@widgetic/canvas 0.5.39 → 0.5.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +7 -3
  2. package/dist/canvas/DomCanvas.svelte +7 -3
  3. package/dist/canvas/DomCanvas.svelte.d.ts +8 -0
  4. package/dist/canvas/autosaveScheduler.js +89 -37
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +19 -7
  8. package/dist/canvas/chromeLayout.d.ts +2 -0
  9. package/dist/canvas/chromeLayout.js +31 -17
  10. package/dist/canvas/eventScope.js +14 -10
  11. package/dist/canvas/host/CanvasHost.d.ts +6 -0
  12. package/dist/canvas/host/CanvasHost.js +1556 -1255
  13. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  14. package/dist/canvas/host/CanvasHostApi.js +25 -4
  15. package/dist/canvas/host/browserServices.js +116 -65
  16. package/dist/canvas/host/conversion.js +170 -82
  17. package/dist/canvas/host/hostObject.js +7 -7
  18. package/dist/canvas/host/pageEvents.js +4 -4
  19. package/dist/canvas/host/screenRects.js +31 -28
  20. package/dist/canvas/host/strokeSnap.js +143 -88
  21. package/dist/canvas/openMarks.js +2 -2
  22. package/dist/canvas/outsideClickDeselect.js +7 -6
  23. package/dist/canvas/panZoomPosition.js +2 -2
  24. package/dist/canvas/preferredTextFont.js +25 -13
  25. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  26. package/dist/canvas/shapes/shapeImageStore.js +3 -3
  27. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  28. package/dist/canvas/toolbarPosition.js +2 -2
  29. package/dist/canvas/ui/CanvasContextMenu.svelte +69 -39
  30. package/dist/canvas/ui/CanvasHint.svelte +17 -4
  31. package/dist/canvas/ui/CanvasHint.svelte.d.ts +2 -17
  32. package/dist/canvas/ui/CanvasToolbar.svelte +27 -10
  33. package/dist/canvas/ui/ColorField.svelte +1 -1
  34. package/dist/canvas/ui/SelectionPanel.svelte +24 -20
  35. package/dist/canvas/ui/ShapesMenu.svelte +0 -2
  36. package/dist/canvas/ui/ToolButton.svelte +11 -3
  37. package/dist/canvas/ui/ToolButton.svelte.d.ts +2 -0
  38. package/dist/canvas/ui/WidgetActions.svelte +1 -1
  39. package/dist/canvas/ui/ZoomControl.svelte +39 -4
  40. package/dist/canvas/ui/ZoomControl.svelte.d.ts +2 -2
  41. package/dist/canvas/ui/colorModel.js +32 -21
  42. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  43. package/dist/canvas/ui/floatingCard.d.ts +7 -5
  44. package/dist/canvas/ui/floatingCard.js +23 -21
  45. package/dist/canvas/ui/floatingLayer.js +6 -5
  46. package/dist/canvas/ui/keyHints.d.ts +5 -0
  47. package/dist/canvas/ui/keyHints.js +23 -7
  48. package/dist/canvas/ui/popoverSide.js +3 -2
  49. package/dist/canvas/ui/selectionTraits.js +40 -34
  50. package/dist/canvas/ui/sizeLabelVisibility.d.ts +5 -2
  51. package/dist/canvas/ui/sizeLabelVisibility.js +7 -6
  52. package/dist/canvas/ui/widgetSelectionPanel.d.ts +6 -0
  53. package/dist/canvas/ui/widgetSelectionPanel.js +9 -0
  54. package/dist/canvas/view/ObjectView.svelte +2 -1
  55. package/dist/canvas/view/SelectionOverlay.svelte +34 -14
  56. package/dist/canvas/view/erasingMarks.js +7 -7
  57. package/dist/canvas/view/geometry.d.ts +14 -4
  58. package/dist/canvas/view/geometry.js +103 -77
  59. package/dist/components/preferenceStorage.js +2 -2
  60. package/dist/engine/EngineCore.d.ts +4 -1
  61. package/dist/engine/EngineCore.js +801 -695
  62. package/dist/engine/codec/canvasDocument.js +173 -173
  63. package/dist/engine/codec/hostReadableKeys.js +1 -1
  64. package/dist/engine/core/arrange.js +38 -26
  65. package/dist/engine/core/arrow.d.ts +10 -3
  66. package/dist/engine/core/arrow.js +96 -75
  67. package/dist/engine/core/arrowBinding.d.ts +69 -0
  68. package/dist/engine/core/arrowBinding.js +344 -0
  69. package/dist/engine/core/arrowBindingRecords.d.ts +43 -0
  70. package/dist/engine/core/arrowBindingRecords.js +141 -0
  71. package/dist/engine/core/brush.js +94 -67
  72. package/dist/engine/core/defaults.js +51 -90
  73. package/dist/engine/core/freehand.js +163 -147
  74. package/dist/engine/core/geometry.js +54 -47
  75. package/dist/engine/core/history.js +50 -33
  76. package/dist/engine/core/hitTest.d.ts +3 -0
  77. package/dist/engine/core/hitTest.js +83 -69
  78. package/dist/engine/core/matrix.js +20 -18
  79. package/dist/engine/core/pathData.js +210 -183
  80. package/dist/engine/core/rotationReset.js +6 -5
  81. package/dist/engine/core/scene.d.ts +3 -0
  82. package/dist/engine/core/scene.js +192 -129
  83. package/dist/engine/core/scribble.js +84 -59
  84. package/dist/engine/core/shapePaths.js +15 -12
  85. package/dist/engine/core/shapeTools.js +63 -72
  86. package/dist/engine/core/snapping.js +117 -65
  87. package/dist/engine/core/style.js +64 -31
  88. package/dist/engine/core/transform.js +94 -83
  89. package/dist/engine/core/types.d.ts +29 -0
  90. package/dist/engine/core/types.js +4 -4
  91. package/dist/engine/core/viewport.js +36 -23
  92. package/dist/engine/input/PointerController.js +476 -447
  93. package/dist/engine/input/arrowHandles.js +12 -12
  94. package/dist/engine/input/gestures.d.ts +12 -1
  95. package/dist/engine/input/gestures.js +342 -251
  96. package/dist/engine/input/hoverCursor.js +1 -1
  97. package/dist/engine/input/keyboard.d.ts +9 -1
  98. package/dist/engine/input/keyboard.js +46 -27
  99. package/dist/engine/input/selectionHandles.js +50 -45
  100. package/dist/engine/input/types.js +1 -1
  101. package/dist/engine/render/rasterize.js +158 -86
  102. package/dist/engine/state.d.ts +6 -1
  103. package/dist/engine/state.js +17 -5
  104. package/dist/engine/text/layoutText.js +62 -43
  105. package/dist/engine/text/textMetrics.js +10 -8
  106. package/dist/engine/widgets.js +137 -101
  107. package/dist/fonts/interFont.js +68 -17
  108. package/dist/fonts/workspaceFonts.js +90 -32
  109. package/dist/i18n/labels.js +6 -5
  110. package/dist/i18n/language.js +4 -4
  111. package/dist/i18n/messages.d.ts +6 -6
  112. package/dist/i18n/messages.js +7 -7
  113. package/dist/i18n/shortcuts.d.ts +12 -0
  114. package/dist/i18n/shortcuts.js +32 -18
  115. package/dist/settings/workspaceToolSettings.js +48 -32
  116. package/dist/tools/components/catalog.d.ts +11 -0
  117. package/dist/tools/components/catalog.js +270 -0
  118. package/dist/tools/components/grouping.d.ts +9 -0
  119. package/dist/tools/components/grouping.js +33 -0
  120. package/dist/tools/definitions.d.ts +19 -0
  121. package/dist/tools/definitions.js +147 -0
  122. package/dist/tools/executors.d.ts +7 -0
  123. package/dist/tools/executors.js +324 -0
  124. package/dist/tools/hostAdapter.d.ts +14 -0
  125. package/dist/tools/hostAdapter.js +40 -0
  126. package/dist/tools/index.d.ts +6 -0
  127. package/dist/tools/index.js +6 -0
  128. package/dist/tools/sceneSummary.d.ts +24 -0
  129. package/dist/tools/sceneSummary.js +170 -0
  130. package/dist/tools/sketchIntent.d.ts +17 -0
  131. package/dist/tools/sketchIntent.js +166 -0
  132. package/dist/tools/types.d.ts +54 -0
  133. package/dist/tools/types.js +11 -0
  134. package/package.json +7 -2
