import * as b from "react";
import { noTextChildNodes as w, possibleStandardNames as h, styleToObject as A, randomString as E } from "./index-helpers2.js";
var v = function() {
  return v = Object.assign || function(r) {
    for (var e, t = 1, n = arguments.length; t < n; t++) {
      e = arguments[t];
      for (var a in e) Object.prototype.hasOwnProperty.call(e, a) && (r[a] = e[a]);
    }
    return r;
  }, v.apply(this, arguments);
}, g = function(r, e) {
  var t = typeof Symbol == "function" && r[Symbol.iterator];
  if (!t) return r;
  var n = t.call(r), a, c = [], l;
  try {
    for (; (e === void 0 || e-- > 0) && !(a = n.next()).done; ) c.push(a.value);
  } catch (u) {
    l = { error: u };
  } finally {
    try {
      a && !a.done && (t = n.return) && t.call(n);
    } finally {
      if (l) throw l.error;
    }
  }
  return c;
}, _ = function(r, e, t) {
  if (t || arguments.length === 2) for (var n = 0, a = e.length, c; n < a; n++)
    (c || !(n in e)) && (c || (c = Array.prototype.slice.call(e, 0, n)), c[n] = e[n]);
  return r.concat(c || Array.prototype.slice.call(e));
};
function O(r, e) {
  var t = {
    key: e
  };
  if (r instanceof Element) {
    var n = r.getAttribute("class");
    n && (t.className = n), _([], g(r.attributes), !1).forEach(function(a) {
      switch (a.name) {
        // this is manually handled above, so break;
        case "class":
          break;
        case "style":
          t[a.name] = A(a.value);
          break;
        case "allowfullscreen":
        case "allowpaymentrequest":
        case "async":
        case "autofocus":
        case "autoplay":
        case "checked":
        case "controls":
        case "default":
        case "defer":
        case "disabled":
        case "formnovalidate":
        case "hidden":
        case "ismap":
        case "itemscope":
        case "loop":
        case "multiple":
        case "muted":
        case "nomodule":
        case "novalidate":
        case "open":
        case "readonly":
        case "required":
        case "reversed":
        case "selected":
        case "typemustmatch":
          t[h[a.name] || a.name] = !0;
          break;
        default:
          t[h[a.name] || a.name] = a.value;
      }
    });
  }
  return t;
}
function S(r, e, t) {
  var n = _([], g(r), !1).map(function(a, c) {
    return p(a, v(v({}, t), { index: c, level: e + 1 }));
  }).filter(Boolean);
  return n.length ? n : null;
}
function k(r) {
  return /[a-z]+[A-Z]+[a-z]+/.test(r) ? r : r.toLowerCase();
}
function p(r, e) {
  var t;
  if (e === void 0 && (e = {}), !r || !(r instanceof Node))
    return null;
  var n = e.actions, a = n === void 0 ? [] : n, c = e.index, l = c === void 0 ? 0 : c, u = e.level, i = u === void 0 ? 0 : u, y = e.randomKey, o = r, s = "".concat(i, "-").concat(l), m = [];
  if (y && i === 0 && (s = "".concat(E(), "-").concat(s)), Array.isArray(a) && a.forEach(function(d) {
    d.condition(o, s, i) && (typeof d.pre == "function" && (o = d.pre(o, s, i), o instanceof Node || (o = r, process.env.NODE_ENV)), typeof d.post == "function" && m.push(d.post(o, s, i)));
  }), m.length)
    return m;
  switch (o.nodeType) {
    case 1:
      return b.createElement(k(o.nodeName), O(o, s), S(o.childNodes, i, e));
    case 3: {
      var f = ((t = o.nodeValue) === null || t === void 0 ? void 0 : t.toString()) || "";
      if (/^\s+$/.test(f) && !/[\u00A0\u202F]/.test(f))
        return null;
      if (!o.parentNode)
        return f;
      var N = o.parentNode.nodeName.toLowerCase();
      return w.includes(N) ? (/\S/.test(f), null) : f;
    }
    case 8:
      return null;
    /* istanbul ignore next */
    default:
      return null;
  }
}
function x(r, e) {
  if (e === void 0 && (e = {}), !r || typeof r != "string")
    return null;
  var t = e.nodeOnly, n = t === void 0 ? !1 : t, a = e.selector, c = a === void 0 ? "body > *" : a, l = e.type, u = l === void 0 ? "text/html" : l;
  try {
    var i = new DOMParser(), y = i.parseFromString(r, u), o = y.querySelector(c);
    if (!(o instanceof Node))
      throw new TypeError("Error parsing input");
    return n ? o : p(o, e);
  } catch {
    process.env.NODE_ENV;
  }
  return null;
}
function F(r, e) {
  return e === void 0 && (e = {}), typeof r == "string" ? x(r, e) : r instanceof Node ? p(r, e) : null;
}
export {
  p as convertFromNode,
  x as convertFromString,
  F as default
};
