markloom 0.3.0 → 0.5.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 (52) hide show
  1. package/README.md +29 -16
  2. package/ai.md +160 -0
  3. package/collab.md +68 -0
  4. package/dist/ai/index.cjs +4 -3
  5. package/dist/ai/index.d.cts +4 -2
  6. package/dist/ai/index.d.ts +4 -2
  7. package/dist/ai/index.js +5 -4
  8. package/dist/ai/theme.css +63 -63
  9. package/dist/{chunk-VVFIQLVR.cjs → chunk-4TMHVNL6.cjs} +71 -79
  10. package/dist/chunk-6DCI7AL3.js +208 -0
  11. package/dist/chunk-AC5E42NH.cjs +208 -0
  12. package/dist/chunk-GQ2HHRGI.cjs +16 -0
  13. package/dist/{chunk-GUPMZI6Q.js → chunk-JMOJU5EU.js} +7 -5
  14. package/dist/chunk-JS527FDV.cjs +294 -0
  15. package/dist/chunk-LA5SBCGQ.js +16 -0
  16. package/dist/{chunk-ITVAR2UM.js → chunk-LEYAQNJA.js} +5 -3
  17. package/dist/{chunk-J3QWW6CN.js → chunk-MFYF2A6U.js} +5 -13
  18. package/dist/chunk-RLTHVQNQ.js +294 -0
  19. package/dist/{chunk-7Q6AXLF2.cjs → chunk-SLRD6FMP.cjs} +30 -28
  20. package/dist/{chunk-UCNEQGMY.js → chunk-WUHTCCAE.js} +391 -332
  21. package/dist/{chunk-2X6AF7XH.cjs → chunk-YJAWPRJW.cjs} +722 -663
  22. package/dist/{chunk-HA6XHJUD.cjs → chunk-YXQDCW4Y.cjs} +22 -20
  23. package/dist/client-A0ZQJnyR.d.ts +137 -0
  24. package/dist/client-BNams4wv.d.cts +137 -0
  25. package/dist/collab/index.cjs +19 -0
  26. package/dist/collab/index.d.cts +3 -0
  27. package/dist/collab/index.d.ts +3 -0
  28. package/dist/collab/index.js +19 -0
  29. package/dist/comments-DlExS6f-.d.cts +43 -0
  30. package/dist/comments-PhnR7Gkn.d.ts +43 -0
  31. package/dist/{controller-Dm4uLD3I.d.ts → controller-BkY1VPzc.d.ts} +24 -8
  32. package/dist/{controller-cE9iEYp3.d.cts → controller-CVIZI--A.d.cts} +24 -8
  33. package/dist/index.cjs +21 -243
  34. package/dist/index.d.cts +5 -7
  35. package/dist/index.d.ts +5 -7
  36. package/dist/index.js +22 -244
  37. package/dist/react/index.cjs +12 -9
  38. package/dist/react/index.d.cts +7 -5
  39. package/dist/react/index.d.ts +7 -5
  40. package/dist/react/index.js +12 -9
  41. package/dist/rebase-batch-8rL_aXEE.d.ts +38 -0
  42. package/dist/rebase-batch-bYnBJpRO.d.cts +38 -0
  43. package/dist/step-BrvHIK7O.d.cts +65 -0
  44. package/dist/step-BrvHIK7O.d.ts +65 -0
  45. package/dist/view/index.cjs +11 -8
  46. package/dist/view/index.d.cts +7 -5
  47. package/dist/view/index.d.ts +7 -5
  48. package/dist/view/index.js +9 -6
  49. package/dist/view/theme.css +507 -507
  50. package/package.json +10 -3
  51. package/dist/comments-USjT1wYN.d.cts +0 -105
  52. package/dist/comments-USjT1wYN.d.ts +0 -105
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  redo,
10
10
  stripCommentMarks,
11
11
  undo
