@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,15 +4,14 @@
4
4
  */
5
5
  import { normalizeDegrees, normalizeSignedDegrees } from './matrix.js';
6
6
  /** How long the upright animation runs, in milliseconds. */
7
- export var ROTATION_RESET_DURATION_MS = 220;
7
+ export const ROTATION_RESET_DURATION_MS = 220;
8
8
  /** Ease-out progress in [0, 1] for `elapsed` ms since the animation started. */
9
- export function rotationResetProgress(elapsed, duration) {
10
- if (duration === void 0) { duration = ROTATION_RESET_DURATION_MS; }
11
- var t = Math.min(1, Math.max(0, elapsed / duration));
12
- return 1 - Math.pow((1 - t), 3);
9
+ export function rotationResetProgress(elapsed, duration = ROTATION_RESET_DURATION_MS) {
10
+ const t = Math.min(1, Math.max(0, elapsed / duration));
11
+ return 1 - (1 - t) ** 3;
13
12
  }
14
13
  /** Rotation in degrees after `progress` of the upright animation from `startRotation`. */
15
14
  export function rotationAfterResetProgress(startRotation, progress) {
16
- var delta = -normalizeSignedDegrees(startRotation);
15
+ const delta = -normalizeSignedDegrees(startRotation);
17
16
  return normalizeDegrees(startRotation + delta * progress);
18
17
  }
@@ -9,26 +9,6 @@
9
9
  * which keeps one rule true everywhere: a group comes first, directly followed by its members, and the
10
10
  * paint order of the board is the order of the list.
11
11
  */
12
- var __assign = (this && this.__assign) || function () {
13
- __assign = Object.assign || function(t) {
14
- for (var s, i = 1, n = arguments.length; i < n; i++) {
15
- s = arguments[i];
16
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
17
- t[p] = s[p];
18
- }
19
- return t;
20
- };
21
- return __assign.apply(this, arguments);
22
- };
23
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
24
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
25
- if (ar || !(i in from)) {
26
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
27
- ar[i] = from[i];
28
- }
29
- }
30
- return to.concat(ar || Array.prototype.slice.call(from));
31
- };
32
12
  import { releaseUnmovedEnds, remapEnds } from './arrowBindingRecords.js';
33
13
  import { brushOverflow, isBrushStroke } from './brush.js';
34
14
  import { rotatedBoxBounds, unionRects, inflateRect } from './geometry.js';
@@ -36,16 +16,13 @@ import { createGroupObject, createObjectId } from './defaults.js';
36
16
  import { isBoxedObject, isPaintedObject } from './types.js';
37
17
  // ──────────────────────────────────────────────────────────── lookup
38
18
  export function indexScene(scene) {
39
- var index = new Map();
40
- for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
41
- var object = scene_1[_i];
19
+ const index = new Map();
20
+ for (const object of scene)
42
21
  index.set(object.id, object);
43
- }
44
22
  return index;
45
23
  }
