@widgetic/canvas 0.5.46 → 0.5.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/canvas/DomCanvas.svelte +1 -2
- package/dist/canvas/host/CanvasHost.d.ts +0 -3
- package/dist/canvas/host/CanvasHost.js +102 -67
- package/dist/canvas/host/pauseCollector.d.ts +18 -0
- package/dist/canvas/host/pauseCollector.js +45 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
- package/dist/canvas/ui/CanvasHint.svelte +10 -9
- package/dist/canvas/ui/SelectionPanel.svelte +14 -12
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
- package/dist/canvas/ui/ShapesMenu.svelte +6 -4
- package/dist/canvas/ui/ToolButton.svelte +7 -6
- package/dist/canvas/ui/floatingCard.d.ts +28 -8
- package/dist/canvas/ui/floatingCard.js +28 -8
- package/dist/canvas/ui/selectionTraits.d.ts +8 -4
- package/dist/canvas/ui/selectionTraits.js +10 -18
- package/dist/canvas/view/SelectionOverlay.svelte +2 -2
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +1 -1
- package/dist/components/input-controls/ColorIC.svelte +1 -1
- package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
- package/dist/engine/EngineCore.d.ts +33 -8
- package/dist/engine/EngineCore.js +66 -30
- package/dist/engine/core/brush.d.ts +24 -0
- package/dist/engine/core/brush.js +145 -13
- package/dist/engine/core/shapeTools.d.ts +23 -18
- package/dist/engine/core/shapeTools.js +45 -17
- package/dist/engine/core/style.d.ts +18 -2
- package/dist/engine/core/style.js +57 -25
- package/dist/engine/core/styleMemory.d.ts +88 -0
- package/dist/engine/core/styleMemory.js +189 -0
- package/dist/engine/input/gestures.d.ts +8 -3
- package/dist/engine/input/gestures.js +123 -48
- package/dist/engine/input/keyboard.js +7 -2
- package/dist/poster/boardPlacement.d.ts +4 -1
- package/dist/poster/boardPlacement.js +6 -3
- package/dist/settings/rememberedStyles.d.ts +22 -0
- package/dist/settings/rememberedStyles.js +47 -0
- package/dist/settings/workspaceToolSettings.d.ts +17 -0
- package/dist/settings/workspaceToolSettings.js +4 -1
- package/dist/tools/hostAdapter.js +0 -1
- package/package.json +4 -4
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<script lang="ts">
|
|
9
9
|
import type { Snippet } from 'svelte';
|
|
10
10
|
import { IconButton } from '@widgetic/design-system/components';
|
|
11
|
-
import { TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES } from './floatingCard.js';
|
|
11
|
+
import { TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES, TOOLBAR_NO_RING_CLASSES } from './floatingCard.js';
|
|
12
12
|
import ShortcutTooltip from './ShortcutTooltip.svelte';
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
@@ -44,15 +44,16 @@
|
|
|
44
44
|
// system's `press-feedback` (which keeps still for a person who asked for less motion). The keyboard focus has no ring on it: like
|
|
45
45
|
// the design system's Icon Button it takes the look of the hover (a ring stayed on the button the pointer had clicked as soon as a
|
|
46
46
|
// shortcut key was pressed). The tool that is on keeps its brand tint, a deeper one while the keyboard holds the focus
|
|
47
|
-
// (`TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES`), so that the focus is never invisible and never a ring
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
// (`TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES`), so that the focus is never invisible and never a ring (`TOOLBAR_NO_RING_CLASSES`,
|
|
48
|
+
// added where each button is drawn below, takes the browser's own ring off every button of the chrome, for `focus` as well as
|
|
49
|
+
// for `focus-visible`). This one stays a plain string: `tests/ui/pressFeedback.test.mjs` reads it for the press cue.
|
|
50
|
+
const LEVEL_CLASSES = 'press-feedback inline-flex h-8 w-10 shrink-0 items-center justify-center rounded-lg text-xs font-medium text-muted-foreground transition-colors duration-fast motion-reduce:transition-none hover:bg-accent hover:text-foreground focus-visible:bg-accent focus-visible:text-foreground disabled:pointer-events-none disabled:opacity-50';
|
|
50
51
|
</script>
|
|
51
52
|
|
|
52
53
|
<ShortcutTooltip {label} {shortcut}>
|
|
53
54
|
{#snippet trigger(props)}
|
|
54
55
|
{#if size === 'level'}
|
|
55
|
-
<button {...props} type="button" aria-label={label} aria-keyshortcuts={keyShortcuts} {disabled} {onclick} class="{LEVEL_CLASSES} {className}">
|
|
56
|
+
<button {...props} type="button" aria-label={label} aria-keyshortcuts={keyShortcuts} {disabled} {onclick} class="{LEVEL_CLASSES} {TOOLBAR_NO_RING_CLASSES} {className}">
|
|
56
57
|
{@render children()}
|
|
57
58
|
</button>
|
|
58
59
|
{:else}
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
aria-pressed={toggle ? active : undefined}
|
|
65
66
|
aria-keyshortcuts={keyShortcuts}
|
|
66
67
|
data-active={active ? '' : undefined}
|
|
67
|
-
class="{SQUARE_CLASSES[size]} data-[active]:bg-brand-subtle data-[active]:text-foreground {TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} {className}"
|
|
68
|
+
class="{SQUARE_CLASSES[size]} data-[active]:bg-brand-subtle data-[active]:text-foreground {TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} {TOOLBAR_NO_RING_CLASSES} {className}"
|
|
68
69
|
>
|
|
69
70
|
{@render children()}
|
|
70
71
|
</IconButton>
|
|
@@ -34,16 +34,36 @@ export declare const OVERLAY_REDUCED_MOTION_CLASSES = "motion-reduce:animate-non
|
|
|
34
34
|
/** Canvas-floated surfaces stay below site dialogs and toasts (design-system overlays use z-50). */
|
|
35
35
|
export declare const CANVAS_OVERLAY_Z_CLASS = "z-40";
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
37
|
+
* No ring on any control of the chrome (the buttons of the toolbar, the Shapes button, the zoom buttons), however the focus got
|
|
38
|
+
* there. The keyboard focus takes the look of the hover on the buttons that are not on, and a deeper brand tint on the one that is
|
|
39
|
+
* (`TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES`), so it is never invisible and never a ring. The Shapes button used to have a ring while
|
|
40
|
+
* its menu was open (Figma draws it so); it was taken off at the owner's request (19 Nov 2026) and the open menu is shown by the
|
|
41
|
+
* menu itself and the chevron that turns.
|
|
41
42
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* `outline-hidden` hides the browser's own ring (it stays in the forced-colours mode of the system, which a person who asked for
|
|
44
|
+
* it needs); it is given for `focus` as well as for `focus-visible`, so that a page whose stylesheet rings every focused button is
|
|
45
|
+
* not heard either. Written out in full, so that a page's stylesheet picks both classes up.
|
|
45
46
|
*/
|
|
46
|
-
export declare const
|
|
47
|
+
export declare const TOOLBAR_NO_RING_CLASSES = "focus:outline-hidden focus-visible:outline-hidden";
|
|
48
|
+
/**
|
|
49
|
+
* How a sub-menu (the Shapes menu's "More shapes", the right-click menu's "Layer order") opens: it fades in while it slides up by
|
|
50
|
+
* `--floating-slide` (8 px), as the Shapes menu does when it opens.
|
|
51
|
+
*
|
|
52
|
+
* The design system's `floating-motion` writes `--floating-slide-x` for a menu that opens to the side (`data-side='right'` or
|
|
53
|
+
* `'left'`), and `--floating-slide-y` only for one that opens above or below. A sub-menu opens to the side, so it set the first and
|
|
54
|
+
* took the second from the menu it stands in (a custom property is inherited): the Shapes menu opens upward and lent it its slide
|
|
55
|
+
* up, so "More shapes" came in from the bottom left, and the right-click menu opens downward and lent "Layer order" its slide
|
|
56
|
+
* down, so it came in from the top left. Both axes are set here, with `!` because the design system's own rule (a `data-side`
|
|
57
|
+
* selector) is more specific than a utility: no slide sideways, and the slide up.
|
|
58
|
+
*/
|
|
59
|
+
export declare const SUBMENU_SLIDE_UP_CLASSES = "[--floating-slide-x:0px]! [--floating-slide-y:var(--floating-slide)]!";
|
|
60
|
+
/**
|
|
61
|
+
* Where the right-click menu's "Layer order" submenu stands against its row: the first row of the submenu level with "Layer order".
|
|
62
|
+
* The submenu is a card with a 1 px border and `LAYER_MENU_PADDING_CLASS` (4 px) of padding before its first row, so the card
|
|
63
|
+
* itself starts 5 px above the row it opens from (the offset runs down from the row's top, so a negative one lifts it). It was 12:
|
|
64
|
+
* the card then stood 13 px below the row.
|
|
65
|
+
*/
|
|
66
|
+
export declare const LAYER_MENU_ALIGN_OFFSET_PX = -5;
|
|
47
67
|
/**
|
|
48
68
|
* How the keyboard focus shows on a button of the chrome that has its brand tint on (the tool in use, the Shapes button while a
|
|
49
69
|
* shape is the tool): no ring, a deeper tint of the same colour. A button that is not on takes the look of the hover, which is the
|
|
@@ -34,16 +34,36 @@ export const OVERLAY_REDUCED_MOTION_CLASSES = 'motion-reduce:animate-none motion
|
|
|
34
34
|
/** Canvas-floated surfaces stay below site dialogs and toasts (design-system overlays use z-50). */
|
|
35
35
|
export const CANVAS_OVERLAY_Z_CLASS = 'z-40';
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
37
|
+
* No ring on any control of the chrome (the buttons of the toolbar, the Shapes button, the zoom buttons), however the focus got
|
|
38
|
+
* there. The keyboard focus takes the look of the hover on the buttons that are not on, and a deeper brand tint on the one that is
|
|
39
|
+
* (`TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES`), so it is never invisible and never a ring. The Shapes button used to have a ring while
|
|
40
|
+
* its menu was open (Figma draws it so); it was taken off at the owner's request (19 Nov 2026) and the open menu is shown by the
|
|
41
|
+
* menu itself and the chevron that turns.
|
|
41
42
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* `outline-hidden` hides the browser's own ring (it stays in the forced-colours mode of the system, which a person who asked for
|
|
44
|
+
* it needs); it is given for `focus` as well as for `focus-visible`, so that a page whose stylesheet rings every focused button is
|
|
45
|
+
* not heard either. Written out in full, so that a page's stylesheet picks both classes up.
|
|
45
46
|
*/
|
|
46
|
-
export const
|
|
47
|
+
export const TOOLBAR_NO_RING_CLASSES = 'focus:outline-hidden focus-visible:outline-hidden';
|
|
48
|
+
/**
|
|
49
|
+
* How a sub-menu (the Shapes menu's "More shapes", the right-click menu's "Layer order") opens: it fades in while it slides up by
|
|
50
|
+
* `--floating-slide` (8 px), as the Shapes menu does when it opens.
|
|
51
|
+
*
|
|
52
|
+
* The design system's `floating-motion` writes `--floating-slide-x` for a menu that opens to the side (`data-side='right'` or
|
|
53
|
+
* `'left'`), and `--floating-slide-y` only for one that opens above or below. A sub-menu opens to the side, so it set the first and
|
|
54
|
+
* took the second from the menu it stands in (a custom property is inherited): the Shapes menu opens upward and lent it its slide
|
|
55
|
+
* up, so "More shapes" came in from the bottom left, and the right-click menu opens downward and lent "Layer order" its slide
|
|
56
|
+
* down, so it came in from the top left. Both axes are set here, with `!` because the design system's own rule (a `data-side`
|
|
57
|
+
* selector) is more specific than a utility: no slide sideways, and the slide up.
|
|
58
|
+
*/
|
|
59
|
+
export const SUBMENU_SLIDE_UP_CLASSES = '[--floating-slide-x:0px]! [--floating-slide-y:var(--floating-slide)]!';
|
|
60
|
+
/**
|
|
61
|
+
* Where the right-click menu's "Layer order" submenu stands against its row: the first row of the submenu level with "Layer order".
|
|
62
|
+
* The submenu is a card with a 1 px border and `LAYER_MENU_PADDING_CLASS` (4 px) of padding before its first row, so the card
|
|
63
|
+
* itself starts 5 px above the row it opens from (the offset runs down from the row's top, so a negative one lifts it). It was 12:
|
|
64
|
+
* the card then stood 13 px below the row.
|
|
65
|
+
*/
|
|
66
|
+
export const LAYER_MENU_ALIGN_OFFSET_PX = -5;
|
|
47
67
|
/**
|
|
48
68
|
* How the keyboard focus shows on a button of the chrome that has its brand tint on (the tool in use, the Shapes button while a
|
|
49
69
|
* shape is the tool): no ring, a deeper tint of the same colour. A button that is not on takes the look of the hover, which is the
|
|
@@ -64,10 +64,14 @@ export declare function minimumStrokeWidth(traits: SelectionTraits): number;
|
|
|
64
64
|
/** What the font size stepper shows: a whole number, never a long float from resizing. */
|
|
65
65
|
export declare function formatFontSizeDisplay(trait: Trait<number>): number | '–';
|
|
66
66
|
/**
|
|
67
|
-
* Whether the
|
|
67
|
+
* Whether the Fill colour row shows: when something selected has a colour to fill, which is a shape's inside, the letters of a text or
|
|
68
|
+
* the line of a line-only icon. The look of the board (the wireframe look, which starts a new shape white with a grey outline) decides
|
|
69
|
+
* how a shape begins, not whether its colours can be changed afterwards: "The shapes are lacking the stroke and the fill color" (19 Nov
|
|
70
|
+
* 2026) was the row being hidden for every shape in that look.
|
|
68
71
|
*/
|
|
69
|
-
export declare function showFillColorRow(traits: SelectionTraits
|
|
72
|
+
export declare function showFillColorRow(traits: SelectionTraits): boolean;
|
|
70
73
|
/**
|
|
71
|
-
* Whether the
|
|
74
|
+
* Whether the Stroke colour row shows: when something selected has an outline or a line of its own to colour (a shape's outline, an
|
|
75
|
+
* arrow, a line drawn by hand, and the pen of the Draw tool). Like the Fill row, whatever the look of the board is.
|
|
72
76
|
*/
|
|
73
|
-
export declare function showStrokeColorRow(traits: SelectionTraits
|
|
77
|
+
export declare function showStrokeColorRow(traits: SelectionTraits): boolean;
|
|
@@ -99,26 +99,18 @@ export function formatFontSizeDisplay(trait) {
|
|
|
99
99
|
return trait.kind === 'same' ? Math.round(trait.value) : '–';
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
* Whether the
|
|
102
|
+
* Whether the Fill colour row shows: when something selected has a colour to fill, which is a shape's inside, the letters of a text or
|
|
103
|
+
* the line of a line-only icon. The look of the board (the wireframe look, which starts a new shape white with a grey outline) decides
|
|
104
|
+
* how a shape begins, not whether its colours can be changed afterwards: "The shapes are lacking the stroke and the fill color" (19 Nov
|
|
105
|
+
* 2026) was the row being hidden for every shape in that look.
|
|
103
106
|
*/
|
|
104
|
-
export function showFillColorRow(traits
|
|
105
|
-
|
|
106
|
-
return false;
|
|
107
|
-
return !wireframeMode || traits.text !== null;
|
|
107
|
+
export function showFillColorRow(traits) {
|
|
108
|
+
return traits.fill.kind !== 'none';
|
|
108
109
|
}
|
|
109
110
|
/**
|
|
110
|
-
* Whether the
|
|
111
|
+
* Whether the Stroke colour row shows: when something selected has an outline or a line of its own to colour (a shape's outline, an
|
|
112
|
+
* arrow, a line drawn by hand, and the pen of the Draw tool). Like the Fill row, whatever the look of the board is.
|
|
111
113
|
*/
|
|
112
|
-
export function showStrokeColorRow(traits
|
|
113
|
-
|
|
114
|
-
return false;
|
|
115
|
-
if (!wireframeMode)
|
|
116
|
-
return true;
|
|
117
|
-
return traits.targets.some((shape) => {
|
|
118
|
-
if (shape.type === 'rect' || shape.type === 'ellipse')
|
|
119
|
-
return false;
|
|
120
|
-
if (shape.type !== 'path')
|
|
121
|
-
return false;
|
|
122
|
-
return isBrushStroke(shape) || isArrow(shape) || !paintsFillOnStroke(shape);
|
|
123
|
-
});
|
|
114
|
+
export function showStrokeColorRow(traits) {
|
|
115
|
+
return traits.stroke.kind !== 'none';
|
|
124
116
|
}
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
}
|
|
226
226
|
if (!frame || state.overlay.readout) return null;
|
|
227
227
|
const text = formatReadout({ kind: 'size', width: Math.round(frame.world.width), height: Math.round(frame.world.height) });
|
|
228
|
-
const at = restingSizeLabelPoint(frame.screen
|
|
228
|
+
const at = restingSizeLabelPoint(frame.screen);
|
|
229
229
|
if (!at) return null;
|
|
230
230
|
return { x: at.x, y: at.y, text };
|
|
231
231
|
});
|
|
@@ -233,7 +233,7 @@
|
|
|
233
233
|
// The figure of a stretch (the size) or of a turn (the angle) stands in the middle of the frame, in both cases.
|
|
234
234
|
const readoutPoint = $derived.by(() => {
|
|
235
235
|
if (!frame || !state.overlay.readout) return null;
|
|
236
|
-
return restingSizeLabelPoint(frame.screen
|
|
236
|
+
return restingSizeLabelPoint(frame.screen);
|
|
237
237
|
});
|
|
238
238
|
|
|
239
239
|
/** Where one handle sits on the frame, as the percentages of its width and height. */
|
|
@@ -97,7 +97,7 @@ export declare function formatReadout(readout: Readout): string;
|
|
|
97
97
|
* all of it when several things are selected), where the figure of a stretch or a turn sits too, so the number is always at
|
|
98
98
|
* the same place and never moves off the thing it measures.
|
|
99
99
|
*/
|
|
100
|
-
export declare function restingSizeLabelPoint(frame: ScreenFrame
|
|
100
|
+
export declare function restingSizeLabelPoint(frame: ScreenFrame): Point | null;
|
|
101
101
|
/** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the turning dot goes. */
|
|
102
102
|
export declare function pointBelowFrame(frame: ScreenFrame, distance: number): Point;
|
|
103
103
|
/**
|
|
@@ -124,7 +124,7 @@ export function formatReadout(readout) {
|
|
|
124
124
|
* all of it when several things are selected), where the figure of a stretch or a turn sits too, so the number is always at
|
|
125
125
|
* the same place and never moves off the thing it measures.
|
|
126
126
|
*/
|
|
127
|
-
export function restingSizeLabelPoint(frame
|
|
127
|
+
export function restingSizeLabelPoint(frame) {
|
|
128
128
|
return { x: frame.centerX, y: frame.centerY };
|
|
129
129
|
}
|
|
130
130
|
/** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the turning dot goes. */
|
|
@@ -228,7 +228,7 @@
|
|
|
228
228
|
|
|
229
229
|
<div class="presets-container overflow-x-hidden p-2 border border-gray-300 rounded-md {presets ? 'fixed-palette' : ''}"
|
|
230
230
|
style={presets ? `grid-template-columns: repeat(${Math.min(presets.length, 8)}, 1fr); max-height: none;` : ''}>
|
|
231
|
-
{#each allPresets as color}
|
|
231
|
+
{#each allPresets as color, presetIndex (presetIndex)}
|
|
232
232
|
<div class="preset-wrapper">
|
|
233
233
|
<button
|
|
234
234
|
class="preset-btn"
|
|
@@ -16,8 +16,9 @@ import type { AlignMode, DistributeAxis } from './core/arrange.js';
|
|
|
16
16
|
import type { ArrowHandleId } from './core/arrow.js';
|
|
17
17
|
import type { ReorderMode, Scene } from './core/scene.js';
|
|
18
18
|
import type { StylePatch } from './core/style.js';
|
|
19
|
+
import type { PatchedStyleKind, RememberedStyles, StyleMemoryKind } from './core/styleMemory.js';
|
|
19
20
|
import type { SelectionFrame } from './core/transform.js';
|
|
20
|
-
import type { ObjectId, Point, Rect,
|
|
21
|
+
import type { ObjectId, Point, Rect, SceneObject, ShapeObject, Size, Viewport, WidgetObject } from './core/types.js';
|
|
21
22
|
import type { EngineOverlay, EngineState, PendingWidgetState, PenStyle, ToolId, WidgetRuntime } from './state.js';
|
|
22
23
|
import type { MeasureText } from './text/layoutText.js';
|
|
23
24
|
/** How many undo steps the board keeps (as the canvas it replaces did). */
|
|
@@ -118,6 +119,13 @@ export interface EngineHooks {
|
|
|
118
119
|
onCleared?: (cause: BoardClearCause) => void;
|
|
119
120
|
/** The selection changed (a selection, a deselection, after a delete or an undo). */
|
|
120
121
|
onSelectionChange?: (selectedIds: readonly ObjectId[]) => void;
|
|
122
|
+
/**
|
|
123
|
+
* The person restyled something and so changed what the next element of a kind starts with: the kinds that came out different (see
|
|
124
|
+
* `EngineCore.rememberedStyles`, and `EngineState.penStyle` for `'pen'`). The host keeps them for the workspace. Called for every
|
|
125
|
+
* change of the memory, a drag of a slider included, and not when an edit says what the memory holds already, nor when the memory
|
|
126
|
+
* is loaded (`setRememberedStyles`).
|
|
127
|
+
*/
|
|
128
|
+
onStyleRemembered?: (kinds: readonly StyleMemoryKind[]) => void;
|
|
121
129
|
/** Widget cards are about to be deleted: one question per widget, and one `false` cancels the whole delete. */
|
|
122
130
|
confirmWidgetDeletion?: ((widgetId: string) => Promise<boolean> | boolean) | null;
|
|
123
131
|
/** Whether widget cards may be duplicated/pasted on the board. Defaults to true. */
|
|
@@ -323,19 +331,29 @@ export declare class EngineCore {
|
|
|
323
331
|
notifyFontsChanged(): void;
|
|
324
332
|
/** Remembers the font family for the next text object the person places. */
|
|
325
333
|
setPreferredTextFontFamily(fontFamily: string): void;
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
334
|
+
/**
|
|
335
|
+
* What the person last chose for each kind of element: the next shape, line icon, arrow or text starts with it, laid over the look it
|
|
336
|
+
* would start with (see `core/styleMemory.ts`). It is what the panel was used for, in this session and, when the host loaded it
|
|
337
|
+
* (`setRememberedStyles`), in the sessions before. The pen of the Draw tool is `state.penStyle`.
|
|
338
|
+
*/
|
|
339
|
+
get rememberedStyles(): RememberedStyles;
|
|
340
|
+
/**
|
|
341
|
+
* Loads what was kept for a workspace (the host does, when the board is opened in one), instead of what the engine has: a kind that
|
|
342
|
+
* the storage does not hold goes back to nothing remembered. What the storage holds is checked key by key (a value that is not one of
|
|
343
|
+
* the key is dropped, a number is brought into its range), so a damaged or an older entry cannot give a shape a look it cannot have.
|
|
344
|
+
* Not an edit of the person: nobody is told (`onStyleRemembered`) and nothing is saved because of it.
|
|
345
|
+
*/
|
|
346
|
+
setRememberedStyles(stored: {
|
|
347
|
+
readonly [kind in PatchedStyleKind]?: unknown;
|
|
348
|
+
} | null): void;
|
|
330
349
|
/**
|
|
331
350
|
* Changes how the Draw tool draws: the lines drawn from now on take the colour, the width and the opacity that are asked for. A key
|
|
332
|
-
* that is left out stays as it was; a value that cannot be a line's (a width under 1 or above
|
|
351
|
+
* that is left out stays as it was; a value that cannot be a line's (a width under 1 or above 50, an opacity out of range, a
|
|
333
352
|
* colour that is not a word, a number that is not a number) is brought to what a line can be, or ignored when it is not a value
|
|
334
353
|
* at all. Nothing on the board changes (that is `setStyle`, for the selection), and nothing is added to the history. Returns
|
|
335
354
|
* whether the pen came out different.
|
|
336
355
|
*/
|
|
337
356
|
setPenStyle(patch: Partial<PenStyle>): boolean;
|
|
338
|
-
workspacePaintForNewShape(wireframe: boolean): Partial<RectObject>;
|
|
339
357
|
/**
|
|
340
358
|
* Makes a text object, puts it on the board and starts editing it. A click makes a label whose width follows its
|
|
341
359
|
* text; a width makes a box whose lines wrap. Nothing is recorded until the editing ends with text in it.
|
|
@@ -363,7 +381,14 @@ export declare class EngineCore {
|
|
|
363
381
|
endTextEdit(options?: {
|
|
364
382
|
keepPlaceholderTool?: boolean;
|
|
365
383
|
}): ObjectId | null;
|
|
366
|
-
/**
|
|
384
|
+
/**
|
|
385
|
+
* Changes how the selection looks. `commit: false` is for a slider that is still being dragged: call `commit()` when it ends.
|
|
386
|
+
*
|
|
387
|
+
* What the person chose is also what the next element of each kind in the selection starts with, until they choose again (a
|
|
388
|
+
* rectangle's fill, stroke and width are the next rectangle's, the next ellipse's, the next star's; an arrow's colour is the next
|
|
389
|
+
* arrow's; a text's size is the next text's; the colour of a line drawn by hand is the pen's). It is kept for every change, a drag
|
|
390
|
+
* of a slider included and a value the selection has already, and the host is told (`onStyleRemembered`). See `core/styleMemory.ts`.
|
|
391
|
+
*/
|
|
367
392
|
setStyle(patch: StylePatch, options?: {
|
|
368
393
|
commit?: boolean;
|
|
369
394
|
}): boolean;
|
|
@@ -22,6 +22,7 @@ import { addObjectsBehindWidgetCards, boardVisualBounds, boundsOfObjects, duplic
|
|
|
22
22
|
import { MIN_BRUSH_WIDTH } from './core/brush.js';
|
|
23
23
|
import { clampNumber } from './core/geometry.js';
|
|
24
24
|
import { MAX_STROKE_WIDTH, applyStylePatch } from './core/style.js';
|
|
25
|
+
import { NO_REMEMBERED_STYLES, rememberStyleEdits, sanitizeRememberedStyles, styleEditOf, withRememberedStyle } from './core/styleMemory.js';
|
|
25
26
|
import { Scribble } from './core/scribble.js';
|
|
26
27
|
import { selectionFrameOf } from './core/transform.js';
|
|
27
28
|
import { INITIAL_VIEWPORT, clampZoom, fitViewportToRect, nextZoomStep, panViewport, sanitizeViewport, screenToWorld, visibleWorldRect, zoomAtPoint } from './core/viewport.js';
|
|
@@ -72,8 +73,12 @@ export class EngineCore {
|
|
|
72
73
|
#textSession = null;
|
|
73
74
|
/** The last font family chosen in the panel; new text objects start with this instead of the catalog default. */
|
|
74
75
|
#preferredTextFontFamily = null;
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
/**
|
|
77
|
+
* What the person last chose for each kind of element (a shape, a line icon, an arrow, a text): the next element of the kind starts
|
|
78
|
+
* with it. Set by every restyle of the selection (`setStyle`) and by the host when it opens the workspace (`setRememberedStyles`).
|
|
79
|
+
* The pen of the Draw tool is not here: it is `EngineState.penStyle`.
|
|
80
|
+
*/
|
|
81
|
+
#rememberedStyles = NO_REMEMBERED_STYLES;
|
|
77
82
|
// The eraser's trail while it lives; what the views draw of it is `state.scribble`.
|
|
78
83
|
#scribble = null;
|
|
79
84
|
#indexes = new WeakMap();
|
|
@@ -861,15 +866,48 @@ export class EngineCore {
|
|
|
861
866
|
setPreferredTextFontFamily(fontFamily) {
|
|
862
867
|
this.#preferredTextFontFamily = fontFamily;
|
|
863
868
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
+
/**
|
|
870
|
+
* What the person last chose for each kind of element: the next shape, line icon, arrow or text starts with it, laid over the look it
|
|
871
|
+
* would start with (see `core/styleMemory.ts`). It is what the panel was used for, in this session and, when the host loaded it
|
|
872
|
+
* (`setRememberedStyles`), in the sessions before. The pen of the Draw tool is `state.penStyle`.
|
|
873
|
+
*/
|
|
874
|
+
get rememberedStyles() {
|
|
875
|
+
return this.#rememberedStyles;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Loads what was kept for a workspace (the host does, when the board is opened in one), instead of what the engine has: a kind that
|
|
879
|
+
* the storage does not hold goes back to nothing remembered. What the storage holds is checked key by key (a value that is not one of
|
|
880
|
+
* the key is dropped, a number is brought into its range), so a damaged or an older entry cannot give a shape a look it cannot have.
|
|
881
|
+
* Not an edit of the person: nobody is told (`onStyleRemembered`) and nothing is saved because of it.
|
|
882
|
+
*/
|
|
883
|
+
setRememberedStyles(stored) {
|
|
884
|
+
this.#rememberedStyles = sanitizeRememberedStyles(stored);
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Takes in what restyling the selection says about the next element of each kind (`setStyle` calls it for every change, a drag of a
|
|
888
|
+
* slider included, and for a value the selection has already). The pen is the pen of the Draw tool: an edit of a line drawn by hand
|
|
889
|
+
* is an edit of the pen, so that the next line is drawn the way the last one was left. The host is told which kinds came out
|
|
890
|
+
* different, once for each change.
|
|
891
|
+
*/
|
|
892
|
+
#rememberStyleEdits(edits) {
|
|
893
|
+
if (edits.length === 0)
|
|
894
|
+
return;
|
|
895
|
+
const { styles, changed } = rememberStyleEdits(this.#rememberedStyles, edits);
|
|
896
|
+
this.#rememberedStyles = styles;
|
|
897
|
+
const kinds = [...changed];
|
|
898
|
+
const penEdit = {};
|
|
899
|
+
for (const { kind, style } of edits)
|
|
900
|
+
if (kind === 'pen')
|
|
901
|
+
Object.assign(penEdit, style);
|
|
902
|
+
if (Object.keys(penEdit).length > 0 && this.setPenStyle({ color: penEdit.stroke, width: penEdit.strokeWidth, opacity: penEdit.opacity }))
|
|
903
|
+
kinds.push('pen');
|
|
904
|
+
if (kinds.length === 0)
|
|
905
|
+
return;
|
|
906
|
+
this.#callHook(() => this.hooks.onStyleRemembered?.(kinds), 'style memory hook');
|
|
869
907
|
}
|
|
870
908
|
/**
|
|
871
909
|
* Changes how the Draw tool draws: the lines drawn from now on take the colour, the width and the opacity that are asked for. A key
|
|
872
|
-
* that is left out stays as it was; a value that cannot be a line's (a width under 1 or above
|
|
910
|
+
* that is left out stays as it was; a value that cannot be a line's (a width under 1 or above 50, an opacity out of range, a
|
|
873
911
|
* colour that is not a word, a number that is not a number) is brought to what a line can be, or ignored when it is not a value
|
|
874
912
|
* at all. Nothing on the board changes (that is `setStyle`, for the selection), and nothing is added to the history. Returns
|
|
875
913
|
* whether the pen came out different.
|
|
@@ -884,20 +922,6 @@ export class EngineCore {
|
|
|
884
922
|
this.#set({ penStyle: Object.freeze({ color, width, opacity }) });
|
|
885
923
|
return true;
|
|
886
924
|
}
|
|
887
|
-
workspacePaintForNewShape(wireframe) {
|
|
888
|
-
if (!this.#workspacePaintDefaults)
|
|
889
|
-
return {};
|
|
890
|
-
if (wireframe) {
|
|
891
|
-
const { stroke, strokeWidth, strokeStyle, opacity } = this.#workspacePaintDefaults;
|
|
892
|
-
return {
|
|
893
|
-
...(stroke !== undefined ? { stroke } : {}),
|
|
894
|
-
...(strokeWidth !== undefined ? { strokeWidth } : {}),
|
|
895
|
-
...(strokeStyle !== undefined ? { strokeStyle } : {}),
|
|
896
|
-
...(opacity !== undefined ? { opacity } : {})
|
|
897
|
-
};
|
|
898
|
-
}
|
|
899
|
-
return { ...this.#workspacePaintDefaults };
|
|
900
|
-
}
|
|
901
925
|
/**
|
|
902
926
|
* Makes a text object, puts it on the board and starts editing it. A click makes a label whose width follows its
|
|
903
927
|
* text; a width makes a box whose lines wrap. Nothing is recorded until the editing ends with text in it.
|
|
@@ -915,10 +939,11 @@ export class EngineCore {
|
|
|
915
939
|
y: point.y,
|
|
916
940
|
width: fixedWidth ? options.width : TEXT_DEFAULTS.minimumWidth,
|
|
917
941
|
autoWidth: !fixedWidth,
|
|
918
|
-
fontFamily: this.#preferredTextFontFamily ??
|
|
919
|
-
...this.#workspaceTextDefaults
|
|
942
|
+
fontFamily: this.#preferredTextFontFamily ?? TEXT_DEFAULTS.fontFamily
|
|
920
943
|
});
|
|
921
|
-
|
|
944
|
+
// What the person last chose for a text (the font, the size, bold, italic, underline, the alignment, the colour of the letters,
|
|
945
|
+
// the opacity) is laid over what a text starts with; the box is laid out below for the size it comes out at.
|
|
946
|
+
const fitted = this.#fitText(withRememberedStyle(base, this.#rememberedStyles.text));
|
|
922
947
|
// The placeholder is centred on the point it is asked for, whatever its size (a bigger font makes a bigger prompt).
|
|
923
948
|
const text = options.placeholder ? { ...fitted, x: point.x - fitted.width / 2, y: point.y - fitted.height / 2 } : fitted;
|
|
924
949
|
const sceneBefore = this.#state.scene;
|
|
@@ -1002,24 +1027,35 @@ export class EngineCore {
|
|
|
1002
1027
|
return kept;
|
|
1003
1028
|
}
|
|
1004
1029
|
// ──────────────────────────────────────────────────────── commands on the selection
|
|
1005
|
-
/**
|
|
1030
|
+
/**
|
|
1031
|
+
* Changes how the selection looks. `commit: false` is for a slider that is still being dragged: call `commit()` when it ends.
|
|
1032
|
+
*
|
|
1033
|
+
* What the person chose is also what the next element of each kind in the selection starts with, until they choose again (a
|
|
1034
|
+
* rectangle's fill, stroke and width are the next rectangle's, the next ellipse's, the next star's; an arrow's colour is the next
|
|
1035
|
+
* arrow's; a text's size is the next text's; the colour of a line drawn by hand is the pen's). It is kept for every change, a drag
|
|
1036
|
+
* of a slider included and a value the selection has already, and the host is told (`onStyleRemembered`). See `core/styleMemory.ts`.
|
|
1037
|
+
*/
|
|
1006
1038
|
setStyle(patch, options = {}) {
|
|
1007
1039
|
const scene = this.#state.scene;
|
|
1008
1040
|
const targetIds = withDescendantIds(scene, this.#state.selectedIds);
|
|
1009
1041
|
let changed = false;
|
|
1042
|
+
const edits = [];
|
|
1010
1043
|
const next = scene.map((object) => {
|
|
1011
1044
|
if (!targetIds.has(object.id) || object.type === 'group')
|
|
1012
1045
|
return object;
|
|
1046
|
+
const edit = styleEditOf(object, patch);
|
|
1047
|
+
if (edit)
|
|
1048
|
+
edits.push(edit);
|
|
1013
1049
|
const styled = applyStylePatch(object, patch);
|
|
1014
1050
|
if (styled === object)
|
|
1015
1051
|
return object;
|
|
1016
1052
|
changed = true;
|
|
1017
1053
|
return this.#fitText(styled);
|
|
1018
1054
|
});
|
|
1019
|
-
if (
|
|
1020
|
-
|
|
1021
|
-
this
|
|
1022
|
-
return
|
|
1055
|
+
if (changed)
|
|
1056
|
+
this.applyScene(next, options.commit === false ? 'transient' : 'push');
|
|
1057
|
+
this.#rememberStyleEdits(edits);
|
|
1058
|
+
return changed;
|
|
1023
1059
|
}
|
|
1024
1060
|
/**
|
|
1025
1061
|
* Turns the one selected shape back upright, about its own middle (a double click on the turning dot). One undo step.
|
|
@@ -35,6 +35,22 @@ export declare function brushCentreline(shape: BrushPath): Point[];
|
|
|
35
35
|
* Always something to draw: a line the outline cannot be made of (one point, or none) is a dot.
|
|
36
36
|
*/
|
|
37
37
|
export declare function brushOutlineData(ink: BrushInk, strokeWidth: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* The pressure a straight line (Shift) is drawn at when the device reports none (a mouse, a finger): the one a stroke drawn by
|
|
40
|
+
* 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
|
|
41
|
+
* 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
|
|
42
|
+
* end as at the other.
|
|
43
|
+
*/
|
|
44
|
+
export declare const STRAIGHT_LINE_PRESSURE = 0;
|
|
45
|
+
/** A stretch of a stroke's line held straight (Shift held while drawing): a straight line of one even width between two samples. */
|
|
46
|
+
export interface BrushStraightSpan {
|
|
47
|
+
/** The index of the sample the stretch begins at: where the pointer was when Shift went down. */
|
|
48
|
+
from: number;
|
|
49
|
+
/** The index of the sample the stretch ends at: where the pointer was when Shift went up, or where it is now. */
|
|
50
|
+
to: number;
|
|
51
|
+
/** The pressure (0 to 1) it is drawn at all along; `STRAIGHT_LINE_PRESSURE` when it is not given. */
|
|
52
|
+
pressure?: number;
|
|
53
|
+
}
|
|
38
54
|
export interface BrushStrokeOptions {
|
|
39
55
|
createId?: (prefix: string) => ObjectId;
|
|
40
56
|
/** The colour of the line. */
|
|
@@ -53,6 +69,14 @@ export interface BrushStrokeOptions {
|
|
|
53
69
|
* the hand even while it is still being drawn (the first and the last sample are the two ends it is drawn between).
|
|
54
70
|
*/
|
|
55
71
|
steadyPressure?: number;
|
|
72
|
+
/**
|
|
73
|
+
* The stretches of the line held straight (Shift held while drawing), each between two of the samples (by index). A stretch is
|
|
74
|
+
* drawn as an exact straight line of one even width; what lies between the stretches is the hand's, smoothed as ever, and ends
|
|
75
|
+
* on the sample where a stretch begins and begins again where it ends. A line that is a single stretch from its first sample to
|
|
76
|
+
* its last is a straight line like the one `steadyPressure` draws. Stretches that overlap or have no length are left out, and
|
|
77
|
+
* so are all of them when `steadyPressure` is given (it makes the whole line straight).
|
|
78
|
+
*/
|
|
79
|
+
straightSpans?: readonly BrushStraightSpan[];
|
|
56
80
|
}
|
|
57
81
|
/**
|
|
58
82
|
* The stroke for the samples of a pointer, in world units: the box of its line, the line itself with its pressure, and the
|