import { s as __toESM } from "./chunk-BNovOVIE.js";
import { t as require_react } from "./react-DA-nE2FX.js";
import { t as require_jsx_runtime } from "./jsx-runtime-COBk7ree.js";
import { l as historyKeymap, o as defaultKeymap, r as lintKeymap, s as history, t as _extends, u as indentWithTab } from "./extends-vAi97cpa.js";
import { $ as ViewPlugin, At as Prec, B as tags, Bt as combineConfig, C as foldKeymap, Dt as EditorState, Et as EditorSelection, F as syntaxHighlighting, Ft as StateField, Ht as findClusterBreak, Mt as RangeSetBuilder, Ot as Facet, Pt as StateEffect, Rt as codePointAt, Ut as fromCodePoint, Y as Decoration, Z as EditorView, _t as showDialog, a as HighlightStyle, bt as crelt, ct as highlightActiveLineGutter, dt as keymap, ft as lineNumbers, g as defaultHighlightStyle, gt as runScopeHandlers, ht as rectangularSelection, it as getPanel, j as indentUnit, k as indentOnInput, lt as highlightSpecialChars, mt as placeholder, nt as drawSelection, p as bracketMatching, rt as dropCursor, st as highlightActiveLine, tt as crosshairCursor, vt as showPanel, wt as CharCategory, x as foldGutter, xt as Annotation, zt as codePointSize } from "./dist-CCADb07R.js";
import { a as closeBracketsKeymap, c as completionKeymap, i as closeBrackets, r as autocompletion } from "./dist-JEhxD_cn.js";
var basicNormalize = typeof String.prototype.normalize == "function" ? (e2) => e2.normalize("NFKD") : (e2) => e2, SearchCursor = class {
  constructor(e2, y, b = 0, x = e2.length, S, C) {
    this.test = C, this.value = {
      from: 0,
      to: 0
    }, this.done = false, this.matches = [], this.buffer = "", this.bufferPos = 0, this.iter = e2.iterRange(b, x), this.bufferStart = b, this.normalize = S ? (e3) => S(basicNormalize(e3)) : basicNormalize, this.query = this.normalize(y);
  }
  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 codePointAt(this.buffer, this.bufferPos);
  }
  next() {
    for (; this.matches.length; ) this.matches.pop();
    return this.nextOverlapping();
  }
  nextOverlapping() {
    for (; ; ) {
      let e2 = this.peek();
      if (e2 < 0) return this.done = true, this;
      let y = fromCodePoint(e2), b = this.bufferStart + this.bufferPos;
      this.bufferPos += codePointSize(e2);
      let x = this.normalize(y);
      if (x.length) for (let e3 = 0, S = b; ; e3++) {
        let C = x.charCodeAt(e3), w = this.match(C, S, this.bufferPos + this.bufferStart);
        if (e3 == x.length - 1) {
          if (w) return this.value = w, this;
          break;
        }
        S == b && e3 < y.length && y.charCodeAt(e3) == C && S++;
      }
    }
  }
  match(e2, y, b) {
    let x = null;
    for (let y2 = 0; y2 < this.matches.length; y2 += 2) {
      let S = this.matches[y2], C = false;
      this.query.charCodeAt(S) == e2 && (S == this.query.length - 1 ? x = {
        from: this.matches[y2 + 1],
        to: b
      } : (this.matches[y2]++, C = true)), C || (this.matches.splice(y2, 2), y2 -= 2);
    }
    return this.query.charCodeAt(0) == e2 && (this.query.length == 1 ? x = {
      from: y,
      to: b
    } : this.matches.push(1, y)), x && this.test && !this.test(x.from, x.to, this.buffer, this.bufferStart) && (x = null), x;
  }
};
typeof Symbol < "u" && (SearchCursor.prototype[Symbol.iterator] = function() {
  return this;
});
var empty = {
  from: -1,
  to: -1,
  match: /* @__PURE__ */ /.*/.exec("")
}, baseFlags = "gm" + (/x/.unicode == null ? "" : "u"), RegExpCursor = class {
  constructor(e2, y, b, x = 0, S = e2.length) {
    if (this.text = e2, this.to = S, this.curLine = "", this.done = false, this.value = empty, /\\[sWDnr]|\n|\r|\[\^/.test(y)) return new MultilineRegExpCursor(e2, y, b, x, S);
    this.re = new RegExp(y, baseFlags + ((b == null ? void 0 : b.ignoreCase) ? "i" : "")), this.test = b == null ? void 0 : b.test, this.iter = e2.iter(), this.curLineStart = e2.lineAt(x).from, this.matchPos = toCharEnd(e2, x), this.getLine(this.curLineStart);
  }
  getLine(e2) {
    this.iter.next(e2), 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);
  }
  next() {
    for (let e2 = this.matchPos - this.curLineStart; ; ) {
      this.re.lastIndex = e2;
      let y = this.matchPos <= this.to && this.re.exec(this.curLine);
      if (y) {
        let b = this.curLineStart + y.index, x = b + y[0].length;
        if (this.matchPos = toCharEnd(this.text, x + (b == x ? 1 : 0)), b == this.curLineStart + this.curLine.length && this.nextLine(), (b < x || b > this.value.to) && (!this.test || this.test(b, x, y))) return this.value = {
          from: b,
          to: x,
          match: y
        }, this;
        e2 = this.matchPos - this.curLineStart;
      } else if (this.curLineStart + this.curLine.length < this.to) this.nextLine(), e2 = 0;
      else return this.done = true, this;
    }
  }
}, flattened = /* @__PURE__ */ new WeakMap(), FlattenedDoc = class e {
  constructor(e2, y) {
    this.from = e2, this.text = y;
  }
  get to() {
    return this.from + this.text.length;
  }
  static get(y, b, x) {
    let S = flattened.get(y);
    if (!S || S.from >= x || S.to <= b) {
      let S2 = new e(b, y.sliceString(b, x));
      return flattened.set(y, S2), S2;
    }
    if (S.from == b && S.to == x) return S;
    let { text: C, from: w } = S;
    return w > b && (C = y.sliceString(b, w) + C, w = b), S.to < x && (C += y.sliceString(S.to, x)), flattened.set(y, new e(w, C)), new e(b, C.slice(b - w, x - w));
  }
}, MultilineRegExpCursor = class {
  constructor(e2, y, b, x, S) {
    this.text = e2, this.to = S, this.done = false, this.value = empty, this.matchPos = toCharEnd(e2, x), this.re = new RegExp(y, baseFlags + ((b == null ? void 0 : b.ignoreCase) ? "i" : "")), this.test = b == null ? void 0 : b.test, this.flat = FlattenedDoc.get(e2, x, this.chunkEnd(x + 5e3));
  }
  chunkEnd(e2) {
    return e2 >= this.to ? this.to : this.text.lineAt(e2).to;
  }
  next() {
    for (; ; ) {
      let e2 = this.re.lastIndex = this.matchPos - this.flat.from, y = this.re.exec(this.flat.text);
      if (y && !y[0] && y.index == e2 && (this.re.lastIndex = e2 + 1, y = this.re.exec(this.flat.text)), y) {
        let e3 = this.flat.from + y.index, b = e3 + y[0].length;
        if ((this.flat.to >= this.to || y.index + y[0].length <= this.flat.text.length - 10) && (!this.test || this.test(e3, b, y))) return this.value = {
          from: e3,
          to: b,
          match: y
        }, this.matchPos = toCharEnd(this.text, b + (e3 == b ? 1 : 0)), this;
      }
      if (this.flat.to == this.to) return this.done = true, this;
      this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
    }
  }
};
typeof Symbol < "u" && (RegExpCursor.prototype[Symbol.iterator] = MultilineRegExpCursor.prototype[Symbol.iterator] = function() {
  return this;
});
function validRegExp(e2) {
  try {
    return new RegExp(e2, baseFlags), true;
  } catch {
    return false;
  }
}
function toCharEnd(e2, y) {
  if (y >= e2.length) return y;
  let b = e2.lineAt(y), x;
  for (; y < b.to && (x = b.text.charCodeAt(y - b.from)) >= 56320 && x < 57344; ) y++;
  return y;
}
var gotoLine = (e2) => {
  let { state: y } = e2, b = String(y.doc.lineAt(e2.state.selection.main.head).number), { close: x, result: S } = showDialog(e2, {
    label: y.phrase("Go to line"),
    input: {
      type: "text",
      name: "line",
      value: b
    },
    focus: true,
    submitLabel: y.phrase("go")
  });
  return S.then((b2) => {
    let S2 = b2 && /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(b2.elements.line.value);
    if (!S2) {
      e2.dispatch({ effects: x });
      return;
    }
    let C = y.doc.lineAt(y.selection.main.head), [, w, T, E, D] = S2, O = E ? +E.slice(1) : 0, k = T ? +T : C.number;
    if (T && D) {
      let e3 = k / 100;
      w && (e3 = e3 * (w == "-" ? -1 : 1) + C.number / y.doc.lines), k = Math.round(y.doc.lines * e3);
    } else T && w && (k = k * (w == "-" ? -1 : 1) + C.number);
    let A = y.doc.line(Math.max(1, Math.min(y.doc.lines, k))), j = EditorSelection.cursor(A.from + Math.max(0, Math.min(O, A.length)));
    e2.dispatch({
      effects: [x, EditorView.scrollIntoView(j.from, { y: "center" })],
      selection: j
    });
  }), true;
}, defaultHighlightOptions = {
  highlightWordAroundCursor: false,
  minSelectionLength: 1,
  maxMatches: 100,
  wholeWords: false
}, highlightConfig = /* @__PURE__ */ Facet.define({ combine(e2) {
  return combineConfig(e2, defaultHighlightOptions, {
    highlightWordAroundCursor: (e3, y) => e3 || y,
    minSelectionLength: Math.min,
    maxMatches: Math.min
  });
} });
function highlightSelectionMatches(e2) {
  let y = [defaultTheme, matchHighlighter];
  return e2 && y.push(highlightConfig.of(e2)), y;
}
var matchDeco = /* @__PURE__ */ Decoration.mark({ class: "cm-selectionMatch" }), mainMatchDeco = /* @__PURE__ */ Decoration.mark({ class: "cm-selectionMatch cm-selectionMatch-main" });
function insideWordBoundaries(e2, y, b, x) {
  return (b == 0 || e2(y.sliceDoc(b - 1, b)) != CharCategory.Word) && (x == y.doc.length || e2(y.sliceDoc(x, x + 1)) != CharCategory.Word);
}
function insideWord(e2, y, b, x) {
  return e2(y.sliceDoc(b, b + 1)) == CharCategory.Word && e2(y.sliceDoc(x - 1, x)) == CharCategory.Word;
}
var matchHighlighter = /* @__PURE__ */ ViewPlugin.fromClass(class {
  constructor(e2) {
    this.decorations = this.getDeco(e2);
  }
  update(e2) {
    (e2.selectionSet || e2.docChanged || e2.viewportChanged) && (this.decorations = this.getDeco(e2.view));
  }
  getDeco(e2) {
    let y = e2.state.facet(highlightConfig), { state: b } = e2, x = b.selection;
    if (x.ranges.length > 1) return Decoration.none;
    let S = x.main, C, w = null;
    if (S.empty) {
      if (!y.highlightWordAroundCursor) return Decoration.none;
      let e3 = b.wordAt(S.head);
      if (!e3) return Decoration.none;
      w = b.charCategorizer(S.head), C = b.sliceDoc(e3.from, e3.to);
    } else {
      let e3 = S.to - S.from;
      if (e3 < y.minSelectionLength || e3 > 200) return Decoration.none;
      if (y.wholeWords) {
        if (C = b.sliceDoc(S.from, S.to), w = b.charCategorizer(S.head), !(insideWordBoundaries(w, b, S.from, S.to) && insideWord(w, b, S.from, S.to))) return Decoration.none;
      } else if (C = b.sliceDoc(S.from, S.to), !C) return Decoration.none;
    }
    let T = [];
    for (let x2 of e2.visibleRanges) {
      let e3 = new SearchCursor(b.doc, C, x2.from, x2.to);
      for (; !e3.next().done; ) {
        let { from: x3, to: C2 } = e3.value;
        if ((!w || insideWordBoundaries(w, b, x3, C2)) && (S.empty && x3 <= S.from && C2 >= S.to ? T.push(mainMatchDeco.range(x3, C2)) : (x3 >= S.to || C2 <= S.from) && T.push(matchDeco.range(x3, C2)), T.length > y.maxMatches)) return Decoration.none;
      }
    }
    return Decoration.set(T);
  }
}, { decorations: (e2) => e2.decorations }), defaultTheme = /* @__PURE__ */ EditorView.baseTheme({
  ".cm-selectionMatch": { backgroundColor: "#99ff7780" },
  ".cm-searchMatch .cm-selectionMatch": { backgroundColor: "transparent" }
}), selectWord = ({ state: e2, dispatch: y }) => {
  let { selection: b } = e2, x = EditorSelection.create(b.ranges.map((y2) => e2.wordAt(y2.head) || EditorSelection.cursor(y2.head)), b.mainIndex);
  return x.eq(b) ? false : (y(e2.update({ selection: x })), true);
};
function findNextOccurrence(e2, y) {
  let { main: b, ranges: x } = e2.selection, S = e2.wordAt(b.head), C = S && S.from == b.from && S.to == b.to;
  for (let b2 = false, S2 = new SearchCursor(e2.doc, y, x[x.length - 1].to); ; ) if (S2.next(), S2.done) {
    if (b2) return null;
    S2 = new SearchCursor(e2.doc, y, 0, Math.max(0, x[x.length - 1].from - 1)), b2 = true;
  } else {
    if (b2 && x.some((e3) => e3.from == S2.value.from)) continue;
    if (C) {
      let y2 = e2.wordAt(S2.value.from);
      if (!y2 || y2.from != S2.value.from || y2.to != S2.value.to) continue;
    }
    return S2.value;
  }
}
var selectNextOccurrence = ({ state: e2, dispatch: y }) => {
  let { ranges: b } = e2.selection;
  if (b.some((e3) => e3.from === e3.to)) return selectWord({
    state: e2,
    dispatch: y
  });
  let x = e2.sliceDoc(b[0].from, b[0].to);
  if (e2.selection.ranges.some((y2) => e2.sliceDoc(y2.from, y2.to) != x)) return false;
  let S = findNextOccurrence(e2, x);
  return S ? (y(e2.update({
    selection: e2.selection.addRange(EditorSelection.range(S.from, S.to), false),
    effects: EditorView.scrollIntoView(S.to)
  })), true) : false;
}, searchConfigFacet = /* @__PURE__ */ Facet.define({ combine(e2) {
  return combineConfig(e2, {
    top: false,
    caseSensitive: false,
    literal: false,
    regexp: false,
    wholeWord: false,
    createPanel: (e3) => new SearchPanel(e3),
    scrollToMatch: (e3) => EditorView.scrollIntoView(e3)
  });
} }), SearchQuery = class {
  constructor(e2) {
    this.search = e2.search, this.caseSensitive = !!e2.caseSensitive, this.literal = !!e2.literal, this.regexp = !!e2.regexp, this.replace = e2.replace || "", this.valid = !!this.search && (!this.regexp || validRegExp(this.search)), this.unquoted = this.unquote(this.search), this.wholeWord = !!e2.wholeWord, this.test = e2.test;
  }
  unquote(e2) {
    return this.literal ? e2 : e2.replace(/\\([nrt\\])/g, (e3, y) => y == "n" ? "\n" : y == "r" ? "\r" : y == "t" ? "	" : "\\");
  }
  eq(e2) {
    return this.search == e2.search && this.replace == e2.replace && this.caseSensitive == e2.caseSensitive && this.regexp == e2.regexp && this.wholeWord == e2.wholeWord && this.test == e2.test;
  }
  create() {
    return this.regexp ? new RegExpQuery(this) : new StringQuery(this);
  }
  getCursor(e2, y = 0, b) {
    let x = e2.doc ? e2 : EditorState.create({ doc: e2 });
    return b ?? (b = x.doc.length), this.regexp ? regexpCursor(this, x, y, b) : stringCursor(this, x, y, b);
  }
}, QueryType = class {
  constructor(e2) {
    this.spec = e2;
  }
};
function wrapStringTest(e2, y, b) {
  return (x, S, C, w) => b && !b(x, S, C, w) ? false : e2(x >= w && S <= w + C.length ? C.slice(x - w, S - w) : y.doc.sliceString(x, S), y, x, S);
}
function stringCursor(e2, y, b, x) {
  let S;
  return e2.wholeWord && (S = stringWordTest(y.doc, y.charCategorizer(y.selection.main.head))), e2.test && (S = wrapStringTest(e2.test, y, S)), new SearchCursor(y.doc, e2.unquoted, b, x, e2.caseSensitive ? void 0 : (e3) => e3.toLowerCase(), S);
}
function stringWordTest(e2, y) {
  return (b, x, S, C) => ((C > b || C + S.length < x) && (C = Math.max(0, b - 2), S = e2.sliceString(C, Math.min(e2.length, x + 2))), (y(charBefore(S, b - C)) != CharCategory.Word || y(charAfter(S, b - C)) != CharCategory.Word) && (y(charAfter(S, x - C)) != CharCategory.Word || y(charBefore(S, x - C)) != CharCategory.Word));
}
var StringQuery = class extends QueryType {
  constructor(e2) {
    super(e2);
  }
  nextMatch(e2, y, b) {
    let x = stringCursor(this.spec, e2, b, e2.doc.length).nextOverlapping();
    if (x.done) {
      let b2 = Math.min(e2.doc.length, y + this.spec.unquoted.length);
      x = stringCursor(this.spec, e2, 0, b2).nextOverlapping();
    }
    return x.done || x.value.from == y && x.value.to == b ? null : x.value;
  }
  prevMatchInRange(e2, y, b) {
    for (let x = b; ; ) {
      let b2 = Math.max(y, x - 1e4 - this.spec.unquoted.length), S = stringCursor(this.spec, e2, b2, x), C = null;
      for (; !S.nextOverlapping().done; ) C = S.value;
      if (C) return C;
      if (b2 == y) return null;
      x -= 1e4;
    }
  }
  prevMatch(e2, y, b) {
    let x = this.prevMatchInRange(e2, 0, y);
    return x || (x = this.prevMatchInRange(e2, Math.max(0, b - this.spec.unquoted.length), e2.doc.length)), x && (x.from != y || x.to != b) ? x : null;
  }
  getReplacement(e2) {
    return this.spec.unquote(this.spec.replace);
  }
  matchAll(e2, y) {
    let b = stringCursor(this.spec, e2, 0, e2.doc.length), x = [];
    for (; !b.next().done; ) {
      if (x.length >= y) return null;
      x.push(b.value);
    }
    return x;
  }
  highlight(e2, y, b, x) {
    let S = stringCursor(this.spec, e2, Math.max(0, y - this.spec.unquoted.length), Math.min(b + this.spec.unquoted.length, e2.doc.length));
    for (; !S.next().done; ) x(S.value.from, S.value.to);
  }
};
function wrapRegexpTest(e2, y, b) {
  return (x, S, C) => (!b || b(x, S, C)) && e2(C[0], y, x, S);
}
function regexpCursor(e2, y, b, x) {
  let S;
  return e2.wholeWord && (S = regexpWordTest(y.charCategorizer(y.selection.main.head))), e2.test && (S = wrapRegexpTest(e2.test, y, S)), new RegExpCursor(y.doc, e2.search, {
    ignoreCase: !e2.caseSensitive,
    test: S
  }, b, x);
}
function charBefore(e2, y) {
  return e2.slice(findClusterBreak(e2, y, false), y);
}
function charAfter(e2, y) {
  return e2.slice(y, findClusterBreak(e2, y));
}
function regexpWordTest(e2) {
  return (y, b, x) => !x[0].length || (e2(charBefore(x.input, x.index)) != CharCategory.Word || e2(charAfter(x.input, x.index)) != CharCategory.Word) && (e2(charAfter(x.input, x.index + x[0].length)) != CharCategory.Word || e2(charBefore(x.input, x.index + x[0].length)) != CharCategory.Word);
}
var RegExpQuery = class extends QueryType {
  nextMatch(e2, y, b) {
    let x = regexpCursor(this.spec, e2, b, e2.doc.length).next();
    return x.done && (x = regexpCursor(this.spec, e2, 0, y).next()), x.done ? null : x.value;
  }
  prevMatchInRange(e2, y, b) {
    for (let x = 1; ; x++) {
      let S = Math.max(y, b - x * 1e4), C = regexpCursor(this.spec, e2, S, b), w = null;
      for (; !C.next().done; ) w = C.value;
      if (w && (S == y || w.from > S + 10)) return w;
      if (S == y) return null;
    }
  }
  prevMatch(e2, y, b) {
    return this.prevMatchInRange(e2, 0, y) || this.prevMatchInRange(e2, b, e2.doc.length);
  }
  getReplacement(e2) {
    return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g, (y, b) => {
      if (b == "&") return e2.match[0];
      if (b == "$") return "$";
      for (let y2 = b.length; y2 > 0; y2--) {
        let x = +b.slice(0, y2);
        if (x > 0 && x < e2.match.length) return e2.match[x] + b.slice(y2);
      }
      return y;
    });
  }
  matchAll(e2, y) {
    let b = regexpCursor(this.spec, e2, 0, e2.doc.length), x = [];
    for (; !b.next().done; ) {
      if (x.length >= y) return null;
      x.push(b.value);
    }
    return x;
  }
  highlight(e2, y, b, x) {
    let S = regexpCursor(this.spec, e2, Math.max(0, y - 250), Math.min(b + 250, e2.doc.length));
    for (; !S.next().done; ) x(S.value.from, S.value.to);
  }
}, setSearchQuery = /* @__PURE__ */ StateEffect.define(), togglePanel = /* @__PURE__ */ StateEffect.define(), searchState = /* @__PURE__ */ StateField.define({
  create(e2) {
    return new SearchState(defaultQuery(e2).create(), null);
  },
  update(e2, y) {
    for (let b of y.effects) b.is(setSearchQuery) ? e2 = new SearchState(b.value.create(), e2.panel) : b.is(togglePanel) && (e2 = new SearchState(e2.query, b.value ? createSearchPanel : null));
    return e2;
  },
  provide: (e2) => showPanel.from(e2, (e3) => e3.panel)
}), SearchState = class {
  constructor(e2, y) {
    this.query = e2, this.panel = y;
  }
}, matchMark = /* @__PURE__ */ Decoration.mark({ class: "cm-searchMatch" }), selectedMatchMark = /* @__PURE__ */ Decoration.mark({ class: "cm-searchMatch cm-searchMatch-selected" }), searchHighlighter = /* @__PURE__ */ ViewPlugin.fromClass(class {
  constructor(e2) {
    this.view = e2, this.decorations = this.highlight(e2.state.field(searchState));
  }
  update(e2) {
    let y = e2.state.field(searchState);
    (y != e2.startState.field(searchState) || e2.docChanged || e2.selectionSet || e2.viewportChanged) && (this.decorations = this.highlight(y));
  }
  highlight({ query: e2, panel: y }) {
    if (!y || !e2.spec.valid) return Decoration.none;
    let { view: b } = this, x = new RangeSetBuilder();
    for (let y2 = 0, S = b.visibleRanges, C = S.length; y2 < C; y2++) {
      let { from: w, to: T } = S[y2];
      for (; y2 < C - 1 && T > S[y2 + 1].from - 500; ) T = S[++y2].to;
      e2.highlight(b.state, w, T, (e3, y3) => {
        let S2 = b.state.selection.ranges.some((b2) => b2.from == e3 && b2.to == y3);
        x.add(e3, y3, S2 ? selectedMatchMark : matchMark);
      });
    }
    return x.finish();
  }
}, { decorations: (e2) => e2.decorations });
function searchCommand(e2) {
  return (y) => {
    let b = y.state.field(searchState, false);
    return b && b.query.spec.valid ? e2(y, b) : openSearchPanel(y);
  };
}
var findNext = /* @__PURE__ */ searchCommand((e2, { query: y }) => {
  let { to: b } = e2.state.selection.main, x = y.nextMatch(e2.state, b, b);
  if (!x) return false;
  let S = EditorSelection.single(x.from, x.to), C = e2.state.facet(searchConfigFacet);
  return e2.dispatch({
    selection: S,
    effects: [announceMatch(e2, x), C.scrollToMatch(S.main, e2)],
    userEvent: "select.search"
  }), selectSearchInput(e2), true;
}), findPrevious = /* @__PURE__ */ searchCommand((e2, { query: y }) => {
  let { state: b } = e2, { from: x } = b.selection.main, S = y.prevMatch(b, x, x);
  if (!S) return false;
  let C = EditorSelection.single(S.from, S.to), w = e2.state.facet(searchConfigFacet);
  return e2.dispatch({
    selection: C,
    effects: [announceMatch(e2, S), w.scrollToMatch(C.main, e2)],
    userEvent: "select.search"
  }), selectSearchInput(e2), true;
}), selectMatches = /* @__PURE__ */ searchCommand((e2, { query: y }) => {
  let b = y.matchAll(e2.state, 1e3);
  return !b || !b.length ? false : (e2.dispatch({
    selection: EditorSelection.create(b.map((e3) => EditorSelection.range(e3.from, e3.to))),
    userEvent: "select.search.matches"
  }), true);
}), selectSelectionMatches = ({ state: e2, dispatch: y }) => {
  let b = e2.selection;
  if (b.ranges.length > 1 || b.main.empty) return false;
  let { from: x, to: S } = b.main, C = [], w = 0;
  for (let y2 = new SearchCursor(e2.doc, e2.sliceDoc(x, S)); !y2.next().done; ) {
    if (C.length > 1e3) return false;
    y2.value.from == x && (w = C.length), C.push(EditorSelection.range(y2.value.from, y2.value.to));
  }
  return y(e2.update({
    selection: EditorSelection.create(C, w),
    userEvent: "select.search.matches"
  })), true;
}, replaceNext = /* @__PURE__ */ searchCommand((e2, { query: y }) => {
  let { state: b } = e2, { from: x, to: S } = b.selection.main;
  if (b.readOnly) return false;
  let C = y.nextMatch(b, x, x);
  if (!C) return false;
  let w = C, T = [], E, D, O = [];
  w.from == x && w.to == S && (D = b.toText(y.getReplacement(w)), T.push({
    from: w.from,
    to: w.to,
    insert: D
  }), w = y.nextMatch(b, w.from, w.to), O.push(EditorView.announce.of(b.phrase("replaced match on line $", b.doc.lineAt(x).number) + ".")));
  let k = e2.state.changes(T);
  return w && (E = EditorSelection.single(w.from, w.to).map(k), O.push(announceMatch(e2, w)), O.push(b.facet(searchConfigFacet).scrollToMatch(E.main, e2))), e2.dispatch({
    changes: k,
    selection: E,
    effects: O,
    userEvent: "input.replace"
  }), true;
}), replaceAll = /* @__PURE__ */ searchCommand((e2, { query: y }) => {
  if (e2.state.readOnly) return false;
  let b = y.matchAll(e2.state, 1e9).map((e3) => {
    let { from: b2, to: x2 } = e3;
    return {
      from: b2,
      to: x2,
      insert: y.getReplacement(e3)
    };
  });
  if (!b.length) return false;
  let x = e2.state.phrase("replaced $ matches", b.length) + ".";
  return e2.dispatch({
    changes: b,
    effects: EditorView.announce.of(x),
    userEvent: "input.replace.all"
  }), true;
});
function createSearchPanel(e2) {
  return e2.state.facet(searchConfigFacet).createPanel(e2);
}
function defaultQuery(e2, y) {
  let b = e2.selection.main, x = b.empty || b.to > b.from + 100 ? "" : e2.sliceDoc(b.from, b.to);
  if (y && !x) return y;
  let S = e2.facet(searchConfigFacet);
  return new SearchQuery({
    search: (y == null ? void 0 : y.literal) ?? S.literal ? x : x.replace(/\n/g, "\\n"),
    caseSensitive: (y == null ? void 0 : y.caseSensitive) ?? S.caseSensitive,
    literal: (y == null ? void 0 : y.literal) ?? S.literal,
    regexp: (y == null ? void 0 : y.regexp) ?? S.regexp,
    wholeWord: (y == null ? void 0 : y.wholeWord) ?? S.wholeWord
  });
}
function getSearchInput(e2) {
  let y = getPanel(e2, createSearchPanel);
  return y && y.dom.querySelector("[main-field]");
}
function selectSearchInput(e2) {
  let y = getSearchInput(e2);
  y && y == e2.root.activeElement && y.select();
}
var openSearchPanel = (e2) => {
  let y = e2.state.field(searchState, false);
  if (y && y.panel) {
    let b = getSearchInput(e2);
    if (b && b != e2.root.activeElement) {
      let x = defaultQuery(e2.state, y.query.spec);
      x.valid && e2.dispatch({ effects: setSearchQuery.of(x) }), b.focus(), b.select();
    }
  } else e2.dispatch({ effects: [togglePanel.of(true), y ? setSearchQuery.of(defaultQuery(e2.state, y.query.spec)) : StateEffect.appendConfig.of(searchExtensions)] });
  return true;
}, closeSearchPanel = (e2) => {
  let y = e2.state.field(searchState, false);
  if (!y || !y.panel) return false;
  let b = getPanel(e2, createSearchPanel);
  return b && b.dom.contains(e2.root.activeElement) && e2.focus(), e2.dispatch({ effects: togglePanel.of(false) }), true;
}, searchKeymap = [
  {
    key: "Mod-f",
    run: openSearchPanel,
    scope: "editor search-panel"
  },
  {
    key: "F3",
    run: findNext,
    shift: findPrevious,
    scope: "editor search-panel",
    preventDefault: true
  },
  {
    key: "Mod-g",
    run: findNext,
    shift: findPrevious,
    scope: "editor search-panel",
    preventDefault: true
  },
  {
    key: "Escape",
    run: closeSearchPanel,
    scope: "editor search-panel"
  },
  {
    key: "Mod-Shift-l",
    run: selectSelectionMatches
  },
  {
    key: "Mod-Alt-g",
    run: gotoLine
  },
  {
    key: "Mod-d",
    run: selectNextOccurrence,
    preventDefault: true
  }
], SearchPanel = class {
  constructor(e2) {
    this.view = e2;
    let y = this.query = e2.state.field(searchState).query.spec;
    this.commit = this.commit.bind(this), this.searchField = crelt("input", {
      value: y.search,
      placeholder: phrase(e2, "Find"),
      "aria-label": phrase(e2, "Find"),
      class: "cm-textfield",
      name: "search",
      form: "",
      "main-field": "true",
      onchange: this.commit,
      onkeyup: this.commit
    }), this.replaceField = crelt("input", {
      value: y.replace,
      placeholder: phrase(e2, "Replace"),
      "aria-label": phrase(e2, "Replace"),
      class: "cm-textfield",
      name: "replace",
      form: "",
      onchange: this.commit,
      onkeyup: this.commit
    }), this.caseField = crelt("input", {
      type: "checkbox",
      name: "case",
      form: "",
      checked: y.caseSensitive,
      onchange: this.commit
    }), this.reField = crelt("input", {
      type: "checkbox",
      name: "re",
      form: "",
      checked: y.regexp,
      onchange: this.commit
    }), this.wordField = crelt("input", {
      type: "checkbox",
      name: "word",
      form: "",
      checked: y.wholeWord,
      onchange: this.commit
    });
    function b(e3, y2, b2) {
      return crelt("button", {
        class: "cm-button",
        name: e3,
        onclick: y2,
        type: "button"
      }, b2);
    }
    this.dom = crelt("div", {
      onkeydown: (e3) => this.keydown(e3),
      class: "cm-search"
    }, [
      this.searchField,
      b("next", () => findNext(e2), [phrase(e2, "next")]),
      b("prev", () => findPrevious(e2), [phrase(e2, "previous")]),
      b("select", () => selectMatches(e2), [phrase(e2, "all")]),
      crelt("label", null, [this.caseField, phrase(e2, "match case")]),
      crelt("label", null, [this.reField, phrase(e2, "regexp")]),
      crelt("label", null, [this.wordField, phrase(e2, "by word")]),
      ...e2.state.readOnly ? [] : [
        crelt("br"),
        this.replaceField,
        b("replace", () => replaceNext(e2), [phrase(e2, "replace")]),
        b("replaceAll", () => replaceAll(e2), [phrase(e2, "replace all")])
      ],
      crelt("button", {
        name: "close",
        onclick: () => closeSearchPanel(e2),
        "aria-label": phrase(e2, "close"),
        type: "button"
      }, ["\xD7"])
    ]);
  }
  commit() {
    let e2 = new SearchQuery({
      search: this.searchField.value,
      caseSensitive: this.caseField.checked,
      regexp: this.reField.checked,
      wholeWord: this.wordField.checked,
      replace: this.replaceField.value
    });
    e2.eq(this.query) || (this.query = e2, this.view.dispatch({ effects: setSearchQuery.of(e2) }));
  }
  keydown(e2) {
    runScopeHandlers(this.view, e2, "search-panel") ? e2.preventDefault() : e2.keyCode == 13 && e2.target == this.searchField ? (e2.preventDefault(), (e2.shiftKey ? findPrevious : findNext)(this.view)) : e2.keyCode == 13 && e2.target == this.replaceField && (e2.preventDefault(), replaceNext(this.view));
  }
  update(e2) {
    for (let y of e2.transactions) for (let e3 of y.effects) e3.is(setSearchQuery) && !e3.value.eq(this.query) && this.setQuery(e3.value);
  }
  setQuery(e2) {
    this.query = e2, this.searchField.value = e2.search, this.replaceField.value = e2.replace, this.caseField.checked = e2.caseSensitive, this.reField.checked = e2.regexp, this.wordField.checked = e2.wholeWord;
  }
  mount() {
    this.searchField.select();
  }
  get pos() {
    return 80;
  }
  get top() {
    return this.view.state.facet(searchConfigFacet).top;
  }
};
function phrase(e2, y) {
  return e2.state.phrase(y);
}
var AnnounceMargin = 30, Break = /[\s\.,:;?!]/;
function announceMatch(e2, { from: y, to: b }) {
  let x = e2.state.doc.lineAt(y), S = e2.state.doc.lineAt(b).to, C = Math.max(x.from, y - AnnounceMargin), w = Math.min(S, b + AnnounceMargin), T = e2.state.sliceDoc(C, w);
  if (C != x.from) {
    for (let e3 = 0; e3 < AnnounceMargin; e3++) if (!Break.test(T[e3 + 1]) && Break.test(T[e3])) {
      T = T.slice(e3);
      break;
    }
  }
  if (w != S) {
    for (let e3 = T.length - 1; e3 > T.length - AnnounceMargin; e3--) if (!Break.test(T[e3 - 1]) && Break.test(T[e3])) {
      T = T.slice(0, e3);
      break;
    }
  }
  return EditorView.announce.of(`${e2.state.phrase("current match")}. ${T} ${e2.state.phrase("on line")} ${x.number}.`);
}
var baseTheme = /* @__PURE__ */ EditorView.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" }
}), searchExtensions = [
  searchState,
  /* @__PURE__ */ Prec.low(searchHighlighter),
  baseTheme
];
function _objectWithoutPropertiesLoose(e2, y) {
  if (e2 == null) return {};
  var b = {};
  for (var x in e2) if ({}.hasOwnProperty.call(e2, x)) {
    if (y.indexOf(x) !== -1) continue;
    b[x] = e2[x];
  }
  return b;
}
var basicSetup = function(e2) {
  e2 === void 0 && (e2 = {});
  var { crosshairCursor: y = false } = e2, b = [];
  e2.closeBracketsKeymap !== false && (b = b.concat(closeBracketsKeymap)), e2.defaultKeymap !== false && (b = b.concat(defaultKeymap)), e2.searchKeymap !== false && (b = b.concat(searchKeymap)), e2.historyKeymap !== false && (b = b.concat(historyKeymap)), e2.foldKeymap !== false && (b = b.concat(foldKeymap)), e2.completionKeymap !== false && (b = b.concat(completionKeymap)), e2.lintKeymap !== false && (b = b.concat(lintKeymap));
  var T = [];
  return e2.lineNumbers !== false && T.push(lineNumbers()), e2.highlightActiveLineGutter !== false && T.push(highlightActiveLineGutter()), e2.highlightSpecialChars !== false && T.push(highlightSpecialChars()), e2.history !== false && T.push(history()), e2.foldGutter !== false && T.push(foldGutter()), e2.drawSelection !== false && T.push(drawSelection()), e2.dropCursor !== false && T.push(dropCursor()), e2.allowMultipleSelections !== false && T.push(EditorState.allowMultipleSelections.of(true)), e2.indentOnInput !== false && T.push(indentOnInput()), e2.syntaxHighlighting !== false && T.push(syntaxHighlighting(defaultHighlightStyle, { fallback: true })), e2.bracketMatching !== false && T.push(bracketMatching()), e2.closeBrackets !== false && T.push(closeBrackets()), e2.autocompletion !== false && T.push(autocompletion()), e2.rectangularSelection !== false && T.push(rectangularSelection()), y !== false && T.push(crosshairCursor()), e2.highlightActiveLine !== false && T.push(highlightActiveLine()), e2.highlightSelectionMatches !== false && T.push(highlightSelectionMatches()), e2.tabSize && typeof e2.tabSize == "number" && T.push(indentUnit.of(" ".repeat(e2.tabSize))), T.concat([keymap.of(b.flat())]).filter(Boolean);
}, minimalSetup = function(e2) {
  e2 === void 0 && (e2 = {});
  var y = [];
  e2.defaultKeymap !== false && (y = y.concat(defaultKeymap)), e2.historyKeymap !== false && (y = y.concat(historyKeymap));
  var b = [];
  return e2.highlightSpecialChars !== false && b.push(highlightSpecialChars()), e2.history !== false && b.push(history()), e2.drawSelection !== false && b.push(drawSelection()), e2.syntaxHighlighting !== false && b.push(syntaxHighlighting(defaultHighlightStyle, { fallback: true })), b.concat([keymap.of(y.flat())]).filter(Boolean);
}, chalky = "#e5c07b", coral = "#e06c75", cyan = "#56b6c2", invalid = "#ffffff", ivory = "#abb2bf", stone = "#7d8799", malibu = "#61afef", sage = "#98c379", whiskey = "#d19a66", violet = "#c678dd", darkBackground = "#21252b", highlightBackground = "#2c313a", background = "#282c34", tooltipBackground = "#353a42", selection = "#3E4451", cursor = "#528bff", oneDark = [/* @__PURE__ */ EditorView.theme({
  "&": {
    color: ivory,
    backgroundColor: background
  },
  ".cm-content": { caretColor: cursor },
  ".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor },
  "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection },
  ".cm-panels": {
    backgroundColor: darkBackground,
    color: ivory
  },
  ".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: background,
    color: stone,
    border: "none"
  },
  ".cm-activeLineGutter": { backgroundColor: highlightBackground },
  ".cm-foldPlaceholder": {
    backgroundColor: "transparent",
    border: "none",
    color: "#ddd"
  },
  ".cm-tooltip": {
    border: "none",
    backgroundColor: tooltipBackground
  },
  ".cm-tooltip .cm-tooltip-arrow:before": {
    borderTopColor: "transparent",
    borderBottomColor: "transparent"
  },
  ".cm-tooltip .cm-tooltip-arrow:after": {
    borderTopColor: tooltipBackground,
    borderBottomColor: tooltipBackground
  },
  ".cm-tooltip-autocomplete": { "& > ul > li[aria-selected]": {
    backgroundColor: highlightBackground,
    color: ivory
  } }
}, { dark: true }), /* @__PURE__ */ syntaxHighlighting(/* @__PURE__ */ HighlightStyle.define([
  {
    tag: tags.keyword,
    color: violet
  },
  {
    tag: [
      tags.name,
      tags.deleted,
      tags.character,
      tags.propertyName,
      tags.macroName
    ],
    color: coral
  },
  {
    tag: [/* @__PURE__ */ tags.function(tags.variableName), tags.labelName],
    color: malibu
  },
  {
    tag: [
      tags.color,
      /* @__PURE__ */ tags.constant(tags.name),
      /* @__PURE__ */ tags.standard(tags.name)
    ],
    color: whiskey
  },
  {
    tag: [/* @__PURE__ */ tags.definition(tags.name), tags.separator],
    color: ivory
  },
  {
    tag: [
      tags.typeName,
      tags.className,
      tags.number,
      tags.changed,
      tags.annotation,
      tags.modifier,
      tags.self,
      tags.namespace
    ],
    color: chalky
  },
  {
    tag: [
      tags.operator,
      tags.operatorKeyword,
      tags.url,
      tags.escape,
      tags.regexp,
      tags.link,
      /* @__PURE__ */ tags.special(tags.string)
    ],
    color: cyan
  },
  {
    tag: [tags.meta, tags.comment],
    color: stone
  },
  {
    tag: tags.strong,
    fontWeight: "bold"
  },
  {
    tag: tags.emphasis,
    fontStyle: "italic"
  },
  {
    tag: tags.strikethrough,
    textDecoration: "line-through"
  },
  {
    tag: tags.link,
    color: stone,
    textDecoration: "underline"
  },
  {
    tag: tags.heading,
    fontWeight: "bold",
    color: coral
  },
  {
    tag: [
      tags.atom,
      tags.bool,
      /* @__PURE__ */ tags.special(tags.variableName)
    ],
    color: whiskey
  },
  {
    tag: [
      tags.processingInstruction,
      tags.string,
      tags.inserted
    ],
    color: sage
  },
  {
    tag: tags.invalid,
    color: invalid
  }
]))], defaultLightThemeOption = EditorView.theme({ "&": { backgroundColor: "#fff" } }, { dark: false }), getDefaultExtensions = function(e2) {
  e2 === void 0 && (e2 = {});
  var { indentWithTab: y = true, editable: b = true, readOnly: x = false, theme: S = "light", placeholder: C = "", basicSetup: w = true } = e2, T = [];
  switch (y && T.unshift(keymap.of([indentWithTab])), w && (typeof w == "boolean" ? T.unshift(basicSetup()) : T.unshift(basicSetup(w))), C && T.unshift(placeholder(C)), S) {
    case "light":
      T.push(defaultLightThemeOption);
      break;
    case "dark":
      T.push(oneDark);
      break;
    case "none":
      break;
    default:
      T.push(S);
      break;
  }
  return b === false && T.push(EditorView.editable.of(false)), x && T.push(EditorState.readOnly.of(true)), [...T];
}, getStatistics = (e2) => ({
  line: e2.state.doc.lineAt(e2.state.selection.main.from),
  lineCount: e2.state.doc.lines,
  lineBreak: e2.state.lineBreak,
  length: e2.state.doc.length,
  readOnly: e2.state.readOnly,
  tabSize: e2.state.tabSize,
  selection: e2.state.selection,
  selectionAsSingle: e2.state.selection.asSingle().main,
  ranges: e2.state.selection.ranges,
  selectionCode: e2.state.sliceDoc(e2.state.selection.main.from, e2.state.selection.main.to),
  selections: e2.state.selection.ranges.map((y) => e2.state.sliceDoc(y.from, y.to)),
  selectedText: e2.state.selection.ranges.some((e3) => !e3.empty)
}), TimeoutLatch = class {
  constructor(e2, y) {
    this.timeLeftMS = void 0, this.timeoutMS = void 0, this.isCancelled = false, this.isTimeExhausted = false, this.callbacks = [], this.timeLeftMS = y, this.timeoutMS = y, this.callbacks.push(e2);
  }
  tick() {
    if (!this.isCancelled && !this.isTimeExhausted && (this.timeLeftMS--, this.timeLeftMS <= 0)) {
      this.isTimeExhausted = true;
      var e2 = this.callbacks.slice();
      this.callbacks.length = 0, e2.forEach((e3) => {
        try {
          e3();
        } catch (e4) {
          console.error("TimeoutLatch callback error:", e4);
        }
      });
    }
  }
  cancel() {
    this.isCancelled = true, this.callbacks.length = 0;
  }
  reset() {
    this.timeLeftMS = this.timeoutMS, this.isCancelled = false, this.isTimeExhausted = false;
  }
  get isDone() {
    return this.isCancelled || this.isTimeExhausted;
  }
}, Scheduler = class {
  constructor() {
    this.interval = null, this.latches = /* @__PURE__ */ new Set();
  }
  add(e2) {
    this.latches.add(e2), this.start();
  }
  remove(e2) {
    this.latches.delete(e2), this.latches.size === 0 && this.stop();
  }
  start() {
    this.interval === null && (this.interval = setInterval(() => {
      this.latches.forEach((e2) => {
        e2.tick(), e2.isDone && this.remove(e2);
      });
    }, 1));
  }
  stop() {
    this.interval !== null && (clearInterval(this.interval), this.interval = null);
  }
}, globalScheduler = null, getScheduler = () => typeof window > "u" ? new Scheduler() : (globalScheduler || (globalScheduler = new Scheduler()), globalScheduler), import_react = /* @__PURE__ */ __toESM(require_react()), ExternalChange = Annotation.define(), TYPING_TIMOUT = 200, emptyExtensions = [];
function useCodeMirror(e2) {
  var { value: y, selection: b, onChange: x, onStatistics: S, onCreateEditor: C, onUpdate: w, extensions: T = emptyExtensions, autoFocus: E, theme: D = "light", height: O = null, minHeight: k = null, maxHeight: A = null, width: j = null, minWidth: N = null, maxWidth: P = null, placeholder: F = "", editable: I = true, readOnly: L = false, indentWithTab: R = true, basicSetup: B = true, root: V, initialState: H } = e2, [W, G] = (0, import_react.useState)(), [K, q] = (0, import_react.useState)(), [J, Y] = (0, import_react.useState)(), X = (0, import_react.useState)(() => ({ current: null }))[0], Z = (0, import_react.useState)(() => ({ current: null }))[0], Q = EditorView.theme({
    "&": {
      height: O,
      minHeight: k,
      maxHeight: A,
      width: j,
      minWidth: N,
      maxWidth: P
    },
    "& .cm-scroller": { height: "100% !important" }
  }), $ = [
    EditorView.updateListener.of((e3) => {
      e3.docChanged && typeof x == "function" && !e3.transactions.some((e4) => e4.annotation(ExternalChange)) && (X.current ? X.current.reset() : (X.current = new TimeoutLatch(() => {
        if (Z.current) {
          var e4 = Z.current;
          Z.current = null, e4();
        }
        X.current = null;
      }, TYPING_TIMOUT), getScheduler().add(X.current)), x(e3.state.doc.toString(), e3)), S && S(getStatistics(e3));
    }),
    Q,
    ...getDefaultExtensions({
      theme: D,
      editable: I,
      readOnly: L,
      placeholder: F,
      indentWithTab: R,
      basicSetup: B
    })
  ];
  return w && typeof w == "function" && $.push(EditorView.updateListener.of(w)), $ = $.concat(T), (0, import_react.useLayoutEffect)(() => {
    if (W && !J) {
      var e3 = {
        doc: y,
        selection: b,
        extensions: $
      }, x2 = H ? EditorState.fromJSON(H.json, e3, H.fields) : EditorState.create(e3);
      if (Y(x2), !K) {
        var S2 = new EditorView({
          state: x2,
          parent: W,
          root: V
        });
        q(S2), C && C(S2, x2);
      }
    }
    return () => {
      K && (Y(void 0), q(void 0));
    };
  }, [W, J]), (0, import_react.useEffect)(() => {
    e2.container && G(e2.container);
  }, [e2.container]), (0, import_react.useEffect)(() => () => {
    K && (K.destroy(), q(void 0)), X.current && (X.current = (X.current.cancel(), null));
  }, [K]), (0, import_react.useEffect)(() => {
    E && K && K.focus();
  }, [E, K]), (0, import_react.useEffect)(() => {
    K && K.dispatch({ effects: StateEffect.reconfigure.of($) });
  }, [
    D,
    T,
    O,
    k,
    A,
    j,
    N,
    P,
    F,
    I,
    L,
    R,
    B,
    x,
    w
  ]), (0, import_react.useEffect)(() => {
    if (y !== void 0) {
      var e3 = K ? K.state.doc.toString() : "";
      if (K && y !== e3) {
        var b2 = X.current && !X.current.isDone, x2 = () => {
          K && y !== K.state.doc.toString() && K.dispatch({
            changes: {
              from: 0,
              to: K.state.doc.toString().length,
              insert: y || ""
            },
            annotations: [ExternalChange.of(true)]
          });
        };
        b2 ? Z.current = x2 : x2();
      }
    }
  }, [y, K]), {
    state: J,
    setState: Y,
    view: K,
    setView: q,
    container: W,
    setContainer: G
  };
}
var import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime()), _excluded = [
  "className",
  "value",
  "selection",
  "extensions",
  "onChange",
  "onStatistics",
  "onCreateEditor",
  "onUpdate",
  "autoFocus",
  "theme",
  "height",
  "minHeight",
  "maxHeight",
  "width",
  "minWidth",
  "maxWidth",
  "basicSetup",
  "placeholder",
  "indentWithTab",
  "editable",
  "readOnly",
  "root",
  "initialState"
], ReactCodeMirror = /* @__PURE__ */ (0, import_react.forwardRef)((e2, y) => {
  var { className: b, value: x = "", selection: S, extensions: C = [], onChange: w, onStatistics: E, onCreateEditor: D, onUpdate: O, autoFocus: k, theme: A = "light", height: j, minHeight: M, maxHeight: N, width: P, minWidth: F, maxWidth: I, basicSetup: L, placeholder: R, indentWithTab: z, editable: B, readOnly: V, root: H, initialState: U } = e2, W = _objectWithoutPropertiesLoose(e2, _excluded), G = (0, import_react.useRef)(null), { state: K, view: q, container: J, setContainer: Y } = useCodeMirror({
    root: H,
    value: x,
    autoFocus: k,
    theme: A,
    height: j,
    minHeight: M,
    maxHeight: N,
    width: P,
    minWidth: F,
    maxWidth: I,
    basicSetup: L,
    placeholder: R,
    indentWithTab: z,
    editable: B,
    readOnly: V,
    selection: S,
    onChange: w,
    onStatistics: E,
    onCreateEditor: D,
    onUpdate: O,
    extensions: C,
    initialState: U
  });
  (0, import_react.useImperativeHandle)(y, () => ({
    editor: G.current,
    state: K,
    view: q
  }), [
    G,
    J,
    K,
    q
  ]);
  var X = (0, import_react.useCallback)((e3) => {
    G.current = e3, Y(e3);
  }, [Y]);
  if (typeof x != "string") throw Error("value must be typeof string but got " + typeof x);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", _extends({
    ref: X,
    className: (typeof A == "string" ? "cm-theme-" + A : "cm-theme") + (b ? " " + b : "")
  }, W));
});
ReactCodeMirror.displayName = "CodeMirror";
var esm_default = ReactCodeMirror;
export {
  minimalSetup as n,
  esm_default as t
};
