@widgetic/canvas 0.5.41 → 0.5.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/README.md +1 -0
  2. package/dist/canvas/DomCanvas.svelte +49 -20
  3. package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
  4. package/dist/canvas/autosaveScheduler.js +37 -89
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +7 -19
  8. package/dist/canvas/chromeLayout.d.ts +14 -3
  9. package/dist/canvas/chromeLayout.js +30 -20
  10. package/dist/canvas/eventScope.js +10 -14
  11. package/dist/canvas/host/CanvasHost.d.ts +47 -5
  12. package/dist/canvas/host/CanvasHost.js +1481 -1566
  13. package/dist/canvas/host/CanvasHostApi.js +4 -19
  14. package/dist/canvas/host/browserServices.js +65 -116
  15. package/dist/canvas/host/conversion.js +82 -170
  16. package/dist/canvas/host/hostObject.js +7 -7
  17. package/dist/canvas/host/nearCards.d.ts +33 -0
  18. package/dist/canvas/host/nearCards.js +78 -0
  19. package/dist/canvas/host/pageEvents.d.ts +16 -4
  20. package/dist/canvas/host/pageEvents.js +17 -8
  21. package/dist/canvas/host/pictureSaves.d.ts +33 -0
  22. package/dist/canvas/host/pictureSaves.js +42 -0
  23. package/dist/canvas/host/screenRects.d.ts +5 -0
  24. package/dist/canvas/host/screenRects.js +28 -31
  25. package/dist/canvas/host/storedPictures.d.ts +88 -0
  26. package/dist/canvas/host/storedPictures.js +288 -0
  27. package/dist/canvas/host/strokeSnap.js +88 -143
  28. package/dist/canvas/index.d.ts +1 -1
  29. package/dist/canvas/index.js +1 -1
  30. package/dist/canvas/openMarks.js +2 -2
  31. package/dist/canvas/outsideClickDeselect.js +6 -7
  32. package/dist/canvas/panZoomPosition.js +2 -2
  33. package/dist/canvas/preferredTextFont.js +13 -25
  34. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  35. package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
  36. package/dist/canvas/shapes/shapeImageStore.js +10 -3
  37. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  38. package/dist/canvas/toolbarPosition.d.ts +2 -2
  39. package/dist/canvas/toolbarPosition.js +4 -4
  40. package/dist/canvas/ui/SelectionPanel.svelte +28 -5
  41. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
  42. package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
  43. package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
  44. package/dist/canvas/ui/ToolButton.svelte +8 -2
  45. package/dist/canvas/ui/colorModel.js +21 -32
  46. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  47. package/dist/canvas/ui/floatingCard.d.ts +2 -2
  48. package/dist/canvas/ui/floatingCard.js +20 -20
  49. package/dist/canvas/ui/floatingLayer.d.ts +13 -2
  50. package/dist/canvas/ui/floatingLayer.js +18 -7
  51. package/dist/canvas/ui/keyHints.js +9 -11
  52. package/dist/canvas/ui/popoverSide.js +2 -3
  53. package/dist/canvas/ui/selectionTraits.js +34 -40
  54. package/dist/canvas/view/CanvasStage.svelte +101 -67
  55. package/dist/canvas/view/LeftToRightScope.svelte +21 -0
  56. package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
  57. package/dist/canvas/view/ObjectView.svelte +15 -10
  58. package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
  59. package/dist/canvas/view/erasingMarks.js +7 -7
  60. package/dist/canvas/view/geometry.js +71 -90
  61. package/dist/canvas/view/liftedScene.d.ts +31 -0
  62. package/dist/canvas/view/liftedScene.js +146 -0
  63. package/dist/canvas/view/mountedScene.d.ts +71 -0
  64. package/dist/canvas/view/mountedScene.js +363 -0
  65. package/dist/components/preferenceStorage.js +2 -2
  66. package/dist/engine/EngineCore.d.ts +15 -1
  67. package/dist/engine/EngineCore.js +724 -797
  68. package/dist/engine/codec/canvasDocument.d.ts +5 -0
  69. package/dist/engine/codec/canvasDocument.js +212 -149
  70. package/dist/engine/codec/hostReadableKeys.js +1 -1
  71. package/dist/engine/core/arrange.js +26 -38
  72. package/dist/engine/core/arrow.js +76 -89
  73. package/dist/engine/core/arrowBinding.js +98 -116
  74. package/dist/engine/core/arrowBindingRecords.js +23 -38
  75. package/dist/engine/core/brush.js +67 -94
  76. package/dist/engine/core/defaults.js +90 -51
  77. package/dist/engine/core/freehand.js +147 -163
  78. package/dist/engine/core/geometry.js +47 -54
  79. package/dist/engine/core/history.d.ts +6 -0
  80. package/dist/engine/core/history.js +49 -50
  81. package/dist/engine/core/hitTest.js +68 -81
  82. package/dist/engine/core/matrix.js +18 -20
  83. package/dist/engine/core/pathData.js +183 -210
  84. package/dist/engine/core/rotationReset.js +5 -6
  85. package/dist/engine/core/scene.d.ts +10 -0
  86. package/dist/engine/core/scene.js +153 -187
  87. package/dist/engine/core/scribble.js +59 -84
  88. package/dist/engine/core/shapePaths.js +12 -15
  89. package/dist/engine/core/shapeTools.js +72 -63
  90. package/dist/engine/core/snapping.js +65 -117
  91. package/dist/engine/core/style.js +31 -64
  92. package/dist/engine/core/transform.js +83 -94
  93. package/dist/engine/core/types.d.ts +8 -2
  94. package/dist/engine/core/types.js +4 -4
  95. package/dist/engine/core/viewport.js +23 -36
  96. package/dist/engine/input/PointerController.js +467 -474
  97. package/dist/engine/input/arrowHandles.js +12 -12
  98. package/dist/engine/input/gestures.js +265 -309
  99. package/dist/engine/input/hoverCursor.js +1 -1
  100. package/dist/engine/input/keyboard.js +27 -30
  101. package/dist/engine/input/selectionHandles.js +45 -50
  102. package/dist/engine/input/types.js +1 -1
  103. package/dist/engine/render/rasterize.js +86 -158
  104. package/dist/engine/state.d.ts +20 -0
  105. package/dist/engine/state.js +5 -15
  106. package/dist/engine/text/layoutText.js +43 -62
  107. package/dist/engine/text/textMetrics.js +8 -10
  108. package/dist/engine/widgets.js +101 -137
  109. package/dist/fonts/interFont.d.ts +10 -1
  110. package/dist/fonts/interFont.js +47 -75
  111. package/dist/fonts/workspaceFonts.js +32 -90
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.d.ts +3 -3
  114. package/dist/i18n/language.js +4 -4
  115. package/dist/i18n/messages.d.ts +8 -1
  116. package/dist/i18n/messages.js +10 -2
  117. package/dist/i18n/shortcuts.js +14 -14
  118. package/dist/index.d.ts +1 -1
  119. package/dist/index.js +1 -1
  120. package/dist/settings/workspaceToolSettings.js +32 -48
  121. package/dist/tools/components/catalog.js +64 -74
  122. package/dist/tools/components/grouping.js +6 -28
  123. package/dist/tools/definitions.js +5 -5
  124. package/dist/tools/executors.js +105 -141
  125. package/dist/tools/hostAdapter.js +11 -13
  126. package/dist/tools/sceneSummary.js +43 -57
  127. package/dist/tools/sketchIntent.js +13 -21
  128. package/dist/tools/types.js +1 -1
  129. package/package.json +1 -1
  130. package/dist/canvas/ui/SelectorBar.svelte +0 -84
  131. package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
@@ -10,74 +10,6 @@
10
10
  * end, so one gesture is one undo step. The pointer controller drives them; everything else (the menus, the
11
11
  * keyboard, the host's own calls) uses the commands below, each of which is one step.
12
12
  */
13
- var __assign = (this && this.__assign) || function () {
14
- __assign = Object.assign || function(t) {
15
- for (var s, i = 1, n = arguments.length; i < n; i++) {
16
- s = arguments[i];
17
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
18
- t[p] = s[p];
19
- }
20
- return t;
21
- };
22
- return __assign.apply(this, arguments);
23
- };
24
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- };
33
- var __generator = (this && this.__generator) || function (thisArg, body) {
34
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
35
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
36
- function verb(n) { return function (v) { return step([n, v]); }; }
37
- function step(op) {
38
- if (f) throw new TypeError("Generator is already executing.");
39
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
40
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
41
- if (y = 0, t) op = [op[0] & 2, t.value];
42
- switch (op[0]) {
43
- case 0: case 1: t = op; break;
44
- case 4: _.label++; return { value: op[1], done: false };
45
- case 5: _.label++; y = op[1]; op = [0]; continue;
46
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
47
- default:
48
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
49
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
50
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
51
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
52
- if (t[2]) _.ops.pop();
53
- _.trys.pop(); continue;
54
- }
55
- op = body.call(thisArg, _);
56
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
57
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
58
- }
59
- };
60
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
61
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
62
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
63
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
64
- };
65
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
66
- if (kind === "m") throw new TypeError("Private method is not writable");
67
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
68
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
69
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
70
- };
71
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
73
- if (ar || !(i in from)) {
74
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
75
- ar[i] = from[i];
76
- }
77
- }
78
- return to.concat(ar || Array.prototype.slice.call(from));
79
- };
80
- var _EngineCore_instances, _EngineCore_state, _EngineCore_rotationResetCancel, _EngineCore_listeners, _EngineCore_history, _EngineCore_clipboard, _EngineCore_pasteSteps, _EngineCore_nudgeMergeUntil, _EngineCore_textSession, _EngineCore_preferredTextFontFamily, _EngineCore_workspaceTextDefaults, _EngineCore_workspacePaintDefaults, _EngineCore_scribble, _EngineCore_indexes, _EngineCore_selectedShapesMemo, _EngineCore_set, _EngineCore_callHook, _EngineCore_sceneForSave, _EngineCore_afterHistoryMove, _EngineCore_setSelection, _EngineCore_dropScribble, _EngineCore_viewCenter, _EngineCore_fittedViewport, _EngineCore_fitText, _EngineCore_fitTexts, _EngineCore_arrange, _EngineCore_insertCopies, _EngineCore_flattenWidgetCard;
81
13
  import { parseCanvasDocument, serializeCanvasDocument } from './codec/canvasDocument.js';
82
14
  import { rotationAfterResetProgress, rotationResetProgress } from './core/rotationReset.js';
83
15
  import { alignObjects, distributeObjects } from './core/arrange.js';
@@ -85,7 +17,7 @@ import { reconcileArrowBindings } from './core/arrowBinding.js';
85
17
  import { createImageObject, createObjectId, createRectObject, createTextObject, createWidgetObject, TEXT_DEFAULTS } from './core/defaults.js';
86
18
  import { HistoryStack } from './core/history.js';
87
19
  import { hitTestPoint, hitTestRect, hitTestStack } from './core/hitTest.js';
88
- import { boardVisualBounds, boundsOfObjects, duplicateObjects, groupObjects, indexScene, leafShapesOf, normalizeScene, normalizeSelection, removeObjects as removeFromScene, reorderObjects, replaceObject, sameIds, translateObjects, ungroupObjects, withDescendantIds } from './core/scene.js';
20
+ import { addObjectsBehindWidgetCards, boardVisualBounds, boundsOfObjects, duplicateObjects, groupObjects, indexScene, leafShapesOf, normalizeScene, normalizeSelection, removeObjects as removeFromScene, reorderObjects, replaceObject, sameIds, translateObjects, ungroupObjects, withDescendantIds } from './core/scene.js';
89
21
  import { applyStylePatch } from './core/style.js';
90
22
  import { Scribble } from './core/scribble.js';
91
23
  import { selectionFrameOf } from './core/transform.js';
