@box/threaded-annotations 4.1.9 → 4.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/chunks/annotation-badge.js +1 -64
  2. package/dist/chunks/custom-placeholder.js +1 -72
  3. package/dist/chunks/delete-annotations-message-popover.js +1 -46
  4. package/dist/chunks/delete-confirmation-popover.js +1 -67
  5. package/dist/chunks/dist.js +2 -1757
  6. package/dist/chunks/mention-component.js +1 -106
  7. package/dist/chunks/message-editor.module.js +1 -12
  8. package/dist/chunks/message-editor2.module.js +1 -29
  9. package/dist/chunks/message-header.js +1 -49
  10. package/dist/chunks/messages-view.js +1 -99
  11. package/dist/chunks/resolved-state.js +1 -55
  12. package/dist/chunks/show-replies-button.js +1 -60
  13. package/dist/chunks/text-message.js +1 -21
  14. package/dist/chunks/text-message.module.js +1 -14
  15. package/dist/chunks/threaded-annotations.js +1 -71
  16. package/dist/chunks/threaded-annotations2.js +1 -87
  17. package/dist/chunks/timestamp-toggle.js +1 -36
  18. package/dist/chunks/virtualized-messages.js +1 -30
  19. package/dist/esm/index.js +1 -8
  20. package/dist/esm/lib/components/mention-component/mention-component.js +1 -2
  21. package/dist/esm/lib/components/mention-component/mention-context.js +1 -26
  22. package/dist/esm/lib/components/message-editor/editor-extensions/custom-mention/custom-mention-suggestions.js +1 -23
  23. package/dist/esm/lib/components/message-editor/editor-extensions/custom-mention/custom-mention.js +1 -59
  24. package/dist/esm/lib/components/message-editor/editor-extensions/custom-mention/useMentionState.js +1 -24
  25. package/dist/esm/lib/components/message-editor/editor-extensions/custom-paragraph.js +1 -13
  26. package/dist/esm/lib/components/message-editor/editor-extensions/custom-placeholder/custom-placeholder-utils.js +1 -26
  27. package/dist/esm/lib/components/message-editor/editor-extensions/custom-placeholder/custom-placeholder.js +1 -2
  28. package/dist/esm/lib/components/message-editor/error-message.js +1 -17
  29. package/dist/esm/lib/components/message-editor/hooks/useMessageEditor.js +1 -69
  30. package/dist/esm/lib/components/message-editor/hooks/useMessagePost.js +1 -35
  31. package/dist/esm/lib/components/message-editor/message-editor-actions.js +1 -29
  32. package/dist/esm/lib/components/message-editor/message-editor-context.js +1 -7
  33. package/dist/esm/lib/components/message-editor/message-editor.js +1 -74
  34. package/dist/esm/lib/components/message-editor/messages.js +1 -44
  35. package/dist/esm/lib/components/message-editor/utils/getMessageEditorState.js +1 -9
  36. package/dist/esm/lib/components/message-header/delete-annotations-message-popover.js +1 -2
  37. package/dist/esm/lib/components/message-header/message-header.js +1 -2
  38. package/dist/esm/lib/components/message-header/messages.js +1 -32
  39. package/dist/esm/lib/components/messages-view/consts.js +1 -2
  40. package/dist/esm/lib/components/messages-view/hooks/useAutoScroll.js +1 -43
  41. package/dist/esm/lib/components/messages-view/hooks/useShowMoreReplies.js +1 -26
  42. package/dist/esm/lib/components/messages-view/hooks/useVirtualizedMessages.js +1 -17
  43. package/dist/esm/lib/components/messages-view/messages-view.js +1 -61
  44. package/dist/esm/lib/components/messages-view/messages.js +1 -12
  45. package/dist/esm/lib/components/messages-view/virtualized-messages.js +1 -2
  46. package/dist/esm/lib/components/text-message/message-renderer.js +1 -58
  47. package/dist/esm/lib/components/text-message/text-message.js +1 -2
  48. package/dist/esm/lib/components/user-avatar/getInitials.js +1 -5
  49. package/dist/esm/lib/components/user-avatar/messages.js +1 -12
  50. package/dist/esm/lib/components/user-avatar/user-avatar.js +1 -31
  51. package/dist/esm/lib/components/v2/annotation-badge/annotation-badge.js +1 -2
  52. package/dist/esm/lib/components/v2/annotation-badge/index.js +1 -2
  53. package/dist/esm/lib/components/v2/annotation-badge/messages.js +1 -12
  54. package/dist/esm/lib/components/v2/message-editor/editor-extensions/custom-mention/custom-mention-suggestions.js +1 -23
  55. package/dist/esm/lib/components/v2/message-editor/editor-extensions/custom-mention/custom-mention.js +1 -59
  56. package/dist/esm/lib/components/v2/message-editor/editor-extensions/custom-mention/mention-trigger-normalization.js +1 -2
  57. package/dist/esm/lib/components/v2/message-editor/editor-extensions/custom-mention/useMentionState.js +1 -27
  58. package/dist/esm/lib/components/v2/message-editor/editor-extensions/custom-paragraph.js +1 -13
  59. package/dist/esm/lib/components/v2/message-editor/hooks/useCharacterLimit.js +1 -24
  60. package/dist/esm/lib/components/v2/message-editor/hooks/useEditorContainerState.js +1 -21
  61. package/dist/esm/lib/components/v2/message-editor/hooks/useMentionUserSelection.js +1 -21
  62. package/dist/esm/lib/components/v2/message-editor/hooks/useMessageSubmit.js +1 -24
  63. package/dist/esm/lib/components/v2/message-editor/message-editor-context.js +1 -19
  64. package/dist/esm/lib/components/v2/message-editor/message-editor.js +1 -187
  65. package/dist/esm/lib/components/v2/message-editor/message-editor.types.js +1 -4
  66. package/dist/esm/lib/components/v2/message-editor/messages.js +1 -52
  67. package/dist/esm/lib/components/v2/message-editor/subcomponents/character-limit-counter.js +1 -26
  68. package/dist/esm/lib/components/v2/message-editor/subcomponents/edit-buttons.js +1 -32
  69. package/dist/esm/lib/components/v2/message-editor/subcomponents/error-message.js +1 -22
  70. package/dist/esm/lib/components/v2/message-editor/subcomponents/post-button.js +1 -29
  71. package/dist/esm/lib/components/v2/message-editor/subcomponents/timestamp-toggle.js +1 -2
  72. package/dist/esm/lib/components/v2/message-header/delete-confirmation-popover.js +1 -2
  73. package/dist/esm/lib/components/v2/message-header/message-header.js +1 -90
  74. package/dist/esm/lib/components/v2/message-header/message-options-menu.js +1 -49
  75. package/dist/esm/lib/components/v2/message-header/messages.js +2 -48
  76. package/dist/esm/lib/components/v2/messages-view/hooks/useAutoScroll.js +1 -69
  77. package/dist/esm/lib/components/v2/messages-view/messages-view.js +1 -2
  78. package/dist/esm/lib/components/v2/resolved-state/messages.js +1 -12
  79. package/dist/esm/lib/components/v2/resolved-state/resolved-state.js +1 -2
  80. package/dist/esm/lib/components/v2/show-replies-button/messages.js +1 -12
  81. package/dist/esm/lib/components/v2/show-replies-button/show-replies-button.js +1 -2
  82. package/dist/esm/lib/components/v2/text-message/constants.js +1 -2
  83. package/dist/esm/lib/components/v2/text-message/messages.js +1 -32
  84. package/dist/esm/lib/components/v2/text-message/subcomponents/message-footer.js +1 -64
  85. package/dist/esm/lib/components/v2/text-message/subcomponents/message-renderer.js +1 -87
  86. package/dist/esm/lib/components/v2/text-message/subcomponents/truncate-document.js +1 -113
  87. package/dist/esm/lib/components/v2/text-message/subcomponents/url-segments.js +1 -38
  88. package/dist/esm/lib/components/v2/text-message/text-message.js +1 -79
  89. package/dist/esm/lib/components/v2/user-avatar/getInitials.js +1 -5
  90. package/dist/esm/lib/components/v2/user-avatar/messages.js +1 -12
  91. package/dist/esm/lib/components/v2/user-avatar/user-avatar.js +1 -37
  92. package/dist/esm/lib/messages.js +1 -24
  93. package/dist/esm/lib/threaded-annotations.js +1 -2
  94. package/dist/esm/lib/utils/getErrorMessage.js +1 -2
  95. package/dist/esm/lib/v2/constants.js +1 -2
  96. package/dist/esm/lib/v2/messages.js +1 -6
  97. package/dist/esm/lib/v2/resin-targets.js +1 -25
  98. package/dist/esm/lib/v2/threaded-annotations-context.js +1 -61
  99. package/dist/esm/lib/v2/threaded-annotations.js +1 -2
  100. package/dist/esm/lib/v2/types/annotation-badge-types.js +1 -4
  101. package/dist/esm/lib/v2/types/index.js +1 -2
  102. package/dist/esm/lib/v2/utils/build-mention-content.js +1 -20
  103. package/dist/esm/lib/v2/utils/serialize-mention-markup.js +2 -12
  104. package/package.json +12 -12
