brainsmatics 1.1.65 → 1.1.67

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 CHANGED
@@ -7,27 +7,31 @@ It is consumed by tools such as OpenCode, Cursor, Claude Code, etc.
7
7
  Project Overview
8
8
  ======================================================================
9
9
 
10
- Project name: brain-ui
10
+ Project name: brain-ui (brainsmatics)
11
11
 
12
- This is a frontend UI project built with:
12
+ This is a **React component library** for neuroscience data visualization, built with:
13
13
 
14
14
  - React 18
15
- - TypeScript
16
- - Vite
17
- - Ant Design (antd)
18
- - Three.js
19
- - Storybook
20
-
21
- The project contains reusable UI components and 3D / visualization related components.
22
- Agents must follow the conventions and constraints defined below.
15
+ - TypeScript 4.9.5
16
+ - Vite 4.2.0
17
+ - Ant Design (antd) 5.24.6 + Ant Design X (@ant-design/x) 1.1.0
18
+ - Three.js 0.157.0
19
+ - Storybook 7.0.6
20
+
21
+ The project provides reusable UI components for:
22
+ - **3D brain visualization** (neurons, brain atlases, regions, SWC files)
23
+ - **2D data viewers** (grids, thumbnails, navigation trees)
24
+ - **AI chat integration** (LLM-powered neuroscience assistant)
25
+ - **Medical imaging** (NIfTI, TIFF, GeoTIFF support)
23
26
 
24
27
  ======================================================================
25
28
  Package Management
26
29
  ======================================================================
27
30
 
28
31
  Preferred package manager:
29
- - pnpm (preferred if lockfile exists)
30
- - npm or yarn if pnpm is unavailable
32
+ - **pnpm** (preferred if lockfile exists - `pnpm-lock.yaml`)
33
+ - **npm** (if `package-lock.json` exists)
34
+ - **yarn** (if `yarn.lock` exists)
31
35
 
32
36
  Do NOT introduce new dependencies unless explicitly requested.
33
37
 
@@ -36,36 +40,101 @@ Development / Build Commands
36
40
  ======================================================================
37
41
 
38
42
  Install dependencies:
39
- - pnpm install
40
- - npm install
41
- - yarn install
43
+ ```bash
44
+ pnpm install
45
+ # or
46
+ npm install
47
+ # or
48
+ yarn install
49
+ ```
42
50
 
43
51
  Start development server:
44
- - pnpm dev
45
- - npm run dev
46
-
47
- Production build:
48
- - pnpm build
49
- - npm run build
52
+ ```bash
53
+ pnpm dev
54
+ # or
55
+ npm run dev
56
+ ```
57
+
58
+ Production build (library):
59
+ ```bash
60
+ pnpm build
61
+ # or
62
+ npm run build
63
+ ```
50
64
 
51
65
  Preview production build:
52
- - pnpm preview
53
- - npm run preview
66
+ ```bash
67
+ pnpm preview
68
+ # or
69
+ npm run preview
70
+ ```
54
71
 
55
72
  ======================================================================
56
73
  Storybook
57
74
  ======================================================================
58
75
 
59
76
  Run Storybook locally:
60
- - pnpm storybook
61
- - npm run storybook
77
+ ```bash
78
+ pnpm storybook
79
+ # or
80
+ npm run storybook
81
+ ```
62
82
 
63
83
  Build Storybook:
64
- - pnpm build-storybook
65
- - npm run build-storybook
84
+ ```bash
85
+ pnpm build-storybook
86
+ # or
87
+ npm run build-storybook
88
+ ```
66
89
 
67
90
  Story files should be colocated with components and named:
