@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
@@ -6,11 +6,33 @@
6
6
  * the release. Two fingers make a pinch, the wheel pans and zooms, and a double click enters a group or edits a
7
7
  * text. Nothing here touches the DOM, so every rule is tested with simulated pointers.
8
8
  */
9
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
10
+ if (kind === "m") throw new TypeError("Private method is not writable");
11
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
12
+ 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");
13
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
14
+ };
15
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
16
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
17
+ 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");
18
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
19
+ };
20
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
21
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
22
+ if (ar || !(i in from)) {
23
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
24
+ ar[i] = from[i];
25
+ }
26
+ }
27
+ return to.concat(ar || Array.prototype.slice.call(from));
28
+ };
29
+ var _PointerController_instances, _PointerController_engine, _PointerController_options, _PointerController_context, _PointerController_active, _PointerController_pinch, _PointerController_pointers, _PointerController_spaceHeld, _PointerController_guidesSuppressed, _PointerController_lastClick, _PointerController_lastHandlePress, _PointerController_lastHover, _PointerController_lastInput, _PointerController_cursorWhenIdle, _PointerController_begin, _PointerController_finish, _PointerController_pressWithTextTool, _PointerController_isDoubleClick, _PointerController_rememberHandlePress, _PointerController_isDoublePressOn, _PointerController_pressWithSelectTool, _PointerController_drillThrough, _PointerController_isHeldByLiveWidget, _PointerController_handleDoubleClick, _PointerController_hover, _PointerController_hoverArrowTarget, _PointerController_hoverWidgetCard, _PointerController_forgetStalePointers, _PointerController_pinchGeometry, _PointerController_startPinch, _PointerController_updatePinch, _PointerController_endPinch;
9
30
  import { pickArrowBinding } from '../core/arrowBinding.js';
31
+ import { QUICK_CAMERA_MOVE_SCALE } from '../core/cameraMove.js';
10
32
  import { hitTestLeaf } from '../core/hitTest.js';
11
33
  import { clampNumber, distanceBetween } from '../core/geometry.js';
12
34
  import { leafShapesOf } from '../core/scene.js';
13
- import { selectionFrameOf } from '../core/transform.js';
35
+ import { frameContains, selectionFrameOf } from '../core/transform.js';
14
36
  import { clampZoom } from '../core/viewport.js';
15
37
  import { cursorForTool } from '../EngineCore.js';
16
38
  import { createArrowHandleGesture, createDrawGesture, createEraseGesture, createMarqueeGesture, createMoveGesture, createPanGesture, createResizeGesture, createRotateGesture, createShapeGesture, createTextGesture } from './gestures.js';
@@ -18,127 +40,133 @@ import { arrowHandleMetricsFor, hitArrowHandle, singleArrowOf } from './arrowHan
18
40
  import { resolveHoverCursor } from './hoverCursor.js';
19
41
  import { availableHandles, cursorForHandle, handleMetricsFor, hitSelectionHandle } from './selectionHandles.js';
20
42
  /** Two presses this close in time and place are a double click. */
21
- export const DOUBLE_CLICK_MS = 400;
22
- export const DOUBLE_CLICK_DISTANCE = 6;
43
+ export var DOUBLE_CLICK_MS = 400;
44
+ export var DOUBLE_CLICK_DISTANCE = 6;
23
45
  /** A pointer that has said nothing for this long is not one of two fingers: its release was lost. */
24
- const STALE_POINTER_MS = 1500;
46
+ var STALE_POINTER_MS = 1500;
25
47
  /** One line of a wheel in a line-based device, in pixels. */
26
- const WHEEL_LINE_PIXELS = 16;
27
- const WHEEL_PAGE_PIXELS = 400;
28
- export class PointerController {
29
- #engine;
30
- #options;
31
- #context;
32
- #active = null;
33
- #pinch = null;
34
- #pointers = new Map();
35
- #spaceHeld = false;
36
- #lastClick = null;
37
- /** The last press on a handle (the turning dot counts as one): a second press on the same one, soon and close, is a double click on it. */
38
- #lastHandlePress = null;
39
- #lastHover = null;
40
- #lastInput = null;
41
- constructor(engine, options = {}) {
42
- this.#engine = engine;
43
- this.#options = options;
44
- this.#context = { engine, options };
45
- }
46
- /** The kind of gesture that is running, or null. */
47
- get gestureKind() {
48
- return this.#pinch ? 'pinch' : (this.#active?.kind ?? null);
49
- }
48
+ var WHEEL_LINE_PIXELS = 16;
49
+ var WHEEL_PAGE_PIXELS = 400;
50
+ var PointerController = /** @class */ (function () {
51
+ function PointerController(engine, options) {
52
+ if (options === void 0) { options = {}; }
53
+ var _this = this;
54
+ _PointerController_instances.add(this);
55
+ _PointerController_engine.set(this, void 0);
56
+ _PointerController_options.set(this, void 0);
57
+ _PointerController_context.set(this, void 0);
58
+ _PointerController_active.set(this, null);
59
+ _PointerController_pinch.set(this, null);
60
+ _PointerController_pointers.set(this, new Map());
61
+ _PointerController_spaceHeld.set(this, false);
62
+ /** G held: the alignment guides are off (a drag neither snaps to the other shapes nor shows a guide). */
63
+ _PointerController_guidesSuppressed.set(this, false);
64
+ _PointerController_lastClick.set(this, null);
65
+ /** The last press on a handle (the turning dot counts as one): a second press on the same one, soon and close, is a double click on it. */
66
+ _PointerController_lastHandlePress.set(this, null);
67
+ _PointerController_lastHover.set(this, null);
68
+ _PointerController_lastInput.set(this, null);
69
+ __classPrivateFieldSet(this, _PointerController_engine, engine, "f");
70
+ __classPrivateFieldSet(this, _PointerController_options, options, "f");
71
+ __classPrivateFieldSet(this, _PointerController_context, { engine: engine, options: options, guidesSuppressed: function () { return __classPrivateFieldGet(_this, _PointerController_guidesSuppressed, "f"); } }, "f");
72
+ }
73
+ Object.defineProperty(PointerController.prototype, "gestureKind", {
74
+ /** The kind of gesture that is running, or null. */
75
+ get: function () {
76
+ var _a, _b;
77
+ return __classPrivateFieldGet(this, _PointerController_pinch, "f") ? 'pinch' : ((_b = (_a = __classPrivateFieldGet(this, _PointerController_active, "f")) === null || _a === void 0 ? void 0 : _a.kind) !== null && _b !== void 0 ? _b : null);
78
+ },
79
+ enumerable: false,
80
+ configurable: true
81
+ });
50
82
  /** Space held: a press pans, whatever the tool. */
51
- setSpaceHeld(held) {
52
- this.#spaceHeld = held;
53
- if (!this.#active && !this.#pinch) {
54
- this.#engine.setCursor(held ? 'grab' : this.#cursorWhenIdle());
83
+ PointerController.prototype.setSpaceHeld = function (held) {
84
+ __classPrivateFieldSet(this, _PointerController_spaceHeld, held, "f");
85
+ if (!__classPrivateFieldGet(this, _PointerController_active, "f") && !__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
86
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setCursor(held ? 'grab' : __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_cursorWhenIdle).call(this));
55
87
  }
56
- }
57
- #cursorWhenIdle() {
58
- return cursorForTool(this.#engine.state.tool);
59
- }
60
- #begin(gesture) {
61
- this.#active = gesture;
62
- this.#engine.setHover(null);
63
- this.#options.onGestureChange?.(gesture.kind);
64
- }
65
- #finish(mode, input) {
66
- const gesture = this.#active;
67
- if (!gesture)
88
+ };
89
+ Object.defineProperty(PointerController.prototype, "guidesSuppressed", {
90
+ /** Whether G is held: the alignment guides are off while it is. */
91
+ get: function () {
92
+ return __classPrivateFieldGet(this, _PointerController_guidesSuppressed, "f");
93
+ },
94
+ enumerable: false,
95
+ configurable: true
96
+ });
97
+ /**
98
+ * G pressed or let go: the alignment guides are off while it is held, whatever is dragged (a held key can come before the press
99
+ * or in the middle of the drag). A drag that is running takes it up at once, without waiting for the pointer to move: the guides
100
+ * go (and the selection stops being caught by them) when the key goes down, and come back when it is let go.
101
+ */
102
+ PointerController.prototype.setGuidesSuppressed = function (suppressed) {
103
+ var _a, _b, _c, _d;
104
+ if (__classPrivateFieldGet(this, _PointerController_guidesSuppressed, "f") === suppressed)
68
105
  return;
69
- this.#active = null;
106
+ __classPrivateFieldSet(this, _PointerController_guidesSuppressed, suppressed, "f");
70
107
  try {
71
- if (mode === 'end' && input)
72
- gesture.end(input);
73
- else
74
- gesture.cancel();
108
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_active, "f")) === null || _a === void 0 ? void 0 : _a.guidesSuppressedChanged) === null || _b === void 0 ? void 0 : _b.call(_a);
75
109
  }
