@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.
Files changed (85) hide show
  1. package/dist/canvas/autosaveScheduler.js +37 -89
  2. package/dist/canvas/boardFrame.js +1 -1
  3. package/dist/canvas/boardSurface.js +1 -1
  4. package/dist/canvas/canvasLogger.js +7 -19
  5. package/dist/canvas/chromeLayout.js +17 -18
  6. package/dist/canvas/eventScope.js +10 -14
  7. package/dist/canvas/host/CanvasHost.js +1286 -1536
  8. package/dist/canvas/host/CanvasHostApi.js +4 -19
  9. package/dist/canvas/host/browserServices.js +65 -116
  10. package/dist/canvas/host/conversion.js +82 -170
  11. package/dist/canvas/host/hostObject.js +7 -7
  12. package/dist/canvas/host/pageEvents.js +4 -4
  13. package/dist/canvas/host/screenRects.js +28 -31
  14. package/dist/canvas/host/strokeSnap.js +88 -143
  15. package/dist/canvas/openMarks.js +2 -2
  16. package/dist/canvas/outsideClickDeselect.js +6 -7
  17. package/dist/canvas/panZoomPosition.js +2 -2
  18. package/dist/canvas/preferredTextFont.js +13 -25
  19. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  20. package/dist/canvas/shapes/shapeImageStore.js +3 -3
  21. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  22. package/dist/canvas/toolbarPosition.js +2 -2
  23. package/dist/canvas/ui/colorModel.js +21 -32
  24. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  25. package/dist/canvas/ui/floatingCard.js +18 -18
  26. package/dist/canvas/ui/floatingLayer.js +5 -6
  27. package/dist/canvas/ui/keyHints.js +9 -11
  28. package/dist/canvas/ui/popoverSide.js +2 -3
  29. package/dist/canvas/ui/selectionTraits.js +34 -40
  30. package/dist/canvas/view/erasingMarks.js +7 -7
  31. package/dist/canvas/view/geometry.js +71 -90
  32. package/dist/components/preferenceStorage.js +2 -2
  33. package/dist/engine/EngineCore.js +696 -795
  34. package/dist/engine/codec/canvasDocument.js +183 -147
  35. package/dist/engine/codec/hostReadableKeys.js +1 -1
  36. package/dist/engine/core/arrange.js +26 -38
  37. package/dist/engine/core/arrow.js +76 -89
  38. package/dist/engine/core/arrowBinding.js +98 -116
  39. package/dist/engine/core/arrowBindingRecords.js +23 -38
  40. package/dist/engine/core/brush.js +67 -94
  41. package/dist/engine/core/defaults.js +90 -51
  42. package/dist/engine/core/freehand.js +147 -163
  43. package/dist/engine/core/geometry.js +47 -54
  44. package/dist/engine/core/history.js +33 -50
  45. package/dist/engine/core/hitTest.js +68 -81
  46. package/dist/engine/core/matrix.js +18 -20
  47. package/dist/engine/core/pathData.js +183 -210
  48. package/dist/engine/core/rotationReset.js +5 -6
  49. package/dist/engine/core/scene.js +129 -187
  50. package/dist/engine/core/scribble.js +59 -84
  51. package/dist/engine/core/shapePaths.js +12 -15
  52. package/dist/engine/core/shapeTools.js +72 -63
  53. package/dist/engine/core/snapping.js +65 -117
  54. package/dist/engine/core/style.js +31 -64
  55. package/dist/engine/core/transform.js +83 -94
  56. package/dist/engine/core/types.js +4 -4
  57. package/dist/engine/core/viewport.js +23 -36
  58. package/dist/engine/input/PointerController.js +467 -474
  59. package/dist/engine/input/arrowHandles.js +12 -12
  60. package/dist/engine/input/gestures.js +262 -308
  61. package/dist/engine/input/hoverCursor.js +1 -1
  62. package/dist/engine/input/keyboard.js +27 -30
  63. package/dist/engine/input/selectionHandles.js +45 -50
  64. package/dist/engine/input/types.js +1 -1
  65. package/dist/engine/render/rasterize.js +86 -158
  66. package/dist/engine/state.js +4 -15
  67. package/dist/engine/text/layoutText.js +43 -62
  68. package/dist/engine/text/textMetrics.js +8 -10
  69. package/dist/engine/widgets.js +101 -137
  70. package/dist/fonts/interFont.js +17 -68
  71. package/dist/fonts/workspaceFonts.js +32 -90
  72. package/dist/i18n/labels.js +4 -4
  73. package/dist/i18n/language.js +4 -4
  74. package/dist/i18n/messages.js +1 -1
  75. package/dist/i18n/shortcuts.js +14 -14
  76. package/dist/settings/workspaceToolSettings.js +32 -48
  77. package/dist/tools/components/catalog.js +64 -74
  78. package/dist/tools/components/grouping.js +6 -28
  79. package/dist/tools/definitions.js +5 -5
  80. package/dist/tools/executors.js +105 -141
  81. package/dist/tools/hostAdapter.js +11 -13
  82. package/dist/tools/sceneSummary.js +43 -57
  83. package/dist/tools/sketchIntent.js +13 -21
  84. package/dist/tools/types.js +1 -1
  85. package/package.json +1 -1
@@ -4,26 +4,6 @@
4
4
  * A gesture changes the scene *transiently* on every move and the engine records one undo step when it ends,
5
5
  * so a drag of a hundred frames is one step. `cancel` puts the board back as it was before the press.
6
6
  */
7
- var __assign = (this && this.__assign) || function () {
8
- __assign = Object.assign || function(t) {
9
- for (var s, i = 1, n = arguments.length; i < n; i++) {
10
- s = arguments[i];
11
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
12
- t[p] = s[p];
13
- }
14
- return t;
15
- };
16
- return __assign.apply(this, arguments);
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
7
  import { arrowPointsInWorld, bendTowards, isArrow, reshapeArrow } from '../core/arrow.js';
28
8
  import { pickArrowBinding, positionBoundArrow } from '../core/arrowBinding.js';
29
9
  import { bindingOfEnd, releaseUnmovedEnds } from '../core/arrowBindingRecords.js';
@@ -40,122 +20,115 @@ import { CORNER_HANDLES, ROTATE_CURSOR, cursorForHandle, isCornerHandle } from '
40
20
  import { fitTextObject } from '../text/layoutText.js';
41
21
  import { cursorForTool } from '../EngineCore.js';
42
22
  /** A press that moves less than this (screen pixels) is still a click. */
43
- export var DRAG_THRESHOLD = 3;
23
+ export const DRAG_THRESHOLD = 3;
44
24
  /** How far the eraser reaches, in screen pixels. */
45
- export var ERASER_RADIUS = 8;
25
+ export const ERASER_RADIUS = 8;
46
26
  /** The step a rotation snaps to while Shift (or Ctrl, or Meta) is held, in degrees. */
47
- export var ROTATION_SNAP_DEGREES = 5;
27
+ export const ROTATION_SNAP_DEGREES = 5;
48
28
  /** When true, a text corner resize hides the pointer and draws an arrow on the corner. */
49
- export var ENABLE_TEXT_VIRTUAL_CURSOR = false;
29
+ export const ENABLE_TEXT_VIRTUAL_CURSOR = false;
50
30
  /** Objects farther than this from the screen (in screen pixels) are not snapped to. */
51
- var SNAP_TARGET_MARGIN = 400;
31
+ const SNAP_TARGET_MARGIN = 400;
52
32
  function worldOf(context, input) {
53
33
  return context.engine.toWorld({ x: input.x, y: input.y });
54
34
  }
55
35
  /** Puts changed shapes into the scene the gesture started from. */
56
36
  function withShapes(scene, shapes) {
57
- var byId = new Map();
58
- for (var _i = 0, shapes_1 = shapes; _i < shapes_1.length; _i++) {
59
- var shape = shapes_1[_i];
37
+ const byId = new Map();
38
+ for (const shape of shapes)
60
39
  byId.set(shape.id, shape);
61
- }
62
- return scene.map(function (object) { var _a; return (_a = byId.get(object.id)) !== null && _a !== void 0 ? _a : object; });
40
+ return scene.map((object) => byId.get(object.id) ?? object);
63
41
  }
64
42
  function fitAll(context, shapes) {
65
- var measure = context.engine.services.measureText;
66
- return shapes.map(function (shape) { return (shape.type === 'text' ? fitTextObject(shape, measure) : shape); });
43
+ const measure = context.engine.services.measureText;
44
+ return shapes.map((shape) => (shape.type === 'text' ? fitTextObject(shape, measure) : shape));
67
45
  }
68
46
  /** The unit (top-level object, or member of the entered group) that holds an object. */
69
47
  function unitIdOf(index, id, enteredGroupId) {
70
- var _a;
71
- var current = index.get(id);
72
- var seen = new Set();
48
+ let current = index.get(id);
49
+ const seen = new Set();
73
50
  while (current && current.parentId !== null && current.parentId !== enteredGroupId && !seen.has(current.id)) {
74
51
  seen.add(current.id);
75
52
  current = index.get(current.parentId);
76
53
  }
77
- return (_a = current === null || current === void 0 ? void 0 : current.id) !== null && _a !== void 0 ? _a : id;
54
+ return current?.id ?? id;
78
55
  }
79
56
  /** The boxes of the other units near the screen: what a moving selection snaps to. */
80
57
  function collectSnapTargets(context, movingIds) {
81
- var engine = context.engine;
82
- var state = engine.state;
83
- var index = engine.sceneIndex();
84
- var reach = inflateRect(engine.visibleRect(), SNAP_TARGET_MARGIN / state.viewport.zoom);
85
- var rectsByUnit = new Map();
86
- for (var _i = 0, _a = state.scene; _i < _a.length; _i++) {
87
- var object = _a[_i];
58
+ const { engine } = context;
59
+ const state = engine.state;
60
+ const index = engine.sceneIndex();
61
+ const reach = inflateRect(engine.visibleRect(), SNAP_TARGET_MARGIN / state.viewport.zoom);
62
+ const rectsByUnit = new Map();
63
+ for (const object of state.scene) {
88
64
  if (object.type === 'group' || state.pending[object.id])
89
65
  continue;
90
- var unitId = unitIdOf(index, object.id, state.enteredGroupId);
66
+ const unitId = unitIdOf(index, object.id, state.enteredGroupId);
91
67
  if (movingIds.has(unitId))
92
68
  continue;
93
- var bounds = shapeBounds(object);
94
- var list = rectsByUnit.get(unitId);
69
+ const bounds = shapeBounds(object);
70
+ const list = rectsByUnit.get(unitId);
95
71
  if (list)
96
72
  list.push(bounds);
97
73
  else
98
74
  rectsByUnit.set(unitId, [bounds]);
99
75
  }
100
- var targets = [];
101
- for (var _b = 0, _c = rectsByUnit.values(); _b < _c.length; _b++) {
102
- var rects = _c[_b];
103
- var union = unionRects(rects);
76
+ const targets = [];
77
+ for (const rects of rectsByUnit.values()) {
78
+ const union = unionRects(rects);
104
79
  if (union && rectsIntersect(union, reach))
105
80
  targets.push(union);
106
81
  }
107
82
  return targets;
108
83
  }
109
84
  /** Drags the selected units. Nothing moves until the pointer has gone `DRAG_THRESHOLD` pixels. */
110
- export function createMoveGesture(context, start, unitIds, options) {
111
- if (options === void 0) { options = {}; }
112
- var engine = context.engine;
113
- var startScene = engine.state.scene;
114
- var startWorld = worldOf(context, start);
115
- var moving = new Set(unitIds);
116
- var startBounds = boundsOfObjects(startScene, unitIds);
117
- var speed = new PointerSpeedTracker();
118
- var started = false;
119
- var duplicated = false;
120
- var targets = null;
85
+ export function createMoveGesture(context, start, unitIds, options = {}) {
86
+ const { engine } = context;
87
+ let startScene = engine.state.scene;
88
+ const startWorld = worldOf(context, start);
89
+ let moving = new Set(unitIds);
90
+ const startBounds = boundsOfObjects(startScene, unitIds);
91
+ const speed = new PointerSpeedTracker();
92
+ let started = false;
93
+ let duplicated = false;
94
+ let targets = null;
121
95
  // The shapes the drag carries, asked once at the first step: the same shapes move at every step, and a step must not
122
96
  // walk the board's groups again to find them (a press that never becomes a drag never asks).
123
- var carried = null;
124
- var last = start;
125
- var apply = function (input) {
126
- var _a, _b, _c;
127
- var world = worldOf(context, input);
128
- var deltaX = world.x - startWorld.x;
129
- var deltaY = world.y - startWorld.y;
130
- var lockX = input.shiftKey && Math.abs(deltaX) < Math.abs(deltaY);
131
- var lockY = input.shiftKey && !lockX;
97
+ let carried = null;
98
+ let last = start;
99
+ const apply = (input) => {
100
+ const world = worldOf(context, input);
101
+ let deltaX = world.x - startWorld.x;
102
+ let deltaY = world.y - startWorld.y;
103
+ const lockX = input.shiftKey && Math.abs(deltaX) < Math.abs(deltaY);
104
+ const lockY = input.shiftKey && !lockX;
132
105
  if (lockX)
133
106
  deltaX = 0;
134
107
  if (lockY)
135
108
  deltaY = 0;
136
- var guides = [];
137
- var snapping = ((_c = (_b = (_a = context.options).snapEnabled) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : true) && !input.metaKey && !input.ctrlKey;
109
+ let guides = [];
110
+ const snapping = (context.options.snapEnabled?.() ?? true) && !input.metaKey && !input.ctrlKey;
138
111
  speed.update(input.x, input.y, input.time);
139
112
  if (snapping && startBounds) {
140
113
  if (!targets)
141
114
  targets = collectSnapTargets(context, moving);
142
- var reach = snapReachInWorld(engine.state.viewport.zoom, speed.speed);
143
- var snap = computeMoveSnap(__assign(__assign({}, startBounds), { x: startBounds.x + deltaX, y: startBounds.y + deltaY }), targets, reach);
115
+ const reach = snapReachInWorld(engine.state.viewport.zoom, speed.speed);
116
+ const snap = computeMoveSnap({ ...startBounds, x: startBounds.x + deltaX, y: startBounds.y + deltaY }, targets, reach);
144
117
  if (!lockX)
145
118
  deltaX += snap.deltaX;
146
119
  if (!lockY)
147
120
  deltaY += snap.deltaY;
148
- guides = snap.guides.filter(function (guide) { return (guide.orientation === 'vertical' ? !lockX : !lockY); });
121
+ guides = snap.guides.filter((guide) => (guide.orientation === 'vertical' ? !lockX : !lockY));
149
122
  }
150
- carried !== null && carried !== void 0 ? carried : (carried = movingShapeIds(startScene, __spreadArray([], moving, true)));
123
+ carried ??= movingShapeIds(startScene, [...moving]);
151
124
  engine.applyScene(translateShapes(startScene, carried, deltaX, deltaY), 'transient');
152
125
  // The handles step aside while the selection is carried: what is carried is all that is to be seen.
153
- engine.setOverlay({ guides: guides, dragging: 'move' });
126
+ engine.setOverlay({ guides, dragging: 'move' });
154
127
  };
155
128
  return {
156
129
  kind: 'move',
157
130
  pointerId: start.pointerId,
158
- move: function (input) {
131
+ move(input) {
159
132
  last = input;
160
133
  if (options.immovable)
161
134
  return;
@@ -168,7 +141,7 @@ export function createMoveGesture(context, start, unitIds, options) {
168
141
  duplicated = true;
169
142
  if (engine.state.selectedIds.length === 0 && unitIds.length > 0)
170
143
  engine.select(unitIds);
171
- var copyIds = engine.duplicateSelectionForDrag();
144
+ const copyIds = engine.duplicateSelectionForDrag();
172
145
  if (copyIds.length > 0) {
173
146
  moving = new Set(copyIds);
174
147
  startScene = engine.state.scene;
@@ -178,10 +151,9 @@ export function createMoveGesture(context, start, unitIds, options) {
178
151
  }
179
152
  apply(input);
180
153
  },
181
- end: function (input) {
182
- var _a;
154
+ end(input) {
183
155
  if (!started) {
184
- (_a = options.onClick) === null || _a === void 0 ? void 0 : _a.call(options);
156
+ options.onClick?.();
185
157
  return;
186
158
  }
187
159
  last = input;
@@ -190,21 +162,21 @@ export function createMoveGesture(context, start, unitIds, options) {
190
162
  engine.commit();
191
163
  engine.setCursor(cursorForTool(engine.state.tool));
192
164
  },
193
- cancel: function () {
165
+ cancel() {
194
166
  if (started)
195
167
  engine.revertToCommitted();
196
168
  engine.setCursor(cursorForTool(engine.state.tool));
197
169
  },
198
- modifiersChanged: function (modifiers) {
170
+ modifiersChanged(modifiers) {
199
171
  if (started)
200
- apply(__assign(__assign({}, last), modifiers));
172
+ apply({ ...last, ...modifiers });
201
173
  }
202
174
  };
203
175
  }
204
176
  // ──────────────────────────────────────────────────────────── resize
205
177
  /** Where a handle of a frame is in the world. */
206
178
  function handlePointOf(frame, handle) {
207
- var direction = handleDirection(handle);
179
+ const direction = handleDirection(handle);
208
180
  return applyMatrixToPoint(boxToWorldMatrix(frame), {
209
181
  x: direction.x === 0 ? frame.width / 2 : direction.x > 0 ? frame.width : 0,
210
182
  y: direction.y === 0 ? frame.height / 2 : direction.y > 0 ? frame.height : 0
@@ -212,12 +184,11 @@ function handlePointOf(frame, handle) {
212
184
  }
213
185
  /** The corner of a frame that is nearest to a point of the world: the one a corner handle dragged to that point is on. */
214
186
  function cornerNearestTo(frame, target) {
215
- var nearest = handlePointOf(frame, CORNER_HANDLES[0]);
216
- var nearestDistance = distanceBetween(nearest, target);
217
- for (var _i = 0, _a = CORNER_HANDLES.slice(1); _i < _a.length; _i++) {
218
- var handle = _a[_i];
219
- var point = handlePointOf(frame, handle);
220
- var distance = distanceBetween(point, target);
187
+ let nearest = handlePointOf(frame, CORNER_HANDLES[0]);
188
+ let nearestDistance = distanceBetween(nearest, target);
189
+ for (const handle of CORNER_HANDLES.slice(1)) {
190
+ const point = handlePointOf(frame, handle);
191
+ const distance = distanceBetween(point, target);
221
192
  if (distance < nearestDistance) {
222
193
  nearest = point;
223
194
  nearestDistance = distance;
@@ -227,51 +198,52 @@ function cornerNearestTo(frame, target) {
227
198
  }
228
199
  /** Drags a handle of the selection. Nothing changes until the pointer has gone `DRAG_THRESHOLD` pixels: a press and a double press are not a stretch. */
229
200
  export function createResizeGesture(context, start, handle, frame, shapes) {
230
- var engine = context.engine;
231
- var startScene = engine.state.scene;
232
- var corner = isCornerHandle(handle);
233
- var single = shapes.length === 1 ? shapes[0] : null;
201
+ const { engine } = context;
202
+ const startScene = engine.state.scene;
203
+ const corner = isCornerHandle(handle);
204
+ const single = shapes.length === 1 ? shapes[0] : null;
234
205
  // An arrow stretched with these shapes comes off the shapes it is tied to that are not stretched with it.
235
- var stretchedIds = new Set(shapes.map(function (shape) { return shape.id; }));
206
+ const stretchedIds = new Set(shapes.map((shape) => shape.id));
236
207
  // A circle, an icon, a picture and a text keep their proportions when a corner is dragged.
237
- var keepsAspect = !!single &&
208
+ const keepsAspect = !!single &&
238
209
  (((single.type === 'path' || single.type === 'ellipse') && single.aspectLocked) ||
239
210
  (corner && (single.type === 'image' || single.type === 'text')));
240
211
  // A text's corner scales its letters, and the box the letters make is not where the hand is. The hand is hidden for the
241
212
  // drag and an arrow is drawn on the corner instead, so the person sees what is being held.
242
- var drawsOwnPointer = ENABLE_TEXT_VIRTUAL_CURSOR && corner && (single === null || single === void 0 ? void 0 : single.type) === 'text';
243
- var direction = handleDirection(handle);
244
- var arrowAngle = (Math.atan2(direction.y, direction.x) * 180) / Math.PI + frame.rotation;
213
+ const drawsOwnPointer = ENABLE_TEXT_VIRTUAL_CURSOR && corner && single?.type === 'text';
214
+ const direction = handleDirection(handle);
215
+ const arrowAngle = (Math.atan2(direction.y, direction.x) * 180) / Math.PI + frame.rotation;
245
216
  engine.setCursor(cursorForHandle(handle, frame.rotation));
246
- var started = false;
247
- var last = start;
217
+ let started = false;
218
+ let last = start;
248
219
  // The handle follows the pointer by the distance the press was from it. A handle's target reaches well past the 8 px
249
220
  // square that is drawn (more for a finger), and the frame must not jump that far to the pointer on the first move.
250
- var handleInWorld = handlePointOf(frame, handle);
251
- var pressInWorld = worldOf(context, start);
252
- var grabOffset = { x: handleInWorld.x - pressInWorld.x, y: handleInWorld.y - pressInWorld.y };
253
- var apply = function (input) {
254
- var pointerInWorld = worldOf(context, input);
255
- var handleTarget = { x: pointerInWorld.x + grabOffset.x, y: pointerInWorld.y + grabOffset.y };
256
- var resized = computeResizedFrame(frame, handle, handleTarget, {
221
+ const handleInWorld = handlePointOf(frame, handle);
222
+ const pressInWorld = worldOf(context, start);
223
+ const grabOffset = { x: handleInWorld.x - pressInWorld.x, y: handleInWorld.y - pressInWorld.y };
224
+ const apply = (input) => {
225
+ const pointerInWorld = worldOf(context, input);
226
+ const handleTarget = { x: pointerInWorld.x + grabOffset.x, y: pointerInWorld.y + grabOffset.y };
227
+ const resized = computeResizedFrame(frame, handle, handleTarget, {
257
228
  fromCenter: input.altKey,
258
229
  keepAspect: input.shiftKey || keepsAspect,
259
230
  allowFlip: true
260
231
  });
261
- var next = fitAll(context, applyFrameResize(shapes, frame, resized, corner)).map(function (shape) { return releaseUnmovedEnds(shape, stretchedIds); });
232
+ const next = fitAll(context, applyFrameResize(shapes, frame, resized, corner)).map((shape) => releaseUnmovedEnds(shape, stretchedIds));
262
233
  engine.applyScene(withShapes(startScene, next), 'transient');
263
- var after = selectionFrameOf(next);
234
+ const after = selectionFrameOf(next);
264
235
  engine.setOverlay({
265
236
  dragging: 'resize',
266
237
  readout: after ? { kind: 'size', width: Math.round(after.width), height: Math.round(after.height) } : null,
267
238
  virtualCursor: drawsOwnPointer && after
268
- ? __assign(__assign({}, worldToScreen(engine.state.viewport, cornerNearestTo(after, handleTarget))), { angle: arrowAngle }) : null
239
+ ? { ...worldToScreen(engine.state.viewport, cornerNearestTo(after, handleTarget)), angle: arrowAngle }
240
+ : null
269
241
  });
270
242
  };
271
243
  return {
272
244
  kind: 'resize',
273
245
  pointerId: start.pointerId,
274
- move: function (input) {
246
+ move(input) {
275
247
  last = input;
276
248
  if (!started) {
277
249
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
@@ -282,21 +254,21 @@ export function createResizeGesture(context, start, handle, frame, shapes) {
282
254
  }
283
255
  apply(input);
284
256
  },
285
- end: function () {
257
+ end() {
286
258
  if (started) {
287
259
  engine.clearOverlay();
288
260
  engine.commit();
289
261
  }
290
262
  engine.setCursor(cursorForTool(engine.state.tool));
291
263
  },
292
- cancel: function () {
264
+ cancel() {
293
265
  if (started)
294
266
  engine.revertToCommitted();
295
267
  engine.setCursor(cursorForTool(engine.state.tool));
296
268
  },
297
- modifiersChanged: function (modifiers) {
269
+ modifiersChanged(modifiers) {
298
270
  if (started)
299
- apply(__assign(__assign({}, last), modifiers));
271
+ apply({ ...last, ...modifiers });
300
272
  }
301
273
  };
302
274
  }
@@ -307,34 +279,33 @@ export function createResizeGesture(context, start, handle, frame, shapes) {
307
279
  * the pointer has gone `DRAG_THRESHOLD` pixels. `source` is where the press landed: the dot (the pointer is a hand that
308
280
  * holds it) or the zone outside a corner (the turning arrow).
309
281
  */
310
- export function createRotateGesture(context, start, frame, shapes, source) {
311
- if (source === void 0) { source = 'corner'; }
312
- var engine = context.engine;
313
- var startScene = engine.state.scene;
314
- var center = frameCenter(frame);
315
- var startAngle = angleFromCenter(center, worldOf(context, start));
316
- var single = shapes.length === 1 ? shapes[0] : null;
282
+ export function createRotateGesture(context, start, frame, shapes, source = 'corner') {
283
+ const { engine } = context;
284
+ const startScene = engine.state.scene;
285
+ const center = frameCenter(frame);
286
+ const startAngle = angleFromCenter(center, worldOf(context, start));
287
+ const single = shapes.length === 1 ? shapes[0] : null;
317
288
  // An arrow turned with these shapes comes off the shapes it is tied to that are not turned with it.
318
- var turnedIds = new Set(shapes.map(function (shape) { return shape.id; }));
289
+ const turnedIds = new Set(shapes.map((shape) => shape.id));
319
290
  engine.setCursor(source === 'dot' ? 'grabbing' : ROTATE_CURSOR);
320
- var started = false;
321
- var last = start;
322
- var apply = function (input) {
323
- var delta = angleFromCenter(center, worldOf(context, input)) - startAngle;
291
+ let started = false;
292
+ let last = start;
293
+ const apply = (input) => {
294
+ let delta = angleFromCenter(center, worldOf(context, input)) - startAngle;
324
295
  if (input.shiftKey || input.ctrlKey || input.metaKey) {
325
296
  delta = single
326
297
  ? snapAngle(single.rotation + delta, ROTATION_SNAP_DEGREES) - single.rotation
327
298
  : snapAngle(delta, ROTATION_SNAP_DEGREES);
328
299
  }
329
- var turned = rotateShapesAbout(shapes, center, delta).map(function (shape) { return releaseUnmovedEnds(shape, turnedIds); });
300
+ const turned = rotateShapesAbout(shapes, center, delta).map((shape) => releaseUnmovedEnds(shape, turnedIds));
330
301
  engine.applyScene(withShapes(startScene, turned), 'transient');
331
- var shown = single ? normalizeDegrees(single.rotation + delta) : normalizeDegrees(delta);
302
+ const shown = single ? normalizeDegrees(single.rotation + delta) : normalizeDegrees(delta);
332
303
  engine.setOverlay({ dragging: 'rotate', readout: { kind: 'angle', degrees: Math.round(shown) % 360 } });
333
304
  };
334
305
  return {
335
306
  kind: 'rotate',
336
307
  pointerId: start.pointerId,
337
- move: function (input) {
308
+ move(input) {
338
309
  last = input;
339
310
  if (!started) {
340
311
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
@@ -343,21 +314,21 @@ export function createRotateGesture(context, start, frame, shapes, source) {
343
314
  }
344
315
  apply(input);
345
316
  },
346
- end: function () {
317
+ end() {
347
318
  if (started) {
348
319
  engine.clearOverlay();
349
320
  engine.commit();
350
321
  }
351
322
  engine.setCursor(cursorForTool(engine.state.tool));
352
323
  },
353
- cancel: function () {
324
+ cancel() {
354
325
  if (started)
355
326
  engine.revertToCommitted();
356
327
  engine.setCursor(cursorForTool(engine.state.tool));
357
328
  },
358
- modifiersChanged: function (modifiers) {
329
+ modifiersChanged(modifiers) {
359
330
  if (started)
360
- apply(__assign(__assign({}, last), modifiers));
331
+ apply({ ...last, ...modifiers });
361
332
  }
362
333
  };
363
334
  }
@@ -376,42 +347,41 @@ export function createRotateGesture(context, start, frame, shapes, source) {
376
347
  * ties it to nothing. The shape the other end is tied to is passed over: the two ends of an arrow are never tied to the same shape.
377
348
  */
378
349
  export function createArrowHandleGesture(context, start, arrow, handle) {
379
- var engine = context.engine;
380
- var startScene = engine.state.scene;
381
- var startPoints = arrowPointsInWorld(arrow);
382
- var otherEndBinding = handle === 'start' ? bindingOfEnd(arrow.arrow, 'end') : handle === 'end' ? bindingOfEnd(arrow.arrow, 'start') : null;
383
- var passedOver = otherEndBinding ? new Set([otherEndBinding.targetId]) : undefined;
384
- var grabbed = handle === 'start' ? startPoints.start : handle === 'end' ? startPoints.end : startPoints.middle;
385
- var pressWorld = worldOf(context, start);
350
+ const { engine } = context;
351
+ const startScene = engine.state.scene;
352
+ const startPoints = arrowPointsInWorld(arrow);
353
+ const otherEndBinding = handle === 'start' ? bindingOfEnd(arrow.arrow, 'end') : handle === 'end' ? bindingOfEnd(arrow.arrow, 'start') : null;
354
+ const passedOver = otherEndBinding ? new Set([otherEndBinding.targetId]) : undefined;
355
+ const grabbed = handle === 'start' ? startPoints.start : handle === 'end' ? startPoints.end : startPoints.middle;
356
+ const pressWorld = worldOf(context, start);
386
357
  // Where the handle is, from where the pointer is: the pointer carries this much of an offset the whole way.
387
- var offset = { x: grabbed.x - pressWorld.x, y: grabbed.y - pressWorld.y };
358
+ const offset = { x: grabbed.x - pressWorld.x, y: grabbed.y - pressWorld.y };
388
359
  engine.setCursor('grabbing');
389
360
  engine.setArrowHandleHover(handle);
390
- var started = false;
391
- var last = start;
392
- var apply = function (input) {
393
- var _a, _b, _c;
394
- var pointer = worldOf(context, input);
395
- var target = { x: pointer.x + offset.x, y: pointer.y + offset.y };
396
- var changed;
397
- var pick = null;
361
+ let started = false;
362
+ let last = start;
363
+ const apply = (input) => {
364
+ const pointer = worldOf(context, input);
365
+ const target = { x: pointer.x + offset.x, y: pointer.y + offset.y };
366
+ let changed;
367
+ let pick = null;
398
368
  if (handle === 'bend') {
399
369
  changed = reshapeArrow(arrow, { bend: bendTowards(startPoints.start, startPoints.end, target) });
400
370
  }
401
371
  else {
402
- var fixed = handle === 'start' ? startPoints.end : startPoints.start;
403
- var moved = input.shiftKey ? snapPointAround(fixed, target, ARROW_SNAP_DEGREES) : target;
372
+ const fixed = handle === 'start' ? startPoints.end : startPoints.start;
373
+ const moved = input.shiftKey ? snapPointAround(fixed, target, ARROW_SNAP_DEGREES) : target;
404
374
  if (!input.altKey && !input.shiftKey) {
405
375
  pick = pickArrowBinding(startScene, target, { zoom: engine.state.viewport.zoom, ignore: passedOver });
406
376
  }
407
377
  // The end is where the hand puts it; the engine draws a tied end from its shape (`reconcileArrowBindings`) in the same step.
408
- var change = handle === 'start' ? { start: moved, startBinding: (_a = pick === null || pick === void 0 ? void 0 : pick.binding) !== null && _a !== void 0 ? _a : null } : { end: moved, endBinding: (_b = pick === null || pick === void 0 ? void 0 : pick.binding) !== null && _b !== void 0 ? _b : null };
378
+ const change = handle === 'start' ? { start: moved, startBinding: pick?.binding ?? null } : { end: moved, endBinding: pick?.binding ?? null };
409
379
  changed = reshapeArrow(arrow, change);
410
380
  }
411
381
  engine.applyScene(withShapes(startScene, [changed]), 'transient');
412
- engine.setOverlay({ arrowBind: (_c = pick === null || pick === void 0 ? void 0 : pick.hint) !== null && _c !== void 0 ? _c : null });
382
+ engine.setOverlay({ arrowBind: pick?.hint ?? null });
413
383
  };
414
- var finish = function () {
384
+ const finish = () => {
415
385
  engine.setOverlay({ arrowBind: null });
416
386
  engine.setArrowHandleHover(null);
417
387
  engine.setCursor(cursorForTool(engine.state.tool));
@@ -419,7 +389,7 @@ export function createArrowHandleGesture(context, start, arrow, handle) {
419
389
  return {
420
390
  kind: 'arrow-handle',
421
391
  pointerId: start.pointerId,
422
- move: function (input) {
392
+ move(input) {
423
393
  last = input;
424
394
  if (!started) {
425
395
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
@@ -428,41 +398,41 @@ export function createArrowHandleGesture(context, start, arrow, handle) {
428
398
  }
429
399
  apply(input);
430
400
  },
431
- end: function () {
401
+ end() {
432
402
  if (started)
433
403
  engine.commit();
434
404
  finish();
435
405
  },
436
- cancel: function () {
406
+ cancel() {
437
407
  if (started)
438
408
  engine.revertToCommitted();
439
409
  finish();
440
410
  },
441
- modifiersChanged: function (modifiers) {
411
+ modifiersChanged(modifiers) {
442
412
  if (started)
443
- apply(__assign(__assign({}, last), modifiers));
413
+ apply({ ...last, ...modifiers });
444
414
  }
445
415
  };
446
416
  }
447
417
  // ──────────────────────────────────────────────────────────── marquee
448
418
  /** What a marquee that touches nothing hands to the overlay: the one shared empty list. */
449
- var NO_UNITS = Object.freeze([]);
419
+ const NO_UNITS = Object.freeze([]);
450
420
  /**
451
421
  * Drags a rectangle over the board. While it is dragged, what it touches is outlined the way the unit under the pointer is
452
422
  * (the overlay's `marqueeHover`), so the person sees what the release will take; the selection is made at the release, from
453
423
  * the same units (added to the ones that were selected when Shift was held at the press).
454
424
  */
455
425
  export function createMarqueeGesture(context, start) {
456
- var engine = context.engine;
457
- var startWorld = worldOf(context, start);
458
- var base = start.shiftKey ? __spreadArray([], engine.state.selectedIds, true) : [];
459
- var started = false;
426
+ const { engine } = context;
427
+ const startWorld = worldOf(context, start);
428
+ const base = start.shiftKey ? [...engine.state.selectedIds] : [];
429
+ let started = false;
460
430
  // The units the marquee takes now. The board is handed the very same list for as long as they are the same units, so a
461
431
  // marquee that grows over nothing new wakes nothing (see `erasingMarks.ts`).
462
- var wouldSelect = NO_UNITS;
432
+ let wouldSelect = NO_UNITS;
463
433
  /** The selection a release at this rectangle would make: made as `select` makes it (a group once, no repeats). */
464
- var selectionFor = function (rect) {
465
- var units = normalizeSelection(engine.state.scene, __spreadArray(__spreadArray([], base, true), engine.hitTestRect(rect, 'intersect'), true));
434
+ const selectionFor = (rect) => {
435
+ const units = normalizeSelection(engine.state.scene, [...base, ...engine.hitTestRect(rect, 'intersect')]);
466
436
  if (units.length === 0)
467
437
  return NO_UNITS;
468
438
  return sameIds(units, wouldSelect) ? wouldSelect : units;
@@ -470,23 +440,23 @@ export function createMarqueeGesture(context, start) {
470
440
  return {
471
441
  kind: 'marquee',
472
442
  pointerId: start.pointerId,
473
- move: function (input) {
443
+ move(input) {
474
444
  if (!started) {
475
445
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
476
446
  return;
477
447
  started = true;
478
448
  }
479
- var rect = rectFromPoints(startWorld, worldOf(context, input));
449
+ const rect = rectFromPoints(startWorld, worldOf(context, input));
480
450
  wouldSelect = selectionFor(rect);
481
451
  engine.setOverlay({ marquee: rect, marqueeHover: wouldSelect });
482
452
  },
483
- end: function (input) {
453
+ end(input) {
484
454
  // A press that never became a drag selects nothing (it cleared the selection when it began).
485
455
  if (started)
486
456
  engine.select(selectionFor(rectFromPoints(startWorld, worldOf(context, input))));
487
457
  engine.setOverlay({ marquee: null, marqueeHover: NO_UNITS });
488
458
  },
489
- cancel: function () {
459
+ cancel() {
490
460
  // Nothing was selected while it was dragged, so there is nothing to put back.
491
461
  engine.setOverlay({ marquee: null, marqueeHover: NO_UNITS });
492
462
  }
@@ -494,18 +464,17 @@ export function createMarqueeGesture(context, start) {
494
464
  }
495
465
  // ──────────────────────────────────────────────────────────── pan
496
466
  /** Drags the view. `onTap` is what a press that never moved does (a finger on empty board clears the selection). */
497
- export function createPanGesture(context, start, options) {
498
- if (options === void 0) { options = {}; }
499
- var engine = context.engine;
500
- var lastX = start.x;
501
- var lastY = start.y;
502
- var moved = false;
467
+ export function createPanGesture(context, start, options = {}) {
468
+ const { engine } = context;
469
+ let lastX = start.x;
470
+ let lastY = start.y;
471
+ let moved = false;
503
472
  engine.setCursor('grabbing');
504
- var restore = function () { return engine.setCursor(cursorForTool(engine.state.tool)); };
473
+ const restore = () => engine.setCursor(cursorForTool(engine.state.tool));
505
474
  return {
506
475
  kind: 'pan',
507
476
  pointerId: start.pointerId,
508
- move: function (input) {
477
+ move(input) {
509
478
  if (!moved && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= DRAG_THRESHOLD)
510
479
  moved = true;
511
480
  if (!moved)
@@ -514,72 +483,67 @@ export function createPanGesture(context, start, options) {
514
483
  lastX = input.x;
515
484
  lastY = input.y;
516
485
  },
517
- end: function () {
518
- var _a;
486
+ end() {
519
487
  restore();
520
488
  if (!moved)
521
- (_a = options.onTap) === null || _a === void 0 ? void 0 : _a.call(options);
489
+ options.onTap?.();
522
490
  },
523
491
  cancel: restore
524
492
  };
525
493
  }
526
494
  // ──────────────────────────────────────────────────────────── ink
527
495
  /** A pen whose pressure never moves by more than this has none to report, and draws as a mouse does. */
528
- var PEN_PRESSURE_SPREAD = 0.02;
496
+ const PEN_PRESSURE_SPREAD = 0.02;
529
497
  /** The pressure of a straight line (Shift): even, so that it is as wide at one end as at the other. */
530
- var STRAIGHT_LINE_PRESSURE = 0.5;
498
+ const STRAIGHT_LINE_PRESSURE = 0.5;
531
499
  /**
532
500
  * Draws with the brush. The line is as thick as the hand presses: a pen's own pressure, or, for a mouse or a finger, the time the
533
501
  * hand spends (a slow stroke swells, a quick one thins). Shift draws a straight line from where the pointer went down.
534
502
  */
535
503
  export function createDrawGesture(context, start) {
536
- var engine = context.engine;
537
- var strokeId = engine.services.createId('obj');
538
- var isPen = start.pointerType === 'pen';
539
- var samples = [];
540
- var leastPressure = Infinity;
541
- var mostPressure = -Infinity;
542
- var straight = start.shiftKey;
543
- var lastScreen = { x: start.x, y: start.y };
544
- var lastInput = start;
545
- var takeSample = function (input) {
546
- var world = worldOf(context, input);
504
+ const { engine } = context;
505
+ const strokeId = engine.services.createId('obj');
506
+ const isPen = start.pointerType === 'pen';
507
+ const samples = [];
508
+ let leastPressure = Infinity;
509
+ let mostPressure = -Infinity;
510
+ let straight = start.shiftKey;
511
+ let lastScreen = { x: start.x, y: start.y };
512
+ let lastInput = start;
513
+ const takeSample = (input) => {
514
+ const world = worldOf(context, input);
547
515
  // Only a pen's pressure means anything: a mouse and a finger report one fixed value while they are down.
548
516
  if (isPen && typeof input.pressure === 'number') {
549
517
  leastPressure = Math.min(leastPressure, input.pressure);
550
518
  mostPressure = Math.max(mostPressure, input.pressure);
551
- samples.push(__assign(__assign({}, world), { pressure: input.pressure }));
519
+ samples.push({ ...world, pressure: input.pressure });
552
520
  }
553
521
  else {
554
522
  samples.push(world);
555
523
  }
556
524
  };
557
525
  takeSample(start);
558
- var readsPressure = function () { return isPen && mostPressure - leastPressure >= PEN_PRESSURE_SPREAD; };
559
- var isStraight = function () { return straight && samples.length > 1; };
526
+ const readsPressure = () => isPen && mostPressure - leastPressure >= PEN_PRESSURE_SPREAD;
527
+ const isStraight = () => straight && samples.length > 1;
560
528
  /** The line the hand drew: the samples, or just their two ends when Shift holds it straight. */
561
- var lineDrawn = function () { return (isStraight() ? [samples[0], samples[samples.length - 1]] : samples); };
562
- var build = function (finished) {
529
+ const lineDrawn = () => (isStraight() ? [samples[0], samples[samples.length - 1]] : samples);
530
+ const build = (finished) => {
563
531
  // A straight line has two ends and an even width, which is what a pen's reading of a steady pressure gives.
564
- var line = isStraight()
565
- ? lineDrawn().map(function (_a) {
566
- var x = _a.x, y = _a.y;
567
- return ({ x: x, y: y, pressure: STRAIGHT_LINE_PRESSURE });
568
- })
532
+ const line = isStraight()
533
+ ? lineDrawn().map(({ x, y }) => ({ x, y, pressure: STRAIGHT_LINE_PRESSURE }))
569
534
  : samples;
570
- return buildBrushStroke(line, { createId: function () { return strokeId; }, pressure: isStraight() || readsPressure() ? 'pen' : 'speed', finished: finished });
535
+ return buildBrushStroke(line, { createId: () => strokeId, pressure: isStraight() || readsPressure() ? 'pen' : 'speed', finished });
571
536
  };
572
- var showPreview = function () { return engine.setOverlay({ preview: build(false) }); };
537
+ const showPreview = () => engine.setOverlay({ preview: build(false) });
573
538
  showPreview();
574
539
  return {
575
540
  kind: 'draw',
576
541
  pointerId: start.pointerId,
577
- move: function (input) {
542
+ move(input) {
578
543
  lastInput = input;
579
544
  straight = input.shiftKey;
580
- var moved = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
581
- for (var _i = 0, moved_1 = moved; _i < moved_1.length; _i++) {
582
- var sample = moved_1[_i];
545
+ const moved = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
546
+ for (const sample of moved) {
583
547
  // A new sample closer than a pixel to the last one adds nothing the eye can see.
584
548
  if (Math.hypot(sample.x - lastScreen.x, sample.y - lastScreen.y) < 1)
585
549
  continue;
@@ -588,22 +552,21 @@ export function createDrawGesture(context, start) {
588
552
  }
589
553
  showPreview();
590
554
  },
591
- end: function (input) {
592
- var _a, _b;
555
+ end(input) {
593
556
  straight = input.shiftKey;
594
- var stroke = build(true);
557
+ const stroke = build(true);
595
558
  engine.clearOverlay();
596
559
  if (!stroke)
597
560
  return;
598
561
  engine.addObjects([stroke]);
599
- (_b = (_a = context.options).onStrokeFinished) === null || _b === void 0 ? void 0 : _b.call(_a, stroke, lineDrawn());
562
+ context.options.onStrokeFinished?.(stroke, lineDrawn());
600
563
  },
601
- cancel: function () {
564
+ cancel() {
602
565
  engine.clearOverlay();
603
566
  },
604
- modifiersChanged: function (modifiers) {
567
+ modifiersChanged(modifiers) {
605
568
  straight = modifiers.shiftKey;
606
- lastInput = __assign(__assign({}, lastInput), modifiers);
569
+ lastInput = { ...lastInput, ...modifiers };
607
570
  showPreview();
608
571
  }
609
572
  };
@@ -618,60 +581,57 @@ export function createDrawGesture(context, start) {
618
581
  * default arrow, tied to nothing; the two ends are never tied to the same shape.
619
582
  */
620
583
  export function createShapeGesture(context, start, kind, libraryKey) {
621
- var engine = context.engine;
622
- var id = engine.services.createId('obj');
584
+ const { engine } = context;
585
+ const id = engine.services.createId('obj');
623
586
  // One colour for the whole drag: a random fill must not change on every frame.
624
- var colorSeed = engine.services.random();
625
- var startWorld = worldOf(context, start);
626
- var dragged = false;
627
- var last = start;
628
- var pickAt = function (point, ignore) {
629
- return pickArrowBinding(engine.state.scene, point, { zoom: engine.state.viewport.zoom, ignore: ignore });
630
- };
587
+ const colorSeed = engine.services.random();
588
+ const startWorld = worldOf(context, start);
589
+ let dragged = false;
590
+ let last = start;
591
+ const pickAt = (point, ignore) => pickArrowBinding(engine.state.scene, point, { zoom: engine.state.viewport.zoom, ignore });
631
592
  // The shape the tail of an arrow would be tied to, from the moment of the press.
632
- var tailPick = kind === 'arrow' && !start.altKey ? pickAt(startWorld) : null;
593
+ const tailPick = kind === 'arrow' && !start.altKey ? pickAt(startWorld) : null;
633
594
  if (tailPick)
634
595
  engine.setOverlay({ arrowBind: tailPick.hint });
635
- var build = function (input) {
636
- var _a, _b;
637
- var end = worldOf(context, input);
638
- var fromCenter = input.altKey && kind !== 'arrow' && dragged;
639
- var shape = buildDraggedShape({
640
- kind: kind,
596
+ const build = (input) => {
597
+ const end = worldOf(context, input);
598
+ const fromCenter = input.altKey && kind !== 'arrow' && dragged;
599
+ const shape = buildDraggedShape({
600
+ kind,
641
601
  start: fromCenter ? { x: 2 * startWorld.x - end.x, y: 2 * startWorld.y - end.y } : startWorld,
642
- end: end,
602
+ end,
643
603
  constrain: input.shiftKey,
644
- dragged: dragged,
645
- libraryKey: libraryKey,
604
+ dragged,
605
+ libraryKey,
646
606
  wireframe: engine.wireframeMode,
647
- createId: function () { return id; },
648
- random: function () { return colorSeed; },
607
+ createId: () => id,
608
+ random: () => colorSeed,
649
609
  workspacePaint: engine.workspacePaintForNewShape(engine.wireframeMode)
650
610
  });
651
611
  if (kind !== 'arrow' || !dragged || input.altKey || shape.type !== 'path' || !isArrow(shape))
652
- return { shape: shape, hint: null };
653
- var tail = tailPick === null || tailPick === void 0 ? void 0 : tailPick.binding;
654
- var headPick = input.shiftKey ? null : pickAt(end, tail ? new Set([tail.targetId]) : undefined);
612
+ return { shape, hint: null };
613
+ const tail = tailPick?.binding;
614
+ const headPick = input.shiftKey ? null : pickAt(end, tail ? new Set([tail.targetId]) : undefined);
655
615
  if (!tail && !headPick)
656
- return { shape: shape, hint: null };
657
- var index = engine.sceneIndex();
658
- var tied = positionBoundArrow(reshapeArrow(shape, { startBinding: tail !== null && tail !== void 0 ? tail : null, endBinding: (_a = headPick === null || headPick === void 0 ? void 0 : headPick.binding) !== null && _a !== void 0 ? _a : null }), function (targetId) { return index.get(targetId); });
659
- return { shape: tied, hint: (_b = headPick === null || headPick === void 0 ? void 0 : headPick.hint) !== null && _b !== void 0 ? _b : null };
616
+ return { shape, hint: null };
617
+ const index = engine.sceneIndex();
618
+ const tied = positionBoundArrow(reshapeArrow(shape, { startBinding: tail ?? null, endBinding: headPick?.binding ?? null }), (targetId) => index.get(targetId));
619
+ return { shape: tied, hint: headPick?.hint ?? null };
660
620
  };
661
621
  return {
662
622
  kind: 'shape',
663
623
  pointerId: start.pointerId,
664
- move: function (input) {
624
+ move(input) {
665
625
  last = input;
666
626
  if (!dragged && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= MIN_DRAW_DISTANCE)
667
627
  dragged = true;
668
628
  if (dragged) {
669
- var _a = build(input), shape = _a.shape, hint = _a.hint;
629
+ const { shape, hint } = build(input);
670
630
  engine.setOverlay({ preview: shape, arrowBind: hint });
671
631
  }
672
632
  },
673
- end: function (input) {
674
- var shape = build(input).shape;
633
+ end(input) {
634
+ const { shape } = build(input);
675
635
  engine.clearOverlay();
676
636
  engine.addObjects([shape]);
677
637
  if (engine.state.stickyTool) {
@@ -682,13 +642,13 @@ export function createShapeGesture(context, start, kind, libraryKey) {
682
642
  engine.select([shape.id]);
683
643
  }
684
644
  },
685
- cancel: function () {
645
+ cancel() {
686
646
  engine.clearOverlay();
687
647
  },
688
- modifiersChanged: function (modifiers) {
648
+ modifiersChanged(modifiers) {
689
649
  if (!dragged)
690
650
  return;
691
- var _a = build(__assign(__assign({}, last), modifiers)), shape = _a.shape, hint = _a.hint;
651
+ const { shape, hint } = build({ ...last, ...modifiers });
692
652
  engine.setOverlay({ preview: shape, arrowBind: hint });
693
653
  }
694
654
  };
@@ -696,35 +656,35 @@ export function createShapeGesture(context, start, kind, libraryKey) {
696
656
  // ──────────────────────────────────────────────────────────── text
697
657
  /** A click makes a label that grows with its text, a drag makes a box of that width. Then the text is edited. */
698
658
  export function createTextGesture(context, start) {
699
- var engine = context.engine;
700
- var startWorld = worldOf(context, start);
701
- var dragged = false;
659
+ const { engine } = context;
660
+ const startWorld = worldOf(context, start);
661
+ let dragged = false;
702
662
  return {
703
663
  kind: 'text',
704
664
  pointerId: start.pointerId,
705
- move: function (input) {
665
+ move(input) {
706
666
  if (!dragged && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= MIN_DRAW_DISTANCE)
707
667
  dragged = true;
708
668
  if (dragged)
709
669
  engine.setOverlay({ textDraft: rectFromPoints(startWorld, worldOf(context, input)) });
710
670
  },
711
- end: function (input) {
671
+ end(input) {
712
672
  engine.setOverlay({ textDraft: null });
713
673
  if (!dragged) {
714
674
  engine.createText(startWorld);
715
675
  return;
716
676
  }
717
- var rect = rectFromPoints(startWorld, worldOf(context, input));
677
+ const rect = rectFromPoints(startWorld, worldOf(context, input));
718
678
  engine.createText({ x: rect.x, y: rect.y }, { width: rect.width });
719
679
  },
720
- cancel: function () {
680
+ cancel() {
721
681
  engine.setOverlay({ textDraft: null });
722
682
  }
723
683
  };
724
684
  }
725
685
  // ──────────────────────────────────────────────────────────── eraser
726
686
  /** The most spots along one sweep of the eraser that are tested for shapes (a flick across a huge board stays affordable). */
727
- var ERASER_MAX_STEPS_PER_SWEEP = 400;
687
+ const ERASER_MAX_STEPS_PER_SWEEP = 400;
728
688
  /**
729
689
  * Marks what the pointer passes over and removes it when the pointer is released.
730
690
  *
@@ -736,48 +696,44 @@ var ERASER_MAX_STEPS_PER_SWEEP = 400;
736
696
  * one by one. A press that does not move marks what lies under it and removes that on release (with Ctrl or Cmd only the top shape).
737
697
  */
738
698
  export function createEraseGesture(context, start) {
739
- var engine = context.engine;
699
+ const { engine } = context;
740
700
  // The scene stays as it was at the press: nothing is removed until the release.
741
- var scene = engine.state.scene;
742
- var index = engine.sceneIndex(scene);
743
- var startWorld = worldOf(context, start);
744
- var zoom = function () { return engine.state.viewport.zoom; };
745
- var marked = [];
701
+ const scene = engine.state.scene;
702
+ const index = engine.sceneIndex(scene);
703
+ const startWorld = worldOf(context, start);
704
+ const zoom = () => engine.state.viewport.zoom;
705
+ const marked = [];
746
706
  // What the hit tests look through: the cards that are never erased, and what is marked already.
747
- var skipped = new Set();
748
- for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
749
- var object = scene_1[_i];
707
+ const skipped = new Set();
708
+ for (const object of scene) {
750
709
  if (object.type === 'widget' || engine.state.pending[object.id])
751
710
  skipped.add(object.id);
752
711
  }
753
712
  // The groups the press began inside of: their members are taken one by one instead of the group as a whole.
754
- var enteredGroups = new Set();
755
- for (var _a = 0, scene_2 = scene; _a < scene_2.length; _a++) {
756
- var object = scene_2[_a];
713
+ const enteredGroups = new Set();
714
+ for (const object of scene) {
757
715
  if (object.type !== 'group')
758
716
  continue;
759
- var box = boundsOfObjects(scene, [object.id]);
717
+ const box = boundsOfObjects(scene, [object.id]);
760
718
  if (box && rectContainsPoint(box, startWorld))
761
719
  enteredGroups.add(object.id);
762
720
  }
763
721
  /** What goes with a shape: the outermost group above it that the press did not begin inside of, else the shape itself. */
764
- var unitOf = function (shapeId) {
765
- var _a;
766
- var unit = index.get(shapeId);
767
- var visited = new Set();
722
+ const unitOf = (shapeId) => {
723
+ let unit = index.get(shapeId);
724
+ const visited = new Set();
768
725
  while (unit && unit.parentId !== null && !visited.has(unit.id)) {
769
726
  visited.add(unit.id);
770
- var parent = index.get(unit.parentId);
727
+ const parent = index.get(unit.parentId);
771
728
  if (!parent || enteredGroups.has(parent.id))
772
729
  break;
773
730
  unit = parent;
774
731
  }
775
- return (_a = unit === null || unit === void 0 ? void 0 : unit.id) !== null && _a !== void 0 ? _a : shapeId;
732
+ return unit?.id ?? shapeId;
776
733
  };
777
- var marksChanged = false;
778
- var markUnitOf = function (shapeId) {
779
- for (var _i = 0, _a = leafShapesOf(scene, [unitOf(shapeId)]); _i < _a.length; _i++) {
780
- var shape = _a[_i];
734
+ let marksChanged = false;
735
+ const markUnitOf = (shapeId) => {
736
+ for (const shape of leafShapesOf(scene, [unitOf(shapeId)])) {
781
737
  if (skipped.has(shape.id))
782
738
  continue;
783
739
  skipped.add(shape.id);
@@ -786,10 +742,9 @@ export function createEraseGesture(context, start) {
786
742
  }
787
743
  };
788
744
  /** Marks the shapes under a spot (all of them, or only the top one). */
789
- var markAt = function (world, onlyTop) {
790
- if (onlyTop === void 0) { onlyTop = false; }
791
- for (var guard = 0; guard < 64; guard += 1) {
792
- var hit = hitTestLeaf(scene, world, { zoom: zoom(), tolerancePixels: ERASER_RADIUS, ignore: skipped });
745
+ const markAt = (world, onlyTop = false) => {
746
+ for (let guard = 0; guard < 64; guard += 1) {
747
+ const hit = hitTestLeaf(scene, world, { zoom: zoom(), tolerancePixels: ERASER_RADIUS, ignore: skipped });
793
748
  if (!hit)
794
749
  break;
795
750
  markUnitOf(hit.id);
@@ -799,18 +754,18 @@ export function createEraseGesture(context, start) {
799
754
  break;
800
755
  }
801
756
  };
802
- var lastWorld = startWorld;
757
+ let lastWorld = startWorld;
803
758
  /** Marks what lies along the way from where the eraser was to where it is. */
804
- var sweepTo = function (to) {
805
- var screenLength = distanceBetween(lastWorld, to) * zoom();
806
- var steps = Math.min(ERASER_MAX_STEPS_PER_SWEEP, Math.max(1, Math.ceil(screenLength / (ERASER_RADIUS / 2))));
807
- for (var step = 1; step <= steps; step += 1) {
808
- var progress = step / steps;
759
+ const sweepTo = (to) => {
760
+ const screenLength = distanceBetween(lastWorld, to) * zoom();
761
+ const steps = Math.min(ERASER_MAX_STEPS_PER_SWEEP, Math.max(1, Math.ceil(screenLength / (ERASER_RADIUS / 2))));
762
+ for (let step = 1; step <= steps; step += 1) {
763
+ const progress = step / steps;
809
764
  markAt({ x: lastWorld.x + (to.x - lastWorld.x) * progress, y: lastWorld.y + (to.y - lastWorld.y) * progress });
810
765
  }
811
766
  lastWorld = to;
812
767
  };
813
- var showMarks = function () {
768
+ const showMarks = () => {
814
769
  if (!marksChanged)
815
770
  return;
816
771
  marksChanged = false;
@@ -819,8 +774,8 @@ export function createEraseGesture(context, start) {
819
774
  // The press itself marks what is under it, so a click shows what it is about to remove.
820
775
  markAt(startWorld, start.ctrlKey || start.metaKey);
821
776
  showMarks();
822
- var dragging = false;
823
- var beginDragging = function () {
777
+ let dragging = false;
778
+ const beginDragging = () => {
824
779
  dragging = true;
825
780
  engine.beginScribble();
826
781
  // A drag takes everything under the spot where it began, also after a click that took only the top shape.
@@ -829,22 +784,21 @@ export function createEraseGesture(context, start) {
829
784
  return {
830
785
  kind: 'erase',
831
786
  pointerId: start.pointerId,
832
- move: function (input) {
787
+ move(input) {
833
788
  if (!dragging) {
834
789
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
835
790
  return;
836
791
  beginDragging();
837
792
  }
838
- var samples = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
839
- for (var _i = 0, samples_1 = samples; _i < samples_1.length; _i++) {
840
- var sample = samples_1[_i];
841
- var world = worldOf(context, sample);
793
+ const samples = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
794
+ for (const sample of samples) {
795
+ const world = worldOf(context, sample);
842
796
  sweepTo(world);
843
797
  engine.extendScribble(world);
844
798
  }
845
799
  showMarks();
846
800
  },
847
- end: function (input) {
801
+ end(input) {
848
802
  // The release can come with a last position no move reported.
849
803
  if (dragging)
850
804
  sweepTo(worldOf(context, input));
@@ -853,7 +807,7 @@ export function createEraseGesture(context, start) {
853
807
  if (marked.length > 0)
854
808
  engine.removeObjects(marked);
855
809
  },
856
- cancel: function () {
810
+ cancel() {
857
811
  engine.stopScribble();
858
812
  engine.clearOverlay();
859
813
  }