68
- - *.stories.tsx
91
+ - `*.stories.tsx`
92
+ - `*.stories.ts`
93
+
94
+ Storybook configuration:
95
+ - Main config: `.storybook/main.js`
96
+ - Preview config: `.storybook/preview.js`
97
+ - Custom middleware: `.storybook/middleware.js` (for API proxying)
98
+
99
+ ======================================================================
100
+ Project Structure
101
+ ======================================================================
102
+
103
+ ```
104
+ src/
105
+ ├── component/
106
+ │ ├── 2d/ # 2D visualization components
107
+ │ │ ├── gridviewer/ # Grid-based data viewer
108
+ │ │ ├── navtree/ # Navigation tree component
109
+ │ │ ├── navigation/ # Navigation controls
110
+ │ │ ├── thumbnail/ # Thumbnail viewer
111
+ │ │ ├── distribution/ # Data distribution charts
112
+ │ │ ├── mulifiveiewer/ # Multi-view layout
113
+ │ │ ├── twoviewer/ # Dual view comparison
114
+ │ │ └── ...
115
+ │ ├── 3d/ # 3D visualization components
116
+ │ │ ├── functionLoop/ # AI-powered functional circuit analysis
117
+ │ │ ├── aichat/ # AI chat interface (@ant-design/x)
118
+ │ │ ├── swctree/ # SWC neuron file viewer
119
+ │ │ ├── modalLoader/ # 3D model loader (FBX/OBJ)
120
+ │ │ ├── stlLoader/ # STL file loader
121
+ │ │ ├── atlas/ # Brain atlas viewer
122
+ │ │ ├── sideBar/ # 3D viewer sidebar
123
+ │ │ ├── volumeAnalysis/ # Volume data analysis
124
+ │ │ ├── registration/ # Image registration
125
+ │ │ └── ...
126
+ │ ├── common/ # Shared UI components
127
+ │ │ ├── Button/
128
+ │ │ └── Header/
129
+ │ ├── types/ # TypeScript type definitions
130
+ │ └── util/ # Utility functions
131
+ │ ├── i18n.ts # Internationalization (i18next)
132
+ │ ├── global.ts # Global state/variables
133
+ │ ├── swc.ts # SWC file utilities
134
+ │ └── ...
135
+ ├── stories/ # Storybook stories
136
+ └── assets/ # Static assets (fonts, icons)
137
+ ```
69
138
 
70
139
  ======================================================================
71
140
  TypeScript Rules
@@ -81,16 +150,23 @@ TypeScript Rules
81
150
 
82
151
  Example:
83
152
 
153
+ ```typescript
84
154
  interface ComponentProps {
85
155
  value: number;
86
156
  onChange?: (value: number) => void;
87
157
  }
158
+ ```
159
+
160
+ Compiler options (from tsconfig.json):
161
+ - Strict mode enabled (`strict: true`)
162
+ - Declaration files generated (`declaration: true`)
163
+ - Path mapping: `"brainsmatics/STAM"` → `dist/component/STAM.d.ts`
88
164
 
89
165
  ======================================================================
90
166
  React Rules
91
167
  ======================================================================
92
168
 
93
- - Use function components only
169
+ - Use **function components only**
94
170
  - Do NOT use class components
95
171
  - Follow the Rules of Hooks
96
172
  - Prefer composition over inheritance
@@ -98,35 +174,47 @@ React Rules
98
174
  - Avoid deeply nested JSX structures
99
175
 
100
176
  State management:
101
- - Prefer local state (useState / useReducer)
102
- - Avoid unnecessary global state
177
+ - Prefer local state (`useState` / `useReducer`)
178
+ - Use global state sparingly (see `src/component/util/global.ts`)
103
179
  - Use refs for mutable values that should not trigger re-render
104
180
 
181
+ Performance:
182
+ - Use `useMemo` / `useCallback` for expensive computations
183
+ - Avoid creating new objects/functions inside render unless required
184
+
105
185
  ======================================================================
106
186
  Component Structure
107
187
  ======================================================================
108
188
 
109
189
  Recommended component structure:
110
190
 
191
+ ```
111
192
  ComponentName/
112
- ├─ index.tsx
113
- ├─ index.less | index.css | index.scss
114
- ├─ ComponentName.stories.tsx
115
- └─ types.ts (optional)
193
+ ├─ index.tsx # Main component export
194
+ ├─ index.css # Component styles
195
+ ├─ ComponentName.stories.tsx # Storybook stories
196
+ ├─ types.ts # Component-specific types (optional)
197
+ └─ SubComponent.tsx # Child components (optional)
198
+ ```
116
199
 
117
200
  Rules:
118
- - index.tsx exports the component
119
- - styles are colocated with the component
120
- - stories demonstrate common usage and edge cases
201
+ - `index.tsx` exports the component
202
+ - Styles are colocated with the component
203
+ - Stories demonstrate common usage and edge cases
204
+ - Use CSS Modules for complex styling (e.g., `index.module.css`)
121
205
 
122
206
  ======================================================================
123
207
  Ant Design (antd) Usage
124
208
  ======================================================================
125
209
 
126
210
  - Use antd components as the primary UI building blocks
211
+ - Also available: **Ant Design X** (`@ant-design/x`) for AI chat interfaces
212
+ - `Bubble` - Chat message bubbles
213
+ - `Sender` - Message input
214
+ - `Prompts` - Prompt suggestions
127
215
  - Avoid copying or modifying antd internal styles
128
216
  - Prefer composition instead of overriding antd components
