prosekit 0.0.0-next-20230627094841

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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/basic/style.css +133 -0
  4. package/dist/chunk-23S3SZFA.js +46 -0
  5. package/dist/chunk-2MVHS73Q.js +709 -0
  6. package/dist/chunk-4GDRVRDP.js +0 -0
  7. package/dist/chunk-5PFF57NB.js +1546 -0
  8. package/dist/chunk-6A2XHVFY.js +46 -0
  9. package/dist/chunk-7OYIOTDD.js +16472 -0
  10. package/dist/chunk-ARJTWYPA.js +1321 -0
  11. package/dist/chunk-CDGN4JUS.js +1546 -0
  12. package/dist/chunk-CG5B6PMC.js +973 -0
  13. package/dist/chunk-DDN3TFRH.js +185 -0
  14. package/dist/chunk-EQV3CWHZ.js +2213 -0
  15. package/dist/chunk-ERNIDFFW.js +1711 -0
  16. package/dist/chunk-FAVXZAF7.js +3279 -0
  17. package/dist/chunk-HSPTUO6P.js +53 -0
  18. package/dist/chunk-JMNJUDT7.js +165 -0
  19. package/dist/chunk-LXCCO2LO.js +52 -0
  20. package/dist/chunk-MIPON3OH.js +922 -0
  21. package/dist/chunk-NAWSCY5F.js +166 -0
  22. package/dist/chunk-S64NFSV2.js +236 -0
  23. package/dist/chunk-S65R2BUY.js +15 -0
  24. package/dist/chunk-T2V5UU6H.js +204 -0
  25. package/dist/chunk-TWIMWRRZ.js +57 -0
  26. package/dist/chunk-US2P3K6I.js +185 -0
  27. package/dist/chunk-UTNVEPBA.js +950 -0
  28. package/dist/chunk-UWHQRU5N.js +4883 -0
  29. package/dist/chunk-VIKPJJET.js +662 -0
  30. package/dist/chunk-WAMZOD5I.js +67 -0
  31. package/dist/chunk-YUY5I2TY.js +236 -0
  32. package/dist/core/style.css +54 -0
  33. package/dist/extension-list/style.css +78 -0
  34. package/dist/pm/view/style/prosemirror.css +52 -0
  35. package/dist/prosekit-basic.js +2 -0
  36. package/dist/prosekit-core.js +2 -0
  37. package/dist/prosekit-extension-blockquote.js +2 -0
  38. package/dist/prosekit-extension-bold.js +2 -0
  39. package/dist/prosekit-extension-code-block.js +2 -0
  40. package/dist/prosekit-extension-code.js +2 -0
  41. package/dist/prosekit-extension-heading.js +2 -0
  42. package/dist/prosekit-extension-horizontal-rule.js +2 -0
  43. package/dist/prosekit-extension-italic.js +2 -0
  44. package/dist/prosekit-extension-list.js +2 -0
  45. package/dist/prosekit-extension-suggestion.js +2 -0
  46. package/dist/prosekit-lit-elements-menu-item.js +2 -0
  47. package/dist/prosekit-lit-elements-menu.js +2 -0
  48. package/dist/prosekit-lit-elements-popover.js +2 -0
  49. package/dist/prosekit-lit.js +2 -0
  50. package/dist/prosekit-pm-commands.js +2 -0
  51. package/dist/prosekit-pm-inputrules.js +2 -0
  52. package/dist/prosekit-pm-keymap.js +2 -0
  53. package/dist/prosekit-pm-model.js +2 -0
  54. package/dist/prosekit-pm-state.js +2 -0
  55. package/dist/prosekit-pm-transform.js +2 -0
  56. package/dist/prosekit-pm-view.js +2 -0
  57. package/dist/prosekit-pm.js +2 -0
  58. package/dist/prosekit-react-components-menu-item.js +2 -0
  59. package/dist/prosekit-react-components-menu.js +2 -0
  60. package/dist/prosekit-react-components-popover-suggestion.js +2 -0
  61. package/dist/prosekit-react-components-popover.js +2 -0
  62. package/dist/prosekit-react.js +2 -0
  63. package/dist/prosekit-vue-components-menu-item.js +2 -0
  64. package/dist/prosekit-vue-components-menu.js +2 -0
  65. package/dist/prosekit-vue-components-popover-suggestion.js +2 -0
  66. package/dist/prosekit-vue-components-popover.js +2 -0
  67. package/dist/prosekit-vue.js +2 -0
  68. package/dist/prosekit.js +0 -0
  69. package/package.json +262 -0
  70. package/src/index.ts +1 -0