76
- finally {
77
- // After the gesture the frame (and dot) may have moved: look again at the pointer without waiting for the next move.
78
- this.#lastHover = null;
79
- this.#options.onGestureChange?.(null);
80
- const hoverInput = input ?? this.#lastInput;
81
- // No pointer seen yet (a gesture cancelled from the keyboard) or a finger: there is nothing to look at.
82
- if (hoverInput && hoverInput.pointerType !== 'touch') {
83
- this.#hover(hoverInput);
84
- }
85
- else {
86
- this.#engine.setRotationDotHover(false);
87
- this.#engine.setArrowHandleHover(null);
88
- }
110
+ catch (error) {
111
+ // A drag that cannot lay itself out again keeps going on the next move of the pointer; the host is told for its log.
112
+ (_d = (_c = __classPrivateFieldGet(this, _PointerController_engine, "f").hooks).onError) === null || _d === void 0 ? void 0 : _d.call(_c, 'The drag could not follow the key that turns the guides off', error);
89
113
  }
90
- }
114
+ };
91
115
  /** Abandons the gesture that is running (Escape). True when there was one. */
92
- cancelGesture() {
93
- if (this.#pinch) {
94
- this.#endPinch();
116
+ PointerController.prototype.cancelGesture = function () {
117
+ if (__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
118
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_endPinch).call(this);
95
119
  return true;
96
120
  }
97
- if (!this.#active)
121
+ if (!__classPrivateFieldGet(this, _PointerController_active, "f"))
98
122
  return false;
99
- this.#finish('cancel');
123
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'cancel');
100
124
  return true;
101
- }
125
+ };
102
126
  /** Shift, Alt, Ctrl or Meta changed while the pointer stayed still. */
103
- modifiersChanged(modifiers) {
104
- this.#active?.modifiersChanged?.(modifiers, this.#lastInput);
105
- }
106
- dispose() {
127
+ PointerController.prototype.modifiersChanged = function (modifiers) {
128
+ var _a, _b;
129
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_active, "f")) === null || _a === void 0 ? void 0 : _a.modifiersChanged) === null || _b === void 0 ? void 0 : _b.call(_a, modifiers, __classPrivateFieldGet(this, _PointerController_lastInput, "f"));
130
+ };
131
+ PointerController.prototype.dispose = function () {
107
132
  this.cancelGesture();
108
- this.#pointers.clear();
109
- }
133
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").clear();
134
+ };
110
135
  // ──────────────────────────────────────────────────────── press
111
136
  /** Handles a press. Returns whether the shell should capture the pointer and keep the browser from acting on it. */
