From 25276ad3ec68f10645e018778bf26086adb5f566 Mon Sep 17 00:00:00 2001 From: Hernan Torrisi Date: Tue, 28 May 2024 15:57:45 -0700 Subject: [PATCH] use getBoundingClientRect to account for decimals in container size --- src/hooks/useResizeCanvas.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hooks/useResizeCanvas.ts b/src/hooks/useResizeCanvas.ts index 1151577..5aa6ff7 100644 --- a/src/hooks/useResizeCanvas.ts +++ b/src/hooks/useResizeCanvas.ts @@ -95,8 +95,9 @@ export default function useResizeCanvas({ const { maxX, maxY } = artboardBounds ?? {}; const getContainerDimensions = useCallback(() => { - const width = containerRef.current?.clientWidth ?? 0; - const height = containerRef.current?.clientHeight ?? 0; + const boundingBox = containerRef.current?.getBoundingClientRect(); + const width = Math.ceil(boundingBox?.width ?? 0); + const height = Math.ceil(boundingBox?.height ?? 0); if (fitCanvasToArtboardHeight && artboardBounds) { const { maxY, maxX } = artboardBounds; return { width, height: width * (maxY / maxX) };