import { __exports as $ } from "./index-sax2.js";
import { __require as ce } from "./index-conventions.js";
var Y;
function le() {
  if (Y) return $;
  Y = 1;
  var O = ce().NAMESPACE, N = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/, U = new RegExp("[\\-\\.0-9" + N.source.slice(1, -1) + "\\u00B7\\u0300-\\u036F\\u203F-\\u2040]"), V = new RegExp("^" + N.source + U.source + "*(?::" + N.source + U.source + "*)?$"), D = 0, T = 1, C = 2, L = 3, F = 4, k = 5, y = 6, P = 7;
  function _(e, r) {
    this.message = e, this.locator = r, Error.captureStackTrace && Error.captureStackTrace(this, _);
  }
  _.prototype = new Error(), _.prototype.name = _.name;
  function X() {
  }
  X.prototype = {
    parse: function(e, r, i) {
      var a = this.domBuilder;
      a.startDocument(), M(r, r = {}), H(
        e,
        r,
        i,
        a,
        this.errorHandler
      ), a.endDocument();
    }
  };
  function H(e, r, i, a, t) {
    function f(o) {
      if (o > 65535) {
        o -= 65536;
        var g = 55296 + (o >> 10), ue = 56320 + (o & 1023);
        return String.fromCharCode(g, ue);
      } else
        return String.fromCharCode(o);
    }
    function c(o) {
      var g = o.slice(1, -1);
      return g in i ? i[g] : g.charAt(0) === "#" ? f(parseInt(g.substr(1).replace("x", "0x"))) : (t.error("entity not found:" + o), o);
    }
    function v(o) {
      if (o > m) {
        var g = e.substring(m, o).replace(/&#?\w+;/g, c);
        l && n(m), a.characters(g, 0, o - m), m = o;
      }
    }
    function n(o, g) {
      for (; o >= u && (g = h.exec(e)); )
        s = g.index, u = s + g[0].length, l.lineNumber++;
      l.columnNumber = o - s + 1;
    }
    for (var s = 0, u = 0, h = /.*(?:\r\n?|\n)|.*$/g, l = a.locator, E = [{ currentNSMap: r }], R = {}, m = 0; ; ) {
      try {
        var p = e.indexOf("<", m);
        if (p < 0) {
          if (!e.substr(m).match(/^\s*$/)) {
            var S = a.doc, z = S.createTextNode(e.substr(m));
            S.appendChild(z), a.currentElement = z;
          }
          return;
        }
        switch (p > m && v(p), e.charAt(p + 1)) {
          case "/":
            var b = e.indexOf(">", p + 3), x = e.substring(p + 2, b).replace(/[ \t\n\r]+$/g, ""), A = E.pop();
            b < 0 ? (x = e.substring(p + 2).replace(/[\s<].*/, ""), t.error("end tag name: " + x + " is not complete:" + A.tagName), b = p + 1 + x.length) : x.match(/\s</) && (x = x.replace(/[\s<].*/, ""), t.error("end tag name: " + x + " maybe not complete"), b = p + 1 + x.length);
            var d = A.localNSMap, Z = A.tagName == x, ne = Z || A.tagName && A.tagName.toLowerCase() == x.toLowerCase();
            if (ne) {
              if (a.endElement(A.uri, A.localName, x), d)
                for (var J in d)
                  Object.prototype.hasOwnProperty.call(d, J) && a.endPrefixMapping(J);
              Z || t.fatalError("end tag name: " + x + " is not match the current start tagName:" + A.tagName);
            } else
              E.push(A);
            b++;
            break;
          // end elment
          case "?":
            l && n(p), b = te(e, p, a);
            break;
          case "!":
            l && n(p), b = ie(e, p, a, t);
            break;
          default:
            l && n(p);
            var w = new Q(), I = E[E.length - 1].currentNSMap, b = B(e, p, w, I, c, t), K = w.length;
            if (!w.closed && re(e, b, w.tagName, R) && (w.closed = !0, i.nbsp || t.warning("unclosed xml attribute")), l && K) {
              for (var se = j(l, {}), q = 0; q < K; q++) {
                var W = w[q];
                n(W.offset), W.locator = j(l, {});
              }
              a.locator = se, G(w, a, I) && E.push(w), a.locator = l;
            } else
              G(w, a, I) && E.push(w);
            O.isHTML(w.uri) && !w.closed ? b = ee(e, b, w.tagName, c, a) : b++;
        }
      } catch (o) {
        if (o instanceof _)
          throw o;
        t.error("element parse error: " + o), b = -1;
      }
      b > m ? m = b : v(Math.max(p, m) + 1);
    }
  }
  function j(e, r) {
    return r.lineNumber = e.lineNumber, r.columnNumber = e.columnNumber, r;
  }
  function B(e, r, i, a, t, f) {
    function c(l, E, R) {
      i.attributeNames.hasOwnProperty(l) && f.fatalError("Attribute " + l + " redefined"), i.addValue(l, E, R);
    }
    for (var v, n, s = ++r, u = D; ; ) {
      var h = e.charAt(s);
      switch (h) {
        case "=":
          if (u === T)
            v = e.slice(r, s), u = L;
          else if (u === C)
            u = L;
          else
            throw new Error("attribute equal must after attrName");
          break;
        case "'":
        case '"':
          if (u === L || u === T)
            if (u === T && (f.warning('attribute value must after "="'), v = e.slice(r, s)), r = s + 1, s = e.indexOf(h, r), s > 0)
              n = e.slice(r, s).replace(/&#?\w+;/g, t), c(v, n, r - 1), u = k;
            else
              throw new Error("attribute value no end '" + h + "' match");
          else if (u == F)
            n = e.slice(r, s).replace(/&#?\w+;/g, t), c(v, n, r), f.warning('attribute "' + v + '" missed start quot(' + h + ")!!"), r = s + 1, u = k;
          else
            throw new Error('attribute value must after "="');
          break;
        case "/":
          switch (u) {
            case D:
              i.setTagName(e.slice(r, s));
            case k:
            case y:
            case P:
              u = P, i.closed = !0;
            case F:
            case T:
              break;
            case C:
              i.closed = !0;
              break;
            //case S_EQ:
            default:
              throw new Error("attribute invalid close char('/')");
          }
          break;
        case "":
          return f.error("unexpected end of input"), u == D && i.setTagName(e.slice(r, s)), s;
        case ">":
          switch (u) {
            case D:
              i.setTagName(e.slice(r, s));
            case k:
            case y:
            case P:
              break;
            //normal
            case F:
            //Compatible state
            case T:
              n = e.slice(r, s), n.slice(-1) === "/" && (i.closed = !0, n = n.slice(0, -1));
            case C:
              u === C && (n = v), u == F ? (f.warning('attribute "' + n + '" missed quot(")!'), c(v, n.replace(/&#?\w+;/g, t), r)) : ((!O.isHTML(a[""]) || !n.match(/^(?:disabled|checked|selected)$/i)) && f.warning('attribute "' + n + '" missed value!! "' + n + '" instead!!'), c(n, n, r));
              break;
            case L:
              throw new Error("attribute value missed!!");
          }
          return s;
        /*xml space '\x20' | #x9 | #xD | #xA; */
        case "":
          h = " ";
        default:
          if (h <= " ")
            switch (u) {
              case D:
                i.setTagName(e.slice(r, s)), u = y;
                break;
              case T:
                v = e.slice(r, s), u = C;
                break;
              case F:
                var n = e.slice(r, s).replace(/&#?\w+;/g, t);
                f.warning('attribute "' + n + '" missed quot(")!!'), c(v, n, r);
              case k:
                u = y;
                break;
            }
          else
            switch (u) {
              //case S_TAG:void();break;
              //case S_ATTR:void();break;
              //case S_ATTR_NOQUOT_VALUE:void();break;
              case C:
                i.tagName, (!O.isHTML(a[""]) || !v.match(/^(?:disabled|checked|selected)$/i)) && f.warning('attribute "' + v + '" missed value!! "' + v + '" instead2!!'), c(v, v, r), r = s, u = T;
                break;
              case k:
                f.warning('attribute space is required"' + v + '"!!');
              case y:
                u = T, r = s;
                break;
              case L:
                u = F, r = s;
                break;
              case P:
                throw new Error("elements closed character '/' and '>' must be connected to");
            }
      }
      s++;
    }
  }
  function G(e, r, i) {
    for (var a = e.tagName, t = null, h = e.length; h--; ) {
      var f = e[h], c = f.qName, v = f.value, l = c.indexOf(":");
      if (l > 0)
        var n = f.prefix = c.slice(0, l), s = c.slice(l + 1), u = n === "xmlns" && s;
      else
        s = c, n = null, u = c === "xmlns" && "";
      f.localName = s, u !== !1 && (t == null && (t = {}, M(i, i = {})), i[u] = t[u] = v, f.uri = O.XMLNS, r.startPrefixMapping(u, v));
    }
    for (var h = e.length; h--; ) {
      f = e[h];
      var n = f.prefix;
      n && (n === "xml" && (f.uri = O.XML), n !== "xmlns" && (f.uri = i[n || ""]));
    }
    var l = a.indexOf(":");
    l > 0 ? (n = e.prefix = a.slice(0, l), s = e.localName = a.slice(l + 1)) : (n = null, s = e.localName = a);
    var E = e.uri = i[n || ""];
    if (r.startElement(E, s, a, e), e.closed) {
      if (r.endElement(E, s, a), t)
        for (n in t)
          Object.prototype.hasOwnProperty.call(t, n) && r.endPrefixMapping(n);
    } else
      return e.currentNSMap = i, e.localNSMap = t, !0;
  }
  function ee(e, r, i, a, t) {
    if (/^(?:script|textarea)$/i.test(i)) {
      var f = e.indexOf("</" + i + ">", r), c = e.substring(r + 1, f);
      if (/[&<]/.test(c))
        return /^script$/i.test(i) ? (t.characters(c, 0, c.length), f) : (c = c.replace(/&#?\w+;/g, a), t.characters(c, 0, c.length), f);
    }
    return r + 1;
  }
  function re(e, r, i, a) {
    var t = a[i];
    return t == null && (t = e.lastIndexOf("</" + i + ">"), t < r && (t = e.lastIndexOf("</" + i)), a[i] = t), t < r;
  }
  function M(e, r) {
    for (var i in e)
      Object.prototype.hasOwnProperty.call(e, i) && (r[i] = e[i]);
  }
  function ie(e, r, i, a) {
    var t = e.charAt(r + 2);
    switch (t) {
      case "-":
        if (e.charAt(r + 3) === "-") {
          var f = e.indexOf("-->", r + 4);
          return f > r ? (i.comment(e, r + 4, f - r - 4), f + 3) : (a.error("Unclosed comment"), -1);
        } else
          return -1;
      default:
        if (e.substr(r + 3, 6) == "CDATA[") {
          var f = e.indexOf("]]>", r + 9);
          return i.startCDATA(), i.characters(e, r + 9, f - r - 9), i.endCDATA(), f + 3;
        }
        var c = ae(e, r), v = c.length;
        if (v > 1 && /!doctype/i.test(c[0][0])) {
          var n = c[1][0], s = !1, u = !1;
          v > 3 && (/^public$/i.test(c[2][0]) ? (s = c[3][0], u = v > 4 && c[4][0]) : /^system$/i.test(c[2][0]) && (u = c[3][0]));
          var h = c[v - 1];
          return i.startDTD(n, s, u), i.endDTD(), h.index + h[0].length;
        }
    }
    return -1;
  }
  function te(e, r, i) {
    var a = e.indexOf("?>", r);
    if (a) {
      var t = e.substring(r, a).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
      return t ? (t[0].length, i.processingInstruction(t[1], t[2]), a + 2) : -1;
    }
    return -1;
  }
  function Q() {
    this.attributeNames = {};
  }
  Q.prototype = {
    setTagName: function(e) {
      if (!V.test(e))
        throw new Error("invalid tagName:" + e);
      this.tagName = e;
    },
    addValue: function(e, r, i) {
      if (!V.test(e))
        throw new Error("invalid attribute:" + e);
      this.attributeNames[e] = this.length, this[this.length++] = { qName: e, value: r, offset: i };
    },
    length: 0,
    getLocalName: function(e) {
      return this[e].localName;
    },
    getLocator: function(e) {
      return this[e].locator;
    },
    getQName: function(e) {
      return this[e].qName;
    },
    getURI: function(e) {
      return this[e].uri;
    },
    getValue: function(e) {
      return this[e].value;
    }
    //	,getIndex:function(uri, localName)){
    //		if(localName){
    //
    //		}else{
    //			var qName = uri
    //		}
    //	},
    //	getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
    //	getType:function(uri,localName){}
    //	getType:function(i){},
  };
  function ae(e, r) {
    var i, a = [], t = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
    for (t.lastIndex = r, t.exec(e); i = t.exec(e); )
      if (a.push(i), i[1]) return a;
  }
  return $.XMLReader = X, $.ParseError = _, $;
}
export {
  le as __require
};
