@widgetic/canvas 0.5.38 → 0.5.40
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 +5 -0
- package/dist/canvas/DomCanvas.svelte +29 -8
- package/dist/canvas/DomCanvas.svelte.d.ts +5 -0
- package/dist/canvas/autosaveScheduler.d.ts +10 -2
- package/dist/canvas/autosaveScheduler.js +31 -5
- package/dist/canvas/boardSurface.d.ts +5 -1
- package/dist/canvas/boardSurface.js +5 -1
- package/dist/canvas/chromeLayout.d.ts +2 -0
- package/dist/canvas/chromeLayout.js +17 -2
- package/dist/canvas/host/CanvasHost.d.ts +32 -1
- package/dist/canvas/host/CanvasHost.js +138 -12
- package/dist/canvas/outsideClickDeselect.d.ts +5 -0
- package/dist/canvas/outsideClickDeselect.js +25 -0
- package/dist/canvas/preferredTextFont.d.ts +7 -1
- package/dist/canvas/preferredTextFont.js +26 -2
- package/dist/canvas/ui/CanvasContextMenu.svelte +69 -39
- package/dist/canvas/ui/CanvasHint.svelte +4 -4
- package/dist/canvas/ui/CanvasToolbar.svelte +21 -3
- package/dist/canvas/ui/ColorField.svelte +2 -1
- package/dist/canvas/ui/SelectionPanel.svelte +82 -43
- package/dist/canvas/ui/SelectorBar.svelte +5 -3
- package/dist/canvas/ui/ShapesMenu.svelte +0 -2
- package/dist/canvas/ui/WidgetActions.svelte +1 -1
- package/dist/canvas/ui/ZoomControl.svelte +39 -4
- package/dist/canvas/ui/ZoomControl.svelte.d.ts +2 -2
- package/dist/canvas/ui/floatingCard.d.ts +7 -5
- package/dist/canvas/ui/floatingCard.js +7 -5
- package/dist/canvas/ui/keyHints.d.ts +5 -0
- package/dist/canvas/ui/keyHints.js +14 -0
- package/dist/canvas/ui/sizeLabelVisibility.d.ts +16 -0
- package/dist/canvas/ui/sizeLabelVisibility.js +16 -0
- package/dist/canvas/ui/widgetSelectionPanel.d.ts +6 -0
- package/dist/canvas/ui/widgetSelectionPanel.js +9 -0
- package/dist/canvas/view/ObjectView.svelte +2 -1
- package/dist/canvas/view/SelectionOverlay.svelte +12 -1
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +1 -1
- package/dist/engine/EngineCore.d.ts +19 -2
- package/dist/engine/EngineCore.js +51 -7
- package/dist/engine/core/defaults.d.ts +1 -1
- package/dist/engine/core/defaults.js +1 -1
- package/dist/engine/core/shapeTools.d.ts +16 -6
- package/dist/engine/core/shapeTools.js +8 -6
- package/dist/engine/input/gestures.js +3 -2
- package/dist/engine/text/layoutText.d.ts +1 -2
- package/dist/engine/text/layoutText.js +2 -4
- package/dist/engine/text/textMetrics.d.ts +19 -0
- package/dist/engine/text/textMetrics.js +24 -0
- package/dist/fonts/interFont.d.ts +5 -0
- package/dist/fonts/interFont.js +31 -0
- package/dist/fonts/workspaceFonts.d.ts +12 -0
- package/dist/fonts/workspaceFonts.js +51 -0
- package/dist/i18n/labels.js +2 -1
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +9 -6
- package/dist/i18n/messages.js +9 -6
- package/dist/settings/workspaceToolSettings.d.ts +45 -0
- package/dist/settings/workspaceToolSettings.js +90 -0
- package/package.json +3 -3
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<script lang="ts">
|
|
19
19
|
import { onDestroy } from 'svelte';
|
|
20
20
|
import type { Attachment } from 'svelte/attachments';
|
|
21
|
-
import { IconButton, Select, Slider
|
|
21
|
+
import { IconButton, NumberStepper, Select, Slider } from '@widgetic/design-system/components';
|
|
22
22
|
import type { StylePatch } from '../../engine/core/style.js';
|
|
23
23
|
import type { EngineState } from '../../engine/state.js';
|
|
24
24
|
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
@@ -29,10 +29,16 @@
|
|
|
29
29
|
import { CANVAS_OVERLAY_Z_CLASS, FLOATING_CARD_CLASSES, OVERLAY_REDUCED_MOTION_CLASSES } from './floatingCard.js';
|
|
30
30
|
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
31
31
|
import { IconAlignCenter, IconAlignLeft, IconAlignRight, IconBold, IconItalic, IconSettings, IconUnderline, IconX } from './icons.js';
|
|
32
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
builtInFontFamiliesForPicker,
|
|
34
|
+
PRIMARY_CANVAS_FONT_FAMILIES,
|
|
35
|
+
workspaceFontFamiliesForPicker,
|
|
36
|
+
writePreferredTextFontFamily
|
|
37
|
+
} from '../preferredTextFont.js';
|
|
33
38
|
import { describeSelection, formatFontSizeDisplay, showFillColorRow, showStrokeColorRow, traitNumber } from './selectionTraits.js';
|
|
34
39
|
import ToolButton from './ToolButton.svelte';
|
|
35
40
|
import WidgetActions from './WidgetActions.svelte';
|
|
41
|
+
import { shouldOfferSelectionPanelForTraits } from './widgetSelectionPanel.js';
|
|
36
42
|
|
|
37
43
|
interface Props {
|
|
38
44
|
host: CanvasHost;
|
|
@@ -69,7 +75,8 @@
|
|
|
69
75
|
);
|
|
70
76
|
|
|
71
77
|
// The font of a text, offered as the old panel offered it: eight families that every screen has.
|
|
72
|
-
const
|
|
78
|
+
const WORKSPACE_FONT_FAMILIES = $derived(workspaceFontFamiliesForPicker());
|
|
79
|
+
const BUILTIN_FONT_FAMILIES = $derived(builtInFontFamiliesForPicker());
|
|
73
80
|
|
|
74
81
|
// ── changes
|
|
75
82
|
// A slider or a picker that is still being dragged changes the board without a step of the history; the step is taken when
|
|
@@ -87,7 +94,10 @@
|
|
|
87
94
|
try {
|
|
88
95
|
host.engine.setStyle(patch, { commit });
|
|
89
96
|
stopCommitTimer();
|
|
90
|
-
if (commit)
|
|
97
|
+
if (commit) {
|
|
98
|
+
host.engine.commit();
|
|
99
|
+
host.persistWorkspaceStyle(patch);
|
|
100
|
+
}
|
|
91
101
|
else commitTimer = setTimeout(() => host.engine.commit(), COMMIT_AFTER_MS);
|
|
92
102
|
} catch (error) {
|
|
93
103
|
console.warn('Canvas: the selection panel could not change the selection', error);
|
|
@@ -131,12 +141,6 @@
|
|
|
131
141
|
changeStyle({ fill: color, color }, commit);
|
|
132
142
|
}
|
|
133
143
|
|
|
134
|
-
function changeStep(current: number, delta: number, min: number, max: number, key: 'strokeWidth' | 'fontSize'): void {
|
|
135
|
-
const stepped = key === 'fontSize' ? Math.round(current + delta) : Math.round((current + delta) * 10) / 10;
|
|
136
|
-
const next = Math.min(max, Math.max(min, stepped));
|
|
137
|
-
changeStyle({ [key]: next } as StylePatch);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
144
|
/** Changes the font of the selected text, and keeps it as the font of the next texts (also after the page is opened again). */
|
|
141
145
|
function chooseFontFamily(fontFamily: string): void {
|
|
142
146
|
changeStyle({ fontFamily });
|
|
@@ -148,7 +152,9 @@
|
|
|
148
152
|
const strokeWidthValue = $derived(traitNumber(traits.strokeWidth, 0));
|
|
149
153
|
const fontSizeValue = $derived(traits.text ? traitNumber(traits.text.fontSize, 16) : 16);
|
|
150
154
|
|
|
151
|
-
const showPanel = $derived(
|
|
155
|
+
const showPanel = $derived(
|
|
156
|
+
(shouldOfferSelectionPanelForTraits(traits) && hasSelection) || (canCapture && !canConvert),
|
|
157
|
+
);
|
|
152
158
|
const showFillColor = $derived(showFillColorRow(traits, wireframeMode));
|
|
153
159
|
const showStrokeColor = $derived(showStrokeColorRow(traits, wireframeMode));
|
|
154
160
|
const fontSizeDisplay = $derived(traits.text ? formatFontSizeDisplay(traits.text.fontSize) : '–');
|
|
@@ -173,12 +179,14 @@
|
|
|
173
179
|
{#if showPanel && !ui.selectionPanelDismissed}
|
|
174
180
|
<aside
|
|
175
181
|
aria-label={$t('canvas.panel.label')}
|
|
182
|
+
data-canvas-ui
|
|
176
183
|
data-canvas-selection-panel
|
|
177
|
-
class="pointer-events-auto absolute end-4 z-20 flex w-[336px] flex-col gap-
|
|
184
|
+
class="pointer-events-auto absolute end-4 z-20 flex min-h-[304px] w-[336px] flex-col gap-4 overflow-y-auto rounded-card border border-border bg-popover p-4 text-foreground shadow-floating {clearance.belowTopCards ? 'top-16 max-h-[calc(100%-5rem)]' : 'top-4 max-h-[calc(100%-2rem)]'} {PANEL_MAX_WIDTH_CLASSES[clearance.besideSideCard ?? 'none']}"
|
|
178
185
|
style:inset-inline-end={clearance.besideSideCard ? PANEL_END_BESIDE_SIDE_CARD[clearance.besideSideCard] : undefined}
|
|
179
186
|
>
|
|
180
|
-
<header class="flex items-center
|
|
181
|
-
<h2 class="truncate text-body font-semibold">{title}</h2>
|
|
187
|
+
<header class="flex h-8 w-full shrink-0 items-center gap-2">
|
|
188
|
+
<h2 class="truncate text-body font-semibold leading-5">{title}</h2>
|
|
189
|
+
<div class="min-h-px min-w-0 flex-1" aria-hidden="true"></div>
|
|
182
190
|
{#if hasSelection}
|
|
183
191
|
<IconButton label={$t('canvas.panel.close')} onclick={dismiss}>
|
|
184
192
|
<IconX />
|
|
@@ -187,35 +195,42 @@
|
|
|
187
195
|
</header>
|
|
188
196
|
|
|
189
197
|
{#if showFillColor}
|
|
190
|
-
<div class="flex h-9
|
|
191
|
-
<span class="text-body">{$t('canvas.panel.fill')}</span>
|
|
198
|
+
<div class="flex h-9 w-full items-start" data-canvas-panel-row="fill">
|
|
199
|
+
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.fill')}</span>
|
|
192
200
|
<ColorField label={$t('canvas.panel.fill')} value={traits.fill} allowNone={!traits.text} onchange={changeFill} />
|
|
193
201
|
</div>
|
|
194
202
|
{/if}
|
|
195
203
|
|
|
196
204
|
{#if showStrokeColor}
|
|
197
|
-
<div class="flex h-9
|
|
198
|
-
<span class="text-body">{$t('canvas.panel.stroke')}</span>
|
|
205
|
+
<div class="flex h-9 w-full items-start" data-canvas-panel-row="stroke">
|
|
206
|
+
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.stroke')}</span>
|
|
199
207
|
<ColorField label={$t('canvas.panel.stroke')} value={traits.stroke} onchange={(color, commit) => changeStyle({ stroke: color }, commit)} />
|
|
200
208
|
</div>
|
|
201
209
|
{/if}
|
|
202
210
|
|
|
203
211
|
{#if traits.strokeWidth.kind !== 'none'}
|
|
204
|
-
<div class="flex h-9
|
|
205
|
-
<span class="text-body">{$t('canvas.panel.strokeWidth')}</span>
|
|
206
|
-
<!-- The
|
|
207
|
-
<
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
+
<div class="flex h-9 w-full items-start" data-canvas-panel-row="strokeWidth">
|
|
213
|
+
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.strokeWidth')}</span>
|
|
214
|
+
<!-- The design system's number stepper (IC Number): the value can be typed or stepped, and the group names the two buttons after the row. -->
|
|
215
|
+
<NumberStepper
|
|
216
|
+
class="w-[185px]"
|
|
217
|
+
label={$t('canvas.panel.strokeWidth')}
|
|
218
|
+
decreaseLabel={$t('canvas.panel.decrease')}
|
|
219
|
+
increaseLabel={$t('canvas.panel.increase')}
|
|
220
|
+
value={traits.strokeWidth.kind === 'same' ? Number(strokeWidthValue.toFixed(1)) : null}
|
|
221
|
+
fallbackValue={strokeWidthValue}
|
|
222
|
+
min={0}
|
|
223
|
+
max={200}
|
|
224
|
+
step={1}
|
|
225
|
+
onChange={(next) => changeStyle({ strokeWidth: next })}
|
|
226
|
+
/>
|
|
212
227
|
</div>
|
|
213
228
|
{/if}
|
|
214
229
|
|
|
215
230
|
{#if traits.roundness.kind !== 'none'}
|
|
216
|
-
<div class="flex h-9
|
|
217
|
-
<span class="text-body">{$t('canvas.panel.roundness')}</span>
|
|
218
|
-
<div class="flex w-[185px] items-center gap-3">
|
|
231
|
+
<div class="flex h-9 w-full items-start" data-canvas-panel-row="roundness" role="group" aria-label={$t('canvas.panel.roundness')} {@attach nameSliderThumb($t('canvas.panel.roundness'))}>
|
|
232
|
+
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.roundness')}</span>
|
|
233
|
+
<div class="flex w-[185px] shrink-0 items-center gap-3">
|
|
219
234
|
<Slider type="single" min={0} max={100} step={1} value={Math.round(traitNumber(traits.roundness, 0))} onValueChange={(next: number) => changeStyle({ roundness: next }, false)} onValueCommit={endChange} />
|
|
220
235
|
<span class="w-7 shrink-0 text-end text-body tabular-nums">{traits.roundness.kind === 'same' ? traits.roundness.value : '–'}</span>
|
|
221
236
|
</div>
|
|
@@ -223,9 +238,9 @@
|
|
|
223
238
|
{/if}
|
|
224
239
|
|
|
225
240
|
{#if traits.opacity.kind !== 'none'}
|
|
226
|
-
<div class="flex h-9
|
|
227
|
-
<span class="text-body">{$t('canvas.panel.opacity')}</span>
|
|
228
|
-
<div class="flex w-[185px] items-center gap-3">
|
|
241
|
+
<div class="flex h-9 w-full items-start" data-canvas-panel-row="opacity" role="group" aria-label={$t('canvas.panel.opacity')} {@attach nameSliderThumb($t('canvas.panel.opacity'))}>
|
|
242
|
+
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.opacity')}</span>
|
|
243
|
+
<div class="flex w-[185px] shrink-0 items-center gap-3">
|
|
229
244
|
<Slider type="single" min={0} max={100} step={1} value={percent(traitNumber(traits.opacity, 1))} onValueChange={(next: number) => changeStyle({ opacity: next / 100 }, false)} onValueCommit={endChange} />
|
|
230
245
|
<span class="w-7 shrink-0 text-end text-body tabular-nums">{traits.opacity.kind === 'same' ? percent(traits.opacity.value) : '–'}</span>
|
|
231
246
|
</div>
|
|
@@ -233,8 +248,8 @@
|
|
|
233
248
|
{/if}
|
|
234
249
|
|
|
235
250
|
{#if traits.text}
|
|
236
|
-
<div class="flex h-9
|
|
237
|
-
<span class="text-body">{$t('canvas.control.fontFamily')}</span>
|
|
251
|
+
<div class="flex h-9 w-full items-start">
|
|
252
|
+
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.control.fontFamily')}</span>
|
|
238
253
|
<Select.Root
|
|
239
254
|
type="single"
|
|
240
255
|
value={traits.text.fontFamily.kind === 'same' ? traits.text.fontFamily.value : undefined}
|
|
@@ -251,21 +266,45 @@
|
|
|
251
266
|
>
|
|
252
267
|
{traits.text.fontFamily.kind === 'same' ? traits.text.fontFamily.value : $t('canvas.panel.mixed')}
|
|
253
268
|
</Select.Trigger>
|
|
254
|
-
<Select.Content
|
|
255
|
-
{
|
|
269
|
+
<Select.Content
|
|
270
|
+
portalProps={canvasOverlayPortalProps($floatingLayer)}
|
|
271
|
+
class="{CANVAS_OVERLAY_Z_CLASS} {OVERLAY_REDUCED_MOTION_CLASSES}"
|
|
272
|
+
data-canvas-ui
|
|
273
|
+
>
|
|
274
|
+
<p class="text-caption text-muted-foreground px-2 py-1">{$t('canvas.panel.fontGroupDefault')}</p>
|
|
275
|
+
{#each PRIMARY_CANVAS_FONT_FAMILIES as family (family)}
|
|
256
276
|
<Select.Item value={family} label={family}>{family}</Select.Item>
|
|
257
277
|
{/each}
|
|
278
|
+
{#if BUILTIN_FONT_FAMILIES.length > 0}
|
|
279
|
+
<p class="text-caption text-muted-foreground px-2 py-1 pt-2">{$t('canvas.panel.fontGroupMore')}</p>
|
|
280
|
+
{#each BUILTIN_FONT_FAMILIES as family (family)}
|
|
281
|
+
<Select.Item value={family} label={family}>{family}</Select.Item>
|
|
282
|
+
{/each}
|
|
283
|
+
{/if}
|
|
284
|
+
{#if WORKSPACE_FONT_FAMILIES.length > 0}
|
|
285
|
+
<p class="text-caption text-muted-foreground px-2 py-1 pt-2">{$t('canvas.panel.fontGroupWorkspace')}</p>
|
|
286
|
+
{#each WORKSPACE_FONT_FAMILIES as family (family)}
|
|
287
|
+
<Select.Item value={family} label={family}>{family}</Select.Item>
|
|
288
|
+
{/each}
|
|
289
|
+
{/if}
|
|
258
290
|
</Select.Content>
|
|
259
291
|
</Select.Root>
|
|
260
292
|
</div>
|
|
261
293
|
|
|
262
|
-
<div class="flex h-9
|
|
263
|
-
<span class="text-body">{$t('canvas.panel.fontSize')}</span>
|
|
264
|
-
<
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
294
|
+
<div class="flex h-9 w-full items-start">
|
|
295
|
+
<span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.fontSize')}</span>
|
|
296
|
+
<NumberStepper
|
|
297
|
+
class="w-[185px]"
|
|
298
|
+
label={$t('canvas.panel.fontSize')}
|
|
299
|
+
decreaseLabel={$t('canvas.panel.decrease')}
|
|
300
|
+
increaseLabel={$t('canvas.panel.increase')}
|
|
301
|
+
value={typeof fontSizeDisplay === 'number' ? fontSizeDisplay : null}
|
|
302
|
+
fallbackValue={fontSizeValue}
|
|
303
|
+
min={8}
|
|
304
|
+
max={200}
|
|
305
|
+
step={1}
|
|
306
|
+
onChange={(next) => changeStyle({ fontSize: next })}
|
|
307
|
+
/>
|
|
269
308
|
</div>
|
|
270
309
|
|
|
271
310
|
<div class="flex items-center justify-between gap-1" role="group" aria-label={$t('canvas.control.textStyle')}>
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
The element selector bar: what stands where the toolbar stood once the page has hidden the drawing tools (after the first
|
|
3
3
|
generation) and asks for the selector instead.
|
|
4
4
|
|
|
5
|
-
One toggle that puts the page's element selector on or off, and,
|
|
6
|
-
|
|
5
|
+
One toggle that puts the page's element selector on or off, and, whenever the page gave its words, the line that says how to
|
|
6
|
+
use it (click, the arrow keys to move between parent and child, a held key to use the widget, Escape to finish). The bar has
|
|
7
|
+
one form only, the open one: the instructions are there before the toggle is pressed, not after (it used to shrink to the
|
|
8
|
+
toggle while the selector was off and grow when it was on).
|
|
7
9
|
The words come from the page (`selectorGuide`), already in its language; the key caps are the keys themselves.
|
|
8
10
|
|
|
9
11
|
The bar stands where the toolbar stands (`toolbarPosition`). On the left or the right edge it stands upright, and the line
|
|
@@ -54,7 +56,7 @@
|
|
|
54
56
|
<ToolButton toggle label={$t('canvas.tool.selector')} active={active} onclick={onToggle}>
|
|
55
57
|
<IconSelectElement />
|
|
56
58
|
</ToolButton>
|
|
57
|
-
{#if
|
|
59
|
+
{#if guide}
|
|
58
60
|
{#if vertical}
|
|
59
61
|
<div class="flex flex-col items-start gap-1.5 px-1 pb-1.5 text-caption-medium text-muted-foreground">
|
|
60
62
|
<span>{guide.click}</span>
|
|
@@ -147,8 +147,6 @@
|
|
|
147
147
|
<DropdownMenu.Item aria-keyshortcuts={imageShortcut} onSelect={() => void host.addImage()}>
|
|
148
148
|
<IconPhoto />
|
|
149
149
|
<span class="flex-1">{$t('canvas.tool.image')}</span>
|
|
150
|
-
<!-- The key is for the eye: the name a screen reader reads is "Image", and the key is given as `aria-keyshortcuts`. -->
|
|
151
|
-
<DropdownMenu.Shortcut aria-hidden="true">{imageShortcut}</DropdownMenu.Shortcut>
|
|
152
150
|
</DropdownMenu.Item>
|
|
153
151
|
<DropdownMenu.Item onSelect={() => void host.addSvg()}>
|
|
154
152
|
<IconBrowser />
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
}
|
|
69
69
|
</script>
|
|
70
70
|
|
|
71
|
-
{#if canCapture && !
|
|
71
|
+
{#if canCapture && !hasSelection}
|
|
72
72
|
<div class="flex flex-col gap-2">
|
|
73
73
|
<span class="text-caption-medium text-muted-foreground">{$t('canvas.widget.createPreview')}</span>
|
|
74
74
|
<Button variant="outline" size="sm" onclick={() => void host.captureSelection()}>
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
ui: HostUiState;
|
|
34
34
|
/** Where the control stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
|
|
35
35
|
anchor: ChromeAnchor;
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/** Board width (px) from which the zoom card is drawn (`zoomVisibilityMinWidth` on the host canvas). */
|
|
37
|
+
visibleMinWidth: number;
|
|
38
38
|
/** The page's `showZoomPanel`: whether the zoom card is drawn at all. */
|
|
39
39
|
showZoom: boolean;
|
|
40
40
|
showSaveButton: boolean;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
let { host, state, ui, anchor,
|
|
43
|
+
let { host, state, ui, anchor, visibleMinWidth, showZoom, showSaveButton }: Props = $props();
|
|
44
44
|
|
|
45
45
|
const { t } = useCanvasLanguage();
|
|
46
46
|
|
|
@@ -55,7 +55,12 @@
|
|
|
55
55
|
|
|
56
56
|
<div class="pointer-events-auto flex gap-2 {vertical ? 'flex-col items-center' : 'items-center'}" data-canvas-zoom-control data-anchor={anchor}>
|
|
57
57
|
{#if showZoom}
|
|
58
|
-
<div
|
|
58
|
+
<div
|
|
59
|
+
role="group"
|
|
60
|
+
aria-label={$t('canvas.zoom.groupLabel')}
|
|
61
|
+
data-zoom-min-width={visibleMinWidth}
|
|
62
|
+
class="canvas-zoom-card items-center gap-1 {vertical ? 'flex-col is-upright' : ''} {FLOATING_CARD_CLASSES}"
|
|
63
|
+
>
|
|
59
64
|
<ToolButton size="compact" label={$t('canvas.zoom.outLabel')} shortcut={chordText({ mod: true, key: '−' }, apple, $t)} onclick={() => host.zoomOut()}>
|
|
60
65
|
<IconZoomOut />
|
|
61
66
|
</ToolButton>
|
|
@@ -87,3 +92,33 @@
|
|
|
87
92
|
</div>
|
|
88
93
|
{/if}
|
|
89
94
|
</div>
|
|
95
|
+
|
|
96
|
+
<style>
|
|
97
|
+
/* Tailwind `@lg` / `@[Npx]` container variants are not emitted in the site dev bundle; honour Figma widths on the board container. */
|
|
98
|
+
.canvas-zoom-card {
|
|
99
|
+
display: none;
|
|
100
|
+
}
|
|
101
|
+
.canvas-zoom-card.is-upright {
|
|
102
|
+
display: flex;
|
|
103
|
+
}
|
|
104
|
+
@container (min-width: 512px) {
|
|
105
|
+
.canvas-zoom-card[data-zoom-min-width='512']:not(.is-upright) {
|
|
106
|
+
display: flex;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
@container (min-width: 560px) {
|
|
110
|
+
.canvas-zoom-card[data-zoom-min-width='560']:not(.is-upright) {
|
|
111
|
+
display: flex;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
@container (min-width: 720px) {
|
|
115
|
+
.canvas-zoom-card[data-zoom-min-width='720']:not(.is-upright) {
|
|
116
|
+
display: flex;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
@container (min-width: 912px) {
|
|
120
|
+
.canvas-zoom-card[data-zoom-min-width='912']:not(.is-upright) {
|
|
121
|
+
display: flex;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
</style>
|
|
@@ -7,8 +7,8 @@ interface Props {
|
|
|
7
7
|
ui: HostUiState;
|
|
8
8
|
/** Where the control stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
|
|
9
9
|
anchor: ChromeAnchor;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** Board width (px) from which the zoom card is drawn (`zoomVisibilityMinWidth` on the host canvas). */
|
|
11
|
+
visibleMinWidth: number;
|
|
12
12
|
/** The page's `showZoomPanel`: whether the zoom card is drawn at all. */
|
|
13
13
|
showZoom: boolean;
|
|
14
14
|
showSaveButton: boolean;
|
|
@@ -20,6 +20,8 @@ export declare const FLOATING_CARD_CLASSES = "rounded-xl border border-border bg
|
|
|
20
20
|
* the Shape Menu is 196 x 246 there, and measures 246 only with 3 px.
|
|
21
21
|
*/
|
|
22
22
|
export declare const MENU_PADDING_CLASS = "p-[3px]";
|
|
23
|
+
/** Figma "Layer Menu" (519:*): 4 px inset, 220 × 136 with 32 px rows. */
|
|
24
|
+
export declare const LAYER_MENU_PADDING_CLASS = "p-1";
|
|
23
25
|
/**
|
|
24
26
|
* A menu, a popover or a tooltip of the design system slides and fades in, and its classes do not ask whether the system wants
|
|
25
27
|
* less motion. The canvas adds this to each one it draws: with `prefers-reduced-motion: reduce` the card appears and goes
|
|
@@ -74,7 +76,7 @@ export declare const FLOATING_CARD_METRICS: {
|
|
|
74
76
|
* with. (An upright bar is as long as the board is tall, so it always has them.) Written out in full, so a page's stylesheet
|
|
75
77
|
* picks it up.
|
|
76
78
|
*/
|
|
77
|
-
export declare const TOOLBAR_HISTORY_VISIBLE_FROM = "hidden @
|
|
79
|
+
export declare const TOOLBAR_HISTORY_VISIBLE_FROM = "hidden @[384px]:flex";
|
|
78
80
|
/**
|
|
79
81
|
* The width of board from which the zoom card is drawn, by the way it stands beside the toolbar (see `chromeLayout.ts`, which
|
|
80
82
|
* picks the case from the two anchors a page named). Narrower than that the zoom card is not drawn, as in Figma's phone: a
|
|
@@ -100,8 +102,8 @@ export declare const ZOOM_CONTROL_MIN_WIDTHS: {
|
|
|
100
102
|
/** The classes that show the zoom card from each of those widths. Written out in full, so a page's stylesheet picks every one up. */
|
|
101
103
|
export declare const ZOOM_CONTROL_VISIBLE_FROM: {
|
|
102
104
|
readonly alone: "hidden @lg:flex";
|
|
103
|
-
readonly sameSlot: "hidden @
|
|
104
|
-
readonly oppositeCorners: "hidden @
|
|
105
|
-
readonly besideCentredToolbar: "hidden @
|
|
106
|
-
readonly centredBesideCornerToolbar: "hidden @
|
|
105
|
+
readonly sameSlot: "hidden @[560px]:flex";
|
|
106
|
+
readonly oppositeCorners: "hidden @[560px]:flex";
|
|
107
|
+
readonly besideCentredToolbar: "hidden @[720px]:flex";
|
|
108
|
+
readonly centredBesideCornerToolbar: "hidden @[912px]:flex";
|
|
107
109
|
};
|
|
@@ -20,6 +20,8 @@ export const FLOATING_CARD_CLASSES = 'rounded-xl border border-border bg-backgro
|
|
|
20
20
|
* the Shape Menu is 196 x 246 there, and measures 246 only with 3 px.
|
|
21
21
|
*/
|
|
22
22
|
export const MENU_PADDING_CLASS = 'p-[3px]';
|
|
23
|
+
/** Figma "Layer Menu" (519:*): 4 px inset, 220 × 136 with 32 px rows. */
|
|
24
|
+
export const LAYER_MENU_PADDING_CLASS = 'p-1';
|
|
23
25
|
/**
|
|
24
26
|
* A menu, a popover or a tooltip of the design system slides and fades in, and its classes do not ask whether the system wants
|
|
25
27
|
* less motion. The canvas adds this to each one it draws: with `prefers-reduced-motion: reduce` the card appears and goes
|
|
@@ -74,7 +76,7 @@ export const FLOATING_CARD_METRICS = {
|
|
|
74
76
|
* with. (An upright bar is as long as the board is tall, so it always has them.) Written out in full, so a page's stylesheet
|
|
75
77
|
* picks it up.
|
|
76
78
|
*/
|
|
77
|
-
export const TOOLBAR_HISTORY_VISIBLE_FROM = 'hidden @
|
|
79
|
+
export const TOOLBAR_HISTORY_VISIBLE_FROM = 'hidden @[384px]:flex';
|
|
78
80
|
/**
|
|
79
81
|
* The width of board from which the zoom card is drawn, by the way it stands beside the toolbar (see `chromeLayout.ts`, which
|
|
80
82
|
* picks the case from the two anchors a page named). Narrower than that the zoom card is not drawn, as in Figma's phone: a
|
|
@@ -100,8 +102,8 @@ export const ZOOM_CONTROL_MIN_WIDTHS = {
|
|
|
100
102
|
/** The classes that show the zoom card from each of those widths. Written out in full, so a page's stylesheet picks every one up. */
|
|
101
103
|
export const ZOOM_CONTROL_VISIBLE_FROM = {
|
|
102
104
|
alone: 'hidden @lg:flex',
|
|
103
|
-
sameSlot: 'hidden @
|
|
104
|
-
oppositeCorners: 'hidden @
|
|
105
|
-
besideCentredToolbar: 'hidden @
|
|
106
|
-
centredBesideCornerToolbar: 'hidden @
|
|
105
|
+
sameSlot: 'hidden @[560px]:flex',
|
|
106
|
+
oppositeCorners: 'hidden @[560px]:flex',
|
|
107
|
+
besideCentredToolbar: 'hidden @[720px]:flex',
|
|
108
|
+
centredBesideCornerToolbar: 'hidden @[912px]:flex'
|
|
107
109
|
};
|
|
@@ -24,4 +24,9 @@ export declare function ariaKeyShortcut(chord: Chord, apple: boolean): string |
|
|
|
24
24
|
* the same in every language; the words of the others come from the page's language.
|
|
25
25
|
*/
|
|
26
26
|
export declare function chordText(chord: Chord, apple: boolean, t: Translator): string;
|
|
27
|
+
/**
|
|
28
|
+
* Shortcut text beside a context-menu row, as in Figma: "Cmd X", "Shift Cmd G" on a Mac; "Ctrl X", "Ctrl Shift G"
|
|
29
|
+
* elsewhere. The toolbar and zoom control keep `chordText` (symbols on Apple).
|
|
30
|
+
*/
|
|
31
|
+
export declare function menuChordText(chord: Chord, apple: boolean, t: Translator): string;
|
|
27
32
|
export {};
|
|
@@ -41,3 +41,17 @@ export function chordText(chord, apple, t) {
|
|
|
41
41
|
parts.push(key);
|
|
42
42
|
return parts.join('+');
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Shortcut text beside a context-menu row, as in Figma: "Cmd X", "Shift Cmd G" on a Mac; "Ctrl X", "Ctrl Shift G"
|
|
46
|
+
* elsewhere. The toolbar and zoom control keep `chordText` (symbols on Apple).
|
|
47
|
+
*/
|
|
48
|
+
export function menuChordText(chord, apple, t) {
|
|
49
|
+
const key = typeof chord.key === 'string' ? chord.key : t(chord.key.name);
|
|
50
|
+
const parts = [];
|
|
51
|
+
if (chord.shift)
|
|
52
|
+
parts.push(t('canvas.key.shift'));
|
|
53
|
+
if (chord.mod)
|
|
54
|
+
parts.push(apple ? 'Cmd' : t('canvas.key.ctrl'));
|
|
55
|
+
parts.push(key);
|
|
56
|
+
return parts.join(' ');
|
|
57
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the size label under a selection is visible (item B21).
|
|
3
|
+
*/
|
|
4
|
+
import type { SelectionDrag } from '../../engine/state.js';
|
|
5
|
+
export interface SizeLabelVisibilityInput {
|
|
6
|
+
hasFrame: boolean;
|
|
7
|
+
/** Any gesture is active (press on body, handle, dot, …). */
|
|
8
|
+
gestureKind: string | null;
|
|
9
|
+
/** Non-null only after the pointer crossed the drag threshold. */
|
|
10
|
+
overlayDragging: SelectionDrag | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* True only while the selection is being resized (Figma "Selection Box" keeps the size chip hidden at rest;
|
|
14
|
+
* see 515:623 `hidden` on the component board).
|
|
15
|
+
*/
|
|
16
|
+
export declare function shouldShowRestingSizeLabel(input: SizeLabelVisibilityInput): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the size label under a selection is visible (item B21).
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* True only while the selection is being resized (Figma "Selection Box" keeps the size chip hidden at rest;
|
|
6
|
+
* see 515:623 `hidden` on the component board).
|
|
7
|
+
*/
|
|
8
|
+
export function shouldShowRestingSizeLabel(input) {
|
|
9
|
+
if (!input.hasFrame)
|
|
10
|
+
return false;
|
|
11
|
+
if (input.overlayDragging === 'resize')
|
|
12
|
+
return true;
|
|
13
|
+
if (input.gestureKind === 'resize')
|
|
14
|
+
return true;
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SelectionTraits } from './selectionTraits.js';
|
|
2
|
+
/**
|
|
3
|
+
* AI-generated widget cards on the board should not open the sketch settings panel (item 17).
|
|
4
|
+
* Sketch shapes and multi-select still use the panel.
|
|
5
|
+
*/
|
|
6
|
+
export declare function shouldOfferSelectionPanelForTraits(traits: Pick<SelectionTraits, 'widgetCard' | 'units'>): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI-generated widget cards on the board should not open the sketch settings panel (item 17).
|
|
3
|
+
* Sketch shapes and multi-select still use the panel.
|
|
4
|
+
*/
|
|
5
|
+
export function shouldOfferSelectionPanelForTraits(traits) {
|
|
6
|
+
if (traits.widgetCard && traits.units.length === 1)
|
|
7
|
+
return false;
|
|
8
|
+
return traits.units.length > 0;
|
|
9
|
+
}
|
|
@@ -211,8 +211,9 @@
|
|
|
211
211
|
{/if}
|
|
212
212
|
</div>
|
|
213
213
|
{:else if look.type === 'widget'}
|
|
214
|
+
<!-- A live widget covers the card (its screenshot is hidden): no white plate behind the widget's own padding (Figma 526:2706). -->
|
|
214
215
|
<div
|
|
215
|
-
class="pointer-events-none absolute overflow-hidden rounded-lg bg-white"
|
|
216
|
+
class="pointer-events-none absolute overflow-hidden rounded-lg {runtime.hiddenImage ? 'bg-transparent' : 'bg-white'}"
|
|
216
217
|
style={frameStyle}
|
|
217
218
|
style:transform={placementOf(object)}
|
|
218
219
|
data-widget-card={look.widgetId}
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
import type { EngineState } from '../../engine/state.js';
|
|
33
33
|
import { worldToScreen } from '../../engine/core/viewport.js';
|
|
34
34
|
import type { CanvasHost } from '../host/CanvasHost.js';
|
|
35
|
+
import { shouldShowRestingSizeLabel } from '../ui/sizeLabelVisibility.js';
|
|
35
36
|
import {
|
|
36
37
|
arrowOutlinePlacement,
|
|
37
38
|
cssCursor,
|
|
@@ -200,7 +201,16 @@
|
|
|
200
201
|
|
|
201
202
|
// The size sits under the frame, at rest and while the frame is stretched, so it does not cover the widget.
|
|
202
203
|
const sizeLabel = $derived.by(() => {
|
|
203
|
-
if (
|
|
204
|
+
if (
|
|
205
|
+
!shouldShowRestingSizeLabel({
|
|
206
|
+
hasFrame: !!frame,
|
|
207
|
+
gestureKind,
|
|
208
|
+
overlayDragging: state.overlay.dragging
|
|
209
|
+
})
|
|
210
|
+
) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
if (!frame) return null;
|
|
204
214
|
const text = formatReadout({ kind: 'size', width: Math.round(frame.world.width), height: Math.round(frame.world.height) });
|
|
205
215
|
const at = restingSizeLabelPoint(frame.screen, text);
|
|
206
216
|
if (!at) return null;
|
|
@@ -327,6 +337,7 @@
|
|
|
327
337
|
class="absolute box-border border-[1.5px] {dragging === 'resize' ? 'border-transparent' : 'border-ring'}"
|
|
328
338
|
style={screenFrameStyle(frame.screen)}
|
|
329
339
|
data-canvas-frame
|
|
340
|
+
data-canvas-selection-frame
|
|
330
341
|
data-dragging={dragging}
|
|
331
342
|
>
|
|
332
343
|
{#if dragging === 'resize'}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Colour of an empty board: the design system's `muted` token, the same the board is painted with. */
|
|
2
|
-
export declare const CANVAS_BOARD_BACKGROUND = "var(--muted, #f5f5f5)";
|
|
2
|
+
export declare const CANVAS_BOARD_BACKGROUND = "var(--canvas-surface, var(--muted, #f5f5f5))";
|
|
3
3
|
/**
|
|
4
4
|
* The empty board, drawn before the canvas itself is there.
|
|
5
5
|
*
|
|
@@ -16,7 +16,7 @@ import type { ArrowHandleId } from './core/arrow.js';
|
|
|
16
16
|
import type { ReorderMode, Scene } from './core/scene.js';
|
|
17
17
|
import type { StylePatch } from './core/style.js';
|
|
18
18
|
import type { SelectionFrame } from './core/transform.js';
|
|
19
|
-
import type { ObjectId, Point, Rect, SceneObject, ShapeObject, Size, Viewport, WidgetObject } from './core/types.js';
|
|
19
|
+
import type { ObjectId, Point, Rect, RectObject, SceneObject, ShapeObject, Size, TextObject, Viewport, WidgetObject } from './core/types.js';
|
|
20
20
|
import type { EngineOverlay, EngineState, PendingWidgetState, ToolId, WidgetRuntime } from './state.js';
|
|
21
21
|
import type { MeasureText } from './text/layoutText.js';
|
|
22
22
|
/** How many undo steps the board keeps (as the canvas it replaces did). */
|
|
@@ -45,6 +45,13 @@ export interface EngineServices {
|
|
|
45
45
|
export interface EngineHooks {
|
|
46
46
|
/** The person changed the board: it needs saving. */
|
|
47
47
|
onDirty?: () => void;
|
|
48
|
+
/**
|
|
49
|
+
* The letters of a text that is still being typed changed. It is not an undo step yet (that comes when the typing ends,
|
|
50
|
+
* and then `onDirty` is called), but it is on the board, so it needs saving too: a person who types a sentence and
|
|
51
|
+
* closes the page must not find the board without it. Called after every change of the letters, and once more when an
|
|
52
|
+
* empty new text is dropped after something was typed in it (the save that held the typed letters is out of date).
|
|
53
|
+
*/
|
|
54
|
+
onDraftChange?: () => void;
|
|
48
55
|
/** The board was emptied by "clear all". */
|
|
49
56
|
onCleared?: () => void;
|
|
50
57
|
/** The selection changed (a selection, a deselection, after a delete or an undo). */
|
|
@@ -102,7 +109,12 @@ export declare class EngineCore {
|
|
|
102
109
|
/** Forgets what can be undone (after the host replaced the board). */
|
|
103
110
|
resetHistory(): void;
|
|
104
111
|
setLoading(loading: boolean): void;
|
|
105
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Tells the engine how big the board element is. With `keepCentre` the view stays on the same point of the world: when
|
|
114
|
+
* the board grows or shrinks, the pan moves by half of the change, so what was in the middle stays in the middle (a board
|
|
115
|
+
* that its page resizes by dragging its edges). The first measure (from 0 by 0) never moves the pan, whatever `keepCentre` says.
|
|
116
|
+
*/
|
|
117
|
+
setViewSize(size: Size, keepCentre?: boolean): void;
|
|
106
118
|
/**
|
|
107
119
|
* Puts a new scene on the board. `transient` is for the frames of a gesture (nothing is recorded), `push`
|
|
108
120
|
* records one undo step and tells the host the board changed, `replace` changes the current step.
|
|
@@ -201,6 +213,11 @@ export declare class EngineCore {
|
|
|
201
213
|
notifyFontsChanged(): void;
|
|
202
214
|
/** Remembers the font family for the next text object the person places. */
|
|
203
215
|
setPreferredTextFontFamily(fontFamily: string): void;
|
|
216
|
+
setWorkspaceToolDefaults(settings: {
|
|
217
|
+
text?: Partial<Pick<TextObject, 'fontFamily' | 'fontSize' | 'fontWeight' | 'fontStyle' | 'color' | 'align' | 'underline'>> | null;
|
|
218
|
+
paint?: Partial<Pick<RectObject, 'fill' | 'stroke' | 'strokeWidth' | 'strokeStyle' | 'opacity' | 'roundness'>> | null;
|
|
219
|
+
}): void;
|
|
220
|
+
workspacePaintForNewShape(wireframe: boolean): Partial<RectObject>;
|
|
204
221
|
/**
|
|
205
222
|
* Makes a text object, puts it on the board and starts editing it. A click makes a label whose width follows its
|
|
206
223
|
* text; a width makes a box whose lines wrap. Nothing is recorded until the editing ends with text in it.
|