@widgetic/canvas 0.5.41 → 0.5.43

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.
Files changed (131) hide show
  1. package/README.md +1 -0
  2. package/dist/canvas/DomCanvas.svelte +49 -20
  3. package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
  4. package/dist/canvas/autosaveScheduler.js +37 -89
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +7 -19
  8. package/dist/canvas/chromeLayout.d.ts +14 -3
  9. package/dist/canvas/chromeLayout.js +30 -20
  10. package/dist/canvas/eventScope.js +10 -14
  11. package/dist/canvas/host/CanvasHost.d.ts +47 -5
  12. package/dist/canvas/host/CanvasHost.js +1481 -1566
  13. package/dist/canvas/host/CanvasHostApi.js +4 -19
  14. package/dist/canvas/host/browserServices.js +65 -116
  15. package/dist/canvas/host/conversion.js +82 -170
  16. package/dist/canvas/host/hostObject.js +7 -7
  17. package/dist/canvas/host/nearCards.d.ts +33 -0
  18. package/dist/canvas/host/nearCards.js +78 -0
  19. package/dist/canvas/host/pageEvents.d.ts +16 -4
  20. package/dist/canvas/host/pageEvents.js +17 -8
  21. package/dist/canvas/host/pictureSaves.d.ts +33 -0
  22. package/dist/canvas/host/pictureSaves.js +42 -0
  23. package/dist/canvas/host/screenRects.d.ts +5 -0
  24. package/dist/canvas/host/screenRects.js +28 -31
  25. package/dist/canvas/host/storedPictures.d.ts +88 -0
  26. package/dist/canvas/host/storedPictures.js +288 -0
  27. package/dist/canvas/host/strokeSnap.js +88 -143
  28. package/dist/canvas/index.d.ts +1 -1
  29. package/dist/canvas/index.js +1 -1
  30. package/dist/canvas/openMarks.js +2 -2
  31. package/dist/canvas/outsideClickDeselect.js +6 -7
  32. package/dist/canvas/panZoomPosition.js +2 -2
  33. package/dist/canvas/preferredTextFont.js +13 -25
  34. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  35. package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
  36. package/dist/canvas/shapes/shapeImageStore.js +10 -3
  37. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  38. package/dist/canvas/toolbarPosition.d.ts +2 -2
  39. package/dist/canvas/toolbarPosition.js +4 -4
  40. package/dist/canvas/ui/SelectionPanel.svelte +28 -5
  41. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
  42. package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
  43. package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
  44. package/dist/canvas/ui/ToolButton.svelte +8 -2
  45. package/dist/canvas/ui/colorModel.js +21 -32
  46. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  47. package/dist/canvas/ui/floatingCard.d.ts +2 -2
  48. package/dist/canvas/ui/floatingCard.js +20 -20
  49. package/dist/canvas/ui/floatingLayer.d.ts +13 -2
  50. package/dist/canvas/ui/floatingLayer.js +18 -7
  51. package/dist/canvas/ui/keyHints.js +9 -11
  52. package/dist/canvas/ui/popoverSide.js +2 -3
  53. package/dist/canvas/ui/selectionTraits.js +34 -40
  54. package/dist/canvas/view/CanvasStage.svelte +101 -67
  55. package/dist/canvas/view/LeftToRightScope.svelte +21 -0
  56. package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
  57. package/dist/canvas/view/ObjectView.svelte +15 -10
  58. package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
  59. package/dist/canvas/view/erasingMarks.js +7 -7
  60. package/dist/canvas/view/geometry.js +71 -90
  61. package/dist/canvas/view/liftedScene.d.ts +31 -0
  62. package/dist/canvas/view/liftedScene.js +146 -0
  63. package/dist/canvas/view/mountedScene.d.ts +71 -0
  64. package/dist/canvas/view/mountedScene.js +363 -0
  65. package/dist/components/preferenceStorage.js +2 -2
  66. package/dist/engine/EngineCore.d.ts +15 -1
  67. package/dist/engine/EngineCore.js +724 -797
  68. package/dist/engine/codec/canvasDocument.d.ts +5 -0
  69. package/dist/engine/codec/canvasDocument.js +212 -149
  70. package/dist/engine/codec/hostReadableKeys.js +1 -1
  71. package/dist/engine/core/arrange.js +26 -38
  72. package/dist/engine/core/arrow.js +76 -89
  73. package/dist/engine/core/arrowBinding.js +98 -116
  74. package/dist/engine/core/arrowBindingRecords.js +23 -38
  75. package/dist/engine/core/brush.js +67 -94
  76. package/dist/engine/core/defaults.js +90 -51
  77. package/dist/engine/core/freehand.js +147 -163
  78. package/dist/engine/core/geometry.js +47 -54
  79. package/dist/engine/core/history.d.ts +6 -0
  80. package/dist/engine/core/history.js +49 -50
  81. package/dist/engine/core/hitTest.js +68 -81
  82. package/dist/engine/core/matrix.js +18 -20
  83. package/dist/engine/core/pathData.js +183 -210
  84. package/dist/engine/core/rotationReset.js +5 -6
  85. package/dist/engine/core/scene.d.ts +10 -0
  86. package/dist/engine/core/scene.js +153 -187
  87. package/dist/engine/core/scribble.js +59 -84
  88. package/dist/engine/core/shapePaths.js +12 -15
  89. package/dist/engine/core/shapeTools.js +72 -63
  90. package/dist/engine/core/snapping.js +65 -117
  91. package/dist/engine/core/style.js +31 -64
  92. package/dist/engine/core/transform.js +83 -94
  93. package/dist/engine/core/types.d.ts +8 -2
  94. package/dist/engine/core/types.js +4 -4
  95. package/dist/engine/core/viewport.js +23 -36
  96. package/dist/engine/input/PointerController.js +467 -474
  97. package/dist/engine/input/arrowHandles.js +12 -12
  98. package/dist/engine/input/gestures.js +265 -309
  99. package/dist/engine/input/hoverCursor.js +1 -1
  100. package/dist/engine/input/keyboard.js +27 -30
  101. package/dist/engine/input/selectionHandles.js +45 -50
  102. package/dist/engine/input/types.js +1 -1
  103. package/dist/engine/render/rasterize.js +86 -158
  104. package/dist/engine/state.d.ts +20 -0
  105. package/dist/engine/state.js +5 -15
  106. package/dist/engine/text/layoutText.js +43 -62
  107. package/dist/engine/text/textMetrics.js +8 -10
  108. package/dist/engine/widgets.js +101 -137
  109. package/dist/fonts/interFont.d.ts +10 -1
  110. package/dist/fonts/interFont.js +47 -75
  111. package/dist/fonts/workspaceFonts.js +32 -90
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.d.ts +3 -3
  114. package/dist/i18n/language.js +4 -4
  115. package/dist/i18n/messages.d.ts +8 -1
  116. package/dist/i18n/messages.js +10 -2
  117. package/dist/i18n/shortcuts.js +14 -14
  118. package/dist/index.d.ts +1 -1
  119. package/dist/index.js +1 -1
  120. package/dist/settings/workspaceToolSettings.js +32 -48
  121. package/dist/tools/components/catalog.js +64 -74
  122. package/dist/tools/components/grouping.js +6 -28
  123. package/dist/tools/definitions.js +5 -5
  124. package/dist/tools/executors.js +105 -141
  125. package/dist/tools/hostAdapter.js +11 -13
  126. package/dist/tools/sceneSummary.js +43 -57
  127. package/dist/tools/sketchIntent.js +13 -21
  128. package/dist/tools/types.js +1 -1
  129. package/package.json +1 -1
  130. package/dist/canvas/ui/SelectorBar.svelte +0 -84
  131. package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