112
- pointerDown(input) {
113
- this.#lastInput = input;
114
- this.#engine.cancelRotationReset();
115
- this.#forgetStalePointers(input.time);
116
- this.#pointers.set(input.pointerId, { x: input.x, y: input.y, seenAt: input.time });
117
- this.#engine.lastPointerWorld = this.#engine.toWorld({ x: input.x, y: input.y });
118
- if (input.pointerType === 'touch' && this.#pointers.size === 2) {
119
- this.#startPinch();
137
+ PointerController.prototype.pointerDown = function (input) {
138
+ __classPrivateFieldSet(this, _PointerController_lastInput, input, "f");
139
+ __classPrivateFieldGet(this, _PointerController_engine, "f").cancelRotationReset();
140
+ // A press on the board takes the view back from a move that is on its way (see `EngineCore.flyTo`).
141
+ __classPrivateFieldGet(this, _PointerController_engine, "f").cancelViewportMove();
142
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_forgetStalePointers).call(this, input.time);
143
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").set(input.pointerId, { x: input.x, y: input.y, seenAt: input.time });
144
+ __classPrivateFieldGet(this, _PointerController_engine, "f").lastPointerWorld = __classPrivateFieldGet(this, _PointerController_engine, "f").toWorld({ x: input.x, y: input.y });
145
+ if (input.pointerType === 'touch' && __classPrivateFieldGet(this, _PointerController_pointers, "f").size === 2) {
146
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_startPinch).call(this);
120
147
  return true;
121
148
  }
122
- if (this.#pointers.size > 1 || this.#pinch)
149
+ if (__classPrivateFieldGet(this, _PointerController_pointers, "f").size > 1 || __classPrivateFieldGet(this, _PointerController_pinch, "f"))
123
150
  return true;
124
- if (this.#active)
125
- this.#finish('cancel');
151
+ if (__classPrivateFieldGet(this, _PointerController_active, "f"))
152
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'cancel');
126
153
  // The secondary button belongs to the context menu.
127
154
  if (input.button === 2)
128
155
  return false;
129
- if (input.button === 1 || (input.button === 0 && this.#spaceHeld) || (input.button === 0 && this.#engine.state.tool === 'pan')) {
130
- this.#begin(createPanGesture(this.#context, input));
156
+ if (input.button === 1 || (input.button === 0 && __classPrivateFieldGet(this, _PointerController_spaceHeld, "f")) || (input.button === 0 && __classPrivateFieldGet(this, _PointerController_engine, "f").state.tool === 'pan')) {
157
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createPanGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
131
158
  return true;
132
159
  }
133
160
  if (input.button !== 0)
134
161
  return false;
135
- // A click on the board ends the typing in a text.
136
- if (this.#engine.state.editingTextId)
137
- this.#engine.endTextEdit();
138
- const state = this.#engine.state;
162
+ // A click on the board ends the typing in a text. The empty placeholder that the Text tool put on the board does not end the
163
+ // tool: the press goes on as a press of the Text tool, and puts the text where it landed (a click) or as wide as the drag.
164
+ if (__classPrivateFieldGet(this, _PointerController_engine, "f").state.editingTextId)
165
+ __classPrivateFieldGet(this, _PointerController_engine, "f").endTextEdit({ keepPlaceholderTool: true });
166
+ var state = __classPrivateFieldGet(this, _PointerController_engine, "f").state;
139
167
  switch (state.tool) {
140
168
  case 'draw':
141
- this.#begin(createDrawGesture(this.#context, input));
169
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createDrawGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
142
170
  return true;
143
171
  case 'rect':
144
172
  case 'rounded-rect':
@@ -147,421 +175,476 @@ export class PointerController {
147
175
  case 'triangle':
148
176
  case 'arrow':
149
177
  case 'library-shape':
150
- this.#begin(createShapeGesture(this.#context, input, state.tool, state.libraryShapeKey));
178
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createShapeGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, state.tool, state.libraryShapeKey));
151
179
  return true;
152
180
  case 'text':
153
- return this.#pressWithTextTool(input);
181
+ return __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_pressWithTextTool).call(this, input);
154
182
  case 'erase':
155
- this.#begin(createEraseGesture(this.#context, input));
183
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createEraseGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
156
184
  return true;
157
185
  default:
158
- return this.#pressWithSelectTool(input);
159
- }
160
- }
161
- #pressWithTextTool(input) {
162
- const engine = this.#engine;
163
- const world = engine.toWorld({ x: input.x, y: input.y });
164
- // A click on a text that is already there edits it instead of making another on top.
165
- const hit = hitTestLeaf(engine.state.scene, world, { zoom: engine.state.viewport.zoom });
166
- if (hit && hit.type === 'text') {
167
- if (hit.parentId)
168
- engine.enterGroup(hit.parentId, hit.id);
169
- engine.beginTextEdit(hit.id);
170
- return true;
171
- }
172
- this.#begin(createTextGesture(this.#context, input));
173
- return true;
174
- }
175
- #isDoubleClick(input) {
176
- const previous = this.#lastClick;
177
- return (!!previous &&
178
- input.time - previous.time <= DOUBLE_CLICK_MS &&
179
- distanceBetween({ x: previous.x, y: previous.y }, { x: input.x, y: input.y }) <= DOUBLE_CLICK_DISTANCE);
180
- }
181
- #rememberHandlePress(input, handle) {
182
- this.#lastHandlePress = { handle, time: input.time, x: input.x, y: input.y };
183
- }
184
- /** Whether this press, on the handle `handle`, follows the last press on that same handle soon and close enough to be its double. */
185
- #isDoublePressOn(input, handle) {
186
- const previous = this.#lastHandlePress;
187
- return (!!previous &&
188
- previous.handle === handle &&
189
- input.time - previous.time <= DOUBLE_CLICK_MS &&
190
- distanceBetween({ x: previous.x, y: previous.y }, { x: input.x, y: input.y }) <= DOUBLE_CLICK_DISTANCE);
191
- }
192
- #pressWithSelectTool(input) {
193
- const engine = this.#engine;
194
- const screenPoint = { x: input.x, y: input.y };
195
- const world = engine.toWorld(screenPoint);
196
- const pickMode = this.#options.pickMode?.() ?? false;
197
- // The handles of the selection come before whatever lies under them.
198
- if (!pickMode && engine.state.selectedIds.length > 0) {
199
- const shapes = engine.selectedShapes();
200
- // One selected arrow has two ends and a middle to take hold of, and no frame; anywhere else on it is the arrow itself.
201
- const arrow = singleArrowOf(shapes, engine.state.selectedIds);
202
- const arrowHandle = arrow ? hitArrowHandle(arrow, engine.state.viewport, screenPoint, arrowHandleMetricsFor(input.pointerType)) : null;
203
- if (arrow && arrowHandle) {
204
- this.#begin(createArrowHandleGesture(this.#context, input, arrow, arrowHandle));
205
- return true;
206
- }
207
- const frame = arrow ? null : selectionFrameOf(shapes);
208
- if (frame) {
209
- const viewport = engine.state.viewport;
210
- const available = availableHandles(shapes, frame, viewport, this.#options.plainCardChrome?.() ?? false);
211
- const hit = hitSelectionHandle(frame, viewport, screenPoint, handleMetricsFor(input.pointerType), available);
212
- if (hit?.type === 'resize') {
213
- // Two quick presses on the side of a text set its width to its letters, as it was when it was made.
214
- if ((hit.handle === 'e' || hit.handle === 'w') && this.#isDoublePressOn(input, hit.handle) && engine.fitSelectedTextToContent()) {
215
- this.#lastHandlePress = null;
216
- return true;
217
- }
218
- this.#rememberHandlePress(input, hit.handle);
219
- this.#begin(createResizeGesture(this.#context, input, hit.handle, frame, shapes));
220
- return true;
221
- }
222
- if (hit?.type === 'rotate') {
223
- // Two quick presses on the dot stand the selection upright again.
224
- if (hit.source === 'dot' && this.#isDoublePressOn(input, 'rotate') && engine.resetSelectionRotation()) {
225
- this.#lastHandlePress = null;
226
- return true;
227
- }
228
- if (hit.source === 'dot')
229
- this.#rememberHandlePress(input, 'rotate');
230
- this.#begin(createRotateGesture(this.#context, input, frame, shapes, hit.source));
231
- return true;
232
- }
233
- }
234
- }
235
- const doubleClick = this.#isDoubleClick(input);
236
- this.#lastClick = doubleClick ? null : { time: input.time, x: input.x, y: input.y };
237
- if (doubleClick && !pickMode && this.#handleDoubleClick(world))
238
- return true;
239
- const unitId = engine.hitTest(world);
240
- if (pickMode) {
241
- if (unitId) {
242
- engine.select([unitId]);
243
- this.#options.onPick?.(unitId);
244
- }
245
- return true;
186
+ return __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_pressWithSelectTool).call(this, input);
246
187
  }
247
- // Alt-drag on an object duplicates the selection; Alt-click with no drag steps through the stack.
248
- if (input.altKey && unitId) {
249
- if (input.shiftKey) {
250
- engine.toggleSelection(unitId);
251
- if (!engine.state.selectedIds.includes(unitId))
252
- return true;
253
- }
254
- const moving = engine.state.selectedIds.length > 0 ? [...engine.state.selectedIds] : [unitId];
255
- this.#begin(createMoveGesture(this.#context, input, moving, {
256
- onClick: () => this.#drillThrough(world),
257
- duplicateOnDrag: true,
258
- immovable: this.#isHeldByLiveWidget(moving)
259
- }));
260
- return true;
261
- }
262
- if (input.altKey && this.#drillThrough(world))
263
- return true;
264
- if (unitId) {
265
- const wasSelected = engine.state.selectedIds.includes(unitId);
266
- if (input.shiftKey) {
267
- engine.toggleSelection(unitId);
268
- // Taking an object out of the selection is the whole press.
269
- if (!engine.state.selectedIds.includes(unitId))
270
- return true;
271
- }
272
- else if (!wasSelected) {
273
- engine.select([unitId]);
274
- }
275
- const moving = [...engine.state.selectedIds];
276
- // A click on one of several selected objects, without a drag, narrows the selection to it.
277
- const onClick = !input.shiftKey && wasSelected && moving.length > 1 ? () => engine.select([unitId]) : undefined;
278
- this.#begin(createMoveGesture(this.#context, input, moving, { onClick, immovable: this.#isHeldByLiveWidget(moving) }));
279
- return true;
280
- }
281
- // Empty board. A finger pans (a tap clears the selection); a mouse drags a marquee.
282
- if (input.pointerType === 'touch') {
283
- this.#begin(createPanGesture(this.#context, input, { onTap: () => engine.clearSelection() }));
284
- return true;
285
- }
286
- if (!input.shiftKey)
287
- engine.clearSelection();
288
- this.#begin(createMarqueeGesture(this.#context, input));
289
- return true;
290
- }
188
+ };
291
189
  /**
292
- * Selects the object one step below the one that is selected, among the objects under the pointer (and the
293
- * top one when the bottom one was reached or nothing was selected). False when there is nothing to step through.
190
+ * A right click or a long press: picks the top object under the pointer, unless something that is selected is under it already.
191
+ * The selection stays when the pointer is on one of its objects even if another object lies above that one there: a layer that
192
+ * was reached through the stack (an Alt-click on what is covered, the only way to pick a text under a shape) is still the one the
193
+ * menu is for, and "Bring to front" is what puts it above the rest. Returns the object the menu is for (the selected one under
194
+ * the pointer, else the top one), or null where nothing is under it (the selection is then left as it is).
294
195
  */
