@widgetic/canvas 0.5.45 → 0.5.47

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