@@ -6,6 +6,28 @@
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_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;
30
+ import { pickArrowBinding } from '../core/arrowBinding.js';
9
31
  import { hitTestLeaf } from '../core/hitTest.js';
10
32
  import { clampNumber, distanceBetween } from '../core/geometry.js';
11
33
  import { leafShapesOf } from '../core/scene.js';
@@ -17,127 +39,101 @@ import { arrowHandleMetricsFor, hitArrowHandle, singleArrowOf } from './arrowHan
17
39
  import { resolveHoverCursor } from './hoverCursor.js';
18
40
  import { availableHandles, cursorForHandle, handleMetricsFor, hitSelectionHandle } from './selectionHandles.js';
19
41
  /** Two presses this close in time and place are a double click. */
20
- export const DOUBLE_CLICK_MS = 400;
21
- export const DOUBLE_CLICK_DISTANCE = 6;
42
+ export var DOUBLE_CLICK_MS = 400;
43
+ export var DOUBLE_CLICK_DISTANCE = 6;
22
44
  /** A pointer that has said nothing for this long is not one of two fingers: its release was lost. */
23
- const STALE_POINTER_MS = 1500;
45
+ var STALE_POINTER_MS = 1500;
24
46
  /** One line of a wheel in a line-based device, in pixels. */
