Skip to content

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

feat: Enhance ZoomPointOverlay with visual scale constant and improve click handling in VideoCanvas

CristianOlivera173415a265c63
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index 4110d23..195dc2d 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -33,7 +33,7 @@ import { drawPhone3DCompositeWithZoom, type Phone3DCompositeContext } from "@/li
import { buildMockupMotionCss, MockupMotionTransform, REST_MOCKUP_MOTION, sampleCombinedMockupMotion } from "@/lib/mockup-motion";
import { Mockup3DFrame } from "./mockups-3d/Mockup3DFrame";
import { filterVisibleElements } from "@/lib/canvas-elements-timeline.utils";
-import { ZoomPointOverlay } from "@/components/ui/ZoomPointOverlay";
+import { ZoomPointOverlay, ZOOM_POINT_VISUAL_SCALE } from "@/components/ui/ZoomPointOverlay";
export type { VideoCanvasHandle, VideoCanvasProps };
@@ -106,6 +106,7 @@ function VideoCanvasInner({
onMockupConfigChange,
selectedZoomFragment = null,
onUpdateZoomFragment,
+ onSelectZoomFragment,
zoomMovements = [],
selectedZoomMovementId = null,
onSelectZoomMovement,
@@ -207,15 +208,27 @@ function VideoCanvasInner({
const handleZoomOverlayClick = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
if (!selectedZoomFragment) return;
- e.stopPropagation();
- if ((e.target as HTMLElement).closest("[data-zoom-drag-handle]")) return;
+ if ((e.target as HTMLElement).closest("[data-zoom-drag-handle]")) {
+ e.stopPropagation();
+ return;
+ }
const container = previewContainerRef.current;
if (!container) return;
const rect = container.getBoundingClientRect();
const x = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100));
const y = Math.max(0, Math.min(100, ((e.clientY - rect.top) / rect.height) * 100));
+ const halfBoxPercent = (100 / zoomLevelToFactor(selectedZoomFragment.zoomLevel)) * ZOOM_POINT_VISUAL_SCALE / 2;
+ const isInsideAnyBox = zoomPointChain.some(
+ (point) => Math.abs(point.x - x) <= halfBoxPercent && Math.abs(point.y - y) <= halfBoxPercent
+ );
+ if (!isInsideAnyBox) {
+ onSelectZoomFragment?.(null);
+ onSelectZoomMovement?.(null);
+ return;
+ }
+ e.stopPropagation();
updateZoomPoint(zoomActivePointId, x, y);
- }, [selectedZoomFragment, zoomActivePointId, updateZoomPoint]);
+ }, [selectedZoomFragment, zoomActivePointId, updateZoomPoint, zoomPointChain, onSelectZoomFragment, onSelectZoomMovement]);
const ctrlScrollWheelRef = useRef<((e: WheelEvent) => void) | null>(null);
const imagePhoneActiveRef = useRef(imagePhoneActive);
diff --git a/components/ui/ZoomPointOverlay.tsx b/components/ui/ZoomPointOverlay.tsx
index e99d241..138d7b7 100644
--- a/components/ui/ZoomPointOverlay.tsx
+++ b/components/ui/ZoomPointOverlay.tsx
@@ -18,6 +18,8 @@ interface ZoomPointOverlayProps {
markerId?: string;
}
+export const ZOOM_POINT_VISUAL_SCALE = 0.7;
+
export function ZoomPointOverlay({
points,
zoomLevel,
@@ -27,9 +29,8 @@ export function ZoomPointOverlay({
}: ZoomPointOverlayProps) {
if (points.length === 0) return null;
- const VISUAL_SCALE = 0.7;
const rawBoxSize = 100 / zoomLevelToFactor(zoomLevel);
- const boxSize = `${rawBoxSize * VISUAL_SCALE}%`;
+ const boxSize = `${rawBoxSize * ZOOM_POINT_VISUAL_SCALE}%`;
return (
<>
@@ -82,18 +83,16 @@ export function ZoomPointOverlay({
: "linear-gradient(to bottom, rgba(16,185,129,0.5), transparent)",
}}
/>
-
+
<div
data-zoom-drag-handle
- className={`absolute z-10 cursor-grab active:cursor-grabbing touch-none transition-[opacity,transform] duration-150 ${
- point.id === activePointId ? "" : "scale-90"
- }`}
+ className={`absolute z-10 cursor-grab active:cursor-grabbing touch-none transition-[opacity,transform] duration-150 ${point.id === activePointId ? "" : "scale-90"
+ }`}
style={{ left: `${point.x}%`, top: `${point.y}%`, transform: "translate(-50%, -50%)" }}
onPointerDown={(e) => onPointPointerDown(e, point.id)}
>
- <div className={`size-8 rounded-full shadow-lg border-2 border-white/90 hover:scale-110 transition-transform flex items-center justify-center ${
- point.id === "origin" ? "bg-blue-500" : "bg-emerald-500"
- }`}>
+ <div className={`size-8 rounded-full shadow-lg border-2 border-white/90 hover:scale-110 transition-transform flex items-center justify-center ${point.id === "origin" ? "bg-blue-500" : "bg-emerald-500"
+ }`}>
<span className="text-[10px] font-bold text-white">{point.label}</span>
</div>
</div>