import { __exports as R } from "../../../../../../../../_virtual/sax.js";
import { __require as ue } from "./conventions.js";
var Y;
function ve() {
  if (Y) return R;
  Y = 1;
  var _ = ue().NAMESPACE, $ = /[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]/, q = new RegExp("[\\-\\.0-9" + $.source.slice(1, -1) + "\\u00B7\\u0300-\\u036F\\u203F-\\u2040]"), U = new RegExp("^" + $.source + q.source + "*(?::" + $.source + q.source + "*)?$"), D = 0, T = 1, C = 2, y = 3, F = 4, O = 5, L = 6, P = 7;
  function k(e, r) {
    this.message = e, this.locator = r, Error.captureStackTrace && Error.captureStackTrace(this, k);
  }
  k.prototype = new Error(), k.prototype.name = k.name;
  function V() {
  }
  V.prototype = {
    parse: function(e, r, i) {
      var t = this.domBuilder;
      t.startDocument(), M(r, r = {}), H(
        e,
        r,
        i,
        t,
        this.errorHandler
      ), t.endDocument();
    }
  };
  function H(e, r, i, t, n) {
    function f(o) {
      if (o > 65535) {
        o -= 65536;
        var g = 55296 + (o >> 10), ce = 56320 + (o & 1023);
        return String.fromCharCode(g, ce);
      } else
        return String.fromCharCode(o);
    }
    function u(o) {
      var g = o.slice(1, -1);
      return Object.hasOwnProperty.call(i, g) ? i[g] : g.charAt(0) === "#" ? f(parseInt(g.substr(1).replace("x", "0x"))) : (n.error("entity not found:" + o), o);
    }
    function l(o) {
      if (o > m) {
        var g = e.substring(m, o).replace(/&#?\w+;/g, u);
        v && a(m), t.characters(g, 0, o - m), m = o;
      }
    }
    function a(o, g) {
      for (; o >= c && (g = h.exec(e)); )
        s = g.index, c = s + g[0].length, v.lineNumber++;
      v.columnNumber = o - s + 1;
    }
    for (var s = 0, c = 0, h = /.*(?:\r\n?|\n)|.*$/g, v = t.locator, E = [{ currentNSMap: r }], N = {}, m = 0; ; ) {
      try {
        var p = e.indexOf("<", m);
        if (p < 0) {
          if (!e.substr(m).match(/^\s*$/)) {
            var S = t.doc, z = S.createTextNode(e.substr(m));
            S.appendChild(z), t.currentElement = z;
          }
          return;
        }
        switch (p > m && l(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<].*/, ""), n.error("end tag name: " + x + " is not complete:" + A.tagName), b = p + 1 + x.length) : x.match(/\s</) && (x = x.replace(/[\s<].*/, ""), n.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 (t.endElement(A.uri, A.localName, x), d)
                for (var J in d)
                  Object.prototype.hasOwnProperty.call(d, J) && t.endPrefixMapping(J);
              Z || n.fatalError("end tag name: " + x + " is not match the current start tagName:" + A.tagName);
            } else
              E.push(A);
            b++;
            break;
          // end elment
          case "?":
            v && a(p), b = te(e, p, t);
            break;
          case "!":
            v && a(p), b = ie(e, p, t, n);
            break;
          default:
            v && a(p);
            var w = new Q(), I = E[E.length - 1].currentNSMap, b = B(e, p, w, I, u, n), K = w.length;
            if (!w.closed && re(e, b, w.tagName, N) && (w.closed = !0, i.nbsp || n.warning("unclosed xml attribute")), v && K) {
              for (var se = X(v, {}), j = 0; j < K; j++) {
                var W = w[j];
                a(W.offset), W.locator = X(v, {});
              }
              t.locator = se, G(w, t, I) && E.push(w), t.locator = v;
            } else
              G(w, t, I) && E.push(w);
            _.isHTML(w.uri) && !w.closed ? b = ee(e, b, w.tagName, u, t) : b++;
        }
      } catch (o) {
        if (o instanceof k)
          throw o;
        n.error("element parse error: " + o), b = -1;
      }
      b > m ? m = b : l(Math.max(p, m) + 1);
    }
  }
  function X(e, r) {
    return r.lineNumber = e.lineNumber, r.columnNumber = e.columnNumber, r;
  }
  function B(e, r, i, t, n, f) {
    function u(v, E, N) {
      i.attributeNames.hasOwnProperty(v) && f.fatalError("Attribute " + v + " redefined"), i.addValue(
        v,
        // @see https://www.w3.org/TR/xml/#AVNormalize
        // since the xmldom sax parser does not "interpret" DTD the following is not implemented:
        // - recursive replacement of (DTD) entity references
        // - trimming and collapsing multiple spaces into a single one for attributes that are not of type CDATA
        E.replace(/[\t\n\r]/g, " ").replace(/&#?\w+;/g, n),
        N
      );
    }
    for (var l, a, s = ++r, c = D; ; ) {
      var h = e.charAt(s);
      switch (h) {
        case "=":
          if (c === T)
            l = e.slice(r, s), c = y;
          else if (c === C)
            c = y;
          else
            throw new Error("attribute equal must after attrName");
          break;
        case "'":
        case '"':
          if (c === y || c === T)
            if (c === T && (f.warning('attribute value must after "="'), l = e.slice(r, s)), r = s + 1, s = e.indexOf(h, r), s > 0)
              a = e.slice(r, s), u(l, a, r - 1), c = O;
            else
              throw new Error("attribute value no end '" + h + "' match");
          else if (c == F)
            a = e.slice(r, s), u(l, a, r), f.warning('attribute "' + l + '" missed start quot(' + h + ")!!"), r = s + 1, c = O;
          else
            throw new Error('attribute value must after "="');
          break;
        case "/":
          switch (c) {
            case D:
              i.setTagName(e.slice(r, s));
            case O:
            case L:
            case P:
              c = 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"), c == D && i.setTagName(e.slice(r, s)), s;
        case ">":
          switch (c) {
            case D:
              i.setTagName(e.slice(r, s));
            case O:
            case L:
            case P:
              break;
            //normal
            case F:
            //Compatible state
            case T:
              a = e.slice(r, s), a.slice(-1) === "/" && (i.closed = !0, a = a.slice(0, -1));
            case C:
              c === C && (a = l), c == F ? (f.warning('attribute "' + a + '" missed quot(")!'), u(l, a, r)) : ((!_.isHTML(t[""]) || !a.match(/^(?:disabled|checked|selected)$/i)) && f.warning('attribute "' + a + '" missed value!! "' + a + '" instead!!'), u(a, a, r));
              break;
            case y:
              throw new Error("attribute value missed!!");
          }
          return s;
        /*xml space '\x20' | #x9 | #xD | #xA; */
        case "":
          h = " ";
        default:
          if (h <= " ")
            switch (c) {
              case D:
                i.setTagName(e.slice(r, s)), c = L;
                break;
              case T:
                l = e.slice(r, s), c = C;
                break;
              case F:
                var a = e.slice(r, s);
                f.warning('attribute "' + a + '" missed quot(")!!'), u(l, a, r);
              case O:
                c = L;
                break;
            }
          else
            switch (c) {
              //case S_TAG:void();break;
              //case S_ATTR:void();break;
              //case S_ATTR_NOQUOT_VALUE:void();break;
              case C:
                i.tagName, (!_.isHTML(t[""]) || !l.match(/^(?:disabled|checked|selected)$/i)) && f.warning('attribute "' + l + '" missed value!! "' + l + '" instead2!!'), u(l, l, r), r = s, c = T;
                break;
              case O:
                f.warning('attribute space is required"' + l + '"!!');
              case L:
                c = T, r = s;
                break;
              case y:
                c = 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 t = e.tagName, n = null, h = e.length; h--; ) {
      var f = e[h], u = f.qName, l = f.value, v = u.indexOf(":");
      if (v > 0)
        var a = f.prefix = u.slice(0, v), s = u.slice(v + 1), c = a === "xmlns" && s;
      else
        s = u, a = null, c = u === "xmlns" && "";
      f.localName = s, c !== !1 && (n == null && (n = {}, M(i, i = {})), i[c] = n[c] = l, f.uri = _.XMLNS, r.startPrefixMapping(c, l));
    }
    for (var h = e.length; h--; ) {
      f = e[h];
      var a = f.prefix;
      a && (a === "xml" && (f.uri = _.XML), a !== "xmlns" && (f.uri = i[a || ""]));
    }
    var v = t.indexOf(":");
    v > 0 ? (a = e.prefix = t.slice(0, v), s = e.localName = t.slice(v + 1)) : (a = null, s = e.localName = t);
    var E = e.uri = i[a || ""];
    if (r.startElement(E, s, t, e), e.closed) {
      if (r.endElement(E, s, t), n)
        for (a in n)
          Object.prototype.hasOwnProperty.call(n, a) && r.endPrefixMapping(a);
    } else
      return e.currentNSMap = i, e.localNSMap = n, !0;
  }
  function ee(e, r, i, t, n) {
    if (/^(?:script|textarea)$/i.test(i)) {
      var f = e.indexOf("</" + i + ">", r), u = e.substring(r + 1, f);
      if (/[&<]/.test(u))
        return /^script$/i.test(i) ? (n.characters(u, 0, u.length), f) : (u = u.replace(/&#?\w+;/g, t), n.characters(u, 0, u.length), f);
    }
    return r + 1;
  }
  function re(e, r, i, t) {
    var n = t[i];
    return n == null && (n = e.lastIndexOf("</" + i + ">"), n < r && (n = e.lastIndexOf("</" + i)), t[i] = n), n < 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, t) {
    var n = e.charAt(r + 2);
    switch (n) {
      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) : (t.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 u = ae(e, r), l = u.length;
        if (l > 1 && /!doctype/i.test(u[0][0])) {
          var a = u[1][0], s = !1, c = !1;
          l > 3 && (/^public$/i.test(u[2][0]) ? (s = u[3][0], c = l > 4 && u[4][0]) : /^system$/i.test(u[2][0]) && (c = u[3][0]));
          var h = u[l - 1];
          return i.startDTD(a, s, c), i.endDTD(), h.index + h[0].length;
        }
    }
    return -1;
  }
  function te(e, r, i) {
    var t = e.indexOf("?>", r);
    if (t) {
      var n = e.substring(r, t).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
      return n ? (n[0].length, i.processingInstruction(n[1], n[2]), t + 2) : -1;
    }
    return -1;
  }
  function Q() {
    this.attributeNames = {};
  }
  Q.prototype = {
    setTagName: function(e) {
      if (!U.test(e))
        throw new Error("invalid tagName:" + e);
      this.tagName = e;
    },
    addValue: function(e, r, i) {
      if (!U.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, t = [], n = /'[^']+'|"[^"]+"|[^\s<>\/=]+=?|(\/?\s*>|<)/g;
    for (n.lastIndex = r, n.exec(e); i = n.exec(e); )
      if (t.push(i), i[1]) return t;
  }
  return R.XMLReader = V, R.ParseError = k, R;
}
export {
  ve as __require
};
//# sourceMappingURL=sax.js.map
