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