@opengis/form 0.1.19 → 0.1.21

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