@xdy-npm/react-particle-backgrounds 1.0.0 → 1.0.2
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/README.md +46 -46
- package/dist/index.d.mts +30 -30
- package/dist/index.d.ts +30 -30
- package/dist/index.js +62 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
# react-particle-backgrounds
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个基于 [tsparticles](https://particles.js.org/) 和 [Three.js](https://threejs.org/) 的 React 粒子背景组件库,提供 **7 种精美粒子背景主题**。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 主题一览
|
|
6
6
|
|
|
7
|
-
|
|
|
8
|
-
|
|
9
|
-
| ✨
|
|
10
|
-
| ❄️
|
|
11
|
-
| 🫧
|
|
12
|
-
| ⭐
|
|
13
|
-
| 🪲
|
|
14
|
-
| 🔷
|
|
15
|
-
| 🌊
|
|
16
|
-
| 🚫
|
|
7
|
+
| 主题 | ID | 描述 |
|
|
8
|
+
|------|----|------|
|
|
9
|
+
| ✨ 星链 | `starline` | 经典粒子连线效果 |
|
|
10
|
+
| ❄️ 飘雪 | `snow` | 浪漫飘落雪花 |
|
|
11
|
+
| 🫧 气泡 | `bubble` | 梦幻上升气泡 |
|
|
12
|
+
| ⭐ 繁星 | `stars` | 闪烁星空效果 |
|
|
13
|
+
| 🪲 萤火虫 | `firefly` | 温暖的萤火虫光效 |
|
|
14
|
+
| 🔷 几何 | `geometry` | 漂浮的抽象几何图形 |
|
|
15
|
+
| 🌊 粒子海洋 | `wave` | 3D 粒子波浪(Three.js) |
|
|
16
|
+
| 🚫 无 | `none` | 关闭粒子效果 |
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## 安装
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
21
|
npm install @xdy-npm/react-particle-backgrounds
|
|
22
|
-
#
|
|
22
|
+
# 或
|
|
23
23
|
pnpm add @xdy-npm/react-particle-backgrounds
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
如需使用**粒子海洋**(wave)主题,还需要安装 Three.js:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
npm install three
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## 快速开始
|
|
33
33
|
|
|
34
|
-
###
|
|
34
|
+
### 基础用法(Props 方式)
|
|
35
35
|
|
|
36
36
|
```tsx
|
|
37
37
|
import { ParticlesBackground } from '@xdy-npm/react-particle-backgrounds';
|
|
@@ -48,7 +48,7 @@ function App() {
|
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
###
|
|
51
|
+
### 配合主题选择器(Context 方式)
|
|
52
52
|
|
|
53
53
|
```tsx
|
|
54
54
|
import {
|
|
@@ -70,7 +70,7 @@ function App() {
|
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
###
|
|
73
|
+
### 编程式切换主题
|
|
74
74
|
|
|
75
75
|
```tsx
|
|
76
76
|
import {
|
|
@@ -84,7 +84,7 @@ function ThemeButton() {
|
|
|
84
84
|
|
|
85
85
|
return (
|
|
86
86
|
<button onClick={() => setTheme('firefly')}>
|
|
87
|
-
|
|
87
|
+
当前:{themeId} — 切换到萤火虫
|
|
88
88
|
</button>
|
|
89
89
|
);
|
|
90
90
|
}
|
|
@@ -103,52 +103,52 @@ function App() {
|
|
|
103
103
|
|
|
104
104
|
### `<ParticlesBackground />`
|
|
105
105
|
|
|
106
|
-
|
|
|
107
|
-
|
|
108
|
-
| `theme` | `ThemeId \| string` | `'starline'` |
|
|
109
|
-
| `isDark` | `boolean` | `true` |
|
|
110
|
-
| `onLoaded` | `(container?) => void` | — |
|
|
111
|
-
| `className` | `string` | — | CSS
|
|
112
|
-
| `style` | `CSSProperties` | — |
|
|
106
|
+
| 属性 | 类型 | 默认值 | 描述 |
|
|
107
|
+
|------|------|--------|------|
|
|
108
|
+
| `theme` | `ThemeId \| string` | `'starline'` | 主题 ID(会覆盖 Provider 中的设置) |
|
|
109
|
+
| `isDark` | `boolean` | `true` | 深色模式开关 |
|
|
110
|
+
| `onLoaded` | `(container?) => void` | — | 粒子加载完成的回调 |
|
|
111
|
+
| `className` | `string` | — | CSS 类名 |
|
|
112
|
+
| `style` | `CSSProperties` | — | 行内样式 |
|
|
113
113
|
|
|
114
114
|
### `<ParticleProvider />`
|
|
115
115
|
|
|
116
|
-
|
|
|
117
|
-
|
|
118
|
-
| `defaultTheme` | `ThemeId \| string` | `'starline'` |
|
|
119
|
-
| `isDark` | `boolean` | `true` |
|
|
120
|
-
| `persist` | `boolean` | `true` |
|
|
121
|
-
| `children` | `ReactNode` | — |
|
|
116
|
+
| 属性 | 类型 | 默认值 | 描述 |
|
|
117
|
+
|------|------|--------|------|
|
|
118
|
+
| `defaultTheme` | `ThemeId \| string` | `'starline'` | 初始主题 |
|
|
119
|
+
| `isDark` | `boolean` | `true` | 深色模式状态 |
|
|
120
|
+
| `persist` | `boolean` | `true` | 是否持久化到 localStorage |
|
|
121
|
+
| `children` | `ReactNode` | — | 子组件 |
|
|
122
122
|
|
|
123
123
|
### `<ThemeSelector />`
|
|
124
124
|
|
|
125
|
-
|
|
|
126
|
-
|
|
127
|
-
| `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` |
|
|
128
|
-
| `accentColor` | `string` | `'#3b82f6'` |
|
|
125
|
+
| 属性 | 类型 | 默认值 | 描述 |
|
|
126
|
+
|------|------|--------|------|
|
|
127
|
+
| `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | 按钮位置 |
|
|
128
|
+
| `accentColor` | `string` | `'#3b82f6'` | 激活状态颜色 |
|
|
129
129
|
|
|
130
130
|
### `useParticleTheme()`
|
|
131
131
|
|
|
132
|
-
Hook
|
|
132
|
+
用于访问主题状态的 Hook(必须在 `<ParticleProvider>` 内使用)。
|
|
133
133
|
|
|
134
134
|
```ts
|
|
135
135
|
const { themeId, isDark, setTheme, setDark } = useParticleTheme();
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
###
|
|
138
|
+
### 主题对象
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
访问单个主题配置:
|
|
141
141
|
|
|
142
142
|
```ts
|
|
143
143
|
import { starlineTheme, particleThemes, getThemeById } from '@xdy-npm/react-particle-backgrounds';
|
|
144
144
|
|
|
145
145
|
const theme = getThemeById('snow');
|
|
146
|
-
const options = theme.options(true); //
|
|
146
|
+
const options = theme.options(true); // 获取深色模式下的 tsparticles 配置
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
##
|
|
149
|
+
## 自定义主题
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
你可以创建自己的主题并直接传入:
|
|
152
152
|
|
|
153
153
|
```tsx
|
|
154
154
|
import type { ParticleTheme } from '@xdy-npm/react-particle-backgrounds';
|
|
@@ -156,9 +156,9 @@ import { baseConfig } from '@xdy-npm/react-particle-backgrounds';
|
|
|
156
156
|
|
|
157
157
|
const myTheme: ParticleTheme = {
|
|
158
158
|
id: 'custom',
|
|
159
|
-
name: '
|
|
159
|
+
name: '我的主题',
|
|
160
160
|
icon: '🎨',
|
|
161
|
-
description: '
|
|
161
|
+
description: '一个自定义粒子主题',
|
|
162
162
|
options: (isDark) => ({
|
|
163
163
|
...baseConfig,
|
|
164
164
|
particles: {
|
|
@@ -172,6 +172,6 @@ const myTheme: ParticleTheme = {
|
|
|
172
172
|
};
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
##
|
|
175
|
+
## 许可证
|
|
176
176
|
|
|
177
177
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -6,41 +6,41 @@ interface ParticleTheme {
|
|
|
6
6
|
name: string;
|
|
7
7
|
icon: string;
|
|
8
8
|
description: string;
|
|
9
|
-
/**
|
|
9
|
+
/** 是否使用 Three.js 而非 tsparticles */
|
|
10
10
|
isThreeJS?: boolean;
|
|
11
|
-
/**
|
|
11
|
+
/** 根据深色模式状态返回 tsparticles 配置 */
|
|
12
12
|
options: (isDark: boolean) => ISourceOptions;
|
|
13
|
-
/**
|
|
13
|
+
/** 纯色背景色 */
|
|
14
14
|
backgroundColor?: string;
|
|
15
|
-
/** CSS
|
|
15
|
+
/** CSS 渐变背景 */
|
|
16
16
|
backgroundGradient?: string;
|
|
17
17
|
}
|
|
18
18
|
type ThemeId = 'starline' | 'snow' | 'bubble' | 'stars' | 'firefly' | 'geometry' | 'wave' | 'none';
|
|
19
19
|
|
|
20
20
|
interface ParticlesBackgroundProps {
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* 要显示的主题 ID。如果在 `<ParticleProvider>` 内使用,
|
|
23
|
+
* 此属性可选,会自动使用 Provider 中的主题。
|
|
24
24
|
*/
|
|
25
25
|
theme?: ThemeId | string;
|
|
26
|
-
/**
|
|
26
|
+
/** 深色模式开关 — 影响支持的主题的粒子颜色 */
|
|
27
27
|
isDark?: boolean;
|
|
28
|
-
/**
|
|
28
|
+
/** 粒子加载完成的回调 */
|
|
29
29
|
onLoaded?: (container?: Container) => void;
|
|
30
|
-
/**
|
|
30
|
+
/** 自定义 CSS 类名 */
|
|
31
31
|
className?: string;
|
|
32
|
-
/**
|
|
32
|
+
/** 自定义行内样式 */
|
|
33
33
|
style?: React.CSSProperties;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* 渲染全屏粒子背景。
|
|
37
37
|
*
|
|
38
|
-
*
|
|
38
|
+
* 可以通过 props 独立使用:
|
|
39
39
|
* ```tsx
|
|
40
40
|
* <ParticlesBackground theme="starline" isDark />
|
|
41
41
|
* ```
|
|
42
42
|
*
|
|
43
|
-
*
|
|
43
|
+
* 也可以在 `<ParticleProvider>` 内使用以共享状态:
|
|
44
44
|
* ```tsx
|
|
45
45
|
* <ParticleProvider defaultTheme="snow">
|
|
46
46
|
* <ParticlesBackground />
|
|
@@ -50,14 +50,14 @@ interface ParticlesBackgroundProps {
|
|
|
50
50
|
declare const ParticlesBackground: React.FC<ParticlesBackgroundProps>;
|
|
51
51
|
|
|
52
52
|
interface ThemeSelectorProps {
|
|
53
|
-
/**
|
|
53
|
+
/** 在屏幕上的位置 */
|
|
54
54
|
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
55
|
-
/**
|
|
55
|
+
/** 激活状态的强调色 */
|
|
56
56
|
accentColor?: string;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* 浮动主题选择器按钮 + 抽屉面板。
|
|
60
|
+
* 必须在 `<ParticleProvider>` 内使用。
|
|
61
61
|
*
|
|
62
62
|
* ```tsx
|
|
63
63
|
* <ParticleProvider>
|
|
@@ -69,14 +69,14 @@ interface ThemeSelectorProps {
|
|
|
69
69
|
declare const ThemeSelector: React.FC<ThemeSelectorProps>;
|
|
70
70
|
|
|
71
71
|
interface ParticleWaveProps {
|
|
72
|
-
/** CSS
|
|
72
|
+
/** 波浪背后的 CSS 渐变或纯色背景 */
|
|
73
73
|
background?: string;
|
|
74
74
|
className?: string;
|
|
75
75
|
style?: React.CSSProperties;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
79
|
-
* Three.js
|
|
78
|
+
* 使用 Three.js 渲染的 3D 粒子海洋波浪。
|
|
79
|
+
* Three.js 以动态方式加载 — 如果未安装,此组件不会渲染任何内容。
|
|
80
80
|
*/
|
|
81
81
|
declare const ParticleWave: React.FC<ParticleWaveProps>;
|
|
82
82
|
|
|
@@ -87,25 +87,25 @@ interface ParticleContextValue {
|
|
|
87
87
|
setDark: (dark: boolean) => void;
|
|
88
88
|
}
|
|
89
89
|
interface ParticleProviderProps {
|
|
90
|
-
/**
|
|
90
|
+
/** 初始/默认主题 ID */
|
|
91
91
|
defaultTheme?: ThemeId | string;
|
|
92
|
-
/**
|
|
92
|
+
/** 是否使用深色模式粒子颜色 */
|
|
93
93
|
isDark?: boolean;
|
|
94
|
-
/**
|
|
94
|
+
/** 是否将主题选择持久化到 localStorage */
|
|
95
95
|
persist?: boolean;
|
|
96
96
|
children: React.ReactNode;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* `<ParticlesBackground />`
|
|
99
|
+
* 为子组件提供粒子主题状态。
|
|
100
|
+
* 用此 Provider 包裹你的应用(或子树),即可无需显式传参地使用
|
|
101
|
+
* `<ParticlesBackground />` 和 `<ThemeSelector />`。
|
|
102
102
|
*/
|
|
103
103
|
declare const ParticleProvider: React.FC<ParticleProviderProps>;
|
|
104
|
-
/**
|
|
104
|
+
/** 访问当前粒子主题上下文。必须在 `<ParticleProvider>` 内使用。 */
|
|
105
105
|
declare const useParticleTheme: () => ParticleContextValue;
|
|
106
106
|
|
|
107
107
|
declare const baseConfig: Partial<ISourceOptions>;
|
|
108
|
-
/**
|
|
108
|
+
/** 支持多色粒子的主题所使用的默认强调色 */
|
|
109
109
|
declare const DEFAULT_COLORS: string[];
|
|
110
110
|
|
|
111
111
|
declare const starlineTheme: ParticleTheme;
|
|
@@ -122,9 +122,9 @@ declare const geometryTheme: ParticleTheme;
|
|
|
122
122
|
|
|
123
123
|
declare const waveTheme: ParticleTheme;
|
|
124
124
|
|
|
125
|
-
/**
|
|
125
|
+
/** 所有内置粒子主题(不包含 "none") */
|
|
126
126
|
declare const particleThemes: ParticleTheme[];
|
|
127
|
-
/**
|
|
127
|
+
/** 根据 ID 获取主题。找不到时回退到 starline。 */
|
|
128
128
|
declare const getThemeById: (id: string) => ParticleTheme;
|
|
129
129
|
declare const DEFAULT_THEME_ID = "starline";
|
|
130
130
|
|
package/dist/index.d.ts
CHANGED
|
@@ -6,41 +6,41 @@ interface ParticleTheme {
|
|
|
6
6
|
name: string;
|
|
7
7
|
icon: string;
|
|
8
8
|
description: string;
|
|
9
|
-
/**
|
|
9
|
+
/** 是否使用 Three.js 而非 tsparticles */
|
|
10
10
|
isThreeJS?: boolean;
|
|
11
|
-
/**
|
|
11
|
+
/** 根据深色模式状态返回 tsparticles 配置 */
|
|
12
12
|
options: (isDark: boolean) => ISourceOptions;
|
|
13
|
-
/**
|
|
13
|
+
/** 纯色背景色 */
|
|
14
14
|
backgroundColor?: string;
|
|
15
|
-
/** CSS
|
|
15
|
+
/** CSS 渐变背景 */
|
|
16
16
|
backgroundGradient?: string;
|
|
17
17
|
}
|
|
18
18
|
type ThemeId = 'starline' | 'snow' | 'bubble' | 'stars' | 'firefly' | 'geometry' | 'wave' | 'none';
|
|
19
19
|
|
|
20
20
|
interface ParticlesBackgroundProps {
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* 要显示的主题 ID。如果在 `<ParticleProvider>` 内使用,
|
|
23
|
+
* 此属性可选,会自动使用 Provider 中的主题。
|
|
24
24
|
*/
|
|
25
25
|
theme?: ThemeId | string;
|
|
26
|
-
/**
|
|
26
|
+
/** 深色模式开关 — 影响支持的主题的粒子颜色 */
|
|
27
27
|
isDark?: boolean;
|
|
28
|
-
/**
|
|
28
|
+
/** 粒子加载完成的回调 */
|
|
29
29
|
onLoaded?: (container?: Container) => void;
|
|
30
|
-
/**
|
|
30
|
+
/** 自定义 CSS 类名 */
|
|
31
31
|
className?: string;
|
|
32
|
-
/**
|
|
32
|
+
/** 自定义行内样式 */
|
|
33
33
|
style?: React.CSSProperties;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* 渲染全屏粒子背景。
|
|
37
37
|
*
|
|
38
|
-
*
|
|
38
|
+
* 可以通过 props 独立使用:
|
|
39
39
|
* ```tsx
|
|
40
40
|
* <ParticlesBackground theme="starline" isDark />
|
|
41
41
|
* ```
|
|
42
42
|
*
|
|
43
|
-
*
|
|
43
|
+
* 也可以在 `<ParticleProvider>` 内使用以共享状态:
|
|
44
44
|
* ```tsx
|
|
45
45
|
* <ParticleProvider defaultTheme="snow">
|
|
46
46
|
* <ParticlesBackground />
|
|
@@ -50,14 +50,14 @@ interface ParticlesBackgroundProps {
|
|
|
50
50
|
declare const ParticlesBackground: React.FC<ParticlesBackgroundProps>;
|
|
51
51
|
|
|
52
52
|
interface ThemeSelectorProps {
|
|
53
|
-
/**
|
|
53
|
+
/** 在屏幕上的位置 */
|
|
54
54
|
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
55
|
-
/**
|
|
55
|
+
/** 激活状态的强调色 */
|
|
56
56
|
accentColor?: string;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* 浮动主题选择器按钮 + 抽屉面板。
|
|
60
|
+
* 必须在 `<ParticleProvider>` 内使用。
|
|
61
61
|
*
|
|
62
62
|
* ```tsx
|
|
63
63
|
* <ParticleProvider>
|
|
@@ -69,14 +69,14 @@ interface ThemeSelectorProps {
|
|
|
69
69
|
declare const ThemeSelector: React.FC<ThemeSelectorProps>;
|
|
70
70
|
|
|
71
71
|
interface ParticleWaveProps {
|
|
72
|
-
/** CSS
|
|
72
|
+
/** 波浪背后的 CSS 渐变或纯色背景 */
|
|
73
73
|
background?: string;
|
|
74
74
|
className?: string;
|
|
75
75
|
style?: React.CSSProperties;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
79
|
-
* Three.js
|
|
78
|
+
* 使用 Three.js 渲染的 3D 粒子海洋波浪。
|
|
79
|
+
* Three.js 以动态方式加载 — 如果未安装,此组件不会渲染任何内容。
|
|
80
80
|
*/
|
|
81
81
|
declare const ParticleWave: React.FC<ParticleWaveProps>;
|
|
82
82
|
|
|
@@ -87,25 +87,25 @@ interface ParticleContextValue {
|
|
|
87
87
|
setDark: (dark: boolean) => void;
|
|
88
88
|
}
|
|
89
89
|
interface ParticleProviderProps {
|
|
90
|
-
/**
|
|
90
|
+
/** 初始/默认主题 ID */
|
|
91
91
|
defaultTheme?: ThemeId | string;
|
|
92
|
-
/**
|
|
92
|
+
/** 是否使用深色模式粒子颜色 */
|
|
93
93
|
isDark?: boolean;
|
|
94
|
-
/**
|
|
94
|
+
/** 是否将主题选择持久化到 localStorage */
|
|
95
95
|
persist?: boolean;
|
|
96
96
|
children: React.ReactNode;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* `<ParticlesBackground />`
|
|
99
|
+
* 为子组件提供粒子主题状态。
|
|
100
|
+
* 用此 Provider 包裹你的应用(或子树),即可无需显式传参地使用
|
|
101
|
+
* `<ParticlesBackground />` 和 `<ThemeSelector />`。
|
|
102
102
|
*/
|
|
103
103
|
declare const ParticleProvider: React.FC<ParticleProviderProps>;
|
|
104
|
-
/**
|
|
104
|
+
/** 访问当前粒子主题上下文。必须在 `<ParticleProvider>` 内使用。 */
|
|
105
105
|
declare const useParticleTheme: () => ParticleContextValue;
|
|
106
106
|
|
|
107
107
|
declare const baseConfig: Partial<ISourceOptions>;
|
|
108
|
-
/**
|
|
108
|
+
/** 支持多色粒子的主题所使用的默认强调色 */
|
|
109
109
|
declare const DEFAULT_COLORS: string[];
|
|
110
110
|
|
|
111
111
|
declare const starlineTheme: ParticleTheme;
|
|
@@ -122,9 +122,9 @@ declare const geometryTheme: ParticleTheme;
|
|
|
122
122
|
|
|
123
123
|
declare const waveTheme: ParticleTheme;
|
|
124
124
|
|
|
125
|
-
/**
|
|
125
|
+
/** 所有内置粒子主题(不包含 "none") */
|
|
126
126
|
declare const particleThemes: ParticleTheme[];
|
|
127
|
-
/**
|
|
127
|
+
/** 根据 ID 获取主题。找不到时回退到 starline。 */
|
|
128
128
|
declare const getThemeById: (id: string) => ParticleTheme;
|
|
129
129
|
declare const DEFAULT_THEME_ID = "starline";
|
|
130
130
|
|