@mp70/react-networks 0.1.5-alpha → 0.1.7-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +48 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +140 -4
- package/dist/index.d.ts +140 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var or=require('react'),reactflow=require('reactflow'),htmlToImage=require('html-to-image'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var or__default=/*#__PURE__*/_interopDefault(or);var _o=()=>"bottom-up",xe=e=>e.data.uNumberingDirection||_o(),Be=(e,r,o)=>o==="bottom-up"?r-e+1:e,Me=(e,r,o)=>o==="bottom-up"?r-e+1:e;var nt=(e,r,o,i)=>{if(!e.parentId||e.parentId!==r.id)return o;let n=e.data.uHeight||1,s=r.data.uHeight||42,c=xe(r),a=60,l=o.y-a,p=Math.round(l/20)+1,m;c==="bottom-up"?m=Be(p,s,c)-n+1:m=Be(p,s,c);let b=s-n+1,y=Math.max(1,Math.min(b,m));if(c==="top-down"&&m<=1&&(y=1),!it(r,e,y,i)){let v=Le(r,e,i,y);v!==y&&(y=v);}let H;if(c==="bottom-up"){let v=y+n-1,I=Me(v,s,c);H=a+(I-1)*20-1;}else {let v=Me(y,s,c);H=a+(v-1)*20-1;}return {x:o.x,y:H,uPosition:y}},it=(e,r,o,i)=>{let n=r.data.uHeight||1,s=e.data.uHeight||42;if(o<1||o+n-1>s)return false;let c=i.filter(a=>a.type==="device"&&a.parentId===e.id&&a.id!==r.id);for(let a of c){let l=a.data.uPosition||1,p=a.data.uHeight||1,m=o,b=o+n-1,y=l,H=l+p-1;if(m<=H&&b>=y)return false}return true},Le=(e,r,o,i=1)=>{let n=r.data.uHeight||1,s=e.data.uHeight||42;for(let c=i;c<=s-n+1;c++)if(it(e,r,c,o))return c;return 1},He=(e,r,o=1)=>{let i=60,n=xe(e),s=e.data.uHeight||42,c=Me(r,s,n),a;if(n==="bottom-up"){let l=r+o-1,p=Me(l,s,n);a=i+(p-1)*20-1;}else a=i+(c-1)*20-1;return {x:0,y:a}},Vt=(e,r,o)=>{let i=e.data.uHeight||1,n=He(r,o,i);return {...e,position:n,data:{...e.data,uPosition:o}}},Ao=(e,r)=>{let o=e.data.uPosition||1,i=e.data.uHeight||1,n=r.data.uHeight||42,s=Math.max(1,Math.min(n-i+1,o));return s!==o?Vt(e,r,s):e};function se(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var st=({data:e,selected:r,id:o,onViewChange:i,onRackFaceChange:n,isDragOver:s=false})=>{let{label:c,ports:a=0,status:l="active",uHeight:p=42,face:m="front",customHeaderText:b}=e,{getNodes:y,setNodes:H}=reactflow.useReactFlow(),v=y(),[I,w]=or.useState(true),_=()=>{let R=xe({data:e})==="bottom-up"?"top-down":"bottom-up";H(x=>x.map(N=>N.id===o?{...N,data:{...N.data,uNumberingDirection:R}}:N));},L=()=>{let h=m==="front"?"rear":"front";n?(n(o,h),i&&v.filter(x=>x.parentId===o).forEach(x=>{i(x.id,h);})):i?v.filter(x=>x.parentId===o).forEach(x=>{i(x.id,h);}):H(R=>R.map(x=>x.id===o?{...x,data:{...x.data,face:h}}:x.parentId===o?{...x,data:{...x.data,view:h}}:x));},z=()=>{let h=[],R=60,x=xe({data:e});for(let N=1;N<=p;N++){let $=R+(N-1)*20-4,T=Be(N,p,x);h.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:"-35px",top:`${$}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${20}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:T},N));}return h};return jsxRuntime.jsxs("div",{className:`rack-node ${r?"selected":""} ${s?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${se(l)}`,borderRadius:"8px",padding:0,width:`${300}px`,height:`${60+p*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:s?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":r?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:c}),jsxRuntime.jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[b?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:b}):jsxRuntime.jsxs("span",{children:[typeof a=="number"?a:0," ports"]})," \u2022 ",p,"U \u2022 ",m]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsxRuntime.jsx("button",{onPointerDown:h=>{h.stopPropagation();},onMouseDown:h=>{h.stopPropagation();},onClick:h=>{h.stopPropagation(),h.preventDefault(),w(!I);},style:{background:I?"#10b981":"#374151",color:I?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${I?"Hide":"Show"} U markers`,children:"U"}),jsxRuntime.jsx("button",{onPointerDown:h=>{h.stopPropagation();},onMouseDown:h=>{h.stopPropagation();},onClick:h=>{h.stopPropagation(),h.preventDefault(),_();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch U numbering to ${xe({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:xe({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),jsxRuntime.jsx("button",{onPointerDown:h=>{h.stopPropagation();},onMouseDown:h=>{h.stopPropagation();},onClick:h=>{h.stopPropagation(),h.preventDefault(),L();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${m==="front"?"rear":"front"} view`,children:m==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${p*20}px`,overflow:"hidden"}}),I&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:z()})]})};var at=({data:e,selected:r})=>{let{label:o,status:i="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${r?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${se(i)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:r?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Top}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Bottom}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right}),jsxRuntime.jsx("div",{style:{textAlign:"center"},children:jsxRuntime.jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:o})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:se(i),borderRadius:"50%"}})]})};var ct=({id:e,sourceX:r,sourceY:o,targetX:i,targetY:n,sourcePosition:s,targetPosition:c,data:a,selected:l,style:p={},className:m})=>{let [b,y,H]=reactflow.getBezierPath({sourceX:r,sourceY:o,sourcePosition:s,targetX:i,targetY:n,targetPosition:c}),{bandwidth:v,length:I,color:w="#00FFFF",striped:_=false}=a||{};m?.includes("edge-connecting");let z={...p,stroke:w,strokeWidth:l?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:b,style:z}),_&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:b,style:{...p,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:l&&a&&(v||I)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${y}px,${H}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${w}`,pointerEvents:"none",zIndex:9999},children:[v&&jsxRuntime.jsx("div",{children:v}),I&&jsxRuntime.jsxs("div",{children:[I,"m"]})]})})]})};var lt=({id:e,sourceX:r,sourceY:o,targetX:i,targetY:n,sourcePosition:s,targetPosition:c,style:a={},data:l,markerEnd:p})=>{let[m]=reactflow.getBezierPath({sourceX:r,sourceY:o,sourcePosition:s,targetX:i,targetY:n,targetPosition:c}),b=l?.connectorType||"C13";return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:m,markerEnd:p,style:(()=>{let H={stroke:l?.color||"#f59e0b",strokeWidth:b==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...a};return b==="C19"?{...H,strokeDasharray:"none"}:{...H,strokeDasharray:"6,3"}})()})};var jt=({data:e,selected:r,style:o={},...i})=>{let{color:n="#00FFFF"}=e||{},s={...o,stroke:n,strokeWidth:r?4:3};return jsxRuntime.jsx(reactflow.SmoothStepEdge,{...i,data:e,selected:r,style:s})};function Zo({sourceX:e,sourceY:r,targetX:o,targetY:i,sourcePosition:n,targetPosition:s}){let c=n===reactflow.Position.Left||n===reactflow.Position.Right,a;if(c){let l=(e+o)/2;a=`M ${e},${r} L ${l},${r} L ${l},${i} L ${o},${i}`;}else {let l=(r+i)/2;a=`M ${e},${r} L ${e},${l} L ${o},${l} L ${o},${i}`;}return a}var Kt=({id:e,sourceX:r,sourceY:o,targetX:i,targetY:n,sourcePosition:s,targetPosition:c,data:a,selected:l,style:p={},...m})=>{let{color:b="#00FFFF",striped:y=false}=a||{},H=Zo({sourceX:r,sourceY:o,sourcePosition:s,targetX:i,targetY:n,targetPosition:c}),v={...p,stroke:b,strokeWidth:l?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:H,style:v}),y&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:H,style:{...p,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var qt=(o=>(o.FULL="full",o.HALF="half",o))(qt||{});var pt={C13:{type:"C13",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C14:{type:"C14",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C19:{type:"C19",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},C20:{type:"C20",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1}};function Ce(e){let r=pt[e];if(!r)throw new Error(`Unknown connector type: ${e}`);let o=r.amperage===16,i=o?12:8,n=o?10:5,s=o?{borderRadius:"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:i,height:n,color:r.color,borderColor:r.borderColor,fontSize:o?"3px":"4px",...s}}function Ge(e){let r=pt[e];if(!r)throw new Error(`Unknown connector type: ${e}`);return r}function Jo(e){return Ge(e).amperage===16}function ut(e){return e%10<8?"C13":"C19"}function Xe(e){let r=e.toLowerCase();return r.includes("mx304")||r.includes("mx480")||r.includes("mx960")?"C20":"C14"}var ft=({data:e,selected:r})=>{let{label:o,status:i="active",deviceType:n="server",manufacturer:s,role:c,uHeight:a=1,width:l="full",ports:p=[],rearPorts:m=[],view:b}=e,y=b||(m.length>0&&p.length===0?"rear":"front"),H={};H["net-top"]="front",H["net-bottom"]="front",p.length>0&&p.forEach(h=>{h.ports.forEach(R=>{let x=R.type?.includes("power")?R.label:`${h.name}-${R.label}`;H[x]="front";});}),H["pwr-left-1"]="rear",H["pwr-left-2"]="rear",H["net-right-1"]="rear",H["net-right-2"]="rear",m.length>0&&m.forEach(h=>{h.ports.forEach(R=>{let x=R.type?.includes("power")?R.label:`${h.name}-${R.label}`;H[x]="rear";});});let v=a*20,I=l==="half"?"150px":"304px",w=l==="half"?"150px":void 0,_=(h,R)=>{let x=[];if(h.length===0)return x;let N=Math.max(4,Math.floor(v*.4)),$=Math.max(2,Math.floor(v*.2));return h.forEach((T,M)=>{T.ports.forEach((C,P)=>{let F=!!C.type&&C.type.includes("power");if(R==="front"&&F)return;let Y=F?`${C.label}`:`${T.name}-${C.label}`,j=C.connected,D="#6b7280";if(j)if(C.type?.includes("power"))D=C.type==="power_c19"?"#fbbf24":"#f59e0b";else if(C.type==="console"||C.type==="mgmt")D="#8b5cf6";else if(C.type==="usb")D="#10b981";else switch(C.cableType){case "smf":D="#fbbf24";break;case "cat6":D="#8b5cf6";break;case "om3":D="#06b6d4";break;case "om4":D="#8b5cf6";break;case "om5":D="#84cc16";break;case "cat5e":D="#3b82f6";break;case "cat6a":D="#ef4444";break;case "cat7":D="#f97316";break;case "fiber":D="#3b82f6";break;case "ethernet":D="#10b981";break;default:D="#10b981";}let G=reactflow.Position.Top,E={width:`${N}px`,height:`${$}px`,background:j?D:"#6b7280",border:`1px solid ${j?D:"#374151"}`,borderRadius:"1px",cursor:"pointer"};if(R==="front")P%2===0?(G=reactflow.Position.Top,E.transform="translateY(50%)",E.left=`${P/2*(N+2)}px`):(G=reactflow.Position.Bottom,E.transform="translateY(-50%)",E.left=`${(P-1)/2*(N+2)}px`);else if((n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel")P%2===0?(G=reactflow.Position.Top,E.transform="translateY(50%)",E.left=`${P/2*(N+2)}px`):(G=reactflow.Position.Bottom,E.transform="translateY(-50%)",E.left=`${(P-1)/2*(N+2)}px`);else if(C.type?.includes("power")){G=reactflow.Position.Left,E.transform="translateX(50%)";let We=v<=20?10:20,Pe=v<=20?30:50;E.top=`${We+P*Pe}%`;let tt=Xe(o),fe=Ce(tt);E={...E,width:`${fe.width}px`,height:`${fe.height}px`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:fe.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:fe.borderRadius,clipPath:fe.clipPath};}else G=reactflow.Position.Right,E.transform="translateX(-50%)",E.top=`${25+P*50}%`;let Ae=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",ue;if(F)ue="target";else if(n==="switch"||n==="router")ue="source",x.push(jsxRuntime.jsx(reactflow.Handle,{id:`${Y}-target`,type:"target",position:G,style:E,title:`${T.name} - ${C.label} (input) ${j?"(connected)":"(disconnected)"}`},`${Y}-target`));else if(Ae){ue=R==="rear"?"source":"target";let ge=R==="rear"?"target":"source";x.push(jsxRuntime.jsx(reactflow.Handle,{id:`${Y}-${ge}`,type:ge,position:G,style:E,title:`${T.name} - ${C.label} (${ge}) ${j?"(connected)":"(disconnected)"}`},`${Y}-${ge}`));}else ue=j?"source":"target";x.push(jsxRuntime.jsx(reactflow.Handle,{id:Y,type:ue,position:G,style:E,title:`${T.name} - ${C.label} ${j?"(connected)":"(disconnected)"}`,children:F?P+1:void 0},Y));});}),x},L=()=>{let h=[],R=Math.max(4,Math.floor(v*.4)),x=Math.max(2,Math.floor(v*.2));if(y==="front"){if(p.length>0)return _(p,"front");if(n==="switch"&&(o.toLowerCase().includes("agg")||o.toLowerCase().includes("core")||c==="agg"||c==="core"))return z();h.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-top",type:"target",position:reactflow.Position.Top,style:{width:`${R}px`,height:`${x}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(50%)"},title:"Network Port (Top)"},"net-top")),h.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-bottom",type:"target",position:reactflow.Position.Bottom,style:{width:`${R}px`,height:`${x}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(-50%)"},title:"Network Port (Bottom)"},"net-bottom"));}else if(y==="rear"){if(m.length>0)return _(m,"rear");let N=n==="switch",T=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel";if(!T){let M=Xe(o),C=Ge(M),P=Ce(M),F=v<=20?"10%":"25%";h.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-1",type:"target",position:reactflow.Position.Left,style:{width:`${P.width}px`,height:`${P.height}px`,background:P.color,border:`1px solid ${P.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:F,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:P.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:P.borderRadius,clipPath:P.clipPath},title:`Power Port 1 (${C.type}) - ${C.voltage}V, ${C.amperage}A`,children:"1"},"pwr-1"));let Y=v<=20?"50%":"75%";h.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-2",type:"target",position:reactflow.Position.Left,style:{width:`${P.width}px`,height:`${P.height}px`,background:P.color,border:`1px solid ${P.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:Y,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:P.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:P.borderRadius,clipPath:P.clipPath},title:`Power Port 2 (${C.type}) - ${C.voltage}V, ${C.amperage}A`,children:"2"},"pwr-2"));}!N&&!T&&(h.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-1",type:"target",position:reactflow.Position.Right,style:{width:`${R}px`,height:`${x}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"25%"},title:"Network Port 1 (Right)"},"net-right-1")),h.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-2",type:"target",position:reactflow.Position.Right,style:{width:`${R}px`,height:`${x}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"75%"},title:"Network Port 2 (Right)"},"net-right-2")));}return h},z=()=>{let h=[],R=Math.max(10,Math.floor(v*.45)),x=Math.max(5,Math.floor(v*.25));for(let N=1;N<=16;N++){let $=jsxRuntime.jsx(reactflow.Handle,{id:`port-${N}`,type:"source",position:reactflow.Position.Top,style:{width:`${R}px`,height:`${x}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(50%)",zIndex:1e3,left:`${(N-1)*(R+2)}px`},title:`Port ${N}`},`port-${N}`);h.push($);}for(let N=17;N<=32;N++){let $=N-16,T=jsxRuntime.jsx(reactflow.Handle,{id:`port-${N}`,type:"source",position:reactflow.Position.Bottom,style:{width:`${R}px`,height:`${x}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(-50%)",zIndex:1e3,left:`${($-1)*(R+2)}px`},title:`Port ${N}`},`port-${N}`);h.push(T);}for(let N=1;N<=4;N++){let $=Math.max(4,Math.floor(v*.3)),T=Math.max(3,Math.floor(v*.15));h.push(jsxRuntime.jsx(reactflow.Handle,{id:`uplink-${N}`,type:"source",position:reactflow.Position.Right,style:{width:`${$}px`,height:`${T}px`,background:"#8b5cf6",border:"0.5px solid #7c3aed",borderRadius:"0.5px",cursor:"pointer",transform:"translateX(-50%)"},title:`Uplink ${N}`},`uplink-${N}`));}return h};return jsxRuntime.jsxs("div",{className:`device-node ${r?"selected":""}`,style:{background:"#1f2937",border:`1px solid ${se(i)}`,borderRadius:"2px",padding:"0px",width:I,...w&&{left:w},height:`${v}px`,color:"white",fontFamily:"monospace",fontSize:"8px",boxShadow:r?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",justifyContent:"center",cursor:"grab",marginBottom:"0px",boxSizing:"border-box",marginTop:"0px",marginLeft:"0px",marginRight:"0px"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",flex:1,display:"flex",flexDirection:"column",justifyContent:"center",overflow:"hidden",padding:"2px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"7px",lineHeight:"1.1",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:o}),a>1&&jsxRuntime.jsx("div",{style:{fontSize:"6px",color:"#9ca3af",lineHeight:"1"},children:s})]}),a>1&&jsxRuntime.jsxs("div",{style:{position:"absolute",bottom:"1px",right:"1px",background:"#374151",color:"#9ca3af",padding:"1px 2px",borderRadius:"1px",fontSize:"6px",lineHeight:"1"},children:[a,"U"]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"1px",left:"1px",width:"4px",height:"4px",background:se(i),borderRadius:"50%"}}),L()]})};var bt=({data:e,selected:r})=>{let{label:o,status:i="active",heightCm:n=100,powerPorts:s=36,widthPx:c=15,mgmt_unit:a}=e,l=n*4.2,p=()=>{let y=Math.ceil(s/10),H=Array(10).fill(0).map((x,N)=>N<8?"10A":"16A");for(let x=0,N=0;x<y;++x)for(let $=0;$<10&&N<s;++$,++N){H[$];}let _=[],L=15,R=(l-L-3)/(s-9)*.5;for(let x=0;x<s;x++){let N=L-2+R*x,$=`${x+1}`;if(a&&(a==="top"&&x===0||a==="middle"&&x===Math.floor(s/2)||a==="bottom"&&x===s-1)){_.push(m(N));continue}let M=ut(x),C=Ce(M),P=Math.round((c-C.width)/2-1);_.push(jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:$,style:{position:"absolute",left:`${P}px`,top:`${N-C.height/2}px`,width:`${C.width}px`,height:`${C.height}px`,background:C.color,border:`1px solid ${C.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:C.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:C.borderRadius,clipPath:C.clipPath},title:`Power Port ${x+1} (${M})`,children:x+1},`handle-${$}`));}return _},m=b=>jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(c-16)/2}px`,top:`${b-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsxRuntime.jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit");return jsxRuntime.jsxs("div",{className:`vertical-pdu-node ${r?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${se(i)}`,borderRadius:"2px",padding:0,width:`${c}px`,height:`${l}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:r?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:"20px",display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:o})}),jsxRuntime.jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${l-20}px`,overflow:"hidden"},children:p()})]})};var yt=({data:e,selected:r,id:o})=>{let{lossDb:i}=e||{},n=reactflow.useEdges(),s=n.find(y=>y.target===o&&y.targetHandle==="left"),c=n.find(y=>y.source===o&&y.sourceHandle==="right"),a=n.find(y=>y.target===o&&y.targetHandle==="right"),l=c||a,p=s?.data?.color||"#555",m=l?.data?.color||"#555",b=!!s&&!!l;return jsxRuntime.jsxs("div",{className:`splice-node ${r?"selected":""}`,style:{width:69,height:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:r?"0 0 0 2px #3b82f6":"none"},children:[jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsxRuntime.jsx("div",{style:{background:p}}),jsxRuntime.jsx("div",{style:{background:m}})]}),jsxRuntime.jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1}}),b&&jsxRuntime.jsx("div",{className:"splice-glow",style:{position:"absolute",left:"50%",top:0,bottom:0,width:"1px",background:"rgba(255, 255, 255, 0.6)",boxShadow:"0 0 2px rgba(255, 255, 255, 0.8), 0 0 4px rgba(255, 255, 255, 0.4)",pointerEvents:"none",zIndex:2}}),b&&typeof i=="number"&&jsxRuntime.jsx("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold"},children:`${i.toFixed(2)} dB`}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left,id:"left",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:p,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:m,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:m,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var he=20,we=32,oo=4,ye=12,er=69,wt=80,xt=(wt-er)/2;var kt=(e,r,o,i)=>{if(!e.parentId||e.parentId!==r.id)return o;let n=we,s=o.y-n,c=Math.round(s/he)+1,l=Math.max(1,Math.min(ye,c));if(!Nt(r,e,l,i)){let y=Ze(r,e,i,l);if(y!==l)return {x:xt,y:n+(y-1)*he+5,holderPosition:y}}let b=n+(l-1)*he+5;return {x:xt,y:b,holderPosition:l}},Nt=(e,r,o,i)=>!i.filter(s=>s.parentId===e.id&&s.type==="splice"&&s.id!==r.id).some(s=>s.data.holderPosition===o),Ze=(e,r,o,i=1)=>{for(let n=i;n<=ye;n++)if(Nt(e,r,n,o))return n;for(let n=i-1;n>=1;n--)if(Nt(e,r,n,o))return n;return 1},Fe=(e,r)=>{let n=we+(r-1)*he+5;return {x:xt,y:n}};var St=({data:e,selected:r})=>{let{label:o="Splice Tray",status:i="active"}=e||{},[n,s]=or.useState(false),c=()=>{if(!n)return null;let a=[],l=we;for(let p=1;p<=ye;p++){let m=l+(p-1)*he;a.push(jsxRuntime.jsxs("div",{style:{position:"absolute",left:"-35px",top:`${m}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${he}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",p]},p));}return a};return jsxRuntime.jsxs("div",{className:`splice-tray-node ${r?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${wt}px`,height:`${we+ye*he+oo}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:r?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${we}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:o}),jsxRuntime.jsx("button",{onPointerDown:a=>{a.stopPropagation();},onMouseDown:a=>{a.stopPropagation();},onClick:a=>{a.stopPropagation(),a.preventDefault(),s(!n);},style:{background:n?"#10b981":"#374151",color:n?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${n?"Hide":"Show"} holder markers`,children:"H"})]}),c(),jsxRuntime.jsx("div",{style:{position:"absolute",top:we,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var ro=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function ae(e){let r=(e-1)%12;return ro[r]}function no(e){return e>12}function _e(e){let r=ae(e);return no(e)?{background:r,backgroundImage:`repeating-linear-gradient(45deg, ${r} 0 6px, #000 6px 9px)`}:{background:r}}function Ht(e){return ae(e)}var Ct=({data:e,selected:r,id:o})=>{let{fibersPerTube:i=12,tubeIndex:n=1,startOn:s="left-center"}=e||{},c=Math.max(1,Math.min(24,Number(i)||12)),a=14,l=4,p=1,m=2,b=20,y=c*a+(c-1)*l,H=Math.max(60,y+p*2+m*2),v=ae((n-1)%12+1),I=`tube-${n}`,w=18,_={width:w,height:w,borderRadius:"50%",opacity:.25,pointerEvents:"auto",background:v,backgroundColor:v,border:`2px solid ${v}`,"--fiber-bg":v},L=()=>s==="left"?reactflow.Position.Left:s==="right"?reactflow.Position.Right:reactflow.Position.Bottom,z=()=>{let h=[],R=H-m*2-p*2,N,$,T=false;s==="left"?(N=p,$=reactflow.Position.Top):s==="right"?(N=p+R-y,$=reactflow.Position.Top,T=true):(N=p+(R-y)/2,$=reactflow.Position.Top);for(let M=0;M<c;M++){let C=T?c-M:M+1,P=_e(C),F=ae(C),Y=N+M*(a+l),j=p,D=P.backgroundImage?P.backgroundImage:F,G={position:"absolute",left:`${Y}px`,top:`${j}px`,width:a,height:a,borderRadius:"50%",border:"none",background:D,backgroundColor:F,zIndex:10,cursor:"pointer","--fiber-bg":F};P.backgroundImage&&(G["--fiber-bg-image"]=P.backgroundImage);let E=`fiber-${C}`;h.push(jsxRuntime.jsxs(or__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:E,type:"target",position:$,className:"tube-fiber-handle",isConnectable:true,style:G,"data-fiber-idx":C,"data-fiber-color":F}),jsxRuntime.jsx(reactflow.Handle,{id:E,type:"source",position:$,className:"tube-fiber-handle",isConnectable:true,style:G,"data-fiber-idx":C,"data-fiber-color":F})]},`fiber-${C}`));}return h};return jsxRuntime.jsxs("div",{style:{width:H,height:b,borderRadius:4,background:"#111827",border:`${m}px solid ${r?"#3b82f6":v}`,position:"relative",boxShadow:r?`0 0 0 ${m}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:p,boxSizing:"border-box"},children:[z(),jsxRuntime.jsx(reactflow.Handle,{id:I,type:"target",position:L(),isConnectable:true,style:_,"data-tube-idx":n,"data-tube-color":v}),jsxRuntime.jsx(reactflow.Handle,{id:I,type:"source",position:L(),isConnectable:true,style:_,"data-tube-idx":n,"data-tube-color":v})]})};var Rt=({data:e,selected:r})=>{let{tubeCount:o=12,fibersPerTube:i=12,fiberCount:n,cableId:s="CBL-002",label:c,tubeStartIndex:a=1,borderStyle:l="default"}=e||{},p=Math.max(1,Math.min(24,Number(o)||12)),m=Math.max(1,Number(a)||1),b=8,y=2,H=6,v=H+b+4,I=60,w=Math.max(120,p*(b+y)+H*2),_=n??p*(Number(i)||12),L=c??`${_}f Cable`,z=s?`Cable ID ${s}`:void 0,h=ae(m),R=r?"#3b82f6":h,x=false;l==="black"?R=r?"#3b82f6":"#000000":l==="black-yellow-striped"&&(R=r?"#3b82f6":"#000000",x=!r);let N=()=>{let M=[];for(let C=0;C<p;C++){let P=m+C,F=_e(P),Y=ae(P),j=H+C*(b+y),D=-4,G=F.backgroundImage?F.backgroundImage:Y,E={position:"absolute",left:`${j}px`,top:`${D}px`,width:b,height:b,borderRadius:"50%",border:"none",background:G,backgroundColor:Y,zIndex:10,cursor:"pointer","--fiber-bg":Y};F.backgroundImage&&(E["--fiber-bg-image"]=F.backgroundImage);let le=`tube-${P}`;M.push(jsxRuntime.jsxs(or__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:le,type:"target",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:E,"data-fiber-idx":P,"data-tube-idx":P,"data-tube-color":Y}),jsxRuntime.jsx(reactflow.Handle,{id:le,type:"source",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:E,"data-fiber-idx":P,"data-tube-idx":P,"data-tube-color":Y})]},`tube-${P}`));}return M},$=2,T=jsxRuntime.jsxs("div",{style:{width:"100%",height:"100%",borderRadius:x?2:4,background:"#111827",position:"relative",padding:H,paddingTop:v,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[N(),jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:L}),z&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:z})]});return x?jsxRuntime.jsx("div",{style:{width:w,height:I,borderRadius:4,background:"repeating-linear-gradient(45deg, #000000 0 6px, #ffdf00 6px 9px)",padding:$,boxSizing:"border-box",position:"relative",boxShadow:r?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)"},children:T}):jsxRuntime.jsxs("div",{style:{width:w,height:I,borderRadius:4,background:"#111827",border:`${$}px solid ${R}`,position:"relative",boxShadow:r?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:H,paddingTop:v,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[N(),jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:L}),z&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:z})]})};function nr(e,r){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let o=r.edges.some(w=>w.source===e.source&&w.sourceHandle===e.sourceHandle),i=r.edges.some(w=>w.target===e.target&&w.targetHandle===e.targetHandle);if(o)return {valid:false,reason:"Source port is already connected"};if(i)return {valid:false,reason:"Target port is already connected"};let n=e.sourceHandle,s=e.targetHandle,c=r.nodes.find(w=>w.id===e.source),a=r.nodes.find(w=>w.id===e.target),l=(w,_)=>{if(!w)return false;let L=w.startsWith("pwr")||w.startsWith("power"),z=_?.type==="vertical-pdu"&&w!=="mgmt-net-1";return L||z},p=(w,_)=>{if(!w)return false;if(_?.type==="vertical-pdu"&&w==="mgmt-net-1"||_?.type==="tube"&&w.startsWith("fiber-")||(_?.type==="tube"||_?.type==="cable")&&w.startsWith("tube-")||_?.type==="splice"&&(w==="left"||w==="right"))return true;let L=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("Fiber")||w.includes("Ports"),z=/^[A-Z0-9]+-\d+$/.test(w)&&!w.startsWith("pwr")&&!w.startsWith("power");return L||z},m=l(n,c),b=l(s,a),y=p(n,c),H=p(s,a);if(m&&H||b&&y)return {valid:false,reason:"Cannot connect network cable to power port"};if(m&&!b||b&&!m)return {valid:false,reason:"Power ports must connect to power-compatible ports"};let v=c?.type==="vertical-pdu",I=a?.type==="vertical-pdu";if(m||b){let w=v?a:I?c:null,_=v?c:I?a:null;if(w&&_&&r.edges.filter(h=>{let R=l(h.sourceHandle||""),x=l(h.targetHandle||""),N=h.source===w.id||h.target===w.id;return (R||x)&&N}).some(h=>h.source===_.id||h.target===_.id))return {valid:false,reason:"Dual-feed required: connect second power to a different PDU"}}return {valid:true}}function Je(e,r){if(!r)return;let o=typeof e=="string"?e.replace(/-(target|source)$/i,""):e,i=r.data??{},n=i.handleSideMap;if(n&&n[o])return n[o];if(o==="net-top"||o==="net-bottom")return "front";if(o==="pwr-left-1"||o==="pwr-left-2"||o==="net-right-1"||o==="net-right-2")return "rear";let s=Array.isArray(i.ports)?i.ports:[],c=Array.isArray(i.rearPorts)?i.rearPorts:[];if(o.startsWith("pwr")||o.includes("power"))return "rear";for(let l of s)for(let p of l.ports||[])if((!!p.type&&String(p.type).includes("power")?p.label:`${l.name}-${p.label}`)===o)return "front";for(let l of c)for(let p of l.ports||[])if((!!p.type&&String(p.type).includes("power")?p.label:`${l.name}-${p.label}`)===o)return "rear"}function Dt(e={},r={}){let o={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},i=new Set;return {getState:()=>o,setState:b=>{o={...o,...b},i.forEach(y=>y(o));},subscribe:b=>(i.add(b),()=>i.delete(b)),selectEdgeZIndex:b=>{let y=o.nodes.find(R=>R.id===b.target);if(!y||y.type!=="device")return 1e3;let H=y.data?.view||"front",v=Je(b.targetHandle||"",y);if(v)return H===v?1e3:500;let I=(b.targetHandle||"").toString(),w=I.toLowerCase(),_=w.startsWith("pwr")||w.startsWith("power"),L=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("fiber")||w.includes("ports"),z=/^[A-Z0-9]+-\d+$/i.test(I)&&!w.startsWith("pwr")&&!w.startsWith("power"),h=L||z;return _?H==="rear"?1e3:500:h?H==="front"?1e3:500:1e3},validateConnection:b=>(r.validateConnection||nr)(b,o),selectNodeById:b=>o.nodes.find(y=>y.id===b),selectConnectedEdges:b=>o.edges.filter(y=>y.source===b||y.target===b)}}function ir(e){let r=n=>e.subscribe(n),o=()=>e.getState();return or.useSyncExternalStore(r,o,o)}function It(e){let r=i=>e.subscribe(i),o=()=>e.getState().nodes;return or.useSyncExternalStore(r,o,o)}function $t(e){let r=i=>e.subscribe(i),o=()=>e.getState().edges;return or.useSyncExternalStore(r,o,o)}function co(e){return e.selectEdgeZIndex}function lo(e){let r=300,o=(e.data.uHeight||42)*20,i=e.position.x,n=e.position.x+r,s=e.position.y,c=e.position.y+o;return {left:i,right:n,top:s,bottom:c}}function Qe(e,r){let o=lo(r);return e.x>=o.left&&e.x<=o.right&&e.y>=o.top&&e.y<=o.bottom}function et(e,r){let o=null,i=1/0;for(let n of r){if(!Qe(e,n))continue;let s=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));s<i&&(i=s,o=n);}return o}function q(e){let{edges:r,connection:o,edgeType:i,selectEdgeZIndex:n,findBy:s,data:c}=e,a=s==="source"?o.sourceHandle:o.targetHandle,l=s==="source"?o.source:o.target;if(!a||!l)return null;let p=r.find(I=>s==="source"?I.source===l&&I.sourceHandle===a:I.target===l&&I.targetHandle===a);if(!p)return null;let m=r.filter(I=>I.id!==p.id),b=reactflow.addEdge(o,m),y=b[b.length-1],H=n({...o,id:y.id,type:i}),v={...y,type:i,zIndex:H,style:{...y.style,zIndex:H},data:c!==void 0?c:y.data};return [...b.slice(0,-1),v]}var xr=(e,r,o)=>({rack:i=>jsxRuntime.jsx(st,{...i,onViewChange:e,onRackFaceChange:r,isDragOver:o?o()===i.id:false}),fiber:at,device:ft,"vertical-pdu":bt,splice:yt,"splice-tray":St,tube:Ct,cable:Rt}),Nr={fiber:ct,power:lt,smoothstep:jt,step:Kt},wr=({nodes:e,edges:r,initialNodes:o,initialEdges:i,onNodesChange:n,onEdgesChange:s,store:c,debug:a,onNodeClick:l,onEdgeClick:p,onViewChange:m,onRackFaceChange:b,className:y,style:H,alignRacksToBottom:v,colorMode:I="dark",onInit:w,onFlowMethods:_,showDownloadButton:L=false,downloadButtonPosition:z="top-right",downloadButtonText:h="Download Image",downloadButtonStyle:R,allowReconnectExisting:x=false,useSmoothstepEdgesForTubes:N=false})=>{let $=Array.isArray(e)&&Array.isArray(r),T=or__default.default.useMemo(()=>c||Dt({nodes:$?e||[]:o||e||[],edges:$?r||[]:i||r||[],debug:a}),[c,$,a]),M=It(T),C=$t(T),[P,F,Y]=reactflow.useNodesState(M),[j,D,G]=reactflow.useEdgesState(C),E=co(T),le=or.useRef(null),{toObject:Ae,setViewport:ue,setNodes:ge,setEdges:We,getNodes:Pe}=reactflow.useReactFlow();or.useEffect(()=>{_&&_({toObject:Ae,setViewport:ue,setNodes:t=>{ge(t),T.setState({nodes:t});},setEdges:t=>{We(t),T.setState({edges:t});},toImage:t=>le.current?htmlToImage.toPng(le.current,t):Promise.reject(new Error("ReactFlow wrapper not available"))});},[_,Ae,ue,ge,We,T]);let tt=or.useCallback(()=>{if(!le.current){a&&console.error("ReactFlow wrapper ref is not available");return}htmlToImage.toPng(le.current,{filter:t=>!(t?.classList?.contains("react-flow__minimap")||t?.classList?.contains("react-flow__controls")||t?.classList?.contains("react-flow__attribution")||t?.classList?.contains("download-button")||t?.tagName==="BUTTON"),backgroundColor:I==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(t=>{let d=document.createElement("a");d.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,d.href=t,d.click();}).catch(t=>{a&&console.error("Error downloading image:",t);});},[I,a]),[fe,Ue]=or.useState(null),Ut=or.useRef(null),zt=or.useRef(m),Ot=or.useRef(b);or.useEffect(()=>{zt.current=m;},[m]),or.useEffect(()=>{Ot.current=b;},[b]),or.useEffect(()=>{Ut.current=fe;},[fe]);let yo=or.useRef(()=>Ut.current),xo=or.useMemo(()=>xr((t,d)=>zt.current?.(t,d),(t,d)=>Ot.current?.(t,d),yo.current),[]),No=or.useMemo(()=>Nr,[]),pe=or.useRef(P);or.useEffect(()=>{pe.current=P;},[P]);let U=or.useRef(j);or.useEffect(()=>{U.current=j;},[j]),or.useEffect(()=>{F(M);},[M,F]),or.useEffect(()=>{D(C);},[C,D]),or.useEffect(()=>{$&&T.setState({nodes:e||[]});},[$,e,T]),or.useEffect(()=>{$&&T.setState({edges:r||[]});},[$,r,T]),or.useEffect(()=>{if(!v||!P||P.length===0)return;let t=P.filter(A=>A.type==="rack");if(t.length===0)return;let d=t.map(A=>{let ie=A.data?.uHeight||42,X=60+ie*20;return (A.position?.y||0)+X}),g=Math.min(...d),f=Math.max(...d);if(f-g<20)return;let u=f,W=P.map(A=>{if(A.type!=="rack")return A;let ie=A.data?.uHeight||42,X=60+ie*20,V=(A.position?.y||0)+X,Z=u-V;return Math.abs(Z)<5?A:{...A,position:{x:A.position?.x||0,y:(A.position?.y||0)+Z}}});W.some((A,ee)=>A.position!==P[ee].position)&&F(W);},[v,P,F]);let O=or.useCallback(t=>pe.current.find(d=>d.id===t),[]),ze=or.useCallback((t,d)=>{if(!t||!d)return;let g=O(t);if(!g)return;if(g.type==="tube"&&d.startsWith("fiber-")){let k=d.replace("fiber-",""),u=parseInt(k,10);if(u>=1&&u<=24){let W=Ht(u),B=u>12;return {color:W,striped:B}}}if((g.type==="cable"||g.type==="tube")&&d.startsWith("tube-")){let k=d.replace("tube-",""),u=parseInt(k,10);if(u>=1&&u<=24){let W=ae(u),B=u>12;return {color:W,striped:B}}}let f=g.data;if(f.color)return {color:f.color}},[O]);or.useEffect(()=>{D(t=>t.map(d=>{let g=E(d);return {...d,zIndex:g,style:{...d.style,zIndex:g}}}));},[P,D,E]),or.useEffect(()=>{let t=P.map(g=>{if(g.type==="splice"&&g.parentId&&g.data.holderPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let f=O(g.parentId);if(f&&f.type==="splice-tray"){let k=Fe(f,g.data.holderPosition);return {...g,position:k}}}if(g.type==="device"&&g.parentId&&g.data.uPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let f=O(g.parentId);if(f){let k=He(f,g.data.uPosition);return {...g,position:k}}}return g});t.some((g,f)=>g.position!==P[f].position)&&F(t);},[P,F,O]);let wo=or.useCallback(t=>{let d=t.map(g=>{if(g.type==="position"&&g.position){let f=O(g.id);if(f&&f.type==="splice"&&f.parentId){let k=O(f.parentId);if(k&&k.type==="splice-tray"){let u=kt(f,k,g.position,pe.current);if(u.holderPosition!==void 0){let W={...f,data:{...f.data,holderPosition:u.holderPosition}};F(B=>B.map(A=>A.id===f.id?W:A));}return {...g,position:{x:u.x,y:u.y}}}}if(f&&f.type==="device"&&f.parentId){let k=O(f.parentId);if(k){let u=nt(f,k,g.position,pe.current);if(u.uPosition!==void 0){let W={...f,data:{...f.data,uPosition:u.uPosition}};F(B=>B.map(A=>A.id===f.id?W:A));}return {...g,position:{x:u.x,y:u.y}}}}if(f&&f.type==="device"&&f.parentId){let k=O(f.parentId);if(k){let u=k;if(!Qe(g.position,u)){let W=g.position.x+u.position.x,B=g.position.y+u.position.y,A={...f,parentId:void 0,extent:void 0,data:{...f.data,uPosition:void 0}};return F(ee=>ee.map(ie=>ie.id===f.id?A:ie)),{...g,position:{x:W,y:B}}}}}}return g});Y(d);},[Y,F,O]),ko=or.useCallback((t,d)=>{Ue(null);},[]),vo=or.useCallback((t,d,g)=>{if(d.type==="device"&&!d.parentId){let f=pe.current.filter(u=>u.type==="rack").map(u=>u),k=et(d.position,f);Ue(k?.id??null);}else Ue(null);},[]),Po=or.useCallback((t,d,g)=>{if(d.type==="device"&&!d.parentId){let f=pe.current.filter(u=>u.type==="rack").map(u=>u),k=et(d.position,f);if(k){let u=d.position.x-k.position.x,W=d.position.y-k.position.y,B={...d,parentId:k.id,extent:"parent",position:{x:u,y:W},data:{...d.data,uPosition:1}},A=pe.current.map(ee=>ee.id===d.id?B:ee);F(A),$||T.setState({nodes:A});}}Ue(null);},[F,$,T]),So=or.useCallback(t=>{if(!t.source||!t.target||!t.sourceHandle||!t.targetHandle)return true;let d=O(t.source),g=O(t.target);if(d?.type==="tube"&&g?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&t.targetHandle.startsWith("fiber-"))return a&&console.log("Connection rejected: Cannot connect fibres within tubes",t),false;if(d?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&(g?.type==="cable"||g?.type==="tube")&&t.targetHandle.startsWith("tube-"))return a&&console.log("Connection rejected: Cannot connect individual fibre to cable/tube tube handle",t),false;if((d?.type==="cable"||d?.type==="tube")&&t.sourceHandle.startsWith("tube-")&&g?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return a&&console.log("Connection rejected: Cannot connect cable/tube tube handle to individual fibre",t),false;if(g?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right"))return U.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle||u.source===t.target&&u.sourceHandle===t.targetHandle)?(a&&console.log("Splice handle already connected, will replace",t),true):(a&&console.log("Allowing connection to splice handle",t),true);if(d?.type==="tube"&&t.sourceHandle.startsWith("fiber-"))return g?.type!=="splice"?(a&&console.log("Connection rejected: Tube fiber handles can only connect to splices",t),false):U.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(a&&console.log("Tube fiber handle already connected, will replace",t),true):(a&&console.log("Allowing connection from tube fiber handle to splice",t),true);if((d?.type==="cable"||d?.type==="tube")&&t.sourceHandle.startsWith("tube-"))return t.targetHandle.startsWith("tube-")?U.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(a&&console.log("Tube-level handle already connected, will replace",t),true):(a&&console.log("Allowing connection from tube-level handle to tube handle",t),true):(a&&console.log("Connection rejected: Tube handles can only connect to other tube handles",t),false);if(d?.type==="splice"&&t.sourceHandle==="right")return U.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle||u.target===t.source&&u.targetHandle===t.sourceHandle)&&a&&console.log("Splice source handle already connected, will replace",t),true;if(g?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return d?.type!=="splice"?(a&&console.log("Connection rejected: Tube fiber handles can only connect from splices",t),false):U.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(a&&console.log("Tube fiber target handle already connected, will replace",t),true):(a&&console.log("Allowing connection from splice to tube fiber handle",t),true);if((g?.type==="cable"||g?.type==="tube")&&t.targetHandle.startsWith("tube-"))return t.sourceHandle.startsWith("tube-")?U.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(a&&console.log("Tube-level target handle already connected, will replace",t),true):(a&&console.log("Allowing connection from tube handle to tube-level handle",t),true):(a&&console.log("Connection rejected: Tube handles can only connect from other tube handles",t),false);let f=T.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!f.valid&&x){if(t.source&&t.sourceHandle&&U.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return a&&console.log("Source handle has existing edge, will replace",t),true;if(t.target&&t.targetHandle&&U.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return a&&console.log("Target handle has existing edge, will replace",t),true}return a&&!f.valid&&console.log("Connection rejected by store validation:",f.reason,t),f.valid},[O,T,a,x]),Ho=or.useCallback(t=>{let d=O(t.source),g=O(t.target),f=d?.type==="vertical-pdu",k=d?.data,u=d?.type==="device"&&k?.deviceType==="switch",W=!!t.targetHandle&&(t.targetHandle.startsWith("pwr")||t.targetHandle.startsWith("power")),B=!!t.targetHandle&&(t.targetHandle.startsWith("net-")||t.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(t.targetHandle)),A=d?.type==="tube"&&g?.type==="cable",ee=d?.type==="cable"&&g?.type==="tube",ie=A||ee,X;f&&W?X="power":ie?X=N?"smoothstep":"fiber":X="fiber";let V;if((X==="fiber"||X==="smoothstep")&&!f){let S=ze(t.source,t.sourceHandle);S&&(V={color:S.color,striped:S.striped});}if(g?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")&&t.target&&t.targetHandle){let S=q({edges:U.current,connection:t,edgeType:"fiber",selectEdgeZIndex:E,findBy:"target",data:V});if(S){D(S);return}if(t.targetHandle==="right"&&(S=q({edges:U.current,connection:t,edgeType:"fiber",selectEdgeZIndex:E,findBy:"source",data:V}),S)){D(S);return}}if(d?.type==="splice"&&t.sourceHandle==="right"&&t.source&&t.sourceHandle){let S=q({edges:U.current,connection:t,edgeType:"fiber",selectEdgeZIndex:E,findBy:"source",data:V});if(S){D(S);return}if(S=q({edges:U.current,connection:t,edgeType:"fiber",selectEdgeZIndex:E,findBy:"target",data:V}),S){D(S);return}}if(d?.type==="tube"&&t.sourceHandle?.startsWith("fiber-")&&t.source&&t.sourceHandle){let S=q({edges:U.current,connection:t,edgeType:"fiber",selectEdgeZIndex:E,findBy:"source",data:V});if(S){D(S);return}}if(g?.type==="tube"&&t.targetHandle?.startsWith("fiber-")&&t.target&&t.targetHandle){let S=q({edges:U.current,connection:t,edgeType:"fiber",selectEdgeZIndex:E,findBy:"target",data:V});if(S){D(S);return}}if((d?.type==="cable"||d?.type==="tube")&&t.sourceHandle?.startsWith("tube-")&&t.source&&t.sourceHandle){let S=q({edges:U.current,connection:t,edgeType:X,selectEdgeZIndex:E,findBy:"source",data:V});if(S){D(S);return}}if((g?.type==="cable"||g?.type==="tube")&&t.targetHandle?.startsWith("tube-")&&t.target&&t.targetHandle){let S=q({edges:U.current,connection:t,edgeType:X,selectEdgeZIndex:E,findBy:"target",data:V});if(S){D(S);return}}if(f&&W&&t.target&&t.targetHandle){let S=q({edges:U.current,connection:t,edgeType:"power",selectEdgeZIndex:E,findBy:"target",data:V});if(S){D(S);return}}if(u&&B&&t.target&&t.targetHandle){let S=q({edges:U.current,connection:t,edgeType:"fiber",selectEdgeZIndex:E,findBy:"target",data:V});if(S){D(S);return}}let Z=T.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!Z.valid){if(x){if(t.source&&t.sourceHandle){let S=q({edges:U.current,connection:t,edgeType:X,selectEdgeZIndex:E,findBy:"source",data:V});if(S){D(S);return}}if(t.target&&t.targetHandle){let S=q({edges:U.current,connection:t,edgeType:X,selectEdgeZIndex:E,findBy:"target",data:V});if(S){D(S);return}}}if(f&&t.source&&t.sourceHandle){let S=q({edges:U.current,connection:t,edgeType:W?"power":"fiber",selectEdgeZIndex:E,findBy:"source",data:V});if(S){D(S);return}}if(u&&t.source&&t.sourceHandle){let S=q({edges:U.current,connection:t,edgeType:"fiber",selectEdgeZIndex:E,findBy:"source",data:V});if(S){D(S);return}}a&&console.warn(`Connection rejected: ${Z.reason}`);return}let Ie={...t,type:X,zIndex:E({...t,id:"temp-id"}),data:V};D(S=>{let Oe=reactflow.addEdge(Ie,S),oe=Oe[Oe.length-1];return oe&&(Mt(rt=>new Set(rt).add(oe.id)),setTimeout(()=>{Mt(rt=>{let Lt=new Set(rt);return Lt.delete(oe.id),Lt});},1e3)),Oe});},[D,T,E,O,a,ze,x,N]),Co=or.useCallback((t,d)=>{if(!d.source||!d.target||!d.sourceHandle||!d.targetHandle)return;let g=t.sourceHandle||"",f=t.targetHandle||"",k=d.sourceHandle||"",u=d.targetHandle||"";if(g.startsWith("tube-")&&k!==g){a&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:d});return}if(f.startsWith("tube-")&&u!==f){a&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:d});return}let W=O(d.source),B=O(d.target),A=W?.type==="vertical-pdu",ee=!!d.targetHandle&&(d.targetHandle.startsWith("pwr")||d.targetHandle.startsWith("power")),ie=W?.type==="tube"&&B?.type==="cable",X=W?.type==="cable"&&B?.type==="tube",V=ie||X,Z;A&&ee?Z="power":V?Z=N?"smoothstep":"fiber":Z="fiber";let Ie;if((Z==="fiber"||Z==="smoothstep")&&!A){let S=ze(d.source,d.sourceHandle);S&&(Ie={color:S.color,striped:S.striped});}D(S=>S.map(oe=>oe.id===t.id?{...oe,source:d.source,target:d.target,sourceHandle:d.sourceHandle,targetHandle:d.targetHandle,type:Z,data:Ie!==void 0?{...oe.data,...Ie}:oe.data,zIndex:E({...d,id:oe.id,type:Z}),style:{...oe.style,zIndex:E({...d,id:oe.id,type:Z})}}:oe));},[D,O,ze,E,N]),Eo=or.useCallback((t,d)=>{let g=t.metaKey||t.ctrlKey;if(d.type==="tube"&&d.parentId&&!g){let k=Pe().find(u=>u.id===d.parentId&&u.type==="cable");if(k){F(u=>u.map(W=>({...W,selected:W.id===k.id}))),l&&l(k);return}}if(g&&d.type==="device"){let f=d.data||{},k=f.view||(Array.isArray(f.rearPorts)&&f.rearPorts.length>0?"rear":"front"),u=k==="front"?"rear":"front";a&&console.log(`Command+click: Toggling device ${d.id} from ${k} to ${u}`),m&&m(d.id,u),l&&l(d);}else l&&l(d);},[m,l,a,Pe,F]),Ro=or.useCallback(()=>{},[]),Do=or.useCallback((t,d)=>{p&&p(d);},[p]),[ce,ot]=or.useState(null),[Bt,Mt]=or.useState(new Set);reactflow.useOnSelectionChange({onChange:({nodes:t})=>{if(t&&t.length===1){let d=t[0];if(d.type==="tube"&&d.parentId){let f=Pe().find(k=>k.id===d.parentId&&k.type==="cable");if(f){ot(f),F(k=>k.map(u=>({...u,selected:u.id===f.id}))),l&&l(f);return}}ot(d),l&&l(d);}else ot(null),l&&l(null);}});let To=or.useCallback((t,{nodeId:d,handleType:g})=>{a&&console.log("Connection started from",{nodeId:d,handleType:g});},[a]),Io=or.useCallback(t=>{a&&console.log("Connection ended",t);},[a]),$o=or.useCallback(()=>{if(!ce)return;let t=O(ce.id);if(t){if(t.type==="rack"){let f=((t.data||{}).face||"front")==="front"?"rear":"front";b?(b(t.id,f),m&&Pe().filter(u=>u.parentId===t.id).forEach(u=>{m(u.id,f);})):F(k=>k.map(u=>u.id===t.id?{...u,data:{...u.data,face:f}}:u.parentId===t.id?{...u,data:{...u.data,view:f}}:u));return}if(t.type==="device"){let d=t.data||{},g=Array.isArray(d.rearPorts)&&d.rearPorts.length>0,f=Array.isArray(d.ports)&&d.ports.length>0,u=(d.view||(g&&!f?"rear":"front"))==="front"?"rear":"front";m?m(t.id,u):F(W=>W.map(B=>B.id===t.id?{...B,data:{...B.data,view:u}}:B));}}},[ce,O,b,m,F]),Fo=or.useMemo(()=>j.map(t=>{let d=t,g=O(String(d.source)),f=O(String(d.target)),k=Je(d.sourceHandle||"",g),u=Je(d.targetHandle||"",f),W=g&&g.data?.view,B=f&&f.data?.view,A=g?.type==="device"&&W==="rear",ee=f?.type==="device"&&B==="rear",Z=A&&k!=="rear"&&(ee&&u!=="rear")?{...t.style,opacity:0,pointerEvents:"none",zIndex:0}:t.style;return {...t,style:Z,className:Bt.has(t.id)?"edge-connecting":t.className}}),[j,Bt,O]);return jsxRuntime.jsxs("div",{ref:le,className:`${y||""} ${I==="light"?"react-flow-light":"react-flow-dark"}`,style:{width:"100%",height:"100%",...H},children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:P,edges:Fo,onNodesChange:t=>{wo(t),$?n&&n(pe.current):T.setState({nodes:pe.current});},onEdgesChange:t=>{let d=t.filter(g=>{if(g.type==="remove"){let f=U.current.find(k=>k.id===g.id);if(f){let k=f.sourceHandle||"",u=f.targetHandle||"";if(k.startsWith("tube-")||u.startsWith("tube-"))return a&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",f),false}}return true});d.length>0&&(G(d),$?s&&s(U.current):T.setState({edges:U.current}));},onConnect:Ho,onConnectStart:To,onConnectEnd:Io,onEdgeUpdate:Co,isValidConnection:So,onNodeClick:Eo,onNodeDoubleClick:Ro,onNodeDragStart:ko,onNodeDrag:vo,onNodeDragStop:Po,onEdgeClick:Do,onInit:w,nodeTypes:xo,edgeTypes:No,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:true,nodesConnectable:true,elementsSelectable:true,selectNodesOnDrag:false,fitView:true,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{color:I==="light"?"#e5e5e5":"#2a2a2a"}),jsxRuntime.jsx(reactflow.Controls,{}),jsxRuntime.jsx(reactflow.MiniMap,{}),jsxRuntime.jsx(reactflow.Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsxRuntime.jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),L&&jsxRuntime.jsx("button",{className:"download-button",onClick:tt,style:{position:"absolute",top:z.includes("top")?"10px":"auto",bottom:z.includes("bottom")?"10px":"auto",right:z.includes("right")?"10px":"auto",left:z.includes("left")?"10px":"auto",zIndex:1e3,background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:"4px",padding:"0.5rem 0.75rem",fontSize:"0.875rem",cursor:"pointer",transition:"all 0.2s ease",...R},children:h}),ce&&(ce.type==="rack"||ce.type==="device")&&jsxRuntime.jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsxRuntime.jsx("button",{onClick:t=>{t.preventDefault(),$o();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let t=ce.data;if(ce.type==="rack")return (t?.face||"front")==="front"?"Switch to rear":"Switch to front";{let d=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,g=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(d&&!g?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let t=ce.data;if(ce.type==="rack")return (t?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let d=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,g=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(d&&!g?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()})})]})},kr=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(wr,{...e})});var go=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,uHeight:e.u_height??e.units??42,inventoryId:e.id,inventoryType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:typeof e.site=="object"&&e.site?e.site.name:e.site,role:typeof e.role=="object"&&e.role?e.role.name:e.role,tenant:typeof e.tenant=="object"&&e.tenant?e.tenant.name:e.tenant}}),fo=e=>({id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${typeof e.rack=="object"&&e.rack?e.rack.id:e.rack}`:void 0,extent:e.rack?"parent":void 0,data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,deviceType:e.device_type?.model??e.model,manufacturer:e.device_type?.manufacturer?.name??e.manufacturer,role:typeof e.device_role=="object"&&e.device_role?e.device_role.name:e.role,uHeight:e.device_type?.u_height??e.u_height??1,uPosition:e.position||1,view:e.face||"front",inventoryId:e.id,inventoryType:"device",primaryIp4:typeof e.primary_ip4=="object"&&e.primary_ip4?e.primary_ip4.address:e.primary_ip4,primaryIp6:typeof e.primary_ip6=="object"&&e.primary_ip6?e.primary_ip6.address:e.primary_ip6,site:typeof e.site=="object"&&e.site?e.site.name:e.site,rack:typeof e.rack=="object"&&e.rack?e.rack.name:e.rack}}),bo=e=>{let r=n=>{if(!n)return;if(typeof n=="string")return n;let s=n.device;return typeof s=="object"&&s?s.id:s},o=r(e.termination_a),i=r(e.termination_b);return {id:`cable-${e.id}`,source:`device-${o}`,target:`device-${i}`,type:"fiber",data:{bandwidth:e.type?.label??e.bandwidth,length:e.length||0,color:e.color,inventoryId:e.id,inventoryType:"cable",status:typeof e.status=="object"&&e.status?e.status.value:e.status,terminationA:typeof e.termination_a=="object"&&e.termination_a?e.termination_a.name:e.termination_a,terminationB:typeof e.termination_b=="object"&&e.termination_b?e.termination_b.name:e.termination_b}}},vr=e=>{let r=[],o=[];return e.racks.forEach(i=>r.push(go(i))),e.devices.forEach(i=>r.push(fo(i))),e.cables.forEach(i=>o.push(bo(i))),{nodes:r,edges:o}},Pr=e=>{let r=e.filter(n=>n.type==="rack"),o=e.filter(n=>n.type==="device"),i=e.filter(n=>!["rack","device"].includes(n.type));return r.forEach((n,s)=>{n.position={x:s*300,y:100};}),o.forEach(n=>{if(n.parentId){let s=r.find(c=>c.id===n.parentId);if(s){let c=n.data.uPosition||1,a=n.data.uHeight||1;n.position={x:s.position.x+50,y:s.position.y+c*20-a*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),i.forEach((n,s)=>{n.position={x:s*150+100,y:300};}),e};var De=class extends Error{constructor(o,i,n,s,c){super(`Device placement conflict: ${i} at U${n}-${n+s-1} in rack ${o}${c?` conflicts with ${c}`:""}`);this.rackId=o;this.deviceId=i;this.uPosition=n;this.uHeight=s;this.conflictWith=c;this.name="DevicePlacementError";}};function At(e,r={}){let o=[],i=[];for(let n of e.devices)n.unit+n.height-1>e.units&&i.push({deviceId:n.id,uPosition:n.unit,uHeight:n.height,rackUHeight:e.units});for(let n=0;n<e.devices.length;n++){let s=e.devices[n],c=s.unit,a=s.unit+s.height-1;for(let l=n+1;l<e.devices.length;l++){let p=e.devices[l],m=p.unit,b=p.unit+p.height-1;c<=b&&a>=m&&o.push({deviceId:s.id,uPosition:s.unit,uHeight:s.height,conflictWith:p.id});}}return {isValid:o.length===0&&i.length===0,conflicts:o,outOfBounds:i}}function mo(e,r,o={}){let{deviceTypeMapping:i={}}=o,n=i[e.type]||"device",s=He(r,e.unit,e.height);return {id:e.id,type:n,position:s,parentId:r.id,extent:"parent",data:{label:e.name,status:"active",deviceType:e.type,uHeight:e.height,uPosition:e.unit,width:e.width||"full",role:e.role,ports:e.ports,rearPorts:e.rearPorts,connections:e.connections}}}function Sr(e){return {id:e.id,type:"rack",position:e.position,data:{label:e.name,status:"active",uHeight:e.units,uNumberingDirection:e.uNumberingDirection||"bottom-up",customHeaderText:e.customHeaderText,ports:[]}}}function Hr(e,r={}){let{conflictPolicy:o="strict",validatePlacements:i=true}=r,n=[],s=[];if(i)for(let c of e){let a=At(c,r);if(!a.isValid&&o==="strict"){let l=[];throw a.conflicts.forEach(p=>{l.push(`Device ${p.deviceId} at U${p.uPosition}-${p.uPosition+p.uHeight-1} conflicts with ${p.conflictWith}`);}),a.outOfBounds.forEach(p=>{l.push(`Device ${p.deviceId} at U${p.uPosition}-${p.uPosition+p.uHeight-1} exceeds rack height (${p.rackUHeight}U)`);}),new De(c.id,a.conflicts[0]?.deviceId||a.outOfBounds[0]?.deviceId||"unknown",a.conflicts[0]?.uPosition||a.outOfBounds[0]?.uPosition||1,a.conflicts[0]?.uHeight||a.outOfBounds[0]?.uHeight||1)}}for(let c of e){let a=Sr(c);n.push(a);for(let l of c.devices)try{let p=mo(l,a,r);s.push(p);}catch(p){if(o==="strict")throw p;if(o==="nearest"){let m=Le(a,{id:l.id,data:{label:l.name,uHeight:l.height}},s,l.unit);if(m!==l.unit){console.warn(`Device ${l.id} moved from U${l.unit} to U${m} due to conflict`);let b={...l,unit:m},y=mo(b,a,r);s.push(y);}else throw new De(c.id,l.id,l.unit,l.height)}}}return n.push(...s),n}function Cr(e){let r=[],o=e.filter(i=>i.type==="rack");for(let i of o){let s=e.filter(c=>c.type==="device"&&c.parentId===i.id).map(c=>({id:c.id,name:c.data.label,unit:c.data.uPosition||1,height:c.data.uHeight||1,type:c.data.deviceType||"server",width:c.data.width,ports:c.data.ports,connections:c.data.connections}));r.push({id:i.id,name:i.data.label,position:i.position,units:i.data.uHeight||42,uNumberingDirection:i.data.uNumberingDirection||"bottom-up",customHeaderText:i.data.customHeaderText,devices:s});}return r}function Er(e,r,o,i){return e.map(n=>n.id!==r?n:{...n,devices:n.devices.map(s=>s.id!==o?s:{...s,unit:i})})}function Rr(e,r,o,i={}){let{conflictPolicy:n="strict"}=i;return e.map(s=>{if(s.id!==r)return s;if(n==="strict"&&!At({...s,devices:[...s.devices,o]},i).isValid)throw new De(r,o.id,o.unit,o.height);return {...s,devices:[...s.devices,o]}})}function Dr(e,r,o){return e.map(i=>i.id!==r?i:{...i,devices:i.devices.filter(n=>n.id!==o)})}var Te=class extends Error{constructor(o,i,n,s){super(`Splice placement conflict: ${i} at holder ${n} in tray ${o}${s?` conflicts with ${s}`:""}`);this.trayId=o;this.spliceId=i;this.holder=n;this.conflictWith=s;this.name="SplicePlacementError";}};function Wt(e,r={}){let o=[],i=[];for(let n of e.splices)(n.holder<1||n.holder>ye)&&i.push({spliceId:n.id,holder:n.holder,max:ye});for(let n=0;n<e.splices.length;n++){let s=e.splices[n];for(let c=n+1;c<e.splices.length;c++){let a=e.splices[c];s.holder===a.holder&&o.push({spliceId:s.id,holder:s.holder,conflictWith:a.id});}}return {isValid:o.length===0&&i.length===0,conflicts:o,outOfBounds:i}}function ho(e,r){let o=Fe(r,e.holder);return {id:e.id,type:"splice",position:o,parentId:r.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb}}}function Tr(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Ir(e,r={}){let{conflictPolicy:o="strict",validatePlacements:i=true}=r,n=[],s=[];if(i)for(let c of e){let a=Wt(c,r);if(!a.isValid&&o==="strict"){let l=[];throw a.conflicts.forEach(p=>{l.push(`Splice ${p.spliceId} at holder ${p.holder} conflicts with ${p.conflictWith}`);}),a.outOfBounds.forEach(p=>{l.push(`Splice ${p.spliceId} at holder ${p.holder} is out of bounds (max: ${p.max})`);}),new Te(c.id,a.conflicts[0]?.spliceId||a.outOfBounds[0]?.spliceId||"unknown",a.conflicts[0]?.holder||a.outOfBounds[0]?.holder||1)}}for(let c of e){let a=Tr(c);n.push(a);for(let l of c.splices)try{let p=ho(l,a);s.push(p);}catch(p){if(o==="strict")throw p;if(o==="nearest"){let m=[...n,...s],b=Ze(a,{id:l.id,data:{label:l.name,holderPosition:l.holder}},m,l.holder);if(b!==l.holder){console.warn(`Splice ${l.id} moved from holder ${l.holder} to holder ${b} due to conflict`);let y={...l,holder:b},H=ho(y,a);s.push(H);}else throw new Te(c.id,l.id,l.holder)}}}return n.push(...s),n}function $r(e){let r=[],o=e.filter(i=>i.type==="splice-tray");for(let i of o){let s=e.filter(c=>c.type==="splice"&&c.parentId===i.id).map(c=>({id:c.id,name:c.data.label,holder:c.data.holderPosition||1,lossDb:c.data.lossDb}));r.push({id:i.id,name:i.data.label,position:i.position,splices:s});}return r}function Fr(e,r,o,i){return e.map(n=>n.id!==r?n:{...n,splices:n.splices.map(s=>s.id!==o?s:{...s,holder:i})})}function _r(e,r,o,i={}){let{conflictPolicy:n="strict"}=i;return e.map(s=>{if(s.id!==r)return s;if(n==="strict"&&!Wt({...s,splices:[...s.splices,o]},i).isValid)throw new Te(r,o.id,o.holder);return {...s,splices:[...s.splices,o]}})}function Ar(e,r,o){return e.map(i=>i.id!==r?i:{...i,splices:i.splices.filter(n=>n.id!==o)})}
|
|
2
|
-
exports.CableNode=
|
|
1
|
+
'use strict';var Or=require('react'),reactflow=require('reactflow'),htmlToImage=require('html-to-image'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Or__default=/*#__PURE__*/_interopDefault(Or);var mr=()=>"bottom-up",Pe=e=>e.data.uNumberingDirection||mr(),Xe=(e,o,r)=>r==="bottom-up"?o-e+1:e,je=(e,o,r)=>r==="bottom-up"?o-e+1:e;var mt=(e,o,r,a)=>{if(!e.parentId||e.parentId!==o.id)return r;let n=e.data.uHeight||1,i=o.data.uHeight||42,d=Pe(o),s=60,c=r.y-s,l=Math.round(c/20)+1,h;d==="bottom-up"?h=Xe(l,i,d)-n+1:h=Xe(l,i,d);let f=i-n+1,m=Math.max(1,Math.min(f,h));if(d==="top-down"&&h<=1&&(m=1),!yt(o,e,m,a)){let k=Ge(o,e,a,m);k!==m&&(m=k);}let v;if(d==="bottom-up"){let k=m+n-1,E=je(k,i,d);v=s+(E-1)*20-1;}else {let k=je(m,i,d);v=s+(k-1)*20-1;}return {x:r.x,y:v,uPosition:m}},yt=(e,o,r,a)=>{let n=o.data.uHeight||1,i=e.data.uHeight||42;if(r<1||r+n-1>i)return false;let d=a.filter(s=>s.type==="device"&&s.parentId===e.id&&s.id!==o.id);for(let s of d){let c=s.data.uPosition||1,l=s.data.uHeight||1,h=r,f=r+n-1,m=c,v=c+l-1;if(h<=v&&f>=m)return false}return true},Ge=(e,o,r,a=1)=>{let n=o.data.uHeight||1,i=e.data.uHeight||42;for(let d=a;d<=i-n+1;d++)if(yt(e,o,d,r))return d;return 1},De=(e,o,r=1)=>{let a=60,n=Pe(e),i=e.data.uHeight||42,d=je(o,i,n),s;if(n==="bottom-up"){let c=o+r-1,l=je(c,i,n);s=a+(l-1)*20-1;}else s=a+(d-1)*20-1;return {x:0,y:s}},fo=(e,o,r)=>{let a=e.data.uHeight||1,n=De(o,r,a);return {...e,position:n,data:{...e.data,uPosition:r}}},yr=(e,o)=>{let r=e.data.uPosition||1,a=e.data.uHeight||1,n=o.data.uHeight||42,i=Math.max(1,Math.min(n-a+1,r));return i!==r?fo(e,o,i):e};function ce(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var xt=({data:e,selected:o,id:r,onViewChange:a,onRackFaceChange:n,isDragOver:i=false})=>{let{label:d,ports:s=0,status:c="active",uHeight:l=42,face:h="front",customHeaderText:f}=e,{getNodes:m,setNodes:v}=reactflow.useReactFlow(),k=m(),[E,w]=Or.useState(true),T=()=>{let H=Pe({data:e})==="bottom-up"?"top-down":"bottom-up";v(y=>y.map(P=>P.id===r?{...P,data:{...P.data,uNumberingDirection:H}}:P));},A=()=>{let x=h==="front"?"rear":"front";n?(n(r,x),a&&k.filter(y=>y.parentId===r).forEach(y=>{a(y.id,x);})):a?k.filter(y=>y.parentId===r).forEach(y=>{a(y.id,x);}):v(H=>H.map(y=>y.id===r?{...y,data:{...y.data,face:x}}:y.parentId===r?{...y,data:{...y.data,view:x}}:y));},W=()=>{let x=[],H=60,y=Pe({data:e});for(let P=1;P<=l;P++){let M=H+(P-1)*20-4,R=Xe(P,l,y);x.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:"-35px",top:`${M}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${20}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:R},P));}return x};return jsxRuntime.jsxs("div",{className:`rack-node ${o?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${ce(c)}`,borderRadius:"8px",padding:0,width:`${300}px`,height:`${60+l*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:i?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxRuntime.jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxRuntime.jsxs("span",{children:[typeof s=="number"?s:0," ports"]})," \u2022 ",l,"U \u2022 ",h]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),w(!E);},style:{background:E?"#10b981":"#374151",color:E?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${E?"Hide":"Show"} U markers`,children:"U"}),jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),T();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch U numbering to ${Pe({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Pe({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),A();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${h==="front"?"rear":"front"} view`,children:h==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"}}),E&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:W()})]})};var wt=({data:e,selected:o})=>{let{label:r,status:a="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${o?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${ce(a)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Top}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Bottom}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right}),jsxRuntime.jsx("div",{style:{textAlign:"center"},children:jsxRuntime.jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:r})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:ce(a),borderRadius:"50%"}})]})};var kt=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},className:h})=>{let[f,m,v]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),{bandwidth:k,length:E,color:w="#00FFFF",striped:T=false}=s||{},A={...l,stroke:w,strokeWidth:c?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:f,style:A}),T&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&s&&(k||E)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${m}px,${v}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${w}`,pointerEvents:"none",zIndex:9999},children:[k&&jsxRuntime.jsx("div",{children:k}),E&&jsxRuntime.jsxs("div",{children:[E,"m"]})]})})]})};var vt=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l})=>{let[h]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),f=c?.connectorType||"C13";return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:h,markerEnd:l,style:(()=>{let v={stroke:c?.color||"#f59e0b",strokeWidth:f==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...s};return f==="C19"?{...v,strokeDasharray:"none"}:{...v,strokeDasharray:"6,3"}})()})};var bo=({data:e,selected:o,style:r={},...a})=>{let{color:n="#00FFFF"}=e||{},i={...r,stroke:n,strokeWidth:o?4:3};return jsxRuntime.jsx(reactflow.SmoothStepEdge,{...a,data:e,selected:o,style:i})};function Dr({sourceX:e,sourceY:o,targetX:r,targetY:a,sourcePosition:n,targetPosition:i}){let d=n===reactflow.Position.Left||n===reactflow.Position.Right,s;if(d){let c=(e+r)/2;s=`M ${e},${o} L ${c},${o} L ${c},${a} L ${r},${a}`;}else {let c=(o+a)/2;s=`M ${e},${o} L ${e},${c} L ${r},${c} L ${r},${a}`;}return s}var xo=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},...h})=>{let{color:f="#00FFFF",striped:m=false}=s||{},v=Dr({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),k={...l,stroke:f,strokeWidth:c?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:v,style:k}),m&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var wo=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l,selected:h})=>{let{color:f="#6366f1",label:m}=c||{},[v,k,E]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),w={...s,stroke:f,strokeWidth:8,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:v,markerEnd:l,style:w}),m&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${k}px,${E}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f}`,pointerEvents:"none",zIndex:9999},children:m})})]})};var No=(r=>(r.FULL="full",r.HALF="half",r))(No||{});var St={C13:{type:"C13",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C14:{type:"C14",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C19:{type:"C19",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},C20:{type:"C20",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1}};function Ie(e){let o=St[e];if(!o)throw new Error(`Unknown connector type: ${e}`);let r=o.amperage===16,a=r?12:8,n=r?10:5,i=r?{borderRadius:"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:a,height:n,color:o.color,borderColor:o.borderColor,fontSize:r?"3px":"4px",...i}}function Je(e){let o=St[e];if(!o)throw new Error(`Unknown connector type: ${e}`);return o}function Lr(e){return Je(e).amperage===16}function Ht(e){return e%10<8?"C13":"C19"}function Qe(e){let o=e.toLowerCase();return o.includes("mx304")||o.includes("mx480")||o.includes("mx960")?"C20":"C14"}var Et=({data:e,selected:o})=>{let{label:r,status:a="active",deviceType:n="server",manufacturer:i,role:d,uHeight:s=1,width:c="full",ports:l=[],rearPorts:h=[],view:f}=e,m=f||(h.length>0&&l.length===0?"rear":"front"),v={};v["net-top"]="front",v["net-bottom"]="front",l.length>0&&l.forEach(x=>{x.ports.forEach(H=>{let y=H.type?.includes("power")?H.label:`${x.name}-${H.label}`;v[y]="front";});}),v["pwr-left-1"]="rear",v["pwr-left-2"]="rear",v["net-right-1"]="rear",v["net-right-2"]="rear",h.length>0&&h.forEach(x=>{x.ports.forEach(H=>{let y=H.type?.includes("power")?H.label:`${x.name}-${H.label}`;v[y]="rear";});});let k=s*20,E=c==="half"?"150px":"304px",w=c==="half"?"150px":void 0,T=(x,H)=>{let y=[];if(x.length===0)return y;let P=Math.max(4,Math.floor(k*.4)),M=Math.max(2,Math.floor(k*.2));return x.forEach((R,C)=>{R.ports.forEach((D,I)=>{let O=!!D.type&&D.type.includes("power");if(H==="front"&&O)return;let _=O?`${D.label}`:`${R.name}-${D.label}`,Z=D.connected,L="#6b7280";if(Z)if(D.type?.includes("power"))L=D.type==="power_c19"?"#fbbf24":"#f59e0b";else if(D.type==="console"||D.type==="mgmt")L="#8b5cf6";else if(D.type==="usb")L="#10b981";else switch(D.cableType){case "smf":L="#fbbf24";break;case "cat6":L="#8b5cf6";break;case "om3":L="#06b6d4";break;case "om4":L="#8b5cf6";break;case "om5":L="#84cc16";break;case "cat5e":L="#3b82f6";break;case "cat6a":L="#ef4444";break;case "cat7":L="#f97316";break;case "fiber":L="#3b82f6";break;case "ethernet":L="#10b981";break;default:L="#10b981";}let $=reactflow.Position.Top,j={width:`${P}px`,height:`${M}px`,background:Z?L:"#6b7280",border:`1px solid ${Z?L:"#374151"}`,borderRadius:"1px",cursor:"pointer"};if(H==="front")I%2===0?($=reactflow.Position.Top,j.transform="translateY(50%)",j.left=`${I/2*(P+2)}px`):($=reactflow.Position.Bottom,j.transform="translateY(-50%)",j.left=`${(I-1)/2*(P+2)}px`);else if((n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel"||n==="switch")I%2===0?($=reactflow.Position.Top,j.transform="translateY(50%)",j.left=`${I/2*(P+2)}px`):($=reactflow.Position.Bottom,j.transform="translateY(-50%)",j.left=`${(I-1)/2*(P+2)}px`);else if(D.type?.includes("power")){$=reactflow.Position.Left,j.transform="translateX(50%)";let ke=k<=20?10:20,gt=k<=20?30:50;j.top=`${ke+I*gt}%`;let Ye=Qe(r),pe=Ie(Ye);j={...j,width:`${pe.width}px`,height:`${pe.height}px`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:pe.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:pe.borderRadius,clipPath:pe.clipPath};}else $=reactflow.Position.Right,j.transform="translateX(-50%)",j.top=`${25+I*50}%`;let ae=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",se;if(O)se="target";else if(n==="switch"||n==="router")se="source",y.push(jsxRuntime.jsx(reactflow.Handle,{id:`${_}-target`,type:"target",position:$,style:j,title:`${R.name} - ${D.label} (input) ${Z?"(connected)":"(disconnected)"}`},`${_}-target`));else if(ae){se=H==="rear"?"source":"target";let me=H==="rear"?"target":"source";y.push(jsxRuntime.jsx(reactflow.Handle,{id:`${_}-${me}`,type:me,position:$,style:j,title:`${R.name} - ${D.label} (${me}) ${Z?"(connected)":"(disconnected)"}`},`${_}-${me}`));}else se=Z?"source":"target";y.push(jsxRuntime.jsx(reactflow.Handle,{id:_,type:se,position:$,style:j,title:`${R.name} - ${D.label} ${Z?"(connected)":"(disconnected)"}`,children:O?I+1:void 0},_));});}),y},A=()=>{let x=[],H=Math.max(4,Math.floor(k*.4)),y=Math.max(2,Math.floor(k*.2));if(m==="front"){if(l.length>0)return T(l,"front");if(n==="switch"&&(r.toLowerCase().includes("agg")||r.toLowerCase().includes("core")||d==="agg"||d==="core"))return W();x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-top",type:"target",position:reactflow.Position.Top,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(50%)"},title:"Network Port (Top)"},"net-top")),x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-bottom",type:"target",position:reactflow.Position.Bottom,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(-50%)"},title:"Network Port (Bottom)"},"net-bottom"));}else if(m==="rear"){if(h.length>0)return T(h,"rear");let P=n==="switch",R=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel";if(!R){let C=Qe(r),D=Je(C),I=Ie(C),O=k<=20?"10%":"25%";x.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-1",type:"target",position:reactflow.Position.Left,style:{width:`${I.width}px`,height:`${I.height}px`,background:I.color,border:`1px solid ${I.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:O,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:I.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:I.borderRadius,clipPath:I.clipPath},title:`Power Port 1 (${D.type}) - ${D.voltage}V, ${D.amperage}A`,children:"1"},"pwr-1"));let _=k<=20?"50%":"75%";x.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-2",type:"target",position:reactflow.Position.Left,style:{width:`${I.width}px`,height:`${I.height}px`,background:I.color,border:`1px solid ${I.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:_,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:I.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:I.borderRadius,clipPath:I.clipPath},title:`Power Port 2 (${D.type}) - ${D.voltage}V, ${D.amperage}A`,children:"2"},"pwr-2"));}!P&&!R&&(x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-1",type:"target",position:reactflow.Position.Right,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"25%"},title:"Network Port 1 (Right)"},"net-right-1")),x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-2",type:"target",position:reactflow.Position.Right,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"75%"},title:"Network Port 2 (Right)"},"net-right-2")));}return x},W=()=>{let x=[],H=Math.max(10,Math.floor(k*.45)),y=Math.max(5,Math.floor(k*.25));for(let P=1;P<=16;P++){let M=jsxRuntime.jsx(reactflow.Handle,{id:`port-${P}`,type:"source",position:reactflow.Position.Top,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(50%)",zIndex:1e3,left:`${(P-1)*(H+2)}px`},title:`Port ${P}`},`port-${P}`);x.push(M);}for(let P=17;P<=32;P++){let M=P-16,R=jsxRuntime.jsx(reactflow.Handle,{id:`port-${P}`,type:"source",position:reactflow.Position.Bottom,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(-50%)",zIndex:1e3,left:`${(M-1)*(H+2)}px`},title:`Port ${P}`},`port-${P}`);x.push(R);}for(let P=1;P<=4;P++){let M=Math.max(4,Math.floor(k*.3)),R=Math.max(3,Math.floor(k*.15));x.push(jsxRuntime.jsx(reactflow.Handle,{id:`uplink-${P}`,type:"source",position:reactflow.Position.Right,style:{width:`${M}px`,height:`${R}px`,background:"#8b5cf6",border:"0.5px solid #7c3aed",borderRadius:"0.5px",cursor:"pointer",transform:"translateX(-50%)"},title:`Uplink ${P}`},`uplink-${P}`));}return x};return jsxRuntime.jsxs("div",{className:`device-node ${o?"selected":""}`,style:{background:"#1f2937",border:`1px solid ${ce(a)}`,borderRadius:"2px",padding:"0px",width:E,...w&&{left:w},height:`${k}px`,color:"white",fontFamily:"monospace",fontSize:"8px",boxShadow:o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",justifyContent:"center",cursor:"grab",marginBottom:"0px",boxSizing:"border-box",marginTop:"0px",marginLeft:"0px",marginRight:"0px"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",flex:1,display:"flex",flexDirection:"column",justifyContent:"center",overflow:"hidden",padding:"2px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"7px",lineHeight:"1.1",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r}),s>1&&jsxRuntime.jsx("div",{style:{fontSize:"6px",color:"#9ca3af",lineHeight:"1"},children:i})]}),s>1&&jsxRuntime.jsxs("div",{style:{position:"absolute",bottom:"1px",right:"1px",background:"#374151",color:"#9ca3af",padding:"1px 2px",borderRadius:"1px",fontSize:"6px",lineHeight:"1"},children:[s,"U"]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"1px",left:"1px",width:"4px",height:"4px",background:ce(a),borderRadius:"50%"}}),A()]})};var Rt=({data:e,selected:o})=>{let{label:r,status:a="active",heightCm:n=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:s}=e,c=n*4.2,l=()=>{let m=Math.ceil(i/10),v=Array(10).fill(0).map((y,P)=>P<8?"10A":"16A");for(let y=0,P=0;y<m;++y)for(let M=0;M<10&&P<i;++M,++P){v[M];}let T=[],A=15,H=(c-A-3)/(i-9)*.5;for(let y=0;y<i;y++){let P=A-2+H*y,M=`${y+1}`;if(s&&(s==="top"&&y===0||s==="middle"&&y===Math.floor(i/2)||s==="bottom"&&y===i-1)){T.push(h(P));continue}let C=Ht(y),D=Ie(C),I=Math.round((d-D.width)/2-1);T.push(jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:M,style:{position:"absolute",left:`${I}px`,top:`${P-D.height/2}px`,width:`${D.width}px`,height:`${D.height}px`,background:D.color,border:`1px solid ${D.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:D.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:D.borderRadius,clipPath:D.clipPath},title:`Power Port ${y+1} (${C})`,children:y+1},`handle-${M}`));}return T},h=f=>jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(d-16)/2}px`,top:`${f-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsxRuntime.jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit");return jsxRuntime.jsxs("div",{className:`vertical-pdu-node ${o?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${ce(a)}`,borderRadius:"2px",padding:0,width:`${d}px`,height:`${c}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:"20px",display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:r})}),jsxRuntime.jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${c-20}px`,overflow:"hidden"},children:l()})]})};var It=({data:e,selected:o,id:r})=>{let{lossDb:a}=e||{},n=reactflow.useEdges(),i=n.find(m=>m.target===r&&m.targetHandle==="left"),d=n.find(m=>m.source===r&&m.sourceHandle==="right"),s=n.find(m=>m.target===r&&m.targetHandle==="right"),c=d||s,l=i?.data?.color||"#555",h=c?.data?.color||"#555",f=!!i&&!!c;return jsxRuntime.jsxs("div",{className:`splice-node ${o?"selected":""}`,style:{width:69,height:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:o?"0 0 0 2px #3b82f6":"none"},children:[jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsxRuntime.jsx("div",{style:{background:l}}),jsxRuntime.jsx("div",{style:{background:h}})]}),jsxRuntime.jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1}}),f&&jsxRuntime.jsx("div",{className:"splice-glow",style:{position:"absolute",left:"50%",top:0,bottom:0,width:"1px",background:"rgba(255, 255, 255, 0.6)",boxShadow:"0 0 2px rgba(255, 255, 255, 0.8), 0 0 4px rgba(255, 255, 255, 0.4)",pointerEvents:"none",zIndex:2}}),f&&typeof a=="number"&&jsxRuntime.jsx("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold"},children:`${a.toFixed(2)} dB`}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left,id:"left",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:l,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:h,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:h,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var we=20,He=32,Ho=4,Ne=12,Ur=69,Ce=80,$t=(Ce-Ur)/2;var Ft=(e,o,r,a)=>{if(!e.parentId||e.parentId!==o.id)return r;let n=He,i=r.y-n,d=Math.round(i/we)+1,c=Math.max(1,Math.min(Ne,d));if(!_t(o,e,c,a)){let f=et(o,e,a,c);if(f!==c)return {x:$t,y:n+(f-1)*we+5,holderPosition:f}}let h=n+(c-1)*we+5;return {x:$t,y:h,holderPosition:c}},_t=(e,o,r,a)=>!a.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==o.id).some(i=>i.data.holderPosition===r),et=(e,o,r,a=1)=>{for(let n=a;n<=Ne;n++)if(_t(e,o,n,r))return n;for(let n=a-1;n>=1;n--)if(_t(e,o,n,r))return n;return 1},Me=(e,o)=>{let n=He+(o-1)*we+5;return {x:$t,y:n}};var zt=({data:e,selected:o})=>{let{label:r="Splice Tray"}=e||{},[a,n]=Or.useState(false),i=()=>{if(!a)return null;let d=[],s=He;for(let c=1;c<=Ne;c++){let l=s+(c-1)*we;d.push(jsxRuntime.jsxs("div",{style:{position:"absolute",left:"-35px",top:`${l}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${we}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return d};return jsxRuntime.jsxs("div",{className:`splice-tray-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${Ce}px`,height:`${He+Ne*we+Ho}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${He}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:r}),jsxRuntime.jsx("button",{onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},onClick:d=>{d.stopPropagation(),d.preventDefault(),n(!a);},style:{background:a?"#10b981":"#374151",color:a?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${a?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsxRuntime.jsx("div",{style:{position:"absolute",top:He,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Co=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function oe(e){let o=(e-1)%12;return Co[o]}function Eo(e){return e>12}function Ue(e){let o=oe(e);return Eo(e)?{background:o,backgroundImage:`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`}:{background:o}}function Lt(e){return oe(e)}var Mt=({data:e,selected:o,id:r})=>{let{fibersPerTube:a=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},d=Math.max(1,Math.min(24,Number(a)||12)),s=14,c=4,l=1,h=2,f=20,m=d*s+(d-1)*c,v=Math.max(60,m+l*2+h*2),k=oe((n-1)%12+1),E=`tube-${n}`,w=18,T={width:w,height:w,borderRadius:"50%",opacity:.25,pointerEvents:"auto",background:k,backgroundColor:k,border:`2px solid ${k}`,"--fiber-bg":k},A=()=>i==="left"?reactflow.Position.Left:i==="right"?reactflow.Position.Right:reactflow.Position.Bottom,W=()=>{let x=[],H=v-h*2-l*2,y,P,M=false;i==="left"?(y=l,P=reactflow.Position.Top):i==="right"?(y=l+H-m,P=reactflow.Position.Top,M=true):(y=l+(H-m)/2,P=reactflow.Position.Top);for(let R=0;R<d;R++){let C=M?d-R:R+1,D=Ue(C),I=oe(C),O=y+R*(s+c),_=l,Z=D.backgroundImage?D.backgroundImage:I,L={position:"absolute",left:`${O}px`,top:`${_}px`,width:s,height:s,borderRadius:"50%",border:"none",background:Z,backgroundColor:I,zIndex:10,cursor:"pointer","--fiber-bg":I};D.backgroundImage&&(L["--fiber-bg-image"]=D.backgroundImage);let $=`fiber-${C}`;x.push(jsxRuntime.jsxs(Or__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:$,type:"target",position:P,className:"tube-fiber-handle",isConnectable:true,style:L,"data-fiber-idx":C,"data-fiber-color":I}),jsxRuntime.jsx(reactflow.Handle,{id:$,type:"source",position:P,className:"tube-fiber-handle",isConnectable:true,style:L,"data-fiber-idx":C,"data-fiber-color":I})]},`fiber-${C}`));}return x};return jsxRuntime.jsxs("div",{style:{width:v,height:f,borderRadius:4,background:"#111827",border:`${h}px solid ${o?"#3b82f6":k}`,position:"relative",boxShadow:o?`0 0 0 ${h}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:l,boxSizing:"border-box"},children:[W(),jsxRuntime.jsx(reactflow.Handle,{id:E,type:"target",position:A(),isConnectable:true,style:T,"data-tube-idx":n,"data-tube-color":k}),jsxRuntime.jsx(reactflow.Handle,{id:E,type:"source",position:A(),isConnectable:true,style:T,"data-tube-idx":n,"data-tube-color":k})]})};var Ut=({data:e,selected:o})=>{let{tubeCount:r=12,fibersPerTube:a=12,fiberCount:n,cableId:i="CBL-002",label:d,tubeStartIndex:s=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(r)||12)),h=Math.max(1,Number(s)||1),f=8,m=2,v=6,k=v+f+4,E=60,w=Math.max(120,l*(f+m)+v*2),T=n??l*(Number(a)||12),A=d??`${T}f Cable`,W=i?`Cable ID ${i}`:void 0,x=oe(h),H=c||x,y=o?"#3b82f6":H,P=()=>{let I=[];for(let O=0;O<l;O++){let _=h+O,Z=Ue(_),L=oe(_),$=v+O*(f+m),j=-4,V=Z.backgroundImage?Z.backgroundImage:L,ae={position:"absolute",left:`${$}px`,top:`${j}px`,width:f,height:f,borderRadius:"50%",border:"none",background:V,backgroundColor:L,zIndex:10,cursor:"pointer","--fiber-bg":L};Z.backgroundImage&&(ae["--fiber-bg-image"]=Z.backgroundImage);let se=`tube-${_}`;I.push(jsxRuntime.jsxs(Or__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:se,type:"target",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":_,"data-tube-idx":_,"data-tube-color":L}),jsxRuntime.jsx(reactflow.Handle,{id:se,type:"source",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":_,"data-tube-idx":_,"data-tube-color":L})]},`tube-${_}`));}return I},M="cable-button",R=8,C={width:R,height:R,borderRadius:"50%",background:H,backgroundColor:H,border:`1px solid ${H}`,cursor:"pointer",zIndex:10};return jsxRuntime.jsxs("div",{style:{width:w,height:E,borderRadius:4,background:"#111827",border:`2px solid ${y}`,position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:v,paddingTop:k,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[P(),jsxRuntime.jsx(reactflow.Handle,{id:M,type:"source",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:C,"data-handle-type":"cable-button","data-cable-color":H}),jsxRuntime.jsx(reactflow.Handle,{id:M,type:"target",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:C,"data-handle-type":"cable-button","data-cable-color":H}),jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:A}),W&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:W})]})};var Bt=({data:e,selected:o,id:r})=>{let{connector:a="LC",couplerFiberCount:n,label:i,portLabelsLeft:d,portLabelsRight:s}=e||{},c=reactflow.useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,h=Math.max(1,Math.min(4,l)),f=7,m=3,v=3,k=60,E=30,w=h*f+(h-1)*m,T=Math.max(E,w+v*2),A=Math.max(k,80),W=(y,P)=>{let M=`${y}-${P+1}`;return c.find(C=>C.source===r&&C.sourceHandle===M||C.target===r&&C.targetHandle===M)?.data?.color||"#555"},x=y=>{let P=[],M=y==="left"?reactflow.Position.Left:reactflow.Position.Right,R=y==="left"?d:s;for(let C=0;C<h;C++){let D=C+1,I=`${y}-${D}`,O=W(y,C),L=v+(T-w)/2+C*(f+m),$={position:"absolute",left:y==="left"?-5:void 0,right:y==="right"?-5:void 0,top:`${L}px`,width:f,height:f,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};P.push(jsxRuntime.jsxs(Or__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:I,type:"target",position:M,isConnectable:true,style:$}),jsxRuntime.jsx(reactflow.Handle,{id:I,type:"source",position:M,isConnectable:true,style:$})]},I)),R&&R[C]&&P.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:y==="left"?-30:void 0,right:y==="right"?-30:void 0,top:`${L}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:y==="left"?"right":"left",width:"25px"},children:R[C]},`${I}-label`));}return P},H=i||`${a}-${h}f`;return jsxRuntime.jsxs("div",{className:`coupler-node ${o?"selected":""}`,style:{width:A,height:T,borderRadius:4,border:`2px solid ${o?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",fontSize:"10px",padding:`${v}px`,boxSizing:"border-box"},children:[x("left"),jsxRuntime.jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:H})}),x("right")]})};var Ee=32,st=30,jr=24,Gr=80,it=400,at=300,Wo=2,he=8,zo=120;function Ot(e){let{couplerFiberCount:o}=e.data||{},r=typeof o=="number"&&[1,2,4].includes(o)?o:2,a=Math.max(1,Math.min(4,r)),n=7,i=3,d=3,s=60,c=30,l=a*n+(a-1)*i,h=Math.max(c,l+d*2);return {width:Math.max(s,80),height:h}}function dt(e){let{fibersPerTube:o=12}=e.data||{},r=Math.max(1,Math.min(24,Number(o)||12)),a=14,n=4,i=1,d=2,s=20,c=r*a+(r-1)*n;return {width:Math.max(60,c+i*2+d*2),height:s}}function Lo(e){return {width:Ce,height:0}}function Oe(e){return e.type==="coupler"?Ot(e):e.type==="tube"?dt(e):e.type==="splice-tray"?Lo():{width:80,height:30}}function Mo(e){return e.data?.panelWidth||it}function Zr(e){return e.data?.panelHeight||at}function Uo(e){return Mo(e)-Wo*2-he*2}function Kr(e,o){return Uo(e)-o}function Bo(e,o=st){return Math.floor(e/o)+1}function Oo(e,o=st){return (e-1)*o}function qr(e,o,r){let a=st,n=Bo(r.y,a),i=Oo(n,a);return {x:r.x,y:i,slotPosition:n}}function Yt(e,o){if(o.length===0)return {width:e.data?.panelWidth||it,height:e.data?.panelHeight||at};let r=o.some(l=>l.type==="tube"),a=o.some(l=>l.type==="splice-tray"),n=o.some(l=>l.type==="coupler"),i,d=5;if(r&&a&&n){let l=0,h=0;for(let f of o)if(f.type==="tube"){let m=dt(f);m.width>l&&(l=m.width);}else if(f.type==="coupler"){let m=Ot(f);m.width>h&&(h=m.width);}i=he+l+zo+Ce+h+d;}else {let l=0;for(let h of o){let f=Oe(h),m=(h.position?.x||0)+f.width;m>l&&(l=m);}i=l+he+d;}i=Math.max(e.data?.panelWidth||it,i);let s=Ee;for(let l of o){let h=Oe(l),f=(l.position?.y||0)+h.height;f>s&&(s=f);}let c=Math.max(e.data?.panelHeight||at,s+he);return {width:i,height:c}}function Yo(e,o,r){if(e===0)return 0;if(e===1)return o;let a=e*o,n=r-a,i=Math.max(5,n/(e-1));return o+i}function Jr(e,o,r){return Yo(e,o,r)}var _o=20,Fo=400,Ao=300;function Vo(e,o){if(o.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||Fo,height:e.data?.closureHeight||e.data?.panelHeight||Ao};let r=o.some(c=>c.type==="tube"),a=o.some(c=>c.type==="splice-tray"),n,i=5;if(r&&a){let c=0,l=0,h=0,f=o.filter(v=>v.type==="tube"),m=o.filter(v=>v.type==="splice-tray");if(f.length>0&&m.length>0){let v=f.map(A=>A.position?.x||0);Math.min(...v);Math.max(...v);let w=m.map(A=>A.position?.x||0),T=w.reduce((A,W)=>A+W,0)/w.length;for(let A of f){let W=dt(A);(A.position?.x||0)<T?W.width>c&&(c=W.width):W.width>l&&(l=W.width);}m.length>0&&(h=Ce),n=he+c+_o+h+_o+l+i;}else {let v=0;for(let k of o){let E=Oe(k),w=(k.position?.x||0)+E.width;w>v&&(v=w);}n=v+he+i;}}else {let c=0;for(let l of o){let h=Oe(l),f=(l.position?.x||0)+h.width;f>c&&(c=f);}n=c+he+i;}n=Math.max(e.data?.closureWidth||e.data?.panelWidth||Fo,n);let d=Ee;for(let c of o){let l=Oe(c),h=(c.position?.y||0)+l.height;h>d&&(d=h);}let s=Math.max(e.data?.closureHeight||e.data?.panelHeight||Ao,d+he);return {width:n,height:s}}var jt=({data:e,selected:o,id:r})=>{let{label:a="Patch Panel",header:n,panelWidth:i,panelHeight:d}=e||{},{getNodes:s,setNodes:c}=reactflow.useReactFlow(),l=Or.useRef(false),h=Or.useMemo(()=>s().filter(A=>A.parentId===r),[s,r]),f=Or.useMemo(()=>({id:r,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[r,e,i,d]),m=Or.useMemo(()=>i&&d?{width:i,height:d}:h.length===0?{width:i||400,height:d||300}:Yt(f,h),[h,f,i,d]);Or.useEffect(()=>{if(i&&d||l.current)return;let T=i,A=d,W=Math.abs((T||0)-m.width),x=Math.abs((A||0)-m.height);(W>1||x>1)&&(l.current=true,c(H=>H.map(y=>y.id===r?{...y,data:{...y.data,panelWidth:m.width,panelHeight:m.height}}:y)),setTimeout(()=>{l.current=false;},0));},[r,m.width,m.height,i,d,c]);let v=m.width,k=m.height,E=Ee,w=n||a;return jsxRuntime.jsxs("div",{className:`patch-panel-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${v}px`,height:`${k}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${E}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:w})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:E,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var Kt=({data:e,selected:o,id:r})=>{let{label:a="Closure",header:n,closureWidth:i,closureHeight:d,panelWidth:s,panelHeight:c}=e||{},{getNodes:l,setNodes:h}=reactflow.useReactFlow(),f=Or.useRef(false),m=Or.useMemo(()=>l().filter(H=>H.parentId===r),[l,r]),v=Or.useMemo(()=>({id:r,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||s,closureHeight:d||c}}),[r,e,i,d,s,c]),k=Or.useMemo(()=>i&&d?{width:i,height:d}:s&&c?{width:s,height:c}:m.length===0?{width:i||s||400,height:d||c||300}:Vo(v,m),[m,v,i,d,s,c]);Or.useEffect(()=>{if(i&&d||s&&c||f.current)return;let x=i||s,H=d||c,y=Math.abs((x||0)-k.width),P=Math.abs((H||0)-k.height);(y>1||P>1)&&(f.current=true,h(M=>M.map(R=>R.id===r?{...R,data:{...R.data,closureWidth:k.width,closureHeight:k.height}}:R)),setTimeout(()=>{f.current=false;},0));},[r,k.width,k.height,i,d,s,c,h]);let E=k.width,w=k.height,T=Ee,A=n||a,W=E/2;return jsxRuntime.jsxs("div",{className:`closure-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${W}px ${W}px 12px 12px`,padding:0,width:`${E}px`,height:`${w}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box",overflow:"hidden",transform:"translateX(-4px)"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${T}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${W}px ${W}px 0 0`,borderBottom:"1px solid #4b5563",transform:"translateX(4px)"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:A})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:T,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};function dn(e,o){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let r=o.edges.some(w=>w.source===e.source&&w.sourceHandle===e.sourceHandle),a=o.edges.some(w=>w.target===e.target&&w.targetHandle===e.targetHandle);if(r)return {valid:false,reason:"Source port is already connected"};if(a)return {valid:false,reason:"Target port is already connected"};let n=e.sourceHandle,i=e.targetHandle,d=o.nodes.find(w=>w.id===e.source),s=o.nodes.find(w=>w.id===e.target),c=(w,T)=>{if(!w)return false;let A=w.startsWith("pwr")||w.startsWith("power"),W=T?.type==="vertical-pdu"&&w!=="mgmt-net-1";return A||W},l=(w,T)=>{if(!w)return false;if(T?.type==="vertical-pdu"&&w==="mgmt-net-1"||T?.type==="tube"&&w.startsWith("fiber-")||(T?.type==="tube"||T?.type==="cable")&&w.startsWith("tube-")||T?.type==="splice"&&(w==="left"||w==="right"))return true;let A=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("Fiber")||w.includes("Ports"),W=/^[A-Z0-9]+-\d+$/.test(w)&&!w.startsWith("pwr")&&!w.startsWith("power");return A||W},h=c(n,d),f=c(i,s),m=l(n,d),v=l(i,s);if(h&&v||f&&m)return {valid:false,reason:"Cannot connect network cable to power port"};if(h&&!f||f&&!h)return {valid:false,reason:"Power ports must connect to power-compatible ports"};let k=d?.type==="vertical-pdu",E=s?.type==="vertical-pdu";if(h||f){let w=k?s:E?d:null,T=k?d:E?s:null;if(w&&T&&o.edges.filter(x=>{let H=c(x.sourceHandle||""),y=c(x.targetHandle||""),P=x.source===w.id||x.target===w.id;return (H||y)&&P}).some(x=>x.source===T.id||x.target===T.id))return {valid:false,reason:"Dual-feed required: connect second power to a different PDU"}}return {valid:true}}function ct(e,o){if(!o)return;let r=typeof e=="string"?e.replace(/-(target|source)$/i,""):e,a=o.data??{},n=a.handleSideMap;if(n&&n[r])return n[r];if(r==="net-top"||r==="net-bottom")return "front";if(r==="pwr-left-1"||r==="pwr-left-2"||r==="net-right-1"||r==="net-right-2")return "rear";let i=Array.isArray(a.ports)?a.ports:[],d=Array.isArray(a.rearPorts)?a.rearPorts:[];if(r.startsWith("pwr")||r.includes("power"))return "rear";for(let c of i)for(let l of c.ports||[])if((!!l.type&&String(l.type).includes("power")?l.label:`${c.name}-${l.label}`)===r)return "front";for(let c of d)for(let l of c.ports||[])if((!!l.type&&String(l.type).includes("power")?l.label:`${c.name}-${l.label}`)===r)return "rear"}function qt(e={},o={}){let r={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},a=new Set;return {getState:()=>r,setState:f=>{r={...r,...f},a.forEach(m=>m(r));},subscribe:f=>(a.add(f),()=>a.delete(f)),selectEdgeZIndex:f=>{let m=r.nodes.find(H=>H.id===f.target);if(!m||m.type!=="device")return 1e3;let v=m.data?.view||"front",k=ct(f.targetHandle||"",m);if(k)return v===k?1e3:500;let E=(f.targetHandle||"").toString(),w=E.toLowerCase(),T=w.startsWith("pwr")||w.startsWith("power"),A=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("fiber")||w.includes("ports"),W=/^[A-Z0-9]+-\d+$/i.test(E)&&!w.startsWith("pwr")&&!w.startsWith("power"),x=A||W;return T?v==="rear"?1e3:500:x?v==="front"?1e3:500:1e3},validateConnection:f=>(o.validateConnection||dn)(f,r),selectNodeById:f=>r.nodes.find(m=>m.id===f),selectConnectedEdges:f=>r.edges.filter(m=>m.source===f||m.target===f)}}function cn(e){let o=n=>e.subscribe(n),r=()=>e.getState();return Or.useSyncExternalStore(o,r,r)}function Qt(e){let o=a=>e.subscribe(a),r=()=>e.getState().nodes;return Or.useSyncExternalStore(o,r,r)}function eo(e){let o=a=>e.subscribe(a),r=()=>e.getState().edges;return Or.useSyncExternalStore(o,r,r)}function Xo(e){return e.selectEdgeZIndex}function jo(e){let o=300,r=(e.data.uHeight||42)*20,a=e.position.x,n=e.position.x+o,i=e.position.y,d=e.position.y+r;return {left:a,right:n,top:i,bottom:d}}function lt(e,o){let r=jo(o);return e.x>=r.left&&e.x<=r.right&&e.y>=r.top&&e.y<=r.bottom}function pt(e,o){let r=null,a=1/0;for(let n of o){if(!lt(e,n))continue;let i=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));i<a&&(a=i,r=n);}return r}function G(e){let{edges:o,connection:r,edgeType:a,selectEdgeZIndex:n,findBy:i,data:d}=e,s=i==="source"?r.sourceHandle:r.targetHandle,c=i==="source"?r.source:r.target;if(!s||!c)return null;let l=o.find(E=>i==="source"?E.source===c&&E.sourceHandle===s:E.target===c&&E.targetHandle===s);if(!l)return null;let h=o.filter(E=>E.id!==l.id),f=reactflow.addEdge(r,h),m=f[f.length-1],v=n({...r,id:m.id,type:a}),k={...m,type:a,zIndex:v,style:{...m.style,zIndex:v},data:d!==void 0?d:m.data};return [...f.slice(0,-1),k]}var vn=(e,o,r)=>({rack:a=>jsxRuntime.jsx(xt,{...a,onViewChange:e,onRackFaceChange:o,isDragOver:r?r()===a.id:false}),fiber:wt,device:Et,"vertical-pdu":Rt,splice:It,"splice-tray":zt,tube:Mt,cable:Ut,coupler:Bt,"patch-panel":jt,closure:Kt}),Pn={fiber:kt,power:vt,smoothstep:bo,step:xo,"thick-cable":wo},Sn=({nodes:e,edges:o,initialNodes:r,initialEdges:a,onNodesChange:n,onEdgesChange:i,store:d,debug:s,onNodeClick:c,onEdgeClick:l,onViewChange:h,onRackFaceChange:f,className:m,style:v,alignRacksToBottom:k,colorMode:E="dark",onInit:w,onFlowMethods:T,showDownloadButton:A=false,downloadButtonPosition:W="top-right",downloadButtonText:x="Download Image",downloadButtonStyle:H,allowReconnectExisting:y=false,useSmoothstepEdgesForTubes:P=false,connectOnClick:M=true})=>{let R=Array.isArray(e)&&Array.isArray(o),C=Or__default.default.useMemo(()=>d||qt({nodes:R?e||[]:r||e||[],edges:R?o||[]:a||o||[],debug:s}),[d,R,s]),D=Qt(C),I=eo(C),[O,_,Z]=reactflow.useNodesState(D),[L,$,j]=reactflow.useEdgesState(I),V=Xo(C),ae=Or.useRef(null),{toObject:se,setViewport:me,setNodes:ut,setEdges:ft,getNodes:ke}=reactflow.useReactFlow();Or.useEffect(()=>{T&&T({toObject:se,setViewport:me,setNodes:t=>{ut(t),C.setState({nodes:t});},setEdges:t=>{ft(t),C.setState({edges:t});},toImage:t=>ae.current?htmlToImage.toPng(ae.current,t):Promise.reject(new Error("ReactFlow wrapper not available"))});},[T,se,me,ut,ft,C]);let gt=Or.useCallback(()=>{if(!ae.current){s&&console.error("ReactFlow wrapper ref is not available");return}htmlToImage.toPng(ae.current,{filter:t=>!(t?.classList?.contains("react-flow__minimap")||t?.classList?.contains("react-flow__controls")||t?.classList?.contains("react-flow__attribution")||t?.classList?.contains("download-button")||t?.tagName==="BUTTON"),backgroundColor:E==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(t=>{let p=document.createElement("a");p.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,p.href=t,p.click();}).catch(t=>{s&&console.error("Error downloading image:",t);});},[E,s]),[Ye,pe]=Or.useState(null),io=Or.useRef(null),ao=Or.useRef(h),so=Or.useRef(f);Or.useEffect(()=>{ao.current=h;},[h]),Or.useEffect(()=>{so.current=f;},[f]),Or.useEffect(()=>{io.current=Ye;},[Ye]);let co=Or.useCallback(()=>io.current,[]),tr=Or.useMemo(()=>vn((t,p)=>ao.current?.(t,p),(t,p)=>so.current?.(t,p),co),[co]),or=Or.useMemo(()=>Pn,[]),ge=Or.useRef(O);Or.useEffect(()=>{ge.current=O;},[O]);let z=Or.useRef(L);Or.useEffect(()=>{z.current=L;},[L]),Or.useEffect(()=>{_(D);},[D,_]),Or.useEffect(()=>{$(I);},[I,$]),Or.useEffect(()=>{R&&C.setState({nodes:e||[]});},[R,e,C]),Or.useEffect(()=>{R&&C.setState({edges:o||[]});},[R,o,C]),Or.useEffect(()=>{if(!k||!O||O.length===0)return;let t=O.filter(U=>U.type==="rack");if(t.length===0)return;let p=t.map(U=>{let de=U.data?.uHeight||42,fe=60+de*20;return (U.position?.y||0)+fe}),b=Math.min(...p),g=Math.max(...p);if(g-b<20)return;let u=g,F=O.map(U=>{if(U.type!=="rack")return U;let de=U.data?.uHeight||42,fe=60+de*20,K=(U.position?.y||0)+fe,B=u-K;return Math.abs(B)<5?U:{...U,position:{x:U.position?.x||0,y:(U.position?.y||0)+B}}});F.some((U,te)=>U.position!==O[te].position)&&_(F);},[k,O,_]);let X=Or.useCallback(t=>ge.current.find(p=>p.id===t),[]),Ve=Or.useCallback((t,p)=>{if(!t||!p)return;let b=X(t);if(!b)return;if(b.type==="tube"&&p.startsWith("fiber-")){let N=p.replace("fiber-",""),u=parseInt(N,10);if(u>=1&&u<=24){let F=Lt(u),Y=u>12;return {color:F,striped:Y}}}if((b.type==="cable"||b.type==="tube")&&p.startsWith("tube-")){let N=p.replace("tube-",""),u=parseInt(N,10);if(u>=1&&u<=24){let F=oe(u),Y=u>12;return {color:F,striped:Y}}}let g=b.data;if(g.color)return {color:g.color}},[X]);Or.useEffect(()=>{$(t=>t.map(p=>{let b=V(p);return {...p,zIndex:b,style:{...p.style,zIndex:b}}}));},[O,$,V]),Or.useEffect(()=>{let t=O.map(b=>{if(b.type==="coupler"&&b.parentId){let g=X(b.parentId);if(g&&(g.type==="patch-panel"||g.type==="closure")&&(!b.extent||b.extent!=="parent"))return {...b,extent:"parent"}}if(b.type==="splice"&&b.parentId&&b.data.holderPosition&&(!b.position||b.position.x===0&&b.position.y===0)){let g=X(b.parentId);if(g&&g.type==="splice-tray"){let N=Me(g,b.data.holderPosition);return {...b,position:N}}}if(b.type==="device"&&b.parentId&&b.data.uPosition&&(!b.position||b.position.x===0&&b.position.y===0)){let g=X(b.parentId);if(g){let N=De(g,b.data.uPosition);return {...b,position:N}}}return b});t.some((b,g)=>{let N=O[g];return b.extent!==N.extent||b.position?.x!==N.position?.x||b.position?.y!==N.position?.y})&&_(t);},[O,_,X]);let rr=Or.useCallback(t=>{let p=t.map(b=>{if(b.type==="position"&&b.position){let g=X(b.id);if(g&&g.type==="coupler"&&g.parentId){let N=X(g.parentId);if(N&&(N.type==="patch-panel"||N.type==="closure")){if(!g.extent||g.extent!=="parent"){let u={...g,extent:"parent"};_(F=>F.map(Y=>Y.id===g.id?u:Y));}return {...b,position:g.position||{x:0,y:0}}}}if(g&&(g.type==="tube"||g.type==="splice-tray")&&g.parentId){let N=X(g.parentId);if(N&&N.type==="closure"){if(!g.extent||g.extent!=="parent"){let u={...g,extent:"parent"};_(F=>F.map(Y=>Y.id===g.id?u:Y));}return {...b,position:g.position||{x:0,y:0}}}}if(g&&g.type==="splice"&&g.parentId){let N=X(g.parentId);if(N&&N.type==="splice-tray"){let u=Ft(g,N,b.position,ge.current);if(u.holderPosition!==void 0){let F={...g,data:{...g.data,holderPosition:u.holderPosition}};_(Y=>Y.map(U=>U.id===g.id?F:U));}return {...b,position:{x:u.x,y:u.y}}}}if(g&&g.type==="device"&&g.parentId){let N=X(g.parentId);if(N){let u=mt(g,N,b.position,ge.current);if(u.uPosition!==void 0){let F={...g,data:{...g.data,uPosition:u.uPosition}};_(Y=>Y.map(U=>U.id===g.id?F:U));}return {...b,position:{x:u.x,y:u.y}}}}if(g&&g.type==="device"&&g.parentId){let N=X(g.parentId);if(N){let u=N;if(!lt(b.position,u)){let F=b.position.x+u.position.x,Y=b.position.y+u.position.y,U={...g,parentId:void 0,extent:void 0,data:{...g.data,uPosition:void 0}};return _(te=>te.map(de=>de.id===g.id?U:de)),{...b,position:{x:F,y:Y}}}}}}return b});Z(p);},[Z,_,X]),nr=Or.useCallback((t,p)=>{pe(null);},[]),ir=Or.useCallback((t,p,b)=>{if(p.type==="device"&&!p.parentId){let g=ge.current.filter(u=>u.type==="rack").map(u=>u),N=pt(p.position,g);pe(N?.id??null);}else pe(null);},[]),ar=Or.useCallback((t,p,b)=>{if(p.type==="device"&&!p.parentId){let g=ge.current.filter(u=>u.type==="rack").map(u=>u),N=pt(p.position,g);if(N){let u=p.position.x-N.position.x,F=p.position.y-N.position.y,Y={...p,parentId:N.id,extent:"parent",position:{x:u,y:F},data:{...p.data,uPosition:1}},U=ge.current.map(te=>te.id===p.id?Y:te);_(U),R||C.setState({nodes:U});}}pe(null);},[_,R,C]),sr=Or.useCallback(t=>{if(!t.source||!t.target||!t.sourceHandle||!t.targetHandle)return true;let p=X(t.source),b=X(t.target);if(p?.type==="tube"&&b?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&t.targetHandle.startsWith("fiber-"))return s&&console.log("Connection rejected: Cannot connect fibres within tubes",t),false;if(p?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&(b?.type==="cable"||b?.type==="tube")&&t.targetHandle.startsWith("tube-"))return s&&console.log("Connection rejected: Cannot connect individual fibre to cable/tube tube handle",t),false;if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle.startsWith("tube-")&&b?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return s&&console.log("Connection rejected: Cannot connect cable/tube tube handle to individual fibre",t),false;if(b?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")){if(z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle||u.source===t.target&&u.sourceHandle===t.targetHandle))return s&&console.log("Splice handle already connected, will replace",t),true;s&&console.log("Allowing connection to splice handle",t);}if(p?.type==="tube"&&t.sourceHandle.startsWith("fiber-"))return b?.type!=="splice"?(s&&console.log("Connection rejected: Tube fiber handles can only connect to splices",t),false):z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Tube fiber handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube fiber handle to splice",t),true);if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle.startsWith("tube-"))return t.targetHandle.startsWith("tube-")?z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Tube-level handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube-level handle to tube handle",t),true):(s&&console.log("Connection rejected: Tube handles can only connect to other tube handles",t),false);if(p?.type==="splice"&&t.sourceHandle==="right"){if(z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle||u.target===t.source&&u.targetHandle===t.sourceHandle))return s&&console.log("Splice source handle already connected, will replace",t),true;s&&console.log("Allowing connection from splice source handle",t);}if(b?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return p?.type!=="splice"?(s&&console.log("Connection rejected: Tube fiber handles can only connect from splices",t),false):z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Tube fiber target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from splice to tube fiber handle",t),true);if((b?.type==="cable"||b?.type==="tube")&&t.targetHandle.startsWith("tube-"))return t.sourceHandle.startsWith("tube-")?z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Tube-level target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube handle to tube-level handle",t),true):(s&&console.log("Connection rejected: Tube handles can only connect from other tube handles",t),false);if(p?.type==="coupler"&&(t.sourceHandle?.startsWith("left-")||t.sourceHandle?.startsWith("right-")))return b?.type!=="splice"?(s&&console.log("Connection rejected: Coupler handles can only connect to splices",t),false):t.targetHandle!=="left"&&t.targetHandle!=="right"?(s&&console.log("Connection rejected: Coupler can only connect to splice left/right handles",t),false):z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Coupler handle already connected, will replace",t),true):(s&&console.log("Allowing connection from coupler handle to splice",t),true);if(b?.type==="coupler"&&(t.targetHandle?.startsWith("left-")||t.targetHandle?.startsWith("right-")))return p?.type!=="splice"?(s&&console.log("Connection rejected: Coupler handles can only connect from splices",t),false):t.sourceHandle!=="left"&&t.sourceHandle!=="right"?(s&&console.log("Connection rejected: Coupler can only connect from splice left/right handles",t),false):z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Coupler target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from splice to coupler handle",t),true);if(t.source&&t.sourceHandle&&z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return s&&console.log("Source handle already connected, will replace",t),true;if(t.target&&t.targetHandle&&z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return s&&console.log("Target handle already connected, will replace",t),true;if((p?.type==="cable"||b?.type==="cable")&&(t.sourceHandle==="cable-button"||t.targetHandle==="cable-button"))return t.sourceHandle!=="cable-button"||t.targetHandle!=="cable-button"?(s&&console.log("Connection rejected: Cable button handles can only connect to other cable button handles",t),false):z.current.find(F=>F.source===t.source&&F.sourceHandle===t.sourceHandle)?(s&&console.log("Cable button source handle already connected, will replace",t),true):z.current.find(F=>F.target===t.target&&F.targetHandle===t.targetHandle)?(s&&console.log("Cable button target handle already connected, will replace",t),true):(s&&console.log("Allowing connection between cable button handles",t),true);let g=C.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!g.valid&&y){if(t.source&&t.sourceHandle&&z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return s&&console.log("Source handle has existing edge, will replace",t),true;if(t.target&&t.targetHandle&&z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return s&&console.log("Target handle has existing edge, will replace",t),true}return s&&!g.valid&&console.log("Connection rejected by store validation:",g.reason,t),g.valid},[X,C,s,y]),dr=Or.useCallback(t=>{let p=X(t.source),b=X(t.target),g=p?.type==="vertical-pdu",N=p?.data,u=p?.type==="device"&&N?.deviceType==="switch",F=!!t.targetHandle&&(t.targetHandle.startsWith("pwr")||t.targetHandle.startsWith("power")),Y=!!t.targetHandle&&(t.targetHandle.startsWith("net-")||t.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(t.targetHandle)),U=p?.type==="tube"&&b?.type==="cable",te=p?.type==="cable"&&b?.type==="tube",de=U||te,fe=t.sourceHandle==="cable-button"&&t.targetHandle==="cable-button",K="fiber";g&&F?K="power":fe?K="thick-cable":de&&(K=P?"smoothstep":"fiber");let B;if((K==="fiber"||K==="smoothstep")&&!g){let S=Ve(t.source,t.sourceHandle);S&&(B={color:S.color,striped:S.striped});}else if(K==="thick-cable"&&fe){let S=p?.data;B={color:S?.color||(S?.tubeStartIndex?oe(S.tubeStartIndex):"#6366f1")};}if(t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}if(b?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}if(t.targetHandle==="right"&&(S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"source",data:B}),S)){$(S);return}}if(p?.type==="splice"&&t.sourceHandle==="right"&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}if(S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"target",data:B}),S){$(S);return}}if(p?.type==="tube"&&t.sourceHandle?.startsWith("fiber-")&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(b?.type==="tube"&&t.targetHandle?.startsWith("fiber-")&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle?.startsWith("tube-")&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if((b?.type==="cable"||b?.type==="tube")&&t.targetHandle?.startsWith("tube-")&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}if(fe&&t.source&&t.sourceHandle&&t.target&&t.targetHandle){let S=p?.data,J=S?.color||(S?.tubeStartIndex?oe(S.tubeStartIndex):"#6366f1"),be=G({edges:z.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:V,findBy:"source",data:{color:J}});if(be){$(be);return}if(be=G({edges:z.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:V,findBy:"target",data:{color:J}}),be){$(be);return}}if(g&&F&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:"power",selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}if(u&&Y&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}let Re=C.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!Re.valid){if(y){if(t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}}if(g&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:F?"power":"fiber",selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(u&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}s&&console.warn(`Connection rejected: ${Re.reason}`);return}let ve={...t,type:K,zIndex:V({...t,id:"temp-id"}),data:B};$(S=>{let J=reactflow.addEdge(ve,S),be=J[J.length-1];return be&&(po(ht=>new Set(ht).add(be.id)),setTimeout(()=>{po(ht=>{let uo=new Set(ht);return uo.delete(be.id),uo});},1e3)),J});},[$,C,V,X,s,Ve,y,P]),cr=Or.useCallback((t,p)=>{if(!p.source||!p.target||!p.sourceHandle||!p.targetHandle)return;let b=t.sourceHandle||"",g=t.targetHandle||"",N=p.sourceHandle||"",u=p.targetHandle||"";if(b.startsWith("tube-")&&N!==b){s&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:p});return}if(g.startsWith("tube-")&&u!==g){s&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:p});return}let F=X(p.source),Y=X(p.target),U=F?.type==="vertical-pdu",te=!!p.targetHandle&&(p.targetHandle.startsWith("pwr")||p.targetHandle.startsWith("power")),de=F?.type==="tube"&&Y?.type==="cable",fe=F?.type==="cable"&&Y?.type==="tube",K=de||fe,B;U&&te?B="power":K?B=P?"smoothstep":"fiber":B="fiber";let Re;if((B==="fiber"||B==="smoothstep")&&!U){let ve=Ve(p.source,p.sourceHandle);ve&&(Re={color:ve.color,striped:ve.striped});}$(ve=>ve.map(J=>J.id===t.id?{...J,source:p.source,target:p.target,sourceHandle:p.sourceHandle,targetHandle:p.targetHandle,type:B,data:Re!==void 0?{...J.data,...Re}:J.data,zIndex:V({...p,id:J.id,type:B}),style:{...J.style,zIndex:V({...p,id:J.id,type:B})}}:J));},[$,X,Ve,V,P,s]),lr=Or.useCallback((t,p)=>{let b=t.metaKey||t.ctrlKey;if(p.type==="tube"&&p.parentId&&!b){let N=ke().find(u=>u.id===p.parentId&&u.type==="cable");if(N){_(u=>u.map(F=>({...F,selected:F.id===N.id}))),c&&c(N);return}}if(b&&p.type==="device"){let g=p.data||{},N=g.view||(Array.isArray(g.rearPorts)&&g.rearPorts.length>0?"rear":"front"),u=N==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${p.id} from ${N} to ${u}`),h&&h(p.id,u),c&&c(p);}else c&&c(p);},[h,c,s,ke,_]),pr=Or.useCallback(()=>{},[]),ur=Or.useCallback((t,p)=>{l&&l(p);},[l]),[ue,bt]=Or.useState(null),[lo,po]=Or.useState(new Set);reactflow.useOnSelectionChange({onChange:({nodes:t})=>{if(t&&t.length===1){let p=t[0];if(p.type==="tube"&&p.parentId){let g=ke().find(N=>N.id===p.parentId&&N.type==="cable");if(g){bt(g),_(N=>N.map(u=>({...u,selected:u.id===g.id}))),c&&c(g);return}}bt(p),c&&c(p);}else bt(null),c&&c(null);}});let fr=Or.useCallback((t,{nodeId:p,handleType:b})=>{s&&console.log("Connection started from",{nodeId:p,handleType:b});},[s]),gr=Or.useCallback(t=>{s&&console.log("Connection ended",t);},[s]),br=Or.useCallback(()=>{if(!ue)return;let t=X(ue.id);if(t){if(t.type==="rack"){let g=((t.data||{}).face||"front")==="front"?"rear":"front";f?(f(t.id,g),h&&ke().filter(u=>u.parentId===t.id).forEach(u=>{h(u.id,g);})):_(N=>N.map(u=>u.id===t.id?{...u,data:{...u.data,face:g}}:u.parentId===t.id?{...u,data:{...u.data,view:g}}:u));return}if(t.type==="device"){let p=t.data||{},b=Array.isArray(p.rearPorts)&&p.rearPorts.length>0,g=Array.isArray(p.ports)&&p.ports.length>0,u=(p.view||(b&&!g?"rear":"front"))==="front"?"rear":"front";h?h(t.id,u):_(F=>F.map(Y=>Y.id===t.id?{...Y,data:{...Y.data,view:u}}:Y));}}},[ue,X,f,h,_,ke]),hr=Or.useMemo(()=>L.map(t=>{let p=t,b=X(String(p.source)),g=X(String(p.target)),N=ct(p.sourceHandle||"",b),u=ct(p.targetHandle||"",g),F=b&&b.data?.view,Y=g&&g.data?.view,U=b?.type==="device"&&F==="rear",te=g?.type==="device"&&Y==="rear",B=U&&N!=="rear"&&(te&&u!=="rear")?{...t.style,opacity:0,pointerEvents:"none",zIndex:0}:t.style;return {...t,style:B,className:lo.has(t.id)?"edge-connecting":t.className}}),[L,lo,X]);return jsxRuntime.jsxs("div",{ref:ae,className:`${m||""} ${E==="light"?"react-flow-light":"react-flow-dark"}`,style:{width:"100%",height:"100%",...v},children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:O,edges:hr,onNodesChange:t=>{rr(t),R?n&&n(ge.current):C.setState({nodes:ge.current});},onEdgesChange:t=>{let p=t.filter(b=>{if(b.type==="remove"){let g=z.current.find(N=>N.id===b.id);if(g){let N=g.sourceHandle||"",u=g.targetHandle||"";if(N.startsWith("tube-")||u.startsWith("tube-"))return s&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",g),false}}return true});p.length>0&&(j(p),R?i&&i(z.current):C.setState({edges:z.current}));},onConnect:dr,onConnectStart:fr,onConnectEnd:gr,onEdgeUpdate:cr,isValidConnection:sr,onNodeClick:lr,onNodeDoubleClick:pr,onNodeDragStart:nr,onNodeDrag:ir,onNodeDragStop:ar,onEdgeClick:ur,onInit:w,nodeTypes:tr,edgeTypes:or,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:true,nodesConnectable:true,elementsSelectable:true,selectNodesOnDrag:false,connectOnClick:M,fitView:true,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{color:E==="light"?"#e5e5e5":"#2a2a2a"}),jsxRuntime.jsx(reactflow.Controls,{}),jsxRuntime.jsx(reactflow.MiniMap,{}),jsxRuntime.jsx(reactflow.Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsxRuntime.jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),A&&jsxRuntime.jsx("button",{className:"download-button",onClick:gt,style:{position:"absolute",top:W.includes("top")?"10px":"auto",bottom:W.includes("bottom")?"10px":"auto",right:W.includes("right")?"10px":"auto",left:W.includes("left")?"10px":"auto",zIndex:1e3,background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:"4px",padding:"0.5rem 0.75rem",fontSize:"0.875rem",cursor:"pointer",transition:"all 0.2s ease",...H},children:x}),ue&&(ue.type==="rack"||ue.type==="device")&&jsxRuntime.jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsxRuntime.jsx("button",{onClick:t=>{t.preventDefault(),br();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let t=ue.data;if(ue.type==="rack")return (t?.face||"front")==="front"?"Switch to rear":"Switch to front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,b=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!b?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let t=ue.data;if(ue.type==="rack")return (t?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,b=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!b?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()})})]})},Hn=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(Sn,{...e})});var Ko=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,uHeight:e.u_height??e.units??42,inventoryId:e.id,inventoryType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:typeof e.site=="object"&&e.site?e.site.name:e.site,role:typeof e.role=="object"&&e.role?e.role.name:e.role,tenant:typeof e.tenant=="object"&&e.tenant?e.tenant.name:e.tenant}}),qo=e=>({id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${typeof e.rack=="object"&&e.rack?e.rack.id:e.rack}`:void 0,extent:e.rack?"parent":void 0,data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,deviceType:e.device_type?.model??e.model,manufacturer:e.device_type?.manufacturer?.name??e.manufacturer,role:typeof e.device_role=="object"&&e.device_role?e.device_role.name:e.role,uHeight:e.device_type?.u_height??e.u_height??1,uPosition:e.position||1,view:e.face||"front",inventoryId:e.id,inventoryType:"device",primaryIp4:typeof e.primary_ip4=="object"&&e.primary_ip4?e.primary_ip4.address:e.primary_ip4,primaryIp6:typeof e.primary_ip6=="object"&&e.primary_ip6?e.primary_ip6.address:e.primary_ip6,site:typeof e.site=="object"&&e.site?e.site.name:e.site,rack:typeof e.rack=="object"&&e.rack?e.rack.name:e.rack}}),Jo=e=>{let o=n=>{if(!n)return;if(typeof n=="string")return n;let i=n.device;return typeof i=="object"&&i?i.id:i},r=o(e.termination_a),a=o(e.termination_b);return {id:`cable-${e.id}`,source:`device-${r}`,target:`device-${a}`,type:"fiber",data:{bandwidth:e.type?.label??e.bandwidth,length:e.length||0,color:e.color,inventoryId:e.id,inventoryType:"cable",status:typeof e.status=="object"&&e.status?e.status.value:e.status,terminationA:typeof e.termination_a=="object"&&e.termination_a?e.termination_a.name:e.termination_a,terminationB:typeof e.termination_b=="object"&&e.termination_b?e.termination_b.name:e.termination_b}}},Cn=e=>{let o=[],r=[];return e.racks.forEach(a=>o.push(Ko(a))),e.devices.forEach(a=>o.push(qo(a))),e.cables.forEach(a=>r.push(Jo(a))),{nodes:o,edges:r}},En=e=>{let o=e.filter(n=>n.type==="rack"),r=e.filter(n=>n.type==="device"),a=e.filter(n=>!["rack","device"].includes(n.type));return o.forEach((n,i)=>{n.position={x:i*300,y:100};}),r.forEach(n=>{if(n.parentId){let i=o.find(d=>d.id===n.parentId);if(i){let d=n.data.uPosition||1,s=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+d*20-s*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),a.forEach((n,i)=>{n.position={x:i*150+100,y:300};}),e};var We=class extends Error{constructor(r,a,n,i,d){super(`Device placement conflict: ${a} at U${n}-${n+i-1} in rack ${r}${d?` conflicts with ${d}`:""}`);this.rackId=r;this.deviceId=a;this.uPosition=n;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function ro(e,o={}){let r=[],a=[];for(let n of e.devices)n.unit+n.height-1>e.units&&a.push({deviceId:n.id,uPosition:n.unit,uHeight:n.height,rackUHeight:e.units});for(let n=0;n<e.devices.length;n++){let i=e.devices[n],d=i.unit,s=i.unit+i.height-1;for(let c=n+1;c<e.devices.length;c++){let l=e.devices[c],h=l.unit,f=l.unit+l.height-1;d<=f&&s>=h&&r.push({deviceId:i.id,uPosition:i.unit,uHeight:i.height,conflictWith:l.id});}}return {isValid:r.length===0&&a.length===0,conflicts:r,outOfBounds:a}}function Qo(e,o,r={}){let{deviceTypeMapping:a={}}=r,n=a[e.type]||"device",i=De(o,e.unit,e.height);return {id:e.id,type:n,position:i,parentId:o.id,extent:"parent",data:{label:e.name,status:"active",deviceType:e.type,uHeight:e.height,uPosition:e.unit,width:e.width||"full",role:e.role,ports:e.ports,rearPorts:e.rearPorts,connections:e.connections}}}function Rn(e){return {id:e.id,type:"rack",position:e.position,data:{label:e.name,status:"active",uHeight:e.units,uNumberingDirection:e.uNumberingDirection||"bottom-up",customHeaderText:e.customHeaderText,ports:[]}}}function Tn(e,o={}){let{conflictPolicy:r="strict",validatePlacements:a=true}=o,n=[],i=[];if(a)for(let d of e){let s=ro(d,o);if(!s.isValid&&r==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new We(d.id,s.conflicts[0]?.deviceId||s.outOfBounds[0]?.deviceId||"unknown",s.conflicts[0]?.uPosition||s.outOfBounds[0]?.uPosition||1,s.conflicts[0]?.uHeight||s.outOfBounds[0]?.uHeight||1)}}for(let d of e){let s=Rn(d);n.push(s);for(let c of d.devices)try{let l=Qo(c,s,o);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let h=Ge(s,{id:c.id,data:{label:c.name,uHeight:c.height}},i,c.unit);if(h!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${h} due to conflict`);let f={...c,unit:h},m=Qo(f,s,o);i.push(m);}else throw new We(d.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function Dn(e){let o=[],r=e.filter(a=>a.type==="rack");for(let a of r){let i=e.filter(d=>d.type==="device"&&d.parentId===a.id).map(d=>({id:d.id,name:d.data.label,unit:d.data.uPosition||1,height:d.data.uHeight||1,type:d.data.deviceType||"server",width:d.data.width,ports:d.data.ports,connections:d.data.connections}));o.push({id:a.id,name:a.data.label,position:a.position,units:a.data.uHeight||42,uNumberingDirection:a.data.uNumberingDirection||"bottom-up",customHeaderText:a.data.customHeaderText,devices:i});}return o}function In(e,o,r,a){return e.map(n=>n.id!==o?n:{...n,devices:n.devices.map(i=>i.id!==r?i:{...i,unit:a})})}function $n(e,o,r,a={}){let{conflictPolicy:n="strict"}=a;return e.map(i=>{if(i.id!==o)return i;if(n==="strict"&&!ro({...i,devices:[...i.devices,r]},a).isValid)throw new We(o,r.id,r.unit,r.height);return {...i,devices:[...i.devices,r]}})}function _n(e,o,r){return e.map(a=>a.id!==o?a:{...a,devices:a.devices.filter(n=>n.id!==r)})}var ze=class extends Error{constructor(r,a,n,i){super(`Splice placement conflict: ${a} at holder ${n} in tray ${r}${i?` conflicts with ${i}`:""}`);this.trayId=r;this.spliceId=a;this.holder=n;this.conflictWith=i;this.name="SplicePlacementError";}};function no(e,o={}){let r=[],a=[];for(let n of e.splices)(n.holder<1||n.holder>Ne)&&a.push({spliceId:n.id,holder:n.holder,max:Ne});for(let n=0;n<e.splices.length;n++){let i=e.splices[n];for(let d=n+1;d<e.splices.length;d++){let s=e.splices[d];i.holder===s.holder&&r.push({spliceId:i.id,holder:i.holder,conflictWith:s.id});}}return {isValid:r.length===0&&a.length===0,conflicts:r,outOfBounds:a}}function er(e,o){let r=Me(o,e.holder);return {id:e.id,type:"splice",position:r,parentId:o.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb}}}function Fn(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function An(e,o={}){let{conflictPolicy:r="strict",validatePlacements:a=true}=o,n=[],i=[];if(a)for(let d of e){let s=no(d,o);if(!s.isValid&&r==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new ze(d.id,s.conflicts[0]?.spliceId||s.outOfBounds[0]?.spliceId||"unknown",s.conflicts[0]?.holder||s.outOfBounds[0]?.holder||1)}}for(let d of e){let s=Fn(d);n.push(s);for(let c of d.splices)try{let l=er(c,s);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let h=[...n,...i],f=et(s,{id:c.id,data:{label:c.name,holderPosition:c.holder}},h,c.holder);if(f!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${f} due to conflict`);let m={...c,holder:f},v=er(m,s);i.push(v);}else throw new ze(d.id,c.id,c.holder)}}}return n.push(...i),n}function Wn(e){let o=[],r=e.filter(a=>a.type==="splice-tray");for(let a of r){let i=e.filter(d=>d.type==="splice"&&d.parentId===a.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb}));o.push({id:a.id,name:a.data.label,position:a.position,splices:i});}return o}function zn(e,o,r,a){return e.map(n=>n.id!==o?n:{...n,splices:n.splices.map(i=>i.id!==r?i:{...i,holder:a})})}function Ln(e,o,r,a={}){let{conflictPolicy:n="strict"}=a;return e.map(i=>{if(i.id!==o)return i;if(n==="strict"&&!no({...i,splices:[...i.splices,r]},a).isValid)throw new ze(o,r.id,r.holder);return {...i,splices:[...i.splices,r]}})}function Mn(e,o,r){return e.map(a=>a.id!==o?a:{...a,splices:a.splices.filter(n=>n.id!==r)})}
|
|
2
|
+
exports.COUPLERS_PER_PANEL=jr;exports.COUPLER_SLOT_HEIGHT_PX=st;exports.COUPLER_WIDTH_PX=Gr;exports.CableNode=Ut;exports.ClosureNode=Kt;exports.CouplerNode=Bt;exports.DeviceNode=Et;exports.DevicePlacementError=We;exports.FIBER_COLORS_12=Co;exports.FiberEdge=kt;exports.FiberNode=wt;exports.NetworkDiagram=Hn;exports.PANEL_BORDER_WIDTH=Wo;exports.PANEL_HEADER_HEIGHT=Ee;exports.PANEL_HEIGHT_PX=at;exports.PANEL_PADDING=he;exports.PANEL_TUBE_TRAY_SPACING=zo;exports.PANEL_WIDTH_PX=it;exports.POWER_CONNECTORS=St;exports.PatchPanelNode=jt;exports.PowerEdge=vt;exports.RackNode=xt;exports.SpliceNode=It;exports.SplicePlacementError=ze;exports.SpliceTrayNode=zt;exports.TubeNode=Mt;exports.VerticalPDU=Rt;exports.Width=No;exports.addDeviceToRack=$n;exports.addSpliceToTray=Ln;exports.baseColorFor=oe;exports.buildNodesFromRackConfig=Tn;exports.buildNodesFromSpliceConfig=An;exports.calculateCouplerRightX=Kr;exports.calculateCouplerSlotSpacing=Jr;exports.calculateCouplerSpacing=Yo;exports.calculateDevicePositionFromU=De;exports.calculatePanelDimensions=Yt;exports.calculateSlotPositionFromY=Bo;exports.calculateSplicePositionFromNumber=Me;exports.calculateYFromSlotPosition=Oo;exports.createNetworkDiagramStore=qt;exports.createRackConfigFromNodes=Dn;exports.createSpliceConfigFromNodes=Wn;exports.fiberSolidOrStriped=Ue;exports.findNearestRack=pt;exports.findNextAvailableHolderPosition=et;exports.findNextAvailableUPosition=Ge;exports.generateLayout=En;exports.getConnectorConfig=Je;exports.getCouplerDimensions=Ot;exports.getDeviceConnectorType=Qe;exports.getFiberColor=Lt;exports.getInnerContentWidth=Uo;exports.getPDUPortType=Ht;exports.getPanelHeight=Zr;exports.getPanelWidth=Mo;exports.getPowerPortStyle=Ie;exports.getRackBounds=jo;exports.getStatusColor=ce;exports.getTrayDimensions=Lo;exports.getTubeDimensions=dt;exports.inventoryCableToNetworkEdge=Jo;exports.inventoryDeviceToNetworkNode=qo;exports.inventoryRackToNetworkNode=Ko;exports.inventoryToNetworkDiagram=Cn;exports.isHighPowerConnector=Lr;exports.isPointInRack=lt;exports.isStriped=Eo;exports.isUPositionAvailable=yt;exports.removeDeviceFromRack=_n;exports.removeSpliceFromTray=Mn;exports.replaceEdge=G;exports.snapToCouplerPosition=qr;exports.snapToSplicePosition=Ft;exports.snapToUPosition=mt;exports.updateDeviceUPosition=fo;exports.updateDeviceUPositionInSchema=In;exports.updateSpliceHolderPosition=zn;exports.useDiagramEdges=eo;exports.useDiagramNodes=Qt;exports.useNetworkDiagram=cn;exports.validateAndSnapDevice=yr;exports.validateRackDevicePlacements=ro;exports.validateSplicePlacements=no;//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|