295
- #drillThrough(world) {
296
- const engine = this.#engine;
297
- const stack = engine.hitTestStack(world);
298
- if (stack.length === 0)
299
- return false;
300
- const selected = engine.state.selectedIds;
301
- const current = selected.length === 1 ? selected[0] : null;
302
- const position = current ? stack.indexOf(current) : -1;
303
- const next = stack[position <= 0 ? stack.length - 1 : position - 1];
304
- if (next !== current)
305
- engine.select([next]);
306
- return true;
307
- }
308
- /** Whether everything the units hold is a widget card that a live widget covers: only the host's own bar moves those. */
309
- #isHeldByLiveWidget(unitIds) {
310
- const shapes = leafShapesOf(this.#engine.state.scene, unitIds);
311
- return shapes.length > 0 && shapes.every((shape) => shape.type === 'widget' && !this.#engine.widgetRuntime(shape.widgetId).bodyDragAllowed);
312
- }
313
- /** Enters a group, edits a text, or tells the host a card was activated. True when something was done. */
314
- #handleDoubleClick(world) {
315
- const engine = this.#engine;
316
- const state = engine.state;
317
- const leaf = hitTestLeaf(state.scene, world, { zoom: state.viewport.zoom });
318
- if (!leaf || state.pending[leaf.id])
319
- return false;
320
- if (leaf.type === 'text') {
321
- if (leaf.parentId)
322
- engine.enterGroup(leaf.parentId, leaf.id);
323
- engine.beginTextEdit(leaf.id);
324
- return true;
196
+ PointerController.prototype.prepareContextMenu = function (screenPoint) {
197
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
198
+ var selectedIds = engine.state.selectedIds;
199
+ // The units under the pointer, the lowest first.
200
+ var stack = engine.hitTestStack(engine.toWorld(screenPoint));
201
+ for (var position = stack.length - 1; position >= 0; position -= 1) {
202
+ if (selectedIds.includes(stack[position]))
203
+ return stack[position];
325
204
  }
326
- const unitId = engine.hitTest(world);
327
- const unit = unitId ? engine.getObject(unitId) : undefined;
328
- if (unit && unit.type === 'group') {
329
- // Go into the group and pick the member that was double-clicked.
330
- const index = engine.sceneIndex();
331
- let member = index.get(leaf.id);
332
- while (member && member.parentId !== unit.id)
333
- member = member.parentId ? index.get(member.parentId) : undefined;
334
- engine.enterGroup(unit.id, member?.id ?? leaf.id);
335
- return true;
336
- }
337
- if (leaf.type === 'widget') {
338
- this.#options.onActivate?.(leaf.id);
339
- return true;
340
- }
341
- return false;
342
- }
343
- /** A right click or a long press: picks the object under the pointer if it is not selected. Returns it. */
344
- prepareContextMenu(screenPoint) {
345
- const engine = this.#engine;
346
- const unitId = engine.hitTest(engine.toWorld(screenPoint));
347
- if (unitId && !engine.state.selectedIds.includes(unitId))
348
- engine.select([unitId]);
349
- return unitId;
350
- }
205
+ var topUnitId = stack.length > 0 ? stack[stack.length - 1] : null;
206
+ if (topUnitId)
207
+ engine.select([topUnitId]);
208
+ return topUnitId;
209
+ };
351
210
  // ──────────────────────────────────────────────────────── move
352
- pointerMove(input) {
353
- this.#lastInput = input;
354
- const tracked = this.#pointers.get(input.pointerId);
211
+ PointerController.prototype.pointerMove = function (input) {
212
+ __classPrivateFieldSet(this, _PointerController_lastInput, input, "f");
213
+ var tracked = __classPrivateFieldGet(this, _PointerController_pointers, "f").get(input.pointerId);
355
214
  if (tracked) {
356
215
  tracked.x = input.x;
357
216
  tracked.y = input.y;
358
217
  tracked.seenAt = input.time;
359
218
  }
360
- this.#engine.lastPointerWorld = this.#engine.toWorld({ x: input.x, y: input.y });
361
- if (this.#pinch) {
362
- this.#updatePinch();
219
+ __classPrivateFieldGet(this, _PointerController_engine, "f").lastPointerWorld = __classPrivateFieldGet(this, _PointerController_engine, "f").toWorld({ x: input.x, y: input.y });
220
+ if (__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
221
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_updatePinch).call(this);
363
222
  return;
364
223
  }
365
- if (this.#active) {
366
- if (input.pointerId === this.#active.pointerId)
367
- this.#active.move(input);
224
+ if (__classPrivateFieldGet(this, _PointerController_active, "f")) {
225
+ if (input.pointerId === __classPrivateFieldGet(this, _PointerController_active, "f").pointerId)
226
+ __classPrivateFieldGet(this, _PointerController_active, "f").move(input);
368
227
  return;
369
228
  }
370
229
  if (input.pointerType === 'touch')
371
230
  return;
372
- this.#hover(input);
373
- }
374
- /** What is under the pointer when nothing is being dragged: the cursor, and the object to outline. */
375
- #hover(input) {
376
- const engine = this.#engine;
377
- const state = engine.state;
378
- if (this.#spaceHeld || (state.tool !== 'select' && state.tool !== 'arrow'))
231
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_hover).call(this, input);
232
+ };
233
+ /** The pointer left the board: nothing is hovered any more. */
234
+ PointerController.prototype.pointerLeave = function () {
235
+ __classPrivateFieldSet(this, _PointerController_lastHover, null, "f");
236
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setHoverWidget(null);
237
+ if (!__classPrivateFieldGet(this, _PointerController_active, "f")) {
238
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setHover(null);
239
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setRotationDotHover(false);
240
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setArrowHandleHover(null);
241
+ if (__classPrivateFieldGet(this, _PointerController_engine, "f").state.overlay.arrowBind)
242
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setOverlay({ arrowBind: null });
243
+ }
244
+ };
245
+ // ──────────────────────────────────────────────────────── release
246
+ PointerController.prototype.pointerUp = function (input) {
247
+ __classPrivateFieldSet(this, _PointerController_lastInput, input, "f");
248
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").delete(input.pointerId);
249
+ // A press that was dragged away from where it began was not a click, so the next press at that place is not its second half.
250
+ if (__classPrivateFieldGet(this, _PointerController_lastClick, "f") && distanceBetween({ x: __classPrivateFieldGet(this, _PointerController_lastClick, "f").x, y: __classPrivateFieldGet(this, _PointerController_lastClick, "f").y }, { x: input.x, y: input.y }) > DOUBLE_CLICK_DISTANCE) {
251
+ __classPrivateFieldSet(this, _PointerController_lastClick, null, "f");
252
+ }
253
+ if (__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
254
+ if (__classPrivateFieldGet(this, _PointerController_pointers, "f").size < 2)
255
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_endPinch).call(this);
379
256
  return;
380
- if (this.#lastHover && Math.abs(this.#lastHover.x - input.x) < 1 && Math.abs(this.#lastHover.y - input.y) < 1)
257
+ }
258
+ if (__classPrivateFieldGet(this, _PointerController_active, "f") && __classPrivateFieldGet(this, _PointerController_active, "f").pointerId === input.pointerId)
259
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'end', input);
260
+ };
261
+ PointerController.prototype.pointerCancel = function (input) {
262
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").delete(input.pointerId);
263
+ if (__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
264
+ if (__classPrivateFieldGet(this, _PointerController_pointers, "f").size < 2)
265
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_endPinch).call(this);
381
266
  return;
382
- this.#lastHover = { x: input.x, y: input.y };
383
- if (state.tool === 'arrow') {
384
- this.#hoverArrowTarget(input);
267
+ }
268
+ if (__classPrivateFieldGet(this, _PointerController_active, "f") && __classPrivateFieldGet(this, _PointerController_active, "f").pointerId === input.pointerId)
269
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'cancel');
270
+ };
271
+ // ──────────────────────────────────────────────────────── wheel
272
+ /** The wheel (or two fingers on a trackpad) pans; with Ctrl or Meta, which a trackpad pinch also reports, it zooms about the pointer. */
273
+ PointerController.prototype.wheel = function (input) {
274
+ var unit = input.deltaMode === 1 ? WHEEL_LINE_PIXELS : input.deltaMode === 2 ? WHEEL_PAGE_PIXELS : 1;
275
+ var deltaX = input.deltaX * unit;
276
+ var deltaY = input.deltaY * unit;
277
+ if (input.ctrlKey || input.metaKey) {
278
+ var factor = Math.exp(-clampNumber(deltaY, -60, 60) * 0.01);
279
+ __classPrivateFieldGet(this, _PointerController_engine, "f").zoomAt({ x: input.x, y: input.y }, __classPrivateFieldGet(this, _PointerController_engine, "f").state.viewport.zoom * factor);
385
280
  return;
386
281
  }
387
- const screenPoint = { x: input.x, y: input.y };
388
- let overHandle = false;
389
- let overDot = false;
390
- let resizeHandleCursor = null;
391
- let arrowHandle = null;
392
- if (state.selectedIds.length > 0) {
393
- const shapes = engine.selectedShapes();
394
- const arrow = singleArrowOf(shapes, state.selectedIds);
395
- if (arrow) {
396
- arrowHandle = hitArrowHandle(arrow, state.viewport, screenPoint, arrowHandleMetricsFor(input.pointerType));
397
- if (arrowHandle) {
398
- overHandle = true;
282
+ // A mouse wheel with Shift held scrolls sideways.
283
+ if (input.shiftKey && deltaX === 0) {
284
+ deltaX = deltaY;
285
+ deltaY = 0;
286
+ }
287
+ __classPrivateFieldGet(this, _PointerController_engine, "f").panBy(-deltaX, -deltaY);
288
+ };
289
+ return PointerController;
290
+ }());
291
+ export { PointerController };
292
+ _PointerController_engine = new WeakMap(), _PointerController_options = new WeakMap(), _PointerController_context = new WeakMap(), _PointerController_active = new WeakMap(), _PointerController_pinch = new WeakMap(), _PointerController_pointers = new WeakMap(), _PointerController_spaceHeld = new WeakMap(), _PointerController_guidesSuppressed = new WeakMap(), _PointerController_lastClick = new WeakMap(), _PointerController_lastHandlePress = new WeakMap(), _PointerController_lastHover = new WeakMap(), _PointerController_lastInput = new WeakMap(), _PointerController_instances = new WeakSet(), _PointerController_cursorWhenIdle = function _PointerController_cursorWhenIdle() {
293
+ return cursorForTool(__classPrivateFieldGet(this, _PointerController_engine, "f").state.tool);
294
+ }, _PointerController_begin = function _PointerController_begin(gesture) {
295
+ var _a, _b;
296
+ __classPrivateFieldSet(this, _PointerController_active, gesture, "f");
297
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setHover(null);
298
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).onGestureChange) === null || _b === void 0 ? void 0 : _b.call(_a, gesture.kind);
299
+ }, _PointerController_finish = function _PointerController_finish(mode, input) {
300
+ var _a, _b;
301
+ var gesture = __classPrivateFieldGet(this, _PointerController_active, "f");
302
+ if (!gesture)
303
+ return;
304
+ __classPrivateFieldSet(this, _PointerController_active, null, "f");
305
+ try {
306
+ if (mode === 'end' && input)
307
+ gesture.end(input);
308
+ else
309
+ gesture.cancel();
310
+ }
311
+ finally {
312
+ // After the gesture the frame (and dot) may have moved: look again at the pointer without waiting for the next move.
313
+ __classPrivateFieldSet(this, _PointerController_lastHover, null, "f");
314
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).onGestureChange) === null || _b === void 0 ? void 0 : _b.call(_a, null);
315
+ var hoverInput = input !== null && input !== void 0 ? input : __classPrivateFieldGet(this, _PointerController_lastInput, "f");
316
+ // No pointer seen yet (a gesture cancelled from the keyboard) or a finger: there is nothing to look at.
317
+ if (hoverInput && hoverInput.pointerType !== 'touch') {
318
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_hover).call(this, hoverInput);
319
+ }
320
+ else {
321
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setRotationDotHover(false);
322
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setArrowHandleHover(null);
323
+ }
324
+ }
325
+ }, _PointerController_pressWithTextTool = function _PointerController_pressWithTextTool(input) {
326
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
327
+ var world = engine.toWorld({ x: input.x, y: input.y });
328
+ // A click on a text that is already there edits it instead of making another on top.
329
+ var hit = hitTestLeaf(engine.state.scene, world, { zoom: engine.state.viewport.zoom });
330
+ if (hit && hit.type === 'text') {
331
+ if (hit.parentId)
332
+ engine.enterGroup(hit.parentId, hit.id);
333
+ engine.beginTextEdit(hit.id);
334
+ return true;
335
+ }
336
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createTextGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
337
+ return true;
338
+ }, _PointerController_isDoubleClick = function _PointerController_isDoubleClick(input) {
339
+ var previous = __classPrivateFieldGet(this, _PointerController_lastClick, "f");
340
+ return (!!previous &&
341
+ input.time - previous.time <= DOUBLE_CLICK_MS &&
342
+ distanceBetween({ x: previous.x, y: previous.y }, { x: input.x, y: input.y }) <= DOUBLE_CLICK_DISTANCE);
343
+ }, _PointerController_rememberHandlePress = function _PointerController_rememberHandlePress(input, handle) {
344
+ __classPrivateFieldSet(this, _PointerController_lastHandlePress, { handle: handle, time: input.time, x: input.x, y: input.y }, "f");
345
+ }, _PointerController_isDoublePressOn = function _PointerController_isDoublePressOn(input, handle) {
346
+ var previous = __classPrivateFieldGet(this, _PointerController_lastHandlePress, "f");
347
+ return (!!previous &&
348
+ previous.handle === handle &&
349
+ input.time - previous.time <= DOUBLE_CLICK_MS &&
350
+ distanceBetween({ x: previous.x, y: previous.y }, { x: input.x, y: input.y }) <= DOUBLE_CLICK_DISTANCE);
351
+ }, _PointerController_pressWithSelectTool = function _PointerController_pressWithSelectTool(input) {
352
+ var _this = this;
353
+ var _a, _b, _c, _d, _e, _f, _g, _h;
354
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
355
+ var screenPoint = { x: input.x, y: input.y };
356
+ var world = engine.toWorld(screenPoint);
357
+ var pickMode = (_c = (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).pickMode) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false;
358
+ // The frame the selection shows, when it shows one: a press inside it, where nothing is drawn, carries the selection (below).
359
+ var selectionFrame = null;
360
+ // The handles of the selection come before whatever lies under them.
361
+ if (!pickMode && engine.state.selectedIds.length > 0) {
362
+ var shapes = engine.selectedShapes();
363
+ // One selected arrow has two ends and a middle to take hold of, and no frame; anywhere else on it is the arrow itself.
364
+ var arrow = singleArrowOf(shapes, engine.state.selectedIds);
365
+ var arrowHandle = arrow ? hitArrowHandle(arrow, engine.state.viewport, screenPoint, arrowHandleMetricsFor(input.pointerType)) : null;
366
+ if (arrow && arrowHandle) {
367
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createArrowHandleGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, arrow, arrowHandle));
368
+ return true;
369
+ }
370
+ var frame = arrow ? null : selectionFrameOf(shapes);
371
+ selectionFrame = frame;
372
+ if (frame) {
373
+ var viewport = engine.state.viewport;
374
+ var available = availableHandles(shapes, frame, viewport, (_f = (_e = (_d = __classPrivateFieldGet(this, _PointerController_options, "f")).plainCardChrome) === null || _e === void 0 ? void 0 : _e.call(_d)) !== null && _f !== void 0 ? _f : false);
375
+ var hit = hitSelectionHandle(frame, viewport, screenPoint, handleMetricsFor(input.pointerType), available);
376
+ if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'resize') {
377
+ // Two quick presses on the side of a text set its width to its letters, as it was when it was made.
378
+ if ((hit.handle === 'e' || hit.handle === 'w') && __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isDoublePressOn).call(this, input, hit.handle) && engine.fitSelectedTextToContent()) {
379
+ __classPrivateFieldSet(this, _PointerController_lastHandlePress, null, "f");
380
+ return true;
399
381
  }