12
- } from "./chunk-ITVAR2UM.js";
12
+ } from "./chunk-LEYAQNJA.js";
13
13
  import {
14
14
  appendText,
15
15
  apply,
@@ -40,10 +40,7 @@ import {
40
40
  insertRow,
41
41
  invert,
42
42
  invertAll,
43
- isElement,
44
- isInlineAtom,
45
43
  isRichHtmlBlocks,
46
- isText,
47
44
  lastLeafEnd,
48
45
  makeTable,
49
46
  mdToDoc,
@@ -73,246 +70,23 @@ import {
73
70
  tableToHtml,
74
71
  validate,
75
72
  validateAll
76
- } from "./chunk-J3QWW6CN.js";
77
-
78
- // src/tree/map.ts
79
- function mapPosition(step, pos) {
80
- const p = pos.path;
81
- switch (step.kind) {
82
- case "insertText":
83
- return mapText(step.path, step.offset, step.text.length, p, pos);
84
- case "deleteText":
85
- return mapText(step.path, step.offset, -step.length, p, pos);
86
- case "spliceChildren":
87
- return mapSplice(step.path, step.at, step.remove, step.insert.length, p, pos);
88
- case "replaceNode":
89
- return underPrefix(step.path, p) ? withPath(step.path.concat(0), pos) : pos;
90
- }
91
- }
92
- function mapSelection(step, sel) {
93
- return { anchor: mapPosition(step, sel.anchor), head: mapPosition(step, sel.head) };
94
- }
95
- function mapText(stepPath, at, delta, p, pos) {
96
- if (p.length !== stepPath.length + 1 || !isPrefix(stepPath, p))
97
- return pos;
98
- const off = p[p.length - 1];
99
- if (off < at)
100
- return pos;
101
- if (off === at) {
102
- if (delta > 0 && (pos.assoc ?? 1) === 1)
103
- return withLast(p, off + delta, pos);
104
- return pos;
105
- }
106
- if (delta < 0 && off < at - delta)
107
- return withLast(p, at, pos);
108
- return withLast(p, off + delta, pos);
109
- }
110
- function mapSplice(parentPath, at, remove, insertCount, p, pos) {
111
- const d = parentPath.length;
112
- if (!isPrefix(parentPath, p) || p.length <= d)
113
- return pos;
114
- const idx = p[d];
115
- const delta = insertCount - remove;
116
- if (idx < at)
117
- return pos;
118
- if (idx < at + remove)
119
- return withPath(parentPath.concat(at), pos);
120
- if (idx === at) {
121
- if (insertCount > 0 && (pos.assoc ?? 1) === 1)
122
- return withSeg(p, d, idx + insertCount, pos);
123
- return pos;
124
- }
125
- return withSeg(p, d, idx + delta, pos);
126
- }
127
- function withPath(path, src) {
128
- return src.assoc === void 0 ? { path } : { path, assoc: src.assoc };
129
- }
130
- function withLast(path, last, src) {
131
- return withPath(path.slice(0, -1).concat(last), src);
132
- }
133
- function withSeg(path, d, seg, src) {
134
- const next = path.slice();
135
- next[d] = seg;
136
- return withPath(next, src);
137
- }
138
- function isPrefix(a, b) {
139
- if (a.length > b.length)
140
- return false;
141
- for (let i = 0; i < a.length; i++) {
142
- if (a[i] !== b[i])
143
- return false;
144
- }
145
- return true;
146
- }
147
- function underPrefix(a, b) {
148
- return b.length > a.length && isPrefix(a, b);
149
- }
150
- function normalizePosition(doc, pos) {
151
- let cur = doc;
152
- for (let i = 0; i < pos.path.length - 1; i++) {
153
- if (!isElement(cur))
154
- break;
155
- const next = cur.children[pos.path[i]];
156
- if (!next)
157
- return pos;
158
- cur = next;
159
- }
160
- if (isText(cur))
161
- return pos;
162
- const at = pos.path[pos.path.length - 1] ?? 0;
163
- const prefix = pos.path.slice(0, -1);
164
- return withPath(descendToText(cur, at, prefix), pos);
165
- }
166
- function descendToText(parent, at, prefix) {
167
- const kids = parent.children;
168
- if (kids.length === 0)
169
- return prefix.concat(0);
170
- const leftIdx = at > 0 ? at - 1 : 0;
171
- const toEnd = at > 0;
172
- let path = prefix.concat(leftIdx);
173
- let node = kids[Math.min(leftIdx, kids.length - 1)];
174
- while (isElement(node)) {
175
- const cs = node.children;
176
- if (cs.length === 0)
177
- return path.concat(0);
178
- const idx = toEnd ? cs.length - 1 : 0;
179
- path = path.concat(idx);
180
- node = cs[idx];
181
- }
182
- return path.concat(toEnd ? node.text.length : 0);
183
- }
184
-
185
- // src/tree/rebase.ts
186
- function makeBias(thisSite, overSite) {
187
- return thisSite > overSite ? 1 : -1;
188
- }
189
- function rebase(over, step, bias) {
190
- switch (step.kind) {
191
- case "insertText":
192
- case "deleteText": {
193
- if ((over.kind === "insertText" || over.kind === "deleteText") && samePath(over.path, step.path))
194
- return textVsText(over, step, bias);
195
- const want = step.path.length + 1;
196
- const mlo = movePoint(over, step.path.concat(step.offset), bias);
197
- if (mlo.length < want)
198
- return null;
199
- if (step.kind === "insertText")
200
- return { ...step, path: mlo.slice(0, -1), offset: mlo[mlo.length - 1] };
201
- const mhi = movePoint(over, step.path.concat(step.offset + step.length), bias);
202
- if (mhi.length < want)
203
- return null;
204
- const a = mlo[mlo.length - 1];
205
- const b = mhi[mhi.length - 1];
206
- return { ...step, path: mlo.slice(0, -1), offset: a, length: Math.max(0, b - a) };
207
- }
208
- case "spliceChildren": {
209
- if (over.kind === "spliceChildren" && samePath(over.path, step.path))
210
- return spliceVsSplice(over, step, bias);
211
- const want = step.path.length + 1;
212
- const moved = movePoint(over, step.path.concat(step.at), bias);
213
- if (moved.length < want)
214
- return null;
215
- return { ...step, path: moved.slice(0, -1), at: moved[moved.length - 1] };
216
- }
217
- case "replaceNode": {
218
- if (removesTarget(over, step.path, bias))
219
- return null;
220
- return { ...step, path: movePoint(over, step.path, 1) };
221
- }
222
- }
223
- }
224
- function removesTarget(over, targetPath, bias) {
225
- if (over.kind === "spliceChildren") {
226
- const d = over.path.length;
227
- if (targetPath.length <= d || !isPrefix2(over.path, targetPath))
228
- return false;
229
- const idx = targetPath[d];
230
- return idx >= over.at && idx < over.at + over.remove;
231
- }
232
- if (over.kind === "replaceNode") {
233
- if (isPrefix2(over.path, targetPath)) {
234
- const sameNode = targetPath.length === over.path.length;
235
- return sameNode ? bias === 1 : true;
236
- }
237
- return false;
238
- }
239
- return false;
240
- }
241
- function textVsText(over, step, bias) {
242
- if (over.kind === "insertText") {
243
- const o = over.offset;
244
- const ins = over.text.length;
245
- if (step.kind === "insertText") {
246
- const x = step.offset;
247
- const off = x < o ? x : x > o ? x + ins : bias === 1 ? x + ins : x;
248
- return { ...step, offset: off };
249
- }
250
- const s2 = step.offset;
251
- const e2 = step.offset + step.length;
252
- if (o <= s2)
253
- return { ...step, offset: s2 + ins, length: step.length };
254
- if (o >= e2)
255
- return { ...step, offset: s2, length: step.length };
256
- return { ...step, offset: s2, length: step.length + ins };
257
- }
258
- const d = over.offset;
259
- const oLen = over.length;
260
- if (step.kind === "insertText") {
261
- const x = step.offset;
262
- if (x > d && x < d + oLen)
263
- return null;
264
- return { ...step, offset: x <= d ? x : x - oLen };
265
- }
266
- const s0 = step.offset;
267
- const e0 = step.offset + step.length;
268
- const s = s0 <= d ? s0 : s0 >= d + oLen ? s0 - oLen : d;
269
- const e = e0 <= d ? e0 : e0 >= d + oLen ? e0 - oLen : d;
270
- const len = Math.max(0, e - s);
271
- if (len === 0)
272
- return null;
273
- return { ...step, offset: s, length: len };
274
- }
275
- function spliceVsSplice(over, step, bias) {
276
- const oa = over.at;
277
- const oe = over.at + over.remove;
278
- const oN = over.insert.length;
279
- const delta = oN - over.remove;
280
- const sa = step.at;
281
- const se = step.at + step.remove;
282
- const out = [];
283
- const leftRem = Math.max(0, Math.min(se, oa) - sa);
284
- const rightRem = Math.max(0, se - Math.max(sa, oe));
285
- if (rightRem > 0)
286
- out.push({ kind: "spliceChildren", path: step.path, at: Math.max(sa, oe) + delta, remove: rightRem, insert: [] });
287
- if (leftRem > 0)
288
- out.push({ kind: "spliceChildren", path: step.path, at: sa, remove: leftRem, insert: [] });
289
- if (step.insert.length > 0) {
290
- const insAt = sa === oa ? bias === 1 ? oa + oN : oa : sa < oa ? sa : sa >= oe ? sa + delta : oa + oN;
291
- out.push({ kind: "spliceChildren", path: step.path, at: insAt, remove: 0, insert: step.insert });
292
- }
293
- if (out.length === 0)
294
- return null;
295
- if (out.length === 1)
296
- return out[0];
297
- out.sort((x, y) => y.at - x.at || x.insert.length - y.insert.length);
298
- return out;
299
- }
300
- function samePath(a, b) {
301
- return a.length === b.length && a.every((x, i) => x === b[i]);
302
- }
303
- function isPrefix2(a, b) {
304
- if (a.length > b.length)
305
- return false;
306
- for (let i = 0; i < a.length; i++) {
307
- if (a[i] !== b[i])
308
- return false;
309
- }
310
- return true;
311
- }
312
- function movePoint(over, path, bias) {
313
- const pos = { path, assoc: bias };
314
- return mapPosition(over, pos).path;
315
- }
73
+ } from "./chunk-MFYF2A6U.js";
74
+ import {
75
+ makeBias,
76
+ mapPosition,
77
+ mapSelection,
78
+ normalizePosition,
79
+ rebase,
80
+ rebaseBatchOver,
81
+ rebaseOne,
82
+ rebaseStepsThrough,
83
+ transformRemoteAgainstPending
84
+ } from "./chunk-RLTHVQNQ.js";
85
+ import {
86
+ isElement,
87
+ isInlineAtom,
88
+ isText
89
+ } from "./chunk-LA5SBCGQ.js";
316
90
 
317
91
  // src/tree/stats.ts
318
92
  function rawText(node) {
@@ -400,6 +174,9 @@ export {
400
174
  outline,
401
175
  pathOfId,
402
176
  rebase,
177
+ rebaseBatchOver,
178
+ rebaseOne,
179
+ rebaseStepsThrough,
403
180
  redo,
404
181
  replaceAt,
405
182
  resolve,
@@ -418,6 +195,7 @@ export {
418
195
  tableSchema,
419
196
  tableShape,
420
197
  tableToHtml,
198
+ transformRemoteAgainstPending,
421
199
  undo,
422
200
  validate,
423
201
  validateAll
@@ -1,13 +1,16 @@
1
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; }
2
2
 
3
- var _chunk2X6AF7XHcjs = require('../chunk-2X6AF7XH.cjs');
4
- require('../chunk-HA6XHJUD.cjs');
5
- require('../chunk-7Q6AXLF2.cjs');
6
- require('../chunk-VVFIQLVR.cjs');
3
+ var _chunkYJAWPRJWcjs = require('../chunk-YJAWPRJW.cjs');
4
+ require('../chunk-YXQDCW4Y.cjs');
5
+ require('../chunk-SLRD6FMP.cjs');
6
+ require('../chunk-4TMHVNL6.cjs');
7
+ require('../chunk-AC5E42NH.cjs');
8
+ require('../chunk-JS527FDV.cjs');
9
+ require('../chunk-GQ2HHRGI.cjs');
7
10
 
8
11
  // src/react/index.ts
9
12
  var _react = require('react');
10
- function useLoom(initialDoc, opts = {}) {
13
+ function useMarkloom(initialDoc, opts = {}) {
11
14
  const ref = _react.useRef.call(void 0, null);
12
15
  const editorRef = _react.useRef.call(void 0, null);
13
16
  const [doc, setDoc] = _react.useState.call(void 0, initialDoc);
@@ -17,7 +20,7 @@ function useLoom(initialDoc, opts = {}) {
17
20
  const host = ref.current;
18
21
  if (!host)
19
22
  return;
20
- const ed = new (0, _chunk2X6AF7XHcjs.Editor)(host, initialDoc, {
23
+ const ed = new (0, _chunkYJAWPRJWcjs.Editor)(host, initialDoc, {
21
24
  ...optsRef.current,
22
25
  onChange: (d) => {
23
26
  setDoc(d);
@@ -35,11 +38,11 @@ function useLoom(initialDoc, opts = {}) {
35
38
  }, [opts.editable]);
36
39
  return { ref, editor: editorRef, doc };
37
40
  }
38
- function Loom({ doc, className, style, ...opts }) {
39
- const { ref } = useLoom(doc, opts);
41
+ function Markloom({ doc, className, style, ...opts }) {
42
+ const { ref } = useMarkloom(doc, opts);
40
43
  return _react.createElement.call(void 0, "div", { ref, className, style });
41
44
  }
42
45
 
43
46
 
44
47
 
45
- exports.Loom = Loom; exports.useLoom = useLoom;
48
+ exports.Markloom = Markloom; exports.useMarkloom = useMarkloom;
@@ -1,15 +1,17 @@
1
1
  import * as react from 'react';
2
2
  import { MutableRefObject } from 'react';
3
- import { E as ElementNode } from '../comments-USjT1wYN.cjs';
4
- import { E as EditorOptions, k as Editor } from '../controller-cE9iEYp3.cjs';
3
+ import { E as ElementNode } from '../step-BrvHIK7O.cjs';
4
+ import { E as EditorOptions, k as Editor } from '../controller-CVIZI--A.cjs';
5
5
  import 'preact';
6
+ import '../comments-DlExS6f-.cjs';
7
+ import '../client-BNams4wv.cjs';
6
8
 
7
- declare function useLoom(initialDoc: ElementNode, opts?: EditorOptions): {
9
+ declare function useMarkloom(initialDoc: ElementNode, opts?: EditorOptions): {
8
10
  ref: react.RefObject<HTMLDivElement | null>;
9
11
  editor: MutableRefObject<Editor | null>;
10
12
  doc: ElementNode;
11
13
  };
12
- declare function Loom({ doc, className, style, ...opts }: EditorOptions & {
14
+ declare function Markloom({ doc, className, style, ...opts }: EditorOptions & {
13
15
  doc: ElementNode;
14
16
  className?: string;
15
17
  style?: React.CSSProperties;
@@ -19,4 +21,4 @@ declare function Loom({ doc, className, style, ...opts }: EditorOptions & {
19
21
  style: react.CSSProperties | undefined;
20
22
  }, HTMLDivElement>;
21
23
 
22
- export { Loom, useLoom };
24
+ export { Markloom, useMarkloom };
@@ -1,15 +1,17 @@
1
1
  import * as react from 'react';
2
2
  import { MutableRefObject } from 'react';
3
- import { E as ElementNode } from '../comments-USjT1wYN.js';
4
- import { E as EditorOptions, k as Editor } from '../controller-Dm4uLD3I.js';
3
+ import { E as ElementNode } from '../step-BrvHIK7O.js';
4
+ import { E as EditorOptions, k as Editor } from '../controller-BkY1VPzc.js';
5
5
  import 'preact';
6
+ import '../comments-PhnR7Gkn.js';
7
+ import '../client-A0ZQJnyR.js';
6
8
 
7
- declare function useLoom(initialDoc: ElementNode, opts?: EditorOptions): {
9
+ declare function useMarkloom(initialDoc: ElementNode, opts?: EditorOptions): {
8
10
  ref: react.RefObject<HTMLDivElement | null>;
9
11
  editor: MutableRefObject<Editor | null>;
10
12
  doc: ElementNode;
11
13
  };
12
- declare function Loom({ doc, className, style, ...opts }: EditorOptions & {
14
+ declare function Markloom({ doc, className, style, ...opts }: EditorOptions & {
13
15
  doc: ElementNode;
14
16
  className?: string;
15
17
  style?: React.CSSProperties;
@@ -19,4 +21,4 @@ declare function Loom({ doc, className, style, ...opts }: EditorOptions & {
19
21
  style: react.CSSProperties | undefined;
20
22
  }, HTMLDivElement>;
21
23
 
22
- export { Loom, useLoom };
24
+ export { Markloom, useMarkloom };
@@ -1,13 +1,16 @@
1
1
  import {
2
2
  Editor
3
- } from "../chunk-UCNEQGMY.js";
4
- import "../chunk-ITVAR2UM.js";
5
- import "../chunk-GUPMZI6Q.js";
6
- import "../chunk-J3QWW6CN.js";
3
+ } from "../chunk-WUHTCCAE.js";
4
+ import "../chunk-LEYAQNJA.js";
5
+ import "../chunk-JMOJU5EU.js";
6
+ import "../chunk-MFYF2A6U.js";
7
+ import "../chunk-6DCI7AL3.js";
8
+ import "../chunk-RLTHVQNQ.js";
9
+ import "../chunk-LA5SBCGQ.js";
7
10
 
8
11
  // src/react/index.ts
9
12
  import { createElement, useEffect, useRef, useState } from "react";
10
- function useLoom(initialDoc, opts = {}) {
13
+ function useMarkloom(initialDoc, opts = {}) {
11
14
  const ref = useRef(null);
12
15
  const editorRef = useRef(null);
13
16
  const [doc, setDoc] = useState(initialDoc);
@@ -35,11 +38,11 @@ function useLoom(initialDoc, opts = {}) {
35
38
  }, [opts.editable]);
36
39
  return { ref, editor: editorRef, doc };
37
40
  }
38
- function Loom({ doc, className, style, ...opts }) {
39
- const { ref } = useLoom(doc, opts);
41
+ function Markloom({ doc, className, style, ...opts }) {
42
+ const { ref } = useMarkloom(doc, opts);
40
43
  return createElement("div", { ref, className, style });
41
44
  }
42
45
  export {
43
- Loom,
44
- useLoom
46
+ Markloom,
47
+ useMarkloom
45
48
  };
@@ -0,0 +1,38 @@
1
+ import { S as Step } from './step-BrvHIK7O.js';
2
+
3
+ type Bias = -1 | 1;
4
+ declare function makeBias(thisSite: number, overSite: number): Bias;
5
+ declare function rebase(over: Step, step: Step, bias: Bias): Step | Step[] | null;
6
+
7
+ /** 把单步 step 穿过 over,产出 0..n 步(裂步)或空(作废) */
8
+ declare function rebaseOne(over: Step, step: Step, bias: Bias): Step[];
9
+ /** 一批 steps 依次穿过一条 over(批内顺序保留,裂步就地展开) */
10
+ declare function rebaseBatchOver(over: Step, steps: Step[], bias: Bias): Step[];
11
+ /**
12
+ * 本站 steps 穿过一系列并发 op(每条带 siteId)。
13
+ * 对 concurrent[i] 用 makeBias(thisSite, concurrent[i].siteId)。
14
+ */
15
+ declare function rebaseStepsThrough(steps: Step[], concurrent: {
16
+ siteId: number;
17
+ steps: Step[];
18
+ }[], thisSite: number): Step[];
19
+ /**
20
+ * 远端一批 remote 穿过本地 pending 队列 → remote';
21
+ * pending 同步被 remote 搬坐标 → pending'。
22
+ *
23
+ * 对每个 pending 项 p:
24
+ * remote 穿过 p: bias = makeBias(remoteSite, localSite)
25
+ * p 穿过「进入 p 前」的 remote: bias = makeBias(localSite, remoteSite)
26
+ */
27
+ declare function transformRemoteAgainstPending(remote: Step[], remoteSite: number, pending: {
28
+ siteId: number;
29
+ steps: Step[];
30
+ }[], localSite: number): {
31
+ remote: Step[];
32
+ pending: {
33
+ siteId: number;
34
+ steps: Step[];
35
+ }[];
36
+ };
37
+
38
+ export { type Bias as B, rebaseOne as a, rebaseStepsThrough as b, rebase as c, makeBias as m, rebaseBatchOver as r, transformRemoteAgainstPending as t };
@@ -0,0 +1,38 @@
1
+ import { S as Step } from './step-BrvHIK7O.cjs';
2
+
3
+ type Bias = -1 | 1;
4
+ declare function makeBias(thisSite: number, overSite: number): Bias;
5
+ declare function rebase(over: Step, step: Step, bias: Bias): Step | Step[] | null;
6
+
7
+ /** 把单步 step 穿过 over,产出 0..n 步(裂步)或空(作废) */
8
+ declare function rebaseOne(over: Step, step: Step, bias: Bias): Step[];
9
+ /** 一批 steps 依次穿过一条 over(批内顺序保留,裂步就地展开) */
10
+ declare function rebaseBatchOver(over: Step, steps: Step[], bias: Bias): Step[];
11
+ /**
12
+ * 本站 steps 穿过一系列并发 op(每条带 siteId)。
13
+ * 对 concurrent[i] 用 makeBias(thisSite, concurrent[i].siteId)。
14
+ */
15
+ declare function rebaseStepsThrough(steps: Step[], concurrent: {
16
+ siteId: number;
17
+ steps: Step[];
18
+ }[], thisSite: number): Step[];
19
+ /**
20
+ * 远端一批 remote 穿过本地 pending 队列 → remote';
21
+ * pending 同步被 remote 搬坐标 → pending'。
22
+ *
23
+ * 对每个 pending 项 p:
24
+ * remote 穿过 p: bias = makeBias(remoteSite, localSite)
25
+ * p 穿过「进入 p 前」的 remote: bias = makeBias(localSite, remoteSite)
26
+ */
27
+ declare function transformRemoteAgainstPending(remote: Step[], remoteSite: number, pending: {
28
+ siteId: number;
29
+ steps: Step[];
30
+ }[], localSite: number): {
31
+ remote: Step[];
32
+ pending: {
33
+ siteId: number;
34
+ steps: Step[];
35
+ }[];
36
+ };
37
+
38
+ export { type Bias as B, rebaseOne as a, rebaseStepsThrough as b, rebase as c, makeBias as m, rebaseBatchOver as r, transformRemoteAgainstPending as t };
@@ -0,0 +1,65 @@
1
+ interface TextNode {
2
+ text: string;
3
+ marks?: Mark[];
4
+ }
5
+ interface ElementNode {
6
+ type: string;
7
+ attrs?: Record<string, unknown>;
8
+ children: Node[];
9
+ id?: string;
10
+ }
11
+ type Node = TextNode | ElementNode;
12
+ interface Mark {
13
+ name: string;
14
+ attrs?: Record<string, unknown>;
15
+ }
16
+ declare function isText(n: Node): n is TextNode;
17
+ declare function isElement(n: Node): n is ElementNode;
18
+ declare function isInlineAtom(n: Node): boolean;
19
+ type Path = number[];
20
+ interface Position {
21
+ path: Path;
22
+ assoc?: -1 | 1;
23
+ }
24
+ interface Selection {
25
+ anchor: Position;
26
+ head: Position;
27
+ }
28
+ type Doc = ElementNode;
29
+
30
+ interface InsertText {
31
+ kind: 'insertText';
32
+ path: Path;
33
+ offset: number;
34
+ text: string;
35
+ marks?: {
36
+ name: string;
37
+ attrs?: Record<string, unknown>;
38
+ }[];
39
+ }
40
+ interface DeleteText {
41
+ kind: 'deleteText';
42
+ path: Path;
43
+ offset: number;
44
+ length: number;
45
+ }
46
+ interface ReplaceNode {
47
+ kind: 'replaceNode';
48
+ path: Path;
49
+ node: Node;
50
+ }
51
+ interface SpliceChildren {
52
+ kind: 'spliceChildren';
53
+ path: Path;
54
+ at: number;
55
+ remove: number;
56
+ insert: Node[];
57
+ }
58
+ type Step = InsertText | DeleteText | ReplaceNode | SpliceChildren;
59
+ declare function apply(doc: ElementNode, step: Step): ElementNode;
60
+ declare function invert(doc: ElementNode, step: Step): Step;
61
+ declare function applyAll(doc: ElementNode, steps: Step[]): ElementNode;
62
+ declare function moveBlock(doc: ElementNode, fromIdx: number, toGap: number): Step[];
63
+ declare function invertAll(doc: ElementNode, steps: Step[]): Step[];
64
+
65
+ export { type DeleteText as D, type ElementNode as E, type InsertText as I, type Mark as M, type Node as N, type Path as P, type ReplaceNode as R, type Step as S, type TextNode as T, type Position as a, type Doc as b, type Selection as c, type SpliceChildren as d, apply as e, applyAll as f, invertAll as g, isElement as h, invert as i, isInlineAtom as j, isText as k, moveBlock as m };
@@ -0,0 +1,65 @@
1
+ interface TextNode {
2
+ text: string;
3
+ marks?: Mark[];
4
+ }
5
+ interface ElementNode {
6
+ type: string;
7
+ attrs?: Record<string, unknown>;
8
+ children: Node[];
9
+ id?: string;
10
+ }
11
+ type Node = TextNode | ElementNode;
12
+ interface Mark {
13
+ name: string;
14
+ attrs?: Record<string, unknown>;
15
+ }
16
+ declare function isText(n: Node): n is TextNode;
17
+ declare function isElement(n: Node): n is ElementNode;
18
+ declare function isInlineAtom(n: Node): boolean;
19
+ type Path = number[];
20
+ interface Position {
21
+ path: Path;
22
+ assoc?: -1 | 1;
23
+ }
24
+ interface Selection {
25
+ anchor: Position;
26
+ head: Position;
27
+ }
28
+ type Doc = ElementNode;
29
+
30
+ interface InsertText {
31
+ kind: 'insertText';
32
+ path: Path;
33
+ offset: number;
34
+ text: string;
35
+ marks?: {
36
+ name: string;
37
+ attrs?: Record<string, unknown>;
38
+ }[];
39
+ }
40
+ interface DeleteText {
41
+ kind: 'deleteText';
42
+ path: Path;
43
+ offset: number;
44
+ length: number;
45
+ }
46
+ interface ReplaceNode {
47
+ kind: 'replaceNode';
48
+ path: Path;
49
+ node: Node;
50
+ }
51
+ interface SpliceChildren {
52
+ kind: 'spliceChildren';
53
+ path: Path;
54
+ at: number;
55
+ remove: number;
56
+ insert: Node[];
57
+ }
58
+ type Step = InsertText | DeleteText | ReplaceNode | SpliceChildren;
59
+ declare function apply(doc: ElementNode, step: Step): ElementNode;
60
+ declare function invert(doc: ElementNode, step: Step): Step;
61
+ declare function applyAll(doc: ElementNode, steps: Step[]): ElementNode;
62
+ declare function moveBlock(doc: ElementNode, fromIdx: number, toGap: number): Step[];
63
+ declare function invertAll(doc: ElementNode, steps: Step[]): Step[];
64
+
65
+ export { type DeleteText as D, type ElementNode as E, type InsertText as I, type Mark as M, type Node as N, type Path as P, type ReplaceNode as R, type Step as S, type TextNode as T, type Position as a, type Doc as b, type Selection as c, type SpliceChildren as d, apply as e, applyAll as f, invertAll as g, isElement as h, invert as i, isInlineAtom as j, isText as k, moveBlock as m };