markloom 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/PACKAGES.md +26 -0
  2. package/README.md +20 -2
  3. package/collab.md +44 -7
  4. package/dist/ai/index.cjs +4 -4
  5. package/dist/ai/index.d.cts +5 -4
  6. package/dist/ai/index.d.ts +5 -4
  7. package/dist/ai/index.js +3 -3
  8. package/dist/ai/theme.css +66 -102
  9. package/dist/{chunk-YJAWPRJW.cjs → chunk-ACFYBYZJ.cjs} +2817 -903
  10. package/dist/chunk-CGYCJORO.js +759 -0
  11. package/dist/chunk-EADZKEU4.cjs +498 -0
  12. package/dist/chunk-EJSFZHGT.js +24 -0
  13. package/dist/{chunk-SLRD6FMP.cjs → chunk-I5VK4U7J.cjs} +122 -73
  14. package/dist/{chunk-WUHTCCAE.js → chunk-KYZJIOOL.js} +2403 -489
  15. package/dist/chunk-QEVME6ZU.cjs +759 -0
  16. package/dist/{chunk-MFYF2A6U.js → chunk-SNFF6X45.js} +51 -1
  17. package/dist/{chunk-JMOJU5EU.js → chunk-TB2OY3D4.js} +69 -20
  18. package/dist/{chunk-4TMHVNL6.cjs → chunk-TWD5T4YC.cjs} +155 -105
  19. package/dist/{chunk-JS527FDV.cjs → chunk-U3JZDFL4.cjs} +49 -9
  20. package/dist/{chunk-RLTHVQNQ.js → chunk-VSBIMMI7.js} +45 -5
  21. package/dist/chunk-YBAT343I.js +498 -0
  22. package/dist/chunk-ZKQSQSSM.cjs +24 -0
  23. package/dist/{client-BNams4wv.d.cts → client-CLYq17SW.d.ts} +70 -7
  24. package/dist/{client-A0ZQJnyR.d.ts → client-DAth8pPq.d.cts} +70 -7
  25. package/dist/collab/index.cjs +22 -4
  26. package/dist/collab/index.d.cts +24 -3
  27. package/dist/collab/index.d.ts +24 -3
  28. package/dist/collab/index.js +24 -6
  29. package/dist/{controller-BkY1VPzc.d.ts → controller-6AJ36G52.d.ts} +108 -8
  30. package/dist/{controller-CVIZI--A.d.cts → controller-BIOO_XKJ.d.cts} +108 -8
  31. package/dist/index.cjs +57 -7
  32. package/dist/index.d.cts +18 -5
  33. package/dist/index.d.ts +18 -5
  34. package/dist/index.js +54 -4
  35. package/dist/io/index.cjs +1413 -0
  36. package/dist/io/index.d.cts +33 -0
  37. package/dist/io/index.d.ts +33 -0
  38. package/dist/io/index.js +1413 -0
  39. package/dist/react/index.cjs +8 -8
  40. package/dist/react/index.d.cts +5 -4
  41. package/dist/react/index.d.ts +5 -4
  42. package/dist/react/index.js +7 -7
  43. package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-DlerAcFN.d.ts} +11 -9
  44. package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-PjENQ742.d.cts} +11 -9
  45. package/dist/suggest-Bk4zLzuv.d.ts +120 -0
  46. package/dist/suggest-BkGGiPKA.d.cts +120 -0
  47. package/dist/types-COUweEav.d.cts +30 -0
  48. package/dist/types-COUweEav.d.ts +30 -0
  49. package/dist/versions-9mG1epfB.d.cts +51 -0
  50. package/dist/versions-Bubyo4pt.d.ts +51 -0
  51. package/dist/view/index.cjs +56 -12
  52. package/dist/view/index.d.cts +203 -11
  53. package/dist/view/index.d.ts +203 -11
  54. package/dist/view/index.js +52 -8
  55. package/dist/view/theme.css +1840 -1526
  56. package/io.md +38 -0
  57. package/package.json +21 -5
  58. package/dist/chunk-6DCI7AL3.js +0 -208
  59. package/dist/chunk-AC5E42NH.cjs +0 -208
  60. package/dist/chunk-GQ2HHRGI.cjs +0 -16
  61. package/dist/chunk-LA5SBCGQ.js +0 -16
  62. package/dist/chunk-LEYAQNJA.js +0 -220
  63. package/dist/chunk-YXQDCW4Y.cjs +0 -220
  64. package/dist/comments-DlExS6f-.d.cts +0 -43
  65. package/dist/comments-PhnR7Gkn.d.ts +0 -43
  66. package/dist/step-BrvHIK7O.d.cts +0 -65
  67. package/dist/step-BrvHIK7O.d.ts +0 -65
