canvasparticles-js 3.7.2 → 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.2'
12
+ static version = '3.7.4'
13
13
 
14
14
  // Mouse interaction with the particles.
15
15
  static interactionType = Object.freeze({
@@ -84,9 +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 this.matchParticleCount()
88
-
89
- this.particles.forEach(particle => this.#updateParticleBounds(particle))
87
+ else this.matchParticleCount({ updateBounds: true })
90
88
  }
91
89
 
92
90
  updateMousePos(event) {
@@ -132,10 +130,11 @@
132
130
  /**
133
131
  * When resizing, add or remove some particles so that the final amount of particles will match 'options.particles.ppm'.
134
132
  * */
135
- matchParticleCount() {
133
+ matchParticleCount({ updateBounds } = {}) {
136
134
  this.#updateParticleCount()
137
135
 
138
136
  this.particles = this.particles.slice(0, this.particleCount)
137
+ if (updateBounds) this.particles.forEach(particle => this.#updateParticleBounds(particle))
139
138
  while (this.particleCount > this.particles.length) this.createParticle()
140
139
  }
141
140
 
@@ -494,17 +493,19 @@
494
493
  /**
495
494
  * Stops the particle animation and optionally clears the canvas.
496
495
  *
497
- * - If 'options.clear' is not strictly false, the canvas will be cleared.
496
+ * - If `clear` is not strictly `false`, the canvas will be cleared.
498
497
  *
499
- * @param {Object} [options] - Optional configuration for stopping the animation.
500
- * @param {boolean} [options.auto] - If true, indicates that the request comes from within.
501
- * @param {boolean} [options.clear] - If strictly false, prevents clearing the canvas-.
502
- * @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.
503
504
  */
504
- stop(options) {
505
- if (!options?.auto) this.enableAnimating = false
505
+ stop({ auto, clear } = {}) {
506
+ if (!auto) this.enableAnimating = false
506
507
  this.animating = false
507
- if (options?.clear !== false) this.canvas.width = this.canvas.width
508
+ if (clear !== false) this.canvas.width = this.canvas.width
508
509
 
509
510
  return true
510
511
  }
@@ -621,5 +622,5 @@
621
622
  // Recalculate the stroke style table.
622
623
  this.strokeStyleTable = this.#generateStrokeStyleTable(this.options.particles.color)
623
624
  }
624
- },
625
+ }
625
626
  )
@@ -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.2'
5
+ static version = '3.7.4'
6
6
 
7
7
  // Mouse interaction with the particles.
8
8
  static interactionType = Object.freeze({
@@ -77,9 +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 this.matchParticleCount()
81
-
82
- this.particles.forEach(particle => this.#updateParticleBounds(particle))
80
+ else this.matchParticleCount({ updateBounds: true })
83
81
  }
84
82
 
85
83
  updateMousePos(event) {
@@ -125,10 +123,11 @@ export default class CanvasParticles {
125
123
  /**
126
124
  * When resizing, add or remove some particles so that the final amount of particles will match 'options.particles.ppm'.
127
125
  * */
128
- matchParticleCount() {
126
+ matchParticleCount({ updateBounds } = {}) {
129
127
  this.#updateParticleCount()
130
128
 
131
129
  this.particles = this.particles.slice(0, this.particleCount)
130
+ if (updateBounds) this.particles.forEach(particle => this.#updateParticleBounds(particle))
132
131
  while (this.particleCount > this.particles.length) this.createParticle()
133
132
  }
134
133
 
@@ -486,17 +485,19 @@ export default class CanvasParticles {
486
485
  /**
487
486
  * Stops the particle animation and optionally clears the canvas.
488
487
  *
489
- * - If 'options.clear' is not strictly false, the canvas will be cleared.
488
+ * - If `clear` is not strictly `false`, the canvas will be cleared.
490
489
  *
491
- * @param {Object} [options] - Optional configuration for stopping the animation.
492
- * @param {boolean} [options.auto] - If true, indicates that the request comes from within.
493
- * @param {boolean} [options.clear] - If strictly false, prevents clearing the canvas-.
494
- * @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.
495
496
  */
496
- stop(options) {
497
- if (!options?.auto) this.enableAnimating = false
497
+ stop({ auto, clear } = {}) {
498
+ if (!auto) this.enableAnimating = false
498
499
  this.animating = false
499
- if (options?.clear !== false) this.canvas.width = this.canvas.width
500
+ if (clear !== false) this.canvas.width = this.canvas.width
500
501
 
501
502
  return true
502
503
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasparticles-js",
3
- "version": "3.7.2",
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",