markloom 0.6.0 → 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 (59) hide show
  1. package/collab.md +25 -13
  2. package/dist/ai/index.cjs +5 -4
  3. package/dist/ai/index.d.cts +5 -5
  4. package/dist/ai/index.d.ts +5 -5
  5. package/dist/ai/index.js +4 -3
  6. package/dist/{chunk-KYZJIOOL.js → chunk-4Q7PAR2T.js} +3671 -904
  7. package/dist/chunk-75EJ4ARB.cjs +642 -0
  8. package/dist/{chunk-U3JZDFL4.cjs → chunk-BMPCVT3B.cjs} +2 -34
  9. package/dist/{chunk-VSBIMMI7.js → chunk-EFYT2223.js} +3 -35
  10. package/dist/chunk-HXABDVLZ.cjs +297 -0
  11. package/dist/{chunk-I5VK4U7J.cjs → chunk-I2LDEVLA.cjs} +434 -80
  12. package/dist/{chunk-YBAT343I.js → chunk-MQLRZQZL.js} +263 -119
  13. package/dist/chunk-OVHASRID.cjs +4279 -0
  14. package/dist/chunk-PCSVBPOR.cjs +40 -0
  15. package/dist/{chunk-TB2OY3D4.js → chunk-PSAXWBNM.js} +413 -59
  16. package/dist/{chunk-QEVME6ZU.cjs → chunk-PZRWTLLB.cjs} +260 -161
  17. package/dist/chunk-QO7JEZDB.js +4279 -0
  18. package/dist/{chunk-EJSFZHGT.js → chunk-WSJUXPAG.js} +18 -2
  19. package/dist/{chunk-ACFYBYZJ.cjs → chunk-Y4IXQFWL.cjs} +4212 -1445
  20. package/dist/{chunk-CGYCJORO.js → chunk-YLVSMDIO.js} +220 -121
  21. package/dist/chunk-ZL6WT6OY.js +297 -0
  22. package/dist/{client-CLYq17SW.d.ts → client-BvvyHjhh.d.ts} +57 -7
  23. package/dist/{client-DAth8pPq.d.cts → client-Ciy7Fa_k.d.cts} +57 -7
  24. package/dist/collab/index.cjs +5 -4
  25. package/dist/collab/index.d.cts +13 -15
  26. package/dist/collab/index.d.ts +13 -15
  27. package/dist/collab/index.js +4 -3
  28. package/dist/{controller-BIOO_XKJ.d.cts → controller-CHznEhAR.d.cts} +186 -27
  29. package/dist/{controller-6AJ36G52.d.ts → controller-DLqI8_jm.d.ts} +186 -27
  30. package/dist/index.cjs +69 -7
  31. package/dist/index.d.cts +127 -8
  32. package/dist/index.d.ts +127 -8
  33. package/dist/index.js +80 -18
  34. package/dist/io/index.cjs +58 -59
  35. package/dist/io/index.d.cts +1 -1
  36. package/dist/io/index.d.ts +1 -1
  37. package/dist/io/index.js +15 -16
  38. package/dist/react/index.cjs +9 -8
  39. package/dist/react/index.d.cts +5 -5
  40. package/dist/react/index.d.ts +5 -5
  41. package/dist/react/index.js +8 -7
  42. package/dist/{rebase-batch-DlerAcFN.d.ts → rebase-batch-CSnv8FKp.d.ts} +1 -1
  43. package/dist/{rebase-batch-PjENQ742.d.cts → rebase-batch-DO1ygkx9.d.cts} +1 -1
  44. package/dist/{types-COUweEav.d.cts → types-BkHlmUFL.d.cts} +5 -1
  45. package/dist/{types-COUweEav.d.ts → types-BkHlmUFL.d.ts} +5 -1
  46. package/dist/{versions-9mG1epfB.d.cts → versions-DNFf8zVz.d.cts} +1 -1
  47. package/dist/{versions-Bubyo4pt.d.ts → versions-DOkOyh2J.d.ts} +1 -1
  48. package/dist/view/index.cjs +215 -17
  49. package/dist/view/index.d.cts +82 -9
  50. package/dist/view/index.d.ts +82 -9
  51. package/dist/view/index.js +212 -14
  52. package/dist/view/theme.css +349 -75
  53. package/dist/{suggest-Bk4zLzuv.d.ts → word-count-BPw9G2Bg.d.ts} +15 -5
  54. package/dist/{suggest-BkGGiPKA.d.cts → word-count-DNLn1h_t.d.cts} +15 -5
  55. package/package.json +11 -6
  56. package/dist/chunk-EADZKEU4.cjs +0 -498
  57. package/dist/chunk-SNFF6X45.js +0 -2347
  58. package/dist/chunk-TWD5T4YC.cjs +0 -2347
  59. package/dist/chunk-ZKQSQSSM.cjs +0 -24
@@ -1,20 +1,24 @@
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
3
 
4
+ var _chunkOVHASRIDcjs = require('./chunk-OVHASRID.cjs');
4
5
 
5
6
 
6
7
 
8
+ var _chunkBMPCVT3Bcjs = require('./chunk-BMPCVT3B.cjs');
7
9
 
8
- var _chunkTWD5T4YCcjs = require('./chunk-TWD5T4YC.cjs');
9
10
 
10
11
 
11
12
 
12
- var _chunkU3JZDFL4cjs = require('./chunk-U3JZDFL4.cjs');
13
13
 
14
+ var _chunkHXABDVLZcjs = require('./chunk-HXABDVLZ.cjs');
14
15
 
15
16
 
16
17
 
