@code0-tech/pictor 0.0.0-mvp.40 → 0.0.0-mvp.42

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 (56) hide show
  1. package/dist/assets/components/data-table/DataTable.style.css +1 -0
  2. package/dist/assets/components/menu/Menu.style.css +1 -1
  3. package/dist/components/d-flow/DFlow.service.js +80 -100
  4. package/dist/components/d-flow-data-type/DFlowDataType.service.js +6 -7
  5. package/dist/components/d-flow-data-type/rules/DFlowDataTypeContainsKeyRule.d.ts +1 -1
  6. package/dist/components/d-flow-data-type/rules/DFlowDataTypeContainsKeyRule.js +15 -15
  7. package/dist/components/d-flow-data-type/rules/DFlowDataTypeContainsTypeRule.d.ts +1 -1
  8. package/dist/components/d-flow-data-type/rules/DFlowDataTypeContainsTypeRule.js +17 -17
  9. package/dist/components/d-flow-data-type/rules/DFlowDataTypeParentRule.d.ts +1 -1
  10. package/dist/components/d-flow-data-type/rules/DFlowDataTypeParentRule.js +1 -1
  11. package/dist/components/d-flow-data-type/rules/DFlowDataTypeReturnTypeRule.d.ts +2 -1
  12. package/dist/components/d-flow-data-type/rules/DFlowDataTypeReturnTypeRule.js +87 -85
  13. package/dist/components/d-flow-data-type/rules/DFlowDataTypeRule.d.ts +2 -1
  14. package/dist/components/d-flow-function/DFlowFunction.input.hook.d.ts +2 -1
  15. package/dist/components/d-flow-function/DFlowFunction.input.hook.js +5 -5
  16. package/dist/components/d-flow-function/DFlowFunction.return.hook.d.ts +2 -1
  17. package/dist/components/d-flow-function/DFlowFunction.return.hook.js +5 -5
  18. package/dist/components/d-flow-input/DFlowInputDataTypeEditDialog.js +1 -1
  19. package/dist/components/d-flow-input/DFlowInputReferenceBadge.js +17 -17
  20. package/dist/components/d-flow-node/DFlowNode.return.hook.d.ts +5 -0
  21. package/dist/components/d-flow-node/DFlowNode.return.hook.js +27 -0
  22. package/dist/components/d-flow-suggestion/DFlowReferenceSuggestions.hook.js +90 -91
  23. package/dist/components/d-flow-validation/DDataTypeValidation.hook.js +1 -1
  24. package/dist/components/d-flow-validation/DNodeValidation.hook.js +33 -33
  25. package/dist/components/d-flow-validation/DValueValidation.hook.d.ts +2 -1
  26. package/dist/components/d-flow-validation/DValueValidation.hook.js +5 -5
  27. package/dist/components/d-project/DNamespaceProject.service.d.ts +2 -1
  28. package/dist/components/data-table/DataTable.d.ts +23 -0
  29. package/dist/components/data-table/DataTable.js +41 -0
  30. package/dist/components/data-table/DataTableColumn.d.ts +6 -0
  31. package/dist/components/data-table/DataTableColumn.js +22 -0
  32. package/dist/components/data-table/DataTableFilterInput.d.ts +18 -0
  33. package/dist/components/data-table/DataTableFilterInput.js +210 -0
  34. package/dist/components/data-table/DataTableFilterSuggestionMenu.d.ts +7 -0
  35. package/dist/components/data-table/DataTableFilterSuggestionMenu.js +53 -0
  36. package/dist/components/data-table/index.d.ts +4 -0
  37. package/dist/components/data-table/index.js +11 -0
  38. package/dist/components/editor/Editor.d.ts +9 -3
  39. package/dist/components/editor/Editor.js +249 -174
  40. package/dist/components/menu/Menu.d.ts +5 -1
  41. package/dist/components/menu/Menu.js +73 -57
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.js +182 -171
  44. package/dist/node_modules/@lezer/highlight/dist/index.js +132 -169
  45. package/dist/utils/generics.d.ts +2 -1
  46. package/dist/utils/generics.js +84 -80
  47. package/package.json +32 -21
  48. package/dist/node_modules/@codemirror/language/dist/index.js +0 -429
  49. package/dist/node_modules/@codemirror/lint/dist/index.js +0 -515
  50. package/dist/node_modules/@codemirror/state/dist/index.js +0 -2614
  51. package/dist/node_modules/@codemirror/view/dist/index.js +0 -6227
  52. package/dist/node_modules/@lezer/common/dist/index.js +0 -1357
  53. package/dist/node_modules/@marijn/find-cluster-break/src/index.js +0 -69
  54. package/dist/node_modules/crelt/index.js +0 -27
  55. package/dist/node_modules/style-mod/src/style-mod.js +0 -109
  56. package/dist/node_modules/w3c-keyname/index.js +0 -88