382
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_rememberHandlePress).call(this, input, hit.handle);
383
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createResizeGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, hit.handle, frame, shapes));
384
+ return true;
400
385
  }
401
- const frame = arrow ? null : selectionFrameOf(shapes);
402
- if (frame) {
403
- const available = availableHandles(shapes, frame, state.viewport, this.#options.plainCardChrome?.() ?? false);
404
- const hit = hitSelectionHandle(frame, state.viewport, screenPoint, handleMetricsFor(input.pointerType), available);
405
- if (hit?.type === 'resize') {
406
- resizeHandleCursor = cursorForHandle(hit.handle, frame.rotation);
407
- overHandle = true;
408
- }
409
- else if (hit?.type === 'rotate') {
410
- overDot = hit.source === 'dot';
411
- overHandle = true;
386
+ if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'rotate') {
387
+ // Two quick presses on the dot stand the selection upright again.
388
+ if (hit.source === 'dot' && __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isDoublePressOn).call(this, input, 'rotate') && engine.resetSelectionRotation()) {
389
+ __classPrivateFieldSet(this, _PointerController_lastHandlePress, null, "f");
390
+ return true;
412
391
  }
392
+ if (hit.source === 'dot')
393
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_rememberHandlePress).call(this, input, 'rotate');
394
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createRotateGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, frame, shapes, hit.source));
395
+ return true;
413
396
  }
