@xdy-npm/react-particle-backgrounds 1.0.2 → 1.1.0
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 +12 -0
- package/dist/index.d.ts +142 -131
- package/dist/index.js +8 -1132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6067 -802
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -14
- package/dist/index.d.mts +0 -131
package/README.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
一个基于 [tsparticles](https://particles.js.org/) 和 [Three.js](https://threejs.org/) 的 React 粒子背景组件库,提供 **7 种精美粒子背景主题**。
|
|
4
4
|
|
|
5
|
+
开发与发布相关说明(Vite 库模式搭建、npm 发布、面试要点)见仓库内 [docs 目录](./docs/README.md)(该目录仅随 Git 维护,**不会**随 `npm install` 的包体发布)。
|
|
6
|
+
|
|
7
|
+
## 本地调试 Demo
|
|
8
|
+
|
|
9
|
+
在仓库根目录执行:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm demo:dev
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
会安装 `examples/demo` 依赖并启动 Vite(默认 `http://localhost:5173`)。Demo 通过别名直接引用根目录 `src/index.ts`,改库源码后保存即可热更新。说明见 [examples/demo/README.md](./examples/demo/README.md)。
|
|
16
|
+
|
|
5
17
|
## 主题一览
|
|
6
18
|
|
|
7
19
|
| 主题 | ID | 描述 |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,131 +1,142 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
style?:
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
declare const
|
|
110
|
-
|
|
111
|
-
declare const starlineTheme: ParticleTheme;
|
|
112
|
-
|
|
113
|
-
declare const
|
|
114
|
-
|
|
115
|
-
declare
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
declare const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
1
|
+
import { Container } from '@tsparticles/engine';
|
|
2
|
+
import { default as default_2 } from 'react';
|
|
3
|
+
import { ISourceOptions } from '@tsparticles/engine';
|
|
4
|
+
|
|
5
|
+
export declare const baseConfig: Partial<ISourceOptions>;
|
|
6
|
+
|
|
7
|
+
export declare const bubbleTheme: ParticleTheme;
|
|
8
|
+
|
|
9
|
+
/** 支持多色粒子的主题所使用的默认强调色 */
|
|
10
|
+
export declare const DEFAULT_COLORS: string[];
|
|
11
|
+
|
|
12
|
+
export declare const DEFAULT_THEME_ID = "starline";
|
|
13
|
+
|
|
14
|
+
export declare const fireflyTheme: ParticleTheme;
|
|
15
|
+
|
|
16
|
+
export declare const geometryTheme: ParticleTheme;
|
|
17
|
+
|
|
18
|
+
/** 根据 ID 获取主题。找不到时回退到 starline。 */
|
|
19
|
+
export declare const getThemeById: (id: string) => ParticleTheme;
|
|
20
|
+
|
|
21
|
+
declare interface ParticleContextValue {
|
|
22
|
+
themeId: string;
|
|
23
|
+
isDark: boolean;
|
|
24
|
+
setTheme: (id: string) => void;
|
|
25
|
+
setDark: (dark: boolean) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 为子组件提供粒子主题状态。
|
|
30
|
+
* 用此 Provider 包裹你的应用(或子树),即可无需显式传参地使用
|
|
31
|
+
* `<ParticlesBackground />` 和 `<ThemeSelector />`。
|
|
32
|
+
*/
|
|
33
|
+
export declare const ParticleProvider: default_2.FC<ParticleProviderProps>;
|
|
34
|
+
|
|
35
|
+
export declare interface ParticleProviderProps {
|
|
36
|
+
/** 初始/默认主题 ID */
|
|
37
|
+
defaultTheme?: ThemeId | string;
|
|
38
|
+
/** 是否使用深色模式粒子颜色 */
|
|
39
|
+
isDark?: boolean;
|
|
40
|
+
/** 是否将主题选择持久化到 localStorage */
|
|
41
|
+
persist?: boolean;
|
|
42
|
+
children: default_2.ReactNode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 渲染全屏粒子背景。
|
|
47
|
+
*
|
|
48
|
+
* 可以通过 props 独立使用:
|
|
49
|
+
* ```tsx
|
|
50
|
+
* <ParticlesBackground theme="starline" isDark />
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* 也可以在 `<ParticleProvider>` 内使用以共享状态:
|
|
54
|
+
* ```tsx
|
|
55
|
+
* <ParticleProvider defaultTheme="snow">
|
|
56
|
+
* <ParticlesBackground />
|
|
57
|
+
* </ParticleProvider>
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const ParticlesBackground: default_2.FC<ParticlesBackgroundProps>;
|
|
61
|
+
|
|
62
|
+
export declare interface ParticlesBackgroundProps {
|
|
63
|
+
/**
|
|
64
|
+
* 要显示的主题 ID。如果在 `<ParticleProvider>` 内使用,
|
|
65
|
+
* 此属性可选,会自动使用 Provider 中的主题。
|
|
66
|
+
*/
|
|
67
|
+
theme?: ThemeId | string;
|
|
68
|
+
/** 深色模式开关 — 影响支持的主题的粒子颜色 */
|
|
69
|
+
isDark?: boolean;
|
|
70
|
+
/** 粒子加载完成的回调 */
|
|
71
|
+
onLoaded?: (container?: Container) => void;
|
|
72
|
+
/** 自定义 CSS 类名 */
|
|
73
|
+
className?: string;
|
|
74
|
+
/** 自定义行内样式 */
|
|
75
|
+
style?: default_2.CSSProperties;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export declare interface ParticleTheme {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
icon: string;
|
|
82
|
+
description: string;
|
|
83
|
+
/** 是否使用 Three.js 而非 tsparticles */
|
|
84
|
+
isThreeJS?: boolean;
|
|
85
|
+
/** 根据深色模式状态返回 tsparticles 配置 */
|
|
86
|
+
options: (isDark: boolean) => ISourceOptions;
|
|
87
|
+
/** 纯色背景色 */
|
|
88
|
+
backgroundColor?: string;
|
|
89
|
+
/** CSS 渐变背景 */
|
|
90
|
+
backgroundGradient?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 所有内置粒子主题(不包含 "none") */
|
|
94
|
+
export declare const particleThemes: ParticleTheme[];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 使用 Canvas 2D 渲染的粒子海洋波浪效果。
|
|
98
|
+
* 轻量级实现,无需 Three.js 依赖。
|
|
99
|
+
*/
|
|
100
|
+
export declare const ParticleWave: default_2.FC<ParticleWaveProps>;
|
|
101
|
+
|
|
102
|
+
declare interface ParticleWaveProps {
|
|
103
|
+
/** 波浪背后的 CSS 渐变或纯色背景 */
|
|
104
|
+
background?: string;
|
|
105
|
+
className?: string;
|
|
106
|
+
style?: default_2.CSSProperties;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare const snowTheme: ParticleTheme;
|
|
110
|
+
|
|
111
|
+
export declare const starlineTheme: ParticleTheme;
|
|
112
|
+
|
|
113
|
+
export declare const starsTheme: ParticleTheme;
|
|
114
|
+
|
|
115
|
+
export declare type ThemeId = 'starline' | 'snow' | 'bubble' | 'stars' | 'firefly' | 'geometry' | 'wave' | 'none';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 浮动主题选择器按钮 + 抽屉面板。
|
|
119
|
+
* 必须在 `<ParticleProvider>` 内使用。
|
|
120
|
+
*
|
|
121
|
+
* ```tsx
|
|
122
|
+
* <ParticleProvider>
|
|
123
|
+
* <ParticlesBackground />
|
|
124
|
+
* <ThemeSelector />
|
|
125
|
+
* </ParticleProvider>
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare const ThemeSelector: default_2.FC<ThemeSelectorProps>;
|
|
129
|
+
|
|
130
|
+
export declare interface ThemeSelectorProps {
|
|
131
|
+
/** 在屏幕上的位置 */
|
|
132
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
133
|
+
/** 激活状态的强调色 */
|
|
134
|
+
accentColor?: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 访问当前粒子主题上下文。必须在 `<ParticleProvider>` 内使用。 */
|
|
138
|
+
export declare const useParticleTheme: () => ParticleContextValue;
|
|
139
|
+
|
|
140
|
+
export declare const waveTheme: ParticleTheme;
|
|
141
|
+
|
|
142
|
+
export { }
|