var ze = Object.defineProperty;
var s = (e, t) => ze(e, "name", { value: t, configurable: !0 });
import { StateField as He, Facet as le, EditorSelection as d, countColumn as W, Text as ce, Annotation as se, Transaction as J, combineConfig as qe, findClusterBreak as O, StateEffect as ie, ChangeSet as Ke, ChangeDesc as $e } from "../../../../../@codemirror_state@6.5.2/node_modules/@codemirror/state/dist/index.js";
import { EditorView as L, Direction as We } from "../../../../../@codemirror_view@6.36.4/node_modules/@codemirror/view/dist/index.js";
import { IndentContext as ue, getIndentation as fe, indentString as I, syntaxTree as Q, matchBrackets as D, getIndentUnit as F, indentUnit as Qe } from "../../../../../@codemirror_language@6.11.0/node_modules/@codemirror/language/dist/index.js";
import { NodeProp as z } from "../../../../../@lezer_common@1.2.3/node_modules/@lezer/common/dist/index.js";
const Xe = /* @__PURE__ */ s((e) => {
  let { state: t } = e, r = t.doc.lineAt(t.selection.main.from), n = Y(e.state, r.from);
  return n.line ? Ye(e) : n.block ? je(e) : !1;
}, "toggleComment");
function X(e, t) {
  return ({ state: r, dispatch: n }) => {
    if (r.readOnly)
      return !1;
    let l = e(t, r);
    return l ? (n(r.update(l)), !0) : !1;
  };
}
s(X, "command");
const Ye = /* @__PURE__ */ X(
  et,
  0
  /* CommentOption.Toggle */
), Ze = /* @__PURE__ */ X(
  ae,
  0
  /* CommentOption.Toggle */
), je = /* @__PURE__ */ X(
  (e, t) => ae(e, t, _e(t)),
  0
  /* CommentOption.Toggle */
);
function Y(e, t) {
  let r = e.languageDataAt("commentTokens", t);
  return r.length ? r[0] : {};
}
s(Y, "getConfig");
const E = 50;
function we(e, { open: t, close: r }, n, l) {
  let o = e.sliceDoc(n - E, n), c = e.sliceDoc(l, l + E), i = /\s*$/.exec(o)[0].length, u = /^\s*/.exec(c)[0].length, a = o.length - i;
  if (o.slice(a - t.length, a) == t && c.slice(u, u + r.length) == r)
    return {
      open: { pos: n - i, margin: i && 1 },
      close: { pos: l + u, margin: u && 1 }
    };
  let f, h;
  l - n <= 2 * E ? f = h = e.sliceDoc(n, l) : (f = e.sliceDoc(n, n + E), h = e.sliceDoc(l - E, l));
  let g = /^\s*/.exec(f)[0].length, b = /\s*$/.exec(h)[0].length, M = h.length - b - r.length;
  return f.slice(g, g + t.length) == t && h.slice(M, M + r.length) == r ? {
    open: {
      pos: n + g + t.length,
      margin: /\s/.test(f.charAt(g + t.length)) ? 1 : 0
    },
    close: {
      pos: l - b - r.length,
      margin: /\s/.test(h.charAt(M - 1)) ? 1 : 0
    }
  } : null;
}
s(we, "findBlockComment");
function _e(e) {
  let t = [];
  for (let r of e.selection.ranges) {
    let n = e.doc.lineAt(r.from), l = r.to <= n.to ? n : e.doc.lineAt(r.to);
    l.from > n.from && l.from == r.to && (l = r.to == n.to + 1 ? n : e.doc.lineAt(r.to - 1));
    let o = t.length - 1;
    o >= 0 && t[o].to > n.from ? t[o].to = l.to : t.push({ from: n.from + /^\s*/.exec(n.text)[0].length, to: l.to });
  }
  return t;
}
s(_e, "selectedLineRanges");
function ae(e, t, r = t.selection.ranges) {
  let n = r.map((o) => Y(t, o.from).block);
  if (!n.every((o) => o))
    return null;
  let l = r.map((o, c) => we(t, n[c], o.from, o.to));
  if (e != 2 && !l.every((o) => o))
    return { changes: t.changes(r.map((o, c) => l[c] ? [] : [{ from: o.from, insert: n[c].open + " " }, { from: o.to, insert: " " + n[c].close }])) };
  if (e != 1 && l.some((o) => o)) {
    let o = [];
    for (let c = 0, i; c < l.length; c++)
      if (i = l[c]) {
        let u = n[c], { open: a, close: f } = i;
        o.push({ from: a.pos - u.open.length, to: a.pos + a.margin }, { from: f.pos - f.margin, to: f.pos + u.close.length });
      }
    return { changes: o };
  }
  return null;
}
s(ae, "changeBlockComment");
function et(e, t, r = t.selection.ranges) {
  let n = [], l = -1;
  for (let { from: o, to: c } of r) {
    let i = n.length, u = 1e9, a = Y(t, o).line;
    if (a) {
      for (let f = o; f <= c; ) {
        let h = t.doc.lineAt(f);
        if (h.from > l && (o == c || c > h.from)) {
          l = h.from;
          let g = /^\s*/.exec(h.text)[0].length, b = g == h.length, M = h.text.slice(g, g + a.length) == a ? g : -1;
          g < h.text.length && g < u && (u = g), n.push({ line: h, comment: M, token: a, indent: g, empty: b, single: !1 });
        }
        f = h.to + 1;
      }
      if (u < 1e9)
        for (let f = i; f < n.length; f++)
          n[f].indent < n[f].line.text.length && (n[f].indent = u);
      n.length == i + 1 && (n[i].single = !0);
    }
  }
  if (e != 2 && n.some((o) => o.comment < 0 && (!o.empty || o.single))) {
    let o = [];
    for (let { line: i, token: u, indent: a, empty: f, single: h } of n)
      (h || !f) && o.push({ from: i.from + a, insert: u + " " });
    let c = t.changes(o);
    return { changes: c, selection: t.selection.map(c, 1) };
  } else if (e != 1 && n.some((o) => o.comment >= 0)) {
    let o = [];
    for (let { line: c, comment: i, token: u } of n)
      if (i >= 0) {
        let a = c.from + i, f = a + u.length;
        c.text[f - c.from] == " " && f++, o.push({ from: a, to: f });
      }
    return { changes: o };
  }
  return null;
}
s(et, "changeLineComment");
const H = /* @__PURE__ */ se.define(), tt = /* @__PURE__ */ se.define(), nt = /* @__PURE__ */ le.define(), he = /* @__PURE__ */ le.define({
  combine(e) {
    return qe(e, {
      minDepth: 100,
      newGroupDelay: 500,
      joinToEvent: /* @__PURE__ */ s((t, r) => r, "joinToEvent")
    }, {
      minDepth: Math.max,
      newGroupDelay: Math.min,
      joinToEvent: /* @__PURE__ */ s((t, r) => (n, l) => t(n, l) || r(n, l), "joinToEvent")
    });
  }
}), de = /* @__PURE__ */ He.define({
  create() {
    return B.empty;
  },
  update(e, t) {
    let r = t.state.facet(he), n = t.annotation(H);
    if (n) {
      let u = p.fromTransaction(t, n.selection), a = n.side, f = a == 0 ? e.undone : e.done;
      return u ? f = v(f, f.length, r.minDepth, u) : f = ge(f, t.startState.selection), new B(a == 0 ? n.rest : f, a == 0 ? f : n.rest);
    }
    let l = t.annotation(tt);
    if ((l == "full" || l == "before") && (e = e.isolate()), t.annotation(J.addToHistory) === !1)
      return t.changes.empty ? e : e.addMapping(t.changes.desc);
    let o = p.fromTransaction(t), c = t.annotation(J.time), i = t.annotation(J.userEvent);
    return o ? e = e.addChanges(o, c, i, r, t) : t.selection && (e = e.addSelection(t.startState.selection, c, i, r.newGroupDelay)), (l == "full" || l == "after") && (e = e.isolate()), e;
  },
  toJSON(e) {
    return { done: e.done.map((t) => t.toJSON()), undone: e.undone.map((t) => t.toJSON()) };
  },
  fromJSON(e) {
    return new B(e.done.map(p.fromJSON), e.undone.map(p.fromJSON));
  }
});
function un(e = {}) {
  return [
    de,
    he.of(e),
    L.domEventHandlers({
      beforeinput(t, r) {
        let n = t.inputType == "historyUndo" ? me : t.inputType == "historyRedo" ? q : null;
        return n ? (t.preventDefault(), n(r)) : !1;
      }
    })
  ];
}
s(un, "history");
function N(e, t) {
  return function({ state: r, dispatch: n }) {
    if (!t && r.readOnly)
      return !1;
    let l = r.field(de, !1);
    if (!l)
      return !1;
    let o = l.pop(e, r, t);
    return o ? (n(o), !0) : !1;
  };
}
s(N, "cmd");
const me = /* @__PURE__ */ N(0, !1), q = /* @__PURE__ */ N(1, !1), rt = /* @__PURE__ */ N(0, !0), ot = /* @__PURE__ */ N(1, !0);
class p {
  static {
    s(this, "HistEvent");
  }
  constructor(t, r, n, l, o) {
    this.changes = t, this.effects = r, this.mapped = n, this.startSelection = l, this.selectionsAfter = o;
  }
  setSelAfter(t) {
    return new p(this.changes, this.effects, this.mapped, this.startSelection, t);
  }
  toJSON() {
    var t, r, n;
    return {
      changes: (t = this.changes) === null || t === void 0 ? void 0 : t.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((l) => l.toJSON())
    };
  }
  static fromJSON(t) {
    return new p(t.changes && Ke.fromJSON(t.changes), [], t.mapped && $e.fromJSON(t.mapped), t.startSelection && d.fromJSON(t.startSelection), t.selectionsAfter.map(d.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(t, r) {
    let n = y;
    for (let l of t.startState.facet(nt)) {
      let o = l(t);
      o.length && (n = n.concat(o));
    }
    return !n.length && t.changes.empty ? null : new p(t.changes.invert(t.startState.doc), n, void 0, r || t.startState.selection, y);
  }
  static selection(t) {
    return new p(void 0, y, void 0, void 0, t);
  }
}
function v(e, t, r, n) {
  let l = t + 1 > r + 20 ? t - r - 1 : 0, o = e.slice(l, t);
  return o.push(n), o;
}
s(v, "updateBranch");
function lt(e, t) {
  let r = [], n = !1;
  return e.iterChangedRanges((l, o) => r.push(l, o)), t.iterChangedRanges((l, o, c, i) => {
    for (let u = 0; u < r.length; ) {
      let a = r[u++], f = r[u++];
      i >= a && c <= f && (n = !0);
    }
  }), n;
}
s(lt, "isAdjacent");
function ct(e, t) {
  return e.ranges.length == t.ranges.length && e.ranges.filter((r, n) => r.empty != t.ranges[n].empty).length === 0;
}
s(ct, "eqSelectionShape");
function pe(e, t) {
  return e.length ? t.length ? e.concat(t) : e : t;
}
s(pe, "conc");
const y = [], st = 200;
function ge(e, t) {
  if (e.length) {
    let r = e[e.length - 1], n = r.selectionsAfter.slice(Math.max(0, r.selectionsAfter.length - st));
    return n.length && n[n.length - 1].eq(t) ? e : (n.push(t), v(e, e.length - 1, 1e9, r.setSelAfter(n)));
  } else
    return [p.selection([t])];
}
s(ge, "addSelection");
function it(e) {
  let t = e[e.length - 1], r = e.slice();
  return r[e.length - 1] = t.setSelAfter(t.selectionsAfter.slice(0, t.selectionsAfter.length - 1)), r;
}
s(it, "popSelection");
function G(e, t) {
  if (!e.length)
    return e;
  let r = e.length, n = y;
  for (; r; ) {
    let l = ut(e[r - 1], t, n);
    if (l.changes && !l.changes.empty || l.effects.length) {
      let o = e.slice(0, r);
      return o[r - 1] = l, o;
    } else
      t = l.mapped, r--, n = l.selectionsAfter;
  }
  return n.length ? [p.selection(n)] : y;
}
s(G, "addMappingToBranch");
function ut(e, t, r) {
  let n = pe(e.selectionsAfter.length ? e.selectionsAfter.map((i) => i.map(t)) : y, r);
  if (!e.changes)
    return p.selection(n);
  let l = e.changes.map(t), o = t.mapDesc(e.changes, !0), c = e.mapped ? e.mapped.composeDesc(o) : o;
  return new p(l, ie.mapEffects(e.effects, t), c, e.startSelection.map(o), n);
}
s(ut, "mapEvent");
const ft = /^(input\.type|delete)($|\.)/;
class B {
  static {
    s(this, "HistoryState");
  }
  constructor(t, r, n = 0, l = void 0) {
    this.done = t, this.undone = r, this.prevTime = n, this.prevUserEvent = l;
  }
  isolate() {
    return this.prevTime ? new B(this.done, this.undone) : this;
  }
  addChanges(t, r, n, l, o) {
    let c = this.done, i = c[c.length - 1];
    return i && i.changes && !i.changes.empty && t.changes && (!n || ft.test(n)) && (!i.selectionsAfter.length && r - this.prevTime < l.newGroupDelay && l.joinToEvent(o, lt(i.changes, t.changes)) || // For compose (but not compose.start) events, always join with previous event
    n == "input.type.compose") ? c = v(c, c.length - 1, l.minDepth, new p(t.changes.compose(i.changes), pe(ie.mapEffects(t.effects, i.changes), i.effects), i.mapped, i.startSelection, y)) : c = v(c, c.length, l.minDepth, t), new B(c, y, r, n);
  }
  addSelection(t, r, n, l) {
    let o = this.done.length ? this.done[this.done.length - 1].selectionsAfter : y;
    return o.length > 0 && r - this.prevTime < l && n == this.prevUserEvent && n && /^select($|\.)/.test(n) && ct(o[o.length - 1], t) ? this : new B(ge(this.done, t), this.undone, r, n);
  }
  addMapping(t) {
    return new B(G(this.done, t), G(this.undone, t), this.prevTime, this.prevUserEvent);
  }
  pop(t, r, n) {
    let l = t == 0 ? this.done : this.undone;
    if (l.length == 0)
      return null;
    let o = l[l.length - 1], c = o.selectionsAfter[0] || r.selection;
    if (n && o.selectionsAfter.length)
      return r.update({
        selection: o.selectionsAfter[o.selectionsAfter.length - 1],
        annotations: H.of({ side: t, rest: it(l), selection: c }),
        userEvent: t == 0 ? "select.undo" : "select.redo",
        scrollIntoView: !0
      });
    if (o.changes) {
      let i = l.length == 1 ? y : l.slice(0, l.length - 1);
      return o.mapped && (i = G(i, o.mapped)), r.update({
        changes: o.changes,
        selection: o.startSelection,
        effects: o.effects,
        annotations: H.of({ side: t, rest: i, selection: c }),
        filter: !1,
        userEvent: t == 0 ? "undo" : "redo",
        scrollIntoView: !0
      });
    } else
      return null;
  }
}
B.empty = /* @__PURE__ */ new B(y, y);
const fn = [
  { key: "Mod-z", run: me, preventDefault: !0 },
  { key: "Mod-y", mac: "Mod-Shift-z", run: q, preventDefault: !0 },
  { linux: "Ctrl-Shift-z", run: q, preventDefault: !0 },
  { key: "Mod-u", run: rt, preventDefault: !0 },
  { key: "Alt-u", mac: "Mod-Shift-u", run: ot, preventDefault: !0 }
];
function C(e, t) {
  return d.create(e.ranges.map(t), e.mainIndex);
}
s(C, "updateSel");
function S(e, t) {
  return e.update({ selection: t, scrollIntoView: !0, userEvent: "select" });
}
s(S, "setSel");
function A({ state: e, dispatch: t }, r) {
  let n = C(e.selection, r);
  return n.eq(e.selection, !0) ? !1 : (t(S(e, n)), !0);
}
s(A, "moveSel");
function P(e, t) {
  return d.cursor(t ? e.to : e.from);
}
s(P, "rangeEnd");
function ye(e, t) {
  return A(e, (r) => r.empty ? e.moveByChar(r, t) : P(r, t));
}
s(ye, "cursorByChar");
function m(e) {
  return e.textDirectionAt(e.state.selection.main.head) == We.LTR;
}
s(m, "ltrAtCursor");
const ke = /* @__PURE__ */ s((e) => ye(e, !m(e)), "cursorCharLeft"), Ae = /* @__PURE__ */ s((e) => ye(e, m(e)), "cursorCharRight");
function Be(e, t) {
  return A(e, (r) => r.empty ? e.moveByGroup(r, t) : P(r, t));
}
s(Be, "cursorByGroup");
const at = /* @__PURE__ */ s((e) => Be(e, !m(e)), "cursorGroupLeft"), ht = /* @__PURE__ */ s((e) => Be(e, m(e)), "cursorGroupRight");
function dt(e, t, r) {
  if (t.type.prop(r))
    return !0;
  let n = t.to - t.from;
  return n && (n > 2 || /[^\s,.;:]/.test(e.sliceDoc(t.from, t.to))) || t.firstChild;
}
s(dt, "interestingNode");
function U(e, t, r) {
  let n = Q(e).resolveInner(t.head), l = r ? z.closedBy : z.openedBy;
  for (let u = t.head; ; ) {
    let a = r ? n.childAfter(u) : n.childBefore(u);
    if (!a)
      break;
    dt(e, a, l) ? n = a : u = r ? a.to : a.from;
  }
  let o = n.type.prop(l), c, i;
  return o && (c = r ? D(e, n.from, 1) : D(e, n.to, -1)) && c.matched ? i = r ? c.end.to : c.end.from : i = r ? n.to : n.from, d.cursor(i, r ? -1 : 1);
}
s(U, "moveBySyntax");
const mt = /* @__PURE__ */ s((e) => A(e, (t) => U(e.state, t, !m(e))), "cursorSyntaxLeft"), pt = /* @__PURE__ */ s((e) => A(e, (t) => U(e.state, t, m(e))), "cursorSyntaxRight");
function Se(e, t) {
  return A(e, (r) => {
    if (!r.empty)
      return P(r, t);
    let n = e.moveVertically(r, t);
    return n.head != r.head ? n : e.moveToLineBoundary(r, t);
  });
}
s(Se, "cursorByLine");
const xe = /* @__PURE__ */ s((e) => Se(e, !1), "cursorLineUp"), De = /* @__PURE__ */ s((e) => Se(e, !0), "cursorLineDown");
function Le(e) {
  let t = e.scrollDOM.clientHeight < e.scrollDOM.scrollHeight - 2, r = 0, n = 0, l;
  if (t) {
    for (let o of e.state.facet(L.scrollMargins)) {
      let c = o(e);
      c?.top && (r = Math.max(c?.top, r)), c?.bottom && (n = Math.max(c?.bottom, n));
    }
    l = e.scrollDOM.clientHeight - r - n;
  } else
    l = (e.dom.ownerDocument.defaultView || window).innerHeight;
  return {
    marginTop: r,
    marginBottom: n,
    selfScroll: t,
    height: Math.max(e.defaultLineHeight, l - 5)
  };
}
s(Le, "pageInfo");
function Ce(e, t) {
  let r = Le(e), { state: n } = e, l = C(n.selection, (c) => c.empty ? e.moveVertically(c, t, r.height) : P(c, t));
  if (l.eq(n.selection))
    return !1;
  let o;
  if (r.selfScroll) {
    let c = e.coordsAtPos(n.selection.main.head), i = e.scrollDOM.getBoundingClientRect(), u = i.top + r.marginTop, a = i.bottom - r.marginBottom;
    c && c.top > u && c.bottom < a && (o = L.scrollIntoView(l.main.head, { y: "start", yMargin: c.top - u }));
  }
  return e.dispatch(S(n, l), { effects: o }), !0;
}
s(Ce, "cursorByPage");
const j = /* @__PURE__ */ s((e) => Ce(e, !1), "cursorPageUp"), K = /* @__PURE__ */ s((e) => Ce(e, !0), "cursorPageDown");
function x(e, t, r) {
  let n = e.lineBlockAt(t.head), l = e.moveToLineBoundary(t, r);
  if (l.head == t.head && l.head != (r ? n.to : n.from) && (l = e.moveToLineBoundary(t, r, !1)), !r && l.head == n.from && n.length) {
    let o = /^\s*/.exec(e.state.sliceDoc(n.from, Math.min(n.from + 100, n.to)))[0].length;
    o && t.head != n.from + o && (l = d.cursor(n.from + o));
  }
  return l;
}
s(x, "moveByLineBoundary");
const gt = /* @__PURE__ */ s((e) => A(e, (t) => x(e, t, !0)), "cursorLineBoundaryForward"), yt = /* @__PURE__ */ s((e) => A(e, (t) => x(e, t, !1)), "cursorLineBoundaryBackward"), kt = /* @__PURE__ */ s((e) => A(e, (t) => x(e, t, !m(e))), "cursorLineBoundaryLeft"), At = /* @__PURE__ */ s((e) => A(e, (t) => x(e, t, m(e))), "cursorLineBoundaryRight"), Bt = /* @__PURE__ */ s((e) => A(e, (t) => d.cursor(e.lineBlockAt(t.head).from, 1)), "cursorLineStart"), St = /* @__PURE__ */ s((e) => A(e, (t) => d.cursor(e.lineBlockAt(t.head).to, -1)), "cursorLineEnd");
function xt(e, t, r) {
  let n = !1, l = C(e.selection, (o) => {
    let c = D(e, o.head, -1) || D(e, o.head, 1) || o.head > 0 && D(e, o.head - 1, 1) || o.head < e.doc.length && D(e, o.head + 1, -1);
    if (!c || !c.end)
      return o;
    n = !0;
    let i = c.start.from == o.head ? c.end.to : c.end.from;
    return d.cursor(i);
  });
  return n ? (t(S(e, l)), !0) : !1;
}
s(xt, "toMatchingBracket");
const Dt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => xt(e, t), "cursorMatchingBracket");
function k(e, t) {
  let r = C(e.state.selection, (n) => {
    let l = t(n);
    return d.range(n.anchor, l.head, l.goalColumn, l.bidiLevel || void 0);
  });
  return r.eq(e.state.selection) ? !1 : (e.dispatch(S(e.state, r)), !0);
}
s(k, "extendSel");
function Me(e, t) {
  return k(e, (r) => e.moveByChar(r, t));
}
s(Me, "selectByChar");
const Ee = /* @__PURE__ */ s((e) => Me(e, !m(e)), "selectCharLeft"), Oe = /* @__PURE__ */ s((e) => Me(e, m(e)), "selectCharRight");
function Te(e, t) {
  return k(e, (r) => e.moveByGroup(r, t));
}
s(Te, "selectByGroup");
const Lt = /* @__PURE__ */ s((e) => Te(e, !m(e)), "selectGroupLeft"), Ct = /* @__PURE__ */ s((e) => Te(e, m(e)), "selectGroupRight"), Mt = /* @__PURE__ */ s((e) => k(e, (t) => U(e.state, t, !m(e))), "selectSyntaxLeft"), Et = /* @__PURE__ */ s((e) => k(e, (t) => U(e.state, t, m(e))), "selectSyntaxRight");
function be(e, t) {
  return k(e, (r) => e.moveVertically(r, t));
}
s(be, "selectByLine");
const Re = /* @__PURE__ */ s((e) => be(e, !1), "selectLineUp"), Ie = /* @__PURE__ */ s((e) => be(e, !0), "selectLineDown");
function ve(e, t) {
  return k(e, (r) => e.moveVertically(r, t, Le(e).height));
}
s(ve, "selectByPage");
const w = /* @__PURE__ */ s((e) => ve(e, !1), "selectPageUp"), _ = /* @__PURE__ */ s((e) => ve(e, !0), "selectPageDown"), Ot = /* @__PURE__ */ s((e) => k(e, (t) => x(e, t, !0)), "selectLineBoundaryForward"), Tt = /* @__PURE__ */ s((e) => k(e, (t) => x(e, t, !1)), "selectLineBoundaryBackward"), bt = /* @__PURE__ */ s((e) => k(e, (t) => x(e, t, !m(e))), "selectLineBoundaryLeft"), Rt = /* @__PURE__ */ s((e) => k(e, (t) => x(e, t, m(e))), "selectLineBoundaryRight"), It = /* @__PURE__ */ s((e) => k(e, (t) => d.cursor(e.lineBlockAt(t.head).from)), "selectLineStart"), vt = /* @__PURE__ */ s((e) => k(e, (t) => d.cursor(e.lineBlockAt(t.head).to)), "selectLineEnd"), ee = /* @__PURE__ */ s(({ state: e, dispatch: t }) => (t(S(e, { anchor: 0 })), !0), "cursorDocStart"), te = /* @__PURE__ */ s(({ state: e, dispatch: t }) => (t(S(e, { anchor: e.doc.length })), !0), "cursorDocEnd"), ne = /* @__PURE__ */ s(({ state: e, dispatch: t }) => (t(S(e, { anchor: e.selection.main.anchor, head: 0 })), !0), "selectDocStart"), re = /* @__PURE__ */ s(({ state: e, dispatch: t }) => (t(S(e, { anchor: e.selection.main.anchor, head: e.doc.length })), !0), "selectDocEnd"), Nt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => (t(e.update({ selection: { anchor: 0, head: e.doc.length }, userEvent: "select" })), !0), "selectAll"), Pt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => {
  let r = V(e).map(({ from: n, to: l }) => d.range(n, Math.min(l + 1, e.doc.length)));
  return t(e.update({ selection: d.create(r), userEvent: "select" })), !0;
}, "selectLine"), Ut = /* @__PURE__ */ s(({ state: e, dispatch: t }) => {
  let r = C(e.selection, (n) => {
    let l = Q(e), o = l.resolveStack(n.from, 1);
    if (n.empty) {
      let c = l.resolveStack(n.from, -1);
      c.node.from >= o.node.from && c.node.to <= o.node.to && (o = c);
    }
    for (let c = o; c; c = c.next) {
      let { node: i } = c;
      if ((i.from < n.from && i.to >= n.to || i.to > n.to && i.from <= n.from) && c.next)
        return d.range(i.to, i.from);
    }
    return n;
  });
  return r.eq(e.selection) ? !1 : (t(S(e, r)), !0);
}, "selectParentSyntax"), Vt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => {
  let r = e.selection, n = null;
  return r.ranges.length > 1 ? n = d.create([r.main]) : r.main.empty || (n = d.create([d.cursor(r.main.head)])), n ? (t(S(e, n)), !0) : !1;
}, "simplifySelection");
function T(e, t) {
  if (e.state.readOnly)
    return !1;
  let r = "delete.selection", { state: n } = e, l = n.changeByRange((o) => {
    let { from: c, to: i } = o;
    if (c == i) {
      let u = t(o);
      u < c ? (r = "delete.backward", u = R(e, u, !1)) : u > c && (r = "delete.forward", u = R(e, u, !0)), c = Math.min(c, u), i = Math.max(i, u);
    } else
      c = R(e, c, !1), i = R(e, i, !0);
    return c == i ? { range: o } : { changes: { from: c, to: i }, range: d.cursor(c, c < o.head ? -1 : 1) };
  });
  return l.changes.empty ? !1 : (e.dispatch(n.update(l, {
    scrollIntoView: !0,
    userEvent: r,
    effects: r == "delete.selection" ? L.announce.of(n.phrase("Selection deleted")) : void 0
  })), !0);
}
s(T, "deleteBy");
function R(e, t, r) {
  if (e instanceof L)
    for (let n of e.state.facet(L.atomicRanges).map((l) => l(e)))
      n.between(t, t, (l, o) => {
        l < t && o > t && (t = r ? o : l);
      });
  return t;
}
s(R, "skipAtomic");
const Ne = /* @__PURE__ */ s((e, t, r) => T(e, (n) => {
  let l = n.from, { state: o } = e, c = o.doc.lineAt(l), i, u;
  if (r && !t && l > c.from && l < c.from + 200 && !/[^ \t]/.test(i = c.text.slice(0, l - c.from))) {
    if (i[i.length - 1] == "	")
      return l - 1;
    let a = W(i, o.tabSize), f = a % F(o) || F(o);
    for (let h = 0; h < f && i[i.length - 1 - h] == " "; h++)
      l--;
    u = l;
  } else
    u = O(c.text, l - c.from, t, t) + c.from, u == l && c.number != (t ? o.doc.lines : 1) ? u += t ? 1 : -1 : !t && /[\ufe00-\ufe0f]/.test(c.text.slice(u - c.from, l - c.from)) && (u = O(c.text, u - c.from, !1, !1) + c.from);
  return u;
}), "deleteByChar"), $ = /* @__PURE__ */ s((e) => Ne(e, !1, !0), "deleteCharBackward"), Pe = /* @__PURE__ */ s((e) => Ne(e, !0, !1), "deleteCharForward"), Ue = /* @__PURE__ */ s((e, t) => T(e, (r) => {
  let n = r.head, { state: l } = e, o = l.doc.lineAt(n), c = l.charCategorizer(n);
  for (let i = null; ; ) {
    if (n == (t ? o.to : o.from)) {
      n == r.head && o.number != (t ? l.doc.lines : 1) && (n += t ? 1 : -1);
      break;
    }
    let u = O(o.text, n - o.from, t) + o.from, a = o.text.slice(Math.min(n, u) - o.from, Math.max(n, u) - o.from), f = c(a);
    if (i != null && f != i)
      break;
    (a != " " || n != r.head) && (i = f), n = u;
  }
  return n;
}), "deleteByGroup"), Ve = /* @__PURE__ */ s((e) => Ue(e, !1), "deleteGroupBackward"), Jt = /* @__PURE__ */ s((e) => Ue(e, !0), "deleteGroupForward"), Gt = /* @__PURE__ */ s((e) => T(e, (t) => {
  let r = e.lineBlockAt(t.head).to;
  return t.head < r ? r : Math.min(e.state.doc.length, t.head + 1);
}), "deleteToLineEnd"), Ft = /* @__PURE__ */ s((e) => T(e, (t) => {
  let r = e.moveToLineBoundary(t, !1).head;
  return t.head > r ? r : Math.max(0, t.head - 1);
}), "deleteLineBoundaryBackward"), zt = /* @__PURE__ */ s((e) => T(e, (t) => {
  let r = e.moveToLineBoundary(t, !0).head;
  return t.head < r ? r : Math.min(e.state.doc.length, t.head + 1);
}), "deleteLineBoundaryForward"), Ht = /* @__PURE__ */ s(({ state: e, dispatch: t }) => {
  if (e.readOnly)
    return !1;
  let r = e.changeByRange((n) => ({
    changes: { from: n.from, to: n.to, insert: ce.of(["", ""]) },
    range: d.cursor(n.from)
  }));
  return t(e.update(r, { scrollIntoView: !0, userEvent: "input" })), !0;
}, "splitLine"), qt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => {
  if (e.readOnly)
    return !1;
  let r = e.changeByRange((n) => {
    if (!n.empty || n.from == 0 || n.from == e.doc.length)
      return { range: n };
    let l = n.from, o = e.doc.lineAt(l), c = l == o.from ? l - 1 : O(o.text, l - o.from, !1) + o.from, i = l == o.to ? l + 1 : O(o.text, l - o.from, !0) + o.from;
    return {
      changes: { from: c, to: i, insert: e.doc.slice(l, i).append(e.doc.slice(c, l)) },
      range: d.cursor(i)
    };
  });
  return r.changes.empty ? !1 : (t(e.update(r, { scrollIntoView: !0, userEvent: "move.character" })), !0);
}, "transposeChars");
function V(e) {
  let t = [], r = -1;
  for (let n of e.selection.ranges) {
    let l = e.doc.lineAt(n.from), o = e.doc.lineAt(n.to);
    if (!n.empty && n.to == o.from && (o = e.doc.lineAt(n.to - 1)), r >= l.number) {
      let c = t[t.length - 1];
      c.to = o.to, c.ranges.push(n);
    } else
      t.push({ from: l.from, to: o.to, ranges: [n] });
    r = o.number + 1;
  }
  return t;
}
s(V, "selectedLineBlocks");
function Je(e, t, r) {
  if (e.readOnly)
    return !1;
  let n = [], l = [];
  for (let o of V(e)) {
    if (r ? o.to == e.doc.length : o.from == 0)
      continue;
    let c = e.doc.lineAt(r ? o.to + 1 : o.from - 1), i = c.length + 1;
    if (r) {
      n.push({ from: o.to, to: c.to }, { from: o.from, insert: c.text + e.lineBreak });
      for (let u of o.ranges)
        l.push(d.range(Math.min(e.doc.length, u.anchor + i), Math.min(e.doc.length, u.head + i)));
    } else {
      n.push({ from: c.from, to: o.from }, { from: o.to, insert: e.lineBreak + c.text });
      for (let u of o.ranges)
        l.push(d.range(u.anchor - i, u.head - i));
    }
  }
  return n.length ? (t(e.update({
    changes: n,
    scrollIntoView: !0,
    selection: d.create(l, e.selection.mainIndex),
    userEvent: "move.line"
  })), !0) : !1;
}
s(Je, "moveLine");
const Kt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => Je(e, t, !1), "moveLineUp"), $t = /* @__PURE__ */ s(({ state: e, dispatch: t }) => Je(e, t, !0), "moveLineDown");
function Ge(e, t, r) {
  if (e.readOnly)
    return !1;
  let n = [];
  for (let l of V(e))
    r ? n.push({ from: l.from, insert: e.doc.slice(l.from, l.to) + e.lineBreak }) : n.push({ from: l.to, insert: e.lineBreak + e.doc.slice(l.from, l.to) });
  return t(e.update({ changes: n, scrollIntoView: !0, userEvent: "input.copyline" })), !0;
}
s(Ge, "copyLine");
const Wt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => Ge(e, t, !1), "copyLineUp"), Qt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => Ge(e, t, !0), "copyLineDown"), Xt = /* @__PURE__ */ s((e) => {
  if (e.state.readOnly)
    return !1;
  let { state: t } = e, r = t.changes(V(t).map(({ from: l, to: o }) => (l > 0 ? l-- : o < t.doc.length && o++, { from: l, to: o }))), n = C(t.selection, (l) => {
    let o;
    if (e.lineWrapping) {
      let c = e.lineBlockAt(l.head), i = e.coordsAtPos(l.head, l.assoc || 1);
      i && (o = c.bottom + e.documentTop - i.bottom + e.defaultLineHeight / 2);
    }
    return e.moveVertically(l, !0, o);
  }).map(r);
  return e.dispatch({ changes: r, selection: n, scrollIntoView: !0, userEvent: "delete.line" }), !0;
}, "deleteLine");
function Yt(e, t) {
  if (/\(\)|\[\]|\{\}/.test(e.sliceDoc(t - 1, t + 1)))
    return { from: t, to: t };
  let r = Q(e).resolveInner(t), n = r.childBefore(t), l = r.childAfter(t), o;
  return n && l && n.to <= t && l.from >= t && (o = n.type.prop(z.closedBy)) && o.indexOf(l.name) > -1 && e.doc.lineAt(n.to).from == e.doc.lineAt(l.from).from && !/\S/.test(e.sliceDoc(n.to, l.from)) ? { from: n.to, to: l.from } : null;
}
s(Yt, "isBetweenBrackets");
const oe = /* @__PURE__ */ Fe(!1), Zt = /* @__PURE__ */ Fe(!0);
function Fe(e) {
  return ({ state: t, dispatch: r }) => {
    if (t.readOnly)
      return !1;
    let n = t.changeByRange((l) => {
      let { from: o, to: c } = l, i = t.doc.lineAt(o), u = !e && o == c && Yt(t, o);
      e && (o = c = (c <= i.to ? i : t.doc.lineAt(c)).to);
      let a = new ue(t, { simulateBreak: o, simulateDoubleBreak: !!u }), f = fe(a, o);
      for (f == null && (f = W(/^\s*/.exec(t.doc.lineAt(o).text)[0], t.tabSize)); c < i.to && /\s/.test(i.text[c - i.from]); )
        c++;
      u ? { from: o, to: c } = u : o > i.from && o < i.from + 100 && !/\S/.test(i.text.slice(0, o)) && (o = i.from);
      let h = ["", I(t, f)];
      return u && h.push(I(t, a.lineIndent(i.from, -1))), {
        changes: { from: o, to: c, insert: ce.of(h) },
        range: d.cursor(o + 1 + h[1].length)
      };
    });
    return r(t.update(n, { scrollIntoView: !0, userEvent: "input" })), !0;
  };
}
s(Fe, "newlineAndIndent");
function Z(e, t) {
  let r = -1;
  return e.changeByRange((n) => {
    let l = [];
    for (let c = n.from; c <= n.to; ) {
      let i = e.doc.lineAt(c);
      i.number > r && (n.empty || n.to > i.from) && (t(i, l, n), r = i.number), c = i.to + 1;
    }
    let o = e.changes(l);
    return {
      changes: l,
      range: d.range(o.mapPos(n.anchor, 1), o.mapPos(n.head, 1))
    };
  });
}
s(Z, "changeBySelectedLine");
const jt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => {
  if (e.readOnly)
    return !1;
  let r = /* @__PURE__ */ Object.create(null), n = new ue(e, { overrideIndentation: /* @__PURE__ */ s((o) => {
    let c = r[o];
    return c ?? -1;
  }, "overrideIndentation") }), l = Z(e, (o, c, i) => {
    let u = fe(n, o.from);
    if (u == null)
      return;
    /\S/.test(o.text) || (u = 0);
    let a = /^\s*/.exec(o.text)[0], f = I(e, u);
    (a != f || i.from < o.from + a.length) && (r[o.from] = u, c.push({ from: o.from, to: o.from + a.length, insert: f }));
  });
  return l.changes.empty || t(e.update(l, { userEvent: "indent" })), !0;
}, "indentSelection"), wt = /* @__PURE__ */ s(({ state: e, dispatch: t }) => e.readOnly ? !1 : (t(e.update(Z(e, (r, n) => {
  n.push({ from: r.from, insert: e.facet(Qe) });
}), { userEvent: "input.indent" })), !0), "indentMore"), _t = /* @__PURE__ */ s(({ state: e, dispatch: t }) => e.readOnly ? !1 : (t(e.update(Z(e, (r, n) => {
  let l = /^\s*/.exec(r.text)[0];
  if (!l)
    return;
  let o = W(l, e.tabSize), c = 0, i = I(e, Math.max(0, o - F(e)));
  for (; c < l.length && c < i.length && l.charCodeAt(c) == i.charCodeAt(c); )
    c++;
  n.push({ from: r.from + c, to: r.from + l.length, insert: i.slice(c) });
}), { userEvent: "delete.dedent" })), !0), "indentLess"), en = /* @__PURE__ */ s((e) => (e.setTabFocusMode(), !0), "toggleTabFocusMode"), tn = [
  { key: "Ctrl-b", run: ke, shift: Ee, preventDefault: !0 },
  { key: "Ctrl-f", run: Ae, shift: Oe },
  { key: "Ctrl-p", run: xe, shift: Re },
  { key: "Ctrl-n", run: De, shift: Ie },
  { key: "Ctrl-a", run: Bt, shift: It },
  { key: "Ctrl-e", run: St, shift: vt },
  { key: "Ctrl-d", run: Pe },
  { key: "Ctrl-h", run: $ },
  { key: "Ctrl-k", run: Gt },
  { key: "Ctrl-Alt-h", run: Ve },
  { key: "Ctrl-o", run: Ht },
  { key: "Ctrl-t", run: qt },
  { key: "Ctrl-v", run: K }
], nn = /* @__PURE__ */ [
  { key: "ArrowLeft", run: ke, shift: Ee, preventDefault: !0 },
  { key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: at, shift: Lt, preventDefault: !0 },
  { mac: "Cmd-ArrowLeft", run: kt, shift: bt, preventDefault: !0 },
  { key: "ArrowRight", run: Ae, shift: Oe, preventDefault: !0 },
  { key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: ht, shift: Ct, preventDefault: !0 },
  { mac: "Cmd-ArrowRight", run: At, shift: Rt, preventDefault: !0 },
  { key: "ArrowUp", run: xe, shift: Re, preventDefault: !0 },
  { mac: "Cmd-ArrowUp", run: ee, shift: ne },
  { mac: "Ctrl-ArrowUp", run: j, shift: w },
  { key: "ArrowDown", run: De, shift: Ie, preventDefault: !0 },
  { mac: "Cmd-ArrowDown", run: te, shift: re },
  { mac: "Ctrl-ArrowDown", run: K, shift: _ },
  { key: "PageUp", run: j, shift: w },
  { key: "PageDown", run: K, shift: _ },
  { key: "Home", run: yt, shift: Tt, preventDefault: !0 },
  { key: "Mod-Home", run: ee, shift: ne },
  { key: "End", run: gt, shift: Ot, preventDefault: !0 },
  { key: "Mod-End", run: te, shift: re },
  { key: "Enter", run: oe, shift: oe },
  { key: "Mod-a", run: Nt },
  { key: "Backspace", run: $, shift: $ },
  { key: "Delete", run: Pe },
  { key: "Mod-Backspace", mac: "Alt-Backspace", run: Ve },
  { key: "Mod-Delete", mac: "Alt-Delete", run: Jt },
  { mac: "Mod-Backspace", run: Ft },
  { mac: "Mod-Delete", run: zt }
].concat(/* @__PURE__ */ tn.map((e) => ({ mac: e.key, run: e.run, shift: e.shift }))), an = /* @__PURE__ */ [
  { key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: mt, shift: Mt },
  { key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: pt, shift: Et },
  { key: "Alt-ArrowUp", run: Kt },
  { key: "Shift-Alt-ArrowUp", run: Wt },
  { key: "Alt-ArrowDown", run: $t },
  { key: "Shift-Alt-ArrowDown", run: Qt },
  { key: "Escape", run: Vt },
  { key: "Mod-Enter", run: Zt },
  { key: "Alt-l", mac: "Ctrl-l", run: Pt },
  { key: "Mod-i", run: Ut, preventDefault: !0 },
  { key: "Mod-[", run: _t },
  { key: "Mod-]", run: wt },
  { key: "Mod-Alt-\\", run: jt },
  { key: "Shift-Mod-k", run: Xt },
  { key: "Shift-Mod-\\", run: Dt },
  { key: "Mod-/", run: Xe },
  { key: "Alt-A", run: Ze },
  { key: "Ctrl-m", mac: "Shift-Alt-m", run: en }
].concat(nn);
export {
  Qt as copyLineDown,
  Wt as copyLineUp,
  ke as cursorCharLeft,
  Ae as cursorCharRight,
  te as cursorDocEnd,
  ee as cursorDocStart,
  at as cursorGroupLeft,
  ht as cursorGroupRight,
  yt as cursorLineBoundaryBackward,
  gt as cursorLineBoundaryForward,
  kt as cursorLineBoundaryLeft,
  At as cursorLineBoundaryRight,
  De as cursorLineDown,
  St as cursorLineEnd,
  Bt as cursorLineStart,
  xe as cursorLineUp,
  Dt as cursorMatchingBracket,
  K as cursorPageDown,
  j as cursorPageUp,
  mt as cursorSyntaxLeft,
  pt as cursorSyntaxRight,
  an as defaultKeymap,
  $ as deleteCharBackward,
  Pe as deleteCharForward,
  Ve as deleteGroupBackward,
  Jt as deleteGroupForward,
  Xt as deleteLine,
  Ft as deleteLineBoundaryBackward,
  zt as deleteLineBoundaryForward,
  Gt as deleteToLineEnd,
  tn as emacsStyleKeymap,
  un as history,
  fn as historyKeymap,
  _t as indentLess,
  wt as indentMore,
  jt as indentSelection,
  Zt as insertBlankLine,
  oe as insertNewlineAndIndent,
  nt as invertedEffects,
  tt as isolateHistory,
  $t as moveLineDown,
  Kt as moveLineUp,
  q as redo,
  ot as redoSelection,
  Nt as selectAll,
  Ee as selectCharLeft,
  Oe as selectCharRight,
  re as selectDocEnd,
  ne as selectDocStart,
  Lt as selectGroupLeft,
  Ct as selectGroupRight,
  Pt as selectLine,
  Tt as selectLineBoundaryBackward,
  Ot as selectLineBoundaryForward,
  bt as selectLineBoundaryLeft,
  Rt as selectLineBoundaryRight,
  Ie as selectLineDown,
  vt as selectLineEnd,
  It as selectLineStart,
  Re as selectLineUp,
  _ as selectPageDown,
  w as selectPageUp,
  Ut as selectParentSyntax,
  Mt as selectSyntaxLeft,
  Et as selectSyntaxRight,
  Vt as simplifySelection,
  Ht as splitLine,
  nn as standardKeymap,
  Ze as toggleBlockComment,
  je as toggleBlockCommentByLine,
  Xe as toggleComment,
  Ye as toggleLineComment,
  en as toggleTabFocusMode,
  qt as transposeChars,
  me as undo,
  rt as undoSelection
};
