@widgetic/canvas 0.5.45 → 0.5.46
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 +1 -1
- 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 -2
- package/dist/canvas/host/CanvasHost.js +1615 -1847
- 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/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/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +21 -21
- 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.js +35 -41
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- 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/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +9 -2
- package/dist/engine/EngineCore.js +798 -907
- 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.js +84 -96
- 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.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +32 -65
- 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.js +267 -310
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +35 -39
- 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.js +28 -30
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +8 -0
- package/dist/settings/workspaceToolSettings.js +35 -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 +11 -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 +2 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Pure function so Node can test the owner's hover rules (item 19).
|
|
4
4
|
*/
|
|
5
5
|
/** The CSS cursor keyword for hovering a canvas object (pointing hand, not an open grab). */
|
|
6
|
-
export
|
|
6
|
+
export const HOVER_SHAPE_CURSOR = 'pointer';
|
|
7
7
|
/**
|
|
8
8
|
* Resolves the board cursor from hover state. Dragging and panning are handled elsewhere; this is idle hover only.
|
|
9
9
|
*/
|
|
@@ -15,7 +15,7 @@ import { QUICK_CAMERA_MOVE_SCALE } from '../core/cameraMove.js';
|
|
|
15
15
|
* `G` is left out on purpose: it hides the alignment guides while it is held (see `routeKeyDown`), so no tool may take it. The
|
|
16
16
|
* triangle has `Y`.
|
|
17
17
|
*/
|
|
18
|
-
export
|
|
18
|
+
export const TOOL_LETTERS = Object.freeze({
|
|
19
19
|
V: 'select',
|
|
20
20
|
E: 'erase',
|
|
21
21
|
D: 'draw',
|
|
@@ -28,7 +28,7 @@ export var TOOL_LETTERS = Object.freeze({
|
|
|
28
28
|
I: 'image'
|
|
29
29
|
});
|
|
30
30
|
/** The tools that are the shapes of the Shapes menu and have a letter: the menu answers these letters while it is open. */
|
|
31
|
-
|
|
31
|
+
const SHAPE_SHORTCUTS = new Set(['rect', 'triangle', 'ellipse']);
|
|
32
32
|
/**
|
|
33
33
|
* The shape that a key press chooses by its letter, or null when the key is not a shape's letter (or is a chord: Ctrl, Cmd and Alt
|
|
34
34
|
* with a letter are the browser's, or the board's own commands, not a tool). The Shapes menu uses it to follow the letters while it
|
|
@@ -39,7 +39,7 @@ export function shapeShortcutOf(input) {
|
|
|
39
39
|
return null;
|
|
40
40
|
if (input.key.length !== 1)
|
|
41
41
|
return null;
|
|
42
|
-
|
|
42
|
+
const tool = TOOL_LETTERS[input.key.toUpperCase()];
|
|
43
43
|
return tool && SHAPE_SHORTCUTS.has(tool) ? tool : null;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
@@ -49,7 +49,7 @@ export function shapeShortcutOf(input) {
|
|
|
49
49
|
* second way to choose a tool: the hints and the list of shortcuts show the letters only, but the toolbar buttons name these
|
|
50
50
|
* numbers in `aria-keyshortcuts` (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
|
|
51
51
|
*/
|
|
52
|
-
export
|
|
52
|
+
export const TOOL_DIGITS = Object.freeze({
|
|
53
53
|
'1': 'select',
|
|
54
54
|
'2': 'draw',
|
|
55
55
|
'3': 'erase',
|
|
@@ -57,21 +57,21 @@ export var TOOL_DIGITS = Object.freeze({
|
|
|
57
57
|
'5': 'text'
|
|
58
58
|
});
|
|
59
59
|
/** The tools that belong to the drawing bar: they are hidden, and so are their letters, when the host turns that bar off. */
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
|
|
61
|
+
const ARROW_STEPS = Object.freeze({
|
|
62
62
|
ArrowUp: [0, -1],
|
|
63
63
|
ArrowDown: [0, 1],
|
|
64
64
|
ArrowLeft: [-1, 0],
|
|
65
65
|
ArrowRight: [1, 0]
|
|
66
66
|
});
|
|
67
67
|
/** The nudge of an arrow key, and of an arrow key with Shift, in world units. */
|
|
68
|
-
export
|
|
69
|
-
export
|
|
68
|
+
export const NUDGE_DISTANCE = 1;
|
|
69
|
+
export const NUDGE_DISTANCE_WITH_SHIFT = 10;
|
|
70
70
|
/** Keys the browser zooms the page with: kept from doing so whatever layout the person has. */
|
|
71
71
|
export function isBrowserZoomKey(input) {
|
|
72
72
|
if (!(input.ctrlKey || input.metaKey))
|
|
73
73
|
return false;
|
|
74
|
-
|
|
74
|
+
const { key, code } = input;
|
|
75
75
|
return (key === '=' ||
|
|
76
76
|
key === '+' ||
|
|
77
77
|
key === '-' ||
|
|
@@ -97,18 +97,17 @@ function selectionExists(engine) {
|
|
|
97
97
|
* it either, and the shell is told for its log. What steers the gesture stays: Escape (leaves it), the modifier keys and Space.
|
|
98
98
|
*/
|
|
99
99
|
function ignoredWhileGesture(input, host) {
|
|
100
|
-
|
|
101
|
-
var gesture = host.controller.gestureKind;
|
|
100
|
+
const gesture = host.controller.gestureKind;
|
|
102
101
|
if (!gesture)
|
|
103
102
|
return false;
|
|
104
103
|
// Told once for the press: a held key repeats, and the repeats are not news.
|
|
105
104
|
if (!input.repeat)
|
|
106
|
-
|
|
105
|
+
host.actions.keyIgnoredDuringGesture?.(input.key, gesture);
|
|
107
106
|
return true;
|
|
108
107
|
}
|
|
109
108
|
/** Escape: leaves whatever is going on, one level at a time. */
|
|
110
109
|
function handleEscape(host) {
|
|
111
|
-
|
|
110
|
+
const { engine, controller, actions } = host;
|
|
112
111
|
if (actions.closePanels())
|
|
113
112
|
return true;
|
|
114
113
|
if (controller.cancelGesture())
|
|
@@ -133,11 +132,11 @@ function handleEscape(host) {
|
|
|
133
132
|
}
|
|
134
133
|
/** Ctrl or Cmd with a key. Returns undefined when the combination is not one of the board's. */
|
|
135
134
|
function handleShortcut(input, host) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
const { engine, controller, actions } = host;
|
|
136
|
+
const key = input.key;
|
|
137
|
+
const lowerKey = key.length === 1 ? key.toLowerCase() : key;
|
|
138
|
+
const editingText = !!engine.state.editingTextId;
|
|
139
|
+
const typing = host.typingInField || editingText;
|
|
141
140
|
// The save and the zoom work wherever the focus is.
|
|
142
141
|
if (lowerKey === 's') {
|
|
143
142
|
actions.save();
|
|
@@ -153,7 +152,7 @@ function handleShortcut(input, host) {
|
|
|
153
152
|
}
|
|
154
153
|
// A jump of the view is left for later while something is being drawn or dragged (the world would move under the pointer), except
|
|
155
154
|
// while the view itself is being panned.
|
|
156
|
-
|
|
155
|
+
const viewJumpIgnored = () => controller.gestureKind !== 'pan' && ignoredWhileGesture(input, host);
|
|
157
156
|
if (key === '0') {
|
|
158
157
|
if (viewJumpIgnored())
|
|
159
158
|
return true;
|
|
@@ -233,7 +232,7 @@ function handleShortcut(input, host) {
|
|
|
233
232
|
// What a drag is doing is not a step yet: the history waits for the release.
|
|
234
233
|
if (controller.gestureKind)
|
|
235
234
|
return true;
|
|
236
|
-
|
|
235
|
+
const redo = input.code === 'KeyY' || input.shiftKey;
|
|
237
236
|
if (redo)
|
|
238
237
|
engine.redo();
|
|
239
238
|
else
|
|
@@ -248,15 +247,15 @@ function handleShortcut(input, host) {
|
|
|
248
247
|
* The bare brackets keep moving one step, as they always did on this board.
|
|
249
248
|
*/
|
|
250
249
|
function handleLayerKey(input, host) {
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
const { engine } = host;
|
|
251
|
+
const forward = input.code === 'BracketRight';
|
|
253
252
|
if (host.typingInField || engine.state.editingTextId)
|
|
254
253
|
return false;
|
|
255
254
|
if (!selectionExists(engine))
|
|
256
255
|
return false;
|
|
257
256
|
if (ignoredWhileGesture(input, host))
|
|
258
257
|
return true;
|
|
259
|
-
|
|
258
|
+
const toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
|
|
260
259
|
engine.reorderSelection(forward ? (toEnd ? 'front' : 'forward') : toEnd ? 'back' : 'backward');
|
|
261
260
|
return true;
|
|
262
261
|
}
|
|
@@ -269,9 +268,8 @@ export function toolIsAvailable(tool, tools) {
|
|
|
269
268
|
* does not also scroll, zoom or select the page.
|
|
270
269
|
*/
|
|
271
270
|
export function routeKeyDown(input, host) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
var key = input.key;
|
|
271
|
+
const { engine, controller, actions } = host;
|
|
272
|
+
const key = input.key;
|
|
275
273
|
if (key === 'Escape')
|
|
276
274
|
return handleEscape(host);
|
|
277
275
|
// The keys that only change what a gesture does while it runs are not answered here: the shell tells the controller.
|
|
@@ -280,11 +278,11 @@ export function routeKeyDown(input, host) {
|
|
|
280
278
|
if (input.code === 'BracketRight' || input.code === 'BracketLeft')
|
|
281
279
|
return handleLayerKey(input, host);
|
|
282
280
|
if (input.ctrlKey || input.metaKey) {
|
|
283
|
-
|
|
281
|
+
const answered = handleShortcut(input, host);
|
|
284
282
|
// A combination that is not ours (Ctrl+R, Ctrl+P) is the browser's.
|
|
285
283
|
return answered === true;
|
|
286
284
|
}
|
|
287
|
-
|
|
285
|
+
const editingText = !!engine.state.editingTextId;
|
|
288
286
|
if (host.typingInField || editingText)
|
|
289
287
|
return false;
|
|
290
288
|
if (input.code === 'Space') {
|
|
@@ -294,7 +292,7 @@ export function routeKeyDown(input, host) {
|
|
|
294
292
|
if (engine.state.tool === 'pan')
|
|
295
293
|
return false;
|
|
296
294
|
controller.setSpaceHeld(true);
|
|
297
|
-
|
|
295
|
+
actions.spacePanChanged?.(true);
|
|
298
296
|
return true;
|
|
299
297
|
}
|
|
300
298
|
// G held: the alignment guides are off for as long as it is down (a drag neither snaps to the other shapes nor shows a guide).
|
|
@@ -305,7 +303,7 @@ export function routeKeyDown(input, host) {
|
|
|
305
303
|
if (input.repeat)
|
|
306
304
|
return true;
|
|
307
305
|
controller.setGuidesSuppressed(true);
|
|
308
|
-
|
|
306
|
+
actions.guidesSuppressedChanged?.(true);
|
|
309
307
|
return true;
|
|
310
308
|
}
|
|
311
309
|
if (key === 'Delete' || key === 'Backspace') {
|
|
@@ -316,7 +314,7 @@ export function routeKeyDown(input, host) {
|
|
|
316
314
|
void engine.deleteSelection();
|
|
317
315
|
return true;
|
|
318
316
|
}
|
|
319
|
-
|
|
317
|
+
const step = ARROW_STEPS[key];
|
|
320
318
|
if (step) {
|
|
321
319
|
if (host.selectorHintOpen)
|
|
322
320
|
return false;
|
|
@@ -324,7 +322,7 @@ export function routeKeyDown(input, host) {
|
|
|
324
322
|
return false;
|
|
325
323
|
if (ignoredWhileGesture(input, host))
|
|
326
324
|
return true;
|
|
327
|
-
|
|
325
|
+
const distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
|
|
328
326
|
engine.nudgeSelection(step[0] * distance, step[1] * distance);
|
|
329
327
|
return true;
|
|
330
328
|
}
|
|
@@ -336,7 +334,7 @@ export function routeKeyDown(input, host) {
|
|
|
336
334
|
return false;
|
|
337
335
|
// A letter chooses its tool, and so does the number of a tool of the drawing bar. This point is only reached when the person is
|
|
338
336
|
// not typing (a field of the page, or a text on the board: both returned above), so a digit written into a text stays a digit.
|
|
339
|
-
|
|
337
|
+
const tool = key.length === 1 ? (TOOL_LETTERS[key.toUpperCase()] ?? TOOL_DIGITS[key]) : undefined;
|
|
340
338
|
if (tool && toolIsAvailable(tool, host.tools)) {
|
|
341
339
|
// A held key repeats, and the tool is already the one it chooses (and the image tool would open its file chooser over and
|
|
342
340
|
// over): only the first press counts. Choosing a tool also clears the selection and the overlay, so a letter pressed while
|
|
@@ -353,27 +351,25 @@ export function routeKeyDown(input, host) {
|
|
|
353
351
|
}
|
|
354
352
|
/** A key was released. Returns whether the board used it. */
|
|
355
353
|
export function routeKeyUp(input, host) {
|
|
356
|
-
var _a, _b, _c, _d;
|
|
357
354
|
if (input.code === 'Space') {
|
|
358
355
|
host.controller.setSpaceHeld(false);
|
|
359
|
-
|
|
356
|
+
host.actions.spacePanChanged?.(false);
|
|
360
357
|
return true;
|
|
361
358
|
}
|
|
362
359
|
// A G that the board is holding is let go; a G that was typed into a field, and never held by the board, is not the board's.
|
|
363
360
|
if (input.code === 'KeyG' && host.controller.guidesSuppressed) {
|
|
364
361
|
host.controller.setGuidesSuppressed(false);
|
|
365
|
-
|
|
362
|
+
host.actions.guidesSuppressedChanged?.(false);
|
|
366
363
|
return true;
|
|
367
364
|
}
|
|
368
365
|
return false;
|
|
369
366
|
}
|
|
370
367
|
/** The window lost the focus: nothing is held any more. */
|
|
371
368
|
export function releaseHeldKeys(host) {
|
|
372
|
-
var _a, _b, _c, _d;
|
|
373
369
|
host.controller.setSpaceHeld(false);
|
|
374
|
-
|
|
370
|
+
host.actions.spacePanChanged?.(false);
|
|
375
371
|
if (host.controller.guidesSuppressed) {
|
|
376
372
|
host.controller.setGuidesSuppressed(false);
|
|
377
|
-
|
|
373
|
+
host.actions.guidesSuppressedChanged?.(false);
|
|
378
374
|
}
|
|
379
375
|
}
|
|
@@ -13,29 +13,29 @@
|
|
|
13
13
|
import { degreesToRadians } from '../core/matrix.js';
|
|
14
14
|
import { handleDirection } from '../core/transform.js';
|
|
15
15
|
import { worldToScreen } from '../core/viewport.js';
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const MOUSE_METRICS = { cornerReach: 10, edgeReach: 13, rotateZone: 22, dotReach: 18 };
|
|
17
|
+
const TOUCH_METRICS = { cornerReach: 22, edgeReach: 20, rotateZone: 40, dotReach: 24 };
|
|
18
18
|
export function handleMetricsFor(pointerType) {
|
|
19
19
|
return pointerType === 'touch' ? TOUCH_METRICS : MOUSE_METRICS;
|
|
20
20
|
}
|
|
21
21
|
/** When false, only the dot under the frame turns the selection (corner zones stay in code but do not hit). */
|
|
22
|
-
export
|
|
22
|
+
export const ENABLE_CORNER_ROTATE_ZONES = false;
|
|
23
23
|
/** How far under the bottom edge of the frame the turning dot rests, to its middle: half an edge handle, 4 px of air, half the grown dot. */
|
|
24
|
-
export
|
|
24
|
+
export const ROTATION_DOT_OFFSET = 21;
|
|
25
25
|
/** The turning dot while nobody is near it: a small handle. */
|
|
26
|
-
export
|
|
26
|
+
export const ROTATION_DOT_REST_SIZE = 8;
|
|
27
27
|
/** The turning dot under the pointer, and while it turns the selection. */
|
|
28
|
-
export
|
|
28
|
+
export const ROTATION_DOT_ACTIVE_SIZE = 24;
|
|
29
29
|
/** A selection thinner than this (screen pixels) has no edge handles: they would cover it, and it could not be moved. */
|
|
30
|
-
export
|
|
31
|
-
export
|
|
32
|
-
export
|
|
30
|
+
export const MIN_EDGE_HANDLE_PIXELS = 16;
|
|
31
|
+
export const ALL_HANDLES = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
|
|
32
|
+
export const CORNER_HANDLES = ['nw', 'ne', 'se', 'sw'];
|
|
33
33
|
/** A text has no top or bottom handle: its height is its lines, so only the corners (which scale the letters) and the sides (which set the width) do anything. */
|
|
34
|
-
export
|
|
34
|
+
export const TEXT_HANDLES = ['nw', 'ne', 'se', 'sw', 'e', 'w'];
|
|
35
35
|
/** Which handles a selection shows, before its size is looked at (`handleAvailability` does that). */
|
|
36
36
|
export function visibleHandles(shapes) {
|
|
37
37
|
if (shapes.length === 1) {
|
|
38
|
-
|
|
38
|
+
const only = shapes[0];
|
|
39
39
|
if ((only.type === 'path' || only.type === 'ellipse') && only.aspectLocked)
|
|
40
40
|
return CORNER_HANDLES;
|
|
41
41
|
if (only.type === 'text')
|
|
@@ -44,14 +44,14 @@ export function visibleHandles(shapes) {
|
|
|
44
44
|
return ALL_HANDLES;
|
|
45
45
|
}
|
|
46
46
|
/** What a selection with nothing special offers. */
|
|
47
|
-
export
|
|
47
|
+
export const FULL_AVAILABILITY = Object.freeze({ handles: ALL_HANDLES, canRotate: true });
|
|
48
48
|
/**
|
|
49
49
|
* Whether the person can turn a selection. Not when a text is in it, alone, among other shapes, or inside a group: a text
|
|
50
50
|
* is read upright, so it has no turning dot under its frame and no turning zone outside its corners (the owner's call, 8 Nov
|
|
51
51
|
* 2026). A text that was saved turned stays as it was saved; nothing here turns it, and nothing turns it back.
|
|
52
52
|
*/
|
|
53
53
|
export function canRotateSelection(shapes) {
|
|
54
|
-
return !shapes.some(
|
|
54
|
+
return !shapes.some((shape) => shape.type === 'text');
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* The handles of a selection. A widget card is plainer while the page's advanced tools are off (its four corners, no
|
|
@@ -59,19 +59,17 @@ export function canRotateSelection(shapes) {
|
|
|
59
59
|
* (`canRotateSelection`). A selection that is thinner than `MIN_EDGE_HANDLE_PIXELS` on the screen (`screenSize`) keeps its
|
|
60
60
|
* corners only.
|
|
61
61
|
*/
|
|
62
|
-
export function handleAvailability(shapes, plainCards, screenSize) {
|
|
63
|
-
if (plainCards === void 0) { plainCards = false; }
|
|
62
|
+
export function handleAvailability(shapes, plainCards = false, screenSize) {
|
|
64
63
|
if (plainCards && shapes.length === 1 && shapes[0].type === 'widget')
|
|
65
64
|
return { handles: CORNER_HANDLES, canRotate: false };
|
|
66
|
-
|
|
65
|
+
let handles = visibleHandles(shapes);
|
|
67
66
|
if (screenSize && Math.min(screenSize.width, screenSize.height) < MIN_EDGE_HANDLE_PIXELS) {
|
|
68
67
|
handles = handles.filter(isCornerHandle);
|
|
69
68
|
}
|
|
70
|
-
return { handles
|
|
69
|
+
return { handles, canRotate: canRotateSelection(shapes) };
|
|
71
70
|
}
|
|
72
71
|
/** The handles of a selection whose frame stands on the board at this zoom: `handleAvailability` with the frame's size on the screen. */
|
|
73
|
-
export function availableHandles(shapes, frame, viewport, plainCards) {
|
|
74
|
-
if (plainCards === void 0) { plainCards = false; }
|
|
72
|
+
export function availableHandles(shapes, frame, viewport, plainCards = false) {
|
|
75
73
|
return handleAvailability(shapes, plainCards, { width: frame.width * viewport.zoom, height: frame.height * viewport.zoom });
|
|
76
74
|
}
|
|
77
75
|
/** Whether a handle sits on a corner of the frame. */
|
|
@@ -80,10 +78,10 @@ export function isCornerHandle(handle) {
|
|
|
80
78
|
}
|
|
81
79
|
/** A point of the screen in the frame's own space: pixels from its centre, with the frame's turn undone. */
|
|
82
80
|
function toFrameSpace(frame, viewport, screenPoint) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const center = worldToScreen(viewport, { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 });
|
|
82
|
+
const radians = -degreesToRadians(frame.rotation);
|
|
83
|
+
const deltaX = screenPoint.x - center.x;
|
|
84
|
+
const deltaY = screenPoint.y - center.y;
|
|
87
85
|
return {
|
|
88
86
|
local: {
|
|
89
87
|
x: deltaX * Math.cos(radians) - deltaY * Math.sin(radians),
|
|
@@ -107,41 +105,39 @@ function innerReach(reach, shortSide) {
|
|
|
107
105
|
* The turning dot comes first (it is drawn above the others), then the corners, then the edges, and last the zone just
|
|
108
106
|
* outside a corner. Nothing is taken for a selection that offers no turning.
|
|
109
107
|
*/
|
|
110
|
-
export function hitSelectionHandle(frame, viewport, screenPoint, metrics, available) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
var shortSide = Math.min(halfWidth, halfHeight) * 2;
|
|
108
|
+
export function hitSelectionHandle(frame, viewport, screenPoint, metrics, available = FULL_AVAILABILITY) {
|
|
109
|
+
const { local, halfWidth, halfHeight } = toFrameSpace(frame, viewport, screenPoint);
|
|
110
|
+
const { handles, canRotate } = available;
|
|
111
|
+
const shortSide = Math.min(halfWidth, halfHeight) * 2;
|
|
115
112
|
// The dot under the bottom edge.
|
|
116
113
|
if (canRotate && Math.abs(local.x) <= metrics.dotReach && Math.abs(local.y - (halfHeight + ROTATION_DOT_OFFSET)) <= metrics.dotReach) {
|
|
117
114
|
return { type: 'rotate', source: 'dot' };
|
|
118
115
|
}
|
|
119
116
|
// The corners: a square that reaches `cornerReach` outside the frame and a little into it. The nearest one wins where squares meet.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
for (
|
|
123
|
-
var handle = handles_1[_i];
|
|
117
|
+
const cornerInner = innerReach(metrics.cornerReach, shortSide);
|
|
118
|
+
let nearest = null;
|
|
119
|
+
for (const handle of handles) {
|
|
124
120
|
if (!isCornerHandle(handle))
|
|
125
121
|
continue;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
const direction = handleDirection(handle);
|
|
123
|
+
const offsetX = local.x - direction.x * halfWidth;
|
|
124
|
+
const offsetY = local.y - direction.y * halfHeight;
|
|
129
125
|
// Positive is out of the frame, on the side the corner points to.
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
const outwardX = offsetX * direction.x;
|
|
127
|
+
const outwardY = offsetY * direction.y;
|
|
132
128
|
if (outwardX > metrics.cornerReach || outwardX < -cornerInner || outwardY > metrics.cornerReach || outwardY < -cornerInner)
|
|
133
129
|
continue;
|
|
134
|
-
|
|
130
|
+
const distance = Math.hypot(offsetX, offsetY);
|
|
135
131
|
if (!nearest || distance < nearest.distance)
|
|
136
|
-
nearest = { handle
|
|
132
|
+
nearest = { handle, distance };
|
|
137
133
|
}
|
|
138
134
|
if (nearest)
|
|
139
135
|
return { type: 'resize', handle: nearest.handle };
|
|
140
136
|
// The edges: a strip along the whole edge, between the corners.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
137
|
+
const edgeInner = innerReach(metrics.edgeReach, shortSide);
|
|
138
|
+
const onEdge = (outward) => outward <= metrics.edgeReach && outward >= -edgeInner;
|
|
139
|
+
const withinWidth = Math.abs(local.x) <= halfWidth;
|
|
140
|
+
const withinHeight = Math.abs(local.y) <= halfHeight;
|
|
145
141
|
if (withinWidth && handles.includes('n') && onEdge(-(local.y + halfHeight)))
|
|
146
142
|
return { type: 'resize', handle: 'n' };
|
|
147
143
|
if (withinWidth && handles.includes('s') && onEdge(local.y - halfHeight))
|
|
@@ -152,9 +148,8 @@ export function hitSelectionHandle(frame, viewport, screenPoint, metrics, availa
|
|
|
152
148
|
return { type: 'resize', handle: 'e' };
|
|
153
149
|
// Just outside a corner the selection turns (optional: the dot below the frame is the main control).
|
|
154
150
|
if (ENABLE_CORNER_ROTATE_ZONES && canRotate && (!withinWidth || !withinHeight)) {
|
|
155
|
-
for (
|
|
156
|
-
|
|
157
|
-
var direction = handleDirection(handle);
|
|
151
|
+
for (const handle of CORNER_HANDLES) {
|
|
152
|
+
const direction = handleDirection(handle);
|
|
158
153
|
if (Math.hypot(local.x - direction.x * halfWidth, local.y - direction.y * halfHeight) <= metrics.rotateZone) {
|
|
159
154
|
return { type: 'rotate', source: 'corner' };
|
|
160
155
|
}
|
|
@@ -164,11 +159,11 @@ export function hitSelectionHandle(frame, viewport, screenPoint, metrics, availa
|
|
|
164
159
|
}
|
|
165
160
|
/** The CSS cursor of a resize handle on a frame turned by `rotation` degrees. */
|
|
166
161
|
export function cursorForHandle(handle, rotation) {
|
|
167
|
-
|
|
168
|
-
|
|
162
|
+
const direction = handleDirection(handle);
|
|
163
|
+
const angle = ((Math.atan2(direction.y, direction.x) * 180) / Math.PI + rotation + 360 * 4) % 180;
|
|
169
164
|
// 0: along x, 45: down-right, 90: along y, 135: down-left, measured on a screen where y grows downward.
|
|
170
|
-
|
|
165
|
+
const step = Math.round(angle / 45) % 4;
|
|
171
166
|
return ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'][step];
|
|
172
167
|
}
|
|
173
168
|
/** The name the board maps to its turning cursor: there is no CSS keyword for it. */
|
|
174
|
-
export
|
|
169
|
+
export const ROTATE_CURSOR = 'rotate';
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* What the input layer exchanges with the shell: plain records, so the whole gesture logic runs in Node tests with
|
|
3
3
|
* simulated pointers and no browser.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export const NO_MODIFIERS = Object.freeze({ shiftKey: false, altKey: false, metaKey: false, ctrlKey: false });
|