@aiready/components 0.14.3 → 0.14.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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,