var De = Object.defineProperty;
var f = (n, e) => De(n, "name", { value: e, configurable: !0 });
import { NodeProp as w, Tree as A, IterMode as Oe, TreeFragment as N, Parser as Be, NodeType as X } from "../../../../../@lezer_common@1.2.3/node_modules/@lezer/common/dist/index.js";
import { Facet as v, StateField as Y, RangeSetBuilder as ae, StateEffect as H, EditorState as B, Prec as Ie, combineConfig as fe, countColumn as Me, RangeSet as Ne } from "../../../../../@codemirror_state@6.5.2/node_modules/@codemirror/state/dist/index.js";
import { ViewPlugin as Z, gutter as Ee, EditorView as y, GutterMarker as Fe, Decoration as m, logException as Le, WidgetType as ce, Direction as ee } from "../../../../../@codemirror_view@6.36.4/node_modules/@codemirror/view/dist/index.js";
import { tagHighlighter as He, highlightTree as We, tags as h, styleTags as Re } from "../../../../../@lezer_highlight@1.2.1/node_modules/@lezer/highlight/dist/index.js";
import { StyleModule as te } from "../../../../../style-mod@4.1.2/node_modules/style-mod/src/style-mod.js";
var j;
const P = /* @__PURE__ */ new w();
function Ue(n) {
  return v.define({
    combine: n ? (e) => e.concat(n) : void 0
  });
}
f(Ue, "defineLanguageFacet");
const je = /* @__PURE__ */ new w();
class k {
  static {
    f(this, "Language");
  }
  /**
  Construct a language object. If you need to invoke this
  directly, first define a data facet with
  [`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
  configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
  to the language's outer syntax node.
  */
  constructor(e, t, r = [], i = "") {
    this.data = e, this.name = i, B.prototype.hasOwnProperty("tree") || Object.defineProperty(B.prototype, "tree", { get() {
      return b(this);
    } }), this.parser = t, this.extension = [
      x.of(this),
      B.languageData.of((o, s, a) => {
        let l = ne(o, s, a), c = l.type.prop(P);
        if (!c)
          return [];
        let u = o.facet(c), d = l.type.prop(je);
        if (d) {
          let g = l.resolve(s - l.from, a);
          for (let p of d)
            if (p.test(g, o)) {
              let T = o.facet(p.facet);
              return p.type == "replace" ? T : T.concat(u);
            }
        }
        return u;
      })
    ].concat(r);
  }
  /**
  Query whether this language is active at the given position.
  */
  isActiveAt(e, t, r = -1) {
    return ne(e, t, r).type.prop(P) == this.data;
  }
  /**
  Find the document regions that were parsed using this language.
  The returned regions will _include_ any nested languages rooted
  in this language, when those exist.
  */
  findRegions(e) {
    let t = e.facet(x);
    if (t?.data == this.data)
      return [{ from: 0, to: e.doc.length }];
    if (!t || !t.allowsNesting)
      return [];
    let r = [], i = /* @__PURE__ */ f((o, s) => {
      if (o.prop(P) == this.data) {
        r.push({ from: s, to: s + o.length });
        return;
      }
      let a = o.prop(w.mounted);
      if (a) {
        if (a.tree.prop(P) == this.data) {
          if (a.overlay)
            for (let l of a.overlay)
              r.push({ from: l.from + s, to: l.to + s });
          else
            r.push({ from: s, to: s + o.length });
          return;
        } else if (a.overlay) {
          let l = r.length;
          if (i(a.tree, a.overlay[0].from + s), r.length > l)
            return;
        }
      }
      for (let l = 0; l < o.children.length; l++) {
        let c = o.children[l];
        c instanceof A && i(c, o.positions[l] + s);
      }
    }, "explore");
    return i(b(e), 0), r;
  }
  /**
  Indicates whether this language allows nested languages. The
  default implementation returns true.
  */
  get allowsNesting() {
    return !0;
  }
}
k.setState = /* @__PURE__ */ H.define();
function ne(n, e, t) {
  let r = n.facet(x), i = b(n).topNode;
  if (!r || r.allowsNesting)
    for (let o = i; o; o = o.enter(e, t, Oe.ExcludeBuffers))
      o.type.isTop && (i = o);
  return i;
}
f(ne, "topNodeAt");
class J extends k {
  static {
    f(this, "LRLanguage");
  }
  constructor(e, t, r) {
    super(e, t, [], r), this.parser = t;
  }
  /**
  Define a language from a parser.
  */
  static define(e) {
    let t = Ue(e.languageData);
    return new J(t, e.parser.configure({
      props: [P.add((r) => r.isTop ? t : void 0)]
    }), e.name);
  }
  /**
  Create a new instance of this language with a reconfigured
  version of its parser and optionally a new name.
  */
  configure(e, t) {
    return new J(this.data, this.parser.configure(e), t || this.name);
  }
  get allowsNesting() {
    return this.parser.hasWrappers();
  }
}
function b(n) {
  let e = n.field(k.state, !1);
  return e ? e.tree : A.empty;
}
f(b, "syntaxTree");
class $e {
  static {
    f(this, "DocInput");
  }
  /**
  Create an input object for the given document.
  */
  constructor(e) {
    this.doc = e, this.cursorPos = 0, this.string = "", this.cursor = e.iter();
  }
  get length() {
    return this.doc.length;
  }
  syncTo(e) {
    return this.string = this.cursor.next(e - this.cursorPos).value, this.cursorPos = e + this.string.length, this.cursorPos - this.string.length;
  }
  chunk(e) {
    return this.syncTo(e), this.string;
  }
  get lineChunks() {
    return !0;
  }
  read(e, t) {
    let r = this.cursorPos - this.string.length;
    return e < r || t >= this.cursorPos ? this.doc.sliceString(e, t) : this.string.slice(e - r, t - r);
  }
}
let O = null;
class E {
  static {
    f(this, "ParseContext");
  }
  constructor(e, t, r = [], i, o, s, a, l) {
    this.parser = e, this.state = t, this.fragments = r, this.tree = i, this.treeLen = o, this.viewport = s, this.skipped = a, this.scheduleOn = l, this.parse = null, this.tempSkipped = [];
  }
  /**
  @internal
  */
  static create(e, t, r) {
    return new E(e, t, [], A.empty, 0, r, [], null);
  }
  startParse() {
    return this.parser.startParse(new $e(this.state.doc), this.fragments);
  }
  /**
  @internal
  */
  work(e, t) {
    return t != null && t >= this.state.doc.length && (t = void 0), this.tree != A.empty && this.isDone(t ?? this.state.doc.length) ? (this.takeTree(), !0) : this.withContext(() => {
      var r;
      if (typeof e == "number") {
        let i = Date.now() + e;
        e = /* @__PURE__ */ f(() => Date.now() > i, "until");
      }
      for (this.parse || (this.parse = this.startParse()), t != null && (this.parse.stoppedAt == null || this.parse.stoppedAt > t) && t < this.state.doc.length && this.parse.stopAt(t); ; ) {
        let i = this.parse.advance();
        if (i)
          if (this.fragments = this.withoutTempSkipped(N.addTree(i, this.fragments, this.parse.stoppedAt != null)), this.treeLen = (r = this.parse.stoppedAt) !== null && r !== void 0 ? r : this.state.doc.length, this.tree = i, this.parse = null, this.treeLen < (t ?? this.state.doc.length))
            this.parse = this.startParse();
          else
            return !0;
        if (e())
          return !1;
      }
    });
  }
  /**
  @internal
  */
  takeTree() {
    let e, t;
    this.parse && (e = this.parse.parsedPos) >= this.treeLen && ((this.parse.stoppedAt == null || this.parse.stoppedAt > e) && this.parse.stopAt(e), this.withContext(() => {
      for (; !(t = this.parse.advance()); )
        ;
    }), this.treeLen = e, this.tree = t, this.fragments = this.withoutTempSkipped(N.addTree(this.tree, this.fragments, !0)), this.parse = null);
  }
  withContext(e) {
    let t = O;
    O = this;
    try {
      return e();
    } finally {
      O = t;
    }
  }
  withoutTempSkipped(e) {
    for (let t; t = this.tempSkipped.pop(); )
      e = re(e, t.from, t.to);
    return e;
  }
  /**
  @internal
  */
  changes(e, t) {
    let { fragments: r, tree: i, treeLen: o, viewport: s, skipped: a } = this;
    if (this.takeTree(), !e.empty) {
      let l = [];
      if (e.iterChangedRanges((c, u, d, g) => l.push({ fromA: c, toA: u, fromB: d, toB: g })), r = N.applyChanges(r, l), i = A.empty, o = 0, s = { from: e.mapPos(s.from, -1), to: e.mapPos(s.to, 1) }, this.skipped.length) {
        a = [];
        for (let c of this.skipped) {
          let u = e.mapPos(c.from, 1), d = e.mapPos(c.to, -1);
          u < d && a.push({ from: u, to: d });
        }
      }
    }
    return new E(this.parser, t, r, i, o, s, a, this.scheduleOn);
  }
  /**
  @internal
  */
  updateViewport(e) {
    if (this.viewport.from == e.from && this.viewport.to == e.to)
      return !1;
    this.viewport = e;
    let t = this.skipped.length;
    for (let r = 0; r < this.skipped.length; r++) {
      let { from: i, to: o } = this.skipped[r];
      i < e.to && o > e.from && (this.fragments = re(this.fragments, i, o), this.skipped.splice(r--, 1));
    }
    return this.skipped.length >= t ? !1 : (this.reset(), !0);
  }
  /**
  @internal
  */
  reset() {
    this.parse && (this.takeTree(), this.parse = null);
  }
  /**
  Notify the parse scheduler that the given region was skipped
  because it wasn't in view, and the parse should be restarted
  when it comes into view.
  */
  skipUntilInView(e, t) {
    this.skipped.push({ from: e, to: t });
  }
  /**
  Returns a parser intended to be used as placeholder when
  asynchronously loading a nested parser. It'll skip its input and
  mark it as not-really-parsed, so that the next update will parse
  it again.
  
  When `until` is given, a reparse will be scheduled when that
  promise resolves.
  */
  static getSkippingParser(e) {
    return new class extends Be {
      createParse(t, r, i) {
        let o = i[0].from, s = i[i.length - 1].to;
        return {
          parsedPos: o,
          advance() {
            let l = O;
            if (l) {
              for (let c of i)
                l.tempSkipped.push(c);
              e && (l.scheduleOn = l.scheduleOn ? Promise.all([l.scheduleOn, e]) : e);
            }
            return this.parsedPos = s, new A(X.none, [], [], s - o);
          },
          stoppedAt: null,
          stopAt() {
          }
        };
      }
    }();
  }
  /**
  @internal
  */
  isDone(e) {
    e = Math.min(e, this.state.doc.length);
    let t = this.fragments;
    return this.treeLen >= e && t.length && t[0].from == 0 && t[0].to >= e;
  }
  /**
  Get the context for the current parse, or `null` if no editor
  parse is in progress.
  */
  static get() {
    return O;
  }
}
function re(n, e, t) {
  return N.applyChanges(n, [{ fromA: e, toA: t, fromB: e, toB: t }]);
}
f(re, "cutFragments");
class D {
  static {
    f(this, "LanguageState");
  }
  constructor(e) {
    this.context = e, this.tree = e.tree;
  }
  apply(e) {
    if (!e.docChanged && this.tree == this.context.tree)
      return this;
    let t = this.context.changes(e.changes, e.state), r = this.context.treeLen == e.startState.doc.length ? void 0 : Math.max(e.changes.mapPos(this.context.treeLen), t.viewport.to);
    return t.work(20, r) || t.takeTree(), new D(t);
  }
  static init(e) {
    let t = Math.min(3e3, e.doc.length), r = E.create(e.facet(x).parser, e, { from: 0, to: t });
    return r.work(20, t) || r.takeTree(), new D(r);
  }
}
k.state = /* @__PURE__ */ Y.define({
  create: D.init,
  update(n, e) {
    for (let t of e.effects)
      if (t.is(k.setState))
        return t.value;
    return e.startState.facet(x) != e.state.facet(x) ? D.init(e.state) : n.apply(e);
  }
});
let ue = /* @__PURE__ */ f((n) => {
  let e = setTimeout(
    () => n(),
    500
    /* Work.MaxPause */
  );
  return () => clearTimeout(e);
}, "requestIdle");
typeof requestIdleCallback < "u" && (ue = /* @__PURE__ */ f((n) => {
  let e = -1, t = setTimeout(
    () => {
      e = requestIdleCallback(n, {
        timeout: 400
        /* Work.MinPause */
      });
    },
    100
    /* Work.MinPause */
  );
  return () => e < 0 ? clearTimeout(t) : cancelIdleCallback(e);
}, "requestIdle"));
const $ = typeof navigator < "u" && (!((j = navigator.scheduling) === null || j === void 0) && j.isInputPending) ? () => navigator.scheduling.isInputPending() : null, qe = /* @__PURE__ */ Z.fromClass(class {
  static {
    f(this, "ParseWorker");
  }
  constructor(e) {
    this.view = e, this.working = null, this.workScheduled = 0, this.chunkEnd = -1, this.chunkBudget = -1, this.work = this.work.bind(this), this.scheduleWork();
  }
  update(e) {
    let t = this.view.state.field(k.state).context;
    (t.updateViewport(e.view.viewport) || this.view.viewport.to > t.treeLen) && this.scheduleWork(), (e.docChanged || e.selectionSet) && (this.view.hasFocus && (this.chunkBudget += 50), this.scheduleWork()), this.checkAsyncSchedule(t);
  }
  scheduleWork() {
    if (this.working)
      return;
    let { state: e } = this.view, t = e.field(k.state);
    (t.tree != t.context.tree || !t.context.isDone(e.doc.length)) && (this.working = ue(this.work));
  }
  work(e) {
    this.working = null;
    let t = Date.now();
    if (this.chunkEnd < t && (this.chunkEnd < 0 || this.view.hasFocus) && (this.chunkEnd = t + 3e4, this.chunkBudget = 3e3), this.chunkBudget <= 0)
      return;
    let { state: r, viewport: { to: i } } = this.view, o = r.field(k.state);
    if (o.tree == o.context.tree && o.context.isDone(
      i + 1e5
      /* Work.MaxParseAhead */
    ))
      return;
    let s = Date.now() + Math.min(this.chunkBudget, 100, e && !$ ? Math.max(25, e.timeRemaining() - 5) : 1e9), a = o.context.treeLen < i && r.doc.length > i + 1e3, l = o.context.work(() => $ && $() || Date.now() > s, i + (a ? 0 : 1e5));
    this.chunkBudget -= Date.now() - t, (l || this.chunkBudget <= 0) && (o.context.takeTree(), this.view.dispatch({ effects: k.setState.of(new D(o.context)) })), this.chunkBudget > 0 && !(l && !a) && this.scheduleWork(), this.checkAsyncSchedule(o.context);
  }
  checkAsyncSchedule(e) {
    e.scheduleOn && (this.workScheduled++, e.scheduleOn.then(() => this.scheduleWork()).catch((t) => Le(this.view.state, t)).then(() => this.workScheduled--), e.scheduleOn = null);
  }
  destroy() {
    this.working && this.working();
  }
  isWorking() {
    return !!(this.working || this.workScheduled > 0);
  }
}, {
  eventHandlers: { focus() {
    this.scheduleWork();
  } }
}), x = /* @__PURE__ */ v.define({
  combine(n) {
    return n.length ? n[0] : null;
  },
  enables: /* @__PURE__ */ f((n) => [
    k.state,
    qe,
    y.contentAttributes.compute([n], (e) => {
      let t = e.facet(n);
      return t && t.name ? { "data-language": t.name } : {};
    })
  ], "enables")
});
class Lt {
  static {
    f(this, "LanguageSupport");
  }
  /**
  Create a language support object.
  */
  constructor(e, t = []) {
    this.language = e, this.support = t, this.extension = [e, t];
  }
}
const ze = /* @__PURE__ */ v.define(), he = /* @__PURE__ */ v.define({
  combine: /* @__PURE__ */ f((n) => {
    if (!n.length)
      return "  ";
    let e = n[0];
    if (!e || /\S/.test(e) || Array.from(e).some((t) => t != e[0]))
      throw new Error("Invalid indent unit: " + JSON.stringify(n[0]));
    return e;
  }, "combine")
});
function Ge(n) {
  let e = n.facet(he);
  return e.charCodeAt(0) == 9 ? n.tabSize * e.length : e.length;
}
f(Ge, "getIndentUnit");
function Je(n, e) {
  let t = "", r = n.tabSize, i = n.facet(he)[0];
  if (i == "	") {
    for (; e >= r; )
      t += "	", e -= r;
    i = " ";
  }
  for (let o = 0; o < e; o++)
    t += i;
  return t;
}
f(Je, "indentString");
function Ve(n, e) {
  n instanceof B && (n = new de(n));
  for (let r of n.state.facet(ze)) {
    let i = r(n, e);
    if (i !== void 0)
      return i;
  }
  let t = b(n.state);
  return t.length >= e ? Qe(n, t, e) : null;
}
f(Ve, "getIndentation");
class de {
  static {
    f(this, "IndentContext");
  }
  /**
  Create an indent context.
  */
  constructor(e, t = {}) {
    this.state = e, this.options = t, this.unit = Ge(e);
  }
  /**
  Get a description of the line at the given position, taking
  [simulated line
  breaks](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
  into account. If there is such a break at `pos`, the `bias`
  argument determines whether the part of the line line before or
  after the break is used.
  */
  lineAt(e, t = 1) {
    let r = this.state.doc.lineAt(e), { simulateBreak: i, simulateDoubleBreak: o } = this.options;
    return i != null && i >= r.from && i <= r.to ? o && i == e ? { text: "", from: e } : (t < 0 ? i < e : i <= e) ? { text: r.text.slice(i - r.from), from: i } : { text: r.text.slice(0, i - r.from), from: r.from } : r;
  }
  /**
  Get the text directly after `pos`, either the entire line
  or the next 100 characters, whichever is shorter.
  */
  textAfterPos(e, t = 1) {
    if (this.options.simulateDoubleBreak && e == this.options.simulateBreak)
      return "";
    let { text: r, from: i } = this.lineAt(e, t);
    return r.slice(e - i, Math.min(r.length, e + 100 - i));
  }
  /**
  Find the column for the given position.
  */
  column(e, t = 1) {
    let { text: r, from: i } = this.lineAt(e, t), o = this.countColumn(r, e - i), s = this.options.overrideIndentation ? this.options.overrideIndentation(i) : -1;
    return s > -1 && (o += s - this.countColumn(r, r.search(/\S|$/))), o;
  }
  /**
  Find the column position (taking tabs into account) of the given
  position in the given string.
  */
  countColumn(e, t = e.length) {
    return Me(e, this.state.tabSize, t);
  }
  /**
  Find the indentation column of the line at the given point.
  */
  lineIndent(e, t = 1) {
    let { text: r, from: i } = this.lineAt(e, t), o = this.options.overrideIndentation;
    if (o) {
      let s = o(i);
      if (s > -1)
        return s;
    }
    return this.countColumn(r, r.search(/\S|$/));
  }
  /**
  Returns the [simulated line
  break](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
  for this context, if any.
  */
  get simulatedBreak() {
    return this.options.simulateBreak || null;
  }
}
const Ke = /* @__PURE__ */ new w();
function Qe(n, e, t) {
  let r = e.resolveStack(t), i = e.resolveInner(t, -1).resolve(t, 0).enterUnfinishedNodesBefore(t);
  if (i != r.node) {
    let o = [];
    for (let s = i; s && !(s.from == r.node.from && s.type == r.node.type); s = s.parent)
      o.push(s);
    for (let s = o.length - 1; s >= 0; s--)
      r = { node: o[s], next: r };
  }
  return pe(r, n, t);
}
f(Qe, "syntaxIndentation");
function pe(n, e, t) {
  for (let r = n; r; r = r.next) {
    let i = Ye(r.node);
    if (i)
      return i(_.create(e, t, r));
  }
  return 0;
}
f(pe, "indentFor");
function Xe(n) {
  return n.pos == n.options.simulateBreak && n.options.simulateDoubleBreak;
}
f(Xe, "ignoreClosed");
function Ye(n) {
  let e = n.type.prop(Ke);
  if (e)
    return e;
  let t = n.firstChild, r;
  if (t && (r = t.type.prop(w.closedBy))) {
    let i = n.lastChild, o = i && r.indexOf(i.name) > -1;
    return (s) => me(s, !0, 1, void 0, o && !Xe(s) ? i.from : void 0);
  }
  return n.parent == null ? Ze : null;
}
f(Ye, "indentStrategy");
function Ze() {
  return 0;
}
f(Ze, "topIndent");
class _ extends de {
  static {
    f(this, "TreeIndentContext");
  }
  constructor(e, t, r) {
    super(e.state, e.options), this.base = e, this.pos = t, this.context = r;
  }
  /**
  The syntax tree node to which the indentation strategy
  applies.
  */
  get node() {
    return this.context.node;
  }
  /**
  @internal
  */
  static create(e, t, r) {
    return new _(e, t, r);
  }
  /**
  Get the text directly after `this.pos`, either the entire line
  or the next 100 characters, whichever is shorter.
  */
  get textAfter() {
    return this.textAfterPos(this.pos);
  }
  /**
  Get the indentation at the reference line for `this.node`, which
  is the line on which it starts, unless there is a node that is
  _not_ a parent of this node covering the start of that line. If
  so, the line at the start of that node is tried, again skipping
  on if it is covered by another such node.
  */
  get baseIndent() {
    return this.baseIndentFor(this.node);
  }
  /**
  Get the indentation for the reference line of the given node
  (see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
  */
  baseIndentFor(e) {
    let t = this.state.doc.lineAt(e.from);
    for (; ; ) {
      let r = e.resolve(t.from);
      for (; r.parent && r.parent.from == r.from; )
        r = r.parent;
      if (_e(r, e))
        break;
      t = this.state.doc.lineAt(r.from);
    }
    return this.lineIndent(t.from);
  }
  /**
  Continue looking for indentations in the node's parent nodes,
  and return the result of that.
  */
  continue() {
    return pe(this.context.next, this.base, this.pos);
  }
}
function _e(n, e) {
  for (let t = e; t; t = t.parent)
    if (n == t)
      return !0;
  return !1;
}
f(_e, "isParent");
function et(n) {
  let e = n.node, t = e.childAfter(e.from), r = e.lastChild;
  if (!t)
    return null;
  let i = n.options.simulateBreak, o = n.state.doc.lineAt(t.from), s = i == null || i <= o.from ? o.to : Math.min(o.to, i);
  for (let a = t.to; ; ) {
    let l = e.childAfter(a);
    if (!l || l == r)
      return null;
    if (!l.type.isSkipped) {
      if (l.from >= s)
        return null;
      let c = /^ */.exec(o.text.slice(t.to - o.from))[0].length;
      return { from: t.from, to: t.to + c };
    }
    a = l.to;
  }
}
f(et, "bracketedAligned");
function Ht({ closing: n, align: e = !0, units: t = 1 }) {
  return (r) => me(r, e, t, n);
}
f(Ht, "delimitedIndent");
function me(n, e, t, r, i) {
  let o = n.textAfter, s = o.match(/^\s*/)[0].length, a = r && o.slice(s, s + r.length) == r || i == n.pos + s, l = e ? et(n) : null;
  return l ? a ? n.column(l.from) : n.column(l.to) : n.baseIndent + (a ? 0 : n.unit * t);
}
f(me, "delimitedStrategy");
const Wt = /* @__PURE__ */ f((n) => n.baseIndent, "flatIndent");
function Rt({ except: n, units: e = 1 } = {}) {
  return (t) => {
    let r = n && n.test(t.textAfter);
    return t.baseIndent + (r ? 0 : e * t.unit);
  };
}
f(Rt, "continuedIndent");
const tt = 200;
function Ut() {
  return B.transactionFilter.of((n) => {
    if (!n.docChanged || !n.isUserEvent("input.type") && !n.isUserEvent("input.complete"))
      return n;
    let e = n.startState.languageDataAt("indentOnInput", n.startState.selection.main.head);
    if (!e.length)
      return n;
    let t = n.newDoc, { head: r } = n.newSelection.main, i = t.lineAt(r);
    if (r > i.from + tt)
      return n;
    let o = t.sliceString(i.from, r);
    if (!e.some((c) => c.test(o)))
      return n;
    let { state: s } = n, a = -1, l = [];
    for (let { head: c } of s.selection.ranges) {
      let u = s.doc.lineAt(c);
      if (u.from == a)
        continue;
      a = u.from;
      let d = Ve(s, u.from);
      if (d == null)
        continue;
      let g = /^\s*/.exec(u.text)[0], p = Je(s, d);
      g != p && l.push({ from: u.from, to: u.from + g.length, insert: p });
    }
    return l.length ? [n, { changes: l, sequential: !0 }] : n;
  });
}
f(Ut, "indentOnInput");
const nt = /* @__PURE__ */ v.define(), rt = /* @__PURE__ */ new w();
function jt(n) {
  let e = n.firstChild, t = n.lastChild;
  return e && e.to < t.from ? { from: e.to, to: t.type.isError ? n.to : t.from } : null;
}
f(jt, "foldInside");
function it(n, e, t) {
  let r = b(n);
  if (r.length < t)
    return null;
  let i = r.resolveStack(t, 1), o = null;
  for (let s = i; s; s = s.next) {
    let a = s.node;
    if (a.to <= t || a.from > t)
      continue;
    if (o && a.from < e)
      break;
    let l = a.type.prop(rt);
    if (l && (a.to < r.length - 50 || r.length == n.doc.length || !ot(a))) {
      let c = l(a, n);
      c && c.from <= t && c.from >= e && c.to > t && (o = c);
    }
  }
  return o;
}
f(it, "syntaxFolding");
function ot(n) {
  let e = n.lastChild;
  return e && e.to == n.to && e.type.isError;
}
f(ot, "isUnfinished");
function F(n, e, t) {
  for (let r of n.facet(nt)) {
    let i = r(n, e, t);
    if (i)
      return i;
  }
  return it(n, e, t);
}
f(F, "foldable");
function ge(n, e) {
  let t = e.mapPos(n.from, 1), r = e.mapPos(n.to, -1);
  return t >= r ? void 0 : { from: t, to: r };
}
f(ge, "mapRange");
const W = /* @__PURE__ */ H.define({ map: ge }), I = /* @__PURE__ */ H.define({ map: ge });
function ke(n) {
  let e = [];
  for (let { head: t } of n.state.selection.ranges)
    e.some((r) => r.from <= t && r.to >= t) || e.push(n.lineBlockAt(t));
  return e;
}
f(ke, "selectedLines");
const S = /* @__PURE__ */ Y.define({
  create() {
    return m.none;
  },
  update(n, e) {
    n = n.map(e.changes);
    for (let t of e.effects)
      if (t.is(W) && !st(n, t.value.from, t.value.to)) {
        let { preparePlaceholder: r } = e.state.facet(we), i = r ? m.replace({ widget: new ht(r(e.state, t.value)) }) : ie;
        n = n.update({ add: [i.range(t.value.from, t.value.to)] });
      } else t.is(I) && (n = n.update({
        filter: /* @__PURE__ */ f((r, i) => t.value.from != r || t.value.to != i, "filter"),
        filterFrom: t.value.from,
        filterTo: t.value.to
      }));
    if (e.selection) {
      let t = !1, { head: r } = e.selection.main;
      n.between(r, r, (i, o) => {
        i < r && o > r && (t = !0);
      }), t && (n = n.update({
        filterFrom: r,
        filterTo: r,
        filter: /* @__PURE__ */ f((i, o) => o <= r || i >= r, "filter")
      }));
    }
    return n;
  },
  provide: /* @__PURE__ */ f((n) => y.decorations.from(n), "provide"),
  toJSON(n, e) {
    let t = [];
    return n.between(0, e.doc.length, (r, i) => {
      t.push(r, i);
    }), t;
  },
  fromJSON(n) {
    if (!Array.isArray(n) || n.length % 2)
      throw new RangeError("Invalid JSON for fold state");
    let e = [];
    for (let t = 0; t < n.length; ) {
      let r = n[t++], i = n[t++];
      if (typeof r != "number" || typeof i != "number")
        throw new RangeError("Invalid JSON for fold state");
      e.push(ie.range(r, i));
    }
    return m.set(e, !0);
  }
});
function L(n, e, t) {
  var r;
  let i = null;
  return (r = n.field(S, !1)) === null || r === void 0 || r.between(e, t, (o, s) => {
    (!i || i.from > o) && (i = { from: o, to: s });
  }), i;
}
f(L, "findFold");
function st(n, e, t) {
  let r = !1;
  return n.between(e, e, (i, o) => {
    i == e && o == t && (r = !0);
  }), r;
}
f(st, "foldExists");
function be(n, e) {
  return n.field(S, !1) ? e : e.concat(H.appendConfig.of(ve()));
}
f(be, "maybeEnable");
const lt = /* @__PURE__ */ f((n) => {
  for (let e of ke(n)) {
    let t = F(n.state, e.from, e.to);
    if (t)
      return n.dispatch({ effects: be(n.state, [W.of(t), ye(n, t)]) }), !0;
  }
  return !1;
}, "foldCode"), at = /* @__PURE__ */ f((n) => {
  if (!n.state.field(S, !1))
    return !1;
  let e = [];
  for (let t of ke(n)) {
    let r = L(n.state, t.from, t.to);
    r && e.push(I.of(r), ye(n, r, !1));
  }
  return e.length && n.dispatch({ effects: e }), e.length > 0;
}, "unfoldCode");
function ye(n, e, t = !0) {
  let r = n.state.doc.lineAt(e.from).number, i = n.state.doc.lineAt(e.to).number;
  return y.announce.of(`${n.state.phrase(t ? "Folded lines" : "Unfolded lines")} ${r} ${n.state.phrase("to")} ${i}.`);
}
f(ye, "announceFold");
const ft = /* @__PURE__ */ f((n) => {
  let { state: e } = n, t = [];
  for (let r = 0; r < e.doc.length; ) {
    let i = n.lineBlockAt(r), o = F(e, i.from, i.to);
    o && t.push(W.of(o)), r = (o ? n.lineBlockAt(o.to) : i).to + 1;
  }
  return t.length && n.dispatch({ effects: be(n.state, t) }), !!t.length;
}, "foldAll"), ct = /* @__PURE__ */ f((n) => {
  let e = n.state.field(S, !1);
  if (!e || !e.size)
    return !1;
  let t = [];
  return e.between(0, n.state.doc.length, (r, i) => {
    t.push(I.of({ from: r, to: i }));
  }), n.dispatch({ effects: t }), !0;
}, "unfoldAll"), $t = [
  { key: "Ctrl-Shift-[", mac: "Cmd-Alt-[", run: lt },
  { key: "Ctrl-Shift-]", mac: "Cmd-Alt-]", run: at },
  { key: "Ctrl-Alt-[", run: ft },
  { key: "Ctrl-Alt-]", run: ct }
], ut = {
  placeholderDOM: null,
  preparePlaceholder: null,
  placeholderText: "…"
}, we = /* @__PURE__ */ v.define({
  combine(n) {
    return fe(n, ut);
  }
});
function ve(n) {
  return [S, pt];
}
f(ve, "codeFolding");
function xe(n, e) {
  let { state: t } = n, r = t.facet(we), i = /* @__PURE__ */ f((s) => {
    let a = n.lineBlockAt(n.posAtDOM(s.target)), l = L(n.state, a.from, a.to);
    l && n.dispatch({ effects: I.of(l) }), s.preventDefault();
  }, "onclick");
  if (r.placeholderDOM)
    return r.placeholderDOM(n, i, e);
  let o = document.createElement("span");
  return o.textContent = r.placeholderText, o.setAttribute("aria-label", t.phrase("folded code")), o.title = t.phrase("unfold"), o.className = "cm-foldPlaceholder", o.onclick = i, o;
}
f(xe, "widgetToDOM");
const ie = /* @__PURE__ */ m.replace({ widget: /* @__PURE__ */ new class extends ce {
  toDOM(n) {
    return xe(n, null);
  }
}() });
class ht extends ce {
  static {
    f(this, "PreparedFoldWidget");
  }
  constructor(e) {
    super(), this.value = e;
  }
  eq(e) {
    return this.value == e.value;
  }
  toDOM(e) {
    return xe(e, this.value);
  }
}
const dt = {
  openText: "⌄",
  closedText: "›",
  markerDOM: null,
  domEventHandlers: {},
  foldingChanged: /* @__PURE__ */ f(() => !1, "foldingChanged")
};
class q extends Fe {
  static {
    f(this, "FoldMarker");
  }
  constructor(e, t) {
    super(), this.config = e, this.open = t;
  }
  eq(e) {
    return this.config == e.config && this.open == e.open;
  }
  toDOM(e) {
    if (this.config.markerDOM)
      return this.config.markerDOM(this.open);
    let t = document.createElement("span");
    return t.textContent = this.open ? this.config.openText : this.config.closedText, t.title = e.state.phrase(this.open ? "Fold line" : "Unfold line"), t;
  }
}
function qt(n = {}) {
  let e = Object.assign(Object.assign({}, dt), n), t = new q(e, !0), r = new q(e, !1), i = Z.fromClass(class {
    constructor(s) {
      this.from = s.viewport.from, this.markers = this.buildMarkers(s);
    }
    update(s) {
      (s.docChanged || s.viewportChanged || s.startState.facet(x) != s.state.facet(x) || s.startState.field(S, !1) != s.state.field(S, !1) || b(s.startState) != b(s.state) || e.foldingChanged(s)) && (this.markers = this.buildMarkers(s.view));
    }
    buildMarkers(s) {
      let a = new ae();
      for (let l of s.viewportLineBlocks) {
        let c = L(s.state, l.from, l.to) ? r : F(s.state, l.from, l.to) ? t : null;
        c && a.add(l.from, l.from, c);
      }
      return a.finish();
    }
  }), { domEventHandlers: o } = e;
  return [
    i,
    Ee({
      class: "cm-foldGutter",
      markers(s) {
        var a;
        return ((a = s.plugin(i)) === null || a === void 0 ? void 0 : a.markers) || Ne.empty;
      },
      initialSpacer() {
        return new q(e, !1);
      },
      domEventHandlers: Object.assign(Object.assign({}, o), { click: /* @__PURE__ */ f((s, a, l) => {
        if (o.click && o.click(s, a, l))
          return !0;
        let c = L(s.state, a.from, a.to);
        if (c)
          return s.dispatch({ effects: I.of(c) }), !0;
        let u = F(s.state, a.from, a.to);
        return u ? (s.dispatch({ effects: W.of(u) }), !0) : !1;
      }, "click") })
    }),
    ve()
  ];
}
f(qt, "foldGutter");
const pt = /* @__PURE__ */ y.baseTheme({
  ".cm-foldPlaceholder": {
    backgroundColor: "#eee",
    border: "1px solid #ddd",
    color: "#888",
    borderRadius: ".2em",
    margin: "0 1px",
    padding: "0 1px",
    cursor: "pointer"
  },
  ".cm-foldGutter span": {
    padding: "0 1px",
    cursor: "pointer"
  }
});
class R {
  static {
    f(this, "HighlightStyle");
  }
  constructor(e, t) {
    this.specs = e;
    let r;
    function i(a) {
      let l = te.newName();
      return (r || (r = /* @__PURE__ */ Object.create(null)))["." + l] = a, l;
    }
    f(i, "def");
    const o = typeof t.all == "string" ? t.all : t.all ? i(t.all) : void 0, s = t.scope;
    this.scope = s instanceof k ? (a) => a.prop(P) == s.data : s ? (a) => a == s : void 0, this.style = He(e.map((a) => ({
      tag: a.tag,
      class: a.class || i(Object.assign({}, a, { tag: null }))
    })), {
      all: o
    }).style, this.module = r ? new te(r) : null, this.themeType = t.themeType;
  }
  /**
  Create a highlighter style that associates the given styles to
  the given tags. The specs must be objects that hold a style tag
  or array of tags in their `tag` property, and either a single
  `class` property providing a static CSS class (for highlighter
  that rely on external styling), or a
  [`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
  set of CSS properties (which define the styling for those tags).
  
  The CSS rules created for a highlighter will be emitted in the
  order of the spec's properties. That means that for elements that
  have multiple tags associated with them, styles defined further
  down in the list will have a higher CSS precedence than styles
  defined earlier.
  */
  static define(e, t) {
    return new R(e, t || {});
  }
}
const V = /* @__PURE__ */ v.define(), Se = /* @__PURE__ */ v.define({
  combine(n) {
    return n.length ? [n[0]] : null;
  }
});
function z(n) {
  let e = n.facet(V);
  return e.length ? e : n.facet(Se);
}
f(z, "getHighlighters");
function zt(n, e) {
  let t = [gt], r;
  return n instanceof R && (n.module && t.push(y.styleModule.of(n.module)), r = n.themeType), e?.fallback ? t.push(Se.of(n)) : r ? t.push(V.computeN([y.darkTheme], (i) => i.facet(y.darkTheme) == (r == "dark") ? [n] : [])) : t.push(V.of(n)), t;
}
f(zt, "syntaxHighlighting");
class mt {
  static {
    f(this, "TreeHighlighter");
  }
  constructor(e) {
    this.markCache = /* @__PURE__ */ Object.create(null), this.tree = b(e.state), this.decorations = this.buildDeco(e, z(e.state)), this.decoratedTo = e.viewport.to;
  }
  update(e) {
    let t = b(e.state), r = z(e.state), i = r != z(e.startState), { viewport: o } = e.view, s = e.changes.mapPos(this.decoratedTo, 1);
    t.length < o.to && !i && t.type == this.tree.type && s >= o.to ? (this.decorations = this.decorations.map(e.changes), this.decoratedTo = s) : (t != this.tree || e.viewportChanged || i) && (this.tree = t, this.decorations = this.buildDeco(e.view, r), this.decoratedTo = o.to);
  }
  buildDeco(e, t) {
    if (!t || !this.tree.length)
      return m.none;
    let r = new ae();
    for (let { from: i, to: o } of e.visibleRanges)
      We(this.tree, t, (s, a, l) => {
        r.add(s, a, this.markCache[l] || (this.markCache[l] = m.mark({ class: l })));
      }, i, o);
    return r.finish();
  }
}
const gt = /* @__PURE__ */ Ie.high(/* @__PURE__ */ Z.fromClass(mt, {
  decorations: /* @__PURE__ */ f((n) => n.decorations, "decorations")
})), Gt = /* @__PURE__ */ R.define([
  {
    tag: h.meta,
    color: "#404740"
  },
  {
    tag: h.link,
    textDecoration: "underline"
  },
  {
    tag: h.heading,
    textDecoration: "underline",
    fontWeight: "bold"
  },
  {
    tag: h.emphasis,
    fontStyle: "italic"
  },
  {
    tag: h.strong,
    fontWeight: "bold"
  },
  {
    tag: h.strikethrough,
    textDecoration: "line-through"
  },
  {
    tag: h.keyword,
    color: "#708"
  },
  {
    tag: [h.atom, h.bool, h.url, h.contentSeparator, h.labelName],
    color: "#219"
  },
  {
    tag: [h.literal, h.inserted],
    color: "#164"
  },
  {
    tag: [h.string, h.deleted],
    color: "#a11"
  },
  {
    tag: [h.regexp, h.escape, /* @__PURE__ */ h.special(h.string)],
    color: "#e40"
  },
  {
    tag: /* @__PURE__ */ h.definition(h.variableName),
    color: "#00f"
  },
  {
    tag: /* @__PURE__ */ h.local(h.variableName),
    color: "#30a"
  },
  {
    tag: [h.typeName, h.namespace],
    color: "#085"
  },
  {
    tag: h.className,
    color: "#167"
  },
  {
    tag: [/* @__PURE__ */ h.special(h.variableName), h.macroName],
    color: "#256"
  },
  {
    tag: /* @__PURE__ */ h.definition(h.propertyName),
    color: "#00c"
  },
  {
    tag: h.comment,
    color: "#940"
  },
  {
    tag: h.invalid,
    color: "#f00"
  }
]), kt = /* @__PURE__ */ y.baseTheme({
  "&.cm-focused .cm-matchingBracket": { backgroundColor: "#328c8252" },
  "&.cm-focused .cm-nonmatchingBracket": { backgroundColor: "#bb555544" }
}), Te = 1e4, Ce = "()[]{}", Ae = /* @__PURE__ */ v.define({
  combine(n) {
    return fe(n, {
      afterCursor: !0,
      brackets: Ce,
      maxScanDistance: Te,
      renderMatch: wt
    });
  }
}), bt = /* @__PURE__ */ m.mark({ class: "cm-matchingBracket" }), yt = /* @__PURE__ */ m.mark({ class: "cm-nonmatchingBracket" });
function wt(n) {
  let e = [], t = n.matched ? bt : yt;
  return e.push(t.range(n.start.from, n.start.to)), n.end && e.push(t.range(n.end.from, n.end.to)), e;
}
f(wt, "defaultRenderMatch");
const vt = /* @__PURE__ */ Y.define({
  create() {
    return m.none;
  },
  update(n, e) {
    if (!e.docChanged && !e.selection)
      return n;
    let t = [], r = e.state.facet(Ae);
    for (let i of e.state.selection.ranges) {
      if (!i.empty)
        continue;
      let o = M(e.state, i.head, -1, r) || i.head > 0 && M(e.state, i.head - 1, 1, r) || r.afterCursor && (M(e.state, i.head, 1, r) || i.head < e.state.doc.length && M(e.state, i.head + 1, -1, r));
      o && (t = t.concat(r.renderMatch(o, e.state)));
    }
    return m.set(t, !0);
  },
  provide: /* @__PURE__ */ f((n) => y.decorations.from(n), "provide")
}), xt = [
  vt,
  kt
];
function Jt(n = {}) {
  return [Ae.of(n), xt];
}
f(Jt, "bracketMatching");
const St = /* @__PURE__ */ new w();
function K(n, e, t) {
  let r = n.prop(e < 0 ? w.openedBy : w.closedBy);
  if (r)
    return r;
  if (n.name.length == 1) {
    let i = t.indexOf(n.name);
    if (i > -1 && i % 2 == (e < 0 ? 1 : 0))
      return [t[i + e]];
  }
  return null;
}
f(K, "matchingNodes");
function Q(n) {
  let e = n.type.prop(St);
  return e ? e(n.node) : n;
}
f(Q, "findHandle");
function M(n, e, t, r = {}) {
  let i = r.maxScanDistance || Te, o = r.brackets || Ce, s = b(n), a = s.resolveInner(e, t);
  for (let l = a; l; l = l.parent) {
    let c = K(l.type, t, o);
    if (c && l.from < l.to) {
      let u = Q(l);
      if (u && (t > 0 ? e >= u.from && e < u.to : e > u.from && e <= u.to))
        return Tt(n, e, t, l, u, c, o);
    }
  }
  return Ct(n, e, t, s, a.type, i, o);
}
f(M, "matchBrackets");
function Tt(n, e, t, r, i, o, s) {
  let a = r.parent, l = { from: i.from, to: i.to }, c = 0, u = a?.cursor();
  if (u && (t < 0 ? u.childBefore(r.from) : u.childAfter(r.to)))
    do
      if (t < 0 ? u.to <= r.from : u.from >= r.to) {
        if (c == 0 && o.indexOf(u.type.name) > -1 && u.from < u.to) {
          let d = Q(u);
          return { start: l, end: d ? { from: d.from, to: d.to } : void 0, matched: !0 };
        } else if (K(u.type, t, s))
          c++;
        else if (K(u.type, -t, s)) {
          if (c == 0) {
            let d = Q(u);
            return {
              start: l,
              end: d && d.from < d.to ? { from: d.from, to: d.to } : void 0,
              matched: !1
            };
          }
          c--;
        }
      }
    while (t < 0 ? u.prevSibling() : u.nextSibling());
  return { start: l, matched: !1 };
}
f(Tt, "matchMarkedBrackets");
function Ct(n, e, t, r, i, o, s) {
  let a = t < 0 ? n.sliceDoc(e - 1, e) : n.sliceDoc(e, e + 1), l = s.indexOf(a);
  if (l < 0 || l % 2 == 0 != t > 0)
    return null;
  let c = { from: t < 0 ? e - 1 : e, to: t > 0 ? e + 1 : e }, u = n.doc.iterRange(e, t > 0 ? n.doc.length : 0), d = 0;
  for (let g = 0; !u.next().done && g <= o; ) {
    let p = u.value;
    t < 0 && (g += p.length);
    let T = e + g * t;
    for (let C = t > 0 ? 0 : p.length - 1, Pe = t > 0 ? p.length : -1; C != Pe; C += t) {
      let U = s.indexOf(p[C]);
      if (!(U < 0 || r.resolveInner(T + C, 1).type != i))
        if (U % 2 == 0 == t > 0)
          d++;
        else {
          if (d == 1)
            return { start: c, end: { from: T + C, to: T + C + 1 }, matched: U >> 1 == l >> 1 };
          d--;
        }
    }
    t > 0 && (g += p.length);
  }
  return u.done ? { start: c, matched: !1 } : null;
}
f(Ct, "matchPlainBrackets");
const At = /* @__PURE__ */ Object.create(null), oe = [X.none], se = [], le = /* @__PURE__ */ Object.create(null), Pt = /* @__PURE__ */ Object.create(null);
for (let [n, e] of [
  ["variable", "variableName"],
  ["variable-2", "variableName.special"],
  ["string-2", "string.special"],
  ["def", "variableName.definition"],
  ["tag", "tagName"],
  ["attribute", "attributeName"],
  ["type", "typeName"],
  ["builtin", "variableName.standard"],
  ["qualifier", "modifier"],
  ["error", "invalid"],
  ["header", "heading"],
  ["property", "propertyName"]
])
  Pt[n] = /* @__PURE__ */ Dt(At, e);
