@widgetic/canvas 0.5.44 → 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/DomCanvas.svelte +52 -3
- package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
- package/dist/canvas/host/CanvasHost.d.ts +74 -3
- package/dist/canvas/host/CanvasHost.js +278 -16
- package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
- package/dist/canvas/host/CanvasHostApi.js +9 -1
- package/dist/canvas/host/boardFiles.d.ts +90 -0
- package/dist/canvas/host/boardFiles.js +139 -0
- package/dist/canvas/host/browserServices.d.ts +17 -0
- package/dist/canvas/host/browserServices.js +58 -0
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
- package/dist/canvas/ui/SelectionPanel.svelte +78 -17
- package/dist/canvas/ui/ShapesMenu.svelte +65 -31
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
- package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
- package/dist/canvas/ui/ToolButton.svelte +34 -55
- package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
- package/dist/canvas/ui/floatingCard.d.ts +26 -4
- package/dist/canvas/ui/floatingCard.js +26 -4
- package/dist/canvas/ui/icons.d.ts +1 -1
- package/dist/canvas/ui/icons.js +1 -1
- package/dist/canvas/ui/selectionTraits.d.ts +12 -0
- package/dist/canvas/ui/selectionTraits.js +26 -1
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
- package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
- package/dist/canvas/view/CanvasStage.svelte +7 -2
- package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
- package/dist/canvas/view/SelectionOverlay.svelte +17 -10
- package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +1 -1
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasBoardPoster.svelte +206 -0
- package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte +129 -0
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +15 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +8 -0
- package/dist/engine/EngineCore.d.ts +46 -4
- package/dist/engine/EngineCore.js +85 -16
- package/dist/engine/codec/canvasDocument.d.ts +7 -0
- package/dist/engine/codec/canvasDocument.js +25 -2
- package/dist/engine/core/arrow.d.ts +18 -8
- package/dist/engine/core/arrow.js +24 -12
- package/dist/engine/core/arrowBinding.d.ts +1 -1
- package/dist/engine/core/arrowBinding.js +10 -3
- package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
- package/dist/engine/core/arrowBindingRecords.js +10 -6
- package/dist/engine/core/brush.d.ts +8 -0
- package/dist/engine/core/brush.js +10 -2
- package/dist/engine/core/cameraMove.d.ts +6 -0
- package/dist/engine/core/cameraMove.js +6 -0
- package/dist/engine/core/defaults.js +2 -0
- package/dist/engine/core/scene.d.ts +22 -0
- package/dist/engine/core/scene.js +86 -1
- package/dist/engine/core/style.d.ts +10 -0
- package/dist/engine/core/style.js +19 -3
- package/dist/engine/core/transform.d.ts +6 -0
- package/dist/engine/core/transform.js +9 -0
- package/dist/engine/core/types.d.ts +7 -0
- package/dist/engine/input/PointerController.d.ts +15 -1
- package/dist/engine/input/PointerController.js +70 -12
- package/dist/engine/input/gestures.d.ts +3 -1
- package/dist/engine/input/gestures.js +41 -10
- package/dist/engine/input/keyboard.d.ts +22 -3
- package/dist/engine/input/keyboard.js +100 -5
- package/dist/engine/input/types.d.ts +7 -0
- package/dist/engine/state.d.ts +18 -0
- package/dist/engine/state.js +10 -0
- package/dist/fonts/workspaceFonts.d.ts +6 -0
- package/dist/fonts/workspaceFonts.js +44 -29
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.js +6 -0
- package/dist/i18n/shortcuts.d.ts +6 -4
- package/dist/i18n/shortcuts.js +16 -12
- package/dist/index.d.ts +2 -1
- package/dist/poster/boardPlacement.d.ts +80 -0
- package/dist/poster/boardPlacement.js +138 -0
- package/dist/poster/boardPoster.d.ts +80 -0
- package/dist/poster/boardPoster.js +226 -0
- package/dist/poster/paintBoardPoster.d.ts +49 -0
- package/dist/poster/paintBoardPoster.js +89 -0
- package/dist/poster/posterPictures.d.ts +32 -0
- package/dist/poster/posterPictures.js +122 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +14 -0
- package/dist/settings/workspaceToolSettings.js +21 -10
- package/dist/tools/definitions.js +26 -4
- package/dist/tools/executors.js +81 -5
- package/dist/tools/hostAdapter.d.ts +5 -1
- package/dist/tools/hostAdapter.js +2 -0
- package/dist/tools/styleArguments.d.ts +35 -0
- package/dist/tools/styleArguments.js +91 -0
- package/dist/tools/types.d.ts +26 -1
- package/dist/tools/types.js +1 -0
- package/package.json +2 -2
|
@@ -204,6 +204,13 @@ export interface ImageObject extends ObjectBase, BoxProps {
|
|
|
204
204
|
/** The reference under which the host's image store keeps the bytes, when they are not inline. */
|
|
205
205
|
imageRef: string | null;
|
|
206
206
|
fileName: string | null;
|
|
207
|
+
/**
|
|
208
|
+
* The id the person's file library (the File Browser of the workspace) knows this picture by, once it is in the library.
|
|
209
|
+
* Null for a picture that only lives on this board. Deleting the picture from the board never touches the library file.
|
|
210
|
+
*/
|
|
211
|
+
libraryFileId: string | null;
|
|
212
|
+
/** Where the library keeps the file (its own address, never the board's bytes). Null while the picture is not in the library. */
|
|
213
|
+
libraryFileUrl: string | null;
|
|
207
214
|
/** The size of the picture itself, to keep its aspect ratio when it is resized. */
|
|
208
215
|
naturalWidth: number;
|
|
209
216
|
naturalHeight: number;
|
|
@@ -19,6 +19,14 @@ export declare class PointerController {
|
|
|
19
19
|
get gestureKind(): string | null;
|
|
20
20
|
/** Space held: a press pans, whatever the tool. */
|
|
21
21
|
setSpaceHeld(held: boolean): void;
|
|
22
|
+
/** Whether G is held: the alignment guides are off while it is. */
|
|
23
|
+
get guidesSuppressed(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* G pressed or let go: the alignment guides are off while it is held, whatever is dragged (a held key can come before the press
|
|
26
|
+
* or in the middle of the drag). A drag that is running takes it up at once, without waiting for the pointer to move: the guides
|
|
27
|
+
* go (and the selection stops being caught by them) when the key goes down, and come back when it is let go.
|
|
28
|
+
*/
|
|
29
|
+
setGuidesSuppressed(suppressed: boolean): void;
|
|
22
30
|
/** Abandons the gesture that is running (Escape). True when there was one. */
|
|
23
31
|
cancelGesture(): boolean;
|
|
24
32
|
/** Shift, Alt, Ctrl or Meta changed while the pointer stayed still. */
|
|
@@ -26,7 +34,13 @@ export declare class PointerController {
|
|
|
26
34
|
dispose(): void;
|
|
27
35
|
/** Handles a press. Returns whether the shell should capture the pointer and keep the browser from acting on it. */
|
|
28
36
|
pointerDown(input: PointerInput): boolean;
|
|
29
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* A right click or a long press: picks the top object under the pointer, unless something that is selected is under it already.
|
|
39
|
+
* The selection stays when the pointer is on one of its objects even if another object lies above that one there: a layer that
|
|
40
|
+
* was reached through the stack (an Alt-click on what is covered, the only way to pick a text under a shape) is still the one the
|
|
41
|
+
* menu is for, and "Bring to front" is what puts it above the rest. Returns the object the menu is for (the selected one under
|
|
42
|
+
* the pointer, else the top one), or null where nothing is under it (the selection is then left as it is).
|
|
43
|
+
*/
|
|
30
44
|
prepareContextMenu(screenPoint: Point): string | null;
|
|
31
45
|
pointerMove(input: PointerInput): void;
|
|
32
46
|
/** The pointer left the board: nothing is hovered any more. */
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* text. Nothing here touches the DOM, so every rule is tested with simulated pointers.
|
|
8
8
|
*/
|
|
9
9
|
import { pickArrowBinding } from '../core/arrowBinding.js';
|
|
10
|
+
import { QUICK_CAMERA_MOVE_SCALE } from '../core/cameraMove.js';
|
|
10
11
|
import { hitTestLeaf } from '../core/hitTest.js';
|
|
11
12
|
import { clampNumber, distanceBetween } from '../core/geometry.js';
|
|
12
13
|
import { leafShapesOf } from '../core/scene.js';
|
|
13
|
-
import { selectionFrameOf } from '../core/transform.js';
|
|
14
|
+
import { frameContains, selectionFrameOf } from '../core/transform.js';
|
|
14
15
|
import { clampZoom } from '../core/viewport.js';
|
|
15
16
|
import { cursorForTool } from '../EngineCore.js';
|
|
16
17
|
import { createArrowHandleGesture, createDrawGesture, createEraseGesture, createMarqueeGesture, createMoveGesture, createPanGesture, createResizeGesture, createRotateGesture, createShapeGesture, createTextGesture } from './gestures.js';
|
|
@@ -33,6 +34,8 @@ export class PointerController {
|
|
|
33
34
|
#pinch = null;
|
|
34
35
|
#pointers = new Map();
|
|
35
36
|
#spaceHeld = false;
|
|
37
|
+
/** G held: the alignment guides are off (a drag neither snaps to the other shapes nor shows a guide). */
|
|
38
|
+
#guidesSuppressed = false;
|
|
36
39
|
#lastClick = null;
|
|
37
40
|
/** The last press on a handle (the turning dot counts as one): a second press on the same one, soon and close, is a double click on it. */
|
|
38
41
|
#lastHandlePress = null;
|
|
@@ -41,7 +44,7 @@ export class PointerController {
|
|
|
41
44
|
constructor(engine, options = {}) {
|
|
42
45
|
this.#engine = engine;
|
|
43
46
|
this.#options = options;
|
|
44
|
-
this.#context = { engine, options };
|
|
47
|
+
this.#context = { engine, options, guidesSuppressed: () => this.#guidesSuppressed };
|
|
45
48
|
}
|
|
46
49
|
/** The kind of gesture that is running, or null. */
|
|
47
50
|
get gestureKind() {
|
|
@@ -57,6 +60,27 @@ export class PointerController {
|
|
|
57
60
|
#cursorWhenIdle() {
|
|
58
61
|
return cursorForTool(this.#engine.state.tool);
|
|
59
62
|
}
|
|
63
|
+
/** Whether G is held: the alignment guides are off while it is. */
|
|
64
|
+
get guidesSuppressed() {
|
|
65
|
+
return this.#guidesSuppressed;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* G pressed or let go: the alignment guides are off while it is held, whatever is dragged (a held key can come before the press
|
|
69
|
+
* or in the middle of the drag). A drag that is running takes it up at once, without waiting for the pointer to move: the guides
|
|
70
|
+
* go (and the selection stops being caught by them) when the key goes down, and come back when it is let go.
|
|
71
|
+
*/
|
|
72
|
+
setGuidesSuppressed(suppressed) {
|
|
73
|
+
if (this.#guidesSuppressed === suppressed)
|
|
74
|
+
return;
|
|
75
|
+
this.#guidesSuppressed = suppressed;
|
|
76
|
+
try {
|
|
77
|
+
this.#active?.guidesSuppressedChanged?.();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// A drag that cannot lay itself out again keeps going on the next move of the pointer; the host is told for its log.
|
|
81
|
+
this.#engine.hooks.onError?.('The drag could not follow the key that turns the guides off', error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
60
84
|
#begin(gesture) {
|
|
61
85
|
this.#active = gesture;
|
|
62
86
|
this.#engine.setHover(null);
|
|
@@ -134,9 +158,10 @@ export class PointerController {
|
|
|
134
158
|
}
|
|
135
159
|
if (input.button !== 0)
|
|
136
160
|
return false;
|
|
137
|
-
// A click on the board ends the typing in a text.
|
|
161
|
+
// A click on the board ends the typing in a text. The empty placeholder that the Text tool put on the board does not end the
|
|
162
|
+
// tool: the press goes on as a press of the Text tool, and puts the text where it landed (a click) or as wide as the drag.
|
|
138
163
|
if (this.#engine.state.editingTextId)
|
|
139
|
-
this.#engine.endTextEdit();
|
|
164
|
+
this.#engine.endTextEdit({ keepPlaceholderTool: true });
|
|
140
165
|
const state = this.#engine.state;
|
|
141
166
|
switch (state.tool) {
|
|
142
167
|
case 'draw':
|
|
@@ -196,6 +221,8 @@ export class PointerController {
|
|
|
196
221
|
const screenPoint = { x: input.x, y: input.y };
|
|
197
222
|
const world = engine.toWorld(screenPoint);
|
|
198
223
|
const pickMode = this.#options.pickMode?.() ?? false;
|
|
224
|
+
// The frame the selection shows, when it shows one: a press inside it, where nothing is drawn, carries the selection (below).
|
|
225
|
+
let selectionFrame = null;
|
|
199
226
|
// The handles of the selection come before whatever lies under them.
|
|
200
227
|
if (!pickMode && engine.state.selectedIds.length > 0) {
|
|
201
228
|
const shapes = engine.selectedShapes();
|
|
@@ -207,6 +234,7 @@ export class PointerController {
|
|
|
207
234
|
return true;
|
|
208
235
|
}
|
|
209
236
|
const frame = arrow ? null : selectionFrameOf(shapes);
|
|
237
|
+
selectionFrame = frame;
|
|
210
238
|
if (frame) {
|
|
211
239
|
const viewport = engine.state.viewport;
|
|
212
240
|
const available = availableHandles(shapes, frame, viewport, this.#options.plainCardChrome?.() ?? false);
|
|
@@ -280,10 +308,21 @@ export class PointerController {
|
|
|
280
308
|
this.#begin(createMoveGesture(this.#context, input, moving, { onClick, immovable: this.#isHeldByLiveWidget(moving) }));
|
|
281
309
|
return true;
|
|
282
310
|
}
|
|
311
|
+
// Nothing that is drawn is under the pointer, but it is inside the frame of the selection: the whole box is what was picked, and
|
|
312
|
+
// not only the line a stroke or a hollow shape is drawn with (a press a little off that line is still a press on the object). The
|
|
313
|
+
// press carries the selection; with no drag it leaves it as it is (the way out is a click outside the frame). Shift on the empty
|
|
314
|
+
// board is a marquee that adds to the selection, so it keeps meaning that; Alt duplicates on the drag, as on an object.
|
|
315
|
+
if (selectionFrame && !input.shiftKey && frameContains(selectionFrame, world)) {
|
|
316
|
+
const moving = [...engine.state.selectedIds];
|
|
317
|
+
this.#begin(createMoveGesture(this.#context, input, moving, { duplicateOnDrag: input.altKey, immovable: this.#isHeldByLiveWidget(moving) }));
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
283
320
|
// Empty board, and this is the second press of a double click (or a double tap): the view eases back to 100%, with the middle of
|
|
284
|
-
// everything that is drawn in the middle of the board. The first press already cleared the selection
|
|
321
|
+
// everything that is drawn in the middle of the board. The first press already cleared the selection (a press inside the frame of
|
|
322
|
+
// the selection is not on the empty board: it is handled above). The ease is a quick one: it answers the person's own double
|
|
323
|
+
// click, so it does not take the time a move that a page asks for takes.
|
|
285
324
|
if (doubleClick) {
|
|
286
|
-
engine.flyToContent();
|
|
325
|
+
engine.flyToContent({ durationScale: QUICK_CAMERA_MOVE_SCALE });
|
|
287
326
|
return true;
|
|
288
327
|
}
|
|
289
328
|
// Empty board. A finger pans (a tap clears the selection); a mouse drags a marquee.
|
|
@@ -348,13 +387,26 @@ export class PointerController {
|
|
|
348
387
|
}
|
|
349
388
|
return false;
|
|
350
389
|
}
|
|
351
|
-
/**
|
|
390
|
+
/**
|
|
391
|
+
* A right click or a long press: picks the top object under the pointer, unless something that is selected is under it already.
|
|
392
|
+
* The selection stays when the pointer is on one of its objects even if another object lies above that one there: a layer that
|
|
393
|
+
* was reached through the stack (an Alt-click on what is covered, the only way to pick a text under a shape) is still the one the
|
|
394
|
+
* menu is for, and "Bring to front" is what puts it above the rest. Returns the object the menu is for (the selected one under
|
|
395
|
+
* the pointer, else the top one), or null where nothing is under it (the selection is then left as it is).
|
|
396
|
+
*/
|
|
352
397
|
prepareContextMenu(screenPoint) {
|
|
353
398
|
const engine = this.#engine;
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
399
|
+
const selectedIds = engine.state.selectedIds;
|
|
400
|
+
// The units under the pointer, the lowest first.
|
|
401
|
+
const stack = engine.hitTestStack(engine.toWorld(screenPoint));
|
|
402
|
+
for (let position = stack.length - 1; position >= 0; position -= 1) {
|
|
403
|
+
if (selectedIds.includes(stack[position]))
|
|
404
|
+
return stack[position];
|
|
405
|
+
}
|
|
406
|
+
const topUnitId = stack.length > 0 ? stack[stack.length - 1] : null;
|
|
407
|
+
if (topUnitId)
|
|
408
|
+
engine.select([topUnitId]);
|
|
409
|
+
return topUnitId;
|
|
358
410
|
}
|
|
359
411
|
// ──────────────────────────────────────────────────────── move
|
|
360
412
|
pointerMove(input) {
|
|
@@ -397,6 +449,8 @@ export class PointerController {
|
|
|
397
449
|
let overDot = false;
|
|
398
450
|
let resizeHandleCursor = null;
|
|
399
451
|
let arrowHandle = null;
|
|
452
|
+
// The frame the selection shows, when it shows one: a press inside it, where nothing is drawn, carries the selection.
|
|
453
|
+
let selectionFrame = null;
|
|
400
454
|
if (state.selectedIds.length > 0) {
|
|
401
455
|
const shapes = engine.selectedShapes();
|
|
402
456
|
const arrow = singleArrowOf(shapes, state.selectedIds);
|
|
@@ -407,6 +461,7 @@ export class PointerController {
|
|
|
407
461
|
}
|
|
408
462
|
}
|
|
409
463
|
const frame = arrow ? null : selectionFrameOf(shapes);
|
|
464
|
+
selectionFrame = frame;
|
|
410
465
|
if (frame) {
|
|
411
466
|
const available = availableHandles(shapes, frame, state.viewport, this.#options.plainCardChrome?.() ?? false);
|
|
412
467
|
const hit = hitSelectionHandle(frame, state.viewport, screenPoint, handleMetricsFor(input.pointerType), available);
|
|
@@ -422,7 +477,10 @@ export class PointerController {
|
|
|
422
477
|
}
|
|
423
478
|
const world = engine.toWorld(screenPoint);
|
|
424
479
|
const hovered = overHandle ? null : engine.hitTest(world);
|
|
425
|
-
|
|
480
|
+
// Inside the frame of the selection with nothing drawn under the pointer is still the selection (a press there carries it, except
|
|
481
|
+
// with Shift, which starts a marquee), so the cursor says so, as it does over a selected object.
|
|
482
|
+
const insideSelectionFrame = !overHandle && !hovered && !input.shiftKey && !!selectionFrame && frameContains(selectionFrame, world);
|
|
483
|
+
const hoveredSelected = insideSelectionFrame || (!overHandle && !!hovered && state.selectedIds.includes(hovered));
|
|
426
484
|
const hoveredUnselected = !overHandle && !!hovered && !state.selectedIds.includes(hovered) ? hovered : null;
|
|
427
485
|
const cursor = resolveHoverCursor({
|
|
428
486
|
spaceHeld: this.#spaceHeld,
|
|
@@ -63,7 +63,9 @@ export declare function createPanGesture(context: GestureContext, start: Pointer
|
|
|
63
63
|
}): Gesture;
|
|
64
64
|
/**
|
|
65
65
|
* 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
|
|
66
|
-
* hand spends (a slow stroke swells, a quick one thins). Shift draws a straight line from where the pointer went down
|
|
66
|
+
* hand spends (a slow stroke swells, a quick one thins). Shift draws a straight line from where the pointer went down to the pointer,
|
|
67
|
+
* with the colour and the thickness of the lines drawn without Shift: the brush is the same, held at one pressure. The colour, the
|
|
68
|
+
* width and the opacity of the line are the pen's (`EngineState.penStyle`), which the settings panel sets before a line is drawn.
|
|
67
69
|
*/
|
|
68
70
|
export declare function createDrawGesture(context: GestureContext, start: PointerInput): Gesture;
|
|
69
71
|
/**
|
|
@@ -107,7 +107,8 @@ export function createMoveGesture(context, start, unitIds, options = {}) {
|
|
|
107
107
|
if (lockY)
|
|
108
108
|
deltaY = 0;
|
|
109
109
|
let guides = [];
|
|
110
|
-
|
|
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.
|
|
111
|
+
const snapping = (context.options.snapEnabled?.() ?? true) && !input.metaKey && !input.ctrlKey && !(context.guidesSuppressed?.() ?? false);
|
|
111
112
|
speed.update(input.x, input.y, input.time);
|
|
112
113
|
if (snapping && startBounds) {
|
|
113
114
|
if (!targets)
|
|
@@ -170,8 +171,15 @@ export function createMoveGesture(context, start, unitIds, options = {}) {
|
|
|
170
171
|
engine.setCursor(cursorForTool(engine.state.tool));
|
|
171
172
|
},
|
|
172
173
|
modifiersChanged(modifiers) {
|
|
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.
|
|
175
|
+
last = { ...last, ...modifiers };
|
|
173
176
|
if (started)
|
|
174
|
-
apply(
|
|
177
|
+
apply(last);
|
|
178
|
+
},
|
|
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.
|
|
180
|
+
guidesSuppressedChanged() {
|
|
181
|
+
if (started)
|
|
182
|
+
apply(last);
|
|
175
183
|
}
|
|
176
184
|
};
|
|
177
185
|
}
|
|
@@ -496,19 +504,32 @@ export function createPanGesture(context, start, options = {}) {
|
|
|
496
504
|
// ──────────────────────────────────────────────────────────── ink
|
|
497
505
|
/** A pen whose pressure never moves by more than this has none to report, and draws as a mouse does. */
|
|
498
506
|
const PEN_PRESSURE_SPREAD = 0.02;
|
|
499
|
-
/**
|
|
500
|
-
|
|
507
|
+
/**
|
|
508
|
+
* The pressure a straight line (Shift) is drawn at when the device reports none (a mouse, a finger): the one a stroke drawn by
|
|
509
|
+
* 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
|
|
510
|
+
* 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
|
|
511
|
+
* end as at the other.
|
|
512
|
+
*/
|
|
513
|
+
const STRAIGHT_LINE_PRESSURE = 0;
|
|
501
514
|
/**
|
|
502
515
|
* 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
|
|
503
|
-
* hand spends (a slow stroke swells, a quick one thins). Shift draws a straight line from where the pointer went down
|
|
516
|
+
* hand spends (a slow stroke swells, a quick one thins). Shift draws a straight line from where the pointer went down to the pointer,
|
|
517
|
+
* with the colour and the thickness of the lines drawn without Shift: the brush is the same, held at one pressure. The colour, the
|
|
518
|
+
* width and the opacity of the line are the pen's (`EngineState.penStyle`), which the settings panel sets before a line is drawn.
|
|
504
519
|
*/
|
|
505
520
|
export function createDrawGesture(context, start) {
|
|
506
521
|
const { engine } = context;
|
|
507
522
|
const strokeId = engine.services.createId('obj');
|
|
508
523
|
const isPen = start.pointerType === 'pen';
|
|
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
|
|
525
|
+
// began: a line already being drawn is not changed by a panel that is touched meanwhile.
|
|
526
|
+
const { color, width: strokeWidth, opacity } = engine.state.penStyle;
|
|
509
527
|
const samples = [];
|
|
510
528
|
let leastPressure = Infinity;
|
|
511
529
|
let mostPressure = -Infinity;
|
|
530
|
+
// What a pen has reported so far, to find the pressure a straight line is held at.
|
|
531
|
+
let pressureTotal = 0;
|
|
532
|
+
let pressureCount = 0;
|
|
512
533
|
let straight = start.shiftKey;
|
|
513
534
|
let lastScreen = { x: start.x, y: start.y };
|
|
514
535
|
let lastInput = start;
|
|
@@ -518,6 +539,8 @@ export function createDrawGesture(context, start) {
|
|
|
518
539
|
if (isPen && typeof input.pressure === 'number') {
|
|
519
540
|
leastPressure = Math.min(leastPressure, input.pressure);
|
|
520
541
|
mostPressure = Math.max(mostPressure, input.pressure);
|
|
542
|
+
pressureTotal += input.pressure;
|
|
543
|
+
pressureCount += 1;
|
|
521
544
|
samples.push({ ...world, pressure: input.pressure });
|
|
522
545
|
}
|
|
523
546
|
else {
|
|
@@ -530,11 +553,15 @@ export function createDrawGesture(context, start) {
|
|
|
530
553
|
/** The line the hand drew: the samples, or just their two ends when Shift holds it straight. */
|
|
531
554
|
const lineDrawn = () => (isStraight() ? [samples[0], samples[samples.length - 1]] : samples);
|
|
532
555
|
const build = (finished) => {
|
|
533
|
-
//
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
556
|
+
// 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.
|
|
557
|
+
const brushKind = readsPressure() ? 'pen' : 'speed';
|
|
558
|
+
const look = { createId: () => strokeId, color, strokeWidth, opacity, pressure: brushKind, finished };
|
|
559
|
+
if (!isStraight())
|
|
560
|
+
return buildBrushStroke(samples, look);
|
|
561
|
+
// A straight line has two ends and an even width: one pressure all along (the pen's own average, or the mouse's usual one), and
|
|
562
|
+
// it is drawn all the way to the pointer, not trailing behind it as a hand-drawn line does while it is being drawn.
|
|
563
|
+
const steadyPressure = brushKind === 'pen' && pressureCount > 0 ? pressureTotal / pressureCount : STRAIGHT_LINE_PRESSURE;
|
|
564
|
+
return buildBrushStroke(lineDrawn(), { ...look, steadyPressure });
|
|
538
565
|
};
|
|
539
566
|
const showPreview = () => engine.setOverlay({ preview: build(false) });
|
|
540
567
|
showPreview();
|
|
@@ -556,6 +583,10 @@ export function createDrawGesture(context, start) {
|
|
|
556
583
|
},
|
|
557
584
|
end(input) {
|
|
558
585
|
straight = input.shiftKey;
|
|
586
|
+
// A straight line ends where the pointer was let go, even when that is a little beyond the last move (a fast flick). Only the
|
|
587
|
+
// position is taken: a pen reports no pressure once it is lifted, and the line holds one pressure anyway.
|
|
588
|
+
if (isStraight() && Math.hypot(input.x - lastScreen.x, input.y - lastScreen.y) >= 1)
|
|
589
|
+
takeSample({ x: input.x, y: input.y });
|
|
559
590
|
const stroke = build(true);
|
|
560
591
|
engine.clearOverlay();
|
|
561
592
|
if (!stroke)
|
|
@@ -24,13 +24,25 @@ export interface KeyInput {
|
|
|
24
24
|
}
|
|
25
25
|
/** A tool that has a letter. The frame and video tools are gone with the objects they made. */
|
|
26
26
|
export type ToolShortcut = 'select' | 'erase' | 'draw' | 'pan' | 'arrow' | 'rect' | 'triangle' | 'ellipse' | 'text' | 'image';
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* The letter of each tool (the same letters the hints and the list of shortcuts show).
|
|
29
|
+
*
|
|
30
|
+
* `G` is left out on purpose: it hides the alignment guides while it is held (see `routeKeyDown`), so no tool may take it. The
|
|
31
|
+
* triangle has `Y`.
|
|
32
|
+
*/
|
|
28
33
|
export declare const TOOL_LETTERS: Readonly<Record<string, ToolShortcut>>;
|
|
34
|
+
/**
|
|
35
|
+
* 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
|
|
36
|
+
* 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
|
|
37
|
+
* is open, since the board's own keys are not answered inside a menu.
|
|
38
|
+
*/
|
|
39
|
+
export declare function shapeShortcutOf(input: Pick<KeyInput, 'key' | 'altKey' | 'metaKey' | 'ctrlKey'>): ToolShortcut | null;
|
|
29
40
|
/**
|
|
30
41
|
* The number of each tool of the drawing bar, in the order the bar lists them (select, draw, erase, arrow, text): the
|
|
31
42
|
* digits 1 to 5 choose them, besides their letters. A digit is the one the person types (`key`), on the number row or on the
|
|
32
|
-
* numpad, so a layout whose number row needs Shift to type a digit reaches the tools as it types the digit. The
|
|
33
|
-
*
|
|
43
|
+
* numpad, so a layout whose number row needs Shift to type a digit reaches the tools as it types the digit. The numbers are the
|
|
44
|
+
* second way to choose a tool: the hints and the list of shortcuts show the letters only, but the toolbar buttons name these
|
|
45
|
+
* numbers in `aria-keyshortcuts` (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
|
|
34
46
|
*/
|
|
35
47
|
export declare const TOOL_DIGITS: Readonly<Record<string, ToolShortcut>>;
|
|
36
48
|
/** What the shell does that the engine does not: the things outside the board. */
|
|
@@ -47,6 +59,13 @@ export interface KeyboardActions {
|
|
|
47
59
|
afterCopy(): void;
|
|
48
60
|
/** The person pressed Space to pan: the shell shows the grid while it is held. */
|
|
49
61
|
spacePanChanged?(held: boolean): void;
|
|
62
|
+
/** The person pressed G (`held`) or let it go: the alignment guides are off while it is held. Told once for the press, for the shell's log. */
|
|
63
|
+
guidesSuppressedChanged?(held: boolean): void;
|
|
64
|
+
/**
|
|
65
|
+
* A key that would change what a gesture works on was taken and left unanswered on purpose, because the pointer is drawing or
|
|
66
|
+
* dragging something (`gesture` is the kind of gesture). Told once for a press, not for the repeats of a held key, for the shell's log.
|
|
67
|
+
*/
|
|
68
|
+
keyIgnoredDuringGesture?(key: string, gesture: string): void;
|
|
50
69
|
}
|
|
51
70
|
export interface KeyboardHost {
|
|
52
71
|
engine: EngineCore;
|
|
@@ -8,7 +8,13 @@
|
|
|
8
8
|
* of each tool, and the number of each tool of the drawing bar); they live here, apart from the DOM, so each one is
|
|
9
9
|
* tested with a plain record.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
import { QUICK_CAMERA_MOVE_SCALE } from '../core/cameraMove.js';
|
|
12
|
+
/**
|
|
13
|
+
* The letter of each tool (the same letters the hints and the list of shortcuts show).
|
|
14
|
+
*
|
|
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
|
+
* triangle has `Y`.
|
|
17
|
+
*/
|
|
12
18
|
export const TOOL_LETTERS = Object.freeze({
|
|
13
19
|
V: 'select',
|
|
14
20
|
E: 'erase',
|
|
@@ -16,16 +22,32 @@ export const TOOL_LETTERS = Object.freeze({
|
|
|
16
22
|
H: 'pan',
|
|
17
23
|
A: 'arrow',
|
|
18
24
|
R: 'rect',
|
|
19
|
-
|
|
25
|
+
Y: 'triangle',
|
|
20
26
|
O: 'ellipse',
|
|
21
27
|
T: 'text',
|
|
22
28
|
I: 'image'
|
|
23
29
|
});
|
|
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
|
+
const SHAPE_SHORTCUTS = new Set(['rect', 'triangle', 'ellipse']);
|
|
32
|
+
/**
|
|
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
|
+
* 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
|
|
35
|
+
* is open, since the board's own keys are not answered inside a menu.
|
|
36
|
+
*/
|
|
37
|
+
export function shapeShortcutOf(input) {
|
|
38
|
+
if (input.ctrlKey || input.metaKey || input.altKey)
|
|
39
|
+
return null;
|
|
40
|
+
if (input.key.length !== 1)
|
|
41
|
+
return null;
|
|
42
|
+
const tool = TOOL_LETTERS[input.key.toUpperCase()];
|
|
43
|
+
return tool && SHAPE_SHORTCUTS.has(tool) ? tool : null;
|
|
44
|
+
}
|
|
24
45
|
/**
|
|
25
46
|
* The number of each tool of the drawing bar, in the order the bar lists them (select, draw, erase, arrow, text): the
|
|
26
47
|
* digits 1 to 5 choose them, besides their letters. A digit is the one the person types (`key`), on the number row or on the
|
|
27
|
-
* numpad, so a layout whose number row needs Shift to type a digit reaches the tools as it types the digit. The
|
|
28
|
-
*
|
|
48
|
+
* numpad, so a layout whose number row needs Shift to type a digit reaches the tools as it types the digit. The numbers are the
|
|
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
|
+
* numbers in `aria-keyshortcuts` (`TOOL_DIGIT_KEYS` in `i18n/shortcuts.ts`; a test holds the two together).
|
|
29
51
|
*/
|
|
30
52
|
export const TOOL_DIGITS = Object.freeze({
|
|
31
53
|
'1': 'select',
|
|
@@ -68,6 +90,21 @@ export function isBrowserZoomKey(input) {
|
|
|
68
90
|
function selectionExists(engine) {
|
|
69
91
|
return engine.state.selectedIds.length > 0;
|
|
70
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Whether a key that would change what a gesture works on is to be left alone, because the pointer is drawing or dragging something.
|
|
95
|
+
* A tool, a delete, a nudge, a layer step, a group or a jump of the view under the gesture would pull the ground from under it (a
|
|
96
|
+
* changed tool even clears the selection and the overlay the gesture draws). The key is still taken, so the browser does nothing with
|
|
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
|
+
*/
|
|
99
|
+
function ignoredWhileGesture(input, host) {
|
|
100
|
+
const gesture = host.controller.gestureKind;
|
|
101
|
+
if (!gesture)
|
|
102
|
+
return false;
|
|
103
|
+
// Told once for the press: a held key repeats, and the repeats are not news.
|
|
104
|
+
if (!input.repeat)
|
|
105
|
+
host.actions.keyIgnoredDuringGesture?.(input.key, gesture);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
71
108
|
/** Escape: leaves whatever is going on, one level at a time. */
|
|
72
109
|
function handleEscape(host) {
|
|
73
110
|
const { engine, controller, actions } = host;
|
|
@@ -113,11 +150,24 @@ function handleShortcut(input, host) {
|
|
|
113
150
|
engine.zoomStep(-1);
|
|
114
151
|
return true;
|
|
115
152
|
}
|
|
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
|
|
154
|
+
// while the view itself is being panned.
|
|
155
|
+
const viewJumpIgnored = () => controller.gestureKind !== 'pan' && ignoredWhileGesture(input, host);
|
|
116
156
|
if (key === '0') {
|
|
117
|
-
|
|
157
|
+
if (viewJumpIgnored())
|
|
158
|
+
return true;
|
|
159
|
+
// With nothing selected it does what a double click on the empty board does: the view eases back to 100% with the middle of
|
|
160
|
+
// everything that is drawn in the middle of the board. With something selected it keeps resetting the zoom about the middle
|
|
161
|
+
// of the view, so the selection stays where the person was looking at it.
|
|
162
|
+
if (!selectionExists(engine))
|
|
163
|
+
engine.flyToContent({ durationScale: QUICK_CAMERA_MOVE_SCALE });
|
|
164
|
+
else
|
|
165
|
+
engine.zoomReset();
|
|
118
166
|
return true;
|
|
119
167
|
}
|
|
120
168
|
if (key === '9') {
|
|
169
|
+
if (viewJumpIgnored())
|
|
170
|
+
return true;
|
|
121
171
|
engine.zoomToFit();
|
|
122
172
|
return true;
|
|
123
173
|
}
|
|
@@ -128,6 +178,8 @@ function handleShortcut(input, host) {
|
|
|
128
178
|
case 'a':
|
|
129
179
|
if (typing)
|
|
130
180
|
return false;
|
|
181
|
+
if (ignoredWhileGesture(input, host))
|
|
182
|
+
return true;
|
|
131
183
|
if (engine.state.tool !== 'select')
|
|
132
184
|
engine.setTool('select');
|
|
133
185
|
engine.selectAll();
|
|
@@ -137,6 +189,8 @@ function handleShortcut(input, host) {
|
|
|
137
189
|
return false;
|
|
138
190
|
if (!selectionExists(engine))
|
|
139
191
|
return false;
|
|
192
|
+
if (ignoredWhileGesture(input, host))
|
|
193
|
+
return true;
|
|
140
194
|
if (engine.copySelection())
|
|
141
195
|
actions.afterCopy();
|
|
142
196
|
return true;
|
|
@@ -145,6 +199,8 @@ function handleShortcut(input, host) {
|
|
|
145
199
|
return false;
|
|
146
200
|
if (!selectionExists(engine))
|
|
147
201
|
return false;
|
|
202
|
+
if (ignoredWhileGesture(input, host))
|
|
203
|
+
return true;
|
|
148
204
|
if (engine.cutSelection())
|
|
149
205
|
actions.afterCopy();
|
|
150
206
|
return true;
|
|
@@ -153,11 +209,15 @@ function handleShortcut(input, host) {
|
|
|
153
209
|
return false;
|
|
154
210
|
if (!selectionExists(engine))
|
|
155
211
|
return false;
|
|
212
|
+
if (ignoredWhileGesture(input, host))
|
|
213
|
+
return true;
|
|
156
214
|
engine.duplicateSelection();
|
|
157
215
|
return true;
|
|
158
216
|
case 'g':
|
|
159
217
|
if (typing)
|
|
160
218
|
return false;
|
|
219
|
+
if (ignoredWhileGesture(input, host))
|
|
220
|
+
return true;
|
|
161
221
|
if (input.shiftKey)
|
|
162
222
|
engine.ungroupSelection();
|
|
163
223
|
else
|
|
@@ -193,6 +253,8 @@ function handleLayerKey(input, host) {
|
|
|
193
253
|
return false;
|
|
194
254
|
if (!selectionExists(engine))
|
|
195
255
|
return false;
|
|
256
|
+
if (ignoredWhileGesture(input, host))
|
|
257
|
+
return true;
|
|
196
258
|
const toEnd = (input.ctrlKey || input.metaKey) && input.shiftKey;
|
|
197
259
|
engine.reorderSelection(forward ? (toEnd ? 'front' : 'forward') : toEnd ? 'back' : 'backward');
|
|
198
260
|
return true;
|
|
@@ -233,9 +295,22 @@ export function routeKeyDown(input, host) {
|
|
|
233
295
|
actions.spacePanChanged?.(true);
|
|
234
296
|
return true;
|
|
235
297
|
}
|
|
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).
|
|
299
|
+
// The physical key is read, so Shift (a capital G) and Alt (which types another character on some keyboards) change nothing, and a
|
|
300
|
+
// layout that types another letter on that key still has it. A gesture is not "ignored" here: the key is for the drag itself.
|
|
301
|
+
if (input.code === 'KeyG') {
|
|
302
|
+
// A held key repeats: keep the page still, and change nothing.
|
|
303
|
+
if (input.repeat)
|
|
304
|
+
return true;
|
|
305
|
+
controller.setGuidesSuppressed(true);
|
|
306
|
+
actions.guidesSuppressedChanged?.(true);
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
236
309
|
if (key === 'Delete' || key === 'Backspace') {
|
|
237
310
|
if (!selectionExists(engine))
|
|
238
311
|
return false;
|
|
312
|
+
if (ignoredWhileGesture(input, host))
|
|
313
|
+
return true;
|
|
239
314
|
void engine.deleteSelection();
|
|
240
315
|
return true;
|
|
241
316
|
}
|
|
@@ -245,6 +320,8 @@ export function routeKeyDown(input, host) {
|
|
|
245
320
|
return false;
|
|
246
321
|
if (!selectionExists(engine))
|
|
247
322
|
return false;
|
|
323
|
+
if (ignoredWhileGesture(input, host))
|
|
324
|
+
return true;
|
|
248
325
|
const distance = input.shiftKey ? NUDGE_DISTANCE_WITH_SHIFT : NUDGE_DISTANCE;
|
|
249
326
|
engine.nudgeSelection(step[0] * distance, step[1] * distance);
|
|
250
327
|
return true;
|
|
@@ -259,6 +336,14 @@ export function routeKeyDown(input, host) {
|
|
|
259
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.
|
|
260
337
|
const tool = key.length === 1 ? (TOOL_LETTERS[key.toUpperCase()] ?? TOOL_DIGITS[key]) : undefined;
|
|
261
338
|
if (tool && toolIsAvailable(tool, host.tools)) {
|
|
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
|
|
340
|
+
// over): only the first press counts. Choosing a tool also clears the selection and the overlay, so a letter pressed while
|
|
341
|
+
// the pointer is drawing or dragging something must not change the tool under the gesture. Both are taken (the browser does
|
|
342
|
+
// nothing with them) and answered with nothing.
|
|
343
|
+
if (input.repeat)
|
|
344
|
+
return true;
|
|
345
|
+
if (ignoredWhileGesture(input, host))
|
|
346
|
+
return true;
|
|
262
347
|
actions.chooseTool(tool);
|
|
263
348
|
return true;
|
|
264
349
|
}
|
|
@@ -271,10 +356,20 @@ export function routeKeyUp(input, host) {
|
|
|
271
356
|
host.actions.spacePanChanged?.(false);
|
|
272
357
|
return true;
|
|
273
358
|
}
|
|
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.
|
|
360
|
+
if (input.code === 'KeyG' && host.controller.guidesSuppressed) {
|
|
361
|
+
host.controller.setGuidesSuppressed(false);
|
|
362
|
+
host.actions.guidesSuppressedChanged?.(false);
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
274
365
|
return false;
|
|
275
366
|
}
|
|
276
367
|
/** The window lost the focus: nothing is held any more. */
|
|
277
368
|
export function releaseHeldKeys(host) {
|
|
278
369
|
host.controller.setSpaceHeld(false);
|
|
279
370
|
host.actions.spacePanChanged?.(false);
|
|
371
|
+
if (host.controller.guidesSuppressed) {
|
|
372
|
+
host.controller.setGuidesSuppressed(false);
|
|
373
|
+
host.actions.guidesSuppressedChanged?.(false);
|
|
374
|
+
}
|
|
280
375
|
}
|
|
@@ -55,6 +55,8 @@ export interface Gesture {
|
|
|
55
55
|
cancel(): void;
|
|
56
56
|
/** A modifier key changed while the pointer stayed still (Shift pressed in the middle of a drag). */
|
|
57
57
|
modifiersChanged?(modifiers: Modifiers, lastInput: PointerInput | null): void;
|
|
58
|
+
/** The key that turns the alignment guides off was pressed or let go while the pointer stayed still (G held in the middle of a drag). */
|
|
59
|
+
guidesSuppressedChanged?(): void;
|
|
58
60
|
}
|
|
59
61
|
export interface PointerControllerOptions {
|
|
60
62
|
/** Whether moving objects snap to the others. Read at every move. */
|
|
@@ -79,4 +81,9 @@ export interface PointerControllerOptions {
|
|
|
79
81
|
export interface GestureContext {
|
|
80
82
|
engine: EngineCore;
|
|
81
83
|
options: PointerControllerOptions;
|
|
84
|
+
/**
|
|
85
|
+
* Whether the person holds the key that turns the alignment guides off (G): a drag then neither snaps to the other shapes nor shows
|
|
86
|
+
* a guide. Read at every step of a drag; a context that leaves it out has the guides on.
|
|
87
|
+
*/
|
|
88
|
+
guidesSuppressed?: () => boolean;
|
|
82
89
|
}
|
package/dist/engine/state.d.ts
CHANGED
|
@@ -11,6 +11,22 @@ import type { ArrowBindHint, ObjectId, Rect, SceneObject, Size, Viewport } from
|
|
|
11
11
|
export type ToolId = 'select' | 'draw' | 'rect' | 'rounded-rect' | 'ellipse' | 'circle' | 'triangle' | 'arrow' | 'library-shape' | 'text' | 'erase' | 'pan';
|
|
12
12
|
/** The tools that drag a shape out. */
|
|
13
13
|
export type ShapeToolId = 'rect' | 'rounded-rect' | 'ellipse' | 'circle' | 'triangle' | 'arrow' | 'library-shape';
|
|
14
|
+
/**
|
|
15
|
+
* How the Draw tool draws, set before a line is drawn: the lines drawn from then on have this colour, this width and this opacity.
|
|
16
|
+
* A line that is already on the board keeps what it has (the settings panel changes it while it is selected).
|
|
17
|
+
*/
|
|
18
|
+
export interface PenStyle {
|
|
19
|
+
/** The colour of the line. */
|
|
20
|
+
color: string;
|
|
21
|
+
/** The width of the line, as the Width control of the panel shows it. */
|
|
22
|
+
width: number;
|
|
23
|
+
/** How much of the board shows through the whole line, from 0 to 1: 1 is solid. */
|
|
24
|
+
opacity: number;
|
|
25
|
+
}
|
|
26
|
+
/** The least opaque the pen may be made: a line that cannot be seen is not a pen anyone means to choose, and a drawn line would look like nothing happened. */
|
|
27
|
+
export declare const MIN_PEN_OPACITY = 0.05;
|
|
28
|
+
/** The pen of a board that was not given another: the colour and the width the Draw tool has always drawn with, fully solid. */
|
|
29
|
+
export declare const DEFAULT_PEN_STYLE: PenStyle;
|
|
14
30
|
export declare const SHAPE_TOOLS: readonly ToolId[];
|
|
15
31
|
/** A widget card whose widget the host is still working on. Not saved. */
|
|
16
32
|
export type PendingWidgetState = 'duplicating' | 'linking' | 'converting';
|
|
@@ -123,6 +139,8 @@ export interface EngineState {
|
|
|
123
139
|
libraryShapeKey: string | null;
|
|
124
140
|
/** Keep the tool after a shape has been placed (otherwise the tool goes back to Select). */
|
|
125
141
|
stickyTool: boolean;
|
|
142
|
+
/** How the Draw tool draws the next line (see `PenStyle`). Not part of the saved board: it is the person's setting. */
|
|
143
|
+
penStyle: PenStyle;
|
|
126
144
|
/** The CSS cursor of the board. */
|
|
127
145
|
cursor: string;
|
|
128
146
|
overlay: EngineOverlay;
|