@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
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
Figma "Shape Menu": the button with the category icon and a chevron at the end of the toolbar's drawing group, and the menu it
|
|
3
3
|
opens: the eight shapes people reach for (a square, a rounded square, a circle, a triangle, a diamond, a hexagon, a star
|
|
4
|
-
and a pentagon), the media entries (an image
|
|
4
|
+
and a pentagon), the media entries (the person's files, when the page offers them, then an image and an SVG), and "More shapes",
|
|
5
|
+
which opens the whole library by group.
|
|
5
6
|
|
|
6
7
|
The menu is the design system's Dropdown Menu, portaled so it is not clipped by a hosting card (see floatingLayer.ts).
|
|
7
8
|
Choosing a shape does not draw it: it arms the tool,
|
|
8
9
|
and the shape is dragged out on the board, as for every tool.
|
|
10
|
+
|
|
11
|
+
Each tile has a tooltip with the shape's name and, when it has one, its key (the same tooltip as the toolbar's buttons). The keys
|
|
12
|
+
of the shapes work while the menu is open: the host answers them (see `CanvasHost`), the tool changes and the menu stays open,
|
|
13
|
+
so the mark moves to the tile of the shape as it is looked at.
|
|
9
14
|
-->
|
|
10
15
|
<script lang="ts">
|
|
11
16
|
import { DropdownMenu } from '@widgetic/design-system/components';
|
|
12
17
|
import type { ToolId } from '../../engine/state.js';
|
|
13
18
|
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
14
19
|
import { categoryLabel } from '../../i18n/labels.js';
|
|
20
|
+
import { TOOL_KEYS } from '../../i18n/shortcuts.js';
|
|
15
21
|
import { getShapeByKey, getShapesByCategory } from '../shapes/ShapeLibrary.js';
|
|
16
22
|
import type { LibraryShape } from '../shapes/ShapeLibrary.js';
|
|
17
23
|
import type { CanvasHost } from '../host/CanvasHost.js';
|
|
@@ -23,16 +29,19 @@
|
|
|
23
29
|
MENU_TRIGGER_RING_CLASSES,
|
|
24
30
|
OVERLAY_REDUCED_MOTION_CLASSES,
|
|
25
31
|
SHAPE_LIBRARY_STROKE_WIDTH,
|
|
32
|
+
TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES,
|
|
26
33
|
TOOLBAR_ICON_STROKE_CLASSES
|
|
27
34
|
} from './floatingCard.js';
|
|
28
35
|
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
29
36
|
import { usePopoverSide } from './popoverSide.js';
|
|
37
|
+
import ShortcutTooltip from './ShortcutTooltip.svelte';
|
|
30
38
|
import {
|
|
31
39
|
IconBrowser,
|
|
32
40
|
IconCategory,
|
|
33
41
|
IconChevronDown,
|
|
34
42
|
IconCircle,
|
|
35
43
|
IconDiamond,
|
|
44
|
+
IconFolder,
|
|
36
45
|
IconHexagon,
|
|
37
46
|
IconPentagon,
|
|
38
47
|
IconPhoto,
|
|
@@ -51,9 +60,11 @@
|
|
|
51
60
|
open: boolean;
|
|
52
61
|
/** The key that opens the image chooser, as it is printed on a key cap. */
|
|
53
62
|
imageShortcut: string;
|
|
63
|
+
/** Whether the menu offers the person's file library before the Image entry (the page turned it on and gave the browser that opens it). */
|
|
64
|
+
showFiles?: boolean;
|
|
54
65
|
}
|
|
55
66
|
|
|
56
|
-
let { host, tool, libraryShapeKey, open, imageShortcut }: Props = $props();
|
|
67
|
+
let { host, tool, libraryShapeKey, open, imageShortcut, showFiles = false }: Props = $props();
|
|
57
68
|
|
|
58
69
|
// The menu is drawn into the canvas's floating layer (see floatingLayer.ts).
|
|
59
70
|
const floatingLayer = useFloatingLayer();
|
|
@@ -66,20 +77,24 @@
|
|
|
66
77
|
|
|
67
78
|
const { t } = useCanvasLanguage();
|
|
68
79
|
|
|
69
|
-
/** A tile of the first two rows: what it draws, how it is named, and when it is the one in use. */
|
|
80
|
+
/** A tile of the first two rows: what it draws, how it is named, the key that chooses it (if it has one), and when it is the one in use. */
|
|
70
81
|
interface Tile {
|
|
71
82
|
id: string;
|
|
72
83
|
icon: CanvasIcon;
|
|
73
84
|
label: CanvasMessageKey;
|
|
85
|
+
/** The key that chooses the shape, as it is printed on a key cap: in the tile's tooltip, and its `aria-keyshortcuts`. */
|
|
86
|
+
shortcut?: string;
|
|
74
87
|
active: boolean;
|
|
75
88
|
choose: () => void;
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
const tiles = $derived<Tile[]>([
|
|
79
|
-
{ id: 'rect', icon: IconSquare, label: 'canvas.tool.rectangle', active: tool === 'rect', choose: () => host.onSelectShapeTool('rect') },
|
|
92
|
+
{ id: 'rect', icon: IconSquare, label: 'canvas.tool.rectangle', shortcut: TOOL_KEYS.rectangle, active: tool === 'rect', choose: () => host.onSelectShapeTool('rect') },
|
|
80
93
|
{ id: 'rounded-rect', icon: IconSquareRounded, label: 'canvas.tool.roundedRectangle', active: tool === 'rounded-rect', choose: () => host.onSelectShapeTool('rounded-rect') },
|
|
81
|
-
|
|
82
|
-
|
|
94
|
+
// The round shape of the menu: its key (O) draws the oval, which the menu has no tile of its own for, so the circle's tile is the one
|
|
95
|
+
// that is marked (and that names the key) whether the tool in use is the circle or the oval.
|
|
96
|
+
{ id: 'circle', icon: IconCircle, label: 'canvas.tool.circle', shortcut: TOOL_KEYS.ellipse, active: tool === 'circle' || tool === 'ellipse', choose: () => host.onSelectShapeTool('circle-true') },
|
|
97
|
+
{ id: 'triangle', icon: IconTriangle, label: 'canvas.tool.triangle', shortcut: TOOL_KEYS.triangle, active: tool === 'triangle', choose: () => host.onSelectShapeTool('triangle') },
|
|
83
98
|
libraryTile('diamond', IconDiamond),
|
|
84
99
|
libraryTile('hexagon', IconHexagon),
|
|
85
100
|
libraryTile('star', IconStar),
|
|
@@ -117,7 +132,7 @@
|
|
|
117
132
|
type="button"
|
|
118
133
|
aria-label={$t('canvas.tool.shapes')}
|
|
119
134
|
data-active={shapeToolInUse ? '' : undefined}
|
|
120
|
-
class="flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground transition-colors duration-fast hover:bg-accent focus-visible:outline-hidden data-[active]:bg-brand-subtle {MENU_TRIGGER_RING_CLASSES} [&_svg]:size-4 {TOOLBAR_ICON_STROKE_CLASSES}"
|
|
135
|
+
class="flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground transition-colors duration-fast hover:bg-accent focus-visible:bg-accent focus-visible:outline-hidden data-[active]:bg-brand-subtle {TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} {MENU_TRIGGER_RING_CLASSES} [&_svg]:size-4 {TOOLBAR_ICON_STROKE_CLASSES}"
|
|
121
136
|
>
|
|
122
137
|
<IconCategory />
|
|
123
138
|
<IconChevronDown class="transition-transform duration-fast motion-reduce:transition-none data-[open]:rotate-180" data-open={open ? '' : undefined} />
|
|
@@ -125,25 +140,39 @@
|
|
|
125
140
|
{/snippet}
|
|
126
141
|
</DropdownMenu.Trigger>
|
|
127
142
|
|
|
128
|
-
|
|
143
|
+
<!-- `data-canvas-ui`: the menu (its "More shapes" submenu sits inside it) is the canvas's own even when it is portaled to `document.body` (a page without a shadow root), so a press on a tile is not a press outside the canvas (`outsideClickDeselect.ts`). -->
|
|
144
|
+
<DropdownMenu.Content side={menuSide} align={menuAlign} sideOffset={8} portalProps={canvasOverlayPortalProps($floatingLayer)} aria-label={$t('canvas.tool.shapes')} data-canvas-ui class="{CANVAS_OVERLAY_Z_CLASS} w-[196px] {MENU_PADDING_CLASS} shadow-floating focus-visible:outline-hidden {OVERLAY_REDUCED_MOTION_CLASSES}">
|
|
129
145
|
<DropdownMenu.Label>{$t('canvas.tool.shapes')}</DropdownMenu.Label>
|
|
130
146
|
<div class="grid grid-cols-4 gap-x-3 px-1" role="presentation">
|
|
131
147
|
{#each tiles as tile (tile.id)}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
<!-- The pointer gives a menu entry the focus as it passes, so only a focus from the keyboard opens the tooltip at once. -->
|
|
149
|
+
<ShortcutTooltip label={$t(tile.label)} shortcut={tile.shortcut} side="top" ignoreNonKeyboardFocus passive>
|
|
150
|
+
{#snippet trigger(triggerProps)}
|
|
151
|
+
<DropdownMenu.Item
|
|
152
|
+
{...triggerProps}
|
|
153
|
+
aria-label={$t(tile.label)}
|
|
154
|
+
aria-keyshortcuts={tile.shortcut}
|
|
155
|
+
aria-current={tile.active ? 'true' : undefined}
|
|
156
|
+
data-active={tile.active ? '' : undefined}
|
|
157
|
+
class="size-9 min-h-9 justify-center p-0 data-[active]:bg-brand-subtle {TOOLBAR_ICON_STROKE_CLASSES}"
|
|
158
|
+
onSelect={tile.choose}
|
|
159
|
+
>
|
|
160
|
+
<tile.icon class="size-4" />
|
|
161
|
+
</DropdownMenu.Item>
|
|
162
|
+
{/snippet}
|
|
163
|
+
</ShortcutTooltip>
|
|
142
164
|
{/each}
|
|
143
165
|
</div>
|
|
144
166
|
|
|
145
167
|
<DropdownMenu.Separator />
|
|
146
168
|
<DropdownMenu.Label>{$t('canvas.menu.media')}</DropdownMenu.Label>
|
|
169
|
+
<!-- The person's file library (the page's File Browser, in select state). Only when the page turned it on: it is off by default. -->
|
|
170
|
+
{#if showFiles}
|
|
171
|
+
<DropdownMenu.Item data-canvas-files-entry onSelect={() => void host.openFileBrowser()}>
|
|
172
|
+
<IconFolder />
|
|
173
|
+
<span class="flex-1">{$t('canvas.tool.files')}</span>
|
|
174
|
+
</DropdownMenu.Item>
|
|
175
|
+
{/if}
|
|
147
176
|
<DropdownMenu.Item aria-keyshortcuts={imageShortcut} onSelect={() => void host.addImage()}>
|
|
148
177
|
<IconPhoto />
|
|
149
178
|
<span class="flex-1">{$t('canvas.tool.image')}</span>
|
|
@@ -161,19 +190,24 @@
|
|
|
161
190
|
<DropdownMenu.Label>{categoryLabel(category, $t)}</DropdownMenu.Label>
|
|
162
191
|
<div class="grid grid-cols-5 gap-1 px-1 pb-1" role="presentation">
|
|
163
192
|
{#each shapes as shape (shape.key)}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
193
|
+
<!-- The shapes of the library have no key: their tooltip is the name alone. -->
|
|
194
|
+
<ShortcutTooltip label={$t(shape.labelKey)} side="top" ignoreNonKeyboardFocus passive>
|
|
195
|
+
{#snippet trigger(triggerProps)}
|
|
196
|
+
<DropdownMenu.Item
|
|
197
|
+
{...triggerProps}
|
|
198
|
+
aria-label={$t(shape.labelKey)}
|
|
199
|
+
aria-current={tool === 'library-shape' && libraryShapeKey === shape.key ? 'true' : undefined}
|
|
200
|
+
data-active={tool === 'library-shape' && libraryShapeKey === shape.key ? '' : undefined}
|
|
201
|
+
class="size-9 min-h-9 justify-center p-0 data-[active]:bg-brand-subtle"
|
|
202
|
+
onSelect={() => host.onSelectLibraryShapeTool(shape.key)}
|
|
203
|
+
>
|
|
204
|
+
<!-- The width is an inline style on purpose: the menu item's `[&_svg]:stroke-2` would beat the attribute (see floatingCard.ts). -->
|
|
205
|
+
<svg viewBox="0 0 100 100" class="size-4" fill="none" stroke="currentColor" style:stroke-width={SHAPE_LIBRARY_STROKE_WIDTH} stroke-linejoin="round" stroke-linecap="round" aria-hidden="true">
|
|
206
|
+
<path d={shape.pathData} />
|
|
207
|
+
</svg>
|
|
208
|
+
</DropdownMenu.Item>
|
|
209
|
+
{/snippet}
|
|
210
|
+
</ShortcutTooltip>
|
|
177
211
|
{/each}
|
|
178
212
|
</div>
|
|
179
213
|
{/each}
|
|
@@ -9,6 +9,8 @@ interface Props {
|
|
|
9
9
|
open: boolean;
|
|
10
10
|
/** The key that opens the image chooser, as it is printed on a key cap. */
|
|
11
11
|
imageShortcut: string;
|
|
12
|
+
/** Whether the menu offers the person's file library before the Image entry (the page turned it on and gave the browser that opens it). */
|
|
13
|
+
showFiles?: boolean;
|
|
12
14
|
}
|
|
13
15
|
declare const ShapesMenu: import("svelte").Component<Props, {}, "">;
|
|
14
16
|
type ShapesMenu = ReturnType<typeof ShapesMenu>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The tooltip of a control of the chrome: its name and, when it has one, the key that does the same, on a key cap (Figma "Tool
|
|
3
|
+
Button" tooltip). The toolbar's buttons and the tiles of the Shapes menu draw it, so the two look and behave alike.
|
|
4
|
+
|
|
5
|
+
The control is whatever the caller draws, handed in as the `trigger` snippet: it is given the props of the tooltip's trigger to
|
|
6
|
+
spread onto its element (an Icon Button, a plain button, an entry of a menu). The tooltip is drawn into the canvas's floating
|
|
7
|
+
layer, not in place (see floatingLayer.ts), and it opens after the delay the canvas's provider gives it (`CANVAS_TOOLTIP_DELAY_MS`,
|
|
8
|
+
set in DomCanvas.svelte).
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import type { Snippet } from 'svelte';
|
|
12
|
+
import { Tooltip } from '@widgetic/design-system/components';
|
|
13
|
+
import { CANVAS_OVERLAY_Z_CLASS, OVERLAY_REDUCED_MOTION_CLASSES } from './floatingCard.js';
|
|
14
|
+
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
15
|
+
import { usePopoverSide } from './popoverSide.js';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
/** What the control does: the first line of the tooltip. */
|
|
19
|
+
label: string;
|
|
20
|
+
/** The key that does the same, as it is printed on a key cap ("V"), or nothing: the tooltip is then the name alone. */
|
|
21
|
+
shortcut?: string | undefined;
|
|
22
|
+
/** The side the tooltip opens on. Left out: away from the edge the toolbar stands against (see popoverSide.ts). */
|
|
23
|
+
side?: 'top' | 'right' | 'bottom' | 'left' | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* For a control the pointer gives the focus to by itself (the entries of a menu take the focus as the pointer passes over
|
|
26
|
+
* them): only a focus that comes from the keyboard opens the tooltip at once, and the pointer opens it after its delay.
|
|
27
|
+
*/
|
|
28
|
+
ignoreNonKeyboardFocus?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The tooltip closes as soon as the pointer leaves the control and cannot be hovered itself, so it never stands between the
|
|
31
|
+
* pointer and the controls it overlaps (the tiles of a menu lie close together).
|
|
32
|
+
*/
|
|
33
|
+
passive?: boolean;
|
|
34
|
+
/** The control. It is given the props of the tooltip's trigger, to spread onto its element. */
|
|
35
|
+
trigger: Snippet<[Record<string, unknown>]>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let { label, shortcut = undefined, side = undefined, ignoreNonKeyboardFocus = false, passive = false, trigger }: Props = $props();
|
|
39
|
+
|
|
40
|
+
// The tooltip is drawn into the canvas's floating layer, not in place: see floatingLayer.ts.
|
|
41
|
+
const floatingLayer = useFloatingLayer();
|
|
42
|
+
// Until the canvas has made its layer nothing is mounted (the tooltip is closed then anyway), so the page's body is not written to.
|
|
43
|
+
const overlayPortal = $derived(canvasOverlayPortalProps($floatingLayer));
|
|
44
|
+
// It opens away from the edge the card stands on: upward from the bottom, downward from the top, sideways from a side.
|
|
45
|
+
const popoverSide = usePopoverSide();
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<Tooltip.Root {ignoreNonKeyboardFocus} disableHoverableContent={passive}>
|
|
49
|
+
<Tooltip.Trigger>
|
|
50
|
+
{#snippet child({ props }: { props: Record<string, unknown> })}
|
|
51
|
+
{@render trigger(props)}
|
|
52
|
+
{/snippet}
|
|
53
|
+
</Tooltip.Trigger>
|
|
54
|
+
<Tooltip.Portal to={overlayPortal.to} disabled={overlayPortal.disabled}>
|
|
55
|
+
<Tooltip.Content side={side ?? popoverSide()} sideOffset={passive ? 6 : 8} class="{CANVAS_OVERLAY_Z_CLASS} {OVERLAY_REDUCED_MOTION_CLASSES} {passive ? 'pointer-events-none' : ''}">
|
|
56
|
+
<span class="flex items-center gap-2">
|
|
57
|
+
<span>{label}</span>
|
|
58
|
+
{#if shortcut}
|
|
59
|
+
<kbd class="rounded-sm bg-muted px-1.5 py-0.5 font-sans text-xs text-muted-foreground">{shortcut}</kbd>
|
|
60
|
+
{/if}
|
|
61
|
+
</span>
|
|
62
|
+
</Tooltip.Content>
|
|
63
|
+
</Tooltip.Portal>
|
|
64
|
+
</Tooltip.Root>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** What the control does: the first line of the tooltip. */
|
|
4
|
+
label: string;
|
|
5
|
+
/** The key that does the same, as it is printed on a key cap ("V"), or nothing: the tooltip is then the name alone. */
|
|
6
|
+
shortcut?: string | undefined;
|
|
7
|
+
/** The side the tooltip opens on. Left out: away from the edge the toolbar stands against (see popoverSide.ts). */
|
|
8
|
+
side?: 'top' | 'right' | 'bottom' | 'left' | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* For a control the pointer gives the focus to by itself (the entries of a menu take the focus as the pointer passes over
|
|
11
|
+
* them): only a focus that comes from the keyboard opens the tooltip at once, and the pointer opens it after its delay.
|
|
12
|
+
*/
|
|
13
|
+
ignoreNonKeyboardFocus?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The tooltip closes as soon as the pointer leaves the control and cannot be hovered itself, so it never stands between the
|
|
16
|
+
* pointer and the controls it overlaps (the tiles of a menu lie close together).
|
|
17
|
+
*/
|
|
18
|
+
passive?: boolean;
|
|
19
|
+
/** The control. It is given the props of the tooltip's trigger, to spread onto its element. */
|
|
20
|
+
trigger: Snippet<[Record<string, unknown>]>;
|
|
21
|
+
}
|
|
22
|
+
declare const ShortcutTooltip: import("svelte").Component<Props, {}, "">;
|
|
23
|
+
type ShortcutTooltip = ReturnType<typeof ShortcutTooltip>;
|
|
24
|
+
export default ShortcutTooltip;
|
|
@@ -7,17 +7,19 @@
|
|
|
7
7
|
-->
|
|
8
8
|
<script lang="ts">
|
|
9
9
|
import type { Snippet } from 'svelte';
|
|
10
|
-
import { IconButton
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import { usePopoverSide } from './popoverSide.js';
|
|
10
|
+
import { IconButton } from '@widgetic/design-system/components';
|
|
11
|
+
import { TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES } from './floatingCard.js';
|
|
12
|
+
import ShortcutTooltip from './ShortcutTooltip.svelte';
|
|
14
13
|
|
|
15
14
|
interface Props {
|
|
16
15
|
/** What the button does. It is the accessible name and the first line of the tooltip. */
|
|
17
16
|
label: string;
|
|
18
17
|
/** The key that does the same, as it is printed on a key cap ("V"), or nothing. It is also the button's `aria-keyshortcuts`. */
|
|
19
18
|
shortcut?: string | undefined;
|
|
20
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* A second key that does the same ("1", the number of the tool): a second entry of `aria-keyshortcuts`. The tooltip does not
|
|
21
|
+
* draw it (the letter is the one the person is shown); the key still works.
|
|
22
|
+
*/
|
|
21
23
|
alternateShortcut?: string | undefined;
|
|
22
24
|
/** The tool this button chooses is the one in use. */
|
|
23
25
|
active?: boolean;
|
|
@@ -36,59 +38,36 @@
|
|
|
36
38
|
// `aria-keyshortcuts` lists the keys that do the same, separated by a space ("V 1").
|
|
37
39
|
const keyShortcuts = $derived([shortcut, alternateShortcut].filter(Boolean).join(' ') || undefined);
|
|
38
40
|
|
|
39
|
-
// The tooltip is drawn into the canvas's floating layer, not in place: see floatingLayer.ts.
|
|
40
|
-
const floatingLayer = useFloatingLayer();
|
|
41
|
-
// Until the canvas has made its layer nothing is mounted (the tooltip is closed then anyway), so the page's body is not written to.
|
|
42
|
-
const overlayPortal = $derived(canvasOverlayPortalProps($floatingLayer));
|
|
43
|
-
// It opens away from the edge the card stands on: upward from the bottom, downward from the top, sideways from a side.
|
|
44
|
-
const popoverSide = usePopoverSide();
|
|
45
|
-
|
|
46
41
|
// Written out in full, so that the stylesheet of a page that installs the canvas picks every class up.
|
|
47
42
|
const SQUARE_CLASSES = { toolbar: 'size-9', compact: 'size-8' } as const;
|
|
48
43
|
// The zoom level is a real button, so it shrinks a little while it is pressed like the zoom buttons beside it, through the design
|
|
49
|
-
// system's `press-feedback` (which keeps still for a person who asked for less motion).
|
|
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
|
+
// 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
|
+
// 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.
|
|
50
48
|
const LEVEL_CLASSES =
|
|
51
|
-
'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:
|
|
52
|
-
// The design system's Icon Button shows the keyboard focus by a tint of its background, and the brand tint of the tool that is on
|
|
53
|
-
// is a background too, that wins over it: the tool in use, which is where the keyboard begins, showed no focus at all (found with
|
|
54
|
-
// the accessibility check). It gets the ring that the zoom level and the Shapes button show, and only when the keyboard has the focus.
|
|
55
|
-
const ACTIVE_FOCUS_CLASSES = 'data-[active]:focus-visible:ring-2 data-[active]:focus-visible:ring-ring';
|
|
49
|
+
'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 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50';
|
|
56
50
|
</script>
|
|
57
51
|
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
{#
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
</Tooltip.Trigger>
|
|
81
|
-
<Tooltip.Portal to={overlayPortal.to} disabled={overlayPortal.disabled}>
|
|
82
|
-
<Tooltip.Content side={popoverSide()} sideOffset={8} class="{CANVAS_OVERLAY_Z_CLASS} {OVERLAY_REDUCED_MOTION_CLASSES}">
|
|
83
|
-
<span class="flex items-center gap-2">
|
|
84
|
-
<span>{label}</span>
|
|
85
|
-
{#if shortcut}
|
|
86
|
-
<kbd class="rounded-sm bg-muted px-1.5 py-0.5 font-sans text-xs text-muted-foreground">{shortcut}</kbd>
|
|
87
|
-
{/if}
|
|
88
|
-
{#if alternateShortcut}
|
|
89
|
-
<kbd class="rounded-sm bg-muted px-1.5 py-0.5 font-sans text-xs text-muted-foreground">{alternateShortcut}</kbd>
|
|
90
|
-
{/if}
|
|
91
|
-
</span>
|
|
92
|
-
</Tooltip.Content>
|
|
93
|
-
</Tooltip.Portal>
|
|
94
|
-
</Tooltip.Root>
|
|
52
|
+
<ShortcutTooltip {label} {shortcut}>
|
|
53
|
+
{#snippet trigger(props)}
|
|
54
|
+
{#if size === 'level'}
|
|
55
|
+
<button {...props} type="button" aria-label={label} aria-keyshortcuts={keyShortcuts} {disabled} {onclick} class="{LEVEL_CLASSES} {className}">
|
|
56
|
+
{@render children()}
|
|
57
|
+
</button>
|
|
58
|
+
{:else}
|
|
59
|
+
<IconButton
|
|
60
|
+
{...props}
|
|
61
|
+
{label}
|
|
62
|
+
{disabled}
|
|
63
|
+
{onclick}
|
|
64
|
+
aria-pressed={toggle ? active : undefined}
|
|
65
|
+
aria-keyshortcuts={keyShortcuts}
|
|
66
|
+
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
|
+
>
|
|
69
|
+
{@render children()}
|
|
70
|
+
</IconButton>
|
|
71
|
+
{/if}
|
|
72
|
+
{/snippet}
|
|
73
|
+
</ShortcutTooltip>
|
|
@@ -4,7 +4,10 @@ interface Props {
|
|
|
4
4
|
label: string;
|
|
5
5
|
/** The key that does the same, as it is printed on a key cap ("V"), or nothing. It is also the button's `aria-keyshortcuts`. */
|
|
6
6
|
shortcut?: string | undefined;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* A second key that does the same ("1", the number of the tool): a second entry of `aria-keyshortcuts`. The tooltip does not
|
|
9
|
+
* draw it (the letter is the one the person is shown); the key still works.
|
|
10
|
+
*/
|
|
8
11
|
alternateShortcut?: string | undefined;
|
|
9
12
|
/** The tool this button chooses is the one in use. */
|
|
10
13
|
active?: boolean;
|
|
@@ -34,15 +34,37 @@ 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
|
-
* The ring of a menu's button while its menu is open
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* The ring of a menu's button while its menu is open: 2 px of ring standing 2 px off the button, with the board's colour in the
|
|
38
|
+
* gap, as the design system draws its focus ring. Figma draws the open "Shapes" button that way (the ring makes it 59 x 44, the
|
|
39
|
+
* height of the toolbar). The keyboard focus has no ring on the buttons of the chrome: it takes the look of the hover, as it does
|
|
40
|
+
* on the design system's Icon Button (a ring stayed on the button the pointer had clicked as soon as a shortcut key was pressed).
|
|
40
41
|
*
|
|
41
42
|
* It is two plain shadows, not Tailwind's `ring-2 ring-offset-2`: the design system's global stylesheet zeroes
|
|
42
43
|
* `--tw-ring-offset-width` with `!important` on every element that has `aria-expanded` (a menu's button always has), so the
|
|
43
44
|
* offset of a ring on such a button is lost, whatever class asks for it.
|
|
44
45
|
*/
|
|
45
|
-
export declare const MENU_TRIGGER_RING_CLASSES = "
|
|
46
|
+
export declare const MENU_TRIGGER_RING_CLASSES = "data-[state=open]:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)]";
|
|
47
|
+
/**
|
|
48
|
+
* 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
|
+
* 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
|
|
50
|
+
* design system's own rule for its buttons. A button that is on has no look of the hover to take (the tint is already there), and
|
|
51
|
+
* with nothing at all the person who works by keyboard could not see where the focus is (the accessibility check of the browser
|
|
52
|
+
* scripts reads exactly that).
|
|
53
|
+
*
|
|
54
|
+
* The `data-[active]` and `focus-visible` variants are stacked so that this beats both `data-[active]:bg-brand-subtle` and the
|
|
55
|
+
* design system's `focus-visible:bg-accent`.
|
|
56
|
+
*/
|
|
57
|
+
export declare const TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES = "data-[active]:focus-visible:bg-brand/40";
|
|
58
|
+
/**
|
|
59
|
+
* How long the pointer rests on a button of the chrome before its tooltip (the name and the key) opens, in milliseconds. The
|
|
60
|
+
* tooltips were quicker and opened on the way across the toolbar; this is the delay of the design system's own tooltips.
|
|
61
|
+
*/
|
|
62
|
+
export declare const CANVAS_TOOLTIP_DELAY_MS = 700;
|
|
63
|
+
/**
|
|
64
|
+
* After one tooltip has closed, the time within which the next button the pointer rests on opens its tooltip at once, so that
|
|
65
|
+
* moving along the toolbar to the next tool reads as one hover.
|
|
66
|
+
*/
|
|
67
|
+
export declare const CANVAS_TOOLTIP_SKIP_DELAY_MS = 200;
|
|
46
68
|
/**
|
|
47
69
|
* Tabler toolbar icons are 16 px (`size-4`) with stroke 2 in a 24 px viewBox: 2 × 16 / 24 = 1.333 px on screen.
|
|
48
70
|
* A library shape glyph is drawn in a 100 px viewBox, so it needs a stroke of 1.333 × 100 / 16 = 8.33 in its own units to
|
|
@@ -34,15 +34,37 @@ 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
|
-
* The ring of a menu's button while its menu is open
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* The ring of a menu's button while its menu is open: 2 px of ring standing 2 px off the button, with the board's colour in the
|
|
38
|
+
* gap, as the design system draws its focus ring. Figma draws the open "Shapes" button that way (the ring makes it 59 x 44, the
|
|
39
|
+
* height of the toolbar). The keyboard focus has no ring on the buttons of the chrome: it takes the look of the hover, as it does
|
|
40
|
+
* on the design system's Icon Button (a ring stayed on the button the pointer had clicked as soon as a shortcut key was pressed).
|
|
40
41
|
*
|
|
41
42
|
* It is two plain shadows, not Tailwind's `ring-2 ring-offset-2`: the design system's global stylesheet zeroes
|
|
42
43
|
* `--tw-ring-offset-width` with `!important` on every element that has `aria-expanded` (a menu's button always has), so the
|
|
43
44
|
* offset of a ring on such a button is lost, whatever class asks for it.
|
|
44
45
|
*/
|
|
45
|
-
export const MENU_TRIGGER_RING_CLASSES = '
|
|
46
|
+
export const MENU_TRIGGER_RING_CLASSES = 'data-[state=open]:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)]';
|
|
47
|
+
/**
|
|
48
|
+
* 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
|
+
* 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
|
|
50
|
+
* design system's own rule for its buttons. A button that is on has no look of the hover to take (the tint is already there), and
|
|
51
|
+
* with nothing at all the person who works by keyboard could not see where the focus is (the accessibility check of the browser
|
|
52
|
+
* scripts reads exactly that).
|
|
53
|
+
*
|
|
54
|
+
* The `data-[active]` and `focus-visible` variants are stacked so that this beats both `data-[active]:bg-brand-subtle` and the
|
|
55
|
+
* design system's `focus-visible:bg-accent`.
|
|
56
|
+
*/
|
|
57
|
+
export const TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES = 'data-[active]:focus-visible:bg-brand/40';
|
|
58
|
+
/**
|
|
59
|
+
* How long the pointer rests on a button of the chrome before its tooltip (the name and the key) opens, in milliseconds. The
|
|
60
|
+
* tooltips were quicker and opened on the way across the toolbar; this is the delay of the design system's own tooltips.
|
|
61
|
+
*/
|
|
62
|
+
export const CANVAS_TOOLTIP_DELAY_MS = 700;
|
|
63
|
+
/**
|
|
64
|
+
* After one tooltip has closed, the time within which the next button the pointer rests on opens its tooltip at once, so that
|
|
65
|
+
* moving along the toolbar to the next tool reads as one hover.
|
|
66
|
+
*/
|
|
67
|
+
export const CANVAS_TOOLTIP_SKIP_DELAY_MS = 200;
|
|
46
68
|
/**
|
|
47
69
|
* Tabler toolbar icons are 16 px (`size-4`) with stroke 2 in a 24 px viewBox: 2 × 16 / 24 = 1.333 px on screen.
|
|
48
70
|
* A library shape glyph is drawn in a 100 px viewBox, so it needs a stroke of 1.333 × 100 / 16 = 8.33 in its own units to
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* of what the chrome uses is visible at a glance and no component reaches for an icon library of its own.
|
|
4
4
|
*/
|
|
5
5
|
import type { IconSquare as SquareIcon } from '@widgetic/design-system/icons';
|
|
6
|
-
export { IconAlertTriangle, IconAlignCenter, IconAlignLeft, IconAlignRight, IconArrowBackUp, IconArrowBarToDown, IconArrowBarToUp, IconArrowForwardUp, IconArrowsMaximize, IconArrowUpRight, IconBold, IconBrowser, IconCamera, IconCategory, IconCheck, IconChevronDown, IconCircle, IconClipboard, IconCopy, IconDeviceFloppy, IconDiamond, IconEraser, IconHexagon, IconItalic, IconLink, IconLoader2, IconPencil, IconPentagon, IconPhoto, IconPointer, IconRefresh, IconReplace, IconScissors, IconSelectAll, IconSettings, IconSquare, IconSquareRounded, IconStack, IconStack2, IconStackBack, IconStackFront, IconStackPop, IconStar, IconTrash, IconTriangle, IconTypography, IconUnderline, IconX, IconZoomIn, IconZoomOut } from '@widgetic/design-system/icons';
|
|
6
|
+
export { IconAlertTriangle, IconAlignCenter, IconAlignLeft, IconAlignRight, IconArrowBackUp, IconArrowBarToDown, IconArrowBarToUp, IconArrowForwardUp, IconArrowsMaximize, IconArrowUpRight, IconBold, IconBrowser, IconCamera, IconCategory, IconCheck, IconChevronDown, IconCircle, IconClipboard, IconCopy, IconDeviceFloppy, IconDiamond, IconEraser, IconFolder, IconHexagon, IconItalic, IconLink, IconLoader2, IconPencil, IconPentagon, IconPhoto, IconPointer, IconRefresh, IconReplace, IconScissors, IconSelectAll, IconSettings, IconSquare, IconSquareRounded, IconStack, IconStack2, IconStackBack, IconStackFront, IconStackPop, IconStar, IconTrash, IconTriangle, IconTypography, IconUnderline, IconX, IconZoomIn, IconZoomOut } from '@widgetic/design-system/icons';
|
|
7
7
|
export { SquareDashedMousePointer as IconSelectElement } from '@widgetic/design-system/icons';
|
|
8
8
|
/**
|
|
9
9
|
* What a Tabler icon is: a component class that every icon of the set shares the shape of. A row of a menu keeps its icon
|
package/dist/canvas/ui/icons.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Every icon the canvas draws, imported from the Widgetic design system's own set (Tabler) in this one place, so the list
|
|
3
3
|
* of what the chrome uses is visible at a glance and no component reaches for an icon library of its own.
|
|
4
4
|
*/
|
|
5
|
-
export { IconAlertTriangle, IconAlignCenter, IconAlignLeft, IconAlignRight, IconArrowBackUp, IconArrowBarToDown, IconArrowBarToUp, IconArrowForwardUp, IconArrowsMaximize, IconArrowUpRight, IconBold, IconBrowser, IconCamera, IconCategory, IconCheck, IconChevronDown, IconCircle, IconClipboard, IconCopy, IconDeviceFloppy, IconDiamond, IconEraser, IconHexagon, IconItalic, IconLink, IconLoader2, IconPencil, IconPentagon, IconPhoto, IconPointer, IconRefresh, IconReplace, IconScissors, IconSelectAll, IconSettings, IconSquare, IconSquareRounded, IconStack, IconStack2, IconStackBack, IconStackFront, IconStackPop, IconStar, IconTrash, IconTriangle, IconTypography, IconUnderline, IconX, IconZoomIn, IconZoomOut } from '@widgetic/design-system/icons';
|
|
5
|
+
export { IconAlertTriangle, IconAlignCenter, IconAlignLeft, IconAlignRight, IconArrowBackUp, IconArrowBarToDown, IconArrowBarToUp, IconArrowForwardUp, IconArrowsMaximize, IconArrowUpRight, IconBold, IconBrowser, IconCamera, IconCategory, IconCheck, IconChevronDown, IconCircle, IconClipboard, IconCopy, IconDeviceFloppy, IconDiamond, IconEraser, IconFolder, IconHexagon, IconItalic, IconLink, IconLoader2, IconPencil, IconPentagon, IconPhoto, IconPointer, IconRefresh, IconReplace, IconScissors, IconSelectAll, IconSettings, IconSquare, IconSquareRounded, IconStack, IconStack2, IconStackBack, IconStackFront, IconStackPop, IconStar, IconTrash, IconTriangle, IconTypography, IconUnderline, IconX, IconZoomIn, IconZoomOut } from '@widgetic/design-system/icons';
|
|
6
6
|
// The element selector's own icon exists only in the Lucide set of the design system's barrel.
|
|
7
7
|
export { SquareDashedMousePointer as IconSelectElement } from '@widgetic/design-system/icons';
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { Scene } from '../../engine/core/scene.js';
|
|
9
9
|
import type { ObjectId, SceneObject, ShapeObject, TextAlign, WidgetObject } from '../../engine/core/types.js';
|
|
10
|
+
import type { PenStyle } from '../../engine/state.js';
|
|
10
11
|
/** A value the selected shapes share, differ in, or do not have at all. */
|
|
11
12
|
export type Trait<T> = {
|
|
12
13
|
kind: 'none';
|
|
@@ -47,8 +48,19 @@ export interface SelectionTraits {
|
|
|
47
48
|
}
|
|
48
49
|
/** Describes the selection for the panel. */
|
|
49
50
|
export declare function describeSelection(scene: Scene, selectedIds: readonly ObjectId[]): SelectionTraits;
|
|
51
|
+
/**
|
|
52
|
+
* What the panel shows for the pen of the Draw tool, when the tool is chosen and nothing is selected: the controls a line drawn by
|
|
53
|
+
* hand has (its colour as the Stroke, its width, its opacity), each with the one value the pen has. The pen has no inside, no
|
|
54
|
+
* corners and no text, and nothing of it is on the board yet: there is nothing to select, so there are no targets and no units.
|
|
55
|
+
*/
|
|
56
|
+
export declare function describePenStyle(pen: PenStyle): SelectionTraits;
|
|
50
57
|
/** The number of a trait for a control, or a fallback when the shapes differ or the control does not apply. */
|
|
51
58
|
export declare function traitNumber(trait: Trait<number>, fallback: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* The least the Width control offers for the selection. One number is written to every shape, so it is the highest minimum among
|
|
61
|
+
* the shapes: an arrow, a line-only icon or a brush stroke cannot go to 0 (there would be nothing left of it), a rectangle can.
|
|
62
|
+
*/
|
|
63
|
+
export declare function minimumStrokeWidth(traits: SelectionTraits): number;
|
|
52
64
|
/** What the font size stepper shows: a whole number, never a long float from resizing. */
|
|
53
65
|
export declare function formatFontSizeDisplay(trait: Trait<number>): number | '–';
|
|
54
66
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { isArrow } from '../../engine/core/arrow.js';
|
|
9
9
|
import { isBrushStroke } from '../../engine/core/brush.js';
|
|
10
10
|
import { leafShapesOf, normalizeSelection } from '../../engine/core/scene.js';
|
|
11
|
-
import { lineColorOf, paintsFillOnStroke, pathSupportsRoundness } from '../../engine/core/style.js';
|
|
11
|
+
import { lineColorOf, minimumStrokeWidthOf, paintsFillOnStroke, pathSupportsRoundness } from '../../engine/core/style.js';
|
|
12
12
|
const NONE = { kind: 'none' };
|
|
13
13
|
/** One value out of many: the value they all have, `mixed` when they differ, `none` when there is nothing to compare. */
|
|
14
14
|
export function unify(values) {
|
|
@@ -65,10 +65,35 @@ export function describeSelection(scene, selectedIds) {
|
|
|
65
65
|
widgetCard
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* What the panel shows for the pen of the Draw tool, when the tool is chosen and nothing is selected: the controls a line drawn by
|
|
70
|
+
* hand has (its colour as the Stroke, its width, its opacity), each with the one value the pen has. The pen has no inside, no
|
|
71
|
+
* corners and no text, and nothing of it is on the board yet: there is nothing to select, so there are no targets and no units.
|
|
72
|
+
*/
|
|
73
|
+
export function describePenStyle(pen) {
|
|
74
|
+
return {
|
|
75
|
+
targets: [],
|
|
76
|
+
units: [],
|
|
77
|
+
fill: NONE,
|
|
78
|
+
stroke: { kind: 'same', value: pen.color },
|
|
79
|
+
strokeWidth: { kind: 'same', value: pen.width },
|
|
80
|
+
roundness: NONE,
|
|
81
|
+
opacity: { kind: 'same', value: pen.opacity },
|
|
82
|
+
text: null,
|
|
83
|
+
widgetCard: null
|
|
84
|
+
};
|
|
85
|
+
}
|
|
68
86
|
/** The number of a trait for a control, or a fallback when the shapes differ or the control does not apply. */
|
|
69
87
|
export function traitNumber(trait, fallback) {
|
|
70
88
|
return trait.kind === 'same' ? trait.value : fallback;
|
|
71
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* The least the Width control offers for the selection. One number is written to every shape, so it is the highest minimum among
|
|
92
|
+
* the shapes: an arrow, a line-only icon or a brush stroke cannot go to 0 (there would be nothing left of it), a rectangle can.
|
|
93
|
+
*/
|
|
94
|
+
export function minimumStrokeWidth(traits) {
|
|
95
|
+
return Math.max(0, ...traits.targets.filter(isVector).map(minimumStrokeWidthOf));
|
|
96
|
+
}
|
|
72
97
|
/** What the font size stepper shows: a whole number, never a long float from resizing. */
|
|
73
98
|
export function formatFontSizeDisplay(trait) {
|
|
74
99
|
return trait.kind === 'same' ? Math.round(trait.value) : '–';
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
import type { SelectionDrag } from '../../engine/state.js';
|
|
5
5
|
export interface SizeLabelVisibilityInput {
|
|
6
6
|
hasFrame: boolean;
|
|
7
|
-
/** Any gesture is active (press on body, handle, dot, …). */
|
|
8
|
-
gestureKind: string | null;
|
|
9
7
|
/** Non-null only after the pointer crossed the drag threshold. */
|
|
10
8
|
overlayDragging: SelectionDrag | null;
|
|
11
9
|
}
|
|
12
10
|
/**
|
|
13
11
|
* True only while the selection is being resized (Figma "Selection Box" keeps the size chip hidden at rest;
|
|
14
12
|
* see 515:623 `hidden` on the component board).
|
|
13
|
+
*
|
|
14
|
+
* The size is shown once the pointer has started to drag the handle, and not at the press: the engine only reports a drag
|
|
15
|
+
* (`overlayDragging`) after the pointer went the drag threshold, so a plain click on a handle changes nothing on the board.
|
|
16
|
+
* The kind of gesture is not read here: a resize gesture exists from the press on, before anything is being stretched.
|
|
15
17
|
*/
|
|
16
18
|
export declare function shouldShowRestingSizeLabel(input: SizeLabelVisibilityInput): boolean;
|