UNPKG

tldraw

Version:

A tiny little drawing editor.

62 lines (61 loc) 2.19 kB
import { exhaustiveSwitchError } from "@tldraw/editor"; import { PathBuilder } from "../shared/PathBuilder.mjs"; import { getRouteHandlePath } from "./elbow/getElbowArrowInfo.mjs"; function getArrowBodyPath(shape, info, opts) { switch (info.type) { case "straight": return new PathBuilder().moveTo(info.start.point.x, info.start.point.y, { offset: 0, roundness: 0 }).lineTo(info.end.point.x, info.end.point.y, { offset: 0, roundness: 0 }).toSvg(opts); case "arc": return new PathBuilder().moveTo(info.start.point.x, info.start.point.y, { offset: 0, roundness: 0 }).arcTo( info.bodyArc.radius, !!info.bodyArc.largeArcFlag, !!info.bodyArc.sweepFlag, info.end.point.x, info.end.point.y, { offset: 0, roundness: 0 } ).toSvg(opts); case "elbow": { const path = new PathBuilder(); path.moveTo(info.start.point.x, info.start.point.y, { offset: 0 }); for (let i = 1; i < info.route.points.length; i++) { const point = info.route.points[i]; if (info.route.skipPointsWhenDrawing.has(point)) { continue; } path.lineTo(point.x, point.y, { offset: i === info.route.points.length - 1 ? 0 : void 0 }); } return path.toSvg(opts); } default: exhaustiveSwitchError(info, "type"); } } function getArrowHandlePath(info, opts) { switch (info.type) { case "straight": return new PathBuilder().moveTo(info.start.handle.x, info.start.handle.y).lineTo(info.end.handle.x, info.end.handle.y).toSvg(opts); case "arc": return new PathBuilder().moveTo(info.start.handle.x, info.start.handle.y).arcTo( info.handleArc.radius, !!info.handleArc.largeArcFlag, !!info.handleArc.sweepFlag, info.end.handle.x, info.end.handle.y ).toSvg(opts); case "elbow": { const handleRoute = getRouteHandlePath(info.elbow, info.route); return PathBuilder.throughPoints(handleRoute.points).toSvg(opts); } default: exhaustiveSwitchError(info, "type"); } } export { getArrowBodyPath, getArrowHandlePath }; //# sourceMappingURL=ArrowPath.mjs.map