@widgetic/canvas 0.5.44 → 0.5.45

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