@widgetic/canvas 0.5.43 → 0.5.45

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.
Files changed (162) hide show
  1. package/dist/canvas/DomCanvas.svelte +56 -3
  2. package/dist/canvas/DomCanvas.svelte.d.ts +59 -28
  3. package/dist/canvas/autosaveScheduler.js +89 -37
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +19 -7
  7. package/dist/canvas/chromeLayout.js +21 -19
  8. package/dist/canvas/eventScope.js +14 -10
  9. package/dist/canvas/host/CanvasHost.d.ts +87 -2
  10. package/dist/canvas/host/CanvasHost.js +1948 -1394
  11. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  12. package/dist/canvas/host/CanvasHostApi.js +32 -5
  13. package/dist/canvas/host/boardFiles.d.ts +90 -0
  14. package/dist/canvas/host/boardFiles.js +155 -0
  15. package/dist/canvas/host/browserServices.d.ts +17 -0
  16. package/dist/canvas/host/browserServices.js +211 -65
  17. package/dist/canvas/host/conversion.js +170 -82
  18. package/dist/canvas/host/hostObject.js +7 -7
  19. package/dist/canvas/host/nearCards.js +21 -18
  20. package/dist/canvas/host/pageEvents.js +5 -5
  21. package/dist/canvas/host/pictureSaves.js +11 -9
  22. package/dist/canvas/host/screenRects.js +31 -28
  23. package/dist/canvas/host/storedPictures.js +243 -149
  24. package/dist/canvas/host/strokeSnap.js +143 -88
  25. package/dist/canvas/index.d.ts +2 -0
  26. package/dist/canvas/openMarks.js +2 -2
  27. package/dist/canvas/outsideClickDeselect.js +7 -6
  28. package/dist/canvas/panZoomPosition.js +2 -2
  29. package/dist/canvas/preferredTextFont.js +25 -13
  30. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  31. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  32. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  33. package/dist/canvas/toolbarPosition.js +2 -2
  34. package/dist/canvas/types.d.ts +17 -0
  35. package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
  36. package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
  37. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
  38. package/dist/canvas/ui/ColorField.svelte +7 -2
  39. package/dist/canvas/ui/SelectionPanel.svelte +105 -42
  40. package/dist/canvas/ui/ShapesMenu.svelte +65 -31
  41. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
  42. package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
  43. package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
  44. package/dist/canvas/ui/ToolButton.svelte +35 -54
  45. package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
  46. package/dist/canvas/ui/colorModel.js +32 -21
  47. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  48. package/dist/canvas/ui/floatingCard.d.ts +26 -4
  49. package/dist/canvas/ui/floatingCard.js +43 -21
  50. package/dist/canvas/ui/floatingLayer.js +6 -5
  51. package/dist/canvas/ui/icons.d.ts +1 -1
  52. package/dist/canvas/ui/icons.js +1 -1
  53. package/dist/canvas/ui/keyHints.js +11 -9
  54. package/dist/canvas/ui/popoverSide.js +3 -2
  55. package/dist/canvas/ui/selectionTraits.d.ts +12 -0
  56. package/dist/canvas/ui/selectionTraits.js +66 -35
  57. package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
  58. package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
  59. package/dist/canvas/view/CanvasStage.svelte +7 -2
  60. package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
  61. package/dist/canvas/view/SelectionOverlay.svelte +17 -10
  62. package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
  63. package/dist/canvas/view/erasingMarks.js +7 -7
  64. package/dist/canvas/view/geometry.d.ts +1 -1
  65. package/dist/canvas/view/geometry.js +90 -71
  66. package/dist/canvas/view/liftedScene.js +36 -24
  67. package/dist/canvas/view/mountedScene.js +79 -76
  68. package/dist/components/CanvasBoardPoster.svelte +206 -0
  69. package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
  70. package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
  71. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
  72. package/dist/components/index.d.ts +7 -0
  73. package/dist/components/index.js +8 -0
  74. package/dist/components/preferenceStorage.js +2 -2
  75. package/dist/engine/EngineCore.d.ts +111 -2
  76. package/dist/engine/EngineCore.js +1013 -707
  77. package/dist/engine/codec/canvasDocument.d.ts +7 -0
  78. package/dist/engine/codec/canvasDocument.js +172 -186
  79. package/dist/engine/codec/hostReadableKeys.js +1 -1
  80. package/dist/engine/core/arrange.js +38 -26
  81. package/dist/engine/core/arrow.d.ts +18 -8
  82. package/dist/engine/core/arrow.js +109 -84
  83. package/dist/engine/core/arrowBinding.d.ts +1 -1
  84. package/dist/engine/core/arrowBinding.js +126 -101
  85. package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
  86. package/dist/engine/core/arrowBindingRecords.js +48 -29
  87. package/dist/engine/core/brush.d.ts +8 -0
  88. package/dist/engine/core/brush.js +98 -78
  89. package/dist/engine/core/cameraMove.d.ts +73 -0
  90. package/dist/engine/core/cameraMove.js +172 -0
  91. package/dist/engine/core/defaults.js +51 -90
  92. package/dist/engine/core/freehand.js +163 -147
  93. package/dist/engine/core/geometry.js +54 -47
  94. package/dist/engine/core/history.js +55 -38
  95. package/dist/engine/core/hitTest.js +81 -68
  96. package/dist/engine/core/matrix.js +20 -18
  97. package/dist/engine/core/pathData.js +210 -183
  98. package/dist/engine/core/rotationReset.js +6 -5
  99. package/dist/engine/core/scene.d.ts +22 -0
  100. package/dist/engine/core/scene.js +288 -139
  101. package/dist/engine/core/scribble.js +84 -59
  102. package/dist/engine/core/shapePaths.js +15 -12
  103. package/dist/engine/core/shapeTools.js +63 -72
  104. package/dist/engine/core/snapping.js +117 -65
  105. package/dist/engine/core/style.d.ts +10 -0
  106. package/dist/engine/core/style.js +82 -33
  107. package/dist/engine/core/transform.d.ts +6 -0
  108. package/dist/engine/core/transform.js +103 -83
  109. package/dist/engine/core/types.d.ts +7 -0
  110. package/dist/engine/core/types.js +4 -4
  111. package/dist/engine/core/viewport.js +36 -23
  112. package/dist/engine/input/PointerController.d.ts +15 -1
  113. package/dist/engine/input/PointerController.js +549 -466
  114. package/dist/engine/input/arrowHandles.js +12 -12
  115. package/dist/engine/input/gestures.d.ts +3 -1
  116. package/dist/engine/input/gestures.js +340 -266
  117. package/dist/engine/input/hoverCursor.js +1 -1
  118. package/dist/engine/input/keyboard.d.ts +22 -3
  119. package/dist/engine/input/keyboard.js +131 -32
  120. package/dist/engine/input/selectionHandles.js +50 -45
  121. package/dist/engine/input/types.d.ts +7 -0
  122. package/dist/engine/input/types.js +1 -1
  123. package/dist/engine/render/rasterize.js +158 -86
  124. package/dist/engine/state.d.ts +18 -0
  125. package/dist/engine/state.js +25 -4
  126. package/dist/engine/text/layoutText.js +62 -43
  127. package/dist/engine/text/textMetrics.js +10 -8
  128. package/dist/engine/widgets.js +137 -101
  129. package/dist/fonts/interFont.js +83 -30
  130. package/dist/fonts/workspaceFonts.d.ts +6 -0
  131. package/dist/fonts/workspaceFonts.js +108 -34
  132. package/dist/i18n/labels.js +4 -4
  133. package/dist/i18n/language.d.ts +3 -3
  134. package/dist/i18n/language.js +4 -4
  135. package/dist/i18n/messages.d.ts +6 -0
  136. package/dist/i18n/messages.js +7 -1
  137. package/dist/i18n/shortcuts.d.ts +6 -4
  138. package/dist/i18n/shortcuts.js +30 -26
  139. package/dist/index.d.ts +2 -1
  140. package/dist/poster/boardPlacement.d.ts +80 -0
  141. package/dist/poster/boardPlacement.js +140 -0
  142. package/dist/poster/boardPoster.d.ts +80 -0
  143. package/dist/poster/boardPoster.js +251 -0
  144. package/dist/poster/paintBoardPoster.d.ts +49 -0
  145. package/dist/poster/paintBoardPoster.js +112 -0
  146. package/dist/poster/posterPictures.d.ts +32 -0
  147. package/dist/poster/posterPictures.js +138 -0
  148. package/dist/settings/workspaceToolSettings.d.ts +6 -0
  149. package/dist/settings/workspaceToolSettings.js +58 -34
  150. package/dist/tools/components/catalog.js +74 -64
  151. package/dist/tools/components/grouping.js +28 -6
  152. package/dist/tools/definitions.js +31 -9
  153. package/dist/tools/executors.js +214 -106
  154. package/dist/tools/hostAdapter.d.ts +5 -1
  155. package/dist/tools/hostAdapter.js +15 -11
  156. package/dist/tools/sceneSummary.js +57 -43
  157. package/dist/tools/sketchIntent.js +21 -13
  158. package/dist/tools/styleArguments.d.ts +35 -0
  159. package/dist/tools/styleArguments.js +93 -0
  160. package/dist/tools/types.d.ts +26 -1
  161. package/dist/tools/types.js +2 -1
  162. package/package.json +1 -1
