react-d3-cloud-modern 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +307 -0
- package/README.md +69 -17
- package/package.json +2 -2
package/AGENTS.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# AGENTS.md - LLM Developer Reference
|
|
2
|
+
|
|
3
|
+
This document provides context and guidelines for AI agents working on the `react-d3-cloud-modern` project.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
**Package Name:** `react-d3-cloud-modern`
|
|
8
|
+
**Current Version:** 1.0.8
|
|
9
|
+
**Type:** React component library
|
|
10
|
+
**Purpose:** A modern, security-focused word cloud component for React applications
|
|
11
|
+
|
|
12
|
+
This is a maintained fork of [Yoctol/react-d3-cloud](https://github.com/Yoctol/react-d3-cloud) with the primary goals of:
|
|
13
|
+
1. Addressing security vulnerabilities in dependencies
|
|
14
|
+
2. Providing React 19 compatibility
|
|
15
|
+
3. Maintaining modern TypeScript standards
|
|
16
|
+
|
|
17
|
+
## Project Structure
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
react-d3-cloud-modern/
|
|
21
|
+
├── src/
|
|
22
|
+
│ ├── index.ts # Main entry point, exports WordCloud component
|
|
23
|
+
│ ├── WordCloud.tsx # Core component implementation
|
|
24
|
+
│ └── __tests__/ # Test files
|
|
25
|
+
├── lib/ # Build output (CommonJS)
|
|
26
|
+
│ └── esm/ # Build output (ES Modules)
|
|
27
|
+
├── test/
|
|
28
|
+
│ └── jest-setup.ts # Jest configuration
|
|
29
|
+
├── package.json # Dependencies and scripts
|
|
30
|
+
├── tsconfig.json # TypeScript configuration
|
|
31
|
+
├── tsconfig.build.json # TypeScript build configuration
|
|
32
|
+
└── babel.config.js # Babel configuration
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Core Technologies
|
|
36
|
+
|
|
37
|
+
- **React:** Supports versions 16.8+ through 19.x
|
|
38
|
+
- **D3.js:** Uses d3-cloud, d3-scale, d3-selection, d3-scale-chromatic
|
|
39
|
+
- **TypeScript:** Strict mode enabled with comprehensive type checking
|
|
40
|
+
- **Build Tools:** Babel (transpilation), TypeScript (type generation)
|
|
41
|
+
- **Module Formats:** Dual-package (CommonJS + ESM)
|
|
42
|
+
|
|
43
|
+
## Key Dependencies
|
|
44
|
+
|
|
45
|
+
### Runtime Dependencies
|
|
46
|
+
- `d3-cloud@^1.2.7` - Core word cloud layout algorithm
|
|
47
|
+
- `d3-scale@^4.0.2` - Scaling functions
|
|
48
|
+
- `d3-selection@^3.0.0` - DOM manipulation
|
|
49
|
+
- `react-faux-dom@^4.5.0` - Server-side rendering support
|
|
50
|
+
- `react-fast-compare@^3.2.0` - Deep equality checks for memo optimization
|
|
51
|
+
|
|
52
|
+
### Development Dependencies
|
|
53
|
+
- `typescript@^4.4.2` - Type system
|
|
54
|
+
- `@babel/cli`, `@babel/core` - Build pipeline
|
|
55
|
+
- `jest@^27.0.6` - Testing framework
|
|
56
|
+
- `eslint@^9.26.0` - Linting
|
|
57
|
+
- `canvas@^3.2.1` - Native canvas for SSR (dev dependency)
|
|
58
|
+
|
|
59
|
+
## Component Architecture
|
|
60
|
+
|
|
61
|
+
### WordCloud Component (`src/WordCloud.tsx`)
|
|
62
|
+
|
|
63
|
+
**Key Implementation Details:**
|
|
64
|
+
- Uses `react-faux-dom` for creating virtual DOM elements
|
|
65
|
+
- Leverages `d3-cloud` for word positioning algorithm
|
|
66
|
+
- Wrapped with `React.memo()` and `react-fast-compare` for performance
|
|
67
|
+
- Supports customizable fonts, sizes, rotations, spirals, and colors
|
|
68
|
+
- Provides event handlers for click, mouseover, and mouseout
|
|
69
|
+
|
|
70
|
+
**Props Interface:**
|
|
71
|
+
```typescript
|
|
72
|
+
interface WordCloudProps {
|
|
73
|
+
data: { text: string; value: number }[];
|
|
74
|
+
width?: number;
|
|
75
|
+
height?: number;
|
|
76
|
+
font?: string | ((word: Word, index: number) => string);
|
|
77
|
+
fontStyle?: string | ((word: Word, index: number) => string);
|
|
78
|
+
fontWeight?: string | number | ((word: Word, index: number) => string | number);
|
|
79
|
+
fontSize?: number | ((word: Word, index: number) => number);
|
|
80
|
+
rotate?: number | ((word: Word, index: number) => number);
|
|
81
|
+
spiral?: 'archimedean' | 'rectangular' | ((size: [number, number]) => (t: number) => [number, number]);
|
|
82
|
+
padding?: number | ((word: Word, index: number) => number);
|
|
83
|
+
random?: () => number;
|
|
84
|
+
fill?: ValueFn<SVGTextElement, Word, string>;
|
|
85
|
+
onWordClick?: (this: BaseType, event: any, d: Word) => void;
|
|
86
|
+
onWordMouseOver?: (this: BaseType, event: any, d: Word) => void;
|
|
87
|
+
onWordMouseOut?: (this: BaseType, event: any, d: Word) => void;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Build System
|
|
92
|
+
|
|
93
|
+
### NPM Scripts
|
|
94
|
+
- `npm run build` - Full build (clean + CJS + ESM)
|
|
95
|
+
- `npm run build:cjs` - Build CommonJS output to `lib/`
|
|
96
|
+
- `npm run build:esm` - Build ES Modules output to `lib/esm/`
|
|
97
|
+
- `npm run check` - TypeScript type checking (no emit)
|
|
98
|
+
- `npm test` - Currently skips tests (placeholder)
|
|
99
|
+
- `npm run clean` - Remove build artifacts
|
|
100
|
+
- `npm run prettier` - Format code
|
|
101
|
+
- `npm publish` - Publish to npm (runs prepublishOnly hook)
|
|
102
|
+
|
|
103
|
+
### Build Pipeline
|
|
104
|
+
1. Clean previous build artifacts
|
|
105
|
+
2. Babel transpiles TypeScript files to JavaScript
|
|
106
|
+
3. TypeScript compiler generates type declarations (.d.ts)
|
|
107
|
+
4. Output generated for both CommonJS and ESM formats
|
|
108
|
+
|
|
109
|
+
### Package Exports
|
|
110
|
+
```json
|
|
111
|
+
"exports": {
|
|
112
|
+
"import": "./lib/esm/index.js",
|
|
113
|
+
"require": "./lib/index.js"
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Security Practices
|
|
118
|
+
|
|
119
|
+
This project prioritizes security through:
|
|
120
|
+
1. **Regular dependency updates** - Actively monitors and addresses Dependabot alerts
|
|
121
|
+
2. **Dependency overrides** - Uses package.json overrides for transitive dependencies
|
|
122
|
+
3. **Minimal attack surface** - Small, focused codebase with limited dependencies
|
|
123
|
+
|
|
124
|
+
### Current Overrides
|
|
125
|
+
```json
|
|
126
|
+
"overrides": {
|
|
127
|
+
"form-data": "^3.0.4",
|
|
128
|
+
"canvas": "^3.2.1"
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## TypeScript Configuration
|
|
133
|
+
|
|
134
|
+
### Strict Mode Settings
|
|
135
|
+
The project uses comprehensive TypeScript strict mode:
|
|
136
|
+
- `strict: true`
|
|
137
|
+
- `noImplicitAny: true`
|
|
138
|
+
- `strictNullChecks: true`
|
|
139
|
+
- `noUnusedLocals: true`
|
|
140
|
+
- `noUnusedParameters: true`
|
|
141
|
+
- `noImplicitReturns: true`
|
|
142
|
+
- `noUncheckedIndexedAccess: true`
|
|
143
|
+
|
|
144
|
+
**Target:** ES2018
|
|
145
|
+
**Module:** ES2015 (with CommonJS override for CJS build)
|
|
146
|
+
**JSX:** React
|
|
147
|
+
|
|
148
|
+
## Development Guidelines for AI Agents
|
|
149
|
+
|
|
150
|
+
### When Working on This Project
|
|
151
|
+
|
|
152
|
+
1. **Security First**
|
|
153
|
+
- Always check for and address security vulnerabilities
|
|
154
|
+
- Prioritize dependency updates that fix CVEs
|
|
155
|
+
- Use `npm audit` to identify issues
|
|
156
|
+
- Update package overrides when necessary
|
|
157
|
+
|
|
158
|
+
2. **TypeScript Strictness**
|
|
159
|
+
- Maintain all strict TypeScript settings
|
|
160
|
+
- Do not use `@ts-ignore` unless absolutely necessary (currently one instance)
|
|
161
|
+
- Ensure all types are properly defined
|
|
162
|
+
- Run `npm run check` before committing
|
|
163
|
+
|
|
164
|
+
3. **React Compatibility**
|
|
165
|
+
- Test changes against multiple React versions (16.8, 17, 18, 19)
|
|
166
|
+
- Maintain hooks best practices
|
|
167
|
+
- Preserve memo optimization with deep equality checks
|
|
168
|
+
|
|
169
|
+
4. **Build Integrity**
|
|
170
|
+
- Always run `npm run build` after code changes
|
|
171
|
+
- Verify both CommonJS and ESM outputs work
|
|
172
|
+
- Check that type definitions are generated correctly
|
|
173
|
+
|
|
174
|
+
5. **Code Style**
|
|
175
|
+
- Use Prettier for formatting (`npm run prettier`)
|
|
176
|
+
- Follow ESLint rules (when running)
|
|
177
|
+
- Maintain consistency with existing code patterns
|
|
178
|
+
|
|
179
|
+
6. **Version Management**
|
|
180
|
+
- Update `package.json` version field
|
|
181
|
+
- Update CHANGELOG in README.md
|
|
182
|
+
- Follow semantic versioning (MAJOR.MINOR.PATCH)
|
|
183
|
+
- Use conventional commit messages
|
|
184
|
+
|
|
185
|
+
7. **Testing**
|
|
186
|
+
- Run existing tests (when available)
|
|
187
|
+
- Add tests for new functionality
|
|
188
|
+
- Ensure SSR compatibility is maintained
|
|
189
|
+
|
|
190
|
+
### Common Tasks
|
|
191
|
+
|
|
192
|
+
#### Addressing Dependabot Alerts
|
|
193
|
+
1. Review the security advisory
|
|
194
|
+
2. Check if direct or transitive dependency
|
|
195
|
+
3. Update in `dependencies` or `devDependencies` if direct
|
|
196
|
+
4. Add/update in `overrides` if transitive
|
|
197
|
+
5. Test build and functionality
|
|
198
|
+
6. Update changelog
|
|
199
|
+
7. Bump version (patch for security fixes)
|
|
200
|
+
8. Commit with descriptive message
|
|
201
|
+
|
|
202
|
+
#### Adding New Features
|
|
203
|
+
1. Update TypeScript interfaces in `src/WordCloud.tsx`
|
|
204
|
+
2. Implement feature while maintaining memo optimization
|
|
205
|
+
3. Update README.md with new prop documentation
|
|
206
|
+
4. Add usage examples
|
|
207
|
+
5. Update changelog
|
|
208
|
+
6. Bump version (minor for new features)
|
|
209
|
+
|
|
210
|
+
#### Refactoring
|
|
211
|
+
1. Maintain existing public API
|
|
212
|
+
2. Preserve TypeScript strict mode compliance
|
|
213
|
+
3. Run type checking and build
|
|
214
|
+
4. Update internal documentation
|
|
215
|
+
5. Bump version (patch for internal changes)
|
|
216
|
+
|
|
217
|
+
## Known Issues & Considerations
|
|
218
|
+
|
|
219
|
+
1. **@ts-ignore Comment** (line 58-60 in WordCloud.tsx)
|
|
220
|
+
- The ordinal scale function typing has a known issue
|
|
221
|
+
- Should accept numbers but TypeScript infers incorrectly
|
|
222
|
+
- Consider revisiting with d3 type updates
|
|
223
|
+
|
|
224
|
+
2. **Test Suite**
|
|
225
|
+
- Currently tests are skipped (`echo 'Skipping tests'`)
|
|
226
|
+
- Full Jest configuration exists
|
|
227
|
+
- Testing-library is available but not actively used
|
|
228
|
+
- Future work: Enable and write comprehensive tests
|
|
229
|
+
|
|
230
|
+
3. **Lint Configuration**
|
|
231
|
+
- Linting is currently skipped
|
|
232
|
+
- ESLint 9.26+ is installed
|
|
233
|
+
- Configuration exists but may need updates
|
|
234
|
+
- Future work: Enable and fix linting
|
|
235
|
+
|
|
236
|
+
4. **Node Canvas Dependency**
|
|
237
|
+
- Requires native binaries (Cairo, Pango, etc.)
|
|
238
|
+
- Installation instructions in README for Mac/Ubuntu
|
|
239
|
+
- May cause issues in containerized environments
|
|
240
|
+
- Only needed for SSR/testing, not end users
|
|
241
|
+
|
|
242
|
+
## Release Process
|
|
243
|
+
|
|
244
|
+
1. **Pre-release Checks**
|
|
245
|
+
- Run `npm run check` (TypeScript)
|
|
246
|
+
- Run `npm run build` (verify build)
|
|
247
|
+
- Run `npm test` (when tests are enabled)
|
|
248
|
+
- Update version in `package.json`
|
|
249
|
+
- Update CHANGELOG in `README.md`
|
|
250
|
+
|
|
251
|
+
2. **Commit**
|
|
252
|
+
- Use conventional commit format
|
|
253
|
+
- Example: `chore: bump version to X.Y.Z`
|
|
254
|
+
|
|
255
|
+
3. **Publish**
|
|
256
|
+
- Run `npm publish`
|
|
257
|
+
- The `prepublishOnly` hook automatically runs build
|
|
258
|
+
- Verify on npmjs.com
|
|
259
|
+
|
|
260
|
+
4. **Post-publish**
|
|
261
|
+
- Tag release in git
|
|
262
|
+
- Update GitHub releases
|
|
263
|
+
- Close related issues
|
|
264
|
+
|
|
265
|
+
## Useful Commands
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
# Install dependencies
|
|
269
|
+
npm install
|
|
270
|
+
|
|
271
|
+
# Type check
|
|
272
|
+
npm run check
|
|
273
|
+
|
|
274
|
+
# Build for production
|
|
275
|
+
npm run build
|
|
276
|
+
|
|
277
|
+
# Format code
|
|
278
|
+
npm run prettier
|
|
279
|
+
|
|
280
|
+
# Publish package
|
|
281
|
+
npm publish
|
|
282
|
+
|
|
283
|
+
# Check for vulnerabilities
|
|
284
|
+
npm audit
|
|
285
|
+
|
|
286
|
+
# View dependency tree
|
|
287
|
+
npm list --depth=0
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Links & Resources
|
|
291
|
+
|
|
292
|
+
- **NPM Package:** https://www.npmjs.com/package/react-d3-cloud-modern
|
|
293
|
+
- **GitHub Repository:** https://github.com/carlosalvidrez/react-d3-cloud-modern
|
|
294
|
+
- **Original Project:** https://github.com/Yoctol/react-d3-cloud
|
|
295
|
+
- **D3 Cloud Documentation:** https://github.com/jasondavies/d3-cloud
|
|
296
|
+
- **Demo:** https://codesandbox.io/embed/react-d3-cloud-demo-forked-50wzl
|
|
297
|
+
|
|
298
|
+
## Contact
|
|
299
|
+
|
|
300
|
+
**Author:** Carlos Alvidrez (cph)
|
|
301
|
+
**License:** MIT
|
|
302
|
+
**Issues:** https://github.com/carlosalvidrez/react-d3-cloud-modern/issues
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
*Last Updated: 2026-02-10*
|
|
307
|
+
*Document Version: 1.0*
|
package/README.md
CHANGED
|
@@ -5,10 +5,21 @@
|
|
|
5
5
|
|
|
6
6
|
A word cloud react component built with [d3-cloud](https://github.com/jasondavies/d3-cloud).
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
A modern fork of [react-d3-cloud](https://github.com/Yoctol/react-d3-cloud) with updated dependencies to address security vulnerabilities and provide React 19 compatibility.
|
|
9
9
|
|
|
10
10
|

|
|
11
11
|
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- 🎨 Interactive word clouds with customizable styling
|
|
15
|
+
- ⚡ Optimized with React.memo and deep equality checks
|
|
16
|
+
- 🔄 Support for React 16.8+, 17, 18, and 19
|
|
17
|
+
- 📦 Dual module support (CommonJS and ESM)
|
|
18
|
+
- 🎯 Full TypeScript support with type definitions
|
|
19
|
+
- 🖱️ Mouse event handlers (click, mouseover, mouseout)
|
|
20
|
+
- 🎲 Customizable word positioning, rotation, and sizing algorithms
|
|
21
|
+
- 🛡️ Security-focused with regular dependency updates
|
|
22
|
+
|
|
12
23
|
## Installation
|
|
13
24
|
|
|
14
25
|
```sh
|
|
@@ -173,21 +184,44 @@ function App() {
|
|
|
173
184
|
);
|
|
174
185
|
```
|
|
175
186
|
|
|
176
|
-
##
|
|
187
|
+
## NPM Commands
|
|
188
|
+
|
|
189
|
+
### Install dependencies
|
|
190
|
+
|
|
191
|
+
```sh
|
|
192
|
+
npm install
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Build
|
|
177
196
|
|
|
178
197
|
```sh
|
|
179
198
|
npm run build
|
|
180
199
|
```
|
|
181
200
|
|
|
182
|
-
|
|
201
|
+
This will build both CommonJS (`lib/`) and ESM (`lib/esm/`) versions.
|
|
202
|
+
|
|
203
|
+
### Run Tests
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
npm test
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Publish to NPM
|
|
210
|
+
|
|
211
|
+
```sh
|
|
212
|
+
npm publish
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
*(Note: The `prepublishOnly` script will automatically run `npm run build` before publishing.)*
|
|
183
216
|
|
|
184
|
-
|
|
217
|
+
## Development
|
|
218
|
+
|
|
219
|
+
### Pre-install (for `node-canvas` support)
|
|
185
220
|
|
|
186
221
|
#### Mac OS X
|
|
187
222
|
|
|
188
223
|
```sh
|
|
189
224
|
brew install pkg-config cairo pango libpng jpeg giflib librsvg
|
|
190
|
-
npm install
|
|
191
225
|
```
|
|
192
226
|
|
|
193
227
|
#### Ubuntu and Other Debian Based Systems
|
|
@@ -195,17 +229,10 @@ npm install
|
|
|
195
229
|
```sh
|
|
196
230
|
sudo apt-get update
|
|
197
231
|
sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++
|
|
198
|
-
npm install
|
|
199
232
|
```
|
|
200
233
|
|
|
201
234
|
For more details, please check out [Installation guides](https://github.com/Automattic/node-canvas/wiki) at node-canvas wiki.
|
|
202
235
|
|
|
203
|
-
### Run Tests
|
|
204
|
-
|
|
205
|
-
```sh
|
|
206
|
-
npm test
|
|
207
|
-
```
|
|
208
|
-
|
|
209
236
|
## License
|
|
210
237
|
|
|
211
238
|
MIT © [Yoctol](https://github.com/Yoctol/react-d3-cloud)
|
|
@@ -213,15 +240,40 @@ MIT © [Yoctol](https://github.com/Yoctol/react-d3-cloud)
|
|
|
213
240
|
|
|
214
241
|
## Changelog
|
|
215
242
|
|
|
216
|
-
### 1.0.8
|
|
243
|
+
### 1.0.8 (Latest)
|
|
217
244
|
|
|
218
|
-
- Update `@modelcontextprotocol/sdk` to `1.26.0
|
|
219
|
-
- Update `eslint` to `^9.26.0
|
|
245
|
+
- Update `@modelcontextprotocol/sdk` to `1.26.0`
|
|
246
|
+
- Update `eslint` to `^9.26.0`
|
|
220
247
|
|
|
221
248
|
### 1.0.7
|
|
222
249
|
|
|
223
|
-
-
|
|
250
|
+
- Security: Dependency updates to address vulnerabilities
|
|
224
251
|
|
|
225
252
|
### 1.0.6
|
|
226
253
|
|
|
227
|
-
- Upgrade `canvas` to `^3.2.1` to address
|
|
254
|
+
- Security: Upgrade `canvas` to `^3.2.1` to address security vulnerability
|
|
255
|
+
|
|
256
|
+
### 1.0.5
|
|
257
|
+
|
|
258
|
+
- Update `js-yaml` to address security vulnerability
|
|
259
|
+
|
|
260
|
+
### 1.0.4
|
|
261
|
+
|
|
262
|
+
- React 19 compatibility improvements
|
|
263
|
+
|
|
264
|
+
### 1.0.3
|
|
265
|
+
|
|
266
|
+
- Update `@testing-library/react` to v16.3.0
|
|
267
|
+
- Update `@types/react` to v19.1.8
|
|
268
|
+
- Fix Jest configuration
|
|
269
|
+
|
|
270
|
+
### 1.0.2
|
|
271
|
+
|
|
272
|
+
- Fix TypeScript error in useRef hook
|
|
273
|
+
- Improve type safety
|
|
274
|
+
|
|
275
|
+
### 1.0.1
|
|
276
|
+
|
|
277
|
+
- Initial release as fork
|
|
278
|
+
- Modernized dependencies
|
|
279
|
+
- TypeScript improvements
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-d3-cloud-modern",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A word cloud component using d3-cloud",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "cph",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"babel-plugin-typescript-to-proptypes": "^1.4.2",
|
|
79
79
|
"canvas": "^3.2.1",
|
|
80
80
|
"cross-env": "^7.0.3",
|
|
81
|
-
"eslint": "^
|
|
81
|
+
"eslint": "^7.32.0",
|
|
82
82
|
"eslint-config-yoctol": "^0.26.2",
|
|
83
83
|
"eslint-plugin-import": "^2.24.0",
|
|
84
84
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|