129
- - Use className or style props for customization
217
+ - Use `className` or `style` props for customization
130
218
  - Avoid deep CSS selectors targeting antd internals
131
219
 
132
220
  ======================================================================
@@ -134,28 +222,105 @@ Three.js Usage
134
222
  ======================================================================
135
223
 
136
224
  - Keep Three.js logic isolated from UI logic when possible
225
+ - Use shared global scene/camera from `src/component/util/global.ts`
137
226
  - Avoid heavy allocations inside render loops
138
227
  - Be mindful of GPU memory usage
139
228
  - Always clean up resources when no longer needed:
140
- - geometry.dispose()
141
- - material.dispose()
142
- - texture.dispose()
143
-
229
+ ```typescript
230
+ geometry.dispose()
231
+ material.dispose()
232
+ texture.dispose()
233
+ ```
144
234
  - Avoid unnecessary re-creation of:
145
235
  - geometries
146
236
  - materials
147
237
  - textures
148
238
  - Prefer memoization for expensive objects
149
239
 
240
+ Common Three.js imports:
241
+ ```typescript
242
+ import * as THREE from "three";
243
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
244
+ import { FontLoader } from 'three/examples/jsm/loaders/FontLoader';
245
+ import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry';
246
+ import { Line2 } from "three/examples/jsm/lines/Line2";
247
+ import { LineMaterial } from "three/examples/jsm/lines/LineMaterial";
248
+ import { LineGeometry } from "three/examples/jsm/lines/LineGeometry";
249
+ ```
250
+
251
+ ======================================================================
252
+ Internationalization (i18n)
253
+ ======================================================================
254
+
255
+ The project uses **i18next** with react-i18next for internationalization.
256
+
257
+ Supported languages:
258
+ - English (`en_us`)
259
+ - Chinese (`zh_cn`)
260
+
261
+ Translation files:
262
+ - `src/component/util/en_us.json`
263
+ - `src/component/util/zh_cn.json`
264
+
265
+ Usage in components:
266
+ ```typescript
267
+ import { change_language } from '../util/i18n';
268
+
269
+ // Component receives `t` function via props
270
+ interface Props {
271
+ t: (key: string) => string;
272
+ }
273
+ ```
274
+
275
+ ======================================================================
276
+ Key Dependencies
277
+ ======================================================================
278
+
279
+ Core:
280
+ - `react` / `react-dom` (peer dependencies, >=18.0.0)
281
+ - `typescript` 4.9.5
282
+
283
+ UI Framework:
284
+ - `antd` 5.24.6
285
+ - `@ant-design/x` 1.1.0 (AI chat components)
286
+ - `@ant-design/x-markdown` 2.0.0-alpha.5
287
+
288
+ 3D Visualization:
289
+ - `three` 0.157.0
290
+ - `@types/three` 0.157.2
291
+
292
+ Medical Imaging:
293
+ - `@itk-wasm/image-io` 1.6.0
294
+ - `nifti-reader-js` 0.8.0
295
+ - `geotiff` 2.1.3
296
+ - `tiff` 6.0.0
297
+
298
+ Charts & Data:
299
+ - `echarts` 5.5.1
300
+ - `react-window` 1.8.9 (virtualization)
301
+
302
+ Maps:
303
+ - `leaflet` 1.9.4
304
+ - `react-leaflet` 4.2.1
305
+
306
+ Utilities:
307
+ - `i18next` / `react-i18next` (internationalization)
308
+ - `socket.io-client` 4.8.1
309
+ - `markdown-it` 14.1.0
310
+ - `react-markdown` 10.1.0
311
+ - `dompurify` 3.2.5
312
+
150
313
  ======================================================================
151
314
  Performance Guidelines
152
315
  ======================================================================
153
316
 
154
317
  - Avoid unnecessary re-renders
155
- - Use useMemo / useCallback for expensive computations
318
+ - Use `useMemo` / `useCallback` for expensive computations
156
319
  - Do not create new objects/functions inside render unless required
157
- - Be careful with requestAnimationFrame loops
320
+ - Be careful with `requestAnimationFrame` loops
158
321
  - Pay attention to performance in Three.js related code
322
+ - Use `react-window` for long lists
323
+ - Dispose Three.js resources properly
159
324
 
160
325
  ======================================================================
161
326
  Error Handling
@@ -165,6 +330,7 @@ Error Handling
165
330
  - Log meaningful error messages
166
331
  - Validate external or dynamic data before usage
167
332
  - Prefer early returns over deeply nested conditionals
333
+ - Use antd's `message` API for user-facing errors
168
334
 
