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