···11+// node_modules/prosemirror-model/dist/index.js
22+function findDiffStart(a, b, pos) {
33+ for (let i = 0; ; i++) {
44+ if (i == a.childCount || i == b.childCount)
55+ return a.childCount == b.childCount ? null : pos;
66+ let childA = a.child(i), childB = b.child(i);
77+ if (childA == childB) {
88+ pos += childA.nodeSize;
99+ continue;
1010+ }
1111+ if (!childA.sameMarkup(childB))
1212+ return pos;
1313+ if (childA.isText && childA.text != childB.text) {
1414+ for (let j = 0; childA.text[j] == childB.text[j]; j++)
1515+ pos++;
1616+ return pos;
1717+ }
1818+ if (childA.content.size || childB.content.size) {
1919+ let inner = findDiffStart(childA.content, childB.content, pos + 1);
2020+ if (inner != null)
2121+ return inner;
2222+ }
2323+ pos += childA.nodeSize;
2424+ }
2525+}
2626+function findDiffEnd(a, b, posA, posB) {
2727+ for (let iA = a.childCount, iB = b.childCount; ; ) {
2828+ if (iA == 0 || iB == 0)
2929+ return iA == iB ? null : { a: posA, b: posB };
3030+ let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;
3131+ if (childA == childB) {
3232+ posA -= size;
3333+ posB -= size;
3434+ continue;
3535+ }
3636+ if (!childA.sameMarkup(childB))
3737+ return { a: posA, b: posB };
3838+ if (childA.isText && childA.text != childB.text) {
3939+ let same = 0, minSize = Math.min(childA.text.length, childB.text.length);
4040+ while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {
4141+ same++;
4242+ posA--;
4343+ posB--;
4444+ }
4545+ return { a: posA, b: posB };
4646+ }
4747+ if (childA.content.size || childB.content.size) {
4848+ let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);
4949+ if (inner)
5050+ return inner;
5151+ }
5252+ posA -= size;
5353+ posB -= size;
5454+ }
5555+}
5656+var Fragment = class _Fragment {
5757+ /**
5858+ @internal
5959+ */
6060+ constructor(content, size) {
6161+ this.content = content;
6262+ this.size = size || 0;
6363+ if (size == null)
6464+ for (let i = 0; i < content.length; i++)
6565+ this.size += content[i].nodeSize;
6666+ }
6767+ /**
6868+ Invoke a callback for all descendant nodes between the given two
6969+ positions (relative to start of this fragment). Doesn't descend
7070+ into a node when the callback returns `false`.
7171+ */
7272+ nodesBetween(from, to, f, nodeStart = 0, parent) {
7373+ for (let i = 0, pos = 0; pos < to; i++) {
7474+ let child = this.content[i], end = pos + child.nodeSize;
7575+ if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {
7676+ let start = pos + 1;
7777+ child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);
7878+ }
7979+ pos = end;
8080+ }
8181+ }
8282+ /**
8383+ Call the given callback for every descendant node. `pos` will be
8484+ relative to the start of the fragment. The callback may return
8585+ `false` to prevent traversal of a given node's children.
8686+ */
8787+ descendants(f) {
8888+ this.nodesBetween(0, this.size, f);
8989+ }
9090+ /**
9191+ Extract the text between `from` and `to`. See the same method on
9292+ [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
9393+ */
9494+ textBetween(from, to, blockSeparator, leafText) {
9595+ let text = "", first = true;
9696+ this.nodesBetween(from, to, (node, pos) => {
9797+ let nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : "";
9898+ if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) {
9999+ if (first)
100100+ first = false;
101101+ else
102102+ text += blockSeparator;
103103+ }
104104+ text += nodeText;
105105+ }, 0);
106106+ return text;
107107+ }
108108+ /**
109109+ Create a new fragment containing the combined content of this
110110+ fragment and the other.
111111+ */
112112+ append(other) {
113113+ if (!other.size)
114114+ return this;
115115+ if (!this.size)
116116+ return other;
117117+ let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;
118118+ if (last.isText && last.sameMarkup(first)) {
119119+ content[content.length - 1] = last.withText(last.text + first.text);
120120+ i = 1;
121121+ }
122122+ for (; i < other.content.length; i++)
123123+ content.push(other.content[i]);
124124+ return new _Fragment(content, this.size + other.size);
125125+ }
126126+ /**
127127+ Cut out the sub-fragment between the two given positions.
128128+ */
129129+ cut(from, to = this.size) {
130130+ if (from == 0 && to == this.size)
131131+ return this;
132132+ let result = [], size = 0;
133133+ if (to > from)
134134+ for (let i = 0, pos = 0; pos < to; i++) {
135135+ let child = this.content[i], end = pos + child.nodeSize;
136136+ if (end > from) {
137137+ if (pos < from || end > to) {
138138+ if (child.isText)
139139+ child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));
140140+ else
141141+ child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));
142142+ }
143143+ result.push(child);
144144+ size += child.nodeSize;
145145+ }
146146+ pos = end;
147147+ }
148148+ return new _Fragment(result, size);
149149+ }
150150+ /**
151151+ @internal
152152+ */
153153+ cutByIndex(from, to) {
154154+ if (from == to)
155155+ return _Fragment.empty;
156156+ if (from == 0 && to == this.content.length)
157157+ return this;
158158+ return new _Fragment(this.content.slice(from, to));
159159+ }
160160+ /**
161161+ Create a new fragment in which the node at the given index is
162162+ replaced by the given node.
163163+ */
164164+ replaceChild(index, node) {
165165+ let current = this.content[index];
166166+ if (current == node)
167167+ return this;
168168+ let copy = this.content.slice();
169169+ let size = this.size + node.nodeSize - current.nodeSize;
170170+ copy[index] = node;
171171+ return new _Fragment(copy, size);
172172+ }
173173+ /**
174174+ Create a new fragment by prepending the given node to this
175175+ fragment.
176176+ */
177177+ addToStart(node) {
178178+ return new _Fragment([node].concat(this.content), this.size + node.nodeSize);
179179+ }
180180+ /**
181181+ Create a new fragment by appending the given node to this
182182+ fragment.
183183+ */
184184+ addToEnd(node) {
185185+ return new _Fragment(this.content.concat(node), this.size + node.nodeSize);
186186+ }
187187+ /**
188188+ Compare this fragment to another one.
189189+ */
190190+ eq(other) {
191191+ if (this.content.length != other.content.length)
192192+ return false;
193193+ for (let i = 0; i < this.content.length; i++)
194194+ if (!this.content[i].eq(other.content[i]))
195195+ return false;
196196+ return true;
197197+ }
198198+ /**
199199+ The first child of the fragment, or `null` if it is empty.
200200+ */
201201+ get firstChild() {
202202+ return this.content.length ? this.content[0] : null;
203203+ }
204204+ /**
205205+ The last child of the fragment, or `null` if it is empty.
206206+ */
207207+ get lastChild() {
208208+ return this.content.length ? this.content[this.content.length - 1] : null;
209209+ }
210210+ /**
211211+ The number of child nodes in this fragment.
212212+ */
213213+ get childCount() {
214214+ return this.content.length;
215215+ }
216216+ /**
217217+ Get the child node at the given index. Raise an error when the
218218+ index is out of range.
219219+ */
220220+ child(index) {
221221+ let found2 = this.content[index];
222222+ if (!found2)
223223+ throw new RangeError("Index " + index + " out of range for " + this);
224224+ return found2;
225225+ }
226226+ /**
227227+ Get the child node at the given index, if it exists.
228228+ */
229229+ maybeChild(index) {
230230+ return this.content[index] || null;
231231+ }
232232+ /**
233233+ Call `f` for every child node, passing the node, its offset
234234+ into this parent node, and its index.
235235+ */
236236+ forEach(f) {
237237+ for (let i = 0, p = 0; i < this.content.length; i++) {
238238+ let child = this.content[i];
239239+ f(child, p, i);
240240+ p += child.nodeSize;
241241+ }
242242+ }
243243+ /**
244244+ Find the first position at which this fragment and another
245245+ fragment differ, or `null` if they are the same.
246246+ */
247247+ findDiffStart(other, pos = 0) {
248248+ return findDiffStart(this, other, pos);
249249+ }
250250+ /**
251251+ Find the first position, searching from the end, at which this
252252+ fragment and the given fragment differ, or `null` if they are
253253+ the same. Since this position will not be the same in both
254254+ nodes, an object with two separate positions is returned.
255255+ */
256256+ findDiffEnd(other, pos = this.size, otherPos = other.size) {
257257+ return findDiffEnd(this, other, pos, otherPos);
258258+ }
259259+ /**
260260+ Find the index and inner offset corresponding to a given relative
261261+ position in this fragment. The result object will be reused
262262+ (overwritten) the next time the function is called. @internal
263263+ */
264264+ findIndex(pos) {
265265+ if (pos == 0)
266266+ return retIndex(0, pos);
267267+ if (pos == this.size)
268268+ return retIndex(this.content.length, pos);
269269+ if (pos > this.size || pos < 0)
270270+ throw new RangeError(`Position ${pos} outside of fragment (${this})`);
271271+ for (let i = 0, curPos = 0; ; i++) {
272272+ let cur = this.child(i), end = curPos + cur.nodeSize;
273273+ if (end >= pos) {
274274+ if (end == pos)
275275+ return retIndex(i + 1, end);
276276+ return retIndex(i, curPos);
277277+ }
278278+ curPos = end;
279279+ }
280280+ }
281281+ /**
282282+ Return a debugging string that describes this fragment.
283283+ */
284284+ toString() {
285285+ return "<" + this.toStringInner() + ">";
286286+ }
287287+ /**
288288+ @internal
289289+ */
290290+ toStringInner() {
291291+ return this.content.join(", ");
292292+ }
293293+ /**
294294+ Create a JSON-serializeable representation of this fragment.
295295+ */
296296+ toJSON() {
297297+ return this.content.length ? this.content.map((n) => n.toJSON()) : null;
298298+ }
299299+ /**
300300+ Deserialize a fragment from its JSON representation.
301301+ */
302302+ static fromJSON(schema, value) {
303303+ if (!value)
304304+ return _Fragment.empty;
305305+ if (!Array.isArray(value))
306306+ throw new RangeError("Invalid input for Fragment.fromJSON");
307307+ return new _Fragment(value.map(schema.nodeFromJSON));
308308+ }
309309+ /**
310310+ Build a fragment from an array of nodes. Ensures that adjacent
311311+ text nodes with the same marks are joined together.
312312+ */
313313+ static fromArray(array) {
314314+ if (!array.length)
315315+ return _Fragment.empty;
316316+ let joined, size = 0;
317317+ for (let i = 0; i < array.length; i++) {
318318+ let node = array[i];
319319+ size += node.nodeSize;
320320+ if (i && node.isText && array[i - 1].sameMarkup(node)) {
321321+ if (!joined)
322322+ joined = array.slice(0, i);
323323+ joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text);
324324+ } else if (joined) {
325325+ joined.push(node);
326326+ }
327327+ }
328328+ return new _Fragment(joined || array, size);
329329+ }
330330+ /**
331331+ Create a fragment from something that can be interpreted as a
332332+ set of nodes. For `null`, it returns the empty fragment. For a
333333+ fragment, the fragment itself. For a node or array of nodes, a
334334+ fragment containing those nodes.
335335+ */
336336+ static from(nodes) {
337337+ if (!nodes)
338338+ return _Fragment.empty;
339339+ if (nodes instanceof _Fragment)
340340+ return nodes;
341341+ if (Array.isArray(nodes))
342342+ return this.fromArray(nodes);
343343+ if (nodes.attrs)
344344+ return new _Fragment([nodes], nodes.nodeSize);
345345+ throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
346346+ }
347347+};
348348+Fragment.empty = new Fragment([], 0);
349349+var found = { index: 0, offset: 0 };
350350+function retIndex(index, offset) {
351351+ found.index = index;
352352+ found.offset = offset;
353353+ return found;
354354+}
355355+function compareDeep(a, b) {
356356+ if (a === b)
357357+ return true;
358358+ if (!(a && typeof a == "object") || !(b && typeof b == "object"))
359359+ return false;
360360+ let array = Array.isArray(a);
361361+ if (Array.isArray(b) != array)
362362+ return false;
363363+ if (array) {
364364+ if (a.length != b.length)
365365+ return false;
366366+ for (let i = 0; i < a.length; i++)
367367+ if (!compareDeep(a[i], b[i]))
368368+ return false;
369369+ } else {
370370+ for (let p in a)
371371+ if (!(p in b) || !compareDeep(a[p], b[p]))
372372+ return false;
373373+ for (let p in b)
374374+ if (!(p in a))
375375+ return false;
376376+ }
377377+ return true;
378378+}
379379+var Mark = class _Mark {
380380+ /**
381381+ @internal
382382+ */
383383+ constructor(type, attrs) {
384384+ this.type = type;
385385+ this.attrs = attrs;
386386+ }
387387+ /**
388388+ Given a set of marks, create a new set which contains this one as
389389+ well, in the right position. If this mark is already in the set,
390390+ the set itself is returned. If any marks that are set to be
391391+ [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
392392+ those are replaced by this one.
393393+ */
394394+ addToSet(set) {
395395+ let copy, placed = false;
396396+ for (let i = 0; i < set.length; i++) {
397397+ let other = set[i];
398398+ if (this.eq(other))
399399+ return set;
400400+ if (this.type.excludes(other.type)) {
401401+ if (!copy)
402402+ copy = set.slice(0, i);
403403+ } else if (other.type.excludes(this.type)) {
404404+ return set;
405405+ } else {
406406+ if (!placed && other.type.rank > this.type.rank) {
407407+ if (!copy)
408408+ copy = set.slice(0, i);
409409+ copy.push(this);
410410+ placed = true;
411411+ }
412412+ if (copy)
413413+ copy.push(other);
414414+ }
415415+ }
416416+ if (!copy)
417417+ copy = set.slice();
418418+ if (!placed)
419419+ copy.push(this);
420420+ return copy;
421421+ }
422422+ /**
423423+ Remove this mark from the given set, returning a new set. If this
424424+ mark is not in the set, the set itself is returned.
425425+ */
426426+ removeFromSet(set) {
427427+ for (let i = 0; i < set.length; i++)
428428+ if (this.eq(set[i]))
429429+ return set.slice(0, i).concat(set.slice(i + 1));
430430+ return set;
431431+ }
432432+ /**
433433+ Test whether this mark is in the given set of marks.
434434+ */
435435+ isInSet(set) {
436436+ for (let i = 0; i < set.length; i++)
437437+ if (this.eq(set[i]))
438438+ return true;
439439+ return false;
440440+ }
441441+ /**
442442+ Test whether this mark has the same type and attributes as
443443+ another mark.
444444+ */
445445+ eq(other) {
446446+ return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs);
447447+ }
448448+ /**
449449+ Convert this mark to a JSON-serializeable representation.
450450+ */
451451+ toJSON() {
452452+ let obj = { type: this.type.name };
453453+ for (let _ in this.attrs) {
454454+ obj.attrs = this.attrs;
455455+ break;
456456+ }
457457+ return obj;
458458+ }
459459+ /**
460460+ Deserialize a mark from JSON.
461461+ */
462462+ static fromJSON(schema, json) {
463463+ if (!json)
464464+ throw new RangeError("Invalid input for Mark.fromJSON");
465465+ let type = schema.marks[json.type];
466466+ if (!type)
467467+ throw new RangeError(`There is no mark type ${json.type} in this schema`);
468468+ let mark = type.create(json.attrs);
469469+ type.checkAttrs(mark.attrs);
470470+ return mark;
471471+ }
472472+ /**
473473+ Test whether two sets of marks are identical.
474474+ */
475475+ static sameSet(a, b) {
476476+ if (a == b)
477477+ return true;
478478+ if (a.length != b.length)
479479+ return false;
480480+ for (let i = 0; i < a.length; i++)
481481+ if (!a[i].eq(b[i]))
482482+ return false;
483483+ return true;
484484+ }
485485+ /**
486486+ Create a properly sorted mark set from null, a single mark, or an
487487+ unsorted array of marks.
488488+ */
489489+ static setFrom(marks) {
490490+ if (!marks || Array.isArray(marks) && marks.length == 0)
491491+ return _Mark.none;
492492+ if (marks instanceof _Mark)
493493+ return [marks];
494494+ let copy = marks.slice();
495495+ copy.sort((a, b) => a.type.rank - b.type.rank);
496496+ return copy;
497497+ }
498498+};
499499+Mark.none = [];
500500+var ReplaceError = class extends Error {
501501+};
502502+var Slice = class _Slice {
503503+ /**
504504+ Create a slice. When specifying a non-zero open depth, you must
505505+ make sure that there are nodes of at least that depth at the
506506+ appropriate side of the fragment—i.e. if the fragment is an
507507+ empty paragraph node, `openStart` and `openEnd` can't be greater
508508+ than 1.
509509+510510+ It is not necessary for the content of open nodes to conform to
511511+ the schema's content constraints, though it should be a valid
512512+ start/end/middle for such a node, depending on which sides are
513513+ open.
514514+ */
515515+ constructor(content, openStart, openEnd) {
516516+ this.content = content;
517517+ this.openStart = openStart;
518518+ this.openEnd = openEnd;
519519+ }
520520+ /**
521521+ The size this slice would add when inserted into a document.
522522+ */
523523+ get size() {
524524+ return this.content.size - this.openStart - this.openEnd;
525525+ }
526526+ /**
527527+ @internal
528528+ */
529529+ insertAt(pos, fragment) {
530530+ let content = insertInto(this.content, pos + this.openStart, fragment);
531531+ return content && new _Slice(content, this.openStart, this.openEnd);
532532+ }
533533+ /**
534534+ @internal
535535+ */
536536+ removeBetween(from, to) {
537537+ return new _Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);
538538+ }
539539+ /**
540540+ Tests whether this slice is equal to another slice.
541541+ */
542542+ eq(other) {
543543+ return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;
544544+ }
545545+ /**
546546+ @internal
547547+ */
548548+ toString() {
549549+ return this.content + "(" + this.openStart + "," + this.openEnd + ")";
550550+ }
551551+ /**
552552+ Convert a slice to a JSON-serializable representation.
553553+ */
554554+ toJSON() {
555555+ if (!this.content.size)
556556+ return null;
557557+ let json = { content: this.content.toJSON() };
558558+ if (this.openStart > 0)
559559+ json.openStart = this.openStart;
560560+ if (this.openEnd > 0)
561561+ json.openEnd = this.openEnd;
562562+ return json;
563563+ }
564564+ /**
565565+ Deserialize a slice from its JSON representation.
566566+ */
567567+ static fromJSON(schema, json) {
568568+ if (!json)
569569+ return _Slice.empty;
570570+ let openStart = json.openStart || 0, openEnd = json.openEnd || 0;
571571+ if (typeof openStart != "number" || typeof openEnd != "number")
572572+ throw new RangeError("Invalid input for Slice.fromJSON");
573573+ return new _Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd);
574574+ }
575575+ /**
576576+ Create a slice from a fragment by taking the maximum possible
577577+ open value on both side of the fragment.
578578+ */
579579+ static maxOpen(fragment, openIsolating = true) {
580580+ let openStart = 0, openEnd = 0;
581581+ for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild)
582582+ openStart++;
583583+ for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild)
584584+ openEnd++;
585585+ return new _Slice(fragment, openStart, openEnd);
586586+ }
587587+};
588588+Slice.empty = new Slice(Fragment.empty, 0, 0);
589589+function removeRange(content, from, to) {
590590+ let { index, offset } = content.findIndex(from), child = content.maybeChild(index);
591591+ let { index: indexTo, offset: offsetTo } = content.findIndex(to);
592592+ if (offset == from || child.isText) {
593593+ if (offsetTo != to && !content.child(indexTo).isText)
594594+ throw new RangeError("Removing non-flat range");
595595+ return content.cut(0, from).append(content.cut(to));
596596+ }
597597+ if (index != indexTo)
598598+ throw new RangeError("Removing non-flat range");
599599+ return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
600600+}
601601+function insertInto(content, dist, insert, parent) {
602602+ let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
603603+ if (offset == dist || child.isText) {
604604+ if (parent && !parent.canReplace(index, index, insert))
605605+ return null;
606606+ return content.cut(0, dist).append(insert).append(content.cut(dist));
607607+ }
608608+ let inner = insertInto(child.content, dist - offset - 1, insert, child);
609609+ return inner && content.replaceChild(index, child.copy(inner));
610610+}
611611+function replace($from, $to, slice) {
612612+ if (slice.openStart > $from.depth)
613613+ throw new ReplaceError("Inserted content deeper than insertion position");
614614+ if ($from.depth - slice.openStart != $to.depth - slice.openEnd)
615615+ throw new ReplaceError("Inconsistent open depths");
616616+ return replaceOuter($from, $to, slice, 0);
617617+}
618618+function replaceOuter($from, $to, slice, depth) {
619619+ let index = $from.index(depth), node = $from.node(depth);
620620+ if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {
621621+ let inner = replaceOuter($from, $to, slice, depth + 1);
622622+ return node.copy(node.content.replaceChild(index, inner));
623623+ } else if (!slice.content.size) {
624624+ return close(node, replaceTwoWay($from, $to, depth));
625625+ } else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) {
626626+ let parent = $from.parent, content = parent.content;
627627+ return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));
628628+ } else {
629629+ let { start, end } = prepareSliceForReplace(slice, $from);
630630+ return close(node, replaceThreeWay($from, start, end, $to, depth));
631631+ }
632632+}
633633+function checkJoin(main, sub) {
634634+ if (!sub.type.compatibleContent(main.type))
635635+ throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
636636+}
637637+function joinable($before, $after, depth) {
638638+ let node = $before.node(depth);
639639+ checkJoin(node, $after.node(depth));
640640+ return node;
641641+}
642642+function addNode(child, target) {
643643+ let last = target.length - 1;
644644+ if (last >= 0 && child.isText && child.sameMarkup(target[last]))
645645+ target[last] = child.withText(target[last].text + child.text);
646646+ else
647647+ target.push(child);
648648+}
649649+function addRange($start, $end, depth, target) {
650650+ let node = ($end || $start).node(depth);
651651+ let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;
652652+ if ($start) {
653653+ startIndex = $start.index(depth);
654654+ if ($start.depth > depth) {
655655+ startIndex++;
656656+ } else if ($start.textOffset) {
657657+ addNode($start.nodeAfter, target);
658658+ startIndex++;
659659+ }
660660+ }
661661+ for (let i = startIndex; i < endIndex; i++)
662662+ addNode(node.child(i), target);
663663+ if ($end && $end.depth == depth && $end.textOffset)
664664+ addNode($end.nodeBefore, target);
665665+}
666666+function close(node, content) {
667667+ node.type.checkContent(content);
668668+ return node.copy(content);
669669+}
670670+function replaceThreeWay($from, $start, $end, $to, depth) {
671671+ let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
672672+ let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
673673+ let content = [];
674674+ addRange(null, $from, depth, content);
675675+ if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
676676+ checkJoin(openStart, openEnd);
677677+ addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);
678678+ } else {
679679+ if (openStart)
680680+ addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);
681681+ addRange($start, $end, depth, content);
682682+ if (openEnd)
683683+ addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);
684684+ }
685685+ addRange($to, null, depth, content);
686686+ return new Fragment(content);
687687+}
688688+function replaceTwoWay($from, $to, depth) {
689689+ let content = [];
690690+ addRange(null, $from, depth, content);
691691+ if ($from.depth > depth) {
692692+ let type = joinable($from, $to, depth + 1);
693693+ addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);
694694+ }
695695+ addRange($to, null, depth, content);
696696+ return new Fragment(content);
697697+}
698698+function prepareSliceForReplace(slice, $along) {
699699+ let extra = $along.depth - slice.openStart, parent = $along.node(extra);
700700+ let node = parent.copy(slice.content);
701701+ for (let i = extra - 1; i >= 0; i--)
702702+ node = $along.node(i).copy(Fragment.from(node));
703703+ return {
704704+ start: node.resolveNoCache(slice.openStart + extra),
705705+ end: node.resolveNoCache(node.content.size - slice.openEnd - extra)
706706+ };
707707+}
708708+var ResolvedPos = class _ResolvedPos {
709709+ /**
710710+ @internal
711711+ */
712712+ constructor(pos, path, parentOffset) {
713713+ this.pos = pos;
714714+ this.path = path;
715715+ this.parentOffset = parentOffset;
716716+ this.depth = path.length / 3 - 1;
717717+ }
718718+ /**
719719+ @internal
720720+ */
721721+ resolveDepth(val) {
722722+ if (val == null)
723723+ return this.depth;
724724+ if (val < 0)
725725+ return this.depth + val;
726726+ return val;
727727+ }
728728+ /**
729729+ The parent node that the position points into. Note that even if
730730+ a position points into a text node, that node is not considered
731731+ the parent—text nodes are ‘flat’ in this model, and have no content.
732732+ */
733733+ get parent() {
734734+ return this.node(this.depth);
735735+ }
736736+ /**
737737+ The root node in which the position was resolved.
738738+ */
739739+ get doc() {
740740+ return this.node(0);
741741+ }
742742+ /**
743743+ The ancestor node at the given level. `p.node(p.depth)` is the
744744+ same as `p.parent`.
745745+ */
746746+ node(depth) {
747747+ return this.path[this.resolveDepth(depth) * 3];
748748+ }
749749+ /**
750750+ The index into the ancestor at the given level. If this points
751751+ at the 3rd node in the 2nd paragraph on the top level, for
752752+ example, `p.index(0)` is 1 and `p.index(1)` is 2.
753753+ */
754754+ index(depth) {
755755+ return this.path[this.resolveDepth(depth) * 3 + 1];
756756+ }
757757+ /**
758758+ The index pointing after this position into the ancestor at the
759759+ given level.
760760+ */
761761+ indexAfter(depth) {
762762+ depth = this.resolveDepth(depth);
763763+ return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);
764764+ }
765765+ /**
766766+ The (absolute) position at the start of the node at the given
767767+ level.
768768+ */
769769+ start(depth) {
770770+ depth = this.resolveDepth(depth);
771771+ return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
772772+ }
773773+ /**
774774+ The (absolute) position at the end of the node at the given
775775+ level.
776776+ */
777777+ end(depth) {
778778+ depth = this.resolveDepth(depth);
779779+ return this.start(depth) + this.node(depth).content.size;
780780+ }
781781+ /**
782782+ The (absolute) position directly before the wrapping node at the
783783+ given level, or, when `depth` is `this.depth + 1`, the original
784784+ position.
785785+ */
786786+ before(depth) {
787787+ depth = this.resolveDepth(depth);
788788+ if (!depth)
789789+ throw new RangeError("There is no position before the top-level node");
790790+ return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];
791791+ }
792792+ /**
793793+ The (absolute) position directly after the wrapping node at the
794794+ given level, or the original position when `depth` is `this.depth + 1`.
795795+ */
796796+ after(depth) {
797797+ depth = this.resolveDepth(depth);
798798+ if (!depth)
799799+ throw new RangeError("There is no position after the top-level node");
800800+ return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;
801801+ }
802802+ /**
803803+ When this position points into a text node, this returns the
804804+ distance between the position and the start of the text node.
805805+ Will be zero for positions that point between nodes.
806806+ */
807807+ get textOffset() {
808808+ return this.pos - this.path[this.path.length - 1];
809809+ }
810810+ /**
811811+ Get the node directly after the position, if any. If the position
812812+ points into a text node, only the part of that node after the
813813+ position is returned.
814814+ */
815815+ get nodeAfter() {
816816+ let parent = this.parent, index = this.index(this.depth);
817817+ if (index == parent.childCount)
818818+ return null;
819819+ let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);
820820+ return dOff ? parent.child(index).cut(dOff) : child;
821821+ }
822822+ /**
823823+ Get the node directly before the position, if any. If the
824824+ position points into a text node, only the part of that node
825825+ before the position is returned.
826826+ */
827827+ get nodeBefore() {
828828+ let index = this.index(this.depth);
829829+ let dOff = this.pos - this.path[this.path.length - 1];
830830+ if (dOff)
831831+ return this.parent.child(index).cut(0, dOff);
832832+ return index == 0 ? null : this.parent.child(index - 1);
833833+ }
834834+ /**
835835+ Get the position at the given index in the parent node at the
836836+ given depth (which defaults to `this.depth`).
837837+ */
838838+ posAtIndex(index, depth) {
839839+ depth = this.resolveDepth(depth);
840840+ let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
841841+ for (let i = 0; i < index; i++)
842842+ pos += node.child(i).nodeSize;
843843+ return pos;
844844+ }
845845+ /**
846846+ Get the marks at this position, factoring in the surrounding
847847+ marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the
848848+ position is at the start of a non-empty node, the marks of the
849849+ node after it (if any) are returned.
850850+ */
851851+ marks() {
852852+ let parent = this.parent, index = this.index();
853853+ if (parent.content.size == 0)
854854+ return Mark.none;
855855+ if (this.textOffset)
856856+ return parent.child(index).marks;
857857+ let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);
858858+ if (!main) {
859859+ let tmp = main;
860860+ main = other;
861861+ other = tmp;
862862+ }
863863+ let marks = main.marks;
864864+ for (var i = 0; i < marks.length; i++)
865865+ if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks)))
866866+ marks = marks[i--].removeFromSet(marks);
867867+ return marks;
868868+ }
869869+ /**
870870+ Get the marks after the current position, if any, except those
871871+ that are non-inclusive and not present at position `$end`. This
872872+ is mostly useful for getting the set of marks to preserve after a
873873+ deletion. Will return `null` if this position is at the end of
874874+ its parent node or its parent node isn't a textblock (in which
875875+ case no marks should be preserved).
876876+ */
877877+ marksAcross($end) {
878878+ let after = this.parent.maybeChild(this.index());
879879+ if (!after || !after.isInline)
880880+ return null;
881881+ let marks = after.marks, next = $end.parent.maybeChild($end.index());
882882+ for (var i = 0; i < marks.length; i++)
883883+ if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks)))
884884+ marks = marks[i--].removeFromSet(marks);
885885+ return marks;
886886+ }
887887+ /**
888888+ The depth up to which this position and the given (non-resolved)
889889+ position share the same parent nodes.
890890+ */
891891+ sharedDepth(pos) {
892892+ for (let depth = this.depth; depth > 0; depth--)
893893+ if (this.start(depth) <= pos && this.end(depth) >= pos)
894894+ return depth;
895895+ return 0;
896896+ }
897897+ /**
898898+ Returns a range based on the place where this position and the
899899+ given position diverge around block content. If both point into
900900+ the same textblock, for example, a range around that textblock
901901+ will be returned. If they point into different blocks, the range
902902+ around those blocks in their shared ancestor is returned. You can
903903+ pass in an optional predicate that will be called with a parent
904904+ node to see if a range into that parent is acceptable.
905905+ */
906906+ blockRange(other = this, pred) {
907907+ if (other.pos < this.pos)
908908+ return other.blockRange(this);
909909+ for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--)
910910+ if (other.pos <= this.end(d) && (!pred || pred(this.node(d))))
911911+ return new NodeRange(this, other, d);
912912+ return null;
913913+ }
914914+ /**
915915+ Query whether the given position shares the same parent node.
916916+ */
917917+ sameParent(other) {
918918+ return this.pos - this.parentOffset == other.pos - other.parentOffset;
919919+ }
920920+ /**
921921+ Return the greater of this and the given position.
922922+ */
923923+ max(other) {
924924+ return other.pos > this.pos ? other : this;
925925+ }
926926+ /**
927927+ Return the smaller of this and the given position.
928928+ */
929929+ min(other) {
930930+ return other.pos < this.pos ? other : this;
931931+ }
932932+ /**
933933+ @internal
934934+ */
935935+ toString() {
936936+ let str = "";
937937+ for (let i = 1; i <= this.depth; i++)
938938+ str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1);
939939+ return str + ":" + this.parentOffset;
940940+ }
941941+ /**
942942+ @internal
943943+ */
944944+ static resolve(doc, pos) {
945945+ if (!(pos >= 0 && pos <= doc.content.size))
946946+ throw new RangeError("Position " + pos + " out of range");
947947+ let path = [];
948948+ let start = 0, parentOffset = pos;
949949+ for (let node = doc; ; ) {
950950+ let { index, offset } = node.content.findIndex(parentOffset);
951951+ let rem = parentOffset - offset;
952952+ path.push(node, index, start + offset);
953953+ if (!rem)
954954+ break;
955955+ node = node.child(index);
956956+ if (node.isText)
957957+ break;
958958+ parentOffset = rem - 1;
959959+ start += offset + 1;
960960+ }
961961+ return new _ResolvedPos(pos, path, parentOffset);
962962+ }
963963+ /**
964964+ @internal
965965+ */
966966+ static resolveCached(doc, pos) {
967967+ let cache = resolveCache.get(doc);
968968+ if (cache) {
969969+ for (let i = 0; i < cache.elts.length; i++) {
970970+ let elt = cache.elts[i];
971971+ if (elt.pos == pos)
972972+ return elt;
973973+ }
974974+ } else {
975975+ resolveCache.set(doc, cache = new ResolveCache());
976976+ }
977977+ let result = cache.elts[cache.i] = _ResolvedPos.resolve(doc, pos);
978978+ cache.i = (cache.i + 1) % resolveCacheSize;
979979+ return result;
980980+ }
981981+};
982982+var ResolveCache = class {
983983+ constructor() {
984984+ this.elts = [];
985985+ this.i = 0;
986986+ }
987987+};
988988+var resolveCacheSize = 12;
989989+var resolveCache = /* @__PURE__ */ new WeakMap();
990990+var NodeRange = class {
991991+ /**
992992+ Construct a node range. `$from` and `$to` should point into the
993993+ same node until at least the given `depth`, since a node range
994994+ denotes an adjacent set of nodes in a single parent node.
995995+ */
996996+ constructor($from, $to, depth) {
997997+ this.$from = $from;
998998+ this.$to = $to;
999999+ this.depth = depth;
10001000+ }
10011001+ /**
10021002+ The position at the start of the range.
10031003+ */
10041004+ get start() {
10051005+ return this.$from.before(this.depth + 1);
10061006+ }
10071007+ /**
10081008+ The position at the end of the range.
10091009+ */
10101010+ get end() {
10111011+ return this.$to.after(this.depth + 1);
10121012+ }
10131013+ /**
10141014+ The parent node that the range points into.
10151015+ */
10161016+ get parent() {
10171017+ return this.$from.node(this.depth);
10181018+ }
10191019+ /**
10201020+ The start index of the range in the parent node.
10211021+ */
10221022+ get startIndex() {
10231023+ return this.$from.index(this.depth);
10241024+ }
10251025+ /**
10261026+ The end index of the range in the parent node.
10271027+ */
10281028+ get endIndex() {
10291029+ return this.$to.indexAfter(this.depth);
10301030+ }
10311031+};
10321032+var emptyAttrs = /* @__PURE__ */ Object.create(null);
10331033+var Node = class _Node {
10341034+ /**
10351035+ @internal
10361036+ */
10371037+ constructor(type, attrs, content, marks = Mark.none) {
10381038+ this.type = type;
10391039+ this.attrs = attrs;
10401040+ this.marks = marks;
10411041+ this.content = content || Fragment.empty;
10421042+ }
10431043+ /**
10441044+ The array of this node's child nodes.
10451045+ */
10461046+ get children() {
10471047+ return this.content.content;
10481048+ }
10491049+ /**
10501050+ The size of this node, as defined by the integer-based [indexing
10511051+ scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
10521052+ amount of characters. For other leaf nodes, it is one. For
10531053+ non-leaf nodes, it is the size of the content plus two (the
10541054+ start and end token).
10551055+ */
10561056+ get nodeSize() {
10571057+ return this.isLeaf ? 1 : 2 + this.content.size;
10581058+ }
10591059+ /**
10601060+ The number of children that the node has.
10611061+ */
10621062+ get childCount() {
10631063+ return this.content.childCount;
10641064+ }
10651065+ /**
10661066+ Get the child node at the given index. Raises an error when the
10671067+ index is out of range.
10681068+ */
10691069+ child(index) {
10701070+ return this.content.child(index);
10711071+ }
10721072+ /**
10731073+ Get the child node at the given index, if it exists.
10741074+ */
10751075+ maybeChild(index) {
10761076+ return this.content.maybeChild(index);
10771077+ }
10781078+ /**
10791079+ Call `f` for every child node, passing the node, its offset
10801080+ into this parent node, and its index.
10811081+ */
10821082+ forEach(f) {
10831083+ this.content.forEach(f);
10841084+ }
10851085+ /**
10861086+ Invoke a callback for all descendant nodes recursively between
10871087+ the given two positions that are relative to start of this
10881088+ node's content. The callback is invoked with the node, its
10891089+ position relative to the original node (method receiver),
10901090+ its parent node, and its child index. When the callback returns
10911091+ false for a given node, that node's children will not be
10921092+ recursed over. The last parameter can be used to specify a
10931093+ starting position to count from.
10941094+ */
10951095+ nodesBetween(from, to, f, startPos = 0) {
10961096+ this.content.nodesBetween(from, to, f, startPos, this);
10971097+ }
10981098+ /**
10991099+ Call the given callback for every descendant node. Doesn't
11001100+ descend into a node when the callback returns `false`.
11011101+ */
11021102+ descendants(f) {
11031103+ this.nodesBetween(0, this.content.size, f);
11041104+ }
11051105+ /**
11061106+ Concatenates all the text nodes found in this fragment and its
11071107+ children.
11081108+ */
11091109+ get textContent() {
11101110+ return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
11111111+ }
11121112+ /**
11131113+ Get all text between positions `from` and `to`. When
11141114+ `blockSeparator` is given, it will be inserted to separate text
11151115+ from different block nodes. If `leafText` is given, it'll be
11161116+ inserted for every non-text leaf node encountered, otherwise
11171117+ [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.
11181118+ */
11191119+ textBetween(from, to, blockSeparator, leafText) {
11201120+ return this.content.textBetween(from, to, blockSeparator, leafText);
11211121+ }
11221122+ /**
11231123+ Returns this node's first child, or `null` if there are no
11241124+ children.
11251125+ */
11261126+ get firstChild() {
11271127+ return this.content.firstChild;
11281128+ }
11291129+ /**
11301130+ Returns this node's last child, or `null` if there are no
11311131+ children.
11321132+ */
11331133+ get lastChild() {
11341134+ return this.content.lastChild;
11351135+ }
11361136+ /**
11371137+ Test whether two nodes represent the same piece of document.
11381138+ */
11391139+ eq(other) {
11401140+ return this == other || this.sameMarkup(other) && this.content.eq(other.content);
11411141+ }
11421142+ /**
11431143+ Compare the markup (type, attributes, and marks) of this node to
11441144+ those of another. Returns `true` if both have the same markup.
11451145+ */
11461146+ sameMarkup(other) {
11471147+ return this.hasMarkup(other.type, other.attrs, other.marks);
11481148+ }
11491149+ /**
11501150+ Check whether this node's markup correspond to the given type,
11511151+ attributes, and marks.
11521152+ */
11531153+ hasMarkup(type, attrs, marks) {
11541154+ return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none);
11551155+ }
11561156+ /**
11571157+ Create a new node with the same markup as this node, containing
11581158+ the given content (or empty, if no content is given).
11591159+ */
11601160+ copy(content = null) {
11611161+ if (content == this.content)
11621162+ return this;
11631163+ return new _Node(this.type, this.attrs, content, this.marks);
11641164+ }
11651165+ /**
11661166+ Create a copy of this node, with the given set of marks instead
11671167+ of the node's own marks.
11681168+ */
11691169+ mark(marks) {
11701170+ return marks == this.marks ? this : new _Node(this.type, this.attrs, this.content, marks);
11711171+ }
11721172+ /**
11731173+ Create a copy of this node with only the content between the
11741174+ given positions. If `to` is not given, it defaults to the end of
11751175+ the node.
11761176+ */
11771177+ cut(from, to = this.content.size) {
11781178+ if (from == 0 && to == this.content.size)
11791179+ return this;
11801180+ return this.copy(this.content.cut(from, to));
11811181+ }
11821182+ /**
11831183+ Cut out the part of the document between the given positions, and
11841184+ return it as a `Slice` object.
11851185+ */
11861186+ slice(from, to = this.content.size, includeParents = false) {
11871187+ if (from == to)
11881188+ return Slice.empty;
11891189+ let $from = this.resolve(from), $to = this.resolve(to);
11901190+ let depth = includeParents ? 0 : $from.sharedDepth(to);
11911191+ let start = $from.start(depth), node = $from.node(depth);
11921192+ let content = node.content.cut($from.pos - start, $to.pos - start);
11931193+ return new Slice(content, $from.depth - depth, $to.depth - depth);
11941194+ }
11951195+ /**
11961196+ Replace the part of the document between the given positions with
11971197+ the given slice. The slice must 'fit', meaning its open sides
11981198+ must be able to connect to the surrounding content, and its
11991199+ content nodes must be valid children for the node they are placed
12001200+ into. If any of this is violated, an error of type
12011201+ [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
12021202+ */
12031203+ replace(from, to, slice) {
12041204+ return replace(this.resolve(from), this.resolve(to), slice);
12051205+ }
12061206+ /**
12071207+ Find the node directly after the given position.
12081208+ */
12091209+ nodeAt(pos) {
12101210+ for (let node = this; ; ) {
12111211+ let { index, offset } = node.content.findIndex(pos);
12121212+ node = node.maybeChild(index);
12131213+ if (!node)
12141214+ return null;
12151215+ if (offset == pos || node.isText)
12161216+ return node;
12171217+ pos -= offset + 1;
12181218+ }
12191219+ }
12201220+ /**
12211221+ Find the (direct) child node after the given offset, if any,
12221222+ and return it along with its index and offset relative to this
12231223+ node.
12241224+ */
12251225+ childAfter(pos) {
12261226+ let { index, offset } = this.content.findIndex(pos);
12271227+ return { node: this.content.maybeChild(index), index, offset };
12281228+ }
12291229+ /**
12301230+ Find the (direct) child node before the given offset, if any,
12311231+ and return it along with its index and offset relative to this
12321232+ node.
12331233+ */
12341234+ childBefore(pos) {
12351235+ if (pos == 0)
12361236+ return { node: null, index: 0, offset: 0 };
12371237+ let { index, offset } = this.content.findIndex(pos);
12381238+ if (offset < pos)
12391239+ return { node: this.content.child(index), index, offset };
12401240+ let node = this.content.child(index - 1);
12411241+ return { node, index: index - 1, offset: offset - node.nodeSize };
12421242+ }
12431243+ /**
12441244+ Resolve the given position in the document, returning an
12451245+ [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
12461246+ */
12471247+ resolve(pos) {
12481248+ return ResolvedPos.resolveCached(this, pos);
12491249+ }
12501250+ /**
12511251+ @internal
12521252+ */
12531253+ resolveNoCache(pos) {
12541254+ return ResolvedPos.resolve(this, pos);
12551255+ }
12561256+ /**
12571257+ Test whether a given mark or mark type occurs in this document
12581258+ between the two given positions.
12591259+ */
12601260+ rangeHasMark(from, to, type) {
12611261+ let found2 = false;
12621262+ if (to > from)
12631263+ this.nodesBetween(from, to, (node) => {
12641264+ if (type.isInSet(node.marks))
12651265+ found2 = true;
12661266+ return !found2;
12671267+ });
12681268+ return found2;
12691269+ }
12701270+ /**
12711271+ True when this is a block (non-inline node)
12721272+ */
12731273+ get isBlock() {
12741274+ return this.type.isBlock;
12751275+ }
12761276+ /**
12771277+ True when this is a textblock node, a block node with inline
12781278+ content.
12791279+ */
12801280+ get isTextblock() {
12811281+ return this.type.isTextblock;
12821282+ }
12831283+ /**
12841284+ True when this node allows inline content.
12851285+ */
12861286+ get inlineContent() {
12871287+ return this.type.inlineContent;
12881288+ }
12891289+ /**
12901290+ True when this is an inline node (a text node or a node that can
12911291+ appear among text).
12921292+ */
12931293+ get isInline() {
12941294+ return this.type.isInline;
12951295+ }
12961296+ /**
12971297+ True when this is a text node.
12981298+ */
12991299+ get isText() {
13001300+ return this.type.isText;
13011301+ }
13021302+ /**
13031303+ True when this is a leaf node.
13041304+ */
13051305+ get isLeaf() {
13061306+ return this.type.isLeaf;
13071307+ }
13081308+ /**
13091309+ True when this is an atom, i.e. when it does not have directly
13101310+ editable content. This is usually the same as `isLeaf`, but can
13111311+ be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
13121312+ on a node's spec (typically used when the node is displayed as
13131313+ an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
13141314+ */
13151315+ get isAtom() {
13161316+ return this.type.isAtom;
13171317+ }
13181318+ /**
13191319+ Return a string representation of this node for debugging
13201320+ purposes.
13211321+ */
13221322+ toString() {
13231323+ if (this.type.spec.toDebugString)
13241324+ return this.type.spec.toDebugString(this);
13251325+ let name = this.type.name;
13261326+ if (this.content.size)
13271327+ name += "(" + this.content.toStringInner() + ")";
13281328+ return wrapMarks(this.marks, name);
13291329+ }
13301330+ /**
13311331+ Get the content match in this node at the given index.
13321332+ */
13331333+ contentMatchAt(index) {
13341334+ let match = this.type.contentMatch.matchFragment(this.content, 0, index);
13351335+ if (!match)
13361336+ throw new Error("Called contentMatchAt on a node with invalid content");
13371337+ return match;
13381338+ }
13391339+ /**
13401340+ Test whether replacing the range between `from` and `to` (by
13411341+ child index) with the given replacement fragment (which defaults
13421342+ to the empty fragment) would leave the node's content valid. You
13431343+ can optionally pass `start` and `end` indices into the
13441344+ replacement fragment.
13451345+ */
13461346+ canReplace(from, to, replacement = Fragment.empty, start = 0, end = replacement.childCount) {
13471347+ let one = this.contentMatchAt(from).matchFragment(replacement, start, end);
13481348+ let two = one && one.matchFragment(this.content, to);
13491349+ if (!two || !two.validEnd)
13501350+ return false;
13511351+ for (let i = start; i < end; i++)
13521352+ if (!this.type.allowsMarks(replacement.child(i).marks))
13531353+ return false;
13541354+ return true;
13551355+ }
13561356+ /**
13571357+ Test whether replacing the range `from` to `to` (by index) with
13581358+ a node of the given type would leave the node's content valid.
13591359+ */
13601360+ canReplaceWith(from, to, type, marks) {
13611361+ if (marks && !this.type.allowsMarks(marks))
13621362+ return false;
13631363+ let start = this.contentMatchAt(from).matchType(type);
13641364+ let end = start && start.matchFragment(this.content, to);
13651365+ return end ? end.validEnd : false;
13661366+ }
13671367+ /**
13681368+ Test whether the given node's content could be appended to this
13691369+ node. If that node is empty, this will only return true if there
13701370+ is at least one node type that can appear in both nodes (to avoid
13711371+ merging completely incompatible nodes).
13721372+ */
13731373+ canAppend(other) {
13741374+ if (other.content.size)
13751375+ return this.canReplace(this.childCount, this.childCount, other.content);
13761376+ else
13771377+ return this.type.compatibleContent(other.type);
13781378+ }
13791379+ /**
13801380+ Check whether this node and its descendants conform to the
13811381+ schema, and raise an exception when they do not.
13821382+ */
13831383+ check() {
13841384+ this.type.checkContent(this.content);
13851385+ this.type.checkAttrs(this.attrs);
13861386+ let copy = Mark.none;
13871387+ for (let i = 0; i < this.marks.length; i++) {
13881388+ let mark = this.marks[i];
13891389+ mark.type.checkAttrs(mark.attrs);
13901390+ copy = mark.addToSet(copy);
13911391+ }
13921392+ if (!Mark.sameSet(copy, this.marks))
13931393+ throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
13941394+ this.content.forEach((node) => node.check());
13951395+ }
13961396+ /**
13971397+ Return a JSON-serializeable representation of this node.
13981398+ */
13991399+ toJSON() {
14001400+ let obj = { type: this.type.name };
14011401+ for (let _ in this.attrs) {
14021402+ obj.attrs = this.attrs;
14031403+ break;
14041404+ }
14051405+ if (this.content.size)
14061406+ obj.content = this.content.toJSON();
14071407+ if (this.marks.length)
14081408+ obj.marks = this.marks.map((n) => n.toJSON());
14091409+ return obj;
14101410+ }
14111411+ /**
14121412+ Deserialize a node from its JSON representation.
14131413+ */
14141414+ static fromJSON(schema, json) {
14151415+ if (!json)
14161416+ throw new RangeError("Invalid input for Node.fromJSON");
14171417+ let marks = void 0;
14181418+ if (json.marks) {
14191419+ if (!Array.isArray(json.marks))
14201420+ throw new RangeError("Invalid mark data for Node.fromJSON");
14211421+ marks = json.marks.map(schema.markFromJSON);
14221422+ }
14231423+ if (json.type == "text") {
14241424+ if (typeof json.text != "string")
14251425+ throw new RangeError("Invalid text node in JSON");
14261426+ return schema.text(json.text, marks);
14271427+ }
14281428+ let content = Fragment.fromJSON(schema, json.content);
14291429+ let node = schema.nodeType(json.type).create(json.attrs, content, marks);
14301430+ node.type.checkAttrs(node.attrs);
14311431+ return node;
14321432+ }
14331433+};
14341434+Node.prototype.text = void 0;
14351435+function wrapMarks(marks, str) {
14361436+ for (let i = marks.length - 1; i >= 0; i--)
14371437+ str = marks[i].type.name + "(" + str + ")";
14381438+ return str;
14391439+}
14401440+var ContentMatch = class _ContentMatch {
14411441+ /**
14421442+ @internal
14431443+ */
14441444+ constructor(validEnd) {
14451445+ this.validEnd = validEnd;
14461446+ this.next = [];
14471447+ this.wrapCache = [];
14481448+ }
14491449+ /**
14501450+ @internal
14511451+ */
14521452+ static parse(string, nodeTypes) {
14531453+ let stream = new TokenStream(string, nodeTypes);
14541454+ if (stream.next == null)
14551455+ return _ContentMatch.empty;
14561456+ let expr = parseExpr(stream);
14571457+ if (stream.next)
14581458+ stream.err("Unexpected trailing text");
14591459+ let match = dfa(nfa(expr));
14601460+ checkForDeadEnds(match, stream);
14611461+ return match;
14621462+ }
14631463+ /**
14641464+ Match a node type, returning a match after that node if
14651465+ successful.
14661466+ */
14671467+ matchType(type) {
14681468+ for (let i = 0; i < this.next.length; i++)
14691469+ if (this.next[i].type == type)
14701470+ return this.next[i].next;
14711471+ return null;
14721472+ }
14731473+ /**
14741474+ Try to match a fragment. Returns the resulting match when
14751475+ successful.
14761476+ */
14771477+ matchFragment(frag, start = 0, end = frag.childCount) {
14781478+ let cur = this;
14791479+ for (let i = start; cur && i < end; i++)
14801480+ cur = cur.matchType(frag.child(i).type);
14811481+ return cur;
14821482+ }
14831483+ /**
14841484+ @internal
14851485+ */
14861486+ get inlineContent() {
14871487+ return this.next.length != 0 && this.next[0].type.isInline;
14881488+ }
14891489+ /**
14901490+ Get the first matching node type at this match position that can
14911491+ be generated.
14921492+ */
14931493+ get defaultType() {
14941494+ for (let i = 0; i < this.next.length; i++) {
14951495+ let { type } = this.next[i];
14961496+ if (!(type.isText || type.hasRequiredAttrs()))
14971497+ return type;
14981498+ }
14991499+ return null;
15001500+ }
15011501+ /**
15021502+ @internal
15031503+ */
15041504+ compatible(other) {
15051505+ for (let i = 0; i < this.next.length; i++)
15061506+ for (let j = 0; j < other.next.length; j++)
15071507+ if (this.next[i].type == other.next[j].type)
15081508+ return true;
15091509+ return false;
15101510+ }
15111511+ /**
15121512+ Try to match the given fragment, and if that fails, see if it can
15131513+ be made to match by inserting nodes in front of it. When
15141514+ successful, return a fragment of inserted nodes (which may be
15151515+ empty if nothing had to be inserted). When `toEnd` is true, only
15161516+ return a fragment if the resulting match goes to the end of the
15171517+ content expression.
15181518+ */
15191519+ fillBefore(after, toEnd = false, startIndex = 0) {
15201520+ let seen = [this];
15211521+ function search(match, types) {
15221522+ let finished = match.matchFragment(after, startIndex);
15231523+ if (finished && (!toEnd || finished.validEnd))
15241524+ return Fragment.from(types.map((tp) => tp.createAndFill()));
15251525+ for (let i = 0; i < match.next.length; i++) {
15261526+ let { type, next } = match.next[i];
15271527+ if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {
15281528+ seen.push(next);
15291529+ let found2 = search(next, types.concat(type));
15301530+ if (found2)
15311531+ return found2;
15321532+ }
15331533+ }
15341534+ return null;
15351535+ }
15361536+ return search(this, []);
15371537+ }
15381538+ /**
15391539+ Find a set of wrapping node types that would allow a node of the
15401540+ given type to appear at this position. The result may be empty
15411541+ (when it fits directly) and will be null when no such wrapping
15421542+ exists.
15431543+ */
15441544+ findWrapping(target) {
15451545+ for (let i = 0; i < this.wrapCache.length; i += 2)
15461546+ if (this.wrapCache[i] == target)
15471547+ return this.wrapCache[i + 1];
15481548+ let computed = this.computeWrapping(target);
15491549+ this.wrapCache.push(target, computed);
15501550+ return computed;
15511551+ }
15521552+ /**
15531553+ @internal
15541554+ */
15551555+ computeWrapping(target) {
15561556+ let seen = /* @__PURE__ */ Object.create(null), active = [{ match: this, type: null, via: null }];
15571557+ while (active.length) {
15581558+ let current = active.shift(), match = current.match;
15591559+ if (match.matchType(target)) {
15601560+ let result = [];
15611561+ for (let obj = current; obj.type; obj = obj.via)
15621562+ result.push(obj.type);
15631563+ return result.reverse();
15641564+ }
15651565+ for (let i = 0; i < match.next.length; i++) {
15661566+ let { type, next } = match.next[i];
15671567+ if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {
15681568+ active.push({ match: type.contentMatch, type, via: current });
15691569+ seen[type.name] = true;
15701570+ }
15711571+ }
15721572+ }
15731573+ return null;
15741574+ }
15751575+ /**
15761576+ The number of outgoing edges this node has in the finite
15771577+ automaton that describes the content expression.
15781578+ */
15791579+ get edgeCount() {
15801580+ return this.next.length;
15811581+ }
15821582+ /**
15831583+ Get the _n_th outgoing edge from this node in the finite
15841584+ automaton that describes the content expression.
15851585+ */
15861586+ edge(n) {
15871587+ if (n >= this.next.length)
15881588+ throw new RangeError(`There's no ${n}th edge in this content match`);
15891589+ return this.next[n];
15901590+ }
15911591+ /**
15921592+ @internal
15931593+ */
15941594+ toString() {
15951595+ let seen = [];
15961596+ function scan(m) {
15971597+ seen.push(m);
15981598+ for (let i = 0; i < m.next.length; i++)
15991599+ if (seen.indexOf(m.next[i].next) == -1)
16001600+ scan(m.next[i].next);
16011601+ }
16021602+ scan(this);
16031603+ return seen.map((m, i) => {
16041604+ let out = i + (m.validEnd ? "*" : " ") + " ";
16051605+ for (let i2 = 0; i2 < m.next.length; i2++)
16061606+ out += (i2 ? ", " : "") + m.next[i2].type.name + "->" + seen.indexOf(m.next[i2].next);
16071607+ return out;
16081608+ }).join("\n");
16091609+ }
16101610+};
16111611+ContentMatch.empty = new ContentMatch(true);
16121612+var TokenStream = class {
16131613+ constructor(string, nodeTypes) {
16141614+ this.string = string;
16151615+ this.nodeTypes = nodeTypes;
16161616+ this.inline = null;
16171617+ this.pos = 0;
16181618+ this.tokens = string.split(/\s*(?=\b|\W|$)/);
16191619+ if (this.tokens[this.tokens.length - 1] == "")
16201620+ this.tokens.pop();
16211621+ if (this.tokens[0] == "")
16221622+ this.tokens.shift();
16231623+ }
16241624+ get next() {
16251625+ return this.tokens[this.pos];
16261626+ }
16271627+ eat(tok) {
16281628+ return this.next == tok && (this.pos++ || true);
16291629+ }
16301630+ err(str) {
16311631+ throw new SyntaxError(str + " (in content expression '" + this.string + "')");
16321632+ }
16331633+};
16341634+function parseExpr(stream) {
16351635+ let exprs = [];
16361636+ do {
16371637+ exprs.push(parseExprSeq(stream));
16381638+ } while (stream.eat("|"));
16391639+ return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
16401640+}
16411641+function parseExprSeq(stream) {
16421642+ let exprs = [];
16431643+ do {
16441644+ exprs.push(parseExprSubscript(stream));
16451645+ } while (stream.next && stream.next != ")" && stream.next != "|");
16461646+ return exprs.length == 1 ? exprs[0] : { type: "seq", exprs };
16471647+}
16481648+function parseExprSubscript(stream) {
16491649+ let expr = parseExprAtom(stream);
16501650+ for (; ; ) {
16511651+ if (stream.eat("+"))
16521652+ expr = { type: "plus", expr };
16531653+ else if (stream.eat("*"))
16541654+ expr = { type: "star", expr };
16551655+ else if (stream.eat("?"))
16561656+ expr = { type: "opt", expr };
16571657+ else if (stream.eat("{"))
16581658+ expr = parseExprRange(stream, expr);
16591659+ else
16601660+ break;
16611661+ }
16621662+ return expr;
16631663+}
16641664+function parseNum(stream) {
16651665+ if (/\D/.test(stream.next))
16661666+ stream.err("Expected number, got '" + stream.next + "'");
16671667+ let result = Number(stream.next);
16681668+ stream.pos++;
16691669+ return result;
16701670+}
16711671+function parseExprRange(stream, expr) {
16721672+ let min = parseNum(stream), max = min;
16731673+ if (stream.eat(",")) {
16741674+ if (stream.next != "}")
16751675+ max = parseNum(stream);
16761676+ else
16771677+ max = -1;
16781678+ }
16791679+ if (!stream.eat("}"))
16801680+ stream.err("Unclosed braced range");
16811681+ return { type: "range", min, max, expr };
16821682+}
16831683+function resolveName(stream, name) {
16841684+ let types = stream.nodeTypes, type = types[name];
16851685+ if (type)
16861686+ return [type];
16871687+ let result = [];
16881688+ for (let typeName in types) {
16891689+ let type2 = types[typeName];
16901690+ if (type2.isInGroup(name))
16911691+ result.push(type2);
16921692+ }
16931693+ if (result.length == 0)
16941694+ stream.err("No node type or group '" + name + "' found");
16951695+ return result;
16961696+}
16971697+function parseExprAtom(stream) {
16981698+ if (stream.eat("(")) {
16991699+ let expr = parseExpr(stream);
17001700+ if (!stream.eat(")"))
17011701+ stream.err("Missing closing paren");
17021702+ return expr;
17031703+ } else if (!/\W/.test(stream.next)) {
17041704+ let exprs = resolveName(stream, stream.next).map((type) => {
17051705+ if (stream.inline == null)
17061706+ stream.inline = type.isInline;
17071707+ else if (stream.inline != type.isInline)
17081708+ stream.err("Mixing inline and block content");
17091709+ return { type: "name", value: type };
17101710+ });
17111711+ stream.pos++;
17121712+ return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
17131713+ } else {
17141714+ stream.err("Unexpected token '" + stream.next + "'");
17151715+ }
17161716+}
17171717+function nfa(expr) {
17181718+ let nfa2 = [[]];
17191719+ connect(compile(expr, 0), node());
17201720+ return nfa2;
17211721+ function node() {
17221722+ return nfa2.push([]) - 1;
17231723+ }
17241724+ function edge(from, to, term) {
17251725+ let edge2 = { term, to };
17261726+ nfa2[from].push(edge2);
17271727+ return edge2;
17281728+ }
17291729+ function connect(edges, to) {
17301730+ edges.forEach((edge2) => edge2.to = to);
17311731+ }
17321732+ function compile(expr2, from) {
17331733+ if (expr2.type == "choice") {
17341734+ return expr2.exprs.reduce((out, expr3) => out.concat(compile(expr3, from)), []);
17351735+ } else if (expr2.type == "seq") {
17361736+ for (let i = 0; ; i++) {
17371737+ let next = compile(expr2.exprs[i], from);
17381738+ if (i == expr2.exprs.length - 1)
17391739+ return next;
17401740+ connect(next, from = node());
17411741+ }
17421742+ } else if (expr2.type == "star") {
17431743+ let loop = node();
17441744+ edge(from, loop);
17451745+ connect(compile(expr2.expr, loop), loop);
17461746+ return [edge(loop)];
17471747+ } else if (expr2.type == "plus") {
17481748+ let loop = node();
17491749+ connect(compile(expr2.expr, from), loop);
17501750+ connect(compile(expr2.expr, loop), loop);
17511751+ return [edge(loop)];
17521752+ } else if (expr2.type == "opt") {
17531753+ return [edge(from)].concat(compile(expr2.expr, from));
17541754+ } else if (expr2.type == "range") {
17551755+ let cur = from;
17561756+ for (let i = 0; i < expr2.min; i++) {
17571757+ let next = node();
17581758+ connect(compile(expr2.expr, cur), next);
17591759+ cur = next;
17601760+ }
17611761+ if (expr2.max == -1) {
17621762+ connect(compile(expr2.expr, cur), cur);
17631763+ } else {
17641764+ for (let i = expr2.min; i < expr2.max; i++) {
17651765+ let next = node();
17661766+ edge(cur, next);
17671767+ connect(compile(expr2.expr, cur), next);
17681768+ cur = next;
17691769+ }
17701770+ }
17711771+ return [edge(cur)];
17721772+ } else if (expr2.type == "name") {
17731773+ return [edge(from, void 0, expr2.value)];
17741774+ } else {
17751775+ throw new Error("Unknown expr type");
17761776+ }
17771777+ }
17781778+}
17791779+function cmp(a, b) {
17801780+ return b - a;
17811781+}
17821782+function nullFrom(nfa2, node) {
17831783+ let result = [];
17841784+ scan(node);
17851785+ return result.sort(cmp);
17861786+ function scan(node2) {
17871787+ let edges = nfa2[node2];
17881788+ if (edges.length == 1 && !edges[0].term)
17891789+ return scan(edges[0].to);
17901790+ result.push(node2);
17911791+ for (let i = 0; i < edges.length; i++) {
17921792+ let { term, to } = edges[i];
17931793+ if (!term && result.indexOf(to) == -1)
17941794+ scan(to);
17951795+ }
17961796+ }
17971797+}
17981798+function dfa(nfa2) {
17991799+ let labeled = /* @__PURE__ */ Object.create(null);
18001800+ return explore(nullFrom(nfa2, 0));
18011801+ function explore(states) {
18021802+ let out = [];
18031803+ states.forEach((node) => {
18041804+ nfa2[node].forEach(({ term, to }) => {
18051805+ if (!term)
18061806+ return;
18071807+ let set;
18081808+ for (let i = 0; i < out.length; i++)
18091809+ if (out[i][0] == term)
18101810+ set = out[i][1];
18111811+ nullFrom(nfa2, to).forEach((node2) => {
18121812+ if (!set)
18131813+ out.push([term, set = []]);
18141814+ if (set.indexOf(node2) == -1)
18151815+ set.push(node2);
18161816+ });
18171817+ });
18181818+ });
18191819+ let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa2.length - 1) > -1);
18201820+ for (let i = 0; i < out.length; i++) {
18211821+ let states2 = out[i][1].sort(cmp);
18221822+ state.next.push({ type: out[i][0], next: labeled[states2.join(",")] || explore(states2) });
18231823+ }
18241824+ return state;
18251825+ }
18261826+}
18271827+function checkForDeadEnds(match, stream) {
18281828+ for (let i = 0, work = [match]; i < work.length; i++) {
18291829+ let state = work[i], dead = !state.validEnd, nodes = [];
18301830+ for (let j = 0; j < state.next.length; j++) {
18311831+ let { type, next } = state.next[j];
18321832+ nodes.push(type.name);
18331833+ if (dead && !(type.isText || type.hasRequiredAttrs()))
18341834+ dead = false;
18351835+ if (work.indexOf(next) == -1)
18361836+ work.push(next);
18371837+ }
18381838+ if (dead)
18391839+ stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
18401840+ }
18411841+}
18421842+18431843+// node_modules/prosemirror-transform/dist/index.js
18441844+var lower16 = 65535;
18451845+var factor16 = Math.pow(2, 16);
18461846+function makeRecover(index, offset) {
18471847+ return index + offset * factor16;
18481848+}
18491849+function recoverIndex(value) {
18501850+ return value & lower16;
18511851+}
18521852+function recoverOffset(value) {
18531853+ return (value - (value & lower16)) / factor16;
18541854+}
18551855+var DEL_BEFORE = 1;
18561856+var DEL_AFTER = 2;
18571857+var DEL_ACROSS = 4;
18581858+var DEL_SIDE = 8;
18591859+var MapResult = class {
18601860+ /**
18611861+ @internal
18621862+ */
18631863+ constructor(pos, delInfo, recover) {
18641864+ this.pos = pos;
18651865+ this.delInfo = delInfo;
18661866+ this.recover = recover;
18671867+ }
18681868+ /**
18691869+ Tells you whether the position was deleted, that is, whether the
18701870+ step removed the token on the side queried (via the `assoc`)
18711871+ argument from the document.
18721872+ */
18731873+ get deleted() {
18741874+ return (this.delInfo & DEL_SIDE) > 0;
18751875+ }
18761876+ /**
18771877+ Tells you whether the token before the mapped position was deleted.
18781878+ */
18791879+ get deletedBefore() {
18801880+ return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0;
18811881+ }
18821882+ /**
18831883+ True when the token after the mapped position was deleted.
18841884+ */
18851885+ get deletedAfter() {
18861886+ return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0;
18871887+ }
18881888+ /**
18891889+ Tells whether any of the steps mapped through deletes across the
18901890+ position (including both the token before and after the
18911891+ position).
18921892+ */
18931893+ get deletedAcross() {
18941894+ return (this.delInfo & DEL_ACROSS) > 0;
18951895+ }
18961896+};
18971897+var StepMap = class _StepMap {
18981898+ /**
18991899+ Create a position map. The modifications to the document are
19001900+ represented as an array of numbers, in which each group of three
19011901+ represents a modified chunk as `[start, oldSize, newSize]`.
19021902+ */
19031903+ constructor(ranges, inverted = false) {
19041904+ this.ranges = ranges;
19051905+ this.inverted = inverted;
19061906+ if (!ranges.length && _StepMap.empty)
19071907+ return _StepMap.empty;
19081908+ }
19091909+ /**
19101910+ @internal
19111911+ */
19121912+ recover(value) {
19131913+ let diff = 0, index = recoverIndex(value);
19141914+ if (!this.inverted)
19151915+ for (let i = 0; i < index; i++)
19161916+ diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
19171917+ return this.ranges[index * 3] + diff + recoverOffset(value);
19181918+ }
19191919+ mapResult(pos, assoc = 1) {
19201920+ return this._map(pos, assoc, false);
19211921+ }
19221922+ map(pos, assoc = 1) {
19231923+ return this._map(pos, assoc, true);
19241924+ }
19251925+ /**
19261926+ @internal
19271927+ */
19281928+ _map(pos, assoc, simple) {
19291929+ let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
19301930+ for (let i = 0; i < this.ranges.length; i += 3) {
19311931+ let start = this.ranges[i] - (this.inverted ? diff : 0);
19321932+ if (start > pos)
19331933+ break;
19341934+ let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
19351935+ if (pos <= end) {
19361936+ let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
19371937+ let result = start + diff + (side < 0 ? 0 : newSize);
19381938+ if (simple)
19391939+ return result;
19401940+ let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
19411941+ let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
19421942+ if (assoc < 0 ? pos != start : pos != end)
19431943+ del |= DEL_SIDE;
19441944+ return new MapResult(result, del, recover);
19451945+ }
19461946+ diff += newSize - oldSize;
19471947+ }
19481948+ return simple ? pos + diff : new MapResult(pos + diff, 0, null);
19491949+ }
19501950+ /**
19511951+ @internal
19521952+ */
19531953+ touches(pos, recover) {
19541954+ let diff = 0, index = recoverIndex(recover);
19551955+ let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
19561956+ for (let i = 0; i < this.ranges.length; i += 3) {
19571957+ let start = this.ranges[i] - (this.inverted ? diff : 0);
19581958+ if (start > pos)
19591959+ break;
19601960+ let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
19611961+ if (pos <= end && i == index * 3)
19621962+ return true;
19631963+ diff += this.ranges[i + newIndex] - oldSize;
19641964+ }
19651965+ return false;
19661966+ }
19671967+ /**
19681968+ Calls the given function on each of the changed ranges included in
19691969+ this map.
19701970+ */
19711971+ forEach(f) {
19721972+ let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
19731973+ for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
19741974+ let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);
19751975+ let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
19761976+ f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
19771977+ diff += newSize - oldSize;
19781978+ }
19791979+ }
19801980+ /**
19811981+ Create an inverted version of this map. The result can be used to
19821982+ map positions in the post-step document to the pre-step document.
19831983+ */
19841984+ invert() {
19851985+ return new _StepMap(this.ranges, !this.inverted);
19861986+ }
19871987+ /**
19881988+ @internal
19891989+ */
19901990+ toString() {
19911991+ return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
19921992+ }
19931993+ /**
19941994+ Create a map that moves all positions by offset `n` (which may be
19951995+ negative). This can be useful when applying steps meant for a
19961996+ sub-document to a larger document, or vice-versa.
19971997+ */
19981998+ static offset(n) {
19991999+ return n == 0 ? _StepMap.empty : new _StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
20002000+ }
20012001+};
20022002+StepMap.empty = new StepMap([]);
20032003+var stepsByID = /* @__PURE__ */ Object.create(null);
20042004+var Step = class {
20052005+ /**
20062006+ Get the step map that represents the changes made by this step,
20072007+ and which can be used to transform between positions in the old
20082008+ and the new document.
20092009+ */
20102010+ getMap() {
20112011+ return StepMap.empty;
20122012+ }
20132013+ /**
20142014+ Try to merge this step with another one, to be applied directly
20152015+ after it. Returns the merged step when possible, null if the
20162016+ steps can't be merged.
20172017+ */
20182018+ merge(other) {
20192019+ return null;
20202020+ }
20212021+ /**
20222022+ Deserialize a step from its JSON representation. Will call
20232023+ through to the step class' own implementation of this method.
20242024+ */
20252025+ static fromJSON(schema, json) {
20262026+ if (!json || !json.stepType)
20272027+ throw new RangeError("Invalid input for Step.fromJSON");
20282028+ let type = stepsByID[json.stepType];
20292029+ if (!type)
20302030+ throw new RangeError(`No step type ${json.stepType} defined`);
20312031+ return type.fromJSON(schema, json);
20322032+ }
20332033+ /**
20342034+ To be able to serialize steps to JSON, each step needs a string
20352035+ ID to attach to its JSON representation. Use this method to
20362036+ register an ID for your step classes. Try to pick something
20372037+ that's unlikely to clash with steps from other modules.
20382038+ */
20392039+ static jsonID(id, stepClass) {
20402040+ if (id in stepsByID)
20412041+ throw new RangeError("Duplicate use of step JSON ID " + id);
20422042+ stepsByID[id] = stepClass;
20432043+ stepClass.prototype.jsonID = id;
20442044+ return stepClass;
20452045+ }
20462046+};
20472047+var StepResult = class _StepResult {
20482048+ /**
20492049+ @internal
20502050+ */
20512051+ constructor(doc, failed) {
20522052+ this.doc = doc;
20532053+ this.failed = failed;
20542054+ }
20552055+ /**
20562056+ Create a successful step result.
20572057+ */
20582058+ static ok(doc) {
20592059+ return new _StepResult(doc, null);
20602060+ }
20612061+ /**
20622062+ Create a failed step result.
20632063+ */
20642064+ static fail(message) {
20652065+ return new _StepResult(null, message);
20662066+ }
20672067+ /**
20682068+ Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
20692069+ arguments. Create a successful result if it succeeds, and a
20702070+ failed one if it throws a `ReplaceError`.
20712071+ */
20722072+ static fromReplace(doc, from, to, slice) {
20732073+ try {
20742074+ return _StepResult.ok(doc.replace(from, to, slice));
20752075+ } catch (e) {
20762076+ if (e instanceof ReplaceError)
20772077+ return _StepResult.fail(e.message);
20782078+ throw e;
20792079+ }
20802080+ }
20812081+};
20822082+function mapFragment(fragment, f, parent) {
20832083+ let mapped = [];
20842084+ for (let i = 0; i < fragment.childCount; i++) {
20852085+ let child = fragment.child(i);
20862086+ if (child.content.size)
20872087+ child = child.copy(mapFragment(child.content, f, child));
20882088+ if (child.isInline)
20892089+ child = f(child, parent, i);
20902090+ mapped.push(child);
20912091+ }
20922092+ return Fragment.fromArray(mapped);
20932093+}
20942094+var AddMarkStep = class _AddMarkStep extends Step {
20952095+ /**
20962096+ Create a mark step.
20972097+ */
20982098+ constructor(from, to, mark) {
20992099+ super();
21002100+ this.from = from;
21012101+ this.to = to;
21022102+ this.mark = mark;
21032103+ }
21042104+ apply(doc) {
21052105+ let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
21062106+ let parent = $from.node($from.sharedDepth(this.to));
21072107+ let slice = new Slice(mapFragment(oldSlice.content, (node, parent2) => {
21082108+ if (!node.isAtom || !parent2.type.allowsMarkType(this.mark.type))
21092109+ return node;
21102110+ return node.mark(this.mark.addToSet(node.marks));
21112111+ }, parent), oldSlice.openStart, oldSlice.openEnd);
21122112+ return StepResult.fromReplace(doc, this.from, this.to, slice);
21132113+ }
21142114+ invert() {
21152115+ return new RemoveMarkStep(this.from, this.to, this.mark);
21162116+ }
21172117+ map(mapping) {
21182118+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
21192119+ if (from.deleted && to.deleted || from.pos >= to.pos)
21202120+ return null;
21212121+ return new _AddMarkStep(from.pos, to.pos, this.mark);
21222122+ }
21232123+ merge(other) {
21242124+ if (other instanceof _AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
21252125+ return new _AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
21262126+ return null;
21272127+ }
21282128+ toJSON() {
21292129+ return {
21302130+ stepType: "addMark",
21312131+ mark: this.mark.toJSON(),
21322132+ from: this.from,
21332133+ to: this.to
21342134+ };
21352135+ }
21362136+ /**
21372137+ @internal
21382138+ */
21392139+ static fromJSON(schema, json) {
21402140+ if (typeof json.from != "number" || typeof json.to != "number")
21412141+ throw new RangeError("Invalid input for AddMarkStep.fromJSON");
21422142+ return new _AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
21432143+ }
21442144+};
21452145+Step.jsonID("addMark", AddMarkStep);
21462146+var RemoveMarkStep = class _RemoveMarkStep extends Step {
21472147+ /**
21482148+ Create a mark-removing step.
21492149+ */
21502150+ constructor(from, to, mark) {
21512151+ super();
21522152+ this.from = from;
21532153+ this.to = to;
21542154+ this.mark = mark;
21552155+ }
21562156+ apply(doc) {
21572157+ let oldSlice = doc.slice(this.from, this.to);
21582158+ let slice = new Slice(mapFragment(oldSlice.content, (node) => {
21592159+ return node.mark(this.mark.removeFromSet(node.marks));
21602160+ }, doc), oldSlice.openStart, oldSlice.openEnd);
21612161+ return StepResult.fromReplace(doc, this.from, this.to, slice);
21622162+ }
21632163+ invert() {
21642164+ return new AddMarkStep(this.from, this.to, this.mark);
21652165+ }
21662166+ map(mapping) {
21672167+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
21682168+ if (from.deleted && to.deleted || from.pos >= to.pos)
21692169+ return null;
21702170+ return new _RemoveMarkStep(from.pos, to.pos, this.mark);
21712171+ }
21722172+ merge(other) {
21732173+ if (other instanceof _RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
21742174+ return new _RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
21752175+ return null;
21762176+ }
21772177+ toJSON() {
21782178+ return {
21792179+ stepType: "removeMark",
21802180+ mark: this.mark.toJSON(),
21812181+ from: this.from,
21822182+ to: this.to
21832183+ };
21842184+ }
21852185+ /**
21862186+ @internal
21872187+ */
21882188+ static fromJSON(schema, json) {
21892189+ if (typeof json.from != "number" || typeof json.to != "number")
21902190+ throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
21912191+ return new _RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
21922192+ }
21932193+};
21942194+Step.jsonID("removeMark", RemoveMarkStep);
21952195+var AddNodeMarkStep = class _AddNodeMarkStep extends Step {
21962196+ /**
21972197+ Create a node mark step.
21982198+ */
21992199+ constructor(pos, mark) {
22002200+ super();
22012201+ this.pos = pos;
22022202+ this.mark = mark;
22032203+ }
22042204+ apply(doc) {
22052205+ let node = doc.nodeAt(this.pos);
22062206+ if (!node)
22072207+ return StepResult.fail("No node at mark step's position");
22082208+ let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
22092209+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
22102210+ }
22112211+ invert(doc) {
22122212+ let node = doc.nodeAt(this.pos);
22132213+ if (node) {
22142214+ let newSet = this.mark.addToSet(node.marks);
22152215+ if (newSet.length == node.marks.length) {
22162216+ for (let i = 0; i < node.marks.length; i++)
22172217+ if (!node.marks[i].isInSet(newSet))
22182218+ return new _AddNodeMarkStep(this.pos, node.marks[i]);
22192219+ return new _AddNodeMarkStep(this.pos, this.mark);
22202220+ }
22212221+ }
22222222+ return new RemoveNodeMarkStep(this.pos, this.mark);
22232223+ }
22242224+ map(mapping) {
22252225+ let pos = mapping.mapResult(this.pos, 1);
22262226+ return pos.deletedAfter ? null : new _AddNodeMarkStep(pos.pos, this.mark);
22272227+ }
22282228+ toJSON() {
22292229+ return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
22302230+ }
22312231+ /**
22322232+ @internal
22332233+ */
22342234+ static fromJSON(schema, json) {
22352235+ if (typeof json.pos != "number")
22362236+ throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
22372237+ return new _AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
22382238+ }
22392239+};
22402240+Step.jsonID("addNodeMark", AddNodeMarkStep);
22412241+var RemoveNodeMarkStep = class _RemoveNodeMarkStep extends Step {
22422242+ /**
22432243+ Create a mark-removing step.
22442244+ */
22452245+ constructor(pos, mark) {
22462246+ super();
22472247+ this.pos = pos;
22482248+ this.mark = mark;
22492249+ }
22502250+ apply(doc) {
22512251+ let node = doc.nodeAt(this.pos);
22522252+ if (!node)
22532253+ return StepResult.fail("No node at mark step's position");
22542254+ let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
22552255+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
22562256+ }
22572257+ invert(doc) {
22582258+ let node = doc.nodeAt(this.pos);
22592259+ if (!node || !this.mark.isInSet(node.marks))
22602260+ return this;
22612261+ return new AddNodeMarkStep(this.pos, this.mark);
22622262+ }
22632263+ map(mapping) {
22642264+ let pos = mapping.mapResult(this.pos, 1);
22652265+ return pos.deletedAfter ? null : new _RemoveNodeMarkStep(pos.pos, this.mark);
22662266+ }
22672267+ toJSON() {
22682268+ return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
22692269+ }
22702270+ /**
22712271+ @internal
22722272+ */
22732273+ static fromJSON(schema, json) {
22742274+ if (typeof json.pos != "number")
22752275+ throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
22762276+ return new _RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
22772277+ }
22782278+};
22792279+Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
22802280+var ReplaceStep = class _ReplaceStep extends Step {
22812281+ /**
22822282+ The given `slice` should fit the 'gap' between `from` and
22832283+ `to`—the depths must line up, and the surrounding nodes must be
22842284+ able to be joined with the open sides of the slice. When
22852285+ `structure` is true, the step will fail if the content between
22862286+ from and to is not just a sequence of closing and then opening
22872287+ tokens (this is to guard against rebased replace steps
22882288+ overwriting something they weren't supposed to).
22892289+ */
22902290+ constructor(from, to, slice, structure = false) {
22912291+ super();
22922292+ this.from = from;
22932293+ this.to = to;
22942294+ this.slice = slice;
22952295+ this.structure = structure;
22962296+ }
22972297+ apply(doc) {
22982298+ if (this.structure && contentBetween(doc, this.from, this.to))
22992299+ return StepResult.fail("Structure replace would overwrite content");
23002300+ return StepResult.fromReplace(doc, this.from, this.to, this.slice);
23012301+ }
23022302+ getMap() {
23032303+ return new StepMap([this.from, this.to - this.from, this.slice.size]);
23042304+ }
23052305+ invert(doc) {
23062306+ return new _ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
23072307+ }
23082308+ map(mapping) {
23092309+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
23102310+ if (from.deletedAcross && to.deletedAcross)
23112311+ return null;
23122312+ return new _ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
23132313+ }
23142314+ merge(other) {
23152315+ if (!(other instanceof _ReplaceStep) || other.structure || this.structure)
23162316+ return null;
23172317+ if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
23182318+ let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
23192319+ return new _ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
23202320+ } else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
23212321+ let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
23222322+ return new _ReplaceStep(other.from, this.to, slice, this.structure);
23232323+ } else {
23242324+ return null;
23252325+ }
23262326+ }
23272327+ toJSON() {
23282328+ let json = { stepType: "replace", from: this.from, to: this.to };
23292329+ if (this.slice.size)
23302330+ json.slice = this.slice.toJSON();
23312331+ if (this.structure)
23322332+ json.structure = true;
23332333+ return json;
23342334+ }
23352335+ /**
23362336+ @internal
23372337+ */
23382338+ static fromJSON(schema, json) {
23392339+ if (typeof json.from != "number" || typeof json.to != "number")
23402340+ throw new RangeError("Invalid input for ReplaceStep.fromJSON");
23412341+ return new _ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
23422342+ }
23432343+};
23442344+Step.jsonID("replace", ReplaceStep);
23452345+var ReplaceAroundStep = class _ReplaceAroundStep extends Step {
23462346+ /**
23472347+ Create a replace-around step with the given range and gap.
23482348+ `insert` should be the point in the slice into which the content
23492349+ of the gap should be moved. `structure` has the same meaning as
23502350+ it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
23512351+ */
23522352+ constructor(from, to, gapFrom, gapTo, slice, insert, structure = false) {
23532353+ super();
23542354+ this.from = from;
23552355+ this.to = to;
23562356+ this.gapFrom = gapFrom;
23572357+ this.gapTo = gapTo;
23582358+ this.slice = slice;
23592359+ this.insert = insert;
23602360+ this.structure = structure;
23612361+ }
23622362+ apply(doc) {
23632363+ if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to)))
23642364+ return StepResult.fail("Structure gap-replace would overwrite content");
23652365+ let gap = doc.slice(this.gapFrom, this.gapTo);
23662366+ if (gap.openStart || gap.openEnd)
23672367+ return StepResult.fail("Gap is not a flat range");
23682368+ let inserted = this.slice.insertAt(this.insert, gap.content);
23692369+ if (!inserted)
23702370+ return StepResult.fail("Content does not fit in gap");
23712371+ return StepResult.fromReplace(doc, this.from, this.to, inserted);
23722372+ }
23732373+ getMap() {
23742374+ return new StepMap([
23752375+ this.from,
23762376+ this.gapFrom - this.from,
23772377+ this.insert,
23782378+ this.gapTo,
23792379+ this.to - this.gapTo,
23802380+ this.slice.size - this.insert
23812381+ ]);
23822382+ }
23832383+ invert(doc) {
23842384+ let gap = this.gapTo - this.gapFrom;
23852385+ return new _ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
23862386+ }
23872387+ map(mapping) {
23882388+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
23892389+ let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
23902390+ let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
23912391+ if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos)
23922392+ return null;
23932393+ return new _ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
23942394+ }
23952395+ toJSON() {
23962396+ let json = {
23972397+ stepType: "replaceAround",
23982398+ from: this.from,
23992399+ to: this.to,
24002400+ gapFrom: this.gapFrom,
24012401+ gapTo: this.gapTo,
24022402+ insert: this.insert
24032403+ };
24042404+ if (this.slice.size)
24052405+ json.slice = this.slice.toJSON();
24062406+ if (this.structure)
24072407+ json.structure = true;
24082408+ return json;
24092409+ }
24102410+ /**
24112411+ @internal
24122412+ */
24132413+ static fromJSON(schema, json) {
24142414+ if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
24152415+ throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
24162416+ return new _ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
24172417+ }
24182418+};
24192419+Step.jsonID("replaceAround", ReplaceAroundStep);
24202420+function contentBetween(doc, from, to) {
24212421+ let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
24222422+ while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
24232423+ depth--;
24242424+ dist--;
24252425+ }
24262426+ if (dist > 0) {
24272427+ let next = $from.node(depth).maybeChild($from.indexAfter(depth));
24282428+ while (dist > 0) {
24292429+ if (!next || next.isLeaf)
24302430+ return true;
24312431+ next = next.firstChild;
24322432+ dist--;
24332433+ }
24342434+ }
24352435+ return false;
24362436+}
24372437+var AttrStep = class _AttrStep extends Step {
24382438+ /**
24392439+ Construct an attribute step.
24402440+ */
24412441+ constructor(pos, attr, value) {
24422442+ super();
24432443+ this.pos = pos;
24442444+ this.attr = attr;
24452445+ this.value = value;
24462446+ }
24472447+ apply(doc) {
24482448+ let node = doc.nodeAt(this.pos);
24492449+ if (!node)
24502450+ return StepResult.fail("No node at attribute step's position");
24512451+ let attrs = /* @__PURE__ */ Object.create(null);
24522452+ for (let name in node.attrs)
24532453+ attrs[name] = node.attrs[name];
24542454+ attrs[this.attr] = this.value;
24552455+ let updated = node.type.create(attrs, null, node.marks);
24562456+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
24572457+ }
24582458+ getMap() {
24592459+ return StepMap.empty;
24602460+ }
24612461+ invert(doc) {
24622462+ return new _AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
24632463+ }
24642464+ map(mapping) {
24652465+ let pos = mapping.mapResult(this.pos, 1);
24662466+ return pos.deletedAfter ? null : new _AttrStep(pos.pos, this.attr, this.value);
24672467+ }
24682468+ toJSON() {
24692469+ return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
24702470+ }
24712471+ static fromJSON(schema, json) {
24722472+ if (typeof json.pos != "number" || typeof json.attr != "string")
24732473+ throw new RangeError("Invalid input for AttrStep.fromJSON");
24742474+ return new _AttrStep(json.pos, json.attr, json.value);
24752475+ }
24762476+};
24772477+Step.jsonID("attr", AttrStep);
24782478+var DocAttrStep = class _DocAttrStep extends Step {
24792479+ /**
24802480+ Construct an attribute step.
24812481+ */
24822482+ constructor(attr, value) {
24832483+ super();
24842484+ this.attr = attr;
24852485+ this.value = value;
24862486+ }
24872487+ apply(doc) {
24882488+ let attrs = /* @__PURE__ */ Object.create(null);
24892489+ for (let name in doc.attrs)
24902490+ attrs[name] = doc.attrs[name];
24912491+ attrs[this.attr] = this.value;
24922492+ let updated = doc.type.create(attrs, doc.content, doc.marks);
24932493+ return StepResult.ok(updated);
24942494+ }
24952495+ getMap() {
24962496+ return StepMap.empty;
24972497+ }
24982498+ invert(doc) {
24992499+ return new _DocAttrStep(this.attr, doc.attrs[this.attr]);
25002500+ }
25012501+ map(mapping) {
25022502+ return this;
25032503+ }
25042504+ toJSON() {
25052505+ return { stepType: "docAttr", attr: this.attr, value: this.value };
25062506+ }
25072507+ static fromJSON(schema, json) {
25082508+ if (typeof json.attr != "string")
25092509+ throw new RangeError("Invalid input for DocAttrStep.fromJSON");
25102510+ return new _DocAttrStep(json.attr, json.value);
25112511+ }
25122512+};
25132513+Step.jsonID("docAttr", DocAttrStep);
25142514+var TransformError = class extends Error {
25152515+};
25162516+TransformError = function TransformError2(message) {
25172517+ let err = Error.call(this, message);
25182518+ err.__proto__ = TransformError2.prototype;
25192519+ return err;
25202520+};
25212521+TransformError.prototype = Object.create(Error.prototype);
25222522+TransformError.prototype.constructor = TransformError;
25232523+TransformError.prototype.name = "TransformError";
25242524+25252525+// node_modules/prosemirror-state/dist/index.js
25262526+var classesById = /* @__PURE__ */ Object.create(null);
25272527+var Selection = class {
25282528+ /**
25292529+ Initialize a selection with the head and anchor and ranges. If no
25302530+ ranges are given, constructs a single range across `$anchor` and
25312531+ `$head`.
25322532+ */
25332533+ constructor($anchor, $head, ranges) {
25342534+ this.$anchor = $anchor;
25352535+ this.$head = $head;
25362536+ this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))];
25372537+ }
25382538+ /**
25392539+ The selection's anchor, as an unresolved position.
25402540+ */
25412541+ get anchor() {
25422542+ return this.$anchor.pos;
25432543+ }
25442544+ /**
25452545+ The selection's head.
25462546+ */
25472547+ get head() {
25482548+ return this.$head.pos;
25492549+ }
25502550+ /**
25512551+ The lower bound of the selection's main range.
25522552+ */
25532553+ get from() {
25542554+ return this.$from.pos;
25552555+ }
25562556+ /**
25572557+ The upper bound of the selection's main range.
25582558+ */
25592559+ get to() {
25602560+ return this.$to.pos;
25612561+ }
25622562+ /**
25632563+ The resolved lower bound of the selection's main range.
25642564+ */
25652565+ get $from() {
25662566+ return this.ranges[0].$from;
25672567+ }
25682568+ /**
25692569+ The resolved upper bound of the selection's main range.
25702570+ */
25712571+ get $to() {
25722572+ return this.ranges[0].$to;
25732573+ }
25742574+ /**
25752575+ Indicates whether the selection contains any content.
25762576+ */
25772577+ get empty() {
25782578+ let ranges = this.ranges;
25792579+ for (let i = 0; i < ranges.length; i++)
25802580+ if (ranges[i].$from.pos != ranges[i].$to.pos)
25812581+ return false;
25822582+ return true;
25832583+ }
25842584+ /**
25852585+ Get the content of this selection as a slice.
25862586+ */
25872587+ content() {
25882588+ return this.$from.doc.slice(this.from, this.to, true);
25892589+ }
25902590+ /**
25912591+ Replace the selection with a slice or, if no slice is given,
25922592+ delete the selection. Will append to the given transaction.
25932593+ */
25942594+ replace(tr, content = Slice.empty) {
25952595+ let lastNode = content.content.lastChild, lastParent = null;
25962596+ for (let i = 0; i < content.openEnd; i++) {
25972597+ lastParent = lastNode;
25982598+ lastNode = lastNode.lastChild;
25992599+ }
26002600+ let mapFrom = tr.steps.length, ranges = this.ranges;
26012601+ for (let i = 0; i < ranges.length; i++) {
26022602+ let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
26032603+ tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
26042604+ if (i == 0)
26052605+ selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);
26062606+ }
26072607+ }
26082608+ /**
26092609+ Replace the selection with the given node, appending the changes
26102610+ to the given transaction.
26112611+ */
26122612+ replaceWith(tr, node) {
26132613+ let mapFrom = tr.steps.length, ranges = this.ranges;
26142614+ for (let i = 0; i < ranges.length; i++) {
26152615+ let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
26162616+ let from = mapping.map($from.pos), to = mapping.map($to.pos);
26172617+ if (i) {
26182618+ tr.deleteRange(from, to);
26192619+ } else {
26202620+ tr.replaceRangeWith(from, to, node);
26212621+ selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1);
26222622+ }
26232623+ }
26242624+ }
26252625+ /**
26262626+ Find a valid cursor or leaf node selection starting at the given
26272627+ position and searching back if `dir` is negative, and forward if
26282628+ positive. When `textOnly` is true, only consider cursor
26292629+ selections. Will return null when no valid selection position is
26302630+ found.
26312631+ */
26322632+ static findFrom($pos, dir, textOnly = false) {
26332633+ let inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);
26342634+ if (inner)
26352635+ return inner;
26362636+ for (let depth = $pos.depth - 1; depth >= 0; depth--) {
26372637+ let found2 = dir < 0 ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly) : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly);
26382638+ if (found2)
26392639+ return found2;
26402640+ }
26412641+ return null;
26422642+ }
26432643+ /**
26442644+ Find a valid cursor or leaf node selection near the given
26452645+ position. Searches forward first by default, but if `bias` is
26462646+ negative, it will search backwards first.
26472647+ */
26482648+ static near($pos, bias = 1) {
26492649+ return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));
26502650+ }
26512651+ /**
26522652+ Find the cursor or leaf node selection closest to the start of
26532653+ the given document. Will return an
26542654+ [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position
26552655+ exists.
26562656+ */
26572657+ static atStart(doc) {
26582658+ return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);
26592659+ }
26602660+ /**
26612661+ Find the cursor or leaf node selection closest to the end of the
26622662+ given document.
26632663+ */
26642664+ static atEnd(doc) {
26652665+ return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);
26662666+ }
26672667+ /**
26682668+ Deserialize the JSON representation of a selection. Must be
26692669+ implemented for custom classes (as a static class method).
26702670+ */
26712671+ static fromJSON(doc, json) {
26722672+ if (!json || !json.type)
26732673+ throw new RangeError("Invalid input for Selection.fromJSON");
26742674+ let cls = classesById[json.type];
26752675+ if (!cls)
26762676+ throw new RangeError(`No selection type ${json.type} defined`);
26772677+ return cls.fromJSON(doc, json);
26782678+ }
26792679+ /**
26802680+ To be able to deserialize selections from JSON, custom selection
26812681+ classes must register themselves with an ID string, so that they
26822682+ can be disambiguated. Try to pick something that's unlikely to
26832683+ clash with classes from other modules.
26842684+ */
26852685+ static jsonID(id, selectionClass) {
26862686+ if (id in classesById)
26872687+ throw new RangeError("Duplicate use of selection JSON ID " + id);
26882688+ classesById[id] = selectionClass;
26892689+ selectionClass.prototype.jsonID = id;
26902690+ return selectionClass;
26912691+ }
26922692+ /**
26932693+ Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,
26942694+ which is a value that can be mapped without having access to a
26952695+ current document, and later resolved to a real selection for a
26962696+ given document again. (This is used mostly by the history to
26972697+ track and restore old selections.) The default implementation of
26982698+ this method just converts the selection to a text selection and
26992699+ returns the bookmark for that.
27002700+ */
27012701+ getBookmark() {
27022702+ return TextSelection.between(this.$anchor, this.$head).getBookmark();
27032703+ }
27042704+};
27052705+Selection.prototype.visible = true;
27062706+var SelectionRange = class {
27072707+ /**
27082708+ Create a range.
27092709+ */
27102710+ constructor($from, $to) {
27112711+ this.$from = $from;
27122712+ this.$to = $to;
27132713+ }
27142714+};
27152715+var warnedAboutTextSelection = false;
27162716+function checkTextSelection($pos) {
27172717+ if (!warnedAboutTextSelection && !$pos.parent.inlineContent) {
27182718+ warnedAboutTextSelection = true;
27192719+ console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")");
27202720+ }
27212721+}
27222722+var TextSelection = class _TextSelection extends Selection {
27232723+ /**
27242724+ Construct a text selection between the given points.
27252725+ */
27262726+ constructor($anchor, $head = $anchor) {
27272727+ checkTextSelection($anchor);
27282728+ checkTextSelection($head);
27292729+ super($anchor, $head);
27302730+ }
27312731+ /**
27322732+ Returns a resolved position if this is a cursor selection (an
27332733+ empty text selection), and null otherwise.
27342734+ */
27352735+ get $cursor() {
27362736+ return this.$anchor.pos == this.$head.pos ? this.$head : null;
27372737+ }
27382738+ map(doc, mapping) {
27392739+ let $head = doc.resolve(mapping.map(this.head));
27402740+ if (!$head.parent.inlineContent)
27412741+ return Selection.near($head);
27422742+ let $anchor = doc.resolve(mapping.map(this.anchor));
27432743+ return new _TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);
27442744+ }
27452745+ replace(tr, content = Slice.empty) {
27462746+ super.replace(tr, content);
27472747+ if (content == Slice.empty) {
27482748+ let marks = this.$from.marksAcross(this.$to);
27492749+ if (marks)
27502750+ tr.ensureMarks(marks);
27512751+ }
27522752+ }
27532753+ eq(other) {
27542754+ return other instanceof _TextSelection && other.anchor == this.anchor && other.head == this.head;
27552755+ }
27562756+ getBookmark() {
27572757+ return new TextBookmark(this.anchor, this.head);
27582758+ }
27592759+ toJSON() {
27602760+ return { type: "text", anchor: this.anchor, head: this.head };
27612761+ }
27622762+ /**
27632763+ @internal
27642764+ */
27652765+ static fromJSON(doc, json) {
27662766+ if (typeof json.anchor != "number" || typeof json.head != "number")
27672767+ throw new RangeError("Invalid input for TextSelection.fromJSON");
27682768+ return new _TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));
27692769+ }
27702770+ /**
27712771+ Create a text selection from non-resolved positions.
27722772+ */
27732773+ static create(doc, anchor, head = anchor) {
27742774+ let $anchor = doc.resolve(anchor);
27752775+ return new this($anchor, head == anchor ? $anchor : doc.resolve(head));
27762776+ }
27772777+ /**
27782778+ Return a text selection that spans the given positions or, if
27792779+ they aren't text positions, find a text selection near them.
27802780+ `bias` determines whether the method searches forward (default)
27812781+ or backwards (negative number) first. Will fall back to calling
27822782+ [`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document
27832783+ doesn't contain a valid text position.
27842784+ */
27852785+ static between($anchor, $head, bias) {
27862786+ let dPos = $anchor.pos - $head.pos;
27872787+ if (!bias || dPos)
27882788+ bias = dPos >= 0 ? 1 : -1;
27892789+ if (!$head.parent.inlineContent) {
27902790+ let found2 = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);
27912791+ if (found2)
27922792+ $head = found2.$head;
27932793+ else
27942794+ return Selection.near($head, bias);
27952795+ }
27962796+ if (!$anchor.parent.inlineContent) {
27972797+ if (dPos == 0) {
27982798+ $anchor = $head;
27992799+ } else {
28002800+ $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor;
28012801+ if ($anchor.pos < $head.pos != dPos < 0)
28022802+ $anchor = $head;
28032803+ }
28042804+ }
28052805+ return new _TextSelection($anchor, $head);
28062806+ }
28072807+};
28082808+Selection.jsonID("text", TextSelection);
28092809+var TextBookmark = class _TextBookmark {
28102810+ constructor(anchor, head) {
28112811+ this.anchor = anchor;
28122812+ this.head = head;
28132813+ }
28142814+ map(mapping) {
28152815+ return new _TextBookmark(mapping.map(this.anchor), mapping.map(this.head));
28162816+ }
28172817+ resolve(doc) {
28182818+ return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));
28192819+ }
28202820+};
28212821+var NodeSelection = class _NodeSelection extends Selection {
28222822+ /**
28232823+ Create a node selection. Does not verify the validity of its
28242824+ argument.
28252825+ */
28262826+ constructor($pos) {
28272827+ let node = $pos.nodeAfter;
28282828+ let $end = $pos.node(0).resolve($pos.pos + node.nodeSize);
28292829+ super($pos, $end);
28302830+ this.node = node;
28312831+ }
28322832+ map(doc, mapping) {
28332833+ let { deleted, pos } = mapping.mapResult(this.anchor);
28342834+ let $pos = doc.resolve(pos);
28352835+ if (deleted)
28362836+ return Selection.near($pos);
28372837+ return new _NodeSelection($pos);
28382838+ }
28392839+ content() {
28402840+ return new Slice(Fragment.from(this.node), 0, 0);
28412841+ }
28422842+ eq(other) {
28432843+ return other instanceof _NodeSelection && other.anchor == this.anchor;
28442844+ }
28452845+ toJSON() {
28462846+ return { type: "node", anchor: this.anchor };
28472847+ }
28482848+ getBookmark() {
28492849+ return new NodeBookmark(this.anchor);
28502850+ }
28512851+ /**
28522852+ @internal
28532853+ */
28542854+ static fromJSON(doc, json) {
28552855+ if (typeof json.anchor != "number")
28562856+ throw new RangeError("Invalid input for NodeSelection.fromJSON");
28572857+ return new _NodeSelection(doc.resolve(json.anchor));
28582858+ }
28592859+ /**
28602860+ Create a node selection from non-resolved positions.
28612861+ */
28622862+ static create(doc, from) {
28632863+ return new _NodeSelection(doc.resolve(from));
28642864+ }
28652865+ /**
28662866+ Determines whether the given node may be selected as a node
28672867+ selection.
28682868+ */
28692869+ static isSelectable(node) {
28702870+ return !node.isText && node.type.spec.selectable !== false;
28712871+ }
28722872+};
28732873+NodeSelection.prototype.visible = false;
28742874+Selection.jsonID("node", NodeSelection);
28752875+var NodeBookmark = class _NodeBookmark {
28762876+ constructor(anchor) {
28772877+ this.anchor = anchor;
28782878+ }
28792879+ map(mapping) {
28802880+ let { deleted, pos } = mapping.mapResult(this.anchor);
28812881+ return deleted ? new TextBookmark(pos, pos) : new _NodeBookmark(pos);
28822882+ }
28832883+ resolve(doc) {
28842884+ let $pos = doc.resolve(this.anchor), node = $pos.nodeAfter;
28852885+ if (node && NodeSelection.isSelectable(node))
28862886+ return new NodeSelection($pos);
28872887+ return Selection.near($pos);
28882888+ }
28892889+};
28902890+var AllSelection = class _AllSelection extends Selection {
28912891+ /**
28922892+ Create an all-selection over the given document.
28932893+ */
28942894+ constructor(doc) {
28952895+ super(doc.resolve(0), doc.resolve(doc.content.size));
28962896+ }
28972897+ replace(tr, content = Slice.empty) {
28982898+ if (content == Slice.empty) {
28992899+ tr.delete(0, tr.doc.content.size);
29002900+ let sel = Selection.atStart(tr.doc);
29012901+ if (!sel.eq(tr.selection))
29022902+ tr.setSelection(sel);
29032903+ } else {
29042904+ super.replace(tr, content);
29052905+ }
29062906+ }
29072907+ toJSON() {
29082908+ return { type: "all" };
29092909+ }
29102910+ /**
29112911+ @internal
29122912+ */
29132913+ static fromJSON(doc) {
29142914+ return new _AllSelection(doc);
29152915+ }
29162916+ map(doc) {
29172917+ return new _AllSelection(doc);
29182918+ }
29192919+ eq(other) {
29202920+ return other instanceof _AllSelection;
29212921+ }
29222922+ getBookmark() {
29232923+ return AllBookmark;
29242924+ }
29252925+};
29262926+Selection.jsonID("all", AllSelection);
29272927+var AllBookmark = {
29282928+ map() {
29292929+ return this;
29302930+ },
29312931+ resolve(doc) {
29322932+ return new AllSelection(doc);
29332933+ }
29342934+};
29352935+function findSelectionIn(doc, node, pos, index, dir, text = false) {
29362936+ if (node.inlineContent)
29372937+ return TextSelection.create(doc, pos);
29382938+ for (let i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) {
29392939+ let child = node.child(i);
29402940+ if (!child.isAtom) {
29412941+ let inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text);
29422942+ if (inner)
29432943+ return inner;
29442944+ } else if (!text && NodeSelection.isSelectable(child)) {
29452945+ return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0));
29462946+ }
29472947+ pos += child.nodeSize * dir;
29482948+ }
29492949+ return null;
29502950+}
29512951+function selectionToInsertionEnd(tr, startLen, bias) {
29522952+ let last = tr.steps.length - 1;
29532953+ if (last < startLen)
29542954+ return;
29552955+ let step = tr.steps[last];
29562956+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
29572957+ return;
29582958+ let map = tr.mapping.maps[last], end;
29592959+ map.forEach((_from, _to, _newFrom, newTo) => {
29602960+ if (end == null)
29612961+ end = newTo;
29622962+ });
29632963+ tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
29642964+}
29652965+function bind(f, self) {
29662966+ return !self || !f ? f : f.bind(self);
29672967+}
29682968+var FieldDesc = class {
29692969+ constructor(name, desc, self) {
29702970+ this.name = name;
29712971+ this.init = bind(desc.init, self);
29722972+ this.apply = bind(desc.apply, self);
29732973+ }
29742974+};
29752975+var baseFields = [
29762976+ new FieldDesc("doc", {
29772977+ init(config) {
29782978+ return config.doc || config.schema.topNodeType.createAndFill();
29792979+ },
29802980+ apply(tr) {
29812981+ return tr.doc;
29822982+ }
29832983+ }),
29842984+ new FieldDesc("selection", {
29852985+ init(config, instance) {
29862986+ return config.selection || Selection.atStart(instance.doc);
29872987+ },
29882988+ apply(tr) {
29892989+ return tr.selection;
29902990+ }
29912991+ }),
29922992+ new FieldDesc("storedMarks", {
29932993+ init(config) {
29942994+ return config.storedMarks || null;
29952995+ },
29962996+ apply(tr, _marks, _old, state) {
29972997+ return state.selection.$cursor ? tr.storedMarks : null;
29982998+ }
29992999+ }),
30003000+ new FieldDesc("scrollToSelection", {
30013001+ init() {
30023002+ return 0;
30033003+ },
30043004+ apply(tr, prev) {
30053005+ return tr.scrolledIntoView ? prev + 1 : prev;
30063006+ }
30073007+ })
30083008+];
30093009+function bindProps(obj, self, target) {
30103010+ for (let prop in obj) {
30113011+ let val = obj[prop];
30123012+ if (val instanceof Function)
30133013+ val = val.bind(self);
30143014+ else if (prop == "handleDOMEvents")
30153015+ val = bindProps(val, self, {});
30163016+ target[prop] = val;
30173017+ }
30183018+ return target;
30193019+}
30203020+var Plugin = class {
30213021+ /**
30223022+ Create a plugin.
30233023+ */
30243024+ constructor(spec) {
30253025+ this.spec = spec;
30263026+ this.props = {};
30273027+ if (spec.props)
30283028+ bindProps(spec.props, this, this.props);
30293029+ this.key = spec.key ? spec.key.key : createKey("plugin");
30303030+ }
30313031+ /**
30323032+ Extract the plugin's state field from an editor state.
30333033+ */
30343034+ getState(state) {
30353035+ return state[this.key];
30363036+ }
30373037+};
30383038+var keys = /* @__PURE__ */ Object.create(null);
30393039+function createKey(name) {
30403040+ if (name in keys)
30413041+ return name + "$" + ++keys[name];
30423042+ keys[name] = 0;
30433043+ return name + "$";
30443044+}
30453045+var PluginKey = class {
30463046+ /**
30473047+ Create a plugin key.
30483048+ */
30493049+ constructor(name = "key") {
30503050+ this.key = createKey(name);
30513051+ }
30523052+ /**
30533053+ Get the active plugin with this key, if any, from an editor
30543054+ state.
30553055+ */
30563056+ get(state) {
30573057+ return state.config.pluginsByKey[this.key];
30583058+ }
30593059+ /**
30603060+ Get the plugin's state from an editor state.
30613061+ */
30623062+ getState(state) {
30633063+ return state[this.key];
30643064+ }
30653065+};
30663066+30673067+// node_modules/prosemirror-collab/dist/index.js
30683068+var Rebaseable = class {
30693069+ constructor(step, inverted, origin) {
30703070+ this.step = step;
30713071+ this.inverted = inverted;
30723072+ this.origin = origin;
30733073+ }
30743074+};
30753075+function rebaseSteps(steps, over, transform) {
30763076+ for (let i = steps.length - 1; i >= 0; i--)
30773077+ transform.step(steps[i].inverted);
30783078+ for (let i = 0; i < over.length; i++)
30793079+ transform.step(over[i]);
30803080+ let result = [];
30813081+ for (let i = 0, mapFrom = steps.length; i < steps.length; i++) {
30823082+ let mapped = steps[i].step.map(transform.mapping.slice(mapFrom));
30833083+ mapFrom--;
30843084+ if (mapped && !transform.maybeStep(mapped).failed) {
30853085+ transform.mapping.setMirror(mapFrom, transform.steps.length - 1);
30863086+ result.push(new Rebaseable(mapped, mapped.invert(transform.docs[transform.docs.length - 1]), steps[i].origin));
30873087+ }
30883088+ }
30893089+ return result;
30903090+}
30913091+var CollabState = class {
30923092+ constructor(version, unconfirmed) {
30933093+ this.version = version;
30943094+ this.unconfirmed = unconfirmed;
30953095+ }
30963096+};
30973097+function unconfirmedFrom(transform) {
30983098+ let result = [];
30993099+ for (let i = 0; i < transform.steps.length; i++)
31003100+ result.push(new Rebaseable(transform.steps[i], transform.steps[i].invert(transform.docs[i]), transform));
31013101+ return result;
31023102+}
31033103+var collabKey = new PluginKey("collab");
31043104+function collab(config = {}) {
31053105+ let conf = {
31063106+ version: config.version || 0,
31073107+ clientID: config.clientID == null ? Math.floor(Math.random() * 4294967295) : config.clientID
31083108+ };
31093109+ return new Plugin({
31103110+ key: collabKey,
31113111+ state: {
31123112+ init: () => new CollabState(conf.version, []),
31133113+ apply(tr, collab2) {
31143114+ let newState = tr.getMeta(collabKey);
31153115+ if (newState)
31163116+ return newState;
31173117+ if (tr.docChanged)
31183118+ return new CollabState(collab2.version, collab2.unconfirmed.concat(unconfirmedFrom(tr)));
31193119+ return collab2;
31203120+ }
31213121+ },
31223122+ config: conf,
31233123+ // This is used to notify the history plugin to not merge steps,
31243124+ // so that the history can be rebased.
31253125+ historyPreserveItems: true
31263126+ });
31273127+}
31283128+function receiveTransaction(state, steps, clientIDs, options = {}) {
31293129+ let collabState = collabKey.getState(state);
31303130+ let version = collabState.version + steps.length;
31313131+ let ourID = collabKey.get(state).spec.config.clientID;
31323132+ let ours = 0;
31333133+ while (ours < clientIDs.length && clientIDs[ours] == ourID)
31343134+ ++ours;
31353135+ let unconfirmed = collabState.unconfirmed.slice(ours);
31363136+ steps = ours ? steps.slice(ours) : steps;
31373137+ if (!steps.length)
31383138+ return state.tr.setMeta(collabKey, new CollabState(version, unconfirmed));
31393139+ let nUnconfirmed = unconfirmed.length;
31403140+ let tr = state.tr;
31413141+ if (nUnconfirmed) {
31423142+ unconfirmed = rebaseSteps(unconfirmed, steps, tr);
31433143+ } else {
31443144+ for (let i = 0; i < steps.length; i++)
31453145+ tr.step(steps[i]);
31463146+ unconfirmed = [];
31473147+ }
31483148+ let newCollabState = new CollabState(version, unconfirmed);
31493149+ if (options && options.mapSelectionBackward && state.selection instanceof TextSelection) {
31503150+ tr.setSelection(TextSelection.between(tr.doc.resolve(tr.mapping.map(state.selection.anchor, -1)), tr.doc.resolve(tr.mapping.map(state.selection.head, -1)), -1));
31513151+ tr.updated &= ~1;
31523152+ }
31533153+ return tr.setMeta("rebased", nUnconfirmed).setMeta("addToHistory", false).setMeta(collabKey, newCollabState);
31543154+}
31553155+function sendableSteps(state) {
31563156+ let collabState = collabKey.getState(state);
31573157+ if (collabState.unconfirmed.length == 0)
31583158+ return null;
31593159+ return {
31603160+ version: collabState.version,
31613161+ steps: collabState.unconfirmed.map((s) => s.step),
31623162+ clientID: collabKey.get(state).spec.config.clientID,
31633163+ get origins() {
31643164+ return this._origins || (this._origins = collabState.unconfirmed.map((s) => s.origin));
31653165+ }
31663166+ };
31673167+}
31683168+function getVersion(state) {
31693169+ return collabKey.getState(state).version;
31703170+}
31713171+export {
31723172+ collab,
31733173+ getVersion,
31743174+ rebaseSteps,
31753175+ receiveTransaction,
31763176+ sendableSteps
31773177+};