@veltra/desktop 1.2.16 → 1.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/components/action/action-group.vue.d.ts +2 -2
  2. package/dist/components/action/action.vue.d.ts +1 -1
  3. package/dist/components/auto-complete/auto-complete.vue.d.ts +2 -2
  4. package/dist/components/cascade/cascade.vue.d.ts +3 -3
  5. package/dist/components/checkbox/checkbox-button.vue.d.ts +1 -1
  6. package/dist/components/checkbox-group/checkbox-group.vue.d.ts +2 -2
  7. package/dist/components/code-editor/basic-setup.js +7 -7
  8. package/dist/components/code-editor/code-editor.js +15 -10
  9. package/dist/components/code-editor/code-editor.js.map +1 -1
  10. package/dist/components/date-picker/date-picker.vue.d.ts +2 -2
  11. package/dist/components/date-range-picker/date-range-picker.vue.d.ts +2 -2
  12. package/dist/components/empty/empty.vue.d.ts +1 -1
  13. package/dist/components/file-picker/file-picker.vue.d.ts +1 -1
  14. package/dist/components/input/input.vue.d.ts +2 -2
  15. package/dist/components/multi-select/multi-select.vue.d.ts +3 -3
  16. package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +3 -3
  17. package/dist/components/number-input/number-input.vue.d.ts +2 -2
  18. package/dist/components/number-range-input/number-range-input.vue.d.ts +1 -1
  19. package/dist/components/password-input/password-input.vue.d.ts +1 -1
  20. package/dist/components/pop-confirm/pop-confirm.vue.d.ts +1 -1
  21. package/dist/components/radio-group/radio-group.vue.d.ts +2 -2
  22. package/dist/components/rich-text-editor/rich-text-editor.vue.d.ts +1 -1
  23. package/dist/components/select/select.vue.d.ts +2 -2
  24. package/dist/components/textarea/textarea.vue.d.ts +2 -2
  25. package/dist/components/tip/tip.vue.d.ts +1 -1
  26. package/dist/components/tree-select/tree-select.vue.d.ts +3 -3
  27. package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js +1750 -0
  28. package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -0
  29. package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js +1719 -0
  30. package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js.map +1 -0
  31. package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js +51 -0
  32. package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js.map +1 -0
  33. package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js +378 -0
  34. package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js.map +1 -0
  35. package/dist/node_modules/.bun/@codemirror_lang-json@6.0.2/node_modules/@codemirror/lang-json/dist/index.js +31 -0
  36. package/dist/node_modules/.bun/@codemirror_lang-json@6.0.2/node_modules/@codemirror/lang-json/dist/index.js.map +1 -0
  37. package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js +601 -0
  38. package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js.map +1 -0
  39. package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js +1767 -0
  40. package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js.map +1 -0
  41. package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js +569 -0
  42. package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js.map +1 -0
  43. package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js +1142 -0
  44. package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js.map +1 -0
  45. package/dist/node_modules/.bun/@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js +3372 -0
  46. package/dist/node_modules/.bun/@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js.map +1 -0
  47. package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js +165 -0
  48. package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js.map +1 -0
  49. package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js +9770 -0
  50. package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js.map +1 -0
  51. package/dist/node_modules/.bun/@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js +1567 -0
  52. package/dist/node_modules/.bun/@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js.map +1 -0
  53. package/dist/node_modules/.bun/@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js +864 -0
  54. package/dist/node_modules/.bun/@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js.map +1 -0
  55. package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js +235 -0
  56. package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js.map +1 -0
  57. package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js +470 -0
  58. package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js.map +1 -0
  59. package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js +55 -0
  60. package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js.map +1 -0
  61. package/dist/node_modules/.bun/@lezer_lr@1.4.10/node_modules/@lezer/lr/dist/index.js +1485 -0
  62. package/dist/node_modules/.bun/@lezer_lr@1.4.10/node_modules/@lezer/lr/dist/index.js.map +1 -0
  63. package/dist/node_modules/.bun/@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js +73 -0
  64. package/dist/node_modules/.bun/@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js.map +1 -0
  65. package/dist/node_modules/.bun/crelt@1.0.6/node_modules/crelt/index.js +26 -0
  66. package/dist/node_modules/.bun/crelt@1.0.6/node_modules/crelt/index.js.map +1 -0
  67. package/dist/node_modules/.bun/style-mod@4.1.3/node_modules/style-mod/src/style-mod.js +95 -0
  68. package/dist/node_modules/.bun/style-mod@4.1.3/node_modules/style-mod/src/style-mod.js.map +1 -0
  69. package/dist/node_modules/.bun/w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js +104 -0
  70. package/dist/node_modules/.bun/w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js.map +1 -0
  71. package/package.json +20 -18
  72. package/src/components/code-editor/code-editor.vue +12 -7
