@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,251 @@
1
+ import { listActions } from "./actions.jsx";
2
+ import { indexBoard } from "./board.jsx";
3
+ import { LIMITS } from "./constants.jsx";
4
+ import { array, id, run } from "./decode.jsx";
5
+ import { heldBy, initialState, step } from "./editor.jsx";
6
+ import { invalid, shapeNotFound } from "./errors.jsx";
7
+ import { isKey } from "./fractional-index.jsx";
8
+ import { hitTestIndex } from "./hit-test.jsx";
9
+ import { describeShape, inspectShapes, listProposals } from "./inspect.jsx";
10
+ import { outlineBoard } from "./outline.jsx";
11
+ import { applyPlan, planTransaction } from "./plan.jsx";
12
+ import { buildScene } from "./scene.jsx";
13
+ import { assets, board, editorInput, editorState, fonts, palette, plan, presence, probe, scene, session, transaction, viewport } from "./schema.jsx";
14
+ import { renderSvg } from "./svg.jsx";
15
+ import { loadFonts } from "./text.jsx";
16
+ // src/kernel/kernel.ts
17
+ /**
18
+ * The kernel surface: every argument is checked, every result is an
19
+ * `Outcome`, and nothing throws. Checked argument objects are remembered so a
20
+ * board passed again (every pointer move) is not checked again. Remembered
21
+ * objects are deep-frozen first, so a host cannot change one after its check.
22
+ */
23
+ /** Freezes `value` and everything it holds, skipping parts already frozen. */
24
+ const freeze = (value) => {
25
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return;
26
+ Object.freeze(value);
27
+ for (const child of Object.values(value)) freeze(child);
28
+ };
29
+ /**
30
+ * A checker for one guard that remembers the objects it accepted, keyed by
31
+ * identity, so an unchanged argument passed again costs one lookup.
32
+ */
33
+ const checker = (guard) => {
34
+ const accepted = /* @__PURE__ */ new WeakMap();
35
+ return {
36
+ check: (value, path) => {
37
+ if (typeof value === "object" && value !== null) {
38
+ const known = accepted.get(value);
39
+ if (known !== void 0) return { ok: known };
40
+ }
41
+ const result = run(guard, value, path);
42
+ if ("issue" in result) return { error: invalid(result.issue.path, result.issue.expected, "Build the value to the matching *Json type the package exports.") };
43
+ if (typeof result.ok === "object" && result.ok !== null) {
44
+ freeze(result.ok);
45
+ accepted.set(result.ok, result.ok);
46
+ }
47
+ return result;
48
+ },
49
+ remember: (value) => {
50
+ if (typeof value === "object" && value !== null) {
51
+ freeze(value);
52
+ accepted.set(value, value);
53
+ }
54
+ }
55
+ };
56
+ };
57
+ const guards = {
58
+ actor: checker(id),
59
+ assets: checker(assets),
60
+ board: checker(board),
61
+ editorInput: checker(editorInput),
62
+ editorState: checker(editorState),
63
+ fonts: checker(fonts),
64
+ id: checker(id),
65
+ ids: checker(array(id, LIMITS.ids)),
66
+ palette: checker(palette),
67
+ plan: checker(plan),
68
+ presence: checker(presence),
69
+ probe: checker(probe),
70
+ scene: checker(scene),
71
+ session: checker(session),
72
+ transaction: checker(transaction),
73
+ viewport: checker(viewport)
74
+ };
75
+ const boards = /* @__PURE__ */ new WeakSet();
76
+ /** Rules the structure cannot state: unique ids and well-formed z keys. */
77
+ const checkBoard = (value, path) => {
78
+ const result = guards.board.check(value, path);
79
+ if ("error" in result || boards.has(result.ok)) return result;
80
+ const board = result.ok;
81
+ const ids = /* @__PURE__ */ new Set();
82
+ for (const [i, shape] of board.shapes.entries()) {
83
+ if (ids.has(shape.id)) return { error: invalid([
84
+ ...path,
85
+ "shapes",
86
+ i,
87
+ "id"
88
+ ], "an id no other shape has", "Store one row per shape id.") };
89
+ ids.add(shape.id);
90
+ if (!isKey(shape.z)) return { error: invalid([
91
+ ...path,
92
+ "shapes",
93
+ i,
94
+ "z"
95
+ ], "a fractional index from the kernel", "Keep z as the kernel planned it.") };
96
+ }
97
+ const transactions = /* @__PURE__ */ new Set();
98
+ let seq = 0;
99
+ for (const [i, record] of board.transactions.entries()) {
100
+ if (record.seq <= seq || record.seq > board.head) return { error: invalid([
101
+ ...path,
102
+ "transactions",
103
+ i,
104
+ "seq"
105
+ ], `a number above ${seq} and at most the head, ${board.head}`, "Store the board exactly as apply returned it.") };
106
+ seq = record.seq;
107
+ if (transactions.has(record.id)) return { error: invalid([
108
+ ...path,
109
+ "transactions",
110
+ i,
111
+ "id"
112
+ ], "an id no other transaction has", "Append each plan's record once.") };
113
+ transactions.add(record.id);
114
+ }
115
+ boards.add(board);
116
+ return result;
117
+ };
118
+ /**
119
+ * Loads a kernel with the font advance tables text is measured with. The
120
+ * one asynchronous call, so a WebAssembly kernel can load the same way.
121
+ */
122
+ const loadKernel = async (fontData) => {
123
+ const data = guards.fonts.check(fontData, ["fonts"]);
124
+ if ("error" in data) return data;
125
+ const fonts = loadFonts(data.ok);
126
+ if ("_tag" in fonts) return { error: fonts };
127
+ return { ok: {
128
+ plan: (board, transaction, actor, presence, connection) => {
129
+ const b = checkBoard(board, ["board"]);
130
+ if ("error" in b) return b;
131
+ const t = guards.transaction.check(transaction, ["transaction"]);
132
+ if ("error" in t) return t;
133
+ const a = guards.id.check(actor, ["actor"]);
134
+ if ("error" in a) return a;
135
+ const p = guards.presence.check(presence, ["presence"]);
136
+ if ("error" in p) return p;
137
+ if (connection !== null) {
138
+ const c = guards.id.check(connection, ["connection"]);
139
+ if ("error" in c) return c;
140
+ }
141
+ return planTransaction(fonts, b.ok, t.ok, a.ok, p.ok, connection);
142
+ },
143
+ apply: (board, plan) => {
144
+ const b = checkBoard(board, ["board"]);
145
+ if ("error" in b) return b;
146
+ const p = guards.plan.check(plan, ["plan"]);
147
+ if ("error" in p) return p;
148
+ const result = applyPlan(b.ok, p.ok);
149
+ if ("ok" in result) {
150
+ guards.board.remember(result.ok);
151
+ boards.add(result.ok);
152
+ }
153
+ return result;
154
+ },
155
+ scene: (board, view, presence, editor) => {
156
+ const b = checkBoard(board, ["board"]);
157
+ if ("error" in b) return b;
158
+ const v = guards.viewport.check(view, ["view"]);
159
+ if ("error" in v) return v;
160
+ const p = guards.presence.check(presence, ["presence"]);
161
+ if ("error" in p) return p;
162
+ if (editor !== null) {
163
+ const e = guards.editorState.check(editor, ["editor"]);
164
+ if ("error" in e) return e;
165
+ }
166
+ return { ok: buildScene(fonts, b.ok, indexBoard(b.ok), v.ok, p.ok, editor) };
167
+ },
168
+ hitTest: (board, probe) => {
169
+ const b = checkBoard(board, ["board"]);
170
+ if ("error" in b) return b;
171
+ const p = guards.probe.check(probe, ["probe"]);
172
+ if ("error" in p) return p;
173
+ return { ok: hitTestIndex(indexBoard(b.ok), p.ok) };
174
+ },
175
+ outline: (board, presence) => {
176
+ const b = checkBoard(board, ["board"]);
177
+ if ("error" in b) return b;
178
+ const p = guards.presence.check(presence, ["presence"]);
179
+ if ("error" in p) return p;
180
+ return { ok: outlineBoard(b.ok, indexBoard(b.ok), p.ok) };
181
+ },
182
+ toSvg: (scene, palette, assets = {}, options = {}) => {
183
+ const s = guards.scene.check(scene, ["scene"]);
184
+ if ("error" in s) return s;
185
+ const p = guards.palette.check(palette, ["palette"]);
186
+ if ("error" in p) return p;
187
+ const a = guards.assets.check(assets, ["assets"]);
188
+ if ("error" in a) return a;
189
+ const given = options;
190
+ if (typeof given !== "object" || given === null) return { error: invalid(["options"], "an object", "Pass { formatInstant } or leave it out.") };
191
+ const format = Reflect.get(given, "formatInstant");
192
+ if (format !== void 0 && typeof format !== "function") return { error: invalid(["options", "formatInstant"], "a function from epoch milliseconds to a string", "Pass a formatter such as (ms) => new Date(ms).toLocaleString(), or leave it out.") };
193
+ return { ok: renderSvg(s.ok, p.ok, a.ok, options.formatInstant) };
194
+ },
195
+ editor: (state, board, input, presence) => {
196
+ const s = guards.editorState.check(state, ["state"]);
197
+ if ("error" in s) return s;
198
+ const b = checkBoard(board, ["board"]);
199
+ if ("error" in b) return b;
200
+ const i = guards.editorInput.check(input, ["input"]);
201
+ if ("error" in i) return i;
202
+ const p = guards.presence.check(presence, ["presence"]);
203
+ if ("error" in p) return p;
204
+ const result = step(fonts, s.ok, b.ok, indexBoard(b.ok), i.ok, p.ok);
205
+ if ("ok" in result) guards.editorState.remember(result.ok.state);
206
+ return result;
207
+ },
208
+ actions: (state, board, presence) => {
209
+ const s = guards.editorState.check(state, ["state"]);
210
+ if ("error" in s) return s;
211
+ const b = checkBoard(board, ["board"]);
212
+ if ("error" in b) return b;
213
+ const p = guards.presence.check(presence, ["presence"]);
214
+ if ("error" in p) return p;
215
+ const index = indexBoard(b.ok);
216
+ return { ok: listActions(s.ok, index, inspectShapes(index, s.ok.selection).can, heldBy(s.ok, p.ok)) };
217
+ },
218
+ inspect: (board, ids) => {
219
+ const b = checkBoard(board, ["board"]);
220
+ if ("error" in b) return b;
221
+ const i = guards.ids.check(ids, ["ids"]);
222
+ if ("error" in i) return i;
223
+ return { ok: inspectShapes(indexBoard(b.ok), i.ok) };
224
+ },
225
+ describe: (board, id) => {
226
+ const b = checkBoard(board, ["board"]);
227
+ if ("error" in b) return b;
228
+ const i = guards.id.check(id, ["id"]);
229
+ if ("error" in i) return i;
230
+ const index = indexBoard(b.ok);
231
+ const shape = index.shapes.get(i.ok);
232
+ if (shape === void 0) return { error: shapeNotFound(["id"], i.ok, index.shapes.keys()) };
233
+ return { ok: describeShape(index, shape) };
234
+ },
235
+ proposals: (board) => {
236
+ const b = checkBoard(board, ["board"]);
237
+ if ("error" in b) return b;
238
+ return { ok: listProposals(b.ok, indexBoard(b.ok)) };
239
+ },
240
+ initialEditor: (session, view) => {
241
+ const s = guards.session.check(session, ["session"]);
242
+ if ("error" in s) return s;
243
+ const v = guards.viewport.check(view, ["view"]);
244
+ if ("error" in v) return v;
245
+ const state = initialState(s.ok, v.ok);
246
+ guards.editorState.remember(state);
247
+ return { ok: state };
248
+ }
249
+ } };
250
+ };
251
+ export { loadKernel };
@@ -0,0 +1,64 @@
1
+ import { bounds, history, pendingProposals } from "./board.jsx";
2
+ import { formatNumber, isoInstant } from "./geometry.jsx";
3
+ // src/kernel/outline.ts
4
+ const anchorText = (anchor) => anchor._tag === "Point" ? `(${formatNumber(anchor.x)}, ${formatNumber(anchor.y)})` : anchor.at === null ? anchor.id : `${anchor.id}@(${formatNumber(anchor.at.x)}, ${formatNumber(anchor.at.y)})`;
5
+ const shapeLine = (index, shape) => {
6
+ const b = bounds(index.shapes, shape);
7
+ const flags = [...shape.group === null ? [] : [`group ${shape.group}`], ...shape.locked ? ["locked"] : []];
8
+ const tail = flags.length === 0 ? "" : ` [${flags.join(", ")}]`;
9
+ const at = `at (${formatNumber(b.x)}, ${formatNumber(b.y)}) size ${formatNumber(b.w)}×${formatNumber(b.h)}`;
10
+ switch (shape.kind) {
11
+ case "Sticky": return `${shape.id}: ${shape.style.color} sticky ${at} ${JSON.stringify(shape.text)}${tail}`;
12
+ case "Box": return `${shape.id}: ${shape.style.color} ${shape.style.form} ${at}${shape.text === "" ? "" : ` ${JSON.stringify(shape.text)}`}${tail}`;
13
+ case "Text": return `${shape.id}: ${shape.style.color} text ${at} ${JSON.stringify(shape.text)}${tail}`;
14
+ case "Arrow": return `${shape.id}: ${shape.style.color} ${shape.style.route} connector from ${anchorText(shape.from)} to ${anchorText(shape.to)}${tail}`;
15
+ case "Ink": return `${shape.id}: ${shape.style.color} ${shape.style.brush} stroke ${at}, ${shape.points.length} points${tail}`;
16
+ case "Image": return `${shape.id}: image ${at} ${shape.alt === "" ? "(no description)" : JSON.stringify(shape.alt)}${tail}`;
17
+ case "Timestamp": return `${shape.id}: timestamp ${at} ${isoInstant(shape.at)}${tail}`;
18
+ }
19
+ };
20
+ const activityText = (entry, index) => {
21
+ const a = entry.activity;
22
+ switch (a._tag) {
23
+ case "Idle": return "idle";
24
+ case "Thinking": return `thinking: ${a.label}`;
25
+ case "Working": return `working: ${a.label}`;
26
+ case "Gesture": return `moving ${a.shapes.map((t) => t.id).join(", ")}`;
27
+ case "Resizing": return `resizing ${a.ids.join(", ")}`;
28
+ case "Selecting": return "selecting";
29
+ case "Creating": return `drawing a ${a.draft}`;
30
+ case "Connecting": return a.arrow !== null && index.shapes.has(a.arrow) ? `moving an end of ${a.arrow}` : "drawing a connector";
31
+ case "Inking": return "drawing ink";
32
+ case "Erasing": return "erasing";
33
+ case "Typing": return `typing in ${a.id}`;
34
+ }
35
+ };
36
+ const outlineBoard = (board, index, presence) => {
37
+ const lines = [];
38
+ const count = index.ordered.length;
39
+ lines.push(`Board: ${count} ${count === 1 ? "shape" : "shapes"}, back to front.`);
40
+ for (const shape of index.ordered) lines.push(`- ${shapeLine(index, shape)}`);
41
+ const pending = pendingProposals(board, history(board));
42
+ if (pending.length > 0) {
43
+ lines.push("Pending proposals:");
44
+ for (const record of pending) {
45
+ const by = record.author.via === null ? record.author.principal : `${record.author.via} for ${record.author.principal}`;
46
+ lines.push(`- ${record.id} by ${by}${record.reason === null ? "" : `: ${JSON.stringify(record.reason)}`}; touches ${record.shapes.join(", ")}`);
47
+ }
48
+ }
49
+ if (presence.length > 0) {
50
+ lines.push("Here now:");
51
+ for (const entry of new Map(presence.map((e) => [e.actor, e])).values()) {
52
+ const parts = [
53
+ `${entry.name} (${entry.kind}, ${entry.actor})`,
54
+ activityText(entry, index),
55
+ ...entry.selection.length === 0 ? [] : [`selected ${entry.selection.join(", ")}`],
56
+ ...entry.claims.length === 0 ? [] : [`editing ${entry.claims.join(", ")}`],
57
+ ...entry.chat === null ? [] : [`chat ${JSON.stringify(entry.chat)}`]
58
+ ];
59
+ lines.push(`- ${parts.join("; ")}`);
60
+ }
61
+ }
62
+ return `${lines.join("\n")}\n`;
63
+ };
64
+ export { outlineBoard };