var Dr = Object.defineProperty;
var Tr = Object.getPrototypeOf;
var Br = Reflect.get;
var jr = (e, r, t) => r in e ? Dr(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
var ye = (e, r, t) => (jr(e, typeof r != "symbol" ? r + "" : r, t), t), Ce = (e, r, t) => {
  if (!r.has(e))
    throw TypeError("Cannot " + t);
};
var $ = (e, r, t) => (Ce(e, r, "read from private field"), t ? t.call(e) : r.get(e)), V = (e, r, t) => {
  if (r.has(e))
    throw TypeError("Cannot add the same private member more than once");
  r instanceof WeakSet ? r.add(e) : r.set(e, t);
}, M = (e, r, t, n) => (Ce(e, r, "write to private field"), n ? n.call(e, t) : r.set(e, t), t);
var be = (e, r, t) => (Ce(e, r, "access private method"), t), Ve = (e, r, t) => Br(Tr(e), t, r);
import { u as Re, j as v, C as Vr, D as zr, a as Wr, b as Hr } from "./index-RZrnTzzg.js";
import { memo as Xr, useMemo as pr, useContext as Zr, useState as Qr, useEffect as qr } from "react";
import "react-dom";
function ne(e) {
  if ([...e].length !== 1)
    throw new Error(`Expected "${e}" to be a single code point`);
  return e.codePointAt(0);
}
function Jr(e, r, t) {
  return e.has(r) || e.set(r, t), e.get(r);
}
const Ue = /* @__PURE__ */ new Set(["alnum", "alpha", "ascii", "blank", "cntrl", "digit", "graph", "lower", "print", "punct", "space", "upper", "word", "xdigit"]), x = String.raw;
function se(e, r) {
  if (e == null)
    throw new Error(r ?? "Value expected");
  return e;
}
const fr = x`\[\^?`, dr = `c.? | C(?:-.?)?|${x`[pP]\{(?:\^?[-\x20_]*[A-Za-z][-\x20\w]*\})?`}|${x`x[89A-Fa-f]\p{AHex}(?:\\x[89A-Fa-f]\p{AHex})*`}|${x`u(?:\p{AHex}{4})? | x\{[^\}]*\}? | x\p{AHex}{0,2}`}|${x`o\{[^\}]*\}?`}|${x`\d{1,3}`}`, Oe = /[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/, le = new RegExp(x`
  \\ (?:
    ${dr}
    | [gk]<[^>]*>?
    | [gk]'[^']*'?
    | .
  )
  | \( (?:
    \? (?:
      [:=!>({]
      | <[=!]
      | <[^>]*>
      | '[^']*'
      | ~\|?
      | #(?:[^)\\]|\\.?)*
      | [^:)]*[:)]
    )?
    | \*[^\)]*\)?
  )?
  | (?:${Oe.source})+
  | ${fr}
  | .
`.replace(/\s+/g, ""), "gsu"), xe = new RegExp(x`
  \\ (?:
    ${dr}
    | .
  )
  | \[:(?:\^?\p{Alpha}+|\^):\]
  | ${fr}
  | &&
  | .
`.replace(/\s+/g, ""), "gsu");
function Kr(e, r = {}) {
  const t = { flags: "", ...r, rules: { captureGroup: !1, singleline: !1, ...r.rules } };
  if (typeof e != "string")
    throw new Error("String expected as pattern");
  const n = wt(t.flags), s = [n.extended], o = { captureGroup: t.rules.captureGroup, getCurrentModX() {
    return s.at(-1);
  }, numOpenGroups: 0, popModX() {
    s.pop();
  }, pushModX(p) {
    s.push(p);
  }, replaceCurrentModX(p) {
    s[s.length - 1] = p;
  }, singleline: t.rules.singleline };
  let a = [], i;
  for (le.lastIndex = 0; i = le.exec(e); ) {
    const p = Yr(o, e, i[0], le.lastIndex);
    p.tokens ? a.push(...p.tokens) : p.token && a.push(p.token), p.lastIndex !== void 0 && (le.lastIndex = p.lastIndex);
  }
  const u = [];
  let c = 0;
  a.filter((p) => p.type === "GroupOpen").forEach((p) => {
    p.kind === "capturing" ? p.number = ++c : p.raw === "(" && u.push(p);
  }), c || u.forEach((p, f) => {
    p.kind = "capturing", p.number = f + 1;
  });
  const l = c || u.length;
  return { tokens: a.map((p) => p.type === "EscapedNumber" ? Ct(p, l) : p).flat(), flags: n };
}
function Yr(e, r, t, n) {
  const [s, o] = t;
  if (t === "[" || t === "[^") {
    const a = et(r, t, n);
    return { tokens: a.tokens, lastIndex: a.lastIndex };
  }
  if (s === "\\") {
    if ("AbBGyYzZ".includes(o))
      return { token: ze(t, t) };
    if (/^\\g[<']/.test(t)) {
      if (!/^\\g(?:<[^>]+>|'[^']+')$/.test(t))
        throw new Error(`Invalid group name "${t}"`);
      return { token: lt(t) };
    }
    if (/^\\k[<']/.test(t)) {
      if (!/^\\k(?:<[^>]+>|'[^']+')$/.test(t))
        throw new Error(`Invalid group name "${t}"`);
      return { token: hr(t) };
    }
    if (o === "K")
      return { token: mr("keep", t) };
    if (o === "N" || o === "R")
      return { token: H("newline", t, { negate: o === "N" }) };
    if (o === "O")
      return { token: H("any", t) };
    if (o === "X")
      return { token: H("text_segment", t) };
    const a = gr(t, { inCharClass: !1 });
    return Array.isArray(a) ? { tokens: a } : { token: a };
  }
  if (s === "(") {
    if (o === "*")
      return { token: gt(t) };
    if (t === "(?{")
      throw new Error(`Unsupported callout "${t}"`);
    if (t.startsWith("(?#")) {
      if (r[n] !== ")")
        throw new Error('Unclosed comment group "(?#"');
      return { lastIndex: n + 1 };
    }
    if (/^\(\?[-imx]+[:)]$/.test(t))
      return { token: dt(t, e) };
    if (e.pushModX(e.getCurrentModX()), e.numOpenGroups++, t === "(" && !e.captureGroup || t === "(?:")
      return { token: re("group", t) };
    if (t === "(?>")
      return { token: re("atomic", t) };
    if (t === "(?=" || t === "(?!" || t === "(?<=" || t === "(?<!")
      return { token: re(t[2] === "<" ? "lookbehind" : "lookahead", t, { negate: t.endsWith("!") }) };
    if (t === "(" && e.captureGroup || t.startsWith("(?<") && t.endsWith(">") || t.startsWith("(?'") && t.endsWith("'"))
      return { token: re("capturing", t, { ...t !== "(" && { name: t.slice(3, -1) } }) };
    if (t.startsWith("(?~")) {
      if (t === "(?~|")
        throw new Error(`Unsupported absence function kind "${t}"`);
      return { token: re("absence_repeater", t) };
    }
    throw t === "(?(" ? new Error(`Unsupported conditional "${t}"`) : new Error(`Invalid or unsupported group option "${t}"`);
  }
  if (t === ")") {
    if (e.popModX(), e.numOpenGroups--, e.numOpenGroups < 0)
      throw new Error('Unmatched ")"');
    return { token: it(t) };
  }
  if (e.getCurrentModX()) {
    if (t === "#") {
      const a = r.indexOf(`
`, n);
      return { lastIndex: a === -1 ? r.length : a };
    }
    if (/^\s$/.test(t)) {
      const a = /\s+/y;
      return a.lastIndex = n, { lastIndex: a.exec(r) ? a.lastIndex : n };
    }
  }
  if (t === ".")
    return { token: H("dot", t) };
  if (t === "^" || t === "$") {
    const a = e.singleline ? { "^": x`\A`, $: x`\Z` }[t] : t;
    return { token: ze(a, t) };
  }
  return t === "|" ? { token: tt(t) } : Oe.test(t) ? { tokens: bt(t) } : { token: R(ne(t), t) };
}
function et(e, r, t) {
  const n = [We(r[1] === "^", r)];
  let s = 1, o;
  for (xe.lastIndex = t; o = xe.exec(e); ) {
    const a = o[0];
    if (a[0] === "[" && a[1] !== ":")
      s++, n.push(We(a[1] === "^", a));
    else if (a === "]") {
      if (n.at(-1).type === "CharacterClassOpen")
        n.push(R(93, a));
      else if (s--, n.push(nt(a)), !s)
        break;
    } else {
      const i = rt(a);
      Array.isArray(i) ? n.push(...i) : n.push(i);
    }
  }
  return { tokens: n, lastIndex: xe.lastIndex || e.length };
}
function rt(e) {
  if (e[0] === "\\")
    return gr(e, { inCharClass: !0 });
  if (e[0] === "[") {
    const r = /\[:(?<negate>\^?)(?<name>[a-z]+):\]/.exec(e);
    if (!r || !Ue.has(r.groups.name))
      throw new Error(`Invalid POSIX class "${e}"`);
    return H("posix", e, { value: r.groups.name, negate: !!r.groups.negate });
  }
  return e === "-" ? st(e) : e === "&&" ? ot(e) : R(ne(e), e);
}
function gr(e, { inCharClass: r }) {
  const t = e[1];
  if (t === "c" || t === "C")
    return ft(e);
  if ("dDhHsSwW".includes(t))
    return ht(e);
  if (e.startsWith(x`\o{`))
    throw new Error(`Incomplete, invalid, or unsupported octal code point "${e}"`);
  if (/^\\[pP]\{/.test(e)) {
    if (e.length === 3)
      throw new Error(`Incomplete or invalid Unicode property "${e}"`);
    return mt(e);
  }
  if (new RegExp("^\\\\x[89A-Fa-f]\\p{AHex}", "u").test(e))
    try {
      const n = e.split(/\\x/).slice(1).map((a) => parseInt(a, 16)), s = new TextDecoder("utf-8", { ignoreBOM: !0, fatal: !0 }).decode(new Uint8Array(n)), o = new TextEncoder();
      return [...s].map((a) => {
        const i = [...o.encode(a)].map((u) => `\\x${u.toString(16)}`).join("");
        return R(ne(a), i);
      });
    } catch {
      throw new Error(`Multibyte code "${e}" incomplete or invalid in Oniguruma`);
    }
  if (t === "u" || t === "x")
    return R(yt(e), e);
  if (He.has(t))
    return R(He.get(t), e);
  if (/\d/.test(t))
    return at(r, e);
  if (e === "\\")
    throw new Error(x`Incomplete escape "\"`);
  if (t === "M")
    throw new Error(`Unsupported meta "${e}"`);
  if ([...e].length === 2)
    return R(e.codePointAt(1), e);
  throw new Error(`Unexpected escape "${e}"`);
}
function tt(e) {
  return { type: "Alternator", raw: e };
}
function ze(e, r) {
  return { type: "Assertion", kind: e, raw: r };
}
function hr(e) {
  return { type: "Backreference", raw: e };
}
function R(e, r) {
  return { type: "Character", value: e, raw: r };
}
function nt(e) {
  return { type: "CharacterClassClose", raw: e };
}
function st(e) {
  return { type: "CharacterClassHyphen", raw: e };
}
function ot(e) {
  return { type: "CharacterClassIntersector", raw: e };
}
function We(e, r) {
  return { type: "CharacterClassOpen", negate: e, raw: r };
}
function H(e, r, t = {}) {
  return { type: "CharacterSet", kind: e, ...t, raw: r };
}
function mr(e, r, t = {}) {
  return e === "keep" ? { type: "Directive", kind: e, raw: r } : { type: "Directive", kind: e, flags: se(t.flags), raw: r };
}
function at(e, r) {
  return { type: "EscapedNumber", inCharClass: e, raw: r };
}
function it(e) {
  return { type: "GroupClose", raw: e };
}
function re(e, r, t = {}) {
  return { type: "GroupOpen", kind: e, ...t, raw: r };
}
function ut(e, r, t, n) {
  return { type: "NamedCallout", kind: e, tag: r, arguments: t, raw: n };
}
function ct(e, r, t, n) {
  return { type: "Quantifier", kind: e, min: r, max: t, raw: n };
}
function lt(e) {
  return { type: "Subroutine", raw: e };
}
const pt = /* @__PURE__ */ new Set(["COUNT", "CMP", "ERROR", "FAIL", "MAX", "MISMATCH", "SKIP", "TOTAL_COUNT"]), He = /* @__PURE__ */ new Map([["a", 7], ["b", 8], ["e", 27], ["f", 12], ["n", 10], ["r", 13], ["t", 9], ["v", 11]]);
function ft(e) {
  const r = e[1] === "c" ? e[2] : e[3];
  if (!r || !/[A-Za-z]/.test(r))
    throw new Error(`Unsupported control character "${e}"`);
  return R(ne(r.toUpperCase()) - 64, e);
}
function dt(e, r) {
  let { on: t, off: n } = /^\(\?(?<on>[imx]*)(?:-(?<off>[-imx]*))?/.exec(e).groups;
  n ?? (n = "");
  const s = (r.getCurrentModX() || t.includes("x")) && !n.includes("x"), o = Ze(t), a = Ze(n), i = {};
  if (o && (i.enable = o), a && (i.disable = a), e.endsWith(")"))
    return r.replaceCurrentModX(s), mr("flags", e, { flags: i });
  if (e.endsWith(":"))
    return r.pushModX(s), r.numOpenGroups++, re("group", e, { ...(o || a) && { flags: i } });
  throw new Error(`Unexpected flag modifier "${e}"`);
}
function gt(e) {
  const r = /\(\*(?<name>[A-Za-z_]\w*)?(?:\[(?<tag>(?:[A-Za-z_]\w*)?)\])?(?:\{(?<args>[^}]*)\})?\)/.exec(e);
  if (!r)
    throw new Error(`Incomplete or invalid named callout "${e}"`);
  const { name: t, tag: n, args: s } = r.groups;
  if (!t)
    throw new Error(`Invalid named callout "${e}"`);
  if (n === "")
    throw new Error(`Named callout tag with empty value not allowed "${e}"`);
  const o = s ? s.split(",").filter((l) => l !== "").map((l) => /^[+-]?\d+$/.test(l) ? +l : l) : [], [a, i, u] = o, c = pt.has(t) ? t.toLowerCase() : "custom";
  switch (c) {
    case "fail":
    case "mismatch":
    case "skip":
      if (o.length > 0)
        throw new Error(`Named callout arguments not allowed "${o}"`);
      break;
    case "error":
      if (o.length > 1)
        throw new Error(`Named callout allows only one argument "${o}"`);
      if (typeof a == "string")
        throw new Error(`Named callout argument must be a number "${a}"`);
      break;
    case "max":
      if (!o.length || o.length > 2)
        throw new Error(`Named callout must have one or two arguments "${o}"`);
      if (typeof a == "string" && !/^[A-Za-z_]\w*$/.test(a))
        throw new Error(`Named callout argument one must be a tag or number "${a}"`);
      if (o.length === 2 && (typeof i == "number" || !/^[<>X]$/.test(i)))
        throw new Error(`Named callout optional argument two must be '<', '>', or 'X' "${i}"`);
      break;
    case "count":
    case "total_count":
      if (o.length > 1)
        throw new Error(`Named callout allows only one argument "${o}"`);
      if (o.length === 1 && (typeof a == "number" || !/^[<>X]$/.test(a)))
        throw new Error(`Named callout optional argument must be '<', '>', or 'X' "${a}"`);
      break;
    case "cmp":
      if (o.length !== 3)
        throw new Error(`Named callout must have three arguments "${o}"`);
      if (typeof a == "string" && !/^[A-Za-z_]\w*$/.test(a))
        throw new Error(`Named callout argument one must be a tag or number "${a}"`);
      if (typeof i == "number" || !/^(?:[<>!=]=|[<>])$/.test(i))
        throw new Error(`Named callout argument two must be '==', '!=', '>', '<', '>=', or '<=' "${i}"`);
      if (typeof u == "string" && !/^[A-Za-z_]\w*$/.test(u))
        throw new Error(`Named callout argument three must be a tag or number "${u}"`);
      break;
    case "custom":
      throw new Error(`Undefined callout name "${t}"`);
    default:
      throw new Error(`Unexpected named callout kind "${c}"`);
  }
  return ut(c, n ?? null, (s == null ? void 0 : s.split(",")) ?? null, e);
}
function Xe(e) {
  let r = null, t, n;
  if (e[0] === "{") {
    const { minStr: s, maxStr: o } = /^\{(?<minStr>\d*)(?:,(?<maxStr>\d*))?/.exec(e).groups, a = 1e5;
    if (+s > a || o && +o > a)
      throw new Error("Quantifier value unsupported in Oniguruma");
    if (t = +s, n = o === void 0 ? +s : o === "" ? 1 / 0 : +o, t > n && (r = "possessive", [t, n] = [n, t]), e.endsWith("?")) {
      if (r === "possessive")
        throw new Error('Unsupported possessive interval quantifier chain with "?"');
      r = "lazy";
    } else
      r || (r = "greedy");
  } else
    t = e[0] === "+" ? 1 : 0, n = e[0] === "?" ? 1 : 1 / 0, r = e[1] === "+" ? "possessive" : e[1] === "?" ? "lazy" : "greedy";
  return ct(r, t, n, e);
}
function ht(e) {
  const r = e[1].toLowerCase();
  return H({ d: "digit", h: "hex", s: "space", w: "word" }[r], e, { negate: e[1] !== r });
}
function mt(e) {
  const { p: r, neg: t, value: n } = /^\\(?<p>[pP])\{(?<neg>\^?)(?<value>[^}]+)/.exec(e).groups;
  return H("property", e, { value: n, negate: r === "P" && !t || r === "p" && !!t });
}
function Ze(e) {
  const r = {};
  return e.includes("i") && (r.ignoreCase = !0), e.includes("m") && (r.dotAll = !0), e.includes("x") && (r.extended = !0), Object.keys(r).length ? r : null;
}
function wt(e) {
  const r = { ignoreCase: !1, dotAll: !1, extended: !1, digitIsAscii: !1, posixIsAscii: !1, spaceIsAscii: !1, wordIsAscii: !1, textSegmentMode: null };
  for (let t = 0; t < e.length; t++) {
    const n = e[t];
    if (!"imxDPSWy".includes(n))
      throw new Error(`Invalid flag "${n}"`);
    if (n === "y") {
      if (!/^y{[gw]}/.test(e.slice(t)))
        throw new Error('Invalid or unspecified flag "y" mode');
      r.textSegmentMode = e[t + 2] === "g" ? "grapheme" : "word", t += 3;
      continue;
    }
    r[{ i: "ignoreCase", m: "dotAll", x: "extended", D: "digitIsAscii", P: "posixIsAscii", S: "spaceIsAscii", W: "wordIsAscii" }[n]] = !0;
  }
  return r;
}
function yt(e) {
  if (new RegExp("^(?:\\\\u(?!\\p{AHex}{4})|\\\\x(?!\\p{AHex}{1,2}|\\{\\p{AHex}{1,8}\\}))", "u").test(e))
    throw new Error(`Incomplete or invalid escape "${e}"`);
  const r = e[2] === "{" ? new RegExp("^\\\\x\\{\\s*(?<hex>\\p{AHex}+)", "u").exec(e).groups.hex : e.slice(2);
  return parseInt(r, 16);
}
function Ct(e, r) {
  const { raw: t, inCharClass: n } = e, s = t.slice(1);
  if (!n && (s !== "0" && s.length === 1 || s[0] !== "0" && +s <= r))
    return [hr(t)];
  const o = [], a = s.match(/^[0-7]+|\d/g);
  for (let i = 0; i < a.length; i++) {
    const u = a[i];
    let c;
    if (i === 0 && u !== "8" && u !== "9") {
      if (c = parseInt(u, 8), c > 127)
        throw new Error(x`Octal encoded byte above 177 unsupported "${t}"`);
    } else
      c = ne(u);
    o.push(R(c, (i === 0 ? "\\" : "") + u));
  }
  return o;
}
function bt(e) {
  const r = [], t = new RegExp(Oe, "gy");
  let n;
  for (; n = t.exec(e); ) {
    const s = n[0];
    if (s[0] === "{") {
      const o = /^\{(?<min>\d+),(?<max>\d+)\}\??$/.exec(s);
      if (o) {
        const { min: a, max: i } = o.groups;
        if (+a > +i && s.endsWith("?")) {
          t.lastIndex--, r.push(Xe(s.slice(0, -1)));
          continue;
        }
      }
    }
    r.push(Xe(s));
  }
  return r;
}
function wr(e, r) {
  if (!Array.isArray(e.body))
    throw new Error("Expected node with body array");
  if (e.body.length !== 1)
    return !1;
  const t = e.body[0];
  return !r || Object.keys(r).every((n) => r[n] === t[n]);
}
function xt(e) {
  return kt.has(e.type);
}
const kt = /* @__PURE__ */ new Set(["AbsenceFunction", "Backreference", "CapturingGroup", "Character", "CharacterClass", "CharacterSet", "Group", "Quantifier", "Subroutine"]);
function yr(e, r = {}) {
  const t = { flags: "", normalizeUnknownPropertyNames: !1, skipBackrefValidation: !1, skipLookbehindValidation: !1, skipPropertyNameValidation: !1, unicodePropertyMap: null, ...r, rules: { captureGroup: !1, singleline: !1, ...r.rules } }, n = Kr(e, { flags: t.flags, rules: { captureGroup: t.rules.captureGroup, singleline: t.rules.singleline } }), s = (f, g) => {
    const d = n.tokens[o.nextIndex];
    switch (o.parent = f, o.nextIndex++, d.type) {
      case "Alternator":
        return q();
      case "Assertion":
        return $t(d);
      case "Backreference":
        return Et(d, o);
      case "Character":
        return he(d.value, { useLastValid: !!g.isCheckingRangeEnd });
      case "CharacterClassHyphen":
        return At(d, o, g);
      case "CharacterClassOpen":
        return It(d, o, g);
      case "CharacterSet":
        return vt(d, o);
      case "Directive":
        return Ft(d.kind, { flags: d.flags });
      case "GroupOpen":
        return St(d, o, g);
      case "NamedCallout":
        return Pt(d.kind, d.tag, d.arguments);
      case "Quantifier":
        return _t(d, o);
      case "Subroutine":
        return Nt(d, o);
      default:
        throw new Error(`Unexpected token type "${d.type}"`);
    }
  }, o = { capturingGroups: [], hasNumberedRef: !1, namedGroupsByName: /* @__PURE__ */ new Map(), nextIndex: 0, normalizeUnknownPropertyNames: t.normalizeUnknownPropertyNames, parent: null, skipBackrefValidation: t.skipBackrefValidation, skipLookbehindValidation: t.skipLookbehindValidation, skipPropertyNameValidation: t.skipPropertyNameValidation, subroutines: [], tokens: n.tokens, unicodePropertyMap: t.unicodePropertyMap, walk: s }, a = Ut(Gt(n.flags));
  let i = a.body[0];
  for (; o.nextIndex < n.tokens.length; ) {
    const f = s(i, {});
    f.type === "Alternative" ? (a.body.push(f), i = f) : i.body.push(f);
  }
  const { capturingGroups: u, hasNumberedRef: c, namedGroupsByName: l, subroutines: p } = o;
  if (c && l.size && !t.rules.captureGroup)
    throw new Error("Numbered backref/subroutine not allowed when using named capture");
  for (const { ref: f } of p)
    if (typeof f == "number") {
      if (f > u.length)
        throw new Error("Subroutine uses a group number that's not defined");
      f && (u[f - 1].isSubroutined = !0);
    } else if (l.has(f)) {
      if (l.get(f).length > 1)
        throw new Error(x`Subroutine uses a duplicate group name "\g<${f}>"`);
      l.get(f)[0].isSubroutined = !0;
    } else
      throw new Error(x`Subroutine uses a group name that's not defined "\g<${f}>"`);
  return a;
}
function $t({ kind: e }) {
  return Ne(se({ "^": "line_start", $: "line_end", "\\A": "string_start", "\\b": "word_boundary", "\\B": "word_boundary", "\\G": "search_start", "\\y": "text_segment_boundary", "\\Y": "text_segment_boundary", "\\z": "string_end", "\\Z": "string_end_newline" }[e], `Unexpected assertion kind "${e}"`), { negate: e === x`\B` || e === x`\Y` });
}
function Et({ raw: e }, r) {
  const t = /^\\k[<']/.test(e), n = t ? e.slice(3, -1) : e.slice(1), s = (o, a = !1) => {
    const i = r.capturingGroups.length;
    let u = !1;
    if (o > i)
      if (r.skipBackrefValidation)
        u = !0;
      else
        throw new Error(`Not enough capturing groups defined to the left "${e}"`);
    return r.hasNumberedRef = !0, Me(a ? i + 1 - o : o, { orphan: u });
  };
  if (t) {
    const o = /^(?<sign>-?)0*(?<num>[1-9]\d*)$/.exec(n);
    if (o)
      return s(+o.groups.num, !!o.groups.sign);
    if (/[-+]/.test(n))
      throw new Error(`Invalid backref name "${e}"`);
    if (!r.namedGroupsByName.has(n))
      throw new Error(`Group name not defined to the left "${e}"`);
    return Me(n);
  }
  return s(+n);
}
function At(e, r, t) {
  const { tokens: n, walk: s } = r, o = r.parent, a = o.body.at(-1), i = n[r.nextIndex];
  if (!t.isCheckingRangeEnd && a && a.type !== "CharacterClass" && a.type !== "CharacterClassRange" && i && i.type !== "CharacterClassOpen" && i.type !== "CharacterClassClose" && i.type !== "CharacterClassIntersector") {
    const u = s(o, { ...t, isCheckingRangeEnd: !0 });
    if (a.type === "Character" && u.type === "Character")
      return o.body.pop(), Lt(a, u);
    throw new Error("Invalid character class range");
  }
  return he(ne("-"));
}
function It({ negate: e }, r, t) {
  const { tokens: n, walk: s } = r, o = n[r.nextIndex], a = [de()];
  let i = Je(o);
  for (; i.type !== "CharacterClassClose"; ) {
    if (i.type === "CharacterClassIntersector")
      a.push(de()), r.nextIndex++;
    else {
      const c = a.at(-1);
      c.body.push(s(c, t));
    }
    i = Je(n[r.nextIndex], o);
  }
  const u = de({ negate: e });
  return a.length === 1 ? u.body = a[0].body : (u.kind = "intersection", u.body = a.map((c) => c.body.length === 1 ? c.body[0] : c)), r.nextIndex++, u;
}
function vt({ kind: e, negate: r, value: t }, n) {
  const { normalizeUnknownPropertyNames: s, skipPropertyNameValidation: o, unicodePropertyMap: a } = n;
  if (e === "property") {
    const i = me(t);
    if (Ue.has(i) && !(a != null && a.has(i)))
      e = "posix", t = i;
    else
      return te(t, { negate: r, normalizeUnknownPropertyNames: s, skipPropertyNameValidation: o, unicodePropertyMap: a });
  }
  return e === "posix" ? Rt(t, { negate: r }) : Le(e, { negate: r });
}
function St(e, r, t) {
  const { tokens: n, capturingGroups: s, namedGroupsByName: o, skipLookbehindValidation: a, walk: i } = r, u = Ot(e), c = u.type === "AbsenceFunction", l = qe(u), p = l && u.negate;
  if (u.type === "CapturingGroup" && (s.push(u), u.name && Jr(o, u.name, []).push(u)), c && t.isInAbsenceFunction)
    throw new Error("Nested absence function not supported by Oniguruma");
  let f = Ke(n[r.nextIndex]);
  for (; f.type !== "GroupClose"; ) {
    if (f.type === "Alternator")
      u.body.push(q()), r.nextIndex++;
    else {
      const g = u.body.at(-1), d = i(g, { ...t, isInAbsenceFunction: t.isInAbsenceFunction || c, isInLookbehind: t.isInLookbehind || l, isInNegLookbehind: t.isInNegLookbehind || p });
      if (g.body.push(d), (l || t.isInLookbehind) && !a) {
        const m = "Lookbehind includes a pattern not allowed by Oniguruma";
        if (p || t.isInNegLookbehind) {
          if (Qe(d) || d.type === "CapturingGroup")
            throw new Error(m);
        } else if (Qe(d) || qe(d) && d.negate)
          throw new Error(m);
      }
    }
    f = Ke(n[r.nextIndex]);
  }
  return r.nextIndex++, u;
}
function _t({ kind: e, min: r, max: t }, n) {
  const s = n.parent, o = s.body.at(-1);
  if (!o || !xt(o))
    throw new Error("Quantifier requires a repeatable token");
  const a = br(e, r, t, o);
  return s.body.pop(), a;
}
function Nt({ raw: e }, r) {
  const { capturingGroups: t, subroutines: n } = r;
  let s = e.slice(3, -1);
  const o = /^(?<sign>[-+]?)0*(?<num>[1-9]\d*)$/.exec(s);
  if (o) {
    const i = +o.groups.num, u = t.length;
    if (r.hasNumberedRef = !0, s = { "": i, "+": u + i, "-": u + 1 - i }[o.groups.sign], s < 1)
      throw new Error("Invalid subroutine number");
  } else
    s === "0" && (s = 0);
  const a = xr(s);
  return n.push(a), a;
}
function Mt(e, r) {
  return { type: "AbsenceFunction", kind: e, body: ce(r == null ? void 0 : r.body) };
}
function q(e) {
  return { type: "Alternative", body: kr(e == null ? void 0 : e.body) };
}
function Ne(e, r) {
  const t = { type: "Assertion", kind: e };
  return (e === "word_boundary" || e === "text_segment_boundary") && (t.negate = !!(r != null && r.negate)), t;
}
function Me(e, r) {
  const t = !!(r != null && r.orphan);
  return { type: "Backreference", ref: e, ...t && { orphan: t } };
}
function Cr(e, r) {
  const t = { name: void 0, isSubroutined: !1, ...r };
  if (t.name !== void 0 && !Dt(t.name))
    throw new Error(`Group name "${t.name}" invalid in Oniguruma`);
  return { type: "CapturingGroup", number: e, ...t.name && { name: t.name }, ...t.isSubroutined && { isSubroutined: t.isSubroutined }, body: ce(r == null ? void 0 : r.body) };
}
function he(e, r) {
  const t = { useLastValid: !1, ...r };
  if (e > 1114111) {
    const n = e.toString(16);
    if (t.useLastValid)
      e = 1114111;
    else
      throw e > 1310719 ? new Error(`Invalid code point out of range "\\x{${n}}"`) : new Error(`Invalid code point out of range in JS "\\x{${n}}"`);
  }
  return { type: "Character", value: e };
}
function de(e) {
  const r = { kind: "union", negate: !1, ...e };
  return { type: "CharacterClass", kind: r.kind, negate: r.negate, body: kr(e == null ? void 0 : e.body) };
}
function Lt(e, r) {
  if (r.value < e.value)
    throw new Error("Character class range out of order");
  return { type: "CharacterClassRange", min: e, max: r };
}
function Le(e, r) {
  const t = !!(r != null && r.negate), n = { type: "CharacterSet", kind: e };
  return (e === "digit" || e === "hex" || e === "newline" || e === "space" || e === "word") && (n.negate = t), (e === "text_segment" || e === "newline" && !t) && (n.variableLength = !0), n;
}
function Ft(e, r = {}) {
  if (e === "keep")
    return { type: "Directive", kind: e };
  if (e === "flags")
    return { type: "Directive", kind: e, flags: se(r.flags) };
  throw new Error(`Unexpected directive kind "${e}"`);
}
function Gt(e) {
  return { type: "Flags", ...e };
}
function L(e) {
  const r = e == null ? void 0 : e.atomic, t = e == null ? void 0 : e.flags;
  if (r && t)
    throw new Error("Atomic group cannot have flags");
  return { type: "Group", ...r && { atomic: r }, ...t && { flags: t }, body: ce(e == null ? void 0 : e.body) };
}
function W(e) {
  const r = { behind: !1, negate: !1, ...e };
  return { type: "LookaroundAssertion", kind: r.behind ? "lookbehind" : "lookahead", negate: r.negate, body: ce(e == null ? void 0 : e.body) };
}
function Pt(e, r, t) {
  return { type: "NamedCallout", kind: e, tag: r, arguments: t };
}
function Rt(e, r) {
  const t = !!(r != null && r.negate);
  if (!Ue.has(e))
    throw new Error(`Invalid POSIX class "${e}"`);
  return { type: "CharacterSet", kind: "posix", value: e, negate: t };
}
function br(e, r, t, n) {
  if (r > t)
    throw new Error("Invalid reversed quantifier range");
  return { type: "Quantifier", kind: e, min: r, max: t, body: n };
}
function Ut(e, r) {
  return { type: "Regex", body: ce(r == null ? void 0 : r.body), flags: e };
}
function xr(e) {
  return { type: "Subroutine", ref: e };
}
function te(e, r) {
  var s;
  const t = { negate: !1, normalizeUnknownPropertyNames: !1, skipPropertyNameValidation: !1, unicodePropertyMap: null, ...r };
  let n = (s = t.unicodePropertyMap) == null ? void 0 : s.get(me(e));
  if (!n) {
    if (t.normalizeUnknownPropertyNames)
      n = Tt(e);
    else if (t.unicodePropertyMap && !t.skipPropertyNameValidation)
      throw new Error(x`Invalid Unicode property "\p{${e}}"`);
  }
  return { type: "CharacterSet", kind: "property", value: n ?? e, negate: t.negate };
}
function Ot({ flags: e, kind: r, name: t, negate: n, number: s }) {
  switch (r) {
    case "absence_repeater":
      return Mt("repeater");
    case "atomic":
      return L({ atomic: !0 });
    case "capturing":
      return Cr(s, { name: t });
    case "group":
      return L({ flags: e });
    case "lookahead":
    case "lookbehind":
      return W({ behind: r === "lookbehind", negate: n });
    default:
      throw new Error(`Unexpected group kind "${r}"`);
  }
}
function ce(e) {
  if (e === void 0)
    e = [q()];
  else if (!Array.isArray(e) || !e.length || !e.every((r) => r.type === "Alternative"))
    throw new Error("Invalid body; expected array of one or more Alternative nodes");
  return e;
}
function kr(e) {
  if (e === void 0)
    e = [];
  else if (!Array.isArray(e) || !e.every((r) => !!r.type))
    throw new Error("Invalid body; expected array of nodes");
  return e;
}
function Qe(e) {
  return e.type === "LookaroundAssertion" && e.kind === "lookahead";
}
function qe(e) {
  return e.type === "LookaroundAssertion" && e.kind === "lookbehind";
}
function Dt(e) {
  return /^[\p{Alpha}\p{Pc}][^)]*$/u.test(e);
}
function Tt(e) {
  return e.trim().replace(/[- _]+/g, "_").replace(/[A-Z][a-z]+(?=[A-Z])/g, "$&_").replace(/[A-Za-z]+/g, (r) => r[0].toUpperCase() + r.slice(1).toLowerCase());
}
function me(e) {
  return e.replace(/[- _]+/g, "").toLowerCase();
}
function Je(e, r) {
  return se(e, `${(r == null ? void 0 : r.type) === "Character" && r.value === 93 ? "Empty" : "Unclosed"} character class`);
}
function Ke(e) {
  return se(e, "Unclosed group");
}
function ae(e, r, t = null) {
  function n(o, a) {
    for (let i = 0; i < o.length; i++) {
      const u = s(o[i], a, i, o);
      i = Math.max(-1, i + u);
    }
  }
  function s(o, a = null, i = null, u = null) {
    var E, A;
    let c = 0, l = !1;
    const p = { node: o, parent: a, key: i, container: u, root: e, remove() {
      pe(u).splice(Math.max(0, K(i) + c), 1), c--, l = !0;
    }, removeAllNextSiblings() {
      return pe(u).splice(K(i) + 1);
    }, removeAllPrevSiblings() {
      const y = K(i) + c;
      return c -= y, pe(u).splice(0, Math.max(0, y));
    }, replaceWith(y, k = {}) {
      const _ = !!k.traverse;
      u ? u[Math.max(0, K(i) + c)] = y : se(a, "Can't replace root node")[i] = y, _ && s(y, a, i, u), l = !0;
    }, replaceWithMultiple(y, k = {}) {
      const _ = !!k.traverse;
      if (pe(u).splice(Math.max(0, K(i) + c), 1, ...y), c += y.length - 1, _) {
        let j = 0;
        for (let N = 0; N < y.length; N++)
          j += s(y[N], a, K(i) + N + j, u);
      }
      l = !0;
    }, skip() {
      l = !0;
    } }, { type: f } = o, g = r["*"], d = r[f], m = typeof g == "function" ? g : g == null ? void 0 : g.enter, w = typeof d == "function" ? d : d == null ? void 0 : d.enter;
    if (m == null || m(p, t), w == null || w(p, t), !l)
      switch (f) {
        case "AbsenceFunction":
        case "CapturingGroup":
        case "Group":
          n(o.body, o);
          break;
        case "Alternative":
        case "CharacterClass":
          n(o.body, o);
          break;
        case "Assertion":
        case "Backreference":
        case "Character":
        case "CharacterSet":
        case "Directive":
        case "Flags":
        case "NamedCallout":
        case "Subroutine":
          break;
        case "CharacterClassRange":
          s(o.min, o, "min"), s(o.max, o, "max");
          break;
        case "LookaroundAssertion":
          n(o.body, o);
          break;
        case "Quantifier":
          s(o.body, o, "body");
          break;
        case "Regex":
          n(o.body, o), s(o.flags, o, "flags");
          break;
        default:
          throw new Error(`Unexpected node type "${f}"`);
      }
    return (E = d == null ? void 0 : d.exit) == null || E.call(d, p, t), (A = g == null ? void 0 : g.exit) == null || A.call(g, p, t), c;
  }
  return s(e), e;
}
function pe(e) {
  if (!Array.isArray(e))
    throw new Error("Container expected");
  return e;
}
function K(e) {
  if (typeof e != "number")
    throw new Error("Numeric key expected");
  return e;
}
const Bt = String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;
function jt(e, r) {
  for (let t = 0; t < e.length; t++)
    e[t] >= r && e[t]++;
}
function Vt(e, r, t, n) {
  return e.slice(0, r) + n + e.slice(r + t.length);
}
const S = Object.freeze({
  DEFAULT: "DEFAULT",
  CHAR_CLASS: "CHAR_CLASS"
});
function De(e, r, t, n) {
  const s = new RegExp(String.raw`${r}|(?<$skip>\[\^?|\\?.)`, "gsu"), o = [!1];
  let a = 0, i = "";
  for (const u of e.matchAll(s)) {
    const { 0: c, groups: { $skip: l } } = u;
    if (!l && (!n || n === S.DEFAULT == !a)) {
      t instanceof Function ? i += t(u, {
        context: a ? S.CHAR_CLASS : S.DEFAULT,
        negated: o[o.length - 1]
      }) : i += t;
      continue;
    }
    c[0] === "[" ? (a++, o.push(c[1] === "^")) : c === "]" && a && (a--, o.pop()), i += c;
  }
  return i;
}
function $r(e, r, t, n) {
  De(e, r, t, n);
}
function zt(e, r, t = 0, n) {
  if (!new RegExp(r, "su").test(e))
    return null;
  const s = new RegExp(`${r}|(?<$skip>\\\\?.)`, "gsu");
  s.lastIndex = t;
  let o = 0, a;
  for (; a = s.exec(e); ) {
    const { 0: i, groups: { $skip: u } } = a;
    if (!u && (!n || n === S.DEFAULT == !o))
      return a;
    i === "[" ? o++ : i === "]" && o && o--, s.lastIndex == a.index && s.lastIndex++;
  }
  return null;
}
function fe(e, r, t) {
  return !!zt(e, r, 0, t);
}
function Wt(e, r) {
  const t = /\\?./gsu;
  t.lastIndex = r;
  let n = e.length, s = 0, o = 1, a;
  for (; a = t.exec(e); ) {
    const [i] = a;
    if (i === "[")
      s++;
    else if (s)
      i === "]" && s--;
    else if (i === "(")
      o++;
    else if (i === ")" && (o--, !o)) {
      n = a.index;
      break;
    }
  }
  return e.slice(r, n);
}
const Ye = new RegExp(String.raw`(?<noncapturingStart>${Bt})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`, "gsu");
function Ht(e, r) {
  const t = (r == null ? void 0 : r.hiddenCaptures) ?? [];
  let n = (r == null ? void 0 : r.captureTransfers) ?? /* @__PURE__ */ new Map();
  if (!/\(\?>/.test(e))
    return {
      pattern: e,
      captureTransfers: n,
      hiddenCaptures: t
    };
  const s = "(?>", o = "(?:(?=(", a = [0], i = [];
  let u = 0, c = 0, l = NaN, p;
  do {
    p = !1;
    let f = 0, g = 0, d = !1, m;
    for (Ye.lastIndex = Number.isNaN(l) ? 0 : l + o.length; m = Ye.exec(e); ) {
      const { 0: w, index: E, groups: { capturingStart: A, noncapturingStart: y } } = m;
      if (w === "[")
        f++;
      else if (f)
        w === "]" && f--;
      else if (w === s && !d)
        l = E, d = !0;
      else if (d && y)
        g++;
      else if (A)
        d ? g++ : (u++, a.push(u + c));
      else if (w === ")" && d) {
        if (!g) {
          c++;
          const k = u + c;
          if (e = `${e.slice(0, l)}${o}${e.slice(l + s.length, E)}))<$$${k}>)${e.slice(E + 1)}`, p = !0, i.push(k), jt(t, k), n.size) {
            const _ = /* @__PURE__ */ new Map();
            n.forEach((j, N) => {
              _.set(
                N >= k ? N + 1 : N,
                j.map((J) => J >= k ? J + 1 : J)
              );
            }), n = _;
          }
          break;
        }
        g--;
      }
    }
  } while (p);
  return t.push(...i), e = De(
    e,
    String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,
    ({ 0: f, groups: { backrefNum: g, wrappedBackrefNum: d } }) => {
      if (g) {
        const m = +g;
        if (m > a.length - 1)
          throw new Error(`Backref "${f}" greater than number of captures`);
        return `\\${a[m]}`;
      }
      return `\\${d}`;
    },
    S.DEFAULT
  ), {
    pattern: e,
    captureTransfers: n,
    hiddenCaptures: t
  };
}
const Er = String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`, ke = new RegExp(String.raw`
\\(?: \d+
  | c[A-Za-z]
  | [gk]<[^>]+>
  | [pPu]\{[^\}]+\}
  | u[A-Fa-f\d]{4}
  | x[A-Fa-f\d]{2}
  )
| \((?: \? (?: [:=!>]
  | <(?:[=!]|[^>]+>)
  | [A-Za-z\-]+:
  | \(DEFINE\)
  ))?
| (?<qBase>${Er})(?<qMod>[?+]?)(?<invalidQ>[?*+\{]?)
| \\?.
`.replace(/\s+/g, ""), "gsu");
function Xt(e) {
  if (!new RegExp(`${Er}\\+`).test(e))
    return {
      pattern: e
    };
  const r = [];
  let t = null, n = null, s = "", o = 0, a;
  for (ke.lastIndex = 0; a = ke.exec(e); ) {
    const { 0: i, index: u, groups: { qBase: c, qMod: l, invalidQ: p } } = a;
    if (i === "[")
      o || (n = u), o++;
    else if (i === "]")
      o ? o-- : n = null;
    else if (!o)
      if (l === "+" && s && !s.startsWith("(")) {
        if (p)
          throw new Error(`Invalid quantifier "${i}"`);
        let f = -1;
        if (/^\{\d+\}$/.test(c))
          e = Vt(e, u + c.length, l, "");
        else {
          if (s === ")" || s === "]") {
            const g = s === ")" ? t : n;
            if (g === null)
              throw new Error(`Invalid unmatched "${s}"`);
            e = `${e.slice(0, g)}(?>${e.slice(g, u)}${c})${e.slice(u + i.length)}`;
          } else
            e = `${e.slice(0, u - s.length)}(?>${s}${c})${e.slice(u + i.length)}`;
          f += 4;
        }
        ke.lastIndex += f;
      } else
        i[0] === "(" ? r.push(u) : i === ")" && (t = r.length ? r.pop() : null);
    s = i;
  }
  return {
    pattern: e
  };
}
const I = String.raw, Zt = I`\\g<(?<gRNameOrNum>[^>&]+)&R=(?<gRDepth>[^>]+)>`, Fe = I`\(\?R=(?<rDepth>[^\)]+)\)|${Zt}`, we = I`\(\?<(?![=!])(?<captureName>[^>]+)>`, Ar = I`${we}|(?<unnamed>\()(?!\?)`, z = new RegExp(I`${we}|${Fe}|\(\?|\\?.`, "gsu"), $e = "Cannot use multiple overlapping recursions";
function Qt(e, r) {
  const { hiddenCaptures: t, mode: n } = {
    hiddenCaptures: [],
    mode: "plugin",
    ...r
  };
  let s = (r == null ? void 0 : r.captureTransfers) ?? /* @__PURE__ */ new Map();
  if (!new RegExp(Fe, "su").test(e))
    return {
      pattern: e,
      captureTransfers: s,
      hiddenCaptures: t
    };
  if (n === "plugin" && fe(e, I`\(\?\(DEFINE\)`, S.DEFAULT))
    throw new Error("DEFINE groups cannot be used with recursion");
  const o = [], a = fe(e, I`\\[1-9]`, S.DEFAULT), i = /* @__PURE__ */ new Map(), u = [];
  let c = !1, l = 0, p = 0, f;
  for (z.lastIndex = 0; f = z.exec(e); ) {
    const { 0: g, groups: { captureName: d, rDepth: m, gRNameOrNum: w, gRDepth: E } } = f;
    if (g === "[")
      l++;
    else if (l)
      g === "]" && l--;
    else if (m) {
      if (er(m), c)
        throw new Error($e);
      if (a)
        throw new Error(
          // When used in `external` mode by transpilers other than Regex+, backrefs might have
          // gone through conversion from named to numbered, so avoid a misleading error
          `${n === "external" ? "Backrefs" : "Numbered backrefs"} cannot be used with global recursion`
        );
      const A = e.slice(0, f.index), y = e.slice(z.lastIndex);
      if (fe(y, Fe, S.DEFAULT))
        throw new Error($e);
      const k = +m - 1;
      e = rr(
        A,
        y,
        k,
        !1,
        t,
        o,
        p
      ), s = nr(
        s,
        A,
        k,
        o.length,
        0,
        p
      );
      break;
    } else if (w) {
      er(E);
      let A = !1;
      for (const oe of u)
        if (oe.name === w || oe.num === +w) {
          if (A = !0, oe.hasRecursedWithin)
            throw new Error($e);
          break;
        }
      if (!A)
        throw new Error(I`Recursive \g cannot be used outside the referenced group "${n === "external" ? w : I`\g<${w}&R=${E}>`}"`);
      const y = i.get(w), k = Wt(e, y);
      if (a && fe(k, I`${we}|\((?!\?)`, S.DEFAULT))
        throw new Error(
          // When used in `external` mode by transpilers other than Regex+, backrefs might have
          // gone through conversion from named to numbered, so avoid a misleading error
          `${n === "external" ? "Backrefs" : "Numbered backrefs"} cannot be used with recursion of capturing groups`
        );
      const _ = e.slice(y, f.index), j = k.slice(_.length + g.length), N = o.length, J = +E - 1, je = rr(
        _,
        j,
        J,
        !0,
        t,
        o,
        p
      );
      s = nr(
        s,
        _,
        J,
        o.length - N,
        N,
        p
      );
      const Ur = e.slice(0, y), Or = e.slice(y + k.length);
      e = `${Ur}${je}${Or}`, z.lastIndex += je.length - g.length - _.length - j.length, u.forEach((oe) => oe.hasRecursedWithin = !0), c = !0;
    } else if (d)
      p++, i.set(String(p), z.lastIndex), i.set(d, z.lastIndex), u.push({
        num: p,
        name: d
      });
    else if (g[0] === "(") {
      const A = g === "(";
      A && (p++, i.set(String(p), z.lastIndex)), u.push(A ? { num: p } : {});
    } else
      g === ")" && u.pop();
  }
  return t.push(...o), {
    pattern: e,
    captureTransfers: s,
    hiddenCaptures: t
  };
}
function er(e) {
  const r = `Max depth must be integer between 2 and 100; used ${e}`;
  if (!/^[1-9]\d*$/.test(e))
    throw new Error(r);
  if (e = +e, e < 2 || e > 100)
    throw new Error(r);
}
function rr(e, r, t, n, s, o, a) {
  const i = /* @__PURE__ */ new Set();
  n && $r(e + r, we, ({ groups: { captureName: c } }) => {
    i.add(c);
  }, S.DEFAULT);
  const u = [
    t,
    n ? i : null,
    s,
    o,
    a
  ];
  return `${e}${tr(`(?:${e}`, "forward", ...u)}(?:)${tr(`${r})`, "backward", ...u)}${r}`;
}
function tr(e, r, t, n, s, o, a) {
  const u = (l) => r === "forward" ? l + 2 : t - l + 2 - 1;
  let c = "";
  for (let l = 0; l < t; l++) {
    const p = u(l);
    c += De(
      e,
      I`${Ar}|\\k<(?<backref>[^>]+)>`,
      ({ 0: f, groups: { captureName: g, unnamed: d, backref: m } }) => {
        if (m && n && !n.has(m))
          return f;
        const w = `_$${p}`;
        if (d || g) {
          const E = a + o.length + 1;
          return o.push(E), qt(s, E), d ? f : `(?<${g}${w}>`;
        }
        return I`\k<${m}${w}>`;
      },
      S.DEFAULT
    );
  }
  return c;
}
function qt(e, r) {
  for (let t = 0; t < e.length; t++)
    e[t] >= r && e[t]++;
}
function nr(e, r, t, n, s, o) {
  if (e.size && n) {
    let a = 0;
    $r(r, Ar, () => a++, S.DEFAULT);
    const i = o - a + s, u = /* @__PURE__ */ new Map();
    return e.forEach((c, l) => {
      const p = (n - a * t) / t, f = a * t, g = l > i + a ? l + n : l, d = [];
      for (const m of c)
        if (m <= i)
          d.push(m);
        else if (m > i + a + p)
          d.push(m + n);
        else if (m <= i + a)
          for (let w = 0; w <= t; w++)
            d.push(m + a * w);
        else
          for (let w = 0; w <= t; w++)
            d.push(m + f + p * w);
      u.set(g, d);
    }), u;
  }
  return e;
}
var b = String.fromCodePoint, h = String.raw, U = {
  flagGroups: (() => {
    try {
      new RegExp("(?i:)");
    } catch {
      return !1;
    }
    return !0;
  })(),
  unicodeSets: (() => {
    try {
      new RegExp("[[]]", "v");
    } catch {
      return !1;
    }
    return !0;
  })()
};
U.bugFlagVLiteralHyphenIsRange = U.unicodeSets ? (() => {
  try {
    new RegExp(h`[\d\-a]`, "v");
  } catch {
    return !0;
  }
  return !1;
})() : !1;
U.bugNestedClassIgnoresNegation = U.unicodeSets && new RegExp("[[^a]]", "v").test("a");
function ge(e, { enable: r, disable: t }) {
  return {
    dotAll: !(t != null && t.dotAll) && !!(r != null && r.dotAll || e.dotAll),
    ignoreCase: !(t != null && t.ignoreCase) && !!(r != null && r.ignoreCase || e.ignoreCase)
  };
}
function ie(e, r, t) {
  return e.has(r) || e.set(r, t), e.get(r);
}
function Ge(e, r) {
  return sr[e] >= sr[r];
}
function Jt(e, r) {
  if (e == null)
    throw new Error(r ?? "Value expected");
  return e;
}
var sr = {
  ES2025: 2025,
  ES2024: 2024,
  ES2018: 2018
}, Kt = (
  /** @type {const} */
  {
    auto: "auto",
    ES2025: "ES2025",
    ES2024: "ES2024",
    ES2018: "ES2018"
  }
);
function Ir(e = {}) {
  if ({}.toString.call(e) !== "[object Object]")
    throw new Error("Unexpected options");
  if (e.target !== void 0 && !Kt[e.target])
    throw new Error(`Unexpected target "${e.target}"`);
  const r = {
    // Sets the level of emulation rigor/strictness.
    accuracy: "default",
    // Disables advanced emulation that relies on returning a `RegExp` subclass, resulting in
    // certain patterns not being emulatable.
    avoidSubclass: !1,
    // Oniguruma flags; a string with `i`, `m`, `x`, `D`, `S`, `W`, `y{g}` in any order (all
    // optional). Oniguruma's `m` is equivalent to JavaScript's `s` (`dotAll`).
    flags: "",
    // Include JavaScript flag `g` (`global`) in the result.
    global: !1,
    // Include JavaScript flag `d` (`hasIndices`) in the result.
    hasIndices: !1,
    // Delay regex construction until first use if the transpiled pattern is at least this length.
    lazyCompileLength: 1 / 0,
    // JavaScript version used for generated regexes. Using `auto` detects the best value based on
    // your environment. Later targets allow faster processing, simpler generated source, and
    // support for additional features.
    target: "auto",
    // Disables minifications that simplify the pattern without changing the meaning.
    verbose: !1,
    ...e,
    // Advanced options that override standard behavior, error checking, and flags when enabled.
    rules: {
      // Useful with TextMate grammars that merge backreferences across patterns.
      allowOrphanBackrefs: !1,
      // Use ASCII `\b` and `\B`, which increases search performance of generated regexes.
      asciiWordBoundaries: !1,
      // Allow unnamed captures and numbered calls (backreferences and subroutines) when using
      // named capture. This is Oniguruma option `ONIG_OPTION_CAPTURE_GROUP`; on by default in
      // `vscode-oniguruma`.
      captureGroup: !1,
      // Change the recursion depth limit from Oniguruma's `20` to an integer `2`–`20`.
      recursionLimit: 20,
      // `^` as `\A`; `$` as`\Z`. Improves search performance of generated regexes without changing
      // the meaning if searching line by line. This is Oniguruma option `ONIG_OPTION_SINGLELINE`.
      singleline: !1,
      ...e.rules
    }
  };
  return r.target === "auto" && (r.target = U.flagGroups ? "ES2025" : U.unicodeSets ? "ES2024" : "ES2018"), r;
}
var Yt = "[	-\r ]", en = /* @__PURE__ */ new Set([
  b(304),
  // İ
  b(305)
  // ı
]), F = h`[\p{L}\p{M}\p{N}\p{Pc}]`;
function vr(e) {
  if (en.has(e))
    return [e];
  const r = /* @__PURE__ */ new Set(), t = e.toLowerCase(), n = t.toUpperCase(), s = nn.get(t), o = rn.get(t), a = tn.get(t);
  return [...n].length === 1 && r.add(n), a && r.add(a), s && r.add(s), r.add(t), o && r.add(o), [...r];
}
var Te = /* @__PURE__ */ new Map(
  `C Other
Cc Control cntrl
Cf Format
Cn Unassigned
Co Private_Use
Cs Surrogate
L Letter
LC Cased_Letter
Ll Lowercase_Letter
Lm Modifier_Letter
Lo Other_Letter
Lt Titlecase_Letter
Lu Uppercase_Letter
M Mark Combining_Mark
Mc Spacing_Mark
Me Enclosing_Mark
Mn Nonspacing_Mark
N Number
Nd Decimal_Number digit
Nl Letter_Number
No Other_Number
P Punctuation punct
Pc Connector_Punctuation
Pd Dash_Punctuation
Pe Close_Punctuation
Pf Final_Punctuation
Pi Initial_Punctuation
Po Other_Punctuation
Ps Open_Punctuation
S Symbol
Sc Currency_Symbol
Sk Modifier_Symbol
Sm Math_Symbol
So Other_Symbol
Z Separator
Zl Line_Separator
Zp Paragraph_Separator
Zs Space_Separator
ASCII
ASCII_Hex_Digit AHex
Alphabetic Alpha
Any
Assigned
Bidi_Control Bidi_C
Bidi_Mirrored Bidi_M
Case_Ignorable CI
Cased
Changes_When_Casefolded CWCF
Changes_When_Casemapped CWCM
Changes_When_Lowercased CWL
Changes_When_NFKC_Casefolded CWKCF
Changes_When_Titlecased CWT
Changes_When_Uppercased CWU
Dash
Default_Ignorable_Code_Point DI
Deprecated Dep
Diacritic Dia
Emoji
Emoji_Component EComp
Emoji_Modifier EMod
Emoji_Modifier_Base EBase
Emoji_Presentation EPres
Extended_Pictographic ExtPict
Extender Ext
Grapheme_Base Gr_Base
Grapheme_Extend Gr_Ext
Hex_Digit Hex
IDS_Binary_Operator IDSB
IDS_Trinary_Operator IDST
ID_Continue IDC
ID_Start IDS
Ideographic Ideo
Join_Control Join_C
Logical_Order_Exception LOE
Lowercase Lower
Math
Noncharacter_Code_Point NChar
Pattern_Syntax Pat_Syn
Pattern_White_Space Pat_WS
Quotation_Mark QMark
Radical
Regional_Indicator RI
Sentence_Terminal STerm
Soft_Dotted SD
Terminal_Punctuation Term
Unified_Ideograph UIdeo
Uppercase Upper
Variation_Selector VS
White_Space space
XID_Continue XIDC
XID_Start XIDS`.split(/\s/).map((e) => [me(e), e])
), rn = /* @__PURE__ */ new Map([
  ["s", b(383)],
  // s, ſ
  [b(383), "s"]
  // ſ, s
]), tn = /* @__PURE__ */ new Map([
  [b(223), b(7838)],
  // ß, ẞ
  [b(107), b(8490)],
  // k, K (Kelvin)
  [b(229), b(8491)],
  // å, Å (Angstrom)
  [b(969), b(8486)]
  // ω, Ω (Ohm)
]), nn = new Map([
  O(453),
  O(456),
  O(459),
  O(498),
  ...Ee(8072, 8079),
  ...Ee(8088, 8095),
  ...Ee(8104, 8111),
  O(8124),
  O(8140),
  O(8188)
]), sn = /* @__PURE__ */ new Map([
  ["alnum", h`[\p{Alpha}\p{Nd}]`],
  ["alpha", h`\p{Alpha}`],
  ["ascii", h`\p{ASCII}`],
  ["blank", h`[\p{Zs}\t]`],
  ["cntrl", h`\p{Cc}`],
  ["digit", h`\p{Nd}`],
  ["graph", h`[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]`],
  ["lower", h`\p{Lower}`],
  ["print", h`[[\P{space}&&\P{Cc}&&\P{Cn}&&\P{Cs}]\p{Zs}]`],
  ["punct", h`[\p{P}\p{S}]`],
  // Updated value from Onig 6.9.9; changed from Unicode `\p{punct}`
  ["space", h`\p{space}`],
  ["upper", h`\p{Upper}`],
  ["word", h`[\p{Alpha}\p{M}\p{Nd}\p{Pc}]`],
  ["xdigit", h`\p{AHex}`]
]);
function on(e, r) {
  const t = [];
  for (let n = e; n <= r; n++)
    t.push(n);
  return t;
}
function O(e) {
  const r = b(e);
  return [r.toLowerCase(), r];
}
function Ee(e, r) {
  return on(e, r).map((t) => O(t));
}
var Sr = /* @__PURE__ */ new Set([
  "Lower",
  "Lowercase",
  "Upper",
  "Uppercase",
  "Ll",
  "Lowercase_Letter",
  "Lt",
  "Titlecase_Letter",
  "Lu",
  "Uppercase_Letter"
  // The `Changes_When_*` properties (and their aliases) could be included, but they're very rare.
  // Some other properties include a handful of chars with specific cases only, but these chars are
  // generally extreme edge cases and using such properties case insensitively generally produces
  // undesired behavior anyway
]);
function an(e, r) {
  const t = {
    // A couple edge cases exist where options `accuracy` and `bestEffortTarget` are used:
    // - `CharacterSet` kind `text_segment` (`\X`): An exact representation would require heavy
    //   Unicode data; a best-effort approximation requires knowing the target.
    // - `CharacterSet` kind `posix` with values `graph` and `print`: Their complex Unicode
    //   representations would be hard to change to ASCII versions after the fact in the generator
    //   based on `target`/`accuracy`, so produce the appropriate structure here.
    accuracy: "default",
    asciiWordBoundaries: !1,
    avoidSubclass: !1,
    bestEffortTarget: "ES2025",
    ...r
  };
  _r(e);
  const n = {
    accuracy: t.accuracy,
    asciiWordBoundaries: t.asciiWordBoundaries,
    avoidSubclass: t.avoidSubclass,
    flagDirectivesByAlt: /* @__PURE__ */ new Map(),
    jsGroupNameMap: /* @__PURE__ */ new Map(),
    minTargetEs2024: Ge(t.bestEffortTarget, "ES2024"),
    passedLookbehind: !1,
    strategy: null,
    // Subroutines can appear before the groups they ref, so collect reffed nodes for a second pass 
    subroutineRefMap: /* @__PURE__ */ new Map(),
    supportedGNodes: /* @__PURE__ */ new Set(),
    digitIsAscii: e.flags.digitIsAscii,
    spaceIsAscii: e.flags.spaceIsAscii,
    wordIsAscii: e.flags.wordIsAscii
  };
  ae(e, un, n);
  const s = {
    dotAll: e.flags.dotAll,
    ignoreCase: e.flags.ignoreCase
  }, o = {
    currentFlags: s,
    prevFlags: null,
    globalFlags: s,
    groupOriginByCopy: /* @__PURE__ */ new Map(),
    groupsByName: /* @__PURE__ */ new Map(),
    multiplexCapturesToLeftByRef: /* @__PURE__ */ new Map(),
    openRefs: /* @__PURE__ */ new Map(),
    reffedNodesByReferencer: /* @__PURE__ */ new Map(),
    subroutineRefMap: n.subroutineRefMap
  };
  ae(e, cn, o);
  const a = {
    groupsByName: o.groupsByName,
    highestOrphanBackref: 0,
    numCapturesToLeft: 0,
    reffedNodesByReferencer: o.reffedNodesByReferencer
  };
  return ae(e, ln, a), e._originMap = o.groupOriginByCopy, e._strategy = n.strategy, e;
}
var un = {
  AbsenceFunction({ node: e, parent: r, replaceWith: t }) {
    const { body: n, kind: s } = e;
    if (s === "repeater") {
      const o = L();
      o.body[0].body.push(
        // Insert own alts as `body`
        W({ negate: !0, body: n }),
        te("Any")
      );
      const a = L();
      a.body[0].body.push(
        br("greedy", 0, 1 / 0, o)
      ), t(C(a, r), { traverse: !0 });
    } else
      throw new Error('Unsupported absence function "(?~|"');
  },
  Alternative: {
    enter({ node: e, parent: r, key: t }, { flagDirectivesByAlt: n }) {
      const s = e.body.filter((o) => o.kind === "flags");
      for (let o = t + 1; o < r.body.length; o++) {
        const a = r.body[o];
        ie(n, a, []).push(...s);
      }
    },
    exit({ node: e }, { flagDirectivesByAlt: r }) {
      var t;
      if ((t = r.get(e)) != null && t.length) {
        const n = Mr(r.get(e));
        if (n) {
          const s = L({ flags: n });
          s.body[0].body = e.body, e.body = [C(s, e)];
        }
      }
    }
  },
  Assertion({ node: e, parent: r, key: t, container: n, root: s, remove: o, replaceWith: a }, i) {
    const { kind: u, negate: c } = e, { asciiWordBoundaries: l, avoidSubclass: p, supportedGNodes: f, wordIsAscii: g } = i;
    if (u === "text_segment_boundary")
      throw new Error(`Unsupported text segment boundary "\\${c ? "Y" : "y"}"`);
    if (u === "line_end")
      a(C(W({ body: [
        q({ body: [Ne("string_end")] }),
        q({ body: [he(10)] })
        // `\n`
      ] }), r));
    else if (u === "line_start")
      a(C(G(h`(?<=\A|\n(?!\z))`, { skipLookbehindValidation: !0 }), r));
    else if (u === "search_start")
      if (f.has(e))
        s.flags.sticky = !0, o();
      else {
        const d = n[t - 1];
        if (d && mn(d))
          a(C(W({ negate: !0 }), r));
        else {
          if (p)
            throw new Error(h`Uses "\G" in a way that requires a subclass`);
          a(D(Ne("string_start"), r)), i.strategy = "clip_search";
        }
      }
    else if (!(u === "string_end" || u === "string_start"))
      if (u === "string_end_newline")
        a(C(G(h`(?=\n?\z)`), r));
      else if (u === "word_boundary") {
        if (!g && !l) {
          const d = `(?:(?<=${F})(?!${F})|(?<!${F})(?=${F}))`, m = `(?:(?<=${F})(?=${F})|(?<!${F})(?!${F}))`;
          a(C(G(c ? m : d), r));
        }
      } else
        throw new Error(`Unexpected assertion kind "${u}"`);
  },
  Backreference({ node: e }, { jsGroupNameMap: r }) {
    let { ref: t } = e;
    typeof t == "string" && !Ie(t) && (t = Ae(t, r), e.ref = t);
  },
  CapturingGroup({ node: e }, { jsGroupNameMap: r, subroutineRefMap: t }) {
    let { name: n } = e;
    n && !Ie(n) && (n = Ae(n, r), e.name = n), t.set(e.number, e), n && t.set(n, e);
  },
  CharacterClassRange({ node: e, parent: r, replaceWith: t }) {
    if (r.kind === "intersection") {
      const n = de({ body: [e] });
      t(C(n, r), { traverse: !0 });
    }
  },
  CharacterSet({ node: e, parent: r, replaceWith: t }, { accuracy: n, minTargetEs2024: s, digitIsAscii: o, spaceIsAscii: a, wordIsAscii: i }) {
    const { kind: u, negate: c, value: l } = e;
    if (o && (u === "digit" || l === "digit")) {
      t(D(Le("digit", { negate: c }), r));
      return;
    }
    if (a && (u === "space" || l === "space")) {
      t(C(ve(G(Yt), c), r));
      return;
    }
    if (i && (u === "word" || l === "word")) {
      t(D(Le("word", { negate: c }), r));
      return;
    }
    if (u === "any")
      t(D(te("Any"), r));
    else if (u === "digit")
      t(D(te("Nd", { negate: c }), r));
    else if (u !== "dot")
      if (u === "text_segment") {
        if (n === "strict")
          throw new Error(h`Use of "\X" requires non-strict accuracy`);
        const p = "\\p{Emoji}(?:\\p{EMod}|\\uFE0F\\u20E3?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})?", f = h`\p{RI}{2}|${p}(?:\u200D${p})*`;
        t(C(G(
          // Close approximation of an extended grapheme cluster; see <unicode.org/reports/tr29/>
          h`(?>\r\n|${s ? h`\p{RGI_Emoji}` : f}|\P{M}\p{M}*)`,
          // Allow JS property `RGI_Emoji` through
          { skipPropertyNameValidation: !0 }
        ), r));
      } else if (u === "hex")
        t(D(te("AHex", { negate: c }), r));
      else if (u === "newline")
        t(C(G(c ? `[^
]` : `(?>\r
?|[
\v\f\u2028\u2029])`), r));
      else if (u === "posix")
        if (!s && (l === "graph" || l === "print")) {
          if (n === "strict")
            throw new Error(`POSIX class "${l}" requires min target ES2024 or non-strict accuracy`);
          let p = {
            graph: "!-~",
            print: " -~"
          }[l];
          c && (p = `\0-${b(p.codePointAt(0) - 1)}${b(p.codePointAt(2) + 1)}-􏿿`), t(C(G(`[${p}]`), r));
        } else
          t(C(ve(G(sn.get(l)), c), r));
      else if (u === "property")
        Te.has(me(l)) || (e.key = "sc");
      else if (u === "space")
        t(D(te("space", { negate: c }), r));
      else if (u === "word")
        t(C(ve(G(F), c), r));
      else
        throw new Error(`Unexpected character set kind "${u}"`);
  },
  Directive({ node: e, parent: r, root: t, remove: n, replaceWith: s, removeAllPrevSiblings: o, removeAllNextSiblings: a }) {
    const { kind: i, flags: u } = e;
    if (i === "flags")
      if (!u.enable && !u.disable)
        n();
      else {
        const c = L({ flags: u });
        c.body[0].body = a(), s(C(c, r), { traverse: !0 });
      }
    else if (i === "keep") {
      const c = t.body[0], p = t.body.length === 1 && // Not emulatable if within a `CapturingGroup`
      wr(c, { type: "Group" }) && c.body[0].body.length === 1 ? c.body[0] : t;
      if (r.parent !== p || p.body.length > 1)
        throw new Error(h`Uses "\K" in a way that's unsupported`);
      const f = W({ behind: !0 });
      f.body[0].body = o(), s(C(f, r));
    } else
      throw new Error(`Unexpected directive kind "${i}"`);
  },
  Flags({ node: e, parent: r }) {
    if (e.posixIsAscii)
      throw new Error('Unsupported flag "P"');
    if (e.textSegmentMode === "word")
      throw new Error('Unsupported flag "y{w}"');
    [
      "digitIsAscii",
      // Flag D
      "extended",
      // Flag x
      "posixIsAscii",
      // Flag P
      "spaceIsAscii",
      // Flag S
      "wordIsAscii",
      // Flag W
      "textSegmentMode"
      // Flag y{g} or y{w}
    ].forEach((t) => delete e[t]), Object.assign(e, {
      // JS flag g; no Onig equiv
      global: !1,
      // JS flag d; no Onig equiv
      hasIndices: !1,
      // JS flag m; no Onig equiv but its behavior is always on in Onig. Onig's only line break
      // char is line feed, unlike JS, so this flag isn't used since it would produce inaccurate
      // results (also allows `^` and `$` to be used in the generator for string start and end)
      multiline: !1,
      // JS flag y; no Onig equiv, but used for `\G` emulation
      sticky: e.sticky ?? !1
      // Note: Regex+ doesn't allow explicitly adding flags it handles implicitly, so leave out
      // properties `unicode` (JS flag u) and `unicodeSets` (JS flag v). Keep the existing values
      // for `ignoreCase` (flag i) and `dotAll` (JS flag s, but Onig flag m)
    }), r.options = {
      disable: {
        // Onig uses different rules for flag x than Regex+, so disable the implicit flag
        x: !0,
        // Onig has no flag to control "named capture only" mode but contextually applies its
        // behavior when named capturing is used, so disable Regex+'s implicit flag for it
        n: !0
      },
      force: {
        // Always add flag v because we're generating an AST that relies on it (it enables JS
        // support for Onig features nested classes, intersection, Unicode properties, etc.).
        // However, the generator might disable flag v based on its `target` option
        v: !0
      }
    };
  },
  Group({ node: e }) {
    if (!e.flags)
      return;
    const { enable: r, disable: t } = e.flags;
    r != null && r.extended && delete r.extended, t != null && t.extended && delete t.extended, r != null && r.dotAll && (t != null && t.dotAll) && delete r.dotAll, r != null && r.ignoreCase && (t != null && t.ignoreCase) && delete r.ignoreCase, r && !Object.keys(r).length && delete e.flags.enable, t && !Object.keys(t).length && delete e.flags.disable, !e.flags.enable && !e.flags.disable && delete e.flags;
  },
  LookaroundAssertion({ node: e }, r) {
    const { kind: t } = e;
    t === "lookbehind" && (r.passedLookbehind = !0);
  },
  NamedCallout({ node: e, parent: r, replaceWith: t }) {
    const { kind: n } = e;
    if (n === "fail")
      t(C(W({ negate: !0 }), r));
    else
      throw new Error(`Unsupported named callout "(*${n.toUpperCase()}"`);
  },
  Quantifier({ node: e }) {
    if (e.body.type === "Quantifier") {
      const r = L();
      r.body[0].body.push(e.body), e.body = C(r, e);
    }
  },
  Regex: {
    enter({ node: e }, { supportedGNodes: r }) {
      const t = [];
      let n = !1, s = !1;
      for (const o of e.body)
        if (o.body.length === 1 && o.body[0].kind === "search_start")
          o.body.pop();
        else {
          const a = Fr(o.body);
          a ? (n = !0, Array.isArray(a) ? t.push(...a) : t.push(a)) : s = !0;
        }
      n && !s && t.forEach((o) => r.add(o));
    },
    exit(e, { accuracy: r, passedLookbehind: t, strategy: n }) {
      if (r === "strict" && t && n)
        throw new Error(h`Uses "\G" in a way that requires non-strict accuracy`);
    }
  },
  Subroutine({ node: e }, { jsGroupNameMap: r }) {
    let { ref: t } = e;
    typeof t == "string" && !Ie(t) && (t = Ae(t, r), e.ref = t);
  }
}, cn = {
  Backreference({ node: e }, { multiplexCapturesToLeftByRef: r, reffedNodesByReferencer: t }) {
    const { orphan: n, ref: s } = e;
    n || t.set(e, [...r.get(s).map(({ node: o }) => o)]);
  },
  CapturingGroup: {
    enter({
      node: e,
      parent: r,
      replaceWith: t,
      skip: n
    }, {
      groupOriginByCopy: s,
      groupsByName: o,
      multiplexCapturesToLeftByRef: a,
      openRefs: i,
      reffedNodesByReferencer: u
    }) {
      const c = s.get(e);
      if (c && i.has(e.number)) {
        const p = D(or(e.number), r);
        u.set(p, i.get(e.number)), t(p);
        return;
      }
      i.set(e.number, e), a.set(e.number, []), e.name && ie(a, e.name, []);
      const l = a.get(e.name ?? e.number);
      for (let p = 0; p < l.length; p++) {
        const f = l[p];
        if (
          // This group is from subroutine expansion, and there's a multiplex value from either the
          // origin node or a prior subroutine expansion group with the same origin
          c === f.node || c && c === f.origin || // This group is not from subroutine expansion, and it comes after a subroutine expansion
          // group that refers to this group
          e === f.origin
        ) {
          l.splice(p, 1);
          break;
        }
      }
      if (a.get(e.number).push({ node: e, origin: c }), e.name && a.get(e.name).push({ node: e, origin: c }), e.name) {
        const p = ie(o, e.name, /* @__PURE__ */ new Map());
        let f = !1;
        if (c)
          f = !0;
        else
          for (const g of p.values())
            if (!g.hasDuplicateNameToRemove) {
              f = !0;
              break;
            }
        o.get(e.name).set(e, { node: e, hasDuplicateNameToRemove: f });
      }
    },
    exit({ node: e }, { openRefs: r }) {
      r.delete(e.number);
    }
  },
  Group: {
    enter({ node: e }, r) {
      r.prevFlags = r.currentFlags, e.flags && (r.currentFlags = ge(r.currentFlags, e.flags));
    },
    exit(e, r) {
      r.currentFlags = r.prevFlags;
    }
  },
  Subroutine({ node: e, parent: r, replaceWith: t }, n) {
    const { isRecursive: s, ref: o } = e;
    if (s) {
      let l = r;
      for (; (l = l.parent) && !(l.type === "CapturingGroup" && (l.name === o || l.number === o)); )
        ;
      n.reffedNodesByReferencer.set(e, l);
      return;
    }
    const a = n.subroutineRefMap.get(o), i = o === 0, u = i ? or(0) : (
      // The reffed group might itself contain subroutines, which are expanded during sub-traversal
      Nr(a, n.groupOriginByCopy, null)
    );
    let c = u;
    if (!i) {
      const l = Mr(dn(
        a,
        (f) => f.type === "Group" && !!f.flags
      )), p = l ? ge(n.globalFlags, l) : n.globalFlags;
      pn(p, n.currentFlags) || (c = L({
        flags: gn(p)
      }), c.body[0].body.push(u));
    }
    t(C(c, r), { traverse: !i });
  }
}, ln = {
  Backreference({ node: e, parent: r, replaceWith: t }, n) {
    if (e.orphan) {
      n.highestOrphanBackref = Math.max(n.highestOrphanBackref, e.ref);
      return;
    }
    const o = n.reffedNodesByReferencer.get(e).filter((a) => fn(a, e));
    if (!o.length)
      t(C(W({ negate: !0 }), r));
    else if (o.length > 1) {
      const a = L({
        atomic: !0,
        body: o.reverse().map((i) => q({
          body: [Me(i.number)]
        }))
      });
      t(C(a, r));
    } else
      e.ref = o[0].number;
  },
  CapturingGroup({ node: e }, r) {
    e.number = ++r.numCapturesToLeft, e.name && r.groupsByName.get(e.name).get(e).hasDuplicateNameToRemove && delete e.name;
  },
  Regex: {
    exit({ node: e }, r) {
      const t = Math.max(r.highestOrphanBackref - r.numCapturesToLeft, 0);
      for (let n = 0; n < t; n++) {
        const s = Cr();
        e.body.at(-1).body.push(s);
      }
    }
  },
  Subroutine({ node: e }, r) {
    !e.isRecursive || e.ref === 0 || (e.ref = r.reffedNodesByReferencer.get(e).number);
  }
};
function _r(e) {
  ae(e, {
    "*"({ node: r, parent: t }) {
      r.parent = t;
    }
  });
}
function pn(e, r) {
  return e.dotAll === r.dotAll && e.ignoreCase === r.ignoreCase;
}
function fn(e, r) {
  let t = r;
  do {
    if (t.type === "Regex")
      return !1;
    if (t.type === "Alternative")
      continue;
    if (t === e)
      return !1;
    const n = Lr(t.parent);
    for (const s of n) {
      if (s === t)
        break;
      if (s === e || Gr(s, e))
        return !0;
    }
  } while (t = t.parent);
  throw new Error("Unexpected path");
}
function Nr(e, r, t, n) {
  const s = Array.isArray(e) ? [] : {};
  for (const [o, a] of Object.entries(e))
    o === "parent" ? s.parent = Array.isArray(t) ? n : t : a && typeof a == "object" ? s[o] = Nr(a, r, s, t) : (o === "type" && a === "CapturingGroup" && r.set(s, r.get(e) ?? e), s[o] = a);
  return s;
}
function or(e) {
  const r = xr(e);
  return r.isRecursive = !0, r;
}
function dn(e, r) {
  const t = [];
  for (; e = e.parent; )
    (!r || r(e)) && t.push(e);
  return t;
}
function Ae(e, r) {
  if (r.has(e))
    return r.get(e);
  const t = `$${r.size}_${e.replace(/^[^$_\p{IDS}]|[^$\u200C\u200D\p{IDC}]/ug, "_")}`;
  return r.set(e, t), t;
}
function Mr(e) {
  const r = ["dotAll", "ignoreCase"], t = { enable: {}, disable: {} };
  return e.forEach(({ flags: n }) => {
    r.forEach((s) => {
      var o, a;
      (o = n.enable) != null && o[s] && (delete t.disable[s], t.enable[s] = !0), (a = n.disable) != null && a[s] && (t.disable[s] = !0);
    });
  }), Object.keys(t.enable).length || delete t.enable, Object.keys(t.disable).length || delete t.disable, t.enable || t.disable ? t : null;
}
function gn({ dotAll: e, ignoreCase: r }) {
  const t = {};
  return (e || r) && (t.enable = {}, e && (t.enable.dotAll = !0), r && (t.enable.ignoreCase = !0)), (!e || !r) && (t.disable = {}, !e && (t.disable.dotAll = !0), !r && (t.disable.ignoreCase = !0)), t;
}
function Lr(e) {
  if (!e)
    throw new Error("Node expected");
  const { body: r } = e;
  return Array.isArray(r) ? r : r ? [r] : null;
}
function Fr(e) {
  const r = e.find((t) => t.kind === "search_start" || wn(t, { negate: !1 }) || !hn(t));
  if (!r)
    return null;
  if (r.kind === "search_start")
    return r;
  if (r.type === "LookaroundAssertion")
    return r.body[0].body[0];
  if (r.type === "CapturingGroup" || r.type === "Group") {
    const t = [];
    for (const n of r.body) {
      const s = Fr(n.body);
      if (!s)
        return null;
      Array.isArray(s) ? t.push(...s) : t.push(s);
    }
    return t;
  }
  return null;
}
function Gr(e, r) {
  const t = Lr(e) ?? [];
  for (const n of t)
    if (n === r || Gr(n, r))
      return !0;
  return !1;
}
function hn({ type: e }) {
  return e === "Assertion" || e === "Directive" || e === "LookaroundAssertion";
}
function mn(e) {
  const r = [
    "Character",
    "CharacterClass",
    "CharacterSet"
  ];
  return r.includes(e.type) || e.type === "Quantifier" && e.min && r.includes(e.body.type);
}
function wn(e, r) {
  const t = {
    negate: null,
    ...r
  };
  return e.type === "LookaroundAssertion" && (t.negate === null || e.negate === t.negate) && e.body.length === 1 && wr(e.body[0], {
    type: "Assertion",
    kind: "search_start"
  });
}
function Ie(e) {
  return /^[$_\p{IDS}][$\u200C\u200D\p{IDC}]*$/u.test(e);
}
function G(e, r) {
  const n = yr(e, {
    ...r,
    // Providing a custom set of Unicode property names avoids converting some JS Unicode
    // properties (ex: `\p{Alpha}`) to Onig POSIX classes
    unicodePropertyMap: Te
  }).body;
  return n.length > 1 || n[0].body.length > 1 ? L({ body: n }) : n[0].body[0];
}
function ve(e, r) {
  return e.negate = r, e;
}
function D(e, r) {
  return e.parent = r, e;
}
function C(e, r) {
  return _r(e), e.parent = r, e;
}
function yn(e, r) {
  const t = Ir(r), n = Ge(t.target, "ES2024"), s = Ge(t.target, "ES2025"), o = t.rules.recursionLimit;
  if (!Number.isInteger(o) || o < 2 || o > 20)
    throw new Error("Invalid recursionLimit; use 2-20");
  let a = null, i = null;
  if (!s) {
    const g = [e.flags.ignoreCase];
    ae(e, Cn, {
      getCurrentModI: () => g.at(-1),
      popModI() {
        g.pop();
      },
      pushModI(d) {
        g.push(d);
      },
      setHasCasedChar() {
        g.at(-1) ? a = !0 : i = !0;
      }
    });
  }
  const u = {
    dotAll: e.flags.dotAll,
    // - Turn global flag i on if a case insensitive node was used and no case sensitive nodes were
    //   used (to avoid unnecessary node expansion).
    // - Turn global flag i off if a case sensitive node was used (since case sensitivity can't be
    //   forced without the use of ES2025 flag groups)
    ignoreCase: !!((e.flags.ignoreCase || a) && !i)
  };
  let c = e;
  const l = {
    accuracy: t.accuracy,
    appliedGlobalFlags: u,
    captureMap: /* @__PURE__ */ new Map(),
    currentFlags: {
      dotAll: e.flags.dotAll,
      ignoreCase: e.flags.ignoreCase
    },
    inCharClass: !1,
    lastNode: c,
    originMap: e._originMap,
    recursionLimit: o,
    useAppliedIgnoreCase: !!(!s && a && i),
    useFlagMods: s,
    useFlagV: n,
    verbose: t.verbose
  };
  function p(g) {
    return l.lastNode = c, c = g, Jt(bn[g.type], `Unexpected node type "${g.type}"`)(g, l, p);
  }
  const f = {
    pattern: e.body.map(p).join("|"),
    // Could reset `lastNode` at this point via `lastNode = ast`, but it isn't needed by flags
    flags: p(e.flags),
    options: { ...e.options }
  };
  return n || (delete f.options.force.v, f.options.disable.v = !0, f.options.unicodeSetsPlugin = null), f._captureTransfers = /* @__PURE__ */ new Map(), f._hiddenCaptures = [], l.captureMap.forEach((g, d) => {
    g.hidden && f._hiddenCaptures.push(d), g.transferTo && ie(f._captureTransfers, g.transferTo, []).push(d);
  }), f;
}
var Cn = {
  "*": {
    enter({ node: e }, r) {
      if (ir(e)) {
        const t = r.getCurrentModI();
        r.pushModI(
          e.flags ? ge({ ignoreCase: t }, e.flags).ignoreCase : t
        );
      }
    },
    exit({ node: e }, r) {
      ir(e) && r.popModI();
    }
  },
  Backreference(e, r) {
    r.setHasCasedChar();
  },
  Character({ node: e }, r) {
    Be(b(e.value)) && r.setHasCasedChar();
  },
  CharacterClassRange({ node: e, skip: r }, t) {
    r(), Pr(e, { firstOnly: !0 }).length && t.setHasCasedChar();
  },
  CharacterSet({ node: e }, r) {
    e.kind === "property" && Sr.has(e.value) && r.setHasCasedChar();
  }
}, bn = {
  /**
  @param {AlternativeNode} node
  */
  Alternative({ body: e }, r, t) {
    return e.map(t).join("");
  },
  /**
  @param {AssertionNode} node
  */
  Assertion({ kind: e, negate: r }) {
    if (e === "string_end")
      return "$";
    if (e === "string_start")
      return "^";
    if (e === "word_boundary")
      return r ? h`\B` : h`\b`;
    throw new Error(`Unexpected assertion kind "${e}"`);
  },
  /**
  @param {BackreferenceNode} node
  */
  Backreference({ ref: e }, r) {
    if (typeof e != "number")
      throw new Error("Unexpected named backref in transformed AST");
    if (!r.useFlagMods && r.accuracy === "strict" && r.currentFlags.ignoreCase && !r.captureMap.get(e).ignoreCase)
      throw new Error("Use of case-insensitive backref to case-sensitive group requires target ES2025 or non-strict accuracy");
    return "\\" + e;
  },
  /**
  @param {CapturingGroupNode} node
  */
  CapturingGroup(e, r, t) {
    const { body: n, name: s, number: o } = e, a = { ignoreCase: r.currentFlags.ignoreCase }, i = r.originMap.get(e);
    return i && (a.hidden = !0, o > i.number && (a.transferTo = i.number)), r.captureMap.set(o, a), `(${s ? `?<${s}>` : ""}${n.map(t).join("|")})`;
  },
  /**
  @param {CharacterNode} node
  */
  Character({ value: e }, r) {
    const t = b(e), n = Y(e, {
      escDigit: r.lastNode.type === "Backreference",
      inCharClass: r.inCharClass,
      useFlagV: r.useFlagV
    });
    if (n !== t)
      return n;
    if (r.useAppliedIgnoreCase && r.currentFlags.ignoreCase && Be(t)) {
      const s = vr(t);
      return r.inCharClass ? s.join("") : s.length > 1 ? `[${s.join("")}]` : s[0];
    }
    return t;
  },
  /**
  @param {CharacterClassNode} node
  */
  CharacterClass(e, r, t) {
    const { kind: n, negate: s, parent: o } = e;
    let { body: a } = e;
    if (n === "intersection" && !r.useFlagV)
      throw new Error("Use of character class intersection requires min target ES2024");
    U.bugFlagVLiteralHyphenIsRange && r.useFlagV && a.some(ur) && (a = [he(45), ...a.filter((c) => !ur(c))]);
    const i = () => `[${s ? "^" : ""}${a.map(t).join(n === "intersection" ? "&&" : "")}]`;
    if (!r.inCharClass) {
      if (
        // Already established `kind !== 'intersection'` if `!state.useFlagV`; don't check again
        (!r.useFlagV || U.bugNestedClassIgnoresNegation) && !s
      ) {
        const l = a.filter(
          (p) => p.type === "CharacterClass" && p.kind === "union" && p.negate
        );
        if (l.length) {
          const p = L(), f = p.body[0];
          return p.parent = o, f.parent = p, a = a.filter((g) => !l.includes(g)), e.body = a, a.length ? (e.parent = f, f.body.push(e)) : p.body.pop(), l.forEach((g) => {
            const d = q({ body: [g] });
            g.parent = d, d.parent = p, p.body.push(d);
          }), t(p);
        }
      }
      r.inCharClass = !0;
      const c = i();
      return r.inCharClass = !1, c;
    }
    const u = a[0];
    if (
      // Already established that the parent is a char class via `inCharClass`; don't check again
      n === "union" && !s && u && // Allows many nested classes to work with `target` ES2018 which doesn't support nesting
      ((!r.useFlagV || !r.verbose) && o.kind === "union" && !(U.bugFlagVLiteralHyphenIsRange && r.useFlagV) || !r.verbose && o.kind === "intersection" && // JS doesn't allow intersection with union or ranges
      a.length === 1 && u.type !== "CharacterClassRange")
    )
      return a.map(t).join("");
    if (!r.useFlagV && o.type === "CharacterClass")
      throw new Error("Uses nested character class in a way that requires min target ES2024");
    return i();
  },
  /**
  @param {CharacterClassRangeNode} node
  */
  CharacterClassRange(e, r) {
    const t = e.min.value, n = e.max.value, s = {
      escDigit: !1,
      inCharClass: !0,
      useFlagV: r.useFlagV
    }, o = Y(t, s), a = Y(n, s), i = /* @__PURE__ */ new Set();
    if (r.useAppliedIgnoreCase && r.currentFlags.ignoreCase) {
      const u = Pr(e);
      An(u).forEach((l) => {
        i.add(
          Array.isArray(l) ? `${Y(l[0], s)}-${Y(l[1], s)}` : Y(l, s)
        );
      });
    }
    return `${o}-${a}${[...i].join("")}`;
  },
  /**
  @param {CharacterSetNode} node
  */
  CharacterSet({ kind: e, negate: r, value: t, key: n }, s) {
    if (e === "dot")
      return s.currentFlags.dotAll ? s.appliedGlobalFlags.dotAll || s.useFlagMods ? "." : "[^]" : (
        // Onig's only line break char is line feed, unlike JS
        h`[^\n]`
      );
    if (e === "digit")
      return r ? h`\D` : h`\d`;
    if (e === "property") {
      if (s.useAppliedIgnoreCase && s.currentFlags.ignoreCase && Sr.has(t))
        throw new Error(`Unicode property "${t}" can't be case-insensitive when other chars have specific case`);
      return `${r ? h`\P` : h`\p`}{${n ? `${n}=` : ""}${t}}`;
    }
    if (e === "word")
      return r ? h`\W` : h`\w`;
    throw new Error(`Unexpected character set kind "${e}"`);
  },
  /**
  @param {FlagsNode} node
  */
  Flags(e, r) {
    return (
      // The transformer should never turn on the properties for flags d, g, m since Onig doesn't
      // have equivs. Flag m is never used since Onig uses different line break chars than JS
      // (node.hasIndices ? 'd' : '') +
      // (node.global ? 'g' : '') +
      // (node.multiline ? 'm' : '') +
      (r.appliedGlobalFlags.ignoreCase ? "i" : "") + (e.dotAll ? "s" : "") + (e.sticky ? "y" : "")
    );
  },
  /**
  @param {GroupNode} node
  */
  Group({ atomic: e, body: r, flags: t, parent: n }, s, o) {
    const a = s.currentFlags;
    t && (s.currentFlags = ge(a, t));
    const i = r.map(o).join("|"), u = !s.verbose && r.length === 1 && // Single alt
    n.type !== "Quantifier" && !e && (!s.useFlagMods || !t) ? i : `(?${In(e, t, s.useFlagMods)}${i})`;
    return s.currentFlags = a, u;
  },
  /**
  @param {LookaroundAssertionNode} node
  */
  LookaroundAssertion({ body: e, kind: r, negate: t }, n, s) {
    return `(?${`${r === "lookahead" ? "" : "<"}${t ? "!" : "="}`}${e.map(s).join("|")})`;
  },
  /**
  @param {QuantifierNode} node
  */
  Quantifier(e, r, t) {
    return t(e.body) + vn(e);
  },
  /**
  @param {SubroutineNode & {isRecursive: true}} node
  */
  Subroutine({ isRecursive: e, ref: r }, t) {
    if (!e)
      throw new Error("Unexpected non-recursive subroutine in transformed AST");
    const n = t.recursionLimit;
    return r === 0 ? `(?R=${n})` : h`\g<${r}&R=${n}>`;
  }
}, xn = /* @__PURE__ */ new Set([
  "$",
  "(",
  ")",
  "*",
  "+",
  ".",
  "?",
  "[",
  "\\",
  "]",
  "^",
  "{",
  "|",
  "}"
]), kn = /* @__PURE__ */ new Set([
  "-",
  "\\",
  "]",
  "^",
  // Literal `[` doesn't require escaping with flag u, but this can help work around regex source
  // linters and regex syntax processors that expect unescaped `[` to create a nested class
  "["
]), $n = /* @__PURE__ */ new Set([
  "(",
  ")",
  "-",
  "/",
  "[",
  "\\",
  "]",
  "^",
  "{",
  "|",
  "}",
  // Double punctuators; also includes already-listed `-` and `^`
  "!",
  "#",
  "$",
  "%",
  "&",
  "*",
  "+",
  ",",
  ".",
  ":",
  ";",
  "<",
  "=",
  ">",
  "?",
  "@",
  "`",
  "~"
]), ar = /* @__PURE__ */ new Map([
  [9, h`\t`],
  // horizontal tab
  [10, h`\n`],
  // line feed
  [11, h`\v`],
  // vertical tab
  [12, h`\f`],
  // form feed
  [13, h`\r`],
  // carriage return
  [8232, h`\u2028`],
  // line separator
  [8233, h`\u2029`],
  // paragraph separator
  [65279, h`\uFEFF`]
  // ZWNBSP/BOM
]), En = new RegExp("^\\p{Cased}$", "u");
function Be(e) {
  return En.test(e);
}
function Pr(e, r) {
  const t = !!(r != null && r.firstOnly), n = e.min.value, s = e.max.value, o = [];
  if (n < 65 && (s === 65535 || s >= 131071) || n === 65536 && s >= 131071)
    return o;
  for (let a = n; a <= s; a++) {
    const i = b(a);
    if (!Be(i))
      continue;
    const u = vr(i).filter((c) => {
      const l = c.codePointAt(0);
      return l < n || l > s;
    });
    if (u.length && (o.push(...u), t))
      break;
  }
  return o;
}
function Y(e, { escDigit: r, inCharClass: t, useFlagV: n }) {
  if (ar.has(e))
    return ar.get(e);
  if (
    // Control chars, etc.; condition modeled on the Chrome developer console's display for strings
    e < 32 || e > 126 && e < 160 || // Unicode planes 4-16; unassigned, special purpose, and private use area
    e > 262143 || // Avoid corrupting a preceding backref by immediately following it with a literal digit
    r && Sn(e)
  )
    return e > 255 ? `\\u{${e.toString(16).toUpperCase()}}` : `\\x${e.toString(16).toUpperCase().padStart(2, "0")}`;
  const s = t ? n ? $n : kn : xn, o = b(e);
  return (s.has(o) ? "\\" : "") + o;
}
function An(e) {
  const r = e.map((s) => s.codePointAt(0)).sort((s, o) => s - o), t = [];
  let n = null;
  for (let s = 0; s < r.length; s++)
    r[s + 1] === r[s] + 1 ? n ?? (n = r[s]) : n === null ? t.push(r[s]) : (t.push([n, r[s]]), n = null);
  return t;
}
function In(e, r, t) {
  if (e)
    return ">";
  let n = "";
  if (r && t) {
    const { enable: s, disable: o } = r;
    n = (s != null && s.ignoreCase ? "i" : "") + (s != null && s.dotAll ? "s" : "") + (o ? "-" : "") + (o != null && o.ignoreCase ? "i" : "") + (o != null && o.dotAll ? "s" : "");
  }
  return `${n}:`;
}
function vn({ kind: e, max: r, min: t }) {
  let n;
  return !t && r === 1 ? n = "?" : !t && r === 1 / 0 ? n = "*" : t === 1 && r === 1 / 0 ? n = "+" : t === r ? n = `{${t}}` : n = `{${t},${r === 1 / 0 ? "" : r}}`, n + {
    greedy: "",
    lazy: "?",
    possessive: "+"
  }[e];
}
function ir({ type: e }) {
  return e === "CapturingGroup" || e === "Group" || e === "LookaroundAssertion";
}
function Sn(e) {
  return e > 47 && e < 58;
}
function ur({ type: e, value: r }) {
  return e === "Character" && r === 45;
}
var T, P, X, B, Z, ue, Pe, Q, _n = (Q = class extends RegExp {
  /**
  @overload
  @param {string} pattern
  @param {string} [flags]
  @param {EmulatedRegExpOptions} [options]
  */
  /**
  @overload
  @param {EmulatedRegExp} pattern
  @param {string} [flags]
  */
  constructor(t, n, s) {
    var r = (...Kn) => (super(...Kn), /**
    Adds support for hidden and transfer captures.
    @param {string} str
    @returns
    */
    V(this, ue), /**
    @type {Map<number, {
      hidden?: true;
      transferTo?: number;
    }>}
    */
    V(this, T, /* @__PURE__ */ new Map()), /**
    @type {RegExp | EmulatedRegExp | null}
    */
    V(this, P, null), /**
    @type {string}
    */
    V(this, X, void 0), /**
    @type {Map<number, string>?}
    */
    V(this, B, null), /**
    @type {string?}
    */
    V(this, Z, null), /**
    Can be used to serialize the instance.
    @type {EmulatedRegExpOptions}
    */
    ye(this, "rawOptions", {}), this);
    const o = !!(s != null && s.lazyCompile);
    if (t instanceof RegExp) {
      if (s)
        throw new Error("Cannot provide options when copying a regexp");
      const a = t;
      r(a, n), M(this, X, a.source), a instanceof Q && (M(this, T, $(a, T)), M(this, B, $(a, B)), M(this, Z, $(a, Z)), this.rawOptions = a.rawOptions);
    } else {
      const a = {
        hiddenCaptures: [],
        strategy: null,
        transfers: [],
        ...s
      };
      r(o ? "" : t, n), M(this, X, t), M(this, T, Mn(a.hiddenCaptures, a.transfers)), M(this, Z, a.strategy), this.rawOptions = s ?? {};
    }
    o || M(this, P, this);
  }
  // Override the getter with one that works with lazy-compiled regexes
  get source() {
    return $(this, X) || "(?:)";
  }
  /**
  Called internally by all String/RegExp methods that use regexes.
  @override
  @param {string} str
  @returns {RegExpExecArray?}
  */
  exec(t) {
    if (!$(this, P)) {
      const { lazyCompile: o, ...a } = this.rawOptions;
      M(this, P, new Q($(this, X), this.flags, a));
    }
    const n = this.global || this.sticky, s = this.lastIndex;
    if ($(this, Z) === "clip_search" && n && s) {
      this.lastIndex = 0;
      const o = be(this, ue, Pe).call(this, t.slice(s));
      return o && (Nn(o, s, t, this.hasIndices), this.lastIndex += s), o;
    }
    return be(this, ue, Pe).call(this, t);
  }
}, T = new WeakMap(), P = new WeakMap(), X = new WeakMap(), B = new WeakMap(), Z = new WeakMap(), ue = new WeakSet(), Pe = function(t) {
  $(this, P).lastIndex = this.lastIndex;
  const n = Ve(Q.prototype, this, "exec").call($(this, P), t);
  if (this.lastIndex = $(this, P).lastIndex, !n || !$(this, T).size)
    return n;
  const s = [...n];
  n.length = 1;
  let o;
  this.hasIndices && (o = [...n.indices], n.indices.length = 1);
  const a = [0];
  for (let i = 1; i < s.length; i++) {
    const { hidden: u, transferTo: c } = $(this, T).get(i) ?? {};
    if (u ? a.push(null) : (a.push(n.length), n.push(s[i]), this.hasIndices && n.indices.push(o[i])), c && s[i] !== void 0) {
      const l = a[c];
      if (!l)
        throw new Error(`Invalid capture transfer to "${l}"`);
      if (n[l] = s[i], this.hasIndices && (n.indices[l] = o[i]), n.groups) {
        $(this, B) || M(this, B, Ln(this.source));
        const p = $(this, B).get(c);
        p && (n.groups[p] = s[i], this.hasIndices && (n.indices.groups[p] = o[i]));
      }
    }
  }
  return n;
}, Q);
function Nn(e, r, t, n) {
  if (e.index += r, e.input = t, n) {
    const s = e.indices;
    for (let a = 0; a < s.length; a++) {
      const i = s[a];
      i && (s[a] = [i[0] + r, i[1] + r]);
    }
    const o = s.groups;
    o && Object.keys(o).forEach((a) => {
      const i = o[a];
      i && (o[a] = [i[0] + r, i[1] + r]);
    });
  }
}
function Mn(e, r) {
  const t = /* @__PURE__ */ new Map();
  for (const n of e)
    t.set(n, {
      hidden: !0
    });
  for (const [n, s] of r)
    for (const o of s)
      ie(t, o, {}).transferTo = n;
  return t;
}
function Ln(e) {
  const r = /(?<capture>\((?:\?<(?![=!])(?<name>[^>]+)>|(?!\?)))|\\?./gsu, t = /* @__PURE__ */ new Map();
  let n = 0, s = 0, o;
  for (; o = r.exec(e); ) {
    const { 0: a, groups: { capture: i, name: u } } = o;
    a === "[" ? n++ : n ? a === "]" && n-- : i && (s++, u && t.set(s, u));
  }
  return t;
}
function Fn(e, r) {
  const t = Gn(e, r);
  return t.options ? new _n(t.pattern, t.flags, t.options) : new RegExp(t.pattern, t.flags);
}
function Gn(e, r) {
  const t = Ir(r), n = yr(e, {
    flags: t.flags,
    normalizeUnknownPropertyNames: !0,
    rules: {
      captureGroup: t.rules.captureGroup,
      singleline: t.rules.singleline
    },
    skipBackrefValidation: t.rules.allowOrphanBackrefs,
    unicodePropertyMap: Te
  }), s = an(n, {
    accuracy: t.accuracy,
    asciiWordBoundaries: t.rules.asciiWordBoundaries,
    avoidSubclass: t.avoidSubclass,
    bestEffortTarget: t.target
  }), o = yn(s, t), a = Qt(o.pattern, {
    captureTransfers: o._captureTransfers,
    hiddenCaptures: o._hiddenCaptures,
    mode: "external"
  }), i = Xt(a.pattern), u = Ht(i.pattern, {
    captureTransfers: a.captureTransfers,
    hiddenCaptures: a.hiddenCaptures
  }), c = {
    pattern: u.pattern,
    flags: `${t.hasIndices ? "d" : ""}${t.global ? "g" : ""}${o.flags}${o.options.disable.v ? "u" : "v"}`
  };
  if (t.avoidSubclass) {
    if (t.lazyCompileLength !== 1 / 0)
      throw new Error("Lazy compilation requires subclass");
  } else {
    const l = u.hiddenCaptures.sort((d, m) => d - m), p = Array.from(u.captureTransfers), f = s._strategy, g = c.pattern.length >= t.lazyCompileLength;
    (l.length || p.length || f || g) && (c.options = {
      ...l.length && { hiddenCaptures: l },
      ...p.length && { transfers: p },
      ...f && { strategy: f },
      ...g && { lazyCompile: g }
    });
  }
  return c;
}
const cr = 4294967295;
class Pn {
  constructor(r, t = {}) {
    ye(this, "regexps");
    this.patterns = r, this.options = t;
    const {
      forgiving: n = !1,
      cache: s,
      regexConstructor: o
    } = t;
    if (!o)
      throw new Error("Option `regexConstructor` is not provided");
    this.regexps = r.map((a) => {
      if (typeof a != "string")
        return a;
      const i = s == null ? void 0 : s.get(a);
      if (i) {
        if (i instanceof RegExp)
          return i;
        if (n)
          return null;
        throw i;
      }
      try {
        const u = o(a);
        return s == null || s.set(a, u), u;
      } catch (u) {
        if (s == null || s.set(a, u), n)
          return null;
        throw u;
      }
    });
  }
  findNextMatchSync(r, t, n) {
    const s = typeof r == "string" ? r : r.content, o = [];
    function a(i, u, c = 0) {
      return {
        index: i,
        captureIndices: u.indices.map((l) => l == null ? {
          start: cr,
          end: cr,
          length: 0
        } : {
          start: l[0] + c,
          end: l[1] + c,
          length: l[1] - l[0]
        })
      };
    }
    for (let i = 0; i < this.regexps.length; i++) {
      const u = this.regexps[i];
      if (u)
        try {
          u.lastIndex = t;
          const c = u.exec(s);
          if (!c)
            continue;
          if (c.index === t)
            return a(i, c, 0);
          o.push([i, c, 0]);
        } catch (c) {
          if (this.options.forgiving)
            continue;
          throw c;
        }
    }
    if (o.length) {
      const i = Math.min(...o.map((u) => u[1].index));
      for (const [u, c, l] of o)
        if (c.index === i)
          return a(u, c, l);
    }
    return null;
  }
}
function Rn(e, r) {
  return Fn(
    e,
    {
      global: !0,
      hasIndices: !0,
      // This has no benefit for the standard JS engine, but it avoids a perf penalty for
      // precompiled grammars when constructing extremely long patterns that aren't always used
      lazyCompileLength: 3e3,
      rules: {
        // Needed since TextMate grammars merge backrefs across patterns
        allowOrphanBackrefs: !0,
        // Improves search performance for generated regexes
        asciiWordBoundaries: !0,
        // Follow `vscode-oniguruma` which enables this Oniguruma option by default
        captureGroup: !0,
        // Oniguruma uses depth limit `20`; lowered here to keep regexes shorter and maybe
        // sometimes faster, but can be increased if issues reported due to low limit
        recursionLimit: 5,
        // Oniguruma option for `^`->`\A`, `$`->`\Z`; improves search performance without any
        // change in meaning since TM grammars search line by line
        singleline: !0
      },
      ...r
    }
  );
}
function Un(e = {}) {
  const r = Object.assign(
    {
      target: "auto",
      cache: /* @__PURE__ */ new Map()
    },
    e
  );
  return r.regexConstructor || (r.regexConstructor = (t) => Rn(t, { target: r.target })), {
    createScanner(t) {
      return new Pn(t, r);
    },
    createString(t) {
      return {
        content: t
      };
    }
  };
}
var On = Re("block", "before:content-[counter(line)]", "before:inline-block", "before:[counter-increment:line]", "before:w-4", "before:mr-4", "before:text-[13px]", "before:text-right", "before:text-muted-foreground/50", "before:font-mono", "before:select-none"), Dn = Xr(({ children: e, result: r, language: t, className: n, ...s }) => {
  let o = pr(() => ({ backgroundColor: r.bg, color: r.fg }), [r.bg, r.fg]);
  return v.jsx("pre", { className: Re(n, "p-4 text-sm dark:bg-(--shiki-dark-bg)!"), "data-language": t, "data-streamdown": "code-block-body", style: o, ...s, children: v.jsx("code", { className: "[counter-increment:line_0] [counter-reset:line]", children: r.tokens.map((a, i) => v.jsx("span", { className: On, children: a.map((u, c) => v.jsx("span", { className: "dark:bg-(--shiki-dark-bg)! dark:text-(--shiki-dark)!", style: { color: u.color, backgroundColor: u.bgColor, ...u.htmlStyle }, ...u.htmlAttrs, children: u.content }, c)) }, i)) }) });
}, (e, r) => e.result === r.result && e.language === r.language && e.className === r.className), Tn = ({ className: e, language: r, style: t, ...n }) => v.jsx("div", { className: Re("my-4 w-full overflow-hidden rounded-xl border border-border", e), "data-language": r, "data-streamdown": "code-block", style: { contentVisibility: "auto", containIntrinsicSize: "auto 200px", ...t }, ...n }), Bn = ({ language: e, children: r }) => v.jsxs("div", { className: "flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs", "data-language": e, "data-streamdown": "code-block-header", children: [v.jsx("span", { className: "ml-1 font-mono lowercase", children: e }), v.jsx("div", { className: "flex items-center gap-2", children: r })] }), jn = Un({ forgiving: !0 }), Se = /* @__PURE__ */ new Map(), _e = /* @__PURE__ */ new Map(), ee = /* @__PURE__ */ new Map(), Vn = (e, r) => `${e}-${r[0]}-${r[1]}`, zn = (e, r, t) => {
  let n = e.slice(0, 100), s = e.length > 100 ? e.slice(-100) : "";
  return `${r}:${t[0]}:${t[1]}:${e.length}:${n}:${s}`;
}, Rr = (e) => Object.hasOwn(Hr, e), Wn = (e, r) => {
  let t = Rr(e) ? e : "text", n = Vn(t, r);
  if (Se.has(n))
    return Se.get(n);
  let s = Wr({ themes: r, langs: [t], engine: jn });
  return Se.set(n, s), s;
}, lr = (e, r, t, n) => {
  let s = Rr(r) ? r : "text", o = zn(e, s, t);
  return _e.has(o) ? _e.get(o) : (n && (ee.has(o) || ee.set(o, /* @__PURE__ */ new Set()), ee.get(o).add(n)), Wn(s, t).then((a) => {
    let i = a.codeToTokens(e, { lang: s, themes: { light: t[0], dark: t[1] } });
    _e.set(o, i);
    let u = ee.get(o);
    if (u) {
      for (let c of u)
        c(i);
      ee.delete(o);
    }
  }).catch((a) => {
    console.error("Failed to highlight code:", a), ee.delete(o);
  }), null);
}, qn = ({ code: e, language: r, className: t, children: n, ...s }) => {
  let { shikiTheme: o } = Zr(Vr), a = pr(() => ({ bg: "transparent", fg: "inherit", tokens: e.split(`
`).map((c) => [{ content: c, color: "inherit", bgColor: "transparent", htmlStyle: {}, offset: 0 }]) }), [e]), [i, u] = Qr(a);
  return qr(() => {
    let c = lr(e, r, o);
    if (c) {
      u(c);
      return;
    }
    lr(e, r, o, (l) => {
      u(l);
    });
  }, [e, r, o]), v.jsx(zr.Provider, { value: { code: e }, children: v.jsxs(Tn, { language: r, children: [v.jsx(Bn, { language: r, children: n }), v.jsx(Dn, { className: t, language: r, result: i, ...s })] }) });
};
export {
  qn as CodeBlock
};
