@memoarchitect/architect 0.7.2 → 0.8.26

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.
Files changed (71) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/{AiWorkspace-Bu9TlIWg.js → AiWorkspace-Z3BbnmaP.js} +1 -1
  3. package/dist/assets/{AnalysisWorkspace-CodmoI-v.js → AnalysisWorkspace-DjaUOo7U.js} +1 -1
  4. package/dist/assets/{ComplianceWizard-CTihkUi-.js → ComplianceWizard-DKxZ1z25.js} +1 -1
  5. package/dist/assets/DSMView-DJhmrXYm.js +5 -0
  6. package/dist/assets/Dashboard-CYT7KjqU.js +1 -0
  7. package/dist/assets/DhfDashboard-DacdOtkU.js +1 -0
  8. package/dist/assets/DhfWorkbench-CIhopT8J.js +69 -0
  9. package/dist/assets/DiagramCanvas-CLE_nv7Y.js +4 -0
  10. package/dist/assets/{DiagramEditor-UJDHcAUF.js → DiagramEditor-puQuE8gB.js} +2 -2
  11. package/dist/assets/DiagramToolbarControls-XMGLx08e.js +1 -0
  12. package/dist/assets/{ElementDetailView-10U0rr33.js → ElementDetailView-D5XvAL_i.js} +1 -1
  13. package/dist/assets/ExplorerTreeRow-DUmcEsqf.js +3 -0
  14. package/dist/assets/{ImportView-D8svP04Q.js → ImportView-9y1nhQS4.js} +1 -1
  15. package/dist/assets/{LayerGrid-DEe0Ryz-.js → LayerGrid-bhFpOIbe.js} +1 -1
  16. package/dist/assets/{LayerTable-CN_b2rDr.js → LayerTable-RuswZVUI.js} +1 -1
  17. package/dist/assets/{MaxGraphCanvas-bo8oPBct.js → MaxGraphCanvas-D3BXQK2y.js} +1 -1
  18. package/dist/assets/{ModelDiff-xe95oVua.js → ModelDiff-Cl2dhlk3.js} +1 -1
  19. package/dist/assets/{OntologyDecompositionDiagram-BL9R8bdB.js → OntologyDecompositionDiagram-aONGngg4.js} +1 -1
  20. package/dist/assets/{OntologyViewer-CtqNkkCn.js → OntologyViewer-VOrKTRuQ.js} +2 -2
  21. package/dist/assets/{RelationshipOverlay-DL0N8Vmk.js → RelationshipOverlay-B3AN-bM-.js} +1 -1
  22. package/dist/assets/{RelationshipsSection-BoJ0aUXe.js → RelationshipsSection-DggeGBKP.js} +1 -1
  23. package/dist/assets/{ReviewDashboard-DeTge2oC.js → ReviewDashboard--LMXZ3F4.js} +1 -1
  24. package/dist/assets/{ScenarioEditor-FAEYTHgP.js → ScenarioEditor-bB4iBbgO.js} +1 -1
  25. package/dist/assets/{StatisticsDashboard-BAZRqIPN.js → StatisticsDashboard-iXimfU20.js} +1 -1
  26. package/dist/assets/{SysmlCodeEditor-BBfup_Ni.js → SysmlCodeEditor-i0BHj3of.js} +117 -117
  27. package/dist/assets/{TabularView-I4LjHhoH.js → TabularView-DnIfq-TB.js} +1 -1
  28. package/dist/assets/TraceabilityMatrix-eilGn6Sr.js +3 -0
  29. package/dist/assets/UiScreensWorkspace-Cs1ivqzc.js +1 -0
  30. package/dist/assets/{WorkflowWizard-VwpEHt3R.js → WorkflowWizard-C7jI6C59.js} +1 -1
  31. package/dist/assets/index-CG-gfw-s.js +4067 -0
  32. package/dist/assets/index-DXB4CKwW.css +1 -0
  33. package/dist/assets/{index.es-ClbJxlAQ.js → index.es-DABt8CUc.js} +1 -1
  34. package/dist/assets/{jspdf.es.min-DZ68BGxk.js → jspdf.es.min-G-Vwo9yG.js} +3 -3
  35. package/dist/assets/{layout-providers-Dr743WlP.js → layout-providers-BSDYNZu0.js} +1 -1
  36. package/dist/assets/notation-scene-DLZms6VR.js +1 -0
  37. package/dist/assets/{reactflow-s7jmJtXx.js → reactflow-C9OlmOYw.js} +1 -1
  38. package/dist/assets/xlsx-CkFp8p6R.js +105 -0
  39. package/dist/index.html +3 -3
  40. package/dist-standalone/index.html +5504 -0
  41. package/lib/__tests__/standalone-distribution.test.d.ts +2 -0
  42. package/lib/__tests__/standalone-distribution.test.d.ts.map +1 -0
  43. package/lib/__tests__/standalone-distribution.test.js +51 -0
  44. package/lib/__tests__/standalone-distribution.test.js.map +1 -0
  45. package/lib/__tests__/supervised-child-args.test.js +21 -1
  46. package/lib/__tests__/supervised-child-args.test.js.map +1 -1
  47. package/lib/commands/build.d.ts.map +1 -1
  48. package/lib/commands/build.js +15 -18
  49. package/lib/commands/build.js.map +1 -1
  50. package/lib/commands/dev.d.ts +14 -0
  51. package/lib/commands/dev.d.ts.map +1 -1
  52. package/lib/commands/dev.js +40 -1
  53. package/lib/commands/dev.js.map +1 -1
  54. package/lib/feature-grants.d.ts.map +1 -1
  55. package/lib/feature-grants.js +3 -1
  56. package/lib/feature-grants.js.map +1 -1
  57. package/package.json +10 -6
  58. package/dist/assets/DSMView-BiC845df.js +0 -1
  59. package/dist/assets/Dashboard-CgnNLhKq.js +0 -1
  60. package/dist/assets/DhfDashboard-w-dJoJHU.js +0 -1
  61. package/dist/assets/DhfWorkbench-o6B_MT-0.js +0 -69
  62. package/dist/assets/DiagramCanvas-CqGqDbgT.js +0 -3
  63. package/dist/assets/DiagramToolbarControls-B2gZFJlg.js +0 -1
  64. package/dist/assets/ExplorerTreeRow-DqhF_qoO.js +0 -3
  65. package/dist/assets/TraceabilityMatrix-DbrvjqLN.js +0 -3
  66. package/dist/assets/UiScreensWorkspace-DDD_PyJs.js +0 -1
  67. package/dist/assets/editor.worker-DyuDvpVp.js +0 -26
  68. package/dist/assets/element-options-B7AgTB8R.js +0 -3
  69. package/dist/assets/index-BWMNo4wW.css +0 -1
  70. package/dist/assets/index-Bij8Q4Kg.js +0 -45
  71. package/dist/assets/notation-scene-DT8LpWVK.js +0 -1