25
- const WHEEL_LINE_PIXELS = 16;
26
- const WHEEL_PAGE_PIXELS = 400;
27
- export class PointerController {
28
- #engine;
29
- #options;
30
- #context;
31
- #active = null;
32
- #pinch = null;
33
- #pointers = new Map();
34
- #spaceHeld = false;
35
- #lastClick = null;
36
- /** 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. */
37
- #lastHandlePress = null;
38
- #lastHover = null;
39
- #lastInput = null;
40
- constructor(engine, options = {}) {
41
- this.#engine = engine;
42
- this.#options = options;
43
- this.#context = { engine, options };
44
- }
45
- /** The kind of gesture that is running, or null. */
46
- get gestureKind() {
47
- return this.#pinch ? 'pinch' : (this.#active?.kind ?? null);
47
+ var WHEEL_LINE_PIXELS = 16;
48
+ var WHEEL_PAGE_PIXELS = 400;
49
+ var PointerController = /** @class */ (function () {
50
+ function PointerController(engine, options) {
51
+ if (options === void 0) { options = {}; }
52
+ _PointerController_instances.add(this);
53
+ _PointerController_engine.set(this, void 0);
54
+ _PointerController_options.set(this, void 0);
55
+ _PointerController_context.set(this, void 0);
56
+ _PointerController_active.set(this, null);
57
+ _PointerController_pinch.set(this, null);
58
+ _PointerController_pointers.set(this, new Map());
59
+ _PointerController_spaceHeld.set(this, false);
60
+ _PointerController_lastClick.set(this, null);
61
+ /** 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. */
62
+ _PointerController_lastHandlePress.set(this, null);
63
+ _PointerController_lastHover.set(this, null);
64
+ _PointerController_lastInput.set(this, null);
65
+ __classPrivateFieldSet(this, _PointerController_engine, engine, "f");
66
+ __classPrivateFieldSet(this, _PointerController_options, options, "f");
67
+ __classPrivateFieldSet(this, _PointerController_context, { engine: engine, options: options }, "f");
48
68
  }
69
+ Object.defineProperty(PointerController.prototype, "gestureKind", {
70
+ /** The kind of gesture that is running, or null. */
71
+ get: function () {
72
+ var _a, _b;
73
+ 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);
74
+ },
75
+ enumerable: false,
76
+ configurable: true
77
+ });
49
78
  /** Space held: a press pans, whatever the tool. */
50
- setSpaceHeld(held) {
51
- this.#spaceHeld = held;
52
- if (!this.#active && !this.#pinch) {
53
- this.#engine.setCursor(held ? 'grab' : this.#cursorWhenIdle());
79
+ PointerController.prototype.setSpaceHeld = function (held) {
80
+ __classPrivateFieldSet(this, _PointerController_spaceHeld, held, "f");
81
+ if (!__classPrivateFieldGet(this, _PointerController_active, "f") && !__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
82
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setCursor(held ? 'grab' : __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_cursorWhenIdle).call(this));
54
83
  }
55
- }
56
- #cursorWhenIdle() {
57
- return cursorForTool(this.#engine.state.tool);
58
- }
59
- #begin(gesture) {
60
- this.#active = gesture;
61
- this.#engine.setHover(null);
62
- this.#options.onGestureChange?.(gesture.kind);
63
- }
64
- #finish(mode, input) {
65
- const gesture = this.#active;
66
- if (!gesture)
67
- return;
68
- this.#active = null;
69
- try {
70
- if (mode === 'end' && input)
71
- gesture.end(input);
72
- else
73
- gesture.cancel();
74
- }
75
- finally {
76
- // After the gesture the frame (and dot) may have moved: look again at the pointer without waiting for the next move.
77
- this.#lastHover = null;
78
- this.#options.onGestureChange?.(null);
79
- const hoverInput = input ?? this.#lastInput;
80
- // No pointer seen yet (a gesture cancelled from the keyboard) or a finger: there is nothing to look at.
81
- if (hoverInput && hoverInput.pointerType !== 'touch') {
82
- this.#hover(hoverInput);
83
- }
84
- else {
85
- this.#engine.setRotationDotHover(false);
86
- this.#engine.setArrowHandleHover(null);
87
- }
88
- }
89
- }
84
+ };
90
85
  /** Abandons the gesture that is running (Escape). True when there was one. */
91
- cancelGesture() {
92
- if (this.#pinch) {
93
- this.#endPinch();
86
+ PointerController.prototype.cancelGesture = function () {
87
+ if (__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
88
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_endPinch).call(this);
94
89
  return true;
95
90
  }
96
- if (!this.#active)
91
+ if (!__classPrivateFieldGet(this, _PointerController_active, "f"))
97
92
  return false;
98
- this.#finish('cancel');
93
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'cancel');
99
94
  return true;
100
- }
95
+ };
101
96
  /** Shift, Alt, Ctrl or Meta changed while the pointer stayed still. */
102
- modifiersChanged(modifiers) {
103
- this.#active?.modifiersChanged?.(modifiers, this.#lastInput);
104
- }
105
- dispose() {
97
+ PointerController.prototype.modifiersChanged = function (modifiers) {
98
+ var _a, _b;
99
+ (_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"));
100
+ };
101
+ PointerController.prototype.dispose = function () {
106
102
  this.cancelGesture();
107
- this.#pointers.clear();
108
- }
103
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").clear();
104
+ };
109
105
  // ──────────────────────────────────────────────────────── press
110
106
  /** Handles a press. Returns whether the shell should capture the pointer and keep the browser from acting on it. */
111
- pointerDown(input) {
112
- this.#lastInput = input;
113
- this.#engine.cancelRotationReset();
114
- this.#forgetStalePointers(input.time);
115
- this.#pointers.set(input.pointerId, { x: input.x, y: input.y, seenAt: input.time });
116
- this.#engine.lastPointerWorld = this.#engine.toWorld({ x: input.x, y: input.y });
117
- if (input.pointerType === 'touch' && this.#pointers.size === 2) {
118
- this.#startPinch();
107
+ PointerController.prototype.pointerDown = function (input) {
108
+ __classPrivateFieldSet(this, _PointerController_lastInput, input, "f");
109
+ __classPrivateFieldGet(this, _PointerController_engine, "f").cancelRotationReset();
110
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_forgetStalePointers).call(this, input.time);
111
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").set(input.pointerId, { x: input.x, y: input.y, seenAt: input.time });
112
+ __classPrivateFieldGet(this, _PointerController_engine, "f").lastPointerWorld = __classPrivateFieldGet(this, _PointerController_engine, "f").toWorld({ x: input.x, y: input.y });
113
+ if (input.pointerType === 'touch' && __classPrivateFieldGet(this, _PointerController_pointers, "f").size === 2) {
114
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_startPinch).call(this);
119
115
  return true;
120
116
  }
121
- if (this.#pointers.size > 1 || this.#pinch)
117
+ if (__classPrivateFieldGet(this, _PointerController_pointers, "f").size > 1 || __classPrivateFieldGet(this, _PointerController_pinch, "f"))
122
118
  return true;
123
- if (this.#active)
124
- this.#finish('cancel');
119
+ if (__classPrivateFieldGet(this, _PointerController_active, "f"))
120
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'cancel');
125
121
  // The secondary button belongs to the context menu.
126
122
  if (input.button === 2)
127
123
  return false;
128
- if (input.button === 1 || (input.button === 0 && this.#spaceHeld) || (input.button === 0 && this.#engine.state.tool === 'pan')) {
129
- this.#begin(createPanGesture(this.#context, input));
124
+ if (input.button === 1 || (input.button === 0 && __classPrivateFieldGet(this, _PointerController_spaceHeld, "f")) || (input.button === 0 && __classPrivateFieldGet(this, _PointerController_engine, "f").state.tool === 'pan')) {
125
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createPanGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
130
126
  return true;
131
127
  }
132
128
  if (input.button !== 0)
133
129
  return false;
134
130
  // A click on the board ends the typing in a text.
135
- if (this.#engine.state.editingTextId)
136
- this.#engine.endTextEdit();
137
- const state = this.#engine.state;
131
+ if (__classPrivateFieldGet(this, _PointerController_engine, "f").state.editingTextId)
132
+ __classPrivateFieldGet(this, _PointerController_engine, "f").endTextEdit();
133
+ var state = __classPrivateFieldGet(this, _PointerController_engine, "f").state;
138
134
  switch (state.tool) {
139
135
  case 'draw':
140
- this.#begin(createDrawGesture(this.#context, input));
136
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createDrawGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
141
137
  return true;
142
138
  case 'rect':
143
139
  case 'rounded-rect':
@@ -146,400 +142,433 @@ export class PointerController {
146
142
  case 'triangle':
147
143
  case 'arrow':
148
144
  case 'library-shape':
149
- this.#begin(createShapeGesture(this.#context, input, state.tool, state.libraryShapeKey));
145
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createShapeGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, state.tool, state.libraryShapeKey));
150
146
  return true;
151
147
  case 'text':
152
- return this.#pressWithTextTool(input);
148
+ return __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_pressWithTextTool).call(this, input);
153
149
  case 'erase':
154
- this.#begin(createEraseGesture(this.#context, input));
150
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createEraseGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
155
151
  return true;
156
152
  default:
157
- return this.#pressWithSelectTool(input);
158
- }
159
- }
160
- #pressWithTextTool(input) {
161
- const engine = this.#engine;
162
- const world = engine.toWorld({ x: input.x, y: input.y });
163
- // A click on a text that is already there edits it instead of making another on top.
164
- const hit = hitTestLeaf(engine.state.scene, world, { zoom: engine.state.viewport.zoom });
165
- if (hit && hit.type === 'text') {
166
- if (hit.parentId)
167
- engine.enterGroup(hit.parentId, hit.id);
168
- engine.beginTextEdit(hit.id);
169
- return true;
170
- }
171
- this.#begin(createTextGesture(this.#context, input));
172
- return true;
173
- }
174
- #isDoubleClick(input) {
175
- const previous = this.#lastClick;
176
- return (!!previous &&
177
- input.time - previous.time <= DOUBLE_CLICK_MS &&
178
- distanceBetween({ x: previous.x, y: previous.y }, { x: input.x, y: input.y }) <= DOUBLE_CLICK_DISTANCE);
179
- }
180
- #rememberHandlePress(input, handle) {
181
- this.#lastHandlePress = { handle, time: input.time, x: input.x, y: input.y };
182
- }
183
- /** Whether this press, on the handle `handle`, follows the last press on that same handle soon and close enough to be its double. */
184
- #isDoublePressOn(input, handle) {
185
- const previous = this.#lastHandlePress;
186
- return (!!previous &&
187
- previous.handle === handle &&
188
- input.time - previous.time <= DOUBLE_CLICK_MS &&
189
- distanceBetween({ x: previous.x, y: previous.y }, { x: input.x, y: input.y }) <= DOUBLE_CLICK_DISTANCE);
190
- }
191
- #pressWithSelectTool(input) {
192
- const engine = this.#engine;
193
- const screenPoint = { x: input.x, y: input.y };
194
- const world = engine.toWorld(screenPoint);
195
- const pickMode = this.#options.pickMode?.() ?? false;
196
- // The handles of the selection come before whatever lies under them.
197
- if (!pickMode && engine.state.selectedIds.length > 0) {
198
- const shapes = engine.selectedShapes();
199
- // One selected arrow has two ends and a middle to take hold of, and no frame; anywhere else on it is the arrow itself.
200
- const arrow = singleArrowOf(shapes, engine.state.selectedIds);
201
- const arrowHandle = arrow ? hitArrowHandle(arrow, engine.state.viewport, screenPoint, arrowHandleMetricsFor(input.pointerType)) : null;
202
- if (arrow && arrowHandle) {
203
- this.#begin(createArrowHandleGesture(this.#context, input, arrow, arrowHandle));
204
- return true;
205
- }
206
- const frame = arrow ? null : selectionFrameOf(shapes);
207
- if (frame) {
208
- const viewport = engine.state.viewport;
209
- const available = availableHandles(shapes, frame, viewport, this.#options.plainCardChrome?.() ?? false);
210
- const hit = hitSelectionHandle(frame, viewport, screenPoint, handleMetricsFor(input.pointerType), available);
211
- if (hit?.type === 'resize') {
212
- // Two quick presses on the side of a text set its width to its letters, as it was when it was made.
213
- if ((hit.handle === 'e' || hit.handle === 'w') && this.#isDoublePressOn(input, hit.handle) && engine.fitSelectedTextToContent()) {
214
- this.#lastHandlePress = null;
215
- return true;
216
- }
217
- this.#rememberHandlePress(input, hit.handle);
218
- this.#begin(createResizeGesture(this.#context, input, hit.handle, frame, shapes));
219
- return true;
220
- }
221
- if (hit?.type === 'rotate') {
222
- // Two quick presses on the dot stand the selection upright again.
223
- if (hit.source === 'dot' && this.#isDoublePressOn(input, 'rotate') && engine.resetSelectionRotation()) {
224
- this.#lastHandlePress = null;
225
- return true;
226
- }
227
- if (hit.source === 'dot')
228
- this.#rememberHandlePress(input, 'rotate');
229
- this.#begin(createRotateGesture(this.#context, input, frame, shapes, hit.source));
230
- return true;
231
- }
232
- }
233
- }
234
- const doubleClick = this.#isDoubleClick(input);
235
- this.#lastClick = doubleClick ? null : { time: input.time, x: input.x, y: input.y };
236
- if (doubleClick && !pickMode && this.#handleDoubleClick(world))
237
- return true;
238
- const unitId = engine.hitTest(world);
239
- if (pickMode) {
240
- if (unitId) {
241
- engine.select([unitId]);
242
- this.#options.onPick?.(unitId);
243
- }
244
- return true;
153
+ return __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_pressWithSelectTool).call(this, input);
245
154
  }
246
- // Alt-drag on an object duplicates the selection; Alt-click with no drag steps through the stack.
247
- if (input.altKey && unitId) {
248
- if (input.shiftKey) {
249
- engine.toggleSelection(unitId);
250
- if (!engine.state.selectedIds.includes(unitId))
251
- return true;
252
- }
253
- const moving = engine.state.selectedIds.length > 0 ? [...engine.state.selectedIds] : [unitId];
254
- this.#begin(createMoveGesture(this.#context, input, moving, {
255
- onClick: () => this.#drillThrough(world),
256
- duplicateOnDrag: true,
257
- immovable: this.#isHeldByLiveWidget(moving)
258
- }));
259
- return true;
260
- }
261
- if (input.altKey && this.#drillThrough(world))
262
- return true;
263
- if (unitId) {
264
- const wasSelected = engine.state.selectedIds.includes(unitId);
265
- if (input.shiftKey) {
266
- engine.toggleSelection(unitId);
267
- // Taking an object out of the selection is the whole press.
268
- if (!engine.state.selectedIds.includes(unitId))
269
- return true;
270
- }
271
- else if (!wasSelected) {
272
- engine.select([unitId]);
273
- }
274
- const moving = [...engine.state.selectedIds];
275
- // A click on one of several selected objects, without a drag, narrows the selection to it.
276
- const onClick = !input.shiftKey && wasSelected && moving.length > 1 ? () => engine.select([unitId]) : undefined;
277
- this.#begin(createMoveGesture(this.#context, input, moving, { onClick, immovable: this.#isHeldByLiveWidget(moving) }));
278
- return true;
279
- }
280
- // Empty board. A finger pans (a tap clears the selection); a mouse drags a marquee.
281
- if (input.pointerType === 'touch') {
282
- this.#begin(createPanGesture(this.#context, input, { onTap: () => engine.clearSelection() }));
283
- return true;
284
- }
285
- if (!input.shiftKey)
286
- engine.clearSelection();
287
- this.#begin(createMarqueeGesture(this.#context, input));
288
- return true;
289
- }
290
- /**
291
- * Selects the object one step below the one that is selected, among the objects under the pointer (and the
292
- * top one when the bottom one was reached or nothing was selected). False when there is nothing to step through.
293
- */
294
- #drillThrough(world) {
295
- const engine = this.#engine;
296
- const stack = engine.hitTestStack(world);
297
- if (stack.length === 0)
298
- return false;
299
- const selected = engine.state.selectedIds;
300
- const current = selected.length === 1 ? selected[0] : null;
301
- const position = current ? stack.indexOf(current) : -1;
302
- const next = stack[position <= 0 ? stack.length - 1 : position - 1];
303
- if (next !== current)
304
- engine.select([next]);
305
- return true;
306
- }
307
- /** Whether everything the units hold is a widget card that a live widget covers: only the host's own bar moves those. */
308
- #isHeldByLiveWidget(unitIds) {
309
- const shapes = leafShapesOf(this.#engine.state.scene, unitIds);
310
- return shapes.length > 0 && shapes.every((shape) => shape.type === 'widget' && !this.#engine.widgetRuntime(shape.widgetId).bodyDragAllowed);
311
- }
312
- /** Enters a group, edits a text, or tells the host a card was activated. True when something was done. */
313
- #handleDoubleClick(world) {
314
- const engine = this.#engine;
315
- const state = engine.state;
316
- const leaf = hitTestLeaf(state.scene, world, { zoom: state.viewport.zoom });
317
- if (!leaf || state.pending[leaf.id])
318
- return false;
319
- if (leaf.type === 'text') {
320
- if (leaf.parentId)
321
- engine.enterGroup(leaf.parentId, leaf.id);
322
- engine.beginTextEdit(leaf.id);
323
- return true;
324
- }
325
- const unitId = engine.hitTest(world);
326
- const unit = unitId ? engine.getObject(unitId) : undefined;
327
- if (unit && unit.type === 'group') {
328
- // Go into the group and pick the member that was double-clicked.
329
- const index = engine.sceneIndex();
330
- let member = index.get(leaf.id);
331
- while (member && member.parentId !== unit.id)
332
- member = member.parentId ? index.get(member.parentId) : undefined;
333
- engine.enterGroup(unit.id, member?.id ?? leaf.id);
334
- return true;
335
- }
336
- if (leaf.type === 'widget') {
337
- this.#options.onActivate?.(leaf.id);
338
- return true;
339
- }
340
- return false;
341
- }
155
+ };
342
156
  /** A right click or a long press: picks the object under the pointer if it is not selected. Returns it. */
