import { characterEntitiesLegacy as L } from "../../../../character-entities-legacy@3.0.0/node_modules/character-entities-legacy/index.es.js";
import { characterReferenceInvalid as j } from "../../../../character-reference-invalid@2.0.1/node_modules/character-reference-invalid/index.es.js";
import { isDecimal as T } from "../../../../is-decimal@2.0.1/node_modules/is-decimal/index.es.js";
import { isHexadecimal as U } from "../../../../is-hexadecimal@2.0.1/node_modules/is-hexadecimal/index.es.js";
import { isAlphanumerical as q } from "../../../../is-alphanumerical@2.0.1/node_modules/is-alphanumerical/index.es.js";
import { decodeNamedCharacterReference as D } from "../../../../decode-named-character-reference@1.2.0/node_modules/decode-named-character-reference/index.dom.es.js";
const z = [
  "",
  /* 1: Non terminated (named) */
  "Named character references must be terminated by a semicolon",
  /* 2: Non terminated (numeric) */
  "Numeric character references must be terminated by a semicolon",
  /* 3: Empty (named) */
  "Named character references cannot be empty",
  /* 4: Empty (numeric) */
  "Numeric character references cannot be empty",
  /* 5: Unknown (named) */
  "Named character references must be known",
  /* 6: Disallowed (numeric) */
  "Numeric character references cannot be disallowed",
  /* 7: Prohibited (numeric) */
  "Numeric character references cannot be outside the permissible Unicode range"
];
function V(t, G) {
  const n = {}, R = typeof n.additional == "string" ? n.additional.charCodeAt(0) : n.additional, y = [];
  let d = 0, k = -1, h = "", m, S;
  n.position && ("start" in n.position || "indent" in n.position ? (S = n.position.indent, m = n.position.start) : m = n.position);
  let E = (m ? m.line : 0) || 1, x = (m ? m.column : 0) || 1, A = b(), u;
  for (d--; ++d <= t.length; )
    if (u === 10 && (x = (S ? S[k] : 0) || 1), u = t.charCodeAt(d), u === 38) {
      const r = t.charCodeAt(d + 1);
      if (r === 9 || r === 10 || r === 12 || r === 32 || r === 38 || r === 60 || Number.isNaN(r) || R && r === R) {
        h += String.fromCharCode(u), x++;
        continue;
      }
      const s = d + 1;
      let c = s, i = s, a;
      if (r === 35) {
        i = ++c;
        const e = t.charCodeAt(i);
        e === 88 || e === 120 ? (a = "hexadecimal", i = ++c) : a = "decimal";
      } else
        a = "named";
      let N = "", C = "", f = "";
      const H = a === "named" ? q : a === "decimal" ? T : U;
      for (i--; ++i <= t.length; ) {
        const e = t.charCodeAt(i);
        if (!H(e))
          break;
        f += String.fromCharCode(e), a === "named" && L.includes(f) && (N = f, C = D(f));
      }
      let g = t.charCodeAt(i) === 59;
      if (g) {
        i++;
        const e = a === "named" ? D(f) : !1;
        e && (N = f, C = e);
      }
      let l = 1 + i - s, p = "";
      if (!(!g && n.nonTerminated === !1)) if (!f)
        a !== "named" && o(4, l);
      else if (a === "named") {
        if (g && !C)
          o(5, 1);
        else if (N !== f && (i = c + N.length, l = 1 + i - c, g = !1), !g) {
          const e = N ? 1 : 3;
          if (n.attribute) {
            const w = t.charCodeAt(i);
            w === 61 ? (o(e, l), C = "") : q(w) ? C = "" : o(e, l);
          } else
            o(e, l);
        }
        p = C;
      } else {
        g || o(2, l);
        let e = Number.parseInt(
          f,
          a === "hexadecimal" ? 16 : 10
        );
        if (B(e))
          o(7, l), p = "�";
        else if (e in j)
          o(6, l), p = j[e];
        else {
          let w = "";
          F(e) && o(6, l), e > 65535 && (e -= 65536, w += String.fromCharCode(
            e >>> 10 | 55296
          ), e = 56320 | e & 1023), p = w + String.fromCharCode(e);
        }
      }
      if (p) {
        I(), A = b(), d = i - 1, x += i - s + 1, y.push(p);
        const e = b();
        e.offset++, n.reference && n.reference.call(
          n.referenceContext || void 0,
          p,
          { start: A, end: e },
          t.slice(s - 1, i)
        ), A = e;
      } else
        f = t.slice(s - 1, i), h += f, x += f.length, d = i - 1;
    } else
      u === 10 && (E++, k++, x = 0), Number.isNaN(u) ? I() : (h += String.fromCharCode(u), x++);
  return y.join("");
  function b() {
    return {
      line: E,
      column: x,
      offset: d + ((m ? m.offset : 0) || 0)
    };
  }
  function o(r, s) {
    let c;
    n.warning && (c = b(), c.column += s, c.offset += s, n.warning.call(
      n.warningContext || void 0,
      z[r],
      c,
      r
    ));
  }
  function I() {
    h && (y.push(h), n.text && n.text.call(n.textContext || void 0, h, {
      start: A,
      end: b()
    }), h = "");
  }
}
function B(t) {
  return t >= 55296 && t <= 57343 || t > 1114111;
}
function F(t) {
  return t >= 1 && t <= 8 || t === 11 || t >= 13 && t <= 31 || t >= 127 && t <= 159 || t >= 64976 && t <= 65007 || (t & 65535) === 65535 || (t & 65535) === 65534;
}
export {
  V as parseEntities
};
//# sourceMappingURL=index.es.js.map
