@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
|
@@ -4,30 +4,10 @@
|
|
|
4
4
|
* A gesture changes the scene *transiently* on every move and the engine records one undo step when it ends,
|
|
5
5
|
* so a drag of a hundred frames is one step. `cancel` puts the board back as it was before the press.
|
|
6
6
|
*/
|
|
7
|
-
var __assign = (this && this.__assign) || function () {
|
|
8
|
-
__assign = Object.assign || function(t) {
|
|
9
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
10
|
-
s = arguments[i];
|
|
11
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
12
|
-
t[p] = s[p];
|
|
13
|
-
}
|
|
14
|
-
return t;
|
|
15
|
-
};
|
|
16
|
-
return __assign.apply(this, arguments);
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
7
|
import { arrowPointsInWorld, bendTowards, isArrow, reshapeArrow } from '../core/arrow.js';
|
|
28
8
|
import { pickArrowBinding, positionBoundArrow } from '../core/arrowBinding.js';
|
|
29
9
|
import { bindingOfEnd, releaseUnmovedEnds } from '../core/arrowBindingRecords.js';
|
|
30
|
-
import { buildBrushStroke } from '../core/brush.js';
|
|
10
|
+
import { STRAIGHT_LINE_PRESSURE, buildBrushStroke } from '../core/brush.js';
|
|
31
11
|
import { ARROW_SNAP_DEGREES, MIN_DRAW_DISTANCE, buildDraggedShape, snapPointAround } from '../core/shapeTools.js';
|
|
32
12
|
import { distanceBetween, inflateRect, rectContainsPoint, rectFromPoints, rectsIntersect, unionRects } from '../core/geometry.js';
|
|
33
13
|
import { hitTestLeaf } from '../core/hitTest.js';
|
|
@@ -40,125 +20,118 @@ import { CORNER_HANDLES, ROTATE_CURSOR, cursorForHandle, isCornerHandle } from '
|
|
|
40
20
|
import { fitTextObject } from '../text/layoutText.js';
|
|
41
21
|
import { cursorForTool } from '../EngineCore.js';
|
|
42
22
|
/** A press that moves less than this (screen pixels) is still a click. */
|
|
43
|
-
export
|
|
23
|
+
export const DRAG_THRESHOLD = 3;
|
|
44
24
|
/** How far the eraser reaches, in screen pixels. */
|
|
45
|
-
export
|
|
25
|
+
export const ERASER_RADIUS = 8;
|
|
46
26
|
/** The step a rotation snaps to while Shift (or Ctrl, or Meta) is held, in degrees. */
|
|
47
|
-
export
|
|
27
|
+
export const ROTATION_SNAP_DEGREES = 5;
|
|
48
28
|
/** When true, a text corner resize hides the pointer and draws an arrow on the corner. */
|
|
49
|
-
export
|
|
29
|
+
export const ENABLE_TEXT_VIRTUAL_CURSOR = false;
|
|
50
30
|
/** Objects farther than this from the screen (in screen pixels) are not snapped to. */
|
|
51
|
-
|
|
31
|
+
const SNAP_TARGET_MARGIN = 400;
|
|
52
32
|
function worldOf(context, input) {
|
|
53
33
|
return context.engine.toWorld({ x: input.x, y: input.y });
|
|
54
34
|
}
|
|
55
35
|
/** Puts changed shapes into the scene the gesture started from. */
|
|
56
36
|
function withShapes(scene, shapes) {
|
|
57
|
-
|
|
58
|
-
for (
|
|
59
|
-
var shape = shapes_1[_i];
|
|
37
|
+
const byId = new Map();
|
|
38
|
+
for (const shape of shapes)
|
|
60
39
|
byId.set(shape.id, shape);
|
|
61
|
-
|
|
62
|
-
return scene.map(function (object) { var _a; return (_a = byId.get(object.id)) !== null && _a !== void 0 ? _a : object; });
|
|
40
|
+
return scene.map((object) => byId.get(object.id) ?? object);
|
|
63
41
|
}
|
|
64
42
|
function fitAll(context, shapes) {
|
|
65
|
-
|
|
66
|
-
return shapes.map(
|
|
43
|
+
const measure = context.engine.services.measureText;
|
|
44
|
+
return shapes.map((shape) => (shape.type === 'text' ? fitTextObject(shape, measure) : shape));
|
|
67
45
|
}
|
|
68
46
|
/** The unit (top-level object, or member of the entered group) that holds an object. */
|
|
69
47
|
function unitIdOf(index, id, enteredGroupId) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var seen = new Set();
|
|
48
|
+
let current = index.get(id);
|
|
49
|
+
const seen = new Set();
|
|
73
50
|
while (current && current.parentId !== null && current.parentId !== enteredGroupId && !seen.has(current.id)) {
|
|
74
51
|
seen.add(current.id);
|
|
75
52
|
current = index.get(current.parentId);
|
|
76
53
|
}
|
|
77
|
-
return
|
|
54
|
+
return current?.id ?? id;
|
|
78
55
|
}
|
|
79
56
|
/** The boxes of the other units near the screen: what a moving selection snaps to. */
|
|
80
57
|
function collectSnapTargets(context, movingIds) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
for (
|
|
87
|
-
var object = _a[_i];
|
|
58
|
+
const { engine } = context;
|
|
59
|
+
const state = engine.state;
|
|
60
|
+
const index = engine.sceneIndex();
|
|
61
|
+
const reach = inflateRect(engine.visibleRect(), SNAP_TARGET_MARGIN / state.viewport.zoom);
|
|
62
|
+
const rectsByUnit = new Map();
|
|
63
|
+
for (const object of state.scene) {
|
|
88
64
|
if (object.type === 'group' || state.pending[object.id])
|
|
89
65
|
continue;
|
|
90
|
-
|
|
66
|
+
const unitId = unitIdOf(index, object.id, state.enteredGroupId);
|
|
91
67
|
if (movingIds.has(unitId))
|
|
92
68
|
continue;
|
|
93
|
-
|
|
94
|
-
|
|
69
|
+
const bounds = shapeBounds(object);
|
|
70
|
+
const list = rectsByUnit.get(unitId);
|
|
95
71
|
if (list)
|
|
96
72
|
list.push(bounds);
|
|
97
73
|
else
|
|
98
74
|
rectsByUnit.set(unitId, [bounds]);
|
|
99
75
|
}
|
|
100
|
-
|
|
101
|
-
for (
|
|
102
|
-
|
|
103
|
-
var union = unionRects(rects);
|
|
76
|
+
const targets = [];
|
|
77
|
+
for (const rects of rectsByUnit.values()) {
|
|
78
|
+
const union = unionRects(rects);
|
|
104
79
|
if (union && rectsIntersect(union, reach))
|
|
105
80
|
targets.push(union);
|
|
106
81
|
}
|
|
107
82
|
return targets;
|
|
108
83
|
}
|
|
109
84
|
/** Drags the selected units. Nothing moves until the pointer has gone `DRAG_THRESHOLD` pixels. */
|
|
110
|
-
export function createMoveGesture(context, start, unitIds, options) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var targets = null;
|
|
85
|
+
export function createMoveGesture(context, start, unitIds, options = {}) {
|
|
86
|
+
const { engine } = context;
|
|
87
|
+
let startScene = engine.state.scene;
|
|
88
|
+
const startWorld = worldOf(context, start);
|
|
89
|
+
let moving = new Set(unitIds);
|
|
90
|
+
const startBounds = boundsOfObjects(startScene, unitIds);
|
|
91
|
+
const speed = new PointerSpeedTracker();
|
|
92
|
+
let started = false;
|
|
93
|
+
let duplicated = false;
|
|
94
|
+
let targets = null;
|
|
121
95
|
// The shapes the drag carries, asked once at the first step: the same shapes move at every step, and a step must not
|
|
122
96
|
// walk the board's groups again to find them (a press that never becomes a drag never asks).
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
var lockY = input.shiftKey && !lockX;
|
|
97
|
+
let carried = null;
|
|
98
|
+
let last = start;
|
|
99
|
+
const apply = (input) => {
|
|
100
|
+
const world = worldOf(context, input);
|
|
101
|
+
let deltaX = world.x - startWorld.x;
|
|
102
|
+
let deltaY = world.y - startWorld.y;
|
|
103
|
+
const lockX = input.shiftKey && Math.abs(deltaX) < Math.abs(deltaY);
|
|
104
|
+
const lockY = input.shiftKey && !lockX;
|
|
132
105
|
if (lockX)
|
|
133
106
|
deltaX = 0;
|
|
134
107
|
if (lockY)
|
|
135
108
|
deltaY = 0;
|
|
136
|
-
|
|
109
|
+
let guides = [];
|
|
137
110
|
// Ctrl or Cmd, and G, turn the guides off for as long as they are held: nothing catches the selection, and no guide is drawn.
|
|
138
|
-
|
|
111
|
+
const snapping = (context.options.snapEnabled?.() ?? true) && !input.metaKey && !input.ctrlKey && !(context.guidesSuppressed?.() ?? false);
|
|
139
112
|
speed.update(input.x, input.y, input.time);
|
|
140
113
|
if (snapping && startBounds) {
|
|
141
114
|
if (!targets)
|
|
142
115
|
targets = collectSnapTargets(context, moving);
|
|
143
|
-
|
|
144
|
-
|
|
116
|
+
const reach = snapReachInWorld(engine.state.viewport.zoom, speed.speed);
|
|
117
|
+
const snap = computeMoveSnap({ ...startBounds, x: startBounds.x + deltaX, y: startBounds.y + deltaY }, targets, reach);
|
|
145
118
|
if (!lockX)
|
|
146
119
|
deltaX += snap.deltaX;
|
|
147
120
|
if (!lockY)
|
|
148
121
|
deltaY += snap.deltaY;
|
|
149
|
-
guides = snap.guides.filter(
|
|
122
|
+
guides = snap.guides.filter((guide) => (guide.orientation === 'vertical' ? !lockX : !lockY));
|
|
150
123
|
}
|
|
151
|
-
carried
|
|
124
|
+
carried ??= movingShapeIds(startScene, [...moving]);
|
|
152
125
|
engine.applyScene(translateShapes(startScene, carried, deltaX, deltaY), 'transient');
|
|
153
126
|
// The handles step aside while the selection is carried: what is carried is all that is to be seen. The board is also told
|
|
154
127
|
// what is carried, from which records and how far (`CarriedShapes`), so that it can draw a big selection as one layer and
|
|
155
128
|
// not as a new record for every shape at every step; the records written above are the same, and the engine reads only them.
|
|
156
|
-
engine.setOverlay({ guides
|
|
129
|
+
engine.setOverlay({ guides, dragging: 'move', carry: { startRecords: engine.sceneIndex(startScene), shapeIds: carried, deltaX, deltaY } });
|
|
157
130
|
};
|
|
158
131
|
return {
|
|
159
132
|
kind: 'move',
|
|
160
133
|
pointerId: start.pointerId,
|
|
161
|
-
move
|
|
134
|
+
move(input) {
|
|
162
135
|
last = input;
|
|
163
136
|
if (options.immovable)
|
|
164
137
|
return;
|
|
@@ -171,7 +144,7 @@ export function createMoveGesture(context, start, unitIds, options) {
|
|
|
171
144
|
duplicated = true;
|
|
172
145
|
if (engine.state.selectedIds.length === 0 && unitIds.length > 0)
|
|
173
146
|
engine.select(unitIds);
|
|
174
|
-
|
|
147
|
+
const copyIds = engine.duplicateSelectionForDrag();
|
|
175
148
|
if (copyIds.length > 0) {
|
|
176
149
|
moving = new Set(copyIds);
|
|
177
150
|
startScene = engine.state.scene;
|
|
@@ -181,10 +154,9 @@ export function createMoveGesture(context, start, unitIds, options) {
|
|
|
181
154
|
}
|
|
182
155
|
apply(input);
|
|
183
156
|
},
|
|
184
|
-
end
|
|
185
|
-
var _a;
|
|
157
|
+
end(input) {
|
|
186
158
|
if (!started) {
|
|
187
|
-
|
|
159
|
+
options.onClick?.();
|
|
188
160
|
return;
|
|
189
161
|
}
|
|
190
162
|
last = input;
|
|
@@ -193,19 +165,19 @@ export function createMoveGesture(context, start, unitIds, options) {
|
|
|
193
165
|
engine.commit();
|
|
194
166
|
engine.setCursor(cursorForTool(engine.state.tool));
|
|
195
167
|
},
|
|
196
|
-
cancel
|
|
168
|
+
cancel() {
|
|
197
169
|
if (started)
|
|
198
170
|
engine.revertToCommitted();
|
|
199
171
|
engine.setCursor(cursorForTool(engine.state.tool));
|
|
200
172
|
},
|
|
201
|
-
modifiersChanged
|
|
173
|
+
modifiersChanged(modifiers) {
|
|
202
174
|
// What the keys say is what the next layout of the drag reads too (the one G asks for below), so it is kept with the pointer.
|
|
203
|
-
last =
|
|
175
|
+
last = { ...last, ...modifiers };
|
|
204
176
|
if (started)
|
|
205
177
|
apply(last);
|
|
206
178
|
},
|
|
207
179
|
// G went down or up under a pointer that stays still: the selection is laid out again at once, with the guides or without them.
|
|
208
|
-
guidesSuppressedChanged
|
|
180
|
+
guidesSuppressedChanged() {
|
|
209
181
|
if (started)
|
|
210
182
|
apply(last);
|
|
211
183
|
}
|
|
@@ -214,7 +186,7 @@ export function createMoveGesture(context, start, unitIds, options) {
|
|
|
214
186
|
// ──────────────────────────────────────────────────────────── resize
|
|
215
187
|
/** Where a handle of a frame is in the world. */
|
|
216
188
|
function handlePointOf(frame, handle) {
|
|
217
|
-
|
|
189
|
+
const direction = handleDirection(handle);
|
|
218
190
|
return applyMatrixToPoint(boxToWorldMatrix(frame), {
|
|
219
191
|
x: direction.x === 0 ? frame.width / 2 : direction.x > 0 ? frame.width : 0,
|
|
220
192
|
y: direction.y === 0 ? frame.height / 2 : direction.y > 0 ? frame.height : 0
|
|
@@ -222,12 +194,11 @@ function handlePointOf(frame, handle) {
|
|
|
222
194
|
}
|
|
223
195
|
/** The corner of a frame that is nearest to a point of the world: the one a corner handle dragged to that point is on. */
|
|
224
196
|
function cornerNearestTo(frame, target) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
for (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
var distance = distanceBetween(point, target);
|
|
197
|
+
let nearest = handlePointOf(frame, CORNER_HANDLES[0]);
|
|
198
|
+
let nearestDistance = distanceBetween(nearest, target);
|
|
199
|
+
for (const handle of CORNER_HANDLES.slice(1)) {
|
|
200
|
+
const point = handlePointOf(frame, handle);
|
|
201
|
+
const distance = distanceBetween(point, target);
|
|
231
202
|
if (distance < nearestDistance) {
|
|
232
203
|
nearest = point;
|
|
233
204
|
nearestDistance = distance;
|
|
@@ -237,51 +208,52 @@ function cornerNearestTo(frame, target) {
|
|
|
237
208
|
}
|
|
238
209
|
/** Drags a handle of the selection. Nothing changes until the pointer has gone `DRAG_THRESHOLD` pixels: a press and a double press are not a stretch. */
|
|
239
210
|
export function createResizeGesture(context, start, handle, frame, shapes) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
211
|
+
const { engine } = context;
|
|
212
|
+
const startScene = engine.state.scene;
|
|
213
|
+
const corner = isCornerHandle(handle);
|
|
214
|
+
const single = shapes.length === 1 ? shapes[0] : null;
|
|
244
215
|
// An arrow stretched with these shapes comes off the shapes it is tied to that are not stretched with it.
|
|
245
|
-
|
|
216
|
+
const stretchedIds = new Set(shapes.map((shape) => shape.id));
|
|
246
217
|
// A circle, an icon, a picture and a text keep their proportions when a corner is dragged.
|
|
247
|
-
|
|
218
|
+
const keepsAspect = !!single &&
|
|
248
219
|
(((single.type === 'path' || single.type === 'ellipse') && single.aspectLocked) ||
|
|
249
220
|
(corner && (single.type === 'image' || single.type === 'text')));
|
|
250
221
|
// A text's corner scales its letters, and the box the letters make is not where the hand is. The hand is hidden for the
|
|
251
222
|
// drag and an arrow is drawn on the corner instead, so the person sees what is being held.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
223
|
+
const drawsOwnPointer = ENABLE_TEXT_VIRTUAL_CURSOR && corner && single?.type === 'text';
|
|
224
|
+
const direction = handleDirection(handle);
|
|
225
|
+
const arrowAngle = (Math.atan2(direction.y, direction.x) * 180) / Math.PI + frame.rotation;
|
|
255
226
|
engine.setCursor(cursorForHandle(handle, frame.rotation));
|
|
256
|
-
|
|
257
|
-
|
|
227
|
+
let started = false;
|
|
228
|
+
let last = start;
|
|
258
229
|
// The handle follows the pointer by the distance the press was from it. A handle's target reaches well past the 8 px
|
|
259
230
|
// square that is drawn (more for a finger), and the frame must not jump that far to the pointer on the first move.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
231
|
+
const handleInWorld = handlePointOf(frame, handle);
|
|
232
|
+
const pressInWorld = worldOf(context, start);
|
|
233
|
+
const grabOffset = { x: handleInWorld.x - pressInWorld.x, y: handleInWorld.y - pressInWorld.y };
|
|
234
|
+
const apply = (input) => {
|
|
235
|
+
const pointerInWorld = worldOf(context, input);
|
|
236
|
+
const handleTarget = { x: pointerInWorld.x + grabOffset.x, y: pointerInWorld.y + grabOffset.y };
|
|
237
|
+
const resized = computeResizedFrame(frame, handle, handleTarget, {
|
|
267
238
|
fromCenter: input.altKey,
|
|
268
239
|
keepAspect: input.shiftKey || keepsAspect,
|
|
269
240
|
allowFlip: true
|
|
270
241
|
});
|
|
271
|
-
|
|
242
|
+
const next = fitAll(context, applyFrameResize(shapes, frame, resized, corner)).map((shape) => releaseUnmovedEnds(shape, stretchedIds));
|
|
272
243
|
engine.applyScene(withShapes(startScene, next), 'transient');
|
|
273
|
-
|
|
244
|
+
const after = selectionFrameOf(next);
|
|
274
245
|
engine.setOverlay({
|
|
275
246
|
dragging: 'resize',
|
|
276
247
|
readout: after ? { kind: 'size', width: Math.round(after.width), height: Math.round(after.height) } : null,
|
|
277
248
|
virtualCursor: drawsOwnPointer && after
|
|
278
|
-
?
|
|
249
|
+
? { ...worldToScreen(engine.state.viewport, cornerNearestTo(after, handleTarget)), angle: arrowAngle }
|
|
250
|
+
: null
|
|
279
251
|
});
|
|
280
252
|
};
|
|
281
253
|
return {
|
|
282
254
|
kind: 'resize',
|
|
283
255
|
pointerId: start.pointerId,
|
|
284
|
-
move
|
|
256
|
+
move(input) {
|
|
285
257
|
last = input;
|
|
286
258
|
if (!started) {
|
|
287
259
|
if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
|
|
@@ -292,21 +264,21 @@ export function createResizeGesture(context, start, handle, frame, shapes) {
|
|
|
292
264
|
}
|
|
293
265
|
apply(input);
|
|
294
266
|
},
|
|
295
|
-
end
|
|
267
|
+
end() {
|
|
296
268
|
if (started) {
|
|
297
269
|
engine.clearOverlay();
|
|
298
270
|
engine.commit();
|
|
299
271
|
}
|
|
300
272
|
engine.setCursor(cursorForTool(engine.state.tool));
|
|
301
273
|
},
|
|
302
|
-
cancel
|
|
274
|
+
cancel() {
|
|
303
275
|
if (started)
|
|
304
276
|
engine.revertToCommitted();
|
|
305
277
|
engine.setCursor(cursorForTool(engine.state.tool));
|
|
306
278
|
},
|
|
307
|
-
modifiersChanged
|
|
279
|
+
modifiersChanged(modifiers) {
|
|
308
280
|
if (started)
|
|
309
|
-
apply(
|
|
281
|
+
apply({ ...last, ...modifiers });
|
|
310
282
|
}
|
|
311
283
|
};
|
|
312
284
|
}
|
|
@@ -317,34 +289,33 @@ export function createResizeGesture(context, start, handle, frame, shapes) {
|
|
|
317
289
|
* the pointer has gone `DRAG_THRESHOLD` pixels. `source` is where the press landed: the dot (the pointer is a hand that
|
|
318
290
|
* holds it) or the zone outside a corner (the turning arrow).
|
|
319
291
|
*/
|
|
320
|
-
export function createRotateGesture(context, start, frame, shapes, source) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
var single = shapes.length === 1 ? shapes[0] : null;
|
|
292
|
+
export function createRotateGesture(context, start, frame, shapes, source = 'corner') {
|
|
293
|
+
const { engine } = context;
|
|
294
|
+
const startScene = engine.state.scene;
|
|
295
|
+
const center = frameCenter(frame);
|
|
296
|
+
const startAngle = angleFromCenter(center, worldOf(context, start));
|
|
297
|
+
const single = shapes.length === 1 ? shapes[0] : null;
|
|
327
298
|
// An arrow turned with these shapes comes off the shapes it is tied to that are not turned with it.
|
|
328
|
-
|
|
299
|
+
const turnedIds = new Set(shapes.map((shape) => shape.id));
|
|
329
300
|
engine.setCursor(source === 'dot' ? 'grabbing' : ROTATE_CURSOR);
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
301
|
+
let started = false;
|
|
302
|
+
let last = start;
|
|
303
|
+
const apply = (input) => {
|
|
304
|
+
let delta = angleFromCenter(center, worldOf(context, input)) - startAngle;
|
|
334
305
|
if (input.shiftKey || input.ctrlKey || input.metaKey) {
|
|
335
306
|
delta = single
|
|
336
307
|
? snapAngle(single.rotation + delta, ROTATION_SNAP_DEGREES) - single.rotation
|
|
337
308
|
: snapAngle(delta, ROTATION_SNAP_DEGREES);
|
|
338
309
|
}
|
|
339
|
-
|
|
310
|
+
const turned = rotateShapesAbout(shapes, center, delta).map((shape) => releaseUnmovedEnds(shape, turnedIds));
|
|
340
311
|
engine.applyScene(withShapes(startScene, turned), 'transient');
|
|
341
|
-
|
|
312
|
+
const shown = single ? normalizeDegrees(single.rotation + delta) : normalizeDegrees(delta);
|
|
342
313
|
engine.setOverlay({ dragging: 'rotate', readout: { kind: 'angle', degrees: Math.round(shown) % 360 } });
|
|
343
314
|
};
|
|
344
315
|
return {
|
|
345
316
|
kind: 'rotate',
|
|
346
317
|
pointerId: start.pointerId,
|
|
347
|
-
move
|
|
318
|
+
move(input) {
|
|
348
319
|
last = input;
|
|
349
320
|
if (!started) {
|
|
350
321
|
if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
|
|
@@ -353,21 +324,21 @@ export function createRotateGesture(context, start, frame, shapes, source) {
|
|
|
353
324
|
}
|
|
354
325
|
apply(input);
|
|
355
326
|
},
|
|
356
|
-
end
|
|
327
|
+
end() {
|
|
357
328
|
if (started) {
|
|
358
329
|
engine.clearOverlay();
|
|
359
330
|
engine.commit();
|
|
360
331
|
}
|
|
361
332
|
engine.setCursor(cursorForTool(engine.state.tool));
|
|
362
333
|
},
|
|
363
|
-
cancel
|
|
334
|
+
cancel() {
|
|
364
335
|
if (started)
|
|
365
336
|
engine.revertToCommitted();
|
|
366
337
|
engine.setCursor(cursorForTool(engine.state.tool));
|
|
367
338
|
},
|
|
368
|
-
modifiersChanged
|
|
339
|
+
modifiersChanged(modifiers) {
|
|
369
340
|
if (started)
|
|
370
|
-
apply(
|
|
341
|
+
apply({ ...last, ...modifiers });
|
|
371
342
|
}
|
|
372
343
|
};
|
|
373
344
|
}
|
|
@@ -386,42 +357,41 @@ export function createRotateGesture(context, start, frame, shapes, source) {
|
|
|
386
357
|
* ties it to nothing. The shape the other end is tied to is passed over: the two ends of an arrow are never tied to the same shape.
|
|
387
358
|
*/
|
|
388
359
|
export function createArrowHandleGesture(context, start, arrow, handle) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
360
|
+
const { engine } = context;
|
|
361
|
+
const startScene = engine.state.scene;
|
|
362
|
+
const startPoints = arrowPointsInWorld(arrow);
|
|
363
|
+
const otherEndBinding = handle === 'start' ? bindingOfEnd(arrow.arrow, 'end') : handle === 'end' ? bindingOfEnd(arrow.arrow, 'start') : null;
|
|
364
|
+
const passedOver = otherEndBinding ? new Set([otherEndBinding.targetId]) : undefined;
|
|
365
|
+
const grabbed = handle === 'start' ? startPoints.start : handle === 'end' ? startPoints.end : startPoints.middle;
|
|
366
|
+
const pressWorld = worldOf(context, start);
|
|
396
367
|
// Where the handle is, from where the pointer is: the pointer carries this much of an offset the whole way.
|
|
397
|
-
|
|
368
|
+
const offset = { x: grabbed.x - pressWorld.x, y: grabbed.y - pressWorld.y };
|
|
398
369
|
engine.setCursor('grabbing');
|
|
399
370
|
engine.setArrowHandleHover(handle);
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
var pick = null;
|
|
371
|
+
let started = false;
|
|
372
|
+
let last = start;
|
|
373
|
+
const apply = (input) => {
|
|
374
|
+
const pointer = worldOf(context, input);
|
|
375
|
+
const target = { x: pointer.x + offset.x, y: pointer.y + offset.y };
|
|
376
|
+
let changed;
|
|
377
|
+
let pick = null;
|
|
408
378
|
if (handle === 'bend') {
|
|
409
379
|
changed = reshapeArrow(arrow, { bend: bendTowards(startPoints.start, startPoints.end, target) });
|
|
410
380
|
}
|
|
411
381
|
else {
|
|
412
|
-
|
|
413
|
-
|
|
382
|
+
const fixed = handle === 'start' ? startPoints.end : startPoints.start;
|
|
383
|
+
const moved = input.shiftKey ? snapPointAround(fixed, target, ARROW_SNAP_DEGREES) : target;
|
|
414
384
|
if (!input.altKey && !input.shiftKey) {
|
|
415
385
|
pick = pickArrowBinding(startScene, target, { zoom: engine.state.viewport.zoom, ignore: passedOver });
|
|
416
386
|
}
|
|
417
387
|
// The end is where the hand puts it; the engine draws a tied end from its shape (`reconcileArrowBindings`) in the same step.
|
|
418
|
-
|
|
388
|
+
const change = handle === 'start' ? { start: moved, startBinding: pick?.binding ?? null } : { end: moved, endBinding: pick?.binding ?? null };
|
|
419
389
|
changed = reshapeArrow(arrow, change);
|
|
420
390
|
}
|
|
421
391
|
engine.applyScene(withShapes(startScene, [changed]), 'transient');
|
|
422
|
-
engine.setOverlay({ arrowBind:
|
|
392
|
+
engine.setOverlay({ arrowBind: pick?.hint ?? null });
|
|
423
393
|
};
|
|
424
|
-
|
|
394
|
+
const finish = () => {
|
|
425
395
|
engine.setOverlay({ arrowBind: null });
|
|
426
396
|
engine.setArrowHandleHover(null);
|
|
427
397
|
engine.setCursor(cursorForTool(engine.state.tool));
|
|
@@ -429,7 +399,7 @@ export function createArrowHandleGesture(context, start, arrow, handle) {
|
|
|
429
399
|
return {
|
|
430
400
|
kind: 'arrow-handle',
|
|
431
401
|
pointerId: start.pointerId,
|
|
432
|
-
move
|
|
402
|
+
move(input) {
|
|
433
403
|
last = input;
|
|
434
404
|
if (!started) {
|
|
435
405
|
if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
|
|
@@ -438,41 +408,41 @@ export function createArrowHandleGesture(context, start, arrow, handle) {
|
|
|
438
408
|
}
|
|
439
409
|
apply(input);
|
|
440
410
|
},
|
|
441
|
-
end
|
|
411
|
+
end() {
|
|
442
412
|
if (started)
|
|
443
413
|
engine.commit();
|
|
444
414
|
finish();
|
|
445
415
|
},
|
|
446
|
-
cancel
|
|
416
|
+
cancel() {
|
|
447
417
|
if (started)
|
|
448
418
|
engine.revertToCommitted();
|
|
449
419
|
finish();
|
|
450
420
|
},
|
|
451
|
-
modifiersChanged
|
|
421
|
+
modifiersChanged(modifiers) {
|
|
452
422
|
if (started)
|
|
453
|
-
apply(
|
|
423
|
+
apply({ ...last, ...modifiers });
|
|
454
424
|
}
|
|
455
425
|
};
|
|
456
426
|
}
|
|
457
427
|
// ──────────────────────────────────────────────────────────── marquee
|
|
458
428
|
/** What a marquee that touches nothing hands to the overlay: the one shared empty list. */
|
|
459
|
-
|
|
429
|
+
const NO_UNITS = Object.freeze([]);
|
|
460
430
|
/**
|
|
461
431
|
* Drags a rectangle over the board. While it is dragged, what it touches is outlined the way the unit under the pointer is
|
|
462
432
|
* (the overlay's `marqueeHover`), so the person sees what the release will take; the selection is made at the release, from
|
|
463
433
|
* the same units (added to the ones that were selected when Shift was held at the press).
|
|
464
434
|
*/
|
|
465
435
|
export function createMarqueeGesture(context, start) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
436
|
+
const { engine } = context;
|
|
437
|
+
const startWorld = worldOf(context, start);
|
|
438
|
+
const base = start.shiftKey ? [...engine.state.selectedIds] : [];
|
|
439
|
+
let started = false;
|
|
470
440
|
// The units the marquee takes now. The board is handed the very same list for as long as they are the same units, so a
|
|
471
441
|
// marquee that grows over nothing new wakes nothing (see `erasingMarks.ts`).
|
|
472
|
-
|
|
442
|
+
let wouldSelect = NO_UNITS;
|
|
473
443
|
/** The selection a release at this rectangle would make: made as `select` makes it (a group once, no repeats). */
|
|
474
|
-
|
|
475
|
-
|
|
444
|
+
const selectionFor = (rect) => {
|
|
445
|
+
const units = normalizeSelection(engine.state.scene, [...base, ...engine.hitTestRect(rect, 'intersect')]);
|
|
476
446
|
if (units.length === 0)
|
|
477
447
|
return NO_UNITS;
|
|
478
448
|
return sameIds(units, wouldSelect) ? wouldSelect : units;
|
|
@@ -480,23 +450,23 @@ export function createMarqueeGesture(context, start) {
|
|
|
480
450
|
return {
|
|
481
451
|
kind: 'marquee',
|
|
482
452
|
pointerId: start.pointerId,
|
|
483
|
-
move
|
|
453
|
+
move(input) {
|
|
484
454
|
if (!started) {
|
|
485
455
|
if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
|
|
486
456
|
return;
|
|
487
457
|
started = true;
|
|
488
458
|
}
|
|
489
|
-
|
|
459
|
+
const rect = rectFromPoints(startWorld, worldOf(context, input));
|
|
490
460
|
wouldSelect = selectionFor(rect);
|
|
491
461
|
engine.setOverlay({ marquee: rect, marqueeHover: wouldSelect });
|
|
492
462
|
},
|
|
493
|
-
end
|
|
463
|
+
end(input) {
|
|
494
464
|
// A press that never became a drag selects nothing (it cleared the selection when it began).
|
|
495
465
|
if (started)
|
|
496
466
|
engine.select(selectionFor(rectFromPoints(startWorld, worldOf(context, input))));
|
|
497
467
|
engine.setOverlay({ marquee: null, marqueeHover: NO_UNITS });
|
|
498
468
|
},
|
|
499
|
-
cancel
|
|
469
|
+
cancel() {
|
|
500
470
|
// Nothing was selected while it was dragged, so there is nothing to put back.
|
|
501
471
|
engine.setOverlay({ marquee: null, marqueeHover: NO_UNITS });
|
|
502
472
|
}
|
|
@@ -504,18 +474,17 @@ export function createMarqueeGesture(context, start) {
|
|
|
504
474
|
}
|
|
505
475
|
// ──────────────────────────────────────────────────────────── pan
|
|
506
476
|
/** Drags the view. `onTap` is what a press that never moved does (a finger on empty board clears the selection). */
|
|
507
|
-
export function createPanGesture(context, start, options) {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
var moved = false;
|
|
477
|
+
export function createPanGesture(context, start, options = {}) {
|
|
478
|
+
const { engine } = context;
|
|
479
|
+
let lastX = start.x;
|
|
480
|
+
let lastY = start.y;
|
|
481
|
+
let moved = false;
|
|
513
482
|
engine.setCursor('grabbing');
|
|
514
|
-
|
|
483
|
+
const restore = () => engine.setCursor(cursorForTool(engine.state.tool));
|
|
515
484
|
return {
|
|
516
485
|
kind: 'pan',
|
|
517
486
|
pointerId: start.pointerId,
|
|
518
|
-
move
|
|
487
|
+
move(input) {
|
|
519
488
|
if (!moved && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= DRAG_THRESHOLD)
|
|
520
489
|
moved = true;
|
|
521
490
|
if (!moved)
|
|
@@ -524,116 +493,187 @@ export function createPanGesture(context, start, options) {
|
|
|
524
493
|
lastX = input.x;
|
|
525
494
|
lastY = input.y;
|
|
526
495
|
},
|
|
527
|
-
end
|
|
528
|
-
var _a;
|
|
496
|
+
end() {
|
|
529
497
|
restore();
|
|
530
498
|
if (!moved)
|
|
531
|
-
|
|
499
|
+
options.onTap?.();
|
|
532
500
|
},
|
|
533
501
|
cancel: restore
|
|
534
502
|
};
|
|
535
503
|
}
|
|
536
504
|
// ──────────────────────────────────────────────────────────── ink
|
|
537
505
|
/** A pen whose pressure never moves by more than this has none to report, and draws as a mouse does. */
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
* hand settles at as soon as the hand moves at an ordinary pace. The straight line is then as thick as the lines drawn by hand
|
|
542
|
-
* beside it (a width of 3 is about 3 px on the screen, and not the 6.6 px of a pen pressing at its middle), and as thick at one
|
|
543
|
-
* end as at the other.
|
|
544
|
-
*/
|
|
545
|
-
var STRAIGHT_LINE_PRESSURE = 0;
|
|
506
|
+
const PEN_PRESSURE_SPREAD = 0.02;
|
|
507
|
+
// A point of the line closer than this many screen pixels to the one before it adds nothing the eye can see.
|
|
508
|
+
const MIN_SAMPLE_DISTANCE = 1;
|
|
546
509
|
/**
|
|
547
510
|
* Draws with the brush. The line is as thick as the hand presses: a pen's own pressure, or, for a mouse or a finger, the time the
|
|
548
|
-
* hand spends (a slow stroke swells, a quick one thins).
|
|
549
|
-
*
|
|
550
|
-
*
|
|
511
|
+
* hand spends (a slow stroke swells, a quick one thins). The colour, the width and the opacity of the line are the pen's
|
|
512
|
+
* (`EngineState.penStyle`), which the settings panel sets before a line is drawn.
|
|
513
|
+
*
|
|
514
|
+
* Shift holds the line straight for as long as it is down. The straight stretch begins where the pointer is when the key goes down
|
|
515
|
+
* (what the hand has drawn up to there stays as it is) and runs to the pointer, with the colour and the thickness of the line
|
|
516
|
+
* drawn without Shift: the brush is the same, held at one pressure. When Shift is let go the stretch is kept up to where the
|
|
517
|
+
* pointer was, and the hand goes on drawing from there as before; Shift down again starts another stretch. With Shift down as the
|
|
518
|
+
* press begins the whole line is straight from the point of the press.
|
|
551
519
|
*/
|
|
552
520
|
export function createDrawGesture(context, start) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
521
|
+
const { engine } = context;
|
|
522
|
+
const strokeId = engine.services.createId('obj');
|
|
523
|
+
const isPen = start.pointerType === 'pen';
|
|
556
524
|
// How the line is drawn (its colour, its width, how much of the board shows through it) is the pen as it was set when the press
|
|
557
525
|
// began: a line already being drawn is not changed by a panel that is touched meanwhile.
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
526
|
+
const { color, width: strokeWidth, opacity } = engine.state.penStyle;
|
|
527
|
+
// The points of the line: where the hand went, and the two ends of every stretch that was held straight.
|
|
528
|
+
const samples = [];
|
|
529
|
+
// The stretches held straight, as the indexes of the samples they run between and the pressure each is drawn at.
|
|
530
|
+
const straightStretches = [];
|
|
531
|
+
let leastPressure = Infinity;
|
|
532
|
+
let mostPressure = -Infinity;
|
|
533
|
+
// What a pen has reported since the stretch that is open began, to find the pressure that stretch is held at.
|
|
534
|
+
let stretchPressureTotal = 0;
|
|
535
|
+
let stretchPressureCount = 0;
|
|
536
|
+
// The stretch Shift is holding open: the index of the sample it began at, where that sample is on the screen, and where the
|
|
537
|
+
// pointer is now (in the world, and on the screen). Null while Shift is up.
|
|
538
|
+
let openStretchStart = null;
|
|
539
|
+
let openStretchAnchorScreen = { x: start.x, y: start.y };
|
|
540
|
+
let openStretchEnd = null;
|
|
541
|
+
let openStretchEndScreen = { x: start.x, y: start.y };
|
|
542
|
+
let lastScreen = { x: start.x, y: start.y };
|
|
543
|
+
// Only a pen's pressure means anything: a mouse and a finger report one fixed value while they are down.
|
|
544
|
+
const reportsPressure = (input) => isPen && typeof input.pressure === 'number';
|
|
545
|
+
const notePressure = (input) => {
|
|
546
|
+
leastPressure = Math.min(leastPressure, input.pressure);
|
|
547
|
+
mostPressure = Math.max(mostPressure, input.pressure);
|
|
548
|
+
if (openStretchStart !== null) {
|
|
549
|
+
stretchPressureTotal += input.pressure;
|
|
550
|
+
stretchPressureCount += 1;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
const takeSample = (input) => {
|
|
554
|
+
const world = worldOf(context, input);
|
|
555
|
+
if (reportsPressure(input)) {
|
|
556
|
+
notePressure(input);
|
|
557
|
+
samples.push({ ...world, pressure: input.pressure });
|
|
577
558
|
}
|
|
578
559
|
else {
|
|
579
560
|
samples.push(world);
|
|
580
561
|
}
|
|
581
562
|
};
|
|
582
563
|
takeSample(start);
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
564
|
+
const readsPressure = () => isPen && mostPressure - leastPressure >= PEN_PRESSURE_SPREAD;
|
|
565
|
+
/** The pressure a straight stretch is held at: the pen's own average while the stretch was drawn, or the mouse's usual one. */
|
|
566
|
+
const stretchPressure = () => (readsPressure() && stretchPressureCount > 0 ? stretchPressureTotal / stretchPressureCount : STRAIGHT_LINE_PRESSURE);
|
|
567
|
+
/** How far the open stretch reaches, in pixels of the screen: one with no length draws nothing and is not kept. */
|
|
568
|
+
const openStretchReach = () => Math.hypot(openStretchEndScreen.x - openStretchAnchorScreen.x, openStretchEndScreen.y - openStretchAnchorScreen.y);
|
|
569
|
+
/** Shift goes down: a straight stretch begins where the hand is, at the last point of the line, and follows the pointer from there. */
|
|
570
|
+
const openStretch = () => {
|
|
571
|
+
if (openStretchStart !== null)
|
|
572
|
+
return;
|
|
573
|
+
openStretchStart = samples.length - 1;
|
|
574
|
+
openStretchAnchorScreen = lastScreen;
|
|
575
|
+
openStretchEnd = null;
|
|
576
|
+
openStretchEndScreen = lastScreen;
|
|
577
|
+
// The pen's pressure at the point the stretch begins is the first of the ones it is averaged from.
|
|
578
|
+
const anchorPressure = samples[openStretchStart].pressure;
|
|
579
|
+
stretchPressureTotal = typeof anchorPressure === 'number' ? anchorPressure : 0;
|
|
580
|
+
stretchPressureCount = typeof anchorPressure === 'number' ? 1 : 0;
|
|
581
|
+
};
|
|
582
|
+
/** The open stretch ends at the pointer: from there the hand goes on, and the line keeps the stretch as it was drawn. */
|
|
583
|
+
const closeStretch = () => {
|
|
584
|
+
if (openStretchStart === null)
|
|
585
|
+
return;
|
|
586
|
+
const from = openStretchStart;
|
|
587
|
+
const end = openStretchEnd;
|
|
588
|
+
const reach = openStretchReach();
|
|
589
|
+
const pressure = stretchPressure();
|
|
590
|
+
const endScreen = openStretchEndScreen;
|
|
591
|
+
openStretchStart = null;
|
|
592
|
+
openStretchEnd = null;
|
|
593
|
+
if (!end || reach < MIN_SAMPLE_DISTANCE)
|
|
594
|
+
return;
|
|
595
|
+
samples.push(end);
|
|
596
|
+
straightStretches.push({ from, to: samples.length - 1, pressure });
|
|
597
|
+
lastScreen = endScreen;
|
|
598
|
+
};
|
|
599
|
+
/** The open stretch follows the pointer. Only the position is taken here: the pen's pressure is noted event by event. */
|
|
600
|
+
const followPointer = (input, pressure) => {
|
|
601
|
+
const world = worldOf(context, input);
|
|
602
|
+
openStretchEnd = typeof pressure === 'number' ? { ...world, pressure } : world;
|
|
603
|
+
openStretchEndScreen = { x: input.x, y: input.y };
|
|
604
|
+
};
|
|
605
|
+
if (start.shiftKey)
|
|
606
|
+
openStretch();
|
|
607
|
+
/** The line as it is now: the samples and the stretches, the open one drawn all the way to the pointer. */
|
|
608
|
+
const lineNow = () => {
|
|
609
|
+
if (openStretchStart === null || !openStretchEnd || openStretchReach() < MIN_SAMPLE_DISTANCE)
|
|
610
|
+
return { points: samples, stretches: straightStretches };
|
|
611
|
+
const points = [...samples, openStretchEnd];
|
|
612
|
+
return { points, stretches: [...straightStretches, { from: openStretchStart, to: points.length - 1, pressure: stretchPressure() }] };
|
|
613
|
+
};
|
|
614
|
+
const build = (finished) => {
|
|
588
615
|
// The brush of the lines beside it: a pen that reports its pressure draws with the pen's brush, anything else with the mouse's.
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
var steadyPressure = brushKind === 'pen' && pressureCount > 0 ? pressureTotal / pressureCount : STRAIGHT_LINE_PRESSURE;
|
|
596
|
-
return buildBrushStroke(lineDrawn(), __assign(__assign({}, look), { steadyPressure: steadyPressure }));
|
|
616
|
+
const brushKind = readsPressure() ? 'pen' : 'speed';
|
|
617
|
+
const look = { createId: () => strokeId, color, strokeWidth, opacity, pressure: brushKind, finished };
|
|
618
|
+
// A straight stretch has two ends and an even width (the pen's own average, or the mouse's usual pressure), and it is drawn all
|
|
619
|
+
// the way to the pointer, not trailing behind it as a hand-drawn line does while it is being drawn.
|
|
620
|
+
const { points, stretches } = lineNow();
|
|
621
|
+
return buildBrushStroke(points, { ...look, straightSpans: stretches });
|
|
597
622
|
};
|
|
598
|
-
|
|
623
|
+
const showPreview = () => engine.setOverlay({ preview: build(false) });
|
|
599
624
|
showPreview();
|
|
600
625
|
return {
|
|
601
626
|
kind: 'draw',
|
|
602
627
|
pointerId: start.pointerId,
|
|
603
|
-
move
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
628
|
+
move(input) {
|
|
629
|
+
const moved = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
|
|
630
|
+
if (input.shiftKey) {
|
|
631
|
+
// Shift is down (its key may not have been seen, or comes with this very move): the stretch begins where the line ended
|
|
632
|
+
// at the last move, and follows the pointer. The line takes no points while it is held: the stretch has only two ends.
|
|
633
|
+
openStretch();
|
|
634
|
+
for (const event of moved)
|
|
635
|
+
if (reportsPressure(event))
|
|
636
|
+
notePressure(event);
|
|
637
|
+
followPointer(input, reportsPressure(input) ? input.pressure : undefined);
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
// Shift is up: a stretch that was open ends where the pointer was, and the hand goes on from there.
|
|
641
|
+
closeStretch();
|
|
642
|
+
for (const sample of moved) {
|
|
643
|
+
// A new sample closer than a pixel to the last one adds nothing the eye can see.
|
|
644
|
+
if (Math.hypot(sample.x - lastScreen.x, sample.y - lastScreen.y) < MIN_SAMPLE_DISTANCE)
|
|
645
|
+
continue;
|
|
646
|
+
takeSample(sample);
|
|
647
|
+
lastScreen = { x: sample.x, y: sample.y };
|
|
648
|
+
}
|
|
614
649
|
}
|
|
615
650
|
showPreview();
|
|
616
651
|
},
|
|
617
|
-
end
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
652
|
+
end(input) {
|
|
653
|
+
if (input.shiftKey) {
|
|
654
|
+
// A straight stretch ends where the pointer was let go, even when that is a little beyond the last move (a fast flick).
|
|
655
|
+
// Only the position is taken: a pen reports no pressure once it is lifted, and the stretch holds one pressure anyway.
|
|
656
|
+
openStretch();
|
|
657
|
+
followPointer(input);
|
|
658
|
+
}
|
|
659
|
+
closeStretch();
|
|
660
|
+
const stroke = build(true);
|
|
661
|
+
const { points } = lineNow();
|
|
625
662
|
engine.clearOverlay();
|
|
626
663
|
if (!stroke)
|
|
627
664
|
return;
|
|
628
665
|
engine.addObjects([stroke]);
|
|
629
|
-
|
|
666
|
+
context.options.onStrokeFinished?.(stroke, points);
|
|
630
667
|
},
|
|
631
|
-
cancel
|
|
668
|
+
cancel() {
|
|
632
669
|
engine.clearOverlay();
|
|
633
670
|
},
|
|
634
|
-
modifiersChanged
|
|
635
|
-
straight
|
|
636
|
-
|
|
671
|
+
modifiersChanged(modifiers) {
|
|
672
|
+
// Shift goes down: a straight stretch begins at the pointer. Shift goes up: the stretch ends there, and the hand goes on.
|
|
673
|
+
if (modifiers.shiftKey)
|
|
674
|
+
openStretch();
|
|
675
|
+
else
|
|
676
|
+
closeStretch();
|
|
637
677
|
showPreview();
|
|
638
678
|
}
|
|
639
679
|
};
|
|
@@ -648,60 +688,58 @@ export function createDrawGesture(context, start) {
|
|
|
648
688
|
* default arrow, tied to nothing; the two ends are never tied to the same shape.
|
|
649
689
|
*/
|
|
650
690
|
export function createShapeGesture(context, start, kind, libraryKey) {
|
|
651
|
-
|
|
652
|
-
|
|
691
|
+
const { engine } = context;
|
|
692
|
+
const id = engine.services.createId('obj');
|
|
653
693
|
// One colour for the whole drag: a random fill must not change on every frame.
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
return pickArrowBinding(engine.state.scene, point, { zoom: engine.state.viewport.zoom, ignore: ignore });
|
|
660
|
-
};
|
|
694
|
+
const colorSeed = engine.services.random();
|
|
695
|
+
const startWorld = worldOf(context, start);
|
|
696
|
+
let dragged = false;
|
|
697
|
+
let last = start;
|
|
698
|
+
const pickAt = (point, ignore) => pickArrowBinding(engine.state.scene, point, { zoom: engine.state.viewport.zoom, ignore });
|
|
661
699
|
// The shape the tail of an arrow would be tied to, from the moment of the press.
|
|
662
|
-
|
|
700
|
+
const tailPick = kind === 'arrow' && !start.altKey ? pickAt(startWorld) : null;
|
|
663
701
|
if (tailPick)
|
|
664
702
|
engine.setOverlay({ arrowBind: tailPick.hint });
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
kind: kind,
|
|
703
|
+
const build = (input) => {
|
|
704
|
+
const end = worldOf(context, input);
|
|
705
|
+
const fromCenter = input.altKey && kind !== 'arrow' && dragged;
|
|
706
|
+
const shape = buildDraggedShape({
|
|
707
|
+
kind,
|
|
671
708
|
start: fromCenter ? { x: 2 * startWorld.x - end.x, y: 2 * startWorld.y - end.y } : startWorld,
|
|
672
|
-
end
|
|
709
|
+
end,
|
|
673
710
|
constrain: input.shiftKey,
|
|
674
|
-
dragged
|
|
675
|
-
libraryKey
|
|
711
|
+
dragged,
|
|
712
|
+
libraryKey,
|
|
676
713
|
wireframe: engine.wireframeMode,
|
|
677
|
-
createId:
|
|
678
|
-
random:
|
|
679
|
-
|
|
714
|
+
createId: () => id,
|
|
715
|
+
random: () => colorSeed,
|
|
716
|
+
// What the person last chose for this kind of shape (the preview and the shape kept are made with the same).
|
|
717
|
+
rememberedStyles: engine.rememberedStyles
|
|
680
718
|
});
|
|
681
719
|
if (kind !== 'arrow' || !dragged || input.altKey || shape.type !== 'path' || !isArrow(shape))
|
|
682
|
-
return { shape
|
|
683
|
-
|
|
684
|
-
|
|
720
|
+
return { shape, hint: null };
|
|
721
|
+
const tail = tailPick?.binding;
|
|
722
|
+
const headPick = input.shiftKey ? null : pickAt(end, tail ? new Set([tail.targetId]) : undefined);
|
|
685
723
|
if (!tail && !headPick)
|
|
686
|
-
return { shape
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
return { shape: tied, hint:
|
|
724
|
+
return { shape, hint: null };
|
|
725
|
+
const index = engine.sceneIndex();
|
|
726
|
+
const tied = positionBoundArrow(reshapeArrow(shape, { startBinding: tail ?? null, endBinding: headPick?.binding ?? null }), (targetId) => index.get(targetId));
|
|
727
|
+
return { shape: tied, hint: headPick?.hint ?? null };
|
|
690
728
|
};
|
|
691
729
|
return {
|
|
692
730
|
kind: 'shape',
|
|
693
731
|
pointerId: start.pointerId,
|
|
694
|
-
move
|
|
732
|
+
move(input) {
|
|
695
733
|
last = input;
|
|
696
734
|
if (!dragged && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= MIN_DRAW_DISTANCE)
|
|
697
735
|
dragged = true;
|
|
698
736
|
if (dragged) {
|
|
699
|
-
|
|
737
|
+
const { shape, hint } = build(input);
|
|
700
738
|
engine.setOverlay({ preview: shape, arrowBind: hint });
|
|
701
739
|
}
|
|
702
740
|
},
|
|
703
|
-
end
|
|
704
|
-
|
|
741
|
+
end(input) {
|
|
742
|
+
const { shape } = build(input);
|
|
705
743
|
engine.clearOverlay();
|
|
706
744
|
engine.addObjects([shape]);
|
|
707
745
|
if (engine.state.stickyTool) {
|
|
@@ -712,13 +750,13 @@ export function createShapeGesture(context, start, kind, libraryKey) {
|
|
|
712
750
|
engine.select([shape.id]);
|
|
713
751
|
}
|
|
714
752
|
},
|
|
715
|
-
cancel
|
|
753
|
+
cancel() {
|
|
716
754
|
engine.clearOverlay();
|
|
717
755
|
},
|
|
718
|
-
modifiersChanged
|
|
756
|
+
modifiersChanged(modifiers) {
|
|
719
757
|
if (!dragged)
|
|
720
758
|
return;
|
|
721
|
-
|
|
759
|
+
const { shape, hint } = build({ ...last, ...modifiers });
|
|
722
760
|
engine.setOverlay({ preview: shape, arrowBind: hint });
|
|
723
761
|
}
|
|
724
762
|
};
|
|
@@ -726,35 +764,35 @@ export function createShapeGesture(context, start, kind, libraryKey) {
|
|
|
726
764
|
// ──────────────────────────────────────────────────────────── text
|
|
727
765
|
/** A click makes a label that grows with its text, a drag makes a box of that width. Then the text is edited. */
|
|
728
766
|
export function createTextGesture(context, start) {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
767
|
+
const { engine } = context;
|
|
768
|
+
const startWorld = worldOf(context, start);
|
|
769
|
+
let dragged = false;
|
|
732
770
|
return {
|
|
733
771
|
kind: 'text',
|
|
734
772
|
pointerId: start.pointerId,
|
|
735
|
-
move
|
|
773
|
+
move(input) {
|
|
736
774
|
if (!dragged && distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) >= MIN_DRAW_DISTANCE)
|
|
737
775
|
dragged = true;
|
|
738
776
|
if (dragged)
|
|
739
777
|
engine.setOverlay({ textDraft: rectFromPoints(startWorld, worldOf(context, input)) });
|
|
740
778
|
},
|
|
741
|
-
end
|
|
779
|
+
end(input) {
|
|
742
780
|
engine.setOverlay({ textDraft: null });
|
|
743
781
|
if (!dragged) {
|
|
744
782
|
engine.createText(startWorld);
|
|
745
783
|
return;
|
|
746
784
|
}
|
|
747
|
-
|
|
785
|
+
const rect = rectFromPoints(startWorld, worldOf(context, input));
|
|
748
786
|
engine.createText({ x: rect.x, y: rect.y }, { width: rect.width });
|
|
749
787
|
},
|
|
750
|
-
cancel
|
|
788
|
+
cancel() {
|
|
751
789
|
engine.setOverlay({ textDraft: null });
|
|
752
790
|
}
|
|
753
791
|
};
|
|
754
792
|
}
|
|
755
793
|
// ──────────────────────────────────────────────────────────── eraser
|
|
756
794
|
/** The most spots along one sweep of the eraser that are tested for shapes (a flick across a huge board stays affordable). */
|
|
757
|
-
|
|
795
|
+
const ERASER_MAX_STEPS_PER_SWEEP = 400;
|
|
758
796
|
/**
|
|
759
797
|
* Marks what the pointer passes over and removes it when the pointer is released.
|
|
760
798
|
*
|
|
@@ -766,48 +804,44 @@ var ERASER_MAX_STEPS_PER_SWEEP = 400;
|
|
|
766
804
|
* one by one. A press that does not move marks what lies under it and removes that on release (with Ctrl or Cmd only the top shape).
|
|
767
805
|
*/
|
|
768
806
|
export function createEraseGesture(context, start) {
|
|
769
|
-
|
|
807
|
+
const { engine } = context;
|
|
770
808
|
// The scene stays as it was at the press: nothing is removed until the release.
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
809
|
+
const scene = engine.state.scene;
|
|
810
|
+
const index = engine.sceneIndex(scene);
|
|
811
|
+
const startWorld = worldOf(context, start);
|
|
812
|
+
const zoom = () => engine.state.viewport.zoom;
|
|
813
|
+
const marked = [];
|
|
776
814
|
// What the hit tests look through: the cards that are never erased, and what is marked already.
|
|
777
|
-
|
|
778
|
-
for (
|
|
779
|
-
var object = scene_1[_i];
|
|
815
|
+
const skipped = new Set();
|
|
816
|
+
for (const object of scene) {
|
|
780
817
|
if (object.type === 'widget' || engine.state.pending[object.id])
|
|
781
818
|
skipped.add(object.id);
|
|
782
819
|
}
|
|
783
820
|
// The groups the press began inside of: their members are taken one by one instead of the group as a whole.
|
|
784
|
-
|
|
785
|
-
for (
|
|
786
|
-
var object = scene_2[_a];
|
|
821
|
+
const enteredGroups = new Set();
|
|
822
|
+
for (const object of scene) {
|
|
787
823
|
if (object.type !== 'group')
|
|
788
824
|
continue;
|
|
789
|
-
|
|
825
|
+
const box = boundsOfObjects(scene, [object.id]);
|
|
790
826
|
if (box && rectContainsPoint(box, startWorld))
|
|
791
827
|
enteredGroups.add(object.id);
|
|
792
828
|
}
|
|
793
829
|
/** What goes with a shape: the outermost group above it that the press did not begin inside of, else the shape itself. */
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
var visited = new Set();
|
|
830
|
+
const unitOf = (shapeId) => {
|
|
831
|
+
let unit = index.get(shapeId);
|
|
832
|
+
const visited = new Set();
|
|
798
833
|
while (unit && unit.parentId !== null && !visited.has(unit.id)) {
|
|
799
834
|
visited.add(unit.id);
|
|
800
|
-
|
|
835
|
+
const parent = index.get(unit.parentId);
|
|
801
836
|
if (!parent || enteredGroups.has(parent.id))
|
|
802
837
|
break;
|
|
803
838
|
unit = parent;
|
|
804
839
|
}
|
|
805
|
-
return
|
|
840
|
+
return unit?.id ?? shapeId;
|
|
806
841
|
};
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
for (
|
|
810
|
-
var shape = _a[_i];
|
|
842
|
+
let marksChanged = false;
|
|
843
|
+
const markUnitOf = (shapeId) => {
|
|
844
|
+
for (const shape of leafShapesOf(scene, [unitOf(shapeId)])) {
|
|
811
845
|
if (skipped.has(shape.id))
|
|
812
846
|
continue;
|
|
813
847
|
skipped.add(shape.id);
|
|
@@ -816,10 +850,9 @@ export function createEraseGesture(context, start) {
|
|
|
816
850
|
}
|
|
817
851
|
};
|
|
818
852
|
/** Marks the shapes under a spot (all of them, or only the top one). */
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
var hit = hitTestLeaf(scene, world, { zoom: zoom(), tolerancePixels: ERASER_RADIUS, ignore: skipped });
|
|
853
|
+
const markAt = (world, onlyTop = false) => {
|
|
854
|
+
for (let guard = 0; guard < 64; guard += 1) {
|
|
855
|
+
const hit = hitTestLeaf(scene, world, { zoom: zoom(), tolerancePixels: ERASER_RADIUS, ignore: skipped });
|
|
823
856
|
if (!hit)
|
|
824
857
|
break;
|
|
825
858
|
markUnitOf(hit.id);
|
|
@@ -829,18 +862,18 @@ export function createEraseGesture(context, start) {
|
|
|
829
862
|
break;
|
|
830
863
|
}
|
|
831
864
|
};
|
|
832
|
-
|
|
865
|
+
let lastWorld = startWorld;
|
|
833
866
|
/** Marks what lies along the way from where the eraser was to where it is. */
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
for (
|
|
838
|
-
|
|
867
|
+
const sweepTo = (to) => {
|
|
868
|
+
const screenLength = distanceBetween(lastWorld, to) * zoom();
|
|
869
|
+
const steps = Math.min(ERASER_MAX_STEPS_PER_SWEEP, Math.max(1, Math.ceil(screenLength / (ERASER_RADIUS / 2))));
|
|
870
|
+
for (let step = 1; step <= steps; step += 1) {
|
|
871
|
+
const progress = step / steps;
|
|
839
872
|
markAt({ x: lastWorld.x + (to.x - lastWorld.x) * progress, y: lastWorld.y + (to.y - lastWorld.y) * progress });
|
|
840
873
|
}
|
|
841
874
|
lastWorld = to;
|
|
842
875
|
};
|
|
843
|
-
|
|
876
|
+
const showMarks = () => {
|
|
844
877
|
if (!marksChanged)
|
|
845
878
|
return;
|
|
846
879
|
marksChanged = false;
|
|
@@ -849,8 +882,8 @@ export function createEraseGesture(context, start) {
|
|
|
849
882
|
// The press itself marks what is under it, so a click shows what it is about to remove.
|
|
850
883
|
markAt(startWorld, start.ctrlKey || start.metaKey);
|
|
851
884
|
showMarks();
|
|
852
|
-
|
|
853
|
-
|
|
885
|
+
let dragging = false;
|
|
886
|
+
const beginDragging = () => {
|
|
854
887
|
dragging = true;
|
|
855
888
|
engine.beginScribble();
|
|
856
889
|
// A drag takes everything under the spot where it began, also after a click that took only the top shape.
|
|
@@ -859,22 +892,21 @@ export function createEraseGesture(context, start) {
|
|
|
859
892
|
return {
|
|
860
893
|
kind: 'erase',
|
|
861
894
|
pointerId: start.pointerId,
|
|
862
|
-
move
|
|
895
|
+
move(input) {
|
|
863
896
|
if (!dragging) {
|
|
864
897
|
if (distanceBetween({ x: start.x, y: start.y }, { x: input.x, y: input.y }) < DRAG_THRESHOLD)
|
|
865
898
|
return;
|
|
866
899
|
beginDragging();
|
|
867
900
|
}
|
|
868
|
-
|
|
869
|
-
for (
|
|
870
|
-
|
|
871
|
-
var world = worldOf(context, sample);
|
|
901
|
+
const samples = input.coalesced && input.coalesced.length > 0 ? input.coalesced : [input];
|
|
902
|
+
for (const sample of samples) {
|
|
903
|
+
const world = worldOf(context, sample);
|
|
872
904
|
sweepTo(world);
|
|
873
905
|
engine.extendScribble(world);
|
|
874
906
|
}
|
|
875
907
|
showMarks();
|
|
876
908
|
},
|
|
877
|
-
end
|
|
909
|
+
end(input) {
|
|
878
910
|
// The release can come with a last position no move reported.
|
|
879
911
|
if (dragging)
|
|
880
912
|
sweepTo(worldOf(context, input));
|
|
@@ -883,7 +915,7 @@ export function createEraseGesture(context, start) {
|
|
|
883
915
|
if (marked.length > 0)
|
|
884
916
|
engine.removeObjects(marked);
|
|
885
917
|
},
|
|
886
|
-
cancel
|
|
918
|
+
cancel() {
|
|
887
919
|
engine.stopScribble();
|
|
888
920
|
engine.clearOverlay();
|
|
889
921
|
}
|