@widgetic/canvas 0.5.41 → 0.5.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.js +17 -18
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.js +1286 -1536
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/browserServices.js +65 -116
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/pageEvents.js +4 -4
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.js +3 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +18 -18
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +34 -40
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.js +696 -795
- package/dist/engine/codec/canvasDocument.js +183 -147
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +76 -89
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +67 -94
- package/dist/engine/core/defaults.js +90 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +33 -50
- package/dist/engine/core/hitTest.js +68 -81
- package/dist/engine/core/matrix.js +18 -20
- package/dist/engine/core/pathData.js +183 -210
- package/dist/engine/core/rotationReset.js +5 -6
- package/dist/engine/core/scene.js +129 -187
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +31 -64
- package/dist/engine/core/transform.js +83 -94
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +467 -474
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +262 -308
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +27 -30
- package/dist/engine/input/selectionHandles.js +45 -50
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +86 -158
- package/dist/engine/state.js +4 -15
- package/dist/engine/text/layoutText.js +43 -62
- package/dist/engine/text/textMetrics.js +8 -10
- package/dist/engine/widgets.js +101 -137
- package/dist/fonts/interFont.js +17 -68
- package/dist/fonts/workspaceFonts.js +32 -90
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/settings/workspaceToolSettings.js +32 -48
- package/dist/tools/components/catalog.js +64 -74
- package/dist/tools/components/grouping.js +6 -28
- package/dist/tools/definitions.js +5 -5
- package/dist/tools/executors.js +105 -141
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/types.js +1 -1
- package/package.json +1 -1
|
@@ -4,23 +4,13 @@
|
|
|
4
4
|
* Both work on the units of a selection (a group is one unit), measured by the rectangle around the shapes
|
|
5
5
|
* they draw, and move whole units: nothing is resized.
|
|
6
6
|
*/
|
|
7
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
8
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
9
|
-
if (ar || !(i in from)) {
|
|
10
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
11
|
-
ar[i] = from[i];
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
15
|
-
};
|
|
16
7
|
import { boundsOfObjects, normalizeSelection, translateObjects } from './scene.js';
|
|
17
8
|
function unitsOf(scene, ids) {
|
|
18
|
-
|
|
19
|
-
for (
|
|
20
|
-
|
|
21
|
-
var bounds = boundsOfObjects(scene, [id]);
|
|
9
|
+
const units = [];
|
|
10
|
+
for (const id of normalizeSelection(scene, ids)) {
|
|
11
|
+
const bounds = boundsOfObjects(scene, [id]);
|
|
22
12
|
if (bounds)
|
|
23
|
-
units.push({ id
|
|
13
|
+
units.push({ id, bounds });
|
|
24
14
|
}
|
|
25
15
|
return units;
|
|
26
16
|
}
|
|
@@ -29,18 +19,17 @@ function unitsOf(scene, ids) {
|
|
|
29
19
|
* Needs two units or more; returns the same scene otherwise, or when everything is already in line.
|
|
30
20
|
*/
|
|
31
21
|
export function alignObjects(scene, ids, mode) {
|
|
32
|
-
|
|
22
|
+
const units = unitsOf(scene, ids);
|
|
33
23
|
if (units.length < 2)
|
|
34
24
|
return scene;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
for (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var deltaY = 0;
|
|
25
|
+
const left = Math.min(...units.map((unit) => unit.bounds.x));
|
|
26
|
+
const right = Math.max(...units.map((unit) => unit.bounds.x + unit.bounds.width));
|
|
27
|
+
const top = Math.min(...units.map((unit) => unit.bounds.y));
|
|
28
|
+
const bottom = Math.max(...units.map((unit) => unit.bounds.y + unit.bounds.height));
|
|
29
|
+
let next = scene;
|
|
30
|
+
for (const unit of units) {
|
|
31
|
+
let deltaX = 0;
|
|
32
|
+
let deltaY = 0;
|
|
44
33
|
switch (mode) {
|
|
45
34
|
case 'left':
|
|
46
35
|
deltaX = left - unit.bounds.x;
|
|
@@ -70,22 +59,21 @@ export function alignObjects(scene, ids, mode) {
|
|
|
70
59
|
* Needs three units or more.
|
|
71
60
|
*/
|
|
72
61
|
export function distributeObjects(scene, ids, axis) {
|
|
73
|
-
|
|
62
|
+
const units = unitsOf(scene, ids);
|
|
74
63
|
if (units.length < 3)
|
|
75
64
|
return scene;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
for (
|
|
87
|
-
|
|
88
|
-
var delta = cursor - start(unit);
|
|
65
|
+
const start = (unit) => (axis === 'horizontal' ? unit.bounds.x : unit.bounds.y);
|
|
66
|
+
const size = (unit) => (axis === 'horizontal' ? unit.bounds.width : unit.bounds.height);
|
|
67
|
+
const ordered = [...units].sort((first, second) => start(first) - start(second));
|
|
68
|
+
const first = ordered[0];
|
|
69
|
+
const last = ordered[ordered.length - 1];
|
|
70
|
+
const span = start(last) + size(last) - start(first);
|
|
71
|
+
const occupied = ordered.reduce((total, unit) => total + size(unit), 0);
|
|
72
|
+
const gap = (span - occupied) / (ordered.length - 1);
|
|
73
|
+
let next = scene;
|
|
74
|
+
let cursor = start(first) + size(first) + gap;
|
|
75
|
+
for (const unit of ordered.slice(1, -1)) {
|
|
76
|
+
const delta = cursor - start(unit);
|
|
89
77
|
next = axis === 'horizontal' ? translateObjects(next, [unit.id], delta, 0) : translateObjects(next, [unit.id], 0, delta);
|
|
90
78
|
cursor += size(unit) + gap;
|
|
91
79
|
}
|
|
@@ -15,43 +15,23 @@
|
|
|
15
15
|
* in the coordinates of the box that holds it, ready to be written into a path object, together with that box and the arrow's
|
|
16
16
|
* `ArrowSpec` in the same coordinates.
|
|
17
17
|
*/
|
|
18
|
-
var __assign = (this && this.__assign) || function () {
|
|
19
|
-
__assign = Object.assign || function(t) {
|
|
20
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
-
s = arguments[i];
|
|
22
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
23
|
-
t[p] = s[p];
|
|
24
|
-
}
|
|
25
|
-
return t;
|
|
26
|
-
};
|
|
27
|
-
return __assign.apply(this, arguments);
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
18
|
import { withBindings } from './arrowBindingRecords.js';
|
|
39
19
|
import { clampNumber } from './geometry.js';
|
|
40
20
|
import { parsePathData, pathBounds, serializePathData, translatePathCommands } from './pathData.js';
|
|
41
21
|
/** The wings of the head open this far either side of the shaft (30 degrees). */
|
|
42
|
-
export
|
|
22
|
+
export const ARROW_HEAD_ANGLE = Math.PI / 6;
|
|
43
23
|
/** The head is this fraction of the length of the arrow ... */
|
|
44
|
-
export
|
|
24
|
+
export const ARROW_HEAD_LENGTH_FRACTION = 1 / 5;
|
|
45
25
|
/** ... but at least this many widths of the line ... */
|
|
46
|
-
export
|
|
26
|
+
export const ARROW_HEAD_MIN_WIDTHS = 1;
|
|
47
27
|
/** ... and at most this many. */
|
|
48
|
-
export
|
|
28
|
+
export const ARROW_HEAD_MAX_WIDTHS = 3;
|
|
49
29
|
/** A bend smaller than this (world units) is not a bend: the arrow is straight. */
|
|
50
|
-
export
|
|
30
|
+
export const MIN_ARROW_BEND = 8;
|
|
51
31
|
/** An arrow bends by at most this many times its own length (a little under a full circle). */
|
|
52
|
-
export
|
|
32
|
+
export const MAX_ARROW_BEND_PER_LENGTH = 2;
|
|
53
33
|
/** The line is at least this wide for the size of the head, so that an arrow drawn with no line still has one. */
|
|
54
|
-
|
|
34
|
+
const MIN_HEAD_LINE_WIDTH = 1;
|
|
55
35
|
/** Whether a shape is an arrow made by the Arrow tool, with the points it is drawn from. */
|
|
56
36
|
export function isArrow(shape) {
|
|
57
37
|
return shape.type === 'path' && shape.arrow !== null;
|
|
@@ -64,28 +44,28 @@ export function drawnBend(bend, length) {
|
|
|
64
44
|
}
|
|
65
45
|
/** The length of the head for an arrow whose shaft is `bodyLength` long, drawn with a line `strokeWidth` wide. */
|
|
66
46
|
export function arrowHeadLength(bodyLength, strokeWidth) {
|
|
67
|
-
|
|
47
|
+
const width = Math.max(strokeWidth, MIN_HEAD_LINE_WIDTH);
|
|
68
48
|
return clampNumber(bodyLength * ARROW_HEAD_LENGTH_FRACTION, width * ARROW_HEAD_MIN_WIDTHS, width * ARROW_HEAD_MAX_WIDTHS);
|
|
69
49
|
}
|
|
70
50
|
/** A point turned about another by an angle (radians, clockwise on screen). */
|
|
71
51
|
function rotateAbout(point, center, radians) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
const cosine = Math.cos(radians);
|
|
53
|
+
const sine = Math.sin(radians);
|
|
54
|
+
const offsetX = point.x - center.x;
|
|
55
|
+
const offsetY = point.y - center.y;
|
|
76
56
|
return { x: center.x + offsetX * cosine - offsetY * sine, y: center.y + offsetX * sine + offsetY * cosine };
|
|
77
57
|
}
|
|
78
58
|
/** The direction from one point to another, and the normal to the right of it. A point that is the other's own has a direction to the right. */
|
|
79
59
|
function directionBetween(start, end) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return { length
|
|
60
|
+
const deltaX = end.x - start.x;
|
|
61
|
+
const deltaY = end.y - start.y;
|
|
62
|
+
const length = Math.hypot(deltaX, deltaY);
|
|
63
|
+
const unit = length > 1e-9 ? { x: deltaX / length, y: deltaY / length } : { x: 1, y: 0 };
|
|
64
|
+
return { length, unit, normal: { x: -unit.y, y: unit.x } };
|
|
85
65
|
}
|
|
86
66
|
/** The middle of the arrow: the middle of the line between its ends, pushed `bend` to the right of the way it points. */
|
|
87
67
|
export function arrowMiddle(start, end, bend) {
|
|
88
|
-
|
|
68
|
+
const { normal } = directionBetween(start, end);
|
|
89
69
|
return { x: (start.x + end.x) / 2 + normal.x * bend, y: (start.y + end.y) / 2 + normal.y * bend };
|
|
90
70
|
}
|
|
91
71
|
/**
|
|
@@ -93,7 +73,7 @@ export function arrowMiddle(start, end, bend) {
|
|
|
93
73
|
* measured along the normal to it (so the middle follows the pointer without sliding along the arrow).
|
|
94
74
|
*/
|
|
95
75
|
export function bendTowards(start, end, point) {
|
|
96
|
-
|
|
76
|
+
const { normal } = directionBetween(start, end);
|
|
97
77
|
return (point.x - (start.x + end.x) / 2) * normal.x + (point.y - (start.y + end.y) / 2) * normal.y;
|
|
98
78
|
}
|
|
99
79
|
/**
|
|
@@ -101,53 +81,52 @@ export function bendTowards(start, end, point) {
|
|
|
101
81
|
* come back in the frame the points were given in, the path moved to the corner of the box that holds it.
|
|
102
82
|
*/
|
|
103
83
|
export function buildArrow(start, end, bend, strokeWidth) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var bodyLength = length;
|
|
84
|
+
const { length, unit, normal } = directionBetween(start, end);
|
|
85
|
+
const bent = drawnBend(bend, length);
|
|
86
|
+
const middle = { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };
|
|
87
|
+
let shaft;
|
|
88
|
+
let bodyLength = length;
|
|
110
89
|
// The point of the shaft one head-length back from the tip: the head is the shaft's own direction turned either way.
|
|
111
|
-
|
|
90
|
+
let pointBack;
|
|
112
91
|
if (bent === 0) {
|
|
113
92
|
shaft = [
|
|
114
93
|
['M', start.x, start.y],
|
|
115
94
|
['L', end.x, end.y]
|
|
116
95
|
];
|
|
117
|
-
pointBack =
|
|
96
|
+
pointBack = (headLength) => ({ x: end.x - unit.x * headLength, y: end.y - unit.y * headLength });
|
|
118
97
|
}
|
|
119
98
|
else {
|
|
120
99
|
// The circle through the start, the end and the middle: the arc between the ends that goes by the middle.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
100
|
+
const half = length / 2;
|
|
101
|
+
const sagitta = Math.abs(bent);
|
|
102
|
+
const radius = (half * half + sagitta * sagitta) / (2 * sagitta);
|
|
103
|
+
const centerAlongNormal = bent - Math.sign(bent) * radius;
|
|
104
|
+
const center = { x: middle.x + normal.x * centerAlongNormal, y: middle.y + normal.y * centerAlongNormal };
|
|
105
|
+
const largeArc = sagitta > half ? 1 : 0;
|
|
127
106
|
// To the right of the way it points (a positive bend) the arc runs against the clock on the screen.
|
|
128
|
-
|
|
129
|
-
shaft = parsePathData(
|
|
130
|
-
bodyLength = 2 *
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
pointBack =
|
|
107
|
+
const sweep = bent > 0 ? 0 : 1;
|
|
108
|
+
shaft = parsePathData(`M ${start.x} ${start.y} A ${radius} ${radius} 0 ${largeArc} ${sweep} ${end.x} ${end.y}`);
|
|
109
|
+
bodyLength = 2 * radius * Math.atan2(half, radius - sagitta);
|
|
110
|
+
const travel = bent > 0 ? -1 : 1;
|
|
111
|
+
const tipAngle = Math.atan2(end.y - center.y, end.x - center.x);
|
|
112
|
+
pointBack = (headLength) => {
|
|
134
113
|
// The point of the arc that is `headLength` from the tip as the crow flies, a little way back along the arc.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return { x:
|
|
114
|
+
const turn = 2 * Math.asin(Math.min(1, headLength / (2 * radius)));
|
|
115
|
+
const angle = tipAngle - travel * turn;
|
|
116
|
+
return { x: center.x + radius * Math.cos(angle), y: center.y + radius * Math.sin(angle) };
|
|
138
117
|
};
|
|
139
118
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
119
|
+
const headLength = arrowHeadLength(bodyLength, strokeWidth);
|
|
120
|
+
const back = pointBack(headLength);
|
|
121
|
+
const leftWing = rotateAbout(back, end, ARROW_HEAD_ANGLE);
|
|
122
|
+
const rightWing = rotateAbout(back, end, -ARROW_HEAD_ANGLE);
|
|
123
|
+
const world = [...shaft, ['M', leftWing.x, leftWing.y], ['L', end.x, end.y], ['L', rightWing.x, rightWing.y]];
|
|
124
|
+
const bounds = pathBounds(world);
|
|
125
|
+
const origin = bounds ? { x: bounds.x, y: bounds.y } : { x: start.x, y: start.y };
|
|
126
|
+
const box = { x: origin.x, y: origin.y, width: Math.max(bounds?.width ?? 0, 1), height: Math.max(bounds?.height ?? 0, 1) };
|
|
148
127
|
return {
|
|
149
128
|
commands: translatePathCommands(world, -origin.x, -origin.y),
|
|
150
|
-
box
|
|
129
|
+
box,
|
|
151
130
|
spec: {
|
|
152
131
|
start: { x: start.x - origin.x, y: start.y - origin.y },
|
|
153
132
|
end: { x: end.x - origin.x, y: end.y - origin.y },
|
|
@@ -157,37 +136,45 @@ export function buildArrow(start, end, bend, strokeWidth) {
|
|
|
157
136
|
}
|
|
158
137
|
/** Where the points of an arrow are in the world: its two ends, and the handle in the middle (on the line while the arrow is straight). */
|
|
159
138
|
export function arrowPointsInWorld(shape) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return { start
|
|
139
|
+
const start = { x: shape.x + shape.arrow.start.x, y: shape.y + shape.arrow.start.y };
|
|
140
|
+
const end = { x: shape.x + shape.arrow.end.x, y: shape.y + shape.arrow.end.y };
|
|
141
|
+
return { start, end, middle: arrowMiddle(start, end, shape.arrow.bend) };
|
|
163
142
|
}
|
|
164
143
|
/**
|
|
165
144
|
* The arrow drawn again after a change: a new shape with the same id, the new box, path and points. What its ends are tied to stays
|
|
166
145
|
* as it was unless the change says otherwise (the points do not move because a tie says so here: `arrowBinding.ts` places them).
|
|
167
146
|
*/
|
|
168
|
-
export function reshapeArrow(shape, change) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
var geometry = buildArrow((_b = change.start) !== null && _b !== void 0 ? _b : current.start, (_c = change.end) !== null && _c !== void 0 ? _c : current.end, (_d = change.bend) !== null && _d !== void 0 ? _d : shape.arrow.bend, strokeWidth);
|
|
174
|
-
var ties = {
|
|
147
|
+
export function reshapeArrow(shape, change = {}) {
|
|
148
|
+
const current = arrowPointsInWorld(shape);
|
|
149
|
+
const strokeWidth = change.strokeWidth ?? shape.strokeWidth;
|
|
150
|
+
const geometry = buildArrow(change.start ?? current.start, change.end ?? current.end, change.bend ?? shape.arrow.bend, strokeWidth);
|
|
151
|
+
const ties = {
|
|
175
152
|
startBinding: 'startBinding' in change ? change.startBinding : shape.arrow.startBinding,
|
|
176
153
|
endBinding: 'endBinding' in change ? change.endBinding : shape.arrow.endBinding
|
|
177
154
|
};
|
|
178
|
-
return
|
|
155
|
+
return {
|
|
156
|
+
...shape,
|
|
157
|
+
x: geometry.box.x,
|
|
158
|
+
y: geometry.box.y,
|
|
159
|
+
width: geometry.box.width,
|
|
160
|
+
height: geometry.box.height,
|
|
161
|
+
rotation: 0,
|
|
162
|
+
strokeWidth,
|
|
163
|
+
d: serializePathData(geometry.commands),
|
|
164
|
+
arrow: withBindings(geometry.spec, ties)
|
|
165
|
+
};
|
|
179
166
|
}
|
|
180
167
|
/**
|
|
181
168
|
* The arrow after the board around it was changed by a mapping of the world (stretched, mirrored, turned): its ends and the middle of
|
|
182
169
|
* its arc go where the mapping sends them, and the bend is whatever puts the arc through those three points.
|
|
183
170
|
*/
|
|
184
171
|
export function transformArrow(shape, mapPoint) {
|
|
185
|
-
|
|
172
|
+
const { start, end } = arrowPointsInWorld(shape);
|
|
186
173
|
// The middle the arrow was drawn with, even when it was too small to show: a straight arrow stays straight.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
174
|
+
const middle = arrowMiddle(start, end, shape.arrow.bend);
|
|
175
|
+
const mappedStart = mapPoint(start);
|
|
176
|
+
const mappedEnd = mapPoint(end);
|
|
177
|
+
const mappedMiddle = mapPoint(middle);
|
|
191
178
|
return reshapeArrow(shape, { start: mappedStart, end: mappedEnd, bend: bendTowards(mappedStart, mappedEnd, mappedMiddle) });
|
|
192
179
|
}
|
|
193
180
|
/**
|
|
@@ -195,9 +182,9 @@ export function transformArrow(shape, mapPoint) {
|
|
|
195
182
|
* tip (the shaft, then two wings, each its own sub-path). Null for a path that is not that.
|
|
196
183
|
*/
|
|
197
184
|
export function arrowPointsOfLegacyPath(commands) {
|
|
198
|
-
|
|
185
|
+
const moves = commands.filter((command) => command[0] === 'M');
|
|
199
186
|
if (moves.length < 2)
|
|
200
187
|
return null;
|
|
201
|
-
|
|
188
|
+
const [first, second] = moves;
|
|
202
189
|
return { start: { x: first[1], y: first[2] }, end: { x: second[1], y: second[2] } };
|
|
203
190
|
}
|