diff --git "a/src/backend/gradio_logsview/templates/component/Index-d65e8fec.js" "b/src/backend/gradio_logsview/templates/component/Index-d65e8fec.js" new file mode 100644--- /dev/null +++ "b/src/backend/gradio_logsview/templates/component/Index-d65e8fec.js" @@ -0,0 +1,19773 @@ +class Y { + /** + Get the line description around the given position. + */ + lineAt(e) { + if (e < 0 || e > this.length) + throw new RangeError(`Invalid position ${e} in document of length ${this.length}`); + return this.lineInner(e, !1, 1, 0); + } + /** + Get the description for the given (1-based) line number. + */ + line(e) { + if (e < 1 || e > this.lines) + throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`); + return this.lineInner(e, !0, 1, 0); + } + /** + Replace a range of the text with the given content. + */ + replace(e, t, i) { + [e, t] = Mi(this, e, t); + let s = []; + return this.decompose( + 0, + e, + s, + 2 + /* Open.To */ + ), i.length && i.decompose( + 0, + i.length, + s, + 3 + /* Open.To */ + ), this.decompose( + t, + this.length, + s, + 1 + /* Open.From */ + ), nt.from(s, this.length - (t - e) + i.length); + } + /** + Append another document to this one. + */ + append(e) { + return this.replace(this.length, this.length, e); + } + /** + Retrieve the text between the given points. + */ + slice(e, t = this.length) { + [e, t] = Mi(this, e, t); + let i = []; + return this.decompose(e, t, i, 0), nt.from(i, t - e); + } + /** + Test whether this text is equal to another instance. + */ + eq(e) { + if (e == this) + return !0; + if (e.length != this.length || e.lines != this.lines) + return !1; + let t = this.scanIdentical(e, 1), i = this.length - this.scanIdentical(e, -1), s = new tn(this), r = new tn(e); + for (let o = t, l = t; ; ) { + if (s.next(o), r.next(o), o = 0, s.lineBreak != r.lineBreak || s.done != r.done || s.value != r.value) + return !1; + if (l += s.value.length, s.done || l >= i) + return !0; + } + } + /** + Iterate over the text. When `dir` is `-1`, iteration happens + from end to start. This will return lines and the breaks between + them as separate strings. + */ + iter(e = 1) { + return new tn(this, e); + } + /** + Iterate over a range of the text. When `from` > `to`, the + iterator will run in reverse. + */ + iterRange(e, t = this.length) { + return new rf(this, e, t); + } + /** + Return a cursor that iterates over the given range of lines, + _without_ returning the line breaks between, and yielding empty + strings for empty lines. + + When `from` and `to` are given, they should be 1-based line numbers. + */ + iterLines(e, t) { + let i; + if (e == null) + i = this.iter(); + else { + t == null && (t = this.lines + 1); + let s = this.line(e).from; + i = this.iterRange(s, Math.max(s, t == this.lines + 1 ? this.length : t <= 1 ? 0 : this.line(t - 1).to)); + } + return new of(i); + } + /** + Return the document as a string, using newline characters to + separate lines. + */ + toString() { + return this.sliceString(0); + } + /** + Convert the document to an array of lines (which can be + deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)). + */ + toJSON() { + let e = []; + return this.flatten(e), e; + } + /** + @internal + */ + constructor() { + } + /** + Create a `Text` instance for the given array of lines. + */ + static of(e) { + if (e.length == 0) + throw new RangeError("A document must have at least one line"); + return e.length == 1 && !e[0] ? Y.empty : e.length <= 32 ? new le(e) : nt.from(le.split(e, [])); + } +} +class le extends Y { + constructor(e, t = kd(e)) { + super(), this.text = e, this.length = t; + } + get lines() { + return this.text.length; + } + get children() { + return null; + } + lineInner(e, t, i, s) { + for (let r = 0; ; r++) { + let o = this.text[r], l = s + o.length; + if ((t ? i : l) >= e) + return new vd(s, l, i, o); + s = l + 1, i++; + } + } + decompose(e, t, i, s) { + let r = e <= 0 && t >= this.length ? this : new le(kl(this.text, e, t), Math.min(t, this.length) - Math.max(0, e)); + if (s & 1) { + let o = i.pop(), l = ts(r.text, o.text.slice(), 0, r.length); + if (l.length <= 32) + i.push(new le(l, o.length + r.length)); + else { + let a = l.length >> 1; + i.push(new le(l.slice(0, a)), new le(l.slice(a))); + } + } else + i.push(r); + } + replace(e, t, i) { + if (!(i instanceof le)) + return super.replace(e, t, i); + [e, t] = Mi(this, e, t); + let s = ts(this.text, ts(i.text, kl(this.text, 0, e)), t), r = this.length + i.length - (t - e); + return s.length <= 32 ? new le(s, r) : nt.from(le.split(s, []), r); + } + sliceString(e, t = this.length, i = ` +`) { + [e, t] = Mi(this, e, t); + let s = ""; + for (let r = 0, o = 0; r <= t && o < this.text.length; o++) { + let l = this.text[o], a = r + l.length; + r > e && o && (s += i), e < a && t > r && (s += l.slice(Math.max(0, e - r), t - r)), r = a + 1; + } + return s; + } + flatten(e) { + for (let t of this.text) + e.push(t); + } + scanIdentical() { + return 0; + } + static split(e, t) { + let i = [], s = -1; + for (let r of e) + i.push(r), s += r.length + 1, i.length == 32 && (t.push(new le(i, s)), i = [], s = -1); + return s > -1 && t.push(new le(i, s)), t; + } +} +class nt extends Y { + constructor(e, t) { + super(), this.children = e, this.length = t, this.lines = 0; + for (let i of e) + this.lines += i.lines; + } + lineInner(e, t, i, s) { + for (let r = 0; ; r++) { + let o = this.children[r], l = s + o.length, a = i + o.lines - 1; + if ((t ? a : l) >= e) + return o.lineInner(e, t, i, s); + s = l + 1, i = a + 1; + } + } + decompose(e, t, i, s) { + for (let r = 0, o = 0; o <= t && r < this.children.length; r++) { + let l = this.children[r], a = o + l.length; + if (e <= a && t >= o) { + let h = s & ((o <= e ? 1 : 0) | (a >= t ? 2 : 0)); + o >= e && a <= t && !h ? i.push(l) : l.decompose(e - o, t - o, i, h); + } + o = a + 1; + } + } + replace(e, t, i) { + if ([e, t] = Mi(this, e, t), i.lines < this.lines) + for (let s = 0, r = 0; s < this.children.length; s++) { + let o = this.children[s], l = r + o.length; + if (e >= r && t <= l) { + let a = o.replace(e - r, t - r, i), h = this.lines - o.lines + a.lines; + if (a.lines < h >> 4 && a.lines > h >> 6) { + let f = this.children.slice(); + return f[s] = a, new nt(f, this.length - (t - e) + i.length); + } + return super.replace(r, l, a); + } + r = l + 1; + } + return super.replace(e, t, i); + } + sliceString(e, t = this.length, i = ` +`) { + [e, t] = Mi(this, e, t); + let s = ""; + for (let r = 0, o = 0; r < this.children.length && o <= t; r++) { + let l = this.children[r], a = o + l.length; + o > e && r && (s += i), e < a && t > o && (s += l.sliceString(e - o, t - o, i)), o = a + 1; + } + return s; + } + flatten(e) { + for (let t of this.children) + t.flatten(e); + } + scanIdentical(e, t) { + if (!(e instanceof nt)) + return 0; + let i = 0, [s, r, o, l] = t > 0 ? [0, 0, this.children.length, e.children.length] : [this.children.length - 1, e.children.length - 1, -1, -1]; + for (; ; s += t, r += t) { + if (s == o || r == l) + return i; + let a = this.children[s], h = e.children[r]; + if (a != h) + return i + a.scanIdentical(h, t); + i += a.length + 1; + } + } + static from(e, t = e.reduce((i, s) => i + s.length + 1, -1)) { + let i = 0; + for (let d of e) + i += d.lines; + if (i < 32) { + let d = []; + for (let p of e) + p.flatten(d); + return new le(d, t); + } + let s = Math.max( + 32, + i >> 5 + /* Tree.BranchShift */ + ), r = s << 1, o = s >> 1, l = [], a = 0, h = -1, f = []; + function c(d) { + let p; + if (d.lines > r && d instanceof nt) + for (let m of d.children) + c(m); + else + d.lines > o && (a > o || !a) ? (u(), l.push(d)) : d instanceof le && a && (p = f[f.length - 1]) instanceof le && d.lines + p.lines <= 32 ? (a += d.lines, h += d.length + 1, f[f.length - 1] = new le(p.text.concat(d.text), p.length + 1 + d.length)) : (a + d.lines > s && u(), a += d.lines, h += d.length + 1, f.push(d)); + } + function u() { + a != 0 && (l.push(f.length == 1 ? f[0] : nt.from(f, h)), h = -1, a = f.length = 0); + } + for (let d of e) + c(d); + return u(), l.length == 1 ? l[0] : new nt(l, t); + } +} +Y.empty = /* @__PURE__ */ new le([""], 0); +function kd(n) { + let e = -1; + for (let t of n) + e += t.length + 1; + return e; +} +function ts(n, e, t = 0, i = 1e9) { + for (let s = 0, r = 0, o = !0; r < n.length && s <= i; r++) { + let l = n[r], a = s + l.length; + a >= t && (a > i && (l = l.slice(0, i - s)), s < t && (l = l.slice(t - s)), o ? (e[e.length - 1] += l, o = !1) : e.push(l)), s = a + 1; + } + return e; +} +function kl(n, e, t) { + return ts(n, [""], e, t); +} +class tn { + constructor(e, t = 1) { + this.dir = t, this.done = !1, this.lineBreak = !1, this.value = "", this.nodes = [e], this.offsets = [t > 0 ? 1 : (e instanceof le ? e.text.length : e.children.length) << 1]; + } + nextInner(e, t) { + for (this.done = this.lineBreak = !1; ; ) { + let i = this.nodes.length - 1, s = this.nodes[i], r = this.offsets[i], o = r >> 1, l = s instanceof le ? s.text.length : s.children.length; + if (o == (t > 0 ? l : 0)) { + if (i == 0) + return this.done = !0, this.value = "", this; + t > 0 && this.offsets[i - 1]++, this.nodes.pop(), this.offsets.pop(); + } else if ((r & 1) == (t > 0 ? 0 : 1)) { + if (this.offsets[i] += t, e == 0) + return this.lineBreak = !0, this.value = ` +`, this; + e--; + } else if (s instanceof le) { + let a = s.text[o + (t < 0 ? -1 : 0)]; + if (this.offsets[i] += t, a.length > Math.max(0, e)) + return this.value = e == 0 ? a : t > 0 ? a.slice(e) : a.slice(0, a.length - e), this; + e -= a.length; + } else { + let a = s.children[o + (t < 0 ? -1 : 0)]; + e > a.length ? (e -= a.length, this.offsets[i] += t) : (t < 0 && this.offsets[i]--, this.nodes.push(a), this.offsets.push(t > 0 ? 1 : (a instanceof le ? a.text.length : a.children.length) << 1)); + } + } + } + next(e = 0) { + return e < 0 && (this.nextInner(-e, -this.dir), e = this.value.length), this.nextInner(e, this.dir); + } +} +class rf { + constructor(e, t, i) { + this.value = "", this.done = !1, this.cursor = new tn(e, t > i ? -1 : 1), this.pos = t > i ? e.length : 0, this.from = Math.min(t, i), this.to = Math.max(t, i); + } + nextInner(e, t) { + if (t < 0 ? this.pos <= this.from : this.pos >= this.to) + return this.value = "", this.done = !0, this; + e += Math.max(0, t < 0 ? this.pos - this.to : this.from - this.pos); + let i = t < 0 ? this.pos - this.from : this.to - this.pos; + e > i && (e = i), i -= e; + let { value: s } = this.cursor.next(e); + return this.pos += (s.length + e) * t, this.value = s.length <= i ? s : t < 0 ? s.slice(s.length - i) : s.slice(0, i), this.done = !this.value, this; + } + next(e = 0) { + 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); + } + get lineBreak() { + return this.cursor.lineBreak && this.value != ""; + } +} +class of { + constructor(e) { + this.inner = e, this.afterBreak = !0, this.value = "", this.done = !1; + } + next(e = 0) { + let { done: t, lineBreak: i, value: s } = this.inner.next(e); + return t && this.afterBreak ? (this.value = "", this.afterBreak = !1) : t ? (this.done = !0, this.value = "") : i ? this.afterBreak ? this.value = "" : (this.afterBreak = !0, this.next()) : (this.value = s, this.afterBreak = !1), this; + } + get lineBreak() { + return !1; + } +} +typeof Symbol < "u" && (Y.prototype[Symbol.iterator] = function() { + return this.iter(); +}, tn.prototype[Symbol.iterator] = rf.prototype[Symbol.iterator] = of.prototype[Symbol.iterator] = function() { + return this; +}); +class vd { + /** + @internal + */ + constructor(e, t, i, s) { + this.from = e, this.to = t, this.number = i, this.text = s; + } + /** + The length of the line (not including any line break after it). + */ + get length() { + return this.to - this.from; + } +} +function Mi(n, e, t) { + return e = Math.max(0, Math.min(n.length, e)), [e, Math.max(e, Math.min(n.length, t))]; +} +let vi = /* @__PURE__ */ "lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((n) => n ? parseInt(n, 36) : 1); +for (let n = 1; n < vi.length; n++) + vi[n] += vi[n - 1]; +function xd(n) { + for (let e = 1; e < vi.length; e += 2) + if (vi[e] > n) + return vi[e - 1] <= n; + return !1; +} +function vl(n) { + return n >= 127462 && n <= 127487; +} +const xl = 8205; +function ve(n, e, t = !0, i = !0) { + return (t ? lf : Sd)(n, e, i); +} +function lf(n, e, t) { + if (e == n.length) + return e; + e && af(n.charCodeAt(e)) && hf(n.charCodeAt(e - 1)) && e--; + let i = ge(n, e); + for (e += Ue(i); e < n.length; ) { + let s = ge(n, e); + if (i == xl || s == xl || t && xd(s)) + e += Ue(s), i = s; + else if (vl(s)) { + let r = 0, o = e - 2; + for (; o >= 0 && vl(ge(n, o)); ) + r++, o -= 2; + if (r % 2 == 0) + break; + e += 2; + } else + break; + } + return e; +} +function Sd(n, e, t) { + for (; e > 0; ) { + let i = lf(n, e - 2, t); + if (i < e) + return i; + e--; + } + return 0; +} +function af(n) { + return n >= 56320 && n < 57344; +} +function hf(n) { + return n >= 55296 && n < 56320; +} +function ge(n, e) { + let t = n.charCodeAt(e); + if (!hf(t) || e + 1 == n.length) + return t; + let i = n.charCodeAt(e + 1); + return af(i) ? (t - 55296 << 10) + (i - 56320) + 65536 : t; +} +function ff(n) { + return n <= 65535 ? String.fromCharCode(n) : (n -= 65536, String.fromCharCode((n >> 10) + 55296, (n & 1023) + 56320)); +} +function Ue(n) { + return n < 65536 ? 1 : 2; +} +const Er = /\r\n?|\n/; +var pe = /* @__PURE__ */ function(n) { + return n[n.Simple = 0] = "Simple", n[n.TrackDel = 1] = "TrackDel", n[n.TrackBefore = 2] = "TrackBefore", n[n.TrackAfter = 3] = "TrackAfter", n; +}(pe || (pe = {})); +class ct { + // Sections are encoded as pairs of integers. The first is the + // length in the current document, and the second is -1 for + // unaffected sections, and the length of the replacement content + // otherwise. So an insertion would be (0, n>0), a deletion (n>0, + // 0), and a replacement two positive numbers. + /** + @internal + */ + constructor(e) { + this.sections = e; + } + /** + The length of the document before the change. + */ + get length() { + let e = 0; + for (let t = 0; t < this.sections.length; t += 2) + e += this.sections[t]; + return e; + } + /** + The length of the document after the change. + */ + get newLength() { + let e = 0; + for (let t = 0; t < this.sections.length; t += 2) { + let i = this.sections[t + 1]; + e += i < 0 ? this.sections[t] : i; + } + return e; + } + /** + False when there are actual changes in this set. + */ + get empty() { + return this.sections.length == 0 || this.sections.length == 2 && this.sections[1] < 0; + } + /** + Iterate over the unchanged parts left by these changes. `posA` + provides the position of the range in the old document, `posB` + the new position in the changed document. + */ + iterGaps(e) { + for (let t = 0, i = 0, s = 0; t < this.sections.length; ) { + let r = this.sections[t++], o = this.sections[t++]; + o < 0 ? (e(i, s, r), s += r) : s += o, i += r; + } + } + /** + Iterate over the ranges changed by these changes. (See + [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a + variant that also provides you with the inserted text.) + `fromA`/`toA` provides the extent of the change in the starting + document, `fromB`/`toB` the extent of the replacement in the + changed document. + + When `individual` is true, adjacent changes (which are kept + separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are + reported separately. + */ + iterChangedRanges(e, t = !1) { + Rr(this, e, t); + } + /** + Get a description of the inverted form of these changes. + */ + get invertedDesc() { + let e = []; + for (let t = 0; t < this.sections.length; ) { + let i = this.sections[t++], s = this.sections[t++]; + s < 0 ? e.push(i, s) : e.push(s, i); + } + return new ct(e); + } + /** + Compute the combined effect of applying another set of changes + after this one. The length of the document after this set should + match the length before `other`. + */ + composeDesc(e) { + return this.empty ? e : e.empty ? this : cf(this, e); + } + /** + Map this description, which should start with the same document + as `other`, over another set of changes, so that it can be + applied after it. When `before` is true, map as if the changes + in `other` happened before the ones in `this`. + */ + mapDesc(e, t = !1) { + return e.empty ? this : Ir(this, e, t); + } + mapPos(e, t = -1, i = pe.Simple) { + let s = 0, r = 0; + for (let o = 0; o < this.sections.length; ) { + let l = this.sections[o++], a = this.sections[o++], h = s + l; + if (a < 0) { + if (h > e) + return r + (e - s); + r += l; + } else { + if (i != pe.Simple && h >= e && (i == pe.TrackDel && s < e && h > e || i == pe.TrackBefore && s < e || i == pe.TrackAfter && h > e)) + return null; + if (h > e || h == e && t < 0 && !l) + return e == s || t < 0 ? r : r + a; + r += a; + } + s = h; + } + if (e > s) + throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`); + return r; + } + /** + Check whether these changes touch a given range. When one of the + changes entirely covers the range, the string `"cover"` is + returned. + */ + touchesRange(e, t = e) { + for (let i = 0, s = 0; i < this.sections.length && s <= t; ) { + let r = this.sections[i++], o = this.sections[i++], l = s + r; + if (o >= 0 && s <= t && l >= e) + return s < e && l > t ? "cover" : !0; + s = l; + } + return !1; + } + /** + @internal + */ + toString() { + let e = ""; + for (let t = 0; t < this.sections.length; ) { + let i = this.sections[t++], s = this.sections[t++]; + e += (e ? " " : "") + i + (s >= 0 ? ":" + s : ""); + } + return e; + } + /** + Serialize this change desc to a JSON-representable value. + */ + toJSON() { + return this.sections; + } + /** + Create a change desc from its JSON representation (as produced + by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON). + */ + static fromJSON(e) { + if (!Array.isArray(e) || e.length % 2 || e.some((t) => typeof t != "number")) + throw new RangeError("Invalid JSON representation of ChangeDesc"); + return new ct(e); + } + /** + @internal + */ + static create(e) { + return new ct(e); + } +} +class fe extends ct { + constructor(e, t) { + super(e), this.inserted = t; + } + /** + Apply the changes to a document, returning the modified + document. + */ + apply(e) { + if (this.length != e.length) + throw new RangeError("Applying change set to a document with the wrong length"); + return Rr(this, (t, i, s, r, o) => e = e.replace(s, s + (i - t), o), !1), e; + } + mapDesc(e, t = !1) { + return Ir(this, e, t, !0); + } + /** + Given the document as it existed _before_ the changes, return a + change set that represents the inverse of this set, which could + be used to go from the document created by the changes back to + the document as it existed before the changes. + */ + invert(e) { + let t = this.sections.slice(), i = []; + for (let s = 0, r = 0; s < t.length; s += 2) { + let o = t[s], l = t[s + 1]; + if (l >= 0) { + t[s] = l, t[s + 1] = o; + let a = s >> 1; + for (; i.length < a; ) + i.push(Y.empty); + i.push(o ? e.slice(r, r + o) : Y.empty); + } + r += o; + } + return new fe(t, i); + } + /** + Combine two subsequent change sets into a single set. `other` + must start in the document produced by `this`. If `this` goes + `docA` → `docB` and `other` represents `docB` → `docC`, the + returned value will represent the change `docA` → `docC`. + */ + compose(e) { + return this.empty ? e : e.empty ? this : cf(this, e, !0); + } + /** + Given another change set starting in the same document, maps this + change set over the other, producing a new change set that can be + applied to the document produced by applying `other`. When + `before` is `true`, order changes as if `this` comes before + `other`, otherwise (the default) treat `other` as coming first. + + Given two changes `A` and `B`, `A.compose(B.map(A))` and + `B.compose(A.map(B, true))` will produce the same document. This + provides a basic form of [operational + transformation](https://en.wikipedia.org/wiki/Operational_transformation), + and can be used for collaborative editing. + */ + map(e, t = !1) { + return e.empty ? this : Ir(this, e, t, !0); + } + /** + Iterate over the changed ranges in the document, calling `f` for + each, with the range in the original document (`fromA`-`toA`) + and the range that replaces it in the new document + (`fromB`-`toB`). + + When `individual` is true, adjacent changes are reported + separately. + */ + iterChanges(e, t = !1) { + Rr(this, e, t); + } + /** + Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change + set. + */ + get desc() { + return ct.create(this.sections); + } + /** + @internal + */ + filter(e) { + let t = [], i = [], s = [], r = new fn(this); + e: + for (let o = 0, l = 0; ; ) { + let a = o == e.length ? 1e9 : e[o++]; + for (; l < a || l == a && r.len == 0; ) { + if (r.done) + break e; + let f = Math.min(r.len, a - l); + me(s, f, -1); + let c = r.ins == -1 ? -1 : r.off == 0 ? r.ins : 0; + me(t, f, c), c > 0 && Tt(i, t, r.text), r.forward(f), l += f; + } + let h = e[o++]; + for (; l < h; ) { + if (r.done) + break e; + let f = Math.min(r.len, h - l); + me(t, f, -1), me(s, f, r.ins == -1 ? -1 : r.off == 0 ? r.ins : 0), r.forward(f), l += f; + } + } + return { + changes: new fe(t, i), + filtered: ct.create(s) + }; + } + /** + Serialize this change set to a JSON-representable value. + */ + toJSON() { + let e = []; + for (let t = 0; t < this.sections.length; t += 2) { + let i = this.sections[t], s = this.sections[t + 1]; + s < 0 ? e.push(i) : s == 0 ? e.push([i]) : e.push([i].concat(this.inserted[t >> 1].toJSON())); + } + return e; + } + /** + Create a change set for the given changes, for a document of the + given length, using `lineSep` as line separator. + */ + static of(e, t, i) { + let s = [], r = [], o = 0, l = null; + function a(f = !1) { + if (!f && !s.length) + return; + o < t && me(s, t - o, -1); + let c = new fe(s, r); + l = l ? l.compose(c.map(l)) : c, s = [], r = [], o = 0; + } + function h(f) { + if (Array.isArray(f)) + for (let c of f) + h(c); + else if (f instanceof fe) { + if (f.length != t) + throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${t})`); + a(), l = l ? l.compose(f.map(l)) : f; + } else { + let { from: c, to: u = c, insert: d } = f; + if (c > u || c < 0 || u > t) + throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${t})`); + let p = d ? typeof d == "string" ? Y.of(d.split(i || Er)) : d : Y.empty, m = p.length; + if (c == u && m == 0) + return; + c < o && a(), c > o && me(s, c - o, -1), me(s, u - c, m), Tt(r, s, p), o = u; + } + } + return h(e), a(!l), l; + } + /** + Create an empty changeset of the given length. + */ + static empty(e) { + return new fe(e ? [e, -1] : [], []); + } + /** + Create a changeset from its JSON representation (as produced by + [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON). + */ + static fromJSON(e) { + if (!Array.isArray(e)) + throw new RangeError("Invalid JSON representation of ChangeSet"); + let t = [], i = []; + for (let s = 0; s < e.length; s++) { + let r = e[s]; + if (typeof r == "number") + t.push(r, -1); + else { + if (!Array.isArray(r) || typeof r[0] != "number" || r.some((o, l) => l && typeof o != "string")) + throw new RangeError("Invalid JSON representation of ChangeSet"); + if (r.length == 1) + t.push(r[0], 0); + else { + for (; i.length < s; ) + i.push(Y.empty); + i[s] = Y.of(r.slice(1)), t.push(r[0], i[s].length); + } + } + } + return new fe(t, i); + } + /** + @internal + */ + static createSet(e, t) { + return new fe(e, t); + } +} +function me(n, e, t, i = !1) { + if (e == 0 && t <= 0) + return; + let s = n.length - 2; + s >= 0 && t <= 0 && t == n[s + 1] ? n[s] += e : e == 0 && n[s] == 0 ? n[s + 1] += t : i ? (n[s] += e, n[s + 1] += t) : n.push(e, t); +} +function Tt(n, e, t) { + if (t.length == 0) + return; + let i = e.length - 2 >> 1; + if (i < n.length) + n[n.length - 1] = n[n.length - 1].append(t); + else { + for (; n.length < i; ) + n.push(Y.empty); + n.push(t); + } +} +function Rr(n, e, t) { + let i = n.inserted; + for (let s = 0, r = 0, o = 0; o < n.sections.length; ) { + let l = n.sections[o++], a = n.sections[o++]; + if (a < 0) + s += l, r += l; + else { + let h = s, f = r, c = Y.empty; + for (; h += l, f += a, a && i && (c = c.append(i[o - 2 >> 1])), !(t || o == n.sections.length || n.sections[o + 1] < 0); ) + l = n.sections[o++], a = n.sections[o++]; + e(s, h, r, f, c), s = h, r = f; + } + } +} +function Ir(n, e, t, i = !1) { + let s = [], r = i ? [] : null, o = new fn(n), l = new fn(e); + for (let a = -1; ; ) + if (o.ins == -1 && l.ins == -1) { + let h = Math.min(o.len, l.len); + me(s, h, -1), o.forward(h), l.forward(h); + } else if (l.ins >= 0 && (o.ins < 0 || a == o.i || o.off == 0 && (l.len < o.len || l.len == o.len && !t))) { + let h = l.len; + for (me(s, l.ins, -1); h; ) { + let f = Math.min(o.len, h); + o.ins >= 0 && a < o.i && o.len <= f && (me(s, 0, o.ins), r && Tt(r, s, o.text), a = o.i), o.forward(f), h -= f; + } + l.next(); + } else if (o.ins >= 0) { + let h = 0, f = o.len; + for (; f; ) + if (l.ins == -1) { + let c = Math.min(f, l.len); + h += c, f -= c, l.forward(c); + } else if (l.ins == 0 && l.len < f) + f -= l.len, l.next(); + else + break; + me(s, h, a < o.i ? o.ins : 0), r && a < o.i && Tt(r, s, o.text), a = o.i, o.forward(o.len - f); + } else { + if (o.done && l.done) + return r ? fe.createSet(s, r) : ct.create(s); + throw new Error("Mismatched change set lengths"); + } +} +function cf(n, e, t = !1) { + let i = [], s = t ? [] : null, r = new fn(n), o = new fn(e); + for (let l = !1; ; ) { + if (r.done && o.done) + return s ? fe.createSet(i, s) : ct.create(i); + if (r.ins == 0) + me(i, r.len, 0, l), r.next(); + else if (o.len == 0 && !o.done) + me(i, 0, o.ins, l), s && Tt(s, i, o.text), o.next(); + else { + if (r.done || o.done) + throw new Error("Mismatched change set lengths"); + { + let a = Math.min(r.len2, o.len), h = i.length; + if (r.ins == -1) { + let f = o.ins == -1 ? -1 : o.off ? 0 : o.ins; + me(i, a, f, l), s && f && Tt(s, i, o.text); + } else + o.ins == -1 ? (me(i, r.off ? 0 : r.len, a, l), s && Tt(s, i, r.textBit(a))) : (me(i, r.off ? 0 : r.len, o.off ? 0 : o.ins, l), s && !o.off && Tt(s, i, o.text)); + l = (r.ins > a || o.ins >= 0 && o.len > a) && (l || i.length > h), r.forward2(a), o.forward(a); + } + } + } +} +class fn { + constructor(e) { + this.set = e, this.i = 0, this.next(); + } + next() { + let { sections: e } = this.set; + this.i < e.length ? (this.len = e[this.i++], this.ins = e[this.i++]) : (this.len = 0, this.ins = -2), this.off = 0; + } + get done() { + return this.ins == -2; + } + get len2() { + return this.ins < 0 ? this.len : this.ins; + } + get text() { + let { inserted: e } = this.set, t = this.i - 2 >> 1; + return t >= e.length ? Y.empty : e[t]; + } + textBit(e) { + let { inserted: t } = this.set, i = this.i - 2 >> 1; + return i >= t.length && !e ? Y.empty : t[i].slice(this.off, e == null ? void 0 : this.off + e); + } + forward(e) { + e == this.len ? this.next() : (this.len -= e, this.off += e); + } + forward2(e) { + this.ins == -1 ? this.forward(e) : e == this.ins ? this.next() : (this.ins -= e, this.off += e); + } +} +class Kt { + constructor(e, t, i) { + this.from = e, this.to = t, this.flags = i; + } + /** + The anchor of the range—the side that doesn't move when you + extend it. + */ + get anchor() { + return this.flags & 32 ? this.to : this.from; + } + /** + The head of the range, which is moved when the range is + [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend). + */ + get head() { + return this.flags & 32 ? this.from : this.to; + } + /** + True when `anchor` and `head` are at the same position. + */ + get empty() { + return this.from == this.to; + } + /** + If this is a cursor that is explicitly associated with the + character on one of its sides, this returns the side. -1 means + the character before its position, 1 the character after, and 0 + means no association. + */ + get assoc() { + return this.flags & 8 ? -1 : this.flags & 16 ? 1 : 0; + } + /** + The bidirectional text level associated with this cursor, if + any. + */ + get bidiLevel() { + let e = this.flags & 7; + return e == 7 ? null : e; + } + /** + The goal column (stored vertical offset) associated with a + cursor. This is used to preserve the vertical position when + [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across + lines of different length. + */ + get goalColumn() { + let e = this.flags >> 6; + return e == 16777215 ? void 0 : e; + } + /** + Map this range through a change, producing a valid range in the + updated document. + */ + map(e, t = -1) { + let i, s; + return this.empty ? i = s = e.mapPos(this.from, t) : (i = e.mapPos(this.from, 1), s = e.mapPos(this.to, -1)), i == this.from && s == this.to ? this : new Kt(i, s, this.flags); + } + /** + Extend this range to cover at least `from` to `to`. + */ + extend(e, t = e) { + if (e <= this.anchor && t >= this.anchor) + return C.range(e, t); + let i = Math.abs(e - this.anchor) > Math.abs(t - this.anchor) ? e : t; + return C.range(this.anchor, i); + } + /** + Compare this range to another range. + */ + eq(e, t = !1) { + return this.anchor == e.anchor && this.head == e.head && (!t || !this.empty || this.assoc == e.assoc); + } + /** + Return a JSON-serializable object representing the range. + */ + toJSON() { + return { anchor: this.anchor, head: this.head }; + } + /** + Convert a JSON representation of a range to a `SelectionRange` + instance. + */ + static fromJSON(e) { + if (!e || typeof e.anchor != "number" || typeof e.head != "number") + throw new RangeError("Invalid JSON representation for SelectionRange"); + return C.range(e.anchor, e.head); + } + /** + @internal + */ + static create(e, t, i) { + return new Kt(e, t, i); + } +} +class C { + constructor(e, t) { + this.ranges = e, this.mainIndex = t; + } + /** + Map a selection through a change. Used to adjust the selection + position for changes. + */ + map(e, t = -1) { + return e.empty ? this : C.create(this.ranges.map((i) => i.map(e, t)), this.mainIndex); + } + /** + Compare this selection to another selection. By default, ranges + are compared only by position. When `includeAssoc` is true, + cursor ranges must also have the same + [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value. + */ + eq(e, t = !1) { + if (this.ranges.length != e.ranges.length || this.mainIndex != e.mainIndex) + return !1; + for (let i = 0; i < this.ranges.length; i++) + if (!this.ranges[i].eq(e.ranges[i], t)) + return !1; + return !0; + } + /** + Get the primary selection range. Usually, you should make sure + your code applies to _all_ ranges, by using methods like + [`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange). + */ + get main() { + return this.ranges[this.mainIndex]; + } + /** + Make sure the selection only has one range. Returns a selection + holding only the main range from this selection. + */ + asSingle() { + return this.ranges.length == 1 ? this : new C([this.main], 0); + } + /** + Extend this selection with an extra range. + */ + addRange(e, t = !0) { + return C.create([e].concat(this.ranges), t ? 0 : this.mainIndex + 1); + } + /** + Replace a given range with another range, and then normalize the + selection to merge and sort ranges if necessary. + */ + replaceRange(e, t = this.mainIndex) { + let i = this.ranges.slice(); + return i[t] = e, C.create(i, this.mainIndex); + } + /** + Convert this selection to an object that can be serialized to + JSON. + */ + toJSON() { + return { ranges: this.ranges.map((e) => e.toJSON()), main: this.mainIndex }; + } + /** + Create a selection from a JSON representation. + */ + static fromJSON(e) { + if (!e || !Array.isArray(e.ranges) || typeof e.main != "number" || e.main >= e.ranges.length) + throw new RangeError("Invalid JSON representation for EditorSelection"); + return new C(e.ranges.map((t) => Kt.fromJSON(t)), e.main); + } + /** + Create a selection holding a single range. + */ + static single(e, t = e) { + return new C([C.range(e, t)], 0); + } + /** + Sort and merge the given set of ranges, creating a valid + selection. + */ + static create(e, t = 0) { + if (e.length == 0) + throw new RangeError("A selection needs at least one range"); + for (let i = 0, s = 0; s < e.length; s++) { + let r = e[s]; + if (r.empty ? r.from <= i : r.from < i) + return C.normalized(e.slice(), t); + i = r.to; + } + return new C(e, t); + } + /** + Create a cursor selection range at the given position. You can + safely ignore the optional arguments in most situations. + */ + static cursor(e, t = 0, i, s) { + return Kt.create(e, e, (t == 0 ? 0 : t < 0 ? 8 : 16) | (i == null ? 7 : Math.min(6, i)) | (s ?? 16777215) << 6); + } + /** + Create a selection range. + */ + static range(e, t, i, s) { + let r = (i ?? 16777215) << 6 | (s == null ? 7 : Math.min(6, s)); + return t < e ? Kt.create(t, e, 48 | r) : Kt.create(e, t, (t > e ? 8 : 0) | r); + } + /** + @internal + */ + static normalized(e, t = 0) { + let i = e[t]; + e.sort((s, r) => s.from - r.from), t = e.indexOf(i); + for (let s = 1; s < e.length; s++) { + let r = e[s], o = e[s - 1]; + if (r.empty ? r.from <= o.to : r.from < o.to) { + let l = o.from, a = Math.max(r.to, o.to); + s <= t && t--, e.splice(--s, 2, r.anchor > r.head ? C.range(a, l) : C.range(l, a)); + } + } + return new C(e, t); + } +} +function uf(n, e) { + for (let t of n.ranges) + if (t.to > e) + throw new RangeError("Selection points outside of document"); +} +let Eo = 0; +class D { + constructor(e, t, i, s, r) { + this.combine = e, this.compareInput = t, this.compare = i, this.isStatic = s, this.id = Eo++, this.default = e([]), this.extensions = typeof r == "function" ? r(this) : r; + } + /** + Returns a facet reader for this facet, which can be used to + [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it. + */ + get reader() { + return this; + } + /** + Define a new facet. + */ + static define(e = {}) { + return new D(e.combine || ((t) => t), e.compareInput || ((t, i) => t === i), e.compare || (e.combine ? (t, i) => t === i : Ro), !!e.static, e.enables); + } + /** + Returns an extension that adds the given value to this facet. + */ + of(e) { + return new is([], this, 0, e); + } + /** + Create an extension that computes a value for the facet from a + state. You must take care to declare the parts of the state that + this value depends on, since your function is only called again + for a new state when one of those parts changed. + + In cases where your value depends only on a single field, you'll + want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead. + */ + compute(e, t) { + if (this.isStatic) + throw new Error("Can't compute a static facet"); + return new is(e, this, 1, t); + } + /** + Create an extension that computes zero or more values for this + facet from a state. + */ + computeN(e, t) { + if (this.isStatic) + throw new Error("Can't compute a static facet"); + return new is(e, this, 2, t); + } + from(e, t) { + return t || (t = (i) => i), this.compute([e], (i) => t(i.field(e))); + } +} +function Ro(n, e) { + return n == e || n.length == e.length && n.every((t, i) => t === e[i]); +} +class is { + constructor(e, t, i, s) { + this.dependencies = e, this.facet = t, this.type = i, this.value = s, this.id = Eo++; + } + dynamicSlot(e) { + var t; + let i = this.value, s = this.facet.compareInput, r = this.id, o = e[r] >> 1, l = this.type == 2, a = !1, h = !1, f = []; + for (let c of this.dependencies) + c == "doc" ? a = !0 : c == "selection" ? h = !0 : ((t = e[c.id]) !== null && t !== void 0 ? t : 1) & 1 || f.push(e[c.id]); + return { + create(c) { + return c.values[o] = i(c), 1; + }, + update(c, u) { + if (a && u.docChanged || h && (u.docChanged || u.selection) || Nr(c, f)) { + let d = i(c); + if (l ? !Sl(d, c.values[o], s) : !s(d, c.values[o])) + return c.values[o] = d, 1; + } + return 0; + }, + reconfigure: (c, u) => { + let d, p = u.config.address[r]; + if (p != null) { + let m = ps(u, p); + if (this.dependencies.every((g) => g instanceof D ? u.facet(g) === c.facet(g) : g instanceof Me ? u.field(g, !1) == c.field(g, !1) : !0) || (l ? Sl(d = i(c), m, s) : s(d = i(c), m))) + return c.values[o] = m, 0; + } else + d = i(c); + return c.values[o] = d, 1; + } + }; + } +} +function Sl(n, e, t) { + if (n.length != e.length) + return !1; + for (let i = 0; i < n.length; i++) + if (!t(n[i], e[i])) + return !1; + return !0; +} +function Nr(n, e) { + let t = !1; + for (let i of e) + nn(n, i) & 1 && (t = !0); + return t; +} +function _d(n, e, t) { + let i = t.map((a) => n[a.id]), s = t.map((a) => a.type), r = i.filter((a) => !(a & 1)), o = n[e.id] >> 1; + function l(a) { + let h = []; + for (let f = 0; f < i.length; f++) { + let c = ps(a, i[f]); + if (s[f] == 2) + for (let u of c) + h.push(u); + else + h.push(c); + } + return e.combine(h); + } + return { + create(a) { + for (let h of i) + nn(a, h); + return a.values[o] = l(a), 1; + }, + update(a, h) { + if (!Nr(a, r)) + return 0; + let f = l(a); + return e.compare(f, a.values[o]) ? 0 : (a.values[o] = f, 1); + }, + reconfigure(a, h) { + let f = Nr(a, i), c = h.config.facets[e.id], u = h.facet(e); + if (c && !f && Ro(t, c)) + return a.values[o] = u, 0; + let d = l(a); + return e.compare(d, u) ? (a.values[o] = u, 0) : (a.values[o] = d, 1); + } + }; +} +const _l = /* @__PURE__ */ D.define({ static: !0 }); +class Me { + constructor(e, t, i, s, r) { + this.id = e, this.createF = t, this.updateF = i, this.compareF = s, this.spec = r, this.provides = void 0; + } + /** + Define a state field. + */ + static define(e) { + let t = new Me(Eo++, e.create, e.update, e.compare || ((i, s) => i === s), e); + return e.provide && (t.provides = e.provide(t)), t; + } + create(e) { + let t = e.facet(_l).find((i) => i.field == this); + return ((t == null ? void 0 : t.create) || this.createF)(e); + } + /** + @internal + */ + slot(e) { + let t = e[this.id] >> 1; + return { + create: (i) => (i.values[t] = this.create(i), 1), + update: (i, s) => { + let r = i.values[t], o = this.updateF(r, s); + return this.compareF(r, o) ? 0 : (i.values[t] = o, 1); + }, + reconfigure: (i, s) => s.config.address[this.id] != null ? (i.values[t] = s.field(this), 0) : (i.values[t] = this.create(i), 1) + }; + } + /** + Returns an extension that enables this field and overrides the + way it is initialized. Can be useful when you need to provide a + non-default starting value for the field. + */ + init(e) { + return [this, _l.of({ field: this, create: e })]; + } + /** + State field instances can be used as + [`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a + given state. + */ + get extension() { + return this; + } +} +const qt = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 }; +function Wi(n) { + return (e) => new df(e, n); +} +const vn = { + /** + The highest precedence level, for extensions that should end up + near the start of the precedence ordering. + */ + highest: /* @__PURE__ */ Wi(qt.highest), + /** + A higher-than-default precedence, for extensions that should + come before those with default precedence. + */ + high: /* @__PURE__ */ Wi(qt.high), + /** + The default precedence, which is also used for extensions + without an explicit precedence. + */ + default: /* @__PURE__ */ Wi(qt.default), + /** + A lower-than-default precedence. + */ + low: /* @__PURE__ */ Wi(qt.low), + /** + The lowest precedence level. Meant for things that should end up + near the end of the extension order. + */ + lowest: /* @__PURE__ */ Wi(qt.lowest) +}; +class df { + constructor(e, t) { + this.inner = e, this.prec = t; + } +} +class Ps { + /** + Create an instance of this compartment to add to your [state + configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions). + */ + of(e) { + return new Vr(this, e); + } + /** + Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that + reconfigures this compartment. + */ + reconfigure(e) { + return Ps.reconfigure.of({ compartment: this, extension: e }); + } + /** + Get the current content of the compartment in the state, or + `undefined` if it isn't present. + */ + get(e) { + return e.config.compartments.get(this); + } +} +class Vr { + constructor(e, t) { + this.compartment = e, this.inner = t; + } +} +class ds { + constructor(e, t, i, s, r, o) { + for (this.base = e, this.compartments = t, this.dynamicSlots = i, this.address = s, this.staticValues = r, this.facets = o, this.statusTemplate = []; this.statusTemplate.length < i.length; ) + this.statusTemplate.push( + 0 + /* SlotStatus.Unresolved */ + ); + } + staticFacet(e) { + let t = this.address[e.id]; + return t == null ? e.default : this.staticValues[t >> 1]; + } + static resolve(e, t, i) { + let s = [], r = /* @__PURE__ */ Object.create(null), o = /* @__PURE__ */ new Map(); + for (let u of Cd(e, t, o)) + u instanceof Me ? s.push(u) : (r[u.facet.id] || (r[u.facet.id] = [])).push(u); + let l = /* @__PURE__ */ Object.create(null), a = [], h = []; + for (let u of s) + l[u.id] = h.length << 1, h.push((d) => u.slot(d)); + let f = i == null ? void 0 : i.config.facets; + for (let u in r) { + let d = r[u], p = d[0].facet, m = f && f[u] || []; + if (d.every( + (g) => g.type == 0 + /* Provider.Static */ + )) + if (l[p.id] = a.length << 1 | 1, Ro(m, d)) + a.push(i.facet(p)); + else { + let g = p.combine(d.map((y) => y.value)); + a.push(i && p.compare(g, i.facet(p)) ? i.facet(p) : g); + } + else { + for (let g of d) + g.type == 0 ? (l[g.id] = a.length << 1 | 1, a.push(g.value)) : (l[g.id] = h.length << 1, h.push((y) => g.dynamicSlot(y))); + l[p.id] = h.length << 1, h.push((g) => _d(g, p, d)); + } + } + let c = h.map((u) => u(l)); + return new ds(e, o, c, l, a, r); + } +} +function Cd(n, e, t) { + let i = [[], [], [], [], []], s = /* @__PURE__ */ new Map(); + function r(o, l) { + let a = s.get(o); + if (a != null) { + if (a <= l) + return; + let h = i[a].indexOf(o); + h > -1 && i[a].splice(h, 1), o instanceof Vr && t.delete(o.compartment); + } + if (s.set(o, l), Array.isArray(o)) + for (let h of o) + r(h, l); + else if (o instanceof Vr) { + if (t.has(o.compartment)) + throw new RangeError("Duplicate use of compartment in extensions"); + let h = e.get(o.compartment) || o.inner; + t.set(o.compartment, h), r(h, l); + } else if (o instanceof df) + r(o.inner, o.prec); + else if (o instanceof Me) + i[l].push(o), o.provides && r(o.provides, l); + else if (o instanceof is) + i[l].push(o), o.facet.extensions && r(o.facet.extensions, qt.default); + else { + let h = o.extension; + if (!h) + throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`); + r(h, l); + } + } + return r(n, qt.default), i.reduce((o, l) => o.concat(l)); +} +function nn(n, e) { + if (e & 1) + return 2; + let t = e >> 1, i = n.status[t]; + if (i == 4) + throw new Error("Cyclic dependency between fields and/or facets"); + if (i & 2) + return i; + n.status[t] = 4; + let s = n.computeSlot(n, n.config.dynamicSlots[t]); + return n.status[t] = 2 | s; +} +function ps(n, e) { + return e & 1 ? n.config.staticValues[e >> 1] : n.values[e >> 1]; +} +const pf = /* @__PURE__ */ D.define(), Fr = /* @__PURE__ */ D.define({ + combine: (n) => n.some((e) => e), + static: !0 +}), mf = /* @__PURE__ */ D.define({ + combine: (n) => n.length ? n[0] : void 0, + static: !0 +}), gf = /* @__PURE__ */ D.define(), bf = /* @__PURE__ */ D.define(), yf = /* @__PURE__ */ D.define(), wf = /* @__PURE__ */ D.define({ + combine: (n) => n.length ? n[0] : !1 +}); +class kt { + /** + @internal + */ + constructor(e, t) { + this.type = e, this.value = t; + } + /** + Define a new type of annotation. + */ + static define() { + return new Ad(); + } +} +class Ad { + /** + Create an instance of this annotation. + */ + of(e) { + return new kt(this, e); + } +} +class Md { + /** + @internal + */ + constructor(e) { + this.map = e; + } + /** + Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this + type. + */ + of(e) { + return new q(this, e); + } +} +class q { + /** + @internal + */ + constructor(e, t) { + this.type = e, this.value = t; + } + /** + Map this effect through a position mapping. Will return + `undefined` when that ends up deleting the effect. + */ + map(e) { + let t = this.type.map(this.value, e); + return t === void 0 ? void 0 : t == this.value ? this : new q(this.type, t); + } + /** + Tells you whether this effect object is of a given + [type](https://codemirror.net/6/docs/ref/#state.StateEffectType). + */ + is(e) { + return this.type == e; + } + /** + Define a new effect type. The type parameter indicates the type + of values that his effect holds. It should be a type that + doesn't include `undefined`, since that is used in + [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is + removed. + */ + static define(e = {}) { + return new Md(e.map || ((t) => t)); + } + /** + Map an array of effects through a change set. + */ + static mapEffects(e, t) { + if (!e.length) + return e; + let i = []; + for (let s of e) { + let r = s.map(t); + r && i.push(r); + } + return i; + } +} +q.reconfigure = /* @__PURE__ */ q.define(); +q.appendConfig = /* @__PURE__ */ q.define(); +class ae { + constructor(e, t, i, s, r, o) { + this.startState = e, this.changes = t, this.selection = i, this.effects = s, this.annotations = r, this.scrollIntoView = o, this._doc = null, this._state = null, i && uf(i, t.newLength), r.some((l) => l.type == ae.time) || (this.annotations = r.concat(ae.time.of(Date.now()))); + } + /** + @internal + */ + static create(e, t, i, s, r, o) { + return new ae(e, t, i, s, r, o); + } + /** + The new document produced by the transaction. Contrary to + [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't + force the entire new state to be computed right away, so it is + recommended that [transaction + filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter + when they need to look at the new document. + */ + get newDoc() { + return this._doc || (this._doc = this.changes.apply(this.startState.doc)); + } + /** + The new selection produced by the transaction. If + [`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined, + this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's + current selection through the changes made by the transaction. + */ + get newSelection() { + return this.selection || this.startState.selection.map(this.changes); + } + /** + The new state created by the transaction. Computed on demand + (but retained for subsequent access), so it is recommended not to + access it in [transaction + filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible. + */ + get state() { + return this._state || this.startState.applyTransaction(this), this._state; + } + /** + Get the value of the given annotation type, if any. + */ + annotation(e) { + for (let t of this.annotations) + if (t.type == e) + return t.value; + } + /** + Indicates whether the transaction changed the document. + */ + get docChanged() { + return !this.changes.empty; + } + /** + Indicates whether this transaction reconfigures the state + (through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or + with a top-level configuration + [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure). + */ + get reconfigured() { + return this.startState.config != this.state.config; + } + /** + Returns true if the transaction has a [user + event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to + or more specific than `event`. For example, if the transaction + has `"select.pointer"` as user event, `"select"` and + `"select.pointer"` will match it. + */ + isUserEvent(e) { + let t = this.annotation(ae.userEvent); + return !!(t && (t == e || t.length > e.length && t.slice(0, e.length) == e && t[e.length] == ".")); + } +} +ae.time = /* @__PURE__ */ kt.define(); +ae.userEvent = /* @__PURE__ */ kt.define(); +ae.addToHistory = /* @__PURE__ */ kt.define(); +ae.remote = /* @__PURE__ */ kt.define(); +function Td(n, e) { + let t = []; + for (let i = 0, s = 0; ; ) { + let r, o; + if (i < n.length && (s == e.length || e[s] >= n[i])) + r = n[i++], o = n[i++]; + else if (s < e.length) + r = e[s++], o = e[s++]; + else + return t; + !t.length || t[t.length - 1] < r ? t.push(r, o) : t[t.length - 1] < o && (t[t.length - 1] = o); + } +} +function kf(n, e, t) { + var i; + let s, r, o; + return t ? (s = e.changes, r = fe.empty(e.changes.length), o = n.changes.compose(e.changes)) : (s = e.changes.map(n.changes), r = n.changes.mapDesc(e.changes, !0), o = n.changes.compose(s)), { + changes: o, + selection: e.selection ? e.selection.map(r) : (i = n.selection) === null || i === void 0 ? void 0 : i.map(s), + effects: q.mapEffects(n.effects, s).concat(q.mapEffects(e.effects, r)), + annotations: n.annotations.length ? n.annotations.concat(e.annotations) : e.annotations, + scrollIntoView: n.scrollIntoView || e.scrollIntoView + }; +} +function Hr(n, e, t) { + let i = e.selection, s = xi(e.annotations); + return e.userEvent && (s = s.concat(ae.userEvent.of(e.userEvent))), { + changes: e.changes instanceof fe ? e.changes : fe.of(e.changes || [], t, n.facet(mf)), + selection: i && (i instanceof C ? i : C.single(i.anchor, i.head)), + effects: xi(e.effects), + annotations: s, + scrollIntoView: !!e.scrollIntoView + }; +} +function vf(n, e, t) { + let i = Hr(n, e.length ? e[0] : {}, n.doc.length); + e.length && e[0].filter === !1 && (t = !1); + for (let r = 1; r < e.length; r++) { + e[r].filter === !1 && (t = !1); + let o = !!e[r].sequential; + i = kf(i, Hr(n, e[r], o ? i.changes.newLength : n.doc.length), o); + } + let s = ae.create(n, i.changes, i.selection, i.effects, i.annotations, i.scrollIntoView); + return Od(t ? Dd(s) : s); +} +function Dd(n) { + let e = n.startState, t = !0; + for (let s of e.facet(gf)) { + let r = s(n); + if (r === !1) { + t = !1; + break; + } + Array.isArray(r) && (t = t === !0 ? r : Td(t, r)); + } + if (t !== !0) { + let s, r; + if (t === !1) + r = n.changes.invertedDesc, s = fe.empty(e.doc.length); + else { + let o = n.changes.filter(t); + s = o.changes, r = o.filtered.mapDesc(o.changes).invertedDesc; + } + n = ae.create(e, s, n.selection && n.selection.map(r), q.mapEffects(n.effects, r), n.annotations, n.scrollIntoView); + } + let i = e.facet(bf); + for (let s = i.length - 1; s >= 0; s--) { + let r = i[s](n); + r instanceof ae ? n = r : Array.isArray(r) && r.length == 1 && r[0] instanceof ae ? n = r[0] : n = vf(e, xi(r), !1); + } + return n; +} +function Od(n) { + let e = n.startState, t = e.facet(yf), i = n; + for (let s = t.length - 1; s >= 0; s--) { + let r = t[s](n); + r && Object.keys(r).length && (i = kf(i, Hr(e, r, n.changes.newLength), !0)); + } + return i == n ? n : ae.create(e, n.changes, n.selection, i.effects, i.annotations, i.scrollIntoView); +} +const Bd = []; +function xi(n) { + return n == null ? Bd : Array.isArray(n) ? n : [n]; +} +var Ee = /* @__PURE__ */ function(n) { + return n[n.Word = 0] = "Word", n[n.Space = 1] = "Space", n[n.Other = 2] = "Other", n; +}(Ee || (Ee = {})); +const Ld = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/; +let Wr; +try { + Wr = /* @__PURE__ */ new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u"); +} catch { +} +function Pd(n) { + if (Wr) + return Wr.test(n); + for (let e = 0; e < n.length; e++) { + let t = n[e]; + if (/\w/.test(t) || t > "€" && (t.toUpperCase() != t.toLowerCase() || Ld.test(t))) + return !0; + } + return !1; +} +function Ed(n) { + return (e) => { + if (!/\S/.test(e)) + return Ee.Space; + if (Pd(e)) + return Ee.Word; + for (let t = 0; t < n.length; t++) + if (e.indexOf(n[t]) > -1) + return Ee.Word; + return Ee.Other; + }; +} +class U { + constructor(e, t, i, s, r, o) { + this.config = e, this.doc = t, this.selection = i, this.values = s, this.status = e.statusTemplate.slice(), this.computeSlot = r, o && (o._state = this); + for (let l = 0; l < this.config.dynamicSlots.length; l++) + nn(this, l << 1); + this.computeSlot = null; + } + field(e, t = !0) { + let i = this.config.address[e.id]; + if (i == null) { + if (t) + throw new RangeError("Field is not present in this state"); + return; + } + return nn(this, i), ps(this, i); + } + /** + Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this + state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec) + can be passed. Unless + [`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the + [changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec + are assumed to start in the _current_ document (not the document + produced by previous specs), and its + [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and + [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer + to the document created by its _own_ changes. The resulting + transaction contains the combined effect of all the different + specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later + specs take precedence over earlier ones. + */ + update(...e) { + return vf(this, e, !0); + } + /** + @internal + */ + applyTransaction(e) { + let t = this.config, { base: i, compartments: s } = t; + for (let l of e.effects) + l.is(Ps.reconfigure) ? (t && (s = /* @__PURE__ */ new Map(), t.compartments.forEach((a, h) => s.set(h, a)), t = null), s.set(l.value.compartment, l.value.extension)) : l.is(q.reconfigure) ? (t = null, i = l.value) : l.is(q.appendConfig) && (t = null, i = xi(i).concat(l.value)); + let r; + t ? r = e.startState.values.slice() : (t = ds.resolve(i, s, this), r = new U(t, this.doc, this.selection, t.dynamicSlots.map(() => null), (a, h) => h.reconfigure(a, this), null).values); + let o = e.startState.facet(Fr) ? e.newSelection : e.newSelection.asSingle(); + new U(t, e.newDoc, o, r, (l, a) => a.update(l, e), e); + } + /** + Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that + replaces every selection range with the given content. + */ + replaceSelection(e) { + return typeof e == "string" && (e = this.toText(e)), this.changeByRange((t) => ({ + changes: { from: t.from, to: t.to, insert: e }, + range: C.cursor(t.from + e.length) + })); + } + /** + Create a set of changes and a new selection by running the given + function for each range in the active selection. The function + can return an optional set of changes (in the coordinate space + of the start document), plus an updated range (in the coordinate + space of the document produced by the call's own changes). This + method will merge all the changes and ranges into a single + changeset and selection, and return it as a [transaction + spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to + [`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update). + */ + changeByRange(e) { + let t = this.selection, i = e(t.ranges[0]), s = this.changes(i.changes), r = [i.range], o = xi(i.effects); + for (let l = 1; l < t.ranges.length; l++) { + let a = e(t.ranges[l]), h = this.changes(a.changes), f = h.map(s); + for (let u = 0; u < l; u++) + r[u] = r[u].map(f); + let c = s.mapDesc(h, !0); + r.push(a.range.map(c)), s = s.compose(f), o = q.mapEffects(o, f).concat(q.mapEffects(xi(a.effects), c)); + } + return { + changes: s, + selection: C.create(r, t.mainIndex), + effects: o + }; + } + /** + Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change + description, taking the state's document length and line + separator into account. + */ + changes(e = []) { + return e instanceof fe ? e : fe.of(e, this.doc.length, this.facet(U.lineSeparator)); + } + /** + Using the state's [line + separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a + [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string. + */ + toText(e) { + return Y.of(e.split(this.facet(U.lineSeparator) || Er)); + } + /** + Return the given range of the document as a string. + */ + sliceDoc(e = 0, t = this.doc.length) { + return this.doc.sliceString(e, t, this.lineBreak); + } + /** + Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet). + */ + facet(e) { + let t = this.config.address[e.id]; + return t == null ? e.default : (nn(this, t), ps(this, t)); + } + /** + Convert this state to a JSON-serializable object. When custom + fields should be serialized, you can pass them in as an object + mapping property names (in the resulting object, which should + not use `doc` or `selection`) to fields. + */ + toJSON(e) { + let t = { + doc: this.sliceDoc(), + selection: this.selection.toJSON() + }; + if (e) + for (let i in e) { + let s = e[i]; + s instanceof Me && this.config.address[s.id] != null && (t[i] = s.spec.toJSON(this.field(e[i]), this)); + } + return t; + } + /** + Deserialize a state from its JSON representation. When custom + fields should be deserialized, pass the same object you passed + to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as + third argument. + */ + static fromJSON(e, t = {}, i) { + if (!e || typeof e.doc != "string") + throw new RangeError("Invalid JSON representation for EditorState"); + let s = []; + if (i) { + for (let r in i) + if (Object.prototype.hasOwnProperty.call(e, r)) { + let o = i[r], l = e[r]; + s.push(o.init((a) => o.spec.fromJSON(l, a))); + } + } + return U.create({ + doc: e.doc, + selection: C.fromJSON(e.selection), + extensions: t.extensions ? s.concat([t.extensions]) : s + }); + } + /** + Create a new state. You'll usually only need this when + initializing an editor—updated states are created by applying + transactions. + */ + static create(e = {}) { + let t = ds.resolve(e.extensions || [], /* @__PURE__ */ new Map()), i = e.doc instanceof Y ? e.doc : Y.of((e.doc || "").split(t.staticFacet(U.lineSeparator) || Er)), s = e.selection ? e.selection instanceof C ? e.selection : C.single(e.selection.anchor, e.selection.head) : C.single(0); + return uf(s, i.length), t.staticFacet(Fr) || (s = s.asSingle()), new U(t, i, s, t.dynamicSlots.map(() => null), (r, o) => o.create(r), null); + } + /** + The size (in columns) of a tab in the document, determined by + the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. + */ + get tabSize() { + return this.facet(U.tabSize); + } + /** + Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator) + string for this state. + */ + get lineBreak() { + return this.facet(U.lineSeparator) || ` +`; + } + /** + Returns true when the editor is + [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. + */ + get readOnly() { + return this.facet(wf); + } + /** + Look up a translation for the given phrase (via the + [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the + original string if no translation is found. + + If additional arguments are passed, they will be inserted in + place of markers like `$1` (for the first value) and `$2`, etc. + A single `$` is equivalent to `$1`, and `$$` will produce a + literal dollar sign. + */ + phrase(e, ...t) { + for (let i of this.facet(U.phrases)) + if (Object.prototype.hasOwnProperty.call(i, e)) { + e = i[e]; + break; + } + return t.length && (e = e.replace(/\$(\$|\d*)/g, (i, s) => { + if (s == "$") + return "$"; + let r = +(s || 1); + return !r || r > t.length ? i : t[r - 1]; + })), e; + } + /** + Find the values for a given language data field, provided by the + the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet. + + Examples of language data fields are... + + - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying + comment syntax. + - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override) + for providing language-specific completion sources. + - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding + characters that should be considered part of words in this + language. + - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls + bracket closing behavior. + */ + languageDataAt(e, t, i = -1) { + let s = []; + for (let r of this.facet(pf)) + for (let o of r(this, t, i)) + Object.prototype.hasOwnProperty.call(o, e) && s.push(o[e]); + return s; + } + /** + Return a function that can categorize strings (expected to + represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak)) + into one of: + + - Word (contains an alphanumeric character or a character + explicitly listed in the local language's `"wordChars"` + language data, which should be a string) + - Space (contains only whitespace) + - Other (anything else) + */ + charCategorizer(e) { + return Ed(this.languageDataAt("wordChars", e).join("")); + } + /** + Find the word at the given position, meaning the range + containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters + around it. If no word characters are adjacent to the position, + this returns null. + */ + wordAt(e) { + let { text: t, from: i, length: s } = this.doc.lineAt(e), r = this.charCategorizer(e), o = e - i, l = e - i; + for (; o > 0; ) { + let a = ve(t, o, !1); + if (r(t.slice(a, o)) != Ee.Word) + break; + o = a; + } + for (; l < s; ) { + let a = ve(t, l); + if (r(t.slice(l, a)) != Ee.Word) + break; + l = a; + } + return o == l ? null : C.range(o + i, l + i); + } +} +U.allowMultipleSelections = Fr; +U.tabSize = /* @__PURE__ */ D.define({ + combine: (n) => n.length ? n[0] : 4 +}); +U.lineSeparator = mf; +U.readOnly = wf; +U.phrases = /* @__PURE__ */ D.define({ + compare(n, e) { + let t = Object.keys(n), i = Object.keys(e); + return t.length == i.length && t.every((s) => n[s] == e[s]); + } +}); +U.languageData = pf; +U.changeFilter = gf; +U.transactionFilter = bf; +U.transactionExtender = yf; +Ps.reconfigure = /* @__PURE__ */ q.define(); +function hi(n, e, t = {}) { + let i = {}; + for (let s of n) + for (let r of Object.keys(s)) { + let o = s[r], l = i[r]; + if (l === void 0) + i[r] = o; + else if (!(l === o || o === void 0)) + if (Object.hasOwnProperty.call(t, r)) + i[r] = t[r](l, o); + else + throw new Error("Config merge conflict for field " + r); + } + for (let s in e) + i[s] === void 0 && (i[s] = e[s]); + return i; +} +class Xt { + /** + Compare this value with another value. Used when comparing + rangesets. The default implementation compares by identity. + Unless you are only creating a fixed number of unique instances + of your value type, it is a good idea to implement this + properly. + */ + eq(e) { + return this == e; + } + /** + Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value. + */ + range(e, t = e) { + return zr.create(e, t, this); + } +} +Xt.prototype.startSide = Xt.prototype.endSide = 0; +Xt.prototype.point = !1; +Xt.prototype.mapMode = pe.TrackDel; +let zr = class xf { + constructor(e, t, i) { + this.from = e, this.to = t, this.value = i; + } + /** + @internal + */ + static create(e, t, i) { + return new xf(e, t, i); + } +}; +function qr(n, e) { + return n.from - e.from || n.value.startSide - e.value.startSide; +} +class Io { + constructor(e, t, i, s) { + this.from = e, this.to = t, this.value = i, this.maxPoint = s; + } + get length() { + return this.to[this.to.length - 1]; + } + // Find the index of the given position and side. Use the ranges' + // `from` pos when `end == false`, `to` when `end == true`. + findIndex(e, t, i, s = 0) { + let r = i ? this.to : this.from; + for (let o = s, l = r.length; ; ) { + if (o == l) + return o; + let a = o + l >> 1, h = r[a] - e || (i ? this.value[a].endSide : this.value[a].startSide) - t; + if (a == o) + return h >= 0 ? o : l; + h >= 0 ? l = a : o = a + 1; + } + } + between(e, t, i, s) { + for (let r = this.findIndex(t, -1e9, !0), o = this.findIndex(i, 1e9, !1, r); r < o; r++) + if (s(this.from[r] + e, this.to[r] + e, this.value[r]) === !1) + return !1; + } + map(e, t) { + let i = [], s = [], r = [], o = -1, l = -1; + for (let a = 0; a < this.value.length; a++) { + let h = this.value[a], f = this.from[a] + e, c = this.to[a] + e, u, d; + if (f == c) { + let p = t.mapPos(f, h.startSide, h.mapMode); + if (p == null || (u = d = p, h.startSide != h.endSide && (d = t.mapPos(f, h.endSide), d < u))) + continue; + } else if (u = t.mapPos(f, h.startSide), d = t.mapPos(c, h.endSide), u > d || u == d && h.startSide > 0 && h.endSide <= 0) + continue; + (d - u || h.endSide - h.startSide) < 0 || (o < 0 && (o = u), h.point && (l = Math.max(l, d - u)), i.push(h), s.push(u - o), r.push(d - o)); + } + return { mapped: i.length ? new Io(s, r, i, l) : null, pos: o }; + } +} +class G { + constructor(e, t, i, s) { + this.chunkPos = e, this.chunk = t, this.nextLayer = i, this.maxPoint = s; + } + /** + @internal + */ + static create(e, t, i, s) { + return new G(e, t, i, s); + } + /** + @internal + */ + get length() { + let e = this.chunk.length - 1; + return e < 0 ? 0 : Math.max(this.chunkEnd(e), this.nextLayer.length); + } + /** + The number of ranges in the set. + */ + get size() { + if (this.isEmpty) + return 0; + let e = this.nextLayer.size; + for (let t of this.chunk) + e += t.value.length; + return e; + } + /** + @internal + */ + chunkEnd(e) { + return this.chunkPos[e] + this.chunk[e].length; + } + /** + Update the range set, optionally adding new ranges or filtering + out existing ones. + + (Note: The type parameter is just there as a kludge to work + around TypeScript variance issues that prevented `RangeSet` + from being a subtype of `RangeSet` when `X` is a subtype of + `Y`.) + */ + update(e) { + let { add: t = [], sort: i = !1, filterFrom: s = 0, filterTo: r = this.length } = e, o = e.filter; + if (t.length == 0 && !o) + return this; + if (i && (t = t.slice().sort(qr)), this.isEmpty) + return t.length ? G.of(t) : this; + let l = new Sf(this, null, -1).goto(0), a = 0, h = [], f = new Zt(); + for (; l.value || a < t.length; ) + if (a < t.length && (l.from - t[a].from || l.startSide - t[a].value.startSide) >= 0) { + let c = t[a++]; + f.addInner(c.from, c.to, c.value) || h.push(c); + } else + l.rangeIndex == 1 && l.chunkIndex < this.chunk.length && (a == t.length || this.chunkEnd(l.chunkIndex) < t[a].from) && (!o || s > this.chunkEnd(l.chunkIndex) || r < this.chunkPos[l.chunkIndex]) && f.addChunk(this.chunkPos[l.chunkIndex], this.chunk[l.chunkIndex]) ? l.nextChunk() : ((!o || s > l.to || r < l.from || o(l.from, l.to, l.value)) && (f.addInner(l.from, l.to, l.value) || h.push(zr.create(l.from, l.to, l.value))), l.next()); + return f.finishInner(this.nextLayer.isEmpty && !h.length ? G.empty : this.nextLayer.update({ add: h, filter: o, filterFrom: s, filterTo: r })); + } + /** + Map this range set through a set of changes, return the new set. + */ + map(e) { + if (e.empty || this.isEmpty) + return this; + let t = [], i = [], s = -1; + for (let o = 0; o < this.chunk.length; o++) { + let l = this.chunkPos[o], a = this.chunk[o], h = e.touchesRange(l, l + a.length); + if (h === !1) + s = Math.max(s, a.maxPoint), t.push(a), i.push(e.mapPos(l)); + else if (h === !0) { + let { mapped: f, pos: c } = a.map(l, e); + f && (s = Math.max(s, f.maxPoint), t.push(f), i.push(c)); + } + } + let r = this.nextLayer.map(e); + return t.length == 0 ? r : new G(i, t, r || G.empty, s); + } + /** + Iterate over the ranges that touch the region `from` to `to`, + calling `f` for each. There is no guarantee that the ranges will + be reported in any specific order. When the callback returns + `false`, iteration stops. + */ + between(e, t, i) { + if (!this.isEmpty) { + for (let s = 0; s < this.chunk.length; s++) { + let r = this.chunkPos[s], o = this.chunk[s]; + if (t >= r && e <= r + o.length && o.between(r, e - r, t - r, i) === !1) + return; + } + this.nextLayer.between(e, t, i); + } + } + /** + Iterate over the ranges in this set, in order, including all + ranges that end at or after `from`. + */ + iter(e = 0) { + return cn.from([this]).goto(e); + } + /** + @internal + */ + get isEmpty() { + return this.nextLayer == this; + } + /** + Iterate over the ranges in a collection of sets, in order, + starting from `from`. + */ + static iter(e, t = 0) { + return cn.from(e).goto(t); + } + /** + Iterate over two groups of sets, calling methods on `comparator` + to notify it of possible differences. + */ + static compare(e, t, i, s, r = -1) { + let o = e.filter((c) => c.maxPoint > 0 || !c.isEmpty && c.maxPoint >= r), l = t.filter((c) => c.maxPoint > 0 || !c.isEmpty && c.maxPoint >= r), a = Cl(o, l, i), h = new zi(o, a, r), f = new zi(l, a, r); + i.iterGaps((c, u, d) => Al(h, c, f, u, d, s)), i.empty && i.length == 0 && Al(h, 0, f, 0, 0, s); + } + /** + Compare the contents of two groups of range sets, returning true + if they are equivalent in the given range. + */ + static eq(e, t, i = 0, s) { + s == null && (s = 999999999); + let r = e.filter((f) => !f.isEmpty && t.indexOf(f) < 0), o = t.filter((f) => !f.isEmpty && e.indexOf(f) < 0); + if (r.length != o.length) + return !1; + if (!r.length) + return !0; + let l = Cl(r, o), a = new zi(r, l, 0).goto(i), h = new zi(o, l, 0).goto(i); + for (; ; ) { + if (a.to != h.to || !jr(a.active, h.active) || a.point && (!h.point || !a.point.eq(h.point))) + return !1; + if (a.to > s) + return !0; + a.next(), h.next(); + } + } + /** + Iterate over a group of range sets at the same time, notifying + the iterator about the ranges covering every given piece of + content. Returns the open count (see + [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end + of the iteration. + */ + static spans(e, t, i, s, r = -1) { + let o = new zi(e, null, r).goto(t), l = t, a = o.openStart; + for (; ; ) { + let h = Math.min(o.to, i); + if (o.point) { + let f = o.activeForPoint(o.to), c = o.pointFrom < t ? f.length + 1 : o.point.startSide < 0 ? f.length : Math.min(f.length, a); + s.point(l, h, o.point, f, c, o.pointRank), a = Math.min(o.openEnd(h), f.length); + } else + h > l && (s.span(l, h, o.active, a), a = o.openEnd(h)); + if (o.to > i) + return a + (o.point && o.to > i ? 1 : 0); + l = o.to, o.next(); + } + } + /** + Create a range set for the given range or array of ranges. By + default, this expects the ranges to be _sorted_ (by start + position and, if two start at the same position, + `value.startSide`). You can pass `true` as second argument to + cause the method to sort them. + */ + static of(e, t = !1) { + let i = new Zt(); + for (let s of e instanceof zr ? [e] : t ? Rd(e) : e) + i.add(s.from, s.to, s.value); + return i.finish(); + } + /** + Join an array of range sets into a single set. + */ + static join(e) { + if (!e.length) + return G.empty; + let t = e[e.length - 1]; + for (let i = e.length - 2; i >= 0; i--) + for (let s = e[i]; s != G.empty; s = s.nextLayer) + t = new G(s.chunkPos, s.chunk, t, Math.max(s.maxPoint, t.maxPoint)); + return t; + } +} +G.empty = /* @__PURE__ */ new G([], [], null, -1); +function Rd(n) { + if (n.length > 1) + for (let e = n[0], t = 1; t < n.length; t++) { + let i = n[t]; + if (qr(e, i) > 0) + return n.slice().sort(qr); + e = i; + } + return n; +} +G.empty.nextLayer = G.empty; +class Zt { + finishChunk(e) { + this.chunks.push(new Io(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 = []); + } + /** + Create an empty builder. + */ + constructor() { + 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; + } + /** + Add a range. Ranges should be added in sorted (by `from` and + `value.startSide`) order. + */ + add(e, t, i) { + this.addInner(e, t, i) || (this.nextLayer || (this.nextLayer = new Zt())).add(e, t, i); + } + /** + @internal + */ + addInner(e, t, i) { + let s = e - this.lastTo || i.startSide - this.last.endSide; + if (s <= 0 && (e - this.lastFrom || i.startSide - this.last.startSide) < 0) + throw new Error("Ranges must be added sorted by `from` position and `startSide`"); + return s < 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 = i, this.lastFrom = e, this.lastTo = t, this.value.push(i), i.point && (this.maxPoint = Math.max(this.maxPoint, t - e)), !0); + } + /** + @internal + */ + addChunk(e, t) { + if ((e - this.lastTo || t.value[0].startSide - this.last.endSide) < 0) + return !1; + this.from.length && this.finishChunk(!0), this.setMaxPoint = Math.max(this.setMaxPoint, t.maxPoint), this.chunks.push(t), this.chunkPos.push(e); + let i = t.value.length - 1; + return this.last = t.value[i], this.lastFrom = t.from[i] + e, this.lastTo = t.to[i] + e, !0; + } + /** + Finish the range set. Returns the new set. The builder can't be + used anymore after this has been called. + */ + finish() { + return this.finishInner(G.empty); + } + /** + @internal + */ + finishInner(e) { + if (this.from.length && this.finishChunk(!1), this.chunks.length == 0) + return e; + let t = G.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(e) : e, this.setMaxPoint); + return this.from = null, t; + } +} +function Cl(n, e, t) { + let i = /* @__PURE__ */ new Map(); + for (let r of n) + for (let o = 0; o < r.chunk.length; o++) + r.chunk[o].maxPoint <= 0 && i.set(r.chunk[o], r.chunkPos[o]); + let s = /* @__PURE__ */ new Set(); + for (let r of e) + for (let o = 0; o < r.chunk.length; o++) { + let l = i.get(r.chunk[o]); + l != null && (t ? t.mapPos(l) : l) == r.chunkPos[o] && !(t != null && t.touchesRange(l, l + r.chunk[o].length)) && s.add(r.chunk[o]); + } + return s; +} +class Sf { + constructor(e, t, i, s = 0) { + this.layer = e, this.skip = t, this.minPoint = i, this.rank = s; + } + get startSide() { + return this.value ? this.value.startSide : 0; + } + get endSide() { + return this.value ? this.value.endSide : 0; + } + goto(e, t = -1e9) { + return this.chunkIndex = this.rangeIndex = 0, this.gotoInner(e, t, !1), this; + } + gotoInner(e, t, i) { + for (; this.chunkIndex < this.layer.chunk.length; ) { + let s = this.layer.chunk[this.chunkIndex]; + if (!(this.skip && this.skip.has(s) || this.layer.chunkEnd(this.chunkIndex) < e || s.maxPoint < this.minPoint)) + break; + this.chunkIndex++, i = !1; + } + if (this.chunkIndex < this.layer.chunk.length) { + let s = this.layer.chunk[this.chunkIndex].findIndex(e - this.layer.chunkPos[this.chunkIndex], t, !0); + (!i || this.rangeIndex < s) && this.setRangeIndex(s); + } + this.next(); + } + forward(e, t) { + (this.to - e || this.endSide - t) < 0 && this.gotoInner(e, t, !0); + } + next() { + for (; ; ) + if (this.chunkIndex == this.layer.chunk.length) { + this.from = this.to = 1e9, this.value = null; + break; + } else { + let e = this.layer.chunkPos[this.chunkIndex], t = this.layer.chunk[this.chunkIndex], i = e + t.from[this.rangeIndex]; + if (this.from = i, 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) + break; + } + } + setRangeIndex(e) { + if (e == this.layer.chunk[this.chunkIndex].value.length) { + if (this.chunkIndex++, this.skip) + for (; this.chunkIndex < this.layer.chunk.length && this.skip.has(this.layer.chunk[this.chunkIndex]); ) + this.chunkIndex++; + this.rangeIndex = 0; + } else + this.rangeIndex = e; + } + nextChunk() { + this.chunkIndex++, this.rangeIndex = 0, this.next(); + } + compare(e) { + return this.from - e.from || this.startSide - e.startSide || this.rank - e.rank || this.to - e.to || this.endSide - e.endSide; + } +} +class cn { + constructor(e) { + this.heap = e; + } + static from(e, t = null, i = -1) { + let s = []; + for (let r = 0; r < e.length; r++) + for (let o = e[r]; !o.isEmpty; o = o.nextLayer) + o.maxPoint >= i && s.push(new Sf(o, t, i, r)); + return s.length == 1 ? s[0] : new cn(s); + } + get startSide() { + return this.value ? this.value.startSide : 0; + } + goto(e, t = -1e9) { + for (let i of this.heap) + i.goto(e, t); + for (let i = this.heap.length >> 1; i >= 0; i--) + Xs(this.heap, i); + return this.next(), this; + } + forward(e, t) { + for (let i of this.heap) + i.forward(e, t); + for (let i = this.heap.length >> 1; i >= 0; i--) + Xs(this.heap, i); + (this.to - e || this.value.endSide - t) < 0 && this.next(); + } + next() { + if (this.heap.length == 0) + this.from = this.to = 1e9, this.value = null, this.rank = -1; + else { + let e = this.heap[0]; + this.from = e.from, this.to = e.to, this.value = e.value, this.rank = e.rank, e.value && e.next(), Xs(this.heap, 0); + } + } +} +function Xs(n, e) { + for (let t = n[e]; ; ) { + let i = (e << 1) + 1; + if (i >= n.length) + break; + let s = n[i]; + if (i + 1 < n.length && s.compare(n[i + 1]) >= 0 && (s = n[i + 1], i++), t.compare(s) < 0) + break; + n[i] = t, n[e] = s, e = i; + } +} +class zi { + constructor(e, t, i) { + this.minPoint = i, 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 = cn.from(e, t, i); + } + goto(e, t = -1e9) { + 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; + } + forward(e, t) { + for (; this.minActive > -1 && (this.activeTo[this.minActive] - e || this.active[this.minActive].endSide - t) < 0; ) + this.removeActive(this.minActive); + this.cursor.forward(e, t); + } + removeActive(e) { + Dn(this.active, e), Dn(this.activeTo, e), Dn(this.activeRank, e), this.minActive = Ml(this.active, this.activeTo); + } + addActive(e) { + let t = 0, { value: i, to: s, rank: r } = this.cursor; + for (; t < this.activeRank.length && (r - this.activeRank[t] || s - this.activeTo[t]) > 0; ) + t++; + On(this.active, t, i), On(this.activeTo, t, s), On(this.activeRank, t, r), e && On(e, t, this.cursor.from), this.minActive = Ml(this.active, this.activeTo); + } + // After calling this, if `this.point` != null, the next range is a + // point. Otherwise, it's a regular range, covered by `this.active`. + next() { + let e = this.to, t = this.point; + this.point = null; + let i = this.openStart < 0 ? [] : null; + for (; ; ) { + let s = this.minActive; + if (s > -1 && (this.activeTo[s] - this.cursor.from || this.active[s].endSide - this.cursor.startSide) < 0) { + if (this.activeTo[s] > e) { + this.to = this.activeTo[s], this.endSide = this.active[s].endSide; + break; + } + this.removeActive(s), i && Dn(i, s); + } else if (this.cursor.value) + if (this.cursor.from > e) { + this.to = this.cursor.from, this.endSide = this.cursor.startSide; + break; + } else { + let r = this.cursor.value; + if (!r.point) + this.addActive(i), this.cursor.next(); + else if (t && this.cursor.to == this.to && this.cursor.from < this.cursor.to) + this.cursor.next(); + else { + this.point = r, this.pointFrom = this.cursor.from, this.pointRank = this.cursor.rank, this.to = this.cursor.to, this.endSide = r.endSide, this.cursor.next(), this.forward(this.to, this.endSide); + break; + } + } + else { + this.to = this.endSide = 1e9; + break; + } + } + if (i) { + this.openStart = 0; + for (let s = i.length - 1; s >= 0 && i[s] < e; s--) + this.openStart++; + } + } + activeForPoint(e) { + if (!this.active.length) + return this.active; + let t = []; + for (let i = this.active.length - 1; i >= 0 && !(this.activeRank[i] < this.pointRank); i--) + (this.activeTo[i] > e || this.activeTo[i] == e && this.active[i].endSide >= this.point.endSide) && t.push(this.active[i]); + return t.reverse(); + } + openEnd(e) { + let t = 0; + for (let i = this.activeTo.length - 1; i >= 0 && this.activeTo[i] > e; i--) + t++; + return t; + } +} +function Al(n, e, t, i, s, r) { + n.goto(e), t.goto(i); + let o = i + s, l = i, a = i - e; + for (; ; ) { + let h = n.to + a - t.to || n.endSide - t.endSide, f = h < 0 ? n.to + a : t.to, c = Math.min(f, o); + if (n.point || t.point ? n.point && t.point && (n.point == t.point || n.point.eq(t.point)) && jr(n.activeForPoint(n.to), t.activeForPoint(t.to)) || r.comparePoint(l, c, n.point, t.point) : c > l && !jr(n.active, t.active) && r.compareRange(l, c, n.active, t.active), f > o) + break; + l = f, h <= 0 && n.next(), h >= 0 && t.next(); + } +} +function jr(n, e) { + if (n.length != e.length) + return !1; + for (let t = 0; t < n.length; t++) + if (n[t] != e[t] && !n[t].eq(e[t])) + return !1; + return !0; +} +function Dn(n, e) { + for (let t = e, i = n.length - 1; t < i; t++) + n[t] = n[t + 1]; + n.pop(); +} +function On(n, e, t) { + for (let i = n.length - 1; i >= e; i--) + n[i + 1] = n[i]; + n[e] = t; +} +function Ml(n, e) { + let t = -1, i = 1e9; + for (let s = 0; s < e.length; s++) + (e[s] - i || n[s].endSide - n[t].endSide) < 0 && (t = s, i = e[s]); + return t; +} +function Ri(n, e, t = n.length) { + let i = 0; + for (let s = 0; s < t; ) + n.charCodeAt(s) == 9 ? (i += e - i % e, s++) : (i++, s = ve(n, s)); + return i; +} +function Kr(n, e, t, i) { + for (let s = 0, r = 0; ; ) { + if (r >= e) + return s; + if (s == n.length) + break; + r += n.charCodeAt(s) == 9 ? t - r % t : 1, s = ve(n, s); + } + return i === !0 ? -1 : n.length; +} +const Ur = "ͼ", Tl = typeof Symbol > "u" ? "__" + Ur : Symbol.for(Ur), Gr = typeof Symbol > "u" ? "__styleSet" + Math.floor(Math.random() * 1e8) : Symbol("styleSet"), Dl = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : {}; +class Pt { + // :: (Object