@xdy-npm/react-particle-backgrounds 1.0.0 → 1.0.1
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 +47 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -23
- 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
|
|
package/dist/index.js
CHANGED
|
@@ -39,9 +39,9 @@ var DEFAULT_COLORS = [
|
|
|
39
39
|
// src/themes/starline.ts
|
|
40
40
|
var starlineTheme = {
|
|
41
41
|
id: "starline",
|
|
42
|
-
name: "
|
|
42
|
+
name: "\u661F\u94FE",
|
|
43
43
|
icon: "\u2728",
|
|
44
|
-
description: "
|
|
44
|
+
description: "\u7ECF\u5178\u7C92\u5B50\u8FDE\u7EBF\u6548\u679C",
|
|
45
45
|
backgroundGradient: "linear-gradient(180deg, #0f172a 0%, #1e293b 50%, #334155 100%)",
|
|
46
46
|
options: (isDark) => {
|
|
47
47
|
const colors = DEFAULT_COLORS;
|
|
@@ -100,9 +100,9 @@ var starlineTheme = {
|
|
|
100
100
|
// src/themes/snow.ts
|
|
101
101
|
var snowTheme = {
|
|
102
102
|
id: "snow",
|
|
103
|
-
name: "
|
|
103
|
+
name: "\u98D8\u96EA",
|
|
104
104
|
icon: "\u2744\uFE0F",
|
|
105
|
-
description: "
|
|
105
|
+
description: "\u6D6A\u6F2B\u98D8\u843D\u96EA\u82B1",
|
|
106
106
|
backgroundGradient: "linear-gradient(180deg, #1e3a5f 0%, #2d4a6b 50%, #3d5a7b 100%)",
|
|
107
107
|
options: (isDark) => ({
|
|
108
108
|
...baseConfig,
|
|
@@ -154,9 +154,9 @@ var snowTheme = {
|
|
|
154
154
|
// src/themes/bubble.ts
|
|
155
155
|
var bubbleTheme = {
|
|
156
156
|
id: "bubble",
|
|
157
|
-
name: "
|
|
157
|
+
name: "\u6C14\u6CE1",
|
|
158
158
|
icon: "\u{1FAE7}",
|
|
159
|
-
description: "
|
|
159
|
+
description: "\u68A6\u5E7B\u4E0A\u5347\u6C14\u6CE1",
|
|
160
160
|
backgroundGradient: "linear-gradient(180deg, #0a2647 0%, #144272 50%, #205295 100%)",
|
|
161
161
|
options: (isDark) => ({
|
|
162
162
|
...baseConfig,
|
|
@@ -213,9 +213,9 @@ var bubbleTheme = {
|
|
|
213
213
|
// src/themes/stars.ts
|
|
214
214
|
var starsTheme = {
|
|
215
215
|
id: "stars",
|
|
216
|
-
name: "
|
|
216
|
+
name: "\u7E41\u661F",
|
|
217
217
|
icon: "\u2B50",
|
|
218
|
-
description: "
|
|
218
|
+
description: "\u95EA\u70C1\u661F\u7A7A\u6548\u679C",
|
|
219
219
|
backgroundGradient: "linear-gradient(180deg, #000000 0%, #1a1a2e 50%, #16213e 100%)",
|
|
220
220
|
options: (isDark) => ({
|
|
221
221
|
...baseConfig,
|
|
@@ -280,9 +280,9 @@ var starsTheme = {
|
|
|
280
280
|
// src/themes/firefly.ts
|
|
281
281
|
var fireflyTheme = {
|
|
282
282
|
id: "firefly",
|
|
283
|
-
name: "
|
|
283
|
+
name: "\u8424\u706B\u866B",
|
|
284
284
|
icon: "\u{1FAB2}",
|
|
285
|
-
description: "
|
|
285
|
+
description: "\u6E29\u6696\u7684\u8424\u706B\u866B\u5149\u6548",
|
|
286
286
|
backgroundGradient: "linear-gradient(180deg, #1a1a1a 0%, #2d2d2d 50%, #1a1a1a 100%)",
|
|
287
287
|
options: (isDark) => ({
|
|
288
288
|
...baseConfig,
|
|
@@ -341,9 +341,9 @@ var fireflyTheme = {
|
|
|
341
341
|
// src/themes/geometry.ts
|
|
342
342
|
var geometryTheme = {
|
|
343
343
|
id: "geometry",
|
|
344
|
-
name: "
|
|
344
|
+
name: "\u51E0\u4F55",
|
|
345
345
|
icon: "\u{1F537}",
|
|
346
|
-
description: "
|
|
346
|
+
description: "\u6F02\u6D6E\u7684\u62BD\u8C61\u51E0\u4F55\u56FE\u5F62",
|
|
347
347
|
backgroundGradient: "linear-gradient(180deg, #0f0c29 0%, #302b63 50%, #24243e 100%)",
|
|
348
348
|
options: (isDark) => ({
|
|
349
349
|
...baseConfig,
|
|
@@ -407,9 +407,9 @@ var geometryTheme = {
|
|
|
407
407
|
// src/themes/wave.ts
|
|
408
408
|
var waveTheme = {
|
|
409
409
|
id: "wave",
|
|
410
|
-
name: "
|
|
410
|
+
name: "\u7C92\u5B50\u6D77\u6D0B",
|
|
411
411
|
icon: "\u{1F30A}",
|
|
412
|
-
description: "3D
|
|
412
|
+
description: "3D \u7C92\u5B50\u6CE2\u6D6A\u6548\u679C\uFF08\u9700\u8981 three.js\uFF09",
|
|
413
413
|
isThreeJS: true,
|
|
414
414
|
backgroundGradient: "linear-gradient(180deg, #000000 0%, #0a1628 50%, #0d1f3c 100%)",
|
|
415
415
|
options: () => ({
|
|
@@ -486,7 +486,7 @@ var ParticleWave = ({
|
|
|
486
486
|
})();
|
|
487
487
|
} catch (e) {
|
|
488
488
|
hasThree.current = false;
|
|
489
|
-
console.warn('[react-particle-backgrounds] "three"
|
|
489
|
+
console.warn('[react-particle-backgrounds] \u672A\u5B89\u88C5 "three"\u3002\u6CE2\u6D6A\u4E3B\u9898\u9700\u8981\u5B83\u4F5C\u4E3A peer dependency\u3002');
|
|
490
490
|
return;
|
|
491
491
|
}
|
|
492
492
|
if (!containerRef.current) return;
|
|
@@ -821,6 +821,7 @@ var ParticleWave = ({
|
|
|
821
821
|
);
|
|
822
822
|
};
|
|
823
823
|
var ParticleWave_default = ParticleWave;
|
|
824
|
+
var instanceCounter = 0;
|
|
824
825
|
var ParticlesBackground = ({
|
|
825
826
|
theme: themeProp,
|
|
826
827
|
isDark: isDarkProp,
|
|
@@ -830,6 +831,9 @@ var ParticlesBackground = ({
|
|
|
830
831
|
}) => {
|
|
831
832
|
var _a, _b;
|
|
832
833
|
const [init, setInit] = react.useState(false);
|
|
834
|
+
const [instanceId, setInstanceId] = react.useState(() => ++instanceCounter);
|
|
835
|
+
const containerRef = react.useRef(void 0);
|
|
836
|
+
const isFirstMount = react.useRef(true);
|
|
833
837
|
const ctx = useParticleThemeOptional();
|
|
834
838
|
const themeId = (_a = themeProp != null ? themeProp : ctx == null ? void 0 : ctx.themeId) != null ? _a : DEFAULT_THEME_ID;
|
|
835
839
|
const isDark = (_b = isDarkProp != null ? isDarkProp : ctx == null ? void 0 : ctx.isDark) != null ? _b : true;
|
|
@@ -843,6 +847,25 @@ var ParticlesBackground = ({
|
|
|
843
847
|
setInit(true);
|
|
844
848
|
});
|
|
845
849
|
}, []);
|
|
850
|
+
react.useEffect(() => {
|
|
851
|
+
if (!isFirstMount.current) {
|
|
852
|
+
setInstanceId(++instanceCounter);
|
|
853
|
+
}
|
|
854
|
+
isFirstMount.current = false;
|
|
855
|
+
return () => {
|
|
856
|
+
if (containerRef.current) {
|
|
857
|
+
containerRef.current.destroy();
|
|
858
|
+
containerRef.current = void 0;
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
}, [themeId, isDark]);
|
|
862
|
+
const particlesLoaded = react.useCallback(async (container) => {
|
|
863
|
+
if (containerRef.current && containerRef.current !== container) {
|
|
864
|
+
containerRef.current.destroy();
|
|
865
|
+
}
|
|
866
|
+
containerRef.current = container;
|
|
867
|
+
onLoaded == null ? void 0 : onLoaded(container);
|
|
868
|
+
}, [onLoaded]);
|
|
846
869
|
const options = react.useMemo(() => theme.options(isDark), [theme, isDark]);
|
|
847
870
|
if (themeId === "none") return null;
|
|
848
871
|
if (theme.isThreeJS) {
|
|
@@ -856,16 +879,17 @@ var ParticlesBackground = ({
|
|
|
856
879
|
);
|
|
857
880
|
}
|
|
858
881
|
if (!init) return null;
|
|
882
|
+
const particlesId = `rpb-tsparticles-${instanceId}`;
|
|
859
883
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
860
884
|
Particles__default.default,
|
|
861
885
|
{
|
|
862
|
-
id:
|
|
886
|
+
id: particlesId,
|
|
863
887
|
className,
|
|
864
888
|
style,
|
|
865
|
-
particlesLoaded
|
|
889
|
+
particlesLoaded,
|
|
866
890
|
options
|
|
867
891
|
},
|
|
868
|
-
|
|
892
|
+
particlesId
|
|
869
893
|
);
|
|
870
894
|
};
|
|
871
895
|
var ParticlesBackground_default = ParticlesBackground;
|
|
@@ -888,7 +912,7 @@ var ThemeSelector = ({
|
|
|
888
912
|
"button",
|
|
889
913
|
{
|
|
890
914
|
onClick: () => setOpen(true),
|
|
891
|
-
title: "
|
|
915
|
+
title: "\u4E3B\u9898\u8BBE\u7F6E",
|
|
892
916
|
style: {
|
|
893
917
|
position: "fixed",
|
|
894
918
|
...positionStyles[position],
|
|
@@ -961,7 +985,7 @@ var ThemeSelector = ({
|
|
|
961
985
|
borderBottom: "1px solid #f0f0f0"
|
|
962
986
|
},
|
|
963
987
|
children: [
|
|
964
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontWeight: 600, fontSize: 16 }, children: "
|
|
988
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontWeight: 600, fontSize: 16 }, children: "\u7C92\u5B50\u4E3B\u9898" }),
|
|
965
989
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
966
990
|
"button",
|
|
967
991
|
{
|
|
@@ -982,9 +1006,9 @@ var ThemeSelector = ({
|
|
|
982
1006
|
),
|
|
983
1007
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: 16, display: "flex", flexDirection: "column", gap: 12 }, children: [...particleThemes, {
|
|
984
1008
|
id: "none",
|
|
985
|
-
name: "
|
|
1009
|
+
name: "\u65E0",
|
|
986
1010
|
icon: "\u{1F6AB}",
|
|
987
|
-
description: "
|
|
1011
|
+
description: "\u5173\u95ED\u7C92\u5B50\u6548\u679C"
|
|
988
1012
|
}].map((theme) => {
|
|
989
1013
|
const isActive = theme.id === themeId;
|
|
990
1014
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1072,7 +1096,7 @@ var ThemeSelector = ({
|
|
|
1072
1096
|
color: "#6b7280",
|
|
1073
1097
|
lineHeight: 1.6
|
|
1074
1098
|
},
|
|
1075
|
-
children: "
|
|
1099
|
+
children: "\u4F60\u7684\u4E3B\u9898\u9009\u62E9\u4F1A\u81EA\u52A8\u4FDD\u5B58\uFF0C\u4E0B\u6B21\u8BBF\u95EE\u65F6\u5C06\u81EA\u52A8\u6062\u590D\u3002"
|
|
1076
1100
|
}
|
|
1077
1101
|
) })
|
|
1078
1102
|
]
|