@memoarchitect/architect 0.4.4 → 0.4.6

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 (32) hide show
  1. package/README.md +17 -6
  2. package/dist/assets/{AskPanel-BpFRMop9.js → AskPanel-D9_AKyYt.js} +1 -1
  3. package/dist/assets/{ComplianceWizard-DCcV-q6X.js → ComplianceWizard-BNvT_ic6.js} +1 -1
  4. package/dist/assets/{DSMView-OMMwi76e.js → DSMView-B4IEz19F.js} +1 -1
  5. package/dist/assets/{Dashboard-Dl5KU656.js → Dashboard-DNRzU1Hk.js} +1 -1
  6. package/dist/assets/{DhfDashboard-agI5JdAZ.js → DhfDashboard-DguH-rDT.js} +1 -1
  7. package/dist/assets/{DhfSettingsPanel-CKvGmNGe.js → DhfSettingsPanel-C89T0dv7.js} +1 -1
  8. package/dist/assets/{DhfWorkbench-BD_buvXh.js → DhfWorkbench-4gHayn-l.js} +3 -3
  9. package/dist/assets/{DiagramCanvas-CUYbaLjV.js → DiagramCanvas-BgfO0AtP.js} +1 -1
  10. package/dist/assets/{DiagramEditor-DZAocSs_.js → DiagramEditor-CEr6iqBf.js} +1 -1
  11. package/dist/assets/{DiagramSurface-BIK9fV8R.js → DiagramSurface-B_lfUNzV.js} +2 -2
  12. package/dist/assets/{ElementDetailView-R_Nob9E0.js → ElementDetailView-AclSjurg.js} +1 -1
  13. package/dist/assets/{ImportView-yxS8JfX4.js → ImportView-t1dIoZF5.js} +1 -1
  14. package/dist/assets/{LayerGrid-DdEtHyAu.js → LayerGrid-fSGvqSEj.js} +1 -1
  15. package/dist/assets/{LayerTable-dOCvwCEb.js → LayerTable-D8QCFY1b.js} +1 -1
  16. package/dist/assets/{MaxGraphCanvas-CDdlW8h_.js → MaxGraphCanvas-DYs6MPuP.js} +1 -1
  17. package/dist/assets/{ModelDiff-BbdzLhXe.js → ModelDiff-CLFqnELG.js} +1 -1
  18. package/dist/assets/{OntologyDecompositionDiagram-BW07CXuV.js → OntologyDecompositionDiagram-cpmTTMRH.js} +1 -1
  19. package/dist/assets/{OntologyViewer-DaRXEQoq.js → OntologyViewer-72jTw72H.js} +2 -2
  20. package/dist/assets/{ReviewDashboard-CipgA5-r.js → ReviewDashboard-BVOe2I5w.js} +1 -1
  21. package/dist/assets/{ScenarioEditor-BfewgrrJ.js → ScenarioEditor-CvOkiRC6.js} +1 -1
  22. package/dist/assets/{StatisticsDashboard-CLww46qL.js → StatisticsDashboard-Dn6lsnKe.js} +1 -1
  23. package/dist/assets/{SysmlGenerator-DnsaN-ey.js → SysmlGenerator-CfBQWovl.js} +1 -1
  24. package/dist/assets/{TabularView-Bp-yKFPV.js → TabularView-B99xy3H3.js} +1 -1
  25. package/dist/assets/{TraceabilityMatrix-B-dn_i5a.js → TraceabilityMatrix-BAJb0X7G.js} +1 -1
  26. package/dist/assets/{WorkflowWizard-C6p5e2IT.js → WorkflowWizard-C38DZKOe.js} +1 -1
  27. package/dist/assets/{index-c27kHB43.js → index-CgRwea72.js} +12 -12
  28. package/dist/assets/{index-BZhRuk7M.css → index-CnFhl4_e.css} +1 -1
  29. package/dist/assets/{layout-selection-DvOsyJH9.js → layout-selection-BQ2WuAEB.js} +1 -1
  30. package/dist/index.html +2 -2
  31. package/lib/bin/memo-architect.js +0 -0
  32. package/package.json +34 -33
