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