@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.
Files changed (196) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +373 -0
  3. package/README.md +15 -2
  4. package/THIRD_PARTY_NOTICES.md +117 -0
  5. package/dist/dom/canvas/assets.js +89 -0
  6. package/dist/dom/canvas/board-store.js +56 -0
  7. package/dist/dom/canvas/canvas-actions.js +78 -0
  8. package/dist/dom/canvas/canvas-board.js +557 -0
  9. package/dist/dom/canvas/canvas-board.styles.js +110 -0
  10. package/dist/dom/canvas/canvas-chrome.js +1167 -0
  11. package/dist/dom/canvas/canvas-chrome.styles.js +220 -0
  12. package/dist/dom/canvas/canvas-comments.js +950 -0
  13. package/dist/dom/canvas/canvas-comments.styles.js +231 -0
  14. package/dist/dom/canvas/canvas-context.js +196 -0
  15. package/dist/dom/canvas/canvas-controller.js +697 -0
  16. package/dist/dom/canvas/canvas-cursor-chat.js +120 -0
  17. package/dist/dom/canvas/canvas-cursor-chat.styles.js +55 -0
  18. package/dist/dom/canvas/canvas-menus.js +276 -0
  19. package/dist/dom/canvas/canvas-menus.styles.js +7 -0
  20. package/dist/dom/canvas/canvas-style-bar.js +930 -0
  21. package/dist/dom/canvas/canvas-style-bar.styles.js +52 -0
  22. package/dist/dom/canvas/canvas-surface.js +1353 -0
  23. package/dist/dom/canvas/canvas-surface.styles.js +345 -0
  24. package/dist/dom/canvas/canvas-tool-rail.js +406 -0
  25. package/dist/dom/canvas/canvas-tool-rail.styles.js +20 -0
  26. package/dist/dom/canvas/comments.js +58 -0
  27. package/dist/dom/canvas/equality.js +13 -0
  28. package/dist/dom/canvas/export-png.js +496 -0
  29. package/dist/dom/canvas/gesture-machine.js +91 -0
  30. package/dist/dom/canvas/handlers.js +18 -0
  31. package/dist/dom/canvas/index.js +9 -0
  32. package/dist/dom/canvas/input.js +85 -0
  33. package/dist/dom/canvas/instant.js +28 -0
  34. package/dist/dom/canvas/kernel.js +39 -0
  35. package/dist/dom/canvas/motion.js +686 -0
  36. package/dist/dom/canvas/palette.js +165 -0
  37. package/dist/dom/canvas/random-id.js +15 -0
  38. package/dist/dom/canvas/scene-renderer.js +559 -0
  39. package/dist/dom/canvas/scene.styles.js +7 -0
  40. package/dist/dom/canvas/surface-model.js +324 -0
  41. package/dist/dom/canvas/uploads.js +294 -0
  42. package/dist/dom/index.js +9 -0
  43. package/dist/dom/kernel/actions.js +455 -0
  44. package/dist/dom/kernel/board.js +856 -0
  45. package/dist/dom/kernel/claims.js +40 -0
  46. package/dist/dom/kernel/clipboard.js +30 -0
  47. package/dist/dom/kernel/constants.js +210 -0
  48. package/dist/dom/kernel/contract.js +0 -0
  49. package/dist/dom/kernel/decode.js +85 -0
  50. package/dist/dom/kernel/editor.js +2077 -0
  51. package/dist/dom/kernel/errors.js +82 -0
  52. package/dist/dom/kernel/fonts/inter.js +7924 -0
  53. package/dist/dom/kernel/fractional-index.js +54 -0
  54. package/dist/dom/kernel/geometry.js +123 -0
  55. package/dist/dom/kernel/hit-test.js +156 -0
  56. package/dist/dom/kernel/index.js +22 -0
  57. package/dist/dom/kernel/inspect.js +116 -0
  58. package/dist/dom/kernel/kernel.js +251 -0
  59. package/dist/dom/kernel/outline.js +64 -0
  60. package/dist/dom/kernel/plan.js +1370 -0
  61. package/dist/dom/kernel/rev.js +173 -0
  62. package/dist/dom/kernel/scene.js +580 -0
  63. package/dist/dom/kernel/schema.js +1109 -0
  64. package/dist/dom/kernel/snap.js +258 -0
  65. package/dist/dom/kernel/svg.js +148 -0
  66. package/dist/dom/kernel/text.js +142 -0
  67. package/dist/solid/canvas/assets.jsx +89 -0
  68. package/dist/solid/canvas/board-store.jsx +56 -0
  69. package/dist/solid/canvas/canvas-actions.jsx +78 -0
  70. package/dist/solid/canvas/canvas-board.jsx +326 -0
  71. package/dist/solid/canvas/canvas-board.styles.jsx +110 -0
  72. package/dist/solid/canvas/canvas-chrome.jsx +612 -0
  73. package/dist/solid/canvas/canvas-chrome.styles.jsx +220 -0
  74. package/dist/solid/canvas/canvas-comments.jsx +435 -0
  75. package/dist/solid/canvas/canvas-comments.styles.jsx +231 -0
  76. package/dist/solid/canvas/canvas-context.jsx +174 -0
  77. package/dist/solid/canvas/canvas-controller.jsx +697 -0
  78. package/dist/solid/canvas/canvas-cursor-chat.jsx +87 -0
  79. package/dist/solid/canvas/canvas-cursor-chat.styles.jsx +55 -0
  80. package/dist/solid/canvas/canvas-menus.jsx +223 -0
  81. package/dist/solid/canvas/canvas-menus.styles.jsx +7 -0
  82. package/dist/solid/canvas/canvas-style-bar.jsx +486 -0
  83. package/dist/solid/canvas/canvas-style-bar.styles.jsx +52 -0
  84. package/dist/solid/canvas/canvas-surface.jsx +681 -0
  85. package/dist/solid/canvas/canvas-surface.styles.jsx +345 -0
  86. package/dist/solid/canvas/canvas-tool-rail.jsx +195 -0
  87. package/dist/solid/canvas/canvas-tool-rail.styles.jsx +20 -0
  88. package/dist/solid/canvas/comments.jsx +58 -0
  89. package/dist/solid/canvas/equality.jsx +13 -0
  90. package/dist/solid/canvas/export-png.jsx +496 -0
  91. package/dist/solid/canvas/gesture-machine.jsx +91 -0
  92. package/dist/solid/canvas/handlers.jsx +18 -0
  93. package/dist/solid/canvas/index.jsx +9 -0
  94. package/dist/solid/canvas/input.jsx +85 -0
  95. package/dist/solid/canvas/instant.jsx +28 -0
  96. package/dist/solid/canvas/kernel.jsx +39 -0
  97. package/dist/solid/canvas/motion.jsx +686 -0
  98. package/dist/solid/canvas/palette.jsx +165 -0
  99. package/dist/solid/canvas/random-id.jsx +15 -0
  100. package/dist/solid/canvas/scene-renderer.jsx +559 -0
  101. package/dist/solid/canvas/scene.styles.jsx +7 -0
  102. package/dist/solid/canvas/surface-model.jsx +324 -0
  103. package/dist/solid/canvas/uploads.jsx +294 -0
  104. package/dist/solid/index.jsx +9 -0
  105. package/dist/solid/kernel/actions.jsx +455 -0
  106. package/dist/solid/kernel/board.jsx +856 -0
  107. package/dist/solid/kernel/claims.jsx +40 -0
  108. package/dist/solid/kernel/clipboard.jsx +30 -0
  109. package/dist/solid/kernel/constants.jsx +210 -0
  110. package/dist/solid/kernel/contract.jsx +0 -0
  111. package/dist/solid/kernel/decode.jsx +85 -0
  112. package/dist/solid/kernel/editor.jsx +2077 -0
  113. package/dist/solid/kernel/errors.jsx +82 -0
  114. package/dist/solid/kernel/fonts/inter.jsx +7924 -0
  115. package/dist/solid/kernel/fractional-index.jsx +54 -0
  116. package/dist/solid/kernel/geometry.jsx +123 -0
  117. package/dist/solid/kernel/hit-test.jsx +156 -0
  118. package/dist/solid/kernel/index.jsx +22 -0
  119. package/dist/solid/kernel/inspect.jsx +116 -0
  120. package/dist/solid/kernel/kernel.jsx +251 -0
  121. package/dist/solid/kernel/outline.jsx +64 -0
  122. package/dist/solid/kernel/plan.jsx +1370 -0
  123. package/dist/solid/kernel/rev.jsx +173 -0
  124. package/dist/solid/kernel/scene.jsx +580 -0
  125. package/dist/solid/kernel/schema.jsx +1109 -0
  126. package/dist/solid/kernel/snap.jsx +258 -0
  127. package/dist/solid/kernel/svg.jsx +148 -0
  128. package/dist/solid/kernel/text.jsx +142 -0
  129. package/dist/styles.css +1 -0
  130. package/dist/types/canvas/assets.d.ts +111 -0
  131. package/dist/types/canvas/board-store.d.ts +86 -0
  132. package/dist/types/canvas/canvas-actions.d.ts +21 -0
  133. package/dist/types/canvas/canvas-board.d.ts +53 -0
  134. package/dist/types/canvas/canvas-board.styles.d.ts +94 -0
  135. package/dist/types/canvas/canvas-chrome.d.ts +109 -0
  136. package/dist/types/canvas/canvas-chrome.styles.d.ts +193 -0
  137. package/dist/types/canvas/canvas-comments.d.ts +20 -0
  138. package/dist/types/canvas/canvas-comments.styles.d.ts +208 -0
  139. package/dist/types/canvas/canvas-context.d.ts +104 -0
  140. package/dist/types/canvas/canvas-controller.d.ts +159 -0
  141. package/dist/types/canvas/canvas-cursor-chat.d.ts +13 -0
  142. package/dist/types/canvas/canvas-cursor-chat.styles.d.ts +54 -0
  143. package/dist/types/canvas/canvas-menus.d.ts +21 -0
  144. package/dist/types/canvas/canvas-menus.styles.d.ts +6 -0
  145. package/dist/types/canvas/canvas-style-bar.d.ts +19 -0
  146. package/dist/types/canvas/canvas-style-bar.styles.d.ts +43 -0
  147. package/dist/types/canvas/canvas-surface.d.ts +15 -0
  148. package/dist/types/canvas/canvas-surface.styles.d.ts +313 -0
  149. package/dist/types/canvas/canvas-tool-rail.d.ts +41 -0
  150. package/dist/types/canvas/canvas-tool-rail.styles.d.ts +15 -0
  151. package/dist/types/canvas/comments.d.ts +106 -0
  152. package/dist/types/canvas/equality.d.ts +4 -0
  153. package/dist/types/canvas/export-png.d.ts +77 -0
  154. package/dist/types/canvas/gesture-machine.d.ts +46 -0
  155. package/dist/types/canvas/handlers.d.ts +7 -0
  156. package/dist/types/canvas/index.d.ts +18 -0
  157. package/dist/types/canvas/input.d.ts +63 -0
  158. package/dist/types/canvas/instant.d.ts +13 -0
  159. package/dist/types/canvas/kernel.d.ts +27 -0
  160. package/dist/types/canvas/motion.d.ts +72 -0
  161. package/dist/types/canvas/palette.d.ts +46 -0
  162. package/dist/types/canvas/random-id.d.ts +6 -0
  163. package/dist/types/canvas/scene-renderer.d.ts +27 -0
  164. package/dist/types/canvas/scene.styles.d.ts +4 -0
  165. package/dist/types/canvas/surface-model.d.ts +113 -0
  166. package/dist/types/canvas/uploads.d.ts +58 -0
  167. package/dist/types/index.d.ts +1 -0
  168. package/dist/types/kernel/actions.d.ts +19 -0
  169. package/dist/types/kernel/board.d.ts +137 -0
  170. package/dist/types/kernel/claims.d.ts +29 -0
  171. package/dist/types/kernel/clipboard.d.ts +10 -0
  172. package/dist/types/kernel/constants.d.ts +195 -0
  173. package/dist/types/kernel/contract.d.ts +1533 -0
  174. package/dist/types/kernel/decode.d.ts +60 -0
  175. package/dist/types/kernel/editor.d.ts +12 -0
  176. package/dist/types/kernel/errors.d.ts +11 -0
  177. package/dist/types/kernel/fractional-index.d.ts +7 -0
  178. package/dist/types/kernel/geometry.d.ts +42 -0
  179. package/dist/types/kernel/hit-test.d.ts +16 -0
  180. package/dist/types/kernel/index.d.ts +8 -0
  181. package/dist/types/kernel/inspect.d.ts +6 -0
  182. package/dist/types/kernel/kernel.d.ts +6 -0
  183. package/dist/types/kernel/outline.d.ts +4 -0
  184. package/dist/types/kernel/plan.d.ts +20 -0
  185. package/dist/types/kernel/rev.d.ts +21 -0
  186. package/dist/types/kernel/scene.d.ts +16 -0
  187. package/dist/types/kernel/schema.d.ts +3436 -0
  188. package/dist/types/kernel/snap.d.ts +41 -0
  189. package/dist/types/kernel/svg.d.ts +3 -0
  190. package/dist/types/kernel/text.d.ts +21 -0
  191. package/docs/api.json +207 -0
  192. package/docs/canvas.md +444 -0
  193. package/docs/kernel.md +108 -0
  194. package/docs/llms.txt +41 -0
  195. package/docs/search-index.json +52 -0
  196. package/package.json +55 -4
