@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,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a host keeps a board's image files. The board stores only an opaque
|
|
3
|
+
* `asset` reference on each image shape; the host uploads files, turns
|
|
4
|
+
* references into URLs and says when a URL changes, such as when a signed
|
|
5
|
+
* one expires. Leave `assets` out and the board has no image tool.
|
|
6
|
+
*/
|
|
7
|
+
/** What the board can draw for an asset right now. */
|
|
8
|
+
type CanvasAssetSource = {
|
|
9
|
+
readonly status: "ready";
|
|
10
|
+
readonly src: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly status: "pending";
|
|
13
|
+
} | {
|
|
14
|
+
readonly status: "failed";
|
|
15
|
+
/** `forbidden`: the viewer may not see it; `missing`: it is gone or broken. */
|
|
16
|
+
readonly reason: "forbidden" | "missing";
|
|
17
|
+
};
|
|
18
|
+
type CanvasUploadOptions = {
|
|
19
|
+
/** Call with the fraction sent so far, from 0 to 1. */
|
|
20
|
+
readonly onProgress: (fraction: number) => void;
|
|
21
|
+
/** Aborted when the viewer cancels or the board unmounts. */
|
|
22
|
+
readonly signal: AbortSignal;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A rejection written for the person adding the image: `message` is shown
|
|
26
|
+
* on the failed placeholder and announced as written, and `retryable` says
|
|
27
|
+
* whether trying again can help. A network drop is retryable; a file too
|
|
28
|
+
* large, a type the host does not store, a board at its image limit, or no
|
|
29
|
+
* access is not, so the board offers only Remove. Any `Error` with a
|
|
30
|
+
* boolean `retryable` counts. Any other rejection shows generic copy and
|
|
31
|
+
* offers Retry.
|
|
32
|
+
*/
|
|
33
|
+
type CanvasUploadFailure = Error & {
|
|
34
|
+
readonly retryable: boolean;
|
|
35
|
+
};
|
|
36
|
+
type CanvasAssets = {
|
|
37
|
+
/**
|
|
38
|
+
* Store a file and resolve with its asset reference. Reject to fail the
|
|
39
|
+
* upload, with a `CanvasUploadFailure` to say why.
|
|
40
|
+
*/
|
|
41
|
+
readonly upload: (file: File, options: CanvasUploadOptions) => Promise<{
|
|
42
|
+
readonly asset: string;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* A source for `asset`, at least `width` device pixels wide; `width` comes
|
|
46
|
+
* in steps, so a host can pick a size. Return the same object until it
|
|
47
|
+
* changes, and call `subscribe`'s listeners when it does.
|
|
48
|
+
*/
|
|
49
|
+
readonly resolve: (asset: string, hint: {
|
|
50
|
+
readonly width: number;
|
|
51
|
+
}) => CanvasAssetSource;
|
|
52
|
+
/** Called when any `resolve` result may have changed. Returns an unsubscribe. */
|
|
53
|
+
readonly subscribe?: (listener: () => void) => () => void;
|
|
54
|
+
/**
|
|
55
|
+
* MIME types the host stores, such as `image/png`. The file picker offers
|
|
56
|
+
* them, and the board turns other files away before sending them.
|
|
57
|
+
*/
|
|
58
|
+
readonly accept: readonly string[];
|
|
59
|
+
/**
|
|
60
|
+
* The largest file the host stores, in bytes, checked before sending. The
|
|
61
|
+
* refusal states it in decimal units: 10,000,000 reads "10 MB".
|
|
62
|
+
*/
|
|
63
|
+
readonly maxBytes: number;
|
|
64
|
+
/** The original file to open or download, when the host offers one. */
|
|
65
|
+
readonly original?: (asset: string) => {
|
|
66
|
+
readonly href: string;
|
|
67
|
+
readonly name: string;
|
|
68
|
+
} | null;
|
|
69
|
+
/**
|
|
70
|
+
* Store an image from a dropped link. Without it, links dropped on the
|
|
71
|
+
* board are ignored. It rejects as `upload` does.
|
|
72
|
+
*/
|
|
73
|
+
readonly fromUrl?: (url: string, options: {
|
|
74
|
+
readonly signal: AbortSignal;
|
|
75
|
+
}) => Promise<{
|
|
76
|
+
readonly asset: string;
|
|
77
|
+
readonly naturalW: number;
|
|
78
|
+
readonly naturalH: number;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
/** The width hint steps: powers of two from 256 to 4096 device pixels. */
|
|
82
|
+
declare function widthStep(pixels: number): number;
|
|
83
|
+
/** Why a file is not uploaded, by the host's rules, or null when it can be. */
|
|
84
|
+
declare function fileProblem(file: File, assets: CanvasAssets): string | null;
|
|
85
|
+
/** What the board shows for a failed upload. */
|
|
86
|
+
type UploadFailure = {
|
|
87
|
+
readonly message: string | null;
|
|
88
|
+
readonly retryable: boolean;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* What a rejected upload says to the viewer: the host's message and whether
|
|
92
|
+
* to offer Retry, or no message and Retry for a rejection not written for
|
|
93
|
+
* people.
|
|
94
|
+
*/
|
|
95
|
+
declare function failureOf(cause: unknown): UploadFailure;
|
|
96
|
+
/**
|
|
97
|
+
* A size in decimal units, as hosts state limits, to one decimal at most:
|
|
98
|
+
* 10,000,000 bytes is "10 MB" and 5,242,880 is "5.2 MB".
|
|
99
|
+
*/
|
|
100
|
+
declare function formatBytes(bytes: number): string;
|
|
101
|
+
/**
|
|
102
|
+
* An image file's size as it displays, with EXIF orientation applied, read
|
|
103
|
+
* from the browser's own decoder in a detached image; null when it has no
|
|
104
|
+
* intrinsic size, such as some SVGs, or cannot be read in time.
|
|
105
|
+
*/
|
|
106
|
+
declare function naturalSize(file: Blob): Promise<{
|
|
107
|
+
readonly w: number;
|
|
108
|
+
readonly h: number;
|
|
109
|
+
} | null>;
|
|
110
|
+
export { failureOf, fileProblem, formatBytes, naturalSize, widthStep };
|
|
111
|
+
export type { CanvasAssets, CanvasAssetSource, CanvasUploadFailure, CanvasUploadOptions };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { BoardJson, CommandErrorJson, EditorPresenceJson, PlanJson, PresenceJson, TransactionJson } from "../kernel/index.js";
|
|
2
|
+
/** A transaction the viewer's editor planned, and the board with it applied. */
|
|
3
|
+
type CanvasCommit = {
|
|
4
|
+
readonly transaction: TransactionJson;
|
|
5
|
+
readonly plan: PlanJson;
|
|
6
|
+
/** `kernel.apply(board, plan)`: show it right away. */
|
|
7
|
+
readonly board: BoardJson;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* How the store settled a commit: kept for good, or refused. A refusal
|
|
11
|
+
* names the kernel's error when there is one, such as `Claimed` when someone
|
|
12
|
+
* else is editing the shape, or null when the backend gave no reason.
|
|
13
|
+
*/
|
|
14
|
+
type CanvasCommitResult = {
|
|
15
|
+
readonly _tag: "Confirmed";
|
|
16
|
+
} | {
|
|
17
|
+
readonly _tag: "Refused";
|
|
18
|
+
readonly error: CommandErrorJson | null;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Where a board lives. The board owns no kernel: the controller plans and
|
|
22
|
+
* applies, and the store keeps the result, sends it on, and tells the
|
|
23
|
+
* controller when the board or other people's presence changes.
|
|
24
|
+
*/
|
|
25
|
+
type CanvasBoardStore = {
|
|
26
|
+
/** The principal the viewer acts as. Transactions and presence carry it. */
|
|
27
|
+
readonly actor: string;
|
|
28
|
+
/**
|
|
29
|
+
* This editor's connection: one id per open board, such as the id the
|
|
30
|
+
* sync layer's server assigned this tab. It becomes the editor's session,
|
|
31
|
+
* so a claim from this tab blocks the viewer's other tabs ("You're editing
|
|
32
|
+
* this in another tab") and never this one. Read once, when the board
|
|
33
|
+
* mounts; mount the board after the id is known. Left out, the board makes
|
|
34
|
+
* one up and passes it to `publish`.
|
|
35
|
+
*/
|
|
36
|
+
readonly connection?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The board now. It returns the same object until the board changes, as
|
|
39
|
+
* `useSyncExternalStore` snapshots do; a new object each call redraws the
|
|
40
|
+
* board for nothing.
|
|
41
|
+
*/
|
|
42
|
+
readonly getBoard: () => BoardJson;
|
|
43
|
+
/**
|
|
44
|
+
* Everyone else on the board: people and agents, and the viewer's other
|
|
45
|
+
* tabs (same `actor`, another `connection`), never this connection. The
|
|
46
|
+
* same array until someone joins, leaves or moves.
|
|
47
|
+
*/
|
|
48
|
+
readonly getPresence: () => readonly PresenceJson[];
|
|
49
|
+
/** Called after the board or presence changes. Returns an unsubscribe. */
|
|
50
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Keep a transaction the editor planned and applied. By the time it
|
|
53
|
+
* returns, `getBoard` includes it. Return the result when it is already
|
|
54
|
+
* known, or a promise that settles once with it when the backend confirms
|
|
55
|
+
* or refuses. A refused change must leave `getBoard` before the result
|
|
56
|
+
* arrives; the editor then drops its undo step and says why.
|
|
57
|
+
*/
|
|
58
|
+
readonly commit: (commit: CanvasCommit) => CanvasCommitResult | Promise<CanvasCommitResult>;
|
|
59
|
+
/**
|
|
60
|
+
* The viewer's cursor, selection, viewport, who they follow and what they
|
|
61
|
+
* are doing, for others to see, at most once a frame. Send it as a
|
|
62
|
+
* `PresenceJson` with `actor`, the viewer's name and kind, and
|
|
63
|
+
* `connection`: this editor's, as given here. Publish all of it: claims,
|
|
64
|
+
* following, edge chips and upload placeholders on other screens read it.
|
|
65
|
+
*/
|
|
66
|
+
readonly publish: (presence: EditorPresenceJson, connection: string) => void;
|
|
67
|
+
};
|
|
68
|
+
type MemoryBoardStore = CanvasBoardStore & {
|
|
69
|
+
/** Replace the board, such as with a change made outside the editor. */
|
|
70
|
+
readonly setBoard: (board: BoardJson) => void;
|
|
71
|
+
/** Replace everyone else's presence. */
|
|
72
|
+
readonly setPresence: (presence: readonly PresenceJson[]) => void;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* A board in memory, for a single-player board, tests and examples, and the
|
|
76
|
+
* reference for the store contract: it keeps every commit, confirms it at
|
|
77
|
+
* once and refuses none.
|
|
78
|
+
*/
|
|
79
|
+
declare function createMemoryBoardStore({ actor, board: initialBoard, connection, presence: initialPresence, }: {
|
|
80
|
+
readonly actor: string;
|
|
81
|
+
readonly connection?: string;
|
|
82
|
+
readonly board?: BoardJson;
|
|
83
|
+
readonly presence?: readonly PresenceJson[];
|
|
84
|
+
}): MemoryBoardStore;
|
|
85
|
+
export { createMemoryBoardStore };
|
|
86
|
+
export type { CanvasBoardStore, CanvasCommit, CanvasCommitResult, MemoryBoardStore };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ActionIdJson, ActionJson, ShortcutJson, ToolJson } from "../kernel/index.js";
|
|
2
|
+
import type { Accessor } from "solid-js";
|
|
3
|
+
declare const TOOL_ACTIONS: Record<ToolJson, ActionIdJson>;
|
|
4
|
+
/**
|
|
5
|
+
* Every action with its label, shortcut and whether it can run now. The map
|
|
6
|
+
* keeps its identity while nothing in it changes, so a pointer move does not
|
|
7
|
+
* re-render the toolbars and menus that read it.
|
|
8
|
+
*/
|
|
9
|
+
declare function useCanvasActions(): Accessor<ReadonlyMap<ActionIdJson, ActionJson>>;
|
|
10
|
+
declare function isApplePlatform(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* One shortcut as keys to show and words to read out: `⌘ ⇧ Z` and
|
|
13
|
+
* "Command Shift Z" on Apple platforms, `Ctrl Shift Z` elsewhere.
|
|
14
|
+
*/
|
|
15
|
+
declare function shortcutKeys(shortcut: ShortcutJson, apple?: boolean): {
|
|
16
|
+
keys: string[];
|
|
17
|
+
spoken: string;
|
|
18
|
+
};
|
|
19
|
+
/** One shortcut as a single string, for menus and the shortcuts dialog. */
|
|
20
|
+
declare function shortcutLabel(shortcut: ShortcutJson, apple?: boolean): string;
|
|
21
|
+
export { isApplePlatform, shortcutKeys, shortcutLabel, TOOL_ACTIONS, useCanvasActions };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { CanvasAssets } from "./assets.js";
|
|
3
|
+
import type { CanvasBoardStore } from "./board-store.js";
|
|
4
|
+
import { type CanvasProviderProps } from "./canvas-context.js";
|
|
5
|
+
import type { CanvasComments } from "./comments.js";
|
|
6
|
+
import type { CanvasKernel } from "./kernel.js";
|
|
7
|
+
export interface CanvasBoardProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "onError"> {
|
|
8
|
+
/** The board's data, which the app owns: commit each change to a backend and confirm or refuse it. */
|
|
9
|
+
store: CanvasBoardStore;
|
|
10
|
+
/**
|
|
11
|
+
* Where the board keeps image files. With it the board has an image tool and takes dropped and pasted
|
|
12
|
+
* images; without it, it has neither.
|
|
13
|
+
*/
|
|
14
|
+
assets?: CanvasAssets;
|
|
15
|
+
/** A loaded kernel (`loadCanvasKernel`); the board loads one itself when this is left out. */
|
|
16
|
+
canvas?: CanvasKernel;
|
|
17
|
+
/**
|
|
18
|
+
* Comment threads on the board and what the viewer may do with them. With it the board has a comment
|
|
19
|
+
* tool (C) and shows each thread as a pin; without it, it has neither. The app keeps the threads and
|
|
20
|
+
* carries out each `onCommand`.
|
|
21
|
+
*/
|
|
22
|
+
comments?: CanvasComments;
|
|
23
|
+
/**
|
|
24
|
+
* Names the board, such as "Retro board": for assistive technology, and as the file name of
|
|
25
|
+
* **Export as PNG** ("canvas.png" without one).
|
|
26
|
+
*/
|
|
27
|
+
label?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Only Select and Hand work; a "View only" badge shows and only presence is sent.
|
|
30
|
+
* @defaultValue false
|
|
31
|
+
*/
|
|
32
|
+
readOnly?: boolean;
|
|
33
|
+
/** Where the view starts. Left out, the board fits its shapes in the area the chrome leaves clear. */
|
|
34
|
+
initialView?: CanvasProviderProps["initialView"];
|
|
35
|
+
/**
|
|
36
|
+
* The app's word on the board's state, such as its connection, in the board's top-left row; build it
|
|
37
|
+
* with `CanvasStatus`. It stands in for the "View only" badge, so say why the board is read-only when it is.
|
|
38
|
+
*/
|
|
39
|
+
status?: JSX.Element;
|
|
40
|
+
/** A change was refused, after the board told the viewer why. For logging. */
|
|
41
|
+
onError?: CanvasProviderProps["onError"];
|
|
42
|
+
/**
|
|
43
|
+
* Copies from the menus. By default the text goes to the system clipboard; the board keeps the shapes
|
|
44
|
+
* for pasting back.
|
|
45
|
+
*/
|
|
46
|
+
onClipboard?: CanvasProviderProps["onClipboard"];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A whiteboard: the surface with its tools, style, zoom, presence, agent proposals, comments, context menu
|
|
50
|
+
* and shortcuts, and images when the app gives it `assets`. It fills its parent, moves its top-centre bars
|
|
51
|
+
* below the top row under 960px wide, and lays its chrome out for a side panel under 560px.
|
|
52
|
+
*/
|
|
53
|
+
export declare function CanvasBoard(props: CanvasBoardProps): JSX.Element;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as stylex from "@stylexjs/stylex";
|
|
2
|
+
export declare const board: Readonly<{
|
|
3
|
+
readonly root: Readonly<{
|
|
4
|
+
readonly position: stylex.StyleXClassNameFor<"position", "relative">;
|
|
5
|
+
readonly isolation: stylex.StyleXClassNameFor<"isolation", "isolate">;
|
|
6
|
+
readonly width: stylex.StyleXClassNameFor<"width", "100%">;
|
|
7
|
+
readonly height: stylex.StyleXClassNameFor<"height", "100%">;
|
|
8
|
+
readonly overflow: stylex.StyleXClassNameFor<"overflow", "hidden">;
|
|
9
|
+
readonly borderRadius: stylex.StyleXClassNameFor<"borderRadius", "inherit">;
|
|
10
|
+
readonly backgroundColor: stylex.StyleXClassNameFor<"backgroundColor", string>;
|
|
11
|
+
readonly color: stylex.StyleXClassNameFor<"color", string>;
|
|
12
|
+
readonly fontFamily: stylex.StyleXClassNameFor<"fontFamily", string>;
|
|
13
|
+
}>;
|
|
14
|
+
readonly keys: Readonly<{
|
|
15
|
+
readonly display: stylex.StyleXClassNameFor<"display", "contents">;
|
|
16
|
+
readonly borderRadius: stylex.StyleXClassNameFor<"borderRadius", "inherit">;
|
|
17
|
+
}>;
|
|
18
|
+
readonly statusRow: Readonly<{
|
|
19
|
+
readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
|
|
20
|
+
readonly top: stylex.StyleXClassNameFor<"top", string>;
|
|
21
|
+
readonly left: stylex.StyleXClassNameFor<"left", string>;
|
|
22
|
+
readonly display: stylex.StyleXClassNameFor<"display", "flex">;
|
|
23
|
+
readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
|
|
24
|
+
readonly gap: stylex.StyleXClassNameFor<"gap", string>;
|
|
25
|
+
readonly height: stylex.StyleXClassNameFor<"height", "2rem">;
|
|
26
|
+
readonly minWidth: stylex.StyleXClassNameFor<"minWidth", 0>;
|
|
27
|
+
readonly pointerEvents: stylex.StyleXClassNameFor<"pointerEvents", "none">;
|
|
28
|
+
}>;
|
|
29
|
+
readonly statusRowWide: Readonly<{
|
|
30
|
+
readonly right: stylex.StyleXClassNameFor<"right", "16.5rem">;
|
|
31
|
+
}>;
|
|
32
|
+
readonly statusRowCompact: Readonly<{
|
|
33
|
+
readonly right: stylex.StyleXClassNameFor<"right", "15.5rem">;
|
|
34
|
+
}>;
|
|
35
|
+
readonly corner: Readonly<{
|
|
36
|
+
readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
|
|
37
|
+
readonly top: stylex.StyleXClassNameFor<"top", string>;
|
|
38
|
+
readonly right: stylex.StyleXClassNameFor<"right", string>;
|
|
39
|
+
readonly display: stylex.StyleXClassNameFor<"display", "flex">;
|
|
40
|
+
readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
|
|
41
|
+
readonly gap: stylex.StyleXClassNameFor<"gap", string>;
|
|
42
|
+
readonly height: stylex.StyleXClassNameFor<"height", "2rem">;
|
|
43
|
+
}>;
|
|
44
|
+
readonly topBars: Readonly<{
|
|
45
|
+
readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
|
|
46
|
+
readonly insetInline: stylex.StyleXClassNameFor<"insetInline", string>;
|
|
47
|
+
readonly display: stylex.StyleXClassNameFor<"display", "flex">;
|
|
48
|
+
readonly flexDirection: stylex.StyleXClassNameFor<"flexDirection", "column">;
|
|
49
|
+
readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
|
|
50
|
+
readonly gap: stylex.StyleXClassNameFor<"gap", string>;
|
|
51
|
+
readonly pointerEvents: stylex.StyleXClassNameFor<"pointerEvents", "none">;
|
|
52
|
+
}>;
|
|
53
|
+
readonly topBarsWide: Readonly<{
|
|
54
|
+
readonly top: stylex.StyleXClassNameFor<"top", string>;
|
|
55
|
+
}>;
|
|
56
|
+
readonly topBarsBelow: Readonly<{
|
|
57
|
+
readonly top: stylex.StyleXClassNameFor<"top", "3rem">;
|
|
58
|
+
}>;
|
|
59
|
+
readonly bottomBar: Readonly<{
|
|
60
|
+
readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
|
|
61
|
+
readonly insetInline: stylex.StyleXClassNameFor<"insetInline", string>;
|
|
62
|
+
readonly bottom: stylex.StyleXClassNameFor<"bottom", string>;
|
|
63
|
+
readonly display: stylex.StyleXClassNameFor<"display", "flex">;
|
|
64
|
+
readonly justifyContent: stylex.StyleXClassNameFor<"justifyContent", "center">;
|
|
65
|
+
readonly pointerEvents: stylex.StyleXClassNameFor<"pointerEvents", "none">;
|
|
66
|
+
}>;
|
|
67
|
+
readonly rail: Readonly<{
|
|
68
|
+
readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
|
|
69
|
+
readonly top: stylex.StyleXClassNameFor<"top", "50%">;
|
|
70
|
+
readonly left: stylex.StyleXClassNameFor<"left", string>;
|
|
71
|
+
readonly transform: stylex.StyleXClassNameFor<"transform", "translateY(-50%)">;
|
|
72
|
+
}>;
|
|
73
|
+
readonly zoom: Readonly<{
|
|
74
|
+
readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
|
|
75
|
+
readonly right: stylex.StyleXClassNameFor<"right", string>;
|
|
76
|
+
readonly bottom: stylex.StyleXClassNameFor<"bottom", string>;
|
|
77
|
+
}>;
|
|
78
|
+
readonly loading: Readonly<{
|
|
79
|
+
readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
|
|
80
|
+
readonly inset: stylex.StyleXClassNameFor<"inset", 0>;
|
|
81
|
+
readonly height: stylex.StyleXClassNameFor<"height", "fit-content">;
|
|
82
|
+
readonly margin: stylex.StyleXClassNameFor<"margin", "auto">;
|
|
83
|
+
readonly textAlign: stylex.StyleXClassNameFor<"textAlign", "center">;
|
|
84
|
+
readonly fontSize: stylex.StyleXClassNameFor<"fontSize", string>;
|
|
85
|
+
readonly color: stylex.StyleXClassNameFor<"color", string>;
|
|
86
|
+
}>;
|
|
87
|
+
readonly hidden: Readonly<{
|
|
88
|
+
readonly width: stylex.StyleXClassNameFor<"width", "1px">;
|
|
89
|
+
readonly height: stylex.StyleXClassNameFor<"height", "1px">;
|
|
90
|
+
readonly overflow: stylex.StyleXClassNameFor<"overflow", "hidden">;
|
|
91
|
+
readonly clipPath: stylex.StyleXClassNameFor<"clipPath", "inset(50%)">;
|
|
92
|
+
readonly whiteSpace: stylex.StyleXClassNameFor<"whiteSpace", "nowrap">;
|
|
93
|
+
}>;
|
|
94
|
+
}>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import { type Accessor } from "solid-js";
|
|
3
|
+
import { type CanvasKernel } from "./kernel.js";
|
|
4
|
+
/** The drawing surface of the board that holds `element`. */
|
|
5
|
+
declare function surfaceOf(element: Element | null | undefined): HTMLElement | null;
|
|
6
|
+
/** Zoom out, the zoom level (which resets it), zoom in, and fit. A narrow board gets one menu instead. */
|
|
7
|
+
export declare function CanvasZoomBar(props: {
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
}): JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* Everyone else on the board, as a button that lists them. Choosing someone follows their view until the
|
|
12
|
+
* viewer pans or zooms, or chooses them again. Who follows whom shows in the list, and how many follow the
|
|
13
|
+
* viewer shows beside the avatars on a wider board, so a leader knows they lead.
|
|
14
|
+
*/
|
|
15
|
+
export declare function CanvasPresence(props: {
|
|
16
|
+
compact: boolean;
|
|
17
|
+
}): JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* Changes an agent proposed. The board draws them as ghosts until someone keeps or discards them; a viewer
|
|
20
|
+
* who cannot edit only sees the note.
|
|
21
|
+
*/
|
|
22
|
+
export declare function CanvasProposals(): JSX.Element;
|
|
23
|
+
/** Says the viewer can look but not change anything. */
|
|
24
|
+
export declare function CanvasReadOnlyBadge(): JSX.Element;
|
|
25
|
+
export interface CanvasStatusProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "children"> {
|
|
26
|
+
/**
|
|
27
|
+
* What the status is about: `warning` (a state that limits editing, such as being offline) and `error`
|
|
28
|
+
* color the icon; `neutral` is progress the viewer waits on, such as catching up after a reconnect.
|
|
29
|
+
* @defaultValue "neutral"
|
|
30
|
+
*/
|
|
31
|
+
tone?: "neutral" | "warning" | "error";
|
|
32
|
+
/** An icon before the text, such as a spinner or a connection glyph (`<Icon icon={WifiOff} />`). */
|
|
33
|
+
icon?: JSX.Element;
|
|
34
|
+
/** A word or two, such as "Offline"; a narrow board truncates the rest. */
|
|
35
|
+
children: JSX.Element;
|
|
36
|
+
/**
|
|
37
|
+
* One small control, such as `<Button size="sm" variant="ghost">Retry now</Button>`, after the text inside
|
|
38
|
+
* the pill.
|
|
39
|
+
*/
|
|
40
|
+
action?: JSX.Element;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* One line about the board's state, in the board's own chrome: a host's connection status, or a change the
|
|
44
|
+
* board could not make. It sits in the top-left row (`CanvasBoard`'s `status`), so a host needs no banner above
|
|
45
|
+
* the board. Its text is a `status` region, read out as it changes without moving focus.
|
|
46
|
+
*/
|
|
47
|
+
export declare function CanvasStatus(props: CanvasStatusProps): JSX.Element;
|
|
48
|
+
/**
|
|
49
|
+
* The latest change the board could not make, said in the status row for a few seconds and dismissible. The
|
|
50
|
+
* board's live region reads it out as well.
|
|
51
|
+
*/
|
|
52
|
+
export declare function CanvasProblem(): JSX.Element;
|
|
53
|
+
/**
|
|
54
|
+
* Text the viewer typed into something another person started editing first. The board could not save it, so
|
|
55
|
+
* it stays on screen until the viewer copies or dismisses it: losing typed words silently is worse than a
|
|
56
|
+
* notice that waits.
|
|
57
|
+
*/
|
|
58
|
+
export declare function CanvasUnsaved(): JSX.Element;
|
|
59
|
+
/**
|
|
60
|
+
* A first step on an empty board: one action that adds a sticky note in the middle, ready to type in. Only the
|
|
61
|
+
* action takes the pointer, so drawing through the message still works.
|
|
62
|
+
*/
|
|
63
|
+
export declare function CanvasEmptyHint(props: {
|
|
64
|
+
compact: boolean;
|
|
65
|
+
}): JSX.Element;
|
|
66
|
+
/**
|
|
67
|
+
* Lists the board's shortcuts, the kernel's actions with theirs; `?` and ⌘/ open it from the board, and ⌘/
|
|
68
|
+
* closes it again. Closing it puts focus on the surface, so the next key is a board shortcut.
|
|
69
|
+
*/
|
|
70
|
+
export declare function CanvasShortcutsDialog(props: {
|
|
71
|
+
/** An element inside the board. */
|
|
72
|
+
board: () => HTMLElement | undefined;
|
|
73
|
+
open: boolean;
|
|
74
|
+
onOpenChange: (open: boolean) => void;
|
|
75
|
+
}): JSX.Element;
|
|
76
|
+
/** A board's PNG export: start one, and what the status row shows about the last one. */
|
|
77
|
+
export interface BoardExporter {
|
|
78
|
+
/** Starts an export of the board `element` sits in; ignored while one runs. Resolves when it ends. */
|
|
79
|
+
readonly run: (element: Element) => Promise<void>;
|
|
80
|
+
/** An export is running. */
|
|
81
|
+
readonly busy: Accessor<boolean>;
|
|
82
|
+
/** The failed export still shown, by id, or null. */
|
|
83
|
+
readonly failed: Accessor<number | null>;
|
|
84
|
+
/** Pictures the last export could not draw, while that is still shown. */
|
|
85
|
+
readonly missingPictures: Accessor<number>;
|
|
86
|
+
/** Clears what the status row shows about the last export. */
|
|
87
|
+
readonly dismiss: () => void;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Downloads the board as `<title>.png`, drawn in the browser in the board's theme, and keeps the latest
|
|
91
|
+
* failure, or the pictures it couldn't draw, for the status row for a few seconds.
|
|
92
|
+
*/
|
|
93
|
+
export declare function useBoardExport(options: {
|
|
94
|
+
canvas: () => CanvasKernel;
|
|
95
|
+
title: () => string | undefined;
|
|
96
|
+
}): BoardExporter;
|
|
97
|
+
/** Downloads the board as a PNG; off while the board is empty. */
|
|
98
|
+
export declare function CanvasExportButton(props: {
|
|
99
|
+
exporter: BoardExporter;
|
|
100
|
+
}): JSX.Element;
|
|
101
|
+
/** A failed export, or one missing pictures, in the status row until dismissed or a few seconds pass. */
|
|
102
|
+
export declare function CanvasExportProblem(props: {
|
|
103
|
+
exporter: BoardExporter;
|
|
104
|
+
}): JSX.Element;
|
|
105
|
+
/** Opens the shortcuts dialog, as `?` does from the board. */
|
|
106
|
+
export declare function CanvasHelpButton(props: {
|
|
107
|
+
onOpen: () => void;
|
|
108
|
+
}): JSX.Element;
|
|
109
|
+
export { surfaceOf };
|