@zsherman/canvas 0.0.0-stage → 0.1.0
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/CHANGELOG.md +7 -0
- package/LICENSE +373 -0
- package/README.md +15 -2
- package/THIRD_PARTY_NOTICES.md +117 -0
- package/dist/dom/canvas/assets.js +89 -0
- package/dist/dom/canvas/board-store.js +56 -0
- package/dist/dom/canvas/canvas-actions.js +78 -0
- package/dist/dom/canvas/canvas-board.js +557 -0
- package/dist/dom/canvas/canvas-board.styles.js +110 -0
- package/dist/dom/canvas/canvas-chrome.js +1167 -0
- package/dist/dom/canvas/canvas-chrome.styles.js +220 -0
- package/dist/dom/canvas/canvas-comments.js +950 -0
- package/dist/dom/canvas/canvas-comments.styles.js +231 -0
- package/dist/dom/canvas/canvas-context.js +196 -0
- package/dist/dom/canvas/canvas-controller.js +697 -0
- package/dist/dom/canvas/canvas-cursor-chat.js +120 -0
- package/dist/dom/canvas/canvas-cursor-chat.styles.js +55 -0
- package/dist/dom/canvas/canvas-menus.js +276 -0
- package/dist/dom/canvas/canvas-menus.styles.js +7 -0
- package/dist/dom/canvas/canvas-style-bar.js +930 -0
- package/dist/dom/canvas/canvas-style-bar.styles.js +52 -0
- package/dist/dom/canvas/canvas-surface.js +1353 -0
- package/dist/dom/canvas/canvas-surface.styles.js +345 -0
- package/dist/dom/canvas/canvas-tool-rail.js +406 -0
- package/dist/dom/canvas/canvas-tool-rail.styles.js +20 -0
- package/dist/dom/canvas/comments.js +58 -0
- package/dist/dom/canvas/equality.js +13 -0
- package/dist/dom/canvas/export-png.js +496 -0
- package/dist/dom/canvas/gesture-machine.js +91 -0
- package/dist/dom/canvas/handlers.js +18 -0
- package/dist/dom/canvas/index.js +9 -0
- package/dist/dom/canvas/input.js +85 -0
- package/dist/dom/canvas/instant.js +28 -0
- package/dist/dom/canvas/kernel.js +39 -0
- package/dist/dom/canvas/motion.js +686 -0
- package/dist/dom/canvas/palette.js +165 -0
- package/dist/dom/canvas/random-id.js +15 -0
- package/dist/dom/canvas/scene-renderer.js +559 -0
- package/dist/dom/canvas/scene.styles.js +7 -0
- package/dist/dom/canvas/surface-model.js +324 -0
- package/dist/dom/canvas/uploads.js +294 -0
- package/dist/dom/index.js +9 -0
- package/dist/dom/kernel/actions.js +455 -0
- package/dist/dom/kernel/board.js +856 -0
- package/dist/dom/kernel/claims.js +40 -0
- package/dist/dom/kernel/clipboard.js +30 -0
- package/dist/dom/kernel/constants.js +210 -0
- package/dist/dom/kernel/contract.js +0 -0
- package/dist/dom/kernel/decode.js +85 -0
- package/dist/dom/kernel/editor.js +2077 -0
- package/dist/dom/kernel/errors.js +82 -0
- package/dist/dom/kernel/fonts/inter.js +7924 -0
- package/dist/dom/kernel/fractional-index.js +54 -0
- package/dist/dom/kernel/geometry.js +123 -0
- package/dist/dom/kernel/hit-test.js +156 -0
- package/dist/dom/kernel/index.js +22 -0
- package/dist/dom/kernel/inspect.js +116 -0
- package/dist/dom/kernel/kernel.js +251 -0
- package/dist/dom/kernel/outline.js +64 -0
- package/dist/dom/kernel/plan.js +1370 -0
- package/dist/dom/kernel/rev.js +173 -0
- package/dist/dom/kernel/scene.js +580 -0
- package/dist/dom/kernel/schema.js +1109 -0
- package/dist/dom/kernel/snap.js +258 -0
- package/dist/dom/kernel/svg.js +148 -0
- package/dist/dom/kernel/text.js +142 -0
- package/dist/solid/canvas/assets.jsx +89 -0
- package/dist/solid/canvas/board-store.jsx +56 -0
- package/dist/solid/canvas/canvas-actions.jsx +78 -0
- package/dist/solid/canvas/canvas-board.jsx +326 -0
- package/dist/solid/canvas/canvas-board.styles.jsx +110 -0
- package/dist/solid/canvas/canvas-chrome.jsx +612 -0
- package/dist/solid/canvas/canvas-chrome.styles.jsx +220 -0
- package/dist/solid/canvas/canvas-comments.jsx +435 -0
- package/dist/solid/canvas/canvas-comments.styles.jsx +231 -0
- package/dist/solid/canvas/canvas-context.jsx +174 -0
- package/dist/solid/canvas/canvas-controller.jsx +697 -0
- package/dist/solid/canvas/canvas-cursor-chat.jsx +87 -0
- package/dist/solid/canvas/canvas-cursor-chat.styles.jsx +55 -0
- package/dist/solid/canvas/canvas-menus.jsx +223 -0
- package/dist/solid/canvas/canvas-menus.styles.jsx +7 -0
- package/dist/solid/canvas/canvas-style-bar.jsx +486 -0
- package/dist/solid/canvas/canvas-style-bar.styles.jsx +52 -0
- package/dist/solid/canvas/canvas-surface.jsx +681 -0
- package/dist/solid/canvas/canvas-surface.styles.jsx +345 -0
- package/dist/solid/canvas/canvas-tool-rail.jsx +195 -0
- package/dist/solid/canvas/canvas-tool-rail.styles.jsx +20 -0
- package/dist/solid/canvas/comments.jsx +58 -0
- package/dist/solid/canvas/equality.jsx +13 -0
- package/dist/solid/canvas/export-png.jsx +496 -0
- package/dist/solid/canvas/gesture-machine.jsx +91 -0
- package/dist/solid/canvas/handlers.jsx +18 -0
- package/dist/solid/canvas/index.jsx +9 -0
- package/dist/solid/canvas/input.jsx +85 -0
- package/dist/solid/canvas/instant.jsx +28 -0
- package/dist/solid/canvas/kernel.jsx +39 -0
- package/dist/solid/canvas/motion.jsx +686 -0
- package/dist/solid/canvas/palette.jsx +165 -0
- package/dist/solid/canvas/random-id.jsx +15 -0
- package/dist/solid/canvas/scene-renderer.jsx +559 -0
- package/dist/solid/canvas/scene.styles.jsx +7 -0
- package/dist/solid/canvas/surface-model.jsx +324 -0
- package/dist/solid/canvas/uploads.jsx +294 -0
- package/dist/solid/index.jsx +9 -0
- package/dist/solid/kernel/actions.jsx +455 -0
- package/dist/solid/kernel/board.jsx +856 -0
- package/dist/solid/kernel/claims.jsx +40 -0
- package/dist/solid/kernel/clipboard.jsx +30 -0
- package/dist/solid/kernel/constants.jsx +210 -0
- package/dist/solid/kernel/contract.jsx +0 -0
- package/dist/solid/kernel/decode.jsx +85 -0
- package/dist/solid/kernel/editor.jsx +2077 -0
- package/dist/solid/kernel/errors.jsx +82 -0
- package/dist/solid/kernel/fonts/inter.jsx +7924 -0
- package/dist/solid/kernel/fractional-index.jsx +54 -0
- package/dist/solid/kernel/geometry.jsx +123 -0
- package/dist/solid/kernel/hit-test.jsx +156 -0
- package/dist/solid/kernel/index.jsx +22 -0
- package/dist/solid/kernel/inspect.jsx +116 -0
- package/dist/solid/kernel/kernel.jsx +251 -0
- package/dist/solid/kernel/outline.jsx +64 -0
- package/dist/solid/kernel/plan.jsx +1370 -0
- package/dist/solid/kernel/rev.jsx +173 -0
- package/dist/solid/kernel/scene.jsx +580 -0
- package/dist/solid/kernel/schema.jsx +1109 -0
- package/dist/solid/kernel/snap.jsx +258 -0
- package/dist/solid/kernel/svg.jsx +148 -0
- package/dist/solid/kernel/text.jsx +142 -0
- package/dist/styles.css +1 -0
- package/dist/types/canvas/assets.d.ts +111 -0
- package/dist/types/canvas/board-store.d.ts +86 -0
- package/dist/types/canvas/canvas-actions.d.ts +21 -0
- package/dist/types/canvas/canvas-board.d.ts +53 -0
- package/dist/types/canvas/canvas-board.styles.d.ts +94 -0
- package/dist/types/canvas/canvas-chrome.d.ts +109 -0
- package/dist/types/canvas/canvas-chrome.styles.d.ts +193 -0
- package/dist/types/canvas/canvas-comments.d.ts +20 -0
- package/dist/types/canvas/canvas-comments.styles.d.ts +208 -0
- package/dist/types/canvas/canvas-context.d.ts +104 -0
- package/dist/types/canvas/canvas-controller.d.ts +159 -0
- package/dist/types/canvas/canvas-cursor-chat.d.ts +13 -0
- package/dist/types/canvas/canvas-cursor-chat.styles.d.ts +54 -0
- package/dist/types/canvas/canvas-menus.d.ts +21 -0
- package/dist/types/canvas/canvas-menus.styles.d.ts +6 -0
- package/dist/types/canvas/canvas-style-bar.d.ts +19 -0
- package/dist/types/canvas/canvas-style-bar.styles.d.ts +43 -0
- package/dist/types/canvas/canvas-surface.d.ts +15 -0
- package/dist/types/canvas/canvas-surface.styles.d.ts +313 -0
- package/dist/types/canvas/canvas-tool-rail.d.ts +41 -0
- package/dist/types/canvas/canvas-tool-rail.styles.d.ts +15 -0
- package/dist/types/canvas/comments.d.ts +106 -0
- package/dist/types/canvas/equality.d.ts +4 -0
- package/dist/types/canvas/export-png.d.ts +77 -0
- package/dist/types/canvas/gesture-machine.d.ts +46 -0
- package/dist/types/canvas/handlers.d.ts +7 -0
- package/dist/types/canvas/index.d.ts +18 -0
- package/dist/types/canvas/input.d.ts +63 -0
- package/dist/types/canvas/instant.d.ts +13 -0
- package/dist/types/canvas/kernel.d.ts +27 -0
- package/dist/types/canvas/motion.d.ts +72 -0
- package/dist/types/canvas/palette.d.ts +46 -0
- package/dist/types/canvas/random-id.d.ts +6 -0
- package/dist/types/canvas/scene-renderer.d.ts +27 -0
- package/dist/types/canvas/scene.styles.d.ts +4 -0
- package/dist/types/canvas/surface-model.d.ts +113 -0
- package/dist/types/canvas/uploads.d.ts +58 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/kernel/actions.d.ts +19 -0
- package/dist/types/kernel/board.d.ts +137 -0
- package/dist/types/kernel/claims.d.ts +29 -0
- package/dist/types/kernel/clipboard.d.ts +10 -0
- package/dist/types/kernel/constants.d.ts +195 -0
- package/dist/types/kernel/contract.d.ts +1533 -0
- package/dist/types/kernel/decode.d.ts +60 -0
- package/dist/types/kernel/editor.d.ts +12 -0
- package/dist/types/kernel/errors.d.ts +11 -0
- package/dist/types/kernel/fractional-index.d.ts +7 -0
- package/dist/types/kernel/geometry.d.ts +42 -0
- package/dist/types/kernel/hit-test.d.ts +16 -0
- package/dist/types/kernel/index.d.ts +8 -0
- package/dist/types/kernel/inspect.d.ts +6 -0
- package/dist/types/kernel/kernel.d.ts +6 -0
- package/dist/types/kernel/outline.d.ts +4 -0
- package/dist/types/kernel/plan.d.ts +20 -0
- package/dist/types/kernel/rev.d.ts +21 -0
- package/dist/types/kernel/scene.d.ts +16 -0
- package/dist/types/kernel/schema.d.ts +3436 -0
- package/dist/types/kernel/snap.d.ts +41 -0
- package/dist/types/kernel/svg.d.ts +3 -0
- package/dist/types/kernel/text.d.ts +21 -0
- package/docs/api.json +207 -0
- package/docs/canvas.md +444 -0
- package/docs/kernel.md +108 -0
- package/docs/llms.txt +41 -0
- package/docs/search-index.json +52 -0
- package/package.json +55 -4
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { useCanvasActions } from "./canvas-actions.jsx";
|
|
2
|
+
import { useCanvasCommands, useCanvasController, useCanvasMedia, useCanvasSelection, useCanvasSelector } from "./canvas-context.jsx";
|
|
3
|
+
import { CanvasDropdownItems } from "./canvas-menus.jsx";
|
|
4
|
+
import { styleBar } from "./canvas-style-bar.styles.jsx";
|
|
5
|
+
import { ActionHint } from "./canvas-tool-rail.jsx";
|
|
6
|
+
import { rail } from "./canvas-tool-rail.styles.jsx";
|
|
7
|
+
import { shallowEqual } from "./equality.jsx";
|
|
8
|
+
import { expectOk } from "./kernel.jsx";
|
|
9
|
+
import { CANVAS_COLORS, COLOR_LABELS, strokeOf } from "./palette.jsx";
|
|
10
|
+
import * as stylex from "@stylexjs/stylex";
|
|
11
|
+
import { For, Match, Show, Switch, createContext, createMemo, createSignal, createUniqueId, useContext } from "solid-js";
|
|
12
|
+
import { Button } from "@zsherman/kit/button";
|
|
13
|
+
import { Icon } from "@zsherman/kit/icon";
|
|
14
|
+
import { AlignCenter, AlignLeft, AlignRight, Download, Ellipsis, PenLine, Trash } from "@zsherman/kit/icons";
|
|
15
|
+
import { Menu, MenuContent, MenuGroup, MenuGroupLabel, MenuRadioGroup, MenuRadioItem, MenuSeparator, MenuTrigger } from "@zsherman/kit/menu";
|
|
16
|
+
import { Toolbar, ToolbarButton, ToolbarLink, ToolbarSeparator } from "@zsherman/kit/toolbar";
|
|
17
|
+
import { Toggle, ToggleGroup } from "@zsherman/kit/toggle";
|
|
18
|
+
import { Field, FieldDescription, FieldLabel, Textarea } from "@zsherman/kit/field";
|
|
19
|
+
import { Popover, PopoverContent, PopoverTrigger } from "@zsherman/kit/popover";
|
|
20
|
+
import { DrawToolbar } from "@zsherman/kit/draw-toolbar";
|
|
21
|
+
// src/canvas/canvas-style-bar.tsx
|
|
22
|
+
/** The style each tool draws with when none is chosen; mirrors the kernel's defaults. */
|
|
23
|
+
const TOOL_DEFAULTS = {
|
|
24
|
+
arrow: {
|
|
25
|
+
color: "gray",
|
|
26
|
+
dash: "solid",
|
|
27
|
+
end: "arrow",
|
|
28
|
+
route: "straight",
|
|
29
|
+
start: "none"
|
|
30
|
+
},
|
|
31
|
+
ellipse: {
|
|
32
|
+
align: "center",
|
|
33
|
+
color: "blue",
|
|
34
|
+
dash: "solid",
|
|
35
|
+
fill: true,
|
|
36
|
+
size: "m"
|
|
37
|
+
},
|
|
38
|
+
pen: {
|
|
39
|
+
brush: "pen",
|
|
40
|
+
color: "ink",
|
|
41
|
+
size: "m"
|
|
42
|
+
},
|
|
43
|
+
rectangle: {
|
|
44
|
+
align: "center",
|
|
45
|
+
color: "blue",
|
|
46
|
+
dash: "solid",
|
|
47
|
+
fill: true,
|
|
48
|
+
size: "m"
|
|
49
|
+
},
|
|
50
|
+
sticky: {
|
|
51
|
+
align: "start",
|
|
52
|
+
color: "yellow",
|
|
53
|
+
size: "m"
|
|
54
|
+
},
|
|
55
|
+
text: {
|
|
56
|
+
align: "start",
|
|
57
|
+
color: "ink",
|
|
58
|
+
size: "m"
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const sameStyle = (a, b) => a === b || a !== null && b !== null && shallowEqual(a, b);
|
|
62
|
+
/** The style to show: the selection's, or the tool's for the next shape. A null key doesn't apply: its control hides. */
|
|
63
|
+
function useShownStyle() {
|
|
64
|
+
const controller = useCanvasController();
|
|
65
|
+
const selection = useCanvasSelection();
|
|
66
|
+
const board = useCanvasSelector((snapshot) => snapshot.state.selection.length > 0 ? snapshot.board : null);
|
|
67
|
+
const toolStyle = useCanvasSelector((snapshot) => snapshot.state.style);
|
|
68
|
+
const tool = useCanvasSelector((snapshot) => snapshot.state.tool);
|
|
69
|
+
return createMemo(() => {
|
|
70
|
+
const ids = selection();
|
|
71
|
+
const current = board();
|
|
72
|
+
if (current !== null && ids.length > 0) {
|
|
73
|
+
const inspection = expectOk(controller.kernel.inspect(current, ids));
|
|
74
|
+
return inspection.can.restyle ? inspection.style : null;
|
|
75
|
+
}
|
|
76
|
+
const defaults = TOOL_DEFAULTS[tool()];
|
|
77
|
+
if (defaults === void 0) return null;
|
|
78
|
+
const chosen = toolStyle();
|
|
79
|
+
const of = (key) => key in defaults ? chosen[key] ?? defaults[key] ?? null : null;
|
|
80
|
+
return {
|
|
81
|
+
align: of("align"),
|
|
82
|
+
brush: of("brush"),
|
|
83
|
+
color: of("color"),
|
|
84
|
+
dash: of("dash"),
|
|
85
|
+
end: of("end"),
|
|
86
|
+
fill: of("fill"),
|
|
87
|
+
route: of("route"),
|
|
88
|
+
size: of("size"),
|
|
89
|
+
start: of("start")
|
|
90
|
+
};
|
|
91
|
+
}, { equals: sameStyle });
|
|
92
|
+
}
|
|
93
|
+
const SIZES = [
|
|
94
|
+
{
|
|
95
|
+
label: "Small",
|
|
96
|
+
value: "s"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
label: "Medium",
|
|
100
|
+
value: "m"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
label: "Large",
|
|
104
|
+
value: "l"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: "Extra large",
|
|
108
|
+
value: "xl"
|
|
109
|
+
}
|
|
110
|
+
];
|
|
111
|
+
const DASHES = [
|
|
112
|
+
{
|
|
113
|
+
label: "Solid",
|
|
114
|
+
value: "solid"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
label: "Dashed",
|
|
118
|
+
value: "dashed"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
label: "Dotted",
|
|
122
|
+
value: "dotted"
|
|
123
|
+
}
|
|
124
|
+
];
|
|
125
|
+
const HEADS = [
|
|
126
|
+
{
|
|
127
|
+
label: "None",
|
|
128
|
+
value: "none"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
label: "Arrow",
|
|
132
|
+
value: "arrow"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
label: "Triangle",
|
|
136
|
+
value: "triangle"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
label: "Dot",
|
|
140
|
+
value: "dot"
|
|
141
|
+
}
|
|
142
|
+
];
|
|
143
|
+
const ROUTES = [{
|
|
144
|
+
label: "Straight",
|
|
145
|
+
value: "straight"
|
|
146
|
+
}, {
|
|
147
|
+
label: "Elbow",
|
|
148
|
+
value: "elbow"
|
|
149
|
+
}];
|
|
150
|
+
const ALIGNS = [
|
|
151
|
+
{
|
|
152
|
+
icon: AlignLeft,
|
|
153
|
+
label: "Align text left",
|
|
154
|
+
value: "start"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
icon: AlignCenter,
|
|
158
|
+
label: "Center text",
|
|
159
|
+
value: "center"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
icon: AlignRight,
|
|
163
|
+
label: "Align text right",
|
|
164
|
+
value: "end"
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
/** A select value: the shared one, or none for mixed. */
|
|
168
|
+
const single = (value) => value === null || value === "mixed" ? "" : value;
|
|
169
|
+
function pick(options, value) {
|
|
170
|
+
return options.find((option) => option.value === value)?.value ?? null;
|
|
171
|
+
}
|
|
172
|
+
/** Which way the bar's popups open: into the board, away from the edge the bar sits on. */
|
|
173
|
+
const PopupSide = createContext(() => "bottom");
|
|
174
|
+
function ColorControl(props) {
|
|
175
|
+
const side = useContext(PopupSide);
|
|
176
|
+
const commands = useCanvasCommands();
|
|
177
|
+
const titleId = createUniqueId();
|
|
178
|
+
const shown = () => props.color === "mixed" || props.color === null ? null : props.color;
|
|
179
|
+
return <Popover>
|
|
180
|
+
<ToolbarButton aria-label={`Color: ${shown() === null ? "Mixed" : COLOR_LABELS[shown()]}`} title="Color" render={(trigger) => <PopoverTrigger {...trigger} iconOnly variant="ghost" />}>
|
|
181
|
+
<span aria-hidden="true" {...stylex.attrs(styleBar.swatch, shown() === null ? styleBar.mixed : null)} style={{ "--canvas-swatch": shown() === null ? "transparent" : strokeOf(shown()) }} />
|
|
182
|
+
</ToolbarButton>
|
|
183
|
+
<PopoverContent size="sm" side={side()} aria-labelledby={titleId}>
|
|
184
|
+
<p id={titleId} {...stylex.attrs(styleBar.title)}>
|
|
185
|
+
Color
|
|
186
|
+
</p>
|
|
187
|
+
<ToggleGroup aria-labelledby={titleId} deselectable={false} value={shown() === null ? [] : [shown()]} onValueChange={(value) => {
|
|
188
|
+
const next = CANVAS_COLORS.find((c) => c === value[0]);
|
|
189
|
+
if (next !== void 0) commands.style({ color: next });
|
|
190
|
+
}} class={stylex.props(styleBar.swatches).className}>
|
|
191
|
+
<For each={CANVAS_COLORS}>
|
|
192
|
+
{(color) => <Toggle value={color} aria-label={COLOR_LABELS[color]} size="sm">
|
|
193
|
+
<span aria-hidden="true" {...stylex.attrs(styleBar.swatch)} style={{ "--canvas-swatch": strokeOf(color) }} />
|
|
194
|
+
</Toggle>}
|
|
195
|
+
</For>
|
|
196
|
+
</ToggleGroup>
|
|
197
|
+
</PopoverContent>
|
|
198
|
+
</Popover>;
|
|
199
|
+
}
|
|
200
|
+
function RadioGroup(props) {
|
|
201
|
+
return <MenuGroup>
|
|
202
|
+
<MenuGroupLabel>{props.label}</MenuGroupLabel>
|
|
203
|
+
<MenuRadioGroup value={props.value} onValueChange={(value) => {
|
|
204
|
+
const found = pick(props.options, value);
|
|
205
|
+
if (found !== null) props.onChange(found);
|
|
206
|
+
}}>
|
|
207
|
+
<For each={props.options}>
|
|
208
|
+
{(option) => <MenuRadioItem value={option.value}>{option.label}</MenuRadioItem>}
|
|
209
|
+
</For>
|
|
210
|
+
</MenuRadioGroup>
|
|
211
|
+
</MenuGroup>;
|
|
212
|
+
}
|
|
213
|
+
const FILLS = [{
|
|
214
|
+
label: "None",
|
|
215
|
+
value: "none"
|
|
216
|
+
}, {
|
|
217
|
+
label: "Solid",
|
|
218
|
+
value: "solid"
|
|
219
|
+
}];
|
|
220
|
+
function LineMenu(props) {
|
|
221
|
+
const side = useContext(PopupSide);
|
|
222
|
+
const commands = useCanvasCommands();
|
|
223
|
+
const groups = createMemo(() => [
|
|
224
|
+
"fill",
|
|
225
|
+
"dash",
|
|
226
|
+
"route",
|
|
227
|
+
"start",
|
|
228
|
+
"end"
|
|
229
|
+
].filter((key) => props.style[key] !== null));
|
|
230
|
+
const group = (key) => {
|
|
231
|
+
switch (key) {
|
|
232
|
+
case "fill": return <RadioGroup label="Fill" options={FILLS} value={props.style.fill === "mixed" ? "" : props.style.fill ? "solid" : "none"} onChange={(value) => commands.style({ fill: value === "solid" })} />;
|
|
233
|
+
case "dash": return <RadioGroup label="Line" options={DASHES} value={single(props.style.dash)} onChange={(dash) => commands.style({ dash })} />;
|
|
234
|
+
case "route": return <RadioGroup label="Route" options={ROUTES} value={single(props.style.route)} onChange={(route) => commands.style({ route })} />;
|
|
235
|
+
case "start":
|
|
236
|
+
case "end": return <RadioGroup label={key === "start" ? "Start" : "End"} options={HEADS} value={single(props.style[key])} onChange={(head) => commands.style({ [key]: head })} />;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return <Show when={groups().length > 0}>
|
|
240
|
+
<Menu>
|
|
241
|
+
<ToolbarButton aria-label="Line and fill" title="Line and fill" render={(trigger) => <MenuTrigger {...trigger} iconOnly variant="ghost" />}>
|
|
242
|
+
<Icon icon={PenLine} aria-hidden="true" />
|
|
243
|
+
</ToolbarButton>
|
|
244
|
+
<MenuContent side={side()}>
|
|
245
|
+
<For each={groups()}>
|
|
246
|
+
{(key, index) => <>
|
|
247
|
+
<Show when={index() > 0}>
|
|
248
|
+
<MenuSeparator />
|
|
249
|
+
</Show>
|
|
250
|
+
{group(key)}
|
|
251
|
+
</>}
|
|
252
|
+
</For>
|
|
253
|
+
</MenuContent>
|
|
254
|
+
</Menu>
|
|
255
|
+
</Show>;
|
|
256
|
+
}
|
|
257
|
+
/** One choice from a few, as a menu, for a narrow bar. */
|
|
258
|
+
function ChoiceMenu(props) {
|
|
259
|
+
const side = useContext(PopupSide);
|
|
260
|
+
const current = () => props.options.find((option) => option.value === props.value)?.label;
|
|
261
|
+
return <Menu>
|
|
262
|
+
<ToolbarButton aria-label={current() === void 0 ? props.label : `${props.label}: ${current()}`} render={(trigger) => <MenuTrigger {...trigger} iconOnly variant="ghost" />}>
|
|
263
|
+
{props.trigger}
|
|
264
|
+
</ToolbarButton>
|
|
265
|
+
<MenuContent side={side()}>
|
|
266
|
+
<RadioGroup label={props.label} options={props.options} value={props.value} onChange={props.onChange} />
|
|
267
|
+
</MenuContent>
|
|
268
|
+
</Menu>;
|
|
269
|
+
}
|
|
270
|
+
/** The one image selected, or null. */
|
|
271
|
+
function useSelectedImage() {
|
|
272
|
+
return useCanvasSelector((snapshot) => {
|
|
273
|
+
const { selection } = snapshot.state;
|
|
274
|
+
if (selection.length !== 1) return null;
|
|
275
|
+
const found = snapshot.board.shapes.find((item) => item.id === selection[0]);
|
|
276
|
+
return found?.kind === "Image" ? {
|
|
277
|
+
alt: found.alt,
|
|
278
|
+
asset: found.asset,
|
|
279
|
+
id: found.id
|
|
280
|
+
} : null;
|
|
281
|
+
}, (a, b) => a === b || a !== null && b !== null && shallowEqual(a, b));
|
|
282
|
+
}
|
|
283
|
+
/** Longest description the bar takes; screen readers read it in one go. */
|
|
284
|
+
const ALT_MAX = 500;
|
|
285
|
+
/** Edits an image's description, which screen readers read out and agents see. Saving sets it for everyone. */
|
|
286
|
+
function AltTextControl(props) {
|
|
287
|
+
const side = useContext(PopupSide);
|
|
288
|
+
const commands = useCanvasCommands();
|
|
289
|
+
const [open, setOpen] = createSignal(false);
|
|
290
|
+
const described = () => props.image.alt.trim() !== "";
|
|
291
|
+
const save = (event) => {
|
|
292
|
+
event.preventDefault();
|
|
293
|
+
const field = event.currentTarget.elements.namedItem("alt");
|
|
294
|
+
const alt = field instanceof HTMLTextAreaElement ? field.value.trim() : "";
|
|
295
|
+
commands.run([{
|
|
296
|
+
_tag: "Update",
|
|
297
|
+
id: props.image.id,
|
|
298
|
+
patch: { alt }
|
|
299
|
+
}], null);
|
|
300
|
+
setOpen(false);
|
|
301
|
+
};
|
|
302
|
+
return <Popover open={open()} onOpenChange={setOpen}>
|
|
303
|
+
<ToolbarButton title={described() ? props.image.alt : "Add a description for screen readers"} data-described={described() ? "" : void 0} render={(trigger) => <PopoverTrigger {...trigger} variant="ghost" size="sm" />}>
|
|
304
|
+
{described() ? "Description" : "Describe this image"}
|
|
305
|
+
</ToolbarButton>
|
|
306
|
+
<PopoverContent align="start" side={side()}>
|
|
307
|
+
<form {...stylex.attrs(styleBar.form)} onSubmit={save}>
|
|
308
|
+
<Field>
|
|
309
|
+
<FieldLabel>Describe this image</FieldLabel>
|
|
310
|
+
<Textarea name="alt" rows={3} maxlength={ALT_MAX} value={props.image.alt} onKeyDown={(event) => {
|
|
311
|
+
event.stopPropagation();
|
|
312
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
313
|
+
event.preventDefault();
|
|
314
|
+
event.currentTarget.form?.requestSubmit();
|
|
315
|
+
}
|
|
316
|
+
}} />
|
|
317
|
+
<FieldDescription>Read out by screen readers and seen by agents on the board</FieldDescription>
|
|
318
|
+
</Field>
|
|
319
|
+
<div {...stylex.attrs(styleBar.actions)}>
|
|
320
|
+
<Button size="sm" type="button" variant="ghost" onClick={() => setOpen(false)}>
|
|
321
|
+
Cancel
|
|
322
|
+
</Button>
|
|
323
|
+
<Button size="sm" type="submit" variant="primary">
|
|
324
|
+
Save
|
|
325
|
+
</Button>
|
|
326
|
+
</div>
|
|
327
|
+
</form>
|
|
328
|
+
</PopoverContent>
|
|
329
|
+
</Popover>;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Uploads a new file for the image, which keeps its place and width. Shown while the image can be changed:
|
|
333
|
+
* the kernel's Delete stands for that, as it's off for a locked image or one someone else is editing.
|
|
334
|
+
*/
|
|
335
|
+
function ReplaceImageButton(props) {
|
|
336
|
+
const media = useCanvasMedia();
|
|
337
|
+
const actions = useCanvasActions();
|
|
338
|
+
return <Show when={actions().get("delete")?.enabled === true ? media() : null}>
|
|
339
|
+
{(current) => <ToolbarButton data-slot="canvas-replace-image" title="Replace with another image" size="sm" onClick={() => current().uploads.pickReplacement(props.id)}>
|
|
340
|
+
Replace
|
|
341
|
+
</ToolbarButton>}
|
|
342
|
+
</Show>;
|
|
343
|
+
}
|
|
344
|
+
/** The bar for one selected image: its description, Replace, the original file when the app offers one, and the selection's actions. */
|
|
345
|
+
function ImageBar(props) {
|
|
346
|
+
const media = useCanvasMedia();
|
|
347
|
+
const original = () => media()?.assets.original?.(props.image.asset) ?? null;
|
|
348
|
+
return <Toolbar aria-label="Image" data-slot="canvas-style-bar" class={stylex.props(rail.floating).className}>
|
|
349
|
+
<Show when={props.image.id} keyed>
|
|
350
|
+
{(_id) => <AltTextControl image={props.image} />}
|
|
351
|
+
</Show>
|
|
352
|
+
<ReplaceImageButton id={props.image.id} />
|
|
353
|
+
<Show when={original()}>
|
|
354
|
+
{(file) => <ToolbarLink href={file().href} download={file().name} aria-label={`Download ${file().name}`} title="Download original" xstyle={styleBar.square}>
|
|
355
|
+
<Icon icon={Download} aria-hidden="true" />
|
|
356
|
+
</ToolbarLink>}
|
|
357
|
+
</Show>
|
|
358
|
+
<SelectionActions />
|
|
359
|
+
</Toolbar>;
|
|
360
|
+
}
|
|
361
|
+
/** The selection's More menu and Delete, at the end of a bar. */
|
|
362
|
+
function SelectionActions() {
|
|
363
|
+
const side = useContext(PopupSide);
|
|
364
|
+
const commands = useCanvasCommands();
|
|
365
|
+
const actions = useCanvasActions();
|
|
366
|
+
return <>
|
|
367
|
+
<ToolbarSeparator />
|
|
368
|
+
<Menu>
|
|
369
|
+
<ToolbarButton aria-label="More actions" title="More actions" render={(trigger) => <MenuTrigger {...trigger} iconOnly variant="ghost" />}>
|
|
370
|
+
<Icon icon={Ellipsis} aria-hidden="true" />
|
|
371
|
+
</ToolbarButton>
|
|
372
|
+
<MenuContent align="end" side={side()}>
|
|
373
|
+
<CanvasDropdownItems />
|
|
374
|
+
</MenuContent>
|
|
375
|
+
</Menu>
|
|
376
|
+
<Show when={actions().get("delete")?.enabled === true}>
|
|
377
|
+
<ActionHint action="delete" side={side()} aria-label="Delete" onClick={() => commands.action("delete")} render={(trigger) => <ToolbarButton {...trigger} iconOnly />}>
|
|
378
|
+
<Icon icon={Trash} aria-hidden="true" />
|
|
379
|
+
</ActionHint>
|
|
380
|
+
</Show>
|
|
381
|
+
</>;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Style for the selection, or for the next shape when a shape tool is in hand, with the selection's actions
|
|
385
|
+
* in a menu. One selected image gets its own bar: a description, the original file, and the actions.
|
|
386
|
+
*/
|
|
387
|
+
function CanvasStyleBar(props) {
|
|
388
|
+
const readOnly = useCanvasSelector((snapshot) => snapshot.state.readOnly);
|
|
389
|
+
const selected = useCanvasSelector((snapshot) => snapshot.state.selection.length > 0);
|
|
390
|
+
const commands = useCanvasCommands();
|
|
391
|
+
const style = useShownStyle();
|
|
392
|
+
const image = useSelectedImage();
|
|
393
|
+
const compact = () => props.compact ?? false;
|
|
394
|
+
const opens = () => (props.edge ?? (compact() ? "bottom" : "top")) === "bottom" ? "top" : "bottom";
|
|
395
|
+
return <PopupSide value={opens}>
|
|
396
|
+
<Show when={!readOnly()}>
|
|
397
|
+
<Switch>
|
|
398
|
+
<Match when={image()}>{(found) => <ImageBar image={found()} />}</Match>
|
|
399
|
+
<Match when={style()}>
|
|
400
|
+
{(shown) => <Toolbar aria-label={selected() ? "Selection style" : "Style"} data-slot="canvas-style-bar" class={stylex.props(rail.floating).className}>
|
|
401
|
+
<Show when={shown().color !== null}>
|
|
402
|
+
<ColorControl color={shown().color} />
|
|
403
|
+
</Show>
|
|
404
|
+
<Show when={shown().size !== null}>
|
|
405
|
+
<Show when={compact()} fallback={<ToggleGroup aria-label="Size" value={single(shown().size) === "" ? [] : [single(shown().size)]} onValueChange={(value) => {
|
|
406
|
+
const size = pick(SIZES, value[0]);
|
|
407
|
+
if (size !== null) commands.style({ size });
|
|
408
|
+
}}>
|
|
409
|
+
<For each={SIZES}>
|
|
410
|
+
{(size) => <Toggle value={size.value} aria-label={size.label} size="sm">
|
|
411
|
+
{size.value.toUpperCase()}
|
|
412
|
+
</Toggle>}
|
|
413
|
+
</For>
|
|
414
|
+
</ToggleGroup>}>
|
|
415
|
+
<ChoiceMenu label="Size" options={SIZES} value={single(shown().size)} onChange={(size) => commands.style({ size })} trigger={single(shown().size).toUpperCase() || "–"} />
|
|
416
|
+
</Show>
|
|
417
|
+
</Show>
|
|
418
|
+
<Show when={shown().align !== null}>
|
|
419
|
+
<Show when={compact()} fallback={<ToggleGroup aria-label="Text alignment" value={single(shown().align) === "" ? [] : [single(shown().align)]} onValueChange={(value) => {
|
|
420
|
+
const align = pick(ALIGNS, value[0]);
|
|
421
|
+
if (align !== null) commands.style({ align });
|
|
422
|
+
}}>
|
|
423
|
+
<For each={ALIGNS}>
|
|
424
|
+
{(option) => <Toggle value={option.value} aria-label={option.label} size="sm">
|
|
425
|
+
<Icon icon={option.icon} aria-hidden="true" />
|
|
426
|
+
</Toggle>}
|
|
427
|
+
</For>
|
|
428
|
+
</ToggleGroup>}>
|
|
429
|
+
<ChoiceMenu label="Text alignment" options={ALIGNS} value={single(shown().align)} onChange={(align) => commands.style({ align })} trigger={<Icon icon={ALIGNS.find((option) => option.value === single(shown().align))?.icon ?? AlignLeft} aria-hidden="true" />} />
|
|
430
|
+
</Show>
|
|
431
|
+
</Show>
|
|
432
|
+
<LineMenu style={shown()} />
|
|
433
|
+
<Show when={selected()}>
|
|
434
|
+
<SelectionActions />
|
|
435
|
+
</Show>
|
|
436
|
+
</Toolbar>}
|
|
437
|
+
</Match>
|
|
438
|
+
</Switch>
|
|
439
|
+
</Show>
|
|
440
|
+
</PopupSide>;
|
|
441
|
+
}
|
|
442
|
+
const BRUSHES = [
|
|
443
|
+
"pen",
|
|
444
|
+
"marker",
|
|
445
|
+
"highlighter"
|
|
446
|
+
];
|
|
447
|
+
/**
|
|
448
|
+
* The board stores four sizes (S to XL), so the slider moves between them as stops 1 to 4: every step, by an
|
|
449
|
+
* arrow key or a drag, is the next size. (On the ink widths, 2, 4, 8 and 12, a step of 1 snapped back to the
|
|
450
|
+
* nearest size and the arrows never got past it.)
|
|
451
|
+
*/
|
|
452
|
+
const sizeStop = (size) => SIZES.findIndex((option) => option.value === size) + 1;
|
|
453
|
+
const sizeAt = (stop) => SIZES[Math.min(Math.max(Math.round(stop), 1), SIZES.length) - 1].value;
|
|
454
|
+
const SWATCHES = CANVAS_COLORS.map((color) => ({
|
|
455
|
+
label: COLOR_LABELS[color],
|
|
456
|
+
paint: strokeOf(color),
|
|
457
|
+
value: color
|
|
458
|
+
}));
|
|
459
|
+
/** Pens, ink color and width while the pen or eraser is in hand: the kit's Draw toolbar. */
|
|
460
|
+
function CanvasDrawBar() {
|
|
461
|
+
const style = useCanvasSelector((snapshot) => snapshot.state.style);
|
|
462
|
+
const tool = useCanvasSelector((snapshot) => snapshot.state.tool);
|
|
463
|
+
const commands = useCanvasCommands();
|
|
464
|
+
const actions = useCanvasActions();
|
|
465
|
+
const drawTool = () => tool() === "eraser" ? "eraser" : style().brush ?? "pen";
|
|
466
|
+
return <DrawToolbar class={stylex.props(rail.floating).className} canRedo={actions().get("redo")?.enabled === true} canUndo={actions().get("undo")?.enabled === true} color={style().color ?? "ink"} eraser onColorChange={(value) => {
|
|
467
|
+
const next = CANVAS_COLORS.find((c) => c === value);
|
|
468
|
+
if (next === void 0) return;
|
|
469
|
+
commands.style({ color: next });
|
|
470
|
+
if (tool() === "eraser") commands.action("tool-pen");
|
|
471
|
+
}} onRedo={() => commands.action("redo")} onSizeChange={(stop) => commands.style({ size: sizeAt(stop) })} onToolChange={(next) => {
|
|
472
|
+
if (next === "eraser") {
|
|
473
|
+
commands.action("tool-eraser");
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const brush = BRUSHES.find((b) => b === next);
|
|
477
|
+
if (brush !== void 0) commands.style({ brush });
|
|
478
|
+
if (tool() !== "pen") commands.action("tool-pen");
|
|
479
|
+
}} onUndo={() => commands.action("undo")} size={sizeStop(style().size ?? "m")} sizeRange={{
|
|
480
|
+
max: SIZES.length,
|
|
481
|
+
min: 1
|
|
482
|
+
}} swatches={SWATCHES} tool={drawTool()} />;
|
|
483
|
+
}
|
|
484
|
+
/** Whether the draw bar shows instead of the style bar. */
|
|
485
|
+
const drawing = (tool) => tool === "pen" || tool === "eraser";
|
|
486
|
+
export { CanvasDrawBar, CanvasStyleBar, drawing };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import "@stylexjs/stylex";
|
|
2
|
+
// src/canvas/canvas-style-bar.styles.ts
|
|
3
|
+
const styleBar = {
|
|
4
|
+
swatch: {
|
|
5
|
+
k1xSpc: "x1lliihq",
|
|
6
|
+
kmuXW: "x2lah0s",
|
|
7
|
+
kzqmXN: "xcdlrvm",
|
|
8
|
+
kZKoxP: "x1l36t39",
|
|
9
|
+
kaIpWk: "x1dg1y8n",
|
|
10
|
+
kWkggS: "x12ujf98",
|
|
11
|
+
kGVxlE: "xg8gn2m",
|
|
12
|
+
kAXs8y: "x1kzknox",
|
|
13
|
+
$$css: true
|
|
14
|
+
},
|
|
15
|
+
mixed: {
|
|
16
|
+
kKwaWg: "x1ozsgnv",
|
|
17
|
+
$$css: true
|
|
18
|
+
},
|
|
19
|
+
title: {
|
|
20
|
+
kogj98: "x1ghz6dp",
|
|
21
|
+
kGuDYH: "x409pna",
|
|
22
|
+
k63SB2: "x1vmg6u2",
|
|
23
|
+
kMwMTN: "x1yjpjgc",
|
|
24
|
+
$$css: true
|
|
25
|
+
},
|
|
26
|
+
swatches: {
|
|
27
|
+
k1xSpc: "xrvj5dj",
|
|
28
|
+
kumcoG: "xfgr5u3",
|
|
29
|
+
kjj79g: "xlqzeqv",
|
|
30
|
+
kOIVth: "xz09phk",
|
|
31
|
+
$$css: true
|
|
32
|
+
},
|
|
33
|
+
form: {
|
|
34
|
+
k1xSpc: "x78zum5",
|
|
35
|
+
kXwgrk: "xdt5ytf",
|
|
36
|
+
kOIVth: "xgtrjx6",
|
|
37
|
+
$$css: true
|
|
38
|
+
},
|
|
39
|
+
actions: {
|
|
40
|
+
k1xSpc: "x78zum5",
|
|
41
|
+
kjj79g: "x13a6bvl",
|
|
42
|
+
kOIVth: "x8rwxmg",
|
|
43
|
+
$$css: true
|
|
44
|
+
},
|
|
45
|
+
square: {
|
|
46
|
+
kOBAk4: "x1plog1",
|
|
47
|
+
kg3NbH: "xnjsko4",
|
|
48
|
+
kjj79g: "xl56j7k",
|
|
49
|
+
$$css: true
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export { styleBar };
|