@tsparticles/updater-gradient 3.0.0-alpha.0 → 3.0.0-beta.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.
Files changed (53) hide show
  1. package/README.md +16 -12
  2. package/browser/GradientUpdater.js +34 -132
  3. package/browser/Options/Classes/AnimatableGradientColor.js +2 -2
  4. package/browser/Options/Classes/GradientAngle.js +2 -1
  5. package/browser/Options/Classes/GradientAngleAnimation.js +5 -1
  6. package/browser/Options/Classes/GradientColorOpacity.js +1 -1
  7. package/browser/Options/Classes/GradientColorOpacityAnimation.js +8 -1
  8. package/browser/Types.js +1 -0
  9. package/browser/Utils.js +107 -0
  10. package/browser/index.js +2 -2
  11. package/cjs/GradientUpdater.js +35 -133
  12. package/cjs/Options/Classes/AnimatableGradientColor.js +1 -1
  13. package/cjs/Options/Classes/GradientAngle.js +2 -1
  14. package/cjs/Options/Classes/GradientAngleAnimation.js +4 -0
  15. package/cjs/Options/Classes/GradientColorOpacity.js +1 -1
  16. package/cjs/Options/Classes/GradientColorOpacityAnimation.js +7 -0
  17. package/cjs/Types.js +2 -0
  18. package/cjs/Utils.js +111 -0
  19. package/cjs/index.js +2 -2
  20. package/esm/GradientUpdater.js +34 -132
  21. package/esm/Options/Classes/AnimatableGradientColor.js +2 -2
  22. package/esm/Options/Classes/GradientAngle.js +2 -1
  23. package/esm/Options/Classes/GradientAngleAnimation.js +5 -1
  24. package/esm/Options/Classes/GradientColorOpacity.js +1 -1
  25. package/esm/Options/Classes/GradientColorOpacityAnimation.js +8 -1
  26. package/esm/Types.js +1 -0
  27. package/esm/Utils.js +107 -0
  28. package/esm/index.js +2 -2
  29. package/package.json +10 -5
  30. package/report.html +4 -4
  31. package/tsparticles.updater.gradient.js +87 -56
  32. package/tsparticles.updater.gradient.min.js +1 -1
  33. package/tsparticles.updater.gradient.min.js.LICENSE.txt +1 -8
  34. package/types/GradientUpdater.d.ts +2 -25
  35. package/types/Options/Classes/AnimatableGradient.d.ts +1 -2
  36. package/types/Options/Classes/AnimatableGradientColor.d.ts +1 -2
  37. package/types/Options/Classes/GradientAngle.d.ts +2 -3
  38. package/types/Options/Classes/GradientAngleAnimation.d.ts +2 -1
  39. package/types/Options/Classes/GradientColorOpacity.d.ts +1 -1
  40. package/types/Options/Classes/GradientColorOpacityAnimation.d.ts +2 -2
  41. package/types/Options/Interfaces/Gradients.d.ts +1 -1
  42. package/types/Types.d.ts +23 -0
  43. package/types/Utils.d.ts +3 -0
  44. package/types/index.d.ts +1 -1
  45. package/umd/GradientUpdater.js +36 -134
  46. package/umd/Options/Classes/AnimatableGradientColor.js +1 -1
  47. package/umd/Options/Classes/GradientAngle.js +3 -2
  48. package/umd/Options/Classes/GradientAngleAnimation.js +4 -0
  49. package/umd/Options/Classes/GradientColorOpacity.js +2 -2
  50. package/umd/Options/Classes/GradientColorOpacityAnimation.js +7 -0
  51. package/umd/Types.js +12 -0
  52. package/umd/Utils.js +121 -0
  53. package/umd/index.js +2 -2
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
7
+ * v3.0.0-beta.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,7 +91,7 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "loadGradientUpdater": () => (/* binding */ loadGradientUpdater)
94
+ loadGradientUpdater: () => (/* binding */ loadGradientUpdater)
95
95
  });
96
96
 
97
97
  // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
@@ -104,6 +104,7 @@ class GradientColorOpacityAnimation {
104
104
  this.enable = false;
105
105
  this.speed = 0;
106
106
  this.decay = 0;
107
+ this.delay = 0;
107
108
  this.sync = false;
108
109
  this.startValue = "random";
109
110
  }
@@ -126,6 +127,12 @@ class GradientColorOpacityAnimation {
126
127
  if (data.startValue !== undefined) {
127
128
  this.startValue = data.startValue;
128
129
  }
130
+ if (data.decay !== undefined) {
131
+ this.decay = (0,engine_root_window_.setRangeValue)(data.decay);
132
+ }
133
+ if (data.delay !== undefined) {
134
+ this.delay = (0,engine_root_window_.setRangeValue)(data.delay);
135
+ }
129
136
  }
130
137
  }
131
138
  ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/GradientColorOpacity.js
