"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const count = require("./src-hierarchy-count.cjs");
const each = require("./src-hierarchy-each.cjs");
const eachBefore = require("./src-hierarchy-eachBefore.cjs");
const eachAfter = require("./src-hierarchy-eachAfter.cjs");
const find = require("./src-hierarchy-find.cjs");
const sum = require("./src-hierarchy-sum.cjs");
const sort = require("./src-hierarchy-sort.cjs");
const path = require("./src-hierarchy-path.cjs");
const ancestors = require("./src-hierarchy-ancestors.cjs");
const descendants = require("./src-hierarchy-descendants.cjs");
const leaves = require("./src-hierarchy-leaves.cjs");
const links = require("./src-hierarchy-links.cjs");
const iterator = require("./src-hierarchy-iterator.cjs");
function hierarchy(data, children) {
  if (data instanceof Map) {
    data = [void 0, data];
    if (children === void 0) children = mapChildren;
  } else if (children === void 0) {
    children = objectChildren;
  }
  var root = new Node(data), node, nodes = [root], child, childs, i, n;
  while (node = nodes.pop()) {
    if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
      node.children = childs;
      for (i = n - 1; i >= 0; --i) {
        nodes.push(child = childs[i] = new Node(childs[i]));
        child.parent = node;
        child.depth = node.depth + 1;
      }
    }
  }
  return root.eachBefore(computeHeight);
}
function node_copy() {
  return hierarchy(this).eachBefore(copyData);
}
function objectChildren(d) {
  return d.children;
}
function mapChildren(d) {
  return Array.isArray(d) ? d[1] : null;
}
function copyData(node) {
  if (node.data.value !== void 0) node.value = node.data.value;
  node.data = node.data.data;
}
function computeHeight(node) {
  var height = 0;
  do
    node.height = height;
  while ((node = node.parent) && node.height < ++height);
}
function Node(data) {
  this.data = data;
  this.depth = this.height = 0;
  this.parent = null;
}
Node.prototype = hierarchy.prototype = {
  constructor: Node,
  count: count.default,
  each: each.default,
  eachAfter: eachAfter.default,
  eachBefore: eachBefore.default,
  find: find.default,
  sum: sum.default,
  sort: sort.default,
  path: path.default,
  ancestors: ancestors.default,
  descendants: descendants.default,
  leaves: leaves.default,
  links: links.default,
  copy: node_copy,
  [Symbol.iterator]: iterator.default
};
exports.Node = Node;
exports.computeHeight = computeHeight;
exports.default = hierarchy;
//# sourceMappingURL=src-hierarchy-index.cjs.map
