import m from "./count.js";
import c from "./each.js";
import s from "./eachBefore.js";
import u from "./eachAfter.js";
import l from "./find.js";
import _ from "./sum.js";
import y from "./sort.js";
import v from "./path.js";
import g from "./ancestors.js";
import A from "./descendants.js";
import w from "./leaves.js";
import B from "./links.js";
import b from "./iterator.js";
function d(e, o) {
  e instanceof Map ? (e = [void 0, e], o === void 0 && (o = j)) : o === void 0 && (o = C);
  for (var f = new i(e), r, h = [f], a, t, n, p; r = h.pop(); )
    if ((t = o(r.data)) && (p = (t = Array.from(t)).length))
      for (r.children = t, n = p - 1; n >= 0; --n)
        h.push(a = t[n] = new i(t[n])), a.parent = r, a.depth = r.depth + 1;
  return f.eachBefore(D);
}
function k() {
  return d(this).eachBefore(x);
}
function C(e) {
  return e.children;
}
function j(e) {
  return Array.isArray(e) ? e[1] : null;
}
function x(e) {
  e.data.value !== void 0 && (e.value = e.data.value), e.data = e.data.data;
}
function D(e) {
  var o = 0;
  do
    e.height = o;
  while ((e = e.parent) && e.height < ++o);
}
function i(e) {
  this.data = e, this.depth = this.height = 0, this.parent = null;
}
i.prototype = d.prototype = {
  constructor: i,
  count: m,
  each: c,
  eachAfter: u,
  eachBefore: s,
  find: l,
  sum: _,
  sort: y,
  path: v,
  ancestors: g,
  descendants: A,
  leaves: w,
  links: B,
  copy: k,
  [Symbol.iterator]: b
};
export {
  i as Node,
  D as computeHeight,
  d as default
};
