UNPKG

tldraw

Version:

A tiny little drawing editor.

8 lines (7 loc) 3.24 kB
{ "version": 3, "sources": ["../../../../src/lib/shapes/arrow/getArrowInfo.ts"], "sourcesContent": ["import {\n\tEditor,\n\tisEqualAllowingForFloatingPointErrors,\n\tTLArrowShape,\n\tTLShapeId,\n} from '@tldraw/editor'\nimport { createComputedCache } from '@tldraw/store'\nimport { TLArrowInfo } from './arrow-types'\nimport { getCurvedArrowInfo } from './curved-arrow'\nimport { getElbowArrowInfo } from './elbow/getElbowArrowInfo'\nimport { getArrowBindings, getIsArrowStraight } from './shared'\nimport { getStraightArrowInfo } from './straight-arrow'\n\nconst arrowInfoCache = createComputedCache<Editor, TLArrowInfo, TLArrowShape>(\n\t'arrow info',\n\t(editor: Editor, shape: TLArrowShape): TLArrowInfo => {\n\t\tconst bindings = getArrowBindings(editor, shape)\n\t\tif (shape.props.kind === 'elbow') {\n\t\t\tconst elbowInfo = getElbowArrowInfo(editor, shape, bindings)\n\t\t\tif (!elbowInfo?.route) return getStraightArrowInfo(editor, shape, bindings)\n\n\t\t\tconst start = elbowInfo.swapOrder ? elbowInfo.B : elbowInfo.A\n\t\t\tconst end = elbowInfo.swapOrder ? elbowInfo.A : elbowInfo.B\n\n\t\t\treturn {\n\t\t\t\ttype: 'elbow',\n\t\t\t\tbindings,\n\t\t\t\tstart: {\n\t\t\t\t\thandle: start.target,\n\t\t\t\t\tpoint: elbowInfo.route.points[0],\n\t\t\t\t\tarrowhead: shape.props.arrowheadStart,\n\t\t\t\t},\n\t\t\t\tend: {\n\t\t\t\t\thandle: end.target,\n\t\t\t\t\tpoint: elbowInfo.route.points[elbowInfo.route.points.length - 1],\n\t\t\t\t\tarrowhead: shape.props.arrowheadEnd,\n\t\t\t\t},\n\t\t\t\telbow: elbowInfo,\n\t\t\t\troute: elbowInfo.route,\n\t\t\t\tisValid: true,\n\t\t\t}\n\t\t}\n\n\t\tif (getIsArrowStraight(shape)) {\n\t\t\treturn getStraightArrowInfo(editor, shape, bindings)\n\t\t} else {\n\t\t\treturn getCurvedArrowInfo(editor, shape, bindings)\n\t\t}\n\t},\n\t{\n\t\tareRecordsEqual: (a, b) => a.props === b.props,\n\t\tareResultsEqual: isEqualAllowingForFloatingPointErrors,\n\t}\n)\n\n/** @public */\nexport function getArrowInfo(editor: Editor, shape: TLArrowShape | TLShapeId) {\n\tconst id = typeof shape === 'string' ? shape : shape.id\n\treturn arrowInfoCache.get(editor, id)\n}\n"], "mappings": "AAAA;AAAA,EAEC;AAAA,OAGM;AACP,SAAS,2BAA2B;AAEpC,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAClC,SAAS,kBAAkB,0BAA0B;AACrD,SAAS,4BAA4B;AAErC,MAAM,iBAAiB;AAAA,EACtB;AAAA,EACA,CAAC,QAAgB,UAAqC;AACrD,UAAM,WAAW,iBAAiB,QAAQ,KAAK;AAC/C,QAAI,MAAM,MAAM,SAAS,SAAS;AACjC,YAAM,YAAY,kBAAkB,QAAQ,OAAO,QAAQ;AAC3D,UAAI,CAAC,WAAW,MAAO,QAAO,qBAAqB,QAAQ,OAAO,QAAQ;AAE1E,YAAM,QAAQ,UAAU,YAAY,UAAU,IAAI,UAAU;AAC5D,YAAM,MAAM,UAAU,YAAY,UAAU,IAAI,UAAU;AAE1D,aAAO;AAAA,QACN,MAAM;AAAA,QACN;AAAA,QACA,OAAO;AAAA,UACN,QAAQ,MAAM;AAAA,UACd,OAAO,UAAU,MAAM,OAAO,CAAC;AAAA,UAC/B,WAAW,MAAM,MAAM;AAAA,QACxB;AAAA,QACA,KAAK;AAAA,UACJ,QAAQ,IAAI;AAAA,UACZ,OAAO,UAAU,MAAM,OAAO,UAAU,MAAM,OAAO,SAAS,CAAC;AAAA,UAC/D,WAAW,MAAM,MAAM;AAAA,QACxB;AAAA,QACA,OAAO;AAAA,QACP,OAAO,UAAU;AAAA,QACjB,SAAS;AAAA,MACV;AAAA,IACD;AAEA,QAAI,mBAAmB,KAAK,GAAG;AAC9B,aAAO,qBAAq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