46
24
  export function findObject(scene, id) {
47
- for (var _i = 0, scene_2 = scene; _i < scene_2.length; _i++) {
48
- var object = scene_2[_i];
25
+ for (const object of scene) {
49
26
  if (object.id === id)
50
27
  return object;
51
28
  }
@@ -53,15 +30,14 @@ export function findObject(scene, id) {
53
30
  }
54
31
  /** The direct members of a group, in paint order. */
55
32
  export function childrenOf(scene, groupId) {
56
- return scene.filter(function (object) { return object.parentId === groupId; });
33
+ return scene.filter((object) => object.parentId === groupId);
57
34
  }
58
35
  /** Every object below a group, at any depth, in list order. */
59
36
  export function descendantsOf(scene, groupId) {
60
- var included = new Set([groupId]);
61
- var result = [];
37
+ const included = new Set([groupId]);
38
+ const result = [];
62
39
  // A group precedes its members in the list, so one pass finds them all.
63
- for (var _i = 0, scene_3 = scene; _i < scene_3.length; _i++) {
64
- var object = scene_3[_i];
40
+ for (const object of scene) {
65
41
  if (object.parentId !== null && included.has(object.parentId)) {
66
42
  included.add(object.id);
67
43
  result.push(object);
@@ -71,10 +47,9 @@ export function descendantsOf(scene, groupId) {
71
47
  }
72
48
  /** The ids given, plus every id below a group among them. */
73
49
  export function withDescendantIds(scene, ids) {
74
- var wanted = new Set(ids);
75
- var included = new Set(wanted);
76
- for (var _i = 0, scene_4 = scene; _i < scene_4.length; _i++) {
77
- var object = scene_4[_i];
50
+ const wanted = new Set(ids);
51
+ const included = new Set(wanted);
52
+ for (const object of scene) {
78
53
  if (object.parentId !== null && included.has(object.parentId))
79
54
  included.add(object.id);
80
55
  }
@@ -82,10 +57,9 @@ export function withDescendantIds(scene, ids) {
82
57
  }
83
58
  /** The shapes drawn by the given objects: a shape is itself, a group is its members at any depth. Unique, in paint order. */
84
59
  export function leafShapesOf(scene, ids) {
85
- var wanted = withDescendantIds(scene, ids);
86
- var shapes = [];
87
- for (var _i = 0, scene_5 = scene; _i < scene_5.length; _i++) {
88
- var object = scene_5[_i];
60
+ const wanted = withDescendantIds(scene, ids);
61
+ const shapes = [];
62
+ for (const object of scene) {
89
63
  if (wanted.has(object.id) && isBoxedObject(object))
90
64
  shapes.push(object);
91
65
  }
@@ -93,26 +67,25 @@ export function leafShapesOf(scene, ids) {
93
67
  }
94
68
  /** The group nearest to the board that contains the object, or the object itself when it is not in a group. */
95
69
  export function topLevelAncestorId(index, id) {
96
- var _a, _b;
97
- var current = index.get(id);
70
+ let current = index.get(id);
98
71
  // Most objects sit on the board itself, with nothing to climb and nothing to keep track of (a marquee asks for all of them
99
72
  // at every step of its drag).
100
73
  if (!current || current.parentId === null)
101
- return (_a = current === null || current === void 0 ? void 0 : current.id) !== null && _a !== void 0 ? _a : id;
102
- var visited = new Set();
74
+ return current?.id ?? id;
75
+ const visited = new Set();
103
76
  while (current && current.parentId !== null && !visited.has(current.id)) {
104
77
  visited.add(current.id);
105
- var parent = index.get(current.parentId);
78
+ const parent = index.get(current.parentId);
106
79
  if (!parent)
107
80
  break;
108
81
  current = parent;
109
82
  }
110
- return (_b = current === null || current === void 0 ? void 0 : current.id) !== null && _b !== void 0 ? _b : id;
83
+ return current?.id ?? id;
111
84
  }
112
85
  /** True when `id` is `ancestorId` or lies below it. */
113
86
  export function isWithin(index, id, ancestorId) {
114
- var current = index.get(id);
115
- var visited = new Set();
87
+ let current = index.get(id);
88
+ const visited = new Set();
116
89
  while (current && !visited.has(current.id)) {
117
90
  if (current.id === ancestorId)
118
91
  return true;
@@ -127,7 +100,7 @@ export function sameIds(first, second) {
127
100
  return true;
128
101
  if (first.length !== second.length)
129
102
  return false;
130
- for (var position = 0; position < first.length; position += 1) {
103
+ for (let position = 0; position < first.length; position += 1) {
131
104
  if (first[position] !== second[position])
132
105
  return false;
133
106
  }
@@ -135,29 +108,26 @@ export function sameIds(first, second) {
135
108
  }
136
109
  /** Drops ids that are not on the board, repeats, and members whose group is selected too. */
137
110
  export function normalizeSelection(scene, ids) {
138
- var _a, _b;
139
- var index = indexScene(scene);
140
- var wanted = new Set();
141
- for (var _i = 0, ids_1 = ids; _i < ids_1.length; _i++) {
142
- var id = ids_1[_i];
111
+ const index = indexScene(scene);
112
+ const wanted = new Set();
113
+ for (const id of ids) {
143
114
  if (index.has(id))
144
115
  wanted.add(id);
145
116
  }
146
- var result = [];
147
- for (var _c = 0, scene_6 = scene; _c < scene_6.length; _c++) {
148
- var object = scene_6[_c];
117
+ const result = [];
118
+ for (const object of scene) {
149
119
  if (!wanted.has(object.id))
150
120
  continue;
151
- var covered = false;
152
- var parentId = object.parentId;
153
- var visited = new Set();
121
+ let covered = false;
122
+ let parentId = object.parentId;
123
+ const visited = new Set();
154
124
  while (parentId !== null && !visited.has(parentId)) {
155
125
  if (wanted.has(parentId)) {
156
126
  covered = true;
157
127
  break;
158
128
  }
159
129
  visited.add(parentId);
160
- parentId = (_b = (_a = index.get(parentId)) === null || _a === void 0 ? void 0 : _a.parentId) !== null && _b !== void 0 ? _b : null;
130
+ parentId = index.get(parentId)?.parentId ?? null;
161
131
  }
162
132
  if (!covered)
163
133
  result.push(object.id);
@@ -171,7 +141,7 @@ export function shapeBounds(shape) {
171
141
  }
172
142
  /** The same, grown by what the stroke adds outside the outline: what a thumbnail or a screenshot must include. */
173
143
  export function shapeVisualBounds(shape) {
174
- var bounds = rotatedBoxBounds(shape);
144
+ const bounds = rotatedBoxBounds(shape);
175
145
  // A brush stroke's outline reaches past the box of its line by up to half the width of the brush at its fullest.
176
146
  if (isBrushStroke(shape))
177
147
  return inflateRect(bounds, brushOverflow(shape));
@@ -186,9 +156,8 @@ export function boundsOfObjects(scene, ids) {
186
156
  }
187
157
  /** The rectangle around every shape on the board, strokes included. Null for an empty board. */
188
158
  export function boardVisualBounds(scene) {
189
- var rectangles = [];
190
- for (var _i = 0, scene_7 = scene; _i < scene_7.length; _i++) {
191
- var object = scene_7[_i];
159
+ const rectangles = [];
160
+ for (const object of scene) {
192
161
  if (isBoxedObject(object))
193
162
  rectangles.push(shapeVisualBounds(object));
194
163
  }
@@ -196,16 +165,15 @@ export function boardVisualBounds(scene) {
196
165
  }
197
166
  // ──────────────────────────────────────────────────────────── tree
198
167
  export function buildSceneTree(scene) {
199
- var nodes = new Map();
200
- var roots = [];
201
- for (var _i = 0, scene_8 = scene; _i < scene_8.length; _i++) {
202
- var object = scene_8[_i];
168
+ const nodes = new Map();
169
+ const roots = [];
170
+ for (const object of scene) {
203
171
  // A repeated id is a corrupt file; the first record wins.
204
172
  if (nodes.has(object.id))
205
173
  continue;
206
- var node = { object: object, children: [] };
174
+ const node = { object, children: [] };
207
175
  nodes.set(object.id, node);
208
- var parent = object.parentId !== null ? nodes.get(object.parentId) : undefined;
176
+ const parent = object.parentId !== null ? nodes.get(object.parentId) : undefined;
209
177
  // A group is always before its members. An object whose group is missing (or comes later) goes to the top.
210
178
  if (parent && parent.object.type === 'group')
211
179
  parent.children.push(node);
@@ -216,28 +184,23 @@ export function buildSceneTree(scene) {
216
184
  }
217
185
  /** Writes a tree back as a list, setting every parent id to the node it hangs from. */
218
186
  export function flattenSceneTree(roots) {
219
- var result = [];
220
- var visit = function (node, parentId) {
221
- var object = node.object.parentId === parentId ? node.object : __assign(__assign({}, node.object), { parentId: parentId });
187
+ const result = [];
188
+ const visit = (node, parentId) => {
189
+ const object = node.object.parentId === parentId ? node.object : { ...node.object, parentId };
222
190
  result.push(object);
223
- for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
224
- var child = _a[_i];
191
+ for (const child of node.children)
225
192
  visit(child, object.id);
226
- }
227
193
  };
228
- for (var _i = 0, roots_1 = roots; _i < roots_1.length; _i++) {
229
- var root = roots_1[_i];
194
+ for (const root of roots)
230
195
  visit(root, null);
231
- }
232
196
  return result;
233
197
  }
234
198
  /** Repairs a list of records into a valid scene: unique ids, groups before their members, no empty groups. */
235
199
  export function normalizeScene(scene) {
236
- var roots = buildSceneTree(scene);
237
- var withoutEmptyGroups = function (nodes) {
238
- var kept = [];
239
- for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
240
- var node = nodes_1[_i];
200
+ const roots = buildSceneTree(scene);
201
+ const withoutEmptyGroups = (nodes) => {
202
+ const kept = [];
203
+ for (const node of nodes) {
241
204
  node.children = withoutEmptyGroups(node.children);
242
205
  if (node.object.type === 'group' && node.children.length === 0)
243
206
  continue;
@@ -248,11 +211,10 @@ export function normalizeScene(scene) {
248
211
  return flattenSceneTree(withoutEmptyGroups(roots));
249
212
  }
250
213
  function findNode(roots, id) {
251
- for (var _i = 0, roots_2 = roots; _i < roots_2.length; _i++) {
252
- var root = roots_2[_i];
214
+ for (const root of roots) {
253
215
  if (root.object.id === id)
254
216
  return root;
255
- var found = findNode(root.children, id);
217
+ const found = findNode(root.children, id);
256
218
  if (found)
257
219
  return found;
258
220
  }
@@ -260,11 +222,11 @@ function findNode(roots, id) {
260
222
  }
261
223
  /** The list of siblings that holds a node, and the node's place in it. */
262
224
  function findSiblingList(roots, id) {
263
- var search = function (siblings, parent) {
264
- for (var position = 0; position < siblings.length; position += 1) {
225
+ const search = (siblings, parent) => {
226
+ for (let position = 0; position < siblings.length; position += 1) {
265
227
  if (siblings[position].object.id === id)
266
- return { siblings: siblings, position: position, parent: parent };
267
- var inside = search(siblings[position].children, siblings[position]);
228
+ return { siblings, position, parent };
229
+ const inside = search(siblings[position].children, siblings[position]);
268
230
  if (inside)
269
231
  return inside;
270
232
  }
@@ -274,14 +236,14 @@ function findSiblingList(roots, id) {
274
236
  }
275
237
  // ──────────────────────────────────────────────────────────── edits
276
238
  export function addObjects(scene, objects) {
277
- return objects.length === 0 ? __spreadArray([], scene, true) : __spreadArray(__spreadArray([], scene, true), objects, true);
239
+ return objects.length === 0 ? [...scene] : [...scene, ...objects];
278
240
  }
279
241
  /** Removes the objects and everything below them, then any group left with no members. */
280
242
  export function removeObjects(scene, ids) {
281
- var doomed = withDescendantIds(scene, ids);
243
+ const doomed = withDescendantIds(scene, ids);
282
244
  if (doomed.size === 0)
283
245
  return scene;
284
- var kept = scene.filter(function (object) { return !doomed.has(object.id); });
246
+ const kept = scene.filter((object) => !doomed.has(object.id));
285
247
  if (kept.length === scene.length)
286
248
  return scene;
287
249
  return normalizeScene(kept);
@@ -292,14 +254,13 @@ export function patchObject(scene, id, patch) {
292
254
  }
293
255
  /** Changes several objects at once, each with its own patch. */
294
256
  export function patchObjects(scene, patches) {
295
- var changed = false;
296
- var next = scene.map(function (object) {
297
- var patch = patches.get(object.id);
257
+ let changed = false;
258
+ const next = scene.map((object) => {
259
+ const patch = patches.get(object.id);
298
260
  if (!patch)
299
261
  return object;
300
- var differs = false;
301
- for (var _i = 0, _a = Object.keys(patch); _i < _a.length; _i++) {
302
- var key = _a[_i];
262
+ let differs = false;
263
+ for (const key of Object.keys(patch)) {
303
264
  if (object[key] !== patch[key]) {
304
265
  differs = true;
305
266
  break;
@@ -308,24 +269,24 @@ export function patchObjects(scene, patches) {
308
269
  if (!differs)
309
270
  return object;
310
271
  changed = true;
311
- return __assign(__assign({}, object), patch);
272
+ return { ...object, ...patch };
312
273
  });
313
274
  return changed ? next : scene;
314
275
  }
315
276
  /** Replaces one record by another (its id stays the one of the record it replaces). */
316
277
  export function replaceObject(scene, id, replacement) {
317
- var changed = false;
318
- var next = scene.map(function (object) {
278
+ let changed = false;
279
+ const next = scene.map((object) => {
319
280
  if (object.id !== id)
320
281
  return object;
321
282
  changed = true;
322
- return __assign(__assign({}, replacement), { id: id, parentId: object.parentId });
283
+ return { ...replacement, id, parentId: object.parentId };
323
284
  });
324
285
  return changed ? next : scene;
325
286
  }
326
287
  /** The ids of the shapes drawn by the given objects (a group is its members at any depth): who moves when they are carried. */
327
288
  export function movingShapeIds(scene, ids) {
328
- return new Set(leafShapesOf(scene, ids).map(function (shape) { return shape.id; }));
289
+ return new Set(leafShapesOf(scene, ids).map((shape) => shape.id));
329
290
  }
330
291
  /**
331
292
  * Moves the shapes with the given ids by a distance. A drag carries the same shapes at every step: it asks `movingShapeIds`
@@ -337,11 +298,9 @@ export function movingShapeIds(scene, ids) {
337
298
  export function translateShapes(scene, moving, deltaX, deltaY) {
338
299
  if ((deltaX === 0 && deltaY === 0) || moving.size === 0)
339
300
  return scene;
340
- return scene.map(function (object) {
341
- return moving.has(object.id) && isBoxedObject(object)
342
- ? releaseUnmovedEnds(__assign(__assign({}, object), { x: object.x + deltaX, y: object.y + deltaY }), moving)
343
- : object;
344
- });
301
+ return scene.map((object) => moving.has(object.id) && isBoxedObject(object)
302
+ ? releaseUnmovedEnds({ ...object, x: object.x + deltaX, y: object.y + deltaY }, moving)
303
+ : object);
345
304
  }
346
305
  /** Moves the shapes drawn by the given objects by a distance. */
347
306
  export function translateObjects(scene, ids, deltaX, deltaY) {
@@ -354,50 +313,43 @@ export function translateObjects(scene, ids, deltaX, deltaY) {
354
313
  * group, never out of it).
355
314
  */
356
315
  export function reorderObjects(scene, ids, mode) {
357
- var _a;
358
- var moved = new Set(normalizeSelection(scene, ids));
316
+ const moved = new Set(normalizeSelection(scene, ids));
359
317
  if (moved.size === 0)
360
318
  return scene;
361
- var roots = buildSceneTree(scene);
362
- var lists = new Map();
363
- for (var _i = 0, moved_1 = moved; _i < moved_1.length; _i++) {
364
- var id = moved_1[_i];
365
- var found = findSiblingList(roots, id);
319
+ const roots = buildSceneTree(scene);
320
+ const lists = new Map();
321
+ for (const id of moved) {
322
+ const found = findSiblingList(roots, id);
366
323
  if (!found)
367
324
  continue;
368
- var set = (_a = lists.get(found.siblings)) !== null && _a !== void 0 ? _a : new Set();
325
+ const set = lists.get(found.siblings) ?? new Set();
369
326
  set.add(id);
370
327
  lists.set(found.siblings, set);
371
328
  }
372
- var _loop_1 = function (siblings, movedIds) {
373
- var _d, _e;
329
+ for (const [siblings, movedIds] of lists) {
374
330
  if (mode === 'front' || mode === 'back') {
375
- var chosen = siblings.filter(function (node) { return movedIds.has(node.object.id); });
376
- var others = siblings.filter(function (node) { return !movedIds.has(node.object.id); });
377
- siblings.splice.apply(siblings, __spreadArray([0, siblings.length], (mode === 'front' ? __spreadArray(__spreadArray([], others, true), chosen, true) : __spreadArray(__spreadArray([], chosen, true), others, true)), false));
331
+ const chosen = siblings.filter((node) => movedIds.has(node.object.id));
332
+ const others = siblings.filter((node) => !movedIds.has(node.object.id));
333
+ siblings.splice(0, siblings.length, ...(mode === 'front' ? [...others, ...chosen] : [...chosen, ...others]));
378
334
  }
379
335
  else if (mode === 'forward') {
380
336
  // From the top down, a chosen node swaps with the unchosen one above it.
381
- for (var position = siblings.length - 2; position >= 0; position -= 1) {
337
+ for (let position = siblings.length - 2; position >= 0; position -= 1) {
382
338
  if (movedIds.has(siblings[position].object.id) && !movedIds.has(siblings[position + 1].object.id)) {
383
- _d = [siblings[position + 1], siblings[position]], siblings[position] = _d[0], siblings[position + 1] = _d[1];
339
+ [siblings[position], siblings[position + 1]] = [siblings[position + 1], siblings[position]];
384
340
  }
385
341
  }
386
342
  }
387
343
  else {
388
- for (var position = 1; position < siblings.length; position += 1) {
344
+ for (let position = 1; position < siblings.length; position += 1) {
389
345
  if (movedIds.has(siblings[position].object.id) && !movedIds.has(siblings[position - 1].object.id)) {
390
- _e = [siblings[position - 1], siblings[position]], siblings[position] = _e[0], siblings[position - 1] = _e[1];
346
+ [siblings[position], siblings[position - 1]] = [siblings[position - 1], siblings[position]];
391
347
  }
392
348
  }
393
349
  }
394
- };
395
- for (var _b = 0, lists_1 = lists; _b < lists_1.length; _b++) {
396
- var _c = lists_1[_b], siblings = _c[0], movedIds = _c[1];
397
- _loop_1(siblings, movedIds);
398
350
  }
399
- var next = flattenSceneTree(roots);
400
- var unchanged = next.length === scene.length && next.every(function (object, position) { return object === scene[position]; });
351
+ const next = flattenSceneTree(roots);
352
+ const unchanged = next.length === scene.length && next.every((object, position) => object === scene[position]);
401
353
  return unchanged ? scene : next;
402
354
  }
403
355
  /**
@@ -406,65 +358,59 @@ export function reorderObjects(scene, ids, mode) {
406
358
  * are grouped whole (a selection never tears a group apart).
407
359
  * Returns null when there is nothing to group (fewer than two units).
408
360
  */
409
- export function groupObjects(scene, ids, groupId) {
410
- var _a, _b;
411
- if (groupId === void 0) { groupId = createObjectId('group'); }
412
- var selected = normalizeSelection(scene, ids);
361
+ export function groupObjects(scene, ids, groupId = createObjectId('group')) {
362
+ const selected = normalizeSelection(scene, ids);
413
363
  if (selected.length < 2)
414
364
  return null;
415
- var index = indexScene(scene);
416
- var sharedParent = selected.every(function (id) { var _a, _b; return ((_a = index.get(id)) === null || _a === void 0 ? void 0 : _a.parentId) === ((_b = index.get(selected[0])) === null || _b === void 0 ? void 0 : _b.parentId); });
417
- var units = sharedParent
365
+ const index = indexScene(scene);
366
+ const sharedParent = selected.every((id) => index.get(id)?.parentId === index.get(selected[0])?.parentId);
367
+ const units = sharedParent
418
368
  ? selected
419
- : Array.from(new Set(selected.map(function (id) { return topLevelAncestorId(index, id); })));
369
+ : Array.from(new Set(selected.map((id) => topLevelAncestorId(index, id))));
420
370
  if (units.length < 2)
421
371
  return null;
422
- var roots = buildSceneTree(scene);
423
- var unitNodes = units.map(function (id) { return findNode(roots, id); }).filter(function (node) { return node !== null; });
372
+ const roots = buildSceneTree(scene);
373
+ const unitNodes = units.map((id) => findNode(roots, id)).filter((node) => node !== null);
424
374
  if (unitNodes.length < 2)
425
375
  return null;
426
- var firstFound = findSiblingList(roots, unitNodes[0].object.id);
376
+ const firstFound = findSiblingList(roots, unitNodes[0].object.id);
427
377
  if (!firstFound)
428
378
  return null;
429
- var siblings = firstFound.siblings;
430
- var unitIds = new Set(unitNodes.map(function (node) { return node.object.id; }));
431
- var inOrder = siblings.filter(function (node) { return unitIds.has(node.object.id); });
379
+ const siblings = firstFound.siblings;
380
+ const unitIds = new Set(unitNodes.map((node) => node.object.id));
381
+ const inOrder = siblings.filter((node) => unitIds.has(node.object.id));
432
382
  // The group takes the place of the highest unit among its siblings.
433
- var insertAt = 0;
434
- siblings.forEach(function (node, position) {
383
+ let insertAt = 0;
384
+ siblings.forEach((node, position) => {
435
385
  if (unitIds.has(node.object.id))
436
386
  insertAt = position;
437
387
  });
438
- var group = createGroupObject({ id: groupId, parentId: (_b = (_a = firstFound.parent) === null || _a === void 0 ? void 0 : _a.object.id) !== null && _b !== void 0 ? _b : null });
439
- var groupNode = { object: group, children: inOrder };
440
- var remaining = siblings.filter(function (node) { return !unitIds.has(node.object.id); });
441
- var removedBefore = siblings.slice(0, insertAt).filter(function (node) { return unitIds.has(node.object.id); }).length;
388
+ const group = createGroupObject({ id: groupId, parentId: firstFound.parent?.object.id ?? null });
389
+ const groupNode = { object: group, children: inOrder };
390
+ const remaining = siblings.filter((node) => !unitIds.has(node.object.id));
391
+ const removedBefore = siblings.slice(0, insertAt).filter((node) => unitIds.has(node.object.id)).length;
442
392
  remaining.splice(insertAt - removedBefore, 0, groupNode);
443
- siblings.splice.apply(siblings, __spreadArray([0, siblings.length], remaining, false));
444
- return { scene: flattenSceneTree(roots), groupId: groupId };
393
+ siblings.splice(0, siblings.length, ...remaining);
394
+ return { scene: flattenSceneTree(roots), groupId };
445
395
  }
446
396
  /** Dissolves groups: their members take the group's place in the list and in its parent. */
447
397
  export function ungroupObjects(scene, ids) {
448
- var _a;
449
- var groupIds = new Set();
450
- var index = indexScene(scene);
451
- for (var _i = 0, ids_2 = ids; _i < ids_2.length; _i++) {
452
- var id = ids_2[_i];
453
- if (((_a = index.get(id)) === null || _a === void 0 ? void 0 : _a.type) === 'group')
398
+ const groupIds = new Set();
399
+ const index = indexScene(scene);
400
+ for (const id of ids) {
401
+ if (index.get(id)?.type === 'group')
454
402
  groupIds.add(id);
455
403
  }
456
404
  if (groupIds.size === 0)
457
- return { scene: scene, releasedIds: [] };
458
- var roots = buildSceneTree(scene);
459
- var releasedIds = [];
460
- var dissolve = function (nodes) {
461
- var result = [];
462
- for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
463
- var node = nodes_2[_i];
405
+ return { scene, releasedIds: [] };
406
+ const roots = buildSceneTree(scene);
407
+ const releasedIds = [];
408
+ const dissolve = (nodes) => {
409
+ const result = [];
410
+ for (const node of nodes) {
464
411
  node.children = dissolve(node.children);
465
412
  if (groupIds.has(node.object.id)) {
466
- for (var _a = 0, _b = node.children; _a < _b.length; _a++) {
467
- var child = _b[_a];
413
+ for (const child of node.children) {
468
414
  releasedIds.push(child.object.id);
469
415
  result.push(child);
470
416
  }
@@ -475,33 +421,29 @@ export function ungroupObjects(scene, ids) {
475
421
  }
476
422
  return result;
477
423
  };
478
- var dissolved = dissolve(roots);
479
- return { scene: flattenSceneTree(dissolved), releasedIds: releasedIds };
424
+ const dissolved = dissolve(roots);
425
+ return { scene: flattenSceneTree(dissolved), releasedIds };
480
426
  }
481
427
  /**
482
428
  * Copies objects (a group is copied with its members) under new ids, shifted by an offset.
483
429
  * The copies are returned in paint order, ready to be added on top of the board.
484
430
  */
485
- export function duplicateObjects(scene, ids, offset, makeId) {
486
- var _a;
487
- if (offset === void 0) { offset = { x: 0, y: 0 }; }
488
- if (makeId === void 0) { makeId = function (type) { return createObjectId(type === 'group' ? 'group' : 'obj'); }; }
489
- var sources = withDescendantIds(scene, normalizeSelection(scene, ids));
490
- var idMap = new Map();
491
- var objects = [];
492
- var rootIds = new Set(normalizeSelection(scene, ids));
493
- for (var _i = 0, scene_9 = scene; _i < scene_9.length; _i++) {
494
- var object = scene_9[_i];
431
+ export function duplicateObjects(scene, ids, offset = { x: 0, y: 0 }, makeId = (type) => createObjectId(type === 'group' ? 'group' : 'obj')) {
432
+ const sources = withDescendantIds(scene, normalizeSelection(scene, ids));
433
+ const idMap = new Map();
434
+ const objects = [];
435
+ const rootIds = new Set(normalizeSelection(scene, ids));
436
+ for (const object of scene) {
495
437
  if (!sources.has(object.id))
496
438
  continue;
497
- var copyId = makeId(object.type);
439
+ const copyId = makeId(object.type);
498
440
  idMap.set(object.id, copyId);
499
- var parentId = rootIds.has(object.id)
441
+ const parentId = rootIds.has(object.id)
500
442
  ? object.parentId
501
443
  : object.parentId !== null
502
- ? ((_a = idMap.get(object.parentId)) !== null && _a !== void 0 ? _a : null)
444
+ ? (idMap.get(object.parentId) ?? null)
503
445
  : null;
504
- var copy = __assign(__assign({}, object), { id: copyId, parentId: parentId });
446
+ const copy = { ...object, id: copyId, parentId };
505
447
  if (isBoxedObject(copy) && isBoxedObject(object)) {
506
448
  copy.x = object.x + offset.x;
507
449
  copy.y = object.y + offset.y;
@@ -509,5 +451,5 @@ export function duplicateObjects(scene, ids, offset, makeId) {
509
451
  objects.push(copy);
510
452
  }
511
453
  // An arrow that was tied to a shape that is copied with it is tied to the copy; one whose shape stays behind is let go.
512
- return { objects: objects.map(function (copy) { return remapEnds(copy, idMap); }), idMap: idMap };
454
+ return { objects: objects.map((copy) => remapEnds(copy, idMap)), idMap };
513
455
  }