UNPKG

bknd

Version:

Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.

2 lines (1 loc) 45.4 kB
import{g as nt,r as it,j as A,D as Qe,t as at,H as Ke,P as X,T as st,a as ot,u as dt,b as ut,M as lt,R as ht,C as ft,c as ct}from"./main-CfjI0j-e.js";var Z,Je;function ze(){if(Je)return Z;Je=1;var v="\0",p="\0",u="";class d{_isDirected=!0;_isMultigraph=!1;_isCompound=!1;_label;_defaultNodeLabelFn=()=>{};_defaultEdgeLabelFn=()=>{};_nodes={};_in={};_preds={};_out={};_sucs={};_edgeObjs={};_edgeLabels={};_nodeCount=0;_edgeCount=0;_parent;_children;constructor(r){r&&(this._isDirected=Object.hasOwn(r,"directed")?r.directed:!0,this._isMultigraph=Object.hasOwn(r,"multigraph")?r.multigraph:!1,this._isCompound=Object.hasOwn(r,"compound")?r.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children[p]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(r){return this._label=r,this}graph(){return this._label}setDefaultNodeLabel(r){return this._defaultNodeLabelFn=r,typeof r!="function"&&(this._defaultNodeLabelFn=()=>r),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var r=this;return this.nodes().filter(t=>Object.keys(r._in[t]).length===0)}sinks(){var r=this;return this.nodes().filter(t=>Object.keys(r._out[t]).length===0)}setNodes(r,t){var l=arguments,h=this;return r.forEach(function(w){l.length>1?h.setNode(w,t):h.setNode(w)}),this}setNode(r,t){return Object.hasOwn(this._nodes,r)?(arguments.length>1&&(this._nodes[r]=t),this):(this._nodes[r]=arguments.length>1?t:this._defaultNodeLabelFn(r),this._isCompound&&(this._parent[r]=p,this._children[r]={},this._children[p][r]=!0),this._in[r]={},this._preds[r]={},this._out[r]={},this._sucs[r]={},++this._nodeCount,this)}node(r){return this._nodes[r]}hasNode(r){return Object.hasOwn(this._nodes,r)}removeNode(r){var t=this;if(Object.hasOwn(this._nodes,r)){var l=h=>t.removeEdge(t._edgeObjs[h]);delete this._nodes[r],this._isCompound&&(this._removeFromParentsChildList(r),delete this._parent[r],this.children(r).forEach(function(h){t.setParent(h)}),delete this._children[r]),Object.keys(this._in[r]).forEach(l),delete this._in[r],delete this._preds[r],Object.keys(this._out[r]).forEach(l),delete this._out[r],delete this._sucs[r],--this._nodeCount}return this}setParent(r,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(t===void 0)t=p;else{t+="";for(var l=t;l!==void 0;l=this.parent(l))if(l===r)throw new Error("Setting "+t+" as parent of "+r+" would create a cycle");this.setNode(t)}return this.setNode(r),this._removeFromParentsChildList(r),this._parent[r]=t,this._children[t][r]=!0,this}_removeFromParentsChildList(r){delete this._children[this._parent[r]][r]}parent(r){if(this._isCompound){var t=this._parent[r];if(t!==p)return t}}children(r=p){if(this._isCompound){var t=this._children[r];if(t)return Object.keys(t)}else{if(r===p)return this.nodes();if(this.hasNode(r))return[]}}predecessors(r){var t=this._preds[r];if(t)return Object.keys(t)}successors(r){var t=this._sucs[r];if(t)return Object.keys(t)}neighbors(r){var t=this.predecessors(r);if(t){const h=new Set(t);for(var l of this.successors(r))h.add(l);return Array.from(h.values())}}isLeaf(r){var t;return this.isDirected()?t=this.successors(r):t=this.neighbors(r),t.length===0}filterNodes(r){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var l=this;Object.entries(this._nodes).forEach(function([j,c]){r(j)&&t.setNode(j,c)}),Object.values(this._edgeObjs).forEach(function(j){t.hasNode(j.v)&&t.hasNode(j.w)&&t.setEdge(j,l.edge(j))});var h={};function w(j){var c=l.parent(j);return c===void 0||t.hasNode(c)?(h[j]=c,c):c in h?h[c]:w(c)}return this._isCompound&&t.nodes().forEach(j=>t.setParent(j,w(j))),t}setDefaultEdgeLabel(r){return this._defaultEdgeLabelFn=r,typeof r!="function"&&(this._defaultEdgeLabelFn=()=>r),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(r,t){var l=this,h=arguments;return r.reduce(function(w,j){return h.length>1?l.setEdge(w,j,t):l.setEdge(w,j),j}),this}setEdge(){var r,t,l,h,w=!1,j=arguments[0];typeof j=="object"&&j!==null&&"v"in j?(r=j.v,t=j.w,l=j.name,arguments.length===2&&(h=arguments[1],w=!0)):(r=j,t=arguments[1],l=arguments[3],arguments.length>2&&(h=arguments[2],w=!0)),r=""+r,t=""+t,l!==void 0&&(l=""+l);var c=e(this._isDirected,r,t,l);if(Object.hasOwn(this._edgeLabels,c))return w&&(this._edgeLabels[c]=h),this;if(l!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(r),this.setNode(t),this._edgeLabels[c]=w?h:this._defaultEdgeLabelFn(r,t,l);var E=s(this._isDirected,r,t,l);return r=E.v,t=E.w,Object.freeze(E),this._edgeObjs[c]=E,a(this._preds[t],r),a(this._sucs[r],t),this._in[t][c]=E,this._out[r][c]=E,this._edgeCount++,this}edge(r,t,l){var h=arguments.length===1?i(this._isDirected,arguments[0]):e(this._isDirected,r,t,l);return this._edgeLabels[h]}edgeAsObj(){const r=this.edge(...arguments);return typeof r!="object"?{label:r}:r}hasEdge(r,t,l){var h=arguments.length===1?i(this._isDirected,arguments[0]):e(this._isDirected,r,t,l);return Object.hasOwn(this._edgeLabels,h)}removeEdge(r,t,l){var h=arguments.length===1?i(this._isDirected,arguments[0]):e(this._isDirected,r,t,l),w=this._edgeObjs[h];return w&&(r=w.v,t=w.w,delete this._edgeLabels[h],delete this._edgeObjs[h],n(this._preds[t],r),n(this._sucs[r],t),delete this._in[t][h],delete this._out[r][h],this._edgeCount--),this}inEdges(r,t){var l=this._in[r];if(l){var h=Object.values(l);return t?h.filter(w=>w.v===t):h}}outEdges(r,t){var l=this._out[r];if(l){var h=Object.values(l);return t?h.filter(w=>w.w===t):h}}nodeEdges(r,t){var l=this.inEdges(r,t);if(l)return l.concat(this.outEdges(r,t))}}function a(o,r){o[r]?o[r]++:o[r]=1}function n(o,r){--o[r]||delete o[r]}function e(o,r,t,l){var h=""+r,w=""+t;if(!o&&h>w){var j=h;h=w,w=j}return h+u+w+u+(l===void 0?v:l)}function s(o,r,t,l){var h=""+r,w=""+t;if(!o&&h>w){var j=h;h=w,w=j}var c={v:h,w};return l&&(c.name=l),c}function i(o,r){return e(o,r.v,r.w,r.name)}return Z=d,Z}var ee,Ze;function pt(){return Ze||(Ze=1,ee="2.2.4"),ee}var re,er;function mt(){return er||(er=1,re={Graph:ze(),version:pt()}),re}var te,rr;function bt(){if(rr)return te;rr=1;var v=ze();te={write:p,read:a};function p(n){var e={options:{directed:n.isDirected(),multigraph:n.isMultigraph(),compound:n.isCompound()},nodes:u(n),edges:d(n)};return n.graph()!==void 0&&(e.value=structuredClone(n.graph())),e}function u(n){return n.nodes().map(function(e){var s=n.node(e),i=n.parent(e),o={v:e};return s!==void 0&&(o.value=s),i!==void 0&&(o.parent=i),o})}function d(n){return n.edges().map(function(e){var s=n.edge(e),i={v:e.v,w:e.w};return e.name!==void 0&&(i.name=e.name),s!==void 0&&(i.value=s),i})}function a(n){var e=new v(n.options).setGraph(n.value);return n.nodes.forEach(function(s){e.setNode(s.v,s.value),s.parent&&e.setParent(s.v,s.parent)}),n.edges.forEach(function(s){e.setEdge({v:s.v,w:s.w,name:s.name},s.value)}),e}return te}var ne,tr;function gt(){if(tr)return ne;tr=1,ne=v;function v(p){var u={},d=[],a;function n(e){Object.hasOwn(u,e)||(u[e]=!0,a.push(e),p.successors(e).forEach(n),p.predecessors(e).forEach(n))}return p.nodes().forEach(function(e){a=[],n(e),a.length&&d.push(a)}),d}return ne}var ie,nr;function $r(){if(nr)return ie;nr=1;class v{_arr=[];_keyIndices={};size(){return this._arr.length}keys(){return this._arr.map(function(u){return u.key})}has(u){return Object.hasOwn(this._keyIndices,u)}priority(u){var d=this._keyIndices[u];if(d!==void 0)return this._arr[d].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(u,d){var a=this._keyIndices;if(u=String(u),!Object.hasOwn(a,u)){var n=this._arr,e=n.length;return a[u]=e,n.push({key:u,priority:d}),this._decrease(e),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var u=this._arr.pop();return delete this._keyIndices[u.key],this._heapify(0),u.key}decrease(u,d){var a=this._keyIndices[u];if(d>this._arr[a].priority)throw new Error("New priority is greater than current priority. Key: "+u+" Old: "+this._arr[a].priority+" New: "+d);this._arr[a].priority=d,this._decrease(a)}_heapify(u){var d=this._arr,a=2*u,n=a+1,e=u;a<d.length&&(e=d[a].priority<d[e].priority?a:e,n<d.length&&(e=d[n].priority<d[e].priority?n:e),e!==u&&(this._swap(u,e),this._heapify(e)))}_decrease(u){for(var d=this._arr,a=d[u].priority,n;u!==0&&(n=u>>1,!(d[n].priority<a));)this._swap(u,n),u=n}_swap(u,d){var a=this._arr,n=this._keyIndices,e=a[u],s=a[d];a[u]=s,a[d]=e,n[s.key]=u,n[e.key]=d}}return ie=v,ie}var ae,ir;function Ur(){if(ir)return ae;ir=1;var v=$r();ae=u;var p=()=>1;function u(a,n,e,s){return d(a,String(n),e||p,s||function(i){return a.outEdges(i)})}function d(a,n,e,s){var i={},o=new v,r,t,l=function(h){var w=h.v!==r?h.v:h.w,j=i[w],c=e(h),E=t.distance+c;if(c<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+h+" Weight: "+c);E<j.distance&&(j.distance=E,j.predecessor=r,o.decrease(w,E))};for(a.nodes().forEach(function(h){var w=h===n?0:Number.POSITIVE_INFINITY;i[h]={distance:w},o.add(h,w)});o.size()>0&&(r=o.removeMin(),t=i[r],t.distance!==Number.POSITIVE_INFINITY);)s(r).forEach(l);return i}return ae}var se,ar;function vt(){if(ar)return se;ar=1;var v=Ur();se=p;function p(u,d,a){return u.nodes().reduce(function(n,e){return n[e]=v(u,e,d,a),n},{})}return se}var oe,sr;function Xr(){if(sr)return oe;sr=1,oe=v;function v(p){var u=0,d=[],a={},n=[];function e(s){var i=a[s]={onStack:!0,lowlink:u,index:u++};if(d.push(s),p.successors(s).forEach(function(t){Object.hasOwn(a,t)?a[t].onStack&&(i.lowlink=Math.min(i.lowlink,a[t].index)):(e(t),i.lowlink=Math.min(i.lowlink,a[t].lowlink))}),i.lowlink===i.index){var o=[],r;do r=d.pop(),a[r].onStack=!1,o.push(r);while(s!==r);n.push(o)}}return p.nodes().forEach(function(s){Object.hasOwn(a,s)||e(s)}),n}return oe}var de,or;function wt(){if(or)return de;or=1;var v=Xr();de=p;function p(u){return v(u).filter(function(d){return d.length>1||d.length===1&&u.hasEdge(d[0],d[0])})}return de}var ue,dr;function Et(){if(dr)return ue;dr=1,ue=p;var v=()=>1;function p(d,a,n){return u(d,a||v,n||function(e){return d.outEdges(e)})}function u(d,a,n){var e={},s=d.nodes();return s.forEach(function(i){e[i]={},e[i][i]={distance:0},s.forEach(function(o){i!==o&&(e[i][o]={distance:Number.POSITIVE_INFINITY})}),n(i).forEach(function(o){var r=o.v===i?o.w:o.v,t=a(o);e[i][r]={distance:t,predecessor:i}})}),s.forEach(function(i){var o=e[i];s.forEach(function(r){var t=e[r];s.forEach(function(l){var h=t[i],w=o[l],j=t[l],c=h.distance+w.distance;c<j.distance&&(j.distance=c,j.predecessor=w.predecessor)})})}),e}return ue}var le,ur;function Qr(){if(ur)return le;ur=1;function v(u){var d={},a={},n=[];function e(s){if(Object.hasOwn(a,s))throw new p;Object.hasOwn(d,s)||(a[s]=!0,d[s]=!0,u.predecessors(s).forEach(e),delete a[s],n.push(s))}if(u.sinks().forEach(e),Object.keys(d).length!==u.nodeCount())throw new p;return n}class p extends Error{constructor(){super(...arguments)}}return le=v,v.CycleException=p,le}var he,lr;function yt(){if(lr)return he;lr=1;var v=Qr();he=p;function p(u){try{v(u)}catch(d){if(d instanceof v.CycleException)return!1;throw d}return!0}return he}var fe,hr;function Kr(){if(hr)return fe;hr=1,fe=v;function v(a,n,e){Array.isArray(n)||(n=[n]);var s=a.isDirected()?t=>a.successors(t):t=>a.neighbors(t),i=e==="post"?p:u,o=[],r={};return n.forEach(t=>{if(!a.hasNode(t))throw new Error("Graph does not have node: "+t);i(t,s,r,o)}),o}function p(a,n,e,s){for(var i=[[a,!1]];i.length>0;){var o=i.pop();o[1]?s.push(o[0]):Object.hasOwn(e,o[0])||(e[o[0]]=!0,i.push([o[0],!0]),d(n(o[0]),r=>i.push([r,!1])))}}function u(a,n,e,s){for(var i=[a];i.length>0;){var o=i.pop();Object.hasOwn(e,o)||(e[o]=!0,s.push(o),d(n(o),r=>i.push(r)))}}function d(a,n){for(var e=a.length;e--;)n(a[e],e,a);return a}return fe}var ce,fr;function _t(){if(fr)return ce;fr=1;var v=Kr();ce=p;function p(u,d){return v(u,d,"post")}return ce}var pe,cr;function kt(){if(cr)return pe;cr=1;var v=Kr();pe=p;function p(u,d){return v(u,d,"pre")}return pe}var me,pr;function Ot(){if(pr)return me;pr=1;var v=ze(),p=$r();me=u;function u(d,a){var n=new v,e={},s=new p,i;function o(t){var l=t.v===i?t.w:t.v,h=s.priority(l);if(h!==void 0){var w=a(t);w<h&&(e[l]=i,s.decrease(l,w))}}if(d.nodeCount()===0)return n;d.nodes().forEach(function(t){s.add(t,Number.POSITIVE_INFINITY),n.setNode(t)}),s.decrease(d.nodes()[0],0);for(var r=!1;s.size()>0;){if(i=s.removeMin(),Object.hasOwn(e,i))n.setEdge(i,e[i]);else{if(r)throw new Error("Input graph is not connected: "+d);r=!0}d.nodeEdges(i).forEach(o)}return n}return me}var be,mr;function Nt(){return mr||(mr=1,be={components:gt(),dijkstra:Ur(),dijkstraAll:vt(),findCycles:wt(),floydWarshall:Et(),isAcyclic:yt(),postorder:_t(),preorder:kt(),prim:Ot(),tarjan:Xr(),topsort:Qr()}),be}var ge,br;function Y(){if(br)return ge;br=1;var v=mt();return ge={Graph:v.Graph,json:bt(),alg:Nt(),version:v.version},ge}var ve,gr;function xt(){if(gr)return ve;gr=1;class v{constructor(){let a={};a._next=a._prev=a,this._sentinel=a}dequeue(){let a=this._sentinel,n=a._prev;if(n!==a)return p(n),n}enqueue(a){let n=this._sentinel;a._prev&&a._next&&p(a),a._next=n._next,n._next._prev=a,n._next=a,a._prev=n}toString(){let a=[],n=this._sentinel,e=n._prev;for(;e!==n;)a.push(JSON.stringify(e,u)),e=e._prev;return"["+a.join(", ")+"]"}}function p(d){d._prev._next=d._next,d._next._prev=d._prev,delete d._next,delete d._prev}function u(d,a){if(d!=="_next"&&d!=="_prev")return a}return ve=v,ve}var we,vr;function jt(){if(vr)return we;vr=1;let v=Y().Graph,p=xt();we=d;let u=()=>1;function d(o,r){if(o.nodeCount()<=1)return[];let t=e(o,r||u);return a(t.graph,t.buckets,t.zeroIdx).flatMap(h=>o.outEdges(h.v,h.w))}function a(o,r,t){let l=[],h=r[r.length-1],w=r[0],j;for(;o.nodeCount();){for(;j=w.dequeue();)n(o,r,t,j);for(;j=h.dequeue();)n(o,r,t,j);if(o.nodeCount()){for(let c=r.length-2;c>0;--c)if(j=r[c].dequeue(),j){l=l.concat(n(o,r,t,j,!0));break}}}return l}function n(o,r,t,l,h){let w=h?[]:void 0;return o.inEdges(l.v).forEach(j=>{let c=o.edge(j),E=o.node(j.v);h&&w.push({v:j.v,w:j.w}),E.out-=c,s(r,t,E)}),o.outEdges(l.v).forEach(j=>{let c=o.edge(j),E=j.w,m=o.node(E);m.in-=c,s(r,t,m)}),o.removeNode(l.v),w}function e(o,r){let t=new v,l=0,h=0;o.nodes().forEach(c=>{t.setNode(c,{v:c,in:0,out:0})}),o.edges().forEach(c=>{let E=t.edge(c.v,c.w)||0,m=r(c),O=E+m;t.setEdge(c.v,c.w,O),h=Math.max(h,t.node(c.v).out+=m),l=Math.max(l,t.node(c.w).in+=m)});let w=i(h+l+3).map(()=>new p),j=l+1;return t.nodes().forEach(c=>{s(w,j,t.node(c))}),{graph:t,buckets:w,zeroIdx:j}}function s(o,r,t){t.out?t.in?o[t.out-t.in+r].enqueue(t):o[o.length-1].enqueue(t):o[0].enqueue(t)}function i(o){const r=[];for(let t=0;t<o;t++)r.push(t);return r}return we}var Ee,wr;function F(){if(wr)return Ee;wr=1;let v=Y().Graph;Ee={addBorderNode:r,addDummyNode:p,applyWithChunking:h,asNonCompoundGraph:d,buildLayerMatrix:s,intersectRect:e,mapValues:I,maxRank:w,normalizeRanks:i,notime:E,partition:j,pick:R,predecessorWeights:n,range:x,removeEmptyRanks:o,simplify:u,successorWeights:a,time:c,uniqueId:O,zipObject:q};function p(f,b,y,k){for(var C=k;f.hasNode(C);)C=O(k);return y.dummy=b,f.setNode(C,y),C}function u(f){let b=new v().setGraph(f.graph());return f.nodes().forEach(y=>b.setNode(y,f.node(y))),f.edges().forEach(y=>{let k=b.edge(y.v,y.w)||{weight:0,minlen:1},C=f.edge(y);b.setEdge(y.v,y.w,{weight:k.weight+C.weight,minlen:Math.max(k.minlen,C.minlen)})}),b}function d(f){let b=new v({multigraph:f.isMultigraph()}).setGraph(f.graph());return f.nodes().forEach(y=>{f.children(y).length||b.setNode(y,f.node(y))}),f.edges().forEach(y=>{b.setEdge(y,f.edge(y))}),b}function a(f){let b=f.nodes().map(y=>{let k={};return f.outEdges(y).forEach(C=>{k[C.w]=(k[C.w]||0)+f.edge(C).weight}),k});return q(f.nodes(),b)}function n(f){let b=f.nodes().map(y=>{let k={};return f.inEdges(y).forEach(C=>{k[C.v]=(k[C.v]||0)+f.edge(C).weight}),k});return q(f.nodes(),b)}function e(f,b){let y=f.x,k=f.y,C=b.x-y,T=b.y-k,S=f.width/2,D=f.height/2;if(!C&&!T)throw new Error("Not possible to find intersection inside of the rectangle");let H,z;return Math.abs(T)*S>Math.abs(C)*D?(T<0&&(D=-D),H=D*C/T,z=D):(C<0&&(S=-S),H=S,z=S*T/C),{x:y+H,y:k+z}}function s(f){let b=x(w(f)+1).map(()=>[]);return f.nodes().forEach(y=>{let k=f.node(y),C=k.rank;C!==void 0&&(b[C][k.order]=y)}),b}function i(f){let b=f.nodes().map(k=>{let C=f.node(k).rank;return C===void 0?Number.MAX_VALUE:C}),y=h(Math.min,b);f.nodes().forEach(k=>{let C=f.node(k);Object.hasOwn(C,"rank")&&(C.rank-=y)})}function o(f){let b=f.nodes().map(S=>f.node(S).rank),y=h(Math.min,b),k=[];f.nodes().forEach(S=>{let D=f.node(S).rank-y;k[D]||(k[D]=[]),k[D].push(S)});let C=0,T=f.graph().nodeRankFactor;Array.from(k).forEach((S,D)=>{S===void 0&&D%T!==0?--C:S!==void 0&&C&&S.forEach(H=>f.node(H).rank+=C)})}function r(f,b,y,k){let C={width:0,height:0};return arguments.length>=4&&(C.rank=y,C.order=k),p(f,"border",C,b)}function t(f,b=l){const y=[];for(let k=0;k<f.length;k+=b){const C=f.slice(k,k+b);y.push(C)}return y}const l=65535;function h(f,b){if(b.length>l){const y=t(b);return f.apply(null,y.map(k=>f.apply(null,k)))}else return f.apply(null,b)}function w(f){const y=f.nodes().map(k=>{let C=f.node(k).rank;return C===void 0?Number.MIN_VALUE:C});return h(Math.max,y)}function j(f,b){let y={lhs:[],rhs:[]};return f.forEach(k=>{b(k)?y.lhs.push(k):y.rhs.push(k)}),y}function c(f,b){let y=Date.now();try{return b()}finally{console.log(f+" time: "+(Date.now()-y)+"ms")}}function E(f,b){return b()}let m=0;function O(f){var b=++m;return f+(""+b)}function x(f,b,y=1){b==null&&(b=f,f=0);let k=T=>T<b;y<0&&(k=T=>b<T);const C=[];for(let T=f;k(T);T+=y)C.push(T);return C}function R(f,b){const y={};for(const k of b)f[k]!==void 0&&(y[k]=f[k]);return y}function I(f,b){let y=b;return typeof b=="string"&&(y=k=>k[b]),Object.entries(f).reduce((k,[C,T])=>(k[C]=y(T,C),k),{})}function q(f,b){return f.reduce((y,k,C)=>(y[k]=b[C],y),{})}return Ee}var ye,Er;function Ct(){if(Er)return ye;Er=1;let v=jt(),p=F().uniqueId;ye={run:u,undo:a};function u(n){(n.graph().acyclicer==="greedy"?v(n,s(n)):d(n)).forEach(i=>{let o=n.edge(i);n.removeEdge(i),o.forwardName=i.name,o.reversed=!0,n.setEdge(i.w,i.v,o,p("rev"))});function s(i){return o=>i.edge(o).weight}}function d(n){let e=[],s={},i={};function o(r){Object.hasOwn(i,r)||(i[r]=!0,s[r]=!0,n.outEdges(r).forEach(t=>{Object.hasOwn(s,t.w)?e.push(t):o(t.w)}),delete s[r])}return n.nodes().forEach(o),e}function a(n){n.edges().forEach(e=>{let s=n.edge(e);if(s.reversed){n.removeEdge(e);let i=s.forwardName;delete s.reversed,delete s.forwardName,n.setEdge(e.w,e.v,s,i)}})}return ye}var _e,yr;function Rt(){if(yr)return _e;yr=1;let v=F();_e={run:p,undo:d};function p(a){a.graph().dummyChains=[],a.edges().forEach(n=>u(a,n))}function u(a,n){let e=n.v,s=a.node(e).rank,i=n.w,o=a.node(i).rank,r=n.name,t=a.edge(n),l=t.labelRank;if(o===s+1)return;a.removeEdge(n);let h,w,j;for(j=0,++s;s<o;++j,++s)t.points=[],w={width:0,height:0,edgeLabel:t,edgeObj:n,rank:s},h=v.addDummyNode(a,"edge",w,"_d"),s===l&&(w.width=t.width,w.height=t.height,w.dummy="edge-label",w.labelpos=t.labelpos),a.setEdge(e,h,{weight:t.weight},r),j===0&&a.graph().dummyChains.push(h),e=h;a.setEdge(e,i,{weight:t.weight},r)}function d(a){a.graph().dummyChains.forEach(n=>{let e=a.node(n),s=e.edgeLabel,i;for(a.setEdge(e.edgeObj,s);e.dummy;)i=a.successors(n)[0],a.removeNode(n),s.points.push({x:e.x,y:e.y}),e.dummy==="edge-label"&&(s.x=e.x,s.y=e.y,s.width=e.width,s.height=e.height),n=i,e=a.node(n)})}return _e}var ke,_r;function Q(){if(_r)return ke;_r=1;const{applyWithChunking:v}=F();ke={longestPath:p,slack:u};function p(d){var a={};function n(e){var s=d.node(e);if(Object.hasOwn(a,e))return s.rank;a[e]=!0;let i=d.outEdges(e).map(r=>r==null?Number.POSITIVE_INFINITY:n(r.w)-d.edge(r).minlen);var o=v(Math.min,i);return o===Number.POSITIVE_INFINITY&&(o=0),s.rank=o}d.sources().forEach(n)}function u(d,a){return d.node(a.w).rank-d.node(a.v).rank-d.edge(a).minlen}return ke}var Oe,kr;function Jr(){if(kr)return Oe;kr=1;var v=Y().Graph,p=Q().slack;Oe=u;function u(e){var s=new v({directed:!1}),i=e.nodes()[0],o=e.nodeCount();s.setNode(i,{});for(var r,t;d(s,e)<o;)r=a(s,e),t=s.hasNode(r.v)?p(e,r):-p(e,r),n(s,e,t);return s}function d(e,s){function i(o){s.nodeEdges(o).forEach(r=>{var t=r.v,l=o===t?r.w:t;!e.hasNode(l)&&!p(s,r)&&(e.setNode(l,{}),e.setEdge(o,l,{}),i(l))})}return e.nodes().forEach(i),e.nodeCount()}function a(e,s){return s.edges().reduce((o,r)=>{let t=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(t=p(s,r)),t<o[0]?[t,r]:o},[Number.POSITIVE_INFINITY,null])[1]}function n(e,s,i){e.nodes().forEach(o=>s.node(o).rank+=i)}return Oe}var Ne,Or;function It(){if(Or)return Ne;Or=1;var v=Jr(),p=Q().slack,u=Q().longestPath,d=Y().alg.preorder,a=Y().alg.postorder,n=F().simplify;Ne=e,e.initLowLimValues=r,e.initCutValues=s,e.calcCutValue=o,e.leaveEdge=l,e.enterEdge=h,e.exchangeEdges=w;function e(m){m=n(m),u(m);var O=v(m);r(O),s(O,m);for(var x,R;x=l(O);)R=h(O,m,x),w(O,m,x,R)}function s(m,O){var x=a(m,m.nodes());x=x.slice(0,x.length-1),x.forEach(R=>i(m,O,R))}function i(m,O,x){var R=m.node(x),I=R.parent;m.edge(x,I).cutvalue=o(m,O,x)}function o(m,O,x){var R=m.node(x),I=R.parent,q=!0,f=O.edge(x,I),b=0;return f||(q=!1,f=O.edge(I,x)),b=f.weight,O.nodeEdges(x).forEach(y=>{var k=y.v===x,C=k?y.w:y.v;if(C!==I){var T=k===q,S=O.edge(y).weight;if(b+=T?S:-S,c(m,x,C)){var D=m.edge(x,C).cutvalue;b+=T?-D:D}}}),b}function r(m,O){arguments.length<2&&(O=m.nodes()[0]),t(m,{},1,O)}function t(m,O,x,R,I){var q=x,f=m.node(R);return O[R]=!0,m.neighbors(R).forEach(b=>{Object.hasOwn(O,b)||(x=t(m,O,x,b,R))}),f.low=q,f.lim=x++,I?f.parent=I:delete f.parent,x}function l(m){return m.edges().find(O=>m.edge(O).cutvalue<0)}function h(m,O,x){var R=x.v,I=x.w;O.hasEdge(R,I)||(R=x.w,I=x.v);var q=m.node(R),f=m.node(I),b=q,y=!1;q.lim>f.lim&&(b=f,y=!0);var k=O.edges().filter(C=>y===E(m,m.node(C.v),b)&&y!==E(m,m.node(C.w),b));return k.reduce((C,T)=>p(O,T)<p(O,C)?T:C)}function w(m,O,x,R){var I=x.v,q=x.w;m.removeEdge(I,q),m.setEdge(R.v,R.w,{}),r(m),s(m,O),j(m,O)}function j(m,O){var x=m.nodes().find(I=>!O.node(I).parent),R=d(m,x);R=R.slice(1),R.forEach(I=>{var q=m.node(I).parent,f=O.edge(I,q),b=!1;f||(f=O.edge(q,I),b=!0),O.node(I).rank=O.node(q).rank+(b?f.minlen:-f.minlen)})}function c(m,O,x){return m.hasEdge(O,x)}function E(m,O,x){return x.low<=O.lim&&O.lim<=x.lim}return Ne}var xe,Nr;function Lt(){if(Nr)return xe;Nr=1;var v=Q(),p=v.longestPath,u=Jr(),d=It();xe=a;function a(i){var o=i.graph().ranker;if(o instanceof Function)return o(i);switch(i.graph().ranker){case"network-simplex":s(i);break;case"tight-tree":e(i);break;case"longest-path":n(i);break;case"none":break;default:s(i)}}var n=p;function e(i){p(i),u(i)}function s(i){d(i)}return xe}var je,xr;function qt(){if(xr)return je;xr=1,je=v;function v(d){let a=u(d);d.graph().dummyChains.forEach(n=>{let e=d.node(n),s=e.edgeObj,i=p(d,a,s.v,s.w),o=i.path,r=i.lca,t=0,l=o[t],h=!0;for(;n!==s.w;){if(e=d.node(n),h){for(;(l=o[t])!==r&&d.node(l).maxRank<e.rank;)t++;l===r&&(h=!1)}if(!h){for(;t<o.length-1&&d.node(l=o[t+1]).minRank<=e.rank;)t++;l=o[t]}d.setParent(n,l),n=d.successors(n)[0]}})}function p(d,a,n,e){let s=[],i=[],o=Math.min(a[n].low,a[e].low),r=Math.max(a[n].lim,a[e].lim),t,l;t=n;do t=d.parent(t),s.push(t);while(t&&(a[t].low>o||r>a[t].lim));for(l=t,t=e;(t=d.parent(t))!==l;)i.push(t);return{path:s.concat(i.reverse()),lca:l}}function u(d){let a={},n=0;function e(s){let i=n;d.children(s).forEach(e),a[s]={low:i,lim:n++}}return d.children().forEach(e),a}return je}var Ce,jr;function Tt(){if(jr)return Ce;jr=1;let v=F();Ce={run:p,cleanup:n};function p(e){let s=v.addDummyNode(e,"root",{},"_root"),i=d(e),o=Object.values(i),r=v.applyWithChunking(Math.max,o)-1,t=2*r+1;e.graph().nestingRoot=s,e.edges().forEach(h=>e.edge(h).minlen*=t);let l=a(e)+1;e.children().forEach(h=>u(e,s,t,l,r,i,h)),e.graph().nodeRankFactor=t}function u(e,s,i,o,r,t,l){let h=e.children(l);if(!h.length){l!==s&&e.setEdge(s,l,{weight:0,minlen:i});return}let w=v.addBorderNode(e,"_bt"),j=v.addBorderNode(e,"_bb"),c=e.node(l);e.setParent(w,l),c.borderTop=w,e.setParent(j,l),c.borderBottom=j,h.forEach(E=>{u(e,s,i,o,r,t,E);let m=e.node(E),O=m.borderTop?m.borderTop:E,x=m.borderBottom?m.borderBottom:E,R=m.borderTop?o:2*o,I=O!==x?1:r-t[l]+1;e.setEdge(w,O,{weight:R,minlen:I,nestingEdge:!0}),e.setEdge(x,j,{weight:R,minlen:I,nestingEdge:!0})}),e.parent(l)||e.setEdge(s,w,{weight:0,minlen:r+t[l]})}function d(e){var s={};function i(o,r){var t=e.children(o);t&&t.length&&t.forEach(l=>i(l,r+1)),s[o]=r}return e.children().forEach(o=>i(o,1)),s}function a(e){return e.edges().reduce((s,i)=>s+e.edge(i).weight,0)}function n(e){var s=e.graph();e.removeNode(s.nestingRoot),delete s.nestingRoot,e.edges().forEach(i=>{var o=e.edge(i);o.nestingEdge&&e.removeEdge(i)})}return Ce}var Re,Cr;function St(){if(Cr)return Re;Cr=1;let v=F();Re=p;function p(d){function a(n){let e=d.children(n),s=d.node(n);if(e.length&&e.forEach(a),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let i=s.minRank,o=s.maxRank+1;i<o;++i)u(d,"borderLeft","_bl",n,s,i),u(d,"borderRight","_br",n,s,i)}}d.children().forEach(a)}function u(d,a,n,e,s,i){let o={width:0,height:0,rank:i,borderType:a},r=s[a][i-1],t=v.addDummyNode(d,"border",o,n);s[a][i]=t,d.setParent(t,e),r&&d.setEdge(r,t,{weight:1})}return Re}var Ie,Rr;function Mt(){if(Rr)return Ie;Rr=1,Ie={adjust:v,undo:p};function v(i){let o=i.graph().rankdir.toLowerCase();(o==="lr"||o==="rl")&&u(i)}function p(i){let o=i.graph().rankdir.toLowerCase();(o==="bt"||o==="rl")&&a(i),(o==="lr"||o==="rl")&&(e(i),u(i))}function u(i){i.nodes().forEach(o=>d(i.node(o))),i.edges().forEach(o=>d(i.edge(o)))}function d(i){let o=i.width;i.width=i.height,i.height=o}function a(i){i.nodes().forEach(o=>n(i.node(o))),i.edges().forEach(o=>{let r=i.edge(o);r.points.forEach(n),Object.hasOwn(r,"y")&&n(r)})}function n(i){i.y=-i.y}function e(i){i.nodes().forEach(o=>s(i.node(o))),i.edges().forEach(o=>{let r=i.edge(o);r.points.forEach(s),Object.hasOwn(r,"x")&&s(r)})}function s(i){let o=i.x;i.x=i.y,i.y=o}return Ie}var Le,Ir;function Pt(){if(Ir)return Le;Ir=1;let v=F();Le=p;function p(u){let d={},a=u.nodes().filter(r=>!u.children(r).length),n=a.map(r=>u.node(r).rank),e=v.applyWithChunking(Math.max,n),s=v.range(e+1).map(()=>[]);function i(r){if(d[r])return;d[r]=!0;let t=u.node(r);s[t.rank].push(r),u.successors(r).forEach(i)}return a.sort((r,t)=>u.node(r).rank-u.node(t).rank).forEach(i),s}return Le}var qe,Lr;function Dt(){if(Lr)return qe;Lr=1;let v=F().zipObject;qe=p;function p(d,a){let n=0;for(let e=1;e<a.length;++e)n+=u(d,a[e-1],a[e]);return n}function u(d,a,n){let e=v(n,n.map((l,h)=>h)),s=a.flatMap(l=>d.outEdges(l).map(h=>({pos:e[h.w],weight:d.edge(h).weight})).sort((h,w)=>h.pos-w.pos)),i=1;for(;i<n.length;)i<<=1;let o=2*i-1;i-=1;let r=new Array(o).fill(0),t=0;return s.forEach(l=>{let h=l.pos+i;r[h]+=l.weight;let w=0;for(;h>0;)h%2&&(w+=r[h+1]),h=h-1>>1,r[h]+=l.weight;t+=l.weight*w}),t}return qe}var Te,qr;function Gt(){if(qr)return Te;qr=1,Te=v;function v(p,u=[]){return u.map(d=>{let a=p.inEdges(d);if(a.length){let n=a.reduce((e,s)=>{let i=p.edge(s),o=p.node(s.v);return{sum:e.sum+i.weight*o.order,weight:e.weight+i.weight}},{sum:0,weight:0});return{v:d,barycenter:n.sum/n.weight,weight:n.weight}}else return{v:d}})}return Te}var Se,Tr;function Ft(){if(Tr)return Se;Tr=1;let v=F();Se=p;function p(a,n){let e={};a.forEach((i,o)=>{let r=e[i.v]={indegree:0,in:[],out:[],vs:[i.v],i:o};i.barycenter!==void 0&&(r.barycenter=i.barycenter,r.weight=i.weight)}),n.edges().forEach(i=>{let o=e[i.v],r=e[i.w];o!==void 0&&r!==void 0&&(r.indegree++,o.out.push(e[i.w]))});let s=Object.values(e).filter(i=>!i.indegree);return u(s)}function u(a){let n=[];function e(i){return o=>{o.merged||(o.barycenter===void 0||i.barycenter===void 0||o.barycenter>=i.barycenter)&&d(i,o)}}function s(i){return o=>{o.in.push(i),--o.indegree===0&&a.push(o)}}for(;a.length;){let i=a.pop();n.push(i),i.in.reverse().forEach(e(i)),i.out.forEach(s(i))}return n.filter(i=>!i.merged).map(i=>v.pick(i,["vs","i","barycenter","weight"]))}function d(a,n){let e=0,s=0;a.weight&&(e+=a.barycenter*a.weight,s+=a.weight),n.weight&&(e+=n.barycenter*n.weight,s+=n.weight),a.vs=n.vs.concat(a.vs),a.barycenter=e/s,a.weight=s,a.i=Math.min(n.i,a.i),n.merged=!0}return Se}var Me,Sr;function At(){if(Sr)return Me;Sr=1;let v=F();Me=p;function p(a,n){let e=v.partition(a,w=>Object.hasOwn(w,"barycenter")),s=e.lhs,i=e.rhs.sort((w,j)=>j.i-w.i),o=[],r=0,t=0,l=0;s.sort(d(!!n)),l=u(o,i,l),s.forEach(w=>{l+=w.vs.length,o.push(w.vs),r+=w.barycenter*w.weight,t+=w.weight,l=u(o,i,l)});let h={vs:o.flat(!0)};return t&&(h.barycenter=r/t,h.weight=t),h}function u(a,n,e){let s;for(;n.length&&(s=n[n.length-1]).i<=e;)n.pop(),a.push(s.vs),e++;return e}function d(a){return(n,e)=>n.barycenter<e.barycenter?-1:n.barycenter>e.barycenter?1:a?e.i-n.i:n.i-e.i}return Me}var Pe,Mr;function Vt(){if(Mr)return Pe;Mr=1;let v=Gt(),p=Ft(),u=At();Pe=d;function d(e,s,i,o){let r=e.children(s),t=e.node(s),l=t?t.borderLeft:void 0,h=t?t.borderRight:void 0,w={};l&&(r=r.filter(m=>m!==l&&m!==h));let j=v(e,r);j.forEach(m=>{if(e.children(m.v).length){let O=d(e,m.v,i,o);w[m.v]=O,Object.hasOwn(O,"barycenter")&&n(m,O)}});let c=p(j,i);a(c,w);let E=u(c,o);if(l&&(E.vs=[l,E.vs,h].flat(!0),e.predecessors(l).length)){let m=e.node(e.predecessors(l)[0]),O=e.node(e.predecessors(h)[0]);Object.hasOwn(E,"barycenter")||(E.barycenter=0,E.weight=0),E.barycenter=(E.barycenter*E.weight+m.order+O.order)/(E.weight+2),E.weight+=2}return E}function a(e,s){e.forEach(i=>{i.vs=i.vs.flatMap(o=>s[o]?s[o].vs:o)})}function n(e,s){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+s.barycenter*s.weight)/(e.weight+s.weight),e.weight+=s.weight):(e.barycenter=s.barycenter,e.weight=s.weight)}return Pe}var De,Pr;function Bt(){if(Pr)return De;Pr=1;let v=Y().Graph,p=F();De=u;function u(a,n,e,s){s||(s=a.nodes());let i=d(a),o=new v({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(r=>a.node(r));return s.forEach(r=>{let t=a.node(r),l=a.parent(r);(t.rank===n||t.minRank<=n&&n<=t.maxRank)&&(o.setNode(r),o.setParent(r,l||i),a[e](r).forEach(h=>{let w=h.v===r?h.w:h.v,j=o.edge(w,r),c=j!==void 0?j.weight:0;o.setEdge(w,r,{weight:a.edge(h).weight+c})}),Object.hasOwn(t,"minRank")&&o.setNode(r,{borderLeft:t.borderLeft[n],borderRight:t.borderRight[n]}))}),o}function d(a){for(var n;a.hasNode(n=p.uniqueId("_root")););return n}return De}var Ge,Dr;function Wt(){if(Dr)return Ge;Dr=1,Ge=v;function v(p,u,d){let a={},n;d.forEach(e=>{let s=p.parent(e),i,o;for(;s;){if(i=p.parent(s),i?(o=a[i],a[i]=s):(o=n,n=s),o&&o!==s){u.setEdge(o,s);return}s=i}})}return Ge}var Fe,Gr;function Yt(){if(Gr)return Fe;Gr=1;let v=Pt(),p=Dt(),u=Vt(),d=Bt(),a=Wt(),n=Y().Graph,e=F();Fe=s;function s(t,l){if(l&&typeof l.customOrder=="function"){l.customOrder(t,s);return}let h=e.maxRank(t),w=i(t,e.range(1,h+1),"inEdges"),j=i(t,e.range(h-1,-1,-1),"outEdges"),c=v(t);if(r(t,c),l&&l.disableOptimalOrderHeuristic)return;let E=Number.POSITIVE_INFINITY,m;for(let O=0,x=0;x<4;++O,++x){o(O%2?w:j,O%4>=2),c=e.buildLayerMatrix(t);let R=p(t,c);R<E&&(x=0,m=Object.assign({},c),E=R)}r(t,m)}function i(t,l,h){const w=new Map,j=(c,E)=>{w.has(c)||w.set(c,[]),w.get(c).push(E)};for(const c of t.nodes()){const E=t.node(c);if(typeof E.rank=="number"&&j(E.rank,c),typeof E.minRank=="number"&&typeof E.maxRank=="number")for(let m=E.minRank;m<=E.maxRank;m++)m!==E.rank&&j(m,c)}return l.map(function(c){return d(t,c,h,w.get(c)||[])})}function o(t,l){let h=new n;t.forEach(function(w){let j=w.graph().root,c=u(w,j,h,l);c.vs.forEach((E,m)=>w.node(E).order=m),a(w,h,c.vs)})}function r(t,l){Object.values(l).forEach(h=>h.forEach((w,j)=>t.node(w).order=j))}return Fe}var Ae,Fr;function Ht(){if(Fr)return Ae;Fr=1;let v=Y().Graph,p=F();Ae={positionX:h,findType1Conflicts:u,findType2Conflicts:d,addConflict:n,hasConflict:e,verticalAlignment:s,horizontalCompaction:i,alignCoordinates:t,findSmallestWidthAlignment:r,balance:l};function u(c,E){let m={};function O(x,R){let I=0,q=0,f=x.length,b=R[R.length-1];return R.forEach((y,k)=>{let C=a(c,y),T=C?c.node(C).order:f;(C||y===b)&&(R.slice(q,k+1).forEach(S=>{c.predecessors(S).forEach(D=>{let H=c.node(D),z=H.order;(z<I||T<z)&&!(H.dummy&&c.node(S).dummy)&&n(m,D,S)})}),q=k+1,I=T)}),R}return E.length&&E.reduce(O),m}function d(c,E){let m={};function O(R,I,q,f,b){let y;p.range(I,q).forEach(k=>{y=R[k],c.node(y).dummy&&c.predecessors(y).forEach(C=>{let T=c.node(C);T.dummy&&(T.order<f||T.order>b)&&n(m,C,y)})})}function x(R,I){let q=-1,f,b=0;return I.forEach((y,k)=>{if(c.node(y).dummy==="border"){let C=c.predecessors(y);C.length&&(f=c.node(C[0]).order,O(I,b,k,q,f),b=k,q=f)}O(I,b,I.length,f,R.length)}),I}return E.length&&E.reduce(x),m}function a(c,E){if(c.node(E).dummy)return c.predecessors(E).find(m=>c.node(m).dummy)}function n(c,E,m){if(E>m){let x=E;E=m,m=x}let O=c[E];O||(c[E]=O={}),O[m]=!0}function e(c,E,m){if(E>m){let O=E;E=m,m=O}return!!c[E]&&Object.hasOwn(c[E],m)}function s(c,E,m,O){let x={},R={},I={};return E.forEach(q=>{q.forEach((f,b)=>{x[f]=f,R[f]=f,I[f]=b})}),E.forEach(q=>{let f=-1;q.forEach(b=>{let y=O(b);if(y.length){y=y.sort((C,T)=>I[C]-I[T]);let k=(y.length-1)/2;for(let C=Math.floor(k),T=Math.ceil(k);C<=T;++C){let S=y[C];R[b]===b&&f<I[S]&&!e(m,b,S)&&(R[S]=b,R[b]=x[b]=x[S],f=I[S])}}})}),{root:x,align:R}}function i(c,E,m,O,x){let R={},I=o(c,E,m,x),q=x?"borderLeft":"borderRight";function f(k,C){let T=I.nodes(),S=T.pop(),D={};for(;S;)D[S]?k(S):(D[S]=!0,T.push(S),T=T.concat(C(S))),S=T.pop()}function b(k){R[k]=I.inEdges(k).reduce((C,T)=>Math.max(C,R[T.v]+I.edge(T)),0)}function y(k){let C=I.outEdges(k).reduce((S,D)=>Math.min(S,R[D.w]-I.edge(D)),Number.POSITIVE_INFINITY),T=c.node(k);C!==Number.POSITIVE_INFINITY&&T.borderType!==q&&(R[k]=Math.max(R[k],C))}return f(b,I.predecessors.bind(I)),f(y,I.successors.bind(I)),Object.keys(O).forEach(k=>R[k]=R[m[k]]),R}function o(c,E,m,O){let x=new v,R=c.graph(),I=w(R.nodesep,R.edgesep,O);return E.forEach(q=>{let f;q.forEach(b=>{let y=m[b];if(x.setNode(y),f){var k=m[f],C=x.edge(k,y);x.setEdge(k,y,Math.max(I(c,b,f),C||0))}f=b})}),x}function r(c,E){return Object.values(E).reduce((m,O)=>{let x=Number.NEGATIVE_INFINITY,R=Number.POSITIVE_INFINITY;Object.entries(O).forEach(([q,f])=>{let b=j(c,q)/2;x=Math.max(f+b,x),R=Math.min(f-b,R)});const I=x-R;return I<m[0]&&(m=[I,O]),m},[Number.POSITIVE_INFINITY,null])[1]}function t(c,E){let m=Object.values(E),O=p.applyWithChunking(Math.min,m),x=p.applyWithChunking(Math.max,m);["u","d"].forEach(R=>{["l","r"].forEach(I=>{let q=R+I,f=c[q];if(f===E)return;let b=Object.values(f),y=O-p.applyWithChunking(Math.min,b);I!=="l"&&(y=x-p.applyWithChunking(Math.max,b)),y&&(c[q]=p.mapValues(f,k=>k+y))})})}function l(c,E){return p.mapValues(c.ul,(m,O)=>{if(E)return c[E.toLowerCase()][O];{let x=Object.values(c).map(R=>R[O]).sort((R,I)=>R-I);return(x[1]+x[2])/2}})}function h(c){let E=p.buildLayerMatrix(c),m=Object.assign(u(c,E),d(c,E)),O={},x;["u","d"].forEach(I=>{x=I==="u"?E:Object.values(E).reverse(),["l","r"].forEach(q=>{q==="r"&&(x=x.map(k=>Object.values(k).reverse()));let f=(I==="u"?c.predecessors:c.successors).bind(c),b=s(c,x,m,f),y=i(c,x,b.root,b.align,q==="r");q==="r"&&(y=p.mapValues(y,k=>-k)),O[I+q]=y})});let R=r(c,O);return t(O,R),l(O,c.graph().align)}function w(c,E,m){return(O,x,R)=>{let I=O.node(x),q=O.node(R),f=0,b;if(f+=I.width/2,Object.hasOwn(I,"labelpos"))switch(I.labelpos.toLowerCase()){case"l":b=-I.width/2;break;case"r":b=I.width/2;break}if(b&&(f+=m?b:-b),b=0,f+=(I.dummy?E:c)/2,f+=(q.dummy?E:c)/2,f+=q.width/2,Object.hasOwn(q,"labelpos"))switch(q.labelpos.toLowerCase()){case"l":b=q.width/2;break;case"r":b=-q.width/2;break}return b&&(f+=m?b:-b),b=0,f}}function j(c,E){return c.node(E).width}return Ae}var Ve,Ar;function zt(){if(Ar)return Ve;Ar=1;let v=F(),p=Ht().positionX;Ve=u;function u(a){a=v.asNonCompoundGraph(a),d(a),Object.entries(p(a)).forEach(([n,e])=>a.node(n).x=e)}function d(a){let n=v.buildLayerMatrix(a),e=a.graph().ranksep,s=0;n.forEach(i=>{const o=i.reduce((r,t)=>{const l=a.node(t).height;return r>l?r:l},0);i.forEach(r=>a.node(r).y=s+o/2),s+=o+e})}return Ve}var Be,Vr;function $t(){if(Vr)return Be;Vr=1;let v=Ct(),p=Rt(),u=Lt(),d=F().normalizeRanks,a=qt(),n=F().removeEmptyRanks,e=Tt(),s=St(),i=Mt(),o=Yt(),r=zt(),t=F(),l=Y().Graph;Be=h;function h(g,_){let N=_&&_.debugTiming?t.time:t.notime;N("layout",()=>{let L=N(" buildLayoutGraph",()=>f(g));N(" runLayout",()=>w(L,N,_)),N(" updateInputGraph",()=>j(g,L))})}function w(g,_,N){_(" makeSpaceForEdgeLabels",()=>b(g)),_(" removeSelfEdges",()=>et(g)),_(" acyclic",()=>v.run(g)),_(" nestingGraph.run",()=>e.run(g)),_(" rank",()=>u(t.asNonCompoundGraph(g))),_(" injectEdgeLabelProxies",()=>y(g)),_(" removeEmptyRanks",()=>n(g)),_(" nestingGraph.cleanup",()=>e.cleanup(g)),_(" normalizeRanks",()=>d(g)),_(" assignRankMinMax",()=>k(g)),_(" removeEdgeLabelProxies",()=>C(g)),_(" normalize.run",()=>p.run(g)),_(" parentDummyChains",()=>a(g)),_(" addBorderSegments",()=>s(g)),_(" order",()=>o(g,N)),_(" insertSelfEdges",()=>rt(g)),_(" adjustCoordinateSystem",()=>i.adjust(g)),_(" position",()=>r(g)),_(" positionSelfEdges",()=>tt(g)),_(" removeBorderNodes",()=>z(g)),_(" normalize.undo",()=>p.undo(g)),_(" fixupEdgeLabelCoords",()=>D(g)),_(" undoCoordinateSystem",()=>i.undo(g)),_(" translateGraph",()=>T(g)),_(" assignNodeIntersects",()=>S(g)),_(" reversePoints",()=>H(g)),_(" acyclic.undo",()=>v.undo(g))}function j(g,_){g.nodes().forEach(N=>{let L=g.node(N),M=_.node(N);L&&(L.x=M.x,L.y=M.y,L.rank=M.rank,_.children(N).length&&(L.width=M.width,L.height=M.height))}),g.edges().forEach(N=>{let L=g.edge(N),M=_.edge(N);L.points=M.points,Object.hasOwn(M,"x")&&(L.x=M.x,L.y=M.y)}),g.graph().width=_.graph().width,g.graph().height=_.graph().height}let c=["nodesep","edgesep","ranksep","marginx","marginy"],E={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},m=["acyclicer","ranker","rankdir","align"],O=["width","height","rank"],x={width:0,height:0},R=["minlen","weight","width","height","labeloffset"],I={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},q=["labelpos"];function f(g){let _=new l({multigraph:!0,compound:!0}),N=J(g.graph());return _.setGraph(Object.assign({},E,K(N,c),t.pick(N,m))),g.nodes().forEach(L=>{let M=J(g.node(L));const P=K(M,O);Object.keys(x).forEach(G=>{P[G]===void 0&&(P[G]=x[G])}),_.setNode(L,P),_.setParent(L,g.parent(L))}),g.edges().forEach(L=>{let M=J(g.edge(L));_.setEdge(L,Object.assign({},I,K(M,R),t.pick(M,q)))}),_}function b(g){let _=g.graph();_.ranksep/=2,g.edges().forEach(N=>{let L=g.edge(N);L.minlen*=2,L.labelpos.toLowerCase()!=="c"&&(_.rankdir==="TB"||_.rankdir==="BT"?L.width+=L.labeloffset:L.height+=L.labeloffset)})}function y(g){g.edges().forEach(_=>{let N=g.edge(_);if(N.width&&N.height){let L=g.node(_.v),P={rank:(g.node(_.w).rank-L.rank)/2+L.rank,e:_};t.addDummyNode(g,"edge-proxy",P,"_ep")}})}function k(g){let _=0;g.nodes().forEach(N=>{let L=g.node(N);L.borderTop&&(L.minRank=g.node(L.borderTop).rank,L.maxRank=g.node(L.borderBottom).rank,_=Math.max(_,L.maxRank))}),g.graph().maxRank=_}function C(g){g.nodes().forEach(_=>{let N=g.node(_);N.dummy==="edge-proxy"&&(g.edge(N.e).labelRank=N.rank,g.removeNode(_))})}function T(g){let _=Number.POSITIVE_INFINITY,N=0,L=Number.POSITIVE_INFINITY,M=0,P=g.graph(),G=P.marginx||0,B=P.marginy||0;function $e(W){let V=W.x,$=W.y,Ue=W.width,Xe=W.height;_=Math.min(_,V-Ue/2),N=Math.max(N,V+Ue/2),L=Math.min(L,$-Xe/2),M=Math.max(M,$+Xe/2)}g.nodes().forEach(W=>$e(g.node(W))),g.edges().forEach(W=>{let V=g.edge(W);Object.hasOwn(V,"x")&&$e(V)}),_-=G,L-=B,g.nodes().forEach(W=>{let V=g.node(W);V.x-=_,V.y-=L}),g.edges().forEach(W=>{let V=g.edge(W);V.points.forEach($=>{$.x-=_,$.y-=L}),Object.hasOwn(V,"x")&&(V.x-=_),Object.hasOwn(V,"y")&&(V.y-=L)}),P.width=N-_+G,P.height=M-L+B}function S(g){g.edges().forEach(_=>{let N=g.edge(_),L=g.node(_.v),M=g.node(_.w),P,G;N.points?(P=N.points[0],G=N.points[N.points.length-1]):(N.points=[],P=M,G=L),N.points.unshift(t.intersectRect(L,P)),N.points.push(t.intersectRect(M,G))})}function D(g){g.edges().forEach(_=>{let N=g.edge(_);if(Object.hasOwn(N,"x"))switch((N.labelpos==="l"||N.labelpos==="r")&&(N.width-=N.labeloffset),N.labelpos){case"l":N.x-=N.width/2+N.labeloffset;break;case"r":N.x+=N.width/2+N.labeloffset;break}})}function H(g){g.edges().forEach(_=>{let N=g.edge(_);N.reversed&&N.points.reverse()})}function z(g){g.nodes().forEach(_=>{if(g.children(_).length){let N=g.node(_),L=g.node(N.borderTop),M=g.node(N.borderBottom),P=g.node(N.borderLeft[N.borderLeft.length-1]),G=g.node(N.borderRight[N.borderRight.length-1]);N.width=Math.abs(G.x-P.x),N.height=Math.abs(M.y-L.y),N.x=P.x+N.width/2,N.y=L.y+N.height/2}}),g.nodes().forEach(_=>{g.node(_).dummy==="border"&&g.removeNode(_)})}function et(g){g.edges().forEach(_=>{if(_.v===_.w){var N=g.node(_.v);N.selfEdges||(N.selfEdges=[]),N.selfEdges.push({e:_,label:g.edge(_)}),g.removeEdge(_)}})}function rt(g){var _=t.buildLayerMatrix(g);_.forEach(N=>{var L=0;N.forEach((M,P)=>{var G=g.node(M);G.order=P+L,(G.selfEdges||[]).forEach(B=>{t.addDummyNode(g,"selfedge",{width:B.label.width,height:B.label.height,rank:G.rank,order:P+ ++L,e:B.e,label:B.label},"_se")}),delete G.selfEdges})})}function tt(g){g.nodes().forEach(_=>{var N=g.node(_);if(N.dummy==="selfedge"){var L=g.node(N.e.v),M=L.x+L.width/2,P=L.y,G=N.x-M,B=L.height/2;g.setEdge(N.e,N.label),g.removeNode(_),N.label.points=[{x:M+2*G/3,y:P-B},{x:M+5*G/6,y:P-B},{x:M+G,y:P},{x:M+5*G/6,y:P+B},{x:M+2*G/3,y:P+B}],N.label.x=N.x,N.label.y=N.y}})}function K(g,_){return t.mapValues(t.pick(g,_),Number)}function J(g){var _={};return g&&Object.entries(g).forEach(([N,L])=>{typeof N=="string"&&(N=N.toLowerCase()),_[N]=L}),_}return Be}var We,Br;function Ut(){if(Br)return We;Br=1;let v=F(),p=Y().Graph;We={debugOrdering:u};function u(d){let a=v.buildLayerMatrix(d),n=new p({compound:!0,multigraph:!0}).setGraph({});return d.nodes().forEach(e=>{n.setNode(e,{label:e}),n.setParent(e,"layer"+d.node(e).rank)}),d.edges().forEach(e=>n.setEdge(e.v,e.w,{},e.name)),a.forEach((e,s)=>{let i="layer"+s;n.setNode(i,{rank:"same"}),e.reduce((o,r)=>(n.setEdge(o,r,{style:"invis"}),r))}),n}return We}var Ye,Wr;function Xt(){return Wr||(Wr=1,Ye="1.1.8"),Ye}var He,Yr;function Qt(){return Yr||(Yr=1,He={graphlib:Y(),layout:$t(),debug:Ut(),util:{time:F().time,notime:F().notime},version:Xt()}),He}var Kt=Qt();const Hr=nt(Kt),Jt=({nodes:v,edges:p,graph:u})=>{const d=new Hr.graphlib.Graph;return d.setDefaultEdgeLabel(()=>({})),d.setGraph(u||{}),v.forEach(a=>{d.setNode(a.id,{width:a.width,height:a.height})}),p.forEach(a=>{d.setEdge(a.target,a.source)}),Hr.layout(d),{nodes:v.map(a=>{const n=d.node(a.id);return{...a,x:n.x-(a.width??0)/2,y:n.y-(a.height??0)/2}}),edges:p}};function Zt(v){const[p,u]=it.useState(!1),{data:d}=v,a=v.data.fields??{},n=Object.keys(a).length;return A.jsxs(Qe,{selected:v.selected,children:[A.jsx(Qe.Header,{label:d.label}),A.jsx("div",{children:Object.entries(a).map(([e,s],i)=>A.jsx(en,{field:{name:e,...s},table:d.label,index:i,last:n===i+1},i))})]})}const zr={background:"transparent",border:"none"},en=({field:v,table:p,index:u,onHover:d,last:a})=>{const n=U.header+U.row*u+U.row/2,e=`${p}:${v.name}`;return A.jsxs("div",{className:at("flex flex-row w-full justify-between font-mono py-1.5 px-2.5 border-b border-primary/15 border-l border-r cursor-auto",a&&"rounded-bl-lg rounded-br-lg","hover:bg-primary/5"),children:[A.jsx(Ke,{title:e,type:"source",id:e,position:X.Left,style:{top:n,left:0,...zr}}),A.jsxs("div",{className:"flex w-6 pr-1.5 justify-center items-center",children:[v.type==="primary"&&A.jsx(st,{className:"text-yellow-700"}),v.type==="relation"&&A.jsx(ot,{className:"text-sky-700"})]}),A.jsx("div",{className:"flex flex-grow",children:v.name}),A.jsx("div",{className:"flex opacity-60",children:v.type}),A.jsx(Ke,{type:"target",title:e,id:e,position:X.Right,style:{top:n,right:-5,...zr}})]})},U={header:30,row:32.5},Zr={Component:Zt,getSize:v=>{const p=v.fields??{},u=Object.keys(p).length;return{width:320,height:U.header+U.row*u}}};function rn(v){return Object.entries(v??{}).map(([p,u])=>({id:p,data:{label:p,...u},type:"entity",dragHandle:".drag-handle",position:{x:0,y:0},sourcePosition:X.Right,targetPosition:X.Left}))}function tn(v){return Object.entries(v??{}).flatMap(([p,u])=>{if(u.type==="m:n"){const a=`${u.source}_${u.target}`;return[{id:p,target:u.source,source:a,targetHandle:`${u.source}:id`,sourceHandle:`${a}:${u.source}_id`},{id:`${p}-2`,target:u.target,source:a,targetHandle:`${u.target}:id`,sourceHandle:`${a}:${u.target}_id`}]}let d=u.source+`:${u.target}`;return u.config?.mappedBy&&(d=`${u.source}:${u.config?.mappedBy}`),u.type!=="poly"&&(d+="_id"),{id:p,source:u.source,target:u.target,sourceHandle:d,targetHandle:u.target+":id"}})}const nn={entity:Zr.Component};function sn(){const{config:{data:v}}=dt(),{theme:p}=ut(),u=rn(v.entities),d=tn(v.relations).map(n=>({...n,style:{stroke:p==="light"?"#ccc":"#666"},type:"smoothstep",markerEnd:{type:lt.Arrow,width:20,height:20,color:p==="light"?"#aaa":"#777"}}));return Jt({nodes:u.map(n=>({id:n.id,...Zr.getSize(n.data)})),edges:d,graph:{rankdir:"LR",marginx:50,marginy:50}}).nodes.forEach(n=>{const e=u.find(s=>s.id===n.id);e&&(e.position={x:n.x,y:n.y})}),A.jsx(ht,{children:A.jsx(ft,{nodes:u,edges:d,nodeTypes:nn,minZoom:.1,maxZoom:2,fitViewOptions:{minZoom:.1,maxZoom:.8},children:A.jsx(ct,{zoom:!0,minimap:!0})})})}export{sn as DataSchemaCanvas};