@@ -0,0 +1,3279 @@
1
+ // ../../node_modules/.pnpm/orderedmap@2.1.1/node_modules/orderedmap/dist/index.js
2
+ function OrderedMap(content) {
3
+ this.content = content;
4
+ }
5
+ OrderedMap.prototype = {
6
+ constructor: OrderedMap,
7
+ find: function(key) {
8
+ for (var i = 0; i < this.content.length; i += 2)
9
+ if (this.content[i] === key)
10
+ return i;
11
+ return -1;
12
+ },
13
+ // :: (string) → ?any
14
+ // Retrieve the value stored under `key`, or return undefined when
15
+ // no such key exists.
16
+ get: function(key) {
17
+ var found2 = this.find(key);
18
+ return found2 == -1 ? void 0 : this.content[found2 + 1];
19
+ },
20
+ // :: (string, any, ?string) → OrderedMap
21
+ // Create a new map by replacing the value of `key` with a new
22
+ // value, or adding a binding to the end of the map. If `newKey` is
23
+ // given, the key of the binding will be replaced with that key.
24
+ update: function(key, value, newKey) {
25
+ var self = newKey && newKey != key ? this.remove(newKey) : this;
26
+ var found2 = self.find(key), content = self.content.slice();
27
+ if (found2 == -1) {
28
+ content.push(newKey || key, value);
29
+ } else {
30
+ content[found2 + 1] = value;
31
+ if (newKey)
32
+ content[found2] = newKey;
33
+ }
34
+ return new OrderedMap(content);
35
+ },
36
+ // :: (string) → OrderedMap
37
+ // Return a map with the given key removed, if it existed.
38
+ remove: function(key) {
39
+ var found2 = this.find(key);
40
+ if (found2 == -1)
41
+ return this;
42
+ var content = this.content.slice();
43
+ content.splice(found2, 2);
44
+ return new OrderedMap(content);
45
+ },
46
+ // :: (string, any) → OrderedMap
47
+ // Add a new key to the start of the map.
48
+ addToStart: function(key, value) {
49
+ return new OrderedMap([key, value].concat(this.remove(key).content));
50
+ },
51
+ // :: (string, any) → OrderedMap
52
+ // Add a new key to the end of the map.
53
+ addToEnd: function(key, value) {
54
+ var content = this.remove(key).content.slice();
55
+ content.push(key, value);
56
+ return new OrderedMap(content);
57
+ },
58
+ // :: (string, string, any) → OrderedMap
59
+ // Add a key after the given key. If `place` is not found, the new
60
+ // key is added to the end.
61
+ addBefore: function(place, key, value) {
62
+ var without = this.remove(key), content = without.content.slice();
63
+ var found2 = without.find(place);
64
+ content.splice(found2 == -1 ? content.length : found2, 0, key, value);
65
+ return new OrderedMap(content);
66
+ },
67
+ // :: ((key: string, value: any))
68
+ // Call the given function for each key/value pair in the map, in
69
+ // order.
70
+ forEach: function(f) {
71
+ for (var i = 0; i < this.content.length; i += 2)
72
+ f(this.content[i], this.content[i + 1]);
73
+ },
74
+ // :: (union<Object, OrderedMap>) → OrderedMap
75
+ // Create a new map by prepending the keys in this map that don't
76
+ // appear in `map` before the keys in `map`.
77
+ prepend: function(map) {
78
+ map = OrderedMap.from(map);
79
+ if (!map.size)
80
+ return this;
81
+ return new OrderedMap(map.content.concat(this.subtract(map).content));
82
+ },
83
+ // :: (union<Object, OrderedMap>) → OrderedMap
84
+ // Create a new map by appending the keys in this map that don't
85
+ // appear in `map` after the keys in `map`.
86
+ append: function(map) {
87
+ map = OrderedMap.from(map);
88
+ if (!map.size)
89
+ return this;
90
+ return new OrderedMap(this.subtract(map).content.concat(map.content));
91
+ },
92
+ // :: (union<Object, OrderedMap>) → OrderedMap
93
+ // Create a map containing all the keys in this map that don't
94
+ // appear in `map`.
95
+ subtract: function(map) {
96
+ var result = this;
97
+ map = OrderedMap.from(map);
98
+ for (var i = 0; i < map.content.length; i += 2)
99
+ result = result.remove(map.content[i]);
100
+ return result;
101
+ },
102
+ // :: () → Object
103
+ // Turn ordered map into a plain object.
104
+ toObject: function() {
105
+ var result = {};
106
+ this.forEach(function(key, value) {
107
+ result[key] = value;
108
+ });
109
+ return result;
110
+ },
111
+ // :: number
112
+ // The amount of keys in this map.
113
+ get size() {
114
+ return this.content.length >> 1;
115
+ }
116
+ };
117
+ OrderedMap.from = function(value) {
118
+ if (value instanceof OrderedMap)
119
+ return value;
120
+ var content = [];
121
+ if (value)
122
+ for (var prop in value)
123
+ content.push(prop, value[prop]);
124
+ return new OrderedMap(content);
125
+ };
126
+ var dist_default = OrderedMap;
127
+
128
+ // ../../node_modules/.pnpm/prosemirror-model@1.19.2/node_modules/prosemirror-model/dist/index.js
129
+ function findDiffStart(a, b, pos) {
130
+ for (let i = 0; ; i++) {
131
+ if (i == a.childCount || i == b.childCount)
132
+ return a.childCount == b.childCount ? null : pos;
133
+ let childA = a.child(i), childB = b.child(i);
134
+ if (childA == childB) {
135
+ pos += childA.nodeSize;
136
+ continue;
137
+ }
138
+ if (!childA.sameMarkup(childB))
139
+ return pos;
140
+ if (childA.isText && childA.text != childB.text) {
141
+ for (let j = 0; childA.text[j] == childB.text[j]; j++)
142
+ pos++;
143
+ return pos;
144
+ }
145
+ if (childA.content.size || childB.content.size) {
146
+ let inner = findDiffStart(childA.content, childB.content, pos + 1);
147
+ if (inner != null)
148
+ return inner;
149
+ }
150
+ pos += childA.nodeSize;
151
+ }
152
+ }
153
+ function findDiffEnd(a, b, posA, posB) {
154
+ for (let iA = a.childCount, iB = b.childCount; ; ) {
155
+ if (iA == 0 || iB == 0)
156
+ return iA == iB ? null : { a: posA, b: posB };
157
+ let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;
158
+ if (childA == childB) {
159
+ posA -= size;
160
+ posB -= size;
161
+ continue;
162
+ }
163
+ if (!childA.sameMarkup(childB))
164
+ return { a: posA, b: posB };
165
+ if (childA.isText && childA.text != childB.text) {
166
+ let same = 0, minSize = Math.min(childA.text.length, childB.text.length);
167
+ while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {
168
+ same++;
169
+ posA--;
170
+ posB--;
171
+ }
172
+ return { a: posA, b: posB };
173
+ }
174
+ if (childA.content.size || childB.content.size) {
175
+ let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);
176
+ if (inner)
177
+ return inner;
178
+ }
179
+ posA -= size;
180
+ posB -= size;
181
+ }
182
+ }
183
+ var Fragment = class _Fragment {
184
+ /**
185
+ @internal
186
+ */
187
+ constructor(content, size) {
188
+ this.content = content;
189
+ this.size = size || 0;
190
+ if (size == null)
191
+ for (let i = 0; i < content.length; i++)
192
+ this.size += content[i].nodeSize;
193
+ }
194
+ /**
195
+ Invoke a callback for all descendant nodes between the given two
196
+ positions (relative to start of this fragment). Doesn't descend
197
+ into a node when the callback returns `false`.
198
+ */
199
+ nodesBetween(from, to, f, nodeStart = 0, parent) {
200
+ for (let i = 0, pos = 0; pos < to; i++) {
201
+ let child = this.content[i], end = pos + child.nodeSize;
202
+ if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {
203
+ let start = pos + 1;
204
+ child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);
205
+ }
206
+ pos = end;
207
+ }
208
+ }
209
+ /**
210
+ Call the given callback for every descendant node. `pos` will be
211
+ relative to the start of the fragment. The callback may return
212
+ `false` to prevent traversal of a given node's children.
213
+ */
214
+ descendants(f) {
215
+ this.nodesBetween(0, this.size, f);
216
+ }
217
+ /**
218
+ Extract the text between `from` and `to`. See the same method on
219
+ [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
220
+ */
221
+ textBetween(from, to, blockSeparator, leafText) {
222
+ let text = "", separated = true;
223
+ this.nodesBetween(from, to, (node, pos) => {
224
+ if (node.isText) {
225
+ text += node.text.slice(Math.max(from, pos) - pos, to - pos);
226
+ separated = !blockSeparator;
227
+ } else if (node.isLeaf) {
228
+ if (leafText) {
229
+ text += typeof leafText === "function" ? leafText(node) : leafText;
230
+ } else if (node.type.spec.leafText) {
231
+ text += node.type.spec.leafText(node);
232
+ }
233
+ separated = !blockSeparator;
234
+ } else if (!separated && node.isBlock) {
235
+ text += blockSeparator;
236
+ separated = true;
237
+ }
238
+ }, 0);
239
+ return text;
240
+ }
241
+ /**
242
+ Create a new fragment containing the combined content of this
243
+ fragment and the other.
244
+ */
245
+ append(other) {
246
+ if (!other.size)
247
+ return this;
248
+ if (!this.size)
249
+ return other;
250
+ let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;
251
+ if (last.isText && last.sameMarkup(first)) {
252
+ content[content.length - 1] = last.withText(last.text + first.text);
253
+ i = 1;
254
+ }
255
+ for (; i < other.content.length; i++)
256
+ content.push(other.content[i]);
257
+ return new _Fragment(content, this.size + other.size);
258
+ }
259
+ /**
260
+ Cut out the sub-fragment between the two given positions.
261
+ */
262
+ cut(from, to = this.size) {
263
+ if (from == 0 && to == this.size)
264
+ return this;
265
+ let result = [], size = 0;
266
+ if (to > from)
267
+ for (let i = 0, pos = 0; pos < to; i++) {
268
+ let child = this.content[i], end = pos + child.nodeSize;
269
+ if (end > from) {
270
+ if (pos < from || end > to) {
271
+ if (child.isText)
272
+ child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));
273
+ else
274
+ child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));
275
+ }
276
+ result.push(child);
277
+ size += child.nodeSize;
278
+ }
279
+ pos = end;
280
+ }
281
+ return new _Fragment(result, size);
282
+ }
283
+ /**
284
+ @internal
285
+ */
286
+ cutByIndex(from, to) {
287
+ if (from == to)
288
+ return _Fragment.empty;
289
+ if (from == 0 && to == this.content.length)
290
+ return this;
291
+ return new _Fragment(this.content.slice(from, to));
292
+ }
293
+ /**
294
+ Create a new fragment in which the node at the given index is
295
+ replaced by the given node.
296
+ */
297
+ replaceChild(index, node) {
298
+ let current = this.content[index];
299
+ if (current == node)
300
+ return this;
301
+ let copy2 = this.content.slice();
302
+ let size = this.size + node.nodeSize - current.nodeSize;
303
+ copy2[index] = node;
304
+ return new _Fragment(copy2, size);
305
+ }
306
+ /**
307
+ Create a new fragment by prepending the given node to this
308
+ fragment.
309
+ */
310
+ addToStart(node) {
311
+ return new _Fragment([node].concat(this.content), this.size + node.nodeSize);
312
+ }
313
+ /**
314
+ Create a new fragment by appending the given node to this
315
+ fragment.
316
+ */
317
+ addToEnd(node) {
318
+ return new _Fragment(this.content.concat(node), this.size + node.nodeSize);
319
+ }
320
+ /**
321
+ Compare this fragment to another one.
322
+ */
323
+ eq(other) {
324
+ if (this.content.length != other.content.length)
325
+ return false;
326
+ for (let i = 0; i < this.content.length; i++)
327
+ if (!this.content[i].eq(other.content[i]))
328
+ return false;
329
+ return true;
330
+ }
331
+ /**
332
+ The first child of the fragment, or `null` if it is empty.
333
+ */
334
+ get firstChild() {
335
+ return this.content.length ? this.content[0] : null;
336
+ }
337
+ /**
338
+ The last child of the fragment, or `null` if it is empty.
339
+ */
340
+ get lastChild() {
341
+ return this.content.length ? this.content[this.content.length - 1] : null;
342
+ }
343
+ /**
344
+ The number of child nodes in this fragment.
345
+ */
346
+ get childCount() {
347
+ return this.content.length;
348
+ }
349
+ /**
350
+ Get the child node at the given index. Raise an error when the
351
+ index is out of range.
352
+ */
353
+ child(index) {
354
+ let found2 = this.content[index];
355
+ if (!found2)
356
+ throw new RangeError("Index " + index + " out of range for " + this);
357
+ return found2;
358
+ }
359
+ /**
360
+ Get the child node at the given index, if it exists.
361
+ */
362
+ maybeChild(index) {
363
+ return this.content[index] || null;
364
+ }
365
+ /**
366
+ Call `f` for every child node, passing the node, its offset
367
+ into this parent node, and its index.
368
+ */
369
+ forEach(f) {
370
+ for (let i = 0, p = 0; i < this.content.length; i++) {
371
+ let child = this.content[i];
372
+ f(child, p, i);
373
+ p += child.nodeSize;
374
+ }
375
+ }
376
+ /**
377
+ Find the first position at which this fragment and another
378
+ fragment differ, or `null` if they are the same.
379
+ */
380
+ findDiffStart(other, pos = 0) {
381
+ return findDiffStart(this, other, pos);
382
+ }
383
+ /**
384
+ Find the first position, searching from the end, at which this
385
+ fragment and the given fragment differ, or `null` if they are
386
+ the same. Since this position will not be the same in both
387
+ nodes, an object with two separate positions is returned.
388
+ */
389
+ findDiffEnd(other, pos = this.size, otherPos = other.size) {
390
+ return findDiffEnd(this, other, pos, otherPos);
391
+ }
392
+ /**
393
+ Find the index and inner offset corresponding to a given relative
394
+ position in this fragment. The result object will be reused
395
+ (overwritten) the next time the function is called. (Not public.)
396
+ */
397
+ findIndex(pos, round = -1) {
398
+ if (pos == 0)
399
+ return retIndex(0, pos);
400
+ if (pos == this.size)
401
+ return retIndex(this.content.length, pos);
402
+ if (pos > this.size || pos < 0)
403
+ throw new RangeError(`Position ${pos} outside of fragment (${this})`);
404
+ for (let i = 0, curPos = 0; ; i++) {
405
+ let cur = this.child(i), end = curPos + cur.nodeSize;
406
+ if (end >= pos) {
407
+ if (end == pos || round > 0)
408
+ return retIndex(i + 1, end);
409
+ return retIndex(i, curPos);
410
+ }
411
+ curPos = end;
412
+ }
413
+ }
414
+ /**
415
+ Return a debugging string that describes this fragment.
416
+ */
417
+ toString() {
418
+ return "<" + this.toStringInner() + ">";
419
+ }
420
+ /**
421
+ @internal
422
+ */
423
+ toStringInner() {
424
+ return this.content.join(", ");
425
+ }
426
+ /**
427
+ Create a JSON-serializeable representation of this fragment.
428
+ */
429
+ toJSON() {
430
+ return this.content.length ? this.content.map((n) => n.toJSON()) : null;
431
+ }
432
+ /**
433
+ Deserialize a fragment from its JSON representation.
434
+ */
435
+ static fromJSON(schema, value) {
436
+ if (!value)
437
+ return _Fragment.empty;
438
+ if (!Array.isArray(value))
439
+ throw new RangeError("Invalid input for Fragment.fromJSON");
440
+ return new _Fragment(value.map(schema.nodeFromJSON));
441
+ }
442
+ /**
443
+ Build a fragment from an array of nodes. Ensures that adjacent
444
+ text nodes with the same marks are joined together.
445
+ */
446
+ static fromArray(array) {
447
+ if (!array.length)
448
+ return _Fragment.empty;
449
+ let joined, size = 0;
450
+ for (let i = 0; i < array.length; i++) {
451
+ let node = array[i];
452
+ size += node.nodeSize;
453
+ if (i && node.isText && array[i - 1].sameMarkup(node)) {
454
+ if (!joined)
455
+ joined = array.slice(0, i);
456
+ joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text);
457
+ } else if (joined) {
458
+ joined.push(node);
459
+ }
460
+ }
461
+ return new _Fragment(joined || array, size);
462
+ }
463
+ /**
464
+ Create a fragment from something that can be interpreted as a
465
+ set of nodes. For `null`, it returns the empty fragment. For a
466
+ fragment, the fragment itself. For a node or array of nodes, a
467
+ fragment containing those nodes.
468
+ */
469
+ static from(nodes) {
470
+ if (!nodes)
471
+ return _Fragment.empty;
472
+ if (nodes instanceof _Fragment)
473
+ return nodes;
474
+ if (Array.isArray(nodes))
475
+ return this.fromArray(nodes);
476
+ if (nodes.attrs)
477
+ return new _Fragment([nodes], nodes.nodeSize);
478
+ throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
479
+ }
480
+ };
481
+ Fragment.empty = new Fragment([], 0);
482
+ var found = { index: 0, offset: 0 };
483
+ function retIndex(index, offset) {
484
+ found.index = index;
485
+ found.offset = offset;
486
+ return found;
487
+ }
488
+ function compareDeep(a, b) {
489
+ if (a === b)
490
+ return true;
491
+ if (!(a && typeof a == "object") || !(b && typeof b == "object"))
492
+ return false;
493
+ let array = Array.isArray(a);
494
+ if (Array.isArray(b) != array)
495
+ return false;
496
+ if (array) {
497
+ if (a.length != b.length)
498
+ return false;
499
+ for (let i = 0; i < a.length; i++)
500
+ if (!compareDeep(a[i], b[i]))
501
+ return false;
502
+ } else {
503
+ for (let p in a)
504
+ if (!(p in b) || !compareDeep(a[p], b[p]))
505
+ return false;
506
+ for (let p in b)
507
+ if (!(p in a))
508
+ return false;
509
+ }
510
+ return true;
511
+ }
512
+ var Mark = class _Mark {
513
+ /**
514
+ @internal
515
+ */
516
+ constructor(type, attrs) {
517
+ this.type = type;
518
+ this.attrs = attrs;
519
+ }
520
+ /**
521
+ Given a set of marks, create a new set which contains this one as
522
+ well, in the right position. If this mark is already in the set,
523
+ the set itself is returned. If any marks that are set to be
524
+ [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
525
+ those are replaced by this one.
526
+ */
527
+ addToSet(set) {
528
+ let copy2, placed = false;
529
+ for (let i = 0; i < set.length; i++) {
530
+ let other = set[i];
531
+ if (this.eq(other))
532
+ return set;
533
+ if (this.type.excludes(other.type)) {
534
+ if (!copy2)
535
+ copy2 = set.slice(0, i);
536
+ } else if (other.type.excludes(this.type)) {
537
+ return set;
538
+ } else {
539
+ if (!placed && other.type.rank > this.type.rank) {
540
+ if (!copy2)
541
+ copy2 = set.slice(0, i);
542
+ copy2.push(this);
543
+ placed = true;
544
+ }
545
+ if (copy2)
546
+ copy2.push(other);
547
+ }
548
+ }
549
+ if (!copy2)
550
+ copy2 = set.slice();
551
+ if (!placed)
552
+ copy2.push(this);
553
+ return copy2;
554
+ }
555
+ /**
556
+ Remove this mark from the given set, returning a new set. If this
557
+ mark is not in the set, the set itself is returned.
558
+ */
559
+ removeFromSet(set) {
560
+ for (let i = 0; i < set.length; i++)
561
+ if (this.eq(set[i]))
562
+ return set.slice(0, i).concat(set.slice(i + 1));
563
+ return set;
564
+ }
565
+ /**
566
+ Test whether this mark is in the given set of marks.
567
+ */
568
+ isInSet(set) {
569
+ for (let i = 0; i < set.length; i++)
570
+ if (this.eq(set[i]))
571
+ return true;
572
+ return false;
573
+ }
574
+ /**
575
+ Test whether this mark has the same type and attributes as
576
+ another mark.
577
+ */
578
+ eq(other) {
579
+ return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs);
580
+ }
581
+ /**
582
+ Convert this mark to a JSON-serializeable representation.
583
+ */
584
+ toJSON() {
585
+ let obj = { type: this.type.name };
586
+ for (let _ in this.attrs) {
587
+ obj.attrs = this.attrs;
588
+ break;
589
+ }
590
+ return obj;
591
+ }
592
+ /**
593
+ Deserialize a mark from JSON.
594
+ */
595
+ static fromJSON(schema, json) {
596
+ if (!json)
597
+ throw new RangeError("Invalid input for Mark.fromJSON");
598
+ let type = schema.marks[json.type];
599
+ if (!type)
600
+ throw new RangeError(`There is no mark type ${json.type} in this schema`);
601
+ return type.create(json.attrs);
602
+ }
603
+ /**
604
+ Test whether two sets of marks are identical.
605
+ */
606
+ static sameSet(a, b) {
607
+ if (a == b)
608
+ return true;
609
+ if (a.length != b.length)
610
+ return false;
611
+ for (let i = 0; i < a.length; i++)
612
+ if (!a[i].eq(b[i]))
613
+ return false;
614
+ return true;
615
+ }
616
+ /**
617
+ Create a properly sorted mark set from null, a single mark, or an
618
+ unsorted array of marks.
619
+ */
620
+ static setFrom(marks) {
621
+ if (!marks || Array.isArray(marks) && marks.length == 0)
622
+ return _Mark.none;
623
+ if (marks instanceof _Mark)
624
+ return [marks];
625
+ let copy2 = marks.slice();
626
+ copy2.sort((a, b) => a.type.rank - b.type.rank);
627
+ return copy2;
628
+ }
629
+ };
630
+ Mark.none = [];
631
+ var ReplaceError = class extends Error {
632
+ };
633
+ var Slice = class _Slice {
634
+ /**
635
+ Create a slice. When specifying a non-zero open depth, you must
636
+ make sure that there are nodes of at least that depth at the
637
+ appropriate side of the fragment—i.e. if the fragment is an
638
+ empty paragraph node, `openStart` and `openEnd` can't be greater
639
+ than 1.
640
+
641
+ It is not necessary for the content of open nodes to conform to
642
+ the schema's content constraints, though it should be a valid
643
+ start/end/middle for such a node, depending on which sides are
644
+ open.
645
+ */
646
+ constructor(content, openStart, openEnd) {
647
+ this.content = content;
648
+ this.openStart = openStart;
649
+ this.openEnd = openEnd;
650
+ }
651
+ /**
652
+ The size this slice would add when inserted into a document.
653
+ */
654
+ get size() {
655
+ return this.content.size - this.openStart - this.openEnd;
656
+ }
657
+ /**
658
+ @internal
659
+ */
660
+ insertAt(pos, fragment) {
661
+ let content = insertInto(this.content, pos + this.openStart, fragment);
662
+ return content && new _Slice(content, this.openStart, this.openEnd);
663
+ }
664
+ /**
665
+ @internal
666
+ */
667
+ removeBetween(from, to) {
668
+ return new _Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);
669
+ }
670
+ /**
671
+ Tests whether this slice is equal to another slice.
672
+ */
673
+ eq(other) {
674
+ return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;
675
+ }
676
+ /**
677
+ @internal
678
+ */
679
+ toString() {
680
+ return this.content + "(" + this.openStart + "," + this.openEnd + ")";
681
+ }
682
+ /**
683
+ Convert a slice to a JSON-serializable representation.
684
+ */
685
+ toJSON() {
686
+ if (!this.content.size)
687
+ return null;
688
+ let json = { content: this.content.toJSON() };
689
+ if (this.openStart > 0)
690
+ json.openStart = this.openStart;
691
+ if (this.openEnd > 0)
692
+ json.openEnd = this.openEnd;
693
+ return json;
694
+ }
695
+ /**
696
+ Deserialize a slice from its JSON representation.
697
+ */
698
+ static fromJSON(schema, json) {
699
+ if (!json)
700
+ return _Slice.empty;
701
+ let openStart = json.openStart || 0, openEnd = json.openEnd || 0;
702
+ if (typeof openStart != "number" || typeof openEnd != "number")
703
+ throw new RangeError("Invalid input for Slice.fromJSON");
704
+ return new _Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd);
705
+ }
706
+ /**
707
+ Create a slice from a fragment by taking the maximum possible
708
+ open value on both side of the fragment.
709
+ */
710
+ static maxOpen(fragment, openIsolating = true) {
711
+ let openStart = 0, openEnd = 0;
712
+ for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild)
713
+ openStart++;
714
+ for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild)
715
+ openEnd++;
716
+ return new _Slice(fragment, openStart, openEnd);
717
+ }
718
+ };
719
+ Slice.empty = new Slice(Fragment.empty, 0, 0);
720
+ function removeRange(content, from, to) {
721
+ let { index, offset } = content.findIndex(from), child = content.maybeChild(index);
722
+ let { index: indexTo, offset: offsetTo } = content.findIndex(to);
723
+ if (offset == from || child.isText) {
724
+ if (offsetTo != to && !content.child(indexTo).isText)
725
+ throw new RangeError("Removing non-flat range");
726
+ return content.cut(0, from).append(content.cut(to));
727
+ }
728
+ if (index != indexTo)
729
+ throw new RangeError("Removing non-flat range");
730
+ return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
731
+ }
732
+ function insertInto(content, dist, insert, parent) {
733
+ let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
734
+ if (offset == dist || child.isText) {
735
+ if (parent && !parent.canReplace(index, index, insert))
736
+ return null;
737
+ return content.cut(0, dist).append(insert).append(content.cut(dist));
738
+ }
739
+ let inner = insertInto(child.content, dist - offset - 1, insert);
740
+ return inner && content.replaceChild(index, child.copy(inner));
741
+ }
742
+ function replace($from, $to, slice) {
743
+ if (slice.openStart > $from.depth)
744
+ throw new ReplaceError("Inserted content deeper than insertion position");
745
+ if ($from.depth - slice.openStart != $to.depth - slice.openEnd)
746
+ throw new ReplaceError("Inconsistent open depths");
747
+ return replaceOuter($from, $to, slice, 0);
748
+ }
749
+ function replaceOuter($from, $to, slice, depth) {
750
+ let index = $from.index(depth), node = $from.node(depth);
751
+ if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {
752
+ let inner = replaceOuter($from, $to, slice, depth + 1);
753
+ return node.copy(node.content.replaceChild(index, inner));
754
+ } else if (!slice.content.size) {
755
+ return close(node, replaceTwoWay($from, $to, depth));
756
+ } else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) {
757
+ let parent = $from.parent, content = parent.content;
758
+ return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));
759
+ } else {
760
+ let { start, end } = prepareSliceForReplace(slice, $from);
761
+ return close(node, replaceThreeWay($from, start, end, $to, depth));
762
+ }
763
+ }
764
+ function checkJoin(main, sub) {
765
+ if (!sub.type.compatibleContent(main.type))
766
+ throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
767
+ }
768
+ function joinable($before, $after, depth) {
769
+ let node = $before.node(depth);
770
+ checkJoin(node, $after.node(depth));
771
+ return node;
772
+ }
773
+ function addNode(child, target) {
774
+ let last = target.length - 1;
775
+ if (last >= 0 && child.isText && child.sameMarkup(target[last]))
776
+ target[last] = child.withText(target[last].text + child.text);
777
+ else
778
+ target.push(child);
779
+ }
780
+ function addRange($start, $end, depth, target) {
781
+ let node = ($end || $start).node(depth);
782
+ let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;
783
+ if ($start) {
784
+ startIndex = $start.index(depth);
785
+ if ($start.depth > depth) {
786
+ startIndex++;
787
+ } else if ($start.textOffset) {
788
+ addNode($start.nodeAfter, target);
789
+ startIndex++;
790
+ }
791
+ }
792
+ for (let i = startIndex; i < endIndex; i++)
793
+ addNode(node.child(i), target);
794
+ if ($end && $end.depth == depth && $end.textOffset)
795
+ addNode($end.nodeBefore, target);
796
+ }
797
+ function close(node, content) {
798
+ node.type.checkContent(content);
799
+ return node.copy(content);
800
+ }
801
+ function replaceThreeWay($from, $start, $end, $to, depth) {
802
+ let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
803
+ let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
804
+ let content = [];
805
+ addRange(null, $from, depth, content);
806
+ if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
807
+ checkJoin(openStart, openEnd);
808
+ addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);
809
+ } else {
810
+ if (openStart)
811
+ addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);
812
+ addRange($start, $end, depth, content);
813
+ if (openEnd)
814
+ addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);
815
+ }
816
+ addRange($to, null, depth, content);
817
+ return new Fragment(content);
818
+ }
819
+ function replaceTwoWay($from, $to, depth) {
820
+ let content = [];
821
+ addRange(null, $from, depth, content);
822
+ if ($from.depth > depth) {
823
+ let type = joinable($from, $to, depth + 1);
824
+ addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);
825
+ }
826
+ addRange($to, null, depth, content);
827
+ return new Fragment(content);
828
+ }
829
+ function prepareSliceForReplace(slice, $along) {
830
+ let extra = $along.depth - slice.openStart, parent = $along.node(extra);
831
+ let node = parent.copy(slice.content);
832
+ for (let i = extra - 1; i >= 0; i--)
833
+ node = $along.node(i).copy(Fragment.from(node));
834
+ return {
835
+ start: node.resolveNoCache(slice.openStart + extra),
836
+ end: node.resolveNoCache(node.content.size - slice.openEnd - extra)
837
+ };
838
+ }
839
+ var ResolvedPos = class _ResolvedPos {
840
+ /**
841
+ @internal
842
+ */
843
+ constructor(pos, path, parentOffset) {
844
+ this.pos = pos;
845
+ this.path = path;
846
+ this.parentOffset = parentOffset;
847
+ this.depth = path.length / 3 - 1;
848
+ }
849
+ /**
850
+ @internal
851
+ */
852
+ resolveDepth(val) {
853
+ if (val == null)
854
+ return this.depth;
855
+ if (val < 0)
856
+ return this.depth + val;
857
+ return val;
858
+ }
859
+ /**
860
+ The parent node that the position points into. Note that even if
861
+ a position points into a text node, that node is not considered
862
+ the parent—text nodes are ‘flat’ in this model, and have no content.
863
+ */
864
+ get parent() {
865
+ return this.node(this.depth);
866
+ }
867
+ /**
868
+ The root node in which the position was resolved.
869
+ */
870
+ get doc() {
871
+ return this.node(0);
872
+ }
873
+ /**
874
+ The ancestor node at the given level. `p.node(p.depth)` is the
875
+ same as `p.parent`.
876
+ */
877
+ node(depth) {
878
+ return this.path[this.resolveDepth(depth) * 3];
879
+ }
880
+ /**
881
+ The index into the ancestor at the given level. If this points
882
+ at the 3rd node in the 2nd paragraph on the top level, for
883
+ example, `p.index(0)` is 1 and `p.index(1)` is 2.
884
+ */
885
+ index(depth) {
886
+ return this.path[this.resolveDepth(depth) * 3 + 1];
887
+ }
888
+ /**
889
+ The index pointing after this position into the ancestor at the
890
+ given level.
891
+ */
892
+ indexAfter(depth) {
893
+ depth = this.resolveDepth(depth);
894
+ return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);
895
+ }
896
+ /**
897
+ The (absolute) position at the start of the node at the given
898
+ level.
899
+ */
900
+ start(depth) {
901
+ depth = this.resolveDepth(depth);
902
+ return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
903
+ }
904
+ /**
905
+ The (absolute) position at the end of the node at the given
906
+ level.
907
+ */
908
+ end(depth) {
909
+ depth = this.resolveDepth(depth);
910
+ return this.start(depth) + this.node(depth).content.size;
911
+ }
912
+ /**
913
+ The (absolute) position directly before the wrapping node at the
914
+ given level, or, when `depth` is `this.depth + 1`, the original
915
+ position.
916
+ */
917
+ before(depth) {
918
+ depth = this.resolveDepth(depth);
919
+ if (!depth)
920
+ throw new RangeError("There is no position before the top-level node");
921
+ return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];
922
+ }
923
+ /**
924
+ The (absolute) position directly after the wrapping node at the
925
+ given level, or the original position when `depth` is `this.depth + 1`.
926
+ */
927
+ after(depth) {
928
+ depth = this.resolveDepth(depth);
929
+ if (!depth)
930
+ throw new RangeError("There is no position after the top-level node");
931
+ return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;
932
+ }
933
+ /**
934
+ When this position points into a text node, this returns the
935
+ distance between the position and the start of the text node.
936
+ Will be zero for positions that point between nodes.
937
+ */
938
+ get textOffset() {
939
+ return this.pos - this.path[this.path.length - 1];
940
+ }
941
+ /**
942
+ Get the node directly after the position, if any. If the position
943
+ points into a text node, only the part of that node after the
944
+ position is returned.
945
+ */
946
+ get nodeAfter() {
947
+ let parent = this.parent, index = this.index(this.depth);
948
+ if (index == parent.childCount)
949
+ return null;
950
+ let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);
951
+ return dOff ? parent.child(index).cut(dOff) : child;
952
+ }
953
+ /**
954
+ Get the node directly before the position, if any. If the
955
+ position points into a text node, only the part of that node
956
+ before the position is returned.
957
+ */
958
+ get nodeBefore() {
959
+ let index = this.index(this.depth);
960
+ let dOff = this.pos - this.path[this.path.length - 1];
961
+ if (dOff)
962
+ return this.parent.child(index).cut(0, dOff);
963
+ return index == 0 ? null : this.parent.child(index - 1);
964
+ }
965
+ /**
966
+ Get the position at the given index in the parent node at the
967
+ given depth (which defaults to `this.depth`).
968
+ */
969
+ posAtIndex(index, depth) {
970
+ depth = this.resolveDepth(depth);
971
+ let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
972
+ for (let i = 0; i < index; i++)
973
+ pos += node.child(i).nodeSize;
974
+ return pos;
975
+ }
976
+ /**
977
+ Get the marks at this position, factoring in the surrounding
978
+ marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the
979
+ position is at the start of a non-empty node, the marks of the
980
+ node after it (if any) are returned.
981
+ */
982
+ marks() {
983
+ let parent = this.parent, index = this.index();
984
+ if (parent.content.size == 0)
985
+ return Mark.none;
986
+ if (this.textOffset)
987
+ return parent.child(index).marks;
988
+ let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);
989
+ if (!main) {
990
+ let tmp = main;
991
+ main = other;
992
+ other = tmp;
993
+ }
994
+ let marks = main.marks;
995
+ for (var i = 0; i < marks.length; i++)
996
+ if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks)))
997
+ marks = marks[i--].removeFromSet(marks);
998
+ return marks;
999
+ }
1000
+ /**
1001
+ Get the marks after the current position, if any, except those
1002
+ that are non-inclusive and not present at position `$end`. This
1003
+ is mostly useful for getting the set of marks to preserve after a
1004
+ deletion. Will return `null` if this position is at the end of
1005
+ its parent node or its parent node isn't a textblock (in which
1006
+ case no marks should be preserved).
1007
+ */
1008
+ marksAcross($end) {
1009
+ let after = this.parent.maybeChild(this.index());
1010
+ if (!after || !after.isInline)
1011
+ return null;
1012
+ let marks = after.marks, next = $end.parent.maybeChild($end.index());
1013
+ for (var i = 0; i < marks.length; i++)
1014
+ if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks)))
1015
+ marks = marks[i--].removeFromSet(marks);
1016
+ return marks;
1017
+ }
1018
+ /**
1019
+ The depth up to which this position and the given (non-resolved)
1020
+ position share the same parent nodes.
1021
+ */
1022
+ sharedDepth(pos) {
1023
+ for (let depth = this.depth; depth > 0; depth--)
1024
+ if (this.start(depth) <= pos && this.end(depth) >= pos)
1025
+ return depth;
1026
+ return 0;
1027
+ }
1028
+ /**
1029
+ Returns a range based on the place where this position and the
1030
+ given position diverge around block content. If both point into
1031
+ the same textblock, for example, a range around that textblock
1032
+ will be returned. If they point into different blocks, the range
1033
+ around those blocks in their shared ancestor is returned. You can
1034
+ pass in an optional predicate that will be called with a parent
1035
+ node to see if a range into that parent is acceptable.
1036
+ */
1037
+ blockRange(other = this, pred) {
1038
+ if (other.pos < this.pos)
1039
+ return other.blockRange(this);
1040
+ for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--)
1041
+ if (other.pos <= this.end(d) && (!pred || pred(this.node(d))))
1042
+ return new NodeRange(this, other, d);
1043
+ return null;
1044
+ }
1045
+ /**
1046
+ Query whether the given position shares the same parent node.
1047
+ */
1048
+ sameParent(other) {
1049
+ return this.pos - this.parentOffset == other.pos - other.parentOffset;
1050
+ }
1051
+ /**
1052
+ Return the greater of this and the given position.
1053
+ */
1054
+ max(other) {
1055
+ return other.pos > this.pos ? other : this;
1056
+ }
1057
+ /**
1058
+ Return the smaller of this and the given position.
1059
+ */
1060
+ min(other) {
1061
+ return other.pos < this.pos ? other : this;
1062
+ }
1063
+ /**
1064
+ @internal
1065
+ */
1066
+ toString() {
1067
+ let str = "";
1068
+ for (let i = 1; i <= this.depth; i++)
1069
+ str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1);
1070
+ return str + ":" + this.parentOffset;
1071
+ }
1072
+ /**
1073
+ @internal
1074
+ */
1075
+ static resolve(doc2, pos) {
1076
+ if (!(pos >= 0 && pos <= doc2.content.size))
1077
+ throw new RangeError("Position " + pos + " out of range");
1078
+ let path = [];
1079
+ let start = 0, parentOffset = pos;
1080
+ for (let node = doc2; ; ) {
1081
+ let { index, offset } = node.content.findIndex(parentOffset);
1082
+ let rem = parentOffset - offset;
1083
+ path.push(node, index, start + offset);
1084
+ if (!rem)
1085
+ break;
1086
+ node = node.child(index);
1087
+ if (node.isText)
1088
+ break;
1089
+ parentOffset = rem - 1;
1090
+ start += offset + 1;
1091
+ }
1092
+ return new _ResolvedPos(pos, path, parentOffset);
1093
+ }
1094
+ /**
1095
+ @internal
1096
+ */
1097
+ static resolveCached(doc2, pos) {
1098
+ for (let i = 0; i < resolveCache.length; i++) {
1099
+ let cached = resolveCache[i];
1100
+ if (cached.pos == pos && cached.doc == doc2)
1101
+ return cached;
1102
+ }
1103
+ let result = resolveCache[resolveCachePos] = _ResolvedPos.resolve(doc2, pos);
1104
+ resolveCachePos = (resolveCachePos + 1) % resolveCacheSize;
1105
+ return result;
1106
+ }
1107
+ };
1108
+ var resolveCache = [];
1109
+ var resolveCachePos = 0;
1110
+ var resolveCacheSize = 12;
1111
+ var NodeRange = class {
1112
+ /**
1113
+ Construct a node range. `$from` and `$to` should point into the
1114
+ same node until at least the given `depth`, since a node range
1115
+ denotes an adjacent set of nodes in a single parent node.
1116
+ */
1117
+ constructor($from, $to, depth) {
1118
+ this.$from = $from;
1119
+ this.$to = $to;
1120
+ this.depth = depth;
1121
+ }
1122
+ /**
1123
+ The position at the start of the range.
1124
+ */
1125
+ get start() {
1126
+ return this.$from.before(this.depth + 1);
1127
+ }
1128
+ /**
1129
+ The position at the end of the range.
1130
+ */
1131
+ get end() {
1132
+ return this.$to.after(this.depth + 1);
1133
+ }
1134
+ /**
1135
+ The parent node that the range points into.
1136
+ */
1137
+ get parent() {
1138
+ return this.$from.node(this.depth);
1139
+ }
1140
+ /**
1141
+ The start index of the range in the parent node.
1142
+ */
1143
+ get startIndex() {
1144
+ return this.$from.index(this.depth);
1145
+ }
1146
+ /**
1147
+ The end index of the range in the parent node.
1148
+ */
1149
+ get endIndex() {
1150
+ return this.$to.indexAfter(this.depth);
1151
+ }
1152
+ };
1153
+ var emptyAttrs = /* @__PURE__ */ Object.create(null);
1154
+ var Node = class _Node {
1155
+ /**
1156
+ @internal
1157
+ */
1158
+ constructor(type, attrs, content, marks = Mark.none) {
1159
+ this.type = type;
1160
+ this.attrs = attrs;
1161
+ this.marks = marks;
1162
+ this.content = content || Fragment.empty;
1163
+ }
1164
+ /**
1165
+ The size of this node, as defined by the integer-based [indexing
1166
+ scheme](/docs/guide/#doc.indexing). For text nodes, this is the
1167
+ amount of characters. For other leaf nodes, it is one. For
1168
+ non-leaf nodes, it is the size of the content plus two (the
1169
+ start and end token).
1170
+ */
1171
+ get nodeSize() {
1172
+ return this.isLeaf ? 1 : 2 + this.content.size;
1173
+ }
1174
+ /**
1175
+ The number of children that the node has.
1176
+ */
1177
+ get childCount() {
1178
+ return this.content.childCount;
1179
+ }
1180
+ /**
1181
+ Get the child node at the given index. Raises an error when the
1182
+ index is out of range.
1183
+ */
1184
+ child(index) {
1185
+ return this.content.child(index);
1186
+ }
1187
+ /**
1188
+ Get the child node at the given index, if it exists.
1189
+ */
1190
+ maybeChild(index) {
1191
+ return this.content.maybeChild(index);
1192
+ }
1193
+ /**
1194
+ Call `f` for every child node, passing the node, its offset
1195
+ into this parent node, and its index.
1196
+ */
1197
+ forEach(f) {
1198
+ this.content.forEach(f);
1199
+ }
1200
+ /**
1201
+ Invoke a callback for all descendant nodes recursively between
1202
+ the given two positions that are relative to start of this
1203
+ node's content. The callback is invoked with the node, its
1204
+ position relative to the original node (method receiver),
1205
+ its parent node, and its child index. When the callback returns
1206
+ false for a given node, that node's children will not be
1207
+ recursed over. The last parameter can be used to specify a
1208
+ starting position to count from.
1209
+ */
1210
+ nodesBetween(from, to, f, startPos = 0) {
1211
+ this.content.nodesBetween(from, to, f, startPos, this);
1212
+ }
1213
+ /**
1214
+ Call the given callback for every descendant node. Doesn't
1215
+ descend into a node when the callback returns `false`.
1216
+ */
1217
+ descendants(f) {
1218
+ this.nodesBetween(0, this.content.size, f);
1219
+ }
1220
+ /**
1221
+ Concatenates all the text nodes found in this fragment and its
1222
+ children.
1223
+ */
1224
+ get textContent() {
1225
+ return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
1226
+ }
1227
+ /**
1228
+ Get all text between positions `from` and `to`. When
1229
+ `blockSeparator` is given, it will be inserted to separate text
1230
+ from different block nodes. If `leafText` is given, it'll be
1231
+ inserted for every non-text leaf node encountered, otherwise
1232
+ [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used.
1233
+ */
1234
+ textBetween(from, to, blockSeparator, leafText) {
1235
+ return this.content.textBetween(from, to, blockSeparator, leafText);
1236
+ }
1237
+ /**
1238
+ Returns this node's first child, or `null` if there are no
1239
+ children.
1240
+ */
1241
+ get firstChild() {
1242
+ return this.content.firstChild;
1243
+ }
1244
+ /**
1245
+ Returns this node's last child, or `null` if there are no
1246
+ children.
1247
+ */
1248
+ get lastChild() {
1249
+ return this.content.lastChild;
1250
+ }
1251
+ /**
1252
+ Test whether two nodes represent the same piece of document.
1253
+ */
1254
+ eq(other) {
1255
+ return this == other || this.sameMarkup(other) && this.content.eq(other.content);
1256
+ }
1257
+ /**
1258
+ Compare the markup (type, attributes, and marks) of this node to
1259
+ those of another. Returns `true` if both have the same markup.
1260
+ */
1261
+ sameMarkup(other) {
1262
+ return this.hasMarkup(other.type, other.attrs, other.marks);
1263
+ }
1264
+ /**
1265
+ Check whether this node's markup correspond to the given type,
1266
+ attributes, and marks.
1267
+ */
1268
+ hasMarkup(type, attrs, marks) {
1269
+ return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none);
1270
+ }
1271
+ /**
1272
+ Create a new node with the same markup as this node, containing
1273
+ the given content (or empty, if no content is given).
1274
+ */
1275
+ copy(content = null) {
1276
+ if (content == this.content)
1277
+ return this;
1278
+ return new _Node(this.type, this.attrs, content, this.marks);
1279
+ }
1280
+ /**
1281
+ Create a copy of this node, with the given set of marks instead
1282
+ of the node's own marks.
1283
+ */
1284
+ mark(marks) {
1285
+ return marks == this.marks ? this : new _Node(this.type, this.attrs, this.content, marks);
1286
+ }
1287
+ /**
1288
+ Create a copy of this node with only the content between the
1289
+ given positions. If `to` is not given, it defaults to the end of
1290
+ the node.
1291
+ */
1292
+ cut(from, to = this.content.size) {
1293
+ if (from == 0 && to == this.content.size)
1294
+ return this;
1295
+ return this.copy(this.content.cut(from, to));
1296
+ }
1297
+ /**
1298
+ Cut out the part of the document between the given positions, and
1299
+ return it as a `Slice` object.
1300
+ */
1301
+ slice(from, to = this.content.size, includeParents = false) {
1302
+ if (from == to)
1303
+ return Slice.empty;
1304
+ let $from = this.resolve(from), $to = this.resolve(to);
1305
+ let depth = includeParents ? 0 : $from.sharedDepth(to);
1306
+ let start = $from.start(depth), node = $from.node(depth);
1307
+ let content = node.content.cut($from.pos - start, $to.pos - start);
1308
+ return new Slice(content, $from.depth - depth, $to.depth - depth);
1309
+ }
1310
+ /**
1311
+ Replace the part of the document between the given positions with
1312
+ the given slice. The slice must 'fit', meaning its open sides
1313
+ must be able to connect to the surrounding content, and its
1314
+ content nodes must be valid children for the node they are placed
1315
+ into. If any of this is violated, an error of type
1316
+ [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
1317
+ */
1318
+ replace(from, to, slice) {
1319
+ return replace(this.resolve(from), this.resolve(to), slice);
1320
+ }
1321
+ /**
1322
+ Find the node directly after the given position.
1323
+ */
1324
+ nodeAt(pos) {
1325
+ for (let node = this; ; ) {
1326
+ let { index, offset } = node.content.findIndex(pos);
1327
+ node = node.maybeChild(index);
1328
+ if (!node)
1329
+ return null;
1330
+ if (offset == pos || node.isText)
1331
+ return node;
1332
+ pos -= offset + 1;
1333
+ }
1334
+ }
1335
+ /**
1336
+ Find the (direct) child node after the given offset, if any,
1337
+ and return it along with its index and offset relative to this
1338
+ node.
1339
+ */
1340
+ childAfter(pos) {
1341
+ let { index, offset } = this.content.findIndex(pos);
1342
+ return { node: this.content.maybeChild(index), index, offset };
1343
+ }
1344
+ /**
1345
+ Find the (direct) child node before the given offset, if any,
1346
+ and return it along with its index and offset relative to this
1347
+ node.
1348
+ */
1349
+ childBefore(pos) {
1350
+ if (pos == 0)
1351
+ return { node: null, index: 0, offset: 0 };
1352
+ let { index, offset } = this.content.findIndex(pos);
1353
+ if (offset < pos)
1354
+ return { node: this.content.child(index), index, offset };
1355
+ let node = this.content.child(index - 1);
1356
+ return { node, index: index - 1, offset: offset - node.nodeSize };
1357
+ }
1358
+ /**
1359
+ Resolve the given position in the document, returning an
1360
+ [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
1361
+ */
1362
+ resolve(pos) {
1363
+ return ResolvedPos.resolveCached(this, pos);
1364
+ }
1365
+ /**
1366
+ @internal
1367
+ */
1368
+ resolveNoCache(pos) {
1369
+ return ResolvedPos.resolve(this, pos);
1370
+ }
1371
+ /**
1372
+ Test whether a given mark or mark type occurs in this document
1373
+ between the two given positions.
1374
+ */
1375
+ rangeHasMark(from, to, type) {
1376
+ let found2 = false;
1377
+ if (to > from)
1378
+ this.nodesBetween(from, to, (node) => {
1379
+ if (type.isInSet(node.marks))
1380
+ found2 = true;
1381
+ return !found2;
1382
+ });
1383
+ return found2;
1384
+ }
1385
+ /**
1386
+ True when this is a block (non-inline node)
1387
+ */
1388
+ get isBlock() {
1389
+ return this.type.isBlock;
1390
+ }
1391
+ /**
1392
+ True when this is a textblock node, a block node with inline
1393
+ content.
1394
+ */
1395
+ get isTextblock() {
1396
+ return this.type.isTextblock;
1397
+ }
1398
+ /**
1399
+ True when this node allows inline content.
1400
+ */
1401
+ get inlineContent() {
1402
+ return this.type.inlineContent;
1403
+ }
1404
+ /**
1405
+ True when this is an inline node (a text node or a node that can
1406
+ appear among text).
1407
+ */
1408
+ get isInline() {
1409
+ return this.type.isInline;
1410
+ }
1411
+ /**
1412
+ True when this is a text node.
1413
+ */
1414
+ get isText() {
1415
+ return this.type.isText;
1416
+ }
1417
+ /**
1418
+ True when this is a leaf node.
1419
+ */
1420
+ get isLeaf() {
1421
+ return this.type.isLeaf;
1422
+ }
1423
+ /**
1424
+ True when this is an atom, i.e. when it does not have directly
1425
+ editable content. This is usually the same as `isLeaf`, but can
1426
+ be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
1427
+ on a node's spec (typically used when the node is displayed as
1428
+ an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
1429
+ */
1430
+ get isAtom() {
1431
+ return this.type.isAtom;
1432
+ }
1433
+ /**
1434
+ Return a string representation of this node for debugging
1435
+ purposes.
1436
+ */
1437
+ toString() {
1438
+ if (this.type.spec.toDebugString)
1439
+ return this.type.spec.toDebugString(this);
1440
+ let name = this.type.name;
1441
+ if (this.content.size)
1442
+ name += "(" + this.content.toStringInner() + ")";
1443
+ return wrapMarks(this.marks, name);
1444
+ }
1445
+ /**
1446
+ Get the content match in this node at the given index.
1447
+ */
1448
+ contentMatchAt(index) {
1449
+ let match = this.type.contentMatch.matchFragment(this.content, 0, index);
1450
+ if (!match)
1451
+ throw new Error("Called contentMatchAt on a node with invalid content");
1452
+ return match;
1453
+ }
1454
+ /**
1455
+ Test whether replacing the range between `from` and `to` (by
1456
+ child index) with the given replacement fragment (which defaults
1457
+ to the empty fragment) would leave the node's content valid. You
1458
+ can optionally pass `start` and `end` indices into the
1459
+ replacement fragment.
1460
+ */
1461
+ canReplace(from, to, replacement = Fragment.empty, start = 0, end = replacement.childCount) {
1462
+ let one = this.contentMatchAt(from).matchFragment(replacement, start, end);
1463
+ let two = one && one.matchFragment(this.content, to);
1464
+ if (!two || !two.validEnd)
1465
+ return false;
1466
+ for (let i = start; i < end; i++)
1467
+ if (!this.type.allowsMarks(replacement.child(i).marks))
1468
+ return false;
1469
+ return true;
1470
+ }
1471
+ /**
1472
+ Test whether replacing the range `from` to `to` (by index) with
1473
+ a node of the given type would leave the node's content valid.
1474
+ */
1475
+ canReplaceWith(from, to, type, marks) {
1476
+ if (marks && !this.type.allowsMarks(marks))
1477
+ return false;
1478
+ let start = this.contentMatchAt(from).matchType(type);
1479
+ let end = start && start.matchFragment(this.content, to);
1480
+ return end ? end.validEnd : false;
1481
+ }
1482
+ /**
1483
+ Test whether the given node's content could be appended to this
1484
+ node. If that node is empty, this will only return true if there
1485
+ is at least one node type that can appear in both nodes (to avoid
1486
+ merging completely incompatible nodes).
1487
+ */
1488
+ canAppend(other) {
1489
+ if (other.content.size)
1490
+ return this.canReplace(this.childCount, this.childCount, other.content);
1491
+ else
1492
+ return this.type.compatibleContent(other.type);
1493
+ }
1494
+ /**
1495
+ Check whether this node and its descendants conform to the
1496
+ schema, and raise error when they do not.
1497
+ */
1498
+ check() {
1499
+ this.type.checkContent(this.content);
1500
+ let copy2 = Mark.none;
1501
+ for (let i = 0; i < this.marks.length; i++)
1502
+ copy2 = this.marks[i].addToSet(copy2);
1503
+ if (!Mark.sameSet(copy2, this.marks))
1504
+ throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
1505
+ this.content.forEach((node) => node.check());
1506
+ }
1507
+ /**
1508
+ Return a JSON-serializeable representation of this node.
1509
+ */
1510
+ toJSON() {
1511
+ let obj = { type: this.type.name };
1512
+ for (let _ in this.attrs) {
1513
+ obj.attrs = this.attrs;
1514
+ break;
1515
+ }
1516
+ if (this.content.size)
1517
+ obj.content = this.content.toJSON();
1518
+ if (this.marks.length)
1519
+ obj.marks = this.marks.map((n) => n.toJSON());
1520
+ return obj;
1521
+ }
1522
+ /**
1523
+ Deserialize a node from its JSON representation.
1524
+ */
1525
+ static fromJSON(schema, json) {
1526
+ if (!json)
1527
+ throw new RangeError("Invalid input for Node.fromJSON");
1528
+ let marks = null;
1529
+ if (json.marks) {
1530
+ if (!Array.isArray(json.marks))
1531
+ throw new RangeError("Invalid mark data for Node.fromJSON");
1532
+ marks = json.marks.map(schema.markFromJSON);
1533
+ }
1534
+ if (json.type == "text") {
1535
+ if (typeof json.text != "string")
1536
+ throw new RangeError("Invalid text node in JSON");
1537
+ return schema.text(json.text, marks);
1538
+ }
1539
+ let content = Fragment.fromJSON(schema, json.content);
1540
+ return schema.nodeType(json.type).create(json.attrs, content, marks);
1541
+ }
1542
+ };
1543
+ Node.prototype.text = void 0;
1544
+ var TextNode = class _TextNode extends Node {
1545
+ /**
1546
+ @internal
1547
+ */
1548
+ constructor(type, attrs, content, marks) {
1549
+ super(type, attrs, null, marks);
1550
+ if (!content)
1551
+ throw new RangeError("Empty text nodes are not allowed");
1552
+ this.text = content;
1553
+ }
1554
+ toString() {
1555
+ if (this.type.spec.toDebugString)
1556
+ return this.type.spec.toDebugString(this);
1557
+ return wrapMarks(this.marks, JSON.stringify(this.text));
1558
+ }
1559
+ get textContent() {
1560
+ return this.text;
1561
+ }
1562
+ textBetween(from, to) {
1563
+ return this.text.slice(from, to);
1564
+ }
1565
+ get nodeSize() {
1566
+ return this.text.length;
1567
+ }
1568
+ mark(marks) {
1569
+ return marks == this.marks ? this : new _TextNode(this.type, this.attrs, this.text, marks);
1570
+ }
1571
+ withText(text) {
1572
+ if (text == this.text)
1573
+ return this;
1574
+ return new _TextNode(this.type, this.attrs, text, this.marks);
1575
+ }
1576
+ cut(from = 0, to = this.text.length) {
1577
+ if (from == 0 && to == this.text.length)
1578
+ return this;
1579
+ return this.withText(this.text.slice(from, to));
1580
+ }
1581
+ eq(other) {
1582
+ return this.sameMarkup(other) && this.text == other.text;
1583
+ }
1584
+ toJSON() {
1585
+ let base = super.toJSON();
1586
+ base.text = this.text;
1587
+ return base;
1588
+ }
1589
+ };
1590
+ function wrapMarks(marks, str) {
1591
+ for (let i = marks.length - 1; i >= 0; i--)
1592
+ str = marks[i].type.name + "(" + str + ")";
1593
+ return str;
1594
+ }
1595
+ var ContentMatch = class _ContentMatch {
1596
+ /**
1597
+ @internal
1598
+ */
1599
+ constructor(validEnd) {
1600
+ this.validEnd = validEnd;
1601
+ this.next = [];
1602
+ this.wrapCache = [];
1603
+ }
1604
+ /**
1605
+ @internal
1606
+ */
1607
+ static parse(string, nodeTypes) {
1608
+ let stream = new TokenStream(string, nodeTypes);
1609
+ if (stream.next == null)
1610
+ return _ContentMatch.empty;
1611
+ let expr = parseExpr(stream);
1612
+ if (stream.next)
1613
+ stream.err("Unexpected trailing text");
1614
+ let match = dfa(nfa(expr));
1615
+ checkForDeadEnds(match, stream);
1616
+ return match;
1617
+ }
1618
+ /**
1619
+ Match a node type, returning a match after that node if
1620
+ successful.
1621
+ */
1622
+ matchType(type) {
1623
+ for (let i = 0; i < this.next.length; i++)
1624
+ if (this.next[i].type == type)
1625
+ return this.next[i].next;
1626
+ return null;
1627
+ }
1628
+ /**
1629
+ Try to match a fragment. Returns the resulting match when
1630
+ successful.
1631
+ */
1632
+ matchFragment(frag, start = 0, end = frag.childCount) {
1633
+ let cur = this;
1634
+ for (let i = start; cur && i < end; i++)
1635
+ cur = cur.matchType(frag.child(i).type);
1636
+ return cur;
1637
+ }
1638
+ /**
1639
+ @internal
1640
+ */
1641
+ get inlineContent() {
1642
+ return this.next.length != 0 && this.next[0].type.isInline;
1643
+ }
1644
+ /**
1645
+ Get the first matching node type at this match position that can
1646
+ be generated.
1647
+ */
1648
+ get defaultType() {
1649
+ for (let i = 0; i < this.next.length; i++) {
1650
+ let { type } = this.next[i];
1651
+ if (!(type.isText || type.hasRequiredAttrs()))
1652
+ return type;
1653
+ }
1654
+ return null;
1655
+ }
1656
+ /**
1657
+ @internal
1658
+ */
1659
+ compatible(other) {
1660
+ for (let i = 0; i < this.next.length; i++)
1661
+ for (let j = 0; j < other.next.length; j++)
1662
+ if (this.next[i].type == other.next[j].type)
1663
+ return true;
1664
+ return false;
1665
+ }
1666
+ /**
1667
+ Try to match the given fragment, and if that fails, see if it can
1668
+ be made to match by inserting nodes in front of it. When
1669
+ successful, return a fragment of inserted nodes (which may be
1670
+ empty if nothing had to be inserted). When `toEnd` is true, only
1671
+ return a fragment if the resulting match goes to the end of the
1672
+ content expression.
1673
+ */
1674
+ fillBefore(after, toEnd = false, startIndex = 0) {
1675
+ let seen = [this];
1676
+ function search(match, types) {
1677
+ let finished = match.matchFragment(after, startIndex);
1678
+ if (finished && (!toEnd || finished.validEnd))
1679
+ return Fragment.from(types.map((tp) => tp.createAndFill()));
1680
+ for (let i = 0; i < match.next.length; i++) {
1681
+ let { type, next } = match.next[i];
1682
+ if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {
1683
+ seen.push(next);
1684
+ let found2 = search(next, types.concat(type));
1685
+ if (found2)
1686
+ return found2;
1687
+ }
1688
+ }
1689
+ return null;
1690
+ }
1691
+ return search(this, []);
1692
+ }
1693
+ /**
1694
+ Find a set of wrapping node types that would allow a node of the
1695
+ given type to appear at this position. The result may be empty
1696
+ (when it fits directly) and will be null when no such wrapping
1697
+ exists.
1698
+ */
1699
+ findWrapping(target) {
1700
+ for (let i = 0; i < this.wrapCache.length; i += 2)
1701
+ if (this.wrapCache[i] == target)
1702
+ return this.wrapCache[i + 1];
1703
+ let computed = this.computeWrapping(target);
1704
+ this.wrapCache.push(target, computed);
1705
+ return computed;
1706
+ }
1707
+ /**
1708
+ @internal
1709
+ */
1710
+ computeWrapping(target) {
1711
+ let seen = /* @__PURE__ */ Object.create(null), active = [{ match: this, type: null, via: null }];
1712
+ while (active.length) {
1713
+ let current = active.shift(), match = current.match;
1714
+ if (match.matchType(target)) {
1715
+ let result = [];
1716
+ for (let obj = current; obj.type; obj = obj.via)
1717
+ result.push(obj.type);
1718
+ return result.reverse();
1719
+ }
1720
+ for (let i = 0; i < match.next.length; i++) {
1721
+ let { type, next } = match.next[i];
1722
+ if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {
1723
+ active.push({ match: type.contentMatch, type, via: current });
1724
+ seen[type.name] = true;
1725
+ }
1726
+ }
1727
+ }
1728
+ return null;
1729
+ }
1730
+ /**
1731
+ The number of outgoing edges this node has in the finite
1732
+ automaton that describes the content expression.
1733
+ */
1734
+ get edgeCount() {
1735
+ return this.next.length;
1736
+ }
1737
+ /**
1738
+ Get the _n_​th outgoing edge from this node in the finite
1739
+ automaton that describes the content expression.
1740
+ */
1741
+ edge(n) {
1742
+ if (n >= this.next.length)
1743
+ throw new RangeError(`There's no ${n}th edge in this content match`);
1744
+ return this.next[n];
1745
+ }
1746
+ /**
1747
+ @internal
1748
+ */
1749
+ toString() {
1750
+ let seen = [];
1751
+ function scan(m) {
1752
+ seen.push(m);
1753
+ for (let i = 0; i < m.next.length; i++)
1754
+ if (seen.indexOf(m.next[i].next) == -1)
1755
+ scan(m.next[i].next);
1756
+ }
1757
+ scan(this);
1758
+ return seen.map((m, i) => {
1759
+ let out = i + (m.validEnd ? "*" : " ") + " ";
1760
+ for (let i2 = 0; i2 < m.next.length; i2++)
1761
+ out += (i2 ? ", " : "") + m.next[i2].type.name + "->" + seen.indexOf(m.next[i2].next);
1762
+ return out;
1763
+ }).join("\n");
1764
+ }
1765
+ };
1766
+ ContentMatch.empty = new ContentMatch(true);
1767
+ var TokenStream = class {
1768
+ constructor(string, nodeTypes) {
1769
+ this.string = string;
1770
+ this.nodeTypes = nodeTypes;
1771
+ this.inline = null;
1772
+ this.pos = 0;
1773
+ this.tokens = string.split(/\s*(?=\b|\W|$)/);
1774
+ if (this.tokens[this.tokens.length - 1] == "")
1775
+ this.tokens.pop();
1776
+ if (this.tokens[0] == "")
1777
+ this.tokens.shift();
1778
+ }
1779
+ get next() {
1780
+ return this.tokens[this.pos];
1781
+ }
1782
+ eat(tok) {
1783
+ return this.next == tok && (this.pos++ || true);
1784
+ }
1785
+ err(str) {
1786
+ throw new SyntaxError(str + " (in content expression '" + this.string + "')");
1787
+ }
1788
+ };
1789
+ function parseExpr(stream) {
1790
+ let exprs = [];
1791
+ do {
1792
+ exprs.push(parseExprSeq(stream));
1793
+ } while (stream.eat("|"));
1794
+ return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
1795
+ }
1796
+ function parseExprSeq(stream) {
1797
+ let exprs = [];
1798
+ do {
1799
+ exprs.push(parseExprSubscript(stream));
1800
+ } while (stream.next && stream.next != ")" && stream.next != "|");
1801
+ return exprs.length == 1 ? exprs[0] : { type: "seq", exprs };
1802
+ }
1803
+ function parseExprSubscript(stream) {
1804
+ let expr = parseExprAtom(stream);
1805
+ for (; ; ) {
1806
+ if (stream.eat("+"))
1807
+ expr = { type: "plus", expr };
1808
+ else if (stream.eat("*"))
1809
+ expr = { type: "star", expr };
1810
+ else if (stream.eat("?"))
1811
+ expr = { type: "opt", expr };
1812
+ else if (stream.eat("{"))
1813
+ expr = parseExprRange(stream, expr);
1814
+ else
1815
+ break;
1816
+ }
1817
+ return expr;
1818
+ }
1819
+ function parseNum(stream) {
1820
+ if (/\D/.test(stream.next))
1821
+ stream.err("Expected number, got '" + stream.next + "'");
1822
+ let result = Number(stream.next);
1823
+ stream.pos++;
1824
+ return result;
1825
+ }
1826
+ function parseExprRange(stream, expr) {
1827
+ let min = parseNum(stream), max = min;
1828
+ if (stream.eat(",")) {
1829
+ if (stream.next != "}")
1830
+ max = parseNum(stream);
1831
+ else
1832
+ max = -1;
1833
+ }
1834
+ if (!stream.eat("}"))
1835
+ stream.err("Unclosed braced range");
1836
+ return { type: "range", min, max, expr };
1837
+ }
1838
+ function resolveName(stream, name) {
1839
+ let types = stream.nodeTypes, type = types[name];
1840
+ if (type)
1841
+ return [type];
1842
+ let result = [];
1843
+ for (let typeName in types) {
1844
+ let type2 = types[typeName];
1845
+ if (type2.groups.indexOf(name) > -1)
1846
+ result.push(type2);
1847
+ }
1848
+ if (result.length == 0)
1849
+ stream.err("No node type or group '" + name + "' found");
1850
+ return result;
1851
+ }
1852
+ function parseExprAtom(stream) {
1853
+ if (stream.eat("(")) {
1854
+ let expr = parseExpr(stream);
1855
+ if (!stream.eat(")"))
1856
+ stream.err("Missing closing paren");
1857
+ return expr;
1858
+ } else if (!/\W/.test(stream.next)) {
1859
+ let exprs = resolveName(stream, stream.next).map((type) => {
1860
+ if (stream.inline == null)
1861
+ stream.inline = type.isInline;
1862
+ else if (stream.inline != type.isInline)
1863
+ stream.err("Mixing inline and block content");
1864
+ return { type: "name", value: type };
1865
+ });
1866
+ stream.pos++;
1867
+ return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
1868
+ } else {
1869
+ stream.err("Unexpected token '" + stream.next + "'");
1870
+ }
1871
+ }
1872
+ function nfa(expr) {
1873
+ let nfa2 = [[]];
1874
+ connect(compile(expr, 0), node());
1875
+ return nfa2;
1876
+ function node() {
1877
+ return nfa2.push([]) - 1;
1878
+ }
1879
+ function edge(from, to, term) {
1880
+ let edge2 = { term, to };
1881
+ nfa2[from].push(edge2);
1882
+ return edge2;
1883
+ }
1884
+ function connect(edges, to) {
1885
+ edges.forEach((edge2) => edge2.to = to);
1886
+ }
1887
+ function compile(expr2, from) {
1888
+ if (expr2.type == "choice") {
1889
+ return expr2.exprs.reduce((out, expr3) => out.concat(compile(expr3, from)), []);
1890
+ } else if (expr2.type == "seq") {
1891
+ for (let i = 0; ; i++) {
1892
+ let next = compile(expr2.exprs[i], from);
1893
+ if (i == expr2.exprs.length - 1)
1894
+ return next;
1895
+ connect(next, from = node());
1896
+ }
1897
+ } else if (expr2.type == "star") {
1898
+ let loop = node();
1899
+ edge(from, loop);
1900
+ connect(compile(expr2.expr, loop), loop);
1901
+ return [edge(loop)];
1902
+ } else if (expr2.type == "plus") {
1903
+ let loop = node();
1904
+ connect(compile(expr2.expr, from), loop);
1905
+ connect(compile(expr2.expr, loop), loop);
1906
+ return [edge(loop)];
1907
+ } else if (expr2.type == "opt") {
1908
+ return [edge(from)].concat(compile(expr2.expr, from));
1909
+ } else if (expr2.type == "range") {
1910
+ let cur = from;
1911
+ for (let i = 0; i < expr2.min; i++) {
1912
+ let next = node();
1913
+ connect(compile(expr2.expr, cur), next);
1914
+ cur = next;
1915
+ }
1916
+ if (expr2.max == -1) {
1917
+ connect(compile(expr2.expr, cur), cur);
1918
+ } else {
1919
+ for (let i = expr2.min; i < expr2.max; i++) {
1920
+ let next = node();
1921
+ edge(cur, next);
1922
+ connect(compile(expr2.expr, cur), next);
1923
+ cur = next;
1924
+ }
1925
+ }
1926
+ return [edge(cur)];
1927
+ } else if (expr2.type == "name") {
1928
+ return [edge(from, void 0, expr2.value)];
1929
+ } else {
1930
+ throw new Error("Unknown expr type");
1931
+ }
1932
+ }
1933
+ }
1934
+ function cmp(a, b) {
1935
+ return b - a;
1936
+ }
1937
+ function nullFrom(nfa2, node) {
1938
+ let result = [];
1939
+ scan(node);
1940
+ return result.sort(cmp);
1941
+ function scan(node2) {
1942
+ let edges = nfa2[node2];
1943
+ if (edges.length == 1 && !edges[0].term)
1944
+ return scan(edges[0].to);
1945
+ result.push(node2);
1946
+ for (let i = 0; i < edges.length; i++) {
1947
+ let { term, to } = edges[i];
1948
+ if (!term && result.indexOf(to) == -1)
1949
+ scan(to);
1950
+ }
1951
+ }
1952
+ }
1953
+ function dfa(nfa2) {
1954
+ let labeled = /* @__PURE__ */ Object.create(null);
1955
+ return explore(nullFrom(nfa2, 0));
1956
+ function explore(states) {
1957
+ let out = [];
1958
+ states.forEach((node) => {
1959
+ nfa2[node].forEach(({ term, to }) => {
1960
+ if (!term)
1961
+ return;
1962
+ let set;
1963
+ for (let i = 0; i < out.length; i++)
1964
+ if (out[i][0] == term)
1965
+ set = out[i][1];
1966
+ nullFrom(nfa2, to).forEach((node2) => {
1967
+ if (!set)
1968
+ out.push([term, set = []]);
1969
+ if (set.indexOf(node2) == -1)
1970
+ set.push(node2);
1971
+ });
1972
+ });
1973
+ });
1974
+ let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa2.length - 1) > -1);
1975
+ for (let i = 0; i < out.length; i++) {
1976
+ let states2 = out[i][1].sort(cmp);
1977
+ state.next.push({ type: out[i][0], next: labeled[states2.join(",")] || explore(states2) });
1978
+ }
1979
+ return state;
1980
+ }
1981
+ }
1982
+ function checkForDeadEnds(match, stream) {
1983
+ for (let i = 0, work = [match]; i < work.length; i++) {
1984
+ let state = work[i], dead = !state.validEnd, nodes = [];
1985
+ for (let j = 0; j < state.next.length; j++) {
1986
+ let { type, next } = state.next[j];
1987
+ nodes.push(type.name);
1988
+ if (dead && !(type.isText || type.hasRequiredAttrs()))
1989
+ dead = false;
1990
+ if (work.indexOf(next) == -1)
1991
+ work.push(next);
1992
+ }
1993
+ if (dead)
1994
+ stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
1995
+ }
1996
+ }
1997
+ function defaultAttrs(attrs) {
1998
+ let defaults = /* @__PURE__ */ Object.create(null);
1999
+ for (let attrName in attrs) {
2000
+ let attr = attrs[attrName];
2001
+ if (!attr.hasDefault)
2002
+ return null;
2003
+ defaults[attrName] = attr.default;
2004
+ }
2005
+ return defaults;
2006
+ }
2007
+ function computeAttrs(attrs, value) {
2008
+ let built = /* @__PURE__ */ Object.create(null);
2009
+ for (let name in attrs) {
2010
+ let given = value && value[name];
2011
+ if (given === void 0) {
2012
+ let attr = attrs[name];
2013
+ if (attr.hasDefault)
2014
+ given = attr.default;
2015
+ else
2016
+ throw new RangeError("No value supplied for attribute " + name);
2017
+ }
2018
+ built[name] = given;
2019
+ }
2020
+ return built;
2021
+ }
2022
+ function initAttrs(attrs) {
2023
+ let result = /* @__PURE__ */ Object.create(null);
2024
+ if (attrs)
2025
+ for (let name in attrs)
2026
+ result[name] = new Attribute(attrs[name]);
2027
+ return result;
2028
+ }
2029
+ var NodeType = class _NodeType {
2030
+ /**
2031
+ @internal
2032
+ */
2033
+ constructor(name, schema, spec) {
2034
+ this.name = name;
2035
+ this.schema = schema;
2036
+ this.spec = spec;
2037
+ this.markSet = null;
2038
+ this.groups = spec.group ? spec.group.split(" ") : [];
2039
+ this.attrs = initAttrs(spec.attrs);
2040
+ this.defaultAttrs = defaultAttrs(this.attrs);
2041
+ this.contentMatch = null;
2042
+ this.inlineContent = null;
2043
+ this.isBlock = !(spec.inline || name == "text");
2044
+ this.isText = name == "text";
2045
+ }
2046
+ /**
2047
+ True if this is an inline type.
2048
+ */
2049
+ get isInline() {
2050
+ return !this.isBlock;
2051
+ }
2052
+ /**
2053
+ True if this is a textblock type, a block that contains inline
2054
+ content.
2055
+ */
2056
+ get isTextblock() {
2057
+ return this.isBlock && this.inlineContent;
2058
+ }
2059
+ /**
2060
+ True for node types that allow no content.
2061
+ */
2062
+ get isLeaf() {
2063
+ return this.contentMatch == ContentMatch.empty;
2064
+ }
2065
+ /**
2066
+ True when this node is an atom, i.e. when it does not have
2067
+ directly editable content.
2068
+ */
2069
+ get isAtom() {
2070
+ return this.isLeaf || !!this.spec.atom;
2071
+ }
2072
+ /**
2073
+ The node type's [whitespace](https://prosemirror.net/docs/ref/#model.NodeSpec.whitespace) option.
2074
+ */
2075
+ get whitespace() {
2076
+ return this.spec.whitespace || (this.spec.code ? "pre" : "normal");
2077
+ }
2078
+ /**
2079
+ Tells you whether this node type has any required attributes.
2080
+ */
2081
+ hasRequiredAttrs() {
2082
+ for (let n in this.attrs)
2083
+ if (this.attrs[n].isRequired)
2084
+ return true;
2085
+ return false;
2086
+ }
2087
+ /**
2088
+ Indicates whether this node allows some of the same content as
2089
+ the given node type.
2090
+ */
2091
+ compatibleContent(other) {
2092
+ return this == other || this.contentMatch.compatible(other.contentMatch);
2093
+ }
2094
+ /**
2095
+ @internal
2096
+ */
2097
+ computeAttrs(attrs) {
2098
+ if (!attrs && this.defaultAttrs)
2099
+ return this.defaultAttrs;
2100
+ else
2101
+ return computeAttrs(this.attrs, attrs);
2102
+ }
2103
+ /**
2104
+ Create a `Node` of this type. The given attributes are
2105
+ checked and defaulted (you can pass `null` to use the type's
2106
+ defaults entirely, if no required attributes exist). `content`
2107
+ may be a `Fragment`, a node, an array of nodes, or
2108
+ `null`. Similarly `marks` may be `null` to default to the empty
2109
+ set of marks.
2110
+ */
2111
+ create(attrs = null, content, marks) {
2112
+ if (this.isText)
2113
+ throw new Error("NodeType.create can't construct text nodes");
2114
+ return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks));
2115
+ }
2116
+ /**
2117
+ Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
2118
+ against the node type's content restrictions, and throw an error
2119
+ if it doesn't match.
2120
+ */
2121
+ createChecked(attrs = null, content, marks) {
2122
+ content = Fragment.from(content);
2123
+ this.checkContent(content);
2124
+ return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks));
2125
+ }
2126
+ /**
2127
+ Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
2128
+ necessary to add nodes to the start or end of the given fragment
2129
+ to make it fit the node. If no fitting wrapping can be found,
2130
+ return null. Note that, due to the fact that required nodes can
2131
+ always be created, this will always succeed if you pass null or
2132
+ `Fragment.empty` as content.
2133
+ */
2134
+ createAndFill(attrs = null, content, marks) {
2135
+ attrs = this.computeAttrs(attrs);
2136
+ content = Fragment.from(content);
2137
+ if (content.size) {
2138
+ let before = this.contentMatch.fillBefore(content);
2139
+ if (!before)
2140
+ return null;
2141
+ content = before.append(content);
2142
+ }
2143
+ let matched = this.contentMatch.matchFragment(content);
2144
+ let after = matched && matched.fillBefore(Fragment.empty, true);
2145
+ if (!after)
2146
+ return null;
2147
+ return new Node(this, attrs, content.append(after), Mark.setFrom(marks));
2148
+ }
2149
+ /**
2150
+ Returns true if the given fragment is valid content for this node
2151
+ type with the given attributes.
2152
+ */
2153
+ validContent(content) {
2154
+ let result = this.contentMatch.matchFragment(content);
2155
+ if (!result || !result.validEnd)
2156
+ return false;
2157
+ for (let i = 0; i < content.childCount; i++)
2158
+ if (!this.allowsMarks(content.child(i).marks))
2159
+ return false;
2160
+ return true;
2161
+ }
2162
+ /**
2163
+ Throws a RangeError if the given fragment is not valid content for this
2164
+ node type.
2165
+ @internal
2166
+ */
2167
+ checkContent(content) {
2168
+ if (!this.validContent(content))
2169
+ throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);
2170
+ }
2171
+ /**
2172
+ Check whether the given mark type is allowed in this node.
2173
+ */
2174
+ allowsMarkType(markType) {
2175
+ return this.markSet == null || this.markSet.indexOf(markType) > -1;
2176
+ }
2177
+ /**
2178
+ Test whether the given set of marks are allowed in this node.
2179
+ */
2180
+ allowsMarks(marks) {
2181
+ if (this.markSet == null)
2182
+ return true;
2183
+ for (let i = 0; i < marks.length; i++)
2184
+ if (!this.allowsMarkType(marks[i].type))
2185
+ return false;
2186
+ return true;
2187
+ }
2188
+ /**
2189
+ Removes the marks that are not allowed in this node from the given set.
2190
+ */
2191
+ allowedMarks(marks) {
2192
+ if (this.markSet == null)
2193
+ return marks;
2194
+ let copy2;
2195
+ for (let i = 0; i < marks.length; i++) {
2196
+ if (!this.allowsMarkType(marks[i].type)) {
2197
+ if (!copy2)
2198
+ copy2 = marks.slice(0, i);
2199
+ } else if (copy2) {
2200
+ copy2.push(marks[i]);
2201
+ }
2202
+ }
2203
+ return !copy2 ? marks : copy2.length ? copy2 : Mark.none;
2204
+ }
2205
+ /**
2206
+ @internal
2207
+ */
2208
+ static compile(nodes, schema) {
2209
+ let result = /* @__PURE__ */ Object.create(null);
2210
+ nodes.forEach((name, spec) => result[name] = new _NodeType(name, schema, spec));
2211
+ let topType = schema.spec.topNode || "doc";
2212
+ if (!result[topType])
2213
+ throw new RangeError("Schema is missing its top node type ('" + topType + "')");
2214
+ if (!result.text)
2215
+ throw new RangeError("Every schema needs a 'text' type");
2216
+ for (let _ in result.text.attrs)
2217
+ throw new RangeError("The text node type should not have attributes");
2218
+ return result;
2219
+ }
2220
+ };
2221
+ var Attribute = class {
2222
+ constructor(options) {
2223
+ this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default");
2224
+ this.default = options.default;
2225
+ }
2226
+ get isRequired() {
2227
+ return !this.hasDefault;
2228
+ }
2229
+ };
2230
+ var MarkType = class _MarkType {
2231
+ /**
2232
+ @internal
2233
+ */
2234
+ constructor(name, rank, schema, spec) {
2235
+ this.name = name;
2236
+ this.rank = rank;
2237
+ this.schema = schema;
2238
+ this.spec = spec;
2239
+ this.attrs = initAttrs(spec.attrs);
2240
+ this.excluded = null;
2241
+ let defaults = defaultAttrs(this.attrs);
2242
+ this.instance = defaults ? new Mark(this, defaults) : null;
2243
+ }
2244
+ /**
2245
+ Create a mark of this type. `attrs` may be `null` or an object
2246
+ containing only some of the mark's attributes. The others, if
2247
+ they have defaults, will be added.
2248
+ */
2249
+ create(attrs = null) {
2250
+ if (!attrs && this.instance)
2251
+ return this.instance;
2252
+ return new Mark(this, computeAttrs(this.attrs, attrs));
2253
+ }
2254
+ /**
2255
+ @internal
2256
+ */
2257
+ static compile(marks, schema) {
2258
+ let result = /* @__PURE__ */ Object.create(null), rank = 0;
2259
+ marks.forEach((name, spec) => result[name] = new _MarkType(name, rank++, schema, spec));
2260
+ return result;
2261
+ }
2262
+ /**
2263
+ When there is a mark of this type in the given set, a new set
2264
+ without it is returned. Otherwise, the input set is returned.
2265
+ */
2266
+ removeFromSet(set) {
2267
+ for (var i = 0; i < set.length; i++)
2268
+ if (set[i].type == this) {
2269
+ set = set.slice(0, i).concat(set.slice(i + 1));
2270
+ i--;
2271
+ }
2272
+ return set;
2273
+ }
2274
+ /**
2275
+ Tests whether there is a mark of this type in the given set.
2276
+ */
2277
+ isInSet(set) {
2278
+ for (let i = 0; i < set.length; i++)
2279
+ if (set[i].type == this)
2280
+ return set[i];
2281
+ }
2282
+ /**
2283
+ Queries whether a given mark type is
2284
+ [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
2285
+ */
2286
+ excludes(other) {
2287
+ return this.excluded.indexOf(other) > -1;
2288
+ }
2289
+ };
2290
+ var Schema = class {
2291
+ /**
2292
+ Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).
2293
+ */
2294
+ constructor(spec) {
2295
+ this.cached = /* @__PURE__ */ Object.create(null);
2296
+ let instanceSpec = this.spec = {};
2297
+ for (let prop in spec)
2298
+ instanceSpec[prop] = spec[prop];
2299
+ instanceSpec.nodes = dist_default.from(spec.nodes), instanceSpec.marks = dist_default.from(spec.marks || {}), this.nodes = NodeType.compile(this.spec.nodes, this);
2300
+ this.marks = MarkType.compile(this.spec.marks, this);
2301
+ let contentExprCache = /* @__PURE__ */ Object.create(null);
2302
+ for (let prop in this.nodes) {
2303
+ if (prop in this.marks)
2304
+ throw new RangeError(prop + " can not be both a node and a mark");
2305
+ let type = this.nodes[prop], contentExpr = type.spec.content || "", markExpr = type.spec.marks;
2306
+ type.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes));
2307
+ type.inlineContent = type.contentMatch.inlineContent;
2308
+ type.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type.inlineContent ? [] : null;
2309
+ }
2310
+ for (let prop in this.marks) {
2311
+ let type = this.marks[prop], excl = type.spec.excludes;
2312
+ type.excluded = excl == null ? [type] : excl == "" ? [] : gatherMarks(this, excl.split(" "));
2313
+ }
2314
+ this.nodeFromJSON = this.nodeFromJSON.bind(this);
2315
+ this.markFromJSON = this.markFromJSON.bind(this);
2316
+ this.topNodeType = this.nodes[this.spec.topNode || "doc"];
2317
+ this.cached.wrappings = /* @__PURE__ */ Object.create(null);
2318
+ }
2319
+ /**
2320
+ Create a node in this schema. The `type` may be a string or a
2321
+ `NodeType` instance. Attributes will be extended with defaults,
2322
+ `content` may be a `Fragment`, `null`, a `Node`, or an array of
2323
+ nodes.
2324
+ */
2325
+ node(type, attrs = null, content, marks) {
2326
+ if (typeof type == "string")
2327
+ type = this.nodeType(type);
2328
+ else if (!(type instanceof NodeType))
2329
+ throw new RangeError("Invalid node type: " + type);
2330
+ else if (type.schema != this)
2331
+ throw new RangeError("Node type from different schema used (" + type.name + ")");
2332
+ return type.createChecked(attrs, content, marks);
2333
+ }
2334
+ /**
2335
+ Create a text node in the schema. Empty text nodes are not
2336
+ allowed.
2337
+ */
2338
+ text(text, marks) {
2339
+ let type = this.nodes.text;
2340
+ return new TextNode(type, type.defaultAttrs, text, Mark.setFrom(marks));
2341
+ }
2342
+ /**
2343
+ Create a mark with the given type and attributes.
2344
+ */
2345
+ mark(type, attrs) {
2346
+ if (typeof type == "string")
2347
+ type = this.marks[type];
2348
+ return type.create(attrs);
2349
+ }
2350
+ /**
2351
+ Deserialize a node from its JSON representation. This method is
2352
+ bound.
2353
+ */
2354
+ nodeFromJSON(json) {
2355
+ return Node.fromJSON(this, json);
2356
+ }
2357
+ /**
2358
+ Deserialize a mark from its JSON representation. This method is
2359
+ bound.
2360
+ */
2361
+ markFromJSON(json) {
2362
+ return Mark.fromJSON(this, json);
2363
+ }
2364
+ /**
2365
+ @internal
2366
+ */
2367
+ nodeType(name) {
2368
+ let found2 = this.nodes[name];
2369
+ if (!found2)
2370
+ throw new RangeError("Unknown node type: " + name);
2371
+ return found2;
2372
+ }
2373
+ };
2374
+ function gatherMarks(schema, marks) {
2375
+ let found2 = [];
2376
+ for (let i = 0; i < marks.length; i++) {
2377
+ let name = marks[i], mark = schema.marks[name], ok = mark;
2378
+ if (mark) {
2379
+ found2.push(mark);
2380
+ } else {
2381
+ for (let prop in schema.marks) {
2382
+ let mark2 = schema.marks[prop];
2383
+ if (name == "_" || mark2.spec.group && mark2.spec.group.split(" ").indexOf(name) > -1)
2384
+ found2.push(ok = mark2);
2385
+ }
2386
+ }
2387
+ if (!ok)
2388
+ throw new SyntaxError("Unknown mark type: '" + marks[i] + "'");
2389
+ }
2390
+ return found2;
2391
+ }
2392
+ var DOMParser = class _DOMParser {
2393
+ /**
2394
+ Create a parser that targets the given schema, using the given
2395
+ parsing rules.
2396
+ */
2397
+ constructor(schema, rules) {
2398
+ this.schema = schema;
2399
+ this.rules = rules;
2400
+ this.tags = [];
2401
+ this.styles = [];
2402
+ rules.forEach((rule) => {
2403
+ if (rule.tag)
2404
+ this.tags.push(rule);
2405
+ else if (rule.style)
2406
+ this.styles.push(rule);
2407
+ });
2408
+ this.normalizeLists = !this.tags.some((r) => {
2409
+ if (!/^(ul|ol)\b/.test(r.tag) || !r.node)
2410
+ return false;
2411
+ let node = schema.nodes[r.node];
2412
+ return node.contentMatch.matchType(node);
2413
+ });
2414
+ }
2415
+ /**
2416
+ Parse a document from the content of a DOM node.
2417
+ */
2418
+ parse(dom, options = {}) {
2419
+ let context = new ParseContext(this, options, false);
2420
+ context.addAll(dom, options.from, options.to);
2421
+ return context.finish();
2422
+ }
2423
+ /**
2424
+ Parses the content of the given DOM node, like
2425
+ [`parse`](https://prosemirror.net/docs/ref/#model.DOMParser.parse), and takes the same set of
2426
+ options. But unlike that method, which produces a whole node,
2427
+ this one returns a slice that is open at the sides, meaning that
2428
+ the schema constraints aren't applied to the start of nodes to
2429
+ the left of the input and the end of nodes at the end.
2430
+ */
2431
+ parseSlice(dom, options = {}) {
2432
+ let context = new ParseContext(this, options, true);
2433
+ context.addAll(dom, options.from, options.to);
2434
+ return Slice.maxOpen(context.finish());
2435
+ }
2436
+ /**
2437
+ @internal
2438
+ */
2439
+ matchTag(dom, context, after) {
2440
+ for (let i = after ? this.tags.indexOf(after) + 1 : 0; i < this.tags.length; i++) {
2441
+ let rule = this.tags[i];
2442
+ if (matches(dom, rule.tag) && (rule.namespace === void 0 || dom.namespaceURI == rule.namespace) && (!rule.context || context.matchesContext(rule.context))) {
2443
+ if (rule.getAttrs) {
2444
+ let result = rule.getAttrs(dom);
2445
+ if (result === false)
2446
+ continue;
2447
+ rule.attrs = result || void 0;
2448
+ }
2449
+ return rule;
2450
+ }
2451
+ }
2452
+ }
2453
+ /**
2454
+ @internal
2455
+ */
2456
+ matchStyle(prop, value, context, after) {
2457
+ for (let i = after ? this.styles.indexOf(after) + 1 : 0; i < this.styles.length; i++) {
2458
+ let rule = this.styles[i], style = rule.style;
2459
+ if (style.indexOf(prop) != 0 || rule.context && !context.matchesContext(rule.context) || // Test that the style string either precisely matches the prop,
2460
+ // or has an '=' sign after the prop, followed by the given
2461
+ // value.
2462
+ style.length > prop.length && (style.charCodeAt(prop.length) != 61 || style.slice(prop.length + 1) != value))
2463
+ continue;
2464
+ if (rule.getAttrs) {
2465
+ let result = rule.getAttrs(value);
2466
+ if (result === false)
2467
+ continue;
2468
+ rule.attrs = result || void 0;
2469
+ }
2470
+ return rule;
2471
+ }
2472
+ }
2473
+ /**
2474
+ @internal
2475
+ */
2476
+ static schemaRules(schema) {
2477
+ let result = [];
2478
+ function insert(rule) {
2479
+ let priority = rule.priority == null ? 50 : rule.priority, i = 0;
2480
+ for (; i < result.length; i++) {
2481
+ let next = result[i], nextPriority = next.priority == null ? 50 : next.priority;
2482
+ if (nextPriority < priority)
2483
+ break;
2484
+ }
2485
+ result.splice(i, 0, rule);
2486
+ }
2487
+ for (let name in schema.marks) {
2488
+ let rules = schema.marks[name].spec.parseDOM;
2489
+ if (rules)
2490
+ rules.forEach((rule) => {
2491
+ insert(rule = copy(rule));
2492
+ if (!(rule.mark || rule.ignore || rule.clearMark))
2493
+ rule.mark = name;
2494
+ });
2495
+ }
2496
+ for (let name in schema.nodes) {
2497
+ let rules = schema.nodes[name].spec.parseDOM;
2498
+ if (rules)
2499
+ rules.forEach((rule) => {
2500
+ insert(rule = copy(rule));
2501
+ if (!(rule.node || rule.ignore || rule.mark))
2502
+ rule.node = name;
2503
+ });
2504
+ }
2505
+ return result;
2506
+ }
2507
+ /**
2508
+ Construct a DOM parser using the parsing rules listed in a
2509
+ schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by
2510
+ [priority](https://prosemirror.net/docs/ref/#model.ParseRule.priority).
2511
+ */
2512
+ static fromSchema(schema) {
2513
+ return schema.cached.domParser || (schema.cached.domParser = new _DOMParser(schema, _DOMParser.schemaRules(schema)));
2514
+ }
2515
+ };
2516
+ var blockTags = {
2517
+ address: true,
2518
+ article: true,
2519
+ aside: true,
2520
+ blockquote: true,
2521
+ canvas: true,
2522
+ dd: true,
2523
+ div: true,
2524
+ dl: true,
2525
+ fieldset: true,
2526
+ figcaption: true,
2527
+ figure: true,
2528
+ footer: true,
2529
+ form: true,
2530
+ h1: true,
2531
+ h2: true,
2532
+ h3: true,
2533
+ h4: true,
2534
+ h5: true,
2535
+ h6: true,
2536
+ header: true,
2537
+ hgroup: true,
2538
+ hr: true,
2539
+ li: true,
2540
+ noscript: true,
2541
+ ol: true,
2542
+ output: true,
2543
+ p: true,
2544
+ pre: true,
2545
+ section: true,
2546
+ table: true,
2547
+ tfoot: true,
2548
+ ul: true
2549
+ };
2550
+ var ignoreTags = {
2551
+ head: true,
2552
+ noscript: true,
2553
+ object: true,
2554
+ script: true,
2555
+ style: true,
2556
+ title: true
2557
+ };
2558
+ var listTags = { ol: true, ul: true };
2559
+ var OPT_PRESERVE_WS = 1;
2560
+ var OPT_PRESERVE_WS_FULL = 2;
2561
+ var OPT_OPEN_LEFT = 4;
2562
+ function wsOptionsFor(type, preserveWhitespace, base) {
2563
+ if (preserveWhitespace != null)
2564
+ return (preserveWhitespace ? OPT_PRESERVE_WS : 0) | (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0);
2565
+ return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & ~OPT_OPEN_LEFT;
2566
+ }
2567
+ var NodeContext = class {
2568
+ constructor(type, attrs, marks, pendingMarks, solid, match, options) {
2569
+ this.type = type;
2570
+ this.attrs = attrs;
2571
+ this.marks = marks;
2572
+ this.pendingMarks = pendingMarks;
2573
+ this.solid = solid;
2574
+ this.options = options;
2575
+ this.content = [];
2576
+ this.activeMarks = Mark.none;
2577
+ this.stashMarks = [];
2578
+ this.match = match || (options & OPT_OPEN_LEFT ? null : type.contentMatch);
2579
+ }
2580
+ findWrapping(node) {
2581
+ if (!this.match) {
2582
+ if (!this.type)
2583
+ return [];
2584
+ let fill = this.type.contentMatch.fillBefore(Fragment.from(node));
2585
+ if (fill) {
2586
+ this.match = this.type.contentMatch.matchFragment(fill);
2587
+ } else {
2588
+ let start = this.type.contentMatch, wrap;
2589
+ if (wrap = start.findWrapping(node.type)) {
2590
+ this.match = start;
2591
+ return wrap;
2592
+ } else {
2593
+ return null;
2594
+ }
2595
+ }
2596
+ }
2597
+ return this.match.findWrapping(node.type);
2598
+ }
2599
+ finish(openEnd) {
2600
+ if (!(this.options & OPT_PRESERVE_WS)) {
2601
+ let last = this.content[this.content.length - 1], m;
2602
+ if (last && last.isText && (m = /[ \t\r\n\u000c]+$/.exec(last.text))) {
2603
+ let text = last;
2604
+ if (last.text.length == m[0].length)
2605
+ this.content.pop();
2606
+ else
2607
+ this.content[this.content.length - 1] = text.withText(text.text.slice(0, text.text.length - m[0].length));
2608
+ }
2609
+ }
2610
+ let content = Fragment.from(this.content);
2611
+ if (!openEnd && this.match)
2612
+ content = content.append(this.match.fillBefore(Fragment.empty, true));
2613
+ return this.type ? this.type.create(this.attrs, content, this.marks) : content;
2614
+ }
2615
+ popFromStashMark(mark) {
2616
+ for (let i = this.stashMarks.length - 1; i >= 0; i--)
2617
+ if (mark.eq(this.stashMarks[i]))
2618
+ return this.stashMarks.splice(i, 1)[0];
2619
+ }
2620
+ applyPending(nextType) {
2621
+ for (let i = 0, pending = this.pendingMarks; i < pending.length; i++) {
2622
+ let mark = pending[i];
2623
+ if ((this.type ? this.type.allowsMarkType(mark.type) : markMayApply(mark.type, nextType)) && !mark.isInSet(this.activeMarks)) {
2624
+ this.activeMarks = mark.addToSet(this.activeMarks);
2625
+ this.pendingMarks = mark.removeFromSet(this.pendingMarks);
2626
+ }
2627
+ }
2628
+ }
2629
+ inlineContext(node) {
2630
+ if (this.type)
2631
+ return this.type.inlineContent;
2632
+ if (this.content.length)
2633
+ return this.content[0].isInline;
2634
+ return node.parentNode && !blockTags.hasOwnProperty(node.parentNode.nodeName.toLowerCase());
2635
+ }
2636
+ };
2637
+ var ParseContext = class {
2638
+ constructor(parser, options, isOpen) {
2639
+ this.parser = parser;
2640
+ this.options = options;
2641
+ this.isOpen = isOpen;
2642
+ this.open = 0;
2643
+ let topNode = options.topNode, topContext;
2644
+ let topOptions = wsOptionsFor(null, options.preserveWhitespace, 0) | (isOpen ? OPT_OPEN_LEFT : 0);
2645
+ if (topNode)
2646
+ topContext = new NodeContext(topNode.type, topNode.attrs, Mark.none, Mark.none, true, options.topMatch || topNode.type.contentMatch, topOptions);
2647
+ else if (isOpen)
2648
+ topContext = new NodeContext(null, null, Mark.none, Mark.none, true, null, topOptions);
2649
+ else
2650
+ topContext = new NodeContext(parser.schema.topNodeType, null, Mark.none, Mark.none, true, null, topOptions);
2651
+ this.nodes = [topContext];
2652
+ this.find = options.findPositions;
2653
+ this.needsBlock = false;
2654
+ }
2655
+ get top() {
2656
+ return this.nodes[this.open];
2657
+ }
2658
+ // Add a DOM node to the content. Text is inserted as text node,
2659
+ // otherwise, the node is passed to `addElement` or, if it has a
2660
+ // `style` attribute, `addElementWithStyles`.
2661
+ addDOM(dom) {
2662
+ if (dom.nodeType == 3) {
2663
+ this.addTextNode(dom);
2664
+ } else if (dom.nodeType == 1) {
2665
+ let style = dom.getAttribute("style");
2666
+ if (!style) {
2667
+ this.addElement(dom);
2668
+ } else {
2669
+ let marks = this.readStyles(parseStyles(style));
2670
+ if (!marks)
2671
+ return;
2672
+ let [addMarks, removeMarks] = marks, top = this.top;
2673
+ for (let i = 0; i < removeMarks.length; i++)
2674
+ this.removePendingMark(removeMarks[i], top);
2675
+ for (let i = 0; i < addMarks.length; i++)
2676
+ this.addPendingMark(addMarks[i]);
2677
+ this.addElement(dom);
2678
+ for (let i = 0; i < addMarks.length; i++)
2679
+ this.removePendingMark(addMarks[i], top);
2680
+ for (let i = 0; i < removeMarks.length; i++)
2681
+ this.addPendingMark(removeMarks[i]);
2682
+ }
2683
+ }
2684
+ }
2685
+ addTextNode(dom) {
2686
+ let value = dom.nodeValue;
2687
+ let top = this.top;
2688
+ if (top.options & OPT_PRESERVE_WS_FULL || top.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) {
2689
+ if (!(top.options & OPT_PRESERVE_WS)) {
2690
+ value = value.replace(/[ \t\r\n\u000c]+/g, " ");
2691
+ if (/^[ \t\r\n\u000c]/.test(value) && this.open == this.nodes.length - 1) {
2692
+ let nodeBefore = top.content[top.content.length - 1];
2693
+ let domNodeBefore = dom.previousSibling;
2694
+ if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == "BR" || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text))
2695
+ value = value.slice(1);
2696
+ }
2697
+ } else if (!(top.options & OPT_PRESERVE_WS_FULL)) {
2698
+ value = value.replace(/\r?\n|\r/g, " ");
2699
+ } else {
2700
+ value = value.replace(/\r\n?/g, "\n");
2701
+ }
2702
+ if (value)
2703
+ this.insertNode(this.parser.schema.text(value));
2704
+ this.findInText(dom);
2705
+ } else {
2706
+ this.findInside(dom);
2707
+ }
2708
+ }
2709
+ // Try to find a handler for the given tag and use that to parse. If
2710
+ // none is found, the element's content nodes are added directly.
2711
+ addElement(dom, matchAfter) {
2712
+ let name = dom.nodeName.toLowerCase(), ruleID;
2713
+ if (listTags.hasOwnProperty(name) && this.parser.normalizeLists)
2714
+ normalizeList(dom);
2715
+ let rule = this.options.ruleFromNode && this.options.ruleFromNode(dom) || (ruleID = this.parser.matchTag(dom, this, matchAfter));
2716
+ if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) {
2717
+ this.findInside(dom);
2718
+ this.ignoreFallback(dom);
2719
+ } else if (!rule || rule.skip || rule.closeParent) {
2720
+ if (rule && rule.closeParent)
2721
+ this.open = Math.max(0, this.open - 1);
2722
+ else if (rule && rule.skip.nodeType)
2723
+ dom = rule.skip;
2724
+ let sync, top = this.top, oldNeedsBlock = this.needsBlock;
2725
+ if (blockTags.hasOwnProperty(name)) {
2726
+ if (top.content.length && top.content[0].isInline && this.open) {
2727
+ this.open--;
2728
+ top = this.top;
2729
+ }
2730
+ sync = true;
2731
+ if (!top.type)
2732
+ this.needsBlock = true;
2733
+ } else if (!dom.firstChild) {
2734
+ this.leafFallback(dom);
2735
+ return;
2736
+ }
2737
+ this.addAll(dom);
2738
+ if (sync)
2739
+ this.sync(top);
2740
+ this.needsBlock = oldNeedsBlock;
2741
+ } else {
2742
+ this.addElementByRule(dom, rule, rule.consuming === false ? ruleID : void 0);
2743
+ }
2744
+ }
2745
+ // Called for leaf DOM nodes that would otherwise be ignored
2746
+ leafFallback(dom) {
2747
+ if (dom.nodeName == "BR" && this.top.type && this.top.type.inlineContent)
2748
+ this.addTextNode(dom.ownerDocument.createTextNode("\n"));
2749
+ }
2750
+ // Called for ignored nodes
2751
+ ignoreFallback(dom) {
2752
+ if (dom.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent))
2753
+ this.findPlace(this.parser.schema.text("-"));
2754
+ }
2755
+ // Run any style parser associated with the node's styles. Either
2756
+ // return an array of marks, or null to indicate some of the styles
2757
+ // had a rule with `ignore` set.
2758
+ readStyles(styles) {
2759
+ let add = Mark.none, remove = Mark.none;
2760
+ for (let i = 0; i < styles.length; i += 2) {
2761
+ for (let after = void 0; ; ) {
2762
+ let rule = this.parser.matchStyle(styles[i], styles[i + 1], this, after);
2763
+ if (!rule)
2764
+ break;
2765
+ if (rule.ignore)
2766
+ return null;
2767
+ if (rule.clearMark) {
2768
+ this.top.pendingMarks.concat(this.top.activeMarks).forEach((m) => {
2769
+ if (rule.clearMark(m))
2770
+ remove = m.addToSet(remove);
2771
+ });
2772
+ } else {
2773
+ add = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(add);
2774
+ }
2775
+ if (rule.consuming === false)
2776
+ after = rule;
2777
+ else
2778
+ break;
2779
+ }
2780
+ }
2781
+ return [add, remove];
2782
+ }
2783
+ // Look up a handler for the given node. If none are found, return
2784
+ // false. Otherwise, apply it, use its return value to drive the way
2785
+ // the node's content is wrapped, and return true.
2786
+ addElementByRule(dom, rule, continueAfter) {
2787
+ let sync, nodeType, mark;
2788
+ if (rule.node) {
2789
+ nodeType = this.parser.schema.nodes[rule.node];
2790
+ if (!nodeType.isLeaf) {
2791
+ sync = this.enter(nodeType, rule.attrs || null, rule.preserveWhitespace);
2792
+ } else if (!this.insertNode(nodeType.create(rule.attrs))) {
2793
+ this.leafFallback(dom);
2794
+ }
2795
+ } else {
2796
+ let markType = this.parser.schema.marks[rule.mark];
2797
+ mark = markType.create(rule.attrs);
2798
+ this.addPendingMark(mark);
2799
+ }
2800
+ let startIn = this.top;
2801
+ if (nodeType && nodeType.isLeaf) {
2802
+ this.findInside(dom);
2803
+ } else if (continueAfter) {
2804
+ this.addElement(dom, continueAfter);
2805
+ } else if (rule.getContent) {
2806
+ this.findInside(dom);
2807
+ rule.getContent(dom, this.parser.schema).forEach((node) => this.insertNode(node));
2808
+ } else {
2809
+ let contentDOM = dom;
2810
+ if (typeof rule.contentElement == "string")
2811
+ contentDOM = dom.querySelector(rule.contentElement);
2812
+ else if (typeof rule.contentElement == "function")
2813
+ contentDOM = rule.contentElement(dom);
2814
+ else if (rule.contentElement)
2815
+ contentDOM = rule.contentElement;
2816
+ this.findAround(dom, contentDOM, true);
2817
+ this.addAll(contentDOM);
2818
+ }
2819
+ if (sync && this.sync(startIn))
2820
+ this.open--;
2821
+ if (mark)
2822
+ this.removePendingMark(mark, startIn);
2823
+ }
2824
+ // Add all child nodes between `startIndex` and `endIndex` (or the
2825
+ // whole node, if not given). If `sync` is passed, use it to
2826
+ // synchronize after every block element.
2827
+ addAll(parent, startIndex, endIndex) {
2828
+ let index = startIndex || 0;
2829
+ for (let dom = startIndex ? parent.childNodes[startIndex] : parent.firstChild, end = endIndex == null ? null : parent.childNodes[endIndex]; dom != end; dom = dom.nextSibling, ++index) {
2830
+ this.findAtPoint(parent, index);
2831
+ this.addDOM(dom);
2832
+ }
2833
+ this.findAtPoint(parent, index);
2834
+ }
2835
+ // Try to find a way to fit the given node type into the current
2836
+ // context. May add intermediate wrappers and/or leave non-solid
2837
+ // nodes that we're in.
2838
+ findPlace(node) {
2839
+ let route, sync;
2840
+ for (let depth = this.open; depth >= 0; depth--) {
2841
+ let cx = this.nodes[depth];
2842
+ let found2 = cx.findWrapping(node);
2843
+ if (found2 && (!route || route.length > found2.length)) {
2844
+ route = found2;
2845
+ sync = cx;
2846
+ if (!found2.length)
2847
+ break;
2848
+ }
2849
+ if (cx.solid)
2850
+ break;
2851
+ }
2852
+ if (!route)
2853
+ return false;
2854
+ this.sync(sync);
2855
+ for (let i = 0; i < route.length; i++)
2856
+ this.enterInner(route[i], null, false);
2857
+ return true;
2858
+ }
2859
+ // Try to insert the given node, adjusting the context when needed.
2860
+ insertNode(node) {
2861
+ if (node.isInline && this.needsBlock && !this.top.type) {
2862
+ let block = this.textblockFromContext();
2863
+ if (block)
2864
+ this.enterInner(block);
2865
+ }
2866
+ if (this.findPlace(node)) {
2867
+ this.closeExtra();
2868
+ let top = this.top;
2869
+ top.applyPending(node.type);
2870
+ if (top.match)
2871
+ top.match = top.match.matchType(node.type);
2872
+ let marks = top.activeMarks;
2873
+ for (let i = 0; i < node.marks.length; i++)
2874
+ if (!top.type || top.type.allowsMarkType(node.marks[i].type))
2875
+ marks = node.marks[i].addToSet(marks);
2876
+ top.content.push(node.mark(marks));
2877
+ return true;
2878
+ }
2879
+ return false;
2880
+ }
2881
+ // Try to start a node of the given type, adjusting the context when
2882
+ // necessary.
2883
+ enter(type, attrs, preserveWS) {
2884
+ let ok = this.findPlace(type.create(attrs));
2885
+ if (ok)
2886
+ this.enterInner(type, attrs, true, preserveWS);
2887
+ return ok;
2888
+ }
2889
+ // Open a node of the given type
2890
+ enterInner(type, attrs = null, solid = false, preserveWS) {
2891
+ this.closeExtra();
2892
+ let top = this.top;
2893
+ top.applyPending(type);
2894
+ top.match = top.match && top.match.matchType(type);
2895
+ let options = wsOptionsFor(type, preserveWS, top.options);
2896
+ if (top.options & OPT_OPEN_LEFT && top.content.length == 0)
2897
+ options |= OPT_OPEN_LEFT;
2898
+ this.nodes.push(new NodeContext(type, attrs, top.activeMarks, top.pendingMarks, solid, null, options));
2899
+ this.open++;
2900
+ }
2901
+ // Make sure all nodes above this.open are finished and added to
2902
+ // their parents
2903
+ closeExtra(openEnd = false) {
2904
+ let i = this.nodes.length - 1;
2905
+ if (i > this.open) {
2906
+ for (; i > this.open; i--)
2907
+ this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd));
2908
+ this.nodes.length = this.open + 1;
2909
+ }
2910
+ }
2911
+ finish() {
2912
+ this.open = 0;
2913
+ this.closeExtra(this.isOpen);
2914
+ return this.nodes[0].finish(this.isOpen || this.options.topOpen);
2915
+ }
2916
+ sync(to) {
2917
+ for (let i = this.open; i >= 0; i--)
2918
+ if (this.nodes[i] == to) {
2919
+ this.open = i;
2920
+ return true;
2921
+ }
2922
+ return false;
2923
+ }
2924
+ get currentPos() {
2925
+ this.closeExtra();
2926
+ let pos = 0;
2927
+ for (let i = this.open; i >= 0; i--) {
2928
+ let content = this.nodes[i].content;
2929
+ for (let j = content.length - 1; j >= 0; j--)
2930
+ pos += content[j].nodeSize;
2931
+ if (i)
2932
+ pos++;
2933
+ }
2934
+ return pos;
2935
+ }
2936
+ findAtPoint(parent, offset) {
2937
+ if (this.find)
2938
+ for (let i = 0; i < this.find.length; i++) {
2939
+ if (this.find[i].node == parent && this.find[i].offset == offset)
2940
+ this.find[i].pos = this.currentPos;
2941
+ }
2942
+ }
2943
+ findInside(parent) {
2944
+ if (this.find)
2945
+ for (let i = 0; i < this.find.length; i++) {
2946
+ if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node))
2947
+ this.find[i].pos = this.currentPos;
2948
+ }
2949
+ }
2950
+ findAround(parent, content, before) {
2951
+ if (parent != content && this.find)
2952
+ for (let i = 0; i < this.find.length; i++) {
2953
+ if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) {
2954
+ let pos = content.compareDocumentPosition(this.find[i].node);
2955
+ if (pos & (before ? 2 : 4))
2956
+ this.find[i].pos = this.currentPos;
2957
+ }
2958
+ }
2959
+ }
2960
+ findInText(textNode) {
2961
+ if (this.find)
2962
+ for (let i = 0; i < this.find.length; i++) {
2963
+ if (this.find[i].node == textNode)
2964
+ this.find[i].pos = this.currentPos - (textNode.nodeValue.length - this.find[i].offset);
2965
+ }
2966
+ }
2967
+ // Determines whether the given context string matches this context.
2968
+ matchesContext(context) {
2969
+ if (context.indexOf("|") > -1)
2970
+ return context.split(/\s*\|\s*/).some(this.matchesContext, this);
2971
+ let parts = context.split("/");
2972
+ let option = this.options.context;
2973
+ let useRoot = !this.isOpen && (!option || option.parent.type == this.nodes[0].type);
2974
+ let minDepth = -(option ? option.depth + 1 : 0) + (useRoot ? 0 : 1);
2975
+ let match = (i, depth) => {
2976
+ for (; i >= 0; i--) {
2977
+ let part = parts[i];
2978
+ if (part == "") {
2979
+ if (i == parts.length - 1 || i == 0)
2980
+ continue;
2981
+ for (; depth >= minDepth; depth--)
2982
+ if (match(i - 1, depth))
2983
+ return true;
2984
+ return false;
2985
+ } else {
2986
+ let next = depth > 0 || depth == 0 && useRoot ? this.nodes[depth].type : option && depth >= minDepth ? option.node(depth - minDepth).type : null;
2987
+ if (!next || next.name != part && next.groups.indexOf(part) == -1)
2988
+ return false;
2989
+ depth--;
2990
+ }
2991
+ }
2992
+ return true;
2993
+ };
2994
+ return match(parts.length - 1, this.open);
2995
+ }
2996
+ textblockFromContext() {
2997
+ let $context = this.options.context;
2998
+ if ($context)
2999
+ for (let d = $context.depth; d >= 0; d--) {
3000
+ let deflt = $context.node(d).contentMatchAt($context.indexAfter(d)).defaultType;
3001
+ if (deflt && deflt.isTextblock && deflt.defaultAttrs)
3002
+ return deflt;
3003
+ }
3004
+ for (let name in this.parser.schema.nodes) {
3005
+ let type = this.parser.schema.nodes[name];
3006
+ if (type.isTextblock && type.defaultAttrs)
3007
+ return type;
3008
+ }
3009
+ }
3010
+ addPendingMark(mark) {
3011
+ let found2 = findSameMarkInSet(mark, this.top.pendingMarks);
3012
+ if (found2)
3013
+ this.top.stashMarks.push(found2);
3014
+ this.top.pendingMarks = mark.addToSet(this.top.pendingMarks);
3015
+ }
3016
+ removePendingMark(mark, upto) {
3017
+ for (let depth = this.open; depth >= 0; depth--) {
3018
+ let level = this.nodes[depth];
3019
+ let found2 = level.pendingMarks.lastIndexOf(mark);
3020
+ if (found2 > -1) {
3021
+ level.pendingMarks = mark.removeFromSet(level.pendingMarks);
3022
+ } else {
3023
+ level.activeMarks = mark.removeFromSet(level.activeMarks);
3024
+ let stashMark = level.popFromStashMark(mark);
3025
+ if (stashMark && level.type && level.type.allowsMarkType(stashMark.type))
3026
+ level.activeMarks = stashMark.addToSet(level.activeMarks);
3027
+ }
3028
+ if (level == upto)
3029
+ break;
3030
+ }
3031
+ }
3032
+ };
3033
+ function normalizeList(dom) {
3034
+ for (let child = dom.firstChild, prevItem = null; child; child = child.nextSibling) {
3035
+ let name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null;
3036
+ if (name && listTags.hasOwnProperty(name) && prevItem) {
3037
+ prevItem.appendChild(child);
3038
+ child = prevItem;
3039
+ } else if (name == "li") {
3040
+ prevItem = child;
3041
+ } else if (name) {
3042
+ prevItem = null;
3043
+ }
3044
+ }
3045
+ }
3046
+ function matches(dom, selector) {
3047
+ return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector);
3048
+ }
3049
+ function parseStyles(style) {
3050
+ let re = /\s*([\w-]+)\s*:\s*([^;]+)/g, m, result = [];
3051
+ while (m = re.exec(style))
3052
+ result.push(m[1], m[2].trim());
3053
+ return result;
3054
+ }
3055
+ function copy(obj) {
3056
+ let copy2 = {};
3057
+ for (let prop in obj)
3058
+ copy2[prop] = obj[prop];
3059
+ return copy2;
3060
+ }
3061
+ function markMayApply(markType, nodeType) {
3062
+ let nodes = nodeType.schema.nodes;
3063
+ for (let name in nodes) {
3064
+ let parent = nodes[name];
3065
+ if (!parent.allowsMarkType(markType))
3066
+ continue;
3067
+ let seen = [], scan = (match) => {
3068
+ seen.push(match);
3069
+ for (let i = 0; i < match.edgeCount; i++) {
3070
+ let { type, next } = match.edge(i);
3071
+ if (type == nodeType)
3072
+ return true;
3073
+ if (seen.indexOf(next) < 0 && scan(next))
3074
+ return true;
3075
+ }
3076
+ };
3077
+ if (scan(parent.contentMatch))
3078
+ return true;
3079
+ }
3080
+ }
3081
+ function findSameMarkInSet(mark, set) {
3082
+ for (let i = 0; i < set.length; i++) {
3083
+ if (mark.eq(set[i]))
3084
+ return set[i];
3085
+ }
3086
+ }
3087
+ var DOMSerializer = class _DOMSerializer {
3088
+ /**
3089
+ Create a serializer. `nodes` should map node names to functions
3090
+ that take a node and return a description of the corresponding
3091
+ DOM. `marks` does the same for mark names, but also gets an
3092
+ argument that tells it whether the mark's content is block or
3093
+ inline content (for typical use, it'll always be inline). A mark
3094
+ serializer may be `null` to indicate that marks of that type
3095
+ should not be serialized.
3096
+ */
3097
+ constructor(nodes, marks) {
3098
+ this.nodes = nodes;
3099
+ this.marks = marks;
3100
+ }
3101
+ /**
3102
+ Serialize the content of this fragment to a DOM fragment. When
3103
+ not in the browser, the `document` option, containing a DOM
3104
+ document, should be passed so that the serializer can create
3105
+ nodes.
3106
+ */
3107
+ serializeFragment(fragment, options = {}, target) {
3108
+ if (!target)
3109
+ target = doc(options).createDocumentFragment();
3110
+ let top = target, active = [];
3111
+ fragment.forEach((node) => {
3112
+ if (active.length || node.marks.length) {
3113
+ let keep = 0, rendered = 0;
3114
+ while (keep < active.length && rendered < node.marks.length) {
3115
+ let next = node.marks[rendered];
3116
+ if (!this.marks[next.type.name]) {
3117
+ rendered++;
3118
+ continue;
3119
+ }
3120
+ if (!next.eq(active[keep][0]) || next.type.spec.spanning === false)
3121
+ break;
3122
+ keep++;
3123
+ rendered++;
3124
+ }
3125
+ while (keep < active.length)
3126
+ top = active.pop()[1];
3127
+ while (rendered < node.marks.length) {
3128
+ let add = node.marks[rendered++];
3129
+ let markDOM = this.serializeMark(add, node.isInline, options);
3130
+ if (markDOM) {
3131
+ active.push([add, top]);
3132
+ top.appendChild(markDOM.dom);
3133
+ top = markDOM.contentDOM || markDOM.dom;
3134
+ }
3135
+ }
3136
+ }
3137
+ top.appendChild(this.serializeNodeInner(node, options));
3138
+ });
3139
+ return target;
3140
+ }
3141
+ /**
3142
+ @internal
3143
+ */
3144
+ serializeNodeInner(node, options) {
3145
+ let { dom, contentDOM } = _DOMSerializer.renderSpec(doc(options), this.nodes[node.type.name](node));
3146
+ if (contentDOM) {
3147
+ if (node.isLeaf)
3148
+ throw new RangeError("Content hole not allowed in a leaf node spec");
3149
+ this.serializeFragment(node.content, options, contentDOM);
3150
+ }
3151
+ return dom;
3152
+ }
3153
+ /**
3154
+ Serialize this node to a DOM node. This can be useful when you
3155
+ need to serialize a part of a document, as opposed to the whole
3156
+ document. To serialize a whole document, use
3157
+ [`serializeFragment`](https://prosemirror.net/docs/ref/#model.DOMSerializer.serializeFragment) on
3158
+ its [content](https://prosemirror.net/docs/ref/#model.Node.content).
3159
+ */
3160
+ serializeNode(node, options = {}) {
3161
+ let dom = this.serializeNodeInner(node, options);
3162
+ for (let i = node.marks.length - 1; i >= 0; i--) {
3163
+ let wrap = this.serializeMark(node.marks[i], node.isInline, options);
3164
+ if (wrap) {
3165
+ (wrap.contentDOM || wrap.dom).appendChild(dom);
3166
+ dom = wrap.dom;
3167
+ }
3168
+ }
3169
+ return dom;
3170
+ }
3171
+ /**
3172
+ @internal
3173
+ */
3174
+ serializeMark(mark, inline, options = {}) {
3175
+ let toDOM = this.marks[mark.type.name];
3176
+ return toDOM && _DOMSerializer.renderSpec(doc(options), toDOM(mark, inline));
3177
+ }
3178
+ /**
3179
+ Render an [output spec](https://prosemirror.net/docs/ref/#model.DOMOutputSpec) to a DOM node. If
3180
+ the spec has a hole (zero) in it, `contentDOM` will point at the
3181
+ node with the hole.
3182
+ */
3183
+ static renderSpec(doc2, structure, xmlNS = null) {
3184
+ if (typeof structure == "string")
3185
+ return { dom: doc2.createTextNode(structure) };
3186
+ if (structure.nodeType != null)
3187
+ return { dom: structure };
3188
+ if (structure.dom && structure.dom.nodeType != null)
3189
+ return structure;
3190
+ let tagName = structure[0], space = tagName.indexOf(" ");
3191
+ if (space > 0) {
3192
+ xmlNS = tagName.slice(0, space);
3193
+ tagName = tagName.slice(space + 1);
3194
+ }
3195
+ let contentDOM;
3196
+ let dom = xmlNS ? doc2.createElementNS(xmlNS, tagName) : doc2.createElement(tagName);
3197
+ let attrs = structure[1], start = 1;
3198
+ if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) {
3199
+ start = 2;
3200
+ for (let name in attrs)
3201
+ if (attrs[name] != null) {
3202
+ let space2 = name.indexOf(" ");
3203
+ if (space2 > 0)
3204
+ dom.setAttributeNS(name.slice(0, space2), name.slice(space2 + 1), attrs[name]);
3205
+ else
3206
+ dom.setAttribute(name, attrs[name]);
3207
+ }
3208
+ }
3209
+ for (let i = start; i < structure.length; i++) {
3210
+ let child = structure[i];
3211
+ if (child === 0) {
3212
+ if (i < structure.length - 1 || i > start)
3213
+ throw new RangeError("Content hole must be the only child of its parent node");
3214
+ return { dom, contentDOM: dom };
3215
+ } else {
3216
+ let { dom: inner, contentDOM: innerContent } = _DOMSerializer.renderSpec(doc2, child, xmlNS);
3217
+ dom.appendChild(inner);
3218
+ if (innerContent) {
3219
+ if (contentDOM)
3220
+ throw new RangeError("Multiple content holes");
3221
+ contentDOM = innerContent;
3222
+ }
3223
+ }
3224
+ }
3225
+ return { dom, contentDOM };
3226
+ }
3227
+ /**
3228
+ Build a serializer using the [`toDOM`](https://prosemirror.net/docs/ref/#model.NodeSpec.toDOM)
3229
+ properties in a schema's node and mark specs.
3230
+ */
3231
+ static fromSchema(schema) {
3232
+ return schema.cached.domSerializer || (schema.cached.domSerializer = new _DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema)));
3233
+ }
3234
+ /**
3235
+ Gather the serializers in a schema's node specs into an object.
3236
+ This can be useful as a base to build a custom serializer from.
3237
+ */
3238
+ static nodesFromSchema(schema) {
3239
+ let result = gatherToDOM(schema.nodes);
3240
+ if (!result.text)
3241
+ result.text = (node) => node.text;
3242
+ return result;
3243
+ }
3244
+ /**
3245
+ Gather the serializers in a schema's mark specs into an object.
3246
+ */
3247
+ static marksFromSchema(schema) {
3248
+ return gatherToDOM(schema.marks);
3249
+ }
3250
+ };
3251
+ function gatherToDOM(obj) {
3252
+ let result = {};
3253
+ for (let name in obj) {
3254
+ let toDOM = obj[name].spec.toDOM;
3255
+ if (toDOM)
3256
+ result[name] = toDOM;
3257
+ }
3258
+ return result;
3259
+ }
3260
+ function doc(options) {
3261
+ return options.document || window.document;
3262
+ }
3263
+
3264
+ export {
3265
+ dist_default,
3266
+ Fragment,
3267
+ Mark,
3268
+ ReplaceError,
3269
+ Slice,
3270
+ ResolvedPos,
3271
+ NodeRange,
3272
+ Node,
3273
+ ContentMatch,
3274
+ NodeType,
3275
+ MarkType,
3276
+ Schema,
3277
+ DOMParser,
3278
+ DOMSerializer
3279
+ };