@@ -1,2614 +0,0 @@
1
- import { findClusterBreak as Le } from "../../../@marijn/find-cluster-break/src/index.js";
2
- class y {
3
- /**
4
- Get the line description around the given position.
5
- */
6
- lineAt(e) {
7
- if (e < 0 || e > this.length)
8
- throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);
9
- return this.lineInner(e, !1, 1, 0);
10
- }
11
- /**
12
- Get the description for the given (1-based) line number.
13
- */
14
- line(e) {
15
- if (e < 1 || e > this.lines)
16
- throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);
17
- return this.lineInner(e, !0, 1, 0);
18
- }
19
- /**
20
- Replace a range of the text with the given content.
21
- */
22
- replace(e, t, n) {
23
- [e, t] = J(this, e, t);
24
- let i = [];
25
- return this.decompose(
26
- 0,
27
- e,
28
- i,
29
- 2
30
- /* Open.To */
31
- ), n.length && n.decompose(
32
- 0,
33
- n.length,
34
- i,
35
- 3
36
- /* Open.To */
37
- ), this.decompose(
38
- t,
39
- this.length,
40
- i,
41
- 1
42
- /* Open.From */
43
- ), E.from(i, this.length - (t - e) + n.length);
44
- }
45
- /**
46
- Append another document to this one.
47
- */
48
- append(e) {
49
- return this.replace(this.length, this.length, e);
50
- }
51
- /**
52
- Retrieve the text between the given points.
53
- */
54
- slice(e, t = this.length) {
55
- [e, t] = J(this, e, t);
56
- let n = [];
57
- return this.decompose(e, t, n, 0), E.from(n, t - e);
58
- }
59
- /**
60
- Test whether this text is equal to another instance.
61
- */
62
- eq(e) {
63
- if (e == this)
64
- return !0;
65
- if (e.length != this.length || e.lines != this.lines)
66
- return !1;
67
- let t = this.scanIdentical(e, 1), n = this.length - this.scanIdentical(e, -1), i = new D(this), s = new D(e);
68
- for (let r = t, h = t; ; ) {
69
- if (i.next(r), s.next(r), r = 0, i.lineBreak != s.lineBreak || i.done != s.done || i.value != s.value)
70
- return !1;
71
- if (h += i.value.length, i.done || h >= n)
72
- return !0;
73
- }
74
- }
75
- /**
76
- Iterate over the text. When `dir` is `-1`, iteration happens
77
- from end to start. This will return lines and the breaks between
78
- them as separate strings.
79
- */
80
- iter(e = 1) {
81
- return new D(this, e);
82
- }
83
- /**
84
- Iterate over a range of the text. When `from` > `to`, the
85
- iterator will run in reverse.
86
- */
87
- iterRange(e, t = this.length) {
88
- return new Ie(this, e, t);
89
- }
90
- /**
91
- Return a cursor that iterates over the given range of lines,
92
- _without_ returning the line breaks between, and yielding empty
93
- strings for empty lines.
94
-
95
- When `from` and `to` are given, they should be 1-based line numbers.
96
- */
97
- iterLines(e, t) {
98
- let n;
99
- if (e == null)
100
- n = this.iter();
101
- else {
102
- t == null && (t = this.lines + 1);
103
- let i = this.line(e).from;
104
- n = this.iterRange(i, Math.max(i, t == this.lines + 1 ? this.length : t <= 1 ? 0 : this.line(t - 1).to));
105
- }
106
- return new Pe(n);
107
- }
108
- /**
109
- Return the document as a string, using newline characters to
110
- separate lines.
111
- */
112
- toString() {
113
- return this.sliceString(0);
114
- }
115
- /**
116
- Convert the document to an array of lines (which can be
117
- deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
118
- */
119
- toJSON() {
120
- let e = [];
121
- return this.flatten(e), e;
122
- }
123
- /**
124
- @internal
125
- */
126
- constructor() {
127
- }
128
- /**
129
- Create a `Text` instance for the given array of lines.
130
- */
131
- static of(e) {
132
- if (e.length == 0)
133
- throw new RangeError("A document must have at least one line");
134
- return e.length == 1 && !e[0] ? y.empty : e.length <= 32 ? new m(e) : E.from(m.split(e, []));
135
- }
136
- }
137
- class m extends y {
138
- constructor(e, t = Ne(e)) {
139
- super(), this.text = e, this.length = t;
140
- }
141
- get lines() {
142
- return this.text.length;
143
- }
144
- get children() {
145
- return null;
146
- }
147
- lineInner(e, t, n, i) {
148
- for (let s = 0; ; s++) {
149
- let r = this.text[s], h = i + r.length;
150
- if ((t ? n : h) >= e)
151
- return new De(i, h, n, r);
152
- i = h + 1, n++;
153
- }
154
- }
155
- decompose(e, t, n, i) {
156
- let s = e <= 0 && t >= this.length ? this : new m(ve(this.text, e, t), Math.min(t, this.length) - Math.max(0, e));
157
- if (i & 1) {
158
- let r = n.pop(), h = Q(s.text, r.text.slice(), 0, s.length);
159
- if (h.length <= 32)
160
- n.push(new m(h, r.length + s.length));
161
- else {
162
- let o = h.length >> 1;
163
- n.push(new m(h.slice(0, o)), new m(h.slice(o)));
164
- }
165
- } else
166
- n.push(s);
167
- }
168
- replace(e, t, n) {
169
- if (!(n instanceof m))
170
- return super.replace(e, t, n);
171
- [e, t] = J(this, e, t);
172
- let i = Q(this.text, Q(n.text, ve(this.text, 0, e)), t), s = this.length + n.length - (t - e);
173
- return i.length <= 32 ? new m(i, s) : E.from(m.split(i, []), s);
174
- }
175
- sliceString(e, t = this.length, n = `
176
- `) {
177
- [e, t] = J(this, e, t);
178
- let i = "";
179
- for (let s = 0, r = 0; s <= t && r < this.text.length; r++) {
180
- let h = this.text[r], o = s + h.length;
181
- s > e && r && (i += n), e < o && t > s && (i += h.slice(Math.max(0, e - s), t - s)), s = o + 1;
182
- }
183
- return i;
184
- }
185
- flatten(e) {
186
- for (let t of this.text)
187
- e.push(t);
188
- }
189
- scanIdentical() {
190
- return 0;
191
- }
192
- static split(e, t) {
193
- let n = [], i = -1;
194
- for (let s of e)
195
- n.push(s), i += s.length + 1, n.length == 32 && (t.push(new m(n, i)), n = [], i = -1);
196
- return i > -1 && t.push(new m(n, i)), t;
197
- }
198
- }
199
- class E extends y {
200
- constructor(e, t) {
201
- super(), this.children = e, this.length = t, this.lines = 0;
202
- for (let n of e)
203
- this.lines += n.lines;
204
- }
205
- lineInner(e, t, n, i) {
206
- for (let s = 0; ; s++) {
207
- let r = this.children[s], h = i + r.length, o = n + r.lines - 1;
208
- if ((t ? o : h) >= e)
209
- return r.lineInner(e, t, n, i);
210
- i = h + 1, n = o + 1;
211
- }
212
- }
213
- decompose(e, t, n, i) {
214
- for (let s = 0, r = 0; r <= t && s < this.children.length; s++) {
215
- let h = this.children[s], o = r + h.length;
216
- if (e <= o && t >= r) {
217
- let a = i & ((r <= e ? 1 : 0) | (o >= t ? 2 : 0));
218
- r >= e && o <= t && !a ? n.push(h) : h.decompose(e - r, t - r, n, a);
219
- }
220
- r = o + 1;
221
- }
222
- }
223
- replace(e, t, n) {
224
- if ([e, t] = J(this, e, t), n.lines < this.lines)
225
- for (let i = 0, s = 0; i < this.children.length; i++) {
226
- let r = this.children[i], h = s + r.length;
227
- if (e >= s && t <= h) {
228
- let o = r.replace(e - s, t - s, n), a = this.lines - r.lines + o.lines;
229
- if (o.lines < a >> 4 && o.lines > a >> 6) {
230
- let u = this.children.slice();
231
- return u[i] = o, new E(u, this.length - (t - e) + n.length);
232
- }
233
- return super.replace(s, h, o);
234
- }
235
- s = h + 1;
236
- }
237
- return super.replace(e, t, n);
238
- }
239
- sliceString(e, t = this.length, n = `
240
- `) {
241
- [e, t] = J(this, e, t);
242
- let i = "";
243
- for (let s = 0, r = 0; s < this.children.length && r <= t; s++) {
244
- let h = this.children[s], o = r + h.length;
245
- r > e && s && (i += n), e < o && t > r && (i += h.sliceString(e - r, t - r, n)), r = o + 1;
246
- }
247
- return i;
248
- }
249
- flatten(e) {
250
- for (let t of this.children)
251
- t.flatten(e);
252
- }
253
- scanIdentical(e, t) {
254
- if (!(e instanceof E))
255
- return 0;
256
- let n = 0, [i, s, r, h] = t > 0 ? [0, 0, this.children.length, e.children.length] : [this.children.length - 1, e.children.length - 1, -1, -1];
257
- for (; ; i += t, s += t) {
258
- if (i == r || s == h)
259
- return n;
260
- let o = this.children[i], a = e.children[s];
261
- if (o != a)
262
- return n + o.scanIdentical(a, t);
263
- n += o.length + 1;
264
- }
265
- }
266
- static from(e, t = e.reduce((n, i) => n + i.length + 1, -1)) {
267
- let n = 0;
268
- for (let c of e)
269
- n += c.lines;
270
- if (n < 32) {
271
- let c = [];
272
- for (let g of e)
273
- g.flatten(c);
274
- return new m(c, t);
275
- }
276
- let i = Math.max(
277
- 32,
278
- n >> 5
279
- /* Tree.BranchShift */
280
- ), s = i << 1, r = i >> 1, h = [], o = 0, a = -1, u = [];
281
- function f(c) {
282
- let g;
283
- if (c.lines > s && c instanceof E)
284
- for (let O of c.children)
285
- f(O);
286
- else c.lines > r && (o > r || !o) ? (d(), h.push(c)) : c instanceof m && o && (g = u[u.length - 1]) instanceof m && c.lines + g.lines <= 32 ? (o += c.lines, a += c.length + 1, u[u.length - 1] = new m(g.text.concat(c.text), g.length + 1 + c.length)) : (o + c.lines > i && d(), o += c.lines, a += c.length + 1, u.push(c));
287
- }
288
- function d() {
289
- o != 0 && (h.push(u.length == 1 ? u[0] : E.from(u, a)), a = -1, o = u.length = 0);
290
- }
291
- for (let c of e)
292
- f(c);
293
- return d(), h.length == 1 ? h[0] : new E(h, t);
294
- }
295
- }
296
- y.empty = /* @__PURE__ */ new m([""], 0);
297
- function Ne(l) {
298
- let e = -1;
299
- for (let t of l)
300
- e += t.length + 1;
301
- return e;
302
- }
303
- function Q(l, e, t = 0, n = 1e9) {
304
- for (let i = 0, s = 0, r = !0; s < l.length && i <= n; s++) {
305
- let h = l[s], o = i + h.length;
306
- o >= t && (o > n && (h = h.slice(0, n - i)), i < t && (h = h.slice(t - i)), r ? (e[e.length - 1] += h, r = !1) : e.push(h)), i = o + 1;
307
- }
308
- return e;
309
- }
310
- function ve(l, e, t) {
311
- return Q(l, [""], e, t);
312
- }
313
- class D {
314
- constructor(e, t = 1) {
315
- this.dir = t, this.done = !1, this.lineBreak = !1, this.value = "", this.nodes = [e], this.offsets = [t > 0 ? 1 : (e instanceof m ? e.text.length : e.children.length) << 1];
316
- }
317
- nextInner(e, t) {
318
- for (this.done = this.lineBreak = !1; ; ) {
319
- let n = this.nodes.length - 1, i = this.nodes[n], s = this.offsets[n], r = s >> 1, h = i instanceof m ? i.text.length : i.children.length;
320
- if (r == (t > 0 ? h : 0)) {
321
- if (n == 0)
322
- return this.done = !0, this.value = "", this;
323
- t > 0 && this.offsets[n - 1]++, this.nodes.pop(), this.offsets.pop();
324
- } else if ((s & 1) == (t > 0 ? 0 : 1)) {
325
- if (this.offsets[n] += t, e == 0)
326
- return this.lineBreak = !0, this.value = `
327
- `, this;
328
- e--;
329
- } else if (i instanceof m) {
330
- let o = i.text[r + (t < 0 ? -1 : 0)];
331
- if (this.offsets[n] += t, o.length > Math.max(0, e))
332
- return this.value = e == 0 ? o : t > 0 ? o.slice(e) : o.slice(0, o.length - e), this;
333
- e -= o.length;
334
- } else {
335
- let o = i.children[r + (t < 0 ? -1 : 0)];
336
- e > o.length ? (e -= o.length, this.offsets[n] += t) : (t < 0 && this.offsets[n]--, this.nodes.push(o), this.offsets.push(t > 0 ? 1 : (o instanceof m ? o.text.length : o.children.length) << 1));
337
- }
338
- }
339
- }
340
- next(e = 0) {
341
- return e < 0 && (this.nextInner(-e, -this.dir), e = this.value.length), this.nextInner(e, this.dir);
342
- }
343
- }
344
- class Ie {
345
- constructor(e, t, n) {
346
- this.value = "", this.done = !1, this.cursor = new D(e, t > n ? -1 : 1), this.pos = t > n ? e.length : 0, this.from = Math.min(t, n), this.to = Math.max(t, n);
347
- }
348
- nextInner(e, t) {
349
- if (t < 0 ? this.pos <= this.from : this.pos >= this.to)
350
- return this.value = "", this.done = !0, this;
351
- e += Math.max(0, t < 0 ? this.pos - this.to : this.from - this.pos);
352
- let n = t < 0 ? this.pos - this.from : this.to - this.pos;
353
- e > n && (e = n), n -= e;
354
- let { value: i } = this.cursor.next(e);
355
- return this.pos += (i.length + e) * t, this.value = i.length <= n ? i : t < 0 ? i.slice(i.length - n) : i.slice(0, n), this.done = !this.value, this;
356
- }
357
- next(e = 0) {
358
- return e < 0 ? e = Math.max(e, this.from - this.pos) : e > 0 && (e = Math.min(e, this.to - this.pos)), this.nextInner(e, this.cursor.dir);
359
- }
360
- get lineBreak() {
361
- return this.cursor.lineBreak && this.value != "";
362
- }
363
- }
364
- class Pe {
365
- constructor(e) {
366
- this.inner = e, this.afterBreak = !0, this.value = "", this.done = !1;
367
- }
368
- next(e = 0) {
369
- let { done: t, lineBreak: n, value: i } = this.inner.next(e);
370
- return t && this.afterBreak ? (this.value = "", this.afterBreak = !1) : t ? (this.done = !0, this.value = "") : n ? this.afterBreak ? this.value = "" : (this.afterBreak = !0, this.next()) : (this.value = i, this.afterBreak = !1), this;
371
- }
372
- get lineBreak() {
373
- return !1;
374
- }
375
- }
376
- typeof Symbol < "u" && (y.prototype[Symbol.iterator] = function() {
377
- return this.iter();
378
- }, D.prototype[Symbol.iterator] = Ie.prototype[Symbol.iterator] = Pe.prototype[Symbol.iterator] = function() {
379
- return this;
380
- });
381
- class De {
382
- /**
383
- @internal
384
- */
385
- constructor(e, t, n, i) {
386
- this.from = e, this.to = t, this.number = n, this.text = i;
387
- }
388
- /**
389
- The length of the line (not including any line break after it).
390
- */
391
- get length() {
392
- return this.to - this.from;
393
- }
394
- }
395
- function J(l, e, t) {
396
- return e = Math.max(0, Math.min(l.length, e)), [e, Math.max(e, Math.min(l.length, t))];
397
- }
398
- function ie(l, e, t = !0, n = !0) {
399
- return Le(l, e, t, n);
400
- }
401
- const se = /\r\n?|\n/;
402
- var M = /* @__PURE__ */ (function(l) {
403
- return l[l.Simple = 0] = "Simple", l[l.TrackDel = 1] = "TrackDel", l[l.TrackBefore = 2] = "TrackBefore", l[l.TrackAfter = 3] = "TrackAfter", l;
404
- })(M || (M = {}));
405
- class b {
406
- // Sections are encoded as pairs of integers. The first is the
407
- // length in the current document, and the second is -1 for
408
- // unaffected sections, and the length of the replacement content
409
- // otherwise. So an insertion would be (0, n>0), a deletion (n>0,
410
- // 0), and a replacement two positive numbers.
411
- /**
412
- @internal
413
- */
414
- constructor(e) {
415
- this.sections = e;
416
- }
417
- /**
418
- The length of the document before the change.
419
- */
420
- get length() {
421
- let e = 0;
422
- for (let t = 0; t < this.sections.length; t += 2)
423
- e += this.sections[t];
424
- return e;
425
- }
426
- /**
427
- The length of the document after the change.
428
- */
429
- get newLength() {
430
- let e = 0;
431
- for (let t = 0; t < this.sections.length; t += 2) {
432
- let n = this.sections[t + 1];
433
- e += n < 0 ? this.sections[t] : n;
434
- }
435
- return e;
436
- }
437
- /**
438
- False when there are actual changes in this set.
439
- */
440
- get empty() {
441
- return this.sections.length == 0 || this.sections.length == 2 && this.sections[1] < 0;
442
- }
443
- /**
444
- Iterate over the unchanged parts left by these changes. `posA`
445
- provides the position of the range in the old document, `posB`
446
- the new position in the changed document.
447
- */
448
- iterGaps(e) {
449
- for (let t = 0, n = 0, i = 0; t < this.sections.length; ) {
450
- let s = this.sections[t++], r = this.sections[t++];
451
- r < 0 ? (e(n, i, s), i += s) : i += r, n += s;
452
- }
453
- }
454
- /**
455
- Iterate over the ranges changed by these changes. (See
456
- [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
457
- variant that also provides you with the inserted text.)
458
- `fromA`/`toA` provides the extent of the change in the starting
459
- document, `fromB`/`toB` the extent of the replacement in the
460
- changed document.
461
-
462
- When `individual` is true, adjacent changes (which are kept
463
- separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
464
- reported separately.
465
- */
466
- iterChangedRanges(e, t = !1) {
467
- re(this, e, t);
468
- }
469
- /**
470
- Get a description of the inverted form of these changes.
471
- */
472
- get invertedDesc() {
473
- let e = [];
474
- for (let t = 0; t < this.sections.length; ) {
475
- let n = this.sections[t++], i = this.sections[t++];
476
- i < 0 ? e.push(n, i) : e.push(i, n);
477
- }
478
- return new b(e);
479
- }
480
- /**
481
- Compute the combined effect of applying another set of changes
482
- after this one. The length of the document after this set should
483
- match the length before `other`.
484
- */
485
- composeDesc(e) {
486
- return this.empty ? e : e.empty ? this : Ae(this, e);
487
- }
488
- /**
489
- Map this description, which should start with the same document
490
- as `other`, over another set of changes, so that it can be
491
- applied after it. When `before` is true, map as if the changes
492
- in `this` happened before the ones in `other`.
493
- */
494
- mapDesc(e, t = !1) {
495
- return e.empty ? this : le(this, e, t);
496
- }
497
- mapPos(e, t = -1, n = M.Simple) {
498
- let i = 0, s = 0;
499
- for (let r = 0; r < this.sections.length; ) {
500
- let h = this.sections[r++], o = this.sections[r++], a = i + h;
501
- if (o < 0) {
502
- if (a > e)
503
- return s + (e - i);
504
- s += h;
505
- } else {
506
- if (n != M.Simple && a >= e && (n == M.TrackDel && i < e && a > e || n == M.TrackBefore && i < e || n == M.TrackAfter && a > e))
507
- return null;
508
- if (a > e || a == e && t < 0 && !h)
509
- return e == i || t < 0 ? s : s + o;
510
- s += o;
511
- }
512
- i = a;
513
- }
514
- if (e > i)
515
- throw new RangeError(`Position ${e} is out of range for changeset of length ${i}`);
516
- return s;
517
- }
518
- /**
519
- Check whether these changes touch a given range. When one of the
520
- changes entirely covers the range, the string `"cover"` is
521
- returned.
522
- */
523
- touchesRange(e, t = e) {
524
- for (let n = 0, i = 0; n < this.sections.length && i <= t; ) {
525
- let s = this.sections[n++], r = this.sections[n++], h = i + s;
526
- if (r >= 0 && i <= t && h >= e)
527
- return i < e && h > t ? "cover" : !0;
528
- i = h;
529
- }
530
- return !1;
531
- }
532
- /**
533
- @internal
534
- */
535
- toString() {
536
- let e = "";
537
- for (let t = 0; t < this.sections.length; ) {
538
- let n = this.sections[t++], i = this.sections[t++];
539
- e += (e ? " " : "") + n + (i >= 0 ? ":" + i : "");
540
- }
541
- return e;
542
- }
543
- /**
544
- Serialize this change desc to a JSON-representable value.
545
- */
546
- toJSON() {
547
- return this.sections;
548
- }
549
- /**
550
- Create a change desc from its JSON representation (as produced
551
- by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).
552
- */
553
- static fromJSON(e) {
554
- if (!Array.isArray(e) || e.length % 2 || e.some((t) => typeof t != "number"))
555
- throw new RangeError("Invalid JSON representation of ChangeDesc");
556
- return new b(e);
557
- }
558
- /**
559
- @internal
560
- */
561
- static create(e) {
562
- return new b(e);
563
- }
564
- }
565
- class k extends b {
566
- constructor(e, t) {
567
- super(e), this.inserted = t;
568
- }
569
- /**
570
- Apply the changes to a document, returning the modified
571
- document.
572
- */
573
- apply(e) {
574
- if (this.length != e.length)
575
- throw new RangeError("Applying change set to a document with the wrong length");
576
- return re(this, (t, n, i, s, r) => e = e.replace(i, i + (n - t), r), !1), e;
577
- }
578
- mapDesc(e, t = !1) {
579
- return le(this, e, t, !0);
580
- }
581
- /**
582
- Given the document as it existed _before_ the changes, return a
583
- change set that represents the inverse of this set, which could
584
- be used to go from the document created by the changes back to
585
- the document as it existed before the changes.
586
- */
587
- invert(e) {
588
- let t = this.sections.slice(), n = [];
589
- for (let i = 0, s = 0; i < t.length; i += 2) {
590
- let r = t[i], h = t[i + 1];
591
- if (h >= 0) {
592
- t[i] = h, t[i + 1] = r;
593
- let o = i >> 1;
594
- for (; n.length < o; )
595
- n.push(y.empty);
596
- n.push(r ? e.slice(s, s + r) : y.empty);
597
- }
598
- s += r;
599
- }
600
- return new k(t, n);
601
- }
602
- /**
603
- Combine two subsequent change sets into a single set. `other`
604
- must start in the document produced by `this`. If `this` goes
605
- `docA` → `docB` and `other` represents `docB` → `docC`, the
606
- returned value will represent the change `docA` → `docC`.
607
- */
608
- compose(e) {
609
- return this.empty ? e : e.empty ? this : Ae(this, e, !0);
610
- }
611
- /**
612
- Given another change set starting in the same document, maps this
613
- change set over the other, producing a new change set that can be
614
- applied to the document produced by applying `other`. When
615
- `before` is `true`, order changes as if `this` comes before
616
- `other`, otherwise (the default) treat `other` as coming first.
617
-
618
- Given two changes `A` and `B`, `A.compose(B.map(A))` and
619
- `B.compose(A.map(B, true))` will produce the same document. This
620
- provides a basic form of [operational
621
- transformation](https://en.wikipedia.org/wiki/Operational_transformation),
622
- and can be used for collaborative editing.
623
- */
624
- map(e, t = !1) {
625
- return e.empty ? this : le(this, e, t, !0);
626
- }
627
- /**
628
- Iterate over the changed ranges in the document, calling `f` for
629
- each, with the range in the original document (`fromA`-`toA`)
630
- and the range that replaces it in the new document
631
- (`fromB`-`toB`).
632
-
633
- When `individual` is true, adjacent changes are reported
634
- separately.
635
- */
636
- iterChanges(e, t = !1) {
637
- re(this, e, t);
638
- }
639
- /**
640
- Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
641
- set.
642
- */
643
- get desc() {
644
- return b.create(this.sections);
645
- }
646
- /**
647
- @internal
648
- */
649
- filter(e) {
650
- let t = [], n = [], i = [], s = new z(this);
651
- e: for (let r = 0, h = 0; ; ) {
652
- let o = r == e.length ? 1e9 : e[r++];
653
- for (; h < o || h == o && s.len == 0; ) {
654
- if (s.done)
655
- break e;
656
- let u = Math.min(s.len, o - h);
657
- x(i, u, -1);
658
- let f = s.ins == -1 ? -1 : s.off == 0 ? s.ins : 0;
659
- x(t, u, f), f > 0 && R(n, t, s.text), s.forward(u), h += u;
660
- }
661
- let a = e[r++];
662
- for (; h < a; ) {
663
- if (s.done)
664
- break e;
665
- let u = Math.min(s.len, a - h);
666
- x(t, u, -1), x(i, u, s.ins == -1 ? -1 : s.off == 0 ? s.ins : 0), s.forward(u), h += u;
667
- }
668
- }
669
- return {
670
- changes: new k(t, n),
671
- filtered: b.create(i)
672
- };
673
- }
674
- /**
675
- Serialize this change set to a JSON-representable value.
676
- */
677
- toJSON() {
678
- let e = [];
679
- for (let t = 0; t < this.sections.length; t += 2) {
680
- let n = this.sections[t], i = this.sections[t + 1];
681
- i < 0 ? e.push(n) : i == 0 ? e.push([n]) : e.push([n].concat(this.inserted[t >> 1].toJSON()));
682
- }
683
- return e;
684
- }
685
- /**
686
- Create a change set for the given changes, for a document of the
687
- given length, using `lineSep` as line separator.
688
- */
689
- static of(e, t, n) {
690
- let i = [], s = [], r = 0, h = null;
691
- function o(u = !1) {
692
- if (!u && !i.length)
693
- return;
694
- r < t && x(i, t - r, -1);
695
- let f = new k(i, s);
696
- h = h ? h.compose(f.map(h)) : f, i = [], s = [], r = 0;
697
- }
698
- function a(u) {
699
- if (Array.isArray(u))
700
- for (let f of u)
701
- a(f);
702
- else if (u instanceof k) {
703
- if (u.length != t)
704
- throw new RangeError(`Mismatched change set length (got ${u.length}, expected ${t})`);
705
- o(), h = h ? h.compose(u.map(h)) : u;
706
- } else {
707
- let { from: f, to: d = f, insert: c } = u;
708
- if (f > d || f < 0 || d > t)
709
- throw new RangeError(`Invalid change range ${f} to ${d} (in doc of length ${t})`);
710
- let g = c ? typeof c == "string" ? y.of(c.split(n || se)) : c : y.empty, O = g.length;
711
- if (f == d && O == 0)
712
- return;
713
- f < r && o(), f > r && x(i, f - r, -1), x(i, d - f, O), R(s, i, g), r = d;
714
- }
715
- }
716
- return a(e), o(!h), h;
717
- }
718
- /**
719
- Create an empty changeset of the given length.
720
- */
721
- static empty(e) {
722
- return new k(e ? [e, -1] : [], []);
723
- }
724
- /**
725
- Create a changeset from its JSON representation (as produced by
726
- [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
727
- */
728
- static fromJSON(e) {
729
- if (!Array.isArray(e))
730
- throw new RangeError("Invalid JSON representation of ChangeSet");
731
- let t = [], n = [];
732
- for (let i = 0; i < e.length; i++) {
733
- let s = e[i];
734
- if (typeof s == "number")
735
- t.push(s, -1);
736
- else {
737
- if (!Array.isArray(s) || typeof s[0] != "number" || s.some((r, h) => h && typeof r != "string"))
738
- throw new RangeError("Invalid JSON representation of ChangeSet");
739
- if (s.length == 1)
740
- t.push(s[0], 0);
741
- else {
742
- for (; n.length < i; )
743
- n.push(y.empty);
744
- n[i] = y.of(s.slice(1)), t.push(s[0], n[i].length);
745
- }
746
- }
747
- }
748
- return new k(t, n);
749
- }
750
- /**
751
- @internal
752
- */
753
- static createSet(e, t) {
754
- return new k(e, t);
755
- }
756
- }
757
- function x(l, e, t, n = !1) {
758
- if (e == 0 && t <= 0)
759
- return;
760
- let i = l.length - 2;
761
- i >= 0 && t <= 0 && t == l[i + 1] ? l[i] += e : i >= 0 && e == 0 && l[i] == 0 ? l[i + 1] += t : n ? (l[i] += e, l[i + 1] += t) : l.push(e, t);
762
- }
763
- function R(l, e, t) {
764
- if (t.length == 0)
765
- return;
766
- let n = e.length - 2 >> 1;
767
- if (n < l.length)
768
- l[l.length - 1] = l[l.length - 1].append(t);
769
- else {
770
- for (; l.length < n; )
771
- l.push(y.empty);
772
- l.push(t);
773
- }
774
- }
775
- function re(l, e, t) {
776
- let n = l.inserted;
777
- for (let i = 0, s = 0, r = 0; r < l.sections.length; ) {
778
- let h = l.sections[r++], o = l.sections[r++];
779
- if (o < 0)
780
- i += h, s += h;
781
- else {
782
- let a = i, u = s, f = y.empty;
783
- for (; a += h, u += o, o && n && (f = f.append(n[r - 2 >> 1])), !(t || r == l.sections.length || l.sections[r + 1] < 0); )
784
- h = l.sections[r++], o = l.sections[r++];
785
- e(i, a, s, u, f), i = a, s = u;
786
- }
787
- }
788
- }
789
- function le(l, e, t, n = !1) {
790
- let i = [], s = n ? [] : null, r = new z(l), h = new z(e);
791
- for (let o = -1; ; ) {
792
- if (r.done && h.len || h.done && r.len)
793
- throw new Error("Mismatched change set lengths");
794
- if (r.ins == -1 && h.ins == -1) {
795
- let a = Math.min(r.len, h.len);
796
- x(i, a, -1), r.forward(a), h.forward(a);
797
- } else if (h.ins >= 0 && (r.ins < 0 || o == r.i || r.off == 0 && (h.len < r.len || h.len == r.len && !t))) {
798
- let a = h.len;
799
- for (x(i, h.ins, -1); a; ) {
800
- let u = Math.min(r.len, a);
801
- r.ins >= 0 && o < r.i && r.len <= u && (x(i, 0, r.ins), s && R(s, i, r.text), o = r.i), r.forward(u), a -= u;
802
- }
803
- h.next();
804
- } else if (r.ins >= 0) {
805
- let a = 0, u = r.len;
806
- for (; u; )
807
- if (h.ins == -1) {
808
- let f = Math.min(u, h.len);
809
- a += f, u -= f, h.forward(f);
810
- } else if (h.ins == 0 && h.len < u)
811
- u -= h.len, h.next();
812
- else
813
- break;
814
- x(i, a, o < r.i ? r.ins : 0), s && o < r.i && R(s, i, r.text), o = r.i, r.forward(r.len - u);
815
- } else {
816
- if (r.done && h.done)
817
- return s ? k.createSet(i, s) : b.create(i);
818
- throw new Error("Mismatched change set lengths");
819
- }
820
- }
821
- }
822
- function Ae(l, e, t = !1) {
823
- let n = [], i = t ? [] : null, s = new z(l), r = new z(e);
824
- for (let h = !1; ; ) {
825
- if (s.done && r.done)
826
- return i ? k.createSet(n, i) : b.create(n);
827
- if (s.ins == 0)
828
- x(n, s.len, 0, h), s.next();
829
- else if (r.len == 0 && !r.done)
830
- x(n, 0, r.ins, h), i && R(i, n, r.text), r.next();
831
- else {
832
- if (s.done || r.done)
833
- throw new Error("Mismatched change set lengths");
834
- {
835
- let o = Math.min(s.len2, r.len), a = n.length;
836
- if (s.ins == -1) {
837
- let u = r.ins == -1 ? -1 : r.off ? 0 : r.ins;
838
- x(n, o, u, h), i && u && R(i, n, r.text);
839
- } else r.ins == -1 ? (x(n, s.off ? 0 : s.len, o, h), i && R(i, n, s.textBit(o))) : (x(n, s.off ? 0 : s.len, r.off ? 0 : r.ins, h), i && !r.off && R(i, n, r.text));
840
- h = (s.ins > o || r.ins >= 0 && r.len > o) && (h || n.length > a), s.forward2(o), r.forward(o);
841
- }
842
- }
843
- }
844
- }
845
- class z {
846
- constructor(e) {
847
- this.set = e, this.i = 0, this.next();
848
- }
849
- next() {
850
- let { sections: e } = this.set;
851
- this.i < e.length ? (this.len = e[this.i++], this.ins = e[this.i++]) : (this.len = 0, this.ins = -2), this.off = 0;
852
- }
853
- get done() {
854
- return this.ins == -2;
855
- }
856
- get len2() {
857
- return this.ins < 0 ? this.len : this.ins;
858
- }
859
- get text() {
860
- let { inserted: e } = this.set, t = this.i - 2 >> 1;
861
- return t >= e.length ? y.empty : e[t];
862
- }
863
- textBit(e) {
864
- let { inserted: t } = this.set, n = this.i - 2 >> 1;
865
- return n >= t.length && !e ? y.empty : t[n].slice(this.off, e == null ? void 0 : this.off + e);
866
- }
867
- forward(e) {
868
- e == this.len ? this.next() : (this.len -= e, this.off += e);
869
- }
870
- forward2(e) {
871
- this.ins == -1 ? this.forward(e) : e == this.ins ? this.next() : (this.ins -= e, this.off += e);
872
- }
873
- }
874
- class C {
875
- constructor(e, t, n) {
876
- this.from = e, this.to = t, this.flags = n;
877
- }
878
- /**
879
- The anchor of the range—the side that doesn't move when you
880
- extend it.
881
- */
882
- get anchor() {
883
- return this.flags & 32 ? this.to : this.from;
884
- }
885
- /**
886
- The head of the range, which is moved when the range is
887
- [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
888
- */
889
- get head() {
890
- return this.flags & 32 ? this.from : this.to;
891
- }
892
- /**
893
- True when `anchor` and `head` are at the same position.
894
- */
895
- get empty() {
896
- return this.from == this.to;
897
- }
898
- /**
899
- If this is a cursor that is explicitly associated with the
900
- character on one of its sides, this returns the side. -1 means
901
- the character before its position, 1 the character after, and 0
902
- means no association.
903
- */
904
- get assoc() {
905
- return this.flags & 8 ? -1 : this.flags & 16 ? 1 : 0;
906
- }
907
- /**
908
- The bidirectional text level associated with this cursor, if
909
- any.
910
- */
911
- get bidiLevel() {
912
- let e = this.flags & 7;
913
- return e == 7 ? null : e;
914
- }
915
- /**
916
- The goal column (stored vertical offset) associated with a
917
- cursor. This is used to preserve the vertical position when
918
- [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
919
- lines of different length.
920
- */
921
- get goalColumn() {
922
- let e = this.flags >> 6;
923
- return e == 16777215 ? void 0 : e;
924
- }
925
- /**
926
- Map this range through a change, producing a valid range in the
927
- updated document.
928
- */
929
- map(e, t = -1) {
930
- let n, i;
931
- return this.empty ? n = i = e.mapPos(this.from, t) : (n = e.mapPos(this.from, 1), i = e.mapPos(this.to, -1)), n == this.from && i == this.to ? this : new C(n, i, this.flags);
932
- }
933
- /**
934
- Extend this range to cover at least `from` to `to`.
935
- */
936
- extend(e, t = e) {
937
- if (e <= this.anchor && t >= this.anchor)
938
- return p.range(e, t);
939
- let n = Math.abs(e - this.anchor) > Math.abs(t - this.anchor) ? e : t;
940
- return p.range(this.anchor, n);
941
- }
942
- /**
943
- Compare this range to another range.
944
- */
945
- eq(e, t = !1) {
946
- return this.anchor == e.anchor && this.head == e.head && this.goalColumn == e.goalColumn && (!t || !this.empty || this.assoc == e.assoc);
947
- }
948
- /**
949
- Return a JSON-serializable object representing the range.
950
- */
951
- toJSON() {
952
- return { anchor: this.anchor, head: this.head };
953
- }
954
- /**
955
- Convert a JSON representation of a range to a `SelectionRange`
956
- instance.
957
- */
958
- static fromJSON(e) {
959
- if (!e || typeof e.anchor != "number" || typeof e.head != "number")
960
- throw new RangeError("Invalid JSON representation for SelectionRange");
961
- return p.range(e.anchor, e.head);
962
- }
963
- /**
964
- @internal
965
- */
966
- static create(e, t, n) {
967
- return new C(e, t, n);
968
- }
969
- }
970
- class p {
971
- constructor(e, t) {
972
- this.ranges = e, this.mainIndex = t;
973
- }
974
- /**
975
- Map a selection through a change. Used to adjust the selection
976
- position for changes.
977
- */
978
- map(e, t = -1) {
979
- return e.empty ? this : p.create(this.ranges.map((n) => n.map(e, t)), this.mainIndex);
980
- }
981
- /**
982
- Compare this selection to another selection. By default, ranges
983
- are compared only by position. When `includeAssoc` is true,
984
- cursor ranges must also have the same
985
- [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
986
- */
987
- eq(e, t = !1) {
988
- if (this.ranges.length != e.ranges.length || this.mainIndex != e.mainIndex)
989
- return !1;
990
- for (let n = 0; n < this.ranges.length; n++)
991
- if (!this.ranges[n].eq(e.ranges[n], t))
992
- return !1;
993
- return !0;
994
- }
995
- /**
996
- Get the primary selection range. Usually, you should make sure
997
- your code applies to _all_ ranges, by using methods like
998
- [`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).
999
- */
1000
- get main() {
1001
- return this.ranges[this.mainIndex];
1002
- }
1003
- /**
1004
- Make sure the selection only has one range. Returns a selection
1005
- holding only the main range from this selection.
1006
- */
1007
- asSingle() {
1008
- return this.ranges.length == 1 ? this : new p([this.main], 0);
1009
- }
1010
- /**
1011
- Extend this selection with an extra range.
1012
- */
1013
- addRange(e, t = !0) {
1014
- return p.create([e].concat(this.ranges), t ? 0 : this.mainIndex + 1);
1015
- }
1016
- /**
1017
- Replace a given range with another range, and then normalize the
1018
- selection to merge and sort ranges if necessary.
1019
- */
1020
- replaceRange(e, t = this.mainIndex) {
1021
- let n = this.ranges.slice();
1022
- return n[t] = e, p.create(n, this.mainIndex);
1023
- }
1024
- /**
1025
- Convert this selection to an object that can be serialized to
1026
- JSON.
1027
- */
1028
- toJSON() {
1029
- return { ranges: this.ranges.map((e) => e.toJSON()), main: this.mainIndex };
1030
- }
1031
- /**
1032
- Create a selection from a JSON representation.
1033
- */
1034
- static fromJSON(e) {
1035
- if (!e || !Array.isArray(e.ranges) || typeof e.main != "number" || e.main >= e.ranges.length)
1036
- throw new RangeError("Invalid JSON representation for EditorSelection");
1037
- return new p(e.ranges.map((t) => C.fromJSON(t)), e.main);
1038
- }
1039
- /**
1040
- Create a selection holding a single range.
1041
- */
1042
- static single(e, t = e) {
1043
- return new p([p.range(e, t)], 0);
1044
- }
1045
- /**
1046
- Sort and merge the given set of ranges, creating a valid
1047
- selection.
1048
- */
1049
- static create(e, t = 0) {
1050
- if (e.length == 0)
1051
- throw new RangeError("A selection needs at least one range");
1052
- for (let n = 0, i = 0; i < e.length; i++) {
1053
- let s = e[i];
1054
- if (s.empty ? s.from <= n : s.from < n)
1055
- return p.normalized(e.slice(), t);
1056
- n = s.to;
1057
- }
1058
- return new p(e, t);
1059
- }
1060
- /**
1061
- Create a cursor selection range at the given position. You can
1062
- safely ignore the optional arguments in most situations.
1063
- */
1064
- static cursor(e, t = 0, n, i) {
1065
- return C.create(e, e, (t == 0 ? 0 : t < 0 ? 8 : 16) | (n == null ? 7 : Math.min(6, n)) | (i ?? 16777215) << 6);
1066
- }
1067
- /**
1068
- Create a selection range.
1069
- */
1070
- static range(e, t, n, i) {
1071
- let s = (n ?? 16777215) << 6 | (i == null ? 7 : Math.min(6, i));
1072
- return t < e ? C.create(t, e, 48 | s) : C.create(e, t, (t > e ? 8 : 0) | s);
1073
- }
1074
- /**
1075
- @internal
1076
- */
1077
- static normalized(e, t = 0) {
1078
- let n = e[t];
1079
- e.sort((i, s) => i.from - s.from), t = e.indexOf(n);
1080
- for (let i = 1; i < e.length; i++) {
1081
- let s = e[i], r = e[i - 1];
1082
- if (s.empty ? s.from <= r.to : s.from < r.to) {
1083
- let h = r.from, o = Math.max(s.to, r.to);
1084
- i <= t && t--, e.splice(--i, 2, s.anchor > s.head ? p.range(o, h) : p.range(h, o));
1085
- }
1086
- }
1087
- return new p(e, t);
1088
- }
1089
- }
1090
- function Oe(l, e) {
1091
- for (let t of l.ranges)
1092
- if (t.to > e)
1093
- throw new RangeError("Selection points outside of document");
1094
- }
1095
- let ge = 0;
1096
- class A {
1097
- constructor(e, t, n, i, s) {
1098
- this.combine = e, this.compareInput = t, this.compare = n, this.isStatic = i, this.id = ge++, this.default = e([]), this.extensions = typeof s == "function" ? s(this) : s;
1099
- }
1100
- /**
1101
- Returns a facet reader for this facet, which can be used to
1102
- [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
1103
- */
1104
- get reader() {
1105
- return this;
1106
- }
1107
- /**
1108
- Define a new facet.
1109
- */
1110
- static define(e = {}) {
1111
- return new A(e.combine || ((t) => t), e.compareInput || ((t, n) => t === n), e.compare || (e.combine ? (t, n) => t === n : pe), !!e.static, e.enables);
1112
- }
1113
- /**
1114
- Returns an extension that adds the given value to this facet.
1115
- */
1116
- of(e) {
1117
- return new X([], this, 0, e);
1118
- }
1119
- /**
1120
- Create an extension that computes a value for the facet from a
1121
- state. You must take care to declare the parts of the state that
1122
- this value depends on, since your function is only called again
1123
- for a new state when one of those parts changed.
1124
-
1125
- In cases where your value depends only on a single field, you'll
1126
- want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
1127
- */
1128
- compute(e, t) {
1129
- if (this.isStatic)
1130
- throw new Error("Can't compute a static facet");
1131
- return new X(e, this, 1, t);
1132
- }
1133
- /**
1134
- Create an extension that computes zero or more values for this
1135
- facet from a state.
1136
- */
1137
- computeN(e, t) {
1138
- if (this.isStatic)
1139
- throw new Error("Can't compute a static facet");
1140
- return new X(e, this, 2, t);
1141
- }
1142
- from(e, t) {
1143
- return t || (t = (n) => n), this.compute([e], (n) => t(n.field(e)));
1144
- }
1145
- }
1146
- function pe(l, e) {
1147
- return l == e || l.length == e.length && l.every((t, n) => t === e[n]);
1148
- }
1149
- class X {
1150
- constructor(e, t, n, i) {
1151
- this.dependencies = e, this.facet = t, this.type = n, this.value = i, this.id = ge++;
1152
- }
1153
- dynamicSlot(e) {
1154
- var t;
1155
- let n = this.value, i = this.facet.compareInput, s = this.id, r = e[s] >> 1, h = this.type == 2, o = !1, a = !1, u = [];
1156
- for (let f of this.dependencies)
1157
- f == "doc" ? o = !0 : f == "selection" ? a = !0 : (((t = e[f.id]) !== null && t !== void 0 ? t : 1) & 1) == 0 && u.push(e[f.id]);
1158
- return {
1159
- create(f) {
1160
- return f.values[r] = n(f), 1;
1161
- },
1162
- update(f, d) {
1163
- if (o && d.docChanged || a && (d.docChanged || d.selection) || he(f, u)) {
1164
- let c = n(f);
1165
- if (h ? !ye(c, f.values[r], i) : !i(c, f.values[r]))
1166
- return f.values[r] = c, 1;
1167
- }
1168
- return 0;
1169
- },
1170
- reconfigure: (f, d) => {
1171
- let c, g = d.config.address[s];
1172
- if (g != null) {
1173
- let O = Z(d, g);
1174
- if (this.dependencies.every((v) => v instanceof A ? d.facet(v) === f.facet(v) : v instanceof V ? d.field(v, !1) == f.field(v, !1) : !0) || (h ? ye(c = n(f), O, i) : i(c = n(f), O)))
1175
- return f.values[r] = O, 0;
1176
- } else
1177
- c = n(f);
1178
- return f.values[r] = c, 1;
1179
- }
1180
- };
1181
- }
1182
- }
1183
- function ye(l, e, t) {
1184
- if (l.length != e.length)
1185
- return !1;
1186
- for (let n = 0; n < l.length; n++)
1187
- if (!t(l[n], e[n]))
1188
- return !1;
1189
- return !0;
1190
- }
1191
- function he(l, e) {
1192
- let t = !1;
1193
- for (let n of e)
1194
- $(l, n) & 1 && (t = !0);
1195
- return t;
1196
- }
1197
- function $e(l, e, t) {
1198
- let n = t.map((o) => l[o.id]), i = t.map((o) => o.type), s = n.filter((o) => !(o & 1)), r = l[e.id] >> 1;
1199
- function h(o) {
1200
- let a = [];
1201
- for (let u = 0; u < n.length; u++) {
1202
- let f = Z(o, n[u]);
1203
- if (i[u] == 2)
1204
- for (let d of f)
1205
- a.push(d);
1206
- else
1207
- a.push(f);
1208
- }
1209
- return e.combine(a);
1210
- }
1211
- return {
1212
- create(o) {
1213
- for (let a of n)
1214
- $(o, a);
1215
- return o.values[r] = h(o), 1;
1216
- },
1217
- update(o, a) {
1218
- if (!he(o, s))
1219
- return 0;
1220
- let u = h(o);
1221
- return e.compare(u, o.values[r]) ? 0 : (o.values[r] = u, 1);
1222
- },
1223
- reconfigure(o, a) {
1224
- let u = he(o, n), f = a.config.facets[e.id], d = a.facet(e);
1225
- if (f && !u && pe(t, f))
1226
- return o.values[r] = d, 0;
1227
- let c = h(o);
1228
- return e.compare(c, d) ? (o.values[r] = d, 0) : (o.values[r] = c, 1);
1229
- }
1230
- };
1231
- }
1232
- const G = /* @__PURE__ */ A.define({ static: !0 });
1233
- class V {
1234
- constructor(e, t, n, i, s) {
1235
- this.id = e, this.createF = t, this.updateF = n, this.compareF = i, this.spec = s, this.provides = void 0;
1236
- }
1237
- /**
1238
- Define a state field.
1239
- */
1240
- static define(e) {
1241
- let t = new V(ge++, e.create, e.update, e.compare || ((n, i) => n === i), e);
1242
- return e.provide && (t.provides = e.provide(t)), t;
1243
- }
1244
- create(e) {
1245
- let t = e.facet(G).find((n) => n.field == this);
1246
- return (t?.create || this.createF)(e);
1247
- }
1248
- /**
1249
- @internal
1250
- */
1251
- slot(e) {
1252
- let t = e[this.id] >> 1;
1253
- return {
1254
- create: (n) => (n.values[t] = this.create(n), 1),
1255
- update: (n, i) => {
1256
- let s = n.values[t], r = this.updateF(s, i);
1257
- return this.compareF(s, r) ? 0 : (n.values[t] = r, 1);
1258
- },
1259
- reconfigure: (n, i) => {
1260
- let s = n.facet(G), r = i.facet(G), h;
1261
- return (h = s.find((o) => o.field == this)) && h != r.find((o) => o.field == this) ? (n.values[t] = h.create(n), 1) : i.config.address[this.id] != null ? (n.values[t] = i.field(this), 0) : (n.values[t] = this.create(n), 1);
1262
- }
1263
- };
1264
- }
1265
- /**
1266
- Returns an extension that enables this field and overrides the
1267
- way it is initialized. Can be useful when you need to provide a
1268
- non-default starting value for the field.
1269
- */
1270
- init(e) {
1271
- return [this, G.of({ field: this, create: e })];
1272
- }
1273
- /**
1274
- State field instances can be used as
1275
- [`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a
1276
- given state.
1277
- */
1278
- get extension() {
1279
- return this;
1280
- }
1281
- }
1282
- const B = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
1283
- function L(l) {
1284
- return (e) => new Ee(e, l);
1285
- }
1286
- const _e = {
1287
- /**
1288
- The highest precedence level, for extensions that should end up
1289
- near the start of the precedence ordering.
1290
- */
1291
- highest: /* @__PURE__ */ L(B.highest),
1292
- /**
1293
- A higher-than-default precedence, for extensions that should
1294
- come before those with default precedence.
1295
- */
1296
- high: /* @__PURE__ */ L(B.high),
1297
- /**
1298
- The default precedence, which is also used for extensions
1299
- without an explicit precedence.
1300
- */
1301
- default: /* @__PURE__ */ L(B.default),
1302
- /**
1303
- A lower-than-default precedence.
1304
- */
1305
- low: /* @__PURE__ */ L(B.low),
1306
- /**
1307
- The lowest precedence level. Meant for things that should end up
1308
- near the end of the extension order.
1309
- */
1310
- lowest: /* @__PURE__ */ L(B.lowest)
1311
- };
1312
- class Ee {
1313
- constructor(e, t) {
1314
- this.inner = e, this.prec = t;
1315
- }
1316
- }
1317
- class ee {
1318
- /**
1319
- Create an instance of this compartment to add to your [state
1320
- configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).
1321
- */
1322
- of(e) {
1323
- return new oe(this, e);
1324
- }
1325
- /**
1326
- Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
1327
- reconfigures this compartment.
1328
- */
1329
- reconfigure(e) {
1330
- return ee.reconfigure.of({ compartment: this, extension: e });
1331
- }
1332
- /**
1333
- Get the current content of the compartment in the state, or
1334
- `undefined` if it isn't present.
1335
- */
1336
- get(e) {
1337
- return e.config.compartments.get(this);
1338
- }
1339
- }
1340
- class oe {
1341
- constructor(e, t) {
1342
- this.compartment = e, this.inner = t;
1343
- }
1344
- }
1345
- class Y {
1346
- constructor(e, t, n, i, s, r) {
1347
- for (this.base = e, this.compartments = t, this.dynamicSlots = n, this.address = i, this.staticValues = s, this.facets = r, this.statusTemplate = []; this.statusTemplate.length < n.length; )
1348
- this.statusTemplate.push(
1349
- 0
1350
- /* SlotStatus.Unresolved */
1351
- );
1352
- }
1353
- staticFacet(e) {
1354
- let t = this.address[e.id];
1355
- return t == null ? e.default : this.staticValues[t >> 1];
1356
- }
1357
- static resolve(e, t, n) {
1358
- let i = [], s = /* @__PURE__ */ Object.create(null), r = /* @__PURE__ */ new Map();
1359
- for (let d of ze(e, t, r))
1360
- d instanceof V ? i.push(d) : (s[d.facet.id] || (s[d.facet.id] = [])).push(d);
1361
- let h = /* @__PURE__ */ Object.create(null), o = [], a = [];
1362
- for (let d of i)
1363
- h[d.id] = a.length << 1, a.push((c) => d.slot(c));
1364
- let u = n?.config.facets;
1365
- for (let d in s) {
1366
- let c = s[d], g = c[0].facet, O = u && u[d] || [];
1367
- if (c.every(
1368
- (v) => v.type == 0
1369
- /* Provider.Static */
1370
- ))
1371
- if (h[g.id] = o.length << 1 | 1, pe(O, c))
1372
- o.push(n.facet(g));
1373
- else {
1374
- let v = g.combine(c.map((te) => te.value));
1375
- o.push(n && g.compare(v, n.facet(g)) ? n.facet(g) : v);
1376
- }
1377
- else {
1378
- for (let v of c)
1379
- v.type == 0 ? (h[v.id] = o.length << 1 | 1, o.push(v.value)) : (h[v.id] = a.length << 1, a.push((te) => v.dynamicSlot(te)));
1380
- h[g.id] = a.length << 1, a.push((v) => $e(v, g, c));
1381
- }
1382
- }
1383
- let f = a.map((d) => d(h));
1384
- return new Y(e, r, f, h, o, s);
1385
- }
1386
- }
1387
- function ze(l, e, t) {
1388
- let n = [[], [], [], [], []], i = /* @__PURE__ */ new Map();
1389
- function s(r, h) {
1390
- let o = i.get(r);
1391
- if (o != null) {
1392
- if (o <= h)
1393
- return;
1394
- let a = n[o].indexOf(r);
1395
- a > -1 && n[o].splice(a, 1), r instanceof oe && t.delete(r.compartment);
1396
- }
1397
- if (i.set(r, h), Array.isArray(r))
1398
- for (let a of r)
1399
- s(a, h);
1400
- else if (r instanceof oe) {
1401
- if (t.has(r.compartment))
1402
- throw new RangeError("Duplicate use of compartment in extensions");
1403
- let a = e.get(r.compartment) || r.inner;
1404
- t.set(r.compartment, a), s(a, h);
1405
- } else if (r instanceof Ee)
1406
- s(r.inner, r.prec);
1407
- else if (r instanceof V)
1408
- n[h].push(r), r.provides && s(r.provides, h);
1409
- else if (r instanceof X)
1410
- n[h].push(r), r.facet.extensions && s(r.facet.extensions, B.default);
1411
- else {
1412
- let a = r.extension;
1413
- if (!a)
1414
- throw new Error(`Unrecognized extension value in extension set (${r}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
1415
- s(a, h);
1416
- }
1417
- }
1418
- return s(l, B.default), n.reduce((r, h) => r.concat(h));
1419
- }
1420
- function $(l, e) {
1421
- if (e & 1)
1422
- return 2;
1423
- let t = e >> 1, n = l.status[t];
1424
- if (n == 4)
1425
- throw new Error("Cyclic dependency between fields and/or facets");
1426
- if (n & 2)
1427
- return n;
1428
- l.status[t] = 4;
1429
- let i = l.computeSlot(l, l.config.dynamicSlots[t]);
1430
- return l.status[t] = 2 | i;
1431
- }
1432
- function Z(l, e) {
1433
- return e & 1 ? l.config.staticValues[e >> 1] : l.values[e >> 1];
1434
- }
1435
- const be = /* @__PURE__ */ A.define(), ae = /* @__PURE__ */ A.define({
1436
- combine: (l) => l.some((e) => e),
1437
- static: !0
1438
- }), Me = /* @__PURE__ */ A.define({
1439
- combine: (l) => l.length ? l[0] : void 0,
1440
- static: !0
1441
- }), Re = /* @__PURE__ */ A.define(), Te = /* @__PURE__ */ A.define(), Be = /* @__PURE__ */ A.define(), Ce = /* @__PURE__ */ A.define({
1442
- combine: (l) => l.length ? l[0] : !1
1443
- });
1444
- class U {
1445
- /**
1446
- @internal
1447
- */
1448
- constructor(e, t) {
1449
- this.type = e, this.value = t;
1450
- }
1451
- /**
1452
- Define a new type of annotation.
1453
- */
1454
- static define() {
1455
- return new qe();
1456
- }
1457
- }
1458
- class qe {
1459
- /**
1460
- Create an instance of this annotation.
1461
- */
1462
- of(e) {
1463
- return new U(this, e);
1464
- }
1465
- }
1466
- class We {
1467
- /**
1468
- @internal
1469
- */
1470
- constructor(e) {
1471
- this.map = e;
1472
- }
1473
- /**
1474
- Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
1475
- type.
1476
- */
1477
- of(e) {
1478
- return new I(this, e);
1479
- }
1480
- }
1481
- class I {
1482
- /**
1483
- @internal
1484
- */
1485
- constructor(e, t) {
1486
- this.type = e, this.value = t;
1487
- }
1488
- /**
1489
- Map this effect through a position mapping. Will return
1490
- `undefined` when that ends up deleting the effect.
1491
- */
1492
- map(e) {
1493
- let t = this.type.map(this.value, e);
1494
- return t === void 0 ? void 0 : t == this.value ? this : new I(this.type, t);
1495
- }
1496
- /**
1497
- Tells you whether this effect object is of a given
1498
- [type](https://codemirror.net/6/docs/ref/#state.StateEffectType).
1499
- */
1500
- is(e) {
1501
- return this.type == e;
1502
- }
1503
- /**
1504
- Define a new effect type. The type parameter indicates the type
1505
- of values that his effect holds. It should be a type that
1506
- doesn't include `undefined`, since that is used in
1507
- [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
1508
- removed.
1509
- */
1510
- static define(e = {}) {
1511
- return new We(e.map || ((t) => t));
1512
- }
1513
- /**
1514
- Map an array of effects through a change set.
1515
- */
1516
- static mapEffects(e, t) {
1517
- if (!e.length)
1518
- return e;
1519
- let n = [];
1520
- for (let i of e) {
1521
- let s = i.map(t);
1522
- s && n.push(s);
1523
- }
1524
- return n;
1525
- }
1526
- }
1527
- I.reconfigure = /* @__PURE__ */ I.define();
1528
- I.appendConfig = /* @__PURE__ */ I.define();
1529
- class P {
1530
- constructor(e, t, n, i, s, r) {
1531
- this.startState = e, this.changes = t, this.selection = n, this.effects = i, this.annotations = s, this.scrollIntoView = r, this._doc = null, this._state = null, n && Oe(n, t.newLength), s.some((h) => h.type == P.time) || (this.annotations = s.concat(P.time.of(Date.now())));
1532
- }
1533
- /**
1534
- @internal
1535
- */
1536
- static create(e, t, n, i, s, r) {
1537
- return new P(e, t, n, i, s, r);
1538
- }
1539
- /**
1540
- The new document produced by the transaction. Contrary to
1541
- [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
1542
- force the entire new state to be computed right away, so it is
1543
- recommended that [transaction
1544
- filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter
1545
- when they need to look at the new document.
1546
- */
1547
- get newDoc() {
1548
- return this._doc || (this._doc = this.changes.apply(this.startState.doc));
1549
- }
1550
- /**
1551
- The new selection produced by the transaction. If
1552
- [`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,
1553
- this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's
1554
- current selection through the changes made by the transaction.
1555
- */
1556
- get newSelection() {
1557
- return this.selection || this.startState.selection.map(this.changes);
1558
- }
1559
- /**
1560
- The new state created by the transaction. Computed on demand
1561
- (but retained for subsequent access), so it is recommended not to
1562
- access it in [transaction
1563
- filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
1564
- */
1565
- get state() {
1566
- return this._state || this.startState.applyTransaction(this), this._state;
1567
- }
1568
- /**
1569
- Get the value of the given annotation type, if any.
1570
- */
1571
- annotation(e) {
1572
- for (let t of this.annotations)
1573
- if (t.type == e)
1574
- return t.value;
1575
- }
1576
- /**
1577
- Indicates whether the transaction changed the document.
1578
- */
1579
- get docChanged() {
1580
- return !this.changes.empty;
1581
- }
1582
- /**
1583
- Indicates whether this transaction reconfigures the state
1584
- (through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or
1585
- with a top-level configuration
1586
- [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
1587
- */
1588
- get reconfigured() {
1589
- return this.startState.config != this.state.config;
1590
- }
1591
- /**
1592
- Returns true if the transaction has a [user
1593
- event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
1594
- or more specific than `event`. For example, if the transaction
1595
- has `"select.pointer"` as user event, `"select"` and
1596
- `"select.pointer"` will match it.
1597
- */
1598
- isUserEvent(e) {
1599
- let t = this.annotation(P.userEvent);
1600
- return !!(t && (t == e || t.length > e.length && t.slice(0, e.length) == e && t[e.length] == "."));
1601
- }
1602
- }
1603
- P.time = /* @__PURE__ */ U.define();
1604
- P.userEvent = /* @__PURE__ */ U.define();
1605
- P.addToHistory = /* @__PURE__ */ U.define();
1606
- P.remote = /* @__PURE__ */ U.define();
1607
- function Ue(l, e) {
1608
- let t = [];
1609
- for (let n = 0, i = 0; ; ) {
1610
- let s, r;
1611
- if (n < l.length && (i == e.length || e[i] >= l[n]))
1612
- s = l[n++], r = l[n++];
1613
- else if (i < e.length)
1614
- s = e[i++], r = e[i++];
1615
- else
1616
- return t;
1617
- !t.length || t[t.length - 1] < s ? t.push(s, r) : t[t.length - 1] < r && (t[t.length - 1] = r);
1618
- }
1619
- }
1620
- function Fe(l, e, t) {
1621
- var n;
1622
- let i, s, r;
1623
- return t ? (i = e.changes, s = k.empty(e.changes.length), r = l.changes.compose(e.changes)) : (i = e.changes.map(l.changes), s = l.changes.mapDesc(e.changes, !0), r = l.changes.compose(i)), {
1624
- changes: r,
1625
- selection: e.selection ? e.selection.map(s) : (n = l.selection) === null || n === void 0 ? void 0 : n.map(i),
1626
- effects: I.mapEffects(l.effects, i).concat(I.mapEffects(e.effects, s)),
1627
- annotations: l.annotations.length ? l.annotations.concat(e.annotations) : e.annotations,
1628
- scrollIntoView: l.scrollIntoView || e.scrollIntoView
1629
- };
1630
- }
1631
- function ue(l, e, t) {
1632
- let n = e.selection, i = F(e.annotations);
1633
- return e.userEvent && (i = i.concat(P.userEvent.of(e.userEvent))), {
1634
- changes: e.changes instanceof k ? e.changes : k.of(e.changes || [], t, l.facet(Me)),
1635
- selection: n && (n instanceof p ? n : p.single(n.anchor, n.head)),
1636
- effects: F(e.effects),
1637
- annotations: i,
1638
- scrollIntoView: !!e.scrollIntoView
1639
- };
1640
- }
1641
- function Je(l, e, t) {
1642
- let n = ue(l, e.length ? e[0] : {}, l.doc.length);
1643
- e.length && e[0].filter === !1 && (t = !1);
1644
- for (let s = 1; s < e.length; s++) {
1645
- e[s].filter === !1 && (t = !1);
1646
- let r = !!e[s].sequential;
1647
- n = Fe(n, ue(l, e[s], r ? n.changes.newLength : l.doc.length), r);
1648
- }
1649
- let i = P.create(l, n.changes, n.selection, n.effects, n.annotations, n.scrollIntoView);
1650
- return He(t ? Ge(i) : i);
1651
- }
1652
- function Ge(l) {
1653
- let e = l.startState, t = !0;
1654
- for (let i of e.facet(Re)) {
1655
- let s = i(l);
1656
- if (s === !1) {
1657
- t = !1;
1658
- break;
1659
- }
1660
- Array.isArray(s) && (t = t === !0 ? s : Ue(t, s));
1661
- }
1662
- if (t !== !0) {
1663
- let i, s;
1664
- if (t === !1)
1665
- s = l.changes.invertedDesc, i = k.empty(e.doc.length);
1666
- else {
1667
- let r = l.changes.filter(t);
1668
- i = r.changes, s = r.filtered.mapDesc(r.changes).invertedDesc;
1669
- }
1670
- l = P.create(e, i, l.selection && l.selection.map(s), I.mapEffects(l.effects, s), l.annotations, l.scrollIntoView);
1671
- }
1672
- let n = e.facet(Te);
1673
- for (let i = n.length - 1; i >= 0; i--) {
1674
- let s = n[i](l);
1675
- s instanceof P ? l = s : Array.isArray(s) && s.length == 1 && s[0] instanceof P ? l = s[0] : l = Je(e, F(s), !1);
1676
- }
1677
- return l;
1678
- }
1679
- function He(l) {
1680
- let e = l.startState, t = e.facet(Be), n = l;
1681
- for (let i = t.length - 1; i >= 0; i--) {
1682
- let s = t[i](l);
1683
- s && Object.keys(s).length && (n = Fe(n, ue(e, s, l.changes.newLength), !0));
1684
- }
1685
- return n == l ? l : P.create(e, l.changes, l.selection, n.effects, n.annotations, n.scrollIntoView);
1686
- }
1687
- const Ke = [];
1688
- function F(l) {
1689
- return l == null ? Ke : Array.isArray(l) ? l : [l];
1690
- }
1691
- var T = /* @__PURE__ */ (function(l) {
1692
- return l[l.Word = 0] = "Word", l[l.Space = 1] = "Space", l[l.Other = 2] = "Other", l;
1693
- })(T || (T = {}));
1694
- const Qe = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
1695
- let fe;
1696
- try {
1697
- fe = /* @__PURE__ */ new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u");
1698
- } catch {
1699
- }
1700
- function Xe(l) {
1701
- if (fe)
1702
- return fe.test(l);
1703
- for (let e = 0; e < l.length; e++) {
1704
- let t = l[e];
1705
- if (/\w/.test(t) || t > "€" && (t.toUpperCase() != t.toLowerCase() || Qe.test(t)))
1706
- return !0;
1707
- }
1708
- return !1;
1709
- }
1710
- function Ye(l) {
1711
- return (e) => {
1712
- if (!/\S/.test(e))
1713
- return T.Space;
1714
- if (Xe(e))
1715
- return T.Word;
1716
- for (let t = 0; t < l.length; t++)
1717
- if (e.indexOf(l[t]) > -1)
1718
- return T.Word;
1719
- return T.Other;
1720
- };
1721
- }
1722
- class w {
1723
- constructor(e, t, n, i, s, r) {
1724
- this.config = e, this.doc = t, this.selection = n, this.values = i, this.status = e.statusTemplate.slice(), this.computeSlot = s, r && (r._state = this);
1725
- for (let h = 0; h < this.config.dynamicSlots.length; h++)
1726
- $(this, h << 1);
1727
- this.computeSlot = null;
1728
- }
1729
- field(e, t = !0) {
1730
- let n = this.config.address[e.id];
1731
- if (n == null) {
1732
- if (t)
1733
- throw new RangeError("Field is not present in this state");
1734
- return;
1735
- }
1736
- return $(this, n), Z(this, n);
1737
- }
1738
- /**
1739
- Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this
1740
- state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)
1741
- can be passed. Unless
1742
- [`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the
1743
- [changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec
1744
- are assumed to start in the _current_ document (not the document
1745
- produced by previous specs), and its
1746
- [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and
1747
- [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer
1748
- to the document created by its _own_ changes. The resulting
1749
- transaction contains the combined effect of all the different
1750
- specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later
1751
- specs take precedence over earlier ones.
1752
- */
1753
- update(...e) {
1754
- return Je(this, e, !0);
1755
- }
1756
- /**
1757
- @internal
1758
- */
1759
- applyTransaction(e) {
1760
- let t = this.config, { base: n, compartments: i } = t;
1761
- for (let h of e.effects)
1762
- h.is(ee.reconfigure) ? (t && (i = /* @__PURE__ */ new Map(), t.compartments.forEach((o, a) => i.set(a, o)), t = null), i.set(h.value.compartment, h.value.extension)) : h.is(I.reconfigure) ? (t = null, n = h.value) : h.is(I.appendConfig) && (t = null, n = F(n).concat(h.value));
1763
- let s;
1764
- t ? s = e.startState.values.slice() : (t = Y.resolve(n, i, this), s = new w(t, this.doc, this.selection, t.dynamicSlots.map(() => null), (o, a) => a.reconfigure(o, this), null).values);
1765
- let r = e.startState.facet(ae) ? e.newSelection : e.newSelection.asSingle();
1766
- new w(t, e.newDoc, r, s, (h, o) => o.update(h, e), e);
1767
- }
1768
- /**
1769
- Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
1770
- replaces every selection range with the given content.
1771
- */
1772
- replaceSelection(e) {
1773
- return typeof e == "string" && (e = this.toText(e)), this.changeByRange((t) => ({
1774
- changes: { from: t.from, to: t.to, insert: e },
1775
- range: p.cursor(t.from + e.length)
1776
- }));
1777
- }
1778
- /**
1779
- Create a set of changes and a new selection by running the given
1780
- function for each range in the active selection. The function
1781
- can return an optional set of changes (in the coordinate space
1782
- of the start document), plus an updated range (in the coordinate
1783
- space of the document produced by the call's own changes). This
1784
- method will merge all the changes and ranges into a single
1785
- changeset and selection, and return it as a [transaction
1786
- spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to
1787
- [`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
1788
- */
1789
- changeByRange(e) {
1790
- let t = this.selection, n = e(t.ranges[0]), i = this.changes(n.changes), s = [n.range], r = F(n.effects);
1791
- for (let h = 1; h < t.ranges.length; h++) {
1792
- let o = e(t.ranges[h]), a = this.changes(o.changes), u = a.map(i);
1793
- for (let d = 0; d < h; d++)
1794
- s[d] = s[d].map(u);
1795
- let f = i.mapDesc(a, !0);
1796
- s.push(o.range.map(f)), i = i.compose(u), r = I.mapEffects(r, u).concat(I.mapEffects(F(o.effects), f));
1797
- }
1798
- return {
1799
- changes: i,
1800
- selection: p.create(s, t.mainIndex),
1801
- effects: r
1802
- };
1803
- }
1804
- /**
1805
- Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change
1806
- description, taking the state's document length and line
1807
- separator into account.
1808
- */
1809
- changes(e = []) {
1810
- return e instanceof k ? e : k.of(e, this.doc.length, this.facet(w.lineSeparator));
1811
- }
1812
- /**
1813
- Using the state's [line
1814
- separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
1815
- [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
1816
- */
1817
- toText(e) {
1818
- return y.of(e.split(this.facet(w.lineSeparator) || se));
1819
- }
1820
- /**
1821
- Return the given range of the document as a string.
1822
- */
1823
- sliceDoc(e = 0, t = this.doc.length) {
1824
- return this.doc.sliceString(e, t, this.lineBreak);
1825
- }
1826
- /**
1827
- Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
1828
- */
1829
- facet(e) {
1830
- let t = this.config.address[e.id];
1831
- return t == null ? e.default : ($(this, t), Z(this, t));
1832
- }
1833
- /**
1834
- Convert this state to a JSON-serializable object. When custom
1835
- fields should be serialized, you can pass them in as an object
1836
- mapping property names (in the resulting object, which should
1837
- not use `doc` or `selection`) to fields.
1838
- */
1839
- toJSON(e) {
1840
- let t = {
1841
- doc: this.sliceDoc(),
1842
- selection: this.selection.toJSON()
1843
- };
1844
- if (e)
1845
- for (let n in e) {
1846
- let i = e[n];
1847
- i instanceof V && this.config.address[i.id] != null && (t[n] = i.spec.toJSON(this.field(e[n]), this));
1848
- }
1849
- return t;
1850
- }
1851
- /**
1852
- Deserialize a state from its JSON representation. When custom
1853
- fields should be deserialized, pass the same object you passed
1854
- to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as
1855
- third argument.
1856
- */
1857
- static fromJSON(e, t = {}, n) {
1858
- if (!e || typeof e.doc != "string")
1859
- throw new RangeError("Invalid JSON representation for EditorState");
1860
- let i = [];
1861
- if (n) {
1862
- for (let s in n)
1863
- if (Object.prototype.hasOwnProperty.call(e, s)) {
1864
- let r = n[s], h = e[s];
1865
- i.push(r.init((o) => r.spec.fromJSON(h, o)));
1866
- }
1867
- }
1868
- return w.create({
1869
- doc: e.doc,
1870
- selection: p.fromJSON(e.selection),
1871
- extensions: t.extensions ? i.concat([t.extensions]) : i
1872
- });
1873
- }
1874
- /**
1875
- Create a new state. You'll usually only need this when
1876
- initializing an editor—updated states are created by applying
1877
- transactions.
1878
- */
1879
- static create(e = {}) {
1880
- let t = Y.resolve(e.extensions || [], /* @__PURE__ */ new Map()), n = e.doc instanceof y ? e.doc : y.of((e.doc || "").split(t.staticFacet(w.lineSeparator) || se)), i = e.selection ? e.selection instanceof p ? e.selection : p.single(e.selection.anchor, e.selection.head) : p.single(0);
1881
- return Oe(i, n.length), t.staticFacet(ae) || (i = i.asSingle()), new w(t, n, i, t.dynamicSlots.map(() => null), (s, r) => r.create(s), null);
1882
- }
1883
- /**
1884
- The size (in columns) of a tab in the document, determined by
1885
- the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.
1886
- */
1887
- get tabSize() {
1888
- return this.facet(w.tabSize);
1889
- }
1890
- /**
1891
- Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)
1892
- string for this state.
1893
- */
1894
- get lineBreak() {
1895
- return this.facet(w.lineSeparator) || `
1896
- `;
1897
- }
1898
- /**
1899
- Returns true when the editor is
1900
- [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
1901
- */
1902
- get readOnly() {
1903
- return this.facet(Ce);
1904
- }
1905
- /**
1906
- Look up a translation for the given phrase (via the
1907
- [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
1908
- original string if no translation is found.
1909
-
1910
- If additional arguments are passed, they will be inserted in
1911
- place of markers like `$1` (for the first value) and `$2`, etc.
1912
- A single `$` is equivalent to `$1`, and `$$` will produce a
1913
- literal dollar sign.
1914
- */
1915
- phrase(e, ...t) {
1916
- for (let n of this.facet(w.phrases))
1917
- if (Object.prototype.hasOwnProperty.call(n, e)) {
1918
- e = n[e];
1919
- break;
1920
- }
1921
- return t.length && (e = e.replace(/\$(\$|\d*)/g, (n, i) => {
1922
- if (i == "$")
1923
- return "$";
1924
- let s = +(i || 1);
1925
- return !s || s > t.length ? n : t[s - 1];
1926
- })), e;
1927
- }
1928
- /**
1929
- Find the values for a given language data field, provided by the
1930
- the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
1931
-
1932
- Examples of language data fields are...
1933
-
1934
- - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
1935
- comment syntax.
1936
- - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
1937
- for providing language-specific completion sources.
1938
- - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
1939
- characters that should be considered part of words in this
1940
- language.
1941
- - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
1942
- bracket closing behavior.
1943
- */
1944
- languageDataAt(e, t, n = -1) {
1945
- let i = [];
1946
- for (let s of this.facet(be))
1947
- for (let r of s(this, t, n))
1948
- Object.prototype.hasOwnProperty.call(r, e) && i.push(r[e]);
1949
- return i;
1950
- }
1951
- /**
1952
- Return a function that can categorize strings (expected to
1953
- represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
1954
- into one of:
1955
-
1956
- - Word (contains an alphanumeric character or a character
1957
- explicitly listed in the local language's `"wordChars"`
1958
- language data, which should be a string)
1959
- - Space (contains only whitespace)
1960
- - Other (anything else)
1961
- */
1962
- charCategorizer(e) {
1963
- let t = this.languageDataAt("wordChars", e);
1964
- return Ye(t.length ? t[0] : "");
1965
- }
1966
- /**
1967
- Find the word at the given position, meaning the range
1968
- containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
1969
- around it. If no word characters are adjacent to the position,
1970
- this returns null.
1971
- */
1972
- wordAt(e) {
1973
- let { text: t, from: n, length: i } = this.doc.lineAt(e), s = this.charCategorizer(e), r = e - n, h = e - n;
1974
- for (; r > 0; ) {
1975
- let o = ie(t, r, !1);
1976
- if (s(t.slice(o, r)) != T.Word)
1977
- break;
1978
- r = o;
1979
- }
1980
- for (; h < i; ) {
1981
- let o = ie(t, h);
1982
- if (s(t.slice(h, o)) != T.Word)
1983
- break;
1984
- h = o;
1985
- }
1986
- return r == h ? null : p.range(r + n, h + n);
1987
- }
1988
- }
1989
- w.allowMultipleSelections = ae;
1990
- w.tabSize = /* @__PURE__ */ A.define({
1991
- combine: (l) => l.length ? l[0] : 4
1992
- });
1993
- w.lineSeparator = Me;
1994
- w.readOnly = Ce;
1995
- w.phrases = /* @__PURE__ */ A.define({
1996
- compare(l, e) {
1997
- let t = Object.keys(l), n = Object.keys(e);
1998
- return t.length == n.length && t.every((i) => l[i] == e[i]);
1999
- }
2000
- });
2001
- w.languageData = be;
2002
- w.changeFilter = Re;
2003
- w.transactionFilter = Te;
2004
- w.transactionExtender = Be;
2005
- ee.reconfigure = /* @__PURE__ */ I.define();
2006
- function et(l, e, t = {}) {
2007
- let n = {};
2008
- for (let i of l)
2009
- for (let s of Object.keys(i)) {
2010
- let r = i[s], h = n[s];
2011
- if (h === void 0)
2012
- n[s] = r;
2013
- else if (!(h === r || r === void 0)) if (Object.hasOwnProperty.call(t, s))
2014
- n[s] = t[s](h, r);
2015
- else
2016
- throw new Error("Config merge conflict for field " + s);
2017
- }
2018
- for (let i in e)
2019
- n[i] === void 0 && (n[i] = e[i]);
2020
- return n;
2021
- }
2022
- class j {
2023
- /**
2024
- Compare this value with another value. Used when comparing
2025
- rangesets. The default implementation compares by identity.
2026
- Unless you are only creating a fixed number of unique instances
2027
- of your value type, it is a good idea to implement this
2028
- properly.
2029
- */
2030
- eq(e) {
2031
- return this == e;
2032
- }
2033
- /**
2034
- Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
2035
- */
2036
- range(e, t = e) {
2037
- return q.create(e, t, this);
2038
- }
2039
- }
2040
- j.prototype.startSide = j.prototype.endSide = 0;
2041
- j.prototype.point = !1;
2042
- j.prototype.mapMode = M.TrackDel;
2043
- function me(l, e) {
2044
- return l == e || l.constructor == e.constructor && l.eq(e);
2045
- }
2046
- class q {
2047
- constructor(e, t, n) {
2048
- this.from = e, this.to = t, this.value = n;
2049
- }
2050
- /**
2051
- @internal
2052
- */
2053
- static create(e, t, n) {
2054
- return new q(e, t, n);
2055
- }
2056
- }
2057
- function ce(l, e) {
2058
- return l.from - e.from || l.value.startSide - e.value.startSide;
2059
- }
2060
- class we {
2061
- constructor(e, t, n, i) {
2062
- this.from = e, this.to = t, this.value = n, this.maxPoint = i;
2063
- }
2064
- get length() {
2065
- return this.to[this.to.length - 1];
2066
- }
2067
- // Find the index of the given position and side. Use the ranges'
2068
- // `from` pos when `end == false`, `to` when `end == true`.
2069
- findIndex(e, t, n, i = 0) {
2070
- let s = n ? this.to : this.from;
2071
- for (let r = i, h = s.length; ; ) {
2072
- if (r == h)
2073
- return r;
2074
- let o = r + h >> 1, a = s[o] - e || (n ? this.value[o].endSide : this.value[o].startSide) - t;
2075
- if (o == r)
2076
- return a >= 0 ? r : h;
2077
- a >= 0 ? h = o : r = o + 1;
2078
- }
2079
- }
2080
- between(e, t, n, i) {
2081
- for (let s = this.findIndex(t, -1e9, !0), r = this.findIndex(n, 1e9, !1, s); s < r; s++)
2082
- if (i(this.from[s] + e, this.to[s] + e, this.value[s]) === !1)
2083
- return !1;
2084
- }
2085
- map(e, t) {
2086
- let n = [], i = [], s = [], r = -1, h = -1;
2087
- for (let o = 0; o < this.value.length; o++) {
2088
- let a = this.value[o], u = this.from[o] + e, f = this.to[o] + e, d, c;
2089
- if (u == f) {
2090
- let g = t.mapPos(u, a.startSide, a.mapMode);
2091
- if (g == null || (d = c = g, a.startSide != a.endSide && (c = t.mapPos(u, a.endSide), c < d)))
2092
- continue;
2093
- } else if (d = t.mapPos(u, a.startSide), c = t.mapPos(f, a.endSide), d > c || d == c && a.startSide > 0 && a.endSide <= 0)
2094
- continue;
2095
- (c - d || a.endSide - a.startSide) < 0 || (r < 0 && (r = d), a.point && (h = Math.max(h, c - d)), n.push(a), i.push(d - r), s.push(c - r));
2096
- }
2097
- return { mapped: n.length ? new we(i, s, n, h) : null, pos: r };
2098
- }
2099
- }
2100
- class S {
2101
- constructor(e, t, n, i) {
2102
- this.chunkPos = e, this.chunk = t, this.nextLayer = n, this.maxPoint = i;
2103
- }
2104
- /**
2105
- @internal
2106
- */
2107
- static create(e, t, n, i) {
2108
- return new S(e, t, n, i);
2109
- }
2110
- /**
2111
- @internal
2112
- */
2113
- get length() {
2114
- let e = this.chunk.length - 1;
2115
- return e < 0 ? 0 : Math.max(this.chunkEnd(e), this.nextLayer.length);
2116
- }
2117
- /**
2118
- The number of ranges in the set.
2119
- */
2120
- get size() {
2121
- if (this.isEmpty)
2122
- return 0;
2123
- let e = this.nextLayer.size;
2124
- for (let t of this.chunk)
2125
- e += t.value.length;
2126
- return e;
2127
- }
2128
- /**
2129
- @internal
2130
- */
2131
- chunkEnd(e) {
2132
- return this.chunkPos[e] + this.chunk[e].length;
2133
- }
2134
- /**
2135
- Update the range set, optionally adding new ranges or filtering
2136
- out existing ones.
2137
-
2138
- (Note: The type parameter is just there as a kludge to work
2139
- around TypeScript variance issues that prevented `RangeSet<X>`
2140
- from being a subtype of `RangeSet<Y>` when `X` is a subtype of
2141
- `Y`.)
2142
- */
2143
- update(e) {
2144
- let { add: t = [], sort: n = !1, filterFrom: i = 0, filterTo: s = this.length } = e, r = e.filter;
2145
- if (t.length == 0 && !r)
2146
- return this;
2147
- if (n && (t = t.slice().sort(ce)), this.isEmpty)
2148
- return t.length ? S.of(t) : this;
2149
- let h = new Ve(this, null, -1).goto(0), o = 0, a = [], u = new _();
2150
- for (; h.value || o < t.length; )
2151
- if (o < t.length && (h.from - t[o].from || h.startSide - t[o].value.startSide) >= 0) {
2152
- let f = t[o++];
2153
- u.addInner(f.from, f.to, f.value) || a.push(f);
2154
- } else h.rangeIndex == 1 && h.chunkIndex < this.chunk.length && (o == t.length || this.chunkEnd(h.chunkIndex) < t[o].from) && (!r || i > this.chunkEnd(h.chunkIndex) || s < this.chunkPos[h.chunkIndex]) && u.addChunk(this.chunkPos[h.chunkIndex], this.chunk[h.chunkIndex]) ? h.nextChunk() : ((!r || i > h.to || s < h.from || r(h.from, h.to, h.value)) && (u.addInner(h.from, h.to, h.value) || a.push(q.create(h.from, h.to, h.value))), h.next());
2155
- return u.finishInner(this.nextLayer.isEmpty && !a.length ? S.empty : this.nextLayer.update({ add: a, filter: r, filterFrom: i, filterTo: s }));
2156
- }
2157
- /**
2158
- Map this range set through a set of changes, return the new set.
2159
- */
2160
- map(e) {
2161
- if (e.empty || this.isEmpty)
2162
- return this;
2163
- let t = [], n = [], i = -1;
2164
- for (let r = 0; r < this.chunk.length; r++) {
2165
- let h = this.chunkPos[r], o = this.chunk[r], a = e.touchesRange(h, h + o.length);
2166
- if (a === !1)
2167
- i = Math.max(i, o.maxPoint), t.push(o), n.push(e.mapPos(h));
2168
- else if (a === !0) {
2169
- let { mapped: u, pos: f } = o.map(h, e);
2170
- u && (i = Math.max(i, u.maxPoint), t.push(u), n.push(f));
2171
- }
2172
- }
2173
- let s = this.nextLayer.map(e);
2174
- return t.length == 0 ? s : new S(n, t, s || S.empty, i);
2175
- }
2176
- /**
2177
- Iterate over the ranges that touch the region `from` to `to`,
2178
- calling `f` for each. There is no guarantee that the ranges will
2179
- be reported in any specific order. When the callback returns
2180
- `false`, iteration stops.
2181
- */
2182
- between(e, t, n) {
2183
- if (!this.isEmpty) {
2184
- for (let i = 0; i < this.chunk.length; i++) {
2185
- let s = this.chunkPos[i], r = this.chunk[i];
2186
- if (t >= s && e <= s + r.length && r.between(s, e - s, t - s, n) === !1)
2187
- return;
2188
- }
2189
- this.nextLayer.between(e, t, n);
2190
- }
2191
- }
2192
- /**
2193
- Iterate over the ranges in this set, in order, including all
2194
- ranges that end at or after `from`.
2195
- */
2196
- iter(e = 0) {
2197
- return W.from([this]).goto(e);
2198
- }
2199
- /**
2200
- @internal
2201
- */
2202
- get isEmpty() {
2203
- return this.nextLayer == this;
2204
- }
2205
- /**
2206
- Iterate over the ranges in a collection of sets, in order,
2207
- starting from `from`.
2208
- */
2209
- static iter(e, t = 0) {
2210
- return W.from(e).goto(t);
2211
- }
2212
- /**
2213
- Iterate over two groups of sets, calling methods on `comparator`
2214
- to notify it of possible differences.
2215
- */
2216
- static compare(e, t, n, i, s = -1) {
2217
- let r = e.filter((f) => f.maxPoint > 0 || !f.isEmpty && f.maxPoint >= s), h = t.filter((f) => f.maxPoint > 0 || !f.isEmpty && f.maxPoint >= s), o = ke(r, h, n), a = new N(r, o, s), u = new N(h, o, s);
2218
- n.iterGaps((f, d, c) => xe(a, f, u, d, c, i)), n.empty && n.length == 0 && xe(a, 0, u, 0, 0, i);
2219
- }
2220
- /**
2221
- Compare the contents of two groups of range sets, returning true
2222
- if they are equivalent in the given range.
2223
- */
2224
- static eq(e, t, n = 0, i) {
2225
- i == null && (i = 999999999);
2226
- let s = e.filter((u) => !u.isEmpty && t.indexOf(u) < 0), r = t.filter((u) => !u.isEmpty && e.indexOf(u) < 0);
2227
- if (s.length != r.length)
2228
- return !1;
2229
- if (!s.length)
2230
- return !0;
2231
- let h = ke(s, r), o = new N(s, h, 0).goto(n), a = new N(r, h, 0).goto(n);
2232
- for (; ; ) {
2233
- if (o.to != a.to || !de(o.active, a.active) || o.point && (!a.point || !me(o.point, a.point)))
2234
- return !1;
2235
- if (o.to > i)
2236
- return !0;
2237
- o.next(), a.next();
2238
- }
2239
- }
2240
- /**
2241
- Iterate over a group of range sets at the same time, notifying
2242
- the iterator about the ranges covering every given piece of
2243
- content. Returns the open count (see
2244
- [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
2245
- of the iteration.
2246
- */
2247
- static spans(e, t, n, i, s = -1) {
2248
- let r = new N(e, null, s).goto(t), h = t, o = r.openStart;
2249
- for (; ; ) {
2250
- let a = Math.min(r.to, n);
2251
- if (r.point) {
2252
- let u = r.activeForPoint(r.to), f = r.pointFrom < t ? u.length + 1 : r.point.startSide < 0 ? u.length : Math.min(u.length, o);
2253
- i.point(h, a, r.point, u, f, r.pointRank), o = Math.min(r.openEnd(a), u.length);
2254
- } else a > h && (i.span(h, a, r.active, o), o = r.openEnd(a));
2255
- if (r.to > n)
2256
- return o + (r.point && r.to > n ? 1 : 0);
2257
- h = r.to, r.next();
2258
- }
2259
- }
2260
- /**
2261
- Create a range set for the given range or array of ranges. By
2262
- default, this expects the ranges to be _sorted_ (by start
2263
- position and, if two start at the same position,
2264
- `value.startSide`). You can pass `true` as second argument to
2265
- cause the method to sort them.
2266
- */
2267
- static of(e, t = !1) {
2268
- let n = new _();
2269
- for (let i of e instanceof q ? [e] : t ? Ze(e) : e)
2270
- n.add(i.from, i.to, i.value);
2271
- return n.finish();
2272
- }
2273
- /**
2274
- Join an array of range sets into a single set.
2275
- */
2276
- static join(e) {
2277
- if (!e.length)
2278
- return S.empty;
2279
- let t = e[e.length - 1];
2280
- for (let n = e.length - 2; n >= 0; n--)
2281
- for (let i = e[n]; i != S.empty; i = i.nextLayer)
2282
- t = new S(i.chunkPos, i.chunk, t, Math.max(i.maxPoint, t.maxPoint));
2283
- return t;
2284
- }
2285
- }
2286
- S.empty = /* @__PURE__ */ new S([], [], null, -1);
2287
- function Ze(l) {
2288
- if (l.length > 1)
2289
- for (let e = l[0], t = 1; t < l.length; t++) {
2290
- let n = l[t];
2291
- if (ce(e, n) > 0)
2292
- return l.slice().sort(ce);
2293
- e = n;
2294
- }
2295
- return l;
2296
- }
2297
- S.empty.nextLayer = S.empty;
2298
- class _ {
2299
- finishChunk(e) {
2300
- this.chunks.push(new we(this.from, this.to, this.value, this.maxPoint)), this.chunkPos.push(this.chunkStart), this.chunkStart = -1, this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint), this.maxPoint = -1, e && (this.from = [], this.to = [], this.value = []);
2301
- }
2302
- /**
2303
- Create an empty builder.
2304
- */
2305
- constructor() {
2306
- this.chunks = [], this.chunkPos = [], this.chunkStart = -1, this.last = null, this.lastFrom = -1e9, this.lastTo = -1e9, this.from = [], this.to = [], this.value = [], this.maxPoint = -1, this.setMaxPoint = -1, this.nextLayer = null;
2307
- }
2308
- /**
2309
- Add a range. Ranges should be added in sorted (by `from` and
2310
- `value.startSide`) order.
2311
- */
2312
- add(e, t, n) {
2313
- this.addInner(e, t, n) || (this.nextLayer || (this.nextLayer = new _())).add(e, t, n);
2314
- }
2315
- /**
2316
- @internal
2317
- */
2318
- addInner(e, t, n) {
2319
- let i = e - this.lastTo || n.startSide - this.last.endSide;
2320
- if (i <= 0 && (e - this.lastFrom || n.startSide - this.last.startSide) < 0)
2321
- throw new Error("Ranges must be added sorted by `from` position and `startSide`");
2322
- return i < 0 ? !1 : (this.from.length == 250 && this.finishChunk(!0), this.chunkStart < 0 && (this.chunkStart = e), this.from.push(e - this.chunkStart), this.to.push(t - this.chunkStart), this.last = n, this.lastFrom = e, this.lastTo = t, this.value.push(n), n.point && (this.maxPoint = Math.max(this.maxPoint, t - e)), !0);
2323
- }
2324
- /**
2325
- @internal
2326
- */
2327
- addChunk(e, t) {
2328
- if ((e - this.lastTo || t.value[0].startSide - this.last.endSide) < 0)
2329
- return !1;
2330
- this.from.length && this.finishChunk(!0), this.setMaxPoint = Math.max(this.setMaxPoint, t.maxPoint), this.chunks.push(t), this.chunkPos.push(e);
2331
- let n = t.value.length - 1;
2332
- return this.last = t.value[n], this.lastFrom = t.from[n] + e, this.lastTo = t.to[n] + e, !0;
2333
- }
2334
- /**
2335
- Finish the range set. Returns the new set. The builder can't be
2336
- used anymore after this has been called.
2337
- */
2338
- finish() {
2339
- return this.finishInner(S.empty);
2340
- }
2341
- /**
2342
- @internal
2343
- */
2344
- finishInner(e) {
2345
- if (this.from.length && this.finishChunk(!1), this.chunks.length == 0)
2346
- return e;
2347
- let t = S.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(e) : e, this.setMaxPoint);
2348
- return this.from = null, t;
2349
- }
2350
- }
2351
- function ke(l, e, t) {
2352
- let n = /* @__PURE__ */ new Map();
2353
- for (let s of l)
2354
- for (let r = 0; r < s.chunk.length; r++)
2355
- s.chunk[r].maxPoint <= 0 && n.set(s.chunk[r], s.chunkPos[r]);
2356
- let i = /* @__PURE__ */ new Set();
2357
- for (let s of e)
2358
- for (let r = 0; r < s.chunk.length; r++) {
2359
- let h = n.get(s.chunk[r]);
2360
- h != null && (t ? t.mapPos(h) : h) == s.chunkPos[r] && !t?.touchesRange(h, h + s.chunk[r].length) && i.add(s.chunk[r]);
2361
- }
2362
- return i;
2363
- }
2364
- class Ve {
2365
- constructor(e, t, n, i = 0) {
2366
- this.layer = e, this.skip = t, this.minPoint = n, this.rank = i;
2367
- }
2368
- get startSide() {
2369
- return this.value ? this.value.startSide : 0;
2370
- }
2371
- get endSide() {
2372
- return this.value ? this.value.endSide : 0;
2373
- }
2374
- goto(e, t = -1e9) {
2375
- return this.chunkIndex = this.rangeIndex = 0, this.gotoInner(e, t, !1), this;
2376
- }
2377
- gotoInner(e, t, n) {
2378
- for (; this.chunkIndex < this.layer.chunk.length; ) {
2379
- let i = this.layer.chunk[this.chunkIndex];
2380
- if (!(this.skip && this.skip.has(i) || this.layer.chunkEnd(this.chunkIndex) < e || i.maxPoint < this.minPoint))
2381
- break;
2382
- this.chunkIndex++, n = !1;
2383
- }
2384
- if (this.chunkIndex < this.layer.chunk.length) {
2385
- let i = this.layer.chunk[this.chunkIndex].findIndex(e - this.layer.chunkPos[this.chunkIndex], t, !0);
2386
- (!n || this.rangeIndex < i) && this.setRangeIndex(i);
2387
- }
2388
- this.next();
2389
- }
2390
- forward(e, t) {
2391
- (this.to - e || this.endSide - t) < 0 && this.gotoInner(e, t, !0);
2392
- }
2393
- next() {
2394
- for (; ; )
2395
- if (this.chunkIndex == this.layer.chunk.length) {
2396
- this.from = this.to = 1e9, this.value = null;
2397
- break;
2398
- } else {
2399
- let e = this.layer.chunkPos[this.chunkIndex], t = this.layer.chunk[this.chunkIndex], n = e + t.from[this.rangeIndex];
2400
- if (this.from = n, this.to = e + t.to[this.rangeIndex], this.value = t.value[this.rangeIndex], this.setRangeIndex(this.rangeIndex + 1), this.minPoint < 0 || this.value.point && this.to - this.from >= this.minPoint)
2401
- break;
2402
- }
2403
- }
2404
- setRangeIndex(e) {
2405
- if (e == this.layer.chunk[this.chunkIndex].value.length) {
2406
- if (this.chunkIndex++, this.skip)
2407
- for (; this.chunkIndex < this.layer.chunk.length && this.skip.has(this.layer.chunk[this.chunkIndex]); )
2408
- this.chunkIndex++;
2409
- this.rangeIndex = 0;
2410
- } else
2411
- this.rangeIndex = e;
2412
- }
2413
- nextChunk() {
2414
- this.chunkIndex++, this.rangeIndex = 0, this.next();
2415
- }
2416
- compare(e) {
2417
- return this.from - e.from || this.startSide - e.startSide || this.rank - e.rank || this.to - e.to || this.endSide - e.endSide;
2418
- }
2419
- }
2420
- class W {
2421
- constructor(e) {
2422
- this.heap = e;
2423
- }
2424
- static from(e, t = null, n = -1) {
2425
- let i = [];
2426
- for (let s = 0; s < e.length; s++)
2427
- for (let r = e[s]; !r.isEmpty; r = r.nextLayer)
2428
- r.maxPoint >= n && i.push(new Ve(r, t, n, s));
2429
- return i.length == 1 ? i[0] : new W(i);
2430
- }
2431
- get startSide() {
2432
- return this.value ? this.value.startSide : 0;
2433
- }
2434
- goto(e, t = -1e9) {
2435
- for (let n of this.heap)
2436
- n.goto(e, t);
2437
- for (let n = this.heap.length >> 1; n >= 0; n--)
2438
- ne(this.heap, n);
2439
- return this.next(), this;
2440
- }
2441
- forward(e, t) {
2442
- for (let n of this.heap)
2443
- n.forward(e, t);
2444
- for (let n = this.heap.length >> 1; n >= 0; n--)
2445
- ne(this.heap, n);
2446
- (this.to - e || this.value.endSide - t) < 0 && this.next();
2447
- }
2448
- next() {
2449
- if (this.heap.length == 0)
2450
- this.from = this.to = 1e9, this.value = null, this.rank = -1;
2451
- else {
2452
- let e = this.heap[0];
2453
- this.from = e.from, this.to = e.to, this.value = e.value, this.rank = e.rank, e.value && e.next(), ne(this.heap, 0);
2454
- }
2455
- }
2456
- }
2457
- function ne(l, e) {
2458
- for (let t = l[e]; ; ) {
2459
- let n = (e << 1) + 1;
2460
- if (n >= l.length)
2461
- break;
2462
- let i = l[n];
2463
- if (n + 1 < l.length && i.compare(l[n + 1]) >= 0 && (i = l[n + 1], n++), t.compare(i) < 0)
2464
- break;
2465
- l[n] = t, l[e] = i, e = n;
2466
- }
2467
- }
2468
- class N {
2469
- constructor(e, t, n) {
2470
- this.minPoint = n, this.active = [], this.activeTo = [], this.activeRank = [], this.minActive = -1, this.point = null, this.pointFrom = 0, this.pointRank = 0, this.to = -1e9, this.endSide = 0, this.openStart = -1, this.cursor = W.from(e, t, n);
2471
- }
2472
- goto(e, t = -1e9) {
2473
- return this.cursor.goto(e, t), this.active.length = this.activeTo.length = this.activeRank.length = 0, this.minActive = -1, this.to = e, this.endSide = t, this.openStart = -1, this.next(), this;
2474
- }
2475
- forward(e, t) {
2476
- for (; this.minActive > -1 && (this.activeTo[this.minActive] - e || this.active[this.minActive].endSide - t) < 0; )
2477
- this.removeActive(this.minActive);
2478
- this.cursor.forward(e, t);
2479
- }
2480
- removeActive(e) {
2481
- H(this.active, e), H(this.activeTo, e), H(this.activeRank, e), this.minActive = Se(this.active, this.activeTo);
2482
- }
2483
- addActive(e) {
2484
- let t = 0, { value: n, to: i, rank: s } = this.cursor;
2485
- for (; t < this.activeRank.length && (s - this.activeRank[t] || i - this.activeTo[t]) > 0; )
2486
- t++;
2487
- K(this.active, t, n), K(this.activeTo, t, i), K(this.activeRank, t, s), e && K(e, t, this.cursor.from), this.minActive = Se(this.active, this.activeTo);
2488
- }
2489
- // After calling this, if `this.point` != null, the next range is a
2490
- // point. Otherwise, it's a regular range, covered by `this.active`.
2491
- next() {
2492
- let e = this.to, t = this.point;
2493
- this.point = null;
2494
- let n = this.openStart < 0 ? [] : null;
2495
- for (; ; ) {
2496
- let i = this.minActive;
2497
- if (i > -1 && (this.activeTo[i] - this.cursor.from || this.active[i].endSide - this.cursor.startSide) < 0) {
2498
- if (this.activeTo[i] > e) {
2499
- this.to = this.activeTo[i], this.endSide = this.active[i].endSide;
2500
- break;
2501
- }
2502
- this.removeActive(i), n && H(n, i);
2503
- } else if (this.cursor.value)
2504
- if (this.cursor.from > e) {
2505
- this.to = this.cursor.from, this.endSide = this.cursor.startSide;
2506
- break;
2507
- } else {
2508
- let s = this.cursor.value;
2509
- if (!s.point)
2510
- this.addActive(n), this.cursor.next();
2511
- else if (t && this.cursor.to == this.to && this.cursor.from < this.cursor.to)
2512
- this.cursor.next();
2513
- else {
2514
- this.point = s, this.pointFrom = this.cursor.from, this.pointRank = this.cursor.rank, this.to = this.cursor.to, this.endSide = s.endSide, this.cursor.next(), this.forward(this.to, this.endSide);
2515
- break;
2516
- }
2517
- }
2518
- else {
2519
- this.to = this.endSide = 1e9;
2520
- break;
2521
- }
2522
- }
2523
- if (n) {
2524
- this.openStart = 0;
2525
- for (let i = n.length - 1; i >= 0 && n[i] < e; i--)
2526
- this.openStart++;
2527
- }
2528
- }
2529
- activeForPoint(e) {
2530
- if (!this.active.length)
2531
- return this.active;
2532
- let t = [];
2533
- for (let n = this.active.length - 1; n >= 0 && !(this.activeRank[n] < this.pointRank); n--)
2534
- (this.activeTo[n] > e || this.activeTo[n] == e && this.active[n].endSide >= this.point.endSide) && t.push(this.active[n]);
2535
- return t.reverse();
2536
- }
2537
- openEnd(e) {
2538
- let t = 0;
2539
- for (let n = this.activeTo.length - 1; n >= 0 && this.activeTo[n] > e; n--)
2540
- t++;
2541
- return t;
2542
- }
2543
- }
2544
- function xe(l, e, t, n, i, s) {
2545
- l.goto(e), t.goto(n);
2546
- let r = n + i, h = n, o = n - e, a = !!s.boundChange;
2547
- for (let u = !1; ; ) {
2548
- let f = l.to + o - t.to, d = f || l.endSide - t.endSide, c = d < 0 ? l.to + o : t.to, g = Math.min(c, r);
2549
- if (l.point || t.point ? (l.point && t.point && me(l.point, t.point) && de(l.activeForPoint(l.to), t.activeForPoint(t.to)) || s.comparePoint(h, g, l.point, t.point), u = !1) : (u && s.boundChange(h), g > h && !de(l.active, t.active) && s.compareRange(h, g, l.active, t.active), a && g < r && (f || l.openEnd(c) != t.openEnd(c)) && (u = !0)), c > r)
2550
- break;
2551
- h = c, d <= 0 && l.next(), d >= 0 && t.next();
2552
- }
2553
- }
2554
- function de(l, e) {
2555
- if (l.length != e.length)
2556
- return !1;
2557
- for (let t = 0; t < l.length; t++)
2558
- if (l[t] != e[t] && !me(l[t], e[t]))
2559
- return !1;
2560
- return !0;
2561
- }
2562
- function H(l, e) {
2563
- for (let t = e, n = l.length - 1; t < n; t++)
2564
- l[t] = l[t + 1];
2565
- l.pop();
2566
- }
2567
- function K(l, e, t) {
2568
- for (let n = l.length - 1; n >= e; n--)
2569
- l[n + 1] = l[n];
2570
- l[e] = t;
2571
- }
2572
- function Se(l, e) {
2573
- let t = -1, n = 1e9;
2574
- for (let i = 0; i < e.length; i++)
2575
- (e[i] - n || l[i].endSide - l[t].endSide) < 0 && (t = i, n = e[i]);
2576
- return t;
2577
- }
2578
- function tt(l, e, t, n) {
2579
- for (let i = 0, s = 0; ; ) {
2580
- if (s >= e)
2581
- return i;
2582
- if (i == l.length)
2583
- break;
2584
- s += l.charCodeAt(i) == 9 ? t - s % t : 1, i = ie(l, i);
2585
- }
2586
- return l.length;
2587
- }
2588
- export {
2589
- U as Annotation,
2590
- qe as AnnotationType,
2591
- b as ChangeDesc,
2592
- k as ChangeSet,
2593
- T as CharCategory,
2594
- ee as Compartment,
2595
- p as EditorSelection,
2596
- w as EditorState,
2597
- A as Facet,
2598
- De as Line,
2599
- M as MapMode,
2600
- _e as Prec,
2601
- q as Range,
2602
- S as RangeSet,
2603
- _ as RangeSetBuilder,
2604
- j as RangeValue,
2605
- C as SelectionRange,
2606
- I as StateEffect,
2607
- We as StateEffectType,
2608
- V as StateField,
2609
- y as Text,
2610
- P as Transaction,
2611
- et as combineConfig,
2612
- ie as findClusterBreak,
2613
- tt as findColumn
2614
- };