414
397
  }
415
- const world = engine.toWorld(screenPoint);
416
- const hovered = overHandle ? null : engine.hitTest(world);
417
- const hoveredSelected = !overHandle && !!hovered && state.selectedIds.includes(hovered);
418
- const hoveredUnselected = !overHandle && !!hovered && !state.selectedIds.includes(hovered) ? hovered : null;
419
- const cursor = resolveHoverCursor({
420
- spaceHeld: this.#spaceHeld,
421
- tool: state.tool,
422
- hoveredUnselectedId: hoveredUnselected,
423
- hoveredSelected,
424
- resizeHandleCursor,
425
- overRotationDot: overDot,
426
- overArrowHandle: !!arrowHandle,
427
- hoverBlockedByLiveWidget: hoveredUnselected ? this.#isHeldByLiveWidget([hoveredUnselected]) : false,
428
- selectionBlockedByLiveWidget: hoveredSelected ? this.#isHeldByLiveWidget(state.selectedIds) : false
429
- });
430
- engine.setHover(hovered && !state.selectedIds.includes(hovered) ? hovered : null);
431
- engine.setRotationDotHover(overDot);
432
- engine.setArrowHandleHover(arrowHandle);
433
- engine.setCursor(cursor);
434
- this.#hoverWidgetCard(overHandle ? null : hitTestLeaf(state.scene, world, { zoom: state.viewport.zoom }));
435
398
  }
436
- /**
437
- * The Arrow tool, nothing pressed: over a shape, the board outlines it and puts a dot where the tail of an arrow pressed here would
438
- * rest (Alt held: the arrow would be tied to nothing, so nothing is shown).
439
- */
440
- #hoverArrowTarget(input) {
441
- const engine = this.#engine;
442
- const world = engine.toWorld({ x: input.x, y: input.y });
443
- const hint = input.altKey ? null : (pickArrowBinding(engine.state.scene, world, { zoom: engine.state.viewport.zoom })?.hint ?? null);
444
- const shown = engine.state.overlay.arrowBind;
445
- const same = hint === null
446
- ? shown === null
447
- : shown !== null && shown.targetId === hint.targetId && shown.kind === hint.kind && shown.point.x === hint.point.x && shown.point.y === hint.point.y;
448
- if (!same)
449
- engine.setOverlay({ arrowBind: hint });
450
- }
451
- /**
452
- * The host draws the bar of a live widget over its card while the pointer is on it, and the card is picked
453
- * just by pointing at it (the bar and the widget inside take the pointer from there).
454
- */
455
- #hoverWidgetCard(leaf) {
456
- const engine = this.#engine;
457
- const state = engine.state;
458
- const card = leaf && leaf.type === 'widget' && leaf.parentId === null && !state.pending[leaf.id] && !engine.widgetRuntime(leaf.widgetId).orphaned ? leaf : null;
459
- engine.setHoverWidget(card ? card.widgetId : null);
460
- if (!card || state.overlayDragActive || state.editingTextId)
461
- return;
462
- if (!state.selectedIds.includes(card.id))
463
- engine.select([card.id]);
464
- }
465
- /** The pointer left the board: nothing is hovered any more. */
466
- pointerLeave() {
467
- this.#lastHover = null;
468
- this.#engine.setHoverWidget(null);
469
- if (!this.#active) {
470
- this.#engine.setHover(null);
471
- this.#engine.setRotationDotHover(false);
472
- this.#engine.setArrowHandleHover(null);
473
- if (this.#engine.state.overlay.arrowBind)
474
- this.#engine.setOverlay({ arrowBind: null });
399
+ var doubleClick = __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isDoubleClick).call(this, input);
400
+ __classPrivateFieldSet(this, _PointerController_lastClick, doubleClick ? null : { time: input.time, x: input.x, y: input.y }, "f");
401
+ if (doubleClick && !pickMode && __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_handleDoubleClick).call(this, world))
402
+ return true;
403
+ var unitId = engine.hitTest(world);
404
+ if (pickMode) {
405
+ if (unitId) {
406
+ engine.select([unitId]);
407
+ (_h = (_g = __classPrivateFieldGet(this, _PointerController_options, "f")).onPick) === null || _h === void 0 ? void 0 : _h.call(_g, unitId);
475
408
  }
409
+ return true;
476
410
  }
477
- // ──────────────────────────────────────────────────────── release
478
- pointerUp(input) {
479
- this.#lastInput = input;
480
- this.#pointers.delete(input.pointerId);
481
- if (this.#pinch) {
482
- if (this.#pointers.size < 2)
483
- this.#endPinch();
484
- return;
411
+ // Alt-drag on an object duplicates the selection; Alt-click with no drag steps through the stack.
412
+ if (input.altKey && unitId) {
413
+ if (input.shiftKey) {
414
+ engine.toggleSelection(unitId);
415
+ if (!engine.state.selectedIds.includes(unitId))
416
+ return true;
485
417
  }
486
- if (this.#active && this.#active.pointerId === input.pointerId)
487
- this.#finish('end', input);
418
+ var moving = engine.state.selectedIds.length > 0 ? __spreadArray([], engine.state.selectedIds, true) : [unitId];
419
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createMoveGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, moving, {
420
+ onClick: function () { return __classPrivateFieldGet(_this, _PointerController_instances, "m", _PointerController_drillThrough).call(_this, world); },
421
+ duplicateOnDrag: true,
422
+ immovable: __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isHeldByLiveWidget).call(this, moving)
423
+ }));
424
+ return true;
488
425
  }
489
- pointerCancel(input) {
490
- this.#pointers.delete(input.pointerId);
491
- if (this.#pinch) {
492
- if (this.#pointers.size < 2)
493
- this.#endPinch();
494
- return;
426
+ if (input.altKey && __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_drillThrough).call(this, world))
427
+ return true;
428
+ if (unitId) {
429
+ var wasSelected = engine.state.selectedIds.includes(unitId);
430
+ if (input.shiftKey) {
431
+ engine.toggleSelection(unitId);
432
+ // Taking an object out of the selection is the whole press.
433
+ if (!engine.state.selectedIds.includes(unitId))
434
+ return true;
495
435
  }
496
- if (this.#active && this.#active.pointerId === input.pointerId)
497
- this.#finish('cancel');
498
- }
499
- #forgetStalePointers(now) {
500
- for (const [id, pointer] of this.#pointers) {
501
- if (now - pointer.seenAt > STALE_POINTER_MS)
502
- this.#pointers.delete(id);
436
+ else if (!wasSelected) {
437
+ engine.select([unitId]);
503
438
  }
439
+ var moving = __spreadArray([], engine.state.selectedIds, true);
440
+ // A click on one of several selected objects, without a drag, narrows the selection to it.
441
+ var onClick = !input.shiftKey && wasSelected && moving.length > 1 ? function () { return engine.select([unitId]); } : undefined;
442
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createMoveGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, moving, { onClick: onClick, immovable: __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isHeldByLiveWidget).call(this, moving) }));
443
+ return true;
504
444
  }
505
- // ──────────────────────────────────────────────────────── pinch
506
- #pinchGeometry() {
507
- const [first, second] = [...this.#pointers.values()];
508
- if (!first || !second)
509
- return null;
510
- return {
511
- center: { x: (first.x + second.x) / 2, y: (first.y + second.y) / 2 },
512
- distance: Math.max(1, Math.hypot(first.x - second.x, first.y - second.y))
513
- };
445
+ // Nothing that is drawn is under the pointer, but it is inside the frame of the selection: the whole box is what was picked, and
446
+ // not only the line a stroke or a hollow shape is drawn with (a press a little off that line is still a press on the object). The
447
+ // press carries the selection; with no drag it leaves it as it is (the way out is a click outside the frame). Shift on the empty
448
+ // board is a marquee that adds to the selection, so it keeps meaning that; Alt duplicates on the drag, as on an object.
449
+ if (selectionFrame && !input.shiftKey && frameContains(selectionFrame, world)) {
450
+ var moving = __spreadArray([], engine.state.selectedIds, true);
451
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createMoveGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, moving, { duplicateOnDrag: input.altKey, immovable: __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isHeldByLiveWidget).call(this, moving) }));
452
+ return true;
514
453
  }
