@widgetic/canvas 0.5.43 → 0.5.45

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