@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 CHANGED
@@ -1,37 +1,37 @@
1
1
  # react-particle-backgrounds
2
2
 
3
- A React component library that provides **7 beautiful particle background themes** powered by [tsparticles](https://particles.js.org/) and [Three.js](https://threejs.org/).
3
+ 一个基于 [tsparticles](https://particles.js.org/) [Three.js](https://threejs.org/) 的 React 粒子背景组件库,提供 **7 种精美粒子背景主题**。
4
4
 
5
- ## Themes
5
+ ## 主题一览
6
6
 
7
- | Theme | ID | Description |
8
- |-------|----|-------------|
9
- | ✨ Star Links | `starline` | Classic particle linking effect |
10
- | ❄️ Snowfall | `snow` | Romantic falling snowflakes |
11
- | 🫧 Bubbles | `bubble` | Dreamy rising bubbles |
12
- | ⭐ Twinkling Stars | `stars` | Sparkling starry sky |
13
- | 🪲 Fireflies | `firefly` | Warm glowing firefly effect |
14
- | 🔷 Geometry | `geometry` | Floating abstract geometric shapes |
15
- | 🌊 Particle Ocean | `wave` | 3D particle wave (Three.js) |
16
- | 🚫 None | `none` | Disable effects |
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
- ## Installation
18
+ ## 安装
19
19
 
20
20
  ```bash
21
21
  npm install @xdy-npm/react-particle-backgrounds
22
- # or
22
+ #
23
23
  pnpm add @xdy-npm/react-particle-backgrounds
24
24
  ```
25
25
 
26
- For the **Particle Ocean** (wave) theme, you also need Three.js:
26
+ 如需使用**粒子海洋**(wave)主题,还需要安装 Three.js
27
27
 
28
28
  ```bash
29
29
  npm install three
30
30
  ```
31
31
 
32
- ## Quick Start
32
+ ## 快速开始
33
33
 
34
- ### Simple Usage (Props)
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
- ### With Theme Selector (Context)
51
+ ### 配合主题选择器(Context 方式)
52
52
 
53
53
  ```tsx
54
54
  import {
@@ -70,7 +70,7 @@ function App() {
70
70
  }
71
71
  ```
72
72
 
73
- ### Programmatic Theme Switching
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
- Current: {themeId} — Switch to Firefly
87
+ 当前:{themeId} — 切换到萤火虫
88
88
  </button>
89
89
  );
90
90
  }
@@ -103,52 +103,52 @@ function App() {
103
103
 
104
104
  ### `<ParticlesBackground />`
105
105
 
106
- | Prop | Type | Default | Description |
107
- |------|------|---------|-------------|
108
- | `theme` | `ThemeId \| string` | `'starline'` | Theme ID (overrides provider) |
109
- | `isDark` | `boolean` | `true` | Dark mode toggle |
110
- | `onLoaded` | `(container?) => void` | — | Callback when particles load |
111
- | `className` | `string` | — | CSS class |
112
- | `style` | `CSSProperties` | — | Inline styles |
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
- | Prop | Type | Default | Description |
117
- |------|------|---------|-------------|
118
- | `defaultTheme` | `ThemeId \| string` | `'starline'` | Initial theme |
119
- | `isDark` | `boolean` | `true` | Dark mode state |
120
- | `persist` | `boolean` | `true` | Save to localStorage |
121
- | `children` | `ReactNode` | — | Child components |
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
- | Prop | Type | Default | Description |
126
- |------|------|---------|-------------|
127
- | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Button position |
128
- | `accentColor` | `string` | `'#3b82f6'` | Active state color |
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 to access theme state (must be within `<ParticleProvider>`).
132
+ 用于访问主题状态的 Hook(必须在 `<ParticleProvider>` 内使用)。
133
133
 
134
134
  ```ts
135
135
  const { themeId, isDark, setTheme, setDark } = useParticleTheme();
136
136
  ```
137
137
 
138
- ### Theme Objects
138
+ ### 主题对象
139
139
 
140
- Access individual theme configs:
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); // get tsparticles config for dark mode
146
+ const options = theme.options(true); // 获取深色模式下的 tsparticles 配置
147
147
  ```
148
148
 
149
- ## Custom Themes
149
+ ## 自定义主题
150
150
 
151
- You can create your own theme and pass it directly:
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: 'My Theme',
159
+ name: '我的主题',
160
160
  icon: '🎨',
161
- description: 'A custom particle theme',
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
- ## License
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
- /** Whether this theme uses Three.js instead of tsparticles */
9
+ /** 是否使用 Three.js 而非 tsparticles */
10
10
  isThreeJS?: boolean;
11
- /** Returns tsparticles config for the given dark mode state */
11
+ /** 根据深色模式状态返回 tsparticles 配置 */
12
12
  options: (isDark: boolean) => ISourceOptions;
13
- /** Solid background color */
13
+ /** 纯色背景色 */
14
14
  backgroundColor?: string;
15
- /** CSS gradient background */
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
- * Theme ID to display. If used inside a `<ParticleProvider>`,
23
- * this is optional and the provider's theme will be used.
22
+ * 要显示的主题 ID。如果在 `<ParticleProvider>` 内使用,
23
+ * 此属性可选,会自动使用 Provider 中的主题。
24
24
  */
25
25
  theme?: ThemeId | string;
26
- /** Dark mode toggle affects particle colors for supported themes */
26
+ /** 深色模式开关影响支持的主题的粒子颜色 */
27
27
  isDark?: boolean;
28
- /** Callback when particles finish loading */
28
+ /** 粒子加载完成的回调 */
29
29
  onLoaded?: (container?: Container) => void;
30
- /** Custom CSS class */
30
+ /** 自定义 CSS 类名 */
31
31
  className?: string;
32
- /** Custom inline styles */
32
+ /** 自定义行内样式 */
33
33
  style?: React.CSSProperties;
34
34
  }
35
35
  /**
36
- * Renders a full-screen particle background.
36
+ * 渲染全屏粒子背景。
37
37
  *
38
- * Can be used standalone with props:
38
+ * 可以通过 props 独立使用:
39
39
  * ```tsx