@@ -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
- var units = [];
19
- for (var _i = 0, _a = normalizeSelection(scene, ids); _i < _a.length; _i++) {
20
- var id = _a[_i];
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: id, bounds: bounds });
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
- var units = unitsOf(scene, ids);
22
+ const units = unitsOf(scene, ids);
33
23
  if (units.length < 2)
34
24
  return scene;
35
- var left = Math.min.apply(Math, units.map(function (unit) { return unit.bounds.x; }));
36
- var right = Math.max.apply(Math, units.map(function (unit) { return unit.bounds.x + unit.bounds.width; }));
37
- var top = Math.min.apply(Math, units.map(function (unit) { return unit.bounds.y; }));
38
- var bottom = Math.max.apply(Math, units.map(function (unit) { return unit.bounds.y + unit.bounds.height; }));
39
- var next = scene;
40
- for (var _i = 0, units_1 = units; _i < units_1.length; _i++) {
41
- var unit = units_1[_i];
42
- var deltaX = 0;
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
- var units = unitsOf(scene, ids);
62
+ const units = unitsOf(scene, ids);
74
63
  if (units.length < 3)
75
64
  return scene;
76
- var start = function (unit) { return (axis === 'horizontal' ? unit.bounds.x : unit.bounds.y); };
77
- var size = function (unit) { return (axis === 'horizontal' ? unit.bounds.width : unit.bounds.height); };
78
- var ordered = __spreadArray([], units, true).sort(function (first, second) { return start(first) - start(second); });
79
- var first = ordered[0];
80
- var last = ordered[ordered.length - 1];
81
- var span = start(last) + size(last) - start(first);
82
- var occupied = ordered.reduce(function (total, unit) { return total + size(unit); }, 0);
83
- var gap = (span - occupied) / (ordered.length - 1);
84
- var next = scene;
85
- var cursor = start(first) + size(first) + gap;
86
- for (var _i = 0, _a = ordered.slice(1, -1); _i < _a.length; _i++) {
87
- var unit = _a[_i];
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 var ARROW_HEAD_ANGLE = Math.PI / 6;
22
+ export const ARROW_HEAD_ANGLE = Math.PI / 6;
43
23
  /** The head is this fraction of the length of the arrow ... */
44
- export var ARROW_HEAD_LENGTH_FRACTION = 1 / 5;
24
+ export const ARROW_HEAD_LENGTH_FRACTION = 1 / 5;
45
25
  /** ... but at least this many widths of the line ... */
46
- export var ARROW_HEAD_MIN_WIDTHS = 1;
26
+ export const ARROW_HEAD_MIN_WIDTHS = 1;
47
27
  /** ... and at most this many. */
48
- export var ARROW_HEAD_MAX_WIDTHS = 3;
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 var MIN_ARROW_BEND = 8;
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 var MAX_ARROW_BEND_PER_LENGTH = 2;
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
- var MIN_HEAD_LINE_WIDTH = 1;
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
- var width = Math.max(strokeWidth, MIN_HEAD_LINE_WIDTH);
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
- var cosine = Math.cos(radians);
73
- var sine = Math.sin(radians);
74
- var offsetX = point.x - center.x;
75
- var offsetY = point.y - center.y;
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
- var deltaX = end.x - start.x;
81
- var deltaY = end.y - start.y;
82
- var length = Math.hypot(deltaX, deltaY);
83
- var unit = length > 1e-9 ? { x: deltaX / length, y: deltaY / length } : { x: 1, y: 0 };
84
- return { length: length, unit: unit, normal: { x: -unit.y, y: unit.x } };
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
- var normal = directionBetween(start, end).normal;
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
- var normal = directionBetween(start, end).normal;
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
- var _a, _b;
105
- var _c = directionBetween(start, end), length = _c.length, unit = _c.unit, normal = _c.normal;
106
- var bent = drawnBend(bend, length);
107
- var middle = { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };
108
- var shaft;
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
- var pointBack;
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 = function (headLength) { return ({ x: end.x - unit.x * headLength, y: end.y - unit.y * headLength }); };
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
- var half = length / 2;
122
- var sagitta = Math.abs(bent);
123
- var radius_1 = (half * half + sagitta * sagitta) / (2 * sagitta);
124
- var centerAlongNormal = bent - Math.sign(bent) * radius_1;
125
- var center_1 = { x: middle.x + normal.x * centerAlongNormal, y: middle.y + normal.y * centerAlongNormal };
126
- var largeArc = sagitta > half ? 1 : 0;
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
- var sweep = bent > 0 ? 0 : 1;
129
- shaft = parsePathData("M ".concat(start.x, " ").concat(start.y, " A ").concat(radius_1, " ").concat(radius_1, " 0 ").concat(largeArc, " ").concat(sweep, " ").concat(end.x, " ").concat(end.y));
130
- bodyLength = 2 * radius_1 * Math.atan2(half, radius_1 - sagitta);
131
- var travel_1 = bent > 0 ? -1 : 1;
132
- var tipAngle_1 = Math.atan2(end.y - center_1.y, end.x - center_1.x);
133
- pointBack = function (headLength) {
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
- var turn = 2 * Math.asin(Math.min(1, headLength / (2 * radius_1)));
136
- var angle = tipAngle_1 - travel_1 * turn;
137
- return { x: center_1.x + radius_1 * Math.cos(angle), y: center_1.y + radius_1 * Math.sin(angle) };
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
- var headLength = arrowHeadLength(bodyLength, strokeWidth);
141
- var back = pointBack(headLength);
142
- var leftWing = rotateAbout(back, end, ARROW_HEAD_ANGLE);
143
- var rightWing = rotateAbout(back, end, -ARROW_HEAD_ANGLE);
144
- var world = __spreadArray(__spreadArray([], shaft, true), [['M', leftWing.x, leftWing.y], ['L', end.x, end.y], ['L', rightWing.x, rightWing.y]], false);
145
- var bounds = pathBounds(world);
146
- var origin = bounds ? { x: bounds.x, y: bounds.y } : { x: start.x, y: start.y };
147
- var box = { x: origin.x, y: origin.y, width: Math.max((_a = bounds === null || bounds === void 0 ? void 0 : bounds.width) !== null && _a !== void 0 ? _a : 0, 1), height: Math.max((_b = bounds === null || bounds === void 0 ? void 0 : bounds.height) !== null && _b !== void 0 ? _b : 0, 1) };
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: 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
- var start = { x: shape.x + shape.arrow.start.x, y: shape.y + shape.arrow.start.y };
161
- var end = { x: shape.x + shape.arrow.end.x, y: shape.y + shape.arrow.end.y };
162
- return { start: start, end: end, middle: arrowMiddle(start, end, shape.arrow.bend) };
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
- var _a, _b, _c, _d;
170
- if (change === void 0) { change = {}; }
171
- var current = arrowPointsInWorld(shape);
172
- var strokeWidth = (_a = change.strokeWidth) !== null && _a !== void 0 ? _a : shape.strokeWidth;
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 __assign(__assign({}, shape), { x: geometry.box.x, y: geometry.box.y, width: geometry.box.width, height: geometry.box.height, rotation: 0, strokeWidth: strokeWidth, d: serializePathData(geometry.commands), arrow: withBindings(geometry.spec, ties) });
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
- var _a = arrowPointsInWorld(shape), start = _a.start, end = _a.end;
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
- var middle = arrowMiddle(start, end, shape.arrow.bend);
188
- var mappedStart = mapPoint(start);
189
- var mappedEnd = mapPoint(end);
190
- var mappedMiddle = mapPoint(middle);
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
- var moves = commands.filter(function (command) { return command[0] === 'M'; });
185
+ const moves = commands.filter((command) => command[0] === 'M');
199
186
  if (moves.length < 2)
200
187
  return null;
201
- var first = moves[0], second = moves[1];
188
+ const [first, second] = moves;
202
189
  return { start: { x: first[1], y: first[2] }, end: { x: second[1], y: second[2] } };
203
190
  }