@aiready/components 0.14.3 → 0.14.4

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.
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const buttonVariants: (props?: ({
6
- variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | "glow" | "glass" | "accent" | null | undefined;
6
+ variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | "glow" | "glass" | "accent" | null | undefined;
7
7
  size?: "default" | "sm" | "lg" | "icon" | "xs" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
@@ -117,10 +117,15 @@ function useForceSimulation(initialNodes, initialLinks, options) {
117
117
  try {
118
118
  seedCircularPositions(nodesCopy, width, height);
119
119
  } catch (error) {
120
- console.warn("AIReady: Position seeding failed, using random fallback:", error);
120
+ console.warn(
121
+ "AIReady: Position seeding failed, using random fallback:",
122
+ error
123
+ );
121
124
  seedRandomPositions(nodesCopy, width, height);
122
125
  }
123
- const simulation = d3.forceSimulation(nodesCopy);
126
+ const simulation = d3.forceSimulation(
127
+ nodesCopy
128
+ );
124
129
  applySimulationForces(simulation, linksCopy);
125
130
  configureSimulationParameters(simulation);
126
131
  simulationRef.current = simulation;
@@ -150,10 +155,19 @@ function useForceSimulation(initialNodes, initialLinks, options) {
150
155
  const applySimulationForces = (simulation, linksCopy) => {
151
156
  try {
152
157
  const linkForce = d3.forceLink(linksCopy).id((d) => d.id).distance((d) => d.distance ?? linkDistance).strength(linkStrength);
153
- simulation.force(FORCE_NAMES.LINK, linkForce).force(FORCE_NAMES.CHARGE, d3.forceManyBody().strength(chargeStrength)).force(FORCE_NAMES.CENTER, d3.forceCenter(width / 2, height / 2).strength(centerStrength)).force(
158
+ simulation.force(FORCE_NAMES.LINK, linkForce).force(FORCE_NAMES.CHARGE, d3.forceManyBody().strength(chargeStrength)).force(
159
+ FORCE_NAMES.CENTER,
160
+ d3.forceCenter(width / 2, height / 2).strength(centerStrength)
161
+ ).force(
154
162
  FORCE_NAMES.COLLISION,
155
163
  d3.forceCollide().radius((d) => (d.size ?? 10) + collisionRadius).strength(collisionStrength)
156
- ).force(FORCE_NAMES.X, d3.forceX(width / 2).strength(Math.max(0.02, centerStrength * 0.5))).force(FORCE_NAMES.Y, d3.forceY(height / 2).strength(Math.max(0.02, centerStrength * 0.5)));
164
+ ).force(
165
+ FORCE_NAMES.X,
166
+ d3.forceX(width / 2).strength(Math.max(0.02, centerStrength * 0.5))
167
+ ).force(
168
+ FORCE_NAMES.Y,
169
+ d3.forceY(height / 2).strength(Math.max(0.02, centerStrength * 0.5))
170
+ );
157
171
  } catch (error) {
158
172
  console.warn("AIReady: Failed to configure simulation forces:", error);
159
173
  }
@@ -167,7 +181,9 @@ function useForceSimulation(initialNodes, initialLinks, options) {
167
181
  }
168
182
  if (maxSimulationTimeMs > 0) {
169
183
  stopTimeoutRef.current = setTimeout(() => {
170
- safelyStopSimulation(simulation, nodesCopy, { stabilize: stabilizeOnStop });
184
+ safelyStopSimulation(simulation, nodesCopy, {
185
+ stabilize: stabilizeOnStop
186
+ });
171
187
  updateStateAfterStop(nodesCopy, linksCopy, 0);
172
188
  }, maxSimulationTimeMs);
173
189
  }
@@ -189,7 +205,9 @@ function useForceSimulation(initialNodes, initialLinks, options) {
189
205
  }
190
206
  const currentAlpha = simulation.alpha();
191
207
  if (currentAlpha <= alphaMin) {
192
- safelyStopSimulation(simulation, nodesCopy, { stabilize: stabilizeOnStop });
208
+ safelyStopSimulation(simulation, nodesCopy, {
209
+ stabilize: stabilizeOnStop
210
+ });
193
211
  updateStateAfterStop(nodesCopy, linksCopy, currentAlpha);
194
212
  return;
195
213
  }
@@ -241,24 +259,29 @@ function useForceSimulation(initialNodes, initialLinks, options) {
241
259
  setIsRunning(false);
242
260
  }
243
261
  }, []);
244
- const setForcesEnabled = useCallback((enabled) => {
245
- const sim = simulationRef.current;
246
- if (!sim || forcesEnabledRef.current === enabled) return;
247
- forcesEnabledRef.current = enabled;
248
- try {
249
- const charge = sim.force(FORCE_NAMES.CHARGE);
250
- if (charge) {
251
- charge.strength(enabled ? originalForcesRef.current.charge : 0);
252
- }
253
- const link = sim.force(FORCE_NAMES.LINK);
254
- if (link) {
255
- link.strength(enabled ? originalForcesRef.current.link : 0);
262
+ const setForcesEnabled = useCallback(
263
+ (enabled) => {
264
+ const sim = simulationRef.current;
265
+ if (!sim || forcesEnabledRef.current === enabled) return;
266
+ forcesEnabledRef.current = enabled;
267
+ try {
268
+ const charge = sim.force(
269
+ FORCE_NAMES.CHARGE
270
+ );
271
+ if (charge) {
272
+ charge.strength(enabled ? originalForcesRef.current.charge : 0);
273
+ }
274
+ const link = sim.force(FORCE_NAMES.LINK);
275
+ if (link) {
276
+ link.strength(enabled ? originalForcesRef.current.link : 0);
277
+ }
278
+ sim.alpha(warmAlpha).restart();
279
+ } catch (error) {
280
+ console.warn("AIReady: Failed to toggle simulation forces:", error);
256
281
  }
257
- sim.alpha(warmAlpha).restart();
258
- } catch (error) {
259
- console.warn("AIReady: Failed to toggle simulation forces:", error);
260
- }
261
- }, [warmAlpha]);
282
+ },
283
+ [warmAlpha]
284
+ );
262
285
  return {
263
286
  nodes,
264
287
  links,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/simulation-helpers.ts","../../src/hooks/simulation-constants.ts","../../src/hooks/useForceSimulation.ts"],"names":[],"mappings":";;;;;;AAMO,SAAS,eAAe,KAAA,EAA+B;AAC5D,EAAA,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,KAAM;AACnB,IAAA,CAAA,CAAE,EAAA,GAAK,CAAA;AACP,IAAA,CAAA,CAAE,EAAA,GAAK,CAAA;AACP,IAAA,IAAI,OAAO,CAAA,CAAE,CAAA,KAAM,QAAA,EAAU,CAAA,CAAE,CA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C,UAAA,EAAY;AACjB,MAAA,IAAI,CAAC,KAAA,CAAM,MAAA,EAAQ,UAAA,CAAW,YAAY,CAAC,CAAA;AAC3C,MAAA,IAAA,CAAK,EAAA,GAAK,IAAA;AACV,MAAA,IAAA,CAAK,EAAA,GAAK,IAAA;AAAA,IACZ,CAAA;AAAA,IACA,CAAC,UAAU;AAAA,GACb;AAEA,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,eAAA;AAAA,IACb,MAAA,EAAQ,aAAA;AAAA,IACR,SAAA,EAAW;AAAA,GACb;AACF","file":"useForceSimulation.js","sourcesContent":["import { SimulationNode } from './simulation-types';\n\n/**\n * Stabilizes nodes by zeroing velocities and rounding positions.\n * Extracted to reduce duplicate patterns in useForceSimulation.\n */\nexport function stabilizeNodes(nodes: SimulationNode[]): void {\n nodes.forEach((n) => {\n n.vx = 0;\n n.vy = 0;\n if (typeof n.x === 'number') n.x = Number(n.x.toFixed(3));\n if (typeof n.y === 'number') n.y = Number(n.y.toFixed(3));\n });\n}\n\n/**\n * Seeds nodes with initial positions in a spread circle.\n * This ensures nodes don't stack at origin and have some initial velocity.\n */\nexport function seedCircularPositions(\n nodes: SimulationNode[],\n width: number,\n height: number\n): void {\n const radius = Math.min(width, height) * 0.45;\n nodes.forEach((n, i) => {\n const angle = (i * 2 * Math.PI) / nodes.length;\n n.x = width / 2 + radius * Math.cos(angle);\n n.y = height / 2 + radius * Math.sin(angle);\n // Add very small random velocity to avoid large initial motion\n n.vx = (Math.random() - 0.5) * 2;\n n.vy = (Math.random() - 0.5) * 2;\n });\n}\n\n/**\n * Seeds nodes with random positions within bounds.\n * Used as fallback when initial positioning fails.\n */\nexport function seedRandomPositions(\n nodes: SimulationNode[],\n width: number,\n height: number\n): void {\n nodes.forEach((n) => {\n n.x = Math.random() * width;\n n.y = Math.random() * height;\n n.vx = (Math.random() - 0.5) * 10;\n n.vy = (Math.random() - 0.5) * 10;\n });\n}\n\n/**\n * Safely stops a d3 simulation and performs cleanup tasks.\n */\nexport function safelyStopSimulation(\n simulation: d3.Simulation<SimulationNode, any>,\n nodes: SimulationNode[],\n options: { stabilize?: boolean } = {}\n): void {\n try {\n if (options.stabilize) {\n stabilizeNodes(nodes);\n }\n simulation.stop();\n } catch (error) {\n console.warn('AIReady: Failed to stop simulation safely:', error);\n }\n}\n","/**\n * Constants for force simulation defaults and configuration\n */\nexport const SIMULATION_DEFAULTS = {\n CHARGE_STRENGTH: -300,\n LINK_DISTANCE: 100,\n LINK_STRENGTH: 1,\n COLLISION_STRENGTH: 1,\n COLLISION_RADIUS: 10,\n CENTER_STRENGTH: 0.1,\n ALPHA_DECAY: 0.0228,\n VELOCITY_DECAY: 0.4,\n ALPHA_TARGET: 0,\n WARM_ALPHA: 0.3,\n ALPHA_MIN: 0.01,\n TICK_THROTTLE_MS: 33, // ~30 fps\n MAX_SIMULATION_TIME_MS: 3000,\n STABILIZE_ON_STOP: true,\n} as const;\n\n/**\n * Force names used in d3-force\n */\nexport const FORCE_NAMES = {\n LINK: 'link',\n CHARGE: 'charge',\n CENTER: 'center',\n COLLISION: 'collision',\n X: 'x',\n Y: 'y',\n} as const;\n\n/**\n * Event names used in d3-force\n */\nexport const EVENT_NAMES = {\n TICK: 'tick',\n END: 'end',\n} as const;\n","/**\n * Hook for managing d3-force simulations\n * Automatically handles simulation lifecycle, tick updates, and cleanup\n */\n\nimport { useEffect, useRef, useState, useCallback } from 'react';\nimport * as d3 from 'd3';\nimport {\n seedRandomPositions,\n seedCircularPositions,\n safelyStopSimulation,\n} from './simulation-helpers';\nimport { SIMULATION_DEFAULTS, FORCE_NAMES, EVENT_NAMES } from './simulation-constants';\nimport type {\n SimulationNode,\n SimulationLink,\n ForceSimulationOptions,\n UseForceSimulationReturn,\n} from './simulation-types';\n\n/**\n * Enhanced return type for the force simulation hook\n */\nexport interface UseForceSimulationReturnExt extends UseForceSimulationReturn {\n /**\n * Enable or disable simulation forces (charge and link forces)\n */\n setForcesEnabled: (enabled: boolean) => void;\n}\n\n/**\n * useForceSimulation: robust d3-force management with React\n * @lastUpdated 2026-03-27\n */\nexport function useForceSimulation(\n initialNodes: SimulationNode[],\n initialLinks: SimulationLink[],\n options: ForceSimulationOptions\n): UseForceSimulationReturnExt {\n const {\n chargeStrength = SIMULATION_DEFAULTS.CHARGE_STRENGTH,\n linkDistance = SIMULATION_DEFAULTS.LINK_DISTANCE,\n linkStrength = SIMULATION_DEFAULTS.LINK_STRENGTH,\n collisionStrength = SIMULATION_DEFAULTS.COLLISION_STRENGTH,\n collisionRadius = SIMULATION_DEFAULTS.COLLISION_RADIUS,\n centerStrength = SIMULATION_DEFAULTS.CENTER_STRENGTH,\n width,\n height,\n alphaDecay = SIMULATION_DEFAULTS.ALPHA_DECAY,\n velocityDecay = SIMULATION_DEFAULTS.VELOCITY_DECAY,\n alphaTarget = SIMULATION_DEFAULTS.ALPHA_TARGET,\n warmAlpha = SIMULATION_DEFAULTS.WARM_ALPHA,\n alphaMin = SIMULATION_DEFAULTS.ALPHA_MIN,\n onTick,\n stabilizeOnStop = SIMULATION_DEFAULTS.STABILIZE_ON_STOP,\n tickThrottleMs = SIMULATION_DEFAULTS.TICK_THROTTLE_MS,\n maxSimulationTimeMs = SIMULATION_DEFAULTS.MAX_SIMULATION_TIME_MS,\n } = options;\n\n const [nodes, setNodes] = useState<SimulationNode[]>(initialNodes);\n const [links, setLinks] = useState<SimulationLink[]>(initialLinks);\n const [isRunning, setIsRunning] = useState(false);\n const [alpha, setAlpha] = useState(1);\n\n const simulationRef = useRef<d3.Simulation<SimulationNode, SimulationLink> | null>(null);\n const stopTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const forcesEnabledRef = useRef(true);\n const originalForcesRef = useRef({\n charge: chargeStrength,\n link: linkStrength,\n });\n\n // Unique keys to detect when to rebuild the simulation\n const nodesKey = initialNodes.map((n) => n.id).join('|');\n const linksKey = initialLinks\n .map((l) => {\n const sourceId = typeof l.source === 'string' ? l.source : (l.source as SimulationNode)?.id;\n const targetId = typeof l.target === 'string' ? l.target : (l.target as SimulationNode)?.id;\n const linkType = (l as any).type || '';\n return `${sourceId}->${targetId}:${linkType}`;\n })\n .join('|');\n\n /**\n * Internal effect to manage simulation lifecycle\n */\n useEffect(() => {\n const nodesCopy = initialNodes.map((node) => ({ ...node }));\n const linksCopy = initialLinks.map((link) => ({ ...link }));\n\n try {\n seedCircularPositions(nodesCopy, width, height);\n } catch (error) {\n console.warn('AIReady: Position seeding failed, using random fallback:', error);\n seedRandomPositions(nodesCopy, width, height);\n }\n\n const simulation = d3.forceSimulation<SimulationNode, SimulationLink>(nodesCopy);\n applySimulationForces(simulation, linksCopy);\n configureSimulationParameters(simulation);\n\n simulationRef.current = simulation;\n\n const rafState = { rafId: null as number | null, lastUpdate: 0 };\n setupTickHandler(simulation, nodesCopy, linksCopy, rafState);\n\n setupStopTimer(simulation, nodesCopy, linksCopy);\n\n return () => cleanupSimulation(simulation, rafState);\n }, [\n nodesKey,\n linksKey,\n chargeStrength,\n linkDistance,\n linkStrength,\n collisionStrength,\n collisionRadius,\n centerStrength,\n width,\n height,\n alphaDecay,\n velocityDecay,\n alphaTarget,\n alphaMin,\n stabilizeOnStop,\n tickThrottleMs,\n maxSimulationTimeMs,\n ]);\n\n /**\n * Applies d3 forces to the simulation instance\n */\n const applySimulationForces = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>,\n linksCopy: SimulationLink[]\n ) => {\n try {\n const linkForce = d3\n .forceLink<SimulationNode, SimulationLink>(linksCopy)\n .id((d) => d.id)\n .distance((d) => (d as any).distance ?? linkDistance)\n .strength(linkStrength);\n\n simulation\n .force(FORCE_NAMES.LINK, linkForce)\n .force(FORCE_NAMES.CHARGE, d3.forceManyBody().strength(chargeStrength))\n .force(FORCE_NAMES.CENTER, d3.forceCenter(width / 2, height / 2).strength(centerStrength))\n .force(\n FORCE_NAMES.COLLISION,\n d3.forceCollide<SimulationNode>().radius((d) => (d.size ?? 10) + collisionRadius).strength(collisionStrength)\n )\n .force(FORCE_NAMES.X, d3.forceX(width / 2).strength(Math.max(0.02, centerStrength * 0.5)))\n .force(FORCE_NAMES.Y, d3.forceY(height / 2).strength(Math.max(0.02, centerStrength * 0.5)));\n } catch (error) {\n console.warn('AIReady: Failed to configure simulation forces:', error);\n }\n };\n\n /**\n * Configures simulation decay and heat parameters\n */\n const configureSimulationParameters = (simulation: d3.Simulation<SimulationNode, SimulationLink>) => {\n simulation\n .alphaDecay(alphaDecay)\n .velocityDecay(velocityDecay)\n .alphaMin(alphaMin)\n .alphaTarget(alphaTarget)\n .alpha(warmAlpha);\n };\n\n /**\n * Sets up a timer to force-stop the simulation after maxSimulationTimeMs\n */\n const setupStopTimer = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>,\n nodesCopy: SimulationNode[],\n linksCopy: SimulationLink[]\n ) => {\n if (stopTimeoutRef.current) {\n clearTimeout(stopTimeoutRef.current);\n }\n\n if (maxSimulationTimeMs > 0) {\n stopTimeoutRef.current = setTimeout(() => {\n safelyStopSimulation(simulation, nodesCopy, { stabilize: stabilizeOnStop });\n updateStateAfterStop(nodesCopy, linksCopy, 0);\n }, maxSimulationTimeMs);\n }\n };\n\n /**\n * Updates state variables after simulation stops\n */\n const updateStateAfterStop = (\n nodesCopy: SimulationNode[],\n linksCopy: SimulationLink[],\n currentAlpha: number\n ) => {\n setIsRunning(false);\n setAlpha(currentAlpha);\n setNodes([...nodesCopy]);\n setLinks([...linksCopy]);\n };\n\n /**\n * Manages simulation ticks and React state sync\n */\n const setupTickHandler = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>,\n nodesCopy: SimulationNode[],\n linksCopy: SimulationLink[],\n rafState: { rafId: number | null; lastUpdate: number }\n ) => {\n const handleTick = () => {\n if (onTick) {\n try {\n onTick(nodesCopy, linksCopy, simulation);\n } catch (error) {\n console.warn('AIReady: Simulation onTick callback failed:', error);\n }\n }\n\n const currentAlpha = simulation.alpha();\n if (currentAlpha <= alphaMin) {\n safelyStopSimulation(simulation, nodesCopy, { stabilize: stabilizeOnStop });\n updateStateAfterStop(nodesCopy, linksCopy, currentAlpha);\n return;\n }\n\n syncStateOnTick(nodesCopy, linksCopy, currentAlpha, rafState);\n };\n\n simulation.on(EVENT_NAMES.TICK, handleTick);\n simulation.on(EVENT_NAMES.END, () => setIsRunning(false));\n };\n\n /**\n * Syncs simulation results to React state using requestAnimationFrame\n */\n const syncStateOnTick = (\n nodesCopy: SimulationNode[],\n linksCopy: SimulationLink[],\n currentAlpha: number,\n rafState: { rafId: number | null; lastUpdate: number }\n ) => {\n const now = Date.now();\n if (rafState.rafId === null && now - rafState.lastUpdate >= tickThrottleMs) {\n rafState.rafId = requestAnimationFrame(() => {\n rafState.rafId = null;\n rafState.lastUpdate = Date.now();\n setNodes([...nodesCopy]);\n setLinks([...linksCopy]);\n setAlpha(currentAlpha);\n setIsRunning(currentAlpha > alphaMin);\n });\n }\n };\n\n /**\n * Cleanup routine for simulation unmount or rebuild\n */\n const cleanupSimulation = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>,\n rafState: { rafId: number | null }\n ) => {\n simulation.on(EVENT_NAMES.TICK, null);\n if (stopTimeoutRef.current) clearTimeout(stopTimeoutRef.current);\n if (rafState.rafId !== null) cancelAnimationFrame(rafState.rafId);\n simulation.stop();\n };\n\n /**\n * Restart the simulation manually\n */\n const restartSimulation = useCallback(() => {\n const sim = simulationRef.current;\n if (!sim) return;\n\n try {\n sim.alphaTarget(warmAlpha).restart();\n setIsRunning(true);\n if (stopTimeoutRef.current) clearTimeout(stopTimeoutRef.current);\n if (maxSimulationTimeMs > 0) {\n stopTimeoutRef.current = setTimeout(() => {\n sim.alpha(0);\n sim.stop();\n setIsRunning(false);\n }, maxSimulationTimeMs);\n }\n } catch (error) {\n console.warn('AIReady: Failed to restart simulation:', error);\n }\n }, [warmAlpha, maxSimulationTimeMs]);\n\n /**\n * Stop the simulation manually\n */\n const stopSimulation = useCallback(() => {\n if (simulationRef.current) {\n simulationRef.current.stop();\n setIsRunning(false);\n }\n }, []);\n\n /**\n * Enable or disable simulation forces\n */\n const setForcesEnabled = useCallback((enabled: boolean) => {\n const sim = simulationRef.current;\n if (!sim || forcesEnabledRef.current === enabled) return;\n \n forcesEnabledRef.current = enabled;\n\n try {\n const charge = sim.force(FORCE_NAMES.CHARGE) as d3.ForceManyBody<SimulationNode> | null;\n if (charge) {\n charge.strength(enabled ? originalForcesRef.current.charge : 0);\n }\n\n const link = sim.force(FORCE_NAMES.LINK) as d3.ForceLink<SimulationNode, SimulationLink> | null;\n if (link) {\n link.strength(enabled ? originalForcesRef.current.link : 0);\n }\n \n sim.alpha(warmAlpha).restart();\n } catch (error) {\n console.warn('AIReady: Failed to toggle simulation forces:', error);\n }\n }, [warmAlpha]);\n\n return {\n nodes,\n links,\n restart: restartSimulation,\n stop: stopSimulation,\n isRunning,\n alpha,\n setForcesEnabled,\n };\n}\n\n/**\n * Hook for creating a draggable force simulation\n */\nexport function useDrag(simulation: d3.Simulation<SimulationNode, any> | null | undefined) {\n const handleDragStart = useCallback(\n (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0.3).restart();\n node.fx = node.x;\n node.fy = node.y;\n },\n [simulation]\n );\n\n const handleDragged = useCallback((event: any, node: SimulationNode) => {\n node.fx = event.x;\n node.fy = event.y;\n }, []);\n\n const handleDragEnd = useCallback(\n (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0);\n node.fx = null;\n node.fy = null;\n },\n [simulation]\n );\n\n return {\n onDragStart: handleDragStart,\n onDrag: handleDragged,\n onDragEnd: handleDragEnd,\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/hooks/simulation-helpers.ts","../../src/hooks/simulation-constants.ts","../../src/hooks/useForceSimulation.ts"],"names":[],"mappings":";;;;;;AAMO,SAAS,eAAe,KAAA,EAA+B;AAC5D,EAAA,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,KAAM;AACnB,IAAA,CAAA,CAAE,EAAA,GAAK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AAA,CAAM,CAAA;AAAA,EAClB,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,aAAA,GAAgB,WAAA;AAAA,IACpB,CAAC,OAAY,IAAA,KAAyB;AACpC,MAAA,IAAI,CAAC,UAAA,EAAY;AACjB,MAAA,IAAI,CAAC,KAAA,CAAM,MAAA,EAAQ,UAAA,CAAW,YAAY,CAAC,CAAA;AAC3C,MAAA,IAAA,CAAK,EAAA,GAAK,IAAA;AACV,MAAA,IAAA,CAAK,EAAA,GAAK,IAAA;AAAA,IACZ,CAAA;AAAA,IACA,CAAC,UAAU;AAAA,GACb;AAEA,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,eAAA;AAAA,IACb,MAAA,EAAQ,aAAA;AAAA,IACR,SAAA,EAAW;AAAA,GACb;AACF","file":"useForceSimulation.js","sourcesContent":["import { SimulationNode } from './simulation-types';\n\n/**\n * Stabilizes nodes by zeroing velocities and rounding positions.\n * Extracted to reduce duplicate patterns in useForceSimulation.\n */\nexport function stabilizeNodes(nodes: SimulationNode[]): void {\n nodes.forEach((n) => {\n n.vx = 0;\n n.vy = 0;\n if (typeof n.x === 'number') n.x = Number(n.x.toFixed(3));\n if (typeof n.y === 'number') n.y = Number(n.y.toFixed(3));\n });\n}\n\n/**\n * Seeds nodes with initial positions in a spread circle.\n * This ensures nodes don't stack at origin and have some initial velocity.\n */\nexport function seedCircularPositions(\n nodes: SimulationNode[],\n width: number,\n height: number\n): void {\n const radius = Math.min(width, height) * 0.45;\n nodes.forEach((n, i) => {\n const angle = (i * 2 * Math.PI) / nodes.length;\n n.x = width / 2 + radius * Math.cos(angle);\n n.y = height / 2 + radius * Math.sin(angle);\n // Add very small random velocity to avoid large initial motion\n n.vx = (Math.random() - 0.5) * 2;\n n.vy = (Math.random() - 0.5) * 2;\n });\n}\n\n/**\n * Seeds nodes with random positions within bounds.\n * Used as fallback when initial positioning fails.\n */\nexport function seedRandomPositions(\n nodes: SimulationNode[],\n width: number,\n height: number\n): void {\n nodes.forEach((n) => {\n n.x = Math.random() * width;\n n.y = Math.random() * height;\n n.vx = (Math.random() - 0.5) * 10;\n n.vy = (Math.random() - 0.5) * 10;\n });\n}\n\n/**\n * Safely stops a d3 simulation and performs cleanup tasks.\n */\nexport function safelyStopSimulation(\n simulation: d3.Simulation<SimulationNode, any>,\n nodes: SimulationNode[],\n options: { stabilize?: boolean } = {}\n): void {\n try {\n if (options.stabilize) {\n stabilizeNodes(nodes);\n }\n simulation.stop();\n } catch (error) {\n console.warn('AIReady: Failed to stop simulation safely:', error);\n }\n}\n","/**\n * Constants for force simulation defaults and configuration\n */\nexport const SIMULATION_DEFAULTS = {\n CHARGE_STRENGTH: -300,\n LINK_DISTANCE: 100,\n LINK_STRENGTH: 1,\n COLLISION_STRENGTH: 1,\n COLLISION_RADIUS: 10,\n CENTER_STRENGTH: 0.1,\n ALPHA_DECAY: 0.0228,\n VELOCITY_DECAY: 0.4,\n ALPHA_TARGET: 0,\n WARM_ALPHA: 0.3,\n ALPHA_MIN: 0.01,\n TICK_THROTTLE_MS: 33, // ~30 fps\n MAX_SIMULATION_TIME_MS: 3000,\n STABILIZE_ON_STOP: true,\n} as const;\n\n/**\n * Force names used in d3-force\n */\nexport const FORCE_NAMES = {\n LINK: 'link',\n CHARGE: 'charge',\n CENTER: 'center',\n COLLISION: 'collision',\n X: 'x',\n Y: 'y',\n} as const;\n\n/**\n * Event names used in d3-force\n */\nexport const EVENT_NAMES = {\n TICK: 'tick',\n END: 'end',\n} as const;\n","/**\n * Hook for managing d3-force simulations\n * Automatically handles simulation lifecycle, tick updates, and cleanup\n */\n\nimport { useEffect, useRef, useState, useCallback } from 'react';\nimport * as d3 from 'd3';\nimport {\n seedRandomPositions,\n seedCircularPositions,\n safelyStopSimulation,\n} from './simulation-helpers';\nimport {\n SIMULATION_DEFAULTS,\n FORCE_NAMES,\n EVENT_NAMES,\n} from './simulation-constants';\nimport type {\n SimulationNode,\n SimulationLink,\n ForceSimulationOptions,\n UseForceSimulationReturn,\n} from './simulation-types';\n\n/**\n * Enhanced return type for the force simulation hook\n */\nexport interface UseForceSimulationReturnExt extends UseForceSimulationReturn {\n /**\n * Enable or disable simulation forces (charge and link forces)\n */\n setForcesEnabled: (enabled: boolean) => void;\n}\n\n/**\n * useForceSimulation: robust d3-force management with React\n * @lastUpdated 2026-03-27\n */\nexport function useForceSimulation(\n initialNodes: SimulationNode[],\n initialLinks: SimulationLink[],\n options: ForceSimulationOptions\n): UseForceSimulationReturnExt {\n const {\n chargeStrength = SIMULATION_DEFAULTS.CHARGE_STRENGTH,\n linkDistance = SIMULATION_DEFAULTS.LINK_DISTANCE,\n linkStrength = SIMULATION_DEFAULTS.LINK_STRENGTH,\n collisionStrength = SIMULATION_DEFAULTS.COLLISION_STRENGTH,\n collisionRadius = SIMULATION_DEFAULTS.COLLISION_RADIUS,\n centerStrength = SIMULATION_DEFAULTS.CENTER_STRENGTH,\n width,\n height,\n alphaDecay = SIMULATION_DEFAULTS.ALPHA_DECAY,\n velocityDecay = SIMULATION_DEFAULTS.VELOCITY_DECAY,\n alphaTarget = SIMULATION_DEFAULTS.ALPHA_TARGET,\n warmAlpha = SIMULATION_DEFAULTS.WARM_ALPHA,\n alphaMin = SIMULATION_DEFAULTS.ALPHA_MIN,\n onTick,\n stabilizeOnStop = SIMULATION_DEFAULTS.STABILIZE_ON_STOP,\n tickThrottleMs = SIMULATION_DEFAULTS.TICK_THROTTLE_MS,\n maxSimulationTimeMs = SIMULATION_DEFAULTS.MAX_SIMULATION_TIME_MS,\n } = options;\n\n const [nodes, setNodes] = useState<SimulationNode[]>(initialNodes);\n const [links, setLinks] = useState<SimulationLink[]>(initialLinks);\n const [isRunning, setIsRunning] = useState(false);\n const [alpha, setAlpha] = useState(1);\n\n const simulationRef = useRef<d3.Simulation<\n SimulationNode,\n SimulationLink\n > | null>(null);\n const stopTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const forcesEnabledRef = useRef(true);\n const originalForcesRef = useRef({\n charge: chargeStrength,\n link: linkStrength,\n });\n\n // Unique keys to detect when to rebuild the simulation\n const nodesKey = initialNodes.map((n) => n.id).join('|');\n const linksKey = initialLinks\n .map((l) => {\n const sourceId =\n typeof l.source === 'string'\n ? l.source\n : (l.source as SimulationNode)?.id;\n const targetId =\n typeof l.target === 'string'\n ? l.target\n : (l.target as SimulationNode)?.id;\n const linkType = (l as any).type || '';\n return `${sourceId}->${targetId}:${linkType}`;\n })\n .join('|');\n\n /**\n * Internal effect to manage simulation lifecycle\n */\n useEffect(() => {\n const nodesCopy = initialNodes.map((node) => ({ ...node }));\n const linksCopy = initialLinks.map((link) => ({ ...link }));\n\n try {\n seedCircularPositions(nodesCopy, width, height);\n } catch (error) {\n console.warn(\n 'AIReady: Position seeding failed, using random fallback:',\n error\n );\n seedRandomPositions(nodesCopy, width, height);\n }\n\n const simulation = d3.forceSimulation<SimulationNode, SimulationLink>(\n nodesCopy\n );\n applySimulationForces(simulation, linksCopy);\n configureSimulationParameters(simulation);\n\n simulationRef.current = simulation;\n\n const rafState = { rafId: null as number | null, lastUpdate: 0 };\n setupTickHandler(simulation, nodesCopy, linksCopy, rafState);\n\n setupStopTimer(simulation, nodesCopy, linksCopy);\n\n return () => cleanupSimulation(simulation, rafState);\n }, [\n nodesKey,\n linksKey,\n chargeStrength,\n linkDistance,\n linkStrength,\n collisionStrength,\n collisionRadius,\n centerStrength,\n width,\n height,\n alphaDecay,\n velocityDecay,\n alphaTarget,\n alphaMin,\n stabilizeOnStop,\n tickThrottleMs,\n maxSimulationTimeMs,\n ]);\n\n /**\n * Applies d3 forces to the simulation instance\n */\n const applySimulationForces = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>,\n linksCopy: SimulationLink[]\n ) => {\n try {\n const linkForce = d3\n .forceLink<SimulationNode, SimulationLink>(linksCopy)\n .id((d) => d.id)\n .distance((d) => (d as any).distance ?? linkDistance)\n .strength(linkStrength);\n\n simulation\n .force(FORCE_NAMES.LINK, linkForce)\n .force(FORCE_NAMES.CHARGE, d3.forceManyBody().strength(chargeStrength))\n .force(\n FORCE_NAMES.CENTER,\n d3.forceCenter(width / 2, height / 2).strength(centerStrength)\n )\n .force(\n FORCE_NAMES.COLLISION,\n d3\n .forceCollide<SimulationNode>()\n .radius((d) => (d.size ?? 10) + collisionRadius)\n .strength(collisionStrength)\n )\n .force(\n FORCE_NAMES.X,\n d3.forceX(width / 2).strength(Math.max(0.02, centerStrength * 0.5))\n )\n .force(\n FORCE_NAMES.Y,\n d3.forceY(height / 2).strength(Math.max(0.02, centerStrength * 0.5))\n );\n } catch (error) {\n console.warn('AIReady: Failed to configure simulation forces:', error);\n }\n };\n\n /**\n * Configures simulation decay and heat parameters\n */\n const configureSimulationParameters = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>\n ) => {\n simulation\n .alphaDecay(alphaDecay)\n .velocityDecay(velocityDecay)\n .alphaMin(alphaMin)\n .alphaTarget(alphaTarget)\n .alpha(warmAlpha);\n };\n\n /**\n * Sets up a timer to force-stop the simulation after maxSimulationTimeMs\n */\n const setupStopTimer = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>,\n nodesCopy: SimulationNode[],\n linksCopy: SimulationLink[]\n ) => {\n if (stopTimeoutRef.current) {\n clearTimeout(stopTimeoutRef.current);\n }\n\n if (maxSimulationTimeMs > 0) {\n stopTimeoutRef.current = setTimeout(() => {\n safelyStopSimulation(simulation, nodesCopy, {\n stabilize: stabilizeOnStop,\n });\n updateStateAfterStop(nodesCopy, linksCopy, 0);\n }, maxSimulationTimeMs);\n }\n };\n\n /**\n * Updates state variables after simulation stops\n */\n const updateStateAfterStop = (\n nodesCopy: SimulationNode[],\n linksCopy: SimulationLink[],\n currentAlpha: number\n ) => {\n setIsRunning(false);\n setAlpha(currentAlpha);\n setNodes([...nodesCopy]);\n setLinks([...linksCopy]);\n };\n\n /**\n * Manages simulation ticks and React state sync\n */\n const setupTickHandler = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>,\n nodesCopy: SimulationNode[],\n linksCopy: SimulationLink[],\n rafState: { rafId: number | null; lastUpdate: number }\n ) => {\n const handleTick = () => {\n if (onTick) {\n try {\n onTick(nodesCopy, linksCopy, simulation);\n } catch (error) {\n console.warn('AIReady: Simulation onTick callback failed:', error);\n }\n }\n\n const currentAlpha = simulation.alpha();\n if (currentAlpha <= alphaMin) {\n safelyStopSimulation(simulation, nodesCopy, {\n stabilize: stabilizeOnStop,\n });\n updateStateAfterStop(nodesCopy, linksCopy, currentAlpha);\n return;\n }\n\n syncStateOnTick(nodesCopy, linksCopy, currentAlpha, rafState);\n };\n\n simulation.on(EVENT_NAMES.TICK, handleTick);\n simulation.on(EVENT_NAMES.END, () => setIsRunning(false));\n };\n\n /**\n * Syncs simulation results to React state using requestAnimationFrame\n */\n const syncStateOnTick = (\n nodesCopy: SimulationNode[],\n linksCopy: SimulationLink[],\n currentAlpha: number,\n rafState: { rafId: number | null; lastUpdate: number }\n ) => {\n const now = Date.now();\n if (\n rafState.rafId === null &&\n now - rafState.lastUpdate >= tickThrottleMs\n ) {\n rafState.rafId = requestAnimationFrame(() => {\n rafState.rafId = null;\n rafState.lastUpdate = Date.now();\n setNodes([...nodesCopy]);\n setLinks([...linksCopy]);\n setAlpha(currentAlpha);\n setIsRunning(currentAlpha > alphaMin);\n });\n }\n };\n\n /**\n * Cleanup routine for simulation unmount or rebuild\n */\n const cleanupSimulation = (\n simulation: d3.Simulation<SimulationNode, SimulationLink>,\n rafState: { rafId: number | null }\n ) => {\n simulation.on(EVENT_NAMES.TICK, null);\n if (stopTimeoutRef.current) clearTimeout(stopTimeoutRef.current);\n if (rafState.rafId !== null) cancelAnimationFrame(rafState.rafId);\n simulation.stop();\n };\n\n /**\n * Restart the simulation manually\n */\n const restartSimulation = useCallback(() => {\n const sim = simulationRef.current;\n if (!sim) return;\n\n try {\n sim.alphaTarget(warmAlpha).restart();\n setIsRunning(true);\n if (stopTimeoutRef.current) clearTimeout(stopTimeoutRef.current);\n if (maxSimulationTimeMs > 0) {\n stopTimeoutRef.current = setTimeout(() => {\n sim.alpha(0);\n sim.stop();\n setIsRunning(false);\n }, maxSimulationTimeMs);\n }\n } catch (error) {\n console.warn('AIReady: Failed to restart simulation:', error);\n }\n }, [warmAlpha, maxSimulationTimeMs]);\n\n /**\n * Stop the simulation manually\n */\n const stopSimulation = useCallback(() => {\n if (simulationRef.current) {\n simulationRef.current.stop();\n setIsRunning(false);\n }\n }, []);\n\n /**\n * Enable or disable simulation forces\n */\n const setForcesEnabled = useCallback(\n (enabled: boolean) => {\n const sim = simulationRef.current;\n if (!sim || forcesEnabledRef.current === enabled) return;\n\n forcesEnabledRef.current = enabled;\n\n try {\n const charge = sim.force(\n FORCE_NAMES.CHARGE\n ) as d3.ForceManyBody<SimulationNode> | null;\n if (charge) {\n charge.strength(enabled ? originalForcesRef.current.charge : 0);\n }\n\n const link = sim.force(FORCE_NAMES.LINK) as d3.ForceLink<\n SimulationNode,\n SimulationLink\n > | null;\n if (link) {\n link.strength(enabled ? originalForcesRef.current.link : 0);\n }\n\n sim.alpha(warmAlpha).restart();\n } catch (error) {\n console.warn('AIReady: Failed to toggle simulation forces:', error);\n }\n },\n [warmAlpha]\n );\n\n return {\n nodes,\n links,\n restart: restartSimulation,\n stop: stopSimulation,\n isRunning,\n alpha,\n setForcesEnabled,\n };\n}\n\n/**\n * Hook for creating a draggable force simulation\n */\nexport function useDrag(\n simulation: d3.Simulation<SimulationNode, any> | null | undefined\n) {\n const handleDragStart = useCallback(\n (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0.3).restart();\n node.fx = node.x;\n node.fy = node.y;\n },\n [simulation]\n );\n\n const handleDragged = useCallback((event: any, node: SimulationNode) => {\n node.fx = event.x;\n node.fy = event.y;\n }, []);\n\n const handleDragEnd = useCallback(\n (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0);\n node.fx = null;\n node.fy = null;\n },\n [simulation]\n );\n\n return {\n onDragStart: handleDragStart,\n onDrag: handleDragged,\n onDragEnd: handleDragEnd,\n };\n}\n"]}
package/dist/index.js CHANGED
@@ -2165,10 +2165,15 @@ function useForceSimulation(initialNodes, initialLinks, options) {
2165
2165
  try {
2166
2166
  seedCircularPositions(nodesCopy, width, height);
2167
2167
  } catch (error) {
2168
- console.warn("AIReady: Position seeding failed, using random fallback:", error);
2168
+ console.warn(
2169
+ "AIReady: Position seeding failed, using random fallback:",
2170
+ error
2171
+ );
2169
2172
  seedRandomPositions(nodesCopy, width, height);
2170
2173
  }
2171
- const simulation = d32.forceSimulation(nodesCopy);
2174
+ const simulation = d32.forceSimulation(
2175
+ nodesCopy
2176
+ );
2172
2177
  applySimulationForces(simulation, linksCopy);
2173
2178
  configureSimulationParameters(simulation);
2174
2179
  simulationRef.current = simulation;
@@ -2198,10 +2203,19 @@ function useForceSimulation(initialNodes, initialLinks, options) {
2198
2203
  const applySimulationForces = (simulation, linksCopy) => {
2199
2204
  try {
2200
2205
  const linkForce = d32.forceLink(linksCopy).id((d) => d.id).distance((d) => d.distance ?? linkDistance).strength(linkStrength);
2201
- simulation.force(FORCE_NAMES.LINK, linkForce).force(FORCE_NAMES.CHARGE, d32.forceManyBody().strength(chargeStrength)).force(FORCE_NAMES.CENTER, d32.forceCenter(width / 2, height / 2).strength(centerStrength)).force(
2206
+ simulation.force(FORCE_NAMES.LINK, linkForce).force(FORCE_NAMES.CHARGE, d32.forceManyBody().strength(chargeStrength)).force(
2207
+ FORCE_NAMES.CENTER,
2208
+ d32.forceCenter(width / 2, height / 2).strength(centerStrength)
2209
+ ).force(
2202
2210
  FORCE_NAMES.COLLISION,
2203
2211
  d32.forceCollide().radius((d) => (d.size ?? 10) + collisionRadius).strength(collisionStrength)
2204
- ).force(FORCE_NAMES.X, d32.forceX(width / 2).strength(Math.max(0.02, centerStrength * 0.5))).force(FORCE_NAMES.Y, d32.forceY(height / 2).strength(Math.max(0.02, centerStrength * 0.5)));
2212
+ ).force(
2213
+ FORCE_NAMES.X,
2214
+ d32.forceX(width / 2).strength(Math.max(0.02, centerStrength * 0.5))
2215
+ ).force(
2216
+ FORCE_NAMES.Y,
2217
+ d32.forceY(height / 2).strength(Math.max(0.02, centerStrength * 0.5))
2218
+ );
2205
2219
  } catch (error) {
2206
2220
  console.warn("AIReady: Failed to configure simulation forces:", error);
2207
2221
  }
@@ -2215,7 +2229,9 @@ function useForceSimulation(initialNodes, initialLinks, options) {
2215
2229
  }
2216
2230
  if (maxSimulationTimeMs > 0) {
2217
2231
  stopTimeoutRef.current = setTimeout(() => {
2218
- safelyStopSimulation(simulation, nodesCopy, { stabilize: stabilizeOnStop });
2232
+ safelyStopSimulation(simulation, nodesCopy, {
2233
+ stabilize: stabilizeOnStop
2234
+ });
2219
2235
  updateStateAfterStop(nodesCopy, linksCopy, 0);
2220
2236
  }, maxSimulationTimeMs);
2221
2237
  }
@@ -2237,7 +2253,9 @@ function useForceSimulation(initialNodes, initialLinks, options) {
2237
2253
  }
2238
2254
  const currentAlpha = simulation.alpha();
2239
2255
  if (currentAlpha <= alphaMin) {
2240
- safelyStopSimulation(simulation, nodesCopy, { stabilize: stabilizeOnStop });
2256
+ safelyStopSimulation(simulation, nodesCopy, {
2257
+ stabilize: stabilizeOnStop
2258
+ });
2241
2259
  updateStateAfterStop(nodesCopy, linksCopy, currentAlpha);
2242
2260
  return;
2243
2261
  }
@@ -2289,24 +2307,29 @@ function useForceSimulation(initialNodes, initialLinks, options) {
2289
2307
  setIsRunning(false);
2290
2308
  }
2291
2309
  }, []);
2292
- const setForcesEnabled = useCallback((enabled) => {
2293
- const sim = simulationRef.current;
2294
- if (!sim || forcesEnabledRef.current === enabled) return;
2295
- forcesEnabledRef.current = enabled;
2296
- try {
2297
- const charge = sim.force(FORCE_NAMES.CHARGE);
2298
- if (charge) {
2299
- charge.strength(enabled ? originalForcesRef.current.charge : 0);
2300
- }
2301
- const link = sim.force(FORCE_NAMES.LINK);
2302
- if (link) {
2303
- link.strength(enabled ? originalForcesRef.current.link : 0);
2310
+ const setForcesEnabled = useCallback(
2311
+ (enabled) => {
2312
+ const sim = simulationRef.current;
2313
+ if (!sim || forcesEnabledRef.current === enabled) return;
2314
+ forcesEnabledRef.current = enabled;
2315
+ try {
2316
+ const charge = sim.force(
2317
+ FORCE_NAMES.CHARGE
2318
+ );
2319
+ if (charge) {
2320
+ charge.strength(enabled ? originalForcesRef.current.charge : 0);
2321
+ }
2322
+ const link = sim.force(FORCE_NAMES.LINK);
2323
+ if (link) {
2324
+ link.strength(enabled ? originalForcesRef.current.link : 0);
2325
+ }
2326
+ sim.alpha(warmAlpha).restart();
2327
+ } catch (error) {
2328
+ console.warn("AIReady: Failed to toggle simulation forces:", error);
2304
2329
  }
2305
- sim.alpha(warmAlpha).restart();
2306
- } catch (error) {
2307
- console.warn("AIReady: Failed to toggle simulation forces:", error);
2308
- }
2309
- }, [warmAlpha]);
2330
+ },
2331
+ [warmAlpha]
2332
+ );
2310
2333
  return {
2311
2334
  nodes,
2312
2335
  links,