40
40
  * <ParticlesBackground theme="starline" isDark />
41
41
  * ```
42
42
  *
43
- * Or inside a `<ParticleProvider>` for shared state:
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
- /** Position on screen */
53
+ /** 在屏幕上的位置 */
54
54
  position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
55
- /** Accent color for active states */
55
+ /** 激活状态的强调色 */
56
56
  accentColor?: string;
57
57
  }
58
58
  /**
59
- * A floating theme selector button + drawer panel.
60
- * Must be used inside a `<ParticleProvider>`.
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 gradient or solid background behind the wave */
72
+ /** 波浪背后的 CSS 渐变或纯色背景 */
73
73
  background?: string;
74
74
  className?: string;
75
75
  style?: React.CSSProperties;
76
76
  }
77
77
  /**
78
- * 3D particle ocean wave rendered with Three.js.
79
- * Three.js is loaded dynamically if not installed, this component renders nothing.
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
- /** Initial/default theme ID */
90
+ /** 初始/默认主题 ID */
91
91
  defaultTheme?: ThemeId | string;
92
- /** Whether to use dark mode particle colors */
92
+ /** 是否使用深色模式粒子颜色 */
93
93
  isDark?: boolean;
94
- /** Persist theme selection to localStorage */
94
+ /** 是否将主题选择持久化到 localStorage */
95
95
  persist?: boolean;
96
96
  children: React.ReactNode;
97
97
  }
98
98
  /**
99
- * Provides particle theme state to child components.
100
- * Wrap your app (or a subtree) with this provider to use
101
- * `<ParticlesBackground />` and `<ThemeSelector />` without explicit props.
99
+ * 为子组件提供粒子主题状态。
100
+ * 用此 Provider 包裹你的应用(或子树),即可无需显式传参地使用
101
+ * `<ParticlesBackground />` `<ThemeSelector />`。
102
102
  */
103
103
  declare const ParticleProvider: React.FC<ParticleProviderProps>;
104
- /** Access the current particle theme context. Must be used within a `<ParticleProvider>`. */
104
+ /** 访问当前粒子主题上下文。必须在 `<ParticleProvider>` 内使用。 */
105
105
  declare const useParticleTheme: () => ParticleContextValue;
106
106
 
107
107
  declare const baseConfig: Partial<ISourceOptions>;
108
- /** Default accent colors used by themes that support multi-color particles */
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
- /** All built-in particle themes (excludes "none") */
125
+ /** 所有内置粒子主题(不包含 "none" */
126
126
  declare const particleThemes: ParticleTheme[];
127
- /** Get a theme by its ID. Falls back to starline if not found. */
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
- /** Whether this theme uses Three.js instead of tsparticles */
9
+ /** 是否使用 Three.js 而非 tsparticles */
10
10
  isThreeJS?: boolean;
11
- /** Returns tsparticles config for the given dark mode state */
11
+ /** 根据深色模式状态返回 tsparticles 配置 */
12
12
  options: (isDark: boolean) => ISourceOptions;
13
- /** Solid background color */
13
+ /** 纯色背景色 */
14
14
  backgroundColor?: string;
15
- /** CSS gradient background */
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
- * Theme ID to display. If used inside a `<ParticleProvider>`,
23
- * this is optional and the provider's theme will be used.
22
+ * 要显示的主题 ID。如果在 `<ParticleProvider>` 内使用,
23
+ * 此属性可选,会自动使用 Provider 中的主题。
24
24
  */
25
25
  theme?: ThemeId | string;
26
- /** Dark mode toggle affects particle colors for supported themes */
26
+ /** 深色模式开关影响支持的主题的粒子颜色 */
27
27
  isDark?: boolean;
28
- /** Callback when particles finish loading */
28
+ /** 粒子加载完成的回调 */
29
29
  onLoaded?: (container?: Container) => void;
30
- /** Custom CSS class */
30
+ /** 自定义 CSS 类名 */
31
31
  className?: string;
32
- /** Custom inline styles */
32
+ /** 自定义行内样式 */
33
33
  style?: React.CSSProperties;
34
34
  }
35
35
  /**
36
- * Renders a full-screen particle background.
36
+ * 渲染全屏粒子背景。
37
37
  *
38
- * Can be used standalone with props:
38
+ * 可以通过 props 独立使用:
39
39
  * ```tsx