function G(n, e) {
  se.indexOf(n) > -1 || (se.push(n), console.warn(e));
}
f(G, "warnForPart");
function Dt(n, e) {
  let t = [];
  for (let a of e.split(" ")) {
    let l = [];
    for (let c of a.split(".")) {
      let u = n[c] || h[c];
      u ? typeof u == "function" ? l.length ? l = l.map(u) : G(c, `Modifier ${c} used at start of tag`) : l.length ? G(c, `Tag ${c} used as modifier`) : l = Array.isArray(u) ? u : [u] : G(c, `Unknown highlighting tag ${c}`);
    }
    for (let c of l)
      t.push(c);
  }
  if (!t.length)
    return 0;
  let r = e.replace(/ /g, "_"), i = r + " " + t.map((a) => a.id), o = le[i];
  if (o)
    return o.id;
  let s = le[i] = X.define({
    id: oe.length,
    name: r,
    props: [Re({ [r]: t })]
  });
  return oe.push(s), s.id;
}
f(Dt, "createTokenType");
ee.RTL, ee.LTR;
export {
  $e as DocInput,
  R as HighlightStyle,
  de as IndentContext,
  J as LRLanguage,
  k as Language,
  Lt as LanguageSupport,
  E as ParseContext,
  _ as TreeIndentContext,
  Jt as bracketMatching,
  St as bracketMatchingHandle,
  ve as codeFolding,
  Rt as continuedIndent,
  Gt as defaultHighlightStyle,
  Ue as defineLanguageFacet,
  Ht as delimitedIndent,
  Wt as flatIndent,
  ft as foldAll,
  lt as foldCode,
  W as foldEffect,
  qt as foldGutter,
  jt as foldInside,
  $t as foldKeymap,
  rt as foldNodeProp,
  nt as foldService,
  S as foldState,
  F as foldable,
  Ge as getIndentUnit,
  Ve as getIndentation,
  Ke as indentNodeProp,
  Ut as indentOnInput,
  ze as indentService,
  Je as indentString,
  he as indentUnit,
  x as language,
  P as languageDataProp,
  M as matchBrackets,
  je as sublanguageProp,
  zt as syntaxHighlighting,
  b as syntaxTree,
  ct as unfoldAll,
  at as unfoldCode,
  I as unfoldEffect
};
