@maketribe/ms-app 3.0.35 → 3.0.37

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