@zsherman/canvas 0.0.0-stage → 0.1.1
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 +24 -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 +1354 -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 +60 -4
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/canvas/board-store.ts
|
|
2
|
+
/**
|
|
3
|
+
* A board with no shapes and no history, as the kernel's `EMPTY_BOARD`. It is
|
|
4
|
+
* spelled out here because importing a value from the kernel would load the
|
|
5
|
+
* kernel with the page instead of when a board first needs it.
|
|
6
|
+
*/
|
|
7
|
+
const EMPTY_BOARD = Object.freeze({
|
|
8
|
+
head: 0,
|
|
9
|
+
["shapes"]: Object.freeze([]),
|
|
10
|
+
transactions: Object.freeze([])
|
|
11
|
+
});
|
|
12
|
+
const CONFIRMED = { _tag: "Confirmed" };
|
|
13
|
+
/**
|
|
14
|
+
* A board in memory, for a single-player board, tests and examples, and the
|
|
15
|
+
* reference for the store contract: it keeps every commit, confirms it at
|
|
16
|
+
* once and refuses none.
|
|
17
|
+
*/
|
|
18
|
+
function createMemoryBoardStore({ actor, board: initialBoard = EMPTY_BOARD, connection, presence: initialPresence = [] }) {
|
|
19
|
+
let board = initialBoard;
|
|
20
|
+
let presence = initialPresence;
|
|
21
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
22
|
+
const notify = () => {
|
|
23
|
+
for (const listener of Array.from(listeners)) listener();
|
|
24
|
+
};
|
|
25
|
+
const store = {
|
|
26
|
+
actor,
|
|
27
|
+
commit(change) {
|
|
28
|
+
board = change.board;
|
|
29
|
+
notify();
|
|
30
|
+
return CONFIRMED;
|
|
31
|
+
},
|
|
32
|
+
getBoard: () => board,
|
|
33
|
+
getPresence: () => presence,
|
|
34
|
+
publish() {},
|
|
35
|
+
setBoard(next) {
|
|
36
|
+
board = next;
|
|
37
|
+
notify();
|
|
38
|
+
},
|
|
39
|
+
setPresence(next) {
|
|
40
|
+
presence = next;
|
|
41
|
+
notify();
|
|
42
|
+
},
|
|
43
|
+
subscribe(listener) {
|
|
44
|
+
listeners.add(listener);
|
|
45
|
+
return () => {
|
|
46
|
+
listeners.delete(listener);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
if (connection === void 0) return store;
|
|
51
|
+
return {
|
|
52
|
+
...store,
|
|
53
|
+
connection
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export { createMemoryBoardStore };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useCanvasController, useCanvasSelector } from "./canvas-context.jsx";
|
|
2
|
+
// src/canvas/canvas-actions.ts
|
|
3
|
+
const TOOL_ACTIONS = {
|
|
4
|
+
arrow: "tool-arrow",
|
|
5
|
+
comment: "tool-comment",
|
|
6
|
+
ellipse: "tool-ellipse",
|
|
7
|
+
eraser: "tool-eraser",
|
|
8
|
+
hand: "tool-hand",
|
|
9
|
+
pen: "tool-pen",
|
|
10
|
+
rectangle: "tool-rectangle",
|
|
11
|
+
select: "tool-select",
|
|
12
|
+
sticky: "tool-sticky",
|
|
13
|
+
text: "tool-text",
|
|
14
|
+
timestamp: "tool-timestamp"
|
|
15
|
+
};
|
|
16
|
+
const sameShortcut = (a, b) => a.key === b.key && a.meta === b.meta && a.alt === b.alt && a.shift === b.shift;
|
|
17
|
+
/** True when every action reads and works the same in both. */
|
|
18
|
+
function sameActions(a, b) {
|
|
19
|
+
if (a === b) return true;
|
|
20
|
+
if (a.size !== b.size) return false;
|
|
21
|
+
for (const [id, action] of a) {
|
|
22
|
+
const other = b.get(id);
|
|
23
|
+
if (other === void 0 || other.enabled !== action.enabled || other.label !== action.label || other.reason !== action.reason || other.checked !== action.checked || other.shortcuts.length !== action.shortcuts.length || other.shortcuts.some((shortcut, index) => {
|
|
24
|
+
const mine = action.shortcuts[index];
|
|
25
|
+
return mine === void 0 || !sameShortcut(shortcut, mine);
|
|
26
|
+
})) return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Every action with its label, shortcut and whether it can run now. The map
|
|
32
|
+
* keeps its identity while nothing in it changes, so a pointer move does not
|
|
33
|
+
* re-render the toolbars and menus that read it.
|
|
34
|
+
*/
|
|
35
|
+
function useCanvasActions() {
|
|
36
|
+
const controller = useCanvasController();
|
|
37
|
+
return useCanvasSelector((snapshot) => controller.actions(snapshot), sameActions);
|
|
38
|
+
}
|
|
39
|
+
function isApplePlatform() {
|
|
40
|
+
if (!("navigator" in globalThis)) return false;
|
|
41
|
+
return /mac|iphone|ipad/i.test(globalThis.navigator.userAgent);
|
|
42
|
+
}
|
|
43
|
+
/** How a key is shown and read out, where that differs from the key itself. */
|
|
44
|
+
const KEY_NAMES = /* @__PURE__ */ new Map([
|
|
45
|
+
["'", ["'", "Quote"]],
|
|
46
|
+
["-", ["-", "Minus"]],
|
|
47
|
+
["=", ["=", "Equals"]],
|
|
48
|
+
["ArrowDown", ["↓", "Down arrow"]],
|
|
49
|
+
["ArrowLeft", ["←", "Left arrow"]],
|
|
50
|
+
["ArrowRight", ["→", "Right arrow"]],
|
|
51
|
+
["ArrowUp", ["↑", "Up arrow"]],
|
|
52
|
+
["Backspace", ["⌫", "Backspace"]],
|
|
53
|
+
["Delete", ["Del", "Delete"]],
|
|
54
|
+
["Enter", ["Enter", "Enter"]],
|
|
55
|
+
["Escape", ["Esc", "Escape"]],
|
|
56
|
+
["Tab", ["Tab", "Tab"]]
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* One shortcut as keys to show and words to read out: `⌘ ⇧ Z` and
|
|
60
|
+
* "Command Shift Z" on Apple platforms, `Ctrl Shift Z` elsewhere.
|
|
61
|
+
*/
|
|
62
|
+
function shortcutKeys(shortcut, apple = isApplePlatform()) {
|
|
63
|
+
const [shown, spoken] = KEY_NAMES.get(shortcut.key) ?? [shortcut.key.toUpperCase(), shortcut.key.toUpperCase()];
|
|
64
|
+
const parts = [];
|
|
65
|
+
if (shortcut.meta) parts.push(apple ? ["⌘", "Command"] : ["Ctrl", "Control"]);
|
|
66
|
+
if (shortcut.alt) parts.push(apple ? ["⌥", "Option"] : ["Alt", "Alt"]);
|
|
67
|
+
if (shortcut.shift) parts.push(apple ? ["⇧", "Shift"] : ["Shift", "Shift"]);
|
|
68
|
+
parts.push([shown, spoken]);
|
|
69
|
+
return {
|
|
70
|
+
keys: parts.map(([key]) => key),
|
|
71
|
+
spoken: parts.map(([, word]) => word).join(" ")
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** One shortcut as a single string, for menus and the shortcuts dialog. */
|
|
75
|
+
function shortcutLabel(shortcut, apple = isApplePlatform()) {
|
|
76
|
+
return shortcutKeys(shortcut, apple).keys.join(apple ? "" : "+");
|
|
77
|
+
}
|
|
78
|
+
export { TOOL_ACTIONS, isApplePlatform, shortcutKeys, shortcutLabel, useCanvasActions };
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { board } from "./canvas-board.styles.jsx";
|
|
2
|
+
import { CanvasEmptyHint, CanvasExportButton, CanvasExportProblem, CanvasHelpButton, CanvasPresence, CanvasProblem, CanvasProposals, CanvasReadOnlyBadge, CanvasShortcutsDialog, CanvasUnsaved, CanvasZoomBar, useBoardExport } from "./canvas-chrome.jsx";
|
|
3
|
+
import { CanvasCommentBar, CanvasCommentLayer } from "./canvas-comments.jsx";
|
|
4
|
+
import { CanvasProvider, useCanvasController, useCanvasKernel, useCanvasSelector } from "./canvas-context.jsx";
|
|
5
|
+
import { CanvasCursorChat } from "./canvas-cursor-chat.jsx";
|
|
6
|
+
import { CanvasContextMenu } from "./canvas-menus.jsx";
|
|
7
|
+
import { CanvasDrawBar, CanvasStyleBar, drawing } from "./canvas-style-bar.jsx";
|
|
8
|
+
import { CanvasSurface } from "./canvas-surface.jsx";
|
|
9
|
+
import { CanvasToolRail } from "./canvas-tool-rail.jsx";
|
|
10
|
+
import { sameList } from "./equality.jsx";
|
|
11
|
+
import { assignRef } from "./handlers.jsx";
|
|
12
|
+
import { composing, isClipboardShortcut, keyOf, modifiersOf } from "./input.jsx";
|
|
13
|
+
import * as stylex from "@stylexjs/stylex";
|
|
14
|
+
import { Match, Show, Switch, children, createEffect, createMemo, createSignal, omit, onSettled } from "solid-js";
|
|
15
|
+
// src/canvas/canvas-board.tsx
|
|
16
|
+
/** Below this width the board lays its chrome out for a side panel. */
|
|
17
|
+
const COMPACT_WIDTH = 560;
|
|
18
|
+
/**
|
|
19
|
+
* Below this height the side rail can't fit: at its tallest, with the image tool, it is 451px, under the
|
|
20
|
+
* 48px top row with an 8px gap below. A shorter board, such as a phone's landscape stage, uses the compact bar.
|
|
21
|
+
*/
|
|
22
|
+
const COMPACT_HEIGHT = 520;
|
|
23
|
+
/** Below this width the top-centre bars (proposals, style) could meet the presence stack: they drop below the top row. */
|
|
24
|
+
const CROWDED_WIDTH = 960;
|
|
25
|
+
/**
|
|
26
|
+
* Screen pixels each layout's fixed chrome covers, so opening and zoom to fit centre the board in what is
|
|
27
|
+
* left: the top row (8 + 32 + 8), the side rail (8 + 44 + 8) or, on a narrow board, the bottom rail. The
|
|
28
|
+
* bars that come and go (proposals, style) add their measured height to their edge.
|
|
29
|
+
*/
|
|
30
|
+
const CHROME_INSET = {
|
|
31
|
+
compact: {
|
|
32
|
+
bottom: 60,
|
|
33
|
+
left: 0,
|
|
34
|
+
right: 0,
|
|
35
|
+
top: 48
|
|
36
|
+
},
|
|
37
|
+
crowded: {
|
|
38
|
+
bottom: 0,
|
|
39
|
+
left: 60,
|
|
40
|
+
right: 0,
|
|
41
|
+
top: 48
|
|
42
|
+
},
|
|
43
|
+
wide: {
|
|
44
|
+
bottom: 0,
|
|
45
|
+
left: 60,
|
|
46
|
+
right: 0,
|
|
47
|
+
top: 48
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/** Space between a bar and the board it leaves clear. */
|
|
51
|
+
const BAR_GAP = 8;
|
|
52
|
+
/** Screen pixels from the top of the board where the top-centre bars end, with no proposals above them. */
|
|
53
|
+
const TOP_BARS = {
|
|
54
|
+
compact: 48,
|
|
55
|
+
crowded: 96,
|
|
56
|
+
wide: 48
|
|
57
|
+
};
|
|
58
|
+
/** Screen pixels a bar takes from its edge of the board: the gap and the bar. */
|
|
59
|
+
const EDGE_BAR = 48;
|
|
60
|
+
/** The selection's bounds in screen pixels, from its items' rows (a connector's spans its ends). */
|
|
61
|
+
function selectionBounds(board, selection, view) {
|
|
62
|
+
if (selection.length === 0) return null;
|
|
63
|
+
const ids = new Set(selection);
|
|
64
|
+
let top = Number.POSITIVE_INFINITY;
|
|
65
|
+
let bottom = Number.NEGATIVE_INFINITY;
|
|
66
|
+
for (const item of board.shapes) {
|
|
67
|
+
if (!ids.has(item.id)) continue;
|
|
68
|
+
top = Math.min(top, item.y, item.y + item.h);
|
|
69
|
+
bottom = Math.max(bottom, item.y, item.y + item.h);
|
|
70
|
+
}
|
|
71
|
+
if (!Number.isFinite(top)) return null;
|
|
72
|
+
return {
|
|
73
|
+
bottom: (bottom - view.y) * view.zoom,
|
|
74
|
+
top: (top - view.y) * view.zoom
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The style bar sits at the top, pinned, so it never jumps while shapes move. When the selection sits under
|
|
79
|
+
* it and there is room below, it sits at the bottom instead, so it never covers what it styles.
|
|
80
|
+
*
|
|
81
|
+
* The side is decided when the selection changes (even mid-gesture: a press on a shape selects it before the
|
|
82
|
+
* pointer comes up, and the bar shows then), when a gesture ends (a drag may have moved the selection under
|
|
83
|
+
* the bars) and when the layout changes. Nothing else moves it: not a drag in progress, and not scrolling the
|
|
84
|
+
* view, which would move the bar (and close a menu open in it) under the viewer's pointer.
|
|
85
|
+
*
|
|
86
|
+
* `topBars` is where the top bars end, proposals included.
|
|
87
|
+
*/
|
|
88
|
+
function placeStyleBar(snapshot, layout, topBars, last) {
|
|
89
|
+
const { mode, selection, view } = snapshot.state;
|
|
90
|
+
const busy = mode._tag !== "Idle";
|
|
91
|
+
if (layout === "compact") return last;
|
|
92
|
+
if (!(!sameList(selection, last.selection) || layout !== last.layout || last.busy && !busy)) return busy === last.busy ? last : {
|
|
93
|
+
...last,
|
|
94
|
+
busy
|
|
95
|
+
};
|
|
96
|
+
const bounds = selectionBounds(snapshot.board, selection, view);
|
|
97
|
+
const height = view.h * view.zoom;
|
|
98
|
+
return {
|
|
99
|
+
busy,
|
|
100
|
+
layout,
|
|
101
|
+
selection,
|
|
102
|
+
side: bounds !== null && bounds.top < topBars && bounds.bottom < height - EDGE_BAR ? "bottom" : "top"
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Writes a menu copy's text to the system clipboard. */
|
|
106
|
+
function writeClipboardText(data) {
|
|
107
|
+
if (!("clipboard" in navigator)) return;
|
|
108
|
+
navigator.clipboard.writeText(data.text).catch(() => {});
|
|
109
|
+
}
|
|
110
|
+
/** Keys a focused control uses itself: activation, focus moves and dismissal. */
|
|
111
|
+
const CONTROL_KEYS = /* @__PURE__ */ new Set([
|
|
112
|
+
" ",
|
|
113
|
+
"ArrowDown",
|
|
114
|
+
"ArrowLeft",
|
|
115
|
+
"ArrowRight",
|
|
116
|
+
"ArrowUp",
|
|
117
|
+
"End",
|
|
118
|
+
"Enter",
|
|
119
|
+
"Escape",
|
|
120
|
+
"Home",
|
|
121
|
+
"PageDown",
|
|
122
|
+
"PageUp",
|
|
123
|
+
"Tab"
|
|
124
|
+
]);
|
|
125
|
+
/** An element that takes typed text. */
|
|
126
|
+
function typing(element) {
|
|
127
|
+
return element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement || element instanceof HTMLElement && element.isContentEditable;
|
|
128
|
+
}
|
|
129
|
+
/** Watches an element's height (0 when empty), from a ResizeObserver. */
|
|
130
|
+
function observeHeight(element, set) {
|
|
131
|
+
const measure = () => set(element.offsetHeight);
|
|
132
|
+
measure();
|
|
133
|
+
const observer = new ResizeObserver(measure);
|
|
134
|
+
observer.observe(element);
|
|
135
|
+
return () => observer.disconnect();
|
|
136
|
+
}
|
|
137
|
+
function BoardChrome(props) {
|
|
138
|
+
const controller = useCanvasController();
|
|
139
|
+
const compact = () => props.layout === "compact";
|
|
140
|
+
const status = children(() => props.status);
|
|
141
|
+
const exporter = useBoardExport({
|
|
142
|
+
canvas: () => props.canvas,
|
|
143
|
+
title: () => props.label
|
|
144
|
+
});
|
|
145
|
+
const tool = useCanvasSelector((snapshot) => snapshot.state.tool);
|
|
146
|
+
const selected = useCanvasSelector((snapshot) => snapshot.state.selection.length > 0);
|
|
147
|
+
const [help, setHelp] = createSignal(false);
|
|
148
|
+
const [chatting, setChatting] = createSignal(false);
|
|
149
|
+
const [showResolved, setShowResolved] = createSignal(false);
|
|
150
|
+
const draws = () => drawing(tool());
|
|
151
|
+
const [topHeight, setTopHeight] = createSignal(0);
|
|
152
|
+
const [bottomHeight, setBottomHeight] = createSignal(0);
|
|
153
|
+
/** The height of the proposals bar atop the top stack, with its gap; 0 without one. */
|
|
154
|
+
const [proposalsHeight, setProposalsHeight] = createSignal(0);
|
|
155
|
+
let placement = {
|
|
156
|
+
busy: false,
|
|
157
|
+
layout: "wide",
|
|
158
|
+
selection: [],
|
|
159
|
+
side: "top"
|
|
160
|
+
};
|
|
161
|
+
const barSide = useCanvasSelector((snapshot) => {
|
|
162
|
+
const topBars = TOP_BARS[props.layout] + proposalsHeight();
|
|
163
|
+
placement = placeStyleBar(snapshot, props.layout, topBars, placement);
|
|
164
|
+
return placement.side;
|
|
165
|
+
});
|
|
166
|
+
let keys;
|
|
167
|
+
let top;
|
|
168
|
+
let bottom;
|
|
169
|
+
onSettled(() => {
|
|
170
|
+
const stops = [top === void 0 ? () => {} : observeHeight(top, (height) => {
|
|
171
|
+
setTopHeight(height);
|
|
172
|
+
const proposals = top?.querySelector("[data-canvas-proposals]");
|
|
173
|
+
const below = proposals === null || proposals === void 0 || top === void 0 ? 0 : proposals.getBoundingClientRect().bottom - top.getBoundingClientRect().top + BAR_GAP;
|
|
174
|
+
setProposalsHeight(Math.round(below));
|
|
175
|
+
}), bottom === void 0 ? () => {} : observeHeight(bottom, setBottomHeight)];
|
|
176
|
+
return () => {
|
|
177
|
+
for (const stop of stops) stop();
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
const inset = createMemo(() => {
|
|
181
|
+
const fixed = CHROME_INSET[props.layout];
|
|
182
|
+
const topStart = props.layout === "wide" ? BAR_GAP : 48;
|
|
183
|
+
return {
|
|
184
|
+
...fixed,
|
|
185
|
+
bottom: bottomHeight() > 0 ? Math.max(fixed.bottom, bottomHeight() + 16) : fixed.bottom,
|
|
186
|
+
top: topHeight() > 0 ? Math.max(fixed.top, topStart + topHeight() + BAR_GAP) : fixed.top
|
|
187
|
+
};
|
|
188
|
+
}, { equals: (a, b) => a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left });
|
|
189
|
+
createEffect(() => inset(), (next) => {
|
|
190
|
+
queueMicrotask(() => controller.setInset(next));
|
|
191
|
+
});
|
|
192
|
+
const onKeyDown = (event) => {
|
|
193
|
+
const target = event.target;
|
|
194
|
+
if (event.defaultPrevented || !(target instanceof Element) || !keys?.contains(target) || typing(target)) return;
|
|
195
|
+
if (target.closest("[role=menu], [role=dialog], [popover]") !== null) return;
|
|
196
|
+
if (event.key === "?" || event.key === "/" && (event.metaKey || event.ctrlKey)) {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
setHelp((open) => !open);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (event.key === "/" && !event.metaKey && !event.ctrlKey && !event.altKey && !composing(event)) {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
setChatting(true);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (target.closest("[data-slot=\"canvas-surface\"]") !== null || CONTROL_KEYS.has(event.key) || composing(event) || isClipboardShortcut(event)) return;
|
|
207
|
+
if (controller.dispatch({
|
|
208
|
+
_tag: "KeyDown",
|
|
209
|
+
key: keyOf(event),
|
|
210
|
+
modifiers: modifiersOf(event)
|
|
211
|
+
}).handled) event.preventDefault();
|
|
212
|
+
};
|
|
213
|
+
const surface = () => keys?.querySelector("[data-slot=\"canvas-surface\"]") ?? void 0;
|
|
214
|
+
const editorOf = (event) => {
|
|
215
|
+
if (controller.getSnapshot().state.mode._tag !== "EditingText") return null;
|
|
216
|
+
const target = event.target;
|
|
217
|
+
if (!(target instanceof Element) || target.closest("button:not([aria-haspopup])") === null) return null;
|
|
218
|
+
return surface()?.querySelector("[data-slot=\"canvas-text-editor\"]") ?? null;
|
|
219
|
+
};
|
|
220
|
+
const keepTyping = (event) => {
|
|
221
|
+
if (editorOf(event) !== null) event.preventDefault();
|
|
222
|
+
};
|
|
223
|
+
const backToTyping = (event) => editorOf(event)?.focus({ preventScroll: true });
|
|
224
|
+
return <div ref={(element) => keys = element} {...stylex.attrs(board.keys)} role="presentation" onKeyDown={onKeyDown}>
|
|
225
|
+
<CanvasContextMenu>
|
|
226
|
+
<CanvasSurface label={props.label ?? "Board"} />
|
|
227
|
+
</CanvasContextMenu>
|
|
228
|
+
<Show when={props.comments}>
|
|
229
|
+
{(comments) => <CanvasCommentLayer comments={comments()} showResolved={showResolved()} />}
|
|
230
|
+
</Show>
|
|
231
|
+
<CanvasCursorChat open={chatting()} onClose={(by) => {
|
|
232
|
+
setChatting(false);
|
|
233
|
+
if (by !== "blur") surface()?.focus({ preventScroll: true });
|
|
234
|
+
}} />
|
|
235
|
+
<CanvasEmptyHint compact={compact()} />
|
|
236
|
+
{}
|
|
237
|
+
<div {...stylex.attrs(board.statusRow, compact() ? board.statusRowCompact : board.statusRowWide)} data-canvas-area>
|
|
238
|
+
{}
|
|
239
|
+
<Show when={status.toArray().length > 0} fallback={<CanvasReadOnlyBadge />}>
|
|
240
|
+
{status()}
|
|
241
|
+
</Show>
|
|
242
|
+
<CanvasUnsaved />
|
|
243
|
+
<CanvasProblem />
|
|
244
|
+
<CanvasExportProblem exporter={exporter} />
|
|
245
|
+
</div>
|
|
246
|
+
<div {...stylex.attrs(board.corner)}>
|
|
247
|
+
<CanvasPresence compact={compact()} />
|
|
248
|
+
<Show when={compact()}>
|
|
249
|
+
<CanvasZoomBar compact />
|
|
250
|
+
</Show>
|
|
251
|
+
<CanvasExportButton exporter={exporter} />
|
|
252
|
+
<CanvasHelpButton onOpen={() => setHelp(true)} />
|
|
253
|
+
</div>
|
|
254
|
+
<div ref={(element) => top = element} {...stylex.attrs(board.topBars, props.layout === "wide" ? board.topBarsWide : board.topBarsBelow)} data-canvas-area onMouseDown={keepTyping} onClick={backToTyping}>
|
|
255
|
+
<CanvasProposals />
|
|
256
|
+
<Switch>
|
|
257
|
+
<Match when={tool() === "comment" ? props.comments : void 0}>
|
|
258
|
+
{(comments) => <CanvasCommentBar comments={comments()} showResolved={showResolved()} onShowResolvedChange={setShowResolved} />}
|
|
259
|
+
</Match>
|
|
260
|
+
<Match when={draws()}>
|
|
261
|
+
<CanvasDrawBar />
|
|
262
|
+
</Match>
|
|
263
|
+
<Match when={!compact() && barSide() === "top"}>
|
|
264
|
+
<CanvasStyleBar />
|
|
265
|
+
</Match>
|
|
266
|
+
</Switch>
|
|
267
|
+
</div>
|
|
268
|
+
<div ref={(element) => bottom = element} {...stylex.attrs(board.bottomBar)} data-slot="canvas-bottom-bar" data-canvas-area onMouseDown={keepTyping} onClick={backToTyping}>
|
|
269
|
+
<Show when={compact()} fallback={<Show when={!draws() && barSide() === "bottom"}>
|
|
270
|
+
<CanvasStyleBar edge="bottom" />
|
|
271
|
+
</Show>}>
|
|
272
|
+
<Show when={selected() && !draws()} fallback={<CanvasToolRail compact />}>
|
|
273
|
+
<CanvasStyleBar compact />
|
|
274
|
+
</Show>
|
|
275
|
+
</Show>
|
|
276
|
+
</div>
|
|
277
|
+
<Show when={!compact()}>
|
|
278
|
+
<div {...stylex.attrs(board.rail)}>
|
|
279
|
+
<CanvasToolRail />
|
|
280
|
+
</div>
|
|
281
|
+
<div {...stylex.attrs(board.zoom)}>
|
|
282
|
+
<CanvasZoomBar />
|
|
283
|
+
</div>
|
|
284
|
+
</Show>
|
|
285
|
+
<CanvasShortcutsDialog board={() => keys} open={help()} onOpenChange={setHelp} />
|
|
286
|
+
</div>;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* A whiteboard: the surface with its tools, style, zoom, presence, agent proposals, comments, context menu
|
|
290
|
+
* and shortcuts, and images when the app gives it `assets`. It fills its parent, moves its top-centre bars
|
|
291
|
+
* below the top row under 960px wide, and lays its chrome out for a side panel under 560px.
|
|
292
|
+
*/
|
|
293
|
+
function CanvasBoard(props) {
|
|
294
|
+
const rest = omit(props, "store", "assets", "canvas", "comments", "label", "readOnly", "initialView", "status", "onError", "onClipboard", "class", "ref");
|
|
295
|
+
const [layout, setLayout] = createSignal("wide");
|
|
296
|
+
let root;
|
|
297
|
+
onSettled(() => {
|
|
298
|
+
const element = root;
|
|
299
|
+
if (element === void 0) return;
|
|
300
|
+
const measure = () => {
|
|
301
|
+
const { height, width } = element.getBoundingClientRect();
|
|
302
|
+
if (width === 0 || height === 0) return;
|
|
303
|
+
setLayout(width < COMPACT_WIDTH || height < COMPACT_HEIGHT ? "compact" : width < CROWDED_WIDTH ? "crowded" : "wide");
|
|
304
|
+
};
|
|
305
|
+
measure();
|
|
306
|
+
const observer = new ResizeObserver(measure);
|
|
307
|
+
observer.observe(element);
|
|
308
|
+
return () => observer.disconnect();
|
|
309
|
+
});
|
|
310
|
+
const kernel = useCanvasKernel();
|
|
311
|
+
const canvas = createMemo(() => props.canvas ?? (kernel().status === "ready" ? kernel().canvas : null));
|
|
312
|
+
const failed = () => props.canvas === void 0 && kernel().status === "failed";
|
|
313
|
+
return <div {...rest} ref={(element) => {
|
|
314
|
+
root = element;
|
|
315
|
+
assignRef(props.ref, element);
|
|
316
|
+
}} class={[stylex.props(board.root).className, props.class]} data-compact={layout() === "compact" ? "" : void 0} data-layout={layout()} data-slot="canvas-board">
|
|
317
|
+
<Show when={canvas()} fallback={<p {...stylex.attrs(board.loading, failed() ? null : board.hidden)} role="status">
|
|
318
|
+
{failed() ? "The board could not load. Reload the page to try again." : "Loading board"}
|
|
319
|
+
</p>}>
|
|
320
|
+
{(loaded) => <CanvasProvider canvas={loaded()} store={props.store} assets={props.assets} comments={props.comments?.canComment === true} initialView={props.initialView} onClipboard={(data) => (props.onClipboard ?? writeClipboardText)(data)} onError={(error) => props.onError?.(error)} readOnly={props.readOnly ?? false}>
|
|
321
|
+
<BoardChrome canvas={loaded()} comments={props.comments} label={props.label} layout={layout()} status={props.status} />
|
|
322
|
+
</CanvasProvider>}
|
|
323
|
+
</Show>
|
|
324
|
+
</div>;
|
|
325
|
+
}
|
|
326
|
+
export { CanvasBoard };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import "@stylexjs/stylex";
|
|
2
|
+
// src/canvas/canvas-board.styles.ts
|
|
3
|
+
const board = {
|
|
4
|
+
root: {
|
|
5
|
+
kVAEAm: "x1n2onr6",
|
|
6
|
+
kHBbk8: "xc8icb0",
|
|
7
|
+
kzqmXN: "xh8yej3",
|
|
8
|
+
kZKoxP: "x5yr21d",
|
|
9
|
+
kVQacm: "xb3r6kr",
|
|
10
|
+
kaIpWk: "x1pjcqnp",
|
|
11
|
+
kWkggS: "xm9f0jk",
|
|
12
|
+
kMwMTN: "x1yjpjgc",
|
|
13
|
+
kMv6JI: "x13rcfk",
|
|
14
|
+
$$css: true
|
|
15
|
+
},
|
|
16
|
+
keys: {
|
|
17
|
+
k1xSpc: "xjp7ctv",
|
|
18
|
+
kaIpWk: "x1pjcqnp",
|
|
19
|
+
$$css: true
|
|
20
|
+
},
|
|
21
|
+
statusRow: {
|
|
22
|
+
kVAEAm: "x10l6tqk",
|
|
23
|
+
k87sOh: "xagm1g7",
|
|
24
|
+
kbCHJM: "xw8ulaf",
|
|
25
|
+
k1xSpc: "x78zum5",
|
|
26
|
+
kGNEyG: "x6s0dn4",
|
|
27
|
+
kOIVth: "x8rwxmg",
|
|
28
|
+
kZKoxP: "xettwda",
|
|
29
|
+
k7Eaqz: "xeuugli",
|
|
30
|
+
kfzvcC: "x47corl",
|
|
31
|
+
$$css: true
|
|
32
|
+
},
|
|
33
|
+
statusRowWide: {
|
|
34
|
+
kCIrl2: "x5avfsc",
|
|
35
|
+
$$css: true
|
|
36
|
+
},
|
|
37
|
+
statusRowCompact: {
|
|
38
|
+
kCIrl2: "x1uqxd5b",
|
|
39
|
+
$$css: true
|
|
40
|
+
},
|
|
41
|
+
corner: {
|
|
42
|
+
kVAEAm: "x10l6tqk",
|
|
43
|
+
k87sOh: "xagm1g7",
|
|
44
|
+
kCIrl2: "xbux4qb",
|
|
45
|
+
k1xSpc: "x78zum5",
|
|
46
|
+
kGNEyG: "x6s0dn4",
|
|
47
|
+
kOIVth: "x8rwxmg",
|
|
48
|
+
kZKoxP: "xettwda",
|
|
49
|
+
$$css: true
|
|
50
|
+
},
|
|
51
|
+
topBars: {
|
|
52
|
+
kVAEAm: "x10l6tqk",
|
|
53
|
+
kkqhue: "xkmtfez",
|
|
54
|
+
k1xSpc: "x78zum5",
|
|
55
|
+
kXwgrk: "xdt5ytf",
|
|
56
|
+
kGNEyG: "x6s0dn4",
|
|
57
|
+
kOIVth: "x8rwxmg",
|
|
58
|
+
kfzvcC: "x47corl",
|
|
59
|
+
$$css: true
|
|
60
|
+
},
|
|
61
|
+
topBarsWide: {
|
|
62
|
+
k87sOh: "xagm1g7",
|
|
63
|
+
$$css: true
|
|
64
|
+
},
|
|
65
|
+
topBarsBelow: {
|
|
66
|
+
k87sOh: "x82b3cp",
|
|
67
|
+
$$css: true
|
|
68
|
+
},
|
|
69
|
+
bottomBar: {
|
|
70
|
+
kVAEAm: "x10l6tqk",
|
|
71
|
+
kkqhue: "xkmtfez",
|
|
72
|
+
krVfgx: "xz22vgf",
|
|
73
|
+
k1xSpc: "x78zum5",
|
|
74
|
+
kjj79g: "xl56j7k",
|
|
75
|
+
kfzvcC: "x47corl",
|
|
76
|
+
$$css: true
|
|
77
|
+
},
|
|
78
|
+
rail: {
|
|
79
|
+
kVAEAm: "x10l6tqk",
|
|
80
|
+
k87sOh: "xwa60dl",
|
|
81
|
+
kbCHJM: "xw8ulaf",
|
|
82
|
+
k3aq6I: "x1cb1t30",
|
|
83
|
+
$$css: true
|
|
84
|
+
},
|
|
85
|
+
zoom: {
|
|
86
|
+
kVAEAm: "x10l6tqk",
|
|
87
|
+
kCIrl2: "xbux4qb",
|
|
88
|
+
krVfgx: "xz22vgf",
|
|
89
|
+
$$css: true
|
|
90
|
+
},
|
|
91
|
+
loading: {
|
|
92
|
+
kVAEAm: "x10l6tqk",
|
|
93
|
+
kpwlN0: "x10a8y8t",
|
|
94
|
+
kZKoxP: "xg7h5cd",
|
|
95
|
+
kogj98: "x1bpp3o7",
|
|
96
|
+
k9WMMc: "x2b8uid",
|
|
97
|
+
kGuDYH: "x409pna",
|
|
98
|
+
kMwMTN: "xe2mk2a",
|
|
99
|
+
$$css: true
|
|
100
|
+
},
|
|
101
|
+
hidden: {
|
|
102
|
+
kzqmXN: "x1i1rx1s",
|
|
103
|
+
kZKoxP: "xjm9jq1",
|
|
104
|
+
kVQacm: "xb3r6kr",
|
|
105
|
+
kz4h6p: "x1hyvwdk",
|
|
106
|
+
khDVqt: "xuxw1ft",
|
|
107
|
+
$$css: true
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
export { board };
|