515
- #startPinch() {
516
- // Whatever one finger was doing is abandoned.
517
- if (this.#active)
518
- this.#finish('cancel');
519
- const geometry = this.#pinchGeometry();
520
- if (!geometry)
521
- return;
522
- const viewport = this.#engine.state.viewport;
523
- this.#pinch = {
524
- startDistance: geometry.distance,
525
- startZoom: viewport.zoom,
526
- anchorWorld: this.#engine.toWorld(geometry.center)
527
- };
528
- this.#options.onGestureChange?.('pinch');
454
+ // Empty board, and this is the second press of a double click (or a double tap): the view eases back to 100%, with the middle of
455
+ // everything that is drawn in the middle of the board. The first press already cleared the selection (a press inside the frame of
456
+ // the selection is not on the empty board: it is handled above). The ease is a quick one: it answers the person's own double
457
+ // click, so it does not take the time a move that a page asks for takes.
458
+ if (doubleClick) {
459
+ engine.flyToContent({ durationScale: QUICK_CAMERA_MOVE_SCALE });
460
+ return true;
529
461
  }
530
- #updatePinch() {
531
- const pinch = this.#pinch;
532
- const geometry = this.#pinchGeometry();
533
- if (!pinch || !geometry)
534
- return;
535
- const zoom = clampZoom(pinch.startZoom * (geometry.distance / pinch.startDistance));
536
- // The world point that was between the fingers stays between them, so the view pans with the hand.
537
- this.#engine.setViewport({
538
- x: geometry.center.x - pinch.anchorWorld.x * zoom,
539
- y: geometry.center.y - pinch.anchorWorld.y * zoom,
540
- zoom
541
- });
462
+ // Empty board. A finger pans (a tap clears the selection); a mouse drags a marquee.
463
+ if (input.pointerType === 'touch') {
464
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createPanGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, { onTap: function () { return engine.clearSelection(); } }));
465
+ return true;
542
466
  }