@@ -93,17 +25,17 @@ import { INITIAL_VIEWPORT, clampZoom, fitViewportToRect, nextZoomStep, panViewpo
93
25
  import { DEFAULT_WIDGET_RUNTIME, EMPTY_OVERLAY, createInitialState } from './state.js';
94
26
  import { createFixedAdvanceMeasure, fitTextObject } from './text/layoutText.js';
95
27
  /** How many undo steps the board keeps (as the canvas it replaces did). */
96
- export var HISTORY_LIMIT = 50;
28
+ export const HISTORY_LIMIT = 50;
97
29
  /** How far a duplicate or a repeated paste lands from the original, in world units. */
98
- export var PASTE_OFFSET = 20;
30
+ export const PASTE_OFFSET = 20;
99
31
  /** Arrow-key nudges within this time of each other are one undo step. */
100
- export var NUDGE_MERGE_MS = 700;
32
+ export const NUDGE_MERGE_MS = 700;
101
33
  /** Room left around the board when it is fitted to the view, in screen pixels. */
102
- export var VIEW_FIT_PADDING = 48;
34
+ export const VIEW_FIT_PADDING = 48;
103
35
  /** The longest a text may be, in letters. */
104
- export var MAX_TEXT_LENGTH = 100000;
36
+ export const MAX_TEXT_LENGTH = 100_000;
105
37
  /** A shape turned by less than this (degrees) stands upright: there is nothing for a reset to do. */
106
- export var UPRIGHT_TOLERANCE_DEGREES = 0.01;
38
+ export const UPRIGHT_TOLERANCE_DEGREES = 0.01;
107
39
  /** The cursor a tool shows over the board when nothing is under the pointer. */
108
40
  export function cursorForTool(tool) {
109
41
  switch (tool) {
@@ -117,174 +49,221 @@ export function cursorForTool(tool) {
117
49
  return 'crosshair';
118
50
  }
119
51
  }
120
- var EngineCore = /** @class */ (function () {
121
- function EngineCore(services) {
122
- if (services === void 0) { services = {}; }
123
- var _this = this;
124
- var _a, _b, _c, _d, _e;
125
- _EngineCore_instances.add(this);
126
- /** What the host shell listens to; the shell sets its own functions here. */
127
- this.hooks = {};
128
- /** Whether a new shape is plain white with a grey outline (true) or gets a random colour. */
129
- this.wireframeMode = true;
130
- /** The last place the pointer was over the board, in world units: where a paste lands. */
131
- this.lastPointerWorld = null;
132
- _EngineCore_state.set(this, createInitialState());
133
- _EngineCore_rotationResetCancel.set(this, null);
134
- _EngineCore_listeners.set(this, new Set());
135
- _EngineCore_history.set(this, void 0);
136
- _EngineCore_clipboard.set(this, null);
137
- _EngineCore_pasteSteps.set(this, 0);
138
- _EngineCore_nudgeMergeUntil.set(this, 0);
139
- _EngineCore_textSession.set(this, null);
140
- /** The last font family chosen in the panel; new text objects start with this instead of the catalog default. */
141
- _EngineCore_preferredTextFontFamily.set(this, null);
142
- _EngineCore_workspaceTextDefaults.set(this, null);
143
- _EngineCore_workspacePaintDefaults.set(this, null);
144
- // The eraser's trail while it lives; what the views draw of it is `state.scribble`.
145
- _EngineCore_scribble.set(this, null);
146
- _EngineCore_indexes.set(this, new WeakMap());
147
- _EngineCore_selectedShapesMemo.set(this, null);
52
+ export class EngineCore {
53
+ /** What the host shell listens to; the shell sets its own functions here. */
54
+ hooks = {};
55
+ /** Whether a new shape is plain white with a grey outline (true) or gets a random colour. */
56
+ wireframeMode = true;
57
+ /** The last place the pointer was over the board, in world units: where a paste lands. */
58
+ lastPointerWorld = null;
59
+ services;
60
+ #state = createInitialState();
61
+ #rotationResetCancel = null;
62
+ #listeners = new Set();
63
+ #history;
64
+ #clipboard = null;
65
+ #pasteSteps = 0;
66
+ #nudgeMergeUntil = 0;
67
+ #textSession = null;
68
+ /** The last font family chosen in the panel; new text objects start with this instead of the catalog default. */
69
+ #preferredTextFontFamily = null;
70
+ #workspaceTextDefaults = null;
71
+ #workspacePaintDefaults = null;
72
+ // The eraser's trail while it lives; what the views draw of it is `state.scribble`.
73
+ #scribble = null;
74
+ #indexes = new WeakMap();
75
+ #selectedShapesMemo = null;
76
+ constructor(services = {}) {
148
77
  this.services = {
149
- createId: (_a = services.createId) !== null && _a !== void 0 ? _a : (function (prefix) { return createObjectId(prefix); }),
150
- measureText: (_b = services.measureText) !== null && _b !== void 0 ? _b : createFixedAdvanceMeasure(),
151
- now: (_c = services.now) !== null && _c !== void 0 ? _c : (function () { return Date.now(); }),
152
- random: (_d = services.random) !== null && _d !== void 0 ? _d : Math.random,
153
- requestAnimationFrame: (_e = services.requestAnimationFrame) !== null && _e !== void 0 ? _e : (function (callback) {
154
- if (typeof globalThis.requestAnimationFrame === 'function') {
155
- var id_1 = globalThis.requestAnimationFrame(callback);
156
- return function () { var _a; return (_a = globalThis.cancelAnimationFrame) === null || _a === void 0 ? void 0 : _a.call(globalThis, id_1); };
157
- }
158
- var id = globalThis.setTimeout(function () { return callback(_this.services.now()); }, 16);
159
- return function () { return globalThis.clearTimeout(id); };
160
- })
78
+ createId: services.createId ?? ((prefix) => createObjectId(prefix)),
79
+ measureText: services.measureText ?? createFixedAdvanceMeasure(),
80
+ now: services.now ?? (() => Date.now()),
81
+ random: services.random ?? Math.random,
82
+ requestAnimationFrame: services.requestAnimationFrame ??
83
+ ((callback) => {
84
+ if (typeof globalThis.requestAnimationFrame === 'function') {
85
+ const id = globalThis.requestAnimationFrame(callback);
86
+ return () => globalThis.cancelAnimationFrame?.(id);
87
+ }
88
+ const id = globalThis.setTimeout(() => callback(this.services.now()), 16);
89
+ return () => globalThis.clearTimeout(id);
90
+ })
161
91
  };
162
- __classPrivateFieldSet(this, _EngineCore_history, new HistoryStack(__classPrivateFieldGet(this, _EngineCore_state, "f").scene, { limit: HISTORY_LIMIT }), "f");
163
- }
164
- Object.defineProperty(EngineCore.prototype, "state", {
165
- // ──────────────────────────────────────────────────────── state and subscriptions
166
- get: function () {
167
- return __classPrivateFieldGet(this, _EngineCore_state, "f");
168
- },
169
- enumerable: false,
170
- configurable: true
171
- });
92
+ this.#history = new HistoryStack(this.#state.scene, { limit: HISTORY_LIMIT });
93
+ }
94
+ // ──────────────────────────────────────────────────────── state and subscriptions
95
+ get state() {
96
+ return this.#state;
97
+ }
172
98
  /** Calls the listener after every change of the state. Returns the function that stops it. */
173
- EngineCore.prototype.subscribe = function (listener) {
174
- var _this = this;
175
- __classPrivateFieldGet(this, _EngineCore_listeners, "f").add(listener);
176
- return function () {
177
- __classPrivateFieldGet(_this, _EngineCore_listeners, "f").delete(listener);
99
+ subscribe(listener) {
100
+ this.#listeners.add(listener);
101
+ return () => {
102
+ this.#listeners.delete(listener);
178
103
  };
179
- };
104
+ }
180
105
  /** Lets go of every listener and hook (the board was removed from the page). */
181
- EngineCore.prototype.dispose = function () {
106
+ dispose() {
182
107
  this.cancelRotationReset();
183
- __classPrivateFieldGet(this, _EngineCore_listeners, "f").clear();
108
+ this.#listeners.clear();
184
109
  this.hooks = {};
185
- __classPrivateFieldSet(this, _EngineCore_textSession, null, "f");
186
- __classPrivateFieldSet(this, _EngineCore_scribble, null, "f");
187
- };
110
+ this.#textSession = null;
111
+ this.#scribble = null;
112
+ }
188
113
  /** Stops an upright animation in progress and records the angle on screen as one undo step. */
189
- EngineCore.prototype.cancelRotationReset = function () {
190
- if (!__classPrivateFieldGet(this, _EngineCore_rotationResetCancel, "f"))
114
+ cancelRotationReset() {
115
+ if (!this.#rotationResetCancel)
191
116
  return;
192
- __classPrivateFieldGet(this, _EngineCore_rotationResetCancel, "f").call(this);
193
- __classPrivateFieldSet(this, _EngineCore_rotationResetCancel, null, "f");
194
- };
117
+ this.#rotationResetCancel();
118
+ this.#rotationResetCancel = null;
119
+ }
120
+ #set(patch) {
121
+ let changed = false;
122
+ for (const key of Object.keys(patch)) {
123
+ if (!Object.is(patch[key], this.#state[key])) {
124
+ changed = true;
125
+ break;
126
+ }
127
+ }
128
+ if (!changed)
129
+ return;
130
+ const before = this.#state.selectedIds;
131
+ this.#state = { ...this.#state, ...patch };
132
+ for (const listener of [...this.#listeners])
133
+ listener(this.#state);
134
+ if (this.#state.selectedIds !== before && !sameIds(this.#state.selectedIds, before)) {
135
+ this.#callHook(() => this.hooks.onSelectionChange?.(this.#state.selectedIds), 'selection hook');
136
+ }
137
+ }
138
+ #callHook(run, name) {
139
+ try {
140
+ run();
141
+ }
142
+ catch (error) {
143
+ this.hooks.onError?.(`The ${name} threw`, error);
144
+ }
145
+ }
195
146
  /** The objects of the scene by id. Built once per scene and kept while the scene is the same array. */
196
- EngineCore.prototype.sceneIndex = function (scene) {
197
- if (scene === void 0) { scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene; }
198
- var index = __classPrivateFieldGet(this, _EngineCore_indexes, "f").get(scene);
147
+ sceneIndex(scene = this.#state.scene) {
148
+ let index = this.#indexes.get(scene);
199
149
  if (!index) {
200
150
  index = indexScene(scene);
201
- __classPrivateFieldGet(this, _EngineCore_indexes, "f").set(scene, index);
151
+ this.#indexes.set(scene, index);
202
152
  }
203
153
  return index;
204
- };
205
- EngineCore.prototype.getObject = function (id) {
154
+ }
155
+ getObject(id) {
206
156
  return this.sceneIndex().get(id);
207
- };
157
+ }
208
158
  /** The objects that are selected (a group counts once). */
209
- EngineCore.prototype.selectedObjects = function () {
210
- var index = this.sceneIndex();
211
- var objects = [];
212
- for (var _i = 0, _a = __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds; _i < _a.length; _i++) {
213
- var id = _a[_i];
214
- var object = index.get(id);
159
+ selectedObjects() {
160
+ const index = this.sceneIndex();
161
+ const objects = [];
162
+ for (const id of this.#state.selectedIds) {
163
+ const object = index.get(id);
215
164
  if (object)
216
165
  objects.push(object);
217
166
  }
218
167
  return objects;
219
- };
168
+ }
220
169
  /**
221
170
  * The shapes the selection draws: its members when a group is selected. Found once for a scene and a selection and kept
222
171
  * while they are the same ones: the frame, the handles and the panel each ask at every step of a drag.
223
172
  */
224
- EngineCore.prototype.selectedShapes = function () {
225
- var _a = __classPrivateFieldGet(this, _EngineCore_state, "f"), scene = _a.scene, selectedIds = _a.selectedIds;
226
- var memo = __classPrivateFieldGet(this, _EngineCore_selectedShapesMemo, "f");
173
+ selectedShapes() {
174
+ const { scene, selectedIds } = this.#state;
175
+ const memo = this.#selectedShapesMemo;
227
176
  if (memo && memo.scene === scene && memo.selectedIds === selectedIds)
228
177
  return memo.shapes;
229
- var shapes = leafShapesOf(scene, selectedIds);
230
- __classPrivateFieldSet(this, _EngineCore_selectedShapesMemo, { scene: scene, selectedIds: selectedIds, shapes: shapes }, "f");
178
+ const shapes = leafShapesOf(scene, selectedIds);
179
+ this.#selectedShapesMemo = { scene, selectedIds, shapes };
231
180
  return shapes;
232
- };
181
+ }
233
182
  /** The box the selection handles surround, or null when nothing is selected. */
234
- EngineCore.prototype.selectionFrame = function () {
183
+ selectionFrame() {
235
184
  return selectionFrameOf(this.selectedShapes());
236
- };
237
- EngineCore.prototype.isEmpty = function () {
238
- return __classPrivateFieldGet(this, _EngineCore_state, "f").scene.length === 0;
239
- };
185
+ }
186
+ isEmpty() {
187
+ return this.#state.scene.length === 0;
188
+ }
240
189
  // ──────────────────────────────────────────────────────── loading and saving
241
190
  /** Shows a canvas that was read from saved data. History starts again from it, and it is not "changed". */
242
- EngineCore.prototype.load = function (parsed, options) {
243
- if (options === void 0) { options = {}; }
244
- __classPrivateFieldSet(this, _EngineCore_textSession, null, "f");
191
+ load(parsed, options = {}) {
192
+ this.#textSession = null;
245
193
  // The texts are laid out first: an arrow tied to one rests on the box its letters make.
246
- var scene = reconcileArrowBindings(__classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_fitTexts).call(this, parsed.scene));
247
- __classPrivateFieldGet(this, _EngineCore_history, "f").reset(scene);
248
- var viewport = options.fitView ? __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_fittedViewport).call(this, scene) : parsed.viewport;
249
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, __assign(__assign({}, __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_dropScribble).call(this)), { scene: scene, viewport: viewport, selectedIds: [], enteredGroupId: null, hoverId: null, editingTextId: null, overlay: EMPTY_OVERLAY, pending: Object.freeze({}), hoverWidgetId: null, canUndo: false, canRedo: false, revision: __classPrivateFieldGet(this, _EngineCore_state, "f").revision + 1 }));
250
- };
194
+ const scene = reconcileArrowBindings(this.#fitTexts(parsed.scene));
195
+ this.#history.reset(scene);
196
+ const viewport = options.fitView ? this.#fittedViewport(scene) : parsed.viewport;
197
+ this.#set({
198
+ ...this.#dropScribble(),
199
+ scene,
200
+ viewport,
201
+ selectedIds: [],
202
+ enteredGroupId: null,
203
+ hoverId: null,
204
+ editingTextId: null,
205
+ overlay: EMPTY_OVERLAY,
206
+ pending: Object.freeze({}),
207
+ hoverWidgetId: null,
208
+ canUndo: false,
209
+ canRedo: false,
210
+ revision: this.#state.revision + 1
211
+ });
212
+ }
251
213
  /** Reads saved data (text or an object) and shows it. Never throws: a bad document loads as an empty board. */
252
- EngineCore.prototype.loadDocument = function (input, options) {
253
- if (options === void 0) { options = {}; }
254
- var parsed = parseCanvasDocument(input);
214
+ loadDocument(input, options = {}) {
215
+ const parsed = parseCanvasDocument(input);
255
216
  this.load(parsed, options);
256
217
  return parsed;
257
- };
218
+ }
258
219
  /** The board as text to store. A card still waiting for its widget, and a text nobody typed in, are left out. */
259
- EngineCore.prototype.serialize = function (options) {
260
- if (options === void 0) { options = {}; }
261
- return serializeCanvasDocument(__classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_sceneForSave).call(this), __classPrivateFieldGet(this, _EngineCore_state, "f").viewport, __assign({ now: new Date(this.services.now()) }, options));
262
- };
220
+ serialize(options = {}) {
221
+ return serializeCanvasDocument(this.#sceneForSave(), this.#state.viewport, {
222
+ now: new Date(this.services.now()),
223
+ ...options
224
+ });
225
+ }
226
+ #sceneForSave() {
227
+ const { scene, pending, editingTextId } = this.#state;
228
+ const unwanted = new Set();
229
+ for (const object of scene) {
230
+ if (pending[object.id])
231
+ unwanted.add(object.id);
232
+ if (object.id === editingTextId && object.type === 'text' && object.text.trim() === '')
233
+ unwanted.add(object.id);
234
+ }
235
+ if (unwanted.size === 0)
236
+ return scene;
237
+ return normalizeScene(scene.filter((object) => !unwanted.has(object.id)));
238
+ }
263
239
  /** Forgets what can be undone (after the host replaced the board). */
264
- EngineCore.prototype.resetHistory = function () {
265
- __classPrivateFieldGet(this, _EngineCore_history, "f").reset(__classPrivateFieldGet(this, _EngineCore_state, "f").scene);
266
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { canUndo: false, canRedo: false });
267
- };
268
- EngineCore.prototype.setLoading = function (loading) {
269
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { loading: loading });
270
- };
240
+ resetHistory() {
241
+ this.#history.reset(this.#state.scene);
242
+ this.#set({ canUndo: false, canRedo: false });
243
+ }
244
+ setLoading(loading) {
245
+ this.#set({ loading });
246
+ }
271
247
  /**
272
248
  * Tells the engine how big the board element is. With `keepCentre` the view stays on the same point of the world: when
273
249
  * the board grows or shrinks, the pan moves by half of the change, so what was in the middle stays in the middle (a board
274
250
  * that its page resizes by dragging its edges). The first measure (from 0 by 0) never moves the pan, whatever `keepCentre` says.
275
251
  */