@@ -0,0 +1,63 @@
1
+ import type { ModifiersJson, PointerKindJson, PointerStyleJson } from "../kernel/index.js";
2
+ type ModifierEvent = {
3
+ readonly altKey: boolean;
4
+ readonly ctrlKey: boolean;
5
+ readonly metaKey: boolean;
6
+ readonly shiftKey: boolean;
7
+ };
8
+ /** Ctrl counts as meta, so Windows and Linux shortcuts match Mac ones. */
9
+ declare function modifiersOf(event: ModifierEvent): ModifiersJson;
10
+ declare function pointerKindOf(pointerType: string): PointerKindJson;
11
+ /** `PointerEvent.button` as the kernel names it; back and forward buttons are ignored. */
12
+ declare function buttonOf(button: number): "middle" | "primary" | "secondary" | null;
13
+ /**
14
+ * `KeyboardEvent.key` as the kernel expects it: letters lowercase. Where the
15
+ * key types something else on the same physical key, such as a symbol with
16
+ * Alt on a Mac or a Cyrillic letter, the letter or digit comes from `code`.
17
+ */
18
+ declare function keyOf(event: {
19
+ readonly altKey: boolean;
20
+ readonly code: string;
21
+ readonly key: string;
22
+ }): string;
23
+ /**
24
+ * Copy, cut and paste run through the browser's clipboard events, so their
25
+ * key presses are left alone.
26
+ */
27
+ declare function isClipboardShortcut(event: ModifierEvent & {
28
+ readonly code: string;
29
+ }): boolean;
30
+ /** Wheel deltas in screen pixels, whatever unit the device reported. */
31
+ declare function wheelDelta(event: {
32
+ readonly deltaMode: number;
33
+ readonly deltaX: number;
34
+ readonly deltaY: number;
35
+ readonly shiftKey: boolean;
36
+ }, pageHeight: number): {
37
+ dx: number;
38
+ dy: number;
39
+ };
40
+ /** The CSS cursor for the kernel's pointer style. */
41
+ declare function cssCursor(style: PointerStyleJson): string;
42
+ /**
43
+ * A pointer's position in an element's own CSS pixels. An ancestor's CSS
44
+ * transform scales the element's box on screen but not its layout, so the
45
+ * offset is scaled back by layout size over box size.
46
+ */
47
+ declare function localPoint(element: HTMLElement, at: {
48
+ readonly clientX: number;
49
+ readonly clientY: number;
50
+ }): {
51
+ x: number;
52
+ y: number;
53
+ };
54
+ /**
55
+ * The key belongs to an input method, such as one composing Japanese. Safari
56
+ * sends the key that ends a composition after `isComposing` turns false, with
57
+ * `keyCode` 229.
58
+ */
59
+ declare function composing(event: {
60
+ readonly isComposing: boolean;
61
+ readonly keyCode: number;
62
+ }): boolean;
63
+ export { buttonOf, composing, cssCursor, isClipboardShortcut, keyOf, localPoint, modifiersOf, pointerKindOf, wheelDelta, };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Instants on a board, in the viewer's zone and locale. A timestamp shape,
3
+ * its PNG and SVG export and comment times all read through these, so one
4
+ * moment reads the same everywhere on one screen.
5
+ */
6
+ /**
7
+ * "2:27 PM": a timestamp shape's badge, the time of day only. The date and
8
+ * zone are in `instantFull`, its title, and the shape keeps the instant.
9
+ */
10
+ declare function instantLabel(epochMs: number): string;
11
+ /** "Thursday, November 20, 2026 at 2:27:05 PM Pacific Standard Time". */
12
+ declare function instantFull(epochMs: number): string;
13
+ export { instantFull, instantLabel };
@@ -0,0 +1,27 @@
1
+ import type { ClipboardDecodeJson, FontDataJson, FontRefJson, Kernel, Outcome } from "../kernel/index.js";
2
+ /**
3
+ * A loaded kernel and the font metrics the DOM text editor needs to sit on
4
+ * the kernel's baselines.
5
+ */
6
+ type CanvasKernel = {
7
+ readonly kernel: Kernel;
8
+ /** Reads clipboard text: a board's shapes, someone else's text, or a board clipboard this kernel can't read. */
9
+ readonly decodeClipboard: (text: string) => ClipboardDecodeJson;
10
+ /** Ascender and descender as fractions of the font size. */
11
+ readonly metrics: {
12
+ readonly ascender: number;
13
+ readonly descender: number;
14
+ };
15
+ };
16
+ /** The kernel's failures are values; a failed call the host cannot recover from is a bug. */
17
+ declare function expectOk<A>(outcome: Outcome<A>): A;
18
+ declare function createCanvasKernel(kernel: Kernel, fonts: FontDataJson, decodeClipboard: CanvasKernel["decodeClipboard"]): CanvasKernel;
19
+ /**
20
+ * Loads the kernel (`../kernel`) and its Inter advance tables once, on
21
+ * first use, so pages without a board never download them.
22
+ */
23
+ declare function loadCanvasKernel(): Promise<CanvasKernel>;
24
+ /** Offset of the first baseline from the top of a text block (CSS half-leading). */
25
+ declare function baselineOffset(metrics: CanvasKernel["metrics"], font: FontRefJson): number;
26
+ export { baselineOffset, createCanvasKernel, expectOk, loadCanvasKernel };
27
+ export type { CanvasKernel };
@@ -0,0 +1,72 @@
1
+ import type { BoardJson, PresenceJson, ViewportJson } from "../kernel/index.js";
2
+ /**
3
+ * Smooth motion for what arrives in steps: other people's presence, at the
4
+ * rate their host sends it, and the viewer's own camera, which the kernel
5
+ * moves in jumps. Pure and clock-free: every call takes the time, so tests
6
+ * drive it with a fake clock.
7
+ */
8
+ /** The longest presence is held back to smooth it, in milliseconds. */
9
+ declare const MAX_DELAY = 300;
10
+ /** A gap after which the next sample starts a new motion, in milliseconds. */
11
+ declare const STALE = 1000;
12
+ /** How long a drop eases the rest of the way to where it was committed, at least. */
13
+ declare const SETTLE_MS = 80;
14
+ /** How long a dragged shape waits at its last preview for the drop to arrive. */
15
+ declare const DROP_GRACE = 1000;
16
+ /** A zoom step's glide, in milliseconds. */
17
+ declare const GLIDE_MS = 220;
18
+ type PresenceFrame = {
19
+ readonly presence: readonly PresenceJson[];
20
+ /** True while someone is still between samples, so another frame is needed. */
21
+ readonly moving: boolean;
22
+ };
23
+ /** A board's shapes, as far as motion reads them. */
24
+ type BoardPlaces = {
25
+ readonly head: BoardJson["head"];
26
+ readonly ["shapes"]: readonly Pick<BoardJson["shapes"][number], "h" | "id" | "w" | "x" | "y">[];
27
+ readonly transactions: readonly Pick<BoardJson["transactions"][number], "author" | "seq" | "shapes">[];
28
+ };
29
+ /**
30
+ * Other people's presence, smoothed. Each connection's samples are kept with the
31
+ * time they arrived and shown a little late, about one sending interval plus
32
+ * a margin for jitter, so the view always has the next sample to move
33
+ * toward. Positions follow a spline through the samples; everything else
34
+ * (selection, claims, the kind of activity, a stroke's points) switches
35
+ * whole, at the sample it came with, so a frame never mixes two samples.
36
+ */
37
+ declare function createPresenceMotion(options?: {
38
+ readonly reduced?: () => boolean;
39
+ }): {
40
+ /** Records presence as it arrives at `now`. */
41
+ push(presence: readonly PresenceJson[], now: number): void;
42
+ /**
43
+ * Records the board as it arrives at `now`: `remote` when it came from
44
+ * the store, so a drop it holds ends the drag that previewed it.
45
+ */
46
+ board(board: BoardPlaces, now: number, remote: boolean): void;
47
+ /** Presence to draw at `now`. The same object until something moves. */
48
+ sample(now: number): PresenceFrame;
49
+ };
50
+ type PresenceMotion = ReturnType<typeof createPresenceMotion>;
51
+ /** One camera frame: the view to show, and the motion still running, or null. */
52
+ type CameraStep = {
53
+ readonly view: ViewportJson;
54
+ readonly motion: CameraMotion | null;
55
+ };
56
+ /** How the shown camera is moving toward the kernel's view. */
57
+ type CameraMotion = {
58
+ readonly _tag: "Glide";
59
+ readonly from: ViewportJson;
60
+ readonly began: number;
61
+ } | {
62
+ readonly _tag: "Follow";
63
+ readonly last: number;
64
+ };
65
+ /**
66
+ * One frame of the camera: a zoom step glides with `ease-out-quint`; while
67
+ * following, the camera eases toward the leader's view each frame and
68
+ * locks on within two pixels. Returns the motion still running, or null.
69
+ */
70
+ declare function stepCamera(shown: ViewportJson, target: ViewportJson, motion: CameraMotion, now: number): CameraStep;
71
+ export { createPresenceMotion, DROP_GRACE, GLIDE_MS, MAX_DELAY, SETTLE_MS, STALE, stepCamera };
72
+ export type { BoardPlaces, CameraMotion, CameraStep, PresenceFrame, PresenceMotion };
@@ -0,0 +1,46 @@
1
+ import type { ActorKindJson, ColorJson, PaletteJson, ToneJson } from "../kernel/index.js";
2
+ /** The kernel's color names, in the order the style bar shows them. */
3
+ declare const CANVAS_COLORS: readonly ["ink", "gray", "yellow", "orange", "red", "pink", "violet", "blue", "teal", "green"];
4
+ declare const COLOR_LABELS: Record<ColorJson, string>;
5
+ /** Shape strokes and text. */
6
+ declare function strokeOf(color: ColorJson): string;
7
+ /** Shape fills (`light`) and sticky paper (`note`). */
8
+ declare function paintOf(color: ColorJson, tone: ToneJson): string;
9
+ /**
10
+ * Text on sticky-note paper. Notes stay light paper in both themes, so their
11
+ * text stays dark, where ink text on the board itself turns light.
12
+ */
13
+ declare const NOTE_INK = "var(--sui-canvas-note-ink)";
14
+ /** Selection, handles and hover: the theme's focus color. */
15
+ declare const SELECTION = "var(--sui-focus)";
16
+ declare const SNAP = "var(--sui-canvas-pink-stroke)";
17
+ /**
18
+ * Text and outlines on an actor's color. Actor colors are the board's strokes, which hold 4.5:1 on the
19
+ * board in either scheme (dark in light, light in dark), so text on them takes the board's color.
20
+ */
21
+ declare const ON_AVATAR = "var(--sui-surface)";
22
+ /** The shadow under sticky notes: the note ink, near black in either scheme, as shadows are. */
23
+ declare const SHADOW = "var(--sui-canvas-note-ink)";
24
+ /**
25
+ * Another person's or an agent's color: people by name, from the board's strokes, and agents all alike
26
+ * (violet).
27
+ */
28
+ declare function actorColor(kind: ActorKindJson, name: string): string;
29
+ /** Text on an actor's color: the board's color, in either scheme. */
30
+ declare function actorInk(_kind: ActorKindJson): string;
31
+ /**
32
+ * The palette as CSS colors, for the live board. It follows the theme with
33
+ * no work because every value is a custom property.
34
+ */
35
+ declare function cssPalette(): PaletteJson;
36
+ /**
37
+ * Runs `read` with a function that turns CSS colors, custom properties
38
+ * included, into hex as they resolve in the theme `element` sits in.
39
+ */
40
+ declare function withHexColors<T>(element: Element, read: (hex: (value: string) => string) => T): T;
41
+ /**
42
+ * The palette resolved to hex in the theme `element` sits in, for
43
+ * `kernel.toSvg`: a standalone SVG cannot read custom properties.
44
+ */
45
+ declare function resolvePalette(element: Element): PaletteJson;
46
+ export { actorColor, actorInk, CANVAS_COLORS, COLOR_LABELS, cssPalette, NOTE_INK, ON_AVATAR, paintOf, resolvePalette, SELECTION, SHADOW, SNAP, strokeOf, withHexColors, };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A random UUID (v4). `crypto.randomUUID` exists only on secure pages (HTTPS, localhost); a board served over
3
+ * plain HTTP elsewhere (a LAN address in development) builds the same form from `crypto.getRandomValues`,
4
+ * which every page has.
5
+ */
6
+ export declare function randomId(): string;
@@ -0,0 +1,27 @@
1
+ import type { SceneJson, ViewportJson } from "../kernel/index.js";
2
+ import type { CanvasAssetSource } from "./assets.js";
3
+ type RenderOptions = {
4
+ /** Grid spacing in board units, or null for a plain board. */
5
+ readonly grid: number | null;
6
+ /** The board item whose text the DOM text editor shows instead. */
7
+ readonly editing: string | null;
8
+ /** Names for other people's and agents' actor ids. */
9
+ readonly names: ReadonlyMap<string, string>;
10
+ /**
11
+ * An image's source at a width in device pixels, or null when the board
12
+ * has no assets, so every image draws as missing.
13
+ */
14
+ readonly image: ((asset: string, width: number) => CanvasAssetSource) | null;
15
+ };
16
+ /**
17
+ * Draws kernel scenes into an `<svg>` by key: each frame updates the
18
+ * elements whose items changed, moves them into scene order and removes the
19
+ * rest, so a frame costs what changed, not the whole board.
20
+ */
21
+ declare function createSceneRenderer(svg: SVGSVGElement): {
22
+ render: (scene: SceneJson, view: ViewportJson, options: RenderOptions) => void;
23
+ dispose(): void;
24
+ };
25
+ type SceneRenderer = ReturnType<typeof createSceneRenderer>;
26
+ export { createSceneRenderer };
27
+ export type { RenderOptions, SceneRenderer };
@@ -0,0 +1,4 @@
1
+ /** The pulse of a waiting image's tile. */
2
+ export declare const pendingClass: string;
3
+ /** A timestamp's badge. */
4
+ export declare const timestampClass: string;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The drawing surface's plain logic: what the HTML layer over the scene shows (the roster), where each
3
+ * of its elements goes every frame, how cursor labels fit, the board's description for assistive
4
+ * technology, what a drop or paste carries, and image sources that retry. No Solid: `canvas-surface.tsx`
5
+ * renders with these.
6
+ */
7
+ import type { ActorKindJson, BoardJson, DrawItemJson, InsetJson, SceneJson, ViewportJson } from "../kernel/index.js";
8
+ import { type CanvasAssetSource } from "./assets.js";
9
+ import type { CanvasMedia } from "./canvas-context.js";
10
+ import type { CanvasKernel } from "./kernel.js";
11
+ import type { CanvasUpload } from "./uploads.js";
12
+ /** The clipboard type a board writes beside plain text. */
13
+ declare const CLIPBOARD_TYPE = "application/x-hyper-canvas+json";
14
+ type TextEditorItem = Extract<DrawItemJson, {
15
+ _tag: "TextEditor";
16
+ }>;
17
+ type CursorItem = Extract<DrawItemJson, {
18
+ _tag: "Cursor";
19
+ }>;
20
+ type TextLinesItem = Extract<DrawItemJson, {
21
+ _tag: "TextLines";
22
+ }>;
23
+ type ScreenBox = {
24
+ readonly x: number;
25
+ readonly y: number;
26
+ readonly w: number;
27
+ readonly h: number;
28
+ };
29
+ declare const screenOf: (view: ViewportJson, x: number, y: number) => {
30
+ x: number;
31
+ y: number;
32
+ };
33
+ /** The part of the screen the chrome leaves clear; all of it when the chrome leaves no room, as the kernel does. */
34
+ declare function clearArea(view: ViewportJson, inset: InsetJson): ScreenBox;
35
+ type CursorEntry = {
36
+ readonly key: string;
37
+ readonly actor: string;
38
+ /** What they are typing in cursor chat, shown in a bubble at the pointer. */
39
+ readonly chat: string | null;
40
+ readonly kind: ActorKindJson;
41
+ readonly label: string;
42
+ readonly name: string;
43
+ };
44
+ type MediaEntry = {
45
+ readonly _tag: "Image";
46
+ readonly key: string;
47
+ readonly status: "pending" | "failed";
48
+ readonly reason: "forbidden" | "missing" | null;
49
+ } | {
50
+ readonly _tag: "Upload";
51
+ readonly key: string;
52
+ readonly id: string;
53
+ readonly mine: boolean;
54
+ readonly name: string | null;
55
+ };
56
+ type EditorEntry = {
57
+ readonly item: TextEditorItem;
58
+ readonly lines: TextLinesItem | undefined;
59
+ readonly note: boolean;
60
+ readonly view: ViewportJson;
61
+ };
62
+ /**
63
+ * What the HTML layer over the scene shows, besides positions: who has a
64
+ * cursor, which images are waiting or broken, whose uploads are on the
65
+ * board, and the text editor. It changes far less often than frames do,
66
+ * so Solid renders it only on change and each frame only moves it.
67
+ */
68
+ type OverlayRoster = {
69
+ readonly cursors: readonly CursorEntry[];
70
+ readonly media: readonly MediaEntry[];
71
+ readonly editor: EditorEntry | null;
72
+ };
73
+ declare const EMPTY_ROSTER: OverlayRoster;
74
+ declare function sameRoster(a: OverlayRoster, b: OverlayRoster): boolean;
75
+ /**
76
+ * Moves the HTML layer to this frame: cursors and edge chips to their
77
+ * screen points with their label fit, and image and upload panels over
78
+ * their boxes. It writes styles and data attributes only, never reactive state.
79
+ */
80
+ declare function placeOverlay(overlay: HTMLElement, scene: SceneJson, view: ViewportJson, area: ScreenBox, uploads: readonly CanvasUpload[]): void;
81
+ /** Where a replacement's progress sits: over the image it replaces. */
82
+ declare const replacingKey: (id: string) => string;
83
+ /** Where a failed new image sits, drawn by the board for the viewer only. */
84
+ declare const failedKey: (id: string) => string;
85
+ /**
86
+ * The board's description for assistive technology: how many shapes it has,
87
+ * and what is selected. Each shape reads out as Tab reaches it, so a large
88
+ * board is not read as one long list. An image reads as its description.
89
+ */
90
+ declare function boardDescription(kernel: CanvasKernel["kernel"], board: BoardJson, selection: readonly string[]): string;
91
+ /** Image files in a transfer, from a drop or a paste. */
92
+ declare function filesOf(data: DataTransfer | null): File[];
93
+ /** True when a drag may carry something the board can add. */
94
+ declare function carriesMedia(data: DataTransfer | null, links: boolean): boolean;
95
+ /** The first web link in a drop's link list. */
96
+ declare function linkOf(data: DataTransfer | null): string | null;
97
+ declare const BROKEN: CanvasAssetSource;
98
+ type ImageSources = {
99
+ readonly resolve: ((asset: string, width: number) => CanvasAssetSource) | null;
100
+ readonly markBroken: (src: string) => void;
101
+ readonly dispose: () => void;
102
+ };
103
+ /**
104
+ * A source per asset and width, for the renderer and the overlay. A
105
+ * source whose image failed to load counts as missing for a while, then
106
+ * loads again: a failure can be a dropped connection or a busy server,
107
+ * and an image that is really gone stays missing at the slowest retry.
108
+ */
109
+ declare function createImageSources(media: CanvasMedia | null, redraw: () => void): ImageSources;
110
+ /** The overlay's roster for a scene. */
111
+ declare function rosterOf(scene: SceneJson, view: ViewportJson, names: ReadonlyMap<string, string>, editing: string | null, resolve: ImageSources["resolve"]): OverlayRoster;
112
+ export { BROKEN, boardDescription, carriesMedia, clearArea, CLIPBOARD_TYPE, createImageSources, EMPTY_ROSTER, failedKey, filesOf, linkOf, placeOverlay, replacingKey, rosterOf, sameRoster, screenOf, };
113
+ export type { CursorEntry, CursorItem, EditorEntry, ImageSources, MediaEntry, OverlayRoster, ScreenBox, TextEditorItem, TextLinesItem, };
@@ -0,0 +1,58 @@
1
+ import type { BoxJson, PointJson } from "../kernel/index.js";
2
+ import { type CanvasAssets } from "./assets.js";
3
+ import type { CanvasController } from "./canvas-controller.js";
4
+ /**
5
+ * One of the viewer's uploads, as only the viewer sees it: a new image, or
6
+ * a new file for an image already on the board (`target`).
7
+ */
8
+ type CanvasUpload = {
9
+ readonly id: string;
10
+ readonly name: string;
11
+ /** The image this upload replaces, or null for a new image. */
12
+ readonly target: string | null;
13
+ } & ({
14
+ readonly status: "uploading";
15
+ /** Sent so far, from 0 to 1; null before the host reports any. */
16
+ readonly progress: number | null;
17
+ } | {
18
+ readonly status: "failed";
19
+ /** The host's reason, written for people, or null for generic copy. */
20
+ readonly message: string | null;
21
+ /** Whether to offer Retry; Remove is always offered. */
22
+ readonly retryable: boolean;
23
+ /**
24
+ * Where a new image's placeholder was. Others no longer see it, so the
25
+ * board draws the failed one here, for the viewer only.
26
+ */
27
+ readonly box: BoxJson | null;
28
+ });
29
+ /**
30
+ * The viewer's image uploads: files read for their size, shown at once as
31
+ * placeholders through the editor's `BeginUpload` (so others see them too),
32
+ * sent to the host, and inserted with `InsertImage` when stored. A failed
33
+ * upload ends its placeholder for everyone and keeps it for the viewer,
34
+ * with the host's reason, Remove, and Retry when trying again can help;
35
+ * Retry shows it to everyone again. A replacement shows only to the viewer
36
+ * and swaps the image's file with one undoable `Update`. Unmounting cancels
37
+ * the rest.
38
+ */
39
+ declare function createUploads(controller: CanvasController, assets: CanvasAssets): {
40
+ /** Uploads `files` laid out from `at`; files the host does not take are named in the problem row. */
41
+ addFiles(files: readonly File[], at: PointJson): Promise<void>;
42
+ /** Stores the image a dropped link points at, when the host can. */
43
+ addUrl(url: string, at: PointJson): boolean;
44
+ replace: (id: string, file: File) => Promise<void>;
45
+ /** Opens the file picker for a new picture for image `id`. */
46
+ pickReplacement(id: string): void;
47
+ /** Stops an upload, or removes a failed one; a replaced image keeps its old picture. */
48
+ cancel(id: string): void;
49
+ /** Cancels every upload, as the board unmounts. */
50
+ dispose(): void;
51
+ getSnapshot: () => readonly CanvasUpload[];
52
+ /** Sends a failed upload again; a new image shows to everyone again where it was. */
53
+ retry(id: string): void;
54
+ subscribe(listener: () => void): () => void;
55
+ };
56
+ type CanvasUploads = ReturnType<typeof createUploads>;
57
+ export { createUploads };
58
+ export type { CanvasUpload, CanvasUploads };
@@ -0,0 +1 @@
1
+ export * from "./canvas/index.js";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Every action, with its label and shortcuts: the one list that menus,
3
+ * tooltips, the shortcut sheet, the command menu and key handling read.
4
+ *
5
+ * Shortcut keys are `KeyboardEvent.key` values with letters lowercase. For
6
+ * letter, digit and punctuation keys, hosts pass the unshifted US character
7
+ * for `KeyboardEvent.code` (so Option and Shift do not change the key), and
8
+ * `meta` is Command on macOS and Control elsewhere.
9
+ */
10
+ import type { ActionIdJson, ActionJson, EditorStateJson, InspectionJson, ModifiersJson, ToolJson } from "./contract.js";
11
+ import type { BoardIndex } from "./board.js";
12
+ export declare const TOOL_OF: Partial<Record<ActionIdJson, ToolJson>>;
13
+ /** Actions bound to a key, in list order. */
14
+ export declare const actionsForKey: (k: string, modifiers: ModifiersJson) => ReadonlyArray<ActionIdJson>;
15
+ export declare const isEnabled: (id: ActionIdJson, state: EditorStateJson, index: BoardIndex, can: InspectionJson["can"]) => boolean;
16
+ /** Edits that change the selected shapes, so another's claim on one blocks them. */
17
+ export declare const changesSelection: (id: ActionIdJson) => boolean;
18
+ export declare const listActions: (state: EditorStateJson, index: BoardIndex, can: InspectionJson["can"], held: ReadonlyMap<string, string>) => ReadonlyArray<ActionJson>;
19
+ export declare const labelOf: (id: ActionIdJson) => string;
@@ -0,0 +1,137 @@
1
+ import type { ArrowJson, BoardJson, BoxJson, FontRefJson, InkJson, InkStyleJson, PointJson, ShapeChangeJson, ShapeFieldsJson, ShapeJson, TextAlignJson, TextLineJson, TransactionRecordJson } from "./contract.js";
2
+ import { type Fonts } from "./text.js";
3
+ export type Shapes = ReadonlyMap<string, ShapeJson>;
4
+ /** Draw order: ascending z, ties by id. */
5
+ export declare const compareShapes: (a: ShapeJson, b: ShapeJson) => number;
6
+ export declare const toMap: (shapes: ReadonlyArray<ShapeJson>) => Map<string, ShapeJson>;
7
+ /** Shapes back to front. */
8
+ export declare const ordered: (shapes: Shapes) => ReadonlyArray<ShapeJson>;
9
+ export declare const sortedIds: (ids: Iterable<string>) => ReadonlyArray<string>;
10
+ export type TextShape = Extract<ShapeJson, {
11
+ readonly text: string;
12
+ }>;
13
+ export declare const hasText: (shape: ShapeJson) => shape is TextShape;
14
+ export interface TextLayout {
15
+ readonly font: FontRefJson;
16
+ /** The area text is laid out in. */
17
+ readonly area: BoxJson;
18
+ readonly align: TextAlignJson;
19
+ readonly lines: ReadonlyArray<TextLineJson>;
20
+ /** The height the shape needs to show every line. */
21
+ readonly neededHeight: number;
22
+ }
23
+ export declare const layoutText: (fonts: Fonts, shape: TextShape) => TextLayout;
24
+ /**
25
+ * A text shape's box after a change: a text shape's height is its lines', an
26
+ * auto-width text's width is its text's, and stickies and boxes grow to fit.
27
+ */
28
+ export declare const fitText: <S extends TextShape>(fonts: Fonts, shape: S) => S;
29
+ /** Ink from board-coordinate points: simplified, rounded, relative to its box. */
30
+ export declare const inkGeometry: (absolute: ReadonlyArray<PointJson>, tolerance: number) => Pick<InkJson, "x" | "y" | "w" | "h" | "points">;
31
+ export declare const inkPoints: (ink: InkJson) => ReadonlyArray<PointJson>;
32
+ /** A smooth path through stroke points: quadratic curves through the midpoints. */
33
+ export declare const strokePath: (points: ReadonlyArray<PointJson>) => string;
34
+ /**
35
+ * The curve `strokePath` draws, as a polyline: each quadratic in up to 64
36
+ * straight pieces, within 0.25 units of the curve unless the curve bends
37
+ * over more than 4,096 units (then within 1/16,384 of its bend).
38
+ */
39
+ export declare const strokeCurve: (points: ReadonlyArray<PointJson>) => ReadonlyArray<PointJson>;
40
+ export declare const polylinePath: (points: ReadonlyArray<PointJson>) => string;
41
+ export interface Route {
42
+ /** At least two points, start first. */
43
+ readonly points: ReadonlyArray<PointJson>;
44
+ }
45
+ /**
46
+ * A connector's route. A bound end with a spot sits on that spot; a floating
47
+ * bound end leaves its shape's outline toward the other end (straight) or
48
+ * from the middle of the side facing it (elbow). An end bound to a missing
49
+ * shape, or both ends bound to one shape without spots, falls back to the
50
+ * connector's last planned route.
51
+ */
52
+ export declare const route: (shapes: Shapes, arrow: ArrowJson) => Route;
53
+ export declare const routeStart: (r: Route) => PointJson;
54
+ export declare const routeEnd: (r: Route) => PointJson;
55
+ /** The connector with its stored route brought up to date. */
56
+ export declare const withRoute: (shapes: Shapes, arrow: ArrowJson) => ArrowJson;
57
+ /** The box a shape occupies: its own, or its route's for a connector. */
58
+ export declare const bounds: (shapes: Shapes, shape: ShapeJson) => BoxJson;
59
+ export declare const boundsOf: (shapes: Shapes, ids: Iterable<string>) => BoxJson | null;
60
+ /** Field order for patches and diffs. */
61
+ declare const FIELDS: readonly ["x", "y", "w", "h", "z", "group", "locked", "text", "style", "from", "to", "points", "asset", "alt", "updatedBy"];
62
+ export type Field = (typeof FIELDS)[number];
63
+ export declare const jsonEqual: (a: unknown, b: unknown) => boolean;
64
+ /**
65
+ * Applies a patch to a shape. Returns null when a field does not belong to
66
+ * the shape's kind, or a style is not that kind's style.
67
+ */
68
+ export declare const patchShape: (shape: ShapeJson, fields: ShapeFieldsJson) => ShapeJson | null;
69
+ export type ChangeFailure = {
70
+ readonly _tag: "Missing";
71
+ readonly index: number;
72
+ readonly id: string;
73
+ } | {
74
+ readonly _tag: "Mismatch";
75
+ readonly index: number;
76
+ readonly id: string;
77
+ };
78
+ /** Applies row changes in order. Strict: every change must apply. */
79
+ export declare const applyChanges: (shapes: Map<string, ShapeJson>, changes: ReadonlyArray<ShapeChangeJson>) => ChangeFailure | null;
80
+ /**
81
+ * The changes that turn `before` into `after`, one per shape in id order,
82
+ * and their inverse.
83
+ */
84
+ export declare const diff: (before: Shapes, after: Shapes) => {
85
+ readonly changes: ReadonlyArray<ShapeChangeJson>;
86
+ readonly inverse: ReadonlyArray<ShapeChangeJson>;
87
+ };
88
+ /** The fields a patch sets, in field order. */
89
+ export declare const patchedFields: (fields: ShapeFieldsJson) => ReadonlyArray<Field>;
90
+ /** A one-field patch of `fields`, or null when it does not set `field`. */
91
+ export declare const pickField: (fields: ShapeFieldsJson, field: Field) => ShapeFieldsJson | null;
92
+ /** The current value of `field` on `shape`, as a one-field patch. */
93
+ export declare const currentField: (shape: ShapeJson, field: Field) => ShapeFieldsJson | null;
94
+ export interface History {
95
+ readonly records: ReadonlyMap<string, TransactionRecordJson>;
96
+ /** Which record first accepted or reverted each resolved transaction. */
97
+ readonly resolvedBy: ReadonlyMap<string, {
98
+ readonly by: string;
99
+ readonly as: "accepted" | "reverted";
100
+ }>;
101
+ }
102
+ export declare const history: (board: BoardJson) => History;
103
+ /** A record's size: UTF-8 bytes of its compact JSON. Key order does not change it. */
104
+ export declare const recordBytes: (record: TransactionRecordJson) => number;
105
+ /**
106
+ * Drops the oldest settled records until the log fits `HISTORY`. Pending
107
+ * proposals and the newest record stay. A record is settled once nothing can
108
+ * resolve it, and whatever resolved it is newer, so it goes first.
109
+ */
110
+ export declare const trimHistory: (log: ReadonlyArray<TransactionRecordJson>) => ReadonlyArray<TransactionRecordJson>;
111
+ /** Pending proposals in log order. */
112
+ export declare const pendingProposals: (board: BoardJson, h: History) => ReadonlyArray<TransactionRecordJson>;
113
+ /**
114
+ * Applies a proposal's changes to the current rows, leniently: a patch or
115
+ * removal of a shape that is gone is skipped, as is a patch the shape's kind
116
+ * no longer takes. Returns the id of a shape the proposal creates that
117
+ * already exists, if any, and applies nothing more after it.
118
+ */
119
+ export declare const applyProposal: (shapes: Map<string, ShapeJson>, record: TransactionRecordJson) => string | null;
120
+ /** Connectors that are among `ids` or attach to one of them, in id order. */
121
+ export declare const affectedArrows: (shapes: Shapes, ids: ReadonlySet<string>) => ReadonlyArray<string>;
122
+ /** Brings stored routes up to date for the given connectors. */
123
+ export declare const refreshRoutes: (shapes: Map<string, ShapeJson>, arrowIds: Iterable<string>) => void;
124
+ export interface BoardIndex {
125
+ readonly shapes: ReadonlyMap<string, ShapeJson>;
126
+ /** Back to front. */
127
+ readonly ordered: ReadonlyArray<ShapeJson>;
128
+ }
129
+ export declare const indexBoard: (board: BoardJson) => BoardIndex;
130
+ /** Stroke width and opacity of ink. */
131
+ export declare const inkStroke: (style: InkStyleJson) => {
132
+ readonly width: number;
133
+ readonly opacity: number;
134
+ };
135
+ /** A shape's outline as SVG path data, for hover and selection outlines. */
136
+ export declare const outlinePath: (shapes: Shapes, shape: ShapeJson) => string;
137
+ export {};
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Claims, the one rule `plan`, `editor`, `actions` and `scene` share.
3
+ *
4
+ * A claim is held per connection, not per actor: an actor's other
5
+ * connections (another tab) are refused like anyone else. When several
6
+ * connections claim a shape, the first in (actor, connection) order holds
7
+ * it, comparing actor and then connection by UTF-16 code units. Presence
8
+ * holds one entry per (actor, connection): the last sent, at its first's
9
+ * position.
10
+ */
11
+ import type { EditorModeJson, PresenceJson } from "./contract.js";
12
+ export interface Connection {
13
+ readonly actor: string;
14
+ readonly connection: string;
15
+ }
16
+ export interface Claimant extends Connection {
17
+ readonly name: string;
18
+ }
19
+ export declare const sameConnection: (a: Connection, b: Connection | null) => boolean;
20
+ /** One entry per connection: the last one sent, at its first's position. */
21
+ export declare const connections: (presence: ReadonlyArray<PresenceJson>) => ReadonlyArray<PresenceJson>;
22
+ /** The shapes an editor mode claims. */
23
+ export declare const claimsOf: (mode: EditorModeJson) => ReadonlyArray<string>;
24
+ /**
25
+ * Each claimed shape's claimants, holder first. `mine`, when given, stands
26
+ * for `self`'s claims in place of its presence entry (the editor's mode is
27
+ * newer than what it published).
28
+ */
29
+ export declare const claimants: (presence: ReadonlyArray<PresenceJson>, self: Connection | null, mine: ReadonlyArray<string> | null) => ReadonlyMap<string, ReadonlyArray<Claimant>>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Reading clipboard text back: hosts write `JSON.stringify(clipboard)` from a
3
+ * `Clipboard` action and pass what they read to `decodeClipboard`.
4
+ */
5
+ import type { ClipboardDecodeJson } from "./contract.js";
6
+ /**
7
+ * The board clipboard in `text`, `NotOurs` for any other text, or `Invalid`
8
+ * for a board clipboard this kernel cannot read. Never throws.
9
+ */
10
+ export declare const decodeClipboard: (text: string) => ClipboardDecodeJson;