40
40
  * <ParticlesBackground theme="starline" isDark />
41
41
  * ```
42
42
  *
43
- * Or inside a `<ParticleProvider>` for shared state:
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
- /** Position on screen */
53
+ /** 在屏幕上的位置 */
54
54
  position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
55
- /** Accent color for active states */
55
+ /** 激活状态的强调色 */
56
56
  accentColor?: string;
57
57
  }
58
58
  /**
59
- * A floating theme selector button + drawer panel.
60
- * Must be used inside a `<ParticleProvider>`.
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 gradient or solid background behind the wave */
72
+ /** 波浪背后的 CSS 渐变或纯色背景 */
73
73
  background?: string;
74
74
  className?: string;
75
75
  style?: React.CSSProperties;
76
76
  }
77
77
  /**
78
- * 3D particle ocean wave rendered with Three.js.
79
- * Three.js is loaded dynamically if not installed, this component renders nothing.
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
- /** Initial/default theme ID */
90
+ /** 初始/默认主题 ID */
91
91
  defaultTheme?: ThemeId | string;
92
- /** Whether to use dark mode particle colors */
92
+ /** 是否使用深色模式粒子颜色 */
93
93
  isDark?: boolean;
94
- /** Persist theme selection to localStorage */
94
+ /** 是否将主题选择持久化到 localStorage */
95
95
  persist?: boolean;
96
96
  children: React.ReactNode;
97
97
  }
98
98
  /**
99
- * Provides particle theme state to child components.
100
- * Wrap your app (or a subtree) with this provider to use
101
- * `<ParticlesBackground />` and `<ThemeSelector />` without explicit props.
99
+ * 为子组件提供粒子主题状态。
100
+ * 用此 Provider 包裹你的应用(或子树),即可无需显式传参地使用
101
+ * `<ParticlesBackground />` `<ThemeSelector />`。
102
102
  */
103
103
  declare const ParticleProvider: React.FC<ParticleProviderProps>;
104
- /** Access the current particle theme context. Must be used within a `<ParticleProvider>`. */
104
+ /** 访问当前粒子主题上下文。必须在 `<ParticleProvider>` 内使用。 */
105
105
  declare const useParticleTheme: () => ParticleContextValue;
106
106
 
107
107
  declare const baseConfig: Partial<ISourceOptions>;
108
- /** Default accent colors used by themes that support multi-color particles */
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
- /** All built-in particle themes (excludes "none") */
125
+ /** 所有内置粒子主题(不包含 "none" */
126
126
  declare const particleThemes: ParticleTheme[];
127
- /** Get a theme by its ID. Falls back to starline if not found. */
127
+ /** 根据 ID 获取主题。找不到时回退到 starline */
128
128
  declare const getThemeById: (id: string) => ParticleTheme;
129
129
  declare const DEFAULT_THEME_ID = "starline";
130
130