STORE & HOOKS
Geometry helpers
computeWhiteboardFit + computeWhiteboardRectFocus — pure functions for camera framing.
SOURCE
import {
computeWhiteboardFit,
computeWhiteboardRectFocus,
} from '@objectifthunes/whiteboard'
// Frame every panel in the viewport, with 60px padding.
const fit = computeWhiteboardFit(panels, viewportSize, 60)
// → { scale, offset } | null
// Frame a single rect, with 40px padding and a max zoom of 1.5×.
const focus = computeWhiteboardRectFocus(rect, viewportSize, 40, 1.5)
// → { scale, offset }NOTES
Pure functions — no React, no Zustand. The store calls them internally for fitToContent and focusPanel, but you can call them yourself for custom framing logic (a "focus selection" button, a snap-to-rect animation, etc.).
Both clamp scale to [0.2, 3]. computeWhiteboardFit clamps the fit-scale to 1.5by default so a single panel doesn't zoom obnoxiously close.