canvasparticles-js 3.7.3 → 3.7.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.
@@ -9,7 +9,7 @@
9
9
  typeof self !== 'undefined' ? self : this,
10
10
  () =>
11
11
  class CanvasParticles {
12
- static version = '3.7.3'
12
+ static version = '3.7.4'
13
13
 
14
14
  // Mouse interaction with the particles.
15
15
  static interactionType = Object.freeze({
@@ -84,12 +84,7 @@
84
84
  this.offY = (this.canvas.height - this.height) / 2
85
85
 
86
86
  if (this.options.particles.regenerateOnResize || this.particles.length === 0) this.newParticles()
87
- else {
88
- // Only update bounds of reused particles
89
- this.particles.forEach(particle => this.#updateParticleBounds(particle))
90
-
91
- this.matchParticleCount()
92
- }
87
+ else this.matchParticleCount({ updateBounds: true })
93
88
  }
94
89
 
95
90
  updateMousePos(event) {
@@ -135,10 +130,11 @@
135
130
  /**
136
131
  * When resizing, add or remove some particles so that the final amount of particles will match 'options.particles.ppm'.
137
132
  * */
138
- matchParticleCount() {
133
+ matchParticleCount({ updateBounds } = {}) {
139
134
  this.#updateParticleCount()
140
135
 
141
136
  this.particles = this.particles.slice(0, this.particleCount)
137
+ if (updateBounds) this.particles.forEach(particle => this.#updateParticleBounds(particle))
142
138
  while (this.particleCount > this.particles.length) this.createParticle()
143
139
  }
144
140
 
@@ -497,17 +493,19 @@
497
493
  /**
498
494
  * Stops the particle animation and optionally clears the canvas.
499
495
  *
500
- * - If 'options.clear' is not strictly false, the canvas will be cleared.
496
+ * - If `clear` is not strictly `false`, the canvas will be cleared.
501
497
  *
502
- * @param {Object} [options] - Optional configuration for stopping the animation.
503
- * @param {boolean} [options.auto] - If true, indicates that the request comes from within.
504
- * @param {boolean} [options.clear] - If strictly false, prevents clearing the canvas-.
505
- * @returns {boolean} `true` when the animation is successfully stopped.
498
+ * @param {Object} [options={}] - Optional configuration object.
499
+ * @param {boolean} [options.auto=false] - If `true`, indicates the stop request came from inside
500
+ * the animation loop rather than an external call.
501
+ * @param {boolean} [options.clear=true] - If `false`, prevents the canvas from being cleared
502
+ * when the animation stops.
503
+ * @returns {boolean} `true` if the animation state was successfully updated.
506
504
  */
507
- stop(options) {
508
- if (!options?.auto) this.enableAnimating = false
505
+ stop({ auto, clear } = {}) {
506
+ if (!auto) this.enableAnimating = false
509
507
  this.animating = false
510
- if (options?.clear !== false) this.canvas.width = this.canvas.width
508
+ if (clear !== false) this.canvas.width = this.canvas.width
511
509
 
512
510
  return true
513
511
  }
@@ -2,7 +2,7 @@
2
2
  // https://github.com/Khoeckman/canvasparticles-js/blob/main/LICENSE
3
3
 
4
4
  export default class CanvasParticles {
5
- static version = '3.7.3'
5
+ static version = '3.7.4'
6
6
 
7
7
  // Mouse interaction with the particles.
8
8
  static interactionType = Object.freeze({
@@ -77,12 +77,7 @@ export default class CanvasParticles {
77
77
  this.offY = (this.canvas.height - this.height) / 2
78
78
 
79
79
  if (this.options.particles.regenerateOnResize || this.particles.length === 0) this.newParticles()
80
- else {
81
- // Only update bounds of reused particles
82
- this.particles.forEach(particle => this.#updateParticleBounds(particle))
83
-
84
- this.matchParticleCount()
85
- }
80
+ else this.matchParticleCount({ updateBounds: true })
86
81
  }
87
82
 
88
83
  updateMousePos(event) {
@@ -128,10 +123,11 @@ export default class CanvasParticles {
128
123
  /**
129
124
  * When resizing, add or remove some particles so that the final amount of particles will match 'options.particles.ppm'.
130
125
  * */
131
- matchParticleCount() {
126
+ matchParticleCount({ updateBounds } = {}) {
132
127
  this.#updateParticleCount()
133
128
 
134
129
  this.particles = this.particles.slice(0, this.particleCount)
130
+ if (updateBounds) this.particles.forEach(particle => this.#updateParticleBounds(particle))
135
131
  while (this.particleCount > this.particles.length) this.createParticle()
136
132
  }
137
133
 
@@ -489,17 +485,19 @@ export default class CanvasParticles {
489
485
  /**
490
486
  * Stops the particle animation and optionally clears the canvas.
491
487
  *
492
- * - If 'options.clear' is not strictly false, the canvas will be cleared.
488
+ * - If `clear` is not strictly `false`, the canvas will be cleared.
493
489
  *
494
- * @param {Object} [options] - Optional configuration for stopping the animation.
495
- * @param {boolean} [options.auto] - If true, indicates that the request comes from within.
496
- * @param {boolean} [options.clear] - If strictly false, prevents clearing the canvas-.
497
- * @returns {boolean} `true` when the animation is successfully stopped.
490
+ * @param {Object} [options={}] - Optional configuration object.
491
+ * @param {boolean} [options.auto=false] - If `true`, indicates the stop request came from inside
492
+ * the animation loop rather than an external call.
493
+ * @param {boolean} [options.clear=true] - If `false`, prevents the canvas from being cleared
494
+ * when the animation stops.
495
+ * @returns {boolean} `true` if the animation state was successfully updated.
498
496
  */
499
- stop(options) {
500
- if (!options?.auto) this.enableAnimating = false
497
+ stop({ auto, clear } = {}) {
498
+ if (!auto) this.enableAnimating = false
501
499
  this.animating = false
502
- if (options?.clear !== false) this.canvas.width = this.canvas.width
500
+ if (clear !== false) this.canvas.width = this.canvas.width
503
501
 
504
502
  return true
505
503
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasparticles-js",
3
- "version": "3.7.3",
3
+ "version": "3.7.4",
4
4
  "description": "In an HTML canvas, a bunch of interactive particles connected with lines when they approach each other.",
5
5
  "main": "canvasParticles.js",
6
6
  "module": "canvasParticles.mjs",