markloom 0.5.1 → 0.7.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 (73) hide show
  1. package/PACKAGES.md +26 -0
  2. package/README.md +20 -2
  3. package/collab.md +60 -13
  4. package/dist/ai/index.cjs +5 -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 +4 -3
  8. package/dist/ai/theme.css +66 -102
  9. package/dist/{chunk-ZMTLSFLO.js → chunk-4Q7PAR2T.js} +5746 -1341
  10. package/dist/chunk-75EJ4ARB.cjs +642 -0
  11. package/dist/{chunk-JS527FDV.cjs → chunk-BMPCVT3B.cjs} +47 -39
  12. package/dist/{chunk-RLTHVQNQ.js → chunk-EFYT2223.js} +47 -39
  13. package/dist/chunk-HXABDVLZ.cjs +297 -0
  14. package/dist/{chunk-YIFOGP2D.cjs → chunk-I2LDEVLA.cjs} +499 -102
  15. package/dist/chunk-MQLRZQZL.js +642 -0
  16. package/dist/chunk-OVHASRID.cjs +4279 -0
  17. package/dist/chunk-PCSVBPOR.cjs +40 -0
  18. package/dist/{chunk-FCH7LZFI.js → chunk-PSAXWBNM.js} +450 -53
  19. package/dist/chunk-PZRWTLLB.cjs +858 -0
  20. package/dist/chunk-QO7JEZDB.js +4279 -0
  21. package/dist/chunk-WSJUXPAG.js +40 -0
  22. package/dist/{chunk-VXM7Q6P5.cjs → chunk-Y4IXQFWL.cjs} +6026 -1621
  23. package/dist/chunk-YLVSMDIO.js +858 -0
  24. package/dist/chunk-ZL6WT6OY.js +297 -0
  25. package/dist/client-BvvyHjhh.d.ts +250 -0
  26. package/dist/client-Ciy7Fa_k.d.cts +250 -0
  27. package/dist/collab/index.cjs +17 -4
  28. package/dist/collab/index.d.cts +18 -7
  29. package/dist/collab/index.d.ts +18 -7
  30. package/dist/collab/index.js +19 -6
  31. package/dist/{controller-DQITsFhy.d.cts → controller-CHznEhAR.d.cts} +277 -26
  32. package/dist/{controller-BNuuUM3E.d.ts → controller-DLqI8_jm.d.ts} +277 -26
  33. package/dist/index.cjs +119 -7
  34. package/dist/index.d.cts +138 -6
  35. package/dist/index.d.ts +138 -6
  36. package/dist/index.js +130 -18
  37. package/dist/io/index.cjs +1412 -0
  38. package/dist/io/index.d.cts +33 -0
  39. package/dist/io/index.d.ts +33 -0
  40. package/dist/io/index.js +1412 -0
  41. package/dist/react/index.cjs +9 -8
  42. package/dist/react/index.d.cts +5 -4
  43. package/dist/react/index.d.ts +5 -4
  44. package/dist/react/index.js +8 -7
  45. package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-CSnv8FKp.d.ts} +11 -9
  46. package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-DO1ygkx9.d.cts} +11 -9
  47. package/dist/types-BkHlmUFL.d.cts +34 -0
  48. package/dist/types-BkHlmUFL.d.ts +34 -0
  49. package/dist/versions-DNFf8zVz.d.cts +51 -0
  50. package/dist/versions-DOkOyh2J.d.ts +51 -0
  51. package/dist/view/index.cjs +259 -17
  52. package/dist/view/index.d.cts +277 -12
  53. package/dist/view/index.d.ts +277 -12
  54. package/dist/view/index.js +256 -14
  55. package/dist/view/theme.css +2093 -1577
  56. package/dist/word-count-BPw9G2Bg.d.ts +130 -0
  57. package/dist/word-count-DNLn1h_t.d.cts +130 -0
  58. package/io.md +38 -0
  59. package/package.json +25 -4
  60. package/dist/chunk-4JSJAHTB.js +0 -255
  61. package/dist/chunk-4TMHVNL6.cjs +0 -2297
  62. package/dist/chunk-ALZ3A5CS.cjs +0 -255
  63. package/dist/chunk-GQ2HHRGI.cjs +0 -16
  64. package/dist/chunk-LA5SBCGQ.js +0 -16
  65. package/dist/chunk-LEYAQNJA.js +0 -220
  66. package/dist/chunk-MFYF2A6U.js +0 -2297
  67. package/dist/chunk-YXQDCW4Y.cjs +0 -220
  68. package/dist/client-6KiH4kGK.d.ts +0 -144
  69. package/dist/client-ZRZj2nkq.d.cts +0 -144
  70. package/dist/comments-DlExS6f-.d.cts +0 -43
  71. package/dist/comments-PhnR7Gkn.d.ts +0 -43
  72. package/dist/step-BrvHIK7O.d.cts +0 -65
  73. package/dist/step-BrvHIK7O.d.ts +0 -65
