var G = Object.defineProperty;
var f = (o, t) => G(o, "name", { value: t, configurable: !0 });
import { NodeProp as J } from "../../../../../@lezer_common@1.2.3/node_modules/@lezer/common/dist/index.js";
let L = 0;
class d {
  static {
    f(this, "Tag");
  }
  /**
  @internal
  */
  constructor(t, a, i, n) {
    this.name = t, this.set = a, this.base = i, this.modified = n, this.id = L++;
  }
  toString() {
    let { name: t } = this;
    for (let a of this.modified)
      a.name && (t = `${a.name}(${t})`);
    return t;
  }
  static define(t, a) {
    let i = typeof t == "string" ? t : "?";
    if (t instanceof d && (a = t), a?.base)
      throw new Error("Can not derive from a modified tag");
    let n = new d(i, [], null, []);
    if (n.set.push(n), a)
      for (let s of a.set)
        n.set.push(s);
    return n;
  }
  /**
  Define a tag _modifier_, which is a function that, given a tag,
  will return a tag that is a subtag of the original. Applying the
  same modifier to a twice tag will return the same value (`m1(t1)
  == m1(t1)`) and applying multiple modifiers will, regardless or
  order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
  
  When multiple modifiers are applied to a given base tag, each
  smaller set of modifiers is registered as a parent, so that for
  example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
  `m1(m3(t1)`, and so on.
  */
  static defineModifier(t) {
    let a = new q(t);
    return (i) => i.modified.indexOf(a) > -1 ? i : q.get(i.base || i, i.modified.concat(a).sort((n, s) => n.id - s.id));
  }
}
let P = 0;
class q {
  static {
    f(this, "Modifier");
  }
  constructor(t) {
    this.name = t, this.instances = [], this.id = P++;
  }
  static get(t, a) {
    if (!a.length)
      return t;
    let i = a[0].instances.find((r) => r.base == t && Q(a, r.modified));
    if (i)
      return i;
    let n = [], s = new d(t.name, n, t, a);
    for (let r of a)
      r.instances.push(s);
    let g = U(a);
    for (let r of t.set)
      if (!r.modified.length)
        for (let p of g)
          n.push(q.get(r, p));
    return s;
  }
}
function Q(o, t) {
  return o.length == t.length && o.every((a, i) => a == t[i]);
}
f(Q, "sameArray");
function U(o) {
  let t = [[]];
  for (let a = 0; a < o.length; a++)
    for (let i = 0, n = t.length; i < n; i++)
      t.push(t[i].concat(o[a]));
  return t.sort((a, i) => i.length - a.length);
}
f(U, "powerSet");
function et(o) {
  let t = /* @__PURE__ */ Object.create(null);
  for (let a in o) {
    let i = o[a];
    Array.isArray(i) || (i = [i]);
    for (let n of a.split(" "))
      if (n) {
        let s = [], g = 2, r = n;
        for (let m = 0; ; ) {
          if (r == "..." && m > 0 && m + 3 == n.length) {
            g = 1;
            break;
          }
          let h = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(r);
          if (!h)
            throw new RangeError("Invalid path: " + n);
          if (s.push(h[0] == "*" ? "" : h[0][0] == '"' ? JSON.parse(h[0]) : h[0]), m += h[0].length, m == n.length)
            break;
          let w = n[m++];
          if (m == n.length && w == "!") {
            g = 0;
            break;
          }
          if (w != "/")
            throw new RangeError("Invalid path: " + n);
          r = n.slice(m);
        }
        let p = s.length - 1, c = s[p];
        if (!c)
          throw new RangeError("Invalid path: " + n);
        let M = new E(i, g, p > 0 ? s.slice(0, p) : null);
        t[c] = M.sort(t[c]);
      }
  }
  return V.add(t);
}
f(et, "styleTags");
const V = new J();
class E {
  static {
    f(this, "Rule");
  }
  constructor(t, a, i, n) {
    this.tags = t, this.mode = a, this.context = i, this.next = n;
  }
  get opaque() {
    return this.mode == 0;
  }
  get inherit() {
    return this.mode == 1;
  }
  sort(t) {
    return !t || t.depth < this.depth ? (this.next = t, this) : (t.next = this.sort(t.next), t);
  }
  get depth() {
    return this.context ? this.context.length : 0;
  }
}
E.empty = new E([], 2, null);
function W(o, t) {
  let a = /* @__PURE__ */ Object.create(null);
  for (let s of o)
    if (!Array.isArray(s.tag))
      a[s.tag.id] = s.class;
    else
      for (let g of s.tag)
        a[g.id] = s.class;
  let { scope: i, all: n = null } = t || {};
  return {
    style: /* @__PURE__ */ f((s) => {
      let g = n;
      for (let r of s)
        for (let p of r.set) {
          let c = a[p.id];
          if (c) {
            g = g ? g + " " + c : c;
            break;
          }
        }
      return g;
    }, "style"),
    scope: i
  };
}
f(W, "tagHighlighter");
function X(o, t) {
  let a = null;
  for (let i of o) {
    let n = i.style(t);
    n && (a = a ? a + " " + n : n);
  }
  return a;
}
f(X, "highlightTags");
function at(o, t, a, i = 0, n = o.length) {
  let s = new Y(i, Array.isArray(t) ? t : [t], a);
  s.highlightRange(o.cursor(), i, n, "", s.highlighters), s.flush(n);
}
f(at, "highlightTree");
class Y {
  static {
    f(this, "HighlightBuilder");
  }
  constructor(t, a, i) {
    this.at = t, this.highlighters = a, this.span = i, this.class = "";
  }
  startSpan(t, a) {
    a != this.class && (this.flush(t), t > this.at && (this.at = t), this.class = a);
  }
  flush(t) {
    t > this.at && this.class && this.span(this.at, t, this.class);
  }
  highlightRange(t, a, i, n, s) {
    let { type: g, from: r, to: p } = t;
    if (r >= i || p <= a)
      return;
    g.isTop && (s = this.highlighters.filter((w) => !w.scope || w.scope(g)));
    let c = n, M = Z(t) || E.empty, m = X(s, M.tags);
    if (m && (c && (c += " "), c += m, M.mode == 1 && (n += (n ? " " : "") + m)), this.startSpan(Math.max(a, r), c), M.opaque)
      return;
    let h = t.tree && t.tree.prop(J.mounted);
    if (h && h.overlay) {
      let w = t.node.enter(h.overlay[0].from + r, 1), z = this.highlighters.filter((v) => !v.scope || v.scope(h.tree.type)), H = t.firstChild();
      for (let v = 0, S = r; ; v++) {
        let O = v < h.overlay.length ? h.overlay[v] : null, K = O ? O.from + r : p, D = Math.max(a, S), A = Math.min(i, K);
        if (D < A && H)
          for (; t.from < A && (this.highlightRange(t, D, A, n, s), this.startSpan(Math.min(A, t.to), c), !(t.to >= K || !t.nextSibling())); )
            ;
        if (!O || K > i)
          break;
        S = O.to + r, S > a && (this.highlightRange(w.cursor(), Math.max(a, O.from + r), Math.min(i, S), "", z), this.startSpan(Math.min(i, S), c));
      }
      H && t.parent();
    } else if (t.firstChild()) {
      h && (n = "");
      do
        if (!(t.to <= a)) {
          if (t.from >= i)
            break;
          this.highlightRange(t, a, i, n, s), this.startSpan(Math.min(i, t.to), c);
        }
      while (t.nextSibling());
      t.parent();
    }
  }
}
function Z(o) {
  let t = o.type.prop(V);
  for (; t && t.context && !o.matchContext(t.context); )
    t = t.next;
  return t || null;
}
f(Z, "getStyleTags");
const e = d.define, I = e(), b = e(), $ = e(b), F = e(b), N = e(), T = e(N), j = e(N), y = e(), x = e(y), u = e(), k = e(), B = e(), R = e(B), C = e(), l = {
  /**
  A comment.
  */
  comment: I,
  /**
  A line [comment](#highlight.tags.comment).
  */
  lineComment: e(I),
  /**
  A block [comment](#highlight.tags.comment).
  */
  blockComment: e(I),
  /**
  A documentation [comment](#highlight.tags.comment).
  */
  docComment: e(I),
  /**
  Any kind of identifier.
  */
  name: b,
  /**
  The [name](#highlight.tags.name) of a variable.
  */
  variableName: e(b),
  /**
  A type [name](#highlight.tags.name).
  */
  typeName: $,
  /**
  A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
  */
  tagName: e($),
  /**
  A property or field [name](#highlight.tags.name).
  */
  propertyName: F,
  /**
  An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
  */
  attributeName: e(F),
  /**
  The [name](#highlight.tags.name) of a class.
  */
  className: e(b),
  /**
  A label [name](#highlight.tags.name).
  */
  labelName: e(b),
  /**
  A namespace [name](#highlight.tags.name).
  */
  namespace: e(b),
  /**
  The [name](#highlight.tags.name) of a macro.
  */
  macroName: e(b),
  /**
  A literal value.
  */
  literal: N,
  /**
  A string [literal](#highlight.tags.literal).
  */
  string: T,
  /**
  A documentation [string](#highlight.tags.string).
  */
  docString: e(T),
  /**
  A character literal (subtag of [string](#highlight.tags.string)).
  */
  character: e(T),
  /**
  An attribute value (subtag of [string](#highlight.tags.string)).
  */
  attributeValue: e(T),
  /**
  A number [literal](#highlight.tags.literal).
  */
  number: j,
  /**
  An integer [number](#highlight.tags.number) literal.
  */
  integer: e(j),
  /**
  A floating-point [number](#highlight.tags.number) literal.
  */
  float: e(j),
  /**
  A boolean [literal](#highlight.tags.literal).
  */
  bool: e(N),
  /**
  Regular expression [literal](#highlight.tags.literal).
  */
  regexp: e(N),
  /**
  An escape [literal](#highlight.tags.literal), for example a
  backslash escape in a string.
  */
  escape: e(N),
  /**
  A color [literal](#highlight.tags.literal).
  */
  color: e(N),
  /**
  A URL [literal](#highlight.tags.literal).
  */
  url: e(N),
  /**
  A language keyword.
  */
  keyword: u,
  /**
  The [keyword](#highlight.tags.keyword) for the self or this
  object.
  */
  self: e(u),
  /**
  The [keyword](#highlight.tags.keyword) for null.
  */
  null: e(u),
  /**
  A [keyword](#highlight.tags.keyword) denoting some atomic value.
  */
  atom: e(u),
  /**
  A [keyword](#highlight.tags.keyword) that represents a unit.
  */
  unit: e(u),
  /**
  A modifier [keyword](#highlight.tags.keyword).
  */
  modifier: e(u),
  /**
  A [keyword](#highlight.tags.keyword) that acts as an operator.
  */
  operatorKeyword: e(u),
  /**
  A control-flow related [keyword](#highlight.tags.keyword).
  */
  controlKeyword: e(u),
  /**
  A [keyword](#highlight.tags.keyword) that defines something.
  */
  definitionKeyword: e(u),
  /**
  A [keyword](#highlight.tags.keyword) related to defining or
  interfacing with modules.
  */
  moduleKeyword: e(u),
  /**
  An operator.
  */
  operator: k,
  /**
  An [operator](#highlight.tags.operator) that dereferences something.
  */
  derefOperator: e(k),
  /**
  Arithmetic-related [operator](#highlight.tags.operator).
  */
  arithmeticOperator: e(k),
  /**
  Logical [operator](#highlight.tags.operator).
  */
  logicOperator: e(k),
  /**
  Bit [operator](#highlight.tags.operator).
  */
  bitwiseOperator: e(k),
  /**
  Comparison [operator](#highlight.tags.operator).
  */
  compareOperator: e(k),
  /**
  [Operator](#highlight.tags.operator) that updates its operand.
  */
  updateOperator: e(k),
  /**
  [Operator](#highlight.tags.operator) that defines something.
  */
  definitionOperator: e(k),
  /**
  Type-related [operator](#highlight.tags.operator).
  */
  typeOperator: e(k),
  /**
  Control-flow [operator](#highlight.tags.operator).
  */
  controlOperator: e(k),
  /**
  Program or markup punctuation.
  */
  punctuation: B,
  /**
  [Punctuation](#highlight.tags.punctuation) that separates
  things.
  */
  separator: e(B),
  /**
  Bracket-style [punctuation](#highlight.tags.punctuation).
  */
  bracket: R,
  /**
  Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
  tokens).
  */
  angleBracket: e(R),
  /**
  Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
  tokens).
  */
  squareBracket: e(R),
  /**
  Parentheses (usually `(` and `)` tokens). Subtag of
  [bracket](#highlight.tags.bracket).
  */
  paren: e(R),
  /**
  Braces (usually `{` and `}` tokens). Subtag of
  [bracket](#highlight.tags.bracket).
  */
  brace: e(R),
  /**
  Content, for example plain text in XML or markup documents.
  */
  content: y,
  /**
  [Content](#highlight.tags.content) that represents a heading.
  */
  heading: x,
  /**
  A level 1 [heading](#highlight.tags.heading).
  */
  heading1: e(x),
  /**
  A level 2 [heading](#highlight.tags.heading).
  */
  heading2: e(x),
  /**
  A level 3 [heading](#highlight.tags.heading).
  */
  heading3: e(x),
  /**
  A level 4 [heading](#highlight.tags.heading).
  */
  heading4: e(x),
  /**
  A level 5 [heading](#highlight.tags.heading).
  */
  heading5: e(x),
  /**
  A level 6 [heading](#highlight.tags.heading).
  */
  heading6: e(x),
  /**
  A prose [content](#highlight.tags.content) separator (such as a horizontal rule).
  */
  contentSeparator: e(y),
  /**
  [Content](#highlight.tags.content) that represents a list.
  */
  list: e(y),
  /**
  [Content](#highlight.tags.content) that represents a quote.
  */
  quote: e(y),
  /**
  [Content](#highlight.tags.content) that is emphasized.
  */
  emphasis: e(y),
  /**
  [Content](#highlight.tags.content) that is styled strong.
  */
  strong: e(y),
  /**
  [Content](#highlight.tags.content) that is part of a link.
  */
  link: e(y),
  /**
  [Content](#highlight.tags.content) that is styled as code or
  monospace.
  */
  monospace: e(y),
  /**
  [Content](#highlight.tags.content) that has a strike-through
  style.
  */
  strikethrough: e(y),
  /**
  Inserted text in a change-tracking format.
  */
  inserted: e(),
  /**
  Deleted text.
  */
  deleted: e(),
  /**
  Changed text.
  */
  changed: e(),
  /**
  An invalid or unsyntactic element.
  */
  invalid: e(),
  /**
  Metadata or meta-instruction.
  */
  meta: C,
  /**
  [Metadata](#highlight.tags.meta) that applies to the entire
  document.
  */
  documentMeta: e(C),
  /**
  [Metadata](#highlight.tags.meta) that annotates or adds
  attributes to a given syntactic element.
  */
  annotation: e(C),
  /**
  Processing instruction or preprocessor directive. Subtag of
  [meta](#highlight.tags.meta).
  */
  processingInstruction: e(C),
  /**
  [Modifier](#highlight.Tag^defineModifier) that indicates that a
  given element is being defined. Expected to be used with the
  various [name](#highlight.tags.name) tags.
  */
  definition: d.defineModifier("definition"),
  /**
  [Modifier](#highlight.Tag^defineModifier) that indicates that
  something is constant. Mostly expected to be used with
  [variable names](#highlight.tags.variableName).
  */
  constant: d.defineModifier("constant"),
  /**
  [Modifier](#highlight.Tag^defineModifier) used to indicate that
  a [variable](#highlight.tags.variableName) or [property
  name](#highlight.tags.propertyName) is being called or defined
  as a function.
  */
  function: d.defineModifier("function"),
  /**
  [Modifier](#highlight.Tag^defineModifier) that can be applied to
  [names](#highlight.tags.name) to indicate that they belong to
  the language's standard environment.
  */
  standard: d.defineModifier("standard"),
  /**
  [Modifier](#highlight.Tag^defineModifier) that indicates a given
  [names](#highlight.tags.name) is local to some scope.
  */
  local: d.defineModifier("local"),
  /**
  A generic variant [modifier](#highlight.Tag^defineModifier) that
  can be used to tag language-specific alternative variants of
  some common tag. It is recommended for themes to define special
  forms of at least the [string](#highlight.tags.string) and
  [variable name](#highlight.tags.variableName) tags, since those
  come up a lot.
  */
  special: d.defineModifier("special")
};
for (let o in l) {
  let t = l[o];
  t instanceof d && (t.name = o);
}
W([
  { tag: l.link, class: "tok-link" },
  { tag: l.heading, class: "tok-heading" },
  { tag: l.emphasis, class: "tok-emphasis" },
  { tag: l.strong, class: "tok-strong" },
  { tag: l.keyword, class: "tok-keyword" },
  { tag: l.atom, class: "tok-atom" },
  { tag: l.bool, class: "tok-bool" },
  { tag: l.url, class: "tok-url" },
  { tag: l.labelName, class: "tok-labelName" },
  { tag: l.inserted, class: "tok-inserted" },
  { tag: l.deleted, class: "tok-deleted" },
  { tag: l.literal, class: "tok-literal" },
  { tag: l.string, class: "tok-string" },
  { tag: l.number, class: "tok-number" },
  { tag: [l.regexp, l.escape, l.special(l.string)], class: "tok-string2" },
  { tag: l.variableName, class: "tok-variableName" },
  { tag: l.local(l.variableName), class: "tok-variableName tok-local" },
  { tag: l.definition(l.variableName), class: "tok-variableName tok-definition" },
  { tag: l.special(l.variableName), class: "tok-variableName2" },
  { tag: l.definition(l.propertyName), class: "tok-propertyName tok-definition" },
  { tag: l.typeName, class: "tok-typeName" },
  { tag: l.namespace, class: "tok-namespace" },
  { tag: l.className, class: "tok-className" },
  { tag: l.macroName, class: "tok-macroName" },
  { tag: l.propertyName, class: "tok-propertyName" },
  { tag: l.operator, class: "tok-operator" },
  { tag: l.comment, class: "tok-comment" },
  { tag: l.meta, class: "tok-meta" },
  { tag: l.invalid, class: "tok-invalid" },
  { tag: l.punctuation, class: "tok-punctuation" }
]);
export {
  d as Tag,
  Z as getStyleTags,
  at as highlightTree,
  et as styleTags,
  W as tagHighlighter,
  l as tags
};
