import e from "../../../lodash-es/forEach.js";
import { addDummyNode as t } from "./util.js";
//#region ../../node_modules/dagre-d3-es/src/dagre/normalize.js
function n(t) {
	t.graph().dummyChains = [], e(t.edges(), function(e) {
		r(t, e);
	});
}
function r(e, n) {
	var r = n.v, i = e.node(r).rank, a = n.w, o = e.node(a).rank, s = n.name, c = e.edge(n), l = c.labelRank;
	if (o !== i + 1) {
		e.removeEdge(n);
		var u = void 0, d, f;
		for (f = 0, ++i; i < o; ++f, ++i) c.points = [], u = {
			width: 0,
			height: 0,
			edgeLabel: c,
			edgeObj: n,
			rank: i
		}, d = t(e, "edge", u, "_d"), i === l && (u.width = c.width, u.height = c.height, u.dummy = "edge-label", u.labelpos = c.labelpos), e.setEdge(r, d, { weight: c.weight }, s), f === 0 && e.graph().dummyChains.push(d), r = d;
		e.setEdge(r, a, { weight: c.weight }, s);
	}
}
function i(t) {
	e(t.graph().dummyChains, function(e) {
		var n = t.node(e), r = n.edgeLabel, i;
		for (t.setEdge(n.edgeObj, r); n.dummy;) i = t.successors(e)[0], t.removeNode(e), r.points.push({
			x: n.x,
			y: n.y
		}), n.dummy === "edge-label" && (r.x = n.x, r.y = n.y, r.width = n.width, r.height = n.height), e = i, n = t.node(e);
	});
}
//#endregion
export { n as run, i as undo };
