fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
21 lines (18 loc) • 482 B
text/typescript
import type { FabricObject, Point } from 'fabric';
export function getDistance(a: number, b: number) {
return Math.abs(a - b);
}
export function setPositionDir(
target: FabricObject,
pos: Point,
dir: 'x' | 'y',
) {
const center = target.translateToCenterPoint(pos, 'center', 'center');
const position = target.translateToOriginPoint(
center,
target.originX,
target.originY,
);
if (dir == 'x') target.setX(position.x);
else target.setY(position.y);
}