UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

62 lines (61 loc) 1.34 kB
import { getDistanceList } from "./basic.mjs"; //#region extensions/aligning_guidelines/util/collect-line.ts function collectLine(target, points) { const list = target.getCoords(); list.push(target.getCenterPoint()); const opts = { target, list, points, margin: this.margin / this.canvas.getZoom() }; return { vLines: collectPoints({ ...opts, type: "x" }), hLines: collectPoints({ ...opts, type: "y" }) }; } const originArr = [ ["left", "top"], ["right", "top"], ["right", "bottom"], ["left", "bottom"], ["center", "center"] ]; function collectPoints(props) { const { target, list, points, margin, type } = props; const res = []; const arr = []; let min = Infinity; for (const item of list) { const o = getDistanceList(item, points, type); arr.push(o); if (min > o.dis) min = o.dis; } if (min > margin) return res; let b = false; for (let i = 0; i < list.length; i++) { if (arr[i].dis != min) continue; for (const item of arr[i].arr) res.push({ origin: list[i], target: item }); if (b) continue; b = true; const d = arr[i].arr[0][type] - list[i][type]; list.forEach((item) => { item[type] += d; }); target.setXY(list[i], ...originArr[i]); target.setCoords(); } return res; } //#endregion export { collectLine }; //# sourceMappingURL=collect-line.mjs.map