UNPKG

tldraw

Version:

A tiny little drawing editor.

73 lines (72 loc) 2.87 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var getArrowInfo_exports = {}; __export(getArrowInfo_exports, { getArrowInfo: () => getArrowInfo }); module.exports = __toCommonJS(getArrowInfo_exports); var import_editor = require("@tldraw/editor"); var import_store = require("@tldraw/store"); var import_curved_arrow = require("./curved-arrow"); var import_getElbowArrowInfo = require("./elbow/getElbowArrowInfo"); var import_shared = require("./shared"); var import_straight_arrow = require("./straight-arrow"); const arrowInfoCache = (0, import_store.createComputedCache)( "arrow info", (editor, shape) => { const bindings = (0, import_shared.getArrowBindings)(editor, shape); if (shape.props.kind === "elbow") { const elbowInfo = (0, import_getElbowArrowInfo.getElbowArrowInfo)(editor, shape, bindings); if (!elbowInfo?.route) return (0, import_straight_arrow.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 ((0, import_shared.getIsArrowStraight)(shape)) { return (0, import_straight_arrow.getStraightArrowInfo)(editor, shape, bindings); } else { return (0, import_curved_arrow.getCurvedArrowInfo)(editor, shape, bindings); } }, { areRecordsEqual: (a, b) => a.props === b.props, areResultsEqual: import_editor.isEqualAllowingForFloatingPointErrors } ); function getArrowInfo(editor, shape) { const id = typeof shape === "string" ? shape : shape.id; return arrowInfoCache.get(editor, id); } //# sourceMappingURL=getArrowInfo.js.map