diff --git a/src/pages/editor/components/canvas/useSnap.ts b/src/pages/editor/components/canvas/useSnap.ts index bc7564a..7601701 100644 --- a/src/pages/editor/components/canvas/useSnap.ts +++ b/src/pages/editor/components/canvas/useSnap.ts @@ -1,4 +1,4 @@ -import type Konva from "konva"; +import Konva from "konva"; export type Guide = { id: string; @@ -40,7 +40,15 @@ type RectBounds = { type Axis = "x" | "y"; -const toRectBounds = (rect: Konva.IRect): RectBounds => { +/** Matches Konva `getClientRect` / `IRect`. */ +type BoundsRect = { + x: number; + y: number; + width: number; + height: number; +}; + +const toRectBounds = (rect: BoundsRect): RectBounds => { const left = rect.x; const top = rect.y; const right = rect.x + rect.width; @@ -195,7 +203,9 @@ const collectEqualSpacingCandidates = ( return matches; }; -const findBestCandidate = (candidates: AxisSnapCandidate[]) => { +const findBestCandidate = ( + candidates: AxisSnapCandidate[], +): AxisSnapCandidate | null => { let best: AxisSnapCandidate | null = null; candidates.forEach((candidate) => { if (isBetterCandidate(candidate, best)) { @@ -237,8 +247,8 @@ export const getSnappedPosition = ( const otherRects: RectBounds[] = []; if (layer) { layer - .find((candidate) => Boolean(candidate)) - .forEach((candidate) => { + .find((candidate: Konva.Node) => Boolean(candidate)) + .forEach((candidate: Konva.Node) => { if (candidate === node) return; if (!candidate.draggable()) return; if (!candidate.isVisible()) return;