@@ -1 +0,0 @@
1
- var oo=Object.defineProperty;var so=(e,t,n)=>t in e?oo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var fe=(e,t,n)=>so(e,typeof t!="symbol"?t+"":t,n);import{h as Ht,N as nt,K as qt,O as sn,F as rt,Q as ie,S as $e,T as Gt,U as Vt,V as Dn,u as de,j as io}from"./index-Bij8Q4Kg.js";import{u as Pn,j as k,H as Pt,P as dt}from"./reactflow-s7jmJtXx.js";import{a as ct}from"./zustand-CrhqMOHB.js";import{r as ro,D as ao}from"./layout-providers-Dr743WlP.js";import{E as co}from"./ExplorerTreeRow-DqhF_qoO.js";const he=new Set(["composedOf","composes","decomposedBy","aggregation"]);function De(e,t,n=he){const s=new Map;for(const a of e)s.set(a.id,a);const o=new Map,r=new Set;for(const a of t)n.has(a.type)&&(!s.has(a.sourceId)||!s.has(a.targetId)||a.sourceId!==a.targetId&&(r.has(a.targetId)||(o.has(a.sourceId)||o.set(a.sourceId,[]),o.get(a.sourceId).push(a.targetId),r.add(a.targetId))));return{roots:[...s.keys()].filter(a=>!r.has(a)),childrenMap:o,elements:s}}function ni(e,t){const n=[],s=(o,r,i)=>{const a=e.childrenMap.get(o)??[];a.length>0&&r>=t&&n.push(o);for(const c of a)i.has(c)||(i.add(c),s(c,r+1,i))};for(const o of e.roots)s(o,0,new Set([o]));return n}function oi(e){if(e.elements.size===0)return null;const t=new Set,n=o=>{if(!t.has(o)){t.add(o);for(const r of e.childrenMap.get(o)??[])n(r)}};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 lo=new Set(["name","title","description","shortDescription","longDescription","sourceReference","rationaleText","semantics","protocolSemantics","queryDescription","dataSourceDescription","documentUsage","doc"]);function ho(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(lo.has(s)||s.includes(".")||s==="id"&&n.some(i=>i.key==="id"))continue;const r=o.split("::").pop().trim();!r||r.length>28||n.push({key:s,value:r})}return n.slice(0,t)}const oe={layout:(e,t)=>ro(e,t)},go=(e,t,n,s=10)=>{const o=n.x-s,r=n.x+n.width+s,i=n.y-s,a=n.y+n.height+s;return e.y===t.y?e.y>=i&&e.y<=a&&Math.max(e.x,t.x)>=o&&Math.min(e.x,t.x)<=r:e.x===t.x?e.x>=o&&e.x<=r&&Math.max(e.y,t.y)>=i&&Math.min(e.y,t.y)<=a:!1},Ln=(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,Rn=(e,t,n,s)=>{const o=e.y===t.y,r=n.y===s.y;if(o===r)return!1;const i=o?e:n,a=o?t:s,c=o?n:e,l=o?s:t;return c.x>Math.min(i.x,a.x)&&c.x<Math.max(i.x,a.x)&&i.y>Math.min(c.y,l.y)&&i.y<Math.max(c.y,l.y)},jn=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},ne=160,$n=(e,t)=>e*73856093^t*19349663;function Te(e,t,n,s,o){const r=Math.floor(e/ne),i=Math.floor(n/ne),a=Math.floor(t/ne),c=Math.floor(s/ne);for(let l=r;l<=i;l++)for(let f=a;f<=c;f++)o($n(l,f))}class uo{constructor(t,n){fe(this,"buckets",new Map);this.pad=n;for(const s of t)Te(s.x-n,s.y-n,s.x+s.width+n,s.y+s.height+n,o=>{const r=this.buckets.get(o);r?r.push(s):this.buckets.set(o,[s])})}contains(t){const n=this.buckets.get($n(Math.floor(t.x/ne),Math.floor(t.y/ne)));if(!n)return!1;for(const s of n)if(t.x>s.x-this.pad&&t.x<s.x+s.width+this.pad&&t.y>s.y-this.pad&&t.y<s.y+s.height+this.pad)return!0;return!1}blocks(t,n,s){let o=!1;return Te(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.max(t.x,n.x),Math.max(t.y,n.y),r=>{if(o)return;const i=this.buckets.get(r);if(i){for(const a of i)if(go(t,n,a,s)){o=!0;return}}}),o}}const fo=4e3,po=600;class yo{constructor(){fe(this,"buckets",new Map);fe(this,"query",0)}add(t,n){const s={a:t,b:n,seen:0};Te(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.max(t.x,n.x),Math.max(t.y,n.y),o=>{const r=this.buckets.get(o);r?r.push(s):this.buckets.set(o,[s])})}penalty(t,n){const s=++this.query;let o=0;return Te(Math.min(t.x,n.x),Math.min(t.y,n.y),Math.max(t.x,n.x),Math.max(t.y,n.y),r=>{const i=this.buckets.get(r);if(i)for(const a of i)a.seen!==s&&(a.seen=s,Ln(t,n,a.a,a.b)?o+=fo:Rn(t,n,a.a,a.b)&&(o+=po))}),o}}const mo=2e4;function xo(e,t){e.push(t);for(let n=e.length-1;n>0;){const s=n-1>>1;if(e[s].f<=e[n].f)break;[e[s],e[n]]=[e[n],e[s]],n=s}}function wo(e){const t=e[0],n=e.pop();if(e.length>0&&n!==void 0){e[0]=n;for(let s=0;;){const o=s*2+1,r=o+1;let i=s;if(o<e.length&&e[o].f<e[i].f&&(i=o),r<e.length&&e[r].f<e[i].f&&(i=r),i===s)break;[e[i],e[s]]=[e[s],e[i]],s=i}}return t}function Bn(e){const t=e.filter((n,s)=>s===0||Math.abs(n.x-e[s-1].x)>.01||Math.abs(n.y-e[s-1].y)>.01);return t.filter((n,s)=>s===0||s===t.length-1||!(t[s-1].x===n.x&&n.x===t[s+1].x||t[s-1].y===n.y&&n.y===t[s+1].y))}const pe=e=>e==="left"||e==="right";function Hn(e){const{source:t,target:n,sourceSide:s,targetSide:o}=e,r=Math.abs(t.x-n.x)+Math.abs(t.y-n.y),i=Math.min(jn,r/3),a=s&&i>.5?Fe(t,s,i):t,c=o&&i>.5?Fe(n,o,i):n,l=Math.abs(a.x-c.x)<.5||Math.abs(a.y-c.y)<.5?[]:pe(s)===pe(o)?pe(s)||!s?[{x:(a.x+c.x)/2,y:a.y},{x:(a.x+c.x)/2,y:c.y}]:[{x:a.x,y:(a.y+c.y)/2},{x:c.x,y:(a.y+c.y)/2}]:pe(s)?[{x:c.x,y:a.y}]:[{x:a.x,y:c.y}];return Bn([t,a,...l,c,n])}function si(e){return new Map(e.map(t=>[t.id,Hn(t)]))}function ge(e,t,n=18,s="long-first"){const o=new Map,r=new yo,i=Math.max(12,n*.75),a=[...e].sort((c,l)=>(s==="long-first"?1:-1)*(Math.abs(l.source.x-l.target.x)+Math.abs(l.source.y-l.target.y)-(Math.abs(c.source.x-c.target.x)+Math.abs(c.source.y-c.target.y))));for(const c of a){const{source:l,target:f}=c,h=Math.abs(l.x-f.x)+Math.abs(l.y-f.y),x=Math.min(jn,h/3),m=!!c.sourceSide&&x>.5,p=!!c.targetSide&&x>.5,y=m?Fe(l,c.sourceSide,x):l,d=p?Fe(f,c.targetSide,x):f,b=(C,D)=>D.x>C.x-i&&D.x<C.x+C.width+i&&D.y>C.y-i&&D.y<C.y+C.height+i,I=Math.max(240,h*.35),v=C=>C.x+C.width>=Math.min(l.x,f.x)-I&&C.x<=Math.max(l.x,f.x)+I&&C.y+C.height>=Math.min(l.y,f.y)-I&&C.y<=Math.max(l.y,f.y)+I,A=t.filter(C=>C.id!==c.sourceNodeId&&C.id!==c.targetNodeId&&v(C)&&!b(C,l)&&!b(C,f)),E=new Set([y.x,d.x,(y.x+d.x)/2,y.x-n,y.x+n,d.x-n,d.x+n]),R=new Set([y.y,d.y,(y.y+d.y)/2,y.y-n,y.y+n,d.y-n,d.y+n]);for(const C of A)E.add(C.x-i),E.add(C.x+C.width+i),R.add(C.y-i),R.add(C.y+C.height+i);const U=[...E].sort((C,D)=>C-D),Z=[...R].sort((C,D)=>C-D),G=[],q=new Map,tt=(C,D)=>`${C.toFixed(3)}:${D.toFixed(3)}`,wt=new uo(A,i),ht=C=>wt.contains(C);for(const C of Z)for(const D of U){const H={x:D,y:C};ht(H)&&tt(D,C)!==tt(y.x,y.y)&&tt(D,C)!==tt(d.x,d.y)||(q.set(tt(D,C),G.length),G.push(H))}const et=new Map,Ct=(C,D)=>{et.has(C)||et.set(C,[]),et.has(D)||et.set(D,[]),et.get(C).push(D),et.get(D).push(C)},kt=(C,D)=>!wt.blocks(C,D,i-1);for(const C of Z){const D=U.map(H=>q.get(tt(H,C))).filter(H=>H!==void 0);for(let H=1;H<D.length;H++)kt(G[D[H-1]],G[D[H]])&&Ct(D[H-1],D[H])}for(const C of U){const D=Z.map(H=>q.get(tt(C,H))).filter(H=>H!==void 0);for(let H=1;H<D.length;H++)kt(G[D[H-1]],G[D[H]])&&Ct(D[H-1],D[H])}const Y=q.get(tt(y.x,y.y)),Ft=q.get(tt(d.x,d.y)),It=(C,D)=>`${C}:${D}`,pt=Y===void 0?[]:[{node:Y,dir:"N",g:0,f:Math.abs(y.x-d.x)+Math.abs(y.y-d.y)}],lt=new Map(Y===void 0?[]:[[It(Y,"N"),0]]),St=new Map;pt[0]&&St.set(It(pt[0].node,pt[0].dir),pt[0]);let _t;const yt=(C,D,H)=>!H||H==="left"&&D.x<C.x||H==="right"&&D.x>C.x||H==="top"&&D.y<C.y||H==="bottom"&&D.y>C.y,bt=(C,D,H)=>!H||(H==="left"?D.x<=C.x:H==="right"?D.x>=C.x:H==="top"?D.y<=C.y:D.y>=C.y),vt=m?bt:yt,M=p?bt:yt;let j=0;for(;pt.length>0;){const C=wo(pt);if(C.node===Ft){_t=C;break}if(++j>mo)break;for(const D of et.get(C.node)??[]){const H=G[C.node],mt=G[D];if(C.node===Y&&!vt(H,mt,c.sourceSide)||D===Ft&&!M(mt,H,c.targetSide))continue;const Dt=H.y===mt.y?"H":"V",w=Math.abs(H.x-mt.x)+Math.abs(H.y-mt.y);let O=C.dir!=="N"&&C.dir!==Dt?90:0;O+=r.penalty(H,mt);const B=Math.abs(H.x-d.x)+Math.abs(H.y-d.y),W=Math.abs(mt.x-d.x)+Math.abs(mt.y-d.y);W>B&&(O+=(W-B)*1.5);const g=C.g+w+O,T=It(D,Dt);if(g>=(lt.get(T)??Number.POSITIVE_INFINITY))continue;const F={node:D,dir:Dt,g,f:g+W,parent:It(C.node,C.dir)};lt.set(T,g),St.set(T,F),xo(pt,F)}}const $=[];if(_t){let C=_t;for(;C;)$.push(G[C.node]),C=C.parent?St.get(C.parent):void 0;$.reverse(),m&&$.unshift(l),p&&$.push(f)}const K=$.length>=2?Bn($):Hn(c);o.set(c.id,K);for(let C=1;C<K.length;C++)r.add(K[C-1],K[C])}return o}const rn=(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},bo=(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 Pe(e,t){var a;const n=new Map,s=[],o=c=>c.slice(1).reduce((l,f,h)=>l+Math.abs(f.x-c[h].x)+Math.abs(f.y-c[h].y),0),r=e.flatMap(c=>c.points.slice(1).map((l,f)=>({edgeId:c.id,a:c.points[f],b:l}))),i=[...e].sort((c,l)=>o(l.points)-o(c.points));for(const c of i){const{points:l,width:f,height:h}=c;if(l.length<2)continue;const x=[];for(let y=1;y<l.length;y++){const d=l[y-1],b=l[y],I=Math.abs(b.x-d.x)+Math.abs(b.y-d.y),v=Math.abs(b.x-d.x)>=Math.abs(b.y-d.y),A=h/2+4;for(const E of I>=f*1.5?[.5,.3,.7]:[.5,.25,.75]){const R={x:d.x+(b.x-d.x)*E,y:d.y+(b.y-d.y)*E};for(const U of[-1,1])x.push({center:v?{x:R.x,y:R.y+U*A}:{x:R.x+U*(f/2+4),y:R.y},segmentLength:I})}}let m=((a=x[0])==null?void 0:a.center)??l[0],p=Number.POSITIVE_INFINITY;for(const y of x){const d={x:y.center.x-f/2,y:y.center.y-h/2,width:f,height:h};let b=0;for(const I of s)b+=rn(d,I)*3;for(const I of t)b+=rn(d,I)*4;for(const I of r)I.edgeId!==c.id&&(b+=bo(I.a,I.b,d)*12*2.5);b+=Math.max(0,f*1.4-y.segmentLength)*2,b<p&&(p=b,m=y.center)}n.set(c.id,m),s.push({x:m.x-f/2,y:m.y-h/2,width:f,height:h})}return n}const Le=20,Re=e=>e.length*6.4+12;function Io(e){const{connectors:t,rects:n}=e,s=e.obstacles??[...n.entries()].map(([m,p])=>({id:m,...p})),o=[],r=new Map;for(const m of t){const p=n.get(m.sourceId),y=n.get(m.targetId);if(!p||!y||m.sourceId===m.targetId)continue;const d=E=>({x:E.x+E.width/2,y:E.y+E.height/2}),b=Math.abs(d(y).x-d(p).x)>=Math.abs(d(y).y-d(p).y),I=b?d(y).x>=d(p).x:d(y).y>=d(p).y,v=b?I?"right":"left":I?"bottom":"top",A=b?I?"left":"right":I?"top":"bottom";r.set(m.id,{source:v,target:A}),o.push({connectorId:m.id,nodeId:m.sourceId,side:v,otherCentre:d(y)}),o.push({connectorId:m.id,nodeId:m.targetId,side:A,otherCentre:d(p)})}const i=new Map,a=(m,p)=>`${m}\0${p}`,c=new Map;for(const m of o){const p=`${m.nodeId}\0${m.side}`;c.set(p,[...c.get(p)??[],m])}for(const m of c.values()){const p=n.get(m[0].nodeId),y=m[0].side==="left"||m[0].side==="right",d=[...m].sort((v,A)=>y?v.otherCentre.y-A.otherCentre.y:v.otherCentre.x-A.otherCentre.x),b=(y?p.height:p.width)*.7,I=(y?p.y+p.height/2:p.x+p.width/2)-b/2;d.forEach((v,A)=>{const E=d.length===1?(y?p.height:p.width)/2:I+b*(A/(d.length-1))-(y?p.y:p.x);i.set(a(v.connectorId,v.nodeId),{x:v.side==="left"?p.x:v.side==="right"?p.x+p.width:p.x+(y?p.width/2:E),y:v.side==="top"?p.y:v.side==="bottom"?p.y+p.height:p.y+(y?E:p.height/2)})})}const l=[];for(const m of t){const p=r.get(m.id);p&&l.push({id:m.id,source:i.get(a(m.id,m.sourceId)),target:i.get(a(m.id,m.targetId)),sourceNodeId:m.sourceId,targetNodeId:m.targetId,sourceSide:p.source,targetSide:p.target})}const f=ge(l,s,e.channelGap),h=Pe(t.flatMap(m=>{const p=f.get(m.id);return m.label&&p&&p.length>=2?[{id:m.id,points:p,width:Re(m.label),height:Le}]:[]}),s),x=new Map;for(const[m,p]of f)x.set(m,{points:p,labelPoint:h.get(m)});return x}function So(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 Mo(e,t=1.25){return e<=1?Math.max(e,1):Math.min(e,Math.max(2,Math.round(Math.sqrt(e*t))))}function Wn(e,t){const n=new Set(e.map(l=>l.id)),s=new Map,o=new Map(e.map(l=>[l.id,0]));for(const l of t)!n.has(l.source)||!n.has(l.target)||l.source===l.target||(s.has(l.source)||s.set(l.source,[]),s.get(l.source).push(l.target),o.set(l.target,(o.get(l.target)??0)+1));const r=e.map(l=>l.id),i=r.filter(l=>(o.get(l)??0)===0),a=[],c=new Set;for(;i.length;){const l=i.shift();if(!c.has(l)){c.add(l),a.push(l);for(const f of s.get(l)??[])o.set(f,(o.get(f)??1)-1),o.get(f)===0&&i.push(f)}}for(const l of r)c.has(l)||a.push(l);return a}function vo(e,t,n,s,o){const r=new Map(e.map(y=>[y.id,y])),i=Wn(e,t).map(y=>r.get(y)),a=Mo(e.length,o),c=Math.ceil(e.length/a),l=i.map((y,d)=>{const b=Math.floor(d/a),I=d%a,v=b%2===0?I:a-1-I;return{node:y,row:b,col:v}}),f=Array.from({length:a},()=>0),h=Array.from({length:c},()=>0);for(const{node:y,row:d,col:b}of l)f[b]=Math.max(f[b],y.width),h[d]=Math.max(h[d],y.height);const x=f.map((y,d)=>d===0?0:f.slice(0,d).reduce((b,I)=>b+I,0)+n*d),m=h.map((y,d)=>d===0?0:h.slice(0,d).reduce((b,I)=>b+I,0)+s*d),p=l.map(({node:y,row:d,col:b})=>({...y,x:x[b]+(f[b]-y.width)/2,y:m[d]+(h[d]-y.height)/2}));return{strategy:"balanced-board",width:f.reduce((y,d)=>y+d,0)+n*Math.max(a-1,0),height:h.reduce((y,d)=>y+d,0)+s*Math.max(c-1,0),children:p}}function Eo(e,t,n,s){const o={x:e.x+e.width/2,y:e.y+e.height/2},r={x:t.x+t.width/2,y:t.y+t.height/2},i={x:n.x+n.width/2,y:n.y+n.height/2},a={x:s.x+s.width/2,y:s.y+s.height/2},c=(l,f,h)=>(f.x-l.x)*(h.y-l.y)-(f.y-l.y)*(h.x-l.x);return c(o,r,i)*c(o,r,a)<0&&c(i,a,o)*c(i,a,r)<0}function ko(e,t,n=1.5){const s=new Map(e.children.map(p=>[p.id,p]));let o=0,r=0,i=0,a=0;const c=t.filter(p=>s.has(p.source)&&s.has(p.target));for(const p of c){const y=s.get(p.source),d=s.get(p.target);o+=Math.abs(y.x+y.width/2-(d.x+d.width/2))+Math.abs(y.y+y.height/2-(d.y+d.height/2));const b=d.x+d.width/2-(y.x+y.width/2),I=Math.abs(d.y+d.height/2-(y.y+y.height/2));b<=0&&(i+=55e3),i+=Math.max(0,I-Math.max(b,0))*80,Math.abs(b)>8&&I>8&&(a+=18e3)}for(let p=0;p<c.length;p++)for(let y=p+1;y<c.length;y++){const d=c[p],b=c[y];d.source===b.source||d.source===b.target||d.target===b.source||d.target===b.target||Eo(s.get(d.source),s.get(d.target),s.get(b.source),s.get(b.target))&&r++}const l=ge(c.map(p=>{const y=s.get(p.source),d=s.get(p.target);return{id:p.id,source:{x:y.x+y.width,y:y.y+y.height/2},target:{x:d.x,y:d.y+d.height/2},sourceNodeId:p.source,targetNodeId:p.target,sourceSide:"right",targetSide:"left"}}),e.children);let f=0,h=0,x=0;const m=[];for(const[p,y]of l){h+=Math.max(0,y.length-2);for(let d=1;d<y.length;d++)f+=Math.abs(y[d].x-y[d-1].x)+Math.abs(y[d].y-y[d-1].y),m.push({edgeId:p,a:y[d-1],b:y[d]})}for(let p=0;p<m.length;p++)for(let y=p+1;y<m.length;y++){const d=m[p],b=m[y];d.edgeId!==b.edgeId&&(Ln(d.a,d.b,b.a,b.b)||Rn(d.a,d.b,b.a,b.b))&&x++}return So(e.width,e.height,n)+o*18+i+a+r*Math.max(e.width*e.height*.35,5e4)+f*6+h*4e3+x*Math.max(e.width*e.height*.45,7e4)}async function an(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,r=e.gapY??58,i=l=>{const f=new Map(t.map(b=>[b.id,b])),h=Wn(t,n).map(b=>f.get(b));let x=0;const m=Math.max(...l==="RIGHT"?h.map(b=>b.height):h.map(b=>b.width));let p=h.map(b=>{const I={...b,x:l==="RIGHT"?x:(m-b.width)/2,y:l==="DOWN"?x:(m-b.height)/2};return x+=l==="RIGHT"?b.width+o:b.height+r,I});if(l==="RIGHT"&&n.some(b=>b.sourceAnchorY!==void 0&&b.targetAnchorY!==void 0)){new Map(p.map(E=>[E.id,E]));const b=new Map,I=[...p].sort((E,R)=>R.width*R.height-E.width*E.height)[0];b.set(I.id,0);let v=!0;for(;v;){v=!1;for(const E of n){if(E.sourceAnchorY===void 0||E.targetAnchorY===void 0)continue;const R=b.get(E.source),U=b.get(E.target);R!==void 0&&U===void 0?(b.set(E.target,R+E.sourceAnchorY-E.targetAnchorY),v=!0):U!==void 0&&R===void 0&&(b.set(E.source,U+E.targetAnchorY-E.sourceAnchorY),v=!0)}}p=p.map(E=>({...E,y:b.get(E.id)??E.y}));const A=Math.min(...p.map(E=>E.y));p=p.map(E=>({...E,y:E.y-A}))}const y=Math.max(...p.map(b=>b.x+b.width)),d=Math.max(...p.map(b=>b.y+b.height));return{strategy:l==="RIGHT"?"layered-right":"layered-down",width:y,height:d,children:p}};if(e.directedFlowAxis==="RIGHT")return i("RIGHT");if(e.directedFlowAxis==="DOWN")return i("DOWN");const a=[vo(t,n,o,r,s),i("RIGHT"),i("DOWN")];if(t.length>=3&&n.length>0)try{const l=new Map(t.filter(d=>{var b;return(b=d.ports)==null?void 0:b.length}).map(d=>[d.id,d])),f={left:"WEST",right:"EAST",top:"NORTH",bottom:"SOUTH"},h=new Set((e.graphPorts??[]).map(d=>d.id)),x=(e.graphPorts??[]).map(d=>({id:d.id,width:1,height:1,layoutOptions:{"elk.layered.layering.layerConstraint":d.side==="right"?"LAST_SEPARATE":"FIRST_SEPARATE"}})),p=(await oe.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(r),"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:[...x,...t.map(d=>{var b;return(b=d.ports)!=null&&b.length?{id:d.id,width:d.width,height:d.height,layoutOptions:{"elk.portConstraints":"FIXED_SIDE"},ports:d.ports.map(I=>({id:I.id,width:8,height:8,layoutOptions:{"elk.port.side":f[I.side]}}))}:{id:d.id,width:d.width,height:d.height}})],edges:n.map(d=>({id:d.id,sources:[l.has(d.source)&&d.sourcePort?d.sourcePort:d.source],targets:[l.has(d.target)&&d.targetPort?d.targetPort:d.target]}))},{providerId:e.layoutProviderId})).children??[],y=p.filter(d=>!h.has(d.id));if(y.length===t.length){const d=new Map(t.map(E=>[E.id,E])),b=Math.min(...y.map(E=>E.x??0)),I=Math.min(...y.map(E=>E.y??0)),v=y.map(E=>{const R=E.ports;return{...d.get(E.id),x:(E.x??0)-b,y:(E.y??0)-I,...R!=null&&R.length?{portY:new Map(R.map(U=>[U.id,U.y??0]))}:{}}}),A=p.filter(E=>h.has(E.id));a.push({strategy:"elk-layered",width:Math.max(...v.map(E=>E.x+E.width)),height:Math.max(...v.map(E=>E.y+E.height)),...A.length?{graphPortY:new Map(A.map(E=>[E.id,(E.y??0)-I]))}:{},children:v})}}catch{}const c=l=>{const f=ko(l,n,s);if(!e.preferBalancedLayout)return f;const h=Math.abs(Math.log(Math.max(l.width,1)/Math.max(l.height,1)/s));return f+l.width*l.height*h*2.8};return a.reduce((l,f)=>c(f)<c(l)?f:l)}async function Ao(e,t){var I;const n=Object.values(e.elements),s=t!=null&&t.viewpointFilter?n.filter(t.viewpointFilter):n,o=new Set(s.map(v=>v.id)),r=(I=t==null?void 0:t.relationshipTypes)!=null&&I.length?new Set(t.relationshipTypes.map(v=>v.toLowerCase())):void 0,i=e.relationships.filter(v=>o.has(v.sourceId)&&o.has(v.targetId)&&(!r||r.has(v.type.toLowerCase()))),a=s.length,c=a>60?"RIGHT":"DOWN",l=a>40?"24":a>20?"32":"40",f=a>40?"60":a>20?"80":"100",h=t!=null&&t.compartments?new Map(s.map(v=>[v.id,ho(v)])):void 0,x=v=>Math.max(v.name.length*7.5+48,v.kind.length*6.8+48,130),m=v=>{const A=h==null?void 0:h.get(v.id);return 52+(A!=null&&A.length?A.length*15+10:0)},p={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":c,"elk.spacing.nodeNode":l,"elk.layered.spacing.nodeNodeBetweenLayers":f,"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:m(v)})),edges:i.map((v,A)=>({id:v.id||`e-${A}`,sources:[v.sourceId],targets:[v.targetId]}))};let y;try{y=await oe.layout(p,{providerId:t==null?void 0:t.layoutProviderId})}catch(v){console.warn("ELK layout failed, retrying without edge wrapping:",v),delete p.layoutOptions["elk.layered.wrapping.strategy"],delete p.layoutOptions["elk.layered.wrapping.additionalEdgeSpacing"],y=await oe.layout(p,{providerId:t==null?void 0:t.layoutProviderId})}const d=(y.children||[]).map(v=>{const A=e.elements[v.id],E=Ht[A==null?void 0:A.layer]||"#666",R=h==null?void 0:h.get(v.id);return{id:v.id,type:"diagramNode",position:{x:v.x||0,y:v.y||0},data:{label:(A==null?void 0:A.name)||v.id,kind:(A==null?void 0:A.kind)??"",layer:(A==null?void 0:A.layer)??"",construct:A==null?void 0:A.construct,color:E,...R!=null&&R.length?{compartments:R}:{}}}}),b=i.map((v,A)=>{const E=qt[v.type]||"#9CA3AF",R=v.type.toLowerCase(),U=v.type==="flow",Z=v.type==="succession",G=R==="composedof"||R==="decomposedby"||R==="aggregation"||R==="composes";return{id:v.id||`e-${A}`,source:v.sourceId,target:v.targetId,label:G?void 0:v.type,type:Z?"smoothstep":"default",animated:U,style:{stroke:E,strokeWidth:G?2.5:U?2:nt.defaultWidth,strokeDasharray:G||U?void 0:v.type==="traceTo"?"5 3":void 0},labelStyle:{fontSize:"10px",fill:"#6B7280",fontWeight:500},labelBgPadding:nt.labelBgPadding,labelBgBorderRadius:nt.labelBgRadius,labelBgStyle:nt.labelBgStyle,markerEnd:{type:G?"arrow":"arrowclosed",color:E,width:nt.arrowSize,height:nt.arrowSize}}});return{nodes:d,edges:b}}function zn(e){var i;const t=new Set((((i=e.registries)==null?void 0:i.kinds)??[]).filter(a=>{var c;return(c=a.namespace)==null?void 0:c.some(l=>l==="logical"||l==="implementation"||l==="realization")}).map(a=>a.name)),n=new Map;for(const a of Object.values(e.elements))t.has(a.kind)&&n.set(a.id,a);const s=new Map,o=new Set;for(const a of e.relationships)(a.type==="composedOf"||a.type==="aggregation")&&n.has(a.sourceId)&&n.has(a.targetId)&&(s.has(a.sourceId)||s.set(a.sourceId,[]),s.get(a.sourceId).push(a.targetId),o.add(a.targetId));return{roots:[...n.keys()].filter(a=>!o.has(a)),childrenMap:s,elements:n}}const jt=64,ye=100,cn=110,ln=300,dn=44;function Be(e){return Math.max(e.name.length*8+80,220)}async function Co(e,t){const n=t.tree??zn(e);if(n.roots.length===0)return{nodes:[],edges:[]};const s=t.positionCache??new Map,o=x=>t.nodeDirections.get(x)||"vertical",r=x=>(n.childrenMap.get(x)||[]).filter(m=>n.elements.has(m)),i=x=>{const m=n.elements.get(x),p=Be(m),y=r(x);if(!t.expandedNodes.has(x)||y.length===0)return{width:p,height:jt};const d=y.map(i);if(o(x)==="vertical"){const v=d.reduce((E,R)=>E+R.width,0)+(d.length-1)*ye,A=Math.max(...d.map(E=>E.height));return{width:Math.max(p,v),height:jt+cn+A}}const b=Math.max(...d.map(v=>v.width)),I=d.reduce((v,A)=>v+A.height,0)+(d.length-1)*dn;return{width:p+ln+b,height:Math.max(jt,I)}},a=[],c=[],l=qt.composedOf,f=(x,m,p,y)=>{const d=n.elements.get(x),b=Be(d),I=r(x),v=t.expandedNodes.has(x);let A=s.get(x);A||(A={x:p-b/2,y:y-jt/2},s.set(x,A));const E={element:d,layerColor:Ht[d.layer]||"#666",isExpanded:v,hasChildren:I.length>0,childCount:I.length,direction:o(x),onToggleExpand:()=>t.callbacks.onToggleExpand(x),onToggleDirection:()=>t.callbacks.onToggleDirection(x),showDirectionButton:!0,label:d.name};if(a.push({id:x,type:"decompositionNode",position:{x:A.x,y:A.y},data:E,style:{width:b,height:jt}}),m){const U=o(m);c.push({id:`decomp-${m}-${x}`,source:m,target:x,sourceHandle:U==="vertical"?"bottom":"right",targetHandle:U==="vertical"?"top":"left",type:"smoothstep",style:{stroke:l,strokeWidth:nt.defaultWidth},markerEnd:{type:"arrowclosed",color:l,width:nt.arrowSize,height:nt.arrowSize}})}if(!v||I.length===0)return;const R=I.map(i);if(o(x)==="vertical"){const U=R.reduce((q,tt)=>q+tt.width,0)+(R.length-1)*ye;let Z=A.x+b/2-U/2;const G=A.y+jt+cn+jt/2;I.forEach((q,tt)=>{f(q,x,Z+R[tt].width/2,G),Z+=R[tt].width+ye})}else{const U=A.x+b+ln;let Z=A.y+jt+20;I.forEach((G,q)=>{const tt=n.elements.get(G);f(G,x,U+Be(tt)/2,Z+jt/2),Z+=R[q].height+dn})}};let h=0;for(const x of n.roots){if(!n.elements.has(x))continue;const m=i(x);f(x,null,h+m.width/2,100),h+=m.width+ye*2}return{nodes:a,edges:c}}const He=240,We=80,Ut=20;function Fo(e,t){const n=t.tree??zn(e);if(n.roots.length===0)return{nodes:[],edges:[]};const s=[];function o(h,x,m,p,y){const d=n.elements.get(h);if(!d)return{width:0,height:0};const b=Ht[d.layer]||"#666",I=n.childrenMap.get(h)||[],v=I.length>0,A=t.expandedNodes.has(h);let E=He,R=We;if(A&&v){let G=Ut,q=We+Ut,tt=0,wt=0;for(const ht of I){if(!n.elements.has(ht))continue;const et=o(ht,h,m+1,G,q);G+et.width>800&&G>Ut&&(G=Ut,q+=tt+Ut,tt=0,r(ht),o(ht,h,m+1,G,q)),G+=et.width+Ut,tt=Math.max(tt,et.height),wt=Math.max(wt,G)}E=Math.max(He,wt),R=q+tt+Ut}const U=sn[m%sn.length],Z={element:d,layerColor:b,isExpanded:A,hasChildren:v,childCount:I.length,direction:"vertical",onToggleExpand:()=>t.callbacks.onToggleExpand(h),onToggleDirection:()=>{},showDirectionButton:!1,depthBgColor:U,isContainer:v,label:d.name};return s.push({id:h,type:"decompositionNode",position:{x:p,y},...x?{parentId:x,extent:"parent"}:{},data:Z,style:{width:A&&v?E:He,height:A&&v?R:We}}),{width:E,height:R}}function r(h){const x=new Set([h]),m=p=>{for(const y of n.childrenMap.get(p)||[])x.add(y),m(y)};m(h);for(let p=s.length-1;p>=0;p--)x.has(s[p].id)&&s.splice(p,1)}let i=0;for(const h of n.roots){if(!n.elements.has(h))continue;const x=o(h,null,0,i,0);i+=x.width+40}const a=new Map(s.map(h=>[h.id,h])),c=[],l=new Set,f=h=>{if(l.has(h.id))return;const x=h.parentId?a.get(h.parentId):void 0;x&&f(x),l.add(h.id),c.push(h)};for(const h of s)f(h);return{nodes:c,edges:[]}}function To(e){var i;const t=new Set((((i=e.registries)==null?void 0:i.kinds)??[]).filter(a=>{var c;return(c=a.namespace)==null?void 0:c.includes("functional")}).map(a=>a.name)),n=new Map;for(const a of Object.values(e.elements))t.has(a.kind)&&n.set(a.id,a);const s=new Map,o=new Set;for(const a of e.relationships)(a.type==="decomposedBy"||a.type==="composedOf")&&n.has(a.sourceId)&&n.has(a.targetId)&&(s.has(a.sourceId)||s.set(a.sourceId,[]),s.get(a.sourceId).push(a.targetId),o.add(a.targetId));return{roots:[...n.keys()].filter(a=>!o.has(a)),childrenMap:s,elements:n}}async function ii(e,t){const n=To(e);if(n.roots.length===0)return{nodes:[],edges:[]};const s=new Set,o=[];function r(f){if(n.elements.has(f)&&(s.add(f),t.expandedNodes.has(f)))for(const h of n.childrenMap.get(f)||[])n.elements.has(h)&&(o.push({parentId:f,childId:h}),r(h))}for(const f of n.roots)r(f);const i={id:"root",layoutOptions:{"elk.algorithm":"mrtree","elk.direction":"DOWN","elk.spacing.nodeNode":"40","elk.mrtree.searchOrder":"DFS"},children:[...s].map(f=>{const h=n.elements.get(f);return{id:f,width:Math.max(h.name.length*8+80,220),height:56}}),edges:o.map((f,h)=>({id:`fbs-${h}`,sources:[f.parentId],targets:[f.childId]}))},c=((await oe.layout(i,{providerId:t.layoutProviderId})).children||[]).map(f=>{const h=n.elements.get(f.id),x=Ht[h.layer]||"#E67E22",m=(n.childrenMap.get(f.id)||[]).length,p=t.nodeDirections.get(f.id)||"vertical",y={element:h,layerColor:x,isExpanded:t.expandedNodes.has(f.id),hasChildren:m>0,childCount:m,direction:p,onToggleExpand:()=>t.callbacks.onToggleExpand(f.id),onToggleDirection:()=>t.callbacks.onToggleDirection(f.id),showDirectionButton:!0,label:h.name};return{id:f.id,type:"decompositionNode",position:{x:f.x||0,y:f.y||0},data:y}}),l=o.map((f,h)=>{const x=t.nodeDirections.get(f.parentId)||"vertical";return{id:`fbs-e-${h}`,source:f.parentId,target:f.childId,sourceHandle:x==="vertical"?"bottom":"right",targetHandle:x==="vertical"?"top":"left",type:"default",style:{stroke:qt.decomposedBy,strokeWidth:nt.defaultWidth},markerEnd:{type:"arrowclosed",color:qt.decomposedBy,width:nt.arrowSize,height:nt.arrowSize}}});return{nodes:c,edges:l}}const ri=["graph","tree","containment"];function ai(e){const t=e==null?void 0:e.layoutHint;return t==="tree"||t==="containment"||t==="graph"?t:"graph"}function No(e,t){const n=Object.values(e.elements);return t?n.filter(t):n}function Oo(e,t,n){const s=n!=null&&n.length?new Set(n.map(o=>o.charAt(0).toLowerCase()+o.slice(1))):void 0;return De(No(e,t),e.relationships,s)}async function ci(e,t){if(t.mode==="graph")return Ao(e,{viewpointFilter:t.viewpointFilter,relationshipTypes:t.relationshipTypes,compartments:!0,layoutProviderId:t.layoutProviderId});const n=Oo(e,t.viewpointFilter,t.hierarchyRelationshipTypes);return t.mode==="tree"?Co(e,{expandedNodes:t.expandedNodes,nodeDirections:t.nodeDirections,callbacks:t.callbacks,tree:n,positionCache:t.positionCache}):Fo(e,{expandedNodes:t.expandedNodes,callbacks:{onToggleExpand:t.callbacks.onToggleExpand},tree:n})}const Ne="__inner";function li(e){if(e&&!["left","right","top","bottom"].includes(e))return e.endsWith(Ne)?e.slice(0,-Ne.length):e}const di={in:"#16A34A",out:"#D97706",inout:"#2563EB"},_o={data:"#3498DB",energy:"#D97706",material:"#16A34A",control:"#6B7280"};function Do(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 Gn(e){return e.construct==="port"||e.kind.endsWith("Port")}function hn(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 Ot=24,hi=Ot,ze=Ot,ke=30,Je=48,$t=Je,Ge=44,me=12,gn=14,un=92,te=30,re=14,Ye=90,fn=112,Po=72,Lo=(e,t=7.2)=>e.length*t+20,Ro=e=>Math.min(Math.max(Lo(e,7.1),96),180);function Yn(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 jo(e,t,n){return Yn(e)??(t>n?"out":"in")}const $o=e=>e==="in"?"left":"right";function Bo(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 Ho(e,t,n){const s=new Map,o=new Map;for(const[a,c]of e)c.owner&&(t(c.owner)?s.set(a,c.owner):e.has(c.owner)&&o.set(a,c.owner));for(const a of n)!he.has(a.type)||!e.has(a.targetId)||s.has(a.targetId)||o.has(a.targetId)||(t(a.sourceId)?s.set(a.targetId,a.sourceId):e.has(a.sourceId)&&o.set(a.targetId,a.sourceId));const r=new Map,i=(a,c)=>{const l=r.get(a)??s.get(a);if(l)return r.set(a,l),l;const f=o.get(a);if(!f||c.has(f))return;c.add(f);const h=i(f,c);return h&&r.set(a,h),h};for(const a of e.keys())i(a,new Set([a]));return{ownerPart:r,parentPort:o}}function pn(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 r=n.get(s);if(o.has(r))break;o.add(r),s=r}return s}function Wo(e,t,n){const s=new Set,o=r=>{if(!(s.has(r)||!t(r))){s.add(r);for(const i of e.get(r)??[])o(i)}};return o(n),s}function zo(e,t){const n=t.size??Ot,s=t.pitch??te,o=t.nestedPitch??ke,r=new Map;for(const i of["left","right"]){const a=e.filter(h=>t.sideOf(h)===i),c=a.length,l=Math.max(t.bodyBottom-t.bodyTop,0);let f=-1/0;a.forEach((h,x)=>{var p;let m=c===1&&t.singleCenterY!==void 0?t.singleCenterY:t.bodyTop+(c===1?l/2:(x+.5)/c*l);m=Math.max(m,t.bodyTop+s/2,f+s),f=m+((((p=t.weightOf)==null?void 0:p.call(t,h))??1)-1)*o,r.set(h,{x:i==="left"?-n/2:t.width-n/2,y:m-n/2,side:i})})}return r}function yn(e,t){for(const n of["left","right"]){const s=[...e].filter(([r,i])=>i.side===n&&t.has(r)).map(([r])=>r);if(s.length<2)continue;const o=s.map(r=>e.get(r).y).sort((r,i)=>r-i);[...s].sort((r,i)=>t.get(r)-t.get(i)).forEach((r,i)=>{e.get(r).y=o[i]})}}function Go(e,t){return[...e.reduce((n,s)=>{const o=`${t(s.sourceId)}\0${t(s.targetId)}`,r=n.get(o);return r?r.count++:n.set(o,{rel:s,count:1}),n},new Map).values()].map(({rel:n,count:s})=>s===1?n:{...n,id:`bundle-${n.id}`,attributes:{...n.attributes,bundleCount:String(s)}})}async function gi(e,t){var W;const n=Object.values(e.elements),s=t!=null&&t.viewpointFilter?n.filter(t.viewpointFilter):n,o=new Map,r=[];for(const g of s)Gn(g)?o.set(g.id,g):r.push(g);if(r.length===0)return{nodes:[],edges:[]};const i=(t==null?void 0:t.portDisplay)??"all",a=i!=="none",c=De(r,e.relationships),l=t!=null&&t.focusId&&c.elements.has(t.focusId)?t.focusId:void 0,f=l?Wo(c.childrenMap,g=>c.elements.has(g),l):null,h=g=>c.elements.has(g)&&(!f||f.has(g)),x=g=>{var T;return(T=t==null?void 0:t.collapsedNodes)!=null&&T.has(g)?[]:(c.childrenMap.get(g)??[]).filter(h)},{ownerPart:m,parentPort:p}=Ho(o,h,e.relationships);for(const g of[...o.keys()])m.has(g)||o.delete(g);const y=g=>pn(g,"ports",p),d=new Map;for(const[g,T]of m)!o.has(g)||p.has(g)||(d.has(T)||d.set(T,[]),d.get(T).push(g));const b=new Map;if(i==="all")for(const[g]of p){if(!o.has(g))continue;const T=y(g);!o.has(T)||T===g||(b.has(T)||b.set(T,[]),b.get(T).push(g))}const I=g=>{var T;return 1+(((T=b.get(g))==null?void 0:T.length)??0)},v=(W=t==null?void 0:t.relationshipTypes)!=null&&W.length?new Set(t.relationshipTypes.map(g=>g.toLowerCase())):void 0,A=g=>o.has(g)||h(g),E=e.relationships.filter(g=>!he.has(g.type)&&(!v||v.has(g.type.toLowerCase()))&&A(g.sourceId)&&A(g.targetId)&&g.sourceId!==g.targetId),R=g=>m.get(g)??g,U=(t==null?void 0:t.connectionDisplay)??"summary",Z=new Set([...m].filter(([,g])=>g===(t==null?void 0:t.focusId)).map(([g])=>g)),G=Z.size>0?E.filter(g=>Z.has(g.sourceId)||Z.has(g.targetId)):E,q=U==="none"?[]:U==="all"?E:Go(G,R),tt=new Set;for(const g of E)for(const T of[g.sourceId,g.targetId]){if(!o.has(T))continue;let F=T;for(;F&&!tt.has(F);)tt.add(F),F=p.get(F)}for(const[g,T]of d)d.set(g,T.filter(F=>tt.has(F)));const wt=new Set(E.filter(g=>h(g.sourceId)).map(g=>g.sourceId)),ht=new Set(E.filter(g=>h(g.targetId)).map(g=>g.targetId)),et=new Map;for(const[g,T]of c.childrenMap)for(const F of T)h(F)&&et.set(F,g);const Ct=new Map,kt=g=>{const T=Ct.get(g);if(T)return T;const F=o.get(g);let P=Yn(F);if(!P){const _=p.get(g);if(_&&o.has(_))P=kt(_);else{let V=0,u=0;for(const S of q)S.sourceId===g&&V++,S.targetId===g&&u++;P=jo(F,V,u)}}return Ct.set(g,P),P},Y=g=>$o(kt(g)),Ft=g=>({left:g.some(T=>Y(T)==="left")?un:gn,right:g.some(T=>Y(T)==="right")?un:gn}),It=g=>Ro(g.name),pt=(g,T)=>{const F={left:0,right:0};for(const L of T)F[Y(L)]+=te+(I(L)-1)*ke;const P=Math.max(F.left,F.right,0),_=Math.max(Ge+P+8,Po),V=Ft(T),u=It(g),S=Math.max(V.left+u+V.right,fn),N=zo(T,{width:S,bodyTop:Ge,bodyBottom:_-me/2,sideOf:Y,weightOf:I,singleCenterY:Math.max(_/2,Ge+Ot/2)});return{width:S,height:_,childPos:new Map,portPos:N}},lt=new Map,St=new Map,_t=async g=>{const T=x(g),F=a?d.get(g)??[]:[],P=c.elements.get(g);if(T.length===0){const J=pt(P,F);return lt.set(g,J),J}const _=new Map;for(const J of T)_.set(J,await _t(J));const V=new Set(T),u=new Set(F),S=J=>{if(o.has(J)){const X=y(J);if(u.has(X))return X}let Q=R(J);for(;Q&&!V.has(Q);)Q=et.get(Q);return Q},N=(J,Q)=>{var it;if(!o.has(J)||m.get(J)!==Q)return;const X=y(J);return(it=d.get(Q))!=null&&it.includes(X)?X:void 0},L=[],z=new Set;q.forEach((J,Q)=>{const X=S(J.sourceId),it=S(J.targetId);X&&it&&X!==it&&(L.push({id:`ic-${Q}`,source:X,target:it,sourcePort:N(J.sourceId,X),targetPort:N(J.targetId,it)}),V.has(X)&&z.add(X),V.has(it)&&z.add(it))});const{flowKids:ot,orphanKids:ut}=Bo(T,{isConnected:J=>z.has(J),hasChildParts:J=>(c.childrenMap.get(J)??[]).some(h),portCount:J=>{var Q;return((Q=d.get(J))==null?void 0:Q.length)??0}}),Mt=Ft(F),Tt=new Map;let Et=0,Nt=0;if(ot.length>0){const J=X=>(d.get(X)??[]).map(it=>({id:it,side:Y(it)})),Q=await an({id:`container-${g}`,nodes:ot.map(X=>({id:X,width:_.get(X).width,height:_.get(X).height,ports:J(X)})),edges:L,graphPorts:F.map(X=>({id:X,side:Y(X)})),gapX:54,gapY:58,targetAspect:1.3,directedFlowAxis:"AUTO",preferBalancedLayout:!0,layoutProviderId:t==null?void 0:t.layoutProviderId});for(const X of Q.children){const it=X.x+Mt.left,at=X.y+$t;Tt.set(X.id,{x:it,y:at}),Et=Math.max(Et,it-Mt.left+X.width),Nt=Math.max(Nt,at+X.height),X.portY&&yn(_.get(X.id).portPos,X.portY)}Q.graphPortY&&St.set(g,new Map([...Q.graphPortY].map(([X,it])=>[X,it+$t])))}if(ot.length>0&&L.length>0){const J=($t+Math.max(Nt,$t))/2,Q=new Map(St.get(g)??[]),X=(at,gt)=>{if(u.has(at))return Q.get(at)??J;const ft=Tt.get(at),st=_.get(at);if(!ft||!st)return;const xt=gt?st.portPos.get(gt):void 0;return xt?ft.y+xt.y+Ot/2:ft.y+st.height/2},it=at=>at.reduce((gt,ft)=>gt+ft,0)/at.length;for(let at=0;at<2;at++){const gt=new Map,ft=(st,xt)=>{st===void 0||xt===void 0||(gt.has(st)||gt.set(st,[]),gt.get(st).push(xt))};for(const st of L){const xt=X(st.source,st.sourcePort),Rt=X(st.target,st.targetPort);ft(st.sourcePort??(u.has(st.source)?st.source:void 0),Rt),ft(st.targetPort??(u.has(st.target)?st.target:void 0),xt)}for(const st of ot){const xt=_.get(st),Rt=new Map;for(const se of xt.portPos.keys()){const ue=gt.get(se);ue!=null&&ue.length&&Rt.set(se,it(ue))}Rt.size>1&&yn(xt.portPos,Rt)}for(const st of F){const xt=gt.get(st);xt!=null&&xt.length&&Q.set(st,it(xt))}}Q.size>0&&St.set(g,Q)}if(ut.length>0){const J=Math.max(...ut.map(xt=>_.get(xt).width)),Q=Math.max(Et,J),X=Math.max(1,Math.min(ut.length,Math.floor((Q+re)/(J+re))||1)),it=Nt>0?Nt+re:$t;let at=0,gt=it,ft=0,st=0;for(const xt of ut){const Rt=_.get(xt),se=Mt.left+at*(J+re);Tt.set(xt,{x:se,y:gt}),Et=Math.max(Et,se-Mt.left+Rt.width),ft=Math.max(ft,Rt.height),st=Math.max(st,gt+Rt.height),at++,at>=X&&(at=0,gt+=ft+re,ft=0)}Nt=Math.max(Nt,st)}const Wt=Math.min(It(P)+32,248);let Yt=Math.max(Mt.left+Et+Mt.right,Wt,fn),zt=Math.max(Nt+me,$t+me+8);const Zt=new Map,Jt=St.get(g)??new Map;for(const J of["left","right"]){const Q=F.filter(it=>Y(it)===J).sort((it,at)=>(Jt.get(it)??0)-(Jt.get(at)??0));let X=-1/0;for(const it of Q){const at=Math.max(zt/2,$t+Ot/2);let gt=Jt.get(it)??(Q.length===1?at:$t+te/2);gt=Math.max(gt,$t+te/2,X+te);const ft=gt+(I(it)-1)*ke;X=ft,Zt.set(it,{x:J==="left"?-Ot/2:Yt-Ot/2,y:gt-Ot/2,side:J}),zt=Math.max(zt,ft+te/2+me)}}for(const[J,Q]of Zt)Q.side==="right"&&(Q.x=Yt-Ot/2);const je={width:Yt,height:zt,childPos:Tt,portPos:Zt};return lt.set(g,je),je},yt=l?[l]:c.roots.filter(g=>h(g));for(const g of yt)await _t(g);const bt=new Map;if(yt.length===1)bt.set(yt[0],{x:0,y:0});else{const g=u=>{let S=R(u);const N=new Set;for(;S&&et.has(S)&&!N.has(S);)N.add(S),S=et.get(S);return S&&yt.includes(S)?S:yt.includes(u)?u:S},T=new Set(yt),F=[],P=(u,S)=>{var N;if(o.has(u)&&m.get(u)===S){const L=y(u),z=(N=lt.get(S))==null?void 0:N.portPos.get(L);if(z)return z.y+Ot/2}return lt.get(S).height/2};q.forEach((u,S)=>{const N=g(u.sourceId),L=g(u.targetId);N&&L&&N!==L&&T.has(N)&&T.has(L)&&F.push({id:`root-${S}`,source:N,target:L,sourceAnchorY:P(u.sourceId,N),targetAnchorY:P(u.targetId,L)})});const _=await an({id:"interconnection-roots",nodes:yt.map(u=>({id:u,width:lt.get(u).width,height:lt.get(u).height})),edges:F,gapX:Ye,gapY:Ye,targetAspect:1.3,directedFlowAxis:"AUTO",preferBalancedLayout:!0,layoutProviderId:t==null?void 0:t.layoutProviderId});for(const u of _.children)bt.set(u.id,{x:u.x,y:u.y});let V=0;for(const u of yt)bt.has(u)||(bt.set(u,{x:V,y:0}),V+=lt.get(u).width+Ye)}const vt=new Map;for(const[g,T]of d){const F=lt.get(g);if(!F)continue;const P=[];for(const _ of T){const V=F.portPos.get(_);if(!V)continue;const u=o.get(_);P.push({id:_,name:u.name,x:V.x,y:V.y,side:V.side,direction:hn(u)??kt(_)});const S=V.y+Ot/2,N=V.x+(Ot-ze)/2;(b.get(_)??[]).forEach((L,z)=>{const ot=o.get(L);P.push({id:L,name:ot.name,x:N,y:S+ke*(z+1)-ze/2,side:V.side,direction:hn(ot)??kt(L),size:ze,nested:!0})})}vt.set(g,P)}const M=[],j=new Map,$=(g,T,F,P={x:0,y:0},_,V=!1)=>{var Mt;const u=c.elements.get(g),S=lt.get(g),N=Ht[u.layer]||"#64748B",L=F??bt.get(g),z=T?{x:P.x+L.x,y:P.y+L.y}:L;j.set(g,z);const ot=(c.childrenMap.get(g)??[]).some(h),ut=ot;M.push({id:g,type:"interconnectionNode",position:L,...T?{parentId:T,extent:V&&_?[[0,Je],[Math.max(0,_.width-S.width),Math.max(Je,_.height-S.height)]]:"parent"}:{},data:{label:u.name,kind:u.kind,layer:u.layer,color:N,isContainer:ut,isFrame:!T&&ut,hasChildren:ot,isCollapsed:((Mt=t==null?void 0:t.collapsedNodes)==null?void 0:Mt.has(g))??!1,onToggleCollapse:ot&&(t!=null&&t.onToggleCollapse)?()=>t.onToggleCollapse(g):void 0,onDrillIn:ot&&T&&(t!=null&&t.onDrillIn)?()=>t.onDrillIn(g):void 0,ports:vt.get(g)??[],implicitIn:a&&ht.has(g),implicitOut:a&&wt.has(g),onPortMove:t!=null&&t.onPortMove?(Tt,Et)=>t.onPortMove(g,Tt,Et):void 0,minWidth:S.width,minHeight:S.height},style:{width:S.width,height:S.height}});for(const[Tt,Et]of S.childPos)$(Tt,g,Et,z,S,!T&&ut)};for(const g of yt)$(g);const K=(g,T)=>{let F=g;const P=new Set;for(;F&&!P.has(F);){if(F===T)return!0;P.add(F),F=et.get(F)}return!1},C=(g,T)=>{const F=m.get(g),P=R(T);return K(P,F)?`${g}${Ne}`:g},D=g=>o.has(g)?pn(g,i,p):void 0,H=(g,T,F)=>{var N;if(!a)return;const P=vt.get(g)??[];if(!P.length)return;const _=j.get(g),V=j.get(T),u=_&&V?Math.abs(V.x-_.x)>=Math.abs(V.y-_.y)?V.x>=_.x?"right":"left":V.y>=_.y?"bottom":"top":void 0,S=L=>F==="source"?L==="out"?0:L==="inout"?1:4:L==="in"?0:L==="inout"?1:4;return(N=[...P].sort((L,z)=>S(L.direction)-S(z.direction)||+(L.side!==u)-+(z.side!==u)||L.id.localeCompare(z.id))[0])==null?void 0:N.id},mt=q.flatMap((g,T)=>{var J;const F=o.has(g.sourceId)?m.get(g.sourceId):g.sourceId,P=o.has(g.targetId)?m.get(g.targetId):g.targetId;if(!lt.has(F)||!lt.has(P))return[];const _=D(g.sourceId)??H(F,P,"source"),V=D(g.targetId)??H(P,F,"target"),u=Do(g.flowItem,g.type),S=_o[u],N=Number(((J=g.attributes)==null?void 0:J.bundleCount)??0),L=N>1?`${N} connections`:g.flowItem||(g.type.toLowerCase()==="exchangeswith"?void 0:g.type),z=_?C(_,g.targetId):"right",ot=V?C(V,g.sourceId):"left",ut=Q=>Q==="left"?"right":Q==="right"?"left":Q==="top"?"bottom":"top",Mt=(Q,X,it,at)=>{var ft;if(!X)return at;const gt=((ft=(vt.get(Q)??[]).find(st=>st.id===X))==null?void 0:ft.side)??at;return it.endsWith(Ne)?ut(gt):gt},Tt=Mt(F,_,z,"right"),Et=Mt(P,V,ot,"left"),Nt=g.id||`ic-e-${T}`,Wt=(Q,X,it)=>{const at=j.get(Q),gt=lt.get(Q);if(X){const ft=(vt.get(Q)??[]).find(st=>st.id===X);if(ft){const st=ft.size??Ot;return{x:at.x+ft.x+st/2,y:at.y+ft.y+st/2}}}return{x:at.x+(it?gt.width:0),y:at.y+gt.height/2}},Yt=Wt(F,_,!0),zt=Wt(P,V,!1),Zt=j.get(F),Jt=j.get(P);return[{edge:{id:Nt,source:F,target:P,sourceHandle:z,targetHandle:ot,type:"interconnectionEdge",className:"ibd-interconnection-edge",zIndex:5,label:L,animated:g.type==="flow",style:{stroke:S,strokeWidth:Math.max(2,nt.defaultWidth)},labelStyle:{fontSize:rt.badge,fill:"#4B5563",fontWeight:600},labelBgPadding:nt.labelBgPadding,labelBgBorderRadius:nt.labelBgRadius,labelBgStyle:{...nt.labelBgStyle,fillOpacity:.96,stroke:"#E2E8F0",strokeWidth:1},markerEnd:{type:"arrowclosed",color:S,width:nt.arrowSize,height:nt.arrowSize},data:{flowCategory:u,sourceOffset:{x:Yt.x-Zt.x,y:Yt.y-Zt.y},targetOffset:{x:zt.x-Jt.x,y:zt.y-Jt.y},sourcePortId:_,targetPortId:V,sourceSide:Tt,targetSide:Et}},route:{id:Nt,source:Yt,target:zt,sourceNodeId:F,targetNodeId:P,sourceSide:Tt,targetSide:Et}}]}),Dt=M.filter(g=>!g.data.isFrame).map(g=>{const T=j.get(g.id),F=lt.get(g.id);return{id:g.id,x:T.x,y:T.y,width:F.width,height:F.height}}),w=ge(mt.map(g=>g.route),Dt,28,"short-first"),O=Pe(mt.flatMap(({edge:g})=>{const T=w.get(g.id);return g.label&&T&&T.length>=2?[{id:g.id,points:T,width:Re(String(g.label)),height:Le}]:[]}),Dt),B=mt.map(({edge:g})=>({...g,data:{...g.data,points:w.get(g.id)??[],labelPoint:O.get(g.id)}}));return{nodes:M,edges:B}}const Kt="control-in",ee="control-out",At={background:"transparent",border:"none",width:8,height:8};function Yo({onDrillIn:e,color:t,label:n}){return k.jsx("button",{onClick:s=>{s.stopPropagation(),e()},onDoubleClick:s=>s.stopPropagation(),className:"nodrag",title:`Open ${n} as its own diagram`,"aria-label":`Drill into ${n}`,style:{width:16,height:16,flexShrink:0,padding:0,display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${t}66`,borderRadius:4,background:"#FFFFFF",color:t,fontSize:10,fontWeight:700,lineHeight:1,cursor:"pointer"},children:"↳"})}function Uo({data:e,selected:t}){const n=e,{nodeType:s,label:o,laneColor:r,layerColor:i,inPorts:a,outPorts:c}=n,[l,f]=ct.useState(!1);if(s==="start")return k.jsx("div",{style:{width:28,height:28,borderRadius:"50%",background:"#374151",border:"2px solid #374151",boxShadow:$e.sm},children:k.jsx(Pt,{id:ee,type:"source",position:n.flowDirection==="vertical"?dt.Bottom:dt.Right,style:At})});if(s==="done")return k.jsxs("div",{style:{width:28,height:28,borderRadius:"50%",background:"#FFFFFF",border:"3px solid #374151",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:$e.sm},children:[k.jsx("div",{style:{width:14,height:14,borderRadius:"50%",background:"#374151"}}),k.jsx(Pt,{id:Kt,type:"target",position:n.flowDirection==="vertical"?dt.Top:dt.Left,style:At})]});if(s==="decision"||s==="merge"){const I=n.flowDirection==="vertical",v=I?{...At,left:"50%",top:0,right:"auto",bottom:"auto",transform:"translate(-50%, -50%)"}:{...At,left:0,top:32,right:"auto",bottom:"auto",transform:"translate(-50%, -50%)"},A=I?{...At,left:"50%",top:64,right:"auto",bottom:"auto",transform:"translate(-50%, -50%)"}:{...At,left:64,top:32,right:"auto",bottom:"auto",transform:"translate(-50%, -50%)"};return k.jsxs("div",{title:o||(s==="decision"?"Decision node":"Merge node"),style:{width:64,height:64,position:"relative",overflow:"visible"},children:[k.jsx("svg",{width:64,height:64,style:{position:"absolute",inset:0,overflow:"visible"},"aria-hidden":"true",children:k.jsx("polygon",{points:"32,2 62,32 32,62 2,32",fill:"#DDEFB8",stroke:"#374151",strokeWidth:"2.25"})}),k.jsx("span",{style:{position:"absolute",top:70,left:-34,width:132,display:"block",textAlign:"center",fontSize:13,fontWeight:600,lineHeight:1.2,color:"#374151",overflowWrap:"anywhere",pointerEvents:"none"},children:o}),k.jsx(Pt,{id:Kt,type:"target",position:I?dt.Top:dt.Left,style:v}),k.jsx(Pt,{id:ee,type:"source",position:I?dt.Bottom:dt.Right,style:A})]})}if(s==="activityFinal"||s==="flowFinal"){const y=s==="activityFinal";return k.jsxs("div",{title:o||(y?"Activity final / terminate":"Flow final"),style:{width:28,height:28,borderRadius:"50%",background:"#FFFFFF",border:"2px solid #374151",display:"flex",alignItems:"center",justifyContent:"center",position:"relative",overflow:"visible"},children:[y?k.jsx("div",{style:{width:14,height:14,borderRadius:"50%",background:"#374151"}}):k.jsx("span",{style:{color:"#374151",fontSize:22,lineHeight:1},children:"×"}),o&&k.jsx("span",{style:{position:"absolute",top:33,left:-46,width:120,textAlign:"center",fontSize:12,fontWeight:600,lineHeight:1.2,color:"#374151",pointerEvents:"none",overflowWrap:"anywhere"},children:o}),k.jsx(Pt,{id:Kt,type:"target",position:n.flowDirection==="vertical"?dt.Top:dt.Left,style:At})]})}if(s==="fork"||s==="join"){const y=n.flowDirection==="vertical";return k.jsxs("div",{title:s==="fork"?"Fork — split into concurrent flows":"Join — synchronize concurrent flows",style:{width:"100%",height:"100%",background:"#374151",borderRadius:3,boxShadow:$e.sm},children:[k.jsx(Pt,{id:Kt,type:"target",position:y?dt.Top:dt.Left,style:At}),k.jsx(Pt,{id:ee,type:"source",position:y?dt.Bottom:dt.Right,style:At})]})}const h=r||i||"#9CA3AF",x=s==="accept"?"«accept action»":s==="send"?"«send action»":void 0;if(n.isFrame)return k.jsxs("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:`${h}08`,border:`1.5px solid ${h}66`,borderRadius:10,boxShadow:t?"0 0 0 3px #2DD4A8":"none",position:"relative"},children:[k.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 14px 0"},children:[n.onToggleExpand&&k.jsx("button",{"aria-label":`Collapse ${o}`,className:"nodrag",onClick:y=>{y.stopPropagation(),n.onToggleExpand()},onDoubleClick:y=>y.stopPropagation(),style:{width:16,height:16,flexShrink:0,padding:0,display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${h}66`,borderRadius:4,background:"#FFFFFF",color:h,fontSize:11,fontWeight:700,lineHeight:1,cursor:"pointer"},children:"−"}),n.onDrillIn&&k.jsx(Yo,{onDrillIn:n.onDrillIn,color:h,label:o}),k.jsx("span",{style:{fontSize:rt.md,fontWeight:700,color:h,whiteSpace:"nowrap"},children:o}),n.allocatedTo&&k.jsxs("span",{style:{fontSize:"9px",color:"#9CA3AF",whiteSpace:"nowrap"},children:["→"," ",n.allocatedTo]})]}),k.jsx(Pt,{id:Kt,type:"target",position:n.flowDirection==="vertical"?dt.Top:dt.Left,style:At}),k.jsx(Pt,{id:ee,type:"source",position:n.flowDirection==="vertical"?dt.Bottom:dt.Right,style:At})]});const m=18,p=Math.max(a.length*m,c.length*m,0);return k.jsxs("div",{onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),style:{background:"#FFFFFF",border:`1.5px solid ${h}`,borderRadius:3,minWidth:"140px",boxShadow:t?"0 0 0 3px #2DD4A8, 0 4px 12px rgba(45, 212, 168, 0.35)":l?`0 0 0 2px ${h}22`:"none",transition:"box-shadow 150ms ease",overflow:"hidden"},children:[k.jsxs("div",{style:{padding:"8px 14px",fontSize:rt.md,fontWeight:600,color:"#1a1a1a",background:`${h}0D`,borderBottom:p>0?"1px solid #E5E5E0":"none",textAlign:"center",...n.flowDirection==="vertical"?{whiteSpace:"nowrap"}:{whiteSpace:"normal",overflowWrap:"anywhere",lineHeight:1.25}},children:[x&&k.jsx("div",{style:{fontSize:10,color:h,fontStyle:"italic",marginBottom:2},children:x}),o,n.hasChildren&&n.onDrillIn&&k.jsx("button",{"aria-label":`Drill into ${o}`,title:`Open ${o} as its own diagram`,className:"nodrag",onClick:y=>{y.stopPropagation(),n.onDrillIn()},onDoubleClick:y=>y.stopPropagation(),style:{float:"right",marginLeft:4,width:18,height:18,padding:0,border:`1px solid ${h}`,borderRadius:2,background:"#FFFFFF",color:h,fontSize:11,fontWeight:700,lineHeight:"16px",cursor:"pointer"},children:"↳"}),n.hasChildren&&n.onToggleExpand&&k.jsx("button",{"aria-label":n.isExpanded?`Collapse ${o}`:`Expand ${o}`,onClick:y=>{y.stopPropagation(),n.onToggleExpand()},style:{float:"right",marginLeft:8,width:18,height:18,padding:0,border:`1px solid ${h}`,borderRadius:2,background:"#FFFFFF",color:h,fontSize:13,fontWeight:700,lineHeight:"16px",cursor:"pointer"},children:n.isExpanded?"−":"+"})]}),p>0&&k.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0"},children:[k.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:a.map(y=>k.jsxs("div",{style:{fontSize:rt.badge,color:"#6B7280",paddingLeft:"8px",display:"flex",alignItems:"center",height:`${m}px`,gap:"4px"},children:[k.jsx(Pt,{id:`in:${y}`,type:"target",position:n.flowDirection==="vertical"?dt.Top:dt.Left,style:At}),y]},`in-${y}`))}),k.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px",alignItems:"flex-end"},children:c.map(y=>k.jsxs("div",{style:{fontSize:rt.badge,color:"#6B7280",paddingRight:"8px",display:"flex",alignItems:"center",height:`${m}px`,gap:"4px"},children:[y,k.jsx(Pt,{id:`out:${y}`,type:"source",position:n.flowDirection==="vertical"?dt.Bottom:dt.Right,style:At})]},`out-${y}`))})]}),n.allocatedTo&&k.jsxs("div",{style:{fontSize:"9px",color:"#9CA3AF",textAlign:"center",padding:"2px 6px",borderTop:"1px solid #F3F4F6",background:"#FAFAFA"},children:["→"," ",n.allocatedTo]}),k.jsx(Pt,{id:Kt,type:"target",position:n.flowDirection==="vertical"?dt.Top:dt.Left,style:At}),k.jsx(Pt,{id:ee,type:"source",position:n.flowDirection==="vertical"?dt.Bottom:dt.Right,style:At})]})}const ui=ct.memo(Uo);function mn(e,t,n,s,o){const r=e*o+s;return r>=0?0:Math.max(0,Math.min(-r/o,t-n))}const xn=40;function Xo({data:e,selected:t,positionAbsoluteX:n,positionAbsoluteY:s,width:o,height:r}){const i=e,a=i.orientation==="column",[c,l,f]=Pn(h=>h.transform);return k.jsx("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:`${i.color}08`,border:t?"3px solid #2DD4A8":`1px solid ${i.color}30`,borderLeft:t?"3px solid #2DD4A8":a?`1px solid ${i.color}30`:`3px solid ${i.color}`,borderTop:t?"3px solid #2DD4A8":a?`3px solid ${i.color}`:`1px solid ${i.color}30`,borderRadius:ie.md,pointerEvents:"auto",cursor:i.inspectElementId?"pointer":"default",display:"flex"},children:k.jsx("div",{style:{...a?{width:"100%",height:Ko,borderBottom:`1px solid ${i.color}24`}:{width:Vo,height:"100%",borderRight:`1px solid ${i.color}24`},background:`${i.color}0F`,borderRadius:a?`${ie.md}px ${ie.md}px 0 0`:`${ie.md}px 0 0 ${ie.md}px`,flexShrink:0}})})}const fi=ct.memo(Xo),Ko=30,Vo=34;function qo({data:e,positionAbsoluteX:t,positionAbsoluteY:n,width:s,height:o}){const r=e,i=r.orientation==="column",[a,c,l]=Pn(h=>h.transform),f=i?mn(n,o??0,xn,c,l):mn(t,s??0,xn,a,l);return k.jsx("div",{style:{width:"100%",height:"100%",display:"flex",pointerEvents:"none",alignItems:i?"flex-start":"center",justifyContent:i?"center":"flex-start"},children:k.jsx("div",{style:{writingMode:i?"horizontal-tb":"vertical-rl",transform:i?void 0:"rotate(180deg)",padding:i?"6px 12px":"12px 6px",fontSize:rt.xs,fontWeight:700,color:r.color,letterSpacing:"0.04em",textTransform:"uppercase",whiteSpace:"nowrap",background:f>0?"#FFFFFFEE":"transparent",borderRadius:4,...i?{marginTop:f}:{marginLeft:f}},children:r.label})})}const pi=ct.memo(qo);function yi(e,t){const n=t.registries,s=new Set(e.filter(r=>!Gt(r,n)).map(r=>r.id)),o=new Set;for(const r of t.relationships)r.type!=="flow"&&r.type!=="succession"||(s.has(r.sourceId)&&o.add(r.sourceId),s.has(r.targetId)&&o.add(r.targetId));return e.filter(r=>!Gt(r,n)&&!o.has(r.id))}function Un(e,t,n=new Set,s){const o=Object.values(e.elements),i=(t?o.filter(t):o).filter(h=>Vt(h,e.registries)!==void 0),a=i.filter(h=>h.parentAction);if(a.length===0)return i;const c=new Map(i.map(h=>[h.id,h])),l=[],f=h=>{const x=i.filter(m=>m.parentAction===h.id);if(n.has(h.id)&&x.length>0){for(const m of x)f(m);return}l.push(h)};if(s){for(const h of i.filter(x=>x.parentAction===s))f(h);return l}for(const h of a){const x=h.parentAction?c.get(h.parentAction):void 0;x!=null&&x.parentAction||f(h)}return l}function Zo(e,t,n=new Set,s){if(n.size===0)return new Map;const o=new Set(Un(e,t,n,s).map(f=>f.id)),r=Object.values(e.elements),i=t?r.filter(t):r,a=new Map;for(const f of i)f.parentAction&&(a.has(f.parentAction)||a.set(f.parentAction,[]),a.get(f.parentAction).push(f));const c=new Map,l=(f,h)=>{const x=[];for(const m of a.get(f)??[])h.has(m.id)||(h.add(m.id),o.has(m.id)?x.push(m.id):x.push(...l(m.id,h)));return x};for(const f of n){if(o.has(f))continue;const h=l(f,new Set([f]));h.length>0&&c.set(f,h)}return c}function Jo(e,t,n=new Set,s){const o=Object.values(e.elements),i=(t?o.filter(t):o).filter(p=>Vt(p,e.registries)!==void 0),a=[],c=new Map,l=new Map,f=p=>i.filter(y=>y.parentAction===p),h=(p,y)=>{a.push(p),y&&(c.set(p.id,y),l.has(y)||l.set(y,[]),l.get(y).push(p.id));const d=f(p.id);if(!(d.length===0||!n.has(p.id))){l.set(p.id,[]);for(const b of d)h(b,p.id)}};if(s){for(const p of f(s))h(p);return{actions:a,parentOf:c,childrenOf:l}}const x=new Map(i.map(p=>[p.id,p])),m=i.filter(p=>p.parentAction);if(m.length===0)return{actions:i,parentOf:c,childrenOf:l};for(const p of m){const y=p.parentAction?x.get(p.parentAction):void 0;y!=null&&y.parentAction||h(p)}return{actions:a,parentOf:c,childrenOf:l}}function Qo(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(r=>r.direction==="in"||r.direction==="inout").map(r=>r.name),outPorts:o.filter(r=>r.direction==="out"||r.direction==="inout").map(r=>r.name)}}const wn=["#4A90D9","#E67E22","#2ECC71","#9B59B6","#E74C3C","#1ABC9C","#F39C12","#7B68EE"],Ue="Unallocated",ts="Unstaged";function nn(e,t,n="all"){const s=new Map;for(const c of t.relationships)he.has(c.type)&&!s.has(c.targetId)&&s.set(c.targetId,c.sourceId);const o=[e],r=new Set(o);let i=e;for(;s.has(i);){const c=s.get(i);if(r.has(c))break;o.unshift(c),r.add(c),i=c}if(n==="all")return{id:e,level:o.length};const a=Math.min(Math.max(n,1),o.length)-1;return{id:o[a],level:a+1}}function es(e,t,n="all"){var o;const s=nn(e,t,n).id;return((o=t.elements[s])==null?void 0:o.name)??s}function mi(e,t){const n=[...new Set(e)].map(o=>nn(o,t).level);if(n.length===0)return[];const s=Math.min(...n);return s<=1?[]:Array.from({length:s},(o,r)=>r+1)}function ns(e,t,n="allocation",s="all"){var a,c;const o=new Map,r=[],i=new Map;for(const l of e){if(Gt(l,t.registries))continue;const f=l.allocatedTo?nn(l.allocatedTo,t,s).id:Ue,h=n==="stage"?l.attributes.stage||l.attributes.phase||ts:f;if(o.set(l.id,h),!i.has(h)){const x={id:h,label:n==="allocation"&&h!==Ue?((a=t.elements[h])==null?void 0:a.name)??h:h,color:wn[i.size%wn.length],inspectElementId:n==="allocation"&&h!==Ue?h:((c=Object.values(t.elements).find(m=>m.id===h||m.name===h))==null?void 0:c.id)??l.id};i.set(h,x),r.push(x)}}return{laneOf:o,lanes:r}}const os=18,Qe=36,ss=20,Xt=36,bn=16,xe=120,Xe=18,In=40,we=32,Sn=64,Mn=10,Qt=28;function vn(e,t,n,s){return{id:`__lane_label_${e.id}`,type:"actionFlowLaneLabel",position:n,data:{label:e.label,color:e.color,orientation:t,isFrame:!0},style:{...s,pointerEvents:"none"},draggable:!1,selectable:!1,zIndex:5}}const Xn=140,Kn=240,Vn=9,is=20,qn=36;function tn(e){return Math.max(e.name.length*Vn+qn,Xn)}function rs(e,t,n,s){const o=e.filter(r=>{const i=Vt(r,s);return i!=="decision"&&i!=="merge"&&i!=="fork"&&i!=="join"&&i!=="activityFinal"&&i!=="flowFinal"});return o.length===0?Xn:n==="horizontal"?Math.min(Kn,Math.max(...o.map(tn))):Math.max(...o.map(r=>Zn(t.get(r.id),r)+Qe))}function Zn(e,t){const s=Math.max((e==null?void 0:e.inPorts.length)??0,(e==null?void 0:e.outPorts.length)??0,0)*os;return s+(s>0?8:0)+(t.allocatedTo?ss:0)}function as(e,t,n,s,o){const r=Vt(e,s);if(r==="decision"||r==="merge")return{width:64,height:64};if(r==="activityFinal"||r==="flowFinal")return{width:28,height:28};if(r==="fork"||r==="join")return n==="vertical"?{width:Sn,height:Mn}:{width:Mn,height:Sn};const i=Zn(t,e);if(n==="vertical")return{width:tn(e),height:o??Qe+i};const a=o??Math.min(Kn,tn(e)),c=Math.max(1,Math.ceil(e.name.length*Vn/Math.max(1,a-qn)));return{width:a,height:Qe+(c-1)*is+i}}function En(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 Ke={control:"#4B5563",data:"#3498DB",energy:"#D97706",material:"#16A34A"};function cs(e,t){const n=new Map,s=new Map;for(const a of t)s.set(a,0);for(const a of e)!t.has(a.sourceId)||!t.has(a.targetId)||(n.has(a.sourceId)||n.set(a.sourceId,[]),n.get(a.sourceId).push(a),s.set(a.targetId,(s.get(a.targetId)??0)+1));const o=new Set,r=new Map,i=a=>{r.set(a,1);for(const c of n.get(a)??[]){const l=r.get(c.targetId)??0;l===1?o.add(c.id):l===0&&i(c.targetId)}r.set(a,2)};for(const a of t)(s.get(a)??0)===0&&!r.has(a)&&i(a);for(const a of t)r.has(a)||i(a);return o}async function xi(e,t){var C,D,H,mt,Dt;const n=(t==null?void 0:t.nesting)??"flat",s=n==="nested"?Jo(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 r=new Set(o.map(w=>w.id)),{laneOf:i,lanes:a}=ns(o,e,t==null?void 0:t.laneGrouping,t==null?void 0:t.displayLevel),c=(t==null?void 0:t.direction)??"horizontal",l=n!=="nested"&&((t==null?void 0:t.swimlanes)??!0)&&a.length>=1,f=e.relationships.filter(w=>w.type==="succession"),h=e.relationships.filter(w=>w.type==="flow"),x=new Map;for(const w of n==="nested"?[]:(t==null?void 0:t.expandedActionIds)??[]){const O=Object.values(e.elements).filter(g=>g.parentAction===w);if(O.length===0)continue;const B=((C=f.find(g=>g.sourceId===`${w}__start`))==null?void 0:C.targetId)??O[0].id,W=((D=f.find(g=>g.targetId===`${w}__done`))==null?void 0:D.sourceId)??O[O.length-1].id;x.set(w,{first:B,last:W})}const m=w=>w.map(O=>{var B,W;return{...O,sourceId:((B=x.get(O.sourceId))==null?void 0:B.last)??O.sourceId,targetId:((W=x.get(O.targetId))==null?void 0:W.first)??O.targetId}}),p=m(f),y=m(h),d=new Set;for(const w of p){const O=w.sourceId.endsWith("__start")?w.sourceId.slice(0,-7):void 0,B=w.targetId.endsWith("__done")?w.targetId.slice(0,-6):void 0;O&&!x.has(O)&&r.has(w.targetId)&&d.add(w.sourceId),B&&!x.has(B)&&r.has(w.sourceId)&&d.add(w.targetId)}const b=new Set([...r,...d]),I=y.filter(w=>b.has(w.sourceId)&&b.has(w.targetId)&&(!(t!=null&&t.visibleFlowKinds)||t.visibleFlowKinds.has(En(w.flowItem)))),v=new Set(I.map(w=>`${w.sourceId}\0${w.targetId}`)),A=p.filter(w=>b.has(w.sourceId)&&b.has(w.targetId)&&(!(t!=null&&t.visibleFlowKinds)||t.visibleFlowKinds.has("control"))&&!v.has(`${w.sourceId}\0${w.targetId}`)),E=cs(A,b),R=A.filter(w=>!E.has(w.id)),U=new Map(o.map(w=>[w.id,Qo(w,e)])),Z=new Map(o.map(w=>[w.id,w])),G=new Map,q=new Map;if(n==="nested"){for(const[w,O]of s.childrenOf)G.set(w,O.filter(B=>b.has(B)));for(const w of d){const O=w.endsWith("__start")?w.slice(0,-7):w.slice(0,-6);G.has(O)&&G.get(O).push(w)}for(const[w,O]of G)for(const B of O)q.set(B,w)}const tt=rs(o,U,c,e.registries),wt=w=>{const O=Z.get(w);return O?as(O,U.get(w),c,e.registries,tt):{width:Qt,height:Qt}},ht=w=>{const O=G.get(w)??[];return O.length===0?{id:w,...wt(w)}:{id:w,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:O.map(ht)}},et=[...d,...o.map(w=>w.id)].filter(w=>!q.has(w)),Ct={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:et.map(ht),edges:[...I,...R].map((w,O)=>({id:`afe-${O}`,sources:[w.sourceId],targets:[w.targetId]}))},kt=await oe.layout(Ct,{providerId:t==null?void 0:t.layoutProviderId}),Y=new Map,Ft=w=>{Y.set(w.id,{x:w.x??0,y:w.y??0,width:w.width??140,height:w.height??56});for(const O of w.children??[])Ft(O)};for(const w of kt.children??[])Ft(w);const It=new Map(a.map(w=>[w.id,w.color])),pt=[],lt=new Map,St=[...d].some(w=>w.endsWith("__start")),_t=[...d].some(w=>w.endsWith("__done")),yt=St?Qt+24:0,bt=_t?Qt+24:0;if(l&&c==="horizontal"){const w=new Map;for(const T of o){if(Gt(T,e.registries))continue;const F=Y.get(T.id),P=i.get(T.id);w.has(P)||w.set(P,[]),w.get(P).push(F.y)}const O=[...a].sort((T,F)=>{const P=_=>_.reduce((V,u)=>V+u,0)/_.length;return P(w.get(T.id)??[0])-P(w.get(F.id)??[0])});let B=1/0,W=-1/0;for(const T of o){const F=Y.get(T.id);B=Math.min(B,F.x),W=Math.max(W,F.x+F.width)}let g=0;for(const T of O){const F=o.filter(u=>i.get(u.id)===T.id);F.sort((u,S)=>Y.get(u.id).x-Y.get(S.id).x||Y.get(u.id).y-Y.get(S.id).y);const P=Math.min(...F.map(u=>Y.get(u.id).y));let _=0;const V=[];for(const u of F){const S=Y.get(u.id);let N=g+Xt+(S.y-P);for(const L of V)S.x<L.x1&&S.x+S.width>L.x0&&(N=Math.max(N,L.bottom+16));Y.set(u.id,{...S,y:N}),V.push({x0:S.x,x1:S.x+S.width,bottom:N+S.height}),_=Math.max(_,N+S.height-g)}_+=Xt,pt.push({id:`__lane_${T.id}`,type:"actionFlowLane",position:{x:B-xe,y:g},data:{label:T.label,color:T.color,orientation:"row",inspectElementId:T.inspectElementId,memberIds:F.map(u=>u.id),isFrame:!0},style:{width:W-B+xe+Xt,height:_},draggable:!1,selectable:!1,zIndex:-1}),pt.push(vn(T,"row",{x:B-xe,y:g},{width:W-B+xe+Xt,height:_})),g+=_+bn}}else if(l){let w=1/0,O=-1/0;for(const W of o){const g=Y.get(W.id);w=Math.min(w,g.y),O=Math.max(O,g.y+g.height)}let B=0;for(const W of a){const g=o.filter(P=>i.get(P.id)===W.id).sort((P,_)=>Y.get(P.id).y-Y.get(_.id).y||Y.get(P.id).x-Y.get(_.id).x),F=Math.max(...g.map(P=>Y.get(P.id).width))+Xt*2;lt.set(W.id,{left:B,width:F});for(const P of g){const _=Y.get(P.id);Y.set(P.id,{..._,x:B+(F-_.width)/2})}pt.push({id:`__lane_${W.id}`,type:"actionFlowLane",position:{x:B,y:w-we-yt},data:{label:W.label,color:W.color,orientation:"column",inspectElementId:W.inspectElementId,memberIds:g.map(P=>P.id),isFrame:!0},style:{width:F,height:O-w+we+Xt+yt+bt},draggable:!1,selectable:!1,zIndex:-1}),pt.push(vn(W,"column",{x:B,y:w-we-yt},{width:F,height:O-w+we+Xt+yt+bt})),B+=F+bn}}const vt=n==="nested"?[]:o.filter(w=>{const O=Vt(w,e.registries);return O==="decision"||O==="merge"||O==="fork"||O==="join"});if(vt.length>0)for(const w of vt){const O=Y.get(w.id),B=Vt(w,e.registries),W=[];for(const T of[...A,...I]){const F=B==="decision"||B==="fork"?T.targetId===w.id?T.sourceId:void 0:T.sourceId===w.id?T.targetId:void 0;if(F===void 0)continue;const P=Y.get(F);P&&W.push(c==="vertical"?P.x+P.width/2:P.y+P.height/2)}if(W.length===0)continue;const g=W.reduce((T,F)=>T+F,0)/W.length;Y.set(w.id,c==="vertical"?{...O,x:g-O.width/2}:{...O,y:g-O.height/2})}if(c==="vertical"&&l&&lt.size>0){const w=[...A,...I],O=new Map(o.map(B=>[B.id,B]));for(const B of o.filter(W=>Gt(W,e.registries))){const W=new Set,g=[B.id],T=new Set;for(;g.length>0&&W.size<=1;){const S=g.pop();if(!T.has(S)){T.add(S);for(const N of w){const L=N.sourceId===S?N.targetId:N.targetId===S?N.sourceId:void 0;if(!L||T.has(L))continue;const z=O.get(L);if(z)if(Gt(z,e.registries))g.push(L);else{const ot=i.get(L);ot&&W.add(ot)}}}}if(W.size!==1)continue;const F=lt.get([...W][0]),P=Y.get(B.id);if(!F||!P)continue;const _=12,V=F.left+_,u=F.left+F.width-P.width-_;Y.set(B.id,{...P,x:Math.max(V,Math.min(P.x,u))})}}for(const w of n==="nested"?[]:d){const O=Y.get(w);if(!O)continue;const B=[];for(const F of A){const P=F.sourceId===w?F.targetId:F.targetId===w?F.sourceId:void 0;if(!P)continue;const _=Y.get(P);_&&B.push(c==="vertical"?_.x+_.width/2:_.y+_.height/2)}if(B.length===0)continue;const W=B.reduce((F,P)=>F+P,0)/B.length,g=o.filter(F=>!Gt(F,e.registries)).map(F=>Y.get(F.id)).filter(F=>!!F),T=w.endsWith("__start");if(c==="vertical"){const F=Math.min(...g.map(_=>_.y)),P=Math.max(...g.map(_=>_.y+_.height));Y.set(w,{...O,x:W-O.width/2,y:T?F-O.height-16:P+16})}else{const F=Math.min(...g.map(_=>_.x)),P=Math.max(...g.map(_=>_.x+_.width));Y.set(w,{...O,x:T?F-O.width-24:P+24,y:W-O.height/2})}}const M=[];if(n!=="nested"){const w=Zo(e,t==null?void 0:t.viewpointFilter,t==null?void 0:t.expandedActionIds,t==null?void 0:t.focusActionId);for(const[O,B]of w){const W=e.elements[O],g=B.map(u=>Y.get(u)).filter(u=>!!u);if(!W||g.length===0)continue;const T=Math.min(...g.map(u=>u.x)),F=Math.min(...g.map(u=>u.y)),P=Math.max(...g.map(u=>u.x+u.width)),_=Math.max(...g.map(u=>u.y+u.height)),V={element:W,label:W.name,nodeType:"action",laneColor:"#9CA3AF",layerColor:Ht[W.layer]||"#FF6B6B",inPorts:[],outPorts:[],hasChildren:!0,isExpanded:!0,isFrame:!0,onToggleExpand:t!=null&&t.onToggleAction?()=>t.onToggleAction(O):void 0,onDrillIn:t!=null&&t.onDrillInAction?()=>t.onDrillInAction(O):void 0,flowDirection:c};M.push({id:`__group_${O}`,type:"actionFlowNode",position:{x:T-Xe,y:F-In},style:{width:P-T+Xe*2,height:_-F+In+Xe},draggable:!1,selectable:!1,data:V})}}const j=[...pt,...M],$=w=>{const O=q.get(w);return O?{parentId:O,extent:"parent"}:{}};for(const w of d){const O=Y.get(w),B=w.endsWith("__start"),W={label:B?"Start":"Done",nodeType:B?"start":"done",laneColor:"#374151",layerColor:"#374151",inPorts:[],outPorts:[],flowDirection:c};j.push({id:w,type:"actionFlowNode",position:{x:O.x,y:O.y},style:{width:Qt,height:Qt},...$(w),data:W})}for(const w of o){const O=Y.get(w.id),B=Vt(w,e.registries);if(Gt(w,e.registries)){const _={element:w,label:w.name,nodeType:B,laneColor:"#374151",layerColor:"#374151",inPorts:[],outPorts:[],flowDirection:c};j.push({id:w.id,type:"actionFlowNode",position:{x:O.x,y:O.y},style:{width:O.width,height:O.height},...$(w.id),data:_});continue}const W=U.get(w.id),g=i.get(w.id),T=w.allocatedTo?es(w.allocatedTo,e,t==null?void 0:t.displayLevel):void 0,F=(((H=G.get(w.id))==null?void 0:H.length)??0)>0,P={element:w,label:w.name,nodeType:B??"action",parameters:w.parameters,allocatedTo:T,laneColor:It.get(g)??"#9CA3AF",layerColor:Ht[w.layer]||"#FF6B6B",inPorts:W.inPorts,outPorts:W.outPorts,hasChildren:Object.values(e.elements).some(_=>_.parentAction===w.id),isExpanded:((mt=t==null?void 0:t.expandedActionIds)==null?void 0:mt.has(w.id))??!1,isFrame:F,onToggleExpand:t!=null&&t.onToggleAction?()=>t.onToggleAction(w.id):void 0,onDrillIn:t!=null&&t.onDrillInAction?()=>t.onDrillInAction(w.id):void 0,flowDirection:c};j.push({id:w.id,type:"actionFlowNode",position:{x:O.x,y:O.y},style:{width:O.width,height:O.height},...$(w.id),data:P})}if(q.size>0){const w=new Map(j.map(g=>[g.id,g])),O=[],B=new Set,W=g=>{if(B.has(g.id))return;B.add(g.id);const T=g.parentId?w.get(g.parentId):void 0;T&&W(T),O.push(g)};for(const g of j)W(g);j.length=0,j.push(...O)}const K=[];for(const w of I){const O=En(w.flowItem),B=Ke[O],W=w.flowItem?/signal|error|status|code|report|alarm|response|command|data|reading/i.test(w.flowItem):!1;K.push({id:w.id,source:w.sourceId,target:w.targetId,...w.sourceEnd?{sourceHandle:`out:${w.sourceEnd}`}:{},...w.targetEnd?{targetHandle:`in:${w.targetEnd}`}:{},label:void 0,type:"smoothstep",animated:!1,style:{stroke:B,strokeWidth:nt.flowWidth,strokeDasharray:W?"6 3":void 0},labelStyle:{fontSize:rt.badge,fill:B,fontWeight:600},labelBgStyle:nt.labelBgStyle,labelBgPadding:nt.labelBgPadding,labelBgBorderRadius:nt.labelBgRadius,markerEnd:{type:"arrowclosed",color:B,width:nt.arrowSize,height:nt.arrowSize},zIndex:2,data:{flowCategory:O,flowItem:w.flowItem}})}for(const w of A){const O=E.has(w.id);K.push({id:w.id,source:w.sourceId,target:w.targetId,sourceHandle:ee,targetHandle:Kt,type:c==="vertical"&&!O?"straight":"smoothstep",animated:!1,style:{stroke:Ke.control,strokeWidth:1.5},markerEnd:{type:"arrowclosed",color:Ke.control,width:12,height:12},zIndex:2,label:(Dt=w.sourceEnd)!=null&&Dt.startsWith("[")?w.sourceEnd:void 0,data:{flowCategory:"control"}})}return{nodes:j,edges:K}}function ls(e){return e.attributes.sourceState&&e.attributes.targetState?!0:e.kind==="Transition"||e.kind.endsWith("Transition")}function ds(e){return e.kind.endsWith("State")||e.kind.endsWith("Machine")||e.kind.endsWith("Mode")}function hs(e,t){const n=Object.values(e.elements),s=t?n.filter(t):n,o=[],r=[],i=[];for(const a of s)ls(a)?r.push(a):ds(a)?o.push(a):i.push(a);return{states:o,transitions:r,annotations:i}}const kn=46;function gs(e){return e.length>kn?`${e.slice(0,kn-1)}…`:e}function us(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 gs(s?`${o} [${n}]`:o)}function fs(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 r=n.get(o.attributes.sourceState??""),i=n.get(o.attributes.targetState??"");!r||!i||s.push({element:o,sourceId:r,targetId:i,label:us(o)})}return s}function ps(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(m=>e.elements.has(m)),r=s?o(s):[],i=r.length>0?r:e.roots.filter(x=>e.elements.has(x)),a=new Set,c=new Map,l=new Map,f=(x,m)=>{c.set(x,m),l.set(m,(l.get(m)??0)+1);for(const p of o(x))f(p,m)},h=x=>{a.add(x);const m=o(x);if(n.has(x)){for(const p of m)f(p,x);return}for(const p of m)h(p)};for(const x of i)h(x);return{visible:a,liftTo:c,hiddenCount:l,roots:i}}function ys(e,t){const n=o=>t.visible.has(o)?o:t.liftTo.get(o),s=[];for(const o of e){const r=n(o.sourceId),i=n(o.targetId);if(!r||!i)continue;const a=o.sourceId===o.targetId;r===i&&!a||s.push({...o,sourceId:r,targetId:i})}return s}const ms="#FF6B6B",xs="#95A5A6",An="#64748B";async function wi(e,t){const{states:n,transitions:s,annotations:o}=hs(e,t==null?void 0:t.viewpointFilter);if(n.length===0&&o.length===0)return{nodes:[],edges:[]};const r=De(n,e.relationships),i=ps(r,{focusStateId:t==null?void 0:t.focusStateId,collapsedStateIds:t==null?void 0:t.collapsedStateIds}),a=ys(fs(s,n),i);if(i.visible.size===0&&o.length===0)return{nodes:[],edges:[]};const c=I=>({width:Math.max(I.name.length*7.5+56,150),height:(r.childrenMap.get(I.id)??[]).some(v=>r.elements.has(v))?74:54}),l=I=>{const v=r.elements.get(I),A=(r.childrenMap.get(I)??[]).filter(E=>i.visible.has(E));return A.length===0?{id:I,...c(v)}:{id:I,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:A.map(l)}},f={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:i.roots.map(l),edges:a.map((I,v)=>({id:`st-${v}`,sources:[I.sourceId],targets:[I.targetId]}))},h=await oe.layout(f,{providerId:t==null?void 0:t.layoutProviderId}),x=[],m=new Map,p=(I,v,A={x:0,y:0})=>{var R,U;const E=r.elements.get(I.id);if(E){const Z=!!((R=I.children)!=null&&R.length),G=E.kind.endsWith("Machine"),q={x:A.x+(I.x??0),y:A.y+(I.y??0)};m.set(I.id,{...q,width:I.width??150,height:I.height??54,isContainer:Z}),x.push({id:I.id,type:"stateNode",position:{x:I.x??0,y:I.y??0},...v?{parentId:v,extent:"parent"}:{},data:{label:E.name,kind:E.kind,color:ms,isContainer:Z,isMachine:G,subtitle:E.attributes.modeKind,hasChildren:(r.childrenMap.get(I.id)??[]).some(tt=>r.elements.has(tt)),isCollapsed:!!((U=t==null?void 0:t.collapsedStateIds)!=null&&U.has(I.id)),hiddenCount:i.hiddenCount.get(I.id)??0,onToggleCollapse:t!=null&&t.onToggleCollapse?()=>t.onToggleCollapse(I.id):void 0,onDrillIn:t!=null&&t.onDrillIn?()=>t.onDrillIn(I.id):void 0},style:{width:I.width??150,height:I.height??54}});for(const tt of I.children??[])p(tt,I.id,q);return}};for(const I of h.children??[])p(I);if(o.length>0){let I=0,v=800;for(const Z of h.children??[])I=Math.max(I,(Z.y??0)+(Z.height??0)),v=Math.max(v,(Z.x??0)+(Z.width??0));const A=240,E=48,R=14,U=Math.max(2,Math.floor(v/(A+R)));o.forEach((Z,G)=>{x.push({id:Z.id,type:"stateNode",position:{x:G%U*(A+R),y:I+56+Math.floor(G/U)*(E+R)},data:{label:Z.name,kind:Z.kind,color:xs,isNote:!0},style:{width:A,height:E}})})}const y=[...m.entries()].filter(([,I])=>!I.isContainer).map(([I,v])=>({id:I,x:v.x,y:v.y,width:v.width,height:v.height})),d=Io({connectors:a.map((I,v)=>({id:I.element.id||`st-e-${v}`,sourceId:I.sourceId,targetId:I.targetId,label:I.label})),rects:m,obstacles:y,channelGap:26}),b=a.map((I,v)=>{const A=I.element.id||`st-e-${v}`,E=d.get(A),R={id:A,source:I.sourceId,target:I.targetId,label:I.label,style:{stroke:An,strokeWidth:nt.defaultWidth},markerEnd:{type:"arrowclosed",color:An,width:nt.arrowSize,height:nt.arrowSize}};return E?{...R,type:"interconnectionEdge",data:{points:E.points,labelPoint:E.labelPoint}}:{...R,type:"smoothstep",labelStyle:{fontSize:rt.badge,fill:"#6B7280",fontWeight:500},labelBgPadding:nt.labelBgPadding,labelBgBorderRadius:nt.labelBgRadius,labelBgStyle:nt.labelBgStyle}});return{nodes:x,edges:b}}const ws=/(?:Actor|User)$/,bs=new Set(["UseCase"]),Jn=new Set(["initiates","participatesin","performs","interactswith","includes","extends"]),Lt=e=>e.toLowerCase();function Qn(e){return ws.test(e.kind)||e.construct==="actor"}function on(e){return bs.has(e.kind)||e.construct==="use case"}function bi(e){const t=new Set(Object.values(e.elements).filter(on).map(o=>o.id)),n=new Map;for(const o of e.relationships.filter(r=>Lt(r.type)==="includes"&&t.has(r.sourceId)&&t.has(r.targetId)))n.set(o.targetId,[...n.get(o.targetId)??[],o.sourceId]);const s=(o,r=new Set)=>{if(r.has(o))return 0;const i=n.get(o)??[];return i.length===0?0:1+Math.min(...i.map(a=>s(a,new Set([...r,o]))))};return Math.max(0,...[...t].map(o=>s(o)))}function Ii(e){const t=Object.values(e.elements),n=new Set(t.filter(on).map(o=>o.id)),s=new Set(e.relationships.filter(o=>Jn.has(Lt(o.type))).flatMap(o=>n.has(o.sourceId)?[o.targetId]:n.has(o.targetId)?[o.sourceId]:[]));return t.filter(Qn).filter(o=>s.has(o.id)).map(o=>({id:o.id,name:o.name})).sort((o,r)=>o.name.localeCompare(r.name))}function Si(e){var o,r;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())??""]??((r=s==null?void 0:s[1])==null?void 0:r.toLowerCase())??"straight"}}function Mi(e,t={}){const n=Object.values(e.elements).filter(u=>!t.viewpointFilter||t.viewpointFilter(u)),s=n.filter(on),o=e.relationships.filter(u=>Jn.has(Lt(u.type))),r=new Map;for(const u of o.filter(S=>Lt(S.type)==="includes")){const S=r.get(u.targetId)??[];S.push(u.sourceId),r.set(u.targetId,S)}const i=(u,S=new Set)=>{if(S.has(u))return 0;const N=r.get(u)??[];return N.length===0?0:1+Math.min(...N.map(L=>i(L,new Set([...S,u]))))},a=t.level??"all",c=new Set(s.filter(u=>a==="all"||i(u.id)<=a).map(u=>u.id));let l=!0;for(;l;){l=!1;for(const u of o.filter(S=>Lt(S.type)==="extends"))if(c.has(u.sourceId)||c.has(u.targetId))for(const S of[u.sourceId,u.targetId])!c.has(S)&&s.some(N=>N.id===S)&&(c.add(S),l=!0)}const f=t.hiddenActorIds??new Set;for(const u of o){const S=c.has(u.sourceId)?u.targetId:c.has(u.targetId)?u.sourceId:void 0;S&&f.has(S)&&(c.delete(u.sourceId),c.delete(u.targetId))}const h=s.filter(u=>c.has(u.id)),x=n.filter(Qn).filter(u=>!f.has(u.id)).filter(u=>o.some(S=>S.sourceId===u.id&&c.has(S.targetId)||S.targetId===u.id&&c.has(S.sourceId))),m=new Set([...x,...h].map(u=>u.id));if(h.length===0)return{nodes:[],edges:[]};const p=new Set(o.filter(u=>Lt(u.type)==="extends").map(u=>u.sourceId)),y=new Map;for(const u of h){if(p.has(u.id))continue;const S=i(u.id);y.set(S,[...y.get(S)??[],u])}const b=[...y.keys()].sort((u,S)=>u-S).map(u=>[...y.get(u)??[]]);if(b.length===1&&b[0].length>4){const u=b[0],S=Math.min(3,Math.ceil(u.length/4)),N=Math.ceil(u.length/S);b.splice(0,1,...Array.from({length:S},(L,z)=>u.slice(z*N,(z+1)*N)))}const I=new Map;b.forEach((u,S)=>u.forEach(N=>I.set(N.id,S)));const v=new Map;for(const u of o.filter(S=>Lt(S.type)==="extends")){const S=h.find(z=>z.id===u.sourceId),N=I.get(u.targetId);if(!S||N===void 0||I.has(S.id))continue;const L=b[N];L.splice(L.findIndex(z=>z.id===u.targetId)+1,0,S),I.set(S.id,N),v.set(u.targetId,[...v.get(u.targetId)??[],S])}const A=new Set([...v.values()].flat().map(u=>u.id)),E=u=>o.filter(S=>S.sourceId===u||S.targetId===u).map(S=>S.sourceId===u?S.targetId:S.sourceId),R=new Map,U=()=>b.forEach(u=>u.forEach((S,N)=>R.set(S.id,N)));U(),x.forEach((u,S)=>R.set(u.id,S));const Z=u=>{const S=E(u).map(N=>R.get(N)).filter(N=>N!==void 0);return S.length===0?R.get(u)??0:S.reduce((N,L)=>N+L,0)/S.length};for(let u=0;u<3;u++){const S=u%2===0?b:[...b].reverse();for(const N of S){const L=N.filter(z=>!A.has(z.id));L.sort((z,ot)=>Z(z.id)-Z(ot.id)),N.splice(0,N.length,...L.flatMap(z=>[z,...v.get(z.id)??[]])),U()}x.sort((N,L)=>Z(N.id)-Z(L.id)),x.forEach((N,L)=>R.set(N.id,L))}const G=176,q=88,tt=104,wt=40,ht=104,et=88,Ct=116,kt=48,Y=62,Ft=44,It=76,pt=20,lt=Math.max(1,...b.map(u=>u.length)),St=Math.max(520,b.length*G+Math.max(b.length-1,0)*tt+kt*2),_t=Math.max(300,lt*q+(lt-1)*wt+Y+Ft),yt=u=>kt+u*(G+tt)+G/2,bt=new Map;for(const u of x){const S=E(u.id).map(L=>I.get(L)).filter(L=>L!==void 0).map(yt),N=S.length?S.reduce((L,z)=>L+z,0)/S.length:0;bt.set(u.id,S.length===0||N<=St/2?"left":"right")}const vt=x.filter(u=>bt.get(u.id)==="left"),M=x.filter(u=>bt.get(u.id)==="right"),j=pt+(vt.length?ht+It:0),$=pt,K=[{id:"__use_case_boundary__",type:"useCaseBoundary",position:{x:j,y:$},data:{label:t.systemName||"System Boundary",isFrame:!0,kind:"System Boundary"},style:{width:St,height:_t},draggable:!1,selectable:!1,zIndex:-1}],C=new Map,D=$+Y,H=_t-Y-Ft;b.forEach((u,S)=>{const N=u.length*q+(u.length-1)*wt;let L=D+(H-N)/2;for(const z of u){const ot={x:j+kt+S*(G+tt),y:L};C.set(z.id,ot),K.push({id:z.id,type:"useCase",position:ot,data:{label:z.name,kind:z.kind,color:"#E67E22",level:i(z.id)},style:{width:G,height:q}}),L+=q+wt}});for(const u of["left","right"]){const N=(u==="left"?vt:M).map(z=>{const ot=E(z.id).map(ut=>C.get(ut)).filter(ut=>!!ut).map(ut=>ut.y);return{actor:z,y:ot.length?ot.reduce((ut,Mt)=>ut+Mt,0)/ot.length:$+Y}}).sort((z,ot)=>z.y-ot.y);let L=-1/0;for(const{actor:z,y:ot}of N){const ut=Math.max(ot,L+Ct-et,pt);L=ut+et,K.push({id:z.id,type:"useCaseActor",position:{x:u==="left"?pt:j+St+It,y:ut},data:{label:z.name,kind:z.kind,color:"#334155",side:u},style:{width:ht,height:et}})}}const mt=t.edgeStyle??"straight",Dt=o.filter(u=>m.has(u.sourceId)&&m.has(u.targetId)).map(u=>{const S=M.some(z=>z.id===u.sourceId),N=S?u.targetId:u.sourceId,L=S?u.sourceId:u.targetId;return{edge:{id:u.id,source:N,target:L,label:/^(includes|extends)$/.test(Lt(u.type))?`«${Lt(u.type)}»`:void 0,type:"useCaseEdge",data:{routing:mt},style:{stroke:"#64748B",strokeWidth:1.4,strokeDasharray:/^(includes|extends)$/.test(Lt(u.type))?"5 4":void 0}},source:N,target:L}}),w=new Map(K.map(u=>[u.id,u])),O=u=>{var S,N;return{width:Number(((S=u.style)==null?void 0:S.width)??150),height:Number(((N=u.style)==null?void 0:N.height)??82)}},B=(u,S)=>{const N=O(w.get(u));return S==="left"?{x:0,y:N.height/2}:S==="right"?{x:N.width,y:N.height/2}:S==="top"?{x:N.width/2,y:0}:{x:N.width/2,y:N.height}},W=(u,S)=>{const N=w.get(u),L=B(u,S);return{x:N.position.x+L.x,y:N.position.y+L.y}},g=Dt.map(({edge:u,source:S,target:N})=>{var Et,Nt;const L=x.find(Wt=>Wt.id===S),z=x.find(Wt=>Wt.id===N),ot=!L&&!z&&I.get(S)!==void 0&&I.get(S)===I.get(N),ut=ot&&(((Et=C.get(S))==null?void 0:Et.y)??0)<(((Nt=C.get(N))==null?void 0:Nt.y)??0),Mt=L?M.includes(L)?"left":"right":ot?ut?"bottom":"top":"right",Tt=z?M.includes(z)?"left":"right":ot?ut?"top":"bottom":"left";return{id:u.id,source:W(S,Mt),target:W(N,Tt),sourceNodeId:S,targetNodeId:N,sourceSide:Mt,targetSide:Tt}}),T=K.filter(u=>u.type==="useCase"||u.type==="useCaseActor").map(u=>({id:u.id,x:u.position.x,y:u.position.y,...O(u)})),F=mt==="straight"?new Map:ge(g,T,28),P=Pe(Dt.flatMap(({edge:u})=>{const S=F.get(u.id),N=u.label;return N&&S&&S.length>=2?[{id:u.id,points:S,width:Re(N),height:Le}]:[]}),T),_=new Map(g.map(u=>[u.id,u])),V=Dt.map(({edge:u})=>({...u,data:{...u.data,points:F.get(u.id)??[],labelPoint:P.get(u.id),sourceOffset:B(u.source,_.get(u.id).sourceSide),targetOffset:B(u.target,_.get(u.id).targetSide),sourceSide:_.get(u.id).sourceSide,targetSide:_.get(u.id).targetSide}}));return{nodes:K,edges:V}}const Cn=new Set(["includesStep",...he]);function Fn(e){return e.kind.endsWith("Step")||!!e.attributes.stepOrder}function Is(e){if(!e)return;const t=e.split(":");return(t.length>1?t[t.length-1]:t[0]).trim()||void 0}function Ss(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 Tn=e=>{const t=Number(e.attributes.stepOrder);return Number.isFinite(t)?t:0};function Ms(e,t){const n=Object.values(e.elements),s=t?n.filter(t):n,o=s.filter(Fn),r=new Set(o.map(y=>y.id)),i=s.filter(y=>!Fn(y)&&e.relationships.some(d=>Cn.has(d.type)&&d.sourceId===y.id&&r.has(d.targetId))),a=[],c=new Map,l=y=>{const d=y.split(":")[0].trim()||y;return c.has(d)||(c.set(d,a.length),a.push({id:d,label:Ss(y,e)})),c.get(d)},f=y=>[...y].sort((d,b)=>Tn(d)-Tn(b)).map(d=>({step:d,lane:l(d.attributes.allocatedFunction??d.allocatedTo??d.id),item:Is(d.attributes.exchangeItem)})),h=y=>{var b;const d=e.relationships.find(I=>I.type==="realizesScenario"&&I.sourceId===y.id);return d?(b=e.elements[d.targetId])==null?void 0:b.name:void 0},x=new Set,m=[];for(const y of i){const d=e.relationships.filter(b=>Cn.has(b.type)&&b.sourceId===y.id&&r.has(b.targetId)).map(b=>e.elements[b.targetId]);for(const b of d)x.add(b.id);m.push({chain:y,scenario:h(y),occurrences:f(d)})}const p=o.filter(y=>!x.has(y.id));return p.length>0&&m.push({occurrences:f(p)}),{lifelines:a,sections:m.filter(y=>y.occurrences.length>0)}}const ae=240,vs=52,Es=68,ks=40,As=24,Nn=14;function vi(e,t){const n=Ms(e,t==null?void 0:t.viewpointFilter);if(n.lifelines.length===0)return{nodes:[],edges:[]};const s=[],o=[],r=f=>f*ae+ae/2;let i=vs+28;const a=[];for(const f of n.sections){const h=i;i+=ks;const x=f.occurrences.map(m=>{const p={...m,y:i};return i+=Es,p});a.push({section:f,top:h,bottom:i,placed:x}),i+=As}const c=i,l=n.lifelines.length*ae;return n.lifelines.forEach((f,h)=>{s.push({id:`__lifeline_${f.id}`,type:"seqLifeline",position:{x:h*ae,y:0},data:{label:f.label},style:{width:ae,height:c},draggable:!1,selectable:!1,zIndex:-2})}),a.forEach(({section:f,top:h,bottom:x,placed:m},p)=>{var y;s.push({id:`__section_${p}`,type:"seqSection",position:{x:-24,y:h},data:{label:((y=f.chain)==null?void 0:y.name)??"Steps",scenario:f.scenario},style:{width:l+48,height:x-h},draggable:!1,selectable:!1,zIndex:-1}),m.forEach((d,b)=>{if(s.push({id:d.step.id,type:"seqOccurrence",position:{x:r(d.lane)-Nn/2,y:d.y-Nn/2},data:{label:d.step.name,kind:d.step.kind},draggable:!1,zIndex:2}),b<m.length-1){const I=m[b+1],v=I.lane>=d.lane,A=I.lane===d.lane;o.push({id:`seq-${p}-${b}`,source:d.step.id,target:I.step.id,sourceHandle:A||v?"right":"left",targetHandle:A?"right":v?"left":"right",type:A?"smoothstep":"straight",label:d.item,style:{stroke:"#3498DB",strokeWidth:nt.flowWidth},labelStyle:{fontSize:rt.badge,fill:"#4A90D9",fontWeight:600},labelBgPadding:nt.labelBgPadding,labelBgBorderRadius:nt.labelBgRadius,labelBgStyle:nt.labelBgStyle,markerEnd:{type:"arrowclosed",color:"#3498DB",width:nt.arrowSize,height:nt.arrowSize},zIndex:1})}})}),{nodes:s,edges:o}}const Cs=new Set(["interactsincontext","interactswith","exchangeswith","appliesincontext","connectsphysically"]),Ve=new Set(["Actor","User"]),Ae=e=>e.toLowerCase(),qe=e=>e.kind==="UseContext"||/environment|context/i.test(e.name)||/environment/i.test(String(e.attributes.entityKind??"")),Fs=e=>/systemofinterest|system-of-interest/i.test(String(e.attributes.contextRole??""))||String(e.attributes.isSystemOfInterest??"").toLowerCase()==="true",Bt=76,to=170,Ts=238,be=30,ce=104,Ie=240,Se=108,Me=92,ve=74,Ze=40,Ee=e=>Math.min(Math.max(e.length*7.4+28,to),Ts),Ns=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"},Os=e=>{var t;return((t=e.attributes)==null?void 0:t.interactionLabel)||`«${Ae(e.type)}»`};function _s(e,t,n){const s=new Map,o=[];for(const r of e){const i=t.some(c=>c.sourceId===r&&c.targetId===n),a=t.some(c=>c.sourceId===n&&c.targetId===r);i&&!a?s.set(r,"left"):a&&!i?s.set(r,"right"):o.push(r)}for(const r of o){const i=[...s.values()].filter(c=>c==="left").length,a=s.size-i;s.set(r,i<=a?"left":"right")}return s}function Ei(e,t,n={}){var bt,vt;const s=Object.values(e.elements).filter(M=>!n.viewpointFilter||n.viewpointFilter(M)),o=(bt=n.relationshipTypes)!=null&&bt.length?new Set(n.relationshipTypes.map(Ae)):void 0,r=e.relationships.filter(M=>Cs.has(Ae(M.type))&&(!o||o.has(Ae(M.type)))),i=new Set(r.flatMap(M=>[M.sourceId,M.targetId])),a=s.filter(M=>i.has(M.id)&&!Gn(M));if(a.length===0)return{nodes:[],edges:[]};const c=M=>r.filter(j=>j.sourceId===M.id||j.targetId===M.id).length,l=a.find(Fs)??a.find(M=>/system/i.test(M.name))??[...a].sort((M,j)=>c(j)-c(M))[0],f=a.filter(M=>M.id!==l.id),h=new Set([l.id,...f.map(M=>M.id)]),x=r.filter(M=>h.has(M.sourceId)&&h.has(M.targetId)),m=_s(f.map(M=>M.id),x,l.id);for(const M of x){const j=Ns(M);j&&m.set(M.sourceId,j)}const p=M=>Ve.has(M.kind)?0:qe(M)?1:2,y=M=>f.filter(j=>m.get(j.id)===M).sort((j,$)=>p(j)-p($)||j.name.localeCompare($.name)),d={left:y("left"),right:y("right"),top:y("top"),bottom:y("bottom")},b=M=>M.length===0?0:M.length*Bt+(M.length-1)*be,I=M=>M.length===0?0:Math.max(...M.map(j=>Ee(j.name))),v=M=>M.length===0?0:M.reduce((j,$)=>j+Ee($.name),0)+(M.length-1)*be,A=Ie+Me*2,E=Se+ve*2,R=I(d.left),U=Ze+(R>0?R+ce:0)+Math.max(A,v(d.top),v(d.bottom))/2,Z=Ze+(d.top.length>0?Bt+ce:0)+Math.max(E,b(d.left),b(d.right))/2,G=U-A/2,q=Z-E/2,tt=G+A+(d.right.length>0?ce:0),wt=[{id:"__context_boundary__",type:"contextBoundary",position:{x:G,y:q},style:{width:A,height:E},data:{label:`${t??l.name} — System Boundary`,isFrame:!0,minWidth:Ie+Me*2,minHeight:Se+ve*2},zIndex:-1},{id:l.id,type:"contextSystem",parentId:"__context_boundary__",extent:"parent",position:{x:Me,y:ve},data:{label:l.name,kind:l.kind},style:{width:Ie,height:Se}}],ht=new Map;for(const M of["left","right"]){const j=d[M];let $=Z-b(j)/2;for(const K of j){const C=Ee(K.name),D=M==="left"?Ze+R-C:tt;ht.set(K.id,{x:D,y:$,width:C,height:Bt,side:M}),wt.push({id:K.id,type:"contextExternal",position:{x:D,y:$},data:{label:K.name,kind:K.kind,category:qe(K)?"environment":Ve.has(K.kind)?"person":"system"},style:{width:C,height:Bt}}),$+=Bt+be}}for(const M of["top","bottom"]){const j=d[M],$=v(j);let K=U-$/2;const C=M==="top"?q-ce-Bt:q+E+ce;for(const D of j){const H=Ee(D.name);ht.set(D.id,{x:K,y:C,width:H,height:Bt,side:M}),wt.push({id:D.id,type:"contextExternal",position:{x:K,y:C},data:{label:D.name,kind:D.kind,category:qe(D)?"environment":Ve.has(D.kind)?"person":"system"},style:{width:H,height:Bt}}),K+=H+be}}const et={x:G+Me,y:q+ve,width:Ie,height:Se},Ct={left:[],right:[],top:[],bottom:[]};for(const M of x){const j=M.sourceId===l.id?M.targetId:M.sourceId;if(M.sourceId!==l.id&&M.targetId!==l.id)continue;const $=(vt=ht.get(j))==null?void 0:vt.side;$&&!Ct[$].includes(M.id)&&Ct[$].push(M.id)}for(const M of["left","right"])Ct[M].sort((j,$)=>{const K=C=>{var H;const D=x.find(mt=>mt.id===C);return((H=ht.get(D.sourceId===l.id?D.targetId:D.sourceId))==null?void 0:H.y)??0};return K(j)-K($)});const kt=(M,j)=>{const $=Ct[j],K=Math.max($.indexOf(M),0);return{x:j==="left"?et.x:j==="right"?et.x+et.width:et.x+et.width*(K+.5)/Math.max($.length,1),y:j==="top"?et.y:j==="bottom"?et.y+et.height:et.y+et.height*(K+.5)/Math.max($.length,1)}},Y=(M,j)=>{const $=ht.get(M);return j==="top"?{x:$.x+$.width/2,y:$.y}:j==="bottom"?{x:$.x+$.width/2,y:$.y+$.height}:{x:j==="left"?$.x:$.x+$.width,y:$.y+$.height/2}},Ft=(M,j)=>{var H;if(M===l.id)return((H=ht.get(j))==null?void 0:H.side)??"left";const $=ht.get(M),K=j===l.id?et:ht.get(j),C={x:$.x+$.width/2,y:$.y+$.height/2},D={x:K.x+K.width/2,y:K.y+K.height/2};return Math.abs(D.y-C.y)>Math.abs(D.x-C.x)?D.y<C.y?"top":"bottom":K.x+(j===l.id?et.width:ht.get(j).width)/2>=$.x+$.width/2?"right":"left"},It=x.map(M=>{const j=Ft(M.sourceId,M.targetId),$=Ft(M.targetId,M.sourceId),K=(C,D)=>C===l.id?kt(M.id,D):Y(C,D);return{rel:M,sourceSide:j,targetSide:$,source:K(M.sourceId,j),target:K(M.targetId,$)}}),pt=wt.filter(M=>!M.data.isFrame).map(M=>{var j,$;return{id:M.id,x:M.position.x,y:M.position.y,width:Number(((j=M.style)==null?void 0:j.width)??to),height:Number((($=M.style)==null?void 0:$.height)??Bt)}}),lt=ge(It.map(M=>({id:M.rel.id,source:M.source,target:M.target,sourceNodeId:M.rel.sourceId,targetNodeId:M.rel.targetId,sourceSide:M.sourceSide,targetSide:M.targetSide})),pt,24),St=new Map(It.map(M=>[M.rel.id,Os(M.rel)])),_t=Pe(It.flatMap(M=>{const j=lt.get(M.rel.id),$=St.get(M.rel.id);return j&&j.length>=2?[{id:M.rel.id,points:j,width:Re($),height:Le}]:[]}),pt),yt=It.map(M=>{const j=($,K,C)=>{const D=$===l.id?et:ht.get($);return{x:C.x-D.x,y:C.y-D.y,side:K}};return{id:M.rel.id,source:M.rel.sourceId,target:M.rel.targetId,type:"useCaseEdge",label:St.get(M.rel.id),style:{stroke:"#0F766E",strokeWidth:1.5},data:{routing:"rounded",points:lt.get(M.rel.id)??[M.source,M.target],labelPoint:_t.get(M.rel.id),sourceSide:M.sourceSide,targetSide:M.targetSide,sourceOffset:j(M.rel.sourceId,M.sourceSide,M.source),targetOffset:j(M.rel.targetId,M.targetSide,M.target)}}});return{nodes:wt,edges:yt}}const Ds=new Set(["name","title","description","shortDescription","longDescription","sourceReference","rationaleText","semantics","queryDescription","dataSourceDescription","doc"]),Ps=7,en=80;function Ls(e,t){const n=e.attributes[t];return n===void 0?void 0:(n.includes("::")?n.split("::").pop().trim():n)||void 0}function Rs(e){const t=new Map;for(const n of e)for(const s of Object.keys(n.attributes))Ds.has(s)||s.includes(".")||t.set(s,(t.get(s)??0)+1);return[...t.entries()].sort((n,s)=>s[1]-n[1]).slice(0,Ps).map(([n])=>n)}function js(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 r=Rs(o),i=o.map(c=>({element:c,values:r.map(l=>Ls(c,l))})),a=r.map((c,l)=>{const f=i.map(h=>h.values[l]).filter(h=>h!==void 0);return f.length>0&&f.every(h=>Number.isFinite(Number(h)))});n.push({kind:s,columns:r,numeric:a,rows:i})}return n.sort((s,o)=>o.rows.length-s.rows.length)}function $s(e,t,n){const s=n==="asc"?1:-1;return[...e.rows].sort((r,i)=>{if(t<0)return r.element.name.localeCompare(i.element.name)*s;const a=r.values[t],c=i.values[t];return a===void 0&&c===void 0?0:a===void 0?1:c===void 0?-1:e.numeric[t]?(Number(a)-Number(c))*s:a.localeCompare(c)*s})}function Bs(e,t,n){const s=new Map(e.map(h=>[h.id,h])),o=n!=null&&n.length?new Set(n.map(h=>h.toLowerCase())):void 0,r=t.filter(h=>s.has(h.sourceId)&&s.has(h.targetId)&&h.sourceId!==h.targetId&&(!o||o.has(h.type.toLowerCase())));if(r.length===0)return;const i=new Set,a=new Set,c=new Map,l=new Set;for(const h of r){i.add(h.sourceId),a.add(h.targetId),l.add(h.type);const x=`${h.sourceId}|${h.targetId}`;c.has(x)||c.set(x,[]),c.get(x).includes(h.type)||c.get(x).push(h.type)}const f=(h,x)=>h.kind.localeCompare(x.kind)||h.name.localeCompare(x.name);return{rows:[...i].map(h=>s.get(h)).sort(f),cols:[...a].map(h=>s.get(h)).sort(f),cells:c,relTypes:[...l].sort()}}const Oe={padding:"6px 10px",fontSize:rt.xs,fontWeight:600,color:"#374151",textAlign:"left",borderBottom:"2px solid #E5E5E0",background:"#FAFAF8",position:"sticky",top:0,cursor:"pointer",whiteSpace:"nowrap",userSelect:"none"},_e={padding:"5px 10px",fontSize:rt.xs,color:"#374151",borderBottom:"1px solid #F0F0ED",verticalAlign:"top"};function Hs(e){return e.length>en?`${e.slice(0,en-1)}…`:e}function Ws({section:e,search:t}){var h;const n=de(x=>x.selectElement),[s,o]=ct.useState(-1),[r,i]=ct.useState("asc"),a=ct.useMemo(()=>{const x=$s(e,s,r);if(!t)return x;const m=t.toLowerCase();return x.filter(p=>p.element.name.toLowerCase().includes(m)||p.values.some(y=>y==null?void 0:y.toLowerCase().includes(m)))},[e,s,r,t]);if(a.length===0)return null;const c=Ht[(h=e.rows[0])==null?void 0:h.element.layer]||"#6B7280",l=x=>{s===x?i(m=>m==="asc"?"desc":"asc"):(o(x),i("asc"))},f=x=>s===x?r==="asc"?" ↑":" ↓":"";return k.jsxs("div",{style:{marginBottom:28},children:[k.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[k.jsx("span",{style:{width:8,height:8,borderRadius:2,background:c,display:"inline-block"}}),k.jsx("span",{style:{fontSize:rt.sm,fontWeight:700,color:"#1B3A4B"},children:e.kind}),k.jsx("span",{style:{fontSize:rt.xs,color:"#9CA3AF"},children:a.length})]}),k.jsxs("table",{style:{borderCollapse:"collapse",width:"100%",background:"#FFFFFF",borderRadius:8,overflow:"hidden",border:"1px solid #E5E5E0"},children:[k.jsx("thead",{children:k.jsxs("tr",{children:[k.jsxs("th",{style:Oe,onClick:()=>l(-1),children:["Element",f(-1)]}),e.columns.map((x,m)=>k.jsxs("th",{style:Oe,onClick:()=>l(m),children:[x,f(m)]},x))]})}),k.jsx("tbody",{children:a.map(x=>k.jsxs("tr",{onMouseEnter:m=>{m.currentTarget.style.background="#F7F7F5"},onMouseLeave:m=>{m.currentTarget.style.background="transparent"},children:[k.jsx("td",{style:{..._e,whiteSpace:"nowrap"},children:k.jsx("button",{onClick:()=>n(x.element.id),style:{background:"none",border:"none",padding:0,fontSize:rt.xs,fontWeight:600,color:"#1B6FD9",cursor:"pointer",textDecoration:"none"},title:"Open element detail",children:x.element.name})}),x.values.map((m,p)=>k.jsx("td",{style:_e,title:m&&m.length>en?m:void 0,children:m?Hs(m):k.jsx("span",{style:{color:"#D1D5DB"},children:"—"})},p))]},x.element.id))})]})]})}function zs({elements:e,model:t,relationshipTypes:n}){const s=de(i=>i.selectElement),o=ct.useMemo(()=>Bs(e,t.relationships,n),[e,t.relationships,n]);if(!o)return k.jsx("div",{style:{color:"#9CA3AF",fontSize:rt.sm,padding:24},children:"No relationships among this view's elements."});const r=(i,a=!1)=>k.jsx("button",{onClick:()=>s(i.id),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontSize:"10px",fontWeight:600,color:"#374151",...a?{writingMode:"vertical-rl",transform:"rotate(180deg)",maxHeight:120}:{},whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:180},title:`${i.kind} · open detail`,children:i.name});return k.jsxs("div",{children:[k.jsx("div",{className:"flex gap-3 mb-2",style:{fontSize:rt.xs,color:"#6B7280"},children:o.relTypes.map(i=>k.jsxs("span",{className:"flex items-center gap-1",children:[k.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:qt[i]||"#6B7280",display:"inline-block"}}),i]},i))}),k.jsxs("table",{style:{borderCollapse:"collapse",background:"#FFFFFF",border:"1px solid #E5E5E0"},children:[k.jsx("thead",{children:k.jsxs("tr",{children:[k.jsx("th",{style:{...Oe,cursor:"default"}}),o.cols.map(i=>k.jsx("th",{style:{...Oe,cursor:"default",verticalAlign:"bottom",padding:"8px 4px"},children:r(i,!0)},i.id))]})}),k.jsx("tbody",{children:o.rows.map(i=>k.jsxs("tr",{children:[k.jsx("td",{style:{..._e,whiteSpace:"nowrap",background:"#FAFAF8"},children:r(i)}),o.cols.map(a=>{const c=o.cells.get(`${i.id}|${a.id}`);return k.jsx("td",{style:{..._e,textAlign:"center",padding:"4px 6px"},title:c==null?void 0:c.join(", "),children:c==null?void 0:c.map(l=>k.jsx("span",{style:{width:9,height:9,borderRadius:"50%",margin:1,background:qt[l]||"#6B7280",display:"inline-block"}},l))},a.id)})]},i.id))})]})]})}function ki({diagram:e,model:t,viewpointFilter:n}){const[s,o]=ct.useState("table"),[r,i]=ct.useState(""),a=ct.useMemo(()=>{const f=Object.values(t.elements);return n?f.filter(n):f},[t,n]),c=ct.useMemo(()=>js(a),[a]),l=Dn.grid;return k.jsx("div",{className:"flex-1 overflow-auto",style:{background:"#F7F7F5"},children:k.jsxs("div",{style:{padding:"16px 20px",maxWidth:1240},children:[k.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[k.jsx("span",{className:"px-1.5 py-0.5 rounded font-semibold",style:{background:l.color+"20",color:l.color,fontSize:rt.badge},title:l.fullName,children:l.label}),k.jsx("span",{style:{fontSize:rt.md,fontWeight:700,color:"#1a1a1a"},children:e.name}),k.jsxs("span",{style:{fontSize:rt.xs,color:"#9CA3AF"},children:[a.length," elements"]}),k.jsx("div",{className:"flex rounded overflow-hidden ml-2",style:{border:"1px solid #E5E5E0"},children:["table","matrix"].map(f=>k.jsx("button",{onClick:()=>o(f),className:"px-2 py-0.5 text-xs font-medium capitalize",style:{background:s===f?"#1B3A4B":"#FFFFFF",color:s===f?"#FFFFFF":"#6B7280",border:"none",cursor:"pointer"},children:f},f))}),s==="table"&&k.jsx("input",{value:r,onChange:f=>i(f.target.value),placeholder:"Filter rows…",className:"px-2 py-1 rounded focus:outline-none ml-auto",style:{fontSize:rt.xs,border:"1px solid #E5E5E0",background:"#FFFFFF",color:"#1a1a1a",width:200}})]}),s==="table"?c.map(f=>k.jsx(Ws,{section:f,search:r},f.kind)):k.jsx(zs,{elements:a,model:t,relationshipTypes:e.relationshipTypes}),s==="table"&&c.length===0&&k.jsx("div",{style:{color:"#9CA3AF",fontSize:rt.sm,padding:24},children:"This view selects no elements."})]})})}const Gs=8;function eo(e,t,n){const s=(t.get(e.id)??[]).filter(o=>n.has(o)).map(o=>eo(n.get(o),t,n));return s.sort(Ce),{id:e.id,label:e.name,element:e,kind:e.kind,layer:e.layer,children:s,count:1+s.reduce((o,r)=>o+r.count,0)}}const Ce=(e,t)=>(e.kind??"").localeCompare(t.kind??"")||e.label.localeCompare(t.label);function Ys(e,t){const n=De(e,t),s=new Map,o=[];for(const r of n.roots){const i=n.elements.get(r),a=eo(i,n.childrenMap,n.elements),c=i.package;if(!c){o.push(a);continue}if(!s.has(c)){const f=c.split("::").pop()??c,h={id:`pkg:${c}`,label:f,title:c,children:[],count:0};s.set(c,h),o.push(h)}const l=s.get(c);l.children.push(a),l.count+=a.count}for(const r of s.values()){const i=new Set(r.children.map(c=>c.kind));if(r.children.length<=Gs||i.size<=1){r.children.sort(Ce);continue}const a=new Map;for(const c of r.children){const l=c.kind??"—";a.has(l)||a.set(l,[]),a.get(l).push(c)}r.children=[...a.entries()].sort((c,l)=>c[0].localeCompare(l[0])).map(([c,l])=>{var f;return{id:`kind:${r.id}:${c}`,label:c,kind:c,layer:(f=l[0])==null?void 0:f.layer,children:l.sort(Ce),count:l.reduce((h,x)=>h+x.count,0)}})}return o.sort(Ce),o}function Us(e,t){const n=t.trim().toLowerCase();if(!n)return;const s=new Set,o=new Set,r=(i,a)=>{const c=i.label.toLowerCase().includes(n)||(i.kind??"").toLowerCase().includes(n);let l=!1;for(const f of i.children)r(f,[...a,i.id])&&(l=!0);if(c||l){s.add(i.id);for(const f of a)s.add(f),o.add(f);return l&&o.add(i.id),!0}return!1};for(const i of e)r(i,[]);return{visible:s,expanded:o}}function Xs(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()}function no({node:e,depth:t,expanded:n,visible:s,forceExpanded:o,onToggle:r}){const i=de(p=>p.selectElement),a=de(p=>p.selectedElementId),c=de(p=>p.deleteModelElement);if(s&&!s.has(e.id))return null;const l=n.has(e.id)||!!(o!=null&&o.has(e.id)),f=e.children.length>0,h=!e.element,x=Ht[e.layer??""]||"#95A5A6",m=e.element&&e.id===a;return k.jsxs(k.Fragment,{children:[k.jsx(co,{id:e.id,label:e.label,depth:t,hasChildren:f,expanded:l,selected:!!m,badge:h?e.id.startsWith("pkg:")?"PKG":"GRP":Xs(e.kind),badgeColor:x,count:f?e.count:void 0,title:e.title??e.kind,onClick:()=>{f&&r(e.id),e.element&&i(e.id)},onDelete:e.element?()=>c(e.id):void 0}),l&&e.children.map(p=>k.jsx(no,{node:p,depth:t+1,expanded:n,visible:s,forceExpanded:o,onToggle:r},p.id))]})}function Ai({diagram:e,model:t,viewpointFilter:n}){const[s,o]=ct.useState(new Set),[r,i]=ct.useState(""),a=ct.useMemo(()=>{const p=Object.values(t.elements);return n?p.filter(n):p},[t,n]),c=ct.useMemo(()=>Ys(a,t.relationships),[a,t.relationships]),l=ct.useMemo(()=>Us(c,r),[c,r]),f=ct.useCallback(p=>{o(y=>{const d=new Set(y);return d.has(p)?d.delete(p):d.add(p),d})},[]),h=ct.useCallback((p,y)=>{for(const d of p)d.children.length>0&&(y.add(d.id),h(d.children,y));return y},[]),x=Dn.browser,m=a.length;return k.jsx("div",{className:"flex-1 overflow-auto",style:{background:"#F7F7F5"},children:k.jsxs("div",{style:{padding:"16px 20px",maxWidth:860},children:[k.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[k.jsx("span",{className:"px-1.5 py-0.5 rounded font-semibold",style:{background:x.color+"20",color:x.color,fontSize:rt.badge},title:x.fullName,children:x.label}),k.jsx("span",{style:{fontSize:rt.md,fontWeight:700,color:"#1a1a1a"},children:e.name}),k.jsxs("span",{style:{fontSize:rt.xs,color:"#9CA3AF"},children:[m," elements"]}),k.jsx("button",{onClick:()=>o(h(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"}),k.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"}),k.jsx("input",{value:r,onChange:p=>i(p.target.value),placeholder:"Filter by name or kind…",className:"px-2 py-1 rounded focus:outline-none ml-auto",style:{fontSize:rt.xs,border:"1px solid #E5E5E0",background:"#FFFFFF",color:"#1a1a1a",width:220}})]}),k.jsxs("div",{style:{background:"#FFFFFF",border:"1px solid #E5E5E0",borderRadius:10,padding:"10px 8px"},children:[c.length===0&&k.jsx("div",{style:{color:"#9CA3AF",fontSize:rt.sm,padding:16},children:"This view selects no elements."}),c.map(p=>k.jsx(no,{node:p,depth:0,expanded:s,visible:l==null?void 0:l.visible,forceExpanded:l==null?void 0:l.expanded,onToggle:f},p.id)),l&&c.every(p=>!l.visible.has(p.id))&&k.jsxs("div",{style:{color:"#9CA3AF",fontSize:rt.sm,padding:16},children:["No matches for “",r,"”."]})]})]})})}function Ci({x:e,y:t,sourceElement:n,targetElement:s,registries:o,allowedTypes:r,onSelect:i,onCancel:a}){const c=ct.useRef(null),[l,f]=ct.useState(""),[h,x]=ct.useState(""),m=ct.useRef(null);ct.useEffect(()=>{var A;(A=m.current)==null||A.focus()},[]),ct.useEffect(()=>{const A=E=>{c.current&&!c.current.contains(E.target)&&a()};return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[a]),ct.useEffect(()=>{const A=E=>{E.key==="Escape"&&a()};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[a]);const p=ct.useMemo(()=>{const A=io(n,s,o);if(!(r!=null&&r.length))return A;const E=new Set(r.map(R=>R.toLowerCase()));return A.filter(R=>E.has(R.definition.name.toLowerCase())||E.has(R.definition.sysmlName.toLowerCase()))},[n,s,o,r]),y=ct.useMemo(()=>{const A=l.trim().toLowerCase();return A?p.filter(E=>E.definition.label.toLowerCase().includes(A)||E.definition.name.toLowerCase().includes(A)):p},[p,l]),d=260,b=320,I=Math.min(e,window.innerWidth-d-8),v=Math.min(t,window.innerHeight-b-8);return k.jsxs("div",{ref:c,className:"fixed z-50 flex flex-col shadow-xl rounded-xl overflow-hidden",style:{left:I,top:v,width:d,maxHeight:b,background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 8px 32px rgba(0,0,0,0.16)"},children:[k.jsxs("div",{className:"px-3 py-2",style:{borderBottom:"1px solid #E5E5E0",flexShrink:0},children:[k.jsx("div",{style:{fontSize:rt.xs,fontWeight:600,color:"#374151",marginBottom:4},children:"Relationship Type"}),k.jsxs("div",{style:{fontSize:"10px",color:"#9CA3AF",marginBottom:4},children:[n.kind," → ",s.kind]}),k.jsx("input",{ref:m,value:l,onChange:A=>f(A.target.value),placeholder:"Search…","aria-label":"Search relationship types",className:"w-full px-2 py-1 rounded focus:outline-none",style:{fontSize:rt.xs,background:"#F7F7F5",border:"1px solid #E5E5E0",color:"#374151"}}),k.jsx("input",{value:h,onChange:A=>x(A.target.value),placeholder:"Transported item / flow label (optional)","aria-label":"Transported item or flow label",className:"w-full px-2 py-1 rounded focus:outline-none",style:{marginTop:6,fontSize:rt.xs,background:"#F7F7F5",border:"1px solid #E5E5E0",color:"#374151"}})]}),k.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[y.map(A=>{const{definition:E,direction:R,sourceId:U,targetId:Z}=A,G=R==="incoming";return k.jsxs("button",{onClick:()=>i({type:E.name,sourceId:U,targetId:Z,direction:R,flowItem:h.trim()||void 0}),className:"w-full flex items-center gap-2.5 px-3 py-1.5 text-left",style:{background:"none",border:"none",cursor:"pointer"},onMouseEnter:q=>{q.currentTarget.style.background="#F7F7F5"},onMouseLeave:q=>{q.currentTarget.style.background="none"},children:[k.jsx("div",{style:{width:10,height:10,borderRadius:"50%",flexShrink:0,background:qt[E.name]??"#6B7280"}}),k.jsxs("div",{style:{minWidth:0},children:[k.jsxs("div",{style:{fontSize:rt.xs,fontWeight:500,color:"#1a1a1a"},children:[E.label,G&&k.jsx("span",{style:{color:"#9CA3AF",fontWeight:400},children:" (reversed)"})]}),k.jsxs("div",{className:"truncate",style:{fontSize:"10px",color:"#9CA3AF"},children:[E.sourceEnd.name," → ",E.targetEnd.name]})]})]},`${E.name}-${R}`)}),y.length===0&&k.jsx("div",{className:"p-3 text-center",style:{color:"#9CA3AF",fontSize:rt.xs},children:p.length===0?`The ontology defines no relationship between a ${n.kind} and a ${s.kind}.`:"No matching types"})]})]})}function Fi(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)??ao}const On={AcceptActionUsage:"accept",SendActionUsage:"send",DecisionNodeUsage:"decision",MergeNodeUsage:"merge",ForkNodeUsage:"fork",JoinNodeUsage:"join",TerminateActionUsage:"activity-final",ActivityFinalNodeUsage:"activity-final",FlowFinalNodeUsage:"flow-final"},_n={action:"usage",accept:"accept",send:"send",decision:"decision",merge:"merge",fork:"fork",join:"join",activityFinal:"activity-final",flowFinal:"flow-final"};function Ks(e){return e.isDefinition?"definition":e.metaclass&&On[e.metaclass]?On[e.metaclass]:e.metaclass&&_n[e.metaclass]?_n[e.metaclass]:"usage"}const le=e=>typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&Number.isFinite(Number.parseFloat(e))?Number.parseFloat(e):void 0;function Vs(e){const t=new Map(e.map(r=>[r.id,r])),n=[],s=new Set,o=r=>{s.has(r.id)||(s.add(r.id),r.parentId&&t.has(r.parentId)&&o(t.get(r.parentId)),n.push(r))};return e.forEach(o),n}function Ti(e,t){const n=new Set(e.map(o=>o.id));return{nodes:Vs(e).map(o=>{var p,y,d,b;const r=o.data??{},i=typeof r.label=="string"&&r.label?r.label:o.id,a=typeof r.kind=="string"?r.kind:o.type??"",c=/definition$| def$/i.test(a)||r.isDefinition===!0,l=typeof r.nodeType=="string"?r.nodeType:a,f=r.isFrame===!0?"frame":r.genericRecord===!0?"generic":Ks({metaclass:l||a,isDefinition:c,viewKind:typeof r.viewKind=="string"?r.viewKind:void 0}),h=Array.isArray(r.ports)?r.ports.filter(I=>!!I&&typeof I=="object"&&typeof I.id=="string"):[],x=h.length?h:[...Array.isArray(r.inPorts)?r.inPorts.filter(I=>typeof I=="string").map((I,v)=>({id:`in:${I}`,name:I,side:"left",direction:"in",pin:!0,_i:v})):[],...Array.isArray(r.outPorts)?r.outPorts.filter(I=>typeof I=="string").map((I,v)=>({id:`out:${I}`,name:I,side:"right",direction:"out",pin:!0,_i:v})):[]],m=Array.isArray(r.compartments)?r.compartments:void 0;return{id:o.id,subjectId:typeof r.subjectId=="string"?r.subjectId:o.id,...o.parentId&&n.has(o.parentId)?{parentId:o.parentId}:{},x:((p=o.position)==null?void 0:p.x)??0,y:((y=o.position)==null?void 0:y.y)??0,width:le(o.width)??le((d=o.style)==null?void 0:d.width)??Math.max(130,i.length*7.5+48),height:le(o.height)??le((b=o.style)==null?void 0:b.height)??52,label:i,kind:a,glyph:f,color:[r.bgColor,r.color,r.layerColor].find(I=>typeof I=="string"&&!!I)??"#6B7280",isDefinition:c,isFrame:r.isFrame===!0,...x.length?{ports:x}:{},...m!=null&&m.length?{compartments:m}:{},...Array.isArray(r.memberIds)?{memberIds:r.memberIds}:{},...r.orientation==="row"||r.orientation==="column"?{orientation:r.orientation}:{},accessibilityText:`${f} ${i}${a?` (${a})`:""}`,...r.diagnostic&&typeof r.diagnostic=="object"?{diagnostic:r.diagnostic}:{}}}),edges:t.filter(o=>n.has(o.source)&&n.has(o.target)).map(o=>{var i,a,c;const r=o.style;return{id:o.id,subjectId:typeof((i=o.data)==null?void 0:i.subjectId)=="string"?o.data.subjectId:o.id,sourceId:o.source,targetId:o.target,...typeof o.label=="string"&&o.label?{label:o.label}:{},...o.sourceHandle?{sourcePortId:o.sourceHandle}:{},...o.targetHandle?{targetPortId:o.targetHandle}:{},color:typeof(r==null?void 0:r.stroke)=="string"?r.stroke:"#9CA3AF",strokeWidth:le(r==null?void 0:r.strokeWidth)??1.5,dashed:typeof(r==null?void 0:r.strokeDasharray)=="string",animated:o.animated===!0,...typeof((a=o.data)==null?void 0:a.routing)=="string"?{routing:o.data.routing}:{},points:Array.isArray((c=o.data)==null?void 0:c.points)&&o.data.points.length>2?o.data.points.slice(1,-1):[]}})}}function Ni(e){const t=i=>i.replace(/[&<>"']/g,a=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[a]),n=Math.max(1,...e.nodes.map(i=>i.x+i.width+24)),s=Math.max(1,...e.nodes.map(i=>i.y+i.height+24)),o=i=>{const a=i.glyph==="decision"||i.glyph==="merge"?`<polygon points="${i.x+i.width/2},${i.y} ${i.x+i.width},${i.y+i.height/2} ${i.x+i.width/2},${i.y+i.height} ${i.x},${i.y+i.height/2}"/>`:i.glyph==="fork"||i.glyph==="join"?`<rect x="${i.x}" y="${i.y+i.height/2-4}" width="${i.width}" height="8" rx="2" fill="#111"/>`:i.glyph==="activity-final"?`<circle cx="${i.x+i.width/2}" cy="${i.y+i.height/2}" r="${Math.min(i.width,i.height)/2-3}"/><circle cx="${i.x+i.width/2}" cy="${i.y+i.height/2}" r="${Math.min(i.width,i.height)/2-9}" fill="white"/>`:`<rect x="${i.x}" y="${i.y}" width="${i.width}" height="${i.height}" rx="${i.isDefinition?2:12}"/>`;return`<g data-subject-id="${t(i.subjectId)}" aria-label="${t(i.accessibilityText)}" fill="white" stroke="${i.color}" stroke-width="1.5">${a}<text x="${i.x+i.width/2}" y="${i.y+i.height/2}" text-anchor="middle" fill="#111" stroke="none" font-size="12">${t(i.label)}</text>${i.diagnostic?`<circle cx="${i.x+i.width-7}" cy="${i.y+7}" r="5" fill="#d97706" stroke="none"/>`:""}</g>`},r=i=>{const a=e.nodes.find(f=>f.id===i.sourceId),c=e.nodes.find(f=>f.id===i.targetId);if(!a||!c)return"";const l=[{x:a.x+a.width,y:a.y+a.height/2},...i.points,{x:c.x,y:c.y+c.height/2}].map(f=>`${f.x},${f.y}`).join(" ");return`<g data-subject-id="${t(i.subjectId)}"><polyline points="${l}" fill="none" stroke="${i.color}" stroke-width="${i.strokeWidth}"${i.dashed?' stroke-dasharray="5 3"':""}/>${i.label?`<text x="${(a.x+c.x)/2}" y="${(a.y+c.y)/2-5}" font-size="11">${t(i.label)}</text>`:""}</g>`};return`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${s}" viewBox="0 0 ${n} ${s}">${e.edges.map(r).join("")}${e.nodes.map(o).join("")}</svg>`}export{pi as A,To as B,he as C,zn as D,li as E,ki as F,ri as G,Ai as H,hi as I,_o as J,ge as K,si as L,Pe as M,Ti as N,Ni as O,di as P,Ci as R,Co as a,Fo as b,ii as c,Mi as d,Ei as e,gi as f,xi as g,wi as h,vi as i,ci as j,Ao as k,Ne as l,Ii as m,mi as n,yi as o,ds as p,Si as q,ai as r,Fi as s,fi as t,bi as u,ui as v,ni as w,De as x,oi as y,Oo as z};