Skip to content

Commit

Permalink
use getBoundingClientRect to account for decimals in container size
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymovin committed May 28, 2024
1 parent f0ea7ad commit 25276ad
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/hooks/useResizeCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand Down

0 comments on commit 25276ad

Please sign in to comment.