let gl = [], qu = []; (() => { let r = "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((e) => e ? parseInt(e, 36) : 1); for (let e = 0, t = 0; e < r.length; e++) (e % 2 ? qu : gl).push(t = t + r[e]); })(); function kg(r) { if (r < 768) return !1; for (let e = 0, t = gl.length; ; ) { let i = e + t >> 1; if (r < gl[i]) t = i; else if (r >= qu[i]) e = i + 1; else return !0; if (e == t) return !1; } } function _h(r) { return r >= 127462 && r <= 127487; } const Bh = 8205; function Qg(r, e, t = !0, i = !0) { return (t ? Yu : vg)(r, e, i); } function Yu(r, e, t) { if (e == r.length) return e; e && Nu(r.charCodeAt(e)) && Wu(r.charCodeAt(e - 1)) && e--; let i = So(r, e); for (e += Ih(i); e < r.length; ) { let n = So(r, e); if (i == Bh || n == Bh || t && kg(n)) e += Ih(n), i = n; else if (_h(n)) { let s = 0, o = e - 2; for (; o >= 0 && _h(So(r, o)); ) s++, o -= 2; if (s % 2 == 0) break; e += 2; } else break; } return e; } function vg(r, e, t) { for (; e > 0; ) { let i = Yu(r, e - 2, t); if (i < e) return i; e--; } return 0; } function So(r, e) { let t = r.charCodeAt(e); if (!Wu(t) || e + 1 == r.length) return t; let i = r.charCodeAt(e + 1); return Nu(i) ? (t - 55296 << 10) + (i - 56320) + 65536 : t; } function Nu(r) { return r >= 56320 && r < 57344; } function Wu(r) { return r >= 55296 && r < 56320; } function Ih(r) { return r < 65536 ? 1 : 2; } class K { /** 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] = Vi(this, e, t); let n = []; return this.decompose( 0, e, n, 2 /* Open.To */ ), i.length && i.decompose( 0, i.length, n, 3 /* Open.To */ ), this.decompose( t, this.length, n, 1 /* Open.From */ ), St.from(n, 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] = Vi(this, e, t); let i = []; return this.decompose(e, t, i, 0), St.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), n = new Pr(this), s = new Pr(e); for (let o = t, l = t; ; ) { if (n.next(o), s.next(o), o = 0, n.lineBreak != s.lineBreak || n.done != s.done || n.value != s.value) return !1; if (l += n.value.length, n.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 Pr(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 ju(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 n = this.line(e).from; i = this.iterRange(n, Math.max(n, t == this.lines + 1 ? this.length : t <= 1 ? 0 : this.line(t - 1).to)); } return new Gu(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] ? K.empty : e.length <= 32 ? new de(e) : St.from(de.split(e, [])); } } class de extends K { constructor(e, t = $g(e)) { super(), this.text = e, this.length = t; } get lines() { return this.text.length; } get children() { return null; } lineInner(e, t, i, n) { for (let s = 0; ; s++) { let o = this.text[s], l = n + o.length; if ((t ? i : l) >= e) return new Pg(n, l, i, o); n = l + 1, i++; } } decompose(e, t, i, n) { let s = e <= 0 && t >= this.length ? this : new de(Vh(this.text, e, t), Math.min(t, this.length) - Math.max(0, e)); if (n & 1) { let o = i.pop(), l = Fn(s.text, o.text.slice(), 0, s.length); if (l.length <= 32) i.push(new de(l, o.length + s.length)); else { let a = l.length >> 1; i.push(new de(l.slice(0, a)), new de(l.slice(a))); } } else i.push(s); } replace(e, t, i) { if (!(i instanceof de)) return super.replace(e, t, i); [e, t] = Vi(this, e, t); let n = Fn(this.text, Fn(i.text, Vh(this.text, 0, e)), t), s = this.length + i.length - (t - e); return n.length <= 32 ? new de(n, s) : St.from(de.split(n, []), s); } sliceString(e, t = this.length, i = ` `) { [e, t] = Vi(this, e, t); let n = ""; for (let s = 0, o = 0; s <= t && o < this.text.length; o++) { let l = this.text[o], a = s + l.length; s > e && o && (n += i), e < a && t > s && (n += l.slice(Math.max(0, e - s), t - s)), s = a + 1; } return n; } flatten(e) { for (let t of this.text) e.push(t); } scanIdentical() { return 0; } static split(e, t) { let i = [], n = -1; for (let s of e) i.push(s), n += s.length + 1, i.length == 32 && (t.push(new de(i, n)), i = [], n = -1); return n > -1 && t.push(new de(i, n)), t; } } class St extends K { 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, n) { for (let s = 0; ; s++) { let o = this.children[s], l = n + o.length, a = i + o.lines - 1; if ((t ? a : l) >= e) return o.lineInner(e, t, i, n); n = l + 1, i = a + 1; } } decompose(e, t, i, n) { for (let s = 0, o = 0; o <= t && s < this.children.length; s++) { let l = this.children[s], a = o + l.length; if (e <= a && t >= o) { let h = n & ((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] = Vi(this, e, t), i.lines < this.lines) for (let n = 0, s = 0; n < this.children.length; n++) { let o = this.children[n], l = s + o.length; if (e >= s && t <= l) { let a = o.replace(e - s, t - s, i), h = this.lines - o.lines + a.lines; if (a.lines < h >> 4 && a.lines > h >> 6) { let c = this.children.slice(); return c[n] = a, new St(c, this.length - (t - e) + i.length); } return super.replace(s, l, a); } s = l + 1; } return super.replace(e, t, i); } sliceString(e, t = this.length, i = ` `) { [e, t] = Vi(this, e, t); let n = ""; for (let s = 0, o = 0; s < this.children.length && o <= t; s++) { let l = this.children[s], a = o + l.length; o > e && s && (n += i), e < a && t > o && (n += l.sliceString(e - o, t - o, i)), o = a + 1; } return n; } flatten(e) { for (let t of this.children) t.flatten(e); } scanIdentical(e, t) { if (!(e instanceof St)) return 0; let i = 0, [n, s, o, l] = t > 0 ? [0, 0, this.children.length, e.children.length] : [this.children.length - 1, e.children.length - 1, -1, -1]; for (; ; n += t, s += t) { if (n == o || s == l) return i; let a = this.children[n], h = e.children[s]; if (a != h) return i + a.scanIdentical(h, t); i += a.length + 1; } } static from(e, t = e.reduce((i, n) => i + n.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 de(d, t); } let n = Math.max( 32, i >> 5 /* Tree.BranchShift */ ), s = n << 1, o = n >> 1, l = [], a = 0, h = -1, c = []; function f(d) { let p; if (d.lines > s && d instanceof St) for (let O of d.children) f(O); else d.lines > o && (a > o || !a) ? (u(), l.push(d)) : d instanceof de && a && (p = c[c.length - 1]) instanceof de && d.lines + p.lines <= 32 ? (a += d.lines, h += d.length + 1, c[c.length - 1] = new de(p.text.concat(d.text), p.length + 1 + d.length)) : (a + d.lines > n && u(), a += d.lines, h += d.length + 1, c.push(d)); } function u() { a != 0 && (l.push(c.length == 1 ? c[0] : St.from(c, h)), h = -1, a = c.length = 0); } for (let d of e) f(d); return u(), l.length == 1 ? l[0] : new St(l, t); } } K.empty = /* @__PURE__ */ new de([""], 0); function $g(r) { let e = -1; for (let t of r) e += t.length + 1; return e; } function Fn(r, e, t = 0, i = 1e9) { for (let n = 0, s = 0, o = !0; s < r.length && n <= i; s++) { let l = r[s], a = n + l.length; a >= t && (a > i && (l = l.slice(0, i - n)), n < t && (l = l.slice(t - n)), o ? (e[e.length - 1] += l, o = !1) : e.push(l)), n = a + 1; } return e; } function Vh(r, e, t) { return Fn(r, [""], e, t); } class Pr { 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 de ? e.text.length : e.children.length) << 1]; } nextInner(e, t) { for (this.done = this.lineBreak = !1; ; ) { let i = this.nodes.length - 1, n = this.nodes[i], s = this.offsets[i], o = s >> 1, l = n instanceof de ? n.text.length : n.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 ((s & 1) == (t > 0 ? 0 : 1)) { if (this.offsets[i] += t, e == 0) return this.lineBreak = !0, this.value = ` `, this; e--; } else if (n instanceof de) { let a = n.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 = n.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 de ? 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 ju { constructor(e, t, i) { this.value = "", this.done = !1, this.cursor = new Pr(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: n } = this.cursor.next(e); return this.pos += (n.length + e) * t, this.value = n.length <= i ? n : t < 0 ? n.slice(n.length - i) : n.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 Gu { constructor(e) { this.inner = e, this.afterBreak = !0, this.value = "", this.done = !1; } next(e = 0) { let { done: t, lineBreak: i, value: n } = 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 = n, this.afterBreak = !1), this; } get lineBreak() { return !1; } } typeof Symbol < "u" && (K.prototype[Symbol.iterator] = function() { return this.iter(); }, Pr.prototype[Symbol.iterator] = ju.prototype[Symbol.iterator] = Gu.prototype[Symbol.iterator] = function() { return this; }); let Pg = class { /** @internal */ constructor(e, t, i, n) { this.from = e, this.to = t, this.number = i, this.text = n; } /** The length of the line (not including any line break after it). */ get length() { return this.to - this.from; } }; function Vi(r, e, t) { return e = Math.max(0, Math.min(r.length, e)), [e, Math.max(e, Math.min(r.length, t))]; } function De(r, e, t = !0, i = !0) { return Qg(r, e, t, i); } function Cg(r) { return r >= 56320 && r < 57344; } function Tg(r) { return r >= 55296 && r < 56320; } function Ee(r, e) { let t = r.charCodeAt(e); if (!Tg(t) || e + 1 == r.length) return t; let i = r.charCodeAt(e + 1); return Cg(i) ? (t - 55296 << 10) + (i - 56320) + 65536 : t; } function Da(r) { return r <= 65535 ? String.fromCharCode(r) : (r -= 65536, String.fromCharCode((r >> 10) + 55296, (r & 1023) + 56320)); } function ot(r) { return r < 65536 ? 1 : 2; } const bl = /\r\n?|\n/; var ke = /* @__PURE__ */ (function(r) { return r[r.Simple = 0] = "Simple", r[r.TrackDel = 1] = "TrackDel", r[r.TrackBefore = 2] = "TrackBefore", r[r.TrackAfter = 3] = "TrackAfter", r; })(ke || (ke = {})); class vt { // 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, n = 0; t < this.sections.length; ) { let s = this.sections[t++], o = this.sections[t++]; o < 0 ? (e(i, n, s), n += s) : n += o, i += 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) { yl(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++], n = this.sections[t++]; n < 0 ? e.push(i, n) : e.push(n, i); } return new vt(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 : Uu(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 `this` happened before the ones in `other`. */ mapDesc(e, t = !1) { return e.empty ? this : Sl(this, e, t); } mapPos(e, t = -1, i = ke.Simple) { let n = 0, s = 0; for (let o = 0; o < this.sections.length; ) { let l = this.sections[o++], a = this.sections[o++], h = n + l; if (a < 0) { if (h > e) return s + (e - n); s += l; } else { if (i != ke.Simple && h >= e && (i == ke.TrackDel && n < e && h > e || i == ke.TrackBefore && n < e || i == ke.TrackAfter && h > e)) return null; if (h > e || h == e && t < 0 && !l) return e == n || t < 0 ? s : s + a; s += a; } n = h; } if (e > n) throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`); 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 i = 0, n = 0; i < this.sections.length && n <= t; ) { let s = this.sections[i++], o = this.sections[i++], l = n + s; if (o >= 0 && n <= t && l >= e) return n < e && l > t ? "cover" : !0; n = l; } return !1; } /** @internal */ toString() { let e = ""; for (let t = 0; t < this.sections.length; ) { let i = this.sections[t++], n = this.sections[t++]; e += (e ? " " : "") + i + (n >= 0 ? ":" + n : ""); } 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 vt(e); } /** @internal */ static create(e) { return new vt(e); } } class ye extends vt { 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 yl(this, (t, i, n, s, o) => e = e.replace(n, n + (i - t), o), !1), e; } mapDesc(e, t = !1) { return Sl(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 n = 0, s = 0; n < t.length; n += 2) { let o = t[n], l = t[n + 1]; if (l >= 0) { t[n] = l, t[n + 1] = o; let a = n >> 1; for (; i.length < a; ) i.push(K.empty); i.push(o ? e.slice(s, s + o) : K.empty); } s += o; } return new ye(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 : Uu(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 : Sl(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) { yl(this, e, t); } /** Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change set. */ get desc() { return vt.create(this.sections); } /** @internal */ filter(e) { let t = [], i = [], n = [], s = new zr(this); e: for (let o = 0, l = 0; ; ) { let a = o == e.length ? 1e9 : e[o++]; for (; l < a || l == a && s.len == 0; ) { if (s.done) break e; let c = Math.min(s.len, a - l); $e(n, c, -1); let f = s.ins == -1 ? -1 : s.off == 0 ? s.ins : 0; $e(t, c, f), f > 0 && ti(i, t, s.text), s.forward(c), l += c; } let h = e[o++]; for (; l < h; ) { if (s.done) break e; let c = Math.min(s.len, h - l); $e(t, c, -1), $e(n, c, s.ins == -1 ? -1 : s.off == 0 ? s.ins : 0), s.forward(c), l += c; } } return { changes: new ye(t, i), filtered: vt.create(n) }; } /** 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], n = this.sections[t + 1]; n < 0 ? e.push(i) : n == 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 n = [], s = [], o = 0, l = null; function a(c = !1) { if (!c && !n.length) return; o < t && $e(n, t - o, -1); let f = new ye(n, s); l = l ? l.compose(f.map(l)) : f, n = [], s = [], o = 0; } function h(c) { if (Array.isArray(c)) for (let f of c) h(f); else if (c instanceof ye) { if (c.length != t) throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`); a(), l = l ? l.compose(c.map(l)) : c; } else { let { from: f, to: u = f, insert: d } = c; if (f > u || f < 0 || u > t) throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`); let p = d ? typeof d == "string" ? K.of(d.split(i || bl)) : d : K.empty, O = p.length; if (f == u && O == 0) return; f < o && a(), f > o && $e(n, f - o, -1), $e(n, u - f, O), ti(s, n, p), o = u; } } return h(e), a(!l), l; } /** Create an empty changeset of the given length. */ static empty(e) { return new ye(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 n = 0; n < e.length; n++) { let s = e[n]; if (typeof s == "number") t.push(s, -1); else { if (!Array.isArray(s) || typeof s[0] != "number" || s.some((o, l) => l && typeof o != "string")) throw new RangeError("Invalid JSON representation of ChangeSet"); if (s.length == 1) t.push(s[0], 0); else { for (; i.length < n; ) i.push(K.empty); i[n] = K.of(s.slice(1)), t.push(s[0], i[n].length); } } } return new ye(t, i); } /** @internal */ static createSet(e, t) { return new ye(e, t); } } function $e(r, e, t, i = !1) { if (e == 0 && t <= 0) return; let n = r.length - 2; n >= 0 && t <= 0 && t == r[n + 1] ? r[n] += e : n >= 0 && e == 0 && r[n] == 0 ? r[n + 1] += t : i ? (r[n] += e, r[n + 1] += t) : r.push(e, t); } function ti(r, e, t) { if (t.length == 0) return; let i = e.length - 2 >> 1; if (i < r.length) r[r.length - 1] = r[r.length - 1].append(t); else { for (; r.length < i; ) r.push(K.empty); r.push(t); } } function yl(r, e, t) { let i = r.inserted; for (let n = 0, s = 0, o = 0; o < r.sections.length; ) { let l = r.sections[o++], a = r.sections[o++]; if (a < 0) n += l, s += l; else { let h = n, c = s, f = K.empty; for (; h += l, c += a, a && i && (f = f.append(i[o - 2 >> 1])), !(t || o == r.sections.length || r.sections[o + 1] < 0); ) l = r.sections[o++], a = r.sections[o++]; e(n, h, s, c, f), n = h, s = c; } } } function Sl(r, e, t, i = !1) { let n = [], s = i ? [] : null, o = new zr(r), l = new zr(e); for (let a = -1; ; ) { if (o.done && l.len || l.done && o.len) throw new Error("Mismatched change set lengths"); if (o.ins == -1 && l.ins == -1) { let h = Math.min(o.len, l.len); $e(n, 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 ($e(n, l.ins, -1); h; ) { let c = Math.min(o.len, h); o.ins >= 0 && a < o.i && o.len <= c && ($e(n, 0, o.ins), s && ti(s, n, o.text), a = o.i), o.forward(c), h -= c; } l.next(); } else if (o.ins >= 0) { let h = 0, c = o.len; for (; c; ) if (l.ins == -1) { let f = Math.min(c, l.len); h += f, c -= f, l.forward(f); } else if (l.ins == 0 && l.len < c) c -= l.len, l.next(); else break; $e(n, h, a < o.i ? o.ins : 0), s && a < o.i && ti(s, n, o.text), a = o.i, o.forward(o.len - c); } else { if (o.done && l.done) return s ? ye.createSet(n, s) : vt.create(n); throw new Error("Mismatched change set lengths"); } } } function Uu(r, e, t = !1) { let i = [], n = t ? [] : null, s = new zr(r), o = new zr(e); for (let l = !1; ; ) { if (s.done && o.done) return n ? ye.createSet(i, n) : vt.create(i); if (s.ins == 0) $e(i, s.len, 0, l), s.next(); else if (o.len == 0 && !o.done) $e(i, 0, o.ins, l), n && ti(n, i, o.text), o.next(); else { if (s.done || o.done) throw new Error("Mismatched change set lengths"); { let a = Math.min(s.len2, o.len), h = i.length; if (s.ins == -1) { let c = o.ins == -1 ? -1 : o.off ? 0 : o.ins; $e(i, a, c, l), n && c && ti(n, i, o.text); } else o.ins == -1 ? ($e(i, s.off ? 0 : s.len, a, l), n && ti(n, i, s.textBit(a))) : ($e(i, s.off ? 0 : s.len, o.off ? 0 : o.ins, l), n && !o.off && ti(n, i, o.text)); l = (s.ins > a || o.ins >= 0 && o.len > a) && (l || i.length > h), s.forward2(a), o.forward(a); } } } } class zr { 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 ? K.empty : e[t]; } textBit(e) { let { inserted: t } = this.set, i = this.i - 2 >> 1; return i >= t.length && !e ? K.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 xi { 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, n; return this.empty ? i = n = e.mapPos(this.from, t) : (i = e.mapPos(this.from, 1), n = e.mapPos(this.to, -1)), i == this.from && n == this.to ? this : new xi(i, n, this.flags); } /** Extend this range to cover at least `from` to `to`. */ extend(e, t = e) { if (e <= this.anchor && t >= this.anchor) return v.range(e, t); let i = Math.abs(e - this.anchor) > Math.abs(t - this.anchor) ? e : t; return v.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 v.range(e.anchor, e.head); } /** @internal */ static create(e, t, i) { return new xi(e, t, i); } } class v { 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 : v.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 v([this.main], 0); } /** Extend this selection with an extra range. */ addRange(e, t = !0) { return v.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, v.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 v(e.ranges.map((t) => xi.fromJSON(t)), e.main); } /** Create a selection holding a single range. */ static single(e, t = e) { return new v([v.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, n = 0; n < e.length; n++) { let s = e[n]; if (s.empty ? s.from <= i : s.from < i) return v.normalized(e.slice(), t); i = s.to; } return new v(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, n) { return xi.create(e, e, (t == 0 ? 0 : t < 0 ? 8 : 16) | (i == null ? 7 : Math.min(6, i)) | (n ?? 16777215) << 6); } /** Create a selection range. */ static range(e, t, i, n) { let s = (i ?? 16777215) << 6 | (n == null ? 7 : Math.min(6, n)); return t < e ? xi.create(t, e, 48 | s) : xi.create(e, t, (t > e ? 8 : 0) | s); } /** @internal */ static normalized(e, t = 0) { let i = e[t]; e.sort((n, s) => n.from - s.from), t = e.indexOf(i); for (let n = 1; n < e.length; n++) { let s = e[n], o = e[n - 1]; if (s.empty ? s.from <= o.to : s.from < o.to) { let l = o.from, a = Math.max(s.to, o.to); n <= t && t--, e.splice(--n, 2, s.anchor > s.head ? v.range(a, l) : v.range(l, a)); } } return new v(e, t); } } function Fu(r, e) { for (let t of r.ranges) if (t.to > e) throw new RangeError("Selection points outside of document"); } let _a = 0; class R { constructor(e, t, i, n, s) { this.combine = e, this.compareInput = t, this.compare = i, this.isStatic = n, this.id = _a++, 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 R(e.combine || ((t) => t), e.compareInput || ((t, i) => t === i), e.compare || (e.combine ? (t, i) => t === i : Ba), !!e.static, e.enables); } /** Returns an extension that adds the given value to this facet. */ of(e) { return new Hn([], 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 Hn(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 Hn(e, this, 2, t); } from(e, t) { return t || (t = (i) => i), this.compute([e], (i) => t(i.field(e))); } } function Ba(r, e) { return r == e || r.length == e.length && r.every((t, i) => t === e[i]); } class Hn { constructor(e, t, i, n) { this.dependencies = e, this.facet = t, this.type = i, this.value = n, this.id = _a++; } dynamicSlot(e) { var t; let i = this.value, n = this.facet.compareInput, s = this.id, o = e[s] >> 1, l = this.type == 2, a = !1, h = !1, c = []; for (let f of this.dependencies) f == "doc" ? a = !0 : f == "selection" ? h = !0 : (((t = e[f.id]) !== null && t !== void 0 ? t : 1) & 1) == 0 && c.push(e[f.id]); return { create(f) { return f.values[o] = i(f), 1; }, update(f, u) { if (a && u.docChanged || h && (u.docChanged || u.selection) || wl(f, c)) { let d = i(f); if (l ? !qh(d, f.values[o], n) : !n(d, f.values[o])) return f.values[o] = d, 1; } return 0; }, reconfigure: (f, u) => { let d, p = u.config.address[s]; if (p != null) { let O = gs(u, p); if (this.dependencies.every((g) => g instanceof R ? u.facet(g) === f.facet(g) : g instanceof ge ? u.field(g, !1) == f.field(g, !1) : !0) || (l ? qh(d = i(f), O, n) : n(d = i(f), O))) return f.values[o] = O, 0; } else d = i(f); return f.values[o] = d, 1; } }; } } function qh(r, e, t) { if (r.length != e.length) return !1; for (let i = 0; i < r.length; i++) if (!t(r[i], e[i])) return !1; return !0; } function wl(r, e) { let t = !1; for (let i of e) Cr(r, i) & 1 && (t = !0); return t; } function Ag(r, e, t) { let i = t.map((a) => r[a.id]), n = t.map((a) => a.type), s = i.filter((a) => !(a & 1)), o = r[e.id] >> 1; function l(a) { let h = []; for (let c = 0; c < i.length; c++) { let f = gs(a, i[c]); if (n[c] == 2) for (let u of f) h.push(u); else h.push(f); } return e.combine(h); } return { create(a) { for (let h of i) Cr(a, h); return a.values[o] = l(a), 1; }, update(a, h) { if (!wl(a, s)) return 0; let c = l(a); return e.compare(c, a.values[o]) ? 0 : (a.values[o] = c, 1); }, reconfigure(a, h) { let c = wl(a, i), f = h.config.facets[e.id], u = h.facet(e); if (f && !c && Ba(t, f)) 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 bn = /* @__PURE__ */ R.define({ static: !0 }); class ge { constructor(e, t, i, n, s) { this.id = e, this.createF = t, this.updateF = i, this.compareF = n, this.spec = s, this.provides = void 0; } /** Define a state field. */ static define(e) { let t = new ge(_a++, e.create, e.update, e.compare || ((i, n) => i === n), e); return e.provide && (t.provides = e.provide(t)), t; } create(e) { let t = e.facet(bn).find((i) => i.field == this); return (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, n) => { let s = i.values[t], o = this.updateF(s, n); return this.compareF(s, o) ? 0 : (i.values[t] = o, 1); }, reconfigure: (i, n) => { let s = i.facet(bn), o = n.facet(bn), l; return (l = s.find((a) => a.field == this)) && l != o.find((a) => a.field == this) ? (i.values[t] = l.create(i), 1) : n.config.address[this.id] != null ? (i.values[t] = n.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, bn.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 yi = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 }; function lr(r) { return (e) => new Hu(e, r); } const Vt = { /** The highest precedence level, for extensions that should end up near the start of the precedence ordering. */ highest: /* @__PURE__ */ lr(yi.highest), /** A higher-than-default precedence, for extensions that should come before those with default precedence. */ high: /* @__PURE__ */ lr(yi.high), /** The default precedence, which is also used for extensions without an explicit precedence. */ default: /* @__PURE__ */ lr(yi.default), /** A lower-than-default precedence. */ low: /* @__PURE__ */ lr(yi.low), /** The lowest precedence level. Meant for things that should end up near the end of the extension order. */ lowest: /* @__PURE__ */ lr(yi.lowest) }; class Hu { constructor(e, t) { this.inner = e, this.prec = t; } } class eo { /** 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 xl(this, e); } /** Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that reconfigures this compartment. */ reconfigure(e) { return eo.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 xl { constructor(e, t) { this.compartment = e, this.inner = t; } } class ms { constructor(e, t, i, n, s, o) { for (this.base = e, this.compartments = t, this.dynamicSlots = i, this.address = n, this.staticValues = s, 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 n = [], s = /* @__PURE__ */ Object.create(null), o = /* @__PURE__ */ new Map(); for (let u of Mg(e, t, o)) u instanceof ge ? n.push(u) : (s[u.facet.id] || (s[u.facet.id] = [])).push(u); let l = /* @__PURE__ */ Object.create(null), a = [], h = []; for (let u of n) l[u.id] = h.length << 1, h.push((d) => u.slot(d)); let c = i?.config.facets; for (let u in s) { let d = s[u], p = d[0].facet, O = c && c[u] || []; if (d.every( (g) => g.type == 0 /* Provider.Static */ )) if (l[p.id] = a.length << 1 | 1, Ba(O, d)) a.push(i.facet(p)); else { let g = p.combine(d.map((b) => b.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((b) => g.dynamicSlot(b))); l[p.id] = h.length << 1, h.push((g) => Ag(g, p, d)); } } let f = h.map((u) => u(l)); return new ms(e, o, f, l, a, s); } } function Mg(r, e, t) { let i = [[], [], [], [], []], n = /* @__PURE__ */ new Map(); function s(o, l) { let a = n.get(o); if (a != null) { if (a <= l) return; let h = i[a].indexOf(o); h > -1 && i[a].splice(h, 1), o instanceof xl && t.delete(o.compartment); } if (n.set(o, l), Array.isArray(o)) for (let h of o) s(h, l); else if (o instanceof xl) { 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), s(h, l); } else if (o instanceof Hu) s(o.inner, o.prec); else if (o instanceof ge) i[l].push(o), o.provides && s(o.provides, l); else if (o instanceof Hn) i[l].push(o), o.facet.extensions && s(o.facet.extensions, yi.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.`); s(h, l); } } return s(r, yi.default), i.reduce((o, l) => o.concat(l)); } function Cr(r, e) { if (e & 1) return 2; let t = e >> 1, i = r.status[t]; if (i == 4) throw new Error("Cyclic dependency between fields and/or facets"); if (i & 2) return i; r.status[t] = 4; let n = r.computeSlot(r, r.config.dynamicSlots[t]); return r.status[t] = 2 | n; } function gs(r, e) { return e & 1 ? r.config.staticValues[e >> 1] : r.values[e >> 1]; } const Ku = /* @__PURE__ */ R.define(), kl = /* @__PURE__ */ R.define({ combine: (r) => r.some((e) => e), static: !0 }), Ju = /* @__PURE__ */ R.define({ combine: (r) => r.length ? r[0] : void 0, static: !0 }), ed = /* @__PURE__ */ R.define(), td = /* @__PURE__ */ R.define(), id = /* @__PURE__ */ R.define(), rd = /* @__PURE__ */ R.define({ combine: (r) => r.length ? r[0] : !1 }); class qt { /** @internal */ constructor(e, t) { this.type = e, this.value = t; } /** Define a new type of annotation. */ static define() { return new Zg(); } } class Zg { /** Create an instance of this annotation. */ of(e) { return new qt(this, e); } } class Xg { /** @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 V(this, e); } } class V { /** @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 V(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 Xg(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 n of e) { let s = n.map(t); s && i.push(s); } return i; } } V.reconfigure = /* @__PURE__ */ V.define(); V.appendConfig = /* @__PURE__ */ V.define(); class me { constructor(e, t, i, n, s, o) { this.startState = e, this.changes = t, this.selection = i, this.effects = n, this.annotations = s, this.scrollIntoView = o, this._doc = null, this._state = null, i && Fu(i, t.newLength), s.some((l) => l.type == me.time) || (this.annotations = s.concat(me.time.of(Date.now()))); } /** @internal */ static create(e, t, i, n, s, o) { return new me(e, t, i, n, s, 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(me.userEvent); return !!(t && (t == e || t.length > e.length && t.slice(0, e.length) == e && t[e.length] == ".")); } } me.time = /* @__PURE__ */ qt.define(); me.userEvent = /* @__PURE__ */ qt.define(); me.addToHistory = /* @__PURE__ */ qt.define(); me.remote = /* @__PURE__ */ qt.define(); function Rg(r, e) { let t = []; for (let i = 0, n = 0; ; ) { let s, o; if (i < r.length && (n == e.length || e[n] >= r[i])) s = r[i++], o = r[i++]; else if (n < e.length) s = e[n++], o = e[n++]; else return t; !t.length || t[t.length - 1] < s ? t.push(s, o) : t[t.length - 1] < o && (t[t.length - 1] = o); } } function nd(r, e, t) { var i; let n, s, o; return t ? (n = e.changes, s = ye.empty(e.changes.length), o = r.changes.compose(e.changes)) : (n = e.changes.map(r.changes), s = r.changes.mapDesc(e.changes, !0), o = r.changes.compose(n)), { changes: o, selection: e.selection ? e.selection.map(s) : (i = r.selection) === null || i === void 0 ? void 0 : i.map(n), effects: V.mapEffects(r.effects, n).concat(V.mapEffects(e.effects, s)), annotations: r.annotations.length ? r.annotations.concat(e.annotations) : e.annotations, scrollIntoView: r.scrollIntoView || e.scrollIntoView }; } function Ql(r, e, t) { let i = e.selection, n = zi(e.annotations); return e.userEvent && (n = n.concat(me.userEvent.of(e.userEvent))), { changes: e.changes instanceof ye ? e.changes : ye.of(e.changes || [], t, r.facet(Ju)), selection: i && (i instanceof v ? i : v.single(i.anchor, i.head)), effects: zi(e.effects), annotations: n, scrollIntoView: !!e.scrollIntoView }; } function sd(r, e, t) { let i = Ql(r, e.length ? e[0] : {}, r.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 o = !!e[s].sequential; i = nd(i, Ql(r, e[s], o ? i.changes.newLength : r.doc.length), o); } let n = me.create(r, i.changes, i.selection, i.effects, i.annotations, i.scrollIntoView); return Eg(t ? Lg(n) : n); } function Lg(r) { let e = r.startState, t = !0; for (let n of e.facet(ed)) { let s = n(r); if (s === !1) { t = !1; break; } Array.isArray(s) && (t = t === !0 ? s : Rg(t, s)); } if (t !== !0) { let n, s; if (t === !1) s = r.changes.invertedDesc, n = ye.empty(e.doc.length); else { let o = r.changes.filter(t); n = o.changes, s = o.filtered.mapDesc(o.changes).invertedDesc; } r = me.create(e, n, r.selection && r.selection.map(s), V.mapEffects(r.effects, s), r.annotations, r.scrollIntoView); } let i = e.facet(td); for (let n = i.length - 1; n >= 0; n--) { let s = i[n](r); s instanceof me ? r = s : Array.isArray(s) && s.length == 1 && s[0] instanceof me ? r = s[0] : r = sd(e, zi(s), !1); } return r; } function Eg(r) { let e = r.startState, t = e.facet(id), i = r; for (let n = t.length - 1; n >= 0; n--) { let s = t[n](r); s && Object.keys(s).length && (i = nd(i, Ql(e, s, r.changes.newLength), !0)); } return i == r ? r : me.create(e, r.changes, r.selection, i.effects, i.annotations, i.scrollIntoView); } const zg = []; function zi(r) { return r == null ? zg : Array.isArray(r) ? r : [r]; } var Ze = /* @__PURE__ */ (function(r) { return r[r.Word = 0] = "Word", r[r.Space = 1] = "Space", r[r.Other = 2] = "Other", r; })(Ze || (Ze = {})); const Dg = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/; let vl; try { vl = /* @__PURE__ */ new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u"); } catch { } function _g(r) { if (vl) return vl.test(r); for (let e = 0; e < r.length; e++) { let t = r[e]; if (/\w/.test(t) || t > "€" && (t.toUpperCase() != t.toLowerCase() || Dg.test(t))) return !0; } return !1; } function Bg(r) { return (e) => { if (!/\S/.test(e)) return Ze.Space; if (_g(e)) return Ze.Word; for (let t = 0; t < r.length; t++) if (e.indexOf(r[t]) > -1) return Ze.Word; return Ze.Other; }; } class W { constructor(e, t, i, n, s, o) { this.config = e, this.doc = t, this.selection = i, this.values = n, this.status = e.statusTemplate.slice(), this.computeSlot = s, o && (o._state = this); for (let l = 0; l < this.config.dynamicSlots.length; l++) Cr(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 Cr(this, i), gs(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 sd(this, e, !0); } /** @internal */ applyTransaction(e) { let t = this.config, { base: i, compartments: n } = t; for (let l of e.effects) l.is(eo.reconfigure) ? (t && (n = /* @__PURE__ */ new Map(), t.compartments.forEach((a, h) => n.set(h, a)), t = null), n.set(l.value.compartment, l.value.extension)) : l.is(V.reconfigure) ? (t = null, i = l.value) : l.is(V.appendConfig) && (t = null, i = zi(i).concat(l.value)); let s; t ? s = e.startState.values.slice() : (t = ms.resolve(i, n, this), s = new W(t, this.doc, this.selection, t.dynamicSlots.map(() => null), (a, h) => h.reconfigure(a, this), null).values); let o = e.startState.facet(kl) ? e.newSelection : e.newSelection.asSingle(); new W(t, e.newDoc, o, s, (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: v.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]), n = this.changes(i.changes), s = [i.range], o = zi(i.effects); for (let l = 1; l < t.ranges.length; l++) { let a = e(t.ranges[l]), h = this.changes(a.changes), c = h.map(n); for (let u = 0; u < l; u++) s[u] = s[u].map(c); let f = n.mapDesc(h, !0); s.push(a.range.map(f)), n = n.compose(c), o = V.mapEffects(o, c).concat(V.mapEffects(zi(a.effects), f)); } return { changes: n, selection: v.create(s, 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 ye ? e : ye.of(e, this.doc.length, this.facet(W.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 K.of(e.split(this.facet(W.lineSeparator) || bl)); } /** 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 : (Cr(this, t), gs(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 n = e[i]; n instanceof ge && this.config.address[n.id] != null && (t[i] = n.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 n = []; if (i) { for (let s in i) if (Object.prototype.hasOwnProperty.call(e, s)) { let o = i[s], l = e[s]; n.push(o.init((a) => o.spec.fromJSON(l, a))); } } return W.create({ doc: e.doc, selection: v.fromJSON(e.selection), extensions: t.extensions ? n.concat([t.extensions]) : n }); } /** 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 = ms.resolve(e.extensions || [], /* @__PURE__ */ new Map()), i = e.doc instanceof K ? e.doc : K.of((e.doc || "").split(t.staticFacet(W.lineSeparator) || bl)), n = e.selection ? e.selection instanceof v ? e.selection : v.single(e.selection.anchor, e.selection.head) : v.single(0); return Fu(n, i.length), t.staticFacet(kl) || (n = n.asSingle()), new W(t, i, n, t.dynamicSlots.map(() => null), (s, o) => o.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(W.tabSize); } /** Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator) string for this state. */ get lineBreak() { return this.facet(W.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(rd); } /** 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(W.phrases)) if (Object.prototype.hasOwnProperty.call(i, e)) { e = i[e]; break; } return t.length && (e = e.replace(/\$(\$|\d*)/g, (i, n) => { if (n == "$") return "$"; let s = +(n || 1); return !s || s > t.length ? i : 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, i = -1) { let n = []; for (let s of this.facet(Ku)) for (let o of s(this, t, i)) Object.prototype.hasOwnProperty.call(o, e) && n.push(o[e]); return n; } /** 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 Bg(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: n } = this.doc.lineAt(e), s = this.charCategorizer(e), o = e - i, l = e - i; for (; o > 0; ) { let a = De(t, o, !1); if (s(t.slice(a, o)) != Ze.Word) break; o = a; } for (; l < n; ) { let a = De(t, l); if (s(t.slice(l, a)) != Ze.Word) break; l = a; } return o == l ? null : v.range(o + i, l + i); } } W.allowMultipleSelections = kl; W.tabSize = /* @__PURE__ */ R.define({ combine: (r) => r.length ? r[0] : 4 }); W.lineSeparator = Ju; W.readOnly = rd; W.phrases = /* @__PURE__ */ R.define({ compare(r, e) { let t = Object.keys(r), i = Object.keys(e); return t.length == i.length && t.every((n) => r[n] == e[n]); } }); W.languageData = Ku; W.changeFilter = ed; W.transactionFilter = td; W.transactionExtender = id; eo.reconfigure = /* @__PURE__ */ V.define(); function Yt(r, e, t = {}) { let i = {}; for (let n of r) for (let s of Object.keys(n)) { let o = n[s], l = i[s]; if (l === void 0) i[s] = o; else if (!(l === o || o === void 0)) if (Object.hasOwnProperty.call(t, s)) i[s] = t[s](l, o); else throw new Error("Config merge conflict for field " + s); } for (let n in e) i[n] === void 0 && (i[n] = e[n]); return i; } class oi { /** 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 $l.create(e, t, this); } } oi.prototype.startSide = oi.prototype.endSide = 0; oi.prototype.point = !1; oi.prototype.mapMode = ke.TrackDel; let $l = class od { constructor(e, t, i) { this.from = e, this.to = t, this.value = i; } /** @internal */ static create(e, t, i) { return new od(e, t, i); } }; function Pl(r, e) { return r.from - e.from || r.value.startSide - e.value.startSide; } class Ia { constructor(e, t, i, n) { this.from = e, this.to = t, this.value = i, this.maxPoint = n; } 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, n = 0) { let s = i ? this.to : this.from; for (let o = n, l = s.length; ; ) { if (o == l) return o; let a = o + l >> 1, h = s[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, n) { for (let s = this.findIndex(t, -1e9, !0), o = this.findIndex(i, 1e9, !1, s); s < o; s++) if (n(this.from[s] + e, this.to[s] + e, this.value[s]) === !1) return !1; } map(e, t) { let i = [], n = [], s = [], o = -1, l = -1; for (let a = 0; a < this.value.length; a++) { let h = this.value[a], c = this.from[a] + e, f = this.to[a] + e, u, d; if (c == f) { let p = t.mapPos(c, h.startSide, h.mapMode); if (p == null || (u = d = p, h.startSide != h.endSide && (d = t.mapPos(c, h.endSide), d < u))) continue; } else if (u = t.mapPos(c, h.startSide), d = t.mapPos(f, 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), n.push(u - o), s.push(d - o)); } return { mapped: i.length ? new Ia(n, s, i, l) : null, pos: o }; } } class H { constructor(e, t, i, n) { this.chunkPos = e, this.chunk = t, this.nextLayer = i, this.maxPoint = n; } /** @internal */ static create(e, t, i, n) { return new H(e, t, i, n); } /** @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: n = 0, filterTo: s = this.length } = e, o = e.filter; if (t.length == 0 && !o) return this; if (i && (t = t.slice().sort(Pl)), this.isEmpty) return t.length ? H.of(t) : this; let l = new ld(this, null, -1).goto(0), a = 0, h = [], c = new _t(); for (; l.value || a < t.length; ) if (a < t.length && (l.from - t[a].from || l.startSide - t[a].value.startSide) >= 0) { let f = t[a++]; c.addInner(f.from, f.to, f.value) || h.push(f); } else l.rangeIndex == 1 && l.chunkIndex < this.chunk.length && (a == t.length || this.chunkEnd(l.chunkIndex) < t[a].from) && (!o || n > this.chunkEnd(l.chunkIndex) || s < this.chunkPos[l.chunkIndex]) && c.addChunk(this.chunkPos[l.chunkIndex], this.chunk[l.chunkIndex]) ? l.nextChunk() : ((!o || n > l.to || s < l.from || o(l.from, l.to, l.value)) && (c.addInner(l.from, l.to, l.value) || h.push($l.create(l.from, l.to, l.value))), l.next()); return c.finishInner(this.nextLayer.isEmpty && !h.length ? H.empty : this.nextLayer.update({ add: h, filter: o, filterFrom: n, 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 = [], i = [], n = -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) n = Math.max(n, a.maxPoint), t.push(a), i.push(e.mapPos(l)); else if (h === !0) { let { mapped: c, pos: f } = a.map(l, e); c && (n = Math.max(n, c.maxPoint), t.push(c), i.push(f)); } } let s = this.nextLayer.map(e); return t.length == 0 ? s : new H(i, t, s || H.empty, n); } /** 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 n = 0; n < this.chunk.length; n++) { let s = this.chunkPos[n], o = this.chunk[n]; if (t >= s && e <= s + o.length && o.between(s, e - s, t - s, 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 Dr.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 Dr.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, n, s = -1) { let o = e.filter((f) => f.maxPoint > 0 || !f.isEmpty && f.maxPoint >= s), l = t.filter((f) => f.maxPoint > 0 || !f.isEmpty && f.maxPoint >= s), a = Yh(o, l, i), h = new ar(o, a, s), c = new ar(l, a, s); i.iterGaps((f, u, d) => Nh(h, f, c, u, d, n)), i.empty && i.length == 0 && Nh(h, 0, c, 0, 0, n); } /** 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, n) { n == null && (n = 999999999); let s = e.filter((c) => !c.isEmpty && t.indexOf(c) < 0), o = t.filter((c) => !c.isEmpty && e.indexOf(c) < 0); if (s.length != o.length) return !1; if (!s.length) return !0; let l = Yh(s, o), a = new ar(s, l, 0).goto(i), h = new ar(o, l, 0).goto(i); for (; ; ) { if (a.to != h.to || !Cl(a.active, h.active) || a.point && (!h.point || !a.point.eq(h.point))) return !1; if (a.to > n) 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, n, s = -1) { let o = new ar(e, null, s).goto(t), l = t, a = o.openStart; for (; ; ) { let h = Math.min(o.to, i); if (o.point) { let c = o.activeForPoint(o.to), f = o.pointFrom < t ? c.length + 1 : o.point.startSide < 0 ? c.length : Math.min(c.length, a); n.point(l, h, o.point, c, f, o.pointRank), a = Math.min(o.openEnd(h), c.length); } else h > l && (n.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 _t(); for (let n of e instanceof $l ? [e] : t ? Ig(e) : e) i.add(n.from, n.to, n.value); return i.finish(); } /** Join an array of range sets into a single set. */ static join(e) { if (!e.length) return H.empty; let t = e[e.length - 1]; for (let i = e.length - 2; i >= 0; i--) for (let n = e[i]; n != H.empty; n = n.nextLayer) t = new H(n.chunkPos, n.chunk, t, Math.max(n.maxPoint, t.maxPoint)); return t; } } H.empty = /* @__PURE__ */ new H([], [], null, -1); function Ig(r) { if (r.length > 1) for (let e = r[0], t = 1; t < r.length; t++) { let i = r[t]; if (Pl(e, i) > 0) return r.slice().sort(Pl); e = i; } return r; } H.empty.nextLayer = H.empty; class _t { finishChunk(e) { this.chunks.push(new Ia(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 _t())).add(e, t, i); } /** @internal */ addInner(e, t, i) { let n = e - this.lastTo || i.startSide - this.last.endSide; if (n <= 0 && (e - this.lastFrom || i.startSide - this.last.startSide) < 0) throw new Error("Ranges must be added sorted by `from` position and `startSide`"); return n < 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(H.empty); } /** @internal */ finishInner(e) { if (this.from.length && this.finishChunk(!1), this.chunks.length == 0) return e; let t = H.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(e) : e, this.setMaxPoint); return this.from = null, t; } } function Yh(r, e, t) { let i = /* @__PURE__ */ new Map(); for (let s of r) for (let o = 0; o < s.chunk.length; o++) s.chunk[o].maxPoint <= 0 && i.set(s.chunk[o], s.chunkPos[o]); let n = /* @__PURE__ */ new Set(); for (let s of e) for (let o = 0; o < s.chunk.length; o++) { let l = i.get(s.chunk[o]); l != null && (t ? t.mapPos(l) : l) == s.chunkPos[o] && !t?.touchesRange(l, l + s.chunk[o].length) && n.add(s.chunk[o]); } return n; } class ld { constructor(e, t, i, n = 0) { this.layer = e, this.skip = t, this.minPoint = i, this.rank = n; } 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 n = this.layer.chunk[this.chunkIndex]; if (!(this.skip && this.skip.has(n) || this.layer.chunkEnd(this.chunkIndex) < e || n.maxPoint < this.minPoint)) break; this.chunkIndex++, i = !1; } if (this.chunkIndex < this.layer.chunk.length) { let n = this.layer.chunk[this.chunkIndex].findIndex(e - this.layer.chunkPos[this.chunkIndex], t, !0); (!i || this.rangeIndex < n) && this.setRangeIndex(n); } 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 Dr { constructor(e) { this.heap = e; } static from(e, t = null, i = -1) { let n = []; for (let s = 0; s < e.length; s++) for (let o = e[s]; !o.isEmpty; o = o.nextLayer) o.maxPoint >= i && n.push(new ld(o, t, i, s)); return n.length == 1 ? n[0] : new Dr(n); } 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--) wo(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--) wo(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(), wo(this.heap, 0); } } } function wo(r, e) { for (let t = r[e]; ; ) { let i = (e << 1) + 1; if (i >= r.length) break; let n = r[i]; if (i + 1 < r.length && n.compare(r[i + 1]) >= 0 && (n = r[i + 1], i++), t.compare(n) < 0) break; r[i] = t, r[e] = n, e = i; } } class ar { 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 = Dr.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) { yn(this.active, e), yn(this.activeTo, e), yn(this.activeRank, e), this.minActive = Wh(this.active, this.activeTo); } addActive(e) { let t = 0, { value: i, to: n, rank: s } = this.cursor; for (; t < this.activeRank.length && (s - this.activeRank[t] || n - this.activeTo[t]) > 0; ) t++; Sn(this.active, t, i), Sn(this.activeTo, t, n), Sn(this.activeRank, t, s), e && Sn(e, t, this.cursor.from), this.minActive = Wh(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 n = this.minActive; if (n > -1 && (this.activeTo[n] - this.cursor.from || this.active[n].endSide - this.cursor.startSide) < 0) { if (this.activeTo[n] > e) { this.to = this.activeTo[n], this.endSide = this.active[n].endSide; break; } this.removeActive(n), i && yn(i, n); } 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(i), 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 (i) { this.openStart = 0; for (let n = i.length - 1; n >= 0 && i[n] < e; n--) 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 Nh(r, e, t, i, n, s) { r.goto(e), t.goto(i); let o = i + n, l = i, a = i - e; for (; ; ) { let h = r.to + a - t.to, c = h || r.endSide - t.endSide, f = c < 0 ? r.to + a : t.to, u = Math.min(f, o); if (r.point || t.point ? r.point && t.point && (r.point == t.point || r.point.eq(t.point)) && Cl(r.activeForPoint(r.to), t.activeForPoint(t.to)) || s.comparePoint(l, u, r.point, t.point) : u > l && !Cl(r.active, t.active) && s.compareRange(l, u, r.active, t.active), f > o) break; (h || r.openEnd != t.openEnd) && s.boundChange && s.boundChange(f), l = f, c <= 0 && r.next(), c >= 0 && t.next(); } } function Cl(r, e) { if (r.length != e.length) return !1; for (let t = 0; t < r.length; t++) if (r[t] != e[t] && !r[t].eq(e[t])) return !1; return !0; } function yn(r, e) { for (let t = e, i = r.length - 1; t < i; t++) r[t] = r[t + 1]; r.pop(); } function Sn(r, e, t) { for (let i = r.length - 1; i >= e; i--) r[i + 1] = r[i]; r[e] = t; } function Wh(r, e) { let t = -1, i = 1e9; for (let n = 0; n < e.length; n++) (e[n] - i || r[n].endSide - r[t].endSide) < 0 && (t = n, i = e[n]); return t; } function lt(r, e, t = r.length) { let i = 0; for (let n = 0; n < t && n < r.length; ) r.charCodeAt(n) == 9 ? (i += e - i % e, n++) : (i++, n = De(r, n)); return i; } function Tl(r, e, t, i) { for (let n = 0, s = 0; ; ) { if (s >= e) return n; if (n == r.length) break; s += r.charCodeAt(n) == 9 ? t - s % t : 1, n = De(r, n); } return i === !0 ? -1 : r.length; } const Al = "ͼ", jh = typeof Symbol > "u" ? "__" + Al : Symbol.for(Al), Ml = typeof Symbol > "u" ? "__styleSet" + Math.floor(Math.random() * 1e8) : Symbol("styleSet"), Gh = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : {}; class Pt { // :: (Object