169
335
  ======================================================================
170
336
  Imports & Naming
@@ -172,15 +338,33 @@ Imports & Naming
172
338
 
173
339
  Imports order:
174
340
  1. React and external libraries
175
- 2. UI components
176
- 3. hooks / utils
177
- 4. styles
341
+ 2. UI components (antd, @ant-design/x)
342
+ 3. Three.js and visualization libraries
343
+ 4. Internal hooks / utils
344
+ 5. Styles
178
345
 
179
346
  Naming conventions:
180
- - Components: PascalCase
181
- - Hooks: useSomething
347
+ - Components: PascalCase (e.g., `FunctionLoop`, `SwcTree`)
348
+ - Hooks: camelCase with `use` prefix (e.g., `useSomething`)
182
349
  - Files: follow existing project convention
183
350
  - Variables: camelCase
351
+ - Constants: UPPER_SNAKE_CASE
352
+
353
+ ======================================================================
354
+ Build Configuration
355
+ ======================================================================
356
+
357
+ Vite configuration (`vite.config.js`):
358
+ - Library mode build (outputs ES and CJS formats)
359
+ - Entry point: `src/index.ts`
360
+ - External dependencies: `react`, `react-dom`
361
+ - TypeScript declaration files generated
362
+ - Proxy configured for `/api` → `http://192.168.50.54:8080`
363
+
364
+ Output:
365
+ - Main: `dist/index.mjs`
366
+ - Types: `dist/index.d.ts`
367
+ - CSS: `dist/style.css`
184
368
 
185
369
  ======================================================================
186
370
  Testing (If Present)
@@ -189,6 +373,7 @@ Testing (If Present)
189
373
  - Prefer testing public behavior over implementation details
190
374
  - Avoid excessive snapshot testing
191
375
  - Keep tests focused and readable
376
+ - Use Storybook for component testing and documentation
192
377
 
193
378
  ======================================================================
194
379
  Agent Behavior Rules (IMPORTANT)
@@ -203,6 +388,7 @@ When modifying code, agents MUST:
203
388
  5. Do NOT introduce new dependencies unless requested
204
389
  6. Ensure TypeScript types remain correct
205
390
  7. Ensure Storybook stories still work if affected
391
+ 8. Respect the existing component architecture (2d vs 3d separation)
206
392
 
207
393
  If a change is non-trivial, explain WHY the change is needed.
208
394
 
@@ -213,7 +399,8 @@ Out of Scope
213
399
  - Backend logic
214
400
  - API implementations
215
401
  - CI/CD configuration unless explicitly requested
402
+ - Database schema changes
216
403
 
217
404
  ======================================================================
218
405
  End of AGENTS.md
