import { __exports as m } from "./index-dom-parser2.js";
import { __require as T } from "./index-conventions.js";
import { __require as q } from "./index-dom.js";
import { __require as A } from "./index-entities.js";
import { __require as C } from "./index-sax.js";
var M;
function O() {
  if (M) return m;
  M = 1;
  var N = T(), p = q(), h = A(), v = C(), _ = p.DOMImplementation, E = N.NAMESPACE, x = v.ParseError, y = v.XMLReader;
  function D(t) {
    this.options = t || { locator: {} };
  }
  D.prototype.parseFromString = function(t, r) {
    var n = this.options, e = new y(), i = n.domBuilder || new f(), a = n.errorHandler, c = n.locator, o = n.xmlns || {}, l = /\/x?html?$/.test(r), u = l ? h.HTML_ENTITIES : h.XML_ENTITIES;
    return c && i.setDocumentLocator(c), e.errorHandler = b(a, i, c), e.domBuilder = n.domBuilder || i, l && (o[""] = E.HTML), o.xml = o.xml || E.XML, t && typeof t == "string" ? e.parse(t, o, u) : e.errorHandler.error("invalid doc source"), i.doc;
  };
  function b(t, r, n) {
    if (!t) {
      if (r instanceof f)
        return r;
      t = r;
    }
    var e = {}, i = t instanceof Function;
    n = n || {};
    function a(c) {
      var o = t[c];
      !o && i && (o = t.length == 2 ? function(l) {
        t(c, l);
      } : t), e[c] = o && function(l) {
        o("[xmldom " + c + "]	" + l + S(n));
      } || function() {
      };
    }
    return a("warning"), a("error"), a("fatalError"), e;
  }
  function f() {
    this.cdata = !1;
  }
  function s(t, r) {
    r.lineNumber = t.lineNumber, r.columnNumber = t.columnNumber;
  }
  f.prototype = {
    startDocument: function() {
      this.doc = new _().createDocument(null, null, null), this.locator && (this.doc.documentURI = this.locator.systemId);
    },
    startElement: function(t, r, n, e) {
      var i = this.doc, a = i.createElementNS(t, n || r), c = e.length;
      d(this, a), this.currentElement = a, this.locator && s(this.locator, a);
      for (var o = 0; o < c; o++) {
        var t = e.getURI(o), l = e.getValue(o), n = e.getQName(o), u = i.createAttributeNS(t, n);
        this.locator && s(e.getLocator(o), u), u.value = u.nodeValue = l, a.setAttributeNode(u);
      }
    },
    endElement: function(t, r, n) {
      var e = this.currentElement;
      e.tagName, this.currentElement = e.parentNode;
    },
    startPrefixMapping: function(t, r) {
    },
    endPrefixMapping: function(t) {
    },
    processingInstruction: function(t, r) {
      var n = this.doc.createProcessingInstruction(t, r);
      this.locator && s(this.locator, n), d(this, n);
    },
    ignorableWhitespace: function(t, r, n) {
    },
    characters: function(t, r, n) {
      if (t = g.apply(this, arguments), t) {
        if (this.cdata)
          var e = this.doc.createCDATASection(t);
        else
          var e = this.doc.createTextNode(t);
        this.currentElement ? this.currentElement.appendChild(e) : /^\s*$/.test(t) && this.doc.appendChild(e), this.locator && s(this.locator, e);
      }
    },
    skippedEntity: function(t) {
    },
    endDocument: function() {
      this.doc.normalize();
    },
    setDocumentLocator: function(t) {
      (this.locator = t) && (t.lineNumber = 0);
    },
    //LexicalHandler
    comment: function(t, r, n) {
      t = g.apply(this, arguments);
      var e = this.doc.createComment(t);
      this.locator && s(this.locator, e), d(this, e);
    },
    startCDATA: function() {
      this.cdata = !0;
    },
    endCDATA: function() {
      this.cdata = !1;
    },
    startDTD: function(t, r, n) {
      var e = this.doc.implementation;
      if (e && e.createDocumentType) {
        var i = e.createDocumentType(t, r, n);
        this.locator && s(this.locator, i), d(this, i), this.doc.doctype = i;
      }
    },
    /**
     * @see org.xml.sax.ErrorHandler
     * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
     */
    warning: function(t) {
    },
    error: function(t) {
    },
    fatalError: function(t) {
      throw new x(t, this.locator);
    }
  };
  function S(t) {
    if (t)
      return `
@` + (t.systemId || "") + "#[line:" + t.lineNumber + ",col:" + t.columnNumber + "]";
  }
  function g(t, r, n) {
    return typeof t == "string" ? t.substr(r, n) : t.length >= r + n || r ? new java.lang.String(t, r, n) + "" : t;
  }
  "endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g, function(t) {
    f.prototype[t] = function() {
      return null;
    };
  });
  function d(t, r) {
    t.currentElement ? t.currentElement.appendChild(r) : t.doc.appendChild(r);
  }
  return m.__DOMHandler = f, m.DOMParser = D, m.DOMImplementation = p.DOMImplementation, m.XMLSerializer = p.XMLSerializer, m;
}
export {
  O as __require
};
