@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,198 @@
1
+ import { R as M, E as d } from "../chunks/runtime-BVJHE1Pg.js";
2
+ import { P as N, a as O, S as _, W as H } from "../chunks/runtime-BVJHE1Pg.js";
3
+ import { RequestContext as $ } from "../../standalone/script/proxy.js";
4
+ class R {
5
+ constructor(s, o) {
6
+ this.peer = o, this.id = s.documentId, this.kitId = s.kitId, this.name = s.name, this.readOnly = s.readOnly, this.schema = s.schema;
7
+ }
8
+ listeners = /* @__PURE__ */ new Set();
9
+ id;
10
+ kitId;
11
+ /** The document's file name, when the host gives it. */
12
+ name;
13
+ /** Whether writes are refused (a read-only document, or no `model.write` permission). */
14
+ readOnly;
15
+ schema;
16
+ /** Runs `script` with a new request context; what it queued and did not `sync()` is sent when it returns. */
17
+ async run(s) {
18
+ const o = this.context(), l = await s(o);
19
+ return o.queued && await o.sync(), l;
20
+ }
21
+ context() {
22
+ return new $(this.schema, (s) => this.batch(s));
23
+ }
24
+ /** One `model/batch` in its wire form (the host sets its origin). */
25
+ batch(s) {
26
+ return this.peer.request("model/batch", { documentId: this.id, request: s });
27
+ }
28
+ describe() {
29
+ return this.peer.request("model/describe", { documentId: this.id });
30
+ }
31
+ commands = {
32
+ list: () => this.peer.request("model/commands", { documentId: this.id }),
33
+ enabled: async (s) => (await this.commands.list()).some((o) => o.id === s && o.enabled !== !1),
34
+ run: async (s, o) => (await this.batch({ ops: [{ op: "command", id: s, ...o === void 0 ? {} : { params: o } }] })).results[0]
35
+ };
36
+ on(s, o) {
37
+ if (s !== "changed") throw new Error(`unknown event \`${s}\``);
38
+ return this.listeners.add(o), () => {
39
+ this.listeners.delete(o);
40
+ };
41
+ }
42
+ /** The host's `document/changed`. */
43
+ emit(s) {
44
+ for (const o of [...this.listeners])
45
+ try {
46
+ o(s);
47
+ } catch (l) {
48
+ console.error("[kition-extension] a changed listener failed", l);
49
+ }
50
+ }
51
+ close() {
52
+ this.listeners.clear();
53
+ }
54
+ }
55
+ const f = (b) => typeof b == "function";
56
+ function A(b, s) {
57
+ const o = new M(b);
58
+ let l = null, x = null, v = "extension";
59
+ const h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), k = (e) => {
60
+ const t = g.get(e);
61
+ if (t) {
62
+ g.delete(e), t.peer.close("the panel closed");
63
+ for (const n of [...t.closed, ...t.dispose ? [t.dispose] : []])
64
+ try {
65
+ n();
66
+ } catch (a) {
67
+ console.error("[kition-extension] a panel close listener failed", a);
68
+ }
69
+ }
70
+ }, I = (e, t, n, a) => {
71
+ const u = new R(e, o), { id: w, name: m, version: p, permissions: y } = l;
72
+ return {
73
+ extension: { id: w, name: m, version: p, permissions: [...y] },
74
+ document: u,
75
+ commands: {
76
+ register: (i, c) => {
77
+ if (typeof i != "string" || !f(c)) throw new TypeError("commands.register takes a command id and a function");
78
+ if (v === "script") throw new d("invalid", "a script cannot register commands");
79
+ if (!l.contributes.commands.some((r) => r.id === i))
80
+ throw new d("invalid", `${w} does not contribute ${i}: declare it in extension.json contributes.commands`);
81
+ return n.set(i, c), t.push(o.request("commands/register", { documentId: e.documentId, command: i })), () => {
82
+ n.get(i) === c && n.delete(i);
83
+ };
84
+ }
85
+ },
86
+ panels: {
87
+ register: (i, c) => {
88
+ if (typeof i != "string" || !f(c)) throw new TypeError("panels.register takes a panel id and a function");
89
+ if (v === "script") throw new d("invalid", "a script cannot serve panels");
90
+ if (!l.contributes.panels?.some((r) => r.id === i))
91
+ throw new d("invalid", `${w} does not contribute the panel ${i}: declare it in extension.json contributes.panels`);
92
+ return a.set(i, c), () => {
93
+ a.get(i) === c && a.delete(i);
94
+ };
95
+ }
96
+ },
97
+ notify: (i, c) => {
98
+ const r = typeof i == "string" ? { level: c?.level ?? "info", title: i, ...c?.description ? { description: c.description } : {} } : i;
99
+ o.notify("host/notify", r);
100
+ },
101
+ subscriptions: []
102
+ };
103
+ }, E = () => {
104
+ if (!l || !x) throw new d("failed", "the extension has not started");
105
+ return { manifest: l, module: x };
106
+ };
107
+ return o.handle("extension/start", async (e) => {
108
+ if (x) throw new d("invalid", "the extension has already started");
109
+ l = e.manifest, v = e.kind ?? "extension";
110
+ const t = await s(e.source);
111
+ if (v === "script" ? !f(t.default) && !f(t.run) : !f(t.activate))
112
+ throw new d("invalid", v === "script" ? "a script exports a default function (or run)" : `${l.entry} exports no activate function`);
113
+ return x = t, null;
114
+ }).handle("extension/activate", async (e) => {
115
+ const { module: t } = E();
116
+ if (h.has(e.documentId)) return { commands: [...h.get(e.documentId).handlers.keys()] };
117
+ const n = [], a = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), w = I(e, n, a, u), m = { context: w, handlers: a, panels: u, disposeActivate: null };
118
+ h.set(e.documentId, m);
119
+ try {
120
+ const p = await t.activate(w);
121
+ f(p) && (m.disposeActivate = p), await Promise.all(n);
122
+ } catch (p) {
123
+ h.delete(e.documentId);
124
+ for (const y of n) y.catch(() => {
125
+ });
126
+ throw p;
127
+ }
128
+ return { commands: [...a.keys()] };
129
+ }).handle("extension/command", async ({ documentId: e, command: t }) => {
130
+ const n = h.get(e)?.handlers.get(t);
131
+ if (!n) throw new d("not-found", `${t} is not registered on ${e}`);
132
+ return await n() ?? null;
133
+ }).handle("extension/deactivate", async ({ documentId: e }) => {
134
+ const t = h.get(e);
135
+ if (!t) return null;
136
+ h.delete(e);
137
+ for (const [a, u] of [...g]) u.documentId === e && k(a);
138
+ const { context: n } = t;
139
+ try {
140
+ await x?.deactivate?.(n), await t.disposeActivate?.();
141
+ } finally {
142
+ for (const a of n.subscriptions.splice(0))
143
+ try {
144
+ a();
145
+ } catch (u) {
146
+ console.error("[kition-extension] a subscription failed to dispose", u);
147
+ }
148
+ n.document.close();
149
+ }
150
+ return null;
151
+ }).handle("script/run", async (e) => {
152
+ const { module: t } = E(), n = f(t.default) ? t.default : t.run, a = I(e, [], /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map());
153
+ return h.set(e.documentId, { context: a, handlers: /* @__PURE__ */ new Map(), panels: /* @__PURE__ */ new Map(), disposeActivate: null }), await n(a) ?? null;
154
+ }).handle("document/changed", ({ documentId: e, origin: t }) => {
155
+ h.get(e)?.context.document.emit({ origin: t });
156
+ }).handle("panel/open", async ({ documentId: e, panel: t, session: n }, a) => {
157
+ const u = h.get(e);
158
+ if (!u) throw new d("not-found", `the extension is not active on ${e}`);
159
+ const w = a[0];
160
+ if (!w) throw new d("invalid", "a panel opens with its port");
161
+ if (g.has(n)) throw new d("invalid", `the panel session ${n} is open already`);
162
+ const m = new M(w);
163
+ let p = null;
164
+ m.handle("panel/request", async (r) => {
165
+ if (!p) throw new d("not-found", `the extension does not answer the panel ${t}`);
166
+ return await p(r) ?? null;
167
+ });
168
+ const y = { documentId: e, peer: m, closed: /* @__PURE__ */ new Set(), dispose: null };
169
+ g.set(n, y);
170
+ const i = {
171
+ id: t,
172
+ session: n,
173
+ post: (r) => m.notify("panel/message", r),
174
+ onRequest: (r) => {
175
+ if (!f(r)) throw new TypeError("onRequest takes a function");
176
+ p = r;
177
+ },
178
+ onClose: (r) => (y.closed.add(r), () => {
179
+ y.closed.delete(r);
180
+ })
181
+ }, c = u.panels.get(t);
182
+ try {
183
+ const r = c ? await c(i) : null;
184
+ f(r) && (y.dispose = r);
185
+ } catch (r) {
186
+ throw k(n), r;
187
+ }
188
+ return null;
189
+ }).handle("panel/close", ({ session: e }) => (k(e), null)), o;
190
+ }
191
+ export {
192
+ R as ExtensionDocument,
193
+ N as PANEL_HTML,
194
+ O as RUNTIME_INPUTS_SHA256,
195
+ _ as SANDBOX_HTML,
196
+ H as WORKER_RUNTIME,
197
+ A as startRuntime
198
+ };
@@ -0,0 +1,35 @@
1
+ <!doctype html>
2
+ <!-- Generated by packages/extensions/scripts/build-runtime.mjs from sandbox/bootstrap.js. Do not edit; rebuild it. -->
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="Content-Security-Policy" content="script-src 'sha256-w5PK36FENsjJixOfZqEByZ2fjQ+2p/KZc2ZsgQ9e4rs=' blob:; worker-src blob:; object-src 'none'; base-uri 'none'; form-action 'none'; frame-src 'none'; img-src 'none'; media-src 'none'; font-src 'none'; style-src 'none'; manifest-src 'none'">
7
+ <meta name="referrer" content="no-referrer">
8
+ <title>Kition extension sandbox</title>
9
+ <script>// The extension sandbox page's only script (its CSP allows it by hash). The host posts it the
10
+ // worker runtime, the extension's allowed connect-src, and the channel's port; it adds the
11
+ // connect-src policy, starts the worker from a blob, and hands the worker the port.
12
+ ;(() => {
13
+ 'use strict'
14
+ const TAG = 'kition-ext-sandbox/1'
15
+ const SOURCE = /^(?:'none'|(?:(?:https|wss|http|ws):\/\/(?:\*\.)?[a-z0-9.-]+(?::\d{1,5})?)(?: (?:https|wss|http|ws):\/\/(?:\*\.)?[a-z0-9.-]+(?::\d{1,5})?)*)$/
16
+ let started = false
17
+ addEventListener('message', (event) => {
18
+ const data = event.data
19
+ if (started || event.source !== parent || !data || data.tag !== TAG || data.type !== 'start') return
20
+ const port = event.ports[0]
21
+ if (!port || typeof data.runtime !== 'string' || typeof data.connect !== 'string' || !SOURCE.test(data.connect)) return
22
+ started = true
23
+ const policy = document.createElement('meta')
24
+ policy.httpEquiv = 'Content-Security-Policy'
25
+ policy.content = `connect-src ${data.connect}`
26
+ document.head.appendChild(policy)
27
+ const url = URL.createObjectURL(new Blob([data.runtime], { type: 'text/javascript' }))
28
+ const worker = new Worker(url, { name: 'kition-extension' })
29
+ worker.postMessage({ tag: TAG, type: 'port' }, [port])
30
+ })
31
+ })()
32
+ </script>
33
+ </head>
34
+ <body></body>
35
+ </html>
@@ -0,0 +1,437 @@
1
+ import { B as At, O as Tt, P as St, b as Et, d as vt, h as Mt, r as Nt, a as It, c as jt, e as kt, f as Ct, s as Rt } from "../chunks/batch-BWpAyHvP.js";
2
+ import { K as F, e as v, c as I, a as z } from "../chunks/canonical-BIWfVCL-.js";
3
+ import { LoroDoc as H, isContainer as U, LoroMap as W } from "loro-crdt";
4
+ import { o as k, V as L } from "../chunks/envelope-D6MGY-ZN.js";
5
+ import { O as B, T as X, R as P, n as G } from "../chunks/replica-D8w3I4sn.js";
6
+ import { E as Bt, L as Jt, N as Dt, a as Pt, d as $t, b as Ft, c as Lt, e as Vt, r as xt, t as Kt, u as Yt, f as qt, g as zt, w as Ht, h as Ut, i as Wt, j as Xt } from "../chunks/replica-D8w3I4sn.js";
7
+ import { K as Qt, T as Zt, k as te, c as ee, l as se, d as ne, n as oe, q as ie, f as re, e as fe, h as ce, r as ae, i as de, g as le, p as ue, s as he, t as ge, u as pe } from "../chunks/toolIds-BCeSGHpV.js";
8
+ const S = "CommentThread", M = "Comment", ft = {
9
+ fields: { anchor: { kind: "json" }, resolved: { kind: "boolean", optional: !0 }, comments: { kind: "list", of: M } },
10
+ batchOps: { "*": { direct: !0 } }
11
+ }, ct = {
12
+ fields: { author: { kind: "string" }, name: { kind: "string", optional: !0 }, body: { kind: "text" }, created: { kind: "string" } },
13
+ batchOps: { "*": { direct: !0 } }
14
+ };
15
+ function Q(t) {
16
+ return t === S || t === M;
17
+ }
18
+ function V(t, e) {
19
+ const n = { author: e.author, created: e.created };
20
+ e.name !== void 0 && (n.name = e.name);
21
+ const s = t.create(M, n);
22
+ return e.body && t.textInsert(s, "body", 0, e.body), s;
23
+ }
24
+ function j(t, e) {
25
+ if (t.objectType(e) !== S) throw new F("invalid-value", `${e} is not a ${S}`);
26
+ }
27
+ function at(t, e, n) {
28
+ const s = t.create(S, { anchor: e, resolved: !1 }), o = V(t, n);
29
+ return t.listInsert(s, "comments", 0, o), { thread: s, comment: o };
30
+ }
31
+ function dt(t, e, n) {
32
+ j(t, e);
33
+ const s = V(t, n);
34
+ return t.listInsert(e, "comments", t.listItems(e, "comments").length, s), s;
35
+ }
36
+ function lt(t, e, n) {
37
+ j(t, e), t.set(e, "resolved", n);
38
+ }
39
+ function ut(t, e, n) {
40
+ j(t, e);
41
+ const s = t.listItems(e, "comments"), o = s.indexOf(n);
42
+ if (o < 0) throw new F("not-found", n);
43
+ t.listRemove(e, "comments", o), t.delete(n), s.length === 1 && t.delete(e);
44
+ }
45
+ function ht(t, e) {
46
+ j(t, e);
47
+ for (const n of t.listItems(e, "comments")) t.exists(n) && t.delete(n);
48
+ t.delete(e);
49
+ }
50
+ function Z(t) {
51
+ return t && typeof t == "object" && !Array.isArray(t) && typeof t.object == "string" ? t : null;
52
+ }
53
+ const C = (t) => typeof t == "string" ? t : void 0;
54
+ function gt(t) {
55
+ const e = t.schema.types;
56
+ if (!Object.hasOwn(e, S) || !Object.hasOwn(e, M)) return [];
57
+ const n = [];
58
+ for (const o of t.objectsOfType(S)) {
59
+ const r = [];
60
+ for (const f of t.list(o, "comments")) {
61
+ if (!t.exists(f) || t.objectType(f) !== M) continue;
62
+ const y = C(t.get(f, "name"));
63
+ r.push({
64
+ id: f,
65
+ author: C(t.get(f, "author")) ?? "",
66
+ ...y === void 0 ? {} : { name: y },
67
+ body: t.text(f, "body"),
68
+ created: C(t.get(f, "created")) ?? ""
69
+ });
70
+ }
71
+ n.push({ id: o, anchor: Z(t.get(o, "anchor")), resolved: t.get(o, "resolved") === !0, comments: r });
72
+ }
73
+ const s = (o) => o.comments[0]?.created ?? "";
74
+ 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);
75
+ }
76
+ function pt(t, e) {
77
+ const n = t.range;
78
+ if (!n) return null;
79
+ const s = t.quote;
80
+ if (!s) return n.end <= e.length ? n : null;
81
+ if (e.slice(n.start, n.end) === s) return n;
82
+ let o = null;
83
+ for (let r = e.indexOf(s); r >= 0; r = e.indexOf(s, r + 1))
84
+ (o === null || Math.abs(r - n.start) < Math.abs(o - n.start)) && (o = r);
85
+ return o === null ? null : { start: o, end: o + s.length };
86
+ }
87
+ function yt(t) {
88
+ if (t.outside) return !1;
89
+ for (const e of t.objects.values()) if (e === null || !Q(e)) return !1;
90
+ return !0;
91
+ }
92
+ const R = (t) => t instanceof Error ? t.message : String(t);
93
+ function $(t, e) {
94
+ const n = t.getMap(B).get(e);
95
+ if (!(n instanceof W)) return null;
96
+ const s = n.get(X);
97
+ return typeof s == "string" ? s : null;
98
+ }
99
+ class x {
100
+ constructor(e) {
101
+ this.doc = e;
102
+ }
103
+ /** From a snapshot or a full change export of the document. */
104
+ static load(e) {
105
+ const n = new H();
106
+ try {
107
+ n.import(k(e).engine);
108
+ } catch (s) {
109
+ throw v.encoding(R(s));
110
+ }
111
+ return new x(n);
112
+ }
113
+ version() {
114
+ return L.fromEngine(this.doc.oplogVersion());
115
+ }
116
+ /** Takes changes the document already holds without looking at them (another replica's, an undo). */
117
+ follow(e) {
118
+ try {
119
+ this.doc.import(k(e).engine);
120
+ } catch (n) {
121
+ throw v.encoding(R(n));
122
+ }
123
+ }
124
+ /** Takes `changes` and answers what they touched. */
125
+ touched(e) {
126
+ const n = k(e).engine, s = this.doc.oplogFrontiers(), o = /* @__PURE__ */ new Set();
127
+ let r = !1;
128
+ const f = this.doc.subscribe((a) => {
129
+ for (const u of a.events)
130
+ if (u.path[0] !== B) r = !0;
131
+ else if (u.path.length >= 2) o.add(String(u.path[1]));
132
+ else if (u.diff.type === "map") for (const m of Object.keys(u.diff.updated)) o.add(m);
133
+ else r = !0;
134
+ });
135
+ try {
136
+ this.doc.import(n);
137
+ } catch (a) {
138
+ throw v.encoding(R(a));
139
+ } finally {
140
+ f();
141
+ }
142
+ const y = /* @__PURE__ */ new Map();
143
+ if (!o.size) return { objects: y, outside: r };
144
+ const l = new Map([...o].map((a) => [a, $(this.doc, a)]));
145
+ this.doc.checkout(s);
146
+ try {
147
+ for (const a of o) y.set(a, $(this.doc, a) ?? l.get(a) ?? null);
148
+ } finally {
149
+ this.doc.checkoutToLatest();
150
+ }
151
+ for (const a of o) {
152
+ const u = this.doc.getMap(B).get(a);
153
+ u !== void 0 && !U(u) && y.set(a, null);
154
+ }
155
+ return { objects: y, outside: r };
156
+ }
157
+ }
158
+ const E = 4, w = (t) => typeof t == "object" && t !== null && !Array.isArray(t), O = (t, e) => Array.isArray(t[e]) ? t[e].filter(w) : [], T = (t) => w(t) && typeof t.parent == "string" && typeof t.field == "string" ? [t.parent, t.field] : null, N = (t, e) => JSON.stringify([t, e]);
159
+ function tt(t) {
160
+ const e = /* @__PURE__ */ new Map(), n = (s) => {
161
+ s && e.set(N(...s), s);
162
+ };
163
+ for (const s of [...O(t, "created"), ...O(t, "deleted")]) n(T(s.at));
164
+ for (const s of O(t, "moved"))
165
+ n(T(s.from)), n(T(s.to));
166
+ for (const s of O(t, "changed"))
167
+ if (!(!Array.isArray(s.edits) || s.edits.length > 0 || typeof s.id != "string"))
168
+ for (const o of Array.isArray(s.fields) ? s.fields : []) typeof o == "string" && n([s.id, o]);
169
+ return [...e.values()].sort((s, o) => s[0] === o[0] ? s[1] < o[1] ? -1 : s[1] > o[1] ? 1 : 0 : s[0] < o[0] ? -1 : 1);
170
+ }
171
+ function D(t, e) {
172
+ if (typeof t == "number" && typeof e == "number") {
173
+ const r = e - t;
174
+ return Number.isFinite(r) ? r : null;
175
+ }
176
+ const n = (r) => typeof r == "string" && /^-?\d+$/.test(r) ? BigInt(r) : null, [s, o] = [n(t), n(e)];
177
+ return s === null || o === null ? null : (o - s).toString();
178
+ }
179
+ function mt(t, e) {
180
+ const n = JSON.parse(JSON.stringify(t)), s = new Set(["created", "deleted", "moved"].flatMap((i) => O(t, i)).map((i) => i.id)), o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), f = [];
181
+ for (const i of O(t, "changed")) {
182
+ const d = Array.isArray(i.edits) ? i.edits : [];
183
+ if (typeof i.id != "string" || s.has(i.id) || d.length === 0) continue;
184
+ const c = [];
185
+ for (const h of d) {
186
+ if (!w(h) || typeof h.field != "string") break;
187
+ const p = D(h.before, h.after);
188
+ if (p === null) break;
189
+ c.push([h.field, p]);
190
+ }
191
+ const g = Array.isArray(i.fields) ? i.fields : [];
192
+ c.length !== d.length || g.length !== c.length || !c.every(([h]) => g.includes(h)) || (c.sort((h, p) => h[0] < p[0] ? -1 : h[0] > p[0] ? 1 : 0), c.length === 1 && (o.set(i.id, JSON.stringify(c[0])), r.set(i.id, c[0])), f.push([i.id, c]));
193
+ }
194
+ const y = [], l = /* @__PURE__ */ new Set(), a = tt(t);
195
+ if (o.size >= E)
196
+ for (const [i, d] of a) {
197
+ const c = e(i, d);
198
+ if (!c) continue;
199
+ let g = 0;
200
+ for (; g < c.length; ) {
201
+ const h = o.get(c[g]);
202
+ if (h === void 0) {
203
+ g += 1;
204
+ continue;
205
+ }
206
+ let p = g + 1;
207
+ for (; p < c.length && o.get(c[p]) === h; ) p += 1;
208
+ if (p - g >= E) {
209
+ const [K, Y] = r.get(c[g]);
210
+ y.push({ parent: i, field: d, from: g, count: p - g, shift: { field: K, by: Y } });
211
+ for (const q of c.slice(g, p)) l.add(q);
212
+ }
213
+ g = p;
214
+ }
215
+ }
216
+ const u = [];
217
+ for (const [i, d] of f) {
218
+ if (l.has(i)) continue;
219
+ const c = JSON.stringify(d), g = u.find(([h]) => h === c);
220
+ g ? g[2].push(i) : u.push([c, d, [i]]);
221
+ }
222
+ for (const [, i, d] of u)
223
+ if (!(d.length < E)) {
224
+ y.push({ ids: d, edits: i.map(([c, g]) => ({ field: c, by: g })) });
225
+ for (const c of d) l.add(c);
226
+ }
227
+ const m = /* @__PURE__ */ new Map();
228
+ for (const i of O(t, "changed")) {
229
+ if (typeof i.id != "string" || l.has(i.id) || s.has(i.id) || !Array.isArray(i.edits) || i.edits.length === 0 || !Array.isArray(i.fields)) continue;
230
+ const d = [];
231
+ for (const h of i.edits) {
232
+ if (!w(h) || typeof h.field != "string" || !Object.hasOwn(h, "after")) break;
233
+ const p = h.after;
234
+ if (w(p) && ("excerpt" in p || Object.keys(p).length === 1 && "size" in p)) break;
235
+ d.push({ field: h.field, after: p });
236
+ }
237
+ if (d.length !== i.edits.length || i.fields.length !== d.length || !d.every((h) => i.fields.includes(h.field))) continue;
238
+ d.sort((h, p) => I(h.field, p.field));
239
+ const c = z(d), g = m.get(c);
240
+ g ? g.ids.push(i.id) : m.set(c, { edits: d, ids: [i.id] });
241
+ }
242
+ for (const { edits: i, ids: d } of m.values())
243
+ if (!(d.length < E)) {
244
+ y.push({ ids: d, edits: i });
245
+ for (const c of d) l.add(c);
246
+ }
247
+ const b = new Set(
248
+ y.filter((i) => typeof i.parent == "string").map((i) => N(i.parent, i.field))
249
+ ), A = (i) => {
250
+ i && b.add(N(...i));
251
+ };
252
+ for (const i of [...O(t, "created"), ...O(t, "deleted")]) A(T(i.at));
253
+ for (const i of O(t, "moved"))
254
+ A(T(i.from)), A(T(i.to));
255
+ return Array.isArray(n.changed) && (n.changed = n.changed.filter((i) => {
256
+ if (!w(i) || typeof i.id != "string") return !0;
257
+ if (l.has(i.id)) return !1;
258
+ if (!Array.isArray(i.edits) || i.edits.length > 0 || !Array.isArray(i.fields)) return !0;
259
+ const d = i.id;
260
+ return i.fields = i.fields.filter((c) => typeof c != "string" || !b.has(N(d, c))), i.fields.length > 0;
261
+ })), y.length > 0 && (n.footprint = y), et(n);
262
+ }
263
+ function J(t, e, n, s, o) {
264
+ if (JSON.stringify(e) === JSON.stringify(n)) return !0;
265
+ if (w(e) && w(n)) {
266
+ const r = Object.keys(e).sort(I);
267
+ return r.some((f) => !f || f.includes(".") || f.includes("*")) || JSON.stringify(r) !== JSON.stringify(Object.keys(n).sort(I)) ? !1 : (o.add(t), r.every((f) => J(`${t}.${f}`, e[f], n[f], s, o)));
268
+ }
269
+ return Array.isArray(e) && Array.isArray(n) ? e.length !== n.length ? !1 : e.every((r, f) => J(`${t}.${f}`, r, n[f], s, o)) : D(e, n) === null ? !1 : (s.push({ field: t, before: e, after: n }), !0);
270
+ }
271
+ function et(t) {
272
+ for (const e of O(t, "changed")) {
273
+ const n = Array.isArray(e.edits) ? e.edits.filter(w) : [], s = [], o = /* @__PURE__ */ new Set();
274
+ for (const l of n) {
275
+ const a = [];
276
+ typeof l.field == "string" && (w(l.before) || Array.isArray(l.before)) && J(l.field, l.before, l.after, a, o) ? s.push(...a) : s.push(l);
277
+ }
278
+ const r = /* @__PURE__ */ new Map();
279
+ s.forEach((l, a) => {
280
+ const u = D(l.before, l.after);
281
+ if (u === null || typeof l.field != "string") return;
282
+ const m = l.field.split(".");
283
+ for (let b = 1; b < m.length - 1; b++) {
284
+ if (/^\d+$/.test(m[b]) && !o.has(m.slice(0, b).join("."))) continue;
285
+ const A = m.map((c, g) => g === b ? "*" : c).join("."), i = JSON.stringify([A, u]), d = r.get(i) ?? { field: A, by: u, members: [] };
286
+ d.members.push([a, m[b]]), r.set(i, d);
287
+ }
288
+ });
289
+ const f = /* @__PURE__ */ new Set(), y = [];
290
+ for (const l of [...r.values()].sort((a, u) => a.field < u.field ? -1 : a.field > u.field ? 1 : JSON.stringify(a.by) < JSON.stringify(u.by) ? -1 : 1)) {
291
+ const a = l.members.filter(([m]) => !f.has(m)), u = [...new Set(a.map(([, m]) => m))].sort(I);
292
+ u.length < E || u.length !== a.length || (y.push({ field: l.field, count: u.length, keys: u, shift: { by: l.by } }), a.forEach(([m]) => f.add(m)));
293
+ }
294
+ y.length && (e.edits = [...s.filter((l, a) => !f.has(a)), ...y], e.fields = [...new Set(e.edits.map((l) => l.field))].sort());
295
+ }
296
+ return t;
297
+ }
298
+ const _ = (1n << 64n) - 1n;
299
+ class st {
300
+ state;
301
+ constructor(e) {
302
+ this.state = BigInt(e) * 0x9e3779b97f4a7c15n & _ | 1n;
303
+ }
304
+ nextU64() {
305
+ return this.state ^= this.state >> 12n, this.state = (this.state ^ this.state << 25n) & _, this.state ^= this.state >> 27n, this.state * 0x2545f4914f6cdd1dn & _;
306
+ }
307
+ /** A value in `0..bound`, or 0 when `bound` is 0. */
308
+ below(e) {
309
+ return e <= 0 ? 0 : Number(this.nextU64() % BigInt(e));
310
+ }
311
+ shuffle(e) {
312
+ for (let n = e.length - 1; n > 0; n -= 1) {
313
+ const s = this.below(n + 1);
314
+ [e[n], e[s]] = [e[s], e[n]];
315
+ }
316
+ }
317
+ }
318
+ class Ot {
319
+ replicas;
320
+ rng;
321
+ /** Fails with `out-of-range` when `count` is 0: a network has at least one replica. */
322
+ constructor(e, n, s = 1) {
323
+ if (!Number.isSafeInteger(n) || n < 1) throw v.outOfRange(0, 0);
324
+ const o = P.create(e, G(), 1n), r = o.snapshot();
325
+ this.replicas = [o];
326
+ for (let f = 2; f <= n; f += 1) this.replicas.push(P.load(e, r, BigInt(f)));
327
+ this.rng = new st(s);
328
+ }
329
+ /** Sends what `to` lacks from `from`. */
330
+ deliver(e, n) {
331
+ const s = this.replica(n);
332
+ s.importChanges(this.replica(e).exportChanges(s.version()));
333
+ }
334
+ /**
335
+ * Delivers every replica's changes to every other replica in a seeded order, then sends
336
+ * everything again from scratch to prove that duplicates are harmless.
337
+ */
338
+ syncAll() {
339
+ const e = this.replicas.length, n = [];
340
+ for (let s = 0; s < e; s += 1)
341
+ for (let o = 0; o < e; o += 1) s !== o && n.push([s, o]);
342
+ this.rng.shuffle(n);
343
+ for (const [s, o] of n) this.deliver(s, o);
344
+ for (const [s, o] of n) this.replica(o).importChanges(this.replica(s).exportChanges(L.empty()));
345
+ }
346
+ /** The common canonical state; throws with both states when two replicas differ, or when there are no replicas. */
347
+ converged() {
348
+ const [e, ...n] = this.replicas;
349
+ if (!e) throw new Error("the network has no replicas");
350
+ const s = e.stateText();
351
+ return n.forEach((o, r) => {
352
+ const f = o.stateText();
353
+ if (f !== s) throw new Error(`replica 0 and ${r + 1} differ:
354
+ ${s}
355
+ ---
356
+ ${f}`);
357
+ }), s;
358
+ }
359
+ replica(e) {
360
+ if (!Number.isSafeInteger(e) || e < 0 || e >= this.replicas.length) throw v.outOfRange(e, this.replicas.length);
361
+ return this.replicas[e];
362
+ }
363
+ }
364
+ export {
365
+ At as BatchError,
366
+ S as COMMENT_THREAD_TYPE,
367
+ ft as COMMENT_THREAD_TYPE_DEF,
368
+ M as COMMENT_TYPE,
369
+ ct as COMMENT_TYPE_DEF,
370
+ x as ChangeAudit,
371
+ Bt as EXCERPT_CHARS,
372
+ E as FOOTPRINT_MIN_RUN,
373
+ Qt as KDM_VERSION,
374
+ F as KdmError,
375
+ Jt as LEAF_EDITS,
376
+ Ot as Network,
377
+ Dt as NodeRef,
378
+ Tt as OBJECT_MODEL_CAPABILITY,
379
+ St as ProjectionView,
380
+ P as Replica,
381
+ st as Rng,
382
+ Zt as ToolIds,
383
+ Pt as Tx,
384
+ L as Version,
385
+ at as addThread,
386
+ te as agent,
387
+ Et as batchOrigin,
388
+ z as canonicalText,
389
+ ee as checkValue,
390
+ gt as commentThreads,
391
+ se as decodeCommit,
392
+ ne as decodeOrigin,
393
+ ut as deleteComment,
394
+ ht as deleteThread,
395
+ vt as describeModel,
396
+ $t as diffIsEmpty,
397
+ Ft as diffStates,
398
+ Lt as diffWithToolIds,
399
+ oe as encodeCommit,
400
+ ie as encodeOrigin,
401
+ re as fieldDef,
402
+ tt as footprintLists,
403
+ fe as hasMarks,
404
+ Mt as hasProjections,
405
+ ce as hasToolIds,
406
+ Q as isCommentType,
407
+ ae as isContainer,
408
+ G as newDocId,
409
+ Vt as newObjectId,
410
+ de as objectReadOnly,
411
+ k as openEnvelope,
412
+ le as parseSchema,
413
+ ue as person,
414
+ xt as randomActor,
415
+ Nt as readField,
416
+ pt as relocateAnchorRange,
417
+ It as replicaTarget,
418
+ dt as reply,
419
+ jt as resolveValues,
420
+ kt as rootId,
421
+ Ct as runBatch,
422
+ Rt as schemaOfDescription,
423
+ lt as setResolved,
424
+ he as system,
425
+ Kt as textSpan,
426
+ yt as touchesOnlyComments,
427
+ ge as typeDef,
428
+ pe as undoScopeOf,
429
+ Yt as uuidFromBytes,
430
+ qt as uuidToBytes,
431
+ zt as uuidV7,
432
+ Ht as withDeletedBasis,
433
+ mt as withFootprint,
434
+ Ut as withLeafEdits,
435
+ Wt as withTextBasis,
436
+ Xt as withTextSpans
437
+ };