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