@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,94 @@
1
+ import { K as l } from "./envelope-GX4Cynkx.js";
2
+ const c = "CommentThread", d = "Comment", T = {
3
+ fields: { anchor: { kind: "json" }, resolved: { kind: "boolean", optional: !0 }, comments: { kind: "list", of: d } },
4
+ batchOps: { "*": { direct: !0 } }
5
+ }, b = {
6
+ fields: { author: { kind: "string" }, name: { kind: "string", optional: !0 }, body: { kind: "text" }, created: { kind: "string" } },
7
+ batchOps: { "*": { direct: !0 } }
8
+ };
9
+ function y(e) {
10
+ return e === c || e === d;
11
+ }
12
+ function m(e, t) {
13
+ const n = { author: t.author, created: t.created };
14
+ t.name !== void 0 && (n.name = t.name);
15
+ const s = e.create(d, n);
16
+ return t.body && e.textInsert(s, "body", 0, t.body), s;
17
+ }
18
+ function f(e, t) {
19
+ if (e.objectType(t) !== c) throw new l("invalid-value", `${t} is not a ${c}`);
20
+ }
21
+ function O(e, t, n) {
22
+ const s = e.create(c, { anchor: t, resolved: !1 }), o = m(e, n);
23
+ return e.listInsert(s, "comments", 0, o), { thread: s, comment: o };
24
+ }
25
+ function E(e, t, n) {
26
+ f(e, t);
27
+ const s = m(e, n);
28
+ return e.listInsert(t, "comments", e.listItems(t, "comments").length, s), s;
29
+ }
30
+ function p(e, t, n) {
31
+ f(e, t), e.set(t, "resolved", n);
32
+ }
33
+ function M(e, t, n) {
34
+ f(e, t);
35
+ const s = e.listItems(t, "comments"), o = s.indexOf(n);
36
+ if (o < 0) throw new l("not-found", n);
37
+ e.listRemove(t, "comments", o), e.delete(n), s.length === 1 && e.delete(t);
38
+ }
39
+ function j(e, t) {
40
+ f(e, t);
41
+ for (const n of e.listItems(t, "comments")) e.exists(n) && e.delete(n);
42
+ e.delete(t);
43
+ }
44
+ function h(e) {
45
+ return e && typeof e == "object" && !Array.isArray(e) && typeof e.object == "string" ? e : null;
46
+ }
47
+ const a = (e) => typeof e == "string" ? e : void 0;
48
+ function C(e) {
49
+ const t = e.schema.types;
50
+ if (!Object.hasOwn(t, c) || !Object.hasOwn(t, d)) return [];
51
+ const n = [];
52
+ for (const o of e.objectsOfType(c)) {
53
+ const r = [];
54
+ for (const i of e.list(o, "comments")) {
55
+ if (!e.exists(i) || e.objectType(i) !== d) continue;
56
+ const u = a(e.get(i, "name"));
57
+ r.push({
58
+ id: i,
59
+ author: a(e.get(i, "author")) ?? "",
60
+ ...u === void 0 ? {} : { name: u },
61
+ body: e.text(i, "body"),
62
+ created: a(e.get(i, "created")) ?? ""
63
+ });
64
+ }
65
+ n.push({ id: o, anchor: h(e.get(o, "anchor")), resolved: e.get(o, "resolved") === !0, comments: r });
66
+ }
67
+ const s = (o) => o.comments[0]?.created ?? "";
68
+ return n.sort((o, r) => s(o) < s(r) ? -1 : s(o) > s(r) ? 1 : o.id < r.id ? -1 : o.id > r.id ? 1 : 0);
69
+ }
70
+ function k(e, t) {
71
+ const n = e.range;
72
+ if (!n) return null;
73
+ const s = e.quote;
74
+ if (!s) return n.end <= t.length ? n : null;
75
+ if (t.slice(n.start, n.end) === s) return n;
76
+ let o = null;
77
+ for (let r = t.indexOf(s); r >= 0; r = t.indexOf(s, r + 1))
78
+ (o === null || Math.abs(r - n.start) < Math.abs(o - n.start)) && (o = r);
79
+ return o === null ? null : { start: o, end: o + s.length };
80
+ }
81
+ export {
82
+ b as C,
83
+ T as a,
84
+ c as b,
85
+ d as c,
86
+ C as d,
87
+ O as e,
88
+ M as f,
89
+ j as g,
90
+ E as h,
91
+ y as i,
92
+ k as r,
93
+ p as s
94
+ };
@@ -0,0 +1,41 @@
1
+ import { p as o, R as n, r as h } from "./replica-Di2iCPiD.js";
2
+ import { C as i, a as m, b as a, c as p, d as r } from "./comment-Ds9t8xSE.js";
3
+ import "./envelope-GX4Cynkx.js";
4
+ const y = (e) => e.slice().buffer;
5
+ function E(e) {
6
+ return o({
7
+ kdm: 1,
8
+ kit: e,
9
+ // A document's minimum schema version is at most this, so every version of the kit's documents opens.
10
+ schemaVersion: 4294967295,
11
+ root: a,
12
+ types: { [a]: m, [p]: i }
13
+ });
14
+ }
15
+ class u {
16
+ schema;
17
+ copy = null;
18
+ constructor(s) {
19
+ this.schema = E(s);
20
+ }
21
+ /** The threads as the replica holds them now. */
22
+ async threads(s) {
23
+ if (this.copy)
24
+ try {
25
+ const { changes: t } = await s.exportChanges(y(this.copy.version().encode()));
26
+ return t.byteLength && this.copy.importChanges(new Uint8Array(t)), r(this.copy);
27
+ } catch {
28
+ this.copy = null;
29
+ }
30
+ const { changes: c } = await s.exportChanges(new ArrayBuffer(0));
31
+ return this.copy = n.load(this.schema, new Uint8Array(c), h()), r(this.copy);
32
+ }
33
+ /** Forgets the copy, for a kit opened again. */
34
+ reset() {
35
+ this.copy = null;
36
+ }
37
+ }
38
+ export {
39
+ u as CommentReader,
40
+ E as commentSchema
41
+ };
@@ -0,0 +1,324 @@
1
+ import { B as p, f as E, d as S } from "./batch-CAGYk6m4.js";
2
+ import { K as x } from "./envelope-GX4Cynkx.js";
3
+ import { p as k, R as f, r as b, k as j } from "./replica-Di2iCPiD.js";
4
+ import { k as A } from "./kits-Cp51mDlw.js";
5
+ import { RequestContext as I } from "../script/proxy.js";
6
+ const y = "the kit refused the changes";
7
+ class P {
8
+ constructor(e, s) {
9
+ this.port = e, this.schema = "types" in s && "root" in s && "kit" in s ? k(s) : s;
10
+ }
11
+ scratch = null;
12
+ queue = Promise.resolve();
13
+ schema;
14
+ /** The scratch replica's version after the last batch, or `null` before the first. */
15
+ version() {
16
+ return this.scratch?.version() ?? null;
17
+ }
18
+ async catchUp() {
19
+ if (this.scratch) {
20
+ const e = await this.port.exportChanges(this.scratch.version().encode());
21
+ try {
22
+ e.byteLength > 0 && this.scratch.importChanges(e);
23
+ } catch (s) {
24
+ if (!(s instanceof x) || s.reason !== "wrong-document") throw s;
25
+ this.scratch = null;
26
+ const n = await this.port.exportChanges(new Uint8Array(0));
27
+ this.scratch = f.load(this.schema, n, b());
28
+ }
29
+ } else {
30
+ const e = await this.port.exportChanges(new Uint8Array(0));
31
+ this.scratch = f.load(this.schema, e, b());
32
+ }
33
+ return this.scratch;
34
+ }
35
+ target() {
36
+ return {
37
+ replica: () => this.catchUp(),
38
+ transact: async (e, s) => {
39
+ const n = await this.catchUp(), r = n.version();
40
+ if (n.transact(e, s), !n.version().equals(r))
41
+ try {
42
+ await this.port.importChanges(n.exportChanges(r));
43
+ } catch (i) {
44
+ throw new p("invalid-value", null, `${y}: ${i instanceof Error ? i.message : String(i)}`);
45
+ }
46
+ },
47
+ command: (e, s, n) => this.port.command(e, s, n),
48
+ readOnly: () => this.port.readOnly?.() ?? !1,
49
+ ...this.port.projectedObjects ? { projectedObjects: () => this.port.projectedObjects() } : {}
50
+ };
51
+ }
52
+ serial(e) {
53
+ const s = this.queue.then(e, e);
54
+ return this.queue = s.catch(() => {
55
+ }), s;
56
+ }
57
+ /** `model/batch`. */
58
+ batch(e) {
59
+ return this.serial(async () => {
60
+ try {
61
+ return await E(this.target(), e);
62
+ } catch (s) {
63
+ throw s instanceof p && s.message.startsWith(y) && (this.scratch = null), s;
64
+ }
65
+ });
66
+ }
67
+ /** `model/describe`: the schema, the root, and the kit's commands. */
68
+ describe() {
69
+ return this.serial(async () => {
70
+ const e = await this.port.commands();
71
+ return { ...S(await this.catchUp()), commands: e };
72
+ });
73
+ }
74
+ /** Forgets the scratch replica (the engine opened another document). */
75
+ reset() {
76
+ this.scratch = null;
77
+ }
78
+ }
79
+ const U = ["invalid-op", "not-found", "invalid-value", "read-only", "command-failed"];
80
+ function g(t) {
81
+ const e = t?.data;
82
+ if (!e || typeof e.code != "string" || !U.includes(e.code)) return t;
83
+ const s = typeof e.message == "string" ? e.message : t instanceof Error ? t.message : String(t);
84
+ return new p(e.code, typeof e.index == "number" ? e.index : null, s);
85
+ }
86
+ function B(t, e) {
87
+ const s = "types" in e && "root" in e && "kit" in e ? k(e) : e, n = JSON.parse(JSON.stringify(e));
88
+ let r = null, i = Promise.resolve(), a = null;
89
+ const u = (o) => {
90
+ const c = i.then(o, o);
91
+ return i = c.catch(() => {
92
+ }), c;
93
+ };
94
+ return {
95
+ kitId: t.kitId,
96
+ schema: s,
97
+ batch: (o) => u(async () => {
98
+ const c = t.model.batch(o, n);
99
+ a = c.catch(() => {
100
+ });
101
+ try {
102
+ const { version: l, ...O } = await c;
103
+ return r = l ?? null, O;
104
+ } catch (l) {
105
+ throw g(l);
106
+ } finally {
107
+ a = null;
108
+ }
109
+ }),
110
+ describe: () => u(async () => {
111
+ try {
112
+ return await t.model.describe(n);
113
+ } catch (o) {
114
+ throw g(o);
115
+ }
116
+ }),
117
+ commands: () => t.commands(),
118
+ version: () => r,
119
+ events: t.events,
120
+ on: t.on?.bind(t),
121
+ onChanged: t.onChanged ? (o) => t.onChanged((c) => {
122
+ const l = a;
123
+ l ? l.then(() => o(c)) : o(c);
124
+ }) : void 0
125
+ };
126
+ }
127
+ const h = (t) => typeof t == "object" && t !== null, d = (t) => typeof t == "function";
128
+ function M(t) {
129
+ return h(t) && typeof t.kitId == "string" && d(t.exportChanges) && d(t.importChanges) && d(t.command);
130
+ }
131
+ const m = (t) => t instanceof Uint8Array ? t : new Uint8Array(t), w = (t) => t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength), N = (t) => h(t) && h(t.kit) && Array.isArray(t.capabilities) && h(t.ai) && h(t.replica);
132
+ function D(t, e = {}) {
133
+ const s = t.capabilities.includes("model") ? t.model : void 0;
134
+ if (!t.capabilities.includes("replica") && !s)
135
+ throw new Error(`${t.kit.id} was opened without the replica capability: the host must offer replica (with @kition/embed, pass storage.replica or model: true)`);
136
+ const n = typeof t.onPresence == "function" ? t.onPresence.bind(t) : null;
137
+ return {
138
+ kitId: t.kit.id,
139
+ exportChanges: async (r) => m((await t.replica.exportChanges(w(r))).changes),
140
+ importChanges: async (r) => {
141
+ await t.replica.importChanges(w(r), new ArrayBuffer(0));
142
+ },
143
+ command: async (r, i) => (await t.ai.run([{ command: r, ...h(i) ? { params: i } : {} }], !1)).completed[0]?.result ?? null,
144
+ commands: async () => await t.ai.commands(""),
145
+ readOnly: e.readOnly,
146
+ onChanged: (r) => t.replica.onChanged((i) => r(m(i))),
147
+ ...n ? {
148
+ events: ["selection"],
149
+ on: (r, i) => r === "selection" ? n((a) => i({ ids: [...a.selection] })) : () => {
150
+ }
151
+ } : {},
152
+ ...s ? {
153
+ model: {
154
+ describe: (r) => s.describe(r),
155
+ batch: async (r, i) => {
156
+ const { version: a, ...u } = await s.batch({ ...r, schema: i });
157
+ return { ...u, version: a ? m(a) : null };
158
+ }
159
+ }
160
+ } : {}
161
+ };
162
+ }
163
+ const J = (t) => h(t) && d(t.exportChanges) && d(t.importChanges) && d(t.execute) && d(t.commands), R = (t) => t === "" ? null : JSON.parse(t);
164
+ function $(t, e, s = {}) {
165
+ return {
166
+ events: s.events,
167
+ on: s.on,
168
+ kitId: e,
169
+ exportChanges: async (n) => t.exportChanges(n),
170
+ importChanges: async (n) => {
171
+ t.importChanges(n);
172
+ },
173
+ command: async (n, r, i) => {
174
+ const a = JSON.stringify(r ?? {});
175
+ return R(t.executeAs ? t.executeAs(n, a, j(i)) : t.execute(n, a));
176
+ },
177
+ commands: async () => JSON.parse(t.commands()),
178
+ readOnly: s.readOnly,
179
+ onChanged: s.onChanged,
180
+ ...t.premiseRead ? { projectedObjects: async () => JSON.parse(t.premiseRead("projected", "{}")) } : {}
181
+ };
182
+ }
183
+ async function F(t, e) {
184
+ if (h(t) && d(t.modelPort)) return await t.modelPort();
185
+ if (N(t)) return D(t);
186
+ if (J(t)) {
187
+ if (!e) throw new Error("an engine does not name its kit: pass options.kit");
188
+ return $(t, e);
189
+ }
190
+ throw new Error("openDocument takes a ModelPort, an @kition/embed editor, a KitConnection, or a kit engine");
191
+ }
192
+ function C(t) {
193
+ return {
194
+ kitId: t.port.kitId,
195
+ schema: t.schema,
196
+ batch: (e) => t.batch(e),
197
+ describe: () => t.describe(),
198
+ commands: () => t.port.commands(),
199
+ version: () => t.version()?.encode() ?? null,
200
+ onChanged: t.port.onChanged?.bind(t.port),
201
+ events: t.port.events,
202
+ on: t.port.on?.bind(t.port)
203
+ };
204
+ }
205
+ class v {
206
+ constructor(e, s) {
207
+ this.backend = e, this.origin = s, this.unsubscribe = e.onChanged?.((n) => {
208
+ const r = this.backend.version();
209
+ n && r && K(n, r) || this.emit({ origin: "kit", version: n });
210
+ }) ?? null;
211
+ }
212
+ listeners = /* @__PURE__ */ new Set();
213
+ unsubscribe = null;
214
+ /** Unsubscribes of the source's other events this handle hears. */
215
+ hearing = /* @__PURE__ */ new Set();
216
+ closed = !1;
217
+ get kitId() {
218
+ return this.backend.kitId;
219
+ }
220
+ get schema() {
221
+ return this.backend.schema;
222
+ }
223
+ /**
224
+ * Runs `script` with a new request context; operations it queued and did not `sync()` are sent
225
+ * when it returns. Answers what `script` answers.
226
+ */
227
+ async run(e) {
228
+ const s = this.context(), n = await e(s);
229
+ return s.queued && await s.sync(), n;
230
+ }
231
+ /** A request context to keep (`run` makes one per script). */
232
+ context() {
233
+ return this.alive(), new I(this.schema, (e) => this.batch(e), this.origin);
234
+ }
235
+ /** One `model/batch` in its wire form. */
236
+ async batch(e) {
237
+ this.alive();
238
+ const s = await this.backend.batch(e.origin || !this.origin ? e : { ...e, origin: this.origin });
239
+ return (e.ops?.length ?? 0) > 0 && this.emit({ origin: "local", version: this.backend.version() }), s;
240
+ }
241
+ /** `model/describe`: the schema, the root's id, and the kit's commands. */
242
+ describe() {
243
+ return this.alive(), this.backend.describe();
244
+ }
245
+ commands = {
246
+ list: () => this.backend.commands(),
247
+ /** Whether a command can run now. */
248
+ enabled: async (e) => (await this.backend.commands()).some((s) => s.id === e && s.enabled !== !1),
249
+ /** Runs one command now (outside any request context). */
250
+ run: async (e, s) => (await this.batch({ ops: [{ op: "command", id: e, ...s === void 0 ? {} : { params: s } }] })).results[0]
251
+ };
252
+ /**
253
+ * Whether this document's source reports `event`: `changed` always; `saved`, `presence`,
254
+ * `conflict`, and `selection` when its host or kit does (an `@kition/embed` editor reports
255
+ * `saved` and `conflict`, and `presence` when it co-edits; a headless kit and a Node package
256
+ * document report `saved`).
257
+ */
258
+ supports(e) {
259
+ return e === "changed" || typeof this.backend.on == "function" && (this.backend.events ?? []).includes(e);
260
+ }
261
+ on(e, s) {
262
+ if (e === "changed") {
263
+ const r = s;
264
+ return this.listeners.add(r), () => {
265
+ this.listeners.delete(r);
266
+ };
267
+ }
268
+ if (!q.includes(e)) throw new Error(`unknown event \`${e}\``);
269
+ if (this.alive(), !this.supports(e)) return () => {
270
+ };
271
+ const n = this.backend.on(e, (r) => {
272
+ const i = s;
273
+ try {
274
+ i(r);
275
+ } catch (a) {
276
+ console.error(`[kition-sdk] a ${e} listener failed`, a);
277
+ }
278
+ });
279
+ return this.hearing.add(n), () => {
280
+ this.hearing.delete(n) && n();
281
+ };
282
+ }
283
+ /** Stops listening to the engine; the engine (or the kit's document) itself stays open. */
284
+ close() {
285
+ this.closed = !0, this.unsubscribe?.(), this.unsubscribe = null, this.listeners.clear();
286
+ for (const e of this.hearing) e();
287
+ this.hearing.clear();
288
+ }
289
+ alive() {
290
+ if (this.closed) throw new Error("the document handle is closed");
291
+ }
292
+ emit(e) {
293
+ for (const s of [...this.listeners])
294
+ try {
295
+ s(e);
296
+ } catch (n) {
297
+ console.error("[kition-sdk] a changed listener failed", n);
298
+ }
299
+ }
300
+ }
301
+ const q = ["saved", "presence", "conflict", "selection"], K = (t, e) => t.byteLength === e.byteLength && t.every((s, n) => s === e[n]);
302
+ async function L(t, e = {}) {
303
+ const s = M(t) ? t : await F(t, e.kit), n = e.schema ?? A(s.kitId)?.schema;
304
+ if (!n) throw new Error(`no schema for ${s.kitId}: pass options.schema or registerKit() its descriptor`);
305
+ const r = s.model ? B({ ...s, model: s.model }, n) : C(new P(s, n));
306
+ return new v(r, e.origin);
307
+ }
308
+ const G = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
309
+ __proto__: null,
310
+ ModelDocument: v,
311
+ exchangeBackend: C,
312
+ openDocument: L
313
+ }, Symbol.toStringTag, { value: "Module" }));
314
+ export {
315
+ P as E,
316
+ v as M,
317
+ D as a,
318
+ G as d,
319
+ C as e,
320
+ M as i,
321
+ B as k,
322
+ L as o,
323
+ $ as p
324
+ };