brainsmatics 1.1.64 → 1.1.65
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/.opencode/skills/react/SKILL.md +49 -0
- package/.opencode/skills/three/SKILL.md +82 -0
- package/AGENTS.md +219 -0
- package/bun.lock +285 -0
- package/dist/component/3d/auxiliary/index.d.ts +2 -0
- package/dist/component/3d/functionLoop/ConnectivityCard.d.ts +41 -0
- package/dist/component/3d/functionLoop/GeneExpressionCard.d.ts +23 -0
- package/dist/component/3d/functionLoop/SingleNeuronCard.d.ts +27 -0
- package/dist/component/3d/functionLoop/SynapseCard.d.ts +24 -0
- package/dist/component/3d/functionLoop/index.d.ts +10 -0
- package/dist/component/3d/sideBar/index.d.ts +1 -0
- package/dist/component/util/global.d.ts +2 -0
- package/dist/{deflate-f4eb6480.mjs → deflate-3e488582.mjs} +1 -1
- package/dist/{deflate-e75a387d.js → deflate-ae534b41.js} +1 -1
- package/dist/{index-ca8e8a08.mjs → index-74ec7690.mjs} +63287 -53967
- package/dist/{index-42e52578.js → index-b0a350ce.js} +526 -417
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{lerc-b86782f1.mjs → lerc-0b89497a.mjs} +1 -1
- package/dist/{lerc-1703e1aa.js → lerc-c7148a19.js} +1 -1
- package/dist/stories/SingleNeuronCard.stories.d.ts +11 -0
- package/dist/style.css +1 -1
- package/index.html +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 专注于 React + TypeScript + Ant Design + Vite 的前端开发规范与最佳实践
|
|
3
|
+
tags: [react, typescript, antd, vite, frontend]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# React & UI Development Skill
|
|
7
|
+
|
|
8
|
+
## 角色定位
|
|
9
|
+
你是一个资深的 React 架构师,精通 TypeScript 类型安全、Ant Design 组件库封装以及 Vite 构建优化。
|
|
10
|
+
|
|
11
|
+
## 核心准则
|
|
12
|
+
1. **函数式组件**: 始终使用函数式组件和 Hooks。
|
|
13
|
+
2. **严格类型**: 所有组件 Props、State 和函数参数必须定义明确的 TypeScript 接口。禁止使用 `any`。
|
|
14
|
+
3. **UI 规范**: 优先使用 Ant Design (v5+) 组件。如需自定义样式,优先考虑内联样式或 CSS Modules。
|
|
15
|
+
4. **性能优化**: 合理使用 `useMemo` 和 `useCallback` 避免不必要的重绘。
|
|
16
|
+
|
|
17
|
+
## 技术栈细节
|
|
18
|
+
- **构建工具**: Vite (配置在 vite.config.ts)。
|
|
19
|
+
- **状态管理**: 优先使用 Context API 或 Zustand (如果项目中已安装)。
|
|
20
|
+
- **文档化**: 新组件应在 `src/stories` 目录下创建对应的 Storybook 文件 (`.stories.tsx`)。
|
|
21
|
+
- **Ant Design**:
|
|
22
|
+
- 使用 ConfigProvider 全局配置主题。
|
|
23
|
+
- 复杂表单使用 `Form` 组件并配合 `onFinish` 处理。
|
|
24
|
+
|
|
25
|
+
## 常用模式示例
|
|
26
|
+
### 组件结构
|
|
27
|
+
```tsx
|
|
28
|
+
import React from 'react';
|
|
29
|
+
import { Button, Space } from 'antd';
|
|
30
|
+
|
|
31
|
+
interface MyComponentProps {
|
|
32
|
+
title: string;
|
|
33
|
+
onAction?: () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const MyComponent: React.FC<MyComponentProps> = ({ title, onAction }) => {
|
|
37
|
+
return (
|
|
38
|
+
<Space direction="vertical">
|
|
39
|
+
<h3>{title}</h3>
|
|
40
|
+
<Button type="primary" onClick={onAction}>点击</Button>
|
|
41
|
+
</Space>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 调试与诊断
|
|
47
|
+
- 如果遇到热更新(HMR)失效,检查文件命名是否符合规范(React 刷新通常要求导出名称与文件名关联)。
|
|
48
|
+
- 检查 `tsconfig.json` 以确保路径别名(如 `@/`)配置正确。
|
|
49
|
+
- 如果 Ant Design 样式未生效,检查是否在入口文件引入了样式重置或 ConfigProvider。
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 专注于在 React 架构下通过原生 Three.js 进行分布式场景管理和对象生命周期控制
|
|
3
|
+
tags: [threejs, webgl, react-integration, scene-management]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Three.js Distributed Architecture Skill
|
|
7
|
+
|
|
8
|
+
## 角色定位
|
|
9
|
+
你是一个精通 Three.js 架构的专家。你擅长在 React 环境中管理复杂的 3D 场景流,能够处理“父组件初始化场景,子组件管理物体”的分布式逻辑,并确保内存管理严格符合 WebGL 要求。
|
|
10
|
+
|
|
11
|
+
## 核心准则 (分布式开发)
|
|
12
|
+
1. **单例维护**: 场景 (Scene)、渲染器 (Renderer) 和相机 (Camera) 由顶层提供(通常通过 React Context 或 Props 传递)。
|
|
13
|
+
2. **子组件职责**:
|
|
14
|
+
- 子组件不应创建渲染器,只负责创建、添加和删除其管辖内的 `Object3D`。
|
|
15
|
+
- 在 `useEffect` 的挂载阶段将物体 `scene.add(object)`。
|
|
16
|
+
- 在卸载阶段必须执行 `scene.remove(object)` 并调用 `geometry.dispose()` 和 `material.dispose()`。
|
|
17
|
+
3. **引用一致性**: 使用 `useRef` 持有 Three.js 原生对象,确保在 React 重绘时对象不被重新创建。
|
|
18
|
+
4. **数据同步**: 监听 Props 变化,在 `useEffect` 中手动更新 Three.js 对象的属性(如 `position.set()`, `material.color.set()`)。
|
|
19
|
+
|
|
20
|
+
## 推荐架构模式
|
|
21
|
+
|
|
22
|
+
### 1. 顶层共享模式 (Context)
|
|
23
|
+
建议使用 React Context 共享底层的 Three.js 实例,以便深层子组件访问。
|
|
24
|
+
|
|
25
|
+
### 2. 子组件示例 (Logic Fragment)
|
|
26
|
+
当需要编写一个负责渲染特定物体的子组件时,遵循以下结构:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import React, { useEffect, useRef } from 'react';
|
|
30
|
+
import * as THREE from 'three';
|
|
31
|
+
|
|
32
|
+
interface BoxProps {
|
|
33
|
+
scene: THREE.Scene; // 从父组件或 Context 传入
|
|
34
|
+
position: [number, number, number];
|
|
35
|
+
color: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const BoxElement: React.FC<BoxProps> = ({ scene, position, color }) => {
|
|
39
|
+
const meshRef = useRef<THREE.Mesh>();
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
// 初始化物体
|
|
43
|
+
const geo = new THREE.BoxGeometry(1, 1, 1);
|
|
44
|
+
const mat = new THREE.MeshStandardMaterial({ color });
|
|
45
|
+
const mesh = new THREE.Mesh(geo, mat);
|
|
46
|
+
mesh.position.set(...position);
|
|
47
|
+
|
|
48
|
+
// 挂载到全局场景
|
|
49
|
+
scene.add(mesh);
|
|
50
|
+
meshRef.current = mesh;
|
|
51
|
+
|
|
52
|
+
// 销毁逻辑:必须彻底释放显存
|
|
53
|
+
return () => {
|
|
54
|
+
scene.remove(mesh);
|
|
55
|
+
geo.dispose();
|
|
56
|
+
mat.dispose();
|
|
57
|
+
};
|
|
58
|
+
}, [scene]); // 仅在场景对象变更时重新初始化
|
|
59
|
+
|
|
60
|
+
// 监听属性变化并同步到 Three.js 对象
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (meshRef.current) {
|
|
63
|
+
meshRef.current.position.set(...position);
|
|
64
|
+
(meshRef.current.material as THREE.MeshStandardMaterial).color.set(color);
|
|
65
|
+
}
|
|
66
|
+
}, [position, color]);
|
|
67
|
+
|
|
68
|
+
return null; // 这是一个逻辑组件,不渲染任何 DOM
|
|
69
|
+
};
|
|
70
|
+
```
|
|
71
|
+
## 调试与诊断
|
|
72
|
+
1. **物体未显示**:
|
|
73
|
+
- 确认子组件是否正确执行了 scene.add()。
|
|
74
|
+
- 确认 mesh.frustumCulled 是否导致物体在相机视野外被剔除。
|
|
75
|
+
- **检查父组件的渲染循环 (requestAnimationFrame) 是否正在运行。
|
|
76
|
+
2. **内存持续增长**: 检查子组件卸载时是否遗漏了 geometry.dispose()。使用 renderer.info.memory 监控资源。
|
|
77
|
+
3. **重复添加**: 确保 scene.add 逻辑在 useEffect 中有正确的清理机制,防止 React StrictMode 下重复挂载。
|
|
78
|
+
|
|
79
|
+
## 注意事项
|
|
80
|
+
1. **计算逻辑**: 复杂的几何计算应放在 useMemo 中或单独的 worker 中,避免阻塞 React 主线程。
|
|
81
|
+
2. **渲染频率**: 不要将 Three.js 的每一帧状态同步回 React 的 State,这会导致严重的性能瓶颈。
|
|
82
|
+
3. **坐标系一致性**: 在分布式开发中,所有子组件应约定使用统一的比例尺和坐标基准。
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file defines how agentic coding assistants should operate in this repository.
|
|
4
|
+
It is consumed by tools such as OpenCode, Cursor, Claude Code, etc.
|
|
5
|
+
|
|
6
|
+
======================================================================
|
|
7
|
+
Project Overview
|
|
8
|
+
======================================================================
|
|
9
|
+
|
|
10
|
+
Project name: brain-ui
|
|
11
|
+
|
|
12
|
+
This is a frontend UI project built with:
|
|
13
|
+
|
|
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.
|
|
23
|
+
|
|
24
|
+
======================================================================
|
|
25
|
+
Package Management
|
|
26
|
+
======================================================================
|
|
27
|
+
|
|
28
|
+
Preferred package manager:
|
|
29
|
+
- pnpm (preferred if lockfile exists)
|
|
30
|
+
- npm or yarn if pnpm is unavailable
|
|
31
|
+
|
|
32
|
+
Do NOT introduce new dependencies unless explicitly requested.
|
|
33
|
+
|
|
34
|
+
======================================================================
|
|
35
|
+
Development / Build Commands
|
|
36
|
+
======================================================================
|
|
37
|
+
|
|
38
|
+
Install dependencies:
|
|
39
|
+
- pnpm install
|
|
40
|
+
- npm install
|
|
41
|
+
- yarn install
|
|
42
|
+
|
|
43
|
+
Start development server:
|
|
44
|
+
- pnpm dev
|
|
45
|
+
- npm run dev
|
|
46
|
+
|
|
47
|
+
Production build:
|
|
48
|
+
- pnpm build
|
|
49
|
+
- npm run build
|
|
50
|
+
|
|
51
|
+
Preview production build:
|
|
52
|
+
- pnpm preview
|
|
53
|
+
- npm run preview
|
|
54
|
+
|
|
55
|
+
======================================================================
|
|
56
|
+
Storybook
|
|
57
|
+
======================================================================
|
|
58
|
+
|
|
59
|
+
Run Storybook locally:
|
|
60
|
+
- pnpm storybook
|
|
61
|
+
- npm run storybook
|
|
62
|
+
|
|
63
|
+
Build Storybook:
|
|
64
|
+
- pnpm build-storybook
|
|
65
|
+
- npm run build-storybook
|
|
66
|
+
|
|
67
|
+
Story files should be colocated with components and named:
|
|
68
|
+
- *.stories.tsx
|
|
69
|
+
|
|
70
|
+
======================================================================
|
|
71
|
+
TypeScript Rules
|
|
72
|
+
======================================================================
|
|
73
|
+
|
|
74
|
+
- Always use TypeScript (.ts / .tsx)
|
|
75
|
+
- Avoid `any` unless absolutely unavoidable
|
|
76
|
+
- Prefer explicit types for:
|
|
77
|
+
- component props
|
|
78
|
+
- public functions
|
|
79
|
+
- Use `interface` for component props and public APIs
|
|
80
|
+
- Use `type` for unions, utility types, and internal helpers
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
|
|
84
|
+
interface ComponentProps {
|
|
85
|
+
value: number;
|
|
86
|
+
onChange?: (value: number) => void;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
======================================================================
|
|
90
|
+
React Rules
|
|
91
|
+
======================================================================
|
|
92
|
+
|
|
93
|
+
- Use function components only
|
|
94
|
+
- Do NOT use class components
|
|
95
|
+
- Follow the Rules of Hooks
|
|
96
|
+
- Prefer composition over inheritance
|
|
97
|
+
- Extract reusable logic into custom hooks
|
|
98
|
+
- Avoid deeply nested JSX structures
|
|
99
|
+
|
|
100
|
+
State management:
|
|
101
|
+
- Prefer local state (useState / useReducer)
|
|
102
|
+
- Avoid unnecessary global state
|
|
103
|
+
- Use refs for mutable values that should not trigger re-render
|
|
104
|
+
|
|
105
|
+
======================================================================
|
|
106
|
+
Component Structure
|
|
107
|
+
======================================================================
|
|
108
|
+
|
|
109
|
+
Recommended component structure:
|
|
110
|
+
|
|
111
|
+
ComponentName/
|
|
112
|
+
├─ index.tsx
|
|
113
|
+
├─ index.less | index.css | index.scss
|
|
114
|
+
├─ ComponentName.stories.tsx
|
|
115
|
+
└─ types.ts (optional)
|
|
116
|
+
|
|
117
|
+
Rules:
|
|
118
|
+
- index.tsx exports the component
|
|
119
|
+
- styles are colocated with the component
|
|
120
|
+
- stories demonstrate common usage and edge cases
|
|
121
|
+
|
|
122
|
+
======================================================================
|
|
123
|
+
Ant Design (antd) Usage
|
|
124
|
+
======================================================================
|
|
125
|
+
|
|
126
|
+
- Use antd components as the primary UI building blocks
|
|
127
|
+
- Avoid copying or modifying antd internal styles
|
|
128
|
+
- Prefer composition instead of overriding antd components
|
|
129
|
+
- Use className or style props for customization
|
|
130
|
+
- Avoid deep CSS selectors targeting antd internals
|
|
131
|
+
|
|
132
|
+
======================================================================
|
|
133
|
+
Three.js Usage
|
|
134
|
+
======================================================================
|
|
135
|
+
|
|
136
|
+
- Keep Three.js logic isolated from UI logic when possible
|
|
137
|
+
- Avoid heavy allocations inside render loops
|
|
138
|
+
- Be mindful of GPU memory usage
|
|
139
|
+
- Always clean up resources when no longer needed:
|
|
140
|
+
- geometry.dispose()
|
|
141
|
+
- material.dispose()
|
|
142
|
+
- texture.dispose()
|
|
143
|
+
|
|
144
|
+
- Avoid unnecessary re-creation of:
|
|
145
|
+
- geometries
|
|
146
|
+
- materials
|
|
147
|
+
- textures
|
|
148
|
+
- Prefer memoization for expensive objects
|
|
149
|
+
|
|
150
|
+
======================================================================
|
|
151
|
+
Performance Guidelines
|
|
152
|
+
======================================================================
|
|
153
|
+
|
|
154
|
+
- Avoid unnecessary re-renders
|
|
155
|
+
- Use useMemo / useCallback for expensive computations
|
|
156
|
+
- Do not create new objects/functions inside render unless required
|
|
157
|
+
- Be careful with requestAnimationFrame loops
|
|
158
|
+
- Pay attention to performance in Three.js related code
|
|
159
|
+
|
|
160
|
+
======================================================================
|
|
161
|
+
Error Handling
|
|
162
|
+
======================================================================
|
|
163
|
+
|
|
164
|
+
- Do not silently swallow errors
|
|
165
|
+
- Log meaningful error messages
|
|
166
|
+
- Validate external or dynamic data before usage
|
|
167
|
+
- Prefer early returns over deeply nested conditionals
|
|
168
|
+
|
|
169
|
+
======================================================================
|
|
170
|
+
Imports & Naming
|
|
171
|
+
======================================================================
|
|
172
|
+
|
|
173
|
+
Imports order:
|
|
174
|
+
1. React and external libraries
|
|
175
|
+
2. UI components
|
|
176
|
+
3. hooks / utils
|
|
177
|
+
4. styles
|
|
178
|
+
|
|
179
|
+
Naming conventions:
|
|
180
|
+
- Components: PascalCase
|
|
181
|
+
- Hooks: useSomething
|
|
182
|
+
- Files: follow existing project convention
|
|
183
|
+
- Variables: camelCase
|
|
184
|
+
|
|
185
|
+
======================================================================
|
|
186
|
+
Testing (If Present)
|
|
187
|
+
======================================================================
|
|
188
|
+
|
|
189
|
+
- Prefer testing public behavior over implementation details
|
|
190
|
+
- Avoid excessive snapshot testing
|
|
191
|
+
- Keep tests focused and readable
|
|
192
|
+
|
|
193
|
+
======================================================================
|
|
194
|
+
Agent Behavior Rules (IMPORTANT)
|
|
195
|
+
======================================================================
|
|
196
|
+
|
|
197
|
+
When modifying code, agents MUST:
|
|
198
|
+
|
|
199
|
+
1. Read existing code before making changes
|
|
200
|
+
2. Follow existing patterns and conventions
|
|
201
|
+
3. Keep changes minimal and scoped
|
|
202
|
+
4. Do NOT refactor unrelated code
|
|
203
|
+
5. Do NOT introduce new dependencies unless requested
|
|
204
|
+
6. Ensure TypeScript types remain correct
|
|
205
|
+
7. Ensure Storybook stories still work if affected
|
|
206
|
+
|
|
207
|
+
If a change is non-trivial, explain WHY the change is needed.
|
|
208
|
+
|
|
209
|
+
======================================================================
|
|
210
|
+
Out of Scope
|
|
211
|
+
======================================================================
|
|
212
|
+
|
|
213
|
+
- Backend logic
|
|
214
|
+
- API implementations
|
|
215
|
+
- CI/CD configuration unless explicitly requested
|
|
216
|
+
|
|
217
|
+
======================================================================
|
|
218
|
+
End of AGENTS.md
|
|
219
|
+
======================================================================
|