@@ -1 +1 @@
1
- import{j as e,H as A,P as N,N as ct,u as zt,a as Mn,B as On,E as Io,R as Wn,b as $n,c as Pn,d as _n,e as Hn,i as Kn,C as Vn,f as Yn,g as Gn,M as Xn}from"./reactflow-WKyu73tD.js";import{a as l,W as No}from"./zustand-qbFpP9Up.js";/* empty css */import{F as C,S as ee,m as qn,u as M,d as Xo,R as je,g as Un,D as Do,n as We,r as Zn,f as Ao,o as Qn,h as Jn,V as Ro,C as To}from"./index-c27kHB43.js";import{I as Mt,a as es,P as at,s as ts,G as Nt,c as os,f as ns,C as ss,r as is,v as rs,b as Lo,d as as,e as ls,g as ds,B as cs,w as ps,h as us,i as xs,j as hs,k as fs,l as gs,m as ms,n as ys,o as bs,p as Fs,q as ws,t as js}from"./layout-selection-DvOsyJH9.js";import{l as vs}from"./layout-providers-BAUgp0nu.js";import"./elk-B75IRfCd.js";import"web-worker";function Es(o,d,r="both",s=10){const i=o.elements[d];if(!i)return{rootId:d,rootName:"(unknown)",rootKind:"",nodes:[],edges:[]};const u=new Map,h=new Map;for(const x of o.relationships)u.has(x.sourceId)||u.set(x.sourceId,[]),u.get(x.sourceId).push(x),h.has(x.targetId)||h.set(x.targetId,[]),h.get(x.targetId).push(x);const F=new Set;F.add(d);const S=[],b=[],j=[[d,0]];for(;j.length>0;){const[x,y]=j.shift();if(y>=s)continue;const w=y+1;if(r==="downstream"||r==="both")for(const g of u.get(x)||[]){const E=g.targetId;if(b.push({fromId:x,toId:E,relType:g.type,relId:g.id}),!F.has(E)){F.add(E);const m=o.elements[E];m&&(S.push({elementId:E,name:m.name,kind:m.kind,layer:m.layer,depth:w,viaRelType:g.type,direction:"downstream"}),j.push([E,w]))}}if(r==="upstream"||r==="both")for(const g of h.get(x)||[]){const E=g.sourceId;if(b.push({fromId:E,toId:x,relType:g.type,relId:g.id}),!F.has(E)){F.add(E);const m=o.elements[E];m&&(S.push({elementId:E,name:m.name,kind:m.kind,layer:m.layer,depth:w,viaRelType:g.type,direction:"upstream"}),j.push([E,w]))}}}return S.sort((x,y)=>x.depth-y.depth||x.name.localeCompare(y.name)),{rootId:d,rootName:i.name,rootKind:i.kind,nodes:S,edges:b}}function ks({data:o}){const d=o,{element:r,layerColor:s,isExpanded:i,hasChildren:u,childCount:h,direction:F,onToggleExpand:S,onToggleDirection:b,showDirectionButton:j,depthBgColor:x,isContainer:y}=d,w=F==="vertical"?"V":"H",g=y&&i;return e.jsxs("div",{style:{background:g?x||"#FAFAF9":"#FFFFFF",borderLeft:g?`2px solid ${s}40`:`3px solid ${s}`,borderTop:`1px solid ${g?s+"30":"#E5E5E0"}`,borderRight:`1px solid ${g?s+"30":"#E5E5E0"}`,borderBottom:`1px solid ${g?s+"30":"#E5E5E0"}`,borderRadius:3,padding:g?"0":"8px 12px",minWidth:g?void 0:"200px",boxShadow:"none",width:"100%",height:"100%",boxSizing:"border-box"},children:[e.jsx(A,{type:"target",position:N.Top,id:"top",style:nt}),e.jsx(A,{type:"source",position:N.Bottom,id:"bottom",style:nt}),e.jsx(A,{type:"target",position:N.Left,id:"left",style:nt}),e.jsx(A,{type:"source",position:N.Right,id:"right",style:nt}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:g?"8px 12px":"0"},children:[u&&e.jsx("button",{onClick:E=>{E.stopPropagation(),S()},style:{width:"20px",height:"20px",borderRadius:2,border:`1px solid ${s}`,background:i?s+"12":"#FFFFFF",color:s,fontSize:C.md,fontWeight:700,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,flexShrink:0,transition:"background 200ms ease, color 200ms ease"},title:i?"Collapse":"Expand",children:i?"−":"+"}),u&&j&&e.jsx("button",{onClick:E=>{E.stopPropagation(),b()},style:{width:"20px",height:"20px",borderRadius:"4px",border:"1.5px solid #10b981",background:"transparent",color:"#10b981",fontSize:"9px",fontWeight:700,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:0,flexShrink:0,transition:"background 200ms ease"},title:`Direction: ${F}. Click to toggle`,children:w}),e.jsx("span",{style:{fontSize:C.md,fontWeight:600,color:g?s:"#1a1a1a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.name})]}),!g&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginTop:"3px",paddingLeft:u?"26px":"14px"},children:[e.jsx("span",{style:{fontSize:C.badge,color:"#9CA3AF"},children:r.kind}),u&&e.jsxs("span",{style:{fontSize:"9px",color:"#6B7280",background:"#F0F0ED",padding:"1px 5px",borderRadius:2,fontWeight:600},children:[h," parts",i?"":" (collapsed)"]})]})]})}const nt={width:"8px",height:"8px",background:"#2DD4A8",border:"1.5px solid #FFFFFF",opacity:0},Ss=l.memo(ks),Bo={top:N.Top,bottom:N.Bottom,left:N.Left,right:N.Right},Cs={top:"bottom",bottom:"top",left:"right",right:"left"},Is="#6B7280",qo=o=>o?at[o]:Is;function Uo(o,d){if(o==="inout")return"⇄";if(!o)return"";const r=o==="in";switch(d){case"left":return r?"→":"←";case"right":return r?"←":"→";case"top":return r?"↓":"↑";default:return r?"↑":"↓"}}const Ns=104,Dt=40,zo=o=>({opacity:0,width:o,height:o,top:"50%",left:"50%",transform:"translate(-50%, -50%)",border:"none",background:"transparent",pointerEvents:"none"});function Ds({port:o,onMove:d}){const{getZoom:r}=zt(),s=Mn(j=>j.transform[2]),i=o.size??Mt,u=(Dt-i)/2,h=i+5,F=qo(o.direction),S=o.side==="left"||o.side==="right",b={position:"absolute",fontSize:o.nested?"9.5px":"10.5px",fontWeight:o.nested?600:650,color:o.nested?"#6B7280":"#374151",whiteSpace:"normal",pointerEvents:"none",overflow:"hidden",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,width:S?Ns:72,background:"rgba(255,255,255,0.94)",padding:"1px 3px",borderRadius:4,lineHeight:1.12,...o.side==="left"?{left:h,bottom:"50%",marginBottom:2}:o.side==="right"?{right:h,bottom:"50%",marginBottom:2,textAlign:"right"}:o.side==="top"?{top:h,left:"50%",transform:"translateX(-50%)"}:{bottom:h,left:"50%",transform:"translateX(-50%)"}};return e.jsx("div",{className:"nodrag nopan",onPointerDown:d?j=>{j.preventDefault(),j.stopPropagation();const x=j.clientY,y=o.y,w=E=>d(y+(E.clientY-x)/r()),g=()=>{window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",g)};window.addEventListener("pointermove",w),window.addEventListener("pointerup",g,{once:!0})}:void 0,style:{position:"absolute",left:o.x-u,top:o.y-u,width:Dt,height:Dt,display:"flex",alignItems:"center",justifyContent:"center",zIndex:o.nested?11:10,cursor:d?"grab":"default",touchAction:"none",transform:`scale(${1/Math.max(s,.1)})`,transformOrigin:"center"},title:`${o.name}${o.direction?` (${o.direction})`:""}`,children:e.jsxs("div",{style:{position:"relative",width:i,height:i,boxSizing:"border-box",background:"#FFFFFF",border:`2px solid ${F}`,borderRadius:5,boxShadow:"0 1px 3px rgba(15,23,42,0.18)",display:"flex",alignItems:"center",justifyContent:"center",color:F,fontSize:o.nested?"10px":"12px",fontWeight:800,lineHeight:1,pointerEvents:"none"},children:[Uo(o.direction,o.side),e.jsx("span",{style:b,children:o.name.replace(/([a-z0-9])([A-Z])/g,"$1​$2")}),[{suffix:"",pos:Bo[o.side]},{suffix:es,pos:Bo[Cs[o.side]]}].flatMap(j=>[e.jsx(A,{className:"ibd-port-anchor",type:"source",id:`${o.id}${j.suffix}`,position:j.pos,style:zo(i),isConnectable:!1},`s${j.suffix}`),e.jsx(A,{className:"ibd-port-anchor",type:"target",id:`${o.id}${j.suffix}`,position:j.pos,style:zo(i),isConnectable:!1},`t${j.suffix}`)])]})})}function Mo({side:o,direction:d}){const r=qo(d),s=Mt;return e.jsx("div",{"aria-label":`implicit ${d} port`,title:`Implicit ${d} port — relationship targets the part directly`,style:{position:"absolute",top:"50%",left:o==="left"?-s/2:void 0,right:o==="right"?-s/2:void 0,transform:"translateY(-50%)",width:s,height:s,boxSizing:"border-box",background:"#FFFFFF",border:`2px solid ${r}`,borderRadius:4,boxShadow:"0 1px 3px rgba(15,23,42,0.18)",display:"flex",alignItems:"center",justifyContent:"center",color:r,fontSize:11,fontWeight:800,lineHeight:1,zIndex:4,pointerEvents:"none"},children:Uo(d,o)})}const st={width:8,height:8,background:"#2DD4A8",border:"1.5px solid #FFFFFF",opacity:0};function Oo({name:o,kind:d,nameColor:r,typeColor:s,frame:i=!1}){return e.jsxs("span",{title:`${o} : ${d}`,style:{display:"flex",flexDirection:i?"row":"column",alignItems:i?"baseline":"flex-start",gap:i?6:1,minWidth:0,overflow:"hidden",flex:1},children:[e.jsx("span",{style:{display:i?"block":"-webkit-box",width:"100%",minWidth:0,fontSize:i?C.md:C.sm,lineHeight:1.2,fontWeight:700,color:r,whiteSpace:i?"nowrap":"normal",overflow:"hidden",textOverflow:"ellipsis",WebkitBoxOrient:"vertical",WebkitLineClamp:i?void 0:2,overflowWrap:"anywhere"},children:o}),e.jsx("span",{style:{display:"block",maxWidth:"100%",fontSize:"9px",lineHeight:1.15,fontWeight:650,letterSpacing:"0.055em",textTransform:"uppercase",color:s,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:i?`: ${d}`:`«${d}»`})]})}function Wo({label:o,isCollapsed:d,onToggle:r,color:s,onColor:i}){return e.jsx("button",{"aria-label":d?`Expand ${o}`:`Collapse ${o}`,onClick:u=>{u.stopPropagation(),r()},style:{marginLeft:"auto",width:18,height:18,padding:0,borderRadius:3,border:i?"1px solid rgba(255,255,255,0.7)":`1px solid ${s}88`,background:i?"rgba(255,255,255,0.18)":"#FFFFFF",color:i?"#FFFFFF":s,fontSize:13,lineHeight:"15px",cursor:"pointer",fontWeight:700,flexShrink:0},children:d?"+":"−"})}function As({id:o,data:d,selected:r,height:s}){const i=d,{label:u,kind:h,color:F,isContainer:S,isFrame:b,ports:j,implicitIn:x,implicitOut:y,onPortMove:w,hasChildren:g,isCollapsed:E,onToggleCollapse:m}=i,[D,O]=l.useState(!1),v=r?ee.selected:b?"none":D?"0 8px 20px rgba(15,23,42,0.12)":S?"0 1px 2px rgba(15,23,42,0.05)":"0 2px 8px rgba(15,23,42,0.08)";return e.jsxs("div",{onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1),style:{width:"100%",height:"100%",boxSizing:"border-box",background:"#FFFFFF",border:b?"1.5px solid #94A3B8":`1px solid ${D?F+"9A":"#CBD5E1"}`,...b?{}:{borderTop:`3px solid ${F}`},borderRadius:b?10:8,boxShadow:v,transition:"box-shadow 150ms ease, border-color 150ms ease",position:"relative"},children:[!b&&e.jsx(ct,{nodeId:o,isVisible:r,minWidth:180,minHeight:100,color:"#2563EB",lineStyle:{borderWidth:1},handleStyle:{width:10,height:10,borderRadius:2}}),e.jsx(A,{type:"target",position:N.Top,id:"top",style:st}),e.jsx(A,{type:"source",position:N.Bottom,id:"bottom",style:st}),e.jsx(A,{type:"target",position:N.Left,id:"left",style:st}),e.jsx(A,{type:"source",position:N.Right,id:"right",style:st}),b?e.jsxs("div",{style:{position:"absolute",top:0,left:0,right:0,height:38,display:"flex",alignItems:"center",gap:8,padding:"0 10px",background:"#F8FAFC",borderBottom:"1px solid #E2E8F0",borderRadius:"9px 9px 0 0"},children:[e.jsx("span",{style:{padding:"2px 6px",borderRadius:4,background:F,color:"#FFFFFF",fontSize:9,fontWeight:800,letterSpacing:"0.08em"},children:"IBD"}),e.jsx(Oo,{name:u,kind:h,nameColor:"#0F172A",typeColor:"#64748B",frame:!0}),g&&m&&e.jsx(Wo,{label:u,isCollapsed:E,onToggle:m,color:F})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minHeight:58,padding:"7px 10px 6px",background:"#FFFFFF",borderBottom:g?"1px solid #E2E8F0":"none",borderRadius:"7px 7px 0 0",overflow:"hidden"},children:[e.jsx(Oo,{name:u,kind:h,nameColor:"#0F172A",typeColor:S?F:"#64748B"}),g&&m&&e.jsx(Wo,{label:u,isCollapsed:E,onToggle:m,color:F})]}),j.map(I=>e.jsx(Ds,{port:I,onMove:w?$=>{const z=I.size??Mt,X=(b||S?70:62)-z/2,T=Math.max(X,(s??X+z+18)-z-18);w(I.id,Math.min(Math.max($,X),T))}:void 0},I.id)),x&&e.jsx(Mo,{side:"left",direction:"in"}),y&&e.jsx(Mo,{side:"right",direction:"out"})]})}const Rs=l.memo(As);function $o(o,d){const r=o.map(i=>({...i}));let s=d;for(;r.length>=2&&s>0;){const i=r[0],u=r[1],h=Math.hypot(u.x-i.x,u.y-i.y);if(h<=s)s-=h,r.shift();else{const F=s/h;r[0]={x:i.x+(u.x-i.x)*F,y:i.y+(u.y-i.y)*F},s=0}}return r}function Ts(o,d){const r=$o(o,d);return $o([...r].reverse(),d).reverse()}const Ls=o=>o.slice(1).reduce((d,r,s)=>d+Math.hypot(r.x-o[s].x,r.y-o[s].y),0);function At(o,d=7){if(o.length<2)return"";let r=`M ${o[0].x},${o[0].y}`;for(let i=1;i<o.length-1;i++){const u=o[i-1],h=o[i],F=o[i+1],S=Math.hypot(h.x-u.x,h.y-u.y),b=Math.hypot(F.x-h.x,F.y-h.y),j=Math.min(d,S/2,b/2),x=h.x-Math.sign(h.x-u.x)*j,y=h.y-Math.sign(h.y-u.y)*j,w=h.x+Math.sign(F.x-h.x)*j,g=h.y+Math.sign(F.y-h.y)*j;r+=` L ${x},${y} Q ${h.x},${h.y} ${w},${g}`}const s=o[o.length-1];return`${r} L ${s.x},${s.y}`}function Bs(o){const d=o.slice(1).map((i,u)=>Math.abs(i.x-o[u].x)+Math.abs(i.y-o[u].y)),r=d.reduce((i,u)=>i+u,0)/2;let s=0;for(let i=0;i<d.length;i++){if(s+d[i]>=r){const u=d[i]?(r-s)/d[i]:0;return{x:o[i].x+(o[i+1].x-o[i].x)*u,y:o[i].y+(o[i+1].y-o[i].y)*u}}s+=d[i]}return o[o.length-1]}function zs(o){var j,x,y,w,g,E;const{getZoom:d}=zt(),r=((j=o.data)==null?void 0:j.points)??[];if(r.length<2)return null;const s=Bs(r),i=Math.min(28/Math.max(d(),.1),Ls(r)*.3),u=Ts(r,i),h=(x=o.data)==null?void 0:x.onRouteChange,F=(y=o.data)==null?void 0:y.onSelect,S=!!((w=o.data)!=null&&w.flowAnimation),b=r.length===2?[{index:1,a:r[0],b:r[1],straight:!0}]:r.slice(1).map((m,D)=>({index:D+1,a:r[D],b:m,straight:!1})).filter(m=>m.index>=2&&m.index<=r.length-2);return e.jsxs(e.Fragment,{children:[e.jsx(On,{id:o.id,path:At(r),style:o.style,markerEnd:o.markerEnd}),S&&e.jsx("path",{d:At(r),fill:"none",stroke:String(((g=o.style)==null?void 0:g.stroke)??"#2563EB"),strokeWidth:Math.max(2,Number(((E=o.style)==null?void 0:E.strokeWidth)??2)),className:"memo-ibd-flow"}),u.length>=2&&e.jsx("path",{d:At(u),fill:"none",stroke:"transparent",strokeWidth:18/Math.max(d(),.1),pointerEvents:"stroke",cursor:"pointer",onClick:m=>F==null?void 0:F(m)}),o.label?e.jsx(Io,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${s.x}px, ${s.y}px)`,fontSize:C.badge,fontWeight:600,color:"#475569",background:"rgba(255,255,255,0.96)",border:"1px solid #E2E8F0",padding:"1px 4px",borderRadius:4,pointerEvents:"none"},children:o.label})}):null,o.selected&&h?b.map(m=>{const D=(m.a.x+m.b.x)/2,O=(m.a.y+m.b.y)/2;return e.jsx(Io,{children:e.jsx("div",{className:"nodrag nopan",title:"Drag connector segment",onPointerDown:v=>{v.preventDefault(),v.stopPropagation();const I=v.clientX,$=v.clientY,z=T=>{const le=(T.clientX-I)/d(),U=(T.clientY-$)/d();if(m.straight){if(Math.abs(U)>=Math.abs(le)){const G=m.a.y+U;h([m.a,{x:m.a.x,y:G},{x:m.b.x,y:G},m.b])}else{const G=(m.a.x+m.b.x)/2+le;h([m.a,{x:G,y:m.a.y},{x:G,y:m.b.y},m.b])}return}const Y=r.map(G=>({...G}));m.a.y===m.b.y?(Y[m.index-1].y=m.a.y+U,Y[m.index].y=m.b.y+U):(Y[m.index-1].x=m.a.x+le,Y[m.index].x=m.b.x+le),h(Y)},X=()=>{window.removeEventListener("pointermove",z),window.removeEventListener("pointerup",X)};window.addEventListener("pointermove",z),window.addEventListener("pointerup",X,{once:!0})},style:{position:"absolute",transform:`translate(-50%, -50%) translate(${D}px, ${O}px)`,width:12,height:12,borderRadius:3,background:"#FFFFFF",border:"2px solid #2563EB",boxShadow:"0 1px 4px rgba(15,23,42,0.22)",cursor:m.a.y===m.b.y?"ns-resize":"ew-resize",pointerEvents:"all",touchAction:"none",zIndex:20}})},`route-${m.index}`)}):null]})}const Ms=l.memo(zs);function Os({data:o,selected:d}){const r=o,{nodeType:s,label:i,laneColor:u,layerColor:h,inPorts:F,outPorts:S}=r,[b,j]=l.useState(!1);if(s==="start")return e.jsx("div",{style:{width:28,height:28,borderRadius:"50%",background:"#374151",border:"2px solid #374151",boxShadow:ee.sm},children:e.jsx(A,{type:"source",position:r.flowDirection==="vertical"?N.Bottom:N.Right,style:{background:"#374151",width:6,height:6}})});if(s==="done")return e.jsxs("div",{style:{width:28,height:28,borderRadius:"50%",background:"#FFFFFF",border:"3px solid #374151",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:ee.sm},children:[e.jsx("div",{style:{width:14,height:14,borderRadius:"50%",background:"#374151"}}),e.jsx(A,{type:"target",position:r.flowDirection==="vertical"?N.Top:N.Left,style:{background:"#374151",width:6,height:6}})]});if(s==="fork"||s==="join"){const g=r.flowDirection==="vertical";return e.jsxs("div",{title:s==="fork"?"Fork — split into concurrent flows":"Join — synchronize concurrent flows",style:{width:"100%",height:"100%",background:"#374151",borderRadius:3,boxShadow:ee.sm},children:[e.jsx(A,{type:"target",position:g?N.Top:N.Left,style:{background:"#374151",width:6,height:6,border:"none"}}),e.jsx(A,{type:"source",position:g?N.Bottom:N.Right,style:{background:"#374151",width:6,height:6,border:"none"}})]})}const x=u||h||"#9CA3AF",y=18,w=Math.max(F.length*y,S.length*y,0);return e.jsxs("div",{onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),style:{background:"#FFFFFF",border:`1.5px solid ${x}`,borderRadius:3,minWidth:"140px",boxShadow:d?"0 0 0 3px #2DD4A8, 0 4px 12px rgba(45, 212, 168, 0.35)":b?`0 0 0 2px ${x}22`:"none",transition:"box-shadow 150ms ease",overflow:"hidden"},children:[e.jsxs("div",{style:{padding:"8px 14px",fontSize:C.md,fontWeight:600,color:"#1a1a1a",background:`${x}0D`,borderBottom:w>0?"1px solid #E5E5E0":"none",textAlign:"center",whiteSpace:"nowrap"},children:[i,r.hasChildren&&r.onToggleExpand&&e.jsx("button",{"aria-label":r.isExpanded?`Collapse ${i}`:`Expand ${i}`,onClick:g=>{g.stopPropagation(),r.onToggleExpand()},style:{float:"right",marginLeft:8,width:18,height:18,padding:0,border:`1px solid ${x}`,borderRadius:2,background:"#FFFFFF",color:x,fontSize:13,fontWeight:700,lineHeight:"16px",cursor:"pointer"},children:r.isExpanded?"−":"+"})]}),w>0&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0"},children:[e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:F.map(g=>e.jsxs("div",{style:{fontSize:C.badge,color:"#6B7280",paddingLeft:"8px",display:"flex",alignItems:"center",height:`${y}px`,gap:"4px"},children:[e.jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"#3498DB",flexShrink:0}}),g]},`in-${g}`))}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px",alignItems:"flex-end"},children:S.map(g=>e.jsxs("div",{style:{fontSize:C.badge,color:"#6B7280",paddingRight:"8px",display:"flex",alignItems:"center",height:`${y}px`,gap:"4px"},children:[g,e.jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"#E67E22",flexShrink:0}})]},`out-${g}`))})]}),r.allocatedTo&&e.jsxs("div",{style:{fontSize:"9px",color:"#9CA3AF",textAlign:"center",padding:"2px 6px",borderTop:"1px solid #F3F4F6",background:"#FAFAFA"},children:["→"," ",r.allocatedTo]}),e.jsx(A,{type:"target",position:r.flowDirection==="vertical"?N.Top:N.Left,style:{background:x,width:8,height:8,border:"2px solid #FFFFFF"}}),e.jsx(A,{type:"source",position:r.flowDirection==="vertical"?N.Bottom:N.Right,style:{background:x,width:8,height:8,border:"2px solid #FFFFFF"}})]})}const Ws=l.memo(Os);function $s({data:o,selected:d}){const r=o,s=r.orientation==="column";return e.jsx("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:`${r.color}08`,border:d?"3px solid #2DD4A8":`1px solid ${r.color}30`,borderLeft:d?"3px solid #2DD4A8":s?`1px solid ${r.color}30`:`3px solid ${r.color}`,borderTop:d?"3px solid #2DD4A8":s?`3px solid ${r.color}`:`1px solid ${r.color}30`,borderRadius:qn.md,pointerEvents:"auto",cursor:r.inspectElementId?"pointer":"default",display:"flex"},children:e.jsx("div",{style:{writingMode:s?"horizontal-tb":"vertical-rl",transform:s?void 0:"rotate(180deg)",padding:s?"7px 10px":"10px 6px",fontSize:C.xs,fontWeight:700,color:r.color,letterSpacing:"0.04em",textTransform:"uppercase",alignSelf:s?"flex-start":"center",width:s?"100%":void 0,textAlign:s?"center":void 0,whiteSpace:"nowrap"},children:r.label})})}const Ps=l.memo($s),it={width:8,height:8,border:"none",background:"transparent",opacity:0};function Rt(){return e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"target",position:N.Top,id:"top",style:it}),e.jsx(A,{type:"source",position:N.Bottom,id:"bottom",style:it}),e.jsx(A,{type:"target",position:N.Left,id:"left",style:it}),e.jsx(A,{type:"source",position:N.Right,id:"right",style:it})]})}function _s({data:o,selected:d}){const r=o;return r.isNote?e.jsxs("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:"#FFFDF5",border:`1px solid ${r.color}66`,borderRadius:4,padding:"6px 10px",boxShadow:ee.sm,display:"flex",flexDirection:"column",justifyContent:"center"},title:r.kind,children:[e.jsx(Rt,{}),e.jsx("span",{style:{fontSize:C.xs,fontWeight:600,color:"#374151",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.label}),e.jsx("span",{style:{fontSize:"8px",fontWeight:700,color:r.color,textTransform:"uppercase",letterSpacing:"0.05em"},children:r.kind})]}):r.isContainer?e.jsxs("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:r.isMachine?"transparent":`${r.color}06`,border:r.isMachine?`1.5px dashed ${r.color}88`:`1.5px solid ${r.color}55`,borderRadius:14,boxShadow:d?ee.selected:"none",position:"relative"},children:[e.jsx(Rt,{}),e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,padding:"10px 14px 0"},children:[e.jsx("span",{style:{fontSize:C.md,fontWeight:700,color:r.color,whiteSpace:"nowrap"},children:r.label}),e.jsx("span",{style:{fontSize:"8px",fontWeight:700,color:`${r.color}AA`,textTransform:"uppercase",letterSpacing:"0.06em"},children:r.kind})]})]}):e.jsxs("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:"#FFFFFF",border:`1.5px solid ${r.color}`,borderRadius:12,boxShadow:d?ee.selected:ee.md,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,padding:"4px 12px"},children:[e.jsx(Rt,{}),e.jsx("span",{style:{fontSize:C.md,fontWeight:600,color:"#1a1a1a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:r.label}),r.subtitle&&e.jsx("span",{style:{fontSize:"8px",fontWeight:600,color:"#9CA3AF",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:r.subtitle})]})}const Hs=l.memo(_s),Bt="#3498DB";function Ks({data:o}){const d=o;return e.jsxs("div",{style:{width:"100%",height:"100%",position:"relative",pointerEvents:"none"},children:[e.jsx("div",{style:{position:"absolute",top:0,left:"50%",transform:"translateX(-50%)",minWidth:140,maxWidth:"90%",padding:"10px 16px",background:"#FFFFFF",border:`1.5px solid ${Bt}`,borderRadius:8,boxShadow:ee.md,textAlign:"center",fontSize:C.md,fontWeight:600,color:"#1a1a1a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.label}),e.jsx("div",{style:{position:"absolute",top:44,bottom:0,left:"50%",borderLeft:`1.5px dashed ${Bt}66`}})]})}const Vs=l.memo(Ks);function Ys({data:o}){const d=o;return e.jsx("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:"#1B3A4B06",border:"1px solid #1B3A4B22",borderRadius:10,pointerEvents:"none"},children:e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,padding:"8px 14px"},children:[e.jsx("span",{style:{fontSize:C.sm,fontWeight:700,color:"#1B3A4B"},children:d.label}),d.scenario&&e.jsxs("span",{style:{fontSize:C.xs,color:"#6B7280"},children:["realizes ",d.scenario]})]})})}const Gs=l.memo(Ys),rt={width:6,height:6,border:"none",background:"transparent",opacity:0};function Xs({data:o,selected:d}){const r=o;return e.jsxs("div",{style:{width:14,height:14,borderRadius:"50%",background:"#FFFFFF",border:`3px solid ${Bt}`,boxShadow:d?ee.selected:ee.sm,position:"relative"},title:r.kind,children:[e.jsx(A,{type:"source",id:"right",position:N.Right,style:rt}),e.jsx(A,{type:"target",id:"right",position:N.Right,style:rt}),e.jsx(A,{type:"source",id:"left",position:N.Left,style:rt}),e.jsx(A,{type:"target",id:"left",position:N.Left,style:rt}),e.jsx("span",{style:{position:"absolute",top:-20,left:"50%",transform:"translateX(-50%)",fontSize:"9px",fontWeight:600,color:"#374151",whiteSpace:"nowrap",background:"#FFFFFFCC",padding:"1px 5px",borderRadius:4},children:r.label})]})}const qs=l.memo(Xs),Us=l.memo(function({id:d,data:r,selected:s}){var v;const i=r,[u,h]=l.useState(!1),[F,S]=l.useState(""),[b,j]=l.useState(!1),x=l.useRef(null),y=l.useCallback(()=>{S(i.label),h(!0),setTimeout(()=>{var I;(I=x.current)==null||I.select()},10)},[i.label]),w=l.useCallback(()=>{var $;h(!1);const I=F.trim();I&&I!==i.label&&(($=i.onInlineEdit)==null||$.call(i,d,I))},[F,i,d]),g=l.useCallback(I=>{I.key==="Enter"&&(I.preventDefault(),w()),I.key==="Escape"&&h(!1)},[w]),E=l.useCallback(I=>{var $;I.preventDefault(),($=i.onContextMenu)==null||$.call(i,I,d)},[i,d]),m=i.bgColor??"#FFFFFF",D=i.color,O={background:D,border:"2px solid #FFFFFF",width:10,height:10,opacity:b||s?1:0,transition:"opacity 0.15s"};return e.jsxs("div",{onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),onContextMenu:E,onDoubleClick:y,style:{minWidth:120,minHeight:40,background:m,borderLeft:`3px solid ${D}`,borderRadius:8,boxShadow:s?`0 0 0 2px ${D}, 0 4px 12px ${D}44`:b?"0 4px 16px rgba(0,0,0,0.14)":"0 1px 4px rgba(0,0,0,0.08)",cursor:u?"text":"grab",position:"relative",transition:"box-shadow 0.15s",opacity:i.isNew?.7:1},children:[s&&e.jsx(ct,{minWidth:80,minHeight:36,maxWidth:600,maxHeight:400,color:D,lineStyle:{borderColor:D},handleStyle:{background:D,border:"2px solid #fff",width:10,height:10,borderRadius:2}}),e.jsxs("div",{style:{padding:"8px 12px",userSelect:"none"},children:[e.jsx("div",{style:{fontSize:"9px",fontWeight:700,color:D,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:i.kind}),u?e.jsx("input",{ref:x,value:F,onChange:I=>S(I.target.value),onBlur:w,onKeyDown:g,onClick:I=>I.stopPropagation(),autoFocus:!0,style:{fontSize:C.sm,fontWeight:500,color:"#1a1a1a",background:"transparent",border:"none",outline:"none",width:"100%",padding:0}}):e.jsx("div",{style:{fontSize:C.sm,fontWeight:500,color:"#1a1a1a",lineHeight:1.3,wordBreak:"break-word"},children:i.label||i.kind}),i.isNew&&e.jsx("div",{style:{fontSize:"9px",color:"#9CA3AF",marginTop:2},children:"saving…"})]}),!!((v=i.compartments)!=null&&v.length)&&e.jsx("div",{style:{borderTop:"1px solid #EDEDEA",padding:"5px 12px 7px",userSelect:"none"},children:i.compartments.map(I=>e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"baseline",fontSize:"10px",lineHeight:"15px",whiteSpace:"nowrap",overflow:"hidden"},children:[e.jsx("span",{style:{color:"#9CA3AF"},children:I.key}),e.jsx("span",{style:{color:"#4B5563",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis"},children:I.value})]},I.key))}),e.jsx(A,{type:"target",position:N.Top,style:{...O,top:-5}}),e.jsx(A,{type:"source",position:N.Bottom,style:{...O,bottom:-5},id:"bottom"}),e.jsx(A,{type:"source",position:N.Right,style:{...O,right:-5},id:"right"}),e.jsx(A,{type:"target",position:N.Left,style:{...O,left:-5}})]})});function Tt({collapsed:o,onToggleCollapse:d,elementIds:r=[]}){const s=M(y=>y.model),i=M(y=>y.selectedElementId),u=M(y=>y.inspectElement),[h,F]=l.useState(""),[S,b]=l.useState(new Set),j=l.useMemo(()=>{var E;if(!s)return[];const y=h.trim().toLowerCase(),w=new Map,g=new Set(r);for(const m of r){const D=(E=s.elements[m])==null?void 0:E.allocatedTo;D&&g.add(D)}for(const m of g){const D=s.elements[m];D&&(y&&!D.name.toLowerCase().includes(y)&&!D.kind.toLowerCase().includes(y)||(w.has(D.kind)||w.set(D.kind,[]),w.get(D.kind).push(D)))}return[...w.entries()].map(([m,D])=>({kind:m,elements:D.sort((O,v)=>O.name.localeCompare(v.name))})).sort((m,D)=>m.kind.localeCompare(D.kind))},[s,r,h]),x=y=>b(w=>{const g=new Set(w);return g.has(y)?g.delete(y):g.add(y),g});return o?e.jsxs("button",{className:"flex flex-col items-center py-2 gap-1 cursor-pointer",style:{width:36,border:0,borderRight:"1px solid #E5E5E0",background:"#FAFAF8",flexShrink:0},onClick:d,title:"Expand diagram elements","aria-label":"Expand diagram elements",children:[e.jsx("span",{style:{color:"#6B7280",fontSize:18},children:"›"}),e.jsx("span",{style:{fontSize:10,color:"#6B7280",writingMode:"vertical-rl"},children:"Diagram Elements"})]}):e.jsxs("div",{className:"flex flex-col overflow-hidden",style:{width:240,borderRight:"1px solid #E5E5E0",background:"#FAFAF8",flexShrink:0},children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid #E5E5E0",flexShrink:0},children:[e.jsx("span",{style:{fontSize:C.xs,fontWeight:600,color:"#374151"},children:"Diagram Elements"}),e.jsx("button",{onClick:d,title:"Collapse diagram elements","aria-label":"Collapse diagram elements",style:{background:"none",border:"none",cursor:"pointer",color:"#6B7280",fontSize:18,lineHeight:1},children:"‹"})]}),e.jsx("div",{className:"px-2 pt-2 pb-1",style:{flexShrink:0},children:e.jsx("input",{value:h,onChange:y=>F(y.target.value),placeholder:"Search elements…",className:"w-full px-2 py-1 rounded focus:outline-none",style:{fontSize:C.xs,background:"#F0F0ED",border:"1px solid #E5E5E0",color:"#374151"}})}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[j.map(y=>{var E;const w=S.has(y.kind),g=Xo[(E=y.elements[0])==null?void 0:E.layer]??"#6B7280";return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>x(y.kind),className:"w-full flex items-center gap-1.5 px-2 py-1",style:{background:"none",border:"none",cursor:"pointer",textAlign:"left"},children:[e.jsx("span",{style:{fontSize:10,color:g},children:w?"▶":"▼"}),e.jsx("span",{className:"truncate",style:{fontSize:10,color:g,fontWeight:700},children:y.kind}),e.jsx("span",{style:{fontSize:9,color:"#9CA3AF",marginLeft:"auto"},children:y.elements.length})]}),!w&&y.elements.map(m=>{const D=i===m.id;return e.jsxs("button",{onClick:()=>u(m.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left",style:{border:"none",cursor:"pointer",fontSize:C.xs,background:D?"#DDF7EF":"transparent",color:D?"#116149":"#374151",fontWeight:D?600:400},title:`Highlight ${m.name} in diagram`,children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2,background:g,flexShrink:0}}),e.jsx("span",{className:"truncate flex-1",children:m.name})]},m.id)})]},y.kind)}),j.length===0&&e.jsx("div",{className:"p-3 text-center",style:{color:"#9CA3AF",fontSize:C.xs},children:h?"No matching elements":"No elements in this diagram"})]})]})}const Po=[{type:"mitigates",label:"Mitigates",desc:"Risk control → Hazard"},{type:"causes",label:"Causes",desc:"Hazard → Hazardous Situation"},{type:"leadsTo",label:"Leads To",desc:"Situation → Harm"},{type:"identifies",label:"Identifies",desc:"Analysis → Risk"},{type:"traceTo",label:"Traces To",desc:"Requirement → Requirement"},{type:"satisfy",label:"Satisfies",desc:"Function → Requirement"},{type:"verify",label:"Verifies",desc:"Test → Requirement"},{type:"allocateTo",label:"Allocates To",desc:"Function → Component"},{type:"composedOf",label:"Composed Of",desc:"Parent → Child"},{type:"decomposedBy",label:"Decomposed By",desc:"Function → Sub-function"},{type:"flow",label:"Flow",desc:"Data / material flow"},{type:"succession",label:"Succession",desc:"Action sequence"},{type:"aggregation",label:"Aggregation",desc:"Logical grouping"}];function Zs({x:o,y:d,sourceKind:r,targetKind:s,closureRules:i,onSelect:u,onCancel:h}){const F=l.useRef(null),[S,b]=l.useState(""),j=l.useRef(null);l.useEffect(()=>{var v;(v=j.current)==null||v.focus()},[]),l.useEffect(()=>{const v=I=>{F.current&&!F.current.contains(I.target)&&h()};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[h]),l.useEffect(()=>{const v=I=>{I.key==="Escape"&&h()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[h]);const x=i?i[r]??Object.keys(je):Object.keys(je),y=Po.filter(v=>x.includes(v.type)&&(!S||v.label.toLowerCase().includes(S.toLowerCase())||v.type.toLowerCase().includes(S.toLowerCase()))),w=new Set(Po.map(v=>v.type)),g=x.filter(v=>!w.has(v)&&(!S||v.toLowerCase().includes(S.toLowerCase()))),E=240,m=320,D=Math.min(o,window.innerWidth-E-8),O=Math.min(d,window.innerHeight-m-8);return e.jsxs("div",{ref:F,className:"fixed z-50 flex flex-col shadow-xl rounded-xl overflow-hidden",style:{left:D,top:O,width:E,maxHeight:m,background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 8px 32px rgba(0,0,0,0.16)"},children:[e.jsxs("div",{className:"px-3 py-2",style:{borderBottom:"1px solid #E5E5E0",flexShrink:0},children:[e.jsx("div",{style:{fontSize:C.xs,fontWeight:600,color:"#374151",marginBottom:4},children:"Relationship Type"}),e.jsxs("div",{style:{fontSize:"10px",color:"#9CA3AF",marginBottom:4},children:[r," → ",s]}),e.jsx("input",{ref:j,value:S,onChange:v=>b(v.target.value),placeholder:"Search…",className:"w-full px-2 py-1 rounded focus:outline-none",style:{fontSize:C.xs,background:"#F7F7F5",border:"1px solid #E5E5E0",color:"#374151"}})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[y.map(v=>e.jsxs("button",{onClick:()=>u(v.type),className:"w-full flex items-center gap-2.5 px-3 py-1.5 text-left",style:{background:"none",border:"none",cursor:"pointer"},onMouseEnter:I=>{I.currentTarget.style.background="#F7F7F5"},onMouseLeave:I=>{I.currentTarget.style.background="none"},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",flexShrink:0,background:je[v.type]??"#6B7280"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:C.xs,fontWeight:500,color:"#1a1a1a"},children:v.label}),e.jsx("div",{style:{fontSize:"10px",color:"#9CA3AF"},children:v.desc})]})]},v.type)),g.map(v=>e.jsxs("button",{onClick:()=>u(v),className:"w-full flex items-center gap-2.5 px-3 py-1.5 text-left",style:{background:"none",border:"none",cursor:"pointer"},onMouseEnter:I=>{I.currentTarget.style.background="#F7F7F5"},onMouseLeave:I=>{I.currentTarget.style.background="none"},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",flexShrink:0,background:je[v]??"#6B7280"}}),e.jsx("span",{style:{fontSize:C.xs,color:"#1a1a1a"},children:v})]},v)),y.length===0&&g.length===0&&e.jsx("div",{className:"p-3 text-center",style:{color:"#9CA3AF",fontSize:C.xs},children:"No matching types"})]})]})}function Q({label:o,icon:d,danger:r,onClick:s}){return e.jsxs("button",{onClick:s,className:"w-full flex items-center gap-2 px-3 py-1.5 text-left",style:{background:"none",border:"none",cursor:"pointer",fontSize:C.xs},onMouseEnter:i=>{i.currentTarget.style.background=r?"#FEF2F2":"#F7F7F5"},onMouseLeave:i=>{i.currentTarget.style.background="none"},children:[d&&e.jsx("span",{style:{fontSize:"12px",width:16,textAlign:"center"},children:d}),e.jsx("span",{style:{color:r?"#DC2626":"#1a1a1a"},children:o})]})}function lt(){return e.jsx("div",{style:{height:1,background:"#E5E5E0",margin:"2px 0"}})}function Zo({x:o,y:d,onClose:r,children:s}){const i=l.useRef(null);l.useEffect(()=>{const S=j=>{i.current&&!i.current.contains(j.target)&&r()},b=j=>{j.key==="Escape"&&r()};return document.addEventListener("mousedown",S),document.addEventListener("keydown",b),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("keydown",b)}},[r]);const u=210,h=Math.min(o,window.innerWidth-u-8),F=Math.min(d,window.innerHeight-200);return e.jsx("div",{ref:i,className:"fixed z-50 rounded-xl overflow-hidden py-1",style:{left:h,top:F,minWidth:u,background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 8px 32px rgba(0,0,0,0.14)"},children:s})}const Qs=[{label:"Layer default",value:""},{label:"Mint",value:"#E8F5E9"},{label:"Sky",value:"#E3F2FD"},{label:"Amber",value:"#FFF8E1"},{label:"Rose",value:"#FFF0F0"},{label:"Lavender",value:"#F3E5F5"},{label:"Peach",value:"#FBE9E7"}];function Js({x:o,y:d,nodeId:r,nodeKind:s,onClose:i,onEditName:u,onChangeColor:h,onRemoveFromDiagram:F,onDeleteFromModel:S,onLinkRisk:b,onLinkRequirement:j,onShowProperties:x,onFocusElement:y,onShowInCatalog:w,onShowRelMatrix:g,onOpenSource:E,onViewKindInOntology:m}){const[D,O]=l.useState(!1);return e.jsxs(Zo,{x:o,y:d,onClose:i,children:[e.jsxs("div",{className:"px-3 py-1.5",style:{borderBottom:"1px solid #E5E5E0"},children:[e.jsx("div",{style:{fontSize:"10px",fontWeight:600,color:"#9CA3AF"},children:s}),e.jsx("div",{style:{fontSize:"9px",color:"#D1D5DB",fontFamily:"monospace"},children:r})]}),x&&e.jsx(Q,{label:"Show Properties",icon:"ℹ",onClick:()=>{i(),x()}}),w&&e.jsx(Q,{label:"Show in Catalog",icon:"☰",onClick:()=>{i(),w()}}),y&&e.jsx(Q,{label:"Focus on Element",icon:"◎",onClick:()=>{i(),y()}}),g&&e.jsx(Q,{label:"Show Relationship Matrix",icon:"☷",onClick:()=>{i(),g()}}),m&&e.jsx(Q,{label:"View Kind in Ontology",icon:"⬡",onClick:()=>{i(),m()}}),E&&e.jsx(Q,{label:"Open Source File",icon:"⟨/⟩",onClick:()=>{i(),E()}}),(x||w||y||g||m||E)&&e.jsx(lt,{}),e.jsx(Q,{label:"Edit name",icon:"✏️",onClick:()=>{i(),u()}}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-1.5",style:{background:"none",border:"none",cursor:"pointer",fontSize:C.xs},onMouseEnter:v=>{O(!0),v.currentTarget.style.background="#F7F7F5"},onMouseLeave:v=>{v.currentTarget.style.background="none"},children:[e.jsx("span",{style:{fontSize:"12px",width:16,textAlign:"center"},children:"🎨"}),e.jsx("span",{style:{flex:1,textAlign:"left",color:"#1a1a1a"},children:"Change color"}),e.jsx("span",{style:{color:"#9CA3AF",fontSize:"10px"},children:"▶"})]}),D&&e.jsx("div",{className:"absolute left-full top-0 rounded-xl overflow-hidden py-1",style:{background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 4px 16px rgba(0,0,0,0.12)",minWidth:160},onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1),children:Qs.map(v=>e.jsxs("button",{onClick:()=>{i(),h(v.value)},className:"w-full flex items-center gap-2.5 px-3 py-1.5",style:{background:"none",border:"none",cursor:"pointer"},onMouseEnter:I=>{I.currentTarget.style.background="#F7F7F5"},onMouseLeave:I=>{I.currentTarget.style.background="none"},children:[e.jsx("div",{style:{width:14,height:14,borderRadius:3,flexShrink:0,background:v.value||"#E5E5E0",border:"1px solid #D1D5DB"}}),e.jsx("span",{style:{fontSize:C.xs,color:"#374151"},children:v.label})]},v.value))})]}),e.jsx(lt,{}),b&&e.jsx(Q,{label:"Link Risk",icon:"⚠️",onClick:()=>{i(),b()}}),j&&e.jsx(Q,{label:"Link Requirement",icon:"📋",onClick:()=>{i(),j()}}),(b||j)&&e.jsx(lt,{}),e.jsx(Q,{label:"Remove from diagram",icon:"↩️",onClick:()=>{i(),F()}}),e.jsx(Q,{label:"Delete from model",icon:"🗑️",danger:!0,onClick:()=>{window.confirm(`Delete ${r} from the model? This cannot be undone.`)&&(i(),S())}})]})}const ei=[{label:"Auto",value:""},{label:"Red",value:"#EF4444"},{label:"Blue",value:"#3B82F6"},{label:"Green",value:"#10B981"},{label:"Orange",value:"#F59E0B"},{label:"Gray",value:"#6B7280"}];function ti({x:o,y:d,edgeId:r,relType:s,onClose:i,onChangeStyle:u,onChangeColor:h,onToggleLabel:F,onDelete:S}){return e.jsxs(Zo,{x:o,y:d,onClose:i,children:[e.jsxs("div",{className:"px-3 py-1.5",style:{borderBottom:"1px solid #E5E5E0"},children:[e.jsx("div",{style:{fontSize:"10px",fontWeight:600,color:"#9CA3AF"},children:s}),e.jsx("div",{style:{fontSize:"9px",color:"#D1D5DB",fontFamily:"monospace"},children:r})]}),e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2",children:[e.jsx("span",{style:{fontSize:"10px",color:"#9CA3AF",minWidth:40},children:"Style"}),["solid","dashed","dotted"].map(b=>e.jsx("button",{onClick:()=>{i(),u(b)},style:{fontSize:"10px",padding:"2px 8px",border:"1px solid #E5E5E0",borderRadius:4,cursor:"pointer",background:"#F7F7F5",color:"#374151"},children:b},b))]}),e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{style:{fontSize:"10px",color:"#9CA3AF",minWidth:40,flexShrink:0},children:"Color"}),ei.map(b=>e.jsx("button",{onClick:()=>{i(),h(b.value)},title:b.label,style:{width:16,height:16,borderRadius:"50%",background:b.value||"#E5E5E0",border:"1px solid #D1D5DB",cursor:"pointer"}},b.value))]}),e.jsx(lt,{}),e.jsx(Q,{label:"Toggle label",icon:"🏷️",onClick:()=>{i(),F()}}),e.jsx(Q,{label:"Delete edge",icon:"🗑️",danger:!0,onClick:()=>{i(),S()}})]})}const oi=l.memo(function({id:d,data:r,selected:s}){const i=r,u=i.color??i.layerColor??"#E67E22",h=80,F=l.useCallback(S=>{var b;S.preventDefault(),(b=i.onContextMenu)==null||b.call(i,S,d)},[i,d]);return e.jsxs("div",{style:{width:h,height:h,position:"relative"},onContextMenu:F,children:[s&&e.jsx(ct,{minWidth:60,minHeight:60}),e.jsx("svg",{width:h,height:h,style:{position:"absolute",top:0,left:0},children:e.jsx("polygon",{points:`${h/2},4 ${h-4},${h/2} ${h/2},${h-4} 4,${h/2}`,fill:i.color?i.color+"44":"#FFF8E1",stroke:u,strokeWidth:s?2.5:1.5})}),e.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:600,color:"#374151",textAlign:"center",padding:"4px 8px",pointerEvents:"none"},children:i.condition||i.label||"?"}),e.jsx(A,{type:"target",position:N.Top,style:{background:u,border:"2px solid #fff"}}),e.jsx(A,{type:"source",position:N.Right,style:{background:u,border:"2px solid #fff"},id:"right"}),e.jsx(A,{type:"source",position:N.Bottom,style:{background:u,border:"2px solid #fff"},id:"bottom"}),e.jsx(A,{type:"target",position:N.Left,style:{background:u,border:"2px solid #fff"}})]})}),ni=l.memo(function({id:d,data:r,selected:s}){const i=r,u=(i.orientation??"horizontal")==="horizontal",h=u?120:8,F=u?8:60,S=l.useCallback(b=>{var j;b.preventDefault(),(j=i.onContextMenu)==null||j.call(i,b,d)},[i,d]);return e.jsxs("div",{style:{width:h,height:F,background:"#1a1a1a",borderRadius:4,position:"relative"},title:i.nodeType==="join"?"Join (synchronization)":"Fork (parallel)",onContextMenu:S,children:[s&&e.jsx(ct,{minWidth:40,minHeight:6}),u?e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"target",position:N.Left,style:{background:"#2DD4A8",border:"2px solid #fff",left:-1}}),e.jsx(A,{type:"source",position:N.Top,style:{background:"#2DD4A8",border:"2px solid #fff",top:-1},id:"top"}),e.jsx(A,{type:"source",position:N.Bottom,style:{background:"#2DD4A8",border:"2px solid #fff",bottom:-1},id:"bottom"}),e.jsx(A,{type:"source",position:N.Right,style:{background:"#2DD4A8",border:"2px solid #fff",right:-1},id:"right"})]}):e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"target",position:N.Top,style:{background:"#2DD4A8",border:"2px solid #fff",top:-1}}),e.jsx(A,{type:"source",position:N.Left,style:{background:"#2DD4A8",border:"2px solid #fff",left:-1},id:"left"}),e.jsx(A,{type:"source",position:N.Right,style:{background:"#2DD4A8",border:"2px solid #fff",right:-1},id:"right"}),e.jsx(A,{type:"source",position:N.Bottom,style:{background:"#2DD4A8",border:"2px solid #fff",bottom:-1},id:"bottom"})]})]})}),si=l.memo(function({id:d,data:r}){const s=r,i=s.nodeType==="start",u=32,h=l.useCallback(F=>{var S;F.preventDefault(),(S=s.onContextMenu)==null||S.call(s,F,d)},[s,d]);return e.jsxs("div",{style:{width:u,height:u,position:"relative"},onContextMenu:h,children:[e.jsx("svg",{width:u,height:u,children:i?e.jsx("circle",{cx:u/2,cy:u/2,r:u/2-2,fill:"#1a1a1a"}):e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:u/2,cy:u/2,r:u/2-2,fill:"#1a1a1a"}),e.jsx("circle",{cx:u/2,cy:u/2,r:u/2-6,fill:"#FFFFFF"}),e.jsx("circle",{cx:u/2,cy:u/2,r:u/2-10,fill:"#1a1a1a"})]})}),i?e.jsx(A,{type:"source",position:N.Bottom,style:{background:"#1a1a1a",border:"2px solid #fff"}}):e.jsx(A,{type:"target",position:N.Top,style:{background:"#1a1a1a",border:"2px solid #fff"}})]})}),ii="#ECEBE6",dt="#1B3A4B",Ot="#5B6470",ri="0 1px 2px rgba(0,0,0,0.16), 0 0 0 0.5px rgba(0,0,0,0.05)",fe=(o,d)=>e.jsx("svg",{width:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.9,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block"},children:d}),ae={arrowRight:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 12h14"}),e.jsx("path",{d:"M13 6l6 6-6 6"})]})),arrowDown:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M12 4v14"}),e.jsx("path",{d:"M6 13l6 6 6-6"})]})),lanes:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"3",y:"5",width:"18",height:"3.4",rx:"1.3"}),e.jsx("rect",{x:"3",y:"10.3",width:"18",height:"3.4",rx:"1.3"}),e.jsx("rect",{x:"3",y:"15.6",width:"18",height:"3.4",rx:"1.3"})]})),grid:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"3.5",y:"3.5",width:"17",height:"17",rx:"2.5"}),e.jsx("path",{d:"M9.2 3.5v17M14.8 3.5v17M3.5 9.2h17M3.5 14.8h17"})]})),expand:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M15 4h5v5"}),e.jsx("path",{d:"M9 20H4v-5"}),e.jsx("path",{d:"M20 4l-7 7"}),e.jsx("path",{d:"M4 20l7-7"})]})),collapse:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M14 10h5"}),e.jsx("path",{d:"M19 10V5"}),e.jsx("path",{d:"M10 14H5"}),e.jsx("path",{d:"M5 14v5"}),e.jsx("path",{d:"M20 4l-6 6"}),e.jsx("path",{d:"M4 20l6-6"})]})),filter:({size:o=16})=>fe(o,e.jsx("path",{d:"M4 5h16l-6.2 7.4V19l-3.6 1.8v-8.4z"})),back:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M11 5l-6 7 6 7"}),e.jsx("path",{d:"M5 12h14"})]}))};function $e(){return e.jsx("span",{"aria-hidden":"true",style:{width:1,height:18,background:"#E2E1DB",margin:"0 3px",borderRadius:1}})}function _o({options:o,value:d,onChange:r}){return e.jsx("div",{role:"tablist",style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,background:ii,borderRadius:9},children:o.map(s=>{const i=s.value===d;return e.jsxs("button",{role:"tab","aria-selected":i,onClick:()=>r(s.value),title:s.title,className:"flex items-center gap-1.5 text-xs font-semibold",style:{padding:s.label?"3px 9px":"4px 7px",borderRadius:7,border:"none",cursor:"pointer",color:i?dt:Ot,background:i?"#FFFFFF":"transparent",boxShadow:i?ri:"none",transition:"background 140ms ease, color 140ms ease, box-shadow 140ms ease"},children:[s.icon,s.label&&e.jsx("span",{children:s.label})]},s.value)})})}function ai({children:o}){return e.jsx("div",{style:{display:"inline-flex",alignItems:"center",background:"#FFFFFF",border:"1px solid #E2E1DB",borderRadius:9,overflow:"hidden"},children:No.Children.toArray(o).map((d,r)=>e.jsxs(No.Fragment,{children:[r>0&&e.jsx("span",{"aria-hidden":"true",style:{width:1,alignSelf:"stretch",background:"#EDECE7"}}),d]},r))})}function Ho({icon:o,label:d,onClick:r,active:s=!1,title:i,ariaExpanded:u}){return e.jsxs("button",{onClick:r,title:i,"aria-pressed":s,"aria-expanded":u,className:"flex items-center gap-1.5 text-xs font-semibold",style:{padding:d?"5px 9px":"5px 7px",border:"none",cursor:"pointer",color:s?"#FFFFFF":Ot,background:s?dt:"transparent",transition:"background 140ms ease, color 140ms ease"},children:[o,d&&e.jsx("span",{children:d})]})}function Pe({icon:o,label:d,onClick:r,active:s=!1,title:i,badge:u}){return e.jsxs("button",{onClick:r,title:i,"aria-pressed":s,className:"flex items-center gap-1.5 text-xs font-semibold",style:{padding:u!=null||d!=null?"5px 9px":"5px 7px",borderRadius:9,border:`1px solid ${s?dt:"#E2E1DB"}`,cursor:"pointer",color:s?"#FFFFFF":Ot,background:s?dt:"#FFFFFF",transition:"background 140ms ease, color 140ms ease, border-color 140ms ease"},children:[o,d!=null&&e.jsx("span",{children:d}),u!=null&&e.jsx("span",{style:{fontSize:11,fontWeight:700,lineHeight:1,padding:"2px 5px",borderRadius:6,background:s?"rgba(255,255,255,0.22)":"#F0EFEA",color:s?"#FFFFFF":"#6B7280"},children:u})]})}const Ko="memo-layout-progress";if(typeof document<"u"&&!document.getElementById(Ko)){const o=document.createElement("style");o.id=Ko,o.textContent="@keyframes memo-layout-progress { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }",document.head.appendChild(o)}const li={background:"#F7F7F5"},di={padding:.08,maxZoom:2},ci={background:"#FFFFFF"},pi={hideAttribution:!0},ui=[20,20],xi=50,Vo=8e3,hi=90;function Yo(o,d){return new Promise((r,s)=>{const i=window.setTimeout(()=>s(new Error(`${d} layout exceeded ${Vo/1e3}s`)),Vo);o.then(u=>{window.clearTimeout(i),r(u)},u=>{window.clearTimeout(i),s(u)})})}function Go(o,d){const r=new Map(o.map(x=>[x.id,x])),s=new Map,i=x=>{const y=s.get(x);if(y)return y;const w=r.get(x),g=w.parentId?i(w.parentId):{x:0,y:0},E={x:g.x+w.position.x,y:g.y+w.position.y};return s.set(x,E),E},u=x=>{var y,w;return{width:Number(x.width??((y=x.style)==null?void 0:y.width)??0),height:Number(x.height??((w=x.style)==null?void 0:w.height)??0)}},h=d.flatMap(x=>{var D,O,v,I,$,z;const y=(X,T,le)=>{var U,Y;if(typeof T=="string"){const G=(((Y=(U=r.get(X))==null?void 0:U.data)==null?void 0:Y.ports)??[]).find(ge=>ge.id===T);if(G){const ge=G.size??20;return{x:G.x+ge/2,y:G.y+ge/2}}}return le},w=y(x.source,(D=x.data)==null?void 0:D.sourcePortId,(O=x.data)==null?void 0:O.sourceOffset),g=y(x.target,(v=x.data)==null?void 0:v.targetPortId,(I=x.data)==null?void 0:I.targetOffset);if(!w||!g||!r.has(x.source)||!r.has(x.target))return[];const E=i(x.source),m=i(x.target);return[{id:x.id,source:{x:E.x+w.x,y:E.y+w.y},target:{x:m.x+g.x,y:m.y+g.y},sourceNodeId:x.source,targetNodeId:x.target,sourceSide:($=x.data)==null?void 0:$.sourceSide,targetSide:(z=x.data)==null?void 0:z.targetSide}]});if(h.length===0)return d;const F=o.filter(x=>!x.data.isFrame).map(x=>({id:x.id,...i(x.id),...u(x)})),S=new Map(h.map(x=>[x.id,x])),b=h.filter(x=>{var y,w;return!((w=(y=d.find(g=>g.id===x.id))==null?void 0:y.data)!=null&&w.manualRoute)}),j=xs(b,F);return d.map(x=>{var w;const y=S.get(x.id);if(!y)return x;if((w=x.data)!=null&&w.manualRoute){const g=[...x.data.points??[]];if(g.length>=2)return g[0]=y.source,g[g.length-1]=y.target,{...x,data:{...x.data,points:g}}}return j.has(x.id)?{...x,data:{...x.data,points:j.get(x.id)}}:x})}function fi({x:o,y:d,onConfirm:r,onCancel:s}){const[i,u]=l.useState(""),h=l.useRef(null);l.useEffect(()=>{var b;(b=h.current)==null||b.focus()},[]),l.useEffect(()=>{const b=j=>{const x=document.getElementById("quick-create-popup");x&&!x.contains(j.target)&&s()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[s]);const F=Math.min(o,window.innerWidth-220),S=Math.min(d,window.innerHeight-80);return e.jsxs("div",{id:"quick-create-popup",className:"fixed z-50 rounded-xl shadow-xl overflow-hidden",style:{left:F,top:S,width:200,background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 8px 32px rgba(0,0,0,0.14)"},children:[e.jsx("div",{className:"px-3 py-2",style:{borderBottom:"1px solid #E5E5E0",fontSize:C.xs,color:"#9CA3AF",fontWeight:600},children:"New Element"}),e.jsxs("div",{className:"px-2 py-2",children:[e.jsx("input",{ref:h,value:i,onChange:b=>u(b.target.value),placeholder:"Element name…",className:"w-full px-2 py-1.5 rounded focus:outline-none",style:{fontSize:C.xs,border:"1px solid #E5E5E0",background:"#F7F7F5",color:"#1a1a1a"},onKeyDown:b=>{b.key==="Enter"&&i.trim()&&(b.preventDefault(),r(i.trim())),b.key==="Escape"&&s()}}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx("button",{onClick:()=>i.trim()&&r(i.trim()),style:{flex:1,fontSize:C.xs,padding:"4px 8px",background:"#2DD4A8",color:"#FFFFFF",border:"none",borderRadius:6,cursor:"pointer",fontWeight:600},children:"Create"}),e.jsx("button",{onClick:s,style:{fontSize:C.xs,padding:"4px 8px",background:"#F7F7F5",color:"#6B7280",border:"1px solid #E5E5E0",borderRadius:6,cursor:"pointer"},children:"Cancel"})]})]})]})}function Lt({color:o,glyph:d}){return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:13,height:13,borderRadius:2,background:o+"22",border:`1.5px solid ${o}`,color:o,fontSize:9,fontWeight:800,lineHeight:1},children:d})}function gi(){var ho,fo,go,mo,yo,bo,Fo,wo,jo,vo;const o=M(t=>t.model),d=M(t=>t.selectedElementId),r=M(t=>t.selectedViewpointId),s=M(t=>t.selectedDiagramId),i=M(t=>t.hiddenLayers),u=M(t=>t.selectElement),h=M(t=>t.inspectElement),F=M(t=>t.inspectRelationship),S=M(t=>t.setActiveMode),b=M(t=>t.setActiveView),j=M(t=>t.setExplorerTab),x=M(t=>t.availableOntologies),y=M(t=>t.setSelectedOntologyKind),w=M(t=>t.diagramLayouts),g=M(t=>t.setNodeLayout),E=M(t=>t.mergeDiagramLayouts),m=M(t=>t.updateDiagramElementIds),{fitView:D,screenToFlowPosition:O,getViewport:v,setViewport:I}=zt(),[$,z]=$n([]),[X,T,le]=Pn([]),U=l.useRef([]),Y=l.useRef([]),G=l.useRef(o),ge=l.useRef(s),pt=l.useRef(null),ut=l.useRef(null),xt=l.useRef(null),be=l.useRef(0);l.useEffect(()=>{U.current=$},[$]),l.useEffect(()=>{Y.current=X},[X]);const _e=l.useCallback(t=>{U.current=t,ut.current===null&&(ut.current=requestAnimationFrame(()=>{ut.current=null;const n=U.current,a=Go(n,Y.current);Y.current=a,z(n),T(a)}))},[z,T]),[te,He]=l.useState(!1),[Wt,Fe]=l.useState(0),[$t,ht]=l.useState(null),[Pt,Qo]=l.useState(0),[Jo,ft]=l.useState(0),[ve,gt]=l.useState(!0),[en,_t]=l.useState(!0),[Ht,tn]=l.useState(!0),[mt,on]=l.useState("horizontal"),[Ke,Kt]=l.useState("allocation"),[yt,Vt]=l.useState("all"),[Yt,nn]=l.useState(!1),[de,sn]=l.useState(new Set(["control","data","energy","material"])),[J,Ee]=l.useState(null),[ce,Ve]=l.useState(null),[q,ke]=l.useState(null),[ie,Ye]=l.useState(null),[Se,Gt]=l.useState(null),[Ge,rn]=l.useState(2),[Xe,Xt]=l.useState(null),Ce=l.useRef([]),bt=l.useRef([]),qt=l.useCallback(t=>{Ce.current.push(t),Ce.current.length>xi&&Ce.current.shift(),bt.current=[]},[]),f=Un(o,s),Ie=f?Do[f.diagramType]:null,qe=!!((ho=f==null?void 0:f.properties)!=null&&ho.layoutStyle),pe=((fo=f==null?void 0:f.properties)==null?void 0:fo.layoutStyle)==="fbs",me=s?w[s]:void 0,ue=ts(me),re=((go=me==null?void 0:me.canvas)==null?void 0:go.autoLayout)!==!1,xe=((mo=me==null?void 0:me.canvas)==null?void 0:mo.flowAnimation)===!0,oe=l.useCallback(()=>{var n;if(!s)return;const t=M.getState().diagramLayouts[s]??{nodes:{},edges:{}};((n=t.canvas)==null?void 0:n.autoLayout)!==!1&&E({[s]:{...t,canvas:{...t.canvas,autoLayout:!1}}})},[s,E]);l.useEffect(()=>{if(!s||re||te||$.length===0||Wt===0)return;const t=window.setTimeout(()=>{const n=M.getState().diagramLayouts[s]??{nodes:{},edges:{}},a=v(),p={nodes:Object.fromEntries($.map(c=>[c.id,{...n.nodes[c.id]??{},x:c.position.x,y:c.position.y,...c.width?{width:c.width}:{},...c.height?{height:c.height}:{},ports:Object.fromEntries((c.data.ports??[]).map(k=>[k.id,{x:k.x,y:k.y,side:k.side}]))}])),edges:Object.fromEntries(X.map(c=>{var k,B,R,P,H,W;return[c.id,{...(()=>{var _;const{points:V,...K}=((_=n.edges)==null?void 0:_[c.id])??{};return K})(),...(k=c.data)!=null&&k.manualRoute&&((R=(B=c.data)==null?void 0:B.points)!=null&&R.length)?{points:(P=c.data)==null?void 0:P.points,source:c.source,target:c.target,sourcePortId:(H=c.data)==null?void 0:H.sourcePortId,targetPortId:(W=c.data)==null?void 0:W.targetPortId}:{}}]})),canvas:{...n.canvas,zoom:a.zoom,pan:{x:a.x,y:a.y},autoLayout:!1}};E({[s]:p}),We(s,p),Fe(0)},350);return()=>window.clearTimeout(t)},[s,re,te,Wt,$,X,v,E]);const L=f?f.viewKind??(Ie==null?void 0:Ie.viewKind)??"general":void 0,Ne=L==="interconnection"?.72:.1,De=L?Ro[L]:null,ye=L==="general"&&!qe&&!pe,[he,Ut]=l.useState("graph"),Zt=l.useMemo(()=>L==="statetransition"?["compound-graph"]:["flat-graph"],[L]),Ft=l.useMemo(()=>vs(Zt).filter(t=>t.mode==="automatic"),[Zt]),an=pe||ye&&he==="graph"||L==="interconnection"||L==="actionflow"||L==="statetransition",wt=(yo=f==null?void 0:f.properties)==null?void 0:yo.modes,ln=l.useMemo(()=>{if(!wt)return Nt;const t=new Set(wt.split(",").map(a=>a.trim())),n=Nt.filter(a=>t.has(a));return n.length?n:Nt},[wt]),[Ae,Qt]=l.useState(!0),Jt=l.useMemo(()=>{if(!o||!f)return[];const t=new Set(f.elementIds),n=Object.values(o.elements).filter(a=>t.has(a.id)&&a.allocatedTo).map(a=>a.allocatedTo);return os(n,o)},[o,f]),dn=l.useMemo(()=>{if(!o||!f)return"Activity Diagram";const t=Zn(f);return Do[t].fullName},[o,f]),cn=l.useMemo(()=>{if(!o||!f)return!1;const t=new Set(f.elementIds);return Object.values(o.elements).some(n=>t.has(n.id)&&!!(n.attributes.stage||n.attributes.phase))},[o,f]),Ue=l.useMemo(()=>{if(!o||!f||L!=="actionflow")return[];const t=(f.elementIds??[]).map(n=>o.elements[n]).filter(n=>!!n&&n.construct==="action");return ns(t,o)},[o,f,L]),[Re,pn]=l.useState("containment"),[Te,Ze]=l.useState(new Set),[eo,Le]=l.useState(new Set),[we,Qe]=l.useState(null),[Be,to]=l.useState("all"),[oo,no]=l.useState(!1),[so,ze]=l.useState(new Set),[Me,jt]=l.useState(null),[Je,un]=l.useState(new Map),ne=l.useRef(new Map),vt=l.useMemo(()=>{if(!o||!we)return[];const t=new Map;for(const c of o.relationships)ss.has(c.type)&&!t.has(c.targetId)&&t.set(c.targetId,c.sourceId);const n=[we],a=new Set(n);let p=we;for(;t.has(p);){const c=t.get(p);if(a.has(c))break;n.unshift(c),a.add(c),p=c}return n},[o,we]);l.useEffect(()=>{var n,a;Fe(0),Ut(is(f==null?void 0:f.properties)),Qt(!0),Kt("allocation"),Vt("all");const t=(a=(n=f==null?void 0:f.properties)==null?void 0:n.styleHint)!=null&&a.startsWith("expanded:")?f.properties.styleHint.slice(9).split(",").map(p=>p.trim()).filter(Boolean):[];Ze(new Set(t)),Le(new Set),Qe(null),to("all"),no(!1),ze(new Set),jt(null),ne.current.clear()},[s,(bo=f==null?void 0:f.properties)==null?void 0:bo.layoutHint,(Fo=f==null?void 0:f.properties)==null?void 0:Fo.styleHint]);const xn=l.useMemo(()=>({decompositionNode:Ss,interconnectionNode:Rs,actionFlowNode:Ws,actionFlowLane:Ps,stateNode:Hs,seqLifeline:Vs,seqSection:Gs,seqOccurrence:qs,diagramNode:Us,decisionNode:oi,forkNode:ni,startEndNode:si}),[]),hn=l.useMemo(()=>({interconnectionEdge:Ms}),[]),fn=l.useCallback(t=>{var n,a;return((n=t.data)==null?void 0:n.color)||((a=t.data)==null?void 0:a.layerColor)||"#ccc"},[]),Z=l.useMemo(()=>{const t=(f==null?void 0:f.viewpointId)==="__model"?null:(f==null?void 0:f.viewpointId)||r,n=t&&(o==null?void 0:o.viewpoints),a=i.size>0,p=f!=null&&f.elementIds?new Set(f.elementIds):void 0;if(!n&&!a&&!p)return;const c=n?o.viewpoints.find(R=>R.id===t):void 0,k=c?new Set(c.visibleKinds):void 0,B=c?new Set(c.visibleLayers):void 0;return R=>i.has(R.layer)?!1:p?p.has(R.id):k&&B?k.has(R.kind)||B.has(R.layer):!0},[r,f,o==null?void 0:o.viewpoints,i]),et=l.useMemo(()=>!o||!f||f.diagramType!=="bdd"?null:rs(Lo(o,Z)),[o,f,Z]),io=l.useCallback(()=>{if(o)return pe?as(o):ye?Lo(o,Z):ls(o)},[o,pe,ye,Z]),Oe=l.useCallback(t=>{Ze(n=>{const a=new Set(n);return a.has(t)?a.delete(t):a.add(t),a})},[]),ro=l.useCallback(t=>{Le(n=>{const a=new Set(n);return a.has(t)?a.delete(t):a.add(t),a})},[]),ao=l.useCallback(t=>{ze(n=>{const a=new Set(n);return a.has(t)?a.delete(t):a.add(t),a})},[]),tt=l.useCallback(t=>{ne.current.clear(),un(n=>{const a=new Map(n),p=a.get(t)||"vertical";return a.set(t,p==="vertical"?"horizontal":"vertical"),a})},[]),Et=l.useCallback(()=>{const t=io();if(!t)return;const n=new Set,a=p=>{n.add(p);for(const c of t.childrenMap.get(p)||[])t.elements.has(c)&&a(c)};for(const p of t.roots)t.elements.has(p)&&a(p);Ze(n)},[io]),kt=l.useCallback(()=>Ze(new Set),[]),St=l.useCallback(()=>{ne.current.clear(),ft(t=>t+1)},[]),lo=l.useCallback(t=>t.map(n=>{if(n.type!=="diagramNode")return n;const a=o==null?void 0:o.elements[n.id];return{...n,data:{...n.data,onContextMenu:(p,c)=>{ke({x:p.clientX,y:p.clientY,nodeId:c,nodeKind:n.data.kind??""})},onInlineEdit:(p,c)=>{if(!a)return;const k={...a,name:c};Ao(k)}}}}),[o]),co=l.useCallback((t,n)=>{const a=t.map(c=>{const k=n.nodes[c.id];return k?{...c,position:{x:k.x,y:k.y},...k.width?{width:k.width}:{},...k.height?{height:k.height}:{},data:{...c.data,bgColor:k.color||void 0,...k.ports?{ports:(c.data.ports??[]).map(B=>{var R;return{...B,...((R=k.ports)==null?void 0:R[B.id])??{}}})}:{}}}:c}),p=new Map(a.map(c=>[c.id,c]));return a.map(c=>{if(c.type!=="actionFlowLane")return c;const k=c.data,B=(k.memberIds??[]).map(K=>p.get(K)).filter(Boolean);if(B.length===0)return c;const R=Math.min(...B.map(K=>K.position.x)),P=Math.min(...B.map(K=>K.position.y)),H=Math.max(...B.map(K=>{var _;return K.position.x+Number(K.width??((_=K.style)==null?void 0:_.width)??180)})),W=Math.max(...B.map(K=>{var _;return K.position.y+Number(K.height??((_=K.style)==null?void 0:_.height)??96)})),V=k.orientation==="column";return{...c,position:{x:V?R-36:R-120,y:V?P-32:P-36},style:{...c.style,width:H-R+(V?72:156),height:W-P+(V?68:72)}}})},[]),po=l.useCallback((t,n,a)=>{be.current=Date.now()+250,oe(),Fe(k=>k+1);const p=Y.current.map(k=>{var W,V;if(!(((W=k.data)==null?void 0:W.sourcePortId)===n||((V=k.data)==null?void 0:V.targetPortId)===n))return k;const{points:R,manualRoute:P,...H}=k.data??{};return{...k,data:H}});Y.current=p;const c=U.current.map(k=>k.id!==t?k:{...k,data:{...k.data,ports:(k.data.ports??[]).map(B=>B.id===n?{...B,y:a}:B)}});_e(c)},[_e,oe]),uo=l.useCallback((t,n)=>{be.current=Date.now()+250,oe(),Fe(a=>a+1),T(a=>{const p=a.map(c=>c.id===t?{...c,data:{...c.data,points:n,manualRoute:!0}}:c);return Y.current=p,p})},[oe,T]);l.useEffect(()=>{if(!o)return;const t=G.current!==o&&ge.current===s;if(pt.current=t?v():null,G.current=o,ge.current=s,L==="grid"||L==="browser"||L==="geometry")return;let n=!1;const a=({nodes:R,edges:P},H=!0)=>{if(n)return;const W=s?M.getState().diagramLayouts[s]:void 0,V=W&&Object.keys(W.nodes).length>0?co(R,W):R,K=P.map(_=>{var Eo,ko,So;const se=(Eo=W==null?void 0:W.edges)==null?void 0:Eo[_.id],ot=!(se!=null&&se.source)||se.source===_.source&&se.target===_.target&&se.sourcePortId===((ko=_.data)==null?void 0:ko.sourcePortId)&&se.targetPortId===((So=_.data)==null?void 0:So.targetPortId)?se==null?void 0:se.points:void 0;return{..._,data:{..._.data,...ot!=null&&ot.length?{points:ot,manualRoute:!0}:{},flowAnimation:xe,onRouteChange:Ct=>uo(_.id,Ct),onSelect:Ct=>{Ct.stopPropagation(),!(Date.now()<be.current)&&(T(It=>It.map(Co=>({...Co,selected:Co.id===_.id}))),o.relationships.some(It=>It.id===_.id)&&F(_.id))}}}});z(H?lo(V):V),T(Go(V,K)),He(!1),Qo(_=>_+1)},p=R=>P=>{n||(console.error(`${R} layout error:`,P),He(!1),ht(`${R} layout could not be completed. Try resetting the layout or reducing the visible hierarchy.`))},c=(R,P,H=!0)=>{He(!0),ht(null),Yo(P,R).then(W=>a(W,H)).catch(p(R))},k=()=>{if(pe)c("FBS",hs(o,{expandedNodes:Te,nodeDirections:Je,callbacks:{onToggleExpand:Oe,onToggleDirection:tt},layoutProviderId:ue}));else if(qe)Re==="decomposition"?c("Decomposition",fs(o,{expandedNodes:Te,nodeDirections:Je,callbacks:{onToggleExpand:Oe,onToggleDirection:tt},positionCache:ne.current})):a(gs(o,{expandedNodes:Te,callbacks:{onToggleExpand:Oe}}));else if(L==="interconnection")c("Interconnection",ms(o,{viewpointFilter:Z,relationshipTypes:f==null?void 0:f.relationshipTypes,collapsedNodes:eo,onToggleCollapse:ro,focusId:we??void 0,portDisplay:Be,onPortMove:po,layoutProviderId:ue}),!1);else if(L==="actionflow")c("Action flow",ys(o,{viewpointFilter:Z,swimlanes:Ae,laneGrouping:Ke,displayLevel:yt,expandedActionIds:so,onToggleAction:ao,focusActionId:Me??void 0,visibleFlowKinds:de,direction:mt,layoutProviderId:ue}),!1);else if(L==="statetransition")c("State transition",bs(o,{viewpointFilter:Z,layoutProviderId:ue}),!1);else if(L==="sequence")a(Fs(o,{viewpointFilter:Z}),!1);else if(ye&&he!=="graph")c("General",ws(o,{mode:he,viewpointFilter:Z,expandedNodes:Te,nodeDirections:Je,callbacks:{onToggleExpand:Oe,onToggleDirection:tt},positionCache:ne.current,layoutProviderId:ue}));else{const R=f==null?void 0:f.relationshipTypes,P=ye;He(!0),ht(null),Yo(js(o,{viewpointFilter:Z,relationshipTypes:R,compartments:P,layoutProviderId:ue}),"Standard").then(({nodes:H,edges:W})=>{a({nodes:H,edges:W})}).catch(p("Standard"))}},B=window.setTimeout(k,hi);return()=>{n=!0,window.clearTimeout(B)}},[o,Z,qe,pe,Re,L,ye,he,Ae,Jo,f==null?void 0:f.relationshipTypes,ue,Te,eo,we,Be,so,Me,de,mt,Ke,yt,Je,Oe,ro,ao,tt,s,co,lo,po,uo,F,v]),l.useEffect(()=>{if(Pt===0)return;const t=setTimeout(()=>{var p;const n=pt.current;if(pt.current=null,n){I(n);return}const a=s?(p=M.getState().diagramLayouts[s])==null?void 0:p.canvas:void 0;(a==null?void 0:a.zoom)!==void 0&&a.pan?I({x:a.pan.x,y:a.pan.y,zoom:a.zoom},{duration:300}):D({padding:.08,minZoom:Ne,maxZoom:2,duration:500})},200);return()=>clearTimeout(t)},[Pt,s,D,Ne,I]),l.useEffect(()=>{z(t=>t.map(n=>{const a=n.type==="actionFlowLane"?n.data.inspectElementId:void 0,p=!!d&&(n.id===d||a===d);return{...n,selected:p,style:{...n.style,boxShadow:p?"0 0 0 2px #2DD4A8, 0 4px 12px rgba(45, 212, 168, 0.3)":void 0,opacity:d?p?1:.5:1}}}))},[d,z]),l.useEffect(()=>{if(!Se||!o)return;const t=Es(o,Se,"both",Ge),n=new Set(t.nodes.map(a=>a.elementId));n.add(Se),z(a=>a.map(p=>({...p,style:{...p.style,opacity:n.has(p.id)?1:.08,pointerEvents:n.has(p.id)?"all":"none"}}))),T(a=>a.map(p=>({...p,style:{...p.style,opacity:n.has(p.source)&&n.has(p.target)?1:.05}})))},[Se,Ge,o,z,T]),l.useEffect(()=>{if(!Xe)return;const t=setTimeout(()=>Xt(null),2500);return()=>clearTimeout(t)},[Xe]),l.useEffect(()=>{const t=n=>{const a=n.target;if(!(a.tagName==="INPUT"||a.tagName==="TEXTAREA")){if((n.metaKey||n.ctrlKey)&&n.key==="z"&&!n.shiftKey){n.preventDefault();const p=Ce.current.pop();p&&(p.undo(),bt.current.push(p))}if((n.metaKey||n.ctrlKey)&&(n.key==="Z"||n.key==="z"&&n.shiftKey)){n.preventDefault();const p=bt.current.pop();p&&(p.do(),Ce.current.push(p))}n.key==="g"&&(n.metaKey||n.ctrlKey)&&n.shiftKey&&(n.preventDefault(),_t(p=>!p)),n.key==="0"&&(n.metaKey||n.ctrlKey)&&(n.preventDefault(),D({padding:.08,minZoom:Ne,maxZoom:2,duration:400}))}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[D,Ne]);const gn=l.useCallback(t=>{t.preventDefault(),t.dataTransfer.dropEffect="copy"},[]),mn=l.useCallback(t=>{t.preventDefault();const n=t.dataTransfer.getData("application/memo-kind");if(n)try{const a=JSON.parse(n),p=O({x:t.clientX,y:t.clientY});Ee({x:t.clientX,y:t.clientY,flowX:p.x,flowY:p.y,kind:a.kind,layer:a.layer,construct:a.construct})}catch{}},[O]),yn=l.useCallback(t=>{const n=O({x:t.clientX,y:t.clientY});Ee({x:t.clientX,y:t.clientY,flowX:n.x,flowY:n.y})},[O]),bn=l.useCallback(t=>{if(!J||!s){Ee(null);return}const n=J.kind??"Part",a=J.layer??"logical",p=J.construct??"part",c=Xo[a]??"#6B7280",k=`_new_${Date.now()}`,B={id:k,type:"diagramNode",position:{x:J.flowX,y:J.flowY},data:{label:t,kind:n,layer:a,construct:p,color:c,isNew:!0,onContextMenu:(W,V)=>{ke({x:W.clientX,y:W.clientY,nodeId:V,nodeKind:n})},onInlineEdit:(W,V)=>{Ao({id:k,name:V,kind:n,construct:p,layer:a})}}};z(W=>[...W,B]),Qn({name:t,kind:n,construct:p,attributes:{_layer:a}});const R=(f==null?void 0:f.elementIds)??[];m(s,[...R,k]);const P=s,H={nodes:{...(w[P]??{}).nodes??{},[k]:{x:J.flowX,y:J.flowY}},edges:(w[P]??{}).edges??{}};E({[P]:H}),We(P,H),Ee(null)},[J,s,f,w,E,m,z]),Fn=l.useCallback(()=>{ke(null),Ye(null)},[]),wn=l.useCallback((t,n)=>{n!=null&&n.isValid},[]),jn=l.useCallback(t=>{const{source:n,target:a}=t;if(!n||!a)return;const p=o==null?void 0:o.elements[n],c=o==null?void 0:o.elements[a];Ve({x:window.innerWidth/2-120,y:window.innerHeight/2-160,sourceId:n,targetId:a,sourceKind:(p==null?void 0:p.kind)??"",targetKind:(c==null?void 0:c.kind)??""})},[o]),vn=l.useCallback(t=>{if(!ce||!s){Ve(null);return}const{sourceId:n,targetId:a}=ce,p=je[t]??"#6B7280",k={id:`e_${n}_${a}_${t}_${Date.now()}`,source:n,target:a,label:t,type:"default",style:{stroke:p,strokeWidth:2},labelStyle:{fontSize:"10px",fill:"#374151"},labelBgStyle:{fill:"#FFFFFF",fillOpacity:.9},labelBgPadding:[4,2],labelBgBorderRadius:4,markerEnd:{type:"arrowclosed",color:p}};T(B=>_n(k,B)),Jn(n,a,t),Ve(null)},[ce,s,T]),En=l.useCallback((t,n)=>{xt.current={id:n.id,x:n.position.x,y:n.position.y}},[]),kn=l.useCallback((t,n)=>{const a=xt.current;if(xt.current=null,(a==null?void 0:a.id)===n.id&&Math.hypot(n.position.x-a.x,n.position.y-a.y)>2&&(be.current=Date.now()+250,Fe(B=>B+1)),!s)return;oe();const{x:p,y:c}=n.position,k=ne.current.get(n.id);if(ne.current.set(n.id,{x:p,y:c}),g(s,n.id,{x:p,y:c}),k){const B=n.id,R=s;qt({do:()=>g(R,B,{x:p,y:c}),undo:()=>{g(R,B,k),z(P=>P.map(H=>H.id===B?{...H,position:k}:H))}})}},[s,g,qt,z,oe]),Sn=l.useCallback(t=>{t.some(n=>n.type==="position")&&oe(),t.some(n=>n.type==="dimensions"&&n.resizing)&&(oe(),Fe(n=>n+1)),_e(Hn(t,U.current))},[_e,oe]),Cn=l.useCallback((t,n)=>{},[]),In=l.useCallback((t,n)=>{t.preventDefault(),Ye({x:t.clientX,y:t.clientY,edgeId:n.id,relType:String(n.label??"edge")})},[]),Nn=l.useCallback((t,n)=>{if(Date.now()<be.current)return;const a=n.type==="actionFlowLane"?n.data.inspectElementId:void 0;!a&&(n.id.startsWith("__")||n.id.includes("__start")||n.id.includes("__done"))||(h(a??n.id),s&&b({type:"diagram",diagramId:s}))},[h,s,b]),Dn=l.useCallback((t,n)=>{var a;if((a=t==null?void 0:t.stopPropagation)==null||a.call(t),L==="actionflow"){if(!Object.values((o==null?void 0:o.elements)??{}).some(c=>c.parentAction===n.id))return;jt(n.id),ze(new Set),h(null);return}if(L==="interconnection"){if(!!!n.data.isContainer){h(n.id);return}Qe(n.id),Le(new Set),h(null)}},[L,o==null?void 0:o.elements,h]),An=l.useCallback(()=>{u(null),F(null),ke(null),Ye(null),z(t=>t.map(n=>({...n,style:{...n.style,opacity:1,boxShadow:void 0}}))),T(t=>t.map(n=>n.selected?{...n,selected:!1}:n))},[u,F,z,T]),Rn=l.useCallback((t,n)=>{var a;(a=t==null?void 0:t.stopPropagation)==null||a.call(t),!(Date.now()<be.current)&&(T(p=>p.map(c=>({...c,selected:c.id===n.id}))),o!=null&&o.relationships.some(p=>p.id===n.id)?F(n.id):o!=null&&o.elements[n.id]&&h(n.id))},[o,h,F,T]),Tn=l.useCallback((t,n)=>{var a;s&&(g(s,t,{...((a=w[s])==null?void 0:a.nodes[t])??{x:0,y:0},color:n||void 0}),z(p=>p.map(c=>c.id===t?{...c,data:{...c.data,bgColor:n||void 0}}:c)))},[s,w,g,z]),xo=l.useCallback(t=>{if(!s||!f)return;const n=(f.elementIds??[]).filter(a=>a!==t);m(s,n),z(a=>a.filter(p=>p.id!==t))},[s,f,m,z]),Ln=l.useCallback((t,n)=>{const a=n==="dashed"?"6 3":n==="dotted"?"2 3":void 0;T(p=>p.map(c=>c.id===t?{...c,style:{...c.style,strokeDasharray:a}}:c))},[T]),Bn=l.useCallback((t,n)=>{T(a=>a.map(p=>p.id===t?{...p,style:{...p.style,stroke:n||(je[String(p.label??"")]??"#6B7280")}}:p))},[T]),zn=l.useCallback(t=>{T(n=>n.map(a=>a.id===t?{...a,label:a.label?"":t.split("_")[3]??""}:a))},[T]);if(f&&o&&L==="grid")return e.jsx(ds,{diagram:f,model:o,viewpointFilter:Z});if(f&&o&&L==="browser")return e.jsx(cs,{diagram:f,model:o,viewpointFilter:Z});if(f&&L==="geometry"){const t=Ro.geometry;return e.jsx("div",{className:"flex-1 flex items-center justify-center",style:{background:"#F7F7F5"},children:e.jsxs("div",{className:"text-center",style:{maxWidth:"380px"},children:[e.jsx("span",{className:"inline-block px-2 py-0.5 rounded font-semibold",style:{background:t.color+"20",color:t.color,fontSize:C.badge,marginBottom:"12px"},children:t.label}),e.jsx("h3",{style:{fontSize:C.lg,fontWeight:600,color:"#374151",marginBottom:"8px"},children:f.name}),e.jsx("p",{style:{fontSize:C.md,color:"#9CA3AF",lineHeight:1.6},children:"Geometry View rendering is deferred (ADR-1-19): the ontology carries no spatial data to draw. This view is recognized and validated, but has no renderer yet."})]})})}return!f&&$.length===0&&!te?e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[!ve&&e.jsx(Tt,{collapsed:ve,onToggleCollapse:()=>gt(!0)}),ve&&e.jsx(Tt,{collapsed:!0,onToggleCollapse:()=>gt(!1)}),e.jsx("div",{className:"flex-1 flex items-center justify-center",style:{background:"#F7F7F5"},children:e.jsxs("div",{className:"text-center",style:{maxWidth:"320px"},children:[e.jsx("div",{style:{fontSize:"40px",marginBottom:"16px",opacity:.4},children:"📊"}),e.jsx("h3",{style:{fontSize:C.lg,fontWeight:600,color:"#374151",marginBottom:"8px"},children:"Select a Diagram"}),e.jsx("p",{style:{fontSize:C.md,color:"#9CA3AF",lineHeight:1.6},children:"Choose a diagram from the sidebar or drag elements from the palette."})]})})]}):e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx(Tt,{collapsed:ve,onToggleCollapse:()=>gt(!ve),elementIds:f==null?void 0:f.elementIds,eligibleKinds:f!=null&&f.viewpointId&&(o!=null&&o.viewpoints)?new Set(((wo=o.viewpoints.find(t=>t.id===f.viewpointId))==null?void 0:wo.visibleKinds)??[]):void 0}),e.jsxs("div",{className:"flex-1 relative",onDragOver:gn,onDrop:mn,onDoubleClick:yn,children:[f&&e.jsxs("div",{className:"absolute top-3 left-3 z-10 flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs relative",style:{background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:[De&&e.jsx("span",{className:"px-1.5 py-0.5 rounded font-semibold",style:{background:De.color+"20",color:De.color,fontSize:C.badge},title:`${De.fullName}${Ie?` · ${Ie.fullName}`:""}`,children:L==="actionflow"?dn:De.label}),e.jsx("span",{className:"font-medium",style:{color:"#1a1a1a"},children:f.name}),f.auto&&e.jsx("span",{style:{color:"#9CA3AF",fontSize:"9px"},children:"auto"}),e.jsx($e,{}),e.jsx(Pe,{icon:e.jsx(ae.grid,{}),label:"Grid",active:Ht,onClick:()=>{tn(t=>{const n=!t;return _t(n),n})},title:"Show or hide the canvas grid and snapping (⌘⇧G)"}),pe&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("button",{onClick:Et,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Expand All"}),e.jsx("button",{onClick:kt,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Collapse All"})]}),L==="actionflow"&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{icon:e.jsx(ae.lanes,{}),active:Ae,onClick:()=>Qt(t=>!t),title:"Toggle allocation swimlanes"}),Ae&&cn&&e.jsx(Pe,{icon:e.jsx(ae.lanes,{}),label:"Stage",active:Ke==="stage",onClick:()=>Kt(t=>t==="stage"?"allocation":"stage"),title:"Group this flow by its modeled stages"}),Ae&&Ke==="allocation"&&Jt.length>0&&e.jsxs("select",{"aria-label":"Display hierarchy level",title:"Display responsibility lanes at a hierarchy level; the SysML allocation is unchanged",value:yt,onChange:t=>Vt(t.target.value==="all"?"all":Number(t.target.value)),className:"text-xs font-semibold rounded-lg px-2 py-1",style:{color:"#5B6470",background:"#FFFFFF",border:"1px solid #E2E1DB"},children:[e.jsx("option",{value:"all",children:"All levels"}),Jt.map(t=>e.jsxs("option",{value:t,children:["L",t]},t))]}),e.jsx($e,{}),e.jsx(_o,{value:mt,onChange:on,options:[{value:"horizontal",icon:e.jsx(ae.arrowRight,{}),title:"Left-to-right flow"},{value:"vertical",icon:e.jsx(ae.arrowDown,{}),title:"Top-to-bottom flow"}]}),e.jsx($e,{}),e.jsxs(ai,{children:[e.jsx(Ho,{icon:e.jsx(ae.expand,{}),title:"Expand all sub-actions",onClick:()=>ze(new Set(Object.values((o==null?void 0:o.elements)??{}).map(t=>t.parentAction).filter(t=>!!t)))}),e.jsx(Ho,{icon:e.jsx(ae.collapse,{}),title:"Collapse all sub-actions",onClick:()=>ze(new Set)})]}),e.jsx($e,{}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Pe,{icon:e.jsx(ae.filter,{}),active:Yt,badge:`${de.size}/4`,onClick:()=>nn(t=>!t),title:"Choose which modeled connection categories are visible"}),Yt&&e.jsxs("div",{className:"absolute top-full right-0 mt-2 p-3 rounded-lg",style:{width:264,background:"#FFFFFF",border:"1px solid #D1D5DB",boxShadow:"0 8px 24px rgba(0,0,0,0.14)",zIndex:30},children:[e.jsx("div",{style:{color:"#1F2937",fontWeight:700,fontSize:C.xs},children:"Show connection categories"}),e.jsx("div",{style:{color:"#6B7280",fontSize:C.xs,lineHeight:1.4,marginTop:3,marginBottom:8},children:"Changes this diagram view only; the SysML model is not modified."}),["control","data","energy","material"].map(t=>{const n=de.has(t),a=t==="control"?"#4B5563":t==="data"?"#3498DB":t==="energy"?"#D97706":"#16A34A";return e.jsxs("button",{role:"switch","aria-checked":n,onClick:()=>sn(p=>{const c=new Set(p);return c.has(t)?c.delete(t):c.add(t),c}),className:"w-full flex items-center justify-between px-1 py-1.5 rounded",style:{color:"#374151",textTransform:"capitalize"},title:`${n?"Hide":"Show"} ${t} connections`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{style:{width:9,height:9,borderRadius:"50%",background:a}}),t]}),e.jsx("span",{"aria-hidden":"true",style:{width:32,height:18,borderRadius:9,background:n?"#2563EB":"#D1D5DB",padding:2,transition:"background 160ms ease"},children:e.jsx("span",{style:{display:"block",width:14,height:14,borderRadius:"50%",background:"#FFFFFF",boxShadow:"0 1px 2px rgba(0,0,0,0.22)",transform:n?"translateX(14px)":"translateX(0)",transition:"transform 160ms ease"}})})]},t)})]})]}),Me&&e.jsxs(e.Fragment,{children:[e.jsx($e,{}),e.jsx(Pe,{icon:e.jsx(ae.back,{}),label:"Parent",onClick:()=>jt(null),title:"Return to the parent action flow"}),e.jsx("span",{style:{color:"#6B7280",fontSize:C.xs},children:((jo=o==null?void 0:o.elements[Me])==null?void 0:jo.name)??Me})]})]}),L==="interconnection"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("button",{onClick:()=>Le(new Set),className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Expand All"}),e.jsx("button",{onClick:()=>Le(new Set((o==null?void 0:o.relationships.filter(t=>["composes","composedof","aggregation","decomposedby"].includes(t.type.toLowerCase())).map(t=>t.sourceId))??[])),className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Collapse All"}),e.jsx("span",{style:{color:"#9CA3AF",fontSize:C.xs,fontWeight:600},children:"Ports"}),e.jsx(_o,{value:Be,onChange:to,options:[{value:"all",label:"Nested",title:"Show ports and their nested ports"},{value:"ports",label:"Top",title:"Show top-level ports only (nested connectors lift to the parent port)"},{value:"none",label:"Off",title:"Hide ports; connectors run part to part"}]}),vt.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("button",{onClick:()=>Qe(null),className:"px-1.5 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#2563EB",border:"1px solid #E5E5E0"},title:"Back to the whole diagram",children:"⌂ All"}),vt.map((t,n)=>{var p,c;const a=n===vt.length-1;return e.jsxs("span",{className:"flex items-center gap-1",style:{color:"#9CA3AF"},children:[e.jsx("span",{children:"›"}),e.jsx("button",{onClick:()=>Qe(t),disabled:a,className:"text-xs font-medium",style:{color:a?"#1a1a1a":"#2563EB",fontWeight:a?700:500,cursor:a?"default":"pointer"},title:a?void 0:`Focus ${((p=o==null?void 0:o.elements[t])==null?void 0:p.name)??t}`,children:((c=o==null?void 0:o.elements[t])==null?void 0:c.name)??t})]},t)})]})]}),ye&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("div",{className:"flex rounded overflow-hidden",style:{border:"1px solid #E5E5E0"},children:ln.map(t=>e.jsx("button",{onClick:()=>{Ut(t),ne.current.clear()},className:"px-2 py-0.5 text-xs font-medium capitalize",style:{background:he===t?"#1B3A4B":"#FFFFFF",color:he===t?"#FFFFFF":"#6B7280"},title:t==="graph"?"Relationship graph with compartments":t==="tree"?"Decomposition tree with expand/collapse":"Nested containment blocks",children:t},t))}),he!=="graph"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:Et,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Expand All"}),e.jsx("button",{onClick:kt,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Collapse All"}),he==="tree"&&e.jsx("button",{onClick:St,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},title:"Re-layout the tree from scratch",children:"↻ Reset"})]})]}),qe&&!pe&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("div",{className:"flex rounded overflow-hidden",style:{border:"1px solid #E5E5E0"},children:["containment","decomposition"].map(t=>e.jsx("button",{onClick:()=>{pn(t),ne.current.clear()},className:"px-2 py-0.5 text-xs font-medium",style:{background:Re===t?"#1B3A4B":"#FFFFFF",color:Re===t?"#FFFFFF":"#6B7280"},children:t==="containment"?"Containment":"Decomposition"},t))}),e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("button",{onClick:Et,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Expand All"}),e.jsx("button",{onClick:kt,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Collapse All"}),Re==="decomposition"&&e.jsx("button",{onClick:St,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},title:"Re-layout the tree from scratch",children:"↻ Reset"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),an&&Ft.length>0&&e.jsx("select",{"aria-label":"Layout provider",value:ue,disabled:te,onChange:t=>{const n=Ft.find(c=>c.id===t.target.value);if(!n)return;const a=M.getState().diagramLayouts[s],p=ps({...a??{nodes:{},edges:{}},nodes:{},edges:{},canvas:{...a==null?void 0:a.canvas,autoLayout:!0}},n);E({[s]:p}),We(s,p),ne.current.clear(),ft(c=>c+1)},title:"Choose an installed layout provider for this diagram",className:"px-1.5 py-0.5 text-xs font-medium rounded",style:{color:"#374151",background:"#FFFFFF",border:"1px solid #D1D5DB"},children:Ft.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))}),e.jsxs("button",{"aria-pressed":re,onClick:()=>{if(re)oe();else{const t=M.getState().diagramLayouts[s],n={nodes:{},edges:{},canvas:{...t==null?void 0:t.canvas,autoLayout:!0}};E({[s]:n}),We(s,n),ft(a=>a+1)}},className:"px-2 py-0.5 text-xs font-semibold rounded",style:{background:re?"#ECFDF5":"#FFF7ED",color:re?"#047857":"#C2410C",border:`1px solid ${re?"#A7F3D0":"#FED7AA"}`},title:re?"Auto layout is on. Drag any item to switch it off and preserve your changes automatically.":"Auto layout is off. Your changes are saved automatically; click to discard overrides and recalculate.",children:["Auto layout: ",re?"On":"Off"]})]}),s&&L==="interconnection"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsxs("button",{"aria-pressed":xe,onClick:()=>{const t=M.getState().diagramLayouts[s]??{nodes:{},edges:{}},n={...t,canvas:{...t.canvas,flowAnimation:!xe}};E({[s]:n}),We(s,n),T(a=>a.map(p=>({...p,data:{...p.data,flowAnimation:!xe}})))},className:"px-2 py-0.5 text-xs font-semibold rounded",style:{background:xe?"#EFF6FF":"#F8FAFC",color:xe?"#1D4ED8":"#64748B",border:`1px solid ${xe?"#93C5FD":"#CBD5E1"}`},title:"Toggle animated source-to-target flow on IBD connectors",children:["Flow: ",xe?"On":"Off"]}),e.jsx("button",{"aria-pressed":oo,onClick:()=>no(t=>!t),className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F8FAFC",color:"#475569",border:"1px solid #CBD5E1"},title:"Show or hide the IBD notation legend",children:"Legend"})]})]}),Se&&e.jsxs("div",{className:"absolute top-3 right-3 z-10 flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs",style:{background:"#1B3A4B",color:"#FFFFFF",boxShadow:"0 2px 8px rgba(0,0,0,0.18)"},children:[e.jsx("span",{style:{color:"#2DD4A8",fontWeight:700},children:"◎ Focus"}),e.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Depth"}),[1,2,3].map(t=>e.jsx("button",{onClick:()=>rn(t),style:{width:20,height:20,borderRadius:4,cursor:"pointer",background:Ge===t?"#2DD4A8":"rgba(255,255,255,0.15)",color:Ge===t?"#1B3A4B":"#FFFFFF",fontWeight:700,fontSize:"11px",border:"none"},children:t},t)),e.jsx("button",{onClick:()=>{Gt(null),z(t=>t.map(n=>({...n,style:{...n.style,opacity:1,pointerEvents:"all"}}))),T(t=>t.map(n=>({...n,style:{...n.style,opacity:1}})))},style:{marginLeft:4,padding:"2px 8px",borderRadius:4,cursor:"pointer",background:"rgba(255,255,255,0.15)",color:"#FFFFFF",fontSize:"11px",border:"none"},children:"Exit Focus"})]}),Xe&&e.jsxs("div",{className:"absolute bottom-12 left-1/2 -translate-x-1/2 z-50 px-4 py-2 rounded-lg text-xs font-mono",style:{background:"#1B3A4B",color:"#2DD4A8",boxShadow:"0 4px 16px rgba(0,0,0,0.2)",whiteSpace:"nowrap"},children:["Copied: ",Xe]}),te&&e.jsx("div",{className:"absolute top-3 left-1/2 -translate-x-1/2 z-10 px-4 py-1.5 rounded-full text-xs font-medium",style:{background:"#FFFFFF",color:"#6B7280",border:"1px solid #E5E5E0",boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:"Computing layout…"}),$t&&!te&&e.jsxs("div",{role:"alert",className:"absolute top-3 left-1/2 -translate-x-1/2 z-20 flex items-center gap-3 px-3 py-2",style:{maxWidth:620,background:"#FFFDF7",color:"#5F4300",border:"1px solid #E7C35A",borderRadius:4,boxShadow:"0 2px 8px rgba(31,41,55,0.10)",fontSize:C.xs},children:[e.jsx("span",{children:$t}),e.jsx("button",{onClick:St,style:{border:"1px solid #B58A12",borderRadius:3,background:"#FFFFFF",color:"#5F4300",padding:"3px 8px",fontWeight:700,whiteSpace:"nowrap"},children:"Retry"})]}),Ue.length>0&&!te&&e.jsxs("div",{role:"alert",className:"absolute top-16 left-1/2 -translate-x-1/2 z-20 px-3 py-2",style:{maxWidth:720,background:"#FEF2F2",color:"#991B1B",border:"1px solid #FCA5A5",borderRadius:4,boxShadow:"0 2px 8px rgba(31,41,55,0.10)",fontSize:C.xs},children:[e.jsx("span",{style:{fontWeight:700},children:"Diagram error:"})," ",Ue.length," floating ",Ue.length===1?"action has":"actions have"," no flow or succession connection:"," ",Ue.map((t,n)=>e.jsxs("span",{children:[n>0&&", ",e.jsx("button",{onClick:()=>h(t.id),style:{color:"#991B1B",textDecoration:"underline",fontWeight:700},children:t.name})]},t.id))]}),et&&!te&&e.jsxs("div",{role:"alert",className:"absolute top-16 left-1/2 -translate-x-1/2 z-20 px-3 py-2",style:{maxWidth:720,background:"#FEF2F2",color:"#991B1B",border:"1px solid #FCA5A5",borderRadius:4,boxShadow:"0 2px 8px rgba(31,41,55,0.10)",fontSize:C.xs},children:[e.jsx("span",{style:{fontWeight:700},children:"BDD error:"})," ","expected one connected hierarchy, but found ",et.rootIds.length," roots",et.disconnectedIds.length>0&&e.jsxs(e.Fragment,{children:[" and ",et.disconnectedIds.length," disconnected/floating elements"]}),"."]}),L==="actionflow"&&e.jsxs("div",{"aria-label":"Action flow legend",className:"absolute right-3 bottom-3 z-10 flex items-center gap-4 px-3 py-2",style:{background:"rgba(255,255,255,0.96)",border:"1px solid #D1D5DB",borderRadius:3,color:"#374151",fontSize:C.xs},children:[e.jsx("span",{style:{fontWeight:700},children:"Legend"}),de.has("control")&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:24,height:0,borderTop:"2px solid #4B5563"}}),"Control flow"]}),de.has("data")&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:24,height:0,borderTop:"2.5px solid #3498DB"}}),"Object flow"]}),de.has("energy")&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:24,height:0,borderTop:"2.5px solid #D97706"}}),"Energy flow"]}),de.has("material")&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:24,height:0,borderTop:"2.5px solid #16A34A"}}),"Material flow"]})]}),L==="interconnection"&&$.length>0&&oo&&e.jsxs("div",{"aria-label":"Interconnection legend",className:"absolute right-3 bottom-3 z-10 flex flex-col gap-1.5 px-3 py-2",style:{background:"rgba(255,255,255,0.96)",border:"1px solid #D1D5DB",borderRadius:4,color:"#374151",fontSize:C.xs},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{style:{fontWeight:700},children:"Ports"}),Be!=="none"?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lt,{color:at.in,glyph:"→"})," in"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lt,{color:at.out,glyph:"→"})," out"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lt,{color:at.inout,glyph:"⇄"})," inout"]}),Be==="all"&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{style:{width:9,height:9,borderRadius:2,flexShrink:0,background:"#6B728022",border:"1.5px solid #6B7280"}}),"nested"]})]}):e.jsx("span",{style:{color:"#9CA3AF"},children:"hidden"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{style:{fontWeight:700},children:"Flow"}),["data","energy","material"].map(t=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:20,height:0,borderTop:`2.5px solid ${us[t]}`}}),t]},t))]})]}),!te&&$.length===0&&f&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",style:{zIndex:1},children:f.auto&&((vo=f.elementIds)==null?void 0:vo.length)===0?e.jsxs("div",{className:"text-center",style:{maxWidth:420},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:8},children:"🔍"}),e.jsx("div",{style:{fontSize:C.sm,color:"#374151",fontWeight:600,marginBottom:4},children:"This view selects no elements"}),e.jsx("div",{style:{fontSize:C.xs,color:"#6B7280",lineHeight:1.6},children:"The view is auto-populated from its selectionQuery in the model. Add includeElementKinds / includeLayers to its SysML definition, or link elements to it with IncludedIn relationships."})]}):e.jsxs("div",{className:"text-center",style:{opacity:.4},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:8},children:"🖱️"}),e.jsx("div",{style:{fontSize:C.sm,color:"#6B7280"},children:"Drag from palette or double-click to create elements"})]})}),te&&e.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,height:"2px",zIndex:20,background:`linear-gradient(90deg, ${To.accent} 0%, ${To.accent}80 50%, transparent 100%)`,backgroundSize:"200% 100%",animation:"memo-layout-progress 1.2s linear infinite"}}),e.jsxs(Kn,{nodes:$,edges:X,nodeTypes:xn,edgeTypes:hn,onNodesChange:Sn,onEdgesChange:le,onNodeClick:Nn,onNodeDoubleClick:Dn,onEdgeClick:Rn,onPaneClick:An,onNodeDragStart:En,onNodeDragStop:kn,onNodeContextMenu:Cn,onEdgeContextMenu:In,onConnect:jn,onConnectStart:Fn,onConnectEnd:wn,connectionMode:Vn.Loose,defaultEdgeOptions:{interactionWidth:24},snapToGrid:en,snapGrid:ui,fitView:!0,fitViewOptions:{...di,minZoom:Ne},minZoom:.1,maxZoom:3,zoomOnScroll:!0,panOnScroll:!0,panOnScrollMode:"free",selectionOnDrag:!1,proOptions:pi,style:li,children:[Ht&&e.jsx(Yn,{color:"#C5C7C2",gap:20,size:1.5}),e.jsx(Gn,{}),$.length>20&&e.jsx(Xn,{style:ci,nodeColor:fn,maskColor:"rgba(247, 247, 245, 0.7)"})]})]}),J&&e.jsx(fi,{x:J.x,y:J.y,onConfirm:bn,onCancel:()=>Ee(null)}),ce&&e.jsx(Zs,{x:ce.x,y:ce.y,sourceKind:ce.sourceKind,targetKind:ce.targetKind,onSelect:vn,onCancel:()=>Ve(null)}),q&&e.jsx(Js,{x:q.x,y:q.y,nodeId:q.nodeId,nodeKind:q.nodeKind,onClose:()=>ke(null),onEditName:()=>{z(t=>t.map(n=>n.id===q.nodeId?{...n,data:{...n.data,_triggerEdit:!0}}:n))},onChangeColor:t=>Tn(q.nodeId,t),onRemoveFromDiagram:()=>xo(q.nodeId),onDeleteFromModel:()=>{xo(q.nodeId)},onShowProperties:()=>{u(q.nodeId)},onShowInCatalog:()=>{u(q.nodeId),S("catalog")},onFocusElement:()=>{Gt(q.nodeId)},onShowRelMatrix:()=>{b({type:"traceability"})},onOpenSource:()=>{const t=o==null?void 0:o.elements[q.nodeId];t!=null&&t.file&&(navigator.clipboard.writeText(t.file).catch(()=>{}),Xt(t.file))},onViewKindInOntology:()=>{const t=q.nodeKind;let n=null,a=null;for(const p of x){for(const c of p.layers)if(c.kinds.some(k=>k.name===t)){n=p.name,a=c.id;break}if(n)break}n&&(y(t),j("ontologies"),S("ontology"),b({type:"ontology-detail",packageName:n,layerId:a??void 0}))}}),ie&&e.jsx(ti,{x:ie.x,y:ie.y,edgeId:ie.edgeId,relType:ie.relType,onClose:()=>Ye(null),onChangeStyle:t=>Ln(ie.edgeId,t),onChangeColor:t=>Bn(ie.edgeId,t),onToggleLabel:()=>zn(ie.edgeId),onDelete:()=>T(t=>t.filter(n=>n.id!==ie.edgeId))})]})}function Si(){return e.jsx(Wn,{children:e.jsx(gi,{})})}export{Si as DiagramCanvas};
1
+ import{j as e,H as A,P as N,N as ct,u as zt,a as Mn,B as On,E as Io,R as Wn,b as $n,c as Pn,d as _n,e as Hn,i as Kn,C as Vn,f as Yn,g as Gn,M as Xn}from"./reactflow-WKyu73tD.js";import{a as l,W as No}from"./zustand-qbFpP9Up.js";/* empty css */import{F as C,S as ee,m as qn,u as M,d as Xo,R as je,g as Un,D as Do,n as We,r as Zn,f as Ao,o as Qn,h as Jn,V as Ro,C as To}from"./index-CgRwea72.js";import{I as Mt,a as es,P as at,s as ts,G as Nt,c as os,f as ns,C as ss,r as is,v as rs,b as Lo,d as as,e as ls,g as ds,B as cs,w as ps,h as us,i as xs,j as hs,k as fs,l as gs,m as ms,n as ys,o as bs,p as Fs,q as ws,t as js}from"./layout-selection-BQ2WuAEB.js";import{l as vs}from"./layout-providers-BAUgp0nu.js";import"./elk-B75IRfCd.js";import"web-worker";function Es(o,d,r="both",s=10){const i=o.elements[d];if(!i)return{rootId:d,rootName:"(unknown)",rootKind:"",nodes:[],edges:[]};const u=new Map,h=new Map;for(const x of o.relationships)u.has(x.sourceId)||u.set(x.sourceId,[]),u.get(x.sourceId).push(x),h.has(x.targetId)||h.set(x.targetId,[]),h.get(x.targetId).push(x);const F=new Set;F.add(d);const S=[],b=[],j=[[d,0]];for(;j.length>0;){const[x,y]=j.shift();if(y>=s)continue;const w=y+1;if(r==="downstream"||r==="both")for(const g of u.get(x)||[]){const E=g.targetId;if(b.push({fromId:x,toId:E,relType:g.type,relId:g.id}),!F.has(E)){F.add(E);const m=o.elements[E];m&&(S.push({elementId:E,name:m.name,kind:m.kind,layer:m.layer,depth:w,viaRelType:g.type,direction:"downstream"}),j.push([E,w]))}}if(r==="upstream"||r==="both")for(const g of h.get(x)||[]){const E=g.sourceId;if(b.push({fromId:E,toId:x,relType:g.type,relId:g.id}),!F.has(E)){F.add(E);const m=o.elements[E];m&&(S.push({elementId:E,name:m.name,kind:m.kind,layer:m.layer,depth:w,viaRelType:g.type,direction:"upstream"}),j.push([E,w]))}}}return S.sort((x,y)=>x.depth-y.depth||x.name.localeCompare(y.name)),{rootId:d,rootName:i.name,rootKind:i.kind,nodes:S,edges:b}}function ks({data:o}){const d=o,{element:r,layerColor:s,isExpanded:i,hasChildren:u,childCount:h,direction:F,onToggleExpand:S,onToggleDirection:b,showDirectionButton:j,depthBgColor:x,isContainer:y}=d,w=F==="vertical"?"V":"H",g=y&&i;return e.jsxs("div",{style:{background:g?x||"#FAFAF9":"#FFFFFF",borderLeft:g?`2px solid ${s}40`:`3px solid ${s}`,borderTop:`1px solid ${g?s+"30":"#E5E5E0"}`,borderRight:`1px solid ${g?s+"30":"#E5E5E0"}`,borderBottom:`1px solid ${g?s+"30":"#E5E5E0"}`,borderRadius:3,padding:g?"0":"8px 12px",minWidth:g?void 0:"200px",boxShadow:"none",width:"100%",height:"100%",boxSizing:"border-box"},children:[e.jsx(A,{type:"target",position:N.Top,id:"top",style:nt}),e.jsx(A,{type:"source",position:N.Bottom,id:"bottom",style:nt}),e.jsx(A,{type:"target",position:N.Left,id:"left",style:nt}),e.jsx(A,{type:"source",position:N.Right,id:"right",style:nt}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:g?"8px 12px":"0"},children:[u&&e.jsx("button",{onClick:E=>{E.stopPropagation(),S()},style:{width:"20px",height:"20px",borderRadius:2,border:`1px solid ${s}`,background:i?s+"12":"#FFFFFF",color:s,fontSize:C.md,fontWeight:700,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0,flexShrink:0,transition:"background 200ms ease, color 200ms ease"},title:i?"Collapse":"Expand",children:i?"−":"+"}),u&&j&&e.jsx("button",{onClick:E=>{E.stopPropagation(),b()},style:{width:"20px",height:"20px",borderRadius:"4px",border:"1.5px solid #10b981",background:"transparent",color:"#10b981",fontSize:"9px",fontWeight:700,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:0,flexShrink:0,transition:"background 200ms ease"},title:`Direction: ${F}. Click to toggle`,children:w}),e.jsx("span",{style:{fontSize:C.md,fontWeight:600,color:g?s:"#1a1a1a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.name})]}),!g&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginTop:"3px",paddingLeft:u?"26px":"14px"},children:[e.jsx("span",{style:{fontSize:C.badge,color:"#9CA3AF"},children:r.kind}),u&&e.jsxs("span",{style:{fontSize:"9px",color:"#6B7280",background:"#F0F0ED",padding:"1px 5px",borderRadius:2,fontWeight:600},children:[h," parts",i?"":" (collapsed)"]})]})]})}const nt={width:"8px",height:"8px",background:"#2DD4A8",border:"1.5px solid #FFFFFF",opacity:0},Ss=l.memo(ks),Bo={top:N.Top,bottom:N.Bottom,left:N.Left,right:N.Right},Cs={top:"bottom",bottom:"top",left:"right",right:"left"},Is="#6B7280",qo=o=>o?at[o]:Is;function Uo(o,d){if(o==="inout")return"⇄";if(!o)return"";const r=o==="in";switch(d){case"left":return r?"→":"←";case"right":return r?"←":"→";case"top":return r?"↓":"↑";default:return r?"↑":"↓"}}const Ns=104,Dt=40,zo=o=>({opacity:0,width:o,height:o,top:"50%",left:"50%",transform:"translate(-50%, -50%)",border:"none",background:"transparent",pointerEvents:"none"});function Ds({port:o,onMove:d}){const{getZoom:r}=zt(),s=Mn(j=>j.transform[2]),i=o.size??Mt,u=(Dt-i)/2,h=i+5,F=qo(o.direction),S=o.side==="left"||o.side==="right",b={position:"absolute",fontSize:o.nested?"9.5px":"10.5px",fontWeight:o.nested?600:650,color:o.nested?"#6B7280":"#374151",whiteSpace:"normal",pointerEvents:"none",overflow:"hidden",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,width:S?Ns:72,background:"rgba(255,255,255,0.94)",padding:"1px 3px",borderRadius:4,lineHeight:1.12,...o.side==="left"?{left:h,bottom:"50%",marginBottom:2}:o.side==="right"?{right:h,bottom:"50%",marginBottom:2,textAlign:"right"}:o.side==="top"?{top:h,left:"50%",transform:"translateX(-50%)"}:{bottom:h,left:"50%",transform:"translateX(-50%)"}};return e.jsx("div",{className:"nodrag nopan",onPointerDown:d?j=>{j.preventDefault(),j.stopPropagation();const x=j.clientY,y=o.y,w=E=>d(y+(E.clientY-x)/r()),g=()=>{window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",g)};window.addEventListener("pointermove",w),window.addEventListener("pointerup",g,{once:!0})}:void 0,style:{position:"absolute",left:o.x-u,top:o.y-u,width:Dt,height:Dt,display:"flex",alignItems:"center",justifyContent:"center",zIndex:o.nested?11:10,cursor:d?"grab":"default",touchAction:"none",transform:`scale(${1/Math.max(s,.1)})`,transformOrigin:"center"},title:`${o.name}${o.direction?` (${o.direction})`:""}`,children:e.jsxs("div",{style:{position:"relative",width:i,height:i,boxSizing:"border-box",background:"#FFFFFF",border:`2px solid ${F}`,borderRadius:5,boxShadow:"0 1px 3px rgba(15,23,42,0.18)",display:"flex",alignItems:"center",justifyContent:"center",color:F,fontSize:o.nested?"10px":"12px",fontWeight:800,lineHeight:1,pointerEvents:"none"},children:[Uo(o.direction,o.side),e.jsx("span",{style:b,children:o.name.replace(/([a-z0-9])([A-Z])/g,"$1​$2")}),[{suffix:"",pos:Bo[o.side]},{suffix:es,pos:Bo[Cs[o.side]]}].flatMap(j=>[e.jsx(A,{className:"ibd-port-anchor",type:"source",id:`${o.id}${j.suffix}`,position:j.pos,style:zo(i),isConnectable:!1},`s${j.suffix}`),e.jsx(A,{className:"ibd-port-anchor",type:"target",id:`${o.id}${j.suffix}`,position:j.pos,style:zo(i),isConnectable:!1},`t${j.suffix}`)])]})})}function Mo({side:o,direction:d}){const r=qo(d),s=Mt;return e.jsx("div",{"aria-label":`implicit ${d} port`,title:`Implicit ${d} port — relationship targets the part directly`,style:{position:"absolute",top:"50%",left:o==="left"?-s/2:void 0,right:o==="right"?-s/2:void 0,transform:"translateY(-50%)",width:s,height:s,boxSizing:"border-box",background:"#FFFFFF",border:`2px solid ${r}`,borderRadius:4,boxShadow:"0 1px 3px rgba(15,23,42,0.18)",display:"flex",alignItems:"center",justifyContent:"center",color:r,fontSize:11,fontWeight:800,lineHeight:1,zIndex:4,pointerEvents:"none"},children:Uo(d,o)})}const st={width:8,height:8,background:"#2DD4A8",border:"1.5px solid #FFFFFF",opacity:0};function Oo({name:o,kind:d,nameColor:r,typeColor:s,frame:i=!1}){return e.jsxs("span",{title:`${o} : ${d}`,style:{display:"flex",flexDirection:i?"row":"column",alignItems:i?"baseline":"flex-start",gap:i?6:1,minWidth:0,overflow:"hidden",flex:1},children:[e.jsx("span",{style:{display:i?"block":"-webkit-box",width:"100%",minWidth:0,fontSize:i?C.md:C.sm,lineHeight:1.2,fontWeight:700,color:r,whiteSpace:i?"nowrap":"normal",overflow:"hidden",textOverflow:"ellipsis",WebkitBoxOrient:"vertical",WebkitLineClamp:i?void 0:2,overflowWrap:"anywhere"},children:o}),e.jsx("span",{style:{display:"block",maxWidth:"100%",fontSize:"9px",lineHeight:1.15,fontWeight:650,letterSpacing:"0.055em",textTransform:"uppercase",color:s,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:i?`: ${d}`:`«${d}»`})]})}function Wo({label:o,isCollapsed:d,onToggle:r,color:s,onColor:i}){return e.jsx("button",{"aria-label":d?`Expand ${o}`:`Collapse ${o}`,onClick:u=>{u.stopPropagation(),r()},style:{marginLeft:"auto",width:18,height:18,padding:0,borderRadius:3,border:i?"1px solid rgba(255,255,255,0.7)":`1px solid ${s}88`,background:i?"rgba(255,255,255,0.18)":"#FFFFFF",color:i?"#FFFFFF":s,fontSize:13,lineHeight:"15px",cursor:"pointer",fontWeight:700,flexShrink:0},children:d?"+":"−"})}function As({id:o,data:d,selected:r,height:s}){const i=d,{label:u,kind:h,color:F,isContainer:S,isFrame:b,ports:j,implicitIn:x,implicitOut:y,onPortMove:w,hasChildren:g,isCollapsed:E,onToggleCollapse:m}=i,[D,O]=l.useState(!1),v=r?ee.selected:b?"none":D?"0 8px 20px rgba(15,23,42,0.12)":S?"0 1px 2px rgba(15,23,42,0.05)":"0 2px 8px rgba(15,23,42,0.08)";return e.jsxs("div",{onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1),style:{width:"100%",height:"100%",boxSizing:"border-box",background:"#FFFFFF",border:b?"1.5px solid #94A3B8":`1px solid ${D?F+"9A":"#CBD5E1"}`,...b?{}:{borderTop:`3px solid ${F}`},borderRadius:b?10:8,boxShadow:v,transition:"box-shadow 150ms ease, border-color 150ms ease",position:"relative"},children:[!b&&e.jsx(ct,{nodeId:o,isVisible:r,minWidth:180,minHeight:100,color:"#2563EB",lineStyle:{borderWidth:1},handleStyle:{width:10,height:10,borderRadius:2}}),e.jsx(A,{type:"target",position:N.Top,id:"top",style:st}),e.jsx(A,{type:"source",position:N.Bottom,id:"bottom",style:st}),e.jsx(A,{type:"target",position:N.Left,id:"left",style:st}),e.jsx(A,{type:"source",position:N.Right,id:"right",style:st}),b?e.jsxs("div",{style:{position:"absolute",top:0,left:0,right:0,height:38,display:"flex",alignItems:"center",gap:8,padding:"0 10px",background:"#F8FAFC",borderBottom:"1px solid #E2E8F0",borderRadius:"9px 9px 0 0"},children:[e.jsx("span",{style:{padding:"2px 6px",borderRadius:4,background:F,color:"#FFFFFF",fontSize:9,fontWeight:800,letterSpacing:"0.08em"},children:"IBD"}),e.jsx(Oo,{name:u,kind:h,nameColor:"#0F172A",typeColor:"#64748B",frame:!0}),g&&m&&e.jsx(Wo,{label:u,isCollapsed:E,onToggle:m,color:F})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,minHeight:58,padding:"7px 10px 6px",background:"#FFFFFF",borderBottom:g?"1px solid #E2E8F0":"none",borderRadius:"7px 7px 0 0",overflow:"hidden"},children:[e.jsx(Oo,{name:u,kind:h,nameColor:"#0F172A",typeColor:S?F:"#64748B"}),g&&m&&e.jsx(Wo,{label:u,isCollapsed:E,onToggle:m,color:F})]}),j.map(I=>e.jsx(Ds,{port:I,onMove:w?$=>{const z=I.size??Mt,X=(b||S?70:62)-z/2,T=Math.max(X,(s??X+z+18)-z-18);w(I.id,Math.min(Math.max($,X),T))}:void 0},I.id)),x&&e.jsx(Mo,{side:"left",direction:"in"}),y&&e.jsx(Mo,{side:"right",direction:"out"})]})}const Rs=l.memo(As);function $o(o,d){const r=o.map(i=>({...i}));let s=d;for(;r.length>=2&&s>0;){const i=r[0],u=r[1],h=Math.hypot(u.x-i.x,u.y-i.y);if(h<=s)s-=h,r.shift();else{const F=s/h;r[0]={x:i.x+(u.x-i.x)*F,y:i.y+(u.y-i.y)*F},s=0}}return r}function Ts(o,d){const r=$o(o,d);return $o([...r].reverse(),d).reverse()}const Ls=o=>o.slice(1).reduce((d,r,s)=>d+Math.hypot(r.x-o[s].x,r.y-o[s].y),0);function At(o,d=7){if(o.length<2)return"";let r=`M ${o[0].x},${o[0].y}`;for(let i=1;i<o.length-1;i++){const u=o[i-1],h=o[i],F=o[i+1],S=Math.hypot(h.x-u.x,h.y-u.y),b=Math.hypot(F.x-h.x,F.y-h.y),j=Math.min(d,S/2,b/2),x=h.x-Math.sign(h.x-u.x)*j,y=h.y-Math.sign(h.y-u.y)*j,w=h.x+Math.sign(F.x-h.x)*j,g=h.y+Math.sign(F.y-h.y)*j;r+=` L ${x},${y} Q ${h.x},${h.y} ${w},${g}`}const s=o[o.length-1];return`${r} L ${s.x},${s.y}`}function Bs(o){const d=o.slice(1).map((i,u)=>Math.abs(i.x-o[u].x)+Math.abs(i.y-o[u].y)),r=d.reduce((i,u)=>i+u,0)/2;let s=0;for(let i=0;i<d.length;i++){if(s+d[i]>=r){const u=d[i]?(r-s)/d[i]:0;return{x:o[i].x+(o[i+1].x-o[i].x)*u,y:o[i].y+(o[i+1].y-o[i].y)*u}}s+=d[i]}return o[o.length-1]}function zs(o){var j,x,y,w,g,E;const{getZoom:d}=zt(),r=((j=o.data)==null?void 0:j.points)??[];if(r.length<2)return null;const s=Bs(r),i=Math.min(28/Math.max(d(),.1),Ls(r)*.3),u=Ts(r,i),h=(x=o.data)==null?void 0:x.onRouteChange,F=(y=o.data)==null?void 0:y.onSelect,S=!!((w=o.data)!=null&&w.flowAnimation),b=r.length===2?[{index:1,a:r[0],b:r[1],straight:!0}]:r.slice(1).map((m,D)=>({index:D+1,a:r[D],b:m,straight:!1})).filter(m=>m.index>=2&&m.index<=r.length-2);return e.jsxs(e.Fragment,{children:[e.jsx(On,{id:o.id,path:At(r),style:o.style,markerEnd:o.markerEnd}),S&&e.jsx("path",{d:At(r),fill:"none",stroke:String(((g=o.style)==null?void 0:g.stroke)??"#2563EB"),strokeWidth:Math.max(2,Number(((E=o.style)==null?void 0:E.strokeWidth)??2)),className:"memo-ibd-flow"}),u.length>=2&&e.jsx("path",{d:At(u),fill:"none",stroke:"transparent",strokeWidth:18/Math.max(d(),.1),pointerEvents:"stroke",cursor:"pointer",onClick:m=>F==null?void 0:F(m)}),o.label?e.jsx(Io,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${s.x}px, ${s.y}px)`,fontSize:C.badge,fontWeight:600,color:"#475569",background:"rgba(255,255,255,0.96)",border:"1px solid #E2E8F0",padding:"1px 4px",borderRadius:4,pointerEvents:"none"},children:o.label})}):null,o.selected&&h?b.map(m=>{const D=(m.a.x+m.b.x)/2,O=(m.a.y+m.b.y)/2;return e.jsx(Io,{children:e.jsx("div",{className:"nodrag nopan",title:"Drag connector segment",onPointerDown:v=>{v.preventDefault(),v.stopPropagation();const I=v.clientX,$=v.clientY,z=T=>{const le=(T.clientX-I)/d(),U=(T.clientY-$)/d();if(m.straight){if(Math.abs(U)>=Math.abs(le)){const G=m.a.y+U;h([m.a,{x:m.a.x,y:G},{x:m.b.x,y:G},m.b])}else{const G=(m.a.x+m.b.x)/2+le;h([m.a,{x:G,y:m.a.y},{x:G,y:m.b.y},m.b])}return}const Y=r.map(G=>({...G}));m.a.y===m.b.y?(Y[m.index-1].y=m.a.y+U,Y[m.index].y=m.b.y+U):(Y[m.index-1].x=m.a.x+le,Y[m.index].x=m.b.x+le),h(Y)},X=()=>{window.removeEventListener("pointermove",z),window.removeEventListener("pointerup",X)};window.addEventListener("pointermove",z),window.addEventListener("pointerup",X,{once:!0})},style:{position:"absolute",transform:`translate(-50%, -50%) translate(${D}px, ${O}px)`,width:12,height:12,borderRadius:3,background:"#FFFFFF",border:"2px solid #2563EB",boxShadow:"0 1px 4px rgba(15,23,42,0.22)",cursor:m.a.y===m.b.y?"ns-resize":"ew-resize",pointerEvents:"all",touchAction:"none",zIndex:20}})},`route-${m.index}`)}):null]})}const Ms=l.memo(zs);function Os({data:o,selected:d}){const r=o,{nodeType:s,label:i,laneColor:u,layerColor:h,inPorts:F,outPorts:S}=r,[b,j]=l.useState(!1);if(s==="start")return e.jsx("div",{style:{width:28,height:28,borderRadius:"50%",background:"#374151",border:"2px solid #374151",boxShadow:ee.sm},children:e.jsx(A,{type:"source",position:r.flowDirection==="vertical"?N.Bottom:N.Right,style:{background:"#374151",width:6,height:6}})});if(s==="done")return e.jsxs("div",{style:{width:28,height:28,borderRadius:"50%",background:"#FFFFFF",border:"3px solid #374151",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:ee.sm},children:[e.jsx("div",{style:{width:14,height:14,borderRadius:"50%",background:"#374151"}}),e.jsx(A,{type:"target",position:r.flowDirection==="vertical"?N.Top:N.Left,style:{background:"#374151",width:6,height:6}})]});if(s==="fork"||s==="join"){const g=r.flowDirection==="vertical";return e.jsxs("div",{title:s==="fork"?"Fork — split into concurrent flows":"Join — synchronize concurrent flows",style:{width:"100%",height:"100%",background:"#374151",borderRadius:3,boxShadow:ee.sm},children:[e.jsx(A,{type:"target",position:g?N.Top:N.Left,style:{background:"#374151",width:6,height:6,border:"none"}}),e.jsx(A,{type:"source",position:g?N.Bottom:N.Right,style:{background:"#374151",width:6,height:6,border:"none"}})]})}const x=u||h||"#9CA3AF",y=18,w=Math.max(F.length*y,S.length*y,0);return e.jsxs("div",{onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),style:{background:"#FFFFFF",border:`1.5px solid ${x}`,borderRadius:3,minWidth:"140px",boxShadow:d?"0 0 0 3px #2DD4A8, 0 4px 12px rgba(45, 212, 168, 0.35)":b?`0 0 0 2px ${x}22`:"none",transition:"box-shadow 150ms ease",overflow:"hidden"},children:[e.jsxs("div",{style:{padding:"8px 14px",fontSize:C.md,fontWeight:600,color:"#1a1a1a",background:`${x}0D`,borderBottom:w>0?"1px solid #E5E5E0":"none",textAlign:"center",whiteSpace:"nowrap"},children:[i,r.hasChildren&&r.onToggleExpand&&e.jsx("button",{"aria-label":r.isExpanded?`Collapse ${i}`:`Expand ${i}`,onClick:g=>{g.stopPropagation(),r.onToggleExpand()},style:{float:"right",marginLeft:8,width:18,height:18,padding:0,border:`1px solid ${x}`,borderRadius:2,background:"#FFFFFF",color:x,fontSize:13,fontWeight:700,lineHeight:"16px",cursor:"pointer"},children:r.isExpanded?"−":"+"})]}),w>0&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0"},children:[e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:F.map(g=>e.jsxs("div",{style:{fontSize:C.badge,color:"#6B7280",paddingLeft:"8px",display:"flex",alignItems:"center",height:`${y}px`,gap:"4px"},children:[e.jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"#3498DB",flexShrink:0}}),g]},`in-${g}`))}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px",alignItems:"flex-end"},children:S.map(g=>e.jsxs("div",{style:{fontSize:C.badge,color:"#6B7280",paddingRight:"8px",display:"flex",alignItems:"center",height:`${y}px`,gap:"4px"},children:[g,e.jsx("span",{style:{width:"6px",height:"6px",borderRadius:"50%",background:"#E67E22",flexShrink:0}})]},`out-${g}`))})]}),r.allocatedTo&&e.jsxs("div",{style:{fontSize:"9px",color:"#9CA3AF",textAlign:"center",padding:"2px 6px",borderTop:"1px solid #F3F4F6",background:"#FAFAFA"},children:["→"," ",r.allocatedTo]}),e.jsx(A,{type:"target",position:r.flowDirection==="vertical"?N.Top:N.Left,style:{background:x,width:8,height:8,border:"2px solid #FFFFFF"}}),e.jsx(A,{type:"source",position:r.flowDirection==="vertical"?N.Bottom:N.Right,style:{background:x,width:8,height:8,border:"2px solid #FFFFFF"}})]})}const Ws=l.memo(Os);function $s({data:o,selected:d}){const r=o,s=r.orientation==="column";return e.jsx("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:`${r.color}08`,border:d?"3px solid #2DD4A8":`1px solid ${r.color}30`,borderLeft:d?"3px solid #2DD4A8":s?`1px solid ${r.color}30`:`3px solid ${r.color}`,borderTop:d?"3px solid #2DD4A8":s?`3px solid ${r.color}`:`1px solid ${r.color}30`,borderRadius:qn.md,pointerEvents:"auto",cursor:r.inspectElementId?"pointer":"default",display:"flex"},children:e.jsx("div",{style:{writingMode:s?"horizontal-tb":"vertical-rl",transform:s?void 0:"rotate(180deg)",padding:s?"7px 10px":"10px 6px",fontSize:C.xs,fontWeight:700,color:r.color,letterSpacing:"0.04em",textTransform:"uppercase",alignSelf:s?"flex-start":"center",width:s?"100%":void 0,textAlign:s?"center":void 0,whiteSpace:"nowrap"},children:r.label})})}const Ps=l.memo($s),it={width:8,height:8,border:"none",background:"transparent",opacity:0};function Rt(){return e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"target",position:N.Top,id:"top",style:it}),e.jsx(A,{type:"source",position:N.Bottom,id:"bottom",style:it}),e.jsx(A,{type:"target",position:N.Left,id:"left",style:it}),e.jsx(A,{type:"source",position:N.Right,id:"right",style:it})]})}function _s({data:o,selected:d}){const r=o;return r.isNote?e.jsxs("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:"#FFFDF5",border:`1px solid ${r.color}66`,borderRadius:4,padding:"6px 10px",boxShadow:ee.sm,display:"flex",flexDirection:"column",justifyContent:"center"},title:r.kind,children:[e.jsx(Rt,{}),e.jsx("span",{style:{fontSize:C.xs,fontWeight:600,color:"#374151",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.label}),e.jsx("span",{style:{fontSize:"8px",fontWeight:700,color:r.color,textTransform:"uppercase",letterSpacing:"0.05em"},children:r.kind})]}):r.isContainer?e.jsxs("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:r.isMachine?"transparent":`${r.color}06`,border:r.isMachine?`1.5px dashed ${r.color}88`:`1.5px solid ${r.color}55`,borderRadius:14,boxShadow:d?ee.selected:"none",position:"relative"},children:[e.jsx(Rt,{}),e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,padding:"10px 14px 0"},children:[e.jsx("span",{style:{fontSize:C.md,fontWeight:700,color:r.color,whiteSpace:"nowrap"},children:r.label}),e.jsx("span",{style:{fontSize:"8px",fontWeight:700,color:`${r.color}AA`,textTransform:"uppercase",letterSpacing:"0.06em"},children:r.kind})]})]}):e.jsxs("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:"#FFFFFF",border:`1.5px solid ${r.color}`,borderRadius:12,boxShadow:d?ee.selected:ee.md,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,padding:"4px 12px"},children:[e.jsx(Rt,{}),e.jsx("span",{style:{fontSize:C.md,fontWeight:600,color:"#1a1a1a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:r.label}),r.subtitle&&e.jsx("span",{style:{fontSize:"8px",fontWeight:600,color:"#9CA3AF",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:r.subtitle})]})}const Hs=l.memo(_s),Bt="#3498DB";function Ks({data:o}){const d=o;return e.jsxs("div",{style:{width:"100%",height:"100%",position:"relative",pointerEvents:"none"},children:[e.jsx("div",{style:{position:"absolute",top:0,left:"50%",transform:"translateX(-50%)",minWidth:140,maxWidth:"90%",padding:"10px 16px",background:"#FFFFFF",border:`1.5px solid ${Bt}`,borderRadius:8,boxShadow:ee.md,textAlign:"center",fontSize:C.md,fontWeight:600,color:"#1a1a1a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.label}),e.jsx("div",{style:{position:"absolute",top:44,bottom:0,left:"50%",borderLeft:`1.5px dashed ${Bt}66`}})]})}const Vs=l.memo(Ks);function Ys({data:o}){const d=o;return e.jsx("div",{style:{width:"100%",height:"100%",boxSizing:"border-box",background:"#1B3A4B06",border:"1px solid #1B3A4B22",borderRadius:10,pointerEvents:"none"},children:e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,padding:"8px 14px"},children:[e.jsx("span",{style:{fontSize:C.sm,fontWeight:700,color:"#1B3A4B"},children:d.label}),d.scenario&&e.jsxs("span",{style:{fontSize:C.xs,color:"#6B7280"},children:["realizes ",d.scenario]})]})})}const Gs=l.memo(Ys),rt={width:6,height:6,border:"none",background:"transparent",opacity:0};function Xs({data:o,selected:d}){const r=o;return e.jsxs("div",{style:{width:14,height:14,borderRadius:"50%",background:"#FFFFFF",border:`3px solid ${Bt}`,boxShadow:d?ee.selected:ee.sm,position:"relative"},title:r.kind,children:[e.jsx(A,{type:"source",id:"right",position:N.Right,style:rt}),e.jsx(A,{type:"target",id:"right",position:N.Right,style:rt}),e.jsx(A,{type:"source",id:"left",position:N.Left,style:rt}),e.jsx(A,{type:"target",id:"left",position:N.Left,style:rt}),e.jsx("span",{style:{position:"absolute",top:-20,left:"50%",transform:"translateX(-50%)",fontSize:"9px",fontWeight:600,color:"#374151",whiteSpace:"nowrap",background:"#FFFFFFCC",padding:"1px 5px",borderRadius:4},children:r.label})]})}const qs=l.memo(Xs),Us=l.memo(function({id:d,data:r,selected:s}){var v;const i=r,[u,h]=l.useState(!1),[F,S]=l.useState(""),[b,j]=l.useState(!1),x=l.useRef(null),y=l.useCallback(()=>{S(i.label),h(!0),setTimeout(()=>{var I;(I=x.current)==null||I.select()},10)},[i.label]),w=l.useCallback(()=>{var $;h(!1);const I=F.trim();I&&I!==i.label&&(($=i.onInlineEdit)==null||$.call(i,d,I))},[F,i,d]),g=l.useCallback(I=>{I.key==="Enter"&&(I.preventDefault(),w()),I.key==="Escape"&&h(!1)},[w]),E=l.useCallback(I=>{var $;I.preventDefault(),($=i.onContextMenu)==null||$.call(i,I,d)},[i,d]),m=i.bgColor??"#FFFFFF",D=i.color,O={background:D,border:"2px solid #FFFFFF",width:10,height:10,opacity:b||s?1:0,transition:"opacity 0.15s"};return e.jsxs("div",{onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),onContextMenu:E,onDoubleClick:y,style:{minWidth:120,minHeight:40,background:m,borderLeft:`3px solid ${D}`,borderRadius:8,boxShadow:s?`0 0 0 2px ${D}, 0 4px 12px ${D}44`:b?"0 4px 16px rgba(0,0,0,0.14)":"0 1px 4px rgba(0,0,0,0.08)",cursor:u?"text":"grab",position:"relative",transition:"box-shadow 0.15s",opacity:i.isNew?.7:1},children:[s&&e.jsx(ct,{minWidth:80,minHeight:36,maxWidth:600,maxHeight:400,color:D,lineStyle:{borderColor:D},handleStyle:{background:D,border:"2px solid #fff",width:10,height:10,borderRadius:2}}),e.jsxs("div",{style:{padding:"8px 12px",userSelect:"none"},children:[e.jsx("div",{style:{fontSize:"9px",fontWeight:700,color:D,textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:i.kind}),u?e.jsx("input",{ref:x,value:F,onChange:I=>S(I.target.value),onBlur:w,onKeyDown:g,onClick:I=>I.stopPropagation(),autoFocus:!0,style:{fontSize:C.sm,fontWeight:500,color:"#1a1a1a",background:"transparent",border:"none",outline:"none",width:"100%",padding:0}}):e.jsx("div",{style:{fontSize:C.sm,fontWeight:500,color:"#1a1a1a",lineHeight:1.3,wordBreak:"break-word"},children:i.label||i.kind}),i.isNew&&e.jsx("div",{style:{fontSize:"9px",color:"#9CA3AF",marginTop:2},children:"saving…"})]}),!!((v=i.compartments)!=null&&v.length)&&e.jsx("div",{style:{borderTop:"1px solid #EDEDEA",padding:"5px 12px 7px",userSelect:"none"},children:i.compartments.map(I=>e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"baseline",fontSize:"10px",lineHeight:"15px",whiteSpace:"nowrap",overflow:"hidden"},children:[e.jsx("span",{style:{color:"#9CA3AF"},children:I.key}),e.jsx("span",{style:{color:"#4B5563",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis"},children:I.value})]},I.key))}),e.jsx(A,{type:"target",position:N.Top,style:{...O,top:-5}}),e.jsx(A,{type:"source",position:N.Bottom,style:{...O,bottom:-5},id:"bottom"}),e.jsx(A,{type:"source",position:N.Right,style:{...O,right:-5},id:"right"}),e.jsx(A,{type:"target",position:N.Left,style:{...O,left:-5}})]})});function Tt({collapsed:o,onToggleCollapse:d,elementIds:r=[]}){const s=M(y=>y.model),i=M(y=>y.selectedElementId),u=M(y=>y.inspectElement),[h,F]=l.useState(""),[S,b]=l.useState(new Set),j=l.useMemo(()=>{var E;if(!s)return[];const y=h.trim().toLowerCase(),w=new Map,g=new Set(r);for(const m of r){const D=(E=s.elements[m])==null?void 0:E.allocatedTo;D&&g.add(D)}for(const m of g){const D=s.elements[m];D&&(y&&!D.name.toLowerCase().includes(y)&&!D.kind.toLowerCase().includes(y)||(w.has(D.kind)||w.set(D.kind,[]),w.get(D.kind).push(D)))}return[...w.entries()].map(([m,D])=>({kind:m,elements:D.sort((O,v)=>O.name.localeCompare(v.name))})).sort((m,D)=>m.kind.localeCompare(D.kind))},[s,r,h]),x=y=>b(w=>{const g=new Set(w);return g.has(y)?g.delete(y):g.add(y),g});return o?e.jsxs("button",{className:"flex flex-col items-center py-2 gap-1 cursor-pointer",style:{width:36,border:0,borderRight:"1px solid #E5E5E0",background:"#FAFAF8",flexShrink:0},onClick:d,title:"Expand diagram elements","aria-label":"Expand diagram elements",children:[e.jsx("span",{style:{color:"#6B7280",fontSize:18},children:"›"}),e.jsx("span",{style:{fontSize:10,color:"#6B7280",writingMode:"vertical-rl"},children:"Diagram Elements"})]}):e.jsxs("div",{className:"flex flex-col overflow-hidden",style:{width:240,borderRight:"1px solid #E5E5E0",background:"#FAFAF8",flexShrink:0},children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",style:{borderBottom:"1px solid #E5E5E0",flexShrink:0},children:[e.jsx("span",{style:{fontSize:C.xs,fontWeight:600,color:"#374151"},children:"Diagram Elements"}),e.jsx("button",{onClick:d,title:"Collapse diagram elements","aria-label":"Collapse diagram elements",style:{background:"none",border:"none",cursor:"pointer",color:"#6B7280",fontSize:18,lineHeight:1},children:"‹"})]}),e.jsx("div",{className:"px-2 pt-2 pb-1",style:{flexShrink:0},children:e.jsx("input",{value:h,onChange:y=>F(y.target.value),placeholder:"Search elements…",className:"w-full px-2 py-1 rounded focus:outline-none",style:{fontSize:C.xs,background:"#F0F0ED",border:"1px solid #E5E5E0",color:"#374151"}})}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[j.map(y=>{var E;const w=S.has(y.kind),g=Xo[(E=y.elements[0])==null?void 0:E.layer]??"#6B7280";return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>x(y.kind),className:"w-full flex items-center gap-1.5 px-2 py-1",style:{background:"none",border:"none",cursor:"pointer",textAlign:"left"},children:[e.jsx("span",{style:{fontSize:10,color:g},children:w?"▶":"▼"}),e.jsx("span",{className:"truncate",style:{fontSize:10,color:g,fontWeight:700},children:y.kind}),e.jsx("span",{style:{fontSize:9,color:"#9CA3AF",marginLeft:"auto"},children:y.elements.length})]}),!w&&y.elements.map(m=>{const D=i===m.id;return e.jsxs("button",{onClick:()=>u(m.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left",style:{border:"none",cursor:"pointer",fontSize:C.xs,background:D?"#DDF7EF":"transparent",color:D?"#116149":"#374151",fontWeight:D?600:400},title:`Highlight ${m.name} in diagram`,children:[e.jsx("span",{style:{width:8,height:8,borderRadius:2,background:g,flexShrink:0}}),e.jsx("span",{className:"truncate flex-1",children:m.name})]},m.id)})]},y.kind)}),j.length===0&&e.jsx("div",{className:"p-3 text-center",style:{color:"#9CA3AF",fontSize:C.xs},children:h?"No matching elements":"No elements in this diagram"})]})]})}const Po=[{type:"mitigates",label:"Mitigates",desc:"Risk control → Hazard"},{type:"causes",label:"Causes",desc:"Hazard → Hazardous Situation"},{type:"leadsTo",label:"Leads To",desc:"Situation → Harm"},{type:"identifies",label:"Identifies",desc:"Analysis → Risk"},{type:"traceTo",label:"Traces To",desc:"Requirement → Requirement"},{type:"satisfy",label:"Satisfies",desc:"Function → Requirement"},{type:"verify",label:"Verifies",desc:"Test → Requirement"},{type:"allocateTo",label:"Allocates To",desc:"Function → Component"},{type:"composedOf",label:"Composed Of",desc:"Parent → Child"},{type:"decomposedBy",label:"Decomposed By",desc:"Function → Sub-function"},{type:"flow",label:"Flow",desc:"Data / material flow"},{type:"succession",label:"Succession",desc:"Action sequence"},{type:"aggregation",label:"Aggregation",desc:"Logical grouping"}];function Zs({x:o,y:d,sourceKind:r,targetKind:s,closureRules:i,onSelect:u,onCancel:h}){const F=l.useRef(null),[S,b]=l.useState(""),j=l.useRef(null);l.useEffect(()=>{var v;(v=j.current)==null||v.focus()},[]),l.useEffect(()=>{const v=I=>{F.current&&!F.current.contains(I.target)&&h()};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[h]),l.useEffect(()=>{const v=I=>{I.key==="Escape"&&h()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[h]);const x=i?i[r]??Object.keys(je):Object.keys(je),y=Po.filter(v=>x.includes(v.type)&&(!S||v.label.toLowerCase().includes(S.toLowerCase())||v.type.toLowerCase().includes(S.toLowerCase()))),w=new Set(Po.map(v=>v.type)),g=x.filter(v=>!w.has(v)&&(!S||v.toLowerCase().includes(S.toLowerCase()))),E=240,m=320,D=Math.min(o,window.innerWidth-E-8),O=Math.min(d,window.innerHeight-m-8);return e.jsxs("div",{ref:F,className:"fixed z-50 flex flex-col shadow-xl rounded-xl overflow-hidden",style:{left:D,top:O,width:E,maxHeight:m,background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 8px 32px rgba(0,0,0,0.16)"},children:[e.jsxs("div",{className:"px-3 py-2",style:{borderBottom:"1px solid #E5E5E0",flexShrink:0},children:[e.jsx("div",{style:{fontSize:C.xs,fontWeight:600,color:"#374151",marginBottom:4},children:"Relationship Type"}),e.jsxs("div",{style:{fontSize:"10px",color:"#9CA3AF",marginBottom:4},children:[r," → ",s]}),e.jsx("input",{ref:j,value:S,onChange:v=>b(v.target.value),placeholder:"Search…",className:"w-full px-2 py-1 rounded focus:outline-none",style:{fontSize:C.xs,background:"#F7F7F5",border:"1px solid #E5E5E0",color:"#374151"}})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[y.map(v=>e.jsxs("button",{onClick:()=>u(v.type),className:"w-full flex items-center gap-2.5 px-3 py-1.5 text-left",style:{background:"none",border:"none",cursor:"pointer"},onMouseEnter:I=>{I.currentTarget.style.background="#F7F7F5"},onMouseLeave:I=>{I.currentTarget.style.background="none"},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",flexShrink:0,background:je[v.type]??"#6B7280"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:C.xs,fontWeight:500,color:"#1a1a1a"},children:v.label}),e.jsx("div",{style:{fontSize:"10px",color:"#9CA3AF"},children:v.desc})]})]},v.type)),g.map(v=>e.jsxs("button",{onClick:()=>u(v),className:"w-full flex items-center gap-2.5 px-3 py-1.5 text-left",style:{background:"none",border:"none",cursor:"pointer"},onMouseEnter:I=>{I.currentTarget.style.background="#F7F7F5"},onMouseLeave:I=>{I.currentTarget.style.background="none"},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",flexShrink:0,background:je[v]??"#6B7280"}}),e.jsx("span",{style:{fontSize:C.xs,color:"#1a1a1a"},children:v})]},v)),y.length===0&&g.length===0&&e.jsx("div",{className:"p-3 text-center",style:{color:"#9CA3AF",fontSize:C.xs},children:"No matching types"})]})]})}function Q({label:o,icon:d,danger:r,onClick:s}){return e.jsxs("button",{onClick:s,className:"w-full flex items-center gap-2 px-3 py-1.5 text-left",style:{background:"none",border:"none",cursor:"pointer",fontSize:C.xs},onMouseEnter:i=>{i.currentTarget.style.background=r?"#FEF2F2":"#F7F7F5"},onMouseLeave:i=>{i.currentTarget.style.background="none"},children:[d&&e.jsx("span",{style:{fontSize:"12px",width:16,textAlign:"center"},children:d}),e.jsx("span",{style:{color:r?"#DC2626":"#1a1a1a"},children:o})]})}function lt(){return e.jsx("div",{style:{height:1,background:"#E5E5E0",margin:"2px 0"}})}function Zo({x:o,y:d,onClose:r,children:s}){const i=l.useRef(null);l.useEffect(()=>{const S=j=>{i.current&&!i.current.contains(j.target)&&r()},b=j=>{j.key==="Escape"&&r()};return document.addEventListener("mousedown",S),document.addEventListener("keydown",b),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("keydown",b)}},[r]);const u=210,h=Math.min(o,window.innerWidth-u-8),F=Math.min(d,window.innerHeight-200);return e.jsx("div",{ref:i,className:"fixed z-50 rounded-xl overflow-hidden py-1",style:{left:h,top:F,minWidth:u,background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 8px 32px rgba(0,0,0,0.14)"},children:s})}const Qs=[{label:"Layer default",value:""},{label:"Mint",value:"#E8F5E9"},{label:"Sky",value:"#E3F2FD"},{label:"Amber",value:"#FFF8E1"},{label:"Rose",value:"#FFF0F0"},{label:"Lavender",value:"#F3E5F5"},{label:"Peach",value:"#FBE9E7"}];function Js({x:o,y:d,nodeId:r,nodeKind:s,onClose:i,onEditName:u,onChangeColor:h,onRemoveFromDiagram:F,onDeleteFromModel:S,onLinkRisk:b,onLinkRequirement:j,onShowProperties:x,onFocusElement:y,onShowInCatalog:w,onShowRelMatrix:g,onOpenSource:E,onViewKindInOntology:m}){const[D,O]=l.useState(!1);return e.jsxs(Zo,{x:o,y:d,onClose:i,children:[e.jsxs("div",{className:"px-3 py-1.5",style:{borderBottom:"1px solid #E5E5E0"},children:[e.jsx("div",{style:{fontSize:"10px",fontWeight:600,color:"#9CA3AF"},children:s}),e.jsx("div",{style:{fontSize:"9px",color:"#D1D5DB",fontFamily:"monospace"},children:r})]}),x&&e.jsx(Q,{label:"Show Properties",icon:"ℹ",onClick:()=>{i(),x()}}),w&&e.jsx(Q,{label:"Show in Catalog",icon:"☰",onClick:()=>{i(),w()}}),y&&e.jsx(Q,{label:"Focus on Element",icon:"◎",onClick:()=>{i(),y()}}),g&&e.jsx(Q,{label:"Show Relationship Matrix",icon:"☷",onClick:()=>{i(),g()}}),m&&e.jsx(Q,{label:"View Kind in Ontology",icon:"⬡",onClick:()=>{i(),m()}}),E&&e.jsx(Q,{label:"Open Source File",icon:"⟨/⟩",onClick:()=>{i(),E()}}),(x||w||y||g||m||E)&&e.jsx(lt,{}),e.jsx(Q,{label:"Edit name",icon:"✏️",onClick:()=>{i(),u()}}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-1.5",style:{background:"none",border:"none",cursor:"pointer",fontSize:C.xs},onMouseEnter:v=>{O(!0),v.currentTarget.style.background="#F7F7F5"},onMouseLeave:v=>{v.currentTarget.style.background="none"},children:[e.jsx("span",{style:{fontSize:"12px",width:16,textAlign:"center"},children:"🎨"}),e.jsx("span",{style:{flex:1,textAlign:"left",color:"#1a1a1a"},children:"Change color"}),e.jsx("span",{style:{color:"#9CA3AF",fontSize:"10px"},children:"▶"})]}),D&&e.jsx("div",{className:"absolute left-full top-0 rounded-xl overflow-hidden py-1",style:{background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 4px 16px rgba(0,0,0,0.12)",minWidth:160},onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1),children:Qs.map(v=>e.jsxs("button",{onClick:()=>{i(),h(v.value)},className:"w-full flex items-center gap-2.5 px-3 py-1.5",style:{background:"none",border:"none",cursor:"pointer"},onMouseEnter:I=>{I.currentTarget.style.background="#F7F7F5"},onMouseLeave:I=>{I.currentTarget.style.background="none"},children:[e.jsx("div",{style:{width:14,height:14,borderRadius:3,flexShrink:0,background:v.value||"#E5E5E0",border:"1px solid #D1D5DB"}}),e.jsx("span",{style:{fontSize:C.xs,color:"#374151"},children:v.label})]},v.value))})]}),e.jsx(lt,{}),b&&e.jsx(Q,{label:"Link Risk",icon:"⚠️",onClick:()=>{i(),b()}}),j&&e.jsx(Q,{label:"Link Requirement",icon:"📋",onClick:()=>{i(),j()}}),(b||j)&&e.jsx(lt,{}),e.jsx(Q,{label:"Remove from diagram",icon:"↩️",onClick:()=>{i(),F()}}),e.jsx(Q,{label:"Delete from model",icon:"🗑️",danger:!0,onClick:()=>{window.confirm(`Delete ${r} from the model? This cannot be undone.`)&&(i(),S())}})]})}const ei=[{label:"Auto",value:""},{label:"Red",value:"#EF4444"},{label:"Blue",value:"#3B82F6"},{label:"Green",value:"#10B981"},{label:"Orange",value:"#F59E0B"},{label:"Gray",value:"#6B7280"}];function ti({x:o,y:d,edgeId:r,relType:s,onClose:i,onChangeStyle:u,onChangeColor:h,onToggleLabel:F,onDelete:S}){return e.jsxs(Zo,{x:o,y:d,onClose:i,children:[e.jsxs("div",{className:"px-3 py-1.5",style:{borderBottom:"1px solid #E5E5E0"},children:[e.jsx("div",{style:{fontSize:"10px",fontWeight:600,color:"#9CA3AF"},children:s}),e.jsx("div",{style:{fontSize:"9px",color:"#D1D5DB",fontFamily:"monospace"},children:r})]}),e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2",children:[e.jsx("span",{style:{fontSize:"10px",color:"#9CA3AF",minWidth:40},children:"Style"}),["solid","dashed","dotted"].map(b=>e.jsx("button",{onClick:()=>{i(),u(b)},style:{fontSize:"10px",padding:"2px 8px",border:"1px solid #E5E5E0",borderRadius:4,cursor:"pointer",background:"#F7F7F5",color:"#374151"},children:b},b))]}),e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{style:{fontSize:"10px",color:"#9CA3AF",minWidth:40,flexShrink:0},children:"Color"}),ei.map(b=>e.jsx("button",{onClick:()=>{i(),h(b.value)},title:b.label,style:{width:16,height:16,borderRadius:"50%",background:b.value||"#E5E5E0",border:"1px solid #D1D5DB",cursor:"pointer"}},b.value))]}),e.jsx(lt,{}),e.jsx(Q,{label:"Toggle label",icon:"🏷️",onClick:()=>{i(),F()}}),e.jsx(Q,{label:"Delete edge",icon:"🗑️",danger:!0,onClick:()=>{i(),S()}})]})}const oi=l.memo(function({id:d,data:r,selected:s}){const i=r,u=i.color??i.layerColor??"#E67E22",h=80,F=l.useCallback(S=>{var b;S.preventDefault(),(b=i.onContextMenu)==null||b.call(i,S,d)},[i,d]);return e.jsxs("div",{style:{width:h,height:h,position:"relative"},onContextMenu:F,children:[s&&e.jsx(ct,{minWidth:60,minHeight:60}),e.jsx("svg",{width:h,height:h,style:{position:"absolute",top:0,left:0},children:e.jsx("polygon",{points:`${h/2},4 ${h-4},${h/2} ${h/2},${h-4} 4,${h/2}`,fill:i.color?i.color+"44":"#FFF8E1",stroke:u,strokeWidth:s?2.5:1.5})}),e.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:600,color:"#374151",textAlign:"center",padding:"4px 8px",pointerEvents:"none"},children:i.condition||i.label||"?"}),e.jsx(A,{type:"target",position:N.Top,style:{background:u,border:"2px solid #fff"}}),e.jsx(A,{type:"source",position:N.Right,style:{background:u,border:"2px solid #fff"},id:"right"}),e.jsx(A,{type:"source",position:N.Bottom,style:{background:u,border:"2px solid #fff"},id:"bottom"}),e.jsx(A,{type:"target",position:N.Left,style:{background:u,border:"2px solid #fff"}})]})}),ni=l.memo(function({id:d,data:r,selected:s}){const i=r,u=(i.orientation??"horizontal")==="horizontal",h=u?120:8,F=u?8:60,S=l.useCallback(b=>{var j;b.preventDefault(),(j=i.onContextMenu)==null||j.call(i,b,d)},[i,d]);return e.jsxs("div",{style:{width:h,height:F,background:"#1a1a1a",borderRadius:4,position:"relative"},title:i.nodeType==="join"?"Join (synchronization)":"Fork (parallel)",onContextMenu:S,children:[s&&e.jsx(ct,{minWidth:40,minHeight:6}),u?e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"target",position:N.Left,style:{background:"#2DD4A8",border:"2px solid #fff",left:-1}}),e.jsx(A,{type:"source",position:N.Top,style:{background:"#2DD4A8",border:"2px solid #fff",top:-1},id:"top"}),e.jsx(A,{type:"source",position:N.Bottom,style:{background:"#2DD4A8",border:"2px solid #fff",bottom:-1},id:"bottom"}),e.jsx(A,{type:"source",position:N.Right,style:{background:"#2DD4A8",border:"2px solid #fff",right:-1},id:"right"})]}):e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"target",position:N.Top,style:{background:"#2DD4A8",border:"2px solid #fff",top:-1}}),e.jsx(A,{type:"source",position:N.Left,style:{background:"#2DD4A8",border:"2px solid #fff",left:-1},id:"left"}),e.jsx(A,{type:"source",position:N.Right,style:{background:"#2DD4A8",border:"2px solid #fff",right:-1},id:"right"}),e.jsx(A,{type:"source",position:N.Bottom,style:{background:"#2DD4A8",border:"2px solid #fff",bottom:-1},id:"bottom"})]})]})}),si=l.memo(function({id:d,data:r}){const s=r,i=s.nodeType==="start",u=32,h=l.useCallback(F=>{var S;F.preventDefault(),(S=s.onContextMenu)==null||S.call(s,F,d)},[s,d]);return e.jsxs("div",{style:{width:u,height:u,position:"relative"},onContextMenu:h,children:[e.jsx("svg",{width:u,height:u,children:i?e.jsx("circle",{cx:u/2,cy:u/2,r:u/2-2,fill:"#1a1a1a"}):e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:u/2,cy:u/2,r:u/2-2,fill:"#1a1a1a"}),e.jsx("circle",{cx:u/2,cy:u/2,r:u/2-6,fill:"#FFFFFF"}),e.jsx("circle",{cx:u/2,cy:u/2,r:u/2-10,fill:"#1a1a1a"})]})}),i?e.jsx(A,{type:"source",position:N.Bottom,style:{background:"#1a1a1a",border:"2px solid #fff"}}):e.jsx(A,{type:"target",position:N.Top,style:{background:"#1a1a1a",border:"2px solid #fff"}})]})}),ii="#ECEBE6",dt="#1B3A4B",Ot="#5B6470",ri="0 1px 2px rgba(0,0,0,0.16), 0 0 0 0.5px rgba(0,0,0,0.05)",fe=(o,d)=>e.jsx("svg",{width:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.9,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"block"},children:d}),ae={arrowRight:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 12h14"}),e.jsx("path",{d:"M13 6l6 6-6 6"})]})),arrowDown:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M12 4v14"}),e.jsx("path",{d:"M6 13l6 6 6-6"})]})),lanes:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"3",y:"5",width:"18",height:"3.4",rx:"1.3"}),e.jsx("rect",{x:"3",y:"10.3",width:"18",height:"3.4",rx:"1.3"}),e.jsx("rect",{x:"3",y:"15.6",width:"18",height:"3.4",rx:"1.3"})]})),grid:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"3.5",y:"3.5",width:"17",height:"17",rx:"2.5"}),e.jsx("path",{d:"M9.2 3.5v17M14.8 3.5v17M3.5 9.2h17M3.5 14.8h17"})]})),expand:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M15 4h5v5"}),e.jsx("path",{d:"M9 20H4v-5"}),e.jsx("path",{d:"M20 4l-7 7"}),e.jsx("path",{d:"M4 20l7-7"})]})),collapse:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M14 10h5"}),e.jsx("path",{d:"M19 10V5"}),e.jsx("path",{d:"M10 14H5"}),e.jsx("path",{d:"M5 14v5"}),e.jsx("path",{d:"M20 4l-6 6"}),e.jsx("path",{d:"M4 20l6-6"})]})),filter:({size:o=16})=>fe(o,e.jsx("path",{d:"M4 5h16l-6.2 7.4V19l-3.6 1.8v-8.4z"})),back:({size:o=16})=>fe(o,e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M11 5l-6 7 6 7"}),e.jsx("path",{d:"M5 12h14"})]}))};function $e(){return e.jsx("span",{"aria-hidden":"true",style:{width:1,height:18,background:"#E2E1DB",margin:"0 3px",borderRadius:1}})}function _o({options:o,value:d,onChange:r}){return e.jsx("div",{role:"tablist",style:{display:"inline-flex",alignItems:"center",gap:2,padding:2,background:ii,borderRadius:9},children:o.map(s=>{const i=s.value===d;return e.jsxs("button",{role:"tab","aria-selected":i,onClick:()=>r(s.value),title:s.title,className:"flex items-center gap-1.5 text-xs font-semibold",style:{padding:s.label?"3px 9px":"4px 7px",borderRadius:7,border:"none",cursor:"pointer",color:i?dt:Ot,background:i?"#FFFFFF":"transparent",boxShadow:i?ri:"none",transition:"background 140ms ease, color 140ms ease, box-shadow 140ms ease"},children:[s.icon,s.label&&e.jsx("span",{children:s.label})]},s.value)})})}function ai({children:o}){return e.jsx("div",{style:{display:"inline-flex",alignItems:"center",background:"#FFFFFF",border:"1px solid #E2E1DB",borderRadius:9,overflow:"hidden"},children:No.Children.toArray(o).map((d,r)=>e.jsxs(No.Fragment,{children:[r>0&&e.jsx("span",{"aria-hidden":"true",style:{width:1,alignSelf:"stretch",background:"#EDECE7"}}),d]},r))})}function Ho({icon:o,label:d,onClick:r,active:s=!1,title:i,ariaExpanded:u}){return e.jsxs("button",{onClick:r,title:i,"aria-pressed":s,"aria-expanded":u,className:"flex items-center gap-1.5 text-xs font-semibold",style:{padding:d?"5px 9px":"5px 7px",border:"none",cursor:"pointer",color:s?"#FFFFFF":Ot,background:s?dt:"transparent",transition:"background 140ms ease, color 140ms ease"},children:[o,d&&e.jsx("span",{children:d})]})}function Pe({icon:o,label:d,onClick:r,active:s=!1,title:i,badge:u}){return e.jsxs("button",{onClick:r,title:i,"aria-pressed":s,className:"flex items-center gap-1.5 text-xs font-semibold",style:{padding:u!=null||d!=null?"5px 9px":"5px 7px",borderRadius:9,border:`1px solid ${s?dt:"#E2E1DB"}`,cursor:"pointer",color:s?"#FFFFFF":Ot,background:s?dt:"#FFFFFF",transition:"background 140ms ease, color 140ms ease, border-color 140ms ease"},children:[o,d!=null&&e.jsx("span",{children:d}),u!=null&&e.jsx("span",{style:{fontSize:11,fontWeight:700,lineHeight:1,padding:"2px 5px",borderRadius:6,background:s?"rgba(255,255,255,0.22)":"#F0EFEA",color:s?"#FFFFFF":"#6B7280"},children:u})]})}const Ko="memo-layout-progress";if(typeof document<"u"&&!document.getElementById(Ko)){const o=document.createElement("style");o.id=Ko,o.textContent="@keyframes memo-layout-progress { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }",document.head.appendChild(o)}const li={background:"#F7F7F5"},di={padding:.08,maxZoom:2},ci={background:"#FFFFFF"},pi={hideAttribution:!0},ui=[20,20],xi=50,Vo=8e3,hi=90;function Yo(o,d){return new Promise((r,s)=>{const i=window.setTimeout(()=>s(new Error(`${d} layout exceeded ${Vo/1e3}s`)),Vo);o.then(u=>{window.clearTimeout(i),r(u)},u=>{window.clearTimeout(i),s(u)})})}function Go(o,d){const r=new Map(o.map(x=>[x.id,x])),s=new Map,i=x=>{const y=s.get(x);if(y)return y;const w=r.get(x),g=w.parentId?i(w.parentId):{x:0,y:0},E={x:g.x+w.position.x,y:g.y+w.position.y};return s.set(x,E),E},u=x=>{var y,w;return{width:Number(x.width??((y=x.style)==null?void 0:y.width)??0),height:Number(x.height??((w=x.style)==null?void 0:w.height)??0)}},h=d.flatMap(x=>{var D,O,v,I,$,z;const y=(X,T,le)=>{var U,Y;if(typeof T=="string"){const G=(((Y=(U=r.get(X))==null?void 0:U.data)==null?void 0:Y.ports)??[]).find(ge=>ge.id===T);if(G){const ge=G.size??20;return{x:G.x+ge/2,y:G.y+ge/2}}}return le},w=y(x.source,(D=x.data)==null?void 0:D.sourcePortId,(O=x.data)==null?void 0:O.sourceOffset),g=y(x.target,(v=x.data)==null?void 0:v.targetPortId,(I=x.data)==null?void 0:I.targetOffset);if(!w||!g||!r.has(x.source)||!r.has(x.target))return[];const E=i(x.source),m=i(x.target);return[{id:x.id,source:{x:E.x+w.x,y:E.y+w.y},target:{x:m.x+g.x,y:m.y+g.y},sourceNodeId:x.source,targetNodeId:x.target,sourceSide:($=x.data)==null?void 0:$.sourceSide,targetSide:(z=x.data)==null?void 0:z.targetSide}]});if(h.length===0)return d;const F=o.filter(x=>!x.data.isFrame).map(x=>({id:x.id,...i(x.id),...u(x)})),S=new Map(h.map(x=>[x.id,x])),b=h.filter(x=>{var y,w;return!((w=(y=d.find(g=>g.id===x.id))==null?void 0:y.data)!=null&&w.manualRoute)}),j=xs(b,F);return d.map(x=>{var w;const y=S.get(x.id);if(!y)return x;if((w=x.data)!=null&&w.manualRoute){const g=[...x.data.points??[]];if(g.length>=2)return g[0]=y.source,g[g.length-1]=y.target,{...x,data:{...x.data,points:g}}}return j.has(x.id)?{...x,data:{...x.data,points:j.get(x.id)}}:x})}function fi({x:o,y:d,onConfirm:r,onCancel:s}){const[i,u]=l.useState(""),h=l.useRef(null);l.useEffect(()=>{var b;(b=h.current)==null||b.focus()},[]),l.useEffect(()=>{const b=j=>{const x=document.getElementById("quick-create-popup");x&&!x.contains(j.target)&&s()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[s]);const F=Math.min(o,window.innerWidth-220),S=Math.min(d,window.innerHeight-80);return e.jsxs("div",{id:"quick-create-popup",className:"fixed z-50 rounded-xl shadow-xl overflow-hidden",style:{left:F,top:S,width:200,background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 8px 32px rgba(0,0,0,0.14)"},children:[e.jsx("div",{className:"px-3 py-2",style:{borderBottom:"1px solid #E5E5E0",fontSize:C.xs,color:"#9CA3AF",fontWeight:600},children:"New Element"}),e.jsxs("div",{className:"px-2 py-2",children:[e.jsx("input",{ref:h,value:i,onChange:b=>u(b.target.value),placeholder:"Element name…",className:"w-full px-2 py-1.5 rounded focus:outline-none",style:{fontSize:C.xs,border:"1px solid #E5E5E0",background:"#F7F7F5",color:"#1a1a1a"},onKeyDown:b=>{b.key==="Enter"&&i.trim()&&(b.preventDefault(),r(i.trim())),b.key==="Escape"&&s()}}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx("button",{onClick:()=>i.trim()&&r(i.trim()),style:{flex:1,fontSize:C.xs,padding:"4px 8px",background:"#2DD4A8",color:"#FFFFFF",border:"none",borderRadius:6,cursor:"pointer",fontWeight:600},children:"Create"}),e.jsx("button",{onClick:s,style:{fontSize:C.xs,padding:"4px 8px",background:"#F7F7F5",color:"#6B7280",border:"1px solid #E5E5E0",borderRadius:6,cursor:"pointer"},children:"Cancel"})]})]})]})}function Lt({color:o,glyph:d}){return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:13,height:13,borderRadius:2,background:o+"22",border:`1.5px solid ${o}`,color:o,fontSize:9,fontWeight:800,lineHeight:1},children:d})}function gi(){var ho,fo,go,mo,yo,bo,Fo,wo,jo,vo;const o=M(t=>t.model),d=M(t=>t.selectedElementId),r=M(t=>t.selectedViewpointId),s=M(t=>t.selectedDiagramId),i=M(t=>t.hiddenLayers),u=M(t=>t.selectElement),h=M(t=>t.inspectElement),F=M(t=>t.inspectRelationship),S=M(t=>t.setActiveMode),b=M(t=>t.setActiveView),j=M(t=>t.setExplorerTab),x=M(t=>t.availableOntologies),y=M(t=>t.setSelectedOntologyKind),w=M(t=>t.diagramLayouts),g=M(t=>t.setNodeLayout),E=M(t=>t.mergeDiagramLayouts),m=M(t=>t.updateDiagramElementIds),{fitView:D,screenToFlowPosition:O,getViewport:v,setViewport:I}=zt(),[$,z]=$n([]),[X,T,le]=Pn([]),U=l.useRef([]),Y=l.useRef([]),G=l.useRef(o),ge=l.useRef(s),pt=l.useRef(null),ut=l.useRef(null),xt=l.useRef(null),be=l.useRef(0);l.useEffect(()=>{U.current=$},[$]),l.useEffect(()=>{Y.current=X},[X]);const _e=l.useCallback(t=>{U.current=t,ut.current===null&&(ut.current=requestAnimationFrame(()=>{ut.current=null;const n=U.current,a=Go(n,Y.current);Y.current=a,z(n),T(a)}))},[z,T]),[te,He]=l.useState(!1),[Wt,Fe]=l.useState(0),[$t,ht]=l.useState(null),[Pt,Qo]=l.useState(0),[Jo,ft]=l.useState(0),[ve,gt]=l.useState(!0),[en,_t]=l.useState(!0),[Ht,tn]=l.useState(!0),[mt,on]=l.useState("horizontal"),[Ke,Kt]=l.useState("allocation"),[yt,Vt]=l.useState("all"),[Yt,nn]=l.useState(!1),[de,sn]=l.useState(new Set(["control","data","energy","material"])),[J,Ee]=l.useState(null),[ce,Ve]=l.useState(null),[q,ke]=l.useState(null),[ie,Ye]=l.useState(null),[Se,Gt]=l.useState(null),[Ge,rn]=l.useState(2),[Xe,Xt]=l.useState(null),Ce=l.useRef([]),bt=l.useRef([]),qt=l.useCallback(t=>{Ce.current.push(t),Ce.current.length>xi&&Ce.current.shift(),bt.current=[]},[]),f=Un(o,s),Ie=f?Do[f.diagramType]:null,qe=!!((ho=f==null?void 0:f.properties)!=null&&ho.layoutStyle),pe=((fo=f==null?void 0:f.properties)==null?void 0:fo.layoutStyle)==="fbs",me=s?w[s]:void 0,ue=ts(me),re=((go=me==null?void 0:me.canvas)==null?void 0:go.autoLayout)!==!1,xe=((mo=me==null?void 0:me.canvas)==null?void 0:mo.flowAnimation)===!0,oe=l.useCallback(()=>{var n;if(!s)return;const t=M.getState().diagramLayouts[s]??{nodes:{},edges:{}};((n=t.canvas)==null?void 0:n.autoLayout)!==!1&&E({[s]:{...t,canvas:{...t.canvas,autoLayout:!1}}})},[s,E]);l.useEffect(()=>{if(!s||re||te||$.length===0||Wt===0)return;const t=window.setTimeout(()=>{const n=M.getState().diagramLayouts[s]??{nodes:{},edges:{}},a=v(),p={nodes:Object.fromEntries($.map(c=>[c.id,{...n.nodes[c.id]??{},x:c.position.x,y:c.position.y,...c.width?{width:c.width}:{},...c.height?{height:c.height}:{},ports:Object.fromEntries((c.data.ports??[]).map(k=>[k.id,{x:k.x,y:k.y,side:k.side}]))}])),edges:Object.fromEntries(X.map(c=>{var k,B,R,P,H,W;return[c.id,{...(()=>{var _;const{points:V,...K}=((_=n.edges)==null?void 0:_[c.id])??{};return K})(),...(k=c.data)!=null&&k.manualRoute&&((R=(B=c.data)==null?void 0:B.points)!=null&&R.length)?{points:(P=c.data)==null?void 0:P.points,source:c.source,target:c.target,sourcePortId:(H=c.data)==null?void 0:H.sourcePortId,targetPortId:(W=c.data)==null?void 0:W.targetPortId}:{}}]})),canvas:{...n.canvas,zoom:a.zoom,pan:{x:a.x,y:a.y},autoLayout:!1}};E({[s]:p}),We(s,p),Fe(0)},350);return()=>window.clearTimeout(t)},[s,re,te,Wt,$,X,v,E]);const L=f?f.viewKind??(Ie==null?void 0:Ie.viewKind)??"general":void 0,Ne=L==="interconnection"?.72:.1,De=L?Ro[L]:null,ye=L==="general"&&!qe&&!pe,[he,Ut]=l.useState("graph"),Zt=l.useMemo(()=>L==="statetransition"?["compound-graph"]:["flat-graph"],[L]),Ft=l.useMemo(()=>vs(Zt).filter(t=>t.mode==="automatic"),[Zt]),an=pe||ye&&he==="graph"||L==="interconnection"||L==="actionflow"||L==="statetransition",wt=(yo=f==null?void 0:f.properties)==null?void 0:yo.modes,ln=l.useMemo(()=>{if(!wt)return Nt;const t=new Set(wt.split(",").map(a=>a.trim())),n=Nt.filter(a=>t.has(a));return n.length?n:Nt},[wt]),[Ae,Qt]=l.useState(!0),Jt=l.useMemo(()=>{if(!o||!f)return[];const t=new Set(f.elementIds),n=Object.values(o.elements).filter(a=>t.has(a.id)&&a.allocatedTo).map(a=>a.allocatedTo);return os(n,o)},[o,f]),dn=l.useMemo(()=>{if(!o||!f)return"Activity Diagram";const t=Zn(f);return Do[t].fullName},[o,f]),cn=l.useMemo(()=>{if(!o||!f)return!1;const t=new Set(f.elementIds);return Object.values(o.elements).some(n=>t.has(n.id)&&!!(n.attributes.stage||n.attributes.phase))},[o,f]),Ue=l.useMemo(()=>{if(!o||!f||L!=="actionflow")return[];const t=(f.elementIds??[]).map(n=>o.elements[n]).filter(n=>!!n&&n.construct==="action");return ns(t,o)},[o,f,L]),[Re,pn]=l.useState("containment"),[Te,Ze]=l.useState(new Set),[eo,Le]=l.useState(new Set),[we,Qe]=l.useState(null),[Be,to]=l.useState("all"),[oo,no]=l.useState(!1),[so,ze]=l.useState(new Set),[Me,jt]=l.useState(null),[Je,un]=l.useState(new Map),ne=l.useRef(new Map),vt=l.useMemo(()=>{if(!o||!we)return[];const t=new Map;for(const c of o.relationships)ss.has(c.type)&&!t.has(c.targetId)&&t.set(c.targetId,c.sourceId);const n=[we],a=new Set(n);let p=we;for(;t.has(p);){const c=t.get(p);if(a.has(c))break;n.unshift(c),a.add(c),p=c}return n},[o,we]);l.useEffect(()=>{var n,a;Fe(0),Ut(is(f==null?void 0:f.properties)),Qt(!0),Kt("allocation"),Vt("all");const t=(a=(n=f==null?void 0:f.properties)==null?void 0:n.styleHint)!=null&&a.startsWith("expanded:")?f.properties.styleHint.slice(9).split(",").map(p=>p.trim()).filter(Boolean):[];Ze(new Set(t)),Le(new Set),Qe(null),to("all"),no(!1),ze(new Set),jt(null),ne.current.clear()},[s,(bo=f==null?void 0:f.properties)==null?void 0:bo.layoutHint,(Fo=f==null?void 0:f.properties)==null?void 0:Fo.styleHint]);const xn=l.useMemo(()=>({decompositionNode:Ss,interconnectionNode:Rs,actionFlowNode:Ws,actionFlowLane:Ps,stateNode:Hs,seqLifeline:Vs,seqSection:Gs,seqOccurrence:qs,diagramNode:Us,decisionNode:oi,forkNode:ni,startEndNode:si}),[]),hn=l.useMemo(()=>({interconnectionEdge:Ms}),[]),fn=l.useCallback(t=>{var n,a;return((n=t.data)==null?void 0:n.color)||((a=t.data)==null?void 0:a.layerColor)||"#ccc"},[]),Z=l.useMemo(()=>{const t=(f==null?void 0:f.viewpointId)==="__model"?null:(f==null?void 0:f.viewpointId)||r,n=t&&(o==null?void 0:o.viewpoints),a=i.size>0,p=f!=null&&f.elementIds?new Set(f.elementIds):void 0;if(!n&&!a&&!p)return;const c=n?o.viewpoints.find(R=>R.id===t):void 0,k=c?new Set(c.visibleKinds):void 0,B=c?new Set(c.visibleLayers):void 0;return R=>i.has(R.layer)?!1:p?p.has(R.id):k&&B?k.has(R.kind)||B.has(R.layer):!0},[r,f,o==null?void 0:o.viewpoints,i]),et=l.useMemo(()=>!o||!f||f.diagramType!=="bdd"?null:rs(Lo(o,Z)),[o,f,Z]),io=l.useCallback(()=>{if(o)return pe?as(o):ye?Lo(o,Z):ls(o)},[o,pe,ye,Z]),Oe=l.useCallback(t=>{Ze(n=>{const a=new Set(n);return a.has(t)?a.delete(t):a.add(t),a})},[]),ro=l.useCallback(t=>{Le(n=>{const a=new Set(n);return a.has(t)?a.delete(t):a.add(t),a})},[]),ao=l.useCallback(t=>{ze(n=>{const a=new Set(n);return a.has(t)?a.delete(t):a.add(t),a})},[]),tt=l.useCallback(t=>{ne.current.clear(),un(n=>{const a=new Map(n),p=a.get(t)||"vertical";return a.set(t,p==="vertical"?"horizontal":"vertical"),a})},[]),Et=l.useCallback(()=>{const t=io();if(!t)return;const n=new Set,a=p=>{n.add(p);for(const c of t.childrenMap.get(p)||[])t.elements.has(c)&&a(c)};for(const p of t.roots)t.elements.has(p)&&a(p);Ze(n)},[io]),kt=l.useCallback(()=>Ze(new Set),[]),St=l.useCallback(()=>{ne.current.clear(),ft(t=>t+1)},[]),lo=l.useCallback(t=>t.map(n=>{if(n.type!=="diagramNode")return n;const a=o==null?void 0:o.elements[n.id];return{...n,data:{...n.data,onContextMenu:(p,c)=>{ke({x:p.clientX,y:p.clientY,nodeId:c,nodeKind:n.data.kind??""})},onInlineEdit:(p,c)=>{if(!a)return;const k={...a,name:c};Ao(k)}}}}),[o]),co=l.useCallback((t,n)=>{const a=t.map(c=>{const k=n.nodes[c.id];return k?{...c,position:{x:k.x,y:k.y},...k.width?{width:k.width}:{},...k.height?{height:k.height}:{},data:{...c.data,bgColor:k.color||void 0,...k.ports?{ports:(c.data.ports??[]).map(B=>{var R;return{...B,...((R=k.ports)==null?void 0:R[B.id])??{}}})}:{}}}:c}),p=new Map(a.map(c=>[c.id,c]));return a.map(c=>{if(c.type!=="actionFlowLane")return c;const k=c.data,B=(k.memberIds??[]).map(K=>p.get(K)).filter(Boolean);if(B.length===0)return c;const R=Math.min(...B.map(K=>K.position.x)),P=Math.min(...B.map(K=>K.position.y)),H=Math.max(...B.map(K=>{var _;return K.position.x+Number(K.width??((_=K.style)==null?void 0:_.width)??180)})),W=Math.max(...B.map(K=>{var _;return K.position.y+Number(K.height??((_=K.style)==null?void 0:_.height)??96)})),V=k.orientation==="column";return{...c,position:{x:V?R-36:R-120,y:V?P-32:P-36},style:{...c.style,width:H-R+(V?72:156),height:W-P+(V?68:72)}}})},[]),po=l.useCallback((t,n,a)=>{be.current=Date.now()+250,oe(),Fe(k=>k+1);const p=Y.current.map(k=>{var W,V;if(!(((W=k.data)==null?void 0:W.sourcePortId)===n||((V=k.data)==null?void 0:V.targetPortId)===n))return k;const{points:R,manualRoute:P,...H}=k.data??{};return{...k,data:H}});Y.current=p;const c=U.current.map(k=>k.id!==t?k:{...k,data:{...k.data,ports:(k.data.ports??[]).map(B=>B.id===n?{...B,y:a}:B)}});_e(c)},[_e,oe]),uo=l.useCallback((t,n)=>{be.current=Date.now()+250,oe(),Fe(a=>a+1),T(a=>{const p=a.map(c=>c.id===t?{...c,data:{...c.data,points:n,manualRoute:!0}}:c);return Y.current=p,p})},[oe,T]);l.useEffect(()=>{if(!o)return;const t=G.current!==o&&ge.current===s;if(pt.current=t?v():null,G.current=o,ge.current=s,L==="grid"||L==="browser"||L==="geometry")return;let n=!1;const a=({nodes:R,edges:P},H=!0)=>{if(n)return;const W=s?M.getState().diagramLayouts[s]:void 0,V=W&&Object.keys(W.nodes).length>0?co(R,W):R,K=P.map(_=>{var Eo,ko,So;const se=(Eo=W==null?void 0:W.edges)==null?void 0:Eo[_.id],ot=!(se!=null&&se.source)||se.source===_.source&&se.target===_.target&&se.sourcePortId===((ko=_.data)==null?void 0:ko.sourcePortId)&&se.targetPortId===((So=_.data)==null?void 0:So.targetPortId)?se==null?void 0:se.points:void 0;return{..._,data:{..._.data,...ot!=null&&ot.length?{points:ot,manualRoute:!0}:{},flowAnimation:xe,onRouteChange:Ct=>uo(_.id,Ct),onSelect:Ct=>{Ct.stopPropagation(),!(Date.now()<be.current)&&(T(It=>It.map(Co=>({...Co,selected:Co.id===_.id}))),o.relationships.some(It=>It.id===_.id)&&F(_.id))}}}});z(H?lo(V):V),T(Go(V,K)),He(!1),Qo(_=>_+1)},p=R=>P=>{n||(console.error(`${R} layout error:`,P),He(!1),ht(`${R} layout could not be completed. Try resetting the layout or reducing the visible hierarchy.`))},c=(R,P,H=!0)=>{He(!0),ht(null),Yo(P,R).then(W=>a(W,H)).catch(p(R))},k=()=>{if(pe)c("FBS",hs(o,{expandedNodes:Te,nodeDirections:Je,callbacks:{onToggleExpand:Oe,onToggleDirection:tt},layoutProviderId:ue}));else if(qe)Re==="decomposition"?c("Decomposition",fs(o,{expandedNodes:Te,nodeDirections:Je,callbacks:{onToggleExpand:Oe,onToggleDirection:tt},positionCache:ne.current})):a(gs(o,{expandedNodes:Te,callbacks:{onToggleExpand:Oe}}));else if(L==="interconnection")c("Interconnection",ms(o,{viewpointFilter:Z,relationshipTypes:f==null?void 0:f.relationshipTypes,collapsedNodes:eo,onToggleCollapse:ro,focusId:we??void 0,portDisplay:Be,onPortMove:po,layoutProviderId:ue}),!1);else if(L==="actionflow")c("Action flow",ys(o,{viewpointFilter:Z,swimlanes:Ae,laneGrouping:Ke,displayLevel:yt,expandedActionIds:so,onToggleAction:ao,focusActionId:Me??void 0,visibleFlowKinds:de,direction:mt,layoutProviderId:ue}),!1);else if(L==="statetransition")c("State transition",bs(o,{viewpointFilter:Z,layoutProviderId:ue}),!1);else if(L==="sequence")a(Fs(o,{viewpointFilter:Z}),!1);else if(ye&&he!=="graph")c("General",ws(o,{mode:he,viewpointFilter:Z,expandedNodes:Te,nodeDirections:Je,callbacks:{onToggleExpand:Oe,onToggleDirection:tt},positionCache:ne.current,layoutProviderId:ue}));else{const R=f==null?void 0:f.relationshipTypes,P=ye;He(!0),ht(null),Yo(js(o,{viewpointFilter:Z,relationshipTypes:R,compartments:P,layoutProviderId:ue}),"Standard").then(({nodes:H,edges:W})=>{a({nodes:H,edges:W})}).catch(p("Standard"))}},B=window.setTimeout(k,hi);return()=>{n=!0,window.clearTimeout(B)}},[o,Z,qe,pe,Re,L,ye,he,Ae,Jo,f==null?void 0:f.relationshipTypes,ue,Te,eo,we,Be,so,Me,de,mt,Ke,yt,Je,Oe,ro,ao,tt,s,co,lo,po,uo,F,v]),l.useEffect(()=>{if(Pt===0)return;const t=setTimeout(()=>{var p;const n=pt.current;if(pt.current=null,n){I(n);return}const a=s?(p=M.getState().diagramLayouts[s])==null?void 0:p.canvas:void 0;(a==null?void 0:a.zoom)!==void 0&&a.pan?I({x:a.pan.x,y:a.pan.y,zoom:a.zoom},{duration:300}):D({padding:.08,minZoom:Ne,maxZoom:2,duration:500})},200);return()=>clearTimeout(t)},[Pt,s,D,Ne,I]),l.useEffect(()=>{z(t=>t.map(n=>{const a=n.type==="actionFlowLane"?n.data.inspectElementId:void 0,p=!!d&&(n.id===d||a===d);return{...n,selected:p,style:{...n.style,boxShadow:p?"0 0 0 2px #2DD4A8, 0 4px 12px rgba(45, 212, 168, 0.3)":void 0,opacity:d?p?1:.5:1}}}))},[d,z]),l.useEffect(()=>{if(!Se||!o)return;const t=Es(o,Se,"both",Ge),n=new Set(t.nodes.map(a=>a.elementId));n.add(Se),z(a=>a.map(p=>({...p,style:{...p.style,opacity:n.has(p.id)?1:.08,pointerEvents:n.has(p.id)?"all":"none"}}))),T(a=>a.map(p=>({...p,style:{...p.style,opacity:n.has(p.source)&&n.has(p.target)?1:.05}})))},[Se,Ge,o,z,T]),l.useEffect(()=>{if(!Xe)return;const t=setTimeout(()=>Xt(null),2500);return()=>clearTimeout(t)},[Xe]),l.useEffect(()=>{const t=n=>{const a=n.target;if(!(a.tagName==="INPUT"||a.tagName==="TEXTAREA")){if((n.metaKey||n.ctrlKey)&&n.key==="z"&&!n.shiftKey){n.preventDefault();const p=Ce.current.pop();p&&(p.undo(),bt.current.push(p))}if((n.metaKey||n.ctrlKey)&&(n.key==="Z"||n.key==="z"&&n.shiftKey)){n.preventDefault();const p=bt.current.pop();p&&(p.do(),Ce.current.push(p))}n.key==="g"&&(n.metaKey||n.ctrlKey)&&n.shiftKey&&(n.preventDefault(),_t(p=>!p)),n.key==="0"&&(n.metaKey||n.ctrlKey)&&(n.preventDefault(),D({padding:.08,minZoom:Ne,maxZoom:2,duration:400}))}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[D,Ne]);const gn=l.useCallback(t=>{t.preventDefault(),t.dataTransfer.dropEffect="copy"},[]),mn=l.useCallback(t=>{t.preventDefault();const n=t.dataTransfer.getData("application/memo-kind");if(n)try{const a=JSON.parse(n),p=O({x:t.clientX,y:t.clientY});Ee({x:t.clientX,y:t.clientY,flowX:p.x,flowY:p.y,kind:a.kind,layer:a.layer,construct:a.construct})}catch{}},[O]),yn=l.useCallback(t=>{const n=O({x:t.clientX,y:t.clientY});Ee({x:t.clientX,y:t.clientY,flowX:n.x,flowY:n.y})},[O]),bn=l.useCallback(t=>{if(!J||!s){Ee(null);return}const n=J.kind??"Part",a=J.layer??"logical",p=J.construct??"part",c=Xo[a]??"#6B7280",k=`_new_${Date.now()}`,B={id:k,type:"diagramNode",position:{x:J.flowX,y:J.flowY},data:{label:t,kind:n,layer:a,construct:p,color:c,isNew:!0,onContextMenu:(W,V)=>{ke({x:W.clientX,y:W.clientY,nodeId:V,nodeKind:n})},onInlineEdit:(W,V)=>{Ao({id:k,name:V,kind:n,construct:p,layer:a})}}};z(W=>[...W,B]),Qn({name:t,kind:n,construct:p,attributes:{_layer:a}});const R=(f==null?void 0:f.elementIds)??[];m(s,[...R,k]);const P=s,H={nodes:{...(w[P]??{}).nodes??{},[k]:{x:J.flowX,y:J.flowY}},edges:(w[P]??{}).edges??{}};E({[P]:H}),We(P,H),Ee(null)},[J,s,f,w,E,m,z]),Fn=l.useCallback(()=>{ke(null),Ye(null)},[]),wn=l.useCallback((t,n)=>{n!=null&&n.isValid},[]),jn=l.useCallback(t=>{const{source:n,target:a}=t;if(!n||!a)return;const p=o==null?void 0:o.elements[n],c=o==null?void 0:o.elements[a];Ve({x:window.innerWidth/2-120,y:window.innerHeight/2-160,sourceId:n,targetId:a,sourceKind:(p==null?void 0:p.kind)??"",targetKind:(c==null?void 0:c.kind)??""})},[o]),vn=l.useCallback(t=>{if(!ce||!s){Ve(null);return}const{sourceId:n,targetId:a}=ce,p=je[t]??"#6B7280",k={id:`e_${n}_${a}_${t}_${Date.now()}`,source:n,target:a,label:t,type:"default",style:{stroke:p,strokeWidth:2},labelStyle:{fontSize:"10px",fill:"#374151"},labelBgStyle:{fill:"#FFFFFF",fillOpacity:.9},labelBgPadding:[4,2],labelBgBorderRadius:4,markerEnd:{type:"arrowclosed",color:p}};T(B=>_n(k,B)),Jn(n,a,t),Ve(null)},[ce,s,T]),En=l.useCallback((t,n)=>{xt.current={id:n.id,x:n.position.x,y:n.position.y}},[]),kn=l.useCallback((t,n)=>{const a=xt.current;if(xt.current=null,(a==null?void 0:a.id)===n.id&&Math.hypot(n.position.x-a.x,n.position.y-a.y)>2&&(be.current=Date.now()+250,Fe(B=>B+1)),!s)return;oe();const{x:p,y:c}=n.position,k=ne.current.get(n.id);if(ne.current.set(n.id,{x:p,y:c}),g(s,n.id,{x:p,y:c}),k){const B=n.id,R=s;qt({do:()=>g(R,B,{x:p,y:c}),undo:()=>{g(R,B,k),z(P=>P.map(H=>H.id===B?{...H,position:k}:H))}})}},[s,g,qt,z,oe]),Sn=l.useCallback(t=>{t.some(n=>n.type==="position")&&oe(),t.some(n=>n.type==="dimensions"&&n.resizing)&&(oe(),Fe(n=>n+1)),_e(Hn(t,U.current))},[_e,oe]),Cn=l.useCallback((t,n)=>{},[]),In=l.useCallback((t,n)=>{t.preventDefault(),Ye({x:t.clientX,y:t.clientY,edgeId:n.id,relType:String(n.label??"edge")})},[]),Nn=l.useCallback((t,n)=>{if(Date.now()<be.current)return;const a=n.type==="actionFlowLane"?n.data.inspectElementId:void 0;!a&&(n.id.startsWith("__")||n.id.includes("__start")||n.id.includes("__done"))||(h(a??n.id),s&&b({type:"diagram",diagramId:s}))},[h,s,b]),Dn=l.useCallback((t,n)=>{var a;if((a=t==null?void 0:t.stopPropagation)==null||a.call(t),L==="actionflow"){if(!Object.values((o==null?void 0:o.elements)??{}).some(c=>c.parentAction===n.id))return;jt(n.id),ze(new Set),h(null);return}if(L==="interconnection"){if(!!!n.data.isContainer){h(n.id);return}Qe(n.id),Le(new Set),h(null)}},[L,o==null?void 0:o.elements,h]),An=l.useCallback(()=>{u(null),F(null),ke(null),Ye(null),z(t=>t.map(n=>({...n,style:{...n.style,opacity:1,boxShadow:void 0}}))),T(t=>t.map(n=>n.selected?{...n,selected:!1}:n))},[u,F,z,T]),Rn=l.useCallback((t,n)=>{var a;(a=t==null?void 0:t.stopPropagation)==null||a.call(t),!(Date.now()<be.current)&&(T(p=>p.map(c=>({...c,selected:c.id===n.id}))),o!=null&&o.relationships.some(p=>p.id===n.id)?F(n.id):o!=null&&o.elements[n.id]&&h(n.id))},[o,h,F,T]),Tn=l.useCallback((t,n)=>{var a;s&&(g(s,t,{...((a=w[s])==null?void 0:a.nodes[t])??{x:0,y:0},color:n||void 0}),z(p=>p.map(c=>c.id===t?{...c,data:{...c.data,bgColor:n||void 0}}:c)))},[s,w,g,z]),xo=l.useCallback(t=>{if(!s||!f)return;const n=(f.elementIds??[]).filter(a=>a!==t);m(s,n),z(a=>a.filter(p=>p.id!==t))},[s,f,m,z]),Ln=l.useCallback((t,n)=>{const a=n==="dashed"?"6 3":n==="dotted"?"2 3":void 0;T(p=>p.map(c=>c.id===t?{...c,style:{...c.style,strokeDasharray:a}}:c))},[T]),Bn=l.useCallback((t,n)=>{T(a=>a.map(p=>p.id===t?{...p,style:{...p.style,stroke:n||(je[String(p.label??"")]??"#6B7280")}}:p))},[T]),zn=l.useCallback(t=>{T(n=>n.map(a=>a.id===t?{...a,label:a.label?"":t.split("_")[3]??""}:a))},[T]);if(f&&o&&L==="grid")return e.jsx(ds,{diagram:f,model:o,viewpointFilter:Z});if(f&&o&&L==="browser")return e.jsx(cs,{diagram:f,model:o,viewpointFilter:Z});if(f&&L==="geometry"){const t=Ro.geometry;return e.jsx("div",{className:"flex-1 flex items-center justify-center",style:{background:"#F7F7F5"},children:e.jsxs("div",{className:"text-center",style:{maxWidth:"380px"},children:[e.jsx("span",{className:"inline-block px-2 py-0.5 rounded font-semibold",style:{background:t.color+"20",color:t.color,fontSize:C.badge,marginBottom:"12px"},children:t.label}),e.jsx("h3",{style:{fontSize:C.lg,fontWeight:600,color:"#374151",marginBottom:"8px"},children:f.name}),e.jsx("p",{style:{fontSize:C.md,color:"#9CA3AF",lineHeight:1.6},children:"Geometry View rendering is deferred (ADR-1-19): the ontology carries no spatial data to draw. This view is recognized and validated, but has no renderer yet."})]})})}return!f&&$.length===0&&!te?e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[!ve&&e.jsx(Tt,{collapsed:ve,onToggleCollapse:()=>gt(!0)}),ve&&e.jsx(Tt,{collapsed:!0,onToggleCollapse:()=>gt(!1)}),e.jsx("div",{className:"flex-1 flex items-center justify-center",style:{background:"#F7F7F5"},children:e.jsxs("div",{className:"text-center",style:{maxWidth:"320px"},children:[e.jsx("div",{style:{fontSize:"40px",marginBottom:"16px",opacity:.4},children:"📊"}),e.jsx("h3",{style:{fontSize:C.lg,fontWeight:600,color:"#374151",marginBottom:"8px"},children:"Select a Diagram"}),e.jsx("p",{style:{fontSize:C.md,color:"#9CA3AF",lineHeight:1.6},children:"Choose a diagram from the sidebar or drag elements from the palette."})]})})]}):e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx(Tt,{collapsed:ve,onToggleCollapse:()=>gt(!ve),elementIds:f==null?void 0:f.elementIds,eligibleKinds:f!=null&&f.viewpointId&&(o!=null&&o.viewpoints)?new Set(((wo=o.viewpoints.find(t=>t.id===f.viewpointId))==null?void 0:wo.visibleKinds)??[]):void 0}),e.jsxs("div",{className:"flex-1 relative",onDragOver:gn,onDrop:mn,onDoubleClick:yn,children:[f&&e.jsxs("div",{className:"absolute top-3 left-3 z-10 flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs relative",style:{background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:[De&&e.jsx("span",{className:"px-1.5 py-0.5 rounded font-semibold",style:{background:De.color+"20",color:De.color,fontSize:C.badge},title:`${De.fullName}${Ie?` · ${Ie.fullName}`:""}`,children:L==="actionflow"?dn:De.label}),e.jsx("span",{className:"font-medium",style:{color:"#1a1a1a"},children:f.name}),f.auto&&e.jsx("span",{style:{color:"#9CA3AF",fontSize:"9px"},children:"auto"}),e.jsx($e,{}),e.jsx(Pe,{icon:e.jsx(ae.grid,{}),label:"Grid",active:Ht,onClick:()=>{tn(t=>{const n=!t;return _t(n),n})},title:"Show or hide the canvas grid and snapping (⌘⇧G)"}),pe&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("button",{onClick:Et,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Expand All"}),e.jsx("button",{onClick:kt,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Collapse All"})]}),L==="actionflow"&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{icon:e.jsx(ae.lanes,{}),active:Ae,onClick:()=>Qt(t=>!t),title:"Toggle allocation swimlanes"}),Ae&&cn&&e.jsx(Pe,{icon:e.jsx(ae.lanes,{}),label:"Stage",active:Ke==="stage",onClick:()=>Kt(t=>t==="stage"?"allocation":"stage"),title:"Group this flow by its modeled stages"}),Ae&&Ke==="allocation"&&Jt.length>0&&e.jsxs("select",{"aria-label":"Display hierarchy level",title:"Display responsibility lanes at a hierarchy level; the SysML allocation is unchanged",value:yt,onChange:t=>Vt(t.target.value==="all"?"all":Number(t.target.value)),className:"text-xs font-semibold rounded-lg px-2 py-1",style:{color:"#5B6470",background:"#FFFFFF",border:"1px solid #E2E1DB"},children:[e.jsx("option",{value:"all",children:"All levels"}),Jt.map(t=>e.jsxs("option",{value:t,children:["L",t]},t))]}),e.jsx($e,{}),e.jsx(_o,{value:mt,onChange:on,options:[{value:"horizontal",icon:e.jsx(ae.arrowRight,{}),title:"Left-to-right flow"},{value:"vertical",icon:e.jsx(ae.arrowDown,{}),title:"Top-to-bottom flow"}]}),e.jsx($e,{}),e.jsxs(ai,{children:[e.jsx(Ho,{icon:e.jsx(ae.expand,{}),title:"Expand all sub-actions",onClick:()=>ze(new Set(Object.values((o==null?void 0:o.elements)??{}).map(t=>t.parentAction).filter(t=>!!t)))}),e.jsx(Ho,{icon:e.jsx(ae.collapse,{}),title:"Collapse all sub-actions",onClick:()=>ze(new Set)})]}),e.jsx($e,{}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Pe,{icon:e.jsx(ae.filter,{}),active:Yt,badge:`${de.size}/4`,onClick:()=>nn(t=>!t),title:"Choose which modeled connection categories are visible"}),Yt&&e.jsxs("div",{className:"absolute top-full right-0 mt-2 p-3 rounded-lg",style:{width:264,background:"#FFFFFF",border:"1px solid #D1D5DB",boxShadow:"0 8px 24px rgba(0,0,0,0.14)",zIndex:30},children:[e.jsx("div",{style:{color:"#1F2937",fontWeight:700,fontSize:C.xs},children:"Show connection categories"}),e.jsx("div",{style:{color:"#6B7280",fontSize:C.xs,lineHeight:1.4,marginTop:3,marginBottom:8},children:"Changes this diagram view only; the SysML model is not modified."}),["control","data","energy","material"].map(t=>{const n=de.has(t),a=t==="control"?"#4B5563":t==="data"?"#3498DB":t==="energy"?"#D97706":"#16A34A";return e.jsxs("button",{role:"switch","aria-checked":n,onClick:()=>sn(p=>{const c=new Set(p);return c.has(t)?c.delete(t):c.add(t),c}),className:"w-full flex items-center justify-between px-1 py-1.5 rounded",style:{color:"#374151",textTransform:"capitalize"},title:`${n?"Hide":"Show"} ${t} connections`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{style:{width:9,height:9,borderRadius:"50%",background:a}}),t]}),e.jsx("span",{"aria-hidden":"true",style:{width:32,height:18,borderRadius:9,background:n?"#2563EB":"#D1D5DB",padding:2,transition:"background 160ms ease"},children:e.jsx("span",{style:{display:"block",width:14,height:14,borderRadius:"50%",background:"#FFFFFF",boxShadow:"0 1px 2px rgba(0,0,0,0.22)",transform:n?"translateX(14px)":"translateX(0)",transition:"transform 160ms ease"}})})]},t)})]})]}),Me&&e.jsxs(e.Fragment,{children:[e.jsx($e,{}),e.jsx(Pe,{icon:e.jsx(ae.back,{}),label:"Parent",onClick:()=>jt(null),title:"Return to the parent action flow"}),e.jsx("span",{style:{color:"#6B7280",fontSize:C.xs},children:((jo=o==null?void 0:o.elements[Me])==null?void 0:jo.name)??Me})]})]}),L==="interconnection"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("button",{onClick:()=>Le(new Set),className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Expand All"}),e.jsx("button",{onClick:()=>Le(new Set((o==null?void 0:o.relationships.filter(t=>["composes","composedof","aggregation","decomposedby"].includes(t.type.toLowerCase())).map(t=>t.sourceId))??[])),className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Collapse All"}),e.jsx("span",{style:{color:"#9CA3AF",fontSize:C.xs,fontWeight:600},children:"Ports"}),e.jsx(_o,{value:Be,onChange:to,options:[{value:"all",label:"Nested",title:"Show ports and their nested ports"},{value:"ports",label:"Top",title:"Show top-level ports only (nested connectors lift to the parent port)"},{value:"none",label:"Off",title:"Hide ports; connectors run part to part"}]}),vt.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("button",{onClick:()=>Qe(null),className:"px-1.5 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#2563EB",border:"1px solid #E5E5E0"},title:"Back to the whole diagram",children:"⌂ All"}),vt.map((t,n)=>{var p,c;const a=n===vt.length-1;return e.jsxs("span",{className:"flex items-center gap-1",style:{color:"#9CA3AF"},children:[e.jsx("span",{children:"›"}),e.jsx("button",{onClick:()=>Qe(t),disabled:a,className:"text-xs font-medium",style:{color:a?"#1a1a1a":"#2563EB",fontWeight:a?700:500,cursor:a?"default":"pointer"},title:a?void 0:`Focus ${((p=o==null?void 0:o.elements[t])==null?void 0:p.name)??t}`,children:((c=o==null?void 0:o.elements[t])==null?void 0:c.name)??t})]},t)})]})]}),ye&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("div",{className:"flex rounded overflow-hidden",style:{border:"1px solid #E5E5E0"},children:ln.map(t=>e.jsx("button",{onClick:()=>{Ut(t),ne.current.clear()},className:"px-2 py-0.5 text-xs font-medium capitalize",style:{background:he===t?"#1B3A4B":"#FFFFFF",color:he===t?"#FFFFFF":"#6B7280"},title:t==="graph"?"Relationship graph with compartments":t==="tree"?"Decomposition tree with expand/collapse":"Nested containment blocks",children:t},t))}),he!=="graph"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:Et,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Expand All"}),e.jsx("button",{onClick:kt,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Collapse All"}),he==="tree"&&e.jsx("button",{onClick:St,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},title:"Re-layout the tree from scratch",children:"↻ Reset"})]})]}),qe&&!pe&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("div",{className:"flex rounded overflow-hidden",style:{border:"1px solid #E5E5E0"},children:["containment","decomposition"].map(t=>e.jsx("button",{onClick:()=>{pn(t),ne.current.clear()},className:"px-2 py-0.5 text-xs font-medium",style:{background:Re===t?"#1B3A4B":"#FFFFFF",color:Re===t?"#FFFFFF":"#6B7280"},children:t==="containment"?"Containment":"Decomposition"},t))}),e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsx("button",{onClick:Et,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Expand All"}),e.jsx("button",{onClick:kt,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},children:"Collapse All"}),Re==="decomposition"&&e.jsx("button",{onClick:St,className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F7F7F5",color:"#374151",border:"1px solid #E5E5E0"},title:"Re-layout the tree from scratch",children:"↻ Reset"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),an&&Ft.length>0&&e.jsx("select",{"aria-label":"Layout provider",value:ue,disabled:te,onChange:t=>{const n=Ft.find(c=>c.id===t.target.value);if(!n)return;const a=M.getState().diagramLayouts[s],p=ps({...a??{nodes:{},edges:{}},nodes:{},edges:{},canvas:{...a==null?void 0:a.canvas,autoLayout:!0}},n);E({[s]:p}),We(s,p),ne.current.clear(),ft(c=>c+1)},title:"Choose an installed layout provider for this diagram",className:"px-1.5 py-0.5 text-xs font-medium rounded",style:{color:"#374151",background:"#FFFFFF",border:"1px solid #D1D5DB"},children:Ft.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))}),e.jsxs("button",{"aria-pressed":re,onClick:()=>{if(re)oe();else{const t=M.getState().diagramLayouts[s],n={nodes:{},edges:{},canvas:{...t==null?void 0:t.canvas,autoLayout:!0}};E({[s]:n}),We(s,n),ft(a=>a+1)}},className:"px-2 py-0.5 text-xs font-semibold rounded",style:{background:re?"#ECFDF5":"#FFF7ED",color:re?"#047857":"#C2410C",border:`1px solid ${re?"#A7F3D0":"#FED7AA"}`},title:re?"Auto layout is on. Drag any item to switch it off and preserve your changes automatically.":"Auto layout is off. Your changes are saved automatically; click to discard overrides and recalculate.",children:["Auto layout: ",re?"On":"Off"]})]}),s&&L==="interconnection"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),e.jsxs("button",{"aria-pressed":xe,onClick:()=>{const t=M.getState().diagramLayouts[s]??{nodes:{},edges:{}},n={...t,canvas:{...t.canvas,flowAnimation:!xe}};E({[s]:n}),We(s,n),T(a=>a.map(p=>({...p,data:{...p.data,flowAnimation:!xe}})))},className:"px-2 py-0.5 text-xs font-semibold rounded",style:{background:xe?"#EFF6FF":"#F8FAFC",color:xe?"#1D4ED8":"#64748B",border:`1px solid ${xe?"#93C5FD":"#CBD5E1"}`},title:"Toggle animated source-to-target flow on IBD connectors",children:["Flow: ",xe?"On":"Off"]}),e.jsx("button",{"aria-pressed":oo,onClick:()=>no(t=>!t),className:"px-2 py-0.5 text-xs font-medium rounded",style:{background:"#F8FAFC",color:"#475569",border:"1px solid #CBD5E1"},title:"Show or hide the IBD notation legend",children:"Legend"})]})]}),Se&&e.jsxs("div",{className:"absolute top-3 right-3 z-10 flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs",style:{background:"#1B3A4B",color:"#FFFFFF",boxShadow:"0 2px 8px rgba(0,0,0,0.18)"},children:[e.jsx("span",{style:{color:"#2DD4A8",fontWeight:700},children:"◎ Focus"}),e.jsx("span",{style:{color:"rgba(255,255,255,0.5)"},children:"Depth"}),[1,2,3].map(t=>e.jsx("button",{onClick:()=>rn(t),style:{width:20,height:20,borderRadius:4,cursor:"pointer",background:Ge===t?"#2DD4A8":"rgba(255,255,255,0.15)",color:Ge===t?"#1B3A4B":"#FFFFFF",fontWeight:700,fontSize:"11px",border:"none"},children:t},t)),e.jsx("button",{onClick:()=>{Gt(null),z(t=>t.map(n=>({...n,style:{...n.style,opacity:1,pointerEvents:"all"}}))),T(t=>t.map(n=>({...n,style:{...n.style,opacity:1}})))},style:{marginLeft:4,padding:"2px 8px",borderRadius:4,cursor:"pointer",background:"rgba(255,255,255,0.15)",color:"#FFFFFF",fontSize:"11px",border:"none"},children:"Exit Focus"})]}),Xe&&e.jsxs("div",{className:"absolute bottom-12 left-1/2 -translate-x-1/2 z-50 px-4 py-2 rounded-lg text-xs font-mono",style:{background:"#1B3A4B",color:"#2DD4A8",boxShadow:"0 4px 16px rgba(0,0,0,0.2)",whiteSpace:"nowrap"},children:["Copied: ",Xe]}),te&&e.jsx("div",{className:"absolute top-3 left-1/2 -translate-x-1/2 z-10 px-4 py-1.5 rounded-full text-xs font-medium",style:{background:"#FFFFFF",color:"#6B7280",border:"1px solid #E5E5E0",boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:"Computing layout…"}),$t&&!te&&e.jsxs("div",{role:"alert",className:"absolute top-3 left-1/2 -translate-x-1/2 z-20 flex items-center gap-3 px-3 py-2",style:{maxWidth:620,background:"#FFFDF7",color:"#5F4300",border:"1px solid #E7C35A",borderRadius:4,boxShadow:"0 2px 8px rgba(31,41,55,0.10)",fontSize:C.xs},children:[e.jsx("span",{children:$t}),e.jsx("button",{onClick:St,style:{border:"1px solid #B58A12",borderRadius:3,background:"#FFFFFF",color:"#5F4300",padding:"3px 8px",fontWeight:700,whiteSpace:"nowrap"},children:"Retry"})]}),Ue.length>0&&!te&&e.jsxs("div",{role:"alert",className:"absolute top-16 left-1/2 -translate-x-1/2 z-20 px-3 py-2",style:{maxWidth:720,background:"#FEF2F2",color:"#991B1B",border:"1px solid #FCA5A5",borderRadius:4,boxShadow:"0 2px 8px rgba(31,41,55,0.10)",fontSize:C.xs},children:[e.jsx("span",{style:{fontWeight:700},children:"Diagram error:"})," ",Ue.length," floating ",Ue.length===1?"action has":"actions have"," no flow or succession connection:"," ",Ue.map((t,n)=>e.jsxs("span",{children:[n>0&&", ",e.jsx("button",{onClick:()=>h(t.id),style:{color:"#991B1B",textDecoration:"underline",fontWeight:700},children:t.name})]},t.id))]}),et&&!te&&e.jsxs("div",{role:"alert",className:"absolute top-16 left-1/2 -translate-x-1/2 z-20 px-3 py-2",style:{maxWidth:720,background:"#FEF2F2",color:"#991B1B",border:"1px solid #FCA5A5",borderRadius:4,boxShadow:"0 2px 8px rgba(31,41,55,0.10)",fontSize:C.xs},children:[e.jsx("span",{style:{fontWeight:700},children:"BDD error:"})," ","expected one connected hierarchy, but found ",et.rootIds.length," roots",et.disconnectedIds.length>0&&e.jsxs(e.Fragment,{children:[" and ",et.disconnectedIds.length," disconnected/floating elements"]}),"."]}),L==="actionflow"&&e.jsxs("div",{"aria-label":"Action flow legend",className:"absolute right-3 bottom-3 z-10 flex items-center gap-4 px-3 py-2",style:{background:"rgba(255,255,255,0.96)",border:"1px solid #D1D5DB",borderRadius:3,color:"#374151",fontSize:C.xs},children:[e.jsx("span",{style:{fontWeight:700},children:"Legend"}),de.has("control")&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:24,height:0,borderTop:"2px solid #4B5563"}}),"Control flow"]}),de.has("data")&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:24,height:0,borderTop:"2.5px solid #3498DB"}}),"Object flow"]}),de.has("energy")&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:24,height:0,borderTop:"2.5px solid #D97706"}}),"Energy flow"]}),de.has("material")&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:24,height:0,borderTop:"2.5px solid #16A34A"}}),"Material flow"]})]}),L==="interconnection"&&$.length>0&&oo&&e.jsxs("div",{"aria-label":"Interconnection legend",className:"absolute right-3 bottom-3 z-10 flex flex-col gap-1.5 px-3 py-2",style:{background:"rgba(255,255,255,0.96)",border:"1px solid #D1D5DB",borderRadius:4,color:"#374151",fontSize:C.xs},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{style:{fontWeight:700},children:"Ports"}),Be!=="none"?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lt,{color:at.in,glyph:"→"})," in"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lt,{color:at.out,glyph:"→"})," out"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lt,{color:at.inout,glyph:"⇄"})," inout"]}),Be==="all"&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{style:{width:9,height:9,borderRadius:2,flexShrink:0,background:"#6B728022",border:"1.5px solid #6B7280"}}),"nested"]})]}):e.jsx("span",{style:{color:"#9CA3AF"},children:"hidden"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{style:{fontWeight:700},children:"Flow"}),["data","energy","material"].map(t=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{style:{width:20,height:0,borderTop:`2.5px solid ${us[t]}`}}),t]},t))]})]}),!te&&$.length===0&&f&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",style:{zIndex:1},children:f.auto&&((vo=f.elementIds)==null?void 0:vo.length)===0?e.jsxs("div",{className:"text-center",style:{maxWidth:420},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:8},children:"🔍"}),e.jsx("div",{style:{fontSize:C.sm,color:"#374151",fontWeight:600,marginBottom:4},children:"This view selects no elements"}),e.jsx("div",{style:{fontSize:C.xs,color:"#6B7280",lineHeight:1.6},children:"The view is auto-populated from its selectionQuery in the model. Add includeElementKinds / includeLayers to its SysML definition, or link elements to it with IncludedIn relationships."})]}):e.jsxs("div",{className:"text-center",style:{opacity:.4},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:8},children:"🖱️"}),e.jsx("div",{style:{fontSize:C.sm,color:"#6B7280"},children:"Drag from palette or double-click to create elements"})]})}),te&&e.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,height:"2px",zIndex:20,background:`linear-gradient(90deg, ${To.accent} 0%, ${To.accent}80 50%, transparent 100%)`,backgroundSize:"200% 100%",animation:"memo-layout-progress 1.2s linear infinite"}}),e.jsxs(Kn,{nodes:$,edges:X,nodeTypes:xn,edgeTypes:hn,onNodesChange:Sn,onEdgesChange:le,onNodeClick:Nn,onNodeDoubleClick:Dn,onEdgeClick:Rn,onPaneClick:An,onNodeDragStart:En,onNodeDragStop:kn,onNodeContextMenu:Cn,onEdgeContextMenu:In,onConnect:jn,onConnectStart:Fn,onConnectEnd:wn,connectionMode:Vn.Loose,defaultEdgeOptions:{interactionWidth:24},snapToGrid:en,snapGrid:ui,fitView:!0,fitViewOptions:{...di,minZoom:Ne},minZoom:.1,maxZoom:3,zoomOnScroll:!0,panOnScroll:!0,panOnScrollMode:"free",selectionOnDrag:!1,proOptions:pi,style:li,children:[Ht&&e.jsx(Yn,{color:"#C5C7C2",gap:20,size:1.5}),e.jsx(Gn,{}),$.length>20&&e.jsx(Xn,{style:ci,nodeColor:fn,maskColor:"rgba(247, 247, 245, 0.7)"})]})]}),J&&e.jsx(fi,{x:J.x,y:J.y,onConfirm:bn,onCancel:()=>Ee(null)}),ce&&e.jsx(Zs,{x:ce.x,y:ce.y,sourceKind:ce.sourceKind,targetKind:ce.targetKind,onSelect:vn,onCancel:()=>Ve(null)}),q&&e.jsx(Js,{x:q.x,y:q.y,nodeId:q.nodeId,nodeKind:q.nodeKind,onClose:()=>ke(null),onEditName:()=>{z(t=>t.map(n=>n.id===q.nodeId?{...n,data:{...n.data,_triggerEdit:!0}}:n))},onChangeColor:t=>Tn(q.nodeId,t),onRemoveFromDiagram:()=>xo(q.nodeId),onDeleteFromModel:()=>{xo(q.nodeId)},onShowProperties:()=>{u(q.nodeId)},onShowInCatalog:()=>{u(q.nodeId),S("catalog")},onFocusElement:()=>{Gt(q.nodeId)},onShowRelMatrix:()=>{b({type:"traceability"})},onOpenSource:()=>{const t=o==null?void 0:o.elements[q.nodeId];t!=null&&t.file&&(navigator.clipboard.writeText(t.file).catch(()=>{}),Xt(t.file))},onViewKindInOntology:()=>{const t=q.nodeKind;let n=null,a=null;for(const p of x){for(const c of p.layers)if(c.kinds.some(k=>k.name===t)){n=p.name,a=c.id;break}if(n)break}n&&(y(t),j("ontologies"),S("ontology"),b({type:"ontology-detail",packageName:n,layerId:a??void 0}))}}),ie&&e.jsx(ti,{x:ie.x,y:ie.y,edgeId:ie.edgeId,relType:ie.relType,onClose:()=>Ye(null),onChangeStyle:t=>Ln(ie.edgeId,t),onChangeColor:t=>Bn(ie.edgeId,t),onToggleLabel:()=>zn(ie.edgeId),onDelete:()=>T(t=>t.filter(n=>n.id!==ie.edgeId))})]})}function Si(){return e.jsx(Wn,{children:e.jsx(gi,{})})}export{Si as DiagramCanvas};
@@ -1,4 +1,4 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SysmlCodeEditor-BLcw6hdp.js","assets/reactflow-WKyu73tD.js","assets/zustand-qbFpP9Up.js","assets/SysmlCodeEditor-BwKcXIZw.css"])))=>i.map(i=>d[i]);
2
- import{u as k,g as P,l as Y,s as V,a as W,F as a,C as o,_ as q,b as G,L as U,c as H,d as J}from"./index-c27kHB43.js";import{j as e}from"./reactflow-WKyu73tD.js";import{a as r}from"./zustand-qbFpP9Up.js";import{DiagramSurface as K}from"./DiagramSurface-BIK9fV8R.js";const Q=r.lazy(()=>q(()=>import("./SysmlCodeEditor-BLcw6hdp.js"),__vite__mapDeps([0,1,2,3])).then(l=>({default:l.SysmlCodeEditor})));function X(l,c){const u=(l.elementIds??[]).map(s=>c[s]).filter(Boolean).map(s=>` ${s.construct??"part"} ${s.id} : ${s.kind};`).join(`
2
+ import{u as k,g as P,l as Y,s as V,a as W,F as a,C as o,_ as q,b as G,L as U,c as H,d as J}from"./index-CgRwea72.js";import{j as e}from"./reactflow-WKyu73tD.js";import{a as r}from"./zustand-qbFpP9Up.js";import{DiagramSurface as K}from"./DiagramSurface-B_lfUNzV.js";const Q=r.lazy(()=>q(()=>import("./SysmlCodeEditor-BLcw6hdp.js"),__vite__mapDeps([0,1,2,3])).then(l=>({default:l.SysmlCodeEditor})));function X(l,c){const u=(l.elementIds??[]).map(s=>c[s]).filter(Boolean).map(s=>` ${s.construct??"part"} ${s.id} : ${s.kind};`).join(`
3
3
  `);return[`package '${l.name}' {`,` // Diagram: ${l.diagramType.toUpperCase()} | Viewpoint: ${l.viewpointId}`,u||" // No elements selected","}"].join(`
4
4
  `)}function Z({diagram:l}){const c=k(n=>n.model),u=k(n=>n.updateDiagramElementIds),[s,x]=r.useState(""),E=r.useMemo(()=>G(c),[c]),w=r.useCallback(n=>{const f=new Set(l.elementIds??[]);f.has(n)?f.delete(n):f.add(n),u(l.id,[...f])},[l.id,l.elementIds,u]),h=r.useMemo(()=>new Set(l.elementIds??[]),[l.elementIds]),p=U.filter(n=>E.has(n));return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",style:{width:"220px",borderLeft:`1px solid ${o.border}`,background:"#FAFAF8",flexShrink:0},children:[e.jsxs("div",{className:"px-2 py-1.5",style:{borderBottom:`1px solid ${o.border}`},children:[e.jsxs("div",{className:"font-semibold mb-1",style:{color:o.primary,fontSize:a.xs},children:["Elements (",h.size," selected)"]}),e.jsx("input",{value:s,onChange:n=>x(n.target.value),placeholder:"Filter…",className:"w-full px-2 py-1 rounded focus:outline-none",style:{background:"#F0F0ED",border:`1px solid ${o.border}`,color:o.primary,fontSize:a.xs}})]}),e.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:p.map(n=>{const f=(E.get(n)??[]).filter(i=>!s||i.name.toLowerCase().includes(s.toLowerCase())||i.id.toLowerCase().includes(s.toLowerCase()));if(f.length===0)return null;const g=J[n]??o.muted;return e.jsxs("div",{children:[e.jsx("div",{className:"px-2 py-1 font-semibold",style:{color:g,fontSize:a.badge},children:H[n]??n}),f.map(i=>e.jsxs("label",{className:"flex items-center gap-2 px-3 py-0.5 cursor-pointer",style:{fontSize:a.xs},onMouseEnter:S=>S.currentTarget.style.background="#F0F0ED",onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsx("input",{type:"checkbox",checked:h.has(i.id),onChange:()=>w(i.id),style:{accentColor:o.accent}}),e.jsx("span",{className:"truncate",style:{color:o.primary},title:i.id,children:i.name||i.id})]},i.id))]},n)})})]})}const ee=[];function le({diagramId:l}){const c=k(t=>t.model),u=k(t=>t.diagramParseErrors[l]??ee),s=P(c,l),[x,E]=r.useState("visual"),[w,h]=r.useState(""),[p,n]=r.useState(!1),[f,g]=r.useState(!1),[i,S]=r.useState(!1),[m,N]=r.useState(!1),[b,j]=r.useState(null),[$,T]=r.useState(null),[C,O]=r.useState(()=>localStorage.getItem("memo.diagramEditor.autoSave")==="true"),F=r.useRef(),y=r.useRef(""),D=r.useRef(0);r.useEffect(()=>{let t=!1;if(clearTimeout(F.current),j(null),T(null),N(!1),!(!s||!c)){if(!s.sourceFile||window.__MEMO_DATA__){const d=X(s,c.elements);y.current=d,h(d),n(!1),g(!1);return}return h(""),y.current="",n(!0),g(!1),Y(l).then(d=>{if(t)return;const v=d.text??"";y.current=v,h(v),g(!0)}).catch(d=>{t||j(d instanceof Error?d.message:String(d))}).finally(()=>{t||n(!1)}),()=>{t=!0}}},[l,s==null?void 0:s.sourceFile]);const B=t=>{y.current=t,h(t),N(!0),j(null)},A=r.useCallback(async t=>{if(!s)return;const d=++D.current;S(!0),j(null);try{s.sourceFile?await V(l,t):W(l,t),y.current===t&&N(!1),T(Date.now())}catch(v){j(v instanceof Error?v.message:String(v))}finally{D.current===d&&S(!1)}},[s,l]);r.useEffect(()=>(localStorage.setItem("memo.diagramEditor.autoSave",String(C)),clearTimeout(F.current),C&&m&&!p&&(F.current=setTimeout(()=>void A(y.current),800)),()=>clearTimeout(F.current)),[C,m,p,w,A]);const M=r.useCallback(()=>{clearTimeout(F.current),A(y.current)},[A]),I=r.useMemo(()=>Object.values((c==null?void 0:c.elements)??{}).map(t=>({id:t.id,name:t.name,kind:t.kind})),[c==null?void 0:c.elements]);if(!s)return e.jsx("div",{className:"flex-1 flex items-center justify-center",style:{color:o.faint,fontSize:a.sm},children:"Diagram not found"});const _=s.auto,L=!_||!!s.sourceFile&&f,z=e.jsxs("div",{className:"flex flex-col h-full flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-hidden",style:{background:"#1E1E1E"},children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"h-full flex items-center justify-center",style:{color:"#9CA3AF",fontSize:a.xs},children:"Loading SysML editor…"}),children:e.jsx(Q,{value:w,sourceFile:s.sourceFile,readOnly:!L||p,symbols:I,onChange:B,onSave:()=>{L&&m&&M()}})})}),u.length>0&&e.jsx("div",{className:"px-3 py-1.5 text-xs",style:{background:"#1C0A0A",color:"#F87171",borderTop:"1px solid #3B0A0A",fontFamily:"monospace"},children:u.join(" · ")}),b&&e.jsx("div",{className:"px-3 py-1.5 text-xs",style:{background:"#1C0A0A",color:"#FCA5A5",borderTop:"1px solid #3B0A0A"},children:b}),!L&&e.jsx("div",{className:"px-3 py-1.5 text-xs",style:{background:"#F9F9F8",color:o.faint,borderTop:`1px solid ${o.border}`},children:s.sourceFile&&window.__MEMO_DATA__?"Static build — run memo-architect dev to edit the SysML source":s.sourceFile?"The SysML source could not be loaded":"Generated model view — no editable SysML source file"})]}),R=e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 flex flex-col overflow-hidden",children:e.jsx(K,{})}),!_&&e.jsx(Z,{diagram:s})]});return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5",style:{borderBottom:`1px solid ${o.border}`,background:"#FAFAF8",flexShrink:0},children:[e.jsx("span",{className:"font-semibold truncate flex-1",style:{color:o.primary,fontSize:a.sm},children:s.name}),s.sourceFile&&e.jsx("span",{className:"truncate",title:s.sourceFile,style:{maxWidth:"220px",color:o.faint,fontSize:a.xs},children:s.sourceFile}),(x==="text"||x==="split")&&e.jsx("span",{title:"Local, public Monaco editor with SysML highlighting and model-aware completion",style:{color:"#4B6E80",fontSize:a.badge},children:"Monaco · SysML"}),p&&e.jsx("span",{style:{color:o.faint,fontSize:a.xs},children:"Loading source…"}),i&&e.jsx("span",{style:{color:o.faint,fontSize:a.xs},children:"Saving…"}),!i&&b&&e.jsx("span",{title:b,style:{color:"#EF4444",fontSize:a.xs},children:"Save failed"}),!i&&!b&&m&&e.jsx("span",{style:{color:"#B45309",fontSize:a.xs},children:"Unsaved"}),!i&&!m&&$&&e.jsx("span",{style:{color:"#15803D",fontSize:a.xs},children:"Saved"}),!i&&u.length>0&&e.jsxs("span",{style:{color:"#EF4444",fontSize:a.xs},children:[u.length," error",u.length>1?"s":""]}),L&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1",style:{color:o.secondary,fontSize:a.xs},title:"Save changes 800ms after typing",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:t=>O(t.target.checked),style:{accentColor:o.accent}}),"Auto-save"]}),e.jsx("button",{onClick:M,disabled:!m||i||p,title:"Save SysML (Ctrl/Cmd+S)",style:{fontSize:a.xs,padding:"3px 10px",borderRadius:"5px",border:`1px solid ${o.border}`,cursor:!m||i||p?"default":"pointer",background:m?o.accent:"#F0F0ED",color:m?"#FFFFFF":o.faint,fontWeight:600},children:"Save"})]}),e.jsx("div",{className:"flex overflow-hidden",style:{border:`1px solid ${o.border}`,borderRadius:"6px"},children:[["visual","⬜ Visual"],["split","⧉ Split"],["text","</> Text"]].map(([t,d])=>e.jsx("button",{onClick:()=>E(t),style:{fontSize:a.xs,padding:"3px 10px",border:"none",cursor:"pointer",background:x===t?o.accent:"transparent",color:x===t?"#FFFFFF":o.secondary,fontWeight:x===t?600:400},children:d},t))})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[x==="visual"&&R,x==="text"&&z,x==="split"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{width:"50%",borderRight:`1px solid ${o.border}`,display:"flex",flexDirection:"column",overflow:"hidden"},children:z}),e.jsx("div",{style:{width:"50%",display:"flex",overflow:"hidden"},children:R})]})]})]})}export{le as DiagramEditor};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiagramCanvas-CUYbaLjV.js","assets/reactflow-WKyu73tD.js","assets/zustand-qbFpP9Up.js","assets/index-c27kHB43.js","assets/index-BZhRuk7M.css","assets/layout-selection-DvOsyJH9.js","assets/layout-providers-BAUgp0nu.js","assets/elk-B75IRfCd.js","assets/style-BZV40eAE.css","assets/MaxGraphCanvas-CDdlW8h_.js"])))=>i.map(i=>d[i]);
2
- var R=Object.defineProperty;var w=(t,e,r)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>w(t,typeof e!="symbol"?e+"":e,r);import{j as o}from"./reactflow-WKyu73tD.js";import{a as s}from"./zustand-qbFpP9Up.js";import{_ as f,F as h}from"./index-c27kHB43.js";const d="memo.renderer.reactflow";class E{constructor(){l(this,"providers",new Map);l(this,"components",new Map)}register(e){const r=this.providers.get(e.descriptor.id);if(r&&r!==e)throw new Error(`Renderer provider already registered: ${e.descriptor.id}`);this.providers.set(e.descriptor.id,e)}unregister(e){return this.components.delete(e),this.providers.delete(e)}get(e){return this.providers.get(e)}has(e){return this.providers.has(e)}list(e=[]){return[...this.providers.values()].map(r=>r.descriptor).filter(r=>e.every(n=>r.capabilities.includes(n))).sort((r,n)=>r.name.localeCompare(n.name))}loadComponent(e){const r=this.providers.get(e)??this.providers.get(d);if(!r)throw new Error(`Renderer provider not found: ${e} (no default registered)`);const n=r.descriptor.id;let a=this.components.get(n);return a||(a=r.loadComponent(),this.components.set(n,a)),a}}const v={descriptor:{id:"memo.renderer.reactflow",name:"ReactFlow",engine:"ReactFlow (@xyflow/react 12)",version:"12",contractVersion:"1",license:"MIT",description:"Default authoring canvas — React node components, palette, full editing.",capabilities:["interactive-editing","all-view-kinds","manual-layout","undo-redo","minimap","orthogonal-routes"]},loadComponent:()=>f(()=>import("./DiagramCanvas-CUYbaLjV.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])).then(t=>t.DiagramCanvas)},x={descriptor:{id:"memo.renderer.maxgraph",name:"maxGraph",engine:"maxGraph (@maxgraph/core — draw.io rendering engine lineage)",version:"0.x",contractVersion:"1",license:"Apache-2.0",description:"draw.io-style retained-mode canvas — SVG cells, rubberband selection, image export.",capabilities:["all-view-kinds","manual-layout","export-image"]},loadComponent:()=>f(()=>import("./MaxGraphCanvas-CDdlW8h_.js"),__vite__mapDeps([9,1,2,3,4,5,6,7])).then(t=>t.MaxGraphCanvas)},i=new E;i.register(v);i.register(x);function _(t=[]){return i.list(t)}const y={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},g="memo.diagram.renderer.v3",m="renderer",F="memo.renderer.",u=new Set;function c(t){const e=t==null?void 0:t.trim();if(e)return e.includes(".")?e:`${F}${e}`}function S(){if(!(typeof window>"u"))try{return c(new URLSearchParams(window.location.search).get(m))}catch{return}}function b(){if(!(typeof window>"u"))try{return c(window.localStorage.getItem(g))}catch{return}}function D(){try{const t=y;return c(t==null?void 0:t.VITE_MEMO_DIAGRAM_RENDERER)}catch{return}}function p(){return S()??b()??D()??d}function I(t){const e=c(t)??d;try{window.localStorage.setItem(g,e)}catch{}try{const r=new URL(window.location.href);r.searchParams.has(m)&&(r.searchParams.delete(m),window.history.replaceState(window.history.state,"",r))}catch{}for(const r of[...u])r()}function A(t){return u.add(t),()=>u.delete(t)}function C(){return o.jsx("div",{className:"flex-1 flex items-center justify-center",style:{background:"#F7F7F5",color:"#9CA3AF",fontSize:h.sm},children:"Loading renderer…"})}function j({activeId:t}){const e=_();return e.length<2?null:o.jsx("div",{className:"absolute bottom-3 right-3 z-10 flex items-center overflow-hidden rounded-lg",style:{border:"1px solid #E5E5E0",background:"#FFFFFF",boxShadow:"0 2px 8px rgba(0,0,0,0.08)"},title:"Diagram rendering engine",children:e.map(r=>{const n=r.id===t;return o.jsx("button",{onClick:()=>I(r.id),title:`${r.engine} — ${r.description}`,style:{fontSize:h.xs,padding:"4px 10px",fontWeight:600,border:"none",cursor:n?"default":"pointer",background:n?"#2DD4A8":"transparent",color:n?"#FFFFFF":"#6B7280"},children:r.name},r.id)})})}function L(){const t=s.useSyncExternalStore(A,p,p),e=i.has(t)?t:d,r=s.useMemo(()=>s.lazy(()=>i.loadComponent(e).then(n=>({default:n}))),[e]);return o.jsxs("div",{className:"relative flex flex-1 overflow-hidden",children:[o.jsx(s.Suspense,{fallback:o.jsx(C,{}),children:o.jsx(r,{})}),o.jsx(j,{activeId:e})]})}export{L as DiagramSurface};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiagramCanvas-BgfO0AtP.js","assets/reactflow-WKyu73tD.js","assets/zustand-qbFpP9Up.js","assets/index-CgRwea72.js","assets/index-CnFhl4_e.css","assets/layout-selection-BQ2WuAEB.js","assets/layout-providers-BAUgp0nu.js","assets/elk-B75IRfCd.js","assets/style-BZV40eAE.css","assets/MaxGraphCanvas-DYs6MPuP.js"])))=>i.map(i=>d[i]);
2
+ var R=Object.defineProperty;var w=(t,e,r)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>w(t,typeof e!="symbol"?e+"":e,r);import{j as o}from"./reactflow-WKyu73tD.js";import{a as s}from"./zustand-qbFpP9Up.js";import{_ as f,F as h}from"./index-CgRwea72.js";const d="memo.renderer.reactflow";class E{constructor(){l(this,"providers",new Map);l(this,"components",new Map)}register(e){const r=this.providers.get(e.descriptor.id);if(r&&r!==e)throw new Error(`Renderer provider already registered: ${e.descriptor.id}`);this.providers.set(e.descriptor.id,e)}unregister(e){return this.components.delete(e),this.providers.delete(e)}get(e){return this.providers.get(e)}has(e){return this.providers.has(e)}list(e=[]){return[...this.providers.values()].map(r=>r.descriptor).filter(r=>e.every(n=>r.capabilities.includes(n))).sort((r,n)=>r.name.localeCompare(n.name))}loadComponent(e){const r=this.providers.get(e)??this.providers.get(d);if(!r)throw new Error(`Renderer provider not found: ${e} (no default registered)`);const n=r.descriptor.id;let a=this.components.get(n);return a||(a=r.loadComponent(),this.components.set(n,a)),a}}const v={descriptor:{id:"memo.renderer.reactflow",name:"ReactFlow",engine:"ReactFlow (@xyflow/react 12)",version:"12",contractVersion:"1",license:"MIT",description:"Default authoring canvas — React node components, palette, full editing.",capabilities:["interactive-editing","all-view-kinds","manual-layout","undo-redo","minimap","orthogonal-routes"]},loadComponent:()=>f(()=>import("./DiagramCanvas-BgfO0AtP.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])).then(t=>t.DiagramCanvas)},x={descriptor:{id:"memo.renderer.maxgraph",name:"maxGraph",engine:"maxGraph (@maxgraph/core — draw.io rendering engine lineage)",version:"0.x",contractVersion:"1",license:"Apache-2.0",description:"draw.io-style retained-mode canvas — SVG cells, rubberband selection, image export.",capabilities:["all-view-kinds","manual-layout","export-image"]},loadComponent:()=>f(()=>import("./MaxGraphCanvas-DYs6MPuP.js"),__vite__mapDeps([9,1,2,3,4,5,6,7])).then(t=>t.MaxGraphCanvas)},i=new E;i.register(v);i.register(x);function _(t=[]){return i.list(t)}const y={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},g="memo.diagram.renderer.v3",m="renderer",F="memo.renderer.",u=new Set;function c(t){const e=t==null?void 0:t.trim();if(e)return e.includes(".")?e:`${F}${e}`}function S(){if(!(typeof window>"u"))try{return c(new URLSearchParams(window.location.search).get(m))}catch{return}}function b(){if(!(typeof window>"u"))try{return c(window.localStorage.getItem(g))}catch{return}}function D(){try{const t=y;return c(t==null?void 0:t.VITE_MEMO_DIAGRAM_RENDERER)}catch{return}}function p(){return S()??b()??D()??d}function I(t){const e=c(t)??d;try{window.localStorage.setItem(g,e)}catch{}try{const r=new URL(window.location.href);r.searchParams.has(m)&&(r.searchParams.delete(m),window.history.replaceState(window.history.state,"",r))}catch{}for(const r of[...u])r()}function A(t){return u.add(t),()=>u.delete(t)}function C(){return o.jsx("div",{className:"flex-1 flex items-center justify-center",style:{background:"#F7F7F5",color:"#9CA3AF",fontSize:h.sm},children:"Loading renderer…"})}function j({activeId:t}){const e=_();return e.length<2?null:o.jsx("div",{className:"absolute bottom-3 right-3 z-10 flex items-center overflow-hidden rounded-lg",style:{border:"1px solid #E5E5E0",background:"#FFFFFF",boxShadow:"0 2px 8px rgba(0,0,0,0.08)"},title:"Diagram rendering engine",children:e.map(r=>{const n=r.id===t;return o.jsx("button",{onClick:()=>I(r.id),title:`${r.engine} — ${r.description}`,style:{fontSize:h.xs,padding:"4px 10px",fontWeight:600,border:"none",cursor:n?"default":"pointer",background:n?"#2DD4A8":"transparent",color:n?"#FFFFFF":"#6B7280"},children:r.name},r.id)})})}function L(){const t=s.useSyncExternalStore(A,p,p),e=i.has(t)?t:d,r=s.useMemo(()=>s.lazy(()=>i.loadComponent(e).then(n=>({default:n}))),[e]);return o.jsxs("div",{className:"relative flex flex-1 overflow-hidden",children:[o.jsx(s.Suspense,{fallback:o.jsx(C,{}),children:o.jsx(r,{})}),o.jsx(j,{activeId:e})]})}export{L as DiagramSurface};