import { C as isArray_default, E as _Symbol_default, S as isObject_default, b as isFunction_default, d as isBuffer_default, l as _nodeUtil_default, r as _Stack_default, u as _baseUnary_default, w as isObjectLike_default } from "./_baseFor-BGiY-cm1.js";
import { d as _arrayMap_default, i as _arrayPush_default, r as _baseFlatten_default } from "./hasIn-COs6vImh.js";
import { n as _getTag_default, t as isEmpty_default } from "./isEmpty-Dd8mx_WL.js";
import { _ as _copyArray_default, a as _cloneArrayBuffer_default, c as keysIn_default, f as _copyObject_default, g as constant_default, i as _cloneTypedArray_default, n as isArrayLikeObject_default, o as _cloneBuffer_default, p as _assignValue_default, r as _initCloneObject_default, s as _getPrototype_default, u as _baseRest_default } from "./merge-CHn7Yx0N.js";
import { d as _baseGetAllKeys_default, f as _getSymbols_default, g as _arrayEach_default, i as forEach_default, m as keys_default, n as reduce_default, p as stubArray_default, r as filter_default, t as _baseUniq_default, u as _getAllKeys_default } from "./_baseUniq-CxZRxRRo.js";
function baseAssign(s, I) {
  return s && _copyObject_default(I, keys_default(I), s);
}
var _baseAssign_default = baseAssign;
function baseAssignIn(s, I) {
  return s && _copyObject_default(I, keysIn_default(I), s);
}
var _baseAssignIn_default = baseAssignIn;
function copySymbols(s, I) {
  return _copyObject_default(s, _getSymbols_default(s), I);
}
var _copySymbols_default = copySymbols, _getSymbolsIn_default = Object.getOwnPropertySymbols ? function(s) {
  for (var I = []; s; ) _arrayPush_default(I, _getSymbols_default(s)), s = _getPrototype_default(s);
  return I;
} : stubArray_default;
function copySymbolsIn(s, I) {
  return _copyObject_default(s, _getSymbolsIn_default(s), I);
}
var _copySymbolsIn_default = copySymbolsIn;
function getAllKeysIn(s) {
  return _baseGetAllKeys_default(s, keysIn_default, _getSymbolsIn_default);
}
var _getAllKeysIn_default = getAllKeysIn, hasOwnProperty = Object.prototype.hasOwnProperty;
function initCloneArray(s) {
  var I = s.length, L = new s.constructor(I);
  return I && typeof s[0] == "string" && hasOwnProperty.call(s, "index") && (L.index = s.index, L.input = s.input), L;
}
var _initCloneArray_default = initCloneArray;
function cloneDataView(s, I) {
  var L = I ? _cloneArrayBuffer_default(s.buffer) : s.buffer;
  return new s.constructor(L, s.byteOffset, s.byteLength);
}
var _cloneDataView_default = cloneDataView, reFlags = /\w*$/;
function cloneRegExp(s) {
  var I = new s.constructor(s.source, reFlags.exec(s));
  return I.lastIndex = s.lastIndex, I;
}
var _cloneRegExp_default = cloneRegExp, symbolProto = _Symbol_default ? _Symbol_default.prototype : void 0, symbolValueOf = symbolProto ? symbolProto.valueOf : void 0;
function cloneSymbol(s) {
  return symbolValueOf ? Object(symbolValueOf.call(s)) : {};
}
var _cloneSymbol_default = cloneSymbol, boolTag$1 = "[object Boolean]", dateTag$1 = "[object Date]", mapTag$2 = "[object Map]", numberTag$1 = "[object Number]", regexpTag$1 = "[object RegExp]", setTag$2 = "[object Set]", stringTag$1 = "[object String]", symbolTag$1 = "[object Symbol]", arrayBufferTag$1 = "[object ArrayBuffer]", dataViewTag$1 = "[object DataView]", float32Tag$1 = "[object Float32Array]", float64Tag$1 = "[object Float64Array]", int8Tag$1 = "[object Int8Array]", int16Tag$1 = "[object Int16Array]", int32Tag$1 = "[object Int32Array]", uint8Tag$1 = "[object Uint8Array]", uint8ClampedTag$1 = "[object Uint8ClampedArray]", uint16Tag$1 = "[object Uint16Array]", uint32Tag$1 = "[object Uint32Array]";
function initCloneByTag(s, I, L) {
  var R = s.constructor;
  switch (I) {
    case arrayBufferTag$1:
      return _cloneArrayBuffer_default(s);
    case boolTag$1:
    case dateTag$1:
      return new R(+s);
    case dataViewTag$1:
      return _cloneDataView_default(s, L);
    case float32Tag$1:
    case float64Tag$1:
    case int8Tag$1:
    case int16Tag$1:
    case int32Tag$1:
    case uint8Tag$1:
    case uint8ClampedTag$1:
    case uint16Tag$1:
    case uint32Tag$1:
      return _cloneTypedArray_default(s, L);
    case mapTag$2:
      return new R();
    case numberTag$1:
    case stringTag$1:
      return new R(s);
    case regexpTag$1:
      return _cloneRegExp_default(s);
    case setTag$2:
      return new R();
    case symbolTag$1:
      return _cloneSymbol_default(s);
  }
}
var _initCloneByTag_default = initCloneByTag, mapTag$1 = "[object Map]";
function baseIsMap(s) {
  return isObjectLike_default(s) && _getTag_default(s) == mapTag$1;
}
var _baseIsMap_default = baseIsMap, nodeIsMap = _nodeUtil_default && _nodeUtil_default.isMap, isMap_default = nodeIsMap ? _baseUnary_default(nodeIsMap) : _baseIsMap_default, setTag$1 = "[object Set]";
function baseIsSet(s) {
  return isObjectLike_default(s) && _getTag_default(s) == setTag$1;
}
var _baseIsSet_default = baseIsSet, nodeIsSet = _nodeUtil_default && _nodeUtil_default.isSet, isSet_default = nodeIsSet ? _baseUnary_default(nodeIsSet) : _baseIsSet_default, CLONE_DEEP_FLAG = 1, CLONE_FLAT_FLAG = 2, CLONE_SYMBOLS_FLAG = 4, argsTag = "[object Arguments]", arrayTag = "[object Array]", boolTag = "[object Boolean]", dateTag = "[object Date]", errorTag = "[object Error]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", mapTag = "[object Map]", numberTag = "[object Number]", objectTag = "[object Object]", regexpTag = "[object RegExp]", setTag = "[object Set]", stringTag = "[object String]", symbolTag = "[object Symbol]", weakMapTag = "[object WeakMap]", arrayBufferTag = "[object ArrayBuffer]", dataViewTag = "[object DataView]", float32Tag = "[object Float32Array]", float64Tag = "[object Float64Array]", int8Tag = "[object Int8Array]", int16Tag = "[object Int16Array]", int32Tag = "[object Int32Array]", uint8Tag = "[object Uint8Array]", uint8ClampedTag = "[object Uint8ClampedArray]", uint16Tag = "[object Uint16Array]", uint32Tag = "[object Uint32Array]", cloneableTags = {};
cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = cloneableTags[boolTag] = cloneableTags[dateTag] = cloneableTags[float32Tag] = cloneableTags[float64Tag] = cloneableTags[int8Tag] = cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[mapTag] = cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[regexpTag] = cloneableTags[setTag] = cloneableTags[stringTag] = cloneableTags[symbolTag] = cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true, cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false;
function baseClone(I, R, B, H, U, W) {
  var G, K = R & CLONE_DEEP_FLAG, q = R & CLONE_FLAT_FLAG, J = R & CLONE_SYMBOLS_FLAG;
  if (B && (G = U ? B(I, H, U, W) : B(I)), G !== void 0) return G;
  if (!isObject_default(I)) return I;
  var Y = isArray_default(I);
  if (Y) {
    if (G = _initCloneArray_default(I), !K) return _copyArray_default(I, G);
  } else {
    var X = _getTag_default(I), Z = X == funcTag || X == genTag;
    if (isBuffer_default(I)) return _cloneBuffer_default(I, K);
    if (X == objectTag || X == argsTag || Z && !U) {
      if (G = q || Z ? {} : _initCloneObject_default(I), !K) return q ? _copySymbolsIn_default(I, _baseAssignIn_default(G, I)) : _copySymbols_default(I, _baseAssign_default(G, I));
    } else {
      if (!cloneableTags[X]) return U ? I : {};
      G = _initCloneByTag_default(I, X, K);
    }
  }
  W || (W = new _Stack_default());
  var Q = W.get(I);
  if (Q) return Q;
  W.set(I, G), isSet_default(I) ? I.forEach(function(s) {
    G.add(baseClone(s, R, B, s, I, W));
  }) : isMap_default(I) && I.forEach(function(s, L) {
    G.set(L, baseClone(s, R, B, L, I, W));
  });
  var $ = Y ? void 0 : (J ? q ? _getAllKeysIn_default : _getAllKeys_default : q ? keysIn_default : keys_default)(I);
  return _arrayEach_default($ || I, function(s, L) {
    $ && (L = s, s = I[L]), _assignValue_default(G, L, baseClone(s, R, B, L, I, W));
  }), G;
}
var _baseClone_default = baseClone;
function baseValues(s, I) {
  return _arrayMap_default(I, function(I2) {
    return s[I2];
  });
}
var _baseValues_default = baseValues;
function values(s) {
  return s == null ? [] : _baseValues_default(s, keys_default(s));
}
var values_default = values;
function isUndefined(s) {
  return s === void 0;
}
var isUndefined_default = isUndefined, union_default = _baseRest_default(function(s) {
  return _baseUniq_default(_baseFlatten_default(s, 1, isArrayLikeObject_default, true));
}), DEFAULT_EDGE_NAME = "\0", GRAPH_NODE = "\0", EDGE_KEY_DELIM = "", Graph = class {
  constructor(s = {}) {
    this._isDirected = Object.prototype.hasOwnProperty.call(s, "directed") ? s.directed : true, this._isMultigraph = Object.prototype.hasOwnProperty.call(s, "multigraph") ? s.multigraph : false, this._isCompound = Object.prototype.hasOwnProperty.call(s, "compound") ? s.compound : false, this._label = void 0, this._defaultNodeLabelFn = constant_default(void 0), this._defaultEdgeLabelFn = constant_default(void 0), this._nodes = {}, this._isCompound && (this._parent = {}, this._children = {}, this._children[GRAPH_NODE] = {}), 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(s) {
    return this._label = s, this;
  }
  graph() {
    return this._label;
  }
  setDefaultNodeLabel(s) {
    return isFunction_default(s) || (s = constant_default(s)), this._defaultNodeLabelFn = s, this;
  }
  nodeCount() {
    return this._nodeCount;
  }
  nodes() {
    return keys_default(this._nodes);
  }
  sources() {
    var s = this;
    return filter_default(this.nodes(), function(I) {
      return isEmpty_default(s._in[I]);
    });
  }
  sinks() {
    var s = this;
    return filter_default(this.nodes(), function(I) {
      return isEmpty_default(s._out[I]);
    });
  }
  setNodes(s, I) {
    var L = arguments, R = this;
    return forEach_default(s, function(s2) {
      L.length > 1 ? R.setNode(s2, I) : R.setNode(s2);
    }), this;
  }
  setNode(s, I) {
    return Object.prototype.hasOwnProperty.call(this._nodes, s) ? (arguments.length > 1 && (this._nodes[s] = I), this) : (this._nodes[s] = arguments.length > 1 ? I : this._defaultNodeLabelFn(s), this._isCompound && (this._parent[s] = GRAPH_NODE, this._children[s] = {}, this._children[GRAPH_NODE][s] = true), this._in[s] = {}, this._preds[s] = {}, this._out[s] = {}, this._sucs[s] = {}, ++this._nodeCount, this);
  }
  node(s) {
    return this._nodes[s];
  }
  hasNode(s) {
    return Object.prototype.hasOwnProperty.call(this._nodes, s);
  }
  removeNode(s) {
    if (Object.prototype.hasOwnProperty.call(this._nodes, s)) {
      var I = (s2) => this.removeEdge(this._edgeObjs[s2]);
      delete this._nodes[s], this._isCompound && (this._removeFromParentsChildList(s), delete this._parent[s], forEach_default(this.children(s), (s2) => {
        this.setParent(s2);
      }), delete this._children[s]), forEach_default(keys_default(this._in[s]), I), delete this._in[s], delete this._preds[s], forEach_default(keys_default(this._out[s]), I), delete this._out[s], delete this._sucs[s], --this._nodeCount;
    }
    return this;
  }
  setParent(s, I) {
    if (!this._isCompound) throw Error("Cannot set parent in a non-compound graph");
    if (isUndefined_default(I)) I = GRAPH_NODE;
    else {
      I += "";
      for (var L = I; !isUndefined_default(L); L = this.parent(L)) if (L === s) throw Error("Setting " + I + " as parent of " + s + " would create a cycle");
      this.setNode(I);
    }
    return this.setNode(s), this._removeFromParentsChildList(s), this._parent[s] = I, this._children[I][s] = true, this;
  }
  _removeFromParentsChildList(s) {
    delete this._children[this._parent[s]][s];
  }
  parent(s) {
    if (this._isCompound) {
      var I = this._parent[s];
      if (I !== GRAPH_NODE) return I;
    }
  }
  children(s) {
    if (isUndefined_default(s) && (s = GRAPH_NODE), this._isCompound) {
      var I = this._children[s];
      if (I) return keys_default(I);
    } else if (s === GRAPH_NODE) return this.nodes();
    else if (this.hasNode(s)) return [];
  }
  predecessors(s) {
    var I = this._preds[s];
    if (I) return keys_default(I);
  }
  successors(s) {
    var I = this._sucs[s];
    if (I) return keys_default(I);
  }
  neighbors(s) {
    var I = this.predecessors(s);
    if (I) return union_default(I, this.successors(s));
  }
  isLeaf(s) {
    return (this.isDirected() ? this.successors(s) : this.neighbors(s)).length === 0;
  }
  filterNodes(s) {
    var I = new this.constructor({
      directed: this._isDirected,
      multigraph: this._isMultigraph,
      compound: this._isCompound
    });
    I.setGraph(this.graph());
    var L = this;
    forEach_default(this._nodes, function(L2, R2) {
      s(R2) && I.setNode(R2, L2);
    }), forEach_default(this._edgeObjs, function(s2) {
      I.hasNode(s2.v) && I.hasNode(s2.w) && I.setEdge(s2, L.edge(s2));
    });
    var R = {};
    function z(s2) {
      var B = L.parent(s2);
      return B === void 0 || I.hasNode(B) ? (R[s2] = B, B) : B in R ? R[B] : z(B);
    }
    return this._isCompound && forEach_default(I.nodes(), function(s2) {
      I.setParent(s2, z(s2));
    }), I;
  }
  setDefaultEdgeLabel(s) {
    return isFunction_default(s) || (s = constant_default(s)), this._defaultEdgeLabelFn = s, this;
  }
  edgeCount() {
    return this._edgeCount;
  }
  edges() {
    return values_default(this._edgeObjs);
  }
  setPath(s, I) {
    var L = this, R = arguments;
    return reduce_default(s, function(s2, z) {
      return R.length > 1 ? L.setEdge(s2, z, I) : L.setEdge(s2, z), z;
    }), this;
  }
  setEdge() {
    var s, I, L, R, z = false, B = arguments[0];
    typeof B == "object" && B && "v" in B ? (s = B.v, I = B.w, L = B.name, arguments.length === 2 && (R = arguments[1], z = true)) : (s = B, I = arguments[1], L = arguments[3], arguments.length > 2 && (R = arguments[2], z = true)), s = "" + s, I = "" + I, isUndefined_default(L) || (L = "" + L);
    var V = edgeArgsToId(this._isDirected, s, I, L);
    if (Object.prototype.hasOwnProperty.call(this._edgeLabels, V)) return z && (this._edgeLabels[V] = R), this;
    if (!isUndefined_default(L) && !this._isMultigraph) throw Error("Cannot set a named edge when isMultigraph = false");
    this.setNode(s), this.setNode(I), this._edgeLabels[V] = z ? R : this._defaultEdgeLabelFn(s, I, L);
    var H = edgeArgsToObj(this._isDirected, s, I, L);
    return s = H.v, I = H.w, Object.freeze(H), this._edgeObjs[V] = H, incrementOrInitEntry(this._preds[I], s), incrementOrInitEntry(this._sucs[s], I), this._in[I][V] = H, this._out[s][V] = H, this._edgeCount++, this;
  }
  edge(s, I, L) {
    var R = arguments.length === 1 ? edgeObjToId(this._isDirected, arguments[0]) : edgeArgsToId(this._isDirected, s, I, L);
    return this._edgeLabels[R];
  }
  hasEdge(s, I, L) {
    var R = arguments.length === 1 ? edgeObjToId(this._isDirected, arguments[0]) : edgeArgsToId(this._isDirected, s, I, L);
    return Object.prototype.hasOwnProperty.call(this._edgeLabels, R);
  }
  removeEdge(s, I, L) {
    var R = arguments.length === 1 ? edgeObjToId(this._isDirected, arguments[0]) : edgeArgsToId(this._isDirected, s, I, L), z = this._edgeObjs[R];
    return z && (s = z.v, I = z.w, delete this._edgeLabels[R], delete this._edgeObjs[R], decrementOrRemoveEntry(this._preds[I], s), decrementOrRemoveEntry(this._sucs[s], I), delete this._in[I][R], delete this._out[s][R], this._edgeCount--), this;
  }
  inEdges(s, I) {
    var L = this._in[s];
    if (L) {
      var R = values_default(L);
      return I ? filter_default(R, function(s2) {
        return s2.v === I;
      }) : R;
    }
  }
  outEdges(s, I) {
    var L = this._out[s];
    if (L) {
      var R = values_default(L);
      return I ? filter_default(R, function(s2) {
        return s2.w === I;
      }) : R;
    }
  }
  nodeEdges(s, I) {
    var L = this.inEdges(s, I);
    if (L) return L.concat(this.outEdges(s, I));
  }
};
Graph.prototype._nodeCount = 0, Graph.prototype._edgeCount = 0;
function incrementOrInitEntry(s, I) {
  s[I] ? s[I]++ : s[I] = 1;
}
function decrementOrRemoveEntry(s, I) {
  --s[I] || delete s[I];
}
function edgeArgsToId(s, I, L, R) {
  var z = "" + I, B = "" + L;
  if (!s && z > B) {
    var V = z;
    z = B, B = V;
  }
  return z + EDGE_KEY_DELIM + B + EDGE_KEY_DELIM + (isUndefined_default(R) ? DEFAULT_EDGE_NAME : R);
}
function edgeArgsToObj(s, I, L, R) {
  var z = "" + I, B = "" + L;
  if (!s && z > B) {
    var V = z;
    z = B, B = V;
  }
  var H = {
    v: z,
    w: B
  };
  return R && (H.name = R), H;
}
function edgeObjToId(s, I) {
  return edgeArgsToId(s, I.v, I.w, I.name);
}
export {
  _baseClone_default as i,
  isUndefined_default as n,
  values_default as r,
  Graph as t
};