219
- ======================================================================
406
+ ======================================================================
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ export interface BarData {
3
+ name: string;
4
+ value: number;
5
+ itemStyle?: {
6
+ color?: string | {
7
+ type: string;
8
+ x: number;
9
+ y: number;
10
+ x2: number;
11
+ y2: number;
12
+ colorStops: {
13
+ offset: number;
14
+ color: string;
15
+ }[];
16
+ };
17
+ };
18
+ }
19
+ export interface BarChartProps {
20
+ data: BarData[];
21
+ title?: string;
22
+ xAxisLabel?: string;
23
+ yAxisLabel?: string;
24
+ width?: string | number;
25
+ height?: string | number;
26
+ horizontal?: boolean;
27
+ showDataLabels?: boolean;
28
+ description?: string;
29
+ onBarClick?: (data: BarData) => void;
30
+ }
31
+ declare const BarChart: React.FC<BarChartProps>;
32
+ export default BarChart;
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ export interface ChordNode {
3
+ name: string;
4
+ itemStyle?: {
5
+ color?: string;
6
+ };
7
+ }
8
+ export interface ChordLink {
9
+ source: string;
10
+ target: string;
11
+ value: number;
12
+ lineStyle?: {
13
+ color?: string;
14
+ opacity?: number;
15
+ };
16
+ }
17
+ export interface ChordChartProps {
18
+ nodes: ChordNode[];
19
+ links: ChordLink[];
20
+ title?: string;
21
+ width?: string | number;
22
+ height?: string | number;
23
+ showLabels?: boolean;
24
+ labelRotate?: boolean;
25
+ description?: string;
26
+ onNodeClick?: (nodeName: string) => void;
27
+ onLinkClick?: (link: ChordLink) => void;
28
+ }
29
+ declare const ChordChart: React.FC<ChordChartProps>;
30
+ export default ChordChart;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ export interface HeatmapData {
3
+ x: string;
4
+ y: string;
5
+ value: number;
6
+ displayValue?: number | string;
7
+ }
8
+ export interface HeatmapChartProps {
9
+ xCategories: string[];
10
+ yCategories: string[];
11
+ data: HeatmapData[];
12
+ title?: string;
13
+ width?: string | number;
14
+ height?: string | number;
15
+ minValue?: number;
16
+ maxValue?: number;
17
+ colorRange?: string[];
18
+ showLabels?: boolean;
19
+ description?: string;
20
+ onCellClick?: (data: HeatmapData) => void;
21
+ }
22
+ declare const HeatmapChart: React.FC<HeatmapChartProps>;
23
+ export default HeatmapChart;
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ export interface RadarIndicator {
3
+ name: string;
4
+ max: number;
5
+ min?: number;
6
+ }
7
+ export interface RadarSeries {
8
+ name: string;
9
+ value: number[];
10
+ itemStyle?: {
11
+ color?: string;
12
+ };
13
+ areaStyle?: {
14
+ color?: string;
15
+ opacity?: number;
16
+ };
17
+ lineStyle?: {
18
+ color?: string;
19
+ width?: number;
20
+ };
21
+ }
22
+ export interface RadarChartProps {
23
+ indicators: RadarIndicator[];
24
+ data: RadarSeries[];
25
+ title?: string;
26
+ width?: string | number;
27
+ height?: string | number;
28
+ shape?: 'polygon' | 'circle';
29
+ showLegend?: boolean;
30
+ description?: string;
31
+ onSeriesClick?: (seriesName: string) => void;
32
+ }
33
+ declare const RadarChart: React.FC<RadarChartProps>;
34
+ export default RadarChart;
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ export interface SankeyNode {
3
+ name: string;
4
+ itemStyle?: {
5
+ color?: string;
6
+ borderColor?: string;
7
+ borderWidth?: number;
8
+ };
9
+ }
10
+ export interface SankeyLink {
11
+ source: string;
12
+ target: string;
13
+ value: number;
14
+ lineStyle?: {
15
+ color?: string;
16
+ opacity?: number;
17
+ };
18
+ }
19
+ export interface SankeyChartProps {
20
+ data: {
21
+ nodes: SankeyNode[];
22
+ links: SankeyLink[];
23
+ };
24
+ title?: string;
25
+ width?: string | number;
26
+ height?: string | number;
27
+ description?: string;
28
+ onNodeClick?: (nodeName: string) => void;
29
+ onLinkClick?: (link: SankeyLink) => void;
30
+ }
31
+ declare const SankeyChart: React.FC<SankeyChartProps>;
32
+ export default SankeyChart;
@@ -0,0 +1,10 @@
1
+ export { default as SankeyChart } from './SankeyChart';
2
+ export type { SankeyChartProps, SankeyNode, SankeyLink } from './SankeyChart';
3
+ export { default as BarChart } from './BarChart';
4
+ export type { BarChartProps, BarData } from './BarChart';
5
+ export { default as ChordChart } from './ChordChart';
6
+ export type { ChordChartProps, ChordNode, ChordLink } from './ChordChart';
7
+ export { default as RadarChart } from './RadarChart';
8
+ export type { RadarChartProps, RadarIndicator, RadarSeries } from './RadarChart';
9
+ export { default as HeatmapChart } from './HeatmapChart';
10
+ export type { HeatmapChartProps, HeatmapData } from './HeatmapChart';
@@ -7,3 +7,4 @@ export { default as Thumbnail } from "./thumbnail";
7
7
  export { default as MulfiViewer } from "./mulifiveiewer";
8
8
  export { default as Distribution } from "./distribution";
9
9
  export { default as Z } from "./js/index.js";
10
+ export * from "./charts";
@@ -1,4 +1,4 @@
1
- import { i as r } from "./index-74ec7690.mjs";
1
+ import { i as r } from "./index-4863f635.mjs";
2
2
  import { B as o } from "./basedecoder-11034ec6.mjs";
3
3
  import "react";
4
4
  import "react-dom";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index-b0a350ce.js"),t=require("./basedecoder-0503cc54.js");require("react");require("react-dom");class d extends t.BaseDecoder{decodeBlock(e){return r.inflate_1(new Uint8Array(e)).buffer}}exports.default=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index-521f4ce7.js"),t=require("./basedecoder-0503cc54.js");require("react");require("react-dom");class d extends t.BaseDecoder{decodeBlock(e){return r.inflate_1(new Uint8Array(e)).buffer}}exports.default=d;