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-DebpN0FN.js";
import { l as historyKeymap, o as defaultKeymap, r as lintKeymap, s as history, t as _extends, u as indentWithTab } from "./extends-D_hDsj6R.js";
import { $ as EditorView, At as Facet, Bt as codePointAt, C as foldKeymap, Ct as Annotation, Et as CharCategory, F as syntaxHighlighting, Gt as fromCodePoint, H as tags, Ht as combineConfig, It as StateEffect, Lt as StateField, Mt as Prec, Ot as EditorSelection, Pt as RangeSetBuilder, St as crelt, Vt as codePointSize, Wt as findClusterBreak, Z as Decoration, _t as rectangularSelection, a as HighlightStyle, at as dropCursor, bt as showPanel, dt as highlightSpecialChars, g as defaultHighlightStyle, gt as placeholder, it as drawSelection, j as indentUnit, k as indentOnInput, kt as EditorState, lt as highlightActiveLine, mt as lineNumbers, ot as getPanel, p as bracketMatching, pt as keymap, rt as crosshairCursor, tt as ViewPlugin, ut as highlightActiveLineGutter, vt as runScopeHandlers, x as foldGutter, yt as showDialog } from "./dist-U4F-tbMs.js";
import { a as closeBracketsKeymap, c as completionKeymap, i as closeBrackets, r as autocompletion } from "./dist-hT4QzYX-.js";
var basicNormalize = typeof String.prototype.normalize == "function" ? (e2) => e2.normalize("NFKD") : (e2) => e2, SearchCursor = class {
  constructor(e2, b, x = 0, S = e2.length, C, w) {
    this.test = w, this.value = {
      from: 0,
      to: 0
    }, this.done = false, this.matches = [], this.buffer = "", this.bufferPos = 0, this.iter = e2.iterRange(x, S), this.bufferStart = x, this.normalize = C ? (e3) => C(basicNormalize(e3)) : basicNormalize, this.query = this.normalize(b);
  }
  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 b = fromCodePoint(e2), x = this.bufferStart + this.bufferPos;
      this.bufferPos += codePointSize(e2);
      let S = this.normalize(b);
      if (S.length) for (let e3 = 0, C = x; ; e3++) {
        let w = S.charCodeAt(e3), T = this.match(w, C, this.bufferPos + this.bufferStart);
        if (e3 == S.length - 1) {
          if (T) return this.value = T, this;
          break;
        }
        C == x && e3 < b.length && b.charCodeAt(e3) == w && C++;
      }
    }
  }
  match(e2, b, x) {
    let S = null;
    for (let b2 = 0; b2 < this.matches.length; b2 += 2) {
      let C = this.matches[b2], w = false;
      this.query.charCodeAt(C) == e2 && (C == this.query.length - 1 ? S = {
        from: this.matches[b2 + 1],
        to: x
      } : (this.matches[b2]++, w = true)), w || (this.matches.splice(b2, 2), b2 -= 2);
    }
    return this.query.charCodeAt(0) == e2 && (this.query.length == 1 ? S = {
      from: b,
      to: x
    } : this.matches.push(1, b)), S && this.test && !this.test(S.from, S.to, this.buffer, this.bufferStart) && (S = null), S;
  }
};
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, b, x, S = 0, C = e2.length) {
    if (this.text = e2, this.to = C, this.curLine = "", this.done = false, this.value = empty, /\\[sWDnr]|\n|\r|\[\^/.test(b)) return new MultilineRegExpCursor(e2, b, x, S, C);
    this.re = new RegExp(b, baseFlags + ((x == null ? void 0 : x.ignoreCase) ? "i" : "")), this.test = x == null ? void 0 : x.test, this.iter = e2.iter(), this.curLineStart = e2.lineAt(S).from, this.matchPos = toCharEnd(e2, S), 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 b = this.matchPos <= this.to && this.re.exec(this.curLine);
      if (b) {
        let x = this.curLineStart + b.index, S = x + b[0].length;
        if (this.matchPos = toCharEnd(this.text, S + (x == S ? 1 : 0)), x == this.curLineStart + this.curLine.length && this.nextLine(), (x < S || x > this.value.to) && (!this.test || this.test(x, S, b))) return this.value = {
          from: x,
          to: S,
          match: b
        }, 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, b) {
    this.from = e2, this.text = b;
  }
  get to() {
    return this.from + this.text.length;
  }
  static get(b, x, S) {
    let C = flattened.get(b);
    if (!C || C.from >= S || C.to <= x) {
      let C2 = new e(x, b.sliceString(x, S));
      return flattened.set(b, C2), C2;
    }
    if (C.from == x && C.to == S) return C;
    let { text: w, from: T } = C;
    return T > x && (w = b.sliceString(x, T) + w, T = x), C.to < S && (w += b.sliceString(C.to, S)), flattened.set(b, new e(T, w)), new e(x, w.slice(x - T, S - T));
  }
}, MultilineRegExpCursor = class {
  constructor(e2, b, x, S, C) {
    this.text = e2, this.to = C, this.done = false, this.value = empty, this.matchPos = toCharEnd(e2, S), this.re = new RegExp(b, baseFlags + ((x == null ? void 0 : x.ignoreCase) ? "i" : "")), this.test = x == null ? void 0 : x.test, this.flat = FlattenedDoc.get(e2, S, this.chunkEnd(S + 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, b = this.re.exec(this.flat.text);
      if (b && !b[0] && b.index == e2 && (this.re.lastIndex = e2 + 1, b = this.re.exec(this.flat.text)), b) {
        let e3 = this.flat.from + b.index, x = e3 + b[0].length;
        if ((this.flat.to >= this.to || b.index + b[0].length <= this.flat.text.length - 10) && (!this.test || this.test(e3, x, b))) return this.value = {
          from: e3,
          to: x,
          match: b
        }, this.matchPos = toCharEnd(this.text, x + (e3 == x ? 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, b) {
  if (b >= e2.length) return b;
  let x = e2.lineAt(b), S;
  for (; b < x.to && (S = x.text.charCodeAt(b - x.from)) >= 56320 && S < 57344; ) b++;
  return b;
}
var gotoLine = (e2) => {
  let { state: b } = e2, x = String(b.doc.lineAt(e2.state.selection.main.head).number), { close: S, result: C } = showDialog(e2, {
    label: b.phrase("Go to line"),
    input: {
      type: "text",
      name: "line",
      value: x
    },
    focus: true,
    submitLabel: b.phrase("go")
  });
  return C.then((x2) => {
    let C2 = x2 && /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(x2.elements.line.value);
    if (!C2) {
      e2.dispatch({ effects: S });
      return;
    }
    let w = b.doc.lineAt(b.selection.main.head), [, T, E, D, k] = C2, A = D ? +D.slice(1) : 0, j = E ? +E : w.number;
    if (E && k) {
      let e3 = j / 100;
      T && (e3 = e3 * (T == "-" ? -1 : 1) + w.number / b.doc.lines), j = Math.round(b.doc.lines * e3);
    } else E && T && (j = j * (T == "-" ? -1 : 1) + w.number);
    let M = b.doc.line(Math.max(1, Math.min(b.doc.lines, j))), N = EditorSelection.cursor(M.from + Math.max(0, Math.min(A, M.length)));
    e2.dispatch({
      effects: [S, EditorView.scrollIntoView(N.from, { y: "center" })],
      selection: N
    });
  }), true;
}, defaultHighlightOptions = {
  highlightWordAroundCursor: false,
  minSelectionLength: 1,
  maxMatches: 100,
  wholeWords: false
}, highlightConfig = /* @__PURE__ */ Facet.define({ combine(e2) {
  return combineConfig(e2, defaultHighlightOptions, {
    highlightWordAroundCursor: (e3, b) => e3 || b,
    minSelectionLength: Math.min,
    maxMatches: Math.min
  });
} });
function highlightSelectionMatches(e2) {
  let b = [defaultTheme, matchHighlighter];
  return e2 && b.push(highlightConfig.of(e2)), b;
}
var matchDeco = /* @__PURE__ */ Decoration.mark({ class: "cm-selectionMatch" }), mainMatchDeco = /* @__PURE__ */ Decoration.mark({ class: "cm-selectionMatch cm-selectionMatch-main" });
function insideWordBoundaries(e2, b, x, S) {
  return (x == 0 || e2(b.sliceDoc(x - 1, x)) != CharCategory.Word) && (S == b.doc.length || e2(b.sliceDoc(S, S + 1)) != CharCategory.Word);
}
function insideWord(e2, b, x, S) {
  return e2(b.sliceDoc(x, x + 1)) == CharCategory.Word && e2(b.sliceDoc(S - 1, S)) == 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 b = e2.state.facet(highlightConfig), { state: x } = e2, S = x.selection;
    if (S.ranges.length > 1) return Decoration.none;
    let C = S.main, w, T = null;
    if (C.empty) {
      if (!b.highlightWordAroundCursor) return Decoration.none;
      let e3 = x.wordAt(C.head);
      if (!e3) return Decoration.none;
      T = x.charCategorizer(C.head), w = x.sliceDoc(e3.from, e3.to);
    } else {
      let e3 = C.to - C.from;
      if (e3 < b.minSelectionLength || e3 > 200) return Decoration.none;
      if (b.wholeWords) {
        if (w = x.sliceDoc(C.from, C.to), T = x.charCategorizer(C.head), !(insideWordBoundaries(T, x, C.from, C.to) && insideWord(T, x, C.from, C.to))) return Decoration.none;
      } else if (w = x.sliceDoc(C.from, C.to), !w) return Decoration.none;
    }
    let E = [];
    for (let S2 of e2.visibleRanges) {
      let e3 = new SearchCursor(x.doc, w, S2.from, S2.to);
      for (; !e3.next().done; ) {
        let { from: S3, to: w2 } = e3.value;
        if ((!T || insideWordBoundaries(T, x, S3, w2)) && (C.empty && S3 <= C.from && w2 >= C.to ? E.push(mainMatchDeco.range(S3, w2)) : (S3 >= C.to || w2 <= C.from) && E.push(matchDeco.range(S3, w2)), E.length > b.maxMatches)) return Decoration.none;
      }
    }
    return Decoration.set(E);
  }
}, { decorations: (e2) => e2.decorations }), defaultTheme = /* @__PURE__ */ EditorView.baseTheme({
  ".cm-selectionMatch": { backgroundColor: "#99ff7780" },
  ".cm-searchMatch .cm-selectionMatch": { backgroundColor: "transparent" }
}), selectWord = ({ state: e2, dispatch: b }) => {
  let { selection: x } = e2, S = EditorSelection.create(x.ranges.map((b2) => e2.wordAt(b2.head) || EditorSelection.cursor(b2.head)), x.mainIndex);
  return S.eq(x) ? false : (b(e2.update({ selection: S })), true);
};
function findNextOccurrence(e2, b) {
  let { main: x, ranges: S } = e2.selection, C = e2.wordAt(x.head), w = C && C.from == x.from && C.to == x.to;
  for (let x2 = false, C2 = new SearchCursor(e2.doc, b, S[S.length - 1].to); ; ) if (C2.next(), C2.done) {
    if (x2) return null;
    C2 = new SearchCursor(e2.doc, b, 0, Math.max(0, S[S.length - 1].from - 1)), x2 = true;
  } else {
    if (x2 && S.some((e3) => e3.from == C2.value.from)) continue;
    if (w) {
      let b2 = e2.wordAt(C2.value.from);
      if (!b2 || b2.from != C2.value.from || b2.to != C2.value.to) continue;
    }
    return C2.value;
  }
}
var selectNextOccurrence = ({ state: e2, dispatch: b }) => {
  let { ranges: x } = e2.selection;
  if (x.some((e3) => e3.from === e3.to)) return selectWord({
    state: e2,
    dispatch: b
  });
  let S = e2.sliceDoc(x[0].from, x[0].to);
  if (e2.selection.ranges.some((b2) => e2.sliceDoc(b2.from, b2.to) != S)) return false;
  let C = findNextOccurrence(e2, S);
  return C ? (b(e2.update({
    selection: e2.selection.addRange(EditorSelection.range(C.from, C.to), false),
    effects: EditorView.scrollIntoView(C.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, b) => b == "n" ? "\n" : b == "r" ? "\r" : b == "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, b = 0, x) {
    let S = e2.doc ? e2 : EditorState.create({ doc: e2 });
    return x ?? (x = S.doc.length), this.regexp ? regexpCursor(this, S, b, x) : stringCursor(this, S, b, x);
  }
}, QueryType = class {
  constructor(e2) {
    this.spec = e2;
  }
};
function wrapStringTest(e2, b, x) {
  return (S, C, w, T) => x && !x(S, C, w, T) ? false : e2(S >= T && C <= T + w.length ? w.slice(S - T, C - T) : b.doc.sliceString(S, C), b, S, C);
}
function stringCursor(e2, b, x, S) {
  let C;
  return e2.wholeWord && (C = stringWordTest(b.doc, b.charCategorizer(b.selection.main.head))), e2.test && (C = wrapStringTest(e2.test, b, C)), new SearchCursor(b.doc, e2.unquoted, x, S, e2.caseSensitive ? void 0 : (e3) => e3.toLowerCase(), C);
}
function stringWordTest(e2, b) {
  return (x, S, C, w) => ((w > x || w + C.length < S) && (w = Math.max(0, x - 2), C = e2.sliceString(w, Math.min(e2.length, S + 2))), (b(charBefore(C, x - w)) != CharCategory.Word || b(charAfter(C, x - w)) != CharCategory.Word) && (b(charAfter(C, S - w)) != CharCategory.Word || b(charBefore(C, S - w)) != CharCategory.Word));
}
var StringQuery = class extends QueryType {
  constructor(e2) {
    super(e2);
  }
  nextMatch(e2, b, x) {
    let S = stringCursor(this.spec, e2, x, e2.doc.length).nextOverlapping();
    if (S.done) {
      let x2 = Math.min(e2.doc.length, b + this.spec.unquoted.length);
      S = stringCursor(this.spec, e2, 0, x2).nextOverlapping();
    }
    return S.done || S.value.from == b && S.value.to == x ? null : S.value;
  }
  prevMatchInRange(e2, b, x) {
    for (let S = x; ; ) {
      let x2 = Math.max(b, S - 1e4 - this.spec.unquoted.length), C = stringCursor(this.spec, e2, x2, S), w = null;
      for (; !C.nextOverlapping().done; ) w = C.value;
      if (w) return w;
      if (x2 == b) return null;
      S -= 1e4;
    }
  }
  prevMatch(e2, b, x) {
    let S = this.prevMatchInRange(e2, 0, b);
    return S || (S = this.prevMatchInRange(e2, Math.max(0, x - this.spec.unquoted.length), e2.doc.length)), S && (S.from != b || S.to != x) ? S : null;
  }
  getReplacement(e2) {
    return this.spec.unquote(this.spec.replace);
  }
  matchAll(e2, b) {
    let x = stringCursor(this.spec, e2, 0, e2.doc.length), S = [];
    for (; !x.next().done; ) {
      if (S.length >= b) return null;
      S.push(x.value);
    }
    return S;
  }
  highlight(e2, b, x, S) {
    let C = stringCursor(this.spec, e2, Math.max(0, b - this.spec.unquoted.length), Math.min(x + this.spec.unquoted.length, e2.doc.length));
    for (; !C.next().done; ) S(C.value.from, C.value.to);
  }
};
function wrapRegexpTest(e2, b, x) {
  return (S, C, w) => (!x || x(S, C, w)) && e2(w[0], b, S, C);
}
function regexpCursor(e2, b, x, S) {
  let C;
  return e2.wholeWord && (C = regexpWordTest(b.charCategorizer(b.selection.main.head))), e2.test && (C = wrapRegexpTest(e2.test, b, C)), new RegExpCursor(b.doc, e2.search, {
    ignoreCase: !e2.caseSensitive,
    test: C
  }, x, S);
}
function charBefore(e2, b) {
  return e2.slice(findClusterBreak(e2, b, false), b);
}
function charAfter(e2, b) {
  return e2.slice(b, findClusterBreak(e2, b));
}
function regexpWordTest(e2) {
  return (b, x, S) => !S[0].length || (e2(charBefore(S.input, S.index)) != CharCategory.Word || e2(charAfter(S.input, S.index)) != CharCategory.Word) && (e2(charAfter(S.input, S.index + S[0].length)) != CharCategory.Word || e2(charBefore(S.input, S.index + S[0].length)) != CharCategory.Word);
}
var RegExpQuery = class extends QueryType {
  nextMatch(e2, b, x) {
    let S = regexpCursor(this.spec, e2, x, e2.doc.length).next();
    return S.done && (S = regexpCursor(this.spec, e2, 0, b).next()), S.done ? null : S.value;
  }
  prevMatchInRange(e2, b, x) {
    for (let S = 1; ; S++) {
      let C = Math.max(b, x - S * 1e4), w = regexpCursor(this.spec, e2, C, x), T = null;
      for (; !w.next().done; ) T = w.value;
      if (T && (C == b || T.from > C + 10)) return T;
      if (C == b) return null;
    }
  }
  prevMatch(e2, b, x) {
    return this.prevMatchInRange(e2, 0, b) || this.prevMatchInRange(e2, x, e2.doc.length);
  }
  getReplacement(e2) {
    return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g, (b, x) => {
      if (x == "&") return e2.match[0];
      if (x == "$") return "$";
      for (let b2 = x.length; b2 > 0; b2--) {
        let S = +x.slice(0, b2);
        if (S > 0 && S < e2.match.length) return e2.match[S] + x.slice(b2);
      }
      return b;
    });
  }
  matchAll(e2, b) {
    let x = regexpCursor(this.spec, e2, 0, e2.doc.length), S = [];
    for (; !x.next().done; ) {
      if (S.length >= b) return null;
      S.push(x.value);
    }
    return S;
  }
  highlight(e2, b, x, S) {
    let C = regexpCursor(this.spec, e2, Math.max(0, b - 250), Math.min(x + 250, e2.doc.length));
    for (; !C.next().done; ) S(C.value.from, C.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, b) {
    for (let x of b.effects) x.is(setSearchQuery) ? e2 = new SearchState(x.value.create(), e2.panel) : x.is(togglePanel) && (e2 = new SearchState(e2.query, x.value ? createSearchPanel : null));
    return e2;
  },
  provide: (e2) => showPanel.from(e2, (e3) => e3.panel)
}), SearchState = class {
  constructor(e2, b) {
    this.query = e2, this.panel = b;
  }
}, 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 b = e2.state.field(searchState);
    (b != e2.startState.field(searchState) || e2.docChanged || e2.selectionSet || e2.viewportChanged) && (this.decorations = this.highlight(b));
  }
  highlight({ query: e2, panel: b }) {
    if (!b || !e2.spec.valid) return Decoration.none;
    let { view: x } = this, S = new RangeSetBuilder();
    for (let b2 = 0, C = x.visibleRanges, w = C.length; b2 < w; b2++) {
      let { from: T, to: E } = C[b2];
      for (; b2 < w - 1 && E > C[b2 + 1].from - 500; ) E = C[++b2].to;
      e2.highlight(x.state, T, E, (e3, b3) => {
        let C2 = x.state.selection.ranges.some((x2) => x2.from == e3 && x2.to == b3);
        S.add(e3, b3, C2 ? selectedMatchMark : matchMark);
      });
    }
    return S.finish();
  }
}, { decorations: (e2) => e2.decorations });
function searchCommand(e2) {
  return (b) => {
    let x = b.state.field(searchState, false);
    return x && x.query.spec.valid ? e2(b, x) : openSearchPanel(b);
  };
}
var findNext = /* @__PURE__ */ searchCommand((e2, { query: b }) => {
  let { to: x } = e2.state.selection.main, S = b.nextMatch(e2.state, 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;
}), findPrevious = /* @__PURE__ */ searchCommand((e2, { query: b }) => {
  let { state: x } = e2, { from: S } = x.selection.main, C = b.prevMatch(x, S, S);
  if (!C) return false;
  let w = EditorSelection.single(C.from, C.to), T = e2.state.facet(searchConfigFacet);
  return e2.dispatch({
    selection: w,
    effects: [announceMatch(e2, C), T.scrollToMatch(w.main, e2)],
    userEvent: "select.search"
  }), selectSearchInput(e2), true;
}), selectMatches = /* @__PURE__ */ searchCommand((e2, { query: b }) => {
  let x = b.matchAll(e2.state, 1e3);
  return !x || !x.length ? false : (e2.dispatch({
    selection: EditorSelection.create(x.map((e3) => EditorSelection.range(e3.from, e3.to))),
    userEvent: "select.search.matches"
  }), true);
}), selectSelectionMatches = ({ state: e2, dispatch: b }) => {
  let x = e2.selection;
  if (x.ranges.length > 1 || x.main.empty) return false;
  let { from: S, to: C } = x.main, w = [], T = 0;
  for (let b2 = new SearchCursor(e2.doc, e2.sliceDoc(S, C)); !b2.next().done; ) {
    if (w.length > 1e3) return false;
    b2.value.from == S && (T = w.length), w.push(EditorSelection.range(b2.value.from, b2.value.to));
  }
  return b(e2.update({
    selection: EditorSelection.create(w, T),
    userEvent: "select.search.matches"
  })), true;
}, replaceNext = /* @__PURE__ */ searchCommand((e2, { query: b }) => {
  let { state: x } = e2, { from: S, to: C } = x.selection.main;
  if (x.readOnly) return false;
  let w = b.nextMatch(x, S, S);
  if (!w) return false;
  let T = w, E = [], D, k, A = [];
  T.from == S && T.to == C && (k = x.toText(b.getReplacement(T)), E.push({
    from: T.from,
    to: T.to,
    insert: k
  }), T = b.nextMatch(x, T.from, T.to), A.push(EditorView.announce.of(x.phrase("replaced match on line $", x.doc.lineAt(S).number) + ".")));
  let j = e2.state.changes(E);
  return T && (D = EditorSelection.single(T.from, T.to).map(j), A.push(announceMatch(e2, T)), A.push(x.facet(searchConfigFacet).scrollToMatch(D.main, e2))), e2.dispatch({
    changes: j,
    selection: D,
    effects: A,
    userEvent: "input.replace"
  }), true;
}), replaceAll = /* @__PURE__ */ searchCommand((e2, { query: b }) => {
  if (e2.state.readOnly) return false;
  let x = b.matchAll(e2.state, 1e9).map((e3) => {
    let { from: x2, to: S2 } = e3;
    return {
      from: x2,
      to: S2,
      insert: b.getReplacement(e3)
    };
  });
  if (!x.length) return false;
  let S = e2.state.phrase("replaced $ matches", x.length) + ".";
  return e2.dispatch({
    changes: x,
    effects: EditorView.announce.of(S),
    userEvent: "input.replace.all"
  }), true;
});
function createSearchPanel(e2) {
  return e2.state.facet(searchConfigFacet).createPanel(e2);
}
function defaultQuery(e2, b) {
  let x = e2.selection.main, S = x.empty || x.to > x.from + 100 ? "" : e2.sliceDoc(x.from, x.to);
  if (b && !S) return b;
  let C = e2.facet(searchConfigFacet);
  return new SearchQuery({
    search: (b == null ? void 0 : b.literal) ?? C.literal ? S : S.replace(/\n/g, "\\n"),
    caseSensitive: (b == null ? void 0 : b.caseSensitive) ?? C.caseSensitive,
    literal: (b == null ? void 0 : b.literal) ?? C.literal,
    regexp: (b == null ? void 0 : b.regexp) ?? C.regexp,
    wholeWord: (b == null ? void 0 : b.wholeWord) ?? C.wholeWord
  });
}
function getSearchInput(e2) {
  let b = getPanel(e2, createSearchPanel);
  return b && b.dom.querySelector("[main-field]");
}
function selectSearchInput(e2) {
  let b = getSearchInput(e2);
  b && b == e2.root.activeElement && b.select();
}
var openSearchPanel = (e2) => {
  let b = e2.state.field(searchState, false);
  if (b && b.panel) {
    let x = getSearchInput(e2);
    if (x && x != e2.root.activeElement) {
      let S = defaultQuery(e2.state, b.query.spec);
      S.valid && e2.dispatch({ effects: setSearchQuery.of(S) }), x.focus(), x.select();
    }
  } else e2.dispatch({ effects: [togglePanel.of(true), b ? setSearchQuery.of(defaultQuery(e2.state, b.query.spec)) : StateEffect.appendConfig.of(searchExtensions)] });
  return true;
}, closeSearchPanel = (e2) => {
  let b = e2.state.field(searchState, false);
  if (!b || !b.panel) return false;
  let x = getPanel(e2, createSearchPanel);
  return x && x.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 b = this.query = e2.state.field(searchState).query.spec;
    this.commit = this.commit.bind(this), this.searchField = crelt("input", {
      value: b.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: b.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: b.caseSensitive,
      onchange: this.commit
    }), this.reField = crelt("input", {
      type: "checkbox",
      name: "re",
      form: "",
      checked: b.regexp,
      onchange: this.commit
    }), this.wordField = crelt("input", {
      type: "checkbox",
      name: "word",
      form: "",
      checked: b.wholeWord,
      onchange: this.commit
    });
    function x(e3, b2, x2) {
      return crelt("button", {
        class: "cm-button",
        name: e3,
        onclick: b2,
        type: "button"
      }, x2);
    }
    this.dom = crelt("div", {
      onkeydown: (e3) => this.keydown(e3),
      class: "cm-search"
    }, [
      this.searchField,
      x("next", () => findNext(e2), [phrase(e2, "next")]),
      x("prev", () => findPrevious(e2), [phrase(e2, "previous")]),
      x("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,
        x("replace", () => replaceNext(e2), [phrase(e2, "replace")]),
        x("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 b of e2.transactions) for (let e3 of b.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, b) {
  return e2.state.phrase(b);
}
var AnnounceMargin = 30, Break = /[\s\.,:;?!]/;
function announceMatch(e2, { from: b, to: x }) {
  let S = e2.state.doc.lineAt(b), C = e2.state.doc.lineAt(x).to, w = Math.max(S.from, b - AnnounceMargin), T = Math.min(C, x + AnnounceMargin), E = e2.state.sliceDoc(w, T);
  if (w != S.from) {
    for (let e3 = 0; e3 < AnnounceMargin; e3++) if (!Break.test(E[e3 + 1]) && Break.test(E[e3])) {
      E = E.slice(e3);
      break;
    }
  }
  if (T != C) {
    for (let e3 = E.length - 1; e3 > E.length - AnnounceMargin; e3--) if (!Break.test(E[e3 - 1]) && Break.test(E[e3])) {
      E = E.slice(0, e3);
      break;
    }
  }
  return EditorView.announce.of(`${e2.state.phrase("current match")}. ${E} ${e2.state.phrase("on line")} ${S.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, b) {
  if (e2 == null) return {};
  var x = {};
  for (var S in e2) if ({}.hasOwnProperty.call(e2, S)) {
    if (b.indexOf(S) !== -1) continue;
    x[S] = e2[S];
  }
  return x;
}
var basicSetup = function(e2) {
  e2 === void 0 && (e2 = {});
  var { crosshairCursor: b = false } = e2, x = [];
  e2.closeBracketsKeymap !== false && (x = x.concat(closeBracketsKeymap)), e2.defaultKeymap !== false && (x = x.concat(defaultKeymap)), e2.searchKeymap !== false && (x = x.concat(searchKeymap)), e2.historyKeymap !== false && (x = x.concat(historyKeymap)), e2.foldKeymap !== false && (x = x.concat(foldKeymap)), e2.completionKeymap !== false && (x = x.concat(completionKeymap)), e2.lintKeymap !== false && (x = x.concat(lintKeymap));
  var E = [];
  return e2.lineNumbers !== false && E.push(lineNumbers()), e2.highlightActiveLineGutter !== false && E.push(highlightActiveLineGutter()), e2.highlightSpecialChars !== false && E.push(highlightSpecialChars()), e2.history !== false && E.push(history()), e2.foldGutter !== false && E.push(foldGutter()), e2.drawSelection !== false && E.push(drawSelection()), e2.dropCursor !== false && E.push(dropCursor()), e2.allowMultipleSelections !== false && E.push(EditorState.allowMultipleSelections.of(true)), e2.indentOnInput !== false && E.push(indentOnInput()), e2.syntaxHighlighting !== false && E.push(syntaxHighlighting(defaultHighlightStyle, { fallback: true })), e2.bracketMatching !== false && E.push(bracketMatching()), e2.closeBrackets !== false && E.push(closeBrackets()), e2.autocompletion !== false && E.push(autocompletion()), e2.rectangularSelection !== false && E.push(rectangularSelection()), b !== false && E.push(crosshairCursor()), e2.highlightActiveLine !== false && E.push(highlightActiveLine()), e2.highlightSelectionMatches !== false && E.push(highlightSelectionMatches()), e2.tabSize && typeof e2.tabSize == "number" && E.push(indentUnit.of(" ".repeat(e2.tabSize))), E.concat([keymap.of(x.flat())]).filter(Boolean);
}, minimalSetup = function(e2) {
  e2 === void 0 && (e2 = {});
  var b = [];
  e2.defaultKeymap !== false && (b = b.concat(defaultKeymap)), e2.historyKeymap !== false && (b = b.concat(historyKeymap));
  var x = [];
  return e2.highlightSpecialChars !== false && x.push(highlightSpecialChars()), e2.history !== false && x.push(history()), e2.drawSelection !== false && x.push(drawSelection()), e2.syntaxHighlighting !== false && x.push(syntaxHighlighting(defaultHighlightStyle, { fallback: true })), x.concat([keymap.of(b.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: b = true, editable: x = true, readOnly: S = false, theme: C = "light", placeholder: w = "", basicSetup: T = true } = e2, E = [];
  switch (b && E.unshift(keymap.of([indentWithTab])), T && (typeof T == "boolean" ? E.unshift(basicSetup()) : E.unshift(basicSetup(T))), w && E.unshift(placeholder(w)), C) {
    case "light":
      E.push(defaultLightThemeOption);
      break;
    case "dark":
      E.push(oneDark);
      break;
    case "none":
      break;
    default:
      E.push(C);
      break;
  }
  return x === false && E.push(EditorView.editable.of(false)), S && E.push(EditorState.readOnly.of(true)), [...E];
}, 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((b) => e2.state.sliceDoc(b.from, b.to)),
  selectedText: e2.state.selection.ranges.some((e3) => !e3.empty)
}), TimeoutLatch = class {
  constructor(e2, b) {
    this.timeLeftMS = void 0, this.timeoutMS = void 0, this.isCancelled = false, this.isTimeExhausted = false, this.callbacks = [], this.timeLeftMS = b, this.timeoutMS = b, 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: b, selection: x, onChange: S, onStatistics: C, onCreateEditor: w, onUpdate: T, extensions: E = emptyExtensions, autoFocus: D, theme: k = "light", height: A = null, minHeight: j = null, maxHeight: M = null, width: N = null, minWidth: P = null, maxWidth: F = null, placeholder: I = "", editable: L = true, readOnly: z = false, indentWithTab: B = true, basicSetup: V = true, root: H, initialState: U } = 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: A,
      minHeight: j,
      maxHeight: M,
      width: N,
      minWidth: P,
      maxWidth: F
    },
    "& .cm-scroller": { height: "100% !important" }
  }), $ = [
    EditorView.updateListener.of((e3) => {
      e3.docChanged && typeof S == "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)), S(e3.state.doc.toString(), e3)), C && C(getStatistics(e3));
    }),
    Q,
    ...getDefaultExtensions({
      theme: k,
      editable: L,
      readOnly: z,
      placeholder: I,
      indentWithTab: B,
      basicSetup: V
    })
  ];
  return T && typeof T == "function" && $.push(EditorView.updateListener.of(T)), $ = $.concat(E), (0, import_react.useLayoutEffect)(() => {
    if (W && !J) {
      var e3 = {
        doc: b,
        selection: x,
        extensions: $
      }, S2 = U ? EditorState.fromJSON(U.json, e3, U.fields) : EditorState.create(e3);
      if (Y(S2), !K) {
        var C2 = new EditorView({
          state: S2,
          parent: W,
          root: H
        });
        q(C2), w && w(C2, S2);
      }
    }
    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)(() => {
    D && K && K.focus();
  }, [D, K]), (0, import_react.useEffect)(() => {
    K && K.dispatch({ effects: StateEffect.reconfigure.of($) });
  }, [
    k,
    E,
    A,
    j,
    M,
    N,
    P,
    F,
    I,
    L,
    z,
    B,
    V,
    S,
    T
  ]), (0, import_react.useEffect)(() => {
    if (b !== void 0) {
      var e3 = K ? K.state.doc.toString() : "";
      if (K && b !== e3) {
        var x2 = X.current && !X.current.isDone, S2 = () => {
          K && b !== K.state.doc.toString() && K.dispatch({
            changes: {
              from: 0,
              to: K.state.doc.toString().length,
              insert: b || ""
            },
            annotations: [ExternalChange.of(true)]
          });
        };
        x2 ? Z.current = S2 : S2();
      }
    }
  }, [b, 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, b) => {
  var { className: x, value: S = "", selection: C, extensions: w = [], onChange: T, onStatistics: D, onCreateEditor: O, onUpdate: k, autoFocus: A, theme: j = "light", height: M, minHeight: N, maxHeight: P, width: F, minWidth: I, maxWidth: L, basicSetup: R, placeholder: z, indentWithTab: B, editable: V, readOnly: H, root: U, initialState: W } = e2, G = _objectWithoutPropertiesLoose(e2, _excluded), K = (0, import_react.useRef)(null), { state: q, view: J, container: Y, setContainer: X } = useCodeMirror({
    root: U,
    value: S,
    autoFocus: A,
    theme: j,
    height: M,
    minHeight: N,
    maxHeight: P,
    width: F,
    minWidth: I,
    maxWidth: L,
    basicSetup: R,
    placeholder: z,
    indentWithTab: B,
    editable: V,
    readOnly: H,
    selection: C,
    onChange: T,
    onStatistics: D,
    onCreateEditor: O,
    onUpdate: k,
    extensions: w,
    initialState: W
  });
  (0, import_react.useImperativeHandle)(b, () => ({
    editor: K.current,
    state: q,
    view: J
  }), [
    K,
    Y,
    q,
    J
  ]);
  var Z = (0, import_react.useCallback)((e3) => {
    K.current = e3, X(e3);
  }, [X]);
  if (typeof S != "string") throw Error("value must be typeof string but got " + typeof S);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", _extends({
    ref: Z,
    className: (typeof j == "string" ? "cm-theme-" + j : "cm-theme") + (x ? " " + x : "")
  }, G));
});
ReactCodeMirror.displayName = "CodeMirror";
var esm_default = ReactCodeMirror;
export {
  minimalSetup as n,
  esm_default as t
};
