canvasparticles-js 3.6.9 → 3.7.0

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 +1,455 @@
1
- declare module 'canvasparticles-js'
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)
4
+
5
+ export default class CanvasParticles {
6
+ /**
7
+ * The version of the CanvasParticles library, used to display on the homepage.
8
+ */
9
+ static readonly version: string
10
+
11
+ /**
12
+ * Enum-like object defining possible mouse interaction types with particles.
13
+ */
14
+ static readonly interactionType: {
15
+ readonly NONE: 0
16
+ readonly SHIFT: 1
17
+ readonly MOVE: 2
18
+ }
19
+
20
+ /**
21
+ * IntersectionObserver to start or stop animation when the canvas enters or exits the viewport.
22
+ */
23
+ static readonly canvasIntersectionObserver: IntersectionObserver
24
+
25
+ /**
26
+ * Creates a new CanvasParticles instance.
27
+ * @param selector - The CSS selector to the canvas element or the HTMLCanvasElement itself.
28
+ * @param options - Configuration options for the particle system.
29
+ */
30
+ constructor(selector: string | HTMLCanvasElement, options?: CanvasParticlesOptions)
31
+
32
+ /**
33
+ * The canvas element associated with this instance.
34
+ */
35
+ canvas: HTMLCanvasElement
36
+
37
+ /**
38
+ * The 2D rendering context of the canvas.
39
+ */
40
+ ctx: CanvasRenderingContext2D
41
+
42
+ /**
43
+ * Flag indicating whether animation is enabled.
44
+ */
45
+ enableAnimating: boolean
46
+
47
+ /**
48
+ * Flag indicating whether the animation is currently running.
49
+ */
50
+ animating: boolean
51
+
52
+ /**
53
+ * Array of particles managed by this instance.
54
+ */
55
+ particles: Particle[]
56
+
57
+ /**
58
+ * Current mouse X position relative to the canvas.
59
+ */
60
+ mouseX: number
61
+
62
+ /**
63
+ * Current mouse Y position relative to the canvas.
64
+ */
65
+ mouseY: number
66
+
67
+ /**
68
+ * Client X coordinate of the mouse.
69
+ */
70
+ clientX: number
71
+
72
+ /**
73
+ * Client Y coordinate of the mouse.
74
+ */
75
+ clientY: number
76
+
77
+ /**
78
+ * Logical width of the particle system, including connection distance buffer.
79
+ */
80
+ width: number
81
+
82
+ /**
83
+ * Logical height of the particle system, including connection distance buffer.
84
+ */
85
+ height: number
86
+
87
+ /**
88
+ * Horizontal offset for particle rendering.
89
+ */
90
+ offX: number
91
+
92
+ /**
93
+ * Vertical offset for particle rendering.
94
+ */
95
+ offY: number
96
+
97
+ /**
98
+ * Counter for frames since last update.
99
+ */
100
+ updateCount: number
101
+
102
+ /**
103
+ * Target number of particles based on canvas size and ppm.
104
+ */
105
+ particleCount: number
106
+
107
+ /**
108
+ * Lookup table for stroke styles with varying alpha values.
109
+ */
110
+ strokeStyleTable: { [alpha: number]: string }
111
+
112
+ /**
113
+ * Configuration options for the particle system.
114
+ */
115
+ options: CanvasParticlesOptions
116
+
117
+ /**
118
+ * Resizes the canvas to match its display size and updates particle properties.
119
+ */
120
+ resizeCanvas(): void
121
+
122
+ /**
123
+ * Updates the mouse position relative to the canvas.
124
+ * @param event - The mouse or scroll event.
125
+ */
126
+ updateMousePos(event: MouseEvent | Event): void
127
+
128
+ /**
129
+ * Generates new particles to match the target particle count.
130
+ */
131
+ newParticles(): void
132
+
133
+ /**
134
+ * Adjusts the number of particles to match the target count.
135
+ */
136
+ matchParticleCount(): void
137
+
138
+ /**
139
+ * Creates a new particle with specified or random properties.
140
+ * @param posX - Initial X position (optional).
141
+ * @param posY - Initial Y position (optional).
142
+ * @param dir - Initial direction in radians (optional).
143
+ * @param speed - Initial speed (optional).
144
+ * @param size - Particle size (optional).
145
+ */
146
+ createParticle(posX?: number, posY?: number, dir?: number, speed?: number, size?: number): void
147
+
148
+ /**
149
+ * Starts the particle animation.
150
+ * @param options - Optional configuration for starting the animation.
151
+ * @returns The current instance for method chaining.
152
+ */
153
+ start(options?: { auto?: boolean }): this
154
+
155
+ /**
156
+ * Stops the particle animation and optionally clears the canvas.
157
+ * @param options - Optional configuration for stopping the animation.
158
+ * @returns `true` when the animation is successfully stopped.
159
+ */
160
+ stop(options?: { auto?: boolean; clear?: boolean }): boolean
161
+
162
+ /**
163
+ * Destroys the instance, removes event listeners, and removes the canvas element.
164
+ */
165
+ destroy(): void
166
+
167
+ /**
168
+ * Sets and validates the options for the particle system.
169
+ * @param options - Configuration options.
170
+ */
171
+ setOptions(options: CanvasParticlesOptions): void
172
+
173
+ /**
174
+ * Sets the canvas background.
175
+ * @param background - The CSS background style or false to disable.
176
+ * @throws TypeError if background is not a string or false.
177
+ */
178
+ setBackground(background: string | false): void
179
+
180
+ /**
181
+ * Sets the mouse connection distance multiplier.
182
+ * @param connectDistMult - Multiplier for the mouse interaction distance.
183
+ */
184
+ setMouseConnectDistMult(connectDistMult: number): void
185
+
186
+ /**
187
+ * Sets the particle color and opacity.
188
+ * @param color - The CSS color for particles and connections.
189
+ */
190
+ setParticleColor(color: string): void
191
+ }
192
+
193
+ /**
194
+ * Configuration options for the CanvasParticles class.
195
+ * @remarks Your screen resolution and refresh rate will directly impact performance.
196
+ */
197
+ interface CanvasParticlesOptions {
198
+ /**
199
+ * Background of the canvas. Can be any CSS supported value for the background property.
200
+ * @default false
201
+ * @remarks No background will be set if background is not a string.
202
+ */
203
+ background?: string | false
204
+
205
+ /**
206
+ * How many times the same frame will be shown before an update happens.
207
+ * @default 1
208
+ * @example 60 fps / 2 framesPerUpdate = 30 updates/s
209
+ * @example 144 fps / 3 framesPerUpdate = 48 updates/s
210
+ * @remarks Recommended: 1 - 3
211
+ */
212
+ framesPerUpdate?: number
213
+
214
+ /**
215
+ * Animation settings.
216
+ */
217
+ animation?: {
218
+ /**
219
+ * Whether to start the animation when the canvas enters the viewport.
220
+ * @default true
221
+ */
222
+ startOnEnter?: boolean
223
+
224
+ /**
225
+ * Whether to stop the animation when the canvas leaves the viewport.
226
+ * @default true
227
+ */
228
+ stopOnLeave?: boolean
229
+ }
230
+
231
+ /**
232
+ * Mouse interaction settings.
233
+ */
234
+ mouse?: {
235
+ /**
236
+ * The type of interaction the mouse will have with particles.
237
+ * - `CanvasParticles.interactionType.NONE` (0): No interaction.
238
+ * - `CanvasParticles.interactionType.SHIFT` (1): The mouse can visually shift the particles.
239
+ * - `CanvasParticles.interactionType.MOVE` (2): The mouse can move the particles.
240
+ * @default 1
241
+ * @remarks `distRatio` should be less than 1 to allow dragging; closer to 0 is easier to drag.
242
+ */
243
+ interactionType?: number
244
+
245
+ /**
246
+ * The maximum distance for the mouse to interact with the particles.
247
+ * The value is multiplied by `particles.connectDistance`.
248
+ * @default 2/3
249
+ * @example 0.8 connectDistMult * 150 particles.connectDistance = 120 pixels
250
+ */
251
+ connectDistMult?: number
252
+
253
+ /**
254
+ * All particles within set radius from the mouse will be drawn to `mouse.connectDistance` pixels from the mouse.
255
+ * @default 2/3
256
+ * @example radius = 150 connectDistance / 0.4 distRatio = 375 pixels
257
+ * @remarks Keep this value above `mouse.connectDistMult`. Recommended: 0.2 - 1.
258
+ */
259
+ distRatio?: number
260
+
261
+ /**
262
+ * Computed mouse connection distance (read-only).
263
+ */
264
+ connectDist?: number
265
+ }
266
+
267
+ /**
268
+ * Particle settings.
269
+ */
270
+ particles?: {
271
+ /**
272
+ * Create new particles when the canvas gets resized.
273
+ * @default false
274
+ * @remarks If false, will instead add or remove a few particles to match `particles.ppm`.
275
+ */
276
+ regenerateOnResize?: boolean
277
+
278
+ /**
279
+ * The color of the particles and their connections. Can be any CSS supported color format.
280
+ * @default 'black'
281
+ */
282
+ color?: string
283
+
284
+ /**
285
+ * Particles per million pixels (ppm). Determines how many particles are created per million pixels of the canvas.
286
+ * @default 100
287
+ * @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.
289
+ */
290
+ ppm?: number
291
+
292
+ /**
293
+ * The maximum number of particles allowed.
294
+ * @default 500
295
+ * @remarks Recommended: < 500
296
+ */
297
+ max?: number
298
+
299
+ /**
300
+ * The maximum "work" a particle can perform before its connections are no longer drawn.
301
+ * @default Infinity
302
+ * @example 10 maxWork = 10 * 150 connectDistance = max 1500 pixels of lines drawn per particle
303
+ * @remarks Low values will stabilize performance at the cost of creating an ugly effect where connections may flicker.
304
+ */
305
+ maxWork?: number
306
+
307
+ /**
308
+ * The maximum distance for a connection between two particles.
309
+ * @default 150
310
+ * @remarks Heavily affects performance.
311
+ */
312
+ connectDist?: number
313
+
314
+ /**
315
+ * The relative moving speed of the particles. The moving speed is a random value between 0.5 and 1 pixels per update multiplied by this value.
316
+ * @default 1
317
+ */
318
+ relSpeed?: number
319
+
320
+ /**
321
+ * The relative size of the particles. The radius is a random value between 0.5 and 2.5 pixels multiplied by this value.
322
+ * @default 1
323
+ */
324
+ relSize?: number
325
+
326
+ /**
327
+ * The speed at which the particles randomly change direction.
328
+ * @default 2
329
+ * @example 1 rotationSpeed = max direction change of 0.01 radians per update
330
+ * @remarks Recommended: < 10
331
+ */
332
+ rotationSpeed?: number
333
+
334
+ /**
335
+ * Computed opacity for particles (read-only).
336
+ */
337
+ opacity?: number
338
+
339
+ /**
340
+ * Computed color with alpha (read-only).
341
+ */
342
+ colorWithAlpha?: string
343
+ }
344
+
345
+ /**
346
+ * Gravitational force settings.
347
+ * @remarks Heavily reduces performance if `gravity.repulsive` or `gravity.pulling` is not equal to 0.
348
+ */
349
+ gravity?: {
350
+ /**
351
+ * The repulsive force between particles.
352
+ * @default 0
353
+ * @remarks Recommended: 0.50 - 5.00
354
+ */
355
+ repulsive?: number
356
+
357
+ /**
358
+ * The attractive force pulling particles together. Works poorly if `gravity.repulsive` is too low.
359
+ * @default 0
360
+ * @remarks `gravity.repulsive` should be great enough to prevent forming a singularity. Recommended: 0.01 - 0.10
361
+ */
362
+ pulling?: number
363
+
364
+ /**
365
+ * The smoothness of the gravitational forces. The force gets multiplied by the friction every update.
366
+ * @default 0.8
367
+ * @example force after x updates = force * friction ** x
368
+ * @remarks Recommended: 0.500 - 0.999
369
+ */
370
+ friction?: number
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Interface for a single particle.
376
+ */
377
+ interface Particle {
378
+ /**
379
+ * Logical X position in pixels.
380
+ */
381
+ posX: number
382
+
383
+ /**
384
+ * Logical Y position in pixels.
385
+ */
386
+ posY: number
387
+
388
+ /**
389
+ * Visual X position in pixels.
390
+ */
391
+ x: number
392
+
393
+ /**
394
+ * Visual Y position in pixels.
395
+ */
396
+ y: number
397
+
398
+ /**
399
+ * Horizontal velocity in pixels per update.
400
+ */
401
+ velX: number
402
+
403
+ /**
404
+ * Vertical velocity in pixels per update.
405
+ */
406
+ velY: number
407
+
408
+ /**
409
+ * Horizontal offset from logical to visual position.
410
+ */
411
+ offX: number
412
+
413
+ /**
414
+ * Vertical offset from logical to visual position.
415
+ */
416
+ offY: number
417
+
418
+ /**
419
+ * Direction in radians.
420
+ */
421
+ dir: number
422
+
423
+ /**
424
+ * Velocity in pixels per update.
425
+ */
426
+ speed: number
427
+
428
+ /**
429
+ * Particle radius in pixels.
430
+ */
431
+ size: number
432
+
433
+ /**
434
+ * Bounds for visibility checking.
435
+ */
436
+ bounds: {
437
+ top: number
438
+ right: number
439
+ bottom: number
440
+ left: number
441
+ }
442
+
443
+ /**
444
+ * Grid position in a 3x3 canvas grid.
445
+ */
446
+ gridPos: {
447
+ x: number
448
+ y: number
449
+ }
450
+
451
+ /**
452
+ * Whether the particle is visible in the canvas center.
453
+ */
454
+ isVisible: boolean
455
+ }
@@ -9,7 +9,7 @@
9
9
  typeof self !== 'undefined' ? self : this,
10
10
  () =>
11
11
  class CanvasParticles {
12
- static version = '3.6.9'
12
+ static version = '3.7.0'
13
13
 
14
14
  // Mouse interaction with the particles.
15
15
  static interactionType = Object.freeze({
@@ -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.6.9'
5
+ static version = '3.7.0'
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.6.9",
3
+ "version": "3.7.0",
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",