343
- prepareContextMenu(screenPoint) {
344
- const engine = this.#engine;
345
- const unitId = engine.hitTest(engine.toWorld(screenPoint));
157
+ PointerController.prototype.prepareContextMenu = function (screenPoint) {
158
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
159
+ var unitId = engine.hitTest(engine.toWorld(screenPoint));
346
160
  if (unitId && !engine.state.selectedIds.includes(unitId))
347
161
  engine.select([unitId]);
348
162
  return unitId;
349
- }
163
+ };
350
164
  // ──────────────────────────────────────────────────────── move
351
- pointerMove(input) {
352
- this.#lastInput = input;
353
- const tracked = this.#pointers.get(input.pointerId);
165
+ PointerController.prototype.pointerMove = function (input) {
166
+ __classPrivateFieldSet(this, _PointerController_lastInput, input, "f");
167
+ var tracked = __classPrivateFieldGet(this, _PointerController_pointers, "f").get(input.pointerId);
354
168
  if (tracked) {
355
169
  tracked.x = input.x;
356
170
  tracked.y = input.y;
357
171
  tracked.seenAt = input.time;
358
172
  }
359
- this.#engine.lastPointerWorld = this.#engine.toWorld({ x: input.x, y: input.y });
360
- if (this.#pinch) {
361
- this.#updatePinch();
173
+ __classPrivateFieldGet(this, _PointerController_engine, "f").lastPointerWorld = __classPrivateFieldGet(this, _PointerController_engine, "f").toWorld({ x: input.x, y: input.y });
174
+ if (__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
175
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_updatePinch).call(this);
362
176
  return;
363
177
  }
364
- if (this.#active) {
365
- if (input.pointerId === this.#active.pointerId)
366
- this.#active.move(input);
178
+ if (__classPrivateFieldGet(this, _PointerController_active, "f")) {
179
+ if (input.pointerId === __classPrivateFieldGet(this, _PointerController_active, "f").pointerId)
180
+ __classPrivateFieldGet(this, _PointerController_active, "f").move(input);
367
181
  return;
368
182
  }
369
183
  if (input.pointerType === 'touch')
370
184
  return;
371
- this.#hover(input);
372
- }
373
- /** What is under the pointer when nothing is being dragged: the cursor, and the object to outline. */
374
- #hover(input) {
375
- const engine = this.#engine;
376
- const state = engine.state;
377
- if (this.#spaceHeld || state.tool !== 'select')
185
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_hover).call(this, input);
186
+ };
187
+ /** The pointer left the board: nothing is hovered any more. */
188
+ PointerController.prototype.pointerLeave = function () {
189
+ __classPrivateFieldSet(this, _PointerController_lastHover, null, "f");
190
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setHoverWidget(null);
191
+ if (!__classPrivateFieldGet(this, _PointerController_active, "f")) {
192
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setHover(null);
193
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setRotationDotHover(false);
194
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setArrowHandleHover(null);
195
+ if (__classPrivateFieldGet(this, _PointerController_engine, "f").state.overlay.arrowBind)
196
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setOverlay({ arrowBind: null });
197
+ }
198
+ };
199
+ // ──────────────────────────────────────────────────────── release
200
+ PointerController.prototype.pointerUp = function (input) {
201
+ __classPrivateFieldSet(this, _PointerController_lastInput, input, "f");
202
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").delete(input.pointerId);
203
+ if (__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
204
+ if (__classPrivateFieldGet(this, _PointerController_pointers, "f").size < 2)
205
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_endPinch).call(this);
378
206
  return;
379
- if (this.#lastHover && Math.abs(this.#lastHover.x - input.x) < 1 && Math.abs(this.#lastHover.y - input.y) < 1)
207
+ }
208
+ if (__classPrivateFieldGet(this, _PointerController_active, "f") && __classPrivateFieldGet(this, _PointerController_active, "f").pointerId === input.pointerId)
209
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'end', input);
210
+ };
211
+ PointerController.prototype.pointerCancel = function (input) {
212
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").delete(input.pointerId);
213
+ if (__classPrivateFieldGet(this, _PointerController_pinch, "f")) {
214
+ if (__classPrivateFieldGet(this, _PointerController_pointers, "f").size < 2)
215
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_endPinch).call(this);
380
216
  return;
381
- this.#lastHover = { x: input.x, y: input.y };
382
- const screenPoint = { x: input.x, y: input.y };
383
- let overHandle = false;
384
- let overDot = false;
385
- let resizeHandleCursor = null;
386
- let arrowHandle = null;
387
- if (state.selectedIds.length > 0) {
388
- const shapes = engine.selectedShapes();
389
- const arrow = singleArrowOf(shapes, state.selectedIds);
390
- if (arrow) {
391
- arrowHandle = hitArrowHandle(arrow, state.viewport, screenPoint, arrowHandleMetricsFor(input.pointerType));
392
- if (arrowHandle) {
393
- overHandle = true;
217
+ }
218
+ if (__classPrivateFieldGet(this, _PointerController_active, "f") && __classPrivateFieldGet(this, _PointerController_active, "f").pointerId === input.pointerId)
219
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'cancel');
220
+ };
221
+ // ──────────────────────────────────────────────────────── wheel
222
+ /** The wheel (or two fingers on a trackpad) pans; with Ctrl or Meta, which a trackpad pinch also reports, it zooms about the pointer. */
223
+ PointerController.prototype.wheel = function (input) {
224
+ var unit = input.deltaMode === 1 ? WHEEL_LINE_PIXELS : input.deltaMode === 2 ? WHEEL_PAGE_PIXELS : 1;
225
+ var deltaX = input.deltaX * unit;
226
+ var deltaY = input.deltaY * unit;
227
+ if (input.ctrlKey || input.metaKey) {
228
+ var factor = Math.exp(-clampNumber(deltaY, -60, 60) * 0.01);
229
+ __classPrivateFieldGet(this, _PointerController_engine, "f").zoomAt({ x: input.x, y: input.y }, __classPrivateFieldGet(this, _PointerController_engine, "f").state.viewport.zoom * factor);
230
+ return;
231
+ }
232
+ // A mouse wheel with Shift held scrolls sideways.
233
+ if (input.shiftKey && deltaX === 0) {
234
+ deltaX = deltaY;
235
+ deltaY = 0;
236
+ }
237
+ __classPrivateFieldGet(this, _PointerController_engine, "f").panBy(-deltaX, -deltaY);
238
+ };
239
+ return PointerController;
240
+ }());
241
+ export { PointerController };
242
+ _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_lastClick = new WeakMap(), _PointerController_lastHandlePress = new WeakMap(), _PointerController_lastHover = new WeakMap(), _PointerController_lastInput = new WeakMap(), _PointerController_instances = new WeakSet(), _PointerController_cursorWhenIdle = function _PointerController_cursorWhenIdle() {
243
+ return cursorForTool(__classPrivateFieldGet(this, _PointerController_engine, "f").state.tool);
244
+ }, _PointerController_begin = function _PointerController_begin(gesture) {
245
+ var _a, _b;
246
+ __classPrivateFieldSet(this, _PointerController_active, gesture, "f");
247
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setHover(null);
248
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).onGestureChange) === null || _b === void 0 ? void 0 : _b.call(_a, gesture.kind);
249
+ }, _PointerController_finish = function _PointerController_finish(mode, input) {
250
+ var _a, _b;
251
+ var gesture = __classPrivateFieldGet(this, _PointerController_active, "f");
252
+ if (!gesture)
253
+ return;
254
+ __classPrivateFieldSet(this, _PointerController_active, null, "f");
255
+ try {
256
+ if (mode === 'end' && input)
257
+ gesture.end(input);
258
+ else
259
+ gesture.cancel();
260
+ }
261
+ finally {
262
+ // After the gesture the frame (and dot) may have moved: look again at the pointer without waiting for the next move.
263
+ __classPrivateFieldSet(this, _PointerController_lastHover, null, "f");
264
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).onGestureChange) === null || _b === void 0 ? void 0 : _b.call(_a, null);
265
+ var hoverInput = input !== null && input !== void 0 ? input : __classPrivateFieldGet(this, _PointerController_lastInput, "f");
266
+ // No pointer seen yet (a gesture cancelled from the keyboard) or a finger: there is nothing to look at.
267
+ if (hoverInput && hoverInput.pointerType !== 'touch') {
268
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_hover).call(this, hoverInput);
269
+ }
270
+ else {
271
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setRotationDotHover(false);
272
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setArrowHandleHover(null);
273
+ }
274
+ }
275
+ }, _PointerController_pressWithTextTool = function _PointerController_pressWithTextTool(input) {
276
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
277
+ var world = engine.toWorld({ x: input.x, y: input.y });
278
+ // A click on a text that is already there edits it instead of making another on top.
279
+ var hit = hitTestLeaf(engine.state.scene, world, { zoom: engine.state.viewport.zoom });
280
+ if (hit && hit.type === 'text') {
281
+ if (hit.parentId)
282
+ engine.enterGroup(hit.parentId, hit.id);
283
+ engine.beginTextEdit(hit.id);
284
+ return true;
285
+ }
286
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createTextGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
287
+ return true;
288
+ }, _PointerController_isDoubleClick = function _PointerController_isDoubleClick(input) {
289
+ var previous = __classPrivateFieldGet(this, _PointerController_lastClick, "f");
290
+ return (!!previous &&
291
+ input.time - previous.time <= DOUBLE_CLICK_MS &&
292
+ distanceBetween({ x: previous.x, y: previous.y }, { x: input.x, y: input.y }) <= DOUBLE_CLICK_DISTANCE);
293
+ }, _PointerController_rememberHandlePress = function _PointerController_rememberHandlePress(input, handle) {
294
+ __classPrivateFieldSet(this, _PointerController_lastHandlePress, { handle: handle, time: input.time, x: input.x, y: input.y }, "f");
295
+ }, _PointerController_isDoublePressOn = function _PointerController_isDoublePressOn(input, handle) {
296
+ var previous = __classPrivateFieldGet(this, _PointerController_lastHandlePress, "f");
297
+ return (!!previous &&
298
+ previous.handle === handle &&
299
+ input.time - previous.time <= DOUBLE_CLICK_MS &&
300
+ distanceBetween({ x: previous.x, y: previous.y }, { x: input.x, y: input.y }) <= DOUBLE_CLICK_DISTANCE);
301
+ }, _PointerController_pressWithSelectTool = function _PointerController_pressWithSelectTool(input) {
302
+ var _this = this;
303
+ var _a, _b, _c, _d, _e, _f, _g, _h;
304
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
305
+ var screenPoint = { x: input.x, y: input.y };
306
+ var world = engine.toWorld(screenPoint);
307
+ 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;
308
+ // The handles of the selection come before whatever lies under them.
309
+ if (!pickMode && engine.state.selectedIds.length > 0) {
310
+ var shapes = engine.selectedShapes();
311
+ // One selected arrow has two ends and a middle to take hold of, and no frame; anywhere else on it is the arrow itself.
312
+ var arrow = singleArrowOf(shapes, engine.state.selectedIds);
313
+ var arrowHandle = arrow ? hitArrowHandle(arrow, engine.state.viewport, screenPoint, arrowHandleMetricsFor(input.pointerType)) : null;
314
+ if (arrow && arrowHandle) {
315
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createArrowHandleGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, arrow, arrowHandle));
316
+ return true;
317
+ }
318
+ var frame = arrow ? null : selectionFrameOf(shapes);
319
+ if (frame) {
320
+ var viewport = engine.state.viewport;
321
+ 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);
322
+ var hit = hitSelectionHandle(frame, viewport, screenPoint, handleMetricsFor(input.pointerType), available);
323
+ if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'resize') {
324
+ // Two quick presses on the side of a text set its width to its letters, as it was when it was made.
325
+ if ((hit.handle === 'e' || hit.handle === 'w') && __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isDoublePressOn).call(this, input, hit.handle) && engine.fitSelectedTextToContent()) {
326
+ __classPrivateFieldSet(this, _PointerController_lastHandlePress, null, "f");
327
+ return true;
394
328
  }
