@widgetic/canvas 0.5.43 → 0.5.45
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.
- package/dist/canvas/DomCanvas.svelte +56 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -28
- package/dist/canvas/autosaveScheduler.js +89 -37
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +19 -7
- package/dist/canvas/chromeLayout.js +21 -19
- package/dist/canvas/eventScope.js +14 -10
- package/dist/canvas/host/CanvasHost.d.ts +87 -2
- package/dist/canvas/host/CanvasHost.js +1948 -1394
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +32 -5
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +155 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +211 -65
- package/dist/canvas/host/conversion.js +170 -82
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +21 -18
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pictureSaves.js +11 -9
- package/dist/canvas/host/screenRects.js +31 -28
- package/dist/canvas/host/storedPictures.js +243 -149
- package/dist/canvas/host/strokeSnap.js +143 -88
- package/dist/canvas/index.d.ts +2 -0
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +7 -6
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +25 -13
- package/dist/canvas/shapes/ShapeLibrary.js +148 -138
- package/dist/canvas/shapes/shapeImageStore.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +17 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
- package/dist/canvas/ui/ColorField.svelte +7 -2
- package/dist/canvas/ui/SelectionPanel.svelte +105 -42
- package/dist/canvas/ui/ShapesMenu.svelte +65 -31
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
- package/dist/canvas/ui/ToolButton.svelte +35 -54
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/colorModel.js +32 -21
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +43 -21
- package/dist/canvas/ui/floatingLayer.js +6 -5
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/keyHints.js +11 -9
- package/dist/canvas/ui/popoverSide.js +3 -2
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +66 -35
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
- package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
- package/dist/canvas/view/CanvasStage.svelte +7 -2
- package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
- package/dist/canvas/view/SelectionOverlay.svelte +17 -10
- package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +90 -71
- package/dist/canvas/view/liftedScene.js +36 -24
- package/dist/canvas/view/mountedScene.js +79 -76
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +111 -2
- package/dist/engine/EngineCore.js +1013 -707
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +172 -186
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +38 -26
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +109 -84
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +126 -101
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +48 -29
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +98 -78
- package/dist/engine/core/cameraMove.d.ts +73 -0
- package/dist/engine/core/cameraMove.js +172 -0
- package/dist/engine/core/defaults.js +51 -90
- package/dist/engine/core/freehand.js +163 -147
- package/dist/engine/core/geometry.js +54 -47
- package/dist/engine/core/history.js +55 -38
- package/dist/engine/core/hitTest.js +81 -68
- package/dist/engine/core/matrix.js +20 -18
- package/dist/engine/core/pathData.js +210 -183
- package/dist/engine/core/rotationReset.js +6 -5
- package/dist/engine/core/scene.d.ts +22 -0
- package/dist/engine/core/scene.js +288 -139
- package/dist/engine/core/scribble.js +84 -59
- package/dist/engine/core/shapePaths.js +15 -12
- package/dist/engine/core/shapeTools.js +63 -72
- package/dist/engine/core/snapping.js +117 -65
- package/dist/engine/core/style.d.ts +10 -0
- package/dist/engine/core/style.js +82 -33
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +103 -83
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +36 -23
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +549 -466
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +340 -266
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +131 -32
- package/dist/engine/input/selectionHandles.js +50 -45
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +158 -86
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +25 -4
- package/dist/engine/text/layoutText.js +62 -43
- package/dist/engine/text/textMetrics.js +10 -8
- package/dist/engine/widgets.js +137 -101
- package/dist/fonts/interFont.js +83 -30
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +108 -34
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +7 -1
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +30 -26
- package/dist/index.d.ts +2 -1
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +140 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +251 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +112 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +138 -0
- package/dist/settings/workspaceToolSettings.d.ts +6 -0
- package/dist/settings/workspaceToolSettings.js +58 -34
- package/dist/tools/components/catalog.js +74 -64
- package/dist/tools/components/grouping.js +28 -6
- package/dist/tools/definitions.js +31 -9
- package/dist/tools/executors.js +214 -106
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +15 -11
- package/dist/tools/sceneSummary.js +57 -43
- package/dist/tools/sketchIntent.js +21 -13
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +93 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +2 -1
- package/package.json +1 -1
|
@@ -9,20 +9,43 @@
|
|
|
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
|
-
|
|
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
|
+
import { ARROW_ENDS, arrowSpecOf, bindingOfEnd, releaseUnmovedEnds, remapEnds } from './arrowBindingRecords.js';
|
|
13
33
|
import { brushOverflow, isBrushStroke } from './brush.js';
|
|
14
34
|
import { rotatedBoxBounds, unionRects, inflateRect } from './geometry.js';
|
|
15
35
|
import { createGroupObject, createObjectId } from './defaults.js';
|
|
16
36
|
import { isBoxedObject, isPaintedObject } from './types.js';
|
|
17
37
|
// ──────────────────────────────────────────────────────────── lookup
|
|
18
38
|
export function indexScene(scene) {
|
|
19
|
-
|
|
20
|
-
for (
|
|
39
|
+
var index = new Map();
|
|
40
|
+
for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
|
|
41
|
+
var object = scene_1[_i];
|
|
21
42
|
index.set(object.id, object);
|
|
43
|
+
}
|
|
22
44
|
return index;
|
|
23
45
|
}
|
|
24
46
|
export function findObject(scene, id) {
|
|
25
|
-
for (
|
|
47
|
+
for (var _i = 0, scene_2 = scene; _i < scene_2.length; _i++) {
|
|
48
|
+
var object = scene_2[_i];
|
|
26
49
|
if (object.id === id)
|
|
27
50
|
return object;
|
|
28
51
|
}
|
|
@@ -30,14 +53,15 @@ export function findObject(scene, id) {
|
|
|
30
53
|
}
|
|
31
54
|
/** The direct members of a group, in paint order. */
|
|
32
55
|
export function childrenOf(scene, groupId) {
|
|
33
|
-
return scene.filter((object)
|
|
56
|
+
return scene.filter(function (object) { return object.parentId === groupId; });
|
|
34
57
|
}
|
|
35
58
|
/** Every object below a group, at any depth, in list order. */
|
|
36
59
|
export function descendantsOf(scene, groupId) {
|
|
37
|
-
|
|
38
|
-
|
|
60
|
+
var included = new Set([groupId]);
|
|
61
|
+
var result = [];
|
|
39
62
|
// A group precedes its members in the list, so one pass finds them all.
|
|
40
|
-
for (
|
|
63
|
+
for (var _i = 0, scene_3 = scene; _i < scene_3.length; _i++) {
|
|
64
|
+
var object = scene_3[_i];
|
|
41
65
|
if (object.parentId !== null && included.has(object.parentId)) {
|
|
42
66
|
included.add(object.id);
|
|
43
67
|
result.push(object);
|
|
@@ -47,9 +71,10 @@ export function descendantsOf(scene, groupId) {
|
|
|
47
71
|
}
|
|
48
72
|
/** The ids given, plus every id below a group among them. */
|
|
49
73
|
export function withDescendantIds(scene, ids) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
for (
|
|
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];
|
|
53
78
|
if (object.parentId !== null && included.has(object.parentId))
|
|
54
79
|
included.add(object.id);
|
|
55
80
|
}
|
|
@@ -57,9 +82,10 @@ export function withDescendantIds(scene, ids) {
|
|
|
57
82
|
}
|
|
58
83
|
/** The shapes drawn by the given objects: a shape is itself, a group is its members at any depth. Unique, in paint order. */
|
|
59
84
|
export function leafShapesOf(scene, ids) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for (
|
|
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];
|
|
63
89
|
if (wanted.has(object.id) && isBoxedObject(object))
|
|
64
90
|
shapes.push(object);
|
|
65
91
|
}
|
|
@@ -67,25 +93,26 @@ export function leafShapesOf(scene, ids) {
|
|
|
67
93
|
}
|
|
68
94
|
/** The group nearest to the board that contains the object, or the object itself when it is not in a group. */
|
|
69
95
|
export function topLevelAncestorId(index, id) {
|
|
70
|
-
|
|
96
|
+
var _a, _b;
|
|
97
|
+
var current = index.get(id);
|
|
71
98
|
// Most objects sit on the board itself, with nothing to climb and nothing to keep track of (a marquee asks for all of them
|
|
72
99
|
// at every step of its drag).
|
|
73
100
|
if (!current || current.parentId === null)
|
|
74
|
-
return current
|
|
75
|
-
|
|
101
|
+
return (_a = current === null || current === void 0 ? void 0 : current.id) !== null && _a !== void 0 ? _a : id;
|
|
102
|
+
var visited = new Set();
|
|
76
103
|
while (current && current.parentId !== null && !visited.has(current.id)) {
|
|
77
104
|
visited.add(current.id);
|
|
78
|
-
|
|
105
|
+
var parent = index.get(current.parentId);
|
|
79
106
|
if (!parent)
|
|
80
107
|
break;
|
|
81
108
|
current = parent;
|
|
82
109
|
}
|
|
83
|
-
return current
|
|
110
|
+
return (_b = current === null || current === void 0 ? void 0 : current.id) !== null && _b !== void 0 ? _b : id;
|
|
84
111
|
}
|
|
85
112
|
/** True when `id` is `ancestorId` or lies below it. */
|
|
86
113
|
export function isWithin(index, id, ancestorId) {
|
|
87
|
-
|
|
88
|
-
|
|
114
|
+
var current = index.get(id);
|
|
115
|
+
var visited = new Set();
|
|
89
116
|
while (current && !visited.has(current.id)) {
|
|
90
117
|
if (current.id === ancestorId)
|
|
91
118
|
return true;
|
|
@@ -100,7 +127,7 @@ export function sameIds(first, second) {
|
|
|
100
127
|
return true;
|
|
101
128
|
if (first.length !== second.length)
|
|
102
129
|
return false;
|
|
103
|
-
for (
|
|
130
|
+
for (var position = 0; position < first.length; position += 1) {
|
|
104
131
|
if (first[position] !== second[position])
|
|
105
132
|
return false;
|
|
106
133
|
}
|
|
@@ -108,26 +135,29 @@ export function sameIds(first, second) {
|
|
|
108
135
|
}
|
|
109
136
|
/** Drops ids that are not on the board, repeats, and members whose group is selected too. */
|
|
110
137
|
export function normalizeSelection(scene, ids) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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];
|
|
114
143
|
if (index.has(id))
|
|
115
144
|
wanted.add(id);
|
|
116
145
|
}
|
|
117
|
-
|
|
118
|
-
for (
|
|
146
|
+
var result = [];
|
|
147
|
+
for (var _c = 0, scene_6 = scene; _c < scene_6.length; _c++) {
|
|
148
|
+
var object = scene_6[_c];
|
|
119
149
|
if (!wanted.has(object.id))
|
|
120
150
|
continue;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
151
|
+
var covered = false;
|
|
152
|
+
var parentId = object.parentId;
|
|
153
|
+
var visited = new Set();
|
|
124
154
|
while (parentId !== null && !visited.has(parentId)) {
|
|
125
155
|
if (wanted.has(parentId)) {
|
|
126
156
|
covered = true;
|
|
127
157
|
break;
|
|
128
158
|
}
|
|
129
159
|
visited.add(parentId);
|
|
130
|
-
parentId = index.get(parentId)
|
|
160
|
+
parentId = (_b = (_a = index.get(parentId)) === null || _a === void 0 ? void 0 : _a.parentId) !== null && _b !== void 0 ? _b : null;
|
|
131
161
|
}
|
|
132
162
|
if (!covered)
|
|
133
163
|
result.push(object.id);
|
|
@@ -141,7 +171,7 @@ export function shapeBounds(shape) {
|
|
|
141
171
|
}
|
|
142
172
|
/** The same, grown by what the stroke adds outside the outline: what a thumbnail or a screenshot must include. */
|
|
143
173
|
export function shapeVisualBounds(shape) {
|
|
144
|
-
|
|
174
|
+
var bounds = rotatedBoxBounds(shape);
|
|
145
175
|
// A brush stroke's outline reaches past the box of its line by up to half the width of the brush at its fullest.
|
|
146
176
|
if (isBrushStroke(shape))
|
|
147
177
|
return inflateRect(bounds, brushOverflow(shape));
|
|
@@ -156,8 +186,9 @@ export function boundsOfObjects(scene, ids) {
|
|
|
156
186
|
}
|
|
157
187
|
/** The rectangle around every shape on the board, strokes included. Null for an empty board. */
|
|
158
188
|
export function boardVisualBounds(scene) {
|
|
159
|
-
|
|
160
|
-
for (
|
|
189
|
+
var rectangles = [];
|
|
190
|
+
for (var _i = 0, scene_7 = scene; _i < scene_7.length; _i++) {
|
|
191
|
+
var object = scene_7[_i];
|
|
161
192
|
if (isBoxedObject(object))
|
|
162
193
|
rectangles.push(shapeVisualBounds(object));
|
|
163
194
|
}
|
|
@@ -165,15 +196,16 @@ export function boardVisualBounds(scene) {
|
|
|
165
196
|
}
|
|
166
197
|
// ──────────────────────────────────────────────────────────── tree
|
|
167
198
|
export function buildSceneTree(scene) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
for (
|
|
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];
|
|
171
203
|
// A repeated id is a corrupt file; the first record wins.
|
|
172
204
|
if (nodes.has(object.id))
|
|
173
205
|
continue;
|
|
174
|
-
|
|
206
|
+
var node = { object: object, children: [] };
|
|
175
207
|
nodes.set(object.id, node);
|
|
176
|
-
|
|
208
|
+
var parent = object.parentId !== null ? nodes.get(object.parentId) : undefined;
|
|
177
209
|
// A group is always before its members. An object whose group is missing (or comes later) goes to the top.
|
|
178
210
|
if (parent && parent.object.type === 'group')
|
|
179
211
|
parent.children.push(node);
|
|
@@ -184,23 +216,28 @@ export function buildSceneTree(scene) {
|
|
|
184
216
|
}
|
|
185
217
|
/** Writes a tree back as a list, setting every parent id to the node it hangs from. */
|
|
186
218
|
export function flattenSceneTree(roots) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
219
|
+
var result = [];
|
|
220
|
+
var visit = function (node, parentId) {
|
|
221
|
+
var object = node.object.parentId === parentId ? node.object : __assign(__assign({}, node.object), { parentId: parentId });
|
|
190
222
|
result.push(object);
|
|
191
|
-
for (
|
|
223
|
+
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
|
224
|
+
var child = _a[_i];
|
|
192
225
|
visit(child, object.id);
|
|
226
|
+
}
|
|
193
227
|
};
|
|
194
|
-
for (
|
|
228
|
+
for (var _i = 0, roots_1 = roots; _i < roots_1.length; _i++) {
|
|
229
|
+
var root = roots_1[_i];
|
|
195
230
|
visit(root, null);
|
|
231
|
+
}
|
|
196
232
|
return result;
|
|
197
233
|
}
|
|
198
234
|
/** Repairs a list of records into a valid scene: unique ids, groups before their members, no empty groups. */
|
|
199
235
|
export function normalizeScene(scene) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
for (
|
|
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];
|
|
204
241
|
node.children = withoutEmptyGroups(node.children);
|
|
205
242
|
if (node.object.type === 'group' && node.children.length === 0)
|
|
206
243
|
continue;
|
|
@@ -211,10 +248,11 @@ export function normalizeScene(scene) {
|
|
|
211
248
|
return flattenSceneTree(withoutEmptyGroups(roots));
|
|
212
249
|
}
|
|
213
250
|
function findNode(roots, id) {
|
|
214
|
-
for (
|
|
251
|
+
for (var _i = 0, roots_2 = roots; _i < roots_2.length; _i++) {
|
|
252
|
+
var root = roots_2[_i];
|
|
215
253
|
if (root.object.id === id)
|
|
216
254
|
return root;
|
|
217
|
-
|
|
255
|
+
var found = findNode(root.children, id);
|
|
218
256
|
if (found)
|
|
219
257
|
return found;
|
|
220
258
|
}
|
|
@@ -222,11 +260,11 @@ function findNode(roots, id) {
|
|
|
222
260
|
}
|
|
223
261
|
/** The list of siblings that holds a node, and the node's place in it. */
|
|
224
262
|
function findSiblingList(roots, id) {
|
|
225
|
-
|
|
226
|
-
for (
|
|
263
|
+
var search = function (siblings, parent) {
|
|
264
|
+
for (var position = 0; position < siblings.length; position += 1) {
|
|
227
265
|
if (siblings[position].object.id === id)
|
|
228
|
-
return { siblings, position, parent };
|
|
229
|
-
|
|
266
|
+
return { siblings: siblings, position: position, parent: parent };
|
|
267
|
+
var inside = search(siblings[position].children, siblings[position]);
|
|
230
268
|
if (inside)
|
|
231
269
|
return inside;
|
|
232
270
|
}
|
|
@@ -236,7 +274,7 @@ function findSiblingList(roots, id) {
|
|
|
236
274
|
}
|
|
237
275
|
// ──────────────────────────────────────────────────────────── edits
|
|
238
276
|
export function addObjects(scene, objects) {
|
|
239
|
-
return objects.length === 0 ? [
|
|
277
|
+
return objects.length === 0 ? __spreadArray([], scene, true) : __spreadArray(__spreadArray([], scene, true), objects, true);
|
|
240
278
|
}
|
|
241
279
|
/**
|
|
242
280
|
* Where something the person draws goes: on top of everything, except that it stays under the widget cards. The page lays
|
|
@@ -249,25 +287,25 @@ export function addObjects(scene, objects) {
|
|
|
249
287
|
*/
|
|
250
288
|
export function addObjectsBehindWidgetCards(scene, objects) {
|
|
251
289
|
if (objects.length === 0)
|
|
252
|
-
return [
|
|
253
|
-
if (objects.some((object)
|
|
254
|
-
return [
|
|
255
|
-
|
|
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'; });
|
|
256
294
|
if (!lowestCard)
|
|
257
|
-
return [
|
|
295
|
+
return __spreadArray(__spreadArray([], scene, true), objects, true);
|
|
258
296
|
// A group comes before its members in the list: the objects go before the group that holds the card, not between its members.
|
|
259
|
-
|
|
260
|
-
|
|
297
|
+
var unitId = topLevelAncestorId(indexScene(scene), lowestCard.id);
|
|
298
|
+
var at = scene.findIndex(function (object) { return object.id === unitId; });
|
|
261
299
|
if (at < 0)
|
|
262
|
-
return [
|
|
263
|
-
return [
|
|
300
|
+
return __spreadArray(__spreadArray([], scene, true), objects, true);
|
|
301
|
+
return __spreadArray(__spreadArray(__spreadArray([], scene.slice(0, at), true), objects, true), scene.slice(at), true);
|
|
264
302
|
}
|
|
265
303
|
/** Removes the objects and everything below them, then any group left with no members. */
|
|
266
304
|
export function removeObjects(scene, ids) {
|
|
267
|
-
|
|
305
|
+
var doomed = withDescendantIds(scene, ids);
|
|
268
306
|
if (doomed.size === 0)
|
|
269
307
|
return scene;
|
|
270
|
-
|
|
308
|
+
var kept = scene.filter(function (object) { return !doomed.has(object.id); });
|
|
271
309
|
if (kept.length === scene.length)
|
|
272
310
|
return scene;
|
|
273
311
|
return normalizeScene(kept);
|
|
@@ -278,13 +316,14 @@ export function patchObject(scene, id, patch) {
|
|
|
278
316
|
}
|
|
279
317
|
/** Changes several objects at once, each with its own patch. */
|
|
280
318
|
export function patchObjects(scene, patches) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
319
|
+
var changed = false;
|
|
320
|
+
var next = scene.map(function (object) {
|
|
321
|
+
var patch = patches.get(object.id);
|
|
284
322
|
if (!patch)
|
|
285
323
|
return object;
|
|
286
|
-
|
|
287
|
-
for (
|
|
324
|
+
var differs = false;
|
|
325
|
+
for (var _i = 0, _a = Object.keys(patch); _i < _a.length; _i++) {
|
|
326
|
+
var key = _a[_i];
|
|
288
327
|
if (object[key] !== patch[key]) {
|
|
289
328
|
differs = true;
|
|
290
329
|
break;
|
|
@@ -293,24 +332,24 @@ export function patchObjects(scene, patches) {
|
|
|
293
332
|
if (!differs)
|
|
294
333
|
return object;
|
|
295
334
|
changed = true;
|
|
296
|
-
return {
|
|
335
|
+
return __assign(__assign({}, object), patch);
|
|
297
336
|
});
|
|
298
337
|
return changed ? next : scene;
|
|
299
338
|
}
|
|
300
339
|
/** Replaces one record by another (its id stays the one of the record it replaces). */
|
|
301
340
|
export function replaceObject(scene, id, replacement) {
|
|
302
|
-
|
|
303
|
-
|
|
341
|
+
var changed = false;
|
|
342
|
+
var next = scene.map(function (object) {
|
|
304
343
|
if (object.id !== id)
|
|
305
344
|
return object;
|
|
306
345
|
changed = true;
|
|
307
|
-
return {
|
|
346
|
+
return __assign(__assign({}, replacement), { id: id, parentId: object.parentId });
|
|
308
347
|
});
|
|
309
348
|
return changed ? next : scene;
|
|
310
349
|
}
|
|
311
350
|
/** The ids of the shapes drawn by the given objects (a group is its members at any depth): who moves when they are carried. */
|
|
312
351
|
export function movingShapeIds(scene, ids) {
|
|
313
|
-
return new Set(leafShapesOf(scene, ids).map((shape)
|
|
352
|
+
return new Set(leafShapesOf(scene, ids).map(function (shape) { return shape.id; }));
|
|
314
353
|
}
|
|
315
354
|
/**
|
|
316
355
|
* Moves the shapes with the given ids by a distance. A drag carries the same shapes at every step: it asks `movingShapeIds`
|
|
@@ -322,9 +361,11 @@ export function movingShapeIds(scene, ids) {
|
|
|
322
361
|
export function translateShapes(scene, moving, deltaX, deltaY) {
|
|
323
362
|
if ((deltaX === 0 && deltaY === 0) || moving.size === 0)
|
|
324
363
|
return scene;
|
|
325
|
-
return scene.map(
|
|
326
|
-
|
|
327
|
-
|
|
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
|
+
});
|
|
328
369
|
}
|
|
329
370
|
/** Moves the shapes drawn by the given objects by a distance. */
|
|
330
371
|
export function translateObjects(scene, ids, deltaX, deltaY) {
|
|
@@ -332,48 +373,146 @@ export function translateObjects(scene, ids, deltaX, deltaY) {
|
|
|
332
373
|
return scene;
|
|
333
374
|
return translateShapes(scene, movingShapeIds(scene, ids), deltaX, deltaY);
|
|
334
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* What is joined to the given objects by arrows, at any distance: an arrow and the shapes its ends are tied to, the other arrows
|
|
378
|
+
* tied to those shapes, and so on to the last one. The given objects come back too (and the members of a group among them: a group
|
|
379
|
+
* stands for the shapes inside it, so an arrow tied to one of its members joins the whole group to what is at the arrow's other end).
|
|
380
|
+
*
|
|
381
|
+
* The ids of the result are the leaf shapes, the arrows and the groups that were given; `withConnectedObjects` turns them into
|
|
382
|
+
* the objects that are put in front of or behind the others.
|
|
383
|
+
*/
|
|
384
|
+
export function connectedObjectIds(scene, ids) {
|
|
385
|
+
var _a;
|
|
386
|
+
var index = indexScene(scene);
|
|
387
|
+
// 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);
|
|
391
|
+
if (neighbours)
|
|
392
|
+
neighbours.push(neighbourId);
|
|
393
|
+
else
|
|
394
|
+
joined.set(id, [neighbourId]);
|
|
395
|
+
};
|
|
396
|
+
for (var _i = 0, scene_9 = scene; _i < scene_9.length; _i++) {
|
|
397
|
+
var object = scene_9[_i];
|
|
398
|
+
var spec = arrowSpecOf(object);
|
|
399
|
+
if (!spec)
|
|
400
|
+
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);
|
|
404
|
+
// A tie to something that is not on the board (a board edited by hand) joins nothing.
|
|
405
|
+
if (!binding || binding.targetId === object.id || !index.has(binding.targetId))
|
|
406
|
+
continue;
|
|
407
|
+
addNeighbour(object.id, binding.targetId);
|
|
408
|
+
addNeighbour(binding.targetId, object.id);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
var connected = new Set();
|
|
412
|
+
var pending = __spreadArray([], withDescendantIds(scene, ids), true).filter(function (id) { return index.has(id); });
|
|
413
|
+
while (pending.length > 0) {
|
|
414
|
+
var id = pending.pop();
|
|
415
|
+
if (connected.has(id))
|
|
416
|
+
continue;
|
|
417
|
+
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];
|
|
420
|
+
if (!connected.has(next))
|
|
421
|
+
pending.push(next);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return connected;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* The object that is `id` itself or the group above it, whichever sits directly in the list of `parentId` (null is the board),
|
|
428
|
+
* or null when `id` is not under that parent at all.
|
|
429
|
+
*/
|
|
430
|
+
export function ancestorWithin(index, id, parentId) {
|
|
431
|
+
var current = index.get(id);
|
|
432
|
+
var visited = new Set();
|
|
433
|
+
while (current && !visited.has(current.id)) {
|
|
434
|
+
if (current.parentId === parentId)
|
|
435
|
+
return current.id;
|
|
436
|
+
visited.add(current.id);
|
|
437
|
+
current = current.parentId === null ? undefined : index.get(current.parentId);
|
|
438
|
+
}
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* The given objects and everything that arrows join to them: shapes that are tied together are one diagram, and putting any
|
|
443
|
+
* one of them in front of the others puts the whole diagram there. What is joined is taken at the level of the given objects,
|
|
444
|
+
* each as the object that sits in the same list of siblings as one of them (a shape inside a group stands for its group when
|
|
445
|
+
* the given objects are on the board, and is left alone when they are inside another group: a layer is only ever moved
|
|
446
|
+
* among its own siblings). In paint order, with no repeats. The same ids, normalised, when nothing is joined.
|
|
447
|
+
*/
|
|
448
|
+
export function withConnectedObjects(scene, ids) {
|
|
449
|
+
var selected = normalizeSelection(scene, ids);
|
|
450
|
+
if (selected.length === 0)
|
|
451
|
+
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);
|
|
461
|
+
if (sibling)
|
|
462
|
+
wanted.add(sibling);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return normalizeSelection(scene, wanted);
|
|
466
|
+
}
|
|
335
467
|
/**
|
|
336
468
|
* Changes the paint order of the objects, each among its own siblings (a member of a group moves inside the
|
|
337
469
|
* group, never out of it).
|
|
338
470
|
*/
|
|
339
471
|
export function reorderObjects(scene, ids, mode) {
|
|
340
|
-
|
|
472
|
+
var _a;
|
|
473
|
+
var moved = new Set(normalizeSelection(scene, ids));
|
|
341
474
|
if (moved.size === 0)
|
|
342
475
|
return scene;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
for (
|
|
346
|
-
|
|
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);
|
|
347
481
|
if (!found)
|
|
348
482
|
continue;
|
|
349
|
-
|
|
483
|
+
var set = (_a = lists.get(found.siblings)) !== null && _a !== void 0 ? _a : new Set();
|
|
350
484
|
set.add(id);
|
|
351
485
|
lists.set(found.siblings, set);
|
|
352
486
|
}
|
|
353
|
-
|
|
487
|
+
var _loop_1 = function (siblings, movedIds) {
|
|
488
|
+
var _d, _e;
|
|
354
489
|
if (mode === 'front' || mode === 'back') {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
siblings.splice(0, siblings.length,
|
|
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));
|
|
358
493
|
}
|
|
359
494
|
else if (mode === 'forward') {
|
|
360
495
|
// From the top down, a chosen node swaps with the unchosen one above it.
|
|
361
|
-
for (
|
|
496
|
+
for (var position = siblings.length - 2; position >= 0; position -= 1) {
|
|
362
497
|
if (movedIds.has(siblings[position].object.id) && !movedIds.has(siblings[position + 1].object.id)) {
|
|
363
|
-
[siblings[position], siblings[position
|
|
498
|
+
_d = [siblings[position + 1], siblings[position]], siblings[position] = _d[0], siblings[position + 1] = _d[1];
|
|
364
499
|
}
|
|
365
500
|
}
|
|
366
501
|
}
|
|
367
502
|
else {
|
|
368
|
-
for (
|
|
503
|
+
for (var position = 1; position < siblings.length; position += 1) {
|
|
369
504
|
if (movedIds.has(siblings[position].object.id) && !movedIds.has(siblings[position - 1].object.id)) {
|
|
370
|
-
[siblings[position], siblings[position
|
|
505
|
+
_e = [siblings[position - 1], siblings[position]], siblings[position] = _e[0], siblings[position - 1] = _e[1];
|
|
371
506
|
}
|
|
372
507
|
}
|
|
373
508
|
}
|
|
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);
|
|
374
513
|
}
|
|
375
|
-
|
|
376
|
-
|
|
514
|
+
var next = flattenSceneTree(roots);
|
|
515
|
+
var unchanged = next.length === scene.length && next.every(function (object, position) { return object === scene[position]; });
|
|
377
516
|
return unchanged ? scene : next;
|
|
378
517
|
}
|
|
379
518
|
/**
|
|
@@ -382,59 +521,65 @@ export function reorderObjects(scene, ids, mode) {
|
|
|
382
521
|
* are grouped whole (a selection never tears a group apart).
|
|
383
522
|
* Returns null when there is nothing to group (fewer than two units).
|
|
384
523
|
*/
|
|
385
|
-
export function groupObjects(scene, ids, groupId
|
|
386
|
-
|
|
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);
|
|
387
528
|
if (selected.length < 2)
|
|
388
529
|
return null;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
|
392
533
|
? selected
|
|
393
|
-
: Array.from(new Set(selected.map((id)
|
|
534
|
+
: Array.from(new Set(selected.map(function (id) { return topLevelAncestorId(index, id); })));
|
|
394
535
|
if (units.length < 2)
|
|
395
536
|
return null;
|
|
396
|
-
|
|
397
|
-
|
|
537
|
+
var roots = buildSceneTree(scene);
|
|
538
|
+
var unitNodes = units.map(function (id) { return findNode(roots, id); }).filter(function (node) { return node !== null; });
|
|
398
539
|
if (unitNodes.length < 2)
|
|
399
540
|
return null;
|
|
400
|
-
|
|
541
|
+
var firstFound = findSiblingList(roots, unitNodes[0].object.id);
|
|
401
542
|
if (!firstFound)
|
|
402
543
|
return null;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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); });
|
|
406
547
|
// The group takes the place of the highest unit among its siblings.
|
|
407
|
-
|
|
408
|
-
siblings.forEach((node, position)
|
|
548
|
+
var insertAt = 0;
|
|
549
|
+
siblings.forEach(function (node, position) {
|
|
409
550
|
if (unitIds.has(node.object.id))
|
|
410
551
|
insertAt = position;
|
|
411
552
|
});
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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;
|
|
416
557
|
remaining.splice(insertAt - removedBefore, 0, groupNode);
|
|
417
|
-
siblings.splice(0, siblings.length,
|
|
418
|
-
return { scene: flattenSceneTree(roots), groupId };
|
|
558
|
+
siblings.splice.apply(siblings, __spreadArray([0, siblings.length], remaining, false));
|
|
559
|
+
return { scene: flattenSceneTree(roots), groupId: groupId };
|
|
419
560
|
}
|
|
420
561
|
/** Dissolves groups: their members take the group's place in the list and in its parent. */
|
|
421
562
|
export function ungroupObjects(scene, ids) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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')
|
|
426
569
|
groupIds.add(id);
|
|
427
570
|
}
|
|
428
571
|
if (groupIds.size === 0)
|
|
429
|
-
return { scene, releasedIds: [] };
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
for (
|
|
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];
|
|
435
579
|
node.children = dissolve(node.children);
|
|
436
580
|
if (groupIds.has(node.object.id)) {
|
|
437
|
-
for (
|
|
581
|
+
for (var _a = 0, _b = node.children; _a < _b.length; _a++) {
|
|
582
|
+
var child = _b[_a];
|
|
438
583
|
releasedIds.push(child.object.id);
|
|
439
584
|
result.push(child);
|
|
440
585
|
}
|
|
@@ -445,29 +590,33 @@ export function ungroupObjects(scene, ids) {
|
|
|
445
590
|
}
|
|
446
591
|
return result;
|
|
447
592
|
};
|
|
448
|
-
|
|
449
|
-
return { scene: flattenSceneTree(dissolved), releasedIds };
|
|
593
|
+
var dissolved = dissolve(roots);
|
|
594
|
+
return { scene: flattenSceneTree(dissolved), releasedIds: releasedIds };
|
|
450
595
|
}
|
|
451
596
|
/**
|
|
452
597
|
* Copies objects (a group is copied with its members) under new ids, shifted by an offset.
|
|
453
598
|
* The copies are returned in paint order, ready to be added on top of the board.
|
|
454
599
|
*/
|
|
455
|
-
export function duplicateObjects(scene, ids, offset
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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];
|
|
461
610
|
if (!sources.has(object.id))
|
|
462
611
|
continue;
|
|
463
|
-
|
|
612
|
+
var copyId = makeId(object.type);
|
|
464
613
|
idMap.set(object.id, copyId);
|
|
465
|
-
|
|
614
|
+
var parentId = rootIds.has(object.id)
|
|
466
615
|
? object.parentId
|
|
467
616
|
: object.parentId !== null
|
|
468
|
-
? (idMap.get(object.parentId)
|
|
617
|
+
? ((_a = idMap.get(object.parentId)) !== null && _a !== void 0 ? _a : null)
|
|
469
618
|
: null;
|
|
470
|
-
|
|
619
|
+
var copy = __assign(__assign({}, object), { id: copyId, parentId: parentId });
|
|
471
620
|
if (isBoxedObject(copy) && isBoxedObject(object)) {
|
|
472
621
|
copy.x = object.x + offset.x;
|
|
473
622
|
copy.y = object.y + offset.y;
|
|
@@ -475,5 +624,5 @@ export function duplicateObjects(scene, ids, offset = { x: 0, y: 0 }, makeId = (
|
|
|
475
624
|
objects.push(copy);
|
|
476
625
|
}
|
|
477
626
|
// 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.
|
|
478
|
-
return { objects: objects.map((copy)
|
|
627
|
+
return { objects: objects.map(function (copy) { return remapEnds(copy, idMap); }), idMap: idMap };
|
|
479
628
|
}
|