@@ -0,0 +1,498 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
+
3
+
4
+ var _chunkU3JZDFL4cjs = require('./chunk-U3JZDFL4.cjs');
5
+
6
+ // src/collab/colors.ts
7
+ var COLLAB_COLORS = [
8
+ "#ffd6d6",
9
+ // 浅粉
10
+ "#ffe8b8",
11
+ // 浅杏
12
+ "#d4f0c8",
13
+ // 薄荷绿
14
+ "#c8e4ff",
15
+ // 天蓝
16
+ "#e0d4f5",
17
+ // 薰衣草
18
+ "#d0d0d0",
19
+ // 浅灰
20
+ "#6b6b6b",
21
+ // 深灰
22
+ "#e85d4c",
23
+ // 红
24
+ "#f5a623",
25
+ // 橙
26
+ "#f0c040",
27
+ // 黄
28
+ "#34b33a",
29
+ // 绿
30
+ "#3b6ff5",
31
+ // 蓝
32
+ "#7c5cff"
33
+ // 紫
34
+ ];
35
+ var COLLAB_CARET_COLORS = [
36
+ "#f06a6a",
37
+ // 粉
38
+ "#e09a20",
39
+ // 杏
40
+ "#3db84a",
41
+ // 绿
42
+ "#3d8cf0",
43
+ // 天蓝
44
+ "#8b6ef0",
45
+ // 薰衣草
46
+ "#8a8a8a",
47
+ // 灰
48
+ "#4a4a4a",
49
+ // 深灰
50
+ "#e03d30",
51
+ // 红
52
+ "#f09000",
53
+ // 橙
54
+ "#e0a800",
55
+ // 黄
56
+ "#1f9e28",
57
+ // 绿
58
+ "#2f5ff0",
59
+ // 蓝
60
+ "#6a48f0"
61
+ // 紫
62
+ ];
63
+ function collabColor(siteId, explicit) {
64
+ if (explicit)
65
+ return explicit;
66
+ const i = Math.abs((siteId || 1) - 1) % COLLAB_COLORS.length;
67
+ return COLLAB_COLORS[i];
68
+ }
69
+ function collabCaretColor(siteId, explicit) {
70
+ if (explicit)
71
+ return solidify(explicit);
72
+ const i = Math.abs((siteId || 1) - 1) % COLLAB_CARET_COLORS.length;
73
+ return COLLAB_CARET_COLORS[i];
74
+ }
75
+ function solidify(hex) {
76
+ const rgb = parseHex(hex);
77
+ if (!rgb)
78
+ return hex;
79
+ const [r, g, b] = rgb;
80
+ const luma = 0.2126 * (r / 255) + 0.7152 * (g / 255) + 0.0722 * (b / 255);
81
+ if (luma <= 0.48)
82
+ return hex;
83
+ const target = 0.4;
84
+ const scale = target / Math.max(luma, 0.01);
85
+ const mid = (r + g + b) / 3;
86
+ const sat = 1.25;
87
+ const punch = (c) => {
88
+ const away = mid + (c - mid) * sat;
89
+ return Math.max(0, Math.min(255, Math.round(away * scale)));
90
+ };
91
+ return toHex(punch(r), punch(g), punch(b));
92
+ }
93
+ function parseHex(hex) {
94
+ const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
95
+ if (!m)
96
+ return null;
97
+ const n = Number.parseInt(m[1], 16);
98
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
99
+ }
100
+ function toHex(r, g, b) {
101
+ return `#${[r, g, b].map((c) => c.toString(16).padStart(2, "0")).join("")}`;
102
+ }
103
+ function collabLuma(hex) {
104
+ const rgb = parseHex(hex);
105
+ if (!rgb)
106
+ return 0.5;
107
+ const [r, g, b] = rgb;
108
+ return 0.2126 * (r / 255) + 0.7152 * (g / 255) + 0.0722 * (b / 255);
109
+ }
110
+ function collabFg(bg) {
111
+ return collabLuma(bg) > 0.62 ? "rgba(0,0,0,0.78)" : "#fff";
112
+ }
113
+ function collabInitial(name, siteId) {
114
+ const n = (name || "").trim();
115
+ if (n) {
116
+ const ch = n[0];
117
+ return /[a-z]/i.test(ch) ? ch.toUpperCase() : ch;
118
+ }
119
+ return String(_nullishCoalesce(siteId, () => ( "?")));
120
+ }
121
+
122
+ // src/collab/client.ts
123
+ function wireToSel(w) {
124
+ const toPos = (p) => ({
125
+ path: p.path.concat(p.offset)
126
+ });
127
+ return { anchor: toPos(w.anchor), head: toPos(w.head) };
128
+ }
129
+ function selToWire(sel) {
130
+ const split = (p) => {
131
+ const path = p.path;
132
+ if (path.length < 1)
133
+ return { path: [], offset: 0 };
134
+ return { path: path.slice(0, -1), offset: path[path.length - 1] };
135
+ };
136
+ return { anchor: split(sel.anchor), head: split(sel.head) };
137
+ }
138
+ function toWsUrl(url, room) {
139
+ let u = url.replace(/\/+$/, "");
140
+ if (u.startsWith("https://"))
141
+ u = `wss://${u.slice(8)}`;
142
+ else if (u.startsWith("http://"))
143
+ u = `ws://${u.slice(7)}`;
144
+ return `${u}/room/${encodeURIComponent(room)}`;
145
+ }
146
+ function retryDelay(attempt) {
147
+ const base = Math.min(1e3 * 2 ** Math.min(attempt, 5), 3e4);
148
+ const jitter = base * 0.5 * Math.random();
149
+ return base * 0.75 + jitter;
150
+ }
151
+ var CollabClient = (_class = class {
152
+
153
+
154
+ __init() {this.ws = null}
155
+ __init2() {this.closed = false}
156
+ __init3() {this.retry = 0}
157
+ __init4() {this.reconnectTimer = null}
158
+ __init5() {this.pingTimer = null}
159
+ __init6() {this.lastPong = 0}
160
+ __init7() {this.authFailed = false}
161
+ __init8() {this.siteId = 0}
162
+ __init9() {this.version = 0}
163
+ __init10() {this.clientSeq = 0}
164
+ __init11() {this.pending = []}
165
+ __init12() {this.peers = /* @__PURE__ */ new Map()}
166
+ __init13() {this.joined = false}
167
+ constructor(cfg, handlers) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);_class.prototype.__init10.call(this);_class.prototype.__init11.call(this);_class.prototype.__init12.call(this);_class.prototype.__init13.call(this);
168
+ this.cfg = cfg;
169
+ this.handlers = handlers;
170
+ this.connect();
171
+ }
172
+ get peersList() {
173
+ return [...this.peers.values()];
174
+ }
175
+ get status() {
176
+ if (this.authFailed)
177
+ return "auth-error";
178
+ if (this.closed)
179
+ return "closed";
180
+ if (!this.joined)
181
+ return _optionalChain([this, 'access', _ => _.ws, 'optionalAccess', _2 => _2.readyState]) === WebSocket.OPEN ? "connecting" : "connecting";
182
+ return "open";
183
+ }
184
+ connect() {
185
+ if (this.closed || this.authFailed)
186
+ return;
187
+ _optionalChain([this, 'access', _3 => _3.handlers, 'access', _4 => _4.onStatus, 'optionalCall', _5 => _5("connecting")]);
188
+ const url = toWsUrl(this.cfg.url, this.cfg.room);
189
+ let ws;
190
+ try {
191
+ ws = new WebSocket(url);
192
+ } catch (e) {
193
+ _optionalChain([this, 'access', _6 => _6.handlers, 'access', _7 => _7.onError, 'optionalCall', _8 => _8(e instanceof Error ? e.message : String(e))]);
194
+ this.scheduleReconnect();
195
+ return;
196
+ }
197
+ this.ws = ws;
198
+ ws.onopen = () => {
199
+ this.retry = 0;
200
+ this.lastPong = Date.now();
201
+ this.startHeartbeat();
202
+ void this.sendJoin();
203
+ };
204
+ ws.onclose = () => {
205
+ this.joined = false;
206
+ this.stopHeartbeat();
207
+ if (this.authFailed) {
208
+ _optionalChain([this, 'access', _9 => _9.handlers, 'access', _10 => _10.onStatus, 'optionalCall', _11 => _11("auth-error")]);
209
+ return;
210
+ }
211
+ _optionalChain([this, 'access', _12 => _12.handlers, 'access', _13 => _13.onStatus, 'optionalCall', _14 => _14("closed")]);
212
+ if (!this.closed)
213
+ this.scheduleReconnect();
214
+ };
215
+ ws.onerror = () => {
216
+ try {
217
+ ws.close();
218
+ } catch (e2) {
219
+ }
220
+ };
221
+ ws.onmessage = (ev) => {
222
+ try {
223
+ const msg = JSON.parse(String(ev.data));
224
+ this.onServer(msg);
225
+ } catch (e3) {
226
+ }
227
+ };
228
+ }
229
+ async sendJoin() {
230
+ let token;
231
+ try {
232
+ const t = this.cfg.token;
233
+ if (typeof t === "function")
234
+ token = await t();
235
+ else if (typeof t === "string")
236
+ token = t;
237
+ } catch (e) {
238
+ _optionalChain([this, 'access', _15 => _15.handlers, 'access', _16 => _16.onError, 'optionalCall', _17 => _17(e instanceof Error ? e.message : String(e))]);
239
+ this.authFailed = true;
240
+ _optionalChain([this, 'access', _18 => _18.handlers, 'access', _19 => _19.onStatus, 'optionalCall', _20 => _20("auth-error")]);
241
+ try {
242
+ _optionalChain([this, 'access', _21 => _21.ws, 'optionalAccess', _22 => _22.close, 'call', _23 => _23()]);
243
+ } catch (e4) {
244
+ }
245
+ return;
246
+ }
247
+ this.send({
248
+ type: "join",
249
+ room: this.cfg.room,
250
+ name: this.cfg.name,
251
+ color: this.cfg.color,
252
+ seed: this.cfg.seed,
253
+ ...token ? { token } : {}
254
+ });
255
+ }
256
+ startHeartbeat() {
257
+ this.stopHeartbeat();
258
+ this.pingTimer = setInterval(() => {
259
+ if (_optionalChain([this, 'access', _24 => _24.ws, 'optionalAccess', _25 => _25.readyState]) !== WebSocket.OPEN)
260
+ return;
261
+ if (this.lastPong && Date.now() - this.lastPong > 45e3) {
262
+ try {
263
+ this.ws.close();
264
+ } catch (e5) {
265
+ }
266
+ return;
267
+ }
268
+ this.send({ type: "ping" });
269
+ }, 2e4);
270
+ }
271
+ stopHeartbeat() {
272
+ if (this.pingTimer) {
273
+ clearInterval(this.pingTimer);
274
+ this.pingTimer = null;
275
+ }
276
+ }
277
+ scheduleReconnect() {
278
+ if (this.reconnectTimer || this.closed || this.authFailed)
279
+ return;
280
+ const delay = retryDelay(this.retry++);
281
+ this.reconnectTimer = setTimeout(() => {
282
+ this.reconnectTimer = null;
283
+ this.connect();
284
+ }, delay);
285
+ }
286
+ send(msg) {
287
+ if (_optionalChain([this, 'access', _26 => _26.ws, 'optionalAccess', _27 => _27.readyState]) === WebSocket.OPEN)
288
+ this.ws.send(JSON.stringify(msg));
289
+ }
290
+ onServer(msg) {
291
+ switch (msg.type) {
292
+ case "welcome": {
293
+ this.siteId = msg.siteId;
294
+ this.version = msg.version;
295
+ this.pending = [];
296
+ this.joined = true;
297
+ _optionalChain([this, 'access', _28 => _28.handlers, 'access', _29 => _29.onStatus, 'optionalCall', _30 => _30("open")]);
298
+ if (!this.cfg.color)
299
+ this.cfg.color = collabColor(msg.siteId);
300
+ this.peers.clear();
301
+ for (const p of msg.peers) {
302
+ this.peers.set(p.siteId, {
303
+ ...p,
304
+ color: collabColor(p.siteId, p.color)
305
+ });
306
+ }
307
+ _optionalChain([this, 'access', _31 => _31.handlers, 'access', _32 => _32.onWelcome, 'optionalCall', _33 => _33({
308
+ siteId: msg.siteId,
309
+ version: msg.version,
310
+ name: this.cfg.name,
311
+ color: this.cfg.color
312
+ })]);
313
+ this.handlers.onDoc(msg.doc, msg.version);
314
+ _optionalChain([this, 'access', _34 => _34.handlers, 'access', _35 => _35.onPeers, 'optionalCall', _36 => _36(this.peersList)]);
315
+ if (msg.versions)
316
+ _optionalChain([this, 'access', _37 => _37.handlers, 'access', _38 => _38.onVersions, 'optionalCall', _39 => _39(msg.versions)]);
317
+ break;
318
+ }
319
+ case "versions": {
320
+ _optionalChain([this, 'access', _40 => _40.handlers, 'access', _41 => _41.onVersions, 'optionalCall', _42 => _42(msg.versions)]);
321
+ break;
322
+ }
323
+ case "resync": {
324
+ this.version = msg.version;
325
+ this.pending = [];
326
+ _optionalChain([this, 'access', _43 => _43.handlers, 'access', _44 => _44.onStatus, 'optionalCall', _45 => _45("resyncing")]);
327
+ _optionalChain([this, 'access', _46 => _46.handlers, 'access', _47 => _47.onResync, 'optionalCall', _48 => _48(msg.version)]);
328
+ this.handlers.onDoc(msg.doc, msg.version);
329
+ _optionalChain([this, 'access', _49 => _49.handlers, 'access', _50 => _50.onStatus, 'optionalCall', _51 => _51("open")]);
330
+ break;
331
+ }
332
+ case "op": {
333
+ if (!this.joined)
334
+ return;
335
+ if (msg.siteId === this.siteId) {
336
+ if (msg.clientSeq != null)
337
+ this.pending = this.pending.filter((p) => p.clientSeq > msg.clientSeq);
338
+ this.version = msg.version;
339
+ return;
340
+ }
341
+ const pendingAs = this.pending.map((p) => ({ siteId: this.siteId, steps: p.steps }));
342
+ const { remote, pending: nextP } = _chunkU3JZDFL4cjs.transformRemoteAgainstPending.call(void 0,
343
+ msg.steps,
344
+ msg.siteId,
345
+ pendingAs,
346
+ this.siteId
347
+ );
348
+ this.pending = this.pending.map((p, i) => ({
349
+ ...p,
350
+ steps: _nullishCoalesce(_optionalChain([nextP, 'access', _52 => _52[i], 'optionalAccess', _53 => _53.steps]), () => ( p.steps))
351
+ }));
352
+ this.version = msg.version;
353
+ if (remote.length) {
354
+ if (!this.peers.has(msg.siteId)) {
355
+ this.peers.set(msg.siteId, {
356
+ siteId: msg.siteId,
357
+ color: collabColor(msg.siteId)
358
+ });
359
+ }
360
+ this.mapPeerSelsThrough(remote);
361
+ this.ensureAuthorCaret(msg.siteId, remote);
362
+ this.handlers.onRemote(remote, msg.siteId);
363
+ _optionalChain([this, 'access', _54 => _54.handlers, 'access', _55 => _55.onPeers, 'optionalCall', _56 => _56(this.peersList)]);
364
+ }
365
+ break;
366
+ }
367
+ case "presence": {
368
+ const cur = _nullishCoalesce(this.peers.get(msg.siteId), () => ( { siteId: msg.siteId }));
369
+ this.peers.set(msg.siteId, {
370
+ ...cur,
371
+ name: _nullishCoalesce(msg.name, () => ( cur.name)),
372
+ color: collabColor(msg.siteId, _nullishCoalesce(msg.color, () => ( cur.color))),
373
+ sel: msg.sel === void 0 ? cur.sel : msg.sel
374
+ });
375
+ _optionalChain([this, 'access', _57 => _57.handlers, 'access', _58 => _58.onPeers, 'optionalCall', _59 => _59(this.peersList)]);
376
+ break;
377
+ }
378
+ case "peer-join": {
379
+ this.peers.set(msg.siteId, {
380
+ siteId: msg.siteId,
381
+ name: msg.name,
382
+ color: collabColor(msg.siteId, msg.color)
383
+ });
384
+ _optionalChain([this, 'access', _60 => _60.handlers, 'access', _61 => _61.onPeers, 'optionalCall', _62 => _62(this.peersList)]);
385
+ break;
386
+ }
387
+ case "peer-leave": {
388
+ this.peers.delete(msg.siteId);
389
+ _optionalChain([this, 'access', _63 => _63.handlers, 'access', _64 => _64.onPeers, 'optionalCall', _65 => _65(this.peersList)]);
390
+ break;
391
+ }
392
+ case "error": {
393
+ _optionalChain([this, 'access', _66 => _66.handlers, 'access', _67 => _67.onError, 'optionalCall', _68 => _68(msg.message)]);
394
+ if (/auth|token|unauthorized/i.test(msg.message)) {
395
+ this.authFailed = true;
396
+ _optionalChain([this, 'access', _69 => _69.handlers, 'access', _70 => _70.onStatus, 'optionalCall', _71 => _71("auth-error")]);
397
+ try {
398
+ _optionalChain([this, 'access', _72 => _72.ws, 'optionalAccess', _73 => _73.close, 'call', _74 => _74()]);
399
+ } catch (e6) {
400
+ }
401
+ }
402
+ break;
403
+ }
404
+ case "pong":
405
+ this.lastPong = Date.now();
406
+ break;
407
+ }
408
+ }
409
+ /** 本地已 apply 的 steps 推上服务器 */
410
+ push(steps) {
411
+ if (!steps.length || !this.joined || this.siteId <= 0)
412
+ return;
413
+ const clientSeq = ++this.clientSeq;
414
+ const baseVersion = this.version;
415
+ this.pending.push({ clientSeq, baseVersion, steps });
416
+ this.send({ type: "op", baseVersion, clientSeq, steps });
417
+ }
418
+ /** 命名版本上行(侧信道,不进 OT) */
419
+ pushVersion(v) {
420
+ if (!this.joined || this.siteId <= 0)
421
+ return;
422
+ this.send({ type: "version-save", version: v });
423
+ }
424
+ removeVersion(id) {
425
+ if (!this.joined || this.siteId <= 0)
426
+ return;
427
+ this.send({ type: "version-remove", id });
428
+ }
429
+ /** 用一批 steps 搬所有 peer 的 wire 选区(作者打字时彩光标贴字) */
430
+ mapPeerSelsThrough(steps) {
431
+ for (const [id, p] of this.peers) {
432
+ if (!p.sel)
433
+ continue;
434
+ let sel = wireToSel(p.sel);
435
+ for (const s of steps)
436
+ sel = _chunkU3JZDFL4cjs.mapSelection.call(void 0, s, sel);
437
+ this.peers.set(id, { ...p, sel: selToWire(sel) });
438
+ }
439
+ }
440
+ /**
441
+ * 作者无历史 presence 时,从本批最后一次 insertText 推光标到插入末尾。
442
+ * 有 sel 时 mapPeerSelsThrough 已搬过,不再覆盖。
443
+ */
444
+ ensureAuthorCaret(siteId, steps) {
445
+ const p = this.peers.get(siteId);
446
+ if (!p || p.sel)
447
+ return;
448
+ for (let i = steps.length - 1; i >= 0; i--) {
449
+ const s = steps[i];
450
+ if (s.kind !== "insertText")
451
+ continue;
452
+ const offset = s.offset + s.text.length;
453
+ p.sel = {
454
+ anchor: { path: s.path.slice(), offset },
455
+ head: { path: s.path.slice(), offset }
456
+ };
457
+ this.peers.set(siteId, p);
458
+ return;
459
+ }
460
+ }
461
+ presence(sel) {
462
+ if (!this.joined)
463
+ return;
464
+ this.send({
465
+ type: "presence",
466
+ name: this.cfg.name,
467
+ color: _nullishCoalesce(this.cfg.color, () => ( collabColor(this.siteId))),
468
+ sel
469
+ });
470
+ }
471
+ close() {
472
+ this.closed = true;
473
+ this.stopHeartbeat();
474
+ if (this.reconnectTimer)
475
+ clearTimeout(this.reconnectTimer);
476
+ try {
477
+ _optionalChain([this, 'access', _75 => _75.ws, 'optionalAccess', _76 => _76.close, 'call', _77 => _77()]);
478
+ } catch (e7) {
479
+ }
480
+ this.ws = null;
481
+ }
482
+ }, _class);
483
+ function connectCollab(cfg, handlers) {
484
+ return new CollabClient(cfg, handlers);
485
+ }
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+ exports.COLLAB_COLORS = COLLAB_COLORS; exports.COLLAB_CARET_COLORS = COLLAB_CARET_COLORS; exports.collabColor = collabColor; exports.collabCaretColor = collabCaretColor; exports.solidify = solidify; exports.collabLuma = collabLuma; exports.collabFg = collabFg; exports.collabInitial = collabInitial; exports.CollabClient = CollabClient; exports.connectCollab = connectCollab;
@@ -0,0 +1,24 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/tree/types.ts
9
+ function isText(n) {
10
+ return n != null && typeof n === "object" && "text" in n;
11
+ }
12
+ function isElement(n) {
13
+ return n != null && typeof n === "object" && "children" in n;
14
+ }
15
+ function isInlineAtom(n) {
16
+ return isElement(n) && (n.type === "mention" || n.type === "hard_break" || n.type === "math");
17
+ }
18
+
19
+ export {
20
+ __require,
21
+ isText,
22
+ isElement,
23
+ isInlineAtom
24
+ };