diff --git "a/src/backend/gradio_highlightedcode/templates/component/Index-COMtKkwP.js" "b/src/backend/gradio_highlightedcode/templates/component/Index-COMtKkwP.js" new file mode 100644--- /dev/null +++ "b/src/backend/gradio_highlightedcode/templates/component/Index-COMtKkwP.js" @@ -0,0 +1,34633 @@ +class Ae { + /** + 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, r) { + [e, t] = Ui(this, e, t); + let i = []; + return this.decompose( + 0, + e, + i, + 2 + /* Open.To */ + ), r.length && r.decompose( + 0, + r.length, + i, + 3 + /* Open.To */ + ), this.decompose( + t, + this.length, + i, + 1 + /* Open.From */ + ), ho.from(i, this.length - (t - e) + r.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] = Ui(this, e, t); + let r = []; + return this.decompose(e, t, r, 0), ho.from(r, 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), r = this.length - this.scanIdentical(e, -1), i = new Rs(this), s = new Rs(e); + for (let l = t, o = t; ; ) { + if (i.next(l), s.next(l), l = 0, i.lineBreak != s.lineBreak || i.done != s.done || i.value != s.value) + return !1; + if (o += i.value.length, i.done || o >= r) + 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 Rs(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 Wm(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 r; + if (e == null) + r = this.iter(); + else { + t == null && (t = this.lines + 1); + let i = this.line(e).from; + r = this.iterRange(i, Math.max(i, t == this.lines + 1 ? this.length : t <= 1 ? 0 : this.line(t - 1).to)); + } + return new Um(r); + } + /** + 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] ? Ae.empty : e.length <= 32 ? new Ke(e) : ho.from(Ke.split(e, [])); + } +} +class Ke extends Ae { + constructor(e, t = C5(e)) { + super(), this.text = e, this.length = t; + } + get lines() { + return this.text.length; + } + get children() { + return null; + } + lineInner(e, t, r, i) { + for (let s = 0; ; s++) { + let l = this.text[s], o = i + l.length; + if ((t ? r : o) >= e) + return new _5(i, o, r, l); + i = o + 1, r++; + } + } + decompose(e, t, r, i) { + let s = e <= 0 && t >= this.length ? this : new Ke(Ic(this.text, e, t), Math.min(t, this.length) - Math.max(0, e)); + if (i & 1) { + let l = r.pop(), o = co(s.text, l.text.slice(), 0, s.length); + if (o.length <= 32) + r.push(new Ke(o, l.length + s.length)); + else { + let a = o.length >> 1; + r.push(new Ke(o.slice(0, a)), new Ke(o.slice(a))); + } + } else + r.push(s); + } + replace(e, t, r) { + if (!(r instanceof Ke)) + return super.replace(e, t, r); + [e, t] = Ui(this, e, t); + let i = co(this.text, co(r.text, Ic(this.text, 0, e)), t), s = this.length + r.length - (t - e); + return i.length <= 32 ? new Ke(i, s) : ho.from(Ke.split(i, []), s); + } + sliceString(e, t = this.length, r = ` +`) { + [e, t] = Ui(this, e, t); + let i = ""; + for (let s = 0, l = 0; s <= t && l < this.text.length; l++) { + let o = this.text[l], a = s + o.length; + s > e && l && (i += r), e < a && t > s && (i += o.slice(Math.max(0, e - s), t - s)), s = a + 1; + } + return i; + } + flatten(e) { + for (let t of this.text) + e.push(t); + } + scanIdentical() { + return 0; + } + static split(e, t) { + let r = [], i = -1; + for (let s of e) + r.push(s), i += s.length + 1, r.length == 32 && (t.push(new Ke(r, i)), r = [], i = -1); + return i > -1 && t.push(new Ke(r, i)), t; + } +} +let ho = class Ei extends Ae { + constructor(e, t) { + super(), this.children = e, this.length = t, this.lines = 0; + for (let r of e) + this.lines += r.lines; + } + lineInner(e, t, r, i) { + for (let s = 0; ; s++) { + let l = this.children[s], o = i + l.length, a = r + l.lines - 1; + if ((t ? a : o) >= e) + return l.lineInner(e, t, r, i); + i = o + 1, r = a + 1; + } + } + decompose(e, t, r, i) { + for (let s = 0, l = 0; l <= t && s < this.children.length; s++) { + let o = this.children[s], a = l + o.length; + if (e <= a && t >= l) { + let u = i & ((l <= e ? 1 : 0) | (a >= t ? 2 : 0)); + l >= e && a <= t && !u ? r.push(o) : o.decompose(e - l, t - l, r, u); + } + l = a + 1; + } + } + replace(e, t, r) { + if ([e, t] = Ui(this, e, t), r.lines < this.lines) + for (let i = 0, s = 0; i < this.children.length; i++) { + let l = this.children[i], o = s + l.length; + if (e >= s && t <= o) { + let a = l.replace(e - s, t - s, r), u = this.lines - l.lines + a.lines; + if (a.lines < u >> 4 && a.lines > u >> 6) { + let h = this.children.slice(); + return h[i] = a, new Ei(h, this.length - (t - e) + r.length); + } + return super.replace(s, o, a); + } + s = o + 1; + } + return super.replace(e, t, r); + } + sliceString(e, t = this.length, r = ` +`) { + [e, t] = Ui(this, e, t); + let i = ""; + for (let s = 0, l = 0; s < this.children.length && l <= t; s++) { + let o = this.children[s], a = l + o.length; + l > e && s && (i += r), e < a && t > l && (i += o.sliceString(e - l, t - l, r)), l = a + 1; + } + return i; + } + flatten(e) { + for (let t of this.children) + t.flatten(e); + } + scanIdentical(e, t) { + if (!(e instanceof Ei)) + return 0; + let r = 0, [i, s, l, o] = t > 0 ? [0, 0, this.children.length, e.children.length] : [this.children.length - 1, e.children.length - 1, -1, -1]; + for (; ; i += t, s += t) { + if (i == l || s == o) + return r; + let a = this.children[i], u = e.children[s]; + if (a != u) + return r + a.scanIdentical(u, t); + r += a.length + 1; + } + } + static from(e, t = e.reduce((r, i) => r + i.length + 1, -1)) { + let r = 0; + for (let m of e) + r += m.lines; + if (r < 32) { + let m = []; + for (let g of e) + g.flatten(m); + return new Ke(m, t); + } + let i = Math.max( + 32, + r >> 5 + /* Tree.BranchShift */ + ), s = i << 1, l = i >> 1, o = [], a = 0, u = -1, h = []; + function c(m) { + let g; + if (m.lines > s && m instanceof Ei) + for (let v of m.children) + c(v); + else m.lines > l && (a > l || !a) ? (f(), o.push(m)) : m instanceof Ke && a && (g = h[h.length - 1]) instanceof Ke && m.lines + g.lines <= 32 ? (a += m.lines, u += m.length + 1, h[h.length - 1] = new Ke(g.text.concat(m.text), g.length + 1 + m.length)) : (a + m.lines > i && f(), a += m.lines, u += m.length + 1, h.push(m)); + } + function f() { + a != 0 && (o.push(h.length == 1 ? h[0] : Ei.from(h, u)), u = -1, a = h.length = 0); + } + for (let m of e) + c(m); + return f(), o.length == 1 ? o[0] : new Ei(o, t); + } +}; +Ae.empty = /* @__PURE__ */ new Ke([""], 0); +function C5(n) { + let e = -1; + for (let t of n) + e += t.length + 1; + return e; +} +function co(n, e, t = 0, r = 1e9) { + for (let i = 0, s = 0, l = !0; s < n.length && i <= r; s++) { + let o = n[s], a = i + o.length; + a >= t && (a > r && (o = o.slice(0, r - i)), i < t && (o = o.slice(t - i)), l ? (e[e.length - 1] += o, l = !1) : e.push(o)), i = a + 1; + } + return e; +} +function Ic(n, e, t) { + return co(n, [""], e, t); +} +class Rs { + 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 Ke ? e.text.length : e.children.length) << 1]; + } + nextInner(e, t) { + for (this.done = this.lineBreak = !1; ; ) { + let r = this.nodes.length - 1, i = this.nodes[r], s = this.offsets[r], l = s >> 1, o = i instanceof Ke ? i.text.length : i.children.length; + if (l == (t > 0 ? o : 0)) { + if (r == 0) + return this.done = !0, this.value = "", this; + t > 0 && this.offsets[r - 1]++, this.nodes.pop(), this.offsets.pop(); + } else if ((s & 1) == (t > 0 ? 0 : 1)) { + if (this.offsets[r] += t, e == 0) + return this.lineBreak = !0, this.value = ` +`, this; + e--; + } else if (i instanceof Ke) { + let a = i.text[l + (t < 0 ? -1 : 0)]; + if (this.offsets[r] += 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 = i.children[l + (t < 0 ? -1 : 0)]; + e > a.length ? (e -= a.length, this.offsets[r] += t) : (t < 0 && this.offsets[r]--, this.nodes.push(a), this.offsets.push(t > 0 ? 1 : (a instanceof Ke ? 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 Wm { + constructor(e, t, r) { + this.value = "", this.done = !1, this.cursor = new Rs(e, t > r ? -1 : 1), this.pos = t > r ? e.length : 0, this.from = Math.min(t, r), this.to = Math.max(t, r); + } + 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 r = t < 0 ? this.pos - this.from : this.to - this.pos; + e > r && (e = r), r -= e; + let { value: i } = this.cursor.next(e); + return this.pos += (i.length + e) * t, this.value = i.length <= r ? i : t < 0 ? i.slice(i.length - r) : i.slice(0, r), 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 Um { + constructor(e) { + this.inner = e, this.afterBreak = !0, this.value = "", this.done = !1; + } + next(e = 0) { + let { done: t, lineBreak: r, value: i } = this.inner.next(e); + return t && this.afterBreak ? (this.value = "", this.afterBreak = !1) : t ? (this.done = !0, this.value = "") : r ? this.afterBreak ? this.value = "" : (this.afterBreak = !0, this.next()) : (this.value = i, this.afterBreak = !1), this; + } + get lineBreak() { + return !1; + } +} +typeof Symbol < "u" && (Ae.prototype[Symbol.iterator] = function() { + return this.iter(); +}, Rs.prototype[Symbol.iterator] = Wm.prototype[Symbol.iterator] = Um.prototype[Symbol.iterator] = function() { + return this; +}); +class _5 { + /** + @internal + */ + constructor(e, t, r, i) { + this.from = e, this.to = t, this.number = r, this.text = i; + } + /** + The length of the line (not including any line break after it). + */ + get length() { + return this.to - this.from; + } +} +function Ui(n, e, t) { + return e = Math.max(0, Math.min(n.length, e)), [e, Math.max(e, Math.min(n.length, t))]; +} +let Ii = /* @__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 < Ii.length; n++) + Ii[n] += Ii[n - 1]; +function M5(n) { + for (let e = 1; e < Ii.length; e += 2) + if (Ii[e] > n) + return Ii[e - 1] <= n; + return !1; +} +function zc(n) { + return n >= 127462 && n <= 127487; +} +const Pc = 8205; +function kt(n, e, t = !0, r = !0) { + return (t ? Gm : T5)(n, e, r); +} +function Gm(n, e, t) { + if (e == n.length) + return e; + e && jm(n.charCodeAt(e)) && $m(n.charCodeAt(e - 1)) && e--; + let r = ft(n, e); + for (e += vr(r); e < n.length; ) { + let i = ft(n, e); + if (r == Pc || i == Pc || t && M5(i)) + e += vr(i), r = i; + else if (zc(i)) { + let s = 0, l = e - 2; + for (; l >= 0 && zc(ft(n, l)); ) + s++, l -= 2; + if (s % 2 == 0) + break; + e += 2; + } else + break; + } + return e; +} +function T5(n, e, t) { + for (; e > 0; ) { + let r = Gm(n, e - 2, t); + if (r < e) + return r; + e--; + } + return 0; +} +function jm(n) { + return n >= 56320 && n < 57344; +} +function $m(n) { + return n >= 55296 && n < 56320; +} +function ft(n, e) { + let t = n.charCodeAt(e); + if (!$m(t) || e + 1 == n.length) + return t; + let r = n.charCodeAt(e + 1); + return jm(r) ? (t - 55296 << 10) + (r - 56320) + 65536 : t; +} +function Ym(n) { + return n <= 65535 ? String.fromCharCode(n) : (n -= 65536, String.fromCharCode((n >> 10) + 55296, (n & 1023) + 56320)); +} +function vr(n) { + return n < 65536 ? 1 : 2; +} +const V0 = /\r\n?|\n/; +var at = /* @__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; +}(at || (at = {})); +class $r { + // 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 r = this.sections[t + 1]; + e += r < 0 ? this.sections[t] : r; + } + 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, r = 0, i = 0; t < this.sections.length; ) { + let s = this.sections[t++], l = this.sections[t++]; + l < 0 ? (e(r, i, s), i += s) : i += l, r += s; + } + } + /** + 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) { + W0(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 r = this.sections[t++], i = this.sections[t++]; + i < 0 ? e.push(r, i) : e.push(i, r); + } + return new $r(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 : Km(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 : U0(this, e, t); + } + mapPos(e, t = -1, r = at.Simple) { + let i = 0, s = 0; + for (let l = 0; l < this.sections.length; ) { + let o = this.sections[l++], a = this.sections[l++], u = i + o; + if (a < 0) { + if (u > e) + return s + (e - i); + s += o; + } else { + if (r != at.Simple && u >= e && (r == at.TrackDel && i < e && u > e || r == at.TrackBefore && i < e || r == at.TrackAfter && u > e)) + return null; + if (u > e || u == e && t < 0 && !o) + return e == i || t < 0 ? s : s + a; + s += a; + } + i = u; + } + if (e > i) + throw new RangeError(`Position ${e} is out of range for changeset of length ${i}`); + return s; + } + /** + 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 r = 0, i = 0; r < this.sections.length && i <= t; ) { + let s = this.sections[r++], l = this.sections[r++], o = i + s; + if (l >= 0 && i <= t && o >= e) + return i < e && o > t ? "cover" : !0; + i = o; + } + return !1; + } + /** + @internal + */ + toString() { + let e = ""; + for (let t = 0; t < this.sections.length; ) { + let r = this.sections[t++], i = this.sections[t++]; + e += (e ? " " : "") + r + (i >= 0 ? ":" + i : ""); + } + 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 $r(e); + } + /** + @internal + */ + static create(e) { + return new $r(e); + } +} +class tt extends $r { + 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 W0(this, (t, r, i, s, l) => e = e.replace(i, i + (r - t), l), !1), e; + } + mapDesc(e, t = !1) { + return U0(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(), r = []; + for (let i = 0, s = 0; i < t.length; i += 2) { + let l = t[i], o = t[i + 1]; + if (o >= 0) { + t[i] = o, t[i + 1] = l; + let a = i >> 1; + for (; r.length < a; ) + r.push(Ae.empty); + r.push(l ? e.slice(s, s + l) : Ae.empty); + } + s += l; + } + return new tt(t, r); + } + /** + 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 : Km(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 : U0(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) { + W0(this, e, t); + } + /** + Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change + set. + */ + get desc() { + return $r.create(this.sections); + } + /** + @internal + */ + filter(e) { + let t = [], r = [], i = [], s = new js(this); + e: for (let l = 0, o = 0; ; ) { + let a = l == e.length ? 1e9 : e[l++]; + for (; o < a || o == a && s.len == 0; ) { + if (s.done) + break e; + let h = Math.min(s.len, a - o); + ct(i, h, -1); + let c = s.ins == -1 ? -1 : s.off == 0 ? s.ins : 0; + ct(t, h, c), c > 0 && Tn(r, t, s.text), s.forward(h), o += h; + } + let u = e[l++]; + for (; o < u; ) { + if (s.done) + break e; + let h = Math.min(s.len, u - o); + ct(t, h, -1), ct(i, h, s.ins == -1 ? -1 : s.off == 0 ? s.ins : 0), s.forward(h), o += h; + } + } + return { + changes: new tt(t, r), + filtered: $r.create(i) + }; + } + /** + Serialize this change set to a JSON-representable value. + */ + toJSON() { + let e = []; + for (let t = 0; t < this.sections.length; t += 2) { + let r = this.sections[t], i = this.sections[t + 1]; + i < 0 ? e.push(r) : i == 0 ? e.push([r]) : e.push([r].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, r) { + let i = [], s = [], l = 0, o = null; + function a(h = !1) { + if (!h && !i.length) + return; + l < t && ct(i, t - l, -1); + let c = new tt(i, s); + o = o ? o.compose(c.map(o)) : c, i = [], s = [], l = 0; + } + function u(h) { + if (Array.isArray(h)) + for (let c of h) + u(c); + else if (h instanceof tt) { + if (h.length != t) + throw new RangeError(`Mismatched change set length (got ${h.length}, expected ${t})`); + a(), o = o ? o.compose(h.map(o)) : h; + } else { + let { from: c, to: f = c, insert: m } = h; + if (c > f || c < 0 || f > t) + throw new RangeError(`Invalid change range ${c} to ${f} (in doc of length ${t})`); + let g = m ? typeof m == "string" ? Ae.of(m.split(r || V0)) : m : Ae.empty, v = g.length; + if (c == f && v == 0) + return; + c < l && a(), c > l && ct(i, c - l, -1), ct(i, f - c, v), Tn(s, i, g), l = f; + } + } + return u(e), a(!o), o; + } + /** + Create an empty changeset of the given length. + */ + static empty(e) { + return new tt(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 = [], r = []; + for (let i = 0; i < e.length; i++) { + let s = e[i]; + if (typeof s == "number") + t.push(s, -1); + else { + if (!Array.isArray(s) || typeof s[0] != "number" || s.some((l, o) => o && typeof l != "string")) + throw new RangeError("Invalid JSON representation of ChangeSet"); + if (s.length == 1) + t.push(s[0], 0); + else { + for (; r.length < i; ) + r.push(Ae.empty); + r[i] = Ae.of(s.slice(1)), t.push(s[0], r[i].length); + } + } + } + return new tt(t, r); + } + /** + @internal + */ + static createSet(e, t) { + return new tt(e, t); + } +} +function ct(n, e, t, r = !1) { + if (e == 0 && t <= 0) + return; + let i = n.length - 2; + i >= 0 && t <= 0 && t == n[i + 1] ? n[i] += e : e == 0 && n[i] == 0 ? n[i + 1] += t : r ? (n[i] += e, n[i + 1] += t) : n.push(e, t); +} +function Tn(n, e, t) { + if (t.length == 0) + return; + let r = e.length - 2 >> 1; + if (r < n.length) + n[n.length - 1] = n[n.length - 1].append(t); + else { + for (; n.length < r; ) + n.push(Ae.empty); + n.push(t); + } +} +function W0(n, e, t) { + let r = n.inserted; + for (let i = 0, s = 0, l = 0; l < n.sections.length; ) { + let o = n.sections[l++], a = n.sections[l++]; + if (a < 0) + i += o, s += o; + else { + let u = i, h = s, c = Ae.empty; + for (; u += o, h += a, a && r && (c = c.append(r[l - 2 >> 1])), !(t || l == n.sections.length || n.sections[l + 1] < 0); ) + o = n.sections[l++], a = n.sections[l++]; + e(i, u, s, h, c), i = u, s = h; + } + } +} +function U0(n, e, t, r = !1) { + let i = [], s = r ? [] : null, l = new js(n), o = new js(e); + for (let a = -1; ; ) + if (l.ins == -1 && o.ins == -1) { + let u = Math.min(l.len, o.len); + ct(i, u, -1), l.forward(u), o.forward(u); + } else if (o.ins >= 0 && (l.ins < 0 || a == l.i || l.off == 0 && (o.len < l.len || o.len == l.len && !t))) { + let u = o.len; + for (ct(i, o.ins, -1); u; ) { + let h = Math.min(l.len, u); + l.ins >= 0 && a < l.i && l.len <= h && (ct(i, 0, l.ins), s && Tn(s, i, l.text), a = l.i), l.forward(h), u -= h; + } + o.next(); + } else if (l.ins >= 0) { + let u = 0, h = l.len; + for (; h; ) + if (o.ins == -1) { + let c = Math.min(h, o.len); + u += c, h -= c, o.forward(c); + } else if (o.ins == 0 && o.len < h) + h -= o.len, o.next(); + else + break; + ct(i, u, a < l.i ? l.ins : 0), s && a < l.i && Tn(s, i, l.text), a = l.i, l.forward(l.len - h); + } else { + if (l.done && o.done) + return s ? tt.createSet(i, s) : $r.create(i); + throw new Error("Mismatched change set lengths"); + } +} +function Km(n, e, t = !1) { + let r = [], i = t ? [] : null, s = new js(n), l = new js(e); + for (let o = !1; ; ) { + if (s.done && l.done) + return i ? tt.createSet(r, i) : $r.create(r); + if (s.ins == 0) + ct(r, s.len, 0, o), s.next(); + else if (l.len == 0 && !l.done) + ct(r, 0, l.ins, o), i && Tn(i, r, l.text), l.next(); + else { + if (s.done || l.done) + throw new Error("Mismatched change set lengths"); + { + let a = Math.min(s.len2, l.len), u = r.length; + if (s.ins == -1) { + let h = l.ins == -1 ? -1 : l.off ? 0 : l.ins; + ct(r, a, h, o), i && h && Tn(i, r, l.text); + } else l.ins == -1 ? (ct(r, s.off ? 0 : s.len, a, o), i && Tn(i, r, s.textBit(a))) : (ct(r, s.off ? 0 : s.len, l.off ? 0 : l.ins, o), i && !l.off && Tn(i, r, l.text)); + o = (s.ins > a || l.ins >= 0 && l.len > a) && (o || r.length > u), s.forward2(a), l.forward(a); + } + } + } +} +class js { + 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 ? Ae.empty : e[t]; + } + textBit(e) { + let { inserted: t } = this.set, r = this.i - 2 >> 1; + return r >= t.length && !e ? Ae.empty : t[r].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 Zn { + constructor(e, t, r) { + this.from = e, this.to = t, this.flags = r; + } + /** + 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 r, i; + return this.empty ? r = i = e.mapPos(this.from, t) : (r = e.mapPos(this.from, 1), i = e.mapPos(this.to, -1)), r == this.from && i == this.to ? this : new Zn(r, i, this.flags); + } + /** + Extend this range to cover at least `from` to `to`. + */ + extend(e, t = e) { + if (e <= this.anchor && t >= this.anchor) + return I.range(e, t); + let r = Math.abs(e - this.anchor) > Math.abs(t - this.anchor) ? e : t; + return I.range(this.anchor, r); + } + /** + 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 I.range(e.anchor, e.head); + } + /** + @internal + */ + static create(e, t, r) { + return new Zn(e, t, r); + } +} +class I { + 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 : I.create(this.ranges.map((r) => r.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 r = 0; r < this.ranges.length; r++) + if (!this.ranges[r].eq(e.ranges[r], 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 I([this.main], 0); + } + /** + Extend this selection with an extra range. + */ + addRange(e, t = !0) { + return I.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 r = this.ranges.slice(); + return r[t] = e, I.create(r, 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 I(e.ranges.map((t) => Zn.fromJSON(t)), e.main); + } + /** + Create a selection holding a single range. + */ + static single(e, t = e) { + return new I([I.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 r = 0, i = 0; i < e.length; i++) { + let s = e[i]; + if (s.empty ? s.from <= r : s.from < r) + return I.normalized(e.slice(), t); + r = s.to; + } + return new I(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, r, i) { + return Zn.create(e, e, (t == 0 ? 0 : t < 0 ? 8 : 16) | (r == null ? 7 : Math.min(6, r)) | (i ?? 16777215) << 6); + } + /** + Create a selection range. + */ + static range(e, t, r, i) { + let s = (r ?? 16777215) << 6 | (i == null ? 7 : Math.min(6, i)); + return t < e ? Zn.create(t, e, 48 | s) : Zn.create(e, t, (t > e ? 8 : 0) | s); + } + /** + @internal + */ + static normalized(e, t = 0) { + let r = e[t]; + e.sort((i, s) => i.from - s.from), t = e.indexOf(r); + for (let i = 1; i < e.length; i++) { + let s = e[i], l = e[i - 1]; + if (s.empty ? s.from <= l.to : s.from < l.to) { + let o = l.from, a = Math.max(s.to, l.to); + i <= t && t--, e.splice(--i, 2, s.anchor > s.head ? I.range(a, o) : I.range(o, a)); + } + } + return new I(e, t); + } +} +function Xm(n, e) { + for (let t of n.ranges) + if (t.to > e) + throw new RangeError("Selection points outside of document"); +} +let rh = 0; +class X { + constructor(e, t, r, i, s) { + this.combine = e, this.compareInput = t, this.compare = r, this.isStatic = i, this.id = rh++, this.default = e([]), this.extensions = typeof s == "function" ? s(this) : s; + } + /** + 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 X(e.combine || ((t) => t), e.compareInput || ((t, r) => t === r), e.compare || (e.combine ? (t, r) => t === r : nh), !!e.static, e.enables); + } + /** + Returns an extension that adds the given value to this facet. + */ + of(e) { + return new fo([], 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 fo(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 fo(e, this, 2, t); + } + from(e, t) { + return t || (t = (r) => r), this.compute([e], (r) => t(r.field(e))); + } +} +function nh(n, e) { + return n == e || n.length == e.length && n.every((t, r) => t === e[r]); +} +class fo { + constructor(e, t, r, i) { + this.dependencies = e, this.facet = t, this.type = r, this.value = i, this.id = rh++; + } + dynamicSlot(e) { + var t; + let r = this.value, i = this.facet.compareInput, s = this.id, l = e[s] >> 1, o = this.type == 2, a = !1, u = !1, h = []; + for (let c of this.dependencies) + c == "doc" ? a = !0 : c == "selection" ? u = !0 : ((t = e[c.id]) !== null && t !== void 0 ? t : 1) & 1 || h.push(e[c.id]); + return { + create(c) { + return c.values[l] = r(c), 1; + }, + update(c, f) { + if (a && f.docChanged || u && (f.docChanged || f.selection) || G0(c, h)) { + let m = r(c); + if (o ? !Hc(m, c.values[l], i) : !i(m, c.values[l])) + return c.values[l] = m, 1; + } + return 0; + }, + reconfigure: (c, f) => { + let m, g = f.config.address[s]; + if (g != null) { + let v = Mo(f, g); + if (this.dependencies.every((k) => k instanceof X ? f.facet(k) === c.facet(k) : k instanceof Lt ? f.field(k, !1) == c.field(k, !1) : !0) || (o ? Hc(m = r(c), v, i) : i(m = r(c), v))) + return c.values[l] = v, 0; + } else + m = r(c); + return c.values[l] = m, 1; + } + }; + } +} +function Hc(n, e, t) { + if (n.length != e.length) + return !1; + for (let r = 0; r < n.length; r++) + if (!t(n[r], e[r])) + return !1; + return !0; +} +function G0(n, e) { + let t = !1; + for (let r of e) + Ls(n, r) & 1 && (t = !0); + return t; +} +function E5(n, e, t) { + let r = t.map((a) => n[a.id]), i = t.map((a) => a.type), s = r.filter((a) => !(a & 1)), l = n[e.id] >> 1; + function o(a) { + let u = []; + for (let h = 0; h < r.length; h++) { + let c = Mo(a, r[h]); + if (i[h] == 2) + for (let f of c) + u.push(f); + else + u.push(c); + } + return e.combine(u); + } + return { + create(a) { + for (let u of r) + Ls(a, u); + return a.values[l] = o(a), 1; + }, + update(a, u) { + if (!G0(a, s)) + return 0; + let h = o(a); + return e.compare(h, a.values[l]) ? 0 : (a.values[l] = h, 1); + }, + reconfigure(a, u) { + let h = G0(a, r), c = u.config.facets[e.id], f = u.facet(e); + if (c && !h && nh(t, c)) + return a.values[l] = f, 0; + let m = o(a); + return e.compare(m, f) ? (a.values[l] = f, 0) : (a.values[l] = m, 1); + } + }; +} +const qc = /* @__PURE__ */ X.define({ static: !0 }); +class Lt { + constructor(e, t, r, i, s) { + this.id = e, this.createF = t, this.updateF = r, this.compareF = i, this.spec = s, this.provides = void 0; + } + /** + Define a state field. + */ + static define(e) { + let t = new Lt(rh++, e.create, e.update, e.compare || ((r, i) => r === i), e); + return e.provide && (t.provides = e.provide(t)), t; + } + create(e) { + let t = e.facet(qc).find((r) => r.field == this); + return (t?.create || this.createF)(e); + } + /** + @internal + */ + slot(e) { + let t = e[this.id] >> 1; + return { + create: (r) => (r.values[t] = this.create(r), 1), + update: (r, i) => { + let s = r.values[t], l = this.updateF(s, i); + return this.compareF(s, l) ? 0 : (r.values[t] = l, 1); + }, + reconfigure: (r, i) => i.config.address[this.id] != null ? (r.values[t] = i.field(this), 0) : (r.values[t] = this.create(r), 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, qc.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 Kn = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 }; +function fs(n) { + return (e) => new Zm(e, n); +} +const al = { + /** + The highest precedence level, for extensions that should end up + near the start of the precedence ordering. + */ + highest: /* @__PURE__ */ fs(Kn.highest), + /** + A higher-than-default precedence, for extensions that should + come before those with default precedence. + */ + high: /* @__PURE__ */ fs(Kn.high), + /** + The default precedence, which is also used for extensions + without an explicit precedence. + */ + default: /* @__PURE__ */ fs(Kn.default), + /** + A lower-than-default precedence. + */ + low: /* @__PURE__ */ fs(Kn.low), + /** + The lowest precedence level. Meant for things that should end up + near the end of the extension order. + */ + lowest: /* @__PURE__ */ fs(Kn.lowest) +}; +class Zm { + constructor(e, t) { + this.inner = e, this.prec = t; + } +} +class ia { + /** + 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 j0(this, e); + } + /** + Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that + reconfigures this compartment. + */ + reconfigure(e) { + return ia.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 j0 { + constructor(e, t) { + this.compartment = e, this.inner = t; + } +} +class _o { + constructor(e, t, r, i, s, l) { + for (this.base = e, this.compartments = t, this.dynamicSlots = r, this.address = i, this.staticValues = s, this.facets = l, this.statusTemplate = []; this.statusTemplate.length < r.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, r) { + let i = [], s = /* @__PURE__ */ Object.create(null), l = /* @__PURE__ */ new Map(); + for (let f of F5(e, t, l)) + f instanceof Lt ? i.push(f) : (s[f.facet.id] || (s[f.facet.id] = [])).push(f); + let o = /* @__PURE__ */ Object.create(null), a = [], u = []; + for (let f of i) + o[f.id] = u.length << 1, u.push((m) => f.slot(m)); + let h = r?.config.facets; + for (let f in s) { + let m = s[f], g = m[0].facet, v = h && h[f] || []; + if (m.every( + (k) => k.type == 0 + /* Provider.Static */ + )) + if (o[g.id] = a.length << 1 | 1, nh(v, m)) + a.push(r.facet(g)); + else { + let k = g.combine(m.map((S) => S.value)); + a.push(r && g.compare(k, r.facet(g)) ? r.facet(g) : k); + } + else { + for (let k of m) + k.type == 0 ? (o[k.id] = a.length << 1 | 1, a.push(k.value)) : (o[k.id] = u.length << 1, u.push((S) => k.dynamicSlot(S))); + o[g.id] = u.length << 1, u.push((k) => E5(k, g, m)); + } + } + let c = u.map((f) => f(o)); + return new _o(e, l, c, o, a, s); + } +} +function F5(n, e, t) { + let r = [[], [], [], [], []], i = /* @__PURE__ */ new Map(); + function s(l, o) { + let a = i.get(l); + if (a != null) { + if (a <= o) + return; + let u = r[a].indexOf(l); + u > -1 && r[a].splice(u, 1), l instanceof j0 && t.delete(l.compartment); + } + if (i.set(l, o), Array.isArray(l)) + for (let u of l) + s(u, o); + else if (l instanceof j0) { + if (t.has(l.compartment)) + throw new RangeError("Duplicate use of compartment in extensions"); + let u = e.get(l.compartment) || l.inner; + t.set(l.compartment, u), s(u, o); + } else if (l instanceof Zm) + s(l.inner, l.prec); + else if (l instanceof Lt) + r[o].push(l), l.provides && s(l.provides, o); + else if (l instanceof fo) + r[o].push(l), l.facet.extensions && s(l.facet.extensions, Kn.default); + else { + let u = l.extension; + if (!u) + throw new Error(`Unrecognized extension value in extension set (${l}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`); + s(u, o); + } + } + return s(n, Kn.default), r.reduce((l, o) => l.concat(o)); +} +function Ls(n, e) { + if (e & 1) + return 2; + let t = e >> 1, r = n.status[t]; + if (r == 4) + throw new Error("Cyclic dependency between fields and/or facets"); + if (r & 2) + return r; + n.status[t] = 4; + let i = n.computeSlot(n, n.config.dynamicSlots[t]); + return n.status[t] = 2 | i; +} +function Mo(n, e) { + return e & 1 ? n.config.staticValues[e >> 1] : n.values[e >> 1]; +} +const Jm = /* @__PURE__ */ X.define(), $0 = /* @__PURE__ */ X.define({ + combine: (n) => n.some((e) => e), + static: !0 +}), Qm = /* @__PURE__ */ X.define({ + combine: (n) => n.length ? n[0] : void 0, + static: !0 +}), ep = /* @__PURE__ */ X.define(), tp = /* @__PURE__ */ X.define(), rp = /* @__PURE__ */ X.define(), np = /* @__PURE__ */ X.define({ + combine: (n) => n.length ? n[0] : !1 +}); +class vn { + /** + @internal + */ + constructor(e, t) { + this.type = e, this.value = t; + } + /** + Define a new type of annotation. + */ + static define() { + return new B5(); + } +} +class B5 { + /** + Create an instance of this annotation. + */ + of(e) { + return new vn(this, e); + } +} +class O5 { + /** + @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 ye(this, e); + } +} +class ye { + /** + @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 ye(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 O5(e.map || ((t) => t)); + } + /** + Map an array of effects through a change set. + */ + static mapEffects(e, t) { + if (!e.length) + return e; + let r = []; + for (let i of e) { + let s = i.map(t); + s && r.push(s); + } + return r; + } +} +ye.reconfigure = /* @__PURE__ */ ye.define(); +ye.appendConfig = /* @__PURE__ */ ye.define(); +class Qe { + constructor(e, t, r, i, s, l) { + this.startState = e, this.changes = t, this.selection = r, this.effects = i, this.annotations = s, this.scrollIntoView = l, this._doc = null, this._state = null, r && Xm(r, t.newLength), s.some((o) => o.type == Qe.time) || (this.annotations = s.concat(Qe.time.of(Date.now()))); + } + /** + @internal + */ + static create(e, t, r, i, s, l) { + return new Qe(e, t, r, i, s, l); + } + /** + 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(Qe.userEvent); + return !!(t && (t == e || t.length > e.length && t.slice(0, e.length) == e && t[e.length] == ".")); + } +} +Qe.time = /* @__PURE__ */ vn.define(); +Qe.userEvent = /* @__PURE__ */ vn.define(); +Qe.addToHistory = /* @__PURE__ */ vn.define(); +Qe.remote = /* @__PURE__ */ vn.define(); +function R5(n, e) { + let t = []; + for (let r = 0, i = 0; ; ) { + let s, l; + if (r < n.length && (i == e.length || e[i] >= n[r])) + s = n[r++], l = n[r++]; + else if (i < e.length) + s = e[i++], l = e[i++]; + else + return t; + !t.length || t[t.length - 1] < s ? t.push(s, l) : t[t.length - 1] < l && (t[t.length - 1] = l); + } +} +function ip(n, e, t) { + var r; + let i, s, l; + return t ? (i = e.changes, s = tt.empty(e.changes.length), l = n.changes.compose(e.changes)) : (i = e.changes.map(n.changes), s = n.changes.mapDesc(e.changes, !0), l = n.changes.compose(i)), { + changes: l, + selection: e.selection ? e.selection.map(s) : (r = n.selection) === null || r === void 0 ? void 0 : r.map(i), + effects: ye.mapEffects(n.effects, i).concat(ye.mapEffects(e.effects, s)), + annotations: n.annotations.length ? n.annotations.concat(e.annotations) : e.annotations, + scrollIntoView: n.scrollIntoView || e.scrollIntoView + }; +} +function Y0(n, e, t) { + let r = e.selection, i = zi(e.annotations); + return e.userEvent && (i = i.concat(Qe.userEvent.of(e.userEvent))), { + changes: e.changes instanceof tt ? e.changes : tt.of(e.changes || [], t, n.facet(Qm)), + selection: r && (r instanceof I ? r : I.single(r.anchor, r.head)), + effects: zi(e.effects), + annotations: i, + scrollIntoView: !!e.scrollIntoView + }; +} +function sp(n, e, t) { + let r = Y0(n, e.length ? e[0] : {}, n.doc.length); + e.length && e[0].filter === !1 && (t = !1); + for (let s = 1; s < e.length; s++) { + e[s].filter === !1 && (t = !1); + let l = !!e[s].sequential; + r = ip(r, Y0(n, e[s], l ? r.changes.newLength : n.doc.length), l); + } + let i = Qe.create(n, r.changes, r.selection, r.effects, r.annotations, r.scrollIntoView); + return N5(t ? L5(i) : i); +} +function L5(n) { + let e = n.startState, t = !0; + for (let i of e.facet(ep)) { + let s = i(n); + if (s === !1) { + t = !1; + break; + } + Array.isArray(s) && (t = t === !0 ? s : R5(t, s)); + } + if (t !== !0) { + let i, s; + if (t === !1) + s = n.changes.invertedDesc, i = tt.empty(e.doc.length); + else { + let l = n.changes.filter(t); + i = l.changes, s = l.filtered.mapDesc(l.changes).invertedDesc; + } + n = Qe.create(e, i, n.selection && n.selection.map(s), ye.mapEffects(n.effects, s), n.annotations, n.scrollIntoView); + } + let r = e.facet(tp); + for (let i = r.length - 1; i >= 0; i--) { + let s = r[i](n); + s instanceof Qe ? n = s : Array.isArray(s) && s.length == 1 && s[0] instanceof Qe ? n = s[0] : n = sp(e, zi(s), !1); + } + return n; +} +function N5(n) { + let e = n.startState, t = e.facet(rp), r = n; + for (let i = t.length - 1; i >= 0; i--) { + let s = t[i](n); + s && Object.keys(s).length && (r = ip(r, Y0(e, s, n.changes.newLength), !0)); + } + return r == n ? n : Qe.create(e, n.changes, n.selection, r.effects, r.annotations, r.scrollIntoView); +} +const I5 = []; +function zi(n) { + return n == null ? I5 : Array.isArray(n) ? n : [n]; +} +var Kt = /* @__PURE__ */ function(n) { + return n[n.Word = 0] = "Word", n[n.Space = 1] = "Space", n[n.Other = 2] = "Other", n; +}(Kt || (Kt = {})); +const z5 = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/; +let K0; +try { + K0 = /* @__PURE__ */ new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u"); +} catch { +} +function P5(n) { + if (K0) + return K0.test(n); + for (let e = 0; e < n.length; e++) { + let t = n[e]; + if (/\w/.test(t) || t > "€" && (t.toUpperCase() != t.toLowerCase() || z5.test(t))) + return !0; + } + return !1; +} +function H5(n) { + return (e) => { + if (!/\S/.test(e)) + return Kt.Space; + if (P5(e)) + return Kt.Word; + for (let t = 0; t < n.length; t++) + if (e.indexOf(n[t]) > -1) + return Kt.Word; + return Kt.Other; + }; +} +class Se { + constructor(e, t, r, i, s, l) { + this.config = e, this.doc = t, this.selection = r, this.values = i, this.status = e.statusTemplate.slice(), this.computeSlot = s, l && (l._state = this); + for (let o = 0; o < this.config.dynamicSlots.length; o++) + Ls(this, o << 1); + this.computeSlot = null; + } + field(e, t = !0) { + let r = this.config.address[e.id]; + if (r == null) { + if (t) + throw new RangeError("Field is not present in this state"); + return; + } + return Ls(this, r), Mo(this, r); + } + /** + 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 sp(this, e, !0); + } + /** + @internal + */ + applyTransaction(e) { + let t = this.config, { base: r, compartments: i } = t; + for (let o of e.effects) + o.is(ia.reconfigure) ? (t && (i = /* @__PURE__ */ new Map(), t.compartments.forEach((a, u) => i.set(u, a)), t = null), i.set(o.value.compartment, o.value.extension)) : o.is(ye.reconfigure) ? (t = null, r = o.value) : o.is(ye.appendConfig) && (t = null, r = zi(r).concat(o.value)); + let s; + t ? s = e.startState.values.slice() : (t = _o.resolve(r, i, this), s = new Se(t, this.doc, this.selection, t.dynamicSlots.map(() => null), (a, u) => u.reconfigure(a, this), null).values); + let l = e.startState.facet($0) ? e.newSelection : e.newSelection.asSingle(); + new Se(t, e.newDoc, l, s, (o, a) => a.update(o, 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: I.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, r = e(t.ranges[0]), i = this.changes(r.changes), s = [r.range], l = zi(r.effects); + for (let o = 1; o < t.ranges.length; o++) { + let a = e(t.ranges[o]), u = this.changes(a.changes), h = u.map(i); + for (let f = 0; f < o; f++) + s[f] = s[f].map(h); + let c = i.mapDesc(u, !0); + s.push(a.range.map(c)), i = i.compose(h), l = ye.mapEffects(l, h).concat(ye.mapEffects(zi(a.effects), c)); + } + return { + changes: i, + selection: I.create(s, t.mainIndex), + effects: l + }; + } + /** + 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 tt ? e : tt.of(e, this.doc.length, this.facet(Se.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 Ae.of(e.split(this.facet(Se.lineSeparator) || V0)); + } + /** + 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 : (Ls(this, t), Mo(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 r in e) { + let i = e[r]; + i instanceof Lt && this.config.address[i.id] != null && (t[r] = i.spec.toJSON(this.field(e[r]), 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 = {}, r) { + if (!e || typeof e.doc != "string") + throw new RangeError("Invalid JSON representation for EditorState"); + let i = []; + if (r) { + for (let s in r) + if (Object.prototype.hasOwnProperty.call(e, s)) { + let l = r[s], o = e[s]; + i.push(l.init((a) => l.spec.fromJSON(o, a))); + } + } + return Se.create({ + doc: e.doc, + selection: I.fromJSON(e.selection), + extensions: t.extensions ? i.concat([t.extensions]) : i + }); + } + /** + 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 = _o.resolve(e.extensions || [], /* @__PURE__ */ new Map()), r = e.doc instanceof Ae ? e.doc : Ae.of((e.doc || "").split(t.staticFacet(Se.lineSeparator) || V0)), i = e.selection ? e.selection instanceof I ? e.selection : I.single(e.selection.anchor, e.selection.head) : I.single(0); + return Xm(i, r.length), t.staticFacet($0) || (i = i.asSingle()), new Se(t, r, i, t.dynamicSlots.map(() => null), (s, l) => l.create(s), 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(Se.tabSize); + } + /** + Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator) + string for this state. + */ + get lineBreak() { + return this.facet(Se.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(np); + } + /** + 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 r of this.facet(Se.phrases)) + if (Object.prototype.hasOwnProperty.call(r, e)) { + e = r[e]; + break; + } + return t.length && (e = e.replace(/\$(\$|\d*)/g, (r, i) => { + if (i == "$") + return "$"; + let s = +(i || 1); + return !s || s > t.length ? r : t[s - 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, r = -1) { + let i = []; + for (let s of this.facet(Jm)) + for (let l of s(this, t, r)) + Object.prototype.hasOwnProperty.call(l, e) && i.push(l[e]); + return i; + } + /** + 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 H5(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: r, length: i } = this.doc.lineAt(e), s = this.charCategorizer(e), l = e - r, o = e - r; + for (; l > 0; ) { + let a = kt(t, l, !1); + if (s(t.slice(a, l)) != Kt.Word) + break; + l = a; + } + for (; o < i; ) { + let a = kt(t, o); + if (s(t.slice(o, a)) != Kt.Word) + break; + o = a; + } + return l == o ? null : I.range(l + r, o + r); + } +} +Se.allowMultipleSelections = $0; +Se.tabSize = /* @__PURE__ */ X.define({ + combine: (n) => n.length ? n[0] : 4 +}); +Se.lineSeparator = Qm; +Se.readOnly = np; +Se.phrases = /* @__PURE__ */ X.define({ + compare(n, e) { + let t = Object.keys(n), r = Object.keys(e); + return t.length == r.length && t.every((i) => n[i] == e[i]); + } +}); +Se.languageData = Jm; +Se.changeFilter = ep; +Se.transactionFilter = tp; +Se.transactionExtender = rp; +ia.reconfigure = /* @__PURE__ */ ye.define(); +function bi(n, e, t = {}) { + let r = {}; + for (let i of n) + for (let s of Object.keys(i)) { + let l = i[s], o = r[s]; + if (o === void 0) + r[s] = l; + else if (!(o === l || l === void 0)) if (Object.hasOwnProperty.call(t, s)) + r[s] = t[s](o, l); + else + throw new Error("Config merge conflict for field " + s); + } + for (let i in e) + r[i] === void 0 && (r[i] = e[i]); + return r; +} +class ri { + /** + 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 X0.create(e, t, this); + } +} +ri.prototype.startSide = ri.prototype.endSide = 0; +ri.prototype.point = !1; +ri.prototype.mapMode = at.TrackDel; +let X0 = class lp { + constructor(e, t, r) { + this.from = e, this.to = t, this.value = r; + } + /** + @internal + */ + static create(e, t, r) { + return new lp(e, t, r); + } +}; +function Z0(n, e) { + return n.from - e.from || n.value.startSide - e.value.startSide; +} +class ih { + constructor(e, t, r, i) { + this.from = e, this.to = t, this.value = r, this.maxPoint = i; + } + 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, r, i = 0) { + let s = r ? this.to : this.from; + for (let l = i, o = s.length; ; ) { + if (l == o) + return l; + let a = l + o >> 1, u = s[a] - e || (r ? this.value[a].endSide : this.value[a].startSide) - t; + if (a == l) + return u >= 0 ? l : o; + u >= 0 ? o = a : l = a + 1; + } + } + between(e, t, r, i) { + for (let s = this.findIndex(t, -1e9, !0), l = this.findIndex(r, 1e9, !1, s); s < l; s++) + if (i(this.from[s] + e, this.to[s] + e, this.value[s]) === !1) + return !1; + } + map(e, t) { + let r = [], i = [], s = [], l = -1, o = -1; + for (let a = 0; a < this.value.length; a++) { + let u = this.value[a], h = this.from[a] + e, c = this.to[a] + e, f, m; + if (h == c) { + let g = t.mapPos(h, u.startSide, u.mapMode); + if (g == null || (f = m = g, u.startSide != u.endSide && (m = t.mapPos(h, u.endSide), m < f))) + continue; + } else if (f = t.mapPos(h, u.startSide), m = t.mapPos(c, u.endSide), f > m || f == m && u.startSide > 0 && u.endSide <= 0) + continue; + (m - f || u.endSide - u.startSide) < 0 || (l < 0 && (l = f), u.point && (o = Math.max(o, m - f)), r.push(u), i.push(f - l), s.push(m - l)); + } + return { mapped: r.length ? new ih(i, s, r, o) : null, pos: l }; + } +} +class Ce { + constructor(e, t, r, i) { + this.chunkPos = e, this.chunk = t, this.nextLayer = r, this.maxPoint = i; + } + /** + @internal + */ + static create(e, t, r, i) { + return new Ce(e, t, r, i); + } + /** + @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: r = !1, filterFrom: i = 0, filterTo: s = this.length } = e, l = e.filter; + if (t.length == 0 && !l) + return this; + if (r && (t = t.slice().sort(Z0)), this.isEmpty) + return t.length ? Ce.of(t) : this; + let o = new op(this, null, -1).goto(0), a = 0, u = [], h = new ni(); + for (; o.value || a < t.length; ) + if (a < t.length && (o.from - t[a].from || o.startSide - t[a].value.startSide) >= 0) { + let c = t[a++]; + h.addInner(c.from, c.to, c.value) || u.push(c); + } else o.rangeIndex == 1 && o.chunkIndex < this.chunk.length && (a == t.length || this.chunkEnd(o.chunkIndex) < t[a].from) && (!l || i > this.chunkEnd(o.chunkIndex) || s < this.chunkPos[o.chunkIndex]) && h.addChunk(this.chunkPos[o.chunkIndex], this.chunk[o.chunkIndex]) ? o.nextChunk() : ((!l || i > o.to || s < o.from || l(o.from, o.to, o.value)) && (h.addInner(o.from, o.to, o.value) || u.push(X0.create(o.from, o.to, o.value))), o.next()); + return h.finishInner(this.nextLayer.isEmpty && !u.length ? Ce.empty : this.nextLayer.update({ add: u, filter: l, filterFrom: i, filterTo: s })); + } + /** + Map this range set through a set of changes, return the new set. + */ + map(e) { + if (e.empty || this.isEmpty) + return this; + let t = [], r = [], i = -1; + for (let l = 0; l < this.chunk.length; l++) { + let o = this.chunkPos[l], a = this.chunk[l], u = e.touchesRange(o, o + a.length); + if (u === !1) + i = Math.max(i, a.maxPoint), t.push(a), r.push(e.mapPos(o)); + else if (u === !0) { + let { mapped: h, pos: c } = a.map(o, e); + h && (i = Math.max(i, h.maxPoint), t.push(h), r.push(c)); + } + } + let s = this.nextLayer.map(e); + return t.length == 0 ? s : new Ce(r, t, s || Ce.empty, i); + } + /** + 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, r) { + if (!this.isEmpty) { + for (let i = 0; i < this.chunk.length; i++) { + let s = this.chunkPos[i], l = this.chunk[i]; + if (t >= s && e <= s + l.length && l.between(s, e - s, t - s, r) === !1) + return; + } + this.nextLayer.between(e, t, r); + } + } + /** + Iterate over the ranges in this set, in order, including all + ranges that end at or after `from`. + */ + iter(e = 0) { + return $s.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 $s.from(e).goto(t); + } + /** + Iterate over two groups of sets, calling methods on `comparator` + to notify it of possible differences. + */ + static compare(e, t, r, i, s = -1) { + let l = e.filter((c) => c.maxPoint > 0 || !c.isEmpty && c.maxPoint >= s), o = t.filter((c) => c.maxPoint > 0 || !c.isEmpty && c.maxPoint >= s), a = Vc(l, o, r), u = new ds(l, a, s), h = new ds(o, a, s); + r.iterGaps((c, f, m) => Wc(u, c, h, f, m, i)), r.empty && r.length == 0 && Wc(u, 0, h, 0, 0, i); + } + /** + Compare the contents of two groups of range sets, returning true + if they are equivalent in the given range. + */ + static eq(e, t, r = 0, i) { + i == null && (i = 999999999); + let s = e.filter((h) => !h.isEmpty && t.indexOf(h) < 0), l = t.filter((h) => !h.isEmpty && e.indexOf(h) < 0); + if (s.length != l.length) + return !1; + if (!s.length) + return !0; + let o = Vc(s, l), a = new ds(s, o, 0).goto(r), u = new ds(l, o, 0).goto(r); + for (; ; ) { + if (a.to != u.to || !J0(a.active, u.active) || a.point && (!u.point || !a.point.eq(u.point))) + return !1; + if (a.to > i) + return !0; + a.next(), u.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, r, i, s = -1) { + let l = new ds(e, null, s).goto(t), o = t, a = l.openStart; + for (; ; ) { + let u = Math.min(l.to, r); + if (l.point) { + let h = l.activeForPoint(l.to), c = l.pointFrom < t ? h.length + 1 : l.point.startSide < 0 ? h.length : Math.min(h.length, a); + i.point(o, u, l.point, h, c, l.pointRank), a = Math.min(l.openEnd(u), h.length); + } else u > o && (i.span(o, u, l.active, a), a = l.openEnd(u)); + if (l.to > r) + return a + (l.point && l.to > r ? 1 : 0); + o = l.to, l.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 r = new ni(); + for (let i of e instanceof X0 ? [e] : t ? q5(e) : e) + r.add(i.from, i.to, i.value); + return r.finish(); + } + /** + Join an array of range sets into a single set. + */ + static join(e) { + if (!e.length) + return Ce.empty; + let t = e[e.length - 1]; + for (let r = e.length - 2; r >= 0; r--) + for (let i = e[r]; i != Ce.empty; i = i.nextLayer) + t = new Ce(i.chunkPos, i.chunk, t, Math.max(i.maxPoint, t.maxPoint)); + return t; + } +} +Ce.empty = /* @__PURE__ */ new Ce([], [], null, -1); +function q5(n) { + if (n.length > 1) + for (let e = n[0], t = 1; t < n.length; t++) { + let r = n[t]; + if (Z0(e, r) > 0) + return n.slice().sort(Z0); + e = r; + } + return n; +} +Ce.empty.nextLayer = Ce.empty; +class ni { + finishChunk(e) { + this.chunks.push(new ih(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, r) { + this.addInner(e, t, r) || (this.nextLayer || (this.nextLayer = new ni())).add(e, t, r); + } + /** + @internal + */ + addInner(e, t, r) { + let i = e - this.lastTo || r.startSide - this.last.endSide; + if (i <= 0 && (e - this.lastFrom || r.startSide - this.last.startSide) < 0) + throw new Error("Ranges must be added sorted by `from` position and `startSide`"); + 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 = r, this.lastFrom = e, this.lastTo = t, this.value.push(r), r.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 r = t.value.length - 1; + return this.last = t.value[r], this.lastFrom = t.from[r] + e, this.lastTo = t.to[r] + 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(Ce.empty); + } + /** + @internal + */ + finishInner(e) { + if (this.from.length && this.finishChunk(!1), this.chunks.length == 0) + return e; + let t = Ce.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(e) : e, this.setMaxPoint); + return this.from = null, t; + } +} +function Vc(n, e, t) { + let r = /* @__PURE__ */ new Map(); + for (let s of n) + for (let l = 0; l < s.chunk.length; l++) + s.chunk[l].maxPoint <= 0 && r.set(s.chunk[l], s.chunkPos[l]); + let i = /* @__PURE__ */ new Set(); + for (let s of e) + for (let l = 0; l < s.chunk.length; l++) { + let o = r.get(s.chunk[l]); + o != null && (t ? t.mapPos(o) : o) == s.chunkPos[l] && !t?.touchesRange(o, o + s.chunk[l].length) && i.add(s.chunk[l]); + } + return i; +} +class op { + constructor(e, t, r, i = 0) { + this.layer = e, this.skip = t, this.minPoint = r, this.rank = i; + } + 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, r) { + for (; this.chunkIndex < this.layer.chunk.length; ) { + let i = this.layer.chunk[this.chunkIndex]; + if (!(this.skip && this.skip.has(i) || this.layer.chunkEnd(this.chunkIndex) < e || i.maxPoint < this.minPoint)) + break; + this.chunkIndex++, r = !1; + } + if (this.chunkIndex < this.layer.chunk.length) { + let i = this.layer.chunk[this.chunkIndex].findIndex(e - this.layer.chunkPos[this.chunkIndex], t, !0); + (!r || this.rangeIndex < i) && this.setRangeIndex(i); + } + 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], r = e + t.from[this.rangeIndex]; + if (this.from = r, 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 $s { + constructor(e) { + this.heap = e; + } + static from(e, t = null, r = -1) { + let i = []; + for (let s = 0; s < e.length; s++) + for (let l = e[s]; !l.isEmpty; l = l.nextLayer) + l.maxPoint >= r && i.push(new op(l, t, r, s)); + return i.length == 1 ? i[0] : new $s(i); + } + get startSide() { + return this.value ? this.value.startSide : 0; + } + goto(e, t = -1e9) { + for (let r of this.heap) + r.goto(e, t); + for (let r = this.heap.length >> 1; r >= 0; r--) + Fa(this.heap, r); + return this.next(), this; + } + forward(e, t) { + for (let r of this.heap) + r.forward(e, t); + for (let r = this.heap.length >> 1; r >= 0; r--) + Fa(this.heap, r); + (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(), Fa(this.heap, 0); + } + } +} +function Fa(n, e) { + for (let t = n[e]; ; ) { + let r = (e << 1) + 1; + if (r >= n.length) + break; + let i = n[r]; + if (r + 1 < n.length && i.compare(n[r + 1]) >= 0 && (i = n[r + 1], r++), t.compare(i) < 0) + break; + n[r] = t, n[e] = i, e = r; + } +} +class ds { + constructor(e, t, r) { + this.minPoint = r, 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 = $s.from(e, t, r); + } + 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) { + Sl(this.active, e), Sl(this.activeTo, e), Sl(this.activeRank, e), this.minActive = Uc(this.active, this.activeTo); + } + addActive(e) { + let t = 0, { value: r, to: i, rank: s } = this.cursor; + for (; t < this.activeRank.length && (s - this.activeRank[t] || i - this.activeTo[t]) > 0; ) + t++; + Al(this.active, t, r), Al(this.activeTo, t, i), Al(this.activeRank, t, s), e && Al(e, t, this.cursor.from), this.minActive = Uc(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 r = this.openStart < 0 ? [] : null; + for (; ; ) { + let i = this.minActive; + if (i > -1 && (this.activeTo[i] - this.cursor.from || this.active[i].endSide - this.cursor.startSide) < 0) { + if (this.activeTo[i] > e) { + this.to = this.activeTo[i], this.endSide = this.active[i].endSide; + break; + } + this.removeActive(i), r && Sl(r, i); + } else if (this.cursor.value) + if (this.cursor.from > e) { + this.to = this.cursor.from, this.endSide = this.cursor.startSide; + break; + } else { + let s = this.cursor.value; + if (!s.point) + this.addActive(r), this.cursor.next(); + else if (t && this.cursor.to == this.to && this.cursor.from < this.cursor.to) + this.cursor.next(); + else { + 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); + break; + } + } + else { + this.to = this.endSide = 1e9; + break; + } + } + if (r) { + this.openStart = 0; + for (let i = r.length - 1; i >= 0 && r[i] < e; i--) + this.openStart++; + } + } + activeForPoint(e) { + if (!this.active.length) + return this.active; + let t = []; + for (let r = this.active.length - 1; r >= 0 && !(this.activeRank[r] < this.pointRank); r--) + (this.activeTo[r] > e || this.activeTo[r] == e && this.active[r].endSide >= this.point.endSide) && t.push(this.active[r]); + return t.reverse(); + } + openEnd(e) { + let t = 0; + for (let r = this.activeTo.length - 1; r >= 0 && this.activeTo[r] > e; r--) + t++; + return t; + } +} +function Wc(n, e, t, r, i, s) { + n.goto(e), t.goto(r); + let l = r + i, o = r, a = r - e; + for (; ; ) { + let u = n.to + a - t.to || n.endSide - t.endSide, h = u < 0 ? n.to + a : t.to, c = Math.min(h, l); + if (n.point || t.point ? n.point && t.point && (n.point == t.point || n.point.eq(t.point)) && J0(n.activeForPoint(n.to), t.activeForPoint(t.to)) || s.comparePoint(o, c, n.point, t.point) : c > o && !J0(n.active, t.active) && s.compareRange(o, c, n.active, t.active), h > l) + break; + o = h, u <= 0 && n.next(), u >= 0 && t.next(); + } +} +function J0(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 Sl(n, e) { + for (let t = e, r = n.length - 1; t < r; t++) + n[t] = n[t + 1]; + n.pop(); +} +function Al(n, e, t) { + for (let r = n.length - 1; r >= e; r--) + n[r + 1] = n[r]; + n[e] = t; +} +function Uc(n, e) { + let t = -1, r = 1e9; + for (let i = 0; i < e.length; i++) + (e[i] - r || n[i].endSide - n[t].endSide) < 0 && (t = i, r = e[i]); + return t; +} +function rs(n, e, t = n.length) { + let r = 0; + for (let i = 0; i < t; ) + n.charCodeAt(i) == 9 ? (r += e - r % e, i++) : (r++, i = kt(n, i)); + return r; +} +function Q0(n, e, t, r) { + for (let i = 0, s = 0; ; ) { + if (s >= e) + return i; + if (i == n.length) + break; + s += n.charCodeAt(i) == 9 ? t - s % t : 1, i = kt(n, i); + } + return r === !0 ? -1 : n.length; +} +const eu = "ͼ", Gc = typeof Symbol > "u" ? "__" + eu : Symbol.for(eu), tu = typeof Symbol > "u" ? "__styleSet" + Math.floor(Math.random() * 1e8) : Symbol("styleSet"), jc = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : {}; +class On { + // :: (Object