276
- EngineCore.prototype.setViewSize = function (size, keepCentre) {
277
- if (keepCentre === void 0) { keepCentre = false; }
278
- var current = __classPrivateFieldGet(this, _EngineCore_state, "f").viewSize;
252
+ setViewSize(size, keepCentre = false) {
253
+ const current = this.#state.viewSize;
279
254
  if (current.width === size.width && current.height === size.height)
280
255
  return;
281
- var patch = { viewSize: { width: size.width, height: size.height } };
256
+ const patch = { viewSize: { width: size.width, height: size.height } };
282
257
  if (keepCentre && current.width > 0 && current.height > 0 && size.width > 0 && size.height > 0) {
283
- var viewport = __classPrivateFieldGet(this, _EngineCore_state, "f").viewport;
284
- patch.viewport = __assign(__assign({}, viewport), { x: viewport.x + (size.width - current.width) / 2, y: viewport.y + (size.height - current.height) / 2 });
258
+ const viewport = this.#state.viewport;
259
+ patch.viewport = {
260
+ ...viewport,
261
+ x: viewport.x + (size.width - current.width) / 2,
262
+ y: viewport.y + (size.height - current.height) / 2
263
+ };
285
264
  }
286
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, patch);
287
- };
265
+ this.#set(patch);
266
+ }
288
267
  // ──────────────────────────────────────────────────────── scene changes
