q-view
Version:
[Preview](https://q-hub-q-view.vercel.app/)
1,578 lines (1,573 loc) • 1.35 MB
JavaScript
var bm = Object.defineProperty;
var wm = (O, e, t) => e in O ? bm(O, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : O[e] = t;
var w = (O, e, t) => wm(O, typeof e != "symbol" ? e + "" : e, t);
import { property as te, customElement as rt, QuarkElement as b, createRef as xe, state as Be, watch as Tm } from "quarkc";
const vm = ":host{position:relative}:host .code-area{width:100%;display:block;background-color:#fff;border:1px solid #e8e8eb;min-height:100px}:host .code-area:focus-within select,:host .code-area:hover select{display:block}:host .code-area[readOnly=true] select{display:block}:host .code-area .cm-editor{font-family:Menlo,Monaco,Consolas,Andale Mono,lucida console,Courier New,monospace;font-size:16px}:host .code-area .cm-editor.cm-focused{outline:none}:host select{position:absolute;top:2px;right:2px;border:1px solid #e5e5e5;padding:2px;border-radius:0;outline:none;font-weight:700}@media (prefers-color-scheme: light){:root{color:#213547;background-color:#fff}a:hover{color:#747bff}button{background-color:#f9f9f9}}";
let bo = [], zu = [];
(() => {
let O = "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 < O.length; e++)
(e % 2 ? zu : bo).push(t = t + O[e]);
})();
function Ym(O) {
if (O < 768) return !1;
for (let e = 0, t = bo.length; ; ) {
let i = e + t >> 1;
if (O < bo[i]) t = i;
else if (O >= zu[i]) e = i + 1;
else return !0;
if (e == t) return !1;
}
}
function oh(O) {
return O >= 127462 && O <= 127487;
}
const ah = 8205;
function km(O, e, t = !0, i = !0) {
return (t ? Cu : Zm)(O, e, i);
}
function Cu(O, e, t) {
if (e == O.length) return e;
e && ju(O.charCodeAt(e)) && Gu(O.charCodeAt(e - 1)) && e--;
let i = vs(O, e);
for (e += lh(i); e < O.length; ) {
let r = vs(O, e);
if (i == ah || r == ah || t && Ym(r))
e += lh(r), i = r;
else if (oh(r)) {
let n = 0, s = e - 2;
for (; s >= 0 && oh(vs(O, s)); )
n++, s -= 2;
if (n % 2 == 0) break;
e += 2;
} else
break;
}
return e;
}
function Zm(O, e, t) {
for (; e > 0; ) {
let i = Cu(O, e - 2, t);
if (i < e) return i;
e--;
}
return 0;
}
function vs(O, e) {
let t = O.charCodeAt(e);
if (!Gu(t) || e + 1 == O.length) return t;
let i = O.charCodeAt(e + 1);
return ju(i) ? (t - 55296 << 10) + (i - 56320) + 65536 : t;
}
function ju(O) {
return O >= 56320 && O < 57344;
}
function Gu(O) {
return O >= 55296 && O < 56320;
}
function lh(O) {
return O < 65536 ? 1 : 2;
}
let H = class Eu {
/**
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] = NO(this, e, t);
let r = [];
return this.decompose(
0,
e,
r,
2
/* Open.To */
), i.length && i.decompose(
0,
i.length,
r,
3
/* Open.To */
), this.decompose(
t,
this.length,
r,
1
/* Open.From */
), Tt.from(r, 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] = NO(this, e, t);
let i = [];
return this.decompose(e, t, i, 0), Tt.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), r = new Ti(this), n = new Ti(e);
for (let s = t, o = t; ; ) {
if (r.next(s), n.next(s), s = 0, r.lineBreak != n.lineBreak || r.done != n.done || r.value != n.value)
return !1;
if (o += r.value.length, r.done || o >= 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 Ti(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 Au(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 r = this.line(e).from;
i = this.iterRange(r, Math.max(r, t == this.lines + 1 ? this.length : t <= 1 ? 0 : this.line(t - 1).to));
}
return new Iu(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] ? Eu.empty : e.length <= 32 ? new Qe(e) : Tt.from(Qe.split(e, []));
}
};
class Qe extends H {
constructor(e, t = Wm(e)) {
super(), this.text = e, this.length = t;
}
get lines() {
return this.text.length;
}
get children() {
return null;
}
lineInner(e, t, i, r) {
for (let n = 0; ; n++) {
let s = this.text[n], o = r + s.length;
if ((t ? i : o) >= e)
return new Rm(r, o, i, s);
r = o + 1, i++;
}
}
decompose(e, t, i, r) {
let n = e <= 0 && t >= this.length ? this : new Qe(hh(this.text, e, t), Math.min(t, this.length) - Math.max(0, e));
if (r & 1) {
let s = i.pop(), o = On(n.text, s.text.slice(), 0, n.length);
if (o.length <= 32)
i.push(new Qe(o, s.length + n.length));
else {
let a = o.length >> 1;
i.push(new Qe(o.slice(0, a)), new Qe(o.slice(a)));
}
} else
i.push(n);
}
replace(e, t, i) {
if (!(i instanceof Qe))
return super.replace(e, t, i);
[e, t] = NO(this, e, t);
let r = On(this.text, On(i.text, hh(this.text, 0, e)), t), n = this.length + i.length - (t - e);
return r.length <= 32 ? new Qe(r, n) : Tt.from(Qe.split(r, []), n);
}
sliceString(e, t = this.length, i = `
`) {
[e, t] = NO(this, e, t);
let r = "";
for (let n = 0, s = 0; n <= t && s < this.text.length; s++) {
let o = this.text[s], a = n + o.length;
n > e && s && (r += i), e < a && t > n && (r += o.slice(Math.max(0, e - n), t - n)), n = a + 1;
}
return r;
}
flatten(e) {
for (let t of this.text)
e.push(t);
}
scanIdentical() {
return 0;
}
static split(e, t) {
let i = [], r = -1;
for (let n of e)
i.push(n), r += n.length + 1, i.length == 32 && (t.push(new Qe(i, r)), i = [], r = -1);
return r > -1 && t.push(new Qe(i, r)), t;
}
}
class Tt extends H {
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, r) {
for (let n = 0; ; n++) {
let s = this.children[n], o = r + s.length, a = i + s.lines - 1;
if ((t ? a : o) >= e)
return s.lineInner(e, t, i, r);
r = o + 1, i = a + 1;
}
}
decompose(e, t, i, r) {
for (let n = 0, s = 0; s <= t && n < this.children.length; n++) {
let o = this.children[n], a = s + o.length;
if (e <= a && t >= s) {
let h = r & ((s <= e ? 1 : 0) | (a >= t ? 2 : 0));
s >= e && a <= t && !h ? i.push(o) : o.decompose(e - s, t - s, i, h);
}
s = a + 1;
}
}
replace(e, t, i) {
if ([e, t] = NO(this, e, t), i.lines < this.lines)
for (let r = 0, n = 0; r < this.children.length; r++) {
let s = this.children[r], o = n + s.length;
if (e >= n && t <= o) {
let a = s.replace(e - n, t - n, i), h = this.lines - s.lines + a.lines;
if (a.lines < h >> 4 && a.lines > h >> 6) {
let l = this.children.slice();
return l[r] = a, new Tt(l, this.length - (t - e) + i.length);
}
return super.replace(n, o, a);
}
n = o + 1;
}
return super.replace(e, t, i);
}
sliceString(e, t = this.length, i = `
`) {
[e, t] = NO(this, e, t);
let r = "";
for (let n = 0, s = 0; n < this.children.length && s <= t; n++) {
let o = this.children[n], a = s + o.length;
s > e && n && (r += i), e < a && t > s && (r += o.sliceString(e - s, t - s, i)), s = a + 1;
}
return r;
}
flatten(e) {
for (let t of this.children)
t.flatten(e);
}
scanIdentical(e, t) {
if (!(e instanceof Tt))
return 0;
let i = 0, [r, n, s, o] = t > 0 ? [0, 0, this.children.length, e.children.length] : [this.children.length - 1, e.children.length - 1, -1, -1];
for (; ; r += t, n += t) {
if (r == s || n == o)
return i;
let a = this.children[r], h = e.children[n];
if (a != h)
return i + a.scanIdentical(h, t);
i += a.length + 1;
}
}
static from(e, t = e.reduce((i, r) => i + r.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 Qe(d, t);
}
let r = Math.max(
32,
i >> 5
/* Tree.BranchShift */
), n = r << 1, s = r >> 1, o = [], a = 0, h = -1, l = [];
function c(d) {
let p;
if (d.lines > n && d instanceof Tt)
for (let Q of d.children)
c(Q);
else d.lines > s && (a > s || !a) ? (f(), o.push(d)) : d instanceof Qe && a && (p = l[l.length - 1]) instanceof Qe && d.lines + p.lines <= 32 ? (a += d.lines, h += d.length + 1, l[l.length - 1] = new Qe(p.text.concat(d.text), p.length + 1 + d.length)) : (a + d.lines > r && f(), a += d.lines, h += d.length + 1, l.push(d));
}
function f() {
a != 0 && (o.push(l.length == 1 ? l[0] : Tt.from(l, h)), h = -1, a = l.length = 0);
}
for (let d of e)
c(d);
return f(), o.length == 1 ? o[0] : new Tt(o, t);
}
}
H.empty = /* @__PURE__ */ new Qe([""], 0);
function Wm(O) {
let e = -1;
for (let t of O)
e += t.length + 1;
return e;
}
function On(O, e, t = 0, i = 1e9) {
for (let r = 0, n = 0, s = !0; n < O.length && r <= i; n++) {
let o = O[n], a = r + o.length;
a >= t && (a > i && (o = o.slice(0, i - r)), r < t && (o = o.slice(t - r)), s ? (e[e.length - 1] += o, s = !1) : e.push(o)), r = a + 1;
}
return e;
}
function hh(O, e, t) {
return On(O, [""], e, t);
}
class Ti {
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 Qe ? e.text.length : e.children.length) << 1];
}
nextInner(e, t) {
for (this.done = this.lineBreak = !1; ; ) {
let i = this.nodes.length - 1, r = this.nodes[i], n = this.offsets[i], s = n >> 1, o = r instanceof Qe ? r.text.length : r.children.length;
if (s == (t > 0 ? o : 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 ((n & 1) == (t > 0 ? 0 : 1)) {
if (this.offsets[i] += t, e == 0)
return this.lineBreak = !0, this.value = `
`, this;
e--;
} else if (r instanceof Qe) {
let a = r.text[s + (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 = r.children[s + (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 Qe ? 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 Au {
constructor(e, t, i) {
this.value = "", this.done = !1, this.cursor = new Ti(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: r } = this.cursor.next(e);
return this.pos += (r.length + e) * t, this.value = r.length <= i ? r : t < 0 ? r.slice(r.length - i) : r.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 Iu {
constructor(e) {
this.inner = e, this.afterBreak = !0, this.value = "", this.done = !1;
}
next(e = 0) {
let { done: t, lineBreak: i, value: r } = 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 = r, this.afterBreak = !1), this;
}
get lineBreak() {
return !1;
}
}
typeof Symbol < "u" && (H.prototype[Symbol.iterator] = function() {
return this.iter();
}, Ti.prototype[Symbol.iterator] = Au.prototype[Symbol.iterator] = Iu.prototype[Symbol.iterator] = function() {
return this;
});
let Rm = class {
/**
@internal
*/
constructor(e, t, i, r) {
this.from = e, this.to = t, this.number = i, this.text = r;
}
/**
The length of the line (not including any line break after it).
*/
get length() {
return this.to - this.from;
}
};
function NO(O, e, t) {
return e = Math.max(0, Math.min(O.length, e)), [e, Math.max(e, Math.min(O.length, t))];
}
function Ye(O, e, t = !0, i = !0) {
return km(O, e, t, i);
}
function qm(O) {
return O >= 56320 && O < 57344;
}
function Um(O) {
return O >= 55296 && O < 56320;
}
function Ae(O, e) {
let t = O.charCodeAt(e);
if (!Um(t) || e + 1 == O.length)
return t;
let i = O.charCodeAt(e + 1);
return qm(i) ? (t - 55296 << 10) + (i - 56320) + 65536 : t;
}
function Na(O) {
return O <= 65535 ? String.fromCharCode(O) : (O -= 65536, String.fromCharCode((O >> 10) + 55296, (O & 1023) + 56320));
}
function vt(O) {
return O < 65536 ? 1 : 2;
}
const wo = /\r\n?|\n/;
var ve = /* @__PURE__ */ function(O) {
return O[O.Simple = 0] = "Simple", O[O.TrackDel = 1] = "TrackDel", O[O.TrackBefore = 2] = "TrackBefore", O[O.TrackAfter = 3] = "TrackAfter", O;
}(ve || (ve = {}));
class Wt {
// 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, r = 0; t < this.sections.length; ) {
let n = this.sections[t++], s = this.sections[t++];
s < 0 ? (e(i, r, n), r += n) : r += s, i += n;
}
}
/**
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) {
To(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++], r = this.sections[t++];
r < 0 ? e.push(i, r) : e.push(r, i);
}
return new Wt(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 : Du(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 : vo(this, e, t);
}
mapPos(e, t = -1, i = ve.Simple) {
let r = 0, n = 0;
for (let s = 0; s < this.sections.length; ) {
let o = this.sections[s++], a = this.sections[s++], h = r + o;
if (a < 0) {
if (h > e)
return n + (e - r);
n += o;
} else {
if (i != ve.Simple && h >= e && (i == ve.TrackDel && r < e && h > e || i == ve.TrackBefore && r < e || i == ve.TrackAfter && h > e))
return null;
if (h > e || h == e && t < 0 && !o)
return e == r || t < 0 ? n : n + a;
n += a;
}
r = h;
}
if (e > r)
throw new RangeError(`Position ${e} is out of range for changeset of length ${r}`);
return n;
}
/**
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, r = 0; i < this.sections.length && r <= t; ) {
let n = this.sections[i++], s = this.sections[i++], o = r + n;
if (s >= 0 && r <= t && o >= e)
return r < e && o > t ? "cover" : !0;
r = o;
}
return !1;
}
/**
@internal
*/
toString() {
let e = "";
for (let t = 0; t < this.sections.length; ) {
let i = this.sections[t++], r = this.sections[t++];
e += (e ? " " : "") + i + (r >= 0 ? ":" + r : "");
}
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 Wt(e);
}
/**
@internal
*/
static create(e) {
return new Wt(e);
}
}
class Pe extends Wt {
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 To(this, (t, i, r, n, s) => e = e.replace(r, r + (i - t), s), !1), e;
}
mapDesc(e, t = !1) {
return vo(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 r = 0, n = 0; r < t.length; r += 2) {
let s = t[r], o = t[r + 1];
if (o >= 0) {
t[r] = o, t[r + 1] = s;
let a = r >> 1;
for (; i.length < a; )
i.push(H.empty);
i.push(s ? e.slice(n, n + s) : H.empty);
}
n += s;
}
return new Pe(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 : Du(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 : vo(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) {
To(this, e, t);
}
/**
Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
set.
*/
get desc() {
return Wt.create(this.sections);
}
/**
@internal
*/
filter(e) {
let t = [], i = [], r = [], n = new _i(this);
e: for (let s = 0, o = 0; ; ) {
let a = s == e.length ? 1e9 : e[s++];
for (; o < a || o == a && n.len == 0; ) {
if (n.done)
break e;
let l = Math.min(n.len, a - o);
Ue(r, l, -1);
let c = n.ins == -1 ? -1 : n.off == 0 ? n.ins : 0;
Ue(t, l, c), c > 0 && eO(i, t, n.text), n.forward(l), o += l;
}
let h = e[s++];
for (; o < h; ) {
if (n.done)
break e;
let l = Math.min(n.len, h - o);
Ue(t, l, -1), Ue(r, l, n.ins == -1 ? -1 : n.off == 0 ? n.ins : 0), n.forward(l), o += l;
}
}
return {
changes: new Pe(t, i),
filtered: Wt.create(r)
};
}
/**
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], r = this.sections[t + 1];
r < 0 ? e.push(i) : r == 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 r = [], n = [], s = 0, o = null;
function a(l = !1) {
if (!l && !r.length)
return;
s < t && Ue(r, t - s, -1);
let c = new Pe(r, n);
o = o ? o.compose(c.map(o)) : c, r = [], n = [], s = 0;
}
function h(l) {
if (Array.isArray(l))
for (let c of l)
h(c);
else if (l instanceof Pe) {
if (l.length != t)
throw new RangeError(`Mismatched change set length (got ${l.length}, expected ${t})`);
a(), o = o ? o.compose(l.map(o)) : l;
} else {
let { from: c, to: f = c, insert: d } = l;
if (c > f || c < 0 || f > t)
throw new RangeError(`Invalid change range ${c} to ${f} (in doc of length ${t})`);
let p = d ? typeof d == "string" ? H.of(d.split(i || wo)) : d : H.empty, Q = p.length;
if (c == f && Q == 0)
return;
c < s && a(), c > s && Ue(r, c - s, -1), Ue(r, f - c, Q), eO(n, r, p), s = f;
}
}
return h(e), a(!o), o;
}
/**
Create an empty changeset of the given length.
*/
static empty(e) {
return new Pe(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 r = 0; r < e.length; r++) {
let n = e[r];
if (typeof n == "number")
t.push(n, -1);
else {
if (!Array.isArray(n) || typeof n[0] != "number" || n.some((s, o) => o && typeof s != "string"))
throw new RangeError("Invalid JSON representation of ChangeSet");
if (n.length == 1)
t.push(n[0], 0);
else {
for (; i.length < r; )
i.push(H.empty);
i[r] = H.of(n.slice(1)), t.push(n[0], i[r].length);
}
}
}
return new Pe(t, i);
}
/**
@internal
*/
static createSet(e, t) {
return new Pe(e, t);
}
}
function Ue(O, e, t, i = !1) {
if (e == 0 && t <= 0)
return;
let r = O.length - 2;
r >= 0 && t <= 0 && t == O[r + 1] ? O[r] += e : r >= 0 && e == 0 && O[r] == 0 ? O[r + 1] += t : i ? (O[r] += e, O[r + 1] += t) : O.push(e, t);
}
function eO(O, e, t) {
if (t.length == 0)
return;
let i = e.length - 2 >> 1;
if (i < O.length)
O[O.length - 1] = O[O.length - 1].append(t);
else {
for (; O.length < i; )
O.push(H.empty);
O.push(t);
}
}
function To(O, e, t) {
let i = O.inserted;
for (let r = 0, n = 0, s = 0; s < O.sections.length; ) {
let o = O.sections[s++], a = O.sections[s++];
if (a < 0)
r += o, n += o;
else {
let h = r, l = n, c = H.empty;
for (; h += o, l += a, a && i && (c = c.append(i[s - 2 >> 1])), !(t || s == O.sections.length || O.sections[s + 1] < 0); )
o = O.sections[s++], a = O.sections[s++];
e(r, h, n, l, c), r = h, n = l;
}
}
}
function vo(O, e, t, i = !1) {
let r = [], n = i ? [] : null, s = new _i(O), o = new _i(e);
for (let a = -1; ; ) {
if (s.done && o.len || o.done && s.len)
throw new Error("Mismatched change set lengths");
if (s.ins == -1 && o.ins == -1) {
let h = Math.min(s.len, o.len);
Ue(r, h, -1), s.forward(h), o.forward(h);
} else if (o.ins >= 0 && (s.ins < 0 || a == s.i || s.off == 0 && (o.len < s.len || o.len == s.len && !t))) {
let h = o.len;
for (Ue(r, o.ins, -1); h; ) {
let l = Math.min(s.len, h);
s.ins >= 0 && a < s.i && s.len <= l && (Ue(r, 0, s.ins), n && eO(n, r, s.text), a = s.i), s.forward(l), h -= l;
}
o.next();
} else if (s.ins >= 0) {
let h = 0, l = s.len;
for (; l; )
if (o.ins == -1) {
let c = Math.min(l, o.len);
h += c, l -= c, o.forward(c);
} else if (o.ins == 0 && o.len < l)
l -= o.len, o.next();
else
break;
Ue(r, h, a < s.i ? s.ins : 0), n && a < s.i && eO(n, r, s.text), a = s.i, s.forward(s.len - l);
} else {
if (s.done && o.done)
return n ? Pe.createSet(r, n) : Wt.create(r);
throw new Error("Mismatched change set lengths");
}
}
}
function Du(O, e, t = !1) {
let i = [], r = t ? [] : null, n = new _i(O), s = new _i(e);
for (let o = !1; ; ) {
if (n.done && s.done)
return r ? Pe.createSet(i, r) : Wt.create(i);
if (n.ins == 0)
Ue(i, n.len, 0, o), n.next();
else if (s.len == 0 && !s.done)
Ue(i, 0, s.ins, o), r && eO(r, i, s.text), s.next();
else {
if (n.done || s.done)
throw new Error("Mismatched change set lengths");
{
let a = Math.min(n.len2, s.len), h = i.length;
if (n.ins == -1) {
let l = s.ins == -1 ? -1 : s.off ? 0 : s.ins;
Ue(i, a, l, o), r && l && eO(r, i, s.text);
} else s.ins == -1 ? (Ue(i, n.off ? 0 : n.len, a, o), r && eO(r, i, n.textBit(a))) : (Ue(i, n.off ? 0 : n.len, s.off ? 0 : s.ins, o), r && !s.off && eO(r, i, s.text));
o = (n.ins > a || s.ins >= 0 && s.len > a) && (o || i.length > h), n.forward2(a), s.forward(a);
}
}
}
}
class _i {
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 ? H.empty : e[t];
}
textBit(e) {
let { inserted: t } = this.set, i = this.i - 2 >> 1;
return i >= t.length && !e ? H.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 XO {
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, r;
return this.empty ? i = r = e.mapPos(this.from, t) : (i = e.mapPos(this.from, 1), r = e.mapPos(this.to, -1)), i == this.from && r == this.to ? this : new XO(i, r, this.flags);
}
/**
Extend this range to cover at least `from` to `to`.
*/
extend(e, t = e) {
if (e <= this.anchor && t >= this.anchor)
return T.range(e, t);
let i = Math.abs(e - this.anchor) > Math.abs(t - this.anchor) ? e : t;
return T.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 T.range(e.anchor, e.head);
}
/**
@internal
*/
static create(e, t, i) {
return new XO(e, t, i);
}
}
class T {
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 : T.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 T([this.main], 0);
}
/**
Extend this selection with an extra range.
*/
addRange(e, t = !0) {
return T.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, T.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 T(e.ranges.map((t) => XO.fromJSON(t)), e.main);
}
/**
Create a selection holding a single range.
*/
static single(e, t = e) {
return new T([T.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, r = 0; r < e.length; r++) {
let n = e[r];
if (n.empty ? n.from <= i : n.from < i)
return T.normalized(e.slice(), t);
i = n.to;
}
return new T(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, r) {
return XO.create(e, e, (t == 0 ? 0 : t < 0 ? 8 : 16) | (i == null ? 7 : Math.min(6, i)) | (r ?? 16777215) << 6);
}
/**
Create a selection range.
*/
static range(e, t, i, r) {
let n = (i ?? 16777215) << 6 | (r == null ? 7 : Math.min(6, r));
return t < e ? XO.create(t, e, 48 | n) : XO.create(e, t, (t > e ? 8 : 0) | n);
}
/**
@internal
*/
static normalized(e, t = 0) {
let i = e[t];
e.sort((r, n) => r.from - n.from), t = e.indexOf(i);
for (let r = 1; r < e.length; r++) {
let n = e[r], s = e[r - 1];
if (n.empty ? n.from <= s.to : n.from < s.to) {
let o = s.from, a = Math.max(n.to, s.to);
r <= t && t--, e.splice(--r, 2, n.anchor > n.head ? T.range(a, o) : T.range(o, a));
}
}
return new T(e, t);
}
}
function Mu(O, e) {
for (let t of O.ranges)
if (t.to > e)
throw new RangeError("Selection points outside of document");
}
let Ba = 0;
class V {
constructor(e, t, i, r, n) {
this.combine = e, this.compareInput = t, this.compare = i, this.isStatic = r, this.id = Ba++, this.default = e([]), this.extensions = typeof n == "function" ? n(this) : n;
}
/**
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 V(e.combine || ((t) => t), e.compareInput || ((t, i) => t === i), e.compare || (e.combine ? (t, i) => t === i : Fa), !!e.static, e.enables);
}
/**
Returns an extension that adds the given value to this facet.
*/
of(e) {
return new rn([], 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 rn(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 rn(e, this, 2, t);
}
from(e, t) {
return t || (t = (i) => i), this.compute([e], (i) => t(i.field(e)));
}
}
function Fa(O, e) {
return O == e || O.length == e.length && O.every((t, i) => t === e[i]);
}
class rn {
constructor(e, t, i, r) {
this.dependencies = e, this.facet = t, this.type = i, this.value = r, this.id = Ba++;
}
dynamicSlot(e) {
var t;
let i = this.value, r = this.facet.compareInput, n = this.id, s = e[n] >> 1, o = this.type == 2, a = !1, h = !1, l = [];
for (let c of this.dependencies)
c == "doc" ? a = !0 : c == "selection" ? h = !0 : (((t = e[c.id]) !== null && t !== void 0 ? t : 1) & 1) == 0 && l.push(e[c.id]);
return {
create(c) {
return c.values[s] = i(c), 1;
},
update(c, f) {
if (a && f.docChanged || h && (f.docChanged || f.selection) || Yo(c, l)) {
let d = i(c);
if (o ? !ch(d, c.values[s], r) : !r(d, c.values[s]))
return c.values[s] = d, 1;
}
return 0;
},
reconfigure: (c, f) => {
let d, p = f.config.address[n];
if (p != null) {
let Q = Pn(f, p);
if (this.dependencies.every((g) => g instanceof V ? f.facet(g) === c.facet(g) : g instanceof ye ? f.field(g, !1) == c.field(g, !1) : !0) || (o ? ch(d = i(c), Q, r) : r(d = i(c), Q)))
return c.values[s] = Q, 0;
} else
d = i(c);
return c.values[s] = d, 1;
}
};
}
}
function ch(O, e, t) {
if (O.length != e.length)
return !1;
for (let i = 0; i < O.length; i++)
if (!t(O[i], e[i]))
return !1;
return !0;
}
function Yo(O, e) {
let t = !1;
for (let i of e)
vi(O, i) & 1 && (t = !0);
return t;
}
function _m(O, e, t) {
let i = t.map((a) => O[a.id]), r = t.map((a) => a.type), n = i.filter((a) => !(a & 1)), s = O[e.id] >> 1;
function o(a) {
let h = [];
for (let l = 0; l < i.length; l++) {
let c = Pn(a, i[l]);
if (r[l] == 2)
for (let f of c)
h.push(f);
else
h.push(c);
}
return e.combine(h);
}
return {
create(a) {
for (let h of i)
vi(a, h);
return a.values[s] = o(a), 1;
},
update(a, h) {
if (!Yo(a, n))
return 0;
let l = o(a);
return e.compare(l, a.values[s]) ? 0 : (a.values[s] = l, 1);
},
reconfigure(a, h) {
let l = Yo(a, i), c = h.config.facets[e.id], f = h.facet(e);
if (c && !l && Fa(t, c))
return a.values[s] = f, 0;
let d = o(a);
return e.compare(d, f) ? (a.values[s] = f, 0) : (a.values[s] = d, 1);
}
};
}
const Tr = /* @__PURE__ */ V.define({ static: !0 });
class ye {
constructor(e, t, i, r, n) {
this.id = e, this.createF = t, this.updateF = i, this.compareF = r, this.spec = n, this.provides = void 0;
}
/**
Define a state field.
*/
static define(e) {
let t = new ye(Ba++, e.create, e.update, e.compare || ((i, r) => i === r), e);
return e.provide && (t.provides = e.provide(t)), t;
}
create(e) {
let t = e.facet(Tr).find((i) => i.field == this);
return ((t == null ? void 0 : t.create) || this.createF)(e);
}
/**
@internal
*/
slot(e) {
let t = e[this.id] >> 1;
return {
create: (i) => (i.values[t] = this.create(i), 1),
update: (i, r) => {
let n = i.values[t], s = this.updateF(n, r);
return this.compareF(n, s) ? 0 : (i.values[t] = s, 1);
},
reconfigure: (i, r) => {
let n = i.facet(Tr), s = r.facet(Tr), o;
return (o = n.find((a) => a.field == this)) && o != s.find((a) => a.field == this) ? (i.values[t] = o.create(i), 1) : r.config.address[this.id] != null ? (i.values[t] = r.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, Tr.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 SO = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
function hi(O) {
return (e) => new Lu(e, O);
}
const Lt = {
/**
The highest precedence level, for extensions that should end up
near the start of the precedence ordering.
*/
highest: /* @__PURE__ */ hi(SO.highest),
/**
A higher-than-default precedence, for extensions that should
come before those with default precedence.
*/
high: /* @__PURE__ */ hi(SO.high),
/**
The default precedence, which is also used for extensions
without an explicit precedence.
*/
default: /* @__PURE__ */ hi(SO.default),
/**
A lower-than-default precedence.
*/
low: /* @__PURE__ */ hi(SO.low),
/**
The lowest precedence level. Meant for things that should end up
near the end of the extension order.
*/
lowest: /* @__PURE__ */ hi(SO.lowest)
};
class Lu {
constructor(e, t) {
this.inner = e, this.prec = t;
}
}
class BO {
/**
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 ko(this, e);
}
/**
Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
reconfigures this compartment.
*/
reconfigure(e) {
return BO.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 ko {
constructor(e, t) {
this.compartment = e, this.inner = t;
}
}
class Sn {
constructor(e, t, i, r, n, s) {
for (this.base = e, this.compartments = t, this.dynamicSlots = i, this.address = r, this.staticValues = n, this.facets = s, 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 r = [], n = /* @__PURE__ */ Object.create(null), s = /* @__PURE__ */ new Map();
for (let f of Vm(e, t, s))
f instanceof ye ? r.push(f) : (n[f.facet.id] || (n[f.facet.id] = [])).push(f);
let o = /* @__PURE__ */ Object.create(null), a = [], h = [];
for (let f of r)
o[f.id] = h.length << 1, h.push((d) => f.slot(d));
let l = i == null ? void 0 : i.config.facets;
for (let f in n) {
let d = n[f], p = d[0].facet, Q = l && l[f] || [];
if (d.every(
(g) => g.type == 0
/* Provider.Static */
))
if (o[p.id] = a.length << 1 | 1, Fa(Q, d))
a.push(i.facet(p));
else {
let g = p.combine(d.map(($) => $.value));
a.push(i && p.compare(g, i.facet(p)) ? i.facet(p) : g);
}
else {
for (let g of d)
g.type == 0 ? (o[g.id] = a.length << 1 | 1, a.push(g.value)) : (o[g.id] = h.length << 1, h.push(($) => g.dynamicSlot($)));
o[p.id] = h.length << 1, h.push((g) => _m(g, p, d));
}
}
let c = h.map((f) => f(o));
return new Sn(e, s, c, o, a, n);
}
}
function Vm(O, e, t) {
let i = [[], [], [], [], []], r = /* @__PURE__ */ new Map();
function n(s, o) {
let a = r.get(s);
if (a != null) {
if (a <= o)
return;
let h = i[a].indexOf(s);
h > -1 && i[a].splice(h, 1), s instanceof ko && t.delete(s.compartment);
}
if (r.set(s, o), Array.isArray(s))
for (let h of s)
n(h, o);
else if (s instanceof ko) {
if (t.has(s.compartment))
throw new RangeError("Duplicate use of compartment in extensions");
let h = e.get(s.compartment) || s.inner;
t.set(s.compartment, h), n(h, o);
} else if (s instanceof Lu)
n(s.inner, s.prec);
else if (s instanceof ye)
i[o].push(s), s.provides && n(s.provides, o);
else if (s instanceof rn)
i[o].push(s), s.facet.extensions && n(s.facet.extensions, SO.default);
else {
let h = s.extension;
if (!h)
throw new Error(`Unrecognized extension value in extension set (${s}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
n(h, o);
}
}
return n(O, SO.default), i.reduce((s, o) => s.concat(o));
}
function vi(O, e) {
if (e & 1)
return 2;
let t = e >> 1, i = O.status[t];
if (i == 4)
throw new Error("Cyclic dependency between fields and/or facets");
if (i & 2)
return i;
O.status[t] = 4;
let r = O.computeSlot(O, O.config.dynamicSlots[t]);
return O.status[t] = 2 | r;
}
function Pn(O, e) {
return e & 1 ? O.config.staticValues[e >> 1] : O.values[e >> 1];
}
const Nu = /* @__PURE__ */ V.define(), Zo = /* @__PURE__ */ V.define({
combine: (O) => O.some((e) => e),
static: !0
}), Bu = /* @__PURE__ */ V.define({
combine: (O) => O.length ? O[0] : void 0,
static: !0
}), Fu = /* @__PURE__ */ V.define(), Hu = /* @__PURE__ */ V.define(), Ju = /* @__PURE__ */ V.define(), Ku = /* @__PURE__ */ V.define({
combine: (O) => O.length ? O[0] : !1
});
class Nt {
/**
@internal
*/
constructor(e, t) {
this.type = e, this.value = t;
}
/**
Define a new type of annotation.
*/
static define() {
return new zm();
}
}
class zm {
/**
Create an instance of this annotation.
*/
of(e) {
return new Nt(this, e);
}
}
class Cm {
/**
@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 A(this, e);
}
}
class A {
/**
@internal
*/
constructor(e, t) {
this.type = e, this.value = t;
}
/**
Map this effect through a position mapping. Will return
`undefined` when that ends up d