329
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_rememberHandlePress).call(this, input, hit.handle);
330
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createResizeGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, hit.handle, frame, shapes));
331
+ return true;
395
332
  }
396
- const frame = arrow ? null : selectionFrameOf(shapes);
397
- if (frame) {
398
- const available = availableHandles(shapes, frame, state.viewport, this.#options.plainCardChrome?.() ?? false);
399
- const hit = hitSelectionHandle(frame, state.viewport, screenPoint, handleMetricsFor(input.pointerType), available);
400
- if (hit?.type === 'resize') {
401
- resizeHandleCursor = cursorForHandle(hit.handle, frame.rotation);
402
- overHandle = true;
403
- }
404
- else if (hit?.type === 'rotate') {
405
- overDot = hit.source === 'dot';
406
- overHandle = true;
333
+ if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'rotate') {
334
+ // Two quick presses on the dot stand the selection upright again.
335
+ if (hit.source === 'dot' && __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isDoublePressOn).call(this, input, 'rotate') && engine.resetSelectionRotation()) {
336
+ __classPrivateFieldSet(this, _PointerController_lastHandlePress, null, "f");
337
+ return true;
407
338
  }
339
+ if (hit.source === 'dot')
340
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_rememberHandlePress).call(this, input, 'rotate');
341
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createRotateGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, frame, shapes, hit.source));
342
+ return true;
408
343
  }
