import { E as e, P as t, R as n, t as r } from "./isArrayLikeObject-DLIYDRni.js";
import { D as i, S as a, a as o, i as s, n as c, r as l, s as u, t as d } from "./_baseUniq-DHuXxixa.js";
import { t as f } from "./isEmpty-DhbfzuZy.js";
//#region node_modules/lodash-es/union.js
var p = e(function(e) {
	return d(a(e, 1, r, !0));
}), m = "\0", h = "\0", g = "", _ = class {
	constructor(e = {}) {
		this._isDirected = Object.prototype.hasOwnProperty.call(e, "directed") ? e.directed : !0, this._isMultigraph = Object.prototype.hasOwnProperty.call(e, "multigraph") ? e.multigraph : !1, this._isCompound = Object.prototype.hasOwnProperty.call(e, "compound") ? e.compound : !1, this._label = void 0, this._defaultNodeLabelFn = t(void 0), this._defaultEdgeLabelFn = t(void 0), this._nodes = {}, this._isCompound && (this._parent = {}, this._children = {}, this._children[h] = {}), this._in = {}, this._preds = {}, this._out = {}, this._sucs = {}, this._edgeObjs = {}, this._edgeLabels = {};
	}
	isDirected() {
		return this._isDirected;
	}
	isMultigraph() {
		return this._isMultigraph;
	}
	isCompound() {
		return this._isCompound;
	}
	setGraph(e) {
		return this._label = e, this;
	}
	graph() {
		return this._label;
	}
	setDefaultNodeLabel(e) {
		return n(e) || (e = t(e)), this._defaultNodeLabelFn = e, this;
	}
	nodeCount() {
		return this._nodeCount;
	}
	nodes() {
		return i(this._nodes);
	}
	sources() {
		var e = this;
		return o(this.nodes(), function(t) {
			return f(e._in[t]);
		});
	}
	sinks() {
		var e = this;
		return o(this.nodes(), function(t) {
			return f(e._out[t]);
		});
	}
	setNodes(e, t) {
		var n = arguments, r = this;
		return u(e, function(e) {
			n.length > 1 ? r.setNode(e, t) : r.setNode(e);
		}), this;
	}
	setNode(e, t) {
		return Object.prototype.hasOwnProperty.call(this._nodes, e) ? (arguments.length > 1 && (this._nodes[e] = t), this) : (this._nodes[e] = arguments.length > 1 ? t : this._defaultNodeLabelFn(e), this._isCompound && (this._parent[e] = h, this._children[e] = {}, this._children[h][e] = !0), this._in[e] = {}, this._preds[e] = {}, this._out[e] = {}, this._sucs[e] = {}, ++this._nodeCount, this);
	}
	node(e) {
		return this._nodes[e];
	}
	hasNode(e) {
		return Object.prototype.hasOwnProperty.call(this._nodes, e);
	}
	removeNode(e) {
		if (Object.prototype.hasOwnProperty.call(this._nodes, e)) {
			var t = (e) => this.removeEdge(this._edgeObjs[e]);
			delete this._nodes[e], this._isCompound && (this._removeFromParentsChildList(e), delete this._parent[e], u(this.children(e), (e) => {
				this.setParent(e);
			}), delete this._children[e]), u(i(this._in[e]), t), delete this._in[e], delete this._preds[e], u(i(this._out[e]), t), delete this._out[e], delete this._sucs[e], --this._nodeCount;
		}
		return this;
	}
	setParent(e, t) {
		if (!this._isCompound) throw Error("Cannot set parent in a non-compound graph");
		if (l(t)) t = h;
		else {
			t += "";
			for (var n = t; !l(n); n = this.parent(n)) if (n === e) throw Error("Setting " + t + " as parent of " + e + " would create a cycle");
			this.setNode(t);
		}
		return this.setNode(e), this._removeFromParentsChildList(e), this._parent[e] = t, this._children[t][e] = !0, this;
	}
	_removeFromParentsChildList(e) {
		delete this._children[this._parent[e]][e];
	}
	parent(e) {
		if (this._isCompound) {
			var t = this._parent[e];
			if (t !== h) return t;
		}
	}
	children(e) {
		if (l(e) && (e = h), this._isCompound) {
			var t = this._children[e];
			if (t) return i(t);
		} else if (e === h) return this.nodes();
		else if (this.hasNode(e)) return [];
	}
	predecessors(e) {
		var t = this._preds[e];
		if (t) return i(t);
	}
	successors(e) {
		var t = this._sucs[e];
		if (t) return i(t);
	}
	neighbors(e) {
		var t = this.predecessors(e);
		if (t) return p(t, this.successors(e));
	}
	isLeaf(e) {
		return (this.isDirected() ? this.successors(e) : this.neighbors(e)).length === 0;
	}
	filterNodes(e) {
		var t = new this.constructor({
			directed: this._isDirected,
			multigraph: this._isMultigraph,
			compound: this._isCompound
		});
		t.setGraph(this.graph());
		var n = this;
		u(this._nodes, function(n, r) {
			e(r) && t.setNode(r, n);
		}), u(this._edgeObjs, function(e) {
			t.hasNode(e.v) && t.hasNode(e.w) && t.setEdge(e, n.edge(e));
		});
		var r = {};
		function i(e) {
			var a = n.parent(e);
			return a === void 0 || t.hasNode(a) ? (r[e] = a, a) : a in r ? r[a] : i(a);
		}
		return this._isCompound && u(t.nodes(), function(e) {
			t.setParent(e, i(e));
		}), t;
	}
	setDefaultEdgeLabel(e) {
		return n(e) || (e = t(e)), this._defaultEdgeLabelFn = e, this;
	}
	edgeCount() {
		return this._edgeCount;
	}
	edges() {
		return s(this._edgeObjs);
	}
	setPath(e, t) {
		var n = this, r = arguments;
		return c(e, function(e, i) {
			return r.length > 1 ? n.setEdge(e, i, t) : n.setEdge(e, i), i;
		}), this;
	}
	setEdge() {
		var e, t, n, r, i = !1, a = arguments[0];
		typeof a == "object" && a && "v" in a ? (e = a.v, t = a.w, n = a.name, arguments.length === 2 && (r = arguments[1], i = !0)) : (e = a, t = arguments[1], n = arguments[3], arguments.length > 2 && (r = arguments[2], i = !0)), e = "" + e, t = "" + t, l(n) || (n = "" + n);
		var o = b(this._isDirected, e, t, n);
		if (Object.prototype.hasOwnProperty.call(this._edgeLabels, o)) return i && (this._edgeLabels[o] = r), this;
		if (!l(n) && !this._isMultigraph) throw Error("Cannot set a named edge when isMultigraph = false");
		this.setNode(e), this.setNode(t), this._edgeLabels[o] = i ? r : this._defaultEdgeLabelFn(e, t, n);
		var s = x(this._isDirected, e, t, n);
		return e = s.v, t = s.w, Object.freeze(s), this._edgeObjs[o] = s, v(this._preds[t], e), v(this._sucs[e], t), this._in[t][o] = s, this._out[e][o] = s, this._edgeCount++, this;
	}
	edge(e, t, n) {
		var r = arguments.length === 1 ? S(this._isDirected, arguments[0]) : b(this._isDirected, e, t, n);
		return this._edgeLabels[r];
	}
	hasEdge(e, t, n) {
		var r = arguments.length === 1 ? S(this._isDirected, arguments[0]) : b(this._isDirected, e, t, n);
		return Object.prototype.hasOwnProperty.call(this._edgeLabels, r);
	}
	removeEdge(e, t, n) {
		var r = arguments.length === 1 ? S(this._isDirected, arguments[0]) : b(this._isDirected, e, t, n), i = this._edgeObjs[r];
		return i && (e = i.v, t = i.w, delete this._edgeLabels[r], delete this._edgeObjs[r], y(this._preds[t], e), y(this._sucs[e], t), delete this._in[t][r], delete this._out[e][r], this._edgeCount--), this;
	}
	inEdges(e, t) {
		var n = this._in[e];
		if (n) {
			var r = s(n);
			return t ? o(r, function(e) {
				return e.v === t;
			}) : r;
		}
	}
	outEdges(e, t) {
		var n = this._out[e];
		if (n) {
			var r = s(n);
			return t ? o(r, function(e) {
				return e.w === t;
			}) : r;
		}
	}
	nodeEdges(e, t) {
		var n = this.inEdges(e, t);
		if (n) return n.concat(this.outEdges(e, t));
	}
};
_.prototype._nodeCount = 0, _.prototype._edgeCount = 0;
function v(e, t) {
	e[t] ? e[t]++ : e[t] = 1;
}
function y(e, t) {
	--e[t] || delete e[t];
}
function b(e, t, n, r) {
	var i = "" + t, a = "" + n;
	if (!e && i > a) {
		var o = i;
		i = a, a = o;
	}
	return i + g + a + g + (l(r) ? m : r);
}
function x(e, t, n, r) {
	var i = "" + t, a = "" + n;
	if (!e && i > a) {
		var o = i;
		i = a, a = o;
	}
	var s = {
		v: i,
		w: a
	};
	return r && (s.name = r), s;
}
function S(e, t) {
	return b(e, t.v, t.w, t.name);
}
//#endregion
export { _ as t };
