@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/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: "Star Links",
42
+ name: "\u661F\u94FE",
43
43
  icon: "\u2728",
44
- description: "Classic particle linking effect",
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;
@@ -55,7 +55,8 @@ var starlineTheme = {
55
55
  resize: { enable: true }
56
56
  },
57
57
  modes: {
58
- push: { quantity: 6 },
58
+ // 快速点击会触发 push 不断增加粒子和连线,限制触发强度和最大粒子数量可避免性能问题
59
+ push: { quantity: 2 },
59
60
  grab: {
60
61
  distance: 200,
61
62
  links: { opacity: 1, color: colors }
@@ -81,7 +82,9 @@ var starlineTheme = {
81
82
  },
82
83
  number: {
83
84
  density: { enable: true, width: 1920, height: 1080 },
84
- value: 100
85
+ value: 100,
86
+ // 限制粒子总量,防止快速点击后粒子与连线无限增长
87
+ limit: { value: 130, mode: "delete" }
85
88
  },
86
89
  opacity: { value: 0.7 },
87
90
  shape: { type: "circle" },
@@ -100,9 +103,9 @@ var starlineTheme = {
100
103
  // src/themes/snow.ts
101
104
  var snowTheme = {
102
105
  id: "snow",
103
- name: "Snowfall",
106
+ name: "\u98D8\u96EA",
104
107
  icon: "\u2744\uFE0F",
105
- description: "Romantic falling snowflakes",
108
+ description: "\u6D6A\u6F2B\u98D8\u843D\u96EA\u82B1",
106
109
  backgroundGradient: "linear-gradient(180deg, #1e3a5f 0%, #2d4a6b 50%, #3d5a7b 100%)",
107
110
  options: (isDark) => ({
108
111
  ...baseConfig,
@@ -154,9 +157,9 @@ var snowTheme = {
154
157
  // src/themes/bubble.ts
155
158
  var bubbleTheme = {
156
159
  id: "bubble",
157
- name: "Bubbles",
160
+ name: "\u6C14\u6CE1",
158
161
  icon: "\u{1FAE7}",
159
- description: "Dreamy rising bubbles",
162
+ description: "\u68A6\u5E7B\u4E0A\u5347\u6C14\u6CE1",
160
163
  backgroundGradient: "linear-gradient(180deg, #0a2647 0%, #144272 50%, #205295 100%)",
161
164
  options: (isDark) => ({
162
165
  ...baseConfig,
@@ -213,9 +216,9 @@ var bubbleTheme = {
213
216
  // src/themes/stars.ts
214
217
  var starsTheme = {
215
218
  id: "stars",
216
- name: "Twinkling Stars",
219
+ name: "\u7E41\u661F",
217
220
  icon: "\u2B50",
218
- description: "Sparkling starry sky",
221
+ description: "\u95EA\u70C1\u661F\u7A7A\u6548\u679C",
219
222
  backgroundGradient: "linear-gradient(180deg, #000000 0%, #1a1a2e 50%, #16213e 100%)",
220
223
  options: (isDark) => ({
221
224
  ...baseConfig,
@@ -227,7 +230,8 @@ var starsTheme = {
227
230
  resize: { enable: true }
228
231
  },
229
232
  modes: {
230
- push: { quantity: 3 },
233
+ // 限制快速点击触发的粒子 push 强度,避免连线过多造成卡顿
234
+ push: { quantity: 1 },
231
235
  connect: { distance: 100, links: { opacity: 0.3 }, radius: 150 }
232
236
  }
233
237
  },
@@ -245,7 +249,9 @@ var starsTheme = {
245
249
  },
246
250
  number: {
247
251
  density: { enable: true, width: 1920, height: 1080 },
248
- value: 120
252
+ value: 120,
253
+ // 限制粒子总量,避免快速点击后连线无限累积
254
+ limit: { value: 150, mode: "delete" }
249
255
  },
250
256
  opacity: {
251
257
  value: { min: 0.2, max: 1 },
@@ -280,9 +286,9 @@ var starsTheme = {
280
286
  // src/themes/firefly.ts
281
287
  var fireflyTheme = {
282
288
  id: "firefly",
283
- name: "Fireflies",
289
+ name: "\u8424\u706B\u866B",
284
290
  icon: "\u{1FAB2}",
285
- description: "Warm glowing firefly effect",
291
+ description: "\u6E29\u6696\u7684\u8424\u706B\u866B\u5149\u6548",
286
292
  backgroundGradient: "linear-gradient(180deg, #1a1a1a 0%, #2d2d2d 50%, #1a1a1a 100%)",
287
293
  options: (isDark) => ({
288
294
  ...baseConfig,
@@ -341,9 +347,9 @@ var fireflyTheme = {
341
347
  // src/themes/geometry.ts
342
348
  var geometryTheme = {
343
349
  id: "geometry",
344
- name: "Geometry",
350
+ name: "\u51E0\u4F55",
345
351
  icon: "\u{1F537}",
346
- description: "Floating abstract geometric shapes",
352
+ description: "\u6F02\u6D6E\u7684\u62BD\u8C61\u51E0\u4F55\u56FE\u5F62",
347
353
  backgroundGradient: "linear-gradient(180deg, #0f0c29 0%, #302b63 50%, #24243e 100%)",
348
354
  options: (isDark) => ({
349
355
  ...baseConfig,
@@ -355,7 +361,8 @@ var geometryTheme = {
355
361
  resize: { enable: true }
356
362
  },
357
363
  modes: {
358
- push: { quantity: 2 },
364
+ // 快速点击会持续触发 push,限制强度有助于降低连线/粒子带来的开销
365
+ push: { quantity: 1 },
359
366
  repulse: { distance: 150, duration: 0.4 }
360
367
  }
361
368
  },
@@ -373,7 +380,9 @@ var geometryTheme = {
373
380
  },
374
381
  number: {
375
382
  density: { enable: true, width: 1920, height: 1080 },
376
- value: 30
383
+ value: 30,
384
+ // 限制粒子总量,避免连续点击时粒子无限增加
385
+ limit: { value: 60, mode: "delete" }
377
386
  },
378
387
  opacity: {
379
388
  value: { min: 0.3, max: 0.7 }
@@ -407,9 +416,9 @@ var geometryTheme = {
407
416
  // src/themes/wave.ts
408
417
  var waveTheme = {
409
418
  id: "wave",
410
- name: "Particle Ocean",
419
+ name: "\u7C92\u5B50\u6D77\u6D0B",
411
420
  icon: "\u{1F30A}",
412
- description: "3D particle wave effect (requires three.js)",
421
+ description: "3D \u7C92\u5B50\u6CE2\u6D6A\u6548\u679C\uFF08\u9700\u8981 three.js\uFF09",
413
422
  isThreeJS: true,
414
423
  backgroundGradient: "linear-gradient(180deg, #000000 0%, #0a1628 50%, #0d1f3c 100%)",
415
424
  options: () => ({
@@ -486,7 +495,7 @@ var ParticleWave = ({
486
495
  })();
487
496
  } catch (e) {
488
497
  hasThree.current = false;
489
- console.warn('[react-particle-backgrounds] "three" is not installed. The wave theme requires it as a peer dependency.');
498
+ console.warn('[react-particle-backgrounds] \u672A\u5B89\u88C5 "three"\u3002\u6CE2\u6D6A\u4E3B\u9898\u9700\u8981\u5B83\u4F5C\u4E3A peer dependency\u3002');
490
499
  return;
491
500
  }
492
501
  if (!containerRef.current) return;
@@ -821,6 +830,7 @@ var ParticleWave = ({
821
830
  );
822
831
  };
823
832
  var ParticleWave_default = ParticleWave;
833
+ var instanceCounter = 0;
824
834
  var ParticlesBackground = ({
825
835
  theme: themeProp,
826
836
  isDark: isDarkProp,
@@ -830,6 +840,9 @@ var ParticlesBackground = ({
830
840
  }) => {
831
841
  var _a, _b;
832
842
  const [init, setInit] = react.useState(false);
843
+ const [instanceId, setInstanceId] = react.useState(() => ++instanceCounter);
844
+ const containerRef = react.useRef(void 0);
845
+ const isFirstMount = react.useRef(true);
833
846
  const ctx = useParticleThemeOptional();
834
847
  const themeId = (_a = themeProp != null ? themeProp : ctx == null ? void 0 : ctx.themeId) != null ? _a : DEFAULT_THEME_ID;
835
848
  const isDark = (_b = isDarkProp != null ? isDarkProp : ctx == null ? void 0 : ctx.isDark) != null ? _b : true;
@@ -843,6 +856,25 @@ var ParticlesBackground = ({
843
856
  setInit(true);
844
857
  });
845
858
  }, []);
859
+ react.useEffect(() => {
860
+ if (!isFirstMount.current) {
861
+ setInstanceId(++instanceCounter);
862
+ }
863
+ isFirstMount.current = false;
864
+ return () => {
865
+ if (containerRef.current) {
866
+ containerRef.current.destroy();
867
+ containerRef.current = void 0;
868
+ }
869
+ };
870
+ }, [themeId, isDark]);
871
+ const particlesLoaded = react.useCallback(async (container) => {
872
+ if (containerRef.current && containerRef.current !== container) {
873
+ containerRef.current.destroy();
874
+ }
875
+ containerRef.current = container;
876
+ onLoaded == null ? void 0 : onLoaded(container);
877
+ }, [onLoaded]);
846
878
  const options = react.useMemo(() => theme.options(isDark), [theme, isDark]);
847
879
  if (themeId === "none") return null;
848
880
  if (theme.isThreeJS) {
@@ -856,16 +888,17 @@ var ParticlesBackground = ({
856
888
  );
857
889
  }
858
890
  if (!init) return null;
891
+ const particlesId = `rpb-tsparticles-${instanceId}`;
859
892
  return /* @__PURE__ */ jsxRuntime.jsx(
860
893
  Particles__default.default,
861
894
  {
862
- id: "rpb-tsparticles",
895
+ id: particlesId,
863
896
  className,
864
897
  style,
865
- particlesLoaded: async (container) => onLoaded == null ? void 0 : onLoaded(container),
898
+ particlesLoaded,
866
899
  options
867
900
  },
868
- themeId
901
+ particlesId
869
902
  );
870
903
  };
871
904
  var ParticlesBackground_default = ParticlesBackground;
@@ -888,7 +921,7 @@ var ThemeSelector = ({
888
921
  "button",
889
922
  {
890
923
  onClick: () => setOpen(true),
891
- title: "Theme Settings",
924
+ title: "\u4E3B\u9898\u8BBE\u7F6E",
892
925
  style: {
893
926
  position: "fixed",
894
927
  ...positionStyles[position],
@@ -961,7 +994,7 @@ var ThemeSelector = ({
961
994
  borderBottom: "1px solid #f0f0f0"
962
995
  },
963
996
  children: [
964
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontWeight: 600, fontSize: 16 }, children: "Particle Theme" }),
997
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontWeight: 600, fontSize: 16 }, children: "\u7C92\u5B50\u4E3B\u9898" }),
965
998
  /* @__PURE__ */ jsxRuntime.jsx(
966
999
  "button",
967
1000
  {
@@ -982,9 +1015,9 @@ var ThemeSelector = ({
982
1015
  ),
983
1016
  /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: 16, display: "flex", flexDirection: "column", gap: 12 }, children: [...particleThemes, {
984
1017
  id: "none",
985
- name: "None",
1018
+ name: "\u65E0",
986
1019
  icon: "\u{1F6AB}",
987
- description: "Disable particle effects"
1020
+ description: "\u5173\u95ED\u7C92\u5B50\u6548\u679C"
988
1021
  }].map((theme) => {
989
1022
  const isActive = theme.id === themeId;
990
1023
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1072,7 +1105,7 @@ var ThemeSelector = ({
1072
1105
  color: "#6b7280",
1073
1106
  lineHeight: 1.6
1074
1107
  },
1075
- children: "Your theme selection is automatically saved and will be remembered on your next visit."
1108
+ 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
1109
  }
1077
1110
  ) })
1078
1111
  ]