543
- #endPinch() {
544
- if (!this.#pinch)
545
- return;
546
- this.#pinch = null;
547
- this.#options.onGestureChange?.(null);
467
+ if (!input.shiftKey)
468
+ engine.clearSelection();
469
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createMarqueeGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
470
+ return true;
471
+ }, _PointerController_drillThrough = function _PointerController_drillThrough(world) {
472
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
473
+ var stack = engine.hitTestStack(world);
474
+ if (stack.length === 0)
475
+ return false;
476
+ var selected = engine.state.selectedIds;
477
+ var current = selected.length === 1 ? selected[0] : null;
478
+ var position = current ? stack.indexOf(current) : -1;
479
+ var next = stack[position <= 0 ? stack.length - 1 : position - 1];
480
+ if (next !== current)
481
+ engine.select([next]);
482
+ return true;
483
+ }, _PointerController_isHeldByLiveWidget = function _PointerController_isHeldByLiveWidget(unitIds) {
484
+ var _this = this;
485
+ var shapes = leafShapesOf(__classPrivateFieldGet(this, _PointerController_engine, "f").state.scene, unitIds);
486
+ return shapes.length > 0 && shapes.every(function (shape) { return shape.type === 'widget' && !__classPrivateFieldGet(_this, _PointerController_engine, "f").widgetRuntime(shape.widgetId).bodyDragAllowed; });
487
+ }, _PointerController_handleDoubleClick = function _PointerController_handleDoubleClick(world) {
488
+ var _a, _b, _c;
489
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
490
+ var state = engine.state;
491
+ var leaf = hitTestLeaf(state.scene, world, { zoom: state.viewport.zoom });
492
+ if (!leaf || state.pending[leaf.id])
493
+ return false;
494
+ if (leaf.type === 'text') {
495
+ if (leaf.parentId)
496
+ engine.enterGroup(leaf.parentId, leaf.id);
497
+ engine.beginTextEdit(leaf.id);
498
+ return true;
548
499
  }
549
- // ──────────────────────────────────────────────────────── wheel
550
- /** The wheel (or two fingers on a trackpad) pans; with Ctrl or Meta, which a trackpad pinch also reports, it zooms about the pointer. */
551
- wheel(input) {
552
- const unit = input.deltaMode === 1 ? WHEEL_LINE_PIXELS : input.deltaMode === 2 ? WHEEL_PAGE_PIXELS : 1;
553
- let deltaX = input.deltaX * unit;
554
- let deltaY = input.deltaY * unit;
555
- if (input.ctrlKey || input.metaKey) {
556
- const factor = Math.exp(-clampNumber(deltaY, -60, 60) * 0.01);
557
- this.#engine.zoomAt({ x: input.x, y: input.y }, this.#engine.state.viewport.zoom * factor);
558
- return;
500
+ var unitId = engine.hitTest(world);
501
+ var unit = unitId ? engine.getObject(unitId) : undefined;
502
+ if (unit && unit.type === 'group') {
503
+ // Go into the group and pick the member that was double-clicked.
504
+ var index = engine.sceneIndex();
505
+ var member = index.get(leaf.id);
506
+ while (member && member.parentId !== unit.id)
507
+ member = member.parentId ? index.get(member.parentId) : undefined;
508
+ engine.enterGroup(unit.id, (_a = member === null || member === void 0 ? void 0 : member.id) !== null && _a !== void 0 ? _a : leaf.id);
509
+ return true;
510
+ }
511
+ if (leaf.type === 'widget') {
512
+ (_c = (_b = __classPrivateFieldGet(this, _PointerController_options, "f")).onActivate) === null || _c === void 0 ? void 0 : _c.call(_b, leaf.id);
513
+ return true;
514
+ }
515
+ return false;
516
+ }, _PointerController_hover = function _PointerController_hover(input) {
517
+ var _a, _b, _c;
518
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
519
+ var state = engine.state;
520
+ if (__classPrivateFieldGet(this, _PointerController_spaceHeld, "f") || (state.tool !== 'select' && state.tool !== 'arrow'))
521
+ return;
522
+ if (__classPrivateFieldGet(this, _PointerController_lastHover, "f") && Math.abs(__classPrivateFieldGet(this, _PointerController_lastHover, "f").x - input.x) < 1 && Math.abs(__classPrivateFieldGet(this, _PointerController_lastHover, "f").y - input.y) < 1)
523
+ return;
524
+ __classPrivateFieldSet(this, _PointerController_lastHover, { x: input.x, y: input.y }, "f");
525
+ if (state.tool === 'arrow') {
526
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_hoverArrowTarget).call(this, input);
527
+ return;
528
+ }
529
+ var screenPoint = { x: input.x, y: input.y };
530
+ var overHandle = false;
531
+ var overDot = false;
532
+ var resizeHandleCursor = null;
533
+ var arrowHandle = null;
534
+ // The frame the selection shows, when it shows one: a press inside it, where nothing is drawn, carries the selection.
535
+ var selectionFrame = null;
536
+ if (state.selectedIds.length > 0) {
537
+ var shapes = engine.selectedShapes();
538
+ var arrow = singleArrowOf(shapes, state.selectedIds);
539
+ if (arrow) {
540
+ arrowHandle = hitArrowHandle(arrow, state.viewport, screenPoint, arrowHandleMetricsFor(input.pointerType));
541
+ if (arrowHandle) {
542
+ overHandle = true;
543
+ }
559
544
  }
560
- // A mouse wheel with Shift held scrolls sideways.
561
- if (input.shiftKey && deltaX === 0) {
562
- deltaX = deltaY;
563
- deltaY = 0;
545
+ var frame = arrow ? null : selectionFrameOf(shapes);
546
+ selectionFrame = frame;
547
+ if (frame) {
548
+ var available = availableHandles(shapes, frame, state.viewport, (_c = (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).plainCardChrome) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false);
549
+ var hit = hitSelectionHandle(frame, state.viewport, screenPoint, handleMetricsFor(input.pointerType), available);
550
+ if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'resize') {
551
+ resizeHandleCursor = cursorForHandle(hit.handle, frame.rotation);
552
+ overHandle = true;
553
+ }
554
+ else if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'rotate') {
555
+ overDot = hit.source === 'dot';
556
+ overHandle = true;
557
+ }
564
558
  }
565
- this.#engine.panBy(-deltaX, -deltaY);
566
559
  }
567
- }
560
+ var world = engine.toWorld(screenPoint);
561
+ var hovered = overHandle ? null : engine.hitTest(world);
562
+ // Inside the frame of the selection with nothing drawn under the pointer is still the selection (a press there carries it, except
563
+ // with Shift, which starts a marquee), so the cursor says so, as it does over a selected object.
564
+ var insideSelectionFrame = !overHandle && !hovered && !input.shiftKey && !!selectionFrame && frameContains(selectionFrame, world);
565
+ var hoveredSelected = insideSelectionFrame || (!overHandle && !!hovered && state.selectedIds.includes(hovered));
566
+ var hoveredUnselected = !overHandle && !!hovered && !state.selectedIds.includes(hovered) ? hovered : null;
567
+ var cursor = resolveHoverCursor({
568
+ spaceHeld: __classPrivateFieldGet(this, _PointerController_spaceHeld, "f"),
569
+ tool: state.tool,
570
+ hoveredUnselectedId: hoveredUnselected,
571
+ hoveredSelected: hoveredSelected,
572
+ resizeHandleCursor: resizeHandleCursor,
573
+ overRotationDot: overDot,
574
+ overArrowHandle: !!arrowHandle,
575
+ hoverBlockedByLiveWidget: hoveredUnselected ? __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isHeldByLiveWidget).call(this, [hoveredUnselected]) : false,
576
+ selectionBlockedByLiveWidget: hoveredSelected ? __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isHeldByLiveWidget).call(this, state.selectedIds) : false
577
+ });
578
+ engine.setHover(hovered && !state.selectedIds.includes(hovered) ? hovered : null);
579
+ engine.setRotationDotHover(overDot);
580
+ engine.setArrowHandleHover(arrowHandle);
581
+ engine.setCursor(cursor);
582
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_hoverWidgetCard).call(this, overHandle ? null : hitTestLeaf(state.scene, world, { zoom: state.viewport.zoom }));
583
+ }, _PointerController_hoverArrowTarget = function _PointerController_hoverArrowTarget(input) {
584
+ var _a, _b;
585
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
586
+ var world = engine.toWorld({ x: input.x, y: input.y });
587
+ var hint = input.altKey ? null : ((_b = (_a = pickArrowBinding(engine.state.scene, world, { zoom: engine.state.viewport.zoom })) === null || _a === void 0 ? void 0 : _a.hint) !== null && _b !== void 0 ? _b : null);
588
+ var shown = engine.state.overlay.arrowBind;
589
+ var same = hint === null
590
+ ? shown === null
591
+ : shown !== null && shown.targetId === hint.targetId && shown.kind === hint.kind && shown.point.x === hint.point.x && shown.point.y === hint.point.y;
592
+ if (!same)
593
+ engine.setOverlay({ arrowBind: hint });
594
+ }, _PointerController_hoverWidgetCard = function _PointerController_hoverWidgetCard(leaf) {
595
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
596
+ var state = engine.state;
597
+ var card = leaf && leaf.type === 'widget' && leaf.parentId === null && !state.pending[leaf.id] && !engine.widgetRuntime(leaf.widgetId).orphaned ? leaf : null;
598
+ engine.setHoverWidget(card ? card.widgetId : null);
599
+ if (!card || state.overlayDragActive || state.editingTextId)
600
+ return;
601
+ if (!state.selectedIds.includes(card.id))
602
+ engine.select([card.id]);
603
+ }, _PointerController_forgetStalePointers = function _PointerController_forgetStalePointers(now) {
604
+ for (var _i = 0, _a = __classPrivateFieldGet(this, _PointerController_pointers, "f"); _i < _a.length; _i++) {
605
+ var _b = _a[_i], id = _b[0], pointer = _b[1];
606
+ if (now - pointer.seenAt > STALE_POINTER_MS)
607
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").delete(id);
608
+ }
609
+ }, _PointerController_pinchGeometry = function _PointerController_pinchGeometry() {
610
+ var _a = __spreadArray([], __classPrivateFieldGet(this, _PointerController_pointers, "f").values(), true), first = _a[0], second = _a[1];
611
+ if (!first || !second)
612
+ return null;
613
+ return {
614
+ center: { x: (first.x + second.x) / 2, y: (first.y + second.y) / 2 },
615
+ distance: Math.max(1, Math.hypot(first.x - second.x, first.y - second.y))
616
+ };
617
+ }, _PointerController_startPinch = function _PointerController_startPinch() {
618
+ var _a, _b;
619
+ // Whatever one finger was doing is abandoned.
620
+ if (__classPrivateFieldGet(this, _PointerController_active, "f"))
621
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'cancel');
622
+ var geometry = __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_pinchGeometry).call(this);
623
+ if (!geometry)
624
+ return;
625
+ var viewport = __classPrivateFieldGet(this, _PointerController_engine, "f").state.viewport;
626
+ __classPrivateFieldSet(this, _PointerController_pinch, {
627
+ startDistance: geometry.distance,
628
+ startZoom: viewport.zoom,
629
+ anchorWorld: __classPrivateFieldGet(this, _PointerController_engine, "f").toWorld(geometry.center)
630
+ }, "f");
631
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).onGestureChange) === null || _b === void 0 ? void 0 : _b.call(_a, 'pinch');
632
+ }, _PointerController_updatePinch = function _PointerController_updatePinch() {
633
+ var pinch = __classPrivateFieldGet(this, _PointerController_pinch, "f");
634
+ var geometry = __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_pinchGeometry).call(this);
635
+ if (!pinch || !geometry)
636
+ return;
637
+ var zoom = clampZoom(pinch.startZoom * (geometry.distance / pinch.startDistance));
638
+ // The world point that was between the fingers stays between them, so the view pans with the hand.
639
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setViewport({
640
+ x: geometry.center.x - pinch.anchorWorld.x * zoom,
641
+ y: geometry.center.y - pinch.anchorWorld.y * zoom,
642
+ zoom: zoom
643
+ });
644
+ }, _PointerController_endPinch = function _PointerController_endPinch() {
645
+ var _a, _b;
646
+ if (!__classPrivateFieldGet(this, _PointerController_pinch, "f"))
647
+ return;
648
+ __classPrivateFieldSet(this, _PointerController_pinch, null, "f");
649
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).onGestureChange) === null || _b === void 0 ? void 0 : _b.call(_a, null);
650
+ };