@widgetic/canvas 0.5.34 → 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.
Files changed (212) hide show
  1. package/README.md +105 -36
  2. package/dist/canvas/DomCanvas.svelte +454 -0
  3. package/dist/canvas/DomCanvas.svelte.d.ts +222 -0
  4. package/dist/canvas/autosaveScheduler.d.ts +58 -0
  5. package/dist/canvas/autosaveScheduler.js +157 -0
  6. package/dist/canvas/boardFrame.d.ts +13 -0
  7. package/dist/canvas/boardFrame.js +13 -0
  8. package/dist/canvas/boardSurface.d.ts +9 -0
  9. package/dist/canvas/boardSurface.js +9 -0
  10. package/dist/canvas/chromeLayout.d.ts +76 -0
  11. package/dist/canvas/chromeLayout.js +121 -0
  12. package/dist/canvas/emptyBoardHint.d.ts +17 -0
  13. package/dist/canvas/emptyBoardHint.js +12 -0
  14. package/dist/canvas/eventScope.d.ts +1 -1
  15. package/dist/canvas/eventScope.js +1 -1
  16. package/dist/canvas/host/CanvasHost.d.ts +351 -0
  17. package/dist/canvas/host/CanvasHost.js +1740 -0
  18. package/dist/canvas/host/CanvasHostApi.d.ts +30 -0
  19. package/dist/canvas/host/CanvasHostApi.js +95 -0
  20. package/dist/canvas/host/browserServices.d.ts +46 -0
  21. package/dist/canvas/host/browserServices.js +167 -0
  22. package/dist/canvas/host/conversion.d.ts +51 -0
  23. package/dist/canvas/host/conversion.js +123 -0
  24. package/dist/canvas/host/hostObject.d.ts +40 -0
  25. package/dist/canvas/host/hostObject.js +93 -0
  26. package/dist/canvas/host/pageEvents.d.ts +24 -0
  27. package/dist/canvas/host/pageEvents.js +35 -0
  28. package/dist/canvas/host/screenRects.d.ts +66 -0
  29. package/dist/canvas/host/screenRects.js +102 -0
  30. package/dist/canvas/host/strokeSnap.d.ts +67 -0
  31. package/dist/canvas/host/strokeSnap.js +165 -0
  32. package/dist/canvas/index.d.ts +9 -7
  33. package/dist/canvas/index.js +9 -7
  34. package/dist/canvas/openMarks.d.ts +17 -0
  35. package/dist/canvas/openMarks.js +26 -0
  36. package/dist/canvas/panZoomPosition.d.ts +15 -0
  37. package/dist/canvas/panZoomPosition.js +16 -0
  38. package/dist/canvas/preferredTextFont.d.ts +12 -0
  39. package/dist/canvas/preferredTextFont.js +38 -0
  40. package/dist/canvas/shapes/ShapeLibrary.d.ts +1 -1
  41. package/dist/canvas/shapes/ShapeLibrary.js +13 -1
  42. package/dist/canvas/shapes/strokeShapeSnap.d.ts +14 -12
  43. package/dist/canvas/shapes/strokeShapeSnap.js +10 -8
  44. package/dist/canvas/toolbarPosition.d.ts +24 -0
  45. package/dist/canvas/toolbarPosition.js +24 -0
  46. package/dist/canvas/types.d.ts +14 -0
  47. package/dist/canvas/ui/CanvasContextMenu.svelte +173 -0
  48. package/dist/canvas/ui/CanvasContextMenu.svelte.d.ts +12 -0
  49. package/dist/canvas/ui/CanvasHint.svelte +20 -0
  50. package/dist/canvas/ui/CanvasHint.svelte.d.ts +18 -0
  51. package/dist/canvas/ui/CanvasToolbar.svelte +95 -0
  52. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +14 -0
  53. package/dist/canvas/ui/ColorField.svelte +155 -0
  54. package/dist/canvas/ui/ColorField.svelte.d.ts +14 -0
  55. package/dist/canvas/ui/LoadNotice.svelte +39 -0
  56. package/dist/canvas/ui/LoadNotice.svelte.d.ts +8 -0
  57. package/dist/canvas/ui/SelectionPanel.svelte +300 -0
  58. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +20 -0
  59. package/dist/canvas/ui/SelectorBar.svelte +82 -0
  60. package/dist/canvas/ui/SelectorBar.svelte.d.ts +12 -0
  61. package/dist/canvas/ui/ShapesMenu.svelte +185 -0
  62. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +15 -0
  63. package/dist/canvas/ui/ShortcutsPanel.svelte +124 -0
  64. package/dist/canvas/ui/ShortcutsPanel.svelte.d.ts +7 -0
  65. package/dist/canvas/ui/ToolButton.svelte +78 -0
  66. package/dist/canvas/ui/ToolButton.svelte.d.ts +20 -0
  67. package/dist/canvas/ui/WidgetActions.svelte +152 -0
  68. package/dist/canvas/ui/WidgetActions.svelte.d.ts +19 -0
  69. package/dist/canvas/ui/ZoomControl.svelte +89 -0
  70. package/dist/canvas/ui/ZoomControl.svelte.d.ts +18 -0
  71. package/dist/canvas/ui/colorModel.d.ts +18 -0
  72. package/dist/canvas/ui/colorModel.js +85 -0
  73. package/dist/canvas/ui/colorPickerMessages.d.ts +5 -0
  74. package/dist/canvas/ui/colorPickerMessages.js +15 -0
  75. package/dist/canvas/ui/floatingCard.d.ts +107 -0
  76. package/dist/canvas/ui/floatingCard.js +107 -0
  77. package/dist/canvas/ui/floatingLayer.d.ts +21 -0
  78. package/dist/canvas/ui/floatingLayer.js +52 -0
  79. package/dist/canvas/ui/icons.d.ts +12 -0
  80. package/dist/canvas/ui/icons.js +7 -0
  81. package/dist/canvas/ui/keyHints.d.ts +27 -0
  82. package/dist/canvas/ui/keyHints.js +43 -0
  83. package/dist/canvas/ui/popoverSide.d.ts +5 -0
  84. package/dist/canvas/ui/popoverSide.js +20 -0
  85. package/dist/canvas/ui/selectionTraits.d.ts +61 -0
  86. package/dist/canvas/ui/selectionTraits.js +99 -0
  87. package/dist/canvas/view/CanvasStage.svelte +132 -0
  88. package/dist/canvas/view/CanvasStage.svelte.d.ts +21 -0
  89. package/dist/canvas/view/EraserTrail.svelte +50 -0
  90. package/dist/canvas/view/EraserTrail.svelte.d.ts +9 -0
  91. package/dist/canvas/view/ObjectView.svelte +245 -0
  92. package/dist/canvas/view/ObjectView.svelte.d.ts +21 -0
  93. package/dist/canvas/view/SelectionOverlay.svelte +487 -0
  94. package/dist/canvas/view/SelectionOverlay.svelte.d.ts +17 -0
  95. package/dist/canvas/view/TextEditor.svelte +76 -0
  96. package/dist/canvas/view/TextEditor.svelte.d.ts +9 -0
  97. package/dist/canvas/view/WidgetChromeLayer.svelte +83 -0
  98. package/dist/canvas/view/WidgetChromeLayer.svelte.d.ts +13 -0
  99. package/dist/canvas/view/erasingMarks.d.ts +13 -0
  100. package/dist/canvas/view/erasingMarks.js +34 -0
  101. package/dist/canvas/view/geometry.d.ts +169 -0
  102. package/dist/canvas/view/geometry.js +272 -0
  103. package/dist/components/CanvasBoardPlaceholder.svelte +5 -3
  104. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +3 -3
  105. package/dist/components/index.js +1 -1
  106. package/dist/components/input-controls/ColorIC.svelte +2 -2
  107. package/dist/engine/EngineCore.d.ts +273 -0
  108. package/dist/engine/EngineCore.js +1051 -0
  109. package/dist/engine/codec/canvasDocument.d.ts +57 -0
  110. package/dist/engine/codec/canvasDocument.js +471 -0
  111. package/dist/engine/codec/hostReadableKeys.d.ts +25 -0
  112. package/dist/engine/codec/hostReadableKeys.js +25 -0
  113. package/dist/engine/core/arrange.d.ts +20 -0
  114. package/dist/engine/core/arrange.js +81 -0
  115. package/dist/engine/core/arrow.d.ts +91 -0
  116. package/dist/engine/core/arrow.js +182 -0
  117. package/dist/engine/core/brush.d.ts +68 -0
  118. package/dist/engine/core/brush.js +173 -0
  119. package/dist/engine/core/defaults.d.ts +70 -0
  120. package/dist/engine/core/defaults.js +158 -0
  121. package/dist/engine/core/freehand.d.ts +130 -0
  122. package/dist/engine/core/freehand.js +430 -0
  123. package/dist/engine/core/geometry.d.ts +44 -0
  124. package/dist/engine/core/geometry.js +216 -0
  125. package/dist/engine/core/history.d.ts +39 -0
  126. package/dist/engine/core/history.js +69 -0
  127. package/dist/engine/core/hitTest.d.ts +54 -0
  128. package/dist/engine/core/hitTest.js +298 -0
  129. package/dist/engine/core/matrix.d.ts +47 -0
  130. package/dist/engine/core/matrix.js +101 -0
  131. package/dist/engine/core/pathData.d.ts +50 -0
  132. package/dist/engine/core/pathData.js +550 -0
  133. package/dist/engine/core/rotationReset.d.ts +10 -0
  134. package/dist/engine/core/rotationReset.js +17 -0
  135. package/dist/engine/core/scene.d.ts +99 -0
  136. package/dist/engine/core/scene.js +450 -0
  137. package/dist/engine/core/scribble.d.ts +64 -0
  138. package/dist/engine/core/scribble.js +121 -0
  139. package/dist/engine/core/shapePaths.d.ts +34 -0
  140. package/dist/engine/core/shapePaths.js +69 -0
  141. package/dist/engine/core/shapeTools.d.ts +80 -0
  142. package/dist/engine/core/shapeTools.js +161 -0
  143. package/dist/engine/core/snapping.d.ts +64 -0
  144. package/dist/engine/core/snapping.js +164 -0
  145. package/dist/engine/core/style.d.ts +40 -0
  146. package/dist/engine/core/style.js +151 -0
  147. package/dist/engine/core/transform.d.ts +79 -0
  148. package/dist/engine/core/transform.js +258 -0
  149. package/dist/engine/core/types.d.ts +238 -0
  150. package/dist/engine/core/types.js +31 -0
  151. package/dist/engine/core/viewport.d.ts +32 -0
  152. package/dist/engine/core/viewport.js +84 -0
  153. package/dist/engine/input/PointerController.d.ts +38 -0
  154. package/dist/engine/input/PointerController.js +545 -0
  155. package/dist/engine/input/arrowHandles.d.ts +38 -0
  156. package/dist/engine/input/arrowHandles.js +60 -0
  157. package/dist/engine/input/gestures.d.ts +79 -0
  158. package/dist/engine/input/gestures.js +769 -0
  159. package/dist/engine/input/hoverCursor.d.ts +29 -0
  160. package/dist/engine/input/hoverCursor.js +23 -0
  161. package/dist/engine/input/keyboard.d.ts +75 -0
  162. package/dist/engine/input/keyboard.js +264 -0
  163. package/dist/engine/input/selectionHandles.d.ts +89 -0
  164. package/dist/engine/input/selectionHandles.js +169 -0
  165. package/dist/engine/input/types.d.ts +82 -0
  166. package/dist/engine/input/types.js +5 -0
  167. package/dist/engine/render/rasterize.d.ts +74 -0
  168. package/dist/engine/render/rasterize.js +273 -0
  169. package/dist/engine/state.d.ts +124 -0
  170. package/dist/engine/state.js +47 -0
  171. package/dist/engine/text/layoutText.d.ts +53 -0
  172. package/dist/engine/text/layoutText.js +170 -0
  173. package/dist/engine/widgets.d.ts +124 -0
  174. package/dist/engine/widgets.js +345 -0
  175. package/dist/i18n/labels.d.ts +4 -15
  176. package/dist/i18n/labels.js +33 -53
  177. package/dist/i18n/language.d.ts +3 -3
  178. package/dist/i18n/messages.d.ts +51 -122
  179. package/dist/i18n/messages.js +58 -131
  180. package/dist/i18n/shortcuts.d.ts +0 -1
  181. package/dist/i18n/shortcuts.js +2 -11
  182. package/dist/index.d.ts +6 -2
  183. package/dist/index.js +6 -2
  184. package/package.json +30 -5
  185. package/dist/canvas/Canvas.svelte +0 -13299
  186. package/dist/canvas/Canvas.svelte.d.ts +0 -281
  187. package/dist/canvas/CanvasToolbar.svelte +0 -1498
  188. package/dist/canvas/CanvasToolbar.svelte.d.ts +0 -69
  189. package/dist/canvas/ContextMenu.svelte +0 -305
  190. package/dist/canvas/ContextMenu.svelte.d.ts +0 -42
  191. package/dist/canvas/PanZoomPanel.svelte +0 -478
  192. package/dist/canvas/PanZoomPanel.svelte.d.ts +0 -38
  193. package/dist/canvas/WidgetSelectionLayer.svelte +0 -156
  194. package/dist/canvas/WidgetSelectionLayer.svelte.d.ts +0 -11
  195. package/dist/canvas/props-panel/PropsPanel.svelte +0 -2075
  196. package/dist/canvas/props-panel/PropsPanel.svelte.d.ts +0 -84
  197. package/dist/canvas/props-panel/TextPropsICSection.svelte +0 -242
  198. package/dist/canvas/props-panel/TextPropsICSection.svelte.d.ts +0 -40
  199. package/dist/canvas/shadowRootText.d.ts +0 -5
  200. package/dist/canvas/shadowRootText.js +0 -43
  201. package/dist/canvas/shapes/FrameShape.d.ts +0 -97
  202. package/dist/canvas/shapes/FrameShape.js +0 -953
  203. package/dist/canvas/shapes/ImageShape.d.ts +0 -47
  204. package/dist/canvas/shapes/ImageShape.js +0 -339
  205. package/dist/canvas/shapes/WidgetShape.d.ts +0 -30
  206. package/dist/canvas/shapes/WidgetShape.js +0 -200
  207. package/dist/canvas/widgetPreviewGeometry.d.ts +0 -19
  208. package/dist/canvas/widgetPreviewGeometry.js +0 -66
  209. package/dist/i18n/shapeWords.d.ts +0 -30
  210. package/dist/i18n/shapeWords.js +0 -36
  211. package/dist/i18n/slots.d.ts +0 -20
  212. package/dist/i18n/slots.js +0 -40
