@owox/web 0.30.0-next-20260723073557 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{r as x,j as g,a as It,b as Ot,I as jt,c as Ct,E as Lt,s as B,D as Ye,d as W,P as Mt,k as Tt,S as Dt,l as Pt,m as St,n as Rt,o as Ft}from"./index-qwc0uqor.js";import{l as At,D as ae,m as $t,W as K,E as Ke,n as Gt,H as ee,a as Vt,P as Y,b as _e,S as xe,N as zt,R as Ht,u as Bt,c as Ne,g as Wt,d as ke,e as Ie,f as Yt,L as Kt,Z as qt,h as Zt,i as Jt,B as Ut,j as Qt,M as Xt,k as en,o as tn}from"./viewport-DISF-Zyg.js";const nn=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}];function rn(e){return e==="vertical"?"vertical":"horizontal"}var qe=Object.defineProperty,on=(e,t,n)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t)qe(e,n,{get:t[n],enumerable:!0})},an=(e,t,n)=>on(e,t+"",n),Ze={};sn(Ze,{Graph:()=>O,alg:()=>he,json:()=>Ue,version:()=>hn});var dn=Object.defineProperty,Je=(e,t)=>{for(var n in t)dn(e,n,{get:t[n],enumerable:!0})},O=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected="directed"in e?e.directed:!0,this._isMultigraph="multigraph"in e?e.multigraph:!1,this._isCompound="compound"in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}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 typeof e!="function"?this._defaultNodeLabelFn=()=>e:this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(n=>{t!==void 0?this.setNode(n,t):this.setNode(n)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][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 in this._nodes}removeNode(e){if(e in this._nodes){let t=n=>this.removeEdge(this._edgeObjs[n]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(n=>{this.setParent(n)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(t===void 0)t="\0";else{t+="";for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw new 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}parent(e){if(this._isCompound){let t=this._parent[e];if(t!=="\0")return t}}children(e="\0"){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e==="\0")return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let r of this.successors(e))n.add(r);return Array.from(n.values())}}isLeaf(e){let t;return this.isDirected()?t=this.successors(e):t=this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([o,i])=>{e(o)&&t.setNode(o,i)}),Object.values(this._edgeObjs).forEach(o=>{t.hasNode(o.v)&&t.hasNode(o.w)&&t.setEdge(o,this.edge(o))});let n={},r=o=>{let i=this.parent(o);return!i||t.hasNode(i)?(n[o]=i??void 0,i??void 0):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(o=>t.setParent(o,r(o))),t}setDefaultEdgeLabel(e){return typeof e!="function"?this._defaultEdgeLabelFn=()=>e:this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((n,r)=>(t!==void 0?this.setEdge(n,r,t):this.setEdge(n,r),r)),this}setEdge(e,t,n,r){let o,i,s,a,d=!1;typeof e=="object"&&e!==null&&"v"in e?(o=e.v,i=e.w,s=e.name,arguments.length===2&&(a=t,d=!0)):(o=e,i=t,s=r,arguments.length>2&&(a=n,d=!0)),o=""+o,i=""+i,s!==void 0&&(s=""+s);let l=F(this._isDirected,o,i,s);if(l in this._edgeLabels)return d&&(this._edgeLabels[l]=a),this;if(s!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(o),this.setNode(i),this._edgeLabels[l]=d?a:this._defaultEdgeLabelFn(o,i,s);let h=ln(this._isDirected,o,i,s);return o=h.v,i=h.w,Object.freeze(h),this._edgeObjs[l]=h,Oe(this._preds[i],o),Oe(this._sucs[o],i),this._in[i][l]=h,this._out[o][l]=h,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?te(this._isDirected,e):F(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r!="object"?{label:r}:r}hasEdge(e,t,n){return(arguments.length===1?te(this._isDirected,e):F(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?te(this._isDirected,e):F(this._isDirected,e,t,n),o=this._edgeObjs[r];if(o){let i=o.v,s=o.w;delete this._edgeLabels[r],delete this._edgeObjs[r],je(this._preds[s],i),je(this._sucs[i],s),delete this._in[s][r],delete this._out[i][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(o=>o.v===t&&o.w===n||o.v===n&&o.w===t):r}};function Oe(e,t){e[t]?e[t]++:e[t]=1}function je(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function F(e,t,n,r){let o=""+t,i=""+n;if(!e&&o>i){let s=o;o=i,i=s}return o+""+i+""+(r===void 0?"\0":r)}function ln(e,t,n,r){let o=""+t,i=""+n;if(!e&&o>i){let a=o;o=i,i=a}let s={v:o,w:i};return r&&(s.name=r),s}function te(e,t){return F(e,t.v,t.w,t.name)}var hn="4.0.1",Ue={};Je(Ue,{read:()=>gn,write:()=>cn});function cn(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:un(e),edges:fn(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function un(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),o={v:t};return n!==void 0&&(o.value=n),r!==void 0&&(o.parent=r),o})}function fn(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function gn(e){let t=new O(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(n=>{t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(n=>{t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var he={};Je(he,{CycleException:()=>Z,bellmanFord:()=>Qe,components:()=>vn,dijkstra:()=>q,dijkstraAll:()=>En,findCycles:()=>yn,floydWarshall:()=>xn,isAcyclic:()=>kn,postorder:()=>On,preorder:()=>jn,prim:()=>Cn,shortestPaths:()=>Ln,tarjan:()=>et,topsort:()=>tt});var pn=()=>1;function Qe(e,t,n,r){return mn(e,String(t),n||pn,r||function(o){return e.outEdges(o)})}function mn(e,t,n,r){let o={},i,s=0,a=e.nodes(),d=function(c){let u=n(c);o[c.v].distance+u<o[c.w].distance&&(o[c.w]={distance:o[c.v].distance+u,predecessor:c.v},i=!0)},l=function(){a.forEach(function(c){r(c).forEach(function(u){let f=u.v===c?u.v:u.w,m=f===u.v?u.w:u.v;d({v:f,w:m})})})};a.forEach(function(c){let u=c===t?0:Number.POSITIVE_INFINITY;o[c]={distance:u,predecessor:""}});let h=a.length;for(let c=1;c<h&&(i=!1,s++,l(),!!i);c++);if(s===h-1&&(i=!1,l(),i))throw new Error("The graph contains a negative weight cycle");return o}function vn(e){let t={},n=[],r;function o(i){i in t||(t[i]=!0,r.push(i),e.successors(i).forEach(o),e.predecessors(i).forEach(o))}return e.nodes().forEach(function(i){r=[],o(i),r.length&&n.push(r)}),n}var Xe=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let o=this._arr,i=o.length;return n[r]=i,o.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw new Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,o=e;n<t.length&&(o=t[n].priority<t[o].priority?n:o,r<t.length&&(o=t[r].priority<t[o].priority?r:o),o!==e&&(this._swap(e,o),this._heapify(o)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,o=n[e],i=n[t];n[e]=i,n[t]=o,r[i.key]=e,r[o.key]=t}},bn=()=>1;function q(e,t,n,r){let o=function(i){return e.outEdges(i)};return wn(e,String(t),n||bn,r||o)}function wn(e,t,n,r){let o={},i=new Xe,s,a,d=function(l){let h=l.v!==s?l.v:l.w,c=o[h],u=n(l),f=a.distance+u;if(u<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+u);f<c.distance&&(c.distance=f,c.predecessor=s,i.decrease(h,f))};for(e.nodes().forEach(function(l){let h=l===t?0:Number.POSITIVE_INFINITY;o[l]={distance:h,predecessor:""},i.add(l,h)});i.size()>0&&(s=i.removeMin(),a=o[s],a.distance!==Number.POSITIVE_INFINITY);)r(s).forEach(d);return o}function En(e,t,n){return e.nodes().reduce(function(r,o){return r[o]=q(e,o,t,n),r},{})}function et(e){let t=0,n=[],r={},o=[];function i(s){let a=r[s]={onStack:!0,lowlink:t,index:t++};if(n.push(s),e.successors(s).forEach(function(d){d in r?r[d].onStack&&(a.lowlink=Math.min(a.lowlink,r[d].index)):(i(d),a.lowlink=Math.min(a.lowlink,r[d].lowlink))}),a.lowlink===a.index){let d=[],l;do l=n.pop(),r[l].onStack=!1,d.push(l);while(s!==l);o.push(d)}}return e.nodes().forEach(function(s){s in r||i(s)}),o}function yn(e){return et(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var _n=()=>1;function xn(e,t,n){return Nn(e,t||_n,n||function(r){return e.outEdges(r)})}function Nn(e,t,n){let r={},o=e.nodes();return o.forEach(function(i){r[i]={},r[i][i]={distance:0,predecessor:""},o.forEach(function(s){i!==s&&(r[i][s]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),n(i).forEach(function(s){let a=s.v===i?s.w:s.v,d=t(s);r[i][a]={distance:d,predecessor:i}})}),o.forEach(function(i){let s=r[i];o.forEach(function(a){let d=r[a];o.forEach(function(l){let h=d[i],c=s[l],u=d[l],f=h.distance+c.distance;f<u.distance&&(u.distance=f,u.predecessor=c.predecessor)})})}),r}var Z=class extends Error{constructor(...e){super(...e)}};function tt(e){let t={},n={},r=[];function o(i){if(i in n)throw new Z;i in t||(n[i]=!0,t[i]=!0,e.predecessors(i).forEach(o),delete n[i],r.push(i))}if(e.sinks().forEach(o),Object.keys(t).length!==e.nodeCount())throw new Z;return r}function kn(e){try{tt(e)}catch(t){if(t instanceof Z)return!1;throw t}return!0}function In(e,t,n,r,o){Array.isArray(t)||(t=[t]);let i=(a=>{var d;return(d=e.isDirected()?e.successors(a):e.neighbors(a))!=null?d:[]}),s={};return t.forEach(function(a){if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);o=nt(e,a,n==="post",s,i,r,o)}),o}function nt(e,t,n,r,o,i,s){return t in r||(r[t]=!0,n||(s=i(s,t)),o(t).forEach(function(a){s=nt(e,a,n,r,o,i,s)}),n&&(s=i(s,t))),s}function rt(e,t,n){return In(e,t,n,function(r,o){return r.push(o),r},[])}function On(e,t){return rt(e,t,"post")}function jn(e,t){return rt(e,t,"pre")}function Cn(e,t){let n=new O,r={},o=new Xe,i;function s(d){let l=d.v===i?d.w:d.v,h=o.priority(l);if(h!==void 0){let c=t(d);c<h&&(r[l]=i,o.decrease(l,c))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(d){o.add(d,Number.POSITIVE_INFINITY),n.setNode(d)}),o.decrease(e.nodes()[0],0);let a=!1;for(;o.size()>0;){if(i=o.removeMin(),i in r)n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(s)}return n}function Ln(e,t,n,r){return Mn(e,t,n,r??(o=>{let i=e.outEdges(o);return i??[]}))}function Mn(e,t,n,r){if(n===void 0)return q(e,t,n,r);let o=!1,i=e.nodes();for(let s=0;s<i.length;s++){let a=r(i[s]);for(let d=0;d<a.length;d++){let l=a[d],h=l.v===i[s]?l.v:l.w,c=h===l.v?l.w:l.v;n({v:h,w:c})<0&&(o=!0)}if(o)return Qe(e,t,n,r)}return q(e,t,n,r)}function P(e,t,n,r){let o=r;for(;e.hasNode(o);)o=ce(r);return n.dummy=t,e.setNode(o,n),o}function Tn(e){let t=new O().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+o.weight,minlen:Math.max(r.minlen,o.minlen)})}),t}function ot(e){let t=new O({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Ce(e,t){let n=e.x,r=e.y,o=t.x-n,i=t.y-r,s=e.width/2,a=e.height/2;if(!o&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let d,l;return Math.abs(i)*s>Math.abs(o)*a?(i<0&&(a=-a),d=a*o/i,l=a):(o<0&&(s=-s),d=s,l=s*i/o),{x:n+d,y:r+l}}function $(e){let t=A(st(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),o=r.rank;o!==void 0&&(t[o]||(t[o]=[]),t[o][r.order]=n)}),t}function Dn(e){let t=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MAX_VALUE:o}),n=C(Math.min,t);e.nodes().forEach(r=>{let o=e.node(r);Object.hasOwn(o,"rank")&&(o.rank-=n)})}function Pn(e){let t=e.nodes().map(s=>e.node(s).rank).filter(s=>s!==void 0),n=C(Math.min,t),r=[];e.nodes().forEach(s=>{let a=e.node(s).rank-n;r[a]||(r[a]=[]),r[a].push(s)});let o=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((s,a)=>{s===void 0&&a%i!==0?--o:s!==void 0&&o&&s.forEach(d=>e.node(d).rank+=o)})}function Le(e,t,n,r){let o={width:0,height:0};return arguments.length>=4&&(o.rank=n,o.order=r),P(e,"border",o,t)}function Sn(e,t=it){let n=[];for(let r=0;r<e.length;r+=t){let o=e.slice(r,r+t);n.push(o)}return n}var it=65535;function C(e,t){if(t.length>it){let n=Sn(t);return e(...n.map(r=>e(...r)))}else return e(...t)}function st(e){let t=e.nodes().map(n=>{let r=e.node(n).rank;return r===void 0?Number.MIN_VALUE:r});return C(Math.max,t)}function Rn(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function at(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function dt(e,t){return t()}var Fn=0;function ce(e){let t=++Fn;return e+(""+t)}function A(e,t,n=1){t==null&&(t=e,e=0);let r=i=>i<t;n<0&&(r=i=>t<i);let o=[];for(let i=e;r(i);i+=n)o.push(i);return o}function J(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function U(e,t){let n;return typeof t=="string"?n=r=>r[t]:n=t,Object.entries(e).reduce((r,[o,i])=>(r[o]=n(i,o),r),{})}function An(e,t){return e.reduce((n,r,o)=>(n[r]=t[o],n),{})}var Q="\0",$n="3.0.0",Gn=class{constructor(){an(this,"_sentinel");let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Me(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Me(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,Vn)),n=n._prev;return"["+e.join(", ")+"]"}};function Me(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Vn(e,t){if(e!=="_next"&&e!=="_prev")return t}var zn=Gn,Hn=()=>1;function Bn(e,t){if(e.nodeCount()<=1)return[];let n=Yn(e,t||Hn);return Wn(n.graph,n.buckets,n.zeroIdx).flatMap(r=>e.outEdges(r.v,r.w)||[])}function Wn(e,t,n){var r;let o=[],i=t[t.length-1],s=t[0],a;for(;e.nodeCount();){for(;a=s.dequeue();)ne(e,t,n,a);for(;a=i.dequeue();)ne(e,t,n,a);if(e.nodeCount()){for(let d=t.length-2;d>0;--d)if(a=(r=t[d])==null?void 0:r.dequeue(),a){o=o.concat(ne(e,t,n,a,!0)||[]);break}}}return o}function ne(e,t,n,r,o){let i=[],s=o?i:void 0;return(e.inEdges(r.v)||[]).forEach(a=>{let d=e.edge(a),l=e.node(a.v);o&&i.push({v:a.v,w:a.w}),l.out-=d,de(t,n,l)}),(e.outEdges(r.v)||[]).forEach(a=>{let d=e.edge(a),l=a.w,h=e.node(l);h.in-=d,de(t,n,h)}),e.removeNode(r.v),s}function Yn(e,t){let n=new O,r=0,o=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let d=n.edge(a.v,a.w)||0,l=t(a),h=d+l;n.setEdge(a.v,a.w,h);let c=n.node(a.v),u=n.node(a.w);o=Math.max(o,c.out+=l),r=Math.max(r,u.in+=l)});let i=Kn(o+r+3).map(()=>new zn),s=r+1;return n.nodes().forEach(a=>{de(i,s,n.node(a))}),{graph:n,buckets:i,zeroIdx:s}}function de(e,t,n){var r,o,i;n.out?n.in?(i=e[n.out-n.in+t])==null||i.enqueue(n):(o=e[e.length-1])==null||o.enqueue(n):(r=e[0])==null||r.enqueue(n)}function Kn(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function qn(e){(e.graph().acyclicer==="greedy"?Bn(e,t(e)):Zn(e)).forEach(n=>{let r=e.edge(n);e.removeEdge(n),r.forwardName=n.name,r.reversed=!0,e.setEdge(n.w,n.v,r,ce("rev"))});function t(n){return r=>n.edge(r).weight}}function Zn(e){let t=[],n={},r={};function o(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(s=>{Object.hasOwn(n,s.w)?t.push(s):o(s.w)}),delete n[i])}return e.nodes().forEach(o),t}function Jn(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function Un(e){e.graph().dummyChains=[],e.edges().forEach(t=>Qn(e,t))}function Qn(e,t){let n=t.v,r=e.node(n).rank,o=t.w,i=e.node(o).rank,s=t.name,a=e.edge(t),d=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,h,c;for(c=0,++r;r<i;++c,++r)a.points=[],h={width:0,height:0,edgeLabel:a,edgeObj:t,rank:r},l=P(e,"edge",h,"_d"),r===d&&(h.width=a.width,h.height=a.height,h.dummy="edge-label",h.labelpos=a.labelpos),e.setEdge(n,l,{weight:a.weight},s),c===0&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,o,{weight:a.weight},s)}function Xn(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,o;for(e.setEdge(n.edgeObj,r);n.dummy;)o=e.successors(t)[0],e.removeNode(t),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),t=o,n=e.node(t)})}function ue(e){let t={};function n(r){let o=e.node(r);if(Object.hasOwn(t,r))return o.rank;t[r]=!0;let i=e.outEdges(r),s=i?i.map(d=>d==null?Number.POSITIVE_INFINITY:n(d.w)-e.edge(d).minlen):[],a=C(Math.min,s);return a===Number.POSITIVE_INFINITY&&(a=0),o.rank=a}e.sources().forEach(n)}function D(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var lt=er;function er(e){let t=new O({directed:!1}),n=e.nodes();if(n.length===0)throw new Error("Graph must have at least one node");let r=n[0],o=e.nodeCount();t.setNode(r,{});let i,s;for(;tr(t,e)<o&&(i=nr(t,e),!!i);)s=t.hasNode(i.v)?D(e,i):-D(e,i),rr(t,e,s);return t}function tr(e,t){function n(r){let o=t.nodeEdges(r);o&&o.forEach(i=>{let s=i.v,a=r===s?i.w:s;!e.hasNode(a)&&!D(t,i)&&(e.setNode(a,{}),e.setEdge(r,a,{}),n(a))})}return e.nodes().forEach(n),e.nodeCount()}function nr(e,t){return t.edges().reduce((n,r)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(o=D(t,r)),o<n[0]?[o,r]:n},[Number.POSITIVE_INFINITY,null])[1]}function rr(e,t,n){e.nodes().forEach(r=>t.node(r).rank+=n)}var{preorder:or,postorder:ir}=he,sr=T;T.initLowLimValues=ge;T.initCutValues=fe;T.calcCutValue=ht;T.leaveEdge=ut;T.enterEdge=ft;T.exchangeEdges=gt;function T(e){e=Tn(e),ue(e);let t=lt(e);ge(t),fe(t,e);let n,r;for(;n=ut(t);)r=ft(t,e,n),gt(t,e,n,r)}function fe(e,t){let n=ir(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>ar(e,t,r))}function ar(e,t,n){let r=e.node(n).parent,o=e.edge(n,r);o.cutvalue=ht(e,t,n)}function ht(e,t,n){let r=e.node(n).parent,o=!0,i=t.edge(n,r),s=0;i||(o=!1,i=t.edge(r,n)),s=i.weight;let a=t.nodeEdges(n);return a&&a.forEach(d=>{let l=d.v===n,h=l?d.w:d.v;if(h!==r){let c=l===o,u=t.edge(d).weight;if(s+=c?u:-u,lr(e,n,h)){let f=e.edge(n,h).cutvalue;s+=c?-f:f}}}),s}function ge(e,t){arguments.length<2&&(t=e.nodes()[0]),ct(e,{},1,t)}function ct(e,t,n,r,o){let i=n,s=e.node(r);t[r]=!0;let a=e.neighbors(r);return a&&a.forEach(d=>{Object.hasOwn(t,d)||(n=ct(e,t,n,d,r))}),s.low=i,s.lim=n++,o?s.parent=o:delete s.parent,n}function ut(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ft(e,t,n){let r=n.v,o=n.w;t.hasEdge(r,o)||(r=n.w,o=n.v);let i=e.node(r),s=e.node(o),a=i,d=!1;return i.lim>s.lim&&(a=s,d=!0),t.edges().filter(l=>d===Te(e,e.node(l.v),a)&&d!==Te(e,e.node(l.w),a)).reduce((l,h)=>D(t,h)<D(t,l)?h:l)}function gt(e,t,n,r){let o=n.v,i=n.w;e.removeEdge(o,i),e.setEdge(r.v,r.w,{}),ge(e),fe(e,t),dr(e,t)}function dr(e,t){let n=e.nodes().find(o=>!e.node(o).parent);if(!n)return;let r=or(e,[n]);r=r.slice(1),r.forEach(o=>{let i=e.node(o).parent,s=t.edge(o,i),a=!1;s||(s=t.edge(i,o),a=!0),t.node(o).rank=t.node(i).rank+(a?s.minlen:-s.minlen)})}function lr(e,t,n){return e.hasEdge(t,n)}function Te(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var hr=cr;function cr(e){let t=e.graph().ranker;if(typeof t=="function")return t(e);switch(t){case"network-simplex":De(e);break;case"tight-tree":fr(e);break;case"longest-path":ur(e);break;case"none":break;default:De(e)}}var ur=ue;function fr(e){ue(e),lt(e)}function De(e){sr(e)}var gr=pr;function pr(e){let t=vr(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),o=r.edgeObj,i=mr(e,t,o.v,o.w),s=i.path,a=i.lca,d=0,l=s[d],h=!0;for(;n!==o.w;){if(r=e.node(n),h){for(;(l=s[d])!==a&&e.node(l).maxRank<r.rank;)d++;l===a&&(h=!1)}if(!h){for(;d<s.length-1&&e.node(s[d+1]).minRank<=r.rank;)d++;l=s[d]}l!==void 0&&e.setParent(n,l),n=e.successors(n)[0]}})}function mr(e,t,n,r){let o=[],i=[],s=Math.min(t[n].low,t[r].low),a=Math.max(t[n].lim,t[r].lim),d;d=n;do d=e.parent(d),o.push(d);while(d&&(t[d].low>s||a>t[d].lim));let l=d,h=r;for(;(h=e.parent(h))!==l;)i.push(h);return{path:o.concat(i.reverse()),lca:l}}function vr(e){let t={},n=0;function r(o){let i=n;e.children(o).forEach(r),t[o]={low:i,lim:n++}}return e.children(Q).forEach(r),t}function br(e){let t=P(e,"root",{},"_root"),n=wr(e),r=Object.values(n),o=C(Math.max,r)-1,i=2*o+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let s=Er(e)+1;e.children(Q).forEach(a=>pt(e,t,i,s,o,n,a)),e.graph().nodeRankFactor=i}function pt(e,t,n,r,o,i,s){var a;let d=e.children(s);if(!d.length){s!==t&&e.setEdge(t,s,{weight:0,minlen:n});return}let l=Le(e,"_bt"),h=Le(e,"_bb"),c=e.node(s);e.setParent(l,s),c.borderTop=l,e.setParent(h,s),c.borderBottom=h,d.forEach(u=>{var f;pt(e,t,n,r,o,i,u);let m=e.node(u),v=m.borderTop?m.borderTop:u,w=m.borderBottom?m.borderBottom:u,b=m.borderTop?r:2*r,N=v!==w?1:o-((f=i[s])!=null?f:0)+1;e.setEdge(l,v,{weight:b,minlen:N,nestingEdge:!0}),e.setEdge(w,h,{weight:b,minlen:N,nestingEdge:!0})}),e.parent(s)||e.setEdge(t,l,{weight:0,minlen:o+((a=i[s])!=null?a:0)})}function wr(e){let t={};function n(r,o){let i=e.children(r);i&&i.length&&i.forEach(s=>n(s,o+1)),t[r]=o}return e.children(Q).forEach(r=>n(r,1)),t}function Er(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function yr(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{e.edge(n).nestingEdge&&e.removeEdge(n)})}var _r=xr;function xr(e){function t(n){let r=e.children(n),o=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let i=o.minRank,s=o.maxRank+1;i<s;++i)Pe(e,"borderLeft","_bl",n,o,i),Pe(e,"borderRight","_br",n,o,i)}}e.children(Q).forEach(t)}function Pe(e,t,n,r,o,i){let s={width:0,height:0,rank:i,borderType:t},a=o[t][i-1],d=P(e,"border",s,n);o[t][i]=d,e.setParent(d,r),a&&e.setEdge(a,d,{weight:1})}function Nr(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="lr"||n==="rl")&&mt(e)}function kr(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="bt"||n==="rl")&&Ir(e),(n==="lr"||n==="rl")&&(Or(e),mt(e))}function mt(e){e.nodes().forEach(t=>Se(e.node(t))),e.edges().forEach(t=>Se(e.edge(t)))}function Se(e){let t=e.width;e.width=e.height,e.height=t}function Ir(e){e.nodes().forEach(t=>re(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(re),Object.hasOwn(r,"y")&&re(r)})}function re(e){e.y=-e.y}function Or(e){e.nodes().forEach(t=>oe(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(oe),Object.hasOwn(r,"x")&&oe(r)})}function oe(e){let t=e.x;e.x=e.y,e.y=t}function jr(e){let t={},n=e.nodes().filter(a=>!e.children(a).length),r=n.map(a=>e.node(a).rank),o=C(Math.max,r),i=A(o+1).map(()=>[]);function s(a){if(t[a])return;t[a]=!0;let d=e.node(a);i[d.rank].push(a);let l=e.successors(a);l&&l.forEach(s)}return n.sort((a,d)=>e.node(a).rank-e.node(d).rank).forEach(s),i}function Cr(e,t){let n=0;for(let r=1;r<t.length;++r)n+=Lr(e,t[r-1],t[r]);return n}function Lr(e,t,n){let r=An(n,n.map((l,h)=>h)),o=t.flatMap(l=>{let h=e.outEdges(l);return h?h.map(c=>({pos:r[c.w],weight:e.edge(c).weight})).sort((c,u)=>c.pos-u.pos):[]}),i=1;for(;i<n.length;)i<<=1;let s=2*i-1;i-=1;let a=new Array(s).fill(0),d=0;return o.forEach(l=>{let h=l.pos+i;a[h]+=l.weight;let c=0;for(;h>0;)h%2&&(c+=a[h+1]),h=h-1>>1,a[h]+=l.weight;d+=l.weight*c}),d}function Mr(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(!r||!r.length)return{v:n};{let o=r.reduce((i,s)=>{let a=e.edge(s),d=e.node(s.v);return{sum:i.sum+a.weight*d.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:o.sum/o.weight,weight:o.weight}}})}function Tr(e,t){let n={};e.forEach((o,i)=>{let s={indegree:0,in:[],out:[],vs:[o.v],i};o.barycenter!==void 0&&(s.barycenter=o.barycenter,s.weight=o.weight),n[o.v]=s}),t.edges().forEach(o=>{let i=n[o.v],s=n[o.w];i!==void 0&&s!==void 0&&(s.indegree++,i.out.push(s))});let r=Object.values(n).filter(o=>!o.indegree);return Dr(r)}function Dr(e){let t=[];function n(o){return i=>{i.merged||(i.barycenter===void 0||o.barycenter===void 0||i.barycenter>=o.barycenter)&&Pr(o,i)}}function r(o){return i=>{i.in.push(o),--i.indegree===0&&e.push(i)}}for(;e.length;){let o=e.pop();t.push(o),o.in.reverse().forEach(n(o)),o.out.forEach(r(o))}return t.filter(o=>!o.merged).map(o=>J(o,["vs","i","barycenter","weight"]))}function Pr(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function Sr(e,t){let n=Rn(e,h=>Object.hasOwn(h,"barycenter")),r=n.lhs,o=n.rhs.sort((h,c)=>c.i-h.i),i=[],s=0,a=0,d=0;r.sort(Rr(!!t)),d=Re(i,o,d),r.forEach(h=>{d+=h.vs.length,i.push(h.vs),s+=h.barycenter*h.weight,a+=h.weight,d=Re(i,o,d)});let l={vs:i.flat(1)};return a&&(l.barycenter=s/a,l.weight=a),l}function Re(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Rr(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function vt(e,t,n,r){let o=e.children(t),i=e.node(t),s=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,d={};s&&(o=o.filter(u=>u!==s&&u!==a));let l=Mr(e,o);l.forEach(u=>{if(e.children(u.v).length){let f=vt(e,u.v,n,r);d[u.v]=f,Object.hasOwn(f,"barycenter")&&Ar(u,f)}});let h=Tr(l,n);Fr(h,d);let c=Sr(h,r);if(s&&a){c.vs=[s,c.vs,a].flat(1);let u=e.predecessors(s);if(u&&u.length){let f=e.node(u[0]),m=e.predecessors(a),v=e.node(m[0]);Object.hasOwn(c,"barycenter")||(c.barycenter=0,c.weight=0),c.barycenter=(c.barycenter*c.weight+f.order+v.order)/(c.weight+2),c.weight+=2}}return c}function Fr(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Ar(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}function $r(e,t,n,r){r||(r=e.nodes());let o=Gr(e),i=new O({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(s=>e.node(s));return r.forEach(s=>{let a=e.node(s),d=e.parent(s);if(a.rank===t||a.minRank<=t&&t<=a.maxRank){i.setNode(s),i.setParent(s,d||o);let l=e[n](s);l&&l.forEach(h=>{let c=h.v===s?h.w:h.v,u=i.edge(c,s),f=u!==void 0?u.weight:0;i.setEdge(c,s,{weight:e.edge(h).weight+f})}),Object.hasOwn(a,"minRank")&&i.setNode(s,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]})}}),i}function Gr(e){let t;for(;e.hasNode(t=ce("_root")););return t}function Vr(e,t,n){let r={},o;n.forEach(i=>{let s=e.parent(i),a,d;for(;s;){if(a=e.parent(s),a?(d=r[a],r[a]=s):(d=o,o=s),d&&d!==s){t.setEdge(d,s);return}s=a}})}function bt(e,t={}){if(typeof t.customOrder=="function"){t.customOrder(e,bt);return}let n=st(e),r=Fe(e,A(1,n+1),"inEdges"),o=Fe(e,A(n-1,-1,-1),"outEdges"),i=jr(e);if(Ae(e,i),t.disableOptimalOrderHeuristic)return;let s=Number.POSITIVE_INFINITY,a,d=t.constraints||[];for(let l=0,h=0;h<4;++l,++h){zr(l%2?r:o,l%4>=2,d),i=$(e);let c=Cr(e,i);c<s?(h=0,a=Object.assign({},i),s=c):c===s&&(a=structuredClone(i))}Ae(e,a)}function Fe(e,t,n){let r=new Map,o=(i,s)=>{r.has(i)||r.set(i,[]),r.get(i).push(s)};for(let i of e.nodes()){let s=e.node(i);if(typeof s.rank=="number"&&o(s.rank,i),typeof s.minRank=="number"&&typeof s.maxRank=="number")for(let a=s.minRank;a<=s.maxRank;a++)a!==s.rank&&o(a,i)}return t.map(function(i){return $r(e,i,n,r.get(i)||[])})}function zr(e,t,n){let r=new O;e.forEach(function(o){n.forEach(a=>r.setEdge(a.left,a.right));let i=o.graph().root,s=vt(o,i,r,t);s.vs.forEach((a,d)=>o.node(a).order=d),Vr(o,r,s.vs)})}function Ae(e,t){Object.values(t).forEach(n=>n.forEach((r,o)=>e.node(r).order=o))}function Hr(e,t){let n={};function r(o,i){let s=0,a=0,d=o.length,l=i[i.length-1];return i.forEach((h,c)=>{let u=Wr(e,h),f=u?e.node(u).order:d;(u||h===l)&&(i.slice(a,c+1).forEach(m=>{let v=e.predecessors(m);v&&v.forEach(w=>{let b=e.node(w),N=b.order;(N<s||f<N)&&!(b.dummy&&e.node(m).dummy)&&wt(n,w,m)})}),a=c+1,s=f)}),i}return t.length&&t.reduce(r),n}function Br(e,t){let n={};function r(i,s,a,d,l){A(s,a).forEach(h=>{let c=i[h];if(c!==void 0&&e.node(c).dummy){let u=e.predecessors(c);u&&u.forEach(f=>{if(f===void 0)return;let m=e.node(f);m.dummy&&(m.order<d||m.order>l)&&wt(n,f,c)})}})}function o(i,s){let a=-1,d=-1,l=0;return s.forEach((h,c)=>{if(e.node(h).dummy==="border"){let u=e.predecessors(h);if(u&&u.length){let f=u[0];if(f===void 0)return;d=e.node(f).order,r(s,l,c,a,d),l=c,a=d}}r(s,l,s.length,d,i.length)}),s}return t.length&&t.reduce(o),n}function Wr(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(r=>e.node(r).dummy)}}function wt(e,t,n){if(t>n){let o=t;t=n,n=o}let r=e[t];r||(e[t]=r={}),r[n]=!0}function Yr(e,t,n){if(t>n){let o=t;t=n,n=o}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function Kr(e,t,n,r){let o={},i={},s={};return t.forEach(a=>{a.forEach((d,l)=>{o[d]=d,i[d]=d,s[d]=l})}),t.forEach(a=>{let d=-1;a.forEach(l=>{let h=r(l);if(h&&h.length){let c=h.sort((f,m)=>{let v=s[f],w=s[m];return(v!==void 0?v:0)-(w!==void 0?w:0)}),u=(c.length-1)/2;for(let f=Math.floor(u),m=Math.ceil(u);f<=m;++f){let v=c[f];if(v===void 0)continue;let w=s[v];if(w!==void 0&&i[l]===l&&d<w&&!Yr(n,l,v)){let b=o[v];b!==void 0&&(i[v]=l,i[l]=o[l]=b,d=w)}}}})}),{root:o,align:i}}function qr(e,t,n,r,o=!1){let i={},s=Zr(e,t,n,o),a=o?"borderLeft":"borderRight";function d(f,m){let v=s.nodes().slice(),w={},b=v.pop();for(;b;){if(w[b])f(b);else{w[b]=!0,v.push(b);for(let N of m(b))v.push(N)}b=v.pop()}}function l(f){let m=s.inEdges(f);m?i[f]=m.reduce((v,w)=>{var b;let N=(b=i[w.v])!=null?b:0,k=s.edge(w);return Math.max(v,N+(k!==void 0?k:0))},0):i[f]=0}function h(f){let m=s.outEdges(f),v=Number.POSITIVE_INFINITY;m&&(v=m.reduce((b,N)=>{let k=i[N.w],L=s.edge(N);return Math.min(b,(k!==void 0?k:0)-(L!==void 0?L:0))},Number.POSITIVE_INFINITY));let w=e.node(f);v!==Number.POSITIVE_INFINITY&&w.borderType!==a&&(i[f]=Math.max(i[f]!==void 0?i[f]:0,v))}function c(f){return s.predecessors(f)||[]}function u(f){return s.successors(f)||[]}return d(l,c),d(h,u),Object.keys(r).forEach(f=>{var m;let v=n[f];v!==void 0&&(i[f]=(m=i[v])!=null?m:0)}),i}function Zr(e,t,n,r){let o=new O,i=e.graph(),s=eo(i.nodesep,i.edgesep,r);return t.forEach(a=>{let d;a.forEach(l=>{let h=n[l];if(h!==void 0){if(o.setNode(h),d!==void 0){let c=n[d];if(c!==void 0){let u=o.edge(c,h);o.setEdge(c,h,Math.max(s(e,l,d),u||0))}}d=l}})}),o}function Jr(e,t){return Object.values(t).reduce((n,r)=>{let o=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,d])=>{let l=to(e,a)/2;o=Math.max(d+l,o),i=Math.min(d-l,i)});let s=o-i;return s<n[0]&&(n=[s,r]),n},[Number.POSITIVE_INFINITY,null])[1]}function Ur(e,t){let n=Object.values(t),r=C(Math.min,n),o=C(Math.max,n);["u","d"].forEach(i=>{["l","r"].forEach(s=>{let a=i+s,d=e[a];if(!d||d===t)return;let l=Object.values(d),h=r-C(Math.min,l);s!=="l"&&(h=o-C(Math.max,l)),h&&(e[a]=U(d,c=>c+h))})})}function Qr(e,t=void 0){let n=e.ul;return n?U(n,(r,o)=>{var i,s;if(t){let d=t.toLowerCase(),l=e[d];if(l&&l[o]!==void 0)return l[o]}let a=Object.values(e).map(d=>{let l=d[o];return l!==void 0?l:0}).sort((d,l)=>d-l);return(((i=a[1])!=null?i:0)+((s=a[2])!=null?s:0))/2}):{}}function Xr(e){let t=$(e),n=Object.assign(Hr(e,t),Br(e,t)),r={},o;["u","d"].forEach(s=>{o=s==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(o=o.map(h=>Object.values(h).reverse()));let d=Kr(e,o,n,h=>(s==="u"?e.predecessors(h):e.successors(h))||[]),l=qr(e,o,d.root,d.align,a==="r");a==="r"&&(l=U(l,h=>-h)),r[s+a]=l})});let i=Jr(e,r);return Ur(r,i),Qr(r,e.graph().align)}function eo(e,t,n){return(r,o,i)=>{let s=r.node(o),a=r.node(i),d=0,l;if(d+=s.width/2,Object.hasOwn(s,"labelpos"))switch(s.labelpos.toLowerCase()){case"l":l=-s.width/2;break;case"r":l=s.width/2;break}if(l&&(d+=n?l:-l),l=void 0,d+=(s.dummy?t:e)/2,d+=(a.dummy?t:e)/2,d+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(d+=n?l:-l),d}}function to(e,t){return e.node(t).width}function no(e){e=ot(e),ro(e),Object.entries(Xr(e)).forEach(([t,n])=>e.node(t).x=n)}function ro(e){let t=$(e),n=e.graph(),r=n.ranksep,o=n.rankalign,i=0;t.forEach(s=>{let a=s.reduce((d,l)=>{var h;let c=(h=e.node(l).height)!=null?h:0;return d>c?d:c},0);s.forEach(d=>{let l=e.node(d);o==="top"?l.y=i+l.height/2:o==="bottom"?l.y=i+a-l.height/2:l.y=i+a/2}),i+=a+r})}function oo(e,t={}){let n=t.debugTiming?at:dt;return n("layout",()=>{let r=n(" buildLayoutGraph",()=>po(e));return n(" runLayout",()=>io(r,n,t)),n(" updateInputGraph",()=>so(e,r)),r})}function io(e,t,n){t(" makeSpaceForEdgeLabels",()=>mo(e)),t(" removeSelfEdges",()=>ko(e)),t(" acyclic",()=>qn(e)),t(" nestingGraph.run",()=>br(e)),t(" rank",()=>hr(ot(e))),t(" injectEdgeLabelProxies",()=>vo(e)),t(" removeEmptyRanks",()=>Pn(e)),t(" nestingGraph.cleanup",()=>yr(e)),t(" normalizeRanks",()=>Dn(e)),t(" assignRankMinMax",()=>bo(e)),t(" removeEdgeLabelProxies",()=>wo(e)),t(" normalize.run",()=>Un(e)),t(" parentDummyChains",()=>gr(e)),t(" addBorderSegments",()=>_r(e)),t(" order",()=>bt(e,n)),t(" insertSelfEdges",()=>Io(e)),t(" adjustCoordinateSystem",()=>Nr(e)),t(" position",()=>no(e)),t(" positionSelfEdges",()=>Oo(e)),t(" removeBorderNodes",()=>No(e)),t(" normalize.undo",()=>Xn(e)),t(" fixupEdgeLabelCoords",()=>_o(e)),t(" undoCoordinateSystem",()=>kr(e)),t(" translateGraph",()=>Eo(e)),t(" assignNodeIntersects",()=>yo(e)),t(" reversePoints",()=>xo(e)),t(" acyclic.undo",()=>Jn(e))}function so(e,t){e.nodes().forEach(n=>{let r=e.node(n),o=t.node(n);r&&(r.x=o.x,r.y=o.y,r.order=o.order,r.rank=o.rank,t.children(n).length&&(r.width=o.width,r.height=o.height))}),e.edges().forEach(n=>{let r=e.edge(n),o=t.edge(n);r.points=o.points,Object.hasOwn(o,"x")&&(r.x=o.x,r.y=o.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var ao=["nodesep","edgesep","ranksep","marginx","marginy"],lo={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},ho=["acyclicer","ranker","rankdir","align","rankalign"],co=["width","height","rank"],$e={width:0,height:0},uo=["minlen","weight","width","height","labeloffset"],fo={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},go=["labelpos"];function po(e){let t=new O({multigraph:!0,compound:!0}),n=se(e.graph());return t.setGraph(Object.assign({},lo,ie(n,ao),J(n,ho))),e.nodes().forEach(r=>{let o=se(e.node(r)),i=ie(o,co);Object.keys($e).forEach(a=>{i[a]===void 0&&(i[a]=$e[a])}),t.setNode(r,i);let s=e.parent(r);s!==void 0&&t.setParent(r,s)}),e.edges().forEach(r=>{let o=se(e.edge(r));t.setEdge(r,Object.assign({},fo,ie(o,uo),J(o,go)))}),t}function mo(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function vo(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),o={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};P(e,"edge-proxy",o,"_ep")}})}function bo(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function wo(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="edge-proxy"){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function Eo(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,o=0,i=e.graph(),s=i.marginx||0,a=i.marginy||0;function d(l){let h=l.x,c=l.y,u=l.width,f=l.height;t=Math.min(t,h-u/2),n=Math.max(n,h+u/2),r=Math.min(r,c-f/2),o=Math.max(o,c+f/2)}e.nodes().forEach(l=>d(e.node(l))),e.edges().forEach(l=>{let h=e.edge(l);Object.hasOwn(h,"x")&&d(h)}),t-=s,r-=a,e.nodes().forEach(l=>{let h=e.node(l);h.x-=t,h.y-=r}),e.edges().forEach(l=>{let h=e.edge(l);h.points.forEach(c=>{c.x-=t,c.y-=r}),Object.hasOwn(h,"x")&&(h.x-=t),Object.hasOwn(h,"y")&&(h.y-=r)}),i.width=n-t+s,i.height=o-r+a}function yo(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),o=e.node(t.w),i,s;n.points?(i=n.points[0],s=n.points[n.points.length-1]):(n.points=[],i=o,s=r),n.points.unshift(Ce(r,i)),n.points.push(Ce(o,s))})}function _o(e){e.edges().forEach(t=>{let n=e.edge(t);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 xo(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function No(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),o=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),s=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(s.x-i.x),n.height=Math.abs(o.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function ko(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Io(e){$(e).forEach(t=>{let n=0;t.forEach((r,o)=>{let i=e.node(r);i.order=o+n,(i.selfEdges||[]).forEach(s=>{P(e,"selfedge",{width:s.label.width,height:s.label.height,rank:i.rank,order:o+ ++n,e:s.e,label:s.label},"_se")}),delete i.selfEdges})})}function Oo(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="selfedge"){let r=n,o=e.node(r.e.v),i=o.x+o.width/2,s=o.y,a=n.x-i,d=o.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:i+2*a/3,y:s-d},{x:i+5*a/6,y:s-d},{x:i+a,y:s},{x:i+5*a/6,y:s+d},{x:i+2*a/3,y:s+d}],r.label.x=n.x,r.label.y=n.y}})}function ie(e,t){return U(J(e,t),Number)}function se(e){let t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}function jo(e){let t=$(e),n=new O({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,o)=>{let i="layer"+o;n.setNode(i,{rank:"same"}),r.reduce((s,a)=>(n.setEdge(s,a,{style:"invis"}),a))}),n}var Co={graphlib:Ze,version:$n,layout:oo,debug:jo,util:{time:at,notime:dt}},Ge=Co;/*! For license information please see dagre.esm.js.LEGAL.txt */const Ve=80;function Lo(e,t){const n=new Map,r=Math.ceil(Math.sqrt(e.length)),{maxWidth:o,maxHeight:i}=e.reduce((s,a)=>({maxWidth:Math.max(s.maxWidth,a.width),maxHeight:Math.max(s.maxHeight,a.height)}),{maxWidth:0,maxHeight:0});return e.forEach((s,a)=>{const d=a%r,l=Math.floor(a/r),h=t==="horizontal"?d:l,c=t==="horizontal"?l:d;n.set(s.id,{x:h*(o+Ve),y:c*(i+Ve)})}),n}function Mo(e,t,n){const r=new Map,o=new Map,i=new Map;if(e.length===0)return{positions:r,routes:o,labelPositions:i};const s=new Ge.graphlib.Graph({multigraph:!0});s.setGraph({rankdir:n==="horizontal"?"LR":"TB"}),s.setDefaultEdgeLabel(()=>({}));for(const a of e)s.setNode(a.id,{width:a.width,height:a.height});for(const a of t){const d=a.label?{width:a.label.width,height:a.label.height,labelpos:"c"}:{};s.setEdge(a.sourceId,a.targetId,d,a.id)}try{Ge.layout(s)}catch(a){if(!(a instanceof RangeError))throw a;return{positions:Lo(e,n),routes:o,labelPositions:i}}for(const a of s.nodes()){const d=s.node(a);d.x===void 0||d.y===void 0||r.set(a,{x:d.x-d.width/2,y:d.y-d.height/2})}for(const a of t){const d=s.edge({v:a.sourceId,w:a.targetId,name:a.id}),l=(d.points??[]).slice(1,-1);l.length>0&&o.set(a.id,l),d.x!==void 0&&d.y!==void 0&&i.set(a.id,{x:d.x,y:d.y})}return{positions:r,routes:o,labelPositions:i}}const To=(e,t)=>[e,t].sort().join("->"),Et=56;function Do(e,t=Et){const n=new Map;for(const o of e){if(o.sourceId===o.targetId)continue;const i=To(o.sourceId,o.targetId),s=n.get(i);s?s.push(o):n.set(i,[o])}const r=new Map;for(const o of e)o.sourceId===o.targetId&&r.set(o.id,0);for(const o of n.values()){const i=[...o].sort((a,d)=>a.id.localeCompare(d.id)),s=i.length;i.forEach((a,d)=>{r.set(a.id,(d-(s-1)/2)*t)})}return r}function le(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function ze(e,t,n){const r=le(e,t);if(r===0)return e;const o=n/r;return{x:e.x+(t.x-e.x)*o,y:e.y+(t.y-e.y)*o}}function Po(e,t){if(e.length<2)return"";if(e.length===2){const[a,d]=e;return`M ${a.x} ${a.y} L ${d.x} ${d.y}`}const[n,...r]=e;let o=`M ${n.x} ${n.y}`,i=n;for(let a=1;a<e.length-1;a++){const d=e[a],l=e[a+1],h=le(i,d),c=le(d,l),u=Math.max(0,Math.min(t,h/2,c/2)),f=u===0?d:ze(d,i,u),m=u===0?d:ze(d,l,u);o+=` L ${f.x} ${f.y}`,o+=` Q ${d.x} ${d.y}, ${m.x} ${m.y}`,i=m}const s=r[r.length-1];return o+=` L ${s.x} ${s.y}`,o}const So=10;function Ro({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:o,targetPosition:i,markerStart:s,markerEnd:a,data:d}){const l=x.useRef(null),[h,c]=x.useState(null),{route:u,bowOffset:f,warning:m,joinLabel:v,dimmed:w,labelPosition:b,direction:N}=d;let k;if(u.length>0)k=Po([{x:e,y:t},...u,{x:n,y:r}],So);else if(f!==0)if(N==="vertical"){const I=Math.max(40,Math.abs(r-t)*.3);k=`M ${e} ${t} C ${e+f} ${t+I}, ${n+f} ${r-I}, ${n} ${r}`}else{const I=Math.max(40,Math.abs(n-e)*.3);k=`M ${e} ${t} C ${e+I} ${t+f}, ${n-I} ${r+f}, ${n} ${r}`}else[k]=At({sourceX:e,sourceY:t,sourcePosition:o,targetX:n,targetY:r,targetPosition:i});const L=.5+Math.max(-.18,Math.min(.18,f/Et*.24)),X=m?K:Ke;x.useEffect(()=>{if(b||v.length===0)return;const I=l.current;if(!I){c(null);return}const E=I.getTotalLength(),j=I.getPointAtLength(E*L);c({x:j.x,y:j.y})},[k,L,b,v]);const S=b??h;return g.jsxs(g.Fragment,{children:[g.jsx("path",{ref:l,d:k,fill:"none",strokeWidth:Gt,stroke:X,strokeDasharray:m?$t:void 0,opacity:w?ae:1,markerEnd:a,markerStart:s,style:{pointerEvents:"auto",transition:"opacity 0.2s"}}),v.length>0&&S&&g.jsx("foreignObject",{x:S.x,y:S.y,width:1,height:1,style:{overflow:"visible"},children:g.jsx("div",{style:{transform:"translate(-50%, -50%)",width:"max-content",background:"var(--background)",border:"1px solid var(--border)",borderRadius:8,padding:"3px 8px",fontSize:11,fontWeight:600,lineHeight:1.5,color:"var(--foreground)",pointerEvents:"none",opacity:w?ae:1,transition:"opacity 0.2s",boxShadow:"0 1px 3px 0 rgba(0,0,0,0.08)"},children:v.map(I=>g.jsx("div",{children:I},I))})})]})}const pe=240,me=74;function Fo({data:e}){const t=e.highlighted?ee:e.isDraft?K:Vt;function n(s){s.stopPropagation(),s.preventDefault(),e.onOpenExternal()}const r=e.direction==="vertical"?Y.Top:Y.Left,o=e.direction==="vertical"?Y.Bottom:Y.Right,i=`Open ${e.title} in new tab`;return g.jsxs("div",{style:{width:pe,height:me,borderRadius:8,border:`2px solid ${t}`,background:"var(--background)",boxShadow:e.highlighted?`0 0 0 3px ${ee}40, 0 0 12px ${ee}60`:"0 1px 4px 0 rgba(0,0,0,0.12)",cursor:"default",position:"relative",opacity:e.dimmed?ae:1,filter:e.dimmed?"grayscale(0.8)":void 0,animation:e.highlighted?"node-pulse 1.5s ease-in-out infinite":void 0,transition:"opacity 0.2s, filter 0.2s"},children:[e.isDraft&&g.jsx("span",{style:{position:"absolute",top:-18,right:4,fontSize:10,fontWeight:600,color:K,lineHeight:1},children:"Draft"}),e.hasIncoming&&g.jsx(_e,{type:"target",position:r,isConnectable:!1,style:xe}),g.jsxs("div",{className:"bg-muted flex items-center justify-between",style:{padding:"8px 10px 8px 14px",fontSize:13,fontWeight:600,borderRadius:"6px 6px 0 0"},children:[g.jsx("span",{className:"truncate",title:e.title,children:e.title}),g.jsxs("div",{className:"ml-2 flex shrink-0 items-center gap-0.5",children:[e.description&&g.jsxs(It,{children:[g.jsx(Ot,{asChild:!0,children:g.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground inline-flex cursor-default rounded p-0.5 transition-colors","aria-label":`Description for ${e.title}`,onPointerDown:s=>{s.stopPropagation()},children:g.jsx(jt,{style:{width:14,height:14},"aria-hidden":"true"})})}),g.jsx(Ct,{side:"top",align:"center",role:"tooltip",children:e.description})]}),g.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground shrink-0 cursor-pointer rounded p-0.5 transition-colors",onPointerDown:s=>{s.stopPropagation()},onClick:n,title:i,"aria-label":i,children:g.jsx(Lt,{style:{width:14,height:14},"aria-hidden":"true"})})]})]}),g.jsx("div",{className:"text-muted-foreground flex items-center",style:{padding:"6px 14px 8px",fontSize:11,minWidth:0},children:g.jsxs("span",{className:"ml-auto shrink-0",children:[e.fieldCount," field",e.fieldCount!==1?"s":""]})}),e.hasOutgoing&&g.jsx(_e,{type:"source",position:o,isConnectable:!1,style:xe})]})}const He="model-canvas-layout",Be="model-canvas-show-join-fields",R=.2,We=12,Ao=6.6,$o=18,Go=16.5,Vo=8,zo=150;function Ho(e){return e.length===0?void 0:{width:Math.max(...e.map(n=>n.length))*Ao+$o,height:e.length*Go+Vo}}const Bo={modelCanvasNode:Fo},Wo={modelCanvasEdge:Ro};function Yo(e){const{node:t,highlight:n}=e;return{id:t.id,type:"modelCanvasNode",position:e.position,width:pe,height:me,draggable:!1,selectable:!1,focusable:!1,style:en,data:{title:t.title,isDraft:t.status===Ye.DRAFT,fieldCount:t.fieldCount,description:t.description,hasIncoming:e.hasIncoming,hasOutgoing:e.hasOutgoing,highlighted:n.highlighted,dimmed:n.dimmed,direction:e.direction,onOpenExternal:e.onOpenExternal}}}function Ko(e){return e.joinConditions.map(t=>`${t.sourceFieldName} = ${t.targetFieldName}`)}function qo(e){const{edge:t,warning:n}=e,r=n?K:Ke,o={type:tn.ArrowClosed,color:r,width:We,height:We};return{id:t.id,type:"modelCanvasEdge",source:t.sourceId,target:t.targetId,focusable:!1,selectable:!1,markerEnd:o,markerStart:t.bidirectional?o:void 0,data:{route:e.route,bowOffset:e.bowOffset,warning:n,joinLabel:e.joinLabel,dimmed:e.dimmed,labelPosition:e.labelPosition,direction:e.direction}}}function Zo({nodes:e,edges:t,searchQuery:n,onOpenDataMart:r}){const o=Bt(),i=Ne(E=>E.width),s=Ne(E=>E.height),a=x.useRef(r);a.current=r;const d=x.useRef(e);d.current=e;const l=x.useRef(n);l.current=n;const[h,c]=x.useState(()=>rn(B.get(He))),[u,f]=x.useState(()=>B.get(Be,"boolean")??!1),[m,v]=x.useState(!1),[w,b]=x.useState([]),[N,k]=x.useState([]),L=x.useMemo(()=>Wt(w),[w]);x.useEffect(()=>{const E=new Set(t.map(p=>p.targetId)),j=new Set(t.map(p=>p.sourceId)),y=new Map(e.map(p=>[p.id,p.status===Ye.DRAFT])),_=ke(e,l.current,p=>p.id,p=>p.title),M=e.map(p=>({id:p.id,width:pe,height:me})),G=u?new Map(t.map(p=>[p.id,Ko(p)])):new Map,V=t.map(p=>({id:p.id,sourceId:p.sourceId,targetId:p.targetId,label:Ho(G.get(p.id)??[])})),{positions:z,routes:H,labelPositions:yt}=Mo(M,V,h),_t=Do(t);b(e.map(p=>Yo({node:p,position:z.get(p.id)??{x:0,y:0},hasIncoming:E.has(p.id),hasOutgoing:j.has(p.id),highlight:_.get(p.id)??Ie,direction:h,onOpenExternal:()=>{a.current(p.id)}}))),k(t.map(p=>{var Ee,ye;const be=H.get(p.id)??[],we=be.length===0?_t.get(p.id)??0:0,Nt=((Ee=_.get(p.sourceId))==null?void 0:Ee.dimmed)??!1,kt=((ye=_.get(p.targetId))==null?void 0:ye.dimmed)??!1;return qo({edge:p,joinLabel:G.get(p.id)??[],route:be,bowOffset:we,warning:p.joinNotConfigured||(y.get(p.sourceId)??!1)||(y.get(p.targetId)??!1),dimmed:Nt&&kt,labelPosition:we===0?yt.get(p.id):void 0,direction:h})})),v(!0);const ve=[..._.entries()].filter(([,p])=>p.highlighted).map(([p])=>p),xt=requestAnimationFrame(()=>{o.fitView(ve.length>0?{nodes:ve.map(p=>({id:p})),duration:300,padding:R}:{padding:R,duration:300})});return()=>{cancelAnimationFrame(xt)}},[e,t,h,u,o]),x.useEffect(()=>{const E=ke(d.current,n,y=>y.id,y=>y.title);b(y=>y.map(_=>{const M=E.get(_.id)??Ie;return _.data.highlighted===M.highlighted&&_.data.dimmed===M.dimmed?_:{..._,data:{..._.data,...M}}})),k(y=>y.map(_=>{var z,H;const M=((z=E.get(_.source))==null?void 0:z.dimmed)??!1,G=((H=E.get(_.target))==null?void 0:H.dimmed)??!1,V=M&&G;return _.data.dimmed===V?_:{..._,data:{..._.data,dimmed:V}}}));const j=[...E.entries()].filter(([,y])=>y.highlighted).map(([y])=>y);j.length>0&&o.fitView({nodes:j.map(y=>({id:y})),duration:300,padding:R})},[n,o]);const X=x.useCallback(E=>{c(E),B.set(He,E)},[]),S=x.useCallback(E=>{f(E),B.set(Be,E)},[]),I=x.useCallback((E,j)=>{if(i===0||s===0)return;const y=Yt(j,L,i,s,zo);y.x===j.x&&y.y===j.y||o.setViewport(y)},[L,s,i,o]);return g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"absolute top-3 right-3 z-10 flex flex-col gap-1.5",children:[g.jsx(W,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{o.fitView({padding:R,duration:300})},"aria-label":"Fit to view",children:g.jsx(Kt,{className:"h-6 w-6"})}),g.jsx(W,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{o.zoomIn({duration:150})},"aria-label":"Zoom in",children:g.jsx(qt,{className:"h-6 w-6"})}),g.jsx(W,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{o.zoomOut({duration:150})},"aria-label":"Zoom out",children:g.jsx(Zt,{className:"h-6 w-6"})}),g.jsxs(Mt,{children:[g.jsx(Tt,{asChild:!0,children:g.jsx(W,{variant:"outline",size:"icon",className:"h-12 w-12","aria-label":"Canvas settings",children:g.jsx(Dt,{className:"h-6 w-6"})})}),g.jsxs(Pt,{align:"end",side:"left",className:"w-56",children:[g.jsx(St,{children:"Layout algorithm"}),g.jsx("div",{role:"radiogroup","aria-label":"Layout algorithm",className:"mt-2 space-y-0.5",children:nn.map(E=>g.jsxs("button",{type:"button",role:"radio","aria-checked":h===E.value,className:"hover:bg-muted flex w-full items-center justify-between rounded px-2 py-1.5 text-left text-sm",onClick:()=>{X(E.value)},children:[g.jsx("span",{children:E.label}),h===E.value&&g.jsx(Rt,{className:"h-4 w-4"})]},E.value))}),g.jsxs("div",{className:"mt-3 flex items-center justify-between gap-2 border-t pt-3",children:[g.jsx("label",{htmlFor:"model-canvas-show-join-fields",className:"text-sm",children:"Show join fields"}),g.jsx(Ft,{id:"model-canvas-show-join-fields",checked:u,onCheckedChange:S})]})]})]})]}),m&&g.jsxs(Jt,{nodes:w,edges:N,nodeTypes:Bo,edgeTypes:Wo,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,edgesFocusable:!1,minZoom:.05,maxZoom:2,onMove:I,fitView:!0,fitViewOptions:{padding:R},style:{width:"100%",height:"100%"},children:[g.jsx(Ut,{variant:Qt.Lines,gap:16,color:"rgba(0,0,0,0.06)"}),g.jsx(Xt,{pannable:!0,zoomable:!0,style:{width:140,height:100}})]})]})}function Qo({nodes:e,edges:t,searchQuery:n,onOpenDataMart:r,className:o,style:i}){return e.length===0?null:g.jsxs("div",{className:`relative overflow-hidden rounded-lg border ${o??""}`,style:i??{height:480},children:[g.jsx("style",{children:zt}),g.jsx(Ht,{children:g.jsx(Zo,{nodes:e,edges:t,searchQuery:n,onOpenDataMart:r})})]})}export{Qo as default};
1
+ import{r as x,j as g,a as It,b as Ot,I as jt,c as Ct,E as Lt,s as B,D as Ye,d as W,P as Mt,k as Tt,S as Dt,l as Pt,m as St,n as Rt,o as Ft}from"./index-Bn6xf3W7.js";import{l as At,D as ae,m as $t,W as K,E as Ke,n as Gt,H as ee,a as Vt,P as Y,b as _e,S as xe,N as zt,R as Ht,u as Bt,c as Ne,g as Wt,d as ke,e as Ie,f as Yt,L as Kt,Z as qt,h as Zt,i as Jt,B as Ut,j as Qt,M as Xt,k as en,o as tn}from"./viewport-ztZvIm-X.js";const nn=[{value:"horizontal",label:"Horizontal"},{value:"vertical",label:"Vertical"}];function rn(e){return e==="vertical"?"vertical":"horizontal"}var qe=Object.defineProperty,on=(e,t,n)=>t in e?qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,sn=(e,t)=>{for(var n in t)qe(e,n,{get:t[n],enumerable:!0})},an=(e,t,n)=>on(e,t+"",n),Ze={};sn(Ze,{Graph:()=>O,alg:()=>he,json:()=>Ue,version:()=>hn});var dn=Object.defineProperty,Je=(e,t)=>{for(var n in t)dn(e,n,{get:t[n],enumerable:!0})},O=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected="directed"in e?e.directed:!0,this._isMultigraph="multigraph"in e?e.multigraph:!1,this._isCompound="compound"in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}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 typeof e!="function"?this._defaultNodeLabelFn=()=>e:this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(n=>{t!==void 0?this.setNode(n,t):this.setNode(n)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][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 in this._nodes}removeNode(e){if(e in this._nodes){let t=n=>this.removeEdge(this._edgeObjs[n]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(n=>{this.setParent(n)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(t===void 0)t="\0";else{t+="";for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw new 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}parent(e){if(this._isCompound){let t=this._parent[e];if(t!=="\0")return t}}children(e="\0"){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e==="\0")return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let r of this.successors(e))n.add(r);return Array.from(n.values())}}isLeaf(e){let t;return this.isDirected()?t=this.successors(e):t=this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([o,i])=>{e(o)&&t.setNode(o,i)}),Object.values(this._edgeObjs).forEach(o=>{t.hasNode(o.v)&&t.hasNode(o.w)&&t.setEdge(o,this.edge(o))});let n={},r=o=>{let i=this.parent(o);return!i||t.hasNode(i)?(n[o]=i??void 0,i??void 0):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(o=>t.setParent(o,r(o))),t}setDefaultEdgeLabel(e){return typeof e!="function"?this._defaultEdgeLabelFn=()=>e:this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((n,r)=>(t!==void 0?this.setEdge(n,r,t):this.setEdge(n,r),r)),this}setEdge(e,t,n,r){let o,i,s,a,d=!1;typeof e=="object"&&e!==null&&"v"in e?(o=e.v,i=e.w,s=e.name,arguments.length===2&&(a=t,d=!0)):(o=e,i=t,s=r,arguments.length>2&&(a=n,d=!0)),o=""+o,i=""+i,s!==void 0&&(s=""+s);let l=F(this._isDirected,o,i,s);if(l in this._edgeLabels)return d&&(this._edgeLabels[l]=a),this;if(s!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(o),this.setNode(i),this._edgeLabels[l]=d?a:this._defaultEdgeLabelFn(o,i,s);let h=ln(this._isDirected,o,i,s);return o=h.v,i=h.w,Object.freeze(h),this._edgeObjs[l]=h,Oe(this._preds[i],o),Oe(this._sucs[o],i),this._in[i][l]=h,this._out[o][l]=h,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?te(this._isDirected,e):F(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r!="object"?{label:r}:r}hasEdge(e,t,n){return(arguments.length===1?te(this._isDirected,e):F(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?te(this._isDirected,e):F(this._isDirected,e,t,n),o=this._edgeObjs[r];if(o){let i=o.v,s=o.w;delete this._edgeLabels[r],delete this._edgeObjs[r],je(this._preds[s],i),je(this._sucs[i],s),delete this._in[s][r],delete this._out[i][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(o=>o.v===t&&o.w===n||o.v===n&&o.w===t):r}};function Oe(e,t){e[t]?e[t]++:e[t]=1}function je(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function F(e,t,n,r){let o=""+t,i=""+n;if(!e&&o>i){let s=o;o=i,i=s}return o+""+i+""+(r===void 0?"\0":r)}function ln(e,t,n,r){let o=""+t,i=""+n;if(!e&&o>i){let a=o;o=i,i=a}let s={v:o,w:i};return r&&(s.name=r),s}function te(e,t){return F(e,t.v,t.w,t.name)}var hn="4.0.1",Ue={};Je(Ue,{read:()=>gn,write:()=>cn});function cn(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:un(e),edges:fn(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function un(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),o={v:t};return n!==void 0&&(o.value=n),r!==void 0&&(o.parent=r),o})}function fn(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function gn(e){let t=new O(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(n=>{t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(n=>{t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var he={};Je(he,{CycleException:()=>Z,bellmanFord:()=>Qe,components:()=>vn,dijkstra:()=>q,dijkstraAll:()=>En,findCycles:()=>yn,floydWarshall:()=>xn,isAcyclic:()=>kn,postorder:()=>On,preorder:()=>jn,prim:()=>Cn,shortestPaths:()=>Ln,tarjan:()=>et,topsort:()=>tt});var pn=()=>1;function Qe(e,t,n,r){return mn(e,String(t),n||pn,r||function(o){return e.outEdges(o)})}function mn(e,t,n,r){let o={},i,s=0,a=e.nodes(),d=function(c){let u=n(c);o[c.v].distance+u<o[c.w].distance&&(o[c.w]={distance:o[c.v].distance+u,predecessor:c.v},i=!0)},l=function(){a.forEach(function(c){r(c).forEach(function(u){let f=u.v===c?u.v:u.w,m=f===u.v?u.w:u.v;d({v:f,w:m})})})};a.forEach(function(c){let u=c===t?0:Number.POSITIVE_INFINITY;o[c]={distance:u,predecessor:""}});let h=a.length;for(let c=1;c<h&&(i=!1,s++,l(),!!i);c++);if(s===h-1&&(i=!1,l(),i))throw new Error("The graph contains a negative weight cycle");return o}function vn(e){let t={},n=[],r;function o(i){i in t||(t[i]=!0,r.push(i),e.successors(i).forEach(o),e.predecessors(i).forEach(o))}return e.nodes().forEach(function(i){r=[],o(i),r.length&&n.push(r)}),n}var Xe=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let o=this._arr,i=o.length;return n[r]=i,o.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw new Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,o=e;n<t.length&&(o=t[n].priority<t[o].priority?n:o,r<t.length&&(o=t[r].priority<t[o].priority?r:o),o!==e&&(this._swap(e,o),this._heapify(o)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,o=n[e],i=n[t];n[e]=i,n[t]=o,r[i.key]=e,r[o.key]=t}},bn=()=>1;function q(e,t,n,r){let o=function(i){return e.outEdges(i)};return wn(e,String(t),n||bn,r||o)}function wn(e,t,n,r){let o={},i=new Xe,s,a,d=function(l){let h=l.v!==s?l.v:l.w,c=o[h],u=n(l),f=a.distance+u;if(u<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+l+" Weight: "+u);f<c.distance&&(c.distance=f,c.predecessor=s,i.decrease(h,f))};for(e.nodes().forEach(function(l){let h=l===t?0:Number.POSITIVE_INFINITY;o[l]={distance:h,predecessor:""},i.add(l,h)});i.size()>0&&(s=i.removeMin(),a=o[s],a.distance!==Number.POSITIVE_INFINITY);)r(s).forEach(d);return o}function En(e,t,n){return e.nodes().reduce(function(r,o){return r[o]=q(e,o,t,n),r},{})}function et(e){let t=0,n=[],r={},o=[];function i(s){let a=r[s]={onStack:!0,lowlink:t,index:t++};if(n.push(s),e.successors(s).forEach(function(d){d in r?r[d].onStack&&(a.lowlink=Math.min(a.lowlink,r[d].index)):(i(d),a.lowlink=Math.min(a.lowlink,r[d].lowlink))}),a.lowlink===a.index){let d=[],l;do l=n.pop(),r[l].onStack=!1,d.push(l);while(s!==l);o.push(d)}}return e.nodes().forEach(function(s){s in r||i(s)}),o}function yn(e){return et(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var _n=()=>1;function xn(e,t,n){return Nn(e,t||_n,n||function(r){return e.outEdges(r)})}function Nn(e,t,n){let r={},o=e.nodes();return o.forEach(function(i){r[i]={},r[i][i]={distance:0,predecessor:""},o.forEach(function(s){i!==s&&(r[i][s]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),n(i).forEach(function(s){let a=s.v===i?s.w:s.v,d=t(s);r[i][a]={distance:d,predecessor:i}})}),o.forEach(function(i){let s=r[i];o.forEach(function(a){let d=r[a];o.forEach(function(l){let h=d[i],c=s[l],u=d[l],f=h.distance+c.distance;f<u.distance&&(u.distance=f,u.predecessor=c.predecessor)})})}),r}var Z=class extends Error{constructor(...e){super(...e)}};function tt(e){let t={},n={},r=[];function o(i){if(i in n)throw new Z;i in t||(n[i]=!0,t[i]=!0,e.predecessors(i).forEach(o),delete n[i],r.push(i))}if(e.sinks().forEach(o),Object.keys(t).length!==e.nodeCount())throw new Z;return r}function kn(e){try{tt(e)}catch(t){if(t instanceof Z)return!1;throw t}return!0}function In(e,t,n,r,o){Array.isArray(t)||(t=[t]);let i=(a=>{var d;return(d=e.isDirected()?e.successors(a):e.neighbors(a))!=null?d:[]}),s={};return t.forEach(function(a){if(!e.hasNode(a))throw new Error("Graph does not have node: "+a);o=nt(e,a,n==="post",s,i,r,o)}),o}function nt(e,t,n,r,o,i,s){return t in r||(r[t]=!0,n||(s=i(s,t)),o(t).forEach(function(a){s=nt(e,a,n,r,o,i,s)}),n&&(s=i(s,t))),s}function rt(e,t,n){return In(e,t,n,function(r,o){return r.push(o),r},[])}function On(e,t){return rt(e,t,"post")}function jn(e,t){return rt(e,t,"pre")}function Cn(e,t){let n=new O,r={},o=new Xe,i;function s(d){let l=d.v===i?d.w:d.v,h=o.priority(l);if(h!==void 0){let c=t(d);c<h&&(r[l]=i,o.decrease(l,c))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(d){o.add(d,Number.POSITIVE_INFINITY),n.setNode(d)}),o.decrease(e.nodes()[0],0);let a=!1;for(;o.size()>0;){if(i=o.removeMin(),i in r)n.setEdge(i,r[i]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(i).forEach(s)}return n}function Ln(e,t,n,r){return Mn(e,t,n,r??(o=>{let i=e.outEdges(o);return i??[]}))}function Mn(e,t,n,r){if(n===void 0)return q(e,t,n,r);let o=!1,i=e.nodes();for(let s=0;s<i.length;s++){let a=r(i[s]);for(let d=0;d<a.length;d++){let l=a[d],h=l.v===i[s]?l.v:l.w,c=h===l.v?l.w:l.v;n({v:h,w:c})<0&&(o=!0)}if(o)return Qe(e,t,n,r)}return q(e,t,n,r)}function P(e,t,n,r){let o=r;for(;e.hasNode(o);)o=ce(r);return n.dummy=t,e.setNode(o,n),o}function Tn(e){let t=new O().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+o.weight,minlen:Math.max(r.minlen,o.minlen)})}),t}function ot(e){let t=new O({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Ce(e,t){let n=e.x,r=e.y,o=t.x-n,i=t.y-r,s=e.width/2,a=e.height/2;if(!o&&!i)throw new Error("Not possible to find intersection inside of the rectangle");let d,l;return Math.abs(i)*s>Math.abs(o)*a?(i<0&&(a=-a),d=a*o/i,l=a):(o<0&&(s=-s),d=s,l=s*i/o),{x:n+d,y:r+l}}function $(e){let t=A(st(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),o=r.rank;o!==void 0&&(t[o]||(t[o]=[]),t[o][r.order]=n)}),t}function Dn(e){let t=e.nodes().map(r=>{let o=e.node(r).rank;return o===void 0?Number.MAX_VALUE:o}),n=C(Math.min,t);e.nodes().forEach(r=>{let o=e.node(r);Object.hasOwn(o,"rank")&&(o.rank-=n)})}function Pn(e){let t=e.nodes().map(s=>e.node(s).rank).filter(s=>s!==void 0),n=C(Math.min,t),r=[];e.nodes().forEach(s=>{let a=e.node(s).rank-n;r[a]||(r[a]=[]),r[a].push(s)});let o=0,i=e.graph().nodeRankFactor;Array.from(r).forEach((s,a)=>{s===void 0&&a%i!==0?--o:s!==void 0&&o&&s.forEach(d=>e.node(d).rank+=o)})}function Le(e,t,n,r){let o={width:0,height:0};return arguments.length>=4&&(o.rank=n,o.order=r),P(e,"border",o,t)}function Sn(e,t=it){let n=[];for(let r=0;r<e.length;r+=t){let o=e.slice(r,r+t);n.push(o)}return n}var it=65535;function C(e,t){if(t.length>it){let n=Sn(t);return e(...n.map(r=>e(...r)))}else return e(...t)}function st(e){let t=e.nodes().map(n=>{let r=e.node(n).rank;return r===void 0?Number.MIN_VALUE:r});return C(Math.max,t)}function Rn(e,t){let n={lhs:[],rhs:[]};return e.forEach(r=>{t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function at(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function dt(e,t){return t()}var Fn=0;function ce(e){let t=++Fn;return e+(""+t)}function A(e,t,n=1){t==null&&(t=e,e=0);let r=i=>i<t;n<0&&(r=i=>t<i);let o=[];for(let i=e;r(i);i+=n)o.push(i);return o}function J(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function U(e,t){let n;return typeof t=="string"?n=r=>r[t]:n=t,Object.entries(e).reduce((r,[o,i])=>(r[o]=n(i,o),r),{})}function An(e,t){return e.reduce((n,r,o)=>(n[r]=t[o],n),{})}var Q="\0",$n="3.0.0",Gn=class{constructor(){an(this,"_sentinel");let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Me(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Me(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,Vn)),n=n._prev;return"["+e.join(", ")+"]"}};function Me(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Vn(e,t){if(e!=="_next"&&e!=="_prev")return t}var zn=Gn,Hn=()=>1;function Bn(e,t){if(e.nodeCount()<=1)return[];let n=Yn(e,t||Hn);return Wn(n.graph,n.buckets,n.zeroIdx).flatMap(r=>e.outEdges(r.v,r.w)||[])}function Wn(e,t,n){var r;let o=[],i=t[t.length-1],s=t[0],a;for(;e.nodeCount();){for(;a=s.dequeue();)ne(e,t,n,a);for(;a=i.dequeue();)ne(e,t,n,a);if(e.nodeCount()){for(let d=t.length-2;d>0;--d)if(a=(r=t[d])==null?void 0:r.dequeue(),a){o=o.concat(ne(e,t,n,a,!0)||[]);break}}}return o}function ne(e,t,n,r,o){let i=[],s=o?i:void 0;return(e.inEdges(r.v)||[]).forEach(a=>{let d=e.edge(a),l=e.node(a.v);o&&i.push({v:a.v,w:a.w}),l.out-=d,de(t,n,l)}),(e.outEdges(r.v)||[]).forEach(a=>{let d=e.edge(a),l=a.w,h=e.node(l);h.in-=d,de(t,n,h)}),e.removeNode(r.v),s}function Yn(e,t){let n=new O,r=0,o=0;e.nodes().forEach(a=>{n.setNode(a,{v:a,in:0,out:0})}),e.edges().forEach(a=>{let d=n.edge(a.v,a.w)||0,l=t(a),h=d+l;n.setEdge(a.v,a.w,h);let c=n.node(a.v),u=n.node(a.w);o=Math.max(o,c.out+=l),r=Math.max(r,u.in+=l)});let i=Kn(o+r+3).map(()=>new zn),s=r+1;return n.nodes().forEach(a=>{de(i,s,n.node(a))}),{graph:n,buckets:i,zeroIdx:s}}function de(e,t,n){var r,o,i;n.out?n.in?(i=e[n.out-n.in+t])==null||i.enqueue(n):(o=e[e.length-1])==null||o.enqueue(n):(r=e[0])==null||r.enqueue(n)}function Kn(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function qn(e){(e.graph().acyclicer==="greedy"?Bn(e,t(e)):Zn(e)).forEach(n=>{let r=e.edge(n);e.removeEdge(n),r.forwardName=n.name,r.reversed=!0,e.setEdge(n.w,n.v,r,ce("rev"))});function t(n){return r=>n.edge(r).weight}}function Zn(e){let t=[],n={},r={};function o(i){Object.hasOwn(r,i)||(r[i]=!0,n[i]=!0,e.outEdges(i).forEach(s=>{Object.hasOwn(n,s.w)?t.push(s):o(s.w)}),delete n[i])}return e.nodes().forEach(o),t}function Jn(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function Un(e){e.graph().dummyChains=[],e.edges().forEach(t=>Qn(e,t))}function Qn(e,t){let n=t.v,r=e.node(n).rank,o=t.w,i=e.node(o).rank,s=t.name,a=e.edge(t),d=a.labelRank;if(i===r+1)return;e.removeEdge(t);let l,h,c;for(c=0,++r;r<i;++c,++r)a.points=[],h={width:0,height:0,edgeLabel:a,edgeObj:t,rank:r},l=P(e,"edge",h,"_d"),r===d&&(h.width=a.width,h.height=a.height,h.dummy="edge-label",h.labelpos=a.labelpos),e.setEdge(n,l,{weight:a.weight},s),c===0&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,o,{weight:a.weight},s)}function Xn(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,o;for(e.setEdge(n.edgeObj,r);n.dummy;)o=e.successors(t)[0],e.removeNode(t),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),t=o,n=e.node(t)})}function ue(e){let t={};function n(r){let o=e.node(r);if(Object.hasOwn(t,r))return o.rank;t[r]=!0;let i=e.outEdges(r),s=i?i.map(d=>d==null?Number.POSITIVE_INFINITY:n(d.w)-e.edge(d).minlen):[],a=C(Math.min,s);return a===Number.POSITIVE_INFINITY&&(a=0),o.rank=a}e.sources().forEach(n)}function D(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var lt=er;function er(e){let t=new O({directed:!1}),n=e.nodes();if(n.length===0)throw new Error("Graph must have at least one node");let r=n[0],o=e.nodeCount();t.setNode(r,{});let i,s;for(;tr(t,e)<o&&(i=nr(t,e),!!i);)s=t.hasNode(i.v)?D(e,i):-D(e,i),rr(t,e,s);return t}function tr(e,t){function n(r){let o=t.nodeEdges(r);o&&o.forEach(i=>{let s=i.v,a=r===s?i.w:s;!e.hasNode(a)&&!D(t,i)&&(e.setNode(a,{}),e.setEdge(r,a,{}),n(a))})}return e.nodes().forEach(n),e.nodeCount()}function nr(e,t){return t.edges().reduce((n,r)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(r.v)!==e.hasNode(r.w)&&(o=D(t,r)),o<n[0]?[o,r]:n},[Number.POSITIVE_INFINITY,null])[1]}function rr(e,t,n){e.nodes().forEach(r=>t.node(r).rank+=n)}var{preorder:or,postorder:ir}=he,sr=T;T.initLowLimValues=ge;T.initCutValues=fe;T.calcCutValue=ht;T.leaveEdge=ut;T.enterEdge=ft;T.exchangeEdges=gt;function T(e){e=Tn(e),ue(e);let t=lt(e);ge(t),fe(t,e);let n,r;for(;n=ut(t);)r=ft(t,e,n),gt(t,e,n,r)}function fe(e,t){let n=ir(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(r=>ar(e,t,r))}function ar(e,t,n){let r=e.node(n).parent,o=e.edge(n,r);o.cutvalue=ht(e,t,n)}function ht(e,t,n){let r=e.node(n).parent,o=!0,i=t.edge(n,r),s=0;i||(o=!1,i=t.edge(r,n)),s=i.weight;let a=t.nodeEdges(n);return a&&a.forEach(d=>{let l=d.v===n,h=l?d.w:d.v;if(h!==r){let c=l===o,u=t.edge(d).weight;if(s+=c?u:-u,lr(e,n,h)){let f=e.edge(n,h).cutvalue;s+=c?-f:f}}}),s}function ge(e,t){arguments.length<2&&(t=e.nodes()[0]),ct(e,{},1,t)}function ct(e,t,n,r,o){let i=n,s=e.node(r);t[r]=!0;let a=e.neighbors(r);return a&&a.forEach(d=>{Object.hasOwn(t,d)||(n=ct(e,t,n,d,r))}),s.low=i,s.lim=n++,o?s.parent=o:delete s.parent,n}function ut(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function ft(e,t,n){let r=n.v,o=n.w;t.hasEdge(r,o)||(r=n.w,o=n.v);let i=e.node(r),s=e.node(o),a=i,d=!1;return i.lim>s.lim&&(a=s,d=!0),t.edges().filter(l=>d===Te(e,e.node(l.v),a)&&d!==Te(e,e.node(l.w),a)).reduce((l,h)=>D(t,h)<D(t,l)?h:l)}function gt(e,t,n,r){let o=n.v,i=n.w;e.removeEdge(o,i),e.setEdge(r.v,r.w,{}),ge(e),fe(e,t),dr(e,t)}function dr(e,t){let n=e.nodes().find(o=>!e.node(o).parent);if(!n)return;let r=or(e,[n]);r=r.slice(1),r.forEach(o=>{let i=e.node(o).parent,s=t.edge(o,i),a=!1;s||(s=t.edge(i,o),a=!0),t.node(o).rank=t.node(i).rank+(a?s.minlen:-s.minlen)})}function lr(e,t,n){return e.hasEdge(t,n)}function Te(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var hr=cr;function cr(e){let t=e.graph().ranker;if(typeof t=="function")return t(e);switch(t){case"network-simplex":De(e);break;case"tight-tree":fr(e);break;case"longest-path":ur(e);break;case"none":break;default:De(e)}}var ur=ue;function fr(e){ue(e),lt(e)}function De(e){sr(e)}var gr=pr;function pr(e){let t=vr(e);e.graph().dummyChains.forEach(n=>{let r=e.node(n),o=r.edgeObj,i=mr(e,t,o.v,o.w),s=i.path,a=i.lca,d=0,l=s[d],h=!0;for(;n!==o.w;){if(r=e.node(n),h){for(;(l=s[d])!==a&&e.node(l).maxRank<r.rank;)d++;l===a&&(h=!1)}if(!h){for(;d<s.length-1&&e.node(s[d+1]).minRank<=r.rank;)d++;l=s[d]}l!==void 0&&e.setParent(n,l),n=e.successors(n)[0]}})}function mr(e,t,n,r){let o=[],i=[],s=Math.min(t[n].low,t[r].low),a=Math.max(t[n].lim,t[r].lim),d;d=n;do d=e.parent(d),o.push(d);while(d&&(t[d].low>s||a>t[d].lim));let l=d,h=r;for(;(h=e.parent(h))!==l;)i.push(h);return{path:o.concat(i.reverse()),lca:l}}function vr(e){let t={},n=0;function r(o){let i=n;e.children(o).forEach(r),t[o]={low:i,lim:n++}}return e.children(Q).forEach(r),t}function br(e){let t=P(e,"root",{},"_root"),n=wr(e),r=Object.values(n),o=C(Math.max,r)-1,i=2*o+1;e.graph().nestingRoot=t,e.edges().forEach(a=>e.edge(a).minlen*=i);let s=Er(e)+1;e.children(Q).forEach(a=>pt(e,t,i,s,o,n,a)),e.graph().nodeRankFactor=i}function pt(e,t,n,r,o,i,s){var a;let d=e.children(s);if(!d.length){s!==t&&e.setEdge(t,s,{weight:0,minlen:n});return}let l=Le(e,"_bt"),h=Le(e,"_bb"),c=e.node(s);e.setParent(l,s),c.borderTop=l,e.setParent(h,s),c.borderBottom=h,d.forEach(u=>{var f;pt(e,t,n,r,o,i,u);let m=e.node(u),v=m.borderTop?m.borderTop:u,w=m.borderBottom?m.borderBottom:u,b=m.borderTop?r:2*r,N=v!==w?1:o-((f=i[s])!=null?f:0)+1;e.setEdge(l,v,{weight:b,minlen:N,nestingEdge:!0}),e.setEdge(w,h,{weight:b,minlen:N,nestingEdge:!0})}),e.parent(s)||e.setEdge(t,l,{weight:0,minlen:o+((a=i[s])!=null?a:0)})}function wr(e){let t={};function n(r,o){let i=e.children(r);i&&i.length&&i.forEach(s=>n(s,o+1)),t[r]=o}return e.children(Q).forEach(r=>n(r,1)),t}function Er(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function yr(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{e.edge(n).nestingEdge&&e.removeEdge(n)})}var _r=xr;function xr(e){function t(n){let r=e.children(n),o=e.node(n);if(r.length&&r.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let i=o.minRank,s=o.maxRank+1;i<s;++i)Pe(e,"borderLeft","_bl",n,o,i),Pe(e,"borderRight","_br",n,o,i)}}e.children(Q).forEach(t)}function Pe(e,t,n,r,o,i){let s={width:0,height:0,rank:i,borderType:t},a=o[t][i-1],d=P(e,"border",s,n);o[t][i]=d,e.setParent(d,r),a&&e.setEdge(a,d,{weight:1})}function Nr(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="lr"||n==="rl")&&mt(e)}function kr(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="bt"||n==="rl")&&Ir(e),(n==="lr"||n==="rl")&&(Or(e),mt(e))}function mt(e){e.nodes().forEach(t=>Se(e.node(t))),e.edges().forEach(t=>Se(e.edge(t)))}function Se(e){let t=e.width;e.width=e.height,e.height=t}function Ir(e){e.nodes().forEach(t=>re(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(re),Object.hasOwn(r,"y")&&re(r)})}function re(e){e.y=-e.y}function Or(e){e.nodes().forEach(t=>oe(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(oe),Object.hasOwn(r,"x")&&oe(r)})}function oe(e){let t=e.x;e.x=e.y,e.y=t}function jr(e){let t={},n=e.nodes().filter(a=>!e.children(a).length),r=n.map(a=>e.node(a).rank),o=C(Math.max,r),i=A(o+1).map(()=>[]);function s(a){if(t[a])return;t[a]=!0;let d=e.node(a);i[d.rank].push(a);let l=e.successors(a);l&&l.forEach(s)}return n.sort((a,d)=>e.node(a).rank-e.node(d).rank).forEach(s),i}function Cr(e,t){let n=0;for(let r=1;r<t.length;++r)n+=Lr(e,t[r-1],t[r]);return n}function Lr(e,t,n){let r=An(n,n.map((l,h)=>h)),o=t.flatMap(l=>{let h=e.outEdges(l);return h?h.map(c=>({pos:r[c.w],weight:e.edge(c).weight})).sort((c,u)=>c.pos-u.pos):[]}),i=1;for(;i<n.length;)i<<=1;let s=2*i-1;i-=1;let a=new Array(s).fill(0),d=0;return o.forEach(l=>{let h=l.pos+i;a[h]+=l.weight;let c=0;for(;h>0;)h%2&&(c+=a[h+1]),h=h-1>>1,a[h]+=l.weight;d+=l.weight*c}),d}function Mr(e,t=[]){return t.map(n=>{let r=e.inEdges(n);if(!r||!r.length)return{v:n};{let o=r.reduce((i,s)=>{let a=e.edge(s),d=e.node(s.v);return{sum:i.sum+a.weight*d.order,weight:i.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:o.sum/o.weight,weight:o.weight}}})}function Tr(e,t){let n={};e.forEach((o,i)=>{let s={indegree:0,in:[],out:[],vs:[o.v],i};o.barycenter!==void 0&&(s.barycenter=o.barycenter,s.weight=o.weight),n[o.v]=s}),t.edges().forEach(o=>{let i=n[o.v],s=n[o.w];i!==void 0&&s!==void 0&&(s.indegree++,i.out.push(s))});let r=Object.values(n).filter(o=>!o.indegree);return Dr(r)}function Dr(e){let t=[];function n(o){return i=>{i.merged||(i.barycenter===void 0||o.barycenter===void 0||i.barycenter>=o.barycenter)&&Pr(o,i)}}function r(o){return i=>{i.in.push(o),--i.indegree===0&&e.push(i)}}for(;e.length;){let o=e.pop();t.push(o),o.in.reverse().forEach(n(o)),o.out.forEach(r(o))}return t.filter(o=>!o.merged).map(o=>J(o,["vs","i","barycenter","weight"]))}function Pr(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function Sr(e,t){let n=Rn(e,h=>Object.hasOwn(h,"barycenter")),r=n.lhs,o=n.rhs.sort((h,c)=>c.i-h.i),i=[],s=0,a=0,d=0;r.sort(Rr(!!t)),d=Re(i,o,d),r.forEach(h=>{d+=h.vs.length,i.push(h.vs),s+=h.barycenter*h.weight,a+=h.weight,d=Re(i,o,d)});let l={vs:i.flat(1)};return a&&(l.barycenter=s/a,l.weight=a),l}function Re(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Rr(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function vt(e,t,n,r){let o=e.children(t),i=e.node(t),s=i?i.borderLeft:void 0,a=i?i.borderRight:void 0,d={};s&&(o=o.filter(u=>u!==s&&u!==a));let l=Mr(e,o);l.forEach(u=>{if(e.children(u.v).length){let f=vt(e,u.v,n,r);d[u.v]=f,Object.hasOwn(f,"barycenter")&&Ar(u,f)}});let h=Tr(l,n);Fr(h,d);let c=Sr(h,r);if(s&&a){c.vs=[s,c.vs,a].flat(1);let u=e.predecessors(s);if(u&&u.length){let f=e.node(u[0]),m=e.predecessors(a),v=e.node(m[0]);Object.hasOwn(c,"barycenter")||(c.barycenter=0,c.weight=0),c.barycenter=(c.barycenter*c.weight+f.order+v.order)/(c.weight+2),c.weight+=2}}return c}function Fr(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(r=>t[r]?t[r].vs:r)})}function Ar(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}function $r(e,t,n,r){r||(r=e.nodes());let o=Gr(e),i=new O({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(s=>e.node(s));return r.forEach(s=>{let a=e.node(s),d=e.parent(s);if(a.rank===t||a.minRank<=t&&t<=a.maxRank){i.setNode(s),i.setParent(s,d||o);let l=e[n](s);l&&l.forEach(h=>{let c=h.v===s?h.w:h.v,u=i.edge(c,s),f=u!==void 0?u.weight:0;i.setEdge(c,s,{weight:e.edge(h).weight+f})}),Object.hasOwn(a,"minRank")&&i.setNode(s,{borderLeft:a.borderLeft[t],borderRight:a.borderRight[t]})}}),i}function Gr(e){let t;for(;e.hasNode(t=ce("_root")););return t}function Vr(e,t,n){let r={},o;n.forEach(i=>{let s=e.parent(i),a,d;for(;s;){if(a=e.parent(s),a?(d=r[a],r[a]=s):(d=o,o=s),d&&d!==s){t.setEdge(d,s);return}s=a}})}function bt(e,t={}){if(typeof t.customOrder=="function"){t.customOrder(e,bt);return}let n=st(e),r=Fe(e,A(1,n+1),"inEdges"),o=Fe(e,A(n-1,-1,-1),"outEdges"),i=jr(e);if(Ae(e,i),t.disableOptimalOrderHeuristic)return;let s=Number.POSITIVE_INFINITY,a,d=t.constraints||[];for(let l=0,h=0;h<4;++l,++h){zr(l%2?r:o,l%4>=2,d),i=$(e);let c=Cr(e,i);c<s?(h=0,a=Object.assign({},i),s=c):c===s&&(a=structuredClone(i))}Ae(e,a)}function Fe(e,t,n){let r=new Map,o=(i,s)=>{r.has(i)||r.set(i,[]),r.get(i).push(s)};for(let i of e.nodes()){let s=e.node(i);if(typeof s.rank=="number"&&o(s.rank,i),typeof s.minRank=="number"&&typeof s.maxRank=="number")for(let a=s.minRank;a<=s.maxRank;a++)a!==s.rank&&o(a,i)}return t.map(function(i){return $r(e,i,n,r.get(i)||[])})}function zr(e,t,n){let r=new O;e.forEach(function(o){n.forEach(a=>r.setEdge(a.left,a.right));let i=o.graph().root,s=vt(o,i,r,t);s.vs.forEach((a,d)=>o.node(a).order=d),Vr(o,r,s.vs)})}function Ae(e,t){Object.values(t).forEach(n=>n.forEach((r,o)=>e.node(r).order=o))}function Hr(e,t){let n={};function r(o,i){let s=0,a=0,d=o.length,l=i[i.length-1];return i.forEach((h,c)=>{let u=Wr(e,h),f=u?e.node(u).order:d;(u||h===l)&&(i.slice(a,c+1).forEach(m=>{let v=e.predecessors(m);v&&v.forEach(w=>{let b=e.node(w),N=b.order;(N<s||f<N)&&!(b.dummy&&e.node(m).dummy)&&wt(n,w,m)})}),a=c+1,s=f)}),i}return t.length&&t.reduce(r),n}function Br(e,t){let n={};function r(i,s,a,d,l){A(s,a).forEach(h=>{let c=i[h];if(c!==void 0&&e.node(c).dummy){let u=e.predecessors(c);u&&u.forEach(f=>{if(f===void 0)return;let m=e.node(f);m.dummy&&(m.order<d||m.order>l)&&wt(n,f,c)})}})}function o(i,s){let a=-1,d=-1,l=0;return s.forEach((h,c)=>{if(e.node(h).dummy==="border"){let u=e.predecessors(h);if(u&&u.length){let f=u[0];if(f===void 0)return;d=e.node(f).order,r(s,l,c,a,d),l=c,a=d}}r(s,l,s.length,d,i.length)}),s}return t.length&&t.reduce(o),n}function Wr(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(r=>e.node(r).dummy)}}function wt(e,t,n){if(t>n){let o=t;t=n,n=o}let r=e[t];r||(e[t]=r={}),r[n]=!0}function Yr(e,t,n){if(t>n){let o=t;t=n,n=o}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function Kr(e,t,n,r){let o={},i={},s={};return t.forEach(a=>{a.forEach((d,l)=>{o[d]=d,i[d]=d,s[d]=l})}),t.forEach(a=>{let d=-1;a.forEach(l=>{let h=r(l);if(h&&h.length){let c=h.sort((f,m)=>{let v=s[f],w=s[m];return(v!==void 0?v:0)-(w!==void 0?w:0)}),u=(c.length-1)/2;for(let f=Math.floor(u),m=Math.ceil(u);f<=m;++f){let v=c[f];if(v===void 0)continue;let w=s[v];if(w!==void 0&&i[l]===l&&d<w&&!Yr(n,l,v)){let b=o[v];b!==void 0&&(i[v]=l,i[l]=o[l]=b,d=w)}}}})}),{root:o,align:i}}function qr(e,t,n,r,o=!1){let i={},s=Zr(e,t,n,o),a=o?"borderLeft":"borderRight";function d(f,m){let v=s.nodes().slice(),w={},b=v.pop();for(;b;){if(w[b])f(b);else{w[b]=!0,v.push(b);for(let N of m(b))v.push(N)}b=v.pop()}}function l(f){let m=s.inEdges(f);m?i[f]=m.reduce((v,w)=>{var b;let N=(b=i[w.v])!=null?b:0,k=s.edge(w);return Math.max(v,N+(k!==void 0?k:0))},0):i[f]=0}function h(f){let m=s.outEdges(f),v=Number.POSITIVE_INFINITY;m&&(v=m.reduce((b,N)=>{let k=i[N.w],L=s.edge(N);return Math.min(b,(k!==void 0?k:0)-(L!==void 0?L:0))},Number.POSITIVE_INFINITY));let w=e.node(f);v!==Number.POSITIVE_INFINITY&&w.borderType!==a&&(i[f]=Math.max(i[f]!==void 0?i[f]:0,v))}function c(f){return s.predecessors(f)||[]}function u(f){return s.successors(f)||[]}return d(l,c),d(h,u),Object.keys(r).forEach(f=>{var m;let v=n[f];v!==void 0&&(i[f]=(m=i[v])!=null?m:0)}),i}function Zr(e,t,n,r){let o=new O,i=e.graph(),s=eo(i.nodesep,i.edgesep,r);return t.forEach(a=>{let d;a.forEach(l=>{let h=n[l];if(h!==void 0){if(o.setNode(h),d!==void 0){let c=n[d];if(c!==void 0){let u=o.edge(c,h);o.setEdge(c,h,Math.max(s(e,l,d),u||0))}}d=l}})}),o}function Jr(e,t){return Object.values(t).reduce((n,r)=>{let o=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([a,d])=>{let l=to(e,a)/2;o=Math.max(d+l,o),i=Math.min(d-l,i)});let s=o-i;return s<n[0]&&(n=[s,r]),n},[Number.POSITIVE_INFINITY,null])[1]}function Ur(e,t){let n=Object.values(t),r=C(Math.min,n),o=C(Math.max,n);["u","d"].forEach(i=>{["l","r"].forEach(s=>{let a=i+s,d=e[a];if(!d||d===t)return;let l=Object.values(d),h=r-C(Math.min,l);s!=="l"&&(h=o-C(Math.max,l)),h&&(e[a]=U(d,c=>c+h))})})}function Qr(e,t=void 0){let n=e.ul;return n?U(n,(r,o)=>{var i,s;if(t){let d=t.toLowerCase(),l=e[d];if(l&&l[o]!==void 0)return l[o]}let a=Object.values(e).map(d=>{let l=d[o];return l!==void 0?l:0}).sort((d,l)=>d-l);return(((i=a[1])!=null?i:0)+((s=a[2])!=null?s:0))/2}):{}}function Xr(e){let t=$(e),n=Object.assign(Hr(e,t),Br(e,t)),r={},o;["u","d"].forEach(s=>{o=s==="u"?t:Object.values(t).reverse(),["l","r"].forEach(a=>{a==="r"&&(o=o.map(h=>Object.values(h).reverse()));let d=Kr(e,o,n,h=>(s==="u"?e.predecessors(h):e.successors(h))||[]),l=qr(e,o,d.root,d.align,a==="r");a==="r"&&(l=U(l,h=>-h)),r[s+a]=l})});let i=Jr(e,r);return Ur(r,i),Qr(r,e.graph().align)}function eo(e,t,n){return(r,o,i)=>{let s=r.node(o),a=r.node(i),d=0,l;if(d+=s.width/2,Object.hasOwn(s,"labelpos"))switch(s.labelpos.toLowerCase()){case"l":l=-s.width/2;break;case"r":l=s.width/2;break}if(l&&(d+=n?l:-l),l=void 0,d+=(s.dummy?t:e)/2,d+=(a.dummy?t:e)/2,d+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":l=a.width/2;break;case"r":l=-a.width/2;break}return l&&(d+=n?l:-l),d}}function to(e,t){return e.node(t).width}function no(e){e=ot(e),ro(e),Object.entries(Xr(e)).forEach(([t,n])=>e.node(t).x=n)}function ro(e){let t=$(e),n=e.graph(),r=n.ranksep,o=n.rankalign,i=0;t.forEach(s=>{let a=s.reduce((d,l)=>{var h;let c=(h=e.node(l).height)!=null?h:0;return d>c?d:c},0);s.forEach(d=>{let l=e.node(d);o==="top"?l.y=i+l.height/2:o==="bottom"?l.y=i+a-l.height/2:l.y=i+a/2}),i+=a+r})}function oo(e,t={}){let n=t.debugTiming?at:dt;return n("layout",()=>{let r=n(" buildLayoutGraph",()=>po(e));return n(" runLayout",()=>io(r,n,t)),n(" updateInputGraph",()=>so(e,r)),r})}function io(e,t,n){t(" makeSpaceForEdgeLabels",()=>mo(e)),t(" removeSelfEdges",()=>ko(e)),t(" acyclic",()=>qn(e)),t(" nestingGraph.run",()=>br(e)),t(" rank",()=>hr(ot(e))),t(" injectEdgeLabelProxies",()=>vo(e)),t(" removeEmptyRanks",()=>Pn(e)),t(" nestingGraph.cleanup",()=>yr(e)),t(" normalizeRanks",()=>Dn(e)),t(" assignRankMinMax",()=>bo(e)),t(" removeEdgeLabelProxies",()=>wo(e)),t(" normalize.run",()=>Un(e)),t(" parentDummyChains",()=>gr(e)),t(" addBorderSegments",()=>_r(e)),t(" order",()=>bt(e,n)),t(" insertSelfEdges",()=>Io(e)),t(" adjustCoordinateSystem",()=>Nr(e)),t(" position",()=>no(e)),t(" positionSelfEdges",()=>Oo(e)),t(" removeBorderNodes",()=>No(e)),t(" normalize.undo",()=>Xn(e)),t(" fixupEdgeLabelCoords",()=>_o(e)),t(" undoCoordinateSystem",()=>kr(e)),t(" translateGraph",()=>Eo(e)),t(" assignNodeIntersects",()=>yo(e)),t(" reversePoints",()=>xo(e)),t(" acyclic.undo",()=>Jn(e))}function so(e,t){e.nodes().forEach(n=>{let r=e.node(n),o=t.node(n);r&&(r.x=o.x,r.y=o.y,r.order=o.order,r.rank=o.rank,t.children(n).length&&(r.width=o.width,r.height=o.height))}),e.edges().forEach(n=>{let r=e.edge(n),o=t.edge(n);r.points=o.points,Object.hasOwn(o,"x")&&(r.x=o.x,r.y=o.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var ao=["nodesep","edgesep","ranksep","marginx","marginy"],lo={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},ho=["acyclicer","ranker","rankdir","align","rankalign"],co=["width","height","rank"],$e={width:0,height:0},uo=["minlen","weight","width","height","labeloffset"],fo={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},go=["labelpos"];function po(e){let t=new O({multigraph:!0,compound:!0}),n=se(e.graph());return t.setGraph(Object.assign({},lo,ie(n,ao),J(n,ho))),e.nodes().forEach(r=>{let o=se(e.node(r)),i=ie(o,co);Object.keys($e).forEach(a=>{i[a]===void 0&&(i[a]=$e[a])}),t.setNode(r,i);let s=e.parent(r);s!==void 0&&t.setParent(r,s)}),e.edges().forEach(r=>{let o=se(e.edge(r));t.setEdge(r,Object.assign({},fo,ie(o,uo),J(o,go)))}),t}function mo(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function vo(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let r=e.node(t.v),o={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};P(e,"edge-proxy",o,"_ep")}})}function bo(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function wo(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="edge-proxy"){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function Eo(e){let t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,o=0,i=e.graph(),s=i.marginx||0,a=i.marginy||0;function d(l){let h=l.x,c=l.y,u=l.width,f=l.height;t=Math.min(t,h-u/2),n=Math.max(n,h+u/2),r=Math.min(r,c-f/2),o=Math.max(o,c+f/2)}e.nodes().forEach(l=>d(e.node(l))),e.edges().forEach(l=>{let h=e.edge(l);Object.hasOwn(h,"x")&&d(h)}),t-=s,r-=a,e.nodes().forEach(l=>{let h=e.node(l);h.x-=t,h.y-=r}),e.edges().forEach(l=>{let h=e.edge(l);h.points.forEach(c=>{c.x-=t,c.y-=r}),Object.hasOwn(h,"x")&&(h.x-=t),Object.hasOwn(h,"y")&&(h.y-=r)}),i.width=n-t+s,i.height=o-r+a}function yo(e){e.edges().forEach(t=>{let n=e.edge(t),r=e.node(t.v),o=e.node(t.w),i,s;n.points?(i=n.points[0],s=n.points[n.points.length-1]):(n.points=[],i=o,s=r),n.points.unshift(Ce(r,i)),n.points.push(Ce(o,s))})}function _o(e){e.edges().forEach(t=>{let n=e.edge(t);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 xo(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function No(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),o=e.node(n.borderBottom),i=e.node(n.borderLeft[n.borderLeft.length-1]),s=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(s.x-i.x),n.height=Math.abs(o.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function ko(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function Io(e){$(e).forEach(t=>{let n=0;t.forEach((r,o)=>{let i=e.node(r);i.order=o+n,(i.selfEdges||[]).forEach(s=>{P(e,"selfedge",{width:s.label.width,height:s.label.height,rank:i.rank,order:o+ ++n,e:s.e,label:s.label},"_se")}),delete i.selfEdges})})}function Oo(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="selfedge"){let r=n,o=e.node(r.e.v),i=o.x+o.width/2,s=o.y,a=n.x-i,d=o.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:i+2*a/3,y:s-d},{x:i+5*a/6,y:s-d},{x:i+a,y:s},{x:i+5*a/6,y:s+d},{x:i+2*a/3,y:s+d}],r.label.x=n.x,r.label.y=n.y}})}function ie(e,t){return U(J(e,t),Number)}function se(e){let t={};return e&&Object.entries(e).forEach(([n,r])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=r}),t}function jo(e){let t=$(e),n=new O({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(r=>{n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),e.edges().forEach(r=>n.setEdge(r.v,r.w,{},r.name)),t.forEach((r,o)=>{let i="layer"+o;n.setNode(i,{rank:"same"}),r.reduce((s,a)=>(n.setEdge(s,a,{style:"invis"}),a))}),n}var Co={graphlib:Ze,version:$n,layout:oo,debug:jo,util:{time:at,notime:dt}},Ge=Co;/*! For license information please see dagre.esm.js.LEGAL.txt */const Ve=80;function Lo(e,t){const n=new Map,r=Math.ceil(Math.sqrt(e.length)),{maxWidth:o,maxHeight:i}=e.reduce((s,a)=>({maxWidth:Math.max(s.maxWidth,a.width),maxHeight:Math.max(s.maxHeight,a.height)}),{maxWidth:0,maxHeight:0});return e.forEach((s,a)=>{const d=a%r,l=Math.floor(a/r),h=t==="horizontal"?d:l,c=t==="horizontal"?l:d;n.set(s.id,{x:h*(o+Ve),y:c*(i+Ve)})}),n}function Mo(e,t,n){const r=new Map,o=new Map,i=new Map;if(e.length===0)return{positions:r,routes:o,labelPositions:i};const s=new Ge.graphlib.Graph({multigraph:!0});s.setGraph({rankdir:n==="horizontal"?"LR":"TB"}),s.setDefaultEdgeLabel(()=>({}));for(const a of e)s.setNode(a.id,{width:a.width,height:a.height});for(const a of t){const d=a.label?{width:a.label.width,height:a.label.height,labelpos:"c"}:{};s.setEdge(a.sourceId,a.targetId,d,a.id)}try{Ge.layout(s)}catch(a){if(!(a instanceof RangeError))throw a;return{positions:Lo(e,n),routes:o,labelPositions:i}}for(const a of s.nodes()){const d=s.node(a);d.x===void 0||d.y===void 0||r.set(a,{x:d.x-d.width/2,y:d.y-d.height/2})}for(const a of t){const d=s.edge({v:a.sourceId,w:a.targetId,name:a.id}),l=(d.points??[]).slice(1,-1);l.length>0&&o.set(a.id,l),d.x!==void 0&&d.y!==void 0&&i.set(a.id,{x:d.x,y:d.y})}return{positions:r,routes:o,labelPositions:i}}const To=(e,t)=>[e,t].sort().join("->"),Et=56;function Do(e,t=Et){const n=new Map;for(const o of e){if(o.sourceId===o.targetId)continue;const i=To(o.sourceId,o.targetId),s=n.get(i);s?s.push(o):n.set(i,[o])}const r=new Map;for(const o of e)o.sourceId===o.targetId&&r.set(o.id,0);for(const o of n.values()){const i=[...o].sort((a,d)=>a.id.localeCompare(d.id)),s=i.length;i.forEach((a,d)=>{r.set(a.id,(d-(s-1)/2)*t)})}return r}function le(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function ze(e,t,n){const r=le(e,t);if(r===0)return e;const o=n/r;return{x:e.x+(t.x-e.x)*o,y:e.y+(t.y-e.y)*o}}function Po(e,t){if(e.length<2)return"";if(e.length===2){const[a,d]=e;return`M ${a.x} ${a.y} L ${d.x} ${d.y}`}const[n,...r]=e;let o=`M ${n.x} ${n.y}`,i=n;for(let a=1;a<e.length-1;a++){const d=e[a],l=e[a+1],h=le(i,d),c=le(d,l),u=Math.max(0,Math.min(t,h/2,c/2)),f=u===0?d:ze(d,i,u),m=u===0?d:ze(d,l,u);o+=` L ${f.x} ${f.y}`,o+=` Q ${d.x} ${d.y}, ${m.x} ${m.y}`,i=m}const s=r[r.length-1];return o+=` L ${s.x} ${s.y}`,o}const So=10;function Ro({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:o,targetPosition:i,markerStart:s,markerEnd:a,data:d}){const l=x.useRef(null),[h,c]=x.useState(null),{route:u,bowOffset:f,warning:m,joinLabel:v,dimmed:w,labelPosition:b,direction:N}=d;let k;if(u.length>0)k=Po([{x:e,y:t},...u,{x:n,y:r}],So);else if(f!==0)if(N==="vertical"){const I=Math.max(40,Math.abs(r-t)*.3);k=`M ${e} ${t} C ${e+f} ${t+I}, ${n+f} ${r-I}, ${n} ${r}`}else{const I=Math.max(40,Math.abs(n-e)*.3);k=`M ${e} ${t} C ${e+I} ${t+f}, ${n-I} ${r+f}, ${n} ${r}`}else[k]=At({sourceX:e,sourceY:t,sourcePosition:o,targetX:n,targetY:r,targetPosition:i});const L=.5+Math.max(-.18,Math.min(.18,f/Et*.24)),X=m?K:Ke;x.useEffect(()=>{if(b||v.length===0)return;const I=l.current;if(!I){c(null);return}const E=I.getTotalLength(),j=I.getPointAtLength(E*L);c({x:j.x,y:j.y})},[k,L,b,v]);const S=b??h;return g.jsxs(g.Fragment,{children:[g.jsx("path",{ref:l,d:k,fill:"none",strokeWidth:Gt,stroke:X,strokeDasharray:m?$t:void 0,opacity:w?ae:1,markerEnd:a,markerStart:s,style:{pointerEvents:"auto",transition:"opacity 0.2s"}}),v.length>0&&S&&g.jsx("foreignObject",{x:S.x,y:S.y,width:1,height:1,style:{overflow:"visible"},children:g.jsx("div",{style:{transform:"translate(-50%, -50%)",width:"max-content",background:"var(--background)",border:"1px solid var(--border)",borderRadius:8,padding:"3px 8px",fontSize:11,fontWeight:600,lineHeight:1.5,color:"var(--foreground)",pointerEvents:"none",opacity:w?ae:1,transition:"opacity 0.2s",boxShadow:"0 1px 3px 0 rgba(0,0,0,0.08)"},children:v.map(I=>g.jsx("div",{children:I},I))})})]})}const pe=240,me=74;function Fo({data:e}){const t=e.highlighted?ee:e.isDraft?K:Vt;function n(s){s.stopPropagation(),s.preventDefault(),e.onOpenExternal()}const r=e.direction==="vertical"?Y.Top:Y.Left,o=e.direction==="vertical"?Y.Bottom:Y.Right,i=`Open ${e.title} in new tab`;return g.jsxs("div",{style:{width:pe,height:me,borderRadius:8,border:`2px solid ${t}`,background:"var(--background)",boxShadow:e.highlighted?`0 0 0 3px ${ee}40, 0 0 12px ${ee}60`:"0 1px 4px 0 rgba(0,0,0,0.12)",cursor:"default",position:"relative",opacity:e.dimmed?ae:1,filter:e.dimmed?"grayscale(0.8)":void 0,animation:e.highlighted?"node-pulse 1.5s ease-in-out infinite":void 0,transition:"opacity 0.2s, filter 0.2s"},children:[e.isDraft&&g.jsx("span",{style:{position:"absolute",top:-18,right:4,fontSize:10,fontWeight:600,color:K,lineHeight:1},children:"Draft"}),e.hasIncoming&&g.jsx(_e,{type:"target",position:r,isConnectable:!1,style:xe}),g.jsxs("div",{className:"bg-muted flex items-center justify-between",style:{padding:"8px 10px 8px 14px",fontSize:13,fontWeight:600,borderRadius:"6px 6px 0 0"},children:[g.jsx("span",{className:"truncate",title:e.title,children:e.title}),g.jsxs("div",{className:"ml-2 flex shrink-0 items-center gap-0.5",children:[e.description&&g.jsxs(It,{children:[g.jsx(Ot,{asChild:!0,children:g.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground inline-flex cursor-default rounded p-0.5 transition-colors","aria-label":`Description for ${e.title}`,onPointerDown:s=>{s.stopPropagation()},children:g.jsx(jt,{style:{width:14,height:14},"aria-hidden":"true"})})}),g.jsx(Ct,{side:"top",align:"center",role:"tooltip",children:e.description})]}),g.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground shrink-0 cursor-pointer rounded p-0.5 transition-colors",onPointerDown:s=>{s.stopPropagation()},onClick:n,title:i,"aria-label":i,children:g.jsx(Lt,{style:{width:14,height:14},"aria-hidden":"true"})})]})]}),g.jsx("div",{className:"text-muted-foreground flex items-center",style:{padding:"6px 14px 8px",fontSize:11,minWidth:0},children:g.jsxs("span",{className:"ml-auto shrink-0",children:[e.fieldCount," field",e.fieldCount!==1?"s":""]})}),e.hasOutgoing&&g.jsx(_e,{type:"source",position:o,isConnectable:!1,style:xe})]})}const He="model-canvas-layout",Be="model-canvas-show-join-fields",R=.2,We=12,Ao=6.6,$o=18,Go=16.5,Vo=8,zo=150;function Ho(e){return e.length===0?void 0:{width:Math.max(...e.map(n=>n.length))*Ao+$o,height:e.length*Go+Vo}}const Bo={modelCanvasNode:Fo},Wo={modelCanvasEdge:Ro};function Yo(e){const{node:t,highlight:n}=e;return{id:t.id,type:"modelCanvasNode",position:e.position,width:pe,height:me,draggable:!1,selectable:!1,focusable:!1,style:en,data:{title:t.title,isDraft:t.status===Ye.DRAFT,fieldCount:t.fieldCount,description:t.description,hasIncoming:e.hasIncoming,hasOutgoing:e.hasOutgoing,highlighted:n.highlighted,dimmed:n.dimmed,direction:e.direction,onOpenExternal:e.onOpenExternal}}}function Ko(e){return e.joinConditions.map(t=>`${t.sourceFieldName} = ${t.targetFieldName}`)}function qo(e){const{edge:t,warning:n}=e,r=n?K:Ke,o={type:tn.ArrowClosed,color:r,width:We,height:We};return{id:t.id,type:"modelCanvasEdge",source:t.sourceId,target:t.targetId,focusable:!1,selectable:!1,markerEnd:o,markerStart:t.bidirectional?o:void 0,data:{route:e.route,bowOffset:e.bowOffset,warning:n,joinLabel:e.joinLabel,dimmed:e.dimmed,labelPosition:e.labelPosition,direction:e.direction}}}function Zo({nodes:e,edges:t,searchQuery:n,onOpenDataMart:r}){const o=Bt(),i=Ne(E=>E.width),s=Ne(E=>E.height),a=x.useRef(r);a.current=r;const d=x.useRef(e);d.current=e;const l=x.useRef(n);l.current=n;const[h,c]=x.useState(()=>rn(B.get(He))),[u,f]=x.useState(()=>B.get(Be,"boolean")??!1),[m,v]=x.useState(!1),[w,b]=x.useState([]),[N,k]=x.useState([]),L=x.useMemo(()=>Wt(w),[w]);x.useEffect(()=>{const E=new Set(t.map(p=>p.targetId)),j=new Set(t.map(p=>p.sourceId)),y=new Map(e.map(p=>[p.id,p.status===Ye.DRAFT])),_=ke(e,l.current,p=>p.id,p=>p.title),M=e.map(p=>({id:p.id,width:pe,height:me})),G=u?new Map(t.map(p=>[p.id,Ko(p)])):new Map,V=t.map(p=>({id:p.id,sourceId:p.sourceId,targetId:p.targetId,label:Ho(G.get(p.id)??[])})),{positions:z,routes:H,labelPositions:yt}=Mo(M,V,h),_t=Do(t);b(e.map(p=>Yo({node:p,position:z.get(p.id)??{x:0,y:0},hasIncoming:E.has(p.id),hasOutgoing:j.has(p.id),highlight:_.get(p.id)??Ie,direction:h,onOpenExternal:()=>{a.current(p.id)}}))),k(t.map(p=>{var Ee,ye;const be=H.get(p.id)??[],we=be.length===0?_t.get(p.id)??0:0,Nt=((Ee=_.get(p.sourceId))==null?void 0:Ee.dimmed)??!1,kt=((ye=_.get(p.targetId))==null?void 0:ye.dimmed)??!1;return qo({edge:p,joinLabel:G.get(p.id)??[],route:be,bowOffset:we,warning:p.joinNotConfigured||(y.get(p.sourceId)??!1)||(y.get(p.targetId)??!1),dimmed:Nt&&kt,labelPosition:we===0?yt.get(p.id):void 0,direction:h})})),v(!0);const ve=[..._.entries()].filter(([,p])=>p.highlighted).map(([p])=>p),xt=requestAnimationFrame(()=>{o.fitView(ve.length>0?{nodes:ve.map(p=>({id:p})),duration:300,padding:R}:{padding:R,duration:300})});return()=>{cancelAnimationFrame(xt)}},[e,t,h,u,o]),x.useEffect(()=>{const E=ke(d.current,n,y=>y.id,y=>y.title);b(y=>y.map(_=>{const M=E.get(_.id)??Ie;return _.data.highlighted===M.highlighted&&_.data.dimmed===M.dimmed?_:{..._,data:{..._.data,...M}}})),k(y=>y.map(_=>{var z,H;const M=((z=E.get(_.source))==null?void 0:z.dimmed)??!1,G=((H=E.get(_.target))==null?void 0:H.dimmed)??!1,V=M&&G;return _.data.dimmed===V?_:{..._,data:{..._.data,dimmed:V}}}));const j=[...E.entries()].filter(([,y])=>y.highlighted).map(([y])=>y);j.length>0&&o.fitView({nodes:j.map(y=>({id:y})),duration:300,padding:R})},[n,o]);const X=x.useCallback(E=>{c(E),B.set(He,E)},[]),S=x.useCallback(E=>{f(E),B.set(Be,E)},[]),I=x.useCallback((E,j)=>{if(i===0||s===0)return;const y=Yt(j,L,i,s,zo);y.x===j.x&&y.y===j.y||o.setViewport(y)},[L,s,i,o]);return g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"absolute top-3 right-3 z-10 flex flex-col gap-1.5",children:[g.jsx(W,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{o.fitView({padding:R,duration:300})},"aria-label":"Fit to view",children:g.jsx(Kt,{className:"h-6 w-6"})}),g.jsx(W,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{o.zoomIn({duration:150})},"aria-label":"Zoom in",children:g.jsx(qt,{className:"h-6 w-6"})}),g.jsx(W,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{o.zoomOut({duration:150})},"aria-label":"Zoom out",children:g.jsx(Zt,{className:"h-6 w-6"})}),g.jsxs(Mt,{children:[g.jsx(Tt,{asChild:!0,children:g.jsx(W,{variant:"outline",size:"icon",className:"h-12 w-12","aria-label":"Canvas settings",children:g.jsx(Dt,{className:"h-6 w-6"})})}),g.jsxs(Pt,{align:"end",side:"left",className:"w-56",children:[g.jsx(St,{children:"Layout algorithm"}),g.jsx("div",{role:"radiogroup","aria-label":"Layout algorithm",className:"mt-2 space-y-0.5",children:nn.map(E=>g.jsxs("button",{type:"button",role:"radio","aria-checked":h===E.value,className:"hover:bg-muted flex w-full items-center justify-between rounded px-2 py-1.5 text-left text-sm",onClick:()=>{X(E.value)},children:[g.jsx("span",{children:E.label}),h===E.value&&g.jsx(Rt,{className:"h-4 w-4"})]},E.value))}),g.jsxs("div",{className:"mt-3 flex items-center justify-between gap-2 border-t pt-3",children:[g.jsx("label",{htmlFor:"model-canvas-show-join-fields",className:"text-sm",children:"Show join fields"}),g.jsx(Ft,{id:"model-canvas-show-join-fields",checked:u,onCheckedChange:S})]})]})]})]}),m&&g.jsxs(Jt,{nodes:w,edges:N,nodeTypes:Bo,edgeTypes:Wo,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,edgesFocusable:!1,minZoom:.05,maxZoom:2,onMove:I,fitView:!0,fitViewOptions:{padding:R},style:{width:"100%",height:"100%"},children:[g.jsx(Ut,{variant:Qt.Lines,gap:16,color:"rgba(0,0,0,0.06)"}),g.jsx(Xt,{pannable:!0,zoomable:!0,style:{width:140,height:100}})]})]})}function Qo({nodes:e,edges:t,searchQuery:n,onOpenDataMart:r,className:o,style:i}){return e.length===0?null:g.jsxs("div",{className:`relative overflow-hidden rounded-lg border ${o??""}`,style:i??{height:480},children:[g.jsx("style",{children:zt}),g.jsx(Ht,{children:g.jsx(Zo,{nodes:e,edges:t,searchQuery:n,onOpenDataMart:r})})]})}export{Qo as default};
@@ -1 +1 @@
1
- import{u as Q,r as o,j as s,h as ee,g as te,C as se,M as ie,T as ae,N as ne,a as oe,b as re,I as le,c as ce,E as de,B as he,d as H,e as ge,i as Y,f as ue}from"./index-qwc0uqor.js";import{N as pe,R as fe,D as Z,H as I,W as P,a as J,b as z,S as K,P as W,u as me,c as U,g as xe,d as ye,e as be,f as Ne,L as we,Z as Ce,h as je,i as De,B as Ae,j as Re,M as Me,k as Se,l as ve,E as Ie,m as Oe,n as Ee}from"./viewport-DISF-Zyg.js";const G=3,_e=1e-4,Pe=1;function ke(t){return{min:Number.isFinite(t)&&t>0?Math.min(t,G):Pe,max:G}}function Te(t,i,m){if(!Number.isFinite(t)||t<=0)return null;const r=t*(1+i),c=Math.min(Math.max(r,m.min),m.max);return!Number.isFinite(c)||Math.abs(c-t)<_e?null:{zoom:c,delta:c/t-1}}const L=240,$=48,k=74,He=280,B=24,Ge=.85,X=1/Ge-1,q=.05,Le=150,Fe="#f59e0b";function ze({data:t}){function i(d){d.stopPropagation(),d.preventDefault(),t.onOpenExternal()}if(t.isSource)return s.jsxs("div",{className:"text-primary flex items-center",style:{width:L,height:$,borderRadius:8,border:`2px solid ${t.highlighted?I:t.isDraft?P:J}`,boxShadow:t.highlighted?`0 0 0 3px ${I}40, 0 0 12px ${I}60`:"0 1px 4px 0 rgba(0,0,0,0.12)",background:"#eff6ff",fontSize:13,fontWeight:600,position:"relative",opacity:t.dimmed?Z:1,filter:t.dimmed?"grayscale(0.8)":void 0,animation:t.highlighted?"node-pulse 1.5s ease-in-out infinite":void 0,transition:"opacity 0.2s, filter 0.2s"},children:[t.isDraft&&s.jsx("span",{style:{position:"absolute",top:-18,right:4,fontSize:10,fontWeight:600,color:P,lineHeight:1},children:"Draft"}),s.jsx("div",{className:"truncate",style:{flex:1,padding:"0 14px"},title:t.label,children:t.label}),t.hasOutgoing&&s.jsx(z,{type:"source",position:W.Right,isConnectable:!1,style:K})]});const m=ee(t)?P:J,r=te(t),c=`Open ${t.label} in new tab`;return s.jsxs("div",{title:t.isCycleStub?se:void 0,style:{width:L,height:k,borderRadius:8,border:`2px solid ${t.highlighted?I:m}`,background:"var(--background)",boxShadow:t.highlighted?`0 0 0 3px ${I}40, 0 0 12px ${I}60`:"0 1px 4px 0 rgba(0,0,0,0.12)",cursor:"default",position:"relative",opacity:t.dimmed?Z:1,filter:t.dimmed?"grayscale(0.8)":void 0,animation:t.highlighted?"node-pulse 1.5s ease-in-out infinite":void 0,transition:"opacity 0.2s, filter 0.2s"},children:[(r==null?void 0:r.kind)==="warning"&&s.jsx("span",{style:{position:"absolute",top:-18,right:4,fontSize:10,fontWeight:600,color:P,lineHeight:1,whiteSpace:"nowrap"},children:r.label}),(r==null?void 0:r.kind)==="attention"&&s.jsxs("span",{title:ie,style:{position:"absolute",top:-18,right:4,display:"inline-flex",alignItems:"center",gap:2,fontSize:10,fontWeight:600,color:Fe,lineHeight:1,whiteSpace:"nowrap"},children:[s.jsx(ae,{style:{width:12,height:12}}),r.label]}),s.jsx(z,{type:"target",position:W.Left,isConnectable:!1,style:K}),s.jsxs("div",{className:"bg-muted flex items-center justify-between",style:{padding:"8px 10px 8px 14px",fontSize:13,fontWeight:600,borderRadius:"6px 6px 0 0"},children:[s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"truncate",title:t.label,children:t.label}),!t.userHasAccess&&s.jsx(ne,{})]}),s.jsxs("div",{className:"ml-2 flex shrink-0 items-center gap-0.5",children:[t.description&&s.jsxs(oe,{children:[s.jsx(re,{asChild:!0,children:s.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground inline-flex cursor-default rounded p-0.5 transition-colors","aria-label":`Description for ${t.label}`,onPointerDown:d=>{d.stopPropagation()},children:s.jsx(le,{style:{width:14,height:14},"aria-hidden":"true"})})}),s.jsx(ce,{side:"top",align:"center",role:"tooltip",children:t.description})]}),s.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground shrink-0 cursor-pointer rounded p-0.5 transition-colors",onPointerDown:d=>{d.stopPropagation()},onClick:i,title:c,"aria-label":c,children:s.jsx(de,{style:{width:14,height:14},"aria-hidden":"true"})})]})]}),s.jsxs("div",{className:"text-muted-foreground flex items-center gap-2",style:{padding:"6px 14px 8px",fontSize:11,minWidth:0},children:[t.targetAlias&&s.jsx(he,{variant:"secondary",className:"inline-block max-w-[120px] truncate px-1.5 py-0 text-[10px]",title:t.targetAlias,children:t.targetAlias}),s.jsxs("span",{className:"ml-auto shrink-0",children:[t.fieldCount??0," field",t.fieldCount!==1?"s":""]})]}),t.hasOutgoing&&s.jsx(z,{type:"source",position:W.Right,isConnectable:!1,style:K})]})}function Ke({sourceX:t,sourceY:i,targetX:m,targetY:r,sourcePosition:c,targetPosition:d,data:h}){const[C]=ve({sourceX:t,sourceY:i,sourcePosition:c,targetX:m,targetY:r,targetPosition:d}),x=h.warning?P:Ie;return s.jsx("path",{d:C,fill:"none",strokeWidth:Ee,stroke:x,strokeDasharray:h.warning?Oe:void 0,opacity:h.dimmed?Z:1,style:{transition:"opacity 0.2s"}})}const We={relationshipNode:ze},Be={relationshipEdge:Ke};function Ze(t){return JSON.stringify([t.nodes.map(i=>[i.id,i.position.x,i.position.y,i.width,i.height,i.data.isSource,i.data.label,i.data.targetAlias,i.data.fieldCount,i.data.description,i.data.isDraft,i.data.isBlocked,i.data.isJoinNotConfigured,i.data.isCycleStub,i.data.isMissingPrimaryKey,i.data.userHasAccess,i.data.hasOutgoing]),t.edges.map(i=>[i.id,i.source,i.target,i.data.warning])])}function $e(t,i,m,r,c,d,h,C){const x=new Map,A=[],g=new Set,y=r==="DRAFT";x.set(t,{dmId:t,title:i,description:m,depth:0,isSource:!0,isDraft:y,userHasAccess:!0});let N=0;const j=new Map;j.set("",t);function M(e,a,f,p){const w=`${a}-${N++}`;A.push({sourceId:e,targetId:w}),g.add(e),x.set(w,{dmId:a,...f}),j.set(p,w)}if(d)for(const e of d.nodes){const a=e.aliasPath.lastIndexOf("."),f=a===-1?"":e.aliasPath.slice(0,a),p=j.get(f);p&&M(p,e.relationship.targetDataMart.id,{title:e.relationship.targetDataMart.title,description:e.relationship.targetDataMart.description,depth:e.depth,isSource:!1,targetAlias:e.relationship.targetAlias,fieldCount:(h==null?void 0:h.get(e.relationship.id))??0,isDraft:e.relationship.targetDataMart.status==="DRAFT",isBlocked:e.isBlocked,isJoinNotConfigured:e.relationship.joinConditions.length===0,isCycleStub:e.isCycleStub,isMissingPrimaryKey:Y(e.relationship.targetDataMart.hasPrimaryKey,e.relationship.joinConditions.length),userHasAccess:e.relationship.targetDataMart.userHasAccess},e.aliasPath)}else for(const e of c)M(t,e.targetDataMart.id,{title:e.targetDataMart.title,description:e.targetDataMart.description,depth:1,isSource:!1,targetAlias:e.targetAlias,fieldCount:(h==null?void 0:h.get(e.id))??0,isDraft:e.targetDataMart.status==="DRAFT",isBlocked:y,isJoinNotConfigured:e.joinConditions.length===0,isCycleStub:e.targetDataMart.id===t,isMissingPrimaryKey:Y(e.targetDataMart.hasPrimaryKey,e.joinConditions.length),userHasAccess:e.targetDataMart.userHasAccess},e.targetAlias);const b=new Map,R=new Map;for(const[e,a]of x){R.set(e,a.isSource?$:k);const f=b.get(a.depth)??[];b.has(a.depth)||b.set(a.depth,f),f.push(e)}const u=new Map,S=Math.max(...Array.from(b.keys()));for(let e=0;e<=S;e++){const a=b.get(e)??[];let f=0;for(const p of a)u.set(p,{x:e*(L+He),y:f}),f+=(R.get(p)??k)+B;if(e===0&&a.length===1){const p=a[0],_=(b.get(1)??[]).reduce((T,F)=>T+(R.get(F)??k)+B,-B),D=R.get(p)??$;u.set(p,{x:0,y:Math.max(0,_/2-D/2)})}}const O=[];for(const[e,a]of x)O.push({id:e,type:"relationshipNode",position:u.get(e)??{x:0,y:0},width:L,height:R.get(e)??k,draggable:!1,selectable:!1,focusable:!1,style:Se,data:{isSource:a.isSource,label:a.title,targetAlias:a.targetAlias,fieldCount:a.fieldCount,description:a.description,isDraft:a.isDraft??!1,isBlocked:a.isBlocked??!1,isJoinNotConfigured:a.isJoinNotConfigured??!1,isCycleStub:a.isCycleStub??!1,isMissingPrimaryKey:a.isMissingPrimaryKey??!1,userHasAccess:a.userHasAccess,hasOutgoing:g.has(e)&&!a.isCycleStub,highlighted:!1,dimmed:!1,onOpenExternal:()=>{C(a.dmId)}}});const E=[];for(const e of A){const a=x.get(e.sourceId),f=x.get(e.targetId);if(!a||!f)continue;const p=ue(a,f);E.push({id:`${e.sourceId}->${e.targetId}`,type:"relationshipEdge",source:e.sourceId,target:e.targetId,focusable:!1,selectable:!1,data:{warning:p,dimmed:!1}})}return{nodes:O,edges:E}}function Ve({dataMartId:t,dataMartTitle:i,dataMartDescription:m,dataMartStatus:r,relationships:c,relationshipGraph:d,connectedFieldCounts:h,searchQuery:C,onRequestFullscreen:x,onOpenExternal:A}){const g=me(),y=U(n=>n.width),N=U(n=>n.height),j=o.useRef(!1),M=o.useRef(!1),[b,R]=o.useState({min:q,max:G}),u=o.useMemo(()=>$e(t,i,m,r,c,d,h,A),[t,i,m,r,c,d,h,A]),S=o.useMemo(()=>Ze(u),[u]),O=o.useMemo(()=>xe(u.nodes),[u.nodes]),E=o.useRef(S);o.useEffect(()=>{E.current!==S&&(E.current=S,M.current=!1)},[S]);const e=o.useMemo(()=>ye(u.nodes,C,n=>n.id,n=>n.data.label),[u.nodes,C]),a=o.useMemo(()=>u.nodes.map(n=>{const l=e.get(n.id)??be;return n.data.highlighted===l.highlighted&&n.data.dimmed===l.dimmed?n:{...n,data:{...n.data,...l}}}),[u.nodes,e]),f=o.useMemo(()=>u.edges.map(n=>{var v,V;const l=(((v=e.get(n.source))==null?void 0:v.dimmed)??!1)&&(((V=e.get(n.target))==null?void 0:V.dimmed)??!1);return n.data.dimmed===l?n:{...n,data:{...n.data,dimmed:l}}}),[u.edges,e]),p=o.useRef(e);p.current=e;const w=o.useCallback(()=>{const n=[...p.current.entries()].filter(([,l])=>l.highlighted).map(([l])=>l);n.length!==0&&g.fitView({nodes:n.map(l=>({id:l})),duration:300,padding:X})},[g]),_=o.useCallback(()=>g.fitView({minZoom:q,maxZoom:G,padding:X}).then(()=>{R(ke(g.getZoom()))}),[g]),D=o.useCallback(()=>{M.current=!0},[]);o.useEffect(()=>{y===0||N===0||M.current||_().then(()=>{j.current=!0,w()})},[y,N,u,_,w]),o.useEffect(()=>{j.current&&w()},[e,w]);const T=o.useCallback(n=>{D();const l=Te(g.getZoom(),n,b);l&&g.zoomTo(l.zoom,{duration:150})},[D,g,b]),F=o.useCallback((n,l)=>{if(y===0||N===0)return;const v=Ne(l,O,y,N,Le);v.x===l.x&&v.y===l.y||g.setViewport(v)},[O,N,y,g]);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"absolute top-3 right-3 z-10 flex items-start gap-2",children:s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(H,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{D(),_()},"aria-label":"Fit to view",children:s.jsx(we,{className:"h-6 w-6"})}),s.jsx(H,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{T(.25)},"aria-label":"Zoom in",children:s.jsx(Ce,{className:"h-6 w-6"})}),s.jsx(H,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{T(-.25)},"aria-label":"Zoom out",children:s.jsx(je,{className:"h-6 w-6"})}),x&&s.jsx(H,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:x,"aria-label":"Expand diagram",children:s.jsx(ge,{className:"h-6 w-6"})})]})}),s.jsx("div",{className:"h-full w-full",onPointerDownCapture:D,onWheelCapture:D,children:s.jsxs(De,{nodes:a,edges:f,nodeTypes:We,edgeTypes:Be,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,edgesFocusable:!1,zoomOnDoubleClick:!1,minZoom:b.min,maxZoom:b.max,onMove:F,onMoveStart:n=>{n&&D()},style:{width:"100%",height:"100%"},children:[s.jsx(Ae,{variant:Re.Lines,gap:16,color:"rgba(0,0,0,0.06)"}),s.jsx(Me,{pannable:!0,zoomable:!0,style:{width:140,height:100}})]})})]})}function Ue({dataMartId:t,dataMartTitle:i,dataMartDescription:m,dataMartStatus:r,relationships:c,relationshipGraph:d,connectedFieldCounts:h,searchQuery:C,onRequestFullscreen:x,className:A,style:g}){const{scope:y}=Q(),N=o.useCallback(j=>{window.open(y(`/data-marts/${j}/data-setup`),"_blank","noopener,noreferrer")},[y]);return c.length===0?null:s.jsxs("div",{className:`relative overflow-hidden rounded-lg border ${A??""}`,style:g??{height:480},children:[s.jsx("style",{children:pe}),s.jsx(fe,{children:s.jsx(Ve,{dataMartId:t,dataMartTitle:i,dataMartDescription:m,dataMartStatus:r,relationships:c,relationshipGraph:d,connectedFieldCounts:h,searchQuery:C,onRequestFullscreen:x,onOpenExternal:N})})]})}export{Ue as RelationshipCanvas,ze as RelationshipFlowNode};
1
+ import{u as Q,r as o,j as s,h as ee,g as te,C as se,M as ie,T as ae,N as ne,a as oe,b as re,I as le,c as ce,E as de,B as he,d as H,e as ge,i as Y,f as ue}from"./index-Bn6xf3W7.js";import{N as pe,R as fe,D as Z,H as I,W as P,a as J,b as z,S as K,P as W,u as me,c as U,g as xe,d as ye,e as be,f as Ne,L as we,Z as Ce,h as je,i as De,B as Ae,j as Re,M as Me,k as Se,l as ve,E as Ie,m as Oe,n as Ee}from"./viewport-ztZvIm-X.js";const G=3,_e=1e-4,Pe=1;function ke(t){return{min:Number.isFinite(t)&&t>0?Math.min(t,G):Pe,max:G}}function Te(t,i,m){if(!Number.isFinite(t)||t<=0)return null;const r=t*(1+i),c=Math.min(Math.max(r,m.min),m.max);return!Number.isFinite(c)||Math.abs(c-t)<_e?null:{zoom:c,delta:c/t-1}}const L=240,$=48,k=74,He=280,B=24,Ge=.85,X=1/Ge-1,q=.05,Le=150,Fe="#f59e0b";function ze({data:t}){function i(d){d.stopPropagation(),d.preventDefault(),t.onOpenExternal()}if(t.isSource)return s.jsxs("div",{className:"text-primary flex items-center",style:{width:L,height:$,borderRadius:8,border:`2px solid ${t.highlighted?I:t.isDraft?P:J}`,boxShadow:t.highlighted?`0 0 0 3px ${I}40, 0 0 12px ${I}60`:"0 1px 4px 0 rgba(0,0,0,0.12)",background:"#eff6ff",fontSize:13,fontWeight:600,position:"relative",opacity:t.dimmed?Z:1,filter:t.dimmed?"grayscale(0.8)":void 0,animation:t.highlighted?"node-pulse 1.5s ease-in-out infinite":void 0,transition:"opacity 0.2s, filter 0.2s"},children:[t.isDraft&&s.jsx("span",{style:{position:"absolute",top:-18,right:4,fontSize:10,fontWeight:600,color:P,lineHeight:1},children:"Draft"}),s.jsx("div",{className:"truncate",style:{flex:1,padding:"0 14px"},title:t.label,children:t.label}),t.hasOutgoing&&s.jsx(z,{type:"source",position:W.Right,isConnectable:!1,style:K})]});const m=ee(t)?P:J,r=te(t),c=`Open ${t.label} in new tab`;return s.jsxs("div",{title:t.isCycleStub?se:void 0,style:{width:L,height:k,borderRadius:8,border:`2px solid ${t.highlighted?I:m}`,background:"var(--background)",boxShadow:t.highlighted?`0 0 0 3px ${I}40, 0 0 12px ${I}60`:"0 1px 4px 0 rgba(0,0,0,0.12)",cursor:"default",position:"relative",opacity:t.dimmed?Z:1,filter:t.dimmed?"grayscale(0.8)":void 0,animation:t.highlighted?"node-pulse 1.5s ease-in-out infinite":void 0,transition:"opacity 0.2s, filter 0.2s"},children:[(r==null?void 0:r.kind)==="warning"&&s.jsx("span",{style:{position:"absolute",top:-18,right:4,fontSize:10,fontWeight:600,color:P,lineHeight:1,whiteSpace:"nowrap"},children:r.label}),(r==null?void 0:r.kind)==="attention"&&s.jsxs("span",{title:ie,style:{position:"absolute",top:-18,right:4,display:"inline-flex",alignItems:"center",gap:2,fontSize:10,fontWeight:600,color:Fe,lineHeight:1,whiteSpace:"nowrap"},children:[s.jsx(ae,{style:{width:12,height:12}}),r.label]}),s.jsx(z,{type:"target",position:W.Left,isConnectable:!1,style:K}),s.jsxs("div",{className:"bg-muted flex items-center justify-between",style:{padding:"8px 10px 8px 14px",fontSize:13,fontWeight:600,borderRadius:"6px 6px 0 0"},children:[s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"truncate",title:t.label,children:t.label}),!t.userHasAccess&&s.jsx(ne,{})]}),s.jsxs("div",{className:"ml-2 flex shrink-0 items-center gap-0.5",children:[t.description&&s.jsxs(oe,{children:[s.jsx(re,{asChild:!0,children:s.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground inline-flex cursor-default rounded p-0.5 transition-colors","aria-label":`Description for ${t.label}`,onPointerDown:d=>{d.stopPropagation()},children:s.jsx(le,{style:{width:14,height:14},"aria-hidden":"true"})})}),s.jsx(ce,{side:"top",align:"center",role:"tooltip",children:t.description})]}),s.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground shrink-0 cursor-pointer rounded p-0.5 transition-colors",onPointerDown:d=>{d.stopPropagation()},onClick:i,title:c,"aria-label":c,children:s.jsx(de,{style:{width:14,height:14},"aria-hidden":"true"})})]})]}),s.jsxs("div",{className:"text-muted-foreground flex items-center gap-2",style:{padding:"6px 14px 8px",fontSize:11,minWidth:0},children:[t.targetAlias&&s.jsx(he,{variant:"secondary",className:"inline-block max-w-[120px] truncate px-1.5 py-0 text-[10px]",title:t.targetAlias,children:t.targetAlias}),s.jsxs("span",{className:"ml-auto shrink-0",children:[t.fieldCount??0," field",t.fieldCount!==1?"s":""]})]}),t.hasOutgoing&&s.jsx(z,{type:"source",position:W.Right,isConnectable:!1,style:K})]})}function Ke({sourceX:t,sourceY:i,targetX:m,targetY:r,sourcePosition:c,targetPosition:d,data:h}){const[C]=ve({sourceX:t,sourceY:i,sourcePosition:c,targetX:m,targetY:r,targetPosition:d}),x=h.warning?P:Ie;return s.jsx("path",{d:C,fill:"none",strokeWidth:Ee,stroke:x,strokeDasharray:h.warning?Oe:void 0,opacity:h.dimmed?Z:1,style:{transition:"opacity 0.2s"}})}const We={relationshipNode:ze},Be={relationshipEdge:Ke};function Ze(t){return JSON.stringify([t.nodes.map(i=>[i.id,i.position.x,i.position.y,i.width,i.height,i.data.isSource,i.data.label,i.data.targetAlias,i.data.fieldCount,i.data.description,i.data.isDraft,i.data.isBlocked,i.data.isJoinNotConfigured,i.data.isCycleStub,i.data.isMissingPrimaryKey,i.data.userHasAccess,i.data.hasOutgoing]),t.edges.map(i=>[i.id,i.source,i.target,i.data.warning])])}function $e(t,i,m,r,c,d,h,C){const x=new Map,A=[],g=new Set,y=r==="DRAFT";x.set(t,{dmId:t,title:i,description:m,depth:0,isSource:!0,isDraft:y,userHasAccess:!0});let N=0;const j=new Map;j.set("",t);function M(e,a,f,p){const w=`${a}-${N++}`;A.push({sourceId:e,targetId:w}),g.add(e),x.set(w,{dmId:a,...f}),j.set(p,w)}if(d)for(const e of d.nodes){const a=e.aliasPath.lastIndexOf("."),f=a===-1?"":e.aliasPath.slice(0,a),p=j.get(f);p&&M(p,e.relationship.targetDataMart.id,{title:e.relationship.targetDataMart.title,description:e.relationship.targetDataMart.description,depth:e.depth,isSource:!1,targetAlias:e.relationship.targetAlias,fieldCount:(h==null?void 0:h.get(e.relationship.id))??0,isDraft:e.relationship.targetDataMart.status==="DRAFT",isBlocked:e.isBlocked,isJoinNotConfigured:e.relationship.joinConditions.length===0,isCycleStub:e.isCycleStub,isMissingPrimaryKey:Y(e.relationship.targetDataMart.hasPrimaryKey,e.relationship.joinConditions.length),userHasAccess:e.relationship.targetDataMart.userHasAccess},e.aliasPath)}else for(const e of c)M(t,e.targetDataMart.id,{title:e.targetDataMart.title,description:e.targetDataMart.description,depth:1,isSource:!1,targetAlias:e.targetAlias,fieldCount:(h==null?void 0:h.get(e.id))??0,isDraft:e.targetDataMart.status==="DRAFT",isBlocked:y,isJoinNotConfigured:e.joinConditions.length===0,isCycleStub:e.targetDataMart.id===t,isMissingPrimaryKey:Y(e.targetDataMart.hasPrimaryKey,e.joinConditions.length),userHasAccess:e.targetDataMart.userHasAccess},e.targetAlias);const b=new Map,R=new Map;for(const[e,a]of x){R.set(e,a.isSource?$:k);const f=b.get(a.depth)??[];b.has(a.depth)||b.set(a.depth,f),f.push(e)}const u=new Map,S=Math.max(...Array.from(b.keys()));for(let e=0;e<=S;e++){const a=b.get(e)??[];let f=0;for(const p of a)u.set(p,{x:e*(L+He),y:f}),f+=(R.get(p)??k)+B;if(e===0&&a.length===1){const p=a[0],_=(b.get(1)??[]).reduce((T,F)=>T+(R.get(F)??k)+B,-B),D=R.get(p)??$;u.set(p,{x:0,y:Math.max(0,_/2-D/2)})}}const O=[];for(const[e,a]of x)O.push({id:e,type:"relationshipNode",position:u.get(e)??{x:0,y:0},width:L,height:R.get(e)??k,draggable:!1,selectable:!1,focusable:!1,style:Se,data:{isSource:a.isSource,label:a.title,targetAlias:a.targetAlias,fieldCount:a.fieldCount,description:a.description,isDraft:a.isDraft??!1,isBlocked:a.isBlocked??!1,isJoinNotConfigured:a.isJoinNotConfigured??!1,isCycleStub:a.isCycleStub??!1,isMissingPrimaryKey:a.isMissingPrimaryKey??!1,userHasAccess:a.userHasAccess,hasOutgoing:g.has(e)&&!a.isCycleStub,highlighted:!1,dimmed:!1,onOpenExternal:()=>{C(a.dmId)}}});const E=[];for(const e of A){const a=x.get(e.sourceId),f=x.get(e.targetId);if(!a||!f)continue;const p=ue(a,f);E.push({id:`${e.sourceId}->${e.targetId}`,type:"relationshipEdge",source:e.sourceId,target:e.targetId,focusable:!1,selectable:!1,data:{warning:p,dimmed:!1}})}return{nodes:O,edges:E}}function Ve({dataMartId:t,dataMartTitle:i,dataMartDescription:m,dataMartStatus:r,relationships:c,relationshipGraph:d,connectedFieldCounts:h,searchQuery:C,onRequestFullscreen:x,onOpenExternal:A}){const g=me(),y=U(n=>n.width),N=U(n=>n.height),j=o.useRef(!1),M=o.useRef(!1),[b,R]=o.useState({min:q,max:G}),u=o.useMemo(()=>$e(t,i,m,r,c,d,h,A),[t,i,m,r,c,d,h,A]),S=o.useMemo(()=>Ze(u),[u]),O=o.useMemo(()=>xe(u.nodes),[u.nodes]),E=o.useRef(S);o.useEffect(()=>{E.current!==S&&(E.current=S,M.current=!1)},[S]);const e=o.useMemo(()=>ye(u.nodes,C,n=>n.id,n=>n.data.label),[u.nodes,C]),a=o.useMemo(()=>u.nodes.map(n=>{const l=e.get(n.id)??be;return n.data.highlighted===l.highlighted&&n.data.dimmed===l.dimmed?n:{...n,data:{...n.data,...l}}}),[u.nodes,e]),f=o.useMemo(()=>u.edges.map(n=>{var v,V;const l=(((v=e.get(n.source))==null?void 0:v.dimmed)??!1)&&(((V=e.get(n.target))==null?void 0:V.dimmed)??!1);return n.data.dimmed===l?n:{...n,data:{...n.data,dimmed:l}}}),[u.edges,e]),p=o.useRef(e);p.current=e;const w=o.useCallback(()=>{const n=[...p.current.entries()].filter(([,l])=>l.highlighted).map(([l])=>l);n.length!==0&&g.fitView({nodes:n.map(l=>({id:l})),duration:300,padding:X})},[g]),_=o.useCallback(()=>g.fitView({minZoom:q,maxZoom:G,padding:X}).then(()=>{R(ke(g.getZoom()))}),[g]),D=o.useCallback(()=>{M.current=!0},[]);o.useEffect(()=>{y===0||N===0||M.current||_().then(()=>{j.current=!0,w()})},[y,N,u,_,w]),o.useEffect(()=>{j.current&&w()},[e,w]);const T=o.useCallback(n=>{D();const l=Te(g.getZoom(),n,b);l&&g.zoomTo(l.zoom,{duration:150})},[D,g,b]),F=o.useCallback((n,l)=>{if(y===0||N===0)return;const v=Ne(l,O,y,N,Le);v.x===l.x&&v.y===l.y||g.setViewport(v)},[O,N,y,g]);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"absolute top-3 right-3 z-10 flex items-start gap-2",children:s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(H,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{D(),_()},"aria-label":"Fit to view",children:s.jsx(we,{className:"h-6 w-6"})}),s.jsx(H,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{T(.25)},"aria-label":"Zoom in",children:s.jsx(Ce,{className:"h-6 w-6"})}),s.jsx(H,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:()=>{T(-.25)},"aria-label":"Zoom out",children:s.jsx(je,{className:"h-6 w-6"})}),x&&s.jsx(H,{variant:"outline",size:"icon",className:"h-12 w-12",onClick:x,"aria-label":"Expand diagram",children:s.jsx(ge,{className:"h-6 w-6"})})]})}),s.jsx("div",{className:"h-full w-full",onPointerDownCapture:D,onWheelCapture:D,children:s.jsxs(De,{nodes:a,edges:f,nodeTypes:We,edgeTypes:Be,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,edgesFocusable:!1,zoomOnDoubleClick:!1,minZoom:b.min,maxZoom:b.max,onMove:F,onMoveStart:n=>{n&&D()},style:{width:"100%",height:"100%"},children:[s.jsx(Ae,{variant:Re.Lines,gap:16,color:"rgba(0,0,0,0.06)"}),s.jsx(Me,{pannable:!0,zoomable:!0,style:{width:140,height:100}})]})})]})}function Ue({dataMartId:t,dataMartTitle:i,dataMartDescription:m,dataMartStatus:r,relationships:c,relationshipGraph:d,connectedFieldCounts:h,searchQuery:C,onRequestFullscreen:x,className:A,style:g}){const{scope:y}=Q(),N=o.useCallback(j=>{window.open(y(`/data-marts/${j}/data-setup`),"_blank","noopener,noreferrer")},[y]);return c.length===0?null:s.jsxs("div",{className:`relative overflow-hidden rounded-lg border ${A??""}`,style:g??{height:480},children:[s.jsx("style",{children:pe}),s.jsx(fe,{children:s.jsx(Ve,{dataMartId:t,dataMartTitle:i,dataMartDescription:m,dataMartStatus:r,relationships:c,relationshipGraph:d,connectedFieldCounts:h,searchQuery:C,onRequestFullscreen:x,onOpenExternal:N})})]})}export{Ue as RelationshipCanvas,ze as RelationshipFlowNode};