409
344
  }
410
- const world = engine.toWorld(screenPoint);
411
- const hovered = overHandle ? null : engine.hitTest(world);
412
- const hoveredSelected = !overHandle && !!hovered && state.selectedIds.includes(hovered);
413
- const hoveredUnselected = !overHandle && !!hovered && !state.selectedIds.includes(hovered) ? hovered : null;
414
- const cursor = resolveHoverCursor({
415
- spaceHeld: this.#spaceHeld,
416
- tool: state.tool,
417
- hoveredUnselectedId: hoveredUnselected,
418
- hoveredSelected,
419
- resizeHandleCursor,
420
- overRotationDot: overDot,
421
- overArrowHandle: !!arrowHandle,
422
- hoverBlockedByLiveWidget: hoveredUnselected ? this.#isHeldByLiveWidget([hoveredUnselected]) : false,
423
- selectionBlockedByLiveWidget: hoveredSelected ? this.#isHeldByLiveWidget(state.selectedIds) : false
424
- });
425
- engine.setHover(hovered && !state.selectedIds.includes(hovered) ? hovered : null);
426
- engine.setRotationDotHover(overDot);
427
- engine.setArrowHandleHover(arrowHandle);
428
- engine.setCursor(cursor);
429
- this.#hoverWidgetCard(overHandle ? null : hitTestLeaf(state.scene, world, { zoom: state.viewport.zoom }));
430
- }
431
- /**
432
- * The host draws the bar of a live widget over its card while the pointer is on it, and the card is picked
433
- * just by pointing at it (the bar and the widget inside take the pointer from there).
434
- */
435
- #hoverWidgetCard(leaf) {
436
- const engine = this.#engine;
437
- const state = engine.state;
438
- const card = leaf && leaf.type === 'widget' && leaf.parentId === null && !state.pending[leaf.id] && !engine.widgetRuntime(leaf.widgetId).orphaned ? leaf : null;
439
- engine.setHoverWidget(card ? card.widgetId : null);
440
- if (!card || state.overlayDragActive || state.editingTextId)
441
- return;
442
- if (!state.selectedIds.includes(card.id))
443
- engine.select([card.id]);
444
345
  }
445
- /** The pointer left the board: nothing is hovered any more. */
446
- pointerLeave() {
447
- this.#lastHover = null;
448
- this.#engine.setHoverWidget(null);
449
- if (!this.#active) {
450
- this.#engine.setHover(null);
451
- this.#engine.setRotationDotHover(false);
452
- this.#engine.setArrowHandleHover(null);
346
+ var doubleClick = __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isDoubleClick).call(this, input);
347
+ __classPrivateFieldSet(this, _PointerController_lastClick, doubleClick ? null : { time: input.time, x: input.x, y: input.y }, "f");
348
+ if (doubleClick && !pickMode && __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_handleDoubleClick).call(this, world))
349
+ return true;
350
+ var unitId = engine.hitTest(world);
351
+ if (pickMode) {
352
+ if (unitId) {
353
+ engine.select([unitId]);
354
+ (_h = (_g = __classPrivateFieldGet(this, _PointerController_options, "f")).onPick) === null || _h === void 0 ? void 0 : _h.call(_g, unitId);
453
355
  }
356
+ return true;
454
357
  }
