@blockslides/extension-add-slide-button 0.1.0

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