Create professional demos and 3D mockups in seconds, directly in your browser
fix(camera): clamp bubble layout so camera stays fully visible
Crisc0288aa55a71
diff --git a/app/components/ui/FloatingCameraPreview.tsx b/app/components/ui/FloatingCameraPreview.tsxindex 13c43f5..d883942 100644--- a/app/components/ui/FloatingCameraPreview.tsx+++ b/app/components/ui/FloatingCameraPreview.tsx@@ -2,7 +2,7 @@import { useCallback, useEffect, useRef, useState } from "react";import { Icon } from "@iconify/react";-import type { CameraConfig } from "@/types/camera.types";+import { getCameraLayout, type CameraConfig } from "@/types/camera.types";interface Props {stream: MediaStream;@@ -79,7 +79,11 @@ export default function FloatingCameraPreview({ stream, config, onConfigChange }[]);- const size = Math.min(window.innerWidth, window.innerHeight) * config.size;+ const { size, left, top } = getCameraLayout(+ config,+ typeof window !== "undefined" ? window.innerWidth : 1920,+ typeof window !== "undefined" ? window.innerHeight : 1080+ );const radius = shapeRadius(config.shape);return (@@ -93,8 +97,8 @@ export default function FloatingCameraPreview({ stream, config, onConfigChange }isDragging ? "cursor-grabbing" : "cursor-grab"}`}style={{- left: `calc(${config.position.x * 100}vw - ${size / 2}px)`,- top: `calc(${config.position.y * 100}vh - ${size / 2}px)`,+ left: `${left}px`,+ top: `${top}px`,width: size,height: size,transition: isDragging ? "none" : "left 120ms ease, top 120ms ease",diff --git a/app/components/ui/RecordingSetupDialog.tsx b/app/components/ui/RecordingSetupDialog.tsxindex 59c8431..8beb99d 100644--- a/app/components/ui/RecordingSetupDialog.tsx+++ b/app/components/ui/RecordingSetupDialog.tsx@@ -208,8 +208,8 @@ export default function RecordingSetupDialog({ open, onClose, onStart }: Props)<divclassName="absolute"style={{- left: `calc(${setup.camera.position.x * 100}% - ${setup.camera.size * 50}%)`,- top: `calc(${setup.camera.position.y * 100}% - ${setup.camera.size * 50}%)`,+ left: `clamp(0px, calc(${setup.camera.position.x * 100}% - ${setup.camera.size * 50}%), calc(100% - ${setup.camera.size * 100}%))`,+ top: `clamp(0px, calc(${setup.camera.position.y * 100}% - ${setup.camera.size * 50}%), calc(100% - ${setup.camera.size * 100}%))`,width: `${setup.camera.size * 100}%`,aspectRatio: "1 / 1",}}diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsxindex db07437..b8cb1f6 100644--- a/app/components/ui/editor/VideoCanvas.tsx+++ b/app/components/ui/editor/VideoCanvas.tsx@@ -3,6 +3,7 @@import { useRef, useEffect, useImperativeHandle, forwardRef, useMemo, useState, useCallback } from "react";import type { VideoCanvasHandle, VideoCanvasProps, VideoThumbnail } from "@/types";import type { ImageElement, SvgElement, CanvasElement } from "@/types/canvas-elements.types";+import { getCameraLayout } from "@/types/camera.types";import { ASPECT_RATIO_DIMENSIONS } from "@/types";// import { interpolateCursorPosition, DEFAULT_CURSOR_CONFIG, EMPTY_CURSOR_DATA } from "@/types/cursor.types";// import type { CursorKeyframe } from "@/types/cursor.types";@@ -939,14 +940,13 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct}}- const shortSide = Math.min(canvasWidth, canvasHeight);- const size = cameraConfig.size * shortSide;+ const { size, left: drawX, top: drawY } = getCameraLayout(+ cameraConfig,+ canvasWidth,+ canvasHeight+ );if (size <= 0) return;-- const centerX = cameraConfig.position.x * canvasWidth;- const centerY = cameraConfig.position.y * canvasHeight;- const drawX = centerX - size / 2;- const drawY = centerY - size / 2;+ const shortSide = Math.min(canvasWidth, canvasHeight);const radius =cameraConfig.shape === "circle"@@ -1288,9 +1288,8 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functstyle={{width: `${cameraConfig.size * 100}cqmin`,aspectRatio: "1 / 1",- left: `${cameraConfig.position.x * 100}%`,- top: `${cameraConfig.position.y * 100}%`,- transform: "translate(-50%, -50%)",+ left: `clamp(0px, calc(${cameraConfig.position.x * 100}% - ${cameraConfig.size * 50}cqmin), calc(100% - ${cameraConfig.size * 100}cqmin))`,+ top: `clamp(0px, calc(${cameraConfig.position.y * 100}% - ${cameraConfig.size * 50}cqmin), calc(100% - ${cameraConfig.size * 100}cqmin))`,transition: isDraggingCamera ? "none" : "left 120ms ease, top 120ms ease",touchAction: "none",}}diff --git a/types/camera.types.ts b/types/camera.types.tsindex 5f60406..6b72f00 100644--- a/types/camera.types.ts+++ b/types/camera.types.ts@@ -75,12 +75,37 @@ export const CORNER_POSITIONS: Record<Exclude<CameraCorner, "custom">,CameraPosition> = {- "top-left": { x: 0.05, y: 0.05 },- "top-right": { x: 0.95, y: 0.05 },- "bottom-left": { x: 0.05, y: 0.95 },- "bottom-right": { x: 0.95, y: 0.95 },+ "top-left": { x: 0.12, y: 0.12 },+ "top-right": { x: 0.88, y: 0.12 },+ "bottom-left": { x: 0.12, y: 0.88 },+ "bottom-right": { x: 0.88, y: 0.88 },};+/**+ * Compute the camera bubble's pixel layout inside a container, clamped so the+ * full bubble stays inside the container regardless of position/size. Callers+ * pass container dimensions (viewport, canvas, or preview box) and get back+ * size + top-left pixel coords ready to apply as CSS or canvas draw coords.+ */+export function getCameraLayout(+ config: CameraConfig,+ containerWidth: number,+ containerHeight: number+): { size: number; left: number; top: number } {+ const shortSide = Math.min(containerWidth, containerHeight);+ const size = Math.min(+ config.size * shortSide,+ containerWidth,+ containerHeight+ );+ const half = size / 2;+ const centerX = config.position.x * containerWidth;+ const centerY = config.position.y * containerHeight;+ const left = Math.max(0, Math.min(containerWidth - size, centerX - half));+ const top = Math.max(0, Math.min(containerHeight - size, centerY - half));+ return { size, left, top };+}+export const CAMERA_SHAPES: Array<{ id: CameraShape; label: string; icon: string }> = [{ id: "circle", label: "Círculo", icon: "solar:record-circle-bold" },{ id: "rounded", label: "Redondeado", icon: "solar:squircle-bold" },