@@ -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 const TOOLBAR_POSITIONS = CHROME_ANCHORS;
14
+ export var TOOLBAR_POSITIONS = CHROME_ANCHORS;
15
15
  /** Where the toolbar stands when the host says nothing: the bottom centre, as it always did. */
16
- export const DEFAULT_TOOLBAR_POSITION = 'BC';
16
+ export var 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
@@ -3,6 +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
7
  /** Payload emitted when a frame is converted to a widget via onConvertToWidget callback. */
7
8
  export interface WidgetConversionPayload {
8
9
  frameName: string;
@@ -77,3 +78,19 @@ export interface StrokeRecognitionResult {
77
78
  }
78
79
  /** The recognizer a host supplies to enable stroke snapping. */
79
80
  export type StrokeRecognizer = (request: StrokeRecognitionRequest) => Promise<StrokeRecognitionResult | null>;
81
+ /**
82
+ * How a move of the view goes (`flyToPoint`, `flyToObjects`, `flyToContent`): a page can set how long it takes, the shape of the
83
+ * motion (`easing`), whether the position and the zoom ease together or the view flies (`path`: `'ease'`, the default, or `'fly'`),
84
+ * and be told when it is over (and whether the view arrived or the person took it first).
85
+ */
86
+ export type CanvasMoveOptions = ViewMoveOptions;
87
+ /** What `flyToPoint` and `flyToObjects` take besides how the move goes: the zoom to arrive at. */
88
+ export interface CanvasFlyOptions extends CanvasMoveOptions {
89
+ /**
90
+ * The zoom to arrive at, in percent as `zoomTo` takes it (100 is 100%). Left out: `flyToObjects` fits the objects to the board
91
+ * (never past 200%) and `flyToPoint` keeps the zoom the board has.
92
+ */
93
+ zoomPercent?: number;
94
+ /** Keeps the zoom the board has and only moves to the place (`flyToObjects` would otherwise fit the objects to the board). Wins over `zoomPercent`. */
95
+ keepZoom?: boolean;
96
+ }
@@ -141,6 +141,12 @@
141
141
  </DropdownMenu.Item>
142
142
  {/snippet}
143
143
 
144
+ <!--
145
+ `data-canvas-ui` marks the menu as the canvas's own (its layer submenu sits inside it): on a page without a shadow root the
146
+ menu is portaled to `document.body`, outside the canvas root, and a press on one of its entries would otherwise count as a
147
+ press outside the canvas (`outsideClickDeselect.ts`) and clear the selection before the click lands. The entries that act
148
+ on the selection (Duplicate, Bring to front, Delete...) are disabled by then, and nothing happens.
149
+ -->
144
150
  <DropdownMenu.Root open={point !== null} onOpenChange={setOpen}>
145
151
  {#if anchor}
146
152
  <DropdownMenu.Content
@@ -151,6 +157,7 @@
151
157
  portalProps={canvasOverlayPortalProps($floatingLayer)}
152
158
  onCloseAutoFocus={returnFocusToBoard}
153
159
  aria-label={$t('canvas.panel.actions')}
160
+ data-canvas-ui
154
161
  data-canvas-context-menu
155
162
  class="{CANVAS_OVERLAY_Z_CLASS} w-[240px] py-1 {MENU_PADDING_CLASS} shadow-floating focus-visible:outline-hidden {OVERLAY_REDUCED_MOTION_CLASSES}"
156
163
  >
@@ -33,11 +33,13 @@
33
33
  state: EngineState;
34
34
  ui: HostUiState;
35
35
  showDrawingTools: boolean;
36
+ /** Whether the Shapes menu offers the person's file library (the page turned it on and gave the browser that opens it). */
37
+ showFiles?: boolean;
36
38
  /** Where the bar stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
37
39
  anchor: ChromeAnchor;
38
40
  }
39
41
 
40
- let { host, state, ui, showDrawingTools, anchor }: Props = $props();
42
+ let { host, state, ui, showDrawingTools, showFiles = false, anchor }: Props = $props();
41
43
 
42
44
  const { t } = useCanvasLanguage();
43
45
 
@@ -81,6 +83,7 @@
81
83
  libraryShapeKey={state.libraryShapeKey}
82
84
  open={ui.shapesMenuOpen}
83
85
  imageShortcut={TOOL_KEYS.image}
86
+ {showFiles}
84
87
  />
85
88
 
86
89
  <!-- The history group is the first thing a board too narrow for the whole bar gives up (Figma's phone): undo and redo stay on the keys. An upright bar is as long as the board is tall, so it keeps them. -->
@@ -6,6 +6,8 @@ interface Props {
6
6
  state: EngineState;
7
7
  ui: HostUiState;
8
8
  showDrawingTools: boolean;
9
+ /** Whether the Shapes menu offers the person's file library (the page turned it on and gave the browser that opens it). */
10
+ showFiles?: boolean;
9
11
  /** Where the bar stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
10
12
  anchor: ChromeAnchor;
11
13
  }
@@ -104,10 +104,15 @@
104
104
  data-canvas-color-picker-trigger
105
105
  aria-label="{label}: {fieldText}"
106
106
  title={$t('canvas.panel.pickColor')}
107
- class="flex h-9 w-[185px] min-h-9 items-center justify-between gap-2 rounded-lg bg-accent py-0 ps-3 pe-2 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
+ class="group/color-field flex h-9 w-[185px] min-h-9 items-center justify-between gap-2 rounded-lg bg-accent py-0 ps-3 pe-2 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"
108
108
  >
109
109
  <span class="truncate tabular-nums">{fieldText}</span>
110
- <span class="size-5 shrink-0 rounded-md border border-border" style:background={swatchBackground}></span>
110
+ <!-- The press cue is the swatch shrinking a little, never the field: a field is a component, and only a real button or a
111
+ small icon inside a component shrinks when it is pressed. A person who asks for less motion gets no shrink. -->
112
+ <span
113
+ class="size-5 shrink-0 rounded-md border border-border transition-transform duration-fast ease-out group-active/color-field:scale-90 motion-reduce:transition-none motion-reduce:group-active/color-field:scale-100"
114
+ style:background={swatchBackground}
115
+ ></span>
111
116
  </button>
112
117
  {/snippet}
113
118
  </Popover.Trigger>
@@ -10,6 +10,11 @@
10
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
11
  is still being dragged is one step of the history, taken when it ends.
12
12
 
13
+ With the Draw tool chosen and nothing selected the panel is about the pen: the line the next stroke is drawn with. It has
14
+ the rows a line drawn by hand has (Stroke, Stroke width and Opacity), and what is set there is what the next line looks like,
15
+ before anything is drawn (see `describePenStyle`). Nothing that is drawn already changes, and the pen is kept for the
16
+ workspace (see `CanvasHost.changePenStyle`). It opens and closes like the panel of a selection.
17
+
13
18
  A selection shows a settings control at the corner; it opens the panel, and the close button collapses it again without
14
19
  changing when the selection changes. Nothing opens the panel by itself, not a selection and not a text: it is closed by
15
20
  default, it stays as the person left it while the selection moves from one object to another, and it goes back to the
@@ -20,9 +25,11 @@
20
25
  <script lang="ts">
21
26
  import { onDestroy } from 'svelte';
22
27
  import type { Attachment } from 'svelte/attachments';
23
- import { IconButton, NumberStepper, Select, Slider } from '@widgetic/design-system/components';
28
+ import { IconButton, NumberControls, Select, Slider } from '@widgetic/design-system/components';
29
+ import { MIN_BRUSH_WIDTH } from '../../engine/core/brush.js';
24
30
  import type { StylePatch } from '../../engine/core/style.js';
25
- import type { EngineState } from '../../engine/state.js';
31
+ import { MIN_PEN_OPACITY } from '../../engine/state.js';
32
+ import type { EngineState, PenStyle } from '../../engine/state.js';
26
33
  import { useCanvasLanguage } from '../../i18n/language.js';
27
34
  import { objectName } from '../../i18n/labels.js';
28
35
  import type { PanelClearance } from '../chromeLayout.js';
@@ -37,7 +44,15 @@
37
44
  workspaceFontFamiliesForPicker,
38
45
  writePreferredTextFontFamily
39
46
  } from '../preferredTextFont.js';
40
- import { describeSelection, formatFontSizeDisplay, showFillColorRow, showStrokeColorRow, traitNumber } from './selectionTraits.js';
47
+ import {
48
+ describePenStyle,
49
+ describeSelection,
50
+ formatFontSizeDisplay,
51
+ minimumStrokeWidth,
52
+ showFillColorRow,
53
+ showStrokeColorRow,
54
+ traitNumber
55
+ } from './selectionTraits.js';
41
56
  import ToolButton from './ToolButton.svelte';
42
57
  import WidgetActions from './WidgetActions.svelte';
43
58
  import { shouldOfferSelectionPanelForTraits } from './widgetSelectionPanel.js';
@@ -76,12 +91,27 @@
76
91
  const PANEL_END_BESIDE_SIDE_CARD = { toolbar: '5.25rem', zoom: '4rem' } as const;
77
92
  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;
78
93
 
79
- const traits = $derived(describeSelection(state.scene, state.selectedIds));
94
+ // ── the pen
95
+ // With the Draw tool chosen and nothing selected, the panel is about the pen: the line the next stroke is drawn with (see
96
+ // `EngineState.penStyle`). It offers what a line drawn by hand has (its colour, its width and how much of the board shows
97
+ // through it), so that these can be set before anything is drawn. A selection is about the selection, whatever the tool is.
98
+ const editsPen = $derived(state.tool === 'draw' && state.selectedIds.length === 0);
99
+
100
+ const traits = $derived(editsPen ? describePenStyle(state.penStyle) : describeSelection(state.scene, state.selectedIds));
80
101
  const hasSelection = $derived(traits.units.length > 0);
81
102
 
82
103
  const title = $derived(
83
- traits.units.length === 1 ? objectName(traits.units[0], $t) : hasSelection ? $t('canvas.type.selection') : $t('canvas.panel.actions')
104
+ editsPen
105
+ ? $t('canvas.tool.draw')
106
+ : traits.units.length === 1
107
+ ? objectName(traits.units[0], $t)
108
+ : hasSelection
109
+ ? $t('canvas.type.selection')
110
+ : $t('canvas.panel.actions')
84
111
  );
112
+ // The name of the panel and of the control that opens it, for a screen reader: the pen is not a selection.
113
+ const panelLabel = $derived(editsPen ? $t('canvas.panel.penLabel') : $t('canvas.panel.label'));
114
+ const openLabel = $derived(editsPen ? $t('canvas.panel.penOpen') : $t('canvas.panel.open'));
85
115
 
86
116
  // The font of a text, offered as the old panel offered it: eight families that every screen has.
87
117
  const WORKSPACE_FONT_FAMILIES = $derived(workspaceFontFamiliesForPicker());
@@ -98,8 +128,24 @@
98
128
  commitTimer = undefined;
99
129
  }
100
130
 
101
- /** Changes how the selection looks. `commit` is false while a drag is going. */
131
+ /**
132
+ * Sets the pen (see `editsPen`): of the keys of a change of style a line takes its colour (`stroke`), its width and its opacity.
133
+ * The pen is not on the board, so there is no step of the history to take and nothing to commit; `final` is false while a drag is going.
134
+ */
135
+ function changePen(patch: StylePatch, final: boolean): void {
136
+ const penPatch: Partial<PenStyle> = {};
137
+ if (patch.stroke !== undefined) penPatch.color = patch.stroke;
138
+ if (patch.strokeWidth !== undefined) penPatch.width = patch.strokeWidth;
139
+ if (patch.opacity !== undefined) penPatch.opacity = patch.opacity;
140
+ host.changePenStyle(penPatch, { final });
141
+ }
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. */
102
144
  function changeStyle(patch: StylePatch, commit = true): void {
145
+ if (editsPen) {
146
+ changePen(patch, commit);
147
+ return;
148
+ }
103
149
  try {
104
150
  host.engine.setStyle(patch, { commit });
105
151
  stopCommitTimer();
@@ -115,7 +161,9 @@
115
161
 
116
162
  function endChange(): void {
117
163
  stopCommitTimer();
118
- host.engine.commit();
164
+ // The pen has nothing to commit: the end of a drag only lets the host say, once, what the pen is now.
165
+ if (editsPen) host.changePenStyle({}, { final: true });
166
+ else host.engine.commit();
119
167
  }
120
168
 
121
169
  onDestroy(() => {
@@ -165,7 +213,13 @@
165
213
  }
166
214
 
167
215
  const percent = (fraction: number): number => Math.round(fraction * 100);
168
- const strokeWidthValue = $derived(traitNumber(traits.strokeWidth, 0));
216
+ // An arrow (or any shape that is only a line) cannot be given no line: the stepper stops at the thinnest one, and the mixed
217
+ // selection starts its buttons from there instead of from a 0 that is out of range.
218
+ // The pen is a line drawn by hand, whose thinnest is the brush's.
219
+ const strokeWidthMin = $derived(editsPen ? MIN_BRUSH_WIDTH : minimumStrokeWidth(traits));
220
+ const strokeWidthValue = $derived(traitNumber(traits.strokeWidth, strokeWidthMin));
221
+ // The pen is never made so faint that it cannot be seen (the slider goes in whole percents, see `MIN_PEN_OPACITY`).
222
+ const opacityMin = $derived(editsPen ? Math.round(MIN_PEN_OPACITY * 100) : 0);
169
223
  const fontSizeValue = $derived(traits.text ? traitNumber(traits.text.fontSize, 16) : 16);
170
224
 
171
225
  // The widget on the board is not edited here: a selected card whose widget is there has no settings control and no panel.
@@ -174,12 +228,15 @@
174
228
  );
175
229
  // A lone widget card does not open the sketch settings panel on any board (`shouldOfferSelectionPanelForTraits`); on the
176
230
  // simple board it does not even when the page can capture (`selectionIsAWidgetWithoutSettings`).
231
+ // The pen has its panel on every board that has the Draw tool: it is the way to set the line before it is drawn.
177
232
  const showPanel = $derived(
178
- !selectionIsAWidgetWithoutSettings &&
179
- ((shouldOfferSelectionPanelForTraits(traits) && hasSelection) || (canCapture && !canConvert))
233
+ editsPen ||
234
+ (!selectionIsAWidgetWithoutSettings &&
235
+ ((shouldOfferSelectionPanelForTraits(traits) && hasSelection) || (canCapture && !canConvert)))
180
236
  );
181
237
  const showFillColor = $derived(showFillColorRow(traits, wireframeMode));
182
- const showStrokeColor = $derived(showStrokeColorRow(traits, wireframeMode));
238
+ // The pen's colour is shown in the wireframe look too: a line drawn by hand keeps its colour there.
239
+ const showStrokeColor = $derived(editsPen || showStrokeColorRow(traits, wireframeMode));
183
240
  const fontSizeDisplay = $derived(traits.text ? formatFontSizeDisplay(traits.text.fontSize) : '–');
184
241
  const panelAnchorClass = $derived(
185
242
  `${clearance.belowTopCards ? 'top-16' : 'top-4'} ${PANEL_MAX_WIDTH_CLASSES[clearance.besideSideCard ?? 'none']}`
@@ -192,7 +249,7 @@
192
249
  style:inset-inline-end={clearance.besideSideCard ? PANEL_END_BESIDE_SIDE_CARD[clearance.besideSideCard] : undefined}
193
250
  >
194
251
  <div class={FLOATING_CARD_CLASSES} data-canvas-selection-settings>
195
- <ToolButton label={$t('canvas.panel.open')} onclick={() => host.updateUi({ selectionPanelDismissed: false })}>
252
+ <ToolButton label={openLabel} onclick={() => host.updateUi({ selectionPanelDismissed: false })}>
196
253
  <IconSettings />
197
254
  </ToolButton>
198
255
  </div>
@@ -201,7 +258,7 @@
201
258
 
202
259
  {#if showPanel && !ui.selectionPanelDismissed}
203
260
  <aside
204
- aria-label={$t('canvas.panel.label')}
261
+ aria-label={panelLabel}
205
262
  data-canvas-ui
206
263
  data-canvas-selection-panel
207
264
  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']}"
@@ -210,7 +267,7 @@
210
267
  <header class="flex h-8 w-full shrink-0 items-center gap-2">
211
268
  <h2 class="truncate text-body font-semibold leading-5">{title}</h2>
212
269
  <div class="min-h-px min-w-0 flex-1" aria-hidden="true"></div>
213
- {#if hasSelection}
270
+ {#if hasSelection || editsPen}
214
271
  <IconButton label={$t('canvas.panel.close')} onclick={dismiss}>
215
272
  <IconX />
216
273
  </IconButton>
@@ -227,26 +284,28 @@
227
284
  {#if showStrokeColor}
228
285
  <div class="flex h-9 w-full items-start" data-canvas-panel-row="stroke">
229
286
  <span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.stroke')}</span>
230
- <ColorField label={$t('canvas.panel.stroke')} value={traits.stroke} onchange={(color, commit) => changeStyle({ stroke: color }, commit)} />
287
+ <!-- A pen always has a colour: "no colour" is a choice for the outline of a shape, not for the line the next stroke is drawn with. -->
288
+ <ColorField label={$t('canvas.panel.stroke')} value={traits.stroke} allowNone={!editsPen} onchange={(color, commit) => changeStyle({ stroke: color }, commit)} />
231
289
  </div>
232
290
  {/if}
233
291
 
234
292
  {#if traits.strokeWidth.kind !== 'none'}
235
293
  <div class="flex h-9 w-full items-start" data-canvas-panel-row="strokeWidth">
236
294
  <span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.strokeWidth')}</span>
237
- <!-- 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. -->
238
- <NumberStepper
239
- class="w-[185px]"
240
- label={$t('canvas.panel.strokeWidth')}
241
- decreaseLabel={$t('canvas.panel.decrease')}
242
- increaseLabel={$t('canvas.panel.increase')}
243
- value={traits.strokeWidth.kind === 'same' ? Number(strokeWidthValue.toFixed(1)) : null}
244
- fallbackValue={strokeWidthValue}
245
- min={0}
246
- max={200}
247
- step={1}
248
- onChange={(next) => changeStyle({ strokeWidth: next })}
249
- />
295
+ <!-- The design system's number control (IC Number), the one the editor draws: the value can be typed or stepped, and the group names the two buttons after the row. -->
296
+ <div class="w-[185px] shrink-0">
297
+ <NumberControls
298
+ label={$t('canvas.panel.strokeWidth')}
299
+ decreaseLabel={$t('canvas.panel.decrease')}
300
+ increaseLabel={$t('canvas.panel.increase')}
301
+ value={traits.strokeWidth.kind === 'same' ? Number(strokeWidthValue.toFixed(1)) : null}
302
+ fallbackValue={strokeWidthValue}
303
+ min={strokeWidthMin}
304
+ max={200}
305
+ step={1}
306
+ onChange={(next) => changeStyle({ strokeWidth: next })}
307
+ />
308
+ </div>
250
309
  </div>
251
310
  {/if}
252
311
 
@@ -264,7 +323,7 @@
264
323
  <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'))}>
265
324
  <span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.opacity')}</span>
266
325
  <div class="flex w-[185px] shrink-0 items-center gap-3">
267
- <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} />
326
+ <Slider type="single" min={opacityMin} max={100} step={1} value={percent(traitNumber(traits.opacity, 1))} onValueChange={(next: number) => changeStyle({ opacity: next / 100 }, false)} onValueCommit={endChange} />
268
327
  <span class="w-7 shrink-0 text-end text-body tabular-nums">{traits.opacity.kind === 'same' ? percent(traits.opacity.value) : '–'}</span>
269
328
  </div>
270
329
  </div>
@@ -316,18 +375,19 @@
316
375
 
317
376
  <div class="flex h-9 w-full items-start">
318
377
  <span class="flex h-9 min-w-0 flex-1 items-center gap-1 text-body">{$t('canvas.panel.fontSize')}</span>
319
- <NumberStepper
320
- class="w-[185px]"
321
- label={$t('canvas.panel.fontSize')}
322
- decreaseLabel={$t('canvas.panel.decrease')}
323
- increaseLabel={$t('canvas.panel.increase')}
324
- value={typeof fontSizeDisplay === 'number' ? fontSizeDisplay : null}
325
- fallbackValue={fontSizeValue}
326
- min={8}
327
- max={200}
328
- step={1}
329
- onChange={(next) => changeStyle({ fontSize: next })}
330
- />
378
+ <div class="w-[185px] shrink-0">
379
+ <NumberControls
380
+ label={$t('canvas.panel.fontSize')}
381
+ decreaseLabel={$t('canvas.panel.decrease')}
382
+ increaseLabel={$t('canvas.panel.increase')}
383
+ value={typeof fontSizeDisplay === 'number' ? fontSizeDisplay : null}
384
+ fallbackValue={fontSizeValue}
385
+ min={8}
386
+ max={200}
387
+ step={1}
388
+ onChange={(next) => changeStyle({ fontSize: next })}
389
+ />
390
+ </div>
331
391
  </div>
332
392
 
333
393
  <div class="flex items-center justify-between gap-1" role="group" aria-label={$t('canvas.control.textStyle')}>
@@ -357,6 +417,9 @@
357
417
  </div>
358
418
  {/if}
359
419
 
360
- <WidgetActions {host} {state} {ui} {traits} {canCapture} {canConvert} {canRename} {canRefresh} {canOpenDetails} />
420
+ <!-- What can be done with the sketch for the page (capture, convert, rename) is about the board, not about the pen: the pen's panel is only the pen. -->
421
+ {#if !editsPen}
422
+ <WidgetActions {host} {state} {ui} {traits} {canCapture} {canConvert} {canRename} {canRefresh} {canOpenDetails} />
423
+ {/if}
361
424
  </aside>
362
425
  {/if}
@@ -1,17 +1,23 @@
1
1
  <!--
2
2
  Figma "Shape Menu": the button with the category icon and a chevron at the end of the toolbar's drawing group, and the menu it
3
3
  opens: the eight shapes people reach for (a square, a rounded square, a circle, a triangle, a diamond, a hexagon, a star
4
- and a pentagon), the media entries (an image, an SVG), and "More shapes", which opens the whole library by group.
4
+ and a pentagon), the media entries (the person's files, when the page offers them, then an image and an SVG), and "More shapes",
5
+ which opens the whole library by group.
5
6
 
6
7
  The menu is the design system's Dropdown Menu, portaled so it is not clipped by a hosting card (see floatingLayer.ts).
7
8
  Choosing a shape does not draw it: it arms the tool,
8
9
  and the shape is dragged out on the board, as for every tool.
10
+
11
+ Each tile has a tooltip with the shape's name and, when it has one, its key (the same tooltip as the toolbar's buttons). The keys
12
+ of the shapes work while the menu is open: the host answers them (see `CanvasHost`), the tool changes and the menu stays open,
13
+ so the mark moves to the tile of the shape as it is looked at.
9
14
  -->
10
15
  <script lang="ts">
11
16
  import { DropdownMenu } from '@widgetic/design-system/components';
12
17
  import type { ToolId } from '../../engine/state.js';
13
18
  import { useCanvasLanguage } from '../../i18n/language.js';
14
19
  import { categoryLabel } from '../../i18n/labels.js';
20
+ import { TOOL_KEYS } from '../../i18n/shortcuts.js';
15
21
  import { getShapeByKey, getShapesByCategory } from '../shapes/ShapeLibrary.js';
16
22
  import type { LibraryShape } from '../shapes/ShapeLibrary.js';
17
23
  import type { CanvasHost } from '../host/CanvasHost.js';
@@ -23,16 +29,19 @@
23
29
  MENU_TRIGGER_RING_CLASSES,
24
30
  OVERLAY_REDUCED_MOTION_CLASSES,
25
31
  SHAPE_LIBRARY_STROKE_WIDTH,
32
+ TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES,
26
33
  TOOLBAR_ICON_STROKE_CLASSES
27
34
  } from './floatingCard.js';
28
35
  import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
29
36
  import { usePopoverSide } from './popoverSide.js';
37
+ import ShortcutTooltip from './ShortcutTooltip.svelte';
30
38
  import {
31
39
  IconBrowser,
32
40
  IconCategory,
33
41
  IconChevronDown,
34
42
  IconCircle,
35
43
  IconDiamond,
44
+ IconFolder,
36
45
  IconHexagon,
37
46
  IconPentagon,
38
47
  IconPhoto,
@@ -51,9 +60,11 @@
51
60
  open: boolean;
52
61
  /** The key that opens the image chooser, as it is printed on a key cap. */
53
62
  imageShortcut: string;
63
+ /** Whether the menu offers the person's file library before the Image entry (the page turned it on and gave the browser that opens it). */
64
+ showFiles?: boolean;
54
65
  }
55
66
 
56
- let { host, tool, libraryShapeKey, open, imageShortcut }: Props = $props();
67
+ let { host, tool, libraryShapeKey, open, imageShortcut, showFiles = false }: Props = $props();
57
68
 
58
69
  // The menu is drawn into the canvas's floating layer (see floatingLayer.ts).
59
70
  const floatingLayer = useFloatingLayer();
@@ -66,20 +77,24 @@
66
77
 
67
78
  const { t } = useCanvasLanguage();
68
79
 
69
- /** A tile of the first two rows: what it draws, how it is named, and when it is the one in use. */
80
+ /** A tile of the first two rows: what it draws, how it is named, the key that chooses it (if it has one), and when it is the one in use. */
70
81
  interface Tile {
71
82
  id: string;
72
83
  icon: CanvasIcon;
73
84
  label: CanvasMessageKey;
85
+ /** The key that chooses the shape, as it is printed on a key cap: in the tile's tooltip, and its `aria-keyshortcuts`. */
86
+ shortcut?: string;
74
87
  active: boolean;
75
88
  choose: () => void;
76
89
  }
77
90
 
78
91
  const tiles = $derived<Tile[]>([
79
- { id: 'rect', icon: IconSquare, label: 'canvas.tool.rectangle', active: tool === 'rect', choose: () => host.onSelectShapeTool('rect') },
92
+ { id: 'rect', icon: IconSquare, label: 'canvas.tool.rectangle', shortcut: TOOL_KEYS.rectangle, active: tool === 'rect', choose: () => host.onSelectShapeTool('rect') },
80
93
  { id: 'rounded-rect', icon: IconSquareRounded, label: 'canvas.tool.roundedRectangle', active: tool === 'rounded-rect', choose: () => host.onSelectShapeTool('rounded-rect') },
81
- { id: 'circle', icon: IconCircle, label: 'canvas.tool.circle', active: tool === 'circle', choose: () => host.onSelectShapeTool('circle-true') },
82
- { id: 'triangle', icon: IconTriangle, label: 'canvas.tool.triangle', active: tool === 'triangle', choose: () => host.onSelectShapeTool('triangle') },
94
+ // The round shape of the menu: its key (O) draws the oval, which the menu has no tile of its own for, so the circle's tile is the one
95
+ // that is marked (and that names the key) whether the tool in use is the circle or the oval.
96
+ { id: 'circle', icon: IconCircle, label: 'canvas.tool.circle', shortcut: TOOL_KEYS.ellipse, active: tool === 'circle' || tool === 'ellipse', choose: () => host.onSelectShapeTool('circle-true') },
97
+ { id: 'triangle', icon: IconTriangle, label: 'canvas.tool.triangle', shortcut: TOOL_KEYS.triangle, active: tool === 'triangle', choose: () => host.onSelectShapeTool('triangle') },
83
98
  libraryTile('diamond', IconDiamond),
84
99
  libraryTile('hexagon', IconHexagon),
85
100
  libraryTile('star', IconStar),
@@ -117,7 +132,7 @@
117
132
  type="button"
118
133
  aria-label={$t('canvas.tool.shapes')}
119
134
  data-active={shapeToolInUse ? '' : undefined}
120
- class="flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground transition-colors duration-fast hover:bg-accent focus-visible:outline-hidden data-[active]:bg-brand-subtle {MENU_TRIGGER_RING_CLASSES} [&_svg]:size-4 {TOOLBAR_ICON_STROKE_CLASSES}"
135
+ class="flex h-9 w-[51px] shrink-0 items-center justify-center gap-1 rounded-lg text-foreground transition-colors duration-fast hover:bg-accent focus-visible:bg-accent focus-visible:outline-hidden data-[active]:bg-brand-subtle {TOOLBAR_ACTIVE_FOCUS_TINT_CLASSES} {MENU_TRIGGER_RING_CLASSES} [&_svg]:size-4 {TOOLBAR_ICON_STROKE_CLASSES}"
121
136
  >
122
137
  <IconCategory />
123
138
  <IconChevronDown class="transition-transform duration-fast motion-reduce:transition-none data-[open]:rotate-180" data-open={open ? '' : undefined} />
@@ -125,25 +140,39 @@
125
140
  {/snippet}
126
141
  </DropdownMenu.Trigger>
127
142
 
128
- <DropdownMenu.Content side={menuSide} align={menuAlign} sideOffset={8} portalProps={canvasOverlayPortalProps($floatingLayer)} aria-label={$t('canvas.tool.shapes')} class="{CANVAS_OVERLAY_Z_CLASS} w-[196px] {MENU_PADDING_CLASS} shadow-floating focus-visible:outline-hidden {OVERLAY_REDUCED_MOTION_CLASSES}">
143
+ <!-- `data-canvas-ui`: the menu (its "More shapes" submenu sits inside it) is the canvas's own even when it is portaled to `document.body` (a page without a shadow root), so a press on a tile is not a press outside the canvas (`outsideClickDeselect.ts`). -->
144
+ <DropdownMenu.Content side={menuSide} align={menuAlign} sideOffset={8} portalProps={canvasOverlayPortalProps($floatingLayer)} aria-label={$t('canvas.tool.shapes')} data-canvas-ui class="{CANVAS_OVERLAY_Z_CLASS} w-[196px] {MENU_PADDING_CLASS} shadow-floating focus-visible:outline-hidden {OVERLAY_REDUCED_MOTION_CLASSES}">
129
145
  <DropdownMenu.Label>{$t('canvas.tool.shapes')}</DropdownMenu.Label>
130
146
  <div class="grid grid-cols-4 gap-x-3 px-1" role="presentation">
131
147
  {#each tiles as tile (tile.id)}
132
- <DropdownMenu.Item
133
- aria-label={$t(tile.label)}
134
- aria-current={tile.active ? 'true' : undefined}
135
- title={$t(tile.label)}
136
- data-active={tile.active ? '' : undefined}
137
- class="size-9 min-h-9 justify-center p-0 data-[active]:bg-brand-subtle {TOOLBAR_ICON_STROKE_CLASSES}"
138
- onSelect={tile.choose}
139
- >
140
- <tile.icon class="size-4" />
141
- </DropdownMenu.Item>
148
+ <!-- The pointer gives a menu entry the focus as it passes, so only a focus from the keyboard opens the tooltip at once. -->
149
+ <ShortcutTooltip label={$t(tile.label)} shortcut={tile.shortcut} side="top" ignoreNonKeyboardFocus passive>
150
+ {#snippet trigger(triggerProps)}
151
+ <DropdownMenu.Item
152
+ {...triggerProps}
153
+ aria-label={$t(tile.label)}
154
+ aria-keyshortcuts={tile.shortcut}
155
+ aria-current={tile.active ? 'true' : undefined}
156
+ data-active={tile.active ? '' : undefined}
157
+ class="size-9 min-h-9 justify-center p-0 data-[active]:bg-brand-subtle {TOOLBAR_ICON_STROKE_CLASSES}"
158
+ onSelect={tile.choose}
159
+ >
160
+ <tile.icon class="size-4" />
161
+ </DropdownMenu.Item>
162
+ {/snippet}
163
+ </ShortcutTooltip>
142
164
  {/each}
143
165
  </div>
144
166
 
145
167
  <DropdownMenu.Separator />
146
168
  <DropdownMenu.Label>{$t('canvas.menu.media')}</DropdownMenu.Label>
169
+ <!-- The person's file library (the page's File Browser, in select state). Only when the page turned it on: it is off by default. -->
170
+ {#if showFiles}
171
+ <DropdownMenu.Item data-canvas-files-entry onSelect={() => void host.openFileBrowser()}>
172
+ <IconFolder />
173
+ <span class="flex-1">{$t('canvas.tool.files')}</span>
174
+ </DropdownMenu.Item>
175
+ {/if}
147
176
  <DropdownMenu.Item aria-keyshortcuts={imageShortcut} onSelect={() => void host.addImage()}>
148
177
  <IconPhoto />
149
178
  <span class="flex-1">{$t('canvas.tool.image')}</span>
@@ -161,19 +190,24 @@
161
190
  <DropdownMenu.Label>{categoryLabel(category, $t)}</DropdownMenu.Label>
162
191
  <div class="grid grid-cols-5 gap-1 px-1 pb-1" role="presentation">
163
192
  {#each shapes as shape (shape.key)}
164
- <DropdownMenu.Item
165
- aria-label={$t(shape.labelKey)}
166
- aria-current={tool === 'library-shape' && libraryShapeKey === shape.key ? 'true' : undefined}
167
- title={$t(shape.labelKey)}
168
- data-active={tool === 'library-shape' && libraryShapeKey === shape.key ? '' : undefined}
169
- class="size-9 min-h-9 justify-center p-0 data-[active]:bg-brand-subtle"
170
- onSelect={() => host.onSelectLibraryShapeTool(shape.key)}
171
- >
172
- <!-- The width is an inline style on purpose: the menu item's `[&_svg]:stroke-2` would beat the attribute (see floatingCard.ts). -->
173
- <svg viewBox="0 0 100 100" class="size-4" fill="none" stroke="currentColor" style:stroke-width={SHAPE_LIBRARY_STROKE_WIDTH} stroke-linejoin="round" stroke-linecap="round" aria-hidden="true">
174
- <path d={shape.pathData} />
175
- </svg>
176
- </DropdownMenu.Item>
193
+ <!-- The shapes of the library have no key: their tooltip is the name alone. -->
194
+ <ShortcutTooltip label={$t(shape.labelKey)} side="top" ignoreNonKeyboardFocus passive>
195
+ {#snippet trigger(triggerProps)}
196
+ <DropdownMenu.Item
197
+ {...triggerProps}
198
+ aria-label={$t(shape.labelKey)}
199
+ aria-current={tool === 'library-shape' && libraryShapeKey === shape.key ? 'true' : undefined}
200
+ data-active={tool === 'library-shape' && libraryShapeKey === shape.key ? '' : undefined}
201
+ class="size-9 min-h-9 justify-center p-0 data-[active]:bg-brand-subtle"
202
+ onSelect={() => host.onSelectLibraryShapeTool(shape.key)}
203
+ >
204
+ <!-- The width is an inline style on purpose: the menu item's `[&_svg]:stroke-2` would beat the attribute (see floatingCard.ts). -->
205
+ <svg viewBox="0 0 100 100" class="size-4" fill="none" stroke="currentColor" style:stroke-width={SHAPE_LIBRARY_STROKE_WIDTH} stroke-linejoin="round" stroke-linecap="round" aria-hidden="true">
206
+ <path d={shape.pathData} />
207
+ </svg>
208
+ </DropdownMenu.Item>
209
+ {/snippet}
210
+ </ShortcutTooltip>
177
211
  {/each}
178
212
  </div>
179
213
  {/each}
@@ -9,6 +9,8 @@ interface Props {
9
9
  open: boolean;
10
10
  /** The key that opens the image chooser, as it is printed on a key cap. */
11
11
  imageShortcut: string;
12
+ /** Whether the menu offers the person's file library before the Image entry (the page turned it on and gave the browser that opens it). */
13
+ showFiles?: boolean;
12
14
  }
13
15
  declare const ShapesMenu: import("svelte").Component<Props, {}, "">;
14
16
  type ShapesMenu = ReturnType<typeof ShapesMenu>;
@@ -0,0 +1,64 @@
1
+ <!--
2
+ The tooltip of a control of the chrome: its name and, when it has one, the key that does the same, on a key cap (Figma "Tool
3
+ Button" tooltip). The toolbar's buttons and the tiles of the Shapes menu draw it, so the two look and behave alike.
4
+
5
+ The control is whatever the caller draws, handed in as the `trigger` snippet: it is given the props of the tooltip's trigger to
6
+ spread onto its element (an Icon Button, a plain button, an entry of a menu). The tooltip is drawn into the canvas's floating
7
+ layer, not in place (see floatingLayer.ts), and it opens after the delay the canvas's provider gives it (`CANVAS_TOOLTIP_DELAY_MS`,
8
+ set in DomCanvas.svelte).
9
+ -->
10
+ <script lang="ts">
11
+ import type { Snippet } from 'svelte';
12
+ import { Tooltip } from '@widgetic/design-system/components';
13
+ import { CANVAS_OVERLAY_Z_CLASS, OVERLAY_REDUCED_MOTION_CLASSES } from './floatingCard.js';
14
+ import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
15
+ import { usePopoverSide } from './popoverSide.js';
16
+
17
+ interface Props {
18
+ /** What the control does: the first line of the tooltip. */
19
+ label: string;
20
+ /** The key that does the same, as it is printed on a key cap ("V"), or nothing: the tooltip is then the name alone. */
21
+ shortcut?: string | undefined;
22
+ /** The side the tooltip opens on. Left out: away from the edge the toolbar stands against (see popoverSide.ts). */
23
+ side?: 'top' | 'right' | 'bottom' | 'left' | undefined;
24
+ /**
25
+ * For a control the pointer gives the focus to by itself (the entries of a menu take the focus as the pointer passes over
26
+ * them): only a focus that comes from the keyboard opens the tooltip at once, and the pointer opens it after its delay.
27
+ */
28
+ ignoreNonKeyboardFocus?: boolean;
29
+ /**
30
+ * The tooltip closes as soon as the pointer leaves the control and cannot be hovered itself, so it never stands between the
31
+ * pointer and the controls it overlaps (the tiles of a menu lie close together).
32
+ */
33
+ passive?: boolean;
34
+ /** The control. It is given the props of the tooltip's trigger, to spread onto its element. */
35
+ trigger: Snippet<[Record<string, unknown>]>;
36
+ }
37
+
38
+ let { label, shortcut = undefined, side = undefined, ignoreNonKeyboardFocus = false, passive = false, trigger }: Props = $props();
39
+
40
+ // The tooltip is drawn into the canvas's floating layer, not in place: see floatingLayer.ts.
41
+ const floatingLayer = useFloatingLayer();
42
+ // Until the canvas has made its layer nothing is mounted (the tooltip is closed then anyway), so the page's body is not written to.
43
+ const overlayPortal = $derived(canvasOverlayPortalProps($floatingLayer));
44
+ // It opens away from the edge the card stands on: upward from the bottom, downward from the top, sideways from a side.
45
+ const popoverSide = usePopoverSide();
46
+ </script>
47
+
48
+ <Tooltip.Root {ignoreNonKeyboardFocus} disableHoverableContent={passive}>
49
+ <Tooltip.Trigger>
50
+ {#snippet child({ props }: { props: Record<string, unknown> })}
51
+ {@render trigger(props)}
52
+ {/snippet}
53
+ </Tooltip.Trigger>
54
+ <Tooltip.Portal to={overlayPortal.to} disabled={overlayPortal.disabled}>
55
+ <Tooltip.Content side={side ?? popoverSide()} sideOffset={passive ? 6 : 8} class="{CANVAS_OVERLAY_Z_CLASS} {OVERLAY_REDUCED_MOTION_CLASSES} {passive ? 'pointer-events-none' : ''}">
56
+ <span class="flex items-center gap-2">
57
+ <span>{label}</span>
58
+ {#if shortcut}
59
+ <kbd class="rounded-sm bg-muted px-1.5 py-0.5 font-sans text-xs text-muted-foreground">{shortcut}</kbd>
60
+ {/if}
61
+ </span>
62
+ </Tooltip.Content>
63
+ </Tooltip.Portal>
64
+ </Tooltip.Root>