@nextgensoftwares/folio-interaction
DOM-free interaction maths shared by Folio's editors: page drawings (folio-plugin-layers), slides and canvas boards snap, resize and rotate the same way. No DOM, no dependencies.
ts
import { resizeFrame, snapAngle, snapMove, snapTargets } from '@nextgensoftwares/folio-interaction';
const targets = snapTargets(page, otherBoxes); // edges and centres to snap to
const { dx, dy, guides } = snapMove(box, rawDx, rawDy, targets, 6 / zoom, grid);| Export | Description |
|---|---|
Box | { x, y, w, h } in page units |
SnapTargets | lines a moving box snaps to (xs, ys) and the other boxes (boxes, for equal spacing) |
snapTargets(page, others) | targets from a page (edges, centre, margins) and other objects' edges and centres |
snapMove(box, dx, dy, targets, threshold, grid?) | a move corrected so the box's edges or centre meet the nearest target, else repeat an equal gap, else land on the grid; with the Guides to draw |
Guide, GapGuide | a smart-guide line (x or y) or an equal-spacing mark (gap: axis, from, to, at) |
alignDeltas(boxes, mode, to?), distributeDeltas(boxes, axis), unionBox(boxes), AlignMode | how far each box moves to line up its edges or centres (with the others, or with to), or for even gaps along an axis (three or more, ends fixed) |
snapSpacing(box, others, axis, threshold) | equal spacing alone: the correction and the gaps to mark, or null |
resizeFrame(frame, handle, dx, dy, keepAspect, min?) | a frame (rotation in degrees) resized by dragging handle, in its own rotated axes, the opposite edge fixed |
Handle | 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw' |
snapAngle(deg, step?) | an angle snapped to step degrees (default 15) |