455
- // ──────────────────────────────────────────────────────── release
456
- pointerUp(input) {
457
- this.#lastInput = input;
458
- this.#pointers.delete(input.pointerId);
459
- if (this.#pinch) {
460
- if (this.#pointers.size < 2)
461
- this.#endPinch();
462
- return;
358
+ // Alt-drag on an object duplicates the selection; Alt-click with no drag steps through the stack.
359
+ if (input.altKey && unitId) {
360
+ if (input.shiftKey) {
361
+ engine.toggleSelection(unitId);
362
+ if (!engine.state.selectedIds.includes(unitId))
363
+ return true;
463
364
  }
464
- if (this.#active && this.#active.pointerId === input.pointerId)
465
- this.#finish('end', input);
365
+ var moving = engine.state.selectedIds.length > 0 ? __spreadArray([], engine.state.selectedIds, true) : [unitId];
366
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createMoveGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, moving, {
367
+ onClick: function () { return __classPrivateFieldGet(_this, _PointerController_instances, "m", _PointerController_drillThrough).call(_this, world); },
368
+ duplicateOnDrag: true,
369
+ immovable: __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isHeldByLiveWidget).call(this, moving)
370
+ }));
371
+ return true;
466
372
  }
467
- pointerCancel(input) {
468
- this.#pointers.delete(input.pointerId);
469
- if (this.#pinch) {
470
- if (this.#pointers.size < 2)
471
- this.#endPinch();
472
- return;
373
+ if (input.altKey && __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_drillThrough).call(this, world))
374
+ return true;
375
+ if (unitId) {
376
+ var wasSelected = engine.state.selectedIds.includes(unitId);
377
+ if (input.shiftKey) {
378
+ engine.toggleSelection(unitId);
379
+ // Taking an object out of the selection is the whole press.
380
+ if (!engine.state.selectedIds.includes(unitId))
381
+ return true;
473
382
  }
474
- if (this.#active && this.#active.pointerId === input.pointerId)
475
- this.#finish('cancel');
476
- }
477
- #forgetStalePointers(now) {
478
- for (const [id, pointer] of this.#pointers) {
479
- if (now - pointer.seenAt > STALE_POINTER_MS)
480
- this.#pointers.delete(id);
383
+ else if (!wasSelected) {
384
+ engine.select([unitId]);
481
385
  }
386
+ var moving = __spreadArray([], engine.state.selectedIds, true);
387
+ // A click on one of several selected objects, without a drag, narrows the selection to it.
388
+ var onClick = !input.shiftKey && wasSelected && moving.length > 1 ? function () { return engine.select([unitId]); } : undefined;
389
+ __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) }));
390
+ return true;
482
391
  }
483
- // ──────────────────────────────────────────────────────── pinch
484
- #pinchGeometry() {
485
- const [first, second] = [...this.#pointers.values()];
486
- if (!first || !second)
487
- return null;
488
- return {
489
- center: { x: (first.x + second.x) / 2, y: (first.y + second.y) / 2 },
490
- distance: Math.max(1, Math.hypot(first.x - second.x, first.y - second.y))
491
- };
392
+ // Empty board. A finger pans (a tap clears the selection); a mouse drags a marquee.
393
+ if (input.pointerType === 'touch') {
394
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createPanGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input, { onTap: function () { return engine.clearSelection(); } }));
395
+ return true;
492
396
  }
493
- #startPinch() {
494
- // Whatever one finger was doing is abandoned.
495
- if (this.#active)
496
- this.#finish('cancel');
497
- const geometry = this.#pinchGeometry();
498
- if (!geometry)
499
- return;
500
- const viewport = this.#engine.state.viewport;
501
- this.#pinch = {
502
- startDistance: geometry.distance,
503
- startZoom: viewport.zoom,
504
- anchorWorld: this.#engine.toWorld(geometry.center)
505
- };
506
- this.#options.onGestureChange?.('pinch');
397
+ if (!input.shiftKey)
398
+ engine.clearSelection();
399
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_begin).call(this, createMarqueeGesture(__classPrivateFieldGet(this, _PointerController_context, "f"), input));
400
+ return true;
401
+ }, _PointerController_drillThrough = function _PointerController_drillThrough(world) {
402
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
403
+ var stack = engine.hitTestStack(world);
404
+ if (stack.length === 0)
405
+ return false;
406
+ var selected = engine.state.selectedIds;
407
+ var current = selected.length === 1 ? selected[0] : null;
408
+ var position = current ? stack.indexOf(current) : -1;
409
+ var next = stack[position <= 0 ? stack.length - 1 : position - 1];
410
+ if (next !== current)
411
+ engine.select([next]);
412
+ return true;
413
+ }, _PointerController_isHeldByLiveWidget = function _PointerController_isHeldByLiveWidget(unitIds) {
414
+ var _this = this;
415
+ var shapes = leafShapesOf(__classPrivateFieldGet(this, _PointerController_engine, "f").state.scene, unitIds);
416
+ return shapes.length > 0 && shapes.every(function (shape) { return shape.type === 'widget' && !__classPrivateFieldGet(_this, _PointerController_engine, "f").widgetRuntime(shape.widgetId).bodyDragAllowed; });
417
+ }, _PointerController_handleDoubleClick = function _PointerController_handleDoubleClick(world) {
418
+ var _a, _b, _c;
419
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
420
+ var state = engine.state;
421
+ var leaf = hitTestLeaf(state.scene, world, { zoom: state.viewport.zoom });
422
+ if (!leaf || state.pending[leaf.id])
423
+ return false;
424
+ if (leaf.type === 'text') {
425
+ if (leaf.parentId)
426
+ engine.enterGroup(leaf.parentId, leaf.id);
427
+ engine.beginTextEdit(leaf.id);
428
+ return true;
507
429
  }
508
- #updatePinch() {
509
- const pinch = this.#pinch;
510
- const geometry = this.#pinchGeometry();
511
- if (!pinch || !geometry)
512
- return;
513
- const zoom = clampZoom(pinch.startZoom * (geometry.distance / pinch.startDistance));
514
- // The world point that was between the fingers stays between them, so the view pans with the hand.
515
- this.#engine.setViewport({
516
- x: geometry.center.x - pinch.anchorWorld.x * zoom,
517
- y: geometry.center.y - pinch.anchorWorld.y * zoom,
518
- zoom
519
- });
430
+ var unitId = engine.hitTest(world);
431
+ var unit = unitId ? engine.getObject(unitId) : undefined;
432
+ if (unit && unit.type === 'group') {
433
+ // Go into the group and pick the member that was double-clicked.
434
+ var index = engine.sceneIndex();
435
+ var member = index.get(leaf.id);
436
+ while (member && member.parentId !== unit.id)
437
+ member = member.parentId ? index.get(member.parentId) : undefined;
438
+ engine.enterGroup(unit.id, (_a = member === null || member === void 0 ? void 0 : member.id) !== null && _a !== void 0 ? _a : leaf.id);
439
+ return true;
520
440
  }
521
- #endPinch() {
522
- if (!this.#pinch)
523
- return;
524
- this.#pinch = null;
525
- this.#options.onGestureChange?.(null);
441
+ if (leaf.type === 'widget') {
442
+ (_c = (_b = __classPrivateFieldGet(this, _PointerController_options, "f")).onActivate) === null || _c === void 0 ? void 0 : _c.call(_b, leaf.id);
443
+ return true;
526
444
  }
527
- // ──────────────────────────────────────────────────────── wheel
528
- /** The wheel (or two fingers on a trackpad) pans; with Ctrl or Meta, which a trackpad pinch also reports, it zooms about the pointer. */
529
- wheel(input) {
530
- const unit = input.deltaMode === 1 ? WHEEL_LINE_PIXELS : input.deltaMode === 2 ? WHEEL_PAGE_PIXELS : 1;
531
- let deltaX = input.deltaX * unit;
532
- let deltaY = input.deltaY * unit;
533
- if (input.ctrlKey || input.metaKey) {
534
- const factor = Math.exp(-clampNumber(deltaY, -60, 60) * 0.01);
535
- this.#engine.zoomAt({ x: input.x, y: input.y }, this.#engine.state.viewport.zoom * factor);
536
- return;
445
+ return false;
446
+ }, _PointerController_hover = function _PointerController_hover(input) {
447
+ var _a, _b, _c;
448
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
449
+ var state = engine.state;
450
+ if (__classPrivateFieldGet(this, _PointerController_spaceHeld, "f") || (state.tool !== 'select' && state.tool !== 'arrow'))
451
+ return;
452
+ 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)
453
+ return;
454
+ __classPrivateFieldSet(this, _PointerController_lastHover, { x: input.x, y: input.y }, "f");
455
+ if (state.tool === 'arrow') {
456
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_hoverArrowTarget).call(this, input);
457
+ return;
458
+ }
459
+ var screenPoint = { x: input.x, y: input.y };
460
+ var overHandle = false;
461
+ var overDot = false;
462
+ var resizeHandleCursor = null;
463
+ var arrowHandle = null;
464
+ if (state.selectedIds.length > 0) {
465
+ var shapes = engine.selectedShapes();
466
+ var arrow = singleArrowOf(shapes, state.selectedIds);
467
+ if (arrow) {
468
+ arrowHandle = hitArrowHandle(arrow, state.viewport, screenPoint, arrowHandleMetricsFor(input.pointerType));
469
+ if (arrowHandle) {
470
+ overHandle = true;
471
+ }
537
472
  }
538
- // A mouse wheel with Shift held scrolls sideways.
539
- if (input.shiftKey && deltaX === 0) {
540
- deltaX = deltaY;
541
- deltaY = 0;
473
+ var frame = arrow ? null : selectionFrameOf(shapes);
474
+ if (frame) {
475
+ 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);
476
+ var hit = hitSelectionHandle(frame, state.viewport, screenPoint, handleMetricsFor(input.pointerType), available);
477
+ if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'resize') {
478
+ resizeHandleCursor = cursorForHandle(hit.handle, frame.rotation);
479
+ overHandle = true;
480
+ }
481
+ else if ((hit === null || hit === void 0 ? void 0 : hit.type) === 'rotate') {
482
+ overDot = hit.source === 'dot';
483
+ overHandle = true;
484
+ }
542
485
  }
543
- this.#engine.panBy(-deltaX, -deltaY);
544
486
  }
