@aiready/components 0.13.19 → 0.13.21

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.
@@ -0,0 +1,49 @@
1
+ import * as d3 from 'd3';
2
+
3
+ interface SimulationNode extends d3.SimulationNodeDatum {
4
+ id: string;
5
+ [key: string]: any;
6
+ }
7
+ interface SimulationLink extends d3.SimulationLinkDatum<SimulationNode> {
8
+ source: string | SimulationNode;
9
+ target: string | SimulationNode;
10
+ [key: string]: any;
11
+ }
12
+ interface ForceSimulationOptions {
13
+ chargeStrength?: number;
14
+ linkDistance?: number;
15
+ linkStrength?: number;
16
+ collisionStrength?: number;
17
+ collisionRadius?: number;
18
+ centerStrength?: number;
19
+ width: number;
20
+ height: number;
21
+ alphaDecay?: number;
22
+ alphaTarget?: number;
23
+ warmAlpha?: number;
24
+ alphaMin?: number;
25
+ stabilizeOnStop?: boolean;
26
+ tickThrottleMs?: number;
27
+ maxSimulationTimeMs?: number;
28
+ velocityDecay?: number;
29
+ onTick?: (nodes: SimulationNode[], links: SimulationLink[], sim: d3.Simulation<SimulationNode, SimulationLink>) => void;
30
+ }
31
+ interface UseForceSimulationReturn {
32
+ nodes: SimulationNode[];
33
+ links: SimulationLink[];
34
+ restart: () => void;
35
+ stop: () => void;
36
+ isRunning: boolean;
37
+ alpha: number;
38
+ }
39
+
40
+ declare function useForceSimulation(initialNodes: SimulationNode[], initialLinks: SimulationLink[], options: ForceSimulationOptions): UseForceSimulationReturn & {
41
+ setForcesEnabled: (enabled: boolean) => void;
42
+ };
43
+ declare function useDrag(simulation: d3.Simulation<SimulationNode, any> | null | undefined): {
44
+ onDragStart: (event: any, node: SimulationNode) => void;
45
+ onDrag: (event: any, node: SimulationNode) => void;
46
+ onDragEnd: (event: any, node: SimulationNode) => void;
47
+ };
48
+
49
+ export { type ForceSimulationOptions as F, type SimulationLink as S, type UseForceSimulationReturn as U, type SimulationNode as a, useForceSimulation as b, useDrag as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/components",
3
- "version": "0.13.19",
3
+ "version": "0.13.21",
4
4
  "description": "Unified shared components library (UI, charts, hooks, utilities) for AIReady",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -91,8 +91,8 @@
91
91
  "import": "./dist/hooks/useForceSimulation.js"
92
92
  },
93
93
  "./charts/ForceDirectedGraph": {
94
- "types": "./dist/charts/ForceDirectedGraph.d.ts",
95
- "import": "./dist/charts/ForceDirectedGraph.js"
94
+ "types": "./dist/charts/ForceDirectedGraph/index.d.ts",
95
+ "import": "./dist/charts/ForceDirectedGraph/index.js"
96
96
  },
97
97
  "./tailwind-config": "./tailwind.config.js"
98
98
  },
@@ -128,7 +128,7 @@
128
128
  "framer-motion": "^12.35.0",
129
129
  "lucide-react": "^0.577.0",
130
130
  "tailwind-merge": "^3.0.0",
131
- "@aiready/core": "0.23.20"
131
+ "@aiready/core": "0.23.22"
132
132
  },
133
133
  "devDependencies": {
134
134
  "@testing-library/jest-dom": "^6.6.5",
@@ -6,7 +6,7 @@ export {
6
6
  type GraphNode,
7
7
  type GraphLink,
8
8
  type LayoutType,
9
- } from './force-directed';
9
+ } from '../force-directed';
10
10
 
11
11
  // Default export for backward compatibility
12
- export { ForceDirectedGraph as default } from './force-directed';
12
+ export { ForceDirectedGraph as default } from '../force-directed';
@@ -1,11 +1,3 @@
1
- // Re-export types from separate module for backward compatibility
2
- export {
3
- type SimulationNode,
4
- type SimulationLink,
5
- type ForceSimulationOptions,
6
- type UseForceSimulationReturn,
7
- } from './simulation-types';
8
-
9
1
  // Import helpers from separate module
10
2
  import { stabilizeNodes, seedRandomPositions } from './simulation-helpers';