17
- var _chunkZKQSQSSMcjs = require('./chunk-ZKQSQSSM.cjs');
18
+
19
+
20
+
21
+ var _chunkPCSVBPORcjs = require('./chunk-PCSVBPOR.cjs');
18
22
 
19
23
  // src/tree/history.ts
20
24
  function init(doc, validate) {
@@ -26,8 +30,10 @@ function gate(h, next) {
26
30
  throw new Error(`[invariant] \u63D0\u4EA4\u4EA7\u751F\u975E\u6CD5 doc: ${v}`);
27
31
  }
28
32
  function commit(h, steps, before, after) {
29
- const inverse = _chunkTWD5T4YCcjs.invertAll.call(void 0, h.doc, steps);
30
- const next = _chunkTWD5T4YCcjs.applyAll.call(void 0, h.doc, steps);
33
+ if (steps.length === 0)
34
+ return h;
35
+ const inverse = _chunkHXABDVLZcjs.invertAll.call(void 0, h.doc, steps);
36
+ const next = _chunkHXABDVLZcjs.applyAll.call(void 0, h.doc, steps);
31
37
  gate(h, next);
32
38
  const entry = { steps, inverse };
33
39
  if (before)
@@ -39,17 +45,17 @@ function commit(h, steps, before, after) {
39
45
  function applyForeign(h, steps, thisSite = 0, foreignSite = 1) {
40
46
  if (steps.length === 0)
41
47
  return h;
42
- const next = _chunkTWD5T4YCcjs.applyAll.call(void 0, h.doc, steps);
48
+ const next = _chunkHXABDVLZcjs.applyAll.call(void 0, h.doc, steps);
43
49
  gate(h, next);
44
50
  const overs = [{ siteId: foreignSite, steps }];
45
51
  const mapCommit = (c) => {
46
- const fwd = _chunkU3JZDFL4cjs.rebaseStepsThrough.call(void 0, c.steps, overs, thisSite);
47
- const inv = _chunkU3JZDFL4cjs.rebaseStepsThrough.call(void 0, c.inverse, overs, thisSite);
52
+ const fwd = _chunkBMPCVT3Bcjs.rebaseStepsThrough.call(void 0, c.steps, overs, thisSite);
53
+ const inv = _chunkBMPCVT3Bcjs.rebaseStepsThrough.call(void 0, c.inverse, overs, thisSite);
48
54
  if (fwd.length === 0 && inv.length === 0)
49
55
  return null;
50
56
  const entry = { steps: fwd, inverse: inv };
51
- const b = _chunkU3JZDFL4cjs.mapSelectionThrough.call(void 0, c.before, steps);
52
- const a = _chunkU3JZDFL4cjs.mapSelectionThrough.call(void 0, c.after, steps);
57
+ const b = _chunkBMPCVT3Bcjs.mapSelectionThrough.call(void 0, c.before, steps);
58
+ const a = _chunkBMPCVT3Bcjs.mapSelectionThrough.call(void 0, c.after, steps);
53
59
  if (b)
54
60
  entry.before = b;
55
61
  if (a)
@@ -69,10 +75,9 @@ function amend(h, more, after, before) {
69
75
  if (h.past.length === 0)
70
76
  return commit(h, more, before, after);
71
77
  const last = h.past[h.past.length - 1];
72
- const docBefore = _chunkTWD5T4YCcjs.applyAll.call(void 0, h.doc, last.inverse);
73
78
  const steps = last.steps.concat(more);
74
- const inverse = _chunkTWD5T4YCcjs.invertAll.call(void 0, docBefore, steps);
75
- const next = _chunkTWD5T4YCcjs.applyAll.call(void 0, docBefore, steps);
79
+ const inverse = _chunkHXABDVLZcjs.invertAll.call(void 0, h.doc, more).concat(last.inverse);
80
+ const next = _chunkHXABDVLZcjs.applyAll.call(void 0, h.doc, more);
76
81
  gate(h, next);
77
82
  const entry = { steps, inverse };
78
83
  if (last.before)
@@ -92,7 +97,7 @@ function undo(h) {
92
97
  const last = h.past[h.past.length - 1];
93
98
  if (!last)
94
99
  return h;
95
- const next = _chunkTWD5T4YCcjs.applyAll.call(void 0, h.doc, last.inverse);
100
+ const next = _chunkHXABDVLZcjs.applyAll.call(void 0, h.doc, last.inverse);
96
101
  gate(h, next);
97
102
  return { ...h, doc: next, past: h.past.slice(0, -1), future: [last, ...h.future] };
98
103
  }
@@ -100,7 +105,7 @@ function redo(h) {
100
105
  const next = h.future[0];
101
106
  if (!next)
102
107
  return h;
103
- const doc = _chunkTWD5T4YCcjs.applyAll.call(void 0, h.doc, next.steps);
108
+ const doc = _chunkHXABDVLZcjs.applyAll.call(void 0, h.doc, next.steps);
104
109
  gate(h, doc);
105
110
  return { ...h, doc, past: h.past.concat(next), future: h.future.slice(1) };
106
111
  }
@@ -108,13 +113,14 @@ function redo(h) {
108
113
  // src/tree/invariants.ts
109
114
  function invariants(schema, doc) {
110
115
  const out = [];
111
- out.push(..._chunkTWD5T4YCcjs.validateAll.call(void 0, schema, doc));
116
+ out.push(..._chunkOVHASRIDcjs.validateAll.call(void 0, schema, doc));
112
117
  const ids = /* @__PURE__ */ new Map();
113
118
  walk(doc, [], schema, out, ids);
114
119
  return out;
115
120
  }
121
+ var INTERNAL_MARKS = ["html", "image"];
116
122
  function walk(node, path, schema, out, ids) {
117
- if (_chunkZKQSQSSMcjs.isText.call(void 0, node)) {
123
+ if (_chunkPCSVBPORcjs.isText.call(void 0, node)) {
118
124
  return;
119
125
  }
120
126
  if (node.id !== void 0) {
@@ -135,27 +141,42 @@ function walk(node, path, schema, out, ids) {
135
141
  out.push({ path, reason: `[mention] \u7F3A id` });
136
142
  return;
137
143
  }
144
+ if (node.type === "footnote_ref") {
145
+ if (typeof _optionalChain([node, 'access', _8 => _8.attrs, 'optionalAccess', _9 => _9.label]) !== "string" || !node.attrs.label)
146
+ out.push({ path, reason: `[footnote_ref] \u7F3A label` });
147
+ return;
148
+ }
138
149
  if (node.type === "math") {
139
- if (typeof _optionalChain([node, 'access', _8 => _8.attrs, 'optionalAccess', _9 => _9.latex]) !== "string")
150
+ if (typeof _optionalChain([node, 'access', _10 => _10.attrs, 'optionalAccess', _11 => _11.latex]) !== "string")
140
151
  out.push({ path, reason: `[math] \u7F3A latex` });
141
152
  return;
142
153
  }
143
154
  if (node.type === "embed") {
144
- if (!_optionalChain([node, 'access', _10 => _10.attrs, 'optionalAccess', _11 => _11.kind]))
155
+ if (!_optionalChain([node, 'access', _12 => _12.attrs, 'optionalAccess', _13 => _13.kind]))
145
156
  out.push({ path, reason: `[embed] \u7F3A kind` });
146
- if (!_optionalChain([node, 'access', _12 => _12.attrs, 'optionalAccess', _13 => _13.src]))
157
+ if (!_optionalChain([node, 'access', _14 => _14.attrs, 'optionalAccess', _15 => _15.src]))
147
158
  out.push({ path, reason: `[embed] \u7F3A src` });
148
159
  return;
149
160
  }
150
- for (const reason of _chunkTWD5T4YCcjs.checkTable.call(void 0, node)) {
161
+ for (const reason of _chunkOVHASRIDcjs.checkTable.call(void 0, node)) {
151
162
  out.push({ path, reason: `[table] ${reason}` });
152
163
  }
153
164
  return;
154
165
  }
155
- if (_optionalChain([spec, 'optionalAccess', _14 => _14.marks])) {
166
+ for (let i = 0; i < node.children.length; i++) {
167
+ const child = node.children[i];
168
+ if (_chunkPCSVBPORcjs.isText.call(void 0, child) && child.marks) {
169
+ for (const m of child.marks) {
170
+ if (!schema.marks.includes(m.name) && !INTERNAL_MARKS.includes(m.name)) {
171
+ out.push({ path: path.concat(i), reason: `\u672A\u77E5 mark "${m.name}"` });
172
+ }
173
+ }
174
+ }
175
+ }
176
+ if (_optionalChain([spec, 'optionalAccess', _16 => _16.marks])) {
156
177
  for (let i = 0; i < node.children.length; i++) {
157
178
  const child = node.children[i];
158
- if (_chunkZKQSQSSMcjs.isText.call(void 0, child) && child.marks) {
179
+ if (_chunkPCSVBPORcjs.isText.call(void 0, child) && child.marks) {
159
180
  for (const m of child.marks) {
160
181
  if (!spec.marks.includes(m.name)) {
161
182
  out.push({ path: path.concat(i), reason: `${node.type} \u4E0D\u5141\u8BB8 mark "${m.name}"` });
@@ -176,80 +197,162 @@ function firstViolation(vs) {
176
197
  return `${v.path.join(",")}: ${v.reason}`;
177
198
  }
178
199
 
200
+ // src/tree/word-count.ts
201
+ function isCjk(c) {
202
+ return c >= 19968 && c <= 40959 || c >= 13312 && c <= 19903 || c >= 131072 && c <= 195103 || c >= 63744 && c <= 64255 || c >= 12352 && c <= 12543 || c >= 44032 && c <= 55215;
203
+ }
204
+ var WORD_CHAR = /[\p{L}\p{N}\p{M}]/u;
205
+ var JOINER = /* @__PURE__ */ new Set(["'", "\u2019", "-", "_"]);
206
+ var SPACE = /\s/u;
207
+ function scan(text, acc) {
208
+ let inWord = false;
209
+ for (const ch of text) {
210
+ if (ch === "\n" || ch === "\r")
211
+ inWord = false;
212
+ else
213
+ acc.chars++;
214
+ if (SPACE.test(ch)) {
215
+ inWord = false;
216
+ continue;
217
+ }
218
+ acc.charsNoSpace++;
219
+ if (isCjk(ch.codePointAt(0))) {
220
+ acc.words++;
221
+ inWord = false;
222
+ } else if (WORD_CHAR.test(ch)) {
223
+ if (!inWord)
224
+ acc.words++;
225
+ inWord = true;
226
+ } else if (!(inWord && JOINER.has(ch))) {
227
+ inWord = false;
228
+ }
229
+ }
230
+ }
231
+ function leafText(n) {
232
+ return n.children.map((c) => _chunkPCSVBPORcjs.isText.call(void 0, c) ? c.text : "\n").join("");
233
+ }
234
+ function walk2(n, acc) {
235
+ if (n.type === "raw")
236
+ return;
237
+ if (n.children.some(_chunkPCSVBPORcjs.isText)) {
238
+ const text = leafText(n);
239
+ if ((n.type === "paragraph" || n.type === "heading") && text.trim() !== "")
240
+ acc.paragraphs++;
241
+ scan(text, acc);
242
+ return;
243
+ }
244
+ for (const c of n.children) {
245
+ if (!_chunkPCSVBPORcjs.isText.call(void 0, c))
246
+ walk2(c, acc);
247
+ }
248
+ }
249
+ function wordCount(doc) {
250
+ const acc = { words: 0, chars: 0, charsNoSpace: 0, paragraphs: 0 };
251
+ walk2(doc, acc);
252
+ return acc;
253
+ }
254
+
179
255
  // src/tree/toc.ts
180
256
  function headingText(node) {
181
257
  let out = "";
182
258
  for (const c of node.children) {
183
- if (_chunkZKQSQSSMcjs.isText.call(void 0, c))
259
+ if (_chunkPCSVBPORcjs.isText.call(void 0, c))
184
260
  out += c.text;
185
261
  }
186
262
  return out;
187
263
  }
188
264
  function outline(doc) {
189
265
  const out = [];
190
- const walk3 = (node, path) => {
191
- if (_chunkZKQSQSSMcjs.isText.call(void 0, node))
266
+ const walk4 = (node, path) => {
267
+ if (_chunkPCSVBPORcjs.isText.call(void 0, node))
192
268
  return;
193
269
  if (node.type === "heading") {
194
- const level = Math.min(Math.max(Number(_nullishCoalesce(_optionalChain([node, 'access', _15 => _15.attrs, 'optionalAccess', _16 => _16.depth]), () => ( 1))), 1), 6);
270
+ const level = Math.min(Math.max(Number(_nullishCoalesce(_optionalChain([node, 'access', _17 => _17.attrs, 'optionalAccess', _18 => _18.depth]), () => ( 1))), 1), 6);
195
271
  out.push({ level, text: headingText(node), path, id: node.id });
196
272
  return;
197
273
  }
198
274
  for (let i = 0; i < node.children.length; i++)
199
- walk3(node.children[i], path.concat(i));
275
+ walk4(node.children[i], path.concat(i));
200
276
  };
201
- walk3(doc, []);
277
+ walk4(doc, []);
202
278
  return out;
203
279
  }
204
280
 
205
- // src/tree/comments.ts
206
- function commentIdsInDoc(doc) {
281
+ // src/tree/annotate.ts
282
+ function markIdsInDoc(doc, name) {
207
283
  const ids = /* @__PURE__ */ new Set();
208
- const walk3 = (n) => {
209
- if (_chunkZKQSQSSMcjs.isText.call(void 0, n)) {
284
+ const walk4 = (n) => {
285
+ if (_chunkPCSVBPORcjs.isText.call(void 0, n)) {
210
286
  for (const m of _nullishCoalesce(n.marks, () => ( []))) {
211
- if (m.name === "comment" && _optionalChain([m, 'access', _17 => _17.attrs, 'optionalAccess', _18 => _18.id]) != null)
287
+ if (m.name === name && _optionalChain([m, 'access', _19 => _19.attrs, 'optionalAccess', _20 => _20.id]) != null)
212
288
  ids.add(String(m.attrs.id));
213
289
  }
214
290
  return;
215
291
  }
216
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, n))
292
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, n))
217
293
  for (const c of n.children)
218
- walk3(c);
294
+ walk4(c);
219
295
  };
220
- walk3(doc);
296
+ walk4(doc);
221
297
  return ids;
222
298
  }
223
- function stripLeaf(leaf, id) {
224
- const rest = (_nullishCoalesce(leaf.marks, () => ( []))).filter((m) => !(m.name === "comment" && String(_optionalChain([m, 'access', _19 => _19.attrs, 'optionalAccess', _20 => _20.id])) === id));
225
- return rest.length ? { ...leaf, marks: rest } : { text: leaf.text };
226
- }
227
- function stripCommentMarks(doc, id) {
299
+ function mapLeafBlocks(doc, fn) {
228
300
  const steps = [];
229
- const walk3 = (node, path) => {
230
- if (node.children.every((c) => _chunkZKQSQSSMcjs.isText.call(void 0, c) || _chunkZKQSQSSMcjs.isInlineAtom.call(void 0, c))) {
231
- let changed = false;
232
- const children = node.children.map((c) => {
233
- if (!_chunkZKQSQSSMcjs.isText.call(void 0, c) || !_optionalChain([c, 'access', _21 => _21.marks, 'optionalAccess', _22 => _22.some, 'call', _23 => _23((m) => m.name === "comment" && String(_optionalChain([m, 'access', _24 => _24.attrs, 'optionalAccess', _25 => _25.id])) === id)]))
234
- return c;
235
- changed = true;
236
- return stripLeaf(c, id);
237
- });
238
- if (changed)
239
- steps.push({ kind: "replaceNode", path, node: { ...node, children } });
301
+ const walk4 = (node, path) => {
302
+ if (node.children.every((c) => _chunkPCSVBPORcjs.isText.call(void 0, c) || _chunkPCSVBPORcjs.isInlineAtom.call(void 0, c))) {
303
+ const next = fn(node, path);
304
+ if (next)
305
+ steps.push({ kind: "replaceNode", path, node: next });
240
306
  return;
241
307
  }
242
308
  node.children.forEach((c, i) => {
243
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, c))
244
- walk3(c, path.concat(i));
309
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, c))
310
+ walk4(c, path.concat(i));
245
311
  });
246
312
  };
247
313
  doc.children.forEach((c, i) => {
248
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, c))
249
- walk3(c, [i]);
314
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, c))
315
+ walk4(c, [i]);
250
316
  });
251
317
  return steps;
252
318
  }
319
+ function stripMarks(doc, pred) {
320
+ return mapLeafBlocks(doc, (node) => {
321
+ let changed = false;
322
+ const children = node.children.map((c) => {
323
+ if (!_chunkPCSVBPORcjs.isText.call(void 0, c) || !_optionalChain([c, 'access', _21 => _21.marks, 'optionalAccess', _22 => _22.some, 'call', _23 => _23(pred)]))
324
+ return c;
325
+ changed = true;
326
+ const rest = (_nullishCoalesce(c.marks, () => ( []))).filter((m) => !pred(m));
327
+ return rest.length ? { ...c, marks: rest } : { text: c.text };
328
+ });
329
+ return changed ? { ...node, children } : null;
330
+ });
331
+ }
332
+ function dropMarkedLeaves(doc, pred) {
333
+ return mapLeafBlocks(doc, (node) => {
334
+ let changed = false;
335
+ const children = [];
336
+ for (const c of node.children) {
337
+ if (_chunkPCSVBPORcjs.isText.call(void 0, c) && pred(c)) {
338
+ changed = true;
339
+ continue;
340
+ }
341
+ children.push(c);
342
+ }
343
+ if (!changed)
344
+ return null;
345
+ return { ...node, children: children.length ? children : [{ text: "" }] };
346
+ });
347
+ }
348
+
349
+ // src/tree/comments.ts
350
+ function commentIdsInDoc(doc) {
351
+ return markIdsInDoc(doc, "comment");
352
+ }
353
+ function stripCommentMarks(doc, id) {
354
+ return stripMarks(doc, (m) => m.name === "comment" && String(_optionalChain([m, 'access', _24 => _24.attrs, 'optionalAccess', _25 => _25.id])) === id);
355
+ }
253
356
 
254
357
  // src/tree/search.ts
255
358
  var DEFAULT_SKIP = ["code"];
@@ -260,7 +363,7 @@ function findText(doc, query, opts = {}) {
260
363
  const cs = opts.caseSensitive === true;
261
364
  const needle = cs ? query : query.toLowerCase();
262
365
  const out = [];
263
- walk2(doc, [], skip, (path, text) => {
366
+ walk3(doc, [], skip, (path, text) => {
264
367
  const hay = cs ? text : text.toLowerCase();
265
368
  let from = 0;
266
369
  while (from <= hay.length - needle.length) {
@@ -299,7 +402,7 @@ function replaceAll(doc, query, replacement, opts = {}) {
299
402
  const cs = opts.caseSensitive === true;
300
403
  const steps = [];
301
404
  let count = 0;
302
- walk2(doc, [], skip, (path, text, leaf) => {
405
+ walk3(doc, [], skip, (path, text, leaf) => {
303
406
  const { text: next, n } = replaceInString(text, query, replacement, cs);
304
407
  if (n === 0)
305
408
  return;
@@ -316,7 +419,7 @@ function applyReplaceAll(doc, query, replacement, opts = {}) {
316
419
  const { steps } = replaceAll(doc, query, replacement, opts);
317
420
  let d = doc;
318
421
  for (const s of steps)
319
- d = _chunkTWD5T4YCcjs.apply.call(void 0, d, s);
422
+ d = _chunkHXABDVLZcjs.apply.call(void 0, d, s);
320
423
  return d;
321
424
  }
322
425
  function replaceInString(text, query, replacement, caseSensitive) {
@@ -345,17 +448,17 @@ function replaceInString(text, query, replacement, caseSensitive) {
345
448
  }
346
449
  return { text: out, n };
347
450
  }
348
- function walk2(node, path, skip, onLeaf) {
349
- if (_chunkZKQSQSSMcjs.isText.call(void 0, node)) {
451
+ function walk3(node, path, skip, onLeaf) {
452
+ if (_chunkPCSVBPORcjs.isText.call(void 0, node)) {
350
453
  onLeaf(path, node.text, node);
351
454
  return;
352
455
  }
353
- if (!_chunkZKQSQSSMcjs.isElement.call(void 0, node))
456
+ if (!_chunkPCSVBPORcjs.isElement.call(void 0, node))
354
457
  return;
355
458
  if (skip.has(node.type))
356
459
  return;
357
460
  for (let i = 0; i < node.children.length; i++)
358
- walk2(node.children[i], path.concat(i), skip, onLeaf);
461
+ walk3(node.children[i], path.concat(i), skip, onLeaf);
359
462
  }
360
463
 
361
464
  // src/tree/versions.ts
@@ -415,29 +518,15 @@ function isSuggestMark(m, id) {
415
518
  return String(_nullishCoalesce(_optionalChain([m, 'access', _28 => _28.attrs, 'optionalAccess', _29 => _29.id]), () => ( ""))) === id;
416
519
  }
417
520
  function suggestIdsInDoc(doc) {
418
- const ids = /* @__PURE__ */ new Set();
419
- const walk3 = (n) => {
420
- if (_chunkZKQSQSSMcjs.isText.call(void 0, n)) {
421
- for (const m of _nullishCoalesce(n.marks, () => ( []))) {
422
- if (m.name === "suggest" && _optionalChain([m, 'access', _30 => _30.attrs, 'optionalAccess', _31 => _31.id]) != null)
423
- ids.add(String(m.attrs.id));
424
- }
425
- return;
426
- }
427
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, n))
428
- for (const c of n.children)
429
- walk3(c);
430
- };
431
- walk3(doc);
432
- return ids;
521
+ return markIdsInDoc(doc, "suggest");
433
522
  }
434
523
  function listSuggestions(doc) {
435
524
  const order = [];
436
525
  const map = /* @__PURE__ */ new Map();
437
- const walk3 = (n) => {
438
- if (_chunkZKQSQSSMcjs.isText.call(void 0, n)) {
526
+ const walk4 = (n) => {
527
+ if (_chunkPCSVBPORcjs.isText.call(void 0, n)) {
439
528
  for (const m of _nullishCoalesce(n.marks, () => ( []))) {
440
- if (m.name !== "suggest" || _optionalChain([m, 'access', _32 => _32.attrs, 'optionalAccess', _33 => _33.id]) == null)
529
+ if (m.name !== "suggest" || _optionalChain([m, 'access', _30 => _30.attrs, 'optionalAccess', _31 => _31.id]) == null)
441
530
  continue;
442
531
  const id = String(m.attrs.id);
443
532
  const kind = m.attrs.kind === "delete" ? "delete" : "insert";
@@ -457,17 +546,13 @@ function listSuggestions(doc) {
457
546
  }
458
547
  return;
459
548
  }
460
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, n))
549
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, n))
461
550
  for (const c of n.children)
462
- walk3(c);
551
+ walk4(c);
463
552
  };
464
- walk3(doc);
553
+ walk4(doc);
465
554
  return order.map((id) => map.get(id));
466
555
  }
467
- function stripLeaf2(leaf, id) {
468
- const rest = (_nullishCoalesce(leaf.marks, () => ( []))).filter((m) => !isSuggestMark(m, id));
469
- return rest.length ? { ...leaf, marks: rest } : { text: leaf.text };
470
- }
471
556
  function leafHasSuggest(leaf, id) {
472
557
  return (_nullishCoalesce(leaf.marks, () => ( []))).some((m) => isSuggestMark(m, id));
473
558
  }
@@ -475,68 +560,18 @@ function leafSuggestKind(leaf, id) {
475
560
  const m = (_nullishCoalesce(leaf.marks, () => ( []))).find((m2) => isSuggestMark(m2, id));
476
561
  if (!m)
477
562
  return null;
478
- return _optionalChain([m, 'access', _34 => _34.attrs, 'optionalAccess', _35 => _35.kind]) === "delete" ? "delete" : "insert";
563
+ return _optionalChain([m, 'access', _32 => _32.attrs, 'optionalAccess', _33 => _33.kind]) === "delete" ? "delete" : "insert";
479
564
  }
480
565
  function stripSuggestMarks(doc, id) {
481
- const steps = [];
482
- const walk3 = (node, path) => {
483
- if (node.children.every((c) => _chunkZKQSQSSMcjs.isText.call(void 0, c) || _chunkZKQSQSSMcjs.isInlineAtom.call(void 0, c))) {
484
- let changed = false;
485
- const children = node.children.map((c) => {
486
- if (!_chunkZKQSQSSMcjs.isText.call(void 0, c) || !leafHasSuggest(c, id))
487
- return c;
488
- changed = true;
489
- return stripLeaf2(c, id);
490
- });
491
- if (changed)
492
- steps.push({ kind: "replaceNode", path, node: { ...node, children } });
493
- return;
494
- }
495
- node.children.forEach((c, i) => {
496
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, c))
497
- walk3(c, path.concat(i));
498
- });
499
- };
500
- doc.children.forEach((c, i) => {
501
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, c))
502
- walk3(c, [i]);
503
- });
504
- return steps;
566
+ return stripMarks(doc, (m) => isSuggestMark(m, id));
505
567
  }
506
568
  function dropSuggestText(doc, id) {
507
- const steps = [];
508
- const walk3 = (node, path) => {
509
- if (node.children.every((c) => _chunkZKQSQSSMcjs.isText.call(void 0, c) || _chunkZKQSQSSMcjs.isInlineAtom.call(void 0, c))) {
510
- let changed = false;
511
- const children = [];
512
- for (const c of node.children) {
513
- if (_chunkZKQSQSSMcjs.isText.call(void 0, c) && leafHasSuggest(c, id)) {
514
- changed = true;
515
- continue;
516
- }
517
- children.push(c);
518
- }
519
- if (changed) {
520
- const next = children.length ? children : [{ text: "" }];
521
- steps.push({ kind: "replaceNode", path, node: { ...node, children: next } });
522
- }
523
- return;
524
- }
525
- node.children.forEach((c, i) => {
526
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, c))
527
- walk3(c, path.concat(i));
528
- });
529
- };
530
- doc.children.forEach((c, i) => {
531
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, c))
532
- walk3(c, [i]);
533
- });
534
- return steps;
569
+ return dropMarkedLeaves(doc, (leaf) => leafHasSuggest(leaf, id));
535
570
  }
536
571
  function kindOfId(doc, id) {
537
572
  let kind = "insert";
538
- const walk3 = (n) => {
539
- if (_chunkZKQSQSSMcjs.isText.call(void 0, n)) {
573
+ const walk4 = (n) => {
574
+ if (_chunkPCSVBPORcjs.isText.call(void 0, n)) {
540
575
  const k = leafSuggestKind(n, id);
541
576
  if (k) {
542
577
  kind = k;
@@ -544,15 +579,15 @@ function kindOfId(doc, id) {
544
579
  }
545
580
  return false;
546
581
  }
547
- if (_chunkZKQSQSSMcjs.isElement.call(void 0, n)) {
582
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, n)) {
548
583
  for (const c of n.children) {
549
- if (walk3(c))
584
+ if (walk4(c))
550
585
  return true;
551
586
  }
552
587
  }
553
588
  return false;
554
589
  };
555
- walk3(doc);
590
+ walk4(doc);
556
591
  return kind;
557
592
  }
558
593
  function acceptSuggestion(doc, id) {
@@ -572,24 +607,24 @@ function blockChar(children, leafIdx, char) {
572
607
  let n = 0;
573
608
  for (let i = 0; i < leafIdx; i++) {
574
609
  const c = children[i];
575
- n += _chunkZKQSQSSMcjs.isText.call(void 0, c) ? c.text.length : 1;
610
+ n += _chunkPCSVBPORcjs.isText.call(void 0, c) ? c.text.length : 1;
576
611
  }
577
612
  return n + char;
578
613
  }
579
614
  function totalChars(children) {
580
- return children.reduce((a, c) => a + (_chunkZKQSQSSMcjs.isText.call(void 0, c) ? c.text.length : 1), 0);
615
+ return children.reduce((a, c) => a + (_chunkPCSVBPORcjs.isText.call(void 0, c) ? c.text.length : 1), 0);
581
616
  }
582
617
  function leafBlocksBetween(doc, fromBlock, toBlock) {
583
618
  const all = [];
584
- const walk3 = (node, path) => {
585
- if (!_chunkZKQSQSSMcjs.isElement.call(void 0, node))
619
+ const walk4 = (node, path) => {
620
+ if (!_chunkPCSVBPORcjs.isElement.call(void 0, node))
586
621
  return;
587
- if (node.children.every((c) => _chunkZKQSQSSMcjs.isText.call(void 0, c) || _chunkZKQSQSSMcjs.isInlineAtom.call(void 0, c)))
622
+ if (node.children.every((c) => _chunkPCSVBPORcjs.isText.call(void 0, c) || _chunkPCSVBPORcjs.isInlineAtom.call(void 0, c)))
588
623
  all.push({ path, node });
589
624
  else
590
- node.children.forEach((c, i) => walk3(c, path.concat(i)));
625
+ node.children.forEach((c, i) => walk4(c, path.concat(i)));
591
626
  };
592
- doc.children.forEach((c, i) => walk3(c, [i]));
627
+ doc.children.forEach((c, i) => walk4(c, [i]));
593
628
  const fi = all.findIndex((b) => cmpPath(b.path, fromBlock) === 0);
594
629
  const ti = all.findIndex((b) => cmpPath(b.path, toBlock) === 0);
595
630
  return fi < 0 || ti < 0 ? [] : all.slice(fi, ti + 1);
@@ -602,7 +637,7 @@ function markChars(block, from, to, mark) {
602
637
  const out = [];
603
638
  let pos = 0;
604
639
  for (const leaf of block.children) {
605
- if (!_chunkZKQSQSSMcjs.isText.call(void 0, leaf)) {
640
+ if (!_chunkPCSVBPORcjs.isText.call(void 0, leaf)) {
606
641
  out.push(leaf);
607
642
  pos += 1;
608
643
  continue;
@@ -627,7 +662,7 @@ function coalesce(nodes) {
627
662
  const out = [];
628
663
  for (const n of nodes) {
629
664
  const prev = out[out.length - 1];
630
- if (prev && _chunkZKQSQSSMcjs.isText.call(void 0, prev) && _chunkZKQSQSSMcjs.isText.call(void 0, n) && sameMarks(prev.marks, n.marks))
665
+ if (prev && _chunkPCSVBPORcjs.isText.call(void 0, prev) && _chunkPCSVBPORcjs.isText.call(void 0, n) && sameMarks(prev.marks, n.marks))
631
666
  out[out.length - 1] = { ...prev, text: prev.text + n.text };
632
667
  else
633
668
  out.push(n);
@@ -649,8 +684,8 @@ function rangeForDelete(doc, sel, dir) {
649
684
  return null;
650
685
  const char = path[path.length - 1];
651
686
  const leafPath = path.slice(0, -1);
652
- const leaf = _chunkTWD5T4YCcjs.nodeAt.call(void 0, doc, leafPath);
653
- if (!_chunkZKQSQSSMcjs.isText.call(void 0, leaf))
687
+ const leaf = _chunkHXABDVLZcjs.nodeAt.call(void 0, doc, leafPath);
688
+ if (!_chunkPCSVBPORcjs.isText.call(void 0, leaf))
654
689
  return null;
655
690
  if (dir === "backward") {
656
691
  if (char <= 0)
@@ -685,7 +720,7 @@ function rangeIsSuggestInsert(doc, sel) {
685
720
  continue;
686
721
  let pos = 0;
687
722
  for (const leaf of blk.node.children) {
688
- if (!_chunkZKQSQSSMcjs.isText.call(void 0, leaf)) {
723
+ if (!_chunkPCSVBPORcjs.isText.call(void 0, leaf)) {
689
724
  pos += 1;
690
725
  continue;
691
726
  }
@@ -694,7 +729,7 @@ function rangeIsSuggestInsert(doc, sel) {
694
729
  const hiC = Math.min(to, pos + len);
695
730
  if (loC < hiC) {
696
731
  any = true;
697
- const hasIns = (_nullishCoalesce(leaf.marks, () => ( []))).some((m) => m.name === "suggest" && _optionalChain([m, 'access', _36 => _36.attrs, 'optionalAccess', _37 => _37.kind]) !== "delete");
732
+ const hasIns = (_nullishCoalesce(leaf.marks, () => ( []))).some((m) => m.name === "suggest" && _optionalChain([m, 'access', _34 => _34.attrs, 'optionalAccess', _35 => _35.kind]) !== "delete");
698
733
  if (!hasIns)
699
734
  return false;
700
735
  }
@@ -725,6 +760,70 @@ function markSuggestRange(doc, sel, kind, id, author) {
725
760
  return steps;
726
761
  }
727
762
 
763
+ // src/tree/footnote.ts
764
+ function footnoteIndex(doc) {
765
+ const order = [];
766
+ const defs = /* @__PURE__ */ new Map();
767
+ const refs = /* @__PURE__ */ new Map();
768
+ const walk4 = (n) => {
769
+ if (_chunkPCSVBPORcjs.isText.call(void 0, n))
770
+ return;
771
+ if (n.type === "footnote_ref") {
772
+ const k = _chunkPCSVBPORcjs.footnoteKey.call(void 0, String(_nullishCoalesce(_optionalChain([n, 'access', _36 => _36.attrs, 'optionalAccess', _37 => _37.label]), () => ( ""))));
773
+ if (!refs.has(k))
774
+ order.push(k);
775
+ refs.set(k, (_nullishCoalesce(refs.get(k), () => ( 0))) + 1);
776
+ return;
777
+ }
778
+ if (_chunkPCSVBPORcjs.isFootnoteDef.call(void 0, n)) {
779
+ const k = _chunkPCSVBPORcjs.footnoteKey.call(void 0, String(_nullishCoalesce(_optionalChain([n, 'access', _38 => _38.attrs, 'optionalAccess', _39 => _39.footnote]), () => ( ""))));
780
+ if (!defs.has(k))
781
+ defs.set(k, n);
782
+ }
783
+ for (const c of n.children)
784
+ walk4(c);
785
+ };
786
+ walk4(doc);
787
+ return { order, defs, refs };
788
+ }
789
+ function footnoteText(def) {
790
+ const lines = [];
791
+ const walk4 = (n, acc) => {
792
+ if (_chunkPCSVBPORcjs.isText.call(void 0, n)) {
793
+ acc.push(n.text);
794
+ return;
795
+ }
796
+ if (n.type === "footnote_ref") {
797
+ acc.push(`[${String(_nullishCoalesce(_optionalChain([n, 'access', _40 => _40.attrs, 'optionalAccess', _41 => _41.label]), () => ( "")))}]`);
798
+ return;
799
+ }
800
+ if (_chunkPCSVBPORcjs.isElement.call(void 0, n) && n.children.length && n.children.every((c) => _chunkPCSVBPORcjs.isText.call(void 0, c) || _chunkPCSVBPORcjs.isElement.call(void 0, c) && c.children.length === 0)) {
801
+ const line = [];
802
+ for (const c of n.children)
803
+ walk4(c, line);
804
+ lines.push(line.join(""));
805
+ return;
806
+ }
807
+ for (const c of n.children)
808
+ walk4(c, acc);
809
+ };
810
+ for (const c of def.children)
811
+ walk4(c, lines);
812
+ return lines.join("\n").trim();
813
+ }
814
+ function hasFootnotes(doc) {
815
+ const walk4 = (n) => !_chunkPCSVBPORcjs.isText.call(void 0, n) && (n.type === "footnote_ref" || _chunkPCSVBPORcjs.isFootnoteDef.call(void 0, n) || n.children.some(walk4));
816
+ return walk4(doc);
817
+ }
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
728
827
 
729
828
 
730
829
 
@@ -756,4 +855,4 @@ function markSuggestRange(doc, sel, kind, id, author) {
756
855
 
757
856
 
758
857
 
759
- exports.init = init; exports.commit = commit; exports.applyForeign = applyForeign; exports.amend = amend; exports.undo = undo; exports.redo = redo; exports.invariants = invariants; exports.firstViolation = firstViolation; exports.outline = outline; exports.commentIdsInDoc = commentIdsInDoc; exports.stripCommentMarks = stripCommentMarks; exports.findText = findText; exports.replaceMatch = replaceMatch; exports.replaceAll = replaceAll; exports.applyReplaceAll = applyReplaceAll; exports.snapshotDoc = snapshotDoc; exports.pushVersion = pushVersion; exports.getVersion = getVersion; exports.removeVersion = removeVersion; exports.suggestMark = suggestMark; exports.isSuggestMark = isSuggestMark; exports.suggestIdsInDoc = suggestIdsInDoc; exports.listSuggestions = listSuggestions; exports.stripSuggestMarks = stripSuggestMarks; exports.dropSuggestText = dropSuggestText; exports.acceptSuggestion = acceptSuggestion; exports.rejectSuggestion = rejectSuggestion; exports.rangeForDelete = rangeForDelete; exports.rangeIsSuggestInsert = rangeIsSuggestInsert; exports.markSuggestRange = markSuggestRange;
858
+ exports.init = init; exports.commit = commit; exports.applyForeign = applyForeign; exports.amend = amend; exports.undo = undo; exports.redo = redo; exports.invariants = invariants; exports.firstViolation = firstViolation; exports.wordCount = wordCount; exports.outline = outline; exports.markIdsInDoc = markIdsInDoc; exports.mapLeafBlocks = mapLeafBlocks; exports.stripMarks = stripMarks; exports.dropMarkedLeaves = dropMarkedLeaves; exports.commentIdsInDoc = commentIdsInDoc; exports.stripCommentMarks = stripCommentMarks; exports.findText = findText; exports.replaceMatch = replaceMatch; exports.replaceAll = replaceAll; exports.applyReplaceAll = applyReplaceAll; exports.snapshotDoc = snapshotDoc; exports.pushVersion = pushVersion; exports.getVersion = getVersion; exports.removeVersion = removeVersion; exports.suggestMark = suggestMark; exports.isSuggestMark = isSuggestMark; exports.suggestIdsInDoc = suggestIdsInDoc; exports.listSuggestions = listSuggestions; exports.stripSuggestMarks = stripSuggestMarks; exports.dropSuggestText = dropSuggestText; exports.acceptSuggestion = acceptSuggestion; exports.rejectSuggestion = rejectSuggestion; exports.rangeForDelete = rangeForDelete; exports.rangeIsSuggestInsert = rangeIsSuggestInsert; exports.markSuggestRange = markSuggestRange; exports.footnoteIndex = footnoteIndex; exports.footnoteText = footnoteText; exports.hasFootnotes = hasFootnotes;