@@ -0,0 +1,89 @@
1
+ <!--
2
+ Figma "Zoom Control": a card of the same make as the toolbar, with 32 px buttons: zoom out, the level (a click puts it back
3
+ to 100%), zoom in, a divider and "fit content to view". Beside it, when the page asks for them, the Save button (with the
4
+ state of the save) and the keyboard shortcuts button.
5
+
6
+ It stands where `panZoomPosition` says (the bottom left by default): any of the eight places of `chromeLayout.ts`. On the
7
+ left or the right edge it stands upright, its buttons one under the other and its tooltips opening sideways. On a board too
8
+ narrow for it the zoom card is not drawn, as in the Figma mobile layout: a pinch zooms, and the keys do the rest. How
9
+ narrow depends on the toolbar: on the bottom edge it shares the line with a centred toolbar, so it needs 720 px (Figma's
10
+ tablet board, 736 px, shows both); at the other places `zoomVisibilityClasses` says. The Save button stays at every width,
11
+ and a page that turns the zoom card off (`showZoomPanel`) keeps it. The list of keyboard shortcuts is opened with the `?`
12
+ key; the design has no button for it.
13
+
14
+ The card is placed by its slot (see `chromeLayout.ts`), which also puts it beside the toolbar when both are named for
15
+ the same place.
16
+ -->
17
+ <script lang="ts">
18
+ import { Separator } from '@widgetic/design-system/components';
19
+ import type { EngineState } from '../../engine/state.js';
20
+ import { useCanvasLanguage } from '../../i18n/language.js';
21
+ import { isSideAnchor, popoverSideFor } from '../chromeLayout.js';
22
+ import type { ChromeAnchor } from '../chromeLayout.js';
23
+ import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
24
+ import ToolButton from './ToolButton.svelte';
25
+ import { IconArrowsMaximize, IconCheck, IconDeviceFloppy, IconLoader2, IconZoomIn, IconZoomOut } from './icons.js';
26
+ import { chordText, isApplePlatform } from './keyHints.js';
27
+ import { FLOATING_CARD_CLASSES } from './floatingCard.js';
28
+ import { providePopoverSide } from './popoverSide.js';
29
+
30
+ interface Props {
31
+ host: CanvasHost;
32
+ state: EngineState;
33
+ ui: HostUiState;
34
+ /** Where the control stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
35
+ anchor: ChromeAnchor;
36
+ /** The classes that show the zoom card from the width of board it needs (see `zoomVisibilityClasses`). */
37
+ visibleFrom: string;
38
+ /** The page's `showZoomPanel`: whether the zoom card is drawn at all. */
39
+ showZoom: boolean;
40
+ showSaveButton: boolean;
41
+ }
42
+
43
+ let { host, state, ui, anchor, visibleFrom, showZoom, showSaveButton }: Props = $props();
44
+
45
+ const { t } = useCanvasLanguage();
46
+
47
+ const apple = isApplePlatform();
48
+ const percent = $derived(Math.round(state.viewport.zoom * 100));
49
+ const vertical = $derived(isSideAnchor(anchor));
50
+ // The tooltips open away from the edge the card stands against.
51
+ providePopoverSide(() => popoverSideFor(anchor));
52
+
53
+ const saveLabel = $derived(ui.saveState === 'dirty' ? $t('canvas.zoom.unsavedTitle') : $t('canvas.zoom.savedTitle'));
54
+ </script>
55
+
56
+ <div class="pointer-events-auto flex gap-2 {vertical ? 'flex-col items-center' : 'items-center'}" data-canvas-zoom-control data-anchor={anchor}>
57
+ {#if showZoom}
58
+ <div role="group" aria-label={$t('canvas.zoom.groupLabel')} class="{visibleFrom} items-center gap-1 {vertical ? 'flex-col' : ''} {FLOATING_CARD_CLASSES}">
59
+ <ToolButton size="compact" label={$t('canvas.zoom.outLabel')} shortcut={chordText({ mod: true, key: '−' }, apple, $t)} onclick={() => host.zoomOut()}>
60
+ <IconZoomOut />
61
+ </ToolButton>
62
+ <!-- The level is 40 px wide in a row; upright it is as wide as the other buttons of the card. -->
63
+ <ToolButton size="level" class={vertical ? 'w-8!' : ''} label={$t('canvas.zoom.resetLabel')} shortcut={chordText({ mod: true, key: '0' }, apple, $t)} onclick={() => host.zoomReset()}>
64
+ {percent}%
65
+ </ToolButton>
66
+ <ToolButton size="compact" label={$t('canvas.zoom.inLabel')} shortcut={chordText({ mod: true, key: '+' }, apple, $t)} onclick={() => host.zoomIn()}>
67
+ <IconZoomIn />
68
+ </ToolButton>
69
+ <Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
70
+ <ToolButton size="compact" label={$t('canvas.zoom.fitLabel')} shortcut={chordText({ mod: true, key: '9' }, apple, $t)} onclick={() => host.zoomFit()}>
71
+ <IconArrowsMaximize />
72
+ </ToolButton>
73
+ </div>
74
+ {/if}
75
+
76
+ {#if showSaveButton}
77
+ <div class={FLOATING_CARD_CLASSES}>
78
+ <ToolButton size="compact" label={saveLabel} shortcut={chordText({ mod: true, key: 'S' }, apple, $t)} disabled={ui.saveState !== 'dirty'} onclick={() => host.saveNow()}>
79
+ {#if ui.saveState === 'saving'}
80
+ <IconLoader2 class="animate-spin" />
81
+ {:else if ui.saveState === 'saved'}
82
+ <IconCheck />
83
+ {:else}
84
+ <IconDeviceFloppy />
85
+ {/if}
86
+ </ToolButton>
87
+ </div>
88
+ {/if}
89
+ </div>
@@ -0,0 +1,18 @@
1
+ import type { EngineState } from '../../engine/state.js';
2
+ import type { ChromeAnchor } 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
+ /** Where the control stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
9
+ anchor: ChromeAnchor;
10
+ /** The classes that show the zoom card from the width of board it needs (see `zoomVisibilityClasses`). */
11
+ visibleFrom: string;
12
+ /** The page's `showZoomPanel`: whether the zoom card is drawn at all. */
13
+ showZoom: boolean;
14
+ showSaveButton: boolean;
15
+ }
16
+ declare const ZoomControl: import("svelte").Component<Props, {}, "">;
17
+ type ZoomControl = ReturnType<typeof ZoomControl>;
18
+ export default ZoomControl;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Colours as the selection panel shows and takes them: `#RRGGBB` in capitals, or no colour at all.
3
+ *
4
+ * The board stores whatever string the engine's records hold (a hex, a named colour from an older canvas, `transparent`),
5
+ * and the panel has to show it and to take what a person types. Plain functions, free of Svelte and of the DOM, so Node
6
+ * can test them.
7
+ */
8
+ /** The colours the panel offers first, one click each. The first two are the board's own ink and paper. */
9
+ export declare const COLOR_PRESETS: readonly string[];
10
+ /** True for a colour that paints nothing: `transparent`, or a colour that is fully see-through. */
11
+ export declare function isNoColor(color: string | null | undefined): boolean;
12
+ /** What a person typed (`f80`, `#FF8800`, `ff8800`) as `#RRGGBB`, or null when it is not a colour. */
13
+ export declare function parseHexInput(text: string): string | null;
14
+ /**
15
+ * A stored colour as `#RRGGBB`: a hex, an `rgb()` or `hsl()` an older canvas may hold, or the nearest the browser can
16
+ * say for a colour name. `fallback` is what is answered for a colour that cannot be read.
17
+ */
18
+ export declare function colorToHex(color: string | null | undefined, fallback?: string): string;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Colours as the selection panel shows and takes them: `#RRGGBB` in capitals, or no colour at all.
3
+ *
4
+ * The board stores whatever string the engine's records hold (a hex, a named colour from an older canvas, `transparent`),
5
+ * and the panel has to show it and to take what a person types. Plain functions, free of Svelte and of the DOM, so Node
6
+ * can test them.
7
+ */
8
+ /** The colours the panel offers first, one click each. The first two are the board's own ink and paper. */
9
+ export const COLOR_PRESETS = [
10
+ '#0F172A',
11
+ '#FFFFFF',
12
+ '#EF4444',
13
+ '#F97316',
14
+ '#EAB308',
15
+ '#22C55E',
16
+ '#3B82F6',
17
+ '#A855F7',
18
+ '#EC4899',
19
+ '#6B7280'
20
+ ];
21
+ const HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
22
+ /** True for a colour that paints nothing: `transparent`, or a colour that is fully see-through. */
23
+ export function isNoColor(color) {
24
+ if (!color)
25
+ return true;
26
+ const text = color.trim().toLowerCase();
27
+ if (text === 'transparent' || text === 'none')
28
+ return true;
29
+ const rgba = text.match(/^rgba\(\s*[^,]+,\s*[^,]+,\s*[^,]+,\s*([\d.]+)\s*\)$/);
30
+ return rgba ? Number.parseFloat(rgba[1]) === 0 : false;
31
+ }
32
+ /** What a person typed (`f80`, `#FF8800`, `ff8800`) as `#RRGGBB`, or null when it is not a colour. */
33
+ export function parseHexInput(text) {
34
+ const match = text.trim().match(HEX_PATTERN);
35
+ if (!match)
36
+ return null;
37
+ const digits = match[1].length === 3 ? [...match[1]].map((digit) => digit + digit).join('') : match[1];
38
+ return `#${digits.toUpperCase()}`;
39
+ }
40
+ function toHexByte(value) {
41
+ return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, '0');
42
+ }
43
+ function hslToHex(hue, saturation, lightness) {
44
+ const s = saturation / 100;
45
+ const l = lightness / 100;
46
+ const a = s * Math.min(l, 1 - l);
47
+ const channel = (n) => {
48
+ const k = (n + hue / 30) % 12;
49
+ return toHexByte(255 * (l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)));
50
+ };
51
+ return `#${channel(0)}${channel(8)}${channel(4)}`.toUpperCase();
52
+ }
53
+ /**
54
+ * A stored colour as `#RRGGBB`: a hex, an `rgb()` or `hsl()` an older canvas may hold, or the nearest the browser can
55
+ * say for a colour name. `fallback` is what is answered for a colour that cannot be read.
56
+ */
57
+ export function colorToHex(color, fallback = '#000000') {
58
+ if (!color)
59
+ return fallback;
60
+ const hex = parseHexInput(color);
61
+ if (hex)
62
+ return hex;
63
+ const text = color.trim();
64
+ const rgb = text.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);
65
+ if (rgb)
66
+ return `#${toHexByte(Number(rgb[1]))}${toHexByte(Number(rgb[2]))}${toHexByte(Number(rgb[3]))}`.toUpperCase();
67
+ const hsl = text.match(/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%/i);
68
+ if (hsl)
69
+ return hslToHex(Number(hsl[1]), Number(hsl[2]), Number(hsl[3]));
70
+ return NAMED_COLORS[text.toLowerCase()] ?? fallback;
71
+ }
72
+ /** The few colour names an older canvas may hold. A name that is not here reads as the fallback. */
73
+ const NAMED_COLORS = Object.freeze({
74
+ black: '#000000',
75
+ white: '#FFFFFF',
76
+ red: '#FF0000',
77
+ green: '#008000',
78
+ blue: '#0000FF',
79
+ yellow: '#FFFF00',
80
+ orange: '#FFA500',
81
+ purple: '#800080',
82
+ pink: '#FFC0CB',
83
+ gray: '#808080',
84
+ grey: '#808080'
85
+ });
@@ -0,0 +1,5 @@
1
+ import type { Translate } from '@widgetic/design-system/i18n';
2
+ import type { ColorPickerMessages } from '@widgetic/design-system/components';
3
+ import type { CanvasMessageKey } from '../../i18n/messages.js';
4
+ /** Words the design-system colour picker speaks; templates keep their placeholders for the picker to replace. */
5
+ export declare function colorPickerMessages(t: Translate<CanvasMessageKey>): ColorPickerMessages;
@@ -0,0 +1,15 @@
1
+ /** Names the colour picker fills in at runtime (`{s}`, `{v}`, `{hex}`), built without literals the word scan would read. */
2
+ const s = `{${'s'}}`;
3
+ const v = `{${'v'}}`;
4
+ const hex = `{${'hex'}}`;
5
+ /** Words the design-system colour picker speaks; templates keep their placeholders for the picker to replace. */
6
+ export function colorPickerMessages(t) {
7
+ return {
8
+ area: t('canvas.colorPicker.area'),
9
+ areaValue: t('canvas.colorPicker.areaValue', { s, v }),
10
+ hue: t('canvas.colorPicker.hue'),
11
+ hex: t('canvas.panel.hex'),
12
+ add: t('canvas.colorPicker.add'),
13
+ swatch: t('canvas.colorPicker.swatch', { hex })
14
+ };
15
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The look of the small cards that float over the board: the toolbar, the zoom control, the Save button and the element
3
+ * selector bar, and the widths of the board at which the zoom control gives way to the toolbar.
4
+ *
5
+ * Figma draws each card with 4 px of padding and a 1 px border that sits *inside* that padding (an inside stroke takes no
6
+ * room in a Figma layout), so a card of 36 px buttons measures 44 px high and the zoom control, with its 32 px buttons, 40 px.
7
+ * In CSS a border takes room of its own, so the padding is 3 px: the buttons then stand 4 px from the outer edge of the
8
+ * card, as in the design, and the cards measure what the design says (349 x 44 for the whole toolbar, 161 x 40 for the zoom
9
+ * control).
10
+ *
11
+ * The classes are written out in full, so that the stylesheet of a page that installs the canvas picks every one of them up
12
+ * when it reads this file. Kept free of Svelte and of the DOM so that Node can test it.
13
+ */
14
+ /** The card itself: its corners, border, fill, padding and shadow. */
15
+ export declare const FLOATING_CARD_CLASSES = "rounded-xl border border-border bg-background p-[3px] shadow-floating";
16
+ /**
17
+ * The padding of the canvas's menus (the Shapes menu, the right-click menu and their submenus). They are the design system's
18
+ * Dropdown Menu, drawn in Figma the same way as the cards above: the first row stands 4 px from the outer edge, the 1 px
19
+ * border inside that. The component's own padding (4 px, beside the border) makes a menu 2 px larger each way than Figma's:
20
+ * the Shape Menu is 196 x 246 there, and measures 246 only with 3 px.
21
+ */
22
+ export declare const MENU_PADDING_CLASS = "p-[3px]";
23
+ /**
24
+ * A menu, a popover or a tooltip of the design system slides and fades in, and its classes do not ask whether the system wants
25
+ * less motion. The canvas adds this to each one it draws: with `prefers-reduced-motion: reduce` the card appears and goes
26
+ * without the animation (and a card with no animation is taken out as soon as it is closed, with nothing to wait for).
27
+ *
28
+ * The states are those of the three components: a menu and a popover are `open` and `closed`, a tooltip `delayed-open`,
29
+ * `instant-open` and `closed`.
30
+ */
31
+ export declare const OVERLAY_REDUCED_MOTION_CLASSES = "motion-reduce:animate-none motion-reduce:data-[state=open]:animate-none motion-reduce:data-[state=closed]:animate-none motion-reduce:data-[state=delayed-open]:animate-none motion-reduce:data-[state=instant-open]:animate-none";
32
+ /** Canvas-floated surfaces stay below site dialogs and toasts (design-system overlays use z-50). */
33
+ export declare const CANVAS_OVERLAY_Z_CLASS = "z-40";
34
+ /**
35
+ * The ring of a menu's button while its menu is open, and while the keyboard is on it: 2 px of ring standing 2 px off the
36
+ * button, with the board's colour in the gap, as the design system draws its focus ring. Figma draws the open "Shapes" button
37
+ * that way (the ring makes it 59 x 44, the height of the toolbar).
38
+ *
39
+ * It is two plain shadows, not Tailwind's `ring-2 ring-offset-2`: the design system's global stylesheet zeroes
40
+ * `--tw-ring-offset-width` with `!important` on every element that has `aria-expanded` (a menu's button always has), so the
41
+ * offset of a ring on such a button is lost, whatever class asks for it.
42
+ */
43
+ export declare const MENU_TRIGGER_RING_CLASSES = "focus-visible:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)] data-[state=open]:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)]";
44
+ /**
45
+ * Tabler toolbar icons are 16 px (`size-4`) with stroke 2 in a 24 px viewBox: 2 × 16 / 24 = 1.333 px on screen.
46
+ * A library shape glyph is drawn in a 100 px viewBox, so it needs a stroke of 1.333 × 100 / 16 = 8.33 in its own units to
47
+ * look as thick. The design system's menu item forces `size-4` and `stroke-2` on every svg inside it through CSS, which beats
48
+ * the `stroke-width` attribute (the glyphs were 0.32 px thick), so the width is set inline on the glyph.
49
+ */
50
+ export declare const TOOLBAR_ICON_STROKE_CLASSES = "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:stroke-2";
51
+ export declare const TOOLBAR_ICON_SIZE_PX = 16;
52
+ export declare const TOOLBAR_ICON_VIEWBOX = 24;
53
+ export declare const TOOLBAR_ICON_STROKE_UNITS = 2;
54
+ export declare const TOOLBAR_ICON_STROKE_PX: number;
55
+ export declare const SHAPE_LIBRARY_ICON_SIZE_PX = 16;
56
+ export declare const SHAPE_LIBRARY_VIEWBOX = 100;
57
+ export declare const SHAPE_LIBRARY_STROKE_WIDTH: number;
58
+ /** Figma's measures of the cards, in px (a Figma frame counts an inside stroke as part of the card). */
59
+ export declare const FLOATING_CARD_METRICS: {
60
+ /** The whole toolbar: five tools, the Shapes menu and the history group, with their dividers. */
61
+ readonly toolbarWidth: 349;
62
+ readonly toolbarHeight: 44;
63
+ /** The toolbar on a phone: the same without the history group. */
64
+ readonly toolbarWidthWithoutHistory: 264;
65
+ readonly zoomControlWidth: 161;
66
+ readonly zoomControlHeight: 40;
67
+ /** The room between a card and the edge of the board. */
68
+ readonly edgeInset: 16;
69
+ };
70
+ /**
71
+ * The class that shows the history group (undo, redo) on a horizontal toolbar from the width of board that holds the whole
72
+ * toolbar and its two 16 px edges: 349 + 2 x 16 = 381, rounded up to 384. Figma's phone is 358 px wide, too narrow for that,
73
+ * and draws the bar without the history group; a board that holds the bar keeps it, because a touch screen has no keys to undo
74
+ * with. (An upright bar is as long as the board is tall, so it always has them.) Written out in full, so a page's stylesheet
75
+ * picks it up.
76
+ */
77
+ export declare const TOOLBAR_HISTORY_VISIBLE_FROM = "hidden @min-[384px]:flex";
78
+ /**
79
+ * The width of board from which the zoom card is drawn, by the way it stands beside the toolbar (see `chromeLayout.ts`, which
80
+ * picks the case from the two anchors a page named). Narrower than that the zoom card is not drawn, as in Figma's phone: a
81
+ * pinch zooms, and the keys do the rest. Each width is the sum the design implies, with at least 8 px between the cards,
82
+ * rounded up to a multiple of 16:
83
+ *
84
+ * - `alone`: nothing shares its line (the toolbar is on another edge, or one of the two stands upright on a side edge), so
85
+ * a board of 512 px (a container of the `lg` size) is wide enough.
86
+ * - `sameSlot`: both named for one place, side by side: 349 px of toolbar, 8 px, 161 px of zoom card, and the 16 px edges.
87
+ * - `oppositeCorners`: the toolbar at one corner of an edge, the zoom card at the other: they need what `sameSlot` needs.
88
+ * - `besideCentredToolbar`: a centred toolbar and the zoom card at a corner of the same edge. Figma's tablet board is 736 px
89
+ * wide and shows them side by side, 16 px apart; from 720 px they are still 8 px apart.
90
+ * - `centredBesideCornerToolbar`: the toolbar at a corner and the zoom card centred: the card's left edge has to clear the
91
+ * toolbar's right edge, which is 365 px from the board's left edge.
92
+ */
93
+ export declare const ZOOM_CONTROL_MIN_WIDTHS: {
94
+ readonly alone: 512;
95
+ readonly sameSlot: 560;
96
+ readonly oppositeCorners: 560;
97
+ readonly besideCentredToolbar: 720;
98
+ readonly centredBesideCornerToolbar: 912;
99
+ };
100
+ /** The classes that show the zoom card from each of those widths. Written out in full, so a page's stylesheet picks every one up. */
101
+ export declare const ZOOM_CONTROL_VISIBLE_FROM: {
102
+ readonly alone: "hidden @lg:flex";
103
+ readonly sameSlot: "hidden @min-[560px]:flex";
104
+ readonly oppositeCorners: "hidden @min-[560px]:flex";
105
+ readonly besideCentredToolbar: "hidden @min-[720px]:flex";
106
+ readonly centredBesideCornerToolbar: "hidden @min-[912px]:flex";
107
+ };
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The look of the small cards that float over the board: the toolbar, the zoom control, the Save button and the element
3
+ * selector bar, and the widths of the board at which the zoom control gives way to the toolbar.
4
+ *
5
+ * Figma draws each card with 4 px of padding and a 1 px border that sits *inside* that padding (an inside stroke takes no
6
+ * room in a Figma layout), so a card of 36 px buttons measures 44 px high and the zoom control, with its 32 px buttons, 40 px.
7
+ * In CSS a border takes room of its own, so the padding is 3 px: the buttons then stand 4 px from the outer edge of the
8
+ * card, as in the design, and the cards measure what the design says (349 x 44 for the whole toolbar, 161 x 40 for the zoom
9
+ * control).
10
+ *
11
+ * The classes are written out in full, so that the stylesheet of a page that installs the canvas picks every one of them up
12
+ * when it reads this file. Kept free of Svelte and of the DOM so that Node can test it.
13
+ */
14
+ /** The card itself: its corners, border, fill, padding and shadow. */
15
+ export const FLOATING_CARD_CLASSES = 'rounded-xl border border-border bg-background p-[3px] shadow-floating';
16
+ /**
17
+ * The padding of the canvas's menus (the Shapes menu, the right-click menu and their submenus). They are the design system's
18
+ * Dropdown Menu, drawn in Figma the same way as the cards above: the first row stands 4 px from the outer edge, the 1 px
19
+ * border inside that. The component's own padding (4 px, beside the border) makes a menu 2 px larger each way than Figma's:
20
+ * the Shape Menu is 196 x 246 there, and measures 246 only with 3 px.
21
+ */
22
+ export const MENU_PADDING_CLASS = 'p-[3px]';
23
+ /**
24
+ * A menu, a popover or a tooltip of the design system slides and fades in, and its classes do not ask whether the system wants
25
+ * less motion. The canvas adds this to each one it draws: with `prefers-reduced-motion: reduce` the card appears and goes
26
+ * without the animation (and a card with no animation is taken out as soon as it is closed, with nothing to wait for).
27
+ *
28
+ * The states are those of the three components: a menu and a popover are `open` and `closed`, a tooltip `delayed-open`,
29
+ * `instant-open` and `closed`.
30
+ */
31
+ export const OVERLAY_REDUCED_MOTION_CLASSES = 'motion-reduce:animate-none motion-reduce:data-[state=open]:animate-none motion-reduce:data-[state=closed]:animate-none motion-reduce:data-[state=delayed-open]:animate-none motion-reduce:data-[state=instant-open]:animate-none';
32
+ /** Canvas-floated surfaces stay below site dialogs and toasts (design-system overlays use z-50). */
33
+ export const CANVAS_OVERLAY_Z_CLASS = 'z-40';
34
+ /**
35
+ * The ring of a menu's button while its menu is open, and while the keyboard is on it: 2 px of ring standing 2 px off the
36
+ * button, with the board's colour in the gap, as the design system draws its focus ring. Figma draws the open "Shapes" button
37
+ * that way (the ring makes it 59 x 44, the height of the toolbar).
38
+ *
39
+ * It is two plain shadows, not Tailwind's `ring-2 ring-offset-2`: the design system's global stylesheet zeroes
40
+ * `--tw-ring-offset-width` with `!important` on every element that has `aria-expanded` (a menu's button always has), so the
41
+ * offset of a ring on such a button is lost, whatever class asks for it.
42
+ */
43
+ export const MENU_TRIGGER_RING_CLASSES = 'focus-visible:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)] data-[state=open]:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)]';
44
+ /**
45
+ * Tabler toolbar icons are 16 px (`size-4`) with stroke 2 in a 24 px viewBox: 2 × 16 / 24 = 1.333 px on screen.
46
+ * A library shape glyph is drawn in a 100 px viewBox, so it needs a stroke of 1.333 × 100 / 16 = 8.33 in its own units to
47
+ * look as thick. The design system's menu item forces `size-4` and `stroke-2` on every svg inside it through CSS, which beats
48
+ * the `stroke-width` attribute (the glyphs were 0.32 px thick), so the width is set inline on the glyph.
49
+ */
50
+ export const TOOLBAR_ICON_STROKE_CLASSES = '[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:stroke-2';
51
+ export const TOOLBAR_ICON_SIZE_PX = 16;
52
+ export const TOOLBAR_ICON_VIEWBOX = 24;
53
+ export const TOOLBAR_ICON_STROKE_UNITS = 2;
54
+ export const TOOLBAR_ICON_STROKE_PX = (TOOLBAR_ICON_STROKE_UNITS * TOOLBAR_ICON_SIZE_PX) / TOOLBAR_ICON_VIEWBOX;
55
+ export const SHAPE_LIBRARY_ICON_SIZE_PX = TOOLBAR_ICON_SIZE_PX;
56
+ export const SHAPE_LIBRARY_VIEWBOX = 100;
57
+ export const SHAPE_LIBRARY_STROKE_WIDTH = (TOOLBAR_ICON_STROKE_PX * SHAPE_LIBRARY_VIEWBOX) / SHAPE_LIBRARY_ICON_SIZE_PX;
58
+ /** Figma's measures of the cards, in px (a Figma frame counts an inside stroke as part of the card). */
59
+ export const FLOATING_CARD_METRICS = {
60
+ /** The whole toolbar: five tools, the Shapes menu and the history group, with their dividers. */
61
+ toolbarWidth: 349,
62
+ toolbarHeight: 44,
63
+ /** The toolbar on a phone: the same without the history group. */
64
+ toolbarWidthWithoutHistory: 264,
65
+ zoomControlWidth: 161,
66
+ zoomControlHeight: 40,
67
+ /** The room between a card and the edge of the board. */
68
+ edgeInset: 16
69
+ };
70
+ /**
71
+ * The class that shows the history group (undo, redo) on a horizontal toolbar from the width of board that holds the whole
72
+ * toolbar and its two 16 px edges: 349 + 2 x 16 = 381, rounded up to 384. Figma's phone is 358 px wide, too narrow for that,
73
+ * and draws the bar without the history group; a board that holds the bar keeps it, because a touch screen has no keys to undo
74
+ * with. (An upright bar is as long as the board is tall, so it always has them.) Written out in full, so a page's stylesheet
75
+ * picks it up.
76
+ */
77
+ export const TOOLBAR_HISTORY_VISIBLE_FROM = 'hidden @min-[384px]:flex';
78
+ /**
79
+ * The width of board from which the zoom card is drawn, by the way it stands beside the toolbar (see `chromeLayout.ts`, which
80
+ * picks the case from the two anchors a page named). Narrower than that the zoom card is not drawn, as in Figma's phone: a
81
+ * pinch zooms, and the keys do the rest. Each width is the sum the design implies, with at least 8 px between the cards,
82
+ * rounded up to a multiple of 16:
83
+ *
84
+ * - `alone`: nothing shares its line (the toolbar is on another edge, or one of the two stands upright on a side edge), so
85
+ * a board of 512 px (a container of the `lg` size) is wide enough.
86
+ * - `sameSlot`: both named for one place, side by side: 349 px of toolbar, 8 px, 161 px of zoom card, and the 16 px edges.
87
+ * - `oppositeCorners`: the toolbar at one corner of an edge, the zoom card at the other: they need what `sameSlot` needs.
88
+ * - `besideCentredToolbar`: a centred toolbar and the zoom card at a corner of the same edge. Figma's tablet board is 736 px
89
+ * wide and shows them side by side, 16 px apart; from 720 px they are still 8 px apart.
90
+ * - `centredBesideCornerToolbar`: the toolbar at a corner and the zoom card centred: the card's left edge has to clear the
91
+ * toolbar's right edge, which is 365 px from the board's left edge.
92
+ */
93
+ export const ZOOM_CONTROL_MIN_WIDTHS = {
94
+ alone: 512,
95
+ sameSlot: 560,
96
+ oppositeCorners: 560,
97
+ besideCentredToolbar: 720,
98
+ centredBesideCornerToolbar: 912
99
+ };
100
+ /** The classes that show the zoom card from each of those widths. Written out in full, so a page's stylesheet picks every one up. */
101
+ export const ZOOM_CONTROL_VISIBLE_FROM = {
102
+ alone: 'hidden @lg:flex',
103
+ sameSlot: 'hidden @min-[560px]:flex',
104
+ oppositeCorners: 'hidden @min-[560px]:flex',
105
+ besideCentredToolbar: 'hidden @min-[720px]:flex',
106
+ centredBesideCornerToolbar: 'hidden @min-[912px]:flex'
107
+ };
@@ -0,0 +1,21 @@
1
+ import type { Readable } from 'svelte/store';
2
+ /**
3
+ * The classes of the layer's element: no size (so it catches no press, and no `pointer-events: none` is needed, which the
4
+ * menus inside would inherit), above the chrome, and a containing block for what is fixed inside it.
5
+ */
6
+ export declare const FLOATING_LAYER_CLASSES = "absolute inset-0 z-50 h-0 w-0 [contain:layout]";
7
+ /** Called by the canvas that owns the layer, before its children are made. */
8
+ export declare function provideFloatingLayer(layer: Readable<HTMLElement | null>): void;
9
+ /** The element to draw a floating thing into. A piece used outside a canvas has none, and the library's own default applies. */
10
+ export declare function useFloatingLayer(): Readable<HTMLElement | null>;
11
+ /** Below design-system dialogs, dropdowns and toasts (`z-50`); still above normal page content so a compact card does not cover menus. */
12
+ export declare const CANVAS_OVERLAY_PORTAL_Z_CLASS = "z-40";
13
+ export type CanvasOverlayPortalProps = {
14
+ to?: HTMLElement;
15
+ class?: string;
16
+ };
17
+ /**
18
+ * Portal target for a menu, popover or tooltip: `document.body` in the light DOM, else the in-canvas floating layer.
19
+ * Floating UI still measures from the trigger; only the mount node changes.
20
+ */
21
+ export declare function canvasOverlayPortalProps(floatingLayer: HTMLElement | null | undefined): CanvasOverlayPortalProps;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The floating layer: where canvas menus, popovers and tooltips mount when the board lives in a shadow root.
3
+ *
4
+ * In the light DOM they mount on `document.body` instead (see `canvasOverlayPortalProps`), so nothing a page puts around the
5
+ * compact canvas (`overflow-hidden` on a card, rounded corners) clips them. In a shadow root the layer element is still used:
6
+ * styles and direction stay inside the root, and the layer is a containing block (`contain: layout`) so Floating UI's
7
+ * `position: fixed` coordinates are not shifted by the canvas root's `@container` query (Chrome disagrees with other engines
8
+ * on whether a query container is a containing block).
9
+ *
10
+ * `DomCanvas` makes the layer element and hands it down as a store; overlays ask for it through `useFloatingLayer` and
11
+ * `canvasOverlayPortalProps`.
12
+ */
13
+ import { getContext, setContext } from 'svelte';
14
+ import { readable } from 'svelte/store';
15
+ const FLOATING_LAYER_CONTEXT_KEY = Symbol('widgetic-canvas-floating-layer');
16
+ /**
17
+ * The classes of the layer's element: no size (so it catches no press, and no `pointer-events: none` is needed, which the
18
+ * menus inside would inherit), above the chrome, and a containing block for what is fixed inside it.
19
+ */
20
+ export const FLOATING_LAYER_CLASSES = 'absolute inset-0 z-50 h-0 w-0 [contain:layout]';
21
+ /** Called by the canvas that owns the layer, before its children are made. */
22
+ export function provideFloatingLayer(layer) {
23
+ setContext(FLOATING_LAYER_CONTEXT_KEY, layer);
24
+ }
25
+ /** The element to draw a floating thing into. A piece used outside a canvas has none, and the library's own default applies. */
26
+ export function useFloatingLayer() {
27
+ return getContext(FLOATING_LAYER_CONTEXT_KEY) ?? readable(null);
28
+ }
29
+ /** Below design-system dialogs, dropdowns and toasts (`z-50`); still above normal page content so a compact card does not cover menus. */
30
+ export const CANVAS_OVERLAY_PORTAL_Z_CLASS = 'z-40';
31
+ /**
32
+ * Portal target for a menu, popover or tooltip: `document.body` in the light DOM, else the in-canvas floating layer.
33
+ * Floating UI still measures from the trigger; only the mount node changes.
34
+ */
35
+ export function canvasOverlayPortalProps(floatingLayer) {
36
+ if (!floatingLayer) {
37
+ return typeof document !== 'undefined'
38
+ ? { to: document.body, class: CANVAS_OVERLAY_PORTAL_Z_CLASS }
39
+ : { class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
40
+ }
41
+ const root = floatingLayer.getRootNode();
42
+ if (typeof Document !== 'undefined' && root instanceof Document) {
43
+ return { to: document.body, class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
44
+ }
45
+ // A shadow root (and only that) exposes `host`; the layer stays the mount in that case.
46
+ if (root && typeof root === 'object' && 'host' in root) {
47
+ return { to: floatingLayer };
48
+ }
49
+ return typeof document !== 'undefined'
50
+ ? { to: document.body, class: CANVAS_OVERLAY_PORTAL_Z_CLASS }
51
+ : { class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
52
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Every icon the canvas draws, imported from the Widgetic design system's own set (Tabler) in this one place, so the list
3
+ * of what the chrome uses is visible at a glance and no component reaches for an icon library of its own.
4
+ */
5
+ import type { IconSquare as SquareIcon } from '@widgetic/design-system/icons';
6
+ export { IconAlertTriangle, IconAlignCenter, IconAlignLeft, IconAlignRight, IconArrowBackUp, IconArrowBarToDown, IconArrowBarToUp, IconArrowForwardUp, IconArrowsMaximize, IconArrowUpRight, IconBold, IconBrowser, IconCamera, IconCategory, IconCheck, IconChevronDown, IconCircle, IconClipboard, IconCopy, IconDeviceFloppy, IconDiamond, IconEraser, IconHexagon, IconItalic, IconLink, IconLoader2, IconPencil, IconPentagon, IconPhoto, IconPointer, IconRefresh, IconReplace, IconScissors, IconSelectAll, IconSettings, IconSquare, IconSquareRounded, IconStack, IconStack2, IconStackBack, IconStackFront, IconStackPop, IconStar, IconTrash, IconTriangle, IconTypography, IconUnderline, IconX, IconZoomIn, IconZoomOut } from '@widgetic/design-system/icons';
7
+ export { SquareDashedMousePointer as IconSelectElement } from '@widgetic/design-system/icons';
8
+ /**
9
+ * What a Tabler icon is: a component class that every icon of the set shares the shape of. A row of a menu keeps its icon
10
+ * in a field of this type (the design system's barrel gives the icons as classes, which Svelte's `Component` type does not take).
11
+ */
12
+ export type CanvasIcon = typeof SquareIcon;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Every icon the canvas draws, imported from the Widgetic design system's own set (Tabler) in this one place, so the list
3
+ * of what the chrome uses is visible at a glance and no component reaches for an icon library of its own.
4
+ */
5
+ export { IconAlertTriangle, IconAlignCenter, IconAlignLeft, IconAlignRight, IconArrowBackUp, IconArrowBarToDown, IconArrowBarToUp, IconArrowForwardUp, IconArrowsMaximize, IconArrowUpRight, IconBold, IconBrowser, IconCamera, IconCategory, IconCheck, IconChevronDown, IconCircle, IconClipboard, IconCopy, IconDeviceFloppy, IconDiamond, IconEraser, IconHexagon, IconItalic, IconLink, IconLoader2, IconPencil, IconPentagon, IconPhoto, IconPointer, IconRefresh, IconReplace, IconScissors, IconSelectAll, IconSettings, IconSquare, IconSquareRounded, IconStack, IconStack2, IconStackBack, IconStackFront, IconStackPop, IconStar, IconTrash, IconTriangle, IconTypography, IconUnderline, IconX, IconZoomIn, IconZoomOut } from '@widgetic/design-system/icons';
6
+ // The element selector's own icon exists only in the Lucide set of the design system's barrel.
7
+ export { SquareDashedMousePointer as IconSelectElement } from '@widgetic/design-system/icons';
@@ -0,0 +1,27 @@
1
+ import type { Translate } from '@widgetic/design-system/i18n';
2
+ import type { CanvasMessageKey } from '../../i18n/messages.js';
3
+ type Translator = Translate<CanvasMessageKey>;
4
+ /** A shortcut as the menus and tooltips write it: the shortcut key (Ctrl or Command), Shift, and one more key. */
5
+ export interface Chord {
6
+ /** Ctrl on Windows and Linux, Command on a Mac. */
7
+ mod?: boolean;
8
+ shift?: boolean;
9
+ /** A key cap that reads the same everywhere ("X", "]"), or a key that is a word. */
10
+ key: string | {
11
+ name: CanvasMessageKey;
12
+ };
13
+ }
14
+ /** True on a Mac, an iPhone or an iPad, where the shortcut key is Command and the menus print it as a symbol. */
15
+ export declare function isApplePlatform(nav?: Navigator | undefined): boolean;
16
+ /**
17
+ * The same shortcut as `aria-keyshortcuts` writes it, which names the keys in English whatever the page's language:
18
+ * "Meta+Shift+]" on a Mac, "Control+Shift+]" elsewhere. A chord whose key is a word of the catalog has no such name here, and
19
+ * gives nothing.
20
+ */
21
+ export declare function ariaKeyShortcut(chord: Chord, apple: boolean): string | undefined;
22
+ /**
23
+ * The text of a shortcut on this platform: "⇧⌘]" on a Mac, "Ctrl+Shift+]" elsewhere. The modifier symbols of a Mac are
24
+ * the same in every language; the words of the others come from the page's language.
25
+ */
26
+ export declare function chordText(chord: Chord, apple: boolean, t: Translator): string;
27
+ export {};
@@ -0,0 +1,43 @@
1
+ /** The platform name of a browser, from the newer API when there is one. */
2
+ function platformName(nav) {
3
+ const withData = nav;
4
+ return withData.userAgentData?.platform ?? nav.platform ?? '';
5
+ }
6
+ /** True on a Mac, an iPhone or an iPad, where the shortcut key is Command and the menus print it as a symbol. */
7
+ export function isApplePlatform(nav = typeof navigator === 'undefined' ? undefined : navigator) {
8
+ if (!nav)
9
+ return false;
10
+ return /mac|iphone|ipad|ipod/i.test(platformName(nav));
11
+ }
12
+ /**
13
+ * The same shortcut as `aria-keyshortcuts` writes it, which names the keys in English whatever the page's language:
14
+ * "Meta+Shift+]" on a Mac, "Control+Shift+]" elsewhere. A chord whose key is a word of the catalog has no such name here, and
15
+ * gives nothing.
16
+ */
17
+ export function ariaKeyShortcut(chord, apple) {
18
+ if (typeof chord.key !== 'string')
19
+ return undefined;
20
+ const parts = [];
21
+ if (chord.mod)
22
+ parts.push(apple ? 'Meta' : 'Control');
23
+ if (chord.shift)
24
+ parts.push('Shift');
25
+ parts.push(chord.key);
26
+ return parts.join('+');
27
+ }
28
+ /**
29
+ * The text of a shortcut on this platform: "⇧⌘]" on a Mac, "Ctrl+Shift+]" elsewhere. The modifier symbols of a Mac are
30
+ * the same in every language; the words of the others come from the page's language.
31
+ */
32
+ export function chordText(chord, apple, t) {
33
+ const key = typeof chord.key === 'string' ? chord.key : t(chord.key.name);
34
+ if (apple)
35
+ return `${chord.shift ? '⇧' : ''}${chord.mod ? '⌘' : ''}${key}`;
36
+ const parts = [];
37
+ if (chord.mod)
38
+ parts.push(t('canvas.key.ctrl'));
39
+ if (chord.shift)
40
+ parts.push(t('canvas.key.shift'));
41
+ parts.push(key);
42
+ return parts.join('+');
43
+ }
@@ -0,0 +1,5 @@
1
+ import type { PopoverSide } from '../chromeLayout.js';
2
+ /** Called by a card of the chrome, before its children are made. */
3
+ export declare function providePopoverSide(getSide: () => PopoverSide): void;
4
+ /** The side to open a tooltip or a menu to. A button used outside a card of the chrome opens upward, as the bottom toolbar always did. */
5
+ export declare function usePopoverSide(): () => PopoverSide;