@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.
- package/README.md +16 -12
- package/browser/GradientUpdater.js +34 -132
- package/browser/Options/Classes/AnimatableGradientColor.js +2 -2
- package/browser/Options/Classes/GradientAngle.js +2 -1
- package/browser/Options/Classes/GradientAngleAnimation.js +5 -1
- package/browser/Options/Classes/GradientColorOpacity.js +1 -1
- package/browser/Options/Classes/GradientColorOpacityAnimation.js +8 -1
- package/browser/Types.js +1 -0
- package/browser/Utils.js +107 -0
- package/browser/index.js +2 -2
- package/cjs/GradientUpdater.js +35 -133
- package/cjs/Options/Classes/AnimatableGradientColor.js +1 -1
- package/cjs/Options/Classes/GradientAngle.js +2 -1
- package/cjs/Options/Classes/GradientAngleAnimation.js +4 -0
- package/cjs/Options/Classes/GradientColorOpacity.js +1 -1
- package/cjs/Options/Classes/GradientColorOpacityAnimation.js +7 -0
- package/cjs/Types.js +2 -0
- package/cjs/Utils.js +111 -0
- package/cjs/index.js +2 -2
- package/esm/GradientUpdater.js +34 -132
- package/esm/Options/Classes/AnimatableGradientColor.js +2 -2
- package/esm/Options/Classes/GradientAngle.js +2 -1
- package/esm/Options/Classes/GradientAngleAnimation.js +5 -1
- package/esm/Options/Classes/GradientColorOpacity.js +1 -1
- package/esm/Options/Classes/GradientColorOpacityAnimation.js +8 -1
- package/esm/Types.js +1 -0
- package/esm/Utils.js +107 -0
- package/esm/index.js +2 -2
- package/package.json +10 -5
- package/report.html +4 -4
- package/tsparticles.updater.gradient.js +87 -56
- package/tsparticles.updater.gradient.min.js +1 -1
- package/tsparticles.updater.gradient.min.js.LICENSE.txt +1 -8
- package/types/GradientUpdater.d.ts +2 -25
- package/types/Options/Classes/AnimatableGradient.d.ts +1 -2
- package/types/Options/Classes/AnimatableGradientColor.d.ts +1 -2
- package/types/Options/Classes/GradientAngle.d.ts +2 -3
- package/types/Options/Classes/GradientAngleAnimation.d.ts +2 -1
- package/types/Options/Classes/GradientColorOpacity.d.ts +1 -1
- package/types/Options/Classes/GradientColorOpacityAnimation.d.ts +2 -2
- package/types/Options/Interfaces/Gradients.d.ts +1 -1
- package/types/Types.d.ts +23 -0
- package/types/Utils.d.ts +3 -0
- package/types/index.d.ts +1 -1
- package/umd/GradientUpdater.js +36 -134
- package/umd/Options/Classes/AnimatableGradientColor.js +1 -1
- package/umd/Options/Classes/GradientAngle.js +3 -2
- package/umd/Options/Classes/GradientAngleAnimation.js +4 -0
- package/umd/Options/Classes/GradientColorOpacity.js +2 -2
- package/umd/Options/Classes/GradientColorOpacityAnimation.js +7 -0
- package/umd/Types.js +12 -0
- package/umd/Utils.js +121 -0
- 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-
|
|
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
|
-
|
|
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 (
|
|
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/
|
|
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 =
|
|
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 += (
|
|
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 -= (
|
|
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,
|
|
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
|
-
|
|
289
|
-
|
|
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 (
|
|
307
|
-
|
|
322
|
+
if (colorValue.velocity && decay !== 1) {
|
|
323
|
+
colorValue.velocity *= decay;
|
|
308
324
|
}
|
|
309
325
|
}
|
|
310
326
|
function updateAngle(delta, angle) {
|
|
311
|
-
|
|
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 =
|
|
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
|
-
|
|
339
|
-
|
|
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 (
|
|
361
|
+
if (particle.color?.h !== undefined) {
|
|
346
362
|
updateColorValue(delta, color.value.h, 360, false);
|
|
347
363
|
}
|
|
348
|
-
if (
|
|
364
|
+
if (particle.color?.s !== undefined) {
|
|
349
365
|
updateColorValue(delta, color.value.s, 100, true);
|
|
350
366
|
}
|
|
351
|
-
if (
|
|
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
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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:
|
|
387
|
-
enable:
|
|
388
|
-
velocity: (0,engine_root_window_.getRangeValue)(
|
|
389
|
-
decay: 1 - (0,engine_root_window_.getRangeValue)(
|
|
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
|
-
|
|
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
|
-
|
|
457
|
+
const {
|
|
458
|
+
opacity: addOpacity
|
|
459
|
+
} = addColor;
|
|
460
|
+
if (grColor.opacity && addOpacity) {
|
|
429
461
|
const opacityRange = grColor.opacity.value;
|
|
430
|
-
|
|
431
|
-
|
|
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
|
-
|
|
436
|
-
|
|
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
|
-
|
|
445
|
-
|
|
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
|
-
|
|
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 (!
|
|
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
|
|
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 {
|
|
2
|
-
import type {
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
7
|
+
value: RangeValue;
|
|
9
8
|
constructor();
|
|
10
9
|
load(data?: RecursivePartial<IGradientAngle & IAnimatable<IAnimation>>): void;
|
|
11
10
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type
|
|
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
|
|
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
|
|
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;
|
package/types/Types.d.ts
ADDED
|
@@ -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
|
+
};
|
package/types/Utils.d.ts
ADDED
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>;
|