import { __exports as u } from "../../../../../../_virtual/querying.js";
import { __require as o } from "../../../../domhandler@5.0.3/node_modules/domhandler/lib/index.js";
var d;
function O() {
  if (d) return u;
  d = 1, Object.defineProperty(u, "__esModule", { value: !0 }), u.filter = y, u.find = s, u.findOneChild = g, u.findOne = c, u.existsOne = v, u.findAll = A;
  var e = /* @__PURE__ */ o();
  function y(f, r, n, t) {
    return n === void 0 && (n = !0), t === void 0 && (t = 1 / 0), s(f, Array.isArray(r) ? r : [r], n, t);
  }
  function s(f, r, n, t) {
    for (var a = [], i = [Array.isArray(r) ? r : [r]], h = [0]; ; ) {
      if (h[0] >= i[0].length) {
        if (h.length === 1)
          return a;
        i.shift(), h.shift();
        continue;
      }
      var l = i[0][h[0]++];
      if (f(l) && (a.push(l), --t <= 0))
        return a;
      n && (0, e.hasChildren)(l) && l.children.length > 0 && (h.unshift(0), i.unshift(l.children));
    }
  }
  function g(f, r) {
    return r.find(f);
  }
  function c(f, r, n) {
    n === void 0 && (n = !0);
    for (var t = Array.isArray(r) ? r : [r], a = 0; a < t.length; a++) {
      var i = t[a];
      if ((0, e.isTag)(i) && f(i))
        return i;
      if (n && (0, e.hasChildren)(i) && i.children.length > 0) {
        var h = c(f, i.children, !0);
        if (h)
          return h;
      }
    }
    return null;
  }
  function v(f, r) {
    return (Array.isArray(r) ? r : [r]).some(function(n) {
      return (0, e.isTag)(n) && f(n) || (0, e.hasChildren)(n) && v(f, n.children);
    });
  }
  function A(f, r) {
    for (var n = [], t = [Array.isArray(r) ? r : [r]], a = [0]; ; ) {
      if (a[0] >= t[0].length) {
        if (t.length === 1)
          return n;
        t.shift(), a.shift();
        continue;
      }
      var i = t[0][a[0]++];
      (0, e.isTag)(i) && f(i) && n.push(i), (0, e.hasChildren)(i) && i.children.length > 0 && (a.unshift(0), t.unshift(i.children));
    }
  }
  return u;
}
export {
  O as __require
};
//# sourceMappingURL=querying.js.map
