canvasparticles-js 3.7.4 → 3.8.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.
@@ -1,6 +1,5 @@
1
- // Type definitions for canvasParticles 3.6.9
2
- // Project: https://github.com/Khoeckman/canvasParticles
3
- // Definitions by: Grok (based on provided JavaScript code and options documentation)
1
+ // Type definitions for canvasparticles-js@3.8.0 (https://github.com/Khoeckman/canvasparticles-js)
2
+ // Definitions by: Grok (based on documented JavaScript code)
4
3
 
5
4
  export default class CanvasParticles {
6
5
  /**
@@ -25,14 +24,23 @@ export default class CanvasParticles {
25
24
  /**
26
25
  * Creates a new CanvasParticles instance.
27
26
  * @param selector - The CSS selector to the canvas element or the HTMLCanvasElement itself.
28
- * @param options - Configuration options for the particle system.
27
+ * @param options - Configuration options for the particle system. Defaults to an empty object.
29
28
  */
30
29
  constructor(selector: string | HTMLCanvasElement, options?: CanvasParticlesOptions)
31
30
 
32
31
  /**
33
32
  * The canvas element associated with this instance.
34
33
  */
35
- canvas: HTMLCanvasElement
34
+ canvas: HTMLCanvasElement & {
35
+ /**
36
+ * Reference to this CanvasParticles instance.
37
+ */
38
+ instance: CanvasParticles
39
+ /**
40
+ * Whether the canvas is currently in the viewport.
41
+ */
42
+ inViewbox: boolean
43
+ }
36
44
 
37
45
  /**
38
46
  * The 2D rendering context of the canvas.
@@ -105,7 +113,7 @@ export default class CanvasParticles {
105
113
  particleCount: number
106
114
 
107
115
  /**
108
- * Lookup table for stroke styles with varying alpha values.
116
+ * Lookup table for stroke styles with varying alpha values (0–255).
109
117
  */
110
118
  strokeStyleTable: { [alpha: number]: string }
111
119
 
@@ -132,8 +140,10 @@ export default class CanvasParticles {
132
140
 
133
141
  /**
134
142
  * Adjusts the number of particles to match the target count.
143
+ * @param options - Configuration for particle count adjustment.
144
+ * @param options.updateBounds - Whether to update particle bounds during adjustment.
135
145
  */
136
- matchParticleCount(): void
146
+ matchParticleCount(options?: { updateBounds?: boolean }): void
137
147
 
138
148
  /**
139
149
  * Creates a new particle with specified or random properties.
@@ -148,6 +158,7 @@ export default class CanvasParticles {
148
158
  /**
149
159
  * Starts the particle animation.
150
160
  * @param options - Optional configuration for starting the animation.
161
+ * @param options.auto - Indicates if the start is triggered automatically (e.g., by IntersectionObserver).
151
162
  * @returns The current instance for method chaining.
152
163
  */
153
164
  start(options?: { auto?: boolean }): this
@@ -155,6 +166,8 @@ export default class CanvasParticles {
155
166
  /**
156
167
  * Stops the particle animation and optionally clears the canvas.
157
168
  * @param options - Optional configuration for stopping the animation.
169
+ * @param options.auto - Indicates if the stop is triggered automatically (e.g., by IntersectionObserver).
170
+ * @param options.clear - Whether to clear the canvas when stopping. Defaults to true.
158
171
  * @returns `true` when the animation is successfully stopped.
159
172
  */
160
173
  stop(options?: { auto?: boolean; clear?: boolean }): boolean
@@ -244,14 +257,14 @@ interface CanvasParticlesOptions {
244
257
 
245
258
  /**
246
259
  * The maximum distance for the mouse to interact with the particles.
247
- * The value is multiplied by `particles.connectDistance`.
260
+ * The value is multiplied by `particles.connectDist`.
248
261
  * @default 2/3
249
262
  * @example 0.8 connectDistMult * 150 particles.connectDistance = 120 pixels
250
263
  */
251
264
  connectDistMult?: number
252
265
 
253
266
  /**
254
- * All particles within set radius from the mouse will be drawn to `mouse.connectDistance` pixels from the mouse.
267
+ * All particles within set radius from the mouse will be drawn to `mouse.connectDist` pixels from the mouse.
255
268
  * @default 2/3
256
269
  * @example radius = 150 connectDistance / 0.4 distRatio = 375 pixels
257
270
  * @remarks Keep this value above `mouse.connectDistMult`. Recommended: 0.2 - 1.
@@ -285,7 +298,7 @@ interface CanvasParticlesOptions {
285
298
  * Particles per million pixels (ppm). Determines how many particles are created per million pixels of the canvas.
286
299
  * @default 100
287
300
  * @example FHD on Chrome = 1920 width * 937 height = 1799040 pixels; 1799040 pixels * 100 ppm / 1_000_000 = 179.904 = 179 particles
288
- * @remarks The amount of particles exponentially reduces performance. People with large screens will have a bad experience with high values. One solution is to increase `particles.connectDistance` and decrease this value. Recommended: < 120.
301
+ * @remarks The amount of particles exponentially reduces performance. Recommended: < 120.
289
302
  */
290
303
  ppm?: number
291
304
 
@@ -324,9 +337,9 @@ interface CanvasParticlesOptions {
324
337
  relSize?: number
325
338
 
326
339
  /**
327
- * The speed at which the particles randomly change direction.
340
+ * The speed at which the particles randomly change direction, scaled by dividing by 100.
328
341
  * @default 2
329
- * @example 1 rotationSpeed = max direction change of 0.01 radians per update
342
+ * @example 2 rotationSpeed = max direction change of 0.02 radians per update
330
343
  * @remarks Recommended: < 10
331
344
  */
332
345
  rotationSpeed?: number
@@ -9,7 +9,7 @@
9
9
  typeof self !== 'undefined' ? self : this,
10
10
  () =>
11
11
  class CanvasParticles {
12
- static version = '3.7.4'
12
+ static version = '3.8.2'
13
13
 
14
14
  // Mouse interaction with the particles.
15
15
  static interactionType = Object.freeze({
@@ -17,7 +17,6 @@
17
17
  SHIFT: 1, // Visually shift the particles
18
18
  MOVE: 2, // Actually move the particles
19
19
  })
20
-
21
20
  // Start or stop the animation when the canvas enters or exits the viewport.
22
21
  static canvasIntersectionObserver = new IntersectionObserver(entry => {
23
22
  entry.forEach(change => {
@@ -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.4'
5
+ static version = '3.8.2'
6
6
 
7
7
  // Mouse interaction with the particles.
8
8
  static interactionType = Object.freeze({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasparticles-js",
3
- "version": "3.7.4",
3
+ "version": "3.8.2",
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",