@widgetic/canvas 0.5.41 → 0.5.43
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 -0
- package/dist/canvas/DomCanvas.svelte +49 -20
- package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
- 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.d.ts +14 -3
- package/dist/canvas/chromeLayout.js +30 -20
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +47 -5
- package/dist/canvas/host/CanvasHost.js +1481 -1566
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/browserServices.js +65 -116
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.d.ts +33 -0
- package/dist/canvas/host/nearCards.js +78 -0
- package/dist/canvas/host/pageEvents.d.ts +16 -4
- package/dist/canvas/host/pageEvents.js +17 -8
- package/dist/canvas/host/pictureSaves.d.ts +33 -0
- package/dist/canvas/host/pictureSaves.js +42 -0
- package/dist/canvas/host/screenRects.d.ts +5 -0
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.d.ts +88 -0
- package/dist/canvas/host/storedPictures.js +288 -0
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/index.js +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.d.ts +45 -2
- package/dist/canvas/shapes/shapeImageStore.js +10 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.d.ts +2 -2
- package/dist/canvas/toolbarPosition.js +4 -4
- package/dist/canvas/ui/SelectionPanel.svelte +28 -5
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
- package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
- package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
- package/dist/canvas/ui/ToolButton.svelte +8 -2
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +2 -2
- package/dist/canvas/ui/floatingCard.js +20 -20
- package/dist/canvas/ui/floatingLayer.d.ts +13 -2
- package/dist/canvas/ui/floatingLayer.js +18 -7
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +34 -40
- package/dist/canvas/view/CanvasStage.svelte +101 -67
- package/dist/canvas/view/LeftToRightScope.svelte +21 -0
- package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
- package/dist/canvas/view/ObjectView.svelte +15 -10
- package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/canvas/view/liftedScene.d.ts +31 -0
- package/dist/canvas/view/liftedScene.js +146 -0
- package/dist/canvas/view/mountedScene.d.ts +71 -0
- package/dist/canvas/view/mountedScene.js +363 -0
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +15 -1
- package/dist/engine/EngineCore.js +724 -797
- package/dist/engine/codec/canvasDocument.d.ts +5 -0
- package/dist/engine/codec/canvasDocument.js +212 -149
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +76 -89
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +67 -94
- package/dist/engine/core/defaults.js +90 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.d.ts +6 -0
- package/dist/engine/core/history.js +49 -50
- 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.d.ts +10 -0
- package/dist/engine/core/scene.js +153 -187
- 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 +31 -64
- package/dist/engine/core/transform.js +83 -94
- package/dist/engine/core/types.d.ts +8 -2
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +467 -474
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +265 -309
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +27 -30
- 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.d.ts +20 -0
- package/dist/engine/state.js +5 -15
- 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.d.ts +10 -1
- package/dist/fonts/interFont.js +47 -75
- package/dist/fonts/workspaceFonts.js +32 -90
- 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 +8 -1
- package/dist/i18n/messages.js +10 -2
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/settings/workspaceToolSettings.js +32 -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 +105 -141
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/types.js +1 -1
- package/package.json +1 -1
- package/dist/canvas/ui/SelectorBar.svelte +0 -84
- package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
|
@@ -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
|
*/
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* tested with a plain record.
|
|
10
10
|
*/
|
|
11
11
|
/** The letter of each tool (the same letters the hints and the list of shortcuts show). */
|
|
12
|
-
export
|
|
12
|
+
export const TOOL_LETTERS = Object.freeze({
|
|
13
13
|
V: 'select',
|
|
14
14
|
E: 'erase',
|
|
15
15
|
D: 'draw',
|
|
@@ -27,7 +27,7 @@ export var TOOL_LETTERS = Object.freeze({
|
|
|
27
27
|
* numpad, so a layout whose number row needs Shift to type a digit reaches the tools as it types the digit. The hints and the
|
|
28
28
|
* list of shortcuts show these same numbers (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
|
|
29
29
|
*/
|
|
30
|
-
export
|
|
30
|
+
export const TOOL_DIGITS = Object.freeze({
|
|
31
31
|
'1': 'select',
|
|
32
32
|
'2': 'draw',
|
|
33
33
|
'3': 'erase',
|
|
@@ -35,21 +35,21 @@ export var TOOL_DIGITS = Object.freeze({
|
|
|
35
35
|
'5': 'text'
|
|
36
36
|
});
|
|
37
37
|
/** The tools that belong to the drawing bar: they are hidden, and so are their letters, when the host turns that bar off. */
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const DRAWING_TOOLS = new Set(['select', 'erase', 'draw', 'arrow', 'text']);
|
|
39
|
+
const ARROW_STEPS = Object.freeze({
|
|
40
40
|
ArrowUp: [0, -1],
|
|
41
41
|
ArrowDown: [0, 1],
|
|
42
42
|
ArrowLeft: [-1, 0],
|
|
43
43
|
ArrowRight: [1, 0]
|
|
44
44
|
});
|
|
45
45
|
/** The nudge of an arrow key, and of an arrow key with Shift, in world units. */
|
|
46
|
-
export
|
|
47
|
-
export
|
|
46
|
+
export const NUDGE_DISTANCE = 1;
|
|
47
|
+
export const NUDGE_DISTANCE_WITH_SHIFT = 10;
|
|
48
48
|
/** Keys the browser zooms the page with: kept from doing so whatever layout the person has. */
|
|
49
49
|
export function isBrowserZoomKey(input) {
|
|
50
50
|
if (!(input.ctrlKey || input.metaKey))
|
|
51
51
|
return false;
|
|
52
|
-
|
|
52
|
+
const { key, code } = input;
|
|
53
53
|
return (key === '=' ||
|
|
54
54
|
key === '+' ||
|
|
55
55
|
key === '-' ||
|
|
@@ -70,7 +70,7 @@ function selectionExists(engine) {
|
|
|
70
70
|
}
|
|
71
71
|
/** Escape: leaves whatever is going on, one level at a time. */
|
|
72
72
|
function handleEscape(host) {
|
|
73
|
-
|
|
73
|
+
const { engine, controller, actions } = host;
|
|
74
74
|
if (actions.closePanels())
|
|
75
75
|
return true;
|
|
76
76
|
if (controller.cancelGesture())
|
|
@@ -95,11 +95,11 @@ function handleEscape(host) {
|
|
|
95
95
|
}
|
|
96
96
|
/** Ctrl or Cmd with a key. Returns undefined when the combination is not one of the board's. */
|
|
97
97
|
function handleShortcut(input, host) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
const { engine, controller, actions } = host;
|
|
99
|
+
const key = input.key;
|
|
100
|
+
const lowerKey = key.length === 1 ? key.toLowerCase() : key;
|
|
101
|
+
const editingText = !!engine.state.editingTextId;
|
|
102
|
+
const typing = host.typingInField || editingText;
|
|
103
103
|
// The save and the zoom work wherever the focus is.
|
|
104
104
|
if (lowerKey === 's') {
|
|
105
105
|
actions.save();
|
|
@@ -172,7 +172,7 @@ function handleShortcut(input, host) {
|
|
|
172
172
|
// What a drag is doing is not a step yet: the history waits for the release.
|
|
173
173
|
if (controller.gestureKind)
|
|
174
174
|
return true;
|
|
175
|
-
|
|
175
|
+
const redo = input.code === 'KeyY' || input.shiftKey;
|
|
176
176
|
if (redo)
|
|
177
177
|
engine.redo();
|
|
178
178
|
else
|
|
@@ -187,13 +187,13 @@ function handleShortcut(input, host) {
|
|
|
187
187
|
* The bare brackets keep moving one step, as they always did on this board.
|
|
188
188
|
*/
|
|
189
189
|
function handleLayerKey(input, host) {
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
const { engine } = host;
|
|
191
|
+
const forward = input.code === 'BracketRight';
|
|
192
192
|
if (host.typingInField || engine.state.editingTextId)
|
|
193
193
|
return false;
|
|
194
194
|
if (!selectionExists(engine))
|
|
195
195
|
return false;
|
|
196
|
-
|
|
196
|
+
const toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
|
|
197
197
|
engine.reorderSelection(forward ? (toEnd ? 'front' : 'forward') : toEnd ? 'back' : 'backward');
|
|
198
198
|
return true;
|
|
199
199
|
}
|
|
@@ -206,9 +206,8 @@ export function toolIsAvailable(tool, tools) {
|
|
|
206
206
|
* does not also scroll, zoom or select the page.
|
|
207
207
|
*/
|
|
208
208
|
export function routeKeyDown(input, host) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
var key = input.key;
|
|
209
|
+
const { engine, controller, actions } = host;
|
|
210
|
+
const key = input.key;
|
|
212
211
|
if (key === 'Escape')
|
|
213
212
|
return handleEscape(host);
|
|
214
213
|
// The keys that only change what a gesture does while it runs are not answered here: the shell tells the controller.
|
|
@@ -217,11 +216,11 @@ export function routeKeyDown(input, host) {
|
|
|
217
216
|
if (input.code === 'BracketRight' || input.code === 'BracketLeft')
|
|
218
217
|
return handleLayerKey(input, host);
|
|
219
218
|
if (input.ctrlKey || input.metaKey) {
|
|
220
|
-
|
|
219
|
+
const answered = handleShortcut(input, host);
|
|
221
220
|
// A combination that is not ours (Ctrl+R, Ctrl+P) is the browser's.
|
|
222
221
|
return answered === true;
|
|
223
222
|
}
|
|
224
|
-
|
|
223
|
+
const editingText = !!engine.state.editingTextId;
|
|
225
224
|
if (host.typingInField || editingText)
|
|
226
225
|
return false;
|
|
227
226
|
if (input.code === 'Space') {
|
|
@@ -231,7 +230,7 @@ export function routeKeyDown(input, host) {
|
|
|
231
230
|
if (engine.state.tool === 'pan')
|
|
232
231
|
return false;
|
|
233
232
|
controller.setSpaceHeld(true);
|
|
234
|
-
|
|
233
|
+
actions.spacePanChanged?.(true);
|
|
235
234
|
return true;
|
|
236
235
|
}
|
|
237
236
|
if (key === 'Delete' || key === 'Backspace') {
|
|
@@ -240,13 +239,13 @@ export function routeKeyDown(input, host) {
|
|
|
240
239
|
void engine.deleteSelection();
|
|
241
240
|
return true;
|
|
242
241
|
}
|
|
243
|
-
|
|
242
|
+
const step = ARROW_STEPS[key];
|
|
244
243
|
if (step) {
|
|
245
244
|
if (host.selectorHintOpen)
|
|
246
245
|
return false;
|
|
247
246
|
if (!selectionExists(engine))
|
|
248
247
|
return false;
|
|
249
|
-
|
|
248
|
+
const distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
|
|
250
249
|
engine.nudgeSelection(step[0] * distance, step[1] * distance);
|
|
251
250
|
return true;
|
|
252
251
|
}
|
|
@@ -258,7 +257,7 @@ export function routeKeyDown(input, host) {
|
|
|
258
257
|
return false;
|
|
259
258
|
// 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
|
|
260
259
|
// 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.
|
|
261
|
-
|
|
260
|
+
const tool = key.length === 1 ? (TOOL_LETTERS[key.toUpperCase()] ?? TOOL_DIGITS[key]) : undefined;
|
|
262
261
|
if (tool && toolIsAvailable(tool, host.tools)) {
|
|
263
262
|
actions.chooseTool(tool);
|
|
264
263
|
return true;
|
|
@@ -267,17 +266,15 @@ export function routeKeyDown(input, host) {
|
|
|
267
266
|
}
|
|
268
267
|
/** A key was released. Returns whether the board used it. */
|
|
269
268
|
export function routeKeyUp(input, host) {
|
|
270
|
-
var _a, _b;
|
|
271
269
|
if (input.code === 'Space') {
|
|
272
270
|
host.controller.setSpaceHeld(false);
|
|
273
|
-
|
|
271
|
+
host.actions.spacePanChanged?.(false);
|
|
274
272
|
return true;
|
|
275
273
|
}
|
|
276
274
|
return false;
|
|
277
275
|
}
|
|
278
276
|
/** The window lost the focus: nothing is held any more. */
|
|
279
277
|
export function releaseHeldKeys(host) {
|
|
280
|
-
var _a, _b;
|
|
281
278
|
host.controller.setSpaceHeld(false);
|
|
282
|
-
|
|
279
|
+
host.actions.spacePanChanged?.(false);
|
|
283
280
|
}
|
|
@@ -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 });
|