Create professional demos and 3D mockups in seconds, directly in your browser
feat: add MacBook mockup component and related utilities
CristianOlivera17ea10999a425
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsxindex ea249f3..46439e1 100644--- a/app/components/ui/editor/VideoCanvas.tsx+++ b/app/components/ui/editor/VideoCanvas.tsx@@ -12,7 +12,7 @@ import PlaceholderEditor from "../PlaceholderEditor";import { MockupWrapper } from "./mockups/MockupWrapper";import { DEFAULT_MOCKUP_CONFIG, type ImageDeviceId } from "@/types/mockup.types";import { calculateSmoothZoom } from "@/lib/canvas.utils";-import { VIDEO_Z_INDEX } from "@/lib/constants";+import { PHOTO_MOCKUPS, VIDEO_Z_INDEX } from "@/lib/constants";import { applyPerspective3D, disposePerspective3D } from "@/lib/perspective3d";import { RotationHandleIcon } from "@/components/ui/RotationHandleIcon";import { CanvasElementsLayer, ElementResizeStart } from "./CanvasElementsLayer";@@ -390,6 +390,7 @@ function VideoCanvasInner({const [isDraggingVideo, setIsDraggingVideo] = useState(false);const [isDraggingRotation, setIsDraggingRotation] = useState(false);const [videoHoverCorner, setVideoHoverCorner] = useState<Corner | null>("top-right");+ const [photoDeviceRect, setPhotoDeviceRect] = useState<{ x: number; y: number; width: number; height: number } | null>(null);const dragStartPos = useRef({ x: 0, y: 0, initialRotation: 0, initialTranslateX: 0, initialTranslateY: 0 });const rotationCenterRef = useRef<{ x: number; y: number } | null>(null);const rotationStartAngleRef = useRef<number>(0);@@ -1280,9 +1281,16 @@ function VideoCanvasInner({const computeContainer = () => {const availableWidth = canvasWidth - scaledPaddingX * 2;const availableHeight = canvasHeight - scaledPaddingY * 2;+ if (PHOTO_MOCKUPS.includes(mockupId)) {+ return {+ containerX: scaledPaddingX,+ containerY: scaledPaddingY,+ containerWidth: availableWidth,+ containerHeight: availableHeight,+ };+ }let mSrcW = sourceWidth;let mSrcH = sourceHeight;-if (cropArea && (cropArea.width < 100 || cropArea.height < 100)) {mSrcW = (cropArea.width / 100) * sourceWidth;mSrcH = (cropArea.height / 100) * sourceHeight;@@ -1676,13 +1684,15 @@ function VideoCanvasInner({}, [hasMockup, mockupId, mockupConfig]);const mockupBoxSize = useMemo(() => {- if (!mediaContainAspect) return null;const { width: Wp, height: Hp } = videoContainerSize;if (Wp <= 0 || Hp <= 0) return null;+ if (PHOTO_MOCKUPS.includes(mockupId)) {+ return { width: Wp, height: Hp };+ }+ if (!mediaContainAspect) return null;const hI = contentInsets.left + contentInsets.right;const vI = contentInsets.top + contentInsets.bottom;-if (hI <= 0 && vI <= 0) {if (Wp / Hp > mediaContainAspect) {const H = Hp;@@ -1690,14 +1700,13 @@ function VideoCanvasInner({}return { width: Wp, height: Wp / mediaContainAspect };}-const widthBoundHeight = vI + (Wp - hI) / mediaContainAspect;if (widthBoundHeight <= Hp) {return { width: Wp, height: widthBoundHeight };}const heightBoundWidth = hI + mediaContainAspect * (Hp - vI);return { width: heightBoundWidth, height: Hp };- }, [mediaContainAspect, videoContainerSize, contentInsets]);+ }, [mediaContainAspect, videoContainerSize, contentInsets, mockupId]);const mockupChildren = useMemo(() => (hasMedia ? (@@ -1711,6 +1720,7 @@ function VideoCanvasInner({cropArea={cropArea}hasMask={hasMask}hasMockup={!!hasMockup}+ objectFit={PHOTO_MOCKUPS.includes(mockupId) ? "cover" : "contain"}maskStyles={maskStyles}currentThumbnail={currentThumbnail}isVideoHovered={isVideoHovered}@@ -1729,9 +1739,25 @@ function VideoCanvasInner({</div>)), [- hasMedia, mediaType, videoUrl, videoRef, imageUrl, imageRef,- cropArea, hasMask, hasMockup, maskStyles, currentThumbnail, isVideoHovered,- onTimeUpdate, onLoadedMetadata, onEnded, onVideoUpload, onImageUpload, isUploading,+ hasMedia,+ mediaType,+ videoUrl,+ videoRef,+ imageUrl,+ imageRef,+ cropArea,+ hasMask,+ hasMockup,+ mockupId,+ maskStyles,+ currentThumbnail,+ isVideoHovered,+ onTimeUpdate,+ onLoadedMetadata,+ onEnded,+ onVideoUpload,+ onImageUpload,+ isUploading,]);const handleHitTestElementSelect = useCallback((id: string | null) => {@@ -1837,7 +1863,7 @@ function VideoCanvasInner({<div className="flex items-stretch min-h-0 min-w-0 w-full h-full justify-center gap-0"><div ref={canvasWrapperRef} className="flex-1 flex items-center justify-center min-h-0 min-w-0 mr-1">- <div className="relative shrink-0 rounded-xl border border-white/20 overflow-hidden">+ <div className="relative shrink-0 squircle-element-camera border border-white/20 overflow-hidden"><divref={previewContainerRef}className="relative shrink-0 transition-all duration-300 overflow-hidden"@@ -1987,7 +2013,7 @@ function VideoCanvasInner({pointerEvents: 'none',transformStyle: mediaType === "image" && !apply3DToBackground ? 'preserve-3d' : undefined,}}- onMouseEnter={() => hasMedia && setIsVideoHovered(true)}+ onMouseEnter={() => { if (hasMedia && !PHOTO_MOCKUPS.includes(mockupId)) setIsVideoHovered(true); }}onMouseLeave={() => {setIsVideoHovered(false);if (isDraggingRotation) return;@@ -2082,11 +2108,15 @@ function VideoCanvasInner({roundedCorners={roundedCorners}shadows={shadows}maskStyles={hasMask ? maskStyles : undefined}+ isSelected={isVideoSelected}+ isHovered={isVideoHovered}+ onDeviceHoverChange={(hovered) => setIsVideoHovered(hovered && hasMedia)}+ onDeviceRectChange={setPhotoDeviceRect}>{mockupChildren}</MockupWrapper>- {(isVideoSelected || isVideoHovered) && hasMedia && !isDraggingRotation && !imagePhoneActive && (+ {(isVideoSelected || isVideoHovered) && hasMedia && !isDraggingRotation && !imagePhoneActive && !PHOTO_MOCKUPS.includes(mockupId) && (<divclassName={`absolute -inset-px border pointer-events-none z-10 opacity-80 ${isVideoSelected ? "border-blue-500" : "border-white"}`}@@ -2094,48 +2124,62 @@ function VideoCanvasInner({/>)}- {isVideoSelected && videoHoverCorner && hasMedia && onVideoTransformChange && !isDraggingVideo && (- <div- data-rotation-handle- style={getCornerStyle(videoHoverCorner, -20)}- onMouseDown={(e) => {- e.preventDefault();- e.stopPropagation();- const container = videoContainerRef.current;- if (!container) return;- const rect = container.getBoundingClientRect();- const centerX = rect.left + rect.width / 2;- const centerY = rect.top + rect.height / 2;- rotationCenterRef.current = { x: centerX, y: centerY };- rotationStartAngleRef.current = Math.atan2(e.clientY - centerY, e.clientX - centerX) * (180 / Math.PI);- setIsDraggingRotation(true);- dragStartPos.current = {- x: e.clientX,- y: e.clientY,- initialRotation: videoTransform.rotation,- initialTranslateX: videoTransform.translateX,- initialTranslateY: videoTransform.translateY,- };- }}- >- <div- style={{- transform: [- `scale(${(mediaType === "image" && imageTransform && !apply3DToBackground- ? 1 / (imageTransform.scale * imageZoomScale)- : 1) * (hasMockup2DMotion && mockupMotionPreview.scale > 0 ? 1 / mockupMotionPreview.scale : 1)- })`,- hasMockup2DMotion- ? `rotateZ(${-mockupMotionPreview.rotateZ}deg) rotateY(${-mockupMotionPreview.rotateY}deg) rotateX(${-mockupMotionPreview.rotateX}deg)`- : "",- ].filter(Boolean).join(" "),- transformOrigin: "center center",- }}- >- <RotationHandleIcon corner={videoHoverCorner} color="#e5e7eb" />+ {(() => {+ const isPhotoMockup = PHOTO_MOCKUPS.includes(mockupId);+ const anchorStyle: React.CSSProperties = isPhotoMockup && photoDeviceRect+ ? {+ position: "absolute",+ left: photoDeviceRect.x,+ top: photoDeviceRect.y,+ width: photoDeviceRect.width,+ height: photoDeviceRect.height,+ pointerEvents: "none",+ }+ : { position: "absolute", inset: 0, pointerEvents: "none" };++ return (+ <div style={anchorStyle}>+ {isVideoSelected && videoHoverCorner && hasMedia && onVideoTransformChange && !isDraggingVideo && (+ <div+ data-rotation-handle+ style={{ ...getCornerStyle(videoHoverCorner, -20), pointerEvents: "auto" }}+ onMouseDown={(e) => {+ e.preventDefault();+ e.stopPropagation();+ const container = videoContainerRef.current;+ if (!container) return;+ const rect = container.getBoundingClientRect();+ const centerX = rect.left + rect.width / 2;+ const centerY = rect.top + rect.height / 2;+ rotationCenterRef.current = { x: centerX, y: centerY };+ rotationStartAngleRef.current = Math.atan2(e.clientY - centerY, e.clientX - centerX) * (180 / Math.PI);+ setIsDraggingRotation(true);+ dragStartPos.current = {+ x: e.clientX,+ y: e.clientY,+ initialRotation: videoTransform.rotation,+ initialTranslateX: videoTransform.translateX,+ initialTranslateY: videoTransform.translateY,+ };+ }}+ >+ <div+ style={{+ transform: [+ `scale(${(mediaType === "image" && imageTransform && !apply3DToBackground ? 1 / (imageTransform.scale * imageZoomScale) : 1) * (hasMockup2DMotion && mockupMotionPreview.scale > 0 ? 1 / mockupMotionPreview.scale : 1)+ })`,+ hasMockup2DMotion ? `rotateZ(${-mockupMotionPreview.rotateZ}deg) rotateY(${-mockupMotionPreview.rotateY}deg) rotateX(${-mockupMotionPreview.rotateX}deg)` : "",+ ].filter(Boolean).join(" "),+ transformOrigin: "center center",+ }}+ >+ <RotationHandleIcon corner={videoHoverCorner} color="#e5e7eb" />+ </div>+ </div>+ )}</div>- </div>- )}+ );+ })()}</div></div></div>diff --git a/app/components/ui/editor/mockups/MacBookMockup.tsx b/app/components/ui/editor/mockups/MacBookMockup.tsxnew file mode 100644index 0000000..923ceb4--- /dev/null+++ b/app/components/ui/editor/mockups/MacBookMockup.tsx@@ -0,0 +1,125 @@+"use client";+import { useCallback, useEffect, useId, useRef, useState } from "react";+import type { MockupRenderProps } from "@/types/mockup.types";+import { MACBOOK_PHOTO_MOCKUP } from "@/lib/photo-mockups.config";+import { usePhotoMockupHitTest, type Rect } from "@/lib/photo-mockup-hit-test.utils";++interface MacBookMockupProps extends MockupRenderProps {+ shadows?: number;+ isSelected?: boolean;+ onDeviceHoverChange?: (hovered: boolean) => void;+ onDeviceRectChange?: (rect: Rect | null) => void;+}++export function MacBookMockup({+ children,+ className = "",+ shadows = 20,+ maskStyles,+ isSelected = false,+ onDeviceHoverChange,+ onDeviceRectChange,+}: MacBookMockupProps) {+ const { imageSrc, screenRect } = MACBOOK_PHOTO_MOCKUP;+ const containerRef = useRef<HTMLDivElement>(null);+ const { imageRect, screenBoxPx, measured, isOnDevice } = usePhotoMockupHitTest(containerRef, MACBOOK_PHOTO_MOCKUP);+ const [deviceHovered, setDeviceHovered] = useState(false);++ const filterIdBase = useId().replace(/[:]/g, "");+ const outlineWhiteId = `macbook-outline-white-${filterIdBase}`;+ const outlineBlueId = `macbook-outline-blue-${filterIdBase}`;++ useEffect(() => {+ onDeviceRectChange?.(measured ? imageRect : null);+ }, [measured, imageRect, onDeviceRectChange]);++ useEffect(() => () => onDeviceRectChange?.(null), [onDeviceRectChange]);++ const reportHover = useCallback((hovered: boolean) => {+ setDeviceHovered(hovered);+ onDeviceHoverChange?.(hovered);+ }, [onDeviceHoverChange]);++ const handleMouseMove = useCallback((e: React.MouseEvent) => {+ reportHover(isOnDevice(e.clientX, e.clientY));+ }, [isOnDevice, reportHover]);++ const handleMouseLeave = useCallback(() => reportHover(false), [reportHover]);++ const handleMouseDownCapture = useCallback((e: React.MouseEvent) => {+ if (!isOnDevice(e.clientX, e.clientY)) e.stopPropagation();+ }, [isOnDevice]);++ const handleClickCapture = useCallback((e: React.MouseEvent) => {+ if (!isOnDevice(e.clientX, e.clientY)) e.stopPropagation();+ }, [isOnDevice]);++ const physicalShadow = shadows > 0+ ? `drop-shadow(0 ${shadows * 0.4}px ${shadows * 1.1}px rgba(0,0,0,0.5))`+ : "";++ const showOutline = isSelected || deviceHovered;+ const outlineFilterId = isSelected ? outlineBlueId : outlineWhiteId;+ const outline = showOutline ? `url(#${outlineFilterId})` : "";+ const combinedFilter = [outline, physicalShadow].filter(Boolean).join(" ") || undefined;++ return (+ <div+ ref={containerRef}+ className={`relative w-full h-full ${className}`}+ onMouseDownCapture={handleMouseDownCapture}+ onClickCapture={handleClickCapture}+ onMouseMove={handleMouseMove}+ onMouseLeave={handleMouseLeave}+ >+ <svg width="0" height="0" style={{ position: "absolute" }} aria-hidden="true">+ <defs>+ {(["white", "blue"] as const).map((variant) => (+ <filter+ key={variant}+ id={variant === "white" ? outlineWhiteId : outlineBlueId}+ x="-15%" y="-15%" width="130%" height="130%"+ >+ <feMorphology in="SourceAlpha" operator="dilate" radius="1.1" result="dilated" />+ <feFlood floodColor={variant === "white" ? "#ffffff" : "#3b82f6"} result="flood" />+ <feComposite in="flood" in2="dilated" operator="in" result="ring" />+ <feComposite in="ring" in2="SourceAlpha" operator="out" result="ringOnly" />+ <feMerge>+ <feMergeNode in="ringOnly" />+ <feMergeNode in="SourceGraphic" />+ </feMerge>+ </filter>+ ))}+ </defs>+ </svg>+ <img+ src={imageSrc}+ alt=""+ draggable={false}+ className="absolute pointer-events-none select-none transition-[filter] duration-150"+ style={{+ left: imageRect.x,+ top: imageRect.y,+ width: imageRect.width,+ height: imageRect.height,+ visibility: measured ? "visible" : "hidden",+ filter: combinedFilter,+ }}+ />+ <div+ className="absolute overflow-hidden"+ style={{+ left: screenBoxPx.x,+ top: screenBoxPx.y,+ width: screenBoxPx.width,+ height: screenBoxPx.height,+ borderRadius: `${screenRect.cornerRadiusPct ?? 0}%`,+ visibility: measured ? "visible" : "hidden",+ ...maskStyles,+ }}+ >+ {children}+ </div>+ </div>+ );+}\ No newline at end of filediff --git a/app/components/ui/editor/mockups/MockupWrapper.tsx b/app/components/ui/editor/mockups/MockupWrapper.tsxindex 884e334..4fd4a9c 100644--- a/app/components/ui/editor/mockups/MockupWrapper.tsx+++ b/app/components/ui/editor/mockups/MockupWrapper.tsx@@ -22,6 +22,7 @@ import { GlassFullMockup } from "./GlassFullMockup";import { HardShellMockup } from "./HardShellMockup";import { S24UltraMockup } from "./S24UltraMockup";import { OutlineMockup } from "./OutlineMockup";+import { MacBookMockup } from "./MacBookMockup";import { memo } from "react";interface MockupWrapperProps {@@ -32,17 +33,13 @@ interface MockupWrapperProps {shadows?: number;className?: string;maskStyles?: React.CSSProperties;+ isSelected?: boolean;+ isHovered?: boolean;+ onDeviceHoverChange?: (hovered: boolean) => void;+ onDeviceRectChange?: (rect: { x: number; y: number; width: number; height: number } | null) => void;}-function MockupWrapperInner({- mockupId,- config,- children,- roundedCorners = 12,- shadows = 20,- className = "",- maskStyles-}: MockupWrapperProps) {+function MockupWrapperInner({ mockupId, config, children, roundedCorners = 12, shadows = 20, className = "", maskStyles, isSelected = false, isHovered = false, onDeviceHoverChange, onDeviceRectChange }: MockupWrapperProps) {switch (mockupId) {case "none":return (@@ -308,6 +305,20 @@ function MockupWrapperInner({{children}</MacosGhostIdeMockup>);+ case "macbook-photo":+ return (+ <MacBookMockup+ config={config}+ shadows={shadows}+ className={className}+ maskStyles={maskStyles}+ isSelected={isSelected}+ onDeviceHoverChange={onDeviceHoverChange}+ onDeviceRectChange={onDeviceRectChange}+ >+ {children}+ </MacBookMockup>+ );default:return (diff --git a/components/ui/MediaContent.tsx b/components/ui/MediaContent.tsxindex bc81193..3fb8e38 100644--- a/components/ui/MediaContent.tsx+++ b/components/ui/MediaContent.tsx@@ -2,87 +2,101 @@ import { VideoCanvasProps, VideoThumbnail } from "@/types";import { memo } from "react";export const MediaContent = memo(function MediaContent({- mediaType, videoUrl, videoRef, imageUrl, imageRef,- cropArea, hasMask, hasMockup, maskStyles,- currentThumbnail, isVideoHovered,- onTimeUpdate, onLoadedMetadata, onEnded,+ mediaType,+ videoUrl,+ videoRef,+ imageUrl,+ imageRef,+ cropArea,+ hasMask,+ hasMockup,+ objectFit = "contain",+ maskStyles,+ currentThumbnail,+ isVideoHovered,+ onTimeUpdate,+ onLoadedMetadata,+ onEnded,}: {- mediaType: "video" | "image";- videoUrl: string | null;- videoRef: React.RefObject<HTMLVideoElement | null>;- imageUrl: string | null;- imageRef?: React.RefObject<HTMLImageElement | null>;- cropArea?: VideoCanvasProps["cropArea"];- hasMask: boolean;- hasMockup: boolean;- maskStyles: React.CSSProperties;- currentThumbnail: VideoThumbnail | null;- isVideoHovered: boolean;- onTimeUpdate?: () => void;- onLoadedMetadata?: () => void;- onEnded?: () => void;+ mediaType: "video" | "image";+ videoUrl: string | null;+ videoRef: React.RefObject<HTMLVideoElement | null>;+ imageUrl: string | null;+ imageRef?: React.RefObject<HTMLImageElement | null>;+ cropArea?: VideoCanvasProps["cropArea"];+ hasMask: boolean;+ hasMockup: boolean;+ objectFit?: "contain" | "cover";+ maskStyles: React.CSSProperties;+ currentThumbnail: VideoThumbnail | null;+ isVideoHovered: boolean;+ onTimeUpdate?: () => void;+ onLoadedMetadata?: () => void;+ onEnded?: () => void;}) {- if (mediaType === "video" && videoUrl) {- return (- <>- <video- key={videoUrl}- ref={videoRef}- preload="auto"- playsInline- className="w-full h-full object-contain"- style={{- ...(cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0)- ? { objectViewBox: `inset(${cropArea.y}% ${100 - cropArea.x - cropArea.width}% ${100 - cropArea.y - cropArea.height}% ${cropArea.x}%)` }- : {}),- ...(hasMask && !hasMockup ? maskStyles : {}),- opacity: currentThumbnail ? 0 : 1,- }}- onTimeUpdate={onTimeUpdate}- onLoadedMetadata={onLoadedMetadata}- onEnded={onEnded}- />- {currentThumbnail && (- <img- src={currentThumbnail.dataUrl}- alt="Preview"- crossOrigin="anonymous"- className="absolute inset-0 w-full h-full object-contain"- style={hasMask && !hasMockup ? maskStyles : {}}- />- )}- </>- );- }+ const fitClass = objectFit === "cover" ? "object-cover" : "object-contain";- if (mediaType === "image" && imageUrl) {- return (- <>- <img- ref={imageRef as React.RefObject<HTMLImageElement>}- src={imageUrl}- alt="Editing image"- crossOrigin="anonymous"- className="w-full h-full object-contain"- style={{- ...(cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0) ? {- objectViewBox: `inset(${cropArea.y}% ${100 - cropArea.x - cropArea.width}% ${100 - cropArea.y - cropArea.height}% ${cropArea.x}%)`- } : {}),- ...(hasMask && !hasMockup ? maskStyles : {}),- }}- onLoad={onLoadedMetadata}- />- <div- className="absolute inset-0 pointer-events-none transition-opacity duration-300"- style={{- background: "radial-gradient(circle at center, transparent 30%, rgba(0, 0, 0, 0.75) 100%)",- opacity: isVideoHovered ? 1 : 0,- zIndex: 10,- }}- />- </>- );- }+ if (mediaType === "video" && videoUrl) {+ return (+ <>+ <video+ key={videoUrl}+ ref={videoRef}+ preload="auto"+ playsInline+ className={`w-full h-full ${fitClass}`}+ style={{+ ...(cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0)+ ? { objectViewBox: `inset(${cropArea.y}% ${100 - cropArea.x - cropArea.width}% ${100 - cropArea.y - cropArea.height}% ${cropArea.x}%)` }+ : {}),+ ...(hasMask && !hasMockup ? maskStyles : {}),+ opacity: currentThumbnail ? 0 : 1,+ }}+ onTimeUpdate={onTimeUpdate}+ onLoadedMetadata={onLoadedMetadata}+ onEnded={onEnded}+ />+ {currentThumbnail && (+ <img+ src={currentThumbnail.dataUrl}+ alt="Preview"+ crossOrigin="anonymous"+ className={`absolute inset-0 w-full h-full ${fitClass}`}+ style={hasMask && !hasMockup ? maskStyles : {}}+ />+ )}+ </>+ );+ }- return null;+ if (mediaType === "image" && imageUrl) {+ return (+ <>+ <img+ ref={imageRef as React.RefObject<HTMLImageElement>}+ src={imageUrl}+ alt="Editing image"+ crossOrigin="anonymous"+ className={`w-full h-full ${fitClass}`}+ style={{+ ...(cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0)+ ? { objectViewBox: `inset(${cropArea.y}% ${100 - cropArea.x - cropArea.width}% ${100 - cropArea.y - cropArea.height}% ${cropArea.x}%)` }+ : {}),+ ...(hasMask && !hasMockup ? maskStyles : {}),+ }}+ onLoad={onLoadedMetadata}+ />+ <div+ className="absolute inset-0 pointer-events-none transition-opacity duration-300"+ style={{+ background: "radial-gradient(circle at center, transparent 30%, rgba(0, 0, 0, 0.75) 100%)",+ opacity: isVideoHovered ? 1 : 0,+ zIndex: 10,+ }}+ />+ </>+ );+ }++ return null;});\ No newline at end of filediff --git a/lib/constants.ts b/lib/constants.tsindex 039b9d5..24a54d6 100644--- a/lib/constants.ts+++ b/lib/constants.ts@@ -54,7 +54,9 @@ export const TIMELINE_ZOOM_SCALE: Record<number, number> = {export const BOTTOM_ONLY_RADIUS_MOCKUPS = ["macos", "macos-glass", "macos-ghost", "macos-ghost-glass", "vscode", "macos-dark-ide", "macos-ghost-ide", "brave", "brave-glass", "browser-tab-glass", "chrome", "chrome-glass", "s24-ultra", "glass-curve", "glass-full", "iphone-slim", "hard-shell"];// Glass mockups → handle their own shadow, do not need the solid rect underneath-export const SELF_SHADOWING_MOCKUPS = ["macos-glass", "outline", "macos-ghost-glass", "glass-ui-container", "macos-container-glass", "brave-glass", "browser-tab-glass", "chrome-glass", "iphone-slim", "glass-curve", "glass-full", "s24-ultra", "hard-shell"];+export const SELF_SHADOWING_MOCKUPS = ["macos-glass", "outline", "macos-ghost-glass", "glass-ui-container", "macos-container-glass", "brave-glass", "browser-tab-glass", "chrome-glass", "iphone-slim", "glass-curve", "glass-full", "s24-ultra", "hard-shell", "macbook-photo"];++export const PHOTO_MOCKUPS = ["macbook-photo"];// Video z-index: elements with zIndex < VIDEO_Z_INDEX render behind the videoexport const VIDEO_Z_INDEX = 1000;diff --git a/lib/mockup-canvas.utils.ts b/lib/mockup-canvas.utils.tsindex a12ba1f..d9537b1 100644--- a/lib/mockup-canvas.utils.ts+++ b/lib/mockup-canvas.utils.ts@@ -22,6 +22,7 @@ import { drawGlassFullMockup } from "./mockup-canvas/glass-full";import { drawHardShellMockup } from "./mockup-canvas/hard-shell";import { drawS24UltraMockup } from "./mockup-canvas/s24-ultra";import { drawOutlineMockup } from "./mockup-canvas/outline";+import { drawMacBookMockup } from "./mockup-canvas/macbook";interface MockupCanvasContext {ctx: CanvasRenderingContext2D;@@ -44,7 +45,7 @@ export function drawMockupToCanvas(canvasWidth: number = 1920,canvasHeight: number = 1080): MockupDrawResult {-+// Important: all mockup calculations are done in a 1280x720 space to maintain proportions, then scaled to the actual canvas size. This ensures the mockup design stays consistent regardless of canvas size or export resolution.const canvasLongSide = Math.max(canvasWidth, canvasHeight);const scale = (canvasLongSide / 1280) * 1.2;@@ -126,6 +127,9 @@ export function drawMockupToCanvas(case "s24-ultra":rawResult = drawS24UltraMockup(context);break;+ case "macbook-photo":+ rawResult = drawMacBookMockup(context);+ break;default:rawResult = {contentX: x / scale,@@ -142,6 +146,9 @@ export function drawMockupToCanvas(contentY: rawResult.contentY * scale,contentWidth: rawResult.contentWidth * scale,contentHeight: rawResult.contentHeight * scale,+ contentRadius: rawResult.contentRadius !== undefined+ ? rawResult.contentRadius * scale+ : undefined,};}diff --git a/lib/mockup-canvas/macbook.ts b/lib/mockup-canvas/macbook.tsnew file mode 100644index 0000000..2829942--- /dev/null+++ b/lib/mockup-canvas/macbook.ts@@ -0,0 +1,68 @@+import type { MockupCanvasContext, MockupDrawResult } from "./types";+import { MACBOOK_PHOTO_MOCKUP } from "@/lib/photo-mockups.config";++let macbookImageCache: HTMLImageElement | null = null;+let macbookImagePromise: Promise<HTMLImageElement> | null = null;++function loadMacbookImage(): Promise<HTMLImageElement> {+ if (macbookImageCache) return Promise.resolve(macbookImageCache);+ if (!macbookImagePromise) {+ macbookImagePromise = new Promise((resolve, reject) => {+ const img = new Image();+ img.crossOrigin = "anonymous";+ img.onload = () => { macbookImageCache = img; resolve(img); };+ img.onerror = (e) => {+ console.error("Failed to load MacBook mockup image:", e);+ macbookImagePromise = null;+ reject(e);+ };+ img.src = MACBOOK_PHOTO_MOCKUP.imageSrc;+ });+ }+ return macbookImagePromise;+}++loadMacbookImage().catch(() => {});++export function drawMacBookMockup(context: MockupCanvasContext): MockupDrawResult {+ const { ctx, x, y, width, height, shadowBlur } = context;+ const { screenRect, naturalWidth, naturalHeight } = MACBOOK_PHOTO_MOCKUP;+ const photoAspect = naturalWidth / naturalHeight;+ const boxAspect = width / height;++ let iw: number, ih: number;+ if (photoAspect > boxAspect) {+ iw = width;+ ih = width / photoAspect;+ } else {+ ih = height;+ iw = height * photoAspect;+ }+ const ix = x + (width - iw) / 2;+ const iy = y + (height - ih) / 2;++ if (macbookImageCache) {+ if (shadowBlur > 0) {+ ctx.save();+ ctx.shadowColor = "rgba(0, 0, 0, 0.45)";+ ctx.shadowBlur = shadowBlur;+ ctx.shadowOffsetY = shadowBlur * 0.25;+ ctx.drawImage(macbookImageCache, ix, iy, iw, ih);+ ctx.restore();+ } else {+ ctx.drawImage(macbookImageCache, ix, iy, iw, ih);+ }+ }++ const contentWidth = (screenRect.width / 100) * iw;+ const contentHeight = (screenRect.height / 100) * ih;+ const contentRadius = ((screenRect.cornerRadiusPct ?? 0) / 100) * contentWidth;++ return {+ contentX: ix + (screenRect.left / 100) * iw,+ contentY: iy + (screenRect.top / 100) * ih,+ contentWidth,+ contentHeight,+ contentRadius,+ };+}\ No newline at end of filediff --git a/lib/mockup-data.tsx b/lib/mockup-data.tsxindex c103d9a..b16477c 100644--- a/lib/mockup-data.tsx+++ b/lib/mockup-data.tsx@@ -1,5 +1,5 @@import { Mockup, DEFAULT_MOCKUP_FEATURES } from "@/types/mockup.types";-import { BraveGlassPreview, BravePreview, BrowserTabGlassPreview, ChromeGlassPreview, ChromePreview, GlassCurvePreview, GlassFullPreview, GlassUIContainerPreview, HardShellPreview, IphoneSlimPreview, MacosContainerGlassPreview, MacosDarkPreview, MacosGhostGlassPreview, MacosGhostIdePreview, MacosGhostPreview, MacosGlassPreview, MacosPreview, NonePreview, OutlinePreview, S24UltraPreview, VSCodePreview } from "./mockup-previews";+import { BraveGlassPreview, BravePreview, BrowserTabGlassPreview, ChromeGlassPreview, ChromePreview, GlassCurvePreview, GlassFullPreview, GlassUIContainerPreview, HardShellPreview, IphoneSlimPreview, MacBookPreview, MacosContainerGlassPreview, MacosDarkPreview, MacosGhostGlassPreview, MacosGhostIdePreview, MacosGhostPreview, MacosGlassPreview, MacosPreview, NonePreview, OutlinePreview, S24UltraPreview, VSCodePreview } from "./mockup-previews";export const MOCKUPS: Mockup[] = [{@@ -272,11 +272,11 @@ export const MOCKUPS: Mockup[] = [),},- // Mobile Mockups+ // device Mockups{id: "iphone-slim",name: "iPhone Slim",- category: "mobile",+ category: "device",features: {hasDarkMode: true,hasFrameColor: true,@@ -298,7 +298,7 @@ export const MOCKUPS: Mockup[] = [{id: "glass-curve",name: "Glass Curve",- category: "mobile",+ category: "device",features: {hasDarkMode: true,hasFrameColor: false,@@ -320,7 +320,7 @@ export const MOCKUPS: Mockup[] = [{id: "glass-full",name: "Glass Full",- category: "mobile",+ category: "device",features: {hasDarkMode: true,hasFrameColor: false,@@ -342,7 +342,7 @@ export const MOCKUPS: Mockup[] = [{id: "hard-shell",name: "Hard Shell",- category: "mobile",+ category: "device",features: {hasDarkMode: true,hasFrameColor: false,@@ -363,7 +363,7 @@ export const MOCKUPS: Mockup[] = [{id: "s24-ultra",name: "S24 Ultra",- category: "mobile",+ category: "device",features: {hasDarkMode: true,hasFrameColor: true,@@ -382,6 +382,16 @@ export const MOCKUPS: Mockup[] = [<S24UltraPreview />),},+ {+ id: "macbook-photo",+ name: "MacBook",+ category: "device",+ features: {+ ...DEFAULT_MOCKUP_FEATURES,+ },+ defaultConfig: {},+ preview: (<MacBookPreview />),+ },// IDE Mockups{@@ -458,6 +468,6 @@ export const MOCKUPS: Mockup[] = [export const MOCKUP_CATEGORIES = [{ id: "all" as const, label: "Todos", icon: "ph:grid-four-bold" },{ id: "browser" as const, label: "Browser", icon: "hugeicons:ai-browser", bgUrl: "/images/mockups/bg-browser.avif" },- { id: "mobile" as const, label: "Mobile", icon: "ph:device-mobile-bold", bgUrl: "/images/mockups/bg-mobile.avif" },+ { id: "device" as const, label: "device", icon: "ph:device-device-bold", bgUrl: "/images/mockups/bg-device.avif" },{ id: "ide" as const, label: "IDE", icon: "ph:code-bold", bgUrl: "/images/mockups/bg-ide.avif" },];diff --git a/lib/mockup-media-draw.utils.ts b/lib/mockup-media-draw.utils.tsindex 3e5a034..7bbda41 100644--- a/lib/mockup-media-draw.utils.ts+++ b/lib/mockup-media-draw.utils.ts@@ -6,7 +6,7 @@ import {} from "@/lib/canvas.utils";import { drawMockupToCanvas } from "@/lib/mockup-canvas.utils";import { DEFAULT_MOCKUP_CONFIG } from "@/types/mockup.types";-import { BOTTOM_ONLY_RADIUS_MOCKUPS, SELF_SHADOWING_MOCKUPS } from "@/lib/constants";+import { BOTTOM_ONLY_RADIUS_MOCKUPS, PHOTO_MOCKUPS, SELF_SHADOWING_MOCKUPS } from "@/lib/constants";import { MockupMotionTransform } from "./mockup-motion";const DEG_TO_RAD = Math.PI / 180;@@ -71,6 +71,7 @@ export function drawMockupAndMedia(const vCY = containerY + containerHeight / 2;const txPx = (videoTransform.translateX / 100) * containerWidth;const tyPx = (videoTransform.translateY / 100) * containerHeight;+ const hasMockupLocal = mockupId && mockupId !== "none";c.save();c.translate(vCX + txPx, vCY + tyPx);@@ -85,7 +86,7 @@ export function drawMockupAndMedia(if (!is3DActive) applyPseudo3DTilt(c, mockupMotion.rotateX, mockupMotion.rotateY);}- if (applyImageXform && imageTransform && !apply3DToBackground) {+ if (applyImageXform && imageTransform && !apply3DToBackground && !hasMockupLocal) {if (imageTransform.perspective && imageTransform.perspective > 0 && (imageTransform.rotateX !== 0 || imageTransform.rotateY !== 0)) {const rotXR = imageTransform.rotateX * DEG_TO_RAD;const rotYR = imageTransform.rotateY * DEG_TO_RAD;@@ -101,7 +102,7 @@ export function drawMockupAndMedia(c.translate(0, iTY / (imageTransform.scale * imageZoomScale));}c.translate(-vCX, -vCY);- if (mockupMotion) c.globalAlpha *= mockupMotion.opacity; // ← nuevo+ if (mockupMotion) c.globalAlpha *= mockupMotion.opacity;if (shadows > 0 && !SELF_SHADOWING_MOCKUPS.includes(mockupId)) {const shadowKey = `${containerWidth.toFixed(1)}x${containerHeight.toFixed(1)}|${scaledRadius.toFixed(1)}|${scaledShadowBlur.toFixed(1)}`;@@ -128,15 +129,24 @@ export function drawMockupAndMedia(c.restore();}- const hasMockupLocal = mockupId && mockupId !== "none";const mockupCfg = mockupConfig || DEFAULT_MOCKUP_CONFIG;let vX = containerX, vY = containerY, vW = containerWidth, vH = containerHeight, vR = scaledRadius;-if (hasMockupLocal) {const mBlur = SELF_SHADOWING_MOCKUPS.includes(mockupId) ? scaledShadowBlur : 0;- const mr = drawMockupToCanvas(c, mockupId, mockupCfg, containerX, containerY, containerWidth, containerHeight, scaledRadius, mBlur, canvasWidth, canvasHeight);- vX = mr.contentX; vY = mr.contentY; vW = mr.contentWidth; vH = mr.contentHeight;- vR = mockupId === "outline" ? scaledRadius * 1.6 : (mockupId === "iphone-slim" || mockupId === "glass-curve" || mockupId === "glass-full") ? scaledRadius * 2.5 : scaledRadius;+ const mr = drawMockupToCanvas(+ c, mockupId, mockupCfg,+ containerX, containerY, containerWidth, containerHeight,+ scaledRadius, mBlur, canvasWidth, canvasHeight+ );+ vX = mr.contentX;+ vY = mr.contentY;+ vW = mr.contentWidth;+ vH = mr.contentHeight;+ vR = mr.contentRadius !== undefined+ ? mr.contentRadius+ : mockupId === "outline" ? scaledRadius * 1.6+ : (mockupId === "iphone-slim" || mockupId === "glass-curve" || mockupId === "glass-full") ? scaledRadius * 2.5+ : scaledRadius;}c.save();@@ -153,7 +163,6 @@ export function drawMockupAndMedia(c.rect(vX, vY, vW, vH);c.clip();}-if (mediaType === "video") {const baseFilter = is3DActive? 'saturate(125%) contrast(110%) brightness(105%)'@@ -162,14 +171,31 @@ export function drawMockupAndMedia(c.filter = baseFilter + motionBlur;}+ let baseSX = 0, baseSY = 0, baseSW = sourceWidth, baseSH = sourceHeight;if (cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0)) {- const sX = (cropArea.x / 100) * sourceWidth;- const sY = (cropArea.y / 100) * sourceHeight;- const cW2 = (cropArea.width / 100) * sourceWidth;- const cH2 = (cropArea.height / 100) * sourceHeight;- c.drawImage(source, sX, sY, cW2, cH2, vX, vY, vW, vH);+ baseSX = (cropArea.x / 100) * sourceWidth;+ baseSY = (cropArea.y / 100) * sourceHeight;+ baseSW = (cropArea.width / 100) * sourceWidth;+ baseSH = (cropArea.height / 100) * sourceHeight;+ }++ if (PHOTO_MOCKUPS.includes(mockupId)) {+++ const destAspect = vW / vH;+ const baseAspect = baseSW / baseSH;+ let coverW = baseSW, coverH = baseSH;+ if (baseAspect > destAspect) {+ coverW = baseSH * destAspect;+ } else {+ coverH = baseSW / destAspect;+ }+ const coverX = baseSX + (baseSW - coverW) / 2;+ const coverY = baseSY + (baseSH - coverH) / 2;+ c.drawImage(source, coverX, coverY, coverW, coverH, vX, vY, vW, vH);} else {- c.drawImage(source, vX, vY, vW, vH);++ c.drawImage(source, baseSX, baseSY, baseSW, baseSH, vX, vY, vW, vH);}c.restore();diff --git a/lib/photo-mockup-hit-test.utils.ts b/lib/photo-mockup-hit-test.utils.tsnew file mode 100644index 0000000..f731d05--- /dev/null+++ b/lib/photo-mockup-hit-test.utils.ts@@ -0,0 +1,121 @@+"use client";+import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";+import type { PhotoMockupConfig } from "./photo-mockups.config";+export interface Rect { x: number; y: number; width: number; height: number }++interface AlphaSampler { data: Uint8ClampedArray; width: number; height: number }++const ALPHA_SAMPLE_WIDTH = 256;+const ALPHA_HIT_THRESHOLD = 10;+const alphaSamplerCache = new Map<string, Promise<AlphaSampler>>();++function getPhotoAlphaSampler(imageSrc: string, aspect: number): Promise<AlphaSampler> {+ const key = `${imageSrc}|${aspect}`;+ let cached = alphaSamplerCache.get(key);+ if (!cached) {+ cached = new Promise((resolve, reject) => {+ const img = new Image();+ img.crossOrigin = "anonymous";+ img.onload = () => {+ const width = ALPHA_SAMPLE_WIDTH;+ const height = Math.round(ALPHA_SAMPLE_WIDTH / aspect);+ const canvas = document.createElement("canvas");+ canvas.width = width;+ canvas.height = height;+ const ctx = canvas.getContext("2d", { willReadFrequently: true });+ if (!ctx) { reject(new Error("2d context unavailable")); return; }+ ctx.drawImage(img, 0, 0, width, height);+ const { data } = ctx.getImageData(0, 0, width, height);+ resolve({ data, width, height });+ };+ img.onerror = reject;+ img.src = imageSrc;+ });+ alphaSamplerCache.set(key, cached);+ }+ return cached;+}++/** Contain-fit rect de una foto de proporción `photoAspect` dentro de una+ * caja de dimensiones dadas — la misma matemática que `object-fit: contain`. */+export function computeContainRect(containerWidth: number, containerHeight: number, photoAspect: number): Rect | null {+ if (containerWidth <= 0 || containerHeight <= 0) return null;+ const boxAspect = containerWidth / containerHeight;+ let iw: number, ih: number;+ if (photoAspect > boxAspect) {+ iw = containerWidth; ih = containerWidth / photoAspect;+ } else {+ ih = containerHeight; iw = containerHeight * photoAspect;+ }+ return { x: (containerWidth - iw) / 2, y: (containerHeight - ih) / 2, width: iw, height: ih };+}++function isAlphaOpaqueAt(sampler: AlphaSampler | null, localX: number, localY: number, imageRect: Rect): boolean {+ if (!sampler) return true;+ if (localX < 0 || localY < 0 || localX >= imageRect.width || localY >= imageRect.height) return false;+ const px = Math.min(sampler.width - 1, Math.floor((localX / imageRect.width) * sampler.width));+ const py = Math.min(sampler.height - 1, Math.floor((localY / imageRect.height) * sampler.height));+ const alpha = sampler.data[(py * sampler.width + px) * 4 + 3];+ return alpha > ALPHA_HIT_THRESHOLD;+}++export interface PhotoMockupHitTest {+ imageRect: Rect;+ screenBoxPx: Rect;+ measured: boolean;+ isOnDevice: (clientX: number, clientY: number) => boolean;+}++export function usePhotoMockupHitTest(+ containerRef: React.RefObject<HTMLElement | null>,+ config: PhotoMockupConfig+): PhotoMockupHitTest {+ const aspect = config.naturalWidth / config.naturalHeight;+ const [imageRect, setImageRect] = useState<Rect>({ x: 0, y: 0, width: 0, height: 0 });+ const [measured, setMeasured] = useState(false);+ const samplerRef = useRef<AlphaSampler | null>(null);++ useLayoutEffect(() => {+ const el = containerRef.current;+ if (!el) return;+ const compute = () => {+ const { width: cw, height: ch } = el.getBoundingClientRect();+ const rect = computeContainRect(cw, ch, aspect);+ if (rect) { setImageRect(rect); setMeasured(true); }+ };+ compute();+ const observer = new ResizeObserver(compute);+ observer.observe(el);+ return () => observer.disconnect();+ }, [containerRef, aspect]);++ useEffect(() => {+ let cancelled = false;+ getPhotoAlphaSampler(config.imageSrc, aspect).then((sampler) => {+ if (!cancelled) samplerRef.current = sampler;+ });+ return () => { cancelled = true; };+ }, [config.imageSrc, aspect]);++ const screenBoxPx = useMemo<Rect>(() => ({+ x: imageRect.x + (config.screenRect.left / 100) * imageRect.width,+ y: imageRect.y + (config.screenRect.top / 100) * imageRect.height,+ width: (config.screenRect.width / 100) * imageRect.width,+ height: (config.screenRect.height / 100) * imageRect.height,+ }), [imageRect, config.screenRect]);++ const isOnDevice = useCallback((clientX: number, clientY: number): boolean => {+ const el = containerRef.current;+ if (!el) return true;+ const rect = el.getBoundingClientRect();+ const localX = clientX - rect.left;+ const localY = clientY - rect.top;+ const insideScreen =+ localX >= screenBoxPx.x && localX <= screenBoxPx.x + screenBoxPx.width &&+ localY >= screenBoxPx.y && localY <= screenBoxPx.y + screenBoxPx.height;+ if (insideScreen) return true;+ return isAlphaOpaqueAt(samplerRef.current, localX - imageRect.x, localY - imageRect.y, imageRect);+ }, [containerRef, imageRect, screenBoxPx]);++ return { imageRect, screenBoxPx, measured, isOnDevice };+}\ No newline at end of filediff --git a/lib/photo-mockups.config.ts b/lib/photo-mockups.config.tsnew file mode 100644index 0000000..ba055cf--- /dev/null+++ b/lib/photo-mockups.config.ts@@ -0,0 +1,27 @@+export interface PhotoMockupScreenRect {+ top: number;+ left: number;+ width: number;+ height: number;+ cornerRadiusPct?: number;+}++export interface PhotoMockupConfig {+ imageSrc: string;+ naturalWidth: number;+ naturalHeight: number;+ screenRect: PhotoMockupScreenRect;+}++export const MACBOOK_PHOTO_MOCKUP: PhotoMockupConfig = {+ imageSrc: "/images/mockups/mac-book.webp",+ naturalWidth: 1294,+ naturalHeight: 819,+ screenRect: {+ top: 4.30,+ left: 9.73,+ width: 80.50,+ height: 83.10,+ cornerRadiusPct: 1,+ },+};\ No newline at end of file