@tsparticles/engine 3.0.0-beta.3 → 3.0.0-beta.4

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.
Files changed (177) hide show
  1. package/browser/Core/Canvas.js +2 -2
  2. package/browser/Core/Container.js +36 -19
  3. package/browser/Core/Engine.js +18 -5
  4. package/browser/Core/Particle.js +75 -40
  5. package/browser/Core/Particles.js +51 -26
  6. package/browser/Core/Retina.js +0 -2
  7. package/browser/Core/Utils/QuadTree.js +1 -1
  8. package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  9. package/browser/Options/Classes/ColorAnimation.js +4 -24
  10. package/browser/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  11. package/browser/Options/Classes/Particles/Effect/Effect.js +32 -0
  12. package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  13. package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +17 -0
  14. package/browser/Options/Classes/Particles/Opacity/Opacity.js +2 -3
  15. package/browser/Options/Classes/Particles/ParticlesOptions.js +3 -0
  16. package/browser/Options/Classes/Particles/Size/Size.js +2 -3
  17. package/browser/Options/Classes/ValueWithRandom.js +1 -10
  18. package/browser/Utils/CanvasUtils.js +23 -18
  19. package/browser/Utils/ColorUtils.js +24 -38
  20. package/browser/Utils/NumberUtils.js +7 -16
  21. package/browser/Utils/Utils.js +7 -7
  22. package/browser/export-types.js +4 -0
  23. package/browser/exports.js +2 -3
  24. package/cjs/Core/Canvas.js +2 -2
  25. package/cjs/Core/Container.js +36 -19
  26. package/cjs/Core/Engine.js +18 -5
  27. package/cjs/Core/Particle.js +74 -39
  28. package/cjs/Core/Particles.js +51 -26
  29. package/cjs/Core/Retina.js +0 -2
  30. package/cjs/Core/Utils/QuadTree.js +1 -1
  31. package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  32. package/cjs/Options/Classes/ColorAnimation.js +4 -24
  33. package/cjs/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  34. package/cjs/Options/Classes/Particles/Effect/Effect.js +36 -0
  35. package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  36. package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +21 -0
  37. package/cjs/Options/Classes/Particles/Opacity/Opacity.js +1 -2
  38. package/cjs/Options/Classes/Particles/ParticlesOptions.js +3 -0
  39. package/cjs/Options/Classes/Particles/Size/Size.js +2 -3
  40. package/cjs/Options/Classes/ValueWithRandom.js +1 -10
  41. package/cjs/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +2 -0
  42. package/cjs/Utils/CanvasUtils.js +26 -21
  43. package/cjs/Utils/ColorUtils.js +24 -38
  44. package/cjs/Utils/NumberUtils.js +8 -18
  45. package/cjs/Utils/Utils.js +6 -6
  46. package/cjs/export-types.js +4 -0
  47. package/cjs/exports.js +2 -3
  48. package/esm/Core/Canvas.js +2 -2
  49. package/esm/Core/Container.js +36 -19
  50. package/esm/Core/Engine.js +18 -5
  51. package/esm/Core/Particle.js +75 -40
  52. package/esm/Core/Particles.js +51 -26
  53. package/esm/Core/Retina.js +0 -2
  54. package/esm/Core/Utils/QuadTree.js +1 -1
  55. package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  56. package/esm/Options/Classes/ColorAnimation.js +4 -24
  57. package/esm/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  58. package/esm/Options/Classes/Particles/Effect/Effect.js +32 -0
  59. package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  60. package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +17 -0
  61. package/esm/Options/Classes/Particles/Opacity/Opacity.js +2 -3
  62. package/esm/Options/Classes/Particles/ParticlesOptions.js +3 -0
  63. package/esm/Options/Classes/Particles/Size/Size.js +2 -3
  64. package/esm/Options/Classes/ValueWithRandom.js +1 -10
  65. package/esm/Options/Interfaces/Particles/Effect/IEffect.js +1 -0
  66. package/esm/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +1 -0
  67. package/esm/Utils/CanvasUtils.js +23 -18
  68. package/esm/Utils/ColorUtils.js +24 -38
  69. package/esm/Utils/NumberUtils.js +7 -16
  70. package/esm/Utils/Utils.js +7 -7
  71. package/esm/export-types.js +4 -0
  72. package/esm/exports.js +2 -3
  73. package/package.json +1 -1
  74. package/report.html +4 -22
  75. package/tsparticles.engine.js +387 -283
  76. package/tsparticles.engine.min.js +1 -1
  77. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  78. package/types/Core/Canvas.d.ts +0 -1
  79. package/types/Core/Container.d.ts +8 -7
  80. package/types/Core/Engine.d.ts +7 -2
  81. package/types/Core/Interfaces/IContainerPlugin.d.ts +2 -3
  82. package/types/Core/Interfaces/IEffectDrawer.d.ts +10 -0
  83. package/types/Core/Interfaces/IExternalInteractor.d.ts +3 -4
  84. package/types/Core/Interfaces/IInteractor.d.ts +3 -3
  85. package/types/Core/Interfaces/IParticleRetinaProps.d.ts +0 -1
  86. package/types/Core/Interfaces/IParticlesInteractor.d.ts +3 -3
  87. package/types/Core/Interfaces/IShapeDrawData.d.ts +10 -0
  88. package/types/Core/Interfaces/IShapeDrawer.d.ts +2 -10
  89. package/types/Core/Particle.d.ts +6 -2
  90. package/types/Core/Particles.d.ts +10 -7
  91. package/types/Core/Retina.d.ts +0 -1
  92. package/types/Core/Utils/ExternalInteractorBase.d.ts +4 -4
  93. package/types/Core/Utils/InteractionManager.d.ts +1 -2
  94. package/types/Core/Utils/ParticlesInteractorBase.d.ts +5 -5
  95. package/types/Enums/Modes/LimitMode.d.ts +4 -0
  96. package/types/Enums/Types/EasingType.d.ts +3 -0
  97. package/types/Options/Classes/BackgroundMask/BackgroundMask.d.ts +1 -1
  98. package/types/Options/Classes/ColorAnimation.d.ts +2 -7
  99. package/types/Options/Classes/Interactivity/Events/ClickEvent.d.ts +1 -2
  100. package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +1 -2
  101. package/types/Options/Classes/Interactivity/Events/Events.d.ts +3 -3
  102. package/types/Options/Classes/Interactivity/Events/HoverEvent.d.ts +2 -3
  103. package/types/Options/Classes/Interactivity/Interactivity.d.ts +2 -2
  104. package/types/Options/Classes/Options.d.ts +6 -6
  105. package/types/Options/Classes/Particles/Bounce/ParticlesBounce.d.ts +2 -2
  106. package/types/Options/Classes/Particles/Collisions/Collisions.d.ts +3 -3
  107. package/types/Options/Classes/Particles/Effect/Effect.d.ts +13 -0
  108. package/types/Options/Classes/Particles/Move/Move.d.ts +8 -8
  109. package/types/Options/Classes/Particles/Move/MoveTrail.d.ts +1 -1
  110. package/types/Options/Classes/Particles/Number/ParticlesNumber.d.ts +3 -2
  111. package/types/Options/Classes/Particles/Number/ParticlesNumberLimit.d.ts +10 -0
  112. package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +3 -3
  113. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +12 -10
  114. package/types/Options/Classes/Particles/Size/Size.d.ts +3 -3
  115. package/types/Options/Classes/Theme/Theme.d.ts +1 -1
  116. package/types/Options/Classes/ValueWithRandom.d.ts +2 -4
  117. package/types/Options/Interfaces/IValueWithRandom.d.ts +0 -2
  118. package/types/Options/Interfaces/Interactivity/Events/IClickEvent.d.ts +1 -2
  119. package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +1 -2
  120. package/types/Options/Interfaces/Interactivity/Events/IHoverEvent.d.ts +1 -2
  121. package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +8 -0
  122. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -0
  123. package/types/Options/Interfaces/Particles/Number/IParticlesNumber.d.ts +2 -1
  124. package/types/Options/Interfaces/Particles/Number/IParticlesNumberLimit.d.ts +5 -0
  125. package/types/Utils/CanvasUtils.d.ts +2 -2
  126. package/types/Utils/NumberUtils.d.ts +0 -2
  127. package/types/Utils/Utils.d.ts +2 -3
  128. package/types/export-types.d.ts +5 -0
  129. package/types/exports.d.ts +2 -3
  130. package/umd/Core/Canvas.js +2 -2
  131. package/umd/Core/Container.js +36 -19
  132. package/umd/Core/Engine.js +18 -5
  133. package/umd/Core/Particle.js +74 -39
  134. package/umd/Core/Particles.js +51 -26
  135. package/umd/Core/Retina.js +0 -2
  136. package/umd/Core/Utils/QuadTree.js +1 -1
  137. package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  138. package/umd/Options/Classes/ColorAnimation.js +5 -25
  139. package/umd/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  140. package/umd/Options/Classes/Particles/Effect/Effect.js +46 -0
  141. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +4 -6
  142. package/umd/Options/Classes/{Random.js → Particles/Number/ParticlesNumberLimit.js} +9 -9
  143. package/umd/Options/Classes/Particles/Opacity/Opacity.js +1 -2
  144. package/umd/Options/Classes/Particles/ParticlesOptions.js +4 -1
  145. package/umd/Options/Classes/Particles/Size/Size.js +3 -4
  146. package/umd/Options/Classes/ValueWithRandom.js +2 -11
  147. package/umd/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +12 -0
  148. package/umd/Utils/CanvasUtils.js +26 -21
  149. package/umd/Utils/ColorUtils.js +24 -38
  150. package/umd/Utils/NumberUtils.js +9 -19
  151. package/umd/Utils/Utils.js +6 -6
  152. package/umd/export-types.js +5 -1
  153. package/umd/exports.js +3 -4
  154. package/browser/Options/Classes/Random.js +0 -17
  155. package/cjs/Options/Classes/Random.js +0 -21
  156. package/esm/Options/Classes/Random.js +0 -17
  157. package/types/Enums/Modes/ClickMode.d.ts +0 -9
  158. package/types/Enums/Modes/DivMode.d.ts +0 -5
  159. package/types/Enums/Modes/HoverMode.d.ts +0 -11
  160. package/types/Options/Classes/Random.d.ts +0 -9
  161. package/types/Options/Interfaces/IRandom.d.ts +0 -4
  162. /package/browser/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  163. /package/browser/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  164. /package/browser/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  165. /package/browser/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
  166. /package/{esm/Enums/Modes/ClickMode.js → browser/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js} +0 -0
  167. /package/cjs/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  168. /package/cjs/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  169. /package/cjs/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  170. /package/cjs/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
  171. /package/esm/{Enums/Modes/DivMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  172. /package/esm/{Enums/Modes/HoverMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  173. /package/esm/{Options/Interfaces/IRandom.js → Enums/Modes/LimitMode.js} +0 -0
  174. /package/umd/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  175. /package/umd/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  176. /package/umd/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  177. /package/umd/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
@@ -19,16 +19,29 @@
19
19
  const Constants_js_1 = require("./Utils/Constants.js");
20
20
  const qTreeCapacity = 4;
21
21
  const qTreeRectangle = (canvasSize) => {
22
- return new Rectangle_js_1.Rectangle(-canvasSize.width / 4, -canvasSize.height / 4, (canvasSize.width * 3) / 2, (canvasSize.height * 3) / 2);
22
+ const { height, width } = canvasSize, posOffset = -0.25, sizeFactor = 1.5;
23
+ return new Rectangle_js_1.Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);
23
24
  };
24
25
  class Particles {
25
26
  constructor(engine, container) {
26
27
  this._applyDensity = (options, manualCount, group) => {
28
+ const numberOptions = options.number;
27
29
  if (!options.number.density?.enable) {
30
+ if (group === undefined) {
31
+ this._limit = numberOptions.limit.value;
32
+ }
33
+ else {
34
+ this._groupLimits.set(group, numberOptions.limit.value);
35
+ }
28
36
  return;
29
37
  }
30
- const numberOptions = options.number, densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit > 0 ? numberOptions.limit : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount, particlesCount = Math.min(this.count, this.filter((t) => t.group === group).length);
31
- this.limit = numberOptions.limit * densityFactor;
38
+ const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > 0 ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount, particlesCount = Math.min(this.count, this.filter((t) => t.group === group).length);
39
+ if (group === undefined) {
40
+ this._limit = numberOptions.limit.value * densityFactor;
41
+ }
42
+ else {
43
+ this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
44
+ }
32
45
  if (particlesCount < particlesNumber) {
33
46
  this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
34
47
  }
@@ -46,7 +59,7 @@
46
59
  };
47
60
  this._pushParticle = (position, overrideOptions, group, initializer) => {
48
61
  try {
49
- let particle = this.pool.pop();
62
+ let particle = this._pool.pop();
50
63
  if (particle) {
51
64
  particle.init(this._nextId, position, overrideOptions, group);
52
65
  }
@@ -85,7 +98,7 @@
85
98
  const zIdx = this._zArray.indexOf(particle);
86
99
  this._array.splice(index, 1);
87
100
  this._zArray.splice(zIdx, 1);
88
- this.pool.push(particle);
101
+ this._pool.push(particle);
89
102
  this._engine.dispatchEvent("particleRemoved", {
90
103
  container: this._container,
91
104
  data: {
@@ -99,10 +112,11 @@
99
112
  this._nextId = 0;
100
113
  this._array = [];
101
114
  this._zArray = [];
102
- this.pool = [];
103
- this.limit = 0;
104
- this.needsSort = false;
105
- this.lastZIndex = 0;
115
+ this._pool = [];
116
+ this._limit = 0;
117
+ this._groupLimits = new Map();
118
+ this._needsSort = false;
119
+ this._lastZIndex = 0;
106
120
  this._interactionManager = new InteractionManager_js_1.InteractionManager(engine, container);
107
121
  const canvasSize = container.canvas.size;
108
122
  this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
@@ -119,17 +133,21 @@
119
133
  }
120
134
  }
121
135
  addParticle(position, overrideOptions, group, initializer) {
122
- this.pushing = true;
123
- const container = this._container, options = container.actualOptions, limit = options.particles.number.limit;
136
+ const limitOptions = this._container.actualOptions.particles.number.limit, limit = group === undefined ? this._limit : this._groupLimits.get(group) ?? this._limit, currentCount = this.count;
124
137
  if (limit > 0) {
125
- const countToRemove = this.count + 1 - limit;
126
- if (countToRemove > 0) {
127
- this.removeQuantity(countToRemove);
138
+ if (limitOptions.mode === "delete") {
139
+ const countToRemove = currentCount + 1 - limit;
140
+ if (countToRemove > 0) {
141
+ this.removeQuantity(countToRemove);
142
+ }
143
+ }
144
+ else if (limitOptions.mode === "wait") {
145
+ if (currentCount >= limit) {
146
+ return;
147
+ }
128
148
  }
129
149
  }
130
- const res = this._pushParticle(position, overrideOptions, group, initializer);
131
- this.pushing = false;
132
- return res;
150
+ return this._pushParticle(position, overrideOptions, group, initializer);
133
151
  }
134
152
  clear() {
135
153
  this._array = [];
@@ -166,8 +184,8 @@
166
184
  }
167
185
  init() {
168
186
  const container = this._container, options = container.actualOptions;
169
- this.lastZIndex = 0;
170
- this.needsSort = false;
187
+ this._lastZIndex = 0;
188
+ this._needsSort = false;
171
189
  let handled = false;
172
190
  this.updaters = this._engine.getUpdaters(container, true);
173
191
  this._interactionManager.init();
@@ -229,6 +247,13 @@
229
247
  }
230
248
  this._applyDensity(options.particles, options.manualParticles.length);
231
249
  }
250
+ setLastZIndex(zIndex) {
251
+ this._lastZIndex = zIndex;
252
+ this._needsSort = this._needsSort || this._lastZIndex < zIndex;
253
+ }
254
+ setResizeFactor(factor) {
255
+ this._resizeFactor = factor;
256
+ }
232
257
  async update(delta) {
233
258
  const container = this._container, particlesToDelete = new Set();
234
259
  this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);
@@ -236,10 +261,10 @@
236
261
  pathGenerator.update();
237
262
  }
238
263
  for (const [, plugin] of container.plugins) {
239
- plugin.update && plugin.update(delta);
264
+ plugin.update && (await plugin.update(delta));
240
265
  }
266
+ const resizeFactor = this._resizeFactor;
241
267
  for (const particle of this._array) {
242
- const resizeFactor = container.canvas.resizeFactor;
243
268
  if (resizeFactor && !particle.ignoresResizeRatio) {
244
269
  particle.position.x *= resizeFactor.width;
245
270
  particle.position.y *= resizeFactor.height;
@@ -267,7 +292,7 @@
267
292
  const checkDelete = (p) => !particlesToDelete.has(p);
268
293
  this._array = this.filter(checkDelete);
269
294
  this._zArray = this._zArray.filter(checkDelete);
270
- this.pool.push(...particlesToDelete);
295
+ this._pool.push(...particlesToDelete);
271
296
  }
272
297
  await this._interactionManager.externalInteract(delta);
273
298
  for (const particle of this._array) {
@@ -278,12 +303,12 @@
278
303
  await this._interactionManager.particlesInteract(particle, delta);
279
304
  }
280
305
  }
281
- delete container.canvas.resizeFactor;
282
- if (this.needsSort) {
306
+ delete this._resizeFactor;
307
+ if (this._needsSort) {
283
308
  const zArray = this._zArray;
284
309
  zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
285
- this.lastZIndex = zArray[zArray.length - 1].position.z;
286
- this.needsSort = false;
310
+ this._lastZIndex = zArray[zArray.length - 1].position.z;
311
+ this._needsSort = false;
287
312
  }
288
313
  }
289
314
  }
@@ -29,13 +29,11 @@
29
29
  canvas.size.height = element.offsetHeight * ratio;
30
30
  }
31
31
  const particles = options.particles, moveOptions = particles.move;
32
- this.attractDistance = (0, NumberUtils_js_1.getRangeValue)(moveOptions.attract.distance) * ratio;
33
32
  this.maxSpeed = (0, NumberUtils_js_1.getRangeValue)(moveOptions.gravity.maxSpeed) * ratio;
34
33
  this.sizeAnimationSpeed = (0, NumberUtils_js_1.getRangeValue)(particles.size.animation.speed) * ratio;
35
34
  }
36
35
  initParticle(particle) {
37
36
  const options = particle.options, ratio = this.pixelRatio, moveOptions = options.move, moveDistance = moveOptions.distance, props = particle.retina;
38
- props.attractDistance = (0, NumberUtils_js_1.getRangeValue)(moveOptions.attract.distance) * ratio;
39
37
  props.moveDrift = (0, NumberUtils_js_1.getRangeValue)(moveOptions.drift) * ratio;
40
38
  props.moveSpeed = (0, NumberUtils_js_1.getRangeValue)(moveOptions.speed) * ratio;
41
39
  props.sizeAnimationSpeed = (0, NumberUtils_js_1.getRangeValue)(options.size.animation.speed) * ratio;
@@ -20,7 +20,7 @@
20
20
  this._subdivide = () => {
21
21
  const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
22
22
  for (let i = 0; i < 4; i++) {
23
- this._subs.push(new QuadTree(new Rectangle_js_1.Rectangle(x + (width / 2) * (i % 2), y + (height / 2) * (Math.round(i / 2) - (i % 2)), width / 2, height / 2), capacity));
23
+ this._subs.push(new QuadTree(new Rectangle_js_1.Rectangle(x + width * 0.5 * (i % 2), y + height * 0.5 * (Math.round(i * 0.5) - (i % 2)), width * 0.5, height * 0.5), capacity));
24
24
  }
25
25
  this._divided = true;
26
26
  };
@@ -26,8 +26,7 @@
26
26
  this.composite = data.composite;
27
27
  }
28
28
  if (data.cover !== undefined) {
29
- const cover = data.cover;
30
- const color = ((0, Utils_js_1.isString)(data.cover) ? { color: data.cover } : data.cover);
29
+ const cover = data.cover, color = ((0, Utils_js_1.isString)(data.cover) ? { color: data.cover } : data.cover);
31
30
  this.cover.load(cover.color !== undefined ? cover : { color: color });
32
31
  }
33
32
  if (data.enable !== undefined) {
@@ -4,48 +4,28 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../../Utils/NumberUtils.js"], factory);
7
+ define(["require", "exports", "./AnimationOptions.js", "../../Utils/NumberUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ColorAnimation = void 0;
13
+ const AnimationOptions_js_1 = require("./AnimationOptions.js");
13
14
  const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
14
- class ColorAnimation {
15
+ class ColorAnimation extends AnimationOptions_js_1.AnimationOptions {
15
16
  constructor() {
16
- this.count = 0;
17
- this.enable = false;
17
+ super();
18
18
  this.offset = 0;
19
- this.speed = 1;
20
- this.delay = 0;
21
- this.decay = 0;
22
19
  this.sync = true;
23
20
  }
24
21
  load(data) {
22
+ super.load(data);
25
23
  if (!data) {
26
24
  return;
27
25
  }
28
- if (data.count !== undefined) {
29
- this.count = (0, NumberUtils_js_1.setRangeValue)(data.count);
30
- }
31
- if (data.enable !== undefined) {
32
- this.enable = data.enable;
33
- }
34
26
  if (data.offset !== undefined) {
35
27
  this.offset = (0, NumberUtils_js_1.setRangeValue)(data.offset);
36
28
  }
37
- if (data.speed !== undefined) {
38
- this.speed = (0, NumberUtils_js_1.setRangeValue)(data.speed);
39
- }
40
- if (data.decay !== undefined) {
41
- this.decay = (0, NumberUtils_js_1.setRangeValue)(data.decay);
42
- }
43
- if (data.delay !== undefined) {
44
- this.delay = (0, NumberUtils_js_1.setRangeValue)(data.delay);
45
- }
46
- if (data.sync !== undefined) {
47
- this.sync = data.sync;
48
- }
49
29
  }
50
30
  }
51
31
  exports.ColorAnimation = ColorAnimation;
@@ -14,7 +14,6 @@
14
14
  class ParticlesBounceFactor extends ValueWithRandom_js_1.ValueWithRandom {
15
15
  constructor() {
16
16
  super();
17
- this.random.minimumValue = 0.1;
18
17
  this.value = 1;
19
18
  }
20
19
  }
@@ -0,0 +1,46 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../../../../Utils/Utils.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Effect = void 0;
13
+ const Utils_js_1 = require("../../../../Utils/Utils.js");
14
+ class Effect {
15
+ constructor() {
16
+ this.close = true;
17
+ this.fill = true;
18
+ this.options = {};
19
+ this.type = [];
20
+ }
21
+ load(data) {
22
+ if (!data) {
23
+ return;
24
+ }
25
+ const options = data.options;
26
+ if (options !== undefined) {
27
+ for (const effect in options) {
28
+ const item = options[effect];
29
+ if (item) {
30
+ this.options[effect] = (0, Utils_js_1.deepExtend)(this.options[effect] ?? {}, item);
31
+ }
32
+ }
33
+ }
34
+ if (data.close !== undefined) {
35
+ this.close = data.close;
36
+ }
37
+ if (data.fill !== undefined) {
38
+ this.fill = data.fill;
39
+ }
40
+ if (data.type !== undefined) {
41
+ this.type = data.type;
42
+ }
43
+ }
44
+ }
45
+ exports.Effect = Effect;
46
+ });
@@ -4,17 +4,18 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./ParticlesDensity.js"], factory);
7
+ define(["require", "exports", "./ParticlesDensity.js", "./ParticlesNumberLimit.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ParticlesNumber = void 0;
13
13
  const ParticlesDensity_js_1 = require("./ParticlesDensity.js");
14
+ const ParticlesNumberLimit_js_1 = require("./ParticlesNumberLimit.js");
14
15
  class ParticlesNumber {
15
16
  constructor() {
16
17
  this.density = new ParticlesDensity_js_1.ParticlesDensity();
17
- this.limit = 0;
18
+ this.limit = new ParticlesNumberLimit_js_1.ParticlesNumberLimit();
18
19
  this.value = 0;
19
20
  }
20
21
  load(data) {
@@ -22,10 +23,7 @@
22
23
  return;
23
24
  }
24
25
  this.density.load(data.density);
25
- const limit = data.limit;
26
- if (limit !== undefined) {
27
- this.limit = limit;
28
- }
26
+ this.limit.load(data.limit);
29
27
  if (data.value !== undefined) {
30
28
  this.value = data.value;
31
29
  }
@@ -9,23 +9,23 @@
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Random = void 0;
13
- class Random {
12
+ exports.ParticlesNumberLimit = void 0;
13
+ class ParticlesNumberLimit {
14
14
  constructor() {
15
- this.enable = false;
16
- this.minimumValue = 0;
15
+ this.mode = "delete";
16
+ this.value = 0;
17
17
  }
18
18
  load(data) {
19
19
  if (!data) {
20
20
  return;
21
21
  }
22
- if (data.enable !== undefined) {
23
- this.enable = data.enable;
22
+ if (data.mode !== undefined) {
23
+ this.mode = data.mode;
24
24
  }
25
- if (data.minimumValue !== undefined) {
26
- this.minimumValue = data.minimumValue;
25
+ if (data.value !== undefined) {
26
+ this.value = data.value;
27
27
  }
28
28
  }
29
29
  }
30
- exports.Random = Random;
30
+ exports.ParticlesNumberLimit = ParticlesNumberLimit;
31
31
  });
@@ -12,11 +12,10 @@
12
12
  exports.Opacity = void 0;
13
13
  const OpacityAnimation_js_1 = require("./OpacityAnimation.js");
14
14
  const ValueWithRandom_js_1 = require("../../ValueWithRandom.js");
15
- class Opacity extends ValueWithRandom_js_1.ValueWithRandom {
15
+ class Opacity extends ValueWithRandom_js_1.RangedAnimationValueWithRandom {
16
16
  constructor() {
17
17
  super();
18
18
  this.animation = new OpacityAnimation_js_1.OpacityAnimation();
19
- this.random.minimumValue = 0.1;
20
19
  this.value = 1;
21
20
  }
22
21
  load(data) {
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../../../Utils/Utils.js", "../AnimatableColor.js", "./Collisions/Collisions.js", "./Move/Move.js", "./Opacity/Opacity.js", "./Bounce/ParticlesBounce.js", "./Number/ParticlesNumber.js", "./Shadow.js", "./Shape/Shape.js", "./Size/Size.js", "./Stroke.js", "./ZIndex/ZIndex.js"], factory);
7
+ define(["require", "exports", "../../../Utils/Utils.js", "../AnimatableColor.js", "./Collisions/Collisions.js", "./Effect/Effect.js", "./Move/Move.js", "./Opacity/Opacity.js", "./Bounce/ParticlesBounce.js", "./Number/ParticlesNumber.js", "./Shadow.js", "./Shape/Shape.js", "./Size/Size.js", "./Stroke.js", "./ZIndex/ZIndex.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -13,6 +13,7 @@
13
13
  const Utils_js_1 = require("../../../Utils/Utils.js");
14
14
  const AnimatableColor_js_1 = require("../AnimatableColor.js");
15
15
  const Collisions_js_1 = require("./Collisions/Collisions.js");
16
+ const Effect_js_1 = require("./Effect/Effect.js");
16
17
  const Move_js_1 = require("./Move/Move.js");
17
18
  const Opacity_js_1 = require("./Opacity/Opacity.js");
18
19
  const ParticlesBounce_js_1 = require("./Bounce/ParticlesBounce.js");
@@ -30,6 +31,7 @@
30
31
  this.collisions = new Collisions_js_1.Collisions();
31
32
  this.color = new AnimatableColor_js_1.AnimatableColor();
32
33
  this.color.value = "#fff";
34
+ this.effect = new Effect_js_1.Effect();
33
35
  this.groups = {};
34
36
  this.move = new Move_js_1.Move();
35
37
  this.number = new ParticlesNumber_js_1.ParticlesNumber();
@@ -47,6 +49,7 @@
47
49
  }
48
50
  this.bounce.load(data.bounce);
49
51
  this.color.load(AnimatableColor_js_1.AnimatableColor.create(this.color, data.color));
52
+ this.effect.load(data.effect);
50
53
  if (data.groups !== undefined) {
51
54
  for (const group in data.groups) {
52
55
  const item = data.groups[group];
@@ -4,19 +4,18 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./SizeAnimation.js", "../../ValueWithRandom.js"], factory);
7
+ define(["require", "exports", "../../ValueWithRandom.js", "./SizeAnimation.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Size = void 0;
13
- const SizeAnimation_js_1 = require("./SizeAnimation.js");
14
13
  const ValueWithRandom_js_1 = require("../../ValueWithRandom.js");
15
- class Size extends ValueWithRandom_js_1.ValueWithRandom {
14
+ const SizeAnimation_js_1 = require("./SizeAnimation.js");
15
+ class Size extends ValueWithRandom_js_1.RangedAnimationValueWithRandom {
16
16
  constructor() {
17
17
  super();
18
18
  this.animation = new SizeAnimation_js_1.SizeAnimation();
19
- this.random.minimumValue = 1;
20
19
  this.value = 3;
21
20
  }
22
21
  load(data) {
@@ -4,33 +4,24 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./AnimationOptions.js", "./Random.js", "../../Utils/Utils.js", "../../Utils/NumberUtils.js"], factory);
7
+ define(["require", "exports", "./AnimationOptions.js", "../../Utils/NumberUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RangedAnimationValueWithRandom = exports.AnimationValueWithRandom = exports.ValueWithRandom = void 0;
13
13
  const AnimationOptions_js_1 = require("./AnimationOptions.js");
14
- const Random_js_1 = require("./Random.js");
15
- const Utils_js_1 = require("../../Utils/Utils.js");
16
14
  const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
17
15
  class ValueWithRandom {
18
16
  constructor() {
19
- this.random = new Random_js_1.Random();
20
17
  this.value = 0;
21
18
  }
22
19
  load(data) {
23
20
  if (!data) {
24
21
  return;
25
22
  }
26
- if ((0, Utils_js_1.isBoolean)(data.random)) {
27
- this.random.enable = data.random;
28
- }
29
- else {
30
- this.random.load(data.random);
31
- }
32
23
  if (data.value !== undefined) {
33
- this.value = (0, NumberUtils_js_1.setRangeValue)(data.value, this.random.enable ? this.random.minimumValue : undefined);
24
+ this.value = (0, NumberUtils_js_1.setRangeValue)(data.value);
34
25
  }
35
26
  }
36
27
  }
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -9,7 +9,7 @@
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.alterHsl = exports.drawParticlePlugin = exports.drawPlugin = exports.drawShapeAfterEffect = exports.drawShape = exports.drawParticle = exports.clear = exports.paintImage = exports.paintBase = exports.drawTriangle = exports.drawLine = void 0;
12
+ exports.alterHsl = exports.drawParticlePlugin = exports.drawPlugin = exports.drawShapeAfterDraw = exports.drawShape = exports.drawEffect = exports.drawParticle = exports.clear = exports.paintImage = exports.paintBase = exports.drawLine = void 0;
13
13
  const ColorUtils_js_1 = require("./ColorUtils.js");
14
14
  function drawLine(context, begin, end) {
15
15
  context.beginPath();
@@ -18,14 +18,6 @@
18
18
  context.closePath();
19
19
  }
20
20
  exports.drawLine = drawLine;
21
- function drawTriangle(context, p1, p2, p3) {
22
- context.beginPath();
23
- context.moveTo(p1.x, p1.y);
24
- context.lineTo(p2.x, p2.y);
25
- context.lineTo(p3.x, p3.y);
26
- context.closePath();
27
- }
28
- exports.drawTriangle = drawTriangle;
29
21
  function paintBase(context, dimension, baseColor) {
30
22
  context.fillStyle = baseColor ?? "rgba(0,0,0,0)";
31
23
  context.fillRect(0, 0, dimension.width, dimension.height);
@@ -56,7 +48,6 @@
56
48
  d: rotateData.cos * (transform.d ?? 1),
57
49
  };
58
50
  context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
59
- context.beginPath();
60
51
  if (backgroundMask) {
61
52
  context.globalCompositeOperation = composite;
62
53
  }
@@ -76,45 +67,59 @@
76
67
  context.strokeStyle = colorStyles.stroke;
77
68
  }
78
69
  const drawData = { container, context, particle, radius, opacity, delta };
70
+ context.beginPath();
79
71
  drawShape(drawData);
72
+ if (particle.shapeClose) {
73
+ context.closePath();
74
+ }
80
75
  if (strokeWidth > 0) {
81
76
  context.stroke();
82
77
  }
83
- if (particle.close) {
84
- context.closePath();
85
- }
86
- if (particle.fill) {
78
+ if (particle.shapeFill) {
87
79
  context.fill();
88
80
  }
89
- drawShapeAfterEffect(drawData);
81
+ drawShapeAfterDraw(drawData);
82
+ drawEffect(drawData);
90
83
  context.globalCompositeOperation = "source-over";
91
84
  context.setTransform(1, 0, 0, 1, 0, 0);
92
85
  }
93
86
  exports.drawParticle = drawParticle;
87
+ function drawEffect(data) {
88
+ const { container, context, particle, radius, opacity, delta } = data;
89
+ if (!particle.effect) {
90
+ return;
91
+ }
92
+ const drawer = container.effectDrawers.get(particle.effect);
93
+ if (!drawer) {
94
+ return;
95
+ }
96
+ drawer.draw({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
97
+ }
98
+ exports.drawEffect = drawEffect;
94
99
  function drawShape(data) {
95
100
  const { container, context, particle, radius, opacity, delta } = data;
96
101
  if (!particle.shape) {
97
102
  return;
98
103
  }
99
- const drawer = container.drawers.get(particle.shape);
104
+ const drawer = container.shapeDrawers.get(particle.shape);
100
105
  if (!drawer) {
101
106
  return;
102
107
  }
103
108
  drawer.draw({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
104
109
  }
105
110
  exports.drawShape = drawShape;
106
- function drawShapeAfterEffect(data) {
111
+ function drawShapeAfterDraw(data) {
107
112
  const { container, context, particle, radius, opacity, delta } = data;
108
113
  if (!particle.shape) {
109
114
  return;
110
115
  }
111
- const drawer = container.drawers.get(particle.shape);
112
- if (!drawer || !drawer.afterEffect) {
116
+ const drawer = container.shapeDrawers.get(particle.shape);
117
+ if (!drawer || !drawer.afterDraw) {
113
118
  return;
114
119
  }
115
- drawer.afterEffect({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
120
+ drawer.afterDraw({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
116
121
  }
117
- exports.drawShapeAfterEffect = drawShapeAfterEffect;
122
+ exports.drawShapeAfterDraw = drawShapeAfterDraw;
118
123
  function drawPlugin(context, plugin, delta) {
119
124
  if (!plugin.draw) {
120
125
  return;