var we = Object.defineProperty;
var _e = (n, t, e) => t in n ? we(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
var L = (n, t, e) => _e(n, typeof t != "symbol" ? t + "" : t, e);
import { ShikiError as _ } from "../../../../../@shikijs_types@3.21.0/node_modules/@shikijs/types/dist/index.js";
import { FontStyle as v, INITIAL as U, EncodedTokenMetadata as re, Registry as ke, Theme as ve } from "../../../../../@shikijs_vscode-textmate@10.0.2/node_modules/@shikijs/vscode-textmate/dist/index.js";
import { toHtml as Le } from "../../../../../hast-util-to-html@9.0.5/node_modules/hast-util-to-html/lib/index.js";
function D(n, t) {
  const e = typeof n == "string" ? {} : { ...n.colorReplacements }, s = typeof n == "string" ? n : n.name;
  for (const [r, o] of Object.entries((t == null ? void 0 : t.colorReplacements) || {}))
    typeof o == "string" ? e[r] = o : r === s && Object.assign(e, o);
  return e;
}
function E(n, t) {
  return n && ((t == null ? void 0 : t[n == null ? void 0 : n.toLowerCase()]) || n);
}
function Ce(n) {
  return Array.isArray(n) ? n : [n];
}
async function ue(n) {
  return Promise.resolve(typeof n == "function" ? n() : n).then((t) => t.default || t);
}
function Q(n) {
  return !n || ["plaintext", "txt", "text", "plain"].includes(n);
}
function he(n) {
  return n === "ansi" || Q(n);
}
function X(n) {
  return n === "none";
}
function ge(n) {
  return X(n);
}
function de(n, t) {
  var s;
  if (!t)
    return n;
  n.properties || (n.properties = {}), (s = n.properties).class || (s.class = []), typeof n.properties.class == "string" && (n.properties.class = n.properties.class.split(/\s+/g)), Array.isArray(n.properties.class) || (n.properties.class = []);
  const e = Array.isArray(t) ? t : t.split(/\s+/g);
  for (const r of e)
    r && !n.properties.class.includes(r) && n.properties.class.push(r);
  return n;
}
function V(n, t = !1) {
  var o;
  if (n.length === 0)
    return [["", 0]];
  const e = n.split(/(\r?\n)/g);
  let s = 0;
  const r = [];
  for (let a = 0; a < e.length; a += 2) {
    const i = t ? e[a] + (e[a + 1] || "") : e[a];
    r.push([i, s]), s += e[a].length, s += ((o = e[a + 1]) == null ? void 0 : o.length) || 0;
  }
  return r;
}
function xe(n) {
  const t = V(n, !0).map(([r]) => r);
  function e(r) {
    if (r === n.length)
      return {
        line: t.length - 1,
        character: t[t.length - 1].length
      };
    let o = r, a = 0;
    for (const i of t) {
      if (o < i.length)
        break;
      o -= i.length, a++;
    }
    return { line: a, character: o };
  }
  function s(r, o) {
    let a = 0;
    for (let i = 0; i < r; i++)
      a += t[i].length;
    return a += o, a;
  }
  return {
    lines: t,
    indexToPos: e,
    posToIndex: s
  };
}
const Z = "light-dark()", $e = ["color", "background-color"];
function Ne(n, t) {
  let e = 0;
  const s = [];
  for (const r of t)
    r > e && s.push({
      ...n,
      content: n.content.slice(e, r),
      offset: n.offset + e
    }), e = r;
  return e < n.content.length && s.push({
    ...n,
    content: n.content.slice(e),
    offset: n.offset + e
  }), s;
}
function Ie(n, t) {
  const e = Array.from(t instanceof Set ? t : new Set(t)).sort((s, r) => s - r);
  return e.length ? n.map((s) => s.flatMap((r) => {
    const o = e.filter((a) => r.offset < a && a < r.offset + r.content.length).map((a) => a - r.offset).sort((a, i) => a - i);
    return o.length ? Ne(r, o) : r;
  })) : n;
}
function Ee(n, t, e, s, r = "css-vars") {
  const o = {
    content: n.content,
    explanation: n.explanation,
    offset: n.offset
  }, a = t.map((h) => W(n.variants[h])), i = new Set(a.flatMap((h) => Object.keys(h))), c = {}, l = (h, f) => {
    const u = f === "color" ? "" : f === "background-color" ? "-bg" : `-${f}`;
    return e + t[h] + (f === "color" ? "" : u);
  };
  return a.forEach((h, f) => {
    for (const u of i) {
      const d = h[u] || "inherit";
      if (f === 0 && s && $e.includes(u))
        if (s === Z && a.length > 1) {
          const m = t.findIndex((b) => b === "light"), y = t.findIndex((b) => b === "dark");
          if (m === -1 || y === -1)
            throw new _('When using `defaultColor: "light-dark()"`, you must provide both `light` and `dark` themes');
          const T = a[m][u] || "inherit", p = a[y][u] || "inherit";
          c[u] = `light-dark(${T}, ${p})`, r === "css-vars" && (c[l(f, u)] = d);
        } else
          c[u] = d;
      else
        r === "css-vars" && (c[l(f, u)] = d);
    }
  }), o.htmlStyle = c, o;
}
function W(n) {
  const t = {};
  if (n.color && (t.color = n.color), n.bgColor && (t["background-color"] = n.bgColor), n.fontStyle) {
    n.fontStyle & v.Italic && (t["font-style"] = "italic"), n.fontStyle & v.Bold && (t["font-weight"] = "bold");
    const e = [];
    n.fontStyle & v.Underline && e.push("underline"), n.fontStyle & v.Strikethrough && e.push("line-through"), e.length && (t["text-decoration"] = e.join(" "));
  }
  return t;
}
function q(n) {
  return typeof n == "string" ? n : Object.entries(n).map(([t, e]) => `${t}:${e}`).join(";");
}
const me = /* @__PURE__ */ new WeakMap();
function J(n, t) {
  me.set(n, t);
}
function R(n) {
  return me.get(n);
}
class F {
  constructor(...t) {
    /**
     * Theme to Stack mapping
     */
    L(this, "_stacks", {});
    L(this, "lang");
    if (t.length === 2) {
      const [e, s] = t;
      this.lang = s, this._stacks = e;
    } else {
      const [e, s, r] = t;
      this.lang = s, this._stacks = { [r]: e };
    }
  }
  get themes() {
    return Object.keys(this._stacks);
  }
  get theme() {
    return this.themes[0];
  }
  get _stack() {
    return this._stacks[this.theme];
  }
  /**
   * Static method to create a initial grammar state.
   */
  static initial(t, e) {
    return new F(
      Object.fromEntries(Ce(e).map((s) => [s, U])),
      t
    );
  }
  /**
   * Get the internal stack object.
   * @internal
   */
  getInternalStack(t = this.theme) {
    return this._stacks[t];
  }
  getScopes(t = this.theme) {
    return Me(this._stacks[t]);
  }
  toJSON() {
    return {
      lang: this.lang,
      theme: this.theme,
      themes: this.themes,
      scopes: this.getScopes()
    };
  }
}
function Me(n) {
  const t = [], e = /* @__PURE__ */ new Set();
  function s(r) {
    var a;
    if (e.has(r))
      return;
    e.add(r);
    const o = (a = r == null ? void 0 : r.nameScopesList) == null ? void 0 : a.scopeName;
    o && t.push(o), r.parent && s(r.parent);
  }
  return s(n), t;
}
function Oe(n, t) {
  if (!(n instanceof F))
    throw new _("Invalid grammar state");
  return n.getInternalStack(t);
}
function Be() {
  const n = /* @__PURE__ */ new WeakMap();
  function t(e) {
    if (!n.has(e.meta)) {
      let s = function(a) {
        if (typeof a == "number") {
          if (a < 0 || a > e.source.length)
            throw new _(`Invalid decoration offset: ${a}. Code length: ${e.source.length}`);
          return {
            ...r.indexToPos(a),
            offset: a
          };
        } else {
          const i = r.lines[a.line];
          if (i === void 0)
            throw new _(`Invalid decoration position ${JSON.stringify(a)}. Lines length: ${r.lines.length}`);
          let c = a.character;
          if (c < 0 && (c = i.length + c), c < 0 || c > i.length)
            throw new _(`Invalid decoration position ${JSON.stringify(a)}. Line ${a.line} length: ${i.length}`);
          return {
            ...a,
            character: c,
            offset: r.posToIndex(a.line, c)
          };
        }
      };
      const r = xe(e.source), o = (e.options.decorations || []).map((a) => ({
        ...a,
        start: s(a.start),
        end: s(a.end)
      }));
      Ae(o), n.set(e.meta, {
        decorations: o,
        converter: r,
        source: e.source
      });
    }
    return n.get(e.meta);
  }
  return {
    name: "shiki:decorations",
    tokens(e) {
      var a;
      if (!((a = this.options.decorations) != null && a.length))
        return;
      const r = t(this).decorations.flatMap((i) => [i.start.offset, i.end.offset]);
      return Ie(e, r);
    },
    code(e) {
      var h;
      if (!((h = this.options.decorations) != null && h.length))
        return;
      const s = t(this), r = Array.from(e.children).filter((f) => f.type === "element" && f.tagName === "span");
      if (r.length !== s.converter.lines.length)
        throw new _(`Number of lines in code element (${r.length}) does not match the number of lines in the source (${s.converter.lines.length}). Failed to apply decorations.`);
      function o(f, u, d, m) {
        const y = r[f];
        let T = "", p = -1, b = -1;
        if (u === 0 && (p = 0), d === 0 && (b = 0), d === Number.POSITIVE_INFINITY && (b = y.children.length), p === -1 || b === -1)
          for (let S = 0; S < y.children.length; S++)
            T += pe(y.children[S]), p === -1 && T.length === u && (p = S + 1), b === -1 && T.length === d && (b = S + 1);
        if (p === -1)
          throw new _(`Failed to find start index for decoration ${JSON.stringify(m.start)}`);
        if (b === -1)
          throw new _(`Failed to find end index for decoration ${JSON.stringify(m.end)}`);
        const g = y.children.slice(p, b);
        if (!m.alwaysWrap && g.length === y.children.length)
          i(y, m, "line");
        else if (!m.alwaysWrap && g.length === 1 && g[0].type === "element")
          i(g[0], m, "token");
        else {
          const S = {
            type: "element",
            tagName: "span",
            properties: {},
            children: g
          };
          i(S, m, "wrapper"), y.children.splice(p, g.length, S);
        }
      }
      function a(f, u) {
        r[f] = i(r[f], u, "line");
      }
      function i(f, u, d) {
        var T;
        const m = u.properties || {}, y = u.transform || ((p) => p);
        return f.tagName = u.tagName || "span", f.properties = {
          ...f.properties,
          ...m,
          class: f.properties.class
        }, (T = u.properties) != null && T.class && de(f, u.properties.class), f = y(f, d) || f, f;
      }
      const c = [], l = s.decorations.sort((f, u) => u.start.offset - f.start.offset || f.end.offset - u.end.offset);
      for (const f of l) {
        const { start: u, end: d } = f;
        if (u.line === d.line)
          o(u.line, u.character, d.character, f);
        else if (u.line < d.line) {
          o(u.line, u.character, Number.POSITIVE_INFINITY, f);
          for (let m = u.line + 1; m < d.line; m++)
            c.unshift(() => a(m, f));
          o(d.line, 0, d.character, f);
        }
      }
      c.forEach((f) => f());
    }
  };
}
function Ae(n) {
  for (let t = 0; t < n.length; t++) {
    const e = n[t];
    if (e.start.offset > e.end.offset)
      throw new _(`Invalid decoration range: ${JSON.stringify(e.start)} - ${JSON.stringify(e.end)}`);
    for (let s = t + 1; s < n.length; s++) {
      const r = n[s], o = e.start.offset <= r.start.offset && r.start.offset < e.end.offset, a = e.start.offset < r.end.offset && r.end.offset <= e.end.offset, i = r.start.offset <= e.start.offset && e.start.offset < r.end.offset, c = r.start.offset < e.end.offset && e.end.offset <= r.end.offset;
      if (o || a || i || c) {
        if (o && a || i && c || i && e.start.offset === e.end.offset || a && r.start.offset === r.end.offset)
          continue;
        throw new _(`Decorations ${JSON.stringify(e.start)} and ${JSON.stringify(r.start)} intersect.`);
      }
    }
  }
}
function pe(n) {
  return n.type === "text" ? n.value : n.type === "element" ? n.children.map(pe).join("") : "";
}
const je = [
  /* @__PURE__ */ Be()
];
function P(n) {
  const t = Fe(n.transformers || []);
  return [
    ...t.pre,
    ...t.normal,
    ...t.post,
    ...je
  ];
}
function Fe(n) {
  const t = [], e = [], s = [];
  for (const r of n)
    switch (r.enforce) {
      case "pre":
        t.push(r);
        break;
      case "post":
        e.push(r);
        break;
      default:
        s.push(r);
    }
  return { pre: t, post: e, normal: s };
}
var M = [
  "black",
  "red",
  "green",
  "yellow",
  "blue",
  "magenta",
  "cyan",
  "white",
  "brightBlack",
  "brightRed",
  "brightGreen",
  "brightYellow",
  "brightBlue",
  "brightMagenta",
  "brightCyan",
  "brightWhite"
], K = {
  1: "bold",
  2: "dim",
  3: "italic",
  4: "underline",
  7: "reverse",
  8: "hidden",
  9: "strikethrough"
};
function Ge(n, t) {
  const e = n.indexOf("\x1B", t);
  if (e !== -1 && n[e + 1] === "[") {
    const s = n.indexOf("m", e);
    if (s !== -1)
      return {
        sequence: n.substring(e + 2, s).split(";"),
        startPosition: e,
        position: s + 1
      };
  }
  return {
    position: n.length
  };
}
function oe(n) {
  const t = n.shift();
  if (t === "2") {
    const e = n.splice(0, 3).map((s) => Number.parseInt(s));
    return e.length !== 3 || e.some((s) => Number.isNaN(s)) ? void 0 : {
      type: "rgb",
      rgb: e
    };
  } else if (t === "5") {
    const e = n.shift();
    if (e)
      return { type: "table", index: Number(e) };
  }
}
function Re(n) {
  const t = [];
  for (; n.length > 0; ) {
    const e = n.shift();
    if (!e)
      continue;
    const s = Number.parseInt(e);
    if (!Number.isNaN(s))
      if (s === 0)
        t.push({ type: "resetAll" });
      else if (s <= 9)
        K[s] && t.push({
          type: "setDecoration",
          value: K[s]
        });
      else if (s <= 29) {
        const r = K[s - 20];
        r && (t.push({
          type: "resetDecoration",
          value: r
        }), r === "dim" && t.push({
          type: "resetDecoration",
          value: "bold"
        }));
      } else if (s <= 37)
        t.push({
          type: "setForegroundColor",
          value: { type: "named", name: M[s - 30] }
        });
      else if (s === 38) {
        const r = oe(n);
        r && t.push({
          type: "setForegroundColor",
          value: r
        });
      } else if (s === 39)
        t.push({
          type: "resetForegroundColor"
        });
      else if (s <= 47)
        t.push({
          type: "setBackgroundColor",
          value: { type: "named", name: M[s - 40] }
        });
      else if (s === 48) {
        const r = oe(n);
        r && t.push({
          type: "setBackgroundColor",
          value: r
        });
      } else s === 49 ? t.push({
        type: "resetBackgroundColor"
      }) : s === 53 ? t.push({
        type: "setDecoration",
        value: "overline"
      }) : s === 55 ? t.push({
        type: "resetDecoration",
        value: "overline"
      }) : s >= 90 && s <= 97 ? t.push({
        type: "setForegroundColor",
        value: { type: "named", name: M[s - 90 + 8] }
      }) : s >= 100 && s <= 107 && t.push({
        type: "setBackgroundColor",
        value: { type: "named", name: M[s - 100 + 8] }
      });
  }
  return t;
}
function De() {
  let n = null, t = null, e = /* @__PURE__ */ new Set();
  return {
    parse(s) {
      const r = [];
      let o = 0;
      do {
        const a = Ge(s, o), i = a.sequence ? s.substring(o, a.startPosition) : s.substring(o);
        if (i.length > 0 && r.push({
          value: i,
          foreground: n,
          background: t,
          decorations: new Set(e)
        }), a.sequence) {
          const c = Re(a.sequence);
          for (const l of c)
            l.type === "resetAll" ? (n = null, t = null, e.clear()) : l.type === "resetForegroundColor" ? n = null : l.type === "resetBackgroundColor" ? t = null : l.type === "resetDecoration" && e.delete(l.value);
          for (const l of c)
            l.type === "setForegroundColor" ? n = l.value : l.type === "setBackgroundColor" ? t = l.value : l.type === "setDecoration" && e.add(l.value);
        }
        o = a.position;
      } while (o < s.length);
      return r;
    }
  };
}
var We = {
  black: "#000000",
  red: "#bb0000",
  green: "#00bb00",
  yellow: "#bbbb00",
  blue: "#0000bb",
  magenta: "#ff00ff",
  cyan: "#00bbbb",
  white: "#eeeeee",
  brightBlack: "#555555",
  brightRed: "#ff5555",
  brightGreen: "#00ff00",
  brightYellow: "#ffff55",
  brightBlue: "#5555ff",
  brightMagenta: "#ff55ff",
  brightCyan: "#55ffff",
  brightWhite: "#ffffff"
};
function Pe(n = We) {
  function t(i) {
    return n[i];
  }
  function e(i) {
    return `#${i.map((c) => Math.max(0, Math.min(c, 255)).toString(16).padStart(2, "0")).join("")}`;
  }
  let s;
  function r() {
    if (s)
      return s;
    s = [];
    for (let l = 0; l < M.length; l++)
      s.push(t(M[l]));
    let i = [0, 95, 135, 175, 215, 255];
    for (let l = 0; l < 6; l++)
      for (let h = 0; h < 6; h++)
        for (let f = 0; f < 6; f++)
          s.push(e([i[l], i[h], i[f]]));
    let c = 8;
    for (let l = 0; l < 24; l++, c += 10)
      s.push(e([c, c, c]));
    return s;
  }
  function o(i) {
    return r()[i];
  }
  function a(i) {
    switch (i.type) {
      case "named":
        return t(i.name);
      case "rgb":
        return e(i.rgb);
      case "table":
        return o(i.index);
    }
  }
  return {
    value: a
  };
}
const He = {
  black: "#000000",
  red: "#cd3131",
  green: "#0DBC79",
  yellow: "#E5E510",
  blue: "#2472C8",
  magenta: "#BC3FBC",
  cyan: "#11A8CD",
  white: "#E5E5E5",
  brightBlack: "#666666",
  brightRed: "#F14C4C",
  brightGreen: "#23D18B",
  brightYellow: "#F5F543",
  brightBlue: "#3B8EEA",
  brightMagenta: "#D670D6",
  brightCyan: "#29B8DB",
  brightWhite: "#FFFFFF"
};
function ze(n, t, e) {
  const s = D(n, e), r = V(t), o = Object.fromEntries(
    M.map((c) => {
      var f;
      const l = `terminal.ansi${c[0].toUpperCase()}${c.substring(1)}`, h = (f = n.colors) == null ? void 0 : f[l];
      return [c, h || He[c]];
    })
  ), a = Pe(o), i = De();
  return r.map(
    (c) => i.parse(c[0]).map((l) => {
      let h, f;
      l.decorations.has("reverse") ? (h = l.background ? a.value(l.background) : n.bg, f = l.foreground ? a.value(l.foreground) : n.fg) : (h = l.foreground ? a.value(l.foreground) : n.fg, f = l.background ? a.value(l.background) : void 0), h = E(h, s), f = E(f, s), l.decorations.has("dim") && (h = Ve(h));
      let u = v.None;
      return l.decorations.has("bold") && (u |= v.Bold), l.decorations.has("italic") && (u |= v.Italic), l.decorations.has("underline") && (u |= v.Underline), l.decorations.has("strikethrough") && (u |= v.Strikethrough), {
        content: l.value,
        offset: c[1],
        // TODO: more accurate offset? might need to fork ansi-sequence-parser
        color: h,
        bgColor: f,
        fontStyle: u
      };
    })
  );
}
function Ve(n) {
  const t = n.match(/#([0-9a-f]{3,8})/i);
  if (t) {
    const s = t[1];
    if (s.length === 8) {
      const r = Math.round(Number.parseInt(s.slice(6, 8), 16) / 2).toString(16).padStart(2, "0");
      return `#${s.slice(0, 6)}${r}`;
    } else {
      if (s.length === 6)
        return `#${s}80`;
      if (s.length === 4) {
        const r = s[0], o = s[1], a = s[2], i = s[3], c = Math.round(Number.parseInt(`${i}${i}`, 16) / 2).toString(16).padStart(2, "0");
        return `#${r}${r}${o}${o}${a}${a}${c}`;
      } else if (s.length === 3) {
        const r = s[0], o = s[1], a = s[2];
        return `#${r}${r}${o}${o}${a}${a}80`;
      }
    }
  }
  const e = n.match(/var\((--[\w-]+-ansi-[\w-]+)\)/);
  return e ? `var(${e[1]}-dim)` : n;
}
function ee(n, t, e = {}) {
  const {
    theme: s = n.getLoadedThemes()[0]
  } = e, r = n.resolveLangAlias(e.lang || "text");
  if (Q(r) || X(s))
    return V(t).map((c) => [{ content: c[0], offset: c[1] }]);
  const { theme: o, colorMap: a } = n.setTheme(s);
  if (r === "ansi")
    return ze(o, t, e);
  const i = n.getLanguage(e.lang || "text");
  if (e.grammarState) {
    if (e.grammarState.lang !== i.name)
      throw new _(`Grammar state language "${e.grammarState.lang}" does not match highlight language "${i.name}"`);
    if (!e.grammarState.themes.includes(o.name))
      throw new _(`Grammar state themes "${e.grammarState.themes}" do not contain highlight theme "${o.name}"`);
  }
  return Ye(t, i, o, a, e);
}
function Je(...n) {
  if (n.length === 2)
    return R(n[1]);
  const [t, e, s = {}] = n, {
    lang: r = "text",
    theme: o = t.getLoadedThemes()[0]
  } = s;
  if (Q(r) || X(o))
    throw new _("Plain language does not have grammar state");
  if (r === "ansi")
    throw new _("ANSI language does not have grammar state");
  const { theme: a, colorMap: i } = t.setTheme(o), c = t.getLanguage(r);
  return new F(
    te(e, c, a, i, s).stateStack,
    c.name,
    a.name
  );
}
function Ye(n, t, e, s, r) {
  const o = te(n, t, e, s, r), a = new F(
    o.stateStack,
    t.name,
    e.name
  );
  return J(o.tokens, a), o.tokens;
}
function te(n, t, e, s, r) {
  const o = D(e, r), {
    tokenizeMaxLineLength: a = 0,
    tokenizeTimeLimit: i = 500
  } = r, c = V(n);
  let l = r.grammarState ? Oe(r.grammarState, e.name) ?? U : r.grammarContextCode != null ? te(
    r.grammarContextCode,
    t,
    e,
    s,
    {
      ...r,
      grammarState: void 0,
      grammarContextCode: void 0
    }
  ).stateStack : U, h = [];
  const f = [];
  for (let u = 0, d = c.length; u < d; u++) {
    const [m, y] = c[u];
    if (m === "") {
      h = [], f.push([]);
      continue;
    }
    if (a > 0 && m.length >= a) {
      h = [], f.push([{
        content: m,
        offset: y,
        color: "",
        fontStyle: 0
      }]);
      continue;
    }
    let T, p, b;
    r.includeExplanation && (T = t.tokenizeLine(m, l, i), p = T.tokens, b = 0);
    const g = t.tokenizeLine2(m, l, i), S = g.tokens.length / 2;
    for (let k = 0; k < S; k++) {
      const C = g.tokens[2 * k], w = k + 1 < S ? g.tokens[2 * k + 2] : m.length;
      if (C === w)
        continue;
      const N = g.tokens[2 * k + 1], x = E(
        s[re.getForeground(N)],
        o
      ), I = re.getFontStyle(N), O = {
        content: m.substring(C, w),
        offset: y + C,
        color: x,
        fontStyle: I
      };
      if (r.includeExplanation) {
        const B = [];
        if (r.includeExplanation !== "scopeName")
          for (const $ of e.settings) {
            let A;
            switch (typeof $.scope) {
              case "string":
                A = $.scope.split(/,/).map((Y) => Y.trim());
                break;
              case "object":
                A = $.scope;
                break;
              default:
                continue;
            }
            B.push({
              settings: $,
              selectors: A.map((Y) => Y.split(/ /))
            });
          }
        O.explanation = [];
        let se = 0;
        for (; C + se < w; ) {
          const $ = p[b], A = m.substring(
            $.startIndex,
            $.endIndex
          );
          se += A.length, O.explanation.push({
            content: A,
            scopes: r.includeExplanation === "scopeName" ? Ke(
              $.scopes
            ) : Ue(
              B,
              $.scopes
            )
          }), b += 1;
        }
      }
      h.push(O);
    }
    f.push(h), h = [], l = g.ruleStack;
  }
  return {
    tokens: f,
    stateStack: l
  };
}
function Ke(n) {
  return n.map((t) => ({ scopeName: t }));
}
function Ue(n, t) {
  const e = [];
  for (let s = 0, r = t.length; s < r; s++) {
    const o = t[s];
    e[s] = {
      scopeName: o,
      themeMatches: Qe(n, o, t.slice(0, s))
    };
  }
  return e;
}
function ae(n, t) {
  return n === t || t.substring(0, n.length) === n && t[n.length] === ".";
}
function qe(n, t, e) {
  if (!ae(n[n.length - 1], t))
    return !1;
  let s = n.length - 2, r = e.length - 1;
  for (; s >= 0 && r >= 0; )
    ae(n[s], e[r]) && (s -= 1), r -= 1;
  return s === -1;
}
function Qe(n, t, e) {
  const s = [];
  for (const { selectors: r, settings: o } of n)
    for (const a of r)
      if (qe(a, t, e)) {
        s.push(o);
        break;
      }
  return s;
}
function ye(n, t, e) {
  const s = Object.entries(e.themes).filter((c) => c[1]).map((c) => ({ color: c[0], theme: c[1] })), r = s.map((c) => {
    const l = ee(n, t, {
      ...e,
      theme: c.theme
    }), h = R(l), f = typeof c.theme == "string" ? c.theme : c.theme.name;
    return {
      tokens: l,
      state: h,
      theme: f
    };
  }), o = Xe(
    ...r.map((c) => c.tokens)
  ), a = o[0].map(
    (c, l) => c.map((h, f) => {
      const u = {
        content: h.content,
        variants: {},
        offset: h.offset
      };
      return "includeExplanation" in e && e.includeExplanation && (u.explanation = h.explanation), o.forEach((d, m) => {
        const {
          content: y,
          explanation: T,
          offset: p,
          ...b
        } = d[l][f];
        u.variants[s[m].color] = b;
      }), u;
    })
  ), i = r[0].state ? new F(
    Object.fromEntries(r.map((c) => {
      var l;
      return [c.theme, (l = c.state) == null ? void 0 : l.getInternalStack(c.theme)];
    })),
    r[0].state.lang
  ) : void 0;
  return i && J(a, i), a;
}
function Xe(...n) {
  const t = n.map(() => []), e = n.length;
  for (let s = 0; s < n[0].length; s++) {
    const r = n.map((c) => c[s]), o = t.map(() => []);
    t.forEach((c, l) => c.push(o[l]));
    const a = r.map(() => 0), i = r.map((c) => c[0]);
    for (; i.every((c) => c); ) {
      const c = Math.min(...i.map((l) => l.content.length));
      for (let l = 0; l < e; l++) {
        const h = i[l];
        h.content.length === c ? (o[l].push(h), a[l] += 1, i[l] = r[l][a[l]]) : (o[l].push({
          ...h,
          content: h.content.slice(0, c)
        }), i[l] = {
          ...h,
          content: h.content.slice(c),
          offset: h.offset + c
        });
      }
    }
  }
  return t;
}
function H(n, t, e) {
  let s, r, o, a, i, c;
  if ("themes" in e) {
    const {
      defaultColor: l = "light",
      cssVariablePrefix: h = "--shiki-",
      colorsRendering: f = "css-vars"
    } = e, u = Object.entries(e.themes).filter((p) => p[1]).map((p) => ({ color: p[0], theme: p[1] })).sort((p, b) => p.color === l ? -1 : b.color === l ? 1 : 0);
    if (u.length === 0)
      throw new _("`themes` option must not be empty");
    const d = ye(
      n,
      t,
      e
    );
    if (c = R(d), l && Z !== l && !u.find((p) => p.color === l))
      throw new _(`\`themes\` option must contain the defaultColor key \`${l}\``);
    const m = u.map((p) => n.getTheme(p.theme)), y = u.map((p) => p.color);
    o = d.map((p) => p.map((b) => Ee(b, y, h, l, f))), c && J(o, c);
    const T = u.map((p) => D(p.theme, e));
    r = ie(u, m, T, h, l, "fg", f), s = ie(u, m, T, h, l, "bg", f), a = `shiki-themes ${m.map((p) => p.name).join(" ")}`, i = l ? void 0 : [r, s].join(";");
  } else if ("theme" in e) {
    const l = D(e.theme, e);
    o = ee(
      n,
      t,
      e
    );
    const h = n.getTheme(e.theme);
    s = E(h.bg, l), r = E(h.fg, l), a = h.name, c = R(o);
  } else
    throw new _("Invalid options, either `theme` or `themes` must be provided");
  return {
    tokens: o,
    fg: r,
    bg: s,
    themeName: a,
    rootStyle: i,
    grammarState: c
  };
}
function ie(n, t, e, s, r, o, a) {
  return n.map((i, c) => {
    const l = E(t[c][o], e[c]) || "inherit", h = `${s + i.color}${o === "bg" ? "-bg" : ""}:${l}`;
    if (c === 0 && r) {
      if (r === Z && n.length > 1) {
        const f = n.findIndex((y) => y.color === "light"), u = n.findIndex((y) => y.color === "dark");
        if (f === -1 || u === -1)
          throw new _('When using `defaultColor: "light-dark()"`, you must provide both `light` and `dark` themes');
        const d = E(t[f][o], e[f]) || "inherit", m = E(t[u][o], e[u]) || "inherit";
        return `light-dark(${d}, ${m});${h}`;
      }
      return l;
    }
    return a === "css-vars" ? h : null;
  }).filter((i) => !!i).join(";");
}
function z(n, t, e, s = {
  meta: {},
  options: e,
  codeToHast: (r, o) => z(n, r, o),
  codeToTokens: (r, o) => H(n, r, o)
}) {
  var m, y;
  let r = t;
  for (const T of P(e))
    r = ((m = T.preprocess) == null ? void 0 : m.call(s, r, e)) || r;
  let {
    tokens: o,
    fg: a,
    bg: i,
    themeName: c,
    rootStyle: l,
    grammarState: h
  } = H(n, r, e);
  const {
    mergeWhitespaces: f = !0,
    mergeSameStyleTokens: u = !1
  } = e;
  f === !0 ? o = et(o) : f === "never" && (o = tt(o)), u && (o = nt(o));
  const d = {
    ...s,
    get source() {
      return r;
    }
  };
  for (const T of P(e))
    o = ((y = T.tokens) == null ? void 0 : y.call(d, o)) || o;
  return Ze(
    o,
    {
      ...e,
      fg: a,
      bg: i,
      themeName: c,
      rootStyle: e.rootStyle === !1 ? !1 : e.rootStyle ?? l
    },
    d,
    h
  );
}
function Ze(n, t, e, s = R(n)) {
  var y, T, p, b;
  const r = P(t), o = [], a = {
    type: "root",
    children: []
  }, {
    structure: i = "classic",
    tabindex: c = "0"
  } = t, l = {
    class: `shiki ${t.themeName || ""}`
  };
  t.rootStyle !== !1 && (t.rootStyle != null ? l.style = t.rootStyle : l.style = `background-color:${t.bg};color:${t.fg}`), c !== !1 && c != null && (l.tabindex = c.toString());
  for (const [g, S] of Object.entries(t.meta || {}))
    g.startsWith("_") || (l[g] = S);
  let h = {
    type: "element",
    tagName: "pre",
    properties: l,
    children: [],
    data: t.data
  }, f = {
    type: "element",
    tagName: "code",
    properties: {},
    children: o
  };
  const u = [], d = {
    ...e,
    structure: i,
    addClassToHast: de,
    get source() {
      return e.source;
    },
    get tokens() {
      return n;
    },
    get options() {
      return t;
    },
    get root() {
      return a;
    },
    get pre() {
      return h;
    },
    get code() {
      return f;
    },
    get lines() {
      return u;
    }
  };
  if (n.forEach((g, S) => {
    var w, N;
    S && (i === "inline" ? a.children.push({ type: "element", tagName: "br", properties: {}, children: [] }) : i === "classic" && o.push({ type: "text", value: `
` }));
    let k = {
      type: "element",
      tagName: "span",
      properties: { class: "line" },
      children: []
    }, C = 0;
    for (const x of g) {
      let I = {
        type: "element",
        tagName: "span",
        properties: {
          ...x.htmlAttrs
        },
        children: [{ type: "text", value: x.content }]
      };
      const O = q(x.htmlStyle || W(x));
      O && (I.properties.style = O);
      for (const B of r)
        I = ((w = B == null ? void 0 : B.span) == null ? void 0 : w.call(d, I, S + 1, C, k, x)) || I;
      i === "inline" ? a.children.push(I) : i === "classic" && k.children.push(I), C += x.content.length;
    }
    if (i === "classic") {
      for (const x of r)
        k = ((N = x == null ? void 0 : x.line) == null ? void 0 : N.call(d, k, S + 1)) || k;
      u.push(k), o.push(k);
    } else i === "inline" && u.push(k);
  }), i === "classic") {
    for (const g of r)
      f = ((y = g == null ? void 0 : g.code) == null ? void 0 : y.call(d, f)) || f;
    h.children.push(f);
    for (const g of r)
      h = ((T = g == null ? void 0 : g.pre) == null ? void 0 : T.call(d, h)) || h;
    a.children.push(h);
  } else if (i === "inline") {
    const g = [];
    let S = {
      type: "element",
      tagName: "span",
      properties: { class: "line" },
      children: []
    };
    for (const w of a.children)
      w.type === "element" && w.tagName === "br" ? (g.push(S), S = {
        type: "element",
        tagName: "span",
        properties: { class: "line" },
        children: []
      }) : (w.type === "element" || w.type === "text") && S.children.push(w);
    g.push(S);
    let C = {
      type: "element",
      tagName: "code",
      properties: {},
      children: g
    };
    for (const w of r)
      C = ((p = w == null ? void 0 : w.code) == null ? void 0 : p.call(d, C)) || C;
    a.children = [];
    for (let w = 0; w < C.children.length; w++) {
      w > 0 && a.children.push({ type: "element", tagName: "br", properties: {}, children: [] });
      const N = C.children[w];
      N.type === "element" && a.children.push(...N.children);
    }
  }
  let m = a;
  for (const g of r)
    m = ((b = g == null ? void 0 : g.root) == null ? void 0 : b.call(d, m)) || m;
  return s && J(m, s), m;
}
function et(n) {
  return n.map((t) => {
    const e = [];
    let s = "", r;
    return t.forEach((o, a) => {
      const c = !(o.fontStyle && (o.fontStyle & v.Underline || o.fontStyle & v.Strikethrough));
      c && o.content.match(/^\s+$/) && t[a + 1] ? (r === void 0 && (r = o.offset), s += o.content) : s ? (c ? e.push({
        ...o,
        offset: r,
        content: s + o.content
      }) : e.push(
        {
          content: s,
          offset: r
        },
        o
      ), r = void 0, s = "") : e.push(o);
    }), e;
  });
}
function tt(n) {
  return n.map((t) => t.flatMap((e) => {
    if (e.content.match(/^\s+$/))
      return e;
    const s = e.content.match(/^(\s*)(.*?)(\s*)$/);
    if (!s)
      return e;
    const [, r, o, a] = s;
    if (!r && !a)
      return e;
    const i = [{
      ...e,
      offset: e.offset + r.length,
      content: o
    }];
    return r && i.unshift({
      content: r,
      offset: e.offset
    }), a && i.push({
      content: a,
      offset: e.offset + r.length + o.length
    }), i;
  }));
}
function nt(n) {
  return n.map((t) => {
    const e = [];
    for (const s of t) {
      if (e.length === 0) {
        e.push({ ...s });
        continue;
      }
      const r = e[e.length - 1], o = q(r.htmlStyle || W(r)), a = q(s.htmlStyle || W(s)), i = r.fontStyle && (r.fontStyle & v.Underline || r.fontStyle & v.Strikethrough), c = s.fontStyle && (s.fontStyle & v.Underline || s.fontStyle & v.Strikethrough);
      !i && !c && o === a ? r.content += s.content : e.push({ ...s });
    }
    return e;
  });
}
const st = Le;
function rt(n, t, e) {
  var o;
  const s = {
    meta: {},
    options: e,
    codeToHast: (a, i) => z(n, a, i),
    codeToTokens: (a, i) => H(n, a, i)
  };
  let r = st(z(n, t, e, s));
  for (const a of P(e))
    r = ((o = a.postprocess) == null ? void 0 : o.call(s, r, e)) || r;
  return r;
}
const ce = { light: "#333333", dark: "#bbbbbb" }, le = { light: "#fffffe", dark: "#1e1e1e" }, fe = "__shiki_resolved";
function ne(n) {
  var i, c, l, h, f;
  if (n != null && n[fe])
    return n;
  const t = {
    ...n
  };
  t.tokenColors && !t.settings && (t.settings = t.tokenColors, delete t.tokenColors), t.type || (t.type = "dark"), t.colorReplacements = { ...t.colorReplacements }, t.settings || (t.settings = []);
  let { bg: e, fg: s } = t;
  if (!e || !s) {
    const u = t.settings ? t.settings.find((d) => !d.name && !d.scope) : void 0;
    (i = u == null ? void 0 : u.settings) != null && i.foreground && (s = u.settings.foreground), (c = u == null ? void 0 : u.settings) != null && c.background && (e = u.settings.background), !s && ((l = t == null ? void 0 : t.colors) != null && l["editor.foreground"]) && (s = t.colors["editor.foreground"]), !e && ((h = t == null ? void 0 : t.colors) != null && h["editor.background"]) && (e = t.colors["editor.background"]), s || (s = t.type === "light" ? ce.light : ce.dark), e || (e = t.type === "light" ? le.light : le.dark), t.fg = s, t.bg = e;
  }
  t.settings[0] && t.settings[0].settings && !t.settings[0].scope || t.settings.unshift({
    settings: {
      foreground: t.fg,
      background: t.bg
    }
  });
  let r = 0;
  const o = /* @__PURE__ */ new Map();
  function a(u) {
    var m;
    if (o.has(u))
      return o.get(u);
    r += 1;
    const d = `#${r.toString(16).padStart(8, "0").toLowerCase()}`;
    return (m = t.colorReplacements) != null && m[`#${d}`] ? a(u) : (o.set(u, d), d);
  }
  t.settings = t.settings.map((u) => {
    var T, p;
    const d = ((T = u.settings) == null ? void 0 : T.foreground) && !u.settings.foreground.startsWith("#"), m = ((p = u.settings) == null ? void 0 : p.background) && !u.settings.background.startsWith("#");
    if (!d && !m)
      return u;
    const y = {
      ...u,
      settings: {
        ...u.settings
      }
    };
    if (d) {
      const b = a(u.settings.foreground);
      t.colorReplacements[b] = u.settings.foreground, y.settings.foreground = b;
    }
    if (m) {
      const b = a(u.settings.background);
      t.colorReplacements[b] = u.settings.background, y.settings.background = b;
    }
    return y;
  });
  for (const u of Object.keys(t.colors || {}))
    if ((u === "editor.foreground" || u === "editor.background" || u.startsWith("terminal.ansi")) && !((f = t.colors[u]) != null && f.startsWith("#"))) {
      const d = a(t.colors[u]);
      t.colorReplacements[d] = t.colors[u], t.colors[u] = d;
    }
  return Object.defineProperty(t, fe, {
    enumerable: !1,
    writable: !1,
    value: !0
  }), t;
}
async function be(n) {
  return Array.from(new Set((await Promise.all(
    n.filter((t) => !he(t)).map(async (t) => await ue(t).then((e) => Array.isArray(e) ? e : [e]))
  )).flat()));
}
async function Se(n) {
  return (await Promise.all(
    n.map(
      async (e) => ge(e) ? null : ne(await ue(e))
    )
  )).filter((e) => !!e);
}
let ot = 3;
function at(n, t = 3) {
  t > ot || console.trace(`[SHIKI DEPRECATE]: ${n}`);
}
class j extends Error {
  constructor(t) {
    super(t), this.name = "ShikiError";
  }
}
function Te(n, t) {
  if (!t)
    return n;
  if (t[n]) {
    const e = /* @__PURE__ */ new Set([n]);
    for (; t[n]; ) {
      if (n = t[n], e.has(n))
        throw new j(`Circular alias \`${Array.from(e).join(" -> ")} -> ${n}\``);
      e.add(n);
    }
  }
  return n;
}
class it extends ke {
  constructor(e, s, r, o = {}) {
    super(e);
    L(this, "_resolvedThemes", /* @__PURE__ */ new Map());
    L(this, "_resolvedGrammars", /* @__PURE__ */ new Map());
    L(this, "_langMap", /* @__PURE__ */ new Map());
    L(this, "_langGraph", /* @__PURE__ */ new Map());
    L(this, "_textmateThemeCache", /* @__PURE__ */ new WeakMap());
    L(this, "_loadedThemesCache", null);
    L(this, "_loadedLanguagesCache", null);
    this._resolver = e, this._themes = s, this._langs = r, this._alias = o, this._themes.map((a) => this.loadTheme(a)), this.loadLanguages(this._langs);
  }
  getTheme(e) {
    return typeof e == "string" ? this._resolvedThemes.get(e) : this.loadTheme(e);
  }
  loadTheme(e) {
    const s = ne(e);
    return s.name && (this._resolvedThemes.set(s.name, s), this._loadedThemesCache = null), s;
  }
  getLoadedThemes() {
    return this._loadedThemesCache || (this._loadedThemesCache = [...this._resolvedThemes.keys()]), this._loadedThemesCache;
  }
  // Override and re-implement this method to cache the textmate themes as `TextMateTheme.createFromRawTheme`
  // is expensive. Themes can switch often especially for dual-theme support.
  //
  // The parent class also accepts `colorMap` as the second parameter, but since we don't use that,
  // we omit here so it's easier to cache the themes.
  setTheme(e) {
    let s = this._textmateThemeCache.get(e);
    s || (s = ve.createFromRawTheme(e), this._textmateThemeCache.set(e, s)), this._syncRegistry.setTheme(s);
  }
  getGrammar(e) {
    return e = Te(e, this._alias), this._resolvedGrammars.get(e);
  }
  loadLanguage(e) {
    var a, i, c, l;
    if (this.getGrammar(e.name))
      return;
    const s = new Set(
      [...this._langMap.values()].filter((h) => {
        var f;
        return (f = h.embeddedLangsLazy) == null ? void 0 : f.includes(e.name);
      })
    );
    this._resolver.addLanguage(e);
    const r = {
      balancedBracketSelectors: e.balancedBracketSelectors || ["*"],
      unbalancedBracketSelectors: e.unbalancedBracketSelectors || []
    };
    this._syncRegistry._rawGrammars.set(e.scopeName, e);
    const o = this.loadGrammarWithConfiguration(e.scopeName, 1, r);
    if (o.name = e.name, this._resolvedGrammars.set(e.name, o), e.aliases && e.aliases.forEach((h) => {
      this._alias[h] = e.name;
    }), this._loadedLanguagesCache = null, s.size)
      for (const h of s)
        this._resolvedGrammars.delete(h.name), this._loadedLanguagesCache = null, (i = (a = this._syncRegistry) == null ? void 0 : a._injectionGrammars) == null || i.delete(h.scopeName), (l = (c = this._syncRegistry) == null ? void 0 : c._grammars) == null || l.delete(h.scopeName), this.loadLanguage(this._langMap.get(h.name));
  }
  dispose() {
    super.dispose(), this._resolvedThemes.clear(), this._resolvedGrammars.clear(), this._langMap.clear(), this._langGraph.clear(), this._loadedThemesCache = null;
  }
  loadLanguages(e) {
    for (const o of e)
      this.resolveEmbeddedLanguages(o);
    const s = Array.from(this._langGraph.entries()), r = s.filter(([o, a]) => !a);
    if (r.length) {
      const o = s.filter(([a, i]) => {
        if (!i)
          return !1;
        const c = i.embeddedLanguages || i.embeddedLangs;
        return c == null ? void 0 : c.some((l) => r.map(([h]) => h).includes(l));
      }).filter((a) => !r.includes(a));
      throw new j(`Missing languages ${r.map(([a]) => `\`${a}\``).join(", ")}, required by ${o.map(([a]) => `\`${a}\``).join(", ")}`);
    }
    for (const [o, a] of s)
      this._resolver.addLanguage(a);
    for (const [o, a] of s)
      this.loadLanguage(a);
  }
  getLoadedLanguages() {
    return this._loadedLanguagesCache || (this._loadedLanguagesCache = [
      .../* @__PURE__ */ new Set([...this._resolvedGrammars.keys(), ...Object.keys(this._alias)])
    ]), this._loadedLanguagesCache;
  }
  resolveEmbeddedLanguages(e) {
    this._langMap.set(e.name, e), this._langGraph.set(e.name, e);
    const s = e.embeddedLanguages ?? e.embeddedLangs;
    if (s)
      for (const r of s)
        this._langGraph.set(r, this._langMap.get(r));
  }
}
class ct {
  constructor(t, e) {
    L(this, "_langs", /* @__PURE__ */ new Map());
    L(this, "_scopeToLang", /* @__PURE__ */ new Map());
    L(this, "_injections", /* @__PURE__ */ new Map());
    L(this, "_onigLib");
    this._onigLib = {
      createOnigScanner: (s) => t.createScanner(s),
      createOnigString: (s) => t.createString(s)
    }, e.forEach((s) => this.addLanguage(s));
  }
  get onigLib() {
    return this._onigLib;
  }
  getLangRegistration(t) {
    return this._langs.get(t);
  }
  loadGrammar(t) {
    return this._scopeToLang.get(t);
  }
  addLanguage(t) {
    this._langs.set(t.name, t), t.aliases && t.aliases.forEach((e) => {
      this._langs.set(e, t);
    }), this._scopeToLang.set(t.scopeName, t), t.injectTo && t.injectTo.forEach((e) => {
      this._injections.get(e) || this._injections.set(e, []), this._injections.get(e).push(t.scopeName);
    });
  }
  getInjections(t) {
    const e = t.split(".");
    let s = [];
    for (let r = 1; r <= e.length; r++) {
      const o = e.slice(0, r).join(".");
      s = [...s, ...this._injections.get(o) || []];
    }
    return s;
  }
}
let G = 0;
function lt(n) {
  G += 1, n.warnings !== !1 && G >= 10 && G % 10 === 0 && console.warn(`[Shiki] ${G} instances have been created. Shiki is supposed to be used as a singleton, consider refactoring your code to cache your highlighter instance; Or call \`highlighter.dispose()\` to release unused instances.`);
  let t = !1;
  if (!n.engine)
    throw new j("`engine` option is required for synchronous mode");
  const e = (n.langs || []).flat(1), s = (n.themes || []).flat(1).map(ne), r = new ct(n.engine, e), o = new it(r, s, e, n.langAlias);
  let a;
  function i(g) {
    return Te(g, n.langAlias);
  }
  function c(g) {
    p();
    const S = o.getGrammar(typeof g == "string" ? g : g.name);
    if (!S)
      throw new j(`Language \`${g}\` not found, you may need to load it first`);
    return S;
  }
  function l(g) {
    if (g === "none")
      return { bg: "", fg: "", name: "none", settings: [], type: "dark" };
    p();
    const S = o.getTheme(g);
    if (!S)
      throw new j(`Theme \`${g}\` not found, you may need to load it first`);
    return S;
  }
  function h(g) {
    p();
    const S = l(g);
    a !== g && (o.setTheme(S), a = g);
    const k = o.getColorMap();
    return {
      theme: S,
      colorMap: k
    };
  }
  function f() {
    return p(), o.getLoadedThemes();
  }
  function u() {
    return p(), o.getLoadedLanguages();
  }
  function d(...g) {
    p(), o.loadLanguages(g.flat(1));
  }
  async function m(...g) {
    return d(await be(g));
  }
  function y(...g) {
    p();
    for (const S of g.flat(1))
      o.loadTheme(S);
  }
  async function T(...g) {
    return p(), y(await Se(g));
  }
  function p() {
    if (t)
      throw new j("Shiki instance has been disposed");
  }
  function b() {
    t || (t = !0, o.dispose(), G -= 1);
  }
  return {
    setTheme: h,
    getTheme: l,
    getLanguage: c,
    getLoadedThemes: f,
    getLoadedLanguages: u,
    resolveLangAlias: i,
    loadLanguage: m,
    loadLanguageSync: d,
    loadTheme: T,
    loadThemeSync: y,
    dispose: b,
    [Symbol.dispose]: b
  };
}
async function ft(n) {
  n.engine || at("`engine` option is required. Use `createOnigurumaEngine` or `createJavaScriptRegexEngine` to create an engine.");
  const [
    t,
    e,
    s
  ] = await Promise.all([
    Se(n.themes || []),
    be(n.langs || []),
    n.engine
  ]);
  return lt({
    ...n,
    themes: t,
    langs: e,
    engine: s
  });
}
async function ut(n) {
  const t = await ft(n);
  return {
    getLastGrammarState: (...e) => Je(t, ...e),
    codeToTokensBase: (e, s) => ee(t, e, s),
    codeToTokensWithThemes: (e, s) => ye(t, e, s),
    codeToTokens: (e, s) => H(t, e, s),
    codeToHast: (e, s) => z(t, e, s),
    codeToHtml: (e, s) => rt(t, e, s),
    getBundledLanguages: () => ({}),
    getBundledThemes: () => ({}),
    ...t,
    getInternalContext: () => t
  };
}
function pt(n) {
  const t = n.langs, e = n.themes, s = n.engine;
  async function r(o) {
    function a(f) {
      var u;
      if (typeof f == "string") {
        if (f = ((u = o.langAlias) == null ? void 0 : u[f]) || f, he(f))
          return [];
        const d = t[f];
        if (!d)
          throw new _(`Language \`${f}\` is not included in this bundle. You may want to load it from external source.`);
        return d;
      }
      return f;
    }
    function i(f) {
      if (ge(f))
        return "none";
      if (typeof f == "string") {
        const u = e[f];
        if (!u)
          throw new _(`Theme \`${f}\` is not included in this bundle. You may want to load it from external source.`);
        return u;
      }
      return f;
    }
    const c = (o.themes ?? []).map((f) => i(f)), l = (o.langs ?? []).map((f) => a(f)), h = await ut({
      engine: o.engine ?? s(),
      ...o,
      themes: c,
      langs: l
    });
    return {
      ...h,
      loadLanguage(...f) {
        return h.loadLanguage(...f.map(a));
      },
      loadTheme(...f) {
        return h.loadTheme(...f.map(i));
      },
      getBundledLanguages() {
        return t;
      },
      getBundledThemes() {
        return e;
      }
    };
  }
  return r;
}
export {
  _ as ShikiError,
  de as addClassToHast,
  E as applyColorReplacements,
  z as codeToHast,
  rt as codeToHtml,
  H as codeToTokens,
  ee as codeToTokensBase,
  ye as codeToTokensWithThemes,
  pt as createBundledHighlighter,
  ut as createHighlighterCore,
  xe as createPositionConverter,
  ft as createShikiInternal,
  lt as createShikiInternalSync,
  Ee as flatTokenVariants,
  W as getTokenStyleObject,
  st as hastToHtml,
  X as isNoneTheme,
  Q as isPlainLang,
  he as isSpecialLang,
  ge as isSpecialTheme,
  ue as normalizeGetter,
  ne as normalizeTheme,
  D as resolveColorReplacements,
  V as splitLines,
  Ne as splitToken,
  Ie as splitTokens,
  q as stringifyTokenStyle,
  Ce as toArray,
  ze as tokenizeAnsiWithTheme,
  Ye as tokenizeWithTheme,
  Ze as tokensToHast,
  Be as transformerDecorations,
  at as warnDeprecated
};
