Create professional demos and 3D mockups in seconds, directly in your browser
feat: update LabelSidebar and Timeline components for improved layout; enhance VideoCropperModal with dynamic box sizing and cleanup unused canvas utility functions
CristianOlivera1a2eee824b2d4
diff --git a/app/components/ui/editor/LabelSidebar.tsx b/app/components/ui/editor/LabelSidebar.tsxindex 3e0e469..f7863ca 100644--- a/app/components/ui/editor/LabelSidebar.tsx+++ b/app/components/ui/editor/LabelSidebar.tsx@@ -11,7 +11,7 @@ export default function LabelSidebar({ audioTracksCount = 0 }: LabelSidebarProps<span className="text-[9px] uppercase font-semibold tracking-wider text-zinc-500">Video</span></div>- <div className={`flex items-center px-3 border-t border-white/5 transition-all duration-300 ${audioTracksCount > 0 ? 'h-12' : 'h-16'+ <div className={`flex items-center px-3 border-t border-white/5 transition-all duration-300 ${audioTracksCount > 0 ? 'h-13' : 'h-16'}`}><span className="text-[9px] uppercase font-semibold tracking-wider text-zinc-500">Zoom</span></div>diff --git a/app/components/ui/editor/Timeline.tsx b/app/components/ui/editor/Timeline.tsxindex 2f12282..2e6589e 100644--- a/app/components/ui/editor/Timeline.tsx+++ b/app/components/ui/editor/Timeline.tsx@@ -521,7 +521,7 @@ export function Timeline({{/* Zoom track */}<div- className="flex-1 flex items-center border-t border-white/5 relative"+ className="flex-1 flex items-center relative"onMouseMove={(e) => {if (isDraggingZoomFragment) return;const rect = e.currentTarget.getBoundingClientRect();@@ -624,7 +624,7 @@ export function Timeline({{/* Audio track - only show if there are audio tracks */}{audioTracks.length > 0 && (- <div className="h-5 shrink-0 flex items-center border-t border-white/5 relative">+ <div className="h-5 shrink-0 flex items-center relative"><div className="h-full w-full flex items-center relative">{audioTracks.map((track) => {const audio = uploadedAudios?.find(a => a.id === track.audioId);diff --git a/app/components/ui/editor/VideoCropperModal.tsx b/app/components/ui/editor/VideoCropperModal.tsxindex f04f830..29d4643 100644--- a/app/components/ui/editor/VideoCropperModal.tsx+++ b/app/components/ui/editor/VideoCropperModal.tsx@@ -26,6 +26,8 @@ export function VideoCropperModal({const [wasOpen, setWasOpen] = useState(false);const dragStartPos = useRef({ x: 0, y: 0 });const initialCropRef = useRef<CropArea>({ x: 0, y: 0, width: 100, height: 100 });+ const videoBoxRef = useRef<HTMLDivElement>(null);+ const [boxSize, setBoxSize] = useState({ width: 0, height: 0 });if (isOpen && !wasOpen) {setCropArea(initialCrop ?? { x: 0, y: 0, width: 100, height: 100 });@@ -73,6 +75,44 @@ export function VideoCropperModal({});}, [videoDimensions]);+ useEffect(() => {+ function updateBoxSize() {+ if (!containerRef.current || !videoDimensions.width || !videoDimensions.height) return;++ const rect = containerRef.current.getBoundingClientRect();+ const containerW = rect.width;+ const containerH = rect.height;+ if (containerW === 0 || containerH === 0) return;++ const videoAspect = videoDimensions.width / videoDimensions.height;+ const containerAspect = containerW / containerH;++ let w: number, h: number;+ if (videoAspect > containerAspect) {+ // el video es más "ancho" que el contenedor -> limita por ancho+ w = containerW;+ h = containerW / videoAspect;+ } else {+ // el video es más "alto" (vertical, tu caso 9:16) -> limita por alto+ h = containerH;+ w = containerH * videoAspect;+ }++ setBoxSize({ width: w, height: h });+ }++ updateBoxSize();++ const ro = new ResizeObserver(updateBoxSize);+ if (containerRef.current) ro.observe(containerRef.current);+ window.addEventListener("resize", updateBoxSize);++ return () => {+ ro.disconnect();+ window.removeEventListener("resize", updateBoxSize);+ };+ }, [videoDimensions, isOpen]);+const handleMouseDown = (e: React.MouseEvent, type: "move" | "resize", handle?: string) => {e.preventDefault();e.stopPropagation();@@ -84,10 +124,10 @@ export function VideoCropperModal({};useEffect(() => {- if (!isDragging || !containerRef.current) return;+ if (!isDragging || !videoBoxRef.current) return;const handleMouseMove = (e: MouseEvent) => {- const container = containerRef.current;+ const container = videoBoxRef.current;if (!container) return;const rect = container.getBoundingClientRect();const deltaX = ((e.clientX - dragStartPos.current.x) / rect.width) * 100;@@ -217,7 +257,7 @@ export function VideoCropperModal({animate={{ scale: 1, opacity: 1, y: 0 }}exit={{ scale: 0.96, opacity: 0, y: 8 }}transition={{ duration: 0.18, ease: [0.16, 1, 0.3, 1] }}- className="bg-[#0a0a0b] rounded-2xl border border-white/10 w-[92vw] max-w-5xl max-h-[88vh] flex flex-col overflow-hidden shadow-2xl"+ className="bg-[#0a0a0b] rounded-2xl border border-white/10 w-[94vw] max-w-6xl h-[88vh] flex flex-col overflow-hidden shadow-2xl"><div className="flex items-center justify-between px-5 py-3.5 border-b border-white/10"><div className="flex items-center gap-2.5">@@ -247,16 +287,11 @@ export function VideoCropperModal({className="relative w-full h-full max-w-full max-h-full flex items-center justify-center"><div+ ref={videoBoxRef}className="relative"style={{- width: "100%",- height: "100%",- maxWidth: "100%",- maxHeight: "100%",- aspectRatio:- videoDimensions.width && videoDimensions.height- ? `${videoDimensions.width}/${videoDimensions.height}`- : "16/9",+ width: boxSize.width || "100%",+ height: boxSize.height || "100%",}}>{videoUrl ? (@@ -309,9 +344,9 @@ export function VideoCropperModal({<divkey={handle}className={`absolute w-3 h-3 bg-white rounded-sm shadow-lg ${handle === "nw" ? "-top-1.5 -left-1.5 cursor-nwse-resize" :- handle === "ne" ? "-top-1.5 -right-1.5 cursor-nesw-resize" :- handle === "sw" ? "-bottom-1.5 -left-1.5 cursor-nesw-resize" :- "-bottom-1.5 -right-1.5 cursor-nwse-resize"+ handle === "ne" ? "-top-1.5 -right-1.5 cursor-nesw-resize" :+ handle === "sw" ? "-bottom-1.5 -left-1.5 cursor-nesw-resize" :+ "-bottom-1.5 -right-1.5 cursor-nwse-resize"}`}onMouseDown={(e) => {e.stopPropagation();@@ -326,9 +361,9 @@ export function VideoCropperModal({<divkey={handle}className={`absolute bg-white rounded-sm ${handle === "n" ? "left-1/2 -translate-x-1/2 -top-0.75 cursor-ns-resize" :- handle === "s" ? "left-1/2 -translate-x-1/2 -bottom-0.75 cursor-ns-resize" :- handle === "w" ? "top-1/2 -translate-y-1/2 -left-0.75 cursor-ew-resize" :- "top-1/2 -translate-y-1/2 -right-0.75 cursor-ew-resize"+ handle === "s" ? "left-1/2 -translate-x-1/2 -bottom-0.75 cursor-ns-resize" :+ handle === "w" ? "top-1/2 -translate-y-1/2 -left-0.75 cursor-ew-resize" :+ "top-1/2 -translate-y-1/2 -right-0.75 cursor-ew-resize"}`}style={{ width: isVertical ? "28px" : "5px", height: isVertical ? "5px" : "28px" }}onMouseDown={(e) => {@@ -355,8 +390,8 @@ export function VideoCropperModal({<buttononClick={() => handleAspectRatioSelect(ratio.value)}className={`w-full py-1.5 text-[11px] font-medium rounded-lg transition-all ${selectedAspectRatio === ratio.value- ? "text-white border-transparent"- : "bg-white/4 text-white/40 hover:bg-white/8 hover:text-white/70 border border-white/10"+ ? "text-white border-transparent"+ : "bg-white/4 text-white/40 hover:bg-white/8 hover:text-white/70 border border-white/10"}`}style={selectedAspectRatio === ratio.valuediff --git a/lib/canvas.utils.ts b/lib/canvas.utils.tsindex 5f9c471..77fff79 100644--- a/lib/canvas.utils.ts+++ b/lib/canvas.utils.ts@@ -76,46 +76,6 @@ export function getAspectRatioNumber(ratio: AspectRatio, customDimensions?: { wi}}-// Get max-width based on aspect ratio-export function getMaxWidth(ratio: AspectRatio, customDimensions?: { width: number; height: number }): string {- if ((ratio === "custom" || ratio === "auto") && customDimensions) {- const aspectValue = customDimensions.width / customDimensions.height;- if (aspectValue > 1.5) return "52rem"; // Landscape- if (aspectValue < 0.7) return "20rem"; // Portrait- return "32rem"; // Square-ish- }-- switch (ratio) {- case "16:9": return "52rem";- case "9:16": return "20rem";- case "3:4": return "26rem";- case "4:3": return "40rem";- case "1:1": return "32rem";- default: return "52rem";- }-}--export function calculateScaledProperties(- padding: number,- roundedCorners: number,- shadows: number,- canvasWidth: number,- canvasHeight: number-) {- const paddingPercent = padding * 0.5 / 100;- const scaledPaddingX = paddingPercent * canvasWidth;- const scaledPaddingY = paddingPercent * canvasHeight;- const scaledRadius = roundedCorners * (canvasWidth / 896);- const scaledShadowBlur = shadows * (canvasWidth / 896) * 0.3;-- return {- scaledPaddingX,- scaledPaddingY,- scaledRadius,- scaledShadowBlur,- };-}-export function applyCanvasBackground(ctx: CanvasRenderingContext2D,cssBackground: string,