import e from "../../../../lodash-es/cloneDeep.js";
import t from "../../../../lodash-es/forEach.js";
import n from "../../../../lodash-es/map.js";
import r from "../../../../lodash-es/range.js";
import { Graph as i } from "../../graphlib/graph.js";
import "../../graphlib/index.js";
import { buildLayerMatrix as a, maxRank as o } from "../util.js";
import { addSubgraphConstraints as s } from "./add-subgraph-constraints.js";
import { buildLayerGraph as c } from "./build-layer-graph.js";
import { crossCount as l } from "./cross-count.js";
import { initOrder as u } from "./init-order.js";
import { sortSubgraph as d } from "./sort-subgraph.js";
//#region ../../node_modules/dagre-d3-es/src/dagre/order/index.js
function f(t) {
	var n = o(t), i = p(t, r(1, n + 1), "inEdges"), s = p(t, r(n - 1, -1, -1), "outEdges"), c = u(t);
	h(t, c);
	for (var d = Infinity, f, g = 0, _ = 0; _ < 4; ++g, ++_) {
		m(g % 2 ? i : s, g % 4 >= 2), c = a(t);
		var v = l(t, c);
		v < d && (_ = 0, f = e(c), d = v);
	}
	h(t, f);
}
function p(e, t, r) {
	return n(t, function(t) {
		return c(e, t, r);
	});
}
function m(e, n) {
	var r = new i();
	t(e, function(e) {
		var i = e.graph().root, a = d(e, i, r, n);
		t(a.vs, function(t, n) {
			e.node(t).order = n;
		}), s(e, r, a.vs);
	});
}
function h(e, n) {
	t(n, function(n) {
		t(n, function(t, n) {
			e.node(t).order = n;
		});
	});
}
//#endregion
export { f as order };

//# sourceMappingURL=index.js.map