@widgetic/canvas 0.5.45 → 0.5.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +3 -2
  2. package/dist/canvas/DomCanvas.svelte +1 -2
  3. package/dist/canvas/autosaveScheduler.js +37 -89
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +7 -19
  7. package/dist/canvas/chromeLayout.js +19 -21
  8. package/dist/canvas/eventScope.js +10 -14
  9. package/dist/canvas/host/CanvasHost.d.ts +6 -5
  10. package/dist/canvas/host/CanvasHost.js +1664 -1861
  11. package/dist/canvas/host/CanvasHostApi.js +4 -19
  12. package/dist/canvas/host/boardFiles.js +35 -51
  13. package/dist/canvas/host/browserServices.js +108 -196
  14. package/dist/canvas/host/conversion.js +82 -170
  15. package/dist/canvas/host/hostObject.js +7 -7
  16. package/dist/canvas/host/nearCards.js +18 -21
  17. package/dist/canvas/host/pageEvents.js +5 -5
  18. package/dist/canvas/host/pauseCollector.d.ts +18 -0
  19. package/dist/canvas/host/pauseCollector.js +45 -0
  20. package/dist/canvas/host/pictureSaves.js +9 -11
  21. package/dist/canvas/host/screenRects.js +28 -31
  22. package/dist/canvas/host/storedPictures.js +149 -243
  23. package/dist/canvas/host/strokeSnap.js +88 -143
  24. package/dist/canvas/index.d.ts +1 -1
  25. package/dist/canvas/openMarks.js +2 -2
  26. package/dist/canvas/outsideClickDeselect.js +6 -7
  27. package/dist/canvas/panZoomPosition.js +2 -2
  28. package/dist/canvas/preferredTextFont.js +13 -25
  29. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  30. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  31. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  32. package/dist/canvas/toolbarPosition.js +2 -2
  33. package/dist/canvas/types.d.ts +7 -1
  34. package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
  35. package/dist/canvas/ui/CanvasHint.svelte +10 -9
  36. package/dist/canvas/ui/SelectionPanel.svelte +14 -12
  37. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
  38. package/dist/canvas/ui/ShapesMenu.svelte +6 -4
  39. package/dist/canvas/ui/ToolButton.svelte +7 -6
  40. package/dist/canvas/ui/colorModel.js +21 -32
  41. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  42. package/dist/canvas/ui/floatingCard.d.ts +28 -8
  43. package/dist/canvas/ui/floatingCard.js +48 -28
  44. package/dist/canvas/ui/floatingLayer.js +5 -6
  45. package/dist/canvas/ui/keyHints.js +9 -11
  46. package/dist/canvas/ui/popoverSide.js +2 -3
  47. package/dist/canvas/ui/selectionTraits.d.ts +8 -4
  48. package/dist/canvas/ui/selectionTraits.js +44 -58
  49. package/dist/canvas/view/CanvasStage.svelte +1 -1
  50. package/dist/canvas/view/SelectionOverlay.svelte +2 -2
  51. package/dist/canvas/view/erasingMarks.js +7 -7
  52. package/dist/canvas/view/geometry.d.ts +1 -1
  53. package/dist/canvas/view/geometry.js +72 -91
  54. package/dist/canvas/view/liftedScene.js +24 -36
  55. package/dist/canvas/view/mountedScene.js +76 -79
  56. package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
  57. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
  58. package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
  59. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
  60. package/dist/components/boardLoaderDelay.d.ts +39 -0
  61. package/dist/components/boardLoaderDelay.js +71 -0
  62. package/dist/components/input-controls/ColorIC.svelte +1 -1
  63. package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
  64. package/dist/components/preferenceStorage.js +2 -2
  65. package/dist/engine/EngineCore.d.ts +42 -10
  66. package/dist/engine/EngineCore.js +843 -916
  67. package/dist/engine/codec/canvasDocument.js +192 -155
  68. package/dist/engine/codec/hostReadableKeys.js +1 -1
  69. package/dist/engine/core/arrange.js +26 -38
  70. package/dist/engine/core/arrow.js +79 -92
  71. package/dist/engine/core/arrowBinding.js +98 -116
  72. package/dist/engine/core/arrowBindingRecords.js +23 -38
  73. package/dist/engine/core/brush.d.ts +24 -0
  74. package/dist/engine/core/brush.js +223 -103
  75. package/dist/engine/core/cameraMove.js +39 -51
  76. package/dist/engine/core/defaults.js +92 -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.js +38 -55
  80. package/dist/engine/core/hitTest.js +68 -81
  81. package/dist/engine/core/matrix.js +18 -20
  82. package/dist/engine/core/pathData.js +183 -210
  83. package/dist/engine/core/rotationReset.js +5 -6
  84. package/dist/engine/core/scene.js +160 -224
  85. package/dist/engine/core/scribble.js +59 -84
  86. package/dist/engine/core/shapePaths.js +12 -15
  87. package/dist/engine/core/shapeTools.d.ts +23 -18
  88. package/dist/engine/core/shapeTools.js +104 -67
  89. package/dist/engine/core/snapping.js +65 -117
  90. package/dist/engine/core/style.d.ts +18 -2
  91. package/dist/engine/core/style.js +79 -80
  92. package/dist/engine/core/styleMemory.d.ts +88 -0
  93. package/dist/engine/core/styleMemory.js +189 -0
  94. package/dist/engine/core/transform.js +84 -95
  95. package/dist/engine/core/types.js +4 -4
  96. package/dist/engine/core/viewport.js +23 -36
  97. package/dist/engine/input/PointerController.js +513 -526
  98. package/dist/engine/input/arrowHandles.js +12 -12
  99. package/dist/engine/input/gestures.d.ts +8 -3
  100. package/dist/engine/input/gestures.js +378 -346
  101. package/dist/engine/input/hoverCursor.js +1 -1
  102. package/dist/engine/input/keyboard.js +42 -41
  103. package/dist/engine/input/selectionHandles.js +45 -50
  104. package/dist/engine/input/types.js +1 -1
  105. package/dist/engine/render/rasterize.js +86 -158
  106. package/dist/engine/state.js +6 -17
  107. package/dist/engine/text/layoutText.js +43 -62
  108. package/dist/engine/text/textMetrics.js +8 -10
  109. package/dist/engine/widgets.js +101 -137
  110. package/dist/fonts/interFont.js +30 -83
  111. package/dist/fonts/workspaceFonts.js +33 -92
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.js +4 -4
  114. package/dist/i18n/messages.js +1 -1
  115. package/dist/i18n/shortcuts.js +14 -14
  116. package/dist/index.d.ts +1 -1
  117. package/dist/poster/boardPlacement.d.ts +4 -1
  118. package/dist/poster/boardPlacement.js +34 -33
  119. package/dist/poster/boardPoster.js +58 -83
  120. package/dist/poster/paintBoardPoster.js +16 -39
  121. package/dist/poster/posterPictures.js +27 -43
  122. package/dist/settings/rememberedStyles.d.ts +22 -0
  123. package/dist/settings/rememberedStyles.js +47 -0
  124. package/dist/settings/rememberedTool.d.ts +50 -0
  125. package/dist/settings/rememberedTool.js +68 -0
  126. package/dist/settings/workspaceToolSettings.d.ts +25 -0
  127. package/dist/settings/workspaceToolSettings.js +38 -48
  128. package/dist/tools/components/catalog.js +64 -74
  129. package/dist/tools/components/grouping.js +6 -28
  130. package/dist/tools/definitions.js +5 -5
  131. package/dist/tools/executors.js +137 -169
  132. package/dist/tools/hostAdapter.js +10 -13
  133. package/dist/tools/sceneSummary.js +43 -57
  134. package/dist/tools/sketchIntent.js +13 -21
  135. package/dist/tools/styleArguments.js +19 -21
  136. package/dist/tools/types.js +1 -1
  137. package/package.json +5 -5
