import { _ as Nn, J as qn } from "./index-B-D9UuLO.js";
import { useState as ae, useLayoutEffect as Vn, useEffect as ce, forwardRef as Hn, useRef as Un, useImperativeHandle as zn, useCallback as Gn } from "react";
import { E as m, b as x, Q as Pt, U as Ft, X as Ae, S as et, T as Ve, F as ge, e as Re, Y as tt, j as Nt, i as nt, Z as te, _, d as F, $ as Kn, a0 as $n, A as rt, r as $e, n as Jn, a1 as Je, m as qt, a2 as it, a3 as _n, a4 as Vt, P as Qn, c as jn, a as Yn, V as Ht, D as v, a5 as ue, a6 as Ut, f as Zn, C as T, a7 as b, a8 as Xn, a9 as er, W as tr, aa as nr, ab as rr, ac as ir, ad as or, ae as sr, af as lr, ag as ar, ah as cr, ai as zt, aj as hr, ak as ur, al as fr, am as dr, k as Gt, an as mr, ao as gr, v as f, ap as pr } from "./index-BnzttJ4w.js";
import { aq as Xo, ar as es, as as ts, at as ns, au as rs, av as is, aw as os, ax as ss, M as ls, ay as as, az as cs, R as hs, h as us, aA as fs, aB as ds, aC as ms, aD as gs, aE as ps, g as ys, aF as ks, aG as xs, aH as Ss, aI as bs, aJ as Cs, aK as vs, aL as Ms, l as As, s as Ls } from "./index-BnzttJ4w.js";
import { a as yr, b as kr, d as xr, e as Sr } from "./index-l6kvDx-m.js";
import { jsx as br } from "react/jsx-runtime";
const Cr = (t) => {
  let { state: e } = t, r = e.doc.lineAt(e.selection.main.from), n = st(t.state, r.from);
  return n.line ? vr(t) : n.block ? Ar(t) : !1;
};
function ot(t, e) {
  return ({ state: r, dispatch: n }) => {
    if (r.readOnly)
      return !1;
    let i = t(e, r);
    return i ? (n(r.update(i)), !0) : !1;
  };
}
const vr = /* @__PURE__ */ ot(
  Dr,
  0
  /* CommentOption.Toggle */
), Mr = /* @__PURE__ */ ot(
  Kt,
  0
  /* CommentOption.Toggle */
), Ar = /* @__PURE__ */ ot(
  (t, e) => Kt(t, e, Br(e)),
  0
  /* CommentOption.Toggle */
);
function st(t, e) {
  let r = t.languageDataAt("commentTokens", e, 1);
  return r.length ? r[0] : {};
}
const he = 50;
function Lr(t, { open: e, close: r }, n, i) {
  let o = t.sliceDoc(n - he, n), s = t.sliceDoc(i, i + he), l = /\s*$/.exec(o)[0].length, a = /^\s*/.exec(s)[0].length, c = o.length - l;
  if (o.slice(c - e.length, c) == e && s.slice(a, a + r.length) == r)
    return {
      open: { pos: n - l, margin: l && 1 },
      close: { pos: i + a, margin: a && 1 }
    };
  let h, u;
  i - n <= 2 * he ? h = u = t.sliceDoc(n, i) : (h = t.sliceDoc(n, n + he), u = t.sliceDoc(i - he, i));
  let d = /^\s*/.exec(h)[0].length, g = /\s*$/.exec(u)[0].length, p = u.length - g - r.length;
  return h.slice(d, d + e.length) == e && u.slice(p, p + r.length) == r ? {
    open: {
      pos: n + d + e.length,
      margin: /\s/.test(h.charAt(d + e.length)) ? 1 : 0
    },
    close: {
      pos: i - g - r.length,
      margin: /\s/.test(u.charAt(p - 1)) ? 1 : 0
    }
  } : null;
}
function Br(t) {
  let e = [];
  for (let r of t.selection.ranges) {
    let n = t.doc.lineAt(r.from), i = r.to <= n.to ? n : t.doc.lineAt(r.to);
    i.from > n.from && i.from == r.to && (i = r.to == n.to + 1 ? n : t.doc.lineAt(r.to - 1));
    let o = e.length - 1;
    o >= 0 && e[o].to > n.from ? e[o].to = i.to : e.push({ from: n.from + /^\s*/.exec(n.text)[0].length, to: i.to });
  }
  return e;
}
function Kt(t, e, r = e.selection.ranges) {
  let n = r.map((o) => st(e, o.from).block);
  if (!n.every((o) => o))
    return null;
  let i = r.map((o, s) => Lr(e, n[s], o.from, o.to));
  if (t != 2 && !i.every((o) => o))
    return { changes: e.changes(r.map((o, s) => i[s] ? [] : [{ from: o.from, insert: n[s].open + " " }, { from: o.to, insert: " " + n[s].close }])) };
  if (t != 1 && i.some((o) => o)) {
    let o = [];
    for (let s = 0, l; s < i.length; s++)
      if (l = i[s]) {
        let a = n[s], { open: c, close: h } = l;
        o.push({ from: c.pos - a.open.length, to: c.pos + c.margin }, { from: h.pos - h.margin, to: h.pos + a.close.length });
      }
    return { changes: o };
  }
  return null;
}
function Dr(t, e, r = e.selection.ranges) {
  let n = [], i = -1;
  e: for (let { from: o, to: s } of r) {
    let l = n.length, a = 1e9, c;
    for (let h = o; h <= s; ) {
      let u = e.doc.lineAt(h);
      if (c == null && (c = st(e, u.from).line, !c))
        continue e;
      if (u.from > i && (o == s || s > u.from)) {
        i = u.from;
        let d = /^\s*/.exec(u.text)[0].length, g = d == u.length, p = u.text.slice(d, d + c.length) == c ? d : -1;
        d < u.text.length && d < a && (a = d), n.push({ line: u, comment: p, token: c, indent: d, empty: g, single: !1 });
      }
      h = u.to + 1;
    }
    if (a < 1e9)
      for (let h = l; h < n.length; h++)
        n[h].indent < n[h].line.text.length && (n[h].indent = a);
    n.length == l + 1 && (n[l].single = !0);
  }
  if (t != 2 && n.some((o) => o.comment < 0 && (!o.empty || o.single))) {
    let o = [];
    for (let { line: l, token: a, indent: c, empty: h, single: u } of n)
      (u || !h) && o.push({ from: l.from + c, insert: a + " " });
    let s = e.changes(o);
    return { changes: s, selection: e.selection.map(s, 1) };
  } else if (t != 1 && n.some((o) => o.comment >= 0)) {
    let o = [];
    for (let { line: s, comment: l, token: a } of n)
      if (l >= 0) {
        let c = s.from + l, h = c + a.length;
        s.text[h - s.from] == " " && h++, o.push({ from: c, to: h });
      }
    return { changes: o };
  }
  return null;
}
const _e = /* @__PURE__ */ rt.define(), Er = /* @__PURE__ */ rt.define(), Tr = /* @__PURE__ */ ge.define(), $t = /* @__PURE__ */ ge.define({
  combine(t) {
    return Re(t, {
      minDepth: 100,
      newGroupDelay: 500,
      joinToEvent: (e, r) => r
    }, {
      minDepth: Math.max,
      newGroupDelay: Math.min,
      joinToEvent: (e, r) => (n, i) => e(n, i) || r(n, i)
    });
  }
}), Jt = /* @__PURE__ */ et.define({
  create() {
    return P.empty;
  },
  update(t, e) {
    let r = e.state.facet($t), n = e.annotation(_e);
    if (n) {
      let a = L.fromTransaction(e, n.selection), c = n.side, h = c == 0 ? t.undone : t.done;
      return a ? h = Le(h, h.length, r.minDepth, a) : h = jt(h, e.startState.selection), new P(c == 0 ? n.rest : h, c == 0 ? h : n.rest);
    }
    let i = e.annotation(Er);
    if ((i == "full" || i == "before") && (t = t.isolate()), e.annotation(Ve.addToHistory) === !1)
      return e.changes.empty ? t : t.addMapping(e.changes.desc);
    let o = L.fromTransaction(e), s = e.annotation(Ve.time), l = e.annotation(Ve.userEvent);
    return o ? t = t.addChanges(o, s, l, r, e) : e.selection && (t = t.addSelection(e.startState.selection, s, l, r.newGroupDelay)), (i == "full" || i == "after") && (t = t.isolate()), t;
  },
  toJSON(t) {
    return { done: t.done.map((e) => e.toJSON()), undone: t.undone.map((e) => e.toJSON()) };
  },
  fromJSON(t) {
    return new P(t.done.map(L.fromJSON), t.undone.map(L.fromJSON));
  }
});
function wr(t = {}) {
  return [
    Jt,
    $t.of(t),
    x.domEventHandlers({
      beforeinput(e, r) {
        let n = e.inputType == "historyUndo" ? _t : e.inputType == "historyRedo" ? Qe : null;
        return n ? (e.preventDefault(), n(r)) : !1;
      }
    })
  ];
}
function Ie(t, e) {
  return function({ state: r, dispatch: n }) {
    if (!e && r.readOnly)
      return !1;
    let i = r.field(Jt, !1);
    if (!i)
      return !1;
    let o = i.pop(t, r, e);
    return o ? (n(o), !0) : !1;
  };
}
const _t = /* @__PURE__ */ Ie(0, !1), Qe = /* @__PURE__ */ Ie(1, !1), Rr = /* @__PURE__ */ Ie(0, !0), Ir = /* @__PURE__ */ Ie(1, !0);
class L {
  constructor(e, r, n, i, o) {
    this.changes = e, this.effects = r, this.mapped = n, this.startSelection = i, this.selectionsAfter = o;
  }
  setSelAfter(e) {
    return new L(this.changes, this.effects, this.mapped, this.startSelection, e);
  }
  toJSON() {
    var e, r, n;
    return {
      changes: (e = this.changes) === null || e === void 0 ? void 0 : e.toJSON(),
      mapped: (r = this.mapped) === null || r === void 0 ? void 0 : r.toJSON(),
      startSelection: (n = this.startSelection) === null || n === void 0 ? void 0 : n.toJSON(),
      selectionsAfter: this.selectionsAfter.map((i) => i.toJSON())
    };
  }
  static fromJSON(e) {
    return new L(e.changes && Kn.fromJSON(e.changes), [], e.mapped && $n.fromJSON(e.mapped), e.startSelection && m.fromJSON(e.startSelection), e.selectionsAfter.map(m.fromJSON));
  }
  // This does not check `addToHistory` and such, it assumes the
  // transaction needs to be converted to an item. Returns null when
  // there are no changes or effects in the transaction.
  static fromTransaction(e, r) {
    let n = w;
    for (let i of e.startState.facet(Tr)) {
      let o = i(e);
      o.length && (n = n.concat(o));
    }
    return !n.length && e.changes.empty ? null : new L(e.changes.invert(e.startState.doc), n, void 0, r || e.startState.selection, w);
  }
  static selection(e) {
    return new L(void 0, w, void 0, void 0, e);
  }
}
function Le(t, e, r, n) {
  let i = e + 1 > r + 20 ? e - r - 1 : 0, o = t.slice(i, e);
  return o.push(n), o;
}
function Or(t, e) {
  let r = [], n = !1;
  return t.iterChangedRanges((i, o) => r.push(i, o)), e.iterChangedRanges((i, o, s, l) => {
    for (let a = 0; a < r.length; ) {
      let c = r[a++], h = r[a++];
      l >= c && s <= h && (n = !0);
    }
  }), n;
}
function Wr(t, e) {
  return t.ranges.length == e.ranges.length && t.ranges.filter((r, n) => r.empty != e.ranges[n].empty).length === 0;
}
function Qt(t, e) {
  return t.length ? e.length ? t.concat(e) : t : e;
}
const w = [], Pr = 200;
function jt(t, e) {
  if (t.length) {
    let r = t[t.length - 1], n = r.selectionsAfter.slice(Math.max(0, r.selectionsAfter.length - Pr));
    return n.length && n[n.length - 1].eq(e) ? t : (n.push(e), Le(t, t.length - 1, 1e9, r.setSelAfter(n)));
  } else
    return [L.selection([e])];
}
function Fr(t) {
  let e = t[t.length - 1], r = t.slice();
  return r[t.length - 1] = e.setSelAfter(e.selectionsAfter.slice(0, e.selectionsAfter.length - 1)), r;
}
function He(t, e) {
  if (!t.length)
    return t;
  let r = t.length, n = w;
  for (; r; ) {
    let i = Nr(t[r - 1], e, n);
    if (i.changes && !i.changes.empty || i.effects.length) {
      let o = t.slice(0, r);
      return o[r - 1] = i, o;
    } else
      e = i.mapped, r--, n = i.selectionsAfter;
  }
  return n.length ? [L.selection(n)] : w;
}
function Nr(t, e, r) {
  let n = Qt(t.selectionsAfter.length ? t.selectionsAfter.map((l) => l.map(e)) : w, r);
  if (!t.changes)
    return L.selection(n);
  let i = t.changes.map(e), o = e.mapDesc(t.changes, !0), s = t.mapped ? t.mapped.composeDesc(o) : o;
  return new L(i, F.mapEffects(t.effects, e), s, t.startSelection.map(o), n);
}
const qr = /^(input\.type|delete)($|\.)/;
class P {
  constructor(e, r, n = 0, i = void 0) {
    this.done = e, this.undone = r, this.prevTime = n, this.prevUserEvent = i;
  }
  isolate() {
    return this.prevTime ? new P(this.done, this.undone) : this;
  }
  addChanges(e, r, n, i, o) {
    let s = this.done, l = s[s.length - 1];
    return l && l.changes && !l.changes.empty && e.changes && (!n || qr.test(n)) && (!l.selectionsAfter.length && r - this.prevTime < i.newGroupDelay && i.joinToEvent(o, Or(l.changes, e.changes)) || // For compose (but not compose.start) events, always join with previous event
    n == "input.type.compose") ? s = Le(s, s.length - 1, i.minDepth, new L(e.changes.compose(l.changes), Qt(F.mapEffects(e.effects, l.changes), l.effects), l.mapped, l.startSelection, w)) : s = Le(s, s.length, i.minDepth, e), new P(s, w, r, n);
  }
  addSelection(e, r, n, i) {
    let o = this.done.length ? this.done[this.done.length - 1].selectionsAfter : w;
    return o.length > 0 && r - this.prevTime < i && n == this.prevUserEvent && n && /^select($|\.)/.test(n) && Wr(o[o.length - 1], e) ? this : new P(jt(this.done, e), this.undone, r, n);
  }
  addMapping(e) {
    return new P(He(this.done, e), He(this.undone, e), this.prevTime, this.prevUserEvent);
  }
  pop(e, r, n) {
    let i = e == 0 ? this.done : this.undone;
    if (i.length == 0)
      return null;
    let o = i[i.length - 1], s = o.selectionsAfter[0] || (o.startSelection ? o.startSelection.map(o.changes.invertedDesc, 1) : r.selection);
    if (n && o.selectionsAfter.length)
      return r.update({
        selection: o.selectionsAfter[o.selectionsAfter.length - 1],
        annotations: _e.of({ side: e, rest: Fr(i), selection: s }),
        userEvent: e == 0 ? "select.undo" : "select.redo",
        scrollIntoView: !0
      });
    if (o.changes) {
      let l = i.length == 1 ? w : i.slice(0, i.length - 1);
      return o.mapped && (l = He(l, o.mapped)), r.update({
        changes: o.changes,
        selection: o.startSelection,
        effects: o.effects,
        annotations: _e.of({ side: e, rest: l, selection: s }),
        filter: !1,
        userEvent: e == 0 ? "undo" : "redo",
        scrollIntoView: !0
      });
    } else
      return null;
  }
}
P.empty = /* @__PURE__ */ new P(w, w);
const Vr = [
  { key: "Mod-z", run: _t, preventDefault: !0 },
  { key: "Mod-y", mac: "Mod-Shift-z", run: Qe, preventDefault: !0 },
  { linux: "Ctrl-Shift-z", run: Qe, preventDefault: !0 },
  { key: "Mod-u", run: Rr, preventDefault: !0 },
  { key: "Alt-u", mac: "Mod-Shift-u", run: Ir, preventDefault: !0 }
];
function ie(t, e) {
  return m.create(t.ranges.map(e), t.mainIndex);
}
function I(t, e) {
  return t.update({ selection: e, scrollIntoView: !0, userEvent: "select" });
}
function O({ state: t, dispatch: e }, r) {
  let n = ie(t.selection, r);
  return n.eq(t.selection, !0) ? !1 : (e(I(t, n)), !0);
}
function Oe(t, e) {
  return m.cursor(e ? t.to : t.from);
}
function Yt(t, e) {
  return O(t, (r) => r.empty ? t.moveByChar(r, e) : Oe(r, e));
}
function M(t) {
  return t.textDirectionAt(t.state.selection.main.head) == Jn.LTR;
}
const Zt = (t) => Yt(t, !M(t)), Xt = (t) => Yt(t, M(t));
function en(t, e) {
  return O(t, (r) => r.empty ? t.moveByGroup(r, e) : Oe(r, e));
}
const Hr = (t) => en(t, !M(t)), Ur = (t) => en(t, M(t));
function zr(t, e, r) {
  if (e.type.prop(r))
    return !0;
  let n = e.to - e.from;
  return n && (n > 2 || /[^\s,.;:]/.test(t.sliceDoc(e.from, e.to))) || e.firstChild;
}
function We(t, e, r) {
  let n = nt(t).resolveInner(e.head), i = r ? $e.closedBy : $e.openedBy;
  for (let a = e.head; ; ) {
    let c = r ? n.childAfter(a) : n.childBefore(a);
    if (!c)
      break;
    zr(t, c, i) ? n = c : a = r ? c.to : c.from;
  }
  let o = n.type.prop(i), s, l;
  return o && (s = r ? te(t, n.from, 1) : te(t, n.to, -1)) && s.matched ? l = r ? s.end.to : s.end.from : l = r ? n.to : n.from, m.cursor(l, r ? -1 : 1);
}
const Gr = (t) => O(t, (e) => We(t.state, e, !M(t))), Kr = (t) => O(t, (e) => We(t.state, e, M(t)));
function tn(t, e) {
  return O(t, (r) => {
    if (!r.empty)
      return Oe(r, e);
    let n = t.moveVertically(r, e);
    return n.head != r.head ? n : t.moveToLineBoundary(r, e);
  });
}
const nn = (t) => tn(t, !1), rn = (t) => tn(t, !0);
function on(t) {
  let e = t.scrollDOM.clientHeight < t.scrollDOM.scrollHeight - 2, r = 0, n = 0, i;
  if (e) {
    for (let o of t.state.facet(x.scrollMargins)) {
      let s = o(t);
      s != null && s.top && (r = Math.max(s == null ? void 0 : s.top, r)), s != null && s.bottom && (n = Math.max(s == null ? void 0 : s.bottom, n));
    }
    i = t.scrollDOM.clientHeight - r - n;
  } else
    i = (t.dom.ownerDocument.defaultView || window).innerHeight;
  return {
    marginTop: r,
    marginBottom: n,
    selfScroll: e,
    height: Math.max(t.defaultLineHeight, i - 5)
  };
}
function sn(t, e) {
  let r = on(t), { state: n } = t, i = ie(n.selection, (s) => s.empty ? t.moveVertically(s, e, r.height) : Oe(s, e));
  if (i.eq(n.selection))
    return !1;
  let o;
  if (r.selfScroll) {
    let s = t.coordsAtPos(n.selection.main.head), l = t.scrollDOM.getBoundingClientRect(), a = l.top + r.marginTop, c = l.bottom - r.marginBottom;
    s && s.top > a && s.bottom < c && (o = x.scrollIntoView(i.main.head, { y: "start", yMargin: s.top - a }));
  }
  return t.dispatch(I(n, i), { effects: o }), !0;
}
const dt = (t) => sn(t, !1), je = (t) => sn(t, !0);
function U(t, e, r) {
  let n = t.lineBlockAt(e.head), i = t.moveToLineBoundary(e, r);
  if (i.head == e.head && i.head != (r ? n.to : n.from) && (i = t.moveToLineBoundary(e, r, !1)), !r && i.head == n.from && n.length) {
    let o = /^\s*/.exec(t.state.sliceDoc(n.from, Math.min(n.from + 100, n.to)))[0].length;
    o && e.head != n.from + o && (i = m.cursor(n.from + o));
  }
  return i;
}
const $r = (t) => O(t, (e) => U(t, e, !0)), Jr = (t) => O(t, (e) => U(t, e, !1)), _r = (t) => O(t, (e) => U(t, e, !M(t))), Qr = (t) => O(t, (e) => U(t, e, M(t))), jr = (t) => O(t, (e) => m.cursor(t.lineBlockAt(e.head).from, 1)), Yr = (t) => O(t, (e) => m.cursor(t.lineBlockAt(e.head).to, -1));
function Zr(t, e, r) {
  let n = !1, i = ie(t.selection, (o) => {
    let s = te(t, o.head, -1) || te(t, o.head, 1) || o.head > 0 && te(t, o.head - 1, 1) || o.head < t.doc.length && te(t, o.head + 1, -1);
    if (!s || !s.end)
      return o;
    n = !0;
    let l = s.start.from == o.head ? s.end.to : s.end.from;
    return m.cursor(l);
  });
  return n ? (e(I(t, i)), !0) : !1;
}
const Xr = ({ state: t, dispatch: e }) => Zr(t, e);
function R(t, e) {
  let r = ie(t.state.selection, (n) => {
    let i = e(n);
    return m.range(n.anchor, i.head, i.goalColumn, i.bidiLevel || void 0, i.assoc);
  });
  return r.eq(t.state.selection) ? !1 : (t.dispatch(I(t.state, r)), !0);
}
function ln(t, e) {
  return R(t, (r) => t.moveByChar(r, e));
}
const an = (t) => ln(t, !M(t)), cn = (t) => ln(t, M(t));
function hn(t, e) {
  return R(t, (r) => t.moveByGroup(r, e));
}
const ei = (t) => hn(t, !M(t)), ti = (t) => hn(t, M(t)), ni = (t) => R(t, (e) => We(t.state, e, !M(t))), ri = (t) => R(t, (e) => We(t.state, e, M(t)));
function un(t, e) {
  return R(t, (r) => t.moveVertically(r, e));
}
const fn = (t) => un(t, !1), dn = (t) => un(t, !0);
function mn(t, e) {
  return R(t, (r) => t.moveVertically(r, e, on(t).height));
}
const mt = (t) => mn(t, !1), gt = (t) => mn(t, !0), ii = (t) => R(t, (e) => U(t, e, !0)), oi = (t) => R(t, (e) => U(t, e, !1)), si = (t) => R(t, (e) => U(t, e, !M(t))), li = (t) => R(t, (e) => U(t, e, M(t))), ai = (t) => R(t, (e) => m.cursor(t.lineBlockAt(e.head).from)), ci = (t) => R(t, (e) => m.cursor(t.lineBlockAt(e.head).to)), pt = ({ state: t, dispatch: e }) => (e(I(t, { anchor: 0 })), !0), yt = ({ state: t, dispatch: e }) => (e(I(t, { anchor: t.doc.length })), !0), kt = ({ state: t, dispatch: e }) => (e(I(t, { anchor: t.selection.main.anchor, head: 0 })), !0), xt = ({ state: t, dispatch: e }) => (e(I(t, { anchor: t.selection.main.anchor, head: t.doc.length })), !0), hi = ({ state: t, dispatch: e }) => (e(t.update({ selection: { anchor: 0, head: t.doc.length }, userEvent: "select" })), !0), ui = ({ state: t, dispatch: e }) => {
  let r = Pe(t).map(({ from: n, to: i }) => m.range(n, Math.min(i + 1, t.doc.length)));
  return e(t.update({ selection: m.create(r), userEvent: "select" })), !0;
}, fi = ({ state: t, dispatch: e }) => {
  let r = ie(t.selection, (n) => {
    let i = nt(t), o = i.resolveStack(n.from, 1);
    if (n.empty) {
      let s = i.resolveStack(n.from, -1);
      s.node.from >= o.node.from && s.node.to <= o.node.to && (o = s);
    }
    for (let s = o; s; s = s.next) {
      let { node: l } = s;
      if ((l.from < n.from && l.to >= n.to || l.to > n.to && l.from <= n.from) && s.next)
        return m.range(l.to, l.from);
    }
    return n;
  });
  return r.eq(t.selection) ? !1 : (e(I(t, r)), !0);
};
function gn(t, e) {
  let { state: r } = t, n = r.selection, i = r.selection.ranges.slice();
  for (let o of r.selection.ranges) {
    let s = r.doc.lineAt(o.head);
    if (e ? s.to < t.state.doc.length : s.from > 0)
      for (let l = o; ; ) {
        let a = t.moveVertically(l, e);
        if (a.head < s.from || a.head > s.to) {
          i.some((c) => c.head == a.head) || i.push(a);
          break;
        } else {
          if (a.head == l.head)
            break;
          l = a;
        }
      }
  }
  return i.length == n.ranges.length ? !1 : (t.dispatch(I(r, m.create(i, i.length - 1))), !0);
}
const di = (t) => gn(t, !1), mi = (t) => gn(t, !0), gi = ({ state: t, dispatch: e }) => {
  let r = t.selection, n = null;
  return r.ranges.length > 1 ? n = m.create([r.main]) : r.main.empty || (n = m.create([m.cursor(r.main.head)])), n ? (e(I(t, n)), !0) : !1;
};
function pe(t, e) {
  if (t.state.readOnly)
    return !1;
  let r = "delete.selection", { state: n } = t, i = n.changeByRange((o) => {
    let { from: s, to: l } = o;
    if (s == l) {
      let a = e(o);
      a < s ? (r = "delete.backward", a = Se(t, a, !1)) : a > s && (r = "delete.forward", a = Se(t, a, !0)), s = Math.min(s, a), l = Math.max(l, a);
    } else
      s = Se(t, s, !1), l = Se(t, l, !0);
    return s == l ? { range: o } : { changes: { from: s, to: l }, range: m.cursor(s, s < o.head ? -1 : 1) };
  });
  return i.changes.empty ? !1 : (t.dispatch(n.update(i, {
    scrollIntoView: !0,
    userEvent: r,
    effects: r == "delete.selection" ? x.announce.of(n.phrase("Selection deleted")) : void 0
  })), !0);
}
function Se(t, e, r) {
  if (t instanceof x)
    for (let n of t.state.facet(x.atomicRanges).map((i) => i(t)))
      n.between(e, e, (i, o) => {
        i < e && o > e && (e = r ? o : i);
      });
  return e;
}
const pn = (t, e, r) => pe(t, (n) => {
  let i = n.from, { state: o } = t, s = o.doc.lineAt(i), l, a;
  if (r && !e && i > s.from && i < s.from + 200 && !/[^ \t]/.test(l = s.text.slice(0, i - s.from))) {
    if (l[l.length - 1] == "	")
      return i - 1;
    let c = tt(l, o.tabSize), h = c % Je(o) || Je(o);
    for (let u = 0; u < h && l[l.length - 1 - u] == " "; u++)
      i--;
    a = i;
  } else
    a = _(s.text, i - s.from, e, e) + s.from, a == i && s.number != (e ? o.doc.lines : 1) ? a += e ? 1 : -1 : !e && /[\ufe00-\ufe0f]/.test(s.text.slice(a - s.from, i - s.from)) && (a = _(s.text, a - s.from, !1, !1) + s.from);
  return a;
}), Ye = (t) => pn(t, !1, !0), yn = (t) => pn(t, !0, !1), kn = (t, e) => pe(t, (r) => {
  let n = r.head, { state: i } = t, o = i.doc.lineAt(n), s = i.charCategorizer(n);
  for (let l = null; ; ) {
    if (n == (e ? o.to : o.from)) {
      n == r.head && o.number != (e ? i.doc.lines : 1) && (n += e ? 1 : -1);
      break;
    }
    let a = _(o.text, n - o.from, e) + o.from, c = o.text.slice(Math.min(n, a) - o.from, Math.max(n, a) - o.from), h = s(c);
    if (l != null && h != l)
      break;
    (c != " " || n != r.head) && (l = h), n = a;
  }
  return n;
}), xn = (t) => kn(t, !1), pi = (t) => kn(t, !0), yi = (t) => pe(t, (e) => {
  let r = t.lineBlockAt(e.head).to;
  return e.head < r ? r : Math.min(t.state.doc.length, e.head + 1);
}), ki = (t) => pe(t, (e) => {
  let r = t.moveToLineBoundary(e, !1).head;
  return e.head > r ? r : Math.max(0, e.head - 1);
}), xi = (t) => pe(t, (e) => {
  let r = t.moveToLineBoundary(e, !0).head;
  return e.head < r ? r : Math.min(t.state.doc.length, e.head + 1);
}), Si = ({ state: t, dispatch: e }) => {
  if (t.readOnly)
    return !1;
  let r = t.changeByRange((n) => ({
    changes: { from: n.from, to: n.to, insert: Nt.of(["", ""]) },
    range: m.cursor(n.from)
  }));
  return e(t.update(r, { scrollIntoView: !0, userEvent: "input" })), !0;
}, bi = ({ state: t, dispatch: e }) => {
  if (t.readOnly)
    return !1;
  let r = t.changeByRange((n) => {
    if (!n.empty || n.from == 0 || n.from == t.doc.length)
      return { range: n };
    let i = n.from, o = t.doc.lineAt(i), s = i == o.from ? i - 1 : _(o.text, i - o.from, !1) + o.from, l = i == o.to ? i + 1 : _(o.text, i - o.from, !0) + o.from;
    return {
      changes: { from: s, to: l, insert: t.doc.slice(i, l).append(t.doc.slice(s, i)) },
      range: m.cursor(l)
    };
  });
  return r.changes.empty ? !1 : (e(t.update(r, { scrollIntoView: !0, userEvent: "move.character" })), !0);
};
function Pe(t) {
  let e = [], r = -1;
  for (let n of t.selection.ranges) {
    let i = t.doc.lineAt(n.from), o = t.doc.lineAt(n.to);
    if (!n.empty && n.to == o.from && (o = t.doc.lineAt(n.to - 1)), r >= i.number) {
      let s = e[e.length - 1];
      s.to = o.to, s.ranges.push(n);
    } else
      e.push({ from: i.from, to: o.to, ranges: [n] });
    r = o.number + 1;
  }
  return e;
}
function Sn(t, e, r) {
  if (t.readOnly)
    return !1;
  let n = [], i = [];
  for (let o of Pe(t)) {
    if (r ? o.to == t.doc.length : o.from == 0)
      continue;
    let s = t.doc.lineAt(r ? o.to + 1 : o.from - 1), l = s.length + 1;
    if (r) {
      n.push({ from: o.to, to: s.to }, { from: o.from, insert: s.text + t.lineBreak });
      for (let a of o.ranges)
        i.push(m.range(Math.min(t.doc.length, a.anchor + l), Math.min(t.doc.length, a.head + l)));
    } else {
      n.push({ from: s.from, to: o.from }, { from: o.to, insert: t.lineBreak + s.text });
      for (let a of o.ranges)
        i.push(m.range(a.anchor - l, a.head - l));
    }
  }
  return n.length ? (e(t.update({
    changes: n,
    scrollIntoView: !0,
    selection: m.create(i, t.selection.mainIndex),
    userEvent: "move.line"
  })), !0) : !1;
}
const Ci = ({ state: t, dispatch: e }) => Sn(t, e, !1), vi = ({ state: t, dispatch: e }) => Sn(t, e, !0);
function bn(t, e, r) {
  if (t.readOnly)
    return !1;
  let n = [];
  for (let o of Pe(t))
    r ? n.push({ from: o.from, insert: t.doc.slice(o.from, o.to) + t.lineBreak }) : n.push({ from: o.to, insert: t.lineBreak + t.doc.slice(o.from, o.to) });
  let i = t.changes(n);
  return e(t.update({
    changes: i,
    selection: t.selection.map(i, r ? 1 : -1),
    scrollIntoView: !0,
    userEvent: "input.copyline"
  })), !0;
}
const Mi = ({ state: t, dispatch: e }) => bn(t, e, !1), Ai = ({ state: t, dispatch: e }) => bn(t, e, !0), Li = (t) => {
  if (t.state.readOnly)
    return !1;
  let { state: e } = t, r = e.changes(Pe(e).map(({ from: i, to: o }) => (i > 0 ? i-- : o < e.doc.length && o++, { from: i, to: o }))), n = ie(e.selection, (i) => {
    let o;
    if (t.lineWrapping) {
      let s = t.lineBlockAt(i.head), l = t.coordsAtPos(i.head, i.assoc || 1);
      l && (o = s.bottom + t.documentTop - l.bottom + t.defaultLineHeight / 2);
    }
    return t.moveVertically(i, !0, o);
  }).map(r);
  return t.dispatch({ changes: r, selection: n, scrollIntoView: !0, userEvent: "delete.line" }), !0;
};
function Bi(t, e) {
  if (/\(\)|\[\]|\{\}/.test(t.sliceDoc(e - 1, e + 1)))
    return { from: e, to: e };
  let r = nt(t).resolveInner(e), n = r.childBefore(e), i = r.childAfter(e), o;
  return n && i && n.to <= e && i.from >= e && (o = n.type.prop($e.closedBy)) && o.indexOf(i.name) > -1 && t.doc.lineAt(n.to).from == t.doc.lineAt(i.from).from && !/\S/.test(t.sliceDoc(n.to, i.from)) ? { from: n.to, to: i.from } : null;
}
const St = /* @__PURE__ */ Cn(!1), Di = /* @__PURE__ */ Cn(!0);
function Cn(t) {
  return ({ state: e, dispatch: r }) => {
    if (e.readOnly)
      return !1;
    let n = e.changeByRange((i) => {
      let { from: o, to: s } = i, l = e.doc.lineAt(o), a = !t && o == s && Bi(e, o);
      t && (o = s = (s <= l.to ? l : e.doc.lineAt(s)).to);
      let c = new Pt(e, { simulateBreak: o, simulateDoubleBreak: !!a }), h = Ft(c, o);
      for (h == null && (h = tt(/^\s*/.exec(e.doc.lineAt(o).text)[0], e.tabSize)); s < l.to && /\s/.test(l.text[s - l.from]); )
        s++;
      a ? { from: o, to: s } = a : o > l.from && o < l.from + 100 && !/\S/.test(l.text.slice(0, o)) && (o = l.from);
      let u = ["", Ae(e, h)];
      return a && u.push(Ae(e, c.lineIndent(l.from, -1))), {
        changes: { from: o, to: s, insert: Nt.of(u) },
        range: m.cursor(o + 1 + u[1].length)
      };
    });
    return r(e.update(n, { scrollIntoView: !0, userEvent: "input" })), !0;
  };
}
function lt(t, e) {
  let r = -1;
  return t.changeByRange((n) => {
    let i = [];
    for (let s = n.from; s <= n.to; ) {
      let l = t.doc.lineAt(s);
      l.number > r && (n.empty || n.to > l.from) && (e(l, i, n), r = l.number), s = l.to + 1;
    }
    let o = t.changes(i);
    return {
      changes: i,
      range: m.range(o.mapPos(n.anchor, 1), o.mapPos(n.head, 1))
    };
  });
}
const Ei = ({ state: t, dispatch: e }) => {
  if (t.readOnly)
    return !1;
  let r = /* @__PURE__ */ Object.create(null), n = new Pt(t, { overrideIndentation: (o) => {
    let s = r[o];
    return s ?? -1;
  } }), i = lt(t, (o, s, l) => {
    let a = Ft(n, o.from);
    if (a == null)
      return;
    /\S/.test(o.text) || (a = 0);
    let c = /^\s*/.exec(o.text)[0], h = Ae(t, a);
    (c != h || l.from < o.from + c.length) && (r[o.from] = a, s.push({ from: o.from, to: o.from + c.length, insert: h }));
  });
  return i.changes.empty || e(t.update(i, { userEvent: "indent" })), !0;
}, vn = ({ state: t, dispatch: e }) => t.readOnly ? !1 : (e(t.update(lt(t, (r, n) => {
  n.push({ from: r.from, insert: t.facet(qt) });
}), { userEvent: "input.indent" })), !0), Mn = ({ state: t, dispatch: e }) => t.readOnly ? !1 : (e(t.update(lt(t, (r, n) => {
  let i = /^\s*/.exec(r.text)[0];
  if (!i)
    return;
  let o = tt(i, t.tabSize), s = 0, l = Ae(t, Math.max(0, o - Je(t)));
  for (; s < i.length && s < l.length && i.charCodeAt(s) == l.charCodeAt(s); )
    s++;
  n.push({ from: r.from + s, to: r.from + i.length, insert: l.slice(s) });
}), { userEvent: "delete.dedent" })), !0), Ti = (t) => (t.setTabFocusMode(), !0), wi = [
  { key: "Ctrl-b", run: Zt, shift: an, preventDefault: !0 },
  { key: "Ctrl-f", run: Xt, shift: cn },
  { key: "Ctrl-p", run: nn, shift: fn },
  { key: "Ctrl-n", run: rn, shift: dn },
  { key: "Ctrl-a", run: jr, shift: ai },
  { key: "Ctrl-e", run: Yr, shift: ci },
  { key: "Ctrl-d", run: yn },
  { key: "Ctrl-h", run: Ye },
  { key: "Ctrl-k", run: yi },
  { key: "Ctrl-Alt-h", run: xn },
  { key: "Ctrl-o", run: Si },
  { key: "Ctrl-t", run: bi },
  { key: "Ctrl-v", run: je }
], Ri = /* @__PURE__ */ [
  { key: "ArrowLeft", run: Zt, shift: an, preventDefault: !0 },
  { key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: Hr, shift: ei, preventDefault: !0 },
  { mac: "Cmd-ArrowLeft", run: _r, shift: si, preventDefault: !0 },
  { key: "ArrowRight", run: Xt, shift: cn, preventDefault: !0 },
  { key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: Ur, shift: ti, preventDefault: !0 },
  { mac: "Cmd-ArrowRight", run: Qr, shift: li, preventDefault: !0 },
  { key: "ArrowUp", run: nn, shift: fn, preventDefault: !0 },
  { mac: "Cmd-ArrowUp", run: pt, shift: kt },
  { mac: "Ctrl-ArrowUp", run: dt, shift: mt },
  { key: "ArrowDown", run: rn, shift: dn, preventDefault: !0 },
  { mac: "Cmd-ArrowDown", run: yt, shift: xt },
  { mac: "Ctrl-ArrowDown", run: je, shift: gt },
  { key: "PageUp", run: dt, shift: mt },
  { key: "PageDown", run: je, shift: gt },
  { key: "Home", run: Jr, shift: oi, preventDefault: !0 },
  { key: "Mod-Home", run: pt, shift: kt },
  { key: "End", run: $r, shift: ii, preventDefault: !0 },
  { key: "Mod-End", run: yt, shift: xt },
  { key: "Enter", run: St, shift: St },
  { key: "Mod-a", run: hi },
  { key: "Backspace", run: Ye, shift: Ye, preventDefault: !0 },
  { key: "Delete", run: yn, preventDefault: !0 },
  { key: "Mod-Backspace", mac: "Alt-Backspace", run: xn, preventDefault: !0 },
  { key: "Mod-Delete", mac: "Alt-Delete", run: pi, preventDefault: !0 },
  { mac: "Mod-Backspace", run: ki, preventDefault: !0 },
  { mac: "Mod-Delete", run: xi, preventDefault: !0 }
].concat(/* @__PURE__ */ wi.map((t) => ({ mac: t.key, run: t.run, shift: t.shift }))), Ii = /* @__PURE__ */ [
  { key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: Gr, shift: ni },
  { key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: Kr, shift: ri },
  { key: "Alt-ArrowUp", run: Ci },
  { key: "Shift-Alt-ArrowUp", run: Mi },
  { key: "Alt-ArrowDown", run: vi },
  { key: "Shift-Alt-ArrowDown", run: Ai },
  { key: "Mod-Alt-ArrowUp", run: di },
  { key: "Mod-Alt-ArrowDown", run: mi },
  { key: "Escape", run: gi },
  { key: "Mod-Enter", run: Di },
  { key: "Alt-l", mac: "Ctrl-l", run: ui },
  { key: "Mod-i", run: fi, preventDefault: !0 },
  { key: "Mod-[", run: Mn },
  { key: "Mod-]", run: vn },
  { key: "Mod-Alt-\\", run: Ei },
  { key: "Shift-Mod-k", run: Li },
  { key: "Shift-Mod-\\", run: Xr },
  { key: "Mod-/", run: Cr },
  { key: "Alt-A", run: Mr },
  { key: "Ctrl-m", mac: "Shift-Alt-m", run: Ti }
].concat(Ri), Oi = { key: "Tab", run: vn, shift: Mn }, bt = typeof String.prototype.normalize == "function" ? (t) => t.normalize("NFKD") : (t) => t;
class re {
  /**
  Create a text cursor. The query is the search string, `from` to
  `to` provides the region to search.
  
  When `normalize` is given, it will be called, on both the query
  string and the content it is matched against, before comparing.
  You can, for example, create a case-insensitive search by
  passing `s => s.toLowerCase()`.
  
  Text is always normalized with
  [`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
  (when supported).
  */
  constructor(e, r, n = 0, i = e.length, o, s) {
    this.test = s, this.value = { from: 0, to: 0, precise: !1 }, this.done = !1, this.matches = [], this.buffer = "", this.bufferPos = 0, this.iter = e.iterRange(n, i), this.bufferStart = n, this.normalize = o ? (l) => o(bt(l)) : bt, this.query = this.normalize(r);
  }
  peek() {
    if (this.bufferPos == this.buffer.length) {
      if (this.bufferStart += this.buffer.length, this.iter.next(), this.iter.done)
        return -1;
      this.bufferPos = 0, this.buffer = this.iter.value;
    }
    return jn(this.buffer, this.bufferPos);
  }
  /**
  Look for the next match. Updates the iterator's
  [`value`](https://codemirror.net/6/docs/ref/#search.SearchCursor.value) and
  [`done`](https://codemirror.net/6/docs/ref/#search.SearchCursor.done) properties. Should be called
  at least once before using the cursor.
  */
  next() {
    for (; this.matches.length; )
      this.matches.pop();
    return this.nextOverlapping();
  }
  /**
  The `next` method will ignore matches that partially overlap a
  previous match. This method behaves like `next`, but includes
  such matches.
  */
  nextOverlapping() {
    for (; ; ) {
      let e = this.peek();
      if (e < 0)
        return this.done = !0, this;
      let r = Zn(e), n = this.bufferStart + this.bufferPos;
      this.bufferPos += Yn(e);
      let i = this.normalize(r);
      if (i.length)
        for (let o = 0, s = n, l = !0; ; o++) {
          let a = i.charCodeAt(o), c = this.match(a, s, l, this.bufferPos + this.bufferStart, o == i.length - 1);
          if (c)
            return this.value = c, this;
          if (o == i.length - 1)
            break;
          l && o < r.length && r.charCodeAt(o) == a ? s++ : l = !1;
        }
    }
  }
  match(e, r, n, i, o) {
    let s = null;
    for (let l = 0; l < this.matches.length; ) {
      let a = this.matches[l], c = !1;
      this.query.charCodeAt(a.index) == e && (a.index == this.query.length - 1 ? s = { from: a.from, to: i, precise: o && a.precise } : (a.index++, c = !0)), c ? l++ : this.matches.splice(l, 1);
    }
    return this.query.charCodeAt(0) == e && (this.query.length == 1 ? s = { from: r, to: i, precise: n && o } : this.matches.push({ from: r, index: 1, precise: n })), s && this.test && !this.test(s.from, s.to, this.buffer, this.bufferStart) && (s = null), s;
  }
}
typeof Symbol < "u" && (re.prototype[Symbol.iterator] = function() {
  return this;
});
const An = { from: -1, to: -1, match: /* @__PURE__ */ /.*/.exec(""), precise: !0 }, at = "gm" + (/x/.unicode == null ? "" : "u");
class Ln {
  /**
  Create a cursor that will search the given range in the given
  document. `query` should be the raw pattern (as you'd pass it to
  `new RegExp`).
  */
  constructor(e, r, n, i = 0, o = e.length) {
    if (this.text = e, this.to = o, this.curLine = "", this.done = !1, this.value = An, /\\[sWDnr]|\n|\r|\[\^/.test(r))
      return new Bn(e, r, n, i, o);
    this.re = new RegExp(r, at + (n != null && n.ignoreCase ? "i" : "")), this.test = n == null ? void 0 : n.test, this.iter = e.iter();
    let s = e.lineAt(i);
    this.curLineStart = s.from, this.matchPos = Be(e, i), this.getLine(this.curLineStart);
  }
  getLine(e) {
    this.iter.next(e), this.iter.lineBreak ? this.curLine = "" : (this.curLine = this.iter.value, this.curLineStart + this.curLine.length > this.to && (this.curLine = this.curLine.slice(0, this.to - this.curLineStart)), this.iter.next());
  }
  nextLine() {
    this.curLineStart = this.curLineStart + this.curLine.length + 1, this.curLineStart > this.to ? this.curLine = "" : this.getLine(0);
  }
  /**
  Move to the next match, if there is one.
  */
  next() {
    for (let e = this.matchPos - this.curLineStart; ; ) {
      this.re.lastIndex = e;
      let r = this.matchPos <= this.to && this.re.exec(this.curLine);
      if (r) {
        let n = this.curLineStart + r.index, i = n + r[0].length;
        if (this.matchPos = Be(this.text, i + (n == i ? 1 : 0)), n == this.curLineStart + this.curLine.length && this.nextLine(), (n < i || n > this.value.to) && (!this.test || this.test(n, i, r)))
          return this.value = { from: n, to: i, precise: !0, match: r }, this;
        e = this.matchPos - this.curLineStart;
      } else if (this.curLineStart + this.curLine.length < this.to)
        this.nextLine(), e = 0;
      else
        return this.done = !0, this;
    }
  }
}
const Ue = /* @__PURE__ */ new WeakMap();
class ne {
  constructor(e, r) {
    this.from = e, this.text = r;
  }
  get to() {
    return this.from + this.text.length;
  }
  static get(e, r, n) {
    let i = Ue.get(e);
    if (!i || i.from >= n || i.to <= r) {
      let l = new ne(r, e.sliceString(r, n));
      return Ue.set(e, l), l;
    }
    if (i.from == r && i.to == n)
      return i;
    let { text: o, from: s } = i;
    return s > r && (o = e.sliceString(r, s) + o, s = r), i.to < n && (o += e.sliceString(i.to, n)), Ue.set(e, new ne(s, o)), new ne(r, o.slice(r - s, n - s));
  }
}
class Bn {
  constructor(e, r, n, i, o) {
    this.text = e, this.to = o, this.done = !1, this.value = An, this.matchPos = Be(e, i), this.re = new RegExp(r, at + (n != null && n.ignoreCase ? "i" : "")), this.test = n == null ? void 0 : n.test, this.flat = ne.get(e, i, this.chunkEnd(
      i + 5e3
      /* Chunk.Base */
    ));
  }
  chunkEnd(e) {
    return e >= this.to ? this.to : this.text.lineAt(e).to;
  }
  next() {
    for (; ; ) {
      let e = this.re.lastIndex = this.matchPos - this.flat.from, r = this.re.exec(this.flat.text);
      if (r && !r[0] && r.index == e && (this.re.lastIndex = e + 1, r = this.re.exec(this.flat.text)), r) {
        let n = this.flat.from + r.index, i = n + r[0].length;
        if ((this.flat.to >= this.to || r.index + r[0].length <= this.flat.text.length - 10) && (!this.test || this.test(n, i, r)))
          return this.value = { from: n, to: i, precise: !0, match: r }, this.matchPos = Be(this.text, i + (n == i ? 1 : 0)), this;
      }
      if (this.flat.to == this.to)
        return this.done = !0, this;
      this.flat = ne.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
    }
  }
}
typeof Symbol < "u" && (Ln.prototype[Symbol.iterator] = Bn.prototype[Symbol.iterator] = function() {
  return this;
});
function Wi(t) {
  try {
    return new RegExp(t, at), !0;
  } catch {
    return !1;
  }
}
function Be(t, e) {
  if (e >= t.length)
    return e;
  let r = t.lineAt(e), n;
  for (; e < r.to && (n = r.text.charCodeAt(e - r.from)) >= 56320 && n < 57344; )
    e++;
  return e;
}
const Pi = (t) => {
  let { state: e } = t, r = String(e.doc.lineAt(t.state.selection.main.head).number), { close: n, result: i } = _n(t, {
    label: e.phrase("Go to line"),
    input: { type: "text", name: "line", value: r },
    focus: !0,
    submitLabel: e.phrase("go")
  });
  return i.then((o) => {
    let s = o && /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(o.elements.line.value);
    if (!s) {
      t.dispatch({ effects: n });
      return;
    }
    let l = e.doc.lineAt(e.selection.main.head), [, a, c, h, u] = s, d = h ? +h.slice(1) : 0, g = c ? +c : l.number;
    if (c && u) {
      let k = g / 100;
      a && (k = k * (a == "-" ? -1 : 1) + l.number / e.doc.lines), g = Math.round(e.doc.lines * k);
    } else c && a && (g = g * (a == "-" ? -1 : 1) + l.number);
    let p = e.doc.line(Math.max(1, Math.min(e.doc.lines, g))), S = m.cursor(p.from + Math.max(0, Math.min(d, p.length)));
    t.dispatch({
      effects: [n, x.scrollIntoView(S.from, { y: "center" })],
      selection: S
    });
  }), !0;
}, Fi = {
  highlightWordAroundCursor: !1,
  minSelectionLength: 1,
  maxMatches: 100,
  wholeWords: !1
}, Ni = /* @__PURE__ */ ge.define({
  combine(t) {
    return Re(t, Fi, {
      highlightWordAroundCursor: (e, r) => e || r,
      minSelectionLength: Math.min,
      maxMatches: Math.min
    });
  }
});
function qi(t) {
  return [Gi, zi];
}
const Vi = /* @__PURE__ */ v.mark({ class: "cm-selectionMatch" }), Hi = /* @__PURE__ */ v.mark({ class: "cm-selectionMatch cm-selectionMatch-main" });
function Ct(t, e, r, n) {
  return (r == 0 || t(e.sliceDoc(r - 1, r)) != T.Word) && (n == e.doc.length || t(e.sliceDoc(n, n + 1)) != T.Word);
}
function Ui(t, e, r, n) {
  return t(e.sliceDoc(r, r + 1)) == T.Word && t(e.sliceDoc(n - 1, n)) == T.Word;
}
const zi = /* @__PURE__ */ Ht.fromClass(class {
  constructor(t) {
    this.decorations = this.getDeco(t);
  }
  update(t) {
    (t.selectionSet || t.docChanged || t.viewportChanged) && (this.decorations = this.getDeco(t.view));
  }
  getDeco(t) {
    let e = t.state.facet(Ni), { state: r } = t, n = r.selection;
    if (n.ranges.length > 1)
      return v.none;
    let i = n.main, o, s = null;
    if (i.empty) {
      if (!e.highlightWordAroundCursor)
        return v.none;
      let a = r.wordAt(i.head);
      if (!a)
        return v.none;
      s = r.charCategorizer(i.head), o = r.sliceDoc(a.from, a.to);
    } else {
      let a = i.to - i.from;
      if (a < e.minSelectionLength || a > 200)
        return v.none;
      if (e.wholeWords) {
        if (o = r.sliceDoc(i.from, i.to), s = r.charCategorizer(i.head), !(Ct(s, r, i.from, i.to) && Ui(s, r, i.from, i.to)))
          return v.none;
      } else if (o = r.sliceDoc(i.from, i.to), !o)
        return v.none;
    }
    let l = [];
    for (let a of t.visibleRanges) {
      let c = new re(r.doc, o, a.from, a.to);
      for (; !c.next().done; ) {
        let { from: h, to: u } = c.value;
        if ((!s || Ct(s, r, h, u)) && (i.empty && h <= i.from && u >= i.to ? l.push(Hi.range(h, u)) : (h >= i.to || u <= i.from) && l.push(Vi.range(h, u)), l.length > e.maxMatches))
          return v.none;
      }
    }
    return v.set(l);
  }
}, {
  decorations: (t) => t.decorations
}), Gi = /* @__PURE__ */ x.baseTheme({
  ".cm-selectionMatch": { backgroundColor: "#99ff7780" },
  ".cm-searchMatch .cm-selectionMatch": { backgroundColor: "transparent" }
}), Ki = ({ state: t, dispatch: e }) => {
  let { selection: r } = t, n = m.create(r.ranges.map((i) => t.wordAt(i.head) || m.cursor(i.head)), r.mainIndex);
  return n.eq(r) ? !1 : (e(t.update({ selection: n })), !0);
};
function $i(t, e) {
  let { main: r, ranges: n } = t.selection, i = t.wordAt(r.head), o = i && i.from == r.from && i.to == r.to;
  for (let s = !1, l = new re(t.doc, e, n[n.length - 1].to); ; )
    if (l.next(), l.done) {
      if (s)
        return null;
      l = new re(t.doc, e, 0, Math.max(0, n[n.length - 1].from - 1)), s = !0;
    } else {
      if (s && n.some((a) => a.from == l.value.from))
        continue;
      if (o) {
        let a = t.wordAt(l.value.from);
        if (!a || a.from != l.value.from || a.to != l.value.to)
          continue;
      }
      return l.value;
    }
}
const Ji = ({ state: t, dispatch: e }) => {
  let { ranges: r } = t.selection;
  if (r.some((o) => o.from === o.to))
    return Ki({ state: t, dispatch: e });
  let n = t.sliceDoc(r[0].from, r[0].to);
  if (t.selection.ranges.some((o) => t.sliceDoc(o.from, o.to) != n))
    return !1;
  let i = $i(t, n);
  return i ? (e(t.update({
    selection: t.selection.addRange(m.range(i.from, i.to), !1),
    effects: x.scrollIntoView(i.to)
  })), !0) : !1;
}, oe = /* @__PURE__ */ ge.define({
  combine(t) {
    return Re(t, {
      top: !1,
      caseSensitive: !1,
      literal: !1,
      regexp: !1,
      wholeWord: !1,
      createPanel: (e) => new lo(e),
      scrollToMatch: (e) => x.scrollIntoView(e)
    });
  }
});
class Dn {
  /**
  Create a query object.
  */
  constructor(e) {
    this.search = e.search, this.caseSensitive = !!e.caseSensitive, this.literal = !!e.literal, this.regexp = !!e.regexp, this.replace = e.replace || "", this.valid = !!this.search && (!this.regexp || Wi(this.search)), this.unquoted = this.unquote(this.search), this.wholeWord = !!e.wholeWord, this.test = e.test;
  }
  /**
  @internal
  */
  unquote(e) {
    return this.literal ? e : e.replace(/\\([nrt\\])/g, (r, n) => n == "n" ? `
` : n == "r" ? "\r" : n == "t" ? "	" : "\\");
  }
  /**
  Compare this query to another query.
  */
  eq(e) {
    return this.search == e.search && this.replace == e.replace && this.caseSensitive == e.caseSensitive && this.regexp == e.regexp && this.wholeWord == e.wholeWord && this.test == e.test;
  }
  /**
  @internal
  */
  create() {
    return this.regexp ? new Xi(this) : new ji(this);
  }
  /**
  Get a search cursor for this query, searching through the given
  range in the given state.
  */
  getCursor(e, r = 0, n) {
    let i = e.doc ? e : ue.create({ doc: e });
    return n == null && (n = i.doc.length), this.regexp ? ee(this, i, r, n) : X(this, i, r, n);
  }
}
class En {
  constructor(e) {
    this.spec = e;
  }
}
function _i(t, e, r) {
  return (n, i, o, s) => {
    if (r && !r(n, i, o, s))
      return !1;
    let l = n >= s && i <= s + o.length ? o.slice(n - s, i - s) : e.doc.sliceString(n, i);
    return t(l, e, n, i);
  };
}
function X(t, e, r, n) {
  let i;
  return t.wholeWord && (i = Qi(e.doc, e.charCategorizer(e.selection.main.head))), t.test && (i = _i(t.test, e, i)), new re(e.doc, t.unquoted, r, n, t.caseSensitive ? void 0 : (o) => o.toLowerCase(), i);
}
function Qi(t, e) {
  return (r, n, i, o) => ((o > r || o + i.length < n) && (o = Math.max(0, r - 2), i = t.sliceString(o, Math.min(t.length, n + 2))), (e(De(i, r - o)) != T.Word || e(Ee(i, r - o)) != T.Word) && (e(Ee(i, n - o)) != T.Word || e(De(i, n - o)) != T.Word));
}
class ji extends En {
  constructor(e) {
    super(e);
  }
  nextMatch(e, r, n) {
    let i = X(this.spec, e, n, e.doc.length).nextOverlapping();
    if (i.done) {
      let o = Math.min(e.doc.length, r + this.spec.unquoted.length);
      i = X(this.spec, e, 0, o).nextOverlapping();
    }
    return i.done || i.value.from == r && i.value.to == n ? null : i.value;
  }
  // Searching in reverse is, rather than implementing an inverted search
  // cursor, done by scanning chunk after chunk forward.
  prevMatchInRange(e, r, n) {
    for (let i = n; ; ) {
      let o = Math.max(r, i - 1e4 - this.spec.unquoted.length), s = X(this.spec, e, o, i), l = null;
      for (; !s.nextOverlapping().done; )
        l = s.value;
      if (l)
        return l;
      if (o == r)
        return null;
      i -= 1e4;
    }
  }
  prevMatch(e, r, n) {
    let i = this.prevMatchInRange(e, 0, r);
    return i || (i = this.prevMatchInRange(e, Math.max(0, n - this.spec.unquoted.length), e.doc.length)), i && (i.from != r || i.to != n) ? i : null;
  }
  getReplacement(e) {
    return this.spec.unquote(this.spec.replace);
  }
  matchAll(e, r) {
    let n = X(this.spec, e, 0, e.doc.length), i = [];
    for (; !n.next().done; ) {
      if (i.length >= r)
        return null;
      i.push(n.value);
    }
    return i;
  }
  highlight(e, r, n, i) {
    let o = X(this.spec, e, Math.max(0, r - this.spec.unquoted.length), Math.min(n + this.spec.unquoted.length, e.doc.length));
    for (; !o.next().done; )
      i(o.value.from, o.value.to);
  }
}
function Yi(t, e, r) {
  return (n, i, o) => (!r || r(n, i, o)) && t(o[0], e, n, i);
}
function ee(t, e, r, n) {
  let i;
  return t.wholeWord && (i = Zi(e.charCategorizer(e.selection.main.head))), t.test && (i = Yi(t.test, e, i)), new Ln(e.doc, t.search, { ignoreCase: !t.caseSensitive, test: i }, r, n);
}
function De(t, e) {
  return t.slice(_(t, e, !1), e);
}
function Ee(t, e) {
  return t.slice(e, _(t, e));
}
function Zi(t) {
  return (e, r, n) => !n[0].length || (t(De(n.input, n.index)) != T.Word || t(Ee(n.input, n.index)) != T.Word) && (t(Ee(n.input, n.index + n[0].length)) != T.Word || t(De(n.input, n.index + n[0].length)) != T.Word);
}
class Xi extends En {
  nextMatch(e, r, n) {
    let i = ee(this.spec, e, n, e.doc.length).next();
    return i.done && (i = ee(this.spec, e, 0, r).next()), i.done ? null : i.value;
  }
  prevMatchInRange(e, r, n) {
    for (let i = 1; ; i++) {
      let o = Math.max(
        r,
        n - i * 1e4
        /* FindPrev.ChunkSize */
      ), s = ee(this.spec, e, o, n), l = null;
      for (; !s.next().done; )
        l = s.value;
      if (l && (o == r || l.from > o + 10))
        return l;
      if (o == r)
        return null;
    }
  }
  prevMatch(e, r, n) {
    return this.prevMatchInRange(e, 0, r) || this.prevMatchInRange(e, n, e.doc.length);
  }
  getReplacement(e) {
    return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g, (r, n) => {
      if (n == "&")
        return e.match[0];
      if (n == "$")
        return "$";
      for (let i = n.length; i > 0; i--) {
        let o = +n.slice(0, i);
        if (o > 0 && o < e.match.length)
          return e.match[o] + n.slice(i);
      }
      return r;
    });
  }
  matchAll(e, r) {
    let n = ee(this.spec, e, 0, e.doc.length), i = [];
    for (; !n.next().done; ) {
      if (i.length >= r)
        return null;
      i.push(n.value);
    }
    return i;
  }
  highlight(e, r, n, i) {
    let o = ee(this.spec, e, Math.max(
      0,
      r - 250
      /* RegExp.HighlightMargin */
    ), Math.min(n + 250, e.doc.length));
    for (; !o.next().done; )
      i(o.value.from, o.value.to);
  }
}
const fe = /* @__PURE__ */ F.define(), ct = /* @__PURE__ */ F.define(), V = /* @__PURE__ */ et.define({
  create(t) {
    return new ze(Ze(t).create(), null);
  },
  update(t, e) {
    for (let r of e.effects)
      r.is(fe) ? t = new ze(r.value.create(), t.panel) : r.is(ct) && (t = new ze(t.query, r.value ? ht : null));
    return t;
  },
  provide: (t) => Vt.from(t, (e) => e.panel)
});
class ze {
  constructor(e, r) {
    this.query = e, this.panel = r;
  }
}
const eo = /* @__PURE__ */ v.mark({ class: "cm-searchMatch" }), to = /* @__PURE__ */ v.mark({ class: "cm-searchMatch cm-searchMatch-selected" }), no = /* @__PURE__ */ Ht.fromClass(class {
  constructor(t) {
    this.view = t, this.decorations = this.highlight(t.state.field(V));
  }
  update(t) {
    let e = t.state.field(V);
    (e != t.startState.field(V) || t.docChanged || t.selectionSet || t.viewportChanged) && (this.decorations = this.highlight(e));
  }
  highlight({ query: t, panel: e }) {
    if (!e || !t.spec.valid)
      return v.none;
    let { view: r } = this, n = new Ut();
    for (let i = 0, o = r.visibleRanges, s = o.length; i < s; i++) {
      let { from: l, to: a } = o[i];
      for (; i < s - 1 && a > o[i + 1].from - 2 * 250; )
        a = o[++i].to;
      t.highlight(r.state, l, a, (c, h) => {
        let u = r.state.selection.ranges.some((d) => d.from == c && d.to == h);
        n.add(c, h, u ? to : eo);
      });
    }
    return n.finish();
  }
}, {
  decorations: (t) => t.decorations
});
function ye(t) {
  return (e) => {
    let r = e.state.field(V, !1);
    return r && r.query.spec.valid ? t(e, r) : Rn(e);
  };
}
const Te = /* @__PURE__ */ ye((t, { query: e }) => {
  let { to: r } = t.state.selection.main, n = e.nextMatch(t.state, r, r);
  if (!n)
    return !1;
  let i = m.single(n.from, n.to), o = t.state.facet(oe);
  return t.dispatch({
    selection: i,
    effects: [ut(t, n), o.scrollToMatch(i.main, t)],
    userEvent: "select.search"
  }), wn(t), !0;
}), we = /* @__PURE__ */ ye((t, { query: e }) => {
  let { state: r } = t, { from: n } = r.selection.main, i = e.prevMatch(r, n, n);
  if (!i)
    return !1;
  let o = m.single(i.from, i.to), s = t.state.facet(oe);
  return t.dispatch({
    selection: o,
    effects: [ut(t, i), s.scrollToMatch(o.main, t)],
    userEvent: "select.search"
  }), wn(t), !0;
}), ro = /* @__PURE__ */ ye((t, { query: e }) => {
  let r = e.matchAll(t.state, 1e3);
  return !r || !r.length ? !1 : (t.dispatch({
    selection: m.create(r.map((n) => m.range(n.from, n.to))),
    userEvent: "select.search.matches"
  }), !0);
}), io = ({ state: t, dispatch: e }) => {
  let r = t.selection;
  if (r.ranges.length > 1 || r.main.empty)
    return !1;
  let { from: n, to: i } = r.main, o = [], s = 0;
  for (let l = new re(t.doc, t.sliceDoc(n, i)); !l.next().done; ) {
    if (o.length > 1e3)
      return !1;
    l.value.from == n && (s = o.length), o.push(m.range(l.value.from, l.value.to));
  }
  return e(t.update({
    selection: m.create(o, s),
    userEvent: "select.search.matches"
  })), !0;
}, vt = /* @__PURE__ */ ye((t, { query: e }) => {
  let { state: r } = t, { from: n, to: i } = r.selection.main;
  if (r.readOnly)
    return !1;
  let o = e.nextMatch(r, n, n);
  if (!o)
    return !1;
  let s = o, l = [], a, c, h = [];
  s.precise ? s.from == n && s.to == i && (c = r.toText(e.getReplacement(s)), l.push({ from: s.from, to: s.to, insert: c }), h.push(x.announce.of(r.phrase("replaced match on line $", r.doc.lineAt(n).number) + "."))) : s = e.nextMatch(r, s.from, s.to);
  let u = t.state.changes(l);
  return s && (a = m.single(s.from, s.to).map(u), h.push(ut(t, s)), h.push(r.facet(oe).scrollToMatch(a.main, t))), t.dispatch({
    changes: u,
    selection: a,
    effects: h,
    userEvent: "input.replace"
  }), !0;
}), oo = /* @__PURE__ */ ye((t, { query: e }) => {
  if (t.state.readOnly)
    return !1;
  let r = [];
  for (let i of e.matchAll(t.state, 1e9)) {
    let { from: o, to: s, precise: l } = i;
    l && r.push({ from: o, to: s, insert: e.getReplacement(i) });
  }
  if (!r.length)
    return !1;
  let n = t.state.phrase("replaced $ matches", r.length) + ".";
  return t.dispatch({
    changes: r,
    effects: x.announce.of(n),
    userEvent: "input.replace.all"
  }), !0;
});
function ht(t) {
  return t.state.facet(oe).createPanel(t);
}
function Ze(t, e) {
  var r, n, i, o, s;
  let l = t.selection.main, a = l.empty || l.to > l.from + 100 ? "" : t.sliceDoc(l.from, l.to);
  if (e && !a)
    return e;
  let c = t.facet(oe);
  return new Dn({
    search: ((r = e == null ? void 0 : e.literal) !== null && r !== void 0 ? r : c.literal) ? a : a.replace(/\n/g, "\\n"),
    caseSensitive: (n = e == null ? void 0 : e.caseSensitive) !== null && n !== void 0 ? n : c.caseSensitive,
    literal: (i = e == null ? void 0 : e.literal) !== null && i !== void 0 ? i : c.literal,
    regexp: (o = e == null ? void 0 : e.regexp) !== null && o !== void 0 ? o : c.regexp,
    wholeWord: (s = e == null ? void 0 : e.wholeWord) !== null && s !== void 0 ? s : c.wholeWord
  });
}
function Tn(t) {
  let e = it(t, ht);
  return e && e.dom.querySelector("[main-field]");
}
function wn(t) {
  let e = Tn(t);
  e && e == t.root.activeElement && e.select();
}
const Rn = (t) => {
  let e = t.state.field(V, !1);
  if (e && e.panel) {
    let r = Tn(t);
    if (r && r != t.root.activeElement) {
      let n = Ze(t.state, e.query.spec);
      n.valid && t.dispatch({ effects: fe.of(n) }), r.focus(), r.select();
    }
  } else
    t.dispatch({ effects: [
      ct.of(!0),
      e ? fe.of(Ze(t.state, e.query.spec)) : F.appendConfig.of(co)
    ] });
  return !0;
}, In = (t) => {
  let e = t.state.field(V, !1);
  if (!e || !e.panel)
    return !1;
  let r = it(t, ht);
  return r && r.dom.contains(t.root.activeElement) && t.focus(), t.dispatch({ effects: ct.of(!1) }), !0;
}, so = [
  { key: "Mod-f", run: Rn, scope: "editor search-panel" },
  { key: "F3", run: Te, shift: we, scope: "editor search-panel", preventDefault: !0 },
  { key: "Mod-g", run: Te, shift: we, scope: "editor search-panel", preventDefault: !0 },
  { key: "Escape", run: In, scope: "editor search-panel" },
  { key: "Mod-Shift-l", run: io },
  { key: "Mod-Alt-g", run: Pi },
  { key: "Mod-d", run: Ji, preventDefault: !0 }
];
class lo {
  constructor(e) {
    this.view = e;
    let r = this.query = e.state.field(V).query.spec;
    this.commit = this.commit.bind(this), this.searchField = b("input", {
      value: r.search,
      placeholder: B(e, "Find"),
      "aria-label": B(e, "Find"),
      class: "cm-textfield",
      name: "search",
      form: "",
      "main-field": "true",
      onchange: this.commit,
      onkeyup: this.commit
    }), this.replaceField = b("input", {
      value: r.replace,
      placeholder: B(e, "Replace"),
      "aria-label": B(e, "Replace"),
      class: "cm-textfield",
      name: "replace",
      form: "",
      onchange: this.commit,
      onkeyup: this.commit
    }), this.caseField = b("input", {
      type: "checkbox",
      name: "case",
      form: "",
      checked: r.caseSensitive,
      onchange: this.commit
    }), this.reField = b("input", {
      type: "checkbox",
      name: "re",
      form: "",
      checked: r.regexp,
      onchange: this.commit
    }), this.wordField = b("input", {
      type: "checkbox",
      name: "word",
      form: "",
      checked: r.wholeWord,
      onchange: this.commit
    });
    function n(i, o, s) {
      return b("button", { class: "cm-button", name: i, onclick: o, type: "button" }, s);
    }
    this.dom = b("div", { onkeydown: (i) => this.keydown(i), class: "cm-search" }, [
      this.searchField,
      n("next", () => Te(e), [B(e, "next")]),
      n("prev", () => we(e), [B(e, "previous")]),
      n("select", () => ro(e), [B(e, "all")]),
      b("label", null, [this.caseField, B(e, "match case")]),
      b("label", null, [this.reField, B(e, "regexp")]),
      b("label", null, [this.wordField, B(e, "by word")]),
      ...e.state.readOnly ? [] : [
        b("br"),
        this.replaceField,
        n("replace", () => vt(e), [B(e, "replace")]),
        n("replaceAll", () => oo(e), [B(e, "replace all")])
      ],
      b("button", {
        name: "close",
        onclick: () => In(e),
        "aria-label": B(e, "close"),
        type: "button"
      }, ["×"])
    ]);
  }
  commit() {
    let e = new Dn({
      search: this.searchField.value,
      caseSensitive: this.caseField.checked,
      regexp: this.reField.checked,
      wholeWord: this.wordField.checked,
      replace: this.replaceField.value
    });
    e.eq(this.query) || (this.query = e, this.view.dispatch({ effects: fe.of(e) }));
  }
  keydown(e) {
    Xn(this.view, e, "search-panel") ? e.preventDefault() : e.keyCode == 13 && e.target == this.searchField ? (e.preventDefault(), (e.shiftKey ? we : Te)(this.view)) : e.keyCode == 13 && e.target == this.replaceField && (e.preventDefault(), vt(this.view));
  }
  update(e) {
    for (let r of e.transactions)
      for (let n of r.effects)
        n.is(fe) && !n.value.eq(this.query) && this.setQuery(n.value);
  }
  setQuery(e) {
    this.query = e, this.searchField.value = e.search, this.replaceField.value = e.replace, this.caseField.checked = e.caseSensitive, this.reField.checked = e.regexp, this.wordField.checked = e.wholeWord;
  }
  mount() {
    this.searchField.select();
  }
  get pos() {
    return 80;
  }
  get top() {
    return this.view.state.facet(oe).top;
  }
}
function B(t, e) {
  return t.state.phrase(e);
}
const be = 30, Ce = /[\s\.,:;?!]/;
function ut(t, { from: e, to: r }) {
  let n = t.state.doc.lineAt(e), i = t.state.doc.lineAt(r).to, o = Math.max(n.from, e - be), s = Math.min(i, r + be), l = t.state.sliceDoc(o, s);
  if (o != n.from) {
    for (let a = 0; a < be; a++)
      if (!Ce.test(l[a + 1]) && Ce.test(l[a])) {
        l = l.slice(a);
        break;
      }
  }
  if (s != i) {
    for (let a = l.length - 1; a > l.length - be; a--)
      if (!Ce.test(l[a - 1]) && Ce.test(l[a])) {
        l = l.slice(0, a);
        break;
      }
  }
  return x.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${n.number}.`);
}
const ao = /* @__PURE__ */ x.baseTheme({
  ".cm-panel.cm-search": {
    padding: "2px 6px 4px",
    position: "relative",
    "& [name=close]": {
      position: "absolute",
      top: "0",
      right: "4px",
      backgroundColor: "inherit",
      border: "none",
      font: "inherit",
      padding: 0,
      margin: 0
    },
    "& input, & button, & label": {
      margin: ".2em .6em .2em 0"
    },
    "& input[type=checkbox]": {
      marginRight: ".2em"
    },
    "& label": {
      fontSize: "80%",
      whiteSpace: "pre"
    }
  },
  "&light .cm-searchMatch": { backgroundColor: "#ffff0054" },
  "&dark .cm-searchMatch": { backgroundColor: "#00ffff8a" },
  "&light .cm-searchMatch-selected": { backgroundColor: "#ff6a0054" },
  "&dark .cm-searchMatch-selected": { backgroundColor: "#ff00ff8a" }
}), co = [
  V,
  /* @__PURE__ */ Qn.low(no),
  ao
];
class Mt {
  constructor(e, r, n) {
    this.from = e, this.to = r, this.diagnostic = n;
  }
}
class J {
  constructor(e, r, n) {
    this.diagnostics = e, this.panel = r, this.selected = n;
  }
  static init(e, r, n) {
    let i = n.facet(de).markerFilter;
    i && (e = i(e, n));
    let o = e.slice().sort((g, p) => g.from - p.from || g.to - p.to), s = new Ut(), l = [], a = 0, c = n.doc.iter(), h = 0, u = n.doc.length;
    for (let g = 0; ; ) {
      let p = g == o.length ? null : o[g];
      if (!p && !l.length)
        break;
      let S, k;
      if (l.length)
        S = a, k = l.reduce((y, A) => Math.min(y, A.to), p && p.from > S ? p.from : 1e8);
      else {
        if (S = p.from, S > u)
          break;
        k = p.to, l.push(p), g++;
      }
      for (; g < o.length; ) {
        let y = o[g];
        if (y.from == S && (y.to > y.from || y.to == S))
          l.push(y), g++, k = Math.min(y.to, k);
        else {
          k = Math.min(y.from, k);
          break;
        }
      }
      k = Math.min(k, u);
      let N = !1;
      if (l.some((y) => y.from == S && (y.to == k || k == u)) && (N = S == k, !N && k - S < 10)) {
        let y = S - (h + c.value.length);
        y > 0 && (c.next(y), h = S);
        for (let A = S; ; ) {
          if (A >= k) {
            N = !0;
            break;
          }
          if (!c.lineBreak && h + c.value.length > A)
            break;
          A = h + c.value.length, h += c.value.length, c.next();
        }
      }
      let z = vo(l);
      if (N)
        s.add(S, S, v.widget({
          widget: new xo(z),
          diagnostics: l.slice()
        }));
      else {
        let y = l.reduce((A, Q) => Q.markClass ? A + " " + Q.markClass : A, "");
        s.add(S, k, v.mark({
          class: "cm-lintRange cm-lintRange-" + z + y,
          diagnostics: l.slice(),
          inclusiveEnd: l.some((A) => A.to > k)
        }));
      }
      if (a = k, a == u)
        break;
      for (let y = 0; y < l.length; y++)
        l[y].to <= a && l.splice(y--, 1);
    }
    let d = s.finish();
    return new J(d, r, H(d));
  }
}
function H(t, e = null, r = 0) {
  let n = null;
  return t.between(r, 1e9, (i, o, { spec: s }) => {
    if (!(e && s.diagnostics.indexOf(e) < 0))
      if (!n)
        n = new Mt(i, o, e || s.diagnostics[0]);
      else {
        if (s.diagnostics.indexOf(n.diagnostic) < 0)
          return !1;
        n = new Mt(n.from, o, n.diagnostic);
      }
  }), n;
}
function ho(t, e) {
  let r = e.pos, n = e.end || r, i = t.state.facet(de).hideOn(t, r, n);
  if (i != null)
    return i;
  let o = t.startState.doc.lineAt(e.pos);
  return !!(t.effects.some((s) => s.is(On)) || t.changes.touchesRange(o.from, Math.max(o.to, n)));
}
function uo(t, e) {
  return t.field(D, !1) ? e : e.concat(F.appendConfig.of(Mo));
}
const On = /* @__PURE__ */ F.define(), ft = /* @__PURE__ */ F.define(), Wn = /* @__PURE__ */ F.define(), D = /* @__PURE__ */ et.define({
  create() {
    return new J(v.none, null, null);
  },
  update(t, e) {
    if (e.docChanged && t.diagnostics.size) {
      let r = t.diagnostics.map(e.changes), n = null, i = t.panel;
      if (t.selected) {
        let o = e.changes.mapPos(t.selected.from, 1);
        n = H(r, t.selected.diagnostic, o) || H(r, null, o);
      }
      !r.size && i && e.state.facet(de).autoPanel && (i = null), t = new J(r, i, n);
    }
    for (let r of e.effects)
      if (r.is(On)) {
        let n = e.state.facet(de).autoPanel ? r.value.length ? me.open : null : t.panel;
        t = J.init(r.value, n, e.state);
      } else r.is(ft) ? t = new J(t.diagnostics, r.value ? me.open : null, t.selected) : r.is(Wn) && (t = new J(t.diagnostics, t.panel, r.value));
    return t;
  },
  provide: (t) => [
    Vt.from(t, (e) => e.panel),
    x.decorations.from(t, (e) => e.diagnostics)
  ]
}), fo = /* @__PURE__ */ v.mark({ class: "cm-lintRange cm-lintRange-active" });
function mo(t, e, r) {
  let { diagnostics: n } = t.state.field(D), i, o = -1, s = -1;
  n.between(e - (r < 0 ? 1 : 0), e + (r > 0 ? 1 : 0), (a, c, { spec: h }) => {
    if (e >= a && e <= c && (a == c || (e > a || r > 0) && (e < c || r < 0)))
      return i = h.diagnostics, o = a, s = c, !1;
  });
  let l = t.state.facet(de).tooltipFilter;
  return i && l && (i = l(i, t.state)), i ? {
    pos: o,
    end: s,
    above: t.state.doc.lineAt(o).to < s,
    create() {
      return { dom: go(t, i) };
    }
  } : null;
}
function go(t, e) {
  return b("ul", { class: "cm-tooltip-lint" }, e.map((r) => Fn(t, r, !1)));
}
const po = (t) => {
  let e = t.state.field(D, !1);
  (!e || !e.panel) && t.dispatch({ effects: uo(t.state, [ft.of(!0)]) });
  let r = it(t, me.open);
  return r && r.dom.querySelector(".cm-panel-lint ul").focus(), !0;
}, At = (t) => {
  let e = t.state.field(D, !1);
  return !e || !e.panel ? !1 : (t.dispatch({ effects: ft.of(!1) }), !0);
}, yo = (t) => {
  let e = t.state.field(D, !1);
  if (!e)
    return !1;
  let r = t.state.selection.main, n = H(e.diagnostics, null, r.to + 1);
  return !n && (n = H(e.diagnostics, null, 0), !n || n.from == r.from && n.to == r.to) ? !1 : (t.dispatch({ selection: { anchor: n.from, head: n.to }, scrollIntoView: !0 }), !0);
}, ko = [
  { key: "Mod-Shift-m", run: po, preventDefault: !0 },
  { key: "F8", run: yo }
], de = /* @__PURE__ */ ge.define({
  combine(t) {
    return {
      sources: t.map((e) => e.source).filter((e) => e != null),
      ...Re(t.map((e) => e.config), {
        delay: 750,
        markerFilter: null,
        tooltipFilter: null,
        needsRefresh: null,
        hideOn: () => null
      }, {
        delay: Math.max,
        markerFilter: Lt,
        tooltipFilter: Lt,
        needsRefresh: (e, r) => e ? r ? (n) => e(n) || r(n) : e : r,
        hideOn: (e, r) => e ? r ? (n, i, o) => e(n, i, o) || r(n, i, o) : e : r,
        autoPanel: (e, r) => e || r
      })
    };
  }
});
function Lt(t, e) {
  return t ? e ? (r, n) => e(t(r, n), n) : t : e;
}
function Pn(t) {
  let e = [];
  if (t)
    e: for (let { name: r } of t) {
      for (let n = 0; n < r.length; n++) {
        let i = r[n];
        if (/[a-zA-Z]/.test(i) && !e.some((o) => o.toLowerCase() == i.toLowerCase())) {
          e.push(i);
          continue e;
        }
      }
      e.push("");
    }
  return e;
}
function Fn(t, e, r) {
  var n;
  let i = r ? Pn(e.actions) : [];
  return b("li", { class: "cm-diagnostic cm-diagnostic-" + e.severity }, b("span", { class: "cm-diagnosticText" }, e.renderMessage ? e.renderMessage(t) : e.message), (n = e.actions) === null || n === void 0 ? void 0 : n.map((o, s) => {
    let l = !1, a = (g) => {
      if (g.preventDefault(), l)
        return;
      l = !0;
      let p = H(t.state.field(D).diagnostics, e);
      p && o.apply(t, p.from, p.to);
    }, { name: c } = o, h = i[s] ? c.indexOf(i[s]) : -1, u = h < 0 ? c : [
      c.slice(0, h),
      b("u", c.slice(h, h + 1)),
      c.slice(h + 1)
    ], d = o.markClass ? " " + o.markClass : "";
    return b("button", {
      type: "button",
      class: "cm-diagnosticAction" + d,
      onclick: a,
      onmousedown: a,
      "aria-label": ` Action: ${c}${h < 0 ? "" : ` (access key "${i[s]})"`}.`
    }, u);
  }), e.source && b("div", { class: "cm-diagnosticSource" }, e.source));
}
class xo extends tr {
  constructor(e) {
    super(), this.sev = e;
  }
  eq(e) {
    return e.sev == this.sev;
  }
  toDOM() {
    return b("span", { class: "cm-lintPoint cm-lintPoint-" + this.sev });
  }
}
class Bt {
  constructor(e, r) {
    this.diagnostic = r, this.id = "item_" + Math.floor(Math.random() * 4294967295).toString(16), this.dom = Fn(e, r, !0), this.dom.id = this.id, this.dom.setAttribute("role", "option");
  }
}
class me {
  constructor(e) {
    this.view = e, this.items = [];
    let r = (i) => {
      if (!(i.ctrlKey || i.altKey || i.metaKey)) {
        if (i.keyCode == 27)
          At(this.view), this.view.focus();
        else if (i.keyCode == 38 || i.keyCode == 33)
          this.moveSelection((this.selectedIndex - 1 + this.items.length) % this.items.length);
        else if (i.keyCode == 40 || i.keyCode == 34)
          this.moveSelection((this.selectedIndex + 1) % this.items.length);
        else if (i.keyCode == 36)
          this.moveSelection(0);
        else if (i.keyCode == 35)
          this.moveSelection(this.items.length - 1);
        else if (i.keyCode == 13)
          this.view.focus();
        else if (i.keyCode >= 65 && i.keyCode <= 90 && this.selectedIndex >= 0) {
          let { diagnostic: o } = this.items[this.selectedIndex], s = Pn(o.actions);
          for (let l = 0; l < s.length; l++)
            if (s[l].toUpperCase().charCodeAt(0) == i.keyCode) {
              let a = H(this.view.state.field(D).diagnostics, o);
              a && o.actions[l].apply(e, a.from, a.to);
            }
        } else
          return;
        i.preventDefault();
      }
    }, n = (i) => {
      for (let o = 0; o < this.items.length; o++)
        this.items[o].dom.contains(i.target) && this.moveSelection(o);
    };
    this.list = b("ul", {
      tabIndex: 0,
      role: "listbox",
      "aria-label": this.view.state.phrase("Diagnostics"),
      onkeydown: r,
      onclick: n
    }), this.dom = b("div", { class: "cm-panel-lint" }, this.list, b("button", {
      type: "button",
      name: "close",
      "aria-label": this.view.state.phrase("close"),
      onclick: () => At(this.view)
    }, "×")), this.update();
  }
  get selectedIndex() {
    let e = this.view.state.field(D).selected;
    if (!e)
      return -1;
    for (let r = 0; r < this.items.length; r++)
      if (this.items[r].diagnostic == e.diagnostic)
        return r;
    return -1;
  }
  update() {
    let { diagnostics: e, selected: r } = this.view.state.field(D), n = 0, i = !1, o = null, s = /* @__PURE__ */ new Set();
    for (e.between(0, this.view.state.doc.length, (l, a, { spec: c }) => {
      for (let h of c.diagnostics) {
        if (s.has(h))
          continue;
        s.add(h);
        let u = -1, d;
        for (let g = n; g < this.items.length; g++)
          if (this.items[g].diagnostic == h) {
            u = g;
            break;
          }
        u < 0 ? (d = new Bt(this.view, h), this.items.splice(n, 0, d), i = !0) : (d = this.items[u], u > n && (this.items.splice(n, u - n), i = !0)), r && d.diagnostic == r.diagnostic ? d.dom.hasAttribute("aria-selected") || (d.dom.setAttribute("aria-selected", "true"), o = d) : d.dom.hasAttribute("aria-selected") && d.dom.removeAttribute("aria-selected"), n++;
      }
    }); n < this.items.length && !(this.items.length == 1 && this.items[0].diagnostic.from < 0); )
      i = !0, this.items.pop();
    this.items.length == 0 && (this.items.push(new Bt(this.view, {
      from: -1,
      to: -1,
      severity: "info",
      message: this.view.state.phrase("No diagnostics")
    })), i = !0), o ? (this.list.setAttribute("aria-activedescendant", o.id), this.view.requestMeasure({
      key: this,
      read: () => ({ sel: o.dom.getBoundingClientRect(), panel: this.list.getBoundingClientRect() }),
      write: ({ sel: l, panel: a }) => {
        let c = a.height / this.list.offsetHeight;
        l.top < a.top ? this.list.scrollTop -= (a.top - l.top) / c : l.bottom > a.bottom && (this.list.scrollTop += (l.bottom - a.bottom) / c);
      }
    })) : this.selectedIndex < 0 && this.list.removeAttribute("aria-activedescendant"), i && this.sync();
  }
  sync() {
    let e = this.list.firstChild;
    function r() {
      let n = e;
      e = n.nextSibling, n.remove();
    }
    for (let n of this.items)
      if (n.dom.parentNode == this.list) {
        for (; e != n.dom; )
          r();
        e = n.dom.nextSibling;
      } else
        this.list.insertBefore(n.dom, e);
    for (; e; )
      r();
  }
  moveSelection(e) {
    if (this.selectedIndex < 0)
      return;
    let r = this.view.state.field(D), n = H(r.diagnostics, this.items[e].diagnostic);
    n && this.view.dispatch({
      selection: { anchor: n.from, head: n.to },
      scrollIntoView: !0,
      effects: Wn.of(n)
    });
  }
  static open(e) {
    return new me(e);
  }
}
function So(t, e = 'viewBox="0 0 40 40"') {
  return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`;
}
function ve(t) {
  return So(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`, 'width="6" height="3"');
}
const bo = /* @__PURE__ */ x.baseTheme({
  ".cm-diagnostic": {
    padding: "3px 6px 3px 8px",
    marginLeft: "-1px",
    display: "block",
    whiteSpace: "pre-wrap"
  },
  ".cm-diagnostic-error": { borderLeft: "5px solid #d11" },
  ".cm-diagnostic-warning": { borderLeft: "5px solid orange" },
  ".cm-diagnostic-info": { borderLeft: "5px solid #999" },
  ".cm-diagnostic-hint": { borderLeft: "5px solid #66d" },
  ".cm-diagnosticAction": {
    font: "inherit",
    border: "none",
    padding: "2px 4px",
    backgroundColor: "#444",
    color: "white",
    borderRadius: "3px",
    marginLeft: "8px",
    cursor: "pointer"
  },
  ".cm-diagnosticSource": {
    fontSize: "70%",
    opacity: 0.7
  },
  ".cm-lintRange": {
    backgroundPosition: "left bottom",
    backgroundRepeat: "repeat-x",
    paddingBottom: "0.7px"
  },
  ".cm-lintRange-error": { backgroundImage: /* @__PURE__ */ ve("#d11") },
  ".cm-lintRange-warning": { backgroundImage: /* @__PURE__ */ ve("orange") },
  ".cm-lintRange-info": { backgroundImage: /* @__PURE__ */ ve("#999") },
  ".cm-lintRange-hint": { backgroundImage: /* @__PURE__ */ ve("#66d") },
  ".cm-lintRange-active": { backgroundColor: "#ffdd9980" },
  ".cm-tooltip-lint": {
    padding: 0,
    margin: 0
  },
  ".cm-lintPoint": {
    position: "relative",
    "&:after": {
      content: '""',
      position: "absolute",
      bottom: 0,
      left: "-2px",
      borderLeft: "3px solid transparent",
      borderRight: "3px solid transparent",
      borderBottom: "4px solid #d11"
    }
  },
  ".cm-lintPoint-warning": {
    "&:after": { borderBottomColor: "orange" }
  },
  ".cm-lintPoint-info": {
    "&:after": { borderBottomColor: "#999" }
  },
  ".cm-lintPoint-hint": {
    "&:after": { borderBottomColor: "#66d" }
  },
  ".cm-panel.cm-panel-lint": {
    position: "relative",
    "& ul": {
      maxHeight: "100px",
      overflowY: "auto",
      "& [aria-selected]": {
        backgroundColor: "#ddd",
        "& u": { textDecoration: "underline" }
      },
      "&:focus [aria-selected]": {
        background_fallback: "#bdf",
        backgroundColor: "Highlight",
        color_fallback: "white",
        color: "HighlightText"
      },
      "& u": { textDecoration: "none" },
      padding: 0,
      margin: 0
    },
    "& [name=close]": {
      position: "absolute",
      top: "0",
      right: "2px",
      background: "inherit",
      border: "none",
      font: "inherit",
      padding: 0,
      margin: 0
    }
  },
  "&dark .cm-lintRange-active": { backgroundColor: "#86714a80" },
  "&dark .cm-panel.cm-panel-lint ul": {
    "& [aria-selected]": {
      backgroundColor: "#2e343e"
    }
  }
});
function Co(t) {
  return t == "error" ? 4 : t == "warning" ? 3 : t == "info" ? 2 : 1;
}
function vo(t) {
  let e = "hint", r = 1;
  for (let n of t) {
    let i = Co(n.severity);
    i > r && (r = i, e = n.severity);
  }
  return e;
}
const Mo = [
  D,
  /* @__PURE__ */ x.decorations.compute([D], (t) => {
    let { selected: e, panel: r } = t.field(D);
    return !e || !r || e.from == e.to ? v.none : v.set([
      fo.range(e.from, e.to)
    ]);
  }),
  /* @__PURE__ */ er(mo, { hideOn: ho }),
  bo
];
var Dt = function(e) {
  e === void 0 && (e = {});
  var {
    crosshairCursor: r = !1
  } = e, n = [];
  e.closeBracketsKeymap !== !1 && (n = n.concat(yr)), e.defaultKeymap !== !1 && (n = n.concat(Ii)), e.searchKeymap !== !1 && (n = n.concat(so)), e.historyKeymap !== !1 && (n = n.concat(Vr)), e.foldKeymap !== !1 && (n = n.concat(nr)), e.completionKeymap !== !1 && (n = n.concat(kr)), e.lintKeymap !== !1 && (n = n.concat(ko));
  var i = [];
  return e.lineNumbers !== !1 && i.push(rr()), e.highlightActiveLineGutter !== !1 && i.push(ir()), e.highlightSpecialChars !== !1 && i.push(or()), e.history !== !1 && i.push(wr()), e.foldGutter !== !1 && i.push(sr()), e.drawSelection !== !1 && i.push(lr()), e.dropCursor !== !1 && i.push(ar()), e.allowMultipleSelections !== !1 && i.push(ue.allowMultipleSelections.of(!0)), e.indentOnInput !== !1 && i.push(cr()), e.syntaxHighlighting !== !1 && i.push(zt(mr, {
    fallback: !0
  })), e.bracketMatching !== !1 && i.push(hr()), e.closeBrackets !== !1 && i.push(xr()), e.autocompletion !== !1 && i.push(Sr()), e.rectangularSelection !== !1 && i.push(ur()), r !== !1 && i.push(fr()), e.highlightActiveLine !== !1 && i.push(dr()), e.highlightSelectionMatches !== !1 && i.push(qi()), e.tabSize && typeof e.tabSize == "number" && i.push(qt.of(" ".repeat(e.tabSize))), i.concat([Gt.of(n.flat())]).filter(Boolean);
};
const Ao = "#e5c07b", Et = "#e06c75", Lo = "#56b6c2", Bo = "#ffffff", Me = "#abb2bf", Xe = "#7d8799", Do = "#61afef", Eo = "#98c379", Tt = "#d19a66", To = "#c678dd", wo = "#21252b", wt = "#2c313a", Rt = "#282c34", Ge = "#353a42", Ro = "#3E4451", It = "#528bff", Io = /* @__PURE__ */ x.theme({
  "&": {
    color: Me,
    backgroundColor: Rt
  },
  ".cm-content": {
    caretColor: It
  },
  ".cm-cursor, .cm-dropCursor": { borderLeftColor: It },
  "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: Ro },
  ".cm-panels": { backgroundColor: wo, color: Me },
  ".cm-panels.cm-panels-top": { borderBottom: "2px solid black" },
  ".cm-panels.cm-panels-bottom": { borderTop: "2px solid black" },
  ".cm-searchMatch": {
    backgroundColor: "#72a1ff59",
    outline: "1px solid #457dff"
  },
  ".cm-searchMatch.cm-searchMatch-selected": {
    backgroundColor: "#6199ff2f"
  },
  ".cm-activeLine": { backgroundColor: "#6699ff0b" },
  ".cm-selectionMatch": { backgroundColor: "#aafe661a" },
  "&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": {
    backgroundColor: "#bad0f847"
  },
  ".cm-gutters": {
    backgroundColor: Rt,
    color: Xe,
    border: "none"
  },
  ".cm-activeLineGutter": {
    backgroundColor: wt
  },
  ".cm-foldPlaceholder": {
    backgroundColor: "transparent",
    border: "none",
    color: "#ddd"
  },
  ".cm-tooltip": {
    border: "none",
    backgroundColor: Ge
  },
  ".cm-tooltip .cm-tooltip-arrow:before": {
    borderTopColor: "transparent",
    borderBottomColor: "transparent"
  },
  ".cm-tooltip .cm-tooltip-arrow:after": {
    borderTopColor: Ge,
    borderBottomColor: Ge
  },
  ".cm-tooltip-autocomplete": {
    "& > ul > li[aria-selected]": {
      backgroundColor: wt,
      color: Me
    }
  }
}, { dark: !0 }), Oo = /* @__PURE__ */ gr.define([
  {
    tag: f.keyword,
    color: To
  },
  {
    tag: [f.name, f.deleted, f.character, f.propertyName, f.macroName],
    color: Et
  },
  {
    tag: [/* @__PURE__ */ f.function(f.variableName), f.labelName],
    color: Do
  },
  {
    tag: [f.color, /* @__PURE__ */ f.constant(f.name), /* @__PURE__ */ f.standard(f.name)],
    color: Tt
  },
  {
    tag: [/* @__PURE__ */ f.definition(f.name), f.separator],
    color: Me
  },
  {
    tag: [f.typeName, f.className, f.number, f.changed, f.annotation, f.modifier, f.self, f.namespace],
    color: Ao
  },
  {
    tag: [f.operator, f.operatorKeyword, f.url, f.escape, f.regexp, f.link, /* @__PURE__ */ f.special(f.string)],
    color: Lo
  },
  {
    tag: [f.meta, f.comment],
    color: Xe
  },
  {
    tag: f.strong,
    fontWeight: "bold"
  },
  {
    tag: f.emphasis,
    fontStyle: "italic"
  },
  {
    tag: f.strikethrough,
    textDecoration: "line-through"
  },
  {
    tag: f.link,
    color: Xe,
    textDecoration: "underline"
  },
  {
    tag: f.heading,
    fontWeight: "bold",
    color: Et
  },
  {
    tag: [f.atom, f.bool, /* @__PURE__ */ f.special(f.variableName)],
    color: Tt
  },
  {
    tag: [f.processingInstruction, f.string, f.inserted],
    color: Eo
  },
  {
    tag: f.invalid,
    color: Bo
  }
]), Wo = [Io, /* @__PURE__ */ zt(Oo)];
var Po = x.theme({
  "&": {
    backgroundColor: "#fff"
  }
}, {
  dark: !1
}), Fo = function(e) {
  e === void 0 && (e = {});
  var {
    indentWithTab: r = !0,
    editable: n = !0,
    readOnly: i = !1,
    theme: o = "light",
    placeholder: s = "",
    basicSetup: l = !0
  } = e, a = [];
  switch (r && a.unshift(Gt.of([Oi])), l && (typeof l == "boolean" ? a.unshift(Dt()) : a.unshift(Dt(l))), s && a.unshift(pr(s)), o) {
    case "light":
      a.push(Po);
      break;
    case "dark":
      a.push(Wo);
      break;
    case "none":
      break;
    default:
      a.push(o);
      break;
  }
  return n === !1 && a.push(x.editable.of(!1)), i && a.push(ue.readOnly.of(!0)), [...a];
}, No = (t) => ({
  line: t.state.doc.lineAt(t.state.selection.main.from),
  lineCount: t.state.doc.lines,
  lineBreak: t.state.lineBreak,
  length: t.state.doc.length,
  readOnly: t.state.readOnly,
  tabSize: t.state.tabSize,
  selection: t.state.selection,
  selectionAsSingle: t.state.selection.asSingle().main,
  ranges: t.state.selection.ranges,
  selectionCode: t.state.sliceDoc(t.state.selection.main.from, t.state.selection.main.to),
  selections: t.state.selection.ranges.map((e) => t.state.sliceDoc(e.from, e.to)),
  selectedText: t.state.selection.ranges.some((e) => !e.empty)
});
class qo {
  constructor(e, r) {
    this.timeLeftMS = void 0, this.timeoutMS = void 0, this.isCancelled = !1, this.isTimeExhausted = !1, this.callbacks = [], this.timeLeftMS = r, this.timeoutMS = r, this.callbacks.push(e);
  }
  tick() {
    if (!this.isCancelled && !this.isTimeExhausted && (this.timeLeftMS--, this.timeLeftMS <= 0)) {
      this.isTimeExhausted = !0;
      var e = this.callbacks.slice();
      this.callbacks.length = 0, e.forEach((r) => {
        try {
          r();
        } catch (n) {
          console.error("TimeoutLatch callback error:", n);
        }
      });
    }
  }
  cancel() {
    this.isCancelled = !0, this.callbacks.length = 0;
  }
  reset() {
    this.timeLeftMS = this.timeoutMS, this.isCancelled = !1, this.isTimeExhausted = !1;
  }
  get isDone() {
    return this.isCancelled || this.isTimeExhausted;
  }
}
class Ot {
  constructor() {
    this.interval = null, this.latches = /* @__PURE__ */ new Set();
  }
  add(e) {
    this.latches.add(e), this.start();
  }
  remove(e) {
    this.latches.delete(e), this.latches.size === 0 && this.stop();
  }
  start() {
    this.interval === null && (this.interval = setInterval(() => {
      this.latches.forEach((e) => {
        e.tick(), e.isDone && this.remove(e);
      });
    }, 1));
  }
  stop() {
    this.interval !== null && (clearInterval(this.interval), this.interval = null);
  }
}
var Ke = null, Vo = () => typeof window > "u" ? new Ot() : (Ke || (Ke = new Ot()), Ke), Wt = rt.define(), Ho = 200, Uo = [];
function zo(t) {
  var {
    value: e,
    selection: r,
    onChange: n,
    onStatistics: i,
    onCreateEditor: o,
    onUpdate: s,
    extensions: l = Uo,
    autoFocus: a,
    theme: c = "light",
    height: h = null,
    minHeight: u = null,
    maxHeight: d = null,
    width: g = null,
    minWidth: p = null,
    maxWidth: S = null,
    placeholder: k = "",
    editable: N = !0,
    readOnly: z = !1,
    indentWithTab: y = !0,
    basicSetup: A = !0,
    root: Q,
    initialState: se
  } = t, [j, ke] = ae(), [C, q] = ae(), [Y, Z] = ae(), E = ae(() => ({
    current: null
  }))[0], G = ae(() => ({
    current: null
  }))[0], Fe = x.theme({
    "&": {
      height: h,
      minHeight: u,
      maxHeight: d,
      width: g,
      minWidth: p,
      maxWidth: S
    },
    "& .cm-scroller": {
      height: "100% !important"
    }
  }), Ne = x.updateListener.of((W) => {
    if (W.docChanged && typeof n == "function" && // Fix echoing of the remote changes:
    // If transaction is market as remote we don't have to call `onChange` handler again
    !W.transactions.some((qe) => qe.annotation(Wt))) {
      E.current ? E.current.reset() : (E.current = new qo(() => {
        if (G.current) {
          var qe = G.current;
          G.current = null, qe();
        }
        E.current = null;
      }, Ho), Vo().add(E.current));
      var K = W.state.doc, $ = K.toString();
      n($, W);
    }
    i && i(No(W));
  }), xe = Fo({
    theme: c,
    editable: N,
    readOnly: z,
    placeholder: k,
    indentWithTab: y,
    basicSetup: A
  }), le = [Ne, Fe, ...xe];
  return s && typeof s == "function" && le.push(x.updateListener.of(s)), le = le.concat(l), Vn(() => {
    if (j && !Y) {
      var W = {
        doc: e,
        selection: r,
        extensions: le
      }, K = se ? ue.fromJSON(se.json, W, se.fields) : ue.create(W);
      if (Z(K), !C) {
        var $ = new x({
          state: K,
          parent: j,
          root: Q
        });
        q($), o && o($, K);
      }
    }
    return () => {
      C && (Z(void 0), q(void 0));
    };
  }, [j, Y]), ce(() => {
    t.container && ke(t.container);
  }, [t.container]), ce(() => () => {
    C && (C.destroy(), q(void 0)), E.current && (E.current.cancel(), E.current = null);
  }, [C]), ce(() => {
    a && C && C.focus();
  }, [a, C]), ce(() => {
    C && C.dispatch({
      effects: F.reconfigure.of(le)
    });
  }, [c, l, h, u, d, g, p, S, k, N, z, y, A, n, s]), ce(() => {
    if (e !== void 0) {
      var W = C ? C.state.doc.toString() : "";
      if (C && e !== W) {
        var K = E.current && !E.current.isDone, $ = () => {
          C && e !== C.state.doc.toString() && C.dispatch({
            changes: {
              from: 0,
              to: C.state.doc.toString().length,
              insert: e || ""
            },
            annotations: [Wt.of(!0)]
          });
        };
        K ? G.current = $ : $();
      }
    }
  }, [e, C]), {
    state: Y,
    setState: Z,
    view: C,
    setView: q,
    container: j,
    setContainer: ke
  };
}
var Go = ["className", "value", "selection", "extensions", "onChange", "onStatistics", "onCreateEditor", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable", "readOnly", "root", "initialState"], Ko = /* @__PURE__ */ Hn((t, e) => {
  var {
    className: r,
    value: n = "",
    selection: i,
    extensions: o = [],
    onChange: s,
    onStatistics: l,
    onCreateEditor: a,
    onUpdate: c,
    autoFocus: h,
    theme: u = "light",
    height: d,
    minHeight: g,
    maxHeight: p,
    width: S,
    minWidth: k,
    maxWidth: N,
    basicSetup: z,
    placeholder: y,
    indentWithTab: A,
    editable: Q,
    readOnly: se,
    root: j,
    initialState: ke
  } = t, C = Nn(t, Go), q = Un(null), {
    state: Y,
    view: Z,
    container: E,
    setContainer: G
  } = zo({
    root: j,
    value: n,
    autoFocus: h,
    theme: u,
    height: d,
    minHeight: g,
    maxHeight: p,
    width: S,
    minWidth: k,
    maxWidth: N,
    basicSetup: z,
    placeholder: y,
    indentWithTab: A,
    editable: Q,
    readOnly: se,
    selection: i,
    onChange: s,
    onStatistics: l,
    onCreateEditor: a,
    onUpdate: c,
    extensions: o,
    initialState: ke
  });
  zn(e, () => ({
    editor: q.current,
    state: Y,
    view: Z
  }), [q, E, Y, Z]);
  var Fe = Gn((xe) => {
    q.current = xe, G(xe);
  }, [G]);
  if (typeof n != "string")
    throw new Error("value must be typeof string but got " + typeof n);
  var Ne = typeof u == "string" ? "cm-theme-" + u : "cm-theme";
  return /* @__PURE__ */ br("div", qn({
    ref: Fe,
    className: "" + Ne + (r ? " " + r : "")
  }, C));
});
Ko.displayName = "CodeMirror";
export {
  rt as Annotation,
  Xo as AnnotationType,
  es as BidiSpan,
  ts as BlockInfo,
  ns as BlockType,
  rs as BlockWrapper,
  $n as ChangeDesc,
  Kn as ChangeSet,
  T as CharCategory,
  is as Compartment,
  v as Decoration,
  Jn as Direction,
  m as EditorSelection,
  ue as EditorState,
  x as EditorView,
  Wt as ExternalChange,
  ge as Facet,
  os as GutterMarker,
  ss as Line,
  ls as MapMode,
  as as MatchDecorator,
  Qn as Prec,
  cs as Range,
  hs as RangeSet,
  Ut as RangeSetBuilder,
  us as RangeValue,
  fs as RectangleMarker,
  ds as SelectionRange,
  F as StateEffect,
  ms as StateEffectType,
  et as StateField,
  Nt as Text,
  Ve as Transaction,
  Ht as ViewPlugin,
  gs as ViewUpdate,
  tr as WidgetType,
  Dt as basicSetup,
  jn as codePointAt,
  Yn as codePointSize,
  Re as combineConfig,
  tt as countColumn,
  fr as crosshairCursor,
  Ko as default,
  Po as defaultLightThemeOption,
  lr as drawSelection,
  ar as dropCursor,
  _ as findClusterBreak,
  ps as findColumn,
  Zn as fromCodePoint,
  Fo as getDefaultExtensions,
  it as getPanel,
  No as getStatistics,
  ys as getTooltip,
  ks as gutter,
  xs as gutterLineClass,
  Ss as gutterWidgetClass,
  bs as gutters,
  dr as highlightActiveLine,
  ir as highlightActiveLineGutter,
  or as highlightSpecialChars,
  er as hoverTooltip,
  Gt as keymap,
  Cs as layer,
  vs as lineNumberMarkers,
  Ms as lineNumberWidgetMarker,
  rr as lineNumbers,
  As as logException,
  Wo as oneDark,
  Oo as oneDarkHighlightStyle,
  Io as oneDarkTheme,
  pr as placeholder,
  ur as rectangularSelection,
  Xn as runScopeHandlers,
  _n as showDialog,
  Vt as showPanel,
  Ls as showTooltip,
  zo as useCodeMirror
};
//# sourceMappingURL=index-BbYsmgpo.js.map