11
3
  import type {
package/src/index.ts CHANGED
@@ -96,14 +96,13 @@ export * from './utils/score';
96
96
  // Hooks
97
97
  export { useDebounce } from './hooks/useDebounce';
98
98
  export { useD3, useD3WithResize } from './hooks/useD3';
99
+ export { useForceSimulation, useDrag } from './hooks/useForceSimulation';
99
100
  export {
100
- useForceSimulation,
101
- useDrag,
102
101
  type SimulationNode,
103
102
  type SimulationLink,
104
103
  type ForceSimulationOptions,
105
104
  type UseForceSimulationReturn,
106
- } from './hooks/useForceSimulation';
105
+ } from './hooks/simulation-types';
107
106
 
108
107
  // Charts
109
108
  export {
@@ -1,28 +1,49 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { scoreColor, scoreBg, scoreLabel, getScoreRating } from '../score';
2
+ import {
3
+ scoreColor,
4
+ scoreBg,
5
+ scoreLabel,
6
+ getScoreRating,
7
+ scoreGlow,
8
+ } from '../score';
3
9
 
4
10
  describe('Score Utilities', () => {
5
11
  it('should return correct color for scores', () => {
12
+ expect(scoreColor(95)).toBe('text-emerald-400');
6
13
  expect(scoreColor(80)).toBe('text-emerald-400');
7
- expect(scoreColor(60)).toBe('text-amber-400');
8
- expect(scoreColor(30)).toBe('text-red-400');
14
+ expect(scoreColor(65)).toBe('text-amber-400');
15
+ expect(scoreColor(45)).toBe('text-red-400');
16
+ expect(scoreColor(20)).toBe('text-red-400');
9
17
  expect(scoreColor(null)).toBe('text-slate-400');
10
18
  });
11
19
 
12
20
  it('should return correct background for scores', () => {
21
+ expect(scoreBg(95)).toContain('emerald');
13
22
  expect(scoreBg(80)).toContain('emerald');
14
- expect(scoreBg(60)).toContain('amber');
15
- expect(scoreBg(30)).toContain('red');
23
+ expect(scoreBg(65)).toContain('amber');
24
+ expect(scoreBg(45)).toContain('red');
25
+ expect(scoreBg(20)).toContain('red');
16
26
  expect(scoreBg(null)).toContain('slate');
17
27
  });
18
28
 
19
29
  it('should return correct labels', () => {
30
+ expect(scoreLabel(95)).toBe('Excellent');
20
31
  expect(scoreLabel(80)).toBe('AI-Ready');
21
- expect(scoreLabel(60)).toBe('Fair');
22
- expect(scoreLabel(30)).toBe('Critical Issues');
32
+ expect(scoreLabel(65)).toBe('Fair');
33
+ expect(scoreLabel(45)).toBe('Needs Improvement');
34
+ expect(scoreLabel(20)).toBe('Critical Issues');
23
35
  expect(scoreLabel(null)).toBe('Not analyzed');
24
36
  });
25
37
 
38
+ it('should return correct glow for scores', () => {
39
+ expect(scoreGlow(95)).toContain('emerald');
40
+ expect(scoreGlow(80)).toContain('emerald');
41
+ expect(scoreGlow(65)).toContain('amber');
42
+ expect(scoreGlow(45)).toContain('red');
43
+ expect(scoreGlow(20)).toContain('red');
44
+ expect(scoreGlow(null)).toBe('');
45
+ });
46
+
26
47
  it('should return correct rating strings', () => {
27
48
  expect(getScoreRating(95)).toBe('excellent');
28
49
  expect(getScoreRating(80)).toBe('good');
@@ -1,82 +1,95 @@
1
1
  import { getRatingSlug } from '@aiready/core/client';
2
2
 
3
+ type RatingSlug = 'excellent' | 'good' | 'fair' | 'needs-work' | 'critical';
4
+
5
+ interface ScoreMetadata {
6
+ color: string;
7
+ bg: string;
8
+ label: string;
9
+ glow: string;
10
+ }
11
+
12
+ const SCORE_METADATA: Record<RatingSlug, ScoreMetadata> = {
13
+ excellent: {
14
+ color: 'text-emerald-400',
15
+ bg: 'bg-emerald-900/30 border-emerald-500/30',
16
+ label: 'Excellent',
17
+ glow: 'shadow-emerald-500/20',
18
+ },
19
+ good: {
20
+ color: 'text-emerald-400',
21
+ bg: 'bg-emerald-900/30 border-emerald-500/30',
22
+ label: 'AI-Ready',
23
+ glow: 'shadow-emerald-500/20',
24
+ },
25
+ fair: {
26
+ color: 'text-amber-400',
27
+ bg: 'bg-amber-900/30 border-amber-500/30',
28
+ label: 'Fair',
29
+ glow: 'shadow-amber-500/20',
30
+ },
31
+ 'needs-work': {
32
+ color: 'text-red-400',
33
+ bg: 'bg-red-900/30 border-red-500/30',
34
+ label: 'Needs Improvement',
35
+ glow: 'shadow-red-500/20',
36
+ },
37
+ critical: {
38
+ color: 'text-red-400',
39
+ bg: 'bg-red-900/30 border-red-500/30',
40
+ label: 'Critical Issues',
41
+ glow: 'shadow-red-500/20',
42
+ },
43
+ };
44
+
45
+ const DEFAULT_METADATA: ScoreMetadata = {
46
+ color: 'text-slate-400',
47
+ bg: 'bg-slate-800/50 border-slate-700',
48
+ label: 'Not analyzed',
49
+ glow: '',
50
+ };
51
+
52
+ /**
53
+ * Get the metadata for a score using core rating system
54
+ */
55
+ function getMetadata(score: number | null | undefined): ScoreMetadata {
56
+ if (score == null) return DEFAULT_METADATA;
57
+ const rating = getRatingSlug(score) as RatingSlug;
58
+ return SCORE_METADATA[rating] || SCORE_METADATA.critical;
59
+ }
60
+
3
61
  /**
4
62
  * Get the Tailwind color class for a score using core rating system
5
63
  */
6
64
  export function scoreColor(score: number | null | undefined): string {
7
- if (score == null) return 'text-slate-400';
8
- const rating = getRatingSlug(score);
9
- switch (rating) {
10
- case 'excellent':
11
- case 'good':
12
- return 'text-emerald-400';
13
- case 'fair':
14
- return 'text-amber-400';
15
- default:
16
- return 'text-red-400';
17
- }
65
+ return getMetadata(score).color;
18
66
  }
19
67
 
20
68
  /**
21
69
  * Get the Tailwind background/border class for a score using core rating system
22
70
  */
23
71
  export function scoreBg(score: number | null | undefined): string {
24
- if (score == null) return 'bg-slate-800/50 border-slate-700';
25
- const rating = getRatingSlug(score);
26
- switch (rating) {
27
- case 'excellent':
28
- case 'good':
29
- return 'bg-emerald-900/30 border-emerald-500/30';
30
- case 'fair':
31
- return 'bg-amber-900/30 border-amber-500/30';
32
- default:
33
- return 'bg-red-900/30 border-red-500/30';
34
- }
72
+ return getMetadata(score).bg;
35
73
  }
36
74
 
37
75
  /**
38
76
  * Get the display label for a score using core rating system
39
77
  */
40
78
  export function scoreLabel(score: number | null | undefined): string {
41
- if (score == null) return 'Not analyzed';
42
- const rating = getRatingSlug(score);
43
- switch (rating) {
44
- case 'excellent':
45
- return 'Excellent';
46
- case 'good':
47
- return 'AI-Ready';
48
- case 'fair':
49
- return 'Fair';
50
- case 'needs-work':
51
- return 'Needs Improvement';
52
- default:
53
- return 'Critical Issues';
54
- }
79
+ return getMetadata(score).label;
55
80
  }
56
81
 
57
82
  /**
58
83
  * Get the Tailwind shadow glow class for a score using core rating system
59
84
  */
60
85
  export function scoreGlow(score: number | null | undefined): string {
61
- if (score == null) return '';
62
- const rating = getRatingSlug(score);
63
- switch (rating) {
64
- case 'excellent':
65
- case 'good':
66
- return 'shadow-emerald-500/20';
67
- case 'fair':
68
- return 'shadow-amber-500/20';
69
- default:
70
- return 'shadow-red-500/20';
71
- }
86
+ return getMetadata(score).glow;
72
87
  }
73
88
 
74
89
  /**
75
90
  * Get rating from score (for use with ScoreBar component)
76
91
  */
77
- export function getScoreRating(
78
- score: number | null | undefined
79
- ): 'excellent' | 'good' | 'fair' | 'needs-work' | 'critical' {
92
+ export function getScoreRating(score: number | null | undefined): RatingSlug {
80
93
  if (score == null) return 'critical';
81
- return getRatingSlug(score) as any;
94
+ return getRatingSlug(score) as RatingSlug;
82
95
  }
@@ -1,3 +0,0 @@
1
- import * as AllIcons from './icons/index';
2
- export * from './icons/index';
3
- export default AllIcons.default;