@memoarchitect/architect 0.6.0 → 0.6.2
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.
- package/README.md +1 -1
- package/dist/assets/{AskPanel-CbZrbBeK.js → AskPanel-Dqc6aaqg.js} +1 -1
- package/dist/assets/{ComplianceWizard-s0BYP9sH.js → ComplianceWizard-Bi9PLmJH.js} +1 -1
- package/dist/assets/{DSMView-C55GKPeE.js → DSMView-DbC_fUKT.js} +1 -1
- package/dist/assets/{Dashboard-DGiiwpMx.js → Dashboard-6Dgma4kY.js} +1 -1
- package/dist/assets/{DhfDashboard-BE5JabB1.js → DhfDashboard-BPXIYJnw.js} +1 -1
- package/dist/assets/{DhfSettingsPanel-BYTUIoK4.js → DhfSettingsPanel-jQ5mh_50.js} +1 -1
- package/dist/assets/{DhfWorkbench-CUzn_SQo.js → DhfWorkbench-CgFdQIts.js} +3 -3
- package/dist/assets/{DiagramCanvas-IINBJE7R.js → DiagramCanvas-CIfN1ybl.js} +1 -1
- package/dist/assets/{DiagramEditor-Ce5_o4RB.js → DiagramEditor-Y4sSx9nO.js} +2 -2
- package/dist/assets/ElementDetailView-B946aM3p.js +2 -0
- package/dist/assets/{ImportView-CdHzpWCe.js → ImportView-HCDzL9Xx.js} +1 -1
- package/dist/assets/{LayerGrid-Bnv8Ww8p.js → LayerGrid-DSxAFwPk.js} +1 -1
- package/dist/assets/{LayerTable-CeO0t2NX.js → LayerTable-C5VBpm6T.js} +1 -1
- package/dist/assets/{MaxGraphCanvas-BH29OQf7.js → MaxGraphCanvas-B7tAFvDf.js} +1 -1
- package/dist/assets/{ModelDiff-DoGTGDhy.js → ModelDiff-MM5NKKXK.js} +1 -1
- package/dist/assets/OntologyDecompositionDiagram-CAzu3z_q.js +1 -0
- package/dist/assets/{OntologyViewer-BGl9FWMx.js → OntologyViewer-C5ik2Kmi.js} +2 -2
- package/dist/assets/{ReviewDashboard-Du0bEgrG.js → ReviewDashboard-DwlsAVBa.js} +1 -1
- package/dist/assets/{ScenarioEditor-BjLWOYwL.js → ScenarioEditor-BRWvcD2f.js} +1 -1
- package/dist/assets/{StatisticsDashboard-BdrXtbp4.js → StatisticsDashboard-C67W4pb0.js} +1 -1
- package/dist/assets/{SysmlGenerator-CxtxOJ9I.js → SysmlGenerator-BwRhtec-.js} +1 -1
- package/dist/assets/{TabularView-BJQSVDMO.js → TabularView-CTQgMG25.js} +1 -1
- package/dist/assets/{TraceabilityMatrix-BhDLjHki.js → TraceabilityMatrix-Bw5ej-So.js} +1 -1
- package/dist/assets/{WorkflowWizard-BWKNcz03.js → WorkflowWizard-BwGWzMkE.js} +1 -1
- package/dist/assets/index-D0i9ua6F.js +3277 -0
- package/dist/assets/layout-selection-BTId1JyG.js +1 -0
- package/dist/index.html +1 -1
- package/lib/bin/memo-architect.js +1 -1
- package/package.json +4 -3
- package/dist/assets/ElementDetailView-CZ8SUxsc.js +0 -2
- package/dist/assets/OntologyDecompositionDiagram-CerdFGpm.js +0 -1
- package/dist/assets/index-CRFOCEAK.js +0 -3277
- package/dist/assets/layout-selection-CtqXOAtf.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{f as Be,E as ne,R as He,t as kt,v as rn,F as ge,V as an,u as nt,w as bn}from"./index-CRFOCEAK.js";import{r as Sn,D as Mn}from"./layout-providers-BFnfta4Z.js";import{j as O}from"./reactflow-CX-HDacK.js";import{a as me}from"./zustand-qbFpP9Up.js";const Ve=new Set(["composedOf","composes","decomposedBy","aggregation"]);function rt(t,e){const n=new Map;for(const h of t)n.set(h.id,h);const o=new Map,s=new Set;for(const h of e)Ve.has(h.type)&&(!n.has(h.sourceId)||!n.has(h.targetId)||h.sourceId!==h.targetId&&(s.has(h.targetId)||(o.has(h.sourceId)||o.set(h.sourceId,[]),o.get(h.sourceId).push(h.targetId),s.add(h.targetId))));return{roots:[...n.keys()].filter(h=>!s.has(h)),childrenMap:o,elements:n}}function Vs(t){if(t.elements.size===0)return null;const e=new Set,n=s=>{if(!e.has(s)){e.add(s);for(const i of t.childrenMap.get(s)??[])n(i)}};t.roots[0]&&n(t.roots[0]);const o=[...t.elements.keys()].filter(s=>!e.has(s));return t.roots.length===1&&o.length===0?null:{rootIds:t.roots,disconnectedIds:o}}const En=new Set(["name","title","description","shortDescription","longDescription","sourceReference","rationaleText","semantics","protocolSemantics","queryDescription","dataSourceDescription","documentUsage","doc"]);function vn(t,e=4){const n=[];t.shortId&&n.push({key:"id",value:t.shortId});for(const[o,s]of Object.entries(t.attributes)){if(n.length>=e)break;if(En.has(o)||o.includes(".")||o==="id"&&n.some(h=>h.key==="id"))continue;const i=s.split("::").pop().trim();!i||i.length>28||n.push({key:o,value:i})}return n.slice(0,e)}const Ge={layout:(t,e)=>Sn(t,e)},kn=(t,e,n,o=10)=>{const s=n.x-o,i=n.x+n.width+o,h=n.y-o,u=n.y+n.height+o;return t.y===e.y?t.y>=h&&t.y<=u&&Math.max(t.x,e.x)>=s&&Math.min(t.x,e.x)<=i:t.x===e.x?t.x>=s&&t.x<=i&&Math.max(t.y,e.y)>=h&&Math.min(t.y,e.y)<=u:!1},cn=(t,e,n,o)=>t.y===e.y&&n.y===o.y&&t.y===n.y?Math.max(Math.min(t.x,e.x),Math.min(n.x,o.x))<Math.min(Math.max(t.x,e.x),Math.max(n.x,o.x)):t.x===e.x&&n.x===o.x&&t.x===n.x?Math.max(Math.min(t.y,e.y),Math.min(n.y,o.y))<Math.min(Math.max(t.y,e.y),Math.max(n.y,o.y)):!1,ln=(t,e,n,o)=>{const s=t.y===e.y,i=n.y===o.y;if(s===i)return!1;const h=s?t:n,u=s?e:o,a=s?n:t,y=s?o:e;return a.x>Math.min(h.x,u.x)&&a.x<Math.max(h.x,u.x)&&h.y>Math.min(a.y,y.y)&&h.y<Math.max(a.y,y.y)},Cn=26,Ct=(t,e,n)=>e==="left"?{x:t.x-n,y:t.y}:e==="right"?{x:t.x+n,y:t.y}:e==="top"?{x:t.x,y:t.y-n}:{x:t.x,y:t.y+n};function qe(t,e,n=18){const o=new Map,s=[],i=Math.max(12,n*.75),h=[...t].sort((u,a)=>Math.abs(a.source.x-a.target.x)+Math.abs(a.source.y-a.target.y)-(Math.abs(u.source.x-u.target.x)+Math.abs(u.source.y-u.target.y)));for(const u of h){const{source:a,target:y}=u,p=Math.abs(a.x-y.x)+Math.abs(a.y-y.y),d=Math.min(Cn,p/3),x=!!u.sourceSide&&d>.5,f=!!u.targetSide&&d>.5,g=x?Ct(a,u.sourceSide,d):a,l=f?Ct(y,u.targetSide,d):y,c=(r,w)=>w.x>r.x-i&&w.x<r.x+r.width+i&&w.y>r.y-i&&w.y<r.y+r.height+i,M=e.filter(r=>r.id!==u.sourceNodeId&&r.id!==u.targetNodeId&&!c(r,a)&&!c(r,y)),b=new Set([g.x,l.x,(g.x+l.x)/2,g.x-n,g.x+n,l.x-n,l.x+n]),E=new Set([g.y,l.y,(g.y+l.y)/2,g.y-n,g.y+n,l.y-n,l.y+n]);for(const r of M)b.add(r.x-i),b.add(r.x+r.width+i),E.add(r.y-i),E.add(r.y+r.height+i);for(const[r,w]of s)b.add(r.x),b.add(w.x),E.add(r.y),E.add(w.y);const S=[...b].sort((r,w)=>r-w),N=[...E].sort((r,w)=>r-w),T=[],G=new Map,W=(r,w)=>`${r.toFixed(3)}:${w.toFixed(3)}`,H=r=>M.some(w=>r.x>w.x-i&&r.x<w.x+w.width+i&&r.y>w.y-i&&r.y<w.y+w.height+i);for(const r of N)for(const w of S){const k={x:w,y:r};H(k)&&W(w,r)!==W(g.x,g.y)&&W(w,r)!==W(l.x,l.y)||(G.set(W(w,r),T.length),T.push(k))}const U=new Map,re=(r,w)=>{U.has(r)||U.set(r,[]),U.has(w)||U.set(w,[]),U.get(r).push(w),U.get(w).push(r)},Ie=(r,w)=>!M.some(k=>kn(r,w,k,i-1));for(const r of N){const w=S.map(k=>G.get(W(k,r))).filter(k=>k!==void 0);for(let k=1;k<w.length;k++)Ie(T[w[k-1]],T[w[k]])&&re(w[k-1],w[k])}for(const r of S){const w=N.map(k=>G.get(W(r,k))).filter(k=>k!==void 0);for(let k=1;k<w.length;k++)Ie(T[w[k-1]],T[w[k]])&&re(w[k-1],w[k])}const fe=G.get(W(g.x,g.y)),$=G.get(W(l.x,l.y)),Ee=(r,w)=>`${r}:${w}`,be=fe===void 0?[]:[{node:fe,dir:"N",g:0,f:Math.abs(g.x-l.x)+Math.abs(g.y-l.y)}],le=new Map(fe===void 0?[]:[[Ee(fe,"N"),0]]),ve=new Map;be[0]&&ve.set(Ee(be[0].node,be[0].dir),be[0]);let xe;const pe=(r,w,k)=>!k||k==="left"&&w.x<r.x||k==="right"&&w.x>r.x||k==="top"&&w.y<r.y||k==="bottom"&&w.y>r.y,Me=(r,w,k)=>!k||(k==="left"?w.x<=r.x:k==="right"?w.x>=r.x:k==="top"?w.y<=r.y:w.y>=r.y),v=x?Me:pe,R=f?Me:pe;for(;be.length>0;){be.sort((w,k)=>w.f-k.f);const r=be.shift();if(r.node===$){xe=r;break}for(const w of U.get(r.node)??[]){const k=T[r.node],L=T[w];if(r.node===fe&&!v(k,L,u.sourceSide)||w===$&&!R(L,k,u.targetSide))continue;const D=k.y===L.y?"H":"V",Q=Math.abs(k.x-L.x)+Math.abs(k.y-L.y);let B=r.dir!=="N"&&r.dir!==D?90:0;for(const[X,z]of s)cn(k,L,X,z)?B+=4e3:ln(k,L,X,z)&&(B+=600);const Z=Math.abs(k.x-l.x)+Math.abs(k.y-l.y),J=Math.abs(L.x-l.x)+Math.abs(L.y-l.y);J>Z&&(B+=(J-Z)*1.5);const m=r.g+Q+B,A=Ee(w,D);if(m>=(le.get(A)??Number.POSITIVE_INFINITY))continue;const P={node:w,dir:D,g:m,f:m+J,parent:Ee(r.node,r.dir)};le.set(A,m),ve.set(A,P),be.push(P)}}let F=[];if(xe){let r=xe;for(;r;)F.push(T[r.node]),r=r.parent?ve.get(r.parent):void 0;F.reverse()}if(F.length<2){const r=(g.x+l.x)/2;F=[g,{x:r,y:g.y},{x:r,y:l.y},l]}x&&F.unshift(a),f&&F.push(y);const ie=F.filter((r,w)=>w===0||w===F.length-1||!(F[w-1].x===r.x&&r.x===F[w+1].x||F[w-1].y===r.y&&r.y===F[w+1].y));o.set(u.id,ie);for(let r=1;r<ie.length;r++)s.push([ie[r-1],ie[r]])}return o}const At=(t,e)=>{const n=Math.min(t.x+t.width,e.x+e.width)-Math.max(t.x,e.x),o=Math.min(t.y+t.height,e.y+e.height)-Math.max(t.y,e.y);return n>0&&o>0?n*o:0},An=(t,e,n)=>{if(t.y===e.y){if(t.y<n.y||t.y>n.y+n.height)return 0;const o=Math.min(Math.max(t.x,e.x),n.x+n.width)-Math.max(Math.min(t.x,e.x),n.x);return Math.max(o,0)}if(t.x===e.x){if(t.x<n.x||t.x>n.x+n.width)return 0;const o=Math.min(Math.max(t.y,e.y),n.y+n.height)-Math.max(Math.min(t.y,e.y),n.y);return Math.max(o,0)}return 0};function it(t,e){var u;const n=new Map,o=[],s=a=>a.slice(1).reduce((y,p,d)=>y+Math.abs(p.x-a[d].x)+Math.abs(p.y-a[d].y),0),i=t.flatMap(a=>a.points.slice(1).map((y,p)=>({edgeId:a.id,a:a.points[p],b:y}))),h=[...t].sort((a,y)=>s(y.points)-s(a.points));for(const a of h){const{points:y,width:p,height:d}=a;if(y.length<2)continue;const x=[];for(let l=1;l<y.length;l++){const c=y[l-1],M=y[l],b=Math.abs(M.x-c.x)+Math.abs(M.y-c.y),E=Math.abs(M.x-c.x)>=Math.abs(M.y-c.y),S=d/2+4;for(const N of b>=p*1.5?[.5,.3,.7]:[.5,.25,.75]){const T={x:c.x+(M.x-c.x)*N,y:c.y+(M.y-c.y)*N};for(const G of[-1,1])x.push({center:E?{x:T.x,y:T.y+G*S}:{x:T.x+G*(p/2+4),y:T.y},segmentLength:b})}}let f=((u=x[0])==null?void 0:u.center)??y[0],g=Number.POSITIVE_INFINITY;for(const l of x){const c={x:l.center.x-p/2,y:l.center.y-d/2,width:p,height:d};let M=0;for(const b of o)M+=At(c,b)*3;for(const b of e)M+=At(c,b)*4;for(const b of i)b.edgeId!==a.id&&(M+=An(b.a,b.b,c)*12*2.5);M+=Math.max(0,p*1.4-l.segmentLength)*2,M<g&&(g=M,f=l.center)}n.set(a.id,f),o.push({x:f.x-p/2,y:f.y-d/2,width:p,height:d})}return n}const at=20,ct=t=>t.length*6.4+12;function On(t){const{connectors:e,rects:n}=t,o=t.obstacles??[...n.entries()].map(([f,g])=>({id:f,...g})),s=[],i=new Map;for(const f of e){const g=n.get(f.sourceId),l=n.get(f.targetId);if(!g||!l||f.sourceId===f.targetId)continue;const c=N=>({x:N.x+N.width/2,y:N.y+N.height/2}),M=Math.abs(c(l).x-c(g).x)>=Math.abs(c(l).y-c(g).y),b=M?c(l).x>=c(g).x:c(l).y>=c(g).y,E=M?b?"right":"left":b?"bottom":"top",S=M?b?"left":"right":b?"top":"bottom";i.set(f.id,{source:E,target:S}),s.push({connectorId:f.id,nodeId:f.sourceId,side:E,otherCentre:c(l)}),s.push({connectorId:f.id,nodeId:f.targetId,side:S,otherCentre:c(g)})}const h=new Map,u=(f,g)=>`${f}\0${g}`,a=new Map;for(const f of s){const g=`${f.nodeId}\0${f.side}`;a.set(g,[...a.get(g)??[],f])}for(const f of a.values()){const g=n.get(f[0].nodeId),l=f[0].side==="left"||f[0].side==="right",c=[...f].sort((E,S)=>l?E.otherCentre.y-S.otherCentre.y:E.otherCentre.x-S.otherCentre.x),M=(l?g.height:g.width)*.7,b=(l?g.y+g.height/2:g.x+g.width/2)-M/2;c.forEach((E,S)=>{const N=c.length===1?(l?g.height:g.width)/2:b+M*(S/(c.length-1))-(l?g.y:g.x);h.set(u(E.connectorId,E.nodeId),{x:E.side==="left"?g.x:E.side==="right"?g.x+g.width:g.x+(l?g.width/2:N),y:E.side==="top"?g.y:E.side==="bottom"?g.y+g.height:g.y+(l?N:g.height/2)})})}const y=[];for(const f of e){const g=i.get(f.id);g&&y.push({id:f.id,source:h.get(u(f.id,f.sourceId)),target:h.get(u(f.id,f.targetId)),sourceNodeId:f.sourceId,targetNodeId:f.targetId,sourceSide:g.source,targetSide:g.target})}const p=qe(y,o,t.channelGap),d=it(e.flatMap(f=>{const g=p.get(f.id);return f.label&&g&&g.length>=2?[{id:f.id,points:g,width:ct(f.label),height:at}]:[]}),o),x=new Map;for(const[f,g]of p)x.set(f,{points:g,labelPoint:d.get(f)});return x}function Nn(t,e,n=1.5){if(t<=0||e<=0)return Number.POSITIVE_INFINITY;const o=1+1.35*Math.abs(Math.log(t/e/n));return t*e*o}function Tn(t,e=1.25){return t<=1?Math.max(t,1):Math.min(t,Math.max(2,Math.round(Math.sqrt(t*e))))}function dn(t,e){const n=new Set(t.map(y=>y.id)),o=new Map,s=new Map(t.map(y=>[y.id,0]));for(const y of e)!n.has(y.source)||!n.has(y.target)||y.source===y.target||(o.has(y.source)||o.set(y.source,[]),o.get(y.source).push(y.target),s.set(y.target,(s.get(y.target)??0)+1));const i=t.map(y=>y.id),h=i.filter(y=>(s.get(y)??0)===0),u=[],a=new Set;for(;h.length;){const y=h.shift();if(!a.has(y)){a.add(y),u.push(y);for(const p of o.get(y)??[])s.set(p,(s.get(p)??1)-1),s.get(p)===0&&h.push(p)}}for(const y of i)a.has(y)||u.push(y);return u}function _n(t,e,n,o,s){const i=new Map(t.map(l=>[l.id,l])),h=dn(t,e).map(l=>i.get(l)),u=Tn(t.length,s),a=Math.ceil(t.length/u),y=h.map((l,c)=>{const M=Math.floor(c/u),b=c%u,E=M%2===0?b:u-1-b;return{node:l,row:M,col:E}}),p=Array.from({length:u},()=>0),d=Array.from({length:a},()=>0);for(const{node:l,row:c,col:M}of y)p[M]=Math.max(p[M],l.width),d[c]=Math.max(d[c],l.height);const x=p.map((l,c)=>c===0?0:p.slice(0,c).reduce((M,b)=>M+b,0)+n*c),f=d.map((l,c)=>c===0?0:d.slice(0,c).reduce((M,b)=>M+b,0)+o*c),g=y.map(({node:l,row:c,col:M})=>({...l,x:x[M]+(p[M]-l.width)/2,y:f[c]+(d[c]-l.height)/2}));return{strategy:"balanced-board",width:p.reduce((l,c)=>l+c,0)+n*Math.max(u-1,0),height:d.reduce((l,c)=>l+c,0)+o*Math.max(a-1,0),children:g}}function Pn(t,e,n,o){const s={x:t.x+t.width/2,y:t.y+t.height/2},i={x:e.x+e.width/2,y:e.y+e.height/2},h={x:n.x+n.width/2,y:n.y+n.height/2},u={x:o.x+o.width/2,y:o.y+o.height/2},a=(y,p,d)=>(p.x-y.x)*(d.y-y.y)-(p.y-y.y)*(d.x-y.x);return a(s,i,h)*a(s,i,u)<0&&a(h,u,s)*a(h,u,i)<0}function Ot(t,e,n=1.5){const o=new Map(t.children.map(g=>[g.id,g]));let s=0,i=0,h=0,u=0;const a=e.filter(g=>o.has(g.source)&&o.has(g.target));for(const g of a){const l=o.get(g.source),c=o.get(g.target);s+=Math.abs(l.x+l.width/2-(c.x+c.width/2))+Math.abs(l.y+l.height/2-(c.y+c.height/2));const M=c.x+c.width/2-(l.x+l.width/2),b=Math.abs(c.y+c.height/2-(l.y+l.height/2));M<=0&&(h+=55e3),h+=Math.max(0,b-Math.max(M,0))*80,Math.abs(M)>8&&b>8&&(u+=18e3)}for(let g=0;g<a.length;g++)for(let l=g+1;l<a.length;l++){const c=a[g],M=a[l];c.source===M.source||c.source===M.target||c.target===M.source||c.target===M.target||Pn(o.get(c.source),o.get(c.target),o.get(M.source),o.get(M.target))&&i++}const y=qe(a.map(g=>{const l=o.get(g.source),c=o.get(g.target);return{id:g.id,source:{x:l.x+l.width,y:l.y+l.height/2},target:{x:c.x,y:c.y+c.height/2},sourceNodeId:g.source,targetNodeId:g.target,sourceSide:"right",targetSide:"left"}}),t.children);let p=0,d=0,x=0;const f=[];for(const[g,l]of y){d+=Math.max(0,l.length-2);for(let c=1;c<l.length;c++)p+=Math.abs(l[c].x-l[c-1].x)+Math.abs(l[c].y-l[c-1].y),f.push({edgeId:g,a:l[c-1],b:l[c]})}for(let g=0;g<f.length;g++)for(let l=g+1;l<f.length;l++){const c=f[g],M=f[l];c.edgeId!==M.edgeId&&(cn(c.a,c.b,M.a,M.b)||ln(c.a,c.b,M.a,M.b))&&x++}return Nn(t.width,t.height,n)+s*18+h+u+i*Math.max(t.width*t.height*.35,5e4)+p*6+d*4e3+x*Math.max(t.width*t.height*.45,7e4)}async function Nt(t){const{nodes:e,edges:n}=t;if(e.length===0)return{strategy:"balanced-board",width:0,height:0,children:[]};const o=t.targetAspect??1.5,s=t.gapX??54,i=t.gapY??58,h=a=>{const y=new Map(e.map(c=>[c.id,c])),p=dn(e,n).map(c=>y.get(c));let d=0;const x=Math.max(...a==="RIGHT"?p.map(c=>c.height):p.map(c=>c.width));let f=p.map(c=>{const M={...c,x:a==="RIGHT"?d:(x-c.width)/2,y:a==="DOWN"?d:(x-c.height)/2};return d+=a==="RIGHT"?c.width+s:c.height+i,M});if(a==="RIGHT"&&n.some(c=>c.sourceAnchorY!==void 0&&c.targetAnchorY!==void 0)){new Map(f.map(S=>[S.id,S]));const c=new Map,M=[...f].sort((S,N)=>N.width*N.height-S.width*S.height)[0];c.set(M.id,0);let b=!0;for(;b;){b=!1;for(const S of n){if(S.sourceAnchorY===void 0||S.targetAnchorY===void 0)continue;const N=c.get(S.source),T=c.get(S.target);N!==void 0&&T===void 0?(c.set(S.target,N+S.sourceAnchorY-S.targetAnchorY),b=!0):T!==void 0&&N===void 0&&(c.set(S.source,T+S.targetAnchorY-S.sourceAnchorY),b=!0)}}f=f.map(S=>({...S,y:c.get(S.id)??S.y}));const E=Math.min(...f.map(S=>S.y));f=f.map(S=>({...S,y:S.y-E}))}const g=Math.max(...f.map(c=>c.x+c.width)),l=Math.max(...f.map(c=>c.y+c.height));return{strategy:a==="RIGHT"?"layered-right":"layered-down",width:g,height:l,children:f}};if(t.directedFlowAxis==="RIGHT")return h("RIGHT");if(t.directedFlowAxis==="DOWN")return h("DOWN");const u=[_n(e,n,s,i,o),h("RIGHT"),h("DOWN")];if(e.length>=3&&n.length>0)try{const a=new Map(e.filter(l=>{var c;return(c=l.ports)==null?void 0:c.length}).map(l=>[l.id,l])),y={left:"WEST",right:"EAST",top:"NORTH",bottom:"SOUTH"},p=new Set((t.graphPorts??[]).map(l=>l.id)),d=(t.graphPorts??[]).map(l=>({id:l.id,width:1,height:1,layoutOptions:{"elk.layered.layering.layerConstraint":l.side==="right"?"LAST_SEPARATE":"FIRST_SEPARATE"}})),f=(await Ge.layout({id:`resolver-${t.id}`,layoutOptions:{"elk.algorithm":"layered","elk.direction":"RIGHT","elk.edgeRouting":"ORTHOGONAL","elk.aspectRatio":String(o),"elk.padding":"[top=0,left=0,bottom=0,right=0]","elk.spacing.nodeNode":String(i),"elk.layered.spacing.nodeNodeBetweenLayers":String(s),"elk.layered.nodePlacement.strategy":"BRANDES_KOEPF","elk.layered.nodePlacement.favorStraightEdges":"true","elk.layered.crossingMinimization.strategy":"LAYER_SWEEP","elk.layered.crossingMinimization.semiInteractive":"true","elk.layered.thoroughness":"18","elk.layered.wrapping.strategy":e.length>5?"MULTI_EDGE":"OFF","elk.layered.wrapping.additionalEdgeSpacing":"18","elk.separateConnectedComponents":"true","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.randomSeed":"1"},children:[...d,...e.map(l=>{var c;return(c=l.ports)!=null&&c.length?{id:l.id,width:l.width,height:l.height,layoutOptions:{"elk.portConstraints":"FIXED_SIDE"},ports:l.ports.map(M=>({id:M.id,width:8,height:8,layoutOptions:{"elk.port.side":y[M.side]}}))}:{id:l.id,width:l.width,height:l.height}})],edges:n.map(l=>({id:l.id,sources:[a.has(l.source)&&l.sourcePort?l.sourcePort:l.source],targets:[a.has(l.target)&&l.targetPort?l.targetPort:l.target]}))},{providerId:t.layoutProviderId})).children??[],g=f.filter(l=>!p.has(l.id));if(g.length===e.length){const l=new Map(e.map(S=>[S.id,S])),c=Math.min(...g.map(S=>S.x??0)),M=Math.min(...g.map(S=>S.y??0)),b=g.map(S=>{const N=S.ports;return{...l.get(S.id),x:(S.x??0)-c,y:(S.y??0)-M,...N!=null&&N.length?{portY:new Map(N.map(T=>[T.id,T.y??0]))}:{}}}),E=f.filter(S=>p.has(S.id));u.push({strategy:"elk-layered",width:Math.max(...b.map(S=>S.x+S.width)),height:Math.max(...b.map(S=>S.y+S.height)),...E.length?{graphPortY:new Map(E.map(S=>[S.id,(S.y??0)-M]))}:{},children:b})}}catch{}return u.reduce((a,y)=>Ot(y,n,o)<Ot(a,n,o)?y:a)}async function Fn(t,e){var b;const n=Object.values(t.elements),o=e!=null&&e.viewpointFilter?n.filter(e.viewpointFilter):n,s=new Set(o.map(E=>E.id)),i=(b=e==null?void 0:e.relationshipTypes)!=null&&b.length?new Set(e.relationshipTypes.map(E=>E.toLowerCase())):void 0,h=t.relationships.filter(E=>s.has(E.sourceId)&&s.has(E.targetId)&&(!i||i.has(E.type.toLowerCase()))),u=o.length,a=u>60?"RIGHT":"DOWN",y=u>40?"24":u>20?"32":"40",p=u>40?"60":u>20?"80":"100",d=e!=null&&e.compartments?new Map(o.map(E=>[E.id,vn(E)])):void 0,x=E=>Math.max(E.name.length*7.5+48,E.kind.length*6.8+48,130),f=E=>{const S=d==null?void 0:d.get(E.id);return 52+(S!=null&&S.length?S.length*15+10:0)},g={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":a,"elk.spacing.nodeNode":y,"elk.layered.spacing.nodeNodeBetweenLayers":p,"elk.layered.spacing.edgeNodeBetweenLayers":"24","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.layered.nodePlacement.strategy":"NETWORK_SIMPLEX","elk.layered.crossingMinimization.strategy":"LAYER_SWEEP","elk.layered.compaction.postCompaction.strategy":"EDGE_LENGTH","elk.layered.wrapping.strategy":"MULTI_EDGE","elk.layered.wrapping.additionalEdgeSpacing":"16","elk.separateConnectedComponents":"true","elk.spacing.componentComponent":"56","elk.aspectRatio":"1.6","elk.padding":"[top=20, left=20, bottom=20, right=20]"},children:o.map(E=>({id:E.id,width:x(E),height:f(E)})),edges:h.map((E,S)=>({id:E.id||`e-${S}`,sources:[E.sourceId],targets:[E.targetId]}))};let l;try{l=await Ge.layout(g,{providerId:e==null?void 0:e.layoutProviderId})}catch(E){console.warn("ELK layout failed, retrying without edge wrapping:",E),delete g.layoutOptions["elk.layered.wrapping.strategy"],delete g.layoutOptions["elk.layered.wrapping.additionalEdgeSpacing"],l=await Ge.layout(g,{providerId:e==null?void 0:e.layoutProviderId})}const c=(l.children||[]).map(E=>{const S=t.elements[E.id],N=Be[S==null?void 0:S.layer]||"#666",T=d==null?void 0:d.get(E.id);return{id:E.id,type:"diagramNode",position:{x:E.x||0,y:E.y||0},data:{label:(S==null?void 0:S.name)||E.id,kind:(S==null?void 0:S.kind)??"",layer:(S==null?void 0:S.layer)??"",construct:S==null?void 0:S.construct,color:N,...T!=null&&T.length?{compartments:T}:{}}}}),M=h.map((E,S)=>{const N=He[E.type]||"#9CA3AF",T=E.type.toLowerCase(),G=E.type==="flow",W=E.type==="succession",H=T==="composedof"||T==="decomposedby"||T==="aggregation"||T==="composes";return{id:E.id||`e-${S}`,source:E.sourceId,target:E.targetId,label:H?void 0:E.type,type:W?"smoothstep":"default",animated:G,style:{stroke:N,strokeWidth:H?2.5:G?2:ne.defaultWidth,strokeDasharray:H||G?void 0:E.type==="traceTo"?"5 3":void 0},labelStyle:{fontSize:"10px",fill:"#6B7280",fontWeight:500},labelBgPadding:ne.labelBgPadding,labelBgBorderRadius:ne.labelBgRadius,labelBgStyle:ne.labelBgStyle,markerEnd:{type:H?"arrow":"arrowclosed",color:N,width:ne.arrowSize,height:ne.arrowSize}}});return{nodes:c,edges:M}}const hn=new Set;for(const t of rn)if(["logical","physical"].includes(t.id))for(const e of t.kinds)hn.add(e);function gn(t){const e=new Map;for(const i of Object.values(t.elements))hn.has(i.kind)&&e.set(i.id,i);const n=new Map,o=new Set;for(const i of t.relationships)(i.type==="composedOf"||i.type==="aggregation")&&e.has(i.sourceId)&&e.has(i.targetId)&&(n.has(i.sourceId)||n.set(i.sourceId,[]),n.get(i.sourceId).push(i.targetId),o.add(i.targetId));return{roots:[...e.keys()].filter(i=>!o.has(i)),childrenMap:n,elements:e}}const De=64,Je=100,Tt=110,_t=300,Pt=44;function lt(t){return Math.max(t.name.length*8+80,220)}async function Dn(t,e){const n=e.tree??gn(t);if(n.roots.length===0)return{nodes:[],edges:[]};const o=e.positionCache??new Map,s=x=>e.nodeDirections.get(x)||"vertical",i=x=>(n.childrenMap.get(x)||[]).filter(f=>n.elements.has(f)),h=x=>{const f=n.elements.get(x),g=lt(f),l=i(x);if(!e.expandedNodes.has(x)||l.length===0)return{width:g,height:De};const c=l.map(h);if(s(x)==="vertical"){const E=c.reduce((N,T)=>N+T.width,0)+(c.length-1)*Je,S=Math.max(...c.map(N=>N.height));return{width:Math.max(g,E),height:De+Tt+S}}const M=Math.max(...c.map(E=>E.width)),b=c.reduce((E,S)=>E+S.height,0)+(c.length-1)*Pt;return{width:g+_t+M,height:Math.max(De,b)}},u=[],a=[],y=He.composedOf,p=(x,f,g,l)=>{const c=n.elements.get(x),M=lt(c),b=i(x),E=e.expandedNodes.has(x);let S=o.get(x);S||(S={x:g-M/2,y:l-De/2},o.set(x,S));const N={element:c,layerColor:Be[c.layer]||"#666",isExpanded:E,hasChildren:b.length>0,childCount:b.length,direction:s(x),onToggleExpand:()=>e.callbacks.onToggleExpand(x),onToggleDirection:()=>e.callbacks.onToggleDirection(x),showDirectionButton:!0,label:c.name};if(u.push({id:x,type:"decompositionNode",position:{x:S.x,y:S.y},data:N,style:{width:M,height:De}}),f){const G=s(f);a.push({id:`decomp-${f}-${x}`,source:f,target:x,sourceHandle:G==="vertical"?"bottom":"right",targetHandle:G==="vertical"?"top":"left",type:"smoothstep",style:{stroke:y,strokeWidth:ne.defaultWidth},markerEnd:{type:"arrowclosed",color:y,width:ne.arrowSize,height:ne.arrowSize}})}if(!E||b.length===0)return;const T=b.map(h);if(s(x)==="vertical"){const G=T.reduce((U,re)=>U+re.width,0)+(T.length-1)*Je;let W=S.x+M/2-G/2;const H=S.y+De+Tt+De/2;b.forEach((U,re)=>{p(U,x,W+T[re].width/2,H),W+=T[re].width+Je})}else{const G=S.x+M+_t;let W=S.y+De+20;b.forEach((H,U)=>{const re=n.elements.get(H);p(H,x,G+lt(re)/2,W+De/2),W+=T[U].height+Pt})}};let d=0;for(const x of n.roots){if(!n.elements.has(x))continue;const f=h(x);p(x,null,d+f.width/2,100),d+=f.width+Je*2}return{nodes:u,edges:a}}const dt=240,ht=80,We=20;function Rn(t,e){const n=e.tree??gn(t);if(n.roots.length===0)return{nodes:[],edges:[]};const o=[];function s(d,x,f,g,l){const c=n.elements.get(d);if(!c)return{width:0,height:0};const M=Be[c.layer]||"#666",b=n.childrenMap.get(d)||[],E=b.length>0,S=e.expandedNodes.has(d);let N=dt,T=ht;if(S&&E){let H=We,U=ht+We,re=0,Ie=0;for(const fe of b){if(!n.elements.has(fe))continue;const $=s(fe,d,f+1,H,U);H+$.width>800&&H>We&&(H=We,U+=re+We,re=0,i(fe),s(fe,d,f+1,H,U)),H+=$.width+We,re=Math.max(re,$.height),Ie=Math.max(Ie,H)}N=Math.max(dt,Ie),T=U+re+We}const G=kt[f%kt.length],W={element:c,layerColor:M,isExpanded:S,hasChildren:E,childCount:b.length,direction:"vertical",onToggleExpand:()=>e.callbacks.onToggleExpand(d),onToggleDirection:()=>{},showDirectionButton:!1,depthBgColor:G,isContainer:E,label:c.name};return o.push({id:d,type:"decompositionNode",position:{x:g,y:l},...x?{parentId:x,extent:"parent"}:{},data:W,style:{width:S&&E?N:dt,height:S&&E?T:ht}}),{width:N,height:T}}function i(d){const x=new Set([d]),f=g=>{for(const l of n.childrenMap.get(g)||[])x.add(l),f(l)};f(d);for(let g=o.length-1;g>=0;g--)x.has(o[g].id)&&o.splice(g,1)}let h=0;for(const d of n.roots){if(!n.elements.has(d))continue;const x=s(d,null,0,h,0);h+=x.width+40}const u=new Map(o.map(d=>[d.id,d])),a=[],y=new Set,p=d=>{if(y.has(d.id))return;const x=d.parentId?u.get(d.parentId):void 0;x&&p(x),y.add(d.id),a.push(d)};for(const d of o)p(d);return{nodes:a,edges:[]}}const un=new Set;for(const t of rn)if(t.id==="functions")for(const e of t.kinds)un.add(e);function Ln(t){const e=new Map;for(const i of Object.values(t.elements))un.has(i.kind)&&e.set(i.id,i);const n=new Map,o=new Set;for(const i of t.relationships)(i.type==="decomposedBy"||i.type==="composedOf")&&e.has(i.sourceId)&&e.has(i.targetId)&&(n.has(i.sourceId)||n.set(i.sourceId,[]),n.get(i.sourceId).push(i.targetId),o.add(i.targetId));return{roots:[...e.keys()].filter(i=>!o.has(i)),childrenMap:n,elements:e}}async function qs(t,e){const n=Ln(t);if(n.roots.length===0)return{nodes:[],edges:[]};const o=new Set,s=[];function i(p){if(n.elements.has(p)&&(o.add(p),e.expandedNodes.has(p)))for(const d of n.childrenMap.get(p)||[])n.elements.has(d)&&(s.push({parentId:p,childId:d}),i(d))}for(const p of n.roots)i(p);const h={id:"root",layoutOptions:{"elk.algorithm":"mrtree","elk.direction":"DOWN","elk.spacing.nodeNode":"40","elk.mrtree.searchOrder":"DFS"},children:[...o].map(p=>{const d=n.elements.get(p);return{id:p,width:Math.max(d.name.length*8+80,220),height:56}}),edges:s.map((p,d)=>({id:`fbs-${d}`,sources:[p.parentId],targets:[p.childId]}))},a=((await Ge.layout(h,{providerId:e.layoutProviderId})).children||[]).map(p=>{const d=n.elements.get(p.id),x=Be[d.layer]||"#E67E22",f=(n.childrenMap.get(p.id)||[]).length,g=e.nodeDirections.get(p.id)||"vertical",l={element:d,layerColor:x,isExpanded:e.expandedNodes.has(p.id),hasChildren:f>0,childCount:f,direction:g,onToggleExpand:()=>e.callbacks.onToggleExpand(p.id),onToggleDirection:()=>e.callbacks.onToggleDirection(p.id),showDirectionButton:!0,label:d.name};return{id:p.id,type:"decompositionNode",position:{x:p.x||0,y:p.y||0},data:l}}),y=s.map((p,d)=>{const x=e.nodeDirections.get(p.parentId)||"vertical";return{id:`fbs-e-${d}`,source:p.parentId,target:p.childId,sourceHandle:x==="vertical"?"bottom":"right",targetHandle:x==="vertical"?"top":"left",type:"default",style:{stroke:He.decomposedBy,strokeWidth:ne.defaultWidth},markerEnd:{type:"arrowclosed",color:He.decomposedBy,width:ne.arrowSize,height:ne.arrowSize}}});return{nodes:a,edges:y}}const Zs=["graph","tree","containment"];function Js(t){const e=t==null?void 0:t.layoutHint;return e==="tree"||e==="containment"||e==="graph"?e:"graph"}function Bn(t,e){const n=Object.values(t.elements);return e?n.filter(e):n}function jn(t,e){return rt(Bn(t,e),t.relationships)}async function Qs(t,e){if(e.mode==="graph")return Fn(t,{viewpointFilter:e.viewpointFilter,relationshipTypes:e.relationshipTypes,compartments:!0,layoutProviderId:e.layoutProviderId});const n=jn(t,e.viewpointFilter);return e.mode==="tree"?Dn(t,{expandedNodes:e.expandedNodes,nodeDirections:e.nodeDirections,callbacks:e.callbacks,tree:n,positionCache:e.positionCache}):Rn(t,{expandedNodes:e.expandedNodes,callbacks:{onToggleExpand:e.callbacks.onToggleExpand},tree:n})}const Ft="__inner",eo={in:"#16A34A",out:"#D97706",inout:"#2563EB"},Wn={data:"#3498DB",energy:"#D97706",material:"#16A34A",control:"#6B7280"};function Hn(t,e){const n=t??"";return/energy|power|voltage|current|thermal|heat/i.test(n)?"energy":/material|fluid|gas|liquid|drug|dose|batch|consumable/i.test(n)?"material":e&&/succession|control/i.test(e)?"control":"data"}function fn(t){return t.construct==="port"||t.kind.endsWith("Port")}function Dt(t){var o,s;const e=(o=t.portSpec)==null?void 0:o.direction;if(e==="in"||e==="out"||e==="inout")return e;const n=(s=(t.attributes.direction??"").split("::").pop())==null?void 0:s.trim();if(n==="bidirectional")return"inout";if(n==="in"||n==="out"||n==="inout")return n}const Oe=24,to=Oe,gt=Oe,et=30,Re=70,ut=62,Qe=18,Rt=14,Lt=128,ze=38,Ye=18,ft=90,Bt=184,zn=168,Gn=(t,e=7.2)=>t.length*e+20,$n=t=>Math.min(Math.max(Gn(t,7.1),132),216);function yn(t){var o,s;const e=(o=t.portSpec)==null?void 0:o.direction,n=e==="in"||e==="out"||e==="inout"?e:(s=(t.attributes.direction??"").split("::").pop())==null?void 0:s.trim();if(n==="in")return"in";if(n==="out"||n==="inout"||n==="bidirectional"||/out(put)?$/i.test(t.name))return"out";if(/in(put)?$/i.test(t.name))return"in"}function Yn(t,e,n){return yn(t)??(e>n?"out":"in")}const Un=t=>t==="in"?"left":"right";function Xn(t,e){const n=t.filter(s=>!e.isConnected(s)&&!e.hasChildParts(s)&&e.portCount(s)===0),o=new Set(n);return{flowKids:t.filter(s=>!o.has(s)),orphanKids:n}}function Kn(t,e,n){const o=new Map,s=new Map;for(const[u,a]of t)a.owner&&(e(a.owner)?o.set(u,a.owner):t.has(a.owner)&&s.set(u,a.owner));for(const u of n)!Ve.has(u.type)||!t.has(u.targetId)||o.has(u.targetId)||s.has(u.targetId)||(e(u.sourceId)?o.set(u.targetId,u.sourceId):t.has(u.sourceId)&&s.set(u.targetId,u.sourceId));const i=new Map,h=(u,a)=>{const y=i.get(u)??o.get(u);if(y)return i.set(u,y),y;const p=s.get(u);if(!p||a.has(p))return;a.add(p);const d=h(p,a);return d&&i.set(u,d),d};for(const u of t.keys())h(u,new Set([u]));return{ownerPart:i,parentPort:s}}function jt(t,e,n){if(e==="none")return;if(e==="all")return t;let o=t;const s=new Set([o]);for(;n.has(o);){const i=n.get(o);if(s.has(i))break;s.add(i),o=i}return o}function Vn(t,e,n){const o=new Set,s=i=>{if(!(o.has(i)||!e(i))){o.add(i);for(const h of t.get(i)??[])s(h)}};return s(n),o}function qn(t,e){const n=e.size??Oe,o=e.pitch??ze,s=e.nestedPitch??et,i=new Map;for(const h of["left","right"]){const u=t.filter(d=>e.sideOf(d)===h),a=u.length,y=Math.max(e.bodyBottom-e.bodyTop,0);let p=-1/0;u.forEach((d,x)=>{var g;let f=a===1&&e.singleCenterY!==void 0?e.singleCenterY:e.bodyTop+(a===1?y/2:(x+.5)/a*y);f=Math.max(f,e.bodyTop+o/2,p+o),p=f+((((g=e.weightOf)==null?void 0:g.call(e,d))??1)-1)*s,i.set(d,{x:h==="left"?-n/2:e.width-n/2,y:f-n/2,side:h})})}return i}function Wt(t,e){for(const n of["left","right"]){const o=[...t].filter(([i,h])=>h.side===n&&e.has(i)).map(([i])=>i);if(o.length<2)continue;const s=o.map(i=>t.get(i).y).sort((i,h)=>i-h);[...o].sort((i,h)=>e.get(i)-e.get(h)).forEach((i,h)=>{t.get(i).y=s[h]})}}async function no(t,e){var J;const n=Object.values(t.elements),o=e!=null&&e.viewpointFilter?n.filter(e.viewpointFilter):n,s=new Map,i=[];for(const m of o)fn(m)?s.set(m.id,m):i.push(m);if(i.length===0)return{nodes:[],edges:[]};const h=(e==null?void 0:e.portDisplay)??"all",u=h!=="none",a=rt(i,t.relationships),y=e!=null&&e.focusId&&a.elements.has(e.focusId)?e.focusId:void 0,p=y?Vn(a.childrenMap,m=>a.elements.has(m),y):null,d=m=>a.elements.has(m)&&(!p||p.has(m)),x=m=>{var A;return(A=e==null?void 0:e.collapsedNodes)!=null&&A.has(m)?[]:(a.childrenMap.get(m)??[]).filter(d)},{ownerPart:f,parentPort:g}=Kn(s,d,t.relationships);for(const m of[...s.keys()])f.has(m)||s.delete(m);const l=m=>jt(m,"ports",g),c=new Map;for(const[m,A]of f)!s.has(m)||g.has(m)||(c.has(A)||c.set(A,[]),c.get(A).push(m));const M=new Map;if(h==="all")for(const[m]of g){if(!s.has(m))continue;const A=l(m);!s.has(A)||A===m||(M.has(A)||M.set(A,[]),M.get(A).push(m))}const b=m=>{var A;return 1+(((A=M.get(m))==null?void 0:A.length)??0)},E=(J=e==null?void 0:e.relationshipTypes)!=null&&J.length?new Set(e.relationshipTypes.map(m=>m.toLowerCase())):void 0,S=m=>s.has(m)||d(m),N=t.relationships.filter(m=>!Ve.has(m.type)&&(!E||E.has(m.type.toLowerCase()))&&S(m.sourceId)&&S(m.targetId)&&m.sourceId!==m.targetId),T=new Set;for(const m of N)for(const A of[m.sourceId,m.targetId]){if(!s.has(A))continue;let P=A;for(;P&&!T.has(P);)T.add(P),P=g.get(P)}for(const[m,A]of c)c.set(m,A.filter(P=>T.has(P)));const G=new Set(N.filter(m=>d(m.sourceId)).map(m=>m.sourceId)),W=new Set(N.filter(m=>d(m.targetId)).map(m=>m.targetId)),H=m=>f.get(m)??m,U=new Map;for(const[m,A]of a.childrenMap)for(const P of A)d(P)&&U.set(P,m);const re=new Map,Ie=m=>{const A=re.get(m);if(A)return A;const P=s.get(m);let X=yn(P);if(!X){const z=g.get(m);if(z&&s.has(z))X=Ie(z);else{let se=0,Y=0;for(const ee of N)ee.sourceId===m&&se++,ee.targetId===m&&Y++;X=Yn(P,se,Y)}}return re.set(m,X),X},fe=m=>Un(Ie(m)),$=m=>({left:m.some(A=>fe(A)==="left")?Lt:Rt,right:m.some(A=>fe(A)==="right")?Lt:Rt}),Ee=m=>$n(m.name),be=(m,A)=>{const P={left:0,right:0};for(const ae of A)P[fe(ae)]+=ze+(b(ae)-1)*et;const X=Math.max(P.left,P.right,12),z=Math.max(ut+X+10,zn),se=$(A),Y=Math.max(Ee(m),118),ee=Math.max(se.left+Y+se.right,Bt),ye=qn(A,{width:ee,bodyTop:ut,bodyBottom:z-Qe/2,sideOf:fe,weightOf:b,singleCenterY:Math.max(z/2,ut+Oe/2)});return{width:ee,height:z,childPos:new Map,portPos:ye}},le=new Map,ve=new Map,xe=async m=>{const A=x(m),P=u?c.get(m)??[]:[],X=a.elements.get(m);if(A.length===0){const q=be(X,P);return le.set(m,q),q}const z=new Map;for(const q of A)z.set(q,await xe(q));const se=new Set(A),Y=new Set(P),ee=q=>{if(s.has(q)){const j=l(q);if(Y.has(j))return j}let oe=H(q);for(;oe&&!se.has(oe);)oe=U.get(oe);return oe},ye=(q,oe)=>{var te;if(!s.has(q)||f.get(q)!==oe)return;const j=l(q);return(te=c.get(oe))!=null&&te.includes(j)?j:void 0},ae=[],ke=new Set;N.forEach((q,oe)=>{const j=ee(q.sourceId),te=ee(q.targetId);j&&te&&j!==te&&(ae.push({id:`ic-${oe}`,source:j,target:te,sourcePort:ye(q.sourceId,j),targetPort:ye(q.targetId,te)}),se.has(j)&&ke.add(j),se.has(te)&&ke.add(te))});const{flowKids:I,orphanKids:C}=Xn(A,{isConnected:q=>ke.has(q),hasChildParts:q=>(a.childrenMap.get(q)??[]).some(d),portCount:q=>{var oe;return((oe=c.get(q))==null?void 0:oe.length)??0}}),_=$(P),K=new Map;let V=0,de=0;if(I.length>0){const q=j=>(c.get(j)??[]).map(te=>({id:te,side:fe(te)})),oe=await Nt({id:`container-${m}`,nodes:I.map(j=>({id:j,width:z.get(j).width,height:z.get(j).height,ports:q(j)})),edges:ae,graphPorts:P.map(j=>({id:j,side:fe(j)})),gapX:54,gapY:58,targetAspect:2.4,layoutProviderId:e==null?void 0:e.layoutProviderId});for(const j of oe.children){const te=j.x+_.left,ce=j.y+Re;K.set(j.id,{x:te,y:ce}),V=Math.max(V,te-_.left+j.width),de=Math.max(de,ce+j.height),j.portY&&Wt(z.get(j.id).portPos,j.portY)}oe.graphPortY&&ve.set(m,new Map([...oe.graphPortY].map(([j,te])=>[j,te+Re])))}if(I.length>0&&ae.length>0){const q=(Re+Math.max(de,Re))/2,oe=new Map(ve.get(m)??[]),j=(ce,ue)=>{if(Y.has(ce))return oe.get(ce)??q;const Ae=K.get(ce),he=z.get(ce);if(!Ae||!he)return;const we=ue?he.portPos.get(ue):void 0;return we?Ae.y+we.y+Oe/2:Ae.y+he.height/2},te=ce=>ce.reduce((ue,Ae)=>ue+Ae,0)/ce.length;for(let ce=0;ce<2;ce++){const ue=new Map,Ae=(he,we)=>{he===void 0||we===void 0||(ue.has(he)||ue.set(he,[]),ue.get(he).push(we))};for(const he of ae){const we=j(he.source,he.sourcePort),Fe=j(he.target,he.targetPort);Ae(he.sourcePort??(Y.has(he.source)?he.source:void 0),Fe),Ae(he.targetPort??(Y.has(he.target)?he.target:void 0),we)}for(const he of I){const we=z.get(he),Fe=new Map;for(const $e of we.portPos.keys()){const Ze=ue.get($e);Ze!=null&&Ze.length&&Fe.set($e,te(Ze))}Fe.size>1&&Wt(we.portPos,Fe)}for(const he of P){const we=ue.get(he);we!=null&&we.length&&oe.set(he,te(we))}}oe.size>0&&ve.set(m,oe)}if(C.length>0){const q=Math.max(...C.map(we=>z.get(we).width)),oe=Math.max(V,q),j=Math.max(1,Math.min(C.length,Math.floor((oe+Ye)/(q+Ye))||1)),te=de>0?de+Ye:Re;let ce=0,ue=te,Ae=0,he=0;for(const we of C){const Fe=z.get(we),$e=_.left+ce*(q+Ye);K.set(we,{x:$e,y:ue}),V=Math.max(V,$e-_.left+Fe.width),Ae=Math.max(Ae,Fe.height),he=Math.max(he,ue+Fe.height),ce++,ce>=j&&(ce=0,ue+=Ae+Ye,Ae=0)}de=Math.max(de,he)}const Se=Math.min(Ee(X)+32,248);let Ne=Math.max(_.left+V+_.right,Se,Bt),Te=Math.max(de+Qe,Re+Qe+8);const Pe=new Map,je=ve.get(m)??new Map;for(const q of["left","right"]){const oe=P.filter(te=>fe(te)===q).sort((te,ce)=>(je.get(te)??0)-(je.get(ce)??0));let j=-1/0;for(const te of oe){const ce=Math.max(Te/2,Re+Oe/2);let ue=je.get(te)??(oe.length===1?ce:Re+ze/2);ue=Math.max(ue,Re+ze/2,j+ze);const Ae=ue+(b(te)-1)*et;j=Ae,Pe.set(te,{x:q==="left"?-Oe/2:Ne-Oe/2,y:ue-Oe/2,side:q}),Te=Math.max(Te,Ae+ze/2+Qe)}}for(const[q,oe]of Pe)oe.side==="right"&&(oe.x=Ne-Oe/2);const Ce={width:Ne,height:Te,childPos:K,portPos:Pe};return le.set(m,Ce),Ce},pe=y?[y]:a.roots.filter(m=>d(m));for(const m of pe)await xe(m);const Me=new Map;if(pe.length===1)Me.set(pe[0],{x:0,y:0});else{const m=Y=>{let ee=H(Y);const ye=new Set;for(;ee&&U.has(ee)&&!ye.has(ee);)ye.add(ee),ee=U.get(ee);return ee&&pe.includes(ee)?ee:pe.includes(Y)?Y:ee},A=new Set(pe),P=[],X=(Y,ee)=>{var ye;if(s.has(Y)&&f.get(Y)===ee){const ae=l(Y),ke=(ye=le.get(ee))==null?void 0:ye.portPos.get(ae);if(ke)return ke.y+Oe/2}return le.get(ee).height/2};N.forEach((Y,ee)=>{const ye=m(Y.sourceId),ae=m(Y.targetId);ye&&ae&&ye!==ae&&A.has(ye)&&A.has(ae)&&P.push({id:`root-${ee}`,source:ye,target:ae,sourceAnchorY:X(Y.sourceId,ye),targetAnchorY:X(Y.targetId,ae)})});const z=await Nt({id:"interconnection-roots",nodes:pe.map(Y=>({id:Y,width:le.get(Y).width,height:le.get(Y).height})),edges:P,gapX:ft,gapY:ft,directedFlowAxis:"RIGHT",layoutProviderId:e==null?void 0:e.layoutProviderId});for(const Y of z.children)Me.set(Y.id,{x:Y.x,y:Y.y});let se=0;for(const Y of pe)Me.has(Y)||(Me.set(Y,{x:se,y:0}),se+=le.get(Y).width+ft)}const v=new Map;for(const[m,A]of c){const P=le.get(m);if(!P)continue;const X=[];for(const z of A){const se=P.portPos.get(z);if(!se)continue;const Y=s.get(z);X.push({id:z,name:Y.name,x:se.x,y:se.y,side:se.side,direction:Dt(Y)??Ie(z)});const ee=se.y+Oe/2,ye=se.x+(Oe-gt)/2;(M.get(z)??[]).forEach((ae,ke)=>{const I=s.get(ae);X.push({id:ae,name:I.name,x:ye,y:ee+et*(ke+1)-gt/2,side:se.side,direction:Dt(I)??Ie(ae),size:gt,nested:!0})})}v.set(m,X)}const R=[],F=new Map,ie=(m,A,P,X={x:0,y:0})=>{var I;const z=a.elements.get(m),se=le.get(m),Y=Be[z.layer]||"#64748B",ee=P??Me.get(m),ye=A?{x:X.x+ee.x,y:X.y+ee.y}:ee;F.set(m,ye);const ae=(a.childrenMap.get(m)??[]).some(d),ke=ae;R.push({id:m,type:"interconnectionNode",position:ee,...A?{parentId:A,extent:"parent"}:{},data:{label:z.name,kind:z.kind,layer:z.layer,color:Y,isContainer:ke,isFrame:!A&&ke,hasChildren:ae,isCollapsed:((I=e==null?void 0:e.collapsedNodes)==null?void 0:I.has(m))??!1,onToggleCollapse:ae&&(e!=null&&e.onToggleCollapse)?()=>e.onToggleCollapse(m):void 0,ports:v.get(m)??[],implicitIn:u&&W.has(m),implicitOut:u&&G.has(m),onPortMove:e!=null&&e.onPortMove?(C,_)=>e.onPortMove(m,C,_):void 0},style:{width:se.width,height:se.height}});for(const[C,_]of se.childPos)ie(C,m,_,ye)};for(const m of pe)ie(m);const r=(m,A)=>{let P=m;const X=new Set;for(;P&&!X.has(P);){if(P===A)return!0;X.add(P),P=U.get(P)}return!1},w=(m,A)=>{const P=f.get(m),X=H(A);return r(X,P)?`${m}${Ft}`:m},k=m=>s.has(m)?jt(m,h,g):void 0,L=N.flatMap((m,A)=>{const P=k(m.sourceId),X=k(m.targetId),z=s.has(m.sourceId)?f.get(m.sourceId):m.sourceId,se=s.has(m.targetId)?f.get(m.targetId):m.targetId;if(!le.has(z)||!le.has(se))return[];const Y=Hn(m.flowItem,m.type),ee=Wn[Y],ye=m.flowItem||(m.type.toLowerCase()==="exchangeswith"?void 0:m.type),ae=P?w(P,m.targetId):"right",ke=X?w(X,m.sourceId):"left",I=Ce=>Ce==="left"?"right":Ce==="right"?"left":Ce==="top"?"bottom":"top",C=(Ce,q,oe,j)=>{var ce;if(!q)return j;const te=((ce=(v.get(Ce)??[]).find(ue=>ue.id===q))==null?void 0:ce.side)??j;return oe.endsWith(Ft)?I(te):te},_=C(z,P,ae,"right"),K=C(se,X,ke,"left"),V=m.id||`ic-e-${A}`,de=(Ce,q,oe)=>{const j=F.get(Ce),te=le.get(Ce);if(q){const ce=(v.get(Ce)??[]).find(ue=>ue.id===q);if(ce){const ue=ce.size??Oe;return{x:j.x+ce.x+ue/2,y:j.y+ce.y+ue/2}}}return{x:j.x+(oe?te.width:0),y:j.y+te.height/2}},Se=de(z,P,!0),Ne=de(se,X,!1),Te=F.get(z),Pe=F.get(se);return[{edge:{id:V,source:z,target:se,sourceHandle:ae,targetHandle:ke,type:"interconnectionEdge",className:"ibd-interconnection-edge",label:ye,animated:m.type==="flow",style:{stroke:ee,strokeWidth:Math.max(2,ne.defaultWidth)},labelStyle:{fontSize:ge.badge,fill:"#4B5563",fontWeight:600},labelBgPadding:ne.labelBgPadding,labelBgBorderRadius:ne.labelBgRadius,labelBgStyle:{...ne.labelBgStyle,fillOpacity:.96,stroke:"#E2E8F0",strokeWidth:1},markerEnd:{type:"arrowclosed",color:ee,width:ne.arrowSize,height:ne.arrowSize},data:{flowCategory:Y,sourceOffset:{x:Se.x-Te.x,y:Se.y-Te.y},targetOffset:{x:Ne.x-Pe.x,y:Ne.y-Pe.y},sourcePortId:P,targetPortId:X,sourceSide:_,targetSide:K}},route:{id:V,source:Se,target:Ne,sourceNodeId:z,targetNodeId:se,sourceSide:_,targetSide:K}}]}),D=R.filter(m=>!m.data.isFrame).map(m=>{const A=F.get(m.id),P=le.get(m.id);return{id:m.id,x:A.x,y:A.y,width:P.width,height:P.height}}),Q=qe(L.map(m=>m.route),D),B=it(L.flatMap(({edge:m})=>{const A=Q.get(m.id);return m.label&&A&&A.length>=2?[{id:m.id,points:A,width:ct(String(m.label)),height:at}]:[]}),D),Z=L.map(({edge:m})=>({...m,data:{...m.data,points:Q.get(m.id)??[],labelPoint:B.get(m.id)}}));return{nodes:R,edges:Z}}function Le(t){return t.kind==="ForkNode"||t.kind==="JoinNode"}function so(t,e){const n=new Set(t.filter(s=>!Le(s)).map(s=>s.id)),o=new Set;for(const s of e.relationships)s.type!=="flow"&&s.type!=="succession"||(n.has(s.sourceId)&&o.add(s.sourceId),n.has(s.targetId)&&o.add(s.targetId));return t.filter(s=>!Le(s)&&!o.has(s.id))}function Zn(t,e,n=new Set,o){const s=Object.values(t.elements),h=(e?s.filter(e):s).filter(d=>d.construct==="action"||d.kind==="ActionUsage"||d.kind==="ActionDefinition"),u=h.filter(d=>d.parentAction);if(u.length===0)return h;const a=new Map(h.map(d=>[d.id,d])),y=[],p=d=>{const x=h.filter(f=>f.parentAction===d.id);if(n.has(d.id)&&x.length>0){for(const f of x)p(f);return}y.push(d)};if(o){for(const d of h.filter(x=>x.parentAction===o))p(d);return y}for(const d of u){const x=d.parentAction?a.get(d.parentAction):void 0;x!=null&&x.parentAction||p(d)}return y}function Jn(t,e,n=new Set,o){const s=Object.values(t.elements),h=(e?s.filter(e):s).filter(g=>g.construct==="action"||g.kind==="ActionUsage"||g.kind==="ActionDefinition"),u=[],a=new Map,y=new Map,p=g=>h.filter(l=>l.parentAction===g),d=(g,l)=>{u.push(g),l&&(a.set(g.id,l),y.has(l)||y.set(l,[]),y.get(l).push(g.id));const c=p(g.id);if(!(c.length===0||!n.has(g.id))){y.set(g.id,[]);for(const M of c)d(M,g.id)}};if(o){for(const g of p(o))d(g);return{actions:u,parentOf:a,childrenOf:y}}const x=new Map(h.map(g=>[g.id,g])),f=h.filter(g=>g.parentAction);if(f.length===0)return{actions:h,parentOf:a,childrenOf:y};for(const g of f){const l=g.parentAction?x.get(g.parentAction):void 0;l!=null&&l.parentAction||d(g)}return{actions:u,parentOf:a,childrenOf:y}}function Qn(t,e){const n=t.attributes.actionType,o=n?e.elements[n]:void 0,s=((o==null?void 0:o.construct)==="action"?o.parameters:t.parameters)??[];return{inPorts:s.filter(i=>i.direction==="in"||i.direction==="inout").map(i=>i.name),outPorts:s.filter(i=>i.direction==="out"||i.direction==="inout").map(i=>i.name)}}const Ht=["#4A90D9","#E67E22","#2ECC71","#9B59B6","#E74C3C","#1ABC9C","#F39C12","#7B68EE"],yt="Unallocated",es="Unstaged";function Et(t,e,n="all"){const o=new Map;for(const a of e.relationships)Ve.has(a.type)&&!o.has(a.targetId)&&o.set(a.targetId,a.sourceId);const s=[t],i=new Set(s);let h=t;for(;o.has(h);){const a=o.get(h);if(i.has(a))break;s.unshift(a),i.add(a),h=a}if(n==="all")return{id:t,level:s.length};const u=Math.min(Math.max(n,1),s.length)-1;return{id:s[u],level:u+1}}function ts(t,e,n="all"){var s;const o=Et(t,e,n).id;return((s=e.elements[o])==null?void 0:s.name)??o}function oo(t,e){const n=[...new Set(t)].map(s=>Et(s,e).level);if(n.length===0)return[];const o=Math.min(...n);return o<=1?[]:Array.from({length:o},(s,i)=>i+1)}function ns(t,e,n="allocation",o="all"){var u,a;const s=new Map,i=[],h=new Map;for(const y of t){if(Le(y))continue;const p=y.allocatedTo?Et(y.allocatedTo,e,o).id:yt,d=n==="stage"?y.attributes.stage||y.attributes.phase||es:p;if(s.set(y.id,d),!h.has(d)){const x={id:d,label:n==="allocation"&&d!==yt?((u=e.elements[d])==null?void 0:u.name)??d:d,color:Ht[h.size%Ht.length],inspectElementId:n==="allocation"&&d!==yt?d:((a=Object.values(e.elements).find(f=>f.id===d||f.name===d))==null?void 0:a.id)??y.id};h.set(d,x),i.push(x)}}return{laneOf:s,lanes:i}}const ss=18,os=36,rs=20,Ue=36,zt=16,Gt=120,pt=32,$t=64,Yt=10;function is(t,e,n){if(Le(t))return n==="vertical"?{width:$t,height:Yt}:{width:Yt,height:$t};const s=Math.max(e.inPorts.length,e.outPorts.length,0)*ss;return{width:Math.max(t.name.length*9+40,140),height:os+s+(s>0?8:0)+(t.allocatedTo?rs:0)}}function Ut(t){const e=t??"";return/energy|power|voltage|current|thermal|heat/i.test(e)?"energy":/material|fluid|gas|liquid|batch|consumable/i.test(e)?"material":"data"}const mt={control:"#4B5563",data:"#3498DB",energy:"#D97706",material:"#16A34A"};async function ro(t,e){var v,R,F,ie;const n=(e==null?void 0:e.nesting)??"flat",o=n==="nested"?Jn(t,e==null?void 0:e.viewpointFilter,e==null?void 0:e.expandedActionIds,e==null?void 0:e.focusActionId):{actions:Zn(t,e==null?void 0:e.viewpointFilter,e==null?void 0:e.expandedActionIds,e==null?void 0:e.focusActionId),childrenOf:new Map},s=o.actions;if(s.length===0)return{nodes:[],edges:[]};const i=new Set(s.map(r=>r.id)),{laneOf:h,lanes:u}=ns(s,t,e==null?void 0:e.laneGrouping,e==null?void 0:e.displayLevel),a=(e==null?void 0:e.direction)??"horizontal",y=n!=="nested"&&((e==null?void 0:e.swimlanes)??!0)&&u.length>=1,p=t.relationships.filter(r=>r.type==="succession"),d=t.relationships.filter(r=>r.type==="flow"),x=new Map;for(const r of n==="nested"?[]:(e==null?void 0:e.expandedActionIds)??[]){const w=Object.values(t.elements).filter(D=>D.parentAction===r);if(w.length===0)continue;const k=((v=p.find(D=>D.sourceId===`${r}__start`))==null?void 0:v.targetId)??w[0].id,L=((R=p.find(D=>D.targetId===`${r}__done`))==null?void 0:R.sourceId)??w[w.length-1].id;x.set(r,{first:k,last:L})}const f=r=>r.map(w=>{var k,L;return{...w,sourceId:((k=x.get(w.sourceId))==null?void 0:k.last)??w.sourceId,targetId:((L=x.get(w.targetId))==null?void 0:L.first)??w.targetId}}),g=f(p),l=f(d),c=new Set;for(const r of g){const w=r.sourceId.endsWith("__start")?r.sourceId.slice(0,-7):void 0,k=r.targetId.endsWith("__done")?r.targetId.slice(0,-6):void 0;w&&!x.has(w)&&i.has(r.targetId)&&c.add(r.sourceId),k&&!x.has(k)&&i.has(r.sourceId)&&c.add(r.targetId)}const M=new Set([...i,...c]),b=l.filter(r=>M.has(r.sourceId)&&M.has(r.targetId)&&(!(e!=null&&e.visibleFlowKinds)||e.visibleFlowKinds.has(Ut(r.flowItem)))),E=new Set(b.map(r=>`${r.sourceId}\0${r.targetId}`)),S=g.filter(r=>M.has(r.sourceId)&&M.has(r.targetId)&&(!(e!=null&&e.visibleFlowKinds)||e.visibleFlowKinds.has("control"))&&!E.has(`${r.sourceId}\0${r.targetId}`)),N=new Map(s.map(r=>[r.id,Qn(r,t)])),T=new Map(s.map(r=>[r.id,r])),G=new Map,W=new Map;if(n==="nested"){for(const[r,w]of o.childrenOf)G.set(r,w.filter(k=>M.has(k)));for(const r of c){const w=r.endsWith("__start")?r.slice(0,-7):r.slice(0,-6);G.has(w)&&G.get(w).push(r)}for(const[r,w]of G)for(const k of w)W.set(k,r)}const H=r=>{const w=T.get(r);return w?is(w,N.get(r),a):{width:28,height:28}},U=r=>{const w=G.get(r)??[];return w.length===0?{id:r,...H(r)}:{id:r,layoutOptions:{"elk.algorithm":"layered","elk.direction":a==="vertical"?"DOWN":"RIGHT","elk.padding":"[top=44,left=24,bottom=24,right=24]","elk.spacing.nodeNode":"36","elk.layered.spacing.nodeNodeBetweenLayers":"68","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES"},children:w.map(U)}},re=[...c,...s.map(r=>r.id)].filter(r=>!W.has(r)),Ie={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":a==="vertical"?"DOWN":"RIGHT","elk.spacing.nodeNode":"40","elk.layered.spacing.nodeNodeBetweenLayers":"80","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.layered.nodePlacement.strategy":"NETWORK_SIMPLEX","elk.layered.crossingMinimization.strategy":"LAYER_SWEEP","elk.separateConnectedComponents":"true","elk.spacing.componentComponent":"56",...n==="nested"?{"elk.hierarchyHandling":"INCLUDE_CHILDREN"}:{}},children:re.map(U),edges:[...b,...S].map((r,w)=>({id:`afe-${w}`,sources:[r.sourceId],targets:[r.targetId]}))},fe=await Ge.layout(Ie,{providerId:e==null?void 0:e.layoutProviderId}),$=new Map,Ee=r=>{$.set(r.id,{x:r.x??0,y:r.y??0,width:r.width??140,height:r.height??56});for(const w of r.children??[])Ee(w)};for(const r of fe.children??[])Ee(r);const be=new Map(u.map(r=>[r.id,r.color])),le=[];if(y&&a==="horizontal"){const r=new Map;for(const Q of s){if(Le(Q))continue;const B=$.get(Q.id),Z=h.get(Q.id);r.has(Z)||r.set(Z,[]),r.get(Z).push(B.y)}const w=[...u].sort((Q,B)=>{const Z=J=>J.reduce((m,A)=>m+A,0)/J.length;return Z(r.get(Q.id)??[0])-Z(r.get(B.id)??[0])});let k=1/0,L=-1/0;for(const Q of s){const B=$.get(Q.id);k=Math.min(k,B.x),L=Math.max(L,B.x+B.width)}let D=0;for(const Q of w){const B=s.filter(A=>h.get(A.id)===Q.id);B.sort((A,P)=>$.get(A.id).x-$.get(P.id).x||$.get(A.id).y-$.get(P.id).y);const Z=Math.min(...B.map(A=>$.get(A.id).y));let J=0;const m=[];for(const A of B){const P=$.get(A.id);let X=D+Ue+(P.y-Z);for(const z of m)P.x<z.x1&&P.x+P.width>z.x0&&(X=Math.max(X,z.bottom+16));$.set(A.id,{...P,y:X}),m.push({x0:P.x,x1:P.x+P.width,bottom:X+P.height}),J=Math.max(J,X+P.height-D)}J+=Ue,le.push({id:`__lane_${Q.id}`,type:"actionFlowLane",position:{x:k-Gt,y:D},data:{label:Q.label,color:Q.color,orientation:"row",inspectElementId:Q.inspectElementId,memberIds:B.map(A=>A.id),isFrame:!0},style:{width:L-k+Gt+Ue,height:J},draggable:!1,selectable:!1,zIndex:-1}),D+=J+zt}}else if(y){let r=1/0,w=-1/0;for(const L of s){const D=$.get(L.id);r=Math.min(r,D.y),w=Math.max(w,D.y+D.height)}let k=0;for(const L of u){const D=s.filter(Z=>h.get(Z.id)===L.id).sort((Z,J)=>$.get(Z.id).y-$.get(J.id).y||$.get(Z.id).x-$.get(J.id).x),B=Math.max(...D.map(Z=>$.get(Z.id).width))+Ue*2;for(const Z of D){const J=$.get(Z.id);$.set(Z.id,{...J,x:k+(B-J.width)/2})}le.push({id:`__lane_${L.id}`,type:"actionFlowLane",position:{x:k,y:r-pt},data:{label:L.label,color:L.color,orientation:"column",inspectElementId:L.inspectElementId,memberIds:D.map(Z=>Z.id),isFrame:!0},style:{width:B,height:w-r+pt+Ue},draggable:!1,selectable:!1,zIndex:-1}),k+=B+zt}}const ve=n==="nested"?[]:s.filter(Le);if(ve.length>0)for(const r of ve){const w=$.get(r.id),k=[];for(const D of[...S,...b]){const Q=D.sourceId===r.id?D.targetId:D.targetId===r.id?D.sourceId:void 0;if(Q===void 0)continue;const B=$.get(Q);B&&k.push(a==="vertical"?B.x+B.width/2:B.y+B.height/2)}if(k.length===0)continue;const L=k.reduce((D,Q)=>D+Q,0)/k.length;$.set(r.id,a==="vertical"?{...w,x:L-w.width/2}:{...w,y:L-w.height/2})}for(const r of n==="nested"?[]:c){const w=$.get(r);if(!w)continue;const k=[];for(const B of S){const Z=B.sourceId===r?B.targetId:B.targetId===r?B.sourceId:void 0;if(!Z)continue;const J=$.get(Z);J&&k.push(a==="vertical"?J.x+J.width/2:J.y+J.height/2)}if(k.length===0)continue;const L=k.reduce((B,Z)=>B+Z,0)/k.length,D=s.filter(B=>!Le(B)).map(B=>$.get(B.id)).filter(B=>!!B),Q=r.endsWith("__start");if(a==="vertical"){const B=Math.min(...D.map(J=>J.y)),Z=Math.max(...D.map(J=>J.y+J.height));$.set(r,{...w,x:L-w.width/2,y:Q?B-w.height-pt-16:Z+24})}else{const B=Math.min(...D.map(J=>J.x)),Z=Math.max(...D.map(J=>J.x+J.width));$.set(r,{...w,x:Q?B-w.width-24:Z+24,y:L-w.height/2})}}const xe=[...le],pe=r=>{const w=W.get(r);return w?{parentId:w,extent:"parent"}:{}};for(const r of c){const w=$.get(r),k=r.endsWith("__start"),L={label:k?"Start":"Done",nodeType:k?"start":"done",laneColor:"#374151",layerColor:"#374151",inPorts:[],outPorts:[],flowDirection:a};xe.push({id:r,type:"actionFlowNode",position:{x:w.x,y:w.y},...pe(r),data:L})}for(const r of s){const w=$.get(r.id);if(Le(r)){const Z={element:r,label:r.name,nodeType:r.kind==="ForkNode"?"fork":"join",laneColor:"#374151",layerColor:"#374151",inPorts:[],outPorts:[],flowDirection:a};xe.push({id:r.id,type:"actionFlowNode",position:{x:w.x,y:w.y},style:{width:w.width,height:w.height},...pe(r.id),data:Z});continue}const k=N.get(r.id),L=h.get(r.id),D=r.allocatedTo?ts(r.allocatedTo,t,e==null?void 0:e.displayLevel):void 0,Q=(((F=G.get(r.id))==null?void 0:F.length)??0)>0,B={element:r,label:r.name,nodeType:"action",parameters:r.parameters,allocatedTo:D,laneColor:be.get(L)??"#9CA3AF",layerColor:Be[r.layer]||"#FF6B6B",inPorts:k.inPorts,outPorts:k.outPorts,hasChildren:Object.values(t.elements).some(Z=>Z.parentAction===r.id),isExpanded:((ie=e==null?void 0:e.expandedActionIds)==null?void 0:ie.has(r.id))??!1,isFrame:Q,onToggleExpand:e!=null&&e.onToggleAction?()=>e.onToggleAction(r.id):void 0,onDrillIn:e!=null&&e.onDrillInAction?()=>e.onDrillInAction(r.id):void 0,flowDirection:a};xe.push({id:r.id,type:"actionFlowNode",position:{x:w.x,y:w.y},...Q?{style:{width:w.width,height:w.height}}:{},...pe(r.id),data:B})}if(W.size>0){const r=new Map(xe.map(D=>[D.id,D])),w=[],k=new Set,L=D=>{if(k.has(D.id))return;k.add(D.id);const Q=D.parentId?r.get(D.parentId):void 0;Q&&L(Q),w.push(D)};for(const D of xe)L(D);xe.length=0,xe.push(...w)}const Me=[];for(const r of b){const w=Ut(r.flowItem),k=mt[w],L=r.flowItem?/signal|error|status|code|report|alarm|response|command|data|reading/i.test(r.flowItem):!1;Me.push({id:r.id,source:r.sourceId,target:r.targetId,label:void 0,type:"smoothstep",animated:!1,style:{stroke:k,strokeWidth:ne.flowWidth,strokeDasharray:L?"6 3":void 0},labelStyle:{fontSize:ge.badge,fill:k,fontWeight:600},labelBgStyle:ne.labelBgStyle,labelBgPadding:ne.labelBgPadding,labelBgBorderRadius:ne.labelBgRadius,markerEnd:{type:"arrowclosed",color:k,width:ne.arrowSize,height:ne.arrowSize},data:{flowCategory:w,flowItem:r.flowItem}})}for(const r of S)Me.push({id:r.id,source:r.sourceId,target:r.targetId,type:"smoothstep",animated:!1,style:{stroke:mt.control,strokeWidth:1.5},markerEnd:{type:"arrowclosed",color:mt.control,width:12,height:12},data:{flowCategory:"control"}});return{nodes:xe,edges:Me}}function as(t){return t.attributes.sourceState&&t.attributes.targetState?!0:t.kind==="Transition"||t.kind.endsWith("Transition")}function cs(t){return t.kind.endsWith("State")||t.kind.endsWith("Machine")||t.kind.endsWith("Mode")}function ls(t,e){const n=Object.values(t.elements),o=e?n.filter(e):n,s=[],i=[],h=[];for(const u of o)as(u)?i.push(u):cs(u)?s.push(u):h.push(u);return{states:s,transitions:i,annotations:h}}const Xt=46;function ds(t){return t.length>Xt?`${t.slice(0,Xt-1)}…`:t}function hs(t){const e=t.attributes.trigger??"",n=t.attributes.guardSummary??t.attributes.guard??"",o=n&&!/^none\b/i.test(n),s=e||t.name;return ds(o?`${s} [${n}]`:s)}function gs(t,e){const n=new Map;for(const s of e)n.set(s.name,s.id),n.set(s.id,s.id);const o=[];for(const s of t){const i=n.get(s.attributes.sourceState??""),h=n.get(s.attributes.targetState??"");!i||!h||o.push({element:s,sourceId:i,targetId:h,label:hs(s)})}return o}function us(t,e={}){const n=e.collapsedStateIds??new Set,o=e.focusStateId&&t.elements.has(e.focusStateId)?e.focusStateId:void 0,s=x=>(t.childrenMap.get(x)??[]).filter(f=>t.elements.has(f)),i=o?s(o):[],h=i.length>0?i:t.roots.filter(x=>t.elements.has(x)),u=new Set,a=new Map,y=new Map,p=(x,f)=>{a.set(x,f),y.set(f,(y.get(f)??0)+1);for(const g of s(x))p(g,f)},d=x=>{u.add(x);const f=s(x);if(n.has(x)){for(const g of f)p(g,x);return}for(const g of f)d(g)};for(const x of h)d(x);return{visible:u,liftTo:a,hiddenCount:y,roots:h}}function fs(t,e){const n=s=>e.visible.has(s)?s:e.liftTo.get(s),o=[];for(const s of t){const i=n(s.sourceId),h=n(s.targetId);if(!i||!h)continue;const u=s.sourceId===s.targetId;i===h&&!u||o.push({...s,sourceId:i,targetId:h})}return o}const ys="#FF6B6B",ps="#95A5A6",Kt="#64748B";async function io(t,e){const{states:n,transitions:o,annotations:s}=ls(t,e==null?void 0:e.viewpointFilter);if(n.length===0&&s.length===0)return{nodes:[],edges:[]};const i=rt(n,t.relationships),h=us(i,{focusStateId:e==null?void 0:e.focusStateId,collapsedStateIds:e==null?void 0:e.collapsedStateIds}),u=fs(gs(o,n),h);if(h.visible.size===0&&s.length===0)return{nodes:[],edges:[]};const a=b=>({width:Math.max(b.name.length*7.5+56,150),height:(i.childrenMap.get(b.id)??[]).some(E=>i.elements.has(E))?74:54}),y=b=>{const E=i.elements.get(b),S=(i.childrenMap.get(b)??[]).filter(N=>h.visible.has(N));return S.length===0?{id:b,...a(E)}:{id:b,layoutOptions:{"elk.algorithm":"layered","elk.direction":"DOWN","elk.padding":"[top=48,left=28,bottom=28,right=28]","elk.spacing.nodeNode":"72","elk.layered.spacing.nodeNodeBetweenLayers":"120","elk.spacing.edgeNode":"32","elk.edgeRouting":"ORTHOGONAL","elk.layered.cycleBreaking.strategy":"MODEL_ORDER","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES"},children:S.map(y)}},p={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":"DOWN","elk.hierarchyHandling":"INCLUDE_CHILDREN","elk.edgeRouting":"ORTHOGONAL","elk.spacing.nodeNode":"72","elk.layered.spacing.nodeNodeBetweenLayers":"120","elk.spacing.edgeNode":"32","elk.spacing.edgeLabel":"8","elk.layered.cycleBreaking.strategy":"MODEL_ORDER","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.separateConnectedComponents":"true","elk.spacing.componentComponent":"64","elk.padding":"[top=20, left=20, bottom=20, right=20]"},children:h.roots.map(y),edges:u.map((b,E)=>({id:`st-${E}`,sources:[b.sourceId],targets:[b.targetId]}))},d=await Ge.layout(p,{providerId:e==null?void 0:e.layoutProviderId}),x=[],f=new Map,g=(b,E,S={x:0,y:0})=>{var T,G;const N=i.elements.get(b.id);if(N){const W=!!((T=b.children)!=null&&T.length),H=N.kind.endsWith("Machine"),U={x:S.x+(b.x??0),y:S.y+(b.y??0)};f.set(b.id,{...U,width:b.width??150,height:b.height??54,isContainer:W}),x.push({id:b.id,type:"stateNode",position:{x:b.x??0,y:b.y??0},...E?{parentId:E,extent:"parent"}:{},data:{label:N.name,kind:N.kind,color:ys,isContainer:W,isMachine:H,subtitle:N.attributes.modeKind,hasChildren:(i.childrenMap.get(b.id)??[]).some(re=>i.elements.has(re)),isCollapsed:!!((G=e==null?void 0:e.collapsedStateIds)!=null&&G.has(b.id)),hiddenCount:h.hiddenCount.get(b.id)??0,onToggleCollapse:e!=null&&e.onToggleCollapse?()=>e.onToggleCollapse(b.id):void 0,onDrillIn:e!=null&&e.onDrillIn?()=>e.onDrillIn(b.id):void 0},style:{width:b.width??150,height:b.height??54}});for(const re of b.children??[])g(re,b.id,U);return}};for(const b of d.children??[])g(b);if(s.length>0){let b=0,E=800;for(const W of d.children??[])b=Math.max(b,(W.y??0)+(W.height??0)),E=Math.max(E,(W.x??0)+(W.width??0));const S=240,N=48,T=14,G=Math.max(2,Math.floor(E/(S+T)));s.forEach((W,H)=>{x.push({id:W.id,type:"stateNode",position:{x:H%G*(S+T),y:b+56+Math.floor(H/G)*(N+T)},data:{label:W.name,kind:W.kind,color:ps,isNote:!0},style:{width:S,height:N}})})}const l=[...f.entries()].filter(([,b])=>!b.isContainer).map(([b,E])=>({id:b,x:E.x,y:E.y,width:E.width,height:E.height})),c=On({connectors:u.map((b,E)=>({id:b.element.id||`st-e-${E}`,sourceId:b.sourceId,targetId:b.targetId,label:b.label})),rects:f,obstacles:l,channelGap:26}),M=u.map((b,E)=>{const S=b.element.id||`st-e-${E}`,N=c.get(S),T={id:S,source:b.sourceId,target:b.targetId,label:b.label,style:{stroke:Kt,strokeWidth:ne.defaultWidth},markerEnd:{type:"arrowclosed",color:Kt,width:ne.arrowSize,height:ne.arrowSize}};return N?{...T,type:"interconnectionEdge",data:{points:N.points,labelPoint:N.labelPoint}}:{...T,type:"smoothstep",labelStyle:{fontSize:ge.badge,fill:"#6B7280",fontWeight:500},labelBgPadding:ne.labelBgPadding,labelBgBorderRadius:ne.labelBgRadius,labelBgStyle:ne.labelBgStyle}});return{nodes:x,edges:M}}const ms=/(?:Actor|User)$/,xs=new Set(["UseCase"]),pn=new Set(["initiates","participatesin","performs","interactswith","includes","extends"]),_e=t=>t.toLowerCase();function mn(t){return ms.test(t.kind)||t.construct==="actor"}function vt(t){return xs.has(t.kind)||t.construct==="use case"}function ao(t){const e=new Set(Object.values(t.elements).filter(vt).map(s=>s.id)),n=new Map;for(const s of t.relationships.filter(i=>_e(i.type)==="includes"&&e.has(i.sourceId)&&e.has(i.targetId)))n.set(s.targetId,[...n.get(s.targetId)??[],s.sourceId]);const o=(s,i=new Set)=>{if(i.has(s))return 0;const h=n.get(s)??[];return h.length===0?0:1+Math.min(...h.map(u=>o(u,new Set([...i,s]))))};return Math.max(0,...[...e].map(s=>o(s)))}function co(t){const e=Object.values(t.elements),n=new Set(e.filter(vt).map(s=>s.id)),o=new Set(t.relationships.filter(s=>pn.has(_e(s.type))).flatMap(s=>n.has(s.sourceId)?[s.targetId]:n.has(s.targetId)?[s.sourceId]:[]));return e.filter(mn).filter(s=>o.has(s.id)).map(s=>({id:s.id,name:s.name})).sort((s,i)=>s.name.localeCompare(i.name))}function lo(t){var s,i;const e=`${(t==null?void 0:t.layoutHint)??""};${(t==null?void 0:t.styleHint)??""}`,n=/(?:usecase:)?level\s*=\s*(all|\d+)/i.exec(e),o=/(?:edge|routing)\s*=\s*(straight|orthogonal|elbow|rounded|curved|arc)/i.exec(e);return{level:(n==null?void 0:n[1])==="all"?"all":n?Number(n[1]):"all",edgeStyle:{orthogonal:"elbow"}[((s=o==null?void 0:o[1])==null?void 0:s.toLowerCase())??""]??((i=o==null?void 0:o[1])==null?void 0:i.toLowerCase())??"rounded"}}function ho(t,e={}){const n=Object.values(t.elements).filter(I=>!e.viewpointFilter||e.viewpointFilter(I)),o=n.filter(vt),s=t.relationships.filter(I=>pn.has(_e(I.type))),i=new Map;for(const I of s.filter(C=>_e(C.type)==="includes")){const C=i.get(I.targetId)??[];C.push(I.sourceId),i.set(I.targetId,C)}const h=(I,C=new Set)=>{if(C.has(I))return 0;const _=i.get(I)??[];return _.length===0?0:1+Math.min(..._.map(K=>h(K,new Set([...C,I]))))},u=e.level??"all",a=new Set(o.filter(I=>u==="all"||h(I.id)<=u).map(I=>I.id));let y=!0;for(;y;){y=!1;for(const I of s.filter(C=>_e(C.type)==="extends"))if(a.has(I.sourceId)||a.has(I.targetId))for(const C of[I.sourceId,I.targetId])!a.has(C)&&o.some(_=>_.id===C)&&(a.add(C),y=!0)}const p=e.hiddenActorIds??new Set;for(const I of s){const C=a.has(I.sourceId)?I.targetId:a.has(I.targetId)?I.sourceId:void 0;C&&p.has(C)&&(a.delete(I.sourceId),a.delete(I.targetId))}const d=o.filter(I=>a.has(I.id)),x=n.filter(mn).filter(I=>!p.has(I.id)).filter(I=>s.some(C=>C.sourceId===I.id&&a.has(C.targetId)||C.targetId===I.id&&a.has(C.sourceId))),f=new Set([...x,...d].map(I=>I.id));if(d.length===0)return{nodes:[],edges:[]};const g=new Set(s.filter(I=>_e(I.type)==="extends").map(I=>I.sourceId)),l=new Map;for(const I of d){if(g.has(I.id))continue;const C=h(I.id);l.set(C,[...l.get(C)??[],I])}const M=[...l.keys()].sort((I,C)=>I-C).map(I=>[...l.get(I)??[]]),b=new Map;M.forEach((I,C)=>I.forEach(_=>b.set(_.id,C)));const E=new Map;for(const I of s.filter(C=>_e(C.type)==="extends")){const C=d.find(V=>V.id===I.sourceId),_=b.get(I.targetId);if(!C||_===void 0||b.has(C.id))continue;const K=M[_];K.splice(K.findIndex(V=>V.id===I.targetId)+1,0,C),b.set(C.id,_),E.set(I.targetId,[...E.get(I.targetId)??[],C])}const S=new Set([...E.values()].flat().map(I=>I.id)),N=I=>s.filter(C=>C.sourceId===I||C.targetId===I).map(C=>C.sourceId===I?C.targetId:C.sourceId),T=new Map,G=()=>M.forEach(I=>I.forEach((C,_)=>T.set(C.id,_)));G(),x.forEach((I,C)=>T.set(I.id,C));const W=I=>{const C=N(I).map(_=>T.get(_)).filter(_=>_!==void 0);return C.length===0?T.get(I)??0:C.reduce((_,K)=>_+K,0)/C.length};for(let I=0;I<3;I++){const C=I%2===0?M:[...M].reverse();for(const _ of C){const K=_.filter(V=>!S.has(V.id));K.sort((V,de)=>W(V.id)-W(de.id)),_.splice(0,_.length,...K.flatMap(V=>[V,...E.get(V.id)??[]])),G()}x.sort((_,K)=>W(_.id)-W(K.id)),x.forEach((_,K)=>T.set(_.id,K))}const H=176,U=88,re=104,Ie=40,fe=104,$=88,Ee=116,be=48,le=62,ve=44,xe=76,pe=20,Me=Math.max(1,...M.map(I=>I.length)),v=Math.max(520,M.length*H+Math.max(M.length-1,0)*re+be*2),R=Math.max(300,Me*U+(Me-1)*Ie+le+ve),F=I=>be+I*(H+re)+H/2,ie=new Map;for(const I of x){const C=N(I.id).map(K=>b.get(K)).filter(K=>K!==void 0).map(F),_=C.length?C.reduce((K,V)=>K+V,0)/C.length:0;ie.set(I.id,C.length===0||_<=v/2?"left":"right")}const r=x.filter(I=>ie.get(I.id)==="left"),w=x.filter(I=>ie.get(I.id)==="right"),k=pe+(r.length?fe+xe:0),L=pe,D=[{id:"__use_case_boundary__",type:"useCaseBoundary",position:{x:k,y:L},data:{label:e.systemName||"System Boundary",isFrame:!0,kind:"System Boundary"},style:{width:v,height:R},draggable:!1,selectable:!1,zIndex:-1}],Q=new Map,B=L+le,Z=R-le-ve;M.forEach((I,C)=>{const _=I.length*U+(I.length-1)*Ie;let K=B+(Z-_)/2;for(const V of I){const de={x:k+be+C*(H+re),y:K};Q.set(V.id,de),D.push({id:V.id,type:"useCase",position:de,data:{label:V.name,kind:V.kind,color:"#E67E22",level:h(V.id)},style:{width:H,height:U}}),K+=U+Ie}});for(const I of["left","right"]){const _=(I==="left"?r:w).map(V=>{const de=N(V.id).map(Se=>Q.get(Se)).filter(Se=>!!Se).map(Se=>Se.y);return{actor:V,y:de.length?de.reduce((Se,Ne)=>Se+Ne,0)/de.length:L+le}}).sort((V,de)=>V.y-de.y);let K=-1/0;for(const{actor:V,y:de}of _){const Se=Math.max(de,K+Ee-$,pe);K=Se+$,D.push({id:V.id,type:"useCaseActor",position:{x:I==="left"?pe:k+v+xe,y:Se},data:{label:V.name,kind:V.kind,color:"#334155",side:I},style:{width:fe,height:$}})}}const J=e.edgeStyle??"rounded",m=s.filter(I=>f.has(I.sourceId)&&f.has(I.targetId)).map(I=>{const C=w.some(V=>V.id===I.sourceId),_=C?I.targetId:I.sourceId,K=C?I.sourceId:I.targetId;return{edge:{id:I.id,source:_,target:K,label:/^(includes|extends)$/.test(_e(I.type))?`«${_e(I.type)}»`:void 0,type:"useCaseEdge",data:{routing:J},style:{stroke:"#64748B",strokeWidth:1.4,strokeDasharray:/^(includes|extends)$/.test(_e(I.type))?"5 4":void 0}},source:_,target:K}}),A=new Map(D.map(I=>[I.id,I])),P=I=>{var C,_;return{width:Number(((C=I.style)==null?void 0:C.width)??150),height:Number(((_=I.style)==null?void 0:_.height)??82)}},X=(I,C)=>{const _=P(A.get(I));return C==="left"?{x:0,y:_.height/2}:C==="right"?{x:_.width,y:_.height/2}:C==="top"?{x:_.width/2,y:0}:{x:_.width/2,y:_.height}},z=(I,C)=>{const _=A.get(I),K=X(I,C);return{x:_.position.x+K.x,y:_.position.y+K.y}},se=m.map(({edge:I,source:C,target:_})=>{var Pe,je;const K=x.find(Ce=>Ce.id===C),V=x.find(Ce=>Ce.id===_),de=!K&&!V&&b.get(C)!==void 0&&b.get(C)===b.get(_),Se=de&&(((Pe=Q.get(C))==null?void 0:Pe.y)??0)<(((je=Q.get(_))==null?void 0:je.y)??0),Ne=K?w.includes(K)?"left":"right":de?Se?"bottom":"top":"right",Te=V?w.includes(V)?"left":"right":de?Se?"top":"bottom":"left";return{id:I.id,source:z(C,Ne),target:z(_,Te),sourceNodeId:C,targetNodeId:_,sourceSide:Ne,targetSide:Te}}),Y=D.filter(I=>I.type==="useCase"||I.type==="useCaseActor").map(I=>({id:I.id,x:I.position.x,y:I.position.y,...P(I)})),ee=J==="straight"?new Map:qe(se,Y,28),ye=it(m.flatMap(({edge:I})=>{const C=ee.get(I.id),_=I.label;return _&&C&&C.length>=2?[{id:I.id,points:C,width:ct(_),height:at}]:[]}),Y),ae=new Map(se.map(I=>[I.id,I])),ke=m.map(({edge:I})=>({...I,data:{...I.data,points:ee.get(I.id)??[],labelPoint:ye.get(I.id),sourceOffset:X(I.source,ae.get(I.id).sourceSide),targetOffset:X(I.target,ae.get(I.id).targetSide),sourceSide:ae.get(I.id).sourceSide,targetSide:ae.get(I.id).targetSide}}));return{nodes:D,edges:ke}}const Vt=new Set(["includesStep",...Ve]);function qt(t){return t.kind.endsWith("Step")||!!t.attributes.stepOrder}function ws(t){if(!t)return;const e=t.split(":");return(e.length>1?e[e.length-1]:e[0]).trim()||void 0}function Is(t,e){const n=t.split(":")[0].trim(),o=e.elements[n];if(o)return o.name;for(const s of Object.values(e.elements))if(s.attributes.id===n)return s.name;return t}const Zt=t=>{const e=Number(t.attributes.stepOrder);return Number.isFinite(e)?e:0};function bs(t,e){const n=Object.values(t.elements),o=e?n.filter(e):n,s=o.filter(qt),i=new Set(s.map(l=>l.id)),h=o.filter(l=>!qt(l)&&t.relationships.some(c=>Vt.has(c.type)&&c.sourceId===l.id&&i.has(c.targetId))),u=[],a=new Map,y=l=>{const c=l.split(":")[0].trim()||l;return a.has(c)||(a.set(c,u.length),u.push({id:c,label:Is(l,t)})),a.get(c)},p=l=>[...l].sort((c,M)=>Zt(c)-Zt(M)).map(c=>({step:c,lane:y(c.attributes.allocatedFunction??c.allocatedTo??c.id),item:ws(c.attributes.exchangeItem)})),d=l=>{var M;const c=t.relationships.find(b=>b.type==="realizesScenario"&&b.sourceId===l.id);return c?(M=t.elements[c.targetId])==null?void 0:M.name:void 0},x=new Set,f=[];for(const l of h){const c=t.relationships.filter(M=>Vt.has(M.type)&&M.sourceId===l.id&&i.has(M.targetId)).map(M=>t.elements[M.targetId]);for(const M of c)x.add(M.id);f.push({chain:l,scenario:d(l),occurrences:p(c)})}const g=s.filter(l=>!x.has(l.id));return g.length>0&&f.push({occurrences:p(g)}),{lifelines:u,sections:f.filter(l=>l.occurrences.length>0)}}const Xe=240,Ss=52,Ms=68,Es=40,vs=24,Jt=14;function go(t,e){const n=bs(t,e==null?void 0:e.viewpointFilter);if(n.lifelines.length===0)return{nodes:[],edges:[]};const o=[],s=[],i=p=>p*Xe+Xe/2;let h=Ss+28;const u=[];for(const p of n.sections){const d=h;h+=Es;const x=p.occurrences.map(f=>{const g={...f,y:h};return h+=Ms,g});u.push({section:p,top:d,bottom:h,placed:x}),h+=vs}const a=h,y=n.lifelines.length*Xe;return n.lifelines.forEach((p,d)=>{o.push({id:`__lifeline_${p.id}`,type:"seqLifeline",position:{x:d*Xe,y:0},data:{label:p.label},style:{width:Xe,height:a},draggable:!1,selectable:!1,zIndex:-2})}),u.forEach(({section:p,top:d,bottom:x,placed:f},g)=>{var l;o.push({id:`__section_${g}`,type:"seqSection",position:{x:-24,y:d},data:{label:((l=p.chain)==null?void 0:l.name)??"Steps",scenario:p.scenario},style:{width:y+48,height:x-d},draggable:!1,selectable:!1,zIndex:-1}),f.forEach((c,M)=>{if(o.push({id:c.step.id,type:"seqOccurrence",position:{x:i(c.lane)-Jt/2,y:c.y-Jt/2},data:{label:c.step.name,kind:c.step.kind},draggable:!1,zIndex:2}),M<f.length-1){const b=f[M+1],E=b.lane>=c.lane,S=b.lane===c.lane;s.push({id:`seq-${g}-${M}`,source:c.step.id,target:b.step.id,sourceHandle:S||E?"right":"left",targetHandle:S?"right":E?"left":"right",type:S?"smoothstep":"straight",label:c.item,style:{stroke:"#3498DB",strokeWidth:ne.flowWidth},labelStyle:{fontSize:ge.badge,fill:"#4A90D9",fontWeight:600},labelBgPadding:ne.labelBgPadding,labelBgBorderRadius:ne.labelBgRadius,labelBgStyle:ne.labelBgStyle,markerEnd:{type:"arrowclosed",color:"#3498DB",width:ne.arrowSize,height:ne.arrowSize},zIndex:1})}})}),{nodes:o,edges:s}}const ks=new Set(["interactswith","exchangeswith","appliesincontext","connectsphysically"]),Qt=/(?:Actor|User)$/,en=t=>t.toLowerCase(),tn=t=>t.kind==="UseContext"||/environment|context/i.test(t.name)||/environment/i.test(String(t.attributes.entityKind??"")),Cs=t=>/systemofinterest|system-of-interest/i.test(String(t.attributes.contextRole??""))||String(t.attributes.isSystemOfInterest??"").toLowerCase()==="true",Ke=76,xn=170,As=238,nn=30,sn=104,xt=240,wt=108,It=92,bt=74,St=40,on=t=>Math.min(Math.max(t.length*7.4+28,xn),As);function Os(t,e,n){const o=new Map,s=[];for(const i of t){const h=e.some(a=>a.sourceId===i&&a.targetId===n),u=e.some(a=>a.sourceId===n&&a.targetId===i);h&&!u?o.set(i,"left"):u&&!h?o.set(i,"right"):s.push(i)}for(const i of s){const h=[...o.values()].filter(a=>a==="left").length,u=o.size-h;o.set(i,h<=u?"left":"right")}return o}function uo(t,e){var Me;const n=Object.values(t.elements),o=t.relationships.filter(v=>ks.has(en(v.type))),s=new Set(o.flatMap(v=>[v.sourceId,v.targetId])),i=n.filter(v=>s.has(v.id)&&!fn(v));if(i.length===0)return{nodes:[],edges:[]};const h=v=>o.filter(R=>R.sourceId===v.id||R.targetId===v.id).length,u=i.find(Cs)??i.find(v=>/system/i.test(v.name))??[...i].sort((v,R)=>h(R)-h(v))[0],a=i.filter(v=>v.id!==u.id),y=new Set([u.id,...a.map(v=>v.id)]),p=o.filter(v=>y.has(v.sourceId)&&y.has(v.targetId)),d=Os(a.map(v=>v.id),p,u.id),x=v=>Qt.test(v.kind)?0:tn(v)?1:2,f=v=>a.filter(R=>d.get(R.id)===v).sort((R,F)=>x(R)-x(F)||R.name.localeCompare(F.name)),g={left:f("left"),right:f("right")},l=v=>v.length===0?0:v.length*Ke+(v.length-1)*nn,c=v=>v.length===0?0:Math.max(...v.map(R=>on(R.name))),M=xt+It*2,b=wt+bt*2,E=St+Math.max(b,l(g.left),l(g.right))/2,S=c(g.left),N=St+(S>0?S+sn:0),T=E-b/2,G=N+M+sn,W=[{id:"__context_boundary__",type:"contextBoundary",position:{x:N,y:T},data:{label:`${e??u.name} — System Boundary`,isFrame:!0},style:{width:M,height:b},draggable:!1,selectable:!1,zIndex:-1},{id:u.id,type:"contextSystem",position:{x:N+It,y:T+bt},data:{label:u.name,kind:u.kind},style:{width:xt,height:wt}}],H=new Map;for(const v of["left","right"]){const R=g[v];let F=E-l(R)/2;for(const ie of R){const r=on(ie.name),w=v==="left"?St+S-r:G;H.set(ie.id,{x:w,y:F,width:r,height:Ke,side:v}),W.push({id:ie.id,type:"contextExternal",position:{x:w,y:F},data:{label:ie.name,kind:ie.kind,category:tn(ie)?"environment":Qt.test(ie.kind)?"person":"system"},style:{width:r,height:Ke}}),F+=Ke+nn}}const U={x:N+It,y:T+bt,width:xt,height:wt},re={left:[],right:[]};for(const v of p){const R=v.sourceId===u.id?v.targetId:v.sourceId;if(v.sourceId!==u.id&&v.targetId!==u.id)continue;const F=(Me=H.get(R))==null?void 0:Me.side;F&&!re[F].includes(v.id)&&re[F].push(v.id)}for(const v of["left","right"])re[v].sort((R,F)=>{const ie=r=>{var k;const w=p.find(L=>L.id===r);return((k=H.get(w.sourceId===u.id?w.targetId:w.sourceId))==null?void 0:k.y)??0};return ie(R)-ie(F)});const Ie=(v,R)=>{const F=re[R],ie=Math.max(F.indexOf(v),0);return{x:R==="left"?U.x:U.x+U.width,y:U.y+U.height*(ie+.5)/Math.max(F.length,1)}},fe=(v,R)=>{const F=H.get(v);return{x:R==="left"?F.x:F.x+F.width,y:F.y+F.height/2}},$=(v,R)=>{var r;if(v===u.id)return((r=H.get(R))==null?void 0:r.side)==="right"?"right":"left";const F=H.get(v);return(R===u.id?U:H.get(R)).x+(R===u.id?U.width:H.get(R).width)/2>=F.x+F.width/2?"right":"left"},Ee=p.map(v=>{const R=$(v.sourceId,v.targetId),F=$(v.targetId,v.sourceId),ie=(r,w)=>r===u.id?Ie(v.id,w):fe(r,w);return{rel:v,sourceSide:R,targetSide:F,source:ie(v.sourceId,R),target:ie(v.targetId,F)}}),be=W.filter(v=>!v.data.isFrame).map(v=>{var R,F;return{id:v.id,x:v.position.x,y:v.position.y,width:Number(((R=v.style)==null?void 0:R.width)??xn),height:Number(((F=v.style)==null?void 0:F.height)??Ke)}}),le=qe(Ee.map(v=>({id:v.rel.id,source:v.source,target:v.target,sourceNodeId:v.rel.sourceId,targetNodeId:v.rel.targetId,sourceSide:v.sourceSide,targetSide:v.targetSide})),be,24),ve=new Map(Ee.map(v=>[v.rel.id,`«${en(v.rel.type)}»`])),xe=it(Ee.flatMap(v=>{const R=le.get(v.rel.id),F=ve.get(v.rel.id);return R&&R.length>=2?[{id:v.rel.id,points:R,width:ct(F),height:at}]:[]}),be),pe=Ee.map(v=>{const R=(F,ie,r)=>{const w=F===u.id?U:H.get(F);return{x:r.x-w.x,y:r.y-w.y,side:ie}};return{id:v.rel.id,source:v.rel.sourceId,target:v.rel.targetId,type:"useCaseEdge",label:ve.get(v.rel.id),style:{stroke:"#0F766E",strokeWidth:1.5},data:{routing:"rounded",points:le.get(v.rel.id)??[v.source,v.target],labelPoint:xe.get(v.rel.id),sourceSide:v.sourceSide,targetSide:v.targetSide,sourceOffset:R(v.rel.sourceId,v.sourceSide,v.source),targetOffset:R(v.rel.targetId,v.targetSide,v.target)}}});return{nodes:W,edges:pe}}const Ns=new Set(["name","title","description","shortDescription","longDescription","sourceReference","rationaleText","semantics","queryDescription","dataSourceDescription","doc"]),Ts=7,Mt=80;function _s(t,e){const n=t.attributes[e];return n===void 0?void 0:(n.includes("::")?n.split("::").pop().trim():n)||void 0}function Ps(t){const e=new Map;for(const n of t)for(const o of Object.keys(n.attributes))Ns.has(o)||o.includes(".")||e.set(o,(e.get(o)??0)+1);return[...e.entries()].sort((n,o)=>o[1]-n[1]).slice(0,Ts).map(([n])=>n)}function Fs(t){const e=new Map;for(const o of t)e.has(o.kind)||e.set(o.kind,[]),e.get(o.kind).push(o);const n=[];for(const[o,s]of e){const i=Ps(s),h=s.map(a=>({element:a,values:i.map(y=>_s(a,y))})),u=i.map((a,y)=>{const p=h.map(d=>d.values[y]).filter(d=>d!==void 0);return p.length>0&&p.every(d=>Number.isFinite(Number(d)))});n.push({kind:o,columns:i,numeric:u,rows:h})}return n.sort((o,s)=>s.rows.length-o.rows.length)}function Ds(t,e,n){const o=n==="asc"?1:-1;return[...t.rows].sort((i,h)=>{if(e<0)return i.element.name.localeCompare(h.element.name)*o;const u=i.values[e],a=h.values[e];return u===void 0&&a===void 0?0:u===void 0?1:a===void 0?-1:t.numeric[e]?(Number(u)-Number(a))*o:u.localeCompare(a)*o})}function Rs(t,e,n){const o=new Map(t.map(d=>[d.id,d])),s=n!=null&&n.length?new Set(n.map(d=>d.toLowerCase())):void 0,i=e.filter(d=>o.has(d.sourceId)&&o.has(d.targetId)&&d.sourceId!==d.targetId&&(!s||s.has(d.type.toLowerCase())));if(i.length===0)return;const h=new Set,u=new Set,a=new Map,y=new Set;for(const d of i){h.add(d.sourceId),u.add(d.targetId),y.add(d.type);const x=`${d.sourceId}|${d.targetId}`;a.has(x)||a.set(x,[]),a.get(x).includes(d.type)||a.get(x).push(d.type)}const p=(d,x)=>d.kind.localeCompare(x.kind)||d.name.localeCompare(x.name);return{rows:[...h].map(d=>o.get(d)).sort(p),cols:[...u].map(d=>o.get(d)).sort(p),cells:a,relTypes:[...y].sort()}}const st={padding:"6px 10px",fontSize:ge.xs,fontWeight:600,color:"#374151",textAlign:"left",borderBottom:"2px solid #E5E5E0",background:"#FAFAF8",position:"sticky",top:0,cursor:"pointer",whiteSpace:"nowrap",userSelect:"none"},ot={padding:"5px 10px",fontSize:ge.xs,color:"#374151",borderBottom:"1px solid #F0F0ED",verticalAlign:"top"};function Ls(t){return t.length>Mt?`${t.slice(0,Mt-1)}…`:t}function Bs({section:t,search:e}){var d;const n=nt(x=>x.selectElement),[o,s]=me.useState(-1),[i,h]=me.useState("asc"),u=me.useMemo(()=>{const x=Ds(t,o,i);if(!e)return x;const f=e.toLowerCase();return x.filter(g=>g.element.name.toLowerCase().includes(f)||g.values.some(l=>l==null?void 0:l.toLowerCase().includes(f)))},[t,o,i,e]);if(u.length===0)return null;const a=Be[(d=t.rows[0])==null?void 0:d.element.layer]||"#6B7280",y=x=>{o===x?h(f=>f==="asc"?"desc":"asc"):(s(x),h("asc"))},p=x=>o===x?i==="asc"?" ↑":" ↓":"";return O.jsxs("div",{style:{marginBottom:28},children:[O.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[O.jsx("span",{style:{width:8,height:8,borderRadius:2,background:a,display:"inline-block"}}),O.jsx("span",{style:{fontSize:ge.sm,fontWeight:700,color:"#1B3A4B"},children:t.kind}),O.jsx("span",{style:{fontSize:ge.xs,color:"#9CA3AF"},children:u.length})]}),O.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",background:"#FFFFFF",borderRadius:8,overflow:"hidden",border:"1px solid #E5E5E0"},children:[O.jsx("thead",{children:O.jsxs("tr",{children:[O.jsxs("th",{style:st,onClick:()=>y(-1),children:["Element",p(-1)]}),t.columns.map((x,f)=>O.jsxs("th",{style:st,onClick:()=>y(f),children:[x,p(f)]},x))]})}),O.jsx("tbody",{children:u.map(x=>O.jsxs("tr",{onMouseEnter:f=>{f.currentTarget.style.background="#F7F7F5"},onMouseLeave:f=>{f.currentTarget.style.background="transparent"},children:[O.jsx("td",{style:{...ot,whiteSpace:"nowrap"},children:O.jsx("button",{onClick:()=>n(x.element.id),style:{background:"none",border:"none",padding:0,fontSize:ge.xs,fontWeight:600,color:"#1B6FD9",cursor:"pointer",textDecoration:"none"},title:"Open element detail",children:x.element.name})}),x.values.map((f,g)=>O.jsx("td",{style:ot,title:f&&f.length>Mt?f:void 0,children:f?Ls(f):O.jsx("span",{style:{color:"#D1D5DB"},children:"—"})},g))]},x.element.id))})]})]})}function js({elements:t,model:e,relationshipTypes:n}){const o=nt(h=>h.selectElement),s=me.useMemo(()=>Rs(t,e.relationships,n),[t,e.relationships,n]);if(!s)return O.jsx("div",{style:{color:"#9CA3AF",fontSize:ge.sm,padding:24},children:"No relationships among this view's elements."});const i=(h,u=!1)=>O.jsx("button",{onClick:()=>o(h.id),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontSize:"10px",fontWeight:600,color:"#374151",...u?{writingMode:"vertical-rl",transform:"rotate(180deg)",maxHeight:120}:{},whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:180},title:`${h.kind} · open detail`,children:h.name});return O.jsxs("div",{children:[O.jsx("div",{className:"flex gap-3 mb-2",style:{fontSize:ge.xs,color:"#6B7280"},children:s.relTypes.map(h=>O.jsxs("span",{className:"flex items-center gap-1",children:[O.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:He[h]||"#6B7280",display:"inline-block"}}),h]},h))}),O.jsxs("table",{style:{borderCollapse:"collapse",background:"#FFFFFF",border:"1px solid #E5E5E0"},children:[O.jsx("thead",{children:O.jsxs("tr",{children:[O.jsx("th",{style:{...st,cursor:"default"}}),s.cols.map(h=>O.jsx("th",{style:{...st,cursor:"default",verticalAlign:"bottom",padding:"8px 4px"},children:i(h,!0)},h.id))]})}),O.jsx("tbody",{children:s.rows.map(h=>O.jsxs("tr",{children:[O.jsx("td",{style:{...ot,whiteSpace:"nowrap",background:"#FAFAF8"},children:i(h)}),s.cols.map(u=>{const a=s.cells.get(`${h.id}|${u.id}`);return O.jsx("td",{style:{...ot,textAlign:"center",padding:"4px 6px"},title:a==null?void 0:a.join(", "),children:a==null?void 0:a.map(y=>O.jsx("span",{style:{width:9,height:9,borderRadius:"50%",margin:1,background:He[y]||"#6B7280",display:"inline-block"}},y))},u.id)})]},h.id))})]})]})}function fo({diagram:t,model:e,viewpointFilter:n}){const[o,s]=me.useState("table"),[i,h]=me.useState(""),u=me.useMemo(()=>{const p=Object.values(e.elements);return n?p.filter(n):p},[e,n]),a=me.useMemo(()=>Fs(u),[u]),y=an.grid;return O.jsx("div",{className:"flex-1 overflow-auto",style:{background:"#F7F7F5"},children:O.jsxs("div",{style:{padding:"16px 20px",maxWidth:1240},children:[O.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[O.jsx("span",{className:"px-1.5 py-0.5 rounded font-semibold",style:{background:y.color+"20",color:y.color,fontSize:ge.badge},title:y.fullName,children:y.label}),O.jsx("span",{style:{fontSize:ge.md,fontWeight:700,color:"#1a1a1a"},children:t.name}),O.jsxs("span",{style:{fontSize:ge.xs,color:"#9CA3AF"},children:[u.length," elements"]}),O.jsx("div",{className:"flex rounded overflow-hidden ml-2",style:{border:"1px solid #E5E5E0"},children:["table","matrix"].map(p=>O.jsx("button",{onClick:()=>s(p),className:"px-2 py-0.5 text-xs font-medium capitalize",style:{background:o===p?"#1B3A4B":"#FFFFFF",color:o===p?"#FFFFFF":"#6B7280",border:"none",cursor:"pointer"},children:p},p))}),o==="table"&&O.jsx("input",{value:i,onChange:p=>h(p.target.value),placeholder:"Filter rows…",className:"px-2 py-1 rounded focus:outline-none ml-auto",style:{fontSize:ge.xs,border:"1px solid #E5E5E0",background:"#FFFFFF",color:"#1a1a1a",width:200}})]}),o==="table"?a.map(p=>O.jsx(Bs,{section:p,search:i},p.kind)):O.jsx(js,{elements:u,model:e,relationshipTypes:t.relationshipTypes}),o==="table"&&a.length===0&&O.jsx("div",{style:{color:"#9CA3AF",fontSize:ge.sm,padding:24},children:"This view selects no elements."})]})})}const Ws=8;function wn(t,e,n){const o=(e.get(t.id)??[]).filter(s=>n.has(s)).map(s=>wn(n.get(s),e,n));return o.sort(tt),{id:t.id,label:t.name,element:t,kind:t.kind,layer:t.layer,children:o,count:1+o.reduce((s,i)=>s+i.count,0)}}const tt=(t,e)=>(t.kind??"").localeCompare(e.kind??"")||t.label.localeCompare(e.label);function Hs(t,e){const n=rt(t,e),o=new Map,s=[];for(const i of n.roots){const h=n.elements.get(i),u=wn(h,n.childrenMap,n.elements),a=h.package;if(!a){s.push(u);continue}if(!o.has(a)){const p=a.split("::").pop()??a,d={id:`pkg:${a}`,label:p,title:a,children:[],count:0};o.set(a,d),s.push(d)}const y=o.get(a);y.children.push(u),y.count+=u.count}for(const i of o.values()){const h=new Set(i.children.map(a=>a.kind));if(i.children.length<=Ws||h.size<=1){i.children.sort(tt);continue}const u=new Map;for(const a of i.children){const y=a.kind??"—";u.has(y)||u.set(y,[]),u.get(y).push(a)}i.children=[...u.entries()].sort((a,y)=>a[0].localeCompare(y[0])).map(([a,y])=>{var p;return{id:`kind:${i.id}:${a}`,label:a,kind:a,layer:(p=y[0])==null?void 0:p.layer,children:y.sort(tt),count:y.reduce((d,x)=>d+x.count,0)}})}return s.sort(tt),s}function zs(t,e){const n=e.trim().toLowerCase();if(!n)return;const o=new Set,s=new Set,i=(h,u)=>{const a=h.label.toLowerCase().includes(n)||(h.kind??"").toLowerCase().includes(n);let y=!1;for(const p of h.children)i(p,[...u,h.id])&&(y=!0);if(a||y){o.add(h.id);for(const p of u)o.add(p),s.add(p);return y&&s.add(h.id),!0}return!1};for(const h of t)i(h,[]);return{visible:o,expanded:s}}function Gs(t){if(!t)return"·";const e=t.replace(/[^A-Za-z]/g,"").match(/[A-Z]/g);return e&&e.length>=2?e.slice(0,2).join(""):t.slice(0,2).toUpperCase()}const $s=26;function In({node:t,depth:e,expanded:n,visible:o,forceExpanded:s,onToggle:i}){const h=nt(f=>f.selectElement),u=nt(f=>f.selectedElementId);if(o&&!o.has(t.id))return null;const a=n.has(t.id)||!!(s!=null&&s.has(t.id)),y=t.children.length>0,p=!t.element,d=Be[t.layer??""]||"#95A5A6",x=t.element&&t.id===u;return O.jsxs(O.Fragment,{children:[O.jsxs("div",{className:"flex items-center gap-1.5",style:{height:$s,paddingLeft:8+e*18,cursor:"pointer",background:x?"#2DD4A818":void 0,borderRadius:6},onMouseEnter:f=>{x||(f.currentTarget.style.background="#F0F0ED")},onMouseLeave:f=>{f.currentTarget.style.background=x?"#2DD4A818":"transparent"},onClick:()=>{y&&i(t.id),t.element&&h(t.id)},title:t.title??t.kind,children:[O.jsx("span",{style:{width:12,textAlign:"center",flexShrink:0,fontSize:"9px",color:"#9CA3AF",transform:a?"rotate(90deg)":"none",transition:"transform 120ms ease",visibility:y?"visible":"hidden"},children:"▶"}),p?O.jsx("span",{style:{fontSize:"10px",flexShrink:0},children:t.id.startsWith("pkg:")?"📦":"▣"}):O.jsx("span",{style:{flexShrink:0,width:20,height:16,borderRadius:4,background:d+"22",color:d,fontSize:"8px",fontWeight:800,display:"inline-flex",alignItems:"center",justifyContent:"center",letterSpacing:"0.02em"},title:t.kind,children:Gs(t.kind)}),O.jsx("span",{style:{fontSize:ge.xs,fontWeight:p?700:500,color:p?"#1B3A4B":"#374151",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t.label}),y&&O.jsx("span",{style:{fontSize:"9px",color:"#9CA3AF"},children:t.count})]}),a&&t.children.map(f=>O.jsx(In,{node:f,depth:e+1,expanded:n,visible:o,forceExpanded:s,onToggle:i},f.id))]})}function yo({diagram:t,model:e,viewpointFilter:n}){const[o,s]=me.useState(new Set),[i,h]=me.useState(""),u=me.useMemo(()=>{const g=Object.values(e.elements);return n?g.filter(n):g},[e,n]),a=me.useMemo(()=>Hs(u,e.relationships),[u,e.relationships]),y=me.useMemo(()=>zs(a,i),[a,i]),p=me.useCallback(g=>{s(l=>{const c=new Set(l);return c.has(g)?c.delete(g):c.add(g),c})},[]),d=me.useCallback((g,l)=>{for(const c of g)c.children.length>0&&(l.add(c.id),d(c.children,l));return l},[]),x=an.browser,f=u.length;return O.jsx("div",{className:"flex-1 overflow-auto",style:{background:"#F7F7F5"},children:O.jsxs("div",{style:{padding:"16px 20px",maxWidth:860},children:[O.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[O.jsx("span",{className:"px-1.5 py-0.5 rounded font-semibold",style:{background:x.color+"20",color:x.color,fontSize:ge.badge},title:x.fullName,children:x.label}),O.jsx("span",{style:{fontSize:ge.md,fontWeight:700,color:"#1a1a1a"},children:t.name}),O.jsxs("span",{style:{fontSize:ge.xs,color:"#9CA3AF"},children:[f," elements"]}),O.jsx("button",{onClick:()=>s(d(a,new Set)),className:"px-2 py-0.5 text-xs font-medium rounded ml-2",style:{background:"#FFFFFF",color:"#374151",border:"1px solid #E5E5E0",cursor:"pointer"},children:"Expand All"}),O.jsx("button",{onClick:()=>s(new Set),className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#FFFFFF",color:"#374151",border:"1px solid #E5E5E0",cursor:"pointer"},children:"Collapse All"}),O.jsx("input",{value:i,onChange:g=>h(g.target.value),placeholder:"Filter by name or kind…",className:"px-2 py-1 rounded focus:outline-none ml-auto",style:{fontSize:ge.xs,border:"1px solid #E5E5E0",background:"#FFFFFF",color:"#1a1a1a",width:220}})]}),O.jsxs("div",{style:{background:"#FFFFFF",border:"1px solid #E5E5E0",borderRadius:10,padding:"10px 8px"},children:[a.length===0&&O.jsx("div",{style:{color:"#9CA3AF",fontSize:ge.sm,padding:16},children:"This view selects no elements."}),a.map(g=>O.jsx(In,{node:g,depth:0,expanded:o,visible:y==null?void 0:y.visible,forceExpanded:y==null?void 0:y.expanded,onToggle:p},g.id)),y&&a.every(g=>!y.visible.has(g.id))&&O.jsxs("div",{style:{color:"#9CA3AF",fontSize:ge.sm,padding:16},children:["No matches for “",i,"”."]})]})]})})}function po({x:t,y:e,sourceElement:n,targetElement:o,registries:s,onSelect:i,onCancel:h}){const u=me.useRef(null),[a,y]=me.useState(""),p=me.useRef(null);me.useEffect(()=>{var M;(M=p.current)==null||M.focus()},[]),me.useEffect(()=>{const M=b=>{u.current&&!u.current.contains(b.target)&&h()};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[h]),me.useEffect(()=>{const M=b=>{b.key==="Escape"&&h()};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[h]);const d=me.useMemo(()=>bn(n,o,s),[n,o,s]),x=me.useMemo(()=>{const M=a.trim().toLowerCase();return M?d.filter(b=>b.definition.label.toLowerCase().includes(M)||b.definition.name.toLowerCase().includes(M)):d},[d,a]),f=260,g=320,l=Math.min(t,window.innerWidth-f-8),c=Math.min(e,window.innerHeight-g-8);return O.jsxs("div",{ref:u,className:"fixed z-50 flex flex-col shadow-xl rounded-xl overflow-hidden",style:{left:l,top:c,width:f,maxHeight:g,background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 8px 32px rgba(0,0,0,0.16)"},children:[O.jsxs("div",{className:"px-3 py-2",style:{borderBottom:"1px solid #E5E5E0",flexShrink:0},children:[O.jsx("div",{style:{fontSize:ge.xs,fontWeight:600,color:"#374151",marginBottom:4},children:"Relationship Type"}),O.jsxs("div",{style:{fontSize:"10px",color:"#9CA3AF",marginBottom:4},children:[n.kind," → ",o.kind]}),O.jsx("input",{ref:p,value:a,onChange:M=>y(M.target.value),placeholder:"Search…","aria-label":"Search relationship types",className:"w-full px-2 py-1 rounded focus:outline-none",style:{fontSize:ge.xs,background:"#F7F7F5",border:"1px solid #E5E5E0",color:"#374151"}})]}),O.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[x.map(M=>{const{definition:b,direction:E,sourceId:S,targetId:N}=M,T=E==="incoming";return O.jsxs("button",{onClick:()=>i({type:b.name,sourceId:S,targetId:N,direction:E}),className:"w-full flex items-center gap-2.5 px-3 py-1.5 text-left",style:{background:"none",border:"none",cursor:"pointer"},onMouseEnter:G=>{G.currentTarget.style.background="#F7F7F5"},onMouseLeave:G=>{G.currentTarget.style.background="none"},children:[O.jsx("div",{style:{width:10,height:10,borderRadius:"50%",flexShrink:0,background:He[b.name]??"#6B7280"}}),O.jsxs("div",{style:{minWidth:0},children:[O.jsxs("div",{style:{fontSize:ge.xs,fontWeight:500,color:"#1a1a1a"},children:[b.label,T&&O.jsx("span",{style:{color:"#9CA3AF",fontWeight:400},children:" (reversed)"})]}),O.jsxs("div",{className:"truncate",style:{fontSize:"10px",color:"#9CA3AF"},children:[b.sourceEnd.name," → ",b.targetEnd.name]})]})]},`${b.name}-${E}`)}),x.length===0&&O.jsx("div",{className:"p-3 text-center",style:{color:"#9CA3AF",fontSize:ge.xs},children:d.length===0?`The ontology defines no relationship between a ${n.kind} and a ${o.kind}.`:"No matching types"})]})]})}function mo(t){var e,n,o;return((o=(n=(e=t)==null?void 0:e.canvas)==null?void 0:n.layout)==null?void 0:o.provider)??Mn}export{qe as A,yo as B,Ve as C,Zs as G,to as I,eo as P,po as R,Dn as a,Rn as b,qs as c,ho as d,uo as e,no as f,ro as g,io as h,go as i,Qs as j,Fn as k,Ft as l,co as m,oo as n,so as o,cs as p,lo as q,Js as r,mo as s,jn as t,ao as u,Vs as v,Ln as w,gn as x,fo as y,Wn as z};
|