@@ -0,0 +1,297 @@
1
+ import {
2
+ isElement,
3
+ isInlineAtom,
4
+ isText
5
+ } from "./chunk-WSJUXPAG.js";
6
+
7
+ // src/tree/addr.ts
8
+ function resolve(doc, path) {
9
+ if (path.length === 0)
10
+ return { node: doc, offset: 0, parents: [], indexInParent: [] };
11
+ const parents = [];
12
+ const indexInParent = [];
13
+ let cur = doc;
14
+ for (let i = 0; i < path.length - 1; i++) {
15
+ if (!isElement(cur))
16
+ throw new Error(`path \u8D8A\u8FC7\u6587\u672C\u53F6: ${path.join(",")} \u5728\u7B2C ${i} \u6BB5`);
17
+ parents.push(cur);
18
+ indexInParent.push(path[i]);
19
+ const child = cur.children[path[i]];
20
+ if (!child)
21
+ throw new Error(`path \u8D8A\u754C: ${path.join(",")} \u5728\u7B2C ${i} \u6BB5\u65E0 child ${path[i]}`);
22
+ cur = child;
23
+ }
24
+ const last = path[path.length - 1];
25
+ return { node: cur, offset: last, parents, indexInParent };
26
+ }
27
+ function firstLeafPath(block) {
28
+ for (let i = 0; i < block.children.length; i++) {
29
+ const c = block.children[i];
30
+ if (isInlineAtom(c))
31
+ continue;
32
+ if (isText(c))
33
+ return [i];
34
+ return [i, ...firstLeafPath(c)];
35
+ }
36
+ return [0];
37
+ }
38
+ function absorbsAfter(n) {
39
+ if (isText(n))
40
+ return false;
41
+ if (n.type === "mention")
42
+ return false;
43
+ return n.children.length === 0 || !hasTextLeaf(n);
44
+ }
45
+ function gapToTextPath(parent, at, prefix = []) {
46
+ const kids = parent.children;
47
+ if (kids.length === 0)
48
+ return prefix.concat(0);
49
+ const clampAt = Math.max(0, Math.min(at, kids.length));
50
+ const tryEnd = (idx) => {
51
+ const n = kids[idx];
52
+ if (!n || isText(n))
53
+ return n && isText(n) ? prefix.concat(idx, n.text.length) : null;
54
+ if (n.children.length === 0 || !hasTextLeaf(n))
55
+ return null;
56
+ return prefix.concat(idx, ...lastLeafEnd(n));
57
+ };
58
+ const tryStart = (idx) => {
59
+ const n = kids[idx];
60
+ if (!n || isText(n))
61
+ return n && isText(n) ? prefix.concat(idx, 0) : null;
62
+ if (n.children.length === 0 || !hasTextLeaf(n))
63
+ return null;
64
+ return prefix.concat(idx, ...firstLeafPath(n), 0);
65
+ };
66
+ let i = clampAt;
67
+ while (i < kids.length && absorbsAfter(kids[i]))
68
+ i++;
69
+ if (i !== clampAt) {
70
+ const skipped = tryStart(i);
71
+ if (skipped)
72
+ return skipped;
73
+ } else if (clampAt > 0) {
74
+ const left = tryEnd(clampAt - 1);
75
+ if (left)
76
+ return left;
77
+ const right = tryStart(clampAt);
78
+ if (right)
79
+ return right;
80
+ } else {
81
+ const right = tryStart(0);
82
+ if (right)
83
+ return right;
84
+ }
85
+ for (let j = Math.min(i, kids.length) - 1; j >= 0; j--) {
86
+ const p = tryEnd(j);
87
+ if (p)
88
+ return p;
89
+ }
90
+ for (let j = i; j < kids.length; j++) {
91
+ const p = tryStart(j);
92
+ if (p)
93
+ return p;
94
+ }
95
+ return prefix.concat(0);
96
+ }
97
+ function hasTextLeaf(n) {
98
+ for (const c of n.children) {
99
+ if (isText(c))
100
+ return true;
101
+ if (isElement(c) && !isInlineAtom(c) && hasTextLeaf(c))
102
+ return true;
103
+ }
104
+ return false;
105
+ }
106
+ function normalizeToLeaf(doc, path) {
107
+ if (path.length === 0)
108
+ return gapToTextPath(doc, 0, []);
109
+ const prefix = [];
110
+ let cur = doc;
111
+ for (let i = 0; i < path.length; i++) {
112
+ if (isText(cur)) {
113
+ return prefix.concat(Math.max(0, path[i]));
114
+ }
115
+ if (i === path.length - 1) {
116
+ if (isElement(cur) && cur.children.length === 0 && prefix.length >= 1) {
117
+ const idx = prefix[prefix.length - 1];
118
+ const parentPath = prefix.slice(0, -1);
119
+ const parent = parentPath.length ? nodeAt(doc, parentPath) : doc;
120
+ return gapToTextPath(parent, absorbsAfter(cur) ? idx + 1 : idx, parentPath);
121
+ }
122
+ return gapToTextPath(cur, path[i], prefix);
123
+ }
124
+ const child = cur.children[path[i]];
125
+ if (!child) {
126
+ if (isElement(cur) && cur.children.length === 0 && prefix.length >= 1) {
127
+ const idx = prefix[prefix.length - 1];
128
+ const parentPath = prefix.slice(0, -1);
129
+ const parent = parentPath.length ? nodeAt(doc, parentPath) : doc;
130
+ return gapToTextPath(parent, absorbsAfter(cur) ? idx + 1 : idx, parentPath);
131
+ }
132
+ return gapToTextPath(cur, path[i] ?? 0, prefix);
133
+ }
134
+ prefix.push(path[i]);
135
+ cur = child;
136
+ }
137
+ if (isText(cur))
138
+ return prefix.concat(0);
139
+ if (isInlineAtom(cur) && prefix.length >= 1) {
140
+ const parent = nodeAt(doc, prefix.slice(0, -1));
141
+ const idx = prefix[prefix.length - 1];
142
+ return gapToTextPath(parent, absorbsAfter(cur) ? idx + 1 : idx, prefix.slice(0, -1));
143
+ }
144
+ if (isElement(cur) && cur.children.length === 0 && prefix.length >= 1) {
145
+ const parent = nodeAt(doc, prefix.slice(0, -1));
146
+ const idx = prefix[prefix.length - 1];
147
+ return gapToTextPath(parent, idx + 1, prefix.slice(0, -1));
148
+ }
149
+ if (isElement(cur))
150
+ return gapToTextPath(cur, 0, prefix);
151
+ return prefix.concat(0);
152
+ }
153
+ function lastLeafEnd(block) {
154
+ for (let i = block.children.length - 1; i >= 0; i--) {
155
+ const last = block.children[i];
156
+ if (isInlineAtom(last))
157
+ continue;
158
+ if (isText(last))
159
+ return [i, last.text.length];
160
+ return [i, ...lastLeafEnd(last)];
161
+ }
162
+ return [0, 0];
163
+ }
164
+ function nodeAt(doc, path) {
165
+ let cur = doc;
166
+ for (const seg of path) {
167
+ if (!isElement(cur))
168
+ throw new Error(`nodeAt \u8D8A\u8FC7\u6587\u672C\u53F6: ${path.join(",")}`);
169
+ const child = cur.children[seg];
170
+ if (!child)
171
+ throw new Error(`nodeAt \u8D8A\u754C: ${path.join(",")} \u65E0 child ${seg}`);
172
+ cur = child;
173
+ }
174
+ return cur;
175
+ }
176
+ function replaceAt(doc, path, next) {
177
+ if (path.length === 0) {
178
+ if (isText(next))
179
+ throw new Error("\u6839\u4E0D\u80FD\u662F\u6587\u672C\u53F6");
180
+ return next;
181
+ }
182
+ return update(doc, path, 0, () => next);
183
+ }
184
+ function spliceAt(doc, path, at, remove, insert) {
185
+ return update(doc, path, 0, (node) => {
186
+ if (!isElement(node))
187
+ throw new Error("spliceAt \u76EE\u6807\u4E0D\u662F\u5143\u7D20");
188
+ const children = node.children.slice();
189
+ children.splice(at, remove, ...insert);
190
+ return { ...node, children };
191
+ });
192
+ }
193
+ function update(node, path, depth, fn) {
194
+ if (depth === path.length) {
195
+ const r = fn(node);
196
+ if (isText(r))
197
+ throw new Error("update \u4E0D\u80FD\u628A\u5143\u7D20\u6362\u6210\u6587\u672C\u53F6");
198
+ return r;
199
+ }
200
+ if (!isElement(node))
201
+ throw new Error(`update \u8D8A\u8FC7\u6587\u672C\u53F6: ${path.join(",")}`);
202
+ const idx = path[depth];
203
+ const children = node.children.slice();
204
+ children[idx] = updateChild(children[idx], path, depth + 1, fn);
205
+ return { ...node, children };
206
+ }
207
+ function updateChild(node, path, depth, fn) {
208
+ if (depth === path.length)
209
+ return fn(node);
210
+ if (!isElement(node))
211
+ throw new Error(`update \u8D8A\u8FC7\u6587\u672C\u53F6: ${path.join(",")}`);
212
+ const idx = path[depth];
213
+ const children = node.children.slice();
214
+ children[idx] = updateChild(children[idx], path, depth + 1, fn);
215
+ return { ...node, children };
216
+ }
217
+
218
+ // src/tree/step.ts
219
+ function apply(doc, step) {
220
+ switch (step.kind) {
221
+ case "insertText": {
222
+ const leaf = nodeAt(doc, step.path);
223
+ if (!isText(leaf))
224
+ throw new Error("insertText \u76EE\u6807\u4E0D\u662F\u6587\u672C\u53F6");
225
+ const text = leaf.text.slice(0, step.offset) + step.text + leaf.text.slice(step.offset);
226
+ return replaceAt(doc, step.path, { ...leaf, text });
227
+ }
228
+ case "deleteText": {
229
+ const leaf = nodeAt(doc, step.path);
230
+ if (!isText(leaf))
231
+ throw new Error("deleteText \u76EE\u6807\u4E0D\u662F\u6587\u672C\u53F6");
232
+ const text = leaf.text.slice(0, step.offset) + leaf.text.slice(step.offset + step.length);
233
+ return replaceAt(doc, step.path, { ...leaf, text });
234
+ }
235
+ case "replaceNode":
236
+ return replaceAt(doc, step.path, step.node);
237
+ case "spliceChildren":
238
+ return spliceAt(doc, step.path, step.at, step.remove, step.insert);
239
+ }
240
+ }
241
+ function invert(doc, step) {
242
+ switch (step.kind) {
243
+ case "insertText":
244
+ return { kind: "deleteText", path: step.path, offset: step.offset, length: step.text.length };
245
+ case "deleteText": {
246
+ const leaf = nodeAt(doc, step.path);
247
+ const removed = leaf.text.slice(step.offset, step.offset + step.length);
248
+ const marks = leaf.marks;
249
+ return { kind: "insertText", path: step.path, offset: step.offset, text: removed, marks };
250
+ }
251
+ case "replaceNode":
252
+ return { kind: "replaceNode", path: step.path, node: nodeAt(doc, step.path) };
253
+ case "spliceChildren": {
254
+ const parent = nodeAt(doc, step.path);
255
+ const removed = parent.children.slice(step.at, step.at + step.remove);
256
+ return { kind: "spliceChildren", path: step.path, at: step.at, remove: step.insert.length, insert: removed };
257
+ }
258
+ }
259
+ }
260
+ function applyAll(doc, steps) {
261
+ return steps.reduce(apply, doc);
262
+ }
263
+ function moveBlock(doc, fromIdx, toGap) {
264
+ if (toGap === fromIdx || toGap === fromIdx + 1)
265
+ return [];
266
+ const block = doc.children[fromIdx];
267
+ const insertAt = toGap > fromIdx ? toGap - 1 : toGap;
268
+ return [
269
+ { kind: "spliceChildren", path: [], at: fromIdx, remove: 1, insert: [] },
270
+ { kind: "spliceChildren", path: [], at: insertAt, remove: 0, insert: [block] }
271
+ ];
272
+ }
273
+ function invertAll(doc, steps) {
274
+ const inverses = [];
275
+ let cur = doc;
276
+ for (const step of steps) {
277
+ inverses.push(invert(cur, step));
278
+ cur = apply(cur, step);
279
+ }
280
+ return inverses.reverse();
281
+ }
282
+
283
+ export {
284
+ resolve,
285
+ firstLeafPath,
286
+ gapToTextPath,
287
+ normalizeToLeaf,
288
+ lastLeafEnd,
289
+ nodeAt,
290
+ replaceAt,
291
+ spliceAt,
292
+ apply,
293
+ invert,
294
+ applyAll,
295
+ moveBlock,
296
+ invertAll
297
+ };
@@ -0,0 +1,250 @@
1
+ import { P as Path, E as ElementNode } from './types-BkHlmUFL.js';
2
+ import { S as Step, a as DocVersion } from './versions-DOkOyh2J.js';
3
+
4
+ /** 光标/选区在协议里的轻量形态(path + offset,无 assoc) */
5
+ type WireSel = {
6
+ anchor: {
7
+ path: Path;
8
+ offset: number;
9
+ };
10
+ head: {
11
+ path: Path;
12
+ offset: number;
13
+ };
14
+ };
15
+ type PeerInfo = {
16
+ siteId: number;
17
+ name?: string;
18
+ color?: string;
19
+ sel?: WireSel | null;
20
+ };
21
+ type ClientJoin = {
22
+ type: 'join';
23
+ room: string;
24
+ clientId: string;
25
+ /** 本地副本已确认到的服务端版本;新副本不传,接收完整快照。 */
26
+ version?: number;
27
+ name?: string;
28
+ color?: string;
29
+ /** 空房时用客户端 doc 初始化 */
30
+ seed?: ElementNode;
31
+ /** 可选鉴权(worker COLLAB_TOKEN 启用时必填) */
32
+ token?: string;
33
+ };
34
+ type ClientOp = {
35
+ type: 'op';
36
+ clientId: string;
37
+ baseVersion: number;
38
+ clientSeq: number;
39
+ steps: Step[];
40
+ };
41
+ type ClientPresence = {
42
+ type: 'presence';
43
+ name?: string;
44
+ color?: string;
45
+ sel?: WireSel | null;
46
+ };
47
+ type ClientPing = {
48
+ type: 'ping';
49
+ };
50
+ /** 命名版本侧信道(不进 OT doc version) */
51
+ type ClientVersionSave = {
52
+ type: 'version-save';
53
+ version: DocVersion;
54
+ };
55
+ type ClientVersionRemove = {
56
+ type: 'version-remove';
57
+ id: string;
58
+ };
59
+ type ClientMsg = ClientJoin | ClientOp | ClientPresence | ClientPing | ClientVersionSave | ClientVersionRemove;
60
+ type ServerWelcome = {
61
+ type: 'welcome';
62
+ siteId: number;
63
+ version: number;
64
+ ackedSeq: number;
65
+ seeded: boolean;
66
+ doc: ElementNode;
67
+ /** 已有本地副本只取 version 之后的完整增量,避免快照覆盖离线写。 */
68
+ ops: ServerOp[];
69
+ peers: PeerInfo[];
70
+ /** 房间内命名版本快照列表 */
71
+ versions?: DocVersion[];
72
+ };
73
+ type ServerOp = {
74
+ type: 'op';
75
+ version: number;
76
+ siteId: number;
77
+ clientId: string;
78
+ clientSeq: number;
79
+ steps: Step[];
80
+ };
81
+ type ServerPresence = {
82
+ type: 'presence';
83
+ siteId: number;
84
+ name?: string;
85
+ color?: string;
86
+ sel?: WireSel | null;
87
+ };
88
+ type ServerPeerJoin = {
89
+ type: 'peer-join';
90
+ siteId: number;
91
+ name?: string;
92
+ color?: string;
93
+ };
94
+ type ServerPeerLeave = {
95
+ type: 'peer-leave';
96
+ siteId: number;
97
+ };
98
+ type ServerResync = {
99
+ type: 'resync';
100
+ version: number;
101
+ doc: ElementNode;
102
+ };
103
+ type ServerErrorCode = 'invalid-message' | 'unauthorized' | 'invalid-version' | 'not-joined' | 'identity-mismatch' | 'operation-rejected';
104
+ type ServerError = {
105
+ type: 'error';
106
+ code: ServerErrorCode;
107
+ message: string;
108
+ };
109
+ type ServerPong = {
110
+ type: 'pong';
111
+ };
112
+ /** 全量版本列表(save/remove 后广播;welcome 亦可带) */
113
+ type ServerVersions = {
114
+ type: 'versions';
115
+ versions: DocVersion[];
116
+ };
117
+ type ServerMsg = ServerWelcome | ServerOp | ServerPresence | ServerPeerJoin | ServerPeerLeave | ServerResync | ServerError | ServerPong | ServerVersions;
118
+
119
+ type CollabStatus = 'connecting' | 'open' | 'closed' | 'resyncing' | 'conflict' | 'auth-error';
120
+ type CollabConflict = {
121
+ reason: 'remote-bootstrap-required' | 'local-diverged' | 'resync-with-pending';
122
+ remote: {
123
+ doc: ElementNode;
124
+ version: number;
125
+ };
126
+ };
127
+ type CollabReplica = {
128
+ clientId: string;
129
+ version: number;
130
+ clientSeq: number;
131
+ synced: boolean;
132
+ pending: {
133
+ clientSeq: number;
134
+ steps: Step[];
135
+ }[];
136
+ };
137
+ type CollabConfig = {
138
+ /** ws(s)://host 或 http(s)://host(自动改 scheme) */
139
+ url: string;
140
+ room: string;
141
+ name?: string;
142
+ color?: string;
143
+ /** 空房初始化文档;默认由 Editor 传入当前 doc */
144
+ seed?: ElementNode;
145
+ /** 与本地文档一同持久化;恢复后可安全重放未确认操作。 */
146
+ replica?: CollabReplica;
147
+ onReplica?: (replica: CollabReplica) => void;
148
+ /** 显式把已有远端房间导入一个全新本地副本;默认永不以远端覆盖本地。 */
149
+ bootstrap?: 'remote';
150
+ /**
151
+ * 鉴权钩:静态 token 或每次 join 取一次(可 async)。
152
+ * worker 设 COLLAB_TOKEN 时服务端校验;未设则忽略。
153
+ */
154
+ token?: string | (() => string | Promise<string>);
155
+ /**
156
+ * 头像条挂载点(应用壳顶栏,类似日期条)。
157
+ * 不传则插在 editor root 内 sticky 顶(lab 默认)。
158
+ */
159
+ railParent?: () => HTMLElement | null;
160
+ /** 连接状态(connecting/open/closed/resyncing/conflict/auth-error) */
161
+ onStatus?: (s: CollabStatus) => void;
162
+ /** 服务端强制 resync(版本落后 / rebase 失败) */
163
+ onResync?: (version: number) => void;
164
+ onConflict?: (conflict: CollabConflict) => void;
165
+ onError?: (message: string) => void;
166
+ };
167
+ type CollabHandlers = {
168
+ /** 新副本快照 / 无 pending 的安全 resync */
169
+ onDoc: (doc: ElementNode, version: number) => void;
170
+ /** 已变换的远端 steps + 作者 siteId,应 applyRemote(不入本端 undo 栈) */
171
+ onRemote: (steps: Step[], siteId: number) => void;
172
+ /** 进房成功(分配 siteId,可画本人头像) */
173
+ onWelcome?: (info: {
174
+ siteId: number;
175
+ version: number;
176
+ name?: string;
177
+ color?: string;
178
+ }) => void;
179
+ onPeers?: (peers: PeerInfo[]) => void;
180
+ onStatus?: (s: CollabStatus) => void;
181
+ /** 即将应用权威快照(resync 路径) */
182
+ onResync?: (version: number) => void;
183
+ onConflict?: (conflict: CollabConflict) => void;
184
+ /** 房间命名版本列表(welcome / 远端 save·remove) */
185
+ onVersions?: (versions: DocVersion[]) => void;
186
+ onError?: (message: string) => void;
187
+ };
188
+ /**
189
+ * 协作会话:WS + pending OT。
190
+ * Editor 调 push(localSteps);远端经 onRemote / onDoc。
191
+ */
192
+ declare class CollabClient {
193
+ private cfg;
194
+ private handlers;
195
+ private ws;
196
+ private closed;
197
+ private retry;
198
+ private reconnectTimer;
199
+ private pingTimer;
200
+ private lastPong;
201
+ private authFailed;
202
+ private currentStatus;
203
+ private notifiedStatus;
204
+ private synced;
205
+ private conflictValue;
206
+ private conflictAckedSeq;
207
+ private conflictWelcome;
208
+ siteId: number;
209
+ readonly clientId: string;
210
+ version: number;
211
+ private clientSeq;
212
+ private pending;
213
+ private peers;
214
+ private joined;
215
+ constructor(cfg: CollabConfig, handlers: CollabHandlers);
216
+ get peersList(): PeerInfo[];
217
+ get status(): CollabStatus;
218
+ get conflict(): CollabConflict | null;
219
+ private setStatus;
220
+ get replica(): CollabReplica;
221
+ private publishReplica;
222
+ private enterConflict;
223
+ private connect;
224
+ private sendJoin;
225
+ private startHeartbeat;
226
+ private stopHeartbeat;
227
+ private scheduleReconnect;
228
+ private send;
229
+ private onServer;
230
+ /** 本地已 apply 的 steps 推上服务器 */
231
+ push(steps: Step[]): void;
232
+ private flushPending;
233
+ private applyServerOp;
234
+ /** 命名版本上行(侧信道,不进 OT) */
235
+ pushVersion(v: DocVersion): void;
236
+ removeVersion(id: string): void;
237
+ acceptRemote(): boolean;
238
+ /** 用一批 steps 搬所有 peer 的 wire 选区(作者打字时彩光标贴字) */
239
+ private mapPeerSelsThrough;
240
+ /**
241
+ * 作者无历史 presence 时,从本批最后一次 insertText 推光标到插入末尾。
242
+ * 有 sel 时 mapPeerSelsThrough 已搬过,不再覆盖。
243
+ */
244
+ private ensureAuthorCaret;
245
+ presence(sel: WireSel | null): void;
246
+ close(): void;
247
+ }
248
+ declare function connectCollab(cfg: CollabConfig, handlers: CollabHandlers): CollabClient;
249
+
250
+ export { type ClientJoin as C, type PeerInfo as P, type ServerError as S, type WireSel as W, type ClientMsg as a, type ClientOp as b, CollabClient as c, type CollabConfig as d, type CollabConflict as e, type CollabHandlers as f, type CollabReplica as g, type CollabStatus as h, type ServerErrorCode as i, type ServerMsg as j, type ServerOp as k, type ServerWelcome as l, connectCollab as m };