@@ -1,1757 +1,2 @@
1
- function e(t, i, a) {
2
- for (let o = 0;; o++) {
3
- if (o == t.childCount || o == i.childCount) return t.childCount == i.childCount ? null : a;
4
- let s = t.child(o), c = i.child(o);
5
- if (s == c) {
6
- a += s.nodeSize;
7
- continue;
8
- }
9
- if (!s.sameMarkup(c)) return a;
10
- if (s.isText && s.text != c.text) {
11
- let e = s.text, t = c.text, i = 0;
12
- for (; e[i] == t[i]; i++) a++;
13
- return i && i < e.length && i < t.length && r(e.charCodeAt(i - 1)) && n(e.charCodeAt(i)) && a--, a;
14
- }
15
- if (s.content.size || c.content.size) {
16
- let t = e(s.content, c.content, a + 1);
17
- if (t != null) return t;
18
- }
19
- a += s.nodeSize;
20
- }
21
- }
22
- function t(e, i, a, o) {
23
- for (let s = e.childCount, c = i.childCount;;) {
24
- if (s == 0 || c == 0) return s == c ? null : {
25
- a,
26
- b: o
27
- };
28
- let l = e.child(--s), u = i.child(--c), d = l.nodeSize;
29
- if (l == u) {
30
- a -= d, o -= d;
31
- continue;
32
- }
33
- if (!l.sameMarkup(u)) return {
34
- a,
35
- b: o
36
- };
37
- if (l.isText && l.text != u.text) {
38
- let e = l.text, t = u.text, i = e.length, s = t.length;
39
- for (; i > 0 && s > 0 && e[i - 1] == t[s - 1];) i--, s--, a--, o--;
40
- return i && s && i < e.length && r(e.charCodeAt(i - 1)) && n(e.charCodeAt(i)) && (a++, o++), {
41
- a,
42
- b: o
43
- };
44
- }
45
- if (l.content.size || u.content.size) {
46
- let e = t(l.content, u.content, a - 1, o - 1);
47
- if (e) return e;
48
- }
49
- a -= d, o -= d;
50
- }
51
- }
52
- function n(e) {
53
- return e >= 56320 && e < 57344;
54
- }
55
- function r(e) {
56
- return e >= 55296 && e < 56320;
57
- }
58
- var i = class n {
59
- constructor(e, t) {
60
- if (this.content = e, this.size = t || 0, t == null) for (let t = 0; t < e.length; t++) this.size += e[t].nodeSize;
61
- }
62
- nodesBetween(e, t, n, r = 0, i) {
63
- for (let a = 0, o = 0; o < t; a++) {
64
- let s = this.content[a], c = o + s.nodeSize;
65
- if (c > e && n(s, r + o, i || null, a) !== !1 && s.content.size) {
66
- let i = o + 1;
67
- s.nodesBetween(Math.max(0, e - i), Math.min(s.content.size, t - i), n, r + i);
68
- }
69
- o = c;
70
- }
71
- }
72
- descendants(e) {
73
- this.nodesBetween(0, this.size, e);
74
- }
75
- textBetween(e, t, n, r) {
76
- let i = "", a = !0;
77
- return this.nodesBetween(e, t, (o, s) => {
78
- let c = o.isText ? o.text.slice(Math.max(e, s) - s, t - s) : o.isLeaf ? r ? typeof r == "function" ? r(o) : r : o.type.spec.leafText ? o.type.spec.leafText(o) : "" : "";
79
- o.isBlock && (o.isLeaf && c || o.isTextblock) && n && (a ? a = !1 : i += n), i += c;
80
- }, 0), i;
81
- }
82
- append(e) {
83
- if (!e.size) return this;
84
- if (!this.size) return e;
85
- let t = this.lastChild, r = e.firstChild, i = this.content.slice(), a = 0;
86
- for (t.isText && t.sameMarkup(r) && (i[i.length - 1] = t.withText(t.text + r.text), a = 1); a < e.content.length; a++) i.push(e.content[a]);
87
- return new n(i, this.size + e.size);
88
- }
89
- cut(e, t = this.size) {
90
- if (e == 0 && t == this.size) return this;
91
- let r = [], i = 0;
92
- if (t > e) for (let n = 0, a = 0; a < t; n++) {
93
- let o = this.content[n], s = a + o.nodeSize;
94
- s > e && ((a < e || s > t) && (o = o.isText ? o.cut(Math.max(0, e - a), Math.min(o.text.length, t - a)) : o.cut(Math.max(0, e - a - 1), Math.min(o.content.size, t - a - 1))), r.push(o), i += o.nodeSize), a = s;
95
- }
96
- return new n(r, i);
97
- }
98
- cutByIndex(e, t) {
99
- return e == t ? n.empty : e == 0 && t == this.content.length ? this : new n(this.content.slice(e, t));
100
- }
101
- replaceChild(e, t) {
102
- let r = this.content[e];
103
- if (r == t) return this;
104
- let i = this.content.slice(), a = this.size + t.nodeSize - r.nodeSize;
105
- return i[e] = t, new n(i, a);
106
- }
107
- addToStart(e) {
108
- return new n([e].concat(this.content), this.size + e.nodeSize);
109
- }
110
- addToEnd(e) {
111
- return new n(this.content.concat(e), this.size + e.nodeSize);
112
- }
113
- eq(e) {
114
- if (this.content.length != e.content.length) return !1;
115
- for (let t = 0; t < this.content.length; t++) if (!this.content[t].eq(e.content[t])) return !1;
116
- return !0;
117
- }
118
- get firstChild() {
119
- return this.content.length ? this.content[0] : null;
120
- }
121
- get lastChild() {
122
- return this.content.length ? this.content[this.content.length - 1] : null;
123
- }
124
- get childCount() {
125
- return this.content.length;
126
- }
127
- child(e) {
128
- let t = this.content[e];
129
- if (!t) throw RangeError("Index " + e + " out of range for " + this);
130
- return t;
131
- }
132
- maybeChild(e) {
133
- return this.content[e] || null;
134
- }
135
- forEach(e) {
136
- for (let t = 0, n = 0; t < this.content.length; t++) {
137
- let r = this.content[t];
138
- e(r, n, t), n += r.nodeSize;
139
- }
140
- }
141
- findDiffStart(t, n = 0) {
142
- return e(this, t, n);
143
- }
144
- findDiffEnd(e, n = this.size, r = e.size) {
145
- return t(this, e, n, r);
146
- }
147
- findIndex(e) {
148
- if (e == 0) return o(0, e);
149
- if (e == this.size) return o(this.content.length, e);
150
- if (e > this.size || e < 0) throw RangeError(`Position ${e} outside of fragment (${this})`);
151
- for (let t = 0, n = 0;; t++) {
152
- let r = this.child(t), i = n + r.nodeSize;
153
- if (i >= e) return i == e ? o(t + 1, i) : o(t, n);
154
- n = i;
155
- }
156
- }
157
- toString() {
158
- return "<" + this.toStringInner() + ">";
159
- }
160
- toStringInner() {
161
- return this.content.join(", ");
162
- }
163
- toJSON() {
164
- return this.content.length ? this.content.map((e) => e.toJSON()) : null;
165
- }
166
- static fromJSON(e, t) {
167
- if (!t) return n.empty;
168
- if (!Array.isArray(t)) throw RangeError("Invalid input for Fragment.fromJSON");
169
- return n.fromArray(t.map(e.nodeFromJSON));
170
- }
171
- static fromArray(e) {
172
- if (!e.length) return n.empty;
173
- let t, r = 0;
174
- for (let n = 0; n < e.length; n++) {
175
- let i = e[n];
176
- r += i.nodeSize, n && i.isText && e[n - 1].sameMarkup(i) ? (t ||= e.slice(0, n), t[t.length - 1] = i.withText(t[t.length - 1].text + i.text)) : t && t.push(i);
177
- }
178
- return new n(t || e, r);
179
- }
180
- static from(e) {
181
- if (!e) return n.empty;
182
- if (e instanceof n) return e;
183
- if (Array.isArray(e)) return this.fromArray(e);
184
- if (e.attrs) return new n([e], e.nodeSize);
185
- throw RangeError("Can not convert " + e + " to a Fragment" + (e.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
186
- }
187
- };
188
- i.empty = new i([], 0);
189
- var a = {
190
- index: 0,
191
- offset: 0
192
- };
193
- function o(e, t) {
194
- return a.index = e, a.offset = t, a;
195
- }
196
- function s(e, t) {
197
- if (e === t) return !0;
198
- if (!(e && typeof e == "object") || !(t && typeof t == "object")) return !1;
199
- let n = Array.isArray(e);
200
- if (Array.isArray(t) != n) return !1;
201
- if (n) {
202
- if (e.length != t.length) return !1;
203
- for (let n = 0; n < e.length; n++) if (!s(e[n], t[n])) return !1;
204
- } else {
205
- for (let n in e) if (!(n in t) || !s(e[n], t[n])) return !1;
206
- for (let n in t) if (!(n in e)) return !1;
207
- }
208
- return !0;
209
- }
210
- var c = class e {
211
- constructor(e, t) {
212
- this.type = e, this.attrs = t;
213
- }
214
- addToSet(e) {
215
- let t, n = !1;
216
- for (let r = 0; r < e.length; r++) {
217
- let i = e[r];
218
- if (this.eq(i)) return e;
219
- if (this.type.excludes(i.type)) t ||= e.slice(0, r);
220
- else if (i.type.excludes(this.type)) return e;
221
- else !n && i.type.rank > this.type.rank && (t ||= e.slice(0, r), t.push(this), n = !0), t && t.push(i);
222
- }
223
- return t ||= e.slice(), n || t.push(this), t;
224
- }
225
- removeFromSet(e) {
226
- for (let t = 0; t < e.length; t++) if (this.eq(e[t])) return e.slice(0, t).concat(e.slice(t + 1));
227
- return e;
228
- }
229
- isInSet(e) {
230
- for (let t = 0; t < e.length; t++) if (this.eq(e[t])) return !0;
231
- return !1;
232
- }
233
- eq(e) {
234
- return this == e || this.type == e.type && s(this.attrs, e.attrs);
235
- }
236
- toJSON() {
237
- let e = { type: this.type.name };
238
- for (let t in this.attrs) {
239
- e.attrs = this.attrs;
240
- break;
241
- }
242
- return e;
243
- }
244
- static fromJSON(e, t) {
245
- if (!t) throw RangeError("Invalid input for Mark.fromJSON");
246
- let n = e.marks[t.type];
247
- if (!n) throw RangeError(`There is no mark type ${t.type} in this schema`);
248
- let r = n.create(t.attrs);
249
- return n.checkAttrs(r.attrs), r;
250
- }
251
- static sameSet(e, t) {
252
- if (e == t) return !0;
253
- if (e.length != t.length) return !1;
254
- for (let n = 0; n < e.length; n++) if (!e[n].eq(t[n])) return !1;
255
- return !0;
256
- }
257
- static setFrom(t) {
258
- if (!t || Array.isArray(t) && t.length == 0) return e.none;
259
- if (t instanceof e) return [t];
260
- let n = t.slice();
261
- return n.sort((e, t) => e.type.rank - t.type.rank), n;
262
- }
263
- };
264
- c.none = [];
265
- var l = class extends Error {}, u = class e {
266
- constructor(e, t, n) {
267
- this.content = e, this.openStart = t, this.openEnd = n;
268
- }
269
- get size() {
270
- return this.content.size - this.openStart - this.openEnd;
271
- }
272
- insertAt(t, n) {
273
- let r = f(this.content, t + this.openStart, n, this.openStart + 1, this.openEnd + 1);
274
- return r && new e(r, this.openStart, this.openEnd);
275
- }
276
- removeBetween(t, n) {
277
- return new e(d(this.content, t + this.openStart, n + this.openStart), this.openStart, this.openEnd);
278
- }
279
- eq(e) {
280
- return this.content.eq(e.content) && this.openStart == e.openStart && this.openEnd == e.openEnd;
281
- }
282
- toString() {
283
- return this.content + "(" + this.openStart + "," + this.openEnd + ")";
284
- }
285
- toJSON() {
286
- if (!this.content.size) return null;
287
- let e = { content: this.content.toJSON() };
288
- return this.openStart > 0 && (e.openStart = this.openStart), this.openEnd > 0 && (e.openEnd = this.openEnd), e;
289
- }
290
- static fromJSON(t, n) {
291
- if (!n) return e.empty;
292
- let r = n.openStart || 0, a = n.openEnd || 0;
293
- if (typeof r != "number" || typeof a != "number") throw RangeError("Invalid input for Slice.fromJSON");
294
- return new e(i.fromJSON(t, n.content), r, a);
295
- }
296
- static maxOpen(t, n = !0) {
297
- let r = 0, i = 0;
298
- for (let e = t.firstChild; e && !e.isLeaf && (n || !e.type.spec.isolating); e = e.firstChild) r++;
299
- for (let e = t.lastChild; e && !e.isLeaf && (n || !e.type.spec.isolating); e = e.lastChild) i++;
300
- return new e(t, r, i);
301
- }
302
- };
303
- u.empty = new u(i.empty, 0, 0);
304
- function d(e, t, n) {
305
- let { index: r, offset: i } = e.findIndex(t), a = e.maybeChild(r), { index: o, offset: s } = e.findIndex(n);
306
- if (i == t || a.isText) {
307
- if (s != n && !e.child(o).isText) throw RangeError("Removing non-flat range");
308
- return e.cut(0, t).append(e.cut(n));
309
- }
310
- if (r != o) throw RangeError("Removing non-flat range");
311
- return e.replaceChild(r, a.copy(d(a.content, t - i - 1, n - i - 1)));
312
- }
313
- function f(e, t, n, r, i, a) {
314
- let { index: o, offset: s } = e.findIndex(t), c = e.maybeChild(o);
315
- if (s == t || c.isText) return a && r <= 0 && i <= 0 && !a.canReplace(o, o, n) ? null : e.cut(0, t).append(n).append(e.cut(t));
316
- let l = f(c.content, t - s - 1, n, o == 0 ? r - 1 : 0, o == e.childCount - 1 ? i - 1 : 0, c);
317
- return l && e.replaceChild(o, c.copy(l));
318
- }
319
- function ee(e, t, n) {
320
- if (n.openStart > e.depth) throw new l("Inserted content deeper than insertion position");
321
- if (e.depth - n.openStart != t.depth - n.openEnd) throw new l("Inconsistent open depths");
322
- return p(e, t, n, 0);
323
- }
324
- function p(e, t, n, r) {
325
- let i = e.index(r), a = e.node(r);
326
- if (i == t.index(r) && r < e.depth - n.openStart) {
327
- let o = p(e, t, n, r + 1);
328
- return a.copy(a.content.replaceChild(i, o));
329
- } else if (!n.content.size) return v(a, y(e, t, r));
330
- else if (!n.openStart && !n.openEnd && e.depth == r && t.depth == r) {
331
- let r = e.parent, i = r.content;
332
- return v(r, i.cut(0, e.parentOffset).append(n.content).append(i.cut(t.parentOffset)));
333
- } else {
334
- let { start: i, end: o } = ne(n, e);
335
- return v(a, te(e, i, o, t, r));
336
- }
337
- }
338
- function m(e, t) {
339
- if (!t.type.compatibleContent(e.type)) throw new l("Cannot join " + t.type.name + " onto " + e.type.name);
340
- }
341
- function h(e, t, n) {
342
- let r = e.node(n);
343
- return m(r, t.node(n)), r;
344
- }
345
- function g(e, t) {
346
- let n = t.length - 1;
347
- n >= 0 && e.isText && e.sameMarkup(t[n]) ? t[n] = e.withText(t[n].text + e.text) : t.push(e);
348
- }
349
- function _(e, t, n, r) {
350
- let i = (t || e).node(n), a = 0, o = t ? t.index(n) : i.childCount;
351
- e && (a = e.index(n), e.depth > n ? a++ : e.textOffset && (g(e.nodeAfter, r), a++));
352
- for (let e = a; e < o; e++) g(i.child(e), r);
353
- t && t.depth == n && t.textOffset && g(t.nodeBefore, r);
354
- }
355
- function v(e, t) {
356
- if (!e.type.validContent(t)) throw new l("Invalid content for node " + e.type.name);
357
- return e.copy(t);
358
- }
359
- function te(e, t, n, r, a) {
360
- let o = e.depth > a && h(e, t, a + 1), s = r.depth > a && h(n, r, a + 1), c = [];
361
- return _(null, e, a, c), o && s && t.index(a) == n.index(a) ? (m(o, s), g(v(o, te(e, t, n, r, a + 1)), c)) : (o && g(v(o, y(e, t, a + 1)), c), _(t, n, a, c), s && g(v(s, y(n, r, a + 1)), c)), _(r, null, a, c), new i(c);
362
- }
363
- function y(e, t, n) {
364
- let r = [];
365
- return _(null, e, n, r), e.depth > n && g(v(h(e, t, n + 1), y(e, t, n + 1)), r), _(t, null, n, r), new i(r);
366
- }
367
- function ne(e, t) {
368
- let n = t.depth - e.openStart, r = t.node(n).copy(e.content);
369
- for (let e = n - 1; e >= 0; e--) r = t.node(e).copy(i.from(r));
370
- return {
371
- start: r.resolveNoCache(e.openStart + n),
372
- end: r.resolveNoCache(r.content.size - e.openEnd - n)
373
- };
374
- }
375
- var b = class e {
376
- constructor(e, t, n) {
377
- this.pos = e, this.path = t, this.parentOffset = n, this.depth = t.length / 3 - 1;
378
- }
379
- resolveDepth(e) {
380
- return e == null ? this.depth : e < 0 ? this.depth + e : e;
381
- }
382
- get parent() {
383
- return this.node(this.depth);
384
- }
385
- get doc() {
386
- return this.node(0);
387
- }
388
- node(e) {
389
- return this.path[this.resolveDepth(e) * 3];
390
- }
391
- index(e) {
392
- return this.path[this.resolveDepth(e) * 3 + 1];
393
- }
394
- indexAfter(e) {
395
- return e = this.resolveDepth(e), this.index(e) + (e == this.depth && !this.textOffset ? 0 : 1);
396
- }
397
- start(e) {
398
- return e = this.resolveDepth(e), e == 0 ? 0 : this.path[e * 3 - 1] + 1;
399
- }
400
- end(e) {
401
- return e = this.resolveDepth(e), this.start(e) + this.node(e).content.size;
402
- }
403
- before(e) {
404
- if (e = this.resolveDepth(e), !e) throw RangeError("There is no position before the top-level node");
405
- return e == this.depth + 1 ? this.pos : this.path[e * 3 - 1];
406
- }
407
- after(e) {
408
- if (e = this.resolveDepth(e), !e) throw RangeError("There is no position after the top-level node");
409
- return e == this.depth + 1 ? this.pos : this.path[e * 3 - 1] + this.path[e * 3].nodeSize;
410
- }
411
- get textOffset() {
412
- return this.pos - this.path[this.path.length - 1];
413
- }
414
- get nodeAfter() {
415
- let e = this.parent, t = this.index(this.depth);
416
- if (t == e.childCount) return null;
417
- let n = this.pos - this.path[this.path.length - 1], r = e.child(t);
418
- return n ? e.child(t).cut(n) : r;
419
- }
420
- get nodeBefore() {
421
- let e = this.index(this.depth), t = this.pos - this.path[this.path.length - 1];
422
- return t ? this.parent.child(e).cut(0, t) : e == 0 ? null : this.parent.child(e - 1);
423
- }
424
- posAtIndex(e, t) {
425
- t = this.resolveDepth(t);
426
- let n = this.path[t * 3], r = t == 0 ? 0 : this.path[t * 3 - 1] + 1;
427
- for (let t = 0; t < e; t++) r += n.child(t).nodeSize;
428
- return r;
429
- }
430
- marks() {
431
- let e = this.parent, t = this.index();
432
- if (e.content.size == 0) return c.none;
433
- if (this.textOffset) return e.child(t).marks;
434
- let n = e.maybeChild(t - 1), r = e.maybeChild(t);
435
- if (!n) {
436
- let e = n;
437
- n = r, r = e;
438
- }
439
- let i = n.marks;
440
- for (var a = 0; a < i.length; a++) i[a].type.spec.inclusive === !1 && (!r || !i[a].isInSet(r.marks)) && (i = i[a--].removeFromSet(i));
441
- return i;
442
- }
443
- marksAcross(e) {
444
- let t = this.parent.maybeChild(this.index());
445
- if (!t || !t.isInline) return null;
446
- let n = t.marks, r = e.parent.maybeChild(e.index());
447
- for (var i = 0; i < n.length; i++) n[i].type.spec.inclusive === !1 && (!r || !n[i].isInSet(r.marks)) && (n = n[i--].removeFromSet(n));
448
- return n;
449
- }
450
- sharedDepth(e) {
451
- for (let t = this.depth; t > 0; t--) if (this.start(t) <= e && this.end(t) >= e) return t;
452
- return 0;
453
- }
454
- blockRange(e = this, t) {
455
- if (e.pos < this.pos) return e.blockRange(this);
456
- for (let n = this.depth - (this.parent.inlineContent || this.pos == e.pos ? 1 : 0); n >= 0; n--) if (e.pos <= this.end(n) && (!t || t(this.node(n)))) return new ae(this, e, n);
457
- return null;
458
- }
459
- sameParent(e) {
460
- return this.pos - this.parentOffset == e.pos - e.parentOffset;
461
- }
462
- max(e) {
463
- return e.pos > this.pos ? e : this;
464
- }
465
- min(e) {
466
- return e.pos < this.pos ? e : this;
467
- }
468
- toString() {
469
- let e = "";
470
- for (let t = 1; t <= this.depth; t++) e += (e ? "/" : "") + this.node(t).type.name + "_" + this.index(t - 1);
471
- return e + ":" + this.parentOffset;
472
- }
473
- static resolve(t, n) {
474
- if (!(n >= 0 && n <= t.content.size)) throw RangeError("Position " + n + " out of range");
475
- let r = [], i = 0, a = n;
476
- for (let e = t;;) {
477
- let { index: t, offset: n } = e.content.findIndex(a), o = a - n;
478
- if (r.push(e, t, i + n), !o || (e = e.child(t), e.isText)) break;
479
- a = o - 1, i += n + 1;
480
- }
481
- return new e(n, r, a);
482
- }
483
- static resolveCached(t, n) {
484
- let r = x.get(t);
485
- if (r) for (let e = 0; e < r.elts.length; e++) {
486
- let t = r.elts[e];
487
- if (t.pos == n) return t;
488
- }
489
- else x.set(t, r = new re());
490
- let i = r.elts[r.i] = e.resolve(t, n);
491
- return r.i = (r.i + 1) % ie, i;
492
- }
493
- }, re = class {
494
- constructor() {
495
- this.elts = [], this.i = 0;
496
- }
497
- }, ie = 12, x = /* @__PURE__ */ new WeakMap(), ae = class {
498
- constructor(e, t, n) {
499
- this.$from = e, this.$to = t, this.depth = n;
500
- }
501
- get start() {
502
- return this.$from.before(this.depth + 1);
503
- }
504
- get end() {
505
- return this.$to.after(this.depth + 1);
506
- }
507
- get parent() {
508
- return this.$from.node(this.depth);
509
- }
510
- get startIndex() {
511
- return this.$from.index(this.depth);
512
- }
513
- get endIndex() {
514
- return this.$to.indexAfter(this.depth);
515
- }
516
- }, oe = Object.create(null), se = class e {
517
- constructor(e, t, n, r = c.none) {
518
- this.type = e, this.attrs = t, this.marks = r, this.content = n || i.empty;
519
- }
520
- get children() {
521
- return this.content.content;
522
- }
523
- get nodeSize() {
524
- return this.isLeaf ? 1 : 2 + this.content.size;
525
- }
526
- get childCount() {
527
- return this.content.childCount;
528
- }
529
- child(e) {
530
- return this.content.child(e);
531
- }
532
- maybeChild(e) {
533
- return this.content.maybeChild(e);
534
- }
535
- forEach(e) {
536
- this.content.forEach(e);
537
- }
538
- nodesBetween(e, t, n, r = 0) {
539
- this.content.nodesBetween(e, t, n, r, this);
540
- }
541
- descendants(e) {
542
- this.nodesBetween(0, this.content.size, e);
543
- }
544
- get textContent() {
545
- return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
546
- }
547
- textBetween(e, t, n, r) {
548
- return this.content.textBetween(e, t, n, r);
549
- }
550
- get firstChild() {
551
- return this.content.firstChild;
552
- }
553
- get lastChild() {
554
- return this.content.lastChild;
555
- }
556
- eq(e) {
557
- return this == e || this.sameMarkup(e) && this.content.eq(e.content);
558
- }
559
- sameMarkup(e) {
560
- return this.hasMarkup(e.type, e.attrs, e.marks);
561
- }
562
- hasMarkup(e, t, n) {
563
- return this.type == e && s(this.attrs, t || e.defaultAttrs || oe) && c.sameSet(this.marks, n || c.none);
564
- }
565
- copy(t = null) {
566
- return t == this.content ? this : new e(this.type, this.attrs, t, this.marks);
567
- }
568
- mark(t) {
569
- return t == this.marks ? this : new e(this.type, this.attrs, this.content, t);
570
- }
571
- cut(e, t = this.content.size) {
572
- return e == 0 && t == this.content.size ? this : this.copy(this.content.cut(e, t));
573
- }
574
- slice(e, t = this.content.size, n = !1) {
575
- if (e == t) return u.empty;
576
- let r = this.resolve(e), i = this.resolve(t), a = n ? 0 : r.sharedDepth(t), o = r.start(a);
577
- return new u(r.node(a).content.cut(r.pos - o, i.pos - o), r.depth - a, i.depth - a);
578
- }
579
- replace(e, t, n) {
580
- return ee(this.resolve(e), this.resolve(t), n);
581
- }
582
- nodeAt(e) {
583
- for (let t = this;;) {
584
- let { index: n, offset: r } = t.content.findIndex(e);
585
- if (t = t.maybeChild(n), !t) return null;
586
- if (r == e || t.isText) return t;
587
- e -= r + 1;
588
- }
589
- }
590
- childAfter(e) {
591
- let { index: t, offset: n } = this.content.findIndex(e);
592
- return {
593
- node: this.content.maybeChild(t),
594
- index: t,
595
- offset: n
596
- };
597
- }
598
- childBefore(e) {
599
- if (e == 0) return {
600
- node: null,
601
- index: 0,
602
- offset: 0
603
- };
604
- let { index: t, offset: n } = this.content.findIndex(e);
605
- if (n < e) return {
606
- node: this.content.child(t),
607
- index: t,
608
- offset: n
609
- };
610
- let r = this.content.child(t - 1);
611
- return {
612
- node: r,
613
- index: t - 1,
614
- offset: n - r.nodeSize
615
- };
616
- }
617
- resolve(e) {
618
- return b.resolveCached(this, e);
619
- }
620
- resolveNoCache(e) {
621
- return b.resolve(this, e);
622
- }
623
- rangeHasMark(e, t, n) {
624
- let r = !1;
625
- return t > e && this.nodesBetween(e, t, (e) => (n.isInSet(e.marks) && (r = !0), !r)), r;
626
- }
627
- get isBlock() {
628
- return this.type.isBlock;
629
- }
630
- get isTextblock() {
631
- return this.type.isTextblock;
632
- }
633
- get inlineContent() {
634
- return this.type.inlineContent;
635
- }
636
- get isInline() {
637
- return this.type.isInline;
638
- }
639
- get isText() {
640
- return this.type.isText;
641
- }
642
- get isLeaf() {
643
- return this.type.isLeaf;
644
- }
645
- get isAtom() {
646
- return this.type.isAtom;
647
- }
648
- toString() {
649
- if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this);
650
- let e = this.type.name;
651
- return this.content.size && (e += "(" + this.content.toStringInner() + ")"), ce(this.marks, e);
652
- }
653
- contentMatchAt(e) {
654
- let t = this.type.contentMatch.matchFragment(this.content, 0, e);
655
- if (!t) throw Error("Called contentMatchAt on a node with invalid content");
656
- return t;
657
- }
658
- canReplace(e, t, n = i.empty, r = 0, a = n.childCount) {
659
- let o = this.contentMatchAt(e).matchFragment(n, r, a), s = o && o.matchFragment(this.content, t);
660
- if (!s || !s.validEnd) return !1;
661
- for (let e = r; e < a; e++) if (!this.type.allowsMarks(n.child(e).marks)) return !1;
662
- return !0;
663
- }
664
- canReplaceWith(e, t, n, r) {
665
- if (r && !this.type.allowsMarks(r)) return !1;
666
- let i = this.contentMatchAt(e).matchType(n), a = i && i.matchFragment(this.content, t);
667
- return a ? a.validEnd : !1;
668
- }
669
- canAppend(e) {
670
- return e.content.size ? this.canReplace(this.childCount, this.childCount, e.content) : this.type.compatibleContent(e.type);
671
- }
672
- check() {
673
- this.type.checkContent(this.content), this.type.checkAttrs(this.attrs);
674
- let e = c.none;
675
- for (let t = 0; t < this.marks.length; t++) {
676
- let n = this.marks[t];
677
- n.type.checkAttrs(n.attrs), e = n.addToSet(e);
678
- }
679
- if (!c.sameSet(e, this.marks)) throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((e) => e.type.name)}`);
680
- this.content.forEach((e) => e.check());
681
- }
682
- toJSON() {
683
- let e = { type: this.type.name };
684
- for (let t in this.attrs) {
685
- e.attrs = this.attrs;
686
- break;
687
- }
688
- return this.content.size && (e.content = this.content.toJSON()), this.marks.length && (e.marks = this.marks.map((e) => e.toJSON())), e;
689
- }
690
- static fromJSON(e, t) {
691
- if (!t) throw RangeError("Invalid input for Node.fromJSON");
692
- let n;
693
- if (t.marks) {
694
- if (!Array.isArray(t.marks)) throw RangeError("Invalid mark data for Node.fromJSON");
695
- n = t.marks.map(e.markFromJSON);
696
- }
697
- if (t.type == "text") {
698
- if (typeof t.text != "string") throw RangeError("Invalid text node in JSON");
699
- return e.text(t.text, n);
700
- }
701
- let r = i.fromJSON(e, t.content), a = e.nodeType(t.type).create(t.attrs, r, n);
702
- return a.type.checkAttrs(a.attrs), a;
703
- }
704
- };
705
- se.prototype.text = void 0;
706
- function ce(e, t) {
707
- for (let n = e.length - 1; n >= 0; n--) t = e[n].type.name + "(" + t + ")";
708
- return t;
709
- }
710
- var S = class e {
711
- constructor(e) {
712
- this.validEnd = e, this.next = [], this.wrapCache = [];
713
- }
714
- static parse(t, n) {
715
- let r = new le(t, n);
716
- if (r.next == null) return e.empty;
717
- let i = ue(r);
718
- r.next && r.err("Unexpected trailing text");
719
- let a = _e(ge(i));
720
- return ve(a, r), a;
721
- }
722
- matchType(e) {
723
- for (let t = 0; t < this.next.length; t++) if (this.next[t].type == e) return this.next[t].next;
724
- return null;
725
- }
726
- matchFragment(e, t = 0, n = e.childCount) {
727
- let r = this;
728
- for (let i = t; r && i < n; i++) r = r.matchType(e.child(i).type);
729
- return r;
730
- }
731
- get inlineContent() {
732
- return this.next.length != 0 && this.next[0].type.isInline;
733
- }
734
- get defaultType() {
735
- for (let e = 0; e < this.next.length; e++) {
736
- let { type: t } = this.next[e];
737
- if (!(t.isText || t.hasRequiredAttrs())) return t;
738
- }
739
- return null;
740
- }
741
- compatible(e) {
742
- for (let t = 0; t < this.next.length; t++) for (let n = 0; n < e.next.length; n++) if (this.next[t].type == e.next[n].type) return !0;
743
- return !1;
744
- }
745
- fillBefore(e, t = !1, n = 0) {
746
- let r = [this];
747
- function a(o, s) {
748
- let c = o.matchFragment(e, n);
749
- if (c && (!t || c.validEnd)) return i.from(s.map((e) => e.createAndFill()));
750
- for (let e = 0; e < o.next.length; e++) {
751
- let { type: t, next: n } = o.next[e];
752
- if (!(t.isText || t.hasRequiredAttrs()) && r.indexOf(n) == -1) {
753
- r.push(n);
754
- let e = a(n, s.concat(t));
755
- if (e) return e;
756
- }
757
- }
758
- return null;
759
- }
760
- return a(this, []);
761
- }
762
- findWrapping(e) {
763
- for (let t = 0; t < this.wrapCache.length; t += 2) if (this.wrapCache[t] == e) return this.wrapCache[t + 1];
764
- let t = this.computeWrapping(e);
765
- return this.wrapCache.push(e, t), t;
766
- }
767
- computeWrapping(e) {
768
- let t = Object.create(null), n = [{
769
- match: this,
770
- type: null,
771
- via: null
772
- }];
773
- for (; n.length;) {
774
- let r = n.shift(), i = r.match;
775
- if (i.matchType(e)) {
776
- let e = [];
777
- for (let t = r; t.type; t = t.via) e.push(t.type);
778
- return e.reverse();
779
- }
780
- for (let e = 0; e < i.next.length; e++) {
781
- let { type: a, next: o } = i.next[e];
782
- !a.isLeaf && !a.hasRequiredAttrs() && !(a.name in t) && (!r.type || o.validEnd) && (n.push({
783
- match: a.contentMatch,
784
- type: a,
785
- via: r
786
- }), t[a.name] = !0);
787
- }
788
- }
789
- return null;
790
- }
791
- get edgeCount() {
792
- return this.next.length;
793
- }
794
- edge(e) {
795
- if (e >= this.next.length) throw RangeError(`There's no ${e}th edge in this content match`);
796
- return this.next[e];
797
- }
798
- toString() {
799
- let e = [];
800
- function t(n) {
801
- e.push(n);
802
- for (let r = 0; r < n.next.length; r++) e.indexOf(n.next[r].next) == -1 && t(n.next[r].next);
803
- }
804
- return t(this), e.map((t, n) => {
805
- let r = n + (t.validEnd ? "*" : " ") + " ";
806
- for (let n = 0; n < t.next.length; n++) r += (n ? ", " : "") + t.next[n].type.name + "->" + e.indexOf(t.next[n].next);
807
- return r;
808
- }).join("\n");
809
- }
810
- };
811
- S.empty = new S(!0);
812
- var le = class {
813
- constructor(e, t) {
814
- this.string = e, this.nodeTypes = t, this.inline = null, this.pos = 0, this.tokens = e.split(/\s*(?=\b|\W|$)/), this.tokens[this.tokens.length - 1] == "" && this.tokens.pop(), this.tokens[0] == "" && this.tokens.shift();
815
- }
816
- get next() {
817
- return this.tokens[this.pos];
818
- }
819
- eat(e) {
820
- return this.next == e && (this.pos++ || !0);
821
- }
822
- err(e) {
823
- throw SyntaxError(e + " (in content expression '" + this.string + "')");
824
- }
825
- };
826
- function ue(e) {
827
- let t = [];
828
- do
829
- t.push(de(e));
830
- while (e.eat("|"));
831
- return t.length == 1 ? t[0] : {
832
- type: "choice",
833
- exprs: t
834
- };
835
- }
836
- function de(e) {
837
- let t = [];
838
- do
839
- t.push(fe(e));
840
- while (e.next && e.next != ")" && e.next != "|");
841
- return t.length == 1 ? t[0] : {
842
- type: "seq",
843
- exprs: t
844
- };
845
- }
846
- function fe(e) {
847
- let t = he(e);
848
- for (;;) if (e.eat("+")) t = {
849
- type: "plus",
850
- expr: t
851
- };
852
- else if (e.eat("*")) t = {
853
- type: "star",
854
- expr: t
855
- };
856
- else if (e.eat("?")) t = {
857
- type: "opt",
858
- expr: t
859
- };
860
- else if (e.eat("{")) t = pe(e, t);
861
- else break;
862
- return t;
863
- }
864
- function C(e) {
865
- /\D/.test(e.next) && e.err("Expected number, got '" + e.next + "'");
866
- let t = Number(e.next);
867
- return e.pos++, t;
868
- }
869
- function pe(e, t) {
870
- let n = C(e), r = n;
871
- return e.eat(",") && (r = e.next == "}" ? -1 : C(e)), e.eat("}") || e.err("Unclosed braced range"), {
872
- type: "range",
873
- min: n,
874
- max: r,
875
- expr: t
876
- };
877
- }
878
- function me(e, t) {
879
- let n = e.nodeTypes, r = n[t];
880
- if (r) return [r];
881
- let i = [];
882
- for (let e in n) {
883
- let r = n[e];
884
- r.isInGroup(t) && i.push(r);
885
- }
886
- return i.length == 0 && e.err("No node type or group '" + t + "' found"), i;
887
- }
888
- function he(e) {
889
- if (e.eat("(")) {
890
- let t = ue(e);
891
- return e.eat(")") || e.err("Missing closing paren"), t;
892
- } else if (/\W/.test(e.next)) e.err("Unexpected token '" + e.next + "'");
893
- else {
894
- let t = me(e, e.next).map((t) => (e.inline == null ? e.inline = t.isInline : e.inline != t.isInline && e.err("Mixing inline and block content"), {
895
- type: "name",
896
- value: t
897
- }));
898
- return e.pos++, t.length == 1 ? t[0] : {
899
- type: "choice",
900
- exprs: t
901
- };
902
- }
903
- }
904
- function ge(e) {
905
- let t = [[]];
906
- return i(a(e, 0), n()), t;
907
- function n() {
908
- return t.push([]) - 1;
909
- }
910
- function r(e, n, r) {
911
- let i = {
912
- term: r,
913
- to: n
914
- };
915
- return t[e].push(i), i;
916
- }
917
- function i(e, t) {
918
- e.forEach((e) => e.to = t);
919
- }
920
- function a(e, t) {
921
- if (e.type == "choice") return e.exprs.reduce((e, n) => e.concat(a(n, t)), []);
922
- if (e.type == "seq") for (let r = 0;; r++) {
923
- let o = a(e.exprs[r], t);
924
- if (r == e.exprs.length - 1) return o;
925
- i(o, t = n());
926
- }
927
- else if (e.type == "star") {
928
- let o = n();
929
- return r(t, o), i(a(e.expr, o), o), [r(o)];
930
- } else if (e.type == "plus") {
931
- let o = n();
932
- return i(a(e.expr, t), o), i(a(e.expr, o), o), [r(o)];
933
- } else if (e.type == "opt") return [r(t)].concat(a(e.expr, t));
934
- else if (e.type == "range") {
935
- let o = t;
936
- for (let t = 0; t < e.min; t++) {
937
- let t = n();
938
- i(a(e.expr, o), t), o = t;
939
- }
940
- if (e.max == -1) i(a(e.expr, o), o);
941
- else for (let t = e.min; t < e.max; t++) {
942
- let t = n();
943
- r(o, t), i(a(e.expr, o), t), o = t;
944
- }
945
- return [r(o)];
946
- } else if (e.type == "name") return [r(t, void 0, e.value)];
947
- else throw Error("Unknown expr type");
948
- }
949
- }
950
- function w(e, t) {
951
- return t - e;
952
- }
953
- function T(e, t) {
954
- let n = [];
955
- return r(t), n.sort(w);
956
- function r(t) {
957
- let i = e[t];
958
- if (i.length == 1 && !i[0].term) return r(i[0].to);
959
- n.push(t);
960
- for (let e = 0; e < i.length; e++) {
961
- let { term: t, to: a } = i[e];
962
- !t && n.indexOf(a) == -1 && r(a);
963
- }
964
- }
965
- }
966
- function _e(e) {
967
- let t = Object.create(null);
968
- return n(T(e, 0));
969
- function n(r) {
970
- let i = [];
971
- r.forEach((t) => {
972
- e[t].forEach(({ term: t, to: n }) => {
973
- if (!t) return;
974
- let r;
975
- for (let e = 0; e < i.length; e++) i[e][0] == t && (r = i[e][1]);
976
- T(e, n).forEach((e) => {
977
- r || i.push([t, r = []]), r.indexOf(e) == -1 && r.push(e);
978
- });
979
- });
980
- });
981
- let a = t[r.join(",")] = new S(r.indexOf(e.length - 1) > -1);
982
- for (let e = 0; e < i.length; e++) {
983
- let r = i[e][1].sort(w);
984
- a.next.push({
985
- type: i[e][0],
986
- next: t[r.join(",")] || n(r)
987
- });
988
- }
989
- return a;
990
- }
991
- }
992
- function ve(e, t) {
993
- for (let n = 0, r = [e]; n < r.length; n++) {
994
- let e = r[n], i = !e.validEnd, a = [];
995
- for (let t = 0; t < e.next.length; t++) {
996
- let { type: n, next: o } = e.next[t];
997
- a.push(n.name), i && !(n.isText || n.hasRequiredAttrs()) && (i = !1), r.indexOf(o) == -1 && r.push(o);
998
- }
999
- i && t.err("Only non-generatable nodes (" + a.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
1000
- }
1001
- }
1002
- var E = 65535, D = 2 ** 16;
1003
- function ye(e, t) {
1004
- return e + t * D;
1005
- }
1006
- function O(e) {
1007
- return e & E;
1008
- }
1009
- function be(e) {
1010
- return (e - (e & E)) / D;
1011
- }
1012
- var xe = 1, Se = 2, k = 4, A = 8, j = class {
1013
- constructor(e, t, n) {
1014
- this.pos = e, this.delInfo = t, this.recover = n;
1015
- }
1016
- get deleted() {
1017
- return (this.delInfo & A) > 0;
1018
- }
1019
- get deletedBefore() {
1020
- return (this.delInfo & 5) > 0;
1021
- }
1022
- get deletedAfter() {
1023
- return (this.delInfo & 6) > 0;
1024
- }
1025
- get deletedAcross() {
1026
- return (this.delInfo & k) > 0;
1027
- }
1028
- }, M = class e {
1029
- constructor(t, n = !1) {
1030
- if (this.ranges = t, this.inverted = n, !t.length && e.empty) return e.empty;
1031
- }
1032
- recover(e) {
1033
- let t = 0, n = O(e);
1034
- if (!this.inverted) for (let e = 0; e < n; e++) t += this.ranges[e * 3 + 2] - this.ranges[e * 3 + 1];
1035
- return this.ranges[n * 3] + t + be(e);
1036
- }
1037
- mapResult(e, t = 1) {
1038
- return this._map(e, t, !1);
1039
- }
1040
- map(e, t = 1) {
1041
- return this._map(e, t, !0);
1042
- }
1043
- _map(e, t, n) {
1044
- let r = 0, i = this.inverted ? 2 : 1, a = this.inverted ? 1 : 2;
1045
- for (let o = 0; o < this.ranges.length; o += 3) {
1046
- let s = this.ranges[o] - (this.inverted ? r : 0);
1047
- if (s > e) break;
1048
- let c = this.ranges[o + i], l = this.ranges[o + a], u = s + c;
1049
- if (e <= u) {
1050
- let i = c ? e == s ? -1 : e == u ? 1 : t : t, a = s + r + (i < 0 ? 0 : l);
1051
- if (n) return a;
1052
- let d = e == (t < 0 ? s : u) ? null : ye(o / 3, e - s), f = e == s ? Se : e == u ? xe : k;
1053
- return (t < 0 ? e != s : e != u) && (f |= A), new j(a, f, d);
1054
- }
1055
- r += l - c;
1056
- }
1057
- return n ? e + r : new j(e + r, 0, null);
1058
- }
1059
- touches(e, t) {
1060
- let n = 0, r = O(t), i = this.inverted ? 2 : 1, a = this.inverted ? 1 : 2;
1061
- for (let t = 0; t < this.ranges.length; t += 3) {
1062
- let o = this.ranges[t] - (this.inverted ? n : 0);
1063
- if (o > e) break;
1064
- let s = this.ranges[t + i];
1065
- if (e <= o + s && t == r * 3) return !0;
1066
- n += this.ranges[t + a] - s;
1067
- }
1068
- return !1;
1069
- }
1070
- forEach(e) {
1071
- let t = this.inverted ? 2 : 1, n = this.inverted ? 1 : 2;
1072
- for (let r = 0, i = 0; r < this.ranges.length; r += 3) {
1073
- let a = this.ranges[r], o = a - (this.inverted ? i : 0), s = a + (this.inverted ? 0 : i), c = this.ranges[r + t], l = this.ranges[r + n];
1074
- e(o, o + c, s, s + l), i += l - c;
1075
- }
1076
- }
1077
- invert() {
1078
- return new e(this.ranges, !this.inverted);
1079
- }
1080
- toString() {
1081
- return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
1082
- }
1083
- static offset(t) {
1084
- return t == 0 ? e.empty : new e(t < 0 ? [
1085
- 0,
1086
- -t,
1087
- 0
1088
- ] : [
1089
- 0,
1090
- 0,
1091
- t
1092
- ]);
1093
- }
1094
- };
1095
- M.empty = new M([]);
1096
- var N = Object.create(null), P = class {
1097
- getMap() {
1098
- return M.empty;
1099
- }
1100
- merge(e) {
1101
- return null;
1102
- }
1103
- static fromJSON(e, t) {
1104
- if (!t || !t.stepType) throw RangeError("Invalid input for Step.fromJSON");
1105
- let n = N[t.stepType];
1106
- if (!n) throw RangeError(`No step type ${t.stepType} defined`);
1107
- return n.fromJSON(e, t);
1108
- }
1109
- static jsonID(e, t) {
1110
- if (e in N) throw RangeError("Duplicate use of step JSON ID " + e);
1111
- return N[e] = t, t.prototype.jsonID = e, t;
1112
- }
1113
- }, F = class e {
1114
- constructor(e, t) {
1115
- this.doc = e, this.failed = t;
1116
- }
1117
- static ok(t) {
1118
- return new e(t, null);
1119
- }
1120
- static fail(t) {
1121
- return new e(null, t);
1122
- }
1123
- static fromReplace(t, n, r, i) {
1124
- try {
1125
- return e.ok(t.replace(n, r, i));
1126
- } catch (t) {
1127
- if (t instanceof l) return e.fail(t.message);
1128
- throw t;
1129
- }
1130
- }
1131
- };
1132
- function I(e, t, n) {
1133
- let r = [];
1134
- for (let i = 0; i < e.childCount; i++) {
1135
- let a = e.child(i);
1136
- a.content.size && (a = a.copy(I(a.content, t, a))), a.isInline && (a = t(a, n, i)), r.push(a);
1137
- }
1138
- return i.fromArray(r);
1139
- }
1140
- var L = class e extends P {
1141
- constructor(e, t, n) {
1142
- super(), this.from = e, this.to = t, this.mark = n;
1143
- }
1144
- apply(e) {
1145
- let t = e.slice(this.from, this.to), n = e.resolve(this.from), r = n.node(n.sharedDepth(this.to)), i = new u(I(t.content, (e, t) => !e.isAtom || !t.type.allowsMarkType(this.mark.type) ? e : e.mark(this.mark.addToSet(e.marks)), r), t.openStart, t.openEnd);
1146
- return F.fromReplace(e, this.from, this.to, i);
1147
- }
1148
- invert() {
1149
- return new R(this.from, this.to, this.mark);
1150
- }
1151
- map(t) {
1152
- let n = t.mapResult(this.from, 1), r = t.mapResult(this.to, -1);
1153
- return n.deleted && r.deleted || n.pos >= r.pos ? null : new e(n.pos, r.pos, this.mark);
1154
- }
1155
- merge(t) {
1156
- return t instanceof e && t.mark.eq(this.mark) && this.from <= t.to && this.to >= t.from ? new e(Math.min(this.from, t.from), Math.max(this.to, t.to), this.mark) : null;
1157
- }
1158
- toJSON() {
1159
- return {
1160
- stepType: "addMark",
1161
- mark: this.mark.toJSON(),
1162
- from: this.from,
1163
- to: this.to
1164
- };
1165
- }
1166
- static fromJSON(t, n) {
1167
- if (typeof n.from != "number" || typeof n.to != "number") throw RangeError("Invalid input for AddMarkStep.fromJSON");
1168
- return new e(n.from, n.to, t.markFromJSON(n.mark));
1169
- }
1170
- };
1171
- P.jsonID("addMark", L);
1172
- var R = class e extends P {
1173
- constructor(e, t, n) {
1174
- super(), this.from = e, this.to = t, this.mark = n;
1175
- }
1176
- apply(e) {
1177
- let t = e.slice(this.from, this.to), n = new u(I(t.content, (e) => e.mark(this.mark.removeFromSet(e.marks)), e), t.openStart, t.openEnd);
1178
- return F.fromReplace(e, this.from, this.to, n);
1179
- }
1180
- invert() {
1181
- return new L(this.from, this.to, this.mark);
1182
- }
1183
- map(t) {
1184
- let n = t.mapResult(this.from, 1), r = t.mapResult(this.to, -1);
1185
- return n.deleted && r.deleted || n.pos >= r.pos ? null : new e(n.pos, r.pos, this.mark);
1186
- }
1187
- merge(t) {
1188
- return t instanceof e && t.mark.eq(this.mark) && this.from <= t.to && this.to >= t.from ? new e(Math.min(this.from, t.from), Math.max(this.to, t.to), this.mark) : null;
1189
- }
1190
- toJSON() {
1191
- return {
1192
- stepType: "removeMark",
1193
- mark: this.mark.toJSON(),
1194
- from: this.from,
1195
- to: this.to
1196
- };
1197
- }
1198
- static fromJSON(t, n) {
1199
- if (typeof n.from != "number" || typeof n.to != "number") throw RangeError("Invalid input for RemoveMarkStep.fromJSON");
1200
- return new e(n.from, n.to, t.markFromJSON(n.mark));
1201
- }
1202
- };
1203
- P.jsonID("removeMark", R);
1204
- var z = class e extends P {
1205
- constructor(e, t) {
1206
- super(), this.pos = e, this.mark = t;
1207
- }
1208
- apply(e) {
1209
- let t = e.nodeAt(this.pos);
1210
- if (!t) return F.fail("No node at mark step's position");
1211
- let n = t.type.create(t.attrs, null, this.mark.addToSet(t.marks));
1212
- return F.fromReplace(e, this.pos, this.pos + 1, new u(i.from(n), 0, +!t.isLeaf));
1213
- }
1214
- invert(t) {
1215
- let n = t.nodeAt(this.pos);
1216
- if (n) {
1217
- let t = this.mark.addToSet(n.marks);
1218
- if (t.length == n.marks.length) {
1219
- for (let r = 0; r < n.marks.length; r++) if (!n.marks[r].isInSet(t)) return new e(this.pos, n.marks[r]);
1220
- return new e(this.pos, this.mark);
1221
- }
1222
- }
1223
- return new B(this.pos, this.mark);
1224
- }
1225
- map(t) {
1226
- let n = t.mapResult(this.pos, 1);
1227
- return n.deletedAfter ? null : new e(n.pos, this.mark);
1228
- }
1229
- toJSON() {
1230
- return {
1231
- stepType: "addNodeMark",
1232
- pos: this.pos,
1233
- mark: this.mark.toJSON()
1234
- };
1235
- }
1236
- static fromJSON(t, n) {
1237
- if (typeof n.pos != "number") throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");
1238
- return new e(n.pos, t.markFromJSON(n.mark));
1239
- }
1240
- };
1241
- P.jsonID("addNodeMark", z);
1242
- var B = class e extends P {
1243
- constructor(e, t) {
1244
- super(), this.pos = e, this.mark = t;
1245
- }
1246
- apply(e) {
1247
- let t = e.nodeAt(this.pos);
1248
- if (!t) return F.fail("No node at mark step's position");
1249
- let n = t.type.create(t.attrs, null, this.mark.removeFromSet(t.marks));
1250
- return F.fromReplace(e, this.pos, this.pos + 1, new u(i.from(n), 0, +!t.isLeaf));
1251
- }
1252
- invert(e) {
1253
- let t = e.nodeAt(this.pos);
1254
- return !t || !this.mark.isInSet(t.marks) ? this : new z(this.pos, this.mark);
1255
- }
1256
- map(t) {
1257
- let n = t.mapResult(this.pos, 1);
1258
- return n.deletedAfter ? null : new e(n.pos, this.mark);
1259
- }
1260
- toJSON() {
1261
- return {
1262
- stepType: "removeNodeMark",
1263
- pos: this.pos,
1264
- mark: this.mark.toJSON()
1265
- };
1266
- }
1267
- static fromJSON(t, n) {
1268
- if (typeof n.pos != "number") throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
1269
- return new e(n.pos, t.markFromJSON(n.mark));
1270
- }
1271
- };
1272
- P.jsonID("removeNodeMark", B);
1273
- var V = class e extends P {
1274
- constructor(e, t, n, r = !1) {
1275
- super(), this.from = e, this.to = t, this.slice = n, this.structure = r;
1276
- }
1277
- apply(e) {
1278
- return this.structure && U(e, this.from, this.to) ? F.fail("Structure replace would overwrite content") : F.fromReplace(e, this.from, this.to, this.slice);
1279
- }
1280
- getMap() {
1281
- return new M([
1282
- this.from,
1283
- this.to - this.from,
1284
- this.slice.size
1285
- ]);
1286
- }
1287
- invert(t) {
1288
- return new e(this.from, this.from + this.slice.size, t.slice(this.from, this.to));
1289
- }
1290
- map(t) {
1291
- let n = t.mapResult(this.to, -1), r = this.from == this.to && e.MAP_BIAS < 0 ? n : t.mapResult(this.from, 1);
1292
- return r.deletedAcross && n.deletedAcross ? null : new e(r.pos, Math.max(r.pos, n.pos), this.slice, this.structure);
1293
- }
1294
- merge(t) {
1295
- if (!(t instanceof e) || t.structure || this.structure) return null;
1296
- if (this.from + this.slice.size == t.from && !this.slice.openEnd && !t.slice.openStart) {
1297
- let n = this.slice.size + t.slice.size == 0 ? u.empty : new u(this.slice.content.append(t.slice.content), this.slice.openStart, t.slice.openEnd);
1298
- return new e(this.from, this.to + (t.to - t.from), n, this.structure);
1299
- } else if (t.to == this.from && !this.slice.openStart && !t.slice.openEnd) {
1300
- let n = this.slice.size + t.slice.size == 0 ? u.empty : new u(t.slice.content.append(this.slice.content), t.slice.openStart, this.slice.openEnd);
1301
- return new e(t.from, this.to, n, this.structure);
1302
- } else return null;
1303
- }
1304
- toJSON() {
1305
- let e = {
1306
- stepType: "replace",
1307
- from: this.from,
1308
- to: this.to
1309
- };
1310
- return this.slice.size && (e.slice = this.slice.toJSON()), this.structure && (e.structure = !0), e;
1311
- }
1312
- static fromJSON(t, n) {
1313
- if (typeof n.from != "number" || typeof n.to != "number") throw RangeError("Invalid input for ReplaceStep.fromJSON");
1314
- return new e(n.from, n.to, u.fromJSON(t, n.slice), !!n.structure);
1315
- }
1316
- };
1317
- V.MAP_BIAS = 1, P.jsonID("replace", V);
1318
- var H = class e extends P {
1319
- constructor(e, t, n, r, i, a, o = !1) {
1320
- super(), this.from = e, this.to = t, this.gapFrom = n, this.gapTo = r, this.slice = i, this.insert = a, this.structure = o;
1321
- }
1322
- apply(e) {
1323
- if (this.structure && (U(e, this.from, this.gapFrom) || U(e, this.gapTo, this.to))) return F.fail("Structure gap-replace would overwrite content");
1324
- let t = e.slice(this.gapFrom, this.gapTo);
1325
- if (t.openStart || t.openEnd) return F.fail("Gap is not a flat range");
1326
- let n = this.slice.insertAt(this.insert, t.content);
1327
- return n ? F.fromReplace(e, this.from, this.to, n) : F.fail("Content does not fit in gap");
1328
- }
1329
- getMap() {
1330
- return new M([
1331
- this.from,
1332
- this.gapFrom - this.from,
1333
- this.insert,
1334
- this.gapTo,
1335
- this.to - this.gapTo,
1336
- this.slice.size - this.insert
1337
- ]);
1338
- }
1339
- invert(t) {
1340
- let n = this.gapTo - this.gapFrom;
1341
- return new e(this.from, this.from + this.slice.size + n, this.from + this.insert, this.from + this.insert + n, t.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
1342
- }
1343
- map(t) {
1344
- let n = t.mapResult(this.from, 1), r = t.mapResult(this.to, -1), i = this.from == this.gapFrom ? n.pos : t.map(this.gapFrom, -1), a = this.to == this.gapTo ? r.pos : t.map(this.gapTo, 1);
1345
- return n.deletedAcross && r.deletedAcross || i < n.pos || a > r.pos ? null : new e(n.pos, r.pos, i, a, this.slice, this.insert, this.structure);
1346
- }
1347
- toJSON() {
1348
- let e = {
1349
- stepType: "replaceAround",
1350
- from: this.from,
1351
- to: this.to,
1352
- gapFrom: this.gapFrom,
1353
- gapTo: this.gapTo,
1354
- insert: this.insert
1355
- };
1356
- return this.slice.size && (e.slice = this.slice.toJSON()), this.structure && (e.structure = !0), e;
1357
- }
1358
- static fromJSON(t, n) {
1359
- if (typeof n.from != "number" || typeof n.to != "number" || typeof n.gapFrom != "number" || typeof n.gapTo != "number" || typeof n.insert != "number") throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");
1360
- return new e(n.from, n.to, n.gapFrom, n.gapTo, u.fromJSON(t, n.slice), n.insert, !!n.structure);
1361
- }
1362
- };
1363
- P.jsonID("replaceAround", H);
1364
- function U(e, t, n) {
1365
- let r = e.resolve(t), i = n - t, a = r.depth;
1366
- for (; i > 0 && a > 0 && r.indexAfter(a) == r.node(a).childCount;) a--, i--;
1367
- if (i > 0) {
1368
- let e = r.node(a).maybeChild(r.indexAfter(a));
1369
- for (; i > 0;) {
1370
- if (!e || e.isLeaf) return !0;
1371
- e = e.firstChild, i--;
1372
- }
1373
- }
1374
- return !1;
1375
- }
1376
- var Ce = class e extends P {
1377
- constructor(e, t, n) {
1378
- super(), this.pos = e, this.attr = t, this.value = n;
1379
- }
1380
- apply(e) {
1381
- let t = e.nodeAt(this.pos);
1382
- if (!t) return F.fail("No node at attribute step's position");
1383
- let n = Object.create(null);
1384
- for (let e in t.attrs) n[e] = t.attrs[e];
1385
- n[this.attr] = this.value;
1386
- let r = t.type.create(n, null, t.marks);
1387
- return F.fromReplace(e, this.pos, this.pos + 1, new u(i.from(r), 0, +!t.isLeaf));
1388
- }
1389
- getMap() {
1390
- return M.empty;
1391
- }
1392
- invert(t) {
1393
- return new e(this.pos, this.attr, t.nodeAt(this.pos).attrs[this.attr]);
1394
- }
1395
- map(t) {
1396
- let n = t.mapResult(this.pos, 1);
1397
- return n.deletedAfter ? null : new e(n.pos, this.attr, this.value);
1398
- }
1399
- toJSON() {
1400
- return {
1401
- stepType: "attr",
1402
- pos: this.pos,
1403
- attr: this.attr,
1404
- value: this.value
1405
- };
1406
- }
1407
- static fromJSON(t, n) {
1408
- if (typeof n.pos != "number" || typeof n.attr != "string") throw RangeError("Invalid input for AttrStep.fromJSON");
1409
- return new e(n.pos, n.attr, n.value);
1410
- }
1411
- };
1412
- P.jsonID("attr", Ce);
1413
- var we = class e extends P {
1414
- constructor(e, t) {
1415
- super(), this.attr = e, this.value = t;
1416
- }
1417
- apply(e) {
1418
- let t = Object.create(null);
1419
- for (let n in e.attrs) t[n] = e.attrs[n];
1420
- t[this.attr] = this.value;
1421
- let n = e.type.create(t, e.content, e.marks);
1422
- return F.ok(n);
1423
- }
1424
- getMap() {
1425
- return M.empty;
1426
- }
1427
- invert(t) {
1428
- return new e(this.attr, t.attrs[this.attr]);
1429
- }
1430
- map(e) {
1431
- return this;
1432
- }
1433
- toJSON() {
1434
- return {
1435
- stepType: "docAttr",
1436
- attr: this.attr,
1437
- value: this.value
1438
- };
1439
- }
1440
- static fromJSON(t, n) {
1441
- if (typeof n.attr != "string") throw RangeError("Invalid input for DocAttrStep.fromJSON");
1442
- return new e(n.attr, n.value);
1443
- }
1444
- };
1445
- P.jsonID("docAttr", we);
1446
- var W = class extends Error {};
1447
- W = function e(t) {
1448
- let n = Error.call(this, t);
1449
- return n.__proto__ = e.prototype, n;
1450
- }, W.prototype = Object.create(Error.prototype), W.prototype.constructor = W, W.prototype.name = "TransformError";
1451
- var G = Object.create(null), K = class {
1452
- constructor(e, t, n) {
1453
- this.$anchor = e, this.$head = t, this.ranges = n || [new Te(e.min(t), e.max(t))];
1454
- }
1455
- get anchor() {
1456
- return this.$anchor.pos;
1457
- }
1458
- get head() {
1459
- return this.$head.pos;
1460
- }
1461
- get from() {
1462
- return this.$from.pos;
1463
- }
1464
- get to() {
1465
- return this.$to.pos;
1466
- }
1467
- get $from() {
1468
- return this.ranges[0].$from;
1469
- }
1470
- get $to() {
1471
- return this.ranges[0].$to;
1472
- }
1473
- get empty() {
1474
- let e = this.ranges;
1475
- for (let t = 0; t < e.length; t++) if (e[t].$from.pos != e[t].$to.pos) return !1;
1476
- return !0;
1477
- }
1478
- content() {
1479
- return this.$from.doc.slice(this.from, this.to, !0);
1480
- }
1481
- replace(e, t = u.empty) {
1482
- let n = t.content.lastChild, r = null;
1483
- for (let e = 0; e < t.openEnd; e++) r = n, n = n.lastChild;
1484
- let i = e.steps.length, a = this.ranges;
1485
- for (let o = 0; o < a.length; o++) {
1486
- let { $from: s, $to: c } = a[o], l = e.mapping.slice(i);
1487
- e.replaceRange(l.map(s.pos), l.map(c.pos), o ? u.empty : t), o == 0 && Ae(e, i, (n ? n.isInline : r && r.isTextblock) ? -1 : 1);
1488
- }
1489
- }
1490
- replaceWith(e, t) {
1491
- let n = e.steps.length, r = this.ranges;
1492
- for (let i = 0; i < r.length; i++) {
1493
- let { $from: a, $to: o } = r[i], s = e.mapping.slice(n), c = s.map(a.pos), l = s.map(o.pos);
1494
- i ? e.deleteRange(c, l) : (e.replaceRangeWith(c, l, t), Ae(e, n, t.isInline ? -1 : 1));
1495
- }
1496
- }
1497
- static findFrom(e, t, n = !1) {
1498
- let r = e.parent.inlineContent ? new J(e) : Z(e.node(0), e.parent, e.pos, e.index(), t, n);
1499
- if (r) return r;
1500
- for (let r = e.depth - 1; r >= 0; r--) {
1501
- let i = t < 0 ? Z(e.node(0), e.node(r), e.before(r + 1), e.index(r), t, n) : Z(e.node(0), e.node(r), e.after(r + 1), e.index(r) + 1, t, n);
1502
- if (i) return i;
1503
- }
1504
- return null;
1505
- }
1506
- static near(e, t = 1) {
1507
- return this.findFrom(e, t) || this.findFrom(e, -t) || new X(e.node(0));
1508
- }
1509
- static atStart(e) {
1510
- return Z(e, e, 0, 0, 1) || new X(e);
1511
- }
1512
- static atEnd(e) {
1513
- return Z(e, e, e.content.size, e.childCount, -1) || new X(e);
1514
- }
1515
- static fromJSON(e, t) {
1516
- if (!t || !t.type) throw RangeError("Invalid input for Selection.fromJSON");
1517
- let n = G[t.type];
1518
- if (!n) throw RangeError(`No selection type ${t.type} defined`);
1519
- return n.fromJSON(e, t);
1520
- }
1521
- static jsonID(e, t) {
1522
- if (e in G) throw RangeError("Duplicate use of selection JSON ID " + e);
1523
- return G[e] = t, t.prototype.jsonID = e, t;
1524
- }
1525
- getBookmark() {
1526
- return J.between(this.$anchor, this.$head).getBookmark();
1527
- }
1528
- };
1529
- K.prototype.visible = !0;
1530
- var Te = class {
1531
- constructor(e, t) {
1532
- this.$from = e, this.$to = t;
1533
- }
1534
- }, q = !1;
1535
- function Ee(e) {
1536
- !q && !e.parent.inlineContent && (q = !0, console.warn("TextSelection endpoint not pointing into a node with inline content (" + e.parent.type.name + ")"));
1537
- }
1538
- var J = class e extends K {
1539
- constructor(e, t = e) {
1540
- Ee(e), Ee(t), super(e, t);
1541
- }
1542
- get $cursor() {
1543
- return this.$anchor.pos == this.$head.pos ? this.$head : null;
1544
- }
1545
- map(t, n) {
1546
- let r = t.resolve(n.map(this.head));
1547
- if (!r.parent.inlineContent) return K.near(r);
1548
- let i = t.resolve(n.map(this.anchor));
1549
- return new e(i.parent.inlineContent ? i : r, r);
1550
- }
1551
- replace(e, t = u.empty) {
1552
- if (super.replace(e, t), t == u.empty) {
1553
- let t = this.$from.marksAcross(this.$to);
1554
- t && e.ensureMarks(t);
1555
- }
1556
- }
1557
- eq(t) {
1558
- return t instanceof e && t.anchor == this.anchor && t.head == this.head;
1559
- }
1560
- getBookmark() {
1561
- return new De(this.anchor, this.head);
1562
- }
1563
- toJSON() {
1564
- return {
1565
- type: "text",
1566
- anchor: this.anchor,
1567
- head: this.head
1568
- };
1569
- }
1570
- static fromJSON(t, n) {
1571
- if (typeof n.anchor != "number" || typeof n.head != "number") throw RangeError("Invalid input for TextSelection.fromJSON");
1572
- return new e(t.resolve(n.anchor), t.resolve(n.head));
1573
- }
1574
- static create(e, t, n = t) {
1575
- let r = e.resolve(t);
1576
- return new this(r, n == t ? r : e.resolve(n));
1577
- }
1578
- static between(t, n, r) {
1579
- let i = t.pos - n.pos;
1580
- if ((!r || i) && (r = i >= 0 ? 1 : -1), !n.parent.inlineContent) {
1581
- let e = K.findFrom(n, r, !0) || K.findFrom(n, -r, !0);
1582
- if (e) n = e.$head;
1583
- else return K.near(n, r);
1584
- }
1585
- return t.parent.inlineContent || (i == 0 ? t = n : (t = (K.findFrom(t, -r, !0) || K.findFrom(t, r, !0)).$anchor, t.pos < n.pos != i < 0 && (t = n))), new e(t, n);
1586
- }
1587
- };
1588
- K.jsonID("text", J);
1589
- var De = class e {
1590
- constructor(e, t) {
1591
- this.anchor = e, this.head = t;
1592
- }
1593
- map(t) {
1594
- return new e(t.map(this.anchor), t.map(this.head));
1595
- }
1596
- resolve(e) {
1597
- return J.between(e.resolve(this.anchor), e.resolve(this.head));
1598
- }
1599
- }, Y = class e extends K {
1600
- constructor(e) {
1601
- let t = e.nodeAfter, n = e.node(0).resolve(e.pos + t.nodeSize);
1602
- super(e, n), this.node = t;
1603
- }
1604
- map(t, n) {
1605
- let { deleted: r, pos: i } = n.mapResult(this.anchor), a = t.resolve(i);
1606
- return r ? K.near(a) : new e(a);
1607
- }
1608
- content() {
1609
- return new u(i.from(this.node), 0, 0);
1610
- }
1611
- eq(t) {
1612
- return t instanceof e && t.anchor == this.anchor;
1613
- }
1614
- toJSON() {
1615
- return {
1616
- type: "node",
1617
- anchor: this.anchor
1618
- };
1619
- }
1620
- getBookmark() {
1621
- return new Oe(this.anchor);
1622
- }
1623
- static fromJSON(t, n) {
1624
- if (typeof n.anchor != "number") throw RangeError("Invalid input for NodeSelection.fromJSON");
1625
- return new e(t.resolve(n.anchor));
1626
- }
1627
- static create(t, n) {
1628
- return new e(t.resolve(n));
1629
- }
1630
- static isSelectable(e) {
1631
- return !e.isText && e.type.spec.selectable !== !1;
1632
- }
1633
- };
1634
- Y.prototype.visible = !1, K.jsonID("node", Y);
1635
- var Oe = class e {
1636
- constructor(e) {
1637
- this.anchor = e;
1638
- }
1639
- map(t) {
1640
- let { deleted: n, pos: r } = t.mapResult(this.anchor);
1641
- return n ? new De(r, r) : new e(r);
1642
- }
1643
- resolve(e) {
1644
- let t = e.resolve(this.anchor), n = t.nodeAfter;
1645
- return n && Y.isSelectable(n) ? new Y(t) : K.near(t);
1646
- }
1647
- }, X = class e extends K {
1648
- constructor(e) {
1649
- super(e.resolve(0), e.resolve(e.content.size));
1650
- }
1651
- replace(e, t = u.empty) {
1652
- if (t == u.empty) {
1653
- e.delete(0, e.doc.content.size);
1654
- let t = K.atStart(e.doc);
1655
- t.eq(e.selection) || e.setSelection(t);
1656
- } else super.replace(e, t);
1657
- }
1658
- toJSON() {
1659
- return { type: "all" };
1660
- }
1661
- static fromJSON(t) {
1662
- return new e(t);
1663
- }
1664
- map(t) {
1665
- return new e(t);
1666
- }
1667
- eq(t) {
1668
- return t instanceof e;
1669
- }
1670
- getBookmark() {
1671
- return ke;
1672
- }
1673
- };
1674
- K.jsonID("all", X);
1675
- var ke = {
1676
- map() {
1677
- return this;
1678
- },
1679
- resolve(e) {
1680
- return new X(e);
1681
- }
1682
- };
1683
- function Z(e, t, n, r, i, a = !1) {
1684
- if (t.inlineContent) return J.create(e, n);
1685
- for (let o = r - (i > 0 ? 0 : 1); i > 0 ? o < t.childCount : o >= 0; o += i) {
1686
- let r = t.child(o);
1687
- if (!r.isAtom) {
1688
- let t = Z(e, r, n + i, i < 0 ? r.childCount : 0, i, a);
1689
- if (t) return t;
1690
- } else if (!a && Y.isSelectable(r)) return Y.create(e, n - (i < 0 ? r.nodeSize : 0));
1691
- n += r.nodeSize * i;
1692
- }
1693
- return null;
1694
- }
1695
- function Ae(e, t, n) {
1696
- let r = e.steps.length - 1;
1697
- if (r < t) return;
1698
- let i = e.steps[r];
1699
- if (!(i instanceof V || i instanceof H)) return;
1700
- let a = e.mapping.maps[r], o;
1701
- a.forEach((e, t, n, r) => {
1702
- o ??= r;
1703
- }), e.setSelection(K.near(e.doc.resolve(o), n));
1704
- }
1705
- function je(e, t) {
1706
- return !t || !e ? e : e.bind(t);
1707
- }
1708
- var Q = class {
1709
- constructor(e, t, n) {
1710
- this.name = e, this.init = je(t.init, n), this.apply = je(t.apply, n);
1711
- }
1712
- };
1713
- new Q("doc", {
1714
- init(e) {
1715
- return e.doc || e.schema.topNodeType.createAndFill();
1716
- },
1717
- apply(e) {
1718
- return e.doc;
1719
- }
1720
- }), new Q("selection", {
1721
- init(e, t) {
1722
- return e.selection || K.atStart(t.doc);
1723
- },
1724
- apply(e) {
1725
- return e.selection;
1726
- }
1727
- }), new Q("storedMarks", {
1728
- init(e) {
1729
- return e.storedMarks || null;
1730
- },
1731
- apply(e, t, n, r) {
1732
- return r.selection.$cursor ? e.storedMarks : null;
1733
- }
1734
- }), new Q("scrollToSelection", {
1735
- init() {
1736
- return 0;
1737
- },
1738
- apply(e, t) {
1739
- return e.scrolledIntoView ? t + 1 : t;
1740
- }
1741
- });
1742
- var $ = Object.create(null);
1743
- function Me(e) {
1744
- return e in $ ? e + "$" + ++$[e] : ($[e] = 0, e + "$");
1745
- }
1746
- var Ne = class {
1747
- constructor(e = "key") {
1748
- this.key = Me(e);
1749
- }
1750
- get(e) {
1751
- return e.config.pluginsByKey[this.key];
1752
- }
1753
- getState(e) {
1754
- return e[this.key];
1755
- }
1756
- };
1757
- export { Ne as t };
1
+ function findDiffStart(a,b,pos){for(let i=0;;i++){if(i==a.childCount||i==b.childCount)return a.childCount==b.childCount?null:pos;let childA=a.child(i),childB=b.child(i);if(childA==childB){pos+=childA.nodeSize;continue}if(!childA.sameMarkup(childB))return pos;if(childA.isText&&childA.text!=childB.text){let tA=childA.text,tB=childB.text,j=0;for(;tA[j]==tB[j];j++)pos++;return j&&j<tA.length&&j<tB.length&&surrogateHigh(tA.charCodeAt(j-1))&&surrogateLow(tA.charCodeAt(j))&&pos--,pos}if(childA.content.size||childB.content.size){let inner=findDiffStart(childA.content,childB.content,pos+1);if(inner!=null)return inner}pos+=childA.nodeSize}}function findDiffEnd(a,b,posA,posB){for(let iA=a.childCount,iB=b.childCount;;){if(iA==0||iB==0)return iA==iB?null:{a:posA,b:posB};let childA=a.child(--iA),childB=b.child(--iB),size=childA.nodeSize;if(childA==childB){posA-=size,posB-=size;continue}if(!childA.sameMarkup(childB))return{a:posA,b:posB};if(childA.isText&&childA.text!=childB.text){let tA=childA.text,tB=childB.text,iA=tA.length,iB=tB.length;for(;iA>0&&iB>0&&tA[iA-1]==tB[iB-1];)iA--,iB--,posA--,posB--;return iA&&iB&&iA<tA.length&&surrogateHigh(tA.charCodeAt(iA-1))&&surrogateLow(tA.charCodeAt(iA))&&(posA++,posB++),{a:posA,b:posB}}if(childA.content.size||childB.content.size){let inner=findDiffEnd(childA.content,childB.content,posA-1,posB-1);if(inner)return inner}posA-=size,posB-=size}}function surrogateLow(ch){return ch>=56320&&ch<57344}function surrogateHigh(ch){return ch>=55296&&ch<56320}var Fragment=class Fragment{constructor(content,size){if(this.content=content,this.size=size||0,size==null)for(let i=0;i<content.length;i++)this.size+=content[i].nodeSize}nodesBetween(from,to,f,nodeStart=0,parent){for(let i=0,pos=0;pos<to;i++){let child=this.content[i],end=pos+child.nodeSize;if(end>from&&f(child,nodeStart+pos,parent||null,i)!==!1&&child.content.size){let start=pos+1;child.nodesBetween(Math.max(0,from-start),Math.min(child.content.size,to-start),f,nodeStart+start)}pos=end}}descendants(f){this.nodesBetween(0,this.size,f)}textBetween(from,to,blockSeparator,leafText){let text=``,first=!0;return this.nodesBetween(from,to,(node,pos)=>{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):``:``;node.isBlock&&(node.isLeaf&&nodeText||node.isTextblock)&&blockSeparator&&(first?first=!1:text+=blockSeparator),text+=nodeText},0),text}append(other){if(!other.size)return this;if(!this.size)return other;let last=this.lastChild,first=other.firstChild,content=this.content.slice(),i=0;for(last.isText&&last.sameMarkup(first)&&(content[content.length-1]=last.withText(last.text+first.text),i=1);i<other.content.length;i++)content.push(other.content[i]);return new Fragment(content,this.size+other.size)}cut(from,to=this.size){if(from==0&&to==this.size)return this;let result=[],size=0;if(to>from)for(let i=0,pos=0;pos<to;i++){let child=this.content[i],end=pos+child.nodeSize;end>from&&((pos<from||end>to)&&(child=child.isText?child.cut(Math.max(0,from-pos),Math.min(child.text.length,to-pos)):child.cut(Math.max(0,from-pos-1),Math.min(child.content.size,to-pos-1))),result.push(child),size+=child.nodeSize),pos=end}return new Fragment(result,size)}cutByIndex(from,to){return from==to?Fragment.empty:from==0&&to==this.content.length?this:new Fragment(this.content.slice(from,to))}replaceChild(index,node){let current=this.content[index];if(current==node)return this;let copy=this.content.slice(),size=this.size+node.nodeSize-current.nodeSize;return copy[index]=node,new Fragment(copy,size)}addToStart(node){return new Fragment([node].concat(this.content),this.size+node.nodeSize)}addToEnd(node){return new Fragment(this.content.concat(node),this.size+node.nodeSize)}eq(other){if(this.content.length!=other.content.length)return!1;for(let i=0;i<this.content.length;i++)if(!this.content[i].eq(other.content[i]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(index){let found=this.content[index];if(!found)throw RangeError(`Index `+index+` out of range for `+this);return found}maybeChild(index){return this.content[index]||null}forEach(f){for(let i=0,p=0;i<this.content.length;i++){let child=this.content[i];f(child,p,i),p+=child.nodeSize}}findDiffStart(other,pos=0){return findDiffStart(this,other,pos)}findDiffEnd(other,pos=this.size,otherPos=other.size){return findDiffEnd(this,other,pos,otherPos)}findIndex(pos){if(pos==0)return retIndex(0,pos);if(pos==this.size)return retIndex(this.content.length,pos);if(pos>this.size||pos<0)throw RangeError(`Position ${pos} outside of fragment (${this})`);for(let i=0,curPos=0;;i++){let cur=this.child(i),end=curPos+cur.nodeSize;if(end>=pos)return end==pos?retIndex(i+1,end):retIndex(i,curPos);curPos=end}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(n=>n.toJSON()):null}static fromJSON(schema,value){if(!value)return Fragment.empty;if(!Array.isArray(value))throw RangeError(`Invalid input for Fragment.fromJSON`);return Fragment.fromArray(value.map(schema.nodeFromJSON))}static fromArray(array){if(!array.length)return Fragment.empty;let joined,size=0;for(let i=0;i<array.length;i++){let node=array[i];size+=node.nodeSize,i&&node.isText&&array[i-1].sameMarkup(node)?(joined||=array.slice(0,i),joined[joined.length-1]=node.withText(joined[joined.length-1].text+node.text)):joined&&joined.push(node)}return new Fragment(joined||array,size)}static from(nodes){if(!nodes)return Fragment.empty;if(nodes instanceof Fragment)return nodes;if(Array.isArray(nodes))return this.fromArray(nodes);if(nodes.attrs)return new Fragment([nodes],nodes.nodeSize);throw RangeError(`Can not convert `+nodes+` to a Fragment`+(nodes.nodesBetween?` (looks like multiple versions of prosemirror-model were loaded)`:``))}};Fragment.empty=new Fragment([],0);var found={index:0,offset:0};function retIndex(index,offset){return found.index=index,found.offset=offset,found}function compareDeep(a,b){if(a===b)return!0;if(!(a&&typeof a==`object`)||!(b&&typeof b==`object`))return!1;let array=Array.isArray(a);if(Array.isArray(b)!=array)return!1;if(array){if(a.length!=b.length)return!1;for(let i=0;i<a.length;i++)if(!compareDeep(a[i],b[i]))return!1}else{for(let p in a)if(!(p in b)||!compareDeep(a[p],b[p]))return!1;for(let p in b)if(!(p in a))return!1}return!0}var Mark=class Mark{constructor(type,attrs){this.type=type,this.attrs=attrs}addToSet(set){let copy,placed=!1;for(let i=0;i<set.length;i++){let other=set[i];if(this.eq(other))return set;if(this.type.excludes(other.type))copy||=set.slice(0,i);else if(other.type.excludes(this.type))return set;else !placed&&other.type.rank>this.type.rank&&(copy||=set.slice(0,i),copy.push(this),placed=!0),copy&&copy.push(other)}return copy||=set.slice(),placed||copy.push(this),copy}removeFromSet(set){for(let i=0;i<set.length;i++)if(this.eq(set[i]))return set.slice(0,i).concat(set.slice(i+1));return set}isInSet(set){for(let i=0;i<set.length;i++)if(this.eq(set[i]))return!0;return!1}eq(other){return this==other||this.type==other.type&&compareDeep(this.attrs,other.attrs)}toJSON(){let obj={type:this.type.name};for(let _ in this.attrs){obj.attrs=this.attrs;break}return obj}static fromJSON(schema,json){if(!json)throw RangeError(`Invalid input for Mark.fromJSON`);let type=schema.marks[json.type];if(!type)throw RangeError(`There is no mark type ${json.type} in this schema`);let mark=type.create(json.attrs);return type.checkAttrs(mark.attrs),mark}static sameSet(a,b){if(a==b)return!0;if(a.length!=b.length)return!1;for(let i=0;i<a.length;i++)if(!a[i].eq(b[i]))return!1;return!0}static setFrom(marks){if(!marks||Array.isArray(marks)&&marks.length==0)return Mark.none;if(marks instanceof Mark)return[marks];let copy=marks.slice();return copy.sort((a,b)=>a.type.rank-b.type.rank),copy}};Mark.none=[];var ReplaceError=class extends Error{},Slice=class Slice{constructor(content,openStart,openEnd){this.content=content,this.openStart=openStart,this.openEnd=openEnd}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(pos,fragment){let content=insertInto(this.content,pos+this.openStart,fragment,this.openStart+1,this.openEnd+1);return content&&new Slice(content,this.openStart,this.openEnd)}removeBetween(from,to){return new Slice(removeRange(this.content,from+this.openStart,to+this.openStart),this.openStart,this.openEnd)}eq(other){return this.content.eq(other.content)&&this.openStart==other.openStart&&this.openEnd==other.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let json={content:this.content.toJSON()};return this.openStart>0&&(json.openStart=this.openStart),this.openEnd>0&&(json.openEnd=this.openEnd),json}static fromJSON(schema,json){if(!json)return Slice.empty;let openStart=json.openStart||0,openEnd=json.openEnd||0;if(typeof openStart!=`number`||typeof openEnd!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new Slice(Fragment.fromJSON(schema,json.content),openStart,openEnd)}static maxOpen(fragment,openIsolating=!0){let openStart=0,openEnd=0;for(let n=fragment.firstChild;n&&!n.isLeaf&&(openIsolating||!n.type.spec.isolating);n=n.firstChild)openStart++;for(let n=fragment.lastChild;n&&!n.isLeaf&&(openIsolating||!n.type.spec.isolating);n=n.lastChild)openEnd++;return new Slice(fragment,openStart,openEnd)}};Slice.empty=new Slice(Fragment.empty,0,0);function removeRange(content,from,to){let{index,offset}=content.findIndex(from),child=content.maybeChild(index),{index:indexTo,offset:offsetTo}=content.findIndex(to);if(offset==from||child.isText){if(offsetTo!=to&&!content.child(indexTo).isText)throw RangeError(`Removing non-flat range`);return content.cut(0,from).append(content.cut(to))}if(index!=indexTo)throw RangeError(`Removing non-flat range`);return content.replaceChild(index,child.copy(removeRange(child.content,from-offset-1,to-offset-1)))}function insertInto(content,dist,insert,openStart,openEnd,parent){let{index,offset}=content.findIndex(dist),child=content.maybeChild(index);if(offset==dist||child.isText)return parent&&openStart<=0&&openEnd<=0&&!parent.canReplace(index,index,insert)?null:content.cut(0,dist).append(insert).append(content.cut(dist));let inner=insertInto(child.content,dist-offset-1,insert,index==0?openStart-1:0,index==content.childCount-1?openEnd-1:0,child);return inner&&content.replaceChild(index,child.copy(inner))}function replace($from,$to,slice){if(slice.openStart>$from.depth)throw new ReplaceError(`Inserted content deeper than insertion position`);if($from.depth-slice.openStart!=$to.depth-slice.openEnd)throw new ReplaceError(`Inconsistent open depths`);return replaceOuter($from,$to,slice,0)}function replaceOuter($from,$to,slice,depth){let index=$from.index(depth),node=$from.node(depth);if(index==$to.index(depth)&&depth<$from.depth-slice.openStart){let inner=replaceOuter($from,$to,slice,depth+1);return node.copy(node.content.replaceChild(index,inner))}else if(!slice.content.size)return close(node,replaceTwoWay($from,$to,depth));else if(!slice.openStart&&!slice.openEnd&&$from.depth==depth&&$to.depth==depth){let parent=$from.parent,content=parent.content;return close(parent,content.cut(0,$from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)))}else{let{start,end}=prepareSliceForReplace(slice,$from);return close(node,replaceThreeWay($from,start,end,$to,depth))}}function checkJoin(main,sub){if(!sub.type.compatibleContent(main.type))throw new ReplaceError(`Cannot join `+sub.type.name+` onto `+main.type.name)}function joinable($before,$after,depth){let node=$before.node(depth);return checkJoin(node,$after.node(depth)),node}function addNode(child,target){let last=target.length-1;last>=0&&child.isText&&child.sameMarkup(target[last])?target[last]=child.withText(target[last].text+child.text):target.push(child)}function addRange($start,$end,depth,target){let node=($end||$start).node(depth),startIndex=0,endIndex=$end?$end.index(depth):node.childCount;$start&&(startIndex=$start.index(depth),$start.depth>depth?startIndex++:$start.textOffset&&(addNode($start.nodeAfter,target),startIndex++));for(let i=startIndex;i<endIndex;i++)addNode(node.child(i),target);$end&&$end.depth==depth&&$end.textOffset&&addNode($end.nodeBefore,target)}function close(node,content){if(!node.type.validContent(content))throw new ReplaceError(`Invalid content for node `+node.type.name);return node.copy(content)}function replaceThreeWay($from,$start,$end,$to,depth){let openStart=$from.depth>depth&&joinable($from,$start,depth+1),openEnd=$to.depth>depth&&joinable($end,$to,depth+1),content=[];return addRange(null,$from,depth,content),openStart&&openEnd&&$start.index(depth)==$end.index(depth)?(checkJoin(openStart,openEnd),addNode(close(openStart,replaceThreeWay($from,$start,$end,$to,depth+1)),content)):(openStart&&addNode(close(openStart,replaceTwoWay($from,$start,depth+1)),content),addRange($start,$end,depth,content),openEnd&&addNode(close(openEnd,replaceTwoWay($end,$to,depth+1)),content)),addRange($to,null,depth,content),new Fragment(content)}function replaceTwoWay($from,$to,depth){let content=[];return addRange(null,$from,depth,content),$from.depth>depth&&addNode(close(joinable($from,$to,depth+1),replaceTwoWay($from,$to,depth+1)),content),addRange($to,null,depth,content),new Fragment(content)}function prepareSliceForReplace(slice,$along){let extra=$along.depth-slice.openStart,node=$along.node(extra).copy(slice.content);for(let i=extra-1;i>=0;i--)node=$along.node(i).copy(Fragment.from(node));return{start:node.resolveNoCache(slice.openStart+extra),end:node.resolveNoCache(node.content.size-slice.openEnd-extra)}}var ResolvedPos=class ResolvedPos{constructor(pos,path,parentOffset){this.pos=pos,this.path=path,this.parentOffset=parentOffset,this.depth=path.length/3-1}resolveDepth(val){return val==null?this.depth:val<0?this.depth+val:val}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(depth){return this.path[this.resolveDepth(depth)*3]}index(depth){return this.path[this.resolveDepth(depth)*3+1]}indexAfter(depth){return depth=this.resolveDepth(depth),this.index(depth)+(depth==this.depth&&!this.textOffset?0:1)}start(depth){return depth=this.resolveDepth(depth),depth==0?0:this.path[depth*3-1]+1}end(depth){return depth=this.resolveDepth(depth),this.start(depth)+this.node(depth).content.size}before(depth){if(depth=this.resolveDepth(depth),!depth)throw RangeError(`There is no position before the top-level node`);return depth==this.depth+1?this.pos:this.path[depth*3-1]}after(depth){if(depth=this.resolveDepth(depth),!depth)throw RangeError(`There is no position after the top-level node`);return depth==this.depth+1?this.pos:this.path[depth*3-1]+this.path[depth*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let parent=this.parent,index=this.index(this.depth);if(index==parent.childCount)return null;let dOff=this.pos-this.path[this.path.length-1],child=parent.child(index);return dOff?parent.child(index).cut(dOff):child}get nodeBefore(){let index=this.index(this.depth),dOff=this.pos-this.path[this.path.length-1];return dOff?this.parent.child(index).cut(0,dOff):index==0?null:this.parent.child(index-1)}posAtIndex(index,depth){depth=this.resolveDepth(depth);let node=this.path[depth*3],pos=depth==0?0:this.path[depth*3-1]+1;for(let i=0;i<index;i++)pos+=node.child(i).nodeSize;return pos}marks(){let parent=this.parent,index=this.index();if(parent.content.size==0)return Mark.none;if(this.textOffset)return parent.child(index).marks;let main=parent.maybeChild(index-1),other=parent.maybeChild(index);if(!main){let tmp=main;main=other,other=tmp}let marks=main.marks;for(var i=0;i<marks.length;i++)marks[i].type.spec.inclusive===!1&&(!other||!marks[i].isInSet(other.marks))&&(marks=marks[i--].removeFromSet(marks));return marks}marksAcross($end){let after=this.parent.maybeChild(this.index());if(!after||!after.isInline)return null;let marks=after.marks,next=$end.parent.maybeChild($end.index());for(var i=0;i<marks.length;i++)marks[i].type.spec.inclusive===!1&&(!next||!marks[i].isInSet(next.marks))&&(marks=marks[i--].removeFromSet(marks));return marks}sharedDepth(pos){for(let depth=this.depth;depth>0;depth--)if(this.start(depth)<=pos&&this.end(depth)>=pos)return depth;return 0}blockRange(other=this,pred){if(other.pos<this.pos)return other.blockRange(this);for(let d=this.depth-(this.parent.inlineContent||this.pos==other.pos?1:0);d>=0;d--)if(other.pos<=this.end(d)&&(!pred||pred(this.node(d))))return new NodeRange(this,other,d);return null}sameParent(other){return this.pos-this.parentOffset==other.pos-other.parentOffset}max(other){return other.pos>this.pos?other:this}min(other){return other.pos<this.pos?other:this}toString(){let str=``;for(let i=1;i<=this.depth;i++)str+=(str?`/`:``)+this.node(i).type.name+`_`+this.index(i-1);return str+`:`+this.parentOffset}static resolve(doc,pos){if(!(pos>=0&&pos<=doc.content.size))throw RangeError(`Position `+pos+` out of range`);let path=[],start=0,parentOffset=pos;for(let node=doc;;){let{index,offset}=node.content.findIndex(parentOffset),rem=parentOffset-offset;if(path.push(node,index,start+offset),!rem||(node=node.child(index),node.isText))break;parentOffset=rem-1,start+=offset+1}return new ResolvedPos(pos,path,parentOffset)}static resolveCached(doc,pos){let cache=resolveCache.get(doc);if(cache)for(let i=0;i<cache.elts.length;i++){let elt=cache.elts[i];if(elt.pos==pos)return elt}else resolveCache.set(doc,cache=new ResolveCache);let result=cache.elts[cache.i]=ResolvedPos.resolve(doc,pos);return cache.i=(cache.i+1)%resolveCacheSize,result}},ResolveCache=class{constructor(){this.elts=[],this.i=0}},resolveCacheSize=12,resolveCache=new WeakMap,NodeRange=class{constructor($from,$to,depth){this.$from=$from,this.$to=$to,this.depth=depth}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},emptyAttrs=Object.create(null),Node=class Node{constructor(type,attrs,content,marks=Mark.none){this.type=type,this.attrs=attrs,this.marks=marks,this.content=content||Fragment.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(index){return this.content.child(index)}maybeChild(index){return this.content.maybeChild(index)}forEach(f){this.content.forEach(f)}nodesBetween(from,to,f,startPos=0){this.content.nodesBetween(from,to,f,startPos,this)}descendants(f){this.nodesBetween(0,this.content.size,f)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,``)}textBetween(from,to,blockSeparator,leafText){return this.content.textBetween(from,to,blockSeparator,leafText)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(other){return this==other||this.sameMarkup(other)&&this.content.eq(other.content)}sameMarkup(other){return this.hasMarkup(other.type,other.attrs,other.marks)}hasMarkup(type,attrs,marks){return this.type==type&&compareDeep(this.attrs,attrs||type.defaultAttrs||emptyAttrs)&&Mark.sameSet(this.marks,marks||Mark.none)}copy(content=null){return content==this.content?this:new Node(this.type,this.attrs,content,this.marks)}mark(marks){return marks==this.marks?this:new Node(this.type,this.attrs,this.content,marks)}cut(from,to=this.content.size){return from==0&&to==this.content.size?this:this.copy(this.content.cut(from,to))}slice(from,to=this.content.size,includeParents=!1){if(from==to)return Slice.empty;let $from=this.resolve(from),$to=this.resolve(to),depth=includeParents?0:$from.sharedDepth(to),start=$from.start(depth);return new Slice($from.node(depth).content.cut($from.pos-start,$to.pos-start),$from.depth-depth,$to.depth-depth)}replace(from,to,slice){return replace(this.resolve(from),this.resolve(to),slice)}nodeAt(pos){for(let node=this;;){let{index,offset}=node.content.findIndex(pos);if(node=node.maybeChild(index),!node)return null;if(offset==pos||node.isText)return node;pos-=offset+1}}childAfter(pos){let{index,offset}=this.content.findIndex(pos);return{node:this.content.maybeChild(index),index,offset}}childBefore(pos){if(pos==0)return{node:null,index:0,offset:0};let{index,offset}=this.content.findIndex(pos);if(offset<pos)return{node:this.content.child(index),index,offset};let node=this.content.child(index-1);return{node,index:index-1,offset:offset-node.nodeSize}}resolve(pos){return ResolvedPos.resolveCached(this,pos)}resolveNoCache(pos){return ResolvedPos.resolve(this,pos)}rangeHasMark(from,to,type){let found=!1;return to>from&&this.nodesBetween(from,to,node=>(type.isInSet(node.marks)&&(found=!0),!found)),found}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let name=this.type.name;return this.content.size&&(name+=`(`+this.content.toStringInner()+`)`),wrapMarks(this.marks,name)}contentMatchAt(index){let match=this.type.contentMatch.matchFragment(this.content,0,index);if(!match)throw Error(`Called contentMatchAt on a node with invalid content`);return match}canReplace(from,to,replacement=Fragment.empty,start=0,end=replacement.childCount){let one=this.contentMatchAt(from).matchFragment(replacement,start,end),two=one&&one.matchFragment(this.content,to);if(!two||!two.validEnd)return!1;for(let i=start;i<end;i++)if(!this.type.allowsMarks(replacement.child(i).marks))return!1;return!0}canReplaceWith(from,to,type,marks){if(marks&&!this.type.allowsMarks(marks))return!1;let start=this.contentMatchAt(from).matchType(type),end=start&&start.matchFragment(this.content,to);return end?end.validEnd:!1}canAppend(other){return other.content.size?this.canReplace(this.childCount,this.childCount,other.content):this.type.compatibleContent(other.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let copy=Mark.none;for(let i=0;i<this.marks.length;i++){let mark=this.marks[i];mark.type.checkAttrs(mark.attrs),copy=mark.addToSet(copy)}if(!Mark.sameSet(copy,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(m=>m.type.name)}`);this.content.forEach(node=>node.check())}toJSON(){let obj={type:this.type.name};for(let _ in this.attrs){obj.attrs=this.attrs;break}return this.content.size&&(obj.content=this.content.toJSON()),this.marks.length&&(obj.marks=this.marks.map(n=>n.toJSON())),obj}static fromJSON(schema,json){if(!json)throw RangeError(`Invalid input for Node.fromJSON`);let marks;if(json.marks){if(!Array.isArray(json.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);marks=json.marks.map(schema.markFromJSON)}if(json.type==`text`){if(typeof json.text!=`string`)throw RangeError(`Invalid text node in JSON`);return schema.text(json.text,marks)}let content=Fragment.fromJSON(schema,json.content),node=schema.nodeType(json.type).create(json.attrs,content,marks);return node.type.checkAttrs(node.attrs),node}};Node.prototype.text=void 0;function wrapMarks(marks,str){for(let i=marks.length-1;i>=0;i--)str=marks[i].type.name+`(`+str+`)`;return str}var ContentMatch=class ContentMatch{constructor(validEnd){this.validEnd=validEnd,this.next=[],this.wrapCache=[]}static parse(string,nodeTypes){let stream=new TokenStream(string,nodeTypes);if(stream.next==null)return ContentMatch.empty;let expr=parseExpr(stream);stream.next&&stream.err(`Unexpected trailing text`);let match=dfa(nfa(expr));return checkForDeadEnds(match,stream),match}matchType(type){for(let i=0;i<this.next.length;i++)if(this.next[i].type==type)return this.next[i].next;return null}matchFragment(frag,start=0,end=frag.childCount){let cur=this;for(let i=start;cur&&i<end;i++)cur=cur.matchType(frag.child(i).type);return cur}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let i=0;i<this.next.length;i++){let{type}=this.next[i];if(!(type.isText||type.hasRequiredAttrs()))return type}return null}compatible(other){for(let i=0;i<this.next.length;i++)for(let j=0;j<other.next.length;j++)if(this.next[i].type==other.next[j].type)return!0;return!1}fillBefore(after,toEnd=!1,startIndex=0){let seen=[this];function search(match,types){let finished=match.matchFragment(after,startIndex);if(finished&&(!toEnd||finished.validEnd))return Fragment.from(types.map(tp=>tp.createAndFill()));for(let i=0;i<match.next.length;i++){let{type,next}=match.next[i];if(!(type.isText||type.hasRequiredAttrs())&&seen.indexOf(next)==-1){seen.push(next);let found=search(next,types.concat(type));if(found)return found}}return null}return search(this,[])}findWrapping(target){for(let i=0;i<this.wrapCache.length;i+=2)if(this.wrapCache[i]==target)return this.wrapCache[i+1];let computed=this.computeWrapping(target);return this.wrapCache.push(target,computed),computed}computeWrapping(target){let seen=Object.create(null),active=[{match:this,type:null,via:null}];for(;active.length;){let current=active.shift(),match=current.match;if(match.matchType(target)){let result=[];for(let obj=current;obj.type;obj=obj.via)result.push(obj.type);return result.reverse()}for(let i=0;i<match.next.length;i++){let{type,next}=match.next[i];!type.isLeaf&&!type.hasRequiredAttrs()&&!(type.name in seen)&&(!current.type||next.validEnd)&&(active.push({match:type.contentMatch,type,via:current}),seen[type.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(n){if(n>=this.next.length)throw RangeError(`There's no ${n}th edge in this content match`);return this.next[n]}toString(){let seen=[];function scan(m){seen.push(m);for(let i=0;i<m.next.length;i++)seen.indexOf(m.next[i].next)==-1&&scan(m.next[i].next)}return scan(this),seen.map((m,i)=>{let out=i+(m.validEnd?`*`:` `)+` `;for(let i=0;i<m.next.length;i++)out+=(i?`, `:``)+m.next[i].type.name+`->`+seen.indexOf(m.next[i].next);return out}).join(`
2
+ `)}};ContentMatch.empty=new ContentMatch(!0);var TokenStream=class{constructor(string,nodeTypes){this.string=string,this.nodeTypes=nodeTypes,this.inline=null,this.pos=0,this.tokens=string.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(tok){return this.next==tok&&(this.pos++||!0)}err(str){throw SyntaxError(str+` (in content expression '`+this.string+`')`)}};function parseExpr(stream){let exprs=[];do exprs.push(parseExprSeq(stream));while(stream.eat(`|`));return exprs.length==1?exprs[0]:{type:`choice`,exprs}}function parseExprSeq(stream){let exprs=[];do exprs.push(parseExprSubscript(stream));while(stream.next&&stream.next!=`)`&&stream.next!=`|`);return exprs.length==1?exprs[0]:{type:`seq`,exprs}}function parseExprSubscript(stream){let expr=parseExprAtom(stream);for(;;)if(stream.eat(`+`))expr={type:`plus`,expr};else if(stream.eat(`*`))expr={type:`star`,expr};else if(stream.eat(`?`))expr={type:`opt`,expr};else if(stream.eat(`{`))expr=parseExprRange(stream,expr);else break;return expr}function parseNum(stream){/\D/.test(stream.next)&&stream.err(`Expected number, got '`+stream.next+`'`);let result=Number(stream.next);return stream.pos++,result}function parseExprRange(stream,expr){let min=parseNum(stream),max=min;return stream.eat(`,`)&&(max=stream.next==`}`?-1:parseNum(stream)),stream.eat(`}`)||stream.err(`Unclosed braced range`),{type:`range`,min,max,expr}}function resolveName(stream,name){let types=stream.nodeTypes,type=types[name];if(type)return[type];let result=[];for(let typeName in types){let type=types[typeName];type.isInGroup(name)&&result.push(type)}return result.length==0&&stream.err(`No node type or group '`+name+`' found`),result}function parseExprAtom(stream){if(stream.eat(`(`)){let expr=parseExpr(stream);return stream.eat(`)`)||stream.err(`Missing closing paren`),expr}else if(/\W/.test(stream.next))stream.err(`Unexpected token '`+stream.next+`'`);else{let exprs=resolveName(stream,stream.next).map(type=>(stream.inline==null?stream.inline=type.isInline:stream.inline!=type.isInline&&stream.err(`Mixing inline and block content`),{type:`name`,value:type}));return stream.pos++,exprs.length==1?exprs[0]:{type:`choice`,exprs}}}function nfa(expr){let nfa=[[]];return connect(compile(expr,0),node()),nfa;function node(){return nfa.push([])-1}function edge(from,to,term){let edge={term,to};return nfa[from].push(edge),edge}function connect(edges,to){edges.forEach(edge=>edge.to=to)}function compile(expr,from){if(expr.type==`choice`)return expr.exprs.reduce((out,expr)=>out.concat(compile(expr,from)),[]);if(expr.type==`seq`)for(let i=0;;i++){let next=compile(expr.exprs[i],from);if(i==expr.exprs.length-1)return next;connect(next,from=node())}else if(expr.type==`star`){let loop=node();return edge(from,loop),connect(compile(expr.expr,loop),loop),[edge(loop)]}else if(expr.type==`plus`){let loop=node();return connect(compile(expr.expr,from),loop),connect(compile(expr.expr,loop),loop),[edge(loop)]}else if(expr.type==`opt`)return[edge(from)].concat(compile(expr.expr,from));else if(expr.type==`range`){let cur=from;for(let i=0;i<expr.min;i++){let next=node();connect(compile(expr.expr,cur),next),cur=next}if(expr.max==-1)connect(compile(expr.expr,cur),cur);else for(let i=expr.min;i<expr.max;i++){let next=node();edge(cur,next),connect(compile(expr.expr,cur),next),cur=next}return[edge(cur)]}else if(expr.type==`name`)return[edge(from,void 0,expr.value)];else throw Error(`Unknown expr type`)}}function cmp(a,b){return b-a}function nullFrom(nfa,node){let result=[];return scan(node),result.sort(cmp);function scan(node){let edges=nfa[node];if(edges.length==1&&!edges[0].term)return scan(edges[0].to);result.push(node);for(let i=0;i<edges.length;i++){let{term,to}=edges[i];!term&&result.indexOf(to)==-1&&scan(to)}}}function dfa(nfa){let labeled=Object.create(null);return explore(nullFrom(nfa,0));function explore(states){let out=[];states.forEach(node=>{nfa[node].forEach(({term,to})=>{if(!term)return;let set;for(let i=0;i<out.length;i++)out[i][0]==term&&(set=out[i][1]);nullFrom(nfa,to).forEach(node=>{set||out.push([term,set=[]]),set.indexOf(node)==-1&&set.push(node)})})});let state=labeled[states.join(`,`)]=new ContentMatch(states.indexOf(nfa.length-1)>-1);for(let i=0;i<out.length;i++){let states=out[i][1].sort(cmp);state.next.push({type:out[i][0],next:labeled[states.join(`,`)]||explore(states)})}return state}}function checkForDeadEnds(match,stream){for(let i=0,work=[match];i<work.length;i++){let state=work[i],dead=!state.validEnd,nodes=[];for(let j=0;j<state.next.length;j++){let{type,next}=state.next[j];nodes.push(type.name),dead&&!(type.isText||type.hasRequiredAttrs())&&(dead=!1),work.indexOf(next)==-1&&work.push(next)}dead&&stream.err(`Only non-generatable nodes (`+nodes.join(`, `)+`) in a required position (see https://prosemirror.net/docs/guide/#generatable)`)}}var lower16=65535,factor16=2**16;function makeRecover(index,offset){return index+offset*factor16}function recoverIndex(value){return value&lower16}function recoverOffset(value){return(value-(value&lower16))/factor16}var DEL_BEFORE=1,DEL_AFTER=2,DEL_ACROSS=4,DEL_SIDE=8,MapResult=class{constructor(pos,delInfo,recover){this.pos=pos,this.delInfo=delInfo,this.recover=recover}get deleted(){return(this.delInfo&DEL_SIDE)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&DEL_ACROSS)>0}},StepMap=class StepMap{constructor(ranges,inverted=!1){if(this.ranges=ranges,this.inverted=inverted,!ranges.length&&StepMap.empty)return StepMap.empty}recover(value){let diff=0,index=recoverIndex(value);if(!this.inverted)for(let i=0;i<index;i++)diff+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[index*3]+diff+recoverOffset(value)}mapResult(pos,assoc=1){return this._map(pos,assoc,!1)}map(pos,assoc=1){return this._map(pos,assoc,!0)}_map(pos,assoc,simple){let diff=0,oldIndex=this.inverted?2:1,newIndex=this.inverted?1:2;for(let i=0;i<this.ranges.length;i+=3){let start=this.ranges[i]-(this.inverted?diff:0);if(start>pos)break;let oldSize=this.ranges[i+oldIndex],newSize=this.ranges[i+newIndex],end=start+oldSize;if(pos<=end){let side=oldSize?pos==start?-1:pos==end?1:assoc:assoc,result=start+diff+(side<0?0:newSize);if(simple)return result;let recover=pos==(assoc<0?start:end)?null:makeRecover(i/3,pos-start),del=pos==start?DEL_AFTER:pos==end?DEL_BEFORE:DEL_ACROSS;return(assoc<0?pos!=start:pos!=end)&&(del|=DEL_SIDE),new MapResult(result,del,recover)}diff+=newSize-oldSize}return simple?pos+diff:new MapResult(pos+diff,0,null)}touches(pos,recover){let diff=0,index=recoverIndex(recover),oldIndex=this.inverted?2:1,newIndex=this.inverted?1:2;for(let i=0;i<this.ranges.length;i+=3){let start=this.ranges[i]-(this.inverted?diff:0);if(start>pos)break;let oldSize=this.ranges[i+oldIndex];if(pos<=start+oldSize&&i==index*3)return!0;diff+=this.ranges[i+newIndex]-oldSize}return!1}forEach(f){let oldIndex=this.inverted?2:1,newIndex=this.inverted?1:2;for(let i=0,diff=0;i<this.ranges.length;i+=3){let start=this.ranges[i],oldStart=start-(this.inverted?diff:0),newStart=start+(this.inverted?0:diff),oldSize=this.ranges[i+oldIndex],newSize=this.ranges[i+newIndex];f(oldStart,oldStart+oldSize,newStart,newStart+newSize),diff+=newSize-oldSize}}invert(){return new StepMap(this.ranges,!this.inverted)}toString(){return(this.inverted?`-`:``)+JSON.stringify(this.ranges)}static offset(n){return n==0?StepMap.empty:new StepMap(n<0?[0,-n,0]:[0,0,n])}};StepMap.empty=new StepMap([]);var stepsByID=Object.create(null),Step=class{getMap(){return StepMap.empty}merge(other){return null}static fromJSON(schema,json){if(!json||!json.stepType)throw RangeError(`Invalid input for Step.fromJSON`);let type=stepsByID[json.stepType];if(!type)throw RangeError(`No step type ${json.stepType} defined`);return type.fromJSON(schema,json)}static jsonID(id,stepClass){if(id in stepsByID)throw RangeError(`Duplicate use of step JSON ID `+id);return stepsByID[id]=stepClass,stepClass.prototype.jsonID=id,stepClass}},StepResult=class StepResult{constructor(doc,failed){this.doc=doc,this.failed=failed}static ok(doc){return new StepResult(doc,null)}static fail(message){return new StepResult(null,message)}static fromReplace(doc,from,to,slice){try{return StepResult.ok(doc.replace(from,to,slice))}catch(e){if(e instanceof ReplaceError)return StepResult.fail(e.message);throw e}}};function mapFragment(fragment,f,parent){let mapped=[];for(let i=0;i<fragment.childCount;i++){let child=fragment.child(i);child.content.size&&(child=child.copy(mapFragment(child.content,f,child))),child.isInline&&(child=f(child,parent,i)),mapped.push(child)}return Fragment.fromArray(mapped)}var AddMarkStep=class AddMarkStep extends Step{constructor(from,to,mark){super(),this.from=from,this.to=to,this.mark=mark}apply(doc){let oldSlice=doc.slice(this.from,this.to),$from=doc.resolve(this.from),parent=$from.node($from.sharedDepth(this.to)),slice=new Slice(mapFragment(oldSlice.content,(node,parent)=>!node.isAtom||!parent.type.allowsMarkType(this.mark.type)?node:node.mark(this.mark.addToSet(node.marks)),parent),oldSlice.openStart,oldSlice.openEnd);return StepResult.fromReplace(doc,this.from,this.to,slice)}invert(){return new RemoveMarkStep(this.from,this.to,this.mark)}map(mapping){let from=mapping.mapResult(this.from,1),to=mapping.mapResult(this.to,-1);return from.deleted&&to.deleted||from.pos>=to.pos?null:new AddMarkStep(from.pos,to.pos,this.mark)}merge(other){return other instanceof AddMarkStep&&other.mark.eq(this.mark)&&this.from<=other.to&&this.to>=other.from?new AddMarkStep(Math.min(this.from,other.from),Math.max(this.to,other.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(schema,json){if(typeof json.from!=`number`||typeof json.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new AddMarkStep(json.from,json.to,schema.markFromJSON(json.mark))}};Step.jsonID(`addMark`,AddMarkStep);var RemoveMarkStep=class RemoveMarkStep extends Step{constructor(from,to,mark){super(),this.from=from,this.to=to,this.mark=mark}apply(doc){let oldSlice=doc.slice(this.from,this.to),slice=new Slice(mapFragment(oldSlice.content,node=>node.mark(this.mark.removeFromSet(node.marks)),doc),oldSlice.openStart,oldSlice.openEnd);return StepResult.fromReplace(doc,this.from,this.to,slice)}invert(){return new AddMarkStep(this.from,this.to,this.mark)}map(mapping){let from=mapping.mapResult(this.from,1),to=mapping.mapResult(this.to,-1);return from.deleted&&to.deleted||from.pos>=to.pos?null:new RemoveMarkStep(from.pos,to.pos,this.mark)}merge(other){return other instanceof RemoveMarkStep&&other.mark.eq(this.mark)&&this.from<=other.to&&this.to>=other.from?new RemoveMarkStep(Math.min(this.from,other.from),Math.max(this.to,other.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(schema,json){if(typeof json.from!=`number`||typeof json.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new RemoveMarkStep(json.from,json.to,schema.markFromJSON(json.mark))}};Step.jsonID(`removeMark`,RemoveMarkStep);var AddNodeMarkStep=class AddNodeMarkStep extends Step{constructor(pos,mark){super(),this.pos=pos,this.mark=mark}apply(doc){let node=doc.nodeAt(this.pos);if(!node)return StepResult.fail(`No node at mark step's position`);let updated=node.type.create(node.attrs,null,this.mark.addToSet(node.marks));return StepResult.fromReplace(doc,this.pos,this.pos+1,new Slice(Fragment.from(updated),0,+!node.isLeaf))}invert(doc){let node=doc.nodeAt(this.pos);if(node){let newSet=this.mark.addToSet(node.marks);if(newSet.length==node.marks.length){for(let i=0;i<node.marks.length;i++)if(!node.marks[i].isInSet(newSet))return new AddNodeMarkStep(this.pos,node.marks[i]);return new AddNodeMarkStep(this.pos,this.mark)}}return new RemoveNodeMarkStep(this.pos,this.mark)}map(mapping){let pos=mapping.mapResult(this.pos,1);return pos.deletedAfter?null:new AddNodeMarkStep(pos.pos,this.mark)}toJSON(){return{stepType:`addNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(schema,json){if(typeof json.pos!=`number`)throw RangeError(`Invalid input for AddNodeMarkStep.fromJSON`);return new AddNodeMarkStep(json.pos,schema.markFromJSON(json.mark))}};Step.jsonID(`addNodeMark`,AddNodeMarkStep);var RemoveNodeMarkStep=class RemoveNodeMarkStep extends Step{constructor(pos,mark){super(),this.pos=pos,this.mark=mark}apply(doc){let node=doc.nodeAt(this.pos);if(!node)return StepResult.fail(`No node at mark step's position`);let updated=node.type.create(node.attrs,null,this.mark.removeFromSet(node.marks));return StepResult.fromReplace(doc,this.pos,this.pos+1,new Slice(Fragment.from(updated),0,+!node.isLeaf))}invert(doc){let node=doc.nodeAt(this.pos);return!node||!this.mark.isInSet(node.marks)?this:new AddNodeMarkStep(this.pos,this.mark)}map(mapping){let pos=mapping.mapResult(this.pos,1);return pos.deletedAfter?null:new RemoveNodeMarkStep(pos.pos,this.mark)}toJSON(){return{stepType:`removeNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(schema,json){if(typeof json.pos!=`number`)throw RangeError(`Invalid input for RemoveNodeMarkStep.fromJSON`);return new RemoveNodeMarkStep(json.pos,schema.markFromJSON(json.mark))}};Step.jsonID(`removeNodeMark`,RemoveNodeMarkStep);var ReplaceStep=class ReplaceStep extends Step{constructor(from,to,slice,structure=!1){super(),this.from=from,this.to=to,this.slice=slice,this.structure=structure}apply(doc){return this.structure&&contentBetween(doc,this.from,this.to)?StepResult.fail(`Structure replace would overwrite content`):StepResult.fromReplace(doc,this.from,this.to,this.slice)}getMap(){return new StepMap([this.from,this.to-this.from,this.slice.size])}invert(doc){return new ReplaceStep(this.from,this.from+this.slice.size,doc.slice(this.from,this.to))}map(mapping){let to=mapping.mapResult(this.to,-1),from=this.from==this.to&&ReplaceStep.MAP_BIAS<0?to:mapping.mapResult(this.from,1);return from.deletedAcross&&to.deletedAcross?null:new ReplaceStep(from.pos,Math.max(from.pos,to.pos),this.slice,this.structure)}merge(other){if(!(other instanceof ReplaceStep)||other.structure||this.structure)return null;if(this.from+this.slice.size==other.from&&!this.slice.openEnd&&!other.slice.openStart){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);return new ReplaceStep(this.from,this.to+(other.to-other.from),slice,this.structure)}else if(other.to==this.from&&!this.slice.openStart&&!other.slice.openEnd){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);return new ReplaceStep(other.from,this.to,slice,this.structure)}else return null}toJSON(){let json={stepType:`replace`,from:this.from,to:this.to};return this.slice.size&&(json.slice=this.slice.toJSON()),this.structure&&(json.structure=!0),json}static fromJSON(schema,json){if(typeof json.from!=`number`||typeof json.to!=`number`)throw RangeError(`Invalid input for ReplaceStep.fromJSON`);return new ReplaceStep(json.from,json.to,Slice.fromJSON(schema,json.slice),!!json.structure)}};ReplaceStep.MAP_BIAS=1,Step.jsonID(`replace`,ReplaceStep);var ReplaceAroundStep=class ReplaceAroundStep extends Step{constructor(from,to,gapFrom,gapTo,slice,insert,structure=!1){super(),this.from=from,this.to=to,this.gapFrom=gapFrom,this.gapTo=gapTo,this.slice=slice,this.insert=insert,this.structure=structure}apply(doc){if(this.structure&&(contentBetween(doc,this.from,this.gapFrom)||contentBetween(doc,this.gapTo,this.to)))return StepResult.fail(`Structure gap-replace would overwrite content`);let gap=doc.slice(this.gapFrom,this.gapTo);if(gap.openStart||gap.openEnd)return StepResult.fail(`Gap is not a flat range`);let inserted=this.slice.insertAt(this.insert,gap.content);return inserted?StepResult.fromReplace(doc,this.from,this.to,inserted):StepResult.fail(`Content does not fit in gap`)}getMap(){return new StepMap([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(doc){let gap=this.gapTo-this.gapFrom;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)}map(mapping){let from=mapping.mapResult(this.from,1),to=mapping.mapResult(this.to,-1),gapFrom=this.from==this.gapFrom?from.pos:mapping.map(this.gapFrom,-1),gapTo=this.to==this.gapTo?to.pos:mapping.map(this.gapTo,1);return from.deletedAcross&&to.deletedAcross||gapFrom<from.pos||gapTo>to.pos?null:new ReplaceAroundStep(from.pos,to.pos,gapFrom,gapTo,this.slice,this.insert,this.structure)}toJSON(){let json={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(json.slice=this.slice.toJSON()),this.structure&&(json.structure=!0),json}static fromJSON(schema,json){if(typeof json.from!=`number`||typeof json.to!=`number`||typeof json.gapFrom!=`number`||typeof json.gapTo!=`number`||typeof json.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new ReplaceAroundStep(json.from,json.to,json.gapFrom,json.gapTo,Slice.fromJSON(schema,json.slice),json.insert,!!json.structure)}};Step.jsonID(`replaceAround`,ReplaceAroundStep);function contentBetween(doc,from,to){let $from=doc.resolve(from),dist=to-from,depth=$from.depth;for(;dist>0&&depth>0&&$from.indexAfter(depth)==$from.node(depth).childCount;)depth--,dist--;if(dist>0){let next=$from.node(depth).maybeChild($from.indexAfter(depth));for(;dist>0;){if(!next||next.isLeaf)return!0;next=next.firstChild,dist--}}return!1}var AttrStep=class AttrStep extends Step{constructor(pos,attr,value){super(),this.pos=pos,this.attr=attr,this.value=value}apply(doc){let node=doc.nodeAt(this.pos);if(!node)return StepResult.fail(`No node at attribute step's position`);let attrs=Object.create(null);for(let name in node.attrs)attrs[name]=node.attrs[name];attrs[this.attr]=this.value;let updated=node.type.create(attrs,null,node.marks);return StepResult.fromReplace(doc,this.pos,this.pos+1,new Slice(Fragment.from(updated),0,+!node.isLeaf))}getMap(){return StepMap.empty}invert(doc){return new AttrStep(this.pos,this.attr,doc.nodeAt(this.pos).attrs[this.attr])}map(mapping){let pos=mapping.mapResult(this.pos,1);return pos.deletedAfter?null:new AttrStep(pos.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(schema,json){if(typeof json.pos!=`number`||typeof json.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new AttrStep(json.pos,json.attr,json.value)}};Step.jsonID(`attr`,AttrStep);var DocAttrStep=class DocAttrStep extends Step{constructor(attr,value){super(),this.attr=attr,this.value=value}apply(doc){let attrs=Object.create(null);for(let name in doc.attrs)attrs[name]=doc.attrs[name];attrs[this.attr]=this.value;let updated=doc.type.create(attrs,doc.content,doc.marks);return StepResult.ok(updated)}getMap(){return StepMap.empty}invert(doc){return new DocAttrStep(this.attr,doc.attrs[this.attr])}map(mapping){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(schema,json){if(typeof json.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new DocAttrStep(json.attr,json.value)}};Step.jsonID(`docAttr`,DocAttrStep);var TransformError=class extends Error{};TransformError=function TransformError(message){let err=Error.call(this,message);return err.__proto__=TransformError.prototype,err},TransformError.prototype=Object.create(Error.prototype),TransformError.prototype.constructor=TransformError,TransformError.prototype.name=`TransformError`;var classesById=Object.create(null),Selection=class{constructor($anchor,$head,ranges){this.$anchor=$anchor,this.$head=$head,this.ranges=ranges||[new SelectionRange($anchor.min($head),$anchor.max($head))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let ranges=this.ranges;for(let i=0;i<ranges.length;i++)if(ranges[i].$from.pos!=ranges[i].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(tr,content=Slice.empty){let lastNode=content.content.lastChild,lastParent=null;for(let i=0;i<content.openEnd;i++)lastParent=lastNode,lastNode=lastNode.lastChild;let mapFrom=tr.steps.length,ranges=this.ranges;for(let i=0;i<ranges.length;i++){let{$from,$to}=ranges[i],mapping=tr.mapping.slice(mapFrom);tr.replaceRange(mapping.map($from.pos),mapping.map($to.pos),i?Slice.empty:content),i==0&&selectionToInsertionEnd(tr,mapFrom,(lastNode?lastNode.isInline:lastParent&&lastParent.isTextblock)?-1:1)}}replaceWith(tr,node){let mapFrom=tr.steps.length,ranges=this.ranges;for(let i=0;i<ranges.length;i++){let{$from,$to}=ranges[i],mapping=tr.mapping.slice(mapFrom),from=mapping.map($from.pos),to=mapping.map($to.pos);i?tr.deleteRange(from,to):(tr.replaceRangeWith(from,to,node),selectionToInsertionEnd(tr,mapFrom,node.isInline?-1:1))}}static findFrom($pos,dir,textOnly=!1){let inner=$pos.parent.inlineContent?new TextSelection($pos):findSelectionIn($pos.node(0),$pos.parent,$pos.pos,$pos.index(),dir,textOnly);if(inner)return inner;for(let depth=$pos.depth-1;depth>=0;depth--){let found=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);if(found)return found}return null}static near($pos,bias=1){return this.findFrom($pos,bias)||this.findFrom($pos,-bias)||new AllSelection($pos.node(0))}static atStart(doc){return findSelectionIn(doc,doc,0,0,1)||new AllSelection(doc)}static atEnd(doc){return findSelectionIn(doc,doc,doc.content.size,doc.childCount,-1)||new AllSelection(doc)}static fromJSON(doc,json){if(!json||!json.type)throw RangeError(`Invalid input for Selection.fromJSON`);let cls=classesById[json.type];if(!cls)throw RangeError(`No selection type ${json.type} defined`);return cls.fromJSON(doc,json)}static jsonID(id,selectionClass){if(id in classesById)throw RangeError(`Duplicate use of selection JSON ID `+id);return classesById[id]=selectionClass,selectionClass.prototype.jsonID=id,selectionClass}getBookmark(){return TextSelection.between(this.$anchor,this.$head).getBookmark()}};Selection.prototype.visible=!0;var SelectionRange=class{constructor($from,$to){this.$from=$from,this.$to=$to}},warnedAboutTextSelection=!1;function checkTextSelection($pos){!warnedAboutTextSelection&&!$pos.parent.inlineContent&&(warnedAboutTextSelection=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+$pos.parent.type.name+`)`))}var TextSelection=class TextSelection extends Selection{constructor($anchor,$head=$anchor){checkTextSelection($anchor),checkTextSelection($head),super($anchor,$head)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(doc,mapping){let $head=doc.resolve(mapping.map(this.head));if(!$head.parent.inlineContent)return Selection.near($head);let $anchor=doc.resolve(mapping.map(this.anchor));return new TextSelection($anchor.parent.inlineContent?$anchor:$head,$head)}replace(tr,content=Slice.empty){if(super.replace(tr,content),content==Slice.empty){let marks=this.$from.marksAcross(this.$to);marks&&tr.ensureMarks(marks)}}eq(other){return other instanceof TextSelection&&other.anchor==this.anchor&&other.head==this.head}getBookmark(){return new TextBookmark(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(doc,json){if(typeof json.anchor!=`number`||typeof json.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new TextSelection(doc.resolve(json.anchor),doc.resolve(json.head))}static create(doc,anchor,head=anchor){let $anchor=doc.resolve(anchor);return new this($anchor,head==anchor?$anchor:doc.resolve(head))}static between($anchor,$head,bias){let dPos=$anchor.pos-$head.pos;if((!bias||dPos)&&(bias=dPos>=0?1:-1),!$head.parent.inlineContent){let found=Selection.findFrom($head,bias,!0)||Selection.findFrom($head,-bias,!0);if(found)$head=found.$head;else return Selection.near($head,bias)}return $anchor.parent.inlineContent||(dPos==0?$anchor=$head:($anchor=(Selection.findFrom($anchor,-bias,!0)||Selection.findFrom($anchor,bias,!0)).$anchor,$anchor.pos<$head.pos!=dPos<0&&($anchor=$head))),new TextSelection($anchor,$head)}};Selection.jsonID(`text`,TextSelection);var TextBookmark=class TextBookmark{constructor(anchor,head){this.anchor=anchor,this.head=head}map(mapping){return new TextBookmark(mapping.map(this.anchor),mapping.map(this.head))}resolve(doc){return TextSelection.between(doc.resolve(this.anchor),doc.resolve(this.head))}},NodeSelection=class NodeSelection extends Selection{constructor($pos){let node=$pos.nodeAfter,$end=$pos.node(0).resolve($pos.pos+node.nodeSize);super($pos,$end),this.node=node}map(doc,mapping){let{deleted,pos}=mapping.mapResult(this.anchor),$pos=doc.resolve(pos);return deleted?Selection.near($pos):new NodeSelection($pos)}content(){return new Slice(Fragment.from(this.node),0,0)}eq(other){return other instanceof NodeSelection&&other.anchor==this.anchor}toJSON(){return{type:`node`,anchor:this.anchor}}getBookmark(){return new NodeBookmark(this.anchor)}static fromJSON(doc,json){if(typeof json.anchor!=`number`)throw RangeError(`Invalid input for NodeSelection.fromJSON`);return new NodeSelection(doc.resolve(json.anchor))}static create(doc,from){return new NodeSelection(doc.resolve(from))}static isSelectable(node){return!node.isText&&node.type.spec.selectable!==!1}};NodeSelection.prototype.visible=!1,Selection.jsonID(`node`,NodeSelection);var NodeBookmark=class NodeBookmark{constructor(anchor){this.anchor=anchor}map(mapping){let{deleted,pos}=mapping.mapResult(this.anchor);return deleted?new TextBookmark(pos,pos):new NodeBookmark(pos)}resolve(doc){let $pos=doc.resolve(this.anchor),node=$pos.nodeAfter;return node&&NodeSelection.isSelectable(node)?new NodeSelection($pos):Selection.near($pos)}},AllSelection=class AllSelection extends Selection{constructor(doc){super(doc.resolve(0),doc.resolve(doc.content.size))}replace(tr,content=Slice.empty){if(content==Slice.empty){tr.delete(0,tr.doc.content.size);let sel=Selection.atStart(tr.doc);sel.eq(tr.selection)||tr.setSelection(sel)}else super.replace(tr,content)}toJSON(){return{type:`all`}}static fromJSON(doc){return new AllSelection(doc)}map(doc){return new AllSelection(doc)}eq(other){return other instanceof AllSelection}getBookmark(){return AllBookmark}};Selection.jsonID(`all`,AllSelection);var AllBookmark={map(){return this},resolve(doc){return new AllSelection(doc)}};function findSelectionIn(doc,node,pos,index,dir,text=!1){if(node.inlineContent)return TextSelection.create(doc,pos);for(let i=index-(dir>0?0:1);dir>0?i<node.childCount:i>=0;i+=dir){let child=node.child(i);if(!child.isAtom){let inner=findSelectionIn(doc,child,pos+dir,dir<0?child.childCount:0,dir,text);if(inner)return inner}else if(!text&&NodeSelection.isSelectable(child))return NodeSelection.create(doc,pos-(dir<0?child.nodeSize:0));pos+=child.nodeSize*dir}return null}function selectionToInsertionEnd(tr,startLen,bias){let last=tr.steps.length-1;if(last<startLen)return;let step=tr.steps[last];if(!(step instanceof ReplaceStep||step instanceof ReplaceAroundStep))return;let map=tr.mapping.maps[last],end;map.forEach((_from,_to,_newFrom,newTo)=>{end??=newTo}),tr.setSelection(Selection.near(tr.doc.resolve(end),bias))}function bind(f,self){return!self||!f?f:f.bind(self)}var FieldDesc=class{constructor(name,desc,self){this.name=name,this.init=bind(desc.init,self),this.apply=bind(desc.apply,self)}};new FieldDesc(`doc`,{init(config){return config.doc||config.schema.topNodeType.createAndFill()},apply(tr){return tr.doc}}),new FieldDesc(`selection`,{init(config,instance){return config.selection||Selection.atStart(instance.doc)},apply(tr){return tr.selection}}),new FieldDesc(`storedMarks`,{init(config){return config.storedMarks||null},apply(tr,_marks,_old,state){return state.selection.$cursor?tr.storedMarks:null}}),new FieldDesc(`scrollToSelection`,{init(){return 0},apply(tr,prev){return tr.scrolledIntoView?prev+1:prev}});var keys=Object.create(null);function createKey(name){return name in keys?name+`$`+ ++keys[name]:(keys[name]=0,name+`$`)}var PluginKey=class{constructor(name=`key`){this.key=createKey(name)}get(state){return state.config.pluginsByKey[this.key]}getState(state){return state[this.key]}};export{PluginKey as t};