@widgetic/canvas 0.5.45 → 0.5.47
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/README.md +3 -2
- package/dist/canvas/DomCanvas.svelte +1 -2
- 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 +19 -21
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +6 -5
- package/dist/canvas/host/CanvasHost.js +1664 -1861
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/boardFiles.js +35 -51
- package/dist/canvas/host/browserServices.js +108 -196
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +18 -21
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pauseCollector.d.ts +18 -0
- package/dist/canvas/host/pauseCollector.js +45 -0
- package/dist/canvas/host/pictureSaves.js +9 -11
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.js +149 -243
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- 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 +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
- package/dist/canvas/ui/CanvasHint.svelte +10 -9
- package/dist/canvas/ui/SelectionPanel.svelte +14 -12
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
- package/dist/canvas/ui/ShapesMenu.svelte +6 -4
- package/dist/canvas/ui/ToolButton.svelte +7 -6
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +28 -8
- package/dist/canvas/ui/floatingCard.js +48 -28
- 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.d.ts +8 -4
- package/dist/canvas/ui/selectionTraits.js +44 -58
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/SelectionOverlay.svelte +2 -2
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +72 -91
- package/dist/canvas/view/liftedScene.js +24 -36
- package/dist/canvas/view/mountedScene.js +76 -79
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/input-controls/ColorIC.svelte +1 -1
- package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +42 -10
- package/dist/engine/EngineCore.js +843 -916
- package/dist/engine/codec/canvasDocument.js +192 -155
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +79 -92
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.d.ts +24 -0
- package/dist/engine/core/brush.js +223 -103
- package/dist/engine/core/cameraMove.js +39 -51
- package/dist/engine/core/defaults.js +92 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +38 -55
- 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 +160 -224
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.d.ts +23 -18
- package/dist/engine/core/shapeTools.js +104 -67
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.d.ts +18 -2
- package/dist/engine/core/style.js +79 -80
- package/dist/engine/core/styleMemory.d.ts +88 -0
- package/dist/engine/core/styleMemory.js +189 -0
- package/dist/engine/core/transform.js +84 -95
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +513 -526
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +8 -3
- package/dist/engine/input/gestures.js +378 -346
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +42 -41
- 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 +6 -17
- 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 +30 -83
- package/dist/fonts/workspaceFonts.js +33 -92
- 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/index.d.ts +1 -1
- package/dist/poster/boardPlacement.d.ts +4 -1
- package/dist/poster/boardPlacement.js +34 -33
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedStyles.d.ts +22 -0
- package/dist/settings/rememberedStyles.js +47 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +25 -0
- package/dist/settings/workspaceToolSettings.js +38 -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 +137 -169
- package/dist/tools/hostAdapter.js +10 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/styleArguments.js +19 -21
- package/dist/tools/types.js +1 -1
- package/package.json +5 -5
|
@@ -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
|
}
|
|
@@ -17,45 +17,25 @@
|
|
|
17
17
|
* 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
|
|
18
18
|
* `ArrowSpec` in the same coordinates.
|
|
19
19
|
*/
|
|
20
|
-
var __assign = (this && this.__assign) || function () {
|
|
21
|
-
__assign = Object.assign || function(t) {
|
|
22
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
-
s = arguments[i];
|
|
24
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
25
|
-
t[p] = s[p];
|
|
26
|
-
}
|
|
27
|
-
return t;
|
|
28
|
-
};
|
|
29
|
-
return __assign.apply(this, arguments);
|
|
30
|
-
};
|
|
31
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
32
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
33
|
-
if (ar || !(i in from)) {
|
|
34
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
35
|
-
ar[i] = from[i];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
39
|
-
};
|
|
40
20
|
import { withBindings } from './arrowBindingRecords.js';
|
|
41
21
|
import { clampNumber } from './geometry.js';
|
|
42
22
|
import { parsePathData, pathBounds, serializePathData, translatePathCommands } from './pathData.js';
|
|
43
23
|
/** The wings of the head open this far either side of the shaft (30 degrees). */
|
|
44
|
-
export
|
|
24
|
+
export const ARROW_HEAD_ANGLE = Math.PI / 6;
|
|
45
25
|
/** The head is this fraction of the length of the arrow ... */
|
|
46
|
-
export
|
|
26
|
+
export const ARROW_HEAD_LENGTH_FRACTION = 1 / 5;
|
|
47
27
|
/** ... but at least this long (world units) ... */
|
|
48
|
-
export
|
|
28
|
+
export const ARROW_HEAD_MIN_LENGTH = 3;
|
|
49
29
|
/** ... and at most this long: the head of the line the Arrow tool draws with. */
|
|
50
|
-
export
|
|
30
|
+
export const ARROW_HEAD_MAX_LENGTH = 9;
|
|
51
31
|
/** The width of that line (the Arrow tool's own, `ARROW_PAINT`): a line this thin or thinner has that head, a thicker one has it grown. */
|
|
52
|
-
export
|
|
32
|
+
export const ARROW_HEAD_REFERENCE_WIDTH = 3;
|
|
53
33
|
/** A head grown for a thick line is at most this fraction of the arrow, so that a short, thick arrow is not all head. */
|
|
54
|
-
export
|
|
34
|
+
export const ARROW_HEAD_GROWTH_LIMIT_FRACTION = 1 / 2;
|
|
55
35
|
/** A bend smaller than this (world units) is not a bend: the arrow is straight. */
|
|
56
|
-
export
|
|
36
|
+
export const MIN_ARROW_BEND = 8;
|
|
57
37
|
/** An arrow bends by at most this many times its own length (a little under a full circle). */
|
|
58
|
-
export
|
|
38
|
+
export const MAX_ARROW_BEND_PER_LENGTH = 2;
|
|
59
39
|
/** Whether a shape is an arrow made by the Arrow tool, with the points it is drawn from. */
|
|
60
40
|
export function isArrow(shape) {
|
|
61
41
|
return shape.type === 'path' && shape.arrow !== null;
|
|
@@ -73,31 +53,31 @@ export function drawnBend(bend, length) {
|
|
|
73
53
|
*/
|
|
74
54
|
export function arrowHeadLength(bodyLength, strokeWidth) {
|
|
75
55
|
// A width that is not a number is taken for the Arrow tool's own, which asks the head for no growth.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
56
|
+
const lineWidth = Number.isFinite(strokeWidth) ? strokeWidth : ARROW_HEAD_REFERENCE_WIDTH;
|
|
57
|
+
const lengthFromArrow = clampNumber(bodyLength * ARROW_HEAD_LENGTH_FRACTION, ARROW_HEAD_MIN_LENGTH, ARROW_HEAD_MAX_LENGTH);
|
|
58
|
+
const lengthGrownForLine = lengthFromArrow * Math.max(1, lineWidth / ARROW_HEAD_REFERENCE_WIDTH);
|
|
79
59
|
// The growth stops at half the arrow, and never takes the head below the one the length gives (a very short arrow is all head).
|
|
80
60
|
return Math.max(lengthFromArrow, Math.min(lengthGrownForLine, bodyLength * ARROW_HEAD_GROWTH_LIMIT_FRACTION));
|
|
81
61
|
}
|
|
82
62
|
/** A point turned about another by an angle (radians, clockwise on screen). */
|
|
83
63
|
function rotateAbout(point, center, radians) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
64
|
+
const cosine = Math.cos(radians);
|
|
65
|
+
const sine = Math.sin(radians);
|
|
66
|
+
const offsetX = point.x - center.x;
|
|
67
|
+
const offsetY = point.y - center.y;
|
|
88
68
|
return { x: center.x + offsetX * cosine - offsetY * sine, y: center.y + offsetX * sine + offsetY * cosine };
|
|
89
69
|
}
|
|
90
70
|
/** 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. */
|
|
91
71
|
function directionBetween(start, end) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return { length
|
|
72
|
+
const deltaX = end.x - start.x;
|
|
73
|
+
const deltaY = end.y - start.y;
|
|
74
|
+
const length = Math.hypot(deltaX, deltaY);
|
|
75
|
+
const unit = length > 1e-9 ? { x: deltaX / length, y: deltaY / length } : { x: 1, y: 0 };
|
|
76
|
+
return { length, unit, normal: { x: -unit.y, y: unit.x } };
|
|
97
77
|
}
|
|
98
78
|
/** The middle of the arrow: the middle of the line between its ends, pushed `bend` to the right of the way it points. */
|
|
99
79
|
export function arrowMiddle(start, end, bend) {
|
|
100
|
-
|
|
80
|
+
const { normal } = directionBetween(start, end);
|
|
101
81
|
return { x: (start.x + end.x) / 2 + normal.x * bend, y: (start.y + end.y) / 2 + normal.y * bend };
|
|
102
82
|
}
|
|
103
83
|
/**
|
|
@@ -105,7 +85,7 @@ export function arrowMiddle(start, end, bend) {
|
|
|
105
85
|
* measured along the normal to it (so the middle follows the pointer without sliding along the arrow).
|
|
106
86
|
*/
|
|
107
87
|
export function bendTowards(start, end, point) {
|
|
108
|
-
|
|
88
|
+
const { normal } = directionBetween(start, end);
|
|
109
89
|
return (point.x - (start.x + end.x) / 2) * normal.x + (point.y - (start.y + end.y) / 2) * normal.y;
|
|
110
90
|
}
|
|
111
91
|
/**
|
|
@@ -113,53 +93,52 @@ export function bendTowards(start, end, point) {
|
|
|
113
93
|
* come back in the frame the points were given in, the path moved to the corner of the box that holds it.
|
|
114
94
|
*/
|
|
115
95
|
export function buildArrow(start, end, bend, strokeWidth) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var bodyLength = length;
|
|
96
|
+
const { length, unit, normal } = directionBetween(start, end);
|
|
97
|
+
const bent = drawnBend(bend, length);
|
|
98
|
+
const middle = { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };
|
|
99
|
+
let shaft;
|
|
100
|
+
let bodyLength = length;
|
|
122
101
|
// The point of the shaft one head-length back from the tip: the head is the shaft's own direction turned either way.
|
|
123
|
-
|
|
102
|
+
let pointBack;
|
|
124
103
|
if (bent === 0) {
|
|
125
104
|
shaft = [
|
|
126
105
|
['M', start.x, start.y],
|
|
127
106
|
['L', end.x, end.y]
|
|
128
107
|
];
|
|
129
|
-
pointBack =
|
|
108
|
+
pointBack = (headLength) => ({ x: end.x - unit.x * headLength, y: end.y - unit.y * headLength });
|
|
130
109
|
}
|
|
131
110
|
else {
|
|
132
111
|
// The circle through the start, the end and the middle: the arc between the ends that goes by the middle.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
112
|
+
const half = length / 2;
|
|
113
|
+
const sagitta = Math.abs(bent);
|
|
114
|
+
const radius = (half * half + sagitta * sagitta) / (2 * sagitta);
|
|
115
|
+
const centerAlongNormal = bent - Math.sign(bent) * radius;
|
|
116
|
+
const center = { x: middle.x + normal.x * centerAlongNormal, y: middle.y + normal.y * centerAlongNormal };
|
|
117
|
+
const largeArc = sagitta > half ? 1 : 0;
|
|
139
118
|
// To the right of the way it points (a positive bend) the arc runs against the clock on the screen.
|
|
140
|
-
|
|
141
|
-
shaft = parsePathData(
|
|
142
|
-
bodyLength = 2 *
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
pointBack =
|
|
119
|
+
const sweep = bent > 0 ? 0 : 1;
|
|
120
|
+
shaft = parsePathData(`M ${start.x} ${start.y} A ${radius} ${radius} 0 ${largeArc} ${sweep} ${end.x} ${end.y}`);
|
|
121
|
+
bodyLength = 2 * radius * Math.atan2(half, radius - sagitta);
|
|
122
|
+
const travel = bent > 0 ? -1 : 1;
|
|
123
|
+
const tipAngle = Math.atan2(end.y - center.y, end.x - center.x);
|
|
124
|
+
pointBack = (headLength) => {
|
|
146
125
|
// The point of the arc that is `headLength` from the tip as the crow flies, a little way back along the arc.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return { x:
|
|
126
|
+
const turn = 2 * Math.asin(Math.min(1, headLength / (2 * radius)));
|
|
127
|
+
const angle = tipAngle - travel * turn;
|
|
128
|
+
return { x: center.x + radius * Math.cos(angle), y: center.y + radius * Math.sin(angle) };
|
|
150
129
|
};
|
|
151
130
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
131
|
+
const headLength = arrowHeadLength(bodyLength, strokeWidth);
|
|
132
|
+
const back = pointBack(headLength);
|
|
133
|
+
const leftWing = rotateAbout(back, end, ARROW_HEAD_ANGLE);
|
|
134
|
+
const rightWing = rotateAbout(back, end, -ARROW_HEAD_ANGLE);
|
|
135
|
+
const world = [...shaft, ['M', leftWing.x, leftWing.y], ['L', end.x, end.y], ['L', rightWing.x, rightWing.y]];
|
|
136
|
+
const bounds = pathBounds(world);
|
|
137
|
+
const origin = bounds ? { x: bounds.x, y: bounds.y } : { x: start.x, y: start.y };
|
|
138
|
+
const box = { x: origin.x, y: origin.y, width: Math.max(bounds?.width ?? 0, 1), height: Math.max(bounds?.height ?? 0, 1) };
|
|
160
139
|
return {
|
|
161
140
|
commands: translatePathCommands(world, -origin.x, -origin.y),
|
|
162
|
-
box
|
|
141
|
+
box,
|
|
163
142
|
spec: {
|
|
164
143
|
start: { x: start.x - origin.x, y: start.y - origin.y },
|
|
165
144
|
end: { x: end.x - origin.x, y: end.y - origin.y },
|
|
@@ -169,37 +148,45 @@ export function buildArrow(start, end, bend, strokeWidth) {
|
|
|
169
148
|
}
|
|
170
149
|
/** 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). */
|
|
171
150
|
export function arrowPointsInWorld(shape) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return { start
|
|
151
|
+
const start = { x: shape.x + shape.arrow.start.x, y: shape.y + shape.arrow.start.y };
|
|
152
|
+
const end = { x: shape.x + shape.arrow.end.x, y: shape.y + shape.arrow.end.y };
|
|
153
|
+
return { start, end, middle: arrowMiddle(start, end, shape.arrow.bend) };
|
|
175
154
|
}
|
|
176
155
|
/**
|
|
177
156
|
* 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
|
|
178
157
|
* as it was unless the change says otherwise (the points do not move because a tie says so here: `arrowBinding.ts` places them).
|
|
179
158
|
*/
|
|
180
|
-
export function reshapeArrow(shape, change) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
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);
|
|
186
|
-
var ties = {
|
|
159
|
+
export function reshapeArrow(shape, change = {}) {
|
|
160
|
+
const current = arrowPointsInWorld(shape);
|
|
161
|
+
const strokeWidth = change.strokeWidth ?? shape.strokeWidth;
|
|
162
|
+
const geometry = buildArrow(change.start ?? current.start, change.end ?? current.end, change.bend ?? shape.arrow.bend, strokeWidth);
|
|
163
|
+
const ties = {
|
|
187
164
|
startBinding: 'startBinding' in change ? change.startBinding : shape.arrow.startBinding,
|
|
188
165
|
endBinding: 'endBinding' in change ? change.endBinding : shape.arrow.endBinding
|
|
189
166
|
};
|
|
190
|
-
return
|
|
167
|
+
return {
|
|
168
|
+
...shape,
|
|
169
|
+
x: geometry.box.x,
|
|
170
|
+
y: geometry.box.y,
|
|
171
|
+
width: geometry.box.width,
|
|
172
|
+
height: geometry.box.height,
|
|
173
|
+
rotation: 0,
|
|
174
|
+
strokeWidth,
|
|
175
|
+
d: serializePathData(geometry.commands),
|
|
176
|
+
arrow: withBindings(geometry.spec, ties)
|
|
177
|
+
};
|
|
191
178
|
}
|
|
192
179
|
/**
|
|
193
180
|
* The arrow after the board around it was changed by a mapping of the world (stretched, mirrored, turned): its ends and the middle of
|
|
194
181
|
* its arc go where the mapping sends them, and the bend is whatever puts the arc through those three points.
|
|
195
182
|
*/
|
|
196
183
|
export function transformArrow(shape, mapPoint) {
|
|
197
|
-
|
|
184
|
+
const { start, end } = arrowPointsInWorld(shape);
|
|
198
185
|
// The middle the arrow was drawn with, even when it was too small to show: a straight arrow stays straight.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
186
|
+
const middle = arrowMiddle(start, end, shape.arrow.bend);
|
|
187
|
+
const mappedStart = mapPoint(start);
|
|
188
|
+
const mappedEnd = mapPoint(end);
|
|
189
|
+
const mappedMiddle = mapPoint(middle);
|
|
203
190
|
return reshapeArrow(shape, { start: mappedStart, end: mappedEnd, bend: bendTowards(mappedStart, mappedEnd, mappedMiddle) });
|
|
204
191
|
}
|
|
205
192
|
/**
|
|
@@ -207,9 +194,9 @@ export function transformArrow(shape, mapPoint) {
|
|
|
207
194
|
* tip (the shaft, then two wings, each its own sub-path). Null for a path that is not that.
|
|
208
195
|
*/
|
|
209
196
|
export function arrowPointsOfLegacyPath(commands) {
|
|
210
|
-
|
|
197
|
+
const moves = commands.filter((command) => command[0] === 'M');
|
|
211
198
|
if (moves.length < 2)
|
|
212
199
|
return null;
|
|
213
|
-
|
|
200
|
+
const [first, second] = moves;
|
|
214
201
|
return { start: { x: first[1], y: first[2] }, end: { x: second[1], y: second[2] } };
|
|
215
202
|
}
|