import{c as ie,t as M,a as pe,g as K,k as p,i as se,d as ve,e as Ee}from"./_baseClone-BMmn5UJb.js";import{t as ue,M as Ae,u as me,U as Y,l as Z,q as J,S as F,v as Oe,w as Le,i as we,c as Pe,x as S,b as Q}from"./_initCloneObject-D0ofMy5o.js";import{i as A,a as be}from"./toString-DnxJX3Gz.js";import{ap as ae,aq as Ce,ar as ye,as as Re,at as N,au as X}from"./intro-DcDf2Rk3.js";import{S as I,a as W}from"./isSymbol-Br3Fhm6g.js";import{i as Ne}from"./isObject-C3e4t58V.js";import{a as Te}from"./parseCss-Cvj3m43l.js";function De(){}function Fe(n,e,r,t){for(var i=n.length,s=r+-1;++s-1}function fe(n,e){e=ie(e,n);for(var r=0,t=e.length;n!=null&&ra))return!1;var g=s.get(n),l=s.get(e);if(g&&l)return g==e&&l==n;var d=-1,h=!0,c=r&Ze?new C:void 0;for(s.set(n,e),s.set(e,n);++d=Hn){var g=Un(n);if(g)return U(g);u=!1,i=de,f=new C}else f=a;e:for(;++t1?i.setNode(s,r):i.setNode(s)}),this}setNode(e,r){return E(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=r),this):(this._nodes[e]=arguments.length>1?r:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=w,this._children[e]={},this._children[w][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 E(this._nodes,e)}removeNode(e){var r=this;if(E(this._nodes,e)){var t=function(i){r.removeEdge(r._edgeObjs[i])};delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],L(this.children(e),function(i){r.setParent(i)}),delete this._children[e]),L(p(this._in[e]),t),delete this._in[e],delete this._preds[e],L(p(this._out[e]),t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,r){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(P(r))r=w;else{r+="";for(var t=r;!P(t);t=this.parent(t))if(t===e)throw new Error("Setting "+r+" as parent of "+e+" would create a cycle");this.setNode(r)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=r,this._children[r][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var r=this._parent[e];if(r!==w)return r}}children(e){if(P(e)&&(e=w),this._isCompound){var r=this._children[e];if(r)return p(r)}else{if(e===w)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var r=this._preds[e];if(r)return p(r)}successors(e){var r=this._sucs[e];if(r)return p(r)}neighbors(e){var r=this.predecessors(e);if(r)return qn(r,this.successors(e))}isLeaf(e){var r;return this.isDirected()?r=this.successors(e):r=this.neighbors(e),r.length===0}filterNodes(e){var r=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});r.setGraph(this.graph());var t=this;L(this._nodes,function(u,a){e(a)&&r.setNode(a,u)}),L(this._edgeObjs,function(u){r.hasNode(u.v)&&r.hasNode(u.w)&&r.setEdge(u,t.edge(u))});var i={};function s(u){var a=t.parent(u);return a===void 0||r.hasNode(a)?(i[u]=a,a):a in i?i[a]:s(a)}return this._isCompound&&L(r.nodes(),function(u){r.setParent(u,s(u))}),r}setDefaultEdgeLabel(e){return Q(e)||(e=N(e)),this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return G(this._edgeObjs)}setPath(e,r){var t=this,i=arguments;return Gn(e,function(s,u){return i.length>1?t.setEdge(s,u,r):t.setEdge(s,u),u}),this}setEdge(){var e,r,t,i,s=!1,u=arguments[0];typeof u=="object"&&u!==null&&"v"in u?(e=u.v,r=u.w,t=u.name,arguments.length===2&&(i=arguments[1],s=!0)):(e=u,r=arguments[1],t=arguments[3],arguments.length>2&&(i=arguments[2],s=!0)),e=""+e,r=""+r,P(t)||(t=""+t);var a=b(this._isDirected,e,r,t);if(E(this._edgeLabels,a))return s&&(this._edgeLabels[a]=i),this;if(!P(t)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(r),this._edgeLabels[a]=s?i:this._defaultEdgeLabelFn(e,r,t);var f=Yn(this._isDirected,e,r,t);return e=f.v,r=f.w,Object.freeze(f),this._edgeObjs[a]=f,re(this._preds[r],e),re(this._sucs[e],r),this._in[r][a]=f,this._out[e][a]=f,this._edgeCount++,this}edge(e,r,t){var i=arguments.length===1?$(this._isDirected,arguments[0]):b(this._isDirected,e,r,t);return this._edgeLabels[i]}hasEdge(e,r,t){var i=arguments.length===1?$(this._isDirected,arguments[0]):b(this._isDirected,e,r,t);return E(this._edgeLabels,i)}removeEdge(e,r,t){var i=arguments.length===1?$(this._isDirected,arguments[0]):b(this._isDirected,e,r,t),s=this._edgeObjs[i];return s&&(e=s.v,r=s.w,delete this._edgeLabels[i],delete this._edgeObjs[i],te(this._preds[r],e),te(this._sucs[e],r),delete this._in[r][i],delete this._out[e][i],this._edgeCount--),this}inEdges(e,r){var t=this._in[e];if(t){var i=G(t);return r?D(i,function(s){return s.v===r}):i}}outEdges(e,r){var t=this._out[e];if(t){var i=G(t);return r?D(i,function(s){return s.w===r}):i}}nodeEdges(e,r){var t=this.inEdges(e,r);if(t)return t.concat(this.outEdges(e,r))}}ce.prototype._nodeCount=0;ce.prototype._edgeCount=0;function re(n,e){n[e]?n[e]++:n[e]=1}function te(n,e){--n[e]||delete n[e]}function b(n,e,r,t){var i=""+e,s=""+r;if(!n&&i>s){var u=i;i=s,s=u}return i+ne+s+ne+(P(t)?Kn:t)}function Yn(n,e,r,t){var i=""+e,s=""+r;if(!n&&i>s){var u=i;i=s,s=u}var a={v:i,w:s};return t&&(a.name=t),a}function $(n,e){return b(n,e.v,e.w,e.name)}export{ce as G,_e as a,Ue as b,Fe as c,B as d,Tn as e,L as f,Rn as g,E as h,P as i,fe as j,On as k,D as l,Gn as r,G as v};