var Le = Object.defineProperty;
var h = (i, e) => Le(i, "name", { value: e, configurable: !0 });
import { Prec as _, StateField as ee, Facet as be, combineConfig as Me, StateEffect as T, codePointAt as S, EditorSelection as C, codePointSize as O, RangeSet as Be, Annotation as ke, Transaction as Fe, Text as je, fromCodePoint as xe, MapMode as G, RangeValue as $e, CharCategory as J } from "../../../../../@codemirror_state@6.5.2/node_modules/@codemirror/state/dist/index.js";
import { ViewPlugin as Ne, EditorView as L, showTooltip as Ue, logException as Z, getTooltip as we, keymap as Ce, Decoration as V, WidgetType as We, Direction as He } from "../../../../../@codemirror_view@6.36.4/node_modules/@codemirror/view/dist/index.js";
import { syntaxTree as q, indentUnit as Ve } from "../../../../../@codemirror_language@6.11.0/node_modules/@codemirror/language/dist/index.js";
class ve {
  static {
    h(this, "CompletionContext");
  }
  /**
  Create a new completion context. (Mostly useful for testing
  completion sources—in the editor, the extension will create
  these for you.)
  */
  constructor(e, t, n, s) {
    this.state = e, this.pos = t, this.explicit = n, this.view = s, this.abortListeners = [], this.abortOnDocChange = !1;
  }
  /**
  Get the extent, content, and (if there is a token) type of the
  token before `this.pos`.
  */
  tokenBefore(e) {
    let t = q(this.state).resolveInner(this.pos, -1);
    for (; t && e.indexOf(t.name) < 0; )
      t = t.parent;
    return t ? {
      from: t.from,
      to: this.pos,
      text: this.state.sliceDoc(t.from, this.pos),
      type: t.type
    } : null;
  }
  /**
  Get the match of the given expression directly before the
  cursor.
  */
  matchBefore(e) {
    let t = this.state.doc.lineAt(this.pos), n = Math.max(t.from, this.pos - 250), s = t.text.slice(n - t.from, this.pos - t.from), o = s.search(Se(e, !1));
    return o < 0 ? null : { from: n + o, to: this.pos, text: s.slice(o) };
  }
  /**
  Yields true when the query has been aborted. Can be useful in
  asynchronous queries to avoid doing work that will be ignored.
  */
  get aborted() {
    return this.abortListeners == null;
  }
  /**
  Allows you to register abort handlers, which will be called when
  the query is
  [aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
  
  By default, running queries will not be aborted for regular
  typing or backspacing, on the assumption that they are likely to
  return a result with a
  [`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) field that
  allows the result to be used after all. Passing `onDocChange:
  true` will cause this query to be aborted for any document
  change.
  */
  addEventListener(e, t, n) {
    e == "abort" && this.abortListeners && (this.abortListeners.push(t), n && n.onDocChange && (this.abortOnDocChange = !0));
  }
}
function ae(i) {
  let e = Object.keys(i).join(""), t = /\w/.test(e);
  return t && (e = e.replace(/\w/g, "")), `[${t ? "\\w" : ""}${e.replace(/[^\w\s]/g, "\\$&")}]`;
}
h(ae, "toSet");
function qe(i) {
  let e = /* @__PURE__ */ Object.create(null), t = /* @__PURE__ */ Object.create(null);
  for (let { label: s } of i) {
    e[s[0]] = !0;
    for (let o = 1; o < s.length; o++)
      t[s[o]] = !0;
  }
  let n = ae(e) + ae(t) + "*$";
  return [new RegExp("^" + n), new RegExp(n)];
}
h(qe, "prefixMatch");
function ze(i) {
  let e = i.map((s) => typeof s == "string" ? { label: s } : s), [t, n] = e.every((s) => /^\w+$/.test(s.label)) ? [/\w*$/, /\w+$/] : qe(e);
  return (s) => {
    let o = s.matchBefore(n);
    return o || s.explicit ? { from: o ? o.from : s.pos, options: e, validFor: t } : null;
  };
}
h(ze, "completeFromList");
function Ht(i, e) {
  return (t) => {
    for (let n = q(t.state).resolveInner(t.pos, -1); n; n = n.parent) {
      if (i.indexOf(n.name) > -1)
        return null;
      if (n.type.isTop)
        break;
    }
    return e(t);
  };
}
h(Ht, "ifNotIn");
class ce {
  static {
    h(this, "Option");
  }
  constructor(e, t, n, s) {
    this.completion = e, this.source = t, this.match = n, this.score = s;
  }
}
function A(i) {
  return i.selection.main.from;
}
h(A, "cur");
function Se(i, e) {
  var t;
  let { source: n } = i, s = e && n[0] != "^", o = n[n.length - 1] != "$";
  return !s && !o ? i : new RegExp(`${s ? "^" : ""}(?:${n})${o ? "$" : ""}`, (t = i.flags) !== null && t !== void 0 ? t : i.ignoreCase ? "i" : "");
}
h(Se, "ensureAnchor");
const te = /* @__PURE__ */ ke.define();
function Ke(i, e, t, n) {
  let { main: s } = i.selection, o = t - s.from, l = n - s.from;
  return Object.assign(Object.assign({}, i.changeByRange((a) => {
    if (a != s && t != n && i.sliceDoc(a.from + o, a.from + l) != i.sliceDoc(t, n))
      return { range: a };
    let r = i.toText(e);
    return {
      changes: { from: a.from + o, to: n == s.from ? a.to : a.from + l, insert: r },
      range: C.cursor(a.from + o + r.length)
    };
  })), { scrollIntoView: !0, userEvent: "input.complete" });
}
h(Ke, "insertCompletionText");
const fe = /* @__PURE__ */ new WeakMap();
function Qe(i) {
  if (!Array.isArray(i))
    return i;
  let e = fe.get(i);
  return e || fe.set(i, e = ze(i)), e;
}
h(Qe, "asSource");
const W = /* @__PURE__ */ T.define(), k = /* @__PURE__ */ T.define();
class Xe {
  static {
    h(this, "FuzzyMatcher");
  }
  constructor(e) {
    this.pattern = e, this.chars = [], this.folded = [], this.any = [], this.precise = [], this.byWord = [], this.score = 0, this.matched = [];
    for (let t = 0; t < e.length; ) {
      let n = S(e, t), s = O(n);
      this.chars.push(n);
      let o = e.slice(t, t + s), l = o.toUpperCase();
      this.folded.push(S(l == o ? o.toLowerCase() : l, 0)), t += s;
    }
    this.astral = e.length != this.chars.length;
  }
  ret(e, t) {
    return this.score = e, this.matched = t, this;
  }
  // Matches a given word (completion) against the pattern (input).
  // Will return a boolean indicating whether there was a match and,
  // on success, set `this.score` to the score, `this.matched` to an
  // array of `from, to` pairs indicating the matched parts of `word`.
  //
  // The score is a number that is more negative the worse the match
  // is. See `Penalty` above.
  match(e) {
    if (this.pattern.length == 0)
      return this.ret(-100, []);
    if (e.length < this.pattern.length)
      return null;
    let { chars: t, folded: n, any: s, precise: o, byWord: l } = this;
    if (t.length == 1) {
      let m = S(e, 0), D = O(m), I = D == e.length ? 0 : -100;
      if (m != t[0]) if (m == n[0])
        I += -200;
      else
        return null;
      return this.ret(I, [0, D]);
    }
    let a = e.indexOf(this.pattern);
    if (a == 0)
      return this.ret(e.length == this.pattern.length ? 0 : -100, [0, this.pattern.length]);
    let r = t.length, f = 0;
    if (a < 0) {
      for (let m = 0, D = Math.min(e.length, 200); m < D && f < r; ) {
        let I = S(e, m);
        (I == t[f] || I == n[f]) && (s[f++] = m), m += O(I);
      }
      if (f < r)
        return null;
    }
    let c = 0, p = 0, u = !1, d = 0, y = -1, w = -1, K = /[a-z]/.test(e), B = !0;
    for (let m = 0, D = Math.min(e.length, 200), I = 0; m < D && p < r; ) {
      let x = S(e, m);
      a < 0 && (c < r && x == t[c] && (o[c++] = m), d < r && (x == t[d] || x == n[d] ? (d == 0 && (y = m), w = m + 1, d++) : d = 0));
      let N, Q = x < 255 ? x >= 48 && x <= 57 || x >= 97 && x <= 122 ? 2 : x >= 65 && x <= 90 ? 1 : 0 : (N = xe(x)) != N.toLowerCase() ? 1 : N != N.toUpperCase() ? 2 : 0;
      (!m || Q == 1 && K || I == 0 && Q != 0) && (t[p] == x || n[p] == x && (u = !0) ? l[p++] = m : l.length && (B = !1)), I = Q, m += O(x);
    }
    return p == r && l[0] == 0 && B ? this.result(-100 + (u ? -200 : 0), l, e) : d == r && y == 0 ? this.ret(-200 - e.length + (w == e.length ? 0 : -100), [0, w]) : a > -1 ? this.ret(-700 - e.length, [a, a + this.pattern.length]) : d == r ? this.ret(-900 - e.length, [y, w]) : p == r ? this.result(-100 + (u ? -200 : 0) + -700 + (B ? 0 : -1100), l, e) : t.length == 2 ? null : this.result((s[0] ? -700 : 0) + -200 + -1100, s, e);
  }
  result(e, t, n) {
    let s = [], o = 0;
    for (let l of t) {
      let a = l + (this.astral ? O(S(n, l)) : 1);
      o && s[o - 1] == l ? s[o - 1] = a : (s[o++] = l, s[o++] = a);
    }
    return this.ret(e - n.length, s);
  }
}
class Ye {
  static {
    h(this, "StrictMatcher");
  }
  constructor(e) {
    this.pattern = e, this.matched = [], this.score = 0, this.folded = e.toLowerCase();
  }
  match(e) {
    if (e.length < this.pattern.length)
      return null;
    let t = e.slice(0, this.pattern.length), n = t == this.pattern ? 0 : t.toLowerCase() == this.folded ? -200 : null;
    return n == null ? null : (this.matched = [0, t.length], this.score = n + (e.length == this.pattern.length ? 0 : -100), this);
  }
}
const g = /* @__PURE__ */ be.define({
  combine(i) {
    return Me(i, {
      activateOnTyping: !0,
      activateOnCompletion: /* @__PURE__ */ h(() => !1, "activateOnCompletion"),
      activateOnTypingDelay: 100,
      selectOnOpen: !0,
      override: null,
      closeOnBlur: !0,
      maxRenderedOptions: 100,
      defaultKeymap: !0,
      tooltipClass: /* @__PURE__ */ h(() => "", "tooltipClass"),
      optionClass: /* @__PURE__ */ h(() => "", "optionClass"),
      aboveCursor: !1,
      icons: !0,
      addToOptions: [],
      positionInfo: Ge,
      filterStrict: !1,
      compareCompletions: /* @__PURE__ */ h((e, t) => e.label.localeCompare(t.label), "compareCompletions"),
      interactionDelay: 75,
      updateSyncTime: 100
    }, {
      defaultKeymap: /* @__PURE__ */ h((e, t) => e && t, "defaultKeymap"),
      closeOnBlur: /* @__PURE__ */ h((e, t) => e && t, "closeOnBlur"),
      icons: /* @__PURE__ */ h((e, t) => e && t, "icons"),
      tooltipClass: /* @__PURE__ */ h((e, t) => (n) => he(e(n), t(n)), "tooltipClass"),
      optionClass: /* @__PURE__ */ h((e, t) => (n) => he(e(n), t(n)), "optionClass"),
      addToOptions: /* @__PURE__ */ h((e, t) => e.concat(t), "addToOptions"),
      filterStrict: /* @__PURE__ */ h((e, t) => e || t, "filterStrict")
    });
  }
});
function he(i, e) {
  return i ? e ? i + " " + e : i : e;
}
h(he, "joinClass");
function Ge(i, e, t, n, s, o) {
  let l = i.textDirection == He.RTL, a = l, r = !1, f = "top", c, p, u = e.left - s.left, d = s.right - e.right, y = n.right - n.left, w = n.bottom - n.top;
  if (a && u < Math.min(y, d) ? a = !1 : !a && d < Math.min(y, u) && (a = !0), y <= (a ? u : d))
    c = Math.max(s.top, Math.min(t.top, s.bottom - w)) - e.top, p = Math.min(400, a ? u : d);
  else {
    r = !0, p = Math.min(
      400,
      (l ? e.right : s.right - e.left) - 30
      /* Info.Margin */
    );
    let m = s.bottom - e.bottom;
    m >= w || m > e.top ? c = t.bottom - e.top : (f = "bottom", c = e.bottom - t.top);
  }
  let K = (e.bottom - e.top) / o.offsetHeight, B = (e.right - e.left) / o.offsetWidth;
  return {
    style: `${f}: ${c / K}px; max-width: ${p / B}px`,
    class: "cm-completionInfo-" + (r ? l ? "left-narrow" : "right-narrow" : a ? "left" : "right")
  };
}
h(Ge, "defaultPositionInfo");
function Je(i) {
  let e = i.addToOptions.slice();
  return i.icons && e.push({
    render(t) {
      let n = document.createElement("div");
      return n.classList.add("cm-completionIcon"), t.type && n.classList.add(...t.type.split(/\s+/g).map((s) => "cm-completionIcon-" + s)), n.setAttribute("aria-hidden", "true"), n;
    },
    position: 20
  }), e.push({
    render(t, n, s, o) {
      let l = document.createElement("span");
      l.className = "cm-completionLabel";
      let a = t.displayLabel || t.label, r = 0;
      for (let f = 0; f < o.length; ) {
        let c = o[f++], p = o[f++];
        c > r && l.appendChild(document.createTextNode(a.slice(r, c)));
        let u = l.appendChild(document.createElement("span"));
        u.appendChild(document.createTextNode(a.slice(c, p))), u.className = "cm-completionMatchedText", r = p;
      }
      return r < a.length && l.appendChild(document.createTextNode(a.slice(r))), l;
    },
    position: 50
  }, {
    render(t) {
      if (!t.detail)
        return null;
      let n = document.createElement("span");
      return n.className = "cm-completionDetail", n.textContent = t.detail, n;
    },
    position: 80
  }), e.sort((t, n) => t.position - n.position).map((t) => t.render);
}
h(Je, "optionContent");
function X(i, e, t) {
  if (i <= t)
    return { from: 0, to: i };
  if (e < 0 && (e = 0), e <= i >> 1) {
    let s = Math.floor(e / t);
    return { from: s * t, to: (s + 1) * t };
  }
  let n = Math.floor((i - e) / t);
  return { from: i - (n + 1) * t, to: i - n * t };
}
h(X, "rangeAroundSelected");
class Ze {
  static {
    h(this, "CompletionTooltip");
  }
  constructor(e, t, n) {
    this.view = e, this.stateField = t, this.applyCompletion = n, this.info = null, this.infoDestroy = null, this.placeInfoReq = {
      read: /* @__PURE__ */ h(() => this.measureInfo(), "read"),
      write: /* @__PURE__ */ h((r) => this.placeInfo(r), "write"),
      key: this
    }, this.space = null, this.currentClass = "";
    let s = e.state.field(t), { options: o, selected: l } = s.open, a = e.state.facet(g);
    this.optionContent = Je(a), this.optionClass = a.optionClass, this.tooltipClass = a.tooltipClass, this.range = X(o.length, l, a.maxRenderedOptions), this.dom = document.createElement("div"), this.dom.className = "cm-tooltip-autocomplete", this.updateTooltipClass(e.state), this.dom.addEventListener("mousedown", (r) => {
      let { options: f } = e.state.field(t).open;
      for (let c = r.target, p; c && c != this.dom; c = c.parentNode)
        if (c.nodeName == "LI" && (p = /-(\d+)$/.exec(c.id)) && +p[1] < f.length) {
          this.applyCompletion(e, f[+p[1]]), r.preventDefault();
          return;
        }
    }), this.dom.addEventListener("focusout", (r) => {
      let f = e.state.field(this.stateField, !1);
      f && f.tooltip && e.state.facet(g).closeOnBlur && r.relatedTarget != e.contentDOM && e.dispatch({ effects: k.of(null) });
    }), this.showOptions(o, s.id);
  }
  mount() {
    this.updateSel();
  }
  showOptions(e, t) {
    this.list && this.list.remove(), this.list = this.dom.appendChild(this.createListBox(e, t, this.range)), this.list.addEventListener("scroll", () => {
      this.info && this.view.requestMeasure(this.placeInfoReq);
    });
  }
  update(e) {
    var t;
    let n = e.state.field(this.stateField), s = e.startState.field(this.stateField);
    if (this.updateTooltipClass(e.state), n != s) {
      let { options: o, selected: l, disabled: a } = n.open;
      (!s.open || s.open.options != o) && (this.range = X(o.length, l, e.state.facet(g).maxRenderedOptions), this.showOptions(o, n.id)), this.updateSel(), a != ((t = s.open) === null || t === void 0 ? void 0 : t.disabled) && this.dom.classList.toggle("cm-tooltip-autocomplete-disabled", !!a);
    }
  }
  updateTooltipClass(e) {
    let t = this.tooltipClass(e);
    if (t != this.currentClass) {
      for (let n of this.currentClass.split(" "))
        n && this.dom.classList.remove(n);
      for (let n of t.split(" "))
        n && this.dom.classList.add(n);
      this.currentClass = t;
    }
  }
  positioned(e) {
    this.space = e, this.info && this.view.requestMeasure(this.placeInfoReq);
  }
  updateSel() {
    let e = this.view.state.field(this.stateField), t = e.open;
    if ((t.selected > -1 && t.selected < this.range.from || t.selected >= this.range.to) && (this.range = X(t.options.length, t.selected, this.view.state.facet(g).maxRenderedOptions), this.showOptions(t.options, e.id)), this.updateSelectedOption(t.selected)) {
      this.destroyInfo();
      let { completion: n } = t.options[t.selected], { info: s } = n;
      if (!s)
        return;
      let o = typeof s == "string" ? document.createTextNode(s) : s(n);
      if (!o)
        return;
      "then" in o ? o.then((l) => {
        l && this.view.state.field(this.stateField, !1) == e && this.addInfoPane(l, n);
      }).catch((l) => Z(this.view.state, l, "completion info")) : this.addInfoPane(o, n);
    }
  }
  addInfoPane(e, t) {
    this.destroyInfo();
    let n = this.info = document.createElement("div");
    if (n.className = "cm-tooltip cm-completionInfo", e.nodeType != null)
      n.appendChild(e), this.infoDestroy = null;
    else {
      let { dom: s, destroy: o } = e;
      n.appendChild(s), this.infoDestroy = o || null;
    }
    this.dom.appendChild(n), this.view.requestMeasure(this.placeInfoReq);
  }
  updateSelectedOption(e) {
    let t = null;
    for (let n = this.list.firstChild, s = this.range.from; n; n = n.nextSibling, s++)
      n.nodeName != "LI" || !n.id ? s-- : s == e ? n.hasAttribute("aria-selected") || (n.setAttribute("aria-selected", "true"), t = n) : n.hasAttribute("aria-selected") && n.removeAttribute("aria-selected");
    return t && et(this.list, t), t;
  }
  measureInfo() {
    let e = this.dom.querySelector("[aria-selected]");
    if (!e || !this.info)
      return null;
    let t = this.dom.getBoundingClientRect(), n = this.info.getBoundingClientRect(), s = e.getBoundingClientRect(), o = this.space;
    if (!o) {
      let l = this.dom.ownerDocument.documentElement;
      o = { left: 0, top: 0, right: l.clientWidth, bottom: l.clientHeight };
    }
    return s.top > Math.min(o.bottom, t.bottom) - 10 || s.bottom < Math.max(o.top, t.top) + 10 ? null : this.view.state.facet(g).positionInfo(this.view, t, s, n, o, this.dom);
  }
  placeInfo(e) {
    this.info && (e ? (e.style && (this.info.style.cssText = e.style), this.info.className = "cm-tooltip cm-completionInfo " + (e.class || "")) : this.info.style.cssText = "top: -1e6px");
  }
  createListBox(e, t, n) {
    const s = document.createElement("ul");
    s.id = t, s.setAttribute("role", "listbox"), s.setAttribute("aria-expanded", "true"), s.setAttribute("aria-label", this.view.state.phrase("Completions")), s.addEventListener("mousedown", (l) => {
      l.target == s && l.preventDefault();
    });
    let o = null;
    for (let l = n.from; l < n.to; l++) {
      let { completion: a, match: r } = e[l], { section: f } = a;
      if (f) {
        let u = typeof f == "string" ? f : f.name;
        if (u != o && (l > n.from || n.from == 0))
          if (o = u, typeof f != "string" && f.header)
            s.appendChild(f.header(f));
          else {
            let d = s.appendChild(document.createElement("completion-section"));
            d.textContent = u;
          }
      }
      const c = s.appendChild(document.createElement("li"));
      c.id = t + "-" + l, c.setAttribute("role", "option");
      let p = this.optionClass(a);
      p && (c.className = p);
      for (let u of this.optionContent) {
        let d = u(a, this.view.state, this.view, r);
        d && c.appendChild(d);
      }
    }
    return n.from && s.classList.add("cm-completionListIncompleteTop"), n.to < e.length && s.classList.add("cm-completionListIncompleteBottom"), s;
  }
  destroyInfo() {
    this.info && (this.infoDestroy && this.infoDestroy(), this.info.remove(), this.info = null);
  }
  destroy() {
    this.destroyInfo();
  }
}
function _e(i, e) {
  return (t) => new Ze(t, i, e);
}
h(_e, "completionTooltip");
function et(i, e) {
  let t = i.getBoundingClientRect(), n = e.getBoundingClientRect(), s = t.height / i.offsetHeight;
  n.top < t.top ? i.scrollTop -= (t.top - n.top) / s : n.bottom > t.bottom && (i.scrollTop += (n.bottom - t.bottom) / s);
}
h(et, "scrollIntoView");
function pe(i) {
  return (i.boost || 0) * 100 + (i.apply ? 10 : 0) + (i.info ? 5 : 0) + (i.type ? 1 : 0);
}
h(pe, "score");
function tt(i, e) {
  let t = [], n = null, s = /* @__PURE__ */ h((f) => {
    t.push(f);
    let { section: c } = f.completion;
    if (c) {
      n || (n = []);
      let p = typeof c == "string" ? c : c.name;
      n.some((u) => u.name == p) || n.push(typeof c == "string" ? { name: p } : c);
    }
  }, "addOption"), o = e.facet(g);
  for (let f of i)
    if (f.hasResult()) {
      let c = f.result.getMatch;
      if (f.result.filter === !1)
        for (let p of f.result.options)
          s(new ce(p, f.source, c ? c(p) : [], 1e9 - t.length));
      else {
        let p = e.sliceDoc(f.from, f.to), u, d = o.filterStrict ? new Ye(p) : new Xe(p);
        for (let y of f.result.options)
          if (u = d.match(y.label)) {
            let w = y.displayLabel ? c ? c(y, u.matched) : [] : u.matched;
            s(new ce(y, f.source, w, u.score + (y.boost || 0)));
          }
      }
    }
  if (n) {
    let f = /* @__PURE__ */ Object.create(null), c = 0, p = /* @__PURE__ */ h((u, d) => {
      var y, w;
      return ((y = u.rank) !== null && y !== void 0 ? y : 1e9) - ((w = d.rank) !== null && w !== void 0 ? w : 1e9) || (u.name < d.name ? -1 : 1);
    }, "cmp");
    for (let u of n.sort(p))
      c -= 1e5, f[u.name] = c;
    for (let u of t) {
      let { section: d } = u.completion;
      d && (u.score += f[typeof d == "string" ? d : d.name]);
    }
  }
  let l = [], a = null, r = o.compareCompletions;
  for (let f of t.sort((c, p) => p.score - c.score || r(c.completion, p.completion))) {
    let c = f.completion;
    !a || a.label != c.label || a.detail != c.detail || a.type != null && c.type != null && a.type != c.type || a.apply != c.apply || a.boost != c.boost ? l.push(f) : pe(f.completion) > pe(a) && (l[l.length - 1] = f), a = f.completion;
  }
  return l;
}
h(tt, "sortOptions");
class P {
  static {
    h(this, "CompletionDialog");
  }
  constructor(e, t, n, s, o, l) {
    this.options = e, this.attrs = t, this.tooltip = n, this.timestamp = s, this.selected = o, this.disabled = l;
  }
  setSelected(e, t) {
    return e == this.selected || e >= this.options.length ? this : new P(this.options, ue(t, e), this.tooltip, this.timestamp, e, this.disabled);
  }
  static build(e, t, n, s, o, l) {
    if (s && !l && e.some((f) => f.isPending))
      return s.setDisabled();
    let a = tt(e, t);
    if (!a.length)
      return s && e.some((f) => f.isPending) ? s.setDisabled() : null;
    let r = t.facet(g).selectOnOpen ? 0 : -1;
    if (s && s.selected != r && s.selected != -1) {
      let f = s.options[s.selected].completion;
      for (let c = 0; c < a.length; c++)
        if (a[c].completion == f) {
          r = c;
          break;
        }
    }
    return new P(a, ue(n, r), {
      pos: e.reduce((f, c) => c.hasResult() ? Math.min(f, c.from) : f, 1e8),
      create: rt,
      above: o.aboveCursor
    }, s ? s.timestamp : Date.now(), r, !1);
  }
  map(e) {
    return new P(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: e.mapPos(this.tooltip.pos) }), this.timestamp, this.selected, this.disabled);
  }
  setDisabled() {
    return new P(this.options, this.attrs, this.tooltip, this.timestamp, this.selected, !0);
  }
}
class H {
  static {
    h(this, "CompletionState");
  }
  constructor(e, t, n) {
    this.active = e, this.id = t, this.open = n;
  }
  static start() {
    return new H(ot, "cm-ac-" + Math.floor(Math.random() * 2e6).toString(36), null);
  }
  update(e) {
    let { state: t } = e, n = t.facet(g), o = (n.override || t.languageDataAt("autocomplete", A(t)).map(Qe)).map((r) => (this.active.find((c) => c.source == r) || new v(
      r,
      this.active.some(
        (c) => c.state != 0
        /* State.Inactive */
      ) ? 1 : 0
      /* State.Inactive */
    )).update(e, n));
    o.length == this.active.length && o.every((r, f) => r == this.active[f]) && (o = this.active);
    let l = this.open, a = e.effects.some((r) => r.is(ie));
    l && e.docChanged && (l = l.map(e.changes)), e.selection || o.some((r) => r.hasResult() && e.changes.touchesRange(r.from, r.to)) || !it(o, this.active) || a ? l = P.build(o, t, this.id, l, n, a) : l && l.disabled && !o.some((r) => r.isPending) && (l = null), !l && o.every((r) => !r.isPending) && o.some((r) => r.hasResult()) && (o = o.map((r) => r.hasResult() ? new v(
      r.source,
      0
      /* State.Inactive */
    ) : r));
    for (let r of e.effects)
      r.is(Oe) && (l = l && l.setSelected(r.value, this.id));
    return o == this.active && l == this.open ? this : new H(o, this.id, l);
  }
  get tooltip() {
    return this.open ? this.open.tooltip : null;
  }
  get attrs() {
    return this.open ? this.open.attrs : this.active.length ? nt : st;
  }
}
function it(i, e) {
  if (i == e)
    return !0;
  for (let t = 0, n = 0; ; ) {
    for (; t < i.length && !i[t].hasResult(); )
      t++;
    for (; n < e.length && !e[n].hasResult(); )
      n++;
    let s = t == i.length, o = n == e.length;
    if (s || o)
      return s == o;
    if (i[t++].result != e[n++].result)
      return !1;
  }
}
h(it, "sameResults");
const nt = {
  "aria-autocomplete": "list"
}, st = {};
function ue(i, e) {
  let t = {
    "aria-autocomplete": "list",
    "aria-haspopup": "listbox",
    "aria-controls": i
  };
  return e > -1 && (t["aria-activedescendant"] = i + "-" + e), t;
}
h(ue, "makeAttrs");
const ot = [];
function Ie(i, e) {
  if (i.isUserEvent("input.complete")) {
    let n = i.annotation(te);
    if (n && e.activateOnCompletion(n))
      return 12;
  }
  let t = i.isUserEvent("input.type");
  return t && e.activateOnTyping ? 5 : t ? 1 : i.isUserEvent("delete.backward") ? 2 : i.selection ? 8 : i.docChanged ? 16 : 0;
}
h(Ie, "getUpdateType");
class v {
  static {
    h(this, "ActiveSource");
  }
  constructor(e, t, n = !1) {
    this.source = e, this.state = t, this.explicit = n;
  }
  hasResult() {
    return !1;
  }
  get isPending() {
    return this.state == 1;
  }
  update(e, t) {
    let n = Ie(e, t), s = this;
    (n & 8 || n & 16 && this.touches(e)) && (s = new v(
      s.source,
      0
      /* State.Inactive */
    )), n & 4 && s.state == 0 && (s = new v(
      this.source,
      1
      /* State.Pending */
    )), s = s.updateFor(e, n);
    for (let o of e.effects)
      if (o.is(W))
        s = new v(s.source, 1, o.value);
      else if (o.is(k))
        s = new v(
          s.source,
          0
          /* State.Inactive */
        );
      else if (o.is(ie))
        for (let l of o.value)
          l.source == s.source && (s = l);
    return s;
  }
  updateFor(e, t) {
    return this.map(e.changes);
  }
  map(e) {
    return this;
  }
  touches(e) {
    return e.changes.touchesRange(A(e.state));
  }
}
class R extends v {
  static {
    h(this, "ActiveResult");
  }
  constructor(e, t, n, s, o, l) {
    super(e, 3, t), this.limit = n, this.result = s, this.from = o, this.to = l;
  }
  hasResult() {
    return !0;
  }
  updateFor(e, t) {
    var n;
    if (!(t & 3))
      return this.map(e.changes);
    let s = this.result;
    s.map && !e.changes.empty && (s = s.map(s, e.changes));
    let o = e.changes.mapPos(this.from), l = e.changes.mapPos(this.to, 1), a = A(e.state);
    if (a > l || !s || t & 2 && (A(e.startState) == this.from || a < this.limit))
      return new v(
        this.source,
        t & 4 ? 1 : 0
        /* State.Inactive */
      );
    let r = e.changes.mapPos(this.limit);
    return lt(s.validFor, e.state, o, l) ? new R(this.source, this.explicit, r, s, o, l) : s.update && (s = s.update(s, o, l, new ve(e.state, a, !1))) ? new R(this.source, this.explicit, r, s, s.from, (n = s.to) !== null && n !== void 0 ? n : A(e.state)) : new v(this.source, 1, this.explicit);
  }
  map(e) {
    return e.empty ? this : (this.result.map ? this.result.map(this.result, e) : this.result) ? new R(this.source, this.explicit, e.mapPos(this.limit), this.result, e.mapPos(this.from), e.mapPos(this.to, 1)) : new v(
      this.source,
      0
      /* State.Inactive */
    );
  }
  touches(e) {
    return e.changes.touchesRange(this.from, this.to);
  }
}
function lt(i, e, t, n) {
  if (!i)
    return !1;
  let s = e.sliceDoc(t, n);
  return typeof i == "function" ? i(s, t, n, e) : Se(i, !0).test(s);
}
h(lt, "checkValid");
const ie = /* @__PURE__ */ T.define({
  map(i, e) {
    return i.map((t) => t.map(e));
  }
}), Oe = /* @__PURE__ */ T.define(), b = /* @__PURE__ */ ee.define({
  create() {
    return H.start();
  },
  update(i, e) {
    return i.update(e);
  },
  provide: /* @__PURE__ */ h((i) => [
    Ue.from(i, (e) => e.tooltip),
    L.contentAttributes.from(i, (e) => e.attrs)
  ], "provide")
});
function ne(i, e) {
  const t = e.completion.apply || e.completion.label;
  let n = i.state.field(b).active.find((s) => s.source == e.source);
  return n instanceof R ? (typeof t == "string" ? i.dispatch(Object.assign(Object.assign({}, Ke(i.state, t, n.from, n.to)), { annotations: te.of(e.completion) })) : t(i, e.completion, n.from, n.to), !0) : !1;
}
h(ne, "applyCompletion");
const rt = /* @__PURE__ */ _e(b, ne);
function U(i, e = "option") {
  return (t) => {
    let n = t.state.field(b, !1);
    if (!n || !n.open || n.open.disabled || Date.now() - n.open.timestamp < t.state.facet(g).interactionDelay)
      return !1;
    let s = 1, o;
    e == "page" && (o = we(t, n.open.tooltip)) && (s = Math.max(2, Math.floor(o.dom.offsetHeight / o.dom.querySelector("li").offsetHeight) - 1));
    let { length: l } = n.open.options, a = n.open.selected > -1 ? n.open.selected + s * (i ? 1 : -1) : i ? 0 : l - 1;
    return a < 0 ? a = e == "page" ? 0 : l - 1 : a >= l && (a = e == "page" ? l - 1 : 0), t.dispatch({ effects: Oe.of(a) }), !0;
  };
}
h(U, "moveCompletionSelection");
const at = /* @__PURE__ */ h((i) => {
  let e = i.state.field(b, !1);
  return i.state.readOnly || !e || !e.open || e.open.selected < 0 || e.open.disabled || Date.now() - e.open.timestamp < i.state.facet(g).interactionDelay ? !1 : ne(i, e.open.options[e.open.selected]);
}, "acceptCompletion"), de = /* @__PURE__ */ h((i) => i.state.field(b, !1) ? (i.dispatch({ effects: W.of(!0) }), !0) : !1, "startCompletion"), ct = /* @__PURE__ */ h((i) => {
  let e = i.state.field(b, !1);
  return !e || !e.active.some(
    (t) => t.state != 0
    /* State.Inactive */
  ) ? !1 : (i.dispatch({ effects: k.of(null) }), !0);
}, "closeCompletion");
class ft {
  static {
    h(this, "RunningQuery");
  }
  constructor(e, t) {
    this.active = e, this.context = t, this.time = Date.now(), this.updates = [], this.done = void 0;
  }
}
const ht = 50, pt = 1e3, ut = /* @__PURE__ */ Ne.fromClass(class {
  constructor(i) {
    this.view = i, this.debounceUpdate = -1, this.running = [], this.debounceAccept = -1, this.pendingStart = !1, this.composing = 0;
    for (let e of i.state.field(b).active)
      e.isPending && this.startQuery(e);
  }
  update(i) {
    let e = i.state.field(b), t = i.state.facet(g);
    if (!i.selectionSet && !i.docChanged && i.startState.field(b) == e)
      return;
    let n = i.transactions.some((o) => {
      let l = Ie(o, t);
      return l & 8 || (o.selection || o.docChanged) && !(l & 3);
    });
    for (let o = 0; o < this.running.length; o++) {
      let l = this.running[o];
      if (n || l.context.abortOnDocChange && i.docChanged || l.updates.length + i.transactions.length > ht && Date.now() - l.time > pt) {
        for (let a of l.context.abortListeners)
          try {
            a();
          } catch (r) {
            Z(this.view.state, r);
          }
        l.context.abortListeners = null, this.running.splice(o--, 1);
      } else
        l.updates.push(...i.transactions);
    }
    this.debounceUpdate > -1 && clearTimeout(this.debounceUpdate), i.transactions.some((o) => o.effects.some((l) => l.is(W))) && (this.pendingStart = !0);
    let s = this.pendingStart ? 50 : t.activateOnTypingDelay;
    if (this.debounceUpdate = e.active.some((o) => o.isPending && !this.running.some((l) => l.active.source == o.source)) ? setTimeout(() => this.startUpdate(), s) : -1, this.composing != 0)
      for (let o of i.transactions)
        o.isUserEvent("input.type") ? this.composing = 2 : this.composing == 2 && o.selection && (this.composing = 3);
  }
  startUpdate() {
    this.debounceUpdate = -1, this.pendingStart = !1;
    let { state: i } = this.view, e = i.field(b);
    for (let t of e.active)
      t.isPending && !this.running.some((n) => n.active.source == t.source) && this.startQuery(t);
    this.running.length && e.open && e.open.disabled && (this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(g).updateSyncTime));
  }
  startQuery(i) {
    let { state: e } = this.view, t = A(e), n = new ve(e, t, i.explicit, this.view), s = new ft(i, n);
    this.running.push(s), Promise.resolve(i.source(n)).then((o) => {
      s.context.aborted || (s.done = o || null, this.scheduleAccept());
    }, (o) => {
      this.view.dispatch({ effects: k.of(null) }), Z(this.view.state, o);
    });
  }
  scheduleAccept() {
    this.running.every((i) => i.done !== void 0) ? this.accept() : this.debounceAccept < 0 && (this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(g).updateSyncTime));
  }
  // For each finished query in this.running, try to create a result
  // or, if appropriate, restart the query.
  accept() {
    var i;
    this.debounceAccept > -1 && clearTimeout(this.debounceAccept), this.debounceAccept = -1;
    let e = [], t = this.view.state.facet(g), n = this.view.state.field(b);
    for (let s = 0; s < this.running.length; s++) {
      let o = this.running[s];
      if (o.done === void 0)
        continue;
      if (this.running.splice(s--, 1), o.done) {
        let a = A(o.updates.length ? o.updates[0].startState : this.view.state), r = Math.min(a, o.done.from + (o.active.explicit ? 0 : 1)), f = new R(o.active.source, o.active.explicit, r, o.done, o.done.from, (i = o.done.to) !== null && i !== void 0 ? i : a);
        for (let c of o.updates)
          f = f.update(c, t);
        if (f.hasResult()) {
          e.push(f);
          continue;
        }
      }
      let l = n.active.find((a) => a.source == o.active.source);
      if (l && l.isPending)
        if (o.done == null) {
          let a = new v(
            o.active.source,
            0
            /* State.Inactive */
          );
          for (let r of o.updates)
            a = a.update(r, t);
          a.isPending || e.push(a);
        } else
          this.startQuery(l);
    }
    (e.length || n.open && n.open.disabled) && this.view.dispatch({ effects: ie.of(e) });
  }
}, {
  eventHandlers: {
    blur(i) {
      let e = this.view.state.field(b, !1);
      if (e && e.tooltip && this.view.state.facet(g).closeOnBlur) {
        let t = e.open && we(this.view, e.open.tooltip);
        (!t || !t.dom.contains(i.relatedTarget)) && setTimeout(() => this.view.dispatch({ effects: k.of(null) }), 10);
      }
    },
    compositionstart() {
      this.composing = 1;
    },
    compositionend() {
      this.composing == 3 && setTimeout(() => this.view.dispatch({ effects: W.of(!1) }), 20), this.composing = 0;
    }
  }
}), dt = typeof navigator == "object" && /* @__PURE__ */ /Win/.test(navigator.platform), mt = /* @__PURE__ */ _.highest(/* @__PURE__ */ L.domEventHandlers({
  keydown(i, e) {
    let t = e.state.field(b, !1);
    if (!t || !t.open || t.open.disabled || t.open.selected < 0 || i.key.length > 1 || i.ctrlKey && !(dt && i.altKey) || i.metaKey)
      return !1;
    let n = t.open.options[t.open.selected], s = t.active.find((l) => l.source == n.source), o = n.completion.commitCharacters || s.result.commitCharacters;
    return o && o.indexOf(i.key) > -1 && ne(e, n), !1;
  }
})), Te = /* @__PURE__ */ L.baseTheme({
  ".cm-tooltip.cm-tooltip-autocomplete": {
    "& > ul": {
      fontFamily: "monospace",
      whiteSpace: "nowrap",
      overflow: "hidden auto",
      maxWidth_fallback: "700px",
      maxWidth: "min(700px, 95vw)",
      minWidth: "250px",
      maxHeight: "10em",
      height: "100%",
      listStyle: "none",
      margin: 0,
      padding: 0,
      "& > li, & > completion-section": {
        padding: "1px 3px",
        lineHeight: 1.2
      },
      "& > li": {
        overflowX: "hidden",
        textOverflow: "ellipsis",
        cursor: "pointer"
      },
      "& > completion-section": {
        display: "list-item",
        borderBottom: "1px solid silver",
        paddingLeft: "0.5em",
        opacity: 0.7
      }
    }
  },
  "&light .cm-tooltip-autocomplete ul li[aria-selected]": {
    background: "#17c",
    color: "white"
  },
  "&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
    background: "#777"
  },
  "&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
    background: "#347",
    color: "white"
  },
  "&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": {
    background: "#444"
  },
  ".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
    content: '"···"',
    opacity: 0.5,
    display: "block",
    textAlign: "center"
  },
  ".cm-tooltip.cm-completionInfo": {
    position: "absolute",
    padding: "3px 9px",
    width: "max-content",
    maxWidth: "400px",
    boxSizing: "border-box",
    whiteSpace: "pre-line"
  },
  ".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
  ".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
  ".cm-completionInfo.cm-completionInfo-left-narrow": { right: "30px" },
  ".cm-completionInfo.cm-completionInfo-right-narrow": { left: "30px" },
  "&light .cm-snippetField": { backgroundColor: "#00000022" },
  "&dark .cm-snippetField": { backgroundColor: "#ffffff22" },
  ".cm-snippetFieldPosition": {
    verticalAlign: "text-top",
    width: 0,
    height: "1.15em",
    display: "inline-block",
    margin: "0 -0.7px -.7em",
    borderLeft: "1.4px dotted #888"
  },
  ".cm-completionMatchedText": {
    textDecoration: "underline"
  },
  ".cm-completionDetail": {
    marginLeft: "0.5em",
    fontStyle: "italic"
  },
  ".cm-completionIcon": {
    fontSize: "90%",
    width: ".8em",
    display: "inline-block",
    textAlign: "center",
    paddingRight: ".6em",
    opacity: "0.6",
    boxSizing: "content-box"
  },
  ".cm-completionIcon-function, .cm-completionIcon-method": {
    "&:after": { content: "'ƒ'" }
  },
  ".cm-completionIcon-class": {
    "&:after": { content: "'○'" }
  },
  ".cm-completionIcon-interface": {
    "&:after": { content: "'◌'" }
  },
  ".cm-completionIcon-variable": {
    "&:after": { content: "'𝑥'" }
  },
  ".cm-completionIcon-constant": {
    "&:after": { content: "'𝐶'" }
  },
  ".cm-completionIcon-type": {
    "&:after": { content: "'𝑡'" }
  },
  ".cm-completionIcon-enum": {
    "&:after": { content: "'∪'" }
  },
  ".cm-completionIcon-property": {
    "&:after": { content: "'□'" }
  },
  ".cm-completionIcon-keyword": {
    "&:after": { content: "'🔑︎'" }
    // Disable emoji rendering
  },
  ".cm-completionIcon-namespace": {
    "&:after": { content: "'▢'" }
  },
  ".cm-completionIcon-text": {
    "&:after": { content: "'abc'", fontSize: "50%", verticalAlign: "middle" }
  }
});
class gt {
  static {
    h(this, "FieldPos");
  }
  constructor(e, t, n, s) {
    this.field = e, this.line = t, this.from = n, this.to = s;
  }
}
class se {
  static {
    h(this, "FieldRange");
  }
  constructor(e, t, n) {
    this.field = e, this.from = t, this.to = n;
  }
  map(e) {
    let t = e.mapPos(this.from, -1, G.TrackDel), n = e.mapPos(this.to, 1, G.TrackDel);
    return t == null || n == null ? null : new se(this.field, t, n);
  }
}
class oe {
  static {
    h(this, "Snippet");
  }
  constructor(e, t) {
    this.lines = e, this.fieldPositions = t;
  }
  instantiate(e, t) {
    let n = [], s = [t], o = e.doc.lineAt(t), l = /^\s*/.exec(o.text)[0];
    for (let r of this.lines) {
      if (n.length) {
        let f = l, c = /^\t*/.exec(r)[0].length;
        for (let p = 0; p < c; p++)
          f += e.facet(Ve);
        s.push(t + f.length - c), r = f + r.slice(c);
      }
      n.push(r), t += r.length + 1;
    }
    let a = this.fieldPositions.map((r) => new se(r.field, s[r.line] + r.from, s[r.line] + r.to));
    return { text: n, ranges: a };
  }
  static parse(e) {
    let t = [], n = [], s = [], o;
    for (let l of e.split(/\r\n?|\n/)) {
      for (; o = /[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(l); ) {
        let a = o[1] ? +o[1] : null, r = o[2] || o[3] || "", f = -1, c = r.replace(/\\[{}]/g, (p) => p[1]);
        for (let p = 0; p < t.length; p++)
          (a != null ? t[p].seq == a : c && t[p].name == c) && (f = p);
        if (f < 0) {
          let p = 0;
          for (; p < t.length && (a == null || t[p].seq != null && t[p].seq < a); )
            p++;
          t.splice(p, 0, { seq: a, name: c }), f = p;
          for (let u of s)
            u.field >= f && u.field++;
        }
        s.push(new gt(f, n.length, o.index, o.index + c.length)), l = l.slice(0, o.index) + r + l.slice(o.index + o[0].length);
      }
      l = l.replace(/\\([{}])/g, (a, r, f) => {
        for (let c of s)
          c.line == n.length && c.from > f && (c.from--, c.to--);
        return r;
      }), n.push(l);
    }
    return new oe(n, s);
  }
}
let yt = /* @__PURE__ */ V.widget({ widget: /* @__PURE__ */ new class extends We {
  toDOM() {
    let i = document.createElement("span");
    return i.className = "cm-snippetFieldPosition", i;
  }
  ignoreEvent() {
    return !1;
  }
}() }), bt = /* @__PURE__ */ V.mark({ class: "cm-snippetField" });
class M {
  static {
    h(this, "ActiveSnippet");
  }
  constructor(e, t) {
    this.ranges = e, this.active = t, this.deco = V.set(e.map((n) => (n.from == n.to ? yt : bt).range(n.from, n.to)));
  }
  map(e) {
    let t = [];
    for (let n of this.ranges) {
      let s = n.map(e);
      if (!s)
        return null;
      t.push(s);
    }
    return new M(t, this.active);
  }
  selectionInsideField(e) {
    return e.ranges.every((t) => this.ranges.some((n) => n.field == this.active && n.from <= t.from && n.to >= t.to));
  }
}
const $ = /* @__PURE__ */ T.define({
  map(i, e) {
    return i && i.map(e);
  }
}), xt = /* @__PURE__ */ T.define(), F = /* @__PURE__ */ ee.define({
  create() {
    return null;
  },
  update(i, e) {
    for (let t of e.effects) {
      if (t.is($))
        return t.value;
      if (t.is(xt) && i)
        return new M(i.ranges, t.value);
    }
    return i && e.docChanged && (i = i.map(e.changes)), i && e.selection && !i.selectionInsideField(e.selection) && (i = null), i;
  },
  provide: /* @__PURE__ */ h((i) => L.decorations.from(i, (e) => e ? e.deco : V.none), "provide")
});
function le(i, e) {
  return C.create(i.filter((t) => t.field == e).map((t) => C.range(t.from, t.to)));
}
h(le, "fieldSelection");
function wt(i) {
  let e = oe.parse(i);
  return (t, n, s, o) => {
    let { text: l, ranges: a } = e.instantiate(t.state, s), { main: r } = t.state.selection, f = {
      changes: { from: s, to: o == r.from ? r.to : o, insert: je.of(l) },
      scrollIntoView: !0,
      annotations: n ? [te.of(n), Fe.userEvent.of("input.complete")] : void 0
    };
    if (a.length && (f.selection = le(a, 0)), a.some((c) => c.field > 0)) {
      let c = new M(a, 0), p = f.effects = [$.of(c)];
      t.state.field(F, !1) === void 0 && p.push(T.appendConfig.of([F, Ot, Tt, Te]));
    }
    t.dispatch(t.state.update(f));
  };
}
h(wt, "snippet");
function Ee(i) {
  return ({ state: e, dispatch: t }) => {
    let n = e.field(F, !1);
    if (!n || i < 0 && n.active == 0)
      return !1;
    let s = n.active + i, o = i > 0 && !n.ranges.some((l) => l.field == s + i);
    return t(e.update({
      selection: le(n.ranges, s),
      effects: $.of(o ? null : new M(n.ranges, s)),
      scrollIntoView: !0
    })), !0;
  };
}
h(Ee, "moveField");
const Ct = /* @__PURE__ */ h(({ state: i, dispatch: e }) => i.field(F, !1) ? (e(i.update({ effects: $.of(null) })), !0) : !1, "clearSnippet"), vt = /* @__PURE__ */ Ee(1), St = /* @__PURE__ */ Ee(-1), It = [
  { key: "Tab", run: vt, shift: St },
  { key: "Escape", run: Ct }
], me = /* @__PURE__ */ be.define({
  combine(i) {
    return i.length ? i[0] : It;
  }
}), Ot = /* @__PURE__ */ _.highest(/* @__PURE__ */ Ce.compute([me], (i) => i.facet(me)));
function Vt(i, e) {
  return Object.assign(Object.assign({}, e), { apply: wt(i) });
}
h(Vt, "snippetCompletion");
const Tt = /* @__PURE__ */ L.domEventHandlers({
  mousedown(i, e) {
    let t = e.state.field(F, !1), n;
    if (!t || (n = e.posAtCoords({ x: i.clientX, y: i.clientY })) == null)
      return !1;
    let s = t.ranges.find((o) => o.from <= n && o.to >= n);
    return !s || s.field == t.active ? !1 : (e.dispatch({
      selection: le(t.ranges, s.field),
      effects: $.of(t.ranges.some((o) => o.field > s.field) ? new M(t.ranges, s.field) : null),
      scrollIntoView: !0
    }), !0);
  }
}), j = {
  brackets: ["(", "[", "{", "'", '"'],
  before: ")]}:;>",
  stringPrefixes: []
}, E = /* @__PURE__ */ T.define({
  map(i, e) {
    let t = e.mapPos(i, -1, G.TrackAfter);
    return t ?? void 0;
  }
}), re = /* @__PURE__ */ new class extends $e {
}();
re.startSide = 1;
re.endSide = -1;
const Ae = /* @__PURE__ */ ee.define({
  create() {
    return Be.empty;
  },
  update(i, e) {
    if (i = i.map(e.changes), e.selection) {
      let t = e.state.doc.lineAt(e.selection.main.head);
      i = i.update({ filter: /* @__PURE__ */ h((n) => n >= t.from && n <= t.to, "filter") });
    }
    for (let t of e.effects)
      t.is(E) && (i = i.update({ add: [re.range(t.value, t.value + 1)] }));
    return i;
  }
});
function qt() {
  return [At, Ae];
}
h(qt, "closeBrackets");
const Y = "()[]{}<>«»»«［］｛｝";
function De(i) {
  for (let e = 0; e < Y.length; e += 2)
    if (Y.charCodeAt(e) == i)
      return Y.charAt(e + 1);
  return xe(i < 128 ? i : i + 1);
}
h(De, "closing");
function Pe(i, e) {
  return i.languageDataAt("closeBrackets", e)[0] || j;
}
h(Pe, "config");
const Et = typeof navigator == "object" && /* @__PURE__ */ /Android\b/.test(navigator.userAgent), At = /* @__PURE__ */ L.inputHandler.of((i, e, t, n) => {
  if ((Et ? i.composing : i.compositionStarted) || i.state.readOnly)
    return !1;
  let s = i.state.selection.main;
  if (n.length > 2 || n.length == 2 && O(S(n, 0)) == 1 || e != s.from || t != s.to)
    return !1;
  let o = Pt(i.state, n);
  return o ? (i.dispatch(o), !0) : !1;
}), Dt = /* @__PURE__ */ h(({ state: i, dispatch: e }) => {
  if (i.readOnly)
    return !1;
  let n = Pe(i, i.selection.main.head).brackets || j.brackets, s = null, o = i.changeByRange((l) => {
    if (l.empty) {
      let a = Rt(i.doc, l.head);
      for (let r of n)
        if (r == a && z(i.doc, l.head) == De(S(r, 0)))
          return {
            changes: { from: l.head - r.length, to: l.head + r.length },
            range: C.cursor(l.head - r.length)
          };
    }
    return { range: s = l };
  });
  return s || e(i.update(o, { scrollIntoView: !0, userEvent: "delete.backward" })), !s;
}, "deleteBracketPair"), zt = [
  { key: "Backspace", run: Dt }
];
function Pt(i, e) {
  let t = Pe(i, i.selection.main.head), n = t.brackets || j.brackets;
  for (let s of n) {
    let o = De(S(s, 0));
    if (e == s)
      return o == s ? Bt(i, s, n.indexOf(s + s + s) > -1, t) : Lt(i, s, o, t.before || j.before);
    if (e == o && Re(i, i.selection.main.from))
      return Mt(i, s, o);
  }
  return null;
}
h(Pt, "insertBracket");
function Re(i, e) {
  let t = !1;
  return i.field(Ae).between(0, i.doc.length, (n) => {
    n == e && (t = !0);
  }), t;
}
h(Re, "closedBracketAt");
function z(i, e) {
  let t = i.sliceString(e, e + 2);
  return t.slice(0, O(S(t, 0)));
}
h(z, "nextChar");
function Rt(i, e) {
  let t = i.sliceString(e - 2, e);
  return O(S(t, 0)) == t.length ? t : t.slice(1);
}
h(Rt, "prevChar");
function Lt(i, e, t, n) {
  let s = null, o = i.changeByRange((l) => {
    if (!l.empty)
      return {
        changes: [{ insert: e, from: l.from }, { insert: t, from: l.to }],
        effects: E.of(l.to + e.length),
        range: C.range(l.anchor + e.length, l.head + e.length)
      };
    let a = z(i.doc, l.head);
    return !a || /\s/.test(a) || n.indexOf(a) > -1 ? {
      changes: { insert: e + t, from: l.head },
      effects: E.of(l.head + e.length),
      range: C.cursor(l.head + e.length)
    } : { range: s = l };
  });
  return s ? null : i.update(o, {
    scrollIntoView: !0,
    userEvent: "input.type"
  });
}
h(Lt, "handleOpen");
function Mt(i, e, t) {
  let n = null, s = i.changeByRange((o) => o.empty && z(i.doc, o.head) == t ? {
    changes: { from: o.head, to: o.head + t.length, insert: t },
    range: C.cursor(o.head + t.length)
  } : n = { range: o });
  return n ? null : i.update(s, {
    scrollIntoView: !0,
    userEvent: "input.type"
  });
}
h(Mt, "handleClose");
function Bt(i, e, t, n) {
  let s = n.stringPrefixes || j.stringPrefixes, o = null, l = i.changeByRange((a) => {
    if (!a.empty)
      return {
        changes: [{ insert: e, from: a.from }, { insert: e, from: a.to }],
        effects: E.of(a.to + e.length),
        range: C.range(a.anchor + e.length, a.head + e.length)
      };
    let r = a.head, f = z(i.doc, r), c;
    if (f == e) {
      if (ge(i, r))
        return {
          changes: { insert: e + e, from: r },
          effects: E.of(r + e.length),
          range: C.cursor(r + e.length)
        };
      if (Re(i, r)) {
        let u = t && i.sliceDoc(r, r + e.length * 3) == e + e + e ? e + e + e : e;
        return {
          changes: { from: r, to: r + u.length, insert: u },
          range: C.cursor(r + u.length)
        };
      }
    } else {
      if (t && i.sliceDoc(r - 2 * e.length, r) == e + e && (c = ye(i, r - 2 * e.length, s)) > -1 && ge(i, c))
        return {
          changes: { insert: e + e + e + e, from: r },
          effects: E.of(r + e.length),
          range: C.cursor(r + e.length)
        };
      if (i.charCategorizer(r)(f) != J.Word && ye(i, r, s) > -1 && !kt(i, r, e, s))
        return {
          changes: { insert: e + e, from: r },
          effects: E.of(r + e.length),
          range: C.cursor(r + e.length)
        };
    }
    return { range: o = a };
  });
  return o ? null : i.update(l, {
    scrollIntoView: !0,
    userEvent: "input.type"
  });
}
h(Bt, "handleSame");
function ge(i, e) {
  let t = q(i).resolveInner(e + 1);
  return t.parent && t.from == e;
}
h(ge, "nodeStart");
function kt(i, e, t, n) {
  let s = q(i).resolveInner(e, -1), o = n.reduce((l, a) => Math.max(l, a.length), 0);
  for (let l = 0; l < 5; l++) {
    let a = i.sliceDoc(s.from, Math.min(s.to, s.from + t.length + o)), r = a.indexOf(t);
    if (!r || r > -1 && n.indexOf(a.slice(0, r)) > -1) {
      let c = s.firstChild;
      for (; c && c.from == s.from && c.to - c.from > t.length + r; ) {
        if (i.sliceDoc(c.to - t.length, c.to) == t)
          return !1;
        c = c.firstChild;
      }
      return !0;
    }
    let f = s.to == e && s.parent;
    if (!f)
      break;
    s = f;
  }
  return !1;
}
h(kt, "probablyInString");
function ye(i, e, t) {
  let n = i.charCategorizer(e);
  if (n(i.sliceDoc(e - 1, e)) != J.Word)
    return e;
  for (let s of t) {
    let o = e - s.length;
    if (i.sliceDoc(o, e) == s && n(i.sliceDoc(o - 1, o)) != J.Word)
      return o;
  }
  return -1;
}
h(ye, "canStartStringAt");
function Kt(i = {}) {
  return [
    mt,
    b,
    g.of(i),
    ut,
    jt,
    Te
  ];
}
h(Kt, "autocompletion");
const Ft = [
  { key: "Ctrl-Space", run: de },
  { mac: "Alt-`", run: de },
  { key: "Escape", run: ct },
  { key: "ArrowDown", run: /* @__PURE__ */ U(!0) },
  { key: "ArrowUp", run: /* @__PURE__ */ U(!1) },
  { key: "PageDown", run: /* @__PURE__ */ U(!0, "page") },
  { key: "PageUp", run: /* @__PURE__ */ U(!1, "page") },
  { key: "Enter", run: at }
], jt = /* @__PURE__ */ _.highest(/* @__PURE__ */ Ce.computeN([g], (i) => i.facet(g).defaultKeymap ? [Ft] : []));
function Qt(i) {
  let e = i.field(b, !1);
  return e && e.active.some((t) => t.isPending) ? "pending" : e && e.active.some(
    (t) => t.state != 0
    /* State.Inactive */
  ) ? "active" : null;
}
h(Qt, "completionStatus");
export {
  ve as CompletionContext,
  at as acceptCompletion,
  Kt as autocompletion,
  Ct as clearSnippet,
  qt as closeBrackets,
  zt as closeBracketsKeymap,
  ct as closeCompletion,
  ze as completeFromList,
  Ft as completionKeymap,
  Qt as completionStatus,
  Dt as deleteBracketPair,
  Ht as ifNotIn,
  Pt as insertBracket,
  Ke as insertCompletionText,
  U as moveCompletionSelection,
  vt as nextSnippetField,
  te as pickedCompletion,
  St as prevSnippetField,
  wt as snippet,
  Vt as snippetCompletion,
  me as snippetKeymap,
  de as startCompletion
};