545
- }
487
+ var world = engine.toWorld(screenPoint);
488
+ var hovered = overHandle ? null : engine.hitTest(world);
489
+ var hoveredSelected = !overHandle && !!hovered && state.selectedIds.includes(hovered);
490
+ var hoveredUnselected = !overHandle && !!hovered && !state.selectedIds.includes(hovered) ? hovered : null;
491
+ var cursor = resolveHoverCursor({
492
+ spaceHeld: __classPrivateFieldGet(this, _PointerController_spaceHeld, "f"),
493
+ tool: state.tool,
494
+ hoveredUnselectedId: hoveredUnselected,
495
+ hoveredSelected: hoveredSelected,
496
+ resizeHandleCursor: resizeHandleCursor,
497
+ overRotationDot: overDot,
498
+ overArrowHandle: !!arrowHandle,
499
+ hoverBlockedByLiveWidget: hoveredUnselected ? __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isHeldByLiveWidget).call(this, [hoveredUnselected]) : false,
500
+ selectionBlockedByLiveWidget: hoveredSelected ? __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_isHeldByLiveWidget).call(this, state.selectedIds) : false
501
+ });
502
+ engine.setHover(hovered && !state.selectedIds.includes(hovered) ? hovered : null);
503
+ engine.setRotationDotHover(overDot);
504
+ engine.setArrowHandleHover(arrowHandle);
505
+ engine.setCursor(cursor);
506
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_hoverWidgetCard).call(this, overHandle ? null : hitTestLeaf(state.scene, world, { zoom: state.viewport.zoom }));
507
+ }, _PointerController_hoverArrowTarget = function _PointerController_hoverArrowTarget(input) {
508
+ var _a, _b;
509
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
510
+ var world = engine.toWorld({ x: input.x, y: input.y });
511
+ 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);
512
+ var shown = engine.state.overlay.arrowBind;
513
+ var same = hint === null
514
+ ? shown === null
515
+ : shown !== null && shown.targetId === hint.targetId && shown.kind === hint.kind && shown.point.x === hint.point.x && shown.point.y === hint.point.y;
516
+ if (!same)
517
+ engine.setOverlay({ arrowBind: hint });
518
+ }, _PointerController_hoverWidgetCard = function _PointerController_hoverWidgetCard(leaf) {
519
+ var engine = __classPrivateFieldGet(this, _PointerController_engine, "f");
520
+ var state = engine.state;
521
+ var card = leaf && leaf.type === 'widget' && leaf.parentId === null && !state.pending[leaf.id] && !engine.widgetRuntime(leaf.widgetId).orphaned ? leaf : null;
522
+ engine.setHoverWidget(card ? card.widgetId : null);
523
+ if (!card || state.overlayDragActive || state.editingTextId)
524
+ return;
525
+ if (!state.selectedIds.includes(card.id))
526
+ engine.select([card.id]);
527
+ }, _PointerController_forgetStalePointers = function _PointerController_forgetStalePointers(now) {
528
+ for (var _i = 0, _a = __classPrivateFieldGet(this, _PointerController_pointers, "f"); _i < _a.length; _i++) {
529
+ var _b = _a[_i], id = _b[0], pointer = _b[1];
530
+ if (now - pointer.seenAt > STALE_POINTER_MS)
531
+ __classPrivateFieldGet(this, _PointerController_pointers, "f").delete(id);
532
+ }
533
+ }, _PointerController_pinchGeometry = function _PointerController_pinchGeometry() {
534
+ var _a = __spreadArray([], __classPrivateFieldGet(this, _PointerController_pointers, "f").values(), true), first = _a[0], second = _a[1];
535
+ if (!first || !second)
536
+ return null;
537
+ return {
538
+ center: { x: (first.x + second.x) / 2, y: (first.y + second.y) / 2 },
539
+ distance: Math.max(1, Math.hypot(first.x - second.x, first.y - second.y))
540
+ };
541
+ }, _PointerController_startPinch = function _PointerController_startPinch() {
542
+ var _a, _b;
543
+ // Whatever one finger was doing is abandoned.
544
+ if (__classPrivateFieldGet(this, _PointerController_active, "f"))
545
+ __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_finish).call(this, 'cancel');
546
+ var geometry = __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_pinchGeometry).call(this);
547
+ if (!geometry)
548
+ return;
549
+ var viewport = __classPrivateFieldGet(this, _PointerController_engine, "f").state.viewport;
550
+ __classPrivateFieldSet(this, _PointerController_pinch, {
551
+ startDistance: geometry.distance,
552
+ startZoom: viewport.zoom,
553
+ anchorWorld: __classPrivateFieldGet(this, _PointerController_engine, "f").toWorld(geometry.center)
554
+ }, "f");
555
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).onGestureChange) === null || _b === void 0 ? void 0 : _b.call(_a, 'pinch');
556
+ }, _PointerController_updatePinch = function _PointerController_updatePinch() {
557
+ var pinch = __classPrivateFieldGet(this, _PointerController_pinch, "f");
558
+ var geometry = __classPrivateFieldGet(this, _PointerController_instances, "m", _PointerController_pinchGeometry).call(this);
559
+ if (!pinch || !geometry)
560
+ return;
561
+ var zoom = clampZoom(pinch.startZoom * (geometry.distance / pinch.startDistance));
562
+ // The world point that was between the fingers stays between them, so the view pans with the hand.
563
+ __classPrivateFieldGet(this, _PointerController_engine, "f").setViewport({
564
+ x: geometry.center.x - pinch.anchorWorld.x * zoom,
565
+ y: geometry.center.y - pinch.anchorWorld.y * zoom,
566
+ zoom: zoom
567
+ });
568
+ }, _PointerController_endPinch = function _PointerController_endPinch() {
569
+ var _a, _b;
570
+ if (!__classPrivateFieldGet(this, _PointerController_pinch, "f"))
571
+ return;
572
+ __classPrivateFieldSet(this, _PointerController_pinch, null, "f");
573
+ (_b = (_a = __classPrivateFieldGet(this, _PointerController_options, "f")).onGestureChange) === null || _b === void 0 ? void 0 : _b.call(_a, null);
574
+ };