@@ -164,7 +171,7 @@ class AnimatableGradientColor {
164
171
  this.value = engine_root_window_.AnimatableColor.create(this.value, data.value);
165
172
  if (data.opacity !== undefined) {
166
173
  this.opacity = new GradientColorOpacity();
167
- if (typeof data.opacity === "number") {
174
+ if ((0,engine_root_window_.isNumber)(data.opacity)) {
168
175
  this.opacity.value = data.opacity;
169
176
  } else {
170
177
  this.opacity.load(data.opacity);
@@ -180,6 +187,7 @@ class GradientAngleAnimation {
180
187
  this.enable = false;
181
188
  this.speed = 0;
182
189
  this.decay = 0;
190
+ this.delay = 0;
183
191
  this.sync = false;
184
192
  }
185
193
  load(data) {
@@ -198,6 +206,9 @@ class GradientAngleAnimation {
198
206
  if (data.decay !== undefined) {
199
207
  this.decay = (0,engine_root_window_.setRangeValue)(data.decay);
200
208
  }
209
+ if (data.delay !== undefined) {
210
+ this.delay = (0,engine_root_window_.setRangeValue)(data.delay);
211
+ }
201
212
  if (data.sync !== undefined) {
202
213
  this.sync = data.sync;
203
214
  }
@@ -205,6 +216,7 @@ class GradientAngleAnimation {
205
216
  }
206
217
  ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/GradientAngle.js
207
218
 
219
+
208
220
  class GradientAngle {
209
221
  constructor() {
210
222
  this.value = 0;
@@ -217,7 +229,7 @@ class GradientAngle {
217
229
  }
218
230
  this.animation.load(data.animation);
219
231
  if (data.value !== undefined) {
220
- this.value = data.value;
232
+ this.value = (0,engine_root_window_.setRangeValue)(data.value);
221
233
  }
222
234
  if (data.direction !== undefined) {
223
235
  this.direction = data.direction;
@@ -250,28 +262,25 @@ class AnimatableGradient {
250
262
  }
251
263
  }
252
264
  }
253
- ;// CONCATENATED MODULE: ./dist/browser/GradientUpdater.js
254
-
255
-
265
+ ;// CONCATENATED MODULE: ./dist/browser/Utils.js
256
266
  function updateColorOpacity(delta, value) {
257
- var _a, _b, _c;
258
267
  if (!value.enable) {
259
268
  return;
260
269
  }
261
- const decay = (_a = value.decay) !== null && _a !== void 0 ? _a : 1;
270
+ const decay = value.decay ?? 1;
262
271
  switch (value.status) {
263
272
  case "increasing":
264
273
  if (value.value >= value.max) {
265
274
  value.status = "decreasing";
266
275
  } else {
267
- value.value += ((_b = value.velocity) !== null && _b !== void 0 ? _b : 0) * delta.factor;
276
+ value.value += (value.velocity ?? 0) * delta.factor;
268
277
  }
269
278
  break;
270
279
  case "decreasing":
271
280
  if (value.value <= value.min) {
272
281
  value.status = "increasing";
273
282
  } else {
274
- value.value -= ((_c = value.velocity) !== null && _c !== void 0 ? _c : 0) * delta.factor;
283
+ value.value -= (value.velocity ?? 0) * delta.factor;
275
284
  }
276
285
  break;
277
286
  }
@@ -279,14 +288,21 @@ function updateColorOpacity(delta, value) {
279
288
  value.velocity *= decay;
280
289
  }
281
290
  }
282
- function updateColorValue(delta, value, max, decrease) {
283
- var _a, _b;
284
- const colorValue = value;
291
+ function updateColorValue(delta, colorValue, max, decrease) {
285
292
  if (!colorValue || !colorValue.enable) {
286
293
  return;
287
294
  }
288
- const velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor,
289
- decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
295
+ if (!colorValue.time) {
296
+ colorValue.time = 0;
297
+ }
298
+ if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
299
+ colorValue.time += delta.value;
300
+ }
301
+ if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
302
+ return;
303
+ }
304
+ const velocity = (colorValue.velocity ?? 0) * delta.factor,
305
+ decay = colorValue.decay ?? 1;
290
306
  if (!decrease || colorValue.status === "increasing") {
291
307
  colorValue.value += velocity;
292
308
  if (decrease && colorValue.value > max) {
@@ -303,15 +319,14 @@ function updateColorValue(delta, value, max, decrease) {
303
319
  if (colorValue.value > max) {
304
320
  colorValue.value %= max;
305
321
  }
306
- if (value.velocity && decay !== 1) {
307
- value.velocity *= decay;
322
+ if (colorValue.velocity && decay !== 1) {
323
+ colorValue.velocity *= decay;
308
324
  }
309
325
  }
310
326
  function updateAngle(delta, angle) {
311
- var _a, _b;
312
- const speed = ((_a = angle.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor,
327
+ const speed = (angle.velocity ?? 0) * delta.factor,
313
328
  max = 2 * Math.PI,
314
- decay = (_b = angle.decay) !== null && _b !== void 0 ? _b : 1;
329
+ decay = angle.decay ?? 1;
315
330
  if (!angle.enable) {
316
331
  return;
317
332
  }
@@ -335,20 +350,21 @@ function updateAngle(delta, angle) {
335
350
  }
336
351
  }
337
352
  function updateGradient(particle, delta) {
338
- var _a, _b, _c;
339
- const gradient = particle.gradient;
353
+ const {
354
+ gradient
355
+ } = particle;
340
356
  if (!gradient) {
341
357
  return;
342
358
  }
343
359
  updateAngle(delta, gradient.angle);
344
360
  for (const color of gradient.colors) {
345
- if (((_a = particle.color) === null || _a === void 0 ? void 0 : _a.h) !== undefined) {
361
+ if (particle.color?.h !== undefined) {
346
362
  updateColorValue(delta, color.value.h, 360, false);
347
363
  }
348
- if (((_b = particle.color) === null || _b === void 0 ? void 0 : _b.s) !== undefined) {
364
+ if (particle.color?.s !== undefined) {
349
365
  updateColorValue(delta, color.value.s, 100, true);
350
366
  }
351
- if (((_c = particle.color) === null || _c === void 0 ? void 0 : _c.l) !== undefined) {
367
+ if (particle.color?.l !== undefined) {
352
368
  updateColorValue(delta, color.value.l, 100, true);
353
369
  }
354
370
  if (color.opacity) {
@@ -356,21 +372,28 @@ function updateGradient(particle, delta) {
356
372
  }
357
373
  }
358
374
  }
375
+ ;// CONCATENATED MODULE: ./dist/browser/GradientUpdater.js
376
+
377
+
378
+
359
379
  class GradientUpdater {
360
380
  getColorStyles(particle, context, radius, opacity) {
361
- var _a, _b;
362
381
  const gradient = particle.gradient;
363
382
  if (!gradient) {
364
383
  return {};
365
384
  }
366
385
  const gradientAngle = gradient.angle.value,
367
386
  fillGradient = gradient.type === "radial" ? context.createRadialGradient(0, 0, 0, 0, 0, radius) : context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
368
- for (const color of gradient.colors) {
369
- fillGradient.addColorStop(color.stop, (0,engine_root_window_.getStyleFromHsl)({
370
- h: color.value.h.value,
371
- s: color.value.s.value,
372
- l: color.value.l.value
373
- }, (_b = (_a = color.opacity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : opacity));
387
+ for (const {
388
+ stop,
389
+ value,
390
+ opacity: cOpacity
391
+ } of gradient.colors) {
392
+ fillGradient.addColorStop(stop, (0,engine_root_window_.getStyleFromHsl)({
393
+ h: value.h.value,
394
+ s: value.s.value,
395
+ l: value.l.value
396
+ }, cOpacity?.value ?? opacity));
374
397
  }
375
398
  return {
376
399
  fill: fillGradient
@@ -381,20 +404,24 @@ class GradientUpdater {
381
404
  if (!gradient) {
382
405
  return;
383
406
  }
407
+ const {
408
+ angle
409
+ } = gradient;
384
410
  particle.gradient = {
385
411
  angle: {
386
- value: gradient.angle.value,
387
- enable: gradient.angle.animation.enable,
388
- velocity: (0,engine_root_window_.getRangeValue)(gradient.angle.animation.speed) / 360 * particle.container.retina.reduceFactor,
389
- decay: 1 - (0,engine_root_window_.getRangeValue)(gradient.angle.animation.decay)
412
+ value: (0,engine_root_window_.getRangeValue)(angle.value),
413
+ enable: angle.animation.enable,
414
+ velocity: (0,engine_root_window_.getRangeValue)(angle.animation.speed) / 360 * particle.container.retina.reduceFactor,
415
+ decay: 1 - (0,engine_root_window_.getRangeValue)(angle.animation.decay),
416
+ delayTime: (0,engine_root_window_.getRangeValue)(angle.animation.delay) * 1000,
417
+ time: 0
390
418
  },
391
419
  type: gradient.type,
392
420
  colors: []
393
421
  };
394
422
  let rotateDirection = gradient.angle.direction;
395
423
  if (rotateDirection === "random") {
396
- const index = Math.floor((0,engine_root_window_.getRandom)() * 2);
397
- rotateDirection = index > 0 ? "counter-clockwise" : "clockwise";
424
+ rotateDirection = (0,engine_root_window_.getRandom)() > 0.5 ? "counter-clockwise" : "clockwise";
398
425
  }
399
426
  switch (rotateDirection) {
400
427
  case "counter-clockwise":
@@ -422,27 +449,32 @@ class GradientUpdater {
422
449
  status: "increasing",
423
450
  value: (0,engine_root_window_.getRangeValue)(grColor.opacity.value),
424
451
  velocity: (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.speed) / 100 * particle.container.retina.reduceFactor,
425
- decay: 1 - (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.decay)
452
+ decay: 1 - (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.decay),
453
+ delayTime: (0,engine_root_window_.getRangeValue)(grColor.opacity.animation.delay) * 1000,
454
+ time: 0
426
455
  } : undefined
427
456
  };
428
- if (grColor.opacity && addColor.opacity) {
457
+ const {
458
+ opacity: addOpacity
459
+ } = addColor;
460
+ if (grColor.opacity && addOpacity) {
429
461
  const opacityRange = grColor.opacity.value;
430
- addColor.opacity.min = (0,engine_root_window_.getRangeMin)(opacityRange);
431
- addColor.opacity.max = (0,engine_root_window_.getRangeMax)(opacityRange);
462
+ addOpacity.min = (0,engine_root_window_.getRangeMin)(opacityRange);
463
+ addOpacity.max = (0,engine_root_window_.getRangeMax)(opacityRange);
432
464
  const opacityAnimation = grColor.opacity.animation;
433
465
  switch (opacityAnimation.startValue) {
434
466
  case "min":
435
- addColor.opacity.value = addColor.opacity.min;
436
- addColor.opacity.status = "increasing";
437
- break;
438
- case "random":
439
- addColor.opacity.value = (0,engine_root_window_.randomInRange)(addColor.opacity);
440
- addColor.opacity.status = (0,engine_root_window_.getRandom)() >= 0.5 ? "increasing" : "decreasing";
467
+ addOpacity.value = addOpacity.min;
468
+ addOpacity.status = "increasing";
441
469
  break;
442
470
  case "max":
471
+ addOpacity.value = addOpacity.max;
472
+ addOpacity.status = "decreasing";
473
+ break;
474
+ case "random":
443
475
  default:
444
- addColor.opacity.value = addColor.opacity.max;
445
- addColor.opacity.status = "decreasing";
476
+ addOpacity.value = (0,engine_root_window_.randomInRange)(addOpacity);
477
+ addOpacity.status = (0,engine_root_window_.getRandom)() >= 0.5 ? "increasing" : "decreasing";
446
478
  break;
447
479
  }
448
480
  }
@@ -450,12 +482,11 @@ class GradientUpdater {
450
482
  }
451
483
  }
452
484
  isEnabled(particle) {
453
- var _a, _b, _c;
454
- return !particle.destroyed && !particle.spawning && (((_a = particle.gradient) === null || _a === void 0 ? void 0 : _a.angle.enable) || ((_c = (_b = particle.gradient) === null || _b === void 0 ? void 0 : _b.colors.some(c => c.value.h.enable || c.value.s.enable || c.value.l.enable)) !== null && _c !== void 0 ? _c : false));
485
+ return !particle.destroyed && !particle.spawning && (particle.gradient?.angle.enable || (particle.gradient?.colors.some(c => c.value.h.enable || c.value.s.enable || c.value.l.enable) ?? false));
455
486
  }
456
487
  loadOptions(options, ...sources) {
457
488
  for (const source of sources) {
458
- if (!(source === null || source === void 0 ? void 0 : source.gradient)) {
489
+ if (!source?.gradient) {
459
490
  continue;
460
491
  }
461
492
  const gradientToLoad = source.gradient;
@@ -475,8 +506,8 @@ class GradientUpdater {
475
506
  }
476
507
  ;// CONCATENATED MODULE: ./dist/browser/index.js
477
508
 
478
- function loadGradientUpdater(engine) {
479
- engine.addParticleUpdater("gradient", () => new GradientUpdater());
509
+ async function loadGradientUpdater(engine, refresh = true) {
510
+ await engine.addParticleUpdater("gradient", () => new GradientUpdater(), refresh);
480
511
  }
481
512
  })();
482
513
 
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.updater.gradient.min.js.LICENSE.txt */
2
- !function(e,a){if("object"==typeof exports&&"object"==typeof module)module.exports=a(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],a);else{var t="object"==typeof exports?a(require("@tsparticles/engine")):a(e.window);for(var o in t)("object"==typeof exports?exports:e)[o]=t[o]}}(this,(e=>(()=>{"use strict";var a={533:a=>{a.exports=e}},t={};function o(e){var i=t[e];if(void 0!==i)return i.exports;var n=t[e]={exports:{}};return a[e](n,n.exports,o),n.exports}o.d=(e,a)=>{for(var t in a)o.o(a,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:a[t]})},o.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{o.r(i),o.d(i,{loadGradientUpdater:()=>p});var e=o(533);class a{constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.sync=!1,this.startValue="random"}load(a){a&&(void 0!==a.count&&(this.count=(0,e.setRangeValue)(a.count)),void 0!==a.enable&&(this.enable=a.enable),void 0!==a.speed&&(this.speed=(0,e.setRangeValue)(a.speed)),void 0!==a.sync&&(this.sync=a.sync),void 0!==a.startValue&&(this.startValue=a.startValue))}}class t{constructor(){this.value=0,this.animation=new a}load(a){a&&(this.animation.load(a.animation),void 0!==a.value&&(this.value=(0,e.setRangeValue)(a.value)))}}class n{constructor(){this.stop=0,this.value=new e.AnimatableColor}load(a){a&&(void 0!==a.stop&&(this.stop=a.stop),this.value=e.AnimatableColor.create(this.value,a.value),void 0!==a.opacity&&(this.opacity=new t,"number"==typeof a.opacity?this.opacity.value=a.opacity:this.opacity.load(a.opacity)))}}class l{constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.sync=!1}load(a){a&&(void 0!==a.count&&(this.count=(0,e.setRangeValue)(a.count)),void 0!==a.enable&&(this.enable=a.enable),void 0!==a.speed&&(this.speed=(0,e.setRangeValue)(a.speed)),void 0!==a.decay&&(this.decay=(0,e.setRangeValue)(a.decay)),void 0!==a.sync&&(this.sync=a.sync))}}class s{constructor(){this.value=0,this.animation=new l,this.direction="clockwise"}load(e){e&&(this.animation.load(e.animation),void 0!==e.value&&(this.value=e.value),void 0!==e.direction&&(this.direction=e.direction))}}class c{constructor(){this.angle=new s,this.colors=[],this.type="random"}load(e){e&&(this.angle.load(e.angle),void 0!==e.colors&&(this.colors=e.colors.map((e=>{const a=new n;return a.load(e),a}))),void 0!==e.type&&(this.type=e.type))}}function r(e,a){var t,o,i;if(!a.enable)return;const n=null!==(t=a.decay)&&void 0!==t?t:1;switch(a.status){case"increasing":a.value>=a.max?a.status="decreasing":a.value+=(null!==(o=a.velocity)&&void 0!==o?o:0)*e.factor;break;case"decreasing":a.value<=a.min?a.status="increasing":a.value-=(null!==(i=a.velocity)&&void 0!==i?i:0)*e.factor}a.velocity&&1!==n&&(a.velocity*=n)}function u(e,a,t,o){var i,n;const l=a;if(!l||!l.enable)return;const s=(null!==(i=a.velocity)&&void 0!==i?i:0)*e.factor,c=null!==(n=a.decay)&&void 0!==n?n:1;o&&"increasing"!==l.status?(l.value-=s,l.value<0&&(l.status="increasing",l.value+=l.value)):(l.value+=s,o&&l.value>t&&(l.status="decreasing",l.value-=l.value%t)),l.value>t&&(l.value%=t),a.velocity&&1!==c&&(a.velocity*=c)}function d(e,a){var t,o,i;const n=e.gradient;if(n){!function(e,a){var t,o;const i=(null!==(t=a.velocity)&&void 0!==t?t:0)*e.factor,n=2*Math.PI,l=null!==(o=a.decay)&&void 0!==o?o:1;a.enable&&("increasing"===a.status?(a.value+=i,a.value>n&&(a.value-=n)):(a.value-=i,a.value<0&&(a.value+=n)),a.velocity&&1!==l&&(a.velocity*=l))}(a,n.angle);for(const l of n.colors)void 0!==(null===(t=e.color)||void 0===t?void 0:t.h)&&u(a,l.value.h,360,!1),void 0!==(null===(o=e.color)||void 0===o?void 0:o.s)&&u(a,l.value.s,100,!0),void 0!==(null===(i=e.color)||void 0===i?void 0:i.l)&&u(a,l.value.l,100,!0),l.opacity&&r(a,l.opacity)}}class v{getColorStyles(a,t,o,i){var n,l;const s=a.gradient;if(!s)return{};const c=s.angle.value,r="radial"===s.type?t.createRadialGradient(0,0,0,0,0,o):t.createLinearGradient(Math.cos(c)*-o,Math.sin(c)*-o,Math.cos(c)*o,Math.sin(c)*o);for(const a of s.colors)r.addColorStop(a.stop,(0,e.getStyleFromHsl)({h:a.value.h.value,s:a.value.s.value,l:a.value.l.value},null!==(l=null===(n=a.opacity)||void 0===n?void 0:n.value)&&void 0!==l?l:i));return{fill:r}}init(a){const t=(0,e.itemFromSingleOrMultiple)(a.options.gradient);if(!t)return;a.gradient={angle:{value:t.angle.value,enable:t.angle.animation.enable,velocity:(0,e.getRangeValue)(t.angle.animation.speed)/360*a.container.retina.reduceFactor,decay:1-(0,e.getRangeValue)(t.angle.animation.decay)},type:t.type,colors:[]};let o=t.angle.direction;if("random"===o){o=Math.floor(2*(0,e.getRandom)())>0?"counter-clockwise":"clockwise"}switch(o){case"counter-clockwise":case"counterClockwise":a.gradient.angle.status="decreasing";break;case"clockwise":a.gradient.angle.status="increasing"}const i=a.options.reduceDuplicates;for(const o of t.colors){const t=(0,e.rangeColorToHsl)(o.value,a.id,i);if(!t)continue;const n=(0,e.getHslAnimationFromHsl)(t,o.value.animation,a.container.retina.reduceFactor),l={stop:o.stop,value:n,opacity:o.opacity?{enable:o.opacity.animation.enable,max:(0,e.getRangeMax)(o.opacity.value),min:(0,e.getRangeMin)(o.opacity.value),status:"increasing",value:(0,e.getRangeValue)(o.opacity.value),velocity:(0,e.getRangeValue)(o.opacity.animation.speed)/100*a.container.retina.reduceFactor,decay:1-(0,e.getRangeValue)(o.opacity.animation.decay)}:void 0};if(o.opacity&&l.opacity){const a=o.opacity.value;l.opacity.min=(0,e.getRangeMin)(a),l.opacity.max=(0,e.getRangeMax)(a);switch(o.opacity.animation.startValue){case"min":l.opacity.value=l.opacity.min,l.opacity.status="increasing";break;case"random":l.opacity.value=(0,e.randomInRange)(l.opacity),l.opacity.status=(0,e.getRandom)()>=.5?"increasing":"decreasing";break;default:l.opacity.value=l.opacity.max,l.opacity.status="decreasing"}}a.gradient.colors.push(l)}}isEnabled(e){var a,t,o;return!e.destroyed&&!e.spawning&&((null===(a=e.gradient)||void 0===a?void 0:a.angle.enable)||null!==(o=null===(t=e.gradient)||void 0===t?void 0:t.colors.some((e=>e.value.h.enable||e.value.s.enable||e.value.l.enable)))&&void 0!==o&&o)}loadOptions(a,...t){for(const o of t){if(!(null==o?void 0:o.gradient))continue;const t=o.gradient;t&&(a.gradient=(0,e.executeOnSingleOrMultiple)(t,(e=>{const a=new c;return a.load(e),a})))}}update(e,a){d(e,a)}}function p(e){e.addParticleUpdater("gradient",(()=>new v))}})(),i})()));
2
+ !function(e,a){if("object"==typeof exports&&"object"==typeof module)module.exports=a(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],a);else{var t="object"==typeof exports?a(require("@tsparticles/engine")):a(e.window);for(var i in t)("object"==typeof exports?exports:e)[i]=t[i]}}(this,(e=>(()=>{"use strict";var a={533:a=>{a.exports=e}},t={};function i(e){var n=t[e];if(void 0!==n)return n.exports;var o=t[e]={exports:{}};return a[e](o,o.exports,i),o.exports}i.d=(e,a)=>{for(var t in a)i.o(a,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:a[t]})},i.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{i.r(n),i.d(n,{loadGradientUpdater:()=>y});var e=i(533);class a{constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.delay=0,this.sync=!1,this.startValue="random"}load(a){a&&(void 0!==a.count&&(this.count=(0,e.setRangeValue)(a.count)),void 0!==a.enable&&(this.enable=a.enable),void 0!==a.speed&&(this.speed=(0,e.setRangeValue)(a.speed)),void 0!==a.sync&&(this.sync=a.sync),void 0!==a.startValue&&(this.startValue=a.startValue),void 0!==a.decay&&(this.decay=(0,e.setRangeValue)(a.decay)),void 0!==a.delay&&(this.delay=(0,e.setRangeValue)(a.delay)))}}class t{constructor(){this.value=0,this.animation=new a}load(a){a&&(this.animation.load(a.animation),void 0!==a.value&&(this.value=(0,e.setRangeValue)(a.value)))}}class o{constructor(){this.stop=0,this.value=new e.AnimatableColor}load(a){a&&(void 0!==a.stop&&(this.stop=a.stop),this.value=e.AnimatableColor.create(this.value,a.value),void 0!==a.opacity&&(this.opacity=new t,(0,e.isNumber)(a.opacity)?this.opacity.value=a.opacity:this.opacity.load(a.opacity)))}}class s{constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.delay=0,this.sync=!1}load(a){a&&(void 0!==a.count&&(this.count=(0,e.setRangeValue)(a.count)),void 0!==a.enable&&(this.enable=a.enable),void 0!==a.speed&&(this.speed=(0,e.setRangeValue)(a.speed)),void 0!==a.decay&&(this.decay=(0,e.setRangeValue)(a.decay)),void 0!==a.delay&&(this.delay=(0,e.setRangeValue)(a.delay)),void 0!==a.sync&&(this.sync=a.sync))}}class l{constructor(){this.value=0,this.animation=new s,this.direction="clockwise"}load(a){a&&(this.animation.load(a.animation),void 0!==a.value&&(this.value=(0,e.setRangeValue)(a.value)),void 0!==a.direction&&(this.direction=a.direction))}}class c{constructor(){this.angle=new l,this.colors=[],this.type="random"}load(e){e&&(this.angle.load(e.angle),void 0!==e.colors&&(this.colors=e.colors.map((e=>{const a=new o;return a.load(e),a}))),void 0!==e.type&&(this.type=e.type))}}function r(e,a){if(!a.enable)return;const t=a.decay??1;switch(a.status){case"increasing":a.value>=a.max?a.status="decreasing":a.value+=(a.velocity??0)*e.factor;break;case"decreasing":a.value<=a.min?a.status="increasing":a.value-=(a.velocity??0)*e.factor}a.velocity&&1!==t&&(a.velocity*=t)}function u(e,a,t,i){if(!a||!a.enable)return;if(a.time||(a.time=0),(a.delayTime??0)>0&&a.time<(a.delayTime??0)&&(a.time+=e.value),(a.delayTime??0)>0&&a.time<(a.delayTime??0))return;const n=(a.velocity??0)*e.factor,o=a.decay??1;i&&"increasing"!==a.status?(a.value-=n,a.value<0&&(a.status="increasing",a.value+=a.value)):(a.value+=n,i&&a.value>t&&(a.status="decreasing",a.value-=a.value%t)),a.value>t&&(a.value%=t),a.velocity&&1!==o&&(a.velocity*=o)}function d(e,a){const{gradient:t}=e;if(t){!function(e,a){const t=(a.velocity??0)*e.factor,i=2*Math.PI,n=a.decay??1;a.enable&&("increasing"===a.status?(a.value+=t,a.value>i&&(a.value-=i)):(a.value-=t,a.value<0&&(a.value+=i)),a.velocity&&1!==n&&(a.velocity*=n))}(a,t.angle);for(const i of t.colors)void 0!==e.color?.h&&u(a,i.value.h,360,!1),void 0!==e.color?.s&&u(a,i.value.s,100,!0),void 0!==e.color?.l&&u(a,i.value.l,100,!0),i.opacity&&r(a,i.opacity)}}class v{getColorStyles(a,t,i,n){const o=a.gradient;if(!o)return{};const s=o.angle.value,l="radial"===o.type?t.createRadialGradient(0,0,0,0,0,i):t.createLinearGradient(Math.cos(s)*-i,Math.sin(s)*-i,Math.cos(s)*i,Math.sin(s)*i);for(const{stop:a,value:t,opacity:i}of o.colors)l.addColorStop(a,(0,e.getStyleFromHsl)({h:t.h.value,s:t.s.value,l:t.l.value},i?.value??n));return{fill:l}}init(a){const t=(0,e.itemFromSingleOrMultiple)(a.options.gradient);if(!t)return;const{angle:i}=t;a.gradient={angle:{value:(0,e.getRangeValue)(i.value),enable:i.animation.enable,velocity:(0,e.getRangeValue)(i.animation.speed)/360*a.container.retina.reduceFactor,decay:1-(0,e.getRangeValue)(i.animation.decay),delayTime:1e3*(0,e.getRangeValue)(i.animation.delay),time:0},type:t.type,colors:[]};let n=t.angle.direction;switch("random"===n&&(n=(0,e.getRandom)()>.5?"counter-clockwise":"clockwise"),n){case"counter-clockwise":case"counterClockwise":a.gradient.angle.status="decreasing";break;case"clockwise":a.gradient.angle.status="increasing"}const o=a.options.reduceDuplicates;for(const i of t.colors){const t=(0,e.rangeColorToHsl)(i.value,a.id,o);if(!t)continue;const n=(0,e.getHslAnimationFromHsl)(t,i.value.animation,a.container.retina.reduceFactor),s={stop:i.stop,value:n,opacity:i.opacity?{enable:i.opacity.animation.enable,max:(0,e.getRangeMax)(i.opacity.value),min:(0,e.getRangeMin)(i.opacity.value),status:"increasing",value:(0,e.getRangeValue)(i.opacity.value),velocity:(0,e.getRangeValue)(i.opacity.animation.speed)/100*a.container.retina.reduceFactor,decay:1-(0,e.getRangeValue)(i.opacity.animation.decay),delayTime:1e3*(0,e.getRangeValue)(i.opacity.animation.delay),time:0}:void 0},{opacity:l}=s;if(i.opacity&&l){const a=i.opacity.value;l.min=(0,e.getRangeMin)(a),l.max=(0,e.getRangeMax)(a);switch(i.opacity.animation.startValue){case"min":l.value=l.min,l.status="increasing";break;case"max":l.value=l.max,l.status="decreasing";break;default:l.value=(0,e.randomInRange)(l),l.status=(0,e.getRandom)()>=.5?"increasing":"decreasing"}}a.gradient.colors.push(s)}}isEnabled(e){return!e.destroyed&&!e.spawning&&(e.gradient?.angle.enable||(e.gradient?.colors.some((e=>e.value.h.enable||e.value.s.enable||e.value.l.enable))??!1))}loadOptions(a,...t){for(const i of t){if(!i?.gradient)continue;const t=i.gradient;t&&(a.gradient=(0,e.executeOnSingleOrMultiple)(t,(e=>{const a=new c;return a.load(e),a})))}}update(e,a){d(e,a)}}async function y(e,a=!0){await e.addParticleUpdater("gradient",(()=>new v),a)}})(),n})()));
@@ -1,8 +1 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
8
- */
1
+ /*! tsParticles Gradient Updater v3.0.0-beta.0 by Matteo Bruni */
@@ -1,27 +1,5 @@
1
- import { GradientType } from "@tsparticles/engine";
2
- import type { IDelta, IParticleColorStyle, IParticleHslAnimation, IParticleNumericValueAnimation, IParticleUpdater, IParticleValueAnimation, IParticlesOptions, Particle, ParticlesOptions, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
3
- import { AnimatableGradient } from "./Options/Classes/AnimatableGradient";
4
- import type { IAnimatableGradient } from "./Options/Interfaces/IAnimatableGradient";
5
- interface IParticleGradientColorAnimation {
6
- opacity?: IParticleNumericValueAnimation;
7
- stop: number;
8
- value: IParticleHslAnimation;
9
- }
10
- interface IParticleGradientAnimation {
11
- angle: IParticleValueAnimation<number>;
12
- colors: IParticleGradientColorAnimation[];
13
- type: GradientType;
14
- }
15
- type GradientParticle = Particle & {
16
- gradient?: IParticleGradientAnimation;
17
- options: GradientParticlesOptions;
18
- };
19
- type IGradientParticlesOptions = IParticlesOptions & {
20
- gradient?: SingleOrMultiple<IAnimatableGradient>;
21
- };
22
- type GradientParticlesOptions = ParticlesOptions & {
23
- gradient?: SingleOrMultiple<AnimatableGradient>;
24
- };
1
+ import { type IDelta, type IParticleColorStyle, type IParticleUpdater, type RecursivePartial } from "@tsparticles/engine";
2
+ import type { GradientParticle, GradientParticlesOptions, IGradientParticlesOptions } from "./Types";
25
3
  export declare class GradientUpdater implements IParticleUpdater {
26
4
  getColorStyles(particle: GradientParticle, context: CanvasRenderingContext2D, radius: number, opacity: number): IParticleColorStyle;
27
5
  init(particle: GradientParticle): void;
@@ -29,4 +7,3 @@ export declare class GradientUpdater implements IParticleUpdater {
29
7
  loadOptions(options: GradientParticlesOptions, ...sources: (RecursivePartial<IGradientParticlesOptions> | undefined)[]): void;
30
8
  update(particle: GradientParticle, delta: IDelta): void;
31
9
  }
32
- export {};
@@ -1,7 +1,6 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
1
+ import { GradientType, type IOptionLoader, type RecursivePartial } from "@tsparticles/engine";
2
2
  import { AnimatableGradientColor } from "./AnimatableGradientColor";
3
3
  import { GradientAngle } from "./GradientAngle";
4
- import { GradientType } from "@tsparticles/engine";
5
4
  import type { IAnimatableGradient } from "../Interfaces/IAnimatableGradient";
6
5
  export declare class AnimatableGradient implements IAnimatableGradient, IOptionLoader<IAnimatableGradient> {
7
6
  angle: GradientAngle;
@@ -1,5 +1,4 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
- import { AnimatableColor } from "@tsparticles/engine";
1
+ import { AnimatableColor, type IOptionLoader, type RecursivePartial } from "@tsparticles/engine";
3
2
  import { GradientColorOpacity } from "./GradientColorOpacity";
4
3
  import type { IAnimatableGradientColor } from "../Interfaces/IOptionsGradient";
5
4
  export declare class AnimatableGradientColor implements IAnimatableGradientColor, IOptionLoader<IAnimatableGradientColor> {
@@ -1,11 +1,10 @@
1
- import type { IAnimatable, IAnimation, IOptionLoader, RecursivePartial, RotateDirectionAlt } from "@tsparticles/engine";
1
+ import { type IAnimatable, type IAnimation, type IOptionLoader, type RangeValue, type RecursivePartial, RotateDirection, type RotateDirectionAlt } from "@tsparticles/engine";
2
2
  import { GradientAngleAnimation } from "./GradientAngleAnimation";
3
3
  import type { IGradientAngle } from "../Interfaces/Gradients";
4
- import { RotateDirection } from "@tsparticles/engine";
5
4
  export declare class GradientAngle implements IGradientAngle, IAnimatable<IAnimation>, IOptionLoader<IGradientAngle & IAnimatable<IAnimation>> {
6
5
  animation: GradientAngleAnimation;
7
6
  direction: RotateDirection | keyof typeof RotateDirection | RotateDirectionAlt;
8
- value: number;
7
+ value: RangeValue;
9
8
  constructor();
10
9
  load(data?: RecursivePartial<IGradientAngle & IAnimatable<IAnimation>>): void;
11
10
  }
@@ -1,7 +1,8 @@
1
- import type { IAnimation, IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
1
+ import { type IAnimation, type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine";
2
2
  export declare class GradientAngleAnimation implements IAnimation, IOptionLoader<IAnimation> {
3
3
  count: RangeValue;
4
4
  decay: RangeValue;
5
+ delay: RangeValue;
5
6
  enable: boolean;
6
7
  speed: RangeValue;
7
8
  sync: boolean;
@@ -1,4 +1,4 @@
1
- import type { IAnimatable, IAnimation, IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
1
+ import { type IAnimatable, type IAnimation, type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine";
2
2
  import { GradientColorOpacityAnimation } from "./GradientColorOpacityAnimation";
3
3
  import type { IGradientColorOpacity } from "../Interfaces/Gradients";
4
4
  import type { IGradientColorOpacityAnimation } from "../Interfaces/IOptionsGradient";
@@ -1,9 +1,9 @@
1
- import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
2
- import { StartValueType } from "@tsparticles/engine";
1
+ import { type IOptionLoader, type RangeValue, type RecursivePartial, StartValueType } from "@tsparticles/engine";
3
2
  import type { IGradientColorOpacityAnimation } from "../Interfaces/IOptionsGradient";
4
3
  export declare class GradientColorOpacityAnimation implements IGradientColorOpacityAnimation, IOptionLoader<IGradientColorOpacityAnimation> {
5
4
  count: RangeValue;
6
5
  decay: RangeValue;
6
+ delay: RangeValue;
7
7
  enable: boolean;
8
8
  speed: RangeValue;
9
9
  startValue: StartValueType | keyof typeof StartValueType;
@@ -9,7 +9,7 @@ export interface IGradientColor {
9
9
  }
10
10
  export interface IGradientAngle {
11
11
  direction: RotateDirection | keyof typeof RotateDirection | RotateDirectionAlt;
12
- value: number;
12
+ value: RangeValue;
13
13
  }
14
14
  export interface IGradient {
15
15
  angle?: IGradientAngle;
@@ -0,0 +1,23 @@
1
+ import type { GradientType, IParticleHslAnimation, IParticleNumericValueAnimation, IParticleValueAnimation, IParticlesOptions, Particle, ParticlesOptions, SingleOrMultiple } from "@tsparticles/engine";
2
+ import type { AnimatableGradient } from "./Options/Classes/AnimatableGradient";
3
+ import type { IAnimatableGradient } from "./Options/Interfaces/IAnimatableGradient";
4
+ export interface IParticleGradientColorAnimation {
5
+ opacity?: IParticleNumericValueAnimation;
6
+ stop: number;
7
+ value: IParticleHslAnimation;
8
+ }
9
+ export interface IParticleGradientAnimation {
10
+ angle: IParticleValueAnimation<number>;
11
+ colors: IParticleGradientColorAnimation[];
12
+ type: GradientType;
13
+ }
14
+ export type GradientParticle = Particle & {
15
+ gradient?: IParticleGradientAnimation;
16
+ options: GradientParticlesOptions;
17
+ };
18
+ export type IGradientParticlesOptions = IParticlesOptions & {
19
+ gradient?: SingleOrMultiple<IAnimatableGradient>;
20
+ };
21
+ export type GradientParticlesOptions = ParticlesOptions & {
22
+ gradient?: SingleOrMultiple<AnimatableGradient>;
23
+ };
@@ -0,0 +1,3 @@
1
+ import { type IDelta } from "@tsparticles/engine";
2
+ import type { GradientParticle } from "./Types";
3
+ export declare function updateGradient(particle: GradientParticle, delta: IDelta): void;
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadGradientUpdater(engine: Engine): void;
2
+ export declare function loadGradientUpdater(engine: Engine, refresh?: boolean): Promise<void>;