Skip to content

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

Refactor editor components and replace BentoDemos with CarouselDemos

CristianOlivera186672d98967a
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index 106ca81..5637875 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -36,7 +36,7 @@ import { EditorTopBar } from "@/app/components/ui/editor/EditorTopBar";
import { VideoCanvas } from "@/app/components/ui/editor/VideoCanvas";
import { PlayerControls } from "@/app/components/ui/editor/PlayerControls";
import { findValidFragmentPosition } from "@/app/components/ui/editor/ZoomFragmentTrackItem";
-import { LoadingSpinner } from "@/app/components/ui/LoadingSpinner";
+import { LoadingSpinner } from "@/components/ui/LoadingSpinner";
import { TimelineSkeleton } from "@/app/components/ui/Skeleton";
import { AudioTrimModal } from "@/app/components/ui/editor/AudioTrimModal";
import { VIDEO_Z_INDEX } from "@/lib/constants";
@@ -524,42 +524,69 @@ export default function Editor() {
}
}, [captureScreen, createProject]);
- // Unified image upload handler - updates current project if exists, otherwise creates new
+ // Unified image upload handler - always creates a new history entry to preserve existing projects
const handleImageUploadToCanvas = useCallback(async (file: File) => {
try {
const img = await createImageBitmap(file);
-
- // If there's a current project, update it instead of creating a new one
- if (currentProject && isPhotoMode) {
- const updated = await saveCurrentProject({
- imageBlob: file,
- imageName: file.name,
- imageWidth: img.width,
- imageHeight: img.height,
- });
-
- if (updated) {
- setImageUrl(updated.imageDataUrl);
- setImageDimensions({ width: img.width, height: img.height });
+ const project = await createProject(
+ file,
+ file.name,
+ img.width,
+ 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,
}
- } else {
- // No current project, create a new one
- const project = await createProject(
- file,
- file.name,
- img.width,
- img.height
- );
+ );
- if (project) {
- setImageUrl(project.imageDataUrl);
- setImageDimensions({ width: img.width, height: img.height });
- }
+ if (project) {
+ setImageUrl(project.imageDataUrl);
+ setImageDimensions({ width: img.width, height: img.height });
}
} catch (error) {
console.error("Failed to upload image:", error);
}
- }, [createProject, currentProject, isPhotoMode, saveCurrentProject]);
+ }, [
+ createProject,
+ backgroundTab,
+ selectedWallpaper,
+ backgroundBlur,
+ selectedImageUrl,
+ backgroundColorConfig,
+ padding,
+ roundedCorners,
+ shadows,
+ aspectRatio,
+ customDimensions,
+ cropArea,
+ mockupId,
+ mockupConfig,
+ canvasElements,
+ videoTransform,
+ imageTransform,
+ apply3DToBackground,
+ imageMaskConfig,
+ ]);
// Handler for drag & drop images on canvas (photo mode only)
const handleImageDrop = useCallback(async (files: FileList | File[]) => {
@@ -572,7 +599,12 @@ export default function Editor() {
await handleImageUploadToCanvas(imageFile);
}
}, [isPhotoMode, handleImageUploadToCanvas]);
-
+ const selectCanvasElement = useCallback((id: string | null) => {
+ setSelectedElementId(id);
+ if (id) {
+ setActiveTool("elements");
+ }
+ }, []);
// Image export handler - using html-to-image with fixed dimensions
const handleImageExport = useCallback(async (
format: ImageExportFormat,
@@ -638,6 +670,10 @@ export default function Editor() {
const hasTransparentBackground = selectedWallpaper === -1;
+ // Temporarily deselect to exclude selection borders from the captured image
+ const prevSelection = selectedElementId;
+ if (prevSelection) selectCanvasElement(null);
+
await new Promise(resolve => setTimeout(resolve, 50));
const blob = await toBlob(previewContainer, {
@@ -650,6 +686,9 @@ export default function Editor() {
pixelRatio: 1,
});
+ // Restore selection after capture
+ if (prevSelection) selectCanvasElement(prevSelection);
+
originalSrcs.forEach((originalSrc, img) => {
img.src = originalSrc;
});
@@ -671,7 +710,7 @@ export default function Editor() {
setImageExportProgress({ status: "error", progress: 0, message: `Export failed: ${errorMessage}` });
setTimeout(() => setImageExportProgress({ status: "idle", progress: 0, message: "" }), 4000);
}
- }, [imageUrl, imageDimensions, selectedWallpaper, aspectRatio, customDimensions]);
+ }, [imageUrl, imageDimensions, selectedWallpaper, aspectRatio, customDimensions, selectedElementId, selectCanvasElement]);
// Generate canvas snapshot for photo mode previews
useEffect(() => {
if (!isPhotoMode || !imageUrl || !canvasRef.current) {
@@ -953,13 +992,6 @@ export default function Editor() {
setSelectedElementId(prev => prev === id ? null : prev);
}, []);
- const selectCanvasElement = useCallback((id: string | null) => {
- setSelectedElementId(id);
- if (id) {
- setActiveTool("elements");
- }
- }, []);
-
const [copiedElement, setCopiedElement] = useState<CanvasElement | null>(null);
const copySelectedElement = useCallback(() => {
diff --git a/app/[locale]/(home)/page.tsx b/app/[locale]/(home)/page.tsx
index 4825ed3..19e4f10 100644
--- a/app/[locale]/(home)/page.tsx
+++ b/app/[locale]/(home)/page.tsx
@@ -1,4 +1,4 @@
-import { BentoDemos } from "@/app/components/ui/BentoDemos";
+import { CarouselDemos } from "@/app/components/ui/CarouselDemos";
import DonationCard from "@/app/components/ui/DonationCard";
import EditorPreview from "@/app/components/ui/EditorPreview";
import Hero from "@/app/components/ui/Hero";
@@ -38,10 +38,10 @@ export default function Home() {
<div className="relative overflow-hidden bg-gradient-radial-primary w-full py-20 pb-40">
<div className="absolute top-0 left-1/2 -translate-x-1/2 w-250 h-[150%] rounded-[100%] blur-xl pointer-events-none "></div>
<section className="w-full">
- <div className="w-full sm:max-w-6xl mx-auto sm:px-6 mb-14">
+ <div className="w-full sm:max-w-6xl mx-auto">
<EditorPreview />
</div>
- <BentoDemos />
+ {/* <CarouselDemos /> */}
</section>
</div>
</div>
diff --git a/app/components/ui/BentoDemos.tsx b/app/components/ui/BentoDemos.tsx
deleted file mode 100644
index 492e0bb..0000000
--- a/app/components/ui/BentoDemos.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-"use client";
-
-import React, { useEffect, useRef, useState } from "react";
-
-const bentoItems = [
- { id: 1, src: "/images/pages/lovable.avif", className: "" },
- { id: 2, src: "/images/pages/vegetative.avif", className: "min-[690px]:col-[2/3] min-[690px]:row-span-2" },
- { id: 3, src: "/images/pages/demo2.mp4", className: "min-[690px]:col-span-2 max-[690px]:col-[2/4] max-[690px]:row-[1/2] max-[470px]:col-auto max-[470px]:row-auto" },
- { id: 4, src: "/images/pages/crafter.avif", className: "" },
- { id: 5, src: "/images/pages/demo.mp4", className: "min-[690px]:col-[3/5] min-[690px]:row-[2/3] max-[470px]:col-span-2" },
-];
-
-export function BentoDemos() {
- const containerRef = useRef<HTMLDivElement>(null);
- const [isVisible, setIsVisible] = useState(false);
-
- useEffect(() => {
- const observer = new IntersectionObserver(
- ([entry]) => {
- if (entry.isIntersecting) {
- setIsVisible(true);
- observer.disconnect();
- }
- },
- { threshold: 0.15 }
- );
-
- if (containerRef.current) {
- observer.observe(containerRef.current);
- }
-
- return () => observer.disconnect();
- }, []);
-
- const isVideo = (src: string) => src.endsWith(".mp4") || src.endsWith(".webm");
-
- return (
- <section
- ref={containerRef}
- className="grid place-content-center gap-4 p-[max(2vh,1.5rem)] w-full h-[82vh] min-h-115 grid-cols-[25%_30%_15%_25%] grid-rows-2 max-[690px]:h-[65vh] max-[470px]:grid-cols-2 max-[470px]:grid-rows-3 perspective-distant"
- >
- {bentoItems.map((item, index) => (
- <div
- key={item.id}
- className={`bento-card group relative rounded-[25px] overflow-hidden bg-zinc-900 border border-white/10 shadow-lg transition-all duration-700 ease-out hover:-translate-y-2 hover:shadow-[0_20px_40px_rgba(0,0,0,0.5)] hover:border-white/30 z-0 hover:z-10 ${item.className}
- ${isVisible ? "opacity-100 translate-y-0" : "opacity-0 translate-y-12"}`}
- style={{
- transitionDelay: isVisible ? `${index * 150}ms` : "0ms"
- }}
- >
- <div className="absolute inset-0 bg-black/20 z-10 transition-opacity duration-700 group-hover:opacity-0 pointer-events-none" />
-
- {isVideo(item.src) ? (
- <video
- autoPlay
- loop
- muted
- playsInline
- preload="metadata"
- className="w-full h-full object-cover transition-transform duration-700 ease-out group-hover:scale-110"
- >
- <source src={item.src} type="video/mp4" />
- </video>
- ) : (
- <img
- src={item.src}
- alt={`Bento item ${item.id}`}
- loading="lazy"
- className="w-full h-full object-cover transition-transform duration-700 ease-out group-hover:scale-110"
- />
- )}
- </div>
- ))}
- </section>
- );
-}
\ No newline at end of file
diff --git a/app/components/ui/CarouselDemos.tsx b/app/components/ui/CarouselDemos.tsx
new file mode 100644
index 0000000..510b5d1
--- /dev/null
+++ b/app/components/ui/CarouselDemos.tsx
@@ -0,0 +1,120 @@
+"use client";
+import React from "react";
+
+const videos = [
+ { src: "/images/pages/demo2.mp4", poster: "" },
+ { src: "/images/pages/demo.mp4", poster: "" },
+ { src: "https://media.w3.org/2010/05/sintel/trailer.mp4", poster: "https://images.unsplash.com/photo-1535016120720-40c7467d5283?w=800" },
+ { src: "https://www.w3schools.com/html/mov_bbb.mp4", poster: "https://images.unsplash.com/photo-1492691527719-9d1e07e534b4?w=800" },
+ { src: "https://media.w3.org/2010/05/sintel/trailer.mp4", poster: "https://images.unsplash.com/photo-1542204165-65bf26472b9b?w=800" },
+ { src: "https://www.w3schools.com/html/mov_bbb.mp4", poster: "https://images.unsplash.com/photo-1574717024653-61fd2cf4d44d?w=800" },
+ { src: "https://media.w3.org/2010/05/sintel/trailer.mp4", poster: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?w=800" },
+ { src: "https://www.w3schools.com/html/mov_bbb.mp4", poster: "https://images.unsplash.com/photo-1478720568477-152d9b164e26?w=800" },
+];
+
+const images = [
+ { src: "/images/pages/lovable.avif", alt: "Lovable" },
+ { src: "/images/pages/vegetative.avif", alt: "Vegetative" },
+ { src: "/images/pages/crafter.avif", alt: "Crafter" },
+ { src: "https://images.unsplash.com/photo-1449824913935-59a10b8d2000?w=800", alt: "City" },
+ { src: "https://images.unsplash.com/photo-1480796927426-f609979314bd?w=800", alt: "Architecture" },
+ { src: "https://images.unsplash.com/photo-1514539079130-25950c84af65?w=800", alt: "Building" },
+ { src: "https://images.unsplash.com/photo-1493246507139-91e8fad9978e?w=800", alt: "Mountain" },
+ { src: "https://images.unsplash.com/photo-1469474968028-56623f02e42e?w=800", alt: "Nature" },
+ { src: "https://images.unsplash.com/photo-1433086966358-54859d0ed716?w=800", alt: "Landscape" },
+ { src: "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=800", alt: "Forest" },
+ { src: "https://images.unsplash.com/photo-1447752875215-b2761acb3c5d?w=800", alt: "Trees" },
+ { src: "https://images.unsplash.com/photo-1465146344425-f00d5f5c8f07?w=800", alt: "Woods" },
+];
+
+export function CarouselDemos() {
+ return (
+ <section className="w-full relative">
+ <style>{`
+ .scene-3d {
+ width: 100%;
+ height: 70vh;
+ min-height: 800px;
+ display: grid;
+ overflow: hidden;
+ perspective: 70em;
+ font-size: clamp(12px, 1.2vw, 25px);
+ mask: linear-gradient(to right, transparent 0%, black 15%, black 85%, transparent 100%);
+ -webkit-mask: linear-gradient(to right, transparent 0%, black 15%, black 85%, transparent 100%);
+ }
+ .a3d-container {
+ grid-area: 1/1;
+ place-self: center;
+ transform-style: preserve-3d;
+ animation: ry 40s linear infinite;
+ display: grid;
+ }
+ @keyframes ry {
+ to { transform: rotateY(1turn); }
+ }
+ .row-videos {
+ translate: 0 -7.5em;
+ }
+ .row-videos .card-3d {
+ --w: 32em;
+ aspect-ratio: 16/9;
+ }
+ .row-images {
+ translate: 0 12em;
+ animation-direction: reverse;
+ animation-duration: 50s;
+ }
+ .row-images .card-3d {
+ --w: 28em;
+ aspect-ratio: 16/9;
+ }
+ .card-3d {
+ --ba: calc(1turn / var(--n));
+ grid-area: 1/1;
+ width: var(--w);
+ object-fit: cover;
+ border-radius: 1rem;
+ backface-visibility: hidden;
+ box-shadow: 0 15px 40px -10px rgba(0, 0, 0, 0.9);
+ transform: rotateY(calc(var(--i) * var(--ba)))
+ translateZ(calc(-1 * (0.5 * var(--w) + 1.5em) / Math.tan(0.5 * var(--ba))));
+ transform: rotateY(calc(var(--i) * var(--ba))) translateZ(calc(-1 * (0.5 * var(--w) + 1.5em) / tan(0.5 * var(--ba))));
+ }
+ @media (prefers-reduced-motion: reduce) {
+ .a3d-container { animation-duration: 120s; }
+ }
+ `}</style>
+
+ <div className="scene-3d">
+ <div className="a3d-container row-videos" style={{ "--n": videos.length } as React.CSSProperties}>
+ {videos.map((vid, index) => (
+ <video
+ key={`video-${index}`}
+ className="card-3d max-w-none bg-zinc-900 border border-white/10"
+ style={{ "--i": index } as React.CSSProperties}
+ autoPlay
+ loop
+ muted
+ playsInline
+ src={vid.src}
+ poster={vid.poster}
+ />
+ ))}
+ </div>
+
+ <div className="a3d-container row-images" style={{ "--n": images.length } as React.CSSProperties}>
+ {images.map((img, index) => (
+ <img
+ key={`img-${index}`}
+ className="card-3d max-w-none bg-zinc-900 border border-white/10"
+ style={{ "--i": index } as React.CSSProperties}
+ src={img.src}
+ alt={img.alt}
+ loading="lazy"
+ />
+ ))}
+ </div>
+ </div>
+ </section>
+ );
+}
\ No newline at end of file
diff --git a/app/components/ui/Skeleton.tsx b/app/components/ui/Skeleton.tsx
index bfbf0f3..449bb77 100644
--- a/app/components/ui/Skeleton.tsx
+++ b/app/components/ui/Skeleton.tsx
@@ -514,26 +514,19 @@ export function VideosMenuSkeleton() {
export function HistoryMenuSkeleton() {
return (
<div className="p-4 flex flex-col gap-5">
- {/* Título del menú */}
<Skeleton height={20} width={120} />
-
- {/* Botón principal de "Subir / Nuevo" */}
<Skeleton height={36} variant="square" />
- {/* Sección de la cuadrícula de historial */}
<div className="space-y-4">
- <Skeleton height={10} width={80} /> {/* Subtítulo (ej. "Recientes") */}
-
+ <Skeleton height={10} width={80} />
<div className="grid grid-cols-2 gap-3">
{Array.from({ length: 6 }).map((_, i) => (
<div key={i} className="flex flex-col gap-2 p-2 rounded-lg bg-white/3 border border-white/5">
- {/* Miniatura del proyecto/imagen */}
<Skeleton
variant="square"
className="w-full rounded-md"
style={{ aspectRatio: "16/9" } as React.CSSProperties}
/>
- {/* Textos simulados (Nombre y fecha) */}
<div className="space-y-1.5 mt-1">
<Skeleton height={10} width="80%" />
<Skeleton height={8} width="50%" />
diff --git a/app/components/ui/SliderControl.tsx b/app/components/ui/SliderControl.tsx
index 8c2b579..7956df9 100644
--- a/app/components/ui/SliderControl.tsx
+++ b/app/components/ui/SliderControl.tsx
@@ -9,10 +9,10 @@ interface SliderControlProps {
value: number;
min?: number;
max?: number;
- step?: number; // Step for decimal values (default: 1)
- suffix?: string; // Optional suffix to display after value (e.g., "%", "px")
+ step?: number;
+ suffix?: string;
onChange?: (value: number) => void;
- onChangeEnd?: () => void; // Called when dragging ends
+ onChangeEnd?: () => void;
}
export function SliderControl({ icon, label, value, min = 0, max = 100, step = 1, suffix = "", onChange, onChangeEnd }: SliderControlProps) {
@@ -48,7 +48,7 @@ export function SliderControl({ icon, label, value, min = 0, max = 100, step = 1
const handleMouseUp = () => {
setIsDragging(false);
- onChangeEnd?.(); // Notify parent that dragging ended
+ onChangeEnd?.();
};
document.addEventListener('mousemove', handleMouseMove);
diff --git a/app/components/ui/editor/CanvasElementsLayer.tsx b/app/components/ui/editor/CanvasElementsLayer.tsx
index af1346f..67c3996 100644
--- a/app/components/ui/editor/CanvasElementsLayer.tsx
+++ b/app/components/ui/editor/CanvasElementsLayer.tsx
@@ -91,11 +91,19 @@ export function CanvasElementsLayer({
ref={setRefs}
className="absolute inset-0"
onClick={(e) => {
- if (e.target === e.currentTarget && onElementSelect) onElementSelect(null);
+ if (e.target === e.currentTarget && onElementSelect) {
+ onElementSelect(null);
+ }
}}
style={{ zIndex: layerZIndex, pointerEvents: 'none' }}
>
- {[...filteredElements].sort((a, b) => a.zIndex - b.zIndex).map((element) => {
+ {[...filteredElements].sort((a, b) => {
+ if (hitTestOnly) {
+ if (a.id === selectedElementId) return 1;
+ if (b.id === selectedElementId) return -1;
+ }
+ return a.zIndex - b.zIndex;
+ }).map((element) => {
const isSelected = selectedElementId === element.id;
const isHovered = hoveredElementId === element.id;
const activeCorner: Corner | null = elementCorners[element.id] ?? null;
@@ -112,7 +120,6 @@ export function CanvasElementsLayer({
transform: `translate(-50%, -50%) rotate(${element.rotation}deg)`,
zIndex: hitTestOnly ? element.zIndex : element.zIndex,
transition: isDraggingElement ? 'none' : 'transform 0.1s ease-out',
- ...(hitTestOnly ? { opacity: 0, pointerEvents: 'auto' } : {}),
};
const handleMouseEnter = () => setHoveredElementId(element.id);
@@ -126,7 +133,10 @@ export function CanvasElementsLayer({
};
const handleMouseDown = (e: React.MouseEvent<HTMLElement>) => {
if (!onElementSelect) return;
- if ((e.target as HTMLElement).closest('[data-element-rotation]')) return;
+ if ((e.target as HTMLElement).closest('[data-element-rotation]')) {
+ e.stopPropagation();
+ return;
+ }
e.preventDefault();
e.stopPropagation();
onElementSelect(element.id);
@@ -140,25 +150,11 @@ export function CanvasElementsLayer({
};
};
- if (hitTestOnly) {
- return (
- <div
- key={element.id}
- data-canvas-element
- className="pointer-events-auto cursor-move"
- style={commonStyle}
- onMouseEnter={handleMouseEnter}
- onMouseLeave={handleMouseLeave}
- onMouseMove={handleMouseMove}
- onMouseDown={handleMouseDown}
- />
- );
- }
-
- const rotationHandle = (isSelected || isHovered) && activeCorner && onElementUpdate ? (
+ const rotationHandle = (isSelected) && activeCorner && onElementUpdate ? (
<div
data-element-rotation
- style={getCornerStyle(activeCorner, -14)}
+ className="pointer-events-auto cursor-grab"
+ style={{ ...getCornerStyle(activeCorner, -14), padding: '1px', margin: '-1px' }}
onMouseDown={(e) => {
e.preventDefault();
e.stopPropagation();
@@ -183,26 +179,91 @@ export function CanvasElementsLayer({
/>
) : null;
- if (element.type === "svg") {
- const SvgComponent = SVG_COMPONENTS[(element as SvgElement).svgId];
+ if (hitTestOnly) {
+ const TOP_Z_INDEX = 2147483647;
+
+ const expandedHitArea = isSelected ? (
+ <div
+ className="absolute"
+ style={{
+ backgroundColor: 'rgba(0,0,0,0.002)',
+ pointerEvents: 'auto'
+ }}
+ />
+ ) : null;
+
+ if (element.type === "text") {
+ return (
+ <div
+ key={element.id}
+ data-canvas-element
+ className="absolute pointer-events-auto cursor-move select-none"
+ style={{
+ left: `${element.x}%`,
+ top: `${element.y}%`,
+ transform: `translate(-50%, -50%) rotate(${element.rotation}deg)`,
+ zIndex: isSelected ? TOP_Z_INDEX : element.zIndex,
+ backgroundColor: isSelected ? 'rgba(0,0,0,0.002)' : 'transparent'
+ }}
+ onMouseEnter={handleMouseEnter}
+ onMouseLeave={handleMouseLeave}
+ onMouseMove={handleMouseMove}
+ onMouseDown={handleMouseDown}
+ >
+ {expandedHitArea}
+
+ <div
+ className="whitespace-nowrap pointer-events-none"
+ style={{
+ fontSize: refSize > 0 ? `${element.fontSize * (refSize / 1080)}px` : `${element.fontSize}px`,
+ fontFamily: element.fontFamily,
+ opacity: 0
+ }}
+ >
+ {element.content}
+ </div>
+
+ {selectionBorder}
+ {rotationHandle}
+ </div>
+ );
+ }
+
return (
<div
key={element.id}
data-canvas-element
- className="pointer-events-auto cursor-move"
- style={commonStyle}
+ className="absolute pointer-events-auto cursor-move"
+ style={{
+ ...commonStyle,
+ zIndex: isSelected ? TOP_Z_INDEX : element.zIndex,
+ backgroundColor: isSelected ? 'rgba(0,0,0,0.002)' : 'transparent'
+ }}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onMouseMove={handleMouseMove}
onMouseDown={handleMouseDown}
+ >
+ {expandedHitArea}
+
+ {selectionBorder}
+ {rotationHandle}
+ </div>
+ );
+ }
+ if (element.type === "svg") {
+ const SvgComponent = SVG_COMPONENTS[(element as SvgElement).svgId];
+ return (
+ <div
+ key={element.id}
+ className="absolute pointer-events-none"
+ style={commonStyle}
>
{SvgComponent && (
<div className="w-full h-full" style={{ opacity: element.opacity }}>
<SvgComponent color={(element as SvgElement).color} className="w-full h-full" />
</div>
)}
- {selectionBorder}
- {rotationHandle}
</div>
);
}
@@ -211,13 +272,8 @@ export function CanvasElementsLayer({
return (
<div
key={element.id}
- data-canvas-element
- className="pointer-events-auto cursor-move"
+ className="absolute pointer-events-none"
style={commonStyle}
- onMouseEnter={handleMouseEnter}
- onMouseLeave={handleMouseLeave}
- onMouseMove={handleMouseMove}
- onMouseDown={handleMouseDown}
>
<img
src={(element as ImageElement).imagePath}
@@ -226,8 +282,6 @@ export function CanvasElementsLayer({
className="w-full h-full object-contain rounded"
style={{ pointerEvents: 'none', opacity: element.opacity }}
/>
- {selectionBorder}
- {rotationHandle}
</div>
);
}
@@ -236,8 +290,7 @@ export function CanvasElementsLayer({
return (
<div
key={element.id}
- data-canvas-element
- className="absolute pointer-events-auto cursor-move select-none"
+ className="absolute pointer-events-none"
style={{
left: `${element.x}%`,
top: `${element.y}%`,
@@ -245,15 +298,11 @@ export function CanvasElementsLayer({
zIndex: element.zIndex,
transition: isDraggingElement ? 'none' : 'transform 0.1s ease-out',
}}
- onMouseEnter={handleMouseEnter}
- onMouseLeave={handleMouseLeave}
- onMouseMove={handleMouseMove}
- onMouseDown={handleMouseDown}
>
<div
className="whitespace-nowrap"
style={{
- fontSize: `${element.fontSize}px`,
+ fontSize: refSize > 0 ? `${element.fontSize * (refSize / 1080)}px` : `${element.fontSize}px`,
fontFamily: element.fontFamily,
fontWeight: element.fontWeight === 'normal' ? 400 : element.fontWeight === 'medium' ? 500 : 700,
textAlign: 'center',
@@ -264,13 +313,6 @@ export function CanvasElementsLayer({
>
{element.content}
</div>
- {(isSelected || isHovered) && (
- <div
- className={`absolute -inset-x-2 -inset-y-1 border pointer-events-none ${isSelected ? 'border-blue-500' : 'border-white/50'}`}
- style={{ borderRadius: '2px' }}
- />
- )}
- {rotationHandle}
</div>
);
}
diff --git a/app/components/ui/editor/EditorHoverTooltip.tsx b/app/components/ui/editor/EditorHoverTooltip.tsx
index 07ca506..845beed 100644
--- a/app/components/ui/editor/EditorHoverTooltip.tsx
+++ b/app/components/ui/editor/EditorHoverTooltip.tsx
@@ -1,10 +1,13 @@
"use client";
+import { useTranslations } from "next-intl";
+
interface EditorHoverTooltipProps {
show: boolean;
}
export function EditorHoverTooltip({ show }: EditorHoverTooltipProps) {
+ const t = useTranslations("editor.hoverTooltip");
if (!show) return null;
return (
@@ -26,7 +29,8 @@ export function EditorHoverTooltip({ show }: EditorHoverTooltipProps) {
<div className="w-px h-4 bg-white/30" />
<div className="flex items-center gap-3">
- <span className="text-[11px] text-white/70 font-medium tracking-tight">Pegar</span>
+ <span className="text-[11px] text-white/70 font-medium tracking-tight"><span>{t("paste")}</span>
+ </span>
<div className="flex items-center gap-1">
<kbd className="h-5 px-1.5 flex items-center justify-center bg-[#171717] rounded border border-white/30 text-[9px] text-white font-mono">
Ctrl
diff --git a/app/components/ui/editor/ElementsMenu.tsx b/app/components/ui/editor/ElementsMenu.tsx
index e39e50e..fe65b17 100644
--- a/app/components/ui/editor/ElementsMenu.tsx
+++ b/app/components/ui/editor/ElementsMenu.tsx
@@ -88,15 +88,19 @@ export function ElementsMenu({
useEffect(() => {
if (!isSyncing.current && selectedElement?.type === "svg" && onUpdateElement) {
+ // SVG elements are always square
onUpdateElement(selectedElement.id, { width: shapeSize, height: shapeSize, color: shapeColor, opacity: shapeOpacity / 100 });
}
}, [shapeSize, shapeColor, shapeOpacity, selectedElement?.id, selectedElement?.type, onUpdateElement]);
useEffect(() => {
if (!isSyncing.current && selectedElement?.type === "image" && onUpdateElement) {
- onUpdateElement(selectedElement.id, { width: imageSize, height: imageSize, opacity: imageOpacity / 100 });
+ // Maintain aspect ratio: calculate height based on original proportions
+ const aspectRatio = selectedElement.width / selectedElement.height;
+ const newHeight = aspectRatio > 0 ? imageSize / aspectRatio : imageSize;
+ onUpdateElement(selectedElement.id, { width: imageSize, height: newHeight, opacity: imageOpacity / 100 });
}
- }, [imageSize, imageOpacity, selectedElement?.id, selectedElement?.type, onUpdateElement]);
+ }, [imageSize, imageOpacity, selectedElement?.id, selectedElement?.type, selectedElement?.width, selectedElement?.height, onUpdateElement]);
useEffect(() => {
if (!isSyncing.current && selectedElement?.type === "text" && onUpdateElement) {
@@ -155,12 +159,27 @@ export function ElementsMenu({
});
}, []);
- const handleAddUploadedImage = useCallback((image: UploadedImage) => {
+ const handleAddUploadedImage = useCallback(async (image: UploadedImage) => {
const timestamp = Date.now();
+ let width = imageSize;
+ let height = imageSize;
+ await new Promise<void>((resolve) => {
+ const img = new Image();
+ img.onload = () => {
+ if (img.naturalWidth && img.naturalHeight) {
+ const ar = img.naturalWidth / img.naturalHeight;
+ if (ar >= 1) { height = imageSize / ar; }
+ else { width = imageSize * ar; }
+ }
+ resolve();
+ };
+ img.onerror = () => resolve();
+ img.src = image.dataUrl;
+ });
const newElement: ImageElement = {
id: `image-${timestamp}-${Math.random().toString(36).substring(2, 9)}`,
type: "image", category: "uploads", x: 50, y: 50,
- width: imageSize, height: imageSize, rotation: 0,
+ width, height, rotation: 0,
opacity: imageOpacity / 100, zIndex: timestamp, imagePath: image.dataUrl,
};
onAddElement(newElement);
@@ -194,12 +213,27 @@ export function ElementsMenu({
onAddElement(newElement);
}, [shapeSize, shapeOpacity, shapeColor, onAddElement]);
- const handleAddImage = useCallback((item: { id: string; name: string; imagePath: string }, categoryId?: string) => {
+ const handleAddImage = useCallback(async (item: { id: string; name: string; imagePath: string }, categoryId?: string) => {
const timestamp = Date.now();
+ let width = imageSize;
+ let height = imageSize;
+ await new Promise<void>((resolve) => {
+ const img = new Image();
+ img.onload = () => {
+ if (img.naturalWidth && img.naturalHeight) {
+ const ar = img.naturalWidth / img.naturalHeight;
+ if (ar >= 1) { height = imageSize / ar; }
+ else { width = imageSize * ar; }
+ }
+ resolve();
+ };
+ img.onerror = () => resolve();
+ img.src = item.imagePath;
+ });
const newElement: ImageElement = {
id: `image-${timestamp}-${Math.random().toString(36).substring(2, 9)}`,
type: "image", category: categoryId || "overlays", x: 50, y: 50,
- width: imageSize, height: imageSize, rotation: 0,
+ width, height, rotation: 0,
opacity: imageOpacity / 100, zIndex: timestamp, imagePath: item.imagePath,
};
onAddElement(newElement);
diff --git a/app/components/ui/editor/MobileControlPanel.tsx b/app/components/ui/editor/MobileControlPanel.tsx
index 8cf81e0..0acf8d7 100644
--- a/app/components/ui/editor/MobileControlPanel.tsx
+++ b/app/components/ui/editor/MobileControlPanel.tsx
@@ -4,7 +4,7 @@ import { Suspense } from "react";
import { Icon } from "@iconify/react";
import * as Dialog from "@radix-ui/react-dialog";
import type { ControlPanelProps } from "@/types/control-panel.types";
-import { LoadingSpinner } from "@/app/components/ui/LoadingSpinner";
+import { LoadingSpinner } from "@/components/ui/LoadingSpinner";
interface MobileControlPanelProps extends ControlPanelProps {
isOpen: boolean;
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index 210b07d..29f05ff 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -20,7 +20,7 @@ import { applyPerspective3D, disposePerspective3D } from "@/lib/perspective3d";
import { RotationHandleIcon } from "@/components/ui/RotationHandleIcon";
import { CanvasElementsLayer } from "./CanvasElementsLayer";
import { EditorHoverTooltip } from "./EditorHoverTooltip";
-import { Icon } from "@iconify/react";
+import DropImage from "@/components/ui/DropImage";
export type { VideoCanvasHandle, VideoCanvasProps };
export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(function VideoCanvas({
@@ -150,6 +150,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
// On-canvas controls state
const [isVideoHovered, setIsVideoHovered] = useState(false);
+ const [isVideoSelected, setIsVideoSelected] = useState(false);
// Image zoom state (for photo mode)
const [imageZoomScale, setImageZoomScale] = useState(1);
@@ -210,7 +211,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
}, []);
const [isDraggingVideo, setIsDraggingVideo] = useState(false);
const [isDraggingRotation, setIsDraggingRotation] = useState(false);
- const [videoHoverCorner, setVideoHoverCorner] = useState<Corner>("top-right");
+ const [videoHoverCorner, setVideoHoverCorner] = useState<Corner | null>("top-right");
const dragStartPos = useRef({ x: 0, y: 0, initialRotation: 0, initialTranslateX: 0, initialTranslateY: 0 });
const lastAngleRef = useRef<number | null>(null);
const videoContainerRef = useRef<HTMLDivElement>(null);
@@ -247,6 +248,16 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
horizontal: number[];
}>({ vertical: [], horizontal: [] });
+ // Wrapper for onElementSelect that also deselects the mockup/video
+ const handleElementSelect = (id: string | null) => {
+ if (id !== null) {
+ setIsVideoSelected(false);
+ }
+ if (onElementSelect) {
+ onElementSelect(id);
+ }
+ };
+
// Drag & drop state for images (photo mode only)
const [isDraggingOver, setIsDraggingOver] = useState(false);
const canvasContainerRef = useRef<HTMLDivElement>(null);
@@ -1255,14 +1266,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
onDrop={handleDrop}
>
{mediaType === "image" && isDraggingOver && (
- <div className="absolute inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm pointer-events-none">
- <div className="flex flex-col items-center gap-4 text-white mask-[radial-gradient(circle,black_50%,transparent_95%)]">
- <Icon icon="hugeicons:image-upload" width="120" />
- <div className="text-xl font-semibold uppercase tracking-wider">
- Suelta la imagen
- </div>
- </div>
- </div>
+ <DropImage />
)}
@@ -1290,8 +1294,13 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
containerType: 'size',
}}
onClick={(e) => {
- if (!(e.target as HTMLElement).closest('[data-canvas-element]') && !(e.target as HTMLElement).closest('[data-camera-overlay]') && onElementSelect) {
- onElementSelect(null);
+ if (
+ !(e.target as HTMLElement).closest('[data-canvas-element]') &&
+ !(e.target as HTMLElement).closest('[data-camera-overlay]') &&
+ !(e.target as HTMLElement).closest('[data-video-container]')
+ ) {
+ if (onElementSelect) onElementSelect(null);
+ setIsVideoSelected(false);
}
}}
>
@@ -1336,7 +1345,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
hoveredElementId={hoveredElementId}
isDraggingElement={isDraggingElement}
behindVideo={true}
- onElementSelect={onElementSelect}
+ onElementSelect={handleElementSelect}
onElementUpdate={onElementUpdate}
setHoveredElementId={setHoveredElementId}
setIsDraggingElement={setIsDraggingElement}
@@ -1351,13 +1360,12 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
<div
className="absolute inset-0 origin-center"
style={{
- transform: zoomTransform.perspective > 0
- ? `rotateX(${zoomTransform.rotateX}deg) rotateY(${zoomTransform.rotateY}deg)`
- : 'none',
+ transform: zoomTransform.perspective > 0 ? `rotateX(${zoomTransform.rotateX}deg) rotateY(${zoomTransform.rotateY}deg)` : 'none',
transition: `transform ${zoomTransform.transitionMs}ms ${ZOOM_EASING}`,
willChange: zoomTransform.perspective > 0 ? 'transform' : 'auto',
transformStyle: 'preserve-3d',
- zIndex: 2
+ zIndex: isVideoSelected ? 101 : 2,
+ pointerEvents: 'none',
}}
>
{/* Capa 2B: Video con padding, esquinas redondeadas y sombras */}
@@ -1365,7 +1373,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
className="absolute inset-0 flex items-center justify-center transition-all duration-200"
style={{
padding: `${padding * 0.5}%`,
- zIndex: 2,
+ zIndex: isVideoSelected ? 101 : 2,
pointerEvents: 'none',
...(mediaType === "image" && imageTransform && !apply3DToBackground ? {
perspective: `${imageTransform.perspective || 600}px`,
@@ -1375,6 +1383,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
>
<div
ref={videoContainerRef}
+ data-video-container
className="relative flex w-full h-full items-center justify-center max-w-full max-h-full"
style={{
transform: mediaType === "image" && imageTransform && !apply3DToBackground
@@ -1396,13 +1405,19 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
transformStyle: mediaType === "image" && !apply3DToBackground ? 'preserve-3d' : undefined,
}}
onMouseEnter={() => hasMedia && setIsVideoHovered(true)}
- onMouseLeave={() => setIsVideoHovered(false)}
+ onMouseLeave={() => {
+ setIsVideoHovered(false);
+ setVideoHoverCorner(null);
+ }}
onMouseDown={(e) => {
if (!hasMedia || !onVideoTransformChange) return;
// Only start dragging if not clicking on rotation handle
if ((e.target as HTMLElement).closest('[data-rotation-handle]')) return;
e.preventDefault();
+ setIsVideoSelected(true);
+ if (onElementSelect) onElementSelect(null);
+ setVideoHoverCorner(getNearestCorner(e, videoTransform.rotation));
setIsDraggingVideo(true);
dragStartPos.current = {
x: e.clientX,
@@ -1415,7 +1430,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
onMouseMove={(e) => { if (hasMedia) setVideoHoverCorner(getNearestCorner(e, videoTransform.rotation)); }}
>
<div className="relative">
- {isVideoHovered && hasMedia && onVideoTransformChange && (
+ {isVideoSelected && videoHoverCorner && hasMedia && onVideoTransformChange && !isDraggingVideo && !isDraggingRotation && (
<div
data-rotation-handle
style={getCornerStyle(videoHoverCorner, -14)}
@@ -1444,9 +1459,9 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
</div>
</div>
)}
- {isVideoHovered && hasMedia && !isDraggingVideo && !isDraggingRotation && (
+ {(isVideoSelected || isVideoHovered) && hasMedia && !isDraggingRotation && (
<div
- className="absolute -inset-px border border-white pointer-events-none z-10 opacity-80"
+ className={`absolute -inset-px border pointer-events-none z-10 opacity-80 ${isVideoSelected ? 'border-blue-500' : 'border-white'}`}
style={{ borderRadius: `${roundedCorners + 1}px` }}
/>
)}
@@ -1554,7 +1569,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
hoveredElementId={hoveredElementId}
isDraggingElement={isDraggingElement}
behindVideo={false}
- onElementSelect={onElementSelect}
+ onElementSelect={handleElementSelect}
onElementUpdate={onElementUpdate}
setHoveredElementId={setHoveredElementId}
setIsDraggingElement={setIsDraggingElement}
@@ -1573,7 +1588,7 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
hoveredElementId={hoveredElementId}
isDraggingElement={isDraggingElement}
behindVideo={true}
- onElementSelect={onElementSelect}
+ onElementSelect={handleElementSelect}
onElementUpdate={onElementUpdate}
setHoveredElementId={setHoveredElementId}
setIsDraggingElement={setIsDraggingElement}
diff --git a/components/ui/DropImage.tsx b/components/ui/DropImage.tsx
new file mode 100644
index 0000000..823337e
--- /dev/null
+++ b/components/ui/DropImage.tsx
@@ -0,0 +1,14 @@
+import { Icon } from "@iconify/react";
+
+export default function DropImage() {
+ return (
+ <div className="absolute inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm pointer-events-none">
+ <div className="flex flex-col items-center gap-4 text-white mask-[radial-gradient(circle,black_50%,transparent_95%)]">
+ <Icon icon="hugeicons:image-upload" width="120" />
+ <div className="text-xl font-semibold uppercase tracking-wider">
+ Suelta la imagen
+ </div>
+ </div>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/app/components/ui/LoadingSpinner.tsx b/components/ui/LoadingSpinner.tsx
similarity index 100%
rename from app/components/ui/LoadingSpinner.tsx
rename to components/ui/LoadingSpinner.tsx