UNPKG

tldraw

Version:

A tiny little drawing editor.

55 lines (54 loc) 1.84 kB
import { isEqualAllowingForFloatingPointErrors } from "@tldraw/editor"; import { createComputedCache } from "@tldraw/store"; import { getCurvedArrowInfo } from "./curved-arrow.mjs"; import { getElbowArrowInfo } from "./elbow/getElbowArrowInfo.mjs"; import { getArrowBindings, getIsArrowStraight } from "./shared.mjs"; import { getStraightArrowInfo } from "./straight-arrow.mjs"; const arrowInfoCache = createComputedCache( "arrow info", (editor, shape) => { const bindings = getArrowBindings(editor, shape); if (shape.props.kind === "elbow") { const elbowInfo = getElbowArrowInfo(editor, shape, bindings); if (!elbowInfo?.route) return getStraightArrowInfo(editor, shape, bindings); const start = elbowInfo.swapOrder ? elbowInfo.B : elbowInfo.A; const end = elbowInfo.swapOrder ? elbowInfo.A : elbowInfo.B; return { type: "elbow", bindings, start: { handle: start.target, point: elbowInfo.route.points[0], arrowhead: shape.props.arrowheadStart }, end: { handle: end.target, point: elbowInfo.route.points[elbowInfo.route.points.length - 1], arrowhead: shape.props.arrowheadEnd }, elbow: elbowInfo, route: elbowInfo.route, isValid: true }; } if (getIsArrowStraight(shape)) { return getStraightArrowInfo(editor, shape, bindings); } else { return getCurvedArrowInfo(editor, shape, bindings); } }, { areRecordsEqual: (a, b) => a.props === b.props, areResultsEqual: isEqualAllowingForFloatingPointErrors } ); function getArrowInfo(editor, shape) { const id = typeof shape === "string" ? shape : shape.id; return arrowInfoCache.get(editor, id); } export { getArrowInfo }; //# sourceMappingURL=getArrowInfo.mjs.map