@@ -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 { ARROW_ENDS, arrowSpecOf, bindingOfEnd, 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,7 +236,7 @@ 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
  /**
280
242
  * Where something the person draws goes: on top of everything, except that it stays under the widget cards. The page lays
@@ -287,25 +249,25 @@ export function addObjects(scene, objects) {
287
249
  */
288
250
  export function addObjectsBehindWidgetCards(scene, objects) {
289
251
  if (objects.length === 0)
290
- return __spreadArray([], scene, true);
291
- if (objects.some(function (object) { return object.type === 'widget' || object.parentId !== null; }))
292
- return __spreadArray(__spreadArray([], scene, true), objects, true);
293
- var lowestCard = scene.find(function (object) { return object.type === 'widget'; });
252
+ return [...scene];
253
+ if (objects.some((object) => object.type === 'widget' || object.parentId !== null))
254
+ return [...scene, ...objects];
255
+ const lowestCard = scene.find((object) => object.type === 'widget');
294
256
  if (!lowestCard)
295
- return __spreadArray(__spreadArray([], scene, true), objects, true);
257
+ return [...scene, ...objects];
296
258
  // A group comes before its members in the list: the objects go before the group that holds the card, not between its members.
297
- var unitId = topLevelAncestorId(indexScene(scene), lowestCard.id);
298
- var at = scene.findIndex(function (object) { return object.id === unitId; });
259
+ const unitId = topLevelAncestorId(indexScene(scene), lowestCard.id);
260
+ const at = scene.findIndex((object) => object.id === unitId);
299
261
  if (at < 0)
300
- return __spreadArray(__spreadArray([], scene, true), objects, true);
301
- return __spreadArray(__spreadArray(__spreadArray([], scene.slice(0, at), true), objects, true), scene.slice(at), true);
262
+ return [...scene, ...objects];
263
+ return [...scene.slice(0, at), ...objects, ...scene.slice(at)];
302
264
  }
303
265
  /** Removes the objects and everything below them, then any group left with no members. */
304
266
  export function removeObjects(scene, ids) {
305
- var doomed = withDescendantIds(scene, ids);
267
+ const doomed = withDescendantIds(scene, ids);
306
268
  if (doomed.size === 0)
307
269
  return scene;
308
- var kept = scene.filter(function (object) { return !doomed.has(object.id); });
270
+ const kept = scene.filter((object) => !doomed.has(object.id));
309
271
  if (kept.length === scene.length)
310
272
  return scene;
311
273
  return normalizeScene(kept);
@@ -316,14 +278,13 @@ export function patchObject(scene, id, patch) {
316
278
  }
317
279
  /** Changes several objects at once, each with its own patch. */
318
280
  export function patchObjects(scene, patches) {
319
- var changed = false;
320
- var next = scene.map(function (object) {
321
- var patch = patches.get(object.id);
281
+ let changed = false;
282
+ const next = scene.map((object) => {
283
+ const patch = patches.get(object.id);
322
284
  if (!patch)
323
285
  return object;
324
- var differs = false;
325
- for (var _i = 0, _a = Object.keys(patch); _i < _a.length; _i++) {
326
- var key = _a[_i];
286
+ let differs = false;
287
+ for (const key of Object.keys(patch)) {
327
288
  if (object[key] !== patch[key]) {
328
289
  differs = true;
329
290
  break;
@@ -332,24 +293,24 @@ export function patchObjects(scene, patches) {
332
293
  if (!differs)
333
294
  return object;
334
295
  changed = true;
335
- return __assign(__assign({}, object), patch);
296
+ return { ...object, ...patch };
336
297
  });
337
298
  return changed ? next : scene;
338
299
  }
339
300
  /** Replaces one record by another (its id stays the one of the record it replaces). */
340
301
  export function replaceObject(scene, id, replacement) {
341
- var changed = false;
342
- var next = scene.map(function (object) {
302
+ let changed = false;
303
+ const next = scene.map((object) => {
343
304
  if (object.id !== id)
344
305
  return object;
345
306
  changed = true;
346
- return __assign(__assign({}, replacement), { id: id, parentId: object.parentId });
307
+ return { ...replacement, id, parentId: object.parentId };
347
308
  });
348
309
  return changed ? next : scene;
349
310
  }
350
311
  /** The ids of the shapes drawn by the given objects (a group is its members at any depth): who moves when they are carried. */
351
312
  export function movingShapeIds(scene, ids) {
352
- return new Set(leafShapesOf(scene, ids).map(function (shape) { return shape.id; }));
313
+ return new Set(leafShapesOf(scene, ids).map((shape) => shape.id));
353
314
  }
354
315
  /**
355
316
  * Moves the shapes with the given ids by a distance. A drag carries the same shapes at every step: it asks `movingShapeIds`
@@ -361,11 +322,9 @@ export function movingShapeIds(scene, ids) {
361
322
  export function translateShapes(scene, moving, deltaX, deltaY) {
362
323
  if ((deltaX === 0 && deltaY === 0) || moving.size === 0)
363
324
  return scene;
364
- return scene.map(function (object) {
365
- return moving.has(object.id) && isBoxedObject(object)
366
- ? releaseUnmovedEnds(__assign(__assign({}, object), { x: object.x + deltaX, y: object.y + deltaY }), moving)
367
- : object;
368
- });
325
+ return scene.map((object) => moving.has(object.id) && isBoxedObject(object)
326
+ ? releaseUnmovedEnds({ ...object, x: object.x + deltaX, y: object.y + deltaY }, moving)
327
+ : object);
369
328
  }
370
329
  /** Moves the shapes drawn by the given objects by a distance. */
371
330
  export function translateObjects(scene, ids, deltaX, deltaY) {
@@ -382,25 +341,22 @@ export function translateObjects(scene, ids, deltaX, deltaY) {
382
341
  * the objects that are put in front of or behind the others.
383
342
  */
384
343
  export function connectedObjectIds(scene, ids) {
385
- var _a;
386
- var index = indexScene(scene);
344
+ const index = indexScene(scene);
387
345
  // Who is tied to whom, both ways: a shape knows its arrows and an arrow knows its shapes.
388
- var joined = new Map();
389
- var addNeighbour = function (id, neighbourId) {
390
- var neighbours = joined.get(id);
346
+ const joined = new Map();
347
+ const addNeighbour = (id, neighbourId) => {
348
+ const neighbours = joined.get(id);
391
349
  if (neighbours)
392
350
  neighbours.push(neighbourId);
393
351
  else
394
352
  joined.set(id, [neighbourId]);
395
353
  };
396
- for (var _i = 0, scene_9 = scene; _i < scene_9.length; _i++) {
397
- var object = scene_9[_i];
398
- var spec = arrowSpecOf(object);
354
+ for (const object of scene) {
355
+ const spec = arrowSpecOf(object);
399
356
  if (!spec)
400
357
  continue;
401
- for (var _b = 0, ARROW_ENDS_1 = ARROW_ENDS; _b < ARROW_ENDS_1.length; _b++) {
402
- var end = ARROW_ENDS_1[_b];
403
- var binding = bindingOfEnd(spec, end);
358
+ for (const end of ARROW_ENDS) {
359
+ const binding = bindingOfEnd(spec, end);
404
360
  // A tie to something that is not on the board (a board edited by hand) joins nothing.
405
361
  if (!binding || binding.targetId === object.id || !index.has(binding.targetId))
406
362
  continue;
@@ -408,15 +364,14 @@ export function connectedObjectIds(scene, ids) {
408
364
  addNeighbour(binding.targetId, object.id);
409
365
  }
410
366
  }
411
- var connected = new Set();
412
- var pending = __spreadArray([], withDescendantIds(scene, ids), true).filter(function (id) { return index.has(id); });
367
+ const connected = new Set();
368
+ const pending = [...withDescendantIds(scene, ids)].filter((id) => index.has(id));
413
369
  while (pending.length > 0) {
414
- var id = pending.pop();
370
+ const id = pending.pop();
415
371
  if (connected.has(id))
416
372
  continue;
417
373
  connected.add(id);
418
- for (var _c = 0, _d = (_a = joined.get(id)) !== null && _a !== void 0 ? _a : []; _c < _d.length; _c++) {
419
- var next = _d[_c];
374
+ for (const next of joined.get(id) ?? []) {
420
375
  if (!connected.has(next))
421
376
  pending.push(next);
422
377
  }
@@ -428,8 +383,8 @@ export function connectedObjectIds(scene, ids) {
428
383
  * or null when `id` is not under that parent at all.
429
384
  */
430
385
  export function ancestorWithin(index, id, parentId) {
431
- var current = index.get(id);
432
- var visited = new Set();
386
+ let current = index.get(id);
387
+ const visited = new Set();
433
388
  while (current && !visited.has(current.id)) {
434
389
  if (current.parentId === parentId)
435
390
  return current.id;
@@ -446,18 +401,16 @@ export function ancestorWithin(index, id, parentId) {
446
401
  * among its own siblings). In paint order, with no repeats. The same ids, normalised, when nothing is joined.
447
402
  */
448
403
  export function withConnectedObjects(scene, ids) {
449
- var selected = normalizeSelection(scene, ids);
404
+ const selected = normalizeSelection(scene, ids);
450
405
  if (selected.length === 0)
451
406
  return selected;
452
- var connected = connectedObjectIds(scene, selected);
453
- var index = indexScene(scene);
454
- var parents = new Set(selected.map(function (id) { var _a, _b; return (_b = (_a = index.get(id)) === null || _a === void 0 ? void 0 : _a.parentId) !== null && _b !== void 0 ? _b : null; }));
455
- var wanted = new Set(selected);
456
- for (var _i = 0, connected_1 = connected; _i < connected_1.length; _i++) {
457
- var id = connected_1[_i];
458
- for (var _a = 0, parents_1 = parents; _a < parents_1.length; _a++) {
459
- var parentId = parents_1[_a];
460
- var sibling = ancestorWithin(index, id, parentId);
407
+ const connected = connectedObjectIds(scene, selected);
408
+ const index = indexScene(scene);
409
+ const parents = new Set(selected.map((id) => index.get(id)?.parentId ?? null));
410
+ const wanted = new Set(selected);
411
+ for (const id of connected) {
412
+ for (const parentId of parents) {
413
+ const sibling = ancestorWithin(index, id, parentId);
461
414
  if (sibling)
462
415
  wanted.add(sibling);
463
416
  }
@@ -469,50 +422,43 @@ export function withConnectedObjects(scene, ids) {
469
422
  * group, never out of it).
470
423
  */
471
424
  export function reorderObjects(scene, ids, mode) {
472
- var _a;
473
- var moved = new Set(normalizeSelection(scene, ids));
425
+ const moved = new Set(normalizeSelection(scene, ids));
474
426
  if (moved.size === 0)
475
427
  return scene;
476
- var roots = buildSceneTree(scene);
477
- var lists = new Map();
478
- for (var _i = 0, moved_1 = moved; _i < moved_1.length; _i++) {
479
- var id = moved_1[_i];
480
- var found = findSiblingList(roots, id);
428
+ const roots = buildSceneTree(scene);
429
+ const lists = new Map();
430
+ for (const id of moved) {
431
+ const found = findSiblingList(roots, id);
481
432
  if (!found)
482
433
  continue;
483
- var set = (_a = lists.get(found.siblings)) !== null && _a !== void 0 ? _a : new Set();
434
+ const set = lists.get(found.siblings) ?? new Set();
484
435
  set.add(id);
485
436
  lists.set(found.siblings, set);
486
437
  }
487
- var _loop_1 = function (siblings, movedIds) {
488
- var _d, _e;
438
+ for (const [siblings, movedIds] of lists) {
489
439
  if (mode === 'front' || mode === 'back') {
490
- var chosen = siblings.filter(function (node) { return movedIds.has(node.object.id); });
491
- var others = siblings.filter(function (node) { return !movedIds.has(node.object.id); });
492
- siblings.splice.apply(siblings, __spreadArray([0, siblings.length], (mode === 'front' ? __spreadArray(__spreadArray([], others, true), chosen, true) : __spreadArray(__spreadArray([], chosen, true), others, true)), false));
440
+ const chosen = siblings.filter((node) => movedIds.has(node.object.id));
441
+ const others = siblings.filter((node) => !movedIds.has(node.object.id));
442
+ siblings.splice(0, siblings.length, ...(mode === 'front' ? [...others, ...chosen] : [...chosen, ...others]));
493
443
  }
494
444
  else if (mode === 'forward') {
495
445
  // From the top down, a chosen node swaps with the unchosen one above it.
496
- for (var position = siblings.length - 2; position >= 0; position -= 1) {
446
+ for (let position = siblings.length - 2; position >= 0; position -= 1) {
497
447
  if (movedIds.has(siblings[position].object.id) && !movedIds.has(siblings[position + 1].object.id)) {
498
- _d = [siblings[position + 1], siblings[position]], siblings[position] = _d[0], siblings[position + 1] = _d[1];
448
+ [siblings[position], siblings[position + 1]] = [siblings[position + 1], siblings[position]];
499
449
  }
500
450
  }
501
451
  }
502
452
  else {
503
- for (var position = 1; position < siblings.length; position += 1) {
453
+ for (let position = 1; position < siblings.length; position += 1) {
504
454
  if (movedIds.has(siblings[position].object.id) && !movedIds.has(siblings[position - 1].object.id)) {
505
- _e = [siblings[position - 1], siblings[position]], siblings[position] = _e[0], siblings[position - 1] = _e[1];
455
+ [siblings[position], siblings[position - 1]] = [siblings[position - 1], siblings[position]];
506
456
  }
507
457
  }
508
458
  }
509
- };
510
- for (var _b = 0, lists_1 = lists; _b < lists_1.length; _b++) {
511
- var _c = lists_1[_b], siblings = _c[0], movedIds = _c[1];
512
- _loop_1(siblings, movedIds);
513
459
  }
514
- var next = flattenSceneTree(roots);
515
- var unchanged = next.length === scene.length && next.every(function (object, position) { return object === scene[position]; });
460
+ const next = flattenSceneTree(roots);
461
+ const unchanged = next.length === scene.length && next.every((object, position) => object === scene[position]);
516
462
  return unchanged ? scene : next;
517
463
  }
518
464
  /**
@@ -521,65 +467,59 @@ export function reorderObjects(scene, ids, mode) {
521
467
  * are grouped whole (a selection never tears a group apart).
522
468
  * Returns null when there is nothing to group (fewer than two units).
523
469
  */
524
- export function groupObjects(scene, ids, groupId) {
525
- var _a, _b;
526
- if (groupId === void 0) { groupId = createObjectId('group'); }
527
- var selected = normalizeSelection(scene, ids);
470
+ export function groupObjects(scene, ids, groupId = createObjectId('group')) {
471
+ const selected = normalizeSelection(scene, ids);
528
472
  if (selected.length < 2)
529
473
  return null;
530
- var index = indexScene(scene);
531
- 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); });
532
- var units = sharedParent
474
+ const index = indexScene(scene);
475
+ const sharedParent = selected.every((id) => index.get(id)?.parentId === index.get(selected[0])?.parentId);
476
+ const units = sharedParent
533
477
  ? selected
534
- : Array.from(new Set(selected.map(function (id) { return topLevelAncestorId(index, id); })));
478
+ : Array.from(new Set(selected.map((id) => topLevelAncestorId(index, id))));
535
479
  if (units.length < 2)
536
480
  return null;
537
- var roots = buildSceneTree(scene);
538
- var unitNodes = units.map(function (id) { return findNode(roots, id); }).filter(function (node) { return node !== null; });
481
+ const roots = buildSceneTree(scene);
482
+ const unitNodes = units.map((id) => findNode(roots, id)).filter((node) => node !== null);
539
483
  if (unitNodes.length < 2)
540
484
  return null;
541
- var firstFound = findSiblingList(roots, unitNodes[0].object.id);
485
+ const firstFound = findSiblingList(roots, unitNodes[0].object.id);
542
486
  if (!firstFound)
543
487
  return null;
544
- var siblings = firstFound.siblings;
545
- var unitIds = new Set(unitNodes.map(function (node) { return node.object.id; }));
546
- var inOrder = siblings.filter(function (node) { return unitIds.has(node.object.id); });
488
+ const siblings = firstFound.siblings;
489
+ const unitIds = new Set(unitNodes.map((node) => node.object.id));
490
+ const inOrder = siblings.filter((node) => unitIds.has(node.object.id));
547
491
  // The group takes the place of the highest unit among its siblings.
548
- var insertAt = 0;
549
- siblings.forEach(function (node, position) {
492
+ let insertAt = 0;
493
+ siblings.forEach((node, position) => {
550
494
  if (unitIds.has(node.object.id))
551
495
  insertAt = position;
552
496
  });
553
- 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 });
554
- var groupNode = { object: group, children: inOrder };
555
- var remaining = siblings.filter(function (node) { return !unitIds.has(node.object.id); });
556
- var removedBefore = siblings.slice(0, insertAt).filter(function (node) { return unitIds.has(node.object.id); }).length;
497
+ const group = createGroupObject({ id: groupId, parentId: firstFound.parent?.object.id ?? null });
498
+ const groupNode = { object: group, children: inOrder };
499
+ const remaining = siblings.filter((node) => !unitIds.has(node.object.id));
500
+ const removedBefore = siblings.slice(0, insertAt).filter((node) => unitIds.has(node.object.id)).length;
557
501
  remaining.splice(insertAt - removedBefore, 0, groupNode);
558
- siblings.splice.apply(siblings, __spreadArray([0, siblings.length], remaining, false));
559
- return { scene: flattenSceneTree(roots), groupId: groupId };
502
+ siblings.splice(0, siblings.length, ...remaining);
503
+ return { scene: flattenSceneTree(roots), groupId };
560
504
  }
561
505
  /** Dissolves groups: their members take the group's place in the list and in its parent. */
562
506
  export function ungroupObjects(scene, ids) {
563
- var _a;
564
- var groupIds = new Set();
565
- var index = indexScene(scene);
566
- for (var _i = 0, ids_2 = ids; _i < ids_2.length; _i++) {
567
- var id = ids_2[_i];
568
- if (((_a = index.get(id)) === null || _a === void 0 ? void 0 : _a.type) === 'group')
507
+ const groupIds = new Set();
508
+ const index = indexScene(scene);
509
+ for (const id of ids) {
510
+ if (index.get(id)?.type === 'group')
569
511
  groupIds.add(id);
570
512
  }
571
513
  if (groupIds.size === 0)
572
- return { scene: scene, releasedIds: [] };
573
- var roots = buildSceneTree(scene);
574
- var releasedIds = [];
575
- var dissolve = function (nodes) {
576
- var result = [];
577
- for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
578
- var node = nodes_2[_i];
514
+ return { scene, releasedIds: [] };
515
+ const roots = buildSceneTree(scene);
516
+ const releasedIds = [];
517
+ const dissolve = (nodes) => {
518
+ const result = [];
519
+ for (const node of nodes) {
579
520
  node.children = dissolve(node.children);
580
521
  if (groupIds.has(node.object.id)) {
581
- for (var _a = 0, _b = node.children; _a < _b.length; _a++) {
582
- var child = _b[_a];
522
+ for (const child of node.children) {
583
523
  releasedIds.push(child.object.id);
584
524
  result.push(child);
585
525
  }
@@ -590,33 +530,29 @@ export function ungroupObjects(scene, ids) {
590
530
  }
591
531
  return result;
592
532
  };
593
- var dissolved = dissolve(roots);
594
- return { scene: flattenSceneTree(dissolved), releasedIds: releasedIds };
533
+ const dissolved = dissolve(roots);
534
+ return { scene: flattenSceneTree(dissolved), releasedIds };
595
535
  }
596
536
  /**
597
537
  * Copies objects (a group is copied with its members) under new ids, shifted by an offset.
598
538
  * The copies are returned in paint order, ready to be added on top of the board.
599
539
  */
600
- export function duplicateObjects(scene, ids, offset, makeId) {
601
- var _a;
602
- if (offset === void 0) { offset = { x: 0, y: 0 }; }
603
- if (makeId === void 0) { makeId = function (type) { return createObjectId(type === 'group' ? 'group' : 'obj'); }; }
604
- var sources = withDescendantIds(scene, normalizeSelection(scene, ids));
605
- var idMap = new Map();
606
- var objects = [];
607
- var rootIds = new Set(normalizeSelection(scene, ids));
608
- for (var _i = 0, scene_10 = scene; _i < scene_10.length; _i++) {
609
- var object = scene_10[_i];
540
+ export function duplicateObjects(scene, ids, offset = { x: 0, y: 0 }, makeId = (type) => createObjectId(type === 'group' ? 'group' : 'obj')) {
541
+ const sources = withDescendantIds(scene, normalizeSelection(scene, ids));
542
+ const idMap = new Map();
543
+ const objects = [];
544
+ const rootIds = new Set(normalizeSelection(scene, ids));
545
+ for (const object of scene) {
610
546
  if (!sources.has(object.id))
611
547
  continue;
612
- var copyId = makeId(object.type);
548
+ const copyId = makeId(object.type);
613
549
  idMap.set(object.id, copyId);
614
- var parentId = rootIds.has(object.id)
550
+ const parentId = rootIds.has(object.id)
615
551
  ? object.parentId
616
552
  : object.parentId !== null
617
- ? ((_a = idMap.get(object.parentId)) !== null && _a !== void 0 ? _a : null)
553
+ ? (idMap.get(object.parentId) ?? null)
618
554
  : null;
619
- var copy = __assign(__assign({}, object), { id: copyId, parentId: parentId });
555
+ const copy = { ...object, id: copyId, parentId };
620
556
  if (isBoxedObject(copy) && isBoxedObject(object)) {
621
557
  copy.x = object.x + offset.x;
622
558
  copy.y = object.y + offset.y;
@@ -624,5 +560,5 @@ export function duplicateObjects(scene, ids, offset, makeId) {
624
560
  objects.push(copy);
625
561
  }
626
562
  // 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.
627
- return { objects: objects.map(function (copy) { return remapEnds(copy, idMap); }), idMap: idMap };
563
+ return { objects: objects.map((copy) => remapEnds(copy, idMap)), idMap };
628
564
  }