@nice2dev/ui-diagrams 1.0.20 → 1.0.22
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/components/NiceDecisionTreeEditor.d.ts +2 -0
- package/dist/components/NiceDecisionTreeEditor.d.ts.map +1 -1
- package/dist/components/NiceDiagramEditor.d.ts +3 -0
- package/dist/components/NiceDiagramEditor.d.ts.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +2328 -2279
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),M=require("@nice2dev/ui"),b=require("react");class zt{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 s of a.particles)s.t=(s.t+i*.3)%1,s.offset+=(Math.random()-.5)*i*2,s.offset=Math.max(-4,Math.min(4,s.offset)),s.opacity=.3+Math.sin(s.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 s=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(s)*c,vy:Math.sin(s)*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 s=0;s<a;s++)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(),s=i.getPointAtLength(e*a);return{x:s.x,y:s.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,s=1/0,c=-1/0,o=-1/0;for(const h of r.nodes)a=Math.min(a,h.position.x),s=Math.min(s,h.position.y),c=Math.max(c,h.position.x+h.size.width),o=Math.max(o,h.position.y+h.size.height);r.nodes.length===0&&(a=s=0,c=o=100);const l=40,u=(c-a+l*2)*t,d=(o-s+l*2)*t,g=-a+l,p=-s+l,m=[];m.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${u} ${d}" width="${u}" height="${d}">`),m.push("<defs>"),m.push('<marker id="arrowhead" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">'),m.push(' <polygon points="0 0, 10 3.5, 0 7" fill="var(--nice-text-secondary, #666)" />'),m.push("</marker>"),m.push("</defs>"),i!=="transparent"&&m.push(`<rect width="${u}" height="${d}" fill="${i}" />`),m.push(`<g transform="translate(${g*t}, ${p*t}) scale(${t})">`);for(const h of r.edges){const x=r.nodes.find(L=>L.id===h.sourceNodeId),v=r.nodes.find(L=>L.id===h.targetNodeId);if(!x||!v)continue;const y=x.position.x+x.size.width/2,S=x.position.y+x.size.height/2,N=v.position.x+v.size.width/2,I=v.position.y+v.size.height/2,_=h.style.strokeColor??"var(--nice-text-secondary, #666)",w=h.style.strokeWidth??2,j=h.style.targetArrow!=="none"?' marker-end="url(#arrowhead)"':"";if(h.style.lineType==="bezier"){const L=(y+N)/2,R=S,V=(y+N)/2,B=I;m.push(`<path d="M${y},${S} C${L},${R} ${V},${B} ${N},${I}" fill="none" stroke="${_}" stroke-width="${w}"${j} />`)}else m.push(`<line x1="${y}" y1="${S}" x2="${N}" y2="${I}" stroke="${_}" stroke-width="${w}"${j} />`);if(h.label){const L=(y+N)/2,R=(S+I)/2;m.push(`<text x="${L}" y="${R-6}" text-anchor="middle" font-size="12" fill="var(--nice-text, #333)">${kt(h.label)}</text>`)}}for(const h of r.nodes){const{x,y:v}=h.position,{width:y,height:S}=h.size,N=h.style.backgroundColor??"var(--nice-bg, #fff)",I=h.style.borderColor??"var(--nice-border, #ccc)",_=h.style.borderWidth??1,w=h.style.borderRadius??(h.shape==="roundedRect"?8:0),j=h.style.fontColor??"var(--nice-text, #333)",L=h.style.fontSize??14;switch(h.shape){case"ellipse":case"circle":m.push(`<ellipse cx="${x+y/2}" cy="${v+S/2}" rx="${y/2}" ry="${S/2}" fill="${N}" stroke="${I}" stroke-width="${_}" />`);break;case"diamond":m.push(`<polygon points="${x+y/2},${v} ${x+y},${v+S/2} ${x+y/2},${v+S} ${x},${v+S/2}" fill="${N}" stroke="${I}" stroke-width="${_}" />`);break;default:m.push(`<rect x="${x}" y="${v}" width="${y}" height="${S}" rx="${w}" fill="${N}" stroke="${I}" stroke-width="${_}" />`)}m.push(`<text x="${x+y/2}" y="${v+S/2+L/3}" text-anchor="middle" font-size="${L}" fill="${j}" font-family="sans-serif">${kt(h.label)}</text>`)}return m.push("</g>"),m.push("</svg>"),m.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),s=i.label.replace(/"/g,"'");switch(i.shape){case"diamond":e.push(` ${a}{${s}}`);break;case"circle":case"ellipse":e.push(` ${a}((${s}))`);break;case"cylinder":e.push(` ${a}[(${s})]`);break;default:e.push(` ${a}["${s}"]`)}}for(const i of r.edges){const a=lt(i.sourceNodeId),s=lt(i.targetNodeId),c=i.label?`|${i.label}|`:"",o=i.style.targetArrow==="none"?"---":"-->";e.push(` ${a} ${o}${c} ${s}`)}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","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","node.label":"Label","node.description":"Description","node.shape":"Shape","node.color":"Color","node.border":"Border","edge.label":"Label","edge.lineType":"Line Type","edge.arrow":"Arrow","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",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","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","node.label":"Etykieta","node.description":"Opis","node.shape":"Kształt","node.color":"Kolor","node.border":"Obramowanie","edge.label":"Etykieta","edge.lineType":"Typ linii","edge.arrow":"Strzałka","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",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","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","node.label":"Bezeichnung","node.description":"Beschreibung","node.shape":"Form","node.color":"Farbe","node.border":"Rahmen","edge.label":"Bezeichnung","edge.lineType":"Linientyp","edge.arrow":"Pfeil","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",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","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","node.label":"Étiquette","node.description":"Description","node.shape":"Forme","node.color":"Couleur","node.border":"Bordure","edge.label":"Étiquette","edge.lineType":"Type de ligne","edge.arrow":"Flèche","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",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","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","node.label":"Etiqueta","node.description":"Descripción","node.shape":"Forma","node.color":"Color","node.border":"Borde","edge.label":"Etiqueta","edge.lineType":"Tipo de línea","edge.arrow":"Flecha","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",untitled:"Diagrama sin título"}},Pt=y.createContext({locale:"en",t:(r,e)=>e??r});function pt({locale:r="en",overrides:e,children:t}){const i=y.useMemo(()=>{const a={..._t.en,..._t[r],...e};return{locale:r,t:(c,o)=>a[c]??o??c}},[r,e]);return y.createElement(Pt.Provider,{value:i},t)}function Ee(){return y.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(s=>s.id).filter(Boolean));for(const s of i.edges)s.sourceNodeId&&!a.has(s.sourceNodeId)&&e.push(`Edge "${s.id}" references non-existent source node "${s.sourceNodeId}"`),s.targetNodeId&&!a.has(s.targetNodeId)&&e.push(`Edge "${s.id}" references non-existent target node "${s.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:ze(),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 s=gr(),c={id:ze(),label:e,position:t,size:a,shape:i,style:{},ports:s};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,s){if(e===i||!this.getNodeById(e)||!this.getNodeById(i))return null;this.pushUndo("Add edge");const c={id:ze(),sourceNodeId:e,sourcePortId:t,targetNodeId:i,targetPortId:a,label:s,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:ze(),label:e,nodeIds:[...t]};return t.forEach(a=>{const s=this.doc.nodes.find(c=>c.id===a);s&&(s.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(s=>s.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:ze(),...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(s=>s.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(s=>s.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:ze(),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 s;const i=(s=this.doc.animationModes)==null?void 0:s.find(c=>c.id===e);if(!i)return null;this.pushUndo("Add animation to mode");const a={id:ze(),...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(s=>s.id===e);i&&(this.pushUndo("Remove animation from mode"),i.animations=i.animations.filter(s=>s.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 ze(){return`ndd_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function gr(){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 mr(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,s=t.rankSpacing??100,c=new Map,o=new Map,l=new Set(r.map(m=>m.id));r.forEach(m=>{c.set(m.id,[]),o.set(m.id,[])}),e.forEach(m=>{l.has(m.sourceNodeId)&&l.has(m.targetNodeId)&&(c.get(m.sourceNodeId).push(m.targetNodeId),o.get(m.targetNodeId).push(m.sourceNodeId))});const f=r.filter(m=>{var S;return(((S=o.get(m.id))==null?void 0:S.length)??0)===0});f.length===0&&r.length>0&&f.push(r[0]);const d=new Map,u=[];for(f.forEach(m=>{d.set(m.id,0),u.push(m.id)});u.length>0;){const m=u.shift(),S=d.get(m)??0;for(const _ of c.get(m)??[])d.has(_)||(d.set(_,S+1),u.push(_))}r.forEach(m=>{d.has(m.id)||d.set(m.id,0)});const x=new Map;r.forEach(m=>{const S=d.get(m.id)??0;x.has(S)||x.set(S,[]),x.get(S).push(m)});const g=new Map,h=i==="LR"||i==="RL",b=i==="BT"||i==="RL";return[...x.keys()].sort((m,S)=>m-S).forEach((m,S)=>{const _=x.get(m);let C=-(_.reduce((w,j)=>w+j.size.width,0)+(_.length-1)*a)/2;_.forEach(w=>{const j=S*(s+(h?w.size.width:w.size.height)),F=C+w.size.width/2;let O,Y;h?(O=b?-j:j,Y=F):(O=F,Y=b?-j:j),g.set(w.id,{x:O,y:Y}),C+=w.size.width+a})}),t.centerGraph&>(g),{positions:g}}function mr(r,e){const t=e.nodeSpacing??80,i=Math.ceil(Math.sqrt(r.length)),a=new Map;return r.forEach((s,c)=>{const o=c%i,l=Math.floor(c/i);a.set(s.id,{x:o*(s.size.width+t),y:l*(s.size.height+t)})}),e.centerGraph&>(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,f)=>(i.get(f.id)??0)-(i.get(l.id)??0)),s=a[0];t.set(s.id,{x:0,y:0});const c=a.slice(1),o=200+c.length*20;return c.forEach((l,f)=>{const d=2*Math.PI*f/c.length;t.set(l.id,{x:Math.cos(d)*o,y:Math.sin(d)*o})}),{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,s=new Map;r.forEach(u=>{s.set(u.id,{x:(Math.random()-.5)*a,y:(Math.random()-.5)*a})});const c=e.map(u=>({source:u.sourceNodeId,target:u.targetNodeId})),o=t.nodeSpacing??150,l=80,f=.95;let d=a/2;for(let u=0;u<l;u++){const x=new Map;r.forEach(g=>x.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 b=s.get(r[g].id),v=s.get(r[h].id),m=v.x-b.x,S=v.y-b.y,_=Math.max(Math.sqrt(m*m+S*S),1),I=o*o/_,C=m/_*I,w=S/_*I;x.get(r[g].id).fx-=C,x.get(r[g].id).fy-=w,x.get(r[h].id).fx+=C,x.get(r[h].id).fy+=w}for(const g of c){const h=s.get(g.source),b=s.get(g.target);if(!h||!b)continue;const v=b.x-h.x,m=b.y-h.y,S=Math.max(Math.sqrt(v*v+m*m),1),_=S*S/o,I=v/S*_,C=m/S*_;x.get(g.source).fx+=I,x.get(g.source).fy+=C,x.get(g.target).fx-=I,x.get(g.target).fy-=C}r.forEach(g=>{const h=x.get(g.id),b=s.get(g.id),v=Math.sqrt(h.fx*h.fx+h.fy*h.fy);if(v>0){const m=Math.min(v,d);b.x+=h.fx/v*m,b.y+=h.fy/v*m}}),d*=f}return r.forEach(u=>{i.set(u.id,{...s.get(u.id)})}),t.centerGraph&>(i),{positions:i}}function gt(r){if(r.size===0)return;let e=1/0,t=1/0,i=-1/0,a=-1/0;r.forEach(o=>{e=Math.min(e,o.x),t=Math.min(t,o.y),i=Math.max(i,o.x),a=Math.max(a,o.y)});const s=(e+i)/2,c=(t+a)/2;r.forEach(o=>{o.x-=s,o.y-=c})}function Lt(r){const e=y.useRef(null);e.current||(e.current=new Je(r));const t=e.current,[,i]=y.useState(0),a=y.useCallback(()=>i(o=>o+1),[]);y.useEffect(()=>t.subscribe(a),[t,a]);const s=t.getDocument(),c=y.useCallback(o=>{Ot(t.getNodes(),t.getEdges(),o).positions.forEach((f,d)=>{t.moveNode(d,f)})},[t]);return y.useMemo(()=>({document:s,nodes:s.nodes,edges:s.edges,groups:s.groups,animations:s.animations,viewport:s.viewport,addNode:(o,l,f,d)=>t.addNode(o,l,f,d),updateNode:(o,l)=>t.updateNode(o,l),moveNode:(o,l)=>t.moveNode(o,l),resizeNode:(o,l)=>t.resizeNode(o,l),removeNode:o=>t.removeNode(o),addEdge:(o,l,f,d,u)=>t.addEdge(o,l,f,d,u),updateEdge:(o,l)=>t.updateEdge(o,l),removeEdge:o=>t.removeEdge(o),createGroup:(o,l)=>t.createGroup(o,l),removeGroup:o=>t.removeGroup(o),toggleGroupCollapse:o=>t.toggleGroupCollapse(o),toggleNodeCollapse:o=>t.toggleNodeCollapse(o),addAnimation:o=>t.addAnimation(o),updateAnimation:(o,l)=>t.updateAnimation(o,l),removeAnimation:o=>t.removeAnimation(o),animationModes:t.getAnimationModes(),activeAnimationMode:t.getActiveAnimationMode(),addAnimationMode:(o,l)=>t.addAnimationMode(o,l),removeAnimationMode:o=>t.removeAnimationMode(o),setActiveAnimationMode:o=>t.setActiveAnimationMode(o),addAnimationToMode:(o,l)=>t.addAnimationToMode(o,l),removeAnimationFromMode:(o,l)=>t.removeAnimationFromMode(o,l),setStylePreset:o=>t.setStylePreset(o),setStyleOverrides:o=>t.setStyleOverrides(o),stylePresetId:s.stylePresetId,playerConfig:t.getPlayerConfig(),setPlayerConfig:o=>t.setPlayerConfig(o),setViewMode:o=>t.setViewMode(o),viewMode:t.getPlayerConfig().mode,applyLayout:c,setViewport:o=>t.setViewport(o),undo:()=>t.undo(),redo:()=>t.redo(),canUndo:t.canUndo(),canRedo:t.canRedo(),loadDocument:o=>t.loadDocument(o),model:t}),[s,t,c])}function ne(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 ce(r,e,t,i,a,s,c){return{canvas:r,nodeDefaults:vr(e,i),edgeDefaults:wr(e,a),groupDefaults:kr(e,s),fontFamily:t,palette:e,effects:c}}const Ce="'Inter', system-ui, sans-serif",mt="'Fira Code', 'Cascadia Code', monospace",_r="'Merriweather', 'Georgia', serif",Cr={id:"default-light",name:"Default Light",category:"corporate",themeSource:"Light",config:ce({background:"var(--nice-bg, #fff)",gridColor:"#e2e8f020",gridSize:20,selectionColor:"var(--nice-primary, #3b82f6)"},ne({}),Ce)},Mr=ne({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-bg-secondary, #f8fafc)",textMuted:"var(--nice-text-secondary, #64748b)",border:"var(--nice-text, #334155)",surface:"var(--nice-text, #1e293b)",surfaceAlt:"var(--nice-text, #0f172a)"}),Nr={id:"default-dark",name:"Default Dark",category:"dark",themeSource:"Dark",config:ce({background:"var(--nice-text, #0f172a)",gridColor:"var(--nice-text, #334155)",gridSize:20,selectionColor:"var(--nice-primary-light, #60a5fa)"},Mr,Ce,{shadow:!1},{strokeColor:"var(--nice-text-secondary, #475569)"},{backgroundColor:"#60a5fa10",borderColor:"#3b82f680"})},Sr=ne({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:ce({background:"#f0f5ff",gridColor:"#93c5fd20",gridSize:20,selectionColor:"var(--nice-primary-dark, #1d4ed8)"},Sr,Ce,{borderWidth:2,borderRadius:6},{strokeColor:"var(--nice-primary-light, #93c5fd)",strokeWidth:2})},jr=ne({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-border, #e0e0e0)",textMuted:"var(--nice-text-secondary, #808080)",border:"#00ff8840",surface:"var(--nice-bg, #1a1a2e)",surfaceAlt:"var(--nice-bg, #16213e)"}),Ar={id:"neon-glow",name:"Neon Glow",category:"dark",config:ce({background:"#0a0a1a",gridColor:"#00ff8810",gridSize:20,selectionColor:"var(--nice-success, #00ff88)"},jr,mt,{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)"})},$r=ne({primary:"var(--nice-accent-pink, #ff2d95)",primaryLight:"#ff6db6",secondary:"#7928ca",accent:"#00d4ff",success:"#39ff14",warning:"var(--nice-warning, #FFD700)",error:"#ff073a",info:"#00d4ff",text:"var(--nice-bg, #fff)",textMuted:"#b0b0b0",border:"#ff2d9540",surface:"#1a0030",surfaceAlt:"#2d004a"}),zr={id:"cyberpunk",name:"Cyberpunk",category:"dark",config:ce({background:"#0d001a",gridColor:"#ff2d9510",gridSize:24,selectionColor:"var(--nice-accent-pink, #ff2d95)"},$r,mt,{borderColor:"var(--nice-accent-pink, #ff2d95)",borderWidth:2,glowColor:"var(--nice-accent-pink, #ff2d95)",glowIntensity:.7,shadow:!0,gradientColor:"#2d004a",gradientDirection:"vertical"},{strokeColor:"#7928ca80",strokeWidth:3},{},{glowColor:"var(--nice-accent-pink, #ff2d95)",glowIntensity:.9,particleColor:"#00d4ff",liquidColor:"var(--nice-accent-pink, #ff2d95)",liquidColorEnd:"#7928ca"})},Dr=ne({primary:"var(--nice-bg, #fff)",primaryLight:"#ffffffaa",secondary:"#4da6ff",accent:"var(--nice-bg, #fff)",text:"var(--nice-bg, #fff)",textMuted:"#ffffffaa",border:"#ffffff40",surface:"#1e3d6e",surfaceAlt:"#163050"}),Tr={id:"blueprint",name:"Technical Blueprint",category:"technical",config:ce({background:"#0a1929",gridColor:"#4da6ff30",gridSize:16,selectionColor:"var(--nice-bg, #fff)"},Dr,mt,{backgroundColor:"transparent",borderColor:"#4da6ff",borderWidth:1,borderStyle:"solid",fontColor:"var(--nice-bg, #fff)",shadow:!1},{strokeColor:"#4da6ff",strokeWidth:1,strokeDash:[4,4]},{backgroundColor:"transparent",borderColor:"#4da6ff40",borderStyle:"dashed",borderWidth:1})},Pr=ne({primary:"var(--nice-accent, #a78bfa)",primaryLight:"var(--nice-accent, #c4b5fd)",secondary:"var(--nice-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:ce({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=ne({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:ce({background:"#f0fdf4",gridColor:"#a7d7c520",gridSize:20,selectionColor:"var(--nice-success, #059669)"},Or,Ce,{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=ne({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:ce({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=ne({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-text, #000000)",surface:"var(--nice-bg, #fff)",surfaceAlt:"var(--nice-border, #eeeeee)"}),Br={id:"high-contrast",name:"High Contrast",category:"accessibility",themeSource:"High Contrast",config:ce({background:"var(--nice-bg, #fff)",gridColor:"#00000020",gridSize:20,selectionColor:"#0000ff"},Wr,"Arial, sans-serif",{borderColor:"var(--nice-text, #000000)",borderWidth:3,fontColor:"var(--nice-text, #000000)",fontWeight:"bold"},{strokeColor:"var(--nice-text, #000000)",strokeWidth:3},{borderColor:"var(--nice-text, #000000)",borderWidth:2})},qr=ne({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:ce({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=ne({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:ce({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=ne({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)"}),Hr={id:"sunset-warm",name:"Sunset Warm",category:"creative",config:ce({background:"#fffde7",gridColor:"#ffccbc20",gridSize:20,selectionColor:"var(--nice-warning-dark, #e65100)"},Xr,Ce,{borderColor:"#ff9e80",gradientColor:"var(--nice-warning-bg, #fff3e0)",gradientDirection:"vertical"},{strokeColor:"#ff9e80"},{},{liquidColor:"var(--nice-warning-dark, #e65100)",liquidColorEnd:"#ffd600",particleColor:"#ffd600"})},Ur=ne({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:ce({background:"#e0f7fa",gridColor:"#b2ebf220",gridSize:20,selectionColor:"#006064"},Ur,Ce,{borderColor:"#00838f",borderRadius:12},{strokeColor:"#4dd0e1"},{},{liquidColor:"#006064",liquidColorEnd:"#4dd0e1",particleColor:"#ffd54f"})},Zr=ne({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:ce({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=ne({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:ce({background:"var(--nice-bg, #fff)",gridColor:"#00000008",gridSize:16,selectionColor:"#ff6600"},Qr,"'Balsamiq Sans', 'Comic Sans MS', cursive",{backgroundColor:"transparent",borderColor:"var(--nice-text-muted, #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=ne({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:ce({background:"var(--nice-success-bg, #e8f5e9)",gridColor:"#a7ffeb20",gridSize:20,selectionColor:"#00bfa5"},ti,Ce,{borderColor:"#00bfa5",borderRadius:20,borderWidth:2,gradientColor:"#b2dfdb",gradientDirection:"radial"},{strokeColor:"#64ffda",strokeWidth:2},{borderRadius:16},{liquidColor:"#00bfa5",liquidColorEnd:"#64ffda",particleColor:"#ff6e40"})},ii=ne({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:ce({background:"var(--nice-bg-secondary, #fafafa)",gridColor:"#e0e0e020",gridSize:20,selectionColor:"#424242"},ii,Ce,{borderColor:"var(--nice-text-secondary, #9e9e9e)",borderWidth:1,shadow:!0,borderRadius:4},{strokeColor:"var(--nice-text-secondary, #9e9e9e)",strokeWidth:1.5})},si=ne({primary:"var(--nice-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"}),oi={id:"candy-pop",name:"Candy Pop",category:"creative",config:ce({background:"#fff0f5",gridColor:"#f8bbd020",gridSize:20,selectionColor:"var(--nice-accent-pink, #e91e63)"},si,"'Quicksand', 'Nunito', sans-serif",{borderColor:"var(--nice-accent-pink, #e91e63)",borderRadius:24,borderWidth:3,gradientColor:"#f3e5f5",gradientDirection:"diagonal"},{strokeColor:"#f48fb1",strokeWidth:3},{borderRadius:20,borderColor:"#f48fb1"},{glowColor:"var(--nice-accent-pink, #e91e63)",glowIntensity:.5,particleColor:"var(--nice-warning, #ffeb3b)"})},ni=ne({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:ce({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=ne({primary:"var(--nice-accent, #7c3aed)",primaryLight:"var(--nice-accent, #a78bfa)",secondary:"var(--nice-info, #06b6d4)",accent:"var(--nice-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-border, #e2e8f0)",textMuted:"var(--nice-text-muted, #94a3b8)",border:"#7c3aed40",surface:"#1e1b4b",surfaceAlt:"#312e81"}),di={id:"aurora-borealis",name:"Aurora Borealis",category:"dark",config:ce({background:"#0f0b2e",gridColor:"#7c3aed15",gridSize:24,selectionColor:"var(--nice-accent, #a78bfa)"},li,Ce,{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=ne({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:ce({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=ne({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-bg, #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:ce({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-bg, #fff)",fontWeight:"bold",borderRadius:12,shadow:!0},{strokeColor:"#90a4ae",strokeWidth:3},{backgroundColor:"#2196f320",borderWidth:2,borderRadius:16})},gi=ne({primary:"#9333ea",primaryLight:"var(--nice-accent, #c084fc)",secondary:"var(--nice-info, #6366f1)",accent:"var(--nice-warning, #f59e0b)",text:"var(--nice-bg-secondary, #f1f5f9)",textMuted:"var(--nice-accent, #a78bfa)",border:"#7c3aed40",surface:"#1c1033",surfaceAlt:"#2d1b69"}),mi={id:"midnight-purple",name:"Midnight Purple",category:"dark",config:ce({background:"#0f0720",gridColor:"#9333ea10",gridSize:20,selectionColor:"var(--nice-accent, #c084fc)"},gi,Ce,{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=[Cr,Nr,Ir,Gr,Yr,Ar,zr,Tr,Fr,Rr,Hr,Jr,Kr,Er,ei,Br,ri,ai,oi,ci,di,fi,pi,mi],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-border, #e2e8f0)",gradientDirection:"vertical"}},{id:"fill-gradient-h",name:"Horizontal Gradient",category:"fill",style:{gradientColor:"var(--nice-border, #e2e8f0)",gradientDirection:"horizontal"}},{id:"fill-gradient-d",name:"Diagonal Gradient",category:"fill",style:{gradientColor:"var(--nice-border, #e2e8f0)",gradientDirection:"diagonal"}},{id:"fill-gradient-r",name:"Radial Gradient",category:"fill",style:{gradientColor:"var(--nice-border, #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,s){const c=ne({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:s.color,surface:i.primary,surfaceAlt:i.secondary}),o=_i(i.primary);return{id:r,name:`${e} Theme`,category:"theme-based",themeSource:e,config:ce({background:i.primary,gridColor:o?`${s.color}40`:`${s.color}20`,gridSize:20,selectionColor:t.primary},c,Ce,{shadow:!o,borderWidth:o?1:2},{strokeColor:o?`${s.color}80`:s.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 Ci=["fadeIn","fadeOut","slideInLeft","slideInRight","slideInTop","slideInBottom","zoomIn","zoomOut","pulse","shake","highlight","flowPulse","bounce","glow","colorShift","liquidFill","expand","collapse","ripple","typewriter","morphShape","drawPath","particleTrail"],Mi=["linear","easeIn","easeOut","easeInOut","spring","bounce"],Ke=({animations:r,onAdd:e,onRemove:t,onUpdate:i,onPlay:a,onStop:s,isPlaying:c=!1,availableTargets:o=[],className:l})=>{const{t:f}=Ee(),[d,u]=y.useState(!1),[x,g]=y.useState(null),h=y.useCallback(()=>{if(!e||o.length===0)return;const m=o[0];e({name:`Animation ${r.length+1}`,targetId:m.id,targetType:m.type,effect:"fadeIn",startMs:r.length*500,durationMs:600,easing:"easeOut"})},[e,r.length,o]),b=y.useCallback(m=>{if(!e||o.length===0)return;const S=o[0];e({name:m.name,targetId:S.id,targetType:S.type,effect:m.effect,startMs:r.length*500,durationMs:m.durationMs,easing:m.easing}),u(!1)},[e,r.length,o]),v=Math.max(2e3,...r.map(m=>m.startMs+m.durationMs+(m.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:f("animation.timeline")}),n.jsxs("div",{className:"nice-diagram-timeline__controls",children:[c?n.jsxs(N.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:s,children:["⏹ ",f("animation.stop")]}):n.jsxs(N.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:a,children:["▶ ",f("animation.play")]}),n.jsxs(N.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:h,disabled:o.length===0,children:["+ ",f("animation.add")]}),n.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[n.jsx(N.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:()=>u(m=>!m),disabled:o.length===0,title:"Add from preset",children:"🎬 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(m=>n.jsx(N.NiceButton,{variant:"ghost",size:"sm",onClick:()=>b(m),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 10px",fontSize:12,borderBottom:"1px solid var(--nice-bg-secondary, #f0f0f0)"},title:`${m.effect} — ${m.durationMs}ms ${m.easing}`,children:m.name},m.id))})]})]})]}),n.jsxs("div",{className:"nice-diagram-timeline__tracks",children:[r.length===0&&n.jsx("p",{className:"nice-diagram-timeline__empty",children:f("animation.noAnimations")}),r.map(m=>{const S=m.startMs/v*100,_=m.durationMs/v*100,I=x===m.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:m.id),style:{cursor:"pointer"},title:"Click to edit",children:m.name}),n.jsx("span",{className:"nice-diagram-timeline__track-effect",children:m.effect}),n.jsx(N.NiceButton,{className:"nice-diagram-timeline__track-remove",variant:"ghost",size:"sm",onClick:()=>t==null?void 0:t(m.id),title:f("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(N.NiceSelect,{value:m.effect,onChange:C=>i==null?void 0:i(m.id,{effect:C}),options:Ci.map(C=>({value:C,label:C})),style:{fontSize:11,padding:"1px 4px"}}),n.jsx(N.NiceSelect,{value:m.easing,onChange:C=>i==null?void 0:i(m.id,{easing:C}),options:Mi.map(C=>({value:C,label:C})),style:{fontSize:11,padding:"1px 4px"}}),n.jsx(N.NiceSelect,{value:m.targetId,onChange:C=>{const w=o.find(j=>j.id===C);w&&(i==null||i(m.id,{targetId:w.id,targetType:w.type}))},options:o.map(C=>({value:C.id,label:C.label})),style:{fontSize:11,padding:"1px 4px",maxWidth:100}}),n.jsx(N.NiceNumberInput,{value:m.startMs,min:0,step:100,onChange:C=>i==null?void 0:i(m.id,{startMs:C??0}),style:{width:60,fontSize:11},title:"Start (ms)"}),n.jsx(N.NiceNumberInput,{value:m.durationMs,min:50,step:50,onChange:C=>i==null?void 0:i(m.id,{durationMs:C??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:`${_}%`},title:`${m.effect} ${m.startMs}ms → ${m.startMs+m.durationMs}ms (${m.easing})`})})]},m.id)})]}),n.jsx("div",{className:"nice-diagram-timeline__ruler",children:Array.from({length:5}).map((m,S)=>{const _=Math.round(v/4*S);return n.jsxs("span",{className:"nice-diagram-timeline__ruler-mark",style:{left:`${S/4*100}%`},children:[_,"ms"]},S)})})]})};Ke.displayName="AnimationTimeline";const Ni=.1,Si=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:s,selectedId:c,selectedIds:o=[],onSelectElement:l,onMultiSelect:f,onNodeDragStart:d,onNodeDrag:u,onNodeDragEnd:x,onNodeResize:g,onNodeLabelChange:h,animationStates:b,particleState:v,viewMode:m="editor",ghostOpacity:S=.15,onGroupCollapse:_,onNodeCollapse:I,onInteraction:C,interactive:w=!1,showGrid:j=!0,showRulers:F=!1,snapToGrid:O=!0,gridSnapSize:Y=10,className:R})=>{const M=y.useRef(null),[z,q]=y.useState(!1),[V,T]=y.useState({x:0,y:0}),[E,X]=y.useState(null),[B,K]=y.useState({x:0,y:0}),[Z,L]=y.useState(null),[G,le]=y.useState(null),[re,fe]=y.useState(null),[xe,be]=y.useState(null),[De,Te]=y.useState(""),[it,pe]=y.useState([]),at=(s==null?void 0:s.canvasBackground)??"var(--nice-bg-secondary, #f8f9fa)",Le=(s==null?void 0:s.gridColor)??"var(--nice-border, #e0e0e0)",Me=(s==null?void 0:s.gridSize)??20,Ne=(s==null?void 0:s.selectionColor)??"var(--nice-primary, #2196f3)",Fe=y.useMemo(()=>{const p=new Set(o);return c&&p.add(c),p},[c,o]),me=y.useCallback(p=>O?Math.round(p/Y)*Y:p,[O,Y]),We=y.useCallback((p,k,A)=>{const D=[],$=k.x,P=k.y,Q=$+A.width/2,U=P+A.height/2,J=$+A.width,te=P+A.height;for(const de of r){if(de.id===p)continue;const ae=de.position.x,se=de.position.y,ue=ae+de.size.width/2,ke=se+de.size.height/2,Se=ae+de.size.width,_e=se+de.size.height;Math.abs($-ae)<5&&D.push({x:ae}),Math.abs(J-Se)<5&&D.push({x:Se}),Math.abs(Q-ue)<5&&D.push({x:ue}),Math.abs($-Se)<5&&D.push({x:Se}),Math.abs(J-ae)<5&&D.push({x:ae}),Math.abs(P-se)<5&&D.push({y:se}),Math.abs(te-_e)<5&&D.push({y:_e}),Math.abs(U-ke)<5&&D.push({y:ke}),Math.abs(P-_e)<5&&D.push({y:_e}),Math.abs(te-se)<5&&D.push({y:se})}pe(D)},[r]),we=y.useCallback(p=>{if(p.preventDefault(),!a)return;const k=p.deltaY>0?.9:1.1,A=Math.min(Si,Math.max(Ni,i.zoom*k)),D=M.current;if(!D)return;const W=D.getBoundingClientRect(),$=p.clientX-W.left,P=p.clientY-W.top,Q=A/i.zoom,U=$-($-i.x)*Q,J=P-(P-i.y)*Q;a({x:U,y:J,zoom:A})},[i,a]),st=y.useCallback(p=>{if(p.button===1||p.button===0&&p.target.tagName==="svg"){if(p.button===0&&w&&!p.shiftKey&&p.target.tagName==="svg"){const k=M.current;if(k){const A=k.getBoundingClientRect(),D=(p.clientX-A.left-i.x)/i.zoom,W=(p.clientY-A.top-i.y)/i.zoom;le({x:D,y:W}),L({x1:D,y1:W,x2:D,y2:W})}l&&l(null),f&&f([]);return}q(!0),T({x:p.clientX-i.x,y:p.clientY-i.y}),l&&p.button===0&&l(null)}},[i,l,f,w]),$e=y.useCallback(p=>{if(G){const k=M.current;if(!k)return;const A=k.getBoundingClientRect(),D=(p.clientX-A.left-i.x)/i.zoom,W=(p.clientY-A.top-i.y)/i.zoom;L({x1:G.x,y1:G.y,x2:D,y2:W});return}if(z&&a){a({...i,x:p.clientX-V.x,y:p.clientY-V.y});return}if(re&&g){const k=M.current;if(!k)return;const A=k.getBoundingClientRect(),D=(p.clientX-A.left-i.x)/i.zoom,W=(p.clientY-A.top-i.y)/i.zoom,$=D-re.startMouse.x,P=W-re.startMouse.y,Q=dt[re.handleIdx];let U=re.startSize.width+$*Q.resizeX,J=re.startSize.height+P*Q.resizeY,te=re.startPos.x+(Q.resizeX<0?$:0),de=re.startPos.y+(Q.resizeY<0?P:0);U=Math.max(30,me(U)),J=Math.max(20,me(J)),te=me(te),de=me(de),g(re.nodeId,{width:U,height:J},{x:te,y:de});return}if(E&&u){const k=M.current;if(!k)return;const A=k.getBoundingClientRect(),D=me((p.clientX-A.left-i.x)/i.zoom-B.x),W=me((p.clientY-A.top-i.y)/i.zoom-B.y);u(E,{x:D,y:W});const $=r.find(P=>P.id===E);$&&We(E,{x:D,y:W},$.size)}},[G,z,a,i,V,re,g,E,u,B,me,r,We]),Be=y.useCallback(p=>{if(Z&&G){const k=Math.min(Z.x1,Z.x2),A=Math.min(Z.y1,Z.y2),D=Math.max(Z.x1,Z.x2),W=Math.max(Z.y1,Z.y2);if(Math.abs(D-k)>5||Math.abs(W-A)>5){const $=r.filter(P=>{const Q=P.position.x,U=P.position.y,J=Q+P.size.width,te=U+P.size.height;return J>k&&Q<D&&te>A&&U<W}).map(P=>P.id);f==null||f($),$.length===1&&(l==null||l($[0]))}L(null),le(null);return}if(z&&q(!1),re){fe(null);return}if(E&&x){const k=M.current;if(!k)return;const A=k.getBoundingClientRect(),D=me((p.clientX-A.left-i.x)/i.zoom-B.x),W=me((p.clientY-A.top-i.y)/i.zoom-B.y);x(E,{x:D,y:W})}X(null),pe([])},[Z,G,z,re,E,x,i,B,me,r,f,l]),qe=y.useCallback((p,k)=>{if(p.stopPropagation(),!w)return;const A=r.find(Q=>Q.id===k);if(!A||A.locked)return;if(p.shiftKey&&f){const Q=[...o],U=Q.indexOf(k);U>=0?Q.splice(U,1):Q.push(k),f(Q);return}l==null||l(k);const D=M.current;if(!D)return;const W=D.getBoundingClientRect(),$=(p.clientX-W.left-i.x)/i.zoom,P=(p.clientY-W.top-i.y)/i.zoom;K({x:$-A.position.x,y:P-A.position.y}),X(k),d==null||d(k)},[w,r,i,l,d,f,o]),ot=y.useCallback((p,k,A)=>{if(p.stopPropagation(),!w)return;const D=r.find(U=>U.id===k);if(!D||D.locked)return;const W=M.current;if(!W)return;const $=W.getBoundingClientRect(),P=(p.clientX-$.left-i.x)/i.zoom,Q=(p.clientY-$.top-i.y)/i.zoom;fe({nodeId:k,handleIdx:A,startMouse:{x:P,y:Q},startPos:{...D.position},startSize:{...D.size}}),l==null||l(k)},[w,r,i,l]),nt=y.useCallback((p,k)=>{if(p.stopPropagation(),!w||!h)return;const A=r.find(D=>D.id===k);!A||A.locked||(be(k),Te(A.label))},[w,r,h]),Ge=y.useCallback(()=>{xe&&h&&h(xe,De),be(null)},[xe,De,h]),H=y.useCallback((p,k)=>{p.stopPropagation(),l==null||l(k)},[l]),je=y.useCallback(p=>{const k=r.find(A=>A.id===p);return k?{x:k.position.x+k.size.width/2,y:k.position.y+k.size.height/2}:{x:0,y:0}},[r]),ge=y.useCallback((p,k)=>{const A=r.find(P=>P.id===p);if(!A)return{x:0,y:0};const D=A.ports.find(P=>P.id===k);if(!D)return je(p);const{position:W,size:$}=A;switch(D.side){case"top":return{x:W.x+$.width*D.offset,y:W.y};case"bottom":return{x:W.x+$.width*D.offset,y:W.y+$.height};case"left":return{x:W.x,y:W.y+$.height*D.offset};case"right":return{x:W.x+$.width,y:W.y+$.height*D.offset};default:return je(p)}},[r,je]),nr=y.useCallback(p=>{const k=ge(p.sourceNodeId,p.sourcePortId),A=ge(p.targetNodeId,p.targetPortId);switch(p.style.lineType??"bezier"){case"straight":return`M ${k.x} ${k.y} L ${A.x} ${A.y}`;case"orthogonal":{const W=(k.x+A.x)/2;return`M ${k.x} ${k.y} L ${W} ${k.y} L ${W} ${A.y} L ${A.x} ${A.y}`}case"step":{const W=(k.y+A.y)/2;return`M ${k.x} ${k.y} L ${k.x} ${W} L ${A.x} ${W} L ${A.x} ${A.y}`}case"bezier":default:{const W=Math.abs(A.x-k.x)*.5;return`M ${k.x} ${k.y} C ${k.x+W} ${k.y}, ${A.x-W} ${A.y}, ${A.x} ${A.y}`}}},[ge]),cr=y.useCallback((p,k)=>{const{size:A,style:D,shape:W}=p,$=A.width,P=A.height,U=!!(D.gradientColor&&D.backgroundColor)?`url(#${k})`:D.backgroundColor??"var(--nice-bg, #fff)",J=D.borderColor??"var(--nice-text, #333333)",te=D.borderWidth??1,de=D.borderRadius??(W==="roundedRect"?8:0),ae=D.borderStyle==="dashed"?"8,4":D.borderStyle==="dotted"?"2,4":void 0,se=D.shadow?"url(#nd-shadow)":void 0;switch(W){case"ellipse":case"circle":return n.jsx("ellipse",{cx:$/2,cy:P/2,rx:$/2,ry:P/2,fill:U,stroke:J,strokeWidth:te,strokeDasharray:ae,filter:se});case"diamond":return n.jsx("polygon",{points:`${$/2},0 ${$},${P/2} ${$/2},${P} 0,${P/2}`,fill:U,stroke:J,strokeWidth:te,strokeDasharray:ae,filter:se});case"hexagon":{const ue=$/4;return n.jsx("polygon",{points:`${ue},0 ${$-ue},0 ${$},${P/2} ${$-ue},${P} ${ue},${P} 0,${P/2}`,fill:U,stroke:J,strokeWidth:te,strokeDasharray:ae,filter:se})}case"parallelogram":{const ue=$*.15;return n.jsx("polygon",{points:`${ue},0 ${$},0 ${$-ue},${P} 0,${P}`,fill:U,stroke:J,strokeWidth:te,strokeDasharray:ae,filter:se})}case"cylinder":return n.jsxs("g",{filter:se,children:[n.jsx("ellipse",{cx:$/2,cy:P*.1,rx:$/2,ry:P*.1,fill:U,stroke:J,strokeWidth:te}),n.jsx("rect",{x:0,y:P*.1,width:$,height:P*.8,fill:U,stroke:"none"}),n.jsx("line",{x1:0,y1:P*.1,x2:0,y2:P*.9,stroke:J,strokeWidth:te}),n.jsx("line",{x1:$,y1:P*.1,x2:$,y2:P*.9,stroke:J,strokeWidth:te}),n.jsx("ellipse",{cx:$/2,cy:P*.9,rx:$/2,ry:P*.1,fill:U,stroke:J,strokeWidth:te})]});case"triangle":return n.jsx("polygon",{points:`${$/2},0 ${$},${P} 0,${P}`,fill:U,stroke:J,strokeWidth:te,strokeDasharray:ae,filter:se});case"cloud":{const ue=`M${$*.25},${P*.8} A${$*.2},${$*.2},0,1,1,${$*.15},${P*.45} A${$*.18},${$*.18},0,1,1,${$*.35},${P*.2} A${$*.2},${$*.2},0,1,1,${$*.65},${P*.2} A${$*.18},${$*.18},0,1,1,${$*.85},${P*.45} A${$*.2},${$*.2},0,1,1,${$*.75},${P*.8} Z`;return n.jsx("path",{d:ue,fill:U,stroke:J,strokeWidth:te,filter:se})}case"document":{const ue=`M 0 0 L ${$} 0 L ${$} ${P*.85} Q ${$*.75} ${P*.7}, ${$*.5} ${P*.85} Q ${$*.25} ${P}, 0 ${P*.85} Z`;return n.jsx("path",{d:ue,fill:U,stroke:J,strokeWidth:te,filter:se})}case"actor":return n.jsxs("g",{stroke:J,strokeWidth:te,fill:"none",filter:se,children:[n.jsx("circle",{cx:$/2,cy:P*.15,r:P*.12,fill:U}),n.jsx("line",{x1:$/2,y1:P*.27,x2:$/2,y2:P*.6}),n.jsx("line",{x1:$*.15,y1:P*.4,x2:$*.85,y2:P*.4}),n.jsx("line",{x1:$/2,y1:P*.6,x2:$*.2,y2:P}),n.jsx("line",{x1:$/2,y1:P*.6,x2:$*.8,y2:P})]});case"rectangle":case"roundedRect":case"custom":default:return n.jsx("rect",{width:$,height:P,rx:de,ry:de,fill:U,stroke:J,strokeWidth:te,strokeDasharray:ae,filter:se})}},[]),wt=y.useCallback(p=>{if(!b)return{};const k=b.get(p);if(!k)return{};const A=k.glow>0?`drop-shadow(0 0 ${k.glow}px gold)`:"",D=k.highlightColor?`drop-shadow(0 0 6px ${k.highlightColor})`:"";return{opacity:k.opacity,transform:`translate(${k.translateX}px, ${k.translateY}px) scale(${k.scale})`,filter:[A,D].filter(Boolean).join(" ")||void 0}},[b]),lr=y.useMemo(()=>{if(!v)return null;const p=[];for(const[,k]of v.glowStates){const A=zt(k.elementId),D=Dt(k.intensity,k.pulse);p.push(n.jsxs("filter",{id:A,x:"-50%",y:"-50%",width:"200%",height:"200%",children:[n.jsx("feGaussianBlur",{in:"SourceGraphic",stdDeviation:D,result:"blur"}),n.jsx("feFlood",{floodColor:k.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"})]})]},A))}return p},[v]),dr=y.useMemo(()=>{if(!v)return null;const p=[];for(const[k,A]of v.liquidFlows){if(!A.active)continue;const D=e.find(U=>U.id===k);if(!(D!=null&&D.style.liquidFlow))continue;const{color:W,colorEnd:$}=D.style.liquidFlow,P=`nd-liquid-${k}`,Q=A.gradientOffset;p.push(n.jsxs("linearGradient",{id:P,x1:"0",y1:"0",x2:"1",y2:"0",children:[n.jsx("stop",{offset:`${Q*100%100}%`,stopColor:W,stopOpacity:.8}),n.jsx("stop",{offset:`${(Q+.3)*100%100}%`,stopColor:$??W,stopOpacity:.4}),n.jsx("stop",{offset:`${(Q+.6)*100%100}%`,stopColor:W,stopOpacity:.8})]},P))}return p},[v,e]),ur=y.useMemo(()=>r.filter(p=>p.style.gradientColor&&p.style.backgroundColor).map(p=>{const k=`nd-grad-${p.id}`,A=p.style.gradientDirection??"vertical";if(A==="radial")return n.jsxs("radialGradient",{id:k,children:[n.jsx("stop",{offset:"0%",stopColor:p.style.backgroundColor}),n.jsx("stop",{offset:"100%",stopColor:p.style.gradientColor})]},k);const D=A==="horizontal"||A==="diagonal"?"1":"0",W=A==="vertical"||A==="diagonal"?"1":"0";return n.jsxs("linearGradient",{id:k,x1:"0",y1:"0",x2:D,y2:W,children:[n.jsx("stop",{offset:"0%",stopColor:p.style.backgroundColor}),n.jsx("stop",{offset:"100%",stopColor:p.style.gradientColor})]},k)}),[r]);return n.jsxs("svg",{ref:M,className:`nice-diagram-canvas ${R??""}`,style:{width:"100%",height:"100%",background:at,cursor:z?"grabbing":re&&re.nodeId?dt[re.handleIdx].cursor:"default"},onWheel:we,onMouseDown:st,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",markerWidth:"8",markerHeight:"8",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",markerWidth:"8",markerHeight:"8",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",markerWidth:"10",markerHeight:"10",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",markerWidth:"8",markerHeight:"8",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"})}),j&&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(p=>p.style.glowColor).map(p=>{const k=`nd-node-glow-${p.id}`,A=(p.style.glowIntensity??.5)*10;return n.jsxs("filter",{id:k,x:"-50%",y:"-50%",width:"200%",height:"200%",children:[n.jsx("feGaussianBlur",{in:"SourceGraphic",stdDeviation:A,result:"blur"}),n.jsx("feFlood",{floodColor:p.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"})]})]},k)})]}),F&&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},(p,k)=>{const A=k*Me*i.zoom+i.x,D=k*Me;return A>20?n.jsxs("g",{children:[n.jsx("line",{x1:A,y1:"0",x2:A,y2:"20",stroke:"var(--nice-text-muted, #999)",strokeWidth:"0.5"}),n.jsx("text",{x:A+2,y:"14",fontSize:"9",fill:"var(--nice-text-secondary, #666)",children:D})]},`rx${k}`):null}),Array.from({length:100},(p,k)=>{const A=k*Me*i.zoom+i.y,D=k*Me;return A>20?n.jsxs("g",{children:[n.jsx("line",{x1:"0",y1:A,x2:"20",y2:A,stroke:"var(--nice-text-muted, #999)",strokeWidth:"0.5"}),n.jsx("text",{x:"2",y:A-2,fontSize:"9",fill:"var(--nice-text-secondary, #666)",writingMode:"tb",children:D})]},`ry${k}`):null})]}),n.jsxs("g",{transform:`translate(${i.x}, ${i.y}) scale(${i.zoom})`,children:[j&&n.jsx("rect",{x:"-10000",y:"-10000",width:"20000",height:"20000",fill:"url(#nd-grid)"}),t.map(p=>{var Q,U,J,te,de,ae,se,ue,ke,Se,_e,Ve;const k=r.filter(oe=>p.nodeIds.includes(oe.id));if(k.length===0&&!p.collapsed)return null;const A=((Q=p.style)==null?void 0:Q.padding)??20;if(p.collapsed){const oe=r.find(ct=>p.nodeIds.includes(ct.id)),Pe=oe?oe.position.x:0,Ye=oe?oe.position.y:0;return n.jsxs("g",{style:{cursor:"pointer"},onClick:()=>_==null?void 0:_(p.id),children:[n.jsx("rect",{x:Pe,y:Ye,width:160,height:40,fill:((U=p.style)==null?void 0:U.backgroundColor)??"rgba(200,200,255,0.3)",stroke:((J=p.style)==null?void 0:J.borderColor)??"var(--nice-text-muted, #aab)",strokeWidth:((te=p.style)==null?void 0:te.borderWidth)??1,rx:((de=p.style)==null?void 0:de.borderRadius)??6,strokeDasharray:"6,3"}),n.jsxs("text",{x:Pe+24,y:Ye+24,fontSize:"12",fill:((ae=p.style)==null?void 0:ae.labelColor)??"var(--nice-text-secondary, #666)",fontWeight:"bold",children:["▶ ",p.label," (",p.nodeIds.length,")"]})]},p.id)}const D=Math.min(...k.map(oe=>oe.position.x))-A,W=Math.min(...k.map(oe=>oe.position.y))-A,$=Math.max(...k.map(oe=>oe.position.x+oe.size.width))+A,P=Math.max(...k.map(oe=>oe.position.y+oe.size.height))+A;return n.jsxs("g",{children:[n.jsx("rect",{x:D,y:W,width:$-D,height:P-W,fill:((se=p.style)==null?void 0:se.backgroundColor)??"rgba(200,200,255,0.1)",stroke:((ue=p.style)==null?void 0:ue.borderColor)??"var(--nice-text-muted, #aab)",strokeWidth:((ke=p.style)==null?void 0:ke.borderWidth)??1,rx:((Se=p.style)==null?void 0:Se.borderRadius)??6,strokeDasharray:((_e=p.style)==null?void 0:_e.borderStyle)==="dashed"?"6,3":void 0}),n.jsx("text",{x:D+6,y:W-4,fontSize:"12",fill:((Ve=p.style)==null?void 0:Ve.labelColor)??"var(--nice-text-secondary, #666)",fontWeight:"bold",children:p.label}),(w||m!=="editor")&&_&&n.jsxs("g",{style:{cursor:"pointer"},onClick:oe=>{oe.stopPropagation(),_(p.id)},children:[n.jsx("rect",{x:$-24,y:W-12,width:20,height:20,rx:4,fill:"white",stroke:"var(--nice-text-muted, #999)",strokeWidth:1}),n.jsx("text",{x:$-14,y:W+3,textAnchor:"middle",fontSize:"12",fill:"var(--nice-text-secondary, #666)",children:"▼"})]})]},p.id)}),it.map((p,k)=>n.jsx("line",{x1:p.x!=null?p.x:-1e4,y1:p.y!=null?p.y:-1e4,x2:p.x!=null?p.x:1e4,y2:p.y!=null?p.y:1e4,stroke:"#ff4081",strokeWidth:.5,strokeDasharray:"4,4"},`snap-${k}`)),e.map(p=>{var de;const k=nr(p),A=Fe.has(p.id),D=p.style.targetArrow==="diamond"?"url(#nd-diamond-marker)":p.style.targetArrow==="circle"?"url(#nd-circle-marker)":p.style.targetArrow==="openArrow"?"url(#nd-open-arrow)":p.style.targetArrow!=="none"?"url(#nd-arrow)":void 0,W=p.style.sourceArrow==="diamond"?"url(#nd-diamond-marker)":p.style.sourceArrow==="circle"?"url(#nd-circle-marker)":p.style.sourceArrow==="openArrow"?"url(#nd-open-arrow)":p.style.sourceArrow==="arrow"?"url(#nd-arrow)":void 0,$=wt(p.id),P=b==null?void 0:b.get(p.id),Q=P==null?void 0:P.strokeProgress,U=Q!=null&&Q>=0&&Q<1?{strokeDasharray:"1000",strokeDashoffset:`${1e3*(1-Q)}`}:void 0,J=p.style.liquidFlow,te=v==null?void 0:v.liquidFlows.get(p.id);return n.jsxs("g",{style:$,onClick:ae=>H(ae,p.id),children:[w&&n.jsx("path",{d:k,fill:"none",stroke:"transparent",strokeWidth:12,style:{cursor:"pointer"}}),(J==null?void 0:J.active)&&n.jsx("path",{d:k,fill:"none",stroke:`url(#nd-liquid-${p.id})`,strokeWidth:J.pipeWidth??(p.style.strokeWidth??1.5)*4,strokeLinecap:"round",opacity:.5}),n.jsx("path",{d:k,fill:"none",stroke:A?Ne:p.style.strokeColor??"var(--nice-text, #333)",strokeWidth:p.style.strokeWidth??1.5,strokeDasharray:(U==null?void 0:U.strokeDasharray)??((de=p.style.strokeDash)==null?void 0:de.join(","))??(p.style.animated?"6,4":void 0),strokeDashoffset:U==null?void 0:U.strokeDashoffset,markerEnd:D,markerStart:W,opacity:p.style.opacity??1,style:w?{cursor:"pointer",transition:U?void 0:"stroke-dashoffset 0.1s"}:void 0}),p.style.animated&&n.jsx("circle",{r:3,fill:Ne,children:n.jsx("animateMotion",{dur:`${1/(p.style.flowSpeed||1)}s`,repeatCount:"indefinite",path:k})}),(te==null?void 0:te.active)&&te.particles.map((ae,se)=>n.jsx("circle",{r:ae.size,fill:(J==null?void 0:J.color)??"var(--nice-primary, #3b82f6)",opacity:ae.opacity*.6,children:n.jsx("animateMotion",{dur:`${3/(((J==null?void 0:J.speed)??1)+.5)}s`,repeatCount:"indefinite",path:k,begin:`${ae.t*3}s`})},`lp-${p.id}-${se}`)),P&&P.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:k,begin:`${P.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:k,begin:`${(P.particleTrailT+.1)*2}s`})})]}),p.label&&(()=>{const ae=ge(p.sourceNodeId,p.sourcePortId),se=ge(p.targetNodeId,p.targetPortId),ue=(ae.x+se.x)/2,ke=(ae.y+se.y)/2;return n.jsxs("g",{children:[n.jsx("rect",{x:ue-4,y:ke-16,width:p.label.length*7+8,height:18,rx:3,fill:"white",fillOpacity:.85}),n.jsx("text",{x:ue,y:ke-2,textAnchor:"start",fontSize:"11",fill:"var(--nice-text-secondary, #555)",children:p.label})]})})()]},p.id)}),r.filter(p=>!p.hidden||m==="editor").map(p=>{const k=Fe.has(p.id),A=wt(p.id),D=b==null?void 0:b.get(p.id),W=p.style.fontFamily??(s==null?void 0:s.fontFamily)??"sans-serif",$=p.style.fontSize??14,P=p.style.fontColor??"var(--nice-text, #222)",Q=p.style.fontWeight??"normal",U=p.style.fontStyle??"normal",J=p.style.textAlign??"center",te=p.style.rotation??0,de=`nd-grad-${p.id}`,ae=!!p.hidden,se=ae?S??.3:p.style.opacity??1,ue=p.style.glowColor?`url(#nd-node-glow-${p.id})`:void 0,ke=J==="left"?"start":J==="right"?"end":"middle",Se=J==="left"?8:J==="right"?p.size.width-8:p.size.width/2,_e=D==null?void 0:D.typewriterChars,Ve=_e!=null&&_e>=0?p.label.slice(0,_e):p.label,oe=D==null?void 0:D.liquidFillProgress,Pe=D==null?void 0:D.rippleRadius,Ye=D==null?void 0:D.rippleOpacity,ct=p.childNodeIds&&p.childNodeIds.length>0,fr=!!p.collapsed;return n.jsxs("g",{transform:`translate(${p.position.x}, ${p.position.y})${te?` rotate(${te}, ${p.size.width/2}, ${p.size.height/2})`:""}`,style:{...A,cursor:ae?"pointer":w&&!p.locked?"grab":"default",opacity:se,filter:ue},onMouseDown:he=>qe(he,p.id),onDoubleClick:he=>nt(he,p.id),onClick:he=>{he.stopPropagation(),l==null||l(p.id),p.interactions&&p.interactions.length>0&&p.interactions.filter(Oe=>Oe.trigger==="click").forEach(Oe=>C==null?void 0:C(p.id,Oe.id))},onMouseEnter:()=>{p.interactions&&p.interactions.filter(Ie=>Ie.trigger==="hover").forEach(Ie=>C==null?void 0:C(p.id,Ie.id))},children:[ae&&n.jsx("rect",{x:-1,y:-1,width:p.size.width+2,height:p.size.height+2,fill:"none",stroke:"var(--nice-text-muted, #999)",strokeWidth:1,strokeDasharray:"3,3",rx:4,opacity:.5}),cr(p,de),oe!=null&&oe>0&&oe<1&&n.jsx("clipPath",{id:`nd-liquid-clip-${p.id}`,children:n.jsx("rect",{x:0,y:p.size.height*(1-oe),width:p.size.width,height:p.size.height*oe})}),oe!=null&&oe>0&&oe<1&&n.jsx("rect",{x:0,y:0,width:p.size.width,height:p.size.height,fill:p.style.glowColor??"var(--nice-primary, #3b82f6)",opacity:.25,rx:p.style.borderRadius??4,clipPath:`url(#nd-liquid-clip-${p.id})`}),Pe!=null&&Pe>0&&n.jsx("circle",{cx:p.size.width/2,cy:p.size.height/2,r:Pe,fill:"none",stroke:p.style.glowColor??Ne,strokeWidth:2,opacity:Ye??.5}),k&&n.jsx("rect",{x:-3,y:-3,width:p.size.width+6,height:p.size.height+6,fill:"none",stroke:Ne,strokeWidth:2,strokeDasharray:"4,3",rx:6}),k&&w&&!p.locked&&dt.map((he,Ie)=>n.jsx("rect",{x:he.dx*p.size.width-Xe/2,y:he.dy*p.size.height-Xe/2,width:Xe,height:Xe,fill:"white",stroke:Ne,strokeWidth:1.5,rx:1,style:{cursor:he.cursor},onMouseDown:Oe=>ot(Oe,p.id,Ie)},Ie)),xe===p.id?n.jsx("foreignObject",{x:4,y:4,width:p.size.width-8,height:p.size.height-8,children:n.jsx("input",{xmlns:"http://www.w3.org/1999/xhtml",type:"text",value:De,onChange:he=>Te(he.target.value),onBlur:Ge,onKeyDown:he=>{he.key==="Enter"&&Ge(),he.key==="Escape"&&be(null)},autoFocus:!0,style:{width:"100%",height:"100%",border:"1px solid "+Ne,borderRadius:3,padding:"2px 4px",fontSize:$,fontFamily:W,fontWeight:Q,fontStyle:U,textAlign:J,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",outline:"none"}})}):n.jsxs(n.Fragment,{children:[n.jsx("text",{x:Se,y:p.size.height/2+(p.description?-4:0),textAnchor:ke,dominantBaseline:"central",fontFamily:W,fontSize:$,fontWeight:Q,fontStyle:U,fill:P,pointerEvents:"none",children:Ve}),p.description&&n.jsx("text",{x:Se,y:p.size.height/2+$*.8,textAnchor:ke,dominantBaseline:"central",fontFamily:W,fontSize:$*.75,fill:"var(--nice-text-secondary, #777)",pointerEvents:"none",children:p.description}),p.icon&&n.jsx("text",{x:p.size.width/2,y:14,textAnchor:"middle",fontSize:16,pointerEvents:"none",children:p.icon}),p.style.linkUrl&&n.jsx("text",{x:p.size.width-4,y:12,textAnchor:"end",fontSize:10,fill:"var(--nice-primary-hover, #1976d2)",pointerEvents:"none",children:"🔗"}),ct&&w&&n.jsxs("g",{onClick:he=>{he.stopPropagation(),I==null||I(p.id)},style:{cursor:"pointer"},children:[n.jsx("rect",{x:p.size.width-18,y:p.size.height-18,width:16,height:16,rx:3,fill:"white",stroke:"var(--nice-text-muted, #aaa)",strokeWidth:.5}),n.jsx("text",{x:p.size.width-10,y:p.size.height-7,textAnchor:"middle",dominantBaseline:"central",fontSize:10,fill:"var(--nice-text-secondary, #666)",children:fr?"▶":"▼"})]})]}),w&&p.ports.map(he=>{const Ie=Ii(p,he.id);return n.jsx("circle",{cx:Ie.x,cy:Ie.y,r:4,fill:"var(--nice-bg, #fff)",stroke:"var(--nice-text-secondary, #666)",strokeWidth:1,style:{cursor:"crosshair"}},he.id)})]},p.id)}),v&&v.particles.length>0&&n.jsx("g",{className:"nd-particle-overlay",children:v.particles.map((p,k)=>n.jsx("circle",{cx:p.x,cy:p.y,r:p.size,fill:p.color,opacity:p.opacity},`ptcl-${k}`))}),Z&&n.jsx("rect",{x:Math.min(Z.x1,Z.x2),y:Math.min(Z.y1,Z.y2),width:Math.abs(Z.x2-Z.x1),height:Math.abs(Z.y2-Z.y1),fill:"rgba(33,150,243,0.1)",stroke:Ne,strokeWidth:1,strokeDasharray:"4,2"})]})]})};function Ii(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:s=600,width:c=ji,height:o=Ai,className:l})=>{const f=y.useMemo(()=>{if(r.length===0)return{minX:0,minY:0,maxX:400,maxY:300};let b=1/0,v=1/0,m=-1/0,S=-1/0;for(const I of r)b=Math.min(b,I.position.x),v=Math.min(v,I.position.y),m=Math.max(m,I.position.x+I.size.width),S=Math.max(S,I.position.y+I.size.height);const _=50;return{minX:b-_,minY:v-_,maxX:m+_,maxY:S+_}},[r]),d=f.maxX-f.minX,u=f.maxY-f.minY,x=Math.min(c/d,o/u),g=y.useMemo(()=>{const b=(-t.x/t.zoom-f.minX)*x,v=(-t.y/t.zoom-f.minY)*x,m=a/t.zoom*x,S=s/t.zoom*x;return{x:b,y:v,w:m,h:S}},[t,f,x,a,s]),h=y.useCallback(b=>{if(!i)return;const v=b.currentTarget.getBoundingClientRect(),m=b.clientX-v.left,S=b.clientY-v.top,_=m/x+f.minX,I=S/x+f.minY;i({...t,x:-(_*t.zoom-a/2),y:-(I*t.zoom-s/2)})},[i,t,x,f,a,s]);return n.jsxs("svg",{className:`nice-diagram-minimap ${l??""}`,width:c,height:o,style:{border:"1px solid var(--nice-border, #ccc)",background:"var(--nice-bg, #fff)",borderRadius:4,cursor:"pointer"},onClick:h,children:[e.map(b=>{const v=r.find(w=>w.id===b.sourceNodeId),m=r.find(w=>w.id===b.targetNodeId);if(!v||!m)return null;const S=(v.position.x+v.size.width/2-f.minX)*x,_=(v.position.y+v.size.height/2-f.minY)*x,I=(m.position.x+m.size.width/2-f.minX)*x,C=(m.position.y+m.size.height/2-f.minY)*x;return n.jsx("line",{x1:S,y1:_,x2:I,y2:C,stroke:"var(--nice-text-muted, #aaa)",strokeWidth:.5},b.id)}),r.map(b=>n.jsx("rect",{x:(b.position.x-f.minX)*x,y:(b.position.y-f.minY)*x,width:b.size.width*x,height:b.size.height*x,fill:b.style.backgroundColor??"var(--nice-border, #ddd)",stroke:"var(--nice-text-muted, #999)",strokeWidth:.5},b.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:s})=>{var f,d,u,x,g;const{t:c}=Ee(),o=y.useCallback((h,b)=>{!r||!t||t(r.id,{style:{...r.style,[h]:b}})},[r,t]),l=y.useCallback((h,b)=>{!e||!i||i(e.id,{style:{...e.style,[h]:b}})},[e,i]);return!r&&!e?n.jsx("div",{className:`nice-diagram-property-panel nice-diagram-property-panel--empty ${s??""}`,children:n.jsx("p",{className:"nice-diagram-property-panel__hint",children:c("panel.noSelection")})}):r?n.jsxs("div",{className:`nice-diagram-property-panel ${s??""}`,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(N.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(N.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(N.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(N.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(N.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(N.NiceColorPicker,{value:r.style.backgroundColor??"var(--nice-bg, #fff)",onChange:h=>o("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(N.NiceColorPicker,{value:r.style.borderColor??"var(--nice-text, #333333)",onChange:h=>o("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(N.NiceNumberInput,{value:r.style.fontSize??14,min:8,max:72,onChange:h=>o("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(N.NiceColorPicker,{value:r.style.fontColor??"var(--nice-bg, #222222)",onChange:h=>o("fontColor",h),className:"nice-diagram-property-panel__color"})]})]}),n.jsx(N.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(N.NiceColorPicker,{value:r.style.glowColor??"var(--nice-primary, #3b82f6)",onChange:h=>o("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(N.NiceSlider,{min:0,max:3,step:.1,value:r.style.glowIntensity??0,onChange:h=>o("glowIntensity",h),className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Opacity",n.jsx(N.NiceSlider,{min:0,max:1,step:.05,value:r.style.opacity??1,onChange:h=>o("opacity",h),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Border Radius",n.jsx(N.NiceNumberInput,{min:0,max:50,value:r.style.borderRadius??4,onChange:h=>o("borderRadius",h??4),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Border Width",n.jsx(N.NiceNumberInput,{min:0,max:10,step:.5,value:r.style.borderWidth??1,onChange:h=>o("borderWidth",h??1),className:"nice-diagram-property-panel__input"})]}),n.jsx(N.NiceCheckbox,{checked:r.style.shadow??!1,onChange:h=>o("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(N.NiceColorPicker,{value:r.style.gradientColor??"var(--nice-bg, #fff)",onChange:h=>o("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(N.NiceSelect,{value:r.style.gradientDirection??"vertical",onChange:h=>o("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(N.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(N.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 ${s??""}`,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(N.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(N.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(N.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(N.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(N.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(N.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(N.NiceSelect,{value:e.style.strokeDash?e.style.strokeDash.join(","):"solid",onChange:h=>{const b=h;b==="solid"?l("strokeDash",[]):l("strokeDash",b.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(N.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(N.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(N.NiceCheckbox,{checked:((f=e.style.liquidFlow)==null?void 0:f.active)??!1,onChange:h=>{const b=e.style.liquidFlow??{active:!1,color:"var(--nice-primary, #3b82f6)",speed:1,pipeWidth:6};i==null||i(e.id,{style:{...e.style,liquidFlow:{...b,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(N.NiceColorPicker,{value:((u=e.style.liquidFlow)==null?void 0:u.color)??"var(--nice-primary, #3b82f6)",onChange:h=>{const b=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...b,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(N.NiceSlider,{min:.1,max:5,step:.1,value:((x=e.style.liquidFlow)==null?void 0:x.speed)??1,onChange:h=>{const b=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...b,speed:h}}})},className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Pipe Width",n.jsx(N.NiceNumberInput,{min:2,max:20,value:((g=e.style.liquidFlow)==null?void 0:g.pipeWidth)??6,onChange:h=>{const b=e.style.liquidFlow;i==null||i(e.id,{style:{...e.style,liquidFlow:{...b,pipeWidth:h??6}}})},className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Opacity",n.jsx(N.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(N.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 Ct={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"]},zi=["dagre","forceDirected","grid","radial","tree"],Di=["sans-serif","serif","monospace","Arial","Helvetica","Times New Roman","Courier New","Georgia","Verdana","Tahoma","Trebuchet MS"],Ti=[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:s,onRedo:c,canUndo:o=!1,canRedo:l=!1,onExport:f,onZoomIn:d,onZoomOut:u,onZoomReset:x,zoomLevel:g=1,onToggleBold:h,onToggleItalic:b,isBold:v=!1,isItalic:m=!1,onFontFamilyChange:S,currentFontFamily:_="sans-serif",onFontSizeChange:I,currentFontSize:C=14,onAlignLeft:w,onAlignCenterH:j,onAlignRight:F,onAlignTop:O,onAlignCenterV:Y,onAlignBottom:R,onDistributeH:M,onDistributeV:z,onBringToFront:q,onSendToBack:V,onGroupSelected:T,onUngroupSelected:E,onCopy:X,onPaste:B,onDuplicate:K,onSelectAll:Z,selectionCount:L=0,onFind:G,showFind:le=!1,findQuery:re="",onFindQueryChange:fe,viewMode:xe="editor",onViewModeChange:be,stylePresetId:De,onStylePresetChange:Te,className:it})=>{const{t:pe}=Ee(),[at,Le]=y.useState(!1),[Me,Ne]=y.useState(!1),[Fe,me]=y.useState(!1),[We,we]=y.useState(!1),[st,$e]=y.useState(!1),[Be,qe]=y.useState(!1),ot=Ct[t]??Ct.custom,nt=y.useCallback(H=>{i==null||i(H),Le(!1)},[i]),Ge=y.useCallback(H=>{a==null||a(H),Ne(!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(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="select"?"primary":"ghost",size:"sm",onClick:()=>e("select"),title:`${pe("toolbar.select")} (V)`,children:"◇"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="pan"?"primary":"ghost",size:"sm",onClick:()=>e("pan"),title:`${pe("toolbar.pan")} (H)`,children:"✋"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="addEdge"?"primary":"ghost",size:"sm",onClick:()=>e("addEdge"),title:`${pe("toolbar.addEdge")} (C)`,children:"↗"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="text"?"primary":"ghost",size:"sm",onClick:()=>e("text"),title:"Text (T)",children:"T"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="freehand"?"primary":"ghost",size:"sm",onClick:()=>e("freehand"),title:"Freehand (F)",children:"✎"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="delete"?"primary":"ghost",size:"sm",onClick:()=>e("delete"),title:`${pe("toolbar.delete")} (Del)`,children:"🗑"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="addNode"?"primary":"ghost",size:"sm",onClick:()=>Le(H=>!H),title:pe("toolbar.addNode"),children:["+ ",pe("toolbar.addNode")]}),at&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown nice-diagram-toolbar__dropdown--shapes",children:ot.map(H=>n.jsxs(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>nt(H),children:[Pi(H)," ",H]},H))})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:X,title:"Copy (Ctrl+C)",children:"📋"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:B,title:"Paste (Ctrl+V)",children:"📃"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:K,title:"Duplicate (Ctrl+D)",children:"⧉"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:Z,title:"Select All (Ctrl+A)",children:"⬚"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:s,disabled:!o,title:`${pe("toolbar.undo")} (Ctrl+Z)`,children:"↩"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:c,disabled:!l,title:`${pe("toolbar.redo")} (Ctrl+Y)`,children:"↪"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:u,title:pe("toolbar.zoomOut"),children:"−"}),n.jsxs("span",{className:"nice-diagram-toolbar__zoom-label",children:[Math.round(g*100),"%"]}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:d,title:pe("toolbar.zoomIn"),children:"+"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:x,title:pe("toolbar.zoomReset"),children:"1:1"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:G,title:"Find (Ctrl+F)",children:"🔍"}),le&&n.jsx(N.NiceTextInput,{className:"nice-diagram-toolbar__search",placeholder:"Search nodes…",value:re,onChange:H=>fe==null?void 0:fe(H),autoFocus:!0})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>me(H=>!H),title:pe("toolbar.export"),children:["⤓ ",pe("toolbar.export")]}),Fe&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{f==null||f("ndd"),me(!1)},children:".ndd.json"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{f==null||f("svg"),me(!1)},children:"SVG"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{f==null||f("mermaid"),me(!1)},children:"Mermaid"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{f==null||f("png"),me(!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(N.NiceSelect,{className:"nice-diagram-toolbar__font-select",value:_,onChange:H=>S==null?void 0:S(H),options:Di.map(H=>({value:H,label:H})),title:"Font Family"}),n.jsx(N.NiceSelect,{className:"nice-diagram-toolbar__size-select",value:String(C),onChange:H=>I==null?void 0:I(Number(H)),options:Ti.map(H=>({value:String(H),label:String(H)})),title:"Font Size"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:v?"primary":"ghost",size:"sm",onClick:h,title:"Bold (Ctrl+B)",children:n.jsx("strong",{children:"B"})}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:m?"primary":"ghost",size:"sm",onClick:b,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(N.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.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{w==null||w(),we(!1)},title:"Align Left",children:"⫷ Left"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{j==null||j(),we(!1)},title:"Align Center",children:"⫿ Center"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{F==null||F(),we(!1)},title:"Align Right",children:"⫸ Right"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{O==null||O(),we(!1)},title:"Align Top",children:"⫠ Top"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{Y==null||Y(),we(!1)},title:"Align Middle",children:"⫟ Middle"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{R==null||R(),we(!1)},title:"Align Bottom",children:"⫡ Bottom"})]}),n.jsx("div",{className:"nice-diagram-toolbar__dropdown-section",children:"Distribute"}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{M==null||M(),we(!1)},title:"Distribute Horizontally",children:"⟺ H"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{z==null||z(),we(!1)},title:"Distribute Vertically",children:"⟺ V"})]})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>$e(H=>!H),title:"Arrange",children:"☰ Arrange"}),st&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{q==null||q(),$e(!1)},children:"↑ Bring to Front"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{V==null||V(),$e(!1)},children:"↓ Send to Back"}),n.jsx("div",{className:"nice-diagram-toolbar__dropdown-divider"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{T==null||T(),$e(!1)},disabled:L<2,children:"⊞ Group"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{E==null||E(),$e(!1)},children:"⊟ Ungroup"})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>Ne(H=>!H),title:pe("toolbar.layout"),children:["⊞ ",pe("toolbar.layout")]}),Me&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown",children:zi.map(H=>n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>Ge(H),children:pe(`layout.${H}`)},H))})]}),L>1&&n.jsxs("span",{className:"nice-diagram-toolbar__selection-info",children:[L," selected"]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:xe==="editor"?"primary":"ghost",size:"sm",onClick:()=>be==null?void 0:be("editor"),title:"Editor Mode",children:"🖊 Editor"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:xe==="player"?"primary":"ghost",size:"sm",onClick:()=>be==null?void 0:be("player"),title:"Player Mode",children:"▶ Player"}),n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:xe==="playerAnimated"?"primary":"ghost",size:"sm",onClick:()=>be==null?void 0:be("playerAnimated"),title:"Animated Player Mode",children:"⚡ Animated"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsx(N.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>qe(H=>!H),title:"Style Presets",children:"🎨 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 ge=je.category??"Other";return H[ge]||(H[ge]=[]),H[ge].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(ge=>n.jsxs(N.NiceButton,{className:`nice-diagram-toolbar__dropdown-item ${De===ge.id?"nice-diagram-toolbar__dropdown-item--active":""}`,variant:De===ge.id?"primary":"ghost",size:"sm",onClick:()=>{Te==null||Te(ge.id),qe(!1)},style:{display:"flex",alignItems:"center",gap:8},children:[n.jsx("span",{style:{width:16,height:16,borderRadius:3,background:ge.config.palette.primary,border:"1px solid "+(ge.config.palette.border??"var(--nice-border, #ccc)"),display:"inline-block",flexShrink:0}}),n.jsx("span",{style:{fontSize:12},children:ge.name})]},ge.id))]},H))})]})]})]})};function Pi(r){switch(r){case"rectangle":return"▭";case"roundedRect":return"▢";case"ellipse":return"⬭";case"circle":return"●";case"diamond":return"◇";case"hexagon":return"⬡";case"parallelogram":return"▱";case"cylinder":return"⌂";case"triangle":return"△";case"cloud":return"☁";case"document":return"📄";case"actor":return"🧑";default:return"▢"}}tt.displayName="DiagramToolbar";const Wt=({initialDocument:r,diagramType:e="flowchart",onChange:t,onExport:i,lang:a="en",showToolbar:s=!0,showPropertyPanel:c=!0,showMinimap:o=!0,showTimeline:l=!0,className:f,style:d})=>{var Z;const u=Lt(r),[x,g]=y.useState("select"),[h,b]=y.useState(null),v=y.useRef(null),[m,S]=y.useState("editor"),_=y.useRef(null),[I,C]=y.useState({particles:[],liquidFlows:new Map,glowStates:new Map});y.useEffect(()=>{const L=new $t(G=>{C(G)});return _.current=L,L.start(),()=>{L.stop(),_.current=null}},[]),y.useEffect(()=>{var G;const L=_.current;if(L)for(const le of u.edges)(G=le.style.liquidFlow)!=null&&G.active?L.startLiquidFlow(le.id,le.style.liquidFlow):L.stopLiquidFlow(le.id)},[u.edges]),y.useEffect(()=>{const L=_.current;if(L)for(const G of u.nodes)G.style.glowColor?L.setGlow(G.id,G.style.glowColor,G.style.glowIntensity??1):L.removeGlow(G.id)},[u.nodes]);const w=y.useCallback(L=>{u.setStylePreset(L)},[u]),j=y.useCallback((L,G)=>{const le=u.nodes.find(fe=>fe.id===L);if(!(le!=null&&le.interactions))return;const re=le.interactions.find(fe=>fe.id===G);if(re)switch(re.action){case"reveal":{if(re.targetId){const fe=u.nodes.find(xe=>xe.id===re.targetId);fe!=null&&fe.hidden&&u.updateNode(re.targetId,{hidden:!1})}break}case"navigate":{if(re.targetId){const fe=u.nodes.find(xe=>xe.id===re.targetId);fe&&(u.setViewport({x:-fe.position.x+300,y:-fe.position.y+200,zoom:u.viewport.zoom}),b(re.targetId))}break}case"switchAnimationMode":{re.targetId&&u.setActiveAnimationMode(re.targetId);break}case"highlight":{re.targetId&&b(re.targetId);break}case"toggleCollapse":{u.toggleNodeCollapse(L);break}}},[u]),F=y.useRef(u.document);u.document!==F.current&&(F.current=u.document,t==null||t(u.document));const O=y.useMemo(()=>h?u.nodes.find(L=>L.id===h)??null:null,[h,u.nodes]),Y=y.useMemo(()=>h?u.edges.find(L=>L.id===h)??null:null,[h,u.edges]),R=y.useCallback(L=>{const G=u.viewport,le=(-G.x+400)/G.zoom,re=(-G.y+300)/G.zoom,fe=u.addNode("New Node",{x:le,y:re},L);b(fe.id),g("select")},[u]),M=y.useCallback(L=>{u.applyLayout({algorithm:L,centerGraph:!0})},[u]),z=y.useCallback((L,G)=>{u.moveNode(L,G)},[u]),q=y.useCallback((L,G)=>{u.moveNode(L,G)},[u]),V=y.useCallback(L=>{u.nodes.find(G=>G.id===L)?u.removeNode(L):u.edges.find(G=>G.id===L)&&u.removeEdge(L),b(null)},[u]),T=y.useCallback(L=>{const G=u.document;let le;switch(L){case"ndd":le=Rt(G,!0);break;case"svg":le=ft(G);break;case"mermaid":le=Tt(G);break;case"png":le=ft(G);break}i==null||i(L,le)},[u,i]),E=y.useCallback(()=>{u.setViewport({...u.viewport,zoom:Math.min(5,u.viewport.zoom*1.2)})},[u]),X=y.useCallback(()=>{u.setViewport({...u.viewport,zoom:Math.max(.1,u.viewport.zoom/1.2)})},[u]),B=y.useCallback(()=>{u.setViewport({x:0,y:0,zoom:1})},[u]),K=y.useMemo(()=>[...u.nodes.map(L=>({id:L.id,label:L.label,type:"node"})),...u.edges.map(L=>({id:L.id,label:L.label??L.id,type:"edge"}))],[u.nodes,u.edges]);return n.jsx(pt,{locale:a,children:n.jsxs("div",{ref:v,className:`nice-diagram-editor ${f??""}`,style:{display:"flex",flexDirection:"column",height:"100%",...d},children:[s&&n.jsx(tt,{activeTool:x,onToolChange:g,diagramType:u.document.diagramType,onAddNode:R,onApplyLayout:M,onUndo:u.undo,onRedo:u.redo,canUndo:u.canUndo,canRedo:u.canRedo,onExport:T,onZoomIn:E,onZoomOut:X,onZoomReset:B,viewMode:m,onViewModeChange:S,stylePresetId:u.stylePresetId,onStylePresetChange:w}),u.animationModes.length>0&&n.jsxs("div",{className:"nice-diagram-editor__mode-tabs",style:{display:"flex",gap:4,padding:"4px 8px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",background:"var(--nice-bg-secondary, #f9f9f9)",fontSize:12,alignItems:"center"},children:[n.jsx("span",{style:{color:"var(--nice-text-secondary, #888)",marginRight:4},children:"Modes:"}),u.animationModes.map(L=>{var G;return n.jsx(N.NiceButton,{variant:((G=u.activeAnimationMode)==null?void 0:G.id)===L.id?"primary":"ghost",size:"sm",onClick:()=>u.setActiveAnimationMode(L.id),style:{padding:"2px 10px",fontSize:11},children:L.name},L.id)}),n.jsx(N.NiceButton,{variant:"ghost",size:"sm",onClick:()=>u.addAnimationMode(`Mode ${u.animationModes.length+1}`),style:{padding:"2px 8px",fontSize:11,color:"var(--nice-text-secondary, #888)"},title:"Add animation mode",children:"+"})]}),n.jsxs("div",{className:"nice-diagram-editor__body",style:{display:"flex",flex:1,overflow:"hidden",position:"relative"},children:[n.jsxs("div",{className:"nice-diagram-editor__canvas",style:{flex:1,position:"relative"},children:[n.jsx(ve,{nodes:u.nodes,edges:u.edges,groups:u.groups,viewport:u.viewport,onViewportChange:u.setViewport,selectedId:h,onSelectElement:b,onNodeDrag:z,onNodeDragEnd:q,interactive:m==="editor",showGrid:m==="editor",particleState:I,viewMode:m,ghostOpacity:((Z=u.playerConfig)==null?void 0:Z.ghostOpacity)??.3,onGroupCollapse:u.toggleGroupCollapse,onNodeCollapse:u.toggleNodeCollapse,onInteraction:j}),o&&n.jsx("div",{style:{position:"absolute",bottom:8,left:8},children:n.jsx(Qe,{nodes:u.nodes,edges:u.edges,viewport:u.viewport,onViewportChange:u.setViewport})})]}),c&&n.jsx("div",{className:"nice-diagram-editor__panel",style:{width:260,borderLeft:"1px solid var(--nice-border, #ddd)",overflowY:"auto"},children:n.jsx(et,{selectedNode:O,selectedEdge:Y,onNodeChange:u.updateNode,onEdgeChange:u.updateEdge,onRemove:V})})]}),l&&n.jsx("div",{className:"nice-diagram-editor__timeline",style:{borderTop:"1px solid var(--nice-border, #ddd)"},children:n.jsx(Ke,{animations:u.animations,onAdd:u.addAnimation,onRemove:u.removeAnimation,availableTargets:K})})]})})};Wt.displayName="NiceDiagramEditor";const Mt={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 Mt[r]??Mt.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 s of this.animations){const c=s.startMs+(s.delayMs??0);c+s.durationMs;const o=s.repeat??0;let l=i-c;if(l<0){this.stateMap.set(s.targetId,Oi(s)),a=!0;continue}if(o===-1)l=l%s.durationMs,a=!0;else if(o>0){const x=s.durationMs*(o+1);if(l>x)continue;l=l%s.durationMs,a=!0}else{if(l>s.durationMs)continue;a=!0}const f=Math.min(l/s.durationMs,1),d=Bt(s.easing)(f),u=Ri(s,d);this.stateMap.set(s.targetId,u)}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 Ri(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 Oi(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:s=!1,className:c,style:o})=>{const l=i??s,f=a??s,[d,u]=y.useState({...r.viewport}),[x,g]=y.useState(new Map),[h,b]=y.useState(!1),v=y.useRef(null),m=y.useCallback(()=>{v.current&&v.current.stop();const w=new Gt(r.animations,j=>{g(new Map(j)),w.isPlaying()||b(!1)});v.current=w,w.play(),b(!0)},[r.animations]),S=y.useCallback(()=>{var w;(w=v.current)==null||w.stop(),b(!1),g(new Map)},[]);y.useEffect(()=>(t&&r.animations.length>0&&m(),()=>{var w;(w=v.current)==null||w.stop()}),[t]);const _=y.useCallback(()=>u(w=>({...w,zoom:Math.min(5,w.zoom*1.2)})),[]),I=y.useCallback(()=>u(w=>({...w,zoom:Math.max(.1,w.zoom/1.2)})),[]),C=y.useCallback(()=>u({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%",...o},children:[l&&n.jsx(Ei,{isPlaying:h,hasAnimations:r.animations.length>0,onPlay:m,onStop:S,onZoomIn:_,onZoomOut:I,onZoomReset:C}),n.jsx("div",{style:{flex:1,position:"relative"},children:n.jsx(ve,{nodes:r.nodes,edges:r.edges,groups:r.groups,viewport:d,onViewportChange:u,theme:r.theme,animationStates:x,interactive:!1,showGrid:f})})]})})},Ei=({isPlaying:r,hasAnimations:e,onPlay:t,onStop:i,onZoomIn:a,onZoomOut:s,onZoomReset:c})=>{const{t:o}=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(N.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:i,children:["⏹ ",o("animation.stop")]}):n.jsxs(N.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:t,children:["▶ ",o("animation.play")]})),n.jsx("span",{style:{flex:1}}),n.jsx(N.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:a,children:"🔍+"}),n.jsx(N.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:s,children:"🔍−"}),n.jsx(N.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:c,children:"1:1"})]})};yt.displayName="NiceDiagramViewer";const Li="_cell_9ewd0_9",Fi="_expandable_9ewd0_29",Wi="_svg_9ewd0_57",Bi="_emptyText_9ewd0_67",qi="_badge_9ewd0_79",Gi="_expandIcon_9ewd0_117",Vi="_modalOverlay_9ewd0_165",Yi="_modalContent_9ewd0_213",Xi="_modalHeader_9ewd0_263",Hi="_modalTitle_9ewd0_281",Ui="_modalClose_9ewd0_295",Ji="_modalBody_9ewd0_333",Zi="_modalSvg_9ewd0_353",Ki="_modalFooter_9ewd0_367",Qi="_modalInfo_9ewd0_385",ye={cell:Li,expandable:Fi,svg:Wi,emptyText:Bi,badge:qi,expandIcon:Gi,modalOverlay:Vi,modalContent:Yi,modalHeader:Xi,modalTitle:Hi,modalClose:Ui,modalBody:Ji,modalSvg:Zi,modalFooter:Ki,modalInfo:Qi},ea=120,ta=48,ra=4,Nt={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 s of r){const c=s.position.x,o=s.position.y,l=s.position.x+s.size.width,f=s.position.y+s.size.height;c<e&&(e=c),o<t&&(t=o),l>i&&(i=l),f>a&&(a=f)}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 Nt[e]??Nt.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,s=t.position.y+t.size.height/2,c=i.position.x+i.size.width/2,o=i.position.y+i.size.height/2;return`M ${a} ${s} L ${c} ${o}`}function ia(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 aa=({document:r,onClose:e})=>{const t=bt(r.nodes),i=40,a=t.width+i*2,s=t.height+i*2,c=y.useMemo(()=>new Map(r.nodes.map(o=>[o.id,o])),[r.nodes]);return n.jsx("div",{className:ye.modalOverlay,onClick:e,children:n.jsxs("div",{className:ye.modalContent,onClick:o=>o.stopPropagation(),children:[n.jsxs("div",{className:ye.modalHeader,children:[n.jsx("h3",{className:ye.modalTitle,children:r.title||"Diagram"}),n.jsx("button",{className:ye.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:ye.modalBody,children:n.jsxs("svg",{viewBox:`${t.minX-i} ${t.minY-i} ${a} ${s}`,className:ye.modalSvg,children:[r.edges.map(o=>{var f,d,u;const l=Yt(o,c);return l?n.jsx("path",{d:l,stroke:((f=o.style)==null?void 0:f.strokeColor)??"var(--nice-text-secondary, #64748b)",strokeWidth:((d=o.style)==null?void 0:d.strokeWidth)??1.5,fill:"none",markerEnd:(u=o.style)!=null&&u.targetArrow&&o.style.targetArrow!=="none"?"url(#arrowhead-modal)":void 0},o.id):null}),r.nodes.map(o=>{var l,f;return n.jsxs("g",{children:[n.jsx("rect",{x:o.position.x,y:o.position.y,width:o.size.width,height:o.size.height,rx:((l=o.style)==null?void 0:l.borderRadius)??4,fill:Vt(o),stroke:((f=o.style)==null?void 0:f.borderColor)??"var(--nice-text, #1e293b)",strokeWidth:1}),n.jsx("text",{x:o.position.x+o.size.width/2,y:o.position.y+o.size.height/2,textAnchor:"middle",dominantBaseline:"middle",fill:"var(--nice-bg, #fff)",fontSize:12,fontFamily:"system-ui, sans-serif",children:o.label.substring(0,30)})]},o.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:ye.modalFooter,children:n.jsxs("span",{className:ye.modalInfo,children:[r.nodes.length," nodes • ",r.edges.length," edges"]})})]})})},sa=({document:r,nodes:e,edges:t,width:i=ea,height:a=ta,showCount:s=!0,expandable:c=!0,onExpand:o,padding:l=ra,backgroundColor:f="transparent",borderRadius:d=4,showLabels:u=!1,edgeColor:x="var(--nice-text-muted, #94a3b8)",tooltip:g})=>{const[h,b]=y.useState(!1),v=y.useMemo(()=>r||(e||t?ia(e??[],t??[]):null),[r,e,t]),m=y.useMemo(()=>v?new Map(v.nodes.map(j=>[j.id,j])):new Map,[v]),{bounds:S,scale:_,translateX:I,translateY:C}=y.useMemo(()=>{if(!v||v.nodes.length===0)return{bounds:{minX:0,minY:0,width:100,height:100},scale:1,translateX:0,translateY:0};const j=bt(v.nodes),F=i-l*2,O=a-l*2,Y=F/j.width,R=O/j.height,M=Math.min(Y,R,1),z=j.width*M,q=j.height*M,V=(i-z)/2-j.minX*M,T=(a-q)/2-j.minY*M;return{bounds:j,scale:M,translateX:V,translateY:T}},[v,i,a,l]),w=y.useCallback(()=>{!v||!c||(o?o(v):b(!0))},[v,c,o]);return!v||v.nodes.length===0?n.jsx("div",{className:ye.cell,style:{width:i,height:a,backgroundColor:f,borderRadius:d},title:g,children:n.jsx("span",{className:ye.emptyText,children:"—"})}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`${ye.cell} ${c?ye.expandable:""}`,style:{width:i,height:a,backgroundColor:f,borderRadius:d},onClick:w,title:g??`${v.nodes.length} nodes, ${v.edges.length} edges`,children:[n.jsx("svg",{width:i,height:a,viewBox:`0 0 ${i} ${a}`,className:ye.svg,children:n.jsxs("g",{transform:`translate(${I}, ${C}) scale(${_})`,children:[v.edges.map(j=>{const F=Yt(j,m);return F?n.jsx("path",{d:F,stroke:x,strokeWidth:1/_,fill:"none"},j.id):null}),v.nodes.map(j=>{const F=Vt(j);return n.jsxs("g",{children:[n.jsx("rect",{x:j.position.x,y:j.position.y,width:j.size.width,height:j.size.height,rx:Math.min(4,j.size.width/4),fill:F}),u&&_>.3&&n.jsx("text",{x:j.position.x+j.size.width/2,y:j.position.y+j.size.height/2,textAnchor:"middle",dominantBaseline:"middle",fill:"var(--nice-bg, #fff)",fontSize:10/_,fontFamily:"system-ui, sans-serif",children:j.label.substring(0,5)})]},j.id)})]})}),s&&n.jsx("span",{className:ye.badge,children:v.nodes.length}),c&&n.jsx("span",{className:ye.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&&v&&n.jsx(aa,{document:v,onClose:()=>b(!1)})]})};function Xt(r,e,t="roundedRect"){const i=[],a=[],s=new Map;for(const c of r){const o=String(c[e.nodeMapping.idField]??"");if(!o)continue;const l=String(c[e.nodeMapping.labelField]??o),f=e.nodeMapping.descriptionField?String(c[e.nodeMapping.descriptionField]??""):void 0,d=e.nodeMapping.iconField?String(c[e.nodeMapping.iconField]??""):void 0,u=e.nodeMapping.colorField?String(c[e.nodeMapping.colorField]??""):void 0,x={id:`data_${o}`,label:l,description:f,icon:d,position:{x:0,y:0},size:{width:180,height:70},shape:t,style:u?{backgroundColor:u}:{},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(x),s.set(o,x)}if(e.nodeMapping.parentField)for(const c of r){const o=String(c[e.nodeMapping.idField]??""),l=String(c[e.nodeMapping.parentField]??"");if(!o||!l)continue;const f=s.get(o),d=s.get(l);!f||!d||a.push({id:`edge_${l}_${o}`,sourceNodeId:d.id,sourcePortId:"bottom",targetNodeId:f.id,targetPortId:"top",style:{lineType:"orthogonal",targetArrow:"arrow"}})}if(e.edgeMapping)for(const c of r){const o=String(c[e.edgeMapping.sourceField]??""),l=String(c[e.edgeMapping.targetField]??"");if(!o||!l)continue;const f=s.get(o),d=s.get(l);if(!f||!d)continue;const u=e.edgeMapping.labelField?String(c[e.edgeMapping.labelField]??""):void 0;a.push({id:`edge_${o}_${l}`,sourceNodeId:f.id,sourcePortId:"right",targetNodeId:d.id,targetPortId:"left",label:u,style:{lineType:"bezier",targetArrow:"arrow"}})}return{nodes:i,edges:a}}async function oa(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(),s=Array.isArray(a)?a:a.value??[];return Xt(s,r,e)}function na(r){return{rectangle:"rectangle",roundedRect:"roundedRect",ellipse:"ellipse",circle:"circle",diamond:"diamond",hexagon:"hexagon",cylinder:"cylinder",cloud:"cloud",triangle:"triangle"}[r||"rectangle"]||"rectangle"}function ca(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 la(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 da(r){if(r)return{backgroundColor:r.fill,borderColor:r.stroke,borderWidth:r.strokeWidth}}function Ht(r){return{id:r.id,label:r.label,position:{x:r.x,y:r.y},size:{width:r.width,height:r.height},shape:na(r.shape),style:ca(r.style),ports:(r.ports||[]).map((e,t)=>({id:e.id,side:e.position||"right",offset:.5})),data:r.data}}function Ut(r,e){var c,o;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`,s=r.targetPort||((o=i==null?void 0:i.ports[0])==null?void 0:o.id)||`${r.target}-in`;return{id:r.id,sourceNodeId:r.source,sourcePortId:a,targetNodeId:r.target,targetPortId:s,label:r.label,style:la(r.style),data:r.data}}function Jt(r){return{id:r.id,label:r.label,nodeIds:r.nodeIds,style:da(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(Ht);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=>Ut(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 ua={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)"},fa={start:"ellipse",end:"ellipse",task:"rectangle",decision:"diamond",parallel:"rectangle",join:"rectangle",subprocess:"rectangle",timer:"ellipse",message:"rectangle",error:"rectangle"},ha={start:"▶",end:"⬛",task:"📋",decision:"❓",parallel:"⫘",join:"⫗",subprocess:"📦",timer:"⏱",message:"✉",error:"⚠"},pa=({data:r,onStepClick:e,onTransitionClick:t,autoPlay:i=!1,animationDelay:a=1e3,showTooltips:s=!0,showMinimap:c=!0,statusColors:o=ua,typeShapes:l=fa,direction:f="horizontal",className:d,style:u})=>{const[x,g]=y.useState(0),h=y.useMemo(()=>{const S=r.steps.map((C,w)=>{const j=C.id===r.currentStepId,F=C.status||"pending",O=o[F],Y=l[C.type],R=f==="horizontal"?w*200:100,M=f==="horizontal"?100:w*150;return{id:C.id,label:C.name,x:R,y:M,width:150,height:60,shape:Y,style:{fill:O,stroke:j?"var(--nice-text, #1f2937)":O,strokeWidth:j?3:1,fontColor:"var(--nice-bg, #fff)",fontSize:12},data:{type:C.type,status:C.status,assignee:C.assignee,dueDate:C.dueDate,icon:ha[C.type],...C.metadata},ports:[{id:`${C.id}-in`,position:"left"},{id:`${C.id}-out`,position:"right"}]}}),_=r.transitions.map(C=>{const w=r.steps.find(O=>O.id===C.from),j=r.steps.find(O=>O.id===C.to);let F="var(--nice-text-muted, #9ca3af)";return(w==null?void 0:w.status)==="completed"&&(j==null?void 0:j.status)!=="pending"?F="var(--nice-success, #10b981)":(w==null?void 0:w.status)==="failed"&&(F="var(--nice-danger, #ef4444)"),{id:C.id,source:C.from,target:C.to,sourcePort:`${C.from}-out`,targetPort:`${C.to}-in`,label:C.label||C.condition,style:{stroke:F,strokeWidth:2,arrowHead:"arrow",lineType:"bezier"},data:{condition:C.condition}}}),I=i?ga(r.steps):[];return Ae({id:r.id,title:r.name,diagramType:"flowchart",nodes:S,edges:_,animations:I,metadata:{type:"workflow",...r.metadata}})},[r,o,l,f,i]);y.useEffect(()=>{if(!i)return;const S=r.steps.filter(I=>I.status==="completed").length;if(x>=S)return;const _=setTimeout(()=>{g(I=>I+1)},a);return()=>clearTimeout(_)},[i,x,a,r.steps]),y.useCallback(S=>{if(!e)return;const _=r.steps.find(I=>I.id===S);_&&e(_)},[r.steps,e]);const[b,v]=y.useState({x:0,y:0,zoom:1}),m=y.useCallback(S=>{if(S&&e){const _=r.steps.find(I=>I.id===S);_&&e(_)}if(S&&t){const _=r.transitions.find(I=>I.id===S);_&&t(_)}},[r.steps,r.transitions,e,t]);return n.jsx("div",{className:`nice-workflow-visualizer ${d||""}`,style:{position:"relative",width:"100%",height:"100%",...u},children:n.jsx(ve,{nodes:h.nodes,edges:h.edges,groups:h.groups,viewport:b,onViewportChange:v,onSelectElement:m,showGrid:!0})})};function ga(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 ma(r){var s,c;const t=new DOMParser().parseFromString(r,"text/xml"),i=[],a=[];return t.querySelectorAll("startEvent").forEach(o=>{i.push({id:o.getAttribute("id")||`start-${i.length}`,name:o.getAttribute("name")||"Start",type:"start"})}),t.querySelectorAll("task, userTask, serviceTask").forEach(o=>{i.push({id:o.getAttribute("id")||`task-${i.length}`,name:o.getAttribute("name")||"Task",type:"task"})}),t.querySelectorAll("exclusiveGateway, parallelGateway").forEach(o=>{const l=o.tagName==="parallelGateway";i.push({id:o.getAttribute("id")||`gateway-${i.length}`,name:o.getAttribute("name")||(l?"Parallel":"Decision"),type:l?"parallel":"decision"})}),t.querySelectorAll("endEvent").forEach(o=>{i.push({id:o.getAttribute("id")||`end-${i.length}`,name:o.getAttribute("name")||"End",type:"end"})}),t.querySelectorAll("sequenceFlow").forEach(o=>{a.push({id:o.getAttribute("id")||`flow-${a.length}`,from:o.getAttribute("sourceRef")||"",to:o.getAttribute("targetRef")||"",label:o.getAttribute("name")||void 0})}),{id:((s=t.querySelector("process"))==null?void 0:s.getAttribute("id"))||"workflow",name:((c=t.querySelector("process"))==null?void 0:c.getAttribute("name"))||"Workflow",steps:i,transitions:a}}function ya(r,e){const t=[],i=[];t.push({id:"start",name:"Start",type:"start",status:"completed"}),r.forEach((a,s)=>{t.push({id:`step-${s}`,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 ba={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)"},xa={"one-to-one":{left:"1",right:"1"},"one-to-many":{left:"1",right:"*"},"many-to-one":{left:"*",right:"1"},"many-to-many":{left:"*",right:"*"}},va=({schema:r,onTableClick:e,onColumnClick:t,onRelationClick:i,showColumnDetails:a=!0,showOnlyKeys:s=!1,highlightTables:c=[],showMinimap:o=!0,schemaColors:l=ba,layout:f="auto",maxColumnsDisplay:d=15,className:u,style:x})=>{const[g,h]=y.useState(null),b=y.useMemo(()=>{const _=wa(r.tables,f),I=r.tables.map((w,j)=>{const F=_[w.name]||{x:j%4*300,y:Math.floor(j/4)*400},O=c.includes(w.name),Y=g===w.name,R=l[w.schema||"dbo"]||"var(--nice-text-secondary, #6b7280)";let M=w.columns;s&&(M=M.filter(T=>T.primaryKey||T.foreignKey)),M.length>d&&(M=M.slice(0,d));const z=40,q=a?28:20,V=z+M.length*q+10;return{id:w.name,label:w.schema?`${w.schema}.${w.name}`:w.name,x:F.x,y:F.y,width:250,height:V,shape:"rectangle",style:{fill:O||Y?R:"var(--nice-bg, #fff)",stroke:R,strokeWidth:Y?3:O?2:1,fontColor:O||Y?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:14,borderRadius:8},data:{type:"table",schema:w.schema,columns:M.map(T=>({...T,icon:ka(T)})),totalColumns:w.columns.length,truncated:w.columns.length>d,comment:w.comment,...w.metadata},ports:[...w.columns.filter(T=>T.primaryKey).map(T=>({id:`${w.name}.${T.name}-pk`,position:"left"})),...w.columns.filter(T=>T.foreignKey).map(T=>({id:`${w.name}.${T.name}-fk`,position:"right"}))]}}),C=r.relations.map(w=>{const j=xa[w.type];return{id:w.id,source:w.fromTable,target:w.toTable,sourcePort:`${w.fromTable}.${w.fromColumn}-fk`,targetPort:`${w.toTable}.${w.toColumn}-pk`,label:w.name||`${j.left}─${j.right}`,style:{stroke:"var(--nice-text-secondary, #6b7280)",strokeWidth:1.5,arrowHead:_a(w.type),arrowTail:Ca(w.type),lineType:"orthogonal",strokeDasharray:w.type==="many-to-many"?"5,5":void 0},data:{type:w.type,fromColumn:w.fromColumn,toColumn:w.toColumn}}});return Ae({id:`schema-${r.name}`,title:r.name,diagramType:"er",nodes:I,edges:C,metadata:{type:"er-diagram",...r.metadata}})},[r,a,s,c,g,l,f,d]);y.useCallback(_=>{if(h(I=>I===_?null:_),e){const I=r.tables.find(C=>C.name===_);I&&e(I)}},[r.tables,e]),y.useCallback(_=>{if(!i)return;const I=r.relations.find(C=>C.id===_);I&&i(I)},[r.relations,i]);const[v,m]=y.useState({x:0,y:0,zoom:1}),S=y.useCallback(_=>{if(_){if(h(I=>I===_?null:_),e){const I=r.tables.find(C=>C.name===_);I&&e(I)}if(i){const I=r.relations.find(C=>C.id===_);I&&i(I)}}},[r.tables,r.relations,e,i]);return n.jsx("div",{className:`nice-database-schema-viewer ${u||""}`,style:{position:"relative",width:"100%",height:"100%",...x},children:n.jsx(ve,{nodes:b.nodes,edges:b.edges,groups:b.groups,viewport:v,onViewportChange:m,onSelectElement:S,showGrid:!0})})};function wa(r,e){const t={};if(e==="grid"){const i=Math.ceil(Math.sqrt(r.length));r.forEach((a,s)=>{t[a.name]={x:s%i*320+50,y:Math.floor(s/i)*450+50}})}else if(e==="hierarchical"){const i={};r.forEach(s=>{const c=s.schema||"default";i[c]||(i[c]=[]),i[c].push(s)});let a=50;Object.entries(i).forEach(([s,c])=>{c.forEach((o,l)=>{t[o.name]={x:l*320+50,y:a}}),a+=500})}else r.forEach((i,a)=>{const s=a/r.length*2*Math.PI,c=300+r.length*20;t[i.name]={x:Math.cos(s)*c+500,y:Math.sin(s)*c+400}});return t}function ka(r){return r.primaryKey?"🔑":r.foreignKey?"🔗":r.unique?"⚡":"📄"}function _a(r){switch(r){case"one-to-one":case"many-to-one":return"none";case"one-to-many":case"many-to-many":return"crow"}}function Ca(r){switch(r){case"one-to-one":case"one-to-many":return"none";case"many-to-one":case"many-to-many":return"crow"}}function Ma(r){const e=[],t=[],i=/CREATE\s+TABLE\s+(?:`?(\w+)`?\.)?`?(\w+)`?\s*\(([\s\S]*?)\);/gi;let a;for(;(a=i.exec(r))!==null;){const s=a[1]||"dbo",c=a[2],o=a[3],l=[],f=/`?(\w+)`?\s+(\w+(?:\([^)]+\))?)\s*(NOT\s+NULL|NULL)?/gi;let d;for(;(d=f.exec(o))!==null;)l.push({name:d[1],type:d[2],nullable:!d[3]||d[3].toUpperCase()!=="NOT NULL"});const u=/PRIMARY\s+KEY\s*\(`?(\w+)`?\)/i.exec(o);if(u){const h=l.find(b=>b.name===u[1]);h&&(h.primaryKey=!0)}const x=/FOREIGN\s+KEY\s*\(`?(\w+)`?\)\s*REFERENCES\s+`?(\w+)`?\s*\(`?(\w+)`?\)/gi;let g;for(;(g=x.exec(o))!==null;){const h=g,b=l.find(v=>v.name===h[1]);b&&(b.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:s,columns:l})}return{name:"Parsed Schema",tables:e,relations:t}}function Na(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 s=i.columns.map(o=>{let l=` ${o.name} ${o.type}`;return o.nullable||(l+=" NOT NULL"),o.primaryKey&&(l+=" PRIMARY KEY"),o.unique&&(l+=" UNIQUE"),o.defaultValue&&(l+=` DEFAULT ${o.defaultValue}`),l}),c=i.columns.filter(o=>o.foreignKey).map(o=>` FOREIGN KEY (${o.name}) REFERENCES ${o.foreignKey.table}(${o.foreignKey.column})`);t.push([...s,...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","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","node.label":"Label","node.description":"Description","node.shape":"Shape","node.color":"Color","node.border":"Border","edge.label":"Label","edge.lineType":"Line Type","edge.arrow":"Arrow","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",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","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","node.label":"Etykieta","node.description":"Opis","node.shape":"Kształt","node.color":"Kolor","node.border":"Obramowanie","edge.label":"Etykieta","edge.lineType":"Typ linii","edge.arrow":"Strzałka","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",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","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","node.label":"Bezeichnung","node.description":"Beschreibung","node.shape":"Form","node.color":"Farbe","node.border":"Rahmen","edge.label":"Bezeichnung","edge.lineType":"Linientyp","edge.arrow":"Pfeil","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",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","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","node.label":"Étiquette","node.description":"Description","node.shape":"Forme","node.color":"Couleur","node.border":"Bordure","edge.label":"Étiquette","edge.lineType":"Type de ligne","edge.arrow":"Flèche","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",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","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","node.label":"Etiqueta","node.description":"Descripción","node.shape":"Forma","node.color":"Color","node.border":"Borde","edge.label":"Etiqueta","edge.lineType":"Tipo de línea","edge.arrow":"Flecha","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",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,o)=>a[c]??o??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(s=>s.id).filter(Boolean));for(const s of i.edges)s.sourceNodeId&&!a.has(s.sourceNodeId)&&e.push(`Edge "${s.id}" references non-existent source node "${s.sourceNodeId}"`),s.targetNodeId&&!a.has(s.targetNodeId)&&e.push(`Edge "${s.id}" references non-existent target node "${s.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:$e(),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 s=gr(),c={id:$e(),label:e,position:t,size:a,shape:i,style:{},ports:s};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,s){if(e===i||!this.getNodeById(e)||!this.getNodeById(i))return null;this.pushUndo("Add edge");const c={id:$e(),sourceNodeId:e,sourcePortId:t,targetNodeId:i,targetPortId:a,label:s,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:$e(),label:e,nodeIds:[...t]};return t.forEach(a=>{const s=this.doc.nodes.find(c=>c.id===a);s&&(s.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(s=>s.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:$e(),...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(s=>s.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(s=>s.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:$e(),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 s;const i=(s=this.doc.animationModes)==null?void 0:s.find(c=>c.id===e);if(!i)return null;this.pushUndo("Add animation to mode");const a={id:$e(),...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(s=>s.id===e);i&&(this.pushUndo("Remove animation from mode"),i.animations=i.animations.filter(s=>s.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 $e(){return`ndd_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function gr(){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 mr(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,s=t.rankSpacing??100,c=new Map,o=new Map,l=new Set(r.map(y=>y.id));r.forEach(y=>{c.set(y.id,[]),o.set(y.id,[])}),e.forEach(y=>{l.has(y.sourceNodeId)&&l.has(y.targetNodeId)&&(c.get(y.sourceNodeId).push(y.targetNodeId),o.get(y.targetNodeId).push(y.sourceNodeId))});const u=r.filter(y=>{var S;return(((S=o.get(y.id))==null?void 0:S.length)??0)===0});u.length===0&&r.length>0&&u.push(r[0]);const d=new Map,g=[];for(u.forEach(y=>{d.set(y.id,0),g.push(y.id)});g.length>0;){const y=g.shift(),S=d.get(y)??0;for(const N of c.get(y)??[])d.has(N)||(d.set(N,S+1),g.push(N))}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 m=new Map,h=i==="LR"||i==="RL",x=i==="BT"||i==="RL";return[...p.keys()].sort((y,S)=>y-S).forEach((y,S)=>{const N=p.get(y);let _=-(N.reduce((w,j)=>w+j.size.width,0)+(N.length-1)*a)/2;N.forEach(w=>{const j=S*(s+(h?w.size.width:w.size.height)),L=_+w.size.width/2;let R,V;h?(R=x?-j:j,V=L):(R=L,V=x?-j:j),m.set(w.id,{x:R,y:V}),_+=w.size.width+a})}),t.centerGraph&>(m),{positions:m}}function mr(r,e){const t=e.nodeSpacing??80,i=Math.ceil(Math.sqrt(r.length)),a=new Map;return r.forEach((s,c)=>{const o=c%i,l=Math.floor(c/i);a.set(s.id,{x:o*(s.size.width+t),y:l*(s.size.height+t)})}),e.centerGraph&>(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)),s=a[0];t.set(s.id,{x:0,y:0});const c=a.slice(1),o=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)*o,y:Math.sin(d)*o})}),{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,s=new Map;r.forEach(g=>{s.set(g.id,{x:(Math.random()-.5)*a,y:(Math.random()-.5)*a})});const c=e.map(g=>({source:g.sourceNodeId,target:g.targetNodeId})),o=t.nodeSpacing??150,l=80,u=.95;let d=a/2;for(let g=0;g<l;g++){const p=new Map;r.forEach(m=>p.set(m.id,{fx:0,fy:0}));for(let m=0;m<r.length;m++)for(let h=m+1;h<r.length;h++){const x=s.get(r[m].id),v=s.get(r[h].id),y=v.x-x.x,S=v.y-x.y,N=Math.max(Math.sqrt(y*y+S*S),1),I=o*o/N,_=y/N*I,w=S/N*I;p.get(r[m].id).fx-=_,p.get(r[m].id).fy-=w,p.get(r[h].id).fx+=_,p.get(r[h].id).fy+=w}for(const m of c){const h=s.get(m.source),x=s.get(m.target);if(!h||!x)continue;const v=x.x-h.x,y=x.y-h.y,S=Math.max(Math.sqrt(v*v+y*y),1),N=S*S/o,I=v/S*N,_=y/S*N;p.get(m.source).fx+=I,p.get(m.source).fy+=_,p.get(m.target).fx-=I,p.get(m.target).fy-=_}r.forEach(m=>{const h=p.get(m.id),x=s.get(m.id),v=Math.sqrt(h.fx*h.fx+h.fy*h.fy);if(v>0){const y=Math.min(v,d);x.x+=h.fx/v*y,x.y+=h.fy/v*y}}),d*=u}return r.forEach(g=>{i.set(g.id,{...s.get(g.id)})}),t.centerGraph&>(i),{positions:i}}function gt(r){if(r.size===0)return;let e=1/0,t=1/0,i=-1/0,a=-1/0;r.forEach(o=>{e=Math.min(e,o.x),t=Math.min(t,o.y),i=Math.max(i,o.x),a=Math.max(a,o.y)});const s=(e+i)/2,c=(t+a)/2;r.forEach(o=>{o.x-=s,o.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(o=>o+1),[]);b.useEffect(()=>t.subscribe(a),[t,a]);const s=t.getDocument(),c=b.useCallback(o=>{Ot(t.getNodes(),t.getEdges(),o).positions.forEach((u,d)=>{t.moveNode(d,u)})},[t]);return b.useMemo(()=>({document:s,nodes:s.nodes,edges:s.edges,groups:s.groups,animations:s.animations,viewport:s.viewport,addNode:(o,l,u,d)=>t.addNode(o,l,u,d),updateNode:(o,l)=>t.updateNode(o,l),moveNode:(o,l)=>t.moveNode(o,l),resizeNode:(o,l)=>t.resizeNode(o,l),removeNode:o=>t.removeNode(o),addEdge:(o,l,u,d,g)=>t.addEdge(o,l,u,d,g),updateEdge:(o,l)=>t.updateEdge(o,l),removeEdge:o=>t.removeEdge(o),createGroup:(o,l)=>t.createGroup(o,l),removeGroup:o=>t.removeGroup(o),toggleGroupCollapse:o=>t.toggleGroupCollapse(o),toggleNodeCollapse:o=>t.toggleNodeCollapse(o),addAnimation:o=>t.addAnimation(o),updateAnimation:(o,l)=>t.updateAnimation(o,l),removeAnimation:o=>t.removeAnimation(o),animationModes:t.getAnimationModes(),activeAnimationMode:t.getActiveAnimationMode(),addAnimationMode:(o,l)=>t.addAnimationMode(o,l),removeAnimationMode:o=>t.removeAnimationMode(o),setActiveAnimationMode:o=>t.setActiveAnimationMode(o),addAnimationToMode:(o,l)=>t.addAnimationToMode(o,l),removeAnimationFromMode:(o,l)=>t.removeAnimationFromMode(o,l),setStylePreset:o=>t.setStylePreset(o),setStyleOverrides:o=>t.setStyleOverrides(o),stylePresetId:s.stylePresetId,playerConfig:t.getPlayerConfig(),setPlayerConfig:o=>t.setPlayerConfig(o),setViewMode:o=>t.setViewMode(o),viewMode:t.getPlayerConfig().mode,applyLayout:c,setViewport:o=>t.setViewport(o),undo:()=>t.undo(),redo:()=>t.redo(),canUndo:t.canUndo(),canRedo:t.canRedo(),loadDocument:o=>t.loadDocument(o),model:t}),[s,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,s,c){return{canvas:r,nodeDefaults:vr(e,i),edgeDefaults:wr(e,a),groupDefaults:kr(e,s),fontFamily:t,palette:e,effects:c}}const Ce="'Inter', system-ui, sans-serif",mt="'Fira Code', 'Cascadia Code', monospace",_r="'Merriweather', 'Georgia', serif",Cr={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({}),Ce)},Mr=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-bg-secondary, #f8fafc)",textMuted:"var(--nice-text-secondary, #64748b)",border:"var(--nice-text, #334155)",surface:"var(--nice-text, #1e293b)",surfaceAlt:"var(--nice-text, #0f172a)"}),Nr={id:"default-dark",name:"Default Dark",category:"dark",themeSource:"Dark",config:le({background:"var(--nice-text, #0f172a)",gridColor:"var(--nice-text, #334155)",gridSize:20,selectionColor:"var(--nice-primary-light, #60a5fa)"},Mr,Ce,{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,Ce,{borderWidth:2,borderRadius:6},{strokeColor:"var(--nice-primary-light, #93c5fd)",strokeWidth:2})},jr=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-border, #e0e0e0)",textMuted:"var(--nice-text-secondary, #808080)",border:"#00ff8840",surface:"var(--nice-bg, #1a1a2e)",surfaceAlt:"var(--nice-bg, #16213e)"}),Ar={id:"neon-glow",name:"Neon Glow",category:"dark",config:le({background:"#0a0a1a",gridColor:"#00ff8810",gridSize:20,selectionColor:"var(--nice-success, #00ff88)"},jr,mt,{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)"})},zr=ce({primary:"var(--nice-accent-pink, #ff2d95)",primaryLight:"#ff6db6",secondary:"#7928ca",accent:"#00d4ff",success:"#39ff14",warning:"var(--nice-warning, #FFD700)",error:"#ff073a",info:"#00d4ff",text:"var(--nice-bg, #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-accent-pink, #ff2d95)"},zr,mt,{borderColor:"var(--nice-accent-pink, #ff2d95)",borderWidth:2,glowColor:"var(--nice-accent-pink, #ff2d95)",glowIntensity:.7,shadow:!0,gradientColor:"#2d004a",gradientDirection:"vertical"},{strokeColor:"#7928ca80",strokeWidth:3},{},{glowColor:"var(--nice-accent-pink, #ff2d95)",glowIntensity:.9,particleColor:"#00d4ff",liquidColor:"var(--nice-accent-pink, #ff2d95)",liquidColorEnd:"#7928ca"})},Dr=ce({primary:"var(--nice-bg, #fff)",primaryLight:"#ffffffaa",secondary:"#4da6ff",accent:"var(--nice-bg, #fff)",text:"var(--nice-bg, #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-bg, #fff)"},Dr,mt,{backgroundColor:"transparent",borderColor:"#4da6ff",borderWidth:1,borderStyle:"solid",fontColor:"var(--nice-bg, #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-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,Ce,{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-text, #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-text, #000000)",borderWidth:3,fontColor:"var(--nice-text, #000000)",fontWeight:"bold"},{strokeColor:"var(--nice-text, #000000)",strokeWidth:3},{borderColor:"var(--nice-text, #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)"}),Hr={id:"sunset-warm",name:"Sunset Warm",category:"creative",config:le({background:"#fffde7",gridColor:"#ffccbc20",gridSize:20,selectionColor:"var(--nice-warning-dark, #e65100)"},Xr,Ce,{borderColor:"#ff9e80",gradientColor:"var(--nice-warning-bg, #fff3e0)",gradientDirection:"vertical"},{strokeColor:"#ff9e80"},{},{liquidColor:"var(--nice-warning-dark, #e65100)",liquidColorEnd:"#ffd600",particleColor:"#ffd600"})},Ur=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"},Ur,Ce,{borderColor:"#00838f",borderRadius:12},{strokeColor:"#4dd0e1"},{},{liquidColor:"#006064",liquidColorEnd:"#4dd0e1",particleColor:"#ffd54f"})},Kr=ce({primary:"#5d4037",primaryLight:"#a1887f",secondary:"#795548",accent:"#c6a263",text:"#3e2723",textMuted:"#8d6e63",border:"#bcaaa4",surface:"#fdf6f0",surfaceAlt:"#efebe9"}),Zr={id:"elegant-serif",name:"Elegant Serif",category:"creative",config:le({background:"#fdf6f0",gridColor:"#bcaaa420",gridSize:24,selectionColor:"#5d4037"},Kr,_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-text-muted, #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,Ce,{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,Ce,{borderColor:"var(--nice-text-secondary, #9e9e9e)",borderWidth:1,shadow:!0,borderRadius:4},{strokeColor:"var(--nice-text-secondary, #9e9e9e)",strokeWidth:1.5})},si=ce({primary:"var(--nice-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"}),oi={id:"candy-pop",name:"Candy Pop",category:"creative",config:le({background:"#fff0f5",gridColor:"#f8bbd020",gridSize:20,selectionColor:"var(--nice-accent-pink, #e91e63)"},si,"'Quicksand', 'Nunito', sans-serif",{borderColor:"var(--nice-accent-pink, #e91e63)",borderRadius:24,borderWidth:3,gradientColor:"#f3e5f5",gradientDirection:"diagonal"},{strokeColor:"#f48fb1",strokeWidth:3},{borderRadius:20,borderColor:"#f48fb1"},{glowColor:"var(--nice-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-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-border, #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,Ce,{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-bg, #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-bg, #fff)",fontWeight:"bold",borderRadius:12,shadow:!0},{strokeColor:"#90a4ae",strokeWidth:3},{backgroundColor:"#2196f320",borderWidth:2,borderRadius:16})},gi=ce({primary:"#9333ea",primaryLight:"var(--nice-accent, #c084fc)",secondary:"var(--nice-info, #6366f1)",accent:"var(--nice-warning, #f59e0b)",text:"var(--nice-bg-secondary, #f1f5f9)",textMuted:"var(--nice-accent, #a78bfa)",border:"#7c3aed40",surface:"#1c1033",surfaceAlt:"#2d1b69"}),mi={id:"midnight-purple",name:"Midnight Purple",category:"dark",config:le({background:"#0f0720",gridColor:"#9333ea10",gridSize:20,selectionColor:"var(--nice-accent, #c084fc)"},gi,Ce,{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)"})},Ke=[Cr,Nr,Ir,Gr,Yr,Ar,$r,Tr,Fr,Rr,Hr,Jr,Zr,Er,ei,Br,ri,ai,oi,ci,di,fi,pi,mi],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-border, #e2e8f0)",gradientDirection:"vertical"}},{id:"fill-gradient-h",name:"Horizontal Gradient",category:"fill",style:{gradientColor:"var(--nice-border, #e2e8f0)",gradientDirection:"horizontal"}},{id:"fill-gradient-d",name:"Diagonal Gradient",category:"fill",style:{gradientColor:"var(--nice-border, #e2e8f0)",gradientDirection:"diagonal"}},{id:"fill-gradient-r",name:"Radial Gradient",category:"fill",style:{gradientColor:"var(--nice-border, #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 Ke.find(e=>e.id===r)}function vi(r){return Ke.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,s){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:s.color,surface:i.primary,surfaceAlt:i.secondary}),o=_i(i.primary);return{id:r,name:`${e} Theme`,category:"theme-based",themeSource:e,config:le({background:i.primary,gridColor:o?`${s.color}40`:`${s.color}20`,gridSize:20,selectionColor:t.primary},c,Ce,{shadow:!o,borderWidth:o?1:2},{strokeColor:o?`${s.color}80`:s.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 Ci=["fadeIn","fadeOut","slideInLeft","slideInRight","slideInTop","slideInBottom","zoomIn","zoomOut","pulse","shake","highlight","flowPulse","bounce","glow","colorShift","liquidFill","expand","collapse","ripple","typewriter","morphShape","drawPath","particleTrail"],Mi=["linear","easeIn","easeOut","easeInOut","spring","bounce"],Ze=({animations:r,onAdd:e,onRemove:t,onUpdate:i,onPlay:a,onStop:s,isPlaying:c=!1,availableTargets:o=[],className:l})=>{const{t:u}=Ee(),[d,g]=b.useState(!1),[p,m]=b.useState(null),h=b.useCallback(()=>{if(!e||o.length===0)return;const y=o[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,o]),x=b.useCallback(y=>{if(!e||o.length===0)return;const S=o[0];e({name:y.name,targetId:S.id,targetType:S.type,effect:y.effect,startMs:r.length*500,durationMs:y.durationMs,easing:y.easing}),g(!1)},[e,r.length,o]),v=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(M.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:s,children:["⏹ ",u("animation.stop")]}):n.jsxs(M.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:a,children:["▶ ",u("animation.play")]}),n.jsxs(M.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:h,disabled:o.length===0,children:["+ ",u("animation.add")]}),n.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[n.jsx(M.NiceButton,{className:"nice-diagram-timeline__btn",variant:"ghost",size:"sm",onClick:()=>g(y=>!y),disabled:o.length===0,title:"Add from preset",children:"🎬 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(M.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/v*100,N=y.durationMs/v*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:()=>m(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(M.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(M.NiceSelect,{value:y.effect,onChange:_=>i==null?void 0:i(y.id,{effect:_}),options:Ci.map(_=>({value:_,label:_})),style:{fontSize:11,padding:"1px 4px"}}),n.jsx(M.NiceSelect,{value:y.easing,onChange:_=>i==null?void 0:i(y.id,{easing:_}),options:Mi.map(_=>({value:_,label:_})),style:{fontSize:11,padding:"1px 4px"}}),n.jsx(M.NiceSelect,{value:y.targetId,onChange:_=>{const w=o.find(j=>j.id===_);w&&(i==null||i(y.id,{targetId:w.id,targetType:w.type}))},options:o.map(_=>({value:_.id,label:_.label})),style:{fontSize:11,padding:"1px 4px",maxWidth:100}}),n.jsx(M.NiceNumberInput,{value:y.startMs,min:0,step:100,onChange:_=>i==null?void 0:i(y.id,{startMs:_??0}),style:{width:60,fontSize:11},title:"Start (ms)"}),n.jsx(M.NiceNumberInput,{value:y.durationMs,min:50,step:50,onChange:_=>i==null?void 0:i(y.id,{durationMs:_??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:`${N}%`},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 N=Math.round(v/4*S);return n.jsxs("span",{className:"nice-diagram-timeline__ruler-mark",style:{left:`${S/4*100}%`},children:[N,"ms"]},S)})})]})};Ze.displayName="AnimationTimeline";const Ni=.1,Si=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:s,selectedId:c,selectedIds:o=[],onSelectElement:l,onMultiSelect:u,onNodeDragStart:d,onNodeDrag:g,onNodeDragEnd:p,onNodeResize:m,onNodeLabelChange:h,animationStates:x,particleState:v,viewMode:y="editor",ghostOpacity:S=.15,onGroupCollapse:N,onNodeCollapse:I,onInteraction:_,interactive:w=!1,showGrid:j=!0,showRulers:L=!1,snapToGrid:R=!0,gridSnapSize:V=10,className:B})=>{const C=b.useRef(null),[$,G]=b.useState(!1),[F,O]=b.useState({x:0,y:0}),[T,K]=b.useState(null),[q,H]=b.useState({x:0,y:0}),[X,ne]=b.useState(null),[E,Z]=b.useState(null),[ee,he]=b.useState(null),[de,me]=b.useState(null),[De,Te]=b.useState(""),[it,ge]=b.useState([]),at=(s==null?void 0:s.canvasBackground)??"var(--nice-bg-secondary, #f8f9fa)",Le=(s==null?void 0:s.gridColor)??"var(--nice-border, #e0e0e0)",Me=(s==null?void 0:s.gridSize)??20,Ne=(s==null?void 0:s.selectionColor)??"var(--nice-primary, #2196f3)",Fe=b.useMemo(()=>{const f=new Set(o);return c&&f.add(c),f},[c,o]),be=b.useCallback(f=>R?Math.round(f/V)*V:f,[R,V]),We=b.useCallback((f,k,A)=>{const D=[],z=k.x,P=k.y,Q=z+A.width/2,U=P+A.height/2,J=z+A.width,re=P+A.height;for(const ue of r){if(ue.id===f)continue;const ae=ue.position.x,se=ue.position.y,fe=ae+ue.size.width/2,ke=se+ue.size.height/2,Se=ae+ue.size.width,_e=se+ue.size.height;Math.abs(z-ae)<5&&D.push({x:ae}),Math.abs(J-Se)<5&&D.push({x:Se}),Math.abs(Q-fe)<5&&D.push({x:fe}),Math.abs(z-Se)<5&&D.push({x:Se}),Math.abs(J-ae)<5&&D.push({x:ae}),Math.abs(P-se)<5&&D.push({y:se}),Math.abs(re-_e)<5&&D.push({y:_e}),Math.abs(U-ke)<5&&D.push({y:ke}),Math.abs(P-_e)<5&&D.push({y:_e}),Math.abs(re-se)<5&&D.push({y:se})}ge(D)},[r]),we=b.useCallback(f=>{if(f.preventDefault(),!a)return;const k=f.deltaY>0?.9:1.1,A=Math.min(Si,Math.max(Ni,i.zoom*k)),D=C.current;if(!D)return;const W=D.getBoundingClientRect(),z=f.clientX-W.left,P=f.clientY-W.top,Q=A/i.zoom,U=z-(z-i.x)*Q,J=P-(P-i.y)*Q;a({x:U,y:J,zoom:A})},[i,a]),st=b.useCallback(f=>{if(f.button===1||f.button===0&&f.target.tagName==="svg"){if(f.button===0&&w&&!f.shiftKey&&f.target.tagName==="svg"){const k=C.current;if(k){const A=k.getBoundingClientRect(),D=(f.clientX-A.left-i.x)/i.zoom,W=(f.clientY-A.top-i.y)/i.zoom;Z({x:D,y:W}),ne({x1:D,y1:W,x2:D,y2:W})}l&&l(null),u&&u([]);return}G(!0),O({x:f.clientX-i.x,y:f.clientY-i.y}),l&&f.button===0&&l(null)}},[i,l,u,w]),ze=b.useCallback(f=>{if(E){const k=C.current;if(!k)return;const A=k.getBoundingClientRect(),D=(f.clientX-A.left-i.x)/i.zoom,W=(f.clientY-A.top-i.y)/i.zoom;ne({x1:E.x,y1:E.y,x2:D,y2:W});return}if($&&a){a({...i,x:f.clientX-F.x,y:f.clientY-F.y});return}if(ee&&m){const k=C.current;if(!k)return;const A=k.getBoundingClientRect(),D=(f.clientX-A.left-i.x)/i.zoom,W=(f.clientY-A.top-i.y)/i.zoom,z=D-ee.startMouse.x,P=W-ee.startMouse.y,Q=dt[ee.handleIdx];let U=ee.startSize.width+z*Q.resizeX,J=ee.startSize.height+P*Q.resizeY,re=ee.startPos.x+(Q.resizeX<0?z:0),ue=ee.startPos.y+(Q.resizeY<0?P:0);U=Math.max(30,be(U)),J=Math.max(20,be(J)),re=be(re),ue=be(ue),m(ee.nodeId,{width:U,height:J},{x:re,y:ue});return}if(T&&g){const k=C.current;if(!k)return;const A=k.getBoundingClientRect(),D=be((f.clientX-A.left-i.x)/i.zoom-q.x),W=be((f.clientY-A.top-i.y)/i.zoom-q.y);g(T,{x:D,y:W});const z=r.find(P=>P.id===T);z&&We(T,{x:D,y:W},z.size)}},[E,$,a,i,F,ee,m,T,g,q,be,r,We]),Be=b.useCallback(f=>{if(X&&E){const k=Math.min(X.x1,X.x2),A=Math.min(X.y1,X.y2),D=Math.max(X.x1,X.x2),W=Math.max(X.y1,X.y2);if(Math.abs(D-k)>5||Math.abs(W-A)>5){const z=r.filter(P=>{const Q=P.position.x,U=P.position.y,J=Q+P.size.width,re=U+P.size.height;return J>k&&Q<D&&re>A&&U<W}).map(P=>P.id);u==null||u(z),z.length===1&&(l==null||l(z[0]))}ne(null),Z(null);return}if($&&G(!1),ee){he(null);return}if(T&&p){const k=C.current;if(!k)return;const A=k.getBoundingClientRect(),D=be((f.clientX-A.left-i.x)/i.zoom-q.x),W=be((f.clientY-A.top-i.y)/i.zoom-q.y);p(T,{x:D,y:W})}K(null),ge([])},[X,E,$,ee,T,p,i,q,be,r,u,l]),qe=b.useCallback((f,k)=>{if(f.stopPropagation(),!w)return;const A=r.find(Q=>Q.id===k);if(!A||A.locked)return;if(f.shiftKey&&u){const Q=[...o],U=Q.indexOf(k);U>=0?Q.splice(U,1):Q.push(k),u(Q);return}l==null||l(k);const D=C.current;if(!D)return;const W=D.getBoundingClientRect(),z=(f.clientX-W.left-i.x)/i.zoom,P=(f.clientY-W.top-i.y)/i.zoom;H({x:z-A.position.x,y:P-A.position.y}),K(k),d==null||d(k)},[w,r,i,l,d,u,o]),ot=b.useCallback((f,k,A)=>{if(f.stopPropagation(),!w)return;const D=r.find(U=>U.id===k);if(!D||D.locked)return;const W=C.current;if(!W)return;const z=W.getBoundingClientRect(),P=(f.clientX-z.left-i.x)/i.zoom,Q=(f.clientY-z.top-i.y)/i.zoom;he({nodeId:k,handleIdx:A,startMouse:{x:P,y:Q},startPos:{...D.position},startSize:{...D.size}}),l==null||l(k)},[w,r,i,l]),nt=b.useCallback((f,k)=>{if(f.stopPropagation(),!w||!h)return;const A=r.find(D=>D.id===k);!A||A.locked||(me(k),Te(A.label))},[w,r,h]),Ge=b.useCallback(()=>{de&&h&&h(de,De),me(null)},[de,De,h]),Y=b.useCallback((f,k)=>{f.stopPropagation(),l==null||l(k)},[l]),je=b.useCallback(f=>{const k=r.find(A=>A.id===f);return k?{x:k.position.x+k.size.width/2,y:k.position.y+k.size.height/2}:{x:0,y:0}},[r]),ye=b.useCallback((f,k)=>{const A=r.find(P=>P.id===f);if(!A)return{x:0,y:0};const D=A.ports.find(P=>P.id===k);if(!D)return je(f);const{position:W,size:z}=A;switch(D.side){case"top":return{x:W.x+z.width*D.offset,y:W.y};case"bottom":return{x:W.x+z.width*D.offset,y:W.y+z.height};case"left":return{x:W.x,y:W.y+z.height*D.offset};case"right":return{x:W.x+z.width,y:W.y+z.height*D.offset};default:return je(f)}},[r,je]),nr=b.useCallback(f=>{const k=ye(f.sourceNodeId,f.sourcePortId),A=ye(f.targetNodeId,f.targetPortId);switch(f.style.lineType??"bezier"){case"straight":return`M ${k.x} ${k.y} L ${A.x} ${A.y}`;case"orthogonal":{const W=(k.x+A.x)/2;return`M ${k.x} ${k.y} L ${W} ${k.y} L ${W} ${A.y} L ${A.x} ${A.y}`}case"step":{const W=(k.y+A.y)/2;return`M ${k.x} ${k.y} L ${k.x} ${W} L ${A.x} ${W} L ${A.x} ${A.y}`}case"bezier":default:{const W=Math.abs(A.x-k.x)*.5;return`M ${k.x} ${k.y} C ${k.x+W} ${k.y}, ${A.x-W} ${A.y}, ${A.x} ${A.y}`}}},[ye]),cr=b.useCallback((f,k)=>{const{size:A,style:D,shape:W}=f,z=A.width,P=A.height,U=!!(D.gradientColor&&D.backgroundColor)?`url(#${k})`:D.backgroundColor??"var(--nice-bg, #fff)",J=D.borderColor??"var(--nice-text, #333333)",re=D.borderWidth??1,ue=D.borderRadius??(W==="roundedRect"?8:0),ae=D.borderStyle==="dashed"?"8,4":D.borderStyle==="dotted"?"2,4":void 0,se=D.shadow?"url(#nd-shadow)":void 0;switch(W){case"ellipse":case"circle":return n.jsx("ellipse",{cx:z/2,cy:P/2,rx:z/2,ry:P/2,fill:U,stroke:J,strokeWidth:re,strokeDasharray:ae,filter:se});case"diamond":return n.jsx("polygon",{points:`${z/2},0 ${z},${P/2} ${z/2},${P} 0,${P/2}`,fill:U,stroke:J,strokeWidth:re,strokeDasharray:ae,filter:se});case"hexagon":{const fe=z/4;return n.jsx("polygon",{points:`${fe},0 ${z-fe},0 ${z},${P/2} ${z-fe},${P} ${fe},${P} 0,${P/2}`,fill:U,stroke:J,strokeWidth:re,strokeDasharray:ae,filter:se})}case"parallelogram":{const fe=z*.15;return n.jsx("polygon",{points:`${fe},0 ${z},0 ${z-fe},${P} 0,${P}`,fill:U,stroke:J,strokeWidth:re,strokeDasharray:ae,filter:se})}case"cylinder":return n.jsxs("g",{filter:se,children:[n.jsx("ellipse",{cx:z/2,cy:P*.1,rx:z/2,ry:P*.1,fill:U,stroke:J,strokeWidth:re}),n.jsx("rect",{x:0,y:P*.1,width:z,height:P*.8,fill:U,stroke:"none"}),n.jsx("line",{x1:0,y1:P*.1,x2:0,y2:P*.9,stroke:J,strokeWidth:re}),n.jsx("line",{x1:z,y1:P*.1,x2:z,y2:P*.9,stroke:J,strokeWidth:re}),n.jsx("ellipse",{cx:z/2,cy:P*.9,rx:z/2,ry:P*.1,fill:U,stroke:J,strokeWidth:re})]});case"triangle":return n.jsx("polygon",{points:`${z/2},0 ${z},${P} 0,${P}`,fill:U,stroke:J,strokeWidth:re,strokeDasharray:ae,filter:se});case"cloud":{const fe=`M${z*.25},${P*.8} A${z*.2},${z*.2},0,1,1,${z*.15},${P*.45} A${z*.18},${z*.18},0,1,1,${z*.35},${P*.2} A${z*.2},${z*.2},0,1,1,${z*.65},${P*.2} A${z*.18},${z*.18},0,1,1,${z*.85},${P*.45} A${z*.2},${z*.2},0,1,1,${z*.75},${P*.8} Z`;return n.jsx("path",{d:fe,fill:U,stroke:J,strokeWidth:re,filter:se})}case"document":{const fe=`M 0 0 L ${z} 0 L ${z} ${P*.85} Q ${z*.75} ${P*.7}, ${z*.5} ${P*.85} Q ${z*.25} ${P}, 0 ${P*.85} Z`;return n.jsx("path",{d:fe,fill:U,stroke:J,strokeWidth:re,filter:se})}case"actor":return n.jsxs("g",{stroke:J,strokeWidth:re,fill:"none",filter:se,children:[n.jsx("circle",{cx:z/2,cy:P*.15,r:P*.12,fill:U}),n.jsx("line",{x1:z/2,y1:P*.27,x2:z/2,y2:P*.6}),n.jsx("line",{x1:z*.15,y1:P*.4,x2:z*.85,y2:P*.4}),n.jsx("line",{x1:z/2,y1:P*.6,x2:z*.2,y2:P}),n.jsx("line",{x1:z/2,y1:P*.6,x2:z*.8,y2:P})]});case"rectangle":case"roundedRect":case"custom":default:return n.jsx("rect",{width:z,height:P,rx:ue,ry:ue,fill:U,stroke:J,strokeWidth:re,strokeDasharray:ae,filter:se})}},[]),wt=b.useCallback(f=>{if(!x)return{};const k=x.get(f);if(!k)return{};const A=k.glow>0?`drop-shadow(0 0 ${k.glow}px gold)`:"",D=k.highlightColor?`drop-shadow(0 0 6px ${k.highlightColor})`:"";return{opacity:k.opacity,transform:`translate(${k.translateX}px, ${k.translateY}px) scale(${k.scale})`,filter:[A,D].filter(Boolean).join(" ")||void 0}},[x]),lr=b.useMemo(()=>{if(!v)return null;const f=[];for(const[,k]of v.glowStates){const A=$t(k.elementId),D=Dt(k.intensity,k.pulse);f.push(n.jsxs("filter",{id:A,x:"-50%",y:"-50%",width:"200%",height:"200%",children:[n.jsx("feGaussianBlur",{in:"SourceGraphic",stdDeviation:D,result:"blur"}),n.jsx("feFlood",{floodColor:k.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"})]})]},A))}return f},[v]),dr=b.useMemo(()=>{if(!v)return null;const f=[];for(const[k,A]of v.liquidFlows){if(!A.active)continue;const D=e.find(U=>U.id===k);if(!(D!=null&&D.style.liquidFlow))continue;const{color:W,colorEnd:z}=D.style.liquidFlow,P=`nd-liquid-${k}`,Q=A.gradientOffset;f.push(n.jsxs("linearGradient",{id:P,x1:"0",y1:"0",x2:"1",y2:"0",children:[n.jsx("stop",{offset:`${Q*100%100}%`,stopColor:W,stopOpacity:.8}),n.jsx("stop",{offset:`${(Q+.3)*100%100}%`,stopColor:z??W,stopOpacity:.4}),n.jsx("stop",{offset:`${(Q+.6)*100%100}%`,stopColor:W,stopOpacity:.8})]},P))}return f},[v,e]),ur=b.useMemo(()=>r.filter(f=>f.style.gradientColor&&f.style.backgroundColor).map(f=>{const k=`nd-grad-${f.id}`,A=f.style.gradientDirection??"vertical";if(A==="radial")return n.jsxs("radialGradient",{id:k,children:[n.jsx("stop",{offset:"0%",stopColor:f.style.backgroundColor}),n.jsx("stop",{offset:"100%",stopColor:f.style.gradientColor})]},k);const D=A==="horizontal"||A==="diagonal"?"1":"0",W=A==="vertical"||A==="diagonal"?"1":"0";return n.jsxs("linearGradient",{id:k,x1:"0",y1:"0",x2:D,y2:W,children:[n.jsx("stop",{offset:"0%",stopColor:f.style.backgroundColor}),n.jsx("stop",{offset:"100%",stopColor:f.style.gradientColor})]},k)}),[r]);return n.jsxs("svg",{ref:C,className:`nice-diagram-canvas ${B??""}`,style:{width:"100%",height:"100%",background:at,cursor:$?"grabbing":ee&&ee.nodeId?dt[ee.handleIdx].cursor:"default"},onWheel:we,onMouseDown:st,onMouseMove:ze,onMouseUp:Be,onMouseLeave:Be,children:[n.jsxs("defs",{children:[n.jsx("marker",{id:"nd-arrow",viewBox:"0 0 10 10",refX:"10",refY:"5",markerWidth:"8",markerHeight:"8",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",markerWidth:"8",markerHeight:"8",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",markerWidth:"10",markerHeight:"10",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",markerWidth:"8",markerHeight:"8",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"})}),j&&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 k=`nd-node-glow-${f.id}`,A=(f.style.glowIntensity??.5)*10;return n.jsxs("filter",{id:k,x:"-50%",y:"-50%",width:"200%",height:"200%",children:[n.jsx("feGaussianBlur",{in:"SourceGraphic",stdDeviation:A,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"})]})]},k)})]}),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,k)=>{const A=k*Me*i.zoom+i.x,D=k*Me;return A>20?n.jsxs("g",{children:[n.jsx("line",{x1:A,y1:"0",x2:A,y2:"20",stroke:"var(--nice-text-muted, #999)",strokeWidth:"0.5"}),n.jsx("text",{x:A+2,y:"14",fontSize:"9",fill:"var(--nice-text-secondary, #666)",children:D})]},`rx${k}`):null}),Array.from({length:100},(f,k)=>{const A=k*Me*i.zoom+i.y,D=k*Me;return A>20?n.jsxs("g",{children:[n.jsx("line",{x1:"0",y1:A,x2:"20",y2:A,stroke:"var(--nice-text-muted, #999)",strokeWidth:"0.5"}),n.jsx("text",{x:"2",y:A-2,fontSize:"9",fill:"var(--nice-text-secondary, #666)",writingMode:"tb",children:D})]},`ry${k}`):null})]}),n.jsxs("g",{transform:`translate(${i.x}, ${i.y}) scale(${i.zoom})`,children:[j&&n.jsx("rect",{x:"-10000",y:"-10000",width:"20000",height:"20000",fill:"url(#nd-grid)"}),t.map(f=>{var Q,U,J,re,ue,ae,se,fe,ke,Se,_e,Ve;const k=r.filter(oe=>f.nodeIds.includes(oe.id));if(k.length===0&&!f.collapsed)return null;const A=((Q=f.style)==null?void 0:Q.padding)??20;if(f.collapsed){const oe=r.find(ct=>f.nodeIds.includes(ct.id)),Pe=oe?oe.position.x:0,Ye=oe?oe.position.y:0;return n.jsxs("g",{style:{cursor:"pointer"},onClick:()=>N==null?void 0:N(f.id),children:[n.jsx("rect",{x:Pe,y:Ye,width:160,height:40,fill:((U=f.style)==null?void 0:U.backgroundColor)??"rgba(200,200,255,0.3)",stroke:((J=f.style)==null?void 0:J.borderColor)??"var(--nice-text-muted, #aab)",strokeWidth:((re=f.style)==null?void 0:re.borderWidth)??1,rx:((ue=f.style)==null?void 0:ue.borderRadius)??6,strokeDasharray:"6,3"}),n.jsxs("text",{x:Pe+24,y:Ye+24,fontSize:"12",fill:((ae=f.style)==null?void 0:ae.labelColor)??"var(--nice-text-secondary, #666)",fontWeight:"bold",children:["▶ ",f.label," (",f.nodeIds.length,")"]})]},f.id)}const D=Math.min(...k.map(oe=>oe.position.x))-A,W=Math.min(...k.map(oe=>oe.position.y))-A,z=Math.max(...k.map(oe=>oe.position.x+oe.size.width))+A,P=Math.max(...k.map(oe=>oe.position.y+oe.size.height))+A;return n.jsxs("g",{children:[n.jsx("rect",{x:D,y:W,width:z-D,height:P-W,fill:((se=f.style)==null?void 0:se.backgroundColor)??"rgba(200,200,255,0.1)",stroke:((fe=f.style)==null?void 0:fe.borderColor)??"var(--nice-text-muted, #aab)",strokeWidth:((ke=f.style)==null?void 0:ke.borderWidth)??1,rx:((Se=f.style)==null?void 0:Se.borderRadius)??6,strokeDasharray:((_e=f.style)==null?void 0:_e.borderStyle)==="dashed"?"6,3":void 0}),n.jsx("text",{x:D+6,y:W-4,fontSize:"12",fill:((Ve=f.style)==null?void 0:Ve.labelColor)??"var(--nice-text-secondary, #666)",fontWeight:"bold",children:f.label}),(w||y!=="editor")&&N&&n.jsxs("g",{style:{cursor:"pointer"},onClick:oe=>{oe.stopPropagation(),N(f.id)},children:[n.jsx("rect",{x:z-24,y:W-12,width:20,height:20,rx:4,fill:"white",stroke:"var(--nice-text-muted, #999)",strokeWidth:1}),n.jsx("text",{x:z-14,y:W+3,textAnchor:"middle",fontSize:"12",fill:"var(--nice-text-secondary, #666)",children:"▼"})]})]},f.id)}),it.map((f,k)=>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-${k}`)),e.map(f=>{var ue;const k=nr(f),A=Fe.has(f.id),D=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,W=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,z=wt(f.id),P=x==null?void 0:x.get(f.id),Q=P==null?void 0:P.strokeProgress,U=Q!=null&&Q>=0&&Q<1?{strokeDasharray:"1000",strokeDashoffset:`${1e3*(1-Q)}`}:void 0,J=f.style.liquidFlow,re=v==null?void 0:v.liquidFlows.get(f.id);return n.jsxs("g",{style:z,onClick:ae=>Y(ae,f.id),children:[w&&n.jsx("path",{d:k,fill:"none",stroke:"transparent",strokeWidth:12,style:{cursor:"pointer"}}),(J==null?void 0:J.active)&&n.jsx("path",{d:k,fill:"none",stroke:`url(#nd-liquid-${f.id})`,strokeWidth:J.pipeWidth??(f.style.strokeWidth??1.5)*4,strokeLinecap:"round",opacity:.5}),n.jsx("path",{d:k,fill:"none",stroke:A?Ne:f.style.strokeColor??"var(--nice-text, #333)",strokeWidth:f.style.strokeWidth??1.5,strokeDasharray:(U==null?void 0:U.strokeDasharray)??((ue=f.style.strokeDash)==null?void 0:ue.join(","))??(f.style.animated?"6,4":void 0),strokeDashoffset:U==null?void 0:U.strokeDashoffset,markerEnd:D,markerStart:W,opacity:f.style.opacity??1,style:w?{cursor:"pointer",transition:U?void 0:"stroke-dashoffset 0.1s"}:void 0}),f.style.animated&&n.jsx("circle",{r:3,fill:Ne,children:n.jsx("animateMotion",{dur:`${1/(f.style.flowSpeed||1)}s`,repeatCount:"indefinite",path:k})}),(re==null?void 0:re.active)&&re.particles.map((ae,se)=>n.jsx("circle",{r:ae.size,fill:(J==null?void 0:J.color)??"var(--nice-primary, #3b82f6)",opacity:ae.opacity*.6,children:n.jsx("animateMotion",{dur:`${3/(((J==null?void 0:J.speed)??1)+.5)}s`,repeatCount:"indefinite",path:k,begin:`${ae.t*3}s`})},`lp-${f.id}-${se}`)),P&&P.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:k,begin:`${P.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:k,begin:`${(P.particleTrailT+.1)*2}s`})})]}),f.label&&(()=>{const ae=ye(f.sourceNodeId,f.sourcePortId),se=ye(f.targetNodeId,f.targetPortId),fe=(ae.x+se.x)/2,ke=(ae.y+se.y)/2;return n.jsxs("g",{children:[n.jsx("rect",{x:fe-4,y:ke-16,width:f.label.length*7+8,height:18,rx:3,fill:"white",fillOpacity:.85}),n.jsx("text",{x:fe,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 k=Fe.has(f.id),A=wt(f.id),D=x==null?void 0:x.get(f.id),W=f.style.fontFamily??(s==null?void 0:s.fontFamily)??"sans-serif",z=f.style.fontSize??14,P=f.style.fontColor??"var(--nice-text, #222)",Q=f.style.fontWeight??"normal",U=f.style.fontStyle??"normal",J=f.style.textAlign??"center",re=f.style.rotation??0,ue=`nd-grad-${f.id}`,ae=!!f.hidden,se=ae?S??.3:f.style.opacity??1,fe=f.style.glowColor?`url(#nd-node-glow-${f.id})`:void 0,ke=J==="left"?"start":J==="right"?"end":"middle",Se=J==="left"?8:J==="right"?f.size.width-8:f.size.width/2,_e=D==null?void 0:D.typewriterChars,Ve=_e!=null&&_e>=0?f.label.slice(0,_e):f.label,oe=D==null?void 0:D.liquidFillProgress,Pe=D==null?void 0:D.rippleRadius,Ye=D==null?void 0:D.rippleOpacity,ct=f.childNodeIds&&f.childNodeIds.length>0,fr=!!f.collapsed;return n.jsxs("g",{transform:`translate(${f.position.x}, ${f.position.y})${re?` rotate(${re}, ${f.size.width/2}, ${f.size.height/2})`:""}`,style:{...A,cursor:ae?"pointer":w&&!f.locked?"grab":"default",opacity:se,filter:fe},onMouseDown:pe=>qe(pe,f.id),onDoubleClick:pe=>nt(pe,f.id),onClick:pe=>{pe.stopPropagation(),l==null||l(f.id),f.interactions&&f.interactions.length>0&&f.interactions.filter(Oe=>Oe.trigger==="click").forEach(Oe=>_==null?void 0:_(f.id,Oe.id))},onMouseEnter:()=>{f.interactions&&f.interactions.filter(Ie=>Ie.trigger==="hover").forEach(Ie=>_==null?void 0:_(f.id,Ie.id))},children:[ae&&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,ue),oe!=null&&oe>0&&oe<1&&n.jsx("clipPath",{id:`nd-liquid-clip-${f.id}`,children:n.jsx("rect",{x:0,y:f.size.height*(1-oe),width:f.size.width,height:f.size.height*oe})}),oe!=null&&oe>0&&oe<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??Ne,strokeWidth:2,opacity:Ye??.5}),k&&n.jsx("rect",{x:-3,y:-3,width:f.size.width+6,height:f.size.height+6,fill:"none",stroke:Ne,strokeWidth:2,strokeDasharray:"4,3",rx:6}),k&&w&&!f.locked&&dt.map((pe,Ie)=>n.jsx("rect",{x:pe.dx*f.size.width-Xe/2,y:pe.dy*f.size.height-Xe/2,width:Xe,height:Xe,fill:"white",stroke:Ne,strokeWidth:1.5,rx:1,style:{cursor:pe.cursor},onMouseDown:Oe=>ot(Oe,f.id,Ie)},Ie)),de===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:De,onChange:pe=>Te(pe.target.value),onBlur:Ge,onKeyDown:pe=>{pe.key==="Enter"&&Ge(),pe.key==="Escape"&&me(null)},autoFocus:!0,style:{width:"100%",height:"100%",border:"1px solid "+Ne,borderRadius:3,padding:"2px 4px",fontSize:z,fontFamily:W,fontWeight:Q,fontStyle:U,textAlign:J,background:"var(--nice-overlay-light-95, rgba(255, 255, 255, 0.95))",outline:"none"}})}):n.jsxs(n.Fragment,{children:[n.jsx("text",{x:Se,y:f.size.height/2+(f.description?-4:0),textAnchor:ke,dominantBaseline:"central",fontFamily:W,fontSize:z,fontWeight:Q,fontStyle:U,fill:P,pointerEvents:"none",children:Ve}),f.description&&n.jsx("text",{x:Se,y:f.size.height/2+z*.8,textAnchor:ke,dominantBaseline:"central",fontFamily:W,fontSize:z*.75,fill:"var(--nice-text-secondary, #777)",pointerEvents:"none",children:f.description}),f.icon&&n.jsx("text",{x:f.size.width/2,y:14,textAnchor:"middle",fontSize:16,pointerEvents:"none",children:f.icon}),f.style.linkUrl&&n.jsx("text",{x:f.size.width-4,y:12,textAnchor:"end",fontSize:10,fill:"var(--nice-primary-hover, #1976d2)",pointerEvents:"none",children:"🔗"}),ct&&w&&n.jsxs("g",{onClick:pe=>{pe.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("text",{x:f.size.width-10,y:f.size.height-7,textAnchor:"middle",dominantBaseline:"central",fontSize:10,fill:"var(--nice-text-secondary, #666)",children:fr?"▶":"▼"})]})]}),w&&f.ports.map(pe=>{const Ie=Ii(f,pe.id);return n.jsx("circle",{cx:Ie.x,cy:Ie.y,r:4,fill:"var(--nice-bg, #fff)",stroke:"var(--nice-text-secondary, #666)",strokeWidth:1,style:{cursor:"crosshair"}},pe.id)})]},f.id)}),v&&v.particles.length>0&&n.jsx("g",{className:"nd-particle-overlay",children:v.particles.map((f,k)=>n.jsx("circle",{cx:f.x,cy:f.y,r:f.size,fill:f.color,opacity:f.opacity},`ptcl-${k}`))}),X&&n.jsx("rect",{x:Math.min(X.x1,X.x2),y:Math.min(X.y1,X.y2),width:Math.abs(X.x2-X.x1),height:Math.abs(X.y2-X.y1),fill:"rgba(33,150,243,0.1)",stroke:Ne,strokeWidth:1,strokeDasharray:"4,2"})]})]})};function Ii(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:s=600,width:c=ji,height:o=Ai,className:l})=>{const u=b.useMemo(()=>{if(r.length===0)return{minX:0,minY:0,maxX:400,maxY:300};let x=1/0,v=1/0,y=-1/0,S=-1/0;for(const I of r)x=Math.min(x,I.position.x),v=Math.min(v,I.position.y),y=Math.max(y,I.position.x+I.size.width),S=Math.max(S,I.position.y+I.size.height);const N=50;return{minX:x-N,minY:v-N,maxX:y+N,maxY:S+N}},[r]),d=u.maxX-u.minX,g=u.maxY-u.minY,p=Math.min(c/d,o/g),m=b.useMemo(()=>{const x=(-t.x/t.zoom-u.minX)*p,v=(-t.y/t.zoom-u.minY)*p,y=a/t.zoom*p,S=s/t.zoom*p;return{x,y:v,w:y,h:S}},[t,u,p,a,s]),h=b.useCallback(x=>{if(!i)return;const v=x.currentTarget.getBoundingClientRect(),y=x.clientX-v.left,S=x.clientY-v.top,N=y/p+u.minX,I=S/p+u.minY;i({...t,x:-(N*t.zoom-a/2),y:-(I*t.zoom-s/2)})},[i,t,p,u,a,s]);return n.jsxs("svg",{className:`nice-diagram-minimap ${l??""}`,width:c,height:o,style:{border:"1px solid var(--nice-border, #ccc)",background:"var(--nice-bg, #fff)",borderRadius:4,cursor:"pointer"},onClick:h,children:[e.map(x=>{const v=r.find(w=>w.id===x.sourceNodeId),y=r.find(w=>w.id===x.targetNodeId);if(!v||!y)return null;const S=(v.position.x+v.size.width/2-u.minX)*p,N=(v.position.y+v.size.height/2-u.minY)*p,I=(y.position.x+y.size.width/2-u.minX)*p,_=(y.position.y+y.size.height/2-u.minY)*p;return n.jsx("line",{x1:S,y1:N,x2:I,y2:_,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:m.x,y:m.y,width:m.w,height:m.h,fill:"rgba(33,150,243,0.15)",stroke:"var(--nice-primary, #2196f3)",strokeWidth:1})]})};Qe.displayName="DiagramMinimap";const zi=["rectangle","roundedRect","ellipse","circle","diamond","hexagon","parallelogram","cylinder","triangle","cloud","document","actor"],et=({selectedNode:r,selectedEdge:e,onNodeChange:t,onEdgeChange:i,onRemove:a,className:s})=>{var u,d,g,p,m;const{t:c}=Ee(),o=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 ${s??""}`,children:n.jsx("p",{className:"nice-diagram-property-panel__hint",children:c("panel.noSelection")})}):r?n.jsxs("div",{className:`nice-diagram-property-panel ${s??""}`,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(M.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(M.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(M.NiceSelect,{value:r.shape,onChange:h=>t==null?void 0:t(r.id,{shape:h}),options:zi.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(M.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(M.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(M.NiceColorPicker,{value:r.style.backgroundColor??"var(--nice-bg, #fff)",onChange:h=>o("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(M.NiceColorPicker,{value:r.style.borderColor??"var(--nice-text, #333333)",onChange:h=>o("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(M.NiceNumberInput,{value:r.style.fontSize??14,min:8,max:72,onChange:h=>o("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(M.NiceColorPicker,{value:r.style.fontColor??"var(--nice-bg, #222222)",onChange:h=>o("fontColor",h),className:"nice-diagram-property-panel__color"})]})]}),n.jsx(M.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(M.NiceColorPicker,{value:r.style.glowColor??"var(--nice-primary, #3b82f6)",onChange:h=>o("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(M.NiceSlider,{min:0,max:3,step:.1,value:r.style.glowIntensity??0,onChange:h=>o("glowIntensity",h),className:"nice-diagram-property-panel__input"})]})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Opacity",n.jsx(M.NiceSlider,{min:0,max:1,step:.05,value:r.style.opacity??1,onChange:h=>o("opacity",h),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Border Radius",n.jsx(M.NiceNumberInput,{min:0,max:50,value:r.style.borderRadius??4,onChange:h=>o("borderRadius",h??4),className:"nice-diagram-property-panel__input"})]}),n.jsxs("label",{className:"nice-diagram-property-panel__label",children:["Border Width",n.jsx(M.NiceNumberInput,{min:0,max:10,step:.5,value:r.style.borderWidth??1,onChange:h=>o("borderWidth",h??1),className:"nice-diagram-property-panel__input"})]}),n.jsx(M.NiceCheckbox,{checked:r.style.shadow??!1,onChange:h=>o("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(M.NiceColorPicker,{value:r.style.gradientColor??"var(--nice-bg, #fff)",onChange:h=>o("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(M.NiceSelect,{value:r.style.gradientDirection??"vertical",onChange:h=>o("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(M.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(M.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 ${s??""}`,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(M.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(M.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(M.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(M.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(M.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(M.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(M.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(M.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(M.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(M.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(M.NiceColorPicker,{value:((g=e.style.liquidFlow)==null?void 0:g.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(M.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(M.NiceNumberInput,{min:2,max:20,value:((m=e.style.liquidFlow)==null?void 0:m.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(M.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(M.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 Ct={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"]},$i=["dagre","forceDirected","grid","radial","tree"],Di=["sans-serif","serif","monospace","Arial","Helvetica","Times New Roman","Courier New","Georgia","Verdana","Tahoma","Trebuchet MS"],Ti=[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:s,onRedo:c,canUndo:o=!1,canRedo:l=!1,onExport:u,onZoomIn:d,onZoomOut:g,onZoomReset:p,zoomLevel:m=1,onToggleBold:h,onToggleItalic:x,isBold:v=!1,isItalic:y=!1,onFontFamilyChange:S,currentFontFamily:N="sans-serif",onFontSizeChange:I,currentFontSize:_=14,onAlignLeft:w,onAlignCenterH:j,onAlignRight:L,onAlignTop:R,onAlignCenterV:V,onAlignBottom:B,onDistributeH:C,onDistributeV:$,onBringToFront:G,onSendToBack:F,onGroupSelected:O,onUngroupSelected:T,onCopy:K,onPaste:q,onDuplicate:H,onSelectAll:X,selectionCount:ne=0,onFind:E,showFind:Z=!1,findQuery:ee="",onFindQueryChange:he,viewMode:de="editor",onViewModeChange:me,stylePresetId:De,onStylePresetChange:Te,className:it})=>{const{t:ge}=Ee(),[at,Le]=b.useState(!1),[Me,Ne]=b.useState(!1),[Fe,be]=b.useState(!1),[We,we]=b.useState(!1),[st,ze]=b.useState(!1),[Be,qe]=b.useState(!1),ot=Ct[t]??Ct.custom,nt=b.useCallback(Y=>{i==null||i(Y),Le(!1)},[i]),Ge=b.useCallback(Y=>{a==null||a(Y),Ne(!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(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="select"?"primary":"ghost",size:"sm",onClick:()=>e("select"),title:`${ge("toolbar.select")} (V)`,children:"◇"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="pan"?"primary":"ghost",size:"sm",onClick:()=>e("pan"),title:`${ge("toolbar.pan")} (H)`,children:"✋"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="addEdge"?"primary":"ghost",size:"sm",onClick:()=>e("addEdge"),title:`${ge("toolbar.addEdge")} (C)`,children:"↗"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="text"?"primary":"ghost",size:"sm",onClick:()=>e("text"),title:"Text (T)",children:"T"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="freehand"?"primary":"ghost",size:"sm",onClick:()=>e("freehand"),title:"Freehand (F)",children:"✎"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="delete"?"primary":"ghost",size:"sm",onClick:()=>e("delete"),title:`${ge("toolbar.delete")} (Del)`,children:"🗑"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:r==="addNode"?"primary":"ghost",size:"sm",onClick:()=>Le(Y=>!Y),title:ge("toolbar.addNode"),children:["+ ",ge("toolbar.addNode")]}),at&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown nice-diagram-toolbar__dropdown--shapes",children:ot.map(Y=>n.jsxs(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>nt(Y),children:[Pi(Y)," ",Y]},Y))})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:K,title:"Copy (Ctrl+C)",children:"📋"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:q,title:"Paste (Ctrl+V)",children:"📃"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:H,title:"Duplicate (Ctrl+D)",children:"⧉"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:X,title:"Select All (Ctrl+A)",children:"⬚"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:s,disabled:!o,title:`${ge("toolbar.undo")} (Ctrl+Z)`,children:"↩"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:c,disabled:!l,title:`${ge("toolbar.redo")} (Ctrl+Y)`,children:"↪"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:g,title:ge("toolbar.zoomOut"),children:"−"}),n.jsxs("span",{className:"nice-diagram-toolbar__zoom-label",children:[Math.round(m*100),"%"]}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:d,title:ge("toolbar.zoomIn"),children:"+"}),n.jsx(M.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(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:E,title:"Find (Ctrl+F)",children:"🔍"}),Z&&n.jsx(M.NiceTextInput,{className:"nice-diagram-toolbar__search",placeholder:"Search nodes…",value:ee,onChange:Y=>he==null?void 0:he(Y),autoFocus:!0})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>be(Y=>!Y),title:ge("toolbar.export"),children:["⤓ ",ge("toolbar.export")]}),Fe&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("ndd"),be(!1)},children:".ndd.json"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("svg"),be(!1)},children:"SVG"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{u==null||u("mermaid"),be(!1)},children:"Mermaid"}),n.jsx(M.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(M.NiceSelect,{className:"nice-diagram-toolbar__font-select",value:N,onChange:Y=>S==null?void 0:S(Y),options:Di.map(Y=>({value:Y,label:Y})),title:"Font Family"}),n.jsx(M.NiceSelect,{className:"nice-diagram-toolbar__size-select",value:String(_),onChange:Y=>I==null?void 0:I(Number(Y)),options:Ti.map(Y=>({value:String(Y),label:String(Y)})),title:"Font Size"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:v?"primary":"ghost",size:"sm",onClick:h,title:"Bold (Ctrl+B)",children:n.jsx("strong",{children:"B"})}),n.jsx(M.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(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>we(Y=>!Y),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.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{w==null||w(),we(!1)},title:"Align Left",children:"⫷ Left"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{j==null||j(),we(!1)},title:"Align Center",children:"⫿ Center"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{L==null||L(),we(!1)},title:"Align Right",children:"⫸ Right"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{R==null||R(),we(!1)},title:"Align Top",children:"⫠ Top"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{V==null||V(),we(!1)},title:"Align Middle",children:"⫟ Middle"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{B==null||B(),we(!1)},title:"Align Bottom",children:"⫡ Bottom"})]}),n.jsx("div",{className:"nice-diagram-toolbar__dropdown-section",children:"Distribute"}),n.jsxs("div",{className:"nice-diagram-toolbar__dropdown-row",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{C==null||C(),we(!1)},title:"Distribute Horizontally",children:"⟺ H"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{$==null||$(),we(!1)},title:"Distribute Vertically",children:"⟺ V"})]})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>ze(Y=>!Y),title:"Arrange",children:"☰ Arrange"}),st&&n.jsxs("div",{className:"nice-diagram-toolbar__dropdown",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{G==null||G(),ze(!1)},children:"↑ Bring to Front"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{F==null||F(),ze(!1)},children:"↓ Send to Back"}),n.jsx("div",{className:"nice-diagram-toolbar__dropdown-divider"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{O==null||O(),ze(!1)},disabled:ne<2,children:"⊞ Group"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>{T==null||T(),ze(!1)},children:"⊟ Ungroup"})]})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsxs(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>Ne(Y=>!Y),title:ge("toolbar.layout"),children:["⊞ ",ge("toolbar.layout")]}),Me&&n.jsx("div",{className:"nice-diagram-toolbar__dropdown",children:$i.map(Y=>n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__dropdown-item",variant:"ghost",size:"sm",onClick:()=>Ge(Y),children:ge(`layout.${Y}`)},Y))})]}),ne>1&&n.jsxs("span",{className:"nice-diagram-toolbar__selection-info",children:[ne," selected"]}),n.jsxs("div",{className:"nice-diagram-toolbar__group",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:de==="editor"?"primary":"ghost",size:"sm",onClick:()=>me==null?void 0:me("editor"),title:"Editor Mode",children:"🖊 Editor"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:de==="player"?"primary":"ghost",size:"sm",onClick:()=>me==null?void 0:me("player"),title:"Player Mode",children:"▶ Player"}),n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:de==="playerAnimated"?"primary":"ghost",size:"sm",onClick:()=>me==null?void 0:me("playerAnimated"),title:"Animated Player Mode",children:"⚡ Animated"})]}),n.jsxs("div",{className:"nice-diagram-toolbar__group nice-diagram-toolbar__group--relative",children:[n.jsx(M.NiceButton,{className:"nice-diagram-toolbar__btn",variant:"ghost",size:"sm",onClick:()=>qe(Y=>!Y),title:"Style Presets",children:"🎨 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(Ke.reduce((Y,je)=>{const ye=je.category??"Other";return Y[ye]||(Y[ye]=[]),Y[ye].push(je),Y},{})).map(([Y,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:Y}),je.map(ye=>n.jsxs(M.NiceButton,{className:`nice-diagram-toolbar__dropdown-item ${De===ye.id?"nice-diagram-toolbar__dropdown-item--active":""}`,variant:De===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))]},Y))})]})]})]})};function Pi(r){switch(r){case"rectangle":return"▭";case"roundedRect":return"▢";case"ellipse":return"⬭";case"circle":return"●";case"diamond":return"◇";case"hexagon":return"⬡";case"parallelogram":return"▱";case"cylinder":return"⌂";case"triangle":return"△";case"cloud":return"☁";case"document":return"📄";case"actor":return"🧑";default:return"▢"}}tt.displayName="DiagramToolbar";const Ri=[{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:s=!0,showPropertyPanel:c=!0,showMinimap:o=!0,showTimeline:l=!0,className:u,style:d,tutorial:g})=>{var ne;const p=Lt(r),[m,h]=b.useState("select"),[x,v]=b.useState(null),y=b.useRef(null),[S,N]=b.useState("editor"),I=b.useRef(null),[_,w]=b.useState({particles:[],liquidFlows:new Map,glowStates:new Map});b.useEffect(()=>{const E=new zt(Z=>{w(Z)});return I.current=E,E.start(),()=>{E.stop(),I.current=null}},[]),b.useEffect(()=>{var Z;const E=I.current;if(E)for(const ee of p.edges)(Z=ee.style.liquidFlow)!=null&&Z.active?E.startLiquidFlow(ee.id,ee.style.liquidFlow):E.stopLiquidFlow(ee.id)},[p.edges]),b.useEffect(()=>{const E=I.current;if(E)for(const Z of p.nodes)Z.style.glowColor?E.setGlow(Z.id,Z.style.glowColor,Z.style.glowIntensity??1):E.removeGlow(Z.id)},[p.nodes]);const j=b.useCallback(E=>{p.setStylePreset(E)},[p]),L=b.useCallback((E,Z)=>{const ee=p.nodes.find(de=>de.id===E);if(!(ee!=null&&ee.interactions))return;const he=ee.interactions.find(de=>de.id===Z);if(he)switch(he.action){case"reveal":{if(he.targetId){const de=p.nodes.find(me=>me.id===he.targetId);de!=null&&de.hidden&&p.updateNode(he.targetId,{hidden:!1})}break}case"navigate":{if(he.targetId){const de=p.nodes.find(me=>me.id===he.targetId);de&&(p.setViewport({x:-de.position.x+300,y:-de.position.y+200,zoom:p.viewport.zoom}),v(he.targetId))}break}case"switchAnimationMode":{he.targetId&&p.setActiveAnimationMode(he.targetId);break}case"highlight":{he.targetId&&v(he.targetId);break}case"toggleCollapse":{p.toggleNodeCollapse(E);break}}},[p]),R=b.useRef(p.document);p.document!==R.current&&(R.current=p.document,t==null||t(p.document));const V=b.useMemo(()=>x?p.nodes.find(E=>E.id===x)??null:null,[x,p.nodes]),B=b.useMemo(()=>x?p.edges.find(E=>E.id===x)??null:null,[x,p.edges]),C=b.useCallback(E=>{const Z=p.viewport,ee=(-Z.x+400)/Z.zoom,he=(-Z.y+300)/Z.zoom,de=p.addNode("New Node",{x:ee,y:he},E);v(de.id),h("select")},[p]),$=b.useCallback(E=>{p.applyLayout({algorithm:E,centerGraph:!0})},[p]),G=b.useCallback((E,Z)=>{p.moveNode(E,Z)},[p]),F=b.useCallback((E,Z)=>{p.moveNode(E,Z)},[p]),O=b.useCallback(E=>{p.nodes.find(Z=>Z.id===E)?p.removeNode(E):p.edges.find(Z=>Z.id===E)&&p.removeEdge(E),v(null)},[p]),T=b.useCallback(E=>{const Z=p.document;let ee;switch(E){case"ndd":ee=Rt(Z,!0);break;case"svg":ee=ft(Z);break;case"mermaid":ee=Tt(Z);break;case"png":ee=ft(Z);break}i==null||i(E,ee)},[p,i]),K=b.useCallback(()=>{p.setViewport({...p.viewport,zoom:Math.min(5,p.viewport.zoom*1.2)})},[p]),q=b.useCallback(()=>{p.setViewport({...p.viewport,zoom:Math.max(.1,p.viewport.zoom/1.2)})},[p]),H=b.useCallback(()=>{p.setViewport({x:0,y:0,zoom:1})},[p]),X=b.useMemo(()=>[...p.nodes.map(E=>({id:E.id,label:E.label,type:"node"})),...p.edges.map(E=>({id:E.id,label:E.label??E.id,type:"edge"}))],[p.nodes,p.edges]);return n.jsx(pt,{locale:a,children:n.jsxs("div",{ref:y,className:`nice-diagram-editor ${u??""}`,style:{position:"relative",display:"flex",flexDirection:"column",height:"100%",...d},children:[n.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:n.jsx(M.NiceTutorialButton,{steps:M.resolveTutorial(g,Ri)})}),s&&n.jsx(tt,{activeTool:m,onToolChange:h,diagramType:p.document.diagramType,onAddNode:C,onApplyLayout:$,onUndo:p.undo,onRedo:p.redo,canUndo:p.canUndo,canRedo:p.canRedo,onExport:T,onZoomIn:K,onZoomOut:q,onZoomReset:H,viewMode:S,onViewModeChange:N,stylePresetId:p.stylePresetId,onStylePresetChange:j}),p.animationModes.length>0&&n.jsxs("div",{className:"nice-diagram-editor__mode-tabs",style:{display:"flex",gap:4,padding:"4px 8px",borderBottom:"1px solid var(--nice-border, #e0e0e0)",background:"var(--nice-bg-secondary, #f9f9f9)",fontSize:12,alignItems:"center"},children:[n.jsx("span",{style:{color:"var(--nice-text-secondary, #888)",marginRight:4},children:"Modes:"}),p.animationModes.map(E=>{var Z;return n.jsx(M.NiceButton,{variant:((Z=p.activeAnimationMode)==null?void 0:Z.id)===E.id?"primary":"ghost",size:"sm",onClick:()=>p.setActiveAnimationMode(E.id),style:{padding:"2px 10px",fontSize:11},children:E.name},E.id)}),n.jsx(M.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:"+"})]}),n.jsxs("div",{className:"nice-diagram-editor__body",style:{display:"flex",flex:1,overflow:"hidden",position:"relative"},children:[n.jsxs("div",{className:"nice-diagram-editor__canvas",style:{flex:1,position:"relative"},children:[n.jsx(ve,{nodes:p.nodes,edges:p.edges,groups:p.groups,viewport:p.viewport,onViewportChange:p.setViewport,selectedId:x,onSelectElement:v,onNodeDrag:G,onNodeDragEnd:F,interactive:S==="editor",showGrid:S==="editor",particleState:_,viewMode:S,ghostOpacity:((ne=p.playerConfig)==null?void 0:ne.ghostOpacity)??.3,onGroupCollapse:p.toggleGroupCollapse,onNodeCollapse:p.toggleNodeCollapse,onInteraction:L}),o&&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})})]}),c&&n.jsx("div",{className:"nice-diagram-editor__panel",style:{width:260,borderLeft:"1px solid var(--nice-border, #ddd)",overflowY:"auto"},children:n.jsx(et,{selectedNode:V,selectedEdge:B,onNodeChange:p.updateNode,onEdgeChange:p.updateEdge,onRemove:O})})]}),l&&n.jsx("div",{className:"nice-diagram-editor__timeline",style:{borderTop:"1px solid var(--nice-border, #ddd)"},children:n.jsx(Ze,{animations:p.animations,onAdd:p.addAnimation,onRemove:p.removeAnimation,availableTargets:X})})]})})};Wt.displayName="NiceDiagramEditor";const Mt={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 Mt[r]??Mt.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 s of this.animations){const c=s.startMs+(s.delayMs??0);c+s.durationMs;const o=s.repeat??0;let l=i-c;if(l<0){this.stateMap.set(s.targetId,Ei(s)),a=!0;continue}if(o===-1)l=l%s.durationMs,a=!0;else if(o>0){const p=s.durationMs*(o+1);if(l>p)continue;l=l%s.durationMs,a=!0}else{if(l>s.durationMs)continue;a=!0}const u=Math.min(l/s.durationMs,1),d=Bt(s.easing)(u),g=Oi(s,d);this.stateMap.set(s.targetId,g)}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 Oi(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 Ei(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:s=!1,className:c,style:o})=>{const l=i??s,u=a??s,[d,g]=b.useState({...r.viewport}),[p,m]=b.useState(new Map),[h,x]=b.useState(!1),v=b.useRef(null),y=b.useCallback(()=>{v.current&&v.current.stop();const w=new Gt(r.animations,j=>{m(new Map(j)),w.isPlaying()||x(!1)});v.current=w,w.play(),x(!0)},[r.animations]),S=b.useCallback(()=>{var w;(w=v.current)==null||w.stop(),x(!1),m(new Map)},[]);b.useEffect(()=>(t&&r.animations.length>0&&y(),()=>{var w;(w=v.current)==null||w.stop()}),[t]);const N=b.useCallback(()=>g(w=>({...w,zoom:Math.min(5,w.zoom*1.2)})),[]),I=b.useCallback(()=>g(w=>({...w,zoom:Math.max(.1,w.zoom/1.2)})),[]),_=b.useCallback(()=>g({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%",...o},children:[l&&n.jsx(Li,{isPlaying:h,hasAnimations:r.animations.length>0,onPlay:y,onStop:S,onZoomIn:N,onZoomOut:I,onZoomReset:_}),n.jsx("div",{style:{flex:1,position:"relative"},children:n.jsx(ve,{nodes:r.nodes,edges:r.edges,groups:r.groups,viewport:d,onViewportChange:g,theme:r.theme,animationStates:p,interactive:!1,showGrid:u})})]})})},Li=({isPlaying:r,hasAnimations:e,onPlay:t,onStop:i,onZoomIn:a,onZoomOut:s,onZoomReset:c})=>{const{t:o}=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(M.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:i,children:["⏹ ",o("animation.stop")]}):n.jsxs(M.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:t,children:["▶ ",o("animation.play")]})),n.jsx("span",{style:{flex:1}}),n.jsx(M.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:a,children:"🔍+"}),n.jsx(M.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:s,children:"🔍−"}),n.jsx(M.NiceButton,{className:"nice-diagram-viewer__btn",variant:"ghost",size:"sm",onClick:c,children:"1:1"})]})};yt.displayName="NiceDiagramViewer";const Fi="_cell_9ewd0_9",Wi="_expandable_9ewd0_29",Bi="_svg_9ewd0_57",qi="_emptyText_9ewd0_67",Gi="_badge_9ewd0_79",Vi="_expandIcon_9ewd0_117",Yi="_modalOverlay_9ewd0_165",Xi="_modalContent_9ewd0_213",Hi="_modalHeader_9ewd0_263",Ui="_modalTitle_9ewd0_281",Ji="_modalClose_9ewd0_295",Ki="_modalBody_9ewd0_333",Zi="_modalSvg_9ewd0_353",Qi="_modalFooter_9ewd0_367",ea="_modalInfo_9ewd0_385",xe={cell:Fi,expandable:Wi,svg:Bi,emptyText:qi,badge:Gi,expandIcon:Vi,modalOverlay:Yi,modalContent:Xi,modalHeader:Hi,modalTitle:Ui,modalClose:Ji,modalBody:Ki,modalSvg:Zi,modalFooter:Qi,modalInfo:ea},ta=120,ra=48,ia=4,Nt={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 s of r){const c=s.position.x,o=s.position.y,l=s.position.x+s.size.width,u=s.position.y+s.size.height;c<e&&(e=c),o<t&&(t=o),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 Nt[e]??Nt.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,s=t.position.y+t.size.height/2,c=i.position.x+i.size.width/2,o=i.position.y+i.size.height/2;return`M ${a} ${s} L ${c} ${o}`}function aa(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,s=t.height+i*2,c=b.useMemo(()=>new Map(r.nodes.map(o=>[o.id,o])),[r.nodes]);return n.jsx("div",{className:xe.modalOverlay,onClick:e,children:n.jsxs("div",{className:xe.modalContent,onClick:o=>o.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} ${s}`,className:xe.modalSvg,children:[r.edges.map(o=>{var u,d,g;const l=Yt(o,c);return l?n.jsx("path",{d:l,stroke:((u=o.style)==null?void 0:u.strokeColor)??"var(--nice-text-secondary, #64748b)",strokeWidth:((d=o.style)==null?void 0:d.strokeWidth)??1.5,fill:"none",markerEnd:(g=o.style)!=null&&g.targetArrow&&o.style.targetArrow!=="none"?"url(#arrowhead-modal)":void 0},o.id):null}),r.nodes.map(o=>{var l,u;return n.jsxs("g",{children:[n.jsx("rect",{x:o.position.x,y:o.position.y,width:o.size.width,height:o.size.height,rx:((l=o.style)==null?void 0:l.borderRadius)??4,fill:Vt(o),stroke:((u=o.style)==null?void 0:u.borderColor)??"var(--nice-text, #1e293b)",strokeWidth:1}),n.jsx("text",{x:o.position.x+o.size.width/2,y:o.position.y+o.size.height/2,textAnchor:"middle",dominantBaseline:"middle",fill:"var(--nice-bg, #fff)",fontSize:12,fontFamily:"system-ui, sans-serif",children:o.label.substring(0,30)})]},o.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"]})})]})})},oa=({document:r,nodes:e,edges:t,width:i=ta,height:a=ra,showCount:s=!0,expandable:c=!0,onExpand:o,padding:l=ia,backgroundColor:u="transparent",borderRadius:d=4,showLabels:g=!1,edgeColor:p="var(--nice-text-muted, #94a3b8)",tooltip:m})=>{const[h,x]=b.useState(!1),v=b.useMemo(()=>r||(e||t?aa(e??[],t??[]):null),[r,e,t]),y=b.useMemo(()=>v?new Map(v.nodes.map(j=>[j.id,j])):new Map,[v]),{bounds:S,scale:N,translateX:I,translateY:_}=b.useMemo(()=>{if(!v||v.nodes.length===0)return{bounds:{minX:0,minY:0,width:100,height:100},scale:1,translateX:0,translateY:0};const j=bt(v.nodes),L=i-l*2,R=a-l*2,V=L/j.width,B=R/j.height,C=Math.min(V,B,1),$=j.width*C,G=j.height*C,F=(i-$)/2-j.minX*C,O=(a-G)/2-j.minY*C;return{bounds:j,scale:C,translateX:F,translateY:O}},[v,i,a,l]),w=b.useCallback(()=>{!v||!c||(o?o(v):x(!0))},[v,c,o]);return!v||v.nodes.length===0?n.jsx("div",{className:xe.cell,style:{width:i,height:a,backgroundColor:u,borderRadius:d},title:m,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:w,title:m??`${v.nodes.length} nodes, ${v.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}, ${_}) scale(${N})`,children:[v.edges.map(j=>{const L=Yt(j,y);return L?n.jsx("path",{d:L,stroke:p,strokeWidth:1/N,fill:"none"},j.id):null}),v.nodes.map(j=>{const L=Vt(j);return n.jsxs("g",{children:[n.jsx("rect",{x:j.position.x,y:j.position.y,width:j.size.width,height:j.size.height,rx:Math.min(4,j.size.width/4),fill:L}),g&&N>.3&&n.jsx("text",{x:j.position.x+j.size.width/2,y:j.position.y+j.size.height/2,textAnchor:"middle",dominantBaseline:"middle",fill:"var(--nice-bg, #fff)",fontSize:10/N,fontFamily:"system-ui, sans-serif",children:j.label.substring(0,5)})]},j.id)})]})}),s&&n.jsx("span",{className:xe.badge,children:v.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&&v&&n.jsx(sa,{document:v,onClose:()=>x(!1)})]})};function Xt(r,e,t="roundedRect"){const i=[],a=[],s=new Map;for(const c of r){const o=String(c[e.nodeMapping.idField]??"");if(!o)continue;const l=String(c[e.nodeMapping.labelField]??o),u=e.nodeMapping.descriptionField?String(c[e.nodeMapping.descriptionField]??""):void 0,d=e.nodeMapping.iconField?String(c[e.nodeMapping.iconField]??""):void 0,g=e.nodeMapping.colorField?String(c[e.nodeMapping.colorField]??""):void 0,p={id:`data_${o}`,label:l,description:u,icon:d,position:{x:0,y:0},size:{width:180,height:70},shape:t,style:g?{backgroundColor:g}:{},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),s.set(o,p)}if(e.nodeMapping.parentField)for(const c of r){const o=String(c[e.nodeMapping.idField]??""),l=String(c[e.nodeMapping.parentField]??"");if(!o||!l)continue;const u=s.get(o),d=s.get(l);!u||!d||a.push({id:`edge_${l}_${o}`,sourceNodeId:d.id,sourcePortId:"bottom",targetNodeId:u.id,targetPortId:"top",style:{lineType:"orthogonal",targetArrow:"arrow"}})}if(e.edgeMapping)for(const c of r){const o=String(c[e.edgeMapping.sourceField]??""),l=String(c[e.edgeMapping.targetField]??"");if(!o||!l)continue;const u=s.get(o),d=s.get(l);if(!u||!d)continue;const g=e.edgeMapping.labelField?String(c[e.edgeMapping.labelField]??""):void 0;a.push({id:`edge_${o}_${l}`,sourceNodeId:u.id,sourcePortId:"right",targetNodeId:d.id,targetPortId:"left",label:g,style:{lineType:"bezier",targetArrow:"arrow"}})}return{nodes:i,edges:a}}async function na(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(),s=Array.isArray(a)?a:a.value??[];return Xt(s,r,e)}function ca(r){return{rectangle:"rectangle",roundedRect:"roundedRect",ellipse:"ellipse",circle:"circle",diamond:"diamond",hexagon:"hexagon",cylinder:"cylinder",cloud:"cloud",triangle:"triangle"}[r||"rectangle"]||"rectangle"}function la(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 da(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 ua(r){if(r)return{backgroundColor:r.fill,borderColor:r.stroke,borderWidth:r.strokeWidth}}function Ht(r){return{id:r.id,label:r.label,position:{x:r.x,y:r.y},size:{width:r.width,height:r.height},shape:ca(r.shape),style:la(r.style),ports:(r.ports||[]).map((e,t)=>({id:e.id,side:e.position||"right",offset:.5})),data:r.data}}function Ut(r,e){var c,o;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`,s=r.targetPort||((o=i==null?void 0:i.ports[0])==null?void 0:o.id)||`${r.target}-in`;return{id:r.id,sourceNodeId:r.source,sourcePortId:a,targetNodeId:r.target,targetPortId:s,label:r.label,style:da(r.style),data:r.data}}function Jt(r){return{id:r.id,label:r.label,nodeIds:r.nodeIds,style:ua(r.style)}}function Kt(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(Ht);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=>Ut(t,e)),groups:(r.groups||[]).map(Jt),animations:(r.animations||[]).map(Kt),viewport:{x:0,y:0,zoom:1},metadata:{createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),...r.metadata}}}const fa={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)"},ha={start:"ellipse",end:"ellipse",task:"rectangle",decision:"diamond",parallel:"rectangle",join:"rectangle",subprocess:"rectangle",timer:"ellipse",message:"rectangle",error:"rectangle"},pa={start:"▶",end:"⬛",task:"📋",decision:"❓",parallel:"⫘",join:"⫗",subprocess:"📦",timer:"⏱",message:"✉",error:"⚠"},ga=({data:r,onStepClick:e,onTransitionClick:t,autoPlay:i=!1,animationDelay:a=1e3,showTooltips:s=!0,showMinimap:c=!0,statusColors:o=fa,typeShapes:l=ha,direction:u="horizontal",className:d,style:g})=>{const[p,m]=b.useState(0),h=b.useMemo(()=>{const S=r.steps.map((_,w)=>{const j=_.id===r.currentStepId,L=_.status||"pending",R=o[L],V=l[_.type],B=u==="horizontal"?w*200:100,C=u==="horizontal"?100:w*150;return{id:_.id,label:_.name,x:B,y:C,width:150,height:60,shape:V,style:{fill:R,stroke:j?"var(--nice-text, #1f2937)":R,strokeWidth:j?3:1,fontColor:"var(--nice-bg, #fff)",fontSize:12},data:{type:_.type,status:_.status,assignee:_.assignee,dueDate:_.dueDate,icon:pa[_.type],..._.metadata},ports:[{id:`${_.id}-in`,position:"left"},{id:`${_.id}-out`,position:"right"}]}}),N=r.transitions.map(_=>{const w=r.steps.find(R=>R.id===_.from),j=r.steps.find(R=>R.id===_.to);let L="var(--nice-text-muted, #9ca3af)";return(w==null?void 0:w.status)==="completed"&&(j==null?void 0:j.status)!=="pending"?L="var(--nice-success, #10b981)":(w==null?void 0:w.status)==="failed"&&(L="var(--nice-danger, #ef4444)"),{id:_.id,source:_.from,target:_.to,sourcePort:`${_.from}-out`,targetPort:`${_.to}-in`,label:_.label||_.condition,style:{stroke:L,strokeWidth:2,arrowHead:"arrow",lineType:"bezier"},data:{condition:_.condition}}}),I=i?ma(r.steps):[];return Ae({id:r.id,title:r.name,diagramType:"flowchart",nodes:S,edges:N,animations:I,metadata:{type:"workflow",...r.metadata}})},[r,o,l,u,i]);b.useEffect(()=>{if(!i)return;const S=r.steps.filter(I=>I.status==="completed").length;if(p>=S)return;const N=setTimeout(()=>{m(I=>I+1)},a);return()=>clearTimeout(N)},[i,p,a,r.steps]),b.useCallback(S=>{if(!e)return;const N=r.steps.find(I=>I.id===S);N&&e(N)},[r.steps,e]);const[x,v]=b.useState({x:0,y:0,zoom:1}),y=b.useCallback(S=>{if(S&&e){const N=r.steps.find(I=>I.id===S);N&&e(N)}if(S&&t){const N=r.transitions.find(I=>I.id===S);N&&t(N)}},[r.steps,r.transitions,e,t]);return n.jsx("div",{className:`nice-workflow-visualizer ${d||""}`,style:{position:"relative",width:"100%",height:"100%",...g},children:n.jsx(ve,{nodes:h.nodes,edges:h.edges,groups:h.groups,viewport:x,onViewportChange:v,onSelectElement:y,showGrid:!0})})};function ma(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 ya(r){var s,c;const t=new DOMParser().parseFromString(r,"text/xml"),i=[],a=[];return t.querySelectorAll("startEvent").forEach(o=>{i.push({id:o.getAttribute("id")||`start-${i.length}`,name:o.getAttribute("name")||"Start",type:"start"})}),t.querySelectorAll("task, userTask, serviceTask").forEach(o=>{i.push({id:o.getAttribute("id")||`task-${i.length}`,name:o.getAttribute("name")||"Task",type:"task"})}),t.querySelectorAll("exclusiveGateway, parallelGateway").forEach(o=>{const l=o.tagName==="parallelGateway";i.push({id:o.getAttribute("id")||`gateway-${i.length}`,name:o.getAttribute("name")||(l?"Parallel":"Decision"),type:l?"parallel":"decision"})}),t.querySelectorAll("endEvent").forEach(o=>{i.push({id:o.getAttribute("id")||`end-${i.length}`,name:o.getAttribute("name")||"End",type:"end"})}),t.querySelectorAll("sequenceFlow").forEach(o=>{a.push({id:o.getAttribute("id")||`flow-${a.length}`,from:o.getAttribute("sourceRef")||"",to:o.getAttribute("targetRef")||"",label:o.getAttribute("name")||void 0})}),{id:((s=t.querySelector("process"))==null?void 0:s.getAttribute("id"))||"workflow",name:((c=t.querySelector("process"))==null?void 0:c.getAttribute("name"))||"Workflow",steps:i,transitions:a}}function ba(r,e){const t=[],i=[];t.push({id:"start",name:"Start",type:"start",status:"completed"}),r.forEach((a,s)=>{t.push({id:`step-${s}`,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 xa={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)"},va={"one-to-one":{left:"1",right:"1"},"one-to-many":{left:"1",right:"*"},"many-to-one":{left:"*",right:"1"},"many-to-many":{left:"*",right:"*"}},wa=({schema:r,onTableClick:e,onColumnClick:t,onRelationClick:i,showColumnDetails:a=!0,showOnlyKeys:s=!1,highlightTables:c=[],showMinimap:o=!0,schemaColors:l=xa,layout:u="auto",maxColumnsDisplay:d=15,className:g,style:p})=>{const[m,h]=b.useState(null),x=b.useMemo(()=>{const N=ka(r.tables,u),I=r.tables.map((w,j)=>{const L=N[w.name]||{x:j%4*300,y:Math.floor(j/4)*400},R=c.includes(w.name),V=m===w.name,B=l[w.schema||"dbo"]||"var(--nice-text-secondary, #6b7280)";let C=w.columns;s&&(C=C.filter(O=>O.primaryKey||O.foreignKey)),C.length>d&&(C=C.slice(0,d));const $=40,G=a?28:20,F=$+C.length*G+10;return{id:w.name,label:w.schema?`${w.schema}.${w.name}`:w.name,x:L.x,y:L.y,width:250,height:F,shape:"rectangle",style:{fill:R||V?B:"var(--nice-bg, #fff)",stroke:B,strokeWidth:V?3:R?2:1,fontColor:R||V?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:14,borderRadius:8},data:{type:"table",schema:w.schema,columns:C.map(O=>({...O,icon:_a(O)})),totalColumns:w.columns.length,truncated:w.columns.length>d,comment:w.comment,...w.metadata},ports:[...w.columns.filter(O=>O.primaryKey).map(O=>({id:`${w.name}.${O.name}-pk`,position:"left"})),...w.columns.filter(O=>O.foreignKey).map(O=>({id:`${w.name}.${O.name}-fk`,position:"right"}))]}}),_=r.relations.map(w=>{const j=va[w.type];return{id:w.id,source:w.fromTable,target:w.toTable,sourcePort:`${w.fromTable}.${w.fromColumn}-fk`,targetPort:`${w.toTable}.${w.toColumn}-pk`,label:w.name||`${j.left}─${j.right}`,style:{stroke:"var(--nice-text-secondary, #6b7280)",strokeWidth:1.5,arrowHead:Ca(w.type),arrowTail:Ma(w.type),lineType:"orthogonal",strokeDasharray:w.type==="many-to-many"?"5,5":void 0},data:{type:w.type,fromColumn:w.fromColumn,toColumn:w.toColumn}}});return Ae({id:`schema-${r.name}`,title:r.name,diagramType:"er",nodes:I,edges:_,metadata:{type:"er-diagram",...r.metadata}})},[r,a,s,c,m,l,u,d]);b.useCallback(N=>{if(h(I=>I===N?null:N),e){const I=r.tables.find(_=>_.name===N);I&&e(I)}},[r.tables,e]),b.useCallback(N=>{if(!i)return;const I=r.relations.find(_=>_.id===N);I&&i(I)},[r.relations,i]);const[v,y]=b.useState({x:0,y:0,zoom:1}),S=b.useCallback(N=>{if(N){if(h(I=>I===N?null:N),e){const I=r.tables.find(_=>_.name===N);I&&e(I)}if(i){const I=r.relations.find(_=>_.id===N);I&&i(I)}}},[r.tables,r.relations,e,i]);return n.jsx("div",{className:`nice-database-schema-viewer ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...p},children:n.jsx(ve,{nodes:x.nodes,edges:x.edges,groups:x.groups,viewport:v,onViewportChange:y,onSelectElement:S,showGrid:!0})})};function ka(r,e){const t={};if(e==="grid"){const i=Math.ceil(Math.sqrt(r.length));r.forEach((a,s)=>{t[a.name]={x:s%i*320+50,y:Math.floor(s/i)*450+50}})}else if(e==="hierarchical"){const i={};r.forEach(s=>{const c=s.schema||"default";i[c]||(i[c]=[]),i[c].push(s)});let a=50;Object.entries(i).forEach(([s,c])=>{c.forEach((o,l)=>{t[o.name]={x:l*320+50,y:a}}),a+=500})}else r.forEach((i,a)=>{const s=a/r.length*2*Math.PI,c=300+r.length*20;t[i.name]={x:Math.cos(s)*c+500,y:Math.sin(s)*c+400}});return t}function _a(r){return r.primaryKey?"🔑":r.foreignKey?"🔗":r.unique?"⚡":"📄"}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 Na(r){const e=[],t=[],i=/CREATE\s+TABLE\s+(?:`?(\w+)`?\.)?`?(\w+)`?\s*\(([\s\S]*?)\);/gi;let a;for(;(a=i.exec(r))!==null;){const s=a[1]||"dbo",c=a[2],o=a[3],l=[],u=/`?(\w+)`?\s+(\w+(?:\([^)]+\))?)\s*(NOT\s+NULL|NULL)?/gi;let d;for(;(d=u.exec(o))!==null;)l.push({name:d[1],type:d[2],nullable:!d[3]||d[3].toUpperCase()!=="NOT NULL"});const g=/PRIMARY\s+KEY\s*\(`?(\w+)`?\)/i.exec(o);if(g){const h=l.find(x=>x.name===g[1]);h&&(h.primaryKey=!0)}const p=/FOREIGN\s+KEY\s*\(`?(\w+)`?\)\s*REFERENCES\s+`?(\w+)`?\s*\(`?(\w+)`?\)/gi;let m;for(;(m=p.exec(o))!==null;){const h=m,x=l.find(v=>v.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:s,columns:l})}return{name:"Parsed Schema",tables:e,relations:t}}function Sa(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 s=i.columns.map(o=>{let l=` ${o.name} ${o.type}`;return o.nullable||(l+=" NOT NULL"),o.primaryKey&&(l+=" PRIMARY KEY"),o.unique&&(l+=" UNIQUE"),o.defaultValue&&(l+=` DEFAULT ${o.defaultValue}`),l}),c=i.columns.filter(o=>o.foreignKey).map(o=>` FOREIGN KEY (${o.name}) REFERENCES ${o.foreignKey.table}(${o.foreignKey.column})`);t.push([...s,...c].join(`,
|
|
4
4
|
`)),t.push(`);
|
|
5
5
|
`)}return t.join(`
|
|
6
|
-
`)}const Sa={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)"},He=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"],Ia=({data:r,rootEmployeeId:e,onEmployeeClick:t,onDepartmentClick:i,showAvatars:a=!0,showContactInfo:s=!1,groupByDepartment:c=!0,collapsedDepartments:o=[],maxLevels:l=0,orientation:f="vertical",spacing:d={horizontal:200,vertical:150},statusColors:u=Sa,showMinimap:x=!0,className:g,style:h})=>{const[b,v]=y.useState(new Set),[m,S]=y.useState(null),_=y.useMemo(()=>{var Y;if(e)return e;const O=r.employees.find(R=>!R.managerId);return(O==null?void 0:O.id)||((Y=r.employees[0])==null?void 0:Y.id)},[r.employees,e]),I=y.useMemo(()=>ja(r.employees,_),[r.employees,_]),C=y.useMemo(()=>{const O=Aa(I,f,d,l),Y=[],R={};c&&r.departments&&r.departments.forEach((V,T)=>{const E=V.color||He[T%He.length];R[V.id]=E;const X=r.employees.filter(B=>B.department===V.id);X.length!==0&&Y.push({id:`dept-${V.id}`,label:V.name,nodeIds:X.map(B=>B.id),style:{fill:`${E}15`,stroke:E,strokeWidth:2},data:{department:V}})});const M=[],z=[],q=(V,T=0)=>{if(l>0&&T>=l||V.employee.department&&o.includes(V.employee.department))return;const E=O[V.employee.id]||{x:0,y:0},X=m===V.employee.id,B=V.employee.status||"active",K=V.employee.department?R[V.employee.department]:"var(--nice-text-secondary, #6b7280)",Z=180,L=s?120:a?90:70;M.push({id:V.employee.id,label:V.employee.name,x:E.x,y:E.y,width:Z,height:L,shape:"rectangle",style:{fill:X?K:"var(--nice-bg, #fff)",stroke:K,strokeWidth:X?3:1,fontColor:X?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:13,borderRadius:12},data:{type:"employee",employee:V.employee,statusColor:u[B],hasChildren:V.children.length>0,childrenCount:V.children.length}}),V.employee.managerId&&z.push({id:`rel-${V.employee.managerId}-${V.employee.id}`,source:V.employee.managerId,target:V.employee.id,style:{stroke:"var(--nice-border, #cbd5e1)",strokeWidth:2,arrowHead:"none",lineType:f==="vertical"?"orthogonal":"curved"}}),V.children.forEach(G=>q(G,T+1))};return I&&q(I),Ae({id:"org-chart",title:"Organization Chart",diagramType:"orgchart",nodes:M,edges:z,groups:Y,metadata:{type:"org-chart",...r.metadata}})},[r,I,f,d,l,c,o,a,s,u,m]);y.useCallback(O=>{if(S(Y=>Y===O?null:O),v(Y=>{const R=new Set(Y);return R.has(O)?R.delete(O):R.add(O),R}),t){const Y=r.employees.find(R=>R.id===O);Y&&t(Y)}},[r.employees,t]),y.useCallback(O=>{if(!i||!r.departments)return;const Y=O.replace("dept-",""),R=r.departments.find(M=>M.id===Y);R&&i(R)},[r.departments,i]);const[w,j]=y.useState({x:0,y:0,zoom:1}),F=y.useCallback(O=>{if(O&&(S(Y=>Y===O?null:O),t)){const Y=r.employees.find(R=>R.id===O);Y&&t(Y)}},[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:C.nodes,edges:C.edges,groups:C.groups,viewport:w,onViewportChange:j,onSelectElement:F,showGrid:!1})})};function ja(r,e){const i=new Map(r.map(s=>[s.id,s])).get(e);if(!i)return null;const a=(s,c)=>{const o=r.filter(l=>l.managerId===s.id);return{employee:s,children:o.map(l=>a(l,c+1)),level:c}};return a(i,0)}function Aa(r,e,t,i){const a={};if(!r)return a;const s=(l,f)=>i>0&&f>=i?0:l.children.length===0?1:l.children.reduce((d,u)=>d+s(u,f+1),0),c=(l,f,d,u)=>{if(i>0&&f>=i)return;const x=d+u*t.horizontal/2,g=f*t.vertical+50;a[l.employee.id]=e==="vertical"?{x,y:g}:{x:g,y:x};let h=d;l.children.forEach(b=>{const v=s(b,f+1);c(b,f+1,h,v),h+=v*t.horizontal})},o=s(r,0);return c(r,0,0,o),a}function $a(r){const t=[...new Set(r.map(i=>i.department).filter(Boolean))].map((i,a)=>({id:i,name:i,color:He[a%He.length],headcount:r.filter(s=>s.department===i).length}));return{employees:r,departments:t}}function za(r){var o;const e=new Set(r.employees.map(l=>l.managerId).filter(Boolean)),t=(l,f=new Set)=>{if(f.has(l))return 0;f.add(l);const d=r.employees.find(u=>u.id===l);return d!=null&&d.managerId?1+t(d.managerId,f):1},i=r.employees.map(l=>t(l.id)),a=Math.max(...i,0),s=Array.from(e).map(l=>r.employees.filter(f=>f.managerId===l).length),c=s.length>0?s.reduce((l,f)=>l+f,0)/s.length:0;return{totalEmployees:r.employees.length,departmentCount:((o=r.departments)==null?void 0:o.length)||0,maxDepth:a,averageSpan:Math.round(c*10)/10,managers:e.size}}const Da=({data:r,onActivityClick:e,onTransitionClick:t,minEdgeFrequency:i=.05,showFrequency:a=!0,showDuration:s=!0,highlightBottlenecks:c=!0,bottleneckThreshold:o=.9,colorScheme:l="frequency",activityColors:f,layout:d="hierarchical",animationSpeed:u=0,showMinimap:x=!0,className:g,style:h})=>{const[b,v]=y.useState(null),m=y.useMemo(()=>"activities"in r?r:Kt(r),[r]),S=y.useMemo(()=>{if(!c)return new Set;const j=m.activities.filter(O=>O.avgDuration!==void 0).map(O=>O.avgDuration);if(j.length===0)return new Set;j.sort((O,Y)=>O-Y);const F=j[Math.floor(j.length*o)]||0;return new Set(m.activities.filter(O=>(O.avgDuration||0)>=F).map(O=>O.name))},[m.activities,c,o]),_=y.useMemo(()=>{const j=Math.max(...m.activities.map(z=>z.frequency),1),F=Ta(m,d),O=m.transitions.filter(z=>z.frequency/m.totalCases>=i),Y=m.activities.map(z=>{const q=F[z.name]||{x:0,y:0},V=m.startActivities.includes(z.name),T=m.endActivities.includes(z.name),E=S.has(z.name),X=b===z.name,B=Ra(z,l,j,f,E);return{id:z.name,label:z.name,x:q.x,y:q.y,width:140,height:60,shape:V?"ellipse":T?"roundedRect":"rectangle",style:{fill:X?B:"var(--nice-bg, #fff)",stroke:B,strokeWidth:E?4:X?3:2,fontColor:X?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:12,borderRadius:T?20:8},data:{type:"activity",activity:z,isStart:V,isEnd:T,isBottleneck:E,frequencyPercent:Math.round(z.frequency/m.totalCases*100)}}}),R=O.map((z,q)=>{const V=z.probability||z.frequency/m.totalCases,T=V>.5,E=[];return a&&E.push(`${z.frequency}x`),s&&z.avgDuration&&E.push(Oa(z.avgDuration)),{id:`trans-${q}`,source:z.from,target:z.to,label:E.join(" | "),style:{stroke:T?"var(--nice-primary, #3b82f6)":"var(--nice-text-muted, #9ca3af)",strokeWidth:Math.max(1,Math.min(6,V*8)),arrowHead:"triangle",lineType:"curved",opacity:Math.max(.3,V)},data:{type:"transition",transition:z,probability:V}}}),M=u>0?Ea(m,u):[];return Ae({id:"process-mining",title:"Process Mining Diagram",diagramType:"flowchart",nodes:Y,edges:R,animations:M,metadata:{type:"process-mining",totalCases:m.totalCases,avgCaseDuration:m.avgCaseDuration}})},[m,i,a,s,c,S,l,f,d,u,b]);y.useCallback(j=>{if(v(F=>F===j?null:j),e){const F=m.activities.find(O=>O.name===j);F&&e(F)}},[m.activities,e]),y.useCallback(j=>{if(!t)return;const F=parseInt(j.replace("trans-",""),10),O=m.transitions[F];O&&t(O)},[m.transitions,t]);const[I,C]=y.useState({x:0,y:0,zoom:1}),w=y.useCallback(j=>{if(j&&(v(F=>F===j?null:j),e)){const F=m.activities.find(O=>O.name===j);F&&e(F)}},[m.activities,e]);return n.jsx("div",{className:`nice-process-mining-diagram ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:n.jsx(ve,{nodes:_.nodes,edges:_.edges,groups:_.groups,viewport:I,onViewportChange:C,onSelectElement:w,showGrid:!0})})};function Ta(r,e){const t={};if(e==="circular"){const i=r.activities;i.forEach((a,s)=>{const c=s/i.length*2*Math.PI-Math.PI/2,o=200+i.length*15;t[a.name]={x:Math.cos(c)*o+400,y:Math.sin(c)*o+300}})}else{const i=Pa(r),a={};r.activities.forEach(c=>{const o=i[c.name]||0;a[o]=(a[o]||0)+1});const s={};r.activities.forEach(c=>{const o=i[c.name]||0,l=s[o]||0;s[o]=l+1;const f=a[o],d=(l-(f-1)/2)*180;t[c.name]={x:400+d,y:50+o*120}})}return t}function Pa(r){const e={},t=new Set,i=r.startActivities.map(a=>({activity:a,level:0}));for(;i.length>0;){const{activity:a,level:s}=i.shift();if(t.has(a))continue;t.add(a),e[a]=s,r.transitions.filter(o=>o.from===a).forEach(o=>{t.has(o.to)||i.push({activity:o.to,level:s+1})})}return r.activities.forEach(a=>{e[a.name]===void 0&&(e[a.name]=0)}),e}function Ra(r,e,t,i,a){if(a)return"var(--nice-danger, #ef4444)";if(i!=null&&i[r.name])return i[r.name];const s=r.frequency/t;switch(e){case"frequency":return ut("var(--nice-success, #10b981)","var(--nice-primary, #3b82f6)",s);case"duration":return r.avgDuration?ut("var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)",s):"var(--nice-text-secondary, #6b7280)";case"cost":return r.avgCost?ut("var(--nice-success, #10b981)","var(--nice-danger, #ef4444)",s):"var(--nice-text-secondary, #6b7280)";default:return"var(--nice-primary, #3b82f6)"}}function ut(r,e,t){const i=f=>{const d=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(f);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),s=i(e),c=Math.round(a.r+(s.r-a.r)*t),o=Math.round(a.g+(s.g-a.g)*t),l=Math.round(a.b+(s.b-a.b)*t);return`#${[c,o,l].map(f=>f.toString(16).padStart(2,"0")).join("")}`}function Oa(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 Ea(r,e){var i;const t=(i=r.variants)==null?void 0:i[0];return t?t.activities.map((a,s)=>({id:`flow-${s}`,type:"highlight",targets:[a],duration:e,delay:s*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,b)=>h.timestamp.getTime()-b.timestamp.getTime())});const i=new Map,a=new Map,s=new Set,c=new Set;t.forEach(g=>{if(g.length!==0){s.add(g[0].activity),c.add(g[g.length-1].activity);for(let h=0;h<g.length;h++){const b=g[h];i.has(b.activity)||i.set(b.activity,{frequency:0,durations:[],resources:new Set,costs:[]});const v=i.get(b.activity);if(v.frequency++,b.resource&&v.resources.add(b.resource),b.cost!==void 0&&v.costs.push(b.cost),h<g.length-1){const m=g[h+1],S=m.timestamp.getTime()-b.timestamp.getTime();v.durations.push(S);const _=`${b.activity}→${m.activity}`;a.has(_)||a.set(_,{frequency:0,durations:[]});const I=a.get(_);I.frequency++,I.durations.push(S)}}}});const o=Array.from(i.entries()).map(([g,h])=>({name:g,frequency:h.frequency,avgDuration:h.durations.length>0?h.durations.reduce((b,v)=>b+v,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((b,v)=>b+v,0)/h.costs.length:void 0})),l=Array.from(a.entries()).map(([g,h])=>{const[b,v]=g.split("→");return{from:b,to:v,frequency:h.frequency,avgDuration:h.durations.length>0?h.durations.reduce((m,S)=>m+S,0)/h.durations.length:void 0,probability:h.frequency/t.size}}),f=new Map;t.forEach((g,h)=>{const b=g.map(m=>m.activity).join("→");f.has(b)||f.set(b,{caseIds:[],durations:[]});const v=f.get(b);if(v.caseIds.push(h),g.length>=2){const m=g[g.length-1].timestamp.getTime()-g[0].timestamp.getTime();v.durations.push(m)}});const d=Array.from(f.entries()).map(([g,h])=>({activities:g.split("→"),frequency:h.caseIds.length,avgDuration:h.durations.length>0?h.durations.reduce((b,v)=>b+v,0)/h.durations.length:0,caseIds:h.caseIds})).sort((g,h)=>h.frequency-g.frequency),u=Array.from(t.values()).filter(g=>g.length>=2).map(g=>g[g.length-1].timestamp.getTime()-g[0].timestamp.getTime()),x=u.length>0?u.reduce((g,h)=>g+h,0)/u.length:void 0;return{activities:o,transitions:l,variants:d,startActivities:Array.from(s),endActivities:Array.from(c),totalCases:t.size,avgCaseDuration:x}}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-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-accent-pink, #ec4899)",dash:"2,2"},circular:{color:"var(--nice-danger, #ef4444)"}},La={module:"📦",package:"📁",microservice:"🔲",library:"📚",api:"🔌",database:"🗄️",external:"🌐",deprecated:"⚠️"},Fa=({data:r,onNodeClick:e,onEdgeClick:t,visibleTypes:i,visibleEdgeTypes:a,highlightCircular:s=!0,showOnlyIssues:c=!1,layout:o="force",groupBy:l="type",nodeSizeBy:f="dependencies",colorScheme:d="type",nodeColors:u,showMetrics:x=!0,interactive:g=!0,showMinimap:h=!0,className:b,style:v})=>{const[m,S]=y.useState(null),[_,I]=y.useState(null),C=y.useMemo(()=>s?tr(r):new Set,[r,s]),w=y.useMemo(()=>{let M=r.nodes;return i&&i.length>0&&(M=M.filter(z=>i.includes(z.type))),c&&(M=M.filter(z=>{var q;return z.status==="critical"||z.status==="warning"||((q=z.metrics)==null?void 0:q.issues)&&z.metrics.issues>0})),M},[r.nodes,i,c]),j=y.useMemo(()=>{const M=new Set(w.map(q=>q.id));let z=r.edges.filter(q=>M.has(q.source)&&M.has(q.target));return a&&a.length>0&&(z=z.filter(q=>a.includes(q.type))),z},[r.edges,w,a]),F=y.useMemo(()=>{const M=Wa(w,j,o),z=qa(w,f),q=[];if(l!=="none"){const E=new Map;w.forEach(B=>{const K=l==="type"?B.type:B.group||"ungrouped";E.has(K)||E.set(K,[]),E.get(K).push(B.id)});let X=0;E.forEach((B,K)=>{var L,G;const Z=l==="type"?Qt[K]||"var(--nice-text-secondary, #6b7280)":((G=(L=r.groups)==null?void 0:L.find(le=>le.id===K))==null?void 0:G.color)||Ue[X%Ue.length];q.push({id:`group-${K}`,label:K,nodeIds:B,style:{fill:`${Z}10`,stroke:Z,strokeWidth:1}}),X++})}const V=w.map(E=>{const X=M[E.id]||{x:0,y:0},B=m===E.id,K=_===E.id,Z=C.has(E.id),L=Ga(E,f,z),G=Va(E,d,u,Z);return{id:E.id,label:E.name,x:X.x,y:X.y,width:L.width,height:L.height,shape:Ya(E.type),style:{fill:B||K?G:"var(--nice-bg, #fff)",stroke:G,strokeWidth:Z?4:B?3:2,fontColor:B||K?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:8,strokeDasharray:E.status==="deprecated"?"4,4":void 0},data:{type:"dependency",node:E,icon:La[E.type],isCircular:Z,statusColor:er[E.status||"unknown"]}}}),T=j.map((E,X)=>{const B=E.type==="circular"||C.has(E.source)&&C.has(E.target),K=St[E.type]||St.import;return{id:E.id||`edge-${X}`,source:E.source,target:E.target,label:E.optional?"(optional)":void 0,style:{stroke:B?"var(--nice-danger, #ef4444)":K.color,strokeWidth:Math.max(1,Math.min(4,E.weight||1)),strokeDasharray:K.dash,arrowHead:"triangle",lineType:"curved",opacity:E.optional?.5:1},data:{type:E.type,edge:E,isCircular:B}}});return Ae({id:"dependency-graph",title:"Dependency Graph",diagramType:"custom",nodes:V,edges:T,groups:q,metadata:{type:"dependency-graph",...r.metadata}})},[w,j,o,l,r.groups,f,d,u,C,m,_]);y.useCallback(M=>{if(S(z=>z===M?null:M),e){const z=r.nodes.find(q=>q.id===M);z&&e(z)}},[r.nodes,e]),y.useCallback(M=>{if(!t)return;const z=r.edges.find(q=>q.id===M);z&&t(z)},[r.edges,t]),y.useCallback(M=>{I(M)},[]);const[O,Y]=y.useState({x:0,y:0,zoom:1}),R=y.useCallback(M=>{if(M){if(S(z=>z===M?null:M),e){const z=r.nodes.find(q=>q.id===M);z&&e(z)}if(t){const z=r.edges.find(q=>q.id===M);z&&t(z)}}},[r.nodes,r.edges,e,t]);return n.jsx("div",{className:`nice-dependency-graph ${b||""}`,style:{position:"relative",width:"100%",height:"100%",...v},children:n.jsx(ve,{nodes:F.nodes,edges:F.edges,groups:F.groups,viewport:O,onViewportChange:Y,onSelectElement:R,interactive:g,showGrid:!0})})},Ue=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-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 o;(o=t.get(c.source))==null||o.push(c.target)});const i=new Set,a=new Set,s=(c,o)=>{i.add(c),a.add(c),o.push(c);const l=t.get(c)||[];for(const f of l)if(i.has(f)){if(a.has(f)){const d=o.indexOf(f);o.slice(d).forEach(x=>e.add(x))}}else if(s(f,[...o]))return!0;return a.delete(c),!1};return r.nodes.forEach(c=>{i.has(c.id)||s(c.id,[])}),e}function Wa(r,e,t){const i={};switch(t){case"circular":{r.forEach((a,s)=>{const c=s/r.length*2*Math.PI-Math.PI/2,o=150+r.length*12;i[a.id]={x:Math.cos(c)*o+400,y:Math.sin(c)*o+300}});break}case"grid":{const a=Math.ceil(Math.sqrt(r.length));r.forEach((s,c)=>{i[s.id]={x:c%a*200+100,y:Math.floor(c/a)*150+100}});break}case"hierarchical":{const a=Ba(r,e),s={},c={};r.forEach(o=>{const l=a[o.id]||0;s[l]=(s[l]||0)+1}),r.forEach(o=>{const l=a[o.id]||0,f=c[l]||0;c[l]=f+1;const d=s[l],u=(f-(d-1)/2)*200;i[o.id]={x:400+u,y:80+l*130}});break}default:{r.forEach((a,s)=>{const c=s/r.length*2*Math.PI,o=200+r.length*10;i[a.id]={x:Math.cos(c)*o+400,y:Math.sin(c)*o+300}});for(let a=0;a<50;a++){const s={};r.forEach(c=>s[c.id]={x:0,y:0});for(let c=0;c<r.length;c++)for(let o=c+1;o<r.length;o++){const l=r[c].id,f=r[o].id,d=i[f].x-i[l].x,u=i[f].y-i[l].y,x=Math.max(1,Math.sqrt(d*d+u*u)),g=5e3/(x*x);s[l].x-=d/x*g,s[l].y-=u/x*g,s[f].x+=d/x*g,s[f].y+=u/x*g}e.forEach(c=>{const o=i[c.target].x-i[c.source].x,l=i[c.target].y-i[c.source].y,f=Math.sqrt(o*o+l*l),d=f*.01;s[c.source].x+=o/f*d,s[c.source].y+=l/f*d,s[c.target].x-=o/f*d,s[c.target].y-=l/f*d}),r.forEach(c=>{i[c.id].x+=Math.max(-10,Math.min(10,s[c.id].x)),i[c.id].y+=Math.max(-10,Math.min(10,s[c.id].y))})}break}}return i}function Ba(r,e){const t={},i={};r.forEach(s=>{t[s.id]=0,i[s.id]=0}),e.forEach(s=>{i[s.target]=(i[s.target]||0)+1});const a=r.filter(s=>i[s.id]===0).map(s=>s.id);for(;a.length>0;){const s=a.shift();e.filter(o=>o.source===s).forEach(o=>{t[o.target]=Math.max(t[o.target],t[s]+1),i[o.target]--,i[o.target]===0&&a.push(o.target)})}return t}function qa(r,e){const t=r.map(i=>{var a,s,c;switch(e){case"dependencies":return((a=i.metrics)==null?void 0:a.dependencies)||0;case"dependents":return((s=i.metrics)==null?void 0:s.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 Ga(r,e,t){var l,f,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=((f=r.metrics)==null?void 0:f.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,s=100,o=s+a*(180-s);return{width:o,height:o*.5}}function Va(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 Ue[Xa(r.group||"")%Ue.length];default:return Qt[r.type]||"var(--nice-text-secondary, #6b7280)"}}function Ya(r){switch(r){case"database":return"cylinder";case"microservice":return"hexagon";case"api":return"diamond";case"external":return"cloud";default:return"rectangle"}}function Xa(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 Ha(r){const e=[{id:r.name,name:r.name,version:r.version,type:"package",status:"healthy"}],t=[];let i=0;const a=(s,c)=>{s&&Object.entries(s).forEach(([o,l])=>{e.find(f=>f.id===o)||e.push({id:o,name:o,version:l.replace(/[\^~>=<]/g,""),type:"library",status:"unknown"}),t.push({id:`edge-${i++}`,source:r.name,target:o,type:c})})};return a(r.dependencies,"runtime"),a(r.devDependencies,"dev"),a(r.peerDependencies,"peer"),e.forEach(s=>{s.metrics={dependencies:t.filter(c=>c.source===s.id).length,dependents:t.filter(c=>c.target===s.id).length}}),{nodes:e,edges:t}}function Ua(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 u=e.get(d.id)||0;u>a&&(a=u,i=d)});let s=null,c=0;r.nodes.forEach(d=>{const u=t.get(d.id)||0;u>c&&(c=u,s=d)});const o=r.nodes.filter(d=>(e.get(d.id)||0)===0&&(t.get(d.id)||0)===0),l=Array.from(t.values()).reduce((d,u)=>d+u,0),f=r.nodes.length>0?l/r.nodes.length:0;return{totalNodes:r.nodes.length,totalEdges:r.edges.length,circularDependencies:[],mostDependent:i,mostDependencies:s,orphanNodes:o,avgDependencies:Math.round(f*10)/10}}const Ja={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)"},Za={router:"🔀",switch:"🔌",firewall:"🛡️",server:"🖥️",workstation:"💻",laptop:"💻",phone:"📱",printer:"🖨️",camera:"📷",iot:"📡",loadbalancer:"⚖️",storage:"💾",cloud:"☁️",internet:"🌐",unknown:"❓"},Ka={ethernet:"var(--nice-primary, #3b82f6)",fiber:"var(--nice-success, #10b981)",wireless:"var(--nice-accent, #8b5cf6)",vpn:"var(--nice-warning, #f59e0b)",wan:"var(--nice-accent-pink, #ec4899)",trunk:"var(--nice-info, #14b8a6)"},Qa=({data:r,onDeviceClick:e,onConnectionClick:t,onRefresh:i,autoRefreshInterval:a=0,visibleDeviceTypes:s,showOnlyIssues:c=!1,layout:o="hierarchical",groupBy:l="group",showMetrics:f=!0,showBandwidth:d=!0,showLatency:u=!1,animateTraffic:x=!1,statusColors:g=Ja,showMinimap:h=!0,className:b,style:v})=>{const[m,S]=y.useState(null),[_,I]=y.useState(new Date);y.useEffect(()=>{if(a<=0||!i)return;const R=setInterval(()=>{i(),I(new Date)},a);return()=>clearInterval(R)},[a,i]);const C=y.useMemo(()=>{let R=r.devices;return s&&s.length>0&&(R=R.filter(M=>s.includes(M.type))),c&&(R=R.filter(M=>M.status==="critical"||M.status==="warning"||M.status==="offline")),R},[r.devices,s,c]),w=y.useMemo(()=>{const R=new Set(C.map(M=>M.id));return r.connections.filter(M=>R.has(M.source)&&R.has(M.target))},[r.connections,C]),j=y.useMemo(()=>{const R=es(C,w,o,r.groups),M=[];if(l!=="none"){const T=new Map;C.forEach(X=>{let B;switch(l){case"type":B=X.type;break;case"location":B=X.location||"Unknown Location";break;default:B=X.group||"ungrouped"}T.has(B)||T.set(B,[]),T.get(B).push(X.id)});let E=0;T.forEach((X,B)=>{var L;const K=(L=r.groups)==null?void 0:L.find(G=>G.id===B||G.name===B),Z=(K==null?void 0:K.color)||It[E%It.length];M.push({id:`group-${B}`,label:(K==null?void 0:K.name)||B,nodeIds:X,style:{fill:`${Z}15`,stroke:Z,strokeWidth:2}}),E++})}const z=C.map(T=>{const E=R[T.id]||{x:0,y:0},X=m===T.id,B=g[T.status],K=Za[T.type];return{id:T.id,label:T.name,x:E.x,y:E.y,width:120,height:f?90:70,shape:ts(T.type),style:{fill:X?B:"var(--nice-bg, #fff)",stroke:B,strokeWidth:X?3:2,fontColor:X?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:8},data:{type:"network-device",device:T,icon:K,statusColor:B}}}),q=w.map((T,E)=>{const X=Ka[T.type]||"var(--nice-text-secondary, #6b7280)",B=T.status==="active",K=T.status==="degraded"||T.status==="error",Z=[];if(d&&T.bandwidth){const L=Math.round(T.bandwidth.used/T.bandwidth.total*100);Z.push(`${L}%`)}return u&&T.latency!==void 0&&Z.push(`${T.latency}ms`),{id:T.id||`conn-${E}`,source:T.source,target:T.target,sourcePort:T.sourcePort,targetPort:T.targetPort,label:Z.join(" | ")||void 0,style:{stroke:K?"var(--nice-danger, #ef4444)":X,strokeWidth:Math.max(1,Math.min(6,(T.speed||1e3)/1e3)),strokeDasharray:B?void 0:"5,5",arrowHead:"none",lineType:T.type==="wireless"?"curved":"orthogonal",opacity:T.status==="inactive"?.3:1},data:{type:T.type,connection:T,isActive:B,isDegraded:K}}}),V=x?rs(w):[];return Ae({id:"network-topology",title:"Network Topology",diagramType:"networkTopology",nodes:z,edges:q,groups:M,animations:V,metadata:{type:"network-topology",lastRefresh:_.toISOString(),...r.metadata}})},[C,w,o,l,r.groups,f,d,u,x,g,m,_]);y.useCallback(R=>{if(S(M=>M===R?null:R),e){const M=r.devices.find(z=>z.id===R);M&&e(M)}},[r.devices,e]),y.useCallback(R=>{if(!t)return;const M=r.connections.find(z=>z.id===R);M&&t(M)},[r.connections,t]);const[F,O]=y.useState({x:0,y:0,zoom:1}),Y=y.useCallback(R=>{if(R&&(S(M=>M===R?null:R),e)){const M=r.devices.find(z=>z.id===R);M&&e(M)}},[r.devices,e]);return n.jsx("div",{className:`nice-network-topology ${b||""}`,style:{position:"relative",width:"100%",height:"100%",...v},children:n.jsx(ve,{nodes:j.nodes,edges:j.edges,groups:j.groups,viewport:F,onViewportChange:O,onSelectElement:Y,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-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"];function es(r,e,t,i){var s;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 o=(s=r[0])==null?void 0:s.id,l=0;c.forEach((d,u)=>{d>l&&(l=d,o=u)}),a[o]={x:400,y:300};const f=r.filter(d=>d.id!==o);f.forEach((d,u)=>{const x=u/f.length*2*Math.PI-Math.PI/2,g=200;a[d.id]={x:Math.cos(x)*g+400,y:Math.sin(x)*g+300}});break}case"mesh":{const c=Math.ceil(Math.sqrt(r.length));r.forEach((o,l)=>{a[o.id]={x:l%c*150+100,y:Math.floor(l/c)*130+100}});break}case"tree":{const c=r.filter(x=>x.type==="internet"||x.type==="cloud"||x.type==="router"),o=new Map,l=c.map(x=>x.id);l.forEach(x=>o.set(x,0));const f=new Set(l);for(;l.length>0;){const x=l.shift(),g=o.get(x)||0;e.forEach(h=>{let b=null;h.source===x&&!f.has(h.target)&&(b=h.target),h.target===x&&!f.has(h.source)&&(b=h.source),b&&(f.add(b),o.set(b,g+1),l.push(b))})}const d={},u={};r.forEach(x=>{const g=o.get(x.id)||0;d[g]=(d[g]||0)+1}),r.forEach(x=>{const g=o.get(x.id)||0,h=u[g]||0;u[g]=h+1;const b=d[g],v=(h-(b-1)/2)*160;a[x.id]={x:400+v,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"],o=new Map;r.forEach(f=>{o.has(f.type)||o.set(f.type,[]),o.get(f.type).push(f)});let l=50;c.forEach(f=>{const d=o.get(f);!d||d.length===0||(d.forEach((u,x)=>{const g=(x-(d.length-1)/2)*150;a[u.id]={x:400+g,y:l}}),l+=130)});break}}return a}function ts(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 rs(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 is(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 as(r){const e=r.devices.filter(u=>u.status==="online").length,t=r.devices.filter(u=>u.status==="offline").length,i=r.devices.filter(u=>u.status==="warning").length,a=r.devices.filter(u=>u.status==="critical").length,s=r.connections.filter(u=>u.status==="active").length,c=r.connections.filter(u=>u.status==="degraded"||u.status==="error").length,o=r.devices.length>0?e/r.devices.length*100:0,l=r.connections.length>0?s/r.connections.length*100:0,f=a*10+i*5+c*5;return{score:Math.max(0,Math.min(100,Math.round(o*.5+l*.5-f))),onlineDevices:e,offlineDevices:t,warningDevices:i,criticalDevices:a,activeConnections:s,degradedConnections:c}}const ss={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)"},os=({data:r,onChange:e,onNodeClick:t,editable:i=!1,showMetrics:a=!0,showProbabilities:s=!0,showSamples:c=!0,highlightPath:o,colorScheme:l="outcome",nodeColors:f,orientation:d="vertical",spacing:u={horizontal:180,vertical:120},showMinimap:x=!0,className:g,style:h})=>{const[b,v]=y.useState(null),[m,S]=y.useState(new Set),_=y.useMemo(()=>o?us(r.root,o):new Set,[r.root,o]),{nodes:I,edges:C}=y.useMemo(()=>ns(r.root,r.edges),[r.root,r.edges]),w=y.useMemo(()=>ls(I),[I]),j=y.useMemo(()=>{var q,V;const R=cs(r.root,d,u),M=I.map(T=>{const E=R[T.id]||{x:0,y:0},X=b===T.id,B=_.has(T.id),K=T.type==="leaf"||T.type==="end",Z=ds(T,l,f,w),L=K?120:160,G=a?80:K?60:70;return{id:T.id,label:T.label,x:E.x,y:E.y,width:L,height:G,shape:K?"roundedRect":"diamond",style:{fill:X||B?Z:"var(--nice-bg, #fff)",stroke:Z,strokeWidth:B?4:X?3:2,fontColor:X||B?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:K?8:0},data:{type:"decision-tree-node",node:T,isLeaf:K,isHighlighted:B}}}),z=C.map((T,E)=>{const X=_.has(T.source)&&_.has(T.target);let B=T.label||"";return s&&T.probability!==void 0&&(B+=B?` (${(T.probability*100).toFixed(0)}%)`:`${(T.probability*100).toFixed(0)}%`),{id:T.id||`edge-${E}`,source:T.source,target:T.target,label:B||void 0,style:{stroke:X?"var(--nice-primary, #3b82f6)":"var(--nice-text-muted, #9ca3af)",strokeWidth:X?3:2,arrowHead:"triangle",lineType:d==="vertical"?"orthogonal":"curved"},data:{type:"decision-edge",edge:T,isHighlighted:X}}});return Ae({id:"decision-tree",title:"Decision Tree",diagramType:"decisionTree",nodes:M,edges:z,animations:o?fs(Array.from(_)):[],metadata:{type:"decision-tree",algorithm:(q=r.metadata)==null?void 0:q.algorithm,accuracy:(V=r.metadata)==null?void 0:V.accuracy}})},[I,C,d,u,a,s,l,f,w,b,_,o,r.metadata]);y.useCallback(R=>{v(z=>z===R?null:R);const M=I.find(z=>z.id===R);M&&M.type!=="leaf"&&M.type!=="end"&&S(z=>{const q=new Set(z);return q.has(R)?q.delete(R):q.add(R),q}),t&&M&&t(M)},[I,t]);const[F,O]=y.useState({x:0,y:0,zoom:1}),Y=y.useCallback(R=>{if(!R)return;v(z=>z===R?null:R);const M=I.find(z=>z.id===R);M&&M.type!=="leaf"&&M.type!=="end"&&S(z=>{const q=new Set(z);return q.has(R)?q.delete(R):q.add(R),q}),t&&M&&t(M)},[I,t]);return n.jsx("div",{className:`nice-decision-tree-editor ${g||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:n.jsx(ve,{nodes:j.nodes,edges:j.edges,groups:j.groups,viewport:F,onViewportChange:O,onSelectElement:Y,interactive:!0,showGrid:!1})})};function ns(r,e){const t=[],i=e?[...e]:[],a=new Set(i.map(c=>`${c.source}-${c.target}`)),s=(c,o)=>{t.push(c),o&&!a.has(`${o}-${c.id}`)&&i.push({id:`e-${o}-${c.id}`,source:o,target:c.id}),c.children&&c.children.forEach((l,f)=>{let d="";c.condition&&(d=f===0?"Yes":"No");const u=`${c.id}-${l.id}`;a.has(u)||(i.push({id:`e-${u}`,source:c.id,target:l.id,label:d,branch:f===0?"yes":"no"}),a.add(u)),s(l,c.id)})};return s(r),{nodes:t,edges:i}}function cs(r,e,t){const i={},a=o=>!o.children||o.children.length===0?1:o.children.reduce((l,f)=>l+a(f),0),s=(o,l,f,d)=>{const u=f+d*t.horizontal/2,x=l*t.vertical+50;if(i[o.id]=e==="vertical"?{x:u,y:x}:{x,y:u},o.children){let g=f;o.children.forEach(h=>{const b=a(h);s(h,l+1,g,b),g+=b*t.horizontal})}},c=a(r);return s(r,0,0,c),i}function ls(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 ds(r,e,t,i){var a,s,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 o=(r.metrics.impurity-i.impurity.min)/(i.impurity.max-i.impurity.min||1);return jt("var(--nice-success, #10b981)","var(--nice-danger, #ef4444)",o)}break;case"samples":if(((s=r.metrics)==null?void 0:s.samples)!==void 0&&i){const o=(r.metrics.samples-i.samples.min)/(i.samples.max-i.samples.min||1);return jt("var(--nice-warning-bg, #fef3c7)","var(--nice-warning, #f59e0b)",o)}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 ss[r.type]||"var(--nice-text-secondary, #6b7280)"}function jt(r,e,t){const i=f=>({r:parseInt(f.slice(1,3),16),g:parseInt(f.slice(3,5),16),b:parseInt(f.slice(5,7),16)}),a=i(r),s=i(e),c=Math.round(a.r+(s.r-a.r)*t),o=Math.round(a.g+(s.g-a.g)*t),l=Math.round(a.b+(s.b-a.b)*t);return`#${[c,o,l].map(f=>f.toString(16).padStart(2,"0")).join("")}`}function us(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 s=e[a.condition.feature],o=rr(s,a.condition.operator,a.condition.value)?0:1;if(a.children[o])return i(a.children[o])}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 fs(r){return r.map((e,t)=>({id:`path-${t}`,type:"highlight",targets:[e],duration:500,delay:t*300}))}function hs(r){const{tree:e,feature_names:t,class_names:i}=r;e.children_left.length;const a=c=>{const o=e.children_left[c]===-1,l=e.n_node_samples[c],f=e.impurity[c],d=e.value[c];if(o){const v=Array.isArray(d)?d:[d],m=Array.isArray(v[0])?v[0]:v,S=m.indexOf(Math.max(...m)),_=(i==null?void 0:i[S])||`Class ${S}`,I=m.reduce((w,j)=>w+j,0),C=I>0?m[S]/I:0;return{id:`node-${c}`,type:"leaf",label:_,outcome:{value:_,class:_,probability:C,samples:l},metrics:{samples:l,impurity:f}}}const u=e.feature[c],x=e.threshold[c],g=t[u]||`feature_${u}`,h=a(e.children_left[c]),b=a(e.children_right[c]);return{id:`node-${c}`,type:c===0?"root":"decision",label:`${g} <= ${x.toFixed(2)}`,condition:{feature:g,operator:"<=",value:x},children:[h,b],metrics:{samples:l,impurity:f,giniIndex:f}}},s=a(0);return{root:s,features:t,classes:i,metadata:{algorithm:"sklearn.DecisionTreeClassifier",maxDepth:ir(s)}}}function ir(r,e=0){return!r.children||r.children.length===0?e:Math.max(...r.children.map(t=>ir(t,e+1)))}function ps(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 gs(r,e){const t=[],i=s=>{var c,o;if(t.push(s.id),s.type==="leaf"||s.type==="end"||!s.children)return{value:((c=s.outcome)==null?void 0:c.value)??s.label,probability:(o=s.outcome)==null?void 0:o.probability};if(s.condition){const l=e[s.condition.feature],d=rr(l,s.condition.operator,s.condition.value)?0:1;if(s.children[d])return i(s.children[d])}return s.children[0]?i(s.children[0]):{value:null}},a=i(r.root);return{prediction:a.value,probability:a.probability,path:t}}const ms={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 ys(r,e,t){return ar(r,t)}function At(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 bs(r,e,t,i,a=5){const s=[],c=At(r,e,t);for(const o of i){if(o.id===r)continue;const l=At(o.id,o.position,o.size);Math.abs(c.centerX-l.centerX)<=a&&s.push({axis:"vertical",position:l.centerX,sourceNodeIds:[r,o.id],type:"center"}),Math.abs(c.left-l.left)<=a&&s.push({axis:"vertical",position:l.left,sourceNodeIds:[r,o.id],type:"edge"}),Math.abs(c.right-l.right)<=a&&s.push({axis:"vertical",position:l.right,sourceNodeIds:[r,o.id],type:"edge"}),Math.abs(c.centerY-l.centerY)<=a&&s.push({axis:"horizontal",position:l.centerY,sourceNodeIds:[r,o.id],type:"center"}),Math.abs(c.top-l.top)<=a&&s.push({axis:"horizontal",position:l.top,sourceNodeIds:[r,o.id],type:"edge"}),Math.abs(c.bottom-l.bottom)<=a&&s.push({axis:"horizontal",position:l.bottom,sourceNodeIds:[r,o.id],type:"edge"})}return vs(s)}function xs(r,e,t){let i=r.x,a=r.y;const s=[],c=t.filter(l=>l.axis==="vertical");if(c.length>0){const l=r.x+e.width/2;let f=null,d=1/0;for(const u of c){const x=u.type==="center"?Math.abs(l-u.position):Math.abs(r.x-u.position);x<d&&(d=x,f=u)}f&&(i=f.type==="center"?f.position-e.width/2:f.position,s.push(f))}const o=t.filter(l=>l.axis==="horizontal");if(o.length>0){const l=r.y+e.height/2;let f=null,d=1/0;for(const u of o){const x=u.type==="center"?Math.abs(l-u.position):Math.abs(r.y-u.position);x<d&&(d=x,f=u)}f&&(a=f.type==="center"?f.position-e.height/2:f.position,s.push(f))}return{snappedPosition:{x:i,y:a},activeGuides:s}}function vs(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 ws=0;function xt(){return`tmpl-${++ws}-${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 ie(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 ks(){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],[ie(r,e,"right","left"),ie(e,t,"right","left"),ie(t,i,"right","left"),ie(i,a,"right","left")])}function _s(){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"),s=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}),o=ee("Message Queue",{x:620,y:380},"parallelogram",{width:160,height:60}),l=[r,e,t,i,a,s,c,o],f=[ie(r,e,"bottom","top"),ie(r,t,"bottom","top"),ie(r,i,"bottom","top"),ie(i,a,"right","left"),ie(t,s,"bottom","top"),ie(i,c,"bottom","top"),ie(a,o,"bottom","top")];return Re("Microservices Architecture","flowchart",l,f)}function Cs(){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"),s=ee("End",{x:350,y:560},"circle",{width:70,height:70});return Re("User Flow","flowchart",[r,e,t,i,a,s],[ie(r,e,"bottom","top"),ie(e,t,"bottom","top","New user"),ie(e,i,"bottom","top","Returning"),ie(t,a,"bottom","top"),ie(i,a,"bottom","top"),ie(a,s,"bottom","top")])}function Ms(){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],[ie(r,e,"right","left","1:N"),ie(e,t,"bottom","top","N:M"),ie(t,i,"right","left","N:1")])}function Ns(){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"),s=ee("Accounting",{x:550,y:320},"roundedRect");return Re("Organization Chart","orgchart",[r,e,t,i,a,s],[ie(r,e,"bottom","top"),ie(r,t,"bottom","top"),ie(e,i,"bottom","top"),ie(e,a,"bottom","top"),ie(t,s,"bottom","top")])}function Ss(){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],[ie(r,e,"right","left","fetch"),ie(e,t,"right","left","ok"),ie(e,i,"bottom","top","fail"),ie(i,a,"left","right"),ie(a,e,"top","bottom","retry"),ie(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:ks},{id:"microservices",name:"Microservices Architecture",description:"Microservices with API gateway, databases, and message queue",category:"software",diagramType:"flowchart",tags:["architecture","microservices","api","backend"],create:_s},{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:Cs},{id:"er-diagram",name:"Entity Relationship",description:"Database ER diagram with tables and relations",category:"software",diagramType:"er",tags:["database","er","schema","sql"],create:Ms},{id:"org-chart",name:"Organization Chart",description:"Company organizational hierarchy",category:"business",diagramType:"orgchart",tags:["org","hierarchy","team","management"],create:Ns},{id:"state-machine",name:"State Machine",description:"Finite state machine with transitions",category:"software",diagramType:"stateMachine",tags:["state","fsm","transitions","machine"],create:Ss}];function Is(r){return rt.find(e=>e.id===r)}function js(r){return rt.filter(e=>e.category===r)}function As(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 sr{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:$s(),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 s=JSON.parse(i.snapshot),c=JSON.parse(a.snapshot),o=this.calculateChanges(s,c),l={nodesAdded:o.filter(f=>f.type==="node-added").length,nodesRemoved:o.filter(f=>f.type==="node-removed").length,nodesMoved:o.filter(f=>f.type==="node-moved").length,nodesRestyled:o.filter(f=>f.type==="node-restyled").length,edgesAdded:o.filter(f=>f.type==="edge-added").length,edgesRemoved:o.filter(f=>f.type==="edge-removed").length,edgesRestyled:o.filter(f=>f.type==="edge-restyled").length,groupsModified:o.filter(f=>f.type.startsWith("group-")).length,totalChanges:o.length};return{fromVersionId:e,toVersionId:t,changes:o,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)),s=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)s.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 u=e.nodes.find(x=>x.id===d.id);u&&((u.position.x!==d.position.x||u.position.y!==d.position.y)&&i.push({type:"node-moved",elementId:d.id,elementType:"node",previousValue:{x:u.position.x,y:u.position.y},newValue:{x:d.position.x,y:d.position.y},description:`Node "${d.label||d.id}" moved`}),(u.size.width!==d.size.width||u.size.height!==d.size.height)&&i.push({type:"node-resized",elementId:d.id,elementType:"node",previousValue:{width:u.size.width,height:u.size.height},newValue:{width:d.size.width,height:d.size.height},description:`Node "${d.label||d.id}" resized`}),u.label!==d.label&&i.push({type:"node-relabeled",elementId:d.id,elementType:"node",previousValue:u.label,newValue:d.label,description:`Node label changed from "${u.label}" to "${d.label}"`}),JSON.stringify(u.style)!==JSON.stringify(d.style)&&i.push({type:"node-restyled",elementId:d.id,elementType:"node",previousValue:u.style,newValue:d.style,description:`Node "${d.label||d.id}" style changed`}))}const c=new Set(e.edges.map(d=>d.id)),o=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)o.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 u=e.edges.find(x=>x.id===d.id);u&&((u.sourceNodeId!==d.sourceNodeId||u.targetNodeId!==d.targetNodeId)&&i.push({type:"edge-rerouted",elementId:d.id,elementType:"edge",previousValue:{source:u.sourceNodeId,target:u.targetNodeId},newValue:{source:d.sourceNodeId,target:d.targetNodeId},description:"Edge rerouted"}),JSON.stringify(u.style)!==JSON.stringify(d.style)&&i.push({type:"edge-restyled",elementId:d.id,elementType:"edge",previousValue:u.style,newValue:d.style,description:"Edge style changed"}))}const l=new Set(e.groups.map(d=>d.id)),f=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)f.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 $s(){return`v_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function zs(r){const e=new sr(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 Ds{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),s={id:Ts(),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(s.id,s),this.notify(),a.forEach(c=>this.notifyMention(s,c.userId)),s}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),s={id:Ps(),authorId:this.config.userId,authorName:this.config.userName,authorAvatar:this.config.userAvatar,text:t,mentions:a,createdAt:new Date().toISOString()};return i.replies.push(s),this.notify(),a.forEach(c=>this.notifyMention(i,c.userId)),s}editReply(e,t,i){const a=this.comments.get(e);if(!a)return null;const s=a.replies.find(c=>c.id===t);return s?(s.text=i,s.mentions=this.parseMentions(i),s.editedAt=new Date().toISOString(),this.notify(),s):null}deleteReply(e,t){const i=this.comments.get(e);if(!i)return!1;const a=i.replies.find(s=>s.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(s=>s.userId===e),a=t.replies.some(s=>s.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(s=>s.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(s=>s.userId===e.mentionedUserId))))})}parseMentions(e){var s;const t=[],i=/@(\w+)/g;let a;for(;(a=i.exec(e))!==null;){const c=a[1],o=(s=this.config.availableUsers)==null?void 0:s.find(l=>l.name.toLowerCase()===c.toLowerCase()||l.id===c);o&&t.push({userId:o.id,userName:o.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 Ts(){return`comment_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function Ps(){return`reply_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}const Rs={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-bg, #fce4ec)",borderColor:"var(--nice-accent-pink, #e91e63)",textColor:"#880e4f",icon:"flame"}};function Os(r){const e=new Date(r),i=new Date().getTime()-e.getTime(),a=Math.floor(i/(1e3*60)),s=Math.floor(a/60),c=Math.floor(s/24);return a<1?"just now":a<60?`${a}m ago`:s<24?`${s}h ago`:c<7?`${c}d ago`:e.toLocaleDateString()}function Es(r,e){if(e.length===0)return r;const t=[...e].sort((a,s)=>s.startIndex-a.startIndex);let i=r;for(const a of t){const s=i.slice(0,a.startIndex),c=i.slice(a.endIndex);i=`${s}<span class="mention" data-user-id="${a.userId}">@${a.userName}</span>${c}`}return i}class or{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,s)=>a.priority-s.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 s=a.rules.find(c=>c.id===e);s&&(Object.assign(s,t),a.rules.sort((c,o)=>c.priority-o.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 s=a.rules.filter(o=>o.enabled&&(o.target==="node"||o.target==="both")&&(!o.elementShapes||o.elementShapes.includes(e.shape))),c=this.processRules(e.id,s,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 s=a.rules.filter(o=>o.enabled&&(o.target==="edge"||o.target==="both")),c=this.processRules(e.id,s,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 s of t)if(this.evaluateCondition(s.condition,i)&&(a.matchedRules.push(s.id),this.applyActions(s.actions,a),s.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 s of i){if(a==null)return;a=a[s]}return a}compareValues(e,t){const{operator:i,value:a,valueTo:s,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 o=c&&typeof e=="string"?e.toLowerCase():e,l=c&&typeof a=="string"?a.toLowerCase():a;switch(i){case"equals":return o===l;case"not_equals":return o!==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 o=="string"&&typeof l=="string"?o.includes(l):Array.isArray(e)?e.includes(a):!1;case"not_contains":return typeof o=="string"&&typeof l=="string"?!o.includes(l):Array.isArray(e)?!e.includes(a):!0;case"starts_with":return typeof o=="string"&&typeof l=="string"&&o.startsWith(l);case"ends_with":return typeof o=="string"&&typeof l=="string"&&o.endsWith(l);case"regex":if(typeof e!="string"||typeof a!="string")return!1;try{const f=c?"i":"";return new RegExp(a,f).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<=s;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 Ls(r){const e=vt.find(t=>t.id===r);return e?{...e,id:`${e.id}_${Date.now()}`}:null}function Fs(r=!1){const e=new or;if(r)for(const t of vt)e.addRule(t);return e}class Ws{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:s=!1,searchData:c=!0,dataProperties:o=[],maxResults:l=100,nodeShapes:f=[],groupIds:d=[]}=t;if(!e.trim())return this.state={...this.state,query:"",results:[],selectedIndex:-1,isActive:!1,totalCount:0},this.notify(),[];const u=[],x=s?e:e.toLowerCase();if(i==="all"||i==="nodes"||i==="labels")for(const g of this.nodes){if(u.length>=l)break;if(f.length>0&&!f.includes(g.shape)||d.length>0&&g.groupId&&!d.includes(g.groupId))continue;const h=this.matchElement(g,x,a,s,c,o);h&&u.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(u.length>=l)break;const h=this.matchElement(g,x,a,s,c,o);h&&u.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(u.length>=l)break;if(d.length>0&&!d.includes(g.id))continue;const h=this.matchElement(g,x,a,s,c,o);h&&u.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 u.sort((g,h)=>h.score-g.score),this.state={...this.state,query:e,results:u,selectedIndex:u.length>0?0:-1,isActive:!0,totalCount:u.length},this.notify(),u}matchElement(e,t,i,a,s,c){let o=null;const l=(d,u,x,g)=>{(!o||g>o.score)&&(o={text:d,property:u,positions:x,score:g})},f=this.matchText(e.id,t,i,a);if(f&&l(e.id,"id",f.positions,100+f.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(s&&"data"in e&&e.data){const d=this.searchInData(e.data,t,i,a,c);for(const u of d)l(u.text,`data.${u.property}`,u.positions,50+u.positions.length*10)}return o}matchText(e,t,i,a){const s=a?e:e.toLowerCase(),c=a?t:t.toLowerCase(),o=[];switch(i){case"exact":s===c&&o.push({start:0,end:e.length});break;case"starts_with":s.startsWith(c)&&o.push({start:0,end:t.length});break;case"ends_with":s.endsWith(c)&&o.push({start:e.length-t.length,end:e.length});break;case"regex":try{const l=a?"g":"gi",f=new RegExp(t,l);let d;for(;(d=f.exec(e))!==null&&(o.push({start:d.index,end:d.index+d[0].length}),!!f.global););}catch{}break;case"contains":default:{let l=0;for(;(l=s.indexOf(c,l))!==-1;)o.push({start:l,end:l+t.length}),l+=t.length;break}}return o.length>0?{positions:o}:null}searchInData(e,t,i,a,s,c=""){const o=[];for(const[l,f]of Object.entries(e)){const d=c?`${c}.${l}`:l;if(!(s.length>0&&!s.some(u=>d.startsWith(u))))if(typeof f=="string"){const u=this.matchText(f,t,i,a);u&&o.push({text:f,property:d,positions:u.positions})}else if(typeof f=="number"||typeof f=="boolean"){const u=String(f),x=this.matchText(u,t,i,a);x&&o.push({text:u,property:d,positions:x.positions})}else f!=null&&typeof f=="object"&&!Array.isArray(f)&&o.push(...this.searchInData(f,t,i,a,s,d))}return o}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(s=>this.matchFilters(s,e)),i=this.edges.filter(s=>this.matchFilters(s,e)),a=this.groups.filter(s=>this.matchFilters(s,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 s of i){if(a==null)return;a=a[s]}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 s=this.getPropertyValue(a,e);s!=null&&i.add(s)}if(!t||t==="edge")for(const a of this.edges){const s=this.getPropertyValue(a,e);s!=null&&i.add(s)}if(!t||t==="group")for(const a of this.groups){const s=this.getPropertyValue(a,e);s!=null&&i.add(s)}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 Bs(r,e,t="search-highlight"){if(e.length===0)return r;const i=[...e].sort((s,c)=>c.start-s.start);let a=r;for(const s of i){const c=a.slice(0,s.start),o=a.slice(s.start,s.end),l=a.slice(s.end);a=`${c}<span class="${t}">${o}</span>${l}`}return a}function qs(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=Rs;exports.ConditionalStylingEngine=or;exports.DEFAULT_GRID_CONFIG=ms;exports.DIAGRAM_STYLE_PRESETS=Ze;exports.DIAGRAM_TEMPLATES=rt;exports.DiagramCanvas=ve;exports.DiagramCellRenderer=sa;exports.DiagramCommentManager=Ds;exports.DiagramMinimap=Qe;exports.DiagramModel=Je;exports.DiagramParticleEngine=$t;exports.DiagramPropertyPanel=et;exports.DiagramSearchFilterEngine=Ws;exports.DiagramToolbar=tt;exports.DiagramVersioningManager=sr;exports.EDGE_STYLE_CATALOG=bi;exports.NODE_STYLE_CATALOG=yi;exports.NiceAnimationTimeline=Ke;exports.NiceDatabaseSchemaViewer=va;exports.NiceDecisionTreeEditor=os;exports.NiceDependencyGraph=Fa;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=Qa;exports.NiceOrgChartVisualizer=Ia;exports.NiceProcessMiningDiagram=Da;exports.NiceWorkflowVisualizer=pa;exports.PRESET_RULES=vt;exports.TRANSITION_PRESETS=Ft;exports.analyzeDependencyGraph=Ua;exports.applyAlignmentSnap=xs;exports.calculateNetworkHealth=as;exports.calculateOrgStats=za;exports.computeAlignmentGuides=bs;exports.computeGlowRadius=Dt;exports.computeLayout=Ot;exports.convertAnimation=Zt;exports.convertEdge=Ut;exports.convertGroup=Jt;exports.convertNode=Ht;exports.createConditionalStylingEngine=Fs;exports.createDecisionTree=ps;exports.createDiagramDocument=Ae;exports.createGlowFilterId=zt;exports.createLinearWorkflow=ya;exports.createOrgChartFromEmployees=$a;exports.createPresetFromTheme=ki;exports.createQuickFilter=qs;exports.createRuleFromPreset=Ls;exports.createVersioningHook=zs;exports.discoverNetworkTopology=is;exports.exportToMermaid=Tt;exports.exportToSvg=ft;exports.fetchAndGenerateDiagram=oa;exports.formatCommentDate=Os;exports.generateDiagramFromData=Xt;exports.getDiagramStylePreset=xi;exports.getDiagramStylePresetsByCategory=vi;exports.getEasing=Bt;exports.getPointOnPath=hr;exports.getTemplateById=Is;exports.getTemplatesByCategory=js;exports.highlightMatches=Bs;exports.mineProcessFromLog=Kt;exports.parseBPMNToWorkflow=ma;exports.parseNddJson=pr;exports.parsePackageJsonToDependencies=Ha;exports.parseSQLToSchema=Ma;exports.parseSklearnTree=hs;exports.predictWithTree=gs;exports.presetToThemeOverrides=wi;exports.renderTextWithMentions=Es;exports.schemaToSQL=Na;exports.searchTemplates=As;exports.snapNodePosition=ys;exports.snapPointToGrid=ar;exports.snapToGrid=ht;exports.stringifyNddJson=Rt;exports.useDiagramEditor=Lt;exports.useNiceTranslation=Ee;
|
|
6
|
+
`)}const Ia={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)"},He=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"],ja=({data:r,rootEmployeeId:e,onEmployeeClick:t,onDepartmentClick:i,showAvatars:a=!0,showContactInfo:s=!1,groupByDepartment:c=!0,collapsedDepartments:o=[],maxLevels:l=0,orientation:u="vertical",spacing:d={horizontal:200,vertical:150},statusColors:g=Ia,showMinimap:p=!0,className:m,style:h})=>{const[x,v]=b.useState(new Set),[y,S]=b.useState(null),N=b.useMemo(()=>{var V;if(e)return e;const R=r.employees.find(B=>!B.managerId);return(R==null?void 0:R.id)||((V=r.employees[0])==null?void 0:V.id)},[r.employees,e]),I=b.useMemo(()=>Aa(r.employees,N),[r.employees,N]),_=b.useMemo(()=>{const R=za(I,u,d,l),V=[],B={};c&&r.departments&&r.departments.forEach((F,O)=>{const T=F.color||He[O%He.length];B[F.id]=T;const K=r.employees.filter(q=>q.department===F.id);K.length!==0&&V.push({id:`dept-${F.id}`,label:F.name,nodeIds:K.map(q=>q.id),style:{fill:`${T}15`,stroke:T,strokeWidth:2},data:{department:F}})});const C=[],$=[],G=(F,O=0)=>{if(l>0&&O>=l||F.employee.department&&o.includes(F.employee.department))return;const T=R[F.employee.id]||{x:0,y:0},K=y===F.employee.id,q=F.employee.status||"active",H=F.employee.department?B[F.employee.department]:"var(--nice-text-secondary, #6b7280)",X=180,ne=s?120:a?90:70;C.push({id:F.employee.id,label:F.employee.name,x:T.x,y:T.y,width:X,height:ne,shape:"rectangle",style:{fill:K?H:"var(--nice-bg, #fff)",stroke:H,strokeWidth:K?3:1,fontColor:K?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:13,borderRadius:12},data:{type:"employee",employee:F.employee,statusColor:g[q],hasChildren:F.children.length>0,childrenCount:F.children.length}}),F.employee.managerId&&$.push({id:`rel-${F.employee.managerId}-${F.employee.id}`,source:F.employee.managerId,target:F.employee.id,style:{stroke:"var(--nice-border, #cbd5e1)",strokeWidth:2,arrowHead:"none",lineType:u==="vertical"?"orthogonal":"curved"}}),F.children.forEach(E=>G(E,O+1))};return I&&G(I),Ae({id:"org-chart",title:"Organization Chart",diagramType:"orgchart",nodes:C,edges:$,groups:V,metadata:{type:"org-chart",...r.metadata}})},[r,I,u,d,l,c,o,a,s,g,y]);b.useCallback(R=>{if(S(V=>V===R?null:R),v(V=>{const B=new Set(V);return B.has(R)?B.delete(R):B.add(R),B}),t){const V=r.employees.find(B=>B.id===R);V&&t(V)}},[r.employees,t]),b.useCallback(R=>{if(!i||!r.departments)return;const V=R.replace("dept-",""),B=r.departments.find(C=>C.id===V);B&&i(B)},[r.departments,i]);const[w,j]=b.useState({x:0,y:0,zoom:1}),L=b.useCallback(R=>{if(R&&(S(V=>V===R?null:R),t)){const V=r.employees.find(B=>B.id===R);V&&t(V)}},[r.employees,t]);return n.jsx("div",{className:`nice-org-chart-visualizer ${m||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:n.jsx(ve,{nodes:_.nodes,edges:_.edges,groups:_.groups,viewport:w,onViewportChange:j,onSelectElement:L,showGrid:!1})})};function Aa(r,e){const i=new Map(r.map(s=>[s.id,s])).get(e);if(!i)return null;const a=(s,c)=>{const o=r.filter(l=>l.managerId===s.id);return{employee:s,children:o.map(l=>a(l,c+1)),level:c}};return a(i,0)}function za(r,e,t,i){const a={};if(!r)return a;const s=(l,u)=>i>0&&u>=i?0:l.children.length===0?1:l.children.reduce((d,g)=>d+s(g,u+1),0),c=(l,u,d,g)=>{if(i>0&&u>=i)return;const p=d+g*t.horizontal/2,m=u*t.vertical+50;a[l.employee.id]=e==="vertical"?{x:p,y:m}:{x:m,y:p};let h=d;l.children.forEach(x=>{const v=s(x,u+1);c(x,u+1,h,v),h+=v*t.horizontal})},o=s(r,0);return c(r,0,0,o),a}function $a(r){const t=[...new Set(r.map(i=>i.department).filter(Boolean))].map((i,a)=>({id:i,name:i,color:He[a%He.length],headcount:r.filter(s=>s.department===i).length}));return{employees:r,departments:t}}function Da(r){var o;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(g=>g.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),s=Array.from(e).map(l=>r.employees.filter(u=>u.managerId===l).length),c=s.length>0?s.reduce((l,u)=>l+u,0)/s.length:0;return{totalEmployees:r.employees.length,departmentCount:((o=r.departments)==null?void 0:o.length)||0,maxDepth:a,averageSpan:Math.round(c*10)/10,managers:e.size}}const Ta=({data:r,onActivityClick:e,onTransitionClick:t,minEdgeFrequency:i=.05,showFrequency:a=!0,showDuration:s=!0,highlightBottlenecks:c=!0,bottleneckThreshold:o=.9,colorScheme:l="frequency",activityColors:u,layout:d="hierarchical",animationSpeed:g=0,showMinimap:p=!0,className:m,style:h})=>{const[x,v]=b.useState(null),y=b.useMemo(()=>"activities"in r?r:Zt(r),[r]),S=b.useMemo(()=>{if(!c)return new Set;const j=y.activities.filter(R=>R.avgDuration!==void 0).map(R=>R.avgDuration);if(j.length===0)return new Set;j.sort((R,V)=>R-V);const L=j[Math.floor(j.length*o)]||0;return new Set(y.activities.filter(R=>(R.avgDuration||0)>=L).map(R=>R.name))},[y.activities,c,o]),N=b.useMemo(()=>{const j=Math.max(...y.activities.map($=>$.frequency),1),L=Pa(y,d),R=y.transitions.filter($=>$.frequency/y.totalCases>=i),V=y.activities.map($=>{const G=L[$.name]||{x:0,y:0},F=y.startActivities.includes($.name),O=y.endActivities.includes($.name),T=S.has($.name),K=x===$.name,q=Oa($,l,j,u,T);return{id:$.name,label:$.name,x:G.x,y:G.y,width:140,height:60,shape:F?"ellipse":O?"roundedRect":"rectangle",style:{fill:K?q:"var(--nice-bg, #fff)",stroke:q,strokeWidth:T?4:K?3:2,fontColor:K?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:12,borderRadius:O?20:8},data:{type:"activity",activity:$,isStart:F,isEnd:O,isBottleneck:T,frequencyPercent:Math.round($.frequency/y.totalCases*100)}}}),B=R.map(($,G)=>{const F=$.probability||$.frequency/y.totalCases,O=F>.5,T=[];return a&&T.push(`${$.frequency}x`),s&&$.avgDuration&&T.push(Ea($.avgDuration)),{id:`trans-${G}`,source:$.from,target:$.to,label:T.join(" | "),style:{stroke:O?"var(--nice-primary, #3b82f6)":"var(--nice-text-muted, #9ca3af)",strokeWidth:Math.max(1,Math.min(6,F*8)),arrowHead:"triangle",lineType:"curved",opacity:Math.max(.3,F)},data:{type:"transition",transition:$,probability:F}}}),C=g>0?La(y,g):[];return Ae({id:"process-mining",title:"Process Mining Diagram",diagramType:"flowchart",nodes:V,edges:B,animations:C,metadata:{type:"process-mining",totalCases:y.totalCases,avgCaseDuration:y.avgCaseDuration}})},[y,i,a,s,c,S,l,u,d,g,x]);b.useCallback(j=>{if(v(L=>L===j?null:j),e){const L=y.activities.find(R=>R.name===j);L&&e(L)}},[y.activities,e]),b.useCallback(j=>{if(!t)return;const L=parseInt(j.replace("trans-",""),10),R=y.transitions[L];R&&t(R)},[y.transitions,t]);const[I,_]=b.useState({x:0,y:0,zoom:1}),w=b.useCallback(j=>{if(j&&(v(L=>L===j?null:j),e)){const L=y.activities.find(R=>R.name===j);L&&e(L)}},[y.activities,e]);return n.jsx("div",{className:`nice-process-mining-diagram ${m||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:n.jsx(ve,{nodes:N.nodes,edges:N.edges,groups:N.groups,viewport:I,onViewportChange:_,onSelectElement:w,showGrid:!0})})};function Pa(r,e){const t={};if(e==="circular"){const i=r.activities;i.forEach((a,s)=>{const c=s/i.length*2*Math.PI-Math.PI/2,o=200+i.length*15;t[a.name]={x:Math.cos(c)*o+400,y:Math.sin(c)*o+300}})}else{const i=Ra(r),a={};r.activities.forEach(c=>{const o=i[c.name]||0;a[o]=(a[o]||0)+1});const s={};r.activities.forEach(c=>{const o=i[c.name]||0,l=s[o]||0;s[o]=l+1;const u=a[o],d=(l-(u-1)/2)*180;t[c.name]={x:400+d,y:50+o*120}})}return t}function Ra(r){const e={},t=new Set,i=r.startActivities.map(a=>({activity:a,level:0}));for(;i.length>0;){const{activity:a,level:s}=i.shift();if(t.has(a))continue;t.add(a),e[a]=s,r.transitions.filter(o=>o.from===a).forEach(o=>{t.has(o.to)||i.push({activity:o.to,level:s+1})})}return r.activities.forEach(a=>{e[a.name]===void 0&&(e[a.name]=0)}),e}function Oa(r,e,t,i,a){if(a)return"var(--nice-danger, #ef4444)";if(i!=null&&i[r.name])return i[r.name];const s=r.frequency/t;switch(e){case"frequency":return ut("var(--nice-success, #10b981)","var(--nice-primary, #3b82f6)",s);case"duration":return r.avgDuration?ut("var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)",s):"var(--nice-text-secondary, #6b7280)";case"cost":return r.avgCost?ut("var(--nice-success, #10b981)","var(--nice-danger, #ef4444)",s):"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})$/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),s=i(e),c=Math.round(a.r+(s.r-a.r)*t),o=Math.round(a.g+(s.g-a.g)*t),l=Math.round(a.b+(s.b-a.b)*t);return`#${[c,o,l].map(u=>u.toString(16).padStart(2,"0")).join("")}`}function Ea(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 La(r,e){var i;const t=(i=r.variants)==null?void 0:i[0];return t?t.activities.map((a,s)=>({id:`flow-${s}`,type:"highlight",targets:[a],duration:e,delay:s*e})):[]}function Zt(r){const e=r.events.map(m=>({...m,timestamp:m.timestamp instanceof Date?m.timestamp:new Date(m.timestamp)})),t=new Map;e.forEach(m=>{t.has(m.caseId)||t.set(m.caseId,[]),t.get(m.caseId).push(m)}),t.forEach(m=>{m.sort((h,x)=>h.timestamp.getTime()-x.timestamp.getTime())});const i=new Map,a=new Map,s=new Set,c=new Set;t.forEach(m=>{if(m.length!==0){s.add(m[0].activity),c.add(m[m.length-1].activity);for(let h=0;h<m.length;h++){const x=m[h];i.has(x.activity)||i.set(x.activity,{frequency:0,durations:[],resources:new Set,costs:[]});const v=i.get(x.activity);if(v.frequency++,x.resource&&v.resources.add(x.resource),x.cost!==void 0&&v.costs.push(x.cost),h<m.length-1){const y=m[h+1],S=y.timestamp.getTime()-x.timestamp.getTime();v.durations.push(S);const N=`${x.activity}→${y.activity}`;a.has(N)||a.set(N,{frequency:0,durations:[]});const I=a.get(N);I.frequency++,I.durations.push(S)}}}});const o=Array.from(i.entries()).map(([m,h])=>({name:m,frequency:h.frequency,avgDuration:h.durations.length>0?h.durations.reduce((x,v)=>x+v,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,v)=>x+v,0)/h.costs.length:void 0})),l=Array.from(a.entries()).map(([m,h])=>{const[x,v]=m.split("→");return{from:x,to:v,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((m,h)=>{const x=m.map(y=>y.activity).join("→");u.has(x)||u.set(x,{caseIds:[],durations:[]});const v=u.get(x);if(v.caseIds.push(h),m.length>=2){const y=m[m.length-1].timestamp.getTime()-m[0].timestamp.getTime();v.durations.push(y)}});const d=Array.from(u.entries()).map(([m,h])=>({activities:m.split("→"),frequency:h.caseIds.length,avgDuration:h.durations.length>0?h.durations.reduce((x,v)=>x+v,0)/h.durations.length:0,caseIds:h.caseIds})).sort((m,h)=>h.frequency-m.frequency),g=Array.from(t.values()).filter(m=>m.length>=2).map(m=>m[m.length-1].timestamp.getTime()-m[0].timestamp.getTime()),p=g.length>0?g.reduce((m,h)=>m+h,0)/g.length:void 0;return{activities:o,transitions:l,variants:d,startActivities:Array.from(s),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-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-accent-pink, #ec4899)",dash:"2,2"},circular:{color:"var(--nice-danger, #ef4444)"}},Fa={module:"📦",package:"📁",microservice:"🔲",library:"📚",api:"🔌",database:"🗄️",external:"🌐",deprecated:"⚠️"},Wa=({data:r,onNodeClick:e,onEdgeClick:t,visibleTypes:i,visibleEdgeTypes:a,highlightCircular:s=!0,showOnlyIssues:c=!1,layout:o="force",groupBy:l="type",nodeSizeBy:u="dependencies",colorScheme:d="type",nodeColors:g,showMetrics:p=!0,interactive:m=!0,showMinimap:h=!0,className:x,style:v})=>{const[y,S]=b.useState(null),[N,I]=b.useState(null),_=b.useMemo(()=>s?tr(r):new Set,[r,s]),w=b.useMemo(()=>{let C=r.nodes;return i&&i.length>0&&(C=C.filter($=>i.includes($.type))),c&&(C=C.filter($=>{var G;return $.status==="critical"||$.status==="warning"||((G=$.metrics)==null?void 0:G.issues)&&$.metrics.issues>0})),C},[r.nodes,i,c]),j=b.useMemo(()=>{const C=new Set(w.map(G=>G.id));let $=r.edges.filter(G=>C.has(G.source)&&C.has(G.target));return a&&a.length>0&&($=$.filter(G=>a.includes(G.type))),$},[r.edges,w,a]),L=b.useMemo(()=>{const C=Ba(w,j,o),$=Ga(w,u),G=[];if(l!=="none"){const T=new Map;w.forEach(q=>{const H=l==="type"?q.type:q.group||"ungrouped";T.has(H)||T.set(H,[]),T.get(H).push(q.id)});let K=0;T.forEach((q,H)=>{var ne,E;const X=l==="type"?Qt[H]||"var(--nice-text-secondary, #6b7280)":((E=(ne=r.groups)==null?void 0:ne.find(Z=>Z.id===H))==null?void 0:E.color)||Ue[K%Ue.length];G.push({id:`group-${H}`,label:H,nodeIds:q,style:{fill:`${X}10`,stroke:X,strokeWidth:1}}),K++})}const F=w.map(T=>{const K=C[T.id]||{x:0,y:0},q=y===T.id,H=N===T.id,X=_.has(T.id),ne=Va(T,u,$),E=Ya(T,d,g,X);return{id:T.id,label:T.name,x:K.x,y:K.y,width:ne.width,height:ne.height,shape:Xa(T.type),style:{fill:q||H?E:"var(--nice-bg, #fff)",stroke:E,strokeWidth:X?4:q?3:2,fontColor:q||H?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:8,strokeDasharray:T.status==="deprecated"?"4,4":void 0},data:{type:"dependency",node:T,icon:Fa[T.type],isCircular:X,statusColor:er[T.status||"unknown"]}}}),O=j.map((T,K)=>{const q=T.type==="circular"||_.has(T.source)&&_.has(T.target),H=St[T.type]||St.import;return{id:T.id||`edge-${K}`,source:T.source,target:T.target,label:T.optional?"(optional)":void 0,style:{stroke:q?"var(--nice-danger, #ef4444)":H.color,strokeWidth:Math.max(1,Math.min(4,T.weight||1)),strokeDasharray:H.dash,arrowHead:"triangle",lineType:"curved",opacity:T.optional?.5:1},data:{type:T.type,edge:T,isCircular:q}}});return Ae({id:"dependency-graph",title:"Dependency Graph",diagramType:"custom",nodes:F,edges:O,groups:G,metadata:{type:"dependency-graph",...r.metadata}})},[w,j,o,l,r.groups,u,d,g,_,y,N]);b.useCallback(C=>{if(S($=>$===C?null:C),e){const $=r.nodes.find(G=>G.id===C);$&&e($)}},[r.nodes,e]),b.useCallback(C=>{if(!t)return;const $=r.edges.find(G=>G.id===C);$&&t($)},[r.edges,t]),b.useCallback(C=>{I(C)},[]);const[R,V]=b.useState({x:0,y:0,zoom:1}),B=b.useCallback(C=>{if(C){if(S($=>$===C?null:C),e){const $=r.nodes.find(G=>G.id===C);$&&e($)}if(t){const $=r.edges.find(G=>G.id===C);$&&t($)}}},[r.nodes,r.edges,e,t]);return n.jsx("div",{className:`nice-dependency-graph ${x||""}`,style:{position:"relative",width:"100%",height:"100%",...v},children:n.jsx(ve,{nodes:L.nodes,edges:L.edges,groups:L.groups,viewport:R,onViewportChange:V,onSelectElement:B,interactive:m,showGrid:!0})})},Ue=["var(--nice-primary, #3b82f6)","var(--nice-success, #10b981)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-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 o;(o=t.get(c.source))==null||o.push(c.target)});const i=new Set,a=new Set,s=(c,o)=>{i.add(c),a.add(c),o.push(c);const l=t.get(c)||[];for(const u of l)if(i.has(u)){if(a.has(u)){const d=o.indexOf(u);o.slice(d).forEach(p=>e.add(p))}}else if(s(u,[...o]))return!0;return a.delete(c),!1};return r.nodes.forEach(c=>{i.has(c.id)||s(c.id,[])}),e}function Ba(r,e,t){const i={};switch(t){case"circular":{r.forEach((a,s)=>{const c=s/r.length*2*Math.PI-Math.PI/2,o=150+r.length*12;i[a.id]={x:Math.cos(c)*o+400,y:Math.sin(c)*o+300}});break}case"grid":{const a=Math.ceil(Math.sqrt(r.length));r.forEach((s,c)=>{i[s.id]={x:c%a*200+100,y:Math.floor(c/a)*150+100}});break}case"hierarchical":{const a=qa(r,e),s={},c={};r.forEach(o=>{const l=a[o.id]||0;s[l]=(s[l]||0)+1}),r.forEach(o=>{const l=a[o.id]||0,u=c[l]||0;c[l]=u+1;const d=s[l],g=(u-(d-1)/2)*200;i[o.id]={x:400+g,y:80+l*130}});break}default:{r.forEach((a,s)=>{const c=s/r.length*2*Math.PI,o=200+r.length*10;i[a.id]={x:Math.cos(c)*o+400,y:Math.sin(c)*o+300}});for(let a=0;a<50;a++){const s={};r.forEach(c=>s[c.id]={x:0,y:0});for(let c=0;c<r.length;c++)for(let o=c+1;o<r.length;o++){const l=r[c].id,u=r[o].id,d=i[u].x-i[l].x,g=i[u].y-i[l].y,p=Math.max(1,Math.sqrt(d*d+g*g)),m=5e3/(p*p);s[l].x-=d/p*m,s[l].y-=g/p*m,s[u].x+=d/p*m,s[u].y+=g/p*m}e.forEach(c=>{const o=i[c.target].x-i[c.source].x,l=i[c.target].y-i[c.source].y,u=Math.sqrt(o*o+l*l),d=u*.01;s[c.source].x+=o/u*d,s[c.source].y+=l/u*d,s[c.target].x-=o/u*d,s[c.target].y-=l/u*d}),r.forEach(c=>{i[c.id].x+=Math.max(-10,Math.min(10,s[c.id].x)),i[c.id].y+=Math.max(-10,Math.min(10,s[c.id].y))})}break}}return i}function qa(r,e){const t={},i={};r.forEach(s=>{t[s.id]=0,i[s.id]=0}),e.forEach(s=>{i[s.target]=(i[s.target]||0)+1});const a=r.filter(s=>i[s.id]===0).map(s=>s.id);for(;a.length>0;){const s=a.shift();e.filter(o=>o.source===s).forEach(o=>{t[o.target]=Math.max(t[o.target],t[s]+1),i[o.target]--,i[o.target]===0&&a.push(o.target)})}return t}function Ga(r,e){const t=r.map(i=>{var a,s,c;switch(e){case"dependencies":return((a=i.metrics)==null?void 0:a.dependencies)||0;case"dependents":return((s=i.metrics)==null?void 0:s.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 Va(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,s=100,o=s+a*(180-s);return{width:o,height:o*.5}}function Ya(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 Ue[Ha(r.group||"")%Ue.length];default:return Qt[r.type]||"var(--nice-text-secondary, #6b7280)"}}function Xa(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 Ua(r){const e=[{id:r.name,name:r.name,version:r.version,type:"package",status:"healthy"}],t=[];let i=0;const a=(s,c)=>{s&&Object.entries(s).forEach(([o,l])=>{e.find(u=>u.id===o)||e.push({id:o,name:o,version:l.replace(/[\^~>=<]/g,""),type:"library",status:"unknown"}),t.push({id:`edge-${i++}`,source:r.name,target:o,type:c})})};return a(r.dependencies,"runtime"),a(r.devDependencies,"dev"),a(r.peerDependencies,"peer"),e.forEach(s=>{s.metrics={dependencies:t.filter(c=>c.source===s.id).length,dependents:t.filter(c=>c.target===s.id).length}}),{nodes:e,edges:t}}function Ja(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 g=e.get(d.id)||0;g>a&&(a=g,i=d)});let s=null,c=0;r.nodes.forEach(d=>{const g=t.get(d.id)||0;g>c&&(c=g,s=d)});const o=r.nodes.filter(d=>(e.get(d.id)||0)===0&&(t.get(d.id)||0)===0),l=Array.from(t.values()).reduce((d,g)=>d+g,0),u=r.nodes.length>0?l/r.nodes.length:0;return{totalNodes:r.nodes.length,totalEdges:r.edges.length,circularDependencies:[],mostDependent:i,mostDependencies:s,orphanNodes:o,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)"},Za={router:"🔀",switch:"🔌",firewall:"🛡️",server:"🖥️",workstation:"💻",laptop:"💻",phone:"📱",printer:"🖨️",camera:"📷",iot:"📡",loadbalancer:"⚖️",storage:"💾",cloud:"☁️",internet:"🌐",unknown:"❓"},Qa={ethernet:"var(--nice-primary, #3b82f6)",fiber:"var(--nice-success, #10b981)",wireless:"var(--nice-accent, #8b5cf6)",vpn:"var(--nice-warning, #f59e0b)",wan:"var(--nice-accent-pink, #ec4899)",trunk:"var(--nice-info, #14b8a6)"},es=({data:r,onDeviceClick:e,onConnectionClick:t,onRefresh:i,autoRefreshInterval:a=0,visibleDeviceTypes:s,showOnlyIssues:c=!1,layout:o="hierarchical",groupBy:l="group",showMetrics:u=!0,showBandwidth:d=!0,showLatency:g=!1,animateTraffic:p=!1,statusColors:m=Ka,showMinimap:h=!0,className:x,style:v})=>{const[y,S]=b.useState(null),[N,I]=b.useState(new Date);b.useEffect(()=>{if(a<=0||!i)return;const B=setInterval(()=>{i(),I(new Date)},a);return()=>clearInterval(B)},[a,i]);const _=b.useMemo(()=>{let B=r.devices;return s&&s.length>0&&(B=B.filter(C=>s.includes(C.type))),c&&(B=B.filter(C=>C.status==="critical"||C.status==="warning"||C.status==="offline")),B},[r.devices,s,c]),w=b.useMemo(()=>{const B=new Set(_.map(C=>C.id));return r.connections.filter(C=>B.has(C.source)&&B.has(C.target))},[r.connections,_]),j=b.useMemo(()=>{const B=ts(_,w,o,r.groups),C=[];if(l!=="none"){const O=new Map;_.forEach(K=>{let q;switch(l){case"type":q=K.type;break;case"location":q=K.location||"Unknown Location";break;default:q=K.group||"ungrouped"}O.has(q)||O.set(q,[]),O.get(q).push(K.id)});let T=0;O.forEach((K,q)=>{var ne;const H=(ne=r.groups)==null?void 0:ne.find(E=>E.id===q||E.name===q),X=(H==null?void 0:H.color)||It[T%It.length];C.push({id:`group-${q}`,label:(H==null?void 0:H.name)||q,nodeIds:K,style:{fill:`${X}15`,stroke:X,strokeWidth:2}}),T++})}const $=_.map(O=>{const T=B[O.id]||{x:0,y:0},K=y===O.id,q=m[O.status],H=Za[O.type];return{id:O.id,label:O.name,x:T.x,y:T.y,width:120,height:u?90:70,shape:rs(O.type),style:{fill:K?q:"var(--nice-bg, #fff)",stroke:q,strokeWidth:K?3:2,fontColor:K?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:8},data:{type:"network-device",device:O,icon:H,statusColor:q}}}),G=w.map((O,T)=>{const K=Qa[O.type]||"var(--nice-text-secondary, #6b7280)",q=O.status==="active",H=O.status==="degraded"||O.status==="error",X=[];if(d&&O.bandwidth){const ne=Math.round(O.bandwidth.used/O.bandwidth.total*100);X.push(`${ne}%`)}return g&&O.latency!==void 0&&X.push(`${O.latency}ms`),{id:O.id||`conn-${T}`,source:O.source,target:O.target,sourcePort:O.sourcePort,targetPort:O.targetPort,label:X.join(" | ")||void 0,style:{stroke:H?"var(--nice-danger, #ef4444)":K,strokeWidth:Math.max(1,Math.min(6,(O.speed||1e3)/1e3)),strokeDasharray:q?void 0:"5,5",arrowHead:"none",lineType:O.type==="wireless"?"curved":"orthogonal",opacity:O.status==="inactive"?.3:1},data:{type:O.type,connection:O,isActive:q,isDegraded:H}}}),F=p?is(w):[];return Ae({id:"network-topology",title:"Network Topology",diagramType:"networkTopology",nodes:$,edges:G,groups:C,animations:F,metadata:{type:"network-topology",lastRefresh:N.toISOString(),...r.metadata}})},[_,w,o,l,r.groups,u,d,g,p,m,y,N]);b.useCallback(B=>{if(S(C=>C===B?null:B),e){const C=r.devices.find($=>$.id===B);C&&e(C)}},[r.devices,e]),b.useCallback(B=>{if(!t)return;const C=r.connections.find($=>$.id===B);C&&t(C)},[r.connections,t]);const[L,R]=b.useState({x:0,y:0,zoom:1}),V=b.useCallback(B=>{if(B&&(S(C=>C===B?null:B),e)){const C=r.devices.find($=>$.id===B);C&&e(C)}},[r.devices,e]);return n.jsx("div",{className:`nice-network-topology ${x||""}`,style:{position:"relative",width:"100%",height:"100%",...v},children:n.jsx(ve,{nodes:j.nodes,edges:j.edges,groups:j.groups,viewport:L,onViewportChange:R,onSelectElement:V,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-accent-pink, #ec4899)","var(--nice-info, #14b8a6)","var(--nice-info, #6366f1)"];function ts(r,e,t,i){var s;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 o=(s=r[0])==null?void 0:s.id,l=0;c.forEach((d,g)=>{d>l&&(l=d,o=g)}),a[o]={x:400,y:300};const u=r.filter(d=>d.id!==o);u.forEach((d,g)=>{const p=g/u.length*2*Math.PI-Math.PI/2,m=200;a[d.id]={x:Math.cos(p)*m+400,y:Math.sin(p)*m+300}});break}case"mesh":{const c=Math.ceil(Math.sqrt(r.length));r.forEach((o,l)=>{a[o.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"),o=new Map,l=c.map(p=>p.id);l.forEach(p=>o.set(p,0));const u=new Set(l);for(;l.length>0;){const p=l.shift(),m=o.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),o.set(x,m+1),l.push(x))})}const d={},g={};r.forEach(p=>{const m=o.get(p.id)||0;d[m]=(d[m]||0)+1}),r.forEach(p=>{const m=o.get(p.id)||0,h=g[m]||0;g[m]=h+1;const x=d[m],v=(h-(x-1)/2)*160;a[p.id]={x:400+v,y:80+m*120}});break}case"hierarchical":default:{const c=["internet","cloud","router","firewall","loadbalancer","switch","server","storage","workstation","laptop","phone","printer","camera","iot","unknown"],o=new Map;r.forEach(u=>{o.has(u.type)||o.set(u.type,[]),o.get(u.type).push(u)});let l=50;c.forEach(u=>{const d=o.get(u);!d||d.length===0||(d.forEach((g,p)=>{const m=(p-(d.length-1)/2)*150;a[g.id]={x:400+m,y:l}}),l+=130)});break}}return a}function rs(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 is(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 as(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 ss(r){const e=r.devices.filter(g=>g.status==="online").length,t=r.devices.filter(g=>g.status==="offline").length,i=r.devices.filter(g=>g.status==="warning").length,a=r.devices.filter(g=>g.status==="critical").length,s=r.connections.filter(g=>g.status==="active").length,c=r.connections.filter(g=>g.status==="degraded"||g.status==="error").length,o=r.devices.length>0?e/r.devices.length*100:0,l=r.connections.length>0?s/r.connections.length*100:0,u=a*10+i*5+c*5;return{score:Math.max(0,Math.min(100,Math.round(o*.5+l*.5-u))),onlineDevices:e,offlineDevices:t,warningDevices:i,criticalDevices:a,activeConnections:s,degradedConnections:c}}const os=[{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"}],ns={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)"},cs=({data:r,onChange:e,onNodeClick:t,editable:i=!1,showMetrics:a=!0,showProbabilities:s=!0,showSamples:c=!0,highlightPath:o,colorScheme:l="outcome",nodeColors:u,orientation:d="vertical",spacing:g={horizontal:180,vertical:120},showMinimap:p=!0,className:m,style:h,tutorial:x})=>{const[v,y]=b.useState(null),[S,N]=b.useState(new Set),I=b.useMemo(()=>o?hs(r.root,o):new Set,[r.root,o]),{nodes:_,edges:w}=b.useMemo(()=>ls(r.root,r.edges),[r.root,r.edges]),j=b.useMemo(()=>us(_),[_]),L=b.useMemo(()=>{var F,O;const C=ds(r.root,d,g),$=_.map(T=>{const K=C[T.id]||{x:0,y:0},q=v===T.id,H=I.has(T.id),X=T.type==="leaf"||T.type==="end",ne=fs(T,l,u,j),E=X?120:160,Z=a?80:X?60:70;return{id:T.id,label:T.label,x:K.x,y:K.y,width:E,height:Z,shape:X?"roundedRect":"diamond",style:{fill:q||H?ne:"var(--nice-bg, #fff)",stroke:ne,strokeWidth:H?4:q?3:2,fontColor:q||H?"var(--nice-bg, #fff)":"var(--nice-text, #1f2937)",fontSize:11,borderRadius:X?8:0},data:{type:"decision-tree-node",node:T,isLeaf:X,isHighlighted:H}}}),G=w.map((T,K)=>{const q=I.has(T.source)&&I.has(T.target);let H=T.label||"";return s&&T.probability!==void 0&&(H+=H?` (${(T.probability*100).toFixed(0)}%)`:`${(T.probability*100).toFixed(0)}%`),{id:T.id||`edge-${K}`,source:T.source,target:T.target,label:H||void 0,style:{stroke:q?"var(--nice-primary, #3b82f6)":"var(--nice-text-muted, #9ca3af)",strokeWidth:q?3:2,arrowHead:"triangle",lineType:d==="vertical"?"orthogonal":"curved"},data:{type:"decision-edge",edge:T,isHighlighted:q}}});return Ae({id:"decision-tree",title:"Decision Tree",diagramType:"decisionTree",nodes:$,edges:G,animations:o?ps(Array.from(I)):[],metadata:{type:"decision-tree",algorithm:(F=r.metadata)==null?void 0:F.algorithm,accuracy:(O=r.metadata)==null?void 0:O.accuracy}})},[_,w,d,g,a,s,l,u,j,v,I,o,r.metadata]);b.useCallback(C=>{y(G=>G===C?null:C);const $=_.find(G=>G.id===C);$&&$.type!=="leaf"&&$.type!=="end"&&N(G=>{const F=new Set(G);return F.has(C)?F.delete(C):F.add(C),F}),t&&$&&t($)},[_,t]);const[R,V]=b.useState({x:0,y:0,zoom:1}),B=b.useCallback(C=>{if(!C)return;y(G=>G===C?null:C);const $=_.find(G=>G.id===C);$&&$.type!=="leaf"&&$.type!=="end"&&N(G=>{const F=new Set(G);return F.has(C)?F.delete(C):F.add(C),F}),t&&$&&t($)},[_,t]);return n.jsxs("div",{className:`nice-decision-tree-editor ${m||""}`,style:{position:"relative",width:"100%",height:"100%",...h},children:[n.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:n.jsx(M.NiceTutorialButton,{steps:M.resolveTutorial(x,os)})}),n.jsx(ve,{nodes:L.nodes,edges:L.edges,groups:L.groups,viewport:R,onViewportChange:V,onSelectElement:B,interactive:!0,showGrid:!1})]})};function ls(r,e){const t=[],i=e?[...e]:[],a=new Set(i.map(c=>`${c.source}-${c.target}`)),s=(c,o)=>{t.push(c),o&&!a.has(`${o}-${c.id}`)&&i.push({id:`e-${o}-${c.id}`,source:o,target:c.id}),c.children&&c.children.forEach((l,u)=>{let d="";c.condition&&(d=u===0?"Yes":"No");const g=`${c.id}-${l.id}`;a.has(g)||(i.push({id:`e-${g}`,source:c.id,target:l.id,label:d,branch:u===0?"yes":"no"}),a.add(g)),s(l,c.id)})};return s(r),{nodes:t,edges:i}}function ds(r,e,t){const i={},a=o=>!o.children||o.children.length===0?1:o.children.reduce((l,u)=>l+a(u),0),s=(o,l,u,d)=>{const g=u+d*t.horizontal/2,p=l*t.vertical+50;if(i[o.id]=e==="vertical"?{x:g,y:p}:{x:p,y:g},o.children){let m=u;o.children.forEach(h=>{const x=a(h);s(h,l+1,m,x),m+=x*t.horizontal})}},c=a(r);return s(r,0,0,c),i}function us(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 fs(r,e,t,i){var a,s,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 o=(r.metrics.impurity-i.impurity.min)/(i.impurity.max-i.impurity.min||1);return jt("var(--nice-success, #10b981)","var(--nice-danger, #ef4444)",o)}break;case"samples":if(((s=r.metrics)==null?void 0:s.samples)!==void 0&&i){const o=(r.metrics.samples-i.samples.min)/(i.samples.max-i.samples.min||1);return jt("var(--nice-warning-bg, #fef3c7)","var(--nice-warning, #f59e0b)",o)}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 ns[r.type]||"var(--nice-text-secondary, #6b7280)"}function jt(r,e,t){const i=u=>({r:parseInt(u.slice(1,3),16),g:parseInt(u.slice(3,5),16),b:parseInt(u.slice(5,7),16)}),a=i(r),s=i(e),c=Math.round(a.r+(s.r-a.r)*t),o=Math.round(a.g+(s.g-a.g)*t),l=Math.round(a.b+(s.b-a.b)*t);return`#${[c,o,l].map(u=>u.toString(16).padStart(2,"0")).join("")}`}function hs(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 s=e[a.condition.feature],o=rr(s,a.condition.operator,a.condition.value)?0:1;if(a.children[o])return i(a.children[o])}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 ps(r){return r.map((e,t)=>({id:`path-${t}`,type:"highlight",targets:[e],duration:500,delay:t*300}))}function gs(r){const{tree:e,feature_names:t,class_names:i}=r;e.children_left.length;const a=c=>{const o=e.children_left[c]===-1,l=e.n_node_samples[c],u=e.impurity[c],d=e.value[c];if(o){const v=Array.isArray(d)?d:[d],y=Array.isArray(v[0])?v[0]:v,S=y.indexOf(Math.max(...y)),N=(i==null?void 0:i[S])||`Class ${S}`,I=y.reduce((w,j)=>w+j,0),_=I>0?y[S]/I:0;return{id:`node-${c}`,type:"leaf",label:N,outcome:{value:N,class:N,probability:_,samples:l},metrics:{samples:l,impurity:u}}}const g=e.feature[c],p=e.threshold[c],m=t[g]||`feature_${g}`,h=a(e.children_left[c]),x=a(e.children_right[c]);return{id:`node-${c}`,type:c===0?"root":"decision",label:`${m} <= ${p.toFixed(2)}`,condition:{feature:m,operator:"<=",value:p},children:[h,x],metrics:{samples:l,impurity:u,giniIndex:u}}},s=a(0);return{root:s,features:t,classes:i,metadata:{algorithm:"sklearn.DecisionTreeClassifier",maxDepth:ir(s)}}}function ir(r,e=0){return!r.children||r.children.length===0?e:Math.max(...r.children.map(t=>ir(t,e+1)))}function ms(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 ys(r,e){const t=[],i=s=>{var c,o;if(t.push(s.id),s.type==="leaf"||s.type==="end"||!s.children)return{value:((c=s.outcome)==null?void 0:c.value)??s.label,probability:(o=s.outcome)==null?void 0:o.probability};if(s.condition){const l=e[s.condition.feature],d=rr(l,s.condition.operator,s.condition.value)?0:1;if(s.children[d])return i(s.children[d])}return s.children[0]?i(s.children[0]):{value:null}},a=i(r.root);return{prediction:a.value,probability:a.probability,path:t}}const bs={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 xs(r,e,t){return ar(r,t)}function At(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 vs(r,e,t,i,a=5){const s=[],c=At(r,e,t);for(const o of i){if(o.id===r)continue;const l=At(o.id,o.position,o.size);Math.abs(c.centerX-l.centerX)<=a&&s.push({axis:"vertical",position:l.centerX,sourceNodeIds:[r,o.id],type:"center"}),Math.abs(c.left-l.left)<=a&&s.push({axis:"vertical",position:l.left,sourceNodeIds:[r,o.id],type:"edge"}),Math.abs(c.right-l.right)<=a&&s.push({axis:"vertical",position:l.right,sourceNodeIds:[r,o.id],type:"edge"}),Math.abs(c.centerY-l.centerY)<=a&&s.push({axis:"horizontal",position:l.centerY,sourceNodeIds:[r,o.id],type:"center"}),Math.abs(c.top-l.top)<=a&&s.push({axis:"horizontal",position:l.top,sourceNodeIds:[r,o.id],type:"edge"}),Math.abs(c.bottom-l.bottom)<=a&&s.push({axis:"horizontal",position:l.bottom,sourceNodeIds:[r,o.id],type:"edge"})}return ks(s)}function ws(r,e,t){let i=r.x,a=r.y;const s=[],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 g of c){const p=g.type==="center"?Math.abs(l-g.position):Math.abs(r.x-g.position);p<d&&(d=p,u=g)}u&&(i=u.type==="center"?u.position-e.width/2:u.position,s.push(u))}const o=t.filter(l=>l.axis==="horizontal");if(o.length>0){const l=r.y+e.height/2;let u=null,d=1/0;for(const g of o){const p=g.type==="center"?Math.abs(l-g.position):Math.abs(r.y-g.position);p<d&&(d=p,u=g)}u&&(a=u.type==="center"?u.position-e.height/2:u.position,s.push(u))}return{snappedPosition:{x:i,y:a},activeGuides:s}}function ks(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 _s=0;function xt(){return`tmpl-${++_s}-${Date.now().toString(36)}`}function te(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 ie(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 Cs(){const r=te("Commit",{x:40,y:200},"circle",{width:80,height:80}),e=te("Build",{x:200,y:200},"roundedRect"),t=te("Test",{x:420,y:200},"roundedRect"),i=te("Deploy",{x:640,y:200},"roundedRect"),a=te("Production",{x:860,y:200},"hexagon",{width:140,height:80});return Re("CI/CD Pipeline","flowchart",[r,e,t,i,a],[ie(r,e,"right","left"),ie(e,t,"right","left"),ie(t,i,"right","left"),ie(i,a,"right","left")])}function Ms(){const r=te("API Gateway",{x:350,y:40},"hexagon",{width:160,height:80}),e=te("Auth Service",{x:80,y:200},"roundedRect"),t=te("User Service",{x:300,y:200},"roundedRect"),i=te("Order Service",{x:520,y:200},"roundedRect"),a=te("Notification",{x:740,y:200},"roundedRect"),s=te("Users DB",{x:180,y:380},"cylinder",{width:120,height:70}),c=te("Orders DB",{x:520,y:380},"cylinder",{width:120,height:70}),o=te("Message Queue",{x:620,y:380},"parallelogram",{width:160,height:60}),l=[r,e,t,i,a,s,c,o],u=[ie(r,e,"bottom","top"),ie(r,t,"bottom","top"),ie(r,i,"bottom","top"),ie(i,a,"right","left"),ie(t,s,"bottom","top"),ie(i,c,"bottom","top"),ie(a,o,"bottom","top")];return Re("Microservices Architecture","flowchart",l,u)}function Ns(){const r=te("Start",{x:350,y:20},"circle",{width:70,height:70}),e=te("Landing Page",{x:310,y:140},"roundedRect"),t=te("Sign Up",{x:140,y:280},"roundedRect"),i=te("Log In",{x:480,y:280},"roundedRect"),a=te("Dashboard",{x:310,y:420},"roundedRect"),s=te("End",{x:350,y:560},"circle",{width:70,height:70});return Re("User Flow","flowchart",[r,e,t,i,a,s],[ie(r,e,"bottom","top"),ie(e,t,"bottom","top","New user"),ie(e,i,"bottom","top","Returning"),ie(t,a,"bottom","top"),ie(i,a,"bottom","top"),ie(a,s,"bottom","top")])}function Ss(){const r=te("Users",{x:80,y:100},"rectangle",{width:180,height:100}),e=te("Orders",{x:380,y:100},"rectangle",{width:180,height:100}),t=te("Products",{x:380,y:320},"rectangle",{width:180,height:100}),i=te("Categories",{x:680,y:320},"rectangle",{width:180,height:100});return Re("Entity Relationship","er",[r,e,t,i],[ie(r,e,"right","left","1:N"),ie(e,t,"bottom","top","N:M"),ie(t,i,"right","left","N:1")])}function Is(){const r=te("CEO",{x:350,y:40},"roundedRect"),e=te("CTO",{x:150,y:180},"roundedRect"),t=te("CFO",{x:550,y:180},"roundedRect"),i=te("Engineering",{x:50,y:320},"roundedRect"),a=te("DevOps",{x:250,y:320},"roundedRect"),s=te("Accounting",{x:550,y:320},"roundedRect");return Re("Organization Chart","orgchart",[r,e,t,i,a,s],[ie(r,e,"bottom","top"),ie(r,t,"bottom","top"),ie(e,i,"bottom","top"),ie(e,a,"bottom","top"),ie(t,s,"bottom","top")])}function js(){const r=te("Idle",{x:80,y:200},"circle",{width:90,height:90}),e=te("Loading",{x:300,y:80},"roundedRect"),t=te("Success",{x:520,y:80},"roundedRect"),i=te("Error",{x:520,y:320},"roundedRect"),a=te("Retry",{x:300,y:320},"diamond",{width:100,height:100});return Re("State Machine","stateMachine",[r,e,t,i,a],[ie(r,e,"right","left","fetch"),ie(e,t,"right","left","ok"),ie(e,i,"bottom","top","fail"),ie(i,a,"left","right"),ie(a,e,"top","bottom","retry"),ie(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:Cs},{id:"microservices",name:"Microservices Architecture",description:"Microservices with API gateway, databases, and message queue",category:"software",diagramType:"flowchart",tags:["architecture","microservices","api","backend"],create:Ms},{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:Ns},{id:"er-diagram",name:"Entity Relationship",description:"Database ER diagram with tables and relations",category:"software",diagramType:"er",tags:["database","er","schema","sql"],create:Ss},{id:"org-chart",name:"Organization Chart",description:"Company organizational hierarchy",category:"business",diagramType:"orgchart",tags:["org","hierarchy","team","management"],create:Is},{id:"state-machine",name:"State Machine",description:"Finite state machine with transitions",category:"software",diagramType:"stateMachine",tags:["state","fsm","transitions","machine"],create:js}];function As(r){return rt.find(e=>e.id===r)}function zs(r){return rt.filter(e=>e.category===r)}function $s(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 sr{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:Ds(),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 s=JSON.parse(i.snapshot),c=JSON.parse(a.snapshot),o=this.calculateChanges(s,c),l={nodesAdded:o.filter(u=>u.type==="node-added").length,nodesRemoved:o.filter(u=>u.type==="node-removed").length,nodesMoved:o.filter(u=>u.type==="node-moved").length,nodesRestyled:o.filter(u=>u.type==="node-restyled").length,edgesAdded:o.filter(u=>u.type==="edge-added").length,edgesRemoved:o.filter(u=>u.type==="edge-removed").length,edgesRestyled:o.filter(u=>u.type==="edge-restyled").length,groupsModified:o.filter(u=>u.type.startsWith("group-")).length,totalChanges:o.length};return{fromVersionId:e,toVersionId:t,changes:o,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)),s=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)s.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 g=e.nodes.find(p=>p.id===d.id);g&&((g.position.x!==d.position.x||g.position.y!==d.position.y)&&i.push({type:"node-moved",elementId:d.id,elementType:"node",previousValue:{x:g.position.x,y:g.position.y},newValue:{x:d.position.x,y:d.position.y},description:`Node "${d.label||d.id}" moved`}),(g.size.width!==d.size.width||g.size.height!==d.size.height)&&i.push({type:"node-resized",elementId:d.id,elementType:"node",previousValue:{width:g.size.width,height:g.size.height},newValue:{width:d.size.width,height:d.size.height},description:`Node "${d.label||d.id}" resized`}),g.label!==d.label&&i.push({type:"node-relabeled",elementId:d.id,elementType:"node",previousValue:g.label,newValue:d.label,description:`Node label changed from "${g.label}" to "${d.label}"`}),JSON.stringify(g.style)!==JSON.stringify(d.style)&&i.push({type:"node-restyled",elementId:d.id,elementType:"node",previousValue:g.style,newValue:d.style,description:`Node "${d.label||d.id}" style changed`}))}const c=new Set(e.edges.map(d=>d.id)),o=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)o.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 g=e.edges.find(p=>p.id===d.id);g&&((g.sourceNodeId!==d.sourceNodeId||g.targetNodeId!==d.targetNodeId)&&i.push({type:"edge-rerouted",elementId:d.id,elementType:"edge",previousValue:{source:g.sourceNodeId,target:g.targetNodeId},newValue:{source:d.sourceNodeId,target:d.targetNodeId},description:"Edge rerouted"}),JSON.stringify(g.style)!==JSON.stringify(d.style)&&i.push({type:"edge-restyled",elementId:d.id,elementType:"edge",previousValue:g.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 Ds(){return`v_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function Ts(r){const e=new sr(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 Ps{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),s={id:Rs(),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(s.id,s),this.notify(),a.forEach(c=>this.notifyMention(s,c.userId)),s}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),s={id:Os(),authorId:this.config.userId,authorName:this.config.userName,authorAvatar:this.config.userAvatar,text:t,mentions:a,createdAt:new Date().toISOString()};return i.replies.push(s),this.notify(),a.forEach(c=>this.notifyMention(i,c.userId)),s}editReply(e,t,i){const a=this.comments.get(e);if(!a)return null;const s=a.replies.find(c=>c.id===t);return s?(s.text=i,s.mentions=this.parseMentions(i),s.editedAt=new Date().toISOString(),this.notify(),s):null}deleteReply(e,t){const i=this.comments.get(e);if(!i)return!1;const a=i.replies.find(s=>s.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(s=>s.userId===e),a=t.replies.some(s=>s.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(s=>s.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(s=>s.userId===e.mentionedUserId))))})}parseMentions(e){var s;const t=[],i=/@(\w+)/g;let a;for(;(a=i.exec(e))!==null;){const c=a[1],o=(s=this.config.availableUsers)==null?void 0:s.find(l=>l.name.toLowerCase()===c.toLowerCase()||l.id===c);o&&t.push({userId:o.id,userName:o.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 Rs(){return`comment_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}function Os(){return`reply_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}const Es={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-bg, #fce4ec)",borderColor:"var(--nice-accent-pink, #e91e63)",textColor:"#880e4f",icon:"flame"}};function Ls(r){const e=new Date(r),i=new Date().getTime()-e.getTime(),a=Math.floor(i/(1e3*60)),s=Math.floor(a/60),c=Math.floor(s/24);return a<1?"just now":a<60?`${a}m ago`:s<24?`${s}h ago`:c<7?`${c}d ago`:e.toLocaleDateString()}function Fs(r,e){if(e.length===0)return r;const t=[...e].sort((a,s)=>s.startIndex-a.startIndex);let i=r;for(const a of t){const s=i.slice(0,a.startIndex),c=i.slice(a.endIndex);i=`${s}<span class="mention" data-user-id="${a.userId}">@${a.userName}</span>${c}`}return i}class or{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,s)=>a.priority-s.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 s=a.rules.find(c=>c.id===e);s&&(Object.assign(s,t),a.rules.sort((c,o)=>c.priority-o.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 s=a.rules.filter(o=>o.enabled&&(o.target==="node"||o.target==="both")&&(!o.elementShapes||o.elementShapes.includes(e.shape))),c=this.processRules(e.id,s,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 s=a.rules.filter(o=>o.enabled&&(o.target==="edge"||o.target==="both")),c=this.processRules(e.id,s,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 s of t)if(this.evaluateCondition(s.condition,i)&&(a.matchedRules.push(s.id),this.applyActions(s.actions,a),s.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 s of i){if(a==null)return;a=a[s]}return a}compareValues(e,t){const{operator:i,value:a,valueTo:s,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 o=c&&typeof e=="string"?e.toLowerCase():e,l=c&&typeof a=="string"?a.toLowerCase():a;switch(i){case"equals":return o===l;case"not_equals":return o!==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 o=="string"&&typeof l=="string"?o.includes(l):Array.isArray(e)?e.includes(a):!1;case"not_contains":return typeof o=="string"&&typeof l=="string"?!o.includes(l):Array.isArray(e)?!e.includes(a):!0;case"starts_with":return typeof o=="string"&&typeof l=="string"&&o.startsWith(l);case"ends_with":return typeof o=="string"&&typeof l=="string"&&o.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<=s;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 Ws(r){const e=vt.find(t=>t.id===r);return e?{...e,id:`${e.id}_${Date.now()}`}:null}function Bs(r=!1){const e=new or;if(r)for(const t of vt)e.addRule(t);return e}class qs{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:s=!1,searchData:c=!0,dataProperties:o=[],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 g=[],p=s?e:e.toLowerCase();if(i==="all"||i==="nodes"||i==="labels")for(const m of this.nodes){if(g.length>=l)break;if(u.length>0&&!u.includes(m.shape)||d.length>0&&m.groupId&&!d.includes(m.groupId))continue;const h=this.matchElement(m,p,a,s,c,o);h&&g.push({id:m.id,type:"node",label:m.label||m.id,element:m,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}if(i==="all"||i==="edges"||i==="labels")for(const m of this.edges){if(g.length>=l)break;const h=this.matchElement(m,p,a,s,c,o);h&&g.push({id:m.id,type:"edge",label:m.label||`${m.sourceNodeId} → ${m.targetNodeId}`,element:m,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}if(i==="all"||i==="groups")for(const m of this.groups){if(g.length>=l)break;if(d.length>0&&!d.includes(m.id))continue;const h=this.matchElement(m,p,a,s,c,o);h&&g.push({id:m.id,type:"group",label:m.label||m.id,element:m,matchText:h.text,matchProperty:h.property,matchPositions:h.positions,score:h.score})}return g.sort((m,h)=>h.score-m.score),this.state={...this.state,query:e,results:g,selectedIndex:g.length>0?0:-1,isActive:!0,totalCount:g.length},this.notify(),g}matchElement(e,t,i,a,s,c){let o=null;const l=(d,g,p,m)=>{(!o||m>o.score)&&(o={text:d,property:g,positions:p,score:m})},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(s&&"data"in e&&e.data){const d=this.searchInData(e.data,t,i,a,c);for(const g of d)l(g.text,`data.${g.property}`,g.positions,50+g.positions.length*10)}return o}matchText(e,t,i,a){const s=a?e:e.toLowerCase(),c=a?t:t.toLowerCase(),o=[];switch(i){case"exact":s===c&&o.push({start:0,end:e.length});break;case"starts_with":s.startsWith(c)&&o.push({start:0,end:t.length});break;case"ends_with":s.endsWith(c)&&o.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&&(o.push({start:d.index,end:d.index+d[0].length}),!!u.global););}catch{}break;case"contains":default:{let l=0;for(;(l=s.indexOf(c,l))!==-1;)o.push({start:l,end:l+t.length}),l+=t.length;break}}return o.length>0?{positions:o}:null}searchInData(e,t,i,a,s,c=""){const o=[];for(const[l,u]of Object.entries(e)){const d=c?`${c}.${l}`:l;if(!(s.length>0&&!s.some(g=>d.startsWith(g))))if(typeof u=="string"){const g=this.matchText(u,t,i,a);g&&o.push({text:u,property:d,positions:g.positions})}else if(typeof u=="number"||typeof u=="boolean"){const g=String(u),p=this.matchText(g,t,i,a);p&&o.push({text:g,property:d,positions:p.positions})}else u!=null&&typeof u=="object"&&!Array.isArray(u)&&o.push(...this.searchInData(u,t,i,a,s,d))}return o}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(s=>this.matchFilters(s,e)),i=this.edges.filter(s=>this.matchFilters(s,e)),a=this.groups.filter(s=>this.matchFilters(s,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 s of i){if(a==null)return;a=a[s]}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 s=this.getPropertyValue(a,e);s!=null&&i.add(s)}if(!t||t==="edge")for(const a of this.edges){const s=this.getPropertyValue(a,e);s!=null&&i.add(s)}if(!t||t==="group")for(const a of this.groups){const s=this.getPropertyValue(a,e);s!=null&&i.add(s)}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 Gs(r,e,t="search-highlight"){if(e.length===0)return r;const i=[...e].sort((s,c)=>c.start-s.start);let a=r;for(const s of i){const c=a.slice(0,s.start),o=a.slice(s.start,s.end),l=a.slice(s.end);a=`${c}<span class="${t}">${o}</span>${l}`}return a}function Vs(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=Ze;exports.COMMENT_PRIORITY_STYLES=Es;exports.ConditionalStylingEngine=or;exports.DEFAULT_GRID_CONFIG=bs;exports.DIAGRAM_STYLE_PRESETS=Ke;exports.DIAGRAM_TEMPLATES=rt;exports.DiagramCanvas=ve;exports.DiagramCellRenderer=oa;exports.DiagramCommentManager=Ps;exports.DiagramMinimap=Qe;exports.DiagramModel=Je;exports.DiagramParticleEngine=zt;exports.DiagramPropertyPanel=et;exports.DiagramSearchFilterEngine=qs;exports.DiagramToolbar=tt;exports.DiagramVersioningManager=sr;exports.EDGE_STYLE_CATALOG=bi;exports.NODE_STYLE_CATALOG=yi;exports.NiceAnimationTimeline=Ze;exports.NiceDatabaseSchemaViewer=wa;exports.NiceDecisionTreeEditor=cs;exports.NiceDependencyGraph=Wa;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=es;exports.NiceOrgChartVisualizer=ja;exports.NiceProcessMiningDiagram=Ta;exports.NiceWorkflowVisualizer=ga;exports.PRESET_RULES=vt;exports.TRANSITION_PRESETS=Ft;exports.analyzeDependencyGraph=Ja;exports.applyAlignmentSnap=ws;exports.calculateNetworkHealth=ss;exports.calculateOrgStats=Da;exports.computeAlignmentGuides=vs;exports.computeGlowRadius=Dt;exports.computeLayout=Ot;exports.convertAnimation=Kt;exports.convertEdge=Ut;exports.convertGroup=Jt;exports.convertNode=Ht;exports.createConditionalStylingEngine=Bs;exports.createDecisionTree=ms;exports.createDiagramDocument=Ae;exports.createGlowFilterId=$t;exports.createLinearWorkflow=ba;exports.createOrgChartFromEmployees=$a;exports.createPresetFromTheme=ki;exports.createQuickFilter=Vs;exports.createRuleFromPreset=Ws;exports.createVersioningHook=Ts;exports.discoverNetworkTopology=as;exports.exportToMermaid=Tt;exports.exportToSvg=ft;exports.fetchAndGenerateDiagram=na;exports.formatCommentDate=Ls;exports.generateDiagramFromData=Xt;exports.getDiagramStylePreset=xi;exports.getDiagramStylePresetsByCategory=vi;exports.getEasing=Bt;exports.getPointOnPath=hr;exports.getTemplateById=As;exports.getTemplatesByCategory=zs;exports.highlightMatches=Gs;exports.mineProcessFromLog=Zt;exports.parseBPMNToWorkflow=ya;exports.parseNddJson=pr;exports.parsePackageJsonToDependencies=Ua;exports.parseSQLToSchema=Na;exports.parseSklearnTree=gs;exports.predictWithTree=ys;exports.presetToThemeOverrides=wi;exports.renderTextWithMentions=Fs;exports.schemaToSQL=Sa;exports.searchTemplates=$s;exports.snapNodePosition=xs;exports.snapPointToGrid=ar;exports.snapToGrid=ht;exports.stringifyNddJson=Rt;exports.useDiagramEditor=Lt;exports.useNiceTranslation=Ee;
|