@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.
- package/README.md +105 -36
- package/dist/canvas/DomCanvas.svelte +454 -0
- package/dist/canvas/DomCanvas.svelte.d.ts +222 -0
- package/dist/canvas/autosaveScheduler.d.ts +58 -0
- package/dist/canvas/autosaveScheduler.js +157 -0
- package/dist/canvas/boardFrame.d.ts +13 -0
- package/dist/canvas/boardFrame.js +13 -0
- package/dist/canvas/boardSurface.d.ts +9 -0
- package/dist/canvas/boardSurface.js +9 -0
- package/dist/canvas/chromeLayout.d.ts +76 -0
- package/dist/canvas/chromeLayout.js +121 -0
- package/dist/canvas/emptyBoardHint.d.ts +17 -0
- package/dist/canvas/emptyBoardHint.js +12 -0
- package/dist/canvas/eventScope.d.ts +1 -1
- package/dist/canvas/eventScope.js +1 -1
- package/dist/canvas/host/CanvasHost.d.ts +351 -0
- package/dist/canvas/host/CanvasHost.js +1740 -0
- package/dist/canvas/host/CanvasHostApi.d.ts +30 -0
- package/dist/canvas/host/CanvasHostApi.js +95 -0
- package/dist/canvas/host/browserServices.d.ts +46 -0
- package/dist/canvas/host/browserServices.js +167 -0
- package/dist/canvas/host/conversion.d.ts +51 -0
- package/dist/canvas/host/conversion.js +123 -0
- package/dist/canvas/host/hostObject.d.ts +40 -0
- package/dist/canvas/host/hostObject.js +93 -0
- package/dist/canvas/host/pageEvents.d.ts +24 -0
- package/dist/canvas/host/pageEvents.js +35 -0
- package/dist/canvas/host/screenRects.d.ts +66 -0
- package/dist/canvas/host/screenRects.js +102 -0
- package/dist/canvas/host/strokeSnap.d.ts +67 -0
- package/dist/canvas/host/strokeSnap.js +165 -0
- package/dist/canvas/index.d.ts +9 -7
- package/dist/canvas/index.js +9 -7
- package/dist/canvas/openMarks.d.ts +17 -0
- package/dist/canvas/openMarks.js +26 -0
- package/dist/canvas/panZoomPosition.d.ts +15 -0
- package/dist/canvas/panZoomPosition.js +16 -0
- package/dist/canvas/preferredTextFont.d.ts +12 -0
- package/dist/canvas/preferredTextFont.js +38 -0
- package/dist/canvas/shapes/ShapeLibrary.d.ts +1 -1
- package/dist/canvas/shapes/ShapeLibrary.js +13 -1
- package/dist/canvas/shapes/strokeShapeSnap.d.ts +14 -12
- package/dist/canvas/shapes/strokeShapeSnap.js +10 -8
- package/dist/canvas/toolbarPosition.d.ts +24 -0
- package/dist/canvas/toolbarPosition.js +24 -0
- package/dist/canvas/types.d.ts +14 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +173 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte.d.ts +12 -0
- package/dist/canvas/ui/CanvasHint.svelte +20 -0
- package/dist/canvas/ui/CanvasHint.svelte.d.ts +18 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +95 -0
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +14 -0
- package/dist/canvas/ui/ColorField.svelte +155 -0
- package/dist/canvas/ui/ColorField.svelte.d.ts +14 -0
- package/dist/canvas/ui/LoadNotice.svelte +39 -0
- package/dist/canvas/ui/LoadNotice.svelte.d.ts +8 -0
- package/dist/canvas/ui/SelectionPanel.svelte +300 -0
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +20 -0
- package/dist/canvas/ui/SelectorBar.svelte +82 -0
- package/dist/canvas/ui/SelectorBar.svelte.d.ts +12 -0
- package/dist/canvas/ui/ShapesMenu.svelte +185 -0
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +15 -0
- package/dist/canvas/ui/ShortcutsPanel.svelte +124 -0
- package/dist/canvas/ui/ShortcutsPanel.svelte.d.ts +7 -0
- package/dist/canvas/ui/ToolButton.svelte +78 -0
- package/dist/canvas/ui/ToolButton.svelte.d.ts +20 -0
- package/dist/canvas/ui/WidgetActions.svelte +152 -0
- package/dist/canvas/ui/WidgetActions.svelte.d.ts +19 -0
- package/dist/canvas/ui/ZoomControl.svelte +89 -0
- package/dist/canvas/ui/ZoomControl.svelte.d.ts +18 -0
- package/dist/canvas/ui/colorModel.d.ts +18 -0
- package/dist/canvas/ui/colorModel.js +85 -0
- package/dist/canvas/ui/colorPickerMessages.d.ts +5 -0
- package/dist/canvas/ui/colorPickerMessages.js +15 -0
- package/dist/canvas/ui/floatingCard.d.ts +107 -0
- package/dist/canvas/ui/floatingCard.js +107 -0
- package/dist/canvas/ui/floatingLayer.d.ts +21 -0
- package/dist/canvas/ui/floatingLayer.js +52 -0
- package/dist/canvas/ui/icons.d.ts +12 -0
- package/dist/canvas/ui/icons.js +7 -0
- package/dist/canvas/ui/keyHints.d.ts +27 -0
- package/dist/canvas/ui/keyHints.js +43 -0
- package/dist/canvas/ui/popoverSide.d.ts +5 -0
- package/dist/canvas/ui/popoverSide.js +20 -0
- package/dist/canvas/ui/selectionTraits.d.ts +61 -0
- package/dist/canvas/ui/selectionTraits.js +99 -0
- package/dist/canvas/view/CanvasStage.svelte +132 -0
- package/dist/canvas/view/CanvasStage.svelte.d.ts +21 -0
- package/dist/canvas/view/EraserTrail.svelte +50 -0
- package/dist/canvas/view/EraserTrail.svelte.d.ts +9 -0
- package/dist/canvas/view/ObjectView.svelte +245 -0
- package/dist/canvas/view/ObjectView.svelte.d.ts +21 -0
- package/dist/canvas/view/SelectionOverlay.svelte +487 -0
- package/dist/canvas/view/SelectionOverlay.svelte.d.ts +17 -0
- package/dist/canvas/view/TextEditor.svelte +76 -0
- package/dist/canvas/view/TextEditor.svelte.d.ts +9 -0
- package/dist/canvas/view/WidgetChromeLayer.svelte +83 -0
- package/dist/canvas/view/WidgetChromeLayer.svelte.d.ts +13 -0
- package/dist/canvas/view/erasingMarks.d.ts +13 -0
- package/dist/canvas/view/erasingMarks.js +34 -0
- package/dist/canvas/view/geometry.d.ts +169 -0
- package/dist/canvas/view/geometry.js +272 -0
- package/dist/components/CanvasBoardPlaceholder.svelte +5 -3
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +3 -3
- package/dist/components/index.js +1 -1
- package/dist/components/input-controls/ColorIC.svelte +2 -2
- package/dist/engine/EngineCore.d.ts +273 -0
- package/dist/engine/EngineCore.js +1051 -0
- package/dist/engine/codec/canvasDocument.d.ts +57 -0
- package/dist/engine/codec/canvasDocument.js +471 -0
- package/dist/engine/codec/hostReadableKeys.d.ts +25 -0
- package/dist/engine/codec/hostReadableKeys.js +25 -0
- package/dist/engine/core/arrange.d.ts +20 -0
- package/dist/engine/core/arrange.js +81 -0
- package/dist/engine/core/arrow.d.ts +91 -0
- package/dist/engine/core/arrow.js +182 -0
- package/dist/engine/core/brush.d.ts +68 -0
- package/dist/engine/core/brush.js +173 -0
- package/dist/engine/core/defaults.d.ts +70 -0
- package/dist/engine/core/defaults.js +158 -0
- package/dist/engine/core/freehand.d.ts +130 -0
- package/dist/engine/core/freehand.js +430 -0
- package/dist/engine/core/geometry.d.ts +44 -0
- package/dist/engine/core/geometry.js +216 -0
- package/dist/engine/core/history.d.ts +39 -0
- package/dist/engine/core/history.js +69 -0
- package/dist/engine/core/hitTest.d.ts +54 -0
- package/dist/engine/core/hitTest.js +298 -0
- package/dist/engine/core/matrix.d.ts +47 -0
- package/dist/engine/core/matrix.js +101 -0
- package/dist/engine/core/pathData.d.ts +50 -0
- package/dist/engine/core/pathData.js +550 -0
- package/dist/engine/core/rotationReset.d.ts +10 -0
- package/dist/engine/core/rotationReset.js +17 -0
- package/dist/engine/core/scene.d.ts +99 -0
- package/dist/engine/core/scene.js +450 -0
- package/dist/engine/core/scribble.d.ts +64 -0
- package/dist/engine/core/scribble.js +121 -0
- package/dist/engine/core/shapePaths.d.ts +34 -0
- package/dist/engine/core/shapePaths.js +69 -0
- package/dist/engine/core/shapeTools.d.ts +80 -0
- package/dist/engine/core/shapeTools.js +161 -0
- package/dist/engine/core/snapping.d.ts +64 -0
- package/dist/engine/core/snapping.js +164 -0
- package/dist/engine/core/style.d.ts +40 -0
- package/dist/engine/core/style.js +151 -0
- package/dist/engine/core/transform.d.ts +79 -0
- package/dist/engine/core/transform.js +258 -0
- package/dist/engine/core/types.d.ts +238 -0
- package/dist/engine/core/types.js +31 -0
- package/dist/engine/core/viewport.d.ts +32 -0
- package/dist/engine/core/viewport.js +84 -0
- package/dist/engine/input/PointerController.d.ts +38 -0
- package/dist/engine/input/PointerController.js +545 -0
- package/dist/engine/input/arrowHandles.d.ts +38 -0
- package/dist/engine/input/arrowHandles.js +60 -0
- package/dist/engine/input/gestures.d.ts +79 -0
- package/dist/engine/input/gestures.js +769 -0
- package/dist/engine/input/hoverCursor.d.ts +29 -0
- package/dist/engine/input/hoverCursor.js +23 -0
- package/dist/engine/input/keyboard.d.ts +75 -0
- package/dist/engine/input/keyboard.js +264 -0
- package/dist/engine/input/selectionHandles.d.ts +89 -0
- package/dist/engine/input/selectionHandles.js +169 -0
- package/dist/engine/input/types.d.ts +82 -0
- package/dist/engine/input/types.js +5 -0
- package/dist/engine/render/rasterize.d.ts +74 -0
- package/dist/engine/render/rasterize.js +273 -0
- package/dist/engine/state.d.ts +124 -0
- package/dist/engine/state.js +47 -0
- package/dist/engine/text/layoutText.d.ts +53 -0
- package/dist/engine/text/layoutText.js +170 -0
- package/dist/engine/widgets.d.ts +124 -0
- package/dist/engine/widgets.js +345 -0
- package/dist/i18n/labels.d.ts +4 -15
- package/dist/i18n/labels.js +33 -53
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +51 -122
- package/dist/i18n/messages.js +58 -131
- package/dist/i18n/shortcuts.d.ts +0 -1
- package/dist/i18n/shortcuts.js +2 -11
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/package.json +30 -5
- package/dist/canvas/Canvas.svelte +0 -13299
- package/dist/canvas/Canvas.svelte.d.ts +0 -281
- package/dist/canvas/CanvasToolbar.svelte +0 -1498
- package/dist/canvas/CanvasToolbar.svelte.d.ts +0 -69
- package/dist/canvas/ContextMenu.svelte +0 -305
- package/dist/canvas/ContextMenu.svelte.d.ts +0 -42
- package/dist/canvas/PanZoomPanel.svelte +0 -478
- package/dist/canvas/PanZoomPanel.svelte.d.ts +0 -38
- package/dist/canvas/WidgetSelectionLayer.svelte +0 -156
- package/dist/canvas/WidgetSelectionLayer.svelte.d.ts +0 -11
- package/dist/canvas/props-panel/PropsPanel.svelte +0 -2075
- package/dist/canvas/props-panel/PropsPanel.svelte.d.ts +0 -84
- package/dist/canvas/props-panel/TextPropsICSection.svelte +0 -242
- package/dist/canvas/props-panel/TextPropsICSection.svelte.d.ts +0 -40
- package/dist/canvas/shadowRootText.d.ts +0 -5
- package/dist/canvas/shadowRootText.js +0 -43
- package/dist/canvas/shapes/FrameShape.d.ts +0 -97
- package/dist/canvas/shapes/FrameShape.js +0 -953
- package/dist/canvas/shapes/ImageShape.d.ts +0 -47
- package/dist/canvas/shapes/ImageShape.js +0 -339
- package/dist/canvas/shapes/WidgetShape.d.ts +0 -30
- package/dist/canvas/shapes/WidgetShape.js +0 -200
- package/dist/canvas/widgetPreviewGeometry.d.ts +0 -19
- package/dist/canvas/widgetPreviewGeometry.js +0 -66
- package/dist/i18n/shapeWords.d.ts +0 -30
- package/dist/i18n/shapeWords.js +0 -36
- package/dist/i18n/slots.d.ts +0 -20
- package/dist/i18n/slots.js +0 -40
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ShapeLibrary.ts
|
|
3
3
|
*
|
|
4
4
|
* Pre-defined SVG path data for special shapes (media controls, UI icons, etc.).
|
|
5
|
-
* All paths are normalized to a 100×100 viewBox so
|
|
5
|
+
* All paths are normalized to a 100×100 viewBox so the board scales them uniformly.
|
|
6
6
|
*
|
|
7
7
|
* cornerRadiusMode per shape:
|
|
8
8
|
* 'none' – shape already curved (circle, heart) → hide Corner Radius slider
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ShapeLibrary.ts
|
|
3
3
|
*
|
|
4
4
|
* Pre-defined SVG path data for special shapes (media controls, UI icons, etc.).
|
|
5
|
-
* All paths are normalized to a 100×100 viewBox so
|
|
5
|
+
* All paths are normalized to a 100×100 viewBox so the board scales them uniformly.
|
|
6
6
|
*
|
|
7
7
|
* cornerRadiusMode per shape:
|
|
8
8
|
* 'none' – shape already curved (circle, heart) → hide Corner Radius slider
|
|
@@ -218,6 +218,18 @@ const GEOMETRIC_SHAPES = [
|
|
|
218
218
|
],
|
|
219
219
|
lockAspectRatio: true,
|
|
220
220
|
},
|
|
221
|
+
{
|
|
222
|
+
key: 'pentagon',
|
|
223
|
+
labelKey: 'canvas.shape.pentagon',
|
|
224
|
+
category: 'Geometric Shapes',
|
|
225
|
+
pathData: 'M 50 4 L 95.6 37.2 L 78.2 90.8 L 21.8 90.8 L 4.4 37.2 Z',
|
|
226
|
+
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><polygon points="12,2.5 21.5,9.4 17.9,20.6 6.1,20.6 2.5,9.4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
227
|
+
cornerRadiusMode: 'pathRegen',
|
|
228
|
+
regenData: [
|
|
229
|
+
{ type: 'polygon', points: [[50, 4], [95.6, 37.2], [78.2, 90.8], [21.8, 90.8], [4.4, 37.2]] },
|
|
230
|
+
],
|
|
231
|
+
lockAspectRatio: true,
|
|
232
|
+
},
|
|
221
233
|
{
|
|
222
234
|
key: 'oval',
|
|
223
235
|
labelKey: 'canvas.shape.oval',
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @file strokeShapeSnap.ts
|
|
3
3
|
* @description Turn a hand-drawn freehand stroke into the shape it was meant to be.
|
|
4
4
|
*
|
|
5
|
-
* The Draw tool
|
|
5
|
+
* The Draw tool records the pointer's samples, so a "shape" the user tries to draw
|
|
6
6
|
* arrives as a wobbly polyline — dozens of sampled points, corners that overshoot,
|
|
7
7
|
* edges that bow. This module measures that polyline and decides whether it is a
|
|
8
8
|
* clean enough instance of a shape the canvas can actually build.
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
* gate it is good at — and which can only ever replace a wrong *snap* with
|
|
24
24
|
* the stroke left as drawn.
|
|
25
25
|
*
|
|
26
|
-
* Everything here is pure: it takes command data and points, never
|
|
27
|
-
*
|
|
26
|
+
* Everything here is pure: it takes command data and points, never an object of
|
|
27
|
+
* the board, so it can be tested with `npm test` and reused by any caller that can
|
|
28
28
|
* produce a polyline.
|
|
29
29
|
*/
|
|
30
30
|
/**
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
* `true` means a recognized stroke is replaced by the clean shape, `false` means
|
|
33
33
|
* every stroke stays exactly as it was drawn. One line to roll back.
|
|
34
34
|
*/
|
|
35
|
-
export declare const CANVAS_SHAPE_SNAP_ENABLED =
|
|
35
|
+
export declare const CANVAS_SHAPE_SNAP_ENABLED = false;
|
|
36
36
|
/**
|
|
37
37
|
* The shapes snapping can produce — the shapes the canvas can *build from
|
|
38
38
|
* scratch*, which is what makes the replacement faithful to what the user would
|
|
39
39
|
* have got from the toolbar:
|
|
40
40
|
*
|
|
41
|
-
* - `rect` →
|
|
42
|
-
* - `circle` →
|
|
43
|
-
* - `oval` →
|
|
41
|
+
* - `rect` → a `rect` object (a square is a `rect` whose bounds are square)
|
|
42
|
+
* - `circle` → the toolbar's Circle (a round `ellipse` object, not the Ellipse tool)
|
|
43
|
+
* - `oval` → an `ellipse` object (the toolbar's oval/ellipse tool)
|
|
44
44
|
* - `triangle` → the same regenerated path the Triangle tool produces
|
|
45
45
|
* - `diamond` → the `diamond` library shape
|
|
46
46
|
* - `hexagon` → the `hexagon` library shape
|
|
@@ -58,7 +58,7 @@ export interface StrokePoint {
|
|
|
58
58
|
x: number;
|
|
59
59
|
y: number;
|
|
60
60
|
}
|
|
61
|
-
/** One
|
|
61
|
+
/** One SVG path command: `['M', x, y]`, `['Q', cx, cy, x, y]`, … */
|
|
62
62
|
export type PathCommand = [string, ...number[]];
|
|
63
63
|
/**
|
|
64
64
|
* A stroke's measurements — the vocabulary the shape profiles are written in and
|
|
@@ -107,11 +107,13 @@ export declare const STROKE_SNAP_MIN_MARGIN = 0.12;
|
|
|
107
107
|
/**
|
|
108
108
|
* Flatten path commands into a polyline.
|
|
109
109
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
110
|
+
* A path may be `M` followed by a run of quadratic curves whose control point is
|
|
111
|
+
* a sampled pointer and whose endpoint is the midpoint of the next segment, so
|
|
112
|
+
* the curves must be sampled rather than read as endpoints.
|
|
113
113
|
* `L`, `H`, `V` and `Z` are handled too, which makes this usable on any path the
|
|
114
|
-
* canvas holds — including the clean shapes themselves.
|
|
114
|
+
* canvas holds — including the clean shapes themselves. (A stroke of the Draw
|
|
115
|
+
* tool is measured through the line it holds, not through its outline: see
|
|
116
|
+
* `strokeMeasurementPoints` in `host/strokeSnap.ts`.)
|
|
115
117
|
*/
|
|
116
118
|
export declare function flattenPathCommands(commands: readonly PathCommand[], samplesPerCurve?: number): StrokePoint[];
|
|
117
119
|
/** Uniform arc-length resample, so fast and slow strokes are measured the same. */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @file strokeShapeSnap.ts
|
|
3
3
|
* @description Turn a hand-drawn freehand stroke into the shape it was meant to be.
|
|
4
4
|
*
|
|
5
|
-
* The Draw tool
|
|
5
|
+
* The Draw tool records the pointer's samples, so a "shape" the user tries to draw
|
|
6
6
|
* arrives as a wobbly polyline — dozens of sampled points, corners that overshoot,
|
|
7
7
|
* edges that bow. This module measures that polyline and decides whether it is a
|
|
8
8
|
* clean enough instance of a shape the canvas can actually build.
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
* gate it is good at — and which can only ever replace a wrong *snap* with
|
|
24
24
|
* the stroke left as drawn.
|
|
25
25
|
*
|
|
26
|
-
* Everything here is pure: it takes command data and points, never
|
|
27
|
-
*
|
|
26
|
+
* Everything here is pure: it takes command data and points, never an object of
|
|
27
|
+
* the board, so it can be tested with `npm test` and reused by any caller that can
|
|
28
28
|
* produce a polyline.
|
|
29
29
|
*/
|
|
30
30
|
/**
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* `true` means a recognized stroke is replaced by the clean shape, `false` means
|
|
33
33
|
* every stroke stays exactly as it was drawn. One line to roll back.
|
|
34
34
|
*/
|
|
35
|
-
export const CANVAS_SHAPE_SNAP_ENABLED =
|
|
35
|
+
export const CANVAS_SHAPE_SNAP_ENABLED = false;
|
|
36
36
|
export const CANVAS_SNAP_SHAPES = [
|
|
37
37
|
'rect',
|
|
38
38
|
'circle',
|
|
@@ -83,11 +83,13 @@ const RESAMPLE_COUNT = 96;
|
|
|
83
83
|
/**
|
|
84
84
|
* Flatten path commands into a polyline.
|
|
85
85
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* A path may be `M` followed by a run of quadratic curves whose control point is
|
|
87
|
+
* a sampled pointer and whose endpoint is the midpoint of the next segment, so
|
|
88
|
+
* the curves must be sampled rather than read as endpoints.
|
|
89
89
|
* `L`, `H`, `V` and `Z` are handled too, which makes this usable on any path the
|
|
90
|
-
* canvas holds — including the clean shapes themselves.
|
|
90
|
+
* canvas holds — including the clean shapes themselves. (A stroke of the Draw
|
|
91
|
+
* tool is measured through the line it holds, not through its outline: see
|
|
92
|
+
* `strokeMeasurementPoints` in `host/strokeSnap.ts`.)
|
|
91
93
|
*/
|
|
92
94
|
export function flattenPathCommands(commands, samplesPerCurve = 10) {
|
|
93
95
|
const points = [];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the drawing toolbar stands on the board.
|
|
3
|
+
*
|
|
4
|
+
* The toolbar has always been at the bottom centre. A host that has something of its own there (Shopify's Sidekick sits in
|
|
5
|
+
* the same spot, a partner may have a cookie bar or a chat bubble) names another anchor with the `toolbarPosition` option:
|
|
6
|
+
* any of the eight places `chromeLayout.ts` describes (the top edge, the bottom edge, or the middle of the left or right
|
|
7
|
+
* edge, where the toolbar stands upright). The selector bar that replaces the toolbar after the first generation stands in
|
|
8
|
+
* the same place, so the two never jump around when one takes over from the other.
|
|
9
|
+
*
|
|
10
|
+
* Kept free of Svelte and of the DOM so that Node can test it.
|
|
11
|
+
*/
|
|
12
|
+
import type { ChromeAnchor } from './chromeLayout.js';
|
|
13
|
+
/** The places the toolbar can stand: `TL TC TR` (top), `CL CR` (the sides) and `BL BC BR` (bottom). */
|
|
14
|
+
export declare const TOOLBAR_POSITIONS: readonly ["TL", "TC", "TR", "CL", "CR", "BL", "BC", "BR"];
|
|
15
|
+
/** One of {@link TOOLBAR_POSITIONS}. */
|
|
16
|
+
export type ToolbarPosition = ChromeAnchor;
|
|
17
|
+
/** Where the toolbar stands when the host says nothing: the bottom centre, as it always did. */
|
|
18
|
+
export declare const DEFAULT_TOOLBAR_POSITION: ToolbarPosition;
|
|
19
|
+
/**
|
|
20
|
+
* 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
|
|
21
|
+
* lower case, nothing at all) is the default, so that a mistake in the host's option never takes the toolbar off the
|
|
22
|
+
* board.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeToolbarPosition(value: unknown): ToolbarPosition;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the drawing toolbar stands on the board.
|
|
3
|
+
*
|
|
4
|
+
* The toolbar has always been at the bottom centre. A host that has something of its own there (Shopify's Sidekick sits in
|
|
5
|
+
* the same spot, a partner may have a cookie bar or a chat bubble) names another anchor with the `toolbarPosition` option:
|
|
6
|
+
* any of the eight places `chromeLayout.ts` describes (the top edge, the bottom edge, or the middle of the left or right
|
|
7
|
+
* edge, where the toolbar stands upright). The selector bar that replaces the toolbar after the first generation stands in
|
|
8
|
+
* the same place, so the two never jump around when one takes over from the other.
|
|
9
|
+
*
|
|
10
|
+
* Kept free of Svelte and of the DOM so that Node can test it.
|
|
11
|
+
*/
|
|
12
|
+
import { CHROME_ANCHORS, normalizeAnchor } from './chromeLayout.js';
|
|
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;
|
|
15
|
+
/** Where the toolbar stands when the host says nothing: the bottom centre, as it always did. */
|
|
16
|
+
export const DEFAULT_TOOLBAR_POSITION = 'BC';
|
|
17
|
+
/**
|
|
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
|
+
* lower case, nothing at all) is the default, so that a mistake in the host's option never takes the toolbar off the
|
|
20
|
+
* board.
|
|
21
|
+
*/
|
|
22
|
+
export function normalizeToolbarPosition(value) {
|
|
23
|
+
return normalizeAnchor(value, DEFAULT_TOOLBAR_POSITION);
|
|
24
|
+
}
|
package/dist/canvas/types.d.ts
CHANGED
|
@@ -25,6 +25,20 @@ export interface WidgetConversionPayload {
|
|
|
25
25
|
hasText: boolean;
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
/** What `onObjectClick` receives when a selection is captured: a screenshot of it and what it is. */
|
|
29
|
+
export interface ObjectClickPayload {
|
|
30
|
+
screenshot: string;
|
|
31
|
+
objectType: string;
|
|
32
|
+
customType?: string;
|
|
33
|
+
bounds: {
|
|
34
|
+
left: number;
|
|
35
|
+
top: number;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
};
|
|
39
|
+
objectId: string;
|
|
40
|
+
metadata: Record<string, any>;
|
|
41
|
+
}
|
|
28
42
|
/**
|
|
29
43
|
* A hand-drawn stroke the canvas could not classify on its own, handed to the
|
|
30
44
|
* host to classify with a model.
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Figma "Canvas Menu" and its "Layer order" submenu: the menu a right click (or a long press) opens on the board.
|
|
3
|
+
|
|
4
|
+
Cut, Copy, Paste and Duplicate; Group and Ungroup; Layer order (a submenu of four) and Select all; Delete in the colour of a
|
|
5
|
+
destructive action. Each row names the key that does the same, written for this platform (the symbols of a Mac, "Ctrl+" on
|
|
6
|
+
the others). A row that cannot act on what is selected is dimmed.
|
|
7
|
+
|
|
8
|
+
The menu is the design system's Dropdown Menu, anchored to the point of the board that was pressed, and drawn into the
|
|
9
|
+
canvas's floating layer. The host decides when it opens (`ui.contextMenu`): a press on an object selects it first.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { DropdownMenu } from '@widgetic/design-system/components';
|
|
13
|
+
import type { ReorderMode } from '../../engine/core/scene.js';
|
|
14
|
+
import type { EngineState } from '../../engine/state.js';
|
|
15
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
16
|
+
import type { CanvasMessageKey } from '../../i18n/messages.js';
|
|
17
|
+
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
18
|
+
import { ariaKeyShortcut, chordText, isApplePlatform } from './keyHints.js';
|
|
19
|
+
import type { Chord } from './keyHints.js';
|
|
20
|
+
import type { CanvasIcon } from './icons.js';
|
|
21
|
+
import { CANVAS_OVERLAY_Z_CLASS, MENU_PADDING_CLASS, OVERLAY_REDUCED_MOTION_CLASSES } from './floatingCard.js';
|
|
22
|
+
import { canvasOverlayPortalProps, useFloatingLayer } from './floatingLayer.js';
|
|
23
|
+
import { IconArrowBarToDown, IconArrowBarToUp, IconClipboard, IconCopy, IconReplace, IconScissors, IconSelectAll, IconStack, IconStack2, IconStackBack, IconStackFront, IconStackPop, IconTrash } from './icons.js';
|
|
24
|
+
|
|
25
|
+
interface Props {
|
|
26
|
+
host: CanvasHost;
|
|
27
|
+
state: EngineState;
|
|
28
|
+
ui: HostUiState;
|
|
29
|
+
/** The board's own element, to turn the pressed point into a point of the page. */
|
|
30
|
+
board: HTMLElement | null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let { host, state, ui, board }: Props = $props();
|
|
34
|
+
|
|
35
|
+
// The menu is drawn into the canvas's floating layer (see floatingLayer.ts).
|
|
36
|
+
const floatingLayer = useFloatingLayer();
|
|
37
|
+
|
|
38
|
+
const { t } = useCanvasLanguage();
|
|
39
|
+
const apple = isApplePlatform();
|
|
40
|
+
|
|
41
|
+
/** A row of the menu: what it is called, its icon, the keys, whether it can act, and what it does. */
|
|
42
|
+
interface Row {
|
|
43
|
+
label: CanvasMessageKey;
|
|
44
|
+
icon: CanvasIcon;
|
|
45
|
+
chord?: Chord;
|
|
46
|
+
disabled: boolean;
|
|
47
|
+
run: () => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const selectionCount = $derived(state.selectedIds.length);
|
|
51
|
+
const hasSelection = $derived(selectionCount > 0);
|
|
52
|
+
// The selection holds units (a group is one), and a group needs two of them.
|
|
53
|
+
const canGroup = $derived(selectionCount > 1);
|
|
54
|
+
const canUngroup = $derived.by(() => {
|
|
55
|
+
const selected = new Set(state.selectedIds);
|
|
56
|
+
return state.scene.some((object) => object.type === 'group' && selected.has(object.id));
|
|
57
|
+
});
|
|
58
|
+
const boardIsEmpty = $derived(state.scene.length === 0);
|
|
59
|
+
|
|
60
|
+
const point = $derived(ui.contextMenu);
|
|
61
|
+
|
|
62
|
+
const clipboardRows = $derived<Row[]>([
|
|
63
|
+
{ label: 'canvas.action.cut', icon: IconScissors, chord: { mod: true, key: 'X' }, disabled: !hasSelection, run: () => void host.cutSelection() },
|
|
64
|
+
{ label: 'canvas.action.copy', icon: IconCopy, chord: { mod: true, key: 'C' }, disabled: !hasSelection, run: () => void host.copySelection() },
|
|
65
|
+
{ label: 'canvas.action.paste', icon: IconClipboard, chord: { mod: true, key: 'V' }, disabled: false, run: () => void host.pasteAt(point) },
|
|
66
|
+
{ label: 'canvas.action.duplicate', icon: IconReplace, chord: { mod: true, key: 'D' }, disabled: !hasSelection, run: () => void host.duplicateSelectedObjects() }
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
const groupRows = $derived<Row[]>([
|
|
70
|
+
{ label: 'canvas.action.group', icon: IconStack2, chord: { mod: true, key: 'G' }, disabled: !canGroup, run: () => void host.onGroupSelection() },
|
|
71
|
+
{ label: 'canvas.action.ungroup', icon: IconStackPop, chord: { mod: true, shift: true, key: 'G' }, disabled: !canUngroup, run: () => host.onUngroupSelection() }
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
const layerRows = $derived<(Row & { mode: ReorderMode })[]>([
|
|
75
|
+
{ mode: 'front', label: 'canvas.layer.front', icon: IconArrowBarToUp, chord: { mod: true, shift: true, key: ']' }, disabled: !hasSelection, run: () => void host.engine.reorderSelection('front') },
|
|
76
|
+
{ mode: 'forward', label: 'canvas.layer.forward', icon: IconStackFront, chord: { mod: true, key: ']' }, disabled: !hasSelection, run: () => void host.engine.reorderSelection('forward') },
|
|
77
|
+
{ mode: 'backward', label: 'canvas.layer.backward', icon: IconStackBack, chord: { mod: true, key: '[' }, disabled: !hasSelection, run: () => void host.engine.reorderSelection('backward') },
|
|
78
|
+
{ mode: 'back', label: 'canvas.layer.back', icon: IconArrowBarToDown, chord: { mod: true, shift: true, key: '[' }, disabled: !hasSelection, run: () => void host.engine.reorderSelection('back') }
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
/** Where the menu opens on the page: the pressed point of the board, which is only known once the board is. */
|
|
82
|
+
const anchor = $derived.by(() => {
|
|
83
|
+
if (!point || !board) return null;
|
|
84
|
+
const rect = board.getBoundingClientRect();
|
|
85
|
+
return { getBoundingClientRect: () => new DOMRect(rect.left + point.x, rect.top + point.y, 0, 0) };
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
function setOpen(next: boolean): void {
|
|
89
|
+
if (!next) host.updateUi({ contextMenu: null });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* How far below the pressed point a menu opens when a finger opened it: clear of the fingertip, so the entry that is
|
|
94
|
+
* under the finger when it lifts is not the first one of the menu.
|
|
95
|
+
*/
|
|
96
|
+
const TOUCH_MENU_OFFSET = 24;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A choice. The finger that opened the menu with a long press is still on the screen or has just lifted: the `click`
|
|
100
|
+
* the browser sends it is that release, not a choice, and the entry under it is left alone (the menu stays open).
|
|
101
|
+
*/
|
|
102
|
+
function choose(event: Event, run: () => void): void {
|
|
103
|
+
if (host.isMenuHeldByItsFinger()) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
run();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The menu closes the way a menu does; the focus goes back to the board, where the keys are read. */
|
|
111
|
+
function returnFocusToBoard(event: Event): void {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
host.focusBoard();
|
|
114
|
+
}
|
|
115
|
+
</script>
|
|
116
|
+
|
|
117
|
+
<!-- The keys are written beside the name for the eye (hidden from the name a screen reader reads) and given as `aria-keyshortcuts`. -->
|
|
118
|
+
{#snippet rowView(row: Row)}
|
|
119
|
+
<DropdownMenu.Item disabled={row.disabled} aria-keyshortcuts={row.chord ? ariaKeyShortcut(row.chord, apple) : undefined} onSelect={(event) => choose(event, row.run)}>
|
|
120
|
+
<row.icon />
|
|
121
|
+
<span class="flex-1">{$t(row.label)}</span>
|
|
122
|
+
{#if row.chord}
|
|
123
|
+
<DropdownMenu.Shortcut aria-hidden="true">{chordText(row.chord, apple, $t)}</DropdownMenu.Shortcut>
|
|
124
|
+
{/if}
|
|
125
|
+
</DropdownMenu.Item>
|
|
126
|
+
{/snippet}
|
|
127
|
+
|
|
128
|
+
<DropdownMenu.Root open={point !== null} onOpenChange={setOpen}>
|
|
129
|
+
{#if anchor}
|
|
130
|
+
<DropdownMenu.Content
|
|
131
|
+
customAnchor={anchor}
|
|
132
|
+
side="bottom"
|
|
133
|
+
align="start"
|
|
134
|
+
sideOffset={point?.byTouch ? TOUCH_MENU_OFFSET : 0}
|
|
135
|
+
portalProps={canvasOverlayPortalProps($floatingLayer)}
|
|
136
|
+
onCloseAutoFocus={returnFocusToBoard}
|
|
137
|
+
aria-label={$t('canvas.panel.actions')}
|
|
138
|
+
data-canvas-context-menu
|
|
139
|
+
class="{CANVAS_OVERLAY_Z_CLASS} w-[240px] {MENU_PADDING_CLASS} shadow-floating focus-visible:outline-hidden {OVERLAY_REDUCED_MOTION_CLASSES}"
|
|
140
|
+
>
|
|
141
|
+
{#each clipboardRows as row (row.label)}
|
|
142
|
+
{@render rowView(row)}
|
|
143
|
+
{/each}
|
|
144
|
+
<DropdownMenu.Separator />
|
|
145
|
+
{#each groupRows as row (row.label)}
|
|
146
|
+
{@render rowView(row)}
|
|
147
|
+
{/each}
|
|
148
|
+
<DropdownMenu.Separator />
|
|
149
|
+
<DropdownMenu.Sub>
|
|
150
|
+
<DropdownMenu.SubTrigger disabled={!hasSelection}>
|
|
151
|
+
<IconStack />
|
|
152
|
+
<span class="flex-1">{$t('canvas.layer.title')}</span>
|
|
153
|
+
</DropdownMenu.SubTrigger>
|
|
154
|
+
<DropdownMenu.SubContent aria-label={$t('canvas.layer.title')} class="{CANVAS_OVERLAY_Z_CLASS} w-[220px] {MENU_PADDING_CLASS} shadow-floating {OVERLAY_REDUCED_MOTION_CLASSES}">
|
|
155
|
+
{#each layerRows as row (row.mode)}
|
|
156
|
+
{@render rowView(row)}
|
|
157
|
+
{/each}
|
|
158
|
+
</DropdownMenu.SubContent>
|
|
159
|
+
</DropdownMenu.Sub>
|
|
160
|
+
<DropdownMenu.Item disabled={boardIsEmpty} aria-keyshortcuts={ariaKeyShortcut({ mod: true, key: 'A' }, apple)} onSelect={(event) => choose(event, () => host.onSelectAllObjects())}>
|
|
161
|
+
<IconSelectAll />
|
|
162
|
+
<span class="flex-1">{$t('canvas.action.selectAll')}</span>
|
|
163
|
+
<DropdownMenu.Shortcut aria-hidden="true">{chordText({ mod: true, key: 'A' }, apple, $t)}</DropdownMenu.Shortcut>
|
|
164
|
+
</DropdownMenu.Item>
|
|
165
|
+
<DropdownMenu.Separator />
|
|
166
|
+
<DropdownMenu.Item data-variant="destructive" disabled={!hasSelection} aria-keyshortcuts="Delete" onSelect={(event) => choose(event, () => void host.deleteSelectedObjects())}>
|
|
167
|
+
<IconTrash />
|
|
168
|
+
<span class="flex-1">{$t('canvas.action.delete')}</span>
|
|
169
|
+
<DropdownMenu.Shortcut aria-hidden="true">{$t('canvas.key.delete')}</DropdownMenu.Shortcut>
|
|
170
|
+
</DropdownMenu.Item>
|
|
171
|
+
</DropdownMenu.Content>
|
|
172
|
+
{/if}
|
|
173
|
+
</DropdownMenu.Root>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EngineState } from '../../engine/state.js';
|
|
2
|
+
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
host: CanvasHost;
|
|
5
|
+
state: EngineState;
|
|
6
|
+
ui: HostUiState;
|
|
7
|
+
/** The board's own element, to turn the pressed point into a point of the page. */
|
|
8
|
+
board: HTMLElement | null;
|
|
9
|
+
}
|
|
10
|
+
declare const CanvasContextMenu: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type CanvasContextMenu = ReturnType<typeof CanvasContextMenu>;
|
|
12
|
+
export default CanvasContextMenu;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Figma "Canvas Hint": what an empty board says. A 40 px tile with a pencil, a title and one line under it, centred on the
|
|
3
|
+
board and never in the way of the pointer. It is shown while the board holds nothing, and goes the moment something is
|
|
4
|
+
drawn.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
8
|
+
import { IconPencil } from './icons.js';
|
|
9
|
+
|
|
10
|
+
const { t } = useCanvasLanguage();
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<div class="pointer-events-none absolute inset-0 flex items-center justify-center p-6" data-canvas-hint>
|
|
14
|
+
<div class="flex w-80 max-w-full flex-col items-center gap-3 text-center">
|
|
15
|
+
<div class="flex size-10 items-center justify-center rounded-xl border border-border bg-background text-foreground">
|
|
16
|
+
<IconPencil class="size-5 stroke-[1.333]" aria-hidden="true" />
|
|
17
|
+
</div>
|
|
18
|
+
<p class="text-body-medium text-foreground">{$t('canvas.hint.title')}</p>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const CanvasHint: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
}, {}, {}, string>;
|
|
17
|
+
type CanvasHint = InstanceType<typeof CanvasHint>;
|
|
18
|
+
export default CanvasHint;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Figma "Toolbar": the card that holds the tools, 16 px from the edge of the board it stands against, 44 px high (349 px wide
|
|
3
|
+
with everything in it, 264 px on a board too narrow for that, where the history group has left).
|
|
4
|
+
|
|
5
|
+
Left to right: the drawing group (select, draw, erase, arrow, text), a divider, the Shapes menu, a divider and the history
|
|
6
|
+
group (undo, redo). Every button is the design system's Icon Button with a tooltip, 36 px square, and the tool in use has
|
|
7
|
+
the brand tint. The page's `showDrawingTools` hides the drawing group (and with it the letters that choose those tools).
|
|
8
|
+
The Shapes menu and the history group are always on the bar: a page that wants a leaner canvas hides the bar itself. On a
|
|
9
|
+
board narrower than the whole bar and its edges (381 px, so Figma's 358 px phone) the history group leaves the bar.
|
|
10
|
+
|
|
11
|
+
The bar stands where the page's `toolbarPosition` says. On the left or the right edge it stands upright: the same groups
|
|
12
|
+
one under the other, 44 px wide, with horizontal dividers, and its tooltips and the Shapes menu open sideways into the
|
|
13
|
+
board. Everywhere else it is the row above, and they open away from the edge it is against.
|
|
14
|
+
|
|
15
|
+
The bar is a sibling of the board, never inside it, so a press on a button never reaches the board's pointer handlers.
|
|
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 { TOOL_KEYS } from '../../i18n/shortcuts.js';
|
|
22
|
+
import { isSideAnchor, popoverSideFor } from '../chromeLayout.js';
|
|
23
|
+
import type { ChromeAnchor } from '../chromeLayout.js';
|
|
24
|
+
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
25
|
+
import { FLOATING_CARD_CLASSES, TOOLBAR_HISTORY_VISIBLE_FROM } from './floatingCard.js';
|
|
26
|
+
import { providePopoverSide } from './popoverSide.js';
|
|
27
|
+
import ShapesMenu from './ShapesMenu.svelte';
|
|
28
|
+
import ToolButton from './ToolButton.svelte';
|
|
29
|
+
import { IconArrowBackUp, IconArrowForwardUp, IconArrowUpRight, IconEraser, IconPencil, IconPointer, IconTypography } from './icons.js';
|
|
30
|
+
|
|
31
|
+
interface Props {
|
|
32
|
+
host: CanvasHost;
|
|
33
|
+
state: EngineState;
|
|
34
|
+
ui: HostUiState;
|
|
35
|
+
showDrawingTools: boolean;
|
|
36
|
+
/** Where the bar stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
|
|
37
|
+
anchor: ChromeAnchor;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let { host, state, ui, showDrawingTools, anchor }: Props = $props();
|
|
41
|
+
|
|
42
|
+
const { t } = useCanvasLanguage();
|
|
43
|
+
|
|
44
|
+
const vertical = $derived(isSideAnchor(anchor));
|
|
45
|
+
// The tooltips and the Shapes menu open away from the edge the bar stands against.
|
|
46
|
+
providePopoverSide(() => popoverSideFor(anchor));
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<!-- `canvas-toolbar-el` is the name pages' own tests have always found the toolbar by (the end-to-end tests of the UI modules). -->
|
|
50
|
+
<div
|
|
51
|
+
role="group"
|
|
52
|
+
aria-label={$t('canvas.toolbar.label')}
|
|
53
|
+
data-canvas-toolbar
|
|
54
|
+
data-anchor={anchor}
|
|
55
|
+
class="canvas-toolbar-el pointer-events-auto flex items-center gap-1 {vertical ? 'max-h-full flex-col overflow-y-auto' : 'max-w-full'} {FLOATING_CARD_CLASSES}"
|
|
56
|
+
>
|
|
57
|
+
{#if showDrawingTools}
|
|
58
|
+
<ToolButton toggle label={$t('canvas.tool.select')} shortcut={TOOL_KEYS.select} active={state.tool === 'select'} onclick={() => host.onSelectSelectTool()}>
|
|
59
|
+
<IconPointer />
|
|
60
|
+
</ToolButton>
|
|
61
|
+
<ToolButton toggle label={$t('canvas.tool.draw')} shortcut={TOOL_KEYS.draw} active={state.tool === 'draw'} onclick={() => host.onSelectDrawTool()}>
|
|
62
|
+
<IconPencil />
|
|
63
|
+
</ToolButton>
|
|
64
|
+
<ToolButton toggle label={$t('canvas.tool.erase')} shortcut={TOOL_KEYS.erase} active={state.tool === 'erase'} onclick={() => host.onSelectEraseTool()}>
|
|
65
|
+
<IconEraser />
|
|
66
|
+
</ToolButton>
|
|
67
|
+
<ToolButton toggle label={$t('canvas.tool.arrow')} shortcut={TOOL_KEYS.arrow} active={state.tool === 'arrow'} onclick={() => host.onSelectArrowTool()}>
|
|
68
|
+
<IconArrowUpRight />
|
|
69
|
+
</ToolButton>
|
|
70
|
+
<ToolButton toggle label={$t('canvas.tool.text')} shortcut={TOOL_KEYS.text} active={state.tool === 'text'} onclick={() => host.onSelectTextTool()}>
|
|
71
|
+
<IconTypography />
|
|
72
|
+
</ToolButton>
|
|
73
|
+
|
|
74
|
+
<Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
|
|
75
|
+
{/if}
|
|
76
|
+
|
|
77
|
+
<ShapesMenu
|
|
78
|
+
{host}
|
|
79
|
+
tool={state.tool}
|
|
80
|
+
libraryShapeKey={state.libraryShapeKey}
|
|
81
|
+
open={ui.shapesMenuOpen}
|
|
82
|
+
imageShortcut={TOOL_KEYS.image}
|
|
83
|
+
/>
|
|
84
|
+
|
|
85
|
+
<!-- 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. -->
|
|
86
|
+
<div class="items-center gap-1 {vertical ? 'flex flex-col' : TOOLBAR_HISTORY_VISIBLE_FROM}">
|
|
87
|
+
<Separator orientation={vertical ? 'horizontal' : 'vertical'} class={vertical ? 'w-5' : 'h-5 min-h-0'} />
|
|
88
|
+
<ToolButton label={$t('canvas.tool.undo')} disabled={!state.canUndo} onclick={() => void host.undo()}>
|
|
89
|
+
<IconArrowBackUp class="rtl:-scale-x-100" />
|
|
90
|
+
</ToolButton>
|
|
91
|
+
<ToolButton label={$t('canvas.tool.redo')} disabled={!state.canRedo} onclick={() => void host.redo()}>
|
|
92
|
+
<IconArrowForwardUp class="rtl:-scale-x-100" />
|
|
93
|
+
</ToolButton>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
showDrawingTools: boolean;
|
|
9
|
+
/** Where the bar stands (see `chromeLayout.ts`): it stands upright on the left and the right edge. */
|
|
10
|
+
anchor: ChromeAnchor;
|
|
11
|
+
}
|
|
12
|
+
declare const CanvasToolbar: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type CanvasToolbar = ReturnType<typeof CanvasToolbar>;
|
|
14
|
+
export default CanvasToolbar;
|