@kitionstage/sdk 0.0.0-stage → 0.5.2-stage.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/README.md +69 -2
  2. package/dist/LICENSE +177 -0
  3. package/dist/THIRD_PARTY_NOTICES +28 -0
  4. package/dist/lib/assets/kitEngine.worker-9haDiVHZ.js +13220 -0
  5. package/dist/lib/chunks/batch-BWpAyHvP.js +789 -0
  6. package/dist/lib/chunks/canonical-BIWfVCL-.js +87 -0
  7. package/dist/lib/chunks/envelope-D6MGY-ZN.js +61 -0
  8. package/dist/lib/chunks/replica-D8w3I4sn.js +2472 -0
  9. package/dist/lib/chunks/runtime-BVJHE1Pg.js +997 -0
  10. package/dist/lib/chunks/session-BqXC9a1-.js +281 -0
  11. package/dist/lib/chunks/toolIds-BCeSGHpV.js +821 -0
  12. package/dist/lib/chunks/workspaceTree-Destqupf.js +23 -0
  13. package/dist/lib/convergence/index.js +1035 -0
  14. package/dist/lib/convergence/node.js +8 -0
  15. package/dist/lib/embed-server/callbacks.js +37 -0
  16. package/dist/lib/embed-server/cli.js +19 -0
  17. package/dist/lib/embed-server/index.js +272 -0
  18. package/dist/lib/extensions/index.js +439 -0
  19. package/dist/lib/extensions/panel.html +208 -0
  20. package/dist/lib/extensions/runtime.js +198 -0
  21. package/dist/lib/extensions/sandbox.html +35 -0
  22. package/dist/lib/kdm/index.js +437 -0
  23. package/dist/lib/kit-dev-host/checkUiIds.mjs +44 -0
  24. package/dist/lib/kit-dev-host/index.js +308 -0
  25. package/dist/lib/kit-dev-host/lineRow.mjs +47 -0
  26. package/dist/lib/kit-dev-host/modeSmoke.mjs +178 -0
  27. package/dist/lib/kit-editor/index.js +6489 -0
  28. package/dist/lib/kit-editor/styles.css +807 -0
  29. package/dist/lib/kit-editor/workspaceTree.js +1 -0
  30. package/dist/lib/kit-engine/index.js +7 -0
  31. package/dist/lib/kit-host/index.js +530 -0
  32. package/dist/lib/kit-ui-protocol/index.js +336 -0
  33. package/dist/lib/node-only/embed-server-callbacks.js +2 -0
  34. package/dist/lib/node-only/embed-server.js +2 -0
  35. package/dist/lib/sync/index.js +1008 -0
  36. package/dist/lib/sync/openToken.js +201 -0
  37. package/dist/lib/sync/replicaVersions.js +51 -0
  38. package/dist/standalone/chunks/batch-CAGYk6m4.js +789 -0
  39. package/dist/standalone/chunks/client-B9xkOcvf.js +772 -0
  40. package/dist/standalone/chunks/collab-B5TbpTyO.js +1022 -0
  41. package/dist/standalone/chunks/comment-Ds9t8xSE.js +94 -0
  42. package/dist/standalone/chunks/comments-uVDS8Wxp.js +41 -0
  43. package/dist/standalone/chunks/document-CuIGSDsY.js +324 -0
  44. package/dist/standalone/chunks/envelope-GX4Cynkx.js +7612 -0
  45. package/dist/standalone/chunks/index-BEgEEnhU.js +287 -0
  46. package/dist/standalone/chunks/index-Blc_B6iX.js +1967 -0
  47. package/dist/standalone/chunks/kits-Cp51mDlw.js +9 -0
  48. package/dist/standalone/chunks/replica-Di2iCPiD.js +3281 -0
  49. package/dist/standalone/chunks/replicaVersions-C3rJxnk9.js +50 -0
  50. package/dist/standalone/chunks/touched-T9jKJjxn.js +78 -0
  51. package/dist/standalone/index.js +12 -0
  52. package/dist/standalone/script/index.js +339 -0
  53. package/dist/standalone/script/kits/board.js +5 -0
  54. package/dist/standalone/script/kits/cad.js +5 -0
  55. package/dist/standalone/script/kits/design.js +5 -0
  56. package/dist/standalone/script/kits/doc.js +5 -0
  57. package/dist/standalone/script/kits/film.js +5 -0
  58. package/dist/standalone/script/kits/html.js +5 -0
  59. package/dist/standalone/script/kits/index.js +38 -0
  60. package/dist/standalone/script/kits/layout.js +5 -0
  61. package/dist/standalone/script/kits/motion.js +5 -0
  62. package/dist/standalone/script/kits/note.js +5 -0
  63. package/dist/standalone/script/kits/pdf.js +5 -0
  64. package/dist/standalone/script/kits/photo.js +5 -0
  65. package/dist/standalone/script/kits/scene.js +5 -0
  66. package/dist/standalone/script/kits/sheet.js +5 -0
  67. package/dist/standalone/script/kits/slide.js +5 -0
  68. package/dist/standalone/script/kits/table.js +5 -0
  69. package/dist/standalone/script/kits/vector.js +5 -0
  70. package/dist/standalone/script/node.js +401 -0
  71. package/dist/standalone/script/proxy.js +254 -0
  72. package/dist/types/convergence/src/adapter.d.ts +131 -0
  73. package/dist/types/convergence/src/engine.d.ts +66 -0
  74. package/dist/types/convergence/src/index.d.ts +21 -0
  75. package/dist/types/convergence/src/net.d.ts +52 -0
  76. package/dist/types/convergence/src/node.d.ts +6 -0
  77. package/dist/types/convergence/src/report.d.ts +56 -0
  78. package/dist/types/convergence/src/rng.d.ts +12 -0
  79. package/dist/types/convergence/src/scenarios.d.ts +15 -0
  80. package/dist/types/convergence/src/state.d.ts +67 -0
  81. package/dist/types/embed/src/agent.d.ts +88 -0
  82. package/dist/types/embed/src/blobs.d.ts +2 -0
  83. package/dist/types/embed/src/collab.d.ts +250 -0
  84. package/dist/types/embed/src/comments.d.ts +30 -0
  85. package/dist/types/embed/src/errors.d.ts +24 -0
  86. package/dist/types/embed/src/handlers.d.ts +92 -0
  87. package/dist/types/embed/src/index.d.ts +20 -0
  88. package/dist/types/embed/src/mount.d.ts +39 -0
  89. package/dist/types/embed/src/replicaStore.d.ts +3 -0
  90. package/dist/types/embed/src/rooms.d.ts +40 -0
  91. package/dist/types/embed/src/schemas.d.ts +7 -0
  92. package/dist/types/embed/src/syncClients.d.ts +28 -0
  93. package/dist/types/embed/src/theme.d.ts +7 -0
  94. package/dist/types/embed/src/types.d.ts +596 -0
  95. package/dist/types/embed/src/ui.d.ts +33 -0
  96. package/dist/types/embed/src/version.d.ts +2 -0
  97. package/dist/types/embed-server/src/callbacks.d.ts +30 -0
  98. package/dist/types/embed-server/src/cli.d.ts +1 -0
  99. package/dist/types/embed-server/src/index.d.ts +19 -0
  100. package/dist/types/embed-server/src/page.d.ts +15 -0
  101. package/dist/types/embed-server/src/server.d.ts +39 -0
  102. package/dist/types/embed-server/src/session.d.ts +22 -0
  103. package/dist/types/extensions/src/gate.d.ts +17 -0
  104. package/dist/types/extensions/src/generated/runtime.d.ts +8 -0
  105. package/dist/types/extensions/src/host.d.ts +135 -0
  106. package/dist/types/extensions/src/index.d.ts +13 -0
  107. package/dist/types/extensions/src/manifest.d.ts +82 -0
  108. package/dist/types/extensions/src/protocol.d.ts +159 -0
  109. package/dist/types/extensions/src/rpc.d.ts +52 -0
  110. package/dist/types/extensions/src/runtime/document.d.ts +40 -0
  111. package/dist/types/extensions/src/runtime/index.d.ts +10 -0
  112. package/dist/types/extensions/src/runtime/panel.d.ts +19 -0
  113. package/dist/types/extensions/src/runtime/runtime.d.ts +54 -0
  114. package/dist/types/extensions/src/runtime/worker.d.ts +1 -0
  115. package/dist/types/extensions/src/sandbox.d.ts +41 -0
  116. package/dist/types/kdm/src/args.d.ts +12 -0
  117. package/dist/types/kdm/src/batch.d.ts +118 -0
  118. package/dist/types/kdm/src/canonical.d.ts +25 -0
  119. package/dist/types/kdm/src/comment.d.ts +114 -0
  120. package/dist/types/kdm/src/diff.d.ts +125 -0
  121. package/dist/types/kdm/src/envelope.d.ts +27 -0
  122. package/dist/types/kdm/src/errors.d.ts +28 -0
  123. package/dist/types/kdm/src/footprint.d.ts +21 -0
  124. package/dist/types/kdm/src/ids.d.ts +57 -0
  125. package/dist/types/kdm/src/index.d.ts +18 -0
  126. package/dist/types/kdm/src/marks.d.ts +32 -0
  127. package/dist/types/kdm/src/op.d.ts +124 -0
  128. package/dist/types/kdm/src/origin.d.ts +41 -0
  129. package/dist/types/kdm/src/overlay.d.ts +92 -0
  130. package/dist/types/kdm/src/projection.d.ts +29 -0
  131. package/dist/types/kdm/src/read.d.ts +90 -0
  132. package/dist/types/kdm/src/replica.d.ts +403 -0
  133. package/dist/types/kdm/src/schema.d.ts +185 -0
  134. package/dist/types/kdm/src/testing.d.ts +28 -0
  135. package/dist/types/kdm/src/toolIds.d.ts +61 -0
  136. package/dist/types/kdm/src/touched.d.ts +24 -0
  137. package/dist/types/kdm/src/tx.d.ts +215 -0
  138. package/dist/types/kdm/src/value.d.ts +23 -0
  139. package/dist/types/kit-dev-host/src/checkNoPaths.d.ts +19 -0
  140. package/dist/types/kit-dev-host/src/checkUiIds.d.mts +2 -0
  141. package/dist/types/kit-dev-host/src/index.d.ts +179 -0
  142. package/dist/types/kit-dev-host/src/lineRow.d.mts +14 -0
  143. package/dist/types/kit-dev-host/src/memoryFiles.d.ts +15 -0
  144. package/dist/types/kit-dev-host/src/modeSmoke.d.mts +8 -0
  145. package/dist/types/kit-editor/src/CommandDialog.d.ts +22 -0
  146. package/dist/types/kit-editor/src/CommentsPanel.d.ts +45 -0
  147. package/dist/types/kit-editor/src/CustomizeDialog.d.ts +32 -0
  148. package/dist/types/kit-editor/src/HostButtons.d.ts +11 -0
  149. package/dist/types/kit-editor/src/RenderFailure.d.ts +7 -0
  150. package/dist/types/kit-editor/src/TextSink.d.ts +6 -0
  151. package/dist/types/kit-editor/src/brand.d.ts +2 -0
  152. package/dist/types/kit-editor/src/catalogMenus.d.ts +27 -0
  153. package/dist/types/kit-editor/src/chart.d.ts +138 -0
  154. package/dist/types/kit-editor/src/conflicts.d.ts +12 -0
  155. package/dist/types/kit-editor/src/drawing.d.ts +83 -0
  156. package/dist/types/kit-editor/src/editor.d.ts +544 -0
  157. package/dist/types/kit-editor/src/engine/KitCanvas.d.ts +70 -0
  158. package/dist/types/kit-editor/src/engine/backdrop.d.ts +32 -0
  159. package/dist/types/kit-editor/src/engine/createKitFile.d.ts +12 -0
  160. package/dist/types/kit-editor/src/engine/decorations.d.ts +14 -0
  161. package/dist/types/kit-editor/src/engine/engineOverlays.d.ts +197 -0
  162. package/dist/types/kit-editor/src/engine/engineTools.d.ts +116 -0
  163. package/dist/types/kit-editor/src/engine/kitDraft.d.ts +70 -0
  164. package/dist/types/kit-editor/src/engine/kitEngine.d.ts +390 -0
  165. package/dist/types/kit-editor/src/engine/kitEngine.worker.d.ts +30 -0
  166. package/dist/types/kit-editor/src/engine/kitHost.d.ts +41 -0
  167. package/dist/types/kit-editor/src/engine/kitModel.d.ts +32 -0
  168. package/dist/types/kit-editor/src/engine/kitModelRunner.d.ts +99 -0
  169. package/dist/types/kit-editor/src/engine/kitModule.d.ts +185 -0
  170. package/dist/types/kit-editor/src/engine/kitShortcuts.d.ts +32 -0
  171. package/dist/types/kit-editor/src/engine/kitTools.d.ts +79 -0
  172. package/dist/types/kit-editor/src/engine/lazyFonts.d.ts +34 -0
  173. package/dist/types/kit-editor/src/engine/lentFiles.d.ts +29 -0
  174. package/dist/types/kit-editor/src/engine/rasterViewport.d.ts +178 -0
  175. package/dist/types/kit-editor/src/engine/readOnly.d.ts +78 -0
  176. package/dist/types/kit-editor/src/engine/refusal.d.ts +39 -0
  177. package/dist/types/kit-editor/src/engine/replica.d.ts +23 -0
  178. package/dist/types/kit-editor/src/engine/useKitDocument.d.ts +154 -0
  179. package/dist/types/kit-editor/src/engine/workerRelay.d.ts +62 -0
  180. package/dist/types/kit-editor/src/files.d.ts +74 -0
  181. package/dist/types/kit-editor/src/frame/EditorFrame.d.ts +74 -0
  182. package/dist/types/kit-editor/src/frame/FocusBar.d.ts +10 -0
  183. package/dist/types/kit-editor/src/frame/MenuNodes.d.ts +20 -0
  184. package/dist/types/kit-editor/src/frame/MenuRibbon.d.ts +8 -0
  185. package/dist/types/kit-editor/src/frame/ModeButton.d.ts +7 -0
  186. package/dist/types/kit-editor/src/frame/menus.d.ts +64 -0
  187. package/dist/types/kit-editor/src/frame/modes.d.ts +51 -0
  188. package/dist/types/kit-editor/src/frame/useFrameLayout.d.ts +34 -0
  189. package/dist/types/kit-editor/src/host.d.ts +127 -0
  190. package/dist/types/kit-editor/src/index.d.ts +85 -0
  191. package/dist/types/kit-editor/src/ink.d.ts +26 -0
  192. package/dist/types/kit-editor/src/lease.d.ts +53 -0
  193. package/dist/types/kit-editor/src/oneInFlight.d.ts +7 -0
  194. package/dist/types/kit-editor/src/phrases.d.ts +25 -0
  195. package/dist/types/kit-editor/src/presence.d.ts +79 -0
  196. package/dist/types/kit-editor/src/strings.d.ts +6 -0
  197. package/dist/types/kit-editor/src/toolIcons.d.ts +32 -0
  198. package/dist/types/kit-editor/src/uiCatalog.d.ts +59 -0
  199. package/dist/types/kit-editor/src/uiConfig.d.ts +53 -0
  200. package/dist/types/kit-editor/src/uiContext.d.ts +65 -0
  201. package/dist/types/kit-editor/src/uiStore.d.ts +20 -0
  202. package/dist/types/kit-editor/src/useCommentAnchors.d.ts +29 -0
  203. package/dist/types/kit-editor/src/useKitSession.d.ts +115 -0
  204. package/dist/types/kit-editor/src/workspaceTree.d.ts +5 -0
  205. package/dist/types/kit-engine/src/contract.d.ts +154 -0
  206. package/dist/types/kit-engine/src/index.d.ts +2 -0
  207. package/dist/types/kit-engine/src/session.d.ts +133 -0
  208. package/dist/types/kit-host/src/files.d.ts +163 -0
  209. package/dist/types/kit-host/src/index.d.ts +315 -0
  210. package/dist/types/kit-ui-protocol/src/index.d.ts +1145 -0
  211. package/dist/types/loro-crdt.d.ts +9 -0
  212. package/dist/types/script/kits/board.d.ts +534 -0
  213. package/dist/types/script/kits/cad.d.ts +2937 -0
  214. package/dist/types/script/kits/design.d.ts +3213 -0
  215. package/dist/types/script/kits/doc.d.ts +2575 -0
  216. package/dist/types/script/kits/film.d.ts +4067 -0
  217. package/dist/types/script/kits/html.d.ts +38 -0
  218. package/dist/types/script/kits/index.d.ts +20 -0
  219. package/dist/types/script/kits/layout.d.ts +3483 -0
  220. package/dist/types/script/kits/motion.d.ts +4826 -0
  221. package/dist/types/script/kits/note.d.ts +631 -0
  222. package/dist/types/script/kits/pdf.d.ts +829 -0
  223. package/dist/types/script/kits/photo.d.ts +7574 -0
  224. package/dist/types/script/kits/scene.d.ts +2962 -0
  225. package/dist/types/script/kits/sheet.d.ts +2419 -0
  226. package/dist/types/script/kits/slide.d.ts +1894 -0
  227. package/dist/types/script/kits/table.d.ts +654 -0
  228. package/dist/types/script/kits/vector.d.ts +5167 -0
  229. package/dist/types/script/src/agentRelay.d.ts +48 -0
  230. package/dist/types/script/src/capabilities.d.ts +21 -0
  231. package/dist/types/script/src/document.d.ts +87 -0
  232. package/dist/types/script/src/drafts.d.ts +141 -0
  233. package/dist/types/script/src/exchange.d.ts +30 -0
  234. package/dist/types/script/src/headless.d.ts +190 -0
  235. package/dist/types/script/src/index.d.ts +15 -0
  236. package/dist/types/script/src/kitModel.d.ts +17 -0
  237. package/dist/types/script/src/kits.d.ts +8 -0
  238. package/dist/types/script/src/node.d.ts +42 -0
  239. package/dist/types/script/src/port.d.ts +89 -0
  240. package/dist/types/script/src/proxy.d.ts +132 -0
  241. package/dist/types/script/src/room.d.ts +162 -0
  242. package/dist/types/script/src/sources.d.ts +73 -0
  243. package/dist/types/sync/src/backoff.d.ts +9 -0
  244. package/dist/types/sync/src/blobSection.d.ts +23 -0
  245. package/dist/types/sync/src/capabilities.d.ts +20 -0
  246. package/dist/types/sync/src/client.d.ts +253 -0
  247. package/dist/types/sync/src/framing.d.ts +35 -0
  248. package/dist/types/sync/src/hash.d.ts +2 -0
  249. package/dist/types/sync/src/index.d.ts +19 -0
  250. package/dist/types/sync/src/leases.d.ts +82 -0
  251. package/dist/types/sync/src/openToken.d.ts +104 -0
  252. package/dist/types/sync/src/protocol.d.ts +484 -0
  253. package/dist/types/sync/src/relay.d.ts +52 -0
  254. package/dist/types/sync/src/replicaVersions.d.ts +17 -0
  255. package/dist/types/sync/src/saveMachine.d.ts +83 -0
  256. package/dist/types/sync/src/saveRun.d.ts +52 -0
  257. package/dist/types/sync/src/transport.d.ts +19 -0
  258. package/package.json +229 -4
@@ -0,0 +1,821 @@
1
+ import { K as G, s as I, e as f, c as A } from "./canonical-BIWfVCL-.js";
2
+ function xe(t) {
3
+ return t === "person" || t === "extension" ? "person" : t === "agent" ? "agent" : null;
4
+ }
5
+ const Ae = (t, e) => ({ kind: "person", principal: t, label: e }), Se = (t, e) => ({ kind: "agent", principal: t, label: e }), Ie = (t) => ({ kind: "system", principal: "kdm", label: t });
6
+ function Ne(t) {
7
+ return JSON.stringify([t.kind, t.principal, t.label ?? null]);
8
+ }
9
+ const V = ["person", "agent", "extension", "import", "system"];
10
+ function qe(t) {
11
+ const e = t !== null && typeof t == "object" ? t : null;
12
+ if (!(e !== null && typeof e.kind == "string" && V.includes(e.kind) && typeof e.principal == "string" && (e.label === void 0 || typeof e.label == "string"))) throw new G("invalid-value", `an origin needs a kind (${V.join(", ")}), a string principal, and an optional string label`);
13
+ }
14
+ function Me(t, e) {
15
+ return JSON.stringify([t.kind, t.principal, t.label ?? null, e]);
16
+ }
17
+ function We(t) {
18
+ const e = B(t);
19
+ if (e === null) return null;
20
+ const o = JSON.parse(t)[3];
21
+ return { origin: e, schemaVersion: typeof o == "number" && Number.isInteger(o) && o >= 0 ? o : null };
22
+ }
23
+ function B(t) {
24
+ let e;
25
+ try {
26
+ e = JSON.parse(t);
27
+ } catch {
28
+ return null;
29
+ }
30
+ return !Array.isArray(e) || typeof e[0] != "string" || !V.includes(e[0]) || typeof e[1] != "string" ? null : { kind: e[0], principal: e[1], label: typeof e[2] == "string" ? e[2] : void 0 };
31
+ }
32
+ const Q = (t) => t >= 56320 && t <= 57343;
33
+ function J(t) {
34
+ let e = "", o = 0;
35
+ for (let s = 0; s < t.length; s += 1) {
36
+ const n = t.charCodeAt(s);
37
+ if (!(n < 55296 || n > 57343)) {
38
+ if (n <= 56319 && Q(t.charCodeAt(s + 1))) {
39
+ s += 1;
40
+ continue;
41
+ }
42
+ e += `${t.slice(o, s)}�`, o = s + 1;
43
+ }
44
+ }
45
+ return o === 0 ? t : e + t.slice(o);
46
+ }
47
+ const Y = (t) => {
48
+ const e = Object.getPrototypeOf(t);
49
+ return e === Object.prototype || e === null;
50
+ };
51
+ function ee(t, e) {
52
+ const o = /* @__PURE__ */ new Set(), s = (n, i) => {
53
+ const a = (r) => {
54
+ throw e(`holds ${r}${i ? ` at ${i}` : ""}, which is not JSON`);
55
+ };
56
+ switch (typeof n) {
57
+ case "string":
58
+ return J(n);
59
+ case "boolean":
60
+ return n;
61
+ case "number":
62
+ return Number.isFinite(n) ? n : a(String(n));
63
+ case "object":
64
+ break;
65
+ default:
66
+ return a(typeof n > "u" ? "undefined" : `a ${typeof n}`);
67
+ }
68
+ if (n === null) return null;
69
+ o.has(n) && a("a cycle"), o.add(n);
70
+ try {
71
+ if (Array.isArray(n)) {
72
+ Object.getPrototypeOf(n) !== Array.prototype && a("an array subclass");
73
+ const l = [];
74
+ for (let c = 0; c < n.length; c += 1)
75
+ c in n || a("a hole"), l.push(s(n[c], `${i}[${c}]`));
76
+ return l;
77
+ }
78
+ Y(n) || a(`a ${n.constructor?.name ?? "non-plain object"}`), Object.getOwnPropertySymbols(n).length > 0 && a("a symbol key");
79
+ const r = {};
80
+ for (const l of Object.keys(n))
81
+ l === "__proto__" && a("a `__proto__` key"), I(r, J(l), s(n[l], `${i}.${l}`));
82
+ return r;
83
+ } finally {
84
+ o.delete(n);
85
+ }
86
+ };
87
+ return t === void 0 ? null : s(t, "");
88
+ }
89
+ const F = 1, K = 2 ** 53, te = 2 ** 32 - 1, ne = (t) => t.kind === "list" || t.kind === "tree" || (t.kind === "ref" || t.kind === "map") && t.owns === !0;
90
+ function oe(t, e) {
91
+ const o = (i) => typeof i == "object" && i !== null && !Array.isArray(i), s = (i) => typeof i == "string" && i !== "" && e(i) ? i : null, n = [];
92
+ if (!o(t)) return n;
93
+ for (const i of Object.keys(t).sort(A)) {
94
+ const a = t[i], r = s(a);
95
+ if (r !== null)
96
+ n.push([r, i]);
97
+ else if (o(a))
98
+ for (const l of Object.keys(a).sort(A)) {
99
+ const c = s(a[l]);
100
+ c !== null && n.push([c, `${i}.${l}`]);
101
+ }
102
+ }
103
+ return n;
104
+ }
105
+ const se = 32;
106
+ function ie(t) {
107
+ return t === "" ? null : t.length > se ? "a prefix has at most 32 characters" : /^[A-Za-z]/.test(t) ? /^[A-Za-z0-9_:/-]*$/.test(t) ? null : "a prefix holds ASCII letters, digits, `_`, `-`, `:`, and `/` only" : "a prefix starts with a letter";
108
+ }
109
+ const Ce = (t) => Object.values(t.types).some((e) => e.toolId !== void 0);
110
+ function _e(t, e) {
111
+ if (t.readOnly) return !0;
112
+ const o = t.readOnlyWhen;
113
+ if (o === void 0) return !1;
114
+ const s = e(o.field);
115
+ return typeof s == "string" && o.values.includes(s);
116
+ }
117
+ const re = ["after", "before", "both", "none"], ae = ["string", "number", "integer", "boolean", "enum", "json", "blob", "ref", "text", "list", "tree", "map"], ce = ["text", "list", "tree", "map"], le = ["ref", "list", "tree"], fe = (t) => ce.includes(t), O = (t) => Object.keys(t).sort(A), u = (t) => t !== null && typeof t == "object" && !Array.isArray(t), P = (t) => typeof t == "number" && Number.isInteger(t) && t >= 0 && t <= te;
118
+ function v(t, e, o) {
119
+ for (const s of Object.keys(e))
120
+ if (!o.includes(s)) throw f.schema(`${t}: unknown field \`${s}\``);
121
+ }
122
+ function X(t, e) {
123
+ if (!u(e)) throw f.schema(`${t}: a field definition is an object`);
124
+ if (v(t, e, ["kind", "of", "values", "optional", "marks", "readOnly", "owns", "cascade", "position", "display", "sample", "minimum", "maximum", "multipleOf", "label", "members"]), typeof e.kind != "string" || !ae.includes(e.kind)) throw f.schema(`${t}: unknown kind \`${String(e.kind)}\``);
125
+ const o = { kind: e.kind };
126
+ if (e.label !== void 0 && e.label !== null) {
127
+ if (typeof e.label != "string") throw f.schema(`${t}: label is a string`);
128
+ o.label = e.label;
129
+ }
130
+ for (const s of ["minimum", "maximum", "multipleOf"]) {
131
+ const n = e[s];
132
+ if (n != null) {
133
+ if (!["number", "integer", "json"].includes(o.kind) || typeof n != "number" || !Number.isFinite(n) || s === "multipleOf" && n <= 0) throw f.schema(`${t}: invalid numeric limit ${s}`);
134
+ o[s] = n;
135
+ }
136
+ }
137
+ if (o.minimum !== void 0 && o.maximum !== void 0 && o.minimum > o.maximum) throw f.schema(`${t}: minimum exceeds maximum`);
138
+ if (e.members !== void 0) {
139
+ if (!u(e.members) || !["json", "map"].includes(o.kind) && Object.keys(e.members).length > 0) throw f.schema(`${t}: members requires json or map and an object`);
140
+ o.members = {};
141
+ for (const [s, n] of Object.entries(e.members)) {
142
+ if (s.split(".").some((c) => !/^[^.[\]]+(?:\[\])*$/.test(c))) throw f.schema(`${t}: invalid member path ${s}`);
143
+ if (!u(n)) throw f.schema(`${t}: member limits must be an object`);
144
+ v(t, n, ["minimum", "maximum", "multipleOf", "nullable"]);
145
+ const { nullable: i, ...a } = n;
146
+ if (i !== void 0 && typeof i != "boolean") throw f.schema(`${t}: nullable is a boolean`);
147
+ const r = X(`${t}.${s}`, { kind: "number", ...a }), l = {};
148
+ i === !0 && (l.nullable = !0);
149
+ for (const c of ["minimum", "maximum", "multipleOf"]) r[c] !== void 0 && (l[c] = r[c]);
150
+ I(o.members, s, l);
151
+ }
152
+ }
153
+ if (e.of !== void 0 && e.of !== null) {
154
+ if (typeof e.of != "string") throw f.schema(`${t}: \`of\` is a type name`);
155
+ o.of = e.of;
156
+ }
157
+ if (e.values !== void 0) {
158
+ if (!Array.isArray(e.values) || !e.values.every((s) => typeof s == "string")) throw f.schema(`${t}: \`values\` is a list of strings`);
159
+ o.values = [...e.values];
160
+ }
161
+ if (e.optional !== void 0) {
162
+ if (typeof e.optional != "boolean") throw f.schema(`${t}: \`optional\` is a boolean`);
163
+ o.optional = e.optional;
164
+ }
165
+ if (e.marks !== void 0) {
166
+ if (!u(e.marks)) throw f.schema(`${t}: \`marks\` is an object of mark definitions`);
167
+ const s = {};
168
+ for (const n of O(e.marks)) {
169
+ const i = e.marks[n];
170
+ if (!u(i)) throw f.schema(`${t} mark \`${n}\`: a mark definition is an object`);
171
+ if (v(`${t} mark \`${n}\``, i, ["expand"]), typeof i.expand != "string" || !re.includes(i.expand)) throw f.schema(`${t} mark \`${n}\`: \`expand\` is after, before, both, or none`);
172
+ I(s, n, { expand: i.expand });
173
+ }
174
+ o.marks = s;
175
+ }
176
+ if (e.readOnly !== void 0) {
177
+ if (typeof e.readOnly != "boolean") throw f.schema(`${t}: \`readOnly\` is a boolean`);
178
+ e.readOnly && (o.readOnly = !0);
179
+ }
180
+ if (e.owns !== void 0) {
181
+ if (typeof e.owns != "boolean") throw f.schema(`${t}: \`owns\` is a boolean`);
182
+ e.owns && (o.owns = !0);
183
+ }
184
+ if (e.cascade !== void 0) {
185
+ if (typeof e.cascade != "boolean" || e.cascade && o.kind !== "tree") throw f.schema(`${t}: cascade requires a tree and a boolean`);
186
+ e.cascade && (o.cascade = !0);
187
+ }
188
+ if (e.position !== void 0) {
189
+ if (typeof e.position != "boolean") throw f.schema(`${t}: \`position\` is a boolean`);
190
+ e.position && (o.position = !0);
191
+ }
192
+ if (e.display !== void 0 && e.display !== null) {
193
+ const s = e.display, n = (i) => typeof i == "number" && Number.isFinite(i) && i > 0;
194
+ if (!u(s) || s.kind !== "time" || !n(s.perSecond) || s.fps !== void 0 && s.fps !== null && !n(s.fps))
195
+ throw f.schema(`${t}: \`display\` is { kind: "time", perSecond, fps? } with positive numbers`);
196
+ v(`${t} display`, s, ["kind", "perSecond", "fps"]), o.display = { kind: "time", perSecond: s.perSecond, ...n(s.fps) ? { fps: s.fps } : {} };
197
+ }
198
+ if (e.sample !== void 0 && e.sample !== null) {
199
+ if (typeof e.sample != "boolean") throw f.schema(`${t}: \`sample\` is a boolean`);
200
+ o.sample = e.sample;
201
+ }
202
+ return o;
203
+ }
204
+ function de(t) {
205
+ return t === "" ? "a mark key is not empty" : t.startsWith("$") ? "names starting with `$` are reserved" : t.includes(":") ? "a mark key holds no `:`" : t === "__proto__" ? "`__proto__` is not a mark key" : null;
206
+ }
207
+ const Ve = (t) => t.kind === "text" && t.marks !== void 0 && Object.keys(t.marks).length > 0;
208
+ function Ee(t) {
209
+ const e = /* @__PURE__ */ new Map();
210
+ for (const o of O(t.types)) {
211
+ const s = t.types[o].fields;
212
+ for (const n of O(s)) {
213
+ const i = s[n].marks ?? {};
214
+ for (const a of O(i)) e.set(a, i[a].expand);
215
+ }
216
+ }
217
+ return e;
218
+ }
219
+ function me(t) {
220
+ if (!u(t)) throw f.schema("a schema is a JSON object");
221
+ if (v("schema", t, ["kdm", "kit", "schemaVersion", "root", "types"]), !P(t.kdm)) throw f.schema("`kdm` is required and is a whole number");
222
+ if (typeof t.kit != "string") throw f.schema("`kit` is required and is a string");
223
+ if (!P(t.schemaVersion)) throw f.schema("`schemaVersion` is required and is a whole number");
224
+ if (typeof t.root != "string") throw f.schema("`root` is required and is a string");
225
+ if (!u(t.types)) throw f.schema("`types` is required and is an object");
226
+ const e = t.types, o = {};
227
+ for (const s of O(t.types)) {
228
+ const n = t.types[s];
229
+ if (!u(n)) throw f.schema(`type \`${s}\` is an object`);
230
+ if (v(`type \`${s}\``, n, ["fields", "projected", "projectedOps", "batchOps", "creation", "readOnly", "readOnlyWhen", "toolId", "pathName", "label", "derived", "text", "batchIndependent", "moveConsequences", "structuralConsequences"]), !u(n.fields)) throw f.schema(`type \`${s}\` needs \`fields\``);
231
+ const i = {};
232
+ for (const r of O(n.fields)) I(i, r, X(`\`${s}.${r}\``, n.fields[r]));
233
+ const a = { fields: i };
234
+ if (n.projected !== void 0) {
235
+ if (typeof n.projected != "boolean") throw f.schema(`type \`${s}\`: projected is a boolean`);
236
+ n.projected && (a.projected = !0);
237
+ }
238
+ if (n.projectedOps !== void 0) {
239
+ if (!a.projected || !u(n.projectedOps)) throw f.schema(`type \`${s}\`: projectedOps requires projected:true`);
240
+ const r = {};
241
+ for (const [l, c] of Object.entries(n.projectedOps)) {
242
+ if (!l || !u(c) || typeof c.command != "string" || !c.command || Object.keys(c).some((h) => !["command", "params"].includes(h)) || c.params !== void 0 && (!u(c.params) || Object.entries(c.params).some(([h, y]) => !h || typeof y != "string" || y.split(".").some((w) => !w))))
243
+ throw f.schema(`type \`${s}\`: projectedOps needs an operation, command and parameter paths`);
244
+ I(r, l, { command: c.command, ...u(c.params) ? { params: { ...c.params } } : {} });
245
+ }
246
+ Object.keys(r).length && (a.projectedOps = r);
247
+ }
248
+ if (n.structuralConsequences !== void 0) {
249
+ const r = n.structuralConsequences;
250
+ if (!Array.isArray(r) || r.some(
251
+ (l) => !u(l) || Object.keys(l).some((c) => !["container", "on", "fields"].includes(c)) || typeof l.container != "string" || !Object.hasOwn(e, l.container) || !Array.isArray(l.on) || !l.on.length || l.on.some((c) => !["create", "delete", "move", "rename"].includes(c) && !(c === "set" && Object.values(e).some((h) => u(h) && h.projected === !0))) || !Array.isArray(l.fields) || !l.fields.length || l.fields.some((c) => typeof c != "string" || c.split(".").some((h) => !h) || !i[c.split(".")[0]] || c.includes(".") && !["json", "map"].includes(i[c.split(".")[0]].kind))
252
+ )) throw f.schema(`type \`${s}\`: structuralConsequences needs a declared container, structural actions and stored field paths`);
253
+ r.length && (a.structuralConsequences = r.map((l) => ({ container: l.container, on: [...l.on], fields: [...l.fields] })));
254
+ }
255
+ if (n.moveConsequences !== void 0) {
256
+ if (!Array.isArray(n.moveConsequences) || n.moveConsequences.some((r) => {
257
+ if (typeof r != "string" || r.split(".").some((c) => !c)) return !0;
258
+ const l = i[r.split(".")[0]];
259
+ return !l?.position || r.includes(".") && l.kind !== "json";
260
+ })) throw f.schema(`type \`${s}\`: moveConsequences must name position fields or their JSON members`);
261
+ n.moveConsequences.length && (a.moveConsequences = [...n.moveConsequences]);
262
+ }
263
+ if (n.creation !== void 0) {
264
+ if (!u(n.creation)) throw f.schema("creation is an object");
265
+ v("creation", n.creation, ["fields", "command", "fixtures"]);
266
+ for (const l of ["fields", "fixtures"]) if (n.creation[l] !== void 0 && !u(n.creation[l])) throw f.schema(`creation.${l} is an object`);
267
+ const r = n.creation.command;
268
+ if (r !== void 0) {
269
+ if (!u(r) || typeof r.command != "string" || !r.command) throw f.schema("creation command required");
270
+ if (v("creation command", r, ["command", "params"]), r.params !== void 0 && (!u(r.params) || Object.entries(r.params).some(([l, c]) => !l || typeof c != "string" || c.split(".").some((h) => !h)))) throw f.schema("invalid creation command paths");
271
+ }
272
+ a.creation = structuredClone(n.creation);
273
+ }
274
+ if (n.batchOps !== void 0) {
275
+ if (!u(n.batchOps)) throw f.schema(`type \`${s}\`: batchOps is a mapping`);
276
+ const r = {};
277
+ for (const [l, c] of Object.entries(n.batchOps)) {
278
+ if (!l || !u(c)) throw f.schema("invalid batchOps operation");
279
+ if (c.direct === !0)
280
+ v("direct batchOps", c, ["direct"]), r[l] = { direct: !0 };
281
+ else {
282
+ if (v("command batchOps", c, ["command", "params"]), typeof c.command != "string" || !c.command || c.params !== void 0 && (!u(c.params) || Object.entries(c.params).some(([h, y]) => !h || typeof y != "string" || y.split(".").some((w) => !w)))) throw f.schema("invalid batchOps command");
283
+ r[l] = { command: c.command, params: c.params };
284
+ }
285
+ }
286
+ a.batchOps = r;
287
+ }
288
+ if (n.batchIndependent !== void 0) {
289
+ if (typeof n.batchIndependent != "boolean") throw f.schema(`type \`${s}\`: \`batchIndependent\` is a boolean`);
290
+ n.batchIndependent && (a.batchIndependent = !0);
291
+ }
292
+ if (n.readOnly !== void 0) {
293
+ if (typeof n.readOnly != "boolean") throw f.schema(`type \`${s}\`: \`readOnly\` is a boolean`);
294
+ n.readOnly && (a.readOnly = !0);
295
+ }
296
+ if (n.readOnlyWhen !== void 0 && n.readOnlyWhen !== null) {
297
+ const r = n.readOnlyWhen;
298
+ if (!u(r)) throw f.schema(`type \`${s}\`: \`readOnlyWhen\` is { field, values }`);
299
+ if (v(`type \`${s}\` readOnlyWhen`, r, ["field", "values"]), typeof r.field != "string") throw f.schema(`type \`${s}\`: \`readOnlyWhen.field\` is a field name`);
300
+ if (!Array.isArray(r.values) || !r.values.every((l) => typeof l == "string")) throw f.schema(`type \`${s}\`: \`readOnlyWhen.values\` is a list of strings`);
301
+ a.readOnlyWhen = { field: r.field, values: [...r.values] };
302
+ }
303
+ if (n.toolId !== void 0 && n.toolId !== null) {
304
+ const r = n.toolId;
305
+ if (!u(r)) throw f.schema(`type \`${s}\`: \`toolId\` is { field, prefix?, parent? }`);
306
+ if (v(`type \`${s}\` toolId`, r, ["field", "prefix", "parent"]), typeof r.field != "string") throw f.schema(`type \`${s}\`: \`toolId.field\` is a field name`);
307
+ if (r.prefix !== void 0 && typeof r.prefix != "string") throw f.schema(`type \`${s}\`: \`toolId.prefix\` is a string`);
308
+ if (r.parent !== void 0 && r.parent !== null && typeof r.parent != "string") throw f.schema(`type \`${s}\`: \`toolId.parent\` is a type name`);
309
+ a.toolId = { field: r.field, prefix: typeof r.prefix == "string" ? r.prefix : "", ...typeof r.parent == "string" ? { parent: r.parent } : {} };
310
+ }
311
+ if (n.pathName !== void 0 && n.pathName !== null) {
312
+ const r = n.pathName, l = typeof r == "string" ? i[r.split(".")[0]]?.kind : void 0, c = l === "json" || (l === "string" || l === "enum") && typeof r == "string" && !r.includes(".");
313
+ if (typeof r != "string" || !c) throw f.schema(`type \`${s}\`: \`pathName\` \`${String(r)}\` names no string or enum field, nor a member of a json field`);
314
+ a.pathName = r;
315
+ }
316
+ for (const r of ["label", "text"]) if (n[r] !== void 0 && n[r] !== null) {
317
+ const l = n[r], c = typeof l == "string" ? i[l.split(".")[0]]?.kind : void 0, h = c === "json" || (c === "string" || c === "text" || c === "enum") && typeof l == "string" && !l.includes(".");
318
+ if (typeof l != "string" || !h) throw f.schema(`type \`${s}\`: \`${r}\` \`${String(l)}\` names no string, text or enum field, nor a member of a json field`);
319
+ a[r] = l;
320
+ }
321
+ if (n.derived !== void 0 && n.derived !== null) {
322
+ if (!u(n.derived)) throw f.schema(`type \`${s}\`: \`derived\` is an object of names`);
323
+ const r = {};
324
+ for (const l of O(n.derived)) {
325
+ if (!/^[A-Za-z0-9_]+$/.test(l)) throw f.schema(`type \`${s}\`: derived \`${l}\` is no name (ASCII letters, digits and \`_\`)`);
326
+ const c = n.derived[l];
327
+ if (!u(c)) throw f.schema(`type \`${s}\`: derived \`${l}\` is { description? }`);
328
+ if (v(`type \`${s}\` derived \`${l}\``, c, ["description", "premiseOnly", "onDemand"]), c.description !== void 0 && typeof c.description != "string") throw f.schema(`type \`${s}\`: derived \`${l}\`.description is a string`);
329
+ if (c.premiseOnly !== void 0 && typeof c.premiseOnly != "boolean") throw f.schema(`type \`${s}\`: derived \`${l}\`.premiseOnly is a boolean`);
330
+ if (c.onDemand !== void 0 && typeof c.onDemand != "boolean") throw f.schema(`type \`${s}\`: derived \`${l}\`.onDemand is a boolean`);
331
+ if (c.onDemand && !c.premiseOnly) throw f.schema(`type \`${s}\`: onDemand derived facts require premiseOnly`);
332
+ I(r, l, { ...typeof c.description == "string" ? { description: c.description } : {}, ...c.premiseOnly ? { premiseOnly: !0 } : {}, ...c.onDemand ? { onDemand: !0 } : {} });
333
+ }
334
+ Object.keys(r).length > 0 && (a.derived = r);
335
+ }
336
+ I(o, s, a);
337
+ }
338
+ return { kdm: t.kdm, kit: t.kit, schemaVersion: t.schemaVersion, root: t.root, types: o };
339
+ }
340
+ function pe(t) {
341
+ if (t.kdm !== F) throw f.schema(`kdm ${t.kdm} is not supported; this build reads ${F}`);
342
+ if (!Object.hasOwn(t.types, t.root)) throw f.schema(`root type \`${t.root}\` is not declared`);
343
+ if (t.types[t.root].projected) throw f.schema("the root type cannot be projected");
344
+ const e = /* @__PURE__ */ new Map();
345
+ for (const o of O(t.types)) {
346
+ if (o.startsWith("$")) throw f.schema(`type \`${o}\`: names starting with \`$\` are reserved`);
347
+ const s = t.types[o], n = s.readOnlyWhen;
348
+ if (n !== void 0) {
349
+ if (s.readOnly) throw f.schema(`type \`${o}\`: \`readOnly\` and \`readOnlyWhen\` exclude each other`);
350
+ if (!Object.hasOwn(s.fields, n.field)) throw f.schema(`type \`${o}\`: \`readOnlyWhen\` names undeclared field \`${n.field}\``);
351
+ const i = s.fields[n.field];
352
+ if (i.kind !== "enum") throw f.schema(`type \`${o}\`: \`readOnlyWhen\` names \`${n.field}\`, which is not an enum`);
353
+ if (n.values.length === 0) throw f.schema(`type \`${o}\`: \`readOnlyWhen\` needs \`values\``);
354
+ const a = n.values.find((r) => !(i.values ?? []).includes(r));
355
+ if (a !== void 0) throw f.schema(`type \`${o}\`: \`readOnlyWhen\` value \`${a}\` is not a value of \`${o}.${n.field}\``);
356
+ }
357
+ s.toolId !== void 0 && ue(t, o, s.toolId);
358
+ for (const i of O(s.fields)) {
359
+ const a = s.fields[i];
360
+ if (i.startsWith("$") || i.startsWith("~")) throw f.schema(`\`${o}.${i}\`: names starting with \`$\` or \`~\` are reserved`);
361
+ const r = le.includes(a.kind), l = a.kind === "map" && a.owns === !0;
362
+ if (a.of !== void 0 && !r && !l) throw f.schema(`\`${o}.${i}\`: only ref, list, and tree fields take \`of\``);
363
+ if (a.owns && (a.kind === "list" || a.kind === "tree"))
364
+ throw f.schema(`\`${o}.${i}\`: only ref fields take \`owns\` (list and tree fields always own their items)`);
365
+ if (a.owns && a.kind !== "ref" && a.kind !== "map") throw f.schema(`\`${o}.${i}\`: only ref and map fields take \`owns\``);
366
+ if (a.values?.length && a.kind !== "enum") throw f.schema(`\`${o}.${i}\`: only enum fields take \`values\``);
367
+ if (a.kind === "enum" && !a.values?.length) throw f.schema(`\`${o}.${i}\`: an enum needs \`values\``);
368
+ if (r || l && a.of !== void 0) {
369
+ if (a.of === void 0) throw f.schema(`\`${o}.${i}\` needs \`of\``);
370
+ if (!Object.hasOwn(t.types, a.of)) throw f.schema(`\`${o}.${i}\` refers to undeclared type \`${a.of}\``);
371
+ }
372
+ const c = a.marks ?? {}, h = O(c);
373
+ if (h.length > 0 && a.kind !== "text") throw f.schema(`\`${o}.${i}\`: only text fields take \`marks\``);
374
+ for (const y of h) {
375
+ const w = de(y);
376
+ if (w !== null) throw f.schema(`\`${o}.${i}\` mark \`${y}\`: ${w}`);
377
+ const N = c[y].expand, q = e.get(y);
378
+ if (q !== void 0 && q !== N)
379
+ throw f.schema(`\`${o}.${i}\` mark \`${y}\` expands \`${N}\`, but it is declared elsewhere expanding \`${q}\`; a mark key has one expand in a schema`);
380
+ e.set(y, N);
381
+ }
382
+ }
383
+ }
384
+ }
385
+ function ue(t, e, o) {
386
+ const s = (y) => f.schema(`type \`${e}\`: \`toolId\` ${y}`), n = t.types[e].fields;
387
+ if (!Object.hasOwn(n, o.field)) throw s(`names undeclared field \`${o.field}\``);
388
+ const i = n[o.field];
389
+ if (i.kind !== "integer" && i.kind !== "string") throw s(`names \`${o.field}\`, which is not an integer or a string`);
390
+ if (!i.readOnly) throw s(`names \`${o.field}\`, which is not \`readOnly\`: only the kit writes an object's tool id`);
391
+ const a = ie(o.prefix);
392
+ if (a !== null) throw s(`prefix \`${o.prefix}\`: ${a}`);
393
+ const r = o.parent;
394
+ if (r === void 0) return;
395
+ if (!Object.hasOwn(t.types, r)) throw s(`names undeclared parent type \`${r}\``);
396
+ const l = t.types[r];
397
+ if (l.toolId === void 0) throw s(`names parent \`${r}\`, which declares no \`toolId\``);
398
+ if (!Object.values(l.fields).some((y) => (y.kind === "list" || y.kind === "tree" || y.kind === "ref" || y.kind === "map" && y.owns) && y.of === e))
399
+ throw s(`names parent \`${r}\`, which has no list, tree, or ref field of \`${e}\``);
400
+ const c = [];
401
+ let h = r;
402
+ for (; h !== void 0; ) {
403
+ if (h === e) throw s(`parent \`${r}\` leads back to \`${e}\`: parents form no cycle`);
404
+ if (c.includes(h)) break;
405
+ c.push(h), h = Object.hasOwn(t.types, h) ? t.types[h].toolId?.parent : void 0;
406
+ }
407
+ }
408
+ function De(t) {
409
+ let e = t;
410
+ if (typeof t == "string")
411
+ try {
412
+ e = JSON.parse(t);
413
+ } catch (s) {
414
+ throw f.schema(String(s));
415
+ }
416
+ const o = me(e);
417
+ return pe(o), o;
418
+ }
419
+ function he(t, e) {
420
+ if (!Object.hasOwn(t.types, e)) throw f.unknownType(e);
421
+ return t.types[e];
422
+ }
423
+ function L(t, e, o) {
424
+ const s = he(t, e);
425
+ if (!Object.hasOwn(s.fields, o)) throw f.unknownField(e, o, Object.keys(s.fields).sort());
426
+ return s.fields[o];
427
+ }
428
+ function Te(t, e, o, s) {
429
+ ye(t, e, o, s);
430
+ }
431
+ function ye(t, e, o, s) {
432
+ const n = L(t, e, o);
433
+ if (fe(n.kind)) throw f.invalidValue(e, o, $e(n.kind));
434
+ if (s == null) {
435
+ if (n.optional) return null;
436
+ throw f.invalidValue(e, o, "is required");
437
+ }
438
+ const i = ee(s, (r) => f.invalidValue(e, o, r));
439
+ if (E(e, o, i, n), n.members !== void 0 && Object.keys(n.members).length > 0) {
440
+ for (const [r, l] of Object.entries(n.members)) for (const c of W(i, r))
441
+ if (!(Array.isArray(c) || u(c) || c === null && l.nullable)) {
442
+ if (typeof c != "number") throw f.invalidValue(e, o, "bounded members require a number or an explicitly nullable null");
443
+ E(e, o, c, l);
444
+ }
445
+ }
446
+ let a;
447
+ switch (n.kind) {
448
+ case "string":
449
+ case "ref":
450
+ a = typeof i == "string";
451
+ break;
452
+ case "number":
453
+ a = typeof i == "number";
454
+ break;
455
+ case "integer":
456
+ a = typeof i == "number" && Number.isInteger(i) && Math.abs(i) <= K;
457
+ break;
458
+ case "boolean":
459
+ a = typeof i == "boolean";
460
+ break;
461
+ case "enum":
462
+ a = typeof i == "string" && (n.values ?? []).includes(i);
463
+ break;
464
+ case "blob":
465
+ a = u(i) && typeof i.hash == "string" && typeof i.mime == "string" && typeof i.size == "number" && Number.isInteger(i.size) && i.size >= 0 && i.size <= K;
466
+ break;
467
+ default:
468
+ a = !0;
469
+ }
470
+ if (!a && n.kind === "enum") throw f.invalidValue(e, o, be(n.values ?? [], i));
471
+ if (!a) throw f.invalidValue(e, o, `expects ${/^[aeiou]/.test(n.kind) ? "an" : "a"} ${n.kind} value`);
472
+ return i;
473
+ }
474
+ function W(t, e) {
475
+ if (e === "") return [t];
476
+ const o = e.search(/[.\[]/), s = o < 0 ? e : e.slice(0, o);
477
+ return s === "*" ? u(t) ? Object.values(t).flatMap((n) => W(n, e.slice(s.length))) : [] : s !== "" ? u(t) && Object.hasOwn(t, s) ? W(t[s], e.slice(s.length)) : [] : e.startsWith("[]") ? Array.isArray(t) ? t.flatMap((n) => W(n, e.slice(2))) : [] : e.startsWith(".") ? W(t, e.slice(1)) : [];
478
+ }
479
+ function E(t, e, o, s) {
480
+ if (typeof o != "number") return;
481
+ const n = s.multipleOf !== void 0 ? o / s.multipleOf : 0;
482
+ if (s.minimum !== void 0 && o < s.minimum || s.maximum !== void 0 && o > s.maximum || !Number.isFinite(n) || Math.abs(n - Math.round(n)) > 1e-9) throw f.invalidValue(t, e, "is outside minimum/maximum or is not a multipleOf the declared step");
483
+ }
484
+ function Je(t, e, o, s, n) {
485
+ const i = L(t, e, o);
486
+ if (i.of !== void 0 && (typeof n != "string" || n === "")) throw f.invalidValue(e, o, `map entry \`${s}\` expects the id of a \`${i.of}\``);
487
+ for (const [a, r] of Object.entries(i.members ?? {}))
488
+ for (const l of W({ [s]: n }, a))
489
+ if (!(Array.isArray(l) || u(l) || l === null && r.nullable)) {
490
+ if (typeof l != "number") throw f.invalidValue(e, o, `map entry \`${s}\` requires a number`);
491
+ E(e, o, l, r);
492
+ }
493
+ }
494
+ const z = 20;
495
+ function be(t, e) {
496
+ const o = t.slice(0, z).map((a) => `\`${a}\``), s = Math.max(0, t.length - z), n = s > 0 ? `, and ${s} more (\`describe\` lists them all)` : "", i = typeof e == "string" ? `\`${e}\`` : typeof e == "number" ? "a number" : typeof e == "boolean" ? "a boolean" : Array.isArray(e) ? "an array" : e === null ? "null" : "an object";
497
+ return `takes one of ${o.join(", ")}${n}, not ${i}`;
498
+ }
499
+ function $e(t) {
500
+ return `is a container, not a value: change it with ${{
501
+ text: "text.insert, text.delete, text.set, text.mark, text.unmark",
502
+ list: "list.insert, list.move, list.remove",
503
+ tree: "tree.insert, tree.move",
504
+ map: "map.set, map.delete"
505
+ }[t] ?? "its operations"}, or set the fields of the objects it holds`;
506
+ }
507
+ const R = 8, C = (t, e) => {
508
+ try {
509
+ return t();
510
+ } catch {
511
+ return e;
512
+ }
513
+ };
514
+ function ge(t) {
515
+ return {
516
+ objectsOfType: (e) => t.objectsOfType(e),
517
+ register: (e, o) => C(() => t.get(e, o), null),
518
+ held: (e, o, s) => {
519
+ if (s === "list") return C(() => t.list(e, o), []);
520
+ if (s === "tree") return C(() => t.tree(e, o), []).map((n) => n.object).filter((n) => t.exists(n));
521
+ if (s === "ref") {
522
+ const n = C(() => t.get(e, o), null);
523
+ return typeof n == "string" ? [n] : [];
524
+ }
525
+ return [];
526
+ },
527
+ map: (e, o) => Object.fromEntries(C(() => t.mapEntries(e, o), [])),
528
+ exists: (e) => t.exists(e)
529
+ };
530
+ }
531
+ const x = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
532
+ function Oe(t) {
533
+ const e = x(t) && x(t.objects) ? t.objects : {}, o = (n, i) => {
534
+ const a = Object.hasOwn(e, n) ? e[n] : void 0;
535
+ return x(a) && Object.hasOwn(a, i) ? a[i] : null;
536
+ }, s = (n, i) => {
537
+ for (const a of Array.isArray(n) ? n : [])
538
+ x(a) && (typeof a.object == "string" && i.push(a.object), s(a.children, i));
539
+ };
540
+ return {
541
+ objectsOfType: (n) => Object.keys(e).filter((i) => x(e[i]) && e[i].$type === n).sort(A),
542
+ register: o,
543
+ held: (n, i, a) => {
544
+ const r = o(n, i), l = [];
545
+ return a === "list" && Array.isArray(r) ? l.push(...r.filter((c) => typeof c == "string")) : a === "tree" ? s(r, l) : a === "ref" && typeof r == "string" && l.push(r), l.filter((c) => Object.hasOwn(e, c));
546
+ },
547
+ map: (n, i) => o(n, i),
548
+ exists: (n) => Object.hasOwn(e, n)
549
+ };
550
+ }
551
+ function ke(t, e, o) {
552
+ const s = o.map(([n, i]) => {
553
+ const a = i === void 0 ? void 0 : t.types[i]?.pathName;
554
+ if (a === void 0) return null;
555
+ const [r, ...l] = a.split(".");
556
+ let c = e.register(n, r);
557
+ for (const h of l) c = x(c) ? c[h] ?? null : null;
558
+ return { text: typeof c == "string" ? c : null };
559
+ });
560
+ return s.map((n, i) => {
561
+ if (n === null) return null;
562
+ const a = n.text, r = a !== null && a !== "" && !/[/.#@]/.test(a) && !/^\d+$/.test(a) ? a : null;
563
+ if (r === null) return `#${i + 1}`;
564
+ const l = s.slice(0, i).filter((c) => c !== null && c.text === r).length;
565
+ return l === 0 ? r : `${r}#${l + 1}`;
566
+ });
567
+ }
568
+ function ve(t) {
569
+ return typeof t == "number" && Number.isInteger(t) ? String(t) : typeof t == "string" && t !== "" ? t : null;
570
+ }
571
+ const je = (t) => t.split(/[:/]/).pop() ?? t;
572
+ function U(t) {
573
+ const e = t.map((o) => `\`${o}\``);
574
+ return e.length <= 1 ? e.join("") : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
575
+ }
576
+ class M {
577
+ constructor(e, o, s, n) {
578
+ this.active = e, this.own = o, this.named = s, this.owners = n;
579
+ }
580
+ static none() {
581
+ return new M(!1, /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map());
582
+ }
583
+ /** The tool ids of a replica's current state. */
584
+ static ofReplica(e) {
585
+ return M.build(e.schema, ge(e));
586
+ }
587
+ /** The tool ids of a canonical state (`Replica.stateJson`) read with `schema`. */
588
+ static ofState(e, o) {
589
+ return M.build(e, Oe(o));
590
+ }
591
+ static build(e, o) {
592
+ const s = O(e.types).flatMap((d) => {
593
+ const m = e.types[d].toolId;
594
+ return m ? [[d, m]] : [];
595
+ });
596
+ if (s.length === 0) return M.none();
597
+ const n = /* @__PURE__ */ new Map();
598
+ for (const [d, m] of s)
599
+ for (const p of o.objectsOfType(d)) {
600
+ const b = ve(o.register(p, m.field));
601
+ b !== null && n.set(p, { type: d, tool: m, value: b });
602
+ }
603
+ const i = /* @__PURE__ */ new Map();
604
+ for (const [d, m] of s) {
605
+ const p = m.parent;
606
+ if (p === void 0 || !Object.hasOwn(e.types, p)) continue;
607
+ const b = e.types[p];
608
+ for (const $ of O(b.fields)) {
609
+ const k = b.fields[$];
610
+ if (!(!(k.kind === "list" || k.kind === "tree" || k.kind === "ref") || k.of !== d))
611
+ for (const j of o.objectsOfType(p))
612
+ for (const g of o.held(j, $, k.kind)) {
613
+ const S = i.get(g) ?? [];
614
+ S.includes(j) || S.push(j), i.set(g, S);
615
+ }
616
+ }
617
+ }
618
+ const a = /* @__PURE__ */ new Map(), r = (d, m) => {
619
+ const p = a.get(d);
620
+ if (p !== void 0) return p;
621
+ const b = n.get(d);
622
+ let $ = null;
623
+ if (b !== void 0) {
624
+ const k = `${b.tool.prefix}${b.value}`;
625
+ if (b.tool.parent === void 0) $ = k;
626
+ else {
627
+ const j = i.get(d);
628
+ if (j !== void 0 && j.length === 1 && m <= 64) {
629
+ const g = r(j[0], m + 1);
630
+ g !== null && ($ = `${g}/${k}`);
631
+ }
632
+ }
633
+ }
634
+ return a.set(d, $), $;
635
+ };
636
+ for (const d of [...n.keys()].sort(A)) r(d, 0);
637
+ const l = /* @__PURE__ */ new Map();
638
+ for (const [d, m] of a) {
639
+ const p = n.get(d);
640
+ if (m === null || p === void 0) continue;
641
+ const b = l.get(m) ?? [];
642
+ b.push({ id: d, type: p.type, value: p.value }), l.set(m, b);
643
+ }
644
+ const c = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
645
+ for (const d of [...l.keys()].sort(A)) {
646
+ const m = l.get(d).sort((p, b) => A(p.type, b.type) || A(p.id, b.id));
647
+ h.set(d, m), m.length === 1 && c.set(m[0].id, d);
648
+ }
649
+ const y = /* @__PURE__ */ new Map(), w = Object.values(e.types).some((d) => d.pathName !== void 0), N = /* @__PURE__ */ new Map();
650
+ if (w) for (const d of O(e.types)) for (const m of o.objectsOfType(d)) N.set(m, d);
651
+ for (const d of O(e.types)) {
652
+ const m = e.types[d].fields;
653
+ for (const p of O(m)) {
654
+ const b = m[p];
655
+ if (ne(b))
656
+ for (const $ of o.objectsOfType(d)) {
657
+ const k = b.kind === "map" ? oe(o.map($, p), (g) => o.exists(g)) : o.held($, p, b.kind).map((g, S) => [g, b.kind === "ref" ? null : String(S)]), j = w && b.kind === "list" ? ke(e, o, k.map(([g]) => [g, N.get(g)])) : [];
658
+ k.forEach(([g, S], H) => {
659
+ const _ = y.get(g) ?? [];
660
+ _.some((T) => T.owner === $ && T.field === p) || _.push({ owner: $, field: p, at: S, name: j[H] ?? null }), y.set(g, _);
661
+ });
662
+ }
663
+ }
664
+ }
665
+ const q = (d) => {
666
+ const m = c.get(d);
667
+ if (m !== void 0) return m;
668
+ const p = y.get(d);
669
+ return p !== void 0 && p.length === 1 && p[0].at !== null && /^\d+$/.test(p[0].at) ? p[0].at : null;
670
+ }, Z = (d) => {
671
+ const m = d.indexOf("."), p = m < 0 ? d : d.slice(0, m), b = m < 0 ? null : d.slice(m + 1);
672
+ let $ = q(p);
673
+ if ($ === null) {
674
+ const k = p.split(":").map(q);
675
+ if (k.some((j) => j === null)) return null;
676
+ $ = k.join(":");
677
+ }
678
+ return b === null ? $ : `${$}.${b}`;
679
+ }, D = [];
680
+ for (const d of y.values())
681
+ for (const m of d) {
682
+ const p = m.at === null ? null : Z(m.at);
683
+ p !== null && D.push([m, p]);
684
+ }
685
+ for (const [d, m] of D) d.at = m;
686
+ return new M(!0, c, h, y);
687
+ }
688
+ /**
689
+ * As the Rust `ToolIds::attributed`: for an object without a tool id of its own, the nearest
690
+ * object holding it that has one and the path from it (`body.paragraphs.0`); `null` for an object
691
+ * with a tool id, without tool ids in the schema, or when an object on the way has no single holder.
692
+ */
693
+ attributed(e) {
694
+ if (!this.active || this.own.has(e)) return null;
695
+ const o = [];
696
+ let s = e;
697
+ for (let n = 0; n < 64; n += 1) {
698
+ const i = this.owners.get(s);
699
+ if (i === void 0 || i.length !== 1) return null;
700
+ const [a] = i;
701
+ a.at !== null && o.push(a.at), o.push(a.field);
702
+ const r = this.own.get(a.owner);
703
+ if (r !== void 0) return { holder: r, path: o.reverse().join(".") };
704
+ s = a.owner;
705
+ }
706
+ return null;
707
+ }
708
+ /**
709
+ * As the Rust `ToolIds::named_path`: `attributed`'s path in the words of the kit's commands, the names
710
+ * of the objects on the way whose type declares a `pathName` joined by `/`, then the path below the
711
+ * last of them; `null` when no object on the way is named so.
712
+ */
713
+ namedPath(e) {
714
+ if (!this.active || this.own.has(e)) return null;
715
+ const o = [], s = [];
716
+ let n = e;
717
+ for (let i = 0; i < 64; i += 1) {
718
+ const a = this.owners.get(n);
719
+ if (a === void 0 || a.length !== 1) return null;
720
+ const [r] = a;
721
+ if (r.name !== null ? o.push(r.name) : o.length === 0 && (r.at !== null && s.push(r.at), s.push(r.field)), this.own.has(r.owner)) {
722
+ if (o.length === 0) return null;
723
+ const l = o.reverse().join("/");
724
+ return s.length === 0 ? l : `${l}.${s.reverse().join(".")}`;
725
+ }
726
+ n = r.owner;
727
+ }
728
+ return null;
729
+ }
730
+ /** The type of the object a tool id names, when it names one. */
731
+ typeOf(e) {
732
+ const o = this.named.get(e);
733
+ return o !== void 0 && o.length === 1 ? o[0].type : null;
734
+ }
735
+ /** Whether the schema declares tool ids. */
736
+ isActive() {
737
+ return this.active;
738
+ }
739
+ /** The object's tool id, when it has one of its own. */
740
+ toolId(e) {
741
+ return this.own.get(e) ?? null;
742
+ }
743
+ /** How the object is named at the tool interface: its tool id, else its object id. */
744
+ showJson(e) {
745
+ return typeof e == "string" ? this.show(e) : Array.isArray(e) ? e.map((o) => this.showJson(o)) : x(e) ? Object.fromEntries(Object.entries(e).map(([o, s]) => [
746
+ this.toolId(o) ?? o.split(":").map((n) => this.show(n)).join(":"),
747
+ this.showJson(s)
748
+ ])) : e;
749
+ }
750
+ show(e) {
751
+ return this.own.get(e) ?? e;
752
+ }
753
+ /** References in marks share the tool id space; inserted characters stay literal. */
754
+ showText(e) {
755
+ return Array.isArray(e) ? e.map((o) => x(o) && Object.hasOwn(o, "attributes") ? { ...o, attributes: this.showJson(o.attributes) } : o) : e;
756
+ }
757
+ /**
758
+ * The object `text` names: a tool id, else an object id for which `exists` holds; an `Unresolved`
759
+ * when it names none or several. Without declared tool ids, `text` as an object id.
760
+ */
761
+ resolve(e, o) {
762
+ if (!this.active) return e;
763
+ const s = this.named.get(e);
764
+ if (s !== void 0 && s.length === 1) return s[0].id;
765
+ if (s !== void 0 && s.length > 1) {
766
+ const n = s.map((a) => `the \`${a.type}\` \`${a.id}\``), i = `${n.slice(0, -1).join(", ")} and ${n[n.length - 1]}`;
767
+ return {
768
+ reason: "ambiguous",
769
+ message: `\`${e}\` names ${s.length} objects (${i}), so it names none of them: give one of their object ids, which they answer until the kit gives each an id of its own`
770
+ };
771
+ }
772
+ return o(e) ? e : { reason: "not-found", message: this.notFound(e) };
773
+ }
774
+ /** Why `text` names no object, with the ids it may have meant (KHP A44, A48). */
775
+ notFound(e) {
776
+ const o = je(e), s = [...this.named.entries()].filter(([, i]) => i.some((a) => a.value === o)).map(([i]) => i);
777
+ if (s.length > 0) {
778
+ const i = s.slice(0, R), a = s.length > i.length ? `, and ${s.length - i.length} more` : "";
779
+ return `no object has the id \`${e}\`; these end in \`${o}\`: ${U(i)}${a} (an id is written whole, as query and load answer it)`;
780
+ }
781
+ const n = e.slice(0, e.length - o.length);
782
+ if (n !== "") {
783
+ const i = [...this.named.keys()].filter((a) => a.startsWith(n));
784
+ if (i.length > 0 && i.length <= R) return `no object has the id \`${e}\`; the ids starting \`${n}\` are ${U(i)}`;
785
+ if (i.length > 0) return `no object has the id \`${e}\`; ${i.length} ids start \`${n}\`: query or load answers them`;
786
+ }
787
+ return `no object has the id \`${e}\`: give an id that query or load answers, \`root\`, or the \`$name\` of an object created earlier in the batch`;
788
+ }
789
+ }
790
+ const Fe = (t) => typeof t != "string";
791
+ export {
792
+ Je as A,
793
+ F as K,
794
+ M as T,
795
+ qe as a,
796
+ O as b,
797
+ Te as c,
798
+ B as d,
799
+ Ve as e,
800
+ L as f,
801
+ De as g,
802
+ Ce as h,
803
+ _e as i,
804
+ Fe as j,
805
+ Se as k,
806
+ We as l,
807
+ oe as m,
808
+ Me as n,
809
+ ne as o,
810
+ Ae as p,
811
+ Ne as q,
812
+ fe as r,
813
+ Ie as s,
814
+ he as t,
815
+ xe as u,
816
+ Ee as v,
817
+ Q as w,
818
+ ye as x,
819
+ J as y,
820
+ ee as z
821
+ };