use getBoundingClientRect to account for decimals in container size

This commit is contained in:
Hernan Torrisi
2024-05-28 15:57:45 -07:00
parent f0ea7add89
commit 25276ad3ec

View File

@@ -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) };