import count_default from "./count.js";
import each_default from "./each.js";
import eachBefore_default from "./eachBefore.js";
import eachAfter_default from "./eachAfter.js";
import find_default from "./find.js";
import sum_default from "./sum.js";
import sort_default from "./sort.js";
import path_default from "./path.js";
import ancestors_default from "./ancestors.js";
import descendants_default from "./descendants.js";
import leaves_default from "./leaves.js";
import links_default from "./links.js";
import iterator_default from "./iterator.js";
function hierarchy(e, f) {
	e instanceof Map ? (e = [void 0, e], f === void 0 && (f = mapChildren)) : f === void 0 && (f = objectChildren);
	for (var p = new Node(e), m, h = [p], g, _, v, y; m = h.pop();) if ((_ = f(m.data)) && (y = (_ = Array.from(_)).length)) for (m.children = _, v = y - 1; v >= 0; --v) h.push(g = _[v] = new Node(_[v])), g.parent = m, g.depth = m.depth + 1;
	return p.eachBefore(computeHeight);
}
function node_copy() {
	return hierarchy(this).eachBefore(copyData);
}
function objectChildren(e) {
	return e.children;
}
function mapChildren(e) {
	return Array.isArray(e) ? e[1] : null;
}
function copyData(e) {
	e.data.value !== void 0 && (e.value = e.data.value), e.data = e.data.data;
}
function computeHeight(e) {
	var f = 0;
	do
		e.height = f;
	while ((e = e.parent) && e.height < ++f);
}
function Node(e) {
	this.data = e, 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
};
export { Node, hierarchy as default };