289
268
  /**
290
269
  * Puts a new scene on the board. `transient` is for the frames of a gesture (nothing is recorded), `push`
@@ -293,502 +272,551 @@ var EngineCore = /** @class */ (function () {
293
272
  * Whatever the change was (a drag, a stretch, a word typed, an undo), the arrows that are tied to shapes are drawn again from
294
273
  * where their shapes are now, in the same scene and the same step: nothing else has to know about the ties.
295
274
  */
296
- EngineCore.prototype.applyScene = function (requested, mode) {
297
- var _a, _b;
298
- if (mode === void 0) { mode = 'push'; }
299
- var previous = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
300
- var next = reconcileArrowBindings(requested);
275
+ applyScene(requested, mode = 'push') {
276
+ const previous = this.#state.scene;
277
+ const next = reconcileArrowBindings(requested);
301
278
  if (next === previous)
302
279
  return mode === 'push' ? this.commit() : false;
303
- var patch = { scene: next, revision: __classPrivateFieldGet(this, _EngineCore_state, "f").revision + 1 };
280
+ const patch = { scene: next, revision: this.#state.revision + 1 };
304
281
  if (mode !== 'transient' || next.length !== previous.length) {
305
282
  // Keep everything that points at an object pointing at one that is still there.
306
- var index_1 = this.sceneIndex(next);
307
- var selection = __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds.filter(function (id) { return index_1.has(id); });
308
- if (selection.length !== __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds.length)
283
+ const index = this.sceneIndex(next);
284
+ const selection = this.#state.selectedIds.filter((id) => index.has(id));
285
+ if (selection.length !== this.#state.selectedIds.length)
309
286
  patch.selectedIds = selection;
310
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").hoverId && !index_1.has(__classPrivateFieldGet(this, _EngineCore_state, "f").hoverId))
287
+ if (this.#state.hoverId && !index.has(this.#state.hoverId))
311
288
  patch.hoverId = null;
312
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").enteredGroupId && !index_1.has(__classPrivateFieldGet(this, _EngineCore_state, "f").enteredGroupId))
289
+ if (this.#state.enteredGroupId && !index.has(this.#state.enteredGroupId))
313
290
  patch.enteredGroupId = null;
314
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").editingTextId && !index_1.has(__classPrivateFieldGet(this, _EngineCore_state, "f").editingTextId))
291
+ if (this.#state.editingTextId && !index.has(this.#state.editingTextId))
315
292
  patch.editingTextId = null;
316
- var pendingIds = Object.keys(__classPrivateFieldGet(this, _EngineCore_state, "f").pending);
317
- if (pendingIds.some(function (id) { return !index_1.has(id); })) {
318
- patch.pending = Object.freeze(Object.fromEntries(Object.entries(__classPrivateFieldGet(this, _EngineCore_state, "f").pending).filter(function (_a) {
319
- var id = _a[0];
320
- return index_1.has(id);
321
- })));
293
+ const pendingIds = Object.keys(this.#state.pending);
294
+ if (pendingIds.some((id) => !index.has(id))) {
295
+ patch.pending = Object.freeze(Object.fromEntries(Object.entries(this.#state.pending).filter(([id]) => index.has(id))));
322
296
  }
323
297
  }
324
298
  if (mode === 'replace')
325
- __classPrivateFieldGet(this, _EngineCore_history, "f").replaceCurrent(next);
326
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, patch);
299
+ this.#history.replaceCurrent(next);
300
+ this.#set(patch);
327
301
  if (mode === 'push')
328
302
  this.commit();
329
303
  else if (mode === 'replace') {
330
- __classPrivateFieldSet(this, _EngineCore_nudgeMergeUntil, 0, "f");
331
- (_b = (_a = this.hooks).onDirty) === null || _b === void 0 ? void 0 : _b.call(_a);
304
+ this.#nudgeMergeUntil = 0;
305
+ this.hooks.onDirty?.();
332
306
  }
333
307
  return true;
334
- };
308
+ }
335
309
  /**
336
310
  * Puts a scene on the board with no undo step and without telling the host that the board changed: a repair
337
311
  * of what was loaded (a name filled in), not an edit.
338
312
  */
339
- EngineCore.prototype.applySilently = function (next) {
340
- if (next === __classPrivateFieldGet(this, _EngineCore_state, "f").scene)
313
+ applySilently(next) {
314
+ if (next === this.#state.scene)
341
315
  return;
342
316
  this.applyScene(next, 'transient');
343
317
  // What the board holds now (the arrows tied to shapes drawn again), not the scene that was asked for.
344
- __classPrivateFieldGet(this, _EngineCore_history, "f").replaceCurrent(__classPrivateFieldGet(this, _EngineCore_state, "f").scene);
345
- };
318
+ this.#history.replaceCurrent(this.#state.scene);
319
+ }
320
+ /**
321
+ * Fills in what was loaded late (a picture that arrived after the board was opened and used) in the board and in every step of
322
+ * its history, with no undo step and without telling the host that the board changed: a repair of what was loaded, not an edit.
323
+ * `repair` must give back the very same scene when it has nothing to change.
324
+ *
325
+ * Not `applySilently`, which is for what is done before the person can do anything: it makes the board the current step, and
326
+ * that is wrong twice over for a repair that comes in the middle of the person's work. A gesture that is under way has a scene
327
+ * of its own (the board is then not any step), and it would be written into the step the gesture started from, so that Escape
328
+ * could not take it back; and the steps before this one would still be without the picture, so an undo would take it away.
329
+ */
330
+ repairLoaded(repair) {
331
+ // At rest the board is the current step itself; during a gesture it is not.
332
+ const atRest = this.#history.current === this.#state.scene;
333
+ this.#history.mapAll(repair);
334
+ const next = atRest ? this.#history.current : repair(this.#state.scene);
335
+ if (next === this.#state.scene)
336
+ return;
337
+ this.applyScene(next, 'transient');
338
+ // What the board holds now (the arrows tied to shapes drawn again), so that the board stays the very same list as its step.
339
+ if (atRest)
340
+ this.#history.replaceCurrent(this.#state.scene);
341
+ }
346
342
  /** Records the scene as it is now as one undo step (the end of a gesture). False when nothing changed since the last step. */
347
- EngineCore.prototype.commit = function () {
348
- var _a, _b;
349
- __classPrivateFieldSet(this, _EngineCore_nudgeMergeUntil, 0, "f");
350
- if (!__classPrivateFieldGet(this, _EngineCore_history, "f").push(__classPrivateFieldGet(this, _EngineCore_state, "f").scene))
343
+ commit() {
344
+ this.#nudgeMergeUntil = 0;
345
+ if (!this.#history.push(this.#state.scene))
351
346
  return false;
352
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { canUndo: __classPrivateFieldGet(this, _EngineCore_history, "f").canUndo, canRedo: __classPrivateFieldGet(this, _EngineCore_history, "f").canRedo });
353
- (_b = (_a = this.hooks).onDirty) === null || _b === void 0 ? void 0 : _b.call(_a);
347
+ this.#set({ canUndo: this.#history.canUndo, canRedo: this.#history.canRedo });
348
+ this.hooks.onDirty?.();
354
349
  return true;
355
- };
350
+ }
356
351
  /** Throws away what a gesture did and goes back to the last step (Escape in the middle of a drag). */
357
- EngineCore.prototype.revertToCommitted = function () {
358
- this.applyScene(__classPrivateFieldGet(this, _EngineCore_history, "f").current, 'transient');
359
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { overlay: EMPTY_OVERLAY });
360
- };
361
- EngineCore.prototype.undo = function () {
352
+ revertToCommitted() {
353
+ this.applyScene(this.#history.current, 'transient');
354
+ this.#set({ overlay: EMPTY_OVERLAY });
355
+ }
356
+ undo() {
362
357
  this.endTextEdit();
363
358
  // An upright turn still on its way ends here as one step, so that this undo takes that step back.
364
359
  this.cancelRotationReset();
365
- var previous = __classPrivateFieldGet(this, _EngineCore_history, "f").undo();
360
+ const previous = this.#history.undo();
366
361
  if (!previous)
367
362
  return false;
368
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_afterHistoryMove).call(this, previous);
363
+ this.#afterHistoryMove(previous);
369
364
  return true;
370
- };
371
- EngineCore.prototype.redo = function () {
365
+ }
366
+ redo() {
372
367
  this.endTextEdit();
373
368
  this.cancelRotationReset();
374
- var next = __classPrivateFieldGet(this, _EngineCore_history, "f").redo();
369
+ const next = this.#history.redo();
375
370
  if (!next)
376
371
  return false;
377
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_afterHistoryMove).call(this, next);
372
+ this.#afterHistoryMove(next);
378
373
  return true;
379
- };
380
- /** Adds objects on top of the board in one step. Returns their ids. */
381
- EngineCore.prototype.addObjects = function (objects, options) {
382
- var _this = this;
383
- if (options === void 0) { options = {}; }
374
+ }
375
+ #afterHistoryMove(scene) {
376
+ this.#nudgeMergeUntil = 0;
377
+ this.applyScene(scene, 'transient');
378
+ this.#set({ canUndo: this.#history.canUndo, canRedo: this.#history.canRedo, overlay: EMPTY_OVERLAY });
379
+ this.hooks.onDirty?.();
380
+ }
381
+ /**
382
+ * Adds objects on top of the board in one step, except that a drawing goes under the widget cards (a card is added on top).
383
+ * Returns their ids.
384
+ */
385
+ addObjects(objects, options = {}) {
384
386
  if (objects.length === 0)
385
387
  return [];
386
- var fitted = objects.map(function (object) { return __classPrivateFieldGet(_this, _EngineCore_instances, "m", _EngineCore_fitText).call(_this, object); });
387
- this.applyScene(__spreadArray(__spreadArray([], __classPrivateFieldGet(this, _EngineCore_state, "f").scene, true), fitted, true), 'push');
388
- var ids = fitted.map(function (object) { return object.id; });
388
+ const fitted = objects.map((object) => this.#fitText(object));
389
+ this.applyScene(addObjectsBehindWidgetCards(this.#state.scene, fitted), 'push');
390
+ const ids = fitted.map((object) => object.id);
389
391
  if (options.select)
390
392
  this.select(ids);
391
393
  return ids;
392
- };
394
+ }
393
395
  /** Removes objects (and what is inside them) without asking anyone. */
394
- EngineCore.prototype.removeObjects = function (ids) {
395
- var next = removeFromScene(__classPrivateFieldGet(this, _EngineCore_state, "f").scene, ids);
396
- if (next === __classPrivateFieldGet(this, _EngineCore_state, "f").scene)
396
+ removeObjects(ids) {
397
+ const next = removeFromScene(this.#state.scene, ids);
398
+ if (next === this.#state.scene)
397
399
  return false;
398
400
  this.applyScene(next, 'push');
399
401
  return true;
400
- };
402
+ }
401
403
  /** Deletes objects, first asking the host about each widget card among them. Resolves false when the host said no. */
402
- EngineCore.prototype.deleteObjects = function (ids) {
403
- return __awaiter(this, void 0, Promise, function () {
404
- var wanted, widgets, confirm, _i, widgets_1, widget, allowed, error_1;
405
- var _a, _b;
406
- return __generator(this, function (_c) {
407
- switch (_c.label) {
408
- case 0:
409
- wanted = __spreadArray([], ids, true);
410
- if (wanted.length === 0)
411
- return [2 /*return*/, false];
412
- widgets = leafShapesOf(__classPrivateFieldGet(this, _EngineCore_state, "f").scene, wanted).filter(function (shape) { return shape.type === 'widget'; });
413
- confirm = this.hooks.confirmWidgetDeletion;
414
- if (!confirm) return [3 /*break*/, 7];
415
- _i = 0, widgets_1 = widgets;
416
- _c.label = 1;
417
- case 1:
418
- if (!(_i < widgets_1.length)) return [3 /*break*/, 7];
419
- widget = widgets_1[_i];
420
- allowed = true;
421
- _c.label = 2;
422
- case 2:
423
- _c.trys.push([2, 4, , 5]);
424
- return [4 /*yield*/, confirm(widget.widgetId)];
425
- case 3:
426
- allowed = (_c.sent()) !== false;
427
- return [3 /*break*/, 5];
428
- case 4:
429
- error_1 = _c.sent();
430
- allowed = false;
431
- (_b = (_a = this.hooks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, 'The widget deletion check threw', error_1);
432
- return [3 /*break*/, 5];
433
- case 5:
434
- if (!allowed)
435
- return [2 /*return*/, false];
436
- _c.label = 6;
437
- case 6:
438
- _i++;
439
- return [3 /*break*/, 1];
440
- case 7: return [2 /*return*/, this.removeObjects(wanted)];
404
+ async deleteObjects(ids) {
405
+ const wanted = [...ids];
406
+ if (wanted.length === 0)
407
+ return false;
408
+ const widgets = leafShapesOf(this.#state.scene, wanted).filter((shape) => shape.type === 'widget');
409
+ const confirm = this.hooks.confirmWidgetDeletion;
410
+ if (confirm) {
411
+ for (const widget of widgets) {
412
+ let allowed = true;
413
+ try {
414
+ allowed = (await confirm(widget.widgetId)) !== false;
441
415
  }
442
- });
443
- });
444
- };
445
- EngineCore.prototype.deleteSelection = function () {
446
- return __awaiter(this, void 0, Promise, function () {
447
- return __generator(this, function (_a) {
448
- return [2 /*return*/, this.deleteObjects(__classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds)];
449
- });
450
- });
451
- };
416
+ catch (error) {
417
+ allowed = false;
418
+ this.hooks.onError?.('The widget deletion check threw', error);
419
+ }
420
+ if (!allowed)
421
+ return false;
422
+ }
423
+ }
424
+ return this.removeObjects(wanted);
425
+ }
426
+ async deleteSelection() {
427
+ return this.deleteObjects(this.#state.selectedIds);
428
+ }
452
429
  /** Empties the board in one undoable step and tells the host. */
453
- EngineCore.prototype.clearAll = function () {
454
- var _this = this;
430
+ clearAll() {
455
431
  this.endTextEdit();
456
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").scene.length === 0)
432
+ if (this.#state.scene.length === 0)
457
433
  return;
458
434
  this.applyScene([], 'push');
459
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { selectedIds: [], enteredGroupId: null, hoverId: null });
460
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_callHook).call(this, function () { var _a, _b; return (_b = (_a = _this.hooks).onCleared) === null || _b === void 0 ? void 0 : _b.call(_a); }, 'cleared hook');
461
- };
435
+ this.#set({ selectedIds: [], enteredGroupId: null, hoverId: null });
436
+ this.#callHook(() => this.hooks.onCleared?.(), 'cleared hook');
437
+ }
462
438
  // ──────────────────────────────────────────────────────── selection
463
439
  /** Selects units (a group counts once). Everything else is deselected unless `additive`. */
464
- EngineCore.prototype.select = function (ids, options) {
465
- if (options === void 0) { options = {}; }
466
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
467
- var requested = options.additive ? __spreadArray(__spreadArray([], __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds, true), ids, true) : __spreadArray([], ids, true);
468
- var selection = normalizeSelection(scene, requested);
469
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_setSelection).call(this, selection);
470
- };
440
+ select(ids, options = {}) {
441
+ const scene = this.#state.scene;
442
+ const requested = options.additive ? [...this.#state.selectedIds, ...ids] : [...ids];
443
+ const selection = normalizeSelection(scene, requested);
444
+ this.#setSelection(selection);
445
+ }
471
446
  /** Adds the unit to the selection, or takes it out when it is in (Shift-click). */
472
- EngineCore.prototype.toggleSelection = function (id) {
473
- var current = __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds;
447
+ toggleSelection(id) {
448
+ const current = this.#state.selectedIds;
474
449
  if (current.includes(id))
475
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_setSelection).call(this, current.filter(function (candidate) { return candidate !== id; }));
450
+ this.#setSelection(current.filter((candidate) => candidate !== id));
476
451
  else
477
452
  this.select([id], { additive: true });
478
- };
453
+ }
479
454
  /** Deselects everything and leaves the group that was entered. */
480
- EngineCore.prototype.clearSelection = function () {
481
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_setSelection).call(this, [], null);
482
- };
483
- EngineCore.prototype.selectAll = function () {
484
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
485
- var entered = __classPrivateFieldGet(this, _EngineCore_state, "f").enteredGroupId;
486
- var units = scene.filter(function (object) { return (entered ? object.parentId === entered : object.parentId === null); });
487
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_setSelection).call(this, units.map(function (object) { return object.id; }), entered);
488
- };
455
+ clearSelection() {
456
+ this.#setSelection([], null);
457
+ }
458
+ selectAll() {
459
+ const scene = this.#state.scene;
460
+ const entered = this.#state.enteredGroupId;
461
+ const units = scene.filter((object) => (entered ? object.parentId === entered : object.parentId === null));
462
+ this.#setSelection(units.map((object) => object.id), entered);
463
+ }
464
+ #setSelection(selection, enteredGroupId = this.#state.enteredGroupId) {
465
+ let entered = enteredGroupId;
466
+ if (entered) {
467
+ const index = this.sceneIndex();
468
+ // Picking something outside the group that was entered leaves the group.
469
+ const stillInside = selection.length === 0 || selection.every((id) => index.get(id)?.parentId === entered);
470
+ if (!stillInside)
471
+ entered = null;
472
+ }
473
+ const next = sameIds(selection, this.#state.selectedIds) ? this.#state.selectedIds : Object.freeze([...selection]);
474
+ this.#set({ selectedIds: next, enteredGroupId: entered });
475
+ }
489
476
  /** Makes the members of a group pickable one by one, and selects one of them. */
490
- EngineCore.prototype.enterGroup = function (groupId, selectId) {
491
- var group = this.getObject(groupId);
477
+ enterGroup(groupId, selectId) {
478
+ const group = this.getObject(groupId);
492
479
  if (!group || group.type !== 'group')
493
480
  return;
494
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { enteredGroupId: groupId, selectedIds: selectId ? [selectId] : [] });
495
- };
481
+ this.#set({ enteredGroupId: groupId, selectedIds: selectId ? [selectId] : [] });
482
+ }
496
483
  /** Goes back out of the entered group and selects the group itself. */
497
- EngineCore.prototype.exitGroup = function () {
498
- var entered = __classPrivateFieldGet(this, _EngineCore_state, "f").enteredGroupId;
484
+ exitGroup() {
485
+ const entered = this.#state.enteredGroupId;
499
486
  if (!entered)
500
487
  return;
501
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { enteredGroupId: null, selectedIds: [entered] });
502
- };
503
- EngineCore.prototype.setHover = function (id) {
504
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { hoverId: id });
505
- };
488
+ this.#set({ enteredGroupId: null, selectedIds: [entered] });
489
+ }
490
+ setHover(id) {
491
+ this.#set({ hoverId: id });
492
+ }
506
493
  /** The pointer is over the turning dot of the selection (or left it): the dot grows while it is. */
507
- EngineCore.prototype.setRotationDotHover = function (hovered) {
508
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { rotationDotHovered: hovered });
509
- };
494
+ setRotationDotHover(hovered) {
495
+ this.#set({ rotationDotHovered: hovered });
496
+ }
510
497
  /** The pointer is over (or is dragging) an end or the middle of the selected arrow, or left them: that handle grows. */
511
- EngineCore.prototype.setArrowHandleHover = function (handle) {
512
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { arrowHandleHovered: handle });
513
- };
498
+ setArrowHandleHover(handle) {
499
+ this.#set({ arrowHandleHovered: handle });
500
+ }
514
501
  /** The unit under a world point. */
515
- EngineCore.prototype.hitTest = function (worldPoint, ignore) {
516
- var state = __classPrivateFieldGet(this, _EngineCore_state, "f");
502
+ hitTest(worldPoint, ignore) {
503
+ const state = this.#state;
517
504
  return hitTestPoint(state.scene, worldPoint, {
518
505
  zoom: state.viewport.zoom,
519
506
  enteredGroupId: state.enteredGroupId,
520
507
  index: this.sceneIndex(),
521
- ignore: ignore
508
+ ignore
522
509
  });
523
- };
510
+ }
524
511
  /** Every unit under a world point, the lowest first (what an Alt-click steps through). */
525
- EngineCore.prototype.hitTestStack = function (worldPoint) {
526
- var state = __classPrivateFieldGet(this, _EngineCore_state, "f");
512
+ hitTestStack(worldPoint) {
513
+ const state = this.#state;
527
514
  return hitTestStack(state.scene, worldPoint, {
528
515
  zoom: state.viewport.zoom,
529
516
  enteredGroupId: state.enteredGroupId,
530
517
  index: this.sceneIndex()
531
518
  });
532
- };
519
+ }
533
520
  /** The units a rectangle of the world takes. */
534
- EngineCore.prototype.hitTestRect = function (rect, mode, ignore) {
535
- if (mode === void 0) { mode = 'intersect'; }
536
- var state = __classPrivateFieldGet(this, _EngineCore_state, "f");
521
+ hitTestRect(rect, mode = 'intersect', ignore) {
522
+ const state = this.#state;
537
523
  return hitTestRect(state.scene, rect, {
538
524
  zoom: state.viewport.zoom,
539
525
  enteredGroupId: state.enteredGroupId,
540
526
  index: this.sceneIndex(),
541
- mode: mode,
542
- ignore: ignore
527
+ mode,
528
+ ignore
543
529
  });
544
- };
530
+ }
545
531
  // ──────────────────────────────────────────────────────── overlay and cursor
546
- EngineCore.prototype.setOverlay = function (patch) {
547
- var next = __assign(__assign({}, __classPrivateFieldGet(this, _EngineCore_state, "f").overlay), patch);
548
- var changed = false;
549
- for (var _i = 0, _a = Object.keys(patch); _i < _a.length; _i++) {
550
- var key = _a[_i];
551
- if (!Object.is(patch[key], __classPrivateFieldGet(this, _EngineCore_state, "f").overlay[key]))
532
+ setOverlay(patch) {
533
+ const next = { ...this.#state.overlay, ...patch };
534
+ let changed = false;
535
+ for (const key of Object.keys(patch)) {
536
+ if (!Object.is(patch[key], this.#state.overlay[key]))
552
537
  changed = true;
553
538
  }
554
539
  if (changed)
555
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { overlay: next });
556
- };
557
- EngineCore.prototype.clearOverlay = function () {
558
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { overlay: EMPTY_OVERLAY });
559
- };
540
+ this.#set({ overlay: next });
541
+ }
542
+ clearOverlay() {
543
+ this.#set({ overlay: EMPTY_OVERLAY });
544
+ }
560
545
  // ──────────────────────────────────────────────────────── the eraser's trail
561
546
  /** The eraser's trail begins (the pointer went past the drag threshold). The host's frame clock runs while `state.scribble` is not null. */
562
- EngineCore.prototype.beginScribble = function () {
563
- __classPrivateFieldSet(this, _EngineCore_scribble, new Scribble(), "f");
564
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { scribble: __classPrivateFieldGet(this, _EngineCore_scribble, "f").view() });
565
- };
547
+ beginScribble() {
548
+ this.#scribble = new Scribble();
549
+ this.#set({ scribble: this.#scribble.view() });
550
+ }
566
551
  /** The pointer reached a place of the board (world units); the next step of the trail takes it in. */
567
- EngineCore.prototype.extendScribble = function (world) {
568
- var _a;
569
- (_a = __classPrivateFieldGet(this, _EngineCore_scribble, "f")) === null || _a === void 0 ? void 0 : _a.add(world, __classPrivateFieldGet(this, _EngineCore_state, "f").viewport.zoom);
570
- };
552
+ extendScribble(world) {
553
+ this.#scribble?.add(world, this.#state.viewport.zoom);
554
+ }
571
555
  /** The pointer let go: the trail is eaten away over the next frames. */
572
- EngineCore.prototype.stopScribble = function () {
573
- var scribble = __classPrivateFieldGet(this, _EngineCore_scribble, "f");
556
+ stopScribble() {
557
+ const scribble = this.#scribble;
574
558
  if (!scribble)
575
559
  return;
576
560
  scribble.stop();
577
561
  // The end of a finished line is drawn capped: the views are told that this one is finished.
578
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { scribble: scribble.view() });
579
- };
562
+ this.#set({ scribble: scribble.view() });
563
+ }
580
564
  /**
581
565
  * One frame of the trail's life, `elapsedMs` after the last one. Returns false when there is no trail any more (the
582
566
  * host stops its clock), true while it lives.
583
567
  */
584
- EngineCore.prototype.stepScribble = function (elapsedMs) {
585
- var scribble = __classPrivateFieldGet(this, _EngineCore_scribble, "f");
568
+ stepScribble(elapsedMs) {
569
+ const scribble = this.#scribble;
586
570
  if (!scribble) {
587
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").scribble !== null)
588
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { scribble: null });
571
+ if (this.#state.scribble !== null)
572
+ this.#set({ scribble: null });
589
573
  return false;
590
574
  }
591
- var changed = scribble.step(elapsedMs);
575
+ const changed = scribble.step(elapsedMs);
592
576
  if (scribble.finished) {
593
- __classPrivateFieldSet(this, _EngineCore_scribble, null, "f");
594
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { scribble: null });
577
+ this.#scribble = null;
578
+ this.#set({ scribble: null });
595
579
  return false;
596
580
  }
597
581
  if (changed)
598
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { scribble: scribble.view() });
582
+ this.#set({ scribble: scribble.view() });
599
583
  return true;
600
- };
601
- EngineCore.prototype.setCursor = function (cursor) {
602
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { cursor: cursor });
603
- };
584
+ }
585
+ /** Takes the trail away at once (the tool changed, the board was replaced). */
586
+ #dropScribble() {
587
+ this.#scribble = null;
588
+ return this.#state.scribble === null ? {} : { scribble: null };
589
+ }
590
+ setCursor(cursor) {
591
+ this.#set({ cursor });
592
+ }
604
593
  // ──────────────────────────────────────────────────────── tools
605
- EngineCore.prototype.setTool = function (tool, options) {
606
- var _a;
607
- if (options === void 0) { options = {}; }
594
+ setTool(tool, options = {}) {
608
595
  this.endTextEdit();
609
- var patch = __assign(__assign({}, __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_dropScribble).call(this)), { tool: tool, overlay: EMPTY_OVERLAY, cursor: cursorForTool(tool), hoverId: null, rotationDotHovered: false, arrowHandleHovered: null, hoverWidgetId: null });
596
+ const patch = {
597
+ ...this.#dropScribble(),
598
+ tool,
599
+ overlay: EMPTY_OVERLAY,
600
+ cursor: cursorForTool(tool),
601
+ hoverId: null,
602
+ rotationDotHovered: false,
603
+ arrowHandleHovered: null,
604
+ hoverWidgetId: null
605
+ };
610
606
  if (tool === 'library-shape')
611
- patch.libraryShapeKey = (_a = options.libraryShapeKey) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _EngineCore_state, "f").libraryShapeKey;
607
+ patch.libraryShapeKey = options.libraryShapeKey ?? this.#state.libraryShapeKey;
612
608
  if (tool !== 'select' && tool !== 'pan' && !options.keepSelection) {
613
609
  patch.selectedIds = [];
614
610
  patch.enteredGroupId = null;
615
611
  }
616
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, patch);
617
- };
612
+ this.#set(patch);
613
+ }
618
614
  /** Back to the Select tool, unless the person asked for the tool to stay. */
619
- EngineCore.prototype.revertToSelect = function (options) {
620
- if (options === void 0) { options = {}; }
621
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").stickyTool && !options.force)
615
+ revertToSelect(options = {}) {
616
+ if (this.#state.stickyTool && !options.force)
622
617
  return;
623
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").tool !== 'select')
618
+ if (this.#state.tool !== 'select')
624
619
  this.setTool('select', { keepSelection: true });
625
- };
626
- EngineCore.prototype.setStickyTool = function (sticky) {
627
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { stickyTool: sticky });
628
- };
620
+ }
621
+ setStickyTool(sticky) {
622
+ this.#set({ stickyTool: sticky });
623
+ }
629
624
  // ──────────────────────────────────────────────────────── viewport
630
- EngineCore.prototype.setViewport = function (viewport) {
631
- var next = sanitizeViewport(viewport);
632
- var current = __classPrivateFieldGet(this, _EngineCore_state, "f").viewport;
625
+ setViewport(viewport) {
626
+ const next = sanitizeViewport(viewport);
627
+ const current = this.#state.viewport;
633
628
  if (next.x === current.x && next.y === current.y && next.zoom === current.zoom)
634
629
  return;
635
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { viewport: next });
636
- };
637
- EngineCore.prototype.panBy = function (deltaX, deltaY) {
630
+ this.#set({ viewport: next });
631
+ }
632
+ panBy(deltaX, deltaY) {
638
633
  if (deltaX === 0 && deltaY === 0)
639
634
  return;
640
- this.setViewport(panViewport(__classPrivateFieldGet(this, _EngineCore_state, "f").viewport, deltaX, deltaY));
641
- };
635
+ this.setViewport(panViewport(this.#state.viewport, deltaX, deltaY));
636
+ }
642
637
  /** Zooms and keeps the world point under `screenPoint` where it is. */
643
- EngineCore.prototype.zoomAt = function (screenPoint, zoom) {
644
- this.setViewport(zoomAtPoint(__classPrivateFieldGet(this, _EngineCore_state, "f").viewport, screenPoint, zoom));
645
- };
638
+ zoomAt(screenPoint, zoom) {
639
+ this.setViewport(zoomAtPoint(this.#state.viewport, screenPoint, zoom));
640
+ }
641
+ #viewCenter() {
642
+ const { width, height } = this.#state.viewSize;
643
+ return { x: width / 2, y: height / 2 };
644
+ }
646
645
  /** One step up or down the zoom ladder, about the centre of the view. */
647
- EngineCore.prototype.zoomStep = function (direction) {
648
- var viewport = __classPrivateFieldGet(this, _EngineCore_state, "f").viewport;
649
- this.zoomAt(__classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_viewCenter).call(this), nextZoomStep(viewport.zoom, direction));
650
- };
646
+ zoomStep(direction) {
647
+ const viewport = this.#state.viewport;
648
+ this.zoomAt(this.#viewCenter(), nextZoomStep(viewport.zoom, direction));
649
+ }
651
650
  /** A zoom level (1 is 100%), about the centre of the view. */
652
- EngineCore.prototype.zoomTo = function (zoom) {
653
- this.zoomAt(__classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_viewCenter).call(this), clampZoom(zoom));
654
- };
651
+ zoomTo(zoom) {
652
+ this.zoomAt(this.#viewCenter(), clampZoom(zoom));
653
+ }
655
654
  /** 100%, with the world origin where it was at the centre of the view. */
656
- EngineCore.prototype.zoomReset = function () {
655
+ zoomReset() {
657
656
  this.zoomTo(1);
658
- };
657
+ }
658
+ #fittedViewport(scene) {
659
+ const bounds = boardVisualBounds(scene);
660
+ if (!bounds)
661
+ return { ...INITIAL_VIEWPORT };
662
+ return fitViewportToRect(bounds, this.#state.viewSize, VIEW_FIT_PADDING);
663
+ }
659
664
  /** Shows everything on the board. An empty board goes back to the start. */
660
- EngineCore.prototype.zoomToFit = function () {
661
- this.setViewport(__classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_fittedViewport).call(this, __classPrivateFieldGet(this, _EngineCore_state, "f").scene));
662
- };
665
+ zoomToFit() {
666
+ this.setViewport(this.#fittedViewport(this.#state.scene));
667
+ }
663
668
  /** Shows the selection, or everything when nothing is selected. */
664
- EngineCore.prototype.zoomToSelection = function () {
665
- var bounds = boundsOfObjects(__classPrivateFieldGet(this, _EngineCore_state, "f").scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds);
669
+ zoomToSelection() {
670
+ const bounds = boundsOfObjects(this.#state.scene, this.#state.selectedIds);
666
671
  if (!bounds) {
667
672
  this.zoomToFit();
668
673
  return;
669
674
  }
670
- this.setViewport(fitViewportToRect(bounds, __classPrivateFieldGet(this, _EngineCore_state, "f").viewSize, VIEW_FIT_PADDING, 2));
671
- };
675
+ this.setViewport(fitViewportToRect(bounds, this.#state.viewSize, VIEW_FIT_PADDING, 2));
676
+ }
672
677
  /** The rectangle of the world that is on screen. */
673
- EngineCore.prototype.visibleRect = function () {
674
- return visibleWorldRect(__classPrivateFieldGet(this, _EngineCore_state, "f").viewport, __classPrivateFieldGet(this, _EngineCore_state, "f").viewSize);
675
- };
678
+ visibleRect() {
679
+ return visibleWorldRect(this.#state.viewport, this.#state.viewSize);
680
+ }
676
681
  /** The point of the world at a point of the board element. */
677
- EngineCore.prototype.toWorld = function (screenPoint) {
678
- return screenToWorld(__classPrivateFieldGet(this, _EngineCore_state, "f").viewport, screenPoint);
679
- };
682
+ toWorld(screenPoint) {
683
+ return screenToWorld(this.#state.viewport, screenPoint);
684
+ }
680
685
  /** The middle of what is on screen, in world units (where a button puts a new object). */
681
- EngineCore.prototype.visibleCenter = function () {
682
- var rect = this.visibleRect();
686
+ visibleCenter() {
687
+ const rect = this.visibleRect();
683
688
  return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
684
- };
689
+ }
690
+ // ──────────────────────────────────────────────────────── text
691
+ #fitText(object) {
692
+ return object.type === 'text' ? fitTextObject(object, this.services.measureText) : object;
693
+ }
694
+ /** Lays out every text of a scene again (after fonts loaded, a file was read, or a style changed). */
695
+ #fitTexts(scene) {
696
+ let changed = false;
697
+ const next = scene.map((object) => {
698
+ if (object.type !== 'text')
699
+ return object;
700
+ const fitted = fitTextObject(object, this.services.measureText);
701
+ if (fitted !== object)
702
+ changed = true;
703
+ return fitted;
704
+ });
705
+ return changed ? next : scene;
706
+ }
685
707
  /** Fonts finished loading: letters changed width, so every text is laid out again. */
686
- EngineCore.prototype.notifyFontsChanged = function () {
708
+ notifyFontsChanged() {
687
709
  // Not a change the person made: no undo step, and nothing is saved because of it.
688
- var committed = __classPrivateFieldGet(this, _EngineCore_history, "f").current;
689
- var refitCommitted = reconcileArrowBindings(__classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_fitTexts).call(this, committed));
710
+ const committed = this.#history.current;
711
+ const refitCommitted = reconcileArrowBindings(this.#fitTexts(committed));
690
712
  if (refitCommitted !== committed)
691
- __classPrivateFieldGet(this, _EngineCore_history, "f").replaceCurrent(refitCommitted);
692
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { fontRevision: __classPrivateFieldGet(this, _EngineCore_state, "f").fontRevision + 1 });
693
- var next = __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_fitTexts).call(this, __classPrivateFieldGet(this, _EngineCore_state, "f").scene);
694
- if (next !== __classPrivateFieldGet(this, _EngineCore_state, "f").scene)
713
+ this.#history.replaceCurrent(refitCommitted);
714
+ this.#set({ fontRevision: this.#state.fontRevision + 1 });
715
+ const next = this.#fitTexts(this.#state.scene);
716
+ if (next !== this.#state.scene)
695
717
  this.applyScene(next, 'transient');
696
- };
718
+ }
697
719
  /** Remembers the font family for the next text object the person places. */
698
- EngineCore.prototype.setPreferredTextFontFamily = function (fontFamily) {
699
- __classPrivateFieldSet(this, _EngineCore_preferredTextFontFamily, fontFamily, "f");
700
- };
701
- EngineCore.prototype.setWorkspaceToolDefaults = function (settings) {
702
- var _a, _b, _c;
703
- __classPrivateFieldSet(this, _EngineCore_workspaceTextDefaults, (_a = settings.text) !== null && _a !== void 0 ? _a : null, "f");
704
- __classPrivateFieldSet(this, _EngineCore_workspacePaintDefaults, (_b = settings.paint) !== null && _b !== void 0 ? _b : null, "f");
705
- if ((_c = settings.text) === null || _c === void 0 ? void 0 : _c.fontFamily)
706
- __classPrivateFieldSet(this, _EngineCore_preferredTextFontFamily, settings.text.fontFamily, "f");
707
- };
708
- EngineCore.prototype.workspacePaintForNewShape = function (wireframe) {
709
- if (!__classPrivateFieldGet(this, _EngineCore_workspacePaintDefaults, "f"))
720
+ setPreferredTextFontFamily(fontFamily) {
721
+ this.#preferredTextFontFamily = fontFamily;
722
+ }
723
+ setWorkspaceToolDefaults(settings) {
724
+ this.#workspaceTextDefaults = settings.text ?? null;
725
+ this.#workspacePaintDefaults = settings.paint ?? null;
726
+ if (settings.text?.fontFamily)
727
+ this.#preferredTextFontFamily = settings.text.fontFamily;
728
+ }
729
+ workspacePaintForNewShape(wireframe) {
730
+ if (!this.#workspacePaintDefaults)
710
731
  return {};
711
732
  if (wireframe) {
712
- var _a = __classPrivateFieldGet(this, _EngineCore_workspacePaintDefaults, "f"), stroke = _a.stroke, strokeWidth = _a.strokeWidth, strokeStyle = _a.strokeStyle, opacity = _a.opacity;
713
- return __assign(__assign(__assign(__assign({}, (stroke !== undefined ? { stroke: stroke } : {})), (strokeWidth !== undefined ? { strokeWidth: strokeWidth } : {})), (strokeStyle !== undefined ? { strokeStyle: strokeStyle } : {})), (opacity !== undefined ? { opacity: opacity } : {}));
733
+ const { stroke, strokeWidth, strokeStyle, opacity } = this.#workspacePaintDefaults;
734
+ return {
735
+ ...(stroke !== undefined ? { stroke } : {}),
736
+ ...(strokeWidth !== undefined ? { strokeWidth } : {}),
737
+ ...(strokeStyle !== undefined ? { strokeStyle } : {}),
738
+ ...(opacity !== undefined ? { opacity } : {})
739
+ };
714
740
  }
715
- return __assign({}, __classPrivateFieldGet(this, _EngineCore_workspacePaintDefaults, "f"));
716
- };
741
+ return { ...this.#workspacePaintDefaults };
742
+ }
717
743
  /**
718
744
  * Makes a text object, puts it on the board and starts editing it. A click makes a label whose width follows its
719
745
  * text; a width makes a box whose lines wrap. Nothing is recorded until the editing ends with text in it.
720
746
  */
721
- EngineCore.prototype.createText = function (point, options) {
722
- var _a, _b, _c;
723
- if (options === void 0) { options = {}; }
747
+ createText(point, options = {}) {
724
748
  this.endTextEdit();
725
- var fixedWidth = options.width !== undefined && options.width > TEXT_DEFAULTS.minimumWidth;
726
- var base = createTextObject(__assign({ id: this.services.createId('obj'), x: point.x, y: point.y, width: fixedWidth ? options.width : TEXT_DEFAULTS.minimumWidth, autoWidth: !fixedWidth, fontFamily: (_c = (_a = __classPrivateFieldGet(this, _EngineCore_preferredTextFontFamily, "f")) !== null && _a !== void 0 ? _a : (_b = __classPrivateFieldGet(this, _EngineCore_workspaceTextDefaults, "f")) === null || _b === void 0 ? void 0 : _b.fontFamily) !== null && _c !== void 0 ? _c : TEXT_DEFAULTS.fontFamily }, __classPrivateFieldGet(this, _EngineCore_workspaceTextDefaults, "f")));
727
- var text = __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_fitText).call(this, base);
728
- var sceneBefore = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
729
- this.applyScene(__spreadArray(__spreadArray([], sceneBefore, true), [text], false), 'transient');
730
- __classPrivateFieldSet(this, _EngineCore_textSession, { id: text.id, isNew: true, sceneBefore: sceneBefore, typed: false }, "f");
731
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { editingTextId: text.id, selectedIds: [text.id], enteredGroupId: null });
749
+ const fixedWidth = options.width !== undefined && options.width > TEXT_DEFAULTS.minimumWidth;
750
+ const base = createTextObject({
751
+ id: this.services.createId('obj'),
752
+ x: point.x,
753
+ y: point.y,
754
+ width: fixedWidth ? options.width : TEXT_DEFAULTS.minimumWidth,
755
+ autoWidth: !fixedWidth,
756
+ fontFamily: this.#preferredTextFontFamily ?? this.#workspaceTextDefaults?.fontFamily ?? TEXT_DEFAULTS.fontFamily,
757
+ ...this.#workspaceTextDefaults
758
+ });
759
+ const text = this.#fitText(base);
760
+ const sceneBefore = this.#state.scene;
761
+ // A text typed after a widget stands goes behind it, like every other drawing.
762
+ this.applyScene(addObjectsBehindWidgetCards(sceneBefore, [text]), 'transient');
763
+ this.#textSession = { id: text.id, isNew: true, sceneBefore, typed: false };
764
+ this.#set({ editingTextId: text.id, selectedIds: [text.id], enteredGroupId: null });
732
765
  return text.id;
733
- };
766
+ }
734
767
  /** Starts editing the text of an existing text object. */
735
- EngineCore.prototype.beginTextEdit = function (id) {
736
- var _a;
737
- var object = this.getObject(id);
768
+ beginTextEdit(id) {
769
+ const object = this.getObject(id);
738
770
  if (!object || object.type !== 'text')
739
771
  return false;
740
- if (((_a = __classPrivateFieldGet(this, _EngineCore_textSession, "f")) === null || _a === void 0 ? void 0 : _a.id) === id)
772
+ if (this.#textSession?.id === id)
741
773
  return true;
742
774
  this.endTextEdit();
743
- __classPrivateFieldSet(this, _EngineCore_textSession, { id: id, isNew: false, sceneBefore: __classPrivateFieldGet(this, _EngineCore_state, "f").scene, typed: false }, "f");
744
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { editingTextId: id, selectedIds: [id] });
775
+ this.#textSession = { id, isNew: false, sceneBefore: this.#state.scene, typed: false };
776
+ this.#set({ editingTextId: id, selectedIds: [id] });
745
777
  return true;
746
- };
778
+ }
747
779
  /** The text the person has typed so far; the box is laid out again on every call. */
748
- EngineCore.prototype.updateEditingText = function (text) {
749
- var _this = this;
750
- var session = __classPrivateFieldGet(this, _EngineCore_textSession, "f");
780
+ updateEditingText(text) {
781
+ const session = this.#textSession;
751
782
  if (!session)
752
783
  return;
753
- var clipped = text.length > MAX_TEXT_LENGTH ? text.slice(0, MAX_TEXT_LENGTH) : text;
754
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
755
- var next = scene.map(function (object) {
756
- return object.id === session.id && object.type === 'text' && object.text !== clipped
757
- ? fitTextObject(__assign(__assign({}, object), { text: clipped }), _this.services.measureText)
758
- : object;
759
- });
760
- var changed = next.some(function (object, position) { return object !== scene[position]; });
784
+ const clipped = text.length > MAX_TEXT_LENGTH ? text.slice(0, MAX_TEXT_LENGTH) : text;
785
+ const scene = this.#state.scene;
786
+ const next = scene.map((object) => object.id === session.id && object.type === 'text' && object.text !== clipped
787
+ ? fitTextObject({ ...object, text: clipped }, this.services.measureText)
788
+ : object);
789
+ const changed = next.some((object, position) => object !== scene[position]);
761
790
  if (!changed)
762
791
  return;
763
792
  this.applyScene(next, 'transient');
764
793
  session.typed = true;
765
794
  // The board is not recorded until the typing ends, but the letters are on it: the host's next save takes them.
766
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_callHook).call(this, function () { var _a, _b; return (_b = (_a = _this.hooks).onDraftChange) === null || _b === void 0 ? void 0 : _b.call(_a); }, 'draft change hook');
767
- };
795
+ this.#callHook(() => this.hooks.onDraftChange?.(), 'draft change hook');
796
+ }
768
797
  /**
769
798
  * Finishes the edit. An empty text is removed (a new one leaves nothing behind, not even an undo step);
770
799
  * otherwise creation and typing together are one undo step.
771
800
  */
772
- EngineCore.prototype.endTextEdit = function () {
773
- var _this = this;
774
- var session = __classPrivateFieldGet(this, _EngineCore_textSession, "f");
801
+ endTextEdit() {
802
+ const session = this.#textSession;
775
803
  if (!session)
776
804
  return null;
777
- __classPrivateFieldSet(this, _EngineCore_textSession, null, "f");
778
- var object = this.getObject(session.id);
779
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { editingTextId: null });
780
- var kept = null;
805
+ this.#textSession = null;
806
+ const object = this.getObject(session.id);
807
+ this.#set({ editingTextId: null });
808
+ let kept = null;
781
809
  if (object && object.type === 'text') {
782
810
  if (object.text.trim() === '') {
783
811
  if (session.isNew) {
784
812
  this.applyScene(session.sceneBefore, 'transient');
785
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { selectedIds: [] });
813
+ this.#set({ selectedIds: [] });
786
814
  // A save may have taken the letters that were typed before they were all deleted: it has to be told they are gone.
787
815
  if (session.typed)
788
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_callHook).call(this, function () { var _a, _b; return (_b = (_a = _this.hooks).onDraftChange) === null || _b === void 0 ? void 0 : _b.call(_a); }, 'draft change hook');
816
+ this.#callHook(() => this.hooks.onDraftChange?.(), 'draft change hook');
789
817
  }
790
818
  else {
791
- this.applyScene(removeFromScene(__classPrivateFieldGet(this, _EngineCore_state, "f").scene, [session.id]), 'push');
819
+ this.applyScene(removeFromScene(this.#state.scene, [session.id]), 'push');
792
820
  }
793
821
  }
794
822
  else {
@@ -797,243 +825,281 @@ var EngineCore = /** @class */ (function () {
797
825
  }
798
826
  }
799
827
  // The Text tool is used once: the board goes back to Select when the typing is over (unless the tool is kept).
800
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").tool === 'text' && !__classPrivateFieldGet(this, _EngineCore_state, "f").stickyTool)
828
+ if (this.#state.tool === 'text' && !this.#state.stickyTool)
801
829
  this.setTool('select', { keepSelection: true });
802
830
  return kept;
803
- };
831
+ }
804
832
  // ──────────────────────────────────────────────────────── commands on the selection
805
833
  /** Changes how the selection looks. `commit: false` is for a slider that is still being dragged: call `commit()` when it ends. */
806
- EngineCore.prototype.setStyle = function (patch, options) {
807
- var _this = this;
808
- if (options === void 0) { options = {}; }
809
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
810
- var targetIds = withDescendantIds(scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds);
811
- var changed = false;
812
- var next = scene.map(function (object) {
834
+ setStyle(patch, options = {}) {
835
+ const scene = this.#state.scene;
836
+ const targetIds = withDescendantIds(scene, this.#state.selectedIds);
837
+ let changed = false;
838
+ const next = scene.map((object) => {
813
839
  if (!targetIds.has(object.id) || object.type === 'group')
814
840
  return object;
815
- var styled = applyStylePatch(object, patch);
841
+ const styled = applyStylePatch(object, patch);
816
842
  if (styled === object)
817
843
  return object;
818
844
  changed = true;
819
- return __classPrivateFieldGet(_this, _EngineCore_instances, "m", _EngineCore_fitText).call(_this, styled);
845
+ return this.#fitText(styled);
820
846
  });
821
847
  if (!changed)
822
848
  return false;
823
849
  this.applyScene(next, options.commit === false ? 'transient' : 'push');
824
850
  return true;
825
- };
851
+ }
826
852
  /**
827
853
  * Turns the one selected shape back upright, about its own middle (a double click on the turning dot). One undo step.
828
854
  * False when the selection is not a single shape, or the shape stands upright already.
829
855
  */
830
- EngineCore.prototype.resetSelectionRotation = function () {
831
- var _this = this;
832
- var shapes = this.selectedShapes();
856
+ resetSelectionRotation() {
857
+ const shapes = this.selectedShapes();
833
858
  if (shapes.length !== 1 || Math.abs(shapes[0].rotation) < UPRIGHT_TOLERANCE_DEGREES)
834
859
  return false;
835
860
  this.cancelRotationReset();
836
- var turned = shapes[0];
837
- var startRotation = turned.rotation;
838
- var startAt = this.services.now();
839
- var committed = false;
840
- var cancelFrame = null;
841
- var commitCurrent = function () {
861
+ const turned = shapes[0];
862
+ const startRotation = turned.rotation;
863
+ const startAt = this.services.now();
864
+ let committed = false;
865
+ let cancelFrame = null;
866
+ const commitCurrent = () => {
842
867
  if (committed)
843
868
  return;
844
869
  committed = true;
845
- __classPrivateFieldSet(_this, _EngineCore_rotationResetCancel, null, "f");
846
- var shape = _this.getObject(turned.id);
847
- var current = shape && 'rotation' in shape ? shape.rotation : startRotation;
848
- var next = __classPrivateFieldGet(_this, _EngineCore_state, "f").scene.map(function (object) { return (object.id === turned.id ? __assign(__assign({}, turned), { rotation: current }) : object); });
849
- _this.applyScene(next, 'push');
870
+ this.#rotationResetCancel = null;
871
+ const shape = this.getObject(turned.id);
872
+ const current = shape && 'rotation' in shape ? shape.rotation : startRotation;
873
+ const next = this.#state.scene.map((object) => (object.id === turned.id ? { ...turned, rotation: current } : object));
874
+ this.applyScene(next, 'push');
850
875
  };
851
876
  // The time comes from the engine's own clock, not from the frame callback: a browser hands the callback a time since the
852
877
  // page opened, while `startAt` is read from `services.now` (the wall clock), so mixing the two would never finish the turn.
853
- var tick = function () {
854
- var elapsed = _this.services.now() - startAt;
855
- var progress = rotationResetProgress(elapsed);
856
- var angle = rotationAfterResetProgress(startRotation, progress);
857
- var next = __classPrivateFieldGet(_this, _EngineCore_state, "f").scene.map(function (object) { return (object.id === turned.id ? __assign(__assign({}, turned), { rotation: angle }) : object); });
858
- _this.applyScene(next, 'transient');
878
+ const tick = () => {
879
+ const elapsed = this.services.now() - startAt;
880
+ const progress = rotationResetProgress(elapsed);
881
+ const angle = rotationAfterResetProgress(startRotation, progress);
882
+ const next = this.#state.scene.map((object) => (object.id === turned.id ? { ...turned, rotation: angle } : object));
883
+ this.applyScene(next, 'transient');
859
884
  if (progress >= 1) {
860
- cancelFrame === null || cancelFrame === void 0 ? void 0 : cancelFrame();
885
+ cancelFrame?.();
861
886
  committed = true;
862
- __classPrivateFieldSet(_this, _EngineCore_rotationResetCancel, null, "f");
863
- var upright = __classPrivateFieldGet(_this, _EngineCore_state, "f").scene.map(function (object) { return (object.id === turned.id ? __assign(__assign({}, turned), { rotation: 0 }) : object); });
864
- _this.applyScene(upright, 'push');
887
+ this.#rotationResetCancel = null;
888
+ const upright = this.#state.scene.map((object) => (object.id === turned.id ? { ...turned, rotation: 0 } : object));
889
+ this.applyScene(upright, 'push');
865
890
  return;
866
891
  }
867
- cancelFrame = _this.services.requestAnimationFrame(tick);
892
+ cancelFrame = this.services.requestAnimationFrame(tick);
868
893
  };
869
894
  cancelFrame = this.services.requestAnimationFrame(tick);
870
- __classPrivateFieldSet(this, _EngineCore_rotationResetCancel, function () {
871
- cancelFrame === null || cancelFrame === void 0 ? void 0 : cancelFrame();
895
+ this.#rotationResetCancel = () => {
896
+ cancelFrame?.();
872
897
  commitCurrent();
873
- }, "f");
898
+ };
874
899
  return true;
875
- };
900
+ }
876
901
  /**
877
902
  * Lays the one selected text out in one line again, as it was when it was made: its width follows its letters (a
878
903
  * double click on its side handle). One undo step. False when the selection is not a single text, or it follows its letters already.
879
904
  */
880
- EngineCore.prototype.fitSelectedTextToContent = function () {
881
- var shapes = this.selectedShapes();
905
+ fitSelectedTextToContent() {
906
+ const shapes = this.selectedShapes();
882
907
  if (shapes.length !== 1 || shapes[0].type !== 'text' || shapes[0].autoWidth)
883
908
  return false;
884
- var only = shapes[0];
885
- var fitted = __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_fitText).call(this, __assign(__assign({}, only), { autoWidth: true }));
886
- this.applyScene(__classPrivateFieldGet(this, _EngineCore_state, "f").scene.map(function (object) { return (object.id === only.id ? fitted : object); }), 'push');
909
+ const only = shapes[0];
910
+ const fitted = this.#fitText({ ...only, autoWidth: true });
911
+ this.applyScene(this.#state.scene.map((object) => (object.id === only.id ? fitted : object)), 'push');
887
912
  return true;
888
- };
913
+ }
889
914
  /** Moves the selection by a distance (an arrow key). Presses close together are one undo step. */
890
- EngineCore.prototype.nudgeSelection = function (deltaX, deltaY) {
891
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
892
- var next = translateObjects(scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds, deltaX, deltaY);
915
+ nudgeSelection(deltaX, deltaY) {
916
+ const scene = this.#state.scene;
917
+ const next = translateObjects(scene, this.#state.selectedIds, deltaX, deltaY);
893
918
  if (next === scene)
894
919
  return false;
895
- var now = this.services.now();
896
- var merging = now < __classPrivateFieldGet(this, _EngineCore_nudgeMergeUntil, "f");
920
+ const now = this.services.now();
921
+ const merging = now < this.#nudgeMergeUntil;
897
922
  this.applyScene(next, merging ? 'replace' : 'push');
898
- __classPrivateFieldSet(this, _EngineCore_nudgeMergeUntil, now + NUDGE_MERGE_MS, "f");
923
+ this.#nudgeMergeUntil = now + NUDGE_MERGE_MS;
924
+ return true;
925
+ }
926
+ alignSelection(mode) {
927
+ return this.#arrange((scene, ids) => alignObjects(scene, ids, mode));
928
+ }
929
+ distributeSelection(axis) {
930
+ return this.#arrange((scene, ids) => distributeObjects(scene, ids, axis));
931
+ }
932
+ #arrange(change) {
933
+ const scene = this.#state.scene;
934
+ const next = change(scene, this.#state.selectedIds);
935
+ if (next === scene)
936
+ return false;
937
+ this.applyScene(next, 'push');
899
938
  return true;
900
- };
901
- EngineCore.prototype.alignSelection = function (mode) {
902
- return __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_arrange).call(this, function (scene, ids) { return alignObjects(scene, ids, mode); });
903
- };
904
- EngineCore.prototype.distributeSelection = function (axis) {
905
- return __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_arrange).call(this, function (scene, ids) { return distributeObjects(scene, ids, axis); });
906
- };
907
- EngineCore.prototype.reorderSelection = function (mode) {
908
- return __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_arrange).call(this, function (scene, ids) { return reorderObjects(scene, ids, mode); });
909
- };
939
+ }
940
+ reorderSelection(mode) {
941
+ return this.#arrange((scene, ids) => reorderObjects(scene, ids, mode));
942
+ }
910
943
  /** Puts the selected units in a group, which becomes the selection. */
911
- EngineCore.prototype.groupSelection = function () {
912
- var grouped = groupObjects(__classPrivateFieldGet(this, _EngineCore_state, "f").scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds, this.services.createId('group'));
944
+ groupSelection() {
945
+ const grouped = groupObjects(this.#state.scene, this.#state.selectedIds, this.services.createId('group'));
913
946
  if (!grouped)
914
947
  return false;
915
948
  this.applyScene(grouped.scene, 'push');
916
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { selectedIds: [grouped.groupId], enteredGroupId: null });
949
+ this.#set({ selectedIds: [grouped.groupId], enteredGroupId: null });
917
950
  return true;
918
- };
951
+ }
919
952
  /** Dissolves the selected groups; their members become the selection. */
920
- EngineCore.prototype.ungroupSelection = function () {
921
- var _a = ungroupObjects(__classPrivateFieldGet(this, _EngineCore_state, "f").scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds), scene = _a.scene, releasedIds = _a.releasedIds;
922
- if (scene === __classPrivateFieldGet(this, _EngineCore_state, "f").scene)
953
+ ungroupSelection() {
954
+ const { scene, releasedIds } = ungroupObjects(this.#state.scene, this.#state.selectedIds);
955
+ if (scene === this.#state.scene)
923
956
  return false;
924
957
  this.applyScene(scene, 'push');
925
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { selectedIds: releasedIds, enteredGroupId: null });
958
+ this.#set({ selectedIds: releasedIds, enteredGroupId: null });
926
959
  return true;
927
- };
960
+ }
928
961
  // ──────────────────────────────────────────────────────── clipboard
929
- EngineCore.prototype.hasClipboard = function () {
930
- return __classPrivateFieldGet(this, _EngineCore_clipboard, "f") !== null;
931
- };
962
+ hasClipboard() {
963
+ return this.#clipboard !== null;
964
+ }
932
965
  /** Remembers the selection for a paste. */
933
- EngineCore.prototype.copySelection = function () {
934
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
935
- var rootIds = normalizeSelection(scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds);
966
+ copySelection() {
967
+ const scene = this.#state.scene;
968
+ const rootIds = normalizeSelection(scene, this.#state.selectedIds);
936
969
  if (rootIds.length === 0)
937
970
  return false;
938
- var included = withDescendantIds(scene, rootIds);
939
- __classPrivateFieldSet(this, _EngineCore_clipboard, { objects: scene.filter(function (object) { return included.has(object.id); }), rootIds: rootIds }, "f");
940
- __classPrivateFieldSet(this, _EngineCore_pasteSteps, 0, "f");
971
+ const included = withDescendantIds(scene, rootIds);
972
+ this.#clipboard = { objects: scene.filter((object) => included.has(object.id)), rootIds };
973
+ this.#pasteSteps = 0;
941
974
  return true;
942
- };
975
+ }
943
976
  /** Copies the selection and removes it, without asking about widget cards: the widget itself stays where it is stored. */
944
- EngineCore.prototype.cutSelection = function () {
977
+ cutSelection() {
945
978
  if (!this.copySelection())
946
979
  return false;
947
- var removed = this.removeObjects(__classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds);
980
+ const removed = this.removeObjects(this.#state.selectedIds);
948
981
  if (removed)
949
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { selectedIds: [] });
982
+ this.#set({ selectedIds: [] });
950
983
  return removed;
951
- };
984
+ }
952
985
  /** Puts a copy of the clipboard on the board, centred on `at` (or shifted a little from the original). Returns the new ids. */
953
- EngineCore.prototype.paste = function (at) {
954
- if (at === void 0) { at = this.lastPointerWorld; }
955
- var clipboard = __classPrivateFieldGet(this, _EngineCore_clipboard, "f");
986
+ paste(at = this.lastPointerWorld) {
987
+ const clipboard = this.#clipboard;
956
988
  if (!clipboard)
957
989
  return [];
958
- var bounds = boundsOfObjects(clipboard.objects, clipboard.rootIds);
959
- __classPrivateFieldSet(this, _EngineCore_pasteSteps, __classPrivateFieldGet(this, _EngineCore_pasteSteps, "f") + 1, "f");
990
+ const bounds = boundsOfObjects(clipboard.objects, clipboard.rootIds);
991
+ this.#pasteSteps += 1;
960
992
  // Each paste after the first steps a little further, so copies pasted in a row do not hide each other.
961
- var cascade = (__classPrivateFieldGet(this, _EngineCore_pasteSteps, "f") - 1) * PASTE_OFFSET;
962
- var offset = at && bounds
993
+ const cascade = (this.#pasteSteps - 1) * PASTE_OFFSET;
994
+ const offset = at && bounds
963
995
  ? { x: at.x - (bounds.x + bounds.width / 2) + cascade, y: at.y - (bounds.y + bounds.height / 2) + cascade }
964
- : { x: PASTE_OFFSET * __classPrivateFieldGet(this, _EngineCore_pasteSteps, "f"), y: PASTE_OFFSET * __classPrivateFieldGet(this, _EngineCore_pasteSteps, "f") };
965
- return __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_insertCopies).call(this, clipboard.objects, clipboard.rootIds, offset);
966
- };
996
+ : { x: PASTE_OFFSET * this.#pasteSteps, y: PASTE_OFFSET * this.#pasteSteps };
997
+ return this.#insertCopies(clipboard.objects, clipboard.rootIds, offset);
998
+ }
967
999
  /** A copy of the selection, a little to the side and below. The copy becomes the selection. */
968
- EngineCore.prototype.duplicateSelection = function () {
969
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
970
- var rootIds = normalizeSelection(scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds);
1000
+ duplicateSelection() {
1001
+ const scene = this.#state.scene;
1002
+ const rootIds = normalizeSelection(scene, this.#state.selectedIds);
971
1003
  if (rootIds.length === 0)
972
1004
  return [];
973
- return __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_insertCopies).call(this, scene, rootIds, { x: PASTE_OFFSET, y: PASTE_OFFSET });
974
- };
1005
+ return this.#insertCopies(scene, rootIds, { x: PASTE_OFFSET, y: PASTE_OFFSET });
1006
+ }
975
1007
  /** Copies the selection in place for an Alt-drag: one undo step when the drag ends. */
976
- EngineCore.prototype.duplicateSelectionForDrag = function () {
977
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
978
- var rootIds = normalizeSelection(scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds);
1008
+ duplicateSelectionForDrag() {
1009
+ const scene = this.#state.scene;
1010
+ const rootIds = normalizeSelection(scene, this.#state.selectedIds);
979
1011
  if (rootIds.length === 0)
980
1012
  return [];
981
- return __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_insertCopies).call(this, scene, rootIds, { x: 0, y: 0 }, 'transient');
982
- };
1013
+ return this.#insertCopies(scene, rootIds, { x: 0, y: 0 }, 'transient');
1014
+ }
1015
+ #insertCopies(source, rootIds, offset, mode = 'push') {
1016
+ const { objects, idMap } = duplicateObjects(source, rootIds, offset, (type) => this.services.createId(type === 'group' ? 'group' : 'obj'));
1017
+ if (objects.length === 0)
1018
+ return [];
1019
+ const duplicatesWidgets = this.hooks.onWidgetDuplicated ?? null;
1020
+ const pending = { ...this.#state.pending };
1021
+ const widgetClones = [];
1022
+ const prepared = objects.map((object) => {
1023
+ if (object.type !== 'widget')
1024
+ return object;
1025
+ if (duplicatesWidgets) {
1026
+ // The card waits, unselected, for the host to make the widget behind it.
1027
+ pending[object.id] = 'duplicating';
1028
+ widgetClones.push({ sourceWidgetId: object.widgetId, clone: object });
1029
+ return object;
1030
+ }
1031
+ // With no host to copy the widget, a copy of a card is only a picture of it.
1032
+ return this.#flattenWidgetCard(object);
1033
+ });
1034
+ // A copy of a member goes into the group of the original; if that group is gone it is repaired to the top level.
1035
+ this.applyScene(normalizeScene([...this.#state.scene, ...prepared.map((object) => this.#fitText(object))]), mode);
1036
+ this.#set({ pending: Object.freeze(pending) });
1037
+ const rootCopyIds = rootIds.map((id) => idMap.get(id)).filter((id) => !!id);
1038
+ const selectable = rootCopyIds.filter((id) => !pending[id]);
1039
+ this.#setSelection(selectable);
1040
+ for (const { sourceWidgetId, clone } of widgetClones) {
1041
+ this.#callHook(() => duplicatesWidgets?.(sourceWidgetId, clone), 'widget duplicated hook');
1042
+ }
1043
+ return rootCopyIds;
1044
+ }
1045
+ /** A widget card with its widget gone: the screenshot it had, or an empty frame. */
1046
+ #flattenWidgetCard(card) {
1047
+ const box = { id: card.id, parentId: card.parentId, x: card.x, y: card.y, width: card.width, height: card.height, rotation: card.rotation, opacity: card.opacity };
1048
+ if (card.thumbnail)
1049
+ return createImageObject({ ...box, src: card.thumbnail, naturalWidth: card.width, naturalHeight: card.height });
1050
+ return createRectObject(box);
1051
+ }
983
1052
  // ──────────────────────────────────────────────────────── widget cards (the parts every caller needs)
984
1053
  /** Marks cards as waiting for the host (a loader is shown over them). `null` clears the mark. */
985
- EngineCore.prototype.setPending = function (id, state) {
986
- var _a;
987
- var current = __classPrivateFieldGet(this, _EngineCore_state, "f").pending;
988
- if (((_a = current[id]) !== null && _a !== void 0 ? _a : null) === state)
1054
+ setPending(id, state) {
1055
+ const current = this.#state.pending;
1056
+ if ((current[id] ?? null) === state)
989
1057
  return;
990
- var next = __assign({}, current);
1058
+ const next = { ...current };
991
1059
  if (state)
992
1060
  next[id] = state;
993
1061
  else
994
1062
  delete next[id];
995
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { pending: Object.freeze(next) });
996
- };
1063
+ this.#set({ pending: Object.freeze(next) });
1064
+ }
997
1065
  /** What the host said about a widget's card, with the defaults for what it never said. */
998
- EngineCore.prototype.widgetRuntime = function (widgetId) {
999
- var _a;
1000
- return (_a = __classPrivateFieldGet(this, _EngineCore_state, "f").widgets[widgetId]) !== null && _a !== void 0 ? _a : DEFAULT_WIDGET_RUNTIME;
1001
- };
1066
+ widgetRuntime(widgetId) {
1067
+ return this.#state.widgets[widgetId] ?? DEFAULT_WIDGET_RUNTIME;
1068
+ }
1002
1069
  /** Records what the host says about a widget's card. True when something changed. */
1003
- EngineCore.prototype.setWidgetRuntime = function (widgetId, patch) {
1004
- var _a;
1005
- var current = this.widgetRuntime(widgetId);
1006
- var next = __assign(__assign({}, current), patch);
1070
+ setWidgetRuntime(widgetId, patch) {
1071
+ const current = this.widgetRuntime(widgetId);
1072
+ const next = { ...current, ...patch };
1007
1073
  if (next.hiddenImage === current.hiddenImage && next.orphaned === current.orphaned && next.bodyDragAllowed === current.bodyDragAllowed) {
1008
1074
  return false;
1009
1075
  }
1010
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { widgets: Object.freeze(__assign(__assign({}, __classPrivateFieldGet(this, _EngineCore_state, "f").widgets), (_a = {}, _a[widgetId] = Object.freeze(next), _a))) });
1076
+ this.#set({ widgets: Object.freeze({ ...this.#state.widgets, [widgetId]: Object.freeze(next) }) });
1011
1077
  return true;
1012
- };
1078
+ }
1013
1079
  /** The widget whose card is under the pointer, or null. */
1014
- EngineCore.prototype.setHoverWidget = function (widgetId) {
1015
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { hoverWidgetId: widgetId });
1016
- };
1080
+ setHoverWidget(widgetId) {
1081
+ this.#set({ hoverWidgetId: widgetId });
1082
+ }
1017
1083
  /** The host's own bar is dragging a card. */
1018
- EngineCore.prototype.setOverlayDragActive = function (active) {
1019
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { overlayDragActive: active });
1020
- };
1084
+ setOverlayDragActive(active) {
1085
+ this.#set({ overlayDragActive: active });
1086
+ }
1021
1087
  /** Gives a card (or any object, which becomes a card) the widget it stands for. The card becomes the selection. */
1022
- EngineCore.prototype.linkObjectToWidget = function (target, widgetId, name) {
1023
- var id = typeof target === 'string' ? target : target.id;
1024
- var object = this.getObject(id);
1088
+ linkObjectToWidget(target, widgetId, name) {
1089
+ const id = typeof target === 'string' ? target : target.id;
1090
+ const object = this.getObject(id);
1025
1091
  if (!object || object.type === 'group')
1026
1092
  return false;
1027
- var replacement;
1093
+ let replacement;
1028
1094
  if (object.type === 'widget') {
1029
- replacement = __assign(__assign({}, object), { widgetId: widgetId, widgetName: name !== null && name !== void 0 ? name : object.widgetName });
1095
+ replacement = { ...object, widgetId, widgetName: name ?? object.widgetName };
1030
1096
  }
1031
1097
  else {
1032
1098
  replacement = createWidgetObject({
1033
- id: id,
1099
+ id,
1034
1100
  parentId: object.parentId,
1035
- widgetId: widgetId,
1036
- widgetName: name !== null && name !== void 0 ? name : null,
1101
+ widgetId,
1102
+ widgetName: name ?? null,
1037
1103
  x: object.x,
1038
1104
  y: object.y,
1039
1105
  width: object.width,
@@ -1042,160 +1108,21 @@ var EngineCore = /** @class */ (function () {
1042
1108
  opacity: object.opacity
1043
1109
  });
1044
1110
  }
1045
- this.applyScene(replaceObject(__classPrivateFieldGet(this, _EngineCore_state, "f").scene, id, replacement), 'push');
1111
+ this.applyScene(replaceObject(this.#state.scene, id, replacement), 'push');
1046
1112
  this.setPending(id, null);
1047
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_setSelection).call(this, [id], null);
1113
+ this.#setSelection([id], null);
1048
1114
  return true;
1049
- };
1115
+ }
1050
1116
  /** Drops a card that was waiting for a widget and will never get one. */
1051
- EngineCore.prototype.discardPending = function (id) {
1052
- if (!__classPrivateFieldGet(this, _EngineCore_state, "f").pending[id])
1117
+ discardPending(id) {
1118
+ if (!this.#state.pending[id])
1053
1119
  return false;
1054
1120
  this.setPending(id, null);
1055
1121
  return this.removeObjects([id]);
1056
- };
1122
+ }
1057
1123
  /** Every widget card that is on the board for good (one still being copied does not count). */
1058
- EngineCore.prototype.widgetCards = function () {
1059
- var pending = __classPrivateFieldGet(this, _EngineCore_state, "f").pending;
1060
- return __classPrivateFieldGet(this, _EngineCore_state, "f").scene.filter(function (object) { return object.type === 'widget' && !pending[object.id]; });
1061
- };
1062
- return EngineCore;
1063
- }());
1064
- export { EngineCore };
1065
- _EngineCore_state = new WeakMap(), _EngineCore_rotationResetCancel = new WeakMap(), _EngineCore_listeners = new WeakMap(), _EngineCore_history = new WeakMap(), _EngineCore_clipboard = new WeakMap(), _EngineCore_pasteSteps = new WeakMap(), _EngineCore_nudgeMergeUntil = new WeakMap(), _EngineCore_textSession = new WeakMap(), _EngineCore_preferredTextFontFamily = new WeakMap(), _EngineCore_workspaceTextDefaults = new WeakMap(), _EngineCore_workspacePaintDefaults = new WeakMap(), _EngineCore_scribble = new WeakMap(), _EngineCore_indexes = new WeakMap(), _EngineCore_selectedShapesMemo = new WeakMap(), _EngineCore_instances = new WeakSet(), _EngineCore_set = function _EngineCore_set(patch) {
1066
- var _this = this;
1067
- var changed = false;
1068
- for (var _i = 0, _a = Object.keys(patch); _i < _a.length; _i++) {
1069
- var key = _a[_i];
1070
- if (!Object.is(patch[key], __classPrivateFieldGet(this, _EngineCore_state, "f")[key])) {
1071
- changed = true;
1072
- break;
1073
- }
1124
+ widgetCards() {
1125
+ const pending = this.#state.pending;
1126
+ return this.#state.scene.filter((object) => object.type === 'widget' && !pending[object.id]);
1074
1127
  }
1075
- if (!changed)
1076
- return;
1077
- var before = __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds;
1078
- __classPrivateFieldSet(this, _EngineCore_state, __assign(__assign({}, __classPrivateFieldGet(this, _EngineCore_state, "f")), patch), "f");
1079
- for (var _b = 0, _c = __spreadArray([], __classPrivateFieldGet(this, _EngineCore_listeners, "f"), true); _b < _c.length; _b++) {
1080
- var listener = _c[_b];
1081
- listener(__classPrivateFieldGet(this, _EngineCore_state, "f"));
1082
- }
1083
- if (__classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds !== before && !sameIds(__classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds, before)) {
1084
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_callHook).call(this, function () { var _a, _b; return (_b = (_a = _this.hooks).onSelectionChange) === null || _b === void 0 ? void 0 : _b.call(_a, __classPrivateFieldGet(_this, _EngineCore_state, "f").selectedIds); }, 'selection hook');
1085
- }
1086
- }, _EngineCore_callHook = function _EngineCore_callHook(run, name) {
1087
- var _a, _b;
1088
- try {
1089
- run();
1090
- }
1091
- catch (error) {
1092
- (_b = (_a = this.hooks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, "The ".concat(name, " threw"), error);
1093
- }
1094
- }, _EngineCore_sceneForSave = function _EngineCore_sceneForSave() {
1095
- var _a = __classPrivateFieldGet(this, _EngineCore_state, "f"), scene = _a.scene, pending = _a.pending, editingTextId = _a.editingTextId;
1096
- var unwanted = new Set();
1097
- for (var _i = 0, scene_1 = scene; _i < scene_1.length; _i++) {
1098
- var object = scene_1[_i];
1099
- if (pending[object.id])
1100
- unwanted.add(object.id);
1101
- if (object.id === editingTextId && object.type === 'text' && object.text.trim() === '')
1102
- unwanted.add(object.id);
1103
- }
1104
- if (unwanted.size === 0)
1105
- return scene;
1106
- return normalizeScene(scene.filter(function (object) { return !unwanted.has(object.id); }));
1107
- }, _EngineCore_afterHistoryMove = function _EngineCore_afterHistoryMove(scene) {
1108
- var _a, _b;
1109
- __classPrivateFieldSet(this, _EngineCore_nudgeMergeUntil, 0, "f");
1110
- this.applyScene(scene, 'transient');
1111
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { canUndo: __classPrivateFieldGet(this, _EngineCore_history, "f").canUndo, canRedo: __classPrivateFieldGet(this, _EngineCore_history, "f").canRedo, overlay: EMPTY_OVERLAY });
1112
- (_b = (_a = this.hooks).onDirty) === null || _b === void 0 ? void 0 : _b.call(_a);
1113
- }, _EngineCore_setSelection = function _EngineCore_setSelection(selection, enteredGroupId) {
1114
- if (enteredGroupId === void 0) { enteredGroupId = __classPrivateFieldGet(this, _EngineCore_state, "f").enteredGroupId; }
1115
- var entered = enteredGroupId;
1116
- if (entered) {
1117
- var index_2 = this.sceneIndex();
1118
- // Picking something outside the group that was entered leaves the group.
1119
- var stillInside = selection.length === 0 || selection.every(function (id) { var _a; return ((_a = index_2.get(id)) === null || _a === void 0 ? void 0 : _a.parentId) === entered; });
1120
- if (!stillInside)
1121
- entered = null;
1122
- }
1123
- var next = sameIds(selection, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds) ? __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds : Object.freeze(__spreadArray([], selection, true));
1124
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { selectedIds: next, enteredGroupId: entered });
1125
- }, _EngineCore_dropScribble = function _EngineCore_dropScribble() {
1126
- __classPrivateFieldSet(this, _EngineCore_scribble, null, "f");
1127
- return __classPrivateFieldGet(this, _EngineCore_state, "f").scribble === null ? {} : { scribble: null };
1128
- }, _EngineCore_viewCenter = function _EngineCore_viewCenter() {
1129
- var _a = __classPrivateFieldGet(this, _EngineCore_state, "f").viewSize, width = _a.width, height = _a.height;
1130
- return { x: width / 2, y: height / 2 };
1131
- }, _EngineCore_fittedViewport = function _EngineCore_fittedViewport(scene) {
1132
- var bounds = boardVisualBounds(scene);
1133
- if (!bounds)
1134
- return __assign({}, INITIAL_VIEWPORT);
1135
- return fitViewportToRect(bounds, __classPrivateFieldGet(this, _EngineCore_state, "f").viewSize, VIEW_FIT_PADDING);
1136
- }, _EngineCore_fitText = function _EngineCore_fitText(object) {
1137
- return object.type === 'text' ? fitTextObject(object, this.services.measureText) : object;
1138
- }, _EngineCore_fitTexts = function _EngineCore_fitTexts(scene) {
1139
- var _this = this;
1140
- var changed = false;
1141
- var next = scene.map(function (object) {
1142
- if (object.type !== 'text')
1143
- return object;
1144
- var fitted = fitTextObject(object, _this.services.measureText);
1145
- if (fitted !== object)
1146
- changed = true;
1147
- return fitted;
1148
- });
1149
- return changed ? next : scene;
1150
- }, _EngineCore_arrange = function _EngineCore_arrange(change) {
1151
- var scene = __classPrivateFieldGet(this, _EngineCore_state, "f").scene;
1152
- var next = change(scene, __classPrivateFieldGet(this, _EngineCore_state, "f").selectedIds);
1153
- if (next === scene)
1154
- return false;
1155
- this.applyScene(next, 'push');
1156
- return true;
1157
- }, _EngineCore_insertCopies = function _EngineCore_insertCopies(source, rootIds, offset, mode) {
1158
- var _this = this;
1159
- var _a;
1160
- if (mode === void 0) { mode = 'push'; }
1161
- var _b = duplicateObjects(source, rootIds, offset, function (type) {
1162
- return _this.services.createId(type === 'group' ? 'group' : 'obj');
1163
- }), objects = _b.objects, idMap = _b.idMap;
1164
- if (objects.length === 0)
1165
- return [];
1166
- var duplicatesWidgets = (_a = this.hooks.onWidgetDuplicated) !== null && _a !== void 0 ? _a : null;
1167
- var pending = __assign({}, __classPrivateFieldGet(this, _EngineCore_state, "f").pending);
1168
- var widgetClones = [];
1169
- var prepared = objects.map(function (object) {
1170
- if (object.type !== 'widget')
1171
- return object;
1172
- if (duplicatesWidgets) {
1173
- // The card waits, unselected, for the host to make the widget behind it.
1174
- pending[object.id] = 'duplicating';
1175
- widgetClones.push({ sourceWidgetId: object.widgetId, clone: object });
1176
- return object;
1177
- }
1178
- // With no host to copy the widget, a copy of a card is only a picture of it.
1179
- return __classPrivateFieldGet(_this, _EngineCore_instances, "m", _EngineCore_flattenWidgetCard).call(_this, object);
1180
- });
1181
- // A copy of a member goes into the group of the original; if that group is gone it is repaired to the top level.
1182
- this.applyScene(normalizeScene(__spreadArray(__spreadArray([], __classPrivateFieldGet(this, _EngineCore_state, "f").scene, true), prepared.map(function (object) { return __classPrivateFieldGet(_this, _EngineCore_instances, "m", _EngineCore_fitText).call(_this, object); }), true)), mode);
1183
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_set).call(this, { pending: Object.freeze(pending) });
1184
- var rootCopyIds = rootIds.map(function (id) { return idMap.get(id); }).filter(function (id) { return !!id; });
1185
- var selectable = rootCopyIds.filter(function (id) { return !pending[id]; });
1186
- __classPrivateFieldGet(this, _EngineCore_instances, "m", _EngineCore_setSelection).call(this, selectable);
1187
- var _loop_1 = function (sourceWidgetId, clone) {
1188
- __classPrivateFieldGet(this_1, _EngineCore_instances, "m", _EngineCore_callHook).call(this_1, function () { return duplicatesWidgets === null || duplicatesWidgets === void 0 ? void 0 : duplicatesWidgets(sourceWidgetId, clone); }, 'widget duplicated hook');
1189
- };
1190
- var this_1 = this;
1191
- for (var _i = 0, widgetClones_1 = widgetClones; _i < widgetClones_1.length; _i++) {
1192
- var _c = widgetClones_1[_i], sourceWidgetId = _c.sourceWidgetId, clone = _c.clone;
1193
- _loop_1(sourceWidgetId, clone);
1194
- }
1195
- return rootCopyIds;
1196
- }, _EngineCore_flattenWidgetCard = function _EngineCore_flattenWidgetCard(card) {
1197
- var box = { id: card.id, parentId: card.parentId, x: card.x, y: card.y, width: card.width, height: card.height, rotation: card.rotation, opacity: card.opacity };
1198
- if (card.thumbnail)
1199
- return createImageObject(__assign(__assign({}, box), { src: card.thumbnail, naturalWidth: card.width, naturalHeight: card.height }));
1200
- return createRectObject(box);
1201
- };
1128
+ }