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