@widgetic/canvas 0.5.35 → 0.5.36
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 +105 -36
- package/dist/canvas/DomCanvas.svelte +454 -0
- package/dist/canvas/DomCanvas.svelte.d.ts +222 -0
- package/dist/canvas/boardFrame.d.ts +13 -0
- package/dist/canvas/boardFrame.js +13 -0
- package/dist/canvas/boardSurface.d.ts +9 -0
- package/dist/canvas/boardSurface.js +9 -0
- package/dist/canvas/chromeLayout.d.ts +76 -0
- package/dist/canvas/chromeLayout.js +121 -0
- package/dist/canvas/emptyBoardHint.d.ts +17 -0
- package/dist/canvas/emptyBoardHint.js +12 -0
- package/dist/canvas/eventScope.d.ts +1 -1
- package/dist/canvas/eventScope.js +1 -1
- package/dist/canvas/host/CanvasHost.d.ts +351 -0
- package/dist/canvas/host/CanvasHost.js +1740 -0
- package/dist/canvas/host/CanvasHostApi.d.ts +30 -0
- package/dist/canvas/host/CanvasHostApi.js +95 -0
- package/dist/canvas/host/browserServices.d.ts +46 -0
- package/dist/canvas/host/browserServices.js +167 -0
- package/dist/canvas/host/conversion.d.ts +51 -0
- package/dist/canvas/host/conversion.js +123 -0
- package/dist/canvas/host/hostObject.d.ts +40 -0
- package/dist/canvas/host/hostObject.js +93 -0
- package/dist/canvas/host/pageEvents.d.ts +24 -0
- package/dist/canvas/host/pageEvents.js +35 -0
- package/dist/canvas/host/screenRects.d.ts +66 -0
- package/dist/canvas/host/screenRects.js +102 -0
- package/dist/canvas/host/strokeSnap.d.ts +67 -0
- package/dist/canvas/host/strokeSnap.js +165 -0
- package/dist/canvas/index.d.ts +7 -7
- package/dist/canvas/index.js +8 -8
- package/dist/canvas/openMarks.d.ts +17 -0
- package/dist/canvas/openMarks.js +26 -0
- package/dist/canvas/panZoomPosition.d.ts +15 -0
- package/dist/canvas/panZoomPosition.js +16 -0
- package/dist/canvas/preferredTextFont.d.ts +12 -0
- package/dist/canvas/preferredTextFont.js +38 -0
- package/dist/canvas/shapes/ShapeLibrary.d.ts +1 -1
- package/dist/canvas/shapes/ShapeLibrary.js +13 -1
- package/dist/canvas/shapes/strokeShapeSnap.d.ts +14 -12
- package/dist/canvas/shapes/strokeShapeSnap.js +10 -8
- package/dist/canvas/toolbarPosition.d.ts +11 -11
- package/dist/canvas/toolbarPosition.js +11 -24
- package/dist/canvas/types.d.ts +14 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +173 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte.d.ts +12 -0
- package/dist/canvas/ui/CanvasHint.svelte +20 -0
- package/dist/canvas/ui/CanvasHint.svelte.d.ts +18 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +95 -0
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +14 -0
- package/dist/canvas/ui/ColorField.svelte +155 -0
- package/dist/canvas/ui/ColorField.svelte.d.ts +14 -0
- package/dist/canvas/ui/LoadNotice.svelte +39 -0
- package/dist/canvas/ui/LoadNotice.svelte.d.ts +8 -0
- package/dist/canvas/ui/SelectionPanel.svelte +300 -0
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +20 -0
- package/dist/canvas/ui/SelectorBar.svelte +82 -0
- package/dist/canvas/ui/SelectorBar.svelte.d.ts +12 -0
- package/dist/canvas/ui/ShapesMenu.svelte +185 -0
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +15 -0
- package/dist/canvas/ui/ShortcutsPanel.svelte +124 -0
- package/dist/canvas/ui/ShortcutsPanel.svelte.d.ts +7 -0
- package/dist/canvas/ui/ToolButton.svelte +78 -0
- package/dist/canvas/ui/ToolButton.svelte.d.ts +20 -0
- package/dist/canvas/ui/WidgetActions.svelte +152 -0
- package/dist/canvas/ui/WidgetActions.svelte.d.ts +19 -0
- package/dist/canvas/ui/ZoomControl.svelte +89 -0
- package/dist/canvas/ui/ZoomControl.svelte.d.ts +18 -0
- package/dist/canvas/ui/colorModel.d.ts +18 -0
- package/dist/canvas/ui/colorModel.js +85 -0
- package/dist/canvas/ui/colorPickerMessages.d.ts +5 -0
- package/dist/canvas/ui/colorPickerMessages.js +15 -0
- package/dist/canvas/ui/floatingCard.d.ts +107 -0
- package/dist/canvas/ui/floatingCard.js +107 -0
- package/dist/canvas/ui/floatingLayer.d.ts +21 -0
- package/dist/canvas/ui/floatingLayer.js +52 -0
- package/dist/canvas/ui/icons.d.ts +12 -0
- package/dist/canvas/ui/icons.js +7 -0
- package/dist/canvas/ui/keyHints.d.ts +27 -0
- package/dist/canvas/ui/keyHints.js +43 -0
- package/dist/canvas/ui/popoverSide.d.ts +5 -0
- package/dist/canvas/ui/popoverSide.js +20 -0
- package/dist/canvas/ui/selectionTraits.d.ts +61 -0
- package/dist/canvas/ui/selectionTraits.js +99 -0
- package/dist/canvas/view/CanvasStage.svelte +132 -0
- package/dist/canvas/view/CanvasStage.svelte.d.ts +21 -0
- package/dist/canvas/view/EraserTrail.svelte +50 -0
- package/dist/canvas/view/EraserTrail.svelte.d.ts +9 -0
- package/dist/canvas/view/ObjectView.svelte +245 -0
- package/dist/canvas/view/ObjectView.svelte.d.ts +21 -0
- package/dist/canvas/view/SelectionOverlay.svelte +487 -0
- package/dist/canvas/view/SelectionOverlay.svelte.d.ts +17 -0
- package/dist/canvas/view/TextEditor.svelte +76 -0
- package/dist/canvas/view/TextEditor.svelte.d.ts +9 -0
- package/dist/canvas/view/WidgetChromeLayer.svelte +83 -0
- package/dist/canvas/view/WidgetChromeLayer.svelte.d.ts +13 -0
- package/dist/canvas/view/erasingMarks.d.ts +13 -0
- package/dist/canvas/view/erasingMarks.js +34 -0
- package/dist/canvas/view/geometry.d.ts +169 -0
- package/dist/canvas/view/geometry.js +272 -0
- package/dist/components/CanvasBoardPlaceholder.svelte +5 -3
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +3 -3
- package/dist/components/index.js +1 -1
- package/dist/components/input-controls/ColorIC.svelte +2 -2
- package/dist/engine/EngineCore.d.ts +273 -0
- package/dist/engine/EngineCore.js +1051 -0
- package/dist/engine/codec/canvasDocument.d.ts +57 -0
- package/dist/engine/codec/canvasDocument.js +471 -0
- package/dist/engine/codec/hostReadableKeys.d.ts +25 -0
- package/dist/engine/codec/hostReadableKeys.js +25 -0
- package/dist/engine/core/arrange.d.ts +20 -0
- package/dist/engine/core/arrange.js +81 -0
- package/dist/engine/core/arrow.d.ts +91 -0
- package/dist/engine/core/arrow.js +182 -0
- package/dist/engine/core/brush.d.ts +68 -0
- package/dist/engine/core/brush.js +173 -0
- package/dist/engine/core/defaults.d.ts +70 -0
- package/dist/engine/core/defaults.js +158 -0
- package/dist/engine/core/freehand.d.ts +130 -0
- package/dist/engine/core/freehand.js +430 -0
- package/dist/engine/core/geometry.d.ts +44 -0
- package/dist/engine/core/geometry.js +216 -0
- package/dist/engine/core/history.d.ts +39 -0
- package/dist/engine/core/history.js +69 -0
- package/dist/engine/core/hitTest.d.ts +54 -0
- package/dist/engine/core/hitTest.js +298 -0
- package/dist/engine/core/matrix.d.ts +47 -0
- package/dist/engine/core/matrix.js +101 -0
- package/dist/engine/core/pathData.d.ts +50 -0
- package/dist/engine/core/pathData.js +550 -0
- package/dist/engine/core/rotationReset.d.ts +10 -0
- package/dist/engine/core/rotationReset.js +17 -0
- package/dist/engine/core/scene.d.ts +99 -0
- package/dist/engine/core/scene.js +450 -0
- package/dist/engine/core/scribble.d.ts +64 -0
- package/dist/engine/core/scribble.js +121 -0
- package/dist/engine/core/shapePaths.d.ts +34 -0
- package/dist/engine/core/shapePaths.js +69 -0
- package/dist/engine/core/shapeTools.d.ts +80 -0
- package/dist/engine/core/shapeTools.js +161 -0
- package/dist/engine/core/snapping.d.ts +64 -0
- package/dist/engine/core/snapping.js +164 -0
- package/dist/engine/core/style.d.ts +40 -0
- package/dist/engine/core/style.js +151 -0
- package/dist/engine/core/transform.d.ts +79 -0
- package/dist/engine/core/transform.js +258 -0
- package/dist/engine/core/types.d.ts +238 -0
- package/dist/engine/core/types.js +31 -0
- package/dist/engine/core/viewport.d.ts +32 -0
- package/dist/engine/core/viewport.js +84 -0
- package/dist/engine/input/PointerController.d.ts +38 -0
- package/dist/engine/input/PointerController.js +545 -0
- package/dist/engine/input/arrowHandles.d.ts +38 -0
- package/dist/engine/input/arrowHandles.js +60 -0
- package/dist/engine/input/gestures.d.ts +79 -0
- package/dist/engine/input/gestures.js +769 -0
- package/dist/engine/input/hoverCursor.d.ts +29 -0
- package/dist/engine/input/hoverCursor.js +23 -0
- package/dist/engine/input/keyboard.d.ts +75 -0
- package/dist/engine/input/keyboard.js +264 -0
- package/dist/engine/input/selectionHandles.d.ts +89 -0
- package/dist/engine/input/selectionHandles.js +169 -0
- package/dist/engine/input/types.d.ts +82 -0
- package/dist/engine/input/types.js +5 -0
- package/dist/engine/render/rasterize.d.ts +74 -0
- package/dist/engine/render/rasterize.js +273 -0
- package/dist/engine/state.d.ts +124 -0
- package/dist/engine/state.js +47 -0
- package/dist/engine/text/layoutText.d.ts +53 -0
- package/dist/engine/text/layoutText.js +170 -0
- package/dist/engine/widgets.d.ts +124 -0
- package/dist/engine/widgets.js +345 -0
- package/dist/i18n/labels.d.ts +4 -15
- package/dist/i18n/labels.js +33 -53
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +51 -122
- package/dist/i18n/messages.js +58 -131
- package/dist/i18n/shortcuts.d.ts +0 -1
- package/dist/i18n/shortcuts.js +2 -11
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -3
- package/package.json +30 -5
- package/dist/canvas/Canvas.svelte +0 -13363
- package/dist/canvas/Canvas.svelte.d.ts +0 -286
- package/dist/canvas/CanvasToolbar.svelte +0 -1498
- package/dist/canvas/CanvasToolbar.svelte.d.ts +0 -69
- package/dist/canvas/ContextMenu.svelte +0 -305
- package/dist/canvas/ContextMenu.svelte.d.ts +0 -42
- package/dist/canvas/PanZoomPanel.svelte +0 -478
- package/dist/canvas/PanZoomPanel.svelte.d.ts +0 -38
- package/dist/canvas/WidgetSelectionLayer.svelte +0 -156
- package/dist/canvas/WidgetSelectionLayer.svelte.d.ts +0 -11
- package/dist/canvas/props-panel/PropsPanel.svelte +0 -2075
- package/dist/canvas/props-panel/PropsPanel.svelte.d.ts +0 -84
- package/dist/canvas/props-panel/TextPropsICSection.svelte +0 -242
- package/dist/canvas/props-panel/TextPropsICSection.svelte.d.ts +0 -40
- package/dist/canvas/shadowRootText.d.ts +0 -5
- package/dist/canvas/shadowRootText.js +0 -43
- package/dist/canvas/shapes/FrameShape.d.ts +0 -97
- package/dist/canvas/shapes/FrameShape.js +0 -953
- package/dist/canvas/shapes/ImageShape.d.ts +0 -47
- package/dist/canvas/shapes/ImageShape.js +0 -339
- package/dist/canvas/shapes/WidgetShape.d.ts +0 -30
- package/dist/canvas/shapes/WidgetShape.js +0 -200
- package/dist/canvas/widgetPreviewGeometry.d.ts +0 -19
- package/dist/canvas/widgetPreviewGeometry.js +0 -66
- package/dist/i18n/shapeWords.d.ts +0 -30
- package/dist/i18n/shapeWords.js +0 -36
- package/dist/i18n/slots.d.ts +0 -20
- package/dist/i18n/slots.js +0 -40
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The colour control of the selection panel (Figma "Fill and Stroke"): a 185 px field on the accent background with the
|
|
3
|
+
colour's hex value and a 20 px swatch. A press opens a popover with the design-system colour picker (one surface: presets,
|
|
4
|
+
saturation, hue and hex — no native colour input).
|
|
5
|
+
|
|
6
|
+
Dragging in the picker changes the colour as it goes (one step of the history when the popover closes), and swatch presses
|
|
7
|
+
apply at once.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { ColorPicker, Popover } from '@widgetic/design-system/components';
|
|
11
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
12
|
+
import { COLOR_PRESETS, colorToHex, isNoColor, parseHexInput } from './colorModel.js';
|
|
13
|
+
import { colorPickerMessages as buildColorPickerMessages } from './colorPickerMessages.js';
|
|
14
|
+
import { CANVAS_OVERLAY_Z_CLASS, OVERLAY_REDUCED_MOTION_CLASSES } from './floatingCard.js';
|
|
15
|
+
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
16
|
+
import type { Trait } from './selectionTraits.js';
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
/** What the row is called ("Fill"); the field's accessible name starts with it. */
|
|
20
|
+
label: string;
|
|
21
|
+
/** The colour the selected shapes share, or that they differ in, or nothing when none applies. */
|
|
22
|
+
value: Trait<string>;
|
|
23
|
+
/** A colour was chosen. `commit` is false while a drag in the picker is still going and true when the choice is made. */
|
|
24
|
+
onchange: (color: string, commit: boolean) => void;
|
|
25
|
+
/** Whether "no colour" is a choice (a fill or a stroke can be none; the colour of letters cannot). */
|
|
26
|
+
allowNone?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let { label, value, onchange, allowNone = true }: Props = $props();
|
|
30
|
+
|
|
31
|
+
// The popover is drawn into the canvas's floating layer (see floatingLayer.ts).
|
|
32
|
+
const floatingLayer = useFloatingLayer();
|
|
33
|
+
|
|
34
|
+
const { t } = useCanvasLanguage();
|
|
35
|
+
|
|
36
|
+
const colorPickerMessages = $derived(buildColorPickerMessages($t));
|
|
37
|
+
|
|
38
|
+
const none = $derived(value.kind === 'same' && isNoColor(value.value));
|
|
39
|
+
const mixed = $derived(value.kind === 'mixed');
|
|
40
|
+
const hex = $derived(value.kind === 'same' && !isNoColor(value.value) ? colorToHex(value.value) : '');
|
|
41
|
+
|
|
42
|
+
/** What the field says: the hex, or the word for no colour or for several. */
|
|
43
|
+
const fieldText = $derived(mixed ? $t('canvas.panel.mixed') : none ? $t('canvas.panel.none') : hex);
|
|
44
|
+
|
|
45
|
+
// The swatch is the colour; no colour is a slash through an empty square, and several are the whole wheel.
|
|
46
|
+
const SWATCH_NONE = 'linear-gradient(135deg, transparent 46%, #ef4444 46%, #ef4444 54%, transparent 54%)';
|
|
47
|
+
const SWATCH_MIXED = 'conic-gradient(#ef4444, #eab308, #22c55e, #3b82f6, #a855f7, #ef4444)';
|
|
48
|
+
const swatchBackground = $derived(mixed ? SWATCH_MIXED : none ? SWATCH_NONE : hex || 'transparent');
|
|
49
|
+
|
|
50
|
+
let pickerOpen = $state(false);
|
|
51
|
+
let pickerHex = $state('#000000');
|
|
52
|
+
let pendingCommit = $state(false);
|
|
53
|
+
|
|
54
|
+
// ── the focus when the picker closes
|
|
55
|
+
let fieldButton: HTMLButtonElement | null = null;
|
|
56
|
+
let closedByPointer = false;
|
|
57
|
+
|
|
58
|
+
function rememberField(button: HTMLButtonElement): () => void {
|
|
59
|
+
fieldButton = button;
|
|
60
|
+
return () => {
|
|
61
|
+
if (fieldButton === button) fieldButton = null;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function remember(event: Event): void {
|
|
66
|
+
closedByPointer = event.type === 'pointerdown' || event.type === 'mousedown' || event.type === 'click';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function returnFocusToField(event: Event): void {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
if (!closedByPointer) fieldButton?.focus({ preventScroll: true });
|
|
72
|
+
closedByPointer = false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function syncPickerFromValue(): void {
|
|
76
|
+
pickerHex = hex || '#000000';
|
|
77
|
+
pendingCommit = false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function handleOpenChange(open: boolean): void {
|
|
81
|
+
pickerOpen = open;
|
|
82
|
+
if (open) syncPickerFromValue();
|
|
83
|
+
else if (pendingCommit) {
|
|
84
|
+
onchange(pickerHex, true);
|
|
85
|
+
pendingCommit = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function handlePickerChange(next: string): void {
|
|
90
|
+
const parsed = parseHexInput(next) ?? next;
|
|
91
|
+
pickerHex = parsed;
|
|
92
|
+
onchange(parsed, false);
|
|
93
|
+
pendingCommit = true;
|
|
94
|
+
}
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
<Popover.Root open={pickerOpen} onOpenChange={handleOpenChange}>
|
|
98
|
+
<Popover.Trigger>
|
|
99
|
+
{#snippet child({ props })}
|
|
100
|
+
<button
|
|
101
|
+
{...props}
|
|
102
|
+
{@attach rememberField}
|
|
103
|
+
type="button"
|
|
104
|
+
aria-label="{label}: {fieldText}"
|
|
105
|
+
title={$t('canvas.panel.pickColor')}
|
|
106
|
+
class="flex h-9 w-[185px] items-center justify-between gap-2 rounded-lg bg-accent px-3 text-body text-foreground transition-colors duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:ring-2 data-[state=open]:ring-ring"
|
|
107
|
+
>
|
|
108
|
+
<span class="truncate tabular-nums">{fieldText}</span>
|
|
109
|
+
<span class="size-5 shrink-0 rounded-md border border-border" style:background={swatchBackground}></span>
|
|
110
|
+
</button>
|
|
111
|
+
{/snippet}
|
|
112
|
+
</Popover.Trigger>
|
|
113
|
+
<Popover.Content
|
|
114
|
+
role="dialog"
|
|
115
|
+
aria-label={label}
|
|
116
|
+
align="end"
|
|
117
|
+
sideOffset={8}
|
|
118
|
+
portalProps={canvasOverlayPortalProps($floatingLayer)}
|
|
119
|
+
onInteractOutside={remember}
|
|
120
|
+
onCloseAutoFocus={returnFocusToField}
|
|
121
|
+
class="{CANVAS_OVERLAY_Z_CLASS} w-64 p-0 shadow-floating {OVERLAY_REDUCED_MOTION_CLASSES}"
|
|
122
|
+
data-canvas-color-picker
|
|
123
|
+
>
|
|
124
|
+
{#if allowNone}
|
|
125
|
+
<div class="border-b border-border p-2">
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
aria-label={$t('canvas.panel.noColor')}
|
|
129
|
+
aria-pressed={none}
|
|
130
|
+
class="flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-body text-foreground transition-colors hover:bg-accent focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring aria-pressed:bg-accent"
|
|
131
|
+
onclick={() => {
|
|
132
|
+
onchange('transparent', true);
|
|
133
|
+
pickerOpen = false;
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<span class="size-5 shrink-0 rounded-md border border-border bg-background" style:background-image={SWATCH_NONE}></span>
|
|
137
|
+
<span>{$t('canvas.panel.noColor')}</span>
|
|
138
|
+
</button>
|
|
139
|
+
</div>
|
|
140
|
+
{/if}
|
|
141
|
+
{#if !mixed}
|
|
142
|
+
<ColorPicker
|
|
143
|
+
bind:value={pickerHex}
|
|
144
|
+
swatches={[...COLOR_PRESETS]}
|
|
145
|
+
maxSwatches={5}
|
|
146
|
+
showConfirm={false}
|
|
147
|
+
messages={colorPickerMessages}
|
|
148
|
+
onChange={handlePickerChange}
|
|
149
|
+
class="p-3"
|
|
150
|
+
/>
|
|
151
|
+
{:else}
|
|
152
|
+
<p class="text-body text-muted-foreground p-4">{$t('canvas.panel.mixed')}</p>
|
|
153
|
+
{/if}
|
|
154
|
+
</Popover.Content>
|
|
155
|
+
</Popover.Root>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Trait } from './selectionTraits.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** What the row is called ("Fill"); the field's accessible name starts with it. */
|
|
4
|
+
label: string;
|
|
5
|
+
/** The colour the selected shapes share, or that they differ in, or nothing when none applies. */
|
|
6
|
+
value: Trait<string>;
|
|
7
|
+
/** A colour was chosen. `commit` is false while a drag in the picker is still going and true when the choice is made. */
|
|
8
|
+
onchange: (color: string, commit: boolean) => void;
|
|
9
|
+
/** Whether "no colour" is a choice (a fill or a stroke can be none; the colour of letters cannot). */
|
|
10
|
+
allowNone?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const ColorField: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type ColorField = ReturnType<typeof ColorField>;
|
|
14
|
+
export default ColorField;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
What the board says when the saved canvas could not be opened: it was made by an older version of the editor, or it is not
|
|
3
|
+
a canvas at all. The board opens empty and nothing saved is overwritten until the person draws something, so the notice is
|
|
4
|
+
a plain sentence they can close.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { IconButton } from '@widgetic/design-system/components';
|
|
8
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
9
|
+
import type { LoadStatus } from '../host/CanvasHost.js';
|
|
10
|
+
import { IconAlertTriangle, IconX } from './icons.js';
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
/** How the last read of the saved canvas went. Only `unsupported` and `invalid` are said. */
|
|
14
|
+
status: LoadStatus | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let { status }: Props = $props();
|
|
18
|
+
|
|
19
|
+
const { t } = useCanvasLanguage();
|
|
20
|
+
|
|
21
|
+
// Closed for the status it was closed for: a different problem on a later load shows again.
|
|
22
|
+
let dismissedFor: LoadStatus | null = $state(null);
|
|
23
|
+
|
|
24
|
+
const visible = $derived((status === 'unsupported' || status === 'invalid') && dismissedFor !== status);
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
{#if visible}
|
|
28
|
+
<div
|
|
29
|
+
class="pointer-events-auto absolute inset-x-4 top-4 z-20 mx-auto flex max-w-md items-start gap-3 rounded-xl border border-border bg-popover p-3 text-popover-foreground shadow-floating"
|
|
30
|
+
role="status"
|
|
31
|
+
data-canvas-load-notice={status}
|
|
32
|
+
>
|
|
33
|
+
<IconAlertTriangle class="mt-0.5 size-4 shrink-0 stroke-[1.333] text-muted-foreground" aria-hidden="true" />
|
|
34
|
+
<p class="text-caption flex-1">{status === 'unsupported' ? $t('canvas.state.unsupported') : $t('canvas.state.invalid')}</p>
|
|
35
|
+
<IconButton label={$t('canvas.state.dismiss')} size="sm" onclick={() => (dismissedFor = status)}>
|
|
36
|
+
<IconX />
|
|
37
|
+
</IconButton>
|
|
38
|
+
</div>
|
|
39
|
+
{/if}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LoadStatus } from '../host/CanvasHost.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** How the last read of the saved canvas went. Only `unsupported` and `invalid` are said. */
|
|
4
|
+
status: LoadStatus | null;
|
|
5
|
+
}
|
|
6
|
+
declare const LoadNotice: import("svelte").Component<Props, {}, "">;
|
|
7
|
+
type LoadNotice = ReturnType<typeof LoadNotice>;
|
|
8
|
+
export default LoadNotice;
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Figma "Selection Panel": the card at the top corner of the board that edits what is selected, 336 px wide, 16 px padding.
|
|
3
|
+
|
|
4
|
+
A header with the name of the selection and a close button, then one row per thing the selection has: Fill and Stroke (a
|
|
5
|
+
colour field each), Stroke width (a stepper), Roundness and Opacity (a slider and its value). A row shows only when
|
|
6
|
+
something selected has it, so a text never offers a stroke and a widget card is not painted. Text adds its own rows (the
|
|
7
|
+
font, the size, bold, italic, underline and the alignment), and a drawing, a widget card or the sketch as a whole shows
|
|
8
|
+
what can be done with it for the page (convert, capture, rename, refresh).
|
|
9
|
+
|
|
10
|
+
Every change goes through the engine's one `setStyle`, so what the panel does is what an undo takes back, and a slider that
|
|
11
|
+
is still being dragged is one step of the history, taken when it ends.
|
|
12
|
+
|
|
13
|
+
A selection shows a settings control at the corner; it opens the panel, and the close button collapses it again without
|
|
14
|
+
changing when the selection changes. It stands
|
|
15
|
+
in the top corner at the end of the line, and keeps clear of the cards the page put there: below the ones on the top
|
|
16
|
+
edge, and beside an upright one on the right edge (see `PanelClearance`).
|
|
17
|
+
-->
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { onDestroy } from 'svelte';
|
|
20
|
+
import type { Attachment } from 'svelte/attachments';
|
|
21
|
+
import { IconButton, Select, Slider, StepperButton } from '@widgetic/design-system/components';
|
|
22
|
+
import type { StylePatch } from '../../engine/core/style.js';
|
|
23
|
+
import type { EngineState } from '../../engine/state.js';
|
|
24
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
25
|
+
import { objectName } from '../../i18n/labels.js';
|
|
26
|
+
import type { PanelClearance } from '../chromeLayout.js';
|
|
27
|
+
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
28
|
+
import ColorField from './ColorField.svelte';
|
|
29
|
+
import { CANVAS_OVERLAY_Z_CLASS, FLOATING_CARD_CLASSES, OVERLAY_REDUCED_MOTION_CLASSES } from './floatingCard.js';
|
|
30
|
+
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
31
|
+
import { IconAlignCenter, IconAlignLeft, IconAlignRight, IconBold, IconItalic, IconSettings, IconUnderline, IconX } from './icons.js';
|
|
32
|
+
import { TEXT_FONT_FAMILIES, writePreferredTextFontFamily } from '../preferredTextFont.js';
|
|
33
|
+
import { describeSelection, formatFontSizeDisplay, showFillColorRow, showStrokeColorRow, traitNumber } from './selectionTraits.js';
|
|
34
|
+
import ToolButton from './ToolButton.svelte';
|
|
35
|
+
import WidgetActions from './WidgetActions.svelte';
|
|
36
|
+
|
|
37
|
+
interface Props {
|
|
38
|
+
host: CanvasHost;
|
|
39
|
+
state: EngineState;
|
|
40
|
+
ui: HostUiState;
|
|
41
|
+
/** The page hides the colour fields (the wireframe mode keeps every shape white with a grey outline). */
|
|
42
|
+
wireframeMode: boolean;
|
|
43
|
+
canCapture: boolean;
|
|
44
|
+
canConvert: boolean;
|
|
45
|
+
canRename: boolean;
|
|
46
|
+
canRefresh: boolean;
|
|
47
|
+
canOpenDetails: boolean;
|
|
48
|
+
/** What the panel keeps clear of: the cards that stand on the top edge, and an upright one on the right edge. */
|
|
49
|
+
clearance: PanelClearance;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let { host, state, ui, wireframeMode, canCapture, canConvert, canRename, canRefresh, canOpenDetails, clearance }: Props = $props();
|
|
53
|
+
|
|
54
|
+
const { t } = useCanvasLanguage();
|
|
55
|
+
const floatingLayer = useFloatingLayer();
|
|
56
|
+
|
|
57
|
+
// An upright card on the right edge stands 16 px from it, and the panel stands 8 px beyond the card: the toolbar is 59 px wide
|
|
58
|
+
// (the shape button's 51 and 4 px of padding on each side), the zoom control 40. On a narrow board the panel is at most the
|
|
59
|
+
// board minus that and the 16 px of the other edge. The classes are written out in full so that the stylesheet of a page
|
|
60
|
+
// that installs the canvas picks them up.
|
|
61
|
+
const PANEL_END_BESIDE_SIDE_CARD = { toolbar: '5.25rem', zoom: '4rem' } as const;
|
|
62
|
+
const PANEL_MAX_WIDTH_CLASSES = { none: 'max-w-[calc(100%-2rem)]', toolbar: 'max-w-[calc(100%-6.25rem)]', zoom: 'max-w-[calc(100%-5rem)]' } as const;
|
|
63
|
+
|
|
64
|
+
const traits = $derived(describeSelection(state.scene, state.selectedIds));
|
|
65
|
+
const hasSelection = $derived(traits.units.length > 0);
|
|
66
|
+
|
|
67
|
+
const title = $derived(
|
|
68
|
+
traits.units.length === 1 ? objectName(traits.units[0], $t) : hasSelection ? $t('canvas.type.selection') : $t('canvas.panel.actions')
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// The font of a text, offered as the old panel offered it: eight families that every screen has.
|
|
72
|
+
const FONT_FAMILIES = TEXT_FONT_FAMILIES;
|
|
73
|
+
|
|
74
|
+
// ── changes
|
|
75
|
+
// A slider or a picker that is still being dragged changes the board without a step of the history; the step is taken when
|
|
76
|
+
// it ends, or a moment after the last change (a key on the thumb ends nothing by itself).
|
|
77
|
+
const COMMIT_AFTER_MS = 350;
|
|
78
|
+
let commitTimer: ReturnType<typeof setTimeout> | undefined;
|
|
79
|
+
|
|
80
|
+
function stopCommitTimer(): void {
|
|
81
|
+
if (commitTimer !== undefined) clearTimeout(commitTimer);
|
|
82
|
+
commitTimer = undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Changes how the selection looks. `commit` is false while a drag is going. */
|
|
86
|
+
function changeStyle(patch: StylePatch, commit = true): void {
|
|
87
|
+
try {
|
|
88
|
+
host.engine.setStyle(patch, { commit });
|
|
89
|
+
stopCommitTimer();
|
|
90
|
+
if (commit) host.engine.commit();
|
|
91
|
+
else commitTimer = setTimeout(() => host.engine.commit(), COMMIT_AFTER_MS);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.warn('Canvas: the selection panel could not change the selection', error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function endChange(): void {
|
|
98
|
+
stopCommitTimer();
|
|
99
|
+
host.engine.commit();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
onDestroy(() => {
|
|
103
|
+
stopCommitTimer();
|
|
104
|
+
host.engine.commit();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gives the thumb of a design-system slider the name of its row. The slider draws its thumb itself and takes no name for
|
|
109
|
+
* it, so a screen reader would say "slider" and nothing more (the group around it is not the thumb's name). The thumb is
|
|
110
|
+
* found by its role, and again if the slider draws it anew.
|
|
111
|
+
*/
|
|
112
|
+
function nameSliderThumb(name: string): Attachment<HTMLElement> {
|
|
113
|
+
return (row) => {
|
|
114
|
+
const applyName = (): void => {
|
|
115
|
+
for (const thumb of row.querySelectorAll('[role="slider"]')) thumb.setAttribute('aria-label', name);
|
|
116
|
+
};
|
|
117
|
+
applyName();
|
|
118
|
+
const observer = new MutationObserver(applyName);
|
|
119
|
+
observer.observe(row, { childList: true, subtree: true });
|
|
120
|
+
return () => observer.disconnect();
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function dismiss(): void {
|
|
125
|
+
host.updateUi({ selectionPanelDismissed: true });
|
|
126
|
+
host.focusBoard();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The change of one of the colour fields: the colour of letters is `color`, of a shape `fill`; each shape takes what it has. */
|
|
130
|
+
function changeFill(color: string, commit: boolean): void {
|
|
131
|
+
changeStyle({ fill: color, color }, commit);
|
|
132
|
+
}
|
|
133
|
+
|
|
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
|
+
/** 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
|
+
function chooseFontFamily(fontFamily: string): void {
|
|
142
|
+
changeStyle({ fontFamily });
|
|
143
|
+
host.engine.setPreferredTextFontFamily(fontFamily);
|
|
144
|
+
writePreferredTextFontFamily(fontFamily);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const percent = (fraction: number): number => Math.round(fraction * 100);
|
|
148
|
+
const strokeWidthValue = $derived(traitNumber(traits.strokeWidth, 0));
|
|
149
|
+
const fontSizeValue = $derived(traits.text ? traitNumber(traits.text.fontSize, 16) : 16);
|
|
150
|
+
|
|
151
|
+
const showPanel = $derived(hasSelection || (canCapture && !canConvert));
|
|
152
|
+
const showFillColor = $derived(showFillColorRow(traits, wireframeMode));
|
|
153
|
+
const showStrokeColor = $derived(showStrokeColorRow(traits, wireframeMode));
|
|
154
|
+
const fontSizeDisplay = $derived(traits.text ? formatFontSizeDisplay(traits.text.fontSize) : '–');
|
|
155
|
+
const panelAnchorClass = $derived(
|
|
156
|
+
`${clearance.belowTopCards ? 'top-16' : 'top-4'} ${PANEL_MAX_WIDTH_CLASSES[clearance.besideSideCard ?? 'none']}`
|
|
157
|
+
);
|
|
158
|
+
</script>
|
|
159
|
+
|
|
160
|
+
{#if showPanel && ui.selectionPanelDismissed}
|
|
161
|
+
<div
|
|
162
|
+
class="pointer-events-auto absolute end-4 z-20 {panelAnchorClass}"
|
|
163
|
+
style:inset-inline-end={clearance.besideSideCard ? PANEL_END_BESIDE_SIDE_CARD[clearance.besideSideCard] : undefined}
|
|
164
|
+
>
|
|
165
|
+
<div class={FLOATING_CARD_CLASSES} data-canvas-selection-settings>
|
|
166
|
+
<ToolButton label={$t('canvas.panel.open')} onclick={() => host.updateUi({ selectionPanelDismissed: false })}>
|
|
167
|
+
<IconSettings />
|
|
168
|
+
</ToolButton>
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
{/if}
|
|
172
|
+
|
|
173
|
+
{#if showPanel && !ui.selectionPanelDismissed}
|
|
174
|
+
<aside
|
|
175
|
+
aria-label={$t('canvas.panel.label')}
|
|
176
|
+
data-canvas-selection-panel
|
|
177
|
+
class="pointer-events-auto absolute end-4 z-20 flex w-[336px] flex-col gap-3 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
|
+
style:inset-inline-end={clearance.besideSideCard ? PANEL_END_BESIDE_SIDE_CARD[clearance.besideSideCard] : undefined}
|
|
179
|
+
>
|
|
180
|
+
<header class="flex items-center justify-between gap-2">
|
|
181
|
+
<h2 class="truncate text-body font-semibold">{title}</h2>
|
|
182
|
+
{#if hasSelection}
|
|
183
|
+
<IconButton label={$t('canvas.panel.close')} onclick={dismiss}>
|
|
184
|
+
<IconX />
|
|
185
|
+
</IconButton>
|
|
186
|
+
{/if}
|
|
187
|
+
</header>
|
|
188
|
+
|
|
189
|
+
{#if showFillColor}
|
|
190
|
+
<div class="flex h-9 items-center justify-between gap-3">
|
|
191
|
+
<span class="text-body">{$t('canvas.panel.fill')}</span>
|
|
192
|
+
<ColorField label={$t('canvas.panel.fill')} value={traits.fill} allowNone={!traits.text} onchange={changeFill} />
|
|
193
|
+
</div>
|
|
194
|
+
{/if}
|
|
195
|
+
|
|
196
|
+
{#if showStrokeColor}
|
|
197
|
+
<div class="flex h-9 items-center justify-between gap-3">
|
|
198
|
+
<span class="text-body">{$t('canvas.panel.stroke')}</span>
|
|
199
|
+
<ColorField label={$t('canvas.panel.stroke')} value={traits.stroke} onchange={(color, commit) => changeStyle({ stroke: color }, commit)} />
|
|
200
|
+
</div>
|
|
201
|
+
{/if}
|
|
202
|
+
|
|
203
|
+
{#if traits.strokeWidth.kind !== 'none'}
|
|
204
|
+
<div class="flex h-9 items-center justify-between gap-3">
|
|
205
|
+
<span class="text-body">{$t('canvas.panel.strokeWidth')}</span>
|
|
206
|
+
<!-- The group gives the two buttons the name of their row ("Stroke width: Decrease"), and the value is read when it changes. -->
|
|
207
|
+
<div class="flex items-center gap-1" role="group" aria-label={$t('canvas.panel.strokeWidth')}>
|
|
208
|
+
<span class="w-10 text-end text-body tabular-nums" role="status">{traits.strokeWidth.kind === 'same' ? Number(strokeWidthValue.toFixed(1)) : '–'}</span>
|
|
209
|
+
<StepperButton kind="minus" label={$t('canvas.panel.decrease')} disabled={traits.strokeWidth.kind === 'same' && strokeWidthValue <= 0} onclick={() => changeStep(strokeWidthValue, -1, 0, 200, 'strokeWidth')} />
|
|
210
|
+
<StepperButton kind="plus" label={$t('canvas.panel.increase')} disabled={traits.strokeWidth.kind === 'same' && strokeWidthValue >= 200} onclick={() => changeStep(strokeWidthValue, 1, 0, 200, 'strokeWidth')} />
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
{/if}
|
|
214
|
+
|
|
215
|
+
{#if traits.roundness.kind !== 'none'}
|
|
216
|
+
<div class="flex h-9 items-center justify-between gap-3" role="group" aria-label={$t('canvas.panel.roundness')} {@attach nameSliderThumb($t('canvas.panel.roundness'))}>
|
|
217
|
+
<span class="text-body">{$t('canvas.panel.roundness')}</span>
|
|
218
|
+
<div class="flex w-[185px] items-center gap-3">
|
|
219
|
+
<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
|
+
<span class="w-7 shrink-0 text-end text-body tabular-nums">{traits.roundness.kind === 'same' ? traits.roundness.value : '–'}</span>
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
{/if}
|
|
224
|
+
|
|
225
|
+
{#if traits.opacity.kind !== 'none'}
|
|
226
|
+
<div class="flex h-9 items-center justify-between gap-3" role="group" aria-label={$t('canvas.panel.opacity')} {@attach nameSliderThumb($t('canvas.panel.opacity'))}>
|
|
227
|
+
<span class="text-body">{$t('canvas.panel.opacity')}</span>
|
|
228
|
+
<div class="flex w-[185px] items-center gap-3">
|
|
229
|
+
<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
|
+
<span class="w-7 shrink-0 text-end text-body tabular-nums">{traits.opacity.kind === 'same' ? percent(traits.opacity.value) : '–'}</span>
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
{/if}
|
|
234
|
+
|
|
235
|
+
{#if traits.text}
|
|
236
|
+
<div class="flex h-9 items-center justify-between gap-3">
|
|
237
|
+
<span class="text-body">{$t('canvas.control.fontFamily')}</span>
|
|
238
|
+
<Select.Root
|
|
239
|
+
type="single"
|
|
240
|
+
value={traits.text.fontFamily.kind === 'same' ? traits.text.fontFamily.value : undefined}
|
|
241
|
+
onValueChange={(value) => {
|
|
242
|
+
if (value) chooseFontFamily(value);
|
|
243
|
+
}}
|
|
244
|
+
>
|
|
245
|
+
<!-- The trigger shows the value; the row's word is its name (it was the label of the native select before). -->
|
|
246
|
+
<Select.Trigger
|
|
247
|
+
id="canvas-panel-font"
|
|
248
|
+
aria-label={$t('canvas.control.fontFamily')}
|
|
249
|
+
class="h-9 w-[185px] cursor-pointer bg-accent"
|
|
250
|
+
onkeydown={(event) => event.stopPropagation()}
|
|
251
|
+
>
|
|
252
|
+
{traits.text.fontFamily.kind === 'same' ? traits.text.fontFamily.value : $t('canvas.panel.mixed')}
|
|
253
|
+
</Select.Trigger>
|
|
254
|
+
<Select.Content portalProps={canvasOverlayPortalProps($floatingLayer)} class="{CANVAS_OVERLAY_Z_CLASS} {OVERLAY_REDUCED_MOTION_CLASSES}">
|
|
255
|
+
{#each FONT_FAMILIES as family (family)}
|
|
256
|
+
<Select.Item value={family} label={family}>{family}</Select.Item>
|
|
257
|
+
{/each}
|
|
258
|
+
</Select.Content>
|
|
259
|
+
</Select.Root>
|
|
260
|
+
</div>
|
|
261
|
+
|
|
262
|
+
<div class="flex h-9 items-center justify-between gap-3">
|
|
263
|
+
<span class="text-body">{$t('canvas.panel.fontSize')}</span>
|
|
264
|
+
<div class="flex items-center gap-1" role="group" aria-label={$t('canvas.panel.fontSize')}>
|
|
265
|
+
<span class="w-10 text-end text-body tabular-nums" role="status">{fontSizeDisplay}</span>
|
|
266
|
+
<StepperButton kind="minus" label={$t('canvas.panel.decrease')} disabled={traits.text.fontSize.kind === 'same' && fontSizeValue <= 8} onclick={() => changeStep(fontSizeValue, -1, 8, 200, 'fontSize')} />
|
|
267
|
+
<StepperButton kind="plus" label={$t('canvas.panel.increase')} disabled={traits.text.fontSize.kind === 'same' && fontSizeValue >= 200} onclick={() => changeStep(fontSizeValue, 1, 8, 200, 'fontSize')} />
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
|
|
271
|
+
<div class="flex items-center justify-between gap-1" role="group" aria-label={$t('canvas.control.textStyle')}>
|
|
272
|
+
<div class="flex items-center gap-1">
|
|
273
|
+
<ToolButton toggle size="compact" label={$t('canvas.control.bold')} active={traits.text.bold.kind === 'same' && traits.text.bold.value} onclick={() => changeStyle({ fontWeight: traits.text?.bold.kind === 'same' && traits.text.bold.value ? 'normal' : 'bold' })}>
|
|
274
|
+
<IconBold />
|
|
275
|
+
</ToolButton>
|
|
276
|
+
<ToolButton toggle size="compact" label={$t('canvas.control.italic')} active={traits.text.italic.kind === 'same' && traits.text.italic.value} onclick={() => changeStyle({ fontStyle: traits.text?.italic.kind === 'same' && traits.text.italic.value ? 'normal' : 'italic' })}>
|
|
277
|
+
<IconItalic />
|
|
278
|
+
</ToolButton>
|
|
279
|
+
<ToolButton toggle size="compact" label={$t('canvas.control.underline')} active={traits.text.underline.kind === 'same' && traits.text.underline.value} onclick={() => changeStyle({ underline: !(traits.text?.underline.kind === 'same' && traits.text.underline.value) })}>
|
|
280
|
+
<IconUnderline />
|
|
281
|
+
</ToolButton>
|
|
282
|
+
</div>
|
|
283
|
+
<!-- The three alignments draw a side of the text box (left, centre, right), so they keep their order on every screen. -->
|
|
284
|
+
<div class="flex items-center gap-1" dir="ltr">
|
|
285
|
+
<ToolButton toggle size="compact" label={$t('canvas.control.alignLeft')} active={traits.text.align.kind === 'same' && traits.text.align.value === 'left'} onclick={() => changeStyle({ align: 'left' })}>
|
|
286
|
+
<IconAlignLeft />
|
|
287
|
+
</ToolButton>
|
|
288
|
+
<ToolButton toggle size="compact" label={$t('canvas.control.alignCenter')} active={traits.text.align.kind === 'same' && traits.text.align.value === 'center'} onclick={() => changeStyle({ align: 'center' })}>
|
|
289
|
+
<IconAlignCenter />
|
|
290
|
+
</ToolButton>
|
|
291
|
+
<ToolButton toggle size="compact" label={$t('canvas.control.alignRight')} active={traits.text.align.kind === 'same' && traits.text.align.value === 'right'} onclick={() => changeStyle({ align: 'right' })}>
|
|
292
|
+
<IconAlignRight />
|
|
293
|
+
</ToolButton>
|
|
294
|
+
</div>
|
|
295
|
+
</div>
|
|
296
|
+
{/if}
|
|
297
|
+
|
|
298
|
+
<WidgetActions {host} {state} {ui} {traits} {canCapture} {canConvert} {canRename} {canRefresh} {canOpenDetails} />
|
|
299
|
+
</aside>
|
|
300
|
+
{/if}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EngineState } from '../../engine/state.js';
|
|
2
|
+
import type { PanelClearance } from '../chromeLayout.js';
|
|
3
|
+
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
4
|
+
interface Props {
|
|
5
|
+
host: CanvasHost;
|
|
6
|
+
state: EngineState;
|
|
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
|
+
canCapture: boolean;
|
|
11
|
+
canConvert: boolean;
|
|
12
|
+
canRename: boolean;
|
|
13
|
+
canRefresh: boolean;
|
|
14
|
+
canOpenDetails: boolean;
|
|
15
|
+
/** What the panel keeps clear of: the cards that stand on the top edge, and an upright one on the right edge. */
|
|
16
|
+
clearance: PanelClearance;
|
|
17
|
+
}
|
|
18
|
+
declare const SelectionPanel: import("svelte").Component<Props, {}, "">;
|
|
19
|
+
type SelectionPanel = ReturnType<typeof SelectionPanel>;
|
|
20
|
+
export default SelectionPanel;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The element selector bar: what stands where the toolbar stood once the page has hidden the drawing tools (after the first
|
|
3
|
+
generation) and asks for the selector instead.
|
|
4
|
+
|
|
5
|
+
One toggle that puts the page's element selector on or off, and, while it is on and the page gave its words, the line that
|
|
6
|
+
says how to use it (click, the arrow keys to move between parent and child, a held key to use the widget, Escape to finish).
|
|
7
|
+
The words come from the page (`selectorGuide`), already in its language; the key caps are the keys themselves.
|
|
8
|
+
|
|
9
|
+
The bar stands where the toolbar stands (`toolbarPosition`). On the left or the right edge it stands upright, and the line
|
|
10
|
+
of words becomes four short lines under the toggle.
|
|
11
|
+
-->
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
14
|
+
import { isSideAnchor, popoverSideFor } from '../chromeLayout.js';
|
|
15
|
+
import type { ChromeAnchor } from '../chromeLayout.js';
|
|
16
|
+
import type { SelectorGuide } from '../host/CanvasHost.js';
|
|
17
|
+
import { FLOATING_CARD_CLASSES } from './floatingCard.js';
|
|
18
|
+
import { IconSelectElement } from './icons.js';
|
|
19
|
+
import { providePopoverSide } from './popoverSide.js';
|
|
20
|
+
import ToolButton from './ToolButton.svelte';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
active: boolean;
|
|
24
|
+
guide: SelectorGuide | null;
|
|
25
|
+
/** Where the bar stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
|
|
26
|
+
anchor: ChromeAnchor;
|
|
27
|
+
onToggle: () => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let { active, guide, anchor, onToggle }: Props = $props();
|
|
31
|
+
|
|
32
|
+
const { t } = useCanvasLanguage();
|
|
33
|
+
|
|
34
|
+
const vertical = $derived(isSideAnchor(anchor));
|
|
35
|
+
providePopoverSide(() => popoverSideFor(anchor));
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
{#snippet keyCap(cap: string)}
|
|
39
|
+
<kbd class="rounded-md border border-border bg-muted px-1.5 py-0.5 font-sans text-xs text-muted-foreground">{cap}</kbd>
|
|
40
|
+
{/snippet}
|
|
41
|
+
|
|
42
|
+
{#snippet dot()}
|
|
43
|
+
<span class="text-border" aria-hidden="true">·</span>
|
|
44
|
+
{/snippet}
|
|
45
|
+
|
|
46
|
+
<!-- `widget-selector-bar` is the name pages' own tests have always found the bar by. -->
|
|
47
|
+
<div
|
|
48
|
+
role="group"
|
|
49
|
+
aria-label={$t('canvas.tool.selector')}
|
|
50
|
+
data-canvas-selector-bar
|
|
51
|
+
data-anchor={anchor}
|
|
52
|
+
class="widget-selector-bar pointer-events-auto flex items-center gap-1 whitespace-nowrap {vertical ? 'max-h-full flex-col overflow-y-auto' : 'max-w-full flex-nowrap'} {FLOATING_CARD_CLASSES}"
|
|
53
|
+
>
|
|
54
|
+
<ToolButton toggle label={$t('canvas.tool.selector')} active={active} onclick={onToggle}>
|
|
55
|
+
<IconSelectElement />
|
|
56
|
+
</ToolButton>
|
|
57
|
+
{#if active && guide}
|
|
58
|
+
{#if vertical}
|
|
59
|
+
<div class="flex flex-col items-start gap-1.5 px-1 pb-1.5 text-caption-medium text-muted-foreground">
|
|
60
|
+
<span>{guide.click}</span>
|
|
61
|
+
<span class="flex items-center gap-1.5">{@render keyCap('↑')}{@render keyCap('↓')}<span>{guide.parentChild}</span></span>
|
|
62
|
+
<span class="flex items-center gap-1.5"><span>{guide.hold}</span>{@render keyCap(guide.cmd)}<span>{guide.interact}</span></span>
|
|
63
|
+
<span class="flex items-center gap-1.5">{@render keyCap(guide.esc)}<span>{guide.done}</span></span>
|
|
64
|
+
</div>
|
|
65
|
+
{:else}
|
|
66
|
+
<div class="flex flex-nowrap items-center gap-1.5 pe-3 ps-1 text-caption-medium text-muted-foreground">
|
|
67
|
+
<span>{guide.click}</span>
|
|
68
|
+
{@render dot()}
|
|
69
|
+
{@render keyCap('↑')}
|
|
70
|
+
{@render keyCap('↓')}
|
|
71
|
+
<span>{guide.parentChild}</span>
|
|
72
|
+
{@render dot()}
|
|
73
|
+
<span>{guide.hold}</span>
|
|
74
|
+
{@render keyCap(guide.cmd)}
|
|
75
|
+
<span>{guide.interact}</span>
|
|
76
|
+
{@render dot()}
|
|
77
|
+
{@render keyCap(guide.esc)}
|
|
78
|
+
<span>{guide.done}</span>
|
|
79
|
+
</div>
|
|
80
|
+
{/if}
|
|
81
|
+
{/if}
|
|
82
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ChromeAnchor } from '../chromeLayout.js';
|
|
2
|
+
import type { SelectorGuide } from '../host/CanvasHost.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
active: boolean;
|
|
5
|
+
guide: SelectorGuide | null;
|
|
6
|
+
/** Where the bar stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
|
|
7
|
+
anchor: ChromeAnchor;
|
|
8
|
+
onToggle: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare const SelectorBar: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type SelectorBar = ReturnType<typeof SelectorBar>;
|
|
12
|
+
export default SelectorBar;
|