@@ -0,0 +1,3372 @@
1
+ import { findClusterBreak as findClusterBreak$1 } from "../../../../../@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js";
2
+ //#region ../../node_modules/.bun/@codemirror+state@6.7.0/node_modules/@codemirror/state/dist/index.js
3
+ /**
4
+ The data structure for documents. @nonabstract
5
+ */
6
+ var Text = class Text {
7
+ /**
8
+ Get the line description around the given position.
9
+ */
10
+ lineAt(pos) {
11
+ if (pos < 0 || pos > this.length) throw new RangeError(`Invalid position ${pos} in document of length ${this.length}`);
12
+ return this.lineInner(pos, false, 1, 0);
13
+ }
14
+ /**
15
+ Get the description for the given (1-based) line number.
16
+ */
17
+ line(n) {
18
+ if (n < 1 || n > this.lines) throw new RangeError(`Invalid line number ${n} in ${this.lines}-line document`);
19
+ return this.lineInner(n, true, 1, 0);
20
+ }
21
+ /**
22
+ Replace a range of the text with the given content.
23
+ */
24
+ replace(from, to, text) {
25
+ [from, to] = clip(this, from, to);
26
+ let parts = [];
27
+ this.decompose(0, from, parts, 2);
28
+ if (text.length) text.decompose(0, text.length, parts, 3);
29
+ this.decompose(to, this.length, parts, 1);
30
+ return TextNode.from(parts, this.length - (to - from) + text.length);
31
+ }
32
+ /**
33
+ Append another document to this one.
34
+ */
35
+ append(other) {
36
+ return this.replace(this.length, this.length, other);
37
+ }
38
+ /**
39
+ Retrieve the text between the given points.
40
+ */
41
+ slice(from, to = this.length) {
42
+ [from, to] = clip(this, from, to);
43
+ let parts = [];
44
+ this.decompose(from, to, parts, 0);
45
+ return TextNode.from(parts, to - from);
46
+ }
47
+ /**
48
+ Test whether this text is equal to another instance.
49
+ */
50
+ eq(other) {
51
+ if (other == this) return true;
52
+ if (other.length != this.length || other.lines != this.lines) return false;
53
+ let start = this.scanIdentical(other, 1), end = this.length - this.scanIdentical(other, -1);
54
+ let a = new RawTextCursor(this), b = new RawTextCursor(other);
55
+ for (let skip = start, pos = start;;) {
56
+ a.next(skip);
57
+ b.next(skip);
58
+ skip = 0;
59
+ if (a.lineBreak != b.lineBreak || a.done != b.done || a.value != b.value) return false;
60
+ pos += a.value.length;
61
+ if (a.done || pos >= end) return true;
62
+ }
63
+ }
64
+ /**
65
+ Iterate over the text. When `dir` is `-1`, iteration happens
66
+ from end to start. This will return lines and the breaks between
67
+ them as separate strings.
68
+ */
69
+ iter(dir = 1) {
70
+ return new RawTextCursor(this, dir);
71
+ }
72
+ /**
73
+ Iterate over a range of the text. When `from` > `to`, the
74
+ iterator will run in reverse.
75
+ */
76
+ iterRange(from, to = this.length) {
77
+ return new PartialTextCursor(this, from, to);
78
+ }
79
+ /**
80
+ Return a cursor that iterates over the given range of lines,
81
+ _without_ returning the line breaks between, and yielding empty
82
+ strings for empty lines.
83
+
84
+ When `from` and `to` are given, they should be 1-based line numbers.
85
+ */
86
+ iterLines(from, to) {
87
+ let inner;
88
+ if (from == null) inner = this.iter();
89
+ else {
90
+ if (to == null) to = this.lines + 1;
91
+ let start = this.line(from).from;
92
+ inner = this.iterRange(start, Math.max(start, to == this.lines + 1 ? this.length : to <= 1 ? 0 : this.line(to - 1).to));
93
+ }
94
+ return new LineCursor(inner);
95
+ }
96
+ /**
97
+ Return the document as a string, using newline characters to
98
+ separate lines.
99
+ */
100
+ toString() {
101
+ return this.sliceString(0);
102
+ }
103
+ /**
104
+ Convert the document to an array of lines (which can be
105
+ deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
106
+ */
107
+ toJSON() {
108
+ let lines = [];
109
+ this.flatten(lines);
110
+ return lines;
111
+ }
112
+ /**
113
+ @internal
114
+ */
115
+ constructor() {}
116
+ /**
117
+ Create a `Text` instance for the given array of lines.
118
+ */
119
+ static of(text) {
120
+ if (text.length == 0) throw new RangeError("A document must have at least one line");
121
+ if (text.length == 1 && !text[0]) return Text.empty;
122
+ return text.length <= 32 ? new TextLeaf(text) : TextNode.from(TextLeaf.split(text, []));
123
+ }
124
+ };
125
+ var TextLeaf = class TextLeaf extends Text {
126
+ constructor(text, length = textLength(text)) {
127
+ super();
128
+ this.text = text;
129
+ this.length = length;
130
+ }
131
+ get lines() {
132
+ return this.text.length;
133
+ }
134
+ get children() {
135
+ return null;
136
+ }
137
+ lineInner(target, isLine, line, offset) {
138
+ for (let i = 0;; i++) {
139
+ let string = this.text[i], end = offset + string.length;
140
+ if ((isLine ? line : end) >= target) return new Line(offset, end, line, string);
141
+ offset = end + 1;
142
+ line++;
143
+ }
144
+ }
145
+ decompose(from, to, target, open) {
146
+ let text = from <= 0 && to >= this.length ? this : new TextLeaf(sliceText(this.text, from, to), Math.min(to, this.length) - Math.max(0, from));
147
+ if (open & 1) {
148
+ let prev = target.pop();
149
+ let joined = appendText(text.text, prev.text.slice(), 0, text.length);
150
+ if (joined.length <= 32) target.push(new TextLeaf(joined, prev.length + text.length));
151
+ else {
152
+ let mid = joined.length >> 1;
153
+ target.push(new TextLeaf(joined.slice(0, mid)), new TextLeaf(joined.slice(mid)));
154
+ }
155
+ } else target.push(text);
156
+ }
157
+ replace(from, to, text) {
158
+ if (!(text instanceof TextLeaf)) return super.replace(from, to, text);
159
+ [from, to] = clip(this, from, to);
160
+ let lines = appendText(this.text, appendText(text.text, sliceText(this.text, 0, from)), to);
161
+ let newLen = this.length + text.length - (to - from);
162
+ if (lines.length <= 32) return new TextLeaf(lines, newLen);
163
+ return TextNode.from(TextLeaf.split(lines, []), newLen);
164
+ }
165
+ sliceString(from, to = this.length, lineSep = "\n") {
166
+ [from, to] = clip(this, from, to);
167
+ let result = "";
168
+ for (let pos = 0, i = 0; pos <= to && i < this.text.length; i++) {
169
+ let line = this.text[i], end = pos + line.length;
170
+ if (pos > from && i) result += lineSep;
171
+ if (from < end && to > pos) result += line.slice(Math.max(0, from - pos), to - pos);
172
+ pos = end + 1;
173
+ }
174
+ return result;
175
+ }
176
+ flatten(target) {
177
+ for (let line of this.text) target.push(line);
178
+ }
179
+ scanIdentical() {
180
+ return 0;
181
+ }
182
+ static split(text, target) {
183
+ let part = [], len = -1;
184
+ for (let line of text) {
185
+ part.push(line);
186
+ len += line.length + 1;
187
+ if (part.length == 32) {
188
+ target.push(new TextLeaf(part, len));
189
+ part = [];
190
+ len = -1;
191
+ }
192
+ }
193
+ if (len > -1) target.push(new TextLeaf(part, len));
194
+ return target;
195
+ }
196
+ };
197
+ var TextNode = class TextNode extends Text {
198
+ constructor(children, length) {
199
+ super();
200
+ this.children = children;
201
+ this.length = length;
202
+ this.lines = 0;
203
+ for (let child of children) this.lines += child.lines;
204
+ }
205
+ lineInner(target, isLine, line, offset) {
206
+ for (let i = 0;; i++) {
207
+ let child = this.children[i], end = offset + child.length, endLine = line + child.lines - 1;
208
+ if ((isLine ? endLine : end) >= target) return child.lineInner(target, isLine, line, offset);
209
+ offset = end + 1;
210
+ line = endLine + 1;
211
+ }
212
+ }
213
+ decompose(from, to, target, open) {
214
+ for (let i = 0, pos = 0; pos <= to && i < this.children.length; i++) {
215
+ let child = this.children[i], end = pos + child.length;
216
+ if (from <= end && to >= pos) {
217
+ let childOpen = open & ((pos <= from ? 1 : 0) | (end >= to ? 2 : 0));
218
+ if (pos >= from && end <= to && !childOpen) target.push(child);
219
+ else child.decompose(from - pos, to - pos, target, childOpen);
220
+ }
221
+ pos = end + 1;
222
+ }
223
+ }
224
+ replace(from, to, text) {
225
+ [from, to] = clip(this, from, to);
226
+ if (text.lines < this.lines) for (let i = 0, pos = 0; i < this.children.length; i++) {
227
+ let child = this.children[i], end = pos + child.length;
228
+ if (from >= pos && to <= end) {
229
+ let updated = child.replace(from - pos, to - pos, text);
230
+ let totalLines = this.lines - child.lines + updated.lines;
231
+ if (updated.lines < totalLines >> 4 && updated.lines > totalLines >> 6) {
232
+ let copy = this.children.slice();
233
+ copy[i] = updated;
234
+ return new TextNode(copy, this.length - (to - from) + text.length);
235
+ }
236
+ return super.replace(pos, end, updated);
237
+ }
238
+ pos = end + 1;
239
+ }
240
+ return super.replace(from, to, text);
241
+ }
242
+ sliceString(from, to = this.length, lineSep = "\n") {
243
+ [from, to] = clip(this, from, to);
244
+ let result = "";
245
+ for (let i = 0, pos = 0; i < this.children.length && pos <= to; i++) {
246
+ let child = this.children[i], end = pos + child.length;
247
+ if (pos > from && i) result += lineSep;
248
+ if (from < end && to > pos) result += child.sliceString(from - pos, to - pos, lineSep);
249
+ pos = end + 1;
250
+ }
251
+ return result;
252
+ }
253
+ flatten(target) {
254
+ for (let child of this.children) child.flatten(target);
255
+ }
256
+ scanIdentical(other, dir) {
257
+ if (!(other instanceof TextNode)) return 0;
258
+ let length = 0;
259
+ let [iA, iB, eA, eB] = dir > 0 ? [
260
+ 0,
261
+ 0,
262
+ this.children.length,
263
+ other.children.length
264
+ ] : [
265
+ this.children.length - 1,
266
+ other.children.length - 1,
267
+ -1,
268
+ -1
269
+ ];
270
+ for (;; iA += dir, iB += dir) {
271
+ if (iA == eA || iB == eB) return length;
272
+ let chA = this.children[iA], chB = other.children[iB];
273
+ if (chA != chB) return length + chA.scanIdentical(chB, dir);
274
+ length += chA.length + 1;
275
+ }
276
+ }
277
+ static from(children, length = children.reduce((l, ch) => l + ch.length + 1, -1)) {
278
+ let lines = 0;
279
+ for (let ch of children) lines += ch.lines;
280
+ if (lines < 32) {
281
+ let flat = [];
282
+ for (let ch of children) ch.flatten(flat);
283
+ return new TextLeaf(flat, length);
284
+ }
285
+ let chunk = Math.max(32, lines >> 5), maxChunk = chunk << 1, minChunk = chunk >> 1;
286
+ let chunked = [], currentLines = 0, currentLen = -1, currentChunk = [];
287
+ function add(child) {
288
+ let last;
289
+ if (child.lines > maxChunk && child instanceof TextNode) for (let node of child.children) add(node);
290
+ else if (child.lines > minChunk && (currentLines > minChunk || !currentLines)) {
291
+ flush();
292
+ chunked.push(child);
293
+ } else if (child instanceof TextLeaf && currentLines && (last = currentChunk[currentChunk.length - 1]) instanceof TextLeaf && child.lines + last.lines <= 32) {
294
+ currentLines += child.lines;
295
+ currentLen += child.length + 1;
296
+ currentChunk[currentChunk.length - 1] = new TextLeaf(last.text.concat(child.text), last.length + 1 + child.length);
297
+ } else {
298
+ if (currentLines + child.lines > chunk) flush();
299
+ currentLines += child.lines;
300
+ currentLen += child.length + 1;
301
+ currentChunk.push(child);
302
+ }
303
+ }
304
+ function flush() {
305
+ if (currentLines == 0) return;
306
+ chunked.push(currentChunk.length == 1 ? currentChunk[0] : TextNode.from(currentChunk, currentLen));
307
+ currentLen = -1;
308
+ currentLines = currentChunk.length = 0;
309
+ }
310
+ for (let child of children) add(child);
311
+ flush();
312
+ return chunked.length == 1 ? chunked[0] : new TextNode(chunked, length);
313
+ }
314
+ };
315
+ Text.empty = /*@__PURE__*/ new TextLeaf([""], 0);
316
+ function textLength(text) {
317
+ let length = -1;
318
+ for (let line of text) length += line.length + 1;
319
+ return length;
320
+ }
321
+ function appendText(text, target, from = 0, to = 1e9) {
322
+ for (let pos = 0, i = 0, first = true; i < text.length && pos <= to; i++) {
323
+ let line = text[i], end = pos + line.length;
324
+ if (end >= from) {
325
+ if (end > to) line = line.slice(0, to - pos);
326
+ if (pos < from) line = line.slice(from - pos);
327
+ if (first) {
328
+ target[target.length - 1] += line;
329
+ first = false;
330
+ } else target.push(line);
331
+ }
332
+ pos = end + 1;
333
+ }
334
+ return target;
335
+ }
336
+ function sliceText(text, from, to) {
337
+ return appendText(text, [""], from, to);
338
+ }
339
+ var RawTextCursor = class {
340
+ constructor(text, dir = 1) {
341
+ this.dir = dir;
342
+ this.done = false;
343
+ this.lineBreak = false;
344
+ this.value = "";
345
+ this.nodes = [text];
346
+ this.offsets = [dir > 0 ? 1 : (text instanceof TextLeaf ? text.text.length : text.children.length) << 1];
347
+ }
348
+ nextInner(skip, dir) {
349
+ this.done = this.lineBreak = false;
350
+ for (;;) {
351
+ let last = this.nodes.length - 1;
352
+ let top = this.nodes[last], offsetValue = this.offsets[last], offset = offsetValue >> 1;
353
+ let size = top instanceof TextLeaf ? top.text.length : top.children.length;
354
+ if (offset == (dir > 0 ? size : 0)) {
355
+ if (last == 0) {
356
+ this.done = true;
357
+ this.value = "";
358
+ return this;
359
+ }
360
+ if (dir > 0) this.offsets[last - 1]++;
361
+ this.nodes.pop();
362
+ this.offsets.pop();
363
+ } else if ((offsetValue & 1) == (dir > 0 ? 0 : 1)) {
364
+ this.offsets[last] += dir;
365
+ if (skip == 0) {
366
+ this.lineBreak = true;
367
+ this.value = "\n";
368
+ return this;
369
+ }
370
+ skip--;
371
+ } else if (top instanceof TextLeaf) {
372
+ let next = top.text[offset + (dir < 0 ? -1 : 0)];
373
+ this.offsets[last] += dir;
374
+ if (next.length > Math.max(0, skip)) {
375
+ this.value = skip == 0 ? next : dir > 0 ? next.slice(skip) : next.slice(0, next.length - skip);
376
+ return this;
377
+ }
378
+ skip -= next.length;
379
+ } else {
380
+ let next = top.children[offset + (dir < 0 ? -1 : 0)];
381
+ if (skip > next.length) {
382
+ skip -= next.length;
383
+ this.offsets[last] += dir;
384
+ } else {
385
+ if (dir < 0) this.offsets[last]--;
386
+ this.nodes.push(next);
387
+ this.offsets.push(dir > 0 ? 1 : (next instanceof TextLeaf ? next.text.length : next.children.length) << 1);
388
+ }
389
+ }
390
+ }
391
+ }
392
+ next(skip = 0) {
393
+ if (skip < 0) {
394
+ this.nextInner(-skip, -this.dir);
395
+ skip = this.value.length;
396
+ }
397
+ return this.nextInner(skip, this.dir);
398
+ }
399
+ };
400
+ var PartialTextCursor = class {
401
+ constructor(text, start, end) {
402
+ this.value = "";
403
+ this.done = false;
404
+ this.cursor = new RawTextCursor(text, start > end ? -1 : 1);
405
+ this.pos = start > end ? text.length : 0;
406
+ this.from = Math.min(start, end);
407
+ this.to = Math.max(start, end);
408
+ }
409
+ nextInner(skip, dir) {
410
+ if (dir < 0 ? this.pos <= this.from : this.pos >= this.to) {
411
+ this.value = "";
412
+ this.done = true;
413
+ return this;
414
+ }
415
+ skip += Math.max(0, dir < 0 ? this.pos - this.to : this.from - this.pos);
416
+ let limit = dir < 0 ? this.pos - this.from : this.to - this.pos;
417
+ if (skip > limit) skip = limit;
418
+ limit -= skip;
419
+ let { value } = this.cursor.next(skip);
420
+ this.pos += (value.length + skip) * dir;
421
+ this.value = value.length <= limit ? value : dir < 0 ? value.slice(value.length - limit) : value.slice(0, limit);
422
+ this.done = !this.value;
423
+ return this;
424
+ }
425
+ next(skip = 0) {
426
+ if (skip < 0) skip = Math.max(skip, this.from - this.pos);
427
+ else if (skip > 0) skip = Math.min(skip, this.to - this.pos);
428
+ return this.nextInner(skip, this.cursor.dir);
429
+ }
430
+ get lineBreak() {
431
+ return this.cursor.lineBreak && this.value != "";
432
+ }
433
+ };
434
+ var LineCursor = class {
435
+ constructor(inner) {
436
+ this.inner = inner;
437
+ this.afterBreak = true;
438
+ this.value = "";
439
+ this.done = false;
440
+ }
441
+ next(skip = 0) {
442
+ let { done, lineBreak, value } = this.inner.next(skip);
443
+ if (done && this.afterBreak) {
444
+ this.value = "";
445
+ this.afterBreak = false;
446
+ } else if (done) {
447
+ this.done = true;
448
+ this.value = "";
449
+ } else if (lineBreak) if (this.afterBreak) this.value = "";
450
+ else {
451
+ this.afterBreak = true;
452
+ this.next();
453
+ }
454
+ else {
455
+ this.value = value;
456
+ this.afterBreak = false;
457
+ }
458
+ return this;
459
+ }
460
+ get lineBreak() {
461
+ return false;
462
+ }
463
+ };
464
+ if (typeof Symbol != "undefined") {
465
+ Text.prototype[Symbol.iterator] = function() {
466
+ return this.iter();
467
+ };
468
+ RawTextCursor.prototype[Symbol.iterator] = PartialTextCursor.prototype[Symbol.iterator] = LineCursor.prototype[Symbol.iterator] = function() {
469
+ return this;
470
+ };
471
+ }
472
+ /**
473
+ This type describes a line in the document. It is created
474
+ on-demand when lines are [queried](https://codemirror.net/6/docs/ref/#state.Text.lineAt).
475
+ */
476
+ var Line = class {
477
+ /**
478
+ @internal
479
+ */
480
+ constructor(from, to, number, text) {
481
+ this.from = from;
482
+ this.to = to;
483
+ this.number = number;
484
+ this.text = text;
485
+ }
486
+ /**
487
+ The length of the line (not including any line break after it).
488
+ */
489
+ get length() {
490
+ return this.to - this.from;
491
+ }
492
+ };
493
+ function clip(text, from, to) {
494
+ from = Math.max(0, Math.min(text.length, from));
495
+ return [from, Math.max(from, Math.min(text.length, to))];
496
+ }
497
+ /**
498
+ Returns a next grapheme cluster break _after_ (not equal to)
499
+ `pos`, if `forward` is true, or before otherwise. Returns `pos`
500
+ itself if no further cluster break is available in the string.
501
+ Moves across surrogate pairs, extending characters (when
502
+ `includeExtending` is true), characters joined with zero-width
503
+ joiners, and flag emoji.
504
+ */
505
+ function findClusterBreak(str, pos, forward = true, includeExtending = true) {
506
+ return findClusterBreak$1(str, pos, forward, includeExtending);
507
+ }
508
+ function surrogateLow(ch) {
509
+ return ch >= 56320 && ch < 57344;
510
+ }
511
+ function surrogateHigh(ch) {
512
+ return ch >= 55296 && ch < 56320;
513
+ }
514
+ /**
515
+ Find the code point at the given position in a string (like the
516
+ [`codePointAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
517
+ string method).
518
+ */
519
+ function codePointAt(str, pos) {
520
+ let code0 = str.charCodeAt(pos);
521
+ if (!surrogateHigh(code0) || pos + 1 == str.length) return code0;
522
+ let code1 = str.charCodeAt(pos + 1);
523
+ if (!surrogateLow(code1)) return code0;
524
+ return (code0 - 55296 << 10) + (code1 - 56320) + 65536;
525
+ }
526
+ /**
527
+ Given a Unicode codepoint, return the JavaScript string that
528
+ respresents it (like
529
+ [`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)).
530
+ */
531
+ function fromCodePoint(code) {
532
+ if (code <= 65535) return String.fromCharCode(code);
533
+ code -= 65536;
534
+ return String.fromCharCode((code >> 10) + 55296, (code & 1023) + 56320);
535
+ }
536
+ /**
537
+ The amount of positions a character takes up in a JavaScript string.
538
+ */
539
+ function codePointSize(code) {
540
+ return code < 65536 ? 1 : 2;
541
+ }
542
+ const DefaultSplit = /\r\n?|\n/;
543
+ /**
544
+ Distinguishes different ways in which positions can be mapped.
545
+ */
546
+ var MapMode = /*@__PURE__*/ (function(MapMode) {
547
+ /**
548
+ Map a position to a valid new position, even when its context
549
+ was deleted.
550
+ */
551
+ MapMode[MapMode["Simple"] = 0] = "Simple";
552
+ /**
553
+ Return null if deletion happens across the position.
554
+ */
555
+ MapMode[MapMode["TrackDel"] = 1] = "TrackDel";
556
+ /**
557
+ Return null if the character _before_ the position is deleted.
558
+ */
559
+ MapMode[MapMode["TrackBefore"] = 2] = "TrackBefore";
560
+ /**
561
+ Return null if the character _after_ the position is deleted.
562
+ */
563
+ MapMode[MapMode["TrackAfter"] = 3] = "TrackAfter";
564
+ return MapMode;
565
+ })(MapMode || (MapMode = {}));
566
+ /**
567
+ A change description is a variant of [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet)
568
+ that doesn't store the inserted text. As such, it can't be
569
+ applied, but is cheaper to store and manipulate.
570
+ */
571
+ var ChangeDesc = class ChangeDesc {
572
+ /**
573
+ @internal
574
+ */
575
+ constructor(sections) {
576
+ this.sections = sections;
577
+ }
578
+ /**
579
+ The length of the document before the change.
580
+ */
581
+ get length() {
582
+ let result = 0;
583
+ for (let i = 0; i < this.sections.length; i += 2) result += this.sections[i];
584
+ return result;
585
+ }
586
+ /**
587
+ The length of the document after the change.
588
+ */
589
+ get newLength() {
590
+ let result = 0;
591
+ for (let i = 0; i < this.sections.length; i += 2) {
592
+ let ins = this.sections[i + 1];
593
+ result += ins < 0 ? this.sections[i] : ins;
594
+ }
595
+ return result;
596
+ }
597
+ /**
598
+ False when there are actual changes in this set.
599
+ */
600
+ get empty() {
601
+ return this.sections.length == 0 || this.sections.length == 2 && this.sections[1] < 0;
602
+ }
603
+ /**
604
+ Iterate over the unchanged parts left by these changes. `posA`
605
+ provides the position of the range in the old document, `posB`
606
+ the new position in the changed document.
607
+ */
608
+ iterGaps(f) {
609
+ for (let i = 0, posA = 0, posB = 0; i < this.sections.length;) {
610
+ let len = this.sections[i++], ins = this.sections[i++];
611
+ if (ins < 0) {
612
+ f(posA, posB, len);
613
+ posB += len;
614
+ } else posB += ins;
615
+ posA += len;
616
+ }
617
+ }
618
+ /**
619
+ Iterate over the ranges changed by these changes. (See
620
+ [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
621
+ variant that also provides you with the inserted text.)
622
+ `fromA`/`toA` provides the extent of the change in the starting
623
+ document, `fromB`/`toB` the extent of the replacement in the
624
+ changed document.
625
+
626
+ When `individual` is true, adjacent changes (which are kept
627
+ separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
628
+ reported separately.
629
+ */
630
+ iterChangedRanges(f, individual = false) {
631
+ iterChanges(this, f, individual);
632
+ }
633
+ /**
634
+ Get a description of the inverted form of these changes.
635
+ */
636
+ get invertedDesc() {
637
+ let sections = [];
638
+ for (let i = 0; i < this.sections.length;) {
639
+ let len = this.sections[i++], ins = this.sections[i++];
640
+ if (ins < 0) sections.push(len, ins);
641
+ else sections.push(ins, len);
642
+ }
643
+ return new ChangeDesc(sections);
644
+ }
645
+ /**
646
+ Compute the combined effect of applying another set of changes
647
+ after this one. The length of the document after this set should
648
+ match the length before `other`.
649
+ */
650
+ composeDesc(other) {
651
+ return this.empty ? other : other.empty ? this : composeSets(this, other);
652
+ }
653
+ /**
654
+ Map this description, which should start with the same document
655
+ as `other`, over another set of changes, so that it can be
656
+ applied after it. When `before` is true, map as if the changes
657
+ in `this` happened before the ones in `other`.
658
+ */
659
+ mapDesc(other, before = false) {
660
+ return other.empty ? this : mapSet(this, other, before);
661
+ }
662
+ mapPos(pos, assoc = -1, mode = MapMode.Simple) {
663
+ let posA = 0, posB = 0;
664
+ for (let i = 0; i < this.sections.length;) {
665
+ let len = this.sections[i++], ins = this.sections[i++], endA = posA + len;
666
+ if (ins < 0) {
667
+ if (endA > pos) return posB + (pos - posA);
668
+ posB += len;
669
+ } else {
670
+ if (mode != MapMode.Simple && endA >= pos && (mode == MapMode.TrackDel && posA < pos && endA > pos || mode == MapMode.TrackBefore && posA < pos || mode == MapMode.TrackAfter && endA > pos)) return null;
671
+ if (endA > pos || endA == pos && assoc < 0 && !len) return pos == posA || assoc < 0 ? posB : posB + ins;
672
+ posB += ins;
673
+ }
674
+ posA = endA;
675
+ }
676
+ if (pos > posA) throw new RangeError(`Position ${pos} is out of range for changeset of length ${posA}`);
677
+ return posB;
678
+ }
679
+ /**
680
+ Check whether these changes touch a given range. When one of the
681
+ changes entirely covers the range, the string `"cover"` is
682
+ returned.
683
+ */
684
+ touchesRange(from, to = from) {
685
+ for (let i = 0, pos = 0; i < this.sections.length && pos <= to;) {
686
+ let len = this.sections[i++], ins = this.sections[i++], end = pos + len;
687
+ if (ins >= 0 && pos <= to && end >= from) return pos < from && end > to ? "cover" : true;
688
+ pos = end;
689
+ }
690
+ return false;
691
+ }
692
+ /**
693
+ @internal
694
+ */
695
+ toString() {
696
+ let result = "";
697
+ for (let i = 0; i < this.sections.length;) {
698
+ let len = this.sections[i++], ins = this.sections[i++];
699
+ result += (result ? " " : "") + len + (ins >= 0 ? ":" + ins : "");
700
+ }
701
+ return result;
702
+ }
703
+ /**
704
+ Serialize this change desc to a JSON-representable value.
705
+ */
706
+ toJSON() {
707
+ return this.sections;
708
+ }
709
+ /**
710
+ Create a change desc from its JSON representation (as produced
711
+ by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).
712
+ */
713
+ static fromJSON(json) {
714
+ if (!Array.isArray(json) || json.length % 2 || json.some((a) => typeof a != "number")) throw new RangeError("Invalid JSON representation of ChangeDesc");
715
+ return new ChangeDesc(json);
716
+ }
717
+ /**
718
+ @internal
719
+ */
720
+ static create(sections) {
721
+ return new ChangeDesc(sections);
722
+ }
723
+ };
724
+ /**
725
+ A change set represents a group of modifications to a document. It
726
+ stores the document length, and can only be applied to documents
727
+ with exactly that length.
728
+ */
729
+ var ChangeSet = class ChangeSet extends ChangeDesc {
730
+ constructor(sections, inserted) {
731
+ super(sections);
732
+ this.inserted = inserted;
733
+ }
734
+ /**
735
+ Apply the changes to a document, returning the modified
736
+ document.
737
+ */
738
+ apply(doc) {
739
+ if (this.length != doc.length) throw new RangeError("Applying change set to a document with the wrong length");
740
+ iterChanges(this, (fromA, toA, fromB, _toB, text) => doc = doc.replace(fromB, fromB + (toA - fromA), text), false);
741
+ return doc;
742
+ }
743
+ mapDesc(other, before = false) {
744
+ return mapSet(this, other, before, true);
745
+ }
746
+ /**
747
+ Given the document as it existed _before_ the changes, return a
748
+ change set that represents the inverse of this set, which could
749
+ be used to go from the document created by the changes back to
750
+ the document as it existed before the changes.
751
+ */
752
+ invert(doc) {
753
+ let sections = this.sections.slice(), inserted = [];
754
+ for (let i = 0, pos = 0; i < sections.length; i += 2) {
755
+ let len = sections[i], ins = sections[i + 1];
756
+ if (ins >= 0) {
757
+ sections[i] = ins;
758
+ sections[i + 1] = len;
759
+ let index = i >> 1;
760
+ while (inserted.length < index) inserted.push(Text.empty);
761
+ inserted.push(len ? doc.slice(pos, pos + len) : Text.empty);
762
+ }
763
+ pos += len;
764
+ }
765
+ return new ChangeSet(sections, inserted);
766
+ }
767
+ /**
768
+ Combine two subsequent change sets into a single set. `other`
769
+ must start in the document produced by `this`. If `this` goes
770
+ `docA` → `docB` and `other` represents `docB` → `docC`, the
771
+ returned value will represent the change `docA` → `docC`.
772
+ */
773
+ compose(other) {
774
+ return this.empty ? other : other.empty ? this : composeSets(this, other, true);
775
+ }
776
+ /**
777
+ Given another change set starting in the same document, maps this
778
+ change set over the other, producing a new change set that can be
779
+ applied to the document produced by applying `other`. When
780
+ `before` is `true`, order changes as if `this` comes before
781
+ `other`, otherwise (the default) treat `other` as coming first.
782
+
783
+ Given two changes `A` and `B`, `A.compose(B.map(A))` and
784
+ `B.compose(A.map(B, true))` will produce the same document. This
785
+ provides a basic form of [operational
786
+ transformation](https://en.wikipedia.org/wiki/Operational_transformation),
787
+ and can be used for collaborative editing.
788
+ */
789
+ map(other, before = false) {
790
+ return other.empty ? this : mapSet(this, other, before, true);
791
+ }
792
+ /**
793
+ Iterate over the changed ranges in the document, calling `f` for
794
+ each, with the range in the original document (`fromA`-`toA`)
795
+ and the range that replaces it in the new document
796
+ (`fromB`-`toB`).
797
+
798
+ When `individual` is true, adjacent changes are reported
799
+ separately.
800
+ */
801
+ iterChanges(f, individual = false) {
802
+ iterChanges(this, f, individual);
803
+ }
804
+ /**
805
+ Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
806
+ set.
807
+ */
808
+ get desc() {
809
+ return ChangeDesc.create(this.sections);
810
+ }
811
+ /**
812
+ @internal
813
+ */
814
+ filter(ranges) {
815
+ let resultSections = [], resultInserted = [], filteredSections = [];
816
+ let iter = new SectionIter(this);
817
+ done: for (let i = 0, pos = 0;;) {
818
+ let next = i == ranges.length ? 1e9 : ranges[i++];
819
+ while (pos < next || pos == next && iter.len == 0) {
820
+ if (iter.done) break done;
821
+ let len = Math.min(iter.len, next - pos);
822
+ addSection(filteredSections, len, -1);
823
+ let ins = iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0;
824
+ addSection(resultSections, len, ins);
825
+ if (ins > 0) addInsert(resultInserted, resultSections, iter.text);
826
+ iter.forward(len);
827
+ pos += len;
828
+ }
829
+ let end = ranges[i++];
830
+ while (pos < end) {
831
+ if (iter.done) break done;
832
+ let len = Math.min(iter.len, end - pos);
833
+ addSection(resultSections, len, -1);
834
+ addSection(filteredSections, len, iter.ins == -1 ? -1 : iter.off == 0 ? iter.ins : 0);
835
+ iter.forward(len);
836
+ pos += len;
837
+ }
838
+ }
839
+ return {
840
+ changes: new ChangeSet(resultSections, resultInserted),
841
+ filtered: ChangeDesc.create(filteredSections)
842
+ };
843
+ }
844
+ /**
845
+ Serialize this change set to a JSON-representable value.
846
+ */
847
+ toJSON() {
848
+ let parts = [];
849
+ for (let i = 0; i < this.sections.length; i += 2) {
850
+ let len = this.sections[i], ins = this.sections[i + 1];
851
+ if (ins < 0) parts.push(len);
852
+ else if (ins == 0) parts.push([len]);
853
+ else parts.push([len].concat(this.inserted[i >> 1].toJSON()));
854
+ }
855
+ return parts;
856
+ }
857
+ /**
858
+ Create a change set for the given changes, for a document of the
859
+ given length, using `lineSep` as line separator.
860
+ */
861
+ static of(changes, length, lineSep) {
862
+ let sections = [], inserted = [], pos = 0;
863
+ let total = null;
864
+ function flush(force = false) {
865
+ if (!force && !sections.length) return;
866
+ if (pos < length) addSection(sections, length - pos, -1);
867
+ let set = new ChangeSet(sections, inserted);
868
+ total = total ? total.compose(set.map(total)) : set;
869
+ sections = [];
870
+ inserted = [];
871
+ pos = 0;
872
+ }
873
+ function process(spec) {
874
+ if (Array.isArray(spec)) for (let sub of spec) process(sub);
875
+ else if (spec instanceof ChangeSet) {
876
+ if (spec.length != length) throw new RangeError(`Mismatched change set length (got ${spec.length}, expected ${length})`);
877
+ flush();
878
+ total = total ? total.compose(spec.map(total)) : spec;
879
+ } else {
880
+ let { from, to = from, insert } = spec;
881
+ if (from > to || from < 0 || to > length) throw new RangeError(`Invalid change range ${from} to ${to} (in doc of length ${length})`);
882
+ let insText = !insert ? Text.empty : typeof insert == "string" ? Text.of(insert.split(lineSep || DefaultSplit)) : insert;
883
+ let insLen = insText.length;
884
+ if (from == to && insLen == 0) return;
885
+ if (from < pos) flush();
886
+ if (from > pos) addSection(sections, from - pos, -1);
887
+ addSection(sections, to - from, insLen);
888
+ addInsert(inserted, sections, insText);
889
+ pos = to;
890
+ }
891
+ }
892
+ process(changes);
893
+ flush(!total);
894
+ return total;
895
+ }
896
+ /**
897
+ Create an empty changeset of the given length.
898
+ */
899
+ static empty(length) {
900
+ return new ChangeSet(length ? [length, -1] : [], []);
901
+ }
902
+ /**
903
+ Create a changeset from its JSON representation (as produced by
904
+ [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
905
+ */
906
+ static fromJSON(json) {
907
+ if (!Array.isArray(json)) throw new RangeError("Invalid JSON representation of ChangeSet");
908
+ let sections = [], inserted = [];
909
+ for (let i = 0; i < json.length; i++) {
910
+ let part = json[i];
911
+ if (typeof part == "number") sections.push(part, -1);
912
+ else if (!Array.isArray(part) || typeof part[0] != "number" || part.some((e, i) => i && typeof e != "string")) throw new RangeError("Invalid JSON representation of ChangeSet");
913
+ else if (part.length == 1) sections.push(part[0], 0);
914
+ else {
915
+ while (inserted.length < i) inserted.push(Text.empty);
916
+ inserted[i] = Text.of(part.slice(1));
917
+ sections.push(part[0], inserted[i].length);
918
+ }
919
+ }
920
+ return new ChangeSet(sections, inserted);
921
+ }
922
+ /**
923
+ @internal
924
+ */
925
+ static createSet(sections, inserted) {
926
+ return new ChangeSet(sections, inserted);
927
+ }
928
+ };
929
+ function addSection(sections, len, ins, forceJoin = false) {
930
+ if (len == 0 && ins <= 0) return;
931
+ let last = sections.length - 2;
932
+ if (last >= 0 && ins <= 0 && ins == sections[last + 1]) sections[last] += len;
933
+ else if (last >= 0 && len == 0 && sections[last] == 0) sections[last + 1] += ins;
934
+ else if (forceJoin) {
935
+ sections[last] += len;
936
+ sections[last + 1] += ins;
937
+ } else sections.push(len, ins);
938
+ }
939
+ function addInsert(values, sections, value) {
940
+ if (value.length == 0) return;
941
+ let index = sections.length - 2 >> 1;
942
+ if (index < values.length) values[values.length - 1] = values[values.length - 1].append(value);
943
+ else {
944
+ while (values.length < index) values.push(Text.empty);
945
+ values.push(value);
946
+ }
947
+ }
948
+ function iterChanges(desc, f, individual) {
949
+ let inserted = desc.inserted;
950
+ for (let posA = 0, posB = 0, i = 0; i < desc.sections.length;) {
951
+ let len = desc.sections[i++], ins = desc.sections[i++];
952
+ if (ins < 0) {
953
+ posA += len;
954
+ posB += len;
955
+ } else {
956
+ let endA = posA, endB = posB, text = Text.empty;
957
+ for (;;) {
958
+ endA += len;
959
+ endB += ins;
960
+ if (ins && inserted) text = text.append(inserted[i - 2 >> 1]);
961
+ if (individual || i == desc.sections.length || desc.sections[i + 1] < 0) break;
962
+ len = desc.sections[i++];
963
+ ins = desc.sections[i++];
964
+ }
965
+ f(posA, endA, posB, endB, text);
966
+ posA = endA;
967
+ posB = endB;
968
+ }
969
+ }
970
+ }
971
+ function mapSet(setA, setB, before, mkSet = false) {
972
+ let sections = [], insert = mkSet ? [] : null;
973
+ let a = new SectionIter(setA), b = new SectionIter(setB);
974
+ for (let inserted = -1;;) if (a.done && b.len || b.done && a.len) throw new Error("Mismatched change set lengths");
975
+ else if (a.ins == -1 && b.ins == -1) {
976
+ let len = Math.min(a.len, b.len);
977
+ addSection(sections, len, -1);
978
+ a.forward(len);
979
+ b.forward(len);
980
+ } else if (b.ins >= 0 && (a.ins < 0 || inserted == a.i || a.off == 0 && (b.len < a.len || b.len == a.len && !before))) {
981
+ let len = b.len;
982
+ addSection(sections, b.ins, -1);
983
+ while (len) {
984
+ let piece = Math.min(a.len, len);
985
+ if (a.ins >= 0 && inserted < a.i && a.len <= piece) {
986
+ addSection(sections, 0, a.ins);
987
+ if (insert) addInsert(insert, sections, a.text);
988
+ inserted = a.i;
989
+ }
990
+ a.forward(piece);
991
+ len -= piece;
992
+ }
993
+ b.next();
994
+ } else if (a.ins >= 0) {
995
+ let len = 0, left = a.len;
996
+ while (left) if (b.ins == -1) {
997
+ let piece = Math.min(left, b.len);
998
+ len += piece;
999
+ left -= piece;
1000
+ b.forward(piece);
1001
+ } else if (b.ins == 0 && b.len < left) {
1002
+ left -= b.len;
1003
+ b.next();
1004
+ } else break;
1005
+ addSection(sections, len, inserted < a.i ? a.ins : 0);
1006
+ if (insert && inserted < a.i) addInsert(insert, sections, a.text);
1007
+ inserted = a.i;
1008
+ a.forward(a.len - left);
1009
+ } else if (a.done && b.done) return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);
1010
+ else throw new Error("Mismatched change set lengths");
1011
+ }
1012
+ function composeSets(setA, setB, mkSet = false) {
1013
+ let sections = [];
1014
+ let insert = mkSet ? [] : null;
1015
+ let a = new SectionIter(setA), b = new SectionIter(setB);
1016
+ for (let open = false;;) if (a.done && b.done) return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);
1017
+ else if (a.ins == 0) {
1018
+ addSection(sections, a.len, 0, open);
1019
+ a.next();
1020
+ } else if (b.len == 0 && !b.done) {
1021
+ addSection(sections, 0, b.ins, open);
1022
+ if (insert) addInsert(insert, sections, b.text);
1023
+ b.next();
1024
+ } else if (a.done || b.done) throw new Error("Mismatched change set lengths");
1025
+ else {
1026
+ let len = Math.min(a.len2, b.len), sectionLen = sections.length;
1027
+ if (a.ins == -1) {
1028
+ let insB = b.ins == -1 ? -1 : b.off ? 0 : b.ins;
1029
+ addSection(sections, len, insB, open);
1030
+ if (insert && insB) addInsert(insert, sections, b.text);
1031
+ } else if (b.ins == -1) {
1032
+ addSection(sections, a.off ? 0 : a.len, len, open);
1033
+ if (insert) addInsert(insert, sections, a.textBit(len));
1034
+ } else {
1035
+ addSection(sections, a.off ? 0 : a.len, b.off ? 0 : b.ins, open);
1036
+ if (insert && !b.off) addInsert(insert, sections, b.text);
1037
+ }
1038
+ open = (a.ins > len || b.ins >= 0 && b.len > len) && (open || sections.length > sectionLen);
1039
+ a.forward2(len);
1040
+ b.forward(len);
1041
+ }
1042
+ }
1043
+ var SectionIter = class {
1044
+ constructor(set) {
1045
+ this.set = set;
1046
+ this.i = 0;
1047
+ this.next();
1048
+ }
1049
+ next() {
1050
+ let { sections } = this.set;
1051
+ if (this.i < sections.length) {
1052
+ this.len = sections[this.i++];
1053
+ this.ins = sections[this.i++];
1054
+ } else {
1055
+ this.len = 0;
1056
+ this.ins = -2;
1057
+ }
1058
+ this.off = 0;
1059
+ }
1060
+ get done() {
1061
+ return this.ins == -2;
1062
+ }
1063
+ get len2() {
1064
+ return this.ins < 0 ? this.len : this.ins;
1065
+ }
1066
+ get text() {
1067
+ let { inserted } = this.set, index = this.i - 2 >> 1;
1068
+ return index >= inserted.length ? Text.empty : inserted[index];
1069
+ }
1070
+ textBit(len) {
1071
+ let { inserted } = this.set, index = this.i - 2 >> 1;
1072
+ return index >= inserted.length && !len ? Text.empty : inserted[index].slice(this.off, len == null ? void 0 : this.off + len);
1073
+ }
1074
+ forward(len) {
1075
+ if (len == this.len) this.next();
1076
+ else {
1077
+ this.len -= len;
1078
+ this.off += len;
1079
+ }
1080
+ }
1081
+ forward2(len) {
1082
+ if (this.ins == -1) this.forward(len);
1083
+ else if (len == this.ins) this.next();
1084
+ else {
1085
+ this.ins -= len;
1086
+ this.off += len;
1087
+ }
1088
+ }
1089
+ };
1090
+ /**
1091
+ A single selection range. When
1092
+ [`allowMultipleSelections`](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
1093
+ is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelection) may hold
1094
+ multiple ranges. By default, selections hold exactly one range.
1095
+ */
1096
+ var SelectionRange = class SelectionRange {
1097
+ constructor(from, to, flags, goalColumn) {
1098
+ this.from = from;
1099
+ this.to = to;
1100
+ this.flags = flags;
1101
+ this.goalColumn = goalColumn;
1102
+ }
1103
+ /**
1104
+ The anchor of the range—the side that doesn't move when you
1105
+ extend it.
1106
+ */
1107
+ get anchor() {
1108
+ return this.flags & 32 ? this.to : this.from;
1109
+ }
1110
+ /**
1111
+ The head of the range, which is moved when the range is
1112
+ [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
1113
+ */
1114
+ get head() {
1115
+ return this.flags & 32 ? this.from : this.to;
1116
+ }
1117
+ /**
1118
+ True when `anchor` and `head` are at the same position.
1119
+ */
1120
+ get empty() {
1121
+ return this.from == this.to;
1122
+ }
1123
+ /**
1124
+ If this is a cursor that is explicitly associated with the
1125
+ character on one of its sides, this returns the side. -1 means
1126
+ the character before its position, 1 the character after, and 0
1127
+ means no association.
1128
+ */
1129
+ get assoc() {
1130
+ return this.flags & 8 ? -1 : this.flags & 16 ? 1 : 0;
1131
+ }
1132
+ /**
1133
+ A flag that, when set, makes some selection-extending commands
1134
+ treat the range's head and anchor as exchangeable, so that for
1135
+ example Shift-ArrowUp will make the lower side of the selection
1136
+ the anchor, even if that was the head before. Used to implement
1137
+ MacOS-style undirectional selections.
1138
+ */
1139
+ get undirectional() {
1140
+ return (this.flags & 64) > 0;
1141
+ }
1142
+ /**
1143
+ The bidirectional text level associated with this cursor, if
1144
+ any.
1145
+ */
1146
+ get bidiLevel() {
1147
+ let level = this.flags & 7;
1148
+ return level == 7 ? null : level;
1149
+ }
1150
+ /**
1151
+ Map this range through a change, producing a valid range in the
1152
+ updated document.
1153
+ */
1154
+ map(change, assoc = -1) {
1155
+ let from, to;
1156
+ if (this.empty) from = to = change.mapPos(this.from, assoc);
1157
+ else {
1158
+ from = change.mapPos(this.from, 1);
1159
+ to = change.mapPos(this.to, -1);
1160
+ }
1161
+ return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags, this.goalColumn);
1162
+ }
1163
+ /**
1164
+ Extend this range to cover at least `from` to `to`.
1165
+ */
1166
+ extend(from, to = from, assoc = 0) {
1167
+ if (from <= this.anchor && to >= this.anchor) return EditorSelection.range(from, to, void 0, void 0, assoc);
1168
+ let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
1169
+ return EditorSelection.range(this.anchor, head, void 0, void 0, assoc);
1170
+ }
1171
+ /**
1172
+ Compare this range to another range.
1173
+ */
1174
+ eq(other, includeAssoc = false) {
1175
+ return this.anchor == other.anchor && this.head == other.head && this.goalColumn == other.goalColumn && (!includeAssoc || !this.empty || this.assoc == other.assoc);
1176
+ }
1177
+ /**
1178
+ Return a JSON-serializable object representing the range.
1179
+ */
1180
+ toJSON() {
1181
+ return {
1182
+ anchor: this.anchor,
1183
+ head: this.head
1184
+ };
1185
+ }
1186
+ /**
1187
+ Convert a JSON representation of a range to a `SelectionRange`
1188
+ instance.
1189
+ */
1190
+ static fromJSON(json) {
1191
+ if (!json || typeof json.anchor != "number" || typeof json.head != "number") throw new RangeError("Invalid JSON representation for SelectionRange");
1192
+ return EditorSelection.range(json.anchor, json.head);
1193
+ }
1194
+ /**
1195
+ @internal
1196
+ */
1197
+ static create(from, to, flags, goalColumn) {
1198
+ return new SelectionRange(from, to, flags, goalColumn);
1199
+ }
1200
+ };
1201
+ /**
1202
+ An editor selection holds one or more selection ranges.
1203
+ */
1204
+ var EditorSelection = class EditorSelection {
1205
+ constructor(ranges, mainIndex) {
1206
+ this.ranges = ranges;
1207
+ this.mainIndex = mainIndex;
1208
+ }
1209
+ /**
1210
+ Map a selection through a change. Used to adjust the selection
1211
+ position for changes.
1212
+ */
1213
+ map(change, assoc = -1) {
1214
+ if (change.empty) return this;
1215
+ return EditorSelection.create(this.ranges.map((r) => r.map(change, assoc)), this.mainIndex);
1216
+ }
1217
+ /**
1218
+ Compare this selection to another selection. By default, ranges
1219
+ are compared only by position. When `includeAssoc` is true,
1220
+ cursor ranges must also have the same
1221
+ [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
1222
+ */
1223
+ eq(other, includeAssoc = false) {
1224
+ if (this.ranges.length != other.ranges.length || this.mainIndex != other.mainIndex) return false;
1225
+ for (let i = 0; i < this.ranges.length; i++) if (!this.ranges[i].eq(other.ranges[i], includeAssoc)) return false;
1226
+ return true;
1227
+ }
1228
+ /**
1229
+ Get the primary selection range. Usually, you should make sure
1230
+ your code applies to _all_ ranges, by using methods like
1231
+ [`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).
1232
+ */
1233
+ get main() {
1234
+ return this.ranges[this.mainIndex];
1235
+ }
1236
+ /**
1237
+ Make sure the selection only has one range. Returns a selection
1238
+ holding only the main range from this selection.
1239
+ */
1240
+ asSingle() {
1241
+ return this.ranges.length == 1 ? this : new EditorSelection([this.main], 0);
1242
+ }
1243
+ /**
1244
+ Extend this selection with an extra range.
1245
+ */
1246
+ addRange(range, main = true) {
1247
+ return EditorSelection.create([range].concat(this.ranges), main ? 0 : this.mainIndex + 1);
1248
+ }
1249
+ /**
1250
+ Replace a given range with another range, and then normalize the
1251
+ selection to merge and sort ranges if necessary.
1252
+ */
1253
+ replaceRange(range, which = this.mainIndex) {
1254
+ let ranges = this.ranges.slice();
1255
+ ranges[which] = range;
1256
+ return EditorSelection.create(ranges, this.mainIndex);
1257
+ }
1258
+ /**
1259
+ Convert this selection to an object that can be serialized to
1260
+ JSON.
1261
+ */
1262
+ toJSON() {
1263
+ return {
1264
+ ranges: this.ranges.map((r) => r.toJSON()),
1265
+ main: this.mainIndex
1266
+ };
1267
+ }
1268
+ /**
1269
+ Create a selection from a JSON representation.
1270
+ */
1271
+ static fromJSON(json) {
1272
+ if (!json || !Array.isArray(json.ranges) || typeof json.main != "number" || json.main >= json.ranges.length) throw new RangeError("Invalid JSON representation for EditorSelection");
1273
+ return new EditorSelection(json.ranges.map((r) => SelectionRange.fromJSON(r)), json.main);
1274
+ }
1275
+ /**
1276
+ Create a selection holding a single range.
1277
+ */
1278
+ static single(anchor, head = anchor) {
1279
+ return new EditorSelection([EditorSelection.range(anchor, head)], 0);
1280
+ }
1281
+ /**
1282
+ Sort and merge the given set of ranges, creating a valid
1283
+ selection.
1284
+ */
1285
+ static create(ranges, mainIndex = 0) {
1286
+ if (ranges.length == 0) throw new RangeError("A selection needs at least one range");
1287
+ for (let pos = 0, i = 0; i < ranges.length; i++) {
1288
+ let range = ranges[i];
1289
+ if (range.empty ? range.from <= pos : range.from < pos) return EditorSelection.normalized(ranges.slice(), mainIndex);
1290
+ pos = range.to;
1291
+ }
1292
+ return new EditorSelection(ranges, mainIndex);
1293
+ }
1294
+ /**
1295
+ Create a cursor selection range at the given position. You can
1296
+ safely ignore the optional arguments in most situations.
1297
+ */
1298
+ static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
1299
+ return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 : 16) | (bidiLevel == null ? 7 : Math.min(6, bidiLevel)), goalColumn);
1300
+ }
1301
+ /**
1302
+ Create a selection range.
1303
+ */
1304
+ static range(anchor, head, goalColumn, bidiLevel, assoc) {
1305
+ let flags = bidiLevel == null ? 7 : Math.min(6, bidiLevel);
1306
+ if (!assoc && anchor != head) assoc = head < anchor ? 1 : -1;
1307
+ if (assoc) flags |= assoc < 0 ? 8 : 16;
1308
+ return head < anchor ? SelectionRange.create(head, anchor, flags | 32, goalColumn) : SelectionRange.create(anchor, head, flags, goalColumn);
1309
+ }
1310
+ /**
1311
+ Create an [undirectional](https://codemirror.net/6/docs/ref/#state.SelectionRange.undirectional)
1312
+ selection range.
1313
+ */
1314
+ static undirectionalRange(from, to) {
1315
+ return SelectionRange.create(from, to, 64, void 0);
1316
+ }
1317
+ /**
1318
+ @internal
1319
+ */
1320
+ static normalized(ranges, mainIndex = 0) {
1321
+ let main = ranges[mainIndex];
1322
+ ranges.sort((a, b) => a.from - b.from);
1323
+ mainIndex = ranges.indexOf(main);
1324
+ for (let i = 1; i < ranges.length; i++) {
1325
+ let range = ranges[i], prev = ranges[i - 1];
1326
+ if (range.empty ? range.from <= prev.to : range.from < prev.to) {
1327
+ let from = prev.from, to = Math.max(range.to, prev.to);
1328
+ if (i <= mainIndex) mainIndex--;
1329
+ ranges.splice(--i, 2, range.anchor > range.head ? EditorSelection.range(to, from) : EditorSelection.range(from, to));
1330
+ }
1331
+ }
1332
+ return new EditorSelection(ranges, mainIndex);
1333
+ }
1334
+ };
1335
+ function checkSelection(selection, docLength) {
1336
+ for (let range of selection.ranges) if (range.to > docLength) throw new RangeError("Selection points outside of document");
1337
+ }
1338
+ let nextID = 0;
1339
+ /**
1340
+ A facet is a labeled value that is associated with an editor
1341
+ state. It takes inputs from any number of extensions, and combines
1342
+ those into a single output value.
1343
+
1344
+ Examples of uses of facets are the [tab
1345
+ size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
1346
+ attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
1347
+ listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
1348
+
1349
+ Note that `Facet` instances can be used anywhere where
1350
+ [`FacetReader`](https://codemirror.net/6/docs/ref/#state.FacetReader) is expected.
1351
+ */
1352
+ var Facet = class Facet {
1353
+ constructor(combine, compareInput, compare, isStatic, enables) {
1354
+ this.combine = combine;
1355
+ this.compareInput = compareInput;
1356
+ this.compare = compare;
1357
+ this.isStatic = isStatic;
1358
+ /**
1359
+ @internal
1360
+ */
1361
+ this.id = nextID++;
1362
+ this.default = combine([]);
1363
+ this.extensions = typeof enables == "function" ? enables(this) : enables;
1364
+ }
1365
+ /**
1366
+ Returns a facet reader for this facet, which can be used to
1367
+ [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
1368
+ */
1369
+ get reader() {
1370
+ return this;
1371
+ }
1372
+ /**
1373
+ Define a new facet.
1374
+ */
1375
+ static define(config = {}) {
1376
+ return new Facet(config.combine || ((a) => a), config.compareInput || ((a, b) => a === b), config.compare || (!config.combine ? sameArray : (a, b) => a === b), !!config.static, config.enables);
1377
+ }
1378
+ /**
1379
+ Returns an extension that adds the given value to this facet.
1380
+ */
1381
+ of(value) {
1382
+ return new FacetProvider([], this, 0, value);
1383
+ }
1384
+ /**
1385
+ Create an extension that computes a value for the facet from a
1386
+ state. You must take care to declare the parts of the state that
1387
+ this value depends on, since your function is only called again
1388
+ for a new state when one of those parts changed.
1389
+
1390
+ In cases where your value depends only on a single field, you'll
1391
+ want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
1392
+ */
1393
+ compute(deps, get) {
1394
+ if (this.isStatic) throw new Error("Can't compute a static facet");
1395
+ return new FacetProvider(deps, this, 1, get);
1396
+ }
1397
+ /**
1398
+ Create an extension that computes zero or more values for this
1399
+ facet from a state.
1400
+ */
1401
+ computeN(deps, get) {
1402
+ if (this.isStatic) throw new Error("Can't compute a static facet");
1403
+ return new FacetProvider(deps, this, 2, get);
1404
+ }
1405
+ from(field, get) {
1406
+ if (!get) get = (x) => x;
1407
+ return this.compute([field], (state) => get(state.field(field)));
1408
+ }
1409
+ };
1410
+ function sameArray(a, b) {
1411
+ return a == b || a.length == b.length && a.every((e, i) => e === b[i]);
1412
+ }
1413
+ var FacetProvider = class {
1414
+ constructor(dependencies, facet, type, value) {
1415
+ this.dependencies = dependencies;
1416
+ this.facet = facet;
1417
+ this.type = type;
1418
+ this.value = value;
1419
+ this.id = nextID++;
1420
+ }
1421
+ dynamicSlot(addresses) {
1422
+ var _a;
1423
+ let getter = this.value;
1424
+ let compare = this.facet.compareInput;
1425
+ let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2;
1426
+ let depDoc = false, depSel = false, depAddrs = [];
1427
+ for (let dep of this.dependencies) if (dep == "doc") depDoc = true;
1428
+ else if (dep == "selection") depSel = true;
1429
+ else if ((((_a = addresses[dep.id]) !== null && _a !== void 0 ? _a : 1) & 1) == 0) depAddrs.push(addresses[dep.id]);
1430
+ return {
1431
+ create(state) {
1432
+ state.values[idx] = getter(state);
1433
+ return 1;
1434
+ },
1435
+ update(state, tr) {
1436
+ if (depDoc && tr.docChanged || depSel && (tr.docChanged || tr.selection) || ensureAll(state, depAddrs)) {
1437
+ let newVal = getter(state);
1438
+ if (multi ? !compareArray(newVal, state.values[idx], compare) : !compare(newVal, state.values[idx])) {
1439
+ state.values[idx] = newVal;
1440
+ return 1;
1441
+ }
1442
+ }
1443
+ return 0;
1444
+ },
1445
+ reconfigure: (state, oldState) => {
1446
+ let newVal, oldAddr = oldState.config.address[id];
1447
+ if (oldAddr != null) {
1448
+ let oldVal = getAddr(oldState, oldAddr);
1449
+ if (this.dependencies.every((dep) => {
1450
+ return dep instanceof Facet ? oldState.facet(dep) === state.facet(dep) : dep instanceof StateField ? oldState.field(dep, false) == state.field(dep, false) : true;
1451
+ }) || (multi ? compareArray(newVal = getter(state), oldVal, compare) : compare(newVal = getter(state), oldVal))) {
1452
+ state.values[idx] = oldVal;
1453
+ return 0;
1454
+ }
1455
+ } else newVal = getter(state);
1456
+ state.values[idx] = newVal;
1457
+ return 1;
1458
+ }
1459
+ };
1460
+ }
1461
+ };
1462
+ function compareArray(a, b, compare) {
1463
+ if (a.length != b.length) return false;
1464
+ for (let i = 0; i < a.length; i++) if (!compare(a[i], b[i])) return false;
1465
+ return true;
1466
+ }
1467
+ function ensureAll(state, addrs) {
1468
+ let changed = false;
1469
+ for (let addr of addrs) if (ensureAddr(state, addr) & 1) changed = true;
1470
+ return changed;
1471
+ }
1472
+ function dynamicFacetSlot(addresses, facet, providers) {
1473
+ let providerAddrs = providers.map((p) => addresses[p.id]);
1474
+ let providerTypes = providers.map((p) => p.type);
1475
+ let dynamic = providerAddrs.filter((p) => !(p & 1));
1476
+ let idx = addresses[facet.id] >> 1;
1477
+ function get(state) {
1478
+ let values = [];
1479
+ for (let i = 0; i < providerAddrs.length; i++) {
1480
+ let value = getAddr(state, providerAddrs[i]);
1481
+ if (providerTypes[i] == 2) for (let val of value) values.push(val);
1482
+ else values.push(value);
1483
+ }
1484
+ return facet.combine(values);
1485
+ }
1486
+ return {
1487
+ create(state) {
1488
+ for (let addr of providerAddrs) ensureAddr(state, addr);
1489
+ state.values[idx] = get(state);
1490
+ return 1;
1491
+ },
1492
+ update(state, tr) {
1493
+ if (!ensureAll(state, dynamic)) return 0;
1494
+ let value = get(state);
1495
+ if (facet.compare(value, state.values[idx])) return 0;
1496
+ state.values[idx] = value;
1497
+ return 1;
1498
+ },
1499
+ reconfigure(state, oldState) {
1500
+ let depChanged = ensureAll(state, providerAddrs);
1501
+ let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);
1502
+ if (oldProviders && !depChanged && sameArray(providers, oldProviders)) {
1503
+ state.values[idx] = oldValue;
1504
+ return 0;
1505
+ }
1506
+ let value = get(state);
1507
+ if (facet.compare(value, oldValue)) {
1508
+ state.values[idx] = oldValue;
1509
+ return 0;
1510
+ }
1511
+ state.values[idx] = value;
1512
+ return 1;
1513
+ }
1514
+ };
1515
+ }
1516
+ const initField = /*@__PURE__*/ Facet.define({ static: true });
1517
+ /**
1518
+ Fields can store additional information in an editor state, and
1519
+ keep it in sync with the rest of the state.
1520
+ */
1521
+ var StateField = class StateField {
1522
+ constructor(id, createF, updateF, compareF, spec) {
1523
+ this.id = id;
1524
+ this.createF = createF;
1525
+ this.updateF = updateF;
1526
+ this.compareF = compareF;
1527
+ this.spec = spec;
1528
+ /**
1529
+ @internal
1530
+ */
1531
+ this.provides = void 0;
1532
+ }
1533
+ /**
1534
+ Define a state field.
1535
+ */
1536
+ static define(config) {
1537
+ let field = new StateField(nextID++, config.create, config.update, config.compare || ((a, b) => a === b), config);
1538
+ if (config.provide) field.provides = config.provide(field);
1539
+ return field;
1540
+ }
1541
+ create(state) {
1542
+ let init = state.facet(initField).find((i) => i.field == this);
1543
+ return ((init === null || init === void 0 ? void 0 : init.create) || this.createF)(state);
1544
+ }
1545
+ /**
1546
+ @internal
1547
+ */
1548
+ slot(addresses) {
1549
+ let idx = addresses[this.id] >> 1;
1550
+ return {
1551
+ create: (state) => {
1552
+ state.values[idx] = this.create(state);
1553
+ return 1;
1554
+ },
1555
+ update: (state, tr) => {
1556
+ let oldVal = state.values[idx];
1557
+ let value = this.updateF(oldVal, tr);
1558
+ if (this.compareF(oldVal, value)) return 0;
1559
+ state.values[idx] = value;
1560
+ return 1;
1561
+ },
1562
+ reconfigure: (state, oldState) => {
1563
+ let init = state.facet(initField), oldInit = oldState.facet(initField), reInit;
1564
+ if ((reInit = init.find((i) => i.field == this)) && reInit != oldInit.find((i) => i.field == this)) {
1565
+ state.values[idx] = reInit.create(state);
1566
+ return 1;
1567
+ }
1568
+ if (oldState.config.address[this.id] != null) {
1569
+ state.values[idx] = oldState.field(this);
1570
+ return 0;
1571
+ }
1572
+ state.values[idx] = this.create(state);
1573
+ return 1;
1574
+ }
1575
+ };
1576
+ }
1577
+ /**
1578
+ Returns an extension that enables this field and overrides the
1579
+ way it is initialized. Can be useful when you need to provide a
1580
+ non-default starting value for the field.
1581
+ */
1582
+ init(create) {
1583
+ return [this, initField.of({
1584
+ field: this,
1585
+ create
1586
+ })];
1587
+ }
1588
+ /**
1589
+ State field instances can be used as
1590
+ [`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a
1591
+ given state.
1592
+ */
1593
+ get extension() {
1594
+ return this;
1595
+ }
1596
+ };
1597
+ const Prec_ = {
1598
+ lowest: 4,
1599
+ low: 3,
1600
+ default: 2,
1601
+ high: 1,
1602
+ highest: 0
1603
+ };
1604
+ function prec(value) {
1605
+ return (ext) => new PrecExtension(ext, value);
1606
+ }
1607
+ /**
1608
+ By default extensions are registered in the order they are found
1609
+ in the flattened form of nested array that was provided.
1610
+ Individual extension values can be assigned a precedence to
1611
+ override this. Extensions that do not have a precedence set get
1612
+ the precedence of the nearest parent with a precedence, or
1613
+ [`default`](https://codemirror.net/6/docs/ref/#state.Prec.default) if there is no such parent. The
1614
+ final ordering of extensions is determined by first sorting by
1615
+ precedence and then by order within each precedence.
1616
+ */
1617
+ const Prec = {
1618
+ /**
1619
+ The highest precedence level, for extensions that should end up
1620
+ near the start of the precedence ordering.
1621
+ */
1622
+ highest: /*@__PURE__*/ prec(Prec_.highest),
1623
+ /**
1624
+ A higher-than-default precedence, for extensions that should
1625
+ come before those with default precedence.
1626
+ */
1627
+ high: /*@__PURE__*/ prec(Prec_.high),
1628
+ /**
1629
+ The default precedence, which is also used for extensions
1630
+ without an explicit precedence.
1631
+ */
1632
+ default: /*@__PURE__*/ prec(Prec_.default),
1633
+ /**
1634
+ A lower-than-default precedence.
1635
+ */
1636
+ low: /*@__PURE__*/ prec(Prec_.low),
1637
+ /**
1638
+ The lowest precedence level. Meant for things that should end up
1639
+ near the end of the extension order.
1640
+ */
1641
+ lowest: /*@__PURE__*/ prec(Prec_.lowest)
1642
+ };
1643
+ var PrecExtension = class {
1644
+ constructor(inner, prec) {
1645
+ this.inner = inner;
1646
+ this.prec = prec;
1647
+ }
1648
+ };
1649
+ /**
1650
+ Extension compartments can be used to make a configuration
1651
+ dynamic. By [wrapping](https://codemirror.net/6/docs/ref/#state.Compartment.of) part of your
1652
+ configuration in a compartment, you can later
1653
+ [replace](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure) that part through a
1654
+ transaction.
1655
+ */
1656
+ var Compartment = class Compartment {
1657
+ /**
1658
+ Create an instance of this compartment to add to your [state
1659
+ configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).
1660
+ */
1661
+ of(ext) {
1662
+ return new CompartmentInstance(this, ext);
1663
+ }
1664
+ /**
1665
+ Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
1666
+ reconfigures this compartment.
1667
+ */
1668
+ reconfigure(content) {
1669
+ return Compartment.reconfigure.of({
1670
+ compartment: this,
1671
+ extension: content
1672
+ });
1673
+ }
1674
+ /**
1675
+ Get the current content of the compartment in the state, or
1676
+ `undefined` if it isn't present.
1677
+ */
1678
+ get(state) {
1679
+ return state.config.compartments.get(this);
1680
+ }
1681
+ };
1682
+ var CompartmentInstance = class {
1683
+ constructor(compartment, inner) {
1684
+ this.compartment = compartment;
1685
+ this.inner = inner;
1686
+ }
1687
+ };
1688
+ var Configuration = class Configuration {
1689
+ constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
1690
+ this.base = base;
1691
+ this.compartments = compartments;
1692
+ this.dynamicSlots = dynamicSlots;
1693
+ this.address = address;
1694
+ this.staticValues = staticValues;
1695
+ this.facets = facets;
1696
+ this.statusTemplate = [];
1697
+ while (this.statusTemplate.length < dynamicSlots.length) this.statusTemplate.push(0);
1698
+ }
1699
+ staticFacet(facet) {
1700
+ let addr = this.address[facet.id];
1701
+ return addr == null ? facet.default : this.staticValues[addr >> 1];
1702
+ }
1703
+ static resolve(base, compartments, oldState) {
1704
+ let fields = [];
1705
+ let facets = Object.create(null);
1706
+ let newCompartments = /* @__PURE__ */ new Map();
1707
+ for (let ext of flatten(base, compartments, newCompartments)) if (ext instanceof StateField) fields.push(ext);
1708
+ else (facets[ext.facet.id] || (facets[ext.facet.id] = [])).push(ext);
1709
+ let address = Object.create(null);
1710
+ let staticValues = [];
1711
+ let dynamicSlots = [];
1712
+ for (let field of fields) {
1713
+ address[field.id] = dynamicSlots.length << 1;
1714
+ dynamicSlots.push((a) => field.slot(a));
1715
+ }
1716
+ let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;
1717
+ for (let id in facets) {
1718
+ let providers = facets[id], facet = providers[0].facet;
1719
+ let oldProviders = oldFacets && oldFacets[id] || [];
1720
+ if (providers.every((p) => p.type == 0)) {
1721
+ address[facet.id] = staticValues.length << 1 | 1;
1722
+ if (sameArray(oldProviders, providers)) staticValues.push(oldState.facet(facet));
1723
+ else {
1724
+ let value = facet.combine(providers.map((p) => p.value));
1725
+ staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);
1726
+ }
1727
+ } else {
1728
+ for (let p of providers) if (p.type == 0) {
1729
+ address[p.id] = staticValues.length << 1 | 1;
1730
+ staticValues.push(p.value);
1731
+ } else {
1732
+ address[p.id] = dynamicSlots.length << 1;
1733
+ dynamicSlots.push((a) => p.dynamicSlot(a));
1734
+ }
1735
+ address[facet.id] = dynamicSlots.length << 1;
1736
+ dynamicSlots.push((a) => dynamicFacetSlot(a, facet, providers));
1737
+ }
1738
+ }
1739
+ return new Configuration(base, newCompartments, dynamicSlots.map((f) => f(address)), address, staticValues, facets);
1740
+ }
1741
+ };
1742
+ function flatten(extension, compartments, newCompartments) {
1743
+ let result = [
1744
+ [],
1745
+ [],
1746
+ [],
1747
+ [],
1748
+ []
1749
+ ];
1750
+ let seen = /* @__PURE__ */ new Map();
1751
+ function inner(ext, prec) {
1752
+ let known = seen.get(ext);
1753
+ if (known != null) {
1754
+ if (known <= prec) return;
1755
+ let found = result[known].indexOf(ext);
1756
+ if (found > -1) result[known].splice(found, 1);
1757
+ if (ext instanceof CompartmentInstance) newCompartments.delete(ext.compartment);
1758
+ }
1759
+ seen.set(ext, prec);
1760
+ if (Array.isArray(ext)) for (let e of ext) inner(e, prec);
1761
+ else if (ext instanceof CompartmentInstance) {
1762
+ if (newCompartments.has(ext.compartment)) throw new RangeError(`Duplicate use of compartment in extensions`);
1763
+ let content = compartments.get(ext.compartment) || ext.inner;
1764
+ newCompartments.set(ext.compartment, content);
1765
+ inner(content, prec);
1766
+ } else if (ext instanceof PrecExtension) inner(ext.inner, ext.prec);
1767
+ else if (ext instanceof StateField) {
1768
+ result[prec].push(ext);
1769
+ if (ext.provides) inner(ext.provides, prec);
1770
+ } else if (ext instanceof FacetProvider) {
1771
+ result[prec].push(ext);
1772
+ if (ext.facet.extensions) inner(ext.facet.extensions, Prec_.default);
1773
+ } else {
1774
+ let content = ext.extension;
1775
+ if (!content) throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
1776
+ inner(content, prec);
1777
+ }
1778
+ }
1779
+ inner(extension, Prec_.default);
1780
+ return result.reduce((a, b) => a.concat(b));
1781
+ }
1782
+ function ensureAddr(state, addr) {
1783
+ if (addr & 1) return 2;
1784
+ let idx = addr >> 1;
1785
+ let status = state.status[idx];
1786
+ if (status == 4) throw new Error("Cyclic dependency between fields and/or facets");
1787
+ if (status & 2) return status;
1788
+ state.status[idx] = 4;
1789
+ let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
1790
+ return state.status[idx] = 2 | changed;
1791
+ }
1792
+ function getAddr(state, addr) {
1793
+ return addr & 1 ? state.config.staticValues[addr >> 1] : state.values[addr >> 1];
1794
+ }
1795
+ const languageData = /*@__PURE__*/ Facet.define();
1796
+ const allowMultipleSelections = /*@__PURE__*/ Facet.define({
1797
+ combine: (values) => values.some((v) => v),
1798
+ static: true
1799
+ });
1800
+ const lineSeparator = /*@__PURE__*/ Facet.define({
1801
+ combine: (values) => values.length ? values[0] : void 0,
1802
+ static: true
1803
+ });
1804
+ const changeFilter = /*@__PURE__*/ Facet.define();
1805
+ const transactionFilter = /*@__PURE__*/ Facet.define();
1806
+ const transactionExtender = /*@__PURE__*/ Facet.define();
1807
+ const readOnly = /*@__PURE__*/ Facet.define({ combine: (values) => values.length ? values[0] : false });
1808
+ /**
1809
+ Annotations are tagged values that are used to add metadata to
1810
+ transactions in an extensible way. They should be used to model
1811
+ things that effect the entire transaction (such as its [time
1812
+ stamp](https://codemirror.net/6/docs/ref/#state.Transaction^time) or information about its
1813
+ [origin](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)). For effects that happen
1814
+ _alongside_ the other changes made by the transaction, [state
1815
+ effects](https://codemirror.net/6/docs/ref/#state.StateEffect) are more appropriate.
1816
+ */
1817
+ var Annotation = class {
1818
+ /**
1819
+ @internal
1820
+ */
1821
+ constructor(type, value) {
1822
+ this.type = type;
1823
+ this.value = value;
1824
+ }
1825
+ /**
1826
+ Define a new type of annotation.
1827
+ */
1828
+ static define() {
1829
+ return new AnnotationType();
1830
+ }
1831
+ };
1832
+ /**
1833
+ Marker that identifies a type of [annotation](https://codemirror.net/6/docs/ref/#state.Annotation).
1834
+ */
1835
+ var AnnotationType = class {
1836
+ /**
1837
+ Create an instance of this annotation.
1838
+ */
1839
+ of(value) {
1840
+ return new Annotation(this, value);
1841
+ }
1842
+ };
1843
+ /**
1844
+ Representation of a type of state effect. Defined with
1845
+ [`StateEffect.define`](https://codemirror.net/6/docs/ref/#state.StateEffect^define).
1846
+ */
1847
+ var StateEffectType = class {
1848
+ /**
1849
+ @internal
1850
+ */
1851
+ constructor(map) {
1852
+ this.map = map;
1853
+ }
1854
+ /**
1855
+ Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
1856
+ type.
1857
+ */
1858
+ of(value) {
1859
+ return new StateEffect(this, value);
1860
+ }
1861
+ };
1862
+ /**
1863
+ State effects can be used to represent additional effects
1864
+ associated with a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction.effects). They
1865
+ are often useful to model changes to custom [state
1866
+ fields](https://codemirror.net/6/docs/ref/#state.StateField), when those changes aren't implicit in
1867
+ document or selection changes.
1868
+ */
1869
+ var StateEffect = class StateEffect {
1870
+ /**
1871
+ @internal
1872
+ */
1873
+ constructor(type, value) {
1874
+ this.type = type;
1875
+ this.value = value;
1876
+ }
1877
+ /**
1878
+ Map this effect through a position mapping. Will return
1879
+ `undefined` when that ends up deleting the effect.
1880
+ */
1881
+ map(mapping) {
1882
+ let mapped = this.type.map(this.value, mapping);
1883
+ return mapped === void 0 ? void 0 : mapped == this.value ? this : new StateEffect(this.type, mapped);
1884
+ }
1885
+ /**
1886
+ Tells you whether this effect object is of a given
1887
+ [type](https://codemirror.net/6/docs/ref/#state.StateEffectType).
1888
+ */
1889
+ is(type) {
1890
+ return this.type == type;
1891
+ }
1892
+ /**
1893
+ Define a new effect type. The type parameter indicates the type
1894
+ of values that his effect holds. It should be a type that
1895
+ doesn't include `undefined`, since that is used in
1896
+ [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
1897
+ removed.
1898
+ */
1899
+ static define(spec = {}) {
1900
+ return new StateEffectType(spec.map || ((v) => v));
1901
+ }
1902
+ /**
1903
+ Map an array of effects through a change set.
1904
+ */
1905
+ static mapEffects(effects, mapping) {
1906
+ if (!effects.length) return effects;
1907
+ let result = [];
1908
+ for (let effect of effects) {
1909
+ let mapped = effect.map(mapping);
1910
+ if (mapped) result.push(mapped);
1911
+ }
1912
+ return result;
1913
+ }
1914
+ };
1915
+ /**
1916
+ This effect can be used to reconfigure the root extensions of
1917
+ the editor. Doing this will discard any extensions
1918
+ [appended](https://codemirror.net/6/docs/ref/#state.StateEffect^appendConfig), but does not reset
1919
+ the content of [reconfigured](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure)
1920
+ compartments.
1921
+ */
1922
+ StateEffect.reconfigure = /*@__PURE__*/ StateEffect.define();
1923
+ /**
1924
+ Append extensions to the top-level configuration of the editor.
1925
+ */
1926
+ StateEffect.appendConfig = /*@__PURE__*/ StateEffect.define();
1927
+ /**
1928
+ Changes to the editor state are grouped into transactions.
1929
+ Typically, a user action creates a single transaction, which may
1930
+ contain any number of document changes, may change the selection,
1931
+ or have other effects. Create a transaction by calling
1932
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update), or immediately
1933
+ dispatch one by calling
1934
+ [`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).
1935
+ */
1936
+ var Transaction = class Transaction {
1937
+ constructor(startState, changes, selection, effects, annotations, scrollIntoView) {
1938
+ this.startState = startState;
1939
+ this.changes = changes;
1940
+ this.selection = selection;
1941
+ this.effects = effects;
1942
+ this.annotations = annotations;
1943
+ this.scrollIntoView = scrollIntoView;
1944
+ /**
1945
+ @internal
1946
+ */
1947
+ this._doc = null;
1948
+ /**
1949
+ @internal
1950
+ */
1951
+ this._state = null;
1952
+ if (selection) checkSelection(selection, changes.newLength);
1953
+ if (!annotations.some((a) => a.type == Transaction.time)) this.annotations = annotations.concat(Transaction.time.of(Date.now()));
1954
+ }
1955
+ /**
1956
+ @internal
1957
+ */
1958
+ static create(startState, changes, selection, effects, annotations, scrollIntoView) {
1959
+ return new Transaction(startState, changes, selection, effects, annotations, scrollIntoView);
1960
+ }
1961
+ /**
1962
+ The new document produced by the transaction. Contrary to
1963
+ [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
1964
+ force the entire new state to be computed right away, so it is
1965
+ recommended that [transaction
1966
+ filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter
1967
+ when they need to look at the new document.
1968
+ */
1969
+ get newDoc() {
1970
+ return this._doc || (this._doc = this.changes.apply(this.startState.doc));
1971
+ }
1972
+ /**
1973
+ The new selection produced by the transaction. If
1974
+ [`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,
1975
+ this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's
1976
+ current selection through the changes made by the transaction.
1977
+ */
1978
+ get newSelection() {
1979
+ return this.selection || this.startState.selection.map(this.changes);
1980
+ }
1981
+ /**
1982
+ The new state created by the transaction. Computed on demand
1983
+ (but retained for subsequent access), so it is recommended not to
1984
+ access it in [transaction
1985
+ filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
1986
+ */
1987
+ get state() {
1988
+ if (!this._state) this.startState.applyTransaction(this);
1989
+ return this._state;
1990
+ }
1991
+ /**
1992
+ Get the value of the given annotation type, if any.
1993
+ */
1994
+ annotation(type) {
1995
+ for (let ann of this.annotations) if (ann.type == type) return ann.value;
1996
+ }
1997
+ /**
1998
+ Indicates whether the transaction changed the document.
1999
+ */
2000
+ get docChanged() {
2001
+ return !this.changes.empty;
2002
+ }
2003
+ /**
2004
+ Indicates whether this transaction reconfigures the state
2005
+ (through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or
2006
+ with a top-level configuration
2007
+ [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
2008
+ */
2009
+ get reconfigured() {
2010
+ return this.startState.config != this.state.config;
2011
+ }
2012
+ /**
2013
+ Returns true if the transaction has a [user
2014
+ event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
2015
+ or more specific than `event`. For example, if the transaction
2016
+ has `"select.pointer"` as user event, `"select"` and
2017
+ `"select.pointer"` will match it.
2018
+ */
2019
+ isUserEvent(event) {
2020
+ let e = this.annotation(Transaction.userEvent);
2021
+ return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
2022
+ }
2023
+ };
2024
+ /**
2025
+ Annotation used to store transaction timestamps. Automatically
2026
+ added to every transaction, holding `Date.now()`.
2027
+ */
2028
+ Transaction.time = /*@__PURE__*/ Annotation.define();
2029
+ /**
2030
+ Annotation used to associate a transaction with a user interface
2031
+ event. Holds a string identifying the event, using a
2032
+ dot-separated format to support attaching more specific
2033
+ information. The events used by the core libraries are:
2034
+
2035
+ - `"input"` when content is entered
2036
+ - `"input.type"` for typed input
2037
+ - `"input.type.compose"` for composition
2038
+ - `"input.paste"` for pasted input
2039
+ - `"input.drop"` when adding content with drag-and-drop
2040
+ - `"input.complete"` when autocompleting
2041
+ - `"delete"` when the user deletes content
2042
+ - `"delete.selection"` when deleting the selection
2043
+ - `"delete.forward"` when deleting forward from the selection
2044
+ - `"delete.backward"` when deleting backward from the selection
2045
+ - `"delete.cut"` when cutting to the clipboard
2046
+ - `"move"` when content is moved
2047
+ - `"move.drop"` when content is moved within the editor through drag-and-drop
2048
+ - `"select"` when explicitly changing the selection
2049
+ - `"select.pointer"` when selecting with a mouse or other pointing device
2050
+ - `"undo"` and `"redo"` for history actions
2051
+
2052
+ Use [`isUserEvent`](https://codemirror.net/6/docs/ref/#state.Transaction.isUserEvent) to check
2053
+ whether the annotation matches a given event.
2054
+ */
2055
+ Transaction.userEvent = /*@__PURE__*/ Annotation.define();
2056
+ /**
2057
+ Annotation indicating whether a transaction should be added to
2058
+ the undo history or not.
2059
+ */
2060
+ Transaction.addToHistory = /*@__PURE__*/ Annotation.define();
2061
+ /**
2062
+ Annotation indicating (when present and true) that a transaction
2063
+ represents a change made by some other actor, not the user. This
2064
+ is used, for example, to tag other people's changes in
2065
+ collaborative editing.
2066
+ */
2067
+ Transaction.remote = /*@__PURE__*/ Annotation.define();
2068
+ function joinRanges(a, b) {
2069
+ let result = [];
2070
+ for (let iA = 0, iB = 0;;) {
2071
+ let from, to;
2072
+ if (iA < a.length && (iB == b.length || b[iB] >= a[iA])) {
2073
+ from = a[iA++];
2074
+ to = a[iA++];
2075
+ } else if (iB < b.length) {
2076
+ from = b[iB++];
2077
+ to = b[iB++];
2078
+ } else return result;
2079
+ if (!result.length || result[result.length - 1] < from) result.push(from, to);
2080
+ else if (result[result.length - 1] < to) result[result.length - 1] = to;
2081
+ }
2082
+ }
2083
+ function mergeTransaction(a, b, sequential) {
2084
+ var _a;
2085
+ let mapForA, mapForB, changes;
2086
+ if (sequential) {
2087
+ mapForA = b.changes;
2088
+ mapForB = ChangeSet.empty(b.changes.length);
2089
+ changes = a.changes.compose(b.changes);
2090
+ } else {
2091
+ mapForA = b.changes.map(a.changes);
2092
+ mapForB = a.changes.mapDesc(b.changes, true);
2093
+ changes = a.changes.compose(mapForA);
2094
+ }
2095
+ return {
2096
+ changes,
2097
+ selection: b.selection ? b.selection.map(mapForB) : (_a = a.selection) === null || _a === void 0 ? void 0 : _a.map(mapForA),
2098
+ effects: StateEffect.mapEffects(a.effects, mapForA).concat(StateEffect.mapEffects(b.effects, mapForB)),
2099
+ annotations: a.annotations.length ? a.annotations.concat(b.annotations) : b.annotations,
2100
+ scrollIntoView: a.scrollIntoView || b.scrollIntoView
2101
+ };
2102
+ }
2103
+ function resolveTransactionInner(state, spec, docSize) {
2104
+ let sel = spec.selection, annotations = asArray(spec.annotations);
2105
+ if (spec.userEvent) annotations = annotations.concat(Transaction.userEvent.of(spec.userEvent));
2106
+ return {
2107
+ changes: spec.changes instanceof ChangeSet ? spec.changes : ChangeSet.of(spec.changes || [], docSize, state.facet(lineSeparator)),
2108
+ selection: sel && (sel instanceof EditorSelection ? sel : EditorSelection.single(sel.anchor, sel.head)),
2109
+ effects: asArray(spec.effects),
2110
+ annotations,
2111
+ scrollIntoView: !!spec.scrollIntoView
2112
+ };
2113
+ }
2114
+ function resolveTransaction(state, specs, filter) {
2115
+ let s = resolveTransactionInner(state, specs.length ? specs[0] : {}, state.doc.length);
2116
+ if (specs.length && specs[0].filter === false) filter = false;
2117
+ for (let i = 1; i < specs.length; i++) {
2118
+ if (specs[i].filter === false) filter = false;
2119
+ let seq = !!specs[i].sequential;
2120
+ s = mergeTransaction(s, resolveTransactionInner(state, specs[i], seq ? s.changes.newLength : state.doc.length), seq);
2121
+ }
2122
+ let tr = Transaction.create(state, s.changes, s.selection, s.effects, s.annotations, s.scrollIntoView);
2123
+ return extendTransaction(filter ? filterTransaction(tr) : tr);
2124
+ }
2125
+ function filterTransaction(tr) {
2126
+ let state = tr.startState;
2127
+ let result = true;
2128
+ for (let filter of state.facet(changeFilter)) {
2129
+ let value = filter(tr);
2130
+ if (value === false) {
2131
+ result = false;
2132
+ break;
2133
+ }
2134
+ if (Array.isArray(value)) result = result === true ? value : joinRanges(result, value);
2135
+ }
2136
+ if (result !== true) {
2137
+ let changes, back;
2138
+ if (result === false) {
2139
+ back = tr.changes.invertedDesc;
2140
+ changes = ChangeSet.empty(state.doc.length);
2141
+ } else {
2142
+ let filtered = tr.changes.filter(result);
2143
+ changes = filtered.changes;
2144
+ back = filtered.filtered.mapDesc(filtered.changes).invertedDesc;
2145
+ }
2146
+ tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);
2147
+ }
2148
+ let filters = state.facet(transactionFilter);
2149
+ for (let i = filters.length - 1; i >= 0; i--) {
2150
+ let filtered = filters[i](tr);
2151
+ if (filtered instanceof Transaction) tr = filtered;
2152
+ else if (Array.isArray(filtered) && filtered.length == 1 && filtered[0] instanceof Transaction) tr = filtered[0];
2153
+ else tr = resolveTransaction(state, asArray(filtered), false);
2154
+ }
2155
+ return tr;
2156
+ }
2157
+ function extendTransaction(tr) {
2158
+ let state = tr.startState, extenders = state.facet(transactionExtender), spec = tr;
2159
+ for (let i = extenders.length - 1; i >= 0; i--) {
2160
+ let extension = extenders[i](tr);
2161
+ if (extension && Object.keys(extension).length) spec = mergeTransaction(spec, resolveTransactionInner(state, extension, tr.changes.newLength), true);
2162
+ }
2163
+ return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);
2164
+ }
2165
+ const none = [];
2166
+ function asArray(value) {
2167
+ return value == null ? none : Array.isArray(value) ? value : [value];
2168
+ }
2169
+ /**
2170
+ The categories produced by a [character
2171
+ categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer). These are used
2172
+ do things like selecting by word.
2173
+ */
2174
+ var CharCategory = /*@__PURE__*/ (function(CharCategory) {
2175
+ /**
2176
+ Word characters.
2177
+ */
2178
+ CharCategory[CharCategory["Word"] = 0] = "Word";
2179
+ /**
2180
+ Whitespace.
2181
+ */
2182
+ CharCategory[CharCategory["Space"] = 1] = "Space";
2183
+ /**
2184
+ Anything else.
2185
+ */
2186
+ CharCategory[CharCategory["Other"] = 2] = "Other";
2187
+ return CharCategory;
2188
+ })(CharCategory || (CharCategory = {}));
2189
+ const nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
2190
+ let wordChar;
2191
+ try {
2192
+ wordChar = /*@__PURE__*/ new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u");
2193
+ } catch (_) {}
2194
+ function hasWordChar(str) {
2195
+ if (wordChar) return wordChar.test(str);
2196
+ for (let i = 0; i < str.length; i++) {
2197
+ let ch = str[i];
2198
+ if (/\w/.test(ch) || ch > "€" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))) return true;
2199
+ }
2200
+ return false;
2201
+ }
2202
+ function makeCategorizer(wordChars) {
2203
+ return (char) => {
2204
+ if (!/\S/.test(char)) return CharCategory.Space;
2205
+ if (hasWordChar(char)) return CharCategory.Word;
2206
+ for (let i = 0; i < wordChars.length; i++) if (char.indexOf(wordChars[i]) > -1) return CharCategory.Word;
2207
+ return CharCategory.Other;
2208
+ };
2209
+ }
2210
+ /**
2211
+ The editor state class is a persistent (immutable) data structure.
2212
+ To update a state, you [create](https://codemirror.net/6/docs/ref/#state.EditorState.update) a
2213
+ [transaction](https://codemirror.net/6/docs/ref/#state.Transaction), which produces a _new_ state
2214
+ instance, without modifying the original object.
2215
+
2216
+ As such, _never_ mutate properties of a state directly. That'll
2217
+ just break things.
2218
+ */
2219
+ var EditorState = class EditorState {
2220
+ constructor(config, doc, selection, values, computeSlot, tr) {
2221
+ this.config = config;
2222
+ this.doc = doc;
2223
+ this.selection = selection;
2224
+ this.values = values;
2225
+ this.status = config.statusTemplate.slice();
2226
+ this.computeSlot = computeSlot;
2227
+ if (tr) tr._state = this;
2228
+ for (let i = 0; i < this.config.dynamicSlots.length; i++) ensureAddr(this, i << 1);
2229
+ this.computeSlot = null;
2230
+ }
2231
+ field(field, require = true) {
2232
+ let addr = this.config.address[field.id];
2233
+ if (addr == null) {
2234
+ if (require) throw new RangeError("Field is not present in this state");
2235
+ return;
2236
+ }
2237
+ ensureAddr(this, addr);
2238
+ return getAddr(this, addr);
2239
+ }
2240
+ /**
2241
+ Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this
2242
+ state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)
2243
+ can be passed. Unless
2244
+ [`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the
2245
+ [changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec
2246
+ are assumed to start in the _current_ document (not the document
2247
+ produced by previous specs), and its
2248
+ [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and
2249
+ [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer
2250
+ to the document created by its _own_ changes. The resulting
2251
+ transaction contains the combined effect of all the different
2252
+ specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later
2253
+ specs take precedence over earlier ones.
2254
+ */
2255
+ update(...specs) {
2256
+ return resolveTransaction(this, specs, true);
2257
+ }
2258
+ /**
2259
+ @internal
2260
+ */
2261
+ applyTransaction(tr) {
2262
+ let conf = this.config, { base, compartments } = conf;
2263
+ for (let effect of tr.effects) if (effect.is(Compartment.reconfigure)) {
2264
+ if (conf) {
2265
+ compartments = /* @__PURE__ */ new Map();
2266
+ conf.compartments.forEach((val, key) => compartments.set(key, val));
2267
+ conf = null;
2268
+ }
2269
+ compartments.set(effect.value.compartment, effect.value.extension);
2270
+ } else if (effect.is(StateEffect.reconfigure)) {
2271
+ conf = null;
2272
+ base = effect.value;
2273
+ } else if (effect.is(StateEffect.appendConfig)) {
2274
+ conf = null;
2275
+ base = asArray(base).concat(effect.value);
2276
+ }
2277
+ let startValues;
2278
+ if (!conf) {
2279
+ conf = Configuration.resolve(base, compartments, this);
2280
+ startValues = new EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null).values;
2281
+ } else startValues = tr.startState.values.slice();
2282
+ let selection = tr.startState.facet(allowMultipleSelections) ? tr.newSelection : tr.newSelection.asSingle();
2283
+ new EditorState(conf, tr.newDoc, selection, startValues, (state, slot) => slot.update(state, tr), tr);
2284
+ }
2285
+ /**
2286
+ Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
2287
+ replaces every selection range with the given content.
2288
+ */
2289
+ replaceSelection(text) {
2290
+ if (typeof text == "string") text = this.toText(text);
2291
+ return this.changeByRange((range) => ({
2292
+ changes: {
2293
+ from: range.from,
2294
+ to: range.to,
2295
+ insert: text
2296
+ },
2297
+ range: EditorSelection.cursor(range.from + text.length)
2298
+ }));
2299
+ }
2300
+ /**
2301
+ Create a set of changes and a new selection by running the given
2302
+ function for each range in the active selection. The function
2303
+ can return an optional set of changes (in the coordinate space
2304
+ of the start document), plus an updated range (in the coordinate
2305
+ space of the document produced by the call's own changes). This
2306
+ method will merge all the changes and ranges into a single
2307
+ changeset and selection, and return it as a [transaction
2308
+ spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to
2309
+ [`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
2310
+ */
2311
+ changeByRange(f) {
2312
+ let sel = this.selection;
2313
+ let result1 = f(sel.ranges[0]);
2314
+ let changes = this.changes(result1.changes), ranges = [result1.range];
2315
+ let effects = asArray(result1.effects);
2316
+ for (let i = 1; i < sel.ranges.length; i++) {
2317
+ let result = f(sel.ranges[i]);
2318
+ let newChanges = this.changes(result.changes), newMapped = newChanges.map(changes);
2319
+ for (let j = 0; j < i; j++) ranges[j] = ranges[j].map(newMapped);
2320
+ let mapBy = changes.mapDesc(newChanges, true);
2321
+ ranges.push(result.range.map(mapBy));
2322
+ changes = changes.compose(newMapped);
2323
+ effects = StateEffect.mapEffects(effects, newMapped).concat(StateEffect.mapEffects(asArray(result.effects), mapBy));
2324
+ }
2325
+ return {
2326
+ changes,
2327
+ selection: EditorSelection.create(ranges, sel.mainIndex),
2328
+ effects
2329
+ };
2330
+ }
2331
+ /**
2332
+ Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change
2333
+ description, taking the state's document length and line
2334
+ separator into account.
2335
+ */
2336
+ changes(spec = []) {
2337
+ if (spec instanceof ChangeSet) return spec;
2338
+ return ChangeSet.of(spec, this.doc.length, this.facet(EditorState.lineSeparator));
2339
+ }
2340
+ /**
2341
+ Using the state's [line
2342
+ separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
2343
+ [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
2344
+ */
2345
+ toText(string) {
2346
+ return Text.of(string.split(this.facet(EditorState.lineSeparator) || DefaultSplit));
2347
+ }
2348
+ /**
2349
+ Return the given range of the document as a string.
2350
+ */
2351
+ sliceDoc(from = 0, to = this.doc.length) {
2352
+ return this.doc.sliceString(from, to, this.lineBreak);
2353
+ }
2354
+ /**
2355
+ Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
2356
+ */
2357
+ facet(facet) {
2358
+ let addr = this.config.address[facet.id];
2359
+ if (addr == null) return facet.default;
2360
+ ensureAddr(this, addr);
2361
+ return getAddr(this, addr);
2362
+ }
2363
+ /**
2364
+ Convert this state to a JSON-serializable object. When custom
2365
+ fields should be serialized, you can pass them in as an object
2366
+ mapping property names (in the resulting object, which should
2367
+ not use `doc` or `selection`) to fields.
2368
+ */
2369
+ toJSON(fields) {
2370
+ let result = {
2371
+ doc: this.sliceDoc(),
2372
+ selection: this.selection.toJSON()
2373
+ };
2374
+ if (fields) for (let prop in fields) {
2375
+ let value = fields[prop];
2376
+ if (value instanceof StateField && this.config.address[value.id] != null) result[prop] = value.spec.toJSON(this.field(fields[prop]), this);
2377
+ }
2378
+ return result;
2379
+ }
2380
+ /**
2381
+ Deserialize a state from its JSON representation. When custom
2382
+ fields should be deserialized, pass the same object you passed
2383
+ to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as
2384
+ third argument.
2385
+ */
2386
+ static fromJSON(json, config = {}, fields) {
2387
+ if (!json || typeof json.doc != "string") throw new RangeError("Invalid JSON representation for EditorState");
2388
+ let fieldInit = [];
2389
+ if (fields) {
2390
+ for (let prop in fields) if (Object.prototype.hasOwnProperty.call(json, prop)) {
2391
+ let field = fields[prop], value = json[prop];
2392
+ fieldInit.push(field.init((state) => field.spec.fromJSON(value, state)));
2393
+ }
2394
+ }
2395
+ return EditorState.create({
2396
+ doc: json.doc,
2397
+ selection: EditorSelection.fromJSON(json.selection),
2398
+ extensions: config.extensions ? fieldInit.concat([config.extensions]) : fieldInit
2399
+ });
2400
+ }
2401
+ /**
2402
+ Create a new state. You'll usually only need this when
2403
+ initializing an editor—updated states are created by applying
2404
+ transactions.
2405
+ */
2406
+ static create(config = {}) {
2407
+ let configuration = Configuration.resolve(config.extensions || [], /* @__PURE__ */ new Map());
2408
+ let doc = config.doc instanceof Text ? config.doc : Text.of((config.doc || "").split(configuration.staticFacet(EditorState.lineSeparator) || DefaultSplit));
2409
+ let selection = !config.selection ? EditorSelection.single(0) : config.selection instanceof EditorSelection ? config.selection : EditorSelection.single(config.selection.anchor, config.selection.head);
2410
+ checkSelection(selection, doc.length);
2411
+ if (!configuration.staticFacet(allowMultipleSelections)) selection = selection.asSingle();
2412
+ return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);
2413
+ }
2414
+ /**
2415
+ The size (in columns) of a tab in the document, determined by
2416
+ the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.
2417
+ */
2418
+ get tabSize() {
2419
+ return this.facet(EditorState.tabSize);
2420
+ }
2421
+ /**
2422
+ Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)
2423
+ string for this state.
2424
+ */
2425
+ get lineBreak() {
2426
+ return this.facet(EditorState.lineSeparator) || "\n";
2427
+ }
2428
+ /**
2429
+ Returns true when the editor is
2430
+ [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
2431
+ */
2432
+ get readOnly() {
2433
+ return this.facet(readOnly);
2434
+ }
2435
+ /**
2436
+ Look up a translation for the given phrase (via the
2437
+ [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
2438
+ original string if no translation is found.
2439
+
2440
+ If additional arguments are passed, they will be inserted in
2441
+ place of markers like `$1` (for the first value) and `$2`, etc.
2442
+ A single `$` is equivalent to `$1`, and `$$` will produce a
2443
+ literal dollar sign.
2444
+ */
2445
+ phrase(phrase, ...insert) {
2446
+ for (let map of this.facet(EditorState.phrases)) if (Object.prototype.hasOwnProperty.call(map, phrase)) {
2447
+ phrase = map[phrase];
2448
+ break;
2449
+ }
2450
+ if (insert.length) phrase = phrase.replace(/\$(\$|\d*)/g, (m, i) => {
2451
+ if (i == "$") return "$";
2452
+ let n = +(i || 1);
2453
+ return !n || n > insert.length ? m : insert[n - 1];
2454
+ });
2455
+ return phrase;
2456
+ }
2457
+ /**
2458
+ Find the values for a given language data field, provided by the
2459
+ the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
2460
+
2461
+ Examples of language data fields are...
2462
+
2463
+ - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
2464
+ comment syntax.
2465
+ - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
2466
+ for providing language-specific completion sources.
2467
+ - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
2468
+ characters that should be considered part of words in this
2469
+ language.
2470
+ - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
2471
+ bracket closing behavior.
2472
+ */
2473
+ languageDataAt(name, pos, side = -1) {
2474
+ let values = [];
2475
+ for (let provider of this.facet(languageData)) for (let result of provider(this, pos, side)) if (Object.prototype.hasOwnProperty.call(result, name)) values.push(result[name]);
2476
+ return values;
2477
+ }
2478
+ /**
2479
+ Return a function that can categorize strings (expected to
2480
+ represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
2481
+ into one of:
2482
+
2483
+ - Word (contains an alphanumeric character or a character
2484
+ explicitly listed in the local language's `"wordChars"`
2485
+ language data, which should be a string)
2486
+ - Space (contains only whitespace)
2487
+ - Other (anything else)
2488
+ */
2489
+ charCategorizer(at) {
2490
+ let chars = this.languageDataAt("wordChars", at);
2491
+ return makeCategorizer(chars.length ? chars[0] : "");
2492
+ }
2493
+ /**
2494
+ Find the word at the given position, meaning the range
2495
+ containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
2496
+ around it. If no word characters are adjacent to the position,
2497
+ this returns null.
2498
+ */
2499
+ wordAt(pos) {
2500
+ let { text, from, length } = this.doc.lineAt(pos);
2501
+ let cat = this.charCategorizer(pos);
2502
+ let start = pos - from, end = pos - from;
2503
+ while (start > 0) {
2504
+ let prev = findClusterBreak(text, start, false);
2505
+ if (cat(text.slice(prev, start)) != CharCategory.Word) break;
2506
+ start = prev;
2507
+ }
2508
+ while (end < length) {
2509
+ let next = findClusterBreak(text, end);
2510
+ if (cat(text.slice(end, next)) != CharCategory.Word) break;
2511
+ end = next;
2512
+ }
2513
+ return start == end ? null : EditorSelection.range(start + from, end + from);
2514
+ }
2515
+ };
2516
+ /**
2517
+ A facet that, when enabled, causes the editor to allow multiple
2518
+ ranges to be selected. Be careful though, because by default the
2519
+ editor relies on the native DOM selection, which cannot handle
2520
+ multiple selections. An extension like
2521
+ [`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) can be used to make
2522
+ secondary selections visible to the user.
2523
+ */
2524
+ EditorState.allowMultipleSelections = allowMultipleSelections;
2525
+ /**
2526
+ Configures the tab size to use in this state. The first
2527
+ (highest-precedence) value of the facet is used. If no value is
2528
+ given, this defaults to 4.
2529
+ */
2530
+ EditorState.tabSize = /*@__PURE__*/ Facet.define({ combine: (values) => values.length ? values[0] : 4 });
2531
+ /**
2532
+ The line separator to use. By default, any of `"\n"`, `"\r\n"`
2533
+ and `"\r"` is treated as a separator when splitting lines, and
2534
+ lines are joined with `"\n"`.
2535
+
2536
+ When you configure a value here, only that precise separator
2537
+ will be used, allowing you to round-trip documents through the
2538
+ editor without normalizing line separators.
2539
+ */
2540
+ EditorState.lineSeparator = lineSeparator;
2541
+ /**
2542
+ This facet controls the value of the
2543
+ [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is
2544
+ consulted by commands and extensions that implement editing
2545
+ functionality to determine whether they should apply. It
2546
+ defaults to false, but when its highest-precedence value is
2547
+ `true`, such functionality disables itself.
2548
+
2549
+ Not to be confused with
2550
+ [`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which
2551
+ controls whether the editor's DOM is set to be editable (and
2552
+ thus focusable).
2553
+ */
2554
+ EditorState.readOnly = readOnly;
2555
+ /**
2556
+ Registers translation phrases. The
2557
+ [`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
2558
+ all objects registered with this facet to find translations for
2559
+ its argument.
2560
+ */
2561
+ EditorState.phrases = /*@__PURE__*/ Facet.define({ compare(a, b) {
2562
+ let kA = Object.keys(a), kB = Object.keys(b);
2563
+ return kA.length == kB.length && kA.every((k) => a[k] == b[k]);
2564
+ } });
2565
+ /**
2566
+ A facet used to register [language
2567
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
2568
+ */
2569
+ EditorState.languageData = languageData;
2570
+ /**
2571
+ Facet used to register change filters, which are called for each
2572
+ transaction (unless explicitly
2573
+ [disabled](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter)), and can suppress
2574
+ part of the transaction's changes.
2575
+
2576
+ Such a function can return `true` to indicate that it doesn't
2577
+ want to do anything, `false` to completely stop the changes in
2578
+ the transaction, or a set of ranges in which changes should be
2579
+ suppressed. Such ranges are represented as an array of numbers,
2580
+ with each pair of two numbers indicating the start and end of a
2581
+ range. So for example `[10, 20, 100, 110]` suppresses changes
2582
+ between 10 and 20, and between 100 and 110.
2583
+ */
2584
+ EditorState.changeFilter = changeFilter;
2585
+ /**
2586
+ Facet used to register a hook that gets a chance to update or
2587
+ replace transaction specs before they are applied. This will
2588
+ only be applied for transactions that don't have
2589
+ [`filter`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter) set to `false`. You
2590
+ can either return a single transaction spec (possibly the input
2591
+ transaction), or an array of specs (which will be combined in
2592
+ the same way as the arguments to
2593
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
2594
+
2595
+ When possible, it is recommended to avoid accessing
2596
+ [`Transaction.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state) in a filter,
2597
+ since it will force creation of a state that will then be
2598
+ discarded again, if the transaction is actually filtered.
2599
+
2600
+ (This functionality should be used with care. Indiscriminately
2601
+ modifying transaction is likely to break something or degrade
2602
+ the user experience.)
2603
+ */
2604
+ EditorState.transactionFilter = transactionFilter;
2605
+ /**
2606
+ This is a more limited form of
2607
+ [`transactionFilter`](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter),
2608
+ which can only add
2609
+ [annotations](https://codemirror.net/6/docs/ref/#state.TransactionSpec.annotations) and
2610
+ [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects). _But_, this type
2611
+ of filter runs even if the transaction has disabled regular
2612
+ [filtering](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter), making it suitable
2613
+ for effects that don't need to touch the changes or selection,
2614
+ but do want to process every transaction.
2615
+
2616
+ Extenders run _after_ filters, when both are present.
2617
+ */
2618
+ EditorState.transactionExtender = transactionExtender;
2619
+ Compartment.reconfigure = /*@__PURE__*/ StateEffect.define();
2620
+ /**
2621
+ Utility function for combining behaviors to fill in a config
2622
+ object from an array of provided configs. `defaults` should hold
2623
+ default values for all optional fields in `Config`.
2624
+
2625
+ The function will, by default, error
2626
+ when a field gets two values that aren't `===`-equal, but you can
2627
+ provide combine functions per field to do something else.
2628
+ */
2629
+ function combineConfig(configs, defaults, combine = {}) {
2630
+ let result = {};
2631
+ for (let config of configs) for (let key of Object.keys(config)) {
2632
+ let value = config[key], current = result[key];
2633
+ if (current === void 0) result[key] = value;
2634
+ else if (current === value || value === void 0);
2635
+ else if (Object.hasOwnProperty.call(combine, key)) result[key] = combine[key](current, value);
2636
+ else throw new Error("Config merge conflict for field " + key);
2637
+ }
2638
+ for (let key in defaults) if (result[key] === void 0) result[key] = defaults[key];
2639
+ return result;
2640
+ }
2641
+ /**
2642
+ Each range is associated with a value, which must inherit from
2643
+ this class.
2644
+ */
2645
+ var RangeValue = class {
2646
+ /**
2647
+ Compare this value with another value. Used when comparing
2648
+ rangesets. The default implementation compares by identity.
2649
+ Unless you are only creating a fixed number of unique instances
2650
+ of your value type, it is a good idea to implement this
2651
+ properly.
2652
+ */
2653
+ eq(other) {
2654
+ return this == other;
2655
+ }
2656
+ /**
2657
+ Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
2658
+ */
2659
+ range(from, to = from) {
2660
+ return Range.create(from, to, this);
2661
+ }
2662
+ };
2663
+ RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
2664
+ RangeValue.prototype.point = false;
2665
+ RangeValue.prototype.mapMode = MapMode.TrackDel;
2666
+ function cmpVal(a, b) {
2667
+ return a == b || a.constructor == b.constructor && a.eq(b);
2668
+ }
2669
+ /**
2670
+ A range associates a value with a range of positions.
2671
+ */
2672
+ var Range = class Range {
2673
+ constructor(from, to, value) {
2674
+ this.from = from;
2675
+ this.to = to;
2676
+ this.value = value;
2677
+ }
2678
+ /**
2679
+ @internal
2680
+ */
2681
+ static create(from, to, value) {
2682
+ return new Range(from, to, value);
2683
+ }
2684
+ };
2685
+ function cmpRange(a, b) {
2686
+ return a.from - b.from || a.value.startSide - b.value.startSide;
2687
+ }
2688
+ var Chunk = class Chunk {
2689
+ constructor(from, to, value, maxPoint) {
2690
+ this.from = from;
2691
+ this.to = to;
2692
+ this.value = value;
2693
+ this.maxPoint = maxPoint;
2694
+ }
2695
+ get length() {
2696
+ return this.to[this.to.length - 1];
2697
+ }
2698
+ findIndex(pos, side, end, startAt = 0) {
2699
+ let arr = end ? this.to : this.from;
2700
+ for (let lo = startAt, hi = arr.length;;) {
2701
+ if (lo == hi) return lo;
2702
+ let mid = lo + hi >> 1;
2703
+ let diff = arr[mid] - pos || (end ? this.value[mid].endSide : this.value[mid].startSide) - side;
2704
+ if (mid == lo) return diff >= 0 ? lo : hi;
2705
+ if (diff >= 0) hi = mid;
2706
+ else lo = mid + 1;
2707
+ }
2708
+ }
2709
+ between(offset, from, to, f) {
2710
+ for (let i = this.findIndex(from, -1e9, true), e = this.findIndex(to, 1e9, false, i); i < e; i++) if (f(this.from[i] + offset, this.to[i] + offset, this.value[i]) === false) return false;
2711
+ }
2712
+ map(offset, changes) {
2713
+ let value = [], from = [], to = [], newPos = -1, maxPoint = -1;
2714
+ for (let i = 0; i < this.value.length; i++) {
2715
+ let val = this.value[i], curFrom = this.from[i] + offset, curTo = this.to[i] + offset, newFrom, newTo;
2716
+ if (curFrom == curTo) {
2717
+ let mapped = changes.mapPos(curFrom, val.startSide, val.mapMode);
2718
+ if (mapped == null) continue;
2719
+ newFrom = newTo = mapped;
2720
+ if (val.startSide != val.endSide) {
2721
+ newTo = changes.mapPos(curFrom, val.endSide);
2722
+ if (newTo < newFrom) continue;
2723
+ }
2724
+ } else {
2725
+ newFrom = changes.mapPos(curFrom, val.startSide);
2726
+ newTo = changes.mapPos(curTo, val.endSide);
2727
+ if (newFrom > newTo || newFrom == newTo && val.startSide > 0 && val.endSide <= 0) continue;
2728
+ }
2729
+ if ((newTo - newFrom || val.endSide - val.startSide) < 0) continue;
2730
+ if (newPos < 0) newPos = newFrom;
2731
+ if (val.point) maxPoint = Math.max(maxPoint, newTo - newFrom);
2732
+ value.push(val);
2733
+ from.push(newFrom - newPos);
2734
+ to.push(newTo - newPos);
2735
+ }
2736
+ return {
2737
+ mapped: value.length ? new Chunk(from, to, value, maxPoint) : null,
2738
+ pos: newPos
2739
+ };
2740
+ }
2741
+ };
2742
+ /**
2743
+ A range set stores a collection of [ranges](https://codemirror.net/6/docs/ref/#state.Range) in a
2744
+ way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.RangeSet.map) and
2745
+ [update](https://codemirror.net/6/docs/ref/#state.RangeSet.update). This is an immutable data
2746
+ structure.
2747
+ */
2748
+ var RangeSet = class RangeSet {
2749
+ constructor(chunkPos, chunk, nextLayer, maxPoint) {
2750
+ this.chunkPos = chunkPos;
2751
+ this.chunk = chunk;
2752
+ this.nextLayer = nextLayer;
2753
+ this.maxPoint = maxPoint;
2754
+ }
2755
+ /**
2756
+ @internal
2757
+ */
2758
+ static create(chunkPos, chunk, nextLayer, maxPoint) {
2759
+ return new RangeSet(chunkPos, chunk, nextLayer, maxPoint);
2760
+ }
2761
+ /**
2762
+ @internal
2763
+ */
2764
+ get length() {
2765
+ let last = this.chunk.length - 1;
2766
+ return last < 0 ? 0 : Math.max(this.chunkEnd(last), this.nextLayer.length);
2767
+ }
2768
+ /**
2769
+ The number of ranges in the set.
2770
+ */
2771
+ get size() {
2772
+ if (this.isEmpty) return 0;
2773
+ let size = this.nextLayer.size;
2774
+ for (let chunk of this.chunk) size += chunk.value.length;
2775
+ return size;
2776
+ }
2777
+ /**
2778
+ @internal
2779
+ */
2780
+ chunkEnd(index) {
2781
+ return this.chunkPos[index] + this.chunk[index].length;
2782
+ }
2783
+ /**
2784
+ Update the range set, optionally adding new ranges or filtering
2785
+ out existing ones.
2786
+
2787
+ (Note: The type parameter is just there as a kludge to work
2788
+ around TypeScript variance issues that prevented `RangeSet<X>`
2789
+ from being a subtype of `RangeSet<Y>` when `X` is a subtype of
2790
+ `Y`.)
2791
+ */
2792
+ update(updateSpec) {
2793
+ let { add = [], sort = false, filterFrom = 0, filterTo = this.length } = updateSpec;
2794
+ let filter = updateSpec.filter;
2795
+ if (add.length == 0 && !filter) return this;
2796
+ if (sort) add = add.slice().sort(cmpRange);
2797
+ if (this.isEmpty) return add.length ? RangeSet.of(add) : this;
2798
+ let cur = new LayerCursor(this, null, -1).goto(0), i = 0, spill = [];
2799
+ let builder = new RangeSetBuilder();
2800
+ while (cur.value || i < add.length) if (i < add.length && (cur.from - add[i].from || cur.startSide - add[i].value.startSide) >= 0) {
2801
+ let range = add[i++];
2802
+ if (!builder.addInner(range.from, range.to, range.value)) spill.push(range);
2803
+ } else if (cur.rangeIndex == 1 && cur.chunkIndex < this.chunk.length && (i == add.length || this.chunkEnd(cur.chunkIndex) < add[i].from) && (!filter || filterFrom > this.chunkEnd(cur.chunkIndex) || filterTo < this.chunkPos[cur.chunkIndex]) && builder.addChunk(this.chunkPos[cur.chunkIndex], this.chunk[cur.chunkIndex])) cur.nextChunk();
2804
+ else {
2805
+ if (!filter || filterFrom > cur.to || filterTo < cur.from || filter(cur.from, cur.to, cur.value)) {
2806
+ if (!builder.addInner(cur.from, cur.to, cur.value)) spill.push(Range.create(cur.from, cur.to, cur.value));
2807
+ }
2808
+ cur.next();
2809
+ }
2810
+ return builder.finishInner(this.nextLayer.isEmpty && !spill.length ? RangeSet.empty : this.nextLayer.update({
2811
+ add: spill,
2812
+ filter,
2813
+ filterFrom,
2814
+ filterTo
2815
+ }));
2816
+ }
2817
+ /**
2818
+ Map this range set through a set of changes, return the new set.
2819
+ */
2820
+ map(changes) {
2821
+ if (changes.empty || this.isEmpty) return this;
2822
+ let chunks = [], chunkPos = [], maxPoint = -1;
2823
+ for (let i = 0; i < this.chunk.length; i++) {
2824
+ let start = this.chunkPos[i], chunk = this.chunk[i];
2825
+ let touch = changes.touchesRange(start, start + chunk.length);
2826
+ if (touch === false) {
2827
+ maxPoint = Math.max(maxPoint, chunk.maxPoint);
2828
+ chunks.push(chunk);
2829
+ chunkPos.push(changes.mapPos(start));
2830
+ } else if (touch === true) {
2831
+ let { mapped, pos } = chunk.map(start, changes);
2832
+ if (mapped) {
2833
+ maxPoint = Math.max(maxPoint, mapped.maxPoint);
2834
+ chunks.push(mapped);
2835
+ chunkPos.push(pos);
2836
+ }
2837
+ }
2838
+ }
2839
+ let next = this.nextLayer.map(changes);
2840
+ return chunks.length == 0 ? next : new RangeSet(chunkPos, chunks, next || RangeSet.empty, maxPoint);
2841
+ }
2842
+ /**
2843
+ Iterate over the ranges that touch the region `from` to `to`,
2844
+ calling `f` for each. There is no guarantee that the ranges will
2845
+ be reported in any specific order. When the callback returns
2846
+ `false`, iteration stops.
2847
+ */
2848
+ between(from, to, f) {
2849
+ if (this.isEmpty) return;
2850
+ for (let i = 0; i < this.chunk.length; i++) {
2851
+ let start = this.chunkPos[i], chunk = this.chunk[i];
2852
+ if (to >= start && from <= start + chunk.length && chunk.between(start, from - start, to - start, f) === false) return;
2853
+ }
2854
+ this.nextLayer.between(from, to, f);
2855
+ }
2856
+ /**
2857
+ Iterate over the ranges in this set, in order, including all
2858
+ ranges that end at or after `from`.
2859
+ */
2860
+ iter(from = 0) {
2861
+ return HeapCursor.from([this]).goto(from);
2862
+ }
2863
+ /**
2864
+ @internal
2865
+ */
2866
+ get isEmpty() {
2867
+ return this.nextLayer == this;
2868
+ }
2869
+ /**
2870
+ Iterate over the ranges in a collection of sets, in order,
2871
+ starting from `from`.
2872
+ */
2873
+ static iter(sets, from = 0) {
2874
+ return HeapCursor.from(sets).goto(from);
2875
+ }
2876
+ /**
2877
+ Iterate over two groups of sets, calling methods on `comparator`
2878
+ to notify it of possible differences.
2879
+ */
2880
+ static compare(oldSets, newSets, textDiff, comparator, minPointSize = -1) {
2881
+ let a = oldSets.filter((set) => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);
2882
+ let b = newSets.filter((set) => set.maxPoint > 0 || !set.isEmpty && set.maxPoint >= minPointSize);
2883
+ let sharedChunks = findSharedChunks(a, b, textDiff);
2884
+ let sideA = new SpanCursor(a, sharedChunks, minPointSize);
2885
+ let sideB = new SpanCursor(b, sharedChunks, minPointSize);
2886
+ textDiff.iterGaps((fromA, fromB, length) => compare(sideA, fromA, sideB, fromB, length, comparator));
2887
+ if (textDiff.empty && textDiff.length == 0) compare(sideA, 0, sideB, 0, 0, comparator);
2888
+ }
2889
+ /**
2890
+ Compare the contents of two groups of range sets, returning true
2891
+ if they are equivalent in the given range.
2892
+ */
2893
+ static eq(oldSets, newSets, from = 0, to) {
2894
+ if (to == null) to = 999999999;
2895
+ let a = oldSets.filter((set) => !set.isEmpty && newSets.indexOf(set) < 0);
2896
+ let b = newSets.filter((set) => !set.isEmpty && oldSets.indexOf(set) < 0);
2897
+ if (a.length != b.length) return false;
2898
+ if (!a.length) return true;
2899
+ let sharedChunks = findSharedChunks(a, b);
2900
+ let sideA = new SpanCursor(a, sharedChunks, 0).goto(from), sideB = new SpanCursor(b, sharedChunks, 0).goto(from);
2901
+ for (;;) {
2902
+ if (sideA.to != sideB.to || !sameValues(sideA.active, sideB.active) || sideA.point && (!sideB.point || !cmpVal(sideA.point, sideB.point))) return false;
2903
+ if (sideA.to > to) return true;
2904
+ sideA.next();
2905
+ sideB.next();
2906
+ }
2907
+ }
2908
+ /**
2909
+ Iterate over a group of range sets at the same time, notifying
2910
+ the iterator about the ranges covering every given piece of
2911
+ content. Returns the open count (see
2912
+ [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
2913
+ of the iteration.
2914
+ */
2915
+ static spans(sets, from, to, iterator, minPointSize = -1) {
2916
+ let cursor = new SpanCursor(sets, null, minPointSize).goto(from), pos = from;
2917
+ let openRanges = cursor.openStart;
2918
+ for (;;) {
2919
+ let curTo = Math.min(cursor.to, to);
2920
+ if (cursor.point) {
2921
+ let active = cursor.activeForPoint(cursor.to);
2922
+ let openCount = cursor.pointFrom < from ? active.length + 1 : cursor.point.startSide < 0 ? active.length : Math.min(active.length, openRanges);
2923
+ iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
2924
+ openRanges = Math.min(cursor.openEnd(curTo), active.length);
2925
+ } else if (curTo > pos) {
2926
+ iterator.span(pos, curTo, cursor.active, openRanges);
2927
+ openRanges = cursor.openEnd(curTo);
2928
+ }
2929
+ if (cursor.to > to) return openRanges + (cursor.point && cursor.to > to ? 1 : 0);
2930
+ pos = cursor.to;
2931
+ cursor.next();
2932
+ }
2933
+ }
2934
+ /**
2935
+ Create a range set for the given range or array of ranges. By
2936
+ default, this expects the ranges to be _sorted_ (by start
2937
+ position and, if two start at the same position,
2938
+ `value.startSide`). You can pass `true` as second argument to
2939
+ cause the method to sort them.
2940
+ */
2941
+ static of(ranges, sort = false) {
2942
+ let build = new RangeSetBuilder();
2943
+ for (let range of ranges instanceof Range ? [ranges] : sort ? lazySort(ranges) : ranges) build.add(range.from, range.to, range.value);
2944
+ return build.finish();
2945
+ }
2946
+ /**
2947
+ Join an array of range sets into a single set.
2948
+ */
2949
+ static join(sets) {
2950
+ if (!sets.length) return RangeSet.empty;
2951
+ let result = sets[sets.length - 1];
2952
+ for (let i = sets.length - 2; i >= 0; i--) for (let layer = sets[i]; layer != RangeSet.empty; layer = layer.nextLayer) result = new RangeSet(layer.chunkPos, layer.chunk, result, Math.max(layer.maxPoint, result.maxPoint));
2953
+ return result;
2954
+ }
2955
+ };
2956
+ /**
2957
+ The empty set of ranges.
2958
+ */
2959
+ RangeSet.empty = /*@__PURE__*/ new RangeSet([], [], null, -1);
2960
+ function lazySort(ranges) {
2961
+ if (ranges.length > 1) for (let prev = ranges[0], i = 1; i < ranges.length; i++) {
2962
+ let cur = ranges[i];
2963
+ if (cmpRange(prev, cur) > 0) return ranges.slice().sort(cmpRange);
2964
+ prev = cur;
2965
+ }
2966
+ return ranges;
2967
+ }
2968
+ RangeSet.empty.nextLayer = RangeSet.empty;
2969
+ /**
2970
+ A range set builder is a data structure that helps build up a
2971
+ [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) directly, without first allocating
2972
+ an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
2973
+ */
2974
+ var RangeSetBuilder = class RangeSetBuilder {
2975
+ finishChunk(newArrays) {
2976
+ this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
2977
+ this.chunkPos.push(this.chunkStart);
2978
+ this.chunkStart = -1;
2979
+ this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
2980
+ this.maxPoint = -1;
2981
+ if (newArrays) {
2982
+ this.from = [];
2983
+ this.to = [];
2984
+ this.value = [];
2985
+ }
2986
+ }
2987
+ /**
2988
+ Create an empty builder.
2989
+ */
2990
+ constructor() {
2991
+ this.chunks = [];
2992
+ this.chunkPos = [];
2993
+ this.chunkStart = -1;
2994
+ this.last = null;
2995
+ this.lastFrom = -1e9;
2996
+ this.lastTo = -1e9;
2997
+ this.from = [];
2998
+ this.to = [];
2999
+ this.value = [];
3000
+ this.maxPoint = -1;
3001
+ this.setMaxPoint = -1;
3002
+ this.nextLayer = null;
3003
+ }
3004
+ /**
3005
+ Add a range. Ranges should be added in sorted (by `from` and
3006
+ `value.startSide`) order.
3007
+ */
3008
+ add(from, to, value) {
3009
+ if (!this.addInner(from, to, value)) (this.nextLayer || (this.nextLayer = new RangeSetBuilder())).add(from, to, value);
3010
+ }
3011
+ /**
3012
+ @internal
3013
+ */
3014
+ addInner(from, to, value) {
3015
+ let diff = from - this.lastTo || value.startSide - this.last.endSide;
3016
+ if (diff <= 0 && (from - this.lastFrom || value.startSide - this.last.startSide) < 0) throw new Error("Ranges must be added sorted by `from` position and `startSide`");
3017
+ if (diff < 0) return false;
3018
+ if (this.from.length == 250) this.finishChunk(true);
3019
+ if (this.chunkStart < 0) this.chunkStart = from;
3020
+ this.from.push(from - this.chunkStart);
3021
+ this.to.push(to - this.chunkStart);
3022
+ this.last = value;
3023
+ this.lastFrom = from;
3024
+ this.lastTo = to;
3025
+ this.value.push(value);
3026
+ if (value.point) this.maxPoint = Math.max(this.maxPoint, to - from);
3027
+ return true;
3028
+ }
3029
+ /**
3030
+ @internal
3031
+ */
3032
+ addChunk(from, chunk) {
3033
+ if ((from - this.lastTo || chunk.value[0].startSide - this.last.endSide) < 0) return false;
3034
+ if (this.from.length) this.finishChunk(true);
3035
+ this.setMaxPoint = Math.max(this.setMaxPoint, chunk.maxPoint);
3036
+ this.chunks.push(chunk);
3037
+ this.chunkPos.push(from);
3038
+ let last = chunk.value.length - 1;
3039
+ this.last = chunk.value[last];
3040
+ this.lastFrom = chunk.from[last] + from;
3041
+ this.lastTo = chunk.to[last] + from;
3042
+ return true;
3043
+ }
3044
+ /**
3045
+ Finish the range set. Returns the new set. The builder can't be
3046
+ used anymore after this has been called.
3047
+ */
3048
+ finish() {
3049
+ return this.finishInner(RangeSet.empty);
3050
+ }
3051
+ /**
3052
+ @internal
3053
+ */
3054
+ finishInner(next) {
3055
+ if (this.from.length) this.finishChunk(false);
3056
+ if (this.chunks.length == 0) return next;
3057
+ let result = RangeSet.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(next) : next, this.setMaxPoint);
3058
+ this.from = null;
3059
+ return result;
3060
+ }
3061
+ };
3062
+ function findSharedChunks(a, b, textDiff) {
3063
+ let inA = /* @__PURE__ */ new Map();
3064
+ for (let set of a) for (let i = 0; i < set.chunk.length; i++) if (set.chunk[i].maxPoint <= 0) inA.set(set.chunk[i], set.chunkPos[i]);
3065
+ let shared = /* @__PURE__ */ new Set();
3066
+ for (let set of b) for (let i = 0; i < set.chunk.length; i++) {
3067
+ let known = inA.get(set.chunk[i]);
3068
+ if (known != null && (textDiff ? textDiff.mapPos(known) : known) == set.chunkPos[i] && !(textDiff === null || textDiff === void 0 ? void 0 : textDiff.touchesRange(known, known + set.chunk[i].length))) shared.add(set.chunk[i]);
3069
+ }
3070
+ return shared;
3071
+ }
3072
+ var LayerCursor = class {
3073
+ constructor(layer, skip, minPoint, rank = 0) {
3074
+ this.layer = layer;
3075
+ this.skip = skip;
3076
+ this.minPoint = minPoint;
3077
+ this.rank = rank;
3078
+ }
3079
+ get startSide() {
3080
+ return this.value ? this.value.startSide : 0;
3081
+ }
3082
+ get endSide() {
3083
+ return this.value ? this.value.endSide : 0;
3084
+ }
3085
+ goto(pos, side = -1e9) {
3086
+ this.chunkIndex = this.rangeIndex = 0;
3087
+ this.gotoInner(pos, side, false);
3088
+ return this;
3089
+ }
3090
+ gotoInner(pos, side, forward) {
3091
+ while (this.chunkIndex < this.layer.chunk.length) {
3092
+ let next = this.layer.chunk[this.chunkIndex];
3093
+ if (!(this.skip && this.skip.has(next) || this.layer.chunkEnd(this.chunkIndex) < pos || next.maxPoint < this.minPoint)) break;
3094
+ this.chunkIndex++;
3095
+ forward = false;
3096
+ }
3097
+ if (this.chunkIndex < this.layer.chunk.length) {
3098
+ let rangeIndex = this.layer.chunk[this.chunkIndex].findIndex(pos - this.layer.chunkPos[this.chunkIndex], side, true);
3099
+ if (!forward || this.rangeIndex < rangeIndex) this.setRangeIndex(rangeIndex);
3100
+ }
3101
+ this.next();
3102
+ }
3103
+ forward(pos, side) {
3104
+ if ((this.to - pos || this.endSide - side) < 0) this.gotoInner(pos, side, true);
3105
+ }
3106
+ next() {
3107
+ for (;;) if (this.chunkIndex == this.layer.chunk.length) {
3108
+ this.from = this.to = 1e9;
3109
+ this.value = null;
3110
+ break;
3111
+ } else {
3112
+ let chunkPos = this.layer.chunkPos[this.chunkIndex], chunk = this.layer.chunk[this.chunkIndex];
3113
+ let from = chunkPos + chunk.from[this.rangeIndex];
3114
+ this.from = from;
3115
+ this.to = chunkPos + chunk.to[this.rangeIndex];
3116
+ this.value = chunk.value[this.rangeIndex];
3117
+ this.setRangeIndex(this.rangeIndex + 1);
3118
+ if (this.minPoint < 0 || this.value.point && this.to - this.from >= this.minPoint) break;
3119
+ }
3120
+ }
3121
+ setRangeIndex(index) {
3122
+ if (index == this.layer.chunk[this.chunkIndex].value.length) {
3123
+ this.chunkIndex++;
3124
+ if (this.skip) while (this.chunkIndex < this.layer.chunk.length && this.skip.has(this.layer.chunk[this.chunkIndex])) this.chunkIndex++;
3125
+ this.rangeIndex = 0;
3126
+ } else this.rangeIndex = index;
3127
+ }
3128
+ nextChunk() {
3129
+ this.chunkIndex++;
3130
+ this.rangeIndex = 0;
3131
+ this.next();
3132
+ }
3133
+ compare(other) {
3134
+ return this.from - other.from || this.startSide - other.startSide || this.rank - other.rank || this.to - other.to || this.endSide - other.endSide;
3135
+ }
3136
+ };
3137
+ var HeapCursor = class HeapCursor {
3138
+ constructor(heap) {
3139
+ this.heap = heap;
3140
+ }
3141
+ static from(sets, skip = null, minPoint = -1) {
3142
+ let heap = [];
3143
+ for (let i = 0; i < sets.length; i++) for (let cur = sets[i]; !cur.isEmpty; cur = cur.nextLayer) if (cur.maxPoint >= minPoint) heap.push(new LayerCursor(cur, skip, minPoint, i));
3144
+ return heap.length == 1 ? heap[0] : new HeapCursor(heap);
3145
+ }
3146
+ get startSide() {
3147
+ return this.value ? this.value.startSide : 0;
3148
+ }
3149
+ goto(pos, side = -1e9) {
3150
+ for (let cur of this.heap) cur.goto(pos, side);
3151
+ for (let i = this.heap.length >> 1; i >= 0; i--) heapBubble(this.heap, i);
3152
+ this.next();
3153
+ return this;
3154
+ }
3155
+ forward(pos, side) {
3156
+ for (let cur of this.heap) cur.forward(pos, side);
3157
+ for (let i = this.heap.length >> 1; i >= 0; i--) heapBubble(this.heap, i);
3158
+ if ((this.to - pos || this.value.endSide - side) < 0) this.next();
3159
+ }
3160
+ next() {
3161
+ if (this.heap.length == 0) {
3162
+ this.from = this.to = 1e9;
3163
+ this.value = null;
3164
+ this.rank = -1;
3165
+ } else {
3166
+ let top = this.heap[0];
3167
+ this.from = top.from;
3168
+ this.to = top.to;
3169
+ this.value = top.value;
3170
+ this.rank = top.rank;
3171
+ if (top.value) top.next();
3172
+ heapBubble(this.heap, 0);
3173
+ }
3174
+ }
3175
+ };
3176
+ function heapBubble(heap, index) {
3177
+ for (let cur = heap[index];;) {
3178
+ let childIndex = (index << 1) + 1;
3179
+ if (childIndex >= heap.length) break;
3180
+ let child = heap[childIndex];
3181
+ if (childIndex + 1 < heap.length && child.compare(heap[childIndex + 1]) >= 0) {
3182
+ child = heap[childIndex + 1];
3183
+ childIndex++;
3184
+ }
3185
+ if (cur.compare(child) < 0) break;
3186
+ heap[childIndex] = cur;
3187
+ heap[index] = child;
3188
+ index = childIndex;
3189
+ }
3190
+ }
3191
+ var SpanCursor = class {
3192
+ constructor(sets, skip, minPoint) {
3193
+ this.minPoint = minPoint;
3194
+ this.active = [];
3195
+ this.activeTo = [];
3196
+ this.activeRank = [];
3197
+ this.minActive = -1;
3198
+ this.point = null;
3199
+ this.pointFrom = 0;
3200
+ this.pointRank = 0;
3201
+ this.to = -1e9;
3202
+ this.endSide = 0;
3203
+ this.openStart = -1;
3204
+ this.cursor = HeapCursor.from(sets, skip, minPoint);
3205
+ }
3206
+ goto(pos, side = -1e9) {
3207
+ this.cursor.goto(pos, side);
3208
+ this.active.length = this.activeTo.length = this.activeRank.length = 0;
3209
+ this.minActive = -1;
3210
+ this.to = pos;
3211
+ this.endSide = side;
3212
+ this.openStart = -1;
3213
+ this.next();
3214
+ return this;
3215
+ }
3216
+ forward(pos, side) {
3217
+ while (this.minActive > -1 && (this.activeTo[this.minActive] - pos || this.active[this.minActive].endSide - side) < 0) this.removeActive(this.minActive);
3218
+ this.cursor.forward(pos, side);
3219
+ }
3220
+ removeActive(index) {
3221
+ remove(this.active, index);
3222
+ remove(this.activeTo, index);
3223
+ remove(this.activeRank, index);
3224
+ this.minActive = findMinIndex(this.active, this.activeTo);
3225
+ }
3226
+ addActive(trackOpen) {
3227
+ let i = 0, { value, to, rank } = this.cursor;
3228
+ while (i < this.activeRank.length && (rank - this.activeRank[i] || to - this.activeTo[i]) > 0) i++;
3229
+ insert(this.active, i, value);
3230
+ insert(this.activeTo, i, to);
3231
+ insert(this.activeRank, i, rank);
3232
+ if (trackOpen) insert(trackOpen, i, this.cursor.from);
3233
+ this.minActive = findMinIndex(this.active, this.activeTo);
3234
+ }
3235
+ next() {
3236
+ let from = this.to, wasPoint = this.point;
3237
+ this.point = null;
3238
+ let trackOpen = this.openStart < 0 ? [] : null;
3239
+ for (;;) {
3240
+ let a = this.minActive;
3241
+ if (a > -1 && (this.activeTo[a] - this.cursor.from || this.active[a].endSide - this.cursor.startSide) < 0) {
3242
+ if (this.activeTo[a] > from) {
3243
+ this.to = this.activeTo[a];
3244
+ this.endSide = this.active[a].endSide;
3245
+ break;
3246
+ }
3247
+ this.removeActive(a);
3248
+ if (trackOpen) remove(trackOpen, a);
3249
+ } else if (!this.cursor.value) {
3250
+ this.to = this.endSide = 1e9;
3251
+ break;
3252
+ } else if (this.cursor.from > from) {
3253
+ this.to = this.cursor.from;
3254
+ this.endSide = this.cursor.startSide;
3255
+ break;
3256
+ } else {
3257
+ let nextVal = this.cursor.value;
3258
+ if (!nextVal.point) {
3259
+ this.addActive(trackOpen);
3260
+ this.cursor.next();
3261
+ } else if (wasPoint && this.cursor.to == this.to && this.cursor.from < this.cursor.to) this.cursor.next();
3262
+ else {
3263
+ this.point = nextVal;
3264
+ this.pointFrom = this.cursor.from;
3265
+ this.pointRank = this.cursor.rank;
3266
+ this.to = this.cursor.to;
3267
+ this.endSide = nextVal.endSide;
3268
+ this.cursor.next();
3269
+ this.forward(this.to, this.endSide);
3270
+ break;
3271
+ }
3272
+ }
3273
+ }
3274
+ if (trackOpen) {
3275
+ this.openStart = 0;
3276
+ for (let i = trackOpen.length - 1; i >= 0 && trackOpen[i] < from; i--) this.openStart++;
3277
+ }
3278
+ }
3279
+ activeForPoint(to) {
3280
+ if (!this.active.length) return this.active;
3281
+ let active = [];
3282
+ for (let i = this.active.length - 1; i >= 0; i--) {
3283
+ if (this.activeRank[i] < this.pointRank) break;
3284
+ if (this.activeTo[i] > to || this.activeTo[i] == to && this.active[i].endSide >= this.point.endSide) active.push(this.active[i]);
3285
+ }
3286
+ return active.reverse();
3287
+ }
3288
+ openEnd(to) {
3289
+ let open = 0;
3290
+ for (let i = this.activeTo.length - 1; i >= 0 && this.activeTo[i] > to; i--) open++;
3291
+ return open;
3292
+ }
3293
+ };
3294
+ function compare(a, startA, b, startB, length, comparator) {
3295
+ a.goto(startA);
3296
+ b.goto(startB);
3297
+ let endB = startB + length;
3298
+ let pos = startB, dPos = startB - startA;
3299
+ let bounds = !!comparator.boundChange;
3300
+ for (let boundChange = false;;) {
3301
+ let dEnd = a.to + dPos - b.to, diff = dEnd || a.endSide - b.endSide;
3302
+ let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
3303
+ if (a.point || b.point) {
3304
+ if (!(a.point && b.point && cmpVal(a.point, b.point) && sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to)))) comparator.comparePoint(pos, clipEnd, a.point, b.point);
3305
+ boundChange = false;
3306
+ } else {
3307
+ if (boundChange) comparator.boundChange(pos);
3308
+ if (clipEnd > pos && !sameValues(a.active, b.active)) comparator.compareRange(pos, clipEnd, a.active, b.active);
3309
+ if (bounds && clipEnd < endB && (dEnd || a.openEnd(end) != b.openEnd(end))) boundChange = true;
3310
+ }
3311
+ if (end > endB) break;
3312
+ pos = end;
3313
+ if (diff <= 0) a.next();
3314
+ if (diff >= 0) b.next();
3315
+ }
3316
+ }
3317
+ function sameValues(a, b) {
3318
+ if (a.length != b.length) return false;
3319
+ for (let i = 0; i < a.length; i++) if (a[i] != b[i] && !cmpVal(a[i], b[i])) return false;
3320
+ return true;
3321
+ }
3322
+ function remove(array, index) {
3323
+ for (let i = index, e = array.length - 1; i < e; i++) array[i] = array[i + 1];
3324
+ array.pop();
3325
+ }
3326
+ function insert(array, index, value) {
3327
+ for (let i = array.length - 1; i >= index; i--) array[i + 1] = array[i];
3328
+ array[index] = value;
3329
+ }
3330
+ function findMinIndex(value, array) {
3331
+ let found = -1, foundPos = 1e9;
3332
+ for (let i = 0; i < array.length; i++) if ((array[i] - foundPos || value[i].endSide - value[found].endSide) < 0) {
3333
+ found = i;
3334
+ foundPos = array[i];
3335
+ }
3336
+ return found;
3337
+ }
3338
+ /**
3339
+ Count the column position at the given offset into the string,
3340
+ taking extending characters and tab size into account.
3341
+ */
3342
+ function countColumn(string, tabSize, to = string.length) {
3343
+ let n = 0;
3344
+ for (let i = 0; i < to && i < string.length;) if (string.charCodeAt(i) == 9) {
3345
+ n += tabSize - n % tabSize;
3346
+ i++;
3347
+ } else {
3348
+ n++;
3349
+ i = findClusterBreak(string, i);
3350
+ }
3351
+ return n;
3352
+ }
3353
+ /**
3354
+ Find the offset that corresponds to the given column position in a
3355
+ string, taking extending characters and tab size into account. By
3356
+ default, the string length is returned when it is too short to
3357
+ reach the column. Pass `strict` true to make it return -1 in that
3358
+ situation.
3359
+ */
3360
+ function findColumn(string, col, tabSize, strict) {
3361
+ for (let i = 0, n = 0;;) {
3362
+ if (n >= col) return i;
3363
+ if (i == string.length) break;
3364
+ n += string.charCodeAt(i) == 9 ? tabSize - n % tabSize : 1;
3365
+ i = findClusterBreak(string, i);
3366
+ }
3367
+ return strict === true ? -1 : string.length;
3368
+ }
3369
+ //#endregion
3370
+ export { Annotation, ChangeDesc, ChangeSet, CharCategory, Compartment, EditorSelection, EditorState, Facet, MapMode, Prec, RangeSet, RangeSetBuilder, RangeValue, StateEffect, StateField, Text, Transaction, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };
3371
+
3372
+ //# sourceMappingURL=index.js.map