@widgetic/canvas 0.5.39 → 0.5.41

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