@widgetic/canvas 0.5.45 → 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 +3 -2
- package/dist/canvas/DomCanvas.svelte +1 -2
- package/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.js +19 -21
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +6 -5
- package/dist/canvas/host/CanvasHost.js +1664 -1861
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/boardFiles.js +35 -51
- package/dist/canvas/host/browserServices.js +108 -196
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +18 -21
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pauseCollector.d.ts +18 -0
- package/dist/canvas/host/pauseCollector.js +45 -0
- package/dist/canvas/host/pictureSaves.js +9 -11
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.js +149 -243
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/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/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +28 -8
- package/dist/canvas/ui/floatingCard.js +48 -28
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.d.ts +8 -4
- package/dist/canvas/ui/selectionTraits.js +44 -58
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/SelectionOverlay.svelte +2 -2
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +72 -91
- package/dist/canvas/view/liftedScene.js +24 -36
- package/dist/canvas/view/mountedScene.js +76 -79
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/input-controls/ColorIC.svelte +1 -1
- package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +42 -10
- package/dist/engine/EngineCore.js +843 -916
- package/dist/engine/codec/canvasDocument.js +192 -155
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +79 -92
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.d.ts +24 -0
- package/dist/engine/core/brush.js +223 -103
- package/dist/engine/core/cameraMove.js +39 -51
- package/dist/engine/core/defaults.js +92 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +38 -55
- package/dist/engine/core/hitTest.js +68 -81
- package/dist/engine/core/matrix.js +18 -20
- package/dist/engine/core/pathData.js +183 -210
- package/dist/engine/core/rotationReset.js +5 -6
- package/dist/engine/core/scene.js +160 -224
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.d.ts +23 -18
- package/dist/engine/core/shapeTools.js +104 -67
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.d.ts +18 -2
- package/dist/engine/core/style.js +79 -80
- package/dist/engine/core/styleMemory.d.ts +88 -0
- package/dist/engine/core/styleMemory.js +189 -0
- package/dist/engine/core/transform.js +84 -95
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +513 -526
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +8 -3
- package/dist/engine/input/gestures.js +378 -346
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +42 -41
- package/dist/engine/input/selectionHandles.js +45 -50
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +86 -158
- package/dist/engine/state.js +6 -17
- package/dist/engine/text/layoutText.js +43 -62
- package/dist/engine/text/textMetrics.js +8 -10
- package/dist/engine/widgets.js +101 -137
- package/dist/fonts/interFont.js +30 -83
- package/dist/fonts/workspaceFonts.js +33 -92
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/poster/boardPlacement.d.ts +4 -1
- package/dist/poster/boardPlacement.js +34 -33
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedStyles.d.ts +22 -0
- package/dist/settings/rememberedStyles.js +47 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +25 -0
- package/dist/settings/workspaceToolSettings.js +38 -48
- package/dist/tools/components/catalog.js +64 -74
- package/dist/tools/components/grouping.js +6 -28
- package/dist/tools/definitions.js +5 -5
- package/dist/tools/executors.js +137 -169
- package/dist/tools/hostAdapter.js +10 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/styleArguments.js +19 -21
- package/dist/tools/types.js +1 -1
- package/package.json +5 -5
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { CHROME_ANCHORS, normalizeAnchor } from './chromeLayout.js';
|
|
13
13
|
/** The places the toolbar can stand: `TL TC TR` (top), `CL CR` (the sides) and `BL BC BR` (bottom). */
|
|
14
|
-
export
|
|
14
|
+
export const TOOLBAR_POSITIONS = CHROME_ANCHORS;
|
|
15
15
|
/** Where the toolbar stands when the host says nothing: the bottom centre, as it always did. */
|
|
16
|
-
export
|
|
16
|
+
export const DEFAULT_TOOLBAR_POSITION = 'BC';
|
|
17
17
|
/**
|
|
18
18
|
* The position to use for what a host passed. Anything that is not one of the eight (the middle of the board, a word in
|
|
19
19
|
* lower case, nothing at all) is the default, so that a mistake in the host's option never takes the toolbar off the
|
package/dist/canvas/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Importable by both the canvas project and consuming apps (e.g. widget-creator).
|
|
4
4
|
*/
|
|
5
5
|
import type { CanvasSnapShape, SnapRanking, StrokeMeasurements } from './shapes/strokeShapeSnap';
|
|
6
|
-
import type { ViewMoveOptions } from '../engine/EngineCore.js';
|
|
6
|
+
import type { BoardClearCause, ViewMoveOptions } from '../engine/EngineCore.js';
|
|
7
7
|
/** Payload emitted when a frame is converted to a widget via onConvertToWidget callback. */
|
|
8
8
|
export interface WidgetConversionPayload {
|
|
9
9
|
frameName: string;
|
|
@@ -84,6 +84,12 @@ export type StrokeRecognizer = (request: StrokeRecognitionRequest) => Promise<St
|
|
|
84
84
|
* and be told when it is over (and whether the view arrived or the person took it first).
|
|
85
85
|
*/
|
|
86
86
|
export type CanvasMoveOptions = ViewMoveOptions;
|
|
87
|
+
/**
|
|
88
|
+
* Why `onCanvasCleared` was called: the page emptied the board (`onClearAllObjects()`, `'clear-all'`) or the person's delete or cut took
|
|
89
|
+
* the last object off it (`'deleted'`). A page that puts the view back (`flyToContent`) for a board the person emptied reacts to
|
|
90
|
+
* `'deleted'` and to a "Clear canvas" link of its own, and leaves the clears it makes itself (opening another board) alone.
|
|
91
|
+
*/
|
|
92
|
+
export type CanvasClearCause = BoardClearCause;
|
|
87
93
|
/** What `flyToPoint` and `flyToObjects` take besides how the move goes: the zoom to arrive at. */
|
|
88
94
|
export interface CanvasFlyOptions extends CanvasMoveOptions {
|
|
89
95
|
/**
|
|
@@ -17,7 +17,14 @@
|
|
|
17
17
|
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
18
18
|
import { ariaKeyShortcut, isApplePlatform, menuChordText } from './keyHints.js';
|
|
19
19
|
import type { Chord } from './keyHints.js';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
CANVAS_OVERLAY_Z_CLASS,
|
|
22
|
+
LAYER_MENU_ALIGN_OFFSET_PX,
|
|
23
|
+
LAYER_MENU_PADDING_CLASS,
|
|
24
|
+
MENU_PADDING_CLASS,
|
|
25
|
+
OVERLAY_REDUCED_MOTION_CLASSES,
|
|
26
|
+
SUBMENU_SLIDE_UP_CLASSES
|
|
27
|
+
} from './floatingCard.js';
|
|
21
28
|
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
22
29
|
|
|
23
30
|
interface Props {
|
|
@@ -109,6 +116,31 @@
|
|
|
109
116
|
event.preventDefault();
|
|
110
117
|
host.focusBoard();
|
|
111
118
|
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* How far, in pixels, the mouse must travel from where the menu opened before letting go over an entry is a choice (press,
|
|
122
|
+
* drag to an entry, release: the way a menu of the system works). Less than that is the hand's own shake while it clicks.
|
|
123
|
+
*/
|
|
124
|
+
const RELEASE_TRAVEL_IN_PIXELS = 4;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The right button opens the menu as it goes down (on a Mac and on Linux), so its release comes after the menu is on the page,
|
|
128
|
+
* and the menu can be under the pointer by then: drawn upward, when the press was low on the board, its last entry ("Delete")
|
|
129
|
+
* is at the pointer, and while the design system's menu slides in it is a few pixels lower still. The menu's own handling of a
|
|
130
|
+
* release that was not pressed on an entry is to choose that entry, so a right click low on the board could delete what was
|
|
131
|
+
* selected. A release that has not left the point where the menu opened ends the press that opened it: it is not a choice, and
|
|
132
|
+
* the entry under it is left alone (the touch case is `choose`, above). A release after a real drag onto an entry is a choice.
|
|
133
|
+
*/
|
|
134
|
+
function keepReleaseOfOpeningPressFromChoosing(event: PointerEvent): void {
|
|
135
|
+
try {
|
|
136
|
+
if (event.pointerType === 'touch' || !point || !board) return;
|
|
137
|
+
const rect = board.getBoundingClientRect();
|
|
138
|
+
const travelInPixels = Math.hypot(event.clientX - (rect.left + point.x), event.clientY - (rect.top + point.y));
|
|
139
|
+
if (travelInPixels < RELEASE_TRAVEL_IN_PIXELS) event.preventDefault();
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.warn('[CanvasContextMenu] could not tell the release of the opening press from a choice', error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
112
144
|
</script>
|
|
113
145
|
|
|
114
146
|
<!-- The keys are written beside the name for the eye (hidden from the name a screen reader reads) and given as `aria-keyshortcuts`. -->
|
|
@@ -156,6 +188,7 @@
|
|
|
156
188
|
sideOffset={point?.byTouch ? TOUCH_MENU_OFFSET : 0}
|
|
157
189
|
portalProps={canvasOverlayPortalProps($floatingLayer)}
|
|
158
190
|
onCloseAutoFocus={returnFocusToBoard}
|
|
191
|
+
onpointerupcapture={keepReleaseOfOpeningPressFromChoosing}
|
|
159
192
|
aria-label={$t('canvas.panel.actions')}
|
|
160
193
|
data-canvas-ui
|
|
161
194
|
data-canvas-context-menu
|
|
@@ -173,13 +206,17 @@
|
|
|
173
206
|
<DropdownMenu.SubTrigger class="h-8 min-h-8 gap-2 px-2 py-1.5" disabled={!hasSelection}>
|
|
174
207
|
<span class="flex-1 text-body">{$t('canvas.layer.title')}</span>
|
|
175
208
|
</DropdownMenu.SubTrigger>
|
|
209
|
+
<!--
|
|
210
|
+
The first row of the submenu stands level with "Layer order" (`LAYER_MENU_ALIGN_OFFSET_PX` lifts the card by its border and
|
|
211
|
+
padding), and the submenu fades in and slides up like the Shapes menu (`SUBMENU_SLIDE_UP_CLASSES`).
|
|
212
|
+
-->
|
|
176
213
|
<DropdownMenu.SubContent
|
|
177
214
|
align="start"
|
|
178
|
-
alignOffset={
|
|
215
|
+
alignOffset={LAYER_MENU_ALIGN_OFFSET_PX}
|
|
179
216
|
sideOffset={13}
|
|
180
217
|
aria-label={$t('canvas.layer.title')}
|
|
181
218
|
data-canvas-layer-menu
|
|
182
|
-
class="{CANVAS_OVERLAY_Z_CLASS} w-[220px] rounded-xl border border-border bg-popover {LAYER_MENU_PADDING_CLASS} shadow-floating {OVERLAY_REDUCED_MOTION_CLASSES}"
|
|
219
|
+
class="{CANVAS_OVERLAY_Z_CLASS} w-[220px] rounded-xl border border-border bg-popover {LAYER_MENU_PADDING_CLASS} shadow-floating {SUBMENU_SLIDE_UP_CLASSES} {OVERLAY_REDUCED_MOTION_CLASSES}"
|
|
183
220
|
>
|
|
184
221
|
{#each layerRows as row (row.mode)}
|
|
185
222
|
{@render layerMenuRowView(row)}
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
board and never in the way of the pointer. It is shown while the board holds nothing, and goes the moment something is
|
|
4
4
|
drawn. A page that words the line under the title as an empty message (`messages`) gets the tile and the title only.
|
|
5
5
|
|
|
6
|
-
Where it stands:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
the
|
|
6
|
+
Where it stands: on the middle of the board, at any height and any width. A board that is dragged taller (the sketch card of
|
|
7
|
+
the Home page) keeps the hint half way down, as far from the top as from the bottom; it is not held at a fixed distance from the
|
|
8
|
+
top (the design's 312 px), which left it high on a tall board. The toolbar is 44 px high and stands 16 px from the bottom, so a
|
|
9
|
+
board as short as the 320 px card of the Home page still shows the whole hint above it.
|
|
10
|
+
|
|
11
|
+
Its words are said as the design system's empty state says them ("No widgets yet" in an empty project): the title and the line
|
|
12
|
+
under it in the muted colour. The tile keeps the board's own look: the board is `muted`, so a tile of that colour would vanish.
|
|
10
13
|
-->
|
|
11
14
|
<script lang="ts">
|
|
12
15
|
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
@@ -18,17 +21,15 @@
|
|
|
18
21
|
const hintDescription = $derived($t('canvas.hint.description'));
|
|
19
22
|
</script>
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<div class="max-h-[312px] min-h-0 flex-1 max-md:hidden"></div>
|
|
24
|
+
<!-- The hint is centred on the whole board (the same on a phone); the 24 px at the sides keep it off the edges of a narrow board. -->
|
|
25
|
+
<div class="pointer-events-none absolute inset-0 flex items-center justify-center px-6" data-canvas-hint>
|
|
24
26
|
<div class="flex w-80 max-w-full flex-col items-center gap-2.5 text-center">
|
|
25
27
|
<div class="flex size-9 items-center justify-center rounded-lg border border-border bg-background text-foreground">
|
|
26
28
|
<IconPencil class="size-4 stroke-[1.333]" aria-hidden="true" />
|
|
27
29
|
</div>
|
|
28
|
-
<p class="text-body-medium text-foreground">{$t('canvas.hint.title')}</p>
|
|
30
|
+
<p class="text-body-medium text-muted-foreground">{$t('canvas.hint.title')}</p>
|
|
29
31
|
{#if hintDescription}
|
|
30
32
|
<p class="text-body text-muted-foreground" data-canvas-hint-description>{hintDescription}</p>
|
|
31
33
|
{/if}
|
|
32
34
|
</div>
|
|
33
|
-
<div class="min-h-0 flex-1 max-md:hidden"></div>
|
|
34
35
|
</div>
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
import type { Attachment } from 'svelte/attachments';
|
|
28
28
|
import { IconButton, NumberControls, Select, Slider } from '@widgetic/design-system/components';
|
|
29
29
|
import { MIN_BRUSH_WIDTH } from '../../engine/core/brush.js';
|
|
30
|
+
import { MAX_STROKE_WIDTH } from '../../engine/core/style.js';
|
|
30
31
|
import type { StylePatch } from '../../engine/core/style.js';
|
|
31
32
|
import { MIN_PEN_OPACITY } from '../../engine/state.js';
|
|
32
33
|
import type { EngineState, PenStyle } from '../../engine/state.js';
|
|
@@ -61,8 +62,6 @@
|
|
|
61
62
|
host: CanvasHost;
|
|
62
63
|
state: EngineState;
|
|
63
64
|
ui: HostUiState;
|
|
64
|
-
/** The page hides the colour fields (the wireframe mode keeps every shape white with a grey outline). */
|
|
65
|
-
wireframeMode: boolean;
|
|
66
65
|
canCapture: boolean;
|
|
67
66
|
canConvert: boolean;
|
|
68
67
|
canRename: boolean;
|
|
@@ -79,7 +78,7 @@
|
|
|
79
78
|
widgetCardHasNoSettings?: boolean;
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
let { host, state, ui,
|
|
81
|
+
let { host, state, ui, canCapture, canConvert, canRename, canRefresh, canOpenDetails, clearance, widgetCardHasNoSettings = false }: Props = $props();
|
|
83
82
|
|
|
84
83
|
const { t } = useCanvasLanguage();
|
|
85
84
|
const floatingLayer = useFloatingLayer();
|
|
@@ -140,7 +139,12 @@
|
|
|
140
139
|
host.changePenStyle(penPatch, { final });
|
|
141
140
|
}
|
|
142
141
|
|
|
143
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* Changes how the selection looks (or the pen, while the panel is about the pen). `commit` is false while a drag is going.
|
|
144
|
+
*
|
|
145
|
+
* The engine remembers what was chosen for the next elements of this kind at every change (a drag of a slider included), and the host
|
|
146
|
+
* keeps it for the workspace: the panel has nothing more to do than change the selection.
|
|
147
|
+
*/
|
|
144
148
|
function changeStyle(patch: StylePatch, commit = true): void {
|
|
145
149
|
if (editsPen) {
|
|
146
150
|
changePen(patch, commit);
|
|
@@ -149,10 +153,7 @@
|
|
|
149
153
|
try {
|
|
150
154
|
host.engine.setStyle(patch, { commit });
|
|
151
155
|
stopCommitTimer();
|
|
152
|
-
if (commit)
|
|
153
|
-
host.engine.commit();
|
|
154
|
-
host.persistWorkspaceStyle(patch);
|
|
155
|
-
}
|
|
156
|
+
if (commit) host.engine.commit();
|
|
156
157
|
else commitTimer = setTimeout(() => host.engine.commit(), COMMIT_AFTER_MS);
|
|
157
158
|
} catch (error) {
|
|
158
159
|
console.warn('Canvas: the selection panel could not change the selection', error);
|
|
@@ -234,9 +235,10 @@
|
|
|
234
235
|
(!selectionIsAWidgetWithoutSettings &&
|
|
235
236
|
((shouldOfferSelectionPanelForTraits(traits) && hasSelection) || (canCapture && !canConvert)))
|
|
236
237
|
);
|
|
237
|
-
|
|
238
|
-
//
|
|
239
|
-
const
|
|
238
|
+
// The colour rows follow what is selected (and the pen's colour, which is the Stroke of its traits), on every board: the wireframe
|
|
239
|
+
// look only decides how a new shape starts (white with a grey outline), not which colours can be changed afterwards.
|
|
240
|
+
const showFillColor = $derived(showFillColorRow(traits));
|
|
241
|
+
const showStrokeColor = $derived(showStrokeColorRow(traits));
|
|
240
242
|
const fontSizeDisplay = $derived(traits.text ? formatFontSizeDisplay(traits.text.fontSize) : '–');
|
|
241
243
|
const panelAnchorClass = $derived(
|
|
242
244
|
`${clearance.belowTopCards ? 'top-16' : 'top-4'} ${PANEL_MAX_WIDTH_CLASSES[clearance.besideSideCard ?? 'none']}`
|
|
@@ -301,7 +303,7 @@
|
|
|
301
303
|
value={traits.strokeWidth.kind === 'same' ? Number(strokeWidthValue.toFixed(1)) : null}
|
|
302
304
|
fallbackValue={strokeWidthValue}
|
|
303
305
|
min={strokeWidthMin}
|
|
304
|
-
max={
|
|
306
|
+
max={MAX_STROKE_WIDTH}
|
|
305
307
|
step={1}
|
|
306
308
|
onChange={(next) => changeStyle({ strokeWidth: next })}
|
|
307
309
|
/>
|
|
@@ -5,8 +5,6 @@ interface Props {
|
|
|
5
5
|
host: CanvasHost;
|
|
6
6
|
state: EngineState;
|
|
7
7
|
ui: HostUiState;
|
|
8
|
-
/** The page hides the colour fields (the wireframe mode keeps every shape white with a grey outline). */
|
|
9
|
-
wireframeMode: boolean;
|
|
10
8
|
canCapture: boolean;
|
|
11
9
|
canConvert: boolean;
|
|
12
10
|
canRename: boolean;
|
|
@@ -26,11 +26,12 @@
|
|
|
26
26
|
import {
|
|
27
27
|
CANVAS_OVERLAY_Z_CLASS,
|
|
28
28
|
MENU_PADDING_CLASS,
|
|
29
|
-
MENU_TRIGGER_RING_CLASSES,
|
|
30
29
|
OVERLAY_REDUCED_MOTION_CLASSES,
|
|
31
30
|
SHAPE_LIBRARY_STROKE_WIDTH,
|
|
31
|
+
SUBMENU_SLIDE_UP_CLASSES,
|
|
32
32
|
TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES,
|
|
33
|
-
TOOLBAR_ICON_STROKE_CLASSES
|
|
33
|
+
TOOLBAR_ICON_STROKE_CLASSES,
|
|
34
|
+
TOOLBAR_NO_RING_CLASSES
|
|
34
35
|
} from './floatingCard.js';
|
|
35
36
|
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
36
37
|
import { usePopoverSide } from './popoverSide.js';
|
|
@@ -132,7 +133,7 @@
|
|
|
132
133
|
type="button"
|
|
133
134
|
aria-label={$t('canvas.tool.shapes')}
|
|
134
135
|
data-active={shapeToolInUse ? '' : undefined}
|
|
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
|
|
136
|
+
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 {TOOLBAR_NO_RING_CLASSES} data-[active]:bg-brand-subtle {TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} [&_svg]:size-4 {TOOLBAR_ICON_STROKE_CLASSES}"
|
|
136
137
|
>
|
|
137
138
|
<IconCategory />
|
|
138
139
|
<IconChevronDown class="transition-transform duration-fast motion-reduce:transition-none data-[open]:rotate-180" data-open={open ? '' : undefined} />
|
|
@@ -185,7 +186,8 @@
|
|
|
185
186
|
<DropdownMenu.Separator />
|
|
186
187
|
<DropdownMenu.Sub>
|
|
187
188
|
<DropdownMenu.SubTrigger>{$t('canvas.tool.moreShapes')}</DropdownMenu.SubTrigger>
|
|
188
|
-
|
|
189
|
+
<!-- It fades in and slides up like the Shapes menu (`SUBMENU_SLIDE_UP_CLASSES`): without it the slide it inherited came from the bottom left. -->
|
|
190
|
+
<DropdownMenu.SubContent aria-label={$t('canvas.tool.moreShapes')} class="{CANVAS_OVERLAY_Z_CLASS} max-h-[min(24rem,70vh)] w-[220px] overflow-y-auto {MENU_PADDING_CLASS} shadow-floating {SUBMENU_SLIDE_UP_CLASSES} {OVERLAY_REDUCED_MOTION_CLASSES}">
|
|
189
191
|
{#each libraryGroups as [category, shapes] (category)}
|
|
190
192
|
<DropdownMenu.Label>{categoryLabel(category, $t)}</DropdownMenu.Label>
|
|
191
193
|
<div class="grid grid-cols-5 gap-1 px-1 pb-1" role="presentation">
|
|
@@ -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>
|
|
@@ -5,17 +5,8 @@
|
|
|
5
5
|
* and the panel has to show it and to take what a person types. Plain functions, free of Svelte and of the DOM, so Node
|
|
6
6
|
* can test them.
|
|
7
7
|
*/
|
|
8
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
9
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
10
|
-
if (ar || !(i in from)) {
|
|
11
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
12
|
-
ar[i] = from[i];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
16
|
-
};
|
|
17
8
|
/** The colours the panel offers first, one click each. The first two are the board's own ink and paper. */
|
|
18
|
-
export
|
|
9
|
+
export const COLOR_PRESETS = [
|
|
19
10
|
'#0F172A',
|
|
20
11
|
'#FFFFFF',
|
|
21
12
|
'#EF4444',
|
|
@@ -27,61 +18,59 @@ export var COLOR_PRESETS = [
|
|
|
27
18
|
'#EC4899',
|
|
28
19
|
'#6B7280'
|
|
29
20
|
];
|
|
30
|
-
|
|
21
|
+
const HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
31
22
|
/** True for a colour that paints nothing: `transparent`, or a colour that is fully see-through. */
|
|
32
23
|
export function isNoColor(color) {
|
|
33
24
|
if (!color)
|
|
34
25
|
return true;
|
|
35
|
-
|
|
26
|
+
const text = color.trim().toLowerCase();
|
|
36
27
|
if (text === 'transparent' || text === 'none')
|
|
37
28
|
return true;
|
|
38
|
-
|
|
29
|
+
const rgba = text.match(/^rgba\(\s*[^,]+,\s*[^,]+,\s*[^,]+,\s*([\d.]+)\s*\)$/);
|
|
39
30
|
return rgba ? Number.parseFloat(rgba[1]) === 0 : false;
|
|
40
31
|
}
|
|
41
32
|
/** What a person typed (`f80`, `#FF8800`, `ff8800`) as `#RRGGBB`, or null when it is not a colour. */
|
|
42
33
|
export function parseHexInput(text) {
|
|
43
|
-
|
|
34
|
+
const match = text.trim().match(HEX_PATTERN);
|
|
44
35
|
if (!match)
|
|
45
36
|
return null;
|
|
46
|
-
|
|
47
|
-
return
|
|
37
|
+
const digits = match[1].length === 3 ? [...match[1]].map((digit) => digit + digit).join('') : match[1];
|
|
38
|
+
return `#${digits.toUpperCase()}`;
|
|
48
39
|
}
|
|
49
40
|
function toHexByte(value) {
|
|
50
41
|
return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, '0');
|
|
51
42
|
}
|
|
52
43
|
function hslToHex(hue, saturation, lightness) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
const s = saturation / 100;
|
|
45
|
+
const l = lightness / 100;
|
|
46
|
+
const a = s * Math.min(l, 1 - l);
|
|
47
|
+
const channel = (n) => {
|
|
48
|
+
const k = (n + hue / 30) % 12;
|
|
58
49
|
return toHexByte(255 * (l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)));
|
|
59
50
|
};
|
|
60
|
-
return
|
|
51
|
+
return `#${channel(0)}${channel(8)}${channel(4)}`.toUpperCase();
|
|
61
52
|
}
|
|
62
53
|
/**
|
|
63
54
|
* A stored colour as `#RRGGBB`: a hex, an `rgb()` or `hsl()` an older canvas may hold, or the nearest the browser can
|
|
64
55
|
* say for a colour name. `fallback` is what is answered for a colour that cannot be read.
|
|
65
56
|
*/
|
|
66
|
-
export function colorToHex(color, fallback) {
|
|
67
|
-
var _a;
|
|
68
|
-
if (fallback === void 0) { fallback = '#000000'; }
|
|
57
|
+
export function colorToHex(color, fallback = '#000000') {
|
|
69
58
|
if (!color)
|
|
70
59
|
return fallback;
|
|
71
|
-
|
|
60
|
+
const hex = parseHexInput(color);
|
|
72
61
|
if (hex)
|
|
73
62
|
return hex;
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
const text = color.trim();
|
|
64
|
+
const rgb = text.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);
|
|
76
65
|
if (rgb)
|
|
77
|
-
return
|
|
78
|
-
|
|
66
|
+
return `#${toHexByte(Number(rgb[1]))}${toHexByte(Number(rgb[2]))}${toHexByte(Number(rgb[3]))}`.toUpperCase();
|
|
67
|
+
const hsl = text.match(/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%/i);
|
|
79
68
|
if (hsl)
|
|
80
69
|
return hslToHex(Number(hsl[1]), Number(hsl[2]), Number(hsl[3]));
|
|
81
|
-
return
|
|
70
|
+
return NAMED_COLORS[text.toLowerCase()] ?? fallback;
|
|
82
71
|
}
|
|
83
72
|
/** The few colour names an older canvas may hold. A name that is not here reads as the fallback. */
|
|
84
|
-
|
|
73
|
+
const NAMED_COLORS = Object.freeze({
|
|
85
74
|
black: '#000000',
|
|
86
75
|
white: '#FFFFFF',
|
|
87
76
|
red: '#FF0000',
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/** Names the colour picker fills in at runtime (`{s}`, `{v}`, `{hex}`), built without literals the word scan would read. */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const s = `{${'s'}}`;
|
|
3
|
+
const v = `{${'v'}}`;
|
|
4
|
+
const hex = `{${'hex'}}`;
|
|
5
5
|
/** Words the design-system colour picker speaks; templates keep their placeholders for the picker to replace. */
|
|
6
6
|
export function colorPickerMessages(t) {
|
|
7
7
|
return {
|
|
8
8
|
area: t('canvas.colorPicker.area'),
|
|
9
|
-
areaValue: t('canvas.colorPicker.areaValue', { s
|
|
9
|
+
areaValue: t('canvas.colorPicker.areaValue', { s, v }),
|
|
10
10
|
hue: t('canvas.colorPicker.hue'),
|
|
11
11
|
hex: t('canvas.panel.hex'),
|
|
12
12
|
add: t('canvas.colorPicker.add'),
|
|
13
|
-
swatch: t('canvas.colorPicker.swatch', { hex
|
|
13
|
+
swatch: t('canvas.colorPicker.swatch', { hex })
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -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
|