@nice2dev/ui-diagrams 1.1.9 → 1.1.10
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.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),v=require("@nice2dev/ui"),b=require("react");class At{constructor(e){this.liquidFlows=new Map,this.glowStates=new Map,this.particles=[],this.emitters=[],this.rafId=0,this.running=!1,this.lastTime=0,this.tick=()=>{if(!this.running)return;const t=performance.now(),i=Math.min((t-this.lastTime)/1e3,.1);this.lastTime=t;for(const[,a]of this.liquidFlows)if(a.active){a.gradientOffset=(a.gradientOffset+i*.5)%1;for(const o of a.particles)o.t=(o.t+i*.3)%1,o.offset+=(Math.random()-.5)*i*2,o.offset=Math.max(-4,Math.min(4,o.offset)),o.opacity=.3+Math.sin(o.t*Math.PI)*.5}for(const[,a]of this.glowStates)a.pulse=(a.pulse+i*2)%(Math.PI*2);this.particles=this.particles.filter(a=>(a.life-=i/a.maxLife,a.life<=0?!1:(a.x+=a.vx*i,a.y+=a.vy*i,a.opacity=Math.min(1,a.life*2),!0)));for(const a of this.emitters)for(a.accumulator=(a.accumulator??0)+i*a.rate;a.accumulator>=1;){a.accumulator-=1;const o=Math.random()*Math.PI*2,c=a.speed*(.5+Math.random());this.particles.push({x:a.position.x+(Math.random()-.5)*a.spread,y:a.position.y+(Math.random()-.5)*a.spread,vx:Math.cos(o)*c,vy:Math.sin(o)*c,life:1,maxLife:a.particleLife,size:a.particleSize*(.5+Math.random()),color:a.color,opacity:1})}this.onFrame(this.getState()),this.rafId=requestAnimationFrame(this.tick)},this.onFrame=e}startLiquidFlow(e,t){const i=[],a=t.particleDensity??3;for(let o=0;o<a;o++)i.push({t:Math.random(),offset:(Math.random()-.5)*(t.pipeWidth??6),size:1.5+Math.random()*2,opacity:.4+Math.random()*.5});this.liquidFlows.set(e,{edgeId:e,gradientOffset:0,fillProgress:t.progress??0,particles:i,active:!0}),this.running||this.start()}stopLiquidFlow(e){this.liquidFlows.delete(e),this.liquidFlows.size===0&&this.glowStates.size===0&&this.emitters.length===0&&this.stop()}setGlow(e,t,i){this.glowStates.set(e,{elementId:e,color:t,intensity:i,pulse:0}),this.running||this.start()}removeGlow(e){this.glowStates.delete(e)}addEmitter(e){return this.emitters.push(e),this.running||this.start(),e.id}removeEmitter(e){this.emitters=this.emitters.filter(t=>t.id!==e)}start(){this.running||(this.running=!0,this.lastTime=performance.now(),this.tick())}stop(){this.running=!1,this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=0}destroy(){this.stop(),this.liquidFlows.clear(),this.glowStates.clear(),this.particles=[],this.emitters=[]}isRunning(){return this.running}getState(){return{liquidFlows:new Map(this.liquidFlows),glowStates:new Map(this.glowStates),particles:[...this.particles]}}}function hr(r,e,t){if(!t)return{x:0,y:0};const i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",r),t.appendChild(i);try{const a=i.getTotalLength(),o=i.getPointAtLength(e*a);return{x:o.x,y:o.y}}finally{t.removeChild(i)}}function $t(r){return`nd-glow-${r.replace(/[^a-zA-Z0-9]/g,"_")}`}function Dt(r,e){const t=r*12,i=1+Math.sin(e)*.3;return t*i}function ft(r,e){const t=(e==null?void 0:e.scale)??1,i=(e==null?void 0:e.background)??"transparent";let a=1/0,o=1/0,c=-1/0,s=-1/0;for(const h of r.nodes)a=Math.min(a,h.position.x),o=Math.min(o,h.position.y),c=Math.max(c,h.position.x+h.size.width),s=Math.max(s,h.position.y+h.size.height);r.nodes.length===0&&(a=o=0,c=s=100);const l=40,u=(c-a+l*2)*t,d=(s-o+l*2)*t,m=-a+l,p=-o+l,g=[];g.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${u} ${d}" width="${u}" height="${d}">`),g.push("<defs>"),g.push('<marker id="arrowhead" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">'),g.push(' <polygon points="0 0, 10 3.5, 0 7" fill="#666" />'),g.push("</marker>"),g.push("</defs>"),i!=="transparent"&&g.push(`<rect width="${u}" height="${d}" fill="${i}" />`),g.push(`<g transform="translate(${m*t}, ${p*t}) scale(${t})">`);for(const h of r.edges){const x=r.nodes.find(L=>L.id===h.sourceNodeId),w=r.nodes.find(L=>L.id===h.targetNodeId);if(!x||!w)continue;const y=x.position.x+x.size.width/2,S=x.position.y+x.size.height/2,M=w.position.x+w.size.width/2,I=w.position.y+w.size.height/2,N=h.style.strokeColor??"#666",k=h.style.strokeWidth??2,T=h.style.targetArrow!=="none"?' marker-end="url(#arrowhead)"':"";if(h.style.lineType==="bezier"){const L=(y+M)/2,O=S,F=(y+M)/2,W=I;g.push(`<path d="M${y},${S} C${L},${O} ${F},${W} ${M},${I}" fill="none" stroke="${N}" stroke-width="${k}"${T} />`)}else g.push(`<line x1="${y}" y1="${S}" x2="${M}" y2="${I}" stroke="${N}" stroke-width="${k}"${T} />`);if(h.label){const L=(y+M)/2,O=(S+I)/2;g.push(`<text x="${L}" y="${O-6}" text-anchor="middle" font-size="12" fill="#333">${kt(h.label)}</text>`)}}for(const h of r.nodes){const{x,y:w}=h.position,{width:y,height:S}=h.size,M=h.style.backgroundColor??"#fff",I=h.style.borderColor??"#ccc",N=h.style.borderWidth??1,k=h.style.borderRadius??(h.shape==="roundedRect"?8:0),T=h.style.fontColor??"#333",L=h.style.fontSize??14;switch(h.shape){case"ellipse":case"circle":g.push(`<ellipse cx="${x+y/2}" cy="${w+S/2}" rx="${y/2}" ry="${S/2}" fill="${M}" stroke="${I}" stroke-width="${N}" />`);break;case"diamond":g.push(`<polygon points="${x+y/2},${w} ${x+y},${w+S/2} ${x+y/2},${w+S} ${x},${w+S/2}" fill="${M}" stroke="${I}" stroke-width="${N}" />`);break;default:g.push(`<rect x="${x}" y="${w}" width="${y}" height="${S}" rx="${k}" fill="${M}" stroke="${I}" stroke-width="${N}" />`)}g.push(`<text x="${x+y/2}" y="${w+S/2+L/3}" text-anchor="middle" font-size="${L}" fill="${T}" font-family="sans-serif">${kt(h.label)}</text>`)}return g.push("</g>"),g.push("</svg>"),g.join(`
|
|
2
2
|
`)}function Tt(r){const e=[],t=r.diagramType==="orgchart"||r.diagramType==="mindmap"?"graph TB":r.diagramType==="stateMachine"?"stateDiagram-v2":"flowchart TD";e.push(t);for(const i of r.nodes){const a=lt(i.id),o=i.label.replace(/"/g,"'");switch(i.shape){case"diamond":e.push(` ${a}{${o}}`);break;case"circle":case"ellipse":e.push(` ${a}((${o}))`);break;case"cylinder":e.push(` ${a}[(${o})]`);break;default:e.push(` ${a}["${o}"]`)}}for(const i of r.edges){const a=lt(i.sourceNodeId),o=lt(i.targetNodeId),c=i.label?`|${i.label}|`:"",s=i.style.targetArrow==="none"?"---":"-->";e.push(` ${a} ${s}${c} ${o}`)}return e.join(`
|
|
3
|
-
`)}function lt(r){return r.replace(/[^a-zA-Z0-9_]/g,"_")}function kt(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const _t={en:{"toolbar.select":"Select","toolbar.addNode":"Add Node","toolbar.addEdge":"Add Edge","toolbar.group":"Group","toolbar.ungroup":"Ungroup","toolbar.delete":"Delete","toolbar.undo":"Undo","toolbar.redo":"Redo","toolbar.zoomIn":"Zoom In","toolbar.zoomOut":"Zoom Out","toolbar.fitToScreen":"Fit to Screen","toolbar.export":"Export","toolbar.import":"Import","toolbar.autoLayout":"Auto Layout","toolbar.animations":"Animations","toolbar.dataBinding":"Data Binding","toolbar.pan":"Pan","toolbar.zoomReset":"Reset Zoom","toolbar.layout":"Layout","layout.dagre":"Hierarchical","layout.forceDirected":"Force-Directed","layout.grid":"Grid","layout.radial":"Radial","layout.tree":"Tree","panel.properties":"Properties","panel.style":"Style","panel.animations":"Animations","panel.data":"Data","panel.noSelection":"Select an element to edit its properties","panel.nodeProperties":"Node Properties","panel.edgeProperties":"Edge Properties","node.label":"Label","node.description":"Description","node.shape":"Shape","node.color":"Color","node.border":"Border","node.width":"Width","node.height":"Height","node.bgColor":"Background","node.borderColor":"Border Color","node.fontSize":"Font Size","node.fontColor":"Font Color","node.locked":"Locked","edge.label":"Label","edge.lineType":"Line Type","edge.arrow":"Arrow","edge.color":"Color","edge.width":"Thickness","edge.animated":"Animated","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Native)","viewer.fullscreen":"Fullscreen","viewer.playAnimations":"Play Animations","viewer.stopAnimations":"Stop","viewer.print":"Print","animation.timeline":"Timeline","animation.play":"Play","animation.stop":"Stop","animation.add":"Add","animation.noAnimations":"No animations yet",untitled:"Untitled Diagram"},pl:{"toolbar.select":"Zaznacz","toolbar.addNode":"Dodaj węzeł","toolbar.addEdge":"Dodaj połączenie","toolbar.group":"Grupuj","toolbar.ungroup":"Rozgrupuj","toolbar.delete":"Usuń","toolbar.undo":"Cofnij","toolbar.redo":"Ponów","toolbar.zoomIn":"Powiększ","toolbar.zoomOut":"Pomniejsz","toolbar.fitToScreen":"Dopasuj do ekranu","toolbar.export":"Eksportuj","toolbar.import":"Importuj","toolbar.autoLayout":"Auto układ","toolbar.animations":"Animacje","toolbar.dataBinding":"Dane","toolbar.pan":"Przesuń","toolbar.zoomReset":"Przywróć powiększenie","toolbar.layout":"Układ","layout.dagre":"Hierarchiczny","layout.forceDirected":"Siłowy","layout.grid":"Siatka","layout.radial":"Promieniowy","layout.tree":"Drzewo","panel.properties":"Właściwości","panel.style":"Styl","panel.animations":"Animacje","panel.data":"Dane","panel.noSelection":"Zaznacz element, aby edytować jego właściwości","panel.nodeProperties":"Właściwości węzła","panel.edgeProperties":"Właściwości połączenia","node.label":"Etykieta","node.description":"Opis","node.shape":"Kształt","node.color":"Kolor","node.border":"Obramowanie","node.width":"Szerokość","node.height":"Wysokość","node.bgColor":"Tło","node.borderColor":"Kolor obramowania","node.fontSize":"Rozmiar czcionki","node.fontColor":"Kolor czcionki","node.locked":"Zablokowany","edge.label":"Etykieta","edge.lineType":"Typ linii","edge.arrow":"Strzałka","edge.color":"Kolor","edge.width":"Grubość","edge.animated":"Animowane","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Natywny)","viewer.fullscreen":"Pełny ekran","viewer.playAnimations":"Odtwórz animacje","viewer.stopAnimations":"Zatrzymaj","viewer.print":"Drukuj","animation.timeline":"Oś czasu","animation.play":"Odtwórz","animation.stop":"Zatrzymaj","animation.add":"Dodaj","animation.noAnimations":"Brak animacji",untitled:"Diagram bez nazwy"},de:{"toolbar.select":"Auswählen","toolbar.addNode":"Knoten hinzufügen","toolbar.addEdge":"Kante hinzufügen","toolbar.group":"Gruppieren","toolbar.ungroup":"Gruppierung aufheben","toolbar.delete":"Löschen","toolbar.undo":"Rückgängig","toolbar.redo":"Wiederholen","toolbar.zoomIn":"Vergrößern","toolbar.zoomOut":"Verkleinern","toolbar.fitToScreen":"An Bildschirm anpassen","toolbar.export":"Exportieren","toolbar.import":"Importieren","toolbar.autoLayout":"Automatisches Layout","toolbar.animations":"Animationen","toolbar.dataBinding":"Datenbindung","toolbar.pan":"Verschieben","toolbar.zoomReset":"Zoom zurücksetzen","toolbar.layout":"Layout","layout.dagre":"Hierarchisch","layout.forceDirected":"Kräftebasiert","layout.grid":"Raster","layout.radial":"Radial","layout.tree":"Baum","panel.properties":"Eigenschaften","panel.style":"Stil","panel.animations":"Animationen","panel.data":"Daten","panel.noSelection":"Wählen Sie ein Element aus, um seine Eigenschaften zu bearbeiten","panel.nodeProperties":"Knoteneigenschaften","panel.edgeProperties":"Kanteneigenschaften","node.label":"Bezeichnung","node.description":"Beschreibung","node.shape":"Form","node.color":"Farbe","node.border":"Rahmen","node.width":"Breite","node.height":"Höhe","node.bgColor":"Hintergrund","node.borderColor":"Rahmenfarbe","node.fontSize":"Schriftgröße","node.fontColor":"Schriftfarbe","node.locked":"Gesperrt","edge.label":"Bezeichnung","edge.lineType":"Linientyp","edge.arrow":"Pfeil","edge.color":"Farbe","edge.width":"Stärke","edge.animated":"Animiert","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Nativ)","viewer.fullscreen":"Vollbild","viewer.playAnimations":"Animationen abspielen","viewer.stopAnimations":"Stopp","viewer.print":"Drucken","animation.timeline":"Zeitleiste","animation.play":"Abspielen","animation.stop":"Stopp","animation.add":"Hinzufügen","animation.noAnimations":"Noch keine Animationen",untitled:"Unbenanntes Diagramm"},fr:{"toolbar.select":"Sélectionner","toolbar.addNode":"Ajouter un nœud","toolbar.addEdge":"Ajouter une arête","toolbar.group":"Grouper","toolbar.ungroup":"Dégrouper","toolbar.delete":"Supprimer","toolbar.undo":"Annuler","toolbar.redo":"Rétablir","toolbar.zoomIn":"Agrandir","toolbar.zoomOut":"Réduire","toolbar.fitToScreen":"Ajuster à l'écran","toolbar.export":"Exporter","toolbar.import":"Importer","toolbar.autoLayout":"Mise en page auto","toolbar.animations":"Animations","toolbar.dataBinding":"Liaison de données","toolbar.pan":"Déplacer","toolbar.zoomReset":"Réinitialiser le zoom","toolbar.layout":"Disposition","layout.dagre":"Hiérarchique","layout.forceDirected":"Force dirigée","layout.grid":"Grille","layout.radial":"Radial","layout.tree":"Arbre","panel.properties":"Propriétés","panel.style":"Style","panel.animations":"Animations","panel.data":"Données","panel.noSelection":"Sélectionnez un élément pour modifier ses propriétés","panel.nodeProperties":"Propriétés du nœud","panel.edgeProperties":"Propriétés de l'arête","node.label":"Étiquette","node.description":"Description","node.shape":"Forme","node.color":"Couleur","node.border":"Bordure","node.width":"Largeur","node.height":"Hauteur","node.bgColor":"Arrière-plan","node.borderColor":"Couleur de bordure","node.fontSize":"Taille de police","node.fontColor":"Couleur de police","node.locked":"Verrouillé","edge.label":"Étiquette","edge.lineType":"Type de ligne","edge.arrow":"Flèche","edge.color":"Couleur","edge.width":"Épaisseur","edge.animated":"Animée","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Natif)","viewer.fullscreen":"Plein écran","viewer.playAnimations":"Lire les animations","viewer.stopAnimations":"Arrêter","viewer.print":"Imprimer","animation.timeline":"Chronologie","animation.play":"Lire","animation.stop":"Arrêter","animation.add":"Ajouter","animation.noAnimations":"Aucune animation",untitled:"Diagramme sans titre"},es:{"toolbar.select":"Seleccionar","toolbar.addNode":"Añadir nodo","toolbar.addEdge":"Añadir arista","toolbar.group":"Agrupar","toolbar.ungroup":"Desagrupar","toolbar.delete":"Eliminar","toolbar.undo":"Deshacer","toolbar.redo":"Rehacer","toolbar.zoomIn":"Ampliar","toolbar.zoomOut":"Reducir","toolbar.fitToScreen":"Ajustar a pantalla","toolbar.export":"Exportar","toolbar.import":"Importar","toolbar.autoLayout":"Diseño automático","toolbar.animations":"Animaciones","toolbar.dataBinding":"Enlace de datos","toolbar.pan":"Desplazar","toolbar.zoomReset":"Restablecer zoom","toolbar.layout":"Diseño","layout.dagre":"Jerárquico","layout.forceDirected":"Fuerza dirigida","layout.grid":"Cuadrícula","layout.radial":"Radial","layout.tree":"Árbol","panel.properties":"Propiedades","panel.style":"Estilo","panel.animations":"Animaciones","panel.data":"Datos","panel.noSelection":"Selecciona un elemento para editar sus propiedades","panel.nodeProperties":"Propiedades del nodo","panel.edgeProperties":"Propiedades de la arista","node.label":"Etiqueta","node.description":"Descripción","node.shape":"Forma","node.color":"Color","node.border":"Borde","node.width":"Ancho","node.height":"Alto","node.bgColor":"Fondo","node.borderColor":"Color del borde","node.fontSize":"Tamaño de fuente","node.fontColor":"Color de fuente","node.locked":"Bloqueado","edge.label":"Etiqueta","edge.lineType":"Tipo de línea","edge.arrow":"Flecha","edge.color":"Color","edge.width":"Grosor","edge.animated":"Animada","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Nativo)","viewer.fullscreen":"Pantalla completa","viewer.playAnimations":"Reproducir animaciones","viewer.stopAnimations":"Detener","viewer.print":"Imprimir","animation.timeline":"Línea de tiempo","animation.play":"Reproducir","animation.stop":"Detener","animation.add":"Añadir","animation.noAnimations":"Sin animaciones",untitled:"Diagrama sin título"}},Pt=b.createContext({locale:"en",t:(r,e)=>e??r});function pt({locale:r="en",overrides:e,children:t}){const i=b.useMemo(()=>{const a={..._t.en,..._t[r],...e};return{locale:r,t:(c,s)=>a[c]??s??c}},[r,e]);return b.createElement(Pt.Provider,{value:i},t)}function Ee(){return b.useContext(Pt)}function pr(r){const e=[];let t;try{t=JSON.parse(r)}catch{return{ok:!1,errors:["Invalid JSON: parse failed"]}}if(typeof t!="object"||t===null||Array.isArray(t))return{ok:!1,errors:["Root must be a JSON object"]};const i=t;if(i.version!=="1.0"&&e.push(`Unsupported version "${String(i.version)}", expected "1.0"`),(typeof i.id!="string"||i.id.length===0)&&e.push('Missing or invalid "id" field'),typeof i.title!="string"&&e.push('Missing or invalid "title" field'),Array.isArray(i.nodes)||e.push('Missing or invalid "nodes" array'),Array.isArray(i.edges)||e.push('Missing or invalid "edges" array'),Array.isArray(i.nodes)&&Array.isArray(i.edges)){const a=new Set(i.nodes.map(o=>o.id).filter(Boolean));for(const o of i.edges)o.sourceNodeId&&!a.has(o.sourceNodeId)&&e.push(`Edge "${o.id}" references non-existent source node "${o.sourceNodeId}"`),o.targetNodeId&&!a.has(o.targetNodeId)&&e.push(`Edge "${o.id}" references non-existent target node "${o.targetNodeId}"`)}return e.length>0?{ok:!1,errors:e}:{ok:!0,document:t,errors:[]}}function Rt(r,e=!0){return JSON.stringify(r,null,e?2:void 0)}class Je{constructor(e){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.maxHistory=100,this.doc=e??Je.createEmpty()}static createEmpty(e="flowchart"){const t=new Date().toISOString();return{version:"1.0",id:De(),title:"Untitled Diagram",diagramType:e,nodes:[],edges:[],groups:[],animations:[],viewport:{x:0,y:0,zoom:1},metadata:{createdAt:t,updatedAt:t}}}getDocument(){return this.doc}getNodes(){return this.doc.nodes}getEdges(){return this.doc.edges}getGroups(){return this.doc.groups}getAnimations(){return this.doc.animations}getNodeById(e){return this.doc.nodes.find(t=>t.id===e)}getEdgeById(e){return this.doc.edges.find(t=>t.id===e)}getViewport(){return{...this.doc.viewport}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){this.doc.metadata.updatedAt=new Date().toISOString(),this.listeners.forEach(e=>e())}pushUndo(e){this.undoStack.push({label:e,snapshot:JSON.stringify(this.doc)}),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack=[]}undo(){const e=this.undoStack.pop();return e?(this.redoStack.push({label:"redo",snapshot:JSON.stringify(this.doc)}),this.doc=JSON.parse(e.snapshot),this.notify(),!0):!1}redo(){const e=this.redoStack.pop();return e?(this.undoStack.push({label:"undo",snapshot:JSON.stringify(this.doc)}),this.doc=JSON.parse(e.snapshot),this.notify(),!0):!1}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}addNode(e,t,i="roundedRect",a={width:160,height:60}){this.pushUndo("Add node");const o=mr(),c={id:De(),label:e,position:t,size:a,shape:i,style:{},ports:o};return this.doc.nodes.push(c),this.notify(),c}updateNode(e,t){this.pushUndo("Update node");const i=this.doc.nodes.find(a=>a.id===e);i&&Object.assign(i,t),this.notify()}moveNode(e,t){const i=this.doc.nodes.find(a=>a.id===e);i&&(this.pushUndo("Move node"),i.position=t,this.notify())}resizeNode(e,t){const i=this.doc.nodes.find(a=>a.id===e);i&&(this.pushUndo("Resize node"),i.size=t,this.notify())}removeNode(e){this.pushUndo("Remove node"),this.doc.nodes=this.doc.nodes.filter(t=>t.id!==e),this.doc.edges=this.doc.edges.filter(t=>t.sourceNodeId!==e&&t.targetNodeId!==e),this.doc.groups.forEach(t=>{t.nodeIds=t.nodeIds.filter(i=>i!==e)}),this.doc.animations=this.doc.animations.filter(t=>t.targetId!==e),this.notify()}addEdge(e,t,i,a,o){if(e===i||!this.getNodeById(e)||!this.getNodeById(i))return null;this.pushUndo("Add edge");const c={id:De(),sourceNodeId:e,sourcePortId:t,targetNodeId:i,targetPortId:a,label:o,style:{lineType:"bezier",targetArrow:"arrow"}};return this.doc.edges.push(c),this.notify(),c}updateEdge(e,t){this.pushUndo("Update edge");const i=this.doc.edges.find(a=>a.id===e);i&&Object.assign(i,t),this.notify()}removeEdge(e){this.pushUndo("Remove edge"),this.doc.edges=this.doc.edges.filter(t=>t.id!==e),this.doc.animations=this.doc.animations.filter(t=>t.targetId!==e),this.notify()}createGroup(e,t){this.pushUndo("Create group");const i={id:De(),label:e,nodeIds:[...t]};return t.forEach(a=>{const o=this.doc.nodes.find(c=>c.id===a);o&&(o.groupId=i.id)}),this.doc.groups.push(i),this.notify(),i}removeGroup(e){this.pushUndo("Remove group");const t=this.doc.groups.find(i=>i.id===e);t&&t.nodeIds.forEach(i=>{const a=this.doc.nodes.find(o=>o.id===i);a&&(a.groupId=void 0)}),this.doc.groups=this.doc.groups.filter(i=>i.id!==e),this.notify()}addAnimation(e){this.pushUndo("Add animation");const t={id:De(),...e};return this.doc.animations.push(t),this.notify(),t}removeAnimation(e){this.pushUndo("Remove animation"),this.doc.animations=this.doc.animations.filter(t=>t.id!==e),this.notify()}setViewport(e){this.doc.viewport={...e},this.notify()}toggleGroupCollapse(e){const t=this.doc.groups.find(i=>i.id===e);t&&(this.pushUndo("Toggle group collapse"),t.collapsed=!t.collapsed,t.nodeIds.forEach(i=>{const a=this.doc.nodes.find(o=>o.id===i);a&&(a.hidden=t.collapsed)}),this.notify())}toggleNodeCollapse(e){const t=this.doc.nodes.find(i=>i.id===e);t&&(this.pushUndo("Toggle node collapse"),t.collapsed=!t.collapsed,(t.childNodeIds??[]).forEach(i=>{const a=this.doc.nodes.find(o=>o.id===i);a&&(a.hidden=t.collapsed)}),this.notify())}getAnimationModes(){return this.doc.animationModes??[]}getActiveAnimationMode(){var e;if((e=this.doc.animationModes)!=null&&e.length)return this.doc.animationModes.find(t=>t.id===this.doc.activeAnimationModeId)??this.doc.animationModes.find(t=>t.isDefault)??this.doc.animationModes[0]}addAnimationMode(e,t){this.pushUndo("Add animation mode"),this.doc.animationModes||(this.doc.animationModes=[]);const i={id:De(),name:e,animations:t??[],isDefault:this.doc.animationModes.length===0};return this.doc.animationModes.push(i),i.isDefault&&(this.doc.activeAnimationModeId=i.id),this.notify(),i}removeAnimationMode(e){var t;this.doc.animationModes&&(this.pushUndo("Remove animation mode"),this.doc.animationModes=this.doc.animationModes.filter(i=>i.id!==e),this.doc.activeAnimationModeId===e&&(this.doc.activeAnimationModeId=(t=this.doc.animationModes[0])==null?void 0:t.id),this.notify())}setActiveAnimationMode(e){var t;(t=this.doc.animationModes)!=null&&t.find(i=>i.id===e)&&(this.doc.activeAnimationModeId=e,this.notify())}addAnimationToMode(e,t){var o;const i=(o=this.doc.animationModes)==null?void 0:o.find(c=>c.id===e);if(!i)return null;this.pushUndo("Add animation to mode");const a={id:De(),...t};return i.animations.push(a),this.notify(),a}removeAnimationFromMode(e,t){var a;const i=(a=this.doc.animationModes)==null?void 0:a.find(o=>o.id===e);i&&(this.pushUndo("Remove animation from mode"),i.animations=i.animations.filter(o=>o.id!==t),this.notify())}setStylePreset(e){this.pushUndo("Set style preset"),this.doc.stylePresetId=e,this.notify()}setStyleOverrides(e){this.pushUndo("Set style overrides"),this.doc.styleOverrides=e,this.notify()}getPlayerConfig(){return this.doc.playerConfig??{mode:"editor",interactionsEnabled:!0,showModeSwitcher:!0,showPlaybackControls:!0,autoPlay:!1,showGhostElements:!0,ghostOpacity:.15,ghostCursorStyle:"pointer"}}setPlayerConfig(e){this.pushUndo("Update player config"),this.doc.playerConfig={...this.getPlayerConfig(),...e},this.notify()}setViewMode(e){const t=this.getPlayerConfig();t.mode=e,this.doc.playerConfig=t,this.notify()}updateAnimation(e,t){this.pushUndo("Update animation");const i=this.doc.animations.find(a=>a.id===e);i&&Object.assign(i,t),this.notify()}loadDocument(e){this.doc=structuredClone(e),this.undoStack=[],this.redoStack=[],this.notify()}}function De(){return`ndd_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function mr(){return[{id:"top",side:"top",offset:.5},{id:"right",side:"right",offset:.5},{id:"bottom",side:"bottom",offset:.5},{id:"left",side:"left",offset:.5}]}function Ot(r,e,t){switch(t.algorithm){case"dagre":return Et(r,e,t);case"grid":return gr(r,t);case"radial":return yr(r,e);case"tree":return br(r,e,t);case"forceDirected":return xr(r,e,t);case"manual":default:return{positions:new Map(r.map(i=>[i.id,{...i.position}]))}}}function Et(r,e,t){const i=t.direction??"TB",a=t.nodeSpacing??60,o=t.rankSpacing??100,c=new Map,s=new Map,l=new Set(r.map(y=>y.id));r.forEach(y=>{c.set(y.id,[]),s.set(y.id,[])}),e.forEach(y=>{l.has(y.sourceNodeId)&&l.has(y.targetNodeId)&&(c.get(y.sourceNodeId).push(y.targetNodeId),s.get(y.targetNodeId).push(y.sourceNodeId))});const u=r.filter(y=>{var S;return(((S=s.get(y.id))==null?void 0:S.length)??0)===0});u.length===0&&r.length>0&&u.push(r[0]);const d=new Map,m=[];for(u.forEach(y=>{d.set(y.id,0),m.push(y.id)});m.length>0;){const y=m.shift(),S=d.get(y)??0;for(const M of c.get(y)??[])d.has(M)||(d.set(M,S+1),m.push(M))}r.forEach(y=>{d.has(y.id)||d.set(y.id,0)});const p=new Map;r.forEach(y=>{const S=d.get(y.id)??0;p.has(S)||p.set(S,[]),p.get(S).push(y)});const g=new Map,h=i==="LR"||i==="RL",x=i==="BT"||i==="RL";return[...p.keys()].sort((y,S)=>y-S).forEach((y,S)=>{const M=p.get(y);let N=-(M.reduce((k,T)=>k+T.size.width,0)+(M.length-1)*a)/2;M.forEach(k=>{const T=S*(o+(h?k.size.width:k.size.height)),L=N+k.size.width/2;let O,F;h?(O=x?-T:T,F=L):(O=L,F=x?-T:T),g.set(k.id,{x:O,y:F}),N+=k.size.width+a})}),t.centerGraph&&mt(g),{positions:g}}function gr(r,e){const t=e.nodeSpacing??80,i=Math.ceil(Math.sqrt(r.length)),a=new Map;return r.forEach((o,c)=>{const s=c%i,l=Math.floor(c/i);a.set(o.id,{x:s*(o.size.width+t),y:l*(o.size.height+t)})}),e.centerGraph&&mt(a),{positions:a}}function yr(r,e){const t=new Map;if(r.length===0)return{positions:t};const i=new Map;r.forEach(l=>i.set(l.id,0)),e.forEach(l=>{i.set(l.sourceNodeId,(i.get(l.sourceNodeId)??0)+1),i.set(l.targetNodeId,(i.get(l.targetNodeId)??0)+1)});const a=[...r].sort((l,u)=>(i.get(u.id)??0)-(i.get(l.id)??0)),o=a[0];t.set(o.id,{x:0,y:0});const c=a.slice(1),s=200+c.length*20;return c.forEach((l,u)=>{const d=2*Math.PI*u/c.length;t.set(l.id,{x:Math.cos(d)*s,y:Math.sin(d)*s})}),{positions:t}}function br(r,e,t){return Et(r,e,{...t,direction:t.direction??"TB",nodeSpacing:t.nodeSpacing??40,rankSpacing:t.rankSpacing??80})}function xr(r,e,t){const i=new Map;if(r.length===0)return{positions:i};const a=400,o=new Map;r.forEach(m=>{o.set(m.id,{x:(Math.random()-.5)*a,y:(Math.random()-.5)*a})});const c=e.map(m=>({source:m.sourceNodeId,target:m.targetNodeId})),s=t.nodeSpacing??150,l=80,u=.95;let d=a/2;for(let m=0;m<l;m++){const p=new Map;r.forEach(g=>p.set(g.id,{fx:0,fy:0}));for(let g=0;g<r.length;g++)for(let h=g+1;h<r.length;h++){const x=o.get(r[g].id),w=o.get(r[h].id),y=w.x-x.x,S=w.y-x.y,M=Math.max(Math.sqrt(y*y+S*S),1),I=s*s/M,N=y/M*I,k=S/M*I;p.get(r[g].id).fx-=N,p.get(r[g].id).fy-=k,p.get(r[h].id).fx+=N,p.get(r[h].id).fy+=k}for(const g of c){const h=o.get(g.source),x=o.get(g.target);if(!h||!x)continue;const w=x.x-h.x,y=x.y-h.y,S=Math.max(Math.sqrt(w*w+y*y),1),M=S*S/s,I=w/S*M,N=y/S*M;p.get(g.source).fx+=I,p.get(g.source).fy+=N,p.get(g.target).fx-=I,p.get(g.target).fy-=N}r.forEach(g=>{const h=p.get(g.id),x=o.get(g.id),w=Math.sqrt(h.fx*h.fx+h.fy*h.fy);if(w>0){const y=Math.min(w,d);x.x+=h.fx/w*y,x.y+=h.fy/w*y}}),d*=u}return r.forEach(m=>{i.set(m.id,{...o.get(m.id)})}),t.centerGraph&&mt(i),{positions:i}}function mt(r){if(r.size===0)return;let e=1/0,t=1/0,i=-1/0,a=-1/0;r.forEach(s=>{e=Math.min(e,s.x),t=Math.min(t,s.y),i=Math.max(i,s.x),a=Math.max(a,s.y)});const o=(e+i)/2,c=(t+a)/2;r.forEach(s=>{s.x-=o,s.y-=c})}function Lt(r){const e=b.useRef(null);e.current||(e.current=new Je(r));const t=e.current,[,i]=b.useState(0),a=b.useCallback(()=>i(s=>s+1),[]);b.useEffect(()=>t.subscribe(a),[t,a]);const o=t.getDocument(),c=b.useCallback(s=>{Ot(t.getNodes(),t.getEdges(),s).positions.forEach((u,d)=>{t.moveNode(d,u)})},[t]);return b.useMemo(()=>({document:o,nodes:o.nodes,edges:o.edges,groups:o.groups,animations:o.animations,viewport:o.viewport,addNode:(s,l,u,d)=>t.addNode(s,l,u,d),updateNode:(s,l)=>t.updateNode(s,l),moveNode:(s,l)=>t.moveNode(s,l),resizeNode:(s,l)=>t.resizeNode(s,l),removeNode:s=>t.removeNode(s),addEdge:(s,l,u,d,m)=>t.addEdge(s,l,u,d,m),updateEdge:(s,l)=>t.updateEdge(s,l),removeEdge:s=>t.removeEdge(s),createGroup:(s,l)=>t.createGroup(s,l),removeGroup:s=>t.removeGroup(s),toggleGroupCollapse:s=>t.toggleGroupCollapse(s),toggleNodeCollapse:s=>t.toggleNodeCollapse(s),addAnimation:s=>t.addAnimation(s),updateAnimation:(s,l)=>t.updateAnimation(s,l),removeAnimation:s=>t.removeAnimation(s),animationModes:t.getAnimationModes(),activeAnimationMode:t.getActiveAnimationMode(),addAnimationMode:(s,l)=>t.addAnimationMode(s,l),removeAnimationMode:s=>t.removeAnimationMode(s),setActiveAnimationMode:s=>t.setActiveAnimationMode(s),addAnimationToMode:(s,l)=>t.addAnimationToMode(s,l),removeAnimationFromMode:(s,l)=>t.removeAnimationFromMode(s,l),setStylePreset:s=>t.setStylePreset(s),setStyleOverrides:s=>t.setStyleOverrides(s),stylePresetId:o.stylePresetId,playerConfig:t.getPlayerConfig(),setPlayerConfig:s=>t.setPlayerConfig(s),setViewMode:s=>t.setViewMode(s),viewMode:t.getPlayerConfig().mode,applyLayout:c,setViewport:s=>t.setViewport(s),undo:()=>t.undo(),redo:()=>t.redo(),canUndo:t.canUndo(),canRedo:t.canRedo(),loadDocument:s=>t.loadDocument(s),model:t}),[o,t,c])}function ce(r){return{primary:"var(--nice-primary, #3b82f6)",primaryLight:"var(--nice-primary-light, #93c5fd)",secondary:"var(--nice-info, #6366f1)",accent:"var(--nice-warning, #f59e0b)",success:"var(--nice-success, #10b981)",warning:"var(--nice-warning, #f59e0b)",error:"var(--nice-danger, #ef4444)",info:"var(--nice-info, #06b6d4)",text:"var(--nice-text, #1e293b)",textMuted:"var(--nice-text-muted, #94a3b8)",border:"var(--nice-border, #e2e8f0)",surface:"var(--nice-bg, #fff)",surfaceAlt:"var(--nice-bg-secondary, #f8fafc)",...r}}function vr(r,e={}){return{backgroundColor:r.surface,borderColor:r.primary,borderWidth:2,borderRadius:8,fontColor:r.text,fontSize:14,fontWeight:"normal",opacity:1,shadow:!0,...e}}function wr(r,e={}){return{strokeColor:r.border,strokeWidth:2,lineType:"bezier",targetArrow:"arrow",...e}}function kr(r,e={}){return{backgroundColor:`${r.primaryLight}18`,borderColor:r.primaryLight,borderWidth:1,borderStyle:"dashed",borderRadius:12,labelColor:r.text,padding:16,...e}}function le(r,e,t,i,a,o,c){return{canvas:r,nodeDefaults:vr(e,i),edgeDefaults:wr(e,a),groupDefaults:kr(e,o),fontFamily:t,palette:e,effects:c}}const Ne="'Inter', system-ui, sans-serif",gt="'Fira Code', 'Cascadia Code', monospace",_r="'Merriweather', 'Georgia', serif",Nr={id:"default-light",name:"Default Light",category:"corporate",themeSource:"Light",config:le({background:"var(--nice-bg, #fff)",gridColor:"#e2e8f020",gridSize:20,selectionColor:"var(--nice-primary, #3b82f6)"},ce({}),Ne)},Cr=ce({primary:"var(--nice-primary-light, #60a5fa)",primaryLight:"var(--nice-primary, #3b82f6)",secondary:"var(--nice-accent, #818cf8)",accent:"var(--nice-warning-light, #fbbf24)",success:"var(--nice-success-light, #34d399)",warning:"var(--nice-warning-light, #fbbf24)",error:"var(--nice-danger-light, #f87171)",info:"var(--nice-info, #22d3ee)",text:"var(--nice-text-primary, #f8fafc)",textMuted:"var(--nice-text-secondary, #64748b)",border:"var(--nice-border-color, #334155)",surface:"var(--nice-bg-secondary, #1e293b)",surfaceAlt:"var(--nice-bg-primary, #0f172a)"}),Mr={id:"default-dark",name:"Default Dark",category:"dark",themeSource:"Dark",config:le({background:"var(--nice-bg-primary, #0f172a)",gridColor:"var(--nice-text, #334155)",gridSize:20,selectionColor:"var(--nice-primary-light, #60a5fa)"},Cr,Ne,{shadow:!1},{strokeColor:"var(--nice-text-secondary, #475569)"},{backgroundColor:"#60a5fa10",borderColor:"#3b82f680"})},Sr=ce({primary:"var(--nice-primary-dark, #1d4ed8)",primaryLight:"var(--nice-primary-light, #93c5fd)",secondary:"var(--nice-primary, #3b82f6)",text:"var(--nice-primary-dark, #1e3a5f)",textMuted:"#7da0c4",border:"var(--nice-primary-light, #93c5fd)",surface:"var(--nice-primary-bg, #eff6ff)",surfaceAlt:"var(--nice-primary-bg, #dbeafe)"}),Ir={id:"corporate-blue",name:"Corporate Blue",category:"corporate",themeSource:"Blue",config:le({background:"#f0f5ff",gridColor:"#93c5fd20",gridSize:20,selectionColor:"var(--nice-primary-dark, #1d4ed8)"},Sr,Ne,{borderWidth:2,borderRadius:6},{strokeColor:"var(--nice-primary-light, #93c5fd)",strokeWidth:2})},zr=ce({primary:"var(--nice-success, #00ff88)",primaryLight:"#00cc6b",secondary:"#ff00ff",accent:"var(--nice-info, #00ffff)",success:"var(--nice-success, #00ff88)",warning:"var(--nice-warning, #ffff00)",error:"#ff3366",info:"var(--nice-info, #00ffff)",text:"var(--nice-text-secondary, #e0e0e0)",textMuted:"var(--nice-text-secondary, #808080)",border:"#00ff8840",surface:"var(--nice-bg, #1a1a2e)",surfaceAlt:"var(--nice-bg, #16213e)"}),jr={id:"neon-glow",name:"Neon Glow",category:"dark",config:le({background:"#0a0a1a",gridColor:"#00ff8810",gridSize:20,selectionColor:"var(--nice-success, #00ff88)"},zr,gt,{borderColor:"var(--nice-success, #00ff88)",borderWidth:2,shadow:!0,glowColor:"var(--nice-success, #00ff88)",glowIntensity:.6},{strokeColor:"#00ff8880",strokeWidth:2},{backgroundColor:"#00ff880a",borderColor:"#00ff8840"},{glowColor:"var(--nice-success, #00ff88)",glowIntensity:.8,particleColor:"var(--nice-info, #00ffff)",liquidColor:"var(--nice-success, #00ff88)",liquidColorEnd:"var(--nice-info, #00ffff)"})},Ar=ce({primary:"var(--nice-color-accent-pink, #ff2d95)",primaryLight:"#ff6db6",secondary:"#7928ca",accent:"#00d4ff",success:"#39ff14",warning:"var(--nice-warning, #FFD700)",error:"#ff073a",info:"#00d4ff",text:"var(--nice-text-primary, #fff)",textMuted:"#b0b0b0",border:"#ff2d9540",surface:"#1a0030",surfaceAlt:"#2d004a"}),$r={id:"cyberpunk",name:"Cyberpunk",category:"dark",config:le({background:"#0d001a",gridColor:"#ff2d9510",gridSize:24,selectionColor:"var(--nice-color-accent-pink, #ff2d95)"},Ar,gt,{borderColor:"var(--nice-color-accent-pink, #ff2d95)",borderWidth:2,glowColor:"var(--nice-color-accent-pink, #ff2d95)",glowIntensity:.7,shadow:!0,gradientColor:"#2d004a",gradientDirection:"vertical"},{strokeColor:"#7928ca80",strokeWidth:3},{},{glowColor:"var(--nice-color-accent-pink, #ff2d95)",glowIntensity:.9,particleColor:"#00d4ff",liquidColor:"var(--nice-color-accent-pink, #ff2d95)",liquidColorEnd:"#7928ca"})},Dr=ce({primary:"var(--nice-bg, #fff)",primaryLight:"#ffffffaa",secondary:"#4da6ff",accent:"var(--nice-bg, #fff)",text:"var(--nice-text-primary, #fff)",textMuted:"#ffffffaa",border:"#ffffff40",surface:"#1e3d6e",surfaceAlt:"#163050"}),Tr={id:"blueprint",name:"Technical Blueprint",category:"technical",config:le({background:"#0a1929",gridColor:"#4da6ff30",gridSize:16,selectionColor:"var(--nice-text-on-primary, #fff)"},Dr,gt,{backgroundColor:"transparent",borderColor:"#4da6ff",borderWidth:1,borderStyle:"solid",fontColor:"var(--nice-text-primary, #fff)",shadow:!1},{strokeColor:"#4da6ff",strokeWidth:1,strokeDash:[4,4]},{backgroundColor:"transparent",borderColor:"#4da6ff40",borderStyle:"dashed",borderWidth:1})},Pr=ce({primary:"var(--nice-accent, #a78bfa)",primaryLight:"var(--nice-accent, #c4b5fd)",secondary:"var(--nice-color-accent-pink, #f472b6)",accent:"var(--nice-warning-light, #fbbf24)",success:"var(--nice-success-light, #6ee7b7)",warning:"var(--nice-warning-bg, #fde68a)",error:"var(--nice-danger-bg, #fca5a5)",info:"var(--nice-primary-light, #93c5fd)",text:"#4a4a68",textMuted:"#9494b0",border:"#e2d8f4",surface:"#faf5ff",surfaceAlt:"#f3e8ff"}),Rr={id:"pastel-dream",name:"Pastel Dream",category:"pastel",config:le({background:"#fefcff",gridColor:"#e2d8f420",gridSize:20,selectionColor:"var(--nice-accent, #a78bfa)"},Pr,"'Nunito', 'Quicksand', sans-serif",{borderColor:"var(--nice-accent, #c4b5fd)",borderWidth:2,borderRadius:16,shadow:!0},{strokeColor:"var(--nice-accent, #c4b5fd)",strokeWidth:2},{backgroundColor:"#a78bfa10",borderColor:"var(--nice-accent, #c4b5fd)",borderRadius:16})},Or=ce({primary:"var(--nice-success, #059669)",primaryLight:"var(--nice-success-light, #6ee7b7)",secondary:"#065f46",accent:"var(--nice-warning, #f59e0b)",success:"var(--nice-success, #10b981)",warning:"var(--nice-warning, #f59e0b)",error:"var(--nice-danger-dark, #dc2626)",info:"#0d9488",text:"#1a3d2f",textMuted:"#6b8f7f",border:"#a7d7c5",surface:"#ecfdf5",surfaceAlt:"#d1fae5"}),Er={id:"nature-forest",name:"Nature Forest",category:"nature",config:le({background:"#f0fdf4",gridColor:"#a7d7c520",gridSize:20,selectionColor:"var(--nice-success, #059669)"},Or,Ne,{borderColor:"var(--nice-success, #059669)",borderRadius:12},{strokeColor:"var(--nice-success-light, #6ee7b7)"},{backgroundColor:"#05966910",borderColor:"var(--nice-success-light, #6ee7b7)"},{liquidColor:"var(--nice-success, #059669)",liquidColorEnd:"var(--nice-success-light, #6ee7b7)",particleColor:"var(--nice-warning, #f59e0b)"})},Lr=ce({primary:"var(--nice-success, #00ff00)",primaryLight:"#00cc00",secondary:"var(--nice-success, #00ff00)",accent:"var(--nice-warning, #ffff00)",text:"var(--nice-success, #00ff00)",textMuted:"#00990088",border:"#00ff0040",surface:"#001100",surfaceAlt:"#002200"}),Fr={id:"retro-terminal",name:"Retro Terminal",category:"retro",config:le({background:"#000800",gridColor:"#00ff0010",gridSize:16,selectionColor:"var(--nice-success, #00ff00)"},Lr,"'Courier New', 'Fira Code', monospace",{backgroundColor:"#001100",borderColor:"#00ff0060",borderWidth:1,fontColor:"var(--nice-success, #00ff00)",shadow:!1,glowColor:"var(--nice-success, #00ff00)",glowIntensity:.4},{strokeColor:"#00ff0060",strokeWidth:1},{},{glowColor:"var(--nice-success, #00ff00)",glowIntensity:.6,particleColor:"var(--nice-success, #00ff00)",liquidColor:"var(--nice-success, #00ff00)"})},Wr=ce({primary:"#0000ff",primaryLight:"#6666ff",secondary:"#ff00ff",accent:"var(--nice-warning, #ffff00)",text:"var(--nice-text, #000000)",textMuted:"var(--nice-text-secondary, #555555)",border:"var(--nice-border-color, #000000)",surface:"var(--nice-bg, #fff)",surfaceAlt:"var(--nice-border, #eeeeee)"}),Br={id:"high-contrast",name:"High Contrast",category:"accessibility",themeSource:"High Contrast",config:le({background:"var(--nice-bg, #fff)",gridColor:"#00000020",gridSize:20,selectionColor:"#0000ff"},Wr,"Arial, sans-serif",{borderColor:"var(--nice-border-color, #000000)",borderWidth:3,fontColor:"var(--nice-text, #000000)",fontWeight:"bold"},{strokeColor:"var(--nice-text, #000000)",strokeWidth:3},{borderColor:"var(--nice-border-color, #000000)",borderWidth:2})},qr=ce({primary:"var(--nice-primary-hover, #1976d2)",primaryLight:"#64b5f6",secondary:"var(--nice-accent, #9c27b0)",accent:"var(--nice-warning, #ff9800)",success:"var(--nice-success, #4caf50)",warning:"var(--nice-warning, #ff9800)",error:"var(--nice-danger, #f44336)",info:"#03a9f4",text:"#212121",textMuted:"#757575",border:"var(--nice-border, #e0e0e0)",surface:"var(--nice-bg-secondary, #fafafa)",surfaceAlt:"var(--nice-bg-secondary, #f5f5f5)"}),Gr={id:"material-design",name:"Material Design",category:"theme-based",themeSource:"Material",config:le({background:"var(--nice-bg-secondary, #fafafa)",gridColor:"#e0e0e020",gridSize:20,selectionColor:"var(--nice-primary-hover, #1976d2)"},qr,"'Roboto', 'Noto Sans', sans-serif",{borderRadius:4,borderWidth:0,shadow:!0},{strokeColor:"#bdbdbd",strokeWidth:2},{borderRadius:8})},Vr=ce({primary:"#0078d4",primaryLight:"#6cb8f7",secondary:"#8661c5",accent:"#ffaa44",success:"#107c10",warning:"#ffaa44",error:"#d13438",info:"#0078d4",text:"#323130",textMuted:"#a19f9d",border:"#edebe9",surface:"var(--nice-bg, #fff)",surfaceAlt:"#faf9f8"}),Yr={id:"fluent-ui",name:"Fluent UI",category:"theme-based",themeSource:"Fluent",config:le({background:"#faf9f8",gridColor:"#edebe920",gridSize:20,selectionColor:"#0078d4"},Vr,"'Segoe UI', system-ui, sans-serif",{borderRadius:4,borderWidth:1,shadow:!0},{strokeColor:"#c8c6c4",strokeWidth:1})},Xr=ce({primary:"var(--nice-warning-dark, #e65100)",primaryLight:"#ff9e80",secondary:"#ff6f00",accent:"#ffd600",success:"#43a047",warning:"#ff6f00",error:"var(--nice-danger-dark, #c62828)",info:"#0277bd",text:"#3e2723",textMuted:"#8d6e63",border:"#ffccbc",surface:"#fff8e1",surfaceAlt:"var(--nice-warning-bg, #fff3e0)"}),Ur={id:"sunset-warm",name:"Sunset Warm",category:"creative",config:le({background:"#fffde7",gridColor:"#ffccbc20",gridSize:20,selectionColor:"var(--nice-warning-dark, #e65100)"},Xr,Ne,{borderColor:"#ff9e80",gradientColor:"var(--nice-warning-bg, #fff3e0)",gradientDirection:"vertical"},{strokeColor:"#ff9e80"},{},{liquidColor:"var(--nice-warning-dark, #e65100)",liquidColorEnd:"#ffd600",particleColor:"#ffd600"})},Hr=ce({primary:"#006064",primaryLight:"#4dd0e1",secondary:"#00838f",accent:"#ffd54f",success:"#00e676",warning:"#ffd54f",error:"#ff5252",info:"#40c4ff",text:"#004d40",textMuted:"#80cbc4",border:"#b2ebf2",surface:"#e0f7fa",surfaceAlt:"#b2ebf2"}),Jr={id:"ocean-deep",name:"Ocean Deep",category:"nature",config:le({background:"#e0f7fa",gridColor:"#b2ebf220",gridSize:20,selectionColor:"#006064"},Hr,Ne,{borderColor:"#00838f",borderRadius:12},{strokeColor:"#4dd0e1"},{},{liquidColor:"#006064",liquidColorEnd:"#4dd0e1",particleColor:"#ffd54f"})},Zr=ce({primary:"#5d4037",primaryLight:"#a1887f",secondary:"#795548",accent:"#c6a263",text:"#3e2723",textMuted:"#8d6e63",border:"#bcaaa4",surface:"#fdf6f0",surfaceAlt:"#efebe9"}),Kr={id:"elegant-serif",name:"Elegant Serif",category:"creative",config:le({background:"#fdf6f0",gridColor:"#bcaaa420",gridSize:24,selectionColor:"#5d4037"},Zr,_r,{borderColor:"#a1887f",borderWidth:1,borderRadius:2,fontStyle:"normal"},{strokeColor:"#bcaaa4",strokeWidth:1},{borderRadius:4})},Qr=ce({primary:"var(--nice-text, #333333)",primaryLight:"var(--nice-text-secondary, #666666)",secondary:"var(--nice-text-secondary, #555555)",accent:"#ff6600",text:"var(--nice-text, #333333)",textMuted:"var(--nice-text-muted, #999999)",border:"var(--nice-border, #cccccc)",surface:"var(--nice-bg, #fff)",surfaceAlt:"var(--nice-bg-secondary, #f5f5f5)"}),ei={id:"wireframe",name:"Wireframe",category:"technical",config:le({background:"var(--nice-bg, #fff)",gridColor:"#00000008",gridSize:16,selectionColor:"#ff6600"},Qr,"'Balsamiq Sans', 'Comic Sans MS', cursive",{backgroundColor:"transparent",borderColor:"var(--nice-border-color, #999999)",borderWidth:1,borderStyle:"solid",shadow:!1,borderRadius:4},{strokeColor:"var(--nice-text-muted, #999999)",strokeWidth:1},{backgroundColor:"transparent",borderStyle:"dashed",borderWidth:1,borderColor:"var(--nice-border, #cccccc)"})},ti=ce({primary:"#00bfa5",primaryLight:"#64ffda",secondary:"#00897b",accent:"#ff6e40",success:"#00e676",warning:"#ffc400",error:"#ff1744",info:"#00e5ff",text:"#1b5e20",textMuted:"#81c784",border:"#a7ffeb",surface:"#e0f2f1",surfaceAlt:"#b2dfdb"}),ri={id:"mint-fresh",name:"Mint Fresh",category:"nature",config:le({background:"var(--nice-success-bg, #e8f5e9)",gridColor:"#a7ffeb20",gridSize:20,selectionColor:"#00bfa5"},ti,Ne,{borderColor:"#00bfa5",borderRadius:20,borderWidth:2,gradientColor:"#b2dfdb",gradientDirection:"radial"},{strokeColor:"#64ffda",strokeWidth:2},{borderRadius:16},{liquidColor:"#00bfa5",liquidColorEnd:"#64ffda",particleColor:"#ff6e40"})},ii=ce({primary:"#424242",primaryLight:"var(--nice-text-secondary, #9e9e9e)",secondary:"#616161",accent:"var(--nice-danger, #ff5722)",text:"#212121",textMuted:"#bdbdbd",border:"var(--nice-border, #e0e0e0)",surface:"var(--nice-bg-secondary, #fafafa)",surfaceAlt:"var(--nice-bg-secondary, #f5f5f5)"}),ai={id:"monochrome",name:"Monochrome",category:"corporate",config:le({background:"var(--nice-bg-secondary, #fafafa)",gridColor:"#e0e0e020",gridSize:20,selectionColor:"#424242"},ii,Ne,{borderColor:"var(--nice-border-color, #9e9e9e)",borderWidth:1,shadow:!0,borderRadius:4},{strokeColor:"var(--nice-text-secondary, #9e9e9e)",strokeWidth:1.5})},oi=ce({primary:"var(--nice-color-accent-pink, #e91e63)",primaryLight:"#f48fb1",secondary:"var(--nice-accent, #9c27b0)",accent:"var(--nice-warning, #ffeb3b)",success:"var(--nice-success, #4caf50)",warning:"var(--nice-warning, #ff9800)",error:"var(--nice-danger, #f44336)",info:"#00bcd4",text:"#4a148c",textMuted:"#ce93d8",border:"#f8bbd0",surface:"#fce4ec",surfaceAlt:"#f3e5f5"}),si={id:"candy-pop",name:"Candy Pop",category:"creative",config:le({background:"#fff0f5",gridColor:"#f8bbd020",gridSize:20,selectionColor:"var(--nice-color-accent-pink, #e91e63)"},oi,"'Quicksand', 'Nunito', sans-serif",{borderColor:"var(--nice-color-accent-pink, #e91e63)",borderRadius:24,borderWidth:3,gradientColor:"#f3e5f5",gradientDirection:"diagonal"},{strokeColor:"#f48fb1",strokeWidth:3},{borderRadius:20,borderColor:"#f48fb1"},{glowColor:"var(--nice-color-accent-pink, #e91e63)",glowIntensity:.5,particleColor:"var(--nice-warning, #ffeb3b)"})},ni=ce({primary:"var(--nice-text-secondary, #475569)",primaryLight:"var(--nice-text-muted, #94a3b8)",secondary:"var(--nice-text, #334155)",accent:"var(--nice-warning, #f59e0b)",text:"var(--nice-text, #0f172a)",textMuted:"var(--nice-text-muted, #94a3b8)",border:"var(--nice-border, #cbd5e1)",surface:"var(--nice-bg-secondary, #f8fafc)",surfaceAlt:"var(--nice-bg-secondary, #f1f5f9)"}),ci={id:"slate-professional",name:"Slate Professional",category:"corporate",config:le({background:"var(--nice-bg-secondary, #f8fafc)",gridColor:"#cbd5e120",gridSize:20,selectionColor:"var(--nice-text-secondary, #475569)"},ni,"'Inter', system-ui, sans-serif",{borderColor:"var(--nice-border, #cbd5e1)",borderWidth:1,borderRadius:6,shadow:!0},{strokeColor:"var(--nice-text-muted, #94a3b8)",strokeWidth:1.5},{borderColor:"var(--nice-border, #cbd5e1)",borderRadius:8})},li=ce({primary:"var(--nice-accent, #7c3aed)",primaryLight:"var(--nice-accent, #a78bfa)",secondary:"var(--nice-info, #06b6d4)",accent:"var(--nice-color-accent-pink, #f472b6)",success:"var(--nice-success-light, #34d399)",warning:"var(--nice-warning-light, #fbbf24)",error:"var(--nice-danger-light, #f87171)",info:"var(--nice-info, #22d3ee)",text:"var(--nice-text-secondary, #e2e8f0)",textMuted:"var(--nice-text-muted, #94a3b8)",border:"#7c3aed40",surface:"#1e1b4b",surfaceAlt:"#312e81"}),di={id:"aurora-borealis",name:"Aurora Borealis",category:"dark",config:le({background:"#0f0b2e",gridColor:"#7c3aed15",gridSize:24,selectionColor:"var(--nice-accent, #a78bfa)"},li,Ne,{borderColor:"var(--nice-accent, #7c3aed)",borderWidth:2,gradientColor:"#312e81",gradientDirection:"vertical",glowColor:"var(--nice-accent, #a78bfa)",glowIntensity:.5},{strokeColor:"#7c3aed80",strokeWidth:2},{},{glowColor:"var(--nice-accent, #a78bfa)",glowIntensity:.7,particleColor:"var(--nice-info, #06b6d4)",liquidColor:"var(--nice-accent, #7c3aed)",liquidColorEnd:"var(--nice-info, #06b6d4)"})},ui=ce({primary:"#2c3e50",primaryLight:"#7f8c8d",secondary:"#2980b9",accent:"#e74c3c",text:"#2c3e50",textMuted:"#95a5a6",border:"#bdc3c7",surface:"#fdfaf6",surfaceAlt:"#f5f0e8"}),fi={id:"sketch-hand-drawn",name:"Sketch / Hand-drawn",category:"creative",config:le({background:"#fdfaf6",gridColor:"#bdc3c720",gridSize:20,selectionColor:"#2980b9"},ui,"'Caveat', 'Patrick Hand', cursive",{backgroundColor:"#fdfaf6",borderColor:"#2c3e50",borderWidth:2,borderRadius:2,shadow:!1},{strokeColor:"#2c3e50",strokeWidth:2},{borderStyle:"dashed",borderWidth:2})},hi=ce({primary:"var(--nice-primary, #2196f3)",primaryLight:"#64b5f6",secondary:"var(--nice-warning, #ff9800)",accent:"var(--nice-danger, #ff5722)",success:"var(--nice-success, #4caf50)",warning:"var(--nice-warning, #ffc107)",error:"var(--nice-danger, #f44336)",info:"#03a9f4",text:"var(--nice-text-primary, #fff)",textMuted:"#b0bec5",border:"#ffffff40",surface:"var(--nice-primary, #2196f3)",surfaceAlt:"var(--nice-primary-dark, #1565c0)"}),pi={id:"infographic-bold",name:"Infographic Bold",category:"creative",config:le({background:"#eceff1",gridColor:"#b0bec520",gridSize:24,selectionColor:"var(--nice-danger, #ff5722)"},hi,"'Montserrat', 'Roboto', sans-serif",{backgroundColor:"var(--nice-primary, #2196f3)",borderColor:"var(--nice-primary-dark, #1565c0)",borderWidth:0,fontColor:"var(--nice-text-on-primary, #fff)",fontWeight:"bold",borderRadius:12,shadow:!0},{strokeColor:"#90a4ae",strokeWidth:3},{backgroundColor:"#2196f320",borderWidth:2,borderRadius:16})},mi=ce({primary:"#9333ea",primaryLight:"var(--nice-accent, #c084fc)",secondary:"var(--nice-info, #6366f1)",accent:"var(--nice-warning, #f59e0b)",text:"var(--nice-text-primary, #f1f5f9)",textMuted:"var(--nice-accent, #a78bfa)",border:"#7c3aed40",surface:"#1c1033",surfaceAlt:"#2d1b69"}),gi={id:"midnight-purple",name:"Midnight Purple",category:"dark",config:le({background:"#0f0720",gridColor:"#9333ea10",gridSize:20,selectionColor:"var(--nice-accent, #c084fc)"},mi,Ne,{borderColor:"#9333ea",borderWidth:2,gradientColor:"#2d1b69",gradientDirection:"vertical",shadow:!1},{strokeColor:"#9333ea80",strokeWidth:2},{},{glowColor:"#9333ea",glowIntensity:.6,liquidColor:"#9333ea",liquidColorEnd:"var(--nice-accent, #c084fc)"})},Ze=[Nr,Mr,Ir,Gr,Yr,jr,$r,Tr,Fr,Rr,Ur,Jr,Kr,Er,ei,Br,ri,ai,si,ci,di,fi,pi,gi],yi=[{id:"fill-solid",name:"Solid Fill",category:"fill",style:{opacity:1}},{id:"fill-gradient-v",name:"Vertical Gradient",category:"fill",style:{gradientColor:"var(--nice-text-secondary, #e2e8f0)",gradientDirection:"vertical"}},{id:"fill-gradient-h",name:"Horizontal Gradient",category:"fill",style:{gradientColor:"var(--nice-text-secondary, #e2e8f0)",gradientDirection:"horizontal"}},{id:"fill-gradient-d",name:"Diagonal Gradient",category:"fill",style:{gradientColor:"var(--nice-text-secondary, #e2e8f0)",gradientDirection:"diagonal"}},{id:"fill-gradient-r",name:"Radial Gradient",category:"fill",style:{gradientColor:"var(--nice-text-secondary, #e2e8f0)",gradientDirection:"radial"}},{id:"fill-transparent",name:"Transparent",category:"fill",style:{backgroundColor:"transparent",opacity:1}},{id:"fill-semi",name:"Semi-transparent",category:"fill",style:{opacity:.6}},{id:"fill-glass",name:"Glassmorphism",category:"fill",style:{opacity:.7,gradientColor:"#ffffff40",gradientDirection:"vertical",borderWidth:1,borderColor:"#ffffff60"}},{id:"border-none",name:"No Border",category:"border",style:{borderWidth:0}},{id:"border-thin",name:"Thin Border",category:"border",style:{borderWidth:1}},{id:"border-medium",name:"Medium Border",category:"border",style:{borderWidth:2}},{id:"border-thick",name:"Thick Border",category:"border",style:{borderWidth:3}},{id:"border-heavy",name:"Heavy Border",category:"border",style:{borderWidth:4}},{id:"border-solid",name:"Solid",category:"border",style:{borderStyle:"solid"}},{id:"border-dashed",name:"Dashed",category:"border",style:{borderStyle:"dashed"}},{id:"border-dotted",name:"Dotted",category:"border",style:{borderStyle:"dotted"}},{id:"border-rounded-sm",name:"Rounded Small",category:"border",style:{borderRadius:4}},{id:"border-rounded-md",name:"Rounded Medium",category:"border",style:{borderRadius:8}},{id:"border-rounded-lg",name:"Rounded Large",category:"border",style:{borderRadius:16}},{id:"border-rounded-xl",name:"Rounded XL",category:"border",style:{borderRadius:24}},{id:"border-pill",name:"Pill / Capsule",category:"border",style:{borderRadius:999}},{id:"border-sharp",name:"Sharp Corners",category:"border",style:{borderRadius:0}},{id:"effect-shadow",name:"Drop Shadow",category:"effect",style:{shadow:!0}},{id:"effect-no-shadow",name:"No Shadow",category:"effect",style:{shadow:!1}},{id:"effect-glow-blue",name:"Blue Glow",category:"effect",style:{glowColor:"var(--nice-primary, #3b82f6)",glowIntensity:.6}},{id:"effect-glow-green",name:"Green Glow",category:"effect",style:{glowColor:"var(--nice-success, #10b981)",glowIntensity:.6}},{id:"effect-glow-red",name:"Red Glow",category:"effect",style:{glowColor:"var(--nice-danger, #ef4444)",glowIntensity:.6}},{id:"effect-glow-purple",name:"Purple Glow",category:"effect",style:{glowColor:"var(--nice-accent, #8b5cf6)",glowIntensity:.6}},{id:"effect-glow-gold",name:"Gold Glow",category:"effect",style:{glowColor:"var(--nice-warning, #f59e0b)",glowIntensity:.6}},{id:"effect-glow-neon",name:"Neon Glow",category:"effect",style:{glowColor:"var(--nice-success, #00ff88)",glowIntensity:.8}}],bi=[{id:"line-straight",name:"Straight",category:"type",style:{lineType:"straight"}},{id:"line-bezier",name:"Bezier Curve",category:"type",style:{lineType:"bezier"}},{id:"line-orthogonal",name:"Orthogonal",category:"type",style:{lineType:"orthogonal"}},{id:"line-step",name:"Step",category:"type",style:{lineType:"step"}},{id:"stroke-thin",name:"Thin Stroke",category:"stroke",style:{strokeWidth:1}},{id:"stroke-medium",name:"Medium Stroke",category:"stroke",style:{strokeWidth:2}},{id:"stroke-thick",name:"Thick Stroke",category:"stroke",style:{strokeWidth:3}},{id:"stroke-heavy",name:"Heavy Stroke",category:"stroke",style:{strokeWidth:4}},{id:"stroke-solid",name:"Solid",category:"stroke",style:{strokeDash:[]}},{id:"stroke-dashed",name:"Dashed",category:"stroke",style:{strokeDash:[8,4]}},{id:"stroke-dotted",name:"Dotted",category:"stroke",style:{strokeDash:[2,4]}},{id:"stroke-dash-dot",name:"Dash-Dot",category:"stroke",style:{strokeDash:[8,4,2,4]}},{id:"stroke-long-dash",name:"Long Dash",category:"stroke",style:{strokeDash:[16,8]}},{id:"arrow-target-none",name:"No Target Arrow",category:"arrow",style:{targetArrow:"none"}},{id:"arrow-target-arrow",name:"Arrow →",category:"arrow",style:{targetArrow:"arrow"}},{id:"arrow-target-open",name:"Open Arrow ▷",category:"arrow",style:{targetArrow:"openArrow"}},{id:"arrow-target-diamond",name:"Diamond ◇",category:"arrow",style:{targetArrow:"diamond"}},{id:"arrow-target-circle",name:"Circle ○",category:"arrow",style:{targetArrow:"circle"}},{id:"arrow-source-none",name:"No Source Arrow",category:"arrow",style:{sourceArrow:"none"}},{id:"arrow-source-arrow",name:"← Source Arrow",category:"arrow",style:{sourceArrow:"arrow"}},{id:"arrow-source-open",name:"◁ Open Source",category:"arrow",style:{sourceArrow:"openArrow"}},{id:"arrow-source-diamond",name:"◇ Diamond Source",category:"arrow",style:{sourceArrow:"diamond"}},{id:"arrow-source-circle",name:"○ Circle Source",category:"arrow",style:{sourceArrow:"circle"}},{id:"arrow-bidirectional",name:"↔ Bidirectional",category:"arrow",style:{sourceArrow:"arrow",targetArrow:"arrow"}},{id:"arrow-association",name:" Association (none)",category:"arrow",style:{sourceArrow:"none",targetArrow:"none"}},{id:"arrow-composition",name:"◆→ Composition",category:"arrow",style:{sourceArrow:"diamond",targetArrow:"arrow"}},{id:"arrow-aggregation",name:"◇→ Aggregation",category:"arrow",style:{sourceArrow:"diamond",targetArrow:"arrow"}},{id:"arrow-dependency",name:"- - → Dependency",category:"arrow",style:{targetArrow:"openArrow",strokeDash:[8,4]}},{id:"arrow-inheritance",name:"△→ Inheritance",category:"arrow",style:{targetArrow:"openArrow"}},{id:"effect-animated",name:"Animated Flow",category:"effect",style:{animated:!0,flowSpeed:1}},{id:"effect-animated-fast",name:"Fast Animated",category:"effect",style:{animated:!0,flowSpeed:2}},{id:"effect-animated-slow",name:"Slow Animated",category:"effect",style:{animated:!0,flowSpeed:.5}},{id:"effect-liquid",name:"Liquid Flow",category:"effect",style:{liquidFlow:{active:!0,color:"var(--nice-primary, #3b82f6)",speed:1}}},{id:"effect-liquid-neon",name:"Neon Liquid",category:"effect",style:{liquidFlow:{active:!0,color:"var(--nice-success, #00ff88)",colorEnd:"var(--nice-info, #00ffff)",speed:1.5,particleDensity:5}}}],Ft=[{id:"tp-fade-in",name:"Fade In",effect:"fadeIn",durationMs:400,easing:"easeOut",description:"Smoothly fades in"},{id:"tp-fade-out",name:"Fade Out",effect:"fadeOut",durationMs:400,easing:"easeIn",description:"Smoothly fades out"},{id:"tp-slide-left",name:"Slide Left",effect:"slideInLeft",durationMs:500,easing:"easeOut",description:"Slides in from left"},{id:"tp-slide-right",name:"Slide Right",effect:"slideInRight",durationMs:500,easing:"easeOut",description:"Slides in from right"},{id:"tp-slide-top",name:"Slide Down",effect:"slideInTop",durationMs:500,easing:"easeOut",description:"Slides in from top"},{id:"tp-slide-bottom",name:"Slide Up",effect:"slideInBottom",durationMs:500,easing:"easeOut",description:"Slides in from bottom"},{id:"tp-zoom-in",name:"Zoom In",effect:"zoomIn",durationMs:400,easing:"spring",description:"Zooms in with spring"},{id:"tp-zoom-out",name:"Zoom Out",effect:"zoomOut",durationMs:400,easing:"easeIn",description:"Zooms out"},{id:"tp-bounce",name:"Bounce In",effect:"bounce",durationMs:800,easing:"bounce",description:"Bounces into place"},{id:"tp-pulse",name:"Pulse",effect:"pulse",durationMs:1e3,easing:"easeInOut",description:"Pulsing scale effect"},{id:"tp-shake",name:"Shake",effect:"shake",durationMs:600,easing:"linear",description:"Shakes horizontally"},{id:"tp-glow",name:"Glow",effect:"glow",durationMs:1200,easing:"easeInOut",description:"Glowing highlight"},{id:"tp-highlight",name:"Highlight",effect:"highlight",durationMs:800,easing:"easeInOut",description:"Golden highlight flash"},{id:"tp-ripple",name:"Ripple",effect:"ripple",durationMs:1e3,easing:"easeOut",description:"Ripple wave effect"},{id:"tp-expand",name:"Expand",effect:"expand",durationMs:500,easing:"spring",description:"Expand from collapsed"},{id:"tp-collapse",name:"Collapse",effect:"collapse",durationMs:400,easing:"easeIn",description:"Collapse to hidden"},{id:"tp-color-shift",name:"Color Shift",effect:"colorShift",durationMs:2e3,easing:"linear",description:"Rainbow color cycle"},{id:"tp-liquid-fill",name:"Liquid Fill",effect:"liquidFill",durationMs:1500,easing:"easeInOut",description:"Liquid filling effect"},{id:"tp-draw-path",name:"Draw Path",effect:"drawPath",durationMs:1200,easing:"easeOut",description:"Edge draws itself"},{id:"tp-particle-trail",name:"Particle Trail",effect:"particleTrail",durationMs:2e3,easing:"linear",description:"Particles along edge"},{id:"tp-typewriter",name:"Typewriter",effect:"typewriter",durationMs:1500,easing:"linear",description:"Text appears letter by letter"}];function xi(r){return Ze.find(e=>e.id===r)}function vi(r){return Ze.filter(e=>e.category===r)}function wi(r){return{canvasBackground:r.canvas.background,gridColor:r.canvas.gridColor,gridSize:r.canvas.gridSize,selectionColor:r.canvas.selectionColor,fontFamily:r.fontFamily,nodeDefaults:r.nodeDefaults,edgeDefaults:r.edgeDefaults,groupDefaults:r.groupDefaults,palette:r.palette,effects:r.effects}}function ki(r,e,t,i,a,o){const c=ce({primary:t.primary,primaryLight:t.primaryHover,secondary:t.info,accent:t.warning,success:t.success,warning:t.warning,error:t.error,info:t.info,text:a.primary,textMuted:a.muted,border:o.color,surface:i.primary,surfaceAlt:i.secondary}),s=_i(i.primary);return{id:r,name:`${e} Theme`,category:"theme-based",themeSource:e,config:le({background:i.primary,gridColor:s?`${o.color}40`:`${o.color}20`,gridSize:20,selectionColor:t.primary},c,Ne,{shadow:!s,borderWidth:s?1:2},{strokeColor:s?`${o.color}80`:o.color})}}function _i(r){const e=r.replace("#","");if(e.length<6)return!1;const t=parseInt(e.slice(0,2),16),i=parseInt(e.slice(2,4),16),a=parseInt(e.slice(4,6),16);return(t*299+i*587+a*114)/1e3<128}const Ni=["fadeIn","fadeOut","slideInLeft","slideInRight","slideInTop","slideInBottom","zoomIn","zoomOut","pulse","shake","highlight","flowPulse","bounce","glow","colorShift","liquidFill","expand","collapse","ripple","typewriter","morphShape","drawPath","particleTrail"],Ci=["linear","easeIn","easeOut","easeInOut","spring","bounce"],Ke=({animations:r,onAdd:e,onRemove:t,onUpdate:i,onPlay:a,onStop:o,isPlaying:c=!1,availableTargets:s=[],className:l})=>{const{t:u}=Ee(),[d,m]=b.useState(!1),[p,g]=b.useState(null),h=b.useCallback(()=>{if(!e||s.length===0)return;const y=s[0];e({name:`Animation ${r.length+1}`,targetId:y.id,targetType:y.type,effect:"fadeIn",startMs:r.length*500,durationMs:600,easing:"easeOut"})},[e,r.length,s]),x=b.useCallback(y=>{if(!e||s.length===0)return;const S=s[0];e({name:y.name,targetId:S.id,targetType:S.type,effect:y.effect,startMs:r.length*500,durationMs:y.durationMs,easing:y.easing}),m(!1)},[e,r.length,s]),w=Math.max(2e3,...r.map(y=>y.startMs+y.durationMs+(y.delayMs??0)));return n.jsxs("div",{className:`nice-diagram-timeline ${l??""}`,children:[n.jsxs("div",{className:"nice-diagram-timeline__header",children:[n.jsx("h4",{className:"nice-diagram-timeline__title",children:u("animation.timeline")}),n.jsxs("div",{className:"nice-diagram-timeline__controls",children:[c?n.jsxs(v.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:o,children:[n.jsx(v.NiceIcon,{name:"stop",size:14})," ",u("animation.stop")]}):n.jsxs(v.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:a,children:[n.jsx(v.NiceIcon,{name:"play",size:14})," ",u("animation.play")]}),n.jsxs(v.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:h,disabled:s.length===0,children:[n.jsx(v.NiceIcon,{name:"plus",size:14})," ",u("animation.add")]}),n.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[n.jsxs(v.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:()=>m(y=>!y),disabled:s.length===0,title:"Add from preset",children:[n.jsx(v.NiceIcon,{name:"video",size:14})," Presets"]}),d&&n.jsx("div",{style:{position:"absolute",bottom:"100%",left:0,background:"var(--nice-bg, #fff)",border:"1px solid var(--nice-border, #ddd)",borderRadius:6,boxShadow:"0 4px 12px var(--nice-overlay-15, rgba(0, 0, 0, 0.15))",maxHeight:280,overflowY:"auto",width:200,zIndex:100},children:Ft.map(y=>n.jsx(v.NiceButton,{variant:"ghost",size:"sm",onClick:()=>x(y),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 10px",fontSize:12,borderBottom:"1px solid var(--nice-bg-secondary, #f0f0f0)"},title:`${y.effect} — ${y.durationMs}ms ${y.easing}`,children:y.name},y.id))})]})]})]}),n.jsxs("div",{className:"nice-diagram-timeline__tracks",children:[r.length===0&&n.jsx("p",{className:"nice-diagram-timeline__empty",children:u("animation.noAnimations")}),r.map(y=>{const S=y.startMs/w*100,M=y.durationMs/w*100,I=p===y.id;return n.jsxs("div",{className:"nice-diagram-timeline__track",children:[n.jsxs("div",{className:"nice-diagram-timeline__track-label",children:[n.jsx("span",{className:"nice-diagram-timeline__track-name",onClick:()=>g(I?null:y.id),style:{cursor:"pointer"},title:"Click to edit",children:y.name}),n.jsx("span",{className:"nice-diagram-timeline__track-effect",children:y.effect}),n.jsx(v.NiceButton,{className:"nice-diagram-timeline__track-remove",variant:"ghost",size:"sm",onClick:()=>t==null?void 0:t(y.id),title:u("toolbar.delete"),children:"×"})]}),I&&n.jsxs("div",{className:"nice-diagram-timeline__track-editor",style:{display:"flex",gap:4,padding:"4px 0",flexWrap:"wrap",fontSize:11},children:[n.jsx(v.NiceSelect,{value:y.effect,onChange:N=>i==null?void 0:i(y.id,{effect:N}),options:Ni.map(N=>({value:N,label:N})),style:{fontSize:11,padding:"1px 4px"}}),n.jsx(v.NiceSelect,{value:y.easing,onChange:N=>i==null?void 0:i(y.id,{easing:N}),options:Ci.map(N=>({value:N,label:N})),style:{fontSize:11,padding:"1px 4px"}}),n.jsx(v.NiceSelect,{value:y.targetId,onChange:N=>{const k=s.find(T=>T.id===N);k&&(i==null||i(y.id,{targetId:k.id,targetType:k.type}))},options:s.map(N=>({value:N.id,label:N.label})),style:{fontSize:11,padding:"1px 4px",maxWidth:100}}),n.jsx(v.NiceNumberInput,{value:y.startMs,min:0,step:100,onChange:N=>i==null?void 0:i(y.id,{startMs:N??0}),style:{width:60,fontSize:11},title:"Start (ms)"}),n.jsx(v.NiceNumberInput,{value:y.durationMs,min:50,step:50,onChange:N=>i==null?void 0:i(y.id,{durationMs:N??50}),style:{width:60,fontSize:11},title:"Duration (ms)"})]}),n.jsx("div",{className:"nice-diagram-timeline__track-bar",children:n.jsx("div",{className:"nice-diagram-timeline__track-segment",style:{left:`${S}%`,width:`${M}%`},title:`${y.effect} ${y.startMs}ms → ${y.startMs+y.durationMs}ms (${y.easing})`})})]},y.id)})]}),n.jsx("div",{className:"nice-diagram-timeline__ruler",children:Array.from({length:5}).map((y,S)=>{const M=Math.round(w/4*S);return n.jsxs("span",{className:"nice-diagram-timeline__ruler-mark",style:{left:`${S/4*100}%`},children:[M,"ms"]},S)})})]})};Ke.displayName="AnimationTimeline";const Mi=/^[a-z][a-z0-9-]*$/,Si=.1,Ii=5,Xe=8,dt=[{cursor:"nw-resize",dx:0,dy:0,resizeX:-1,resizeY:-1},{cursor:"n-resize",dx:.5,dy:0,resizeX:0,resizeY:-1},{cursor:"ne-resize",dx:1,dy:0,resizeX:1,resizeY:-1},{cursor:"w-resize",dx:0,dy:.5,resizeX:-1,resizeY:0},{cursor:"e-resize",dx:1,dy:.5,resizeX:1,resizeY:0},{cursor:"sw-resize",dx:0,dy:1,resizeX:-1,resizeY:1},{cursor:"s-resize",dx:.5,dy:1,resizeX:0,resizeY:1},{cursor:"se-resize",dx:1,dy:1,resizeX:1,resizeY:1}],ve=({nodes:r,edges:e,groups:t=[],viewport:i,onViewportChange:a,theme:o,selectedId:c,selectedIds:s=[],onSelectElement:l,onMultiSelect:u,onNodeDragStart:d,onNodeDrag:m,onNodeDragEnd:p,onNodeResize:g,onNodeLabelChange:h,animationStates:x,particleState:w,viewMode:y="editor",ghostOpacity:S=.15,onGroupCollapse:M,onNodeCollapse:I,onInteraction:N,interactive:k=!1,showGrid:T=!0,showRulers:L=!1,snapToGrid:O=!0,gridSnapSize:F=10,className:W})=>{const C=b.useRef(null),[E,P]=b.useState(!1),[q,R]=b.useState({x:0,y:0}),[$,X]=b.useState(null),[G,U]=b.useState({x:0,y:0}),[J,ne]=b.useState(null),[de,V]=b.useState(null),[Y,ue]=b.useState(null),[fe,ae]=b.useState(null),[Ce,Te]=b.useState(""),[it,ge]=b.useState([]),at=(o==null?void 0:o.canvasBackground)??"var(--nice-bg-secondary, #f8f9fa)",Le=(o==null?void 0:o.gridColor)??"var(--nice-border, #e0e0e0)",Me=(o==null?void 0:o.gridSize)??20,Se=(o==null?void 0:o.selectionColor)??"var(--nice-primary, #2196f3)",Fe=b.useMemo(()=>{const f=new Set(s);return c&&f.add(c),f},[c,s]),be=b.useCallback(f=>O?Math.round(f/F)*F:f,[O,F]),We=b.useCallback((f,_,z)=>{const A=[],j=_.x,D=_.y,Q=j+z.width/2,Z=D+z.height/2,K=j+z.width,te=D+z.height;for(const he of r){if(he.id===f)continue;const ie=he.position.x,oe=he.position.y,pe=ie+he.size.width/2,ke=oe+he.size.height/2,Ie=ie+he.size.width,_e=oe+he.size.height;Math.abs(j-ie)<5&&A.push({x:ie}),Math.abs(K-Ie)<5&&A.push({x:Ie}),Math.abs(Q-pe)<5&&A.push({x:pe}),Math.abs(j-Ie)<5&&A.push({x:Ie}),Math.abs(K-ie)<5&&A.push({x:ie}),Math.abs(D-oe)<5&&A.push({y:oe}),Math.abs(te-_e)<5&&A.push({y:_e}),Math.abs(Z-ke)<5&&A.push({y:ke}),Math.abs(D-_e)<5&&A.push({y:_e}),Math.abs(te-oe)<5&&A.push({y:oe})}ge(A)},[r]),we=b.useCallback(f=>{if(f.preventDefault(),!a)return;const _=f.deltaY>0?.9:1.1,z=Math.min(Ii,Math.max(Si,i.zoom*_)),A=C.current;if(!A)return;const B=A.getBoundingClientRect(),j=f.clientX-B.left,D=f.clientY-B.top,Q=z/i.zoom,Z=j-(j-i.x)*Q,K=D-(D-i.y)*Q;a({x:Z,y:K,zoom:z})},[i,a]),ot=b.useCallback(f=>{if(f.button===1||f.button===0&&f.target.tagName==="svg"){if(f.button===0&&k&&!f.shiftKey&&f.target.tagName==="svg"){const _=C.current;if(_){const z=_.getBoundingClientRect(),A=(f.clientX-z.left-i.x)/i.zoom,B=(f.clientY-z.top-i.y)/i.zoom;V({x:A,y:B}),ne({x1:A,y1:B,x2:A,y2:B})}l&&l(null),u&&u([]);return}P(!0),R({x:f.clientX-i.x,y:f.clientY-i.y}),l&&f.button===0&&l(null)}},[i,l,u,k]),$e=b.useCallback(f=>{if(de){const _=C.current;if(!_)return;const z=_.getBoundingClientRect(),A=(f.clientX-z.left-i.x)/i.zoom,B=(f.clientY-z.top-i.y)/i.zoom;ne({x1:de.x,y1:de.y,x2:A,y2:B});return}if(E&&a){a({...i,x:f.clientX-q.x,y:f.clientY-q.y});return}if(Y&&g){const _=C.current;if(!_)return;const z=_.getBoundingClientRect(),A=(f.clientX-z.left-i.x)/i.zoom,B=(f.clientY-z.top-i.y)/i.zoom,j=A-Y.startMouse.x,D=B-Y.startMouse.y,Q=dt[Y.handleIdx];let Z=Y.startSize.width+j*Q.resizeX,K=Y.startSize.height+D*Q.resizeY,te=Y.startPos.x+(Q.resizeX<0?j:0),he=Y.startPos.y+(Q.resizeY<0?D:0);Z=Math.max(30,be(Z)),K=Math.max(20,be(K)),te=be(te),he=be(he),g(Y.nodeId,{width:Z,height:K},{x:te,y:he});return}if($&&m){const _=C.current;if(!_)return;const z=_.getBoundingClientRect(),A=be((f.clientX-z.left-i.x)/i.zoom-G.x),B=be((f.clientY-z.top-i.y)/i.zoom-G.y);m($,{x:A,y:B});const j=r.find(D=>D.id===$);j&&We($,{x:A,y:B},j.size)}},[de,E,a,i,q,Y,g,$,m,G,be,r,We]),Be=b.useCallback(f=>{if(J&&de){const _=Math.min(J.x1,J.x2),z=Math.min(J.y1,J.y2),A=Math.max(J.x1,J.x2),B=Math.max(J.y1,J.y2);if(Math.abs(A-_)>5||Math.abs(B-z)>5){const j=r.filter(D=>{const Q=D.position.x,Z=D.position.y,K=Q+D.size.width,te=Z+D.size.height;return K>_&&Q<A&&te>z&&Z<B}).map(D=>D.id);u==null||u(j),j.length===1&&(l==null||l(j[0]))}ne(null),V(null);return}if(E&&P(!1),Y){ue(null);return}if($&&p){const _=C.current;if(!_)return;const z=_.getBoundingClientRect(),A=be((f.clientX-z.left-i.x)/i.zoom-G.x),B=be((f.clientY-z.top-i.y)/i.zoom-G.y);p($,{x:A,y:B})}X(null),ge([])},[J,de,E,Y,$,p,i,G,be,r,u,l]),qe=b.useCallback((f,_)=>{if(f.stopPropagation(),!k)return;const z=r.find(Q=>Q.id===_);if(!z||z.locked)return;if(f.shiftKey&&u){const Q=[...s],Z=Q.indexOf(_);Z>=0?Q.splice(Z,1):Q.push(_),u(Q);return}l==null||l(_);const A=C.current;if(!A)return;const B=A.getBoundingClientRect(),j=(f.clientX-B.left-i.x)/i.zoom,D=(f.clientY-B.top-i.y)/i.zoom;U({x:j-z.position.x,y:D-z.position.y}),X(_),d==null||d(_)},[k,r,i,l,d,u,s]),st=b.useCallback((f,_,z)=>{if(f.stopPropagation(),!k)return;const A=r.find(Z=>Z.id===_);if(!A||A.locked)return;const B=C.current;if(!B)return;const j=B.getBoundingClientRect(),D=(f.clientX-j.left-i.x)/i.zoom,Q=(f.clientY-j.top-i.y)/i.zoom;ue({nodeId:_,handleIdx:z,startMouse:{x:D,y:Q},startPos:{...A.position},startSize:{...A.size}}),l==null||l(_)},[k,r,i,l]),nt=b.useCallback((f,_)=>{if(f.stopPropagation(),!k||!h)return;const z=r.find(A=>A.id===_);!z||z.locked||(ae(_),Te(z.label))},[k,r,h]),Ge=b.useCallback(()=>{fe&&h&&h(fe,Ce),ae(null)},[fe,Ce,h]),H=b.useCallback((f,_)=>{f.stopPropagation(),l==null||l(_)},[l]),je=b.useCallback(f=>{const _=r.find(z=>z.id===f);return _?{x:_.position.x+_.size.width/2,y:_.position.y+_.size.height/2}:{x:0,y:0}},[r]),ye=b.useCallback((f,_)=>{const z=r.find(D=>D.id===f);if(!z)return{x:0,y:0};const A=z.ports.find(D=>D.id===_);if(!A)return je(f);const{position:B,size:j}=z;switch(A.side){case"top":return{x:B.x+j.width*A.offset,y:B.y};case"bottom":return{x:B.x+j.width*A.offset,y:B.y+j.height};case"left":return{x:B.x,y:B.y+j.height*A.offset};case"right":return{x:B.x+j.width,y:B.y+j.height*A.offset};default:return je(f)}},[r,je]),nr=b.useCallback(f=>{const _=ye(f.sourceNodeId,f.sourcePortId),z=ye(f.targetNodeId,f.targetPortId);switch(f.style.lineType??"bezier"){case"straight":return`M ${_.x} ${_.y} L ${z.x} ${z.y}`;case"orthogonal":{const B=(_.x+z.x)/2;return`M ${_.x} ${_.y} L ${B} ${_.y} L ${B} ${z.y} L ${z.x} ${z.y}`}case"step":{const B=(_.y+z.y)/2;return`M ${_.x} ${_.y} L ${_.x} ${B} L ${z.x} ${B} L ${z.x} ${z.y}`}case"bezier":default:{const B=Math.abs(z.x-_.x)*.5;return`M ${_.x} ${_.y} C ${_.x+B} ${_.y}, ${z.x-B} ${z.y}, ${z.x} ${z.y}`}}},[ye]),cr=b.useCallback((f,_)=>{const{size:z,style:A,shape:B}=f,j=z.width,D=z.height,Z=!!(A.gradientColor&&A.backgroundColor)?`url(#${_})`:A.backgroundColor??"var(--nice-bg, #fff)",K=A.borderColor??"var(--nice-text, #333333)",te=A.borderWidth??1,he=A.borderRadius??(B==="roundedRect"?8:0),ie=A.borderStyle==="dashed"?"8,4":A.borderStyle==="dotted"?"2,4":void 0,oe=A.shadow?"url(#nd-shadow)":void 0;switch(B){case"ellipse":case"circle":return n.jsx("ellipse",{cx:j/2,cy:D/2,rx:j/2,ry:D/2,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe});case"diamond":return n.jsx("polygon",{points:`${j/2},0 ${j},${D/2} ${j/2},${D} 0,${D/2}`,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe});case"hexagon":{const pe=j/4;return n.jsx("polygon",{points:`${pe},0 ${j-pe},0 ${j},${D/2} ${j-pe},${D} ${pe},${D} 0,${D/2}`,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe})}case"parallelogram":{const pe=j*.15;return n.jsx("polygon",{points:`${pe},0 ${j},0 ${j-pe},${D} 0,${D}`,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe})}case"cylinder":return n.jsxs("g",{filter:oe,children:[n.jsx("ellipse",{cx:j/2,cy:D*.1,rx:j/2,ry:D*.1,fill:Z,stroke:K,strokeWidth:te}),n.jsx("rect",{x:0,y:D*.1,width:j,height:D*.8,fill:Z,stroke:"none"}),n.jsx("line",{x1:0,y1:D*.1,x2:0,y2:D*.9,stroke:K,strokeWidth:te}),n.jsx("line",{x1:j,y1:D*.1,x2:j,y2:D*.9,stroke:K,strokeWidth:te}),n.jsx("ellipse",{cx:j/2,cy:D*.9,rx:j/2,ry:D*.1,fill:Z,stroke:K,strokeWidth:te})]});case"triangle":return n.jsx("polygon",{points:`${j/2},0 ${j},${D} 0,${D}`,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe});case"cloud":{const pe=`M${j*.25},${D*.8} A${j*.2},${j*.2},0,1,1,${j*.15},${D*.45} A${j*.18},${j*.18},0,1,1,${j*.35},${D*.2} A${j*.2},${j*.2},0,1,1,${j*.65},${D*.2} A${j*.18},${j*.18},0,1,1,${j*.85},${D*.45} A${j*.2},${j*.2},0,1,1,${j*.75},${D*.8} Z`;return n.jsx("path",{d:pe,fill:Z,stroke:K,strokeWidth:te,filter:oe})}case"document":{const pe=`M 0 0 L ${j} 0 L ${j} ${D*.85} Q ${j*.75} ${D*.7}, ${j*.5} ${D*.85} Q ${j*.25} ${D}, 0 ${D*.85} Z`;return n.jsx("path",{d:pe,fill:Z,stroke:K,strokeWidth:te,filter:oe})}case"actor":return n.jsxs("g",{stroke:K,strokeWidth:te,fill:"none",filter:oe,children:[n.jsx("circle",{cx:j/2,cy:D*.15,r:D*.12,fill:Z}),n.jsx("line",{x1:j/2,y1:D*.27,x2:j/2,y2:D*.6}),n.jsx("line",{x1:j*.15,y1:D*.4,x2:j*.85,y2:D*.4}),n.jsx("line",{x1:j/2,y1:D*.6,x2:j*.2,y2:D}),n.jsx("line",{x1:j/2,y1:D*.6,x2:j*.8,y2:D})]});case"rectangle":case"roundedRect":case"custom":default:return n.jsx("rect",{width:j,height:D,rx:he,ry:he,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe})}},[]),wt=b.useCallback(f=>{if(!x)return{};const _=x.get(f);if(!_)return{};const z=_.glow>0?`drop-shadow(0 0 ${_.glow}px gold)`:"",A=_.highlightColor?`drop-shadow(0 0 6px ${_.highlightColor})`:"";return{opacity:_.opacity,transform:`translate(${_.translateX}px, ${_.translateY}px) scale(${_.scale})`,filter:[z,A].filter(Boolean).join(" ")||void 0}},[x]),lr=b.useMemo(()=>{if(!w)return null;const f=[];for(const[,_]of w.glowStates){const z=$t(_.elementId),A=Dt(_.intensity,_.pulse);f.push(n.jsxs("filter",{id:z,x:"-50%",y:"-50%",width:"200%",height:"200%",children:[n.jsx("feGaussianBlur",{in:"SourceGraphic",stdDeviation:A,result:"blur"}),n.jsx("feFlood",{floodColor:_.color,floodOpacity:.6,result:"color"}),n.jsx("feComposite",{in:"color",in2:"blur",operator:"in",result:"glowColored"}),n.jsxs("feMerge",{children:[n.jsx("feMergeNode",{in:"glowColored"}),n.jsx("feMergeNode",{in:"SourceGraphic"})]})]},z))}return f},[w]),dr=b.useMemo(()=>{if(!w)return null;const f=[];for(const[_,z]of w.liquidFlows){if(!z.active)continue;const A=e.find(Z=>Z.id===_);if(!(A!=null&&A.style.liquidFlow))continue;const{color:B,colorEnd:j}=A.style.liquidFlow,D=`nd-liquid-${_}`,Q=z.gradientOffset;f.push(n.jsxs("linearGradient",{id:D,x1:"0",y1:"0",x2:"1",y2:"0",children:[n.jsx("stop",{offset:`${Q*100%100}%`,stopColor:B,stopOpacity:.8}),n.jsx("stop",{offset:`${(Q+.3)*100%100}%`,stopColor:j??B,stopOpacity:.4}),n.jsx("stop",{offset:`${(Q+.6)*100%100}%`,stopColor:B,stopOpacity:.8})]},D))}return f},[w,e]),ur=b.useMemo(()=>r.filter(f=>f.style.gradientColor&&f.style.backgroundColor).map(f=>{const _=`nd-grad-${f.id}`,z=f.style.gradientDirection??"vertical";if(z==="radial")return n.jsxs("radialGradient",{id:_,children:[n.jsx("stop",{offset:"0%",stopColor:f.style.backgroundColor}),n.jsx("stop",{offset:"100%",stopColor:f.style.gradientColor})]},_);const A=z==="horizontal"||z==="diagonal"?"1":"0",B=z==="vertical"||z==="diagonal"?"1":"0";return n.jsxs("linearGradient",{id:_,x1:"0",y1:"0",x2:A,y2:B,children:[n.jsx("stop",{offset:"0%",stopColor:f.style.backgroundColor}),n.jsx("stop",{offset:"100%",stopColor:f.style.gradientColor})]},_)}),[r]);return n.jsxs("svg",{ref:C,className:`nice-diagram-canvas ${W??""}`,style:{width:"100%",height:"100%",background:at,cursor:E?"grabbing":Y&&Y.nodeId?dt[Y.handleIdx].cursor:"default"},onWheel:we,onMouseDown:ot,onMouseMove:$e,onMouseUp:Be,onMouseLeave:Be,children:[n.jsxs("defs",{children:[n.jsx("marker",{id:"nd-arrow",viewBox:"0 0 10 10",refX:"10",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:"12",markerHeight:"12",orient:"auto-start-reverse",children:n.jsx("path",{d:"M 0 0 L 10 5 L 0 10 Z",fill:"var(--nice-text, #333)"})}),n.jsx("marker",{id:"nd-open-arrow",viewBox:"0 0 10 10",refX:"10",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:"12",markerHeight:"12",orient:"auto-start-reverse",children:n.jsx("path",{d:"M 0 0 L 10 5 L 0 10",fill:"none",stroke:"var(--nice-text, #333)",strokeWidth:"1.5"})}),n.jsx("marker",{id:"nd-diamond-marker",viewBox:"0 0 10 10",refX:"5",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:"15",markerHeight:"15",orient:"auto-start-reverse",children:n.jsx("polygon",{points:"5,0 10,5 5,10 0,5",fill:"var(--nice-text, #333)"})}),n.jsx("marker",{id:"nd-circle-marker",viewBox:"0 0 10 10",refX:"5",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:"12",markerHeight:"12",orient:"auto-start-reverse",children:n.jsx("circle",{cx:"5",cy:"5",r:"4",fill:"var(--nice-text, #333)"})}),n.jsx("filter",{id:"nd-shadow",x:"-10%",y:"-10%",width:"130%",height:"130%",children:n.jsx("feDropShadow",{dx:"2",dy:"2",stdDeviation:"3",floodColor:"#00000033"})}),T&&n.jsx("pattern",{id:"nd-grid",width:Me,height:Me,patternUnits:"userSpaceOnUse",children:n.jsx("path",{d:`M ${Me} 0 L 0 0 0 ${Me}`,fill:"none",stroke:Le,strokeWidth:"0.5"})}),ur,lr,dr,r.filter(f=>f.style.glowColor).map(f=>{const _=`nd-node-glow-${f.id}`,z=(f.style.glowIntensity??.5)*10;return n.jsxs("filter",{id:_,x:"-50%",y:"-50%",width:"200%",height:"200%",children:[n.jsx("feGaussianBlur",{in:"SourceGraphic",stdDeviation:z,result:"blur"}),n.jsx("feFlood",{floodColor:f.style.glowColor,floodOpacity:.5,result:"color"}),n.jsx("feComposite",{in:"color",in2:"blur",operator:"in",result:"glowColored"}),n.jsxs("feMerge",{children:[n.jsx("feMergeNode",{in:"glowColored"}),n.jsx("feMergeNode",{in:"SourceGraphic"})]})]},_)})]}),L&&n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"0",y:"0",width:"100%",height:"20",fill:"var(--nice-bg-secondary, #f0f0f0)",stroke:"var(--nice-border, #ccc)",strokeWidth:"0.5"}),n.jsx("rect",{x:"0",y:"0",width:"20",height:"100%",fill:"var(--nice-bg-secondary, #f0f0f0)",stroke:"var(--nice-border, #ccc)",strokeWidth:"0.5"}),Array.from({length:100},(f,_)=>{const z=_*Me*i.zoom+i.x,A=_*Me;return z>20?n.jsxs("g",{children:[n.jsx("line",{x1:z,y1:"0",x2:z,y2:"20",stroke:"var(--nice-text-muted, #999)",strokeWidth:"0.5"}),n.jsx("text",{x:z+2,y:"14",fontSize:"9",fill:"var(--nice-text-secondary, #666)",children:A})]},`rx${_}`):null}),Array.from({length:100},(f,_)=>{const z=_*Me*i.zoom+i.y,A=_*Me;return z>20?n.jsxs("g",{children:[n.jsx("line",{x1:"0",y1:z,x2:"20",y2:z,stroke:"var(--nice-text-muted, #999)",strokeWidth:"0.5"}),n.jsx("text",{x:"2",y:z-2,fontSize:"9",fill:"var(--nice-text-secondary, #666)",writingMode:"tb",children:A})]},`ry${_}`):null})]}),n.jsxs("g",{transform:`translate(${i.x}, ${i.y}) scale(${i.zoom})`,children:[T&&n.jsx("rect",{x:"-10000",y:"-10000",width:"20000",height:"20000",fill:"url(#nd-grid)"}),t.map(f=>{var Q,Z,K,te,he,ie,oe,pe,ke,Ie,_e,Ve;const _=r.filter(se=>f.nodeIds.includes(se.id));if(_.length===0&&!f.collapsed)return null;const z=((Q=f.style)==null?void 0:Q.padding)??20;if(f.collapsed){const se=r.find(ct=>f.nodeIds.includes(ct.id)),Pe=se?se.position.x:0,Ye=se?se.position.y:0;return n.jsxs("g",{style:{cursor:"pointer"},onClick:()=>M==null?void 0:M(f.id),children:[n.jsx("rect",{x:Pe,y:Ye,width:160,height:40,fill:((Z=f.style)==null?void 0:Z.backgroundColor)??"rgba(200,200,255,0.3)",stroke:((K=f.style)==null?void 0:K.borderColor)??"var(--nice-text-muted, #aab)",strokeWidth:((te=f.style)==null?void 0:te.borderWidth)??1,rx:((he=f.style)==null?void 0:he.borderRadius)??6,strokeDasharray:"6,3"}),n.jsxs("text",{x:Pe+24,y:Ye+24,fontSize:"12",fill:((ie=f.style)==null?void 0:ie.labelColor)??"var(--nice-text-secondary, #666)",fontWeight:"bold",children:[f.label," (",f.nodeIds.length,")"]})]},f.id)}const A=Math.min(..._.map(se=>se.position.x))-z,B=Math.min(..._.map(se=>se.position.y))-z,j=Math.max(..._.map(se=>se.position.x+se.size.width))+z,D=Math.max(..._.map(se=>se.position.y+se.size.height))+z;return n.jsxs("g",{children:[n.jsx("rect",{x:A,y:B,width:j-A,height:D-B,fill:((oe=f.style)==null?void 0:oe.backgroundColor)??"rgba(200,200,255,0.1)",stroke:((pe=f.style)==null?void 0:pe.borderColor)??"var(--nice-text-muted, #aab)",strokeWidth:((ke=f.style)==null?void 0:ke.borderWidth)??1,rx:((Ie=f.style)==null?void 0:Ie.borderRadius)??6,strokeDasharray:((_e=f.style)==null?void 0:_e.borderStyle)==="dashed"?"6,3":void 0}),n.jsx("text",{x:A+6,y:B-4,fontSize:"12",fill:((Ve=f.style)==null?void 0:Ve.labelColor)??"var(--nice-text-secondary, #666)",fontWeight:"bold",children:f.label}),(k||y!=="editor")&&M&&n.jsxs("g",{style:{cursor:"pointer"},onClick:se=>{se.stopPropagation(),M(f.id)},children:[n.jsx("rect",{x:j-24,y:B-12,width:20,height:20,rx:4,fill:"white",stroke:"var(--nice-text-muted, #999)",strokeWidth:1}),n.jsx("g",{transform:`translate(${j-20}, ${B-8})`,children:n.jsx(v.NiceIcon,{name:"chevron-down",size:12,color:"var(--nice-text-secondary, #666)"})})]})]},f.id)}),it.map((f,_)=>n.jsx("line",{x1:f.x!=null?f.x:-1e4,y1:f.y!=null?f.y:-1e4,x2:f.x!=null?f.x:1e4,y2:f.y!=null?f.y:1e4,stroke:"#ff4081",strokeWidth:.5,strokeDasharray:"4,4"},`snap-${_}`)),e.map(f=>{var he;const _=nr(f),z=Fe.has(f.id),A=f.style.targetArrow==="diamond"?"url(#nd-diamond-marker)":f.style.targetArrow==="circle"?"url(#nd-circle-marker)":f.style.targetArrow==="openArrow"?"url(#nd-open-arrow)":f.style.targetArrow!=="none"?"url(#nd-arrow)":void 0,B=f.style.sourceArrow==="diamond"?"url(#nd-diamond-marker)":f.style.sourceArrow==="circle"?"url(#nd-circle-marker)":f.style.sourceArrow==="openArrow"?"url(#nd-open-arrow)":f.style.sourceArrow==="arrow"?"url(#nd-arrow)":void 0,j=wt(f.id),D=x==null?void 0:x.get(f.id),Q=D==null?void 0:D.strokeProgress,Z=Q!=null&&Q>=0&&Q<1?{strokeDasharray:"1000",strokeDashoffset:`${1e3*(1-Q)}`}:void 0,K=f.style.liquidFlow,te=w==null?void 0:w.liquidFlows.get(f.id);return n.jsxs("g",{style:j,onClick:ie=>H(ie,f.id),children:[k&&n.jsx("path",{d:_,fill:"none",stroke:"transparent",strokeWidth:12,style:{cursor:"pointer"}}),(K==null?void 0:K.active)&&n.jsx("path",{d:_,fill:"none",stroke:`url(#nd-liquid-${f.id})`,strokeWidth:K.pipeWidth??(f.style.strokeWidth??1.5)*4,strokeLinecap:"round",opacity:.5}),n.jsx("path",{d:_,fill:"none",stroke:z?Se:f.style.strokeColor??"var(--nice-text, #333)",strokeWidth:f.style.strokeWidth??1.5,strokeDasharray:(Z==null?void 0:Z.strokeDasharray)??((he=f.style.strokeDash)==null?void 0:he.join(","))??(f.style.animated?"6,4":void 0),strokeDashoffset:Z==null?void 0:Z.strokeDashoffset,markerEnd:A,markerStart:B,opacity:f.style.opacity??1,style:k?{cursor:"pointer",transition:Z?void 0:"stroke-dashoffset 0.1s"}:void 0}),f.style.animated&&n.jsx("circle",{r:3,fill:Se,children:n.jsx("animateMotion",{dur:`${1/(f.style.flowSpeed||1)}s`,repeatCount:"indefinite",path:_})}),(te==null?void 0:te.active)&&te.particles.map((ie,oe)=>n.jsx("circle",{r:ie.size,fill:(K==null?void 0:K.color)??"var(--nice-primary, #3b82f6)",opacity:ie.opacity*.6,children:n.jsx("animateMotion",{dur:`${3/(((K==null?void 0:K.speed)??1)+.5)}s`,repeatCount:"indefinite",path:_,begin:`${ie.t*3}s`})},`lp-${f.id}-${oe}`)),D&&D.particleTrailT>=0&&n.jsxs(n.Fragment,{children:[n.jsx("circle",{r:4,fill:"var(--nice-warning-light, #fbbf24)",opacity:.8,children:n.jsx("animateMotion",{dur:"2s",repeatCount:"indefinite",path:_,begin:`${D.particleTrailT*2}s`})}),n.jsx("circle",{r:2,fill:"var(--nice-warning-light, #fbbf24)",opacity:.5,children:n.jsx("animateMotion",{dur:"2s",repeatCount:"indefinite",path:_,begin:`${(D.particleTrailT+.1)*2}s`})})]}),f.label&&(()=>{const ie=ye(f.sourceNodeId,f.sourcePortId),oe=ye(f.targetNodeId,f.targetPortId),pe=(ie.x+oe.x)/2,ke=(ie.y+oe.y)/2;return n.jsxs("g",{children:[n.jsx("rect",{x:pe-4,y:ke-16,width:f.label.length*7+8,height:18,rx:3,fill:"var(--nice-bg-primary, #fff)",fillOpacity:.85}),n.jsx("text",{x:pe,y:ke-2,textAnchor:"start",fontSize:"11",fill:"var(--nice-text-secondary, #555)",children:f.label})]})})()]},f.id)}),r.filter(f=>!f.hidden||y==="editor").map(f=>{const _=Fe.has(f.id),z=wt(f.id),A=x==null?void 0:x.get(f.id),B=f.style.fontFamily??(o==null?void 0:o.fontFamily)??"sans-serif",j=f.style.fontSize??14,D=f.style.fontColor??"var(--nice-text, #222)",Q=f.style.fontWeight??"normal",Z=f.style.fontStyle??"normal",K=f.style.textAlign??"center",te=f.style.rotation??0,he=`nd-grad-${f.id}`,ie=!!f.hidden,oe=ie?S??.3:f.style.opacity??1,pe=f.style.glowColor?`url(#nd-node-glow-${f.id})`:void 0,ke=K==="left"?"start":K==="right"?"end":"middle",Ie=K==="left"?8:K==="right"?f.size.width-8:f.size.width/2,_e=A==null?void 0:A.typewriterChars,Ve=_e!=null&&_e>=0?f.label.slice(0,_e):f.label,se=A==null?void 0:A.liquidFillProgress,Pe=A==null?void 0:A.rippleRadius,Ye=A==null?void 0:A.rippleOpacity,ct=f.childNodeIds&&f.childNodeIds.length>0,fr=!!f.collapsed;return n.jsxs("g",{transform:`translate(${f.position.x}, ${f.position.y})${te?` rotate(${te}, ${f.size.width/2}, ${f.size.height/2})`:""}`,style:{...z,cursor:ie?"pointer":k&&!f.locked?"grab":"default",opacity:oe,filter:pe},onMouseDown:me=>qe(me,f.id),onDoubleClick:me=>nt(me,f.id),onClick:me=>{me.stopPropagation(),l==null||l(f.id),f.interactions&&f.interactions.length>0&&f.interactions.filter(Oe=>Oe.trigger==="click").forEach(Oe=>N==null?void 0:N(f.id,Oe.id))},onMouseEnter:()=>{f.interactions&&f.interactions.filter(ze=>ze.trigger==="hover").forEach(ze=>N==null?void 0:N(f.id,ze.id))},children:[ie&&n.jsx("rect",{x:-1,y:-1,width:f.size.width+2,height:f.size.height+2,fill:"none",stroke:"var(--nice-text-muted, #999)",strokeWidth:1,strokeDasharray:"3,3",rx:4,opacity:.5}),cr(f,he),se!=null&&se>0&&se<1&&n.jsx("clipPath",{id:`nd-liquid-clip-${f.id}`,children:n.jsx("rect",{x:0,y:f.size.height*(1-se),width:f.size.width,height:f.size.height*se})}),se!=null&&se>0&&se<1&&n.jsx("rect",{x:0,y:0,width:f.size.width,height:f.size.height,fill:f.style.glowColor??"var(--nice-primary, #3b82f6)",opacity:.25,rx:f.style.borderRadius??4,clipPath:`url(#nd-liquid-clip-${f.id})`}),Pe!=null&&Pe>0&&n.jsx("circle",{cx:f.size.width/2,cy:f.size.height/2,r:Pe,fill:"none",stroke:f.style.glowColor??Se,strokeWidth:2,opacity:Ye??.5}),_&&n.jsx("rect",{x:-3,y:-3,width:f.size.width+6,height:f.size.height+6,fill:"none",stroke:Se,strokeWidth:2,strokeDasharray:"4,3",rx:6}),_&&k&&!f.locked&&dt.map((me,ze)=>n.jsx("rect",{x:me.dx*f.size.width-Xe/2,y:me.dy*f.size.height-Xe/2,width:Xe,height:Xe,fill:"white",stroke:Se,strokeWidth:1.5,rx:1,style:{cursor:me.cursor},onMouseDown:Oe=>st(Oe,f.id,ze)},ze)),fe===f.id?n.jsx("foreignObject",{x:4,y:4,width:f.size.width-8,height:f.size.height-8,children:n.jsx("input",{xmlns:"http://www.w3.org/1999/xhtml",type:"text",value:Ce,onChange:me=>Te(me.target.value),onBlur:Ge,onKeyDown:me=>{me.key==="Enter"&&Ge(),me.key==="Escape"&&ae(null)},autoFocus:!0,style:{width:"100%",height:"100%",border:"1px solid "+Se,borderRadius:3,padding:"2px 4px",fontSize:j,fontFamily:B,fontWeight:Q,fontStyle:Z,textAlign:K,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",outline:"none"}})}):n.jsxs(n.Fragment,{children:[n.jsx("text",{x:Ie,y:f.size.height/2+(f.description?-4:0),textAnchor:ke,dominantBaseline:"central",fontFamily:B,fontSize:j,fontWeight:Q,fontStyle:Z,fill:D,pointerEvents:"none",children:Ve}),f.description&&n.jsx("text",{x:Ie,y:f.size.height/2+j*.8,textAnchor:ke,dominantBaseline:"central",fontFamily:B,fontSize:j*.75,fill:"var(--nice-text-secondary, #777)",pointerEvents:"none",children:f.description}),f.icon&&(Mi.test(f.icon)?n.jsx("g",{transform:`translate(${f.size.width/2-8}, 4)`,pointerEvents:"none",children:n.jsx(v.NiceIcon,{name:f.icon,size:16,color:"var(--nice-text-secondary, #666)"})}):n.jsx("text",{x:f.size.width/2,y:14,textAnchor:"middle",fontSize:16,pointerEvents:"none",children:f.icon})),f.style.linkUrl&&n.jsx("g",{transform:`translate(${f.size.width-14}, 3)`,pointerEvents:"none",children:n.jsx(v.NiceIcon,{name:"link",size:10,color:"var(--nice-primary-hover, #1976d2)"})}),ct&&k&&n.jsxs("g",{onClick:me=>{me.stopPropagation(),I==null||I(f.id)},style:{cursor:"pointer"},children:[n.jsx("rect",{x:f.size.width-18,y:f.size.height-18,width:16,height:16,rx:3,fill:"white",stroke:"var(--nice-text-muted, #aaa)",strokeWidth:.5}),n.jsx("g",{transform:`translate(${f.size.width-15}, ${f.size.height-15})`,children:n.jsx(v.NiceIcon,{name:fr?"chevron-right":"chevron-down",size:10,color:"var(--nice-text-secondary, #666)"})})]})]}),k&&f.ports.map(me=>{const ze=zi(f,me.id);return n.jsx("circle",{cx:ze.x,cy:ze.y,r:4,fill:"var(--nice-bg, #fff)",stroke:"var(--nice-text-secondary, #666)",strokeWidth:1,style:{cursor:"crosshair"}},me.id)})]},f.id)}),w&&w.particles.length>0&&n.jsx("g",{className:"nd-particle-overlay",children:w.particles.map((f,_)=>n.jsx("circle",{cx:f.x,cy:f.y,r:f.size,fill:f.color,opacity:f.opacity},`ptcl-${_}`))}),J&&n.jsx("rect",{x:Math.min(J.x1,J.x2),y:Math.min(J.y1,J.y2),width:Math.abs(J.x2-J.x1),height:Math.abs(J.y2-J.y1),fill:"rgba(33,150,243,0.1)",stroke:Se,strokeWidth:1,strokeDasharray:"4,2"})]})]})};function zi(r,e){const t=r.ports.find(a=>a.id===e);if(!t)return{x:0,y:0};const{size:i}=r;switch(t.side){case"top":return{x:i.width*t.offset,y:0};case"bottom":return{x:i.width*t.offset,y:i.height};case"left":return{x:0,y:i.height*t.offset};case"right":return{x:i.width,y:i.height*t.offset};default:return{x:0,y:0}}}ve.displayName="DiagramCanvas";const ji=180,Ai=120,Qe=({nodes:r,edges:e,viewport:t,onViewportChange:i,canvasWidth:a=800,canvasHeight:o=600,width:c=ji,height:s=Ai,className:l})=>{const u=b.useMemo(()=>{if(r.length===0)return{minX:0,minY:0,maxX:400,maxY:300};let x=1/0,w=1/0,y=-1/0,S=-1/0;for(const I of r)x=Math.min(x,I.position.x),w=Math.min(w,I.position.y),y=Math.max(y,I.position.x+I.size.width),S=Math.max(S,I.position.y+I.size.height);const M=50;return{minX:x-M,minY:w-M,maxX:y+M,maxY:S+M}},[r]),d=u.maxX-u.minX,m=u.maxY-u.minY,p=Math.min(c/d,s/m),g=b.useMemo(()=>{const x=(-t.x/t.zoom-u.minX)*p,w=(-t.y/t.zoom-u.minY)*p,y=a/t.zoom*p,S=o/t.zoom*p;return{x,y:w,w:y,h:S}},[t,u,p,a,o]),h=b.useCallback(x=>{if(!i)return;const w=x.currentTarget.getBoundingClientRect(),y=x.clientX-w.left,S=x.clientY-w.top,M=y/p+u.minX,I=S/p+u.minY;i({...t,x:-(M*t.zoom-a/2),y:-(I*t.zoom-o/2)})},[i,t,p,u,a,o]);return n.jsxs("svg",{className:`nice-diagram-minimap ${l??""}`,width:c,height:s,style:{border:"1px solid var(--nice-border, #ccc)",background:"var(--nice-bg, #fff)",borderRadius:4,cursor:"pointer"},onClick:h,children:[e.map(x=>{const w=r.find(k=>k.id===x.sourceNodeId),y=r.find(k=>k.id===x.targetNodeId);if(!w||!y)return null;const S=(w.position.x+w.size.width/2-u.minX)*p,M=(w.position.y+w.size.height/2-u.minY)*p,I=(y.position.x+y.size.width/2-u.minX)*p,N=(y.position.y+y.size.height/2-u.minY)*p;return n.jsx("line",{x1:S,y1:M,x2:I,y2:N,stroke:"var(--nice-text-muted, #aaa)",strokeWidth:.5},x.id)}),r.map(x=>n.jsx("rect",{x:(x.position.x-u.minX)*p,y:(x.position.y-u.minY)*p,width:x.size.width*p,height:x.size.height*p,fill:x.style.backgroundColor??"var(--nice-border, #ddd)",stroke:"var(--nice-text-muted, #999)",strokeWidth:.5},x.id)),n.jsx("rect",{x:g.x,y:g.y,width:g.w,height:g.h,fill:"rgba(33,150,243,0.15)",stroke:"var(--nice-primary, #2196f3)",strokeWidth:1})]})};Qe.displayName="DiagramMinimap";const $i=["rectangle","roundedRect","ellipse","circle","diamond","hexagon","parallelogram","cylinder","triangle","cloud","document","actor"],et=({selectedNode:r,selectedEdge:e,onNodeChange:t,onEdgeChange:i,onRemove:a,className:o})=>{var u,d,m,p,g;const{t:c}=Ee(),s=b.useCallback((h,x)=>{!r||!t||t(r.id,{style:{...r.style,[h]:x}})},[r,t]),l=b.useCallback((h,x)=>{!e||!i||i(e.id,{style:{...e.style,[h]:x}})},[e,i]);return!r&&!e?n.jsx("div",{className:`nice-diagram-property-panel nice-diagram-property-panel--empty ${o??""}`,children:n.jsx("p",{className:"nice-diagram-property-panel__hint",children:c("panel.noSelection")})}):r?n.jsxs("div",{className:`nice-diagram-property-panel ${o??""}`,children:[n.jsx("h3",{className:"nice-diagram-property-panel__title",children:c("panel.nodeProperties")}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("node.label"),n.jsx(v.NiceTextInput,{value:r.label,onChange:h=>t==null?void 0:t(r.id,{label:h}),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("node.description"),n.jsx(v.NiceTextInput,{value:r.description??"",onChange:h=>t==null?void 0:t(r.id,{description:h||void 0}),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("node.shape"),n.jsx(v.NiceSelect,{value:r.shape,onChange:h=>t==null?void 0:t(r.id,{shape:h}),options:$i.map(h=>({value:h,label:h})),className:"nice-diagram-property-panel__select"})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.width"),n.jsx(v.NiceNumberInput,{value:r.size.width,min:20,onChange:h=>t==null?void 0:t(r.id,{size:{...r.size,width:h??40}}),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.height"),n.jsx(v.NiceNumberInput,{value:r.size.height,min:20,onChange:h=>t==null?void 0:t(r.id,{size:{...r.size,height:h??40}}),className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.bgColor"),n.jsx(v.NiceColorPicker,{value:r.style.backgroundColor??"var(--nice-bg, #fff)",onChange:h=>s("backgroundColor",h),className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.borderColor"),n.jsx(v.NiceColorPicker,{value:r.style.borderColor??"var(--nice-text, #333333)",onChange:h=>s("borderColor",h),className:"nice-diagram-property-panel__color"})]})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.fontSize"),n.jsx(v.NiceNumberInput,{value:r.style.fontSize??14,min:8,max:72,onChange:h=>s("fontSize",h??14),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.fontColor"),n.jsx(v.NiceColorPicker,{value:r.style.fontColor??"#222222",onChange:h=>s("fontColor",h),className:"nice-diagram-property-panel__color"})]})]}),n.jsx(v.NiceCheckbox,{checked:r.locked??!1,onChange:h=>t==null?void 0:t(r.id,{locked:h}),label:c("node.locked"),className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),n.jsx("h4",{className:"nice-diagram-property-panel__section-title",style:{fontSize:12,marginTop:12,marginBottom:4,color:"var(--nice-text-secondary, #666)"},children:"Effects"}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Glow Color",n.jsx(v.NiceColorPicker,{value:r.style.glowColor??"var(--nice-primary, #3b82f6)",onChange:h=>s("glowColor",h),className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Glow Intensity",n.jsx(v.NiceSlider,{min:0,max:3,step:.1,value:r.style.glowIntensity??0,onChange:h=>s("glowIntensity",h),className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Opacity",n.jsx(v.NiceSlider,{min:0,max:1,step:.05,value:r.style.opacity??1,onChange:h=>s("opacity",h),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Border Radius",n.jsx(v.NiceNumberInput,{min:0,max:50,value:r.style.borderRadius??4,onChange:h=>s("borderRadius",h??4),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Border Width",n.jsx(v.NiceNumberInput,{min:0,max:10,step:.5,value:r.style.borderWidth??1,onChange:h=>s("borderWidth",h??1),className:"nice-diagram-property-panel__input"})]}),n.jsx(v.NiceCheckbox,{checked:r.style.shadow??!1,onChange:h=>s("shadow",h),label:"Shadow",className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Gradient End",n.jsx(v.NiceColorPicker,{value:r.style.gradientColor??"var(--nice-bg, #fff)",onChange:h=>s("gradientColor",h),className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Gradient Dir",n.jsx(v.NiceSelect,{value:r.style.gradientDirection??"vertical",onChange:h=>s("gradientDirection",h),options:[{value:"vertical",label:"Vertical"},{value:"horizontal",label:"Horizontal"},{value:"diagonal",label:"Diagonal"},{value:"radial",label:"Radial"}],className:"nice-diagram-property-panel__select"})]})]}),n.jsx(v.NiceCheckbox,{checked:r.hidden??!1,onChange:h=>t==null?void 0:t(r.id,{hidden:h}),label:"Hidden (ghost in editor)",className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),n.jsx(v.NiceButton,{className:"nice-diagram-property-panel__btn nice-diagram-property-panel__btn--danger",variant:"ghost",size:"sm",onClick:()=>a==null?void 0:a(r.id),children:c("toolbar.delete")})]}):e?n.jsxs("div",{className:`nice-diagram-property-panel ${o??""}`,children:[n.jsx("h3",{className:"nice-diagram-property-panel__title",children:c("panel.edgeProperties")}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("edge.label"),n.jsx(v.NiceTextInput,{value:e.label??"",onChange:h=>i==null?void 0:i(e.id,{label:h||void 0}),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("edge.lineType"),n.jsx(v.NiceSelect,{value:e.style.lineType??"bezier",onChange:h=>l("lineType",h),options:[{value:"straight",label:"Straight"},{value:"bezier",label:"Bezier"},{value:"orthogonal",label:"Orthogonal"},{value:"step",label:"Step"}],className:"nice-diagram-property-panel__select"})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("edge.color"),n.jsx(v.NiceColorPicker,{value:e.style.strokeColor??"var(--nice-text, #333333)",onChange:h=>l("strokeColor",h),className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("edge.width"),n.jsx(v.NiceNumberInput,{value:e.style.strokeWidth??1.5,min:.5,max:10,step:.5,onChange:h=>l("strokeWidth",h??1.5),className:"nice-diagram-property-panel__input"})]})]}),n.jsx(v.NiceCheckbox,{checked:e.style.animated??!1,onChange:h=>l("animated",h),label:c("edge.animated"),className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),e.style.animated&&n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Flow Speed",n.jsx(v.NiceSlider,{min:.1,max:5,step:.1,value:e.style.flowSpeed??1,onChange:h=>l("flowSpeed",h),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Dash Style",n.jsx(v.NiceSelect,{value:e.style.strokeDash?e.style.strokeDash.join(","):"solid",onChange:h=>{const x=h;x==="solid"?l("strokeDash",[]):l("strokeDash",x.split(",").map(Number))},options:[{value:"solid",label:"Solid"},{value:"6,4",label:"Dashed"},{value:"2,2",label:"Dotted"},{value:"8,4,2,4",label:"Dash-Dot"},{value:"12,6",label:"Long Dash"}],className:"nice-diagram-property-panel__select"})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Target Arrow",n.jsx(v.NiceSelect,{value:e.style.targetArrow??"arrow",onChange:h=>l("targetArrow",h),options:[{value:"arrow",label:"Arrow"},{value:"openArrow",label:"Open Arrow"},{value:"diamond",label:"Diamond"},{value:"circle",label:"Circle"},{value:"none",label:"None"}],className:"nice-diagram-property-panel__select"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Source Arrow",n.jsx(v.NiceSelect,{value:e.style.sourceArrow??"none",onChange:h=>l("sourceArrow",h),options:[{value:"none",label:"None"},{value:"arrow",label:"Arrow"},{value:"openArrow",label:"Open Arrow"},{value:"diamond",label:"Diamond"},{value:"circle",label:"Circle"}],className:"nice-diagram-property-panel__select"})]})]}),n.jsx("h4",{className:"nice-diagram-property-panel__section-title",style:{fontSize:12,marginTop:12,marginBottom:4,color:"var(--nice-text-secondary, #666)"},children:"Liquid Flow"}),n.jsx(v.NiceCheckbox,{checked:((u=e.style.liquidFlow)==null?void 0:u.active)??!1,onChange:h=>{const x=e.style.liquidFlow??{active:!1,color:"var(--nice-primary, #3b82f6)",speed:1,pipeWidth:6};i==null||i(e.id,{style:{...e.style,liquidFlow:{...x,active:h}}})},label:"Enable Liquid Flow",className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),((d=e.style.liquidFlow)==null?void 0:d.active)&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Color",n.jsx(v.NiceColorPicker,{value:((m=e.style.liquidFlow)==null?void 0:m.color)??"var(--nice-primary, #3b82f6)",onChange:h=>{const x=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...x,color:h}}})},className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Speed",n.jsx(v.NiceSlider,{min:.1,max:5,step:.1,value:((p=e.style.liquidFlow)==null?void 0:p.speed)??1,onChange:h=>{const x=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...x,speed:h}}})},className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Pipe Width",n.jsx(v.NiceNumberInput,{min:2,max:20,value:((g=e.style.liquidFlow)==null?void 0:g.pipeWidth)??6,onChange:h=>{const x=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...x,pipeWidth:h??6}}})},className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Opacity",n.jsx(v.NiceSlider,{min:0,max:1,step:.05,value:e.style.opacity??1,onChange:h=>l("opacity",h),className:"nice-diagram-property-panel__input"})]}),n.jsx(v.NiceButton,{className:"nice-diagram-property-panel__btn nice-diagram-property-panel__btn--danger",variant:"ghost",size:"sm",onClick:()=>a==null?void 0:a(e.id),children:c("toolbar.delete")})]}):null};et.displayName="DiagramPropertyPanel";const Nt={flowchart:["rectangle","roundedRect","diamond","parallelogram","ellipse","circle","document","cylinder"],orgchart:["roundedRect","ellipse","rectangle"],mindmap:["roundedRect","ellipse","cloud","rectangle"],bpmn:["rectangle","roundedRect","circle","diamond","document"],er:["rectangle","diamond","ellipse"],sequence:["rectangle","actor","circle"],stateMachine:["roundedRect","circle","diamond"],networkTopology:["rectangle","circle","cloud","cylinder","hexagon"],decisionTree:["rectangle","diamond","roundedRect"],custom:["rectangle","roundedRect","ellipse","circle","diamond","hexagon","parallelogram","cylinder","triangle","cloud","document","actor"]},Di=["dagre","forceDirected","grid","radial","tree"],Ti=["sans-serif","serif","monospace","Arial","Helvetica","Times New Roman","Courier New","Georgia","Verdana","Tahoma","Trebuchet MS"],Pi=[8,9,10,11,12,14,16,18,20,24,28,32,36,48,72],tt=({activeTool:r,onToolChange:e,diagramType:t,onAddNode:i,onApplyLayout:a,onUndo:o,onRedo:c,canUndo:s=!1,canRedo:l=!1,onExport:u,onZoomIn:d,onZoomOut:m,onZoomReset:p,zoomLevel:g=1,onToggleBold:h,onToggleItalic:x,isBold:w=!1,isItalic:y=!1,onFontFamilyChange:S,currentFontFamily:M="sans-serif",onFontSizeChange:I,currentFontSize:N=14,onAlignLeft:k,onAlignCenterH:T,onAlignRight:L,onAlignTop:O,onAlignCenterV:F,onAlignBottom:W,onDistributeH:C,onDistributeV:E,onBringToFront:P,onSendToBack:q,onGroupSelected:R,onUngroupSelected:$,onCopy:X,onPaste:G,onDuplicate:U,onSelectAll:J,selectionCount:ne=0,onFind:de,showFind:V=!1,findQuery:Y="",onFindQueryChange:ue,viewMode:fe="editor",onViewModeChange:ae,stylePresetId:Ce,onStylePresetChange:Te,className:it})=>{const{t:ge}=Ee(),[at,Le]=b.useState(!1),[Me,Se]=b.useState(!1),[Fe,be]=b.useState(!1),[We,we]=b.useState(!1),[ot,$e]=b.useState(!1),[Be,qe]=b.useState(!1),st=Nt[t]??Nt.custom,nt=b.useCallback(H=>{i==null||i(H),Le(!1)},[i]),Ge=b.useCallback(H=>{a==null||a(H),Se(!1)},[a]);return n.jsxs("div",{className:`nice-diagram-toolbar ${it??""}`,children:[n.jsxs("div",{className:"nice-diagram-toolbar__row",children:[n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="select"?"primary":"ghost",size:"sm",onClick:()=>e("select"),title:`${ge("toolbar.select")} (V)`,children:n.jsx(v.NiceIcon,{name:"cursor",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="pan"?"primary":"ghost",size:"sm",onClick:()=>e("pan"),title:`${ge("toolbar.pan")} (H)`,children:n.jsx(v.NiceIcon,{name:"move",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="addEdge"?"primary":"ghost",size:"sm",onClick:()=>e("addEdge"),title:`${ge("toolbar.addEdge")} (C)`,children:n.jsx(v.NiceIcon,{name:"link",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="text"?"primary":"ghost",size:"sm",onClick:()=>e("text"),title:"Text (T)",children:n.jsx(v.NiceIcon,{name:"type",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="freehand"?"primary":"ghost",size:"sm",onClick:()=>e("freehand"),title:"Freehand (F)",children:n.jsx(v.NiceIcon,{name:"pen",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="delete"?"primary":"ghost",size:"sm",onClick:()=>e("delete"),title:`${ge("toolbar.delete")} (Del)`,children:n.jsx(v.NiceIcon,{name:"trash",size:14})})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="addNode"?"primary":"ghost",size:"sm",onClick:()=>Le(H=>!H),title:ge("toolbar.addNode"),children:[n.jsx(v.NiceIcon,{name:"plus",size:14})," ",ge("toolbar.addNode")]}),at&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown nice-diagram-toolbar__dropdown--shapes",children:st.map(H=>n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>nt(H),children:[n.jsx(v.NiceIcon,{name:Ri(H),size:14})," ",H]},H))})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:X,title:"Copy (Ctrl+C)",children:n.jsx(v.NiceIcon,{name:"copy",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:G,title:"Paste (Ctrl+V)",children:n.jsx(v.NiceIcon,{name:"clipboard",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:U,title:"Duplicate (Ctrl+D)",children:n.jsx(v.NiceIcon,{name:"layers",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:J,title:"Select All (Ctrl+A)",children:n.jsx(v.NiceIcon,{name:"check-square",size:14})})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:o,disabled:!s,title:`${ge("toolbar.undo")} (Ctrl+Z)`,children:n.jsx(v.NiceIcon,{name:"undo",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:c,disabled:!l,title:`${ge("toolbar.redo")} (Ctrl+Y)`,children:n.jsx(v.NiceIcon,{name:"redo",size:14})})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:m,title:ge("toolbar.zoomOut"),children:n.jsx(v.NiceIcon,{name:"minus",size:14})}),n.jsxs("span",{className:"nice-diagram-toolbar__zoom-label",children:[Math.round(g*100),"%"]}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:d,title:ge("toolbar.zoomIn"),children:n.jsx(v.NiceIcon,{name:"plus",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:p,title:ge("toolbar.zoomReset"),children:"1:1"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:de,title:"Find (Ctrl+F)",children:n.jsx(v.NiceIcon,{name:"search",size:14})}),V&&n.jsx(v.NiceTextInput,{className:"nice-diagram-toolbar__search",placeholder:"Search nodes…",value:Y,onChange:H=>ue==null?void 0:ue(H),autoFocus:!0})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>be(H=>!H),title:ge("toolbar.export"),children:[n.jsx(v.NiceIcon,{name:"download",size:14})," ",ge("toolbar.export")]}),Fe&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("ndd"),be(!1)},children:".ndd.json"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("svg"),be(!1)},children:"SVG"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("mermaid"),be(!1)},children:"Mermaid"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("png"),be(!1)},children:"PNG"})]})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__row nice-diagram-toolbar__format-bar",children:[n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceSelect,{className:"nice-diagram-toolbar__font-select",value:M,onChange:H=>S==null?void 0:S(H),options:Ti.map(H=>({value:H,label:H})),title:"Font Family"}),n.jsx(v.NiceSelect,{className:"nice-diagram-toolbar__size-select",value:String(N),onChange:H=>I==null?void 0:I(Number(H)),options:Pi.map(H=>({value:String(H),label:String(H)})),title:"Font Size"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:w?"primary":"ghost",size:"sm",onClick:h,title:"Bold (Ctrl+B)",children:n.jsx("strong",{children:"B"})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:y?"primary":"ghost",size:"sm",onClick:x,title:"Italic (Ctrl+I)",children:n.jsx("em",{children:"I"})})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>we(H=>!H),title:"Alignment & Distribution",children:"≡ Align"}),We&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown nice-diagram-toolbar__dropdown--align",children:[n.jsx("div",{className:"nice-diagram-toolbar__dropdown-section",children:"Align"}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{k==null||k(),we(!1)},title:"Align Left",children:[n.jsx(v.NiceIcon,{name:"align-left",size:14})," Left"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{T==null||T(),we(!1)},title:"Align Center",children:[n.jsx(v.NiceIcon,{name:"align-center",size:14})," Center"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{L==null||L(),we(!1)},title:"Align Right",children:[n.jsx(v.NiceIcon,{name:"align-right",size:14})," Right"]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{O==null||O(),we(!1)},title:"Align Top",children:[n.jsx(v.NiceIcon,{name:"align-top",size:14})," Top"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{F==null||F(),we(!1)},title:"Align Middle",children:[n.jsx(v.NiceIcon,{name:"align-middle",size:14})," Middle"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{W==null||W(),we(!1)},title:"Align Bottom",children:[n.jsx(v.NiceIcon,{name:"align-bottom",size:14})," Bottom"]})]}),n.jsx("div",{className:"nice-diagram-toolbar__dropdown-section",children:"Distribute"}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{C==null||C(),we(!1)},title:"Distribute Horizontally",children:[n.jsx(v.NiceIcon,{name:"distribute-h",size:14})," H"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{E==null||E(),we(!1)},title:"Distribute Vertically",children:[n.jsx(v.NiceIcon,{name:"distribute-v",size:14})," V"]})]})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>$e(H=>!H),title:"Arrange",children:[n.jsx(v.NiceIcon,{name:"menu",size:14})," Arrange"]}),ot&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{P==null||P(),$e(!1)},children:"↑ Bring to Front"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{q==null||q(),$e(!1)},children:"↓ Send to Back"}),n.jsx("div",{className:"nice-diagram-toolbar__dropdown-divider"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{R==null||R(),$e(!1)},disabled:ne<2,children:"⊞ Group"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{$==null||$(),$e(!1)},children:"⊟ Ungroup"})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>Se(H=>!H),title:ge("toolbar.layout"),children:["⊞ ",ge("toolbar.layout")]}),Me&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown",children:Di.map(H=>n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>Ge(H),children:ge(`layout.${H}`)},H))})]}),ne>1&&n.jsxs("span",{className:"nice-diagram-toolbar__selection-info",children:[ne," selected"]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:fe==="editor"?"primary":"ghost",size:"sm",onClick:()=>ae==null?void 0:ae("editor"),title:"Editor Mode",children:[n.jsx(v.NiceIcon,{name:"edit",size:14})," Editor"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:fe==="player"?"primary":"ghost",size:"sm",onClick:()=>ae==null?void 0:ae("player"),title:"Player Mode",children:[n.jsx(v.NiceIcon,{name:"play",size:14})," Player"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:fe==="playerAnimated"?"primary":"ghost",size:"sm",onClick:()=>ae==null?void 0:ae("playerAnimated"),title:"Animated Player Mode",children:[n.jsx(v.NiceIcon,{name:"zap",size:14})," Animated"]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>qe(H=>!H),title:"Style Presets",children:[n.jsx(v.NiceIcon,{name:"palette",size:14})," Style"]}),Be&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown nice-diagram-toolbar__dropdown--presets",style:{maxHeight:320,overflowY:"auto",width:220},children:Object.entries(Ze.reduce((H,je)=>{const ye=je.category??"Other";return H[ye]||(H[ye]=[]),H[ye].push(je),H},{})).map(([H,je])=>n.jsxs("div",{children:[n.jsx("div",{className:"nice-diagram-toolbar__dropdown-section",style:{fontSize:10,color:"var(--nice-text-secondary, #888)",padding:"6px 8px 2px",textTransform:"uppercase"},children:H}),je.map(ye=>n.jsxs(v.NiceButton,{className:`nice-diagram-toolbar__dropdown-item ${Ce===ye.id?"nice-diagram-toolbar__dropdown-item--active":""}`,variant:Ce===ye.id?"primary":"ghost",size:"sm",onClick:()=>{Te==null||Te(ye.id),qe(!1)},style:{display:"flex",alignItems:"center",gap:8},children:[n.jsx("span",{style:{width:16,height:16,borderRadius:3,background:ye.config.palette.primary,border:"1px solid "+(ye.config.palette.border??"var(--nice-border, #ccc)"),display:"inline-block",flexShrink:0}}),n.jsx("span",{style:{fontSize:12},children:ye.name})]},ye.id))]},H))})]})]})]})};function Ri(r){switch(r){case"rectangle":return"square";case"roundedRect":return"card";case"ellipse":return"circle";case"circle":return"circle";case"diamond":return"diamond";case"hexagon":return"hexagon";case"parallelogram":return"parallelogram";case"cylinder":return"database";case"triangle":return"triangle";case"cloud":return"cloud";case"document":return"file";case"actor":return"user";default:return"card"}}tt.displayName="DiagramToolbar";const Oi=[{target:".nice-diagram-editor",titleKey:"tutorial.diagramEditor.intro.title",title:"Diagram editor",contentKey:"tutorial.diagramEditor.intro.content",content:"Pick a tool to add and connect nodes on the canvas, edit them in the property panel, and export the diagram from the toolbar.",placement:"auto"}],Wt=({initialDocument:r,diagramType:e="flowchart",onChange:t,onExport:i,lang:a="en",showToolbar:o=!0,showPropertyPanel:c=!0,showMinimap:s=!0,showTimeline:l=!0,className:u,style:d,tutorial:m})=>{var de;const p=Lt(r),[g,h]=b.useState("select"),[x,w]=b.useState(null),y=b.useRef(null),[S,M]=b.useState("editor"),I=b.useRef(null),[N,k]=b.useState({particles:[],liquidFlows:new Map,glowStates:new Map});b.useEffect(()=>{const V=new At(Y=>{k(Y)});return I.current=V,V.start(),()=>{V.stop(),I.current=null}},[]),b.useEffect(()=>{var Y;const V=I.current;if(V)for(const ue of p.edges)(Y=ue.style.liquidFlow)!=null&&Y.active?V.startLiquidFlow(ue.id,ue.style.liquidFlow):V.stopLiquidFlow(ue.id)},[p.edges]),b.useEffect(()=>{const V=I.current;if(V)for(const Y of p.nodes)Y.style.glowColor?V.setGlow(Y.id,Y.style.glowColor,Y.style.glowIntensity??1):V.removeGlow(Y.id)},[p.nodes]);const T=b.useCallback(V=>{p.setStylePreset(V)},[p]),L=b.useCallback((V,Y)=>{const ue=p.nodes.find(ae=>ae.id===V);if(!(ue!=null&&ue.interactions))return;const fe=ue.interactions.find(ae=>ae.id===Y);if(fe)switch(fe.action){case"reveal":{if(fe.targetId){const ae=p.nodes.find(Ce=>Ce.id===fe.targetId);ae!=null&&ae.hidden&&p.updateNode(fe.targetId,{hidden:!1})}break}case"navigate":{if(fe.targetId){const ae=p.nodes.find(Ce=>Ce.id===fe.targetId);ae&&(p.setViewport({x:-ae.position.x+300,y:-ae.position.y+200,zoom:p.viewport.zoom}),w(fe.targetId))}break}case"switchAnimationMode":{fe.targetId&&p.setActiveAnimationMode(fe.targetId);break}case"highlight":{fe.targetId&&w(fe.targetId);break}case"toggleCollapse":{p.toggleNodeCollapse(V);break}}},[p]),O=b.useRef(p.document);p.document!==O.current&&(O.current=p.document,t==null||t(p.document));const F=b.useMemo(()=>x?p.nodes.find(V=>V.id===x)??null:null,[x,p.nodes]),W=b.useMemo(()=>x?p.edges.find(V=>V.id===x)??null:null,[x,p.edges]),C=b.useCallback(V=>{const Y=p.viewport,ue=(-Y.x+400)/Y.zoom,fe=(-Y.y+300)/Y.zoom,ae=p.addNode("New Node",{x:ue,y:fe},V);w(ae.id),h("select")},[p]),E=b.useCallback(V=>{p.applyLayout({algorithm:V,centerGraph:!0})},[p]),P=b.useCallback((V,Y)=>{p.moveNode(V,Y)},[p]),q=b.useCallback((V,Y)=>{p.moveNode(V,Y)},[p]),R=b.useCallback(V=>{p.nodes.find(Y=>Y.id===V)?p.removeNode(V):p.edges.find(Y=>Y.id===V)&&p.removeEdge(V),w(null)},[p]),$=b.useCallback(V=>{const Y=p.document;let ue;switch(V){case"ndd":ue=Rt(Y,!0);break;case"svg":ue=ft(Y);break;case"mermaid":ue=Tt(Y);break;case"png":ue=ft(Y);break}i==null||i(V,ue)},[p,i]),X=b.useCallback(()=>{p.setViewport({...p.viewport,zoom:Math.min(5,p.viewport.zoom*1.2)})},[p]),G=b.useCallback(()=>{p.setViewport({...p.viewport,zoom:Math.max(.1,p.viewport.zoom/1.2)})},[p]),U=b.useCallback(()=>{p.setViewport({x:0,y:0,zoom:1})},[p]),J=b.useMemo(()=>[...p.nodes.map(V=>({id:V.id,label:V.label,type:"node"})),...p.edges.map(V=>({id:V.id,label:V.label??V.id,type:"edge"}))],[p.nodes,p.edges]),ne=o||p.animationModes.length>0?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,width:"100%"},children:[o&&n.jsx(tt,{activeTool:g,onToolChange:h,diagramType:p.document.diagramType,onAddNode:C,onApplyLayout:E,onUndo:p.undo,onRedo:p.redo,canUndo:p.canUndo,canRedo:p.canRedo,onExport:$,onZoomIn:X,onZoomOut:G,onZoomReset:U,viewMode:S,onViewModeChange:M,stylePresetId:p.stylePresetId,onStylePresetChange:T}),p.animationModes.length>0&&n.jsxs("div",{className:"nice-diagram-editor__mode-tabs",style:{display:"flex",gap:4,padding:"4px 8px",fontSize:12,alignItems:"center"},children:[n.jsx("span",{style:{color:"var(--nice-text-secondary, #888)",marginRight:4},children:"Modes:"}),p.animationModes.map(V=>{var Y;return n.jsx(v.NiceButton,{variant:((Y=p.activeAnimationMode)==null?void 0:Y.id)===V.id?"primary":"ghost",size:"sm",onClick:()=>p.setActiveAnimationMode(V.id),style:{padding:"2px 10px",fontSize:11},children:V.name},V.id)}),n.jsx(v.NiceButton,{variant:"ghost",size:"sm",onClick:()=>p.addAnimationMode(`Mode ${p.animationModes.length+1}`),style:{padding:"2px 8px",fontSize:11,color:"var(--nice-text-secondary, #888)"},title:"Add animation mode",children:"+"})]})]}):void 0;return n.jsx(pt,{locale:a,children:n.jsxs(v.NiceAppShell,{ref:y,flush:!0,className:`nice-diagram-editor ${u??""}`,style:{position:"relative",...d},toolbar:ne,rightSidebar:c?n.jsx("div",{className:"nice-diagram-editor__panel",style:{width:260,overflowY:"auto",height:"100%"},children:n.jsx(et,{selectedNode:F,selectedEdge:W,onNodeChange:p.updateNode,onEdgeChange:p.updateEdge,onRemove:R})}):void 0,bottomPanel:l?n.jsx("div",{className:"nice-diagram-editor__timeline",children:n.jsx(Ke,{animations:p.animations,onAdd:p.addAnimation,onRemove:p.removeAnimation,availableTargets:J})}):void 0,children:[n.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:n.jsx(v.NiceTutorialButton,{steps:v.resolveTutorial(m,Oi)})}),n.jsxs("div",{className:"nice-diagram-editor__canvas",style:{height:"100%",position:"relative"},children:[n.jsx(ve,{nodes:p.nodes,edges:p.edges,groups:p.groups,viewport:p.viewport,onViewportChange:p.setViewport,selectedId:x,onSelectElement:w,onNodeDrag:P,onNodeDragEnd:q,interactive:S==="editor",showGrid:S==="editor",particleState:N,viewMode:S,ghostOpacity:((de=p.playerConfig)==null?void 0:de.ghostOpacity)??.3,onGroupCollapse:p.toggleGroupCollapse,onNodeCollapse:p.toggleNodeCollapse,onInteraction:L}),s&&n.jsx("div",{style:{position:"absolute",bottom:8,left:8},children:n.jsx(Qe,{nodes:p.nodes,edges:p.edges,viewport:p.viewport,onViewportChange:p.setViewport})})]})]})})};Wt.displayName="NiceDiagramEditor";const Ct={linear:r=>r,easeIn:r=>r*r,easeOut:r=>r*(2-r),easeInOut:r=>r<.5?2*r*r:-1+(4-2*r)*r,spring:r=>1-Math.cos(r*Math.PI*.5)*Math.exp(-6*r),bounce:r=>{if(r<1/2.75)return 7.5625*r*r;if(r<2/2.75){const t=r-.5454545454545454;return 7.5625*t*t+.75}if(r<2.5/2.75){const t=r-.8181818181818182;return 7.5625*t*t+.9375}const e=r-2.625/2.75;return 7.5625*e*e+.984375}};function Bt(r){return Ct[r]??Ct.linear}const qt={opacity:1,scale:1,translateX:0,translateY:0,glow:0,highlightColor:"",strokeProgress:1,rippleRadius:0,rippleOpacity:0,typewriterChars:-1,liquidFillProgress:-1,particleTrailT:-1};class Gt{constructor(e,t){this.startTime=0,this.playing=!1,this.rafId=0,this.stateMap=new Map,this.tick=()=>{if(!this.playing)return;const i=performance.now()-this.startTime;this.stateMap.clear();let a=!1;for(const o of this.animations){const c=o.startMs+(o.delayMs??0);c+o.durationMs;const s=o.repeat??0;let l=i-c;if(l<0){this.stateMap.set(o.targetId,Li(o)),a=!0;continue}if(s===-1)l=l%o.durationMs,a=!0;else if(s>0){const p=o.durationMs*(s+1);if(l>p)continue;l=l%o.durationMs,a=!0}else{if(l>o.durationMs)continue;a=!0}const u=Math.min(l/o.durationMs,1),d=Bt(o.easing)(u),m=Ei(o,d);this.stateMap.set(o.targetId,m)}this.onFrame(this.stateMap),a?this.rafId=requestAnimationFrame(this.tick):this.playing=!1},this.animations=[...e].sort((i,a)=>i.startMs-a.startMs),this.onFrame=t}play(){this.playing||(this.playing=!0,this.startTime=performance.now(),this.tick())}stop(){this.playing=!1,this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=0,this.stateMap.clear(),this.onFrame(this.stateMap)}pause(){this.playing=!1,this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=0}isPlaying(){return this.playing}}function Ei(r,e){const t={...qt};switch(r.effect){case"fadeIn":t.opacity=e;break;case"fadeOut":t.opacity=1-e;break;case"slideInLeft":t.translateX=-200*(1-e),t.opacity=e;break;case"slideInRight":t.translateX=200*(1-e),t.opacity=e;break;case"slideInTop":t.translateY=-200*(1-e),t.opacity=e;break;case"slideInBottom":t.translateY=200*(1-e),t.opacity=e;break;case"zoomIn":t.scale=e,t.opacity=e;break;case"zoomOut":t.scale=1-e*.5,t.opacity=1-e;break;case"pulse":t.scale=1+.15*Math.sin(e*Math.PI*2);break;case"shake":t.translateX=10*Math.sin(e*Math.PI*6)*(1-e);break;case"highlight":t.highlightColor=`rgba(255, 200, 0, ${.6*(1-Math.abs(2*e-1))})`;break;case"flowPulse":t.opacity=1,t.translateX=e;break;case"bounce":t.translateY=-40*Math.abs(Math.sin(e*Math.PI*3))*(1-e);break;case"glow":t.glow=12*Math.sin(e*Math.PI);break;case"colorShift":t.highlightColor=`hsl(${e*360}, 70%, 60%)`;break;case"liquidFill":t.liquidFillProgress=e;break;case"expand":t.scale=e,t.opacity=e;break;case"collapse":t.scale=1-e,t.opacity=1-e;break;case"ripple":t.rippleRadius=e*40,t.rippleOpacity=1-e;break;case"typewriter":t.typewriterChars=Math.floor(e*100);break;case"morphShape":t.scale=1+.1*Math.sin(e*Math.PI*4)*(1-e),t.translateX=2*Math.sin(e*Math.PI*3)*(1-e);break;case"drawPath":t.strokeProgress=e;break;case"particleTrail":t.particleTrailT=e;break}return t}function Li(r){const e={...qt};switch(r.effect){case"fadeIn":case"slideInLeft":case"slideInRight":case"slideInTop":case"slideInBottom":case"zoomIn":case"expand":e.opacity=0;break;case"drawPath":e.strokeProgress=0;break;case"typewriter":e.typewriterChars=0;break;case"liquidFill":e.liquidFillProgress=0;break}return e}const yt=({document:r,lang:e="en",autoPlay:t=!1,showControls:i,showGrid:a,showWorkspace:o=!1,className:c,style:s})=>{const l=i??o,u=a??o,[d,m]=b.useState({...r.viewport}),[p,g]=b.useState(new Map),[h,x]=b.useState(!1),w=b.useRef(null),y=b.useCallback(()=>{w.current&&w.current.stop();const k=new Gt(r.animations,T=>{g(new Map(T)),k.isPlaying()||x(!1)});w.current=k,k.play(),x(!0)},[r.animations]),S=b.useCallback(()=>{var k;(k=w.current)==null||k.stop(),x(!1),g(new Map)},[]);b.useEffect(()=>(t&&r.animations.length>0&&y(),()=>{var k;(k=w.current)==null||k.stop()}),[t]);const M=b.useCallback(()=>m(k=>({...k,zoom:Math.min(5,k.zoom*1.2)})),[]),I=b.useCallback(()=>m(k=>({...k,zoom:Math.max(.1,k.zoom/1.2)})),[]),N=b.useCallback(()=>m({x:0,y:0,zoom:1}),[]);return n.jsx(pt,{locale:e,children:n.jsxs("div",{className:`nice-diagram-viewer ${c??""}`,style:{display:"flex",flexDirection:"column",height:"100%",...s},children:[l&&n.jsx(Fi,{isPlaying:h,hasAnimations:r.animations.length>0,onPlay:y,onStop:S,onZoomIn:M,onZoomOut:I,onZoomReset:N}),n.jsx("div",{style:{flex:1,position:"relative"},children:n.jsx(ve,{nodes:r.nodes,edges:r.edges,groups:r.groups,viewport:d,onViewportChange:m,theme:r.theme,animationStates:p,interactive:!1,showGrid:u})})]})})},Fi=({isPlaying:r,hasAnimations:e,onPlay:t,onStop:i,onZoomIn:a,onZoomOut:o,onZoomReset:c})=>{const{t:s}=Ee();return n.jsxs("div",{className:"nice-diagram-viewer__controls",style:{display:"flex",gap:4,padding:"4px 8px",borderBottom:"1px solid var(--nice-border, #ddd)",background:"var(--nice-bg-secondary, #fafafa)"},children:[e&&(r?n.jsxs(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:i,children:[n.jsx(v.NiceIcon,{name:"stop",size:14})," ",s("animation.stop")]}):n.jsxs(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:t,children:[n.jsx(v.NiceIcon,{name:"play",size:14})," ",s("animation.play")]})),n.jsx("span",{style:{flex:1}}),n.jsx(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:a,"aria-label":"Zoom in",children:n.jsx(v.NiceIcon,{name:"plus",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:o,"aria-label":"Zoom out",children:n.jsx(v.NiceIcon,{name:"minus",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:c,children:"1:1"})]})};yt.displayName="NiceDiagramViewer";const Wi="_cell_16e1i_9",Bi="_expandable_16e1i_29",qi="_svg_16e1i_57",Gi="_emptyText_16e1i_67",Vi="_badge_16e1i_79",Yi="_expandIcon_16e1i_117",Xi="_modalOverlay_16e1i_169",Ui="_modalContent_16e1i_217",Hi="_modalHeader_16e1i_267",Ji="_modalTitle_16e1i_285",Zi="_modalClose_16e1i_299",Ki="_modalBody_16e1i_337",Qi="_modalSvg_16e1i_357",ea="_modalFooter_16e1i_371",ta="_modalInfo_16e1i_389",xe={cell:Wi,expandable:Bi,svg:qi,emptyText:Gi,badge:Vi,expandIcon:Yi,modalOverlay:Xi,modalContent:Ui,modalHeader:Hi,modalTitle:Ji,modalClose:Zi,modalBody:Ki,modalSvg:Qi,modalFooter:ea,modalInfo:ta},ra=120,ia=48,aa=4,Mt={default:"var(--nice-primary, #3b82f6)",process:"var(--nice-success, #22c55e)",decision:"var(--nice-warning, #f59e0b)",start:"var(--nice-info, #6366f1)",end:"var(--nice-danger, #ef4444)",data:"var(--nice-accent, #8b5cf6)",custom:"var(--nice-text-secondary, #64748b)"};function bt(r){if(r.length===0)return{minX:0,minY:0,maxX:100,maxY:100,width:100,height:100};let e=1/0,t=1/0,i=-1/0,a=-1/0;for(const o of r){const c=o.position.x,s=o.position.y,l=o.position.x+o.size.width,u=o.position.y+o.size.height;c<e&&(e=c),s<t&&(t=s),l>i&&(i=l),u>a&&(a=u)}return{minX:e,minY:t,maxX:i,maxY:a,width:i-e,height:a-t}}function Vt(r){var t;if((t=r.style)!=null&&t.backgroundColor)return r.style.backgroundColor;const e=r.shape??"default";return Mt[e]??Mt.default}function Yt(r,e){const t=e.get(r.sourceNodeId),i=e.get(r.targetNodeId);if(!t||!i)return null;const a=t.position.x+t.size.width/2,o=t.position.y+t.size.height/2,c=i.position.x+i.size.width/2,s=i.position.y+i.size.height/2;return`M ${a} ${o} L ${c} ${s}`}function oa(r,e){const t=bt(r);return{version:"1.0",id:`mini-diagram-${Date.now()}`,title:"Mini Diagram",diagramType:"flowchart",nodes:r,edges:e,groups:[],viewport:{x:t.minX-20,y:t.minY-20,zoom:1},animations:[],metadata:{createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}}}const sa=({document:r,onClose:e})=>{const t=bt(r.nodes),i=40,a=t.width+i*2,o=t.height+i*2,c=b.useMemo(()=>new Map(r.nodes.map(s=>[s.id,s])),[r.nodes]);return n.jsx("div",{className:xe.modalOverlay,onClick:e,children:n.jsxs("div",{className:xe.modalContent,onClick:s=>s.stopPropagation(),children:[n.jsxs("div",{className:xe.modalHeader,children:[n.jsx("h3",{className:xe.modalTitle,children:r.title||"Diagram"}),n.jsx("button",{className:xe.modalClose,onClick:e,children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",children:n.jsx("path",{d:"M15 5L5 15M5 5L15 15",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),n.jsx("div",{className:xe.modalBody,children:n.jsxs("svg",{viewBox:`${t.minX-i} ${t.minY-i} ${a} ${o}`,className:xe.modalSvg,children:[r.edges.map(s=>{var u,d,m;const l=Yt(s,c);return l?n.jsx("path",{d:l,stroke:((u=s.style)==null?void 0:u.strokeColor)??"var(--nice-text-secondary, #64748b)",strokeWidth:((d=s.style)==null?void 0:d.strokeWidth)??1.5,fill:"none",markerEnd:(m=s.style)!=null&&m.targetArrow&&s.style.targetArrow!=="none"?"url(#arrowhead-modal)":void 0},s.id):null}),r.nodes.map(s=>{var l,u;return n.jsxs("g",{children:[n.jsx("rect",{x:s.position.x,y:s.position.y,width:s.size.width,height:s.size.height,rx:((l=s.style)==null?void 0:l.borderRadius)??4,fill:Vt(s),stroke:((u=s.style)==null?void 0:u.borderColor)??"var(--nice-text, #1e293b)",strokeWidth:1}),n.jsx("text",{x:s.position.x+s.size.width/2,y:s.position.y+s.size.height/2,textAnchor:"middle",dominantBaseline:"middle",fill:"var(--nice-text-on-primary, #fff)",fontSize:12,fontFamily:"system-ui, sans-serif",children:s.label.substring(0,30)})]},s.id)}),n.jsx("defs",{children:n.jsx("marker",{id:"arrowhead-modal",markerWidth:"10",markerHeight:"7",refX:"9",refY:"3.5",orient:"auto",children:n.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"var(--nice-text-secondary, #64748b)"})})})]})}),n.jsx("div",{className:xe.modalFooter,children:n.jsxs("span",{className:xe.modalInfo,children:[r.nodes.length," nodes • ",r.edges.length," edges"]})})]})})},na=({document:r,nodes:e,edges:t,width:i=ra,height:a=ia,showCount:o=!0,expandable:c=!0,onExpand:s,padding:l=aa,backgroundColor:u="transparent",borderRadius:d=4,showLabels:m=!1,edgeColor:p="var(--nice-text-muted, #94a3b8)",tooltip:g})=>{const[h,x]=b.useState(!1),w=b.useMemo(()=>r||(e||t?oa(e??[],t??[]):null),[r,e,t]),y=b.useMemo(()=>w?new Map(w.nodes.map(T=>[T.id,T])):new Map,[w]),{bounds:S,scale:M,translateX:I,translateY:N}=b.useMemo(()=>{if(!w||w.nodes.length===0)return{bounds:{minX:0,minY:0,width:100,height:100},scale:1,translateX:0,translateY:0};const T=bt(w.nodes),L=i-l*2,O=a-l*2,F=L/T.width,W=O/T.height,C=Math.min(F,W,1),E=T.width*C,P=T.height*C,q=(i-E)/2-T.minX*C,R=(a-P)/2-T.minY*C;return{bounds:T,scale:C,translateX:q,translateY:R}},[w,i,a,l]),k=b.useCallback(()=>{!w||!c||(s?s(w):x(!0))},[w,c,s]);return!w||w.nodes.length===0?n.jsx("div",{className:xe.cell,style:{width:i,height:a,backgroundColor:u,borderRadius:d},title:g,children:n.jsx("span",{className:xe.emptyText,children:"—"})}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`${xe.cell} ${c?xe.expandable:""}`,style:{width:i,height:a,backgroundColor:u,borderRadius:d},onClick:k,title:g??`${w.nodes.length} nodes, ${w.edges.length} edges`,children:[n.jsx("svg",{width:i,height:a,viewBox:`0 0 ${i} ${a}`,className:xe.svg,children:n.jsxs("g",{transform:`translate(${I}, ${N}) scale(${M})`,children:[w.edges.map(T=>{const L=Yt(T,y);return L?n.jsx("path",{d:L,stroke:p,strokeWidth:1/M,fill:"none"},T.id):null}),w.nodes.map(T=>{const L=Vt(T);return n.jsxs("g",{children:[n.jsx("rect",{x:T.position.x,y:T.position.y,width:T.size.width,height:T.size.height,rx:Math.min(4,T.size.width/4),fill:L}),m&&M>.3&&n.jsx("text",{x:T.position.x+T.size.width/2,y:T.position.y+T.size.height/2,textAnchor:"middle",dominantBaseline:"middle",fill:"var(--nice-text-on-primary, #fff)",fontSize:10/M,fontFamily:"system-ui, sans-serif",children:T.label.substring(0,5)})]},T.id)})]})}),o&&n.jsx("span",{className:xe.badge,children:w.nodes.length}),c&&n.jsx("span",{className:xe.expandIcon,children:n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",children:n.jsx("path",{d:"M2 10V7M2 10h3M2 10l4-4M10 2v3M10 2H7M10 2L6 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})]}),h&&w&&n.jsx(sa,{document:w,onClose:()=>x(!1)})]})};function Xt(r,e,t="roundedRect"){const i=[],a=[],o=new Map;for(const c of r){const s=String(c[e.nodeMapping.idField]??"");if(!s)continue;const l=String(c[e.nodeMapping.labelField]??s),u=e.nodeMapping.descriptionField?String(c[e.nodeMapping.descriptionField]??""):void 0,d=e.nodeMapping.iconField?String(c[e.nodeMapping.iconField]??""):void 0,m=e.nodeMapping.colorField?String(c[e.nodeMapping.colorField]??""):void 0,p={id:`data_${s}`,label:l,description:u,icon:d,position:{x:0,y:0},size:{width:180,height:70},shape:t,style:m?{backgroundColor:m}:{},ports:[{id:"top",side:"top",offset:.5},{id:"right",side:"right",offset:.5},{id:"bottom",side:"bottom",offset:.5},{id:"left",side:"left",offset:.5}],data:c};i.push(p),o.set(s,p)}if(e.nodeMapping.parentField)for(const c of r){const s=String(c[e.nodeMapping.idField]??""),l=String(c[e.nodeMapping.parentField]??"");if(!s||!l)continue;const u=o.get(s),d=o.get(l);!u||!d||a.push({id:`edge_${l}_${s}`,sourceNodeId:d.id,sourcePortId:"bottom",targetNodeId:u.id,targetPortId:"top",style:{lineType:"orthogonal",targetArrow:"arrow"}})}if(e.edgeMapping)for(const c of r){const s=String(c[e.edgeMapping.sourceField]??""),l=String(c[e.edgeMapping.targetField]??"");if(!s||!l)continue;const u=o.get(s),d=o.get(l);if(!u||!d)continue;const m=e.edgeMapping.labelField?String(c[e.edgeMapping.labelField]??""):void 0;a.push({id:`edge_${s}_${l}`,sourceNodeId:u.id,sourcePortId:"right",targetNodeId:d.id,targetPortId:"left",label:m,style:{lineType:"bezier",targetArrow:"arrow"}})}return{nodes:i,edges:a}}async function ca(r,e,t){const i=await fetch(r.sourceUrl,{signal:t});if(!i.ok)throw new Error(`Failed to fetch data: ${i.status} ${i.statusText}`);const a=await i.json(),o=Array.isArray(a)?a:a.value??[];return Xt(o,r,e)}function la(r){return{rectangle:"rectangle",roundedRect:"roundedRect",ellipse:"ellipse",circle:"circle",diamond:"diamond",hexagon:"hexagon",cylinder:"cylinder",cloud:"cloud",triangle:"triangle"}[r||"rectangle"]||"rectangle"}function da(r){return r?{backgroundColor:r.fill,borderColor:r.stroke,borderWidth:r.strokeWidth,fontColor:r.fontColor,fontSize:r.fontSize,borderRadius:r.borderRadius,borderStyle:r.strokeDasharray?"dashed":"solid"}:{}}function ua(r){if(!r)return{};let e="straight";return r.lineType==="orthogonal"?e="orthogonal":r.lineType==="curved"||r.lineType==="bezier"?e="bezier":r.lineType==="step"&&(e="step"),{strokeColor:r.stroke,strokeWidth:r.strokeWidth,strokeDash:r.strokeDasharray?r.strokeDasharray.split(",").map(Number):void 0,lineType:e,sourceArrow:"none",targetArrow:r.arrowHead?"arrow":"none",opacity:r.opacity}}function fa(r){if(r)return{backgroundColor:r.fill,borderColor:r.stroke,borderWidth:r.strokeWidth}}function Ut(r){return{id:r.id,label:r.label,position:{x:r.x,y:r.y},size:{width:r.width,height:r.height},shape:la(r.shape),style:da(r.style),ports:(r.ports||[]).map((e,t)=>({id:e.id,side:e.position||"right",offset:.5})),data:r.data}}function Ht(r,e){var c,s;const t=e.find(l=>l.id===r.source),i=e.find(l=>l.id===r.target),a=r.sourcePort||((c=t==null?void 0:t.ports[0])==null?void 0:c.id)||`${r.source}-out`,o=r.targetPort||((s=i==null?void 0:i.ports[0])==null?void 0:s.id)||`${r.target}-in`;return{id:r.id,sourceNodeId:r.source,sourcePortId:a,targetNodeId:r.target,targetPortId:o,label:r.label,style:ua(r.style),data:r.data}}function Jt(r){return{id:r.id,label:r.label,nodeIds:r.nodeIds,style:fa(r.style)}}function Zt(r){var e;return{id:r.id,name:r.id,targetId:r.targetId||((e=r.targets)==null?void 0:e[0])||"",targetType:"node",effect:r.type==="highlight"?"highlight":"fadeIn",startMs:r.delay,durationMs:r.duration,easing:"easeInOut"}}function Ae(r){const e=r.nodes.map(Ut);return e.forEach((t,i)=>{t.ports.length===0&&(t.ports=[{id:`${t.id}-out`,side:"right",offset:.5},{id:`${t.id}-in`,side:"left",offset:.5},{id:`${t.id}-top`,side:"top",offset:.5},{id:`${t.id}-bottom`,side:"bottom",offset:.5}])}),{version:"1.0",id:r.id,title:r.title,diagramType:r.diagramType,nodes:e,edges:r.edges.map(t=>Ht(t,e)),groups:(r.groups||[]).map(Jt),animations:(r.animations||[]).map(Zt),viewport:{x:0,y:0,zoom:1},metadata:{createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),...r.metadata}}}const ha={pending:"var(--nice-text-muted, #9ca3af)",active:"var(--nice-primary, #3b82f6)",completed:"var(--nice-success, #10b981)",failed:"var(--nice-danger, #ef4444)",skipped:"var(--nice-warning, #f59e0b)",waiting:"var(--nice-accent, #8b5cf6)"},pa={start:"ellipse",end:"ellipse",task:"rectangle",decision:"diamond",parallel:"rectangle",join:"rectangle",subprocess:"rectangle",timer:"ellipse",message:"rectangle",error:"rectangle"},ma={start:"play",end:"stop",task:"clipboard",decision:"help",parallel:"columns",join:"git-branch",subprocess:"box",timer:"clock",message:"mail",error:"warning"},ga=({data:r,onStepClick:e,onTransitionClick:t,autoPlay:i=!1,animationDelay:a=1e3,showTooltips:o=!0,showMinimap:c=!0,statusColors:s=ha,typeShapes:l=pa,direction:u="horizontal",className:d,style:m})=>{const[p,g]=b.useState(0),h=b.useMemo(()=>{const S=r.steps.map((N,k)=>{const T=N.id===r.currentStepId,L=N.status||"pending",O=s[L],F=l[N.type],W=u==="horizontal"?k*200:100,C=u==="horizontal"?100:k*150;return{id:N.id,label:N.name,x:W,y:C,width:150,height:60,shape:F,style:{fill:O,stroke:T?"var(--nice-text, #1f2937)":O,strokeWidth:T?3:1,fontColor:"var(--nice-text-on-primary, #fff)",fontSize:12},data:{type:N.type,status:N.status,assignee:N.assignee,dueDate:N.dueDate,icon:ma[N.type],...N.metadata},ports:[{id:`${N.id}-in`,position:"left"},{id:`${N.id}-out`,position:"right"}]}}),M=r.transitions.map(N=>{const k=r.steps.find(O=>O.id===N.from),T=r.steps.find(O=>O.id===N.to);let L="var(--nice-text-muted, #9ca3af)";return(k==null?void 0:k.status)==="completed"&&(T==null?void 0:T.status)!=="pending"?L="var(--nice-success, #10b981)":(k==null?void 0:k.status)==="failed"&&(L="var(--nice-danger, #ef4444)"),{id:N.id,source:N.from,target:N.to,sourcePort:`${N.from}-out`,targetPort:`${N.to}-in`,label:N.label||N.condition,style:{stroke:L,strokeWidth:2,arrowHead:"arrow",lineType:"bezier"},data:{condition:N.condition}}}),I=i?ya(r.steps):[];return Ae({id:r.id,title:r.name,diagramType:"flowchart",nodes:S,edges:M,animations:I,metadata:{type:"workflow",...r.metadata}})},[r,s,l,u,i]);b.useEffect(()=>{if(!i)return;const S=r.steps.filter(I=>I.status==="completed").length;if(p>=S)return;const M=setTimeout(()=>{g(I=>I+1)},a);return()=>clearTimeout(M)},[i,p,a,r.steps]),b.useCallback(S=>{if(!e)return;const M=r.steps.find(I=>I.id===S);M&&e(M)},[r.steps,e]);const[x,w]=b.useState({x:0,y:0,zoom:1}),y=b.useCallback(S=>{if(S&&e){const M=r.steps.find(I=>I.id===S);M&&e(M)}if(S&&t){const M=r.transitions.find(I=>I.id===S);M&&t(M)}},[r.steps,r.transitions,e,t]);return n.jsx("div",{className:`nice-workflow-visualizer ${d||""}`,style:{position:"relative",width:"100%",height:"100%",...m},children:n.jsx(ve,{nodes:h.nodes,edges:h.edges,groups:h.groups,viewport:x,onViewportChange:w,onSelectElement:y,showGrid:!0})})};function ya(r){return r.filter(t=>t.status==="completed").map((t,i)=>({id:`anim-${t.id}`,targetId:t.id,type:"highlight",delay:i*500,duration:300,easing:"ease-out"}))}function ba(r){var o,c;const t=new DOMParser().parseFromString(r,"text/xml"),i=[],a=[];return t.querySelectorAll("startEvent").forEach(s=>{i.push({id:s.getAttribute("id")||`start-${i.length}`,name:s.getAttribute("name")||"Start",type:"start"})}),t.querySelectorAll("task, userTask, serviceTask").forEach(s=>{i.push({id:s.getAttribute("id")||`task-${i.length}`,name:s.getAttribute("name")||"Task",type:"task"})}),t.querySelectorAll("exclusiveGateway, parallelGateway").forEach(s=>{const l=s.tagName==="parallelGateway";i.push({id:s.getAttribute("id")||`gateway-${i.length}`,name:s.getAttribute("name")||(l?"Parallel":"Decision"),type:l?"parallel":"decision"})}),t.querySelectorAll("endEvent").forEach(s=>{i.push({id:s.getAttribute("id")||`end-${i.length}`,name:s.getAttribute("name")||"End",type:"end"})}),t.querySelectorAll("sequenceFlow").forEach(s=>{a.push({id:s.getAttribute("id")||`flow-${a.length}`,from:s.getAttribute("sourceRef")||"",to:s.getAttribute("targetRef")||"",label:s.getAttribute("name")||void 0})}),{id:((o=t.querySelector("process"))==null?void 0:o.getAttribute("id"))||"workflow",name:((c=t.querySelector("process"))==null?void 0:c.getAttribute("name"))||"Workflow",steps:i,transitions:a}}function xa(r,e){const t=[],i=[];t.push({id:"start",name:"Start",type:"start",status:"completed"}),r.forEach((a,o)=>{t.push({id:`step-${o}`,name:a,type:"task",status:"pending"})}),t.push({id:"end",name:"End",type:"end",status:"pending"}),i.push({id:"start-to-first",from:"start",to:"step-0"});for(let a=0;a<r.length-1;a++)i.push({id:`step-${a}-to-${a+1}`,from:`step-${a}`,to:`step-${a+1}`});return i.push({id:"last-to-end",from:`step-${r.length-1}`,to:"end"}),{id:"linear-workflow",name:"Linear Workflow",steps:t,transitions:i}}const va={dbo:"var(--nice-primary, #3b82f6)",public:"var(--nice-success, #10b981)",auth:"var(--nice-accent, #8b5cf6)",billing:"var(--nice-warning, #f59e0b)",audit:"var(--nice-danger, #ef4444)"},wa={"one-to-one":{left:"1",right:"1"},"one-to-many":{left:"1",right:"*"},"many-to-one":{left:"*",right:"1"},"many-to-many":{left:"*",right:"*"}},ka=({schema:r,onTableClick:e,onColumnClick:t,onRelationClick:i,showColumnDetails:a=!0,showOnlyKeys:o=!1,highlightTables:c=[],showMinimap:s=!0,schemaColors:l=va,layout:u="auto",maxColumnsDisplay:d=15,className:m,style:p})=>{const[g,h]=b.useState(null),x=b.useMemo(()=>{const M=_a(r.tables,u),I=r.tables.map((k,T)=>{const L=M[k.name]||{x:T%4*300,y:Math.floor(T/4)*400},O=c.includes(k.name),F=g===k.name,W=l[k.schema||"dbo"]||"var(--nice-text-secondary, #6b7280)";let C=k.columns;o&&(C=C.filter(R=>R.primaryKey||R.foreignKey)),C.length>d&&(C=C.slice(0,d));const E=40,P=a?28:20,q=E+C.length*P+10;return{id:k.name,label:k.schema?`${k.schema}.${k.name}`:k.name,x:L.x,y:L.y,width:250,height:q,shape:"rectangle",style:{fill:O||F?W:"var(--nice-bg, #fff)",stroke:W,strokeWidth:F?3:O?2:1,fontColor:O||F?"var(--nice-text-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:14,borderRadius:8},data:{type:"table",schema:k.schema,columns:C.map(R=>({...R,icon:Na(R)})),totalColumns:k.columns.length,truncated:k.columns.length>d,comment:k.comment,...k.metadata},ports:[...k.columns.filter(R=>R.primaryKey).map(R=>({id:`${k.name}.${R.name}-pk`,position:"left"})),...k.columns.filter(R=>R.foreignKey).map(R=>({id:`${k.name}.${R.name}-fk`,position:"right"}))]}}),N=r.relations.map(k=>{const T=wa[k.type];return{id:k.id,source:k.fromTable,target:k.toTable,sourcePort:`${k.fromTable}.${k.fromColumn}-fk`,targetPort:`${k.toTable}.${k.toColumn}-pk`,label:k.name||`${T.left}─${T.right}`,style:{stroke:"var(--nice-text-secondary, #6b7280)",strokeWidth:1.5,arrowHead:Ca(k.type),arrowTail:Ma(k.type),lineType:"orthogonal",strokeDasharray:k.type==="many-to-many"?"5,5":void 0},data:{type:k.type,fromColumn:k.fromColumn,toColumn:k.toColumn}}});return Ae({id:`schema-${r.name}`,title:r.name,diagramType:"er",nodes:I,edges:N,metadata:{type:"er-diagram",...r.metadata}})},[r,a,o,c,g,l,u,d]);b.useCallback(M=>{if(h(I=>I===M?null:M),e){const I=r.tables.find(N=>N.name===M);I&&e(I)}},[r.tables,e]),b.useCallback(M=>{if(!i)return;const I=r.relations.find(N=>N.id===M);I&&i(I)},[r.relations,i]);const[w,y]=b.useState({x:0,y:0,zoom:1}),S=b.useCallback(M=>{if(M){if(h(I=>I===M?null:M),e){const I=r.tables.find(N=>N.name===M);I&&e(I)}if(i){const I=r.relations.find(N=>N.id===M);I&&i(I)}}},[r.tables,r.relations,e,i]);return n.jsx("div",{className:`nice-database-schema-viewer ${m||""}`,style:{position:"relative",width:"100%",height:"100%",...p},children:n.jsx(ve,{nodes:x.nodes,edges:x.edges,groups:x.groups,viewport:w,onViewportChange:y,onSelectElement:S,showGrid:!0})})};function _a(r,e){const t={};if(e==="grid"){const i=Math.ceil(Math.sqrt(r.length));r.forEach((a,o)=>{t[a.name]={x:o%i*320+50,y:Math.floor(o/i)*450+50}})}else if(e==="hierarchical"){const i={};r.forEach(o=>{const c=o.schema||"default";i[c]||(i[c]=[]),i[c].push(o)});let a=50;Object.entries(i).forEach(([o,c])=>{c.forEach((s,l)=>{t[s.name]={x:l*320+50,y:a}}),a+=500})}else r.forEach((i,a)=>{const o=a/r.length*2*Math.PI,c=300+r.length*20;t[i.name]={x:Math.cos(o)*c+500,y:Math.sin(o)*c+400}});return t}function Na(r){return r.primaryKey?"lock":r.foreignKey?"link":r.unique?"zap":"file"}function Ca(r){switch(r){case"one-to-one":case"many-to-one":return"none";case"one-to-many":case"many-to-many":return"crow"}}function Ma(r){switch(r){case"one-to-one":case"one-to-many":return"none";case"many-to-one":case"many-to-many":return"crow"}}function Sa(r){const e=[],t=[],i=/CREATE\s+TABLE\s+(?:`?(\w+)`?\.)?`?(\w+)`?\s*\(([\s\S]*?)\);/gi;let a;for(;(a=i.exec(r))!==null;){const o=a[1]||"dbo",c=a[2],s=a[3],l=[],u=/`?(\w+)`?\s+(\w+(?:\([^)]+\))?)\s*(NOT\s+NULL|NULL)?/gi;let d;for(;(d=u.exec(s))!==null;)l.push({name:d[1],type:d[2],nullable:!d[3]||d[3].toUpperCase()!=="NOT NULL"});const m=/PRIMARY\s+KEY\s*\(`?(\w+)`?\)/i.exec(s);if(m){const h=l.find(x=>x.name===m[1]);h&&(h.primaryKey=!0)}const p=/FOREIGN\s+KEY\s*\(`?(\w+)`?\)\s*REFERENCES\s+`?(\w+)`?\s*\(`?(\w+)`?\)/gi;let g;for(;(g=p.exec(s))!==null;){const h=g,x=l.find(w=>w.name===h[1]);x&&(x.foreignKey={table:h[2],column:h[3]},t.push({id:`fk-${c}-${h[1]}`,fromTable:c,fromColumn:h[1],toTable:h[2],toColumn:h[3],type:"many-to-one"}))}e.push({name:c,schema:o,columns:l})}return{name:"Parsed Schema",tables:e,relations:t}}function Ia(r,e="postgres"){const t=[];for(const i of r.tables){const a=i.schema?`${i.schema}.${i.name}`:i.name;t.push(`CREATE TABLE ${a} (`);const o=i.columns.map(s=>{let l=` ${s.name} ${s.type}`;return s.nullable||(l+=" NOT NULL"),s.primaryKey&&(l+=" PRIMARY KEY"),s.unique&&(l+=" UNIQUE"),s.defaultValue&&(l+=` DEFAULT ${s.defaultValue}`),l}),c=i.columns.filter(s=>s.foreignKey).map(s=>` FOREIGN KEY (${s.name}) REFERENCES ${s.foreignKey.table}(${s.foreignKey.column})`);t.push([...o,...c].join(`,
|
|
3
|
+
`)}function lt(r){return r.replace(/[^a-zA-Z0-9_]/g,"_")}function kt(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const _t={en:{"toolbar.select":"Select","toolbar.addNode":"Add Node","toolbar.addEdge":"Add Edge","toolbar.group":"Group","toolbar.ungroup":"Ungroup","toolbar.delete":"Delete","toolbar.undo":"Undo","toolbar.redo":"Redo","toolbar.zoomIn":"Zoom In","toolbar.zoomOut":"Zoom Out","toolbar.fitToScreen":"Fit to Screen","toolbar.export":"Export","toolbar.import":"Import","toolbar.autoLayout":"Auto Layout","toolbar.animations":"Animations","toolbar.dataBinding":"Data Binding","toolbar.pan":"Pan","toolbar.zoomReset":"Reset Zoom","toolbar.layout":"Layout","layout.dagre":"Hierarchical","layout.forceDirected":"Force-Directed","layout.grid":"Grid","layout.radial":"Radial","layout.tree":"Tree","panel.properties":"Properties","panel.style":"Style","panel.animations":"Animations","panel.data":"Data","panel.noSelection":"Select an element to edit its properties","panel.nodeProperties":"Node Properties","panel.edgeProperties":"Edge Properties","node.label":"Label","node.description":"Description","node.shape":"Shape","node.color":"Color","node.border":"Border","node.width":"Width","node.height":"Height","node.bgColor":"Background","node.borderColor":"Border Color","node.fontSize":"Font Size","node.fontColor":"Font Color","node.locked":"Locked","edge.label":"Label","edge.lineType":"Line Type","edge.arrow":"Arrow","edge.color":"Color","edge.width":"Thickness","edge.animated":"Animated","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Native)","viewer.fullscreen":"Fullscreen","viewer.playAnimations":"Play Animations","viewer.stopAnimations":"Stop","viewer.print":"Print","animation.timeline":"Timeline","animation.play":"Play","animation.stop":"Stop","animation.add":"Add","animation.noAnimations":"No animations yet",untitled:"Untitled Diagram"},pl:{"toolbar.select":"Zaznacz","toolbar.addNode":"Dodaj węzeł","toolbar.addEdge":"Dodaj połączenie","toolbar.group":"Grupuj","toolbar.ungroup":"Rozgrupuj","toolbar.delete":"Usuń","toolbar.undo":"Cofnij","toolbar.redo":"Ponów","toolbar.zoomIn":"Powiększ","toolbar.zoomOut":"Pomniejsz","toolbar.fitToScreen":"Dopasuj do ekranu","toolbar.export":"Eksportuj","toolbar.import":"Importuj","toolbar.autoLayout":"Auto układ","toolbar.animations":"Animacje","toolbar.dataBinding":"Dane","toolbar.pan":"Przesuń","toolbar.zoomReset":"Przywróć powiększenie","toolbar.layout":"Układ","layout.dagre":"Hierarchiczny","layout.forceDirected":"Siłowy","layout.grid":"Siatka","layout.radial":"Promieniowy","layout.tree":"Drzewo","panel.properties":"Właściwości","panel.style":"Styl","panel.animations":"Animacje","panel.data":"Dane","panel.noSelection":"Zaznacz element, aby edytować jego właściwości","panel.nodeProperties":"Właściwości węzła","panel.edgeProperties":"Właściwości połączenia","node.label":"Etykieta","node.description":"Opis","node.shape":"Kształt","node.color":"Kolor","node.border":"Obramowanie","node.width":"Szerokość","node.height":"Wysokość","node.bgColor":"Tło","node.borderColor":"Kolor obramowania","node.fontSize":"Rozmiar czcionki","node.fontColor":"Kolor czcionki","node.locked":"Zablokowany","edge.label":"Etykieta","edge.lineType":"Typ linii","edge.arrow":"Strzałka","edge.color":"Kolor","edge.width":"Grubość","edge.animated":"Animowane","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Natywny)","viewer.fullscreen":"Pełny ekran","viewer.playAnimations":"Odtwórz animacje","viewer.stopAnimations":"Zatrzymaj","viewer.print":"Drukuj","animation.timeline":"Oś czasu","animation.play":"Odtwórz","animation.stop":"Zatrzymaj","animation.add":"Dodaj","animation.noAnimations":"Brak animacji",untitled:"Diagram bez nazwy"},de:{"toolbar.select":"Auswählen","toolbar.addNode":"Knoten hinzufügen","toolbar.addEdge":"Kante hinzufügen","toolbar.group":"Gruppieren","toolbar.ungroup":"Gruppierung aufheben","toolbar.delete":"Löschen","toolbar.undo":"Rückgängig","toolbar.redo":"Wiederholen","toolbar.zoomIn":"Vergrößern","toolbar.zoomOut":"Verkleinern","toolbar.fitToScreen":"An Bildschirm anpassen","toolbar.export":"Exportieren","toolbar.import":"Importieren","toolbar.autoLayout":"Automatisches Layout","toolbar.animations":"Animationen","toolbar.dataBinding":"Datenbindung","toolbar.pan":"Verschieben","toolbar.zoomReset":"Zoom zurücksetzen","toolbar.layout":"Layout","layout.dagre":"Hierarchisch","layout.forceDirected":"Kräftebasiert","layout.grid":"Raster","layout.radial":"Radial","layout.tree":"Baum","panel.properties":"Eigenschaften","panel.style":"Stil","panel.animations":"Animationen","panel.data":"Daten","panel.noSelection":"Wählen Sie ein Element aus, um seine Eigenschaften zu bearbeiten","panel.nodeProperties":"Knoteneigenschaften","panel.edgeProperties":"Kanteneigenschaften","node.label":"Bezeichnung","node.description":"Beschreibung","node.shape":"Form","node.color":"Farbe","node.border":"Rahmen","node.width":"Breite","node.height":"Höhe","node.bgColor":"Hintergrund","node.borderColor":"Rahmenfarbe","node.fontSize":"Schriftgröße","node.fontColor":"Schriftfarbe","node.locked":"Gesperrt","edge.label":"Bezeichnung","edge.lineType":"Linientyp","edge.arrow":"Pfeil","edge.color":"Farbe","edge.width":"Stärke","edge.animated":"Animiert","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Nativ)","viewer.fullscreen":"Vollbild","viewer.playAnimations":"Animationen abspielen","viewer.stopAnimations":"Stopp","viewer.print":"Drucken","animation.timeline":"Zeitleiste","animation.play":"Abspielen","animation.stop":"Stopp","animation.add":"Hinzufügen","animation.noAnimations":"Noch keine Animationen",untitled:"Unbenanntes Diagramm"},fr:{"toolbar.select":"Sélectionner","toolbar.addNode":"Ajouter un nœud","toolbar.addEdge":"Ajouter une arête","toolbar.group":"Grouper","toolbar.ungroup":"Dégrouper","toolbar.delete":"Supprimer","toolbar.undo":"Annuler","toolbar.redo":"Rétablir","toolbar.zoomIn":"Agrandir","toolbar.zoomOut":"Réduire","toolbar.fitToScreen":"Ajuster à l'écran","toolbar.export":"Exporter","toolbar.import":"Importer","toolbar.autoLayout":"Mise en page auto","toolbar.animations":"Animations","toolbar.dataBinding":"Liaison de données","toolbar.pan":"Déplacer","toolbar.zoomReset":"Réinitialiser le zoom","toolbar.layout":"Disposition","layout.dagre":"Hiérarchique","layout.forceDirected":"Force dirigée","layout.grid":"Grille","layout.radial":"Radial","layout.tree":"Arbre","panel.properties":"Propriétés","panel.style":"Style","panel.animations":"Animations","panel.data":"Données","panel.noSelection":"Sélectionnez un élément pour modifier ses propriétés","panel.nodeProperties":"Propriétés du nœud","panel.edgeProperties":"Propriétés de l'arête","node.label":"Étiquette","node.description":"Description","node.shape":"Forme","node.color":"Couleur","node.border":"Bordure","node.width":"Largeur","node.height":"Hauteur","node.bgColor":"Arrière-plan","node.borderColor":"Couleur de bordure","node.fontSize":"Taille de police","node.fontColor":"Couleur de police","node.locked":"Verrouillé","edge.label":"Étiquette","edge.lineType":"Type de ligne","edge.arrow":"Flèche","edge.color":"Couleur","edge.width":"Épaisseur","edge.animated":"Animée","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Natif)","viewer.fullscreen":"Plein écran","viewer.playAnimations":"Lire les animations","viewer.stopAnimations":"Arrêter","viewer.print":"Imprimer","animation.timeline":"Chronologie","animation.play":"Lire","animation.stop":"Arrêter","animation.add":"Ajouter","animation.noAnimations":"Aucune animation",untitled:"Diagramme sans titre"},es:{"toolbar.select":"Seleccionar","toolbar.addNode":"Añadir nodo","toolbar.addEdge":"Añadir arista","toolbar.group":"Agrupar","toolbar.ungroup":"Desagrupar","toolbar.delete":"Eliminar","toolbar.undo":"Deshacer","toolbar.redo":"Rehacer","toolbar.zoomIn":"Ampliar","toolbar.zoomOut":"Reducir","toolbar.fitToScreen":"Ajustar a pantalla","toolbar.export":"Exportar","toolbar.import":"Importar","toolbar.autoLayout":"Diseño automático","toolbar.animations":"Animaciones","toolbar.dataBinding":"Enlace de datos","toolbar.pan":"Desplazar","toolbar.zoomReset":"Restablecer zoom","toolbar.layout":"Diseño","layout.dagre":"Jerárquico","layout.forceDirected":"Fuerza dirigida","layout.grid":"Cuadrícula","layout.radial":"Radial","layout.tree":"Árbol","panel.properties":"Propiedades","panel.style":"Estilo","panel.animations":"Animaciones","panel.data":"Datos","panel.noSelection":"Selecciona un elemento para editar sus propiedades","panel.nodeProperties":"Propiedades del nodo","panel.edgeProperties":"Propiedades de la arista","node.label":"Etiqueta","node.description":"Descripción","node.shape":"Forma","node.color":"Color","node.border":"Borde","node.width":"Ancho","node.height":"Alto","node.bgColor":"Fondo","node.borderColor":"Color del borde","node.fontSize":"Tamaño de fuente","node.fontColor":"Color de fuente","node.locked":"Bloqueado","edge.label":"Etiqueta","edge.lineType":"Tipo de línea","edge.arrow":"Flecha","edge.color":"Color","edge.width":"Grosor","edge.animated":"Animada","export.svg":"SVG","export.png":"PNG","export.pdf":"PDF","export.mermaid":"Mermaid","export.ndd":"NDD (Nativo)","viewer.fullscreen":"Pantalla completa","viewer.playAnimations":"Reproducir animaciones","viewer.stopAnimations":"Detener","viewer.print":"Imprimir","animation.timeline":"Línea de tiempo","animation.play":"Reproducir","animation.stop":"Detener","animation.add":"Añadir","animation.noAnimations":"Sin animaciones",untitled:"Diagrama sin título"}},Pt=b.createContext({locale:"en",t:(r,e)=>e??r});function pt({locale:r="en",overrides:e,children:t}){const i=b.useMemo(()=>{const a={..._t.en,..._t[r],...e};return{locale:r,t:(c,s)=>a[c]??s??c}},[r,e]);return b.createElement(Pt.Provider,{value:i},t)}function Ee(){return b.useContext(Pt)}function pr(r){const e=[];let t;try{t=JSON.parse(r)}catch{return{ok:!1,errors:["Invalid JSON: parse failed"]}}if(typeof t!="object"||t===null||Array.isArray(t))return{ok:!1,errors:["Root must be a JSON object"]};const i=t;if(i.version!=="1.0"&&e.push(`Unsupported version "${String(i.version)}", expected "1.0"`),(typeof i.id!="string"||i.id.length===0)&&e.push('Missing or invalid "id" field'),typeof i.title!="string"&&e.push('Missing or invalid "title" field'),Array.isArray(i.nodes)||e.push('Missing or invalid "nodes" array'),Array.isArray(i.edges)||e.push('Missing or invalid "edges" array'),Array.isArray(i.nodes)&&Array.isArray(i.edges)){const a=new Set(i.nodes.map(o=>o.id).filter(Boolean));for(const o of i.edges)o.sourceNodeId&&!a.has(o.sourceNodeId)&&e.push(`Edge "${o.id}" references non-existent source node "${o.sourceNodeId}"`),o.targetNodeId&&!a.has(o.targetNodeId)&&e.push(`Edge "${o.id}" references non-existent target node "${o.targetNodeId}"`)}return e.length>0?{ok:!1,errors:e}:{ok:!0,document:t,errors:[]}}function Rt(r,e=!0){return JSON.stringify(r,null,e?2:void 0)}class Je{constructor(e){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.maxHistory=100,this.doc=e??Je.createEmpty()}static createEmpty(e="flowchart"){const t=new Date().toISOString();return{version:"1.0",id:De(),title:"Untitled Diagram",diagramType:e,nodes:[],edges:[],groups:[],animations:[],viewport:{x:0,y:0,zoom:1},metadata:{createdAt:t,updatedAt:t}}}getDocument(){return this.doc}getNodes(){return this.doc.nodes}getEdges(){return this.doc.edges}getGroups(){return this.doc.groups}getAnimations(){return this.doc.animations}getNodeById(e){return this.doc.nodes.find(t=>t.id===e)}getEdgeById(e){return this.doc.edges.find(t=>t.id===e)}getViewport(){return{...this.doc.viewport}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){this.doc.metadata.updatedAt=new Date().toISOString(),this.listeners.forEach(e=>e())}pushUndo(e){this.undoStack.push({label:e,snapshot:JSON.stringify(this.doc)}),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack=[]}undo(){const e=this.undoStack.pop();return e?(this.redoStack.push({label:"redo",snapshot:JSON.stringify(this.doc)}),this.doc=JSON.parse(e.snapshot),this.notify(),!0):!1}redo(){const e=this.redoStack.pop();return e?(this.undoStack.push({label:"undo",snapshot:JSON.stringify(this.doc)}),this.doc=JSON.parse(e.snapshot),this.notify(),!0):!1}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}addNode(e,t,i="roundedRect",a={width:160,height:60}){this.pushUndo("Add node");const o=mr(),c={id:De(),label:e,position:t,size:a,shape:i,style:{},ports:o};return this.doc.nodes.push(c),this.notify(),c}updateNode(e,t){this.pushUndo("Update node");const i=this.doc.nodes.find(a=>a.id===e);i&&Object.assign(i,t),this.notify()}moveNode(e,t){const i=this.doc.nodes.find(a=>a.id===e);i&&(this.pushUndo("Move node"),i.position=t,this.notify())}resizeNode(e,t){const i=this.doc.nodes.find(a=>a.id===e);i&&(this.pushUndo("Resize node"),i.size=t,this.notify())}removeNode(e){this.pushUndo("Remove node"),this.doc.nodes=this.doc.nodes.filter(t=>t.id!==e),this.doc.edges=this.doc.edges.filter(t=>t.sourceNodeId!==e&&t.targetNodeId!==e),this.doc.groups.forEach(t=>{t.nodeIds=t.nodeIds.filter(i=>i!==e)}),this.doc.animations=this.doc.animations.filter(t=>t.targetId!==e),this.notify()}addEdge(e,t,i,a,o){if(e===i||!this.getNodeById(e)||!this.getNodeById(i))return null;this.pushUndo("Add edge");const c={id:De(),sourceNodeId:e,sourcePortId:t,targetNodeId:i,targetPortId:a,label:o,style:{lineType:"bezier",targetArrow:"arrow"}};return this.doc.edges.push(c),this.notify(),c}updateEdge(e,t){this.pushUndo("Update edge");const i=this.doc.edges.find(a=>a.id===e);i&&Object.assign(i,t),this.notify()}removeEdge(e){this.pushUndo("Remove edge"),this.doc.edges=this.doc.edges.filter(t=>t.id!==e),this.doc.animations=this.doc.animations.filter(t=>t.targetId!==e),this.notify()}createGroup(e,t){this.pushUndo("Create group");const i={id:De(),label:e,nodeIds:[...t]};return t.forEach(a=>{const o=this.doc.nodes.find(c=>c.id===a);o&&(o.groupId=i.id)}),this.doc.groups.push(i),this.notify(),i}removeGroup(e){this.pushUndo("Remove group");const t=this.doc.groups.find(i=>i.id===e);t&&t.nodeIds.forEach(i=>{const a=this.doc.nodes.find(o=>o.id===i);a&&(a.groupId=void 0)}),this.doc.groups=this.doc.groups.filter(i=>i.id!==e),this.notify()}addAnimation(e){this.pushUndo("Add animation");const t={id:De(),...e};return this.doc.animations.push(t),this.notify(),t}removeAnimation(e){this.pushUndo("Remove animation"),this.doc.animations=this.doc.animations.filter(t=>t.id!==e),this.notify()}setViewport(e){this.doc.viewport={...e},this.notify()}toggleGroupCollapse(e){const t=this.doc.groups.find(i=>i.id===e);t&&(this.pushUndo("Toggle group collapse"),t.collapsed=!t.collapsed,t.nodeIds.forEach(i=>{const a=this.doc.nodes.find(o=>o.id===i);a&&(a.hidden=t.collapsed)}),this.notify())}toggleNodeCollapse(e){const t=this.doc.nodes.find(i=>i.id===e);t&&(this.pushUndo("Toggle node collapse"),t.collapsed=!t.collapsed,(t.childNodeIds??[]).forEach(i=>{const a=this.doc.nodes.find(o=>o.id===i);a&&(a.hidden=t.collapsed)}),this.notify())}getAnimationModes(){return this.doc.animationModes??[]}getActiveAnimationMode(){var e;if((e=this.doc.animationModes)!=null&&e.length)return this.doc.animationModes.find(t=>t.id===this.doc.activeAnimationModeId)??this.doc.animationModes.find(t=>t.isDefault)??this.doc.animationModes[0]}addAnimationMode(e,t){this.pushUndo("Add animation mode"),this.doc.animationModes||(this.doc.animationModes=[]);const i={id:De(),name:e,animations:t??[],isDefault:this.doc.animationModes.length===0};return this.doc.animationModes.push(i),i.isDefault&&(this.doc.activeAnimationModeId=i.id),this.notify(),i}removeAnimationMode(e){var t;this.doc.animationModes&&(this.pushUndo("Remove animation mode"),this.doc.animationModes=this.doc.animationModes.filter(i=>i.id!==e),this.doc.activeAnimationModeId===e&&(this.doc.activeAnimationModeId=(t=this.doc.animationModes[0])==null?void 0:t.id),this.notify())}setActiveAnimationMode(e){var t;(t=this.doc.animationModes)!=null&&t.find(i=>i.id===e)&&(this.doc.activeAnimationModeId=e,this.notify())}addAnimationToMode(e,t){var o;const i=(o=this.doc.animationModes)==null?void 0:o.find(c=>c.id===e);if(!i)return null;this.pushUndo("Add animation to mode");const a={id:De(),...t};return i.animations.push(a),this.notify(),a}removeAnimationFromMode(e,t){var a;const i=(a=this.doc.animationModes)==null?void 0:a.find(o=>o.id===e);i&&(this.pushUndo("Remove animation from mode"),i.animations=i.animations.filter(o=>o.id!==t),this.notify())}setStylePreset(e){this.pushUndo("Set style preset"),this.doc.stylePresetId=e,this.notify()}setStyleOverrides(e){this.pushUndo("Set style overrides"),this.doc.styleOverrides=e,this.notify()}getPlayerConfig(){return this.doc.playerConfig??{mode:"editor",interactionsEnabled:!0,showModeSwitcher:!0,showPlaybackControls:!0,autoPlay:!1,showGhostElements:!0,ghostOpacity:.15,ghostCursorStyle:"pointer"}}setPlayerConfig(e){this.pushUndo("Update player config"),this.doc.playerConfig={...this.getPlayerConfig(),...e},this.notify()}setViewMode(e){const t=this.getPlayerConfig();t.mode=e,this.doc.playerConfig=t,this.notify()}updateAnimation(e,t){this.pushUndo("Update animation");const i=this.doc.animations.find(a=>a.id===e);i&&Object.assign(i,t),this.notify()}loadDocument(e){this.doc=structuredClone(e),this.undoStack=[],this.redoStack=[],this.notify()}}function De(){return`ndd_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function mr(){return[{id:"top",side:"top",offset:.5},{id:"right",side:"right",offset:.5},{id:"bottom",side:"bottom",offset:.5},{id:"left",side:"left",offset:.5}]}function Ot(r,e,t){switch(t.algorithm){case"dagre":return Et(r,e,t);case"grid":return gr(r,t);case"radial":return yr(r,e);case"tree":return br(r,e,t);case"forceDirected":return xr(r,e,t);case"manual":default:return{positions:new Map(r.map(i=>[i.id,{...i.position}]))}}}function Et(r,e,t){const i=t.direction??"TB",a=t.nodeSpacing??60,o=t.rankSpacing??100,c=new Map,s=new Map,l=new Set(r.map(y=>y.id));r.forEach(y=>{c.set(y.id,[]),s.set(y.id,[])}),e.forEach(y=>{l.has(y.sourceNodeId)&&l.has(y.targetNodeId)&&(c.get(y.sourceNodeId).push(y.targetNodeId),s.get(y.targetNodeId).push(y.sourceNodeId))});const u=r.filter(y=>{var S;return(((S=s.get(y.id))==null?void 0:S.length)??0)===0});u.length===0&&r.length>0&&u.push(r[0]);const d=new Map,m=[];for(u.forEach(y=>{d.set(y.id,0),m.push(y.id)});m.length>0;){const y=m.shift(),S=d.get(y)??0;for(const M of c.get(y)??[])d.has(M)||(d.set(M,S+1),m.push(M))}r.forEach(y=>{d.has(y.id)||d.set(y.id,0)});const p=new Map;r.forEach(y=>{const S=d.get(y.id)??0;p.has(S)||p.set(S,[]),p.get(S).push(y)});const g=new Map,h=i==="LR"||i==="RL",x=i==="BT"||i==="RL";return[...p.keys()].sort((y,S)=>y-S).forEach((y,S)=>{const M=p.get(y);let N=-(M.reduce((k,T)=>k+T.size.width,0)+(M.length-1)*a)/2;M.forEach(k=>{const T=S*(o+(h?k.size.width:k.size.height)),L=N+k.size.width/2;let O,F;h?(O=x?-T:T,F=L):(O=L,F=x?-T:T),g.set(k.id,{x:O,y:F}),N+=k.size.width+a})}),t.centerGraph&&mt(g),{positions:g}}function gr(r,e){const t=e.nodeSpacing??80,i=Math.ceil(Math.sqrt(r.length)),a=new Map;return r.forEach((o,c)=>{const s=c%i,l=Math.floor(c/i);a.set(o.id,{x:s*(o.size.width+t),y:l*(o.size.height+t)})}),e.centerGraph&&mt(a),{positions:a}}function yr(r,e){const t=new Map;if(r.length===0)return{positions:t};const i=new Map;r.forEach(l=>i.set(l.id,0)),e.forEach(l=>{i.set(l.sourceNodeId,(i.get(l.sourceNodeId)??0)+1),i.set(l.targetNodeId,(i.get(l.targetNodeId)??0)+1)});const a=[...r].sort((l,u)=>(i.get(u.id)??0)-(i.get(l.id)??0)),o=a[0];t.set(o.id,{x:0,y:0});const c=a.slice(1),s=200+c.length*20;return c.forEach((l,u)=>{const d=2*Math.PI*u/c.length;t.set(l.id,{x:Math.cos(d)*s,y:Math.sin(d)*s})}),{positions:t}}function br(r,e,t){return Et(r,e,{...t,direction:t.direction??"TB",nodeSpacing:t.nodeSpacing??40,rankSpacing:t.rankSpacing??80})}function xr(r,e,t){const i=new Map;if(r.length===0)return{positions:i};const a=400,o=new Map;r.forEach(m=>{o.set(m.id,{x:(Math.random()-.5)*a,y:(Math.random()-.5)*a})});const c=e.map(m=>({source:m.sourceNodeId,target:m.targetNodeId})),s=t.nodeSpacing??150,l=80,u=.95;let d=a/2;for(let m=0;m<l;m++){const p=new Map;r.forEach(g=>p.set(g.id,{fx:0,fy:0}));for(let g=0;g<r.length;g++)for(let h=g+1;h<r.length;h++){const x=o.get(r[g].id),w=o.get(r[h].id),y=w.x-x.x,S=w.y-x.y,M=Math.max(Math.sqrt(y*y+S*S),1),I=s*s/M,N=y/M*I,k=S/M*I;p.get(r[g].id).fx-=N,p.get(r[g].id).fy-=k,p.get(r[h].id).fx+=N,p.get(r[h].id).fy+=k}for(const g of c){const h=o.get(g.source),x=o.get(g.target);if(!h||!x)continue;const w=x.x-h.x,y=x.y-h.y,S=Math.max(Math.sqrt(w*w+y*y),1),M=S*S/s,I=w/S*M,N=y/S*M;p.get(g.source).fx+=I,p.get(g.source).fy+=N,p.get(g.target).fx-=I,p.get(g.target).fy-=N}r.forEach(g=>{const h=p.get(g.id),x=o.get(g.id),w=Math.sqrt(h.fx*h.fx+h.fy*h.fy);if(w>0){const y=Math.min(w,d);x.x+=h.fx/w*y,x.y+=h.fy/w*y}}),d*=u}return r.forEach(m=>{i.set(m.id,{...o.get(m.id)})}),t.centerGraph&&mt(i),{positions:i}}function mt(r){if(r.size===0)return;let e=1/0,t=1/0,i=-1/0,a=-1/0;r.forEach(s=>{e=Math.min(e,s.x),t=Math.min(t,s.y),i=Math.max(i,s.x),a=Math.max(a,s.y)});const o=(e+i)/2,c=(t+a)/2;r.forEach(s=>{s.x-=o,s.y-=c})}function Lt(r){const e=b.useRef(null);e.current||(e.current=new Je(r));const t=e.current,[,i]=b.useState(0),a=b.useCallback(()=>i(s=>s+1),[]);b.useEffect(()=>t.subscribe(a),[t,a]);const o=t.getDocument(),c=b.useCallback(s=>{Ot(t.getNodes(),t.getEdges(),s).positions.forEach((u,d)=>{t.moveNode(d,u)})},[t]);return b.useMemo(()=>({document:o,nodes:o.nodes,edges:o.edges,groups:o.groups,animations:o.animations,viewport:o.viewport,addNode:(s,l,u,d)=>t.addNode(s,l,u,d),updateNode:(s,l)=>t.updateNode(s,l),moveNode:(s,l)=>t.moveNode(s,l),resizeNode:(s,l)=>t.resizeNode(s,l),removeNode:s=>t.removeNode(s),addEdge:(s,l,u,d,m)=>t.addEdge(s,l,u,d,m),updateEdge:(s,l)=>t.updateEdge(s,l),removeEdge:s=>t.removeEdge(s),createGroup:(s,l)=>t.createGroup(s,l),removeGroup:s=>t.removeGroup(s),toggleGroupCollapse:s=>t.toggleGroupCollapse(s),toggleNodeCollapse:s=>t.toggleNodeCollapse(s),addAnimation:s=>t.addAnimation(s),updateAnimation:(s,l)=>t.updateAnimation(s,l),removeAnimation:s=>t.removeAnimation(s),animationModes:t.getAnimationModes(),activeAnimationMode:t.getActiveAnimationMode(),addAnimationMode:(s,l)=>t.addAnimationMode(s,l),removeAnimationMode:s=>t.removeAnimationMode(s),setActiveAnimationMode:s=>t.setActiveAnimationMode(s),addAnimationToMode:(s,l)=>t.addAnimationToMode(s,l),removeAnimationFromMode:(s,l)=>t.removeAnimationFromMode(s,l),setStylePreset:s=>t.setStylePreset(s),setStyleOverrides:s=>t.setStyleOverrides(s),stylePresetId:o.stylePresetId,playerConfig:t.getPlayerConfig(),setPlayerConfig:s=>t.setPlayerConfig(s),setViewMode:s=>t.setViewMode(s),viewMode:t.getPlayerConfig().mode,applyLayout:c,setViewport:s=>t.setViewport(s),undo:()=>t.undo(),redo:()=>t.redo(),canUndo:t.canUndo(),canRedo:t.canRedo(),loadDocument:s=>t.loadDocument(s),model:t}),[o,t,c])}function ce(r){return{primary:"var(--nice-primary, #3b82f6)",primaryLight:"var(--nice-primary-light, #93c5fd)",secondary:"var(--nice-info, #6366f1)",accent:"var(--nice-warning, #f59e0b)",success:"var(--nice-success, #10b981)",warning:"var(--nice-warning, #f59e0b)",error:"var(--nice-danger, #ef4444)",info:"var(--nice-info, #06b6d4)",text:"var(--nice-text, #1e293b)",textMuted:"var(--nice-text-muted, #94a3b8)",border:"var(--nice-border, #e2e8f0)",surface:"var(--nice-bg, #fff)",surfaceAlt:"var(--nice-bg-secondary, #f8fafc)",...r}}function vr(r,e={}){return{backgroundColor:r.surface,borderColor:r.primary,borderWidth:2,borderRadius:8,fontColor:r.text,fontSize:14,fontWeight:"normal",opacity:1,shadow:!0,...e}}function wr(r,e={}){return{strokeColor:r.border,strokeWidth:2,lineType:"bezier",targetArrow:"arrow",...e}}function kr(r,e={}){return{backgroundColor:`${r.primaryLight}18`,borderColor:r.primaryLight,borderWidth:1,borderStyle:"dashed",borderRadius:12,labelColor:r.text,padding:16,...e}}function le(r,e,t,i,a,o,c){return{canvas:r,nodeDefaults:vr(e,i),edgeDefaults:wr(e,a),groupDefaults:kr(e,o),fontFamily:t,palette:e,effects:c}}const Ne="'Inter', system-ui, sans-serif",gt="'Fira Code', 'Cascadia Code', monospace",_r="'Merriweather', 'Georgia', serif",Nr={id:"default-light",name:"Default Light",category:"corporate",themeSource:"Light",config:le({background:"var(--nice-bg, #fff)",gridColor:"#e2e8f020",gridSize:20,selectionColor:"var(--nice-primary, #3b82f6)"},ce({}),Ne)},Cr=ce({primary:"var(--nice-primary-light, #60a5fa)",primaryLight:"var(--nice-primary, #3b82f6)",secondary:"var(--nice-accent, #818cf8)",accent:"var(--nice-warning-light, #fbbf24)",success:"var(--nice-success-light, #34d399)",warning:"var(--nice-warning-light, #fbbf24)",error:"var(--nice-danger-light, #f87171)",info:"var(--nice-info, #22d3ee)",text:"var(--nice-text-primary, #f8fafc)",textMuted:"var(--nice-text-secondary, #64748b)",border:"var(--nice-border-color, #334155)",surface:"var(--nice-bg-secondary, #1e293b)",surfaceAlt:"var(--nice-bg-primary, #0f172a)"}),Mr={id:"default-dark",name:"Default Dark",category:"dark",themeSource:"Dark",config:le({background:"var(--nice-bg-primary, #0f172a)",gridColor:"var(--nice-text, #334155)",gridSize:20,selectionColor:"var(--nice-primary-light, #60a5fa)"},Cr,Ne,{shadow:!1},{strokeColor:"var(--nice-text-secondary, #475569)"},{backgroundColor:"#60a5fa10",borderColor:"#3b82f680"})},Sr=ce({primary:"var(--nice-primary-dark, #1d4ed8)",primaryLight:"var(--nice-primary-light, #93c5fd)",secondary:"var(--nice-primary, #3b82f6)",text:"var(--nice-primary-dark, #1e3a5f)",textMuted:"#7da0c4",border:"var(--nice-primary-light, #93c5fd)",surface:"var(--nice-primary-bg, #eff6ff)",surfaceAlt:"var(--nice-primary-bg, #dbeafe)"}),Ir={id:"corporate-blue",name:"Corporate Blue",category:"corporate",themeSource:"Blue",config:le({background:"#f0f5ff",gridColor:"#93c5fd20",gridSize:20,selectionColor:"var(--nice-primary-dark, #1d4ed8)"},Sr,Ne,{borderWidth:2,borderRadius:6},{strokeColor:"var(--nice-primary-light, #93c5fd)",strokeWidth:2})},zr=ce({primary:"var(--nice-success, #00ff88)",primaryLight:"#00cc6b",secondary:"#ff00ff",accent:"var(--nice-info, #00ffff)",success:"var(--nice-success, #00ff88)",warning:"var(--nice-warning, #ffff00)",error:"#ff3366",info:"var(--nice-info, #00ffff)",text:"var(--nice-text-secondary, #e0e0e0)",textMuted:"var(--nice-text-secondary, #808080)",border:"#00ff8840",surface:"var(--nice-bg, #1a1a2e)",surfaceAlt:"var(--nice-bg, #16213e)"}),jr={id:"neon-glow",name:"Neon Glow",category:"dark",config:le({background:"#0a0a1a",gridColor:"#00ff8810",gridSize:20,selectionColor:"var(--nice-success, #00ff88)"},zr,gt,{borderColor:"var(--nice-success, #00ff88)",borderWidth:2,shadow:!0,glowColor:"var(--nice-success, #00ff88)",glowIntensity:.6},{strokeColor:"#00ff8880",strokeWidth:2},{backgroundColor:"#00ff880a",borderColor:"#00ff8840"},{glowColor:"var(--nice-success, #00ff88)",glowIntensity:.8,particleColor:"var(--nice-info, #00ffff)",liquidColor:"var(--nice-success, #00ff88)",liquidColorEnd:"var(--nice-info, #00ffff)"})},Ar=ce({primary:"var(--nice-color-accent-pink, #ff2d95)",primaryLight:"#ff6db6",secondary:"#7928ca",accent:"#00d4ff",success:"#39ff14",warning:"var(--nice-warning, #FFD700)",error:"#ff073a",info:"#00d4ff",text:"var(--nice-text-primary, #fff)",textMuted:"#b0b0b0",border:"#ff2d9540",surface:"#1a0030",surfaceAlt:"#2d004a"}),$r={id:"cyberpunk",name:"Cyberpunk",category:"dark",config:le({background:"#0d001a",gridColor:"#ff2d9510",gridSize:24,selectionColor:"var(--nice-color-accent-pink, #ff2d95)"},Ar,gt,{borderColor:"var(--nice-color-accent-pink, #ff2d95)",borderWidth:2,glowColor:"var(--nice-color-accent-pink, #ff2d95)",glowIntensity:.7,shadow:!0,gradientColor:"#2d004a",gradientDirection:"vertical"},{strokeColor:"#7928ca80",strokeWidth:3},{},{glowColor:"var(--nice-color-accent-pink, #ff2d95)",glowIntensity:.9,particleColor:"#00d4ff",liquidColor:"var(--nice-color-accent-pink, #ff2d95)",liquidColorEnd:"#7928ca"})},Dr=ce({primary:"var(--nice-bg, #fff)",primaryLight:"#ffffffaa",secondary:"#4da6ff",accent:"var(--nice-bg, #fff)",text:"var(--nice-text-primary, #fff)",textMuted:"#ffffffaa",border:"#ffffff40",surface:"#1e3d6e",surfaceAlt:"#163050"}),Tr={id:"blueprint",name:"Technical Blueprint",category:"technical",config:le({background:"#0a1929",gridColor:"#4da6ff30",gridSize:16,selectionColor:"var(--nice-text-on-primary, #fff)"},Dr,gt,{backgroundColor:"transparent",borderColor:"#4da6ff",borderWidth:1,borderStyle:"solid",fontColor:"var(--nice-text-primary, #fff)",shadow:!1},{strokeColor:"#4da6ff",strokeWidth:1,strokeDash:[4,4]},{backgroundColor:"transparent",borderColor:"#4da6ff40",borderStyle:"dashed",borderWidth:1})},Pr=ce({primary:"var(--nice-accent, #a78bfa)",primaryLight:"var(--nice-accent, #c4b5fd)",secondary:"var(--nice-color-accent-pink, #f472b6)",accent:"var(--nice-warning-light, #fbbf24)",success:"var(--nice-success-light, #6ee7b7)",warning:"var(--nice-warning-bg, #fde68a)",error:"var(--nice-danger-bg, #fca5a5)",info:"var(--nice-primary-light, #93c5fd)",text:"#4a4a68",textMuted:"#9494b0",border:"#e2d8f4",surface:"#faf5ff",surfaceAlt:"#f3e8ff"}),Rr={id:"pastel-dream",name:"Pastel Dream",category:"pastel",config:le({background:"#fefcff",gridColor:"#e2d8f420",gridSize:20,selectionColor:"var(--nice-accent, #a78bfa)"},Pr,"'Nunito', 'Quicksand', sans-serif",{borderColor:"var(--nice-accent, #c4b5fd)",borderWidth:2,borderRadius:16,shadow:!0},{strokeColor:"var(--nice-accent, #c4b5fd)",strokeWidth:2},{backgroundColor:"#a78bfa10",borderColor:"var(--nice-accent, #c4b5fd)",borderRadius:16})},Or=ce({primary:"var(--nice-success, #059669)",primaryLight:"var(--nice-success-light, #6ee7b7)",secondary:"#065f46",accent:"var(--nice-warning, #f59e0b)",success:"var(--nice-success, #10b981)",warning:"var(--nice-warning, #f59e0b)",error:"var(--nice-danger-dark, #dc2626)",info:"#0d9488",text:"#1a3d2f",textMuted:"#6b8f7f",border:"#a7d7c5",surface:"#ecfdf5",surfaceAlt:"#d1fae5"}),Er={id:"nature-forest",name:"Nature Forest",category:"nature",config:le({background:"#f0fdf4",gridColor:"#a7d7c520",gridSize:20,selectionColor:"var(--nice-success, #059669)"},Or,Ne,{borderColor:"var(--nice-success, #059669)",borderRadius:12},{strokeColor:"var(--nice-success-light, #6ee7b7)"},{backgroundColor:"#05966910",borderColor:"var(--nice-success-light, #6ee7b7)"},{liquidColor:"var(--nice-success, #059669)",liquidColorEnd:"var(--nice-success-light, #6ee7b7)",particleColor:"var(--nice-warning, #f59e0b)"})},Lr=ce({primary:"var(--nice-success, #00ff00)",primaryLight:"#00cc00",secondary:"var(--nice-success, #00ff00)",accent:"var(--nice-warning, #ffff00)",text:"var(--nice-success, #00ff00)",textMuted:"#00990088",border:"#00ff0040",surface:"#001100",surfaceAlt:"#002200"}),Fr={id:"retro-terminal",name:"Retro Terminal",category:"retro",config:le({background:"#000800",gridColor:"#00ff0010",gridSize:16,selectionColor:"var(--nice-success, #00ff00)"},Lr,"'Courier New', 'Fira Code', monospace",{backgroundColor:"#001100",borderColor:"#00ff0060",borderWidth:1,fontColor:"var(--nice-success, #00ff00)",shadow:!1,glowColor:"var(--nice-success, #00ff00)",glowIntensity:.4},{strokeColor:"#00ff0060",strokeWidth:1},{},{glowColor:"var(--nice-success, #00ff00)",glowIntensity:.6,particleColor:"var(--nice-success, #00ff00)",liquidColor:"var(--nice-success, #00ff00)"})},Wr=ce({primary:"#0000ff",primaryLight:"#6666ff",secondary:"#ff00ff",accent:"var(--nice-warning, #ffff00)",text:"var(--nice-text, #000000)",textMuted:"var(--nice-text-secondary, #555555)",border:"var(--nice-border-color, #000000)",surface:"var(--nice-bg, #fff)",surfaceAlt:"var(--nice-border, #eeeeee)"}),Br={id:"high-contrast",name:"High Contrast",category:"accessibility",themeSource:"High Contrast",config:le({background:"var(--nice-bg, #fff)",gridColor:"#00000020",gridSize:20,selectionColor:"#0000ff"},Wr,"Arial, sans-serif",{borderColor:"var(--nice-border-color, #000000)",borderWidth:3,fontColor:"var(--nice-text, #000000)",fontWeight:"bold"},{strokeColor:"var(--nice-text, #000000)",strokeWidth:3},{borderColor:"var(--nice-border-color, #000000)",borderWidth:2})},qr=ce({primary:"var(--nice-primary-hover, #1976d2)",primaryLight:"#64b5f6",secondary:"var(--nice-accent, #9c27b0)",accent:"var(--nice-warning, #ff9800)",success:"var(--nice-success, #4caf50)",warning:"var(--nice-warning, #ff9800)",error:"var(--nice-danger, #f44336)",info:"#03a9f4",text:"#212121",textMuted:"#757575",border:"var(--nice-border, #e0e0e0)",surface:"var(--nice-bg-secondary, #fafafa)",surfaceAlt:"var(--nice-bg-secondary, #f5f5f5)"}),Gr={id:"material-design",name:"Material Design",category:"theme-based",themeSource:"Material",config:le({background:"var(--nice-bg-secondary, #fafafa)",gridColor:"#e0e0e020",gridSize:20,selectionColor:"var(--nice-primary-hover, #1976d2)"},qr,"'Roboto', 'Noto Sans', sans-serif",{borderRadius:4,borderWidth:0,shadow:!0},{strokeColor:"#bdbdbd",strokeWidth:2},{borderRadius:8})},Vr=ce({primary:"#0078d4",primaryLight:"#6cb8f7",secondary:"#8661c5",accent:"#ffaa44",success:"#107c10",warning:"#ffaa44",error:"#d13438",info:"#0078d4",text:"#323130",textMuted:"#a19f9d",border:"#edebe9",surface:"var(--nice-bg, #fff)",surfaceAlt:"#faf9f8"}),Yr={id:"fluent-ui",name:"Fluent UI",category:"theme-based",themeSource:"Fluent",config:le({background:"#faf9f8",gridColor:"#edebe920",gridSize:20,selectionColor:"#0078d4"},Vr,"'Segoe UI', system-ui, sans-serif",{borderRadius:4,borderWidth:1,shadow:!0},{strokeColor:"#c8c6c4",strokeWidth:1})},Xr=ce({primary:"var(--nice-warning-dark, #e65100)",primaryLight:"#ff9e80",secondary:"#ff6f00",accent:"#ffd600",success:"#43a047",warning:"#ff6f00",error:"var(--nice-danger-dark, #c62828)",info:"#0277bd",text:"#3e2723",textMuted:"#8d6e63",border:"#ffccbc",surface:"#fff8e1",surfaceAlt:"var(--nice-warning-bg, #fff3e0)"}),Ur={id:"sunset-warm",name:"Sunset Warm",category:"creative",config:le({background:"#fffde7",gridColor:"#ffccbc20",gridSize:20,selectionColor:"var(--nice-warning-dark, #e65100)"},Xr,Ne,{borderColor:"#ff9e80",gradientColor:"var(--nice-warning-bg, #fff3e0)",gradientDirection:"vertical"},{strokeColor:"#ff9e80"},{},{liquidColor:"var(--nice-warning-dark, #e65100)",liquidColorEnd:"#ffd600",particleColor:"#ffd600"})},Hr=ce({primary:"#006064",primaryLight:"#4dd0e1",secondary:"#00838f",accent:"#ffd54f",success:"#00e676",warning:"#ffd54f",error:"#ff5252",info:"#40c4ff",text:"#004d40",textMuted:"#80cbc4",border:"#b2ebf2",surface:"#e0f7fa",surfaceAlt:"#b2ebf2"}),Jr={id:"ocean-deep",name:"Ocean Deep",category:"nature",config:le({background:"#e0f7fa",gridColor:"#b2ebf220",gridSize:20,selectionColor:"#006064"},Hr,Ne,{borderColor:"#00838f",borderRadius:12},{strokeColor:"#4dd0e1"},{},{liquidColor:"#006064",liquidColorEnd:"#4dd0e1",particleColor:"#ffd54f"})},Zr=ce({primary:"#5d4037",primaryLight:"#a1887f",secondary:"#795548",accent:"#c6a263",text:"#3e2723",textMuted:"#8d6e63",border:"#bcaaa4",surface:"#fdf6f0",surfaceAlt:"#efebe9"}),Kr={id:"elegant-serif",name:"Elegant Serif",category:"creative",config:le({background:"#fdf6f0",gridColor:"#bcaaa420",gridSize:24,selectionColor:"#5d4037"},Zr,_r,{borderColor:"#a1887f",borderWidth:1,borderRadius:2,fontStyle:"normal"},{strokeColor:"#bcaaa4",strokeWidth:1},{borderRadius:4})},Qr=ce({primary:"var(--nice-text, #333333)",primaryLight:"var(--nice-text-secondary, #666666)",secondary:"var(--nice-text-secondary, #555555)",accent:"#ff6600",text:"var(--nice-text, #333333)",textMuted:"var(--nice-text-muted, #999999)",border:"var(--nice-border, #cccccc)",surface:"var(--nice-bg, #fff)",surfaceAlt:"var(--nice-bg-secondary, #f5f5f5)"}),ei={id:"wireframe",name:"Wireframe",category:"technical",config:le({background:"var(--nice-bg, #fff)",gridColor:"#00000008",gridSize:16,selectionColor:"#ff6600"},Qr,"'Balsamiq Sans', 'Comic Sans MS', cursive",{backgroundColor:"transparent",borderColor:"var(--nice-border-color, #999999)",borderWidth:1,borderStyle:"solid",shadow:!1,borderRadius:4},{strokeColor:"var(--nice-text-muted, #999999)",strokeWidth:1},{backgroundColor:"transparent",borderStyle:"dashed",borderWidth:1,borderColor:"var(--nice-border, #cccccc)"})},ti=ce({primary:"#00bfa5",primaryLight:"#64ffda",secondary:"#00897b",accent:"#ff6e40",success:"#00e676",warning:"#ffc400",error:"#ff1744",info:"#00e5ff",text:"#1b5e20",textMuted:"#81c784",border:"#a7ffeb",surface:"#e0f2f1",surfaceAlt:"#b2dfdb"}),ri={id:"mint-fresh",name:"Mint Fresh",category:"nature",config:le({background:"var(--nice-success-bg, #e8f5e9)",gridColor:"#a7ffeb20",gridSize:20,selectionColor:"#00bfa5"},ti,Ne,{borderColor:"#00bfa5",borderRadius:20,borderWidth:2,gradientColor:"#b2dfdb",gradientDirection:"radial"},{strokeColor:"#64ffda",strokeWidth:2},{borderRadius:16},{liquidColor:"#00bfa5",liquidColorEnd:"#64ffda",particleColor:"#ff6e40"})},ii=ce({primary:"#424242",primaryLight:"var(--nice-text-secondary, #9e9e9e)",secondary:"#616161",accent:"var(--nice-danger, #ff5722)",text:"#212121",textMuted:"#bdbdbd",border:"var(--nice-border, #e0e0e0)",surface:"var(--nice-bg-secondary, #fafafa)",surfaceAlt:"var(--nice-bg-secondary, #f5f5f5)"}),ai={id:"monochrome",name:"Monochrome",category:"corporate",config:le({background:"var(--nice-bg-secondary, #fafafa)",gridColor:"#e0e0e020",gridSize:20,selectionColor:"#424242"},ii,Ne,{borderColor:"var(--nice-border-color, #9e9e9e)",borderWidth:1,shadow:!0,borderRadius:4},{strokeColor:"var(--nice-text-secondary, #9e9e9e)",strokeWidth:1.5})},oi=ce({primary:"var(--nice-color-accent-pink, #e91e63)",primaryLight:"#f48fb1",secondary:"var(--nice-accent, #9c27b0)",accent:"var(--nice-warning, #ffeb3b)",success:"var(--nice-success, #4caf50)",warning:"var(--nice-warning, #ff9800)",error:"var(--nice-danger, #f44336)",info:"#00bcd4",text:"#4a148c",textMuted:"#ce93d8",border:"#f8bbd0",surface:"#fce4ec",surfaceAlt:"#f3e5f5"}),si={id:"candy-pop",name:"Candy Pop",category:"creative",config:le({background:"#fff0f5",gridColor:"#f8bbd020",gridSize:20,selectionColor:"var(--nice-color-accent-pink, #e91e63)"},oi,"'Quicksand', 'Nunito', sans-serif",{borderColor:"var(--nice-color-accent-pink, #e91e63)",borderRadius:24,borderWidth:3,gradientColor:"#f3e5f5",gradientDirection:"diagonal"},{strokeColor:"#f48fb1",strokeWidth:3},{borderRadius:20,borderColor:"#f48fb1"},{glowColor:"var(--nice-color-accent-pink, #e91e63)",glowIntensity:.5,particleColor:"var(--nice-warning, #ffeb3b)"})},ni=ce({primary:"var(--nice-text-secondary, #475569)",primaryLight:"var(--nice-text-muted, #94a3b8)",secondary:"var(--nice-text, #334155)",accent:"var(--nice-warning, #f59e0b)",text:"var(--nice-text, #0f172a)",textMuted:"var(--nice-text-muted, #94a3b8)",border:"var(--nice-border, #cbd5e1)",surface:"var(--nice-bg-secondary, #f8fafc)",surfaceAlt:"var(--nice-bg-secondary, #f1f5f9)"}),ci={id:"slate-professional",name:"Slate Professional",category:"corporate",config:le({background:"var(--nice-bg-secondary, #f8fafc)",gridColor:"#cbd5e120",gridSize:20,selectionColor:"var(--nice-text-secondary, #475569)"},ni,"'Inter', system-ui, sans-serif",{borderColor:"var(--nice-border, #cbd5e1)",borderWidth:1,borderRadius:6,shadow:!0},{strokeColor:"var(--nice-text-muted, #94a3b8)",strokeWidth:1.5},{borderColor:"var(--nice-border, #cbd5e1)",borderRadius:8})},li=ce({primary:"var(--nice-accent, #7c3aed)",primaryLight:"var(--nice-accent, #a78bfa)",secondary:"var(--nice-info, #06b6d4)",accent:"var(--nice-color-accent-pink, #f472b6)",success:"var(--nice-success-light, #34d399)",warning:"var(--nice-warning-light, #fbbf24)",error:"var(--nice-danger-light, #f87171)",info:"var(--nice-info, #22d3ee)",text:"var(--nice-text-secondary, #e2e8f0)",textMuted:"var(--nice-text-muted, #94a3b8)",border:"#7c3aed40",surface:"#1e1b4b",surfaceAlt:"#312e81"}),di={id:"aurora-borealis",name:"Aurora Borealis",category:"dark",config:le({background:"#0f0b2e",gridColor:"#7c3aed15",gridSize:24,selectionColor:"var(--nice-accent, #a78bfa)"},li,Ne,{borderColor:"var(--nice-accent, #7c3aed)",borderWidth:2,gradientColor:"#312e81",gradientDirection:"vertical",glowColor:"var(--nice-accent, #a78bfa)",glowIntensity:.5},{strokeColor:"#7c3aed80",strokeWidth:2},{},{glowColor:"var(--nice-accent, #a78bfa)",glowIntensity:.7,particleColor:"var(--nice-info, #06b6d4)",liquidColor:"var(--nice-accent, #7c3aed)",liquidColorEnd:"var(--nice-info, #06b6d4)"})},ui=ce({primary:"#2c3e50",primaryLight:"#7f8c8d",secondary:"#2980b9",accent:"#e74c3c",text:"#2c3e50",textMuted:"#95a5a6",border:"#bdc3c7",surface:"#fdfaf6",surfaceAlt:"#f5f0e8"}),fi={id:"sketch-hand-drawn",name:"Sketch / Hand-drawn",category:"creative",config:le({background:"#fdfaf6",gridColor:"#bdc3c720",gridSize:20,selectionColor:"#2980b9"},ui,"'Caveat', 'Patrick Hand', cursive",{backgroundColor:"#fdfaf6",borderColor:"#2c3e50",borderWidth:2,borderRadius:2,shadow:!1},{strokeColor:"#2c3e50",strokeWidth:2},{borderStyle:"dashed",borderWidth:2})},hi=ce({primary:"var(--nice-primary, #2196f3)",primaryLight:"#64b5f6",secondary:"var(--nice-warning, #ff9800)",accent:"var(--nice-danger, #ff5722)",success:"var(--nice-success, #4caf50)",warning:"var(--nice-warning, #ffc107)",error:"var(--nice-danger, #f44336)",info:"#03a9f4",text:"var(--nice-text-primary, #fff)",textMuted:"#b0bec5",border:"#ffffff40",surface:"var(--nice-primary, #2196f3)",surfaceAlt:"var(--nice-primary-dark, #1565c0)"}),pi={id:"infographic-bold",name:"Infographic Bold",category:"creative",config:le({background:"#eceff1",gridColor:"#b0bec520",gridSize:24,selectionColor:"var(--nice-danger, #ff5722)"},hi,"'Montserrat', 'Roboto', sans-serif",{backgroundColor:"var(--nice-primary, #2196f3)",borderColor:"var(--nice-primary-dark, #1565c0)",borderWidth:0,fontColor:"var(--nice-text-on-primary, #fff)",fontWeight:"bold",borderRadius:12,shadow:!0},{strokeColor:"#90a4ae",strokeWidth:3},{backgroundColor:"#2196f320",borderWidth:2,borderRadius:16})},mi=ce({primary:"#9333ea",primaryLight:"var(--nice-accent, #c084fc)",secondary:"var(--nice-info, #6366f1)",accent:"var(--nice-warning, #f59e0b)",text:"var(--nice-text-primary, #f1f5f9)",textMuted:"var(--nice-accent, #a78bfa)",border:"#7c3aed40",surface:"#1c1033",surfaceAlt:"#2d1b69"}),gi={id:"midnight-purple",name:"Midnight Purple",category:"dark",config:le({background:"#0f0720",gridColor:"#9333ea10",gridSize:20,selectionColor:"var(--nice-accent, #c084fc)"},mi,Ne,{borderColor:"#9333ea",borderWidth:2,gradientColor:"#2d1b69",gradientDirection:"vertical",shadow:!1},{strokeColor:"#9333ea80",strokeWidth:2},{},{glowColor:"#9333ea",glowIntensity:.6,liquidColor:"#9333ea",liquidColorEnd:"var(--nice-accent, #c084fc)"})},Ze=[Nr,Mr,Ir,Gr,Yr,jr,$r,Tr,Fr,Rr,Ur,Jr,Kr,Er,ei,Br,ri,ai,si,ci,di,fi,pi,gi],yi=[{id:"fill-solid",name:"Solid Fill",category:"fill",style:{opacity:1}},{id:"fill-gradient-v",name:"Vertical Gradient",category:"fill",style:{gradientColor:"var(--nice-text-secondary, #e2e8f0)",gradientDirection:"vertical"}},{id:"fill-gradient-h",name:"Horizontal Gradient",category:"fill",style:{gradientColor:"var(--nice-text-secondary, #e2e8f0)",gradientDirection:"horizontal"}},{id:"fill-gradient-d",name:"Diagonal Gradient",category:"fill",style:{gradientColor:"var(--nice-text-secondary, #e2e8f0)",gradientDirection:"diagonal"}},{id:"fill-gradient-r",name:"Radial Gradient",category:"fill",style:{gradientColor:"var(--nice-text-secondary, #e2e8f0)",gradientDirection:"radial"}},{id:"fill-transparent",name:"Transparent",category:"fill",style:{backgroundColor:"transparent",opacity:1}},{id:"fill-semi",name:"Semi-transparent",category:"fill",style:{opacity:.6}},{id:"fill-glass",name:"Glassmorphism",category:"fill",style:{opacity:.7,gradientColor:"#ffffff40",gradientDirection:"vertical",borderWidth:1,borderColor:"#ffffff60"}},{id:"border-none",name:"No Border",category:"border",style:{borderWidth:0}},{id:"border-thin",name:"Thin Border",category:"border",style:{borderWidth:1}},{id:"border-medium",name:"Medium Border",category:"border",style:{borderWidth:2}},{id:"border-thick",name:"Thick Border",category:"border",style:{borderWidth:3}},{id:"border-heavy",name:"Heavy Border",category:"border",style:{borderWidth:4}},{id:"border-solid",name:"Solid",category:"border",style:{borderStyle:"solid"}},{id:"border-dashed",name:"Dashed",category:"border",style:{borderStyle:"dashed"}},{id:"border-dotted",name:"Dotted",category:"border",style:{borderStyle:"dotted"}},{id:"border-rounded-sm",name:"Rounded Small",category:"border",style:{borderRadius:4}},{id:"border-rounded-md",name:"Rounded Medium",category:"border",style:{borderRadius:8}},{id:"border-rounded-lg",name:"Rounded Large",category:"border",style:{borderRadius:16}},{id:"border-rounded-xl",name:"Rounded XL",category:"border",style:{borderRadius:24}},{id:"border-pill",name:"Pill / Capsule",category:"border",style:{borderRadius:999}},{id:"border-sharp",name:"Sharp Corners",category:"border",style:{borderRadius:0}},{id:"effect-shadow",name:"Drop Shadow",category:"effect",style:{shadow:!0}},{id:"effect-no-shadow",name:"No Shadow",category:"effect",style:{shadow:!1}},{id:"effect-glow-blue",name:"Blue Glow",category:"effect",style:{glowColor:"var(--nice-primary, #3b82f6)",glowIntensity:.6}},{id:"effect-glow-green",name:"Green Glow",category:"effect",style:{glowColor:"var(--nice-success, #10b981)",glowIntensity:.6}},{id:"effect-glow-red",name:"Red Glow",category:"effect",style:{glowColor:"var(--nice-danger, #ef4444)",glowIntensity:.6}},{id:"effect-glow-purple",name:"Purple Glow",category:"effect",style:{glowColor:"var(--nice-accent, #8b5cf6)",glowIntensity:.6}},{id:"effect-glow-gold",name:"Gold Glow",category:"effect",style:{glowColor:"var(--nice-warning, #f59e0b)",glowIntensity:.6}},{id:"effect-glow-neon",name:"Neon Glow",category:"effect",style:{glowColor:"var(--nice-success, #00ff88)",glowIntensity:.8}}],bi=[{id:"line-straight",name:"Straight",category:"type",style:{lineType:"straight"}},{id:"line-bezier",name:"Bezier Curve",category:"type",style:{lineType:"bezier"}},{id:"line-orthogonal",name:"Orthogonal",category:"type",style:{lineType:"orthogonal"}},{id:"line-step",name:"Step",category:"type",style:{lineType:"step"}},{id:"stroke-thin",name:"Thin Stroke",category:"stroke",style:{strokeWidth:1}},{id:"stroke-medium",name:"Medium Stroke",category:"stroke",style:{strokeWidth:2}},{id:"stroke-thick",name:"Thick Stroke",category:"stroke",style:{strokeWidth:3}},{id:"stroke-heavy",name:"Heavy Stroke",category:"stroke",style:{strokeWidth:4}},{id:"stroke-solid",name:"Solid",category:"stroke",style:{strokeDash:[]}},{id:"stroke-dashed",name:"Dashed",category:"stroke",style:{strokeDash:[8,4]}},{id:"stroke-dotted",name:"Dotted",category:"stroke",style:{strokeDash:[2,4]}},{id:"stroke-dash-dot",name:"Dash-Dot",category:"stroke",style:{strokeDash:[8,4,2,4]}},{id:"stroke-long-dash",name:"Long Dash",category:"stroke",style:{strokeDash:[16,8]}},{id:"arrow-target-none",name:"No Target Arrow",category:"arrow",style:{targetArrow:"none"}},{id:"arrow-target-arrow",name:"Arrow →",category:"arrow",style:{targetArrow:"arrow"}},{id:"arrow-target-open",name:"Open Arrow ▷",category:"arrow",style:{targetArrow:"openArrow"}},{id:"arrow-target-diamond",name:"Diamond ◇",category:"arrow",style:{targetArrow:"diamond"}},{id:"arrow-target-circle",name:"Circle ○",category:"arrow",style:{targetArrow:"circle"}},{id:"arrow-source-none",name:"No Source Arrow",category:"arrow",style:{sourceArrow:"none"}},{id:"arrow-source-arrow",name:"← Source Arrow",category:"arrow",style:{sourceArrow:"arrow"}},{id:"arrow-source-open",name:"◁ Open Source",category:"arrow",style:{sourceArrow:"openArrow"}},{id:"arrow-source-diamond",name:"◇ Diamond Source",category:"arrow",style:{sourceArrow:"diamond"}},{id:"arrow-source-circle",name:"○ Circle Source",category:"arrow",style:{sourceArrow:"circle"}},{id:"arrow-bidirectional",name:"↔ Bidirectional",category:"arrow",style:{sourceArrow:"arrow",targetArrow:"arrow"}},{id:"arrow-association",name:" Association (none)",category:"arrow",style:{sourceArrow:"none",targetArrow:"none"}},{id:"arrow-composition",name:"◆→ Composition",category:"arrow",style:{sourceArrow:"diamond",targetArrow:"arrow"}},{id:"arrow-aggregation",name:"◇→ Aggregation",category:"arrow",style:{sourceArrow:"diamond",targetArrow:"arrow"}},{id:"arrow-dependency",name:"- - → Dependency",category:"arrow",style:{targetArrow:"openArrow",strokeDash:[8,4]}},{id:"arrow-inheritance",name:"△→ Inheritance",category:"arrow",style:{targetArrow:"openArrow"}},{id:"effect-animated",name:"Animated Flow",category:"effect",style:{animated:!0,flowSpeed:1}},{id:"effect-animated-fast",name:"Fast Animated",category:"effect",style:{animated:!0,flowSpeed:2}},{id:"effect-animated-slow",name:"Slow Animated",category:"effect",style:{animated:!0,flowSpeed:.5}},{id:"effect-liquid",name:"Liquid Flow",category:"effect",style:{liquidFlow:{active:!0,color:"var(--nice-primary, #3b82f6)",speed:1}}},{id:"effect-liquid-neon",name:"Neon Liquid",category:"effect",style:{liquidFlow:{active:!0,color:"var(--nice-success, #00ff88)",colorEnd:"var(--nice-info, #00ffff)",speed:1.5,particleDensity:5}}}],Ft=[{id:"tp-fade-in",name:"Fade In",effect:"fadeIn",durationMs:400,easing:"easeOut",description:"Smoothly fades in"},{id:"tp-fade-out",name:"Fade Out",effect:"fadeOut",durationMs:400,easing:"easeIn",description:"Smoothly fades out"},{id:"tp-slide-left",name:"Slide Left",effect:"slideInLeft",durationMs:500,easing:"easeOut",description:"Slides in from left"},{id:"tp-slide-right",name:"Slide Right",effect:"slideInRight",durationMs:500,easing:"easeOut",description:"Slides in from right"},{id:"tp-slide-top",name:"Slide Down",effect:"slideInTop",durationMs:500,easing:"easeOut",description:"Slides in from top"},{id:"tp-slide-bottom",name:"Slide Up",effect:"slideInBottom",durationMs:500,easing:"easeOut",description:"Slides in from bottom"},{id:"tp-zoom-in",name:"Zoom In",effect:"zoomIn",durationMs:400,easing:"spring",description:"Zooms in with spring"},{id:"tp-zoom-out",name:"Zoom Out",effect:"zoomOut",durationMs:400,easing:"easeIn",description:"Zooms out"},{id:"tp-bounce",name:"Bounce In",effect:"bounce",durationMs:800,easing:"bounce",description:"Bounces into place"},{id:"tp-pulse",name:"Pulse",effect:"pulse",durationMs:1e3,easing:"easeInOut",description:"Pulsing scale effect"},{id:"tp-shake",name:"Shake",effect:"shake",durationMs:600,easing:"linear",description:"Shakes horizontally"},{id:"tp-glow",name:"Glow",effect:"glow",durationMs:1200,easing:"easeInOut",description:"Glowing highlight"},{id:"tp-highlight",name:"Highlight",effect:"highlight",durationMs:800,easing:"easeInOut",description:"Golden highlight flash"},{id:"tp-ripple",name:"Ripple",effect:"ripple",durationMs:1e3,easing:"easeOut",description:"Ripple wave effect"},{id:"tp-expand",name:"Expand",effect:"expand",durationMs:500,easing:"spring",description:"Expand from collapsed"},{id:"tp-collapse",name:"Collapse",effect:"collapse",durationMs:400,easing:"easeIn",description:"Collapse to hidden"},{id:"tp-color-shift",name:"Color Shift",effect:"colorShift",durationMs:2e3,easing:"linear",description:"Rainbow color cycle"},{id:"tp-liquid-fill",name:"Liquid Fill",effect:"liquidFill",durationMs:1500,easing:"easeInOut",description:"Liquid filling effect"},{id:"tp-draw-path",name:"Draw Path",effect:"drawPath",durationMs:1200,easing:"easeOut",description:"Edge draws itself"},{id:"tp-particle-trail",name:"Particle Trail",effect:"particleTrail",durationMs:2e3,easing:"linear",description:"Particles along edge"},{id:"tp-typewriter",name:"Typewriter",effect:"typewriter",durationMs:1500,easing:"linear",description:"Text appears letter by letter"}];function xi(r){return Ze.find(e=>e.id===r)}function vi(r){return Ze.filter(e=>e.category===r)}function wi(r){return{canvasBackground:r.canvas.background,gridColor:r.canvas.gridColor,gridSize:r.canvas.gridSize,selectionColor:r.canvas.selectionColor,fontFamily:r.fontFamily,nodeDefaults:r.nodeDefaults,edgeDefaults:r.edgeDefaults,groupDefaults:r.groupDefaults,palette:r.palette,effects:r.effects}}function ki(r,e,t,i,a,o){const c=ce({primary:t.primary,primaryLight:t.primaryHover,secondary:t.info,accent:t.warning,success:t.success,warning:t.warning,error:t.error,info:t.info,text:a.primary,textMuted:a.muted,border:o.color,surface:i.primary,surfaceAlt:i.secondary}),s=_i(i.primary);return{id:r,name:`${e} Theme`,category:"theme-based",themeSource:e,config:le({background:i.primary,gridColor:s?`${o.color}40`:`${o.color}20`,gridSize:20,selectionColor:t.primary},c,Ne,{shadow:!s,borderWidth:s?1:2},{strokeColor:s?`${o.color}80`:o.color})}}function _i(r){const e=r.replace("#","");if(e.length<6)return!1;const t=parseInt(e.slice(0,2),16),i=parseInt(e.slice(2,4),16),a=parseInt(e.slice(4,6),16);return(t*299+i*587+a*114)/1e3<128}const Ni=["fadeIn","fadeOut","slideInLeft","slideInRight","slideInTop","slideInBottom","zoomIn","zoomOut","pulse","shake","highlight","flowPulse","bounce","glow","colorShift","liquidFill","expand","collapse","ripple","typewriter","morphShape","drawPath","particleTrail"],Ci=["linear","easeIn","easeOut","easeInOut","spring","bounce"],Ke=({animations:r,onAdd:e,onRemove:t,onUpdate:i,onPlay:a,onStop:o,isPlaying:c=!1,availableTargets:s=[],className:l})=>{const{t:u}=Ee(),[d,m]=b.useState(!1),[p,g]=b.useState(null),h=b.useCallback(()=>{if(!e||s.length===0)return;const y=s[0];e({name:`Animation ${r.length+1}`,targetId:y.id,targetType:y.type,effect:"fadeIn",startMs:r.length*500,durationMs:600,easing:"easeOut"})},[e,r.length,s]),x=b.useCallback(y=>{if(!e||s.length===0)return;const S=s[0];e({name:y.name,targetId:S.id,targetType:S.type,effect:y.effect,startMs:r.length*500,durationMs:y.durationMs,easing:y.easing}),m(!1)},[e,r.length,s]),w=Math.max(2e3,...r.map(y=>y.startMs+y.durationMs+(y.delayMs??0)));return n.jsxs("div",{className:`nice-diagram-timeline ${l??""}`,children:[n.jsxs("div",{className:"nice-diagram-timeline__header",children:[n.jsx("h4",{className:"nice-diagram-timeline__title",children:u("animation.timeline")}),n.jsxs("div",{className:"nice-diagram-timeline__controls",children:[c?n.jsxs(v.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:o,children:[n.jsx(v.NiceIcon,{name:"stop",size:14})," ",u("animation.stop")]}):n.jsxs(v.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:a,children:[n.jsx(v.NiceIcon,{name:"play",size:14})," ",u("animation.play")]}),n.jsxs(v.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:h,disabled:s.length===0,children:[n.jsx(v.NiceIcon,{name:"plus",size:14})," ",u("animation.add")]}),n.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[n.jsxs(v.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:()=>m(y=>!y),disabled:s.length===0,title:"Add from preset",children:[n.jsx(v.NiceIcon,{name:"video",size:14})," Presets"]}),d&&n.jsx("div",{style:{position:"absolute",bottom:"100%",left:0,background:"var(--nice-bg, #fff)",border:"1px solid var(--nice-border, #ddd)",borderRadius:6,boxShadow:"0 4px 12px var(--nice-overlay-15, rgba(0, 0, 0, 0.15))",maxHeight:280,overflowY:"auto",width:200,zIndex:100},children:Ft.map(y=>n.jsx(v.NiceButton,{variant:"ghost",size:"sm",onClick:()=>x(y),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 10px",fontSize:12,borderBottom:"1px solid var(--nice-bg-secondary, #f0f0f0)"},title:`${y.effect} — ${y.durationMs}ms ${y.easing}`,children:y.name},y.id))})]})]})]}),n.jsxs("div",{className:"nice-diagram-timeline__tracks",children:[r.length===0&&n.jsx("p",{className:"nice-diagram-timeline__empty",children:u("animation.noAnimations")}),r.map(y=>{const S=y.startMs/w*100,M=y.durationMs/w*100,I=p===y.id;return n.jsxs("div",{className:"nice-diagram-timeline__track",children:[n.jsxs("div",{className:"nice-diagram-timeline__track-label",children:[n.jsx("span",{className:"nice-diagram-timeline__track-name",onClick:()=>g(I?null:y.id),style:{cursor:"pointer"},title:"Click to edit",children:y.name}),n.jsx("span",{className:"nice-diagram-timeline__track-effect",children:y.effect}),n.jsx(v.NiceButton,{className:"nice-diagram-timeline__track-remove",variant:"ghost",size:"sm",onClick:()=>t==null?void 0:t(y.id),title:u("toolbar.delete"),children:"×"})]}),I&&n.jsxs("div",{className:"nice-diagram-timeline__track-editor",style:{display:"flex",gap:4,padding:"4px 0",flexWrap:"wrap",fontSize:11},children:[n.jsx(v.NiceSelect,{value:y.effect,onChange:N=>i==null?void 0:i(y.id,{effect:N}),options:Ni.map(N=>({value:N,label:N})),style:{fontSize:11,padding:"1px 4px"}}),n.jsx(v.NiceSelect,{value:y.easing,onChange:N=>i==null?void 0:i(y.id,{easing:N}),options:Ci.map(N=>({value:N,label:N})),style:{fontSize:11,padding:"1px 4px"}}),n.jsx(v.NiceSelect,{value:y.targetId,onChange:N=>{const k=s.find(T=>T.id===N);k&&(i==null||i(y.id,{targetId:k.id,targetType:k.type}))},options:s.map(N=>({value:N.id,label:N.label})),style:{fontSize:11,padding:"1px 4px",maxWidth:100}}),n.jsx(v.NiceNumberInput,{value:y.startMs,min:0,step:100,onChange:N=>i==null?void 0:i(y.id,{startMs:N??0}),style:{width:60,fontSize:11},title:"Start (ms)"}),n.jsx(v.NiceNumberInput,{value:y.durationMs,min:50,step:50,onChange:N=>i==null?void 0:i(y.id,{durationMs:N??50}),style:{width:60,fontSize:11},title:"Duration (ms)"})]}),n.jsx("div",{className:"nice-diagram-timeline__track-bar",children:n.jsx("div",{className:"nice-diagram-timeline__track-segment",style:{left:`${S}%`,width:`${M}%`},title:`${y.effect} ${y.startMs}ms → ${y.startMs+y.durationMs}ms (${y.easing})`})})]},y.id)})]}),n.jsx("div",{className:"nice-diagram-timeline__ruler",children:Array.from({length:5}).map((y,S)=>{const M=Math.round(w/4*S);return n.jsxs("span",{className:"nice-diagram-timeline__ruler-mark",style:{left:`${S/4*100}%`},children:[M,"ms"]},S)})})]})};Ke.displayName="AnimationTimeline";const Mi=/^[a-z][a-z0-9-]*$/,Si=.1,Ii=5,Xe=8,dt=[{cursor:"nw-resize",dx:0,dy:0,resizeX:-1,resizeY:-1},{cursor:"n-resize",dx:.5,dy:0,resizeX:0,resizeY:-1},{cursor:"ne-resize",dx:1,dy:0,resizeX:1,resizeY:-1},{cursor:"w-resize",dx:0,dy:.5,resizeX:-1,resizeY:0},{cursor:"e-resize",dx:1,dy:.5,resizeX:1,resizeY:0},{cursor:"sw-resize",dx:0,dy:1,resizeX:-1,resizeY:1},{cursor:"s-resize",dx:.5,dy:1,resizeX:0,resizeY:1},{cursor:"se-resize",dx:1,dy:1,resizeX:1,resizeY:1}],ve=({nodes:r,edges:e,groups:t=[],viewport:i,onViewportChange:a,theme:o,selectedId:c,selectedIds:s=[],onSelectElement:l,onMultiSelect:u,onNodeDragStart:d,onNodeDrag:m,onNodeDragEnd:p,onNodeResize:g,onNodeLabelChange:h,animationStates:x,particleState:w,viewMode:y="editor",ghostOpacity:S=.15,onGroupCollapse:M,onNodeCollapse:I,onInteraction:N,interactive:k=!1,showGrid:T=!0,showRulers:L=!1,snapToGrid:O=!0,gridSnapSize:F=10,className:W})=>{const C=b.useRef(null),[E,P]=b.useState(!1),[q,R]=b.useState({x:0,y:0}),[$,X]=b.useState(null),[G,U]=b.useState({x:0,y:0}),[J,ne]=b.useState(null),[de,V]=b.useState(null),[Y,ue]=b.useState(null),[fe,ae]=b.useState(null),[Ce,Te]=b.useState(""),[it,ge]=b.useState([]),at=(o==null?void 0:o.canvasBackground)??"var(--nice-bg-secondary, #f8f9fa)",Le=(o==null?void 0:o.gridColor)??"var(--nice-border, #e0e0e0)",Me=(o==null?void 0:o.gridSize)??20,Se=(o==null?void 0:o.selectionColor)??"var(--nice-primary, #2196f3)",Fe=b.useMemo(()=>{const f=new Set(s);return c&&f.add(c),f},[c,s]),be=b.useCallback(f=>O?Math.round(f/F)*F:f,[O,F]),We=b.useCallback((f,_,z)=>{const A=[],j=_.x,D=_.y,Q=j+z.width/2,Z=D+z.height/2,K=j+z.width,te=D+z.height;for(const he of r){if(he.id===f)continue;const ie=he.position.x,oe=he.position.y,pe=ie+he.size.width/2,ke=oe+he.size.height/2,Ie=ie+he.size.width,_e=oe+he.size.height;Math.abs(j-ie)<5&&A.push({x:ie}),Math.abs(K-Ie)<5&&A.push({x:Ie}),Math.abs(Q-pe)<5&&A.push({x:pe}),Math.abs(j-Ie)<5&&A.push({x:Ie}),Math.abs(K-ie)<5&&A.push({x:ie}),Math.abs(D-oe)<5&&A.push({y:oe}),Math.abs(te-_e)<5&&A.push({y:_e}),Math.abs(Z-ke)<5&&A.push({y:ke}),Math.abs(D-_e)<5&&A.push({y:_e}),Math.abs(te-oe)<5&&A.push({y:oe})}ge(A)},[r]),we=b.useCallback(f=>{if(f.preventDefault(),!a)return;const _=f.deltaY>0?.9:1.1,z=Math.min(Ii,Math.max(Si,i.zoom*_)),A=C.current;if(!A)return;const B=A.getBoundingClientRect(),j=f.clientX-B.left,D=f.clientY-B.top,Q=z/i.zoom,Z=j-(j-i.x)*Q,K=D-(D-i.y)*Q;a({x:Z,y:K,zoom:z})},[i,a]),ot=b.useCallback(f=>{if(f.button===1||f.button===0&&f.target.tagName==="svg"){if(f.button===0&&k&&!f.shiftKey&&f.target.tagName==="svg"){const _=C.current;if(_){const z=_.getBoundingClientRect(),A=(f.clientX-z.left-i.x)/i.zoom,B=(f.clientY-z.top-i.y)/i.zoom;V({x:A,y:B}),ne({x1:A,y1:B,x2:A,y2:B})}l&&l(null),u&&u([]);return}P(!0),R({x:f.clientX-i.x,y:f.clientY-i.y}),l&&f.button===0&&l(null)}},[i,l,u,k]),$e=b.useCallback(f=>{if(de){const _=C.current;if(!_)return;const z=_.getBoundingClientRect(),A=(f.clientX-z.left-i.x)/i.zoom,B=(f.clientY-z.top-i.y)/i.zoom;ne({x1:de.x,y1:de.y,x2:A,y2:B});return}if(E&&a){a({...i,x:f.clientX-q.x,y:f.clientY-q.y});return}if(Y&&g){const _=C.current;if(!_)return;const z=_.getBoundingClientRect(),A=(f.clientX-z.left-i.x)/i.zoom,B=(f.clientY-z.top-i.y)/i.zoom,j=A-Y.startMouse.x,D=B-Y.startMouse.y,Q=dt[Y.handleIdx];let Z=Y.startSize.width+j*Q.resizeX,K=Y.startSize.height+D*Q.resizeY,te=Y.startPos.x+(Q.resizeX<0?j:0),he=Y.startPos.y+(Q.resizeY<0?D:0);Z=Math.max(30,be(Z)),K=Math.max(20,be(K)),te=be(te),he=be(he),g(Y.nodeId,{width:Z,height:K},{x:te,y:he});return}if($&&m){const _=C.current;if(!_)return;const z=_.getBoundingClientRect(),A=be((f.clientX-z.left-i.x)/i.zoom-G.x),B=be((f.clientY-z.top-i.y)/i.zoom-G.y);m($,{x:A,y:B});const j=r.find(D=>D.id===$);j&&We($,{x:A,y:B},j.size)}},[de,E,a,i,q,Y,g,$,m,G,be,r,We]),Be=b.useCallback(f=>{if(J&&de){const _=Math.min(J.x1,J.x2),z=Math.min(J.y1,J.y2),A=Math.max(J.x1,J.x2),B=Math.max(J.y1,J.y2);if(Math.abs(A-_)>5||Math.abs(B-z)>5){const j=r.filter(D=>{const Q=D.position.x,Z=D.position.y,K=Q+D.size.width,te=Z+D.size.height;return K>_&&Q<A&&te>z&&Z<B}).map(D=>D.id);u==null||u(j),j.length===1&&(l==null||l(j[0]))}ne(null),V(null);return}if(E&&P(!1),Y){ue(null);return}if($&&p){const _=C.current;if(!_)return;const z=_.getBoundingClientRect(),A=be((f.clientX-z.left-i.x)/i.zoom-G.x),B=be((f.clientY-z.top-i.y)/i.zoom-G.y);p($,{x:A,y:B})}X(null),ge([])},[J,de,E,Y,$,p,i,G,be,r,u,l]),qe=b.useCallback((f,_)=>{if(f.stopPropagation(),!k)return;const z=r.find(Q=>Q.id===_);if(!z||z.locked)return;if(f.shiftKey&&u){const Q=[...s],Z=Q.indexOf(_);Z>=0?Q.splice(Z,1):Q.push(_),u(Q);return}l==null||l(_);const A=C.current;if(!A)return;const B=A.getBoundingClientRect(),j=(f.clientX-B.left-i.x)/i.zoom,D=(f.clientY-B.top-i.y)/i.zoom;U({x:j-z.position.x,y:D-z.position.y}),X(_),d==null||d(_)},[k,r,i,l,d,u,s]),st=b.useCallback((f,_,z)=>{if(f.stopPropagation(),!k)return;const A=r.find(Z=>Z.id===_);if(!A||A.locked)return;const B=C.current;if(!B)return;const j=B.getBoundingClientRect(),D=(f.clientX-j.left-i.x)/i.zoom,Q=(f.clientY-j.top-i.y)/i.zoom;ue({nodeId:_,handleIdx:z,startMouse:{x:D,y:Q},startPos:{...A.position},startSize:{...A.size}}),l==null||l(_)},[k,r,i,l]),nt=b.useCallback((f,_)=>{if(f.stopPropagation(),!k||!h)return;const z=r.find(A=>A.id===_);!z||z.locked||(ae(_),Te(z.label))},[k,r,h]),Ge=b.useCallback(()=>{fe&&h&&h(fe,Ce),ae(null)},[fe,Ce,h]),H=b.useCallback((f,_)=>{f.stopPropagation(),l==null||l(_)},[l]),Ae=b.useCallback(f=>{const _=r.find(z=>z.id===f);return _?{x:_.position.x+_.size.width/2,y:_.position.y+_.size.height/2}:{x:0,y:0}},[r]),ye=b.useCallback((f,_)=>{const z=r.find(D=>D.id===f);if(!z)return{x:0,y:0};const A=z.ports.find(D=>D.id===_);if(!A)return Ae(f);const{position:B,size:j}=z;switch(A.side){case"top":return{x:B.x+j.width*A.offset,y:B.y};case"bottom":return{x:B.x+j.width*A.offset,y:B.y+j.height};case"left":return{x:B.x,y:B.y+j.height*A.offset};case"right":return{x:B.x+j.width,y:B.y+j.height*A.offset};default:return Ae(f)}},[r,Ae]),nr=b.useCallback(f=>{const _=ye(f.sourceNodeId,f.sourcePortId),z=ye(f.targetNodeId,f.targetPortId);switch(f.style.lineType??"bezier"){case"straight":return`M ${_.x} ${_.y} L ${z.x} ${z.y}`;case"orthogonal":{const B=(_.x+z.x)/2;return`M ${_.x} ${_.y} L ${B} ${_.y} L ${B} ${z.y} L ${z.x} ${z.y}`}case"step":{const B=(_.y+z.y)/2;return`M ${_.x} ${_.y} L ${_.x} ${B} L ${z.x} ${B} L ${z.x} ${z.y}`}case"bezier":default:{const B=Math.abs(z.x-_.x)*.5;return`M ${_.x} ${_.y} C ${_.x+B} ${_.y}, ${z.x-B} ${z.y}, ${z.x} ${z.y}`}}},[ye]),cr=b.useCallback((f,_)=>{const{size:z,style:A,shape:B}=f,j=z.width,D=z.height,Z=!!(A.gradientColor&&A.backgroundColor)?`url(#${_})`:A.backgroundColor??"var(--nice-bg, #fff)",K=A.borderColor??"var(--nice-text, #333333)",te=A.borderWidth??1,he=A.borderRadius??(B==="roundedRect"?8:0),ie=A.borderStyle==="dashed"?"8,4":A.borderStyle==="dotted"?"2,4":void 0,oe=A.shadow?"url(#nd-shadow)":void 0;switch(B){case"ellipse":case"circle":return n.jsx("ellipse",{cx:j/2,cy:D/2,rx:j/2,ry:D/2,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe});case"diamond":return n.jsx("polygon",{points:`${j/2},0 ${j},${D/2} ${j/2},${D} 0,${D/2}`,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe});case"hexagon":{const pe=j/4;return n.jsx("polygon",{points:`${pe},0 ${j-pe},0 ${j},${D/2} ${j-pe},${D} ${pe},${D} 0,${D/2}`,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe})}case"parallelogram":{const pe=j*.15;return n.jsx("polygon",{points:`${pe},0 ${j},0 ${j-pe},${D} 0,${D}`,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe})}case"cylinder":return n.jsxs("g",{filter:oe,children:[n.jsx("ellipse",{cx:j/2,cy:D*.1,rx:j/2,ry:D*.1,fill:Z,stroke:K,strokeWidth:te}),n.jsx("rect",{x:0,y:D*.1,width:j,height:D*.8,fill:Z,stroke:"none"}),n.jsx("line",{x1:0,y1:D*.1,x2:0,y2:D*.9,stroke:K,strokeWidth:te}),n.jsx("line",{x1:j,y1:D*.1,x2:j,y2:D*.9,stroke:K,strokeWidth:te}),n.jsx("ellipse",{cx:j/2,cy:D*.9,rx:j/2,ry:D*.1,fill:Z,stroke:K,strokeWidth:te})]});case"triangle":return n.jsx("polygon",{points:`${j/2},0 ${j},${D} 0,${D}`,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe});case"cloud":{const pe=`M${j*.25},${D*.8} A${j*.2},${j*.2},0,1,1,${j*.15},${D*.45} A${j*.18},${j*.18},0,1,1,${j*.35},${D*.2} A${j*.2},${j*.2},0,1,1,${j*.65},${D*.2} A${j*.18},${j*.18},0,1,1,${j*.85},${D*.45} A${j*.2},${j*.2},0,1,1,${j*.75},${D*.8} Z`;return n.jsx("path",{d:pe,fill:Z,stroke:K,strokeWidth:te,filter:oe})}case"document":{const pe=`M 0 0 L ${j} 0 L ${j} ${D*.85} Q ${j*.75} ${D*.7}, ${j*.5} ${D*.85} Q ${j*.25} ${D}, 0 ${D*.85} Z`;return n.jsx("path",{d:pe,fill:Z,stroke:K,strokeWidth:te,filter:oe})}case"actor":return n.jsxs("g",{stroke:K,strokeWidth:te,fill:"none",filter:oe,children:[n.jsx("circle",{cx:j/2,cy:D*.15,r:D*.12,fill:Z}),n.jsx("line",{x1:j/2,y1:D*.27,x2:j/2,y2:D*.6}),n.jsx("line",{x1:j*.15,y1:D*.4,x2:j*.85,y2:D*.4}),n.jsx("line",{x1:j/2,y1:D*.6,x2:j*.2,y2:D}),n.jsx("line",{x1:j/2,y1:D*.6,x2:j*.8,y2:D})]});case"rectangle":case"roundedRect":case"custom":default:return n.jsx("rect",{width:j,height:D,rx:he,ry:he,fill:Z,stroke:K,strokeWidth:te,strokeDasharray:ie,filter:oe})}},[]),wt=b.useCallback(f=>{if(!x)return{};const _=x.get(f);if(!_)return{};const z=_.glow>0?`drop-shadow(0 0 ${_.glow}px gold)`:"",A=_.highlightColor?`drop-shadow(0 0 6px ${_.highlightColor})`:"";return{opacity:_.opacity,transform:`translate(${_.translateX}px, ${_.translateY}px) scale(${_.scale})`,filter:[z,A].filter(Boolean).join(" ")||void 0}},[x]),lr=b.useMemo(()=>{if(!w)return null;const f=[];for(const[,_]of w.glowStates){const z=$t(_.elementId),A=Dt(_.intensity,_.pulse);f.push(n.jsxs("filter",{id:z,x:"-50%",y:"-50%",width:"200%",height:"200%",children:[n.jsx("feGaussianBlur",{in:"SourceGraphic",stdDeviation:A,result:"blur"}),n.jsx("feFlood",{floodColor:_.color,floodOpacity:.6,result:"color"}),n.jsx("feComposite",{in:"color",in2:"blur",operator:"in",result:"glowColored"}),n.jsxs("feMerge",{children:[n.jsx("feMergeNode",{in:"glowColored"}),n.jsx("feMergeNode",{in:"SourceGraphic"})]})]},z))}return f},[w]),dr=b.useMemo(()=>{if(!w)return null;const f=[];for(const[_,z]of w.liquidFlows){if(!z.active)continue;const A=e.find(Z=>Z.id===_);if(!(A!=null&&A.style.liquidFlow))continue;const{color:B,colorEnd:j}=A.style.liquidFlow,D=`nd-liquid-${_}`,Q=z.gradientOffset;f.push(n.jsxs("linearGradient",{id:D,x1:"0",y1:"0",x2:"1",y2:"0",children:[n.jsx("stop",{offset:`${Q*100%100}%`,stopColor:B,stopOpacity:.8}),n.jsx("stop",{offset:`${(Q+.3)*100%100}%`,stopColor:j??B,stopOpacity:.4}),n.jsx("stop",{offset:`${(Q+.6)*100%100}%`,stopColor:B,stopOpacity:.8})]},D))}return f},[w,e]),ur=b.useMemo(()=>r.filter(f=>f.style.gradientColor&&f.style.backgroundColor).map(f=>{const _=`nd-grad-${f.id}`,z=f.style.gradientDirection??"vertical";if(z==="radial")return n.jsxs("radialGradient",{id:_,children:[n.jsx("stop",{offset:"0%",stopColor:f.style.backgroundColor}),n.jsx("stop",{offset:"100%",stopColor:f.style.gradientColor})]},_);const A=z==="horizontal"||z==="diagonal"?"1":"0",B=z==="vertical"||z==="diagonal"?"1":"0";return n.jsxs("linearGradient",{id:_,x1:"0",y1:"0",x2:A,y2:B,children:[n.jsx("stop",{offset:"0%",stopColor:f.style.backgroundColor}),n.jsx("stop",{offset:"100%",stopColor:f.style.gradientColor})]},_)}),[r]);return n.jsxs("svg",{ref:C,className:`nice-diagram-canvas ${W??""}`,style:{width:"100%",height:"100%",background:at,cursor:E?"grabbing":Y&&Y.nodeId?dt[Y.handleIdx].cursor:"default"},onWheel:we,onMouseDown:ot,onMouseMove:$e,onMouseUp:Be,onMouseLeave:Be,children:[n.jsxs("defs",{children:[n.jsx("marker",{id:"nd-arrow",viewBox:"0 0 10 10",refX:"10",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:"12",markerHeight:"12",orient:"auto-start-reverse",children:n.jsx("path",{d:"M 0 0 L 10 5 L 0 10 Z",fill:"var(--nice-text, #333)"})}),n.jsx("marker",{id:"nd-open-arrow",viewBox:"0 0 10 10",refX:"10",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:"12",markerHeight:"12",orient:"auto-start-reverse",children:n.jsx("path",{d:"M 0 0 L 10 5 L 0 10",fill:"none",stroke:"var(--nice-text, #333)",strokeWidth:"1.5"})}),n.jsx("marker",{id:"nd-diamond-marker",viewBox:"0 0 10 10",refX:"5",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:"15",markerHeight:"15",orient:"auto-start-reverse",children:n.jsx("polygon",{points:"5,0 10,5 5,10 0,5",fill:"var(--nice-text, #333)"})}),n.jsx("marker",{id:"nd-circle-marker",viewBox:"0 0 10 10",refX:"5",refY:"5",markerUnits:"userSpaceOnUse",markerWidth:"12",markerHeight:"12",orient:"auto-start-reverse",children:n.jsx("circle",{cx:"5",cy:"5",r:"4",fill:"var(--nice-text, #333)"})}),n.jsx("filter",{id:"nd-shadow",x:"-10%",y:"-10%",width:"130%",height:"130%",children:n.jsx("feDropShadow",{dx:"2",dy:"2",stdDeviation:"3",floodColor:"#00000033"})}),T&&n.jsx("pattern",{id:"nd-grid",width:Me,height:Me,patternUnits:"userSpaceOnUse",children:n.jsx("path",{d:`M ${Me} 0 L 0 0 0 ${Me}`,fill:"none",stroke:Le,strokeWidth:"0.5"})}),ur,lr,dr,r.filter(f=>f.style.glowColor).map(f=>{const _=`nd-node-glow-${f.id}`,z=(f.style.glowIntensity??.5)*10;return n.jsxs("filter",{id:_,x:"-50%",y:"-50%",width:"200%",height:"200%",children:[n.jsx("feGaussianBlur",{in:"SourceGraphic",stdDeviation:z,result:"blur"}),n.jsx("feFlood",{floodColor:f.style.glowColor,floodOpacity:.5,result:"color"}),n.jsx("feComposite",{in:"color",in2:"blur",operator:"in",result:"glowColored"}),n.jsxs("feMerge",{children:[n.jsx("feMergeNode",{in:"glowColored"}),n.jsx("feMergeNode",{in:"SourceGraphic"})]})]},_)})]}),L&&n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"0",y:"0",width:"100%",height:"20",fill:"var(--nice-bg-secondary, #f0f0f0)",stroke:"var(--nice-border, #ccc)",strokeWidth:"0.5"}),n.jsx("rect",{x:"0",y:"0",width:"20",height:"100%",fill:"var(--nice-bg-secondary, #f0f0f0)",stroke:"var(--nice-border, #ccc)",strokeWidth:"0.5"}),Array.from({length:100},(f,_)=>{const z=_*Me*i.zoom+i.x,A=_*Me;return z>20?n.jsxs("g",{children:[n.jsx("line",{x1:z,y1:"0",x2:z,y2:"20",stroke:"var(--nice-text-muted, #999)",strokeWidth:"0.5"}),n.jsx("text",{x:z+2,y:"14",fontSize:"9",fill:"var(--nice-text-secondary, #666)",children:A})]},`rx${_}`):null}),Array.from({length:100},(f,_)=>{const z=_*Me*i.zoom+i.y,A=_*Me;return z>20?n.jsxs("g",{children:[n.jsx("line",{x1:"0",y1:z,x2:"20",y2:z,stroke:"var(--nice-text-muted, #999)",strokeWidth:"0.5"}),n.jsx("text",{x:"2",y:z-2,fontSize:"9",fill:"var(--nice-text-secondary, #666)",writingMode:"tb",children:A})]},`ry${_}`):null})]}),n.jsxs("g",{transform:`translate(${i.x}, ${i.y}) scale(${i.zoom})`,children:[T&&n.jsx("rect",{x:"-10000",y:"-10000",width:"20000",height:"20000",fill:"url(#nd-grid)"}),t.map(f=>{var Q,Z,K,te,he,ie,oe,pe,ke,Ie,_e,Ve;const _=r.filter(se=>f.nodeIds.includes(se.id));if(_.length===0&&!f.collapsed)return null;const z=((Q=f.style)==null?void 0:Q.padding)??20;if(f.collapsed){const se=r.find(ct=>f.nodeIds.includes(ct.id)),Pe=se?se.position.x:0,Ye=se?se.position.y:0;return n.jsxs("g",{style:{cursor:"pointer"},onClick:()=>M==null?void 0:M(f.id),children:[n.jsx("rect",{x:Pe,y:Ye,width:160,height:40,fill:((Z=f.style)==null?void 0:Z.backgroundColor)??"rgba(200,200,255,0.3)",stroke:((K=f.style)==null?void 0:K.borderColor)??"var(--nice-text-muted, #aab)",strokeWidth:((te=f.style)==null?void 0:te.borderWidth)??1,rx:((he=f.style)==null?void 0:he.borderRadius)??6,strokeDasharray:"6,3"}),n.jsxs("text",{x:Pe+24,y:Ye+24,fontSize:"12",fill:((ie=f.style)==null?void 0:ie.labelColor)??"var(--nice-text-secondary, #666)",fontWeight:"bold",children:[f.label," (",f.nodeIds.length,")"]})]},f.id)}const A=Math.min(..._.map(se=>se.position.x))-z,B=Math.min(..._.map(se=>se.position.y))-z,j=Math.max(..._.map(se=>se.position.x+se.size.width))+z,D=Math.max(..._.map(se=>se.position.y+se.size.height))+z;return n.jsxs("g",{children:[n.jsx("rect",{x:A,y:B,width:j-A,height:D-B,fill:((oe=f.style)==null?void 0:oe.backgroundColor)??"rgba(200,200,255,0.1)",stroke:((pe=f.style)==null?void 0:pe.borderColor)??"var(--nice-text-muted, #aab)",strokeWidth:((ke=f.style)==null?void 0:ke.borderWidth)??1,rx:((Ie=f.style)==null?void 0:Ie.borderRadius)??6,strokeDasharray:((_e=f.style)==null?void 0:_e.borderStyle)==="dashed"?"6,3":void 0}),n.jsx("text",{x:A+6,y:B-4,fontSize:"12",fill:((Ve=f.style)==null?void 0:Ve.labelColor)??"var(--nice-text-secondary, #666)",fontWeight:"bold",children:f.label}),(k||y!=="editor")&&M&&n.jsxs("g",{style:{cursor:"pointer"},onClick:se=>{se.stopPropagation(),M(f.id)},children:[n.jsx("rect",{x:j-24,y:B-12,width:20,height:20,rx:4,fill:"white",stroke:"var(--nice-text-muted, #999)",strokeWidth:1}),n.jsx("g",{transform:`translate(${j-20}, ${B-8})`,children:n.jsx(v.NiceIcon,{name:"chevron-down",size:12,color:"var(--nice-text-secondary, #666)"})})]})]},f.id)}),it.map((f,_)=>n.jsx("line",{x1:f.x!=null?f.x:-1e4,y1:f.y!=null?f.y:-1e4,x2:f.x!=null?f.x:1e4,y2:f.y!=null?f.y:1e4,stroke:"#ff4081",strokeWidth:.5,strokeDasharray:"4,4"},`snap-${_}`)),e.map(f=>{var he;const _=nr(f),z=Fe.has(f.id),A=f.style.targetArrow==="diamond"?"url(#nd-diamond-marker)":f.style.targetArrow==="circle"?"url(#nd-circle-marker)":f.style.targetArrow==="openArrow"?"url(#nd-open-arrow)":f.style.targetArrow!=="none"?"url(#nd-arrow)":void 0,B=f.style.sourceArrow==="diamond"?"url(#nd-diamond-marker)":f.style.sourceArrow==="circle"?"url(#nd-circle-marker)":f.style.sourceArrow==="openArrow"?"url(#nd-open-arrow)":f.style.sourceArrow==="arrow"?"url(#nd-arrow)":void 0,j=wt(f.id),D=x==null?void 0:x.get(f.id),Q=D==null?void 0:D.strokeProgress,Z=Q!=null&&Q>=0&&Q<1?{strokeDasharray:"1000",strokeDashoffset:`${1e3*(1-Q)}`}:void 0,K=f.style.liquidFlow,te=w==null?void 0:w.liquidFlows.get(f.id);return n.jsxs("g",{style:j,onClick:ie=>H(ie,f.id),children:[k&&n.jsx("path",{d:_,fill:"none",stroke:"transparent",strokeWidth:12,style:{cursor:"pointer"}}),(K==null?void 0:K.active)&&n.jsx("path",{d:_,fill:"none",stroke:`url(#nd-liquid-${f.id})`,strokeWidth:K.pipeWidth??(f.style.strokeWidth??1.5)*4,strokeLinecap:"round",opacity:.5}),n.jsx("path",{d:_,fill:"none",stroke:z?Se:f.style.strokeColor??"var(--nice-text, #333)",strokeWidth:f.style.strokeWidth??1.5,strokeDasharray:(Z==null?void 0:Z.strokeDasharray)??((he=f.style.strokeDash)==null?void 0:he.join(","))??(f.style.animated?"6,4":void 0),strokeDashoffset:Z==null?void 0:Z.strokeDashoffset,markerEnd:A,markerStart:B,opacity:f.style.opacity??1,style:k?{cursor:"pointer",transition:Z?void 0:"stroke-dashoffset 0.1s"}:void 0}),f.style.animated&&n.jsx("circle",{r:3,fill:Se,children:n.jsx("animateMotion",{dur:`${1/(f.style.flowSpeed||1)}s`,repeatCount:"indefinite",path:_})}),(te==null?void 0:te.active)&&te.particles.map((ie,oe)=>n.jsx("circle",{r:ie.size,fill:(K==null?void 0:K.color)??"var(--nice-primary, #3b82f6)",opacity:ie.opacity*.6,children:n.jsx("animateMotion",{dur:`${3/(((K==null?void 0:K.speed)??1)+.5)}s`,repeatCount:"indefinite",path:_,begin:`${ie.t*3}s`})},`lp-${f.id}-${oe}`)),D&&D.particleTrailT>=0&&n.jsxs(n.Fragment,{children:[n.jsx("circle",{r:4,fill:"var(--nice-warning-light, #fbbf24)",opacity:.8,children:n.jsx("animateMotion",{dur:"2s",repeatCount:"indefinite",path:_,begin:`${D.particleTrailT*2}s`})}),n.jsx("circle",{r:2,fill:"var(--nice-warning-light, #fbbf24)",opacity:.5,children:n.jsx("animateMotion",{dur:"2s",repeatCount:"indefinite",path:_,begin:`${(D.particleTrailT+.1)*2}s`})})]}),f.label&&(()=>{const ie=ye(f.sourceNodeId,f.sourcePortId),oe=ye(f.targetNodeId,f.targetPortId),pe=(ie.x+oe.x)/2,ke=(ie.y+oe.y)/2;return n.jsxs("g",{children:[n.jsx("rect",{x:pe-4,y:ke-16,width:f.label.length*7+8,height:18,rx:3,fill:"var(--nice-bg-primary, #fff)",fillOpacity:.85}),n.jsx("text",{x:pe,y:ke-2,textAnchor:"start",fontSize:"11",fill:"var(--nice-text-secondary, #555)",children:f.label})]})})()]},f.id)}),r.filter(f=>!f.hidden||y==="editor").map(f=>{const _=Fe.has(f.id),z=wt(f.id),A=x==null?void 0:x.get(f.id),B=f.style.fontFamily??(o==null?void 0:o.fontFamily)??"sans-serif",j=f.style.fontSize??14,D=f.style.fontColor??"var(--nice-text, #222)",Q=f.style.fontWeight??"normal",Z=f.style.fontStyle??"normal",K=f.style.textAlign??"center",te=f.style.rotation??0,he=`nd-grad-${f.id}`,ie=!!f.hidden,oe=ie?S??.3:f.style.opacity??1,pe=f.style.glowColor?`url(#nd-node-glow-${f.id})`:void 0,ke=K==="left"?"start":K==="right"?"end":"middle",Ie=K==="left"?8:K==="right"?f.size.width-8:f.size.width/2,_e=A==null?void 0:A.typewriterChars,Ve=_e!=null&&_e>=0?f.label.slice(0,_e):f.label,se=A==null?void 0:A.liquidFillProgress,Pe=A==null?void 0:A.rippleRadius,Ye=A==null?void 0:A.rippleOpacity,ct=f.childNodeIds&&f.childNodeIds.length>0,fr=!!f.collapsed;return n.jsxs("g",{transform:`translate(${f.position.x}, ${f.position.y})${te?` rotate(${te}, ${f.size.width/2}, ${f.size.height/2})`:""}`,style:{...z,cursor:ie?"pointer":k&&!f.locked?"grab":"default",opacity:oe,filter:pe},onMouseDown:me=>qe(me,f.id),onDoubleClick:me=>nt(me,f.id),onClick:me=>{me.stopPropagation(),l==null||l(f.id),f.interactions&&f.interactions.length>0&&f.interactions.filter(Oe=>Oe.trigger==="click").forEach(Oe=>N==null?void 0:N(f.id,Oe.id))},onMouseEnter:()=>{f.interactions&&f.interactions.filter(ze=>ze.trigger==="hover").forEach(ze=>N==null?void 0:N(f.id,ze.id))},children:[ie&&n.jsx("rect",{x:-1,y:-1,width:f.size.width+2,height:f.size.height+2,fill:"none",stroke:"var(--nice-text-muted, #999)",strokeWidth:1,strokeDasharray:"3,3",rx:4,opacity:.5}),cr(f,he),se!=null&&se>0&&se<1&&n.jsx("clipPath",{id:`nd-liquid-clip-${f.id}`,children:n.jsx("rect",{x:0,y:f.size.height*(1-se),width:f.size.width,height:f.size.height*se})}),se!=null&&se>0&&se<1&&n.jsx("rect",{x:0,y:0,width:f.size.width,height:f.size.height,fill:f.style.glowColor??"var(--nice-primary, #3b82f6)",opacity:.25,rx:f.style.borderRadius??4,clipPath:`url(#nd-liquid-clip-${f.id})`}),Pe!=null&&Pe>0&&n.jsx("circle",{cx:f.size.width/2,cy:f.size.height/2,r:Pe,fill:"none",stroke:f.style.glowColor??Se,strokeWidth:2,opacity:Ye??.5}),_&&n.jsx("rect",{x:-3,y:-3,width:f.size.width+6,height:f.size.height+6,fill:"none",stroke:Se,strokeWidth:2,strokeDasharray:"4,3",rx:6}),_&&k&&!f.locked&&dt.map((me,ze)=>n.jsx("rect",{x:me.dx*f.size.width-Xe/2,y:me.dy*f.size.height-Xe/2,width:Xe,height:Xe,fill:"white",stroke:Se,strokeWidth:1.5,rx:1,style:{cursor:me.cursor},onMouseDown:Oe=>st(Oe,f.id,ze)},ze)),fe===f.id?n.jsx("foreignObject",{x:4,y:4,width:f.size.width-8,height:f.size.height-8,children:n.jsx("input",{xmlns:"http://www.w3.org/1999/xhtml",type:"text",value:Ce,onChange:me=>Te(me.target.value),onBlur:Ge,onKeyDown:me=>{me.key==="Enter"&&Ge(),me.key==="Escape"&&ae(null)},autoFocus:!0,style:{width:"100%",height:"100%",border:"1px solid "+Se,borderRadius:3,padding:"2px 4px",fontSize:j,fontFamily:B,fontWeight:Q,fontStyle:Z,textAlign:K,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",outline:"none"}})}):n.jsxs(n.Fragment,{children:[n.jsx("text",{x:Ie,y:f.size.height/2+(f.description?-4:0),textAnchor:ke,dominantBaseline:"central",fontFamily:B,fontSize:j,fontWeight:Q,fontStyle:Z,fill:D,pointerEvents:"none",children:Ve}),f.description&&n.jsx("text",{x:Ie,y:f.size.height/2+j*.8,textAnchor:ke,dominantBaseline:"central",fontFamily:B,fontSize:j*.75,fill:"var(--nice-text-secondary, #777)",pointerEvents:"none",children:f.description}),f.icon&&(Mi.test(f.icon)?n.jsx("g",{transform:`translate(${f.size.width/2-8}, 4)`,pointerEvents:"none",children:n.jsx(v.NiceIcon,{name:f.icon,size:16,color:"var(--nice-text-secondary, #666)"})}):n.jsx("text",{x:f.size.width/2,y:14,textAnchor:"middle",fontSize:16,pointerEvents:"none",children:f.icon})),f.style.linkUrl&&n.jsx("g",{transform:`translate(${f.size.width-14}, 3)`,pointerEvents:"none",children:n.jsx(v.NiceIcon,{name:"link",size:10,color:"var(--nice-primary-hover, #1976d2)"})}),ct&&k&&n.jsxs("g",{onClick:me=>{me.stopPropagation(),I==null||I(f.id)},style:{cursor:"pointer"},children:[n.jsx("rect",{x:f.size.width-18,y:f.size.height-18,width:16,height:16,rx:3,fill:"white",stroke:"var(--nice-text-muted, #aaa)",strokeWidth:.5}),n.jsx("g",{transform:`translate(${f.size.width-15}, ${f.size.height-15})`,children:n.jsx(v.NiceIcon,{name:fr?"chevron-right":"chevron-down",size:10,color:"var(--nice-text-secondary, #666)"})})]})]}),k&&f.ports.map(me=>{const ze=zi(f,me.id);return n.jsx("circle",{cx:ze.x,cy:ze.y,r:4,fill:"var(--nice-bg, #fff)",stroke:"var(--nice-text-secondary, #666)",strokeWidth:1,style:{cursor:"crosshair"}},me.id)})]},f.id)}),w&&w.particles.length>0&&n.jsx("g",{className:"nd-particle-overlay",children:w.particles.map((f,_)=>n.jsx("circle",{cx:f.x,cy:f.y,r:f.size,fill:f.color,opacity:f.opacity},`ptcl-${_}`))}),J&&n.jsx("rect",{x:Math.min(J.x1,J.x2),y:Math.min(J.y1,J.y2),width:Math.abs(J.x2-J.x1),height:Math.abs(J.y2-J.y1),fill:"rgba(33,150,243,0.1)",stroke:Se,strokeWidth:1,strokeDasharray:"4,2"})]})]})};function zi(r,e){const t=r.ports.find(a=>a.id===e);if(!t)return{x:0,y:0};const{size:i}=r;switch(t.side){case"top":return{x:i.width*t.offset,y:0};case"bottom":return{x:i.width*t.offset,y:i.height};case"left":return{x:0,y:i.height*t.offset};case"right":return{x:i.width,y:i.height*t.offset};default:return{x:0,y:0}}}ve.displayName="DiagramCanvas";const ji=180,Ai=120,Qe=({nodes:r,edges:e,viewport:t,onViewportChange:i,canvasWidth:a=800,canvasHeight:o=600,width:c=ji,height:s=Ai,className:l})=>{const u=b.useMemo(()=>{if(r.length===0)return{minX:0,minY:0,maxX:400,maxY:300};let x=1/0,w=1/0,y=-1/0,S=-1/0;for(const I of r)x=Math.min(x,I.position.x),w=Math.min(w,I.position.y),y=Math.max(y,I.position.x+I.size.width),S=Math.max(S,I.position.y+I.size.height);const M=50;return{minX:x-M,minY:w-M,maxX:y+M,maxY:S+M}},[r]),d=u.maxX-u.minX,m=u.maxY-u.minY,p=Math.min(c/d,s/m),g=b.useMemo(()=>{const x=(-t.x/t.zoom-u.minX)*p,w=(-t.y/t.zoom-u.minY)*p,y=a/t.zoom*p,S=o/t.zoom*p;return{x,y:w,w:y,h:S}},[t,u,p,a,o]),h=b.useCallback(x=>{if(!i)return;const w=x.currentTarget.getBoundingClientRect(),y=x.clientX-w.left,S=x.clientY-w.top,M=y/p+u.minX,I=S/p+u.minY;i({...t,x:-(M*t.zoom-a/2),y:-(I*t.zoom-o/2)})},[i,t,p,u,a,o]);return n.jsxs("svg",{className:`nice-diagram-minimap ${l??""}`,width:c,height:s,style:{border:"1px solid var(--nice-border, #ccc)",background:"var(--nice-bg, #fff)",borderRadius:4,cursor:"pointer"},onClick:h,children:[e.map(x=>{const w=r.find(k=>k.id===x.sourceNodeId),y=r.find(k=>k.id===x.targetNodeId);if(!w||!y)return null;const S=(w.position.x+w.size.width/2-u.minX)*p,M=(w.position.y+w.size.height/2-u.minY)*p,I=(y.position.x+y.size.width/2-u.minX)*p,N=(y.position.y+y.size.height/2-u.minY)*p;return n.jsx("line",{x1:S,y1:M,x2:I,y2:N,stroke:"var(--nice-text-muted, #aaa)",strokeWidth:.5},x.id)}),r.map(x=>n.jsx("rect",{x:(x.position.x-u.minX)*p,y:(x.position.y-u.minY)*p,width:x.size.width*p,height:x.size.height*p,fill:x.style.backgroundColor??"var(--nice-border, #ddd)",stroke:"var(--nice-text-muted, #999)",strokeWidth:.5},x.id)),n.jsx("rect",{x:g.x,y:g.y,width:g.w,height:g.h,fill:"rgba(33,150,243,0.15)",stroke:"var(--nice-primary, #2196f3)",strokeWidth:1})]})};Qe.displayName="DiagramMinimap";const $i=["rectangle","roundedRect","ellipse","circle","diamond","hexagon","parallelogram","cylinder","triangle","cloud","document","actor"],et=({selectedNode:r,selectedEdge:e,onNodeChange:t,onEdgeChange:i,onRemove:a,className:o})=>{var u,d,m,p,g;const{t:c}=Ee(),s=b.useCallback((h,x)=>{!r||!t||t(r.id,{style:{...r.style,[h]:x}})},[r,t]),l=b.useCallback((h,x)=>{!e||!i||i(e.id,{style:{...e.style,[h]:x}})},[e,i]);return!r&&!e?n.jsx("div",{className:`nice-diagram-property-panel nice-diagram-property-panel--empty ${o??""}`,children:n.jsx("p",{className:"nice-diagram-property-panel__hint",children:c("panel.noSelection")})}):r?n.jsxs("div",{className:`nice-diagram-property-panel ${o??""}`,children:[n.jsx("h3",{className:"nice-diagram-property-panel__title",children:c("panel.nodeProperties")}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("node.label"),n.jsx(v.NiceTextInput,{value:r.label,onChange:h=>t==null?void 0:t(r.id,{label:h}),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("node.description"),n.jsx(v.NiceTextInput,{value:r.description??"",onChange:h=>t==null?void 0:t(r.id,{description:h||void 0}),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("node.shape"),n.jsx(v.NiceSelect,{value:r.shape,onChange:h=>t==null?void 0:t(r.id,{shape:h}),options:$i.map(h=>({value:h,label:h})),className:"nice-diagram-property-panel__select"})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.width"),n.jsx(v.NiceNumberInput,{value:r.size.width,min:20,onChange:h=>t==null?void 0:t(r.id,{size:{...r.size,width:h??40}}),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.height"),n.jsx(v.NiceNumberInput,{value:r.size.height,min:20,onChange:h=>t==null?void 0:t(r.id,{size:{...r.size,height:h??40}}),className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.bgColor"),n.jsx(v.NiceColorPicker,{value:r.style.backgroundColor??"var(--nice-bg, #fff)",onChange:h=>s("backgroundColor",h),className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.borderColor"),n.jsx(v.NiceColorPicker,{value:r.style.borderColor??"var(--nice-text, #333333)",onChange:h=>s("borderColor",h),className:"nice-diagram-property-panel__color"})]})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.fontSize"),n.jsx(v.NiceNumberInput,{value:r.style.fontSize??14,min:8,max:72,onChange:h=>s("fontSize",h??14),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("node.fontColor"),n.jsx(v.NiceColorPicker,{value:r.style.fontColor??"#222222",onChange:h=>s("fontColor",h),className:"nice-diagram-property-panel__color"})]})]}),n.jsx(v.NiceCheckbox,{checked:r.locked??!1,onChange:h=>t==null?void 0:t(r.id,{locked:h}),label:c("node.locked"),className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),n.jsx("h4",{className:"nice-diagram-property-panel__section-title",style:{fontSize:12,marginTop:12,marginBottom:4,color:"var(--nice-text-secondary, #666)"},children:"Effects"}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Glow Color",n.jsx(v.NiceColorPicker,{value:r.style.glowColor??"var(--nice-primary, #3b82f6)",onChange:h=>s("glowColor",h),className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Glow Intensity",n.jsx(v.NiceSlider,{min:0,max:3,step:.1,value:r.style.glowIntensity??0,onChange:h=>s("glowIntensity",h),className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Opacity",n.jsx(v.NiceSlider,{min:0,max:1,step:.05,value:r.style.opacity??1,onChange:h=>s("opacity",h),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Border Radius",n.jsx(v.NiceNumberInput,{min:0,max:50,value:r.style.borderRadius??4,onChange:h=>s("borderRadius",h??4),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Border Width",n.jsx(v.NiceNumberInput,{min:0,max:10,step:.5,value:r.style.borderWidth??1,onChange:h=>s("borderWidth",h??1),className:"nice-diagram-property-panel__input"})]}),n.jsx(v.NiceCheckbox,{checked:r.style.shadow??!1,onChange:h=>s("shadow",h),label:"Shadow",className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Gradient End",n.jsx(v.NiceColorPicker,{value:r.style.gradientColor??"var(--nice-bg, #fff)",onChange:h=>s("gradientColor",h),className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Gradient Dir",n.jsx(v.NiceSelect,{value:r.style.gradientDirection??"vertical",onChange:h=>s("gradientDirection",h),options:[{value:"vertical",label:"Vertical"},{value:"horizontal",label:"Horizontal"},{value:"diagonal",label:"Diagonal"},{value:"radial",label:"Radial"}],className:"nice-diagram-property-panel__select"})]})]}),n.jsx(v.NiceCheckbox,{checked:r.hidden??!1,onChange:h=>t==null?void 0:t(r.id,{hidden:h}),label:"Hidden (ghost in editor)",className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),n.jsx(v.NiceButton,{className:"nice-diagram-property-panel__btn nice-diagram-property-panel__btn--danger",variant:"ghost",size:"sm",onClick:()=>a==null?void 0:a(r.id),children:c("toolbar.delete")})]}):e?n.jsxs("div",{className:`nice-diagram-property-panel ${o??""}`,children:[n.jsx("h3",{className:"nice-diagram-property-panel__title",children:c("panel.edgeProperties")}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("edge.label"),n.jsx(v.NiceTextInput,{value:e.label??"",onChange:h=>i==null?void 0:i(e.id,{label:h||void 0}),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:[c("edge.lineType"),n.jsx(v.NiceSelect,{value:e.style.lineType??"bezier",onChange:h=>l("lineType",h),options:[{value:"straight",label:"Straight"},{value:"bezier",label:"Bezier"},{value:"orthogonal",label:"Orthogonal"},{value:"step",label:"Step"}],className:"nice-diagram-property-panel__select"})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("edge.color"),n.jsx(v.NiceColorPicker,{value:e.style.strokeColor??"var(--nice-text, #333333)",onChange:h=>l("strokeColor",h),className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:[c("edge.width"),n.jsx(v.NiceNumberInput,{value:e.style.strokeWidth??1.5,min:.5,max:10,step:.5,onChange:h=>l("strokeWidth",h??1.5),className:"nice-diagram-property-panel__input"})]})]}),n.jsx(v.NiceCheckbox,{checked:e.style.animated??!1,onChange:h=>l("animated",h),label:c("edge.animated"),className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),e.style.animated&&n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Flow Speed",n.jsx(v.NiceSlider,{min:.1,max:5,step:.1,value:e.style.flowSpeed??1,onChange:h=>l("flowSpeed",h),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Dash Style",n.jsx(v.NiceSelect,{value:e.style.strokeDash?e.style.strokeDash.join(","):"solid",onChange:h=>{const x=h;x==="solid"?l("strokeDash",[]):l("strokeDash",x.split(",").map(Number))},options:[{value:"solid",label:"Solid"},{value:"6,4",label:"Dashed"},{value:"2,2",label:"Dotted"},{value:"8,4,2,4",label:"Dash-Dot"},{value:"12,6",label:"Long Dash"}],className:"nice-diagram-property-panel__select"})]}),n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Target Arrow",n.jsx(v.NiceSelect,{value:e.style.targetArrow??"arrow",onChange:h=>l("targetArrow",h),options:[{value:"arrow",label:"Arrow"},{value:"openArrow",label:"Open Arrow"},{value:"diamond",label:"Diamond"},{value:"circle",label:"Circle"},{value:"none",label:"None"}],className:"nice-diagram-property-panel__select"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Source Arrow",n.jsx(v.NiceSelect,{value:e.style.sourceArrow??"none",onChange:h=>l("sourceArrow",h),options:[{value:"none",label:"None"},{value:"arrow",label:"Arrow"},{value:"openArrow",label:"Open Arrow"},{value:"diamond",label:"Diamond"},{value:"circle",label:"Circle"}],className:"nice-diagram-property-panel__select"})]})]}),n.jsx("h4",{className:"nice-diagram-property-panel__section-title",style:{fontSize:12,marginTop:12,marginBottom:4,color:"var(--nice-text-secondary, #666)"},children:"Liquid Flow"}),n.jsx(v.NiceCheckbox,{checked:((u=e.style.liquidFlow)==null?void 0:u.active)??!1,onChange:h=>{const x=e.style.liquidFlow??{active:!1,color:"var(--nice-primary, #3b82f6)",speed:1,pipeWidth:6};i==null||i(e.id,{style:{...e.style,liquidFlow:{...x,active:h}}})},label:"Enable Liquid Flow",className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--check"}),((d=e.style.liquidFlow)==null?void 0:d.active)&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"nice-diagram-property-panel__row",children:[n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Color",n.jsx(v.NiceColorPicker,{value:((m=e.style.liquidFlow)==null?void 0:m.color)??"var(--nice-primary, #3b82f6)",onChange:h=>{const x=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...x,color:h}}})},className:"nice-diagram-property-panel__color"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label nice-diagram-property-panel__label--half",children:["Speed",n.jsx(v.NiceSlider,{min:.1,max:5,step:.1,value:((p=e.style.liquidFlow)==null?void 0:p.speed)??1,onChange:h=>{const x=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...x,speed:h}}})},className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Pipe Width",n.jsx(v.NiceNumberInput,{min:2,max:20,value:((g=e.style.liquidFlow)==null?void 0:g.pipeWidth)??6,onChange:h=>{const x=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...x,pipeWidth:h??6}}})},className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Opacity",n.jsx(v.NiceSlider,{min:0,max:1,step:.05,value:e.style.opacity??1,onChange:h=>l("opacity",h),className:"nice-diagram-property-panel__input"})]}),n.jsx(v.NiceButton,{className:"nice-diagram-property-panel__btn nice-diagram-property-panel__btn--danger",variant:"ghost",size:"sm",onClick:()=>a==null?void 0:a(e.id),children:c("toolbar.delete")})]}):null};et.displayName="DiagramPropertyPanel";const Nt={flowchart:["rectangle","roundedRect","diamond","parallelogram","ellipse","circle","document","cylinder"],orgchart:["roundedRect","ellipse","rectangle"],mindmap:["roundedRect","ellipse","cloud","rectangle"],bpmn:["rectangle","roundedRect","circle","diamond","document"],er:["rectangle","diamond","ellipse"],sequence:["rectangle","actor","circle"],stateMachine:["roundedRect","circle","diamond"],networkTopology:["rectangle","circle","cloud","cylinder","hexagon"],decisionTree:["rectangle","diamond","roundedRect"],custom:["rectangle","roundedRect","ellipse","circle","diamond","hexagon","parallelogram","cylinder","triangle","cloud","document","actor"]},Di=["dagre","forceDirected","grid","radial","tree"],Ti=["sans-serif","serif","monospace","Arial","Helvetica","Times New Roman","Courier New","Georgia","Verdana","Tahoma","Trebuchet MS"],Pi=[8,9,10,11,12,14,16,18,20,24,28,32,36,48,72],tt=({activeTool:r,onToolChange:e,diagramType:t,onAddNode:i,onApplyLayout:a,onUndo:o,onRedo:c,canUndo:s=!1,canRedo:l=!1,onExport:u,onZoomIn:d,onZoomOut:m,onZoomReset:p,zoomLevel:g=1,onToggleBold:h,onToggleItalic:x,isBold:w=!1,isItalic:y=!1,onFontFamilyChange:S,currentFontFamily:M="sans-serif",onFontSizeChange:I,currentFontSize:N=14,onAlignLeft:k,onAlignCenterH:T,onAlignRight:L,onAlignTop:O,onAlignCenterV:F,onAlignBottom:W,onDistributeH:C,onDistributeV:E,onBringToFront:P,onSendToBack:q,onGroupSelected:R,onUngroupSelected:$,onCopy:X,onPaste:G,onDuplicate:U,onSelectAll:J,selectionCount:ne=0,onFind:de,showFind:V=!1,findQuery:Y="",onFindQueryChange:ue,viewMode:fe="editor",onViewModeChange:ae,stylePresetId:Ce,onStylePresetChange:Te,className:it})=>{const{t:ge}=Ee(),[at,Le]=b.useState(!1),[Me,Se]=b.useState(!1),[Fe,be]=b.useState(!1),[We,we]=b.useState(!1),[ot,$e]=b.useState(!1),[Be,qe]=b.useState(!1),st=Nt[t]??Nt.custom,nt=b.useCallback(H=>{i==null||i(H),Le(!1)},[i]),Ge=b.useCallback(H=>{a==null||a(H),Se(!1)},[a]);return n.jsxs("div",{className:`nice-diagram-toolbar ${it??""}`,children:[n.jsxs("div",{className:"nice-diagram-toolbar__row",children:[n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="select"?"primary":"ghost",size:"sm",onClick:()=>e("select"),title:`${ge("toolbar.select")} (V)`,children:n.jsx(v.NiceIcon,{name:"cursor",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="pan"?"primary":"ghost",size:"sm",onClick:()=>e("pan"),title:`${ge("toolbar.pan")} (H)`,children:n.jsx(v.NiceIcon,{name:"move",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="addEdge"?"primary":"ghost",size:"sm",onClick:()=>e("addEdge"),title:`${ge("toolbar.addEdge")} (C)`,children:n.jsx(v.NiceIcon,{name:"link",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="text"?"primary":"ghost",size:"sm",onClick:()=>e("text"),title:"Text (T)",children:n.jsx(v.NiceIcon,{name:"type",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="freehand"?"primary":"ghost",size:"sm",onClick:()=>e("freehand"),title:"Freehand (F)",children:n.jsx(v.NiceIcon,{name:"pen",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="delete"?"primary":"ghost",size:"sm",onClick:()=>e("delete"),title:`${ge("toolbar.delete")} (Del)`,children:n.jsx(v.NiceIcon,{name:"trash",size:14})})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="addNode"?"primary":"ghost",size:"sm",onClick:()=>Le(H=>!H),title:ge("toolbar.addNode"),children:[n.jsx(v.NiceIcon,{name:"plus",size:14})," ",ge("toolbar.addNode")]}),at&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown nice-diagram-toolbar__dropdown--shapes",children:st.map(H=>n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>nt(H),children:[n.jsx(v.NiceIcon,{name:Ri(H),size:14})," ",H]},H))})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:X,title:"Copy (Ctrl+C)",children:n.jsx(v.NiceIcon,{name:"copy",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:G,title:"Paste (Ctrl+V)",children:n.jsx(v.NiceIcon,{name:"clipboard",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:U,title:"Duplicate (Ctrl+D)",children:n.jsx(v.NiceIcon,{name:"layers",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:J,title:"Select All (Ctrl+A)",children:n.jsx(v.NiceIcon,{name:"check-square",size:14})})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:o,disabled:!s,title:`${ge("toolbar.undo")} (Ctrl+Z)`,children:n.jsx(v.NiceIcon,{name:"undo",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:c,disabled:!l,title:`${ge("toolbar.redo")} (Ctrl+Y)`,children:n.jsx(v.NiceIcon,{name:"redo",size:14})})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:m,title:ge("toolbar.zoomOut"),children:n.jsx(v.NiceIcon,{name:"minus",size:14})}),n.jsxs("span",{className:"nice-diagram-toolbar__zoom-label",children:[Math.round(g*100),"%"]}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:d,title:ge("toolbar.zoomIn"),children:n.jsx(v.NiceIcon,{name:"plus",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:p,title:ge("toolbar.zoomReset"),children:"1:1"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:de,title:"Find (Ctrl+F)",children:n.jsx(v.NiceIcon,{name:"search",size:14})}),V&&n.jsx(v.NiceTextInput,{className:"nice-diagram-toolbar__search",placeholder:"Search nodes…",value:Y,onChange:H=>ue==null?void 0:ue(H),autoFocus:!0})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>be(H=>!H),title:ge("toolbar.export"),children:[n.jsx(v.NiceIcon,{name:"download",size:14})," ",ge("toolbar.export")]}),Fe&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("ndd"),be(!1)},children:".ndd.json"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("svg"),be(!1)},children:"SVG"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("mermaid"),be(!1)},children:"Mermaid"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("png"),be(!1)},children:"PNG"})]})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__row nice-diagram-toolbar__format-bar",children:[n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceSelect,{className:"nice-diagram-toolbar__font-select",value:M,onChange:H=>S==null?void 0:S(H),options:Ti.map(H=>({value:H,label:H})),title:"Font Family"}),n.jsx(v.NiceSelect,{className:"nice-diagram-toolbar__size-select",value:String(N),onChange:H=>I==null?void 0:I(Number(H)),options:Pi.map(H=>({value:String(H),label:String(H)})),title:"Font Size"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:w?"primary":"ghost",size:"sm",onClick:h,title:"Bold (Ctrl+B)",children:n.jsx("strong",{children:"B"})}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:y?"primary":"ghost",size:"sm",onClick:x,title:"Italic (Ctrl+I)",children:n.jsx("em",{children:"I"})})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>we(H=>!H),title:"Alignment & Distribution",children:"≡ Align"}),We&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown nice-diagram-toolbar__dropdown--align",children:[n.jsx("div",{className:"nice-diagram-toolbar__dropdown-section",children:"Align"}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{k==null||k(),we(!1)},title:"Align Left",children:[n.jsx(v.NiceIcon,{name:"align-left",size:14})," Left"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{T==null||T(),we(!1)},title:"Align Center",children:[n.jsx(v.NiceIcon,{name:"align-center",size:14})," Center"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{L==null||L(),we(!1)},title:"Align Right",children:[n.jsx(v.NiceIcon,{name:"align-right",size:14})," Right"]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{O==null||O(),we(!1)},title:"Align Top",children:[n.jsx(v.NiceIcon,{name:"align-top",size:14})," Top"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{F==null||F(),we(!1)},title:"Align Middle",children:[n.jsx(v.NiceIcon,{name:"align-middle",size:14})," Middle"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{W==null||W(),we(!1)},title:"Align Bottom",children:[n.jsx(v.NiceIcon,{name:"align-bottom",size:14})," Bottom"]})]}),n.jsx("div",{className:"nice-diagram-toolbar__dropdown-section",children:"Distribute"}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{C==null||C(),we(!1)},title:"Distribute Horizontally",children:[n.jsx(v.NiceIcon,{name:"distribute-h",size:14})," H"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{E==null||E(),we(!1)},title:"Distribute Vertically",children:[n.jsx(v.NiceIcon,{name:"distribute-v",size:14})," V"]})]})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>$e(H=>!H),title:"Arrange",children:[n.jsx(v.NiceIcon,{name:"menu",size:14})," Arrange"]}),ot&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown",children:[n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{P==null||P(),$e(!1)},children:"↑ Bring to Front"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{q==null||q(),$e(!1)},children:"↓ Send to Back"}),n.jsx("div",{className:"nice-diagram-toolbar__dropdown-divider"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{R==null||R(),$e(!1)},disabled:ne<2,children:"⊞ Group"}),n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{$==null||$(),$e(!1)},children:"⊟ Ungroup"})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>Se(H=>!H),title:ge("toolbar.layout"),children:["⊞ ",ge("toolbar.layout")]}),Me&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown",children:Di.map(H=>n.jsx(v.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>Ge(H),children:ge(`layout.${H}`)},H))})]}),ne>1&&n.jsxs("span",{className:"nice-diagram-toolbar__selection-info",children:[ne," selected"]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:fe==="editor"?"primary":"ghost",size:"sm",onClick:()=>ae==null?void 0:ae("editor"),title:"Editor Mode",children:[n.jsx(v.NiceIcon,{name:"edit",size:14})," Editor"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:fe==="player"?"primary":"ghost",size:"sm",onClick:()=>ae==null?void 0:ae("player"),title:"Player Mode",children:[n.jsx(v.NiceIcon,{name:"play",size:14})," Player"]}),n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:fe==="playerAnimated"?"primary":"ghost",size:"sm",onClick:()=>ae==null?void 0:ae("playerAnimated"),title:"Animated Player Mode",children:[n.jsx(v.NiceIcon,{name:"zap",size:14})," Animated"]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(v.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>qe(H=>!H),title:"Style Presets",children:[n.jsx(v.NiceIcon,{name:"palette",size:14})," Style"]}),Be&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown nice-diagram-toolbar__dropdown--presets",style:{maxHeight:320,overflowY:"auto",width:220},children:Object.entries(Ze.reduce((H,Ae)=>{const ye=Ae.category??"Other";return H[ye]||(H[ye]=[]),H[ye].push(Ae),H},{})).map(([H,Ae])=>n.jsxs("div",{children:[n.jsx("div",{className:"nice-diagram-toolbar__dropdown-section",style:{fontSize:10,color:"var(--nice-text-secondary, #888)",padding:"6px 8px 2px",textTransform:"uppercase"},children:H}),Ae.map(ye=>n.jsxs(v.NiceButton,{className:`nice-diagram-toolbar__dropdown-item ${Ce===ye.id?"nice-diagram-toolbar__dropdown-item--active":""}`,variant:Ce===ye.id?"primary":"ghost",size:"sm",onClick:()=>{Te==null||Te(ye.id),qe(!1)},style:{display:"flex",alignItems:"center",gap:8},children:[n.jsx("span",{style:{width:16,height:16,borderRadius:3,background:ye.config.palette.primary,border:"1px solid "+(ye.config.palette.border??"var(--nice-border, #ccc)"),display:"inline-block",flexShrink:0}}),n.jsx("span",{style:{fontSize:12},children:ye.name})]},ye.id))]},H))})]})]})]})};function Ri(r){switch(r){case"rectangle":return"square";case"roundedRect":return"card";case"ellipse":return"circle";case"circle":return"circle";case"diamond":return"diamond";case"hexagon":return"hexagon";case"parallelogram":return"parallelogram";case"cylinder":return"database";case"triangle":return"triangle";case"cloud":return"cloud";case"document":return"file";case"actor":return"user";default:return"card"}}tt.displayName="DiagramToolbar";const Oi=[{target:".nice-diagram-editor",titleKey:"tutorial.diagramEditor.intro.title",title:"Diagram editor",contentKey:"tutorial.diagramEditor.intro.content",content:"Pick a tool to add and connect nodes on the canvas, edit them in the property panel, and export the diagram from the toolbar.",placement:"auto"}],Wt=({initialDocument:r,diagramType:e="flowchart",onChange:t,onExport:i,lang:a="en",showToolbar:o=!0,showPropertyPanel:c=!0,showMinimap:s=!0,showTimeline:l=!0,className:u,style:d,tutorial:m})=>{var de;const p=Lt(r),[g,h]=b.useState("select"),[x,w]=b.useState(null),y=b.useRef(null),[S,M]=b.useState("editor"),I=b.useRef(null),[N,k]=b.useState({particles:[],liquidFlows:new Map,glowStates:new Map});b.useEffect(()=>{const V=new At(Y=>{k(Y)});return I.current=V,V.start(),()=>{V.stop(),I.current=null}},[]),b.useEffect(()=>{var Y;const V=I.current;if(V)for(const ue of p.edges)(Y=ue.style.liquidFlow)!=null&&Y.active?V.startLiquidFlow(ue.id,ue.style.liquidFlow):V.stopLiquidFlow(ue.id)},[p.edges]),b.useEffect(()=>{const V=I.current;if(V)for(const Y of p.nodes)Y.style.glowColor?V.setGlow(Y.id,Y.style.glowColor,Y.style.glowIntensity??1):V.removeGlow(Y.id)},[p.nodes]);const T=b.useCallback(V=>{p.setStylePreset(V)},[p]),L=b.useCallback((V,Y)=>{const ue=p.nodes.find(ae=>ae.id===V);if(!(ue!=null&&ue.interactions))return;const fe=ue.interactions.find(ae=>ae.id===Y);if(fe)switch(fe.action){case"reveal":{if(fe.targetId){const ae=p.nodes.find(Ce=>Ce.id===fe.targetId);ae!=null&&ae.hidden&&p.updateNode(fe.targetId,{hidden:!1})}break}case"navigate":{if(fe.targetId){const ae=p.nodes.find(Ce=>Ce.id===fe.targetId);ae&&(p.setViewport({x:-ae.position.x+300,y:-ae.position.y+200,zoom:p.viewport.zoom}),w(fe.targetId))}break}case"switchAnimationMode":{fe.targetId&&p.setActiveAnimationMode(fe.targetId);break}case"highlight":{fe.targetId&&w(fe.targetId);break}case"toggleCollapse":{p.toggleNodeCollapse(V);break}}},[p]),O=b.useRef(p.document);p.document!==O.current&&(O.current=p.document,t==null||t(p.document));const F=b.useMemo(()=>x?p.nodes.find(V=>V.id===x)??null:null,[x,p.nodes]),W=b.useMemo(()=>x?p.edges.find(V=>V.id===x)??null:null,[x,p.edges]),C=b.useCallback(V=>{const Y=p.viewport,ue=(-Y.x+400)/Y.zoom,fe=(-Y.y+300)/Y.zoom,ae=p.addNode("New Node",{x:ue,y:fe},V);w(ae.id),h("select")},[p]),E=b.useCallback(V=>{p.applyLayout({algorithm:V,centerGraph:!0})},[p]),P=b.useCallback((V,Y)=>{p.moveNode(V,Y)},[p]),q=b.useCallback((V,Y)=>{p.moveNode(V,Y)},[p]),R=b.useCallback(V=>{p.nodes.find(Y=>Y.id===V)?p.removeNode(V):p.edges.find(Y=>Y.id===V)&&p.removeEdge(V),w(null)},[p]),$=b.useCallback(V=>{const Y=p.document;let ue;switch(V){case"ndd":ue=Rt(Y,!0);break;case"svg":ue=ft(Y);break;case"mermaid":ue=Tt(Y);break;case"png":ue=ft(Y);break}i==null||i(V,ue)},[p,i]),X=b.useCallback(()=>{p.setViewport({...p.viewport,zoom:Math.min(5,p.viewport.zoom*1.2)})},[p]),G=b.useCallback(()=>{p.setViewport({...p.viewport,zoom:Math.max(.1,p.viewport.zoom/1.2)})},[p]),U=b.useCallback(()=>{p.setViewport({x:0,y:0,zoom:1})},[p]),J=b.useMemo(()=>[...p.nodes.map(V=>({id:V.id,label:V.label,type:"node"})),...p.edges.map(V=>({id:V.id,label:V.label??V.id,type:"edge"}))],[p.nodes,p.edges]),ne=o||p.animationModes.length>0?n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,width:"100%"},children:[o&&n.jsx(tt,{activeTool:g,onToolChange:h,diagramType:p.document.diagramType,onAddNode:C,onApplyLayout:E,onUndo:p.undo,onRedo:p.redo,canUndo:p.canUndo,canRedo:p.canRedo,onExport:$,onZoomIn:X,onZoomOut:G,onZoomReset:U,viewMode:S,onViewModeChange:M,stylePresetId:p.stylePresetId,onStylePresetChange:T}),p.animationModes.length>0&&n.jsxs("div",{className:"nice-diagram-editor__mode-tabs",style:{display:"flex",gap:4,padding:"4px 8px",fontSize:12,alignItems:"center"},children:[n.jsx("span",{style:{color:"var(--nice-text-secondary, #888)",marginRight:4},children:"Modes:"}),p.animationModes.map(V=>{var Y;return n.jsx(v.NiceButton,{variant:((Y=p.activeAnimationMode)==null?void 0:Y.id)===V.id?"primary":"ghost",size:"sm",onClick:()=>p.setActiveAnimationMode(V.id),style:{padding:"2px 10px",fontSize:11},children:V.name},V.id)}),n.jsx(v.NiceButton,{variant:"ghost",size:"sm",onClick:()=>p.addAnimationMode(`Mode ${p.animationModes.length+1}`),style:{padding:"2px 8px",fontSize:11,color:"var(--nice-text-secondary, #888)"},title:"Add animation mode",children:"+"})]})]}):void 0;return n.jsx(pt,{locale:a,children:n.jsxs(v.NiceAppShell,{ref:y,flush:!0,className:`nice-diagram-editor ${u??""}`,style:{position:"relative",...d},toolbar:ne,rightSidebar:c?n.jsx("div",{className:"nice-diagram-editor__panel",style:{width:260,overflowY:"auto",height:"100%"},children:n.jsx(et,{selectedNode:F,selectedEdge:W,onNodeChange:p.updateNode,onEdgeChange:p.updateEdge,onRemove:R})}):void 0,bottomPanel:l?n.jsx("div",{className:"nice-diagram-editor__timeline",children:n.jsx(Ke,{animations:p.animations,onAdd:p.addAnimation,onRemove:p.removeAnimation,availableTargets:J})}):void 0,children:[n.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:n.jsx(v.NiceTutorialButton,{steps:v.resolveTutorial(m,Oi)})}),n.jsxs("div",{className:"nice-diagram-editor__canvas",style:{height:"100%",position:"relative"},children:[n.jsx(ve,{nodes:p.nodes,edges:p.edges,groups:p.groups,viewport:p.viewport,onViewportChange:p.setViewport,selectedId:x,onSelectElement:w,onNodeDrag:P,onNodeDragEnd:q,interactive:S==="editor",showGrid:S==="editor",particleState:N,viewMode:S,ghostOpacity:((de=p.playerConfig)==null?void 0:de.ghostOpacity)??.3,onGroupCollapse:p.toggleGroupCollapse,onNodeCollapse:p.toggleNodeCollapse,onInteraction:L}),s&&n.jsx("div",{style:{position:"absolute",bottom:8,left:8},children:n.jsx(Qe,{nodes:p.nodes,edges:p.edges,viewport:p.viewport,onViewportChange:p.setViewport})})]})]})})};Wt.displayName="NiceDiagramEditor";const Ct={linear:r=>r,easeIn:r=>r*r,easeOut:r=>r*(2-r),easeInOut:r=>r<.5?2*r*r:-1+(4-2*r)*r,spring:r=>1-Math.cos(r*Math.PI*.5)*Math.exp(-6*r),bounce:r=>{if(r<1/2.75)return 7.5625*r*r;if(r<2/2.75){const t=r-.5454545454545454;return 7.5625*t*t+.75}if(r<2.5/2.75){const t=r-.8181818181818182;return 7.5625*t*t+.9375}const e=r-2.625/2.75;return 7.5625*e*e+.984375}};function Bt(r){return Ct[r]??Ct.linear}const qt={opacity:1,scale:1,translateX:0,translateY:0,glow:0,highlightColor:"",strokeProgress:1,rippleRadius:0,rippleOpacity:0,typewriterChars:-1,liquidFillProgress:-1,particleTrailT:-1};class Gt{constructor(e,t){this.startTime=0,this.playing=!1,this.rafId=0,this.stateMap=new Map,this.tick=()=>{if(!this.playing)return;const i=performance.now()-this.startTime;this.stateMap.clear();let a=!1;for(const o of this.animations){const c=o.startMs+(o.delayMs??0);c+o.durationMs;const s=o.repeat??0;let l=i-c;if(l<0){this.stateMap.set(o.targetId,Li(o)),a=!0;continue}if(s===-1)l=l%o.durationMs,a=!0;else if(s>0){const p=o.durationMs*(s+1);if(l>p)continue;l=l%o.durationMs,a=!0}else{if(l>o.durationMs)continue;a=!0}const u=Math.min(l/o.durationMs,1),d=Bt(o.easing)(u),m=Ei(o,d);this.stateMap.set(o.targetId,m)}this.onFrame(this.stateMap),a?this.rafId=requestAnimationFrame(this.tick):this.playing=!1},this.animations=[...e].sort((i,a)=>i.startMs-a.startMs),this.onFrame=t}play(){this.playing||(this.playing=!0,this.startTime=performance.now(),this.tick())}stop(){this.playing=!1,this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=0,this.stateMap.clear(),this.onFrame(this.stateMap)}pause(){this.playing=!1,this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=0}isPlaying(){return this.playing}}function Ei(r,e){const t={...qt};switch(r.effect){case"fadeIn":t.opacity=e;break;case"fadeOut":t.opacity=1-e;break;case"slideInLeft":t.translateX=-200*(1-e),t.opacity=e;break;case"slideInRight":t.translateX=200*(1-e),t.opacity=e;break;case"slideInTop":t.translateY=-200*(1-e),t.opacity=e;break;case"slideInBottom":t.translateY=200*(1-e),t.opacity=e;break;case"zoomIn":t.scale=e,t.opacity=e;break;case"zoomOut":t.scale=1-e*.5,t.opacity=1-e;break;case"pulse":t.scale=1+.15*Math.sin(e*Math.PI*2);break;case"shake":t.translateX=10*Math.sin(e*Math.PI*6)*(1-e);break;case"highlight":t.highlightColor=`rgba(255, 200, 0, ${.6*(1-Math.abs(2*e-1))})`;break;case"flowPulse":t.opacity=1,t.translateX=e;break;case"bounce":t.translateY=-40*Math.abs(Math.sin(e*Math.PI*3))*(1-e);break;case"glow":t.glow=12*Math.sin(e*Math.PI);break;case"colorShift":t.highlightColor=`hsl(${e*360}, 70%, 60%)`;break;case"liquidFill":t.liquidFillProgress=e;break;case"expand":t.scale=e,t.opacity=e;break;case"collapse":t.scale=1-e,t.opacity=1-e;break;case"ripple":t.rippleRadius=e*40,t.rippleOpacity=1-e;break;case"typewriter":t.typewriterChars=Math.floor(e*100);break;case"morphShape":t.scale=1+.1*Math.sin(e*Math.PI*4)*(1-e),t.translateX=2*Math.sin(e*Math.PI*3)*(1-e);break;case"drawPath":t.strokeProgress=e;break;case"particleTrail":t.particleTrailT=e;break}return t}function Li(r){const e={...qt};switch(r.effect){case"fadeIn":case"slideInLeft":case"slideInRight":case"slideInTop":case"slideInBottom":case"zoomIn":case"expand":e.opacity=0;break;case"drawPath":e.strokeProgress=0;break;case"typewriter":e.typewriterChars=0;break;case"liquidFill":e.liquidFillProgress=0;break}return e}function Fi(r){return{rectangle:"rectangle",roundedRect:"roundedRect",ellipse:"ellipse",circle:"circle",diamond:"diamond",hexagon:"hexagon",cylinder:"cylinder",cloud:"cloud",triangle:"triangle"}[r||"rectangle"]||"rectangle"}function Wi(r){return r?{backgroundColor:r.fill,borderColor:r.stroke,borderWidth:r.strokeWidth,fontColor:r.fontColor,fontSize:r.fontSize,borderRadius:r.borderRadius,borderStyle:r.strokeDasharray?"dashed":"solid"}:{}}function Bi(r){if(!r)return{};let e="straight";return r.lineType==="orthogonal"?e="orthogonal":r.lineType==="curved"||r.lineType==="bezier"?e="bezier":r.lineType==="step"&&(e="step"),{strokeColor:r.stroke,strokeWidth:r.strokeWidth,strokeDash:r.strokeDasharray?r.strokeDasharray.split(",").map(Number):void 0,lineType:e,sourceArrow:"none",targetArrow:r.arrowHead?"arrow":"none",opacity:r.opacity}}function qi(r){if(r)return{backgroundColor:r.fill,borderColor:r.stroke,borderWidth:r.strokeWidth}}function Vt(r){return{id:r.id,label:r.label,position:{x:r.x,y:r.y},size:{width:r.width,height:r.height},shape:Fi(r.shape),style:Wi(r.style),ports:(r.ports||[]).map((e,t)=>({id:e.id,side:e.position||"right",offset:.5})),data:r.data}}function Yt(r,e){var c,s;const t=e.find(l=>l.id===r.source),i=e.find(l=>l.id===r.target),a=r.sourcePort||((c=t==null?void 0:t.ports[0])==null?void 0:c.id)||`${r.source}-out`,o=r.targetPort||((s=i==null?void 0:i.ports[0])==null?void 0:s.id)||`${r.target}-in`;return{id:r.id,sourceNodeId:r.source,sourcePortId:a,targetNodeId:r.target,targetPortId:o,label:r.label,style:Bi(r.style),data:r.data}}function Xt(r){return{id:r.id,label:r.label,nodeIds:r.nodeIds,style:qi(r.style)}}function Ut(r){var e;return{id:r.id,name:r.id,targetId:r.targetId||((e=r.targets)==null?void 0:e[0])||"",targetType:"node",effect:r.type==="highlight"?"highlight":"fadeIn",startMs:r.delay,durationMs:r.duration,easing:"easeInOut"}}function je(r){const e=r.nodes.map(Vt);return e.forEach((t,i)=>{t.ports.length===0&&(t.ports=[{id:`${t.id}-out`,side:"right",offset:.5},{id:`${t.id}-in`,side:"left",offset:.5},{id:`${t.id}-top`,side:"top",offset:.5},{id:`${t.id}-bottom`,side:"bottom",offset:.5}])}),{version:"1.0",id:r.id,title:r.title,diagramType:r.diagramType,nodes:e,edges:r.edges.map(t=>Yt(t,e)),groups:(r.groups||[]).map(Xt),animations:(r.animations||[]).map(Ut),viewport:{x:0,y:0,zoom:1},metadata:{createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),...r.metadata}}}const Gi=je({id:"empty",title:"",diagramType:"flowchart",nodes:[],edges:[]}),yt=({document:r=Gi,lang:e="en",autoPlay:t=!1,showControls:i,showGrid:a,showWorkspace:o=!1,className:c,style:s})=>{const l=i??o,u=a??o,[d,m]=b.useState({...r.viewport}),[p,g]=b.useState(new Map),[h,x]=b.useState(!1),w=b.useRef(null),y=b.useCallback(()=>{w.current&&w.current.stop();const k=new Gt(r.animations,T=>{g(new Map(T)),k.isPlaying()||x(!1)});w.current=k,k.play(),x(!0)},[r.animations]),S=b.useCallback(()=>{var k;(k=w.current)==null||k.stop(),x(!1),g(new Map)},[]);b.useEffect(()=>(t&&r.animations.length>0&&y(),()=>{var k;(k=w.current)==null||k.stop()}),[t]);const M=b.useCallback(()=>m(k=>({...k,zoom:Math.min(5,k.zoom*1.2)})),[]),I=b.useCallback(()=>m(k=>({...k,zoom:Math.max(.1,k.zoom/1.2)})),[]),N=b.useCallback(()=>m({x:0,y:0,zoom:1}),[]);return n.jsx(pt,{locale:e,children:n.jsxs("div",{className:`nice-diagram-viewer ${c??""}`,style:{display:"flex",flexDirection:"column",height:"100%",...s},children:[l&&n.jsx(Vi,{isPlaying:h,hasAnimations:r.animations.length>0,onPlay:y,onStop:S,onZoomIn:M,onZoomOut:I,onZoomReset:N}),n.jsx("div",{style:{flex:1,position:"relative"},children:n.jsx(ve,{nodes:r.nodes,edges:r.edges,groups:r.groups,viewport:d,onViewportChange:m,theme:r.theme,animationStates:p,interactive:!1,showGrid:u})})]})})},Vi=({isPlaying:r,hasAnimations:e,onPlay:t,onStop:i,onZoomIn:a,onZoomOut:o,onZoomReset:c})=>{const{t:s}=Ee();return n.jsxs("div",{className:"nice-diagram-viewer__controls",style:{display:"flex",gap:4,padding:"4px 8px",borderBottom:"1px solid var(--nice-border, #ddd)",background:"var(--nice-bg-secondary, #fafafa)"},children:[e&&(r?n.jsxs(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:i,children:[n.jsx(v.NiceIcon,{name:"stop",size:14})," ",s("animation.stop")]}):n.jsxs(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:t,children:[n.jsx(v.NiceIcon,{name:"play",size:14})," ",s("animation.play")]})),n.jsx("span",{style:{flex:1}}),n.jsx(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:a,"aria-label":"Zoom in",children:n.jsx(v.NiceIcon,{name:"plus",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:o,"aria-label":"Zoom out",children:n.jsx(v.NiceIcon,{name:"minus",size:14})}),n.jsx(v.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:c,children:"1:1"})]})};yt.displayName="NiceDiagramViewer";const Yi="_cell_16e1i_9",Xi="_expandable_16e1i_29",Ui="_svg_16e1i_57",Hi="_emptyText_16e1i_67",Ji="_badge_16e1i_79",Zi="_expandIcon_16e1i_117",Ki="_modalOverlay_16e1i_169",Qi="_modalContent_16e1i_217",ea="_modalHeader_16e1i_267",ta="_modalTitle_16e1i_285",ra="_modalClose_16e1i_299",ia="_modalBody_16e1i_337",aa="_modalSvg_16e1i_357",oa="_modalFooter_16e1i_371",sa="_modalInfo_16e1i_389",xe={cell:Yi,expandable:Xi,svg:Ui,emptyText:Hi,badge:Ji,expandIcon:Zi,modalOverlay:Ki,modalContent:Qi,modalHeader:ea,modalTitle:ta,modalClose:ra,modalBody:ia,modalSvg:aa,modalFooter:oa,modalInfo:sa},na=120,ca=48,la=4,Mt={default:"var(--nice-primary, #3b82f6)",process:"var(--nice-success, #22c55e)",decision:"var(--nice-warning, #f59e0b)",start:"var(--nice-info, #6366f1)",end:"var(--nice-danger, #ef4444)",data:"var(--nice-accent, #8b5cf6)",custom:"var(--nice-text-secondary, #64748b)"};function bt(r){if(r.length===0)return{minX:0,minY:0,maxX:100,maxY:100,width:100,height:100};let e=1/0,t=1/0,i=-1/0,a=-1/0;for(const o of r){const c=o.position.x,s=o.position.y,l=o.position.x+o.size.width,u=o.position.y+o.size.height;c<e&&(e=c),s<t&&(t=s),l>i&&(i=l),u>a&&(a=u)}return{minX:e,minY:t,maxX:i,maxY:a,width:i-e,height:a-t}}function Ht(r){var t;if((t=r.style)!=null&&t.backgroundColor)return r.style.backgroundColor;const e=r.shape??"default";return Mt[e]??Mt.default}function Jt(r,e){const t=e.get(r.sourceNodeId),i=e.get(r.targetNodeId);if(!t||!i)return null;const a=t.position.x+t.size.width/2,o=t.position.y+t.size.height/2,c=i.position.x+i.size.width/2,s=i.position.y+i.size.height/2;return`M ${a} ${o} L ${c} ${s}`}function da(r,e){const t=bt(r);return{version:"1.0",id:`mini-diagram-${Date.now()}`,title:"Mini Diagram",diagramType:"flowchart",nodes:r,edges:e,groups:[],viewport:{x:t.minX-20,y:t.minY-20,zoom:1},animations:[],metadata:{createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}}}const ua=({document:r,onClose:e})=>{const t=bt(r.nodes),i=40,a=t.width+i*2,o=t.height+i*2,c=b.useMemo(()=>new Map(r.nodes.map(s=>[s.id,s])),[r.nodes]);return n.jsx("div",{className:xe.modalOverlay,onClick:e,children:n.jsxs("div",{className:xe.modalContent,onClick:s=>s.stopPropagation(),children:[n.jsxs("div",{className:xe.modalHeader,children:[n.jsx("h3",{className:xe.modalTitle,children:r.title||"Diagram"}),n.jsx("button",{className:xe.modalClose,onClick:e,children:n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",children:n.jsx("path",{d:"M15 5L5 15M5 5L15 15",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),n.jsx("div",{className:xe.modalBody,children:n.jsxs("svg",{viewBox:`${t.minX-i} ${t.minY-i} ${a} ${o}`,className:xe.modalSvg,children:[r.edges.map(s=>{var u,d,m;const l=Jt(s,c);return l?n.jsx("path",{d:l,stroke:((u=s.style)==null?void 0:u.strokeColor)??"var(--nice-text-secondary, #64748b)",strokeWidth:((d=s.style)==null?void 0:d.strokeWidth)??1.5,fill:"none",markerEnd:(m=s.style)!=null&&m.targetArrow&&s.style.targetArrow!=="none"?"url(#arrowhead-modal)":void 0},s.id):null}),r.nodes.map(s=>{var l,u;return n.jsxs("g",{children:[n.jsx("rect",{x:s.position.x,y:s.position.y,width:s.size.width,height:s.size.height,rx:((l=s.style)==null?void 0:l.borderRadius)??4,fill:Ht(s),stroke:((u=s.style)==null?void 0:u.borderColor)??"var(--nice-text, #1e293b)",strokeWidth:1}),n.jsx("text",{x:s.position.x+s.size.width/2,y:s.position.y+s.size.height/2,textAnchor:"middle",dominantBaseline:"middle",fill:"var(--nice-text-on-primary, #fff)",fontSize:12,fontFamily:"system-ui, sans-serif",children:s.label.substring(0,30)})]},s.id)}),n.jsx("defs",{children:n.jsx("marker",{id:"arrowhead-modal",markerWidth:"10",markerHeight:"7",refX:"9",refY:"3.5",orient:"auto",children:n.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"var(--nice-text-secondary, #64748b)"})})})]})}),n.jsx("div",{className:xe.modalFooter,children:n.jsxs("span",{className:xe.modalInfo,children:[r.nodes.length," nodes • ",r.edges.length," edges"]})})]})})},fa=({document:r,nodes:e,edges:t,width:i=na,height:a=ca,showCount:o=!0,expandable:c=!0,onExpand:s,padding:l=la,backgroundColor:u="transparent",borderRadius:d=4,showLabels:m=!1,edgeColor:p="var(--nice-text-muted, #94a3b8)",tooltip:g})=>{const[h,x]=b.useState(!1),w=b.useMemo(()=>r||(e||t?da(e??[],t??[]):null),[r,e,t]),y=b.useMemo(()=>w?new Map(w.nodes.map(T=>[T.id,T])):new Map,[w]),{bounds:S,scale:M,translateX:I,translateY:N}=b.useMemo(()=>{if(!w||w.nodes.length===0)return{bounds:{minX:0,minY:0,width:100,height:100},scale:1,translateX:0,translateY:0};const T=bt(w.nodes),L=i-l*2,O=a-l*2,F=L/T.width,W=O/T.height,C=Math.min(F,W,1),E=T.width*C,P=T.height*C,q=(i-E)/2-T.minX*C,R=(a-P)/2-T.minY*C;return{bounds:T,scale:C,translateX:q,translateY:R}},[w,i,a,l]),k=b.useCallback(()=>{!w||!c||(s?s(w):x(!0))},[w,c,s]);return!w||w.nodes.length===0?n.jsx("div",{className:xe.cell,style:{width:i,height:a,backgroundColor:u,borderRadius:d},title:g,children:n.jsx("span",{className:xe.emptyText,children:"—"})}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`${xe.cell} ${c?xe.expandable:""}`,style:{width:i,height:a,backgroundColor:u,borderRadius:d},onClick:k,title:g??`${w.nodes.length} nodes, ${w.edges.length} edges`,children:[n.jsx("svg",{width:i,height:a,viewBox:`0 0 ${i} ${a}`,className:xe.svg,children:n.jsxs("g",{transform:`translate(${I}, ${N}) scale(${M})`,children:[w.edges.map(T=>{const L=Jt(T,y);return L?n.jsx("path",{d:L,stroke:p,strokeWidth:1/M,fill:"none"},T.id):null}),w.nodes.map(T=>{const L=Ht(T);return n.jsxs("g",{children:[n.jsx("rect",{x:T.position.x,y:T.position.y,width:T.size.width,height:T.size.height,rx:Math.min(4,T.size.width/4),fill:L}),m&&M>.3&&n.jsx("text",{x:T.position.x+T.size.width/2,y:T.position.y+T.size.height/2,textAnchor:"middle",dominantBaseline:"middle",fill:"var(--nice-text-on-primary, #fff)",fontSize:10/M,fontFamily:"system-ui, sans-serif",children:T.label.substring(0,5)})]},T.id)})]})}),o&&n.jsx("span",{className:xe.badge,children:w.nodes.length}),c&&n.jsx("span",{className:xe.expandIcon,children:n.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",children:n.jsx("path",{d:"M2 10V7M2 10h3M2 10l4-4M10 2v3M10 2H7M10 2L6 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})]}),h&&w&&n.jsx(ua,{document:w,onClose:()=>x(!1)})]})};function Zt(r,e,t="roundedRect"){const i=[],a=[],o=new Map;for(const c of r){const s=String(c[e.nodeMapping.idField]??"");if(!s)continue;const l=String(c[e.nodeMapping.labelField]??s),u=e.nodeMapping.descriptionField?String(c[e.nodeMapping.descriptionField]??""):void 0,d=e.nodeMapping.iconField?String(c[e.nodeMapping.iconField]??""):void 0,m=e.nodeMapping.colorField?String(c[e.nodeMapping.colorField]??""):void 0,p={id:`data_${s}`,label:l,description:u,icon:d,position:{x:0,y:0},size:{width:180,height:70},shape:t,style:m?{backgroundColor:m}:{},ports:[{id:"top",side:"top",offset:.5},{id:"right",side:"right",offset:.5},{id:"bottom",side:"bottom",offset:.5},{id:"left",side:"left",offset:.5}],data:c};i.push(p),o.set(s,p)}if(e.nodeMapping.parentField)for(const c of r){const s=String(c[e.nodeMapping.idField]??""),l=String(c[e.nodeMapping.parentField]??"");if(!s||!l)continue;const u=o.get(s),d=o.get(l);!u||!d||a.push({id:`edge_${l}_${s}`,sourceNodeId:d.id,sourcePortId:"bottom",targetNodeId:u.id,targetPortId:"top",style:{lineType:"orthogonal",targetArrow:"arrow"}})}if(e.edgeMapping)for(const c of r){const s=String(c[e.edgeMapping.sourceField]??""),l=String(c[e.edgeMapping.targetField]??"");if(!s||!l)continue;const u=o.get(s),d=o.get(l);if(!u||!d)continue;const m=e.edgeMapping.labelField?String(c[e.edgeMapping.labelField]??""):void 0;a.push({id:`edge_${s}_${l}`,sourceNodeId:u.id,sourcePortId:"right",targetNodeId:d.id,targetPortId:"left",label:m,style:{lineType:"bezier",targetArrow:"arrow"}})}return{nodes:i,edges:a}}async function ha(r,e,t){const i=await fetch(r.sourceUrl,{signal:t});if(!i.ok)throw new Error(`Failed to fetch data: ${i.status} ${i.statusText}`);const a=await i.json(),o=Array.isArray(a)?a:a.value??[];return Zt(o,r,e)}const pa={pending:"var(--nice-text-muted, #9ca3af)",active:"var(--nice-primary, #3b82f6)",completed:"var(--nice-success, #10b981)",failed:"var(--nice-danger, #ef4444)",skipped:"var(--nice-warning, #f59e0b)",waiting:"var(--nice-accent, #8b5cf6)"},ma={start:"ellipse",end:"ellipse",task:"rectangle",decision:"diamond",parallel:"rectangle",join:"rectangle",subprocess:"rectangle",timer:"ellipse",message:"rectangle",error:"rectangle"},ga={start:"play",end:"stop",task:"clipboard",decision:"help",parallel:"columns",join:"git-branch",subprocess:"box",timer:"clock",message:"mail",error:"warning"},ya=({data:r,onStepClick:e,onTransitionClick:t,autoPlay:i=!1,animationDelay:a=1e3,showTooltips:o=!0,showMinimap:c=!0,statusColors:s=pa,typeShapes:l=ma,direction:u="horizontal",className:d,style:m})=>{const[p,g]=b.useState(0),h=b.useMemo(()=>{const S=r.steps.map((N,k)=>{const T=N.id===r.currentStepId,L=N.status||"pending",O=s[L],F=l[N.type],W=u==="horizontal"?k*200:100,C=u==="horizontal"?100:k*150;return{id:N.id,label:N.name,x:W,y:C,width:150,height:60,shape:F,style:{fill:O,stroke:T?"var(--nice-text, #1f2937)":O,strokeWidth:T?3:1,fontColor:"var(--nice-text-on-primary, #fff)",fontSize:12},data:{type:N.type,status:N.status,assignee:N.assignee,dueDate:N.dueDate,icon:ga[N.type],...N.metadata},ports:[{id:`${N.id}-in`,position:"left"},{id:`${N.id}-out`,position:"right"}]}}),M=r.transitions.map(N=>{const k=r.steps.find(O=>O.id===N.from),T=r.steps.find(O=>O.id===N.to);let L="var(--nice-text-muted, #9ca3af)";return(k==null?void 0:k.status)==="completed"&&(T==null?void 0:T.status)!=="pending"?L="var(--nice-success, #10b981)":(k==null?void 0:k.status)==="failed"&&(L="var(--nice-danger, #ef4444)"),{id:N.id,source:N.from,target:N.to,sourcePort:`${N.from}-out`,targetPort:`${N.to}-in`,label:N.label||N.condition,style:{stroke:L,strokeWidth:2,arrowHead:"arrow",lineType:"bezier"},data:{condition:N.condition}}}),I=i?ba(r.steps):[];return je({id:r.id,title:r.name,diagramType:"flowchart",nodes:S,edges:M,animations:I,metadata:{type:"workflow",...r.metadata}})},[r,s,l,u,i]);b.useEffect(()=>{if(!i)return;const S=r.steps.filter(I=>I.status==="completed").length;if(p>=S)return;const M=setTimeout(()=>{g(I=>I+1)},a);return()=>clearTimeout(M)},[i,p,a,r.steps]),b.useCallback(S=>{if(!e)return;const M=r.steps.find(I=>I.id===S);M&&e(M)},[r.steps,e]);const[x,w]=b.useState({x:0,y:0,zoom:1}),y=b.useCallback(S=>{if(S&&e){const M=r.steps.find(I=>I.id===S);M&&e(M)}if(S&&t){const M=r.transitions.find(I=>I.id===S);M&&t(M)}},[r.steps,r.transitions,e,t]);return n.jsx("div",{className:`nice-workflow-visualizer ${d||""}`,style:{position:"relative",width:"100%",height:"100%",...m},children:n.jsx(ve,{nodes:h.nodes,edges:h.edges,groups:h.groups,viewport:x,onViewportChange:w,onSelectElement:y,showGrid:!0})})};function ba(r){return r.filter(t=>t.status==="completed").map((t,i)=>({id:`anim-${t.id}`,targetId:t.id,type:"highlight",delay:i*500,duration:300,easing:"ease-out"}))}function xa(r){var o,c;const t=new DOMParser().parseFromString(r,"text/xml"),i=[],a=[];return t.querySelectorAll("startEvent").forEach(s=>{i.push({id:s.getAttribute("id")||`start-${i.length}`,name:s.getAttribute("name")||"Start",type:"start"})}),t.querySelectorAll("task, userTask, serviceTask").forEach(s=>{i.push({id:s.getAttribute("id")||`task-${i.length}`,name:s.getAttribute("name")||"Task",type:"task"})}),t.querySelectorAll("exclusiveGateway, parallelGateway").forEach(s=>{const l=s.tagName==="parallelGateway";i.push({id:s.getAttribute("id")||`gateway-${i.length}`,name:s.getAttribute("name")||(l?"Parallel":"Decision"),type:l?"parallel":"decision"})}),t.querySelectorAll("endEvent").forEach(s=>{i.push({id:s.getAttribute("id")||`end-${i.length}`,name:s.getAttribute("name")||"End",type:"end"})}),t.querySelectorAll("sequenceFlow").forEach(s=>{a.push({id:s.getAttribute("id")||`flow-${a.length}`,from:s.getAttribute("sourceRef")||"",to:s.getAttribute("targetRef")||"",label:s.getAttribute("name")||void 0})}),{id:((o=t.querySelector("process"))==null?void 0:o.getAttribute("id"))||"workflow",name:((c=t.querySelector("process"))==null?void 0:c.getAttribute("name"))||"Workflow",steps:i,transitions:a}}function va(r,e){const t=[],i=[];t.push({id:"start",name:"Start",type:"start",status:"completed"}),r.forEach((a,o)=>{t.push({id:`step-${o}`,name:a,type:"task",status:"pending"})}),t.push({id:"end",name:"End",type:"end",status:"pending"}),i.push({id:"start-to-first",from:"start",to:"step-0"});for(let a=0;a<r.length-1;a++)i.push({id:`step-${a}-to-${a+1}`,from:`step-${a}`,to:`step-${a+1}`});return i.push({id:"last-to-end",from:`step-${r.length-1}`,to:"end"}),{id:"linear-workflow",name:"Linear Workflow",steps:t,transitions:i}}const wa={dbo:"var(--nice-primary, #3b82f6)",public:"var(--nice-success, #10b981)",auth:"var(--nice-accent, #8b5cf6)",billing:"var(--nice-warning, #f59e0b)",audit:"var(--nice-danger, #ef4444)"},ka={"one-to-one":{left:"1",right:"1"},"one-to-many":{left:"1",right:"*"},"many-to-one":{left:"*",right:"1"},"many-to-many":{left:"*",right:"*"}},_a=({schema:r,onTableClick:e,onColumnClick:t,onRelationClick:i,showColumnDetails:a=!0,showOnlyKeys:o=!1,highlightTables:c=[],showMinimap:s=!0,schemaColors:l=wa,layout:u="auto",maxColumnsDisplay:d=15,className:m,style:p})=>{const[g,h]=b.useState(null),x=b.useMemo(()=>{const M=Na(r.tables,u),I=r.tables.map((k,T)=>{const L=M[k.name]||{x:T%4*300,y:Math.floor(T/4)*400},O=c.includes(k.name),F=g===k.name,W=l[k.schema||"dbo"]||"var(--nice-text-secondary, #6b7280)";let C=k.columns;o&&(C=C.filter(R=>R.primaryKey||R.foreignKey)),C.length>d&&(C=C.slice(0,d));const E=40,P=a?28:20,q=E+C.length*P+10;return{id:k.name,label:k.schema?`${k.schema}.${k.name}`:k.name,x:L.x,y:L.y,width:250,height:q,shape:"rectangle",style:{fill:O||F?W:"var(--nice-bg, #fff)",stroke:W,strokeWidth:F?3:O?2:1,fontColor:O||F?"var(--nice-text-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:14,borderRadius:8},data:{type:"table",schema:k.schema,columns:C.map(R=>({...R,icon:Ca(R)})),totalColumns:k.columns.length,truncated:k.columns.length>d,comment:k.comment,...k.metadata},ports:[...k.columns.filter(R=>R.primaryKey).map(R=>({id:`${k.name}.${R.name}-pk`,position:"left"})),...k.columns.filter(R=>R.foreignKey).map(R=>({id:`${k.name}.${R.name}-fk`,position:"right"}))]}}),N=r.relations.map(k=>{const T=ka[k.type];return{id:k.id,source:k.fromTable,target:k.toTable,sourcePort:`${k.fromTable}.${k.fromColumn}-fk`,targetPort:`${k.toTable}.${k.toColumn}-pk`,label:k.name||`${T.left}─${T.right}`,style:{stroke:"var(--nice-text-secondary, #6b7280)",strokeWidth:1.5,arrowHead:Ma(k.type),arrowTail:Sa(k.type),lineType:"orthogonal",strokeDasharray:k.type==="many-to-many"?"5,5":void 0},data:{type:k.type,fromColumn:k.fromColumn,toColumn:k.toColumn}}});return je({id:`schema-${r.name}`,title:r.name,diagramType:"er",nodes:I,edges:N,metadata:{type:"er-diagram",...r.metadata}})},[r,a,o,c,g,l,u,d]);b.useCallback(M=>{if(h(I=>I===M?null:M),e){const I=r.tables.find(N=>N.name===M);I&&e(I)}},[r.tables,e]),b.useCallback(M=>{if(!i)return;const I=r.relations.find(N=>N.id===M);I&&i(I)},[r.relations,i]);const[w,y]=b.useState({x:0,y:0,zoom:1}),S=b.useCallback(M=>{if(M){if(h(I=>I===M?null:M),e){const I=r.tables.find(N=>N.name===M);I&&e(I)}if(i){const I=r.relations.find(N=>N.id===M);I&&i(I)}}},[r.tables,r.relations,e,i]);return n.jsx("div",{className:`nice-database-schema-viewer ${m||""}`,style:{position:"relative",width:"100%",height:"100%",...p},children:n.jsx(ve,{nodes:x.nodes,edges:x.edges,groups:x.groups,viewport:w,onViewportChange:y,onSelectElement:S,showGrid:!0})})};function Na(r,e){const t={};if(e==="grid"){const i=Math.ceil(Math.sqrt(r.length));r.forEach((a,o)=>{t[a.name]={x:o%i*320+50,y:Math.floor(o/i)*450+50}})}else if(e==="hierarchical"){const i={};r.forEach(o=>{const c=o.schema||"default";i[c]||(i[c]=[]),i[c].push(o)});let a=50;Object.entries(i).forEach(([o,c])=>{c.forEach((s,l)=>{t[s.name]={x:l*320+50,y:a}}),a+=500})}else r.forEach((i,a)=>{const o=a/r.length*2*Math.PI,c=300+r.length*20;t[i.name]={x:Math.cos(o)*c+500,y:Math.sin(o)*c+400}});return t}function Ca(r){return r.primaryKey?"lock":r.foreignKey?"link":r.unique?"zap":"file"}function Ma(r){switch(r){case"one-to-one":case"many-to-one":return"none";case"one-to-many":case"many-to-many":return"crow"}}function Sa(r){switch(r){case"one-to-one":case"one-to-many":return"none";case"many-to-one":case"many-to-many":return"crow"}}function Ia(r){const e=[],t=[],i=/CREATE\s+TABLE\s+(?:`?(\w+)`?\.)?`?(\w+)`?\s*\(([\s\S]*?)\);/gi;let a;for(;(a=i.exec(r))!==null;){const o=a[1]||"dbo",c=a[2],s=a[3],l=[],u=/`?(\w+)`?\s+(\w+(?:\([^)]+\))?)\s*(NOT\s+NULL|NULL)?/gi;let d;for(;(d=u.exec(s))!==null;)l.push({name:d[1],type:d[2],nullable:!d[3]||d[3].toUpperCase()!=="NOT NULL"});const m=/PRIMARY\s+KEY\s*\(`?(\w+)`?\)/i.exec(s);if(m){const h=l.find(x=>x.name===m[1]);h&&(h.primaryKey=!0)}const p=/FOREIGN\s+KEY\s*\(`?(\w+)`?\)\s*REFERENCES\s+`?(\w+)`?\s*\(`?(\w+)`?\)/gi;let g;for(;(g=p.exec(s))!==null;){const h=g,x=l.find(w=>w.name===h[1]);x&&(x.foreignKey={table:h[2],column:h[3]},t.push({id:`fk-${c}-${h[1]}`,fromTable:c,fromColumn:h[1],toTable:h[2],toColumn:h[3],type:"many-to-one"}))}e.push({name:c,schema:o,columns:l})}return{name:"Parsed Schema",tables:e,relations:t}}function za(r,e="postgres"){const t=[];for(const i of r.tables){const a=i.schema?`${i.schema}.${i.name}`:i.name;t.push(`CREATE TABLE ${a} (`);const o=i.columns.map(s=>{let l=` ${s.name} ${s.type}`;return s.nullable||(l+=" NOT NULL"),s.primaryKey&&(l+=" PRIMARY KEY"),s.unique&&(l+=" UNIQUE"),s.defaultValue&&(l+=` DEFAULT ${s.defaultValue}`),l}),c=i.columns.filter(s=>s.foreignKey).map(s=>` FOREIGN KEY (${s.name}) REFERENCES ${s.foreignKey.table}(${s.foreignKey.column})`);t.push([...o,...c].join(`,
|
|
4
4
|
`)),t.push(`);
|
|
5
5
|
`)}return t.join(`
|
|
6
|
-
`)}const za={active:"var(--nice-success, #10b981)",away:"var(--nice-warning, #f59e0b)",busy:"var(--nice-danger, #ef4444)",offline:"var(--nice-text-secondary, #6b7280)",vacation:"var(--nice-accent, #8b5cf6)",leave:"var(--nice-primary, #3b82f6)"},Ue=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"],ja=({data:r,rootEmployeeId:e,onEmployeeClick:t,onDepartmentClick:i,showAvatars:a=!0,showContactInfo:o=!1,groupByDepartment:c=!0,collapsedDepartments:s=[],maxLevels:l=0,orientation:u="vertical",spacing:d={horizontal:200,vertical:150},statusColors:m=za,showMinimap:p=!0,className:g,style:h})=>{const[x,w]=b.useState(new Set),[y,S]=b.useState(null),M=b.useMemo(()=>{var F;if(e)return e;const O=r.employees.find(W=>!W.managerId);return(O==null?void 0:O.id)||((F=r.employees[0])==null?void 0:F.id)},[r.employees,e]),I=b.useMemo(()=>Aa(r.employees,M),[r.employees,M]),N=b.useMemo(()=>{const O=$a(I,u,d,l),F=[],W={};c&&r.departments&&r.departments.forEach((q,R)=>{const $=q.color||Ue[R%Ue.length];W[q.id]=$;const X=r.employees.filter(G=>G.department===q.id);X.length!==0&&F.push({id:`dept-${q.id}`,label:q.name,nodeIds:X.map(G=>G.id),style:{fill:`${$}15`,stroke:$,strokeWidth:2},data:{department:q}})});const C=[],E=[],P=(q,R=0)=>{if(l>0&&R>=l||q.employee.department&&s.includes(q.employee.department))return;const $=O[q.employee.id]||{x:0,y:0},X=y===q.employee.id,G=q.employee.status||"active",U=q.employee.department?W[q.employee.department]:"var(--nice-text-secondary, #6b7280)",J=180,ne=o?120:a?90:70;C.push({id:q.employee.id,label:q.employee.name,x:$.x,y:$.y,width:J,height:ne,shape:"rectangle",style:{fill:X?U:"var(--nice-bg, #fff)",stroke:U,strokeWidth:X?3:1,fontColor:X?"var(--nice-text-on-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:13,borderRadius:12},data:{type:"employee",employee:q.employee,statusColor:m[G],hasChildren:q.children.length>0,childrenCount:q.children.length}}),q.employee.managerId&&E.push({id:`rel-${q.employee.managerId}-${q.employee.id}`,source:q.employee.managerId,target:q.employee.id,style:{stroke:"var(--nice-border, #cbd5e1)",strokeWidth:2,arrowHead:"none",lineType:u==="vertical"?"orthogonal":"curved"}}),q.children.forEach(de=>P(de,R+1))};return I&&P(I),Ae({id:"org-chart",title:"Organization Chart",diagramType:"orgchart",nodes:C,edges:E,groups:F,metadata:{type:"org-chart",...r.metadata}})},[r,I,u,d,l,c,s,a,o,m,y]);b.useCallback(O=>{if(S(F=>F===O?null:O),w(F=>{const W=new Set(F);return W.has(O)?W.delete(O):W.add(O),W}),t){const F=r.employees.find(W=>W.id===O);F&&t(F)}},[r.employees,t]),b.useCallback(O=>{if(!i||!r.departments)return;const F=O.replace("dept-",""),W=r.departments.find(C=>C.id===F);W&&i(W)},[r.departments,i]);const[k,T]=b.useState({x:0,y:0,zoom:1}),L=b.useCallback(O=>{if(O&&(S(F=>F===O?null:O),t)){const F=r.employees.find(W=>W.id===O);F&&t(F)}},[r.employees,t]);return n.jsx("div",{className:`nice-org-chart-visualizer ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:n.jsx(ve,{nodes:N.nodes,edges:N.edges,groups:N.groups,viewport:k,onViewportChange:T,onSelectElement:L,showGrid:!1})})};function Aa(r,e){const i=new Map(r.map(o=>[o.id,o])).get(e);if(!i)return null;const a=(o,c)=>{const s=r.filter(l=>l.managerId===o.id);return{employee:o,children:s.map(l=>a(l,c+1)),level:c}};return a(i,0)}function $a(r,e,t,i){const a={};if(!r)return a;const o=(l,u)=>i>0&&u>=i?0:l.children.length===0?1:l.children.reduce((d,m)=>d+o(m,u+1),0),c=(l,u,d,m)=>{if(i>0&&u>=i)return;const p=d+m*t.horizontal/2,g=u*t.vertical+50;a[l.employee.id]=e==="vertical"?{x:p,y:g}:{x:g,y:p};let h=d;l.children.forEach(x=>{const w=o(x,u+1);c(x,u+1,h,w),h+=w*t.horizontal})},s=o(r,0);return c(r,0,0,s),a}function Da(r){const t=[...new Set(r.map(i=>i.department).filter(Boolean))].map((i,a)=>({id:i,name:i,color:Ue[a%Ue.length],headcount:r.filter(o=>o.department===i).length}));return{employees:r,departments:t}}function Ta(r){var s;const e=new Set(r.employees.map(l=>l.managerId).filter(Boolean)),t=(l,u=new Set)=>{if(u.has(l))return 0;u.add(l);const d=r.employees.find(m=>m.id===l);return d!=null&&d.managerId?1+t(d.managerId,u):1},i=r.employees.map(l=>t(l.id)),a=Math.max(...i,0),o=Array.from(e).map(l=>r.employees.filter(u=>u.managerId===l).length),c=o.length>0?o.reduce((l,u)=>l+u,0)/o.length:0;return{totalEmployees:r.employees.length,departmentCount:((s=r.departments)==null?void 0:s.length)||0,maxDepth:a,averageSpan:Math.round(c*10)/10,managers:e.size}}const Pa=({data:r,onActivityClick:e,onTransitionClick:t,minEdgeFrequency:i=.05,showFrequency:a=!0,showDuration:o=!0,highlightBottlenecks:c=!0,bottleneckThreshold:s=.9,colorScheme:l="frequency",activityColors:u,layout:d="hierarchical",animationSpeed:m=0,showMinimap:p=!0,className:g,style:h})=>{const[x,w]=b.useState(null),y=b.useMemo(()=>"activities"in r?r:Kt(r),[r]),S=b.useMemo(()=>{if(!c)return new Set;const L=y.activities.filter(F=>F.avgDuration!==void 0).map(F=>F.avgDuration);if(L.length===0)return new Set;L.sort((F,W)=>F-W);const O=L[Math.floor(L.length*s)]||0;return new Set(y.activities.filter(F=>(F.avgDuration||0)>=O).map(F=>F.name))},[y.activities,c,s]),M=b.useMemo(()=>{const L=Math.max(...y.activities.map(P=>P.frequency),1),O=Ra(y,d),F=y.transitions.filter(P=>P.frequency/y.totalCases>=i),W=y.activities.map(P=>{const q=O[P.name]||{x:0,y:0},R=y.startActivities.includes(P.name),$=y.endActivities.includes(P.name),X=S.has(P.name),G=x===P.name,U=Ea(P,l,L,u,X);return{id:P.name,label:P.name,x:q.x,y:q.y,width:140,height:60,shape:R?"ellipse":$?"roundedRect":"rectangle",style:{fill:G?U:"var(--nice-bg, #fff)",stroke:U,strokeWidth:X?4:G?3:2,fontColor:G?"var(--nice-text-on-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:12,borderRadius:$?20:8},data:{type:"activity",activity:P,isStart:R,isEnd:$,isBottleneck:X,frequencyPercent:Math.round(P.frequency/y.totalCases*100)}}}),C=F.map(P=>{const q=y.transitions.indexOf(P),R=P.probability||P.frequency/y.totalCases,$=R>.5,X=[];return a&&X.push(`${P.frequency}x`),o&&P.avgDuration&&X.push(La(P.avgDuration)),{id:`trans-${q}`,source:P.from,target:P.to,label:X.join(" | "),style:{stroke:$?"var(--nice-primary, #3b82f6)":"var(--nice-text-muted, #9ca3af)",strokeWidth:Math.max(1,Math.min(6,R*8)),arrowHead:"triangle",lineType:"curved",opacity:Math.max(.3,R)},data:{type:"transition",transition:P,probability:R}}}),E=m>0?Fa(y,m):[];return Ae({id:"process-mining",title:"Process Mining Diagram",diagramType:"flowchart",nodes:W,edges:C,animations:E,metadata:{type:"process-mining",totalCases:y.totalCases,avgCaseDuration:y.avgCaseDuration}})},[y,i,a,o,c,S,l,u,d,m,x]);b.useCallback(L=>{if(w(O=>O===L?null:L),e){const O=y.activities.find(F=>F.name===L);O&&e(O)}},[y.activities,e]);const I=b.useCallback(L=>{if(!t)return;const O=parseInt(L.replace("trans-",""),10),F=y.transitions[O];F&&t(F)},[y.transitions,t]),[N,k]=b.useState({x:0,y:0,zoom:1}),T=b.useCallback(L=>{if(L){if(L.startsWith("trans-")){I(L);return}if(w(O=>O===L?null:L),e){const O=y.activities.find(F=>F.name===L);O&&e(O)}}},[y.activities,e,I]);return n.jsx("div",{className:`nice-process-mining-diagram ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:n.jsx(ve,{nodes:M.nodes,edges:M.edges,groups:M.groups,viewport:N,onViewportChange:k,onSelectElement:T,showGrid:!0})})};function Ra(r,e){const t={};if(e==="circular"){const i=r.activities;i.forEach((a,o)=>{const c=o/i.length*2*Math.PI-Math.PI/2,s=200+i.length*15;t[a.name]={x:Math.cos(c)*s+400,y:Math.sin(c)*s+300}})}else{const i=Oa(r),a={};r.activities.forEach(c=>{const s=i[c.name]||0;a[s]=(a[s]||0)+1});const o={};r.activities.forEach(c=>{const s=i[c.name]||0,l=o[s]||0;o[s]=l+1;const u=a[s],d=(l-(u-1)/2)*180;t[c.name]={x:400+d,y:50+s*120}})}return t}function Oa(r){const e={},t=new Set,i=r.startActivities.map(a=>({activity:a,level:0}));for(;i.length>0;){const{activity:a,level:o}=i.shift();if(t.has(a))continue;t.add(a),e[a]=o,r.transitions.filter(s=>s.from===a).forEach(s=>{t.has(s.to)||i.push({activity:s.to,level:o+1})})}return r.activities.forEach(a=>{e[a.name]===void 0&&(e[a.name]=0)}),e}function Ea(r,e,t,i,a){if(a)return"var(--nice-danger, #ef4444)";if(i!=null&&i[r.name])return i[r.name];const o=r.frequency/t;switch(e){case"frequency":return ut("var(--nice-success, #10b981)","var(--nice-primary, #3b82f6)",o);case"duration":return r.avgDuration?ut("var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)",o):"var(--nice-text-secondary, #6b7280)";case"cost":return r.avgCost?ut("var(--nice-success, #10b981)","var(--nice-danger, #ef4444)",o):"var(--nice-text-secondary, #6b7280)";default:return"var(--nice-primary, #3b82f6)"}}function ut(r,e,t){const i=u=>{const d=/#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})\b/i.exec(u);return d?{r:parseInt(d[1],16),g:parseInt(d[2],16),b:parseInt(d[3],16)}:{r:0,g:0,b:0}},a=i(r),o=i(e),c=Math.round(a.r+(o.r-a.r)*t),s=Math.round(a.g+(o.g-a.g)*t),l=Math.round(a.b+(o.b-a.b)*t);return`#${[c,s,l].map(u=>u.toString(16).padStart(2,"0")).join("")}`}function La(r){return r<1e3?`${r}ms`:r<6e4?`${(r/1e3).toFixed(1)}s`:r<36e5?`${(r/6e4).toFixed(1)}m`:r<864e5?`${(r/36e5).toFixed(1)}h`:`${(r/864e5).toFixed(1)}d`}function Fa(r,e){var i;const t=(i=r.variants)==null?void 0:i[0];return t?t.activities.map((a,o)=>({id:`flow-${o}`,type:"highlight",targets:[a],duration:e,delay:o*e})):[]}function Kt(r){const e=r.events.map(g=>({...g,timestamp:g.timestamp instanceof Date?g.timestamp:new Date(g.timestamp)})),t=new Map;e.forEach(g=>{t.has(g.caseId)||t.set(g.caseId,[]),t.get(g.caseId).push(g)}),t.forEach(g=>{g.sort((h,x)=>h.timestamp.getTime()-x.timestamp.getTime())});const i=new Map,a=new Map,o=new Set,c=new Set;t.forEach(g=>{if(g.length!==0){o.add(g[0].activity),c.add(g[g.length-1].activity);for(let h=0;h<g.length;h++){const x=g[h];i.has(x.activity)||i.set(x.activity,{frequency:0,durations:[],resources:new Set,costs:[]});const w=i.get(x.activity);if(w.frequency++,x.resource&&w.resources.add(x.resource),x.cost!==void 0&&w.costs.push(x.cost),h<g.length-1){const y=g[h+1],S=y.timestamp.getTime()-x.timestamp.getTime();w.durations.push(S);const M=`${x.activity}→${y.activity}`;a.has(M)||a.set(M,{frequency:0,durations:[]});const I=a.get(M);I.frequency++,I.durations.push(S)}}}});const s=Array.from(i.entries()).map(([g,h])=>({name:g,frequency:h.frequency,avgDuration:h.durations.length>0?h.durations.reduce((x,w)=>x+w,0)/h.durations.length:void 0,minDuration:h.durations.length>0?Math.min(...h.durations):void 0,maxDuration:h.durations.length>0?Math.max(...h.durations):void 0,resources:Array.from(h.resources),avgCost:h.costs.length>0?h.costs.reduce((x,w)=>x+w,0)/h.costs.length:void 0})),l=Array.from(a.entries()).map(([g,h])=>{const[x,w]=g.split("→");return{from:x,to:w,frequency:h.frequency,avgDuration:h.durations.length>0?h.durations.reduce((y,S)=>y+S,0)/h.durations.length:void 0,probability:h.frequency/t.size}}),u=new Map;t.forEach((g,h)=>{const x=g.map(y=>y.activity).join("→");u.has(x)||u.set(x,{caseIds:[],durations:[]});const w=u.get(x);if(w.caseIds.push(h),g.length>=2){const y=g[g.length-1].timestamp.getTime()-g[0].timestamp.getTime();w.durations.push(y)}});const d=Array.from(u.entries()).map(([g,h])=>({activities:g.split("→"),frequency:h.caseIds.length,avgDuration:h.durations.length>0?h.durations.reduce((x,w)=>x+w,0)/h.durations.length:0,caseIds:h.caseIds})).sort((g,h)=>h.frequency-g.frequency),m=Array.from(t.values()).filter(g=>g.length>=2).map(g=>g[g.length-1].timestamp.getTime()-g[0].timestamp.getTime()),p=m.length>0?m.reduce((g,h)=>g+h,0)/m.length:void 0;return{activities:s,transitions:l,variants:d,startActivities:Array.from(o),endActivities:Array.from(c),totalCases:t.size,avgCaseDuration:p}}const Qt={module:"var(--nice-primary, #3b82f6)",package:"var(--nice-success, #10b981)",microservice:"var(--nice-accent, #8b5cf6)",library:"var(--nice-warning, #f59e0b)",api:"var(--nice-color-accent-pink, #ec4899)",database:"var(--nice-info, #14b8a6)",external:"var(--nice-text-secondary, #6b7280)",deprecated:"var(--nice-danger, #ef4444)"},er={healthy:"var(--nice-success, #10b981)",warning:"var(--nice-warning, #f59e0b)",critical:"var(--nice-danger, #ef4444)",unknown:"var(--nice-text-secondary, #6b7280)",deprecated:"var(--nice-text-muted, #9ca3af)"},St={import:{color:"var(--nice-primary, #3b82f6)"},runtime:{color:"var(--nice-success, #10b981)"},dev:{color:"var(--nice-text-secondary, #6b7280)",dash:"5,5"},peer:{color:"var(--nice-warning, #f59e0b)",dash:"10,5"},"api-call":{color:"var(--nice-accent, #8b5cf6)"},database:{color:"var(--nice-info, #14b8a6)"},event:{color:"var(--nice-color-accent-pink, #ec4899)",dash:"2,2"},circular:{color:"var(--nice-danger, #ef4444)"}},Wa={module:"box",package:"folder",microservice:"square",library:"book",api:"plug",database:"database",external:"globe",deprecated:"warning"},Ba=({data:r,onNodeClick:e,onEdgeClick:t,visibleTypes:i,visibleEdgeTypes:a,highlightCircular:o=!0,showOnlyIssues:c=!1,layout:s="force",groupBy:l="type",nodeSizeBy:u="dependencies",colorScheme:d="type",nodeColors:m,showMetrics:p=!0,interactive:g=!0,showMinimap:h=!0,className:x,style:w})=>{const[y,S]=b.useState(null),[M,I]=b.useState(null),N=b.useMemo(()=>o?tr(r):new Set,[r,o]),k=b.useMemo(()=>{let C=r.nodes;return i&&i.length>0&&(C=C.filter(E=>i.includes(E.type))),c&&(C=C.filter(E=>{var P;return E.status==="critical"||E.status==="warning"||((P=E.metrics)==null?void 0:P.issues)&&E.metrics.issues>0})),C},[r.nodes,i,c]),T=b.useMemo(()=>{const C=new Set(k.map(P=>P.id));let E=r.edges.filter(P=>C.has(P.source)&&C.has(P.target));return a&&a.length>0&&(E=E.filter(P=>a.includes(P.type))),E},[r.edges,k,a]),L=b.useMemo(()=>{const C=qa(k,T,s),E=Va(k,u),P=[];if(l!=="none"){const $=new Map;k.forEach(G=>{const U=l==="type"?G.type:G.group||"ungrouped";$.has(U)||$.set(U,[]),$.get(U).push(G.id)});let X=0;$.forEach((G,U)=>{var ne,de;const J=l==="type"?Qt[U]||"var(--nice-text-secondary, #6b7280)":((de=(ne=r.groups)==null?void 0:ne.find(V=>V.id===U))==null?void 0:de.color)||He[X%He.length];P.push({id:`group-${U}`,label:U,nodeIds:G,style:{fill:`${J}10`,stroke:J,strokeWidth:1}}),X++})}const q=k.map($=>{const X=C[$.id]||{x:0,y:0},G=y===$.id,U=M===$.id,J=N.has($.id),ne=Ya($,u,E),de=Xa($,d,m,J);return{id:$.id,label:$.name,x:X.x,y:X.y,width:ne.width,height:ne.height,shape:Ua($.type),style:{fill:G||U?de:"var(--nice-bg, #fff)",stroke:de,strokeWidth:J?4:G?3:2,fontColor:G||U?"var(--nice-text-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:8,strokeDasharray:$.status==="deprecated"?"4,4":void 0},data:{type:"dependency",node:$,icon:Wa[$.type],isCircular:J,statusColor:er[$.status||"unknown"]}}}),R=T.map(($,X)=>{const G=$.type==="circular"||N.has($.source)&&N.has($.target),U=St[$.type]||St.import;return{id:$.id||`edge-${X}`,source:$.source,target:$.target,label:$.optional?"(optional)":void 0,style:{stroke:G?"var(--nice-danger, #ef4444)":U.color,strokeWidth:Math.max(1,Math.min(4,$.weight||1)),strokeDasharray:U.dash,arrowHead:"triangle",lineType:"curved",opacity:$.optional?.5:1},data:{type:$.type,edge:$,isCircular:G}}});return Ae({id:"dependency-graph",title:"Dependency Graph",diagramType:"custom",nodes:q,edges:R,groups:P,metadata:{type:"dependency-graph",...r.metadata}})},[k,T,s,l,r.groups,u,d,m,N,y,M]);b.useCallback(C=>{if(S(E=>E===C?null:C),e){const E=r.nodes.find(P=>P.id===C);E&&e(E)}},[r.nodes,e]),b.useCallback(C=>{if(!t)return;const E=r.edges.find(P=>P.id===C);E&&t(E)},[r.edges,t]),b.useCallback(C=>{I(C)},[]);const[O,F]=b.useState({x:0,y:0,zoom:1}),W=b.useCallback(C=>{if(C){if(S(E=>E===C?null:C),e){const E=r.nodes.find(P=>P.id===C);E&&e(E)}if(t){const E=r.edges.find(P=>P.id===C);E&&t(E)}}},[r.nodes,r.edges,e,t]);return n.jsx("div",{className:`nice-dependency-graph ${x||""}`,style:{position:"relative",width:"100%",height:"100%",...w},children:n.jsx(ve,{nodes:L.nodes,edges:L.edges,groups:L.groups,viewport:O,onViewportChange:F,onSelectElement:W,interactive:g,showGrid:!0})})},He=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"];function tr(r){const e=new Set,t=new Map;r.nodes.forEach(c=>t.set(c.id,[])),r.edges.forEach(c=>{var s;(s=t.get(c.source))==null||s.push(c.target)});const i=new Set,a=new Set,o=(c,s)=>{i.add(c),a.add(c),s.push(c);const l=t.get(c)||[];for(const u of l)if(i.has(u)){if(a.has(u)){const d=s.indexOf(u);s.slice(d).forEach(p=>e.add(p))}}else if(o(u,[...s]))return!0;return a.delete(c),!1};return r.nodes.forEach(c=>{i.has(c.id)||o(c.id,[])}),e}function qa(r,e,t){const i={};switch(t){case"circular":{r.forEach((a,o)=>{const c=o/r.length*2*Math.PI-Math.PI/2,s=150+r.length*12;i[a.id]={x:Math.cos(c)*s+400,y:Math.sin(c)*s+300}});break}case"grid":{const a=Math.ceil(Math.sqrt(r.length));r.forEach((o,c)=>{i[o.id]={x:c%a*200+100,y:Math.floor(c/a)*150+100}});break}case"hierarchical":{const a=Ga(r,e),o={},c={};r.forEach(s=>{const l=a[s.id]||0;o[l]=(o[l]||0)+1}),r.forEach(s=>{const l=a[s.id]||0,u=c[l]||0;c[l]=u+1;const d=o[l],m=(u-(d-1)/2)*200;i[s.id]={x:400+m,y:80+l*130}});break}default:{r.forEach((a,o)=>{const c=o/r.length*2*Math.PI,s=200+r.length*10;i[a.id]={x:Math.cos(c)*s+400,y:Math.sin(c)*s+300}});for(let a=0;a<50;a++){const o={};r.forEach(c=>o[c.id]={x:0,y:0});for(let c=0;c<r.length;c++)for(let s=c+1;s<r.length;s++){const l=r[c].id,u=r[s].id,d=i[u].x-i[l].x,m=i[u].y-i[l].y,p=Math.max(1,Math.sqrt(d*d+m*m)),g=5e3/(p*p);o[l].x-=d/p*g,o[l].y-=m/p*g,o[u].x+=d/p*g,o[u].y+=m/p*g}e.forEach(c=>{const s=i[c.target].x-i[c.source].x,l=i[c.target].y-i[c.source].y,u=Math.sqrt(s*s+l*l),d=u*.01;o[c.source].x+=s/u*d,o[c.source].y+=l/u*d,o[c.target].x-=s/u*d,o[c.target].y-=l/u*d}),r.forEach(c=>{i[c.id].x+=Math.max(-10,Math.min(10,o[c.id].x)),i[c.id].y+=Math.max(-10,Math.min(10,o[c.id].y))})}break}}return i}function Ga(r,e){const t={},i={};r.forEach(o=>{t[o.id]=0,i[o.id]=0}),e.forEach(o=>{i[o.target]=(i[o.target]||0)+1});const a=r.filter(o=>i[o.id]===0).map(o=>o.id);for(;a.length>0;){const o=a.shift();e.filter(s=>s.source===o).forEach(s=>{t[s.target]=Math.max(t[s.target],t[o]+1),i[s.target]--,i[s.target]===0&&a.push(s.target)})}return t}function Va(r,e){const t=r.map(i=>{var a,o,c;switch(e){case"dependencies":return((a=i.metrics)==null?void 0:a.dependencies)||0;case"dependents":return((o=i.metrics)==null?void 0:o.dependents)||0;case"complexity":return((c=i.metrics)==null?void 0:c.complexity)||0;case"size":return i.size||0;default:return 1}});return{min:Math.min(...t,0),max:Math.max(...t,1)}}function Ya(r,e,t){var l,u,d;if(e==="fixed")return{width:140,height:70};let i;switch(e){case"dependencies":i=((l=r.metrics)==null?void 0:l.dependencies)||0;break;case"dependents":i=((u=r.metrics)==null?void 0:u.dependents)||0;break;case"complexity":i=((d=r.metrics)==null?void 0:d.complexity)||0;break;case"size":i=r.size||0;break;default:i=1}const a=t.max>t.min?(i-t.min)/(t.max-t.min):.5,o=100,s=o+a*(180-o);return{width:s,height:s*.5}}function Xa(r,e,t,i){if(i)return"var(--nice-danger, #ef4444)";if(t!=null&&t[r.id])return t[r.id];switch(e){case"status":return er[r.status||"unknown"];case"group":return He[Ha(r.group||"")%He.length];default:return Qt[r.type]||"var(--nice-text-secondary, #6b7280)"}}function Ua(r){switch(r){case"database":return"cylinder";case"microservice":return"hexagon";case"api":return"diamond";case"external":return"cloud";default:return"rectangle"}}function Ha(r){let e=0;for(let t=0;t<r.length;t++)e=(e<<5)-e+r.charCodeAt(t),e|=0;return Math.abs(e)}function Ja(r){const e=[{id:r.name,name:r.name,version:r.version,type:"package",status:"healthy"}],t=[];let i=0;const a=(o,c)=>{o&&Object.entries(o).forEach(([s,l])=>{e.find(u=>u.id===s)||e.push({id:s,name:s,version:l.replace(/[\^~>=<]/g,""),type:"library",status:"unknown"}),t.push({id:`edge-${i++}`,source:r.name,target:s,type:c})})};return a(r.dependencies,"runtime"),a(r.devDependencies,"dev"),a(r.peerDependencies,"peer"),e.forEach(o=>{o.metrics={dependencies:t.filter(c=>c.source===o.id).length,dependents:t.filter(c=>c.target===o.id).length}}),{nodes:e,edges:t}}function Za(r){const e=new Map,t=new Map;r.nodes.forEach(d=>{e.set(d.id,0),t.set(d.id,0)}),r.edges.forEach(d=>{e.set(d.target,(e.get(d.target)||0)+1),t.set(d.source,(t.get(d.source)||0)+1)}),tr(r);let i=null,a=0;r.nodes.forEach(d=>{const m=e.get(d.id)||0;m>a&&(a=m,i=d)});let o=null,c=0;r.nodes.forEach(d=>{const m=t.get(d.id)||0;m>c&&(c=m,o=d)});const s=r.nodes.filter(d=>(e.get(d.id)||0)===0&&(t.get(d.id)||0)===0),l=Array.from(t.values()).reduce((d,m)=>d+m,0),u=r.nodes.length>0?l/r.nodes.length:0;return{totalNodes:r.nodes.length,totalEdges:r.edges.length,circularDependencies:[],mostDependent:i,mostDependencies:o,orphanNodes:s,avgDependencies:Math.round(u*10)/10}}const Ka={online:"var(--nice-success, #10b981)",offline:"var(--nice-text-secondary, #6b7280)",warning:"var(--nice-warning, #f59e0b)",critical:"var(--nice-danger, #ef4444)",maintenance:"var(--nice-primary, #3b82f6)",unknown:"var(--nice-text-muted, #9ca3af)"},Qa={router:"shuffle",switch:"plug",firewall:"lock",server:"server",workstation:"monitor",laptop:"monitor",phone:"phone",printer:"printer",camera:"camera",iot:"wifi",loadbalancer:"scale",storage:"database",cloud:"cloud",internet:"globe",unknown:"help"},eo={ethernet:"var(--nice-primary, #3b82f6)",fiber:"var(--nice-success, #10b981)",wireless:"var(--nice-accent, #8b5cf6)",vpn:"var(--nice-warning, #f59e0b)",wan:"var(--nice-color-accent-pink, #ec4899)",trunk:"var(--nice-info, #14b8a6)"},to=({data:r,onDeviceClick:e,onConnectionClick:t,onRefresh:i,autoRefreshInterval:a=0,visibleDeviceTypes:o,showOnlyIssues:c=!1,layout:s="hierarchical",groupBy:l="group",showMetrics:u=!0,showBandwidth:d=!0,showLatency:m=!1,animateTraffic:p=!1,statusColors:g=Ka,showMinimap:h=!0,className:x,style:w})=>{const[y,S]=b.useState(null),[M,I]=b.useState(new Date);b.useEffect(()=>{if(a<=0||!i)return;const W=setInterval(()=>{i(),I(new Date)},a);return()=>clearInterval(W)},[a,i]);const N=b.useMemo(()=>{let W=r.devices;return o&&o.length>0&&(W=W.filter(C=>o.includes(C.type))),c&&(W=W.filter(C=>C.status==="critical"||C.status==="warning"||C.status==="offline")),W},[r.devices,o,c]),k=b.useMemo(()=>{const W=new Set(N.map(C=>C.id));return r.connections.filter(C=>W.has(C.source)&&W.has(C.target))},[r.connections,N]),T=b.useMemo(()=>{const W=ro(N,k,s,r.groups),C=[];if(l!=="none"){const R=new Map;N.forEach(X=>{let G;switch(l){case"type":G=X.type;break;case"location":G=X.location||"Unknown Location";break;default:G=X.group||"ungrouped"}R.has(G)||R.set(G,[]),R.get(G).push(X.id)});let $=0;R.forEach((X,G)=>{var ne;const U=(ne=r.groups)==null?void 0:ne.find(de=>de.id===G||de.name===G),J=(U==null?void 0:U.color)||It[$%It.length];C.push({id:`group-${G}`,label:(U==null?void 0:U.name)||G,nodeIds:X,style:{fill:`${J}15`,stroke:J,strokeWidth:2}}),$++})}const E=N.map(R=>{const $=W[R.id]||{x:0,y:0},X=y===R.id,G=g[R.status],U=Qa[R.type];return{id:R.id,label:R.name,x:$.x,y:$.y,width:120,height:u?90:70,shape:io(R.type),style:{fill:X?G:"var(--nice-bg, #fff)",stroke:G,strokeWidth:X?3:2,fontColor:X?"var(--nice-text-on-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:8},data:{type:"network-device",device:R,icon:U,statusColor:G}}}),P=k.map((R,$)=>{const X=eo[R.type]||"var(--nice-text-secondary, #6b7280)",G=R.status==="active",U=R.status==="degraded"||R.status==="error",J=[];if(d&&R.bandwidth){const ne=Math.round(R.bandwidth.used/R.bandwidth.total*100);J.push(`${ne}%`)}return m&&R.latency!==void 0&&J.push(`${R.latency}ms`),{id:R.id||`conn-${$}`,source:R.source,target:R.target,sourcePort:R.sourcePort,targetPort:R.targetPort,label:J.join(" | ")||void 0,style:{stroke:U?"var(--nice-danger, #ef4444)":X,strokeWidth:Math.max(1,Math.min(6,(R.speed||1e3)/1e3)),strokeDasharray:G?void 0:"5,5",arrowHead:"none",lineType:R.type==="wireless"?"curved":"orthogonal",opacity:R.status==="inactive"?.3:1},data:{type:R.type,connection:R,isActive:G,isDegraded:U}}}),q=p?ao(k):[];return Ae({id:"network-topology",title:"Network Topology",diagramType:"networkTopology",nodes:E,edges:P,groups:C,animations:q,metadata:{type:"network-topology",lastRefresh:M.toISOString(),...r.metadata}})},[N,k,s,l,r.groups,u,d,m,p,g,y,M]);b.useCallback(W=>{if(S(C=>C===W?null:W),e){const C=r.devices.find(E=>E.id===W);C&&e(C)}},[r.devices,e]),b.useCallback(W=>{if(!t)return;const C=r.connections.find(E=>E.id===W);C&&t(C)},[r.connections,t]);const[L,O]=b.useState({x:0,y:0,zoom:1}),F=b.useCallback(W=>{if(W&&(S(C=>C===W?null:W),e)){const C=r.devices.find(E=>E.id===W);C&&e(C)}},[r.devices,e]);return n.jsx("div",{className:`nice-network-topology ${x||""}`,style:{position:"relative",width:"100%",height:"100%",...w},children:n.jsx(ve,{nodes:T.nodes,edges:T.edges,groups:T.groups,viewport:L,onViewportChange:O,onSelectElement:F,showGrid:!0})})},It=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"];function ro(r,e,t,i){var o;const a={};switch(t){case"star":{const c=new Map;r.forEach(d=>c.set(d.id,0)),e.forEach(d=>{c.set(d.source,(c.get(d.source)||0)+1),c.set(d.target,(c.get(d.target)||0)+1)});let s=(o=r[0])==null?void 0:o.id,l=0;c.forEach((d,m)=>{d>l&&(l=d,s=m)}),a[s]={x:400,y:300};const u=r.filter(d=>d.id!==s);u.forEach((d,m)=>{const p=m/u.length*2*Math.PI-Math.PI/2,g=200;a[d.id]={x:Math.cos(p)*g+400,y:Math.sin(p)*g+300}});break}case"mesh":{const c=Math.ceil(Math.sqrt(r.length));r.forEach((s,l)=>{a[s.id]={x:l%c*150+100,y:Math.floor(l/c)*130+100}});break}case"tree":{const c=r.filter(p=>p.type==="internet"||p.type==="cloud"||p.type==="router"),s=new Map,l=c.map(p=>p.id);l.forEach(p=>s.set(p,0));const u=new Set(l);for(;l.length>0;){const p=l.shift(),g=s.get(p)||0;e.forEach(h=>{let x=null;h.source===p&&!u.has(h.target)&&(x=h.target),h.target===p&&!u.has(h.source)&&(x=h.source),x&&(u.add(x),s.set(x,g+1),l.push(x))})}const d={},m={};r.forEach(p=>{const g=s.get(p.id)||0;d[g]=(d[g]||0)+1}),r.forEach(p=>{const g=s.get(p.id)||0,h=m[g]||0;m[g]=h+1;const x=d[g],w=(h-(x-1)/2)*160;a[p.id]={x:400+w,y:80+g*120}});break}case"hierarchical":default:{const c=["internet","cloud","router","firewall","loadbalancer","switch","server","storage","workstation","laptop","phone","printer","camera","iot","unknown"],s=new Map;r.forEach(u=>{s.has(u.type)||s.set(u.type,[]),s.get(u.type).push(u)});let l=50;c.forEach(u=>{const d=s.get(u);!d||d.length===0||(d.forEach((m,p)=>{const g=(p-(d.length-1)/2)*150;a[m.id]={x:400+g,y:l}}),l+=130)});break}}return a}function io(r){switch(r){case"router":case"switch":return"diamond";case"firewall":return"hexagon";case"server":case"storage":return"rectangle";case"cloud":case"internet":return"cloud";default:return"rectangle"}}function ao(r){return r.filter(e=>e.status==="active"&&e.bandwidth&&e.bandwidth.used>0).map((e,t)=>({id:`traffic-${t}`,type:"flow",targets:[e.id],duration:2e3,delay:t*200}))}async function oo(r={}){return console.log("Network discovery with options:",r),{devices:[{id:"internet",name:"Internet",type:"internet",status:"online"},{id:"router-1",name:"Edge Router",type:"router",ipAddress:"192.168.1.1",status:"online",metrics:{cpu:45,memory:60,latency:5}},{id:"firewall-1",name:"Firewall",type:"firewall",ipAddress:"192.168.1.2",status:"online",metrics:{cpu:30,memory:55}},{id:"switch-1",name:"Core Switch",type:"switch",ipAddress:"192.168.1.10",status:"online"},{id:"server-1",name:"Web Server",type:"server",ipAddress:"192.168.1.100",status:"online",metrics:{cpu:75,memory:80}},{id:"server-2",name:"Database Server",type:"server",ipAddress:"192.168.1.101",status:"warning",metrics:{cpu:90,memory:85}}],connections:[{id:"c1",source:"internet",target:"router-1",type:"wan",status:"active",speed:1e3},{id:"c2",source:"router-1",target:"firewall-1",type:"ethernet",status:"active",speed:1e4},{id:"c3",source:"firewall-1",target:"switch-1",type:"ethernet",status:"active",speed:1e4},{id:"c4",source:"switch-1",target:"server-1",type:"ethernet",status:"active",speed:1e4},{id:"c5",source:"switch-1",target:"server-2",type:"ethernet",status:"active",speed:1e4}]}}function so(r){const e=r.devices.filter(m=>m.status==="online").length,t=r.devices.filter(m=>m.status==="offline").length,i=r.devices.filter(m=>m.status==="warning").length,a=r.devices.filter(m=>m.status==="critical").length,o=r.connections.filter(m=>m.status==="active").length,c=r.connections.filter(m=>m.status==="degraded"||m.status==="error").length,s=r.devices.length>0?e/r.devices.length*100:0,l=r.connections.length>0?o/r.connections.length*100:0,u=a*10+i*5+c*5;return{score:Math.max(0,Math.min(100,Math.round(s*.5+l*.5-u))),onlineDevices:e,offlineDevices:t,warningDevices:i,criticalDevices:a,activeConnections:o,degradedConnections:c}}const no=[{target:".nice-decision-tree-editor",titleKey:"tutorial.decisionTreeEditor.intro.title",title:"Decision tree editor",contentKey:"tutorial.decisionTreeEditor.intro.content",content:"Explore the decision tree: click nodes to inspect conditions and outcomes, toggle metrics, probabilities and samples, and highlight a path for an input.",placement:"auto"}],co={root:"var(--nice-accent, #8b5cf6)",decision:"var(--nice-primary, #3b82f6)",leaf:"var(--nice-success, #10b981)",chance:"var(--nice-warning, #f59e0b)",end:"var(--nice-danger, #ef4444)"},lo=({data:r,onChange:e,onNodeClick:t,editable:i=!1,showMetrics:a=!0,showProbabilities:o=!0,showSamples:c=!0,highlightPath:s,colorScheme:l="outcome",nodeColors:u,orientation:d="vertical",spacing:m={horizontal:180,vertical:120},showMinimap:p=!0,className:g,style:h,tutorial:x})=>{const[w,y]=b.useState(null),[S,M]=b.useState(new Set),I=b.useMemo(()=>s?mo(r.root,s):new Set,[r.root,s]),{nodes:N,edges:k}=b.useMemo(()=>uo(r.root,r.edges),[r.root,r.edges]),T=b.useMemo(()=>ho(N),[N]),L=b.useMemo(()=>{var q,R;const C=fo(r.root,d,m),E=N.map($=>{const X=C[$.id]||{x:0,y:0},G=w===$.id,U=I.has($.id),J=$.type==="leaf"||$.type==="end",ne=po($,l,u,T),de=J?120:160,V=a?80:J?60:70;return{id:$.id,label:$.label,x:X.x,y:X.y,width:de,height:V,shape:J?"roundedRect":"diamond",style:{fill:G||U?ne:"var(--nice-bg, #fff)",stroke:ne,strokeWidth:U?4:G?3:2,fontColor:G||U?"var(--nice-text-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:J?8:0},data:{type:"decision-tree-node",node:$,isLeaf:J,isHighlighted:U}}}),P=k.map(($,X)=>{const G=I.has($.source)&&I.has($.target);let U=$.label||"";return o&&$.probability!==void 0&&(U+=U?` (${($.probability*100).toFixed(0)}%)`:`${($.probability*100).toFixed(0)}%`),{id:$.id||`edge-${X}`,source:$.source,target:$.target,label:U||void 0,style:{stroke:G?"var(--nice-primary, #3b82f6)":"var(--nice-text-muted, #9ca3af)",strokeWidth:G?3:2,arrowHead:"triangle",lineType:d==="vertical"?"orthogonal":"curved"},data:{type:"decision-edge",edge:$,isHighlighted:G}}});return Ae({id:"decision-tree",title:"Decision Tree",diagramType:"decisionTree",nodes:E,edges:P,animations:s?go(Array.from(I)):[],metadata:{type:"decision-tree",algorithm:(q=r.metadata)==null?void 0:q.algorithm,accuracy:(R=r.metadata)==null?void 0:R.accuracy}})},[N,k,d,m,a,o,l,u,T,w,I,s,r.metadata]);b.useCallback(C=>{y(P=>P===C?null:C);const E=N.find(P=>P.id===C);E&&E.type!=="leaf"&&E.type!=="end"&&M(P=>{const q=new Set(P);return q.has(C)?q.delete(C):q.add(C),q}),t&&E&&t(E)},[N,t]);const[O,F]=b.useState({x:0,y:0,zoom:1}),W=b.useCallback(C=>{if(!C)return;y(P=>P===C?null:C);const E=N.find(P=>P.id===C);E&&E.type!=="leaf"&&E.type!=="end"&&M(P=>{const q=new Set(P);return q.has(C)?q.delete(C):q.add(C),q}),t&&E&&t(E)},[N,t]);return n.jsxs("div",{className:`nice-decision-tree-editor ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:[n.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:n.jsx(v.NiceTutorialButton,{steps:v.resolveTutorial(x,no)})}),n.jsx(ve,{nodes:L.nodes,edges:L.edges,groups:L.groups,viewport:O,onViewportChange:F,onSelectElement:W,interactive:!0,showGrid:!1})]})};function uo(r,e){const t=[],i=e?[...e]:[],a=new Set(i.map(c=>`${c.source}-${c.target}`)),o=(c,s)=>{t.push(c),s&&!a.has(`${s}-${c.id}`)&&i.push({id:`e-${s}-${c.id}`,source:s,target:c.id}),c.children&&c.children.forEach((l,u)=>{let d="";c.condition&&(d=u===0?"Yes":"No");const m=`${c.id}-${l.id}`;a.has(m)||(i.push({id:`e-${m}`,source:c.id,target:l.id,label:d,branch:u===0?"yes":"no"}),a.add(m)),o(l,c.id)})};return o(r),{nodes:t,edges:i}}function fo(r,e,t){const i={},a=s=>!s.children||s.children.length===0?1:s.children.reduce((l,u)=>l+a(u),0),o=(s,l,u,d)=>{const m=u+d*t.horizontal/2,p=l*t.vertical+50;if(i[s.id]=e==="vertical"?{x:m,y:p}:{x:p,y:m},s.children){let g=u;s.children.forEach(h=>{const x=a(h);o(h,l+1,g,x),g+=x*t.horizontal})}},c=a(r);return o(r,0,0,c),i}function ho(r){const e=r.filter(i=>{var a;return((a=i.metrics)==null?void 0:a.impurity)!==void 0}).map(i=>i.metrics.impurity),t=r.filter(i=>{var a;return((a=i.metrics)==null?void 0:a.samples)!==void 0}).map(i=>i.metrics.samples);return{impurity:{min:Math.min(...e,0),max:Math.max(...e,1)},samples:{min:Math.min(...t,0),max:Math.max(...t,100)}}}function po(r,e,t,i){var a,o,c;if(t!=null&&t[r.id])return t[r.id];switch(e){case"impurity":if(((a=r.metrics)==null?void 0:a.impurity)!==void 0&&i){const s=(r.metrics.impurity-i.impurity.min)/(i.impurity.max-i.impurity.min||1);return zt("var(--nice-success, #10b981)","var(--nice-danger, #ef4444)",s)}break;case"samples":if(((o=r.metrics)==null?void 0:o.samples)!==void 0&&i){const s=(r.metrics.samples-i.samples.min)/(i.samples.max-i.samples.min||1);return zt("var(--nice-warning-bg, #fef3c7)","var(--nice-warning, #f59e0b)",s)}break;case"outcome":if(r.type==="leaf"&&((c=r.outcome)!=null&&c.class))return{positive:"var(--nice-success, #10b981)",negative:"var(--nice-danger, #ef4444)",true:"var(--nice-success, #10b981)",false:"var(--nice-danger, #ef4444)",yes:"var(--nice-success, #10b981)",no:"var(--nice-danger, #ef4444)"}[r.outcome.class.toLowerCase()]||"var(--nice-primary, #3b82f6)";break}return co[r.type]||"var(--nice-text-secondary, #6b7280)"}function zt(r,e,t){const i=u=>{var m;const d=((m=/#([a-f\d]{6})\b/i.exec(u))==null?void 0:m[1])??"000000";return{r:parseInt(d.slice(0,2),16),g:parseInt(d.slice(2,4),16),b:parseInt(d.slice(4,6),16)}},a=i(r),o=i(e),c=Math.round(a.r+(o.r-a.r)*t),s=Math.round(a.g+(o.g-a.g)*t),l=Math.round(a.b+(o.b-a.b)*t);return`#${[c,s,l].map(u=>u.toString(16).padStart(2,"0")).join("")}`}function mo(r,e){const t=new Set,i=a=>{if(t.add(a.id),a.type==="leaf"||a.type==="end"||!a.children)return!0;if(a.condition){const o=e[a.condition.feature],s=rr(o,a.condition.operator,a.condition.value)?0:1;if(a.children[s])return i(a.children[s])}return a.children[0]?i(a.children[0]):!0};return i(r),t}function rr(r,e,t){switch(e){case"=":return r===t;case"!=":return r!==t;case"<":return Number(r)<Number(t);case"<=":return Number(r)<=Number(t);case">":return Number(r)>Number(t);case">=":return Number(r)>=Number(t);case"in":return Array.isArray(t)&&t.includes(r);case"not_in":return Array.isArray(t)&&!t.includes(r);case"contains":return String(r).includes(String(t));default:return!1}}function go(r){return r.map((e,t)=>({id:`path-${t}`,type:"highlight",targets:[e],duration:500,delay:t*300}))}function yo(r){const{tree:e,feature_names:t,class_names:i}=r;e.children_left.length;const a=c=>{const s=e.children_left[c]===-1,l=e.n_node_samples[c],u=e.impurity[c],d=e.value[c];if(s){const w=Array.isArray(d)?d:[d],y=Array.isArray(w[0])?w[0]:w,S=y.indexOf(Math.max(...y)),M=(i==null?void 0:i[S])||`Class ${S}`,I=y.reduce((k,T)=>k+T,0),N=I>0?y[S]/I:0;return{id:`node-${c}`,type:"leaf",label:M,outcome:{value:M,class:M,probability:N,samples:l},metrics:{samples:l,impurity:u}}}const m=e.feature[c],p=e.threshold[c],g=t[m]||`feature_${m}`,h=a(e.children_left[c]),x=a(e.children_right[c]);return{id:`node-${c}`,type:c===0?"root":"decision",label:`${g} <= ${p.toFixed(2)}`,condition:{feature:g,operator:"<=",value:p},children:[h,x],metrics:{samples:l,impurity:u,giniIndex:u}}},o=a(0);return{root:o,features:t,classes:i,metadata:{algorithm:"sklearn.DecisionTreeClassifier",maxDepth:ir(o)}}}function ir(r,e=0){return!r.children||r.children.length===0?e:Math.max(...r.children.map(t=>ir(t,e+1)))}function bo(r){const e=(i,a)=>typeof i=="string"?{id:a,type:"leaf",label:i,outcome:{value:i}}:{...i,id:a};return{root:{id:"root",type:"root",label:r.question,condition:{feature:r.feature,operator:typeof r.threshold=="number"?"<=":"=",value:r.threshold},children:[e(r.yesOutcome,"yes-outcome"),e(r.noOutcome,"no-outcome")]}}}function xo(r,e){const t=[],i=o=>{var c,s;if(t.push(o.id),o.type==="leaf"||o.type==="end"||!o.children)return{value:((c=o.outcome)==null?void 0:c.value)??o.label,probability:(s=o.outcome)==null?void 0:s.probability};if(o.condition){const l=e[o.condition.feature],d=rr(l,o.condition.operator,o.condition.value)?0:1;if(o.children[d])return i(o.children[d])}return o.children[0]?i(o.children[0]):{value:null}},a=i(r.root);return{prediction:a.value,probability:a.probability,path:t}}const vo={size:20,enabled:!0,guideThreshold:5,showGuides:!0};function ht(r,e){return Math.round(r/e)*e}function ar(r,e){return{x:ht(r.x,e),y:ht(r.y,e)}}function wo(r,e,t){return ar(r,t)}function jt(r,e,t){return{id:r,left:e.x,right:e.x+t.width,top:e.y,bottom:e.y+t.height,centerX:e.x+t.width/2,centerY:e.y+t.height/2}}function ko(r,e,t,i,a=5){const o=[],c=jt(r,e,t);for(const s of i){if(s.id===r)continue;const l=jt(s.id,s.position,s.size);Math.abs(c.centerX-l.centerX)<=a&&o.push({axis:"vertical",position:l.centerX,sourceNodeIds:[r,s.id],type:"center"}),Math.abs(c.left-l.left)<=a&&o.push({axis:"vertical",position:l.left,sourceNodeIds:[r,s.id],type:"edge"}),Math.abs(c.right-l.right)<=a&&o.push({axis:"vertical",position:l.right,sourceNodeIds:[r,s.id],type:"edge"}),Math.abs(c.centerY-l.centerY)<=a&&o.push({axis:"horizontal",position:l.centerY,sourceNodeIds:[r,s.id],type:"center"}),Math.abs(c.top-l.top)<=a&&o.push({axis:"horizontal",position:l.top,sourceNodeIds:[r,s.id],type:"edge"}),Math.abs(c.bottom-l.bottom)<=a&&o.push({axis:"horizontal",position:l.bottom,sourceNodeIds:[r,s.id],type:"edge"})}return No(o)}function _o(r,e,t){let i=r.x,a=r.y;const o=[],c=t.filter(l=>l.axis==="vertical");if(c.length>0){const l=r.x+e.width/2;let u=null,d=1/0;for(const m of c){const p=m.type==="center"?Math.abs(l-m.position):Math.abs(r.x-m.position);p<d&&(d=p,u=m)}u&&(i=u.type==="center"?u.position-e.width/2:u.position,o.push(u))}const s=t.filter(l=>l.axis==="horizontal");if(s.length>0){const l=r.y+e.height/2;let u=null,d=1/0;for(const m of s){const p=m.type==="center"?Math.abs(l-m.position):Math.abs(r.y-m.position);p<d&&(d=p,u=m)}u&&(a=u.type==="center"?u.position-e.height/2:u.position,o.push(u))}return{snappedPosition:{x:i,y:a},activeGuides:o}}function No(r){const e=new Set;return r.filter(t=>{const i=`${t.axis}-${t.position}-${t.type}`;return e.has(i)?!1:(e.add(i),!0)})}let Co=0;function xt(){return`tmpl-${++Co}-${Date.now().toString(36)}`}function ee(r,e,t="roundedRect",i={width:160,height:60},a){return{id:xt(),label:r,position:e,size:i,shape:t,style:{},ports:[{id:"top",side:"top",offset:.5},{id:"right",side:"right",offset:.5},{id:"bottom",side:"bottom",offset:.5},{id:"left",side:"left",offset:.5}],data:a}}function re(r,e,t="bottom",i="top",a){return{id:xt(),sourceNodeId:r.id,sourcePortId:t,targetNodeId:e.id,targetPortId:i,label:a,style:{lineType:"bezier",targetArrow:"arrow"}}}function Re(r,e,t,i){const a=new Date().toISOString();return{version:"1.0",id:xt(),title:r,diagramType:e,nodes:t,edges:i,groups:[],animations:[],viewport:{x:0,y:0,zoom:1},metadata:{createdAt:a,updatedAt:a}}}function Mo(){const r=ee("Commit",{x:40,y:200},"circle",{width:80,height:80}),e=ee("Build",{x:200,y:200},"roundedRect"),t=ee("Test",{x:420,y:200},"roundedRect"),i=ee("Deploy",{x:640,y:200},"roundedRect"),a=ee("Production",{x:860,y:200},"hexagon",{width:140,height:80});return Re("CI/CD Pipeline","flowchart",[r,e,t,i,a],[re(r,e,"right","left"),re(e,t,"right","left"),re(t,i,"right","left"),re(i,a,"right","left")])}function So(){const r=ee("API Gateway",{x:350,y:40},"hexagon",{width:160,height:80}),e=ee("Auth Service",{x:80,y:200},"roundedRect"),t=ee("User Service",{x:300,y:200},"roundedRect"),i=ee("Order Service",{x:520,y:200},"roundedRect"),a=ee("Notification",{x:740,y:200},"roundedRect"),o=ee("Users DB",{x:180,y:380},"cylinder",{width:120,height:70}),c=ee("Orders DB",{x:520,y:380},"cylinder",{width:120,height:70}),s=ee("Message Queue",{x:620,y:380},"parallelogram",{width:160,height:60}),l=[r,e,t,i,a,o,c,s],u=[re(r,e,"bottom","top"),re(r,t,"bottom","top"),re(r,i,"bottom","top"),re(i,a,"right","left"),re(t,o,"bottom","top"),re(i,c,"bottom","top"),re(a,s,"bottom","top")];return Re("Microservices Architecture","flowchart",l,u)}function Io(){const r=ee("Start",{x:350,y:20},"circle",{width:70,height:70}),e=ee("Landing Page",{x:310,y:140},"roundedRect"),t=ee("Sign Up",{x:140,y:280},"roundedRect"),i=ee("Log In",{x:480,y:280},"roundedRect"),a=ee("Dashboard",{x:310,y:420},"roundedRect"),o=ee("End",{x:350,y:560},"circle",{width:70,height:70});return Re("User Flow","flowchart",[r,e,t,i,a,o],[re(r,e,"bottom","top"),re(e,t,"bottom","top","New user"),re(e,i,"bottom","top","Returning"),re(t,a,"bottom","top"),re(i,a,"bottom","top"),re(a,o,"bottom","top")])}function zo(){const r=ee("Users",{x:80,y:100},"rectangle",{width:180,height:100}),e=ee("Orders",{x:380,y:100},"rectangle",{width:180,height:100}),t=ee("Products",{x:380,y:320},"rectangle",{width:180,height:100}),i=ee("Categories",{x:680,y:320},"rectangle",{width:180,height:100});return Re("Entity Relationship","er",[r,e,t,i],[re(r,e,"right","left","1:N"),re(e,t,"bottom","top","N:M"),re(t,i,"right","left","N:1")])}function jo(){const r=ee("CEO",{x:350,y:40},"roundedRect"),e=ee("CTO",{x:150,y:180},"roundedRect"),t=ee("CFO",{x:550,y:180},"roundedRect"),i=ee("Engineering",{x:50,y:320},"roundedRect"),a=ee("DevOps",{x:250,y:320},"roundedRect"),o=ee("Accounting",{x:550,y:320},"roundedRect");return Re("Organization Chart","orgchart",[r,e,t,i,a,o],[re(r,e,"bottom","top"),re(r,t,"bottom","top"),re(e,i,"bottom","top"),re(e,a,"bottom","top"),re(t,o,"bottom","top")])}function Ao(){const r=ee("Idle",{x:80,y:200},"circle",{width:90,height:90}),e=ee("Loading",{x:300,y:80},"roundedRect"),t=ee("Success",{x:520,y:80},"roundedRect"),i=ee("Error",{x:520,y:320},"roundedRect"),a=ee("Retry",{x:300,y:320},"diamond",{width:100,height:100});return Re("State Machine","stateMachine",[r,e,t,i,a],[re(r,e,"right","left","fetch"),re(e,t,"right","left","ok"),re(e,i,"bottom","top","fail"),re(i,a,"left","right"),re(a,e,"top","bottom","retry"),re(a,r,"left","right","cancel")])}const rt=[{id:"cicd-pipeline",name:"CI/CD Pipeline",description:"Continuous integration and deployment pipeline",category:"software",diagramType:"flowchart",tags:["devops","ci","cd","pipeline","deployment"],create:Mo},{id:"microservices",name:"Microservices Architecture",description:"Microservices with API gateway, databases, and message queue",category:"software",diagramType:"flowchart",tags:["architecture","microservices","api","backend"],create:So},{id:"user-flow",name:"User Flow",description:"User journey through signup, login, and dashboard",category:"general",diagramType:"flowchart",tags:["ux","user-flow","journey","wireframe"],create:Io},{id:"er-diagram",name:"Entity Relationship",description:"Database ER diagram with tables and relations",category:"software",diagramType:"er",tags:["database","er","schema","sql"],create:zo},{id:"org-chart",name:"Organization Chart",description:"Company organizational hierarchy",category:"business",diagramType:"orgchart",tags:["org","hierarchy","team","management"],create:jo},{id:"state-machine",name:"State Machine",description:"Finite state machine with transitions",category:"software",diagramType:"stateMachine",tags:["state","fsm","transitions","machine"],create:Ao}];function $o(r){return rt.find(e=>e.id===r)}function Do(r){return rt.filter(e=>e.category===r)}function To(r){const e=r.toLowerCase();return rt.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.tags.some(i=>i.includes(e)))}class or{constructor(e={}){this.versions=[],this.currentVersionIndex=-1,this.autoSaveTimer=null,this.lastDocument=null,this.listeners=new Set,this.config={maxVersions:e.maxVersions??100,autoSaveInterval:e.autoSaveInterval??3e4,compressOldVersions:e.compressOldVersions??!1,userId:e.userId??"",userName:e.userName??"Anonymous"}}startAutoSave(e){this.config.autoSaveInterval<=0||(this.autoSaveTimer=setInterval(()=>{const t=e();this.hasChanges(t)&&this.saveVersion(t,"Auto-save")},this.config.autoSaveInterval))}stopAutoSave(){this.autoSaveTimer&&(clearInterval(this.autoSaveTimer),this.autoSaveTimer=null)}hasChanges(e){return this.lastDocument?JSON.stringify(e)!==JSON.stringify(this.lastDocument):!0}saveVersion(e,t){const i=this.lastDocument?this.calculateChanges(this.lastDocument,e):[{type:"node-added",description:"Initial version"}],a={id:Po(),number:this.versions.length+1,timestamp:new Date().toISOString(),userId:this.config.userId,userName:this.config.userName,label:t,snapshot:JSON.stringify(e),changes:i};return this.currentVersionIndex<this.versions.length-1&&(this.versions=this.versions.slice(0,this.currentVersionIndex+1)),this.versions.push(a),this.currentVersionIndex=this.versions.length-1,this.lastDocument=JSON.parse(JSON.stringify(e)),this.versions.length>this.config.maxVersions&&(this.versions.shift(),this.currentVersionIndex--),this.notify(),a}getVersions(){return this.versions}getCurrentVersionIndex(){return this.currentVersionIndex}getCurrentVersion(){return this.versions[this.currentVersionIndex]??null}getVersion(e){return this.versions.find(t=>t.id===e)}getDocumentAtVersion(e){const t=this.getVersion(e);return t?JSON.parse(t.snapshot):null}restoreToVersion(e){const t=this.versions.findIndex(a=>a.id===e);if(t===-1)return null;this.currentVersionIndex=t;const i=JSON.parse(this.versions[t].snapshot);return this.lastDocument=JSON.parse(JSON.stringify(i)),this.notify(),i}diff(e,t){const i=this.getVersion(e),a=this.getVersion(t);if(!i||!a)return null;const o=JSON.parse(i.snapshot),c=JSON.parse(a.snapshot),s=this.calculateChanges(o,c),l={nodesAdded:s.filter(u=>u.type==="node-added").length,nodesRemoved:s.filter(u=>u.type==="node-removed").length,nodesMoved:s.filter(u=>u.type==="node-moved").length,nodesRestyled:s.filter(u=>u.type==="node-restyled").length,edgesAdded:s.filter(u=>u.type==="edge-added").length,edgesRemoved:s.filter(u=>u.type==="edge-removed").length,edgesRestyled:s.filter(u=>u.type==="edge-restyled").length,groupsModified:s.filter(u=>u.type.startsWith("group-")).length,totalChanges:s.length};return{fromVersionId:e,toVersionId:t,changes:s,summary:l}}calculateChanges(e,t){const i=[];e.title!==t.title&&i.push({type:"title-changed",elementType:"document",previousValue:e.title,newValue:t.title,description:`Title changed from "${e.title}" to "${t.title}"`});const a=new Set(e.nodes.map(d=>d.id)),o=new Set(t.nodes.map(d=>d.id));for(const d of t.nodes)a.has(d.id)||i.push({type:"node-added",elementId:d.id,elementType:"node",newValue:d,description:`Node "${d.label||d.id}" added`});for(const d of e.nodes)o.has(d.id)||i.push({type:"node-removed",elementId:d.id,elementType:"node",previousValue:d,description:`Node "${d.label||d.id}" removed`});for(const d of t.nodes){const m=e.nodes.find(p=>p.id===d.id);m&&((m.position.x!==d.position.x||m.position.y!==d.position.y)&&i.push({type:"node-moved",elementId:d.id,elementType:"node",previousValue:{x:m.position.x,y:m.position.y},newValue:{x:d.position.x,y:d.position.y},description:`Node "${d.label||d.id}" moved`}),(m.size.width!==d.size.width||m.size.height!==d.size.height)&&i.push({type:"node-resized",elementId:d.id,elementType:"node",previousValue:{width:m.size.width,height:m.size.height},newValue:{width:d.size.width,height:d.size.height},description:`Node "${d.label||d.id}" resized`}),m.label!==d.label&&i.push({type:"node-relabeled",elementId:d.id,elementType:"node",previousValue:m.label,newValue:d.label,description:`Node label changed from "${m.label}" to "${d.label}"`}),JSON.stringify(m.style)!==JSON.stringify(d.style)&&i.push({type:"node-restyled",elementId:d.id,elementType:"node",previousValue:m.style,newValue:d.style,description:`Node "${d.label||d.id}" style changed`}))}const c=new Set(e.edges.map(d=>d.id)),s=new Set(t.edges.map(d=>d.id));for(const d of t.edges)c.has(d.id)||i.push({type:"edge-added",elementId:d.id,elementType:"edge",newValue:d,description:`Edge from "${d.sourceNodeId}" to "${d.targetNodeId}" added`});for(const d of e.edges)s.has(d.id)||i.push({type:"edge-removed",elementId:d.id,elementType:"edge",previousValue:d,description:`Edge from "${d.sourceNodeId}" to "${d.targetNodeId}" removed`});for(const d of t.edges){const m=e.edges.find(p=>p.id===d.id);m&&((m.sourceNodeId!==d.sourceNodeId||m.targetNodeId!==d.targetNodeId)&&i.push({type:"edge-rerouted",elementId:d.id,elementType:"edge",previousValue:{source:m.sourceNodeId,target:m.targetNodeId},newValue:{source:d.sourceNodeId,target:d.targetNodeId},description:"Edge rerouted"}),JSON.stringify(m.style)!==JSON.stringify(d.style)&&i.push({type:"edge-restyled",elementId:d.id,elementType:"edge",previousValue:m.style,newValue:d.style,description:"Edge style changed"}))}const l=new Set(e.groups.map(d=>d.id)),u=new Set(t.groups.map(d=>d.id));for(const d of t.groups)l.has(d.id)||i.push({type:"group-added",elementId:d.id,elementType:"group",newValue:d,description:`Group "${d.label||d.id}" added`});for(const d of e.groups)u.has(d.id)||i.push({type:"group-removed",elementId:d.id,elementType:"group",previousValue:d,description:`Group "${d.label||d.id}" removed`});return(e.viewport.x!==t.viewport.x||e.viewport.y!==t.viewport.y||e.viewport.zoom!==t.viewport.zoom)&&i.push({type:"viewport-changed",elementType:"document",previousValue:e.viewport,newValue:t.viewport,description:"Viewport changed"}),JSON.stringify(e.theme)!==JSON.stringify(t.theme)&&i.push({type:"theme-changed",elementType:"document",previousValue:e.theme,newValue:t.theme,description:"Theme changed"}),i}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){this.listeners.forEach(e=>e())}exportHistory(){return JSON.stringify({versions:this.versions,currentVersionIndex:this.currentVersionIndex})}importHistory(e){const t=JSON.parse(e);this.versions=t.versions??[],this.currentVersionIndex=t.currentVersionIndex??-1,this.versions.length>0&&this.currentVersionIndex>=0&&(this.lastDocument=JSON.parse(this.versions[this.currentVersionIndex].snapshot)),this.notify()}clearHistory(){this.versions=[],this.currentVersionIndex=-1,this.lastDocument=null,this.notify()}}function Po(){return`v_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function Ro(r){const e=new or(r);return{manager:e,saveVersion:e.saveVersion.bind(e),getVersions:e.getVersions.bind(e),restoreToVersion:e.restoreToVersion.bind(e),diff:e.diff.bind(e)}}class Oo{constructor(e){this.comments=new Map,this.listeners=new Set,this.mentionListeners=new Set,this.config=e}addComment(e,t,i){const a=this.parseMentions(t),o={id:Eo(),anchor:e,status:"open",authorId:this.config.userId,authorName:this.config.userName,authorAvatar:this.config.userAvatar,text:t,mentions:a,replies:[],createdAt:new Date().toISOString(),style:(i==null?void 0:i.style)??this.config.defaultStyle,tags:i==null?void 0:i.tags,priority:i==null?void 0:i.priority};return this.comments.set(o.id,o),this.notify(),a.forEach(c=>this.notifyMention(o,c.userId)),o}updateComment(e,t){const i=this.comments.get(e);return i?(t.text!==void 0&&(i.text=t.text,i.mentions=this.parseMentions(t.text),i.editedAt=new Date().toISOString()),t.style!==void 0&&(i.style=t.style),t.tags!==void 0&&(i.tags=t.tags),t.priority!==void 0&&(i.priority=t.priority),t.anchor!==void 0&&(i.anchor=t.anchor),this.notify(),i):null}deleteComment(e){const t=this.comments.delete(e);return t&&this.notify(),t}resolveComment(e,t="resolved"){const i=this.comments.get(e);return i?(i.status=t,i.resolvedBy=this.config.userId,i.resolvedAt=new Date().toISOString(),this.notify(),i):null}reopenComment(e){const t=this.comments.get(e);return t?(t.status="open",t.resolvedBy=void 0,t.resolvedAt=void 0,this.notify(),t):null}addReply(e,t){const i=this.comments.get(e);if(!i)return null;const a=this.parseMentions(t),o={id:Lo(),authorId:this.config.userId,authorName:this.config.userName,authorAvatar:this.config.userAvatar,text:t,mentions:a,createdAt:new Date().toISOString()};return i.replies.push(o),this.notify(),a.forEach(c=>this.notifyMention(i,c.userId)),o}editReply(e,t,i){const a=this.comments.get(e);if(!a)return null;const o=a.replies.find(c=>c.id===t);return o?(o.text=i,o.mentions=this.parseMentions(i),o.editedAt=new Date().toISOString(),this.notify(),o):null}deleteReply(e,t){const i=this.comments.get(e);if(!i)return!1;const a=i.replies.find(o=>o.id===t);return a?(a.deleted=!0,a.text="[deleted]",this.notify(),!0):!1}getComment(e){return this.comments.get(e)}getAllComments(){return Array.from(this.comments.values())}getCommentsForElement(e){return Array.from(this.comments.values()).filter(t=>t.anchor.elementId===e)}getOpenComments(){return Array.from(this.comments.values()).filter(e=>e.status==="open")}getCommentsMentioningUser(e){return Array.from(this.comments.values()).filter(t=>{const i=t.mentions.some(o=>o.userId===e),a=t.replies.some(o=>o.mentions.some(c=>c.userId===e));return i||a})}filterComments(e){return Array.from(this.comments.values()).filter(t=>{if(e.status&&!e.status.includes(t.status)||e.authorId&&t.authorId!==e.authorId||e.priority&&t.priority&&!e.priority.includes(t.priority)||e.tags&&e.tags.length>0&&(!t.tags||!e.tags.some(i=>t.tags.includes(i)))||e.anchorType&&!e.anchorType.includes(t.anchor.type)||e.elementId&&t.anchor.elementId!==e.elementId)return!1;if(e.searchText){const i=e.searchText.toLowerCase();if(![t.text,...t.replies.map(o=>o.text)].join(" ").toLowerCase().includes(i))return!1}return!(e.mentionedUserId&&!(t.mentions.some(a=>a.userId===e.mentionedUserId)||t.replies.some(a=>a.mentions.some(o=>o.userId===e.mentionedUserId))))})}parseMentions(e){var o;const t=[],i=/@(\w+)/g;let a;for(;(a=i.exec(e))!==null;){const c=a[1],s=(o=this.config.availableUsers)==null?void 0:o.find(l=>l.name.toLowerCase()===c.toLowerCase()||l.id===c);s&&t.push({userId:s.id,userName:s.name,startIndex:a.index,endIndex:a.index+a[0].length})}return t}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}onMention(e){return this.mentionListeners.add(e),()=>this.mentionListeners.delete(e)}notify(){this.listeners.forEach(e=>e())}notifyMention(e,t){this.mentionListeners.forEach(i=>i(e,t))}exportComments(){return JSON.stringify(Array.from(this.comments.values()))}importComments(e){const t=JSON.parse(e);this.comments.clear(),t.forEach(i=>this.comments.set(i.id,i)),this.notify()}getCounts(){const e=Array.from(this.comments.values());return{open:e.filter(t=>t.status==="open").length,resolved:e.filter(t=>t.status==="resolved").length,wontfix:e.filter(t=>t.status==="wontfix").length,total:e.length}}updateConfig(e){Object.assign(this.config,e)}}function Eo(){return`comment_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function Lo(){return`reply_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}const Fo={low:{backgroundColor:"var(--nice-primary-bg, #e3f2fd)",borderColor:"var(--nice-primary, #2196f3)",textColor:"var(--nice-primary-dark, #1565c0)",icon:"info"},medium:{backgroundColor:"var(--nice-warning-bg, #fff3e0)",borderColor:"var(--nice-warning, #ff9800)",textColor:"var(--nice-warning-dark, #e65100)",icon:"warning"},high:{backgroundColor:"var(--nice-danger-bg, #ffebee)",borderColor:"var(--nice-danger, #f44336)",textColor:"var(--nice-danger-dark, #c62828)",icon:"error"},critical:{backgroundColor:"var(--nice-accent-tint-10, #fce4ec)",borderColor:"var(--nice-color-accent-pink, #e91e63)",textColor:"#880e4f",icon:"flame"}};function Wo(r){const e=new Date(r),i=new Date().getTime()-e.getTime(),a=Math.floor(i/(1e3*60)),o=Math.floor(a/60),c=Math.floor(o/24);return a<1?"just now":a<60?`${a}m ago`:o<24?`${o}h ago`:c<7?`${c}d ago`:e.toLocaleDateString()}function Bo(r,e){if(e.length===0)return r;const t=[...e].sort((a,o)=>o.startIndex-a.startIndex);let i=r;for(const a of t){const o=i.slice(0,a.startIndex),c=i.slice(a.endIndex);i=`${o}<span class="mention" data-user-id="${a.userId}">@${a.userName}</span>${c}`}return i}class sr{constructor(){this.profiles=new Map,this.activeProfileId=null,this.listeners=new Set,this.cache=new Map,this.profiles.set("default",{id:"default",name:"Default",description:"Default conditional styling profile",rules:[],enabled:!0}),this.activeProfileId="default"}addRule(e,t="default"){const i=this.profiles.get(t);i&&(i.rules=i.rules.filter(a=>a.id!==e.id),i.rules.push(e),i.rules.sort((a,o)=>a.priority-o.priority),this.invalidateCache(),this.notify())}removeRule(e,t="default"){const i=this.profiles.get(t);i&&(i.rules=i.rules.filter(a=>a.id!==e),this.invalidateCache(),this.notify())}updateRule(e,t,i="default"){const a=this.profiles.get(i);if(!a)return;const o=a.rules.find(c=>c.id===e);o&&(Object.assign(o,t),a.rules.sort((c,s)=>c.priority-s.priority),this.invalidateCache(),this.notify())}toggleRule(e,t,i="default"){this.updateRule(e,{enabled:t},i)}addProfile(e){this.profiles.set(e.id,e),this.notify()}removeProfile(e){e!=="default"&&(this.profiles.delete(e),this.activeProfileId===e&&(this.activeProfileId="default"),this.invalidateCache(),this.notify())}setActiveProfile(e){this.profiles.has(e)&&(this.activeProfileId=e,this.invalidateCache(),this.notify())}getProfiles(){return Array.from(this.profiles.values())}getActiveProfile(){return this.activeProfileId?this.profiles.get(this.activeProfileId)??null:null}applyToNode(e){const t=`node_${e.id}_${JSON.stringify(e.data)}`,i=this.cache.get(t);if(i)return i;const a=this.getActiveProfile();if(!(a!=null&&a.enabled))return this.emptyStyles(e.id);const o=a.rules.filter(s=>s.enabled&&(s.target==="node"||s.target==="both")&&(!s.elementShapes||s.elementShapes.includes(e.shape))),c=this.processRules(e.id,o,e);return this.cache.set(t,c),c}applyToEdge(e){const t=`edge_${e.id}_${JSON.stringify(e.data)}`,i=this.cache.get(t);if(i)return i;const a=this.getActiveProfile();if(!(a!=null&&a.enabled))return this.emptyStyles(e.id);const o=a.rules.filter(s=>s.enabled&&(s.target==="edge"||s.target==="both")),c=this.processRules(e.id,o,e);return this.cache.set(t,c),c}applyToAll(e,t){const i=new Map;for(const a of e)i.set(a.id,this.applyToNode(a));for(const a of t)i.set(a.id,this.applyToEdge(a));return i}processRules(e,t,i){const a={elementId:e,matchedRules:[],styleOverrides:{},addedClasses:[]};for(const o of t)if(this.evaluateCondition(o.condition,i)&&(a.matchedRules.push(o.id),this.applyActions(o.actions,a),o.stopProcessing))break;return a}evaluateCondition(e,t){if("logic"in e)return e.logic==="and"?e.conditions.every(a=>this.evaluateCondition(a,t)):e.conditions.some(a=>this.evaluateCondition(a,t));const i=this.getPropertyValue(t,e.property);return this.compareValues(i,e)}getPropertyValue(e,t){const i=t.split(".");let a=e;for(const o of i){if(a==null)return;a=a[o]}return a}compareValues(e,t){const{operator:i,value:a,valueTo:o,caseInsensitive:c}=t;if(i==="is_null")return e==null;if(i==="is_not_null")return e!=null;if(i==="is_empty")return e===""||Array.isArray(e)&&e.length===0;if(i==="is_not_empty")return e!==""&&(!Array.isArray(e)||e.length>0);const s=c&&typeof e=="string"?e.toLowerCase():e,l=c&&typeof a=="string"?a.toLowerCase():a;switch(i){case"equals":return s===l;case"not_equals":return s!==l;case"greater_than":return e>a;case"greater_than_or_equals":return e>=a;case"less_than":return e<a;case"less_than_or_equals":return e<=a;case"contains":return typeof s=="string"&&typeof l=="string"?s.includes(l):Array.isArray(e)?e.includes(a):!1;case"not_contains":return typeof s=="string"&&typeof l=="string"?!s.includes(l):Array.isArray(e)?!e.includes(a):!0;case"starts_with":return typeof s=="string"&&typeof l=="string"&&s.startsWith(l);case"ends_with":return typeof s=="string"&&typeof l=="string"&&s.endsWith(l);case"regex":if(typeof e!="string"||typeof a!="string")return!1;try{const u=c?"i":"";return new RegExp(a,u).test(e)}catch{return!1}case"in":return Array.isArray(a)&&a.includes(e);case"not_in":return!Array.isArray(a)||!a.includes(e);case"between":return e>=a&&e<=o;default:return!1}}applyActions(e,t){for(const i of e)switch(i.type){case"set_fill":t.styleOverrides.backgroundColor=i.value;break;case"set_stroke":t.styleOverrides.borderColor=i.value;break;case"set_stroke_width":t.styleOverrides.borderWidth=i.value;break;case"set_text_color":t.styleOverrides.fontColor=i.value;break;case"set_opacity":t.styleOverrides.opacity=i.value;break;case"set_icon":t.icon=i.value;break;case"set_class":t.addedClasses=[i.value];break;case"add_class":t.addedClasses.includes(i.value)||t.addedClasses.push(i.value);break;case"remove_class":t.addedClasses=t.addedClasses.filter(a=>a!==i.value);break;case"set_shadow":t.styleOverrides.shadow=i.value;break;case"set_border_radius":t.styleOverrides.borderRadius=i.value;break;case"set_dash_array":t.styleOverrides.strokeDash=i.value;break;case"set_animation":t.animation=i.value;break;case"set_badge":t.badge=i.value;break;case"set_tooltip":t.tooltip=i.value;break}}emptyStyles(e){return{elementId:e,matchedRules:[],styleOverrides:{},addedClasses:[]}}invalidateCache(){this.cache.clear()}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){this.listeners.forEach(e=>e())}exportConfig(){return JSON.stringify({profiles:Array.from(this.profiles.values()),activeProfileId:this.activeProfileId})}importConfig(e){const t=JSON.parse(e);this.profiles.clear();for(const i of t.profiles)this.profiles.set(i.id,i);this.activeProfileId=t.activeProfileId,this.invalidateCache(),this.notify()}}const vt=[{id:"status-success",name:"Status: Success",description:"Green fill for successful status",enabled:!0,priority:10,target:"node",condition:{property:"data.status",operator:"in",value:["success","completed","done","active","healthy"],caseInsensitive:!0},actions:[{type:"set_fill",value:"var(--nice-success, #4caf50)"},{type:"set_stroke",value:"var(--nice-success-dark, #2e7d32)"},{type:"set_text_color",value:"var(--nice-bg, #fff)"}]},{id:"status-warning",name:"Status: Warning",description:"Orange fill for warning status",enabled:!0,priority:10,target:"node",condition:{property:"data.status",operator:"in",value:["warning","pending","processing","degraded"],caseInsensitive:!0},actions:[{type:"set_fill",value:"var(--nice-warning, #ff9800)"},{type:"set_stroke",value:"var(--nice-warning-dark, #e65100)"},{type:"set_text_color",value:"var(--nice-text, #000000)"}]},{id:"status-error",name:"Status: Error",description:"Red fill for error status",enabled:!0,priority:10,target:"node",condition:{property:"data.status",operator:"in",value:["error","failed","critical","down","unhealthy"],caseInsensitive:!0},actions:[{type:"set_fill",value:"var(--nice-danger, #f44336)"},{type:"set_stroke",value:"var(--nice-danger-dark, #b71c1c)"},{type:"set_text_color",value:"var(--nice-bg, #fff)"},{type:"set_animation",value:"pulse"}]},{id:"high-value",name:"High Value Highlight",description:"Bold border for high-value nodes",enabled:!1,priority:20,target:"node",condition:{property:"data.value",operator:"greater_than",value:1e6},actions:[{type:"set_stroke_width",value:4},{type:"set_stroke",value:"var(--nice-warning, #FFD700)"},{type:"set_badge",value:{text:"$$$",color:"var(--nice-warning, #FFD700)"}}]},{id:"inactive-dim",name:"Dim Inactive",description:"Reduce opacity for inactive elements",enabled:!1,priority:5,target:"both",condition:{property:"data.active",operator:"equals",value:!1},actions:[{type:"set_opacity",value:.5}]}];function qo(r){const e=vt.find(t=>t.id===r);return e?{...e,id:`${e.id}_${Date.now()}`}:null}function Go(r=!1){const e=new sr;if(r)for(const t of vt)e.addRule(t);return e}class Vo{constructor(){this.nodes=[],this.edges=[],this.groups=[],this.presets=new Map,this.state={query:"",results:[],selectedIndex:-1,filters:[],isActive:!1,totalCount:0},this.listeners=new Set}updateData(e,t,i){this.nodes=e,this.edges=t,this.groups=i,this.state.isActive&&this.state.query&&this.search(this.state.query)}search(e,t={}){const{scope:i="all",matchType:a="contains",caseSensitive:o=!1,searchData:c=!0,dataProperties:s=[],maxResults:l=100,nodeShapes:u=[],groupIds:d=[]}=t;if(!e.trim())return this.state={...this.state,query:"",results:[],selectedIndex:-1,isActive:!1,totalCount:0},this.notify(),[];const m=[],p=o?e:e.toLowerCase();if(i==="all"||i==="nodes"||i==="labels")for(const g of this.nodes){if(m.length>=l)break;if(u.length>0&&!u.includes(g.shape)||d.length>0&&g.groupId&&!d.includes(g.groupId))continue;const h=this.matchElement(g,p,a,o,c,s);h&&m.push({id:g.id,type:"node",label:g.label||g.id,element:g,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}if(i==="all"||i==="edges"||i==="labels")for(const g of this.edges){if(m.length>=l)break;const h=this.matchElement(g,p,a,o,c,s);h&&m.push({id:g.id,type:"edge",label:g.label||`${g.sourceNodeId} → ${g.targetNodeId}`,element:g,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}if(i==="all"||i==="groups")for(const g of this.groups){if(m.length>=l)break;if(d.length>0&&!d.includes(g.id))continue;const h=this.matchElement(g,p,a,o,c,s);h&&m.push({id:g.id,type:"group",label:g.label||g.id,element:g,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}return m.sort((g,h)=>h.score-g.score),this.state={...this.state,query:e,results:m,selectedIndex:m.length>0?0:-1,isActive:!0,totalCount:m.length},this.notify(),m}matchElement(e,t,i,a,o,c){let s=null;const l=(d,m,p,g)=>{(!s||g>s.score)&&(s={text:d,property:m,positions:p,score:g})},u=this.matchText(e.id,t,i,a);if(u&&l(e.id,"id",u.positions,100+u.positions.length*10),"label"in e&&e.label){const d=this.matchText(e.label,t,i,a);d&&l(e.label,"label",d.positions,150+d.positions.length*10)}if("shape"in e&&e.shape){const d=this.matchText(e.shape,t,i,a);d&&l(e.shape,"shape",d.positions,80+d.positions.length*10)}if(o&&"data"in e&&e.data){const d=this.searchInData(e.data,t,i,a,c);for(const m of d)l(m.text,`data.${m.property}`,m.positions,50+m.positions.length*10)}return s}matchText(e,t,i,a){const o=a?e:e.toLowerCase(),c=a?t:t.toLowerCase(),s=[];switch(i){case"exact":o===c&&s.push({start:0,end:e.length});break;case"starts_with":o.startsWith(c)&&s.push({start:0,end:t.length});break;case"ends_with":o.endsWith(c)&&s.push({start:e.length-t.length,end:e.length});break;case"regex":try{const l=a?"g":"gi",u=new RegExp(t,l);let d;for(;(d=u.exec(e))!==null&&(s.push({start:d.index,end:d.index+d[0].length}),!!u.global););}catch{}break;case"contains":default:{let l=0;for(;(l=o.indexOf(c,l))!==-1;)s.push({start:l,end:l+t.length}),l+=t.length;break}}return s.length>0?{positions:s}:null}searchInData(e,t,i,a,o,c=""){const s=[];for(const[l,u]of Object.entries(e)){const d=c?`${c}.${l}`:l;if(!(o.length>0&&!o.some(m=>d.startsWith(m))))if(typeof u=="string"){const m=this.matchText(u,t,i,a);m&&s.push({text:u,property:d,positions:m.positions})}else if(typeof u=="number"||typeof u=="boolean"){const m=String(u),p=this.matchText(m,t,i,a);p&&s.push({text:m,property:d,positions:p.positions})}else u!=null&&typeof u=="object"&&!Array.isArray(u)&&s.push(...this.searchInData(u,t,i,a,o,d))}return s}filter(e){if(this.state.filters=e,e.length===0)return{nodes:this.nodes,edges:this.edges,groups:this.groups};const t=this.nodes.filter(o=>this.matchFilters(o,e)),i=this.edges.filter(o=>this.matchFilters(o,e)),a=this.groups.filter(o=>this.matchFilters(o,e));return this.notify(),{nodes:t,edges:i,groups:a}}matchFilters(e,t){return t.every(i=>this.matchFilter(e,i))}matchFilter(e,t){const i=this.getPropertyValue(e,t.property);switch(t.operator){case"equals":return i===t.value;case"not_equals":return i!==t.value;case"contains":return typeof i=="string"&&typeof t.value=="string"?i.toLowerCase().includes(t.value.toLowerCase()):Array.isArray(i)?i.includes(t.value):!1;case"greater_than":return typeof i=="number"&&i>t.value;case"less_than":return typeof i=="number"&&i<t.value;case"in":return Array.isArray(t.value)&&t.value.includes(i);case"not_in":return!Array.isArray(t.value)||!t.value.includes(i);case"is_null":return i==null;case"is_not_null":return i!=null;default:return!0}}getPropertyValue(e,t){const i=t.split(".");let a=e;for(const o of i){if(a==null)return;a=a[o]}return a}nextResult(){return this.state.results.length===0?null:(this.state.selectedIndex=(this.state.selectedIndex+1)%this.state.results.length,this.notify(),this.state.results[this.state.selectedIndex])}previousResult(){return this.state.results.length===0?null:(this.state.selectedIndex=(this.state.selectedIndex-1+this.state.results.length)%this.state.results.length,this.notify(),this.state.results[this.state.selectedIndex])}selectResult(e){return e<0||e>=this.state.results.length?null:(this.state.selectedIndex=e,this.notify(),this.state.results[e])}getState(){return{...this.state}}getSelectedResult(){return this.state.selectedIndex<0?null:this.state.results[this.state.selectedIndex]??null}clearSearch(){this.state={query:"",results:[],selectedIndex:-1,filters:this.state.filters,isActive:!1,totalCount:0},this.notify()}clearFilters(){this.state.filters=[],this.notify()}clearAll(){this.state={query:"",results:[],selectedIndex:-1,filters:[],isActive:!1,totalCount:0},this.notify()}savePreset(e,t){const i={id:`preset_${Date.now()}`,name:e,description:t,filters:[...this.state.filters],searchQuery:this.state.query||void 0,searchOptions:void 0};return this.presets.set(i.id,i),i}loadPreset(e){const t=this.presets.get(e);t&&(this.state.filters=[...t.filters],t.searchQuery&&this.search(t.searchQuery,t.searchOptions),this.notify())}deletePreset(e){return this.presets.delete(e)}getPresets(){return Array.from(this.presets.values())}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){this.listeners.forEach(e=>e(this.state))}getUniqueValues(e,t){const i=new Set;if(!t||t==="node")for(const a of this.nodes){const o=this.getPropertyValue(a,e);o!=null&&i.add(o)}if(!t||t==="edge")for(const a of this.edges){const o=this.getPropertyValue(a,e);o!=null&&i.add(o)}if(!t||t==="group")for(const a of this.groups){const o=this.getPropertyValue(a,e);o!=null&&i.add(o)}return Array.from(i)}getNodeShapes(){return[...new Set(this.nodes.map(e=>e.shape))]}getEdgeLineTypes(){return[...new Set(this.edges.filter(e=>{var t;return(t=e.style)==null?void 0:t.lineType}).map(e=>e.style.lineType))]}getGroups(){return this.groups}exportPresets(){return JSON.stringify(Array.from(this.presets.values()))}importPresets(e){JSON.parse(e).forEach(i=>this.presets.set(i.id,i))}}function Yo(r,e,t="search-highlight"){if(e.length===0)return r;const i=[...e].sort((o,c)=>c.start-o.start);let a=r;for(const o of i){const c=a.slice(0,o.start),s=a.slice(o.start,o.end),l=a.slice(o.end);a=`${c}<span class="${t}">${s}</span>${l}`}return a}function Xo(r,e){switch(r){case"by-type":return{id:`filter_type_${Date.now()}`,property:"type",operator:"equals",value:e};case"by-layer":return{id:`filter_layer_${Date.now()}`,property:"layer",operator:"equals",value:e};case"by-status":return{id:`filter_status_${Date.now()}`,property:"data.status",operator:"equals",value:e};case"custom":default:return{id:`filter_custom_${Date.now()}`,property:"",operator:"equals",value:e}}}exports.AnimationPlayer=Gt;exports.AnimationTimeline=Ke;exports.COMMENT_PRIORITY_STYLES=Fo;exports.ConditionalStylingEngine=sr;exports.DEFAULT_GRID_CONFIG=vo;exports.DIAGRAM_STYLE_PRESETS=Ze;exports.DIAGRAM_TEMPLATES=rt;exports.DiagramCanvas=ve;exports.DiagramCellRenderer=na;exports.DiagramCommentManager=Oo;exports.DiagramMinimap=Qe;exports.DiagramModel=Je;exports.DiagramParticleEngine=At;exports.DiagramPropertyPanel=et;exports.DiagramSearchFilterEngine=Vo;exports.DiagramToolbar=tt;exports.DiagramVersioningManager=or;exports.EDGE_STYLE_CATALOG=bi;exports.NODE_STYLE_CATALOG=yi;exports.NiceAnimationTimeline=Ke;exports.NiceDatabaseSchemaViewer=ka;exports.NiceDecisionTreeEditor=lo;exports.NiceDependencyGraph=Ba;exports.NiceDiagram=yt;exports.NiceDiagramCanvas=ve;exports.NiceDiagramEditor=Wt;exports.NiceDiagramMinimap=Qe;exports.NiceDiagramPropertyPanel=et;exports.NiceDiagramToolbar=tt;exports.NiceDiagramViewer=yt;exports.NiceI18nProvider=pt;exports.NiceNetworkTopology=to;exports.NiceOrgChartVisualizer=ja;exports.NiceProcessMiningDiagram=Pa;exports.NiceWorkflowVisualizer=ga;exports.PRESET_RULES=vt;exports.TRANSITION_PRESETS=Ft;exports.analyzeDependencyGraph=Za;exports.applyAlignmentSnap=_o;exports.calculateNetworkHealth=so;exports.calculateOrgStats=Ta;exports.computeAlignmentGuides=ko;exports.computeGlowRadius=Dt;exports.computeLayout=Ot;exports.convertAnimation=Zt;exports.convertEdge=Ht;exports.convertGroup=Jt;exports.convertNode=Ut;exports.createConditionalStylingEngine=Go;exports.createDecisionTree=bo;exports.createDiagramDocument=Ae;exports.createGlowFilterId=$t;exports.createLinearWorkflow=xa;exports.createOrgChartFromEmployees=Da;exports.createPresetFromTheme=ki;exports.createQuickFilter=Xo;exports.createRuleFromPreset=qo;exports.createVersioningHook=Ro;exports.discoverNetworkTopology=oo;exports.exportToMermaid=Tt;exports.exportToSvg=ft;exports.fetchAndGenerateDiagram=ca;exports.formatCommentDate=Wo;exports.generateDiagramFromData=Xt;exports.getDiagramStylePreset=xi;exports.getDiagramStylePresetsByCategory=vi;exports.getEasing=Bt;exports.getPointOnPath=hr;exports.getTemplateById=$o;exports.getTemplatesByCategory=Do;exports.highlightMatches=Yo;exports.mineProcessFromLog=Kt;exports.parseBPMNToWorkflow=ba;exports.parseNddJson=pr;exports.parsePackageJsonToDependencies=Ja;exports.parseSQLToSchema=Sa;exports.parseSklearnTree=yo;exports.predictWithTree=xo;exports.presetToThemeOverrides=wi;exports.renderTextWithMentions=Bo;exports.schemaToSQL=Ia;exports.searchTemplates=To;exports.snapNodePosition=wo;exports.snapPointToGrid=ar;exports.snapToGrid=ht;exports.stringifyNddJson=Rt;exports.useDiagramEditor=Lt;exports.useNiceTranslation=Ee;
|
|
6
|
+
`)}const ja={active:"var(--nice-success, #10b981)",away:"var(--nice-warning, #f59e0b)",busy:"var(--nice-danger, #ef4444)",offline:"var(--nice-text-secondary, #6b7280)",vacation:"var(--nice-accent, #8b5cf6)",leave:"var(--nice-primary, #3b82f6)"},Ue=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"],Aa={employees:[]},$a=({data:r=Aa,rootEmployeeId:e,onEmployeeClick:t,onDepartmentClick:i,showAvatars:a=!0,showContactInfo:o=!1,groupByDepartment:c=!0,collapsedDepartments:s=[],maxLevels:l=0,orientation:u="vertical",spacing:d={horizontal:200,vertical:150},statusColors:m=ja,showMinimap:p=!0,className:g,style:h})=>{const[x,w]=b.useState(new Set),[y,S]=b.useState(null),M=b.useMemo(()=>{var F;if(e)return e;const O=r.employees.find(W=>!W.managerId);return(O==null?void 0:O.id)||((F=r.employees[0])==null?void 0:F.id)},[r.employees,e]),I=b.useMemo(()=>Da(r.employees,M),[r.employees,M]),N=b.useMemo(()=>{const O=Ta(I,u,d,l),F=[],W={};c&&r.departments&&r.departments.forEach((q,R)=>{const $=q.color||Ue[R%Ue.length];W[q.id]=$;const X=r.employees.filter(G=>G.department===q.id);X.length!==0&&F.push({id:`dept-${q.id}`,label:q.name,nodeIds:X.map(G=>G.id),style:{fill:`${$}15`,stroke:$,strokeWidth:2},data:{department:q}})});const C=[],E=[],P=(q,R=0)=>{if(l>0&&R>=l||q.employee.department&&s.includes(q.employee.department))return;const $=O[q.employee.id]||{x:0,y:0},X=y===q.employee.id,G=q.employee.status||"active",U=q.employee.department?W[q.employee.department]:"var(--nice-text-secondary, #6b7280)",J=180,ne=o?120:a?90:70;C.push({id:q.employee.id,label:q.employee.name,x:$.x,y:$.y,width:J,height:ne,shape:"rectangle",style:{fill:X?U:"var(--nice-bg, #fff)",stroke:U,strokeWidth:X?3:1,fontColor:X?"var(--nice-text-on-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:13,borderRadius:12},data:{type:"employee",employee:q.employee,statusColor:m[G],hasChildren:q.children.length>0,childrenCount:q.children.length}}),q.employee.managerId&&E.push({id:`rel-${q.employee.managerId}-${q.employee.id}`,source:q.employee.managerId,target:q.employee.id,style:{stroke:"var(--nice-border, #cbd5e1)",strokeWidth:2,arrowHead:"none",lineType:u==="vertical"?"orthogonal":"curved"}}),q.children.forEach(de=>P(de,R+1))};return I&&P(I),je({id:"org-chart",title:"Organization Chart",diagramType:"orgchart",nodes:C,edges:E,groups:F,metadata:{type:"org-chart",...r.metadata}})},[r,I,u,d,l,c,s,a,o,m,y]);b.useCallback(O=>{if(S(F=>F===O?null:O),w(F=>{const W=new Set(F);return W.has(O)?W.delete(O):W.add(O),W}),t){const F=r.employees.find(W=>W.id===O);F&&t(F)}},[r.employees,t]),b.useCallback(O=>{if(!i||!r.departments)return;const F=O.replace("dept-",""),W=r.departments.find(C=>C.id===F);W&&i(W)},[r.departments,i]);const[k,T]=b.useState({x:0,y:0,zoom:1}),L=b.useCallback(O=>{if(O&&(S(F=>F===O?null:O),t)){const F=r.employees.find(W=>W.id===O);F&&t(F)}},[r.employees,t]);return n.jsx("div",{className:`nice-org-chart-visualizer ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:n.jsx(ve,{nodes:N.nodes,edges:N.edges,groups:N.groups,viewport:k,onViewportChange:T,onSelectElement:L,showGrid:!1})})};function Da(r,e){const i=new Map(r.map(o=>[o.id,o])).get(e);if(!i)return null;const a=(o,c)=>{const s=r.filter(l=>l.managerId===o.id);return{employee:o,children:s.map(l=>a(l,c+1)),level:c}};return a(i,0)}function Ta(r,e,t,i){const a={};if(!r)return a;const o=(l,u)=>i>0&&u>=i?0:l.children.length===0?1:l.children.reduce((d,m)=>d+o(m,u+1),0),c=(l,u,d,m)=>{if(i>0&&u>=i)return;const p=d+m*t.horizontal/2,g=u*t.vertical+50;a[l.employee.id]=e==="vertical"?{x:p,y:g}:{x:g,y:p};let h=d;l.children.forEach(x=>{const w=o(x,u+1);c(x,u+1,h,w),h+=w*t.horizontal})},s=o(r,0);return c(r,0,0,s),a}function Pa(r){const t=[...new Set(r.map(i=>i.department).filter(Boolean))].map((i,a)=>({id:i,name:i,color:Ue[a%Ue.length],headcount:r.filter(o=>o.department===i).length}));return{employees:r,departments:t}}function Ra(r){var s;const e=new Set(r.employees.map(l=>l.managerId).filter(Boolean)),t=(l,u=new Set)=>{if(u.has(l))return 0;u.add(l);const d=r.employees.find(m=>m.id===l);return d!=null&&d.managerId?1+t(d.managerId,u):1},i=r.employees.map(l=>t(l.id)),a=Math.max(...i,0),o=Array.from(e).map(l=>r.employees.filter(u=>u.managerId===l).length),c=o.length>0?o.reduce((l,u)=>l+u,0)/o.length:0;return{totalEmployees:r.employees.length,departmentCount:((s=r.departments)==null?void 0:s.length)||0,maxDepth:a,averageSpan:Math.round(c*10)/10,managers:e.size}}const Oa=({data:r,onActivityClick:e,onTransitionClick:t,minEdgeFrequency:i=.05,showFrequency:a=!0,showDuration:o=!0,highlightBottlenecks:c=!0,bottleneckThreshold:s=.9,colorScheme:l="frequency",activityColors:u,layout:d="hierarchical",animationSpeed:m=0,showMinimap:p=!0,className:g,style:h})=>{const[x,w]=b.useState(null),y=b.useMemo(()=>"activities"in r?r:Kt(r),[r]),S=b.useMemo(()=>{if(!c)return new Set;const L=y.activities.filter(F=>F.avgDuration!==void 0).map(F=>F.avgDuration);if(L.length===0)return new Set;L.sort((F,W)=>F-W);const O=L[Math.floor(L.length*s)]||0;return new Set(y.activities.filter(F=>(F.avgDuration||0)>=O).map(F=>F.name))},[y.activities,c,s]),M=b.useMemo(()=>{const L=Math.max(...y.activities.map(P=>P.frequency),1),O=Ea(y,d),F=y.transitions.filter(P=>P.frequency/y.totalCases>=i),W=y.activities.map(P=>{const q=O[P.name]||{x:0,y:0},R=y.startActivities.includes(P.name),$=y.endActivities.includes(P.name),X=S.has(P.name),G=x===P.name,U=Fa(P,l,L,u,X);return{id:P.name,label:P.name,x:q.x,y:q.y,width:140,height:60,shape:R?"ellipse":$?"roundedRect":"rectangle",style:{fill:G?U:"var(--nice-bg, #fff)",stroke:U,strokeWidth:X?4:G?3:2,fontColor:G?"var(--nice-text-on-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:12,borderRadius:$?20:8},data:{type:"activity",activity:P,isStart:R,isEnd:$,isBottleneck:X,frequencyPercent:Math.round(P.frequency/y.totalCases*100)}}}),C=F.map(P=>{const q=y.transitions.indexOf(P),R=P.probability||P.frequency/y.totalCases,$=R>.5,X=[];return a&&X.push(`${P.frequency}x`),o&&P.avgDuration&&X.push(Wa(P.avgDuration)),{id:`trans-${q}`,source:P.from,target:P.to,label:X.join(" | "),style:{stroke:$?"var(--nice-primary, #3b82f6)":"var(--nice-text-muted, #9ca3af)",strokeWidth:Math.max(1,Math.min(6,R*8)),arrowHead:"triangle",lineType:"curved",opacity:Math.max(.3,R)},data:{type:"transition",transition:P,probability:R}}}),E=m>0?Ba(y,m):[];return je({id:"process-mining",title:"Process Mining Diagram",diagramType:"flowchart",nodes:W,edges:C,animations:E,metadata:{type:"process-mining",totalCases:y.totalCases,avgCaseDuration:y.avgCaseDuration}})},[y,i,a,o,c,S,l,u,d,m,x]);b.useCallback(L=>{if(w(O=>O===L?null:L),e){const O=y.activities.find(F=>F.name===L);O&&e(O)}},[y.activities,e]);const I=b.useCallback(L=>{if(!t)return;const O=parseInt(L.replace("trans-",""),10),F=y.transitions[O];F&&t(F)},[y.transitions,t]),[N,k]=b.useState({x:0,y:0,zoom:1}),T=b.useCallback(L=>{if(L){if(L.startsWith("trans-")){I(L);return}if(w(O=>O===L?null:L),e){const O=y.activities.find(F=>F.name===L);O&&e(O)}}},[y.activities,e,I]);return n.jsx("div",{className:`nice-process-mining-diagram ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:n.jsx(ve,{nodes:M.nodes,edges:M.edges,groups:M.groups,viewport:N,onViewportChange:k,onSelectElement:T,showGrid:!0})})};function Ea(r,e){const t={};if(e==="circular"){const i=r.activities;i.forEach((a,o)=>{const c=o/i.length*2*Math.PI-Math.PI/2,s=200+i.length*15;t[a.name]={x:Math.cos(c)*s+400,y:Math.sin(c)*s+300}})}else{const i=La(r),a={};r.activities.forEach(c=>{const s=i[c.name]||0;a[s]=(a[s]||0)+1});const o={};r.activities.forEach(c=>{const s=i[c.name]||0,l=o[s]||0;o[s]=l+1;const u=a[s],d=(l-(u-1)/2)*180;t[c.name]={x:400+d,y:50+s*120}})}return t}function La(r){const e={},t=new Set,i=r.startActivities.map(a=>({activity:a,level:0}));for(;i.length>0;){const{activity:a,level:o}=i.shift();if(t.has(a))continue;t.add(a),e[a]=o,r.transitions.filter(s=>s.from===a).forEach(s=>{t.has(s.to)||i.push({activity:s.to,level:o+1})})}return r.activities.forEach(a=>{e[a.name]===void 0&&(e[a.name]=0)}),e}function Fa(r,e,t,i,a){if(a)return"var(--nice-danger, #ef4444)";if(i!=null&&i[r.name])return i[r.name];const o=r.frequency/t;switch(e){case"frequency":return ut("var(--nice-success, #10b981)","var(--nice-primary, #3b82f6)",o);case"duration":return r.avgDuration?ut("var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)",o):"var(--nice-text-secondary, #6b7280)";case"cost":return r.avgCost?ut("var(--nice-success, #10b981)","var(--nice-danger, #ef4444)",o):"var(--nice-text-secondary, #6b7280)";default:return"var(--nice-primary, #3b82f6)"}}function ut(r,e,t){const i=u=>{const d=/#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})\b/i.exec(u);return d?{r:parseInt(d[1],16),g:parseInt(d[2],16),b:parseInt(d[3],16)}:{r:0,g:0,b:0}},a=i(r),o=i(e),c=Math.round(a.r+(o.r-a.r)*t),s=Math.round(a.g+(o.g-a.g)*t),l=Math.round(a.b+(o.b-a.b)*t);return`#${[c,s,l].map(u=>u.toString(16).padStart(2,"0")).join("")}`}function Wa(r){return r<1e3?`${r}ms`:r<6e4?`${(r/1e3).toFixed(1)}s`:r<36e5?`${(r/6e4).toFixed(1)}m`:r<864e5?`${(r/36e5).toFixed(1)}h`:`${(r/864e5).toFixed(1)}d`}function Ba(r,e){var i;const t=(i=r.variants)==null?void 0:i[0];return t?t.activities.map((a,o)=>({id:`flow-${o}`,type:"highlight",targets:[a],duration:e,delay:o*e})):[]}function Kt(r){const e=r.events.map(g=>({...g,timestamp:g.timestamp instanceof Date?g.timestamp:new Date(g.timestamp)})),t=new Map;e.forEach(g=>{t.has(g.caseId)||t.set(g.caseId,[]),t.get(g.caseId).push(g)}),t.forEach(g=>{g.sort((h,x)=>h.timestamp.getTime()-x.timestamp.getTime())});const i=new Map,a=new Map,o=new Set,c=new Set;t.forEach(g=>{if(g.length!==0){o.add(g[0].activity),c.add(g[g.length-1].activity);for(let h=0;h<g.length;h++){const x=g[h];i.has(x.activity)||i.set(x.activity,{frequency:0,durations:[],resources:new Set,costs:[]});const w=i.get(x.activity);if(w.frequency++,x.resource&&w.resources.add(x.resource),x.cost!==void 0&&w.costs.push(x.cost),h<g.length-1){const y=g[h+1],S=y.timestamp.getTime()-x.timestamp.getTime();w.durations.push(S);const M=`${x.activity}→${y.activity}`;a.has(M)||a.set(M,{frequency:0,durations:[]});const I=a.get(M);I.frequency++,I.durations.push(S)}}}});const s=Array.from(i.entries()).map(([g,h])=>({name:g,frequency:h.frequency,avgDuration:h.durations.length>0?h.durations.reduce((x,w)=>x+w,0)/h.durations.length:void 0,minDuration:h.durations.length>0?Math.min(...h.durations):void 0,maxDuration:h.durations.length>0?Math.max(...h.durations):void 0,resources:Array.from(h.resources),avgCost:h.costs.length>0?h.costs.reduce((x,w)=>x+w,0)/h.costs.length:void 0})),l=Array.from(a.entries()).map(([g,h])=>{const[x,w]=g.split("→");return{from:x,to:w,frequency:h.frequency,avgDuration:h.durations.length>0?h.durations.reduce((y,S)=>y+S,0)/h.durations.length:void 0,probability:h.frequency/t.size}}),u=new Map;t.forEach((g,h)=>{const x=g.map(y=>y.activity).join("→");u.has(x)||u.set(x,{caseIds:[],durations:[]});const w=u.get(x);if(w.caseIds.push(h),g.length>=2){const y=g[g.length-1].timestamp.getTime()-g[0].timestamp.getTime();w.durations.push(y)}});const d=Array.from(u.entries()).map(([g,h])=>({activities:g.split("→"),frequency:h.caseIds.length,avgDuration:h.durations.length>0?h.durations.reduce((x,w)=>x+w,0)/h.durations.length:0,caseIds:h.caseIds})).sort((g,h)=>h.frequency-g.frequency),m=Array.from(t.values()).filter(g=>g.length>=2).map(g=>g[g.length-1].timestamp.getTime()-g[0].timestamp.getTime()),p=m.length>0?m.reduce((g,h)=>g+h,0)/m.length:void 0;return{activities:s,transitions:l,variants:d,startActivities:Array.from(o),endActivities:Array.from(c),totalCases:t.size,avgCaseDuration:p}}const Qt={module:"var(--nice-primary, #3b82f6)",package:"var(--nice-success, #10b981)",microservice:"var(--nice-accent, #8b5cf6)",library:"var(--nice-warning, #f59e0b)",api:"var(--nice-color-accent-pink, #ec4899)",database:"var(--nice-info, #14b8a6)",external:"var(--nice-text-secondary, #6b7280)",deprecated:"var(--nice-danger, #ef4444)"},er={healthy:"var(--nice-success, #10b981)",warning:"var(--nice-warning, #f59e0b)",critical:"var(--nice-danger, #ef4444)",unknown:"var(--nice-text-secondary, #6b7280)",deprecated:"var(--nice-text-muted, #9ca3af)"},St={import:{color:"var(--nice-primary, #3b82f6)"},runtime:{color:"var(--nice-success, #10b981)"},dev:{color:"var(--nice-text-secondary, #6b7280)",dash:"5,5"},peer:{color:"var(--nice-warning, #f59e0b)",dash:"10,5"},"api-call":{color:"var(--nice-accent, #8b5cf6)"},database:{color:"var(--nice-info, #14b8a6)"},event:{color:"var(--nice-color-accent-pink, #ec4899)",dash:"2,2"},circular:{color:"var(--nice-danger, #ef4444)"}},qa={module:"box",package:"folder",microservice:"square",library:"book",api:"plug",database:"database",external:"globe",deprecated:"warning"},Ga=({data:r,onNodeClick:e,onEdgeClick:t,visibleTypes:i,visibleEdgeTypes:a,highlightCircular:o=!0,showOnlyIssues:c=!1,layout:s="force",groupBy:l="type",nodeSizeBy:u="dependencies",colorScheme:d="type",nodeColors:m,showMetrics:p=!0,interactive:g=!0,showMinimap:h=!0,className:x,style:w})=>{const[y,S]=b.useState(null),[M,I]=b.useState(null),N=b.useMemo(()=>o?tr(r):new Set,[r,o]),k=b.useMemo(()=>{let C=r.nodes;return i&&i.length>0&&(C=C.filter(E=>i.includes(E.type))),c&&(C=C.filter(E=>{var P;return E.status==="critical"||E.status==="warning"||((P=E.metrics)==null?void 0:P.issues)&&E.metrics.issues>0})),C},[r.nodes,i,c]),T=b.useMemo(()=>{const C=new Set(k.map(P=>P.id));let E=r.edges.filter(P=>C.has(P.source)&&C.has(P.target));return a&&a.length>0&&(E=E.filter(P=>a.includes(P.type))),E},[r.edges,k,a]),L=b.useMemo(()=>{const C=Va(k,T,s),E=Xa(k,u),P=[];if(l!=="none"){const $=new Map;k.forEach(G=>{const U=l==="type"?G.type:G.group||"ungrouped";$.has(U)||$.set(U,[]),$.get(U).push(G.id)});let X=0;$.forEach((G,U)=>{var ne,de;const J=l==="type"?Qt[U]||"var(--nice-text-secondary, #6b7280)":((de=(ne=r.groups)==null?void 0:ne.find(V=>V.id===U))==null?void 0:de.color)||He[X%He.length];P.push({id:`group-${U}`,label:U,nodeIds:G,style:{fill:`${J}10`,stroke:J,strokeWidth:1}}),X++})}const q=k.map($=>{const X=C[$.id]||{x:0,y:0},G=y===$.id,U=M===$.id,J=N.has($.id),ne=Ua($,u,E),de=Ha($,d,m,J);return{id:$.id,label:$.name,x:X.x,y:X.y,width:ne.width,height:ne.height,shape:Ja($.type),style:{fill:G||U?de:"var(--nice-bg, #fff)",stroke:de,strokeWidth:J?4:G?3:2,fontColor:G||U?"var(--nice-text-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:8,strokeDasharray:$.status==="deprecated"?"4,4":void 0},data:{type:"dependency",node:$,icon:qa[$.type],isCircular:J,statusColor:er[$.status||"unknown"]}}}),R=T.map(($,X)=>{const G=$.type==="circular"||N.has($.source)&&N.has($.target),U=St[$.type]||St.import;return{id:$.id||`edge-${X}`,source:$.source,target:$.target,label:$.optional?"(optional)":void 0,style:{stroke:G?"var(--nice-danger, #ef4444)":U.color,strokeWidth:Math.max(1,Math.min(4,$.weight||1)),strokeDasharray:U.dash,arrowHead:"triangle",lineType:"curved",opacity:$.optional?.5:1},data:{type:$.type,edge:$,isCircular:G}}});return je({id:"dependency-graph",title:"Dependency Graph",diagramType:"custom",nodes:q,edges:R,groups:P,metadata:{type:"dependency-graph",...r.metadata}})},[k,T,s,l,r.groups,u,d,m,N,y,M]);b.useCallback(C=>{if(S(E=>E===C?null:C),e){const E=r.nodes.find(P=>P.id===C);E&&e(E)}},[r.nodes,e]),b.useCallback(C=>{if(!t)return;const E=r.edges.find(P=>P.id===C);E&&t(E)},[r.edges,t]),b.useCallback(C=>{I(C)},[]);const[O,F]=b.useState({x:0,y:0,zoom:1}),W=b.useCallback(C=>{if(C){if(S(E=>E===C?null:C),e){const E=r.nodes.find(P=>P.id===C);E&&e(E)}if(t){const E=r.edges.find(P=>P.id===C);E&&t(E)}}},[r.nodes,r.edges,e,t]);return n.jsx("div",{className:`nice-dependency-graph ${x||""}`,style:{position:"relative",width:"100%",height:"100%",...w},children:n.jsx(ve,{nodes:L.nodes,edges:L.edges,groups:L.groups,viewport:O,onViewportChange:F,onSelectElement:W,interactive:g,showGrid:!0})})},He=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"];function tr(r){const e=new Set,t=new Map;r.nodes.forEach(c=>t.set(c.id,[])),r.edges.forEach(c=>{var s;(s=t.get(c.source))==null||s.push(c.target)});const i=new Set,a=new Set,o=(c,s)=>{i.add(c),a.add(c),s.push(c);const l=t.get(c)||[];for(const u of l)if(i.has(u)){if(a.has(u)){const d=s.indexOf(u);s.slice(d).forEach(p=>e.add(p))}}else if(o(u,[...s]))return!0;return a.delete(c),!1};return r.nodes.forEach(c=>{i.has(c.id)||o(c.id,[])}),e}function Va(r,e,t){const i={};switch(t){case"circular":{r.forEach((a,o)=>{const c=o/r.length*2*Math.PI-Math.PI/2,s=150+r.length*12;i[a.id]={x:Math.cos(c)*s+400,y:Math.sin(c)*s+300}});break}case"grid":{const a=Math.ceil(Math.sqrt(r.length));r.forEach((o,c)=>{i[o.id]={x:c%a*200+100,y:Math.floor(c/a)*150+100}});break}case"hierarchical":{const a=Ya(r,e),o={},c={};r.forEach(s=>{const l=a[s.id]||0;o[l]=(o[l]||0)+1}),r.forEach(s=>{const l=a[s.id]||0,u=c[l]||0;c[l]=u+1;const d=o[l],m=(u-(d-1)/2)*200;i[s.id]={x:400+m,y:80+l*130}});break}default:{r.forEach((a,o)=>{const c=o/r.length*2*Math.PI,s=200+r.length*10;i[a.id]={x:Math.cos(c)*s+400,y:Math.sin(c)*s+300}});for(let a=0;a<50;a++){const o={};r.forEach(c=>o[c.id]={x:0,y:0});for(let c=0;c<r.length;c++)for(let s=c+1;s<r.length;s++){const l=r[c].id,u=r[s].id,d=i[u].x-i[l].x,m=i[u].y-i[l].y,p=Math.max(1,Math.sqrt(d*d+m*m)),g=5e3/(p*p);o[l].x-=d/p*g,o[l].y-=m/p*g,o[u].x+=d/p*g,o[u].y+=m/p*g}e.forEach(c=>{const s=i[c.target].x-i[c.source].x,l=i[c.target].y-i[c.source].y,u=Math.sqrt(s*s+l*l),d=u*.01;o[c.source].x+=s/u*d,o[c.source].y+=l/u*d,o[c.target].x-=s/u*d,o[c.target].y-=l/u*d}),r.forEach(c=>{i[c.id].x+=Math.max(-10,Math.min(10,o[c.id].x)),i[c.id].y+=Math.max(-10,Math.min(10,o[c.id].y))})}break}}return i}function Ya(r,e){const t={},i={};r.forEach(o=>{t[o.id]=0,i[o.id]=0}),e.forEach(o=>{i[o.target]=(i[o.target]||0)+1});const a=r.filter(o=>i[o.id]===0).map(o=>o.id);for(;a.length>0;){const o=a.shift();e.filter(s=>s.source===o).forEach(s=>{t[s.target]=Math.max(t[s.target],t[o]+1),i[s.target]--,i[s.target]===0&&a.push(s.target)})}return t}function Xa(r,e){const t=r.map(i=>{var a,o,c;switch(e){case"dependencies":return((a=i.metrics)==null?void 0:a.dependencies)||0;case"dependents":return((o=i.metrics)==null?void 0:o.dependents)||0;case"complexity":return((c=i.metrics)==null?void 0:c.complexity)||0;case"size":return i.size||0;default:return 1}});return{min:Math.min(...t,0),max:Math.max(...t,1)}}function Ua(r,e,t){var l,u,d;if(e==="fixed")return{width:140,height:70};let i;switch(e){case"dependencies":i=((l=r.metrics)==null?void 0:l.dependencies)||0;break;case"dependents":i=((u=r.metrics)==null?void 0:u.dependents)||0;break;case"complexity":i=((d=r.metrics)==null?void 0:d.complexity)||0;break;case"size":i=r.size||0;break;default:i=1}const a=t.max>t.min?(i-t.min)/(t.max-t.min):.5,o=100,s=o+a*(180-o);return{width:s,height:s*.5}}function Ha(r,e,t,i){if(i)return"var(--nice-danger, #ef4444)";if(t!=null&&t[r.id])return t[r.id];switch(e){case"status":return er[r.status||"unknown"];case"group":return He[Za(r.group||"")%He.length];default:return Qt[r.type]||"var(--nice-text-secondary, #6b7280)"}}function Ja(r){switch(r){case"database":return"cylinder";case"microservice":return"hexagon";case"api":return"diamond";case"external":return"cloud";default:return"rectangle"}}function Za(r){let e=0;for(let t=0;t<r.length;t++)e=(e<<5)-e+r.charCodeAt(t),e|=0;return Math.abs(e)}function Ka(r){const e=[{id:r.name,name:r.name,version:r.version,type:"package",status:"healthy"}],t=[];let i=0;const a=(o,c)=>{o&&Object.entries(o).forEach(([s,l])=>{e.find(u=>u.id===s)||e.push({id:s,name:s,version:l.replace(/[\^~>=<]/g,""),type:"library",status:"unknown"}),t.push({id:`edge-${i++}`,source:r.name,target:s,type:c})})};return a(r.dependencies,"runtime"),a(r.devDependencies,"dev"),a(r.peerDependencies,"peer"),e.forEach(o=>{o.metrics={dependencies:t.filter(c=>c.source===o.id).length,dependents:t.filter(c=>c.target===o.id).length}}),{nodes:e,edges:t}}function Qa(r){const e=new Map,t=new Map;r.nodes.forEach(d=>{e.set(d.id,0),t.set(d.id,0)}),r.edges.forEach(d=>{e.set(d.target,(e.get(d.target)||0)+1),t.set(d.source,(t.get(d.source)||0)+1)}),tr(r);let i=null,a=0;r.nodes.forEach(d=>{const m=e.get(d.id)||0;m>a&&(a=m,i=d)});let o=null,c=0;r.nodes.forEach(d=>{const m=t.get(d.id)||0;m>c&&(c=m,o=d)});const s=r.nodes.filter(d=>(e.get(d.id)||0)===0&&(t.get(d.id)||0)===0),l=Array.from(t.values()).reduce((d,m)=>d+m,0),u=r.nodes.length>0?l/r.nodes.length:0;return{totalNodes:r.nodes.length,totalEdges:r.edges.length,circularDependencies:[],mostDependent:i,mostDependencies:o,orphanNodes:s,avgDependencies:Math.round(u*10)/10}}const eo={online:"var(--nice-success, #10b981)",offline:"var(--nice-text-secondary, #6b7280)",warning:"var(--nice-warning, #f59e0b)",critical:"var(--nice-danger, #ef4444)",maintenance:"var(--nice-primary, #3b82f6)",unknown:"var(--nice-text-muted, #9ca3af)"},to={router:"shuffle",switch:"plug",firewall:"lock",server:"server",workstation:"monitor",laptop:"monitor",phone:"phone",printer:"printer",camera:"camera",iot:"wifi",loadbalancer:"scale",storage:"database",cloud:"cloud",internet:"globe",unknown:"help"},ro={ethernet:"var(--nice-primary, #3b82f6)",fiber:"var(--nice-success, #10b981)",wireless:"var(--nice-accent, #8b5cf6)",vpn:"var(--nice-warning, #f59e0b)",wan:"var(--nice-color-accent-pink, #ec4899)",trunk:"var(--nice-info, #14b8a6)"},io=({data:r,onDeviceClick:e,onConnectionClick:t,onRefresh:i,autoRefreshInterval:a=0,visibleDeviceTypes:o,showOnlyIssues:c=!1,layout:s="hierarchical",groupBy:l="group",showMetrics:u=!0,showBandwidth:d=!0,showLatency:m=!1,animateTraffic:p=!1,statusColors:g=eo,showMinimap:h=!0,className:x,style:w})=>{const[y,S]=b.useState(null),[M,I]=b.useState(new Date);b.useEffect(()=>{if(a<=0||!i)return;const W=setInterval(()=>{i(),I(new Date)},a);return()=>clearInterval(W)},[a,i]);const N=b.useMemo(()=>{let W=r.devices;return o&&o.length>0&&(W=W.filter(C=>o.includes(C.type))),c&&(W=W.filter(C=>C.status==="critical"||C.status==="warning"||C.status==="offline")),W},[r.devices,o,c]),k=b.useMemo(()=>{const W=new Set(N.map(C=>C.id));return r.connections.filter(C=>W.has(C.source)&&W.has(C.target))},[r.connections,N]),T=b.useMemo(()=>{const W=ao(N,k,s,r.groups),C=[];if(l!=="none"){const R=new Map;N.forEach(X=>{let G;switch(l){case"type":G=X.type;break;case"location":G=X.location||"Unknown Location";break;default:G=X.group||"ungrouped"}R.has(G)||R.set(G,[]),R.get(G).push(X.id)});let $=0;R.forEach((X,G)=>{var ne;const U=(ne=r.groups)==null?void 0:ne.find(de=>de.id===G||de.name===G),J=(U==null?void 0:U.color)||It[$%It.length];C.push({id:`group-${G}`,label:(U==null?void 0:U.name)||G,nodeIds:X,style:{fill:`${J}15`,stroke:J,strokeWidth:2}}),$++})}const E=N.map(R=>{const $=W[R.id]||{x:0,y:0},X=y===R.id,G=g[R.status],U=to[R.type];return{id:R.id,label:R.name,x:$.x,y:$.y,width:120,height:u?90:70,shape:oo(R.type),style:{fill:X?G:"var(--nice-bg, #fff)",stroke:G,strokeWidth:X?3:2,fontColor:X?"var(--nice-text-on-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:8},data:{type:"network-device",device:R,icon:U,statusColor:G}}}),P=k.map((R,$)=>{const X=ro[R.type]||"var(--nice-text-secondary, #6b7280)",G=R.status==="active",U=R.status==="degraded"||R.status==="error",J=[];if(d&&R.bandwidth){const ne=Math.round(R.bandwidth.used/R.bandwidth.total*100);J.push(`${ne}%`)}return m&&R.latency!==void 0&&J.push(`${R.latency}ms`),{id:R.id||`conn-${$}`,source:R.source,target:R.target,sourcePort:R.sourcePort,targetPort:R.targetPort,label:J.join(" | ")||void 0,style:{stroke:U?"var(--nice-danger, #ef4444)":X,strokeWidth:Math.max(1,Math.min(6,(R.speed||1e3)/1e3)),strokeDasharray:G?void 0:"5,5",arrowHead:"none",lineType:R.type==="wireless"?"curved":"orthogonal",opacity:R.status==="inactive"?.3:1},data:{type:R.type,connection:R,isActive:G,isDegraded:U}}}),q=p?so(k):[];return je({id:"network-topology",title:"Network Topology",diagramType:"networkTopology",nodes:E,edges:P,groups:C,animations:q,metadata:{type:"network-topology",lastRefresh:M.toISOString(),...r.metadata}})},[N,k,s,l,r.groups,u,d,m,p,g,y,M]);b.useCallback(W=>{if(S(C=>C===W?null:W),e){const C=r.devices.find(E=>E.id===W);C&&e(C)}},[r.devices,e]),b.useCallback(W=>{if(!t)return;const C=r.connections.find(E=>E.id===W);C&&t(C)},[r.connections,t]);const[L,O]=b.useState({x:0,y:0,zoom:1}),F=b.useCallback(W=>{if(W&&(S(C=>C===W?null:W),e)){const C=r.devices.find(E=>E.id===W);C&&e(C)}},[r.devices,e]);return n.jsx("div",{className:`nice-network-topology ${x||""}`,style:{position:"relative",width:"100%",height:"100%",...w},children:n.jsx(ve,{nodes:T.nodes,edges:T.edges,groups:T.groups,viewport:L,onViewportChange:O,onSelectElement:F,showGrid:!0})})},It=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"];function ao(r,e,t,i){var o;const a={};switch(t){case"star":{const c=new Map;r.forEach(d=>c.set(d.id,0)),e.forEach(d=>{c.set(d.source,(c.get(d.source)||0)+1),c.set(d.target,(c.get(d.target)||0)+1)});let s=(o=r[0])==null?void 0:o.id,l=0;c.forEach((d,m)=>{d>l&&(l=d,s=m)}),a[s]={x:400,y:300};const u=r.filter(d=>d.id!==s);u.forEach((d,m)=>{const p=m/u.length*2*Math.PI-Math.PI/2,g=200;a[d.id]={x:Math.cos(p)*g+400,y:Math.sin(p)*g+300}});break}case"mesh":{const c=Math.ceil(Math.sqrt(r.length));r.forEach((s,l)=>{a[s.id]={x:l%c*150+100,y:Math.floor(l/c)*130+100}});break}case"tree":{const c=r.filter(p=>p.type==="internet"||p.type==="cloud"||p.type==="router"),s=new Map,l=c.map(p=>p.id);l.forEach(p=>s.set(p,0));const u=new Set(l);for(;l.length>0;){const p=l.shift(),g=s.get(p)||0;e.forEach(h=>{let x=null;h.source===p&&!u.has(h.target)&&(x=h.target),h.target===p&&!u.has(h.source)&&(x=h.source),x&&(u.add(x),s.set(x,g+1),l.push(x))})}const d={},m={};r.forEach(p=>{const g=s.get(p.id)||0;d[g]=(d[g]||0)+1}),r.forEach(p=>{const g=s.get(p.id)||0,h=m[g]||0;m[g]=h+1;const x=d[g],w=(h-(x-1)/2)*160;a[p.id]={x:400+w,y:80+g*120}});break}case"hierarchical":default:{const c=["internet","cloud","router","firewall","loadbalancer","switch","server","storage","workstation","laptop","phone","printer","camera","iot","unknown"],s=new Map;r.forEach(u=>{s.has(u.type)||s.set(u.type,[]),s.get(u.type).push(u)});let l=50;c.forEach(u=>{const d=s.get(u);!d||d.length===0||(d.forEach((m,p)=>{const g=(p-(d.length-1)/2)*150;a[m.id]={x:400+g,y:l}}),l+=130)});break}}return a}function oo(r){switch(r){case"router":case"switch":return"diamond";case"firewall":return"hexagon";case"server":case"storage":return"rectangle";case"cloud":case"internet":return"cloud";default:return"rectangle"}}function so(r){return r.filter(e=>e.status==="active"&&e.bandwidth&&e.bandwidth.used>0).map((e,t)=>({id:`traffic-${t}`,type:"flow",targets:[e.id],duration:2e3,delay:t*200}))}async function no(r={}){return console.log("Network discovery with options:",r),{devices:[{id:"internet",name:"Internet",type:"internet",status:"online"},{id:"router-1",name:"Edge Router",type:"router",ipAddress:"192.168.1.1",status:"online",metrics:{cpu:45,memory:60,latency:5}},{id:"firewall-1",name:"Firewall",type:"firewall",ipAddress:"192.168.1.2",status:"online",metrics:{cpu:30,memory:55}},{id:"switch-1",name:"Core Switch",type:"switch",ipAddress:"192.168.1.10",status:"online"},{id:"server-1",name:"Web Server",type:"server",ipAddress:"192.168.1.100",status:"online",metrics:{cpu:75,memory:80}},{id:"server-2",name:"Database Server",type:"server",ipAddress:"192.168.1.101",status:"warning",metrics:{cpu:90,memory:85}}],connections:[{id:"c1",source:"internet",target:"router-1",type:"wan",status:"active",speed:1e3},{id:"c2",source:"router-1",target:"firewall-1",type:"ethernet",status:"active",speed:1e4},{id:"c3",source:"firewall-1",target:"switch-1",type:"ethernet",status:"active",speed:1e4},{id:"c4",source:"switch-1",target:"server-1",type:"ethernet",status:"active",speed:1e4},{id:"c5",source:"switch-1",target:"server-2",type:"ethernet",status:"active",speed:1e4}]}}function co(r){const e=r.devices.filter(m=>m.status==="online").length,t=r.devices.filter(m=>m.status==="offline").length,i=r.devices.filter(m=>m.status==="warning").length,a=r.devices.filter(m=>m.status==="critical").length,o=r.connections.filter(m=>m.status==="active").length,c=r.connections.filter(m=>m.status==="degraded"||m.status==="error").length,s=r.devices.length>0?e/r.devices.length*100:0,l=r.connections.length>0?o/r.connections.length*100:0,u=a*10+i*5+c*5;return{score:Math.max(0,Math.min(100,Math.round(s*.5+l*.5-u))),onlineDevices:e,offlineDevices:t,warningDevices:i,criticalDevices:a,activeConnections:o,degradedConnections:c}}const lo=[{target:".nice-decision-tree-editor",titleKey:"tutorial.decisionTreeEditor.intro.title",title:"Decision tree editor",contentKey:"tutorial.decisionTreeEditor.intro.content",content:"Explore the decision tree: click nodes to inspect conditions and outcomes, toggle metrics, probabilities and samples, and highlight a path for an input.",placement:"auto"}],uo={root:"var(--nice-accent, #8b5cf6)",decision:"var(--nice-primary, #3b82f6)",leaf:"var(--nice-success, #10b981)",chance:"var(--nice-warning, #f59e0b)",end:"var(--nice-danger, #ef4444)"},fo=({data:r,onChange:e,onNodeClick:t,editable:i=!1,showMetrics:a=!0,showProbabilities:o=!0,showSamples:c=!0,highlightPath:s,colorScheme:l="outcome",nodeColors:u,orientation:d="vertical",spacing:m={horizontal:180,vertical:120},showMinimap:p=!0,className:g,style:h,tutorial:x})=>{const[w,y]=b.useState(null),[S,M]=b.useState(new Set),I=b.useMemo(()=>s?yo(r.root,s):new Set,[r.root,s]),{nodes:N,edges:k}=b.useMemo(()=>ho(r.root,r.edges),[r.root,r.edges]),T=b.useMemo(()=>mo(N),[N]),L=b.useMemo(()=>{var q,R;const C=po(r.root,d,m),E=N.map($=>{const X=C[$.id]||{x:0,y:0},G=w===$.id,U=I.has($.id),J=$.type==="leaf"||$.type==="end",ne=go($,l,u,T),de=J?120:160,V=a?80:J?60:70;return{id:$.id,label:$.label,x:X.x,y:X.y,width:de,height:V,shape:J?"roundedRect":"diamond",style:{fill:G||U?ne:"var(--nice-bg, #fff)",stroke:ne,strokeWidth:U?4:G?3:2,fontColor:G||U?"var(--nice-text-primary, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:J?8:0},data:{type:"decision-tree-node",node:$,isLeaf:J,isHighlighted:U}}}),P=k.map(($,X)=>{const G=I.has($.source)&&I.has($.target);let U=$.label||"";return o&&$.probability!==void 0&&(U+=U?` (${($.probability*100).toFixed(0)}%)`:`${($.probability*100).toFixed(0)}%`),{id:$.id||`edge-${X}`,source:$.source,target:$.target,label:U||void 0,style:{stroke:G?"var(--nice-primary, #3b82f6)":"var(--nice-text-muted, #9ca3af)",strokeWidth:G?3:2,arrowHead:"triangle",lineType:d==="vertical"?"orthogonal":"curved"},data:{type:"decision-edge",edge:$,isHighlighted:G}}});return je({id:"decision-tree",title:"Decision Tree",diagramType:"decisionTree",nodes:E,edges:P,animations:s?bo(Array.from(I)):[],metadata:{type:"decision-tree",algorithm:(q=r.metadata)==null?void 0:q.algorithm,accuracy:(R=r.metadata)==null?void 0:R.accuracy}})},[N,k,d,m,a,o,l,u,T,w,I,s,r.metadata]);b.useCallback(C=>{y(P=>P===C?null:C);const E=N.find(P=>P.id===C);E&&E.type!=="leaf"&&E.type!=="end"&&M(P=>{const q=new Set(P);return q.has(C)?q.delete(C):q.add(C),q}),t&&E&&t(E)},[N,t]);const[O,F]=b.useState({x:0,y:0,zoom:1}),W=b.useCallback(C=>{if(!C)return;y(P=>P===C?null:C);const E=N.find(P=>P.id===C);E&&E.type!=="leaf"&&E.type!=="end"&&M(P=>{const q=new Set(P);return q.has(C)?q.delete(C):q.add(C),q}),t&&E&&t(E)},[N,t]);return n.jsxs("div",{className:`nice-decision-tree-editor ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:[n.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:n.jsx(v.NiceTutorialButton,{steps:v.resolveTutorial(x,lo)})}),n.jsx(ve,{nodes:L.nodes,edges:L.edges,groups:L.groups,viewport:O,onViewportChange:F,onSelectElement:W,interactive:!0,showGrid:!1})]})};function ho(r,e){const t=[],i=e?[...e]:[],a=new Set(i.map(c=>`${c.source}-${c.target}`)),o=(c,s)=>{t.push(c),s&&!a.has(`${s}-${c.id}`)&&i.push({id:`e-${s}-${c.id}`,source:s,target:c.id}),c.children&&c.children.forEach((l,u)=>{let d="";c.condition&&(d=u===0?"Yes":"No");const m=`${c.id}-${l.id}`;a.has(m)||(i.push({id:`e-${m}`,source:c.id,target:l.id,label:d,branch:u===0?"yes":"no"}),a.add(m)),o(l,c.id)})};return o(r),{nodes:t,edges:i}}function po(r,e,t){const i={},a=s=>!s.children||s.children.length===0?1:s.children.reduce((l,u)=>l+a(u),0),o=(s,l,u,d)=>{const m=u+d*t.horizontal/2,p=l*t.vertical+50;if(i[s.id]=e==="vertical"?{x:m,y:p}:{x:p,y:m},s.children){let g=u;s.children.forEach(h=>{const x=a(h);o(h,l+1,g,x),g+=x*t.horizontal})}},c=a(r);return o(r,0,0,c),i}function mo(r){const e=r.filter(i=>{var a;return((a=i.metrics)==null?void 0:a.impurity)!==void 0}).map(i=>i.metrics.impurity),t=r.filter(i=>{var a;return((a=i.metrics)==null?void 0:a.samples)!==void 0}).map(i=>i.metrics.samples);return{impurity:{min:Math.min(...e,0),max:Math.max(...e,1)},samples:{min:Math.min(...t,0),max:Math.max(...t,100)}}}function go(r,e,t,i){var a,o,c;if(t!=null&&t[r.id])return t[r.id];switch(e){case"impurity":if(((a=r.metrics)==null?void 0:a.impurity)!==void 0&&i){const s=(r.metrics.impurity-i.impurity.min)/(i.impurity.max-i.impurity.min||1);return zt("var(--nice-success, #10b981)","var(--nice-danger, #ef4444)",s)}break;case"samples":if(((o=r.metrics)==null?void 0:o.samples)!==void 0&&i){const s=(r.metrics.samples-i.samples.min)/(i.samples.max-i.samples.min||1);return zt("var(--nice-warning-bg, #fef3c7)","var(--nice-warning, #f59e0b)",s)}break;case"outcome":if(r.type==="leaf"&&((c=r.outcome)!=null&&c.class))return{positive:"var(--nice-success, #10b981)",negative:"var(--nice-danger, #ef4444)",true:"var(--nice-success, #10b981)",false:"var(--nice-danger, #ef4444)",yes:"var(--nice-success, #10b981)",no:"var(--nice-danger, #ef4444)"}[r.outcome.class.toLowerCase()]||"var(--nice-primary, #3b82f6)";break}return uo[r.type]||"var(--nice-text-secondary, #6b7280)"}function zt(r,e,t){const i=u=>{var m;const d=((m=/#([a-f\d]{6})\b/i.exec(u))==null?void 0:m[1])??"000000";return{r:parseInt(d.slice(0,2),16),g:parseInt(d.slice(2,4),16),b:parseInt(d.slice(4,6),16)}},a=i(r),o=i(e),c=Math.round(a.r+(o.r-a.r)*t),s=Math.round(a.g+(o.g-a.g)*t),l=Math.round(a.b+(o.b-a.b)*t);return`#${[c,s,l].map(u=>u.toString(16).padStart(2,"0")).join("")}`}function yo(r,e){const t=new Set,i=a=>{if(t.add(a.id),a.type==="leaf"||a.type==="end"||!a.children)return!0;if(a.condition){const o=e[a.condition.feature],s=rr(o,a.condition.operator,a.condition.value)?0:1;if(a.children[s])return i(a.children[s])}return a.children[0]?i(a.children[0]):!0};return i(r),t}function rr(r,e,t){switch(e){case"=":return r===t;case"!=":return r!==t;case"<":return Number(r)<Number(t);case"<=":return Number(r)<=Number(t);case">":return Number(r)>Number(t);case">=":return Number(r)>=Number(t);case"in":return Array.isArray(t)&&t.includes(r);case"not_in":return Array.isArray(t)&&!t.includes(r);case"contains":return String(r).includes(String(t));default:return!1}}function bo(r){return r.map((e,t)=>({id:`path-${t}`,type:"highlight",targets:[e],duration:500,delay:t*300}))}function xo(r){const{tree:e,feature_names:t,class_names:i}=r;e.children_left.length;const a=c=>{const s=e.children_left[c]===-1,l=e.n_node_samples[c],u=e.impurity[c],d=e.value[c];if(s){const w=Array.isArray(d)?d:[d],y=Array.isArray(w[0])?w[0]:w,S=y.indexOf(Math.max(...y)),M=(i==null?void 0:i[S])||`Class ${S}`,I=y.reduce((k,T)=>k+T,0),N=I>0?y[S]/I:0;return{id:`node-${c}`,type:"leaf",label:M,outcome:{value:M,class:M,probability:N,samples:l},metrics:{samples:l,impurity:u}}}const m=e.feature[c],p=e.threshold[c],g=t[m]||`feature_${m}`,h=a(e.children_left[c]),x=a(e.children_right[c]);return{id:`node-${c}`,type:c===0?"root":"decision",label:`${g} <= ${p.toFixed(2)}`,condition:{feature:g,operator:"<=",value:p},children:[h,x],metrics:{samples:l,impurity:u,giniIndex:u}}},o=a(0);return{root:o,features:t,classes:i,metadata:{algorithm:"sklearn.DecisionTreeClassifier",maxDepth:ir(o)}}}function ir(r,e=0){return!r.children||r.children.length===0?e:Math.max(...r.children.map(t=>ir(t,e+1)))}function vo(r){const e=(i,a)=>typeof i=="string"?{id:a,type:"leaf",label:i,outcome:{value:i}}:{...i,id:a};return{root:{id:"root",type:"root",label:r.question,condition:{feature:r.feature,operator:typeof r.threshold=="number"?"<=":"=",value:r.threshold},children:[e(r.yesOutcome,"yes-outcome"),e(r.noOutcome,"no-outcome")]}}}function wo(r,e){const t=[],i=o=>{var c,s;if(t.push(o.id),o.type==="leaf"||o.type==="end"||!o.children)return{value:((c=o.outcome)==null?void 0:c.value)??o.label,probability:(s=o.outcome)==null?void 0:s.probability};if(o.condition){const l=e[o.condition.feature],d=rr(l,o.condition.operator,o.condition.value)?0:1;if(o.children[d])return i(o.children[d])}return o.children[0]?i(o.children[0]):{value:null}},a=i(r.root);return{prediction:a.value,probability:a.probability,path:t}}const ko={size:20,enabled:!0,guideThreshold:5,showGuides:!0};function ht(r,e){return Math.round(r/e)*e}function ar(r,e){return{x:ht(r.x,e),y:ht(r.y,e)}}function _o(r,e,t){return ar(r,t)}function jt(r,e,t){return{id:r,left:e.x,right:e.x+t.width,top:e.y,bottom:e.y+t.height,centerX:e.x+t.width/2,centerY:e.y+t.height/2}}function No(r,e,t,i,a=5){const o=[],c=jt(r,e,t);for(const s of i){if(s.id===r)continue;const l=jt(s.id,s.position,s.size);Math.abs(c.centerX-l.centerX)<=a&&o.push({axis:"vertical",position:l.centerX,sourceNodeIds:[r,s.id],type:"center"}),Math.abs(c.left-l.left)<=a&&o.push({axis:"vertical",position:l.left,sourceNodeIds:[r,s.id],type:"edge"}),Math.abs(c.right-l.right)<=a&&o.push({axis:"vertical",position:l.right,sourceNodeIds:[r,s.id],type:"edge"}),Math.abs(c.centerY-l.centerY)<=a&&o.push({axis:"horizontal",position:l.centerY,sourceNodeIds:[r,s.id],type:"center"}),Math.abs(c.top-l.top)<=a&&o.push({axis:"horizontal",position:l.top,sourceNodeIds:[r,s.id],type:"edge"}),Math.abs(c.bottom-l.bottom)<=a&&o.push({axis:"horizontal",position:l.bottom,sourceNodeIds:[r,s.id],type:"edge"})}return Mo(o)}function Co(r,e,t){let i=r.x,a=r.y;const o=[],c=t.filter(l=>l.axis==="vertical");if(c.length>0){const l=r.x+e.width/2;let u=null,d=1/0;for(const m of c){const p=m.type==="center"?Math.abs(l-m.position):Math.abs(r.x-m.position);p<d&&(d=p,u=m)}u&&(i=u.type==="center"?u.position-e.width/2:u.position,o.push(u))}const s=t.filter(l=>l.axis==="horizontal");if(s.length>0){const l=r.y+e.height/2;let u=null,d=1/0;for(const m of s){const p=m.type==="center"?Math.abs(l-m.position):Math.abs(r.y-m.position);p<d&&(d=p,u=m)}u&&(a=u.type==="center"?u.position-e.height/2:u.position,o.push(u))}return{snappedPosition:{x:i,y:a},activeGuides:o}}function Mo(r){const e=new Set;return r.filter(t=>{const i=`${t.axis}-${t.position}-${t.type}`;return e.has(i)?!1:(e.add(i),!0)})}let So=0;function xt(){return`tmpl-${++So}-${Date.now().toString(36)}`}function ee(r,e,t="roundedRect",i={width:160,height:60},a){return{id:xt(),label:r,position:e,size:i,shape:t,style:{},ports:[{id:"top",side:"top",offset:.5},{id:"right",side:"right",offset:.5},{id:"bottom",side:"bottom",offset:.5},{id:"left",side:"left",offset:.5}],data:a}}function re(r,e,t="bottom",i="top",a){return{id:xt(),sourceNodeId:r.id,sourcePortId:t,targetNodeId:e.id,targetPortId:i,label:a,style:{lineType:"bezier",targetArrow:"arrow"}}}function Re(r,e,t,i){const a=new Date().toISOString();return{version:"1.0",id:xt(),title:r,diagramType:e,nodes:t,edges:i,groups:[],animations:[],viewport:{x:0,y:0,zoom:1},metadata:{createdAt:a,updatedAt:a}}}function Io(){const r=ee("Commit",{x:40,y:200},"circle",{width:80,height:80}),e=ee("Build",{x:200,y:200},"roundedRect"),t=ee("Test",{x:420,y:200},"roundedRect"),i=ee("Deploy",{x:640,y:200},"roundedRect"),a=ee("Production",{x:860,y:200},"hexagon",{width:140,height:80});return Re("CI/CD Pipeline","flowchart",[r,e,t,i,a],[re(r,e,"right","left"),re(e,t,"right","left"),re(t,i,"right","left"),re(i,a,"right","left")])}function zo(){const r=ee("API Gateway",{x:350,y:40},"hexagon",{width:160,height:80}),e=ee("Auth Service",{x:80,y:200},"roundedRect"),t=ee("User Service",{x:300,y:200},"roundedRect"),i=ee("Order Service",{x:520,y:200},"roundedRect"),a=ee("Notification",{x:740,y:200},"roundedRect"),o=ee("Users DB",{x:180,y:380},"cylinder",{width:120,height:70}),c=ee("Orders DB",{x:520,y:380},"cylinder",{width:120,height:70}),s=ee("Message Queue",{x:620,y:380},"parallelogram",{width:160,height:60}),l=[r,e,t,i,a,o,c,s],u=[re(r,e,"bottom","top"),re(r,t,"bottom","top"),re(r,i,"bottom","top"),re(i,a,"right","left"),re(t,o,"bottom","top"),re(i,c,"bottom","top"),re(a,s,"bottom","top")];return Re("Microservices Architecture","flowchart",l,u)}function jo(){const r=ee("Start",{x:350,y:20},"circle",{width:70,height:70}),e=ee("Landing Page",{x:310,y:140},"roundedRect"),t=ee("Sign Up",{x:140,y:280},"roundedRect"),i=ee("Log In",{x:480,y:280},"roundedRect"),a=ee("Dashboard",{x:310,y:420},"roundedRect"),o=ee("End",{x:350,y:560},"circle",{width:70,height:70});return Re("User Flow","flowchart",[r,e,t,i,a,o],[re(r,e,"bottom","top"),re(e,t,"bottom","top","New user"),re(e,i,"bottom","top","Returning"),re(t,a,"bottom","top"),re(i,a,"bottom","top"),re(a,o,"bottom","top")])}function Ao(){const r=ee("Users",{x:80,y:100},"rectangle",{width:180,height:100}),e=ee("Orders",{x:380,y:100},"rectangle",{width:180,height:100}),t=ee("Products",{x:380,y:320},"rectangle",{width:180,height:100}),i=ee("Categories",{x:680,y:320},"rectangle",{width:180,height:100});return Re("Entity Relationship","er",[r,e,t,i],[re(r,e,"right","left","1:N"),re(e,t,"bottom","top","N:M"),re(t,i,"right","left","N:1")])}function $o(){const r=ee("CEO",{x:350,y:40},"roundedRect"),e=ee("CTO",{x:150,y:180},"roundedRect"),t=ee("CFO",{x:550,y:180},"roundedRect"),i=ee("Engineering",{x:50,y:320},"roundedRect"),a=ee("DevOps",{x:250,y:320},"roundedRect"),o=ee("Accounting",{x:550,y:320},"roundedRect");return Re("Organization Chart","orgchart",[r,e,t,i,a,o],[re(r,e,"bottom","top"),re(r,t,"bottom","top"),re(e,i,"bottom","top"),re(e,a,"bottom","top"),re(t,o,"bottom","top")])}function Do(){const r=ee("Idle",{x:80,y:200},"circle",{width:90,height:90}),e=ee("Loading",{x:300,y:80},"roundedRect"),t=ee("Success",{x:520,y:80},"roundedRect"),i=ee("Error",{x:520,y:320},"roundedRect"),a=ee("Retry",{x:300,y:320},"diamond",{width:100,height:100});return Re("State Machine","stateMachine",[r,e,t,i,a],[re(r,e,"right","left","fetch"),re(e,t,"right","left","ok"),re(e,i,"bottom","top","fail"),re(i,a,"left","right"),re(a,e,"top","bottom","retry"),re(a,r,"left","right","cancel")])}const rt=[{id:"cicd-pipeline",name:"CI/CD Pipeline",description:"Continuous integration and deployment pipeline",category:"software",diagramType:"flowchart",tags:["devops","ci","cd","pipeline","deployment"],create:Io},{id:"microservices",name:"Microservices Architecture",description:"Microservices with API gateway, databases, and message queue",category:"software",diagramType:"flowchart",tags:["architecture","microservices","api","backend"],create:zo},{id:"user-flow",name:"User Flow",description:"User journey through signup, login, and dashboard",category:"general",diagramType:"flowchart",tags:["ux","user-flow","journey","wireframe"],create:jo},{id:"er-diagram",name:"Entity Relationship",description:"Database ER diagram with tables and relations",category:"software",diagramType:"er",tags:["database","er","schema","sql"],create:Ao},{id:"org-chart",name:"Organization Chart",description:"Company organizational hierarchy",category:"business",diagramType:"orgchart",tags:["org","hierarchy","team","management"],create:$o},{id:"state-machine",name:"State Machine",description:"Finite state machine with transitions",category:"software",diagramType:"stateMachine",tags:["state","fsm","transitions","machine"],create:Do}];function To(r){return rt.find(e=>e.id===r)}function Po(r){return rt.filter(e=>e.category===r)}function Ro(r){const e=r.toLowerCase();return rt.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.tags.some(i=>i.includes(e)))}class or{constructor(e={}){this.versions=[],this.currentVersionIndex=-1,this.autoSaveTimer=null,this.lastDocument=null,this.listeners=new Set,this.config={maxVersions:e.maxVersions??100,autoSaveInterval:e.autoSaveInterval??3e4,compressOldVersions:e.compressOldVersions??!1,userId:e.userId??"",userName:e.userName??"Anonymous"}}startAutoSave(e){this.config.autoSaveInterval<=0||(this.autoSaveTimer=setInterval(()=>{const t=e();this.hasChanges(t)&&this.saveVersion(t,"Auto-save")},this.config.autoSaveInterval))}stopAutoSave(){this.autoSaveTimer&&(clearInterval(this.autoSaveTimer),this.autoSaveTimer=null)}hasChanges(e){return this.lastDocument?JSON.stringify(e)!==JSON.stringify(this.lastDocument):!0}saveVersion(e,t){const i=this.lastDocument?this.calculateChanges(this.lastDocument,e):[{type:"node-added",description:"Initial version"}],a={id:Oo(),number:this.versions.length+1,timestamp:new Date().toISOString(),userId:this.config.userId,userName:this.config.userName,label:t,snapshot:JSON.stringify(e),changes:i};return this.currentVersionIndex<this.versions.length-1&&(this.versions=this.versions.slice(0,this.currentVersionIndex+1)),this.versions.push(a),this.currentVersionIndex=this.versions.length-1,this.lastDocument=JSON.parse(JSON.stringify(e)),this.versions.length>this.config.maxVersions&&(this.versions.shift(),this.currentVersionIndex--),this.notify(),a}getVersions(){return this.versions}getCurrentVersionIndex(){return this.currentVersionIndex}getCurrentVersion(){return this.versions[this.currentVersionIndex]??null}getVersion(e){return this.versions.find(t=>t.id===e)}getDocumentAtVersion(e){const t=this.getVersion(e);return t?JSON.parse(t.snapshot):null}restoreToVersion(e){const t=this.versions.findIndex(a=>a.id===e);if(t===-1)return null;this.currentVersionIndex=t;const i=JSON.parse(this.versions[t].snapshot);return this.lastDocument=JSON.parse(JSON.stringify(i)),this.notify(),i}diff(e,t){const i=this.getVersion(e),a=this.getVersion(t);if(!i||!a)return null;const o=JSON.parse(i.snapshot),c=JSON.parse(a.snapshot),s=this.calculateChanges(o,c),l={nodesAdded:s.filter(u=>u.type==="node-added").length,nodesRemoved:s.filter(u=>u.type==="node-removed").length,nodesMoved:s.filter(u=>u.type==="node-moved").length,nodesRestyled:s.filter(u=>u.type==="node-restyled").length,edgesAdded:s.filter(u=>u.type==="edge-added").length,edgesRemoved:s.filter(u=>u.type==="edge-removed").length,edgesRestyled:s.filter(u=>u.type==="edge-restyled").length,groupsModified:s.filter(u=>u.type.startsWith("group-")).length,totalChanges:s.length};return{fromVersionId:e,toVersionId:t,changes:s,summary:l}}calculateChanges(e,t){const i=[];e.title!==t.title&&i.push({type:"title-changed",elementType:"document",previousValue:e.title,newValue:t.title,description:`Title changed from "${e.title}" to "${t.title}"`});const a=new Set(e.nodes.map(d=>d.id)),o=new Set(t.nodes.map(d=>d.id));for(const d of t.nodes)a.has(d.id)||i.push({type:"node-added",elementId:d.id,elementType:"node",newValue:d,description:`Node "${d.label||d.id}" added`});for(const d of e.nodes)o.has(d.id)||i.push({type:"node-removed",elementId:d.id,elementType:"node",previousValue:d,description:`Node "${d.label||d.id}" removed`});for(const d of t.nodes){const m=e.nodes.find(p=>p.id===d.id);m&&((m.position.x!==d.position.x||m.position.y!==d.position.y)&&i.push({type:"node-moved",elementId:d.id,elementType:"node",previousValue:{x:m.position.x,y:m.position.y},newValue:{x:d.position.x,y:d.position.y},description:`Node "${d.label||d.id}" moved`}),(m.size.width!==d.size.width||m.size.height!==d.size.height)&&i.push({type:"node-resized",elementId:d.id,elementType:"node",previousValue:{width:m.size.width,height:m.size.height},newValue:{width:d.size.width,height:d.size.height},description:`Node "${d.label||d.id}" resized`}),m.label!==d.label&&i.push({type:"node-relabeled",elementId:d.id,elementType:"node",previousValue:m.label,newValue:d.label,description:`Node label changed from "${m.label}" to "${d.label}"`}),JSON.stringify(m.style)!==JSON.stringify(d.style)&&i.push({type:"node-restyled",elementId:d.id,elementType:"node",previousValue:m.style,newValue:d.style,description:`Node "${d.label||d.id}" style changed`}))}const c=new Set(e.edges.map(d=>d.id)),s=new Set(t.edges.map(d=>d.id));for(const d of t.edges)c.has(d.id)||i.push({type:"edge-added",elementId:d.id,elementType:"edge",newValue:d,description:`Edge from "${d.sourceNodeId}" to "${d.targetNodeId}" added`});for(const d of e.edges)s.has(d.id)||i.push({type:"edge-removed",elementId:d.id,elementType:"edge",previousValue:d,description:`Edge from "${d.sourceNodeId}" to "${d.targetNodeId}" removed`});for(const d of t.edges){const m=e.edges.find(p=>p.id===d.id);m&&((m.sourceNodeId!==d.sourceNodeId||m.targetNodeId!==d.targetNodeId)&&i.push({type:"edge-rerouted",elementId:d.id,elementType:"edge",previousValue:{source:m.sourceNodeId,target:m.targetNodeId},newValue:{source:d.sourceNodeId,target:d.targetNodeId},description:"Edge rerouted"}),JSON.stringify(m.style)!==JSON.stringify(d.style)&&i.push({type:"edge-restyled",elementId:d.id,elementType:"edge",previousValue:m.style,newValue:d.style,description:"Edge style changed"}))}const l=new Set(e.groups.map(d=>d.id)),u=new Set(t.groups.map(d=>d.id));for(const d of t.groups)l.has(d.id)||i.push({type:"group-added",elementId:d.id,elementType:"group",newValue:d,description:`Group "${d.label||d.id}" added`});for(const d of e.groups)u.has(d.id)||i.push({type:"group-removed",elementId:d.id,elementType:"group",previousValue:d,description:`Group "${d.label||d.id}" removed`});return(e.viewport.x!==t.viewport.x||e.viewport.y!==t.viewport.y||e.viewport.zoom!==t.viewport.zoom)&&i.push({type:"viewport-changed",elementType:"document",previousValue:e.viewport,newValue:t.viewport,description:"Viewport changed"}),JSON.stringify(e.theme)!==JSON.stringify(t.theme)&&i.push({type:"theme-changed",elementType:"document",previousValue:e.theme,newValue:t.theme,description:"Theme changed"}),i}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){this.listeners.forEach(e=>e())}exportHistory(){return JSON.stringify({versions:this.versions,currentVersionIndex:this.currentVersionIndex})}importHistory(e){const t=JSON.parse(e);this.versions=t.versions??[],this.currentVersionIndex=t.currentVersionIndex??-1,this.versions.length>0&&this.currentVersionIndex>=0&&(this.lastDocument=JSON.parse(this.versions[this.currentVersionIndex].snapshot)),this.notify()}clearHistory(){this.versions=[],this.currentVersionIndex=-1,this.lastDocument=null,this.notify()}}function Oo(){return`v_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function Eo(r){const e=new or(r);return{manager:e,saveVersion:e.saveVersion.bind(e),getVersions:e.getVersions.bind(e),restoreToVersion:e.restoreToVersion.bind(e),diff:e.diff.bind(e)}}class Lo{constructor(e){this.comments=new Map,this.listeners=new Set,this.mentionListeners=new Set,this.config=e}addComment(e,t,i){const a=this.parseMentions(t),o={id:Fo(),anchor:e,status:"open",authorId:this.config.userId,authorName:this.config.userName,authorAvatar:this.config.userAvatar,text:t,mentions:a,replies:[],createdAt:new Date().toISOString(),style:(i==null?void 0:i.style)??this.config.defaultStyle,tags:i==null?void 0:i.tags,priority:i==null?void 0:i.priority};return this.comments.set(o.id,o),this.notify(),a.forEach(c=>this.notifyMention(o,c.userId)),o}updateComment(e,t){const i=this.comments.get(e);return i?(t.text!==void 0&&(i.text=t.text,i.mentions=this.parseMentions(t.text),i.editedAt=new Date().toISOString()),t.style!==void 0&&(i.style=t.style),t.tags!==void 0&&(i.tags=t.tags),t.priority!==void 0&&(i.priority=t.priority),t.anchor!==void 0&&(i.anchor=t.anchor),this.notify(),i):null}deleteComment(e){const t=this.comments.delete(e);return t&&this.notify(),t}resolveComment(e,t="resolved"){const i=this.comments.get(e);return i?(i.status=t,i.resolvedBy=this.config.userId,i.resolvedAt=new Date().toISOString(),this.notify(),i):null}reopenComment(e){const t=this.comments.get(e);return t?(t.status="open",t.resolvedBy=void 0,t.resolvedAt=void 0,this.notify(),t):null}addReply(e,t){const i=this.comments.get(e);if(!i)return null;const a=this.parseMentions(t),o={id:Wo(),authorId:this.config.userId,authorName:this.config.userName,authorAvatar:this.config.userAvatar,text:t,mentions:a,createdAt:new Date().toISOString()};return i.replies.push(o),this.notify(),a.forEach(c=>this.notifyMention(i,c.userId)),o}editReply(e,t,i){const a=this.comments.get(e);if(!a)return null;const o=a.replies.find(c=>c.id===t);return o?(o.text=i,o.mentions=this.parseMentions(i),o.editedAt=new Date().toISOString(),this.notify(),o):null}deleteReply(e,t){const i=this.comments.get(e);if(!i)return!1;const a=i.replies.find(o=>o.id===t);return a?(a.deleted=!0,a.text="[deleted]",this.notify(),!0):!1}getComment(e){return this.comments.get(e)}getAllComments(){return Array.from(this.comments.values())}getCommentsForElement(e){return Array.from(this.comments.values()).filter(t=>t.anchor.elementId===e)}getOpenComments(){return Array.from(this.comments.values()).filter(e=>e.status==="open")}getCommentsMentioningUser(e){return Array.from(this.comments.values()).filter(t=>{const i=t.mentions.some(o=>o.userId===e),a=t.replies.some(o=>o.mentions.some(c=>c.userId===e));return i||a})}filterComments(e){return Array.from(this.comments.values()).filter(t=>{if(e.status&&!e.status.includes(t.status)||e.authorId&&t.authorId!==e.authorId||e.priority&&t.priority&&!e.priority.includes(t.priority)||e.tags&&e.tags.length>0&&(!t.tags||!e.tags.some(i=>t.tags.includes(i)))||e.anchorType&&!e.anchorType.includes(t.anchor.type)||e.elementId&&t.anchor.elementId!==e.elementId)return!1;if(e.searchText){const i=e.searchText.toLowerCase();if(![t.text,...t.replies.map(o=>o.text)].join(" ").toLowerCase().includes(i))return!1}return!(e.mentionedUserId&&!(t.mentions.some(a=>a.userId===e.mentionedUserId)||t.replies.some(a=>a.mentions.some(o=>o.userId===e.mentionedUserId))))})}parseMentions(e){var o;const t=[],i=/@(\w+)/g;let a;for(;(a=i.exec(e))!==null;){const c=a[1],s=(o=this.config.availableUsers)==null?void 0:o.find(l=>l.name.toLowerCase()===c.toLowerCase()||l.id===c);s&&t.push({userId:s.id,userName:s.name,startIndex:a.index,endIndex:a.index+a[0].length})}return t}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}onMention(e){return this.mentionListeners.add(e),()=>this.mentionListeners.delete(e)}notify(){this.listeners.forEach(e=>e())}notifyMention(e,t){this.mentionListeners.forEach(i=>i(e,t))}exportComments(){return JSON.stringify(Array.from(this.comments.values()))}importComments(e){const t=JSON.parse(e);this.comments.clear(),t.forEach(i=>this.comments.set(i.id,i)),this.notify()}getCounts(){const e=Array.from(this.comments.values());return{open:e.filter(t=>t.status==="open").length,resolved:e.filter(t=>t.status==="resolved").length,wontfix:e.filter(t=>t.status==="wontfix").length,total:e.length}}updateConfig(e){Object.assign(this.config,e)}}function Fo(){return`comment_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function Wo(){return`reply_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}const Bo={low:{backgroundColor:"var(--nice-primary-bg, #e3f2fd)",borderColor:"var(--nice-primary, #2196f3)",textColor:"var(--nice-primary-dark, #1565c0)",icon:"info"},medium:{backgroundColor:"var(--nice-warning-bg, #fff3e0)",borderColor:"var(--nice-warning, #ff9800)",textColor:"var(--nice-warning-dark, #e65100)",icon:"warning"},high:{backgroundColor:"var(--nice-danger-bg, #ffebee)",borderColor:"var(--nice-danger, #f44336)",textColor:"var(--nice-danger-dark, #c62828)",icon:"error"},critical:{backgroundColor:"var(--nice-accent-tint-10, #fce4ec)",borderColor:"var(--nice-color-accent-pink, #e91e63)",textColor:"#880e4f",icon:"flame"}};function qo(r){const e=new Date(r),i=new Date().getTime()-e.getTime(),a=Math.floor(i/(1e3*60)),o=Math.floor(a/60),c=Math.floor(o/24);return a<1?"just now":a<60?`${a}m ago`:o<24?`${o}h ago`:c<7?`${c}d ago`:e.toLocaleDateString()}function Go(r,e){if(e.length===0)return r;const t=[...e].sort((a,o)=>o.startIndex-a.startIndex);let i=r;for(const a of t){const o=i.slice(0,a.startIndex),c=i.slice(a.endIndex);i=`${o}<span class="mention" data-user-id="${a.userId}">@${a.userName}</span>${c}`}return i}class sr{constructor(){this.profiles=new Map,this.activeProfileId=null,this.listeners=new Set,this.cache=new Map,this.profiles.set("default",{id:"default",name:"Default",description:"Default conditional styling profile",rules:[],enabled:!0}),this.activeProfileId="default"}addRule(e,t="default"){const i=this.profiles.get(t);i&&(i.rules=i.rules.filter(a=>a.id!==e.id),i.rules.push(e),i.rules.sort((a,o)=>a.priority-o.priority),this.invalidateCache(),this.notify())}removeRule(e,t="default"){const i=this.profiles.get(t);i&&(i.rules=i.rules.filter(a=>a.id!==e),this.invalidateCache(),this.notify())}updateRule(e,t,i="default"){const a=this.profiles.get(i);if(!a)return;const o=a.rules.find(c=>c.id===e);o&&(Object.assign(o,t),a.rules.sort((c,s)=>c.priority-s.priority),this.invalidateCache(),this.notify())}toggleRule(e,t,i="default"){this.updateRule(e,{enabled:t},i)}addProfile(e){this.profiles.set(e.id,e),this.notify()}removeProfile(e){e!=="default"&&(this.profiles.delete(e),this.activeProfileId===e&&(this.activeProfileId="default"),this.invalidateCache(),this.notify())}setActiveProfile(e){this.profiles.has(e)&&(this.activeProfileId=e,this.invalidateCache(),this.notify())}getProfiles(){return Array.from(this.profiles.values())}getActiveProfile(){return this.activeProfileId?this.profiles.get(this.activeProfileId)??null:null}applyToNode(e){const t=`node_${e.id}_${JSON.stringify(e.data)}`,i=this.cache.get(t);if(i)return i;const a=this.getActiveProfile();if(!(a!=null&&a.enabled))return this.emptyStyles(e.id);const o=a.rules.filter(s=>s.enabled&&(s.target==="node"||s.target==="both")&&(!s.elementShapes||s.elementShapes.includes(e.shape))),c=this.processRules(e.id,o,e);return this.cache.set(t,c),c}applyToEdge(e){const t=`edge_${e.id}_${JSON.stringify(e.data)}`,i=this.cache.get(t);if(i)return i;const a=this.getActiveProfile();if(!(a!=null&&a.enabled))return this.emptyStyles(e.id);const o=a.rules.filter(s=>s.enabled&&(s.target==="edge"||s.target==="both")),c=this.processRules(e.id,o,e);return this.cache.set(t,c),c}applyToAll(e,t){const i=new Map;for(const a of e)i.set(a.id,this.applyToNode(a));for(const a of t)i.set(a.id,this.applyToEdge(a));return i}processRules(e,t,i){const a={elementId:e,matchedRules:[],styleOverrides:{},addedClasses:[]};for(const o of t)if(this.evaluateCondition(o.condition,i)&&(a.matchedRules.push(o.id),this.applyActions(o.actions,a),o.stopProcessing))break;return a}evaluateCondition(e,t){if("logic"in e)return e.logic==="and"?e.conditions.every(a=>this.evaluateCondition(a,t)):e.conditions.some(a=>this.evaluateCondition(a,t));const i=this.getPropertyValue(t,e.property);return this.compareValues(i,e)}getPropertyValue(e,t){const i=t.split(".");let a=e;for(const o of i){if(a==null)return;a=a[o]}return a}compareValues(e,t){const{operator:i,value:a,valueTo:o,caseInsensitive:c}=t;if(i==="is_null")return e==null;if(i==="is_not_null")return e!=null;if(i==="is_empty")return e===""||Array.isArray(e)&&e.length===0;if(i==="is_not_empty")return e!==""&&(!Array.isArray(e)||e.length>0);const s=c&&typeof e=="string"?e.toLowerCase():e,l=c&&typeof a=="string"?a.toLowerCase():a;switch(i){case"equals":return s===l;case"not_equals":return s!==l;case"greater_than":return e>a;case"greater_than_or_equals":return e>=a;case"less_than":return e<a;case"less_than_or_equals":return e<=a;case"contains":return typeof s=="string"&&typeof l=="string"?s.includes(l):Array.isArray(e)?e.includes(a):!1;case"not_contains":return typeof s=="string"&&typeof l=="string"?!s.includes(l):Array.isArray(e)?!e.includes(a):!0;case"starts_with":return typeof s=="string"&&typeof l=="string"&&s.startsWith(l);case"ends_with":return typeof s=="string"&&typeof l=="string"&&s.endsWith(l);case"regex":if(typeof e!="string"||typeof a!="string")return!1;try{const u=c?"i":"";return new RegExp(a,u).test(e)}catch{return!1}case"in":return Array.isArray(a)&&a.includes(e);case"not_in":return!Array.isArray(a)||!a.includes(e);case"between":return e>=a&&e<=o;default:return!1}}applyActions(e,t){for(const i of e)switch(i.type){case"set_fill":t.styleOverrides.backgroundColor=i.value;break;case"set_stroke":t.styleOverrides.borderColor=i.value;break;case"set_stroke_width":t.styleOverrides.borderWidth=i.value;break;case"set_text_color":t.styleOverrides.fontColor=i.value;break;case"set_opacity":t.styleOverrides.opacity=i.value;break;case"set_icon":t.icon=i.value;break;case"set_class":t.addedClasses=[i.value];break;case"add_class":t.addedClasses.includes(i.value)||t.addedClasses.push(i.value);break;case"remove_class":t.addedClasses=t.addedClasses.filter(a=>a!==i.value);break;case"set_shadow":t.styleOverrides.shadow=i.value;break;case"set_border_radius":t.styleOverrides.borderRadius=i.value;break;case"set_dash_array":t.styleOverrides.strokeDash=i.value;break;case"set_animation":t.animation=i.value;break;case"set_badge":t.badge=i.value;break;case"set_tooltip":t.tooltip=i.value;break}}emptyStyles(e){return{elementId:e,matchedRules:[],styleOverrides:{},addedClasses:[]}}invalidateCache(){this.cache.clear()}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){this.listeners.forEach(e=>e())}exportConfig(){return JSON.stringify({profiles:Array.from(this.profiles.values()),activeProfileId:this.activeProfileId})}importConfig(e){const t=JSON.parse(e);this.profiles.clear();for(const i of t.profiles)this.profiles.set(i.id,i);this.activeProfileId=t.activeProfileId,this.invalidateCache(),this.notify()}}const vt=[{id:"status-success",name:"Status: Success",description:"Green fill for successful status",enabled:!0,priority:10,target:"node",condition:{property:"data.status",operator:"in",value:["success","completed","done","active","healthy"],caseInsensitive:!0},actions:[{type:"set_fill",value:"var(--nice-success, #4caf50)"},{type:"set_stroke",value:"var(--nice-success-dark, #2e7d32)"},{type:"set_text_color",value:"var(--nice-bg, #fff)"}]},{id:"status-warning",name:"Status: Warning",description:"Orange fill for warning status",enabled:!0,priority:10,target:"node",condition:{property:"data.status",operator:"in",value:["warning","pending","processing","degraded"],caseInsensitive:!0},actions:[{type:"set_fill",value:"var(--nice-warning, #ff9800)"},{type:"set_stroke",value:"var(--nice-warning-dark, #e65100)"},{type:"set_text_color",value:"var(--nice-text, #000000)"}]},{id:"status-error",name:"Status: Error",description:"Red fill for error status",enabled:!0,priority:10,target:"node",condition:{property:"data.status",operator:"in",value:["error","failed","critical","down","unhealthy"],caseInsensitive:!0},actions:[{type:"set_fill",value:"var(--nice-danger, #f44336)"},{type:"set_stroke",value:"var(--nice-danger-dark, #b71c1c)"},{type:"set_text_color",value:"var(--nice-bg, #fff)"},{type:"set_animation",value:"pulse"}]},{id:"high-value",name:"High Value Highlight",description:"Bold border for high-value nodes",enabled:!1,priority:20,target:"node",condition:{property:"data.value",operator:"greater_than",value:1e6},actions:[{type:"set_stroke_width",value:4},{type:"set_stroke",value:"var(--nice-warning, #FFD700)"},{type:"set_badge",value:{text:"$$$",color:"var(--nice-warning, #FFD700)"}}]},{id:"inactive-dim",name:"Dim Inactive",description:"Reduce opacity for inactive elements",enabled:!1,priority:5,target:"both",condition:{property:"data.active",operator:"equals",value:!1},actions:[{type:"set_opacity",value:.5}]}];function Vo(r){const e=vt.find(t=>t.id===r);return e?{...e,id:`${e.id}_${Date.now()}`}:null}function Yo(r=!1){const e=new sr;if(r)for(const t of vt)e.addRule(t);return e}class Xo{constructor(){this.nodes=[],this.edges=[],this.groups=[],this.presets=new Map,this.state={query:"",results:[],selectedIndex:-1,filters:[],isActive:!1,totalCount:0},this.listeners=new Set}updateData(e,t,i){this.nodes=e,this.edges=t,this.groups=i,this.state.isActive&&this.state.query&&this.search(this.state.query)}search(e,t={}){const{scope:i="all",matchType:a="contains",caseSensitive:o=!1,searchData:c=!0,dataProperties:s=[],maxResults:l=100,nodeShapes:u=[],groupIds:d=[]}=t;if(!e.trim())return this.state={...this.state,query:"",results:[],selectedIndex:-1,isActive:!1,totalCount:0},this.notify(),[];const m=[],p=o?e:e.toLowerCase();if(i==="all"||i==="nodes"||i==="labels")for(const g of this.nodes){if(m.length>=l)break;if(u.length>0&&!u.includes(g.shape)||d.length>0&&g.groupId&&!d.includes(g.groupId))continue;const h=this.matchElement(g,p,a,o,c,s);h&&m.push({id:g.id,type:"node",label:g.label||g.id,element:g,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}if(i==="all"||i==="edges"||i==="labels")for(const g of this.edges){if(m.length>=l)break;const h=this.matchElement(g,p,a,o,c,s);h&&m.push({id:g.id,type:"edge",label:g.label||`${g.sourceNodeId} → ${g.targetNodeId}`,element:g,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}if(i==="all"||i==="groups")for(const g of this.groups){if(m.length>=l)break;if(d.length>0&&!d.includes(g.id))continue;const h=this.matchElement(g,p,a,o,c,s);h&&m.push({id:g.id,type:"group",label:g.label||g.id,element:g,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}return m.sort((g,h)=>h.score-g.score),this.state={...this.state,query:e,results:m,selectedIndex:m.length>0?0:-1,isActive:!0,totalCount:m.length},this.notify(),m}matchElement(e,t,i,a,o,c){let s=null;const l=(d,m,p,g)=>{(!s||g>s.score)&&(s={text:d,property:m,positions:p,score:g})},u=this.matchText(e.id,t,i,a);if(u&&l(e.id,"id",u.positions,100+u.positions.length*10),"label"in e&&e.label){const d=this.matchText(e.label,t,i,a);d&&l(e.label,"label",d.positions,150+d.positions.length*10)}if("shape"in e&&e.shape){const d=this.matchText(e.shape,t,i,a);d&&l(e.shape,"shape",d.positions,80+d.positions.length*10)}if(o&&"data"in e&&e.data){const d=this.searchInData(e.data,t,i,a,c);for(const m of d)l(m.text,`data.${m.property}`,m.positions,50+m.positions.length*10)}return s}matchText(e,t,i,a){const o=a?e:e.toLowerCase(),c=a?t:t.toLowerCase(),s=[];switch(i){case"exact":o===c&&s.push({start:0,end:e.length});break;case"starts_with":o.startsWith(c)&&s.push({start:0,end:t.length});break;case"ends_with":o.endsWith(c)&&s.push({start:e.length-t.length,end:e.length});break;case"regex":try{const l=a?"g":"gi",u=new RegExp(t,l);let d;for(;(d=u.exec(e))!==null&&(s.push({start:d.index,end:d.index+d[0].length}),!!u.global););}catch{}break;case"contains":default:{let l=0;for(;(l=o.indexOf(c,l))!==-1;)s.push({start:l,end:l+t.length}),l+=t.length;break}}return s.length>0?{positions:s}:null}searchInData(e,t,i,a,o,c=""){const s=[];for(const[l,u]of Object.entries(e)){const d=c?`${c}.${l}`:l;if(!(o.length>0&&!o.some(m=>d.startsWith(m))))if(typeof u=="string"){const m=this.matchText(u,t,i,a);m&&s.push({text:u,property:d,positions:m.positions})}else if(typeof u=="number"||typeof u=="boolean"){const m=String(u),p=this.matchText(m,t,i,a);p&&s.push({text:m,property:d,positions:p.positions})}else u!=null&&typeof u=="object"&&!Array.isArray(u)&&s.push(...this.searchInData(u,t,i,a,o,d))}return s}filter(e){if(this.state.filters=e,e.length===0)return{nodes:this.nodes,edges:this.edges,groups:this.groups};const t=this.nodes.filter(o=>this.matchFilters(o,e)),i=this.edges.filter(o=>this.matchFilters(o,e)),a=this.groups.filter(o=>this.matchFilters(o,e));return this.notify(),{nodes:t,edges:i,groups:a}}matchFilters(e,t){return t.every(i=>this.matchFilter(e,i))}matchFilter(e,t){const i=this.getPropertyValue(e,t.property);switch(t.operator){case"equals":return i===t.value;case"not_equals":return i!==t.value;case"contains":return typeof i=="string"&&typeof t.value=="string"?i.toLowerCase().includes(t.value.toLowerCase()):Array.isArray(i)?i.includes(t.value):!1;case"greater_than":return typeof i=="number"&&i>t.value;case"less_than":return typeof i=="number"&&i<t.value;case"in":return Array.isArray(t.value)&&t.value.includes(i);case"not_in":return!Array.isArray(t.value)||!t.value.includes(i);case"is_null":return i==null;case"is_not_null":return i!=null;default:return!0}}getPropertyValue(e,t){const i=t.split(".");let a=e;for(const o of i){if(a==null)return;a=a[o]}return a}nextResult(){return this.state.results.length===0?null:(this.state.selectedIndex=(this.state.selectedIndex+1)%this.state.results.length,this.notify(),this.state.results[this.state.selectedIndex])}previousResult(){return this.state.results.length===0?null:(this.state.selectedIndex=(this.state.selectedIndex-1+this.state.results.length)%this.state.results.length,this.notify(),this.state.results[this.state.selectedIndex])}selectResult(e){return e<0||e>=this.state.results.length?null:(this.state.selectedIndex=e,this.notify(),this.state.results[e])}getState(){return{...this.state}}getSelectedResult(){return this.state.selectedIndex<0?null:this.state.results[this.state.selectedIndex]??null}clearSearch(){this.state={query:"",results:[],selectedIndex:-1,filters:this.state.filters,isActive:!1,totalCount:0},this.notify()}clearFilters(){this.state.filters=[],this.notify()}clearAll(){this.state={query:"",results:[],selectedIndex:-1,filters:[],isActive:!1,totalCount:0},this.notify()}savePreset(e,t){const i={id:`preset_${Date.now()}`,name:e,description:t,filters:[...this.state.filters],searchQuery:this.state.query||void 0,searchOptions:void 0};return this.presets.set(i.id,i),i}loadPreset(e){const t=this.presets.get(e);t&&(this.state.filters=[...t.filters],t.searchQuery&&this.search(t.searchQuery,t.searchOptions),this.notify())}deletePreset(e){return this.presets.delete(e)}getPresets(){return Array.from(this.presets.values())}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){this.listeners.forEach(e=>e(this.state))}getUniqueValues(e,t){const i=new Set;if(!t||t==="node")for(const a of this.nodes){const o=this.getPropertyValue(a,e);o!=null&&i.add(o)}if(!t||t==="edge")for(const a of this.edges){const o=this.getPropertyValue(a,e);o!=null&&i.add(o)}if(!t||t==="group")for(const a of this.groups){const o=this.getPropertyValue(a,e);o!=null&&i.add(o)}return Array.from(i)}getNodeShapes(){return[...new Set(this.nodes.map(e=>e.shape))]}getEdgeLineTypes(){return[...new Set(this.edges.filter(e=>{var t;return(t=e.style)==null?void 0:t.lineType}).map(e=>e.style.lineType))]}getGroups(){return this.groups}exportPresets(){return JSON.stringify(Array.from(this.presets.values()))}importPresets(e){JSON.parse(e).forEach(i=>this.presets.set(i.id,i))}}function Uo(r,e,t="search-highlight"){if(e.length===0)return r;const i=[...e].sort((o,c)=>c.start-o.start);let a=r;for(const o of i){const c=a.slice(0,o.start),s=a.slice(o.start,o.end),l=a.slice(o.end);a=`${c}<span class="${t}">${s}</span>${l}`}return a}function Ho(r,e){switch(r){case"by-type":return{id:`filter_type_${Date.now()}`,property:"type",operator:"equals",value:e};case"by-layer":return{id:`filter_layer_${Date.now()}`,property:"layer",operator:"equals",value:e};case"by-status":return{id:`filter_status_${Date.now()}`,property:"data.status",operator:"equals",value:e};case"custom":default:return{id:`filter_custom_${Date.now()}`,property:"",operator:"equals",value:e}}}exports.AnimationPlayer=Gt;exports.AnimationTimeline=Ke;exports.COMMENT_PRIORITY_STYLES=Bo;exports.ConditionalStylingEngine=sr;exports.DEFAULT_GRID_CONFIG=ko;exports.DIAGRAM_STYLE_PRESETS=Ze;exports.DIAGRAM_TEMPLATES=rt;exports.DiagramCanvas=ve;exports.DiagramCellRenderer=fa;exports.DiagramCommentManager=Lo;exports.DiagramMinimap=Qe;exports.DiagramModel=Je;exports.DiagramParticleEngine=At;exports.DiagramPropertyPanel=et;exports.DiagramSearchFilterEngine=Xo;exports.DiagramToolbar=tt;exports.DiagramVersioningManager=or;exports.EDGE_STYLE_CATALOG=bi;exports.NODE_STYLE_CATALOG=yi;exports.NiceAnimationTimeline=Ke;exports.NiceDatabaseSchemaViewer=_a;exports.NiceDecisionTreeEditor=fo;exports.NiceDependencyGraph=Ga;exports.NiceDiagram=yt;exports.NiceDiagramCanvas=ve;exports.NiceDiagramEditor=Wt;exports.NiceDiagramMinimap=Qe;exports.NiceDiagramPropertyPanel=et;exports.NiceDiagramToolbar=tt;exports.NiceDiagramViewer=yt;exports.NiceI18nProvider=pt;exports.NiceNetworkTopology=io;exports.NiceOrgChartVisualizer=$a;exports.NiceProcessMiningDiagram=Oa;exports.NiceWorkflowVisualizer=ya;exports.PRESET_RULES=vt;exports.TRANSITION_PRESETS=Ft;exports.analyzeDependencyGraph=Qa;exports.applyAlignmentSnap=Co;exports.calculateNetworkHealth=co;exports.calculateOrgStats=Ra;exports.computeAlignmentGuides=No;exports.computeGlowRadius=Dt;exports.computeLayout=Ot;exports.convertAnimation=Ut;exports.convertEdge=Yt;exports.convertGroup=Xt;exports.convertNode=Vt;exports.createConditionalStylingEngine=Yo;exports.createDecisionTree=vo;exports.createDiagramDocument=je;exports.createGlowFilterId=$t;exports.createLinearWorkflow=va;exports.createOrgChartFromEmployees=Pa;exports.createPresetFromTheme=ki;exports.createQuickFilter=Ho;exports.createRuleFromPreset=Vo;exports.createVersioningHook=Eo;exports.discoverNetworkTopology=no;exports.exportToMermaid=Tt;exports.exportToSvg=ft;exports.fetchAndGenerateDiagram=ha;exports.formatCommentDate=qo;exports.generateDiagramFromData=Zt;exports.getDiagramStylePreset=xi;exports.getDiagramStylePresetsByCategory=vi;exports.getEasing=Bt;exports.getPointOnPath=hr;exports.getTemplateById=To;exports.getTemplatesByCategory=Po;exports.highlightMatches=Uo;exports.mineProcessFromLog=Kt;exports.parseBPMNToWorkflow=xa;exports.parseNddJson=pr;exports.parsePackageJsonToDependencies=Ka;exports.parseSQLToSchema=Ia;exports.parseSklearnTree=xo;exports.predictWithTree=wo;exports.presetToThemeOverrides=wi;exports.renderTextWithMentions=Go;exports.schemaToSQL=za;exports.searchTemplates=Ro;exports.snapNodePosition=_o;exports.snapPointToGrid=ar;exports.snapToGrid=ht;exports.stringifyNddJson=Rt;exports.useDiagramEditor=Lt;exports.useNiceTranslation=Ee;
|