@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,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,117 @@ 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
- // 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' });
125
+ // The handles step aside while the selection is carried: what is carried is all that is to be seen. The board is also told
126
+ // what is carried, from which records and how far (`CarriedShapes`), so that it can draw a big selection as one layer and
127
+ // not as a new record for every shape at every step; the records written above are the same, and the engine reads only them.
128
+ engine.setOverlay({ guides, dragging: 'move', carry: { startRecords: engine.sceneIndex(startScene), shapeIds: carried, deltaX, deltaY } });
154
129
  };
155
130
  return {
156
131
  kind: 'move',
157
132
  pointerId: start.pointerId,
158
- move: function (input) {
133
+ move(input) {
159
134
  last = input;
160
135
  if (options.immovable)
161
136
  return;
@@ -168,7 +143,7 @@ export function createMoveGesture(context, start, unitIds, options) {
168
143
  duplicated = true;
169
144
  if (engine.state.selectedIds.length === 0 && unitIds.length > 0)
170
145
  engine.select(unitIds);
171
- var copyIds = engine.duplicateSelectionForDrag();
146
+ const copyIds = engine.duplicateSelectionForDrag();
172
147
  if (copyIds.length > 0) {
173
148
  moving = new Set(copyIds);
174
149
  startScene = engine.state.scene;
@@ -178,10 +153,9 @@ export function createMoveGesture(context, start, unitIds, options) {
178
153
  }
179
154
  apply(input);
180
155
  },
181
- end: function (input) {
182
- var _a;
156
+ end(input) {
183
157
  if (!started) {
184
- (_a = options.onClick) === null || _a === void 0 ? void 0 : _a.call(options);
158
+ options.onClick?.();
185
159
  return;
186
160
  }
187
161
  last = input;
@@ -190,21 +164,21 @@ export function createMoveGesture(context, start, unitIds, options) {
190
164
  engine.commit();
191
165
  engine.setCursor(cursorForTool(engine.state.tool));
192
166
  },
193
- cancel: function () {
167
+ cancel() {
194
168
  if (started)
195
169
  engine.revertToCommitted();
196
170
  engine.setCursor(cursorForTool(engine.state.tool));
197
171
  },
198
- modifiersChanged: function (modifiers) {
172
+ modifiersChanged(modifiers) {
199
173
  if (started)
200
- apply(__assign(__assign({}, last), modifiers));
174
+ apply({ ...last, ...modifiers });
201
175
  }
202
176
  };
203
177
  }
204
178
  // ──────────────────────────────────────────────────────────── resize
205
179
  /** Where a handle of a frame is in the world. */
206
180
  function handlePointOf(frame, handle) {
207
- var direction = handleDirection(handle);
181
+ const direction = handleDirection(handle);
208
182
  return applyMatrixToPoint(boxToWorldMatrix(frame), {
209
183
  x: direction.x === 0 ? frame.width / 2 : direction.x > 0 ? frame.width : 0,
210
184
  y: direction.y === 0 ? frame.height / 2 : direction.y > 0 ? frame.height : 0
@@ -212,12 +186,11 @@ function handlePointOf(frame, handle) {
212
186
  }
213
187
  /** 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
188
  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);
189
+ let nearest = handlePointOf(frame, CORNER_HANDLES[0]);
190
+ let nearestDistance = distanceBetween(nearest, target);
191
+ for (const handle of CORNER_HANDLES.slice(1)) {
192
+ const point = handlePointOf(frame, handle);
193
+ const distance = distanceBetween(point, target);
221
194
  if (distance < nearestDistance) {
222
195
  nearest = point;
223
196
  nearestDistance = distance;
@@ -227,51 +200,52 @@ function cornerNearestTo(frame, target) {
227
200
  }
228
201
  /** 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
202
  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;
203
+ const { engine } = context;
204
+ const startScene = engine.state.scene;
205
+ const corner = isCornerHandle(handle);
206
+ const single = shapes.length === 1 ? shapes[0] : null;
234
207
  // 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; }));
208
+ const stretchedIds = new Set(shapes.map((shape) => shape.id));
236
209
  // A circle, an icon, a picture and a text keep their proportions when a corner is dragged.
237
- var keepsAspect = !!single &&
210
+ const keepsAspect = !!single &&
238
211
  (((single.type === 'path' || single.type === 'ellipse') && single.aspectLocked) ||
239
212
  (corner && (single.type === 'image' || single.type === 'text')));
240
213
  // 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
214
  // 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;
215
+ const drawsOwnPointer = ENABLE_TEXT_VIRTUAL_CURSOR && corner && single?.type === 'text';
216
+ const direction = handleDirection(handle);
217
+ const arrowAngle = (Math.atan2(direction.y, direction.x) * 180) / Math.PI + frame.rotation;
245
218
  engine.setCursor(cursorForHandle(handle, frame.rotation));
246
- var started = false;
247
- var last = start;
219
+ let started = false;
220
+ let last = start;
248
221
  // The handle follows the pointer by the distance the press was from it. A handle's target reaches well past the 8 px
249
222
  // 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, {
223
+ const handleInWorld = handlePointOf(frame, handle);
224
+ const pressInWorld = worldOf(context, start);
225
+ const grabOffset = { x: handleInWorld.x - pressInWorld.x, y: handleInWorld.y - pressInWorld.y };
226
+ const apply = (input) => {
227
+ const pointerInWorld = worldOf(context, input);
228
+ const handleTarget = { x: pointerInWorld.x + grabOffset.x, y: pointerInWorld.y + grabOffset.y };
229
+ const resized = computeResizedFrame(frame, handle, handleTarget, {
257
230
  fromCenter: input.altKey,
258
231
  keepAspect: input.shiftKey || keepsAspect,
259
232
  allowFlip: true
260
233
  });
261
- var next = fitAll(context, applyFrameResize(shapes, frame, resized, corner)).map(function (shape) { return releaseUnmovedEnds(shape, stretchedIds); });
234
+ const next = fitAll(context, applyFrameResize(shapes, frame, resized, corner)).map((shape) => releaseUnmovedEnds(shape, stretchedIds));
262
235
  engine.applyScene(withShapes(startScene, next), 'transient');
263
- var after = selectionFrameOf(next);
236
+ const after = selectionFrameOf(next);
264
237
  engine.setOverlay({
265
238
  dragging: 'resize',
266
239
  readout: after ? { kind: 'size', width: Math.round(after.width), height: Math.round(after.height) } : null,
267
240
  virtualCursor: drawsOwnPointer && after
268
- ? __assign(__assign({}, worldToScreen(engine.state.viewport, cornerNearestTo(after, handleTarget))), { angle: arrowAngle }) : null
241
+ ? { ...worldToScreen(engine.state.viewport, cornerNearestTo(after, handleTarget)), angle: arrowAngle }
242
+ : null
269
243
  });
270
244
  };
271
245
  return {
272
246
  kind: 'resize',
273
247
  pointerId: start.pointerId,
274
- move: function (input) {
248
+ move(input) {
275
249
  last = input;
276
250
  if (!started) {
277
251
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
@@ -282,21 +256,21 @@ export function createResizeGesture(context, start, handle, frame, shapes) {
282
256
  }
283
257
  apply(input);
284
258
  },
285
- end: function () {
259
+ end() {
286
260
  if (started) {
287
261
  engine.clearOverlay();
288
262
  engine.commit();
289
263
  }
290
264
  engine.setCursor(cursorForTool(engine.state.tool));
291
265
  },
292
- cancel: function () {
266
+ cancel() {
293
267
  if (started)
294
268
  engine.revertToCommitted();
295
269
  engine.setCursor(cursorForTool(engine.state.tool));
296
270
  },
297
- modifiersChanged: function (modifiers) {
271
+ modifiersChanged(modifiers) {
298
272
  if (started)
299
- apply(__assign(__assign({}, last), modifiers));
273
+ apply({ ...last, ...modifiers });
300
274
  }
301
275
  };
302
276
  }
@@ -307,34 +281,33 @@ export function createResizeGesture(context, start, handle, frame, shapes) {
307
281
  * the pointer has gone `DRAG_THRESHOLD` pixels. `source` is where the press landed: the dot (the pointer is a hand that
308
282
  * holds it) or the zone outside a corner (the turning arrow).
309
283
  */
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;
284
+ export function createRotateGesture(context, start, frame, shapes, source = 'corner') {
285
+ const { engine } = context;
286
+ const startScene = engine.state.scene;
287
+ const center = frameCenter(frame);
288
+ const startAngle = angleFromCenter(center, worldOf(context, start));
289
+ const single = shapes.length === 1 ? shapes[0] : null;
317
290
  // 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; }));
291
+ const turnedIds = new Set(shapes.map((shape) => shape.id));
319
292
  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;
293
+ let started = false;
294
+ let last = start;
295
+ const apply = (input) => {
296
+ let delta = angleFromCenter(center, worldOf(context, input)) - startAngle;
324
297
  if (input.shiftKey || input.ctrlKey || input.metaKey) {
325
298
  delta = single
326
299
  ? snapAngle(single.rotation + delta, ROTATION_SNAP_DEGREES) - single.rotation
327
300
  : snapAngle(delta, ROTATION_SNAP_DEGREES);
328
301
  }
329
- var turned = rotateShapesAbout(shapes, center, delta).map(function (shape) { return releaseUnmovedEnds(shape, turnedIds); });
302
+ const turned = rotateShapesAbout(shapes, center, delta).map((shape) => releaseUnmovedEnds(shape, turnedIds));
330
303
  engine.applyScene(withShapes(startScene, turned), 'transient');
331
- var shown = single ? normalizeDegrees(single.rotation + delta) : normalizeDegrees(delta);
304
+ const shown = single ? normalizeDegrees(single.rotation + delta) : normalizeDegrees(delta);
332
305
  engine.setOverlay({ dragging: 'rotate', readout: { kind: 'angle', degrees: Math.round(shown) % 360 } });
333
306
  };
334
307
  return {
335
308
  kind: 'rotate',
336
309
  pointerId: start.pointerId,
337
- move: function (input) {
310
+ move(input) {
338
311
  last = input;
339
312
  if (!started) {
340
313
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
@@ -343,21 +316,21 @@ export function createRotateGesture(context, start, frame, shapes, source) {
343
316
  }
344
317
  apply(input);
345
318
  },
346
- end: function () {
319
+ end() {
347
320
  if (started) {
348
321
  engine.clearOverlay();
349
322
  engine.commit();
350
323
  }
351
324
  engine.setCursor(cursorForTool(engine.state.tool));
352
325
  },
353
- cancel: function () {
326
+ cancel() {
354
327
  if (started)
355
328
  engine.revertToCommitted();
356
329
  engine.setCursor(cursorForTool(engine.state.tool));
357
330
  },
358
- modifiersChanged: function (modifiers) {
331
+ modifiersChanged(modifiers) {
359
332
  if (started)
360
- apply(__assign(__assign({}, last), modifiers));
333
+ apply({ ...last, ...modifiers });
361
334
  }
362
335
  };
363
336
  }
@@ -376,42 +349,41 @@ export function createRotateGesture(context, start, frame, shapes, source) {
376
349
  * 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
350
  */
378
351
  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);
352
+ const { engine } = context;
353
+ const startScene = engine.state.scene;
354
+ const startPoints = arrowPointsInWorld(arrow);
355
+ const otherEndBinding = handle === 'start' ? bindingOfEnd(arrow.arrow, 'end') : handle === 'end' ? bindingOfEnd(arrow.arrow, 'start') : null;
356
+ const passedOver = otherEndBinding ? new Set([otherEndBinding.targetId]) : undefined;
357
+ const grabbed = handle === 'start' ? startPoints.start : handle === 'end' ? startPoints.end : startPoints.middle;
358
+ const pressWorld = worldOf(context, start);
386
359
  // 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 };
360
+ const offset = { x: grabbed.x - pressWorld.x, y: grabbed.y - pressWorld.y };
388
361
  engine.setCursor('grabbing');
389
362
  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;
363
+ let started = false;
364
+ let last = start;
365
+ const apply = (input) => {
366
+ const pointer = worldOf(context, input);
367
+ const target = { x: pointer.x + offset.x, y: pointer.y + offset.y };
368
+ let changed;
369
+ let pick = null;
398
370
  if (handle === 'bend') {
399
371
  changed = reshapeArrow(arrow, { bend: bendTowards(startPoints.start, startPoints.end, target) });
400
372
  }
401
373
  else {
402
- var fixed = handle === 'start' ? startPoints.end : startPoints.start;
403
- var moved = input.shiftKey ? snapPointAround(fixed, target, ARROW_SNAP_DEGREES) : target;
374
+ const fixed = handle === 'start' ? startPoints.end : startPoints.start;
375
+ const moved = input.shiftKey ? snapPointAround(fixed, target, ARROW_SNAP_DEGREES) : target;
404
376
  if (!input.altKey && !input.shiftKey) {
405
377
  pick = pickArrowBinding(startScene, target, { zoom: engine.state.viewport.zoom, ignore: passedOver });
406
378
  }
407
379
  // 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 };
380
+ const change = handle === 'start' ? { start: moved, startBinding: pick?.binding ?? null } : { end: moved, endBinding: pick?.binding ?? null };
409
381
  changed = reshapeArrow(arrow, change);
410
382
  }
411
383
  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 });
384
+ engine.setOverlay({ arrowBind: pick?.hint ?? null });
413
385
  };
414
- var finish = function () {
386
+ const finish = () => {
415
387
  engine.setOverlay({ arrowBind: null });
416
388
  engine.setArrowHandleHover(null);
417
389
  engine.setCursor(cursorForTool(engine.state.tool));
@@ -419,7 +391,7 @@ export function createArrowHandleGesture(context, start, arrow, handle) {
419
391
  return {
420
392
  kind: 'arrow-handle',
421
393
  pointerId: start.pointerId,
422
- move: function (input) {
394
+ move(input) {
423
395
  last = input;
424
396
  if (!started) {
425
397
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
@@ -428,41 +400,41 @@ export function createArrowHandleGesture(context, start, arrow, handle) {
428
400
  }
429
401
  apply(input);
430
402
  },
431
- end: function () {
403
+ end() {
432
404
  if (started)
433
405
  engine.commit();
434
406
  finish();
435
407
  },
436
- cancel: function () {
408
+ cancel() {
437
409
  if (started)
438
410
  engine.revertToCommitted();
439
411
  finish();
440
412
  },
441
- modifiersChanged: function (modifiers) {
413
+ modifiersChanged(modifiers) {
442
414
  if (started)
443
- apply(__assign(__assign({}, last), modifiers));
415
+ apply({ ...last, ...modifiers });
444
416
  }
445
417
  };
446
418
  }
447
419
  // ──────────────────────────────────────────────────────────── marquee
448
420
  /** What a marquee that touches nothing hands to the overlay: the one shared empty list. */
449
- var NO_UNITS = Object.freeze([]);
421
+ const NO_UNITS = Object.freeze([]);
450
422
  /**
451
423
  * Drags a rectangle over the board. While it is dragged, what it touches is outlined the way the unit under the pointer is
452
424
  * (the overlay's `marqueeHover`), so the person sees what the release will take; the selection is made at the release, from
453
425
  * the same units (added to the ones that were selected when Shift was held at the press).
454
426
  */
455
427
  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;
428
+ const { engine } = context;
429
+ const startWorld = worldOf(context, start);
430
+ const base = start.shiftKey ? [...engine.state.selectedIds] : [];
431
+ let started = false;
460
432
  // 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
433
  // marquee that grows over nothing new wakes nothing (see `erasingMarks.ts`).
462
- var wouldSelect = NO_UNITS;
434
+ let wouldSelect = NO_UNITS;
463
435
  /** 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));
436
+ const selectionFor = (rect) => {
437
+ const units = normalizeSelection(engine.state.scene, [...base, ...engine.hitTestRect(rect, 'intersect')]);
466
438
  if (units.length === 0)
467
439
  return NO_UNITS;
468
440
  return sameIds(units, wouldSelect) ? wouldSelect : units;
@@ -470,23 +442,23 @@ export function createMarqueeGesture(context, start) {
470
442
  return {
471
443
  kind: 'marquee',
472
444
  pointerId: start.pointerId,
473
- move: function (input) {
445
+ move(input) {
474
446
  if (!started) {
475
447
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
476
448
  return;
477
449
  started = true;
478
450
  }
479
- var rect = rectFromPoints(startWorld, worldOf(context, input));
451
+ const rect = rectFromPoints(startWorld, worldOf(context, input));
480
452
  wouldSelect = selectionFor(rect);
481
453
  engine.setOverlay({ marquee: rect, marqueeHover: wouldSelect });
482
454
  },
483
- end: function (input) {
455
+ end(input) {
484
456
  // A press that never became a drag selects nothing (it cleared the selection when it began).
485
457
  if (started)
486
458
  engine.select(selectionFor(rectFromPoints(startWorld, worldOf(context, input))));
487
459
  engine.setOverlay({ marquee: null, marqueeHover: NO_UNITS });
488
460
  },
489
- cancel: function () {
461
+ cancel() {
490
462
  // Nothing was selected while it was dragged, so there is nothing to put back.
491
463
  engine.setOverlay({ marquee: null, marqueeHover: NO_UNITS });
492
464
  }
@@ -494,18 +466,17 @@ export function createMarqueeGesture(context, start) {
494
466
  }
495
467
  // ──────────────────────────────────────────────────────────── pan
496
468
  /** 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;
469
+ export function createPanGesture(context, start, options = {}) {
470
+ const { engine } = context;
471
+ let lastX = start.x;
472
+ let lastY = start.y;
473
+ let moved = false;
503
474
  engine.setCursor('grabbing');
504
- var restore = function () { return engine.setCursor(cursorForTool(engine.state.tool)); };
475
+ const restore = () => engine.setCursor(cursorForTool(engine.state.tool));
505
476
  return {
506
477
  kind: 'pan',
507
478
  pointerId: start.pointerId,
508
- move: function (input) {
479
+ move(input) {
509
480
  if (!moved && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= DRAG_THRESHOLD)
510
481
  moved = true;
511
482
  if (!moved)
@@ -514,72 +485,67 @@ export function createPanGesture(context, start, options) {
514
485
  lastX = input.x;
515
486
  lastY = input.y;
516
487
  },
517
- end: function () {
518
- var _a;
488
+ end() {
519
489
  restore();
520
490
  if (!moved)
521
- (_a = options.onTap) === null || _a === void 0 ? void 0 : _a.call(options);
491
+ options.onTap?.();
522
492
  },
523
493
  cancel: restore
524
494
  };
525
495
  }
526
496
  // ──────────────────────────────────────────────────────────── ink
527
497
  /** 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;
498
+ const PEN_PRESSURE_SPREAD = 0.02;
529
499
  /** 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;
500
+ const STRAIGHT_LINE_PRESSURE = 0.5;
531
501
  /**
532
502
  * 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
503
  * hand spends (a slow stroke swells, a quick one thins). Shift draws a straight line from where the pointer went down.
534
504
  */
535
505
  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);
506
+ const { engine } = context;
507
+ const strokeId = engine.services.createId('obj');
508
+ const isPen = start.pointerType === 'pen';
509
+ const samples = [];
510
+ let leastPressure = Infinity;
511
+ let mostPressure = -Infinity;
512
+ let straight = start.shiftKey;
513
+ let lastScreen = { x: start.x, y: start.y };
514
+ let lastInput = start;
515
+ const takeSample = (input) => {
516
+ const world = worldOf(context, input);
547
517
  // Only a pen's pressure means anything: a mouse and a finger report one fixed value while they are down.
548
518
  if (isPen && typeof input.pressure === 'number') {
549
519
  leastPressure = Math.min(leastPressure, input.pressure);
550
520
  mostPressure = Math.max(mostPressure, input.pressure);
551
- samples.push(__assign(__assign({}, world), { pressure: input.pressure }));
521
+ samples.push({ ...world, pressure: input.pressure });
552
522
  }
553
523
  else {
554
524
  samples.push(world);
555
525
  }
556
526
  };
557
527
  takeSample(start);
558
- var readsPressure = function () { return isPen && mostPressure - leastPressure >= PEN_PRESSURE_SPREAD; };
559
- var isStraight = function () { return straight && samples.length > 1; };
528
+ const readsPressure = () => isPen && mostPressure - leastPressure >= PEN_PRESSURE_SPREAD;
529
+ const isStraight = () => straight && samples.length > 1;
560
530
  /** 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) {
531
+ const lineDrawn = () => (isStraight() ? [samples[0], samples[samples.length - 1]] : samples);
532
+ const build = (finished) => {
563
533
  // 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
- })
534
+ const line = isStraight()
535
+ ? lineDrawn().map(({ x, y }) => ({ x, y, pressure: STRAIGHT_LINE_PRESSURE }))
569
536
  : samples;
570
- return buildBrushStroke(line, { createId: function () { return strokeId; }, pressure: isStraight() || readsPressure() ? 'pen' : 'speed', finished: finished });
537
+ return buildBrushStroke(line, { createId: () => strokeId, pressure: isStraight() || readsPressure() ? 'pen' : 'speed', finished });
571
538
  };
572
- var showPreview = function () { return engine.setOverlay({ preview: build(false) }); };
539
+ const showPreview = () => engine.setOverlay({ preview: build(false) });
573
540
  showPreview();
574
541
  return {
575
542
  kind: 'draw',
576
543
  pointerId: start.pointerId,
577
- move: function (input) {
544
+ move(input) {
578
545
  lastInput = input;
579
546
  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];
547
+ const moved = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
548
+ for (const sample of moved) {
583
549
  // A new sample closer than a pixel to the last one adds nothing the eye can see.
584
550
  if (Math.hypot(sample.x - lastScreen.x, sample.y - lastScreen.y) < 1)
585
551
  continue;
@@ -588,22 +554,21 @@ export function createDrawGesture(context, start) {
588
554
  }
589
555
  showPreview();
590
556
  },
591
- end: function (input) {
592
- var _a, _b;
557
+ end(input) {
593
558
  straight = input.shiftKey;
594
- var stroke = build(true);
559
+ const stroke = build(true);
595
560
  engine.clearOverlay();
596
561
  if (!stroke)
597
562
  return;
598
563
  engine.addObjects([stroke]);
599
- (_b = (_a = context.options).onStrokeFinished) === null || _b === void 0 ? void 0 : _b.call(_a, stroke, lineDrawn());
564
+ context.options.onStrokeFinished?.(stroke, lineDrawn());
600
565
  },
601
- cancel: function () {
566
+ cancel() {
602
567
  engine.clearOverlay();
603
568
  },
604
- modifiersChanged: function (modifiers) {
569
+ modifiersChanged(modifiers) {
605
570
  straight = modifiers.shiftKey;
606
- lastInput = __assign(__assign({}, lastInput), modifiers);
571
+ lastInput = { ...lastInput, ...modifiers };
607
572
  showPreview();
608
573
  }
609
574
  };
@@ -618,60 +583,57 @@ export function createDrawGesture(context, start) {
618
583
  * default arrow, tied to nothing; the two ends are never tied to the same shape.
619
584
  */
620
585
  export function createShapeGesture(context, start, kind, libraryKey) {
621
- var engine = context.engine;
622
- var id = engine.services.createId('obj');
586
+ const { engine } = context;
587
+ const id = engine.services.createId('obj');
623
588
  // 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
- };
589
+ const colorSeed = engine.services.random();
590
+ const startWorld = worldOf(context, start);
591
+ let dragged = false;
592
+ let last = start;
593
+ const pickAt = (point, ignore) => pickArrowBinding(engine.state.scene, point, { zoom: engine.state.viewport.zoom, ignore });
631
594
  // 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;
595
+ const tailPick = kind === 'arrow' && !start.altKey ? pickAt(startWorld) : null;
633
596
  if (tailPick)
634
597
  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,
598
+ const build = (input) => {
599
+ const end = worldOf(context, input);
600
+ const fromCenter = input.altKey && kind !== 'arrow' && dragged;
601
+ const shape = buildDraggedShape({
602
+ kind,
641
603
  start: fromCenter ? { x: 2 * startWorld.x - end.x, y: 2 * startWorld.y - end.y } : startWorld,
642
- end: end,
604
+ end,
643
605
  constrain: input.shiftKey,
644
- dragged: dragged,
645
- libraryKey: libraryKey,
606
+ dragged,
607
+ libraryKey,
646
608
  wireframe: engine.wireframeMode,
647
- createId: function () { return id; },
648
- random: function () { return colorSeed; },
609
+ createId: () => id,
610
+ random: () => colorSeed,
649
611
  workspacePaint: engine.workspacePaintForNewShape(engine.wireframeMode)
650
612
  });
651
613
  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);
614
+ return { shape, hint: null };
615
+ const tail = tailPick?.binding;
616
+ const headPick = input.shiftKey ? null : pickAt(end, tail ? new Set([tail.targetId]) : undefined);
655
617
  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 };
618
+ return { shape, hint: null };
619
+ const index = engine.sceneIndex();
620
+ const tied = positionBoundArrow(reshapeArrow(shape, { startBinding: tail ?? null, endBinding: headPick?.binding ?? null }), (targetId) => index.get(targetId));
621
+ return { shape: tied, hint: headPick?.hint ?? null };
660
622
  };
661
623
  return {
662
624
  kind: 'shape',
663
625
  pointerId: start.pointerId,
664
- move: function (input) {
626
+ move(input) {
665
627
  last = input;
666
628
  if (!dragged && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= MIN_DRAW_DISTANCE)
667
629
  dragged = true;
668
630
  if (dragged) {
669
- var _a = build(input), shape = _a.shape, hint = _a.hint;
631
+ const { shape, hint } = build(input);
670
632
  engine.setOverlay({ preview: shape, arrowBind: hint });
671
633
  }
672
634
  },
673
- end: function (input) {
674
- var shape = build(input).shape;
635
+ end(input) {
636
+ const { shape } = build(input);
675
637
  engine.clearOverlay();
676
638
  engine.addObjects([shape]);
677
639
  if (engine.state.stickyTool) {
@@ -682,13 +644,13 @@ export function createShapeGesture(context, start, kind, libraryKey) {
682
644
  engine.select([shape.id]);
683
645
  }
684
646
  },
685
- cancel: function () {
647
+ cancel() {
686
648
  engine.clearOverlay();
687
649
  },
688
- modifiersChanged: function (modifiers) {
650
+ modifiersChanged(modifiers) {
689
651
  if (!dragged)
690
652
  return;
691
- var _a = build(__assign(__assign({}, last), modifiers)), shape = _a.shape, hint = _a.hint;
653
+ const { shape, hint } = build({ ...last, ...modifiers });
692
654
  engine.setOverlay({ preview: shape, arrowBind: hint });
693
655
  }
694
656
  };
@@ -696,35 +658,35 @@ export function createShapeGesture(context, start, kind, libraryKey) {
696
658
  // ──────────────────────────────────────────────────────────── text
697
659
  /** A click makes a label that grows with its text, a drag makes a box of that width. Then the text is edited. */
698
660
  export function createTextGesture(context, start) {
699
- var engine = context.engine;
700
- var startWorld = worldOf(context, start);
701
- var dragged = false;
661
+ const { engine } = context;
662
+ const startWorld = worldOf(context, start);
663
+ let dragged = false;
702
664
  return {
703
665
  kind: 'text',
704
666
  pointerId: start.pointerId,
705
- move: function (input) {
667
+ move(input) {
706
668
  if (!dragged && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= MIN_DRAW_DISTANCE)
707
669
  dragged = true;
708
670
  if (dragged)
709
671
  engine.setOverlay({ textDraft: rectFromPoints(startWorld, worldOf(context, input)) });
710
672
  },
711
- end: function (input) {
673
+ end(input) {
712
674
  engine.setOverlay({ textDraft: null });
713
675
  if (!dragged) {
714
676
  engine.createText(startWorld);
715
677
  return;
716
678
  }
717
- var rect = rectFromPoints(startWorld, worldOf(context, input));
679
+ const rect = rectFromPoints(startWorld, worldOf(context, input));
718
680
  engine.createText({ x: rect.x, y: rect.y }, { width: rect.width });
719
681
  },
720
- cancel: function () {
682
+ cancel() {
721
683
  engine.setOverlay({ textDraft: null });
722
684
  }
723
685
  };
724
686
  }
725
687
  // ──────────────────────────────────────────────────────────── eraser
726
688
  /** 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;
689
+ const ERASER_MAX_STEPS_PER_SWEEP = 400;
728
690
  /**
729
691
  * Marks what the pointer passes over and removes it when the pointer is released.
730
692
  *
@@ -736,48 +698,44 @@ var ERASER_MAX_STEPS_PER_SWEEP = 400;
736
698
  * 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
699
  */
738
700
  export function createEraseGesture(context, start) {
739
- var engine = context.engine;
701
+ const { engine } = context;
740
702
  // 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 = [];
703
+ const scene = engine.state.scene;
704
+ const index = engine.sceneIndex(scene);
705
+ const startWorld = worldOf(context, start);
706
+ const zoom = () => engine.state.viewport.zoom;
707
+ const marked = [];
746
708
  // 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];
709
+ const skipped = new Set();
710
+ for (const object of scene) {
750
711
  if (object.type === 'widget' || engine.state.pending[object.id])
751
712
  skipped.add(object.id);
752
713
  }
753
714
  // 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];
715
+ const enteredGroups = new Set();
716
+ for (const object of scene) {
757
717
  if (object.type !== 'group')
758
718
  continue;
759
- var box = boundsOfObjects(scene, [object.id]);
719
+ const box = boundsOfObjects(scene, [object.id]);
760
720
  if (box && rectContainsPoint(box, startWorld))
761
721
  enteredGroups.add(object.id);
762
722
  }
763
723
  /** 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();
724
+ const unitOf = (shapeId) => {
725
+ let unit = index.get(shapeId);
726
+ const visited = new Set();
768
727
  while (unit && unit.parentId !== null && !visited.has(unit.id)) {
769
728
  visited.add(unit.id);
770
- var parent = index.get(unit.parentId);
729
+ const parent = index.get(unit.parentId);
771
730
  if (!parent || enteredGroups.has(parent.id))
772
731
  break;
773
732
  unit = parent;
774
733
  }
775
- return (_a = unit === null || unit === void 0 ? void 0 : unit.id) !== null && _a !== void 0 ? _a : shapeId;
734
+ return unit?.id ?? shapeId;
776
735
  };
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];
736
+ let marksChanged = false;
737
+ const markUnitOf = (shapeId) => {
738
+ for (const shape of leafShapesOf(scene, [unitOf(shapeId)])) {
781
739
  if (skipped.has(shape.id))
782
740
  continue;
783
741
  skipped.add(shape.id);
@@ -786,10 +744,9 @@ export function createEraseGesture(context, start) {
786
744
  }
787
745
  };
788
746
  /** 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 });
747
+ const markAt = (world, onlyTop = false) => {
748
+ for (let guard = 0; guard < 64; guard += 1) {
749
+ const hit = hitTestLeaf(scene, world, { zoom: zoom(), tolerancePixels: ERASER_RADIUS, ignore: skipped });
793
750
  if (!hit)
794
751
  break;
795
752
  markUnitOf(hit.id);
@@ -799,18 +756,18 @@ export function createEraseGesture(context, start) {
799
756
  break;
800
757
  }
801
758
  };
802
- var lastWorld = startWorld;
759
+ let lastWorld = startWorld;
803
760
  /** 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;
761
+ const sweepTo = (to) => {
762
+ const screenLength = distanceBetween(lastWorld, to) * zoom();
763
+ const steps = Math.min(ERASER_MAX_STEPS_PER_SWEEP, Math.max(1, Math.ceil(screenLength / (ERASER_RADIUS / 2))));
764
+ for (let step = 1; step <= steps; step += 1) {
765
+ const progress = step / steps;
809
766
  markAt({ x: lastWorld.x + (to.x - lastWorld.x) * progress, y: lastWorld.y + (to.y - lastWorld.y) * progress });
810
767
  }
811
768
  lastWorld = to;
812
769
  };
813
- var showMarks = function () {
770
+ const showMarks = () => {
814
771
  if (!marksChanged)
815
772
  return;
816
773
  marksChanged = false;
@@ -819,8 +776,8 @@ export function createEraseGesture(context, start) {
819
776
  // The press itself marks what is under it, so a click shows what it is about to remove.
820
777
  markAt(startWorld, start.ctrlKey || start.metaKey);
821
778
  showMarks();
822
- var dragging = false;
823
- var beginDragging = function () {
779
+ let dragging = false;
780
+ const beginDragging = () => {
824
781
  dragging = true;
825
782
  engine.beginScribble();
826
783
  // A drag takes everything under the spot where it began, also after a click that took only the top shape.
@@ -829,22 +786,21 @@ export function createEraseGesture(context, start) {
829
786
  return {
830
787
  kind: 'erase',
831
788
  pointerId: start.pointerId,
832
- move: function (input) {
789
+ move(input) {
833
790
  if (!dragging) {
834
791
  if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
835
792
  return;
836
793
  beginDragging();
837
794
  }
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);
795
+ const samples = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
796
+ for (const sample of samples) {
797
+ const world = worldOf(context, sample);
842
798
  sweepTo(world);
843
799
  engine.extendScribble(world);
844
800
  }
845
801
  showMarks();
846
802
  },
847
- end: function (input) {
803
+ end(input) {
848
804
  // The release can come with a last position no move reported.
849
805
  if (dragging)
850
806
  sweepTo(worldOf(context, input));
@@ -853,7 +809,7 @@ export function createEraseGesture(context, start) {
853
809
  if (marked.length > 0)
854
810
  engine.removeObjects(marked);
855
811
  },
856
- cancel: function () {
812
+ cancel() {
857
813
  engine.stopScribble();
858
814
  engine.clearOverlay();
859
815
  }