@tsparticles/updater-gradient 4.0.0-beta.0 → 4.0.0-beta.10
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/210.min.js +1 -0
- package/README.md +29 -0
- package/browser/GradientUpdater.js +11 -10
- package/browser/index.js +4 -4
- package/cjs/GradientUpdater.js +11 -10
- package/cjs/index.js +4 -4
- package/dist_browser_GradientUpdater_js.js +2 -2
- package/esm/GradientUpdater.js +11 -10
- package/esm/index.js +4 -4
- package/package.json +4 -5
- package/report.html +84 -29
- package/tsparticles.updater.gradient.js +2 -2
- package/tsparticles.updater.gradient.min.js +2 -2
- package/types/GradientUpdater.d.ts +5 -4
- package/711.min.js +0 -1
- package/umd/GradientUpdater.js +0 -146
- package/umd/Options/Classes/AnimatableGradient.js +0 -43
- package/umd/Options/Classes/AnimatableGradientColor.js +0 -43
- package/umd/Options/Classes/GradientAngle.js +0 -38
- package/umd/Options/Classes/GradientAngleAnimation.js +0 -54
- package/umd/Options/Classes/GradientColorOpacity.js +0 -33
- package/umd/Options/Classes/GradientColorOpacityAnimation.js +0 -59
- package/umd/Options/Interfaces/Gradients.js +0 -12
- package/umd/Options/Interfaces/IAnimatableGradient.js +0 -12
- package/umd/Options/Interfaces/IOptionsGradient.js +0 -12
- package/umd/Types.js +0 -12
- package/umd/Utils.js +0 -27
- package/umd/index.js +0 -56
package/210.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_updater_gradient=this.webpackChunk_tsparticles_updater_gradient||[]).push([[210],{210(e,a,t){t.d(a,{GradientUpdater:()=>u});var i=t(303);class n{count;decay;delay;enable;speed;startValue;sync;constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.delay=0,this.sync=!1,this.startValue=i.StartValueType.random}load(e){(0,i.isNull)(e)||(void 0!==e.count&&(this.count=(0,i.setRangeValue)(e.count)),void 0!==e.enable&&(this.enable=e.enable),void 0!==e.speed&&(this.speed=(0,i.setRangeValue)(e.speed)),void 0!==e.sync&&(this.sync=e.sync),void 0!==e.startValue&&(this.startValue=e.startValue),void 0!==e.decay&&(this.decay=(0,i.setRangeValue)(e.decay)),void 0!==e.delay&&(this.delay=(0,i.setRangeValue)(e.delay)))}}class o{animation;value;constructor(){this.value=0,this.animation=new n}load(e){(0,i.isNull)(e)||(this.animation.load(e.animation),void 0!==e.value&&(this.value=(0,i.setRangeValue)(e.value)))}}class l{opacity;stop;value;constructor(){this.stop=0,this.value=new i.AnimatableColor}load(e){(0,i.isNull)(e)||(void 0!==e.stop&&(this.stop=e.stop),this.value=i.AnimatableColor.create(this.value,e.value),void 0!==e.opacity&&(this.opacity=new o,(0,i.isNumber)(e.opacity)?this.opacity.value=e.opacity:this.opacity.load(e.opacity)))}}class s{count;decay;delay;enable;speed;sync;constructor(){this.count=0,this.enable=!1,this.speed=0,this.decay=0,this.delay=0,this.sync=!1}load(e){(0,i.isNull)(e)||(void 0!==e.count&&(this.count=(0,i.setRangeValue)(e.count)),void 0!==e.enable&&(this.enable=e.enable),void 0!==e.speed&&(this.speed=(0,i.setRangeValue)(e.speed)),void 0!==e.decay&&(this.decay=(0,i.setRangeValue)(e.decay)),void 0!==e.delay&&(this.delay=(0,i.setRangeValue)(e.delay)),void 0!==e.sync&&(this.sync=e.sync))}}class c{animation;direction;value;constructor(){this.value=0,this.animation=new s,this.direction=i.RotateDirection.clockwise}load(e){(0,i.isNull)(e)||(this.animation.load(e.animation),void 0!==e.value&&(this.value=(0,i.setRangeValue)(e.value)),void 0!==e.direction&&(this.direction=e.direction))}}class r{angle;colors;type;constructor(){this.angle=new c,this.colors=[],this.type=i.GradientType.random}load(e){(0,i.isNull)(e)||(this.angle.load(e.angle),void 0!==e.colors&&(this.colors=e.colors.map(e=>{let a=new l;return a.load(e),a})),void 0!==e.type&&(this.type=e.type))}}class u{_container;_pluginManager;constructor(e,a){this._pluginManager=e,this._container=a}getColorStyles(e,a,t,n){let o=e.gradient;if(!o)return{};let{_container:l}=this,s=o.angle.value,c=o.type===i.GradientType.radial?a.createRadialGradient(0,0,0,0,0,t):a.createLinearGradient(-(Math.cos(s)*t),-(Math.sin(s)*t),Math.cos(s)*t,Math.sin(s)*t);for(let{stop:e,value:a,opacity:t}of o.colors){let o={h:a.h.value,s:a.s.value,l:a.l.value};c.addColorStop(e,(0,i.getStyleFromHsl)(o,l.hdr,t?.value??n))}return{fill:c}}init(e){let a=(0,i.itemFromSingleOrMultiple)(e.options.gradient);if(!a)return;let t=this._container,{angle:n}=a;e.gradient={angle:{value:(0,i.getRangeValue)(n.value),enable:n.animation.enable,velocity:(0,i.getRangeValue)(n.animation.speed)/360*t.retina.reduceFactor,decay:1-(0,i.getRangeValue)(n.animation.decay),delayTime:(0,i.getRangeValue)(n.animation.delay)*i.millisecondsToSeconds,max:i.doublePI,min:0,time:0},type:a.type,colors:[]};let o=a.angle.direction;switch(o===i.RotateDirection.random&&(o=(0,i.getRandom)()>i.half?i.RotateDirection.counterClockwise:i.RotateDirection.clockwise),o){case i.RotateDirection.counterClockwise:case"counterClockwise":e.gradient.angle.status=i.AnimationStatus.decreasing;break;case i.RotateDirection.clockwise:e.gradient.angle.status=i.AnimationStatus.increasing}let l=e.options.reduceDuplicates;for(let n of a.colors){let a=(0,i.rangeColorToHsl)(this._pluginManager,n.value,e.id,l);if(!a)continue;let o=(0,i.getHslAnimationFromHsl)(a,n.value.animation,t.retina.reduceFactor),s={stop:n.stop,value:o,opacity:n.opacity?{enable:n.opacity.animation.enable,max:(0,i.getRangeMax)(n.opacity.value),min:(0,i.getRangeMin)(n.opacity.value),status:i.AnimationStatus.increasing,value:(0,i.getRangeValue)(n.opacity.value),velocity:(0,i.getRangeValue)(n.opacity.animation.speed)/i.percentDenominator*t.retina.reduceFactor,decay:1-(0,i.getRangeValue)(n.opacity.animation.decay),delayTime:(0,i.getRangeValue)(n.opacity.animation.delay)*i.millisecondsToSeconds,time:0}:void 0},{opacity:c}=s;if(n.opacity&&c){let e=n.opacity.value;switch(c.min=(0,i.getRangeMin)(e),c.max=(0,i.getRangeMax)(e),n.opacity.animation.startValue){case i.StartValueType.min:c.value=c.min,c.status=i.AnimationStatus.increasing;break;case i.StartValueType.max:c.value=c.max,c.status=i.AnimationStatus.decreasing;break;case i.StartValueType.random:default:c.value=(0,i.randomInRangeValue)(c),c.status=(0,i.getRandom)()>=i.half?i.AnimationStatus.increasing:i.AnimationStatus.decreasing}}e.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(e,...a){for(let t of a){if(!t?.gradient)continue;let a=t.gradient;e.gradient=(0,i.executeOnSingleOrMultiple)(a,e=>{let a=new r;return a.load(e),a})}}update(e,a){!function(e,a){let{gradient:t}=e;if(t)for(let n of((0,i.updateAnimation)(e,t.angle,!1,i.DestroyType.none,a),t.colors))(0,i.updateColor)(n.value,a),n.opacity&&(0,i.updateAnimation)(e,n.opacity,!0,i.DestroyType.none,a)}(e,a)}}}}]);
|
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/tsparticles/tsparticles) updater plugin for gradient animations.
|
|
10
10
|
|
|
11
|
+
## Quick checklist
|
|
12
|
+
|
|
13
|
+
1. Install `@tsparticles/engine` (or use the CDN bundle below)
|
|
14
|
+
2. Call the package loader function(s) before `tsParticles.load(...)`
|
|
15
|
+
3. Apply the package options in your `tsParticles.load(...)` config
|
|
16
|
+
|
|
11
17
|
## How to use it
|
|
12
18
|
|
|
13
19
|
### CDN / Vanilla JS / jQuery
|
|
@@ -72,3 +78,26 @@ import { loadGradientUpdater } from "@tsparticles/updater-gradient";
|
|
|
72
78
|
await loadGradientUpdater(tsParticles);
|
|
73
79
|
})();
|
|
74
80
|
```
|
|
81
|
+
|
|
82
|
+
## Option mapping
|
|
83
|
+
|
|
84
|
+
- Primary options key: `particles.color`
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"particles": {
|
|
89
|
+
"color": {}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Common pitfalls
|
|
95
|
+
|
|
96
|
+
- Calling `tsParticles.load(...)` before `loadGradientUpdater(...)`
|
|
97
|
+
- Verify required peer packages before enabling advanced options
|
|
98
|
+
- Change one option group at a time to isolate regressions quickly
|
|
99
|
+
|
|
100
|
+
## Related docs
|
|
101
|
+
|
|
102
|
+
- All packages catalog: <https://github.com/tsparticles/tsparticles>
|
|
103
|
+
- Main docs: <https://particles.js.org/docs/>
|
|
@@ -2,16 +2,18 @@ import { AnimationStatus, GradientType, RotateDirection, StartValueType, doubleP
|
|
|
2
2
|
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
3
|
import { updateGradient } from "./Utils.js";
|
|
4
4
|
export class GradientUpdater {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
_container;
|
|
6
|
+
_pluginManager;
|
|
7
|
+
constructor(pluginManager, container) {
|
|
8
|
+
this._pluginManager = pluginManager;
|
|
9
|
+
this._container = container;
|
|
8
10
|
}
|
|
9
11
|
getColorStyles(particle, context, radius, opacity) {
|
|
10
12
|
const gradient = particle.gradient;
|
|
11
13
|
if (!gradient) {
|
|
12
14
|
return {};
|
|
13
15
|
}
|
|
14
|
-
const { container } =
|
|
16
|
+
const { _container: container } = this, gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === GradientType.radial
|
|
15
17
|
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
16
18
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
17
19
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
@@ -29,12 +31,12 @@ export class GradientUpdater {
|
|
|
29
31
|
if (!gradient) {
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
|
-
const { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
34
|
+
const container = this._container, { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
33
35
|
particle.gradient = {
|
|
34
36
|
angle: {
|
|
35
37
|
value: getRangeValue(angle.value),
|
|
36
38
|
enable: angle.animation.enable,
|
|
37
|
-
velocity: (getRangeValue(angle.animation.speed) / speedFactor) *
|
|
39
|
+
velocity: (getRangeValue(angle.animation.speed) / speedFactor) * container.retina.reduceFactor,
|
|
38
40
|
decay: delayOffset - getRangeValue(angle.animation.decay),
|
|
39
41
|
delayTime: getRangeValue(angle.animation.delay) * millisecondsToSeconds,
|
|
40
42
|
max: doublePI,
|
|
@@ -61,11 +63,11 @@ export class GradientUpdater {
|
|
|
61
63
|
}
|
|
62
64
|
const reduceDuplicates = particle.options.reduceDuplicates;
|
|
63
65
|
for (const grColor of gradient.colors) {
|
|
64
|
-
const grHslColor = rangeColorToHsl(this.
|
|
66
|
+
const grHslColor = rangeColorToHsl(this._pluginManager, grColor.value, particle.id, reduceDuplicates);
|
|
65
67
|
if (!grHslColor) {
|
|
66
68
|
continue;
|
|
67
69
|
}
|
|
68
|
-
const grHslAnimation = getHslAnimationFromHsl(grHslColor, grColor.value.animation,
|
|
70
|
+
const grHslAnimation = getHslAnimationFromHsl(grHslColor, grColor.value.animation, container.retina.reduceFactor), addColor = {
|
|
69
71
|
stop: grColor.stop,
|
|
70
72
|
value: grHslAnimation,
|
|
71
73
|
opacity: grColor.opacity
|
|
@@ -75,8 +77,7 @@ export class GradientUpdater {
|
|
|
75
77
|
min: getRangeMin(grColor.opacity.value),
|
|
76
78
|
status: AnimationStatus.increasing,
|
|
77
79
|
value: getRangeValue(grColor.opacity.value),
|
|
78
|
-
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) *
|
|
79
|
-
particle.container.retina.reduceFactor,
|
|
80
|
+
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) * container.retina.reduceFactor,
|
|
80
81
|
decay: delayOffset - getRangeValue(grColor.opacity.animation.decay),
|
|
81
82
|
delayTime: getRangeValue(grColor.opacity.animation.delay) * millisecondsToSeconds,
|
|
82
83
|
time: 0,
|
package/browser/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export async function loadGradientUpdater(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-beta.
|
|
3
|
-
await engine.register(e => {
|
|
4
|
-
e.addParticleUpdater("gradient", async () => {
|
|
2
|
+
engine.checkVersion("4.0.0-beta.10");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addParticleUpdater("gradient", async (container) => {
|
|
5
5
|
const { GradientUpdater } = await import("./GradientUpdater.js");
|
|
6
|
-
return new GradientUpdater(e);
|
|
6
|
+
return new GradientUpdater(e.pluginManager, container);
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|
package/cjs/GradientUpdater.js
CHANGED
|
@@ -2,16 +2,18 @@ import { AnimationStatus, GradientType, RotateDirection, StartValueType, doubleP
|
|
|
2
2
|
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
3
|
import { updateGradient } from "./Utils.js";
|
|
4
4
|
export class GradientUpdater {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
_container;
|
|
6
|
+
_pluginManager;
|
|
7
|
+
constructor(pluginManager, container) {
|
|
8
|
+
this._pluginManager = pluginManager;
|
|
9
|
+
this._container = container;
|
|
8
10
|
}
|
|
9
11
|
getColorStyles(particle, context, radius, opacity) {
|
|
10
12
|
const gradient = particle.gradient;
|
|
11
13
|
if (!gradient) {
|
|
12
14
|
return {};
|
|
13
15
|
}
|
|
14
|
-
const { container } =
|
|
16
|
+
const { _container: container } = this, gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === GradientType.radial
|
|
15
17
|
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
16
18
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
17
19
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
@@ -29,12 +31,12 @@ export class GradientUpdater {
|
|
|
29
31
|
if (!gradient) {
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
|
-
const { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
34
|
+
const container = this._container, { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
33
35
|
particle.gradient = {
|
|
34
36
|
angle: {
|
|
35
37
|
value: getRangeValue(angle.value),
|
|
36
38
|
enable: angle.animation.enable,
|
|
37
|
-
velocity: (getRangeValue(angle.animation.speed) / speedFactor) *
|
|
39
|
+
velocity: (getRangeValue(angle.animation.speed) / speedFactor) * container.retina.reduceFactor,
|
|
38
40
|
decay: delayOffset - getRangeValue(angle.animation.decay),
|
|
39
41
|
delayTime: getRangeValue(angle.animation.delay) * millisecondsToSeconds,
|
|
40
42
|
max: doublePI,
|
|
@@ -61,11 +63,11 @@ export class GradientUpdater {
|
|
|
61
63
|
}
|
|
62
64
|
const reduceDuplicates = particle.options.reduceDuplicates;
|
|
63
65
|
for (const grColor of gradient.colors) {
|
|
64
|
-
const grHslColor = rangeColorToHsl(this.
|
|
66
|
+
const grHslColor = rangeColorToHsl(this._pluginManager, grColor.value, particle.id, reduceDuplicates);
|
|
65
67
|
if (!grHslColor) {
|
|
66
68
|
continue;
|
|
67
69
|
}
|
|
68
|
-
const grHslAnimation = getHslAnimationFromHsl(grHslColor, grColor.value.animation,
|
|
70
|
+
const grHslAnimation = getHslAnimationFromHsl(grHslColor, grColor.value.animation, container.retina.reduceFactor), addColor = {
|
|
69
71
|
stop: grColor.stop,
|
|
70
72
|
value: grHslAnimation,
|
|
71
73
|
opacity: grColor.opacity
|
|
@@ -75,8 +77,7 @@ export class GradientUpdater {
|
|
|
75
77
|
min: getRangeMin(grColor.opacity.value),
|
|
76
78
|
status: AnimationStatus.increasing,
|
|
77
79
|
value: getRangeValue(grColor.opacity.value),
|
|
78
|
-
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) *
|
|
79
|
-
particle.container.retina.reduceFactor,
|
|
80
|
+
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) * container.retina.reduceFactor,
|
|
80
81
|
decay: delayOffset - getRangeValue(grColor.opacity.animation.decay),
|
|
81
82
|
delayTime: getRangeValue(grColor.opacity.animation.delay) * millisecondsToSeconds,
|
|
82
83
|
time: 0,
|
package/cjs/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export async function loadGradientUpdater(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-beta.
|
|
3
|
-
await engine.register(e => {
|
|
4
|
-
e.addParticleUpdater("gradient", async () => {
|
|
2
|
+
engine.checkVersion("4.0.0-beta.10");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addParticleUpdater("gradient", async (container) => {
|
|
5
5
|
const { GradientUpdater } = await import("./GradientUpdater.js");
|
|
6
|
-
return new GradientUpdater(e);
|
|
6
|
+
return new GradientUpdater(e.pluginManager, container);
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|
|
@@ -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
|
-
* v4.0.0-beta.
|
|
7
|
+
* v4.0.0-beta.10
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
\*****************************************/
|
|
24
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
25
|
|
|
26
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ GradientUpdater: () => (/* binding */ GradientUpdater)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_AnimatableGradient_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/AnimatableGradient.js */ \"./dist/browser/Options/Classes/AnimatableGradient.js\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\n\nclass GradientUpdater {\n
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ GradientUpdater: () => (/* binding */ GradientUpdater)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_AnimatableGradient_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/AnimatableGradient.js */ \"./dist/browser/Options/Classes/AnimatableGradient.js\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\n\nclass GradientUpdater {\n _container;\n _pluginManager;\n constructor(pluginManager, container){\n this._pluginManager = pluginManager;\n this._container = container;\n }\n getColorStyles(particle, context, radius, opacity) {\n const gradient = particle.gradient;\n if (!gradient) {\n return {};\n }\n const { _container: container } = this, gradientAngle = gradient.angle.value, origin = {\n x: 0,\n y: 0\n }, minRadius = 0, fillGradient = gradient.type === _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.GradientType.radial ? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius) : context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);\n for (const { stop, value, opacity: cOpacity } of gradient.colors){\n const hsl = {\n h: value.h.value,\n s: value.s.value,\n l: value.l.value\n };\n fillGradient.addColorStop(stop, (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromHsl)(hsl, container.hdr, cOpacity?.value ?? opacity));\n }\n return {\n fill: fillGradient\n };\n }\n init(particle) {\n const gradient = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(particle.options.gradient);\n if (!gradient) {\n return;\n }\n const container = this._container, { angle } = gradient, speedFactor = 360, delayOffset = 1;\n particle.gradient = {\n angle: {\n value: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(angle.value),\n enable: angle.animation.enable,\n velocity: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(angle.animation.speed) / speedFactor * container.retina.reduceFactor,\n decay: delayOffset - (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(angle.animation.decay),\n delayTime: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(angle.animation.delay) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds,\n max: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.doublePI,\n min: 0,\n time: 0\n },\n type: gradient.type,\n colors: []\n };\n let rotateDirection = gradient.angle.direction;\n if (rotateDirection === _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.RotateDirection.random) {\n rotateDirection = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() > _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half ? _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.RotateDirection.counterClockwise : _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.RotateDirection.clockwise;\n }\n switch(rotateDirection){\n case _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.RotateDirection.counterClockwise:\n case \"counterClockwise\":\n particle.gradient.angle.status = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimationStatus.decreasing;\n break;\n case _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.RotateDirection.clockwise:\n particle.gradient.angle.status = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimationStatus.increasing;\n break;\n default:\n break;\n }\n const reduceDuplicates = particle.options.reduceDuplicates;\n for (const grColor of gradient.colors){\n const grHslColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(this._pluginManager, grColor.value, particle.id, reduceDuplicates);\n if (!grHslColor) {\n continue;\n }\n const grHslAnimation = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getHslAnimationFromHsl)(grHslColor, grColor.value.animation, container.retina.reduceFactor), addColor = {\n stop: grColor.stop,\n value: grHslAnimation,\n opacity: grColor.opacity ? {\n enable: grColor.opacity.animation.enable,\n max: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(grColor.opacity.value),\n min: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMin)(grColor.opacity.value),\n status: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimationStatus.increasing,\n value: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(grColor.opacity.value),\n velocity: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(grColor.opacity.animation.speed) / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.percentDenominator * container.retina.reduceFactor,\n decay: delayOffset - (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(grColor.opacity.animation.decay),\n delayTime: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(grColor.opacity.animation.delay) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds,\n time: 0\n } : undefined\n }, { opacity: addOpacity } = addColor;\n if (grColor.opacity && addOpacity) {\n const opacityRange = grColor.opacity.value;\n addOpacity.min = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMin)(opacityRange);\n addOpacity.max = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(opacityRange);\n const opacityAnimation = grColor.opacity.animation;\n switch(opacityAnimation.startValue){\n case _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.StartValueType.min:\n addOpacity.value = addOpacity.min;\n addOpacity.status = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimationStatus.increasing;\n break;\n case _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.StartValueType.max:\n addOpacity.value = addOpacity.max;\n addOpacity.status = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimationStatus.decreasing;\n break;\n case _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.StartValueType.random:\n default:\n addOpacity.value = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.randomInRangeValue)(addOpacity);\n addOpacity.status = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() >= _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half ? _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimationStatus.increasing : _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimationStatus.decreasing;\n break;\n }\n }\n particle.gradient.colors.push(addColor);\n }\n }\n isEnabled(particle) {\n 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));\n }\n loadOptions(options, ...sources) {\n for (const source of sources){\n if (!source?.gradient) {\n continue;\n }\n const gradientToLoad = source.gradient;\n options.gradient = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(gradientToLoad, (gradient)=>{\n const tmp = new _Options_Classes_AnimatableGradient_js__WEBPACK_IMPORTED_MODULE_1__.AnimatableGradient();\n tmp.load(gradient);\n return tmp;\n });\n }\n }\n update(particle, delta) {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_2__.updateGradient)(particle, delta);\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/updater-gradient/./dist/browser/GradientUpdater.js?\n}");
|
|
27
27
|
|
|
28
28
|
/***/ },
|
|
29
29
|
|
package/esm/GradientUpdater.js
CHANGED
|
@@ -2,16 +2,18 @@ import { AnimationStatus, GradientType, RotateDirection, StartValueType, doubleP
|
|
|
2
2
|
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
3
|
import { updateGradient } from "./Utils.js";
|
|
4
4
|
export class GradientUpdater {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
_container;
|
|
6
|
+
_pluginManager;
|
|
7
|
+
constructor(pluginManager, container) {
|
|
8
|
+
this._pluginManager = pluginManager;
|
|
9
|
+
this._container = container;
|
|
8
10
|
}
|
|
9
11
|
getColorStyles(particle, context, radius, opacity) {
|
|
10
12
|
const gradient = particle.gradient;
|
|
11
13
|
if (!gradient) {
|
|
12
14
|
return {};
|
|
13
15
|
}
|
|
14
|
-
const { container } =
|
|
16
|
+
const { _container: container } = this, gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === GradientType.radial
|
|
15
17
|
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
16
18
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
17
19
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
@@ -29,12 +31,12 @@ export class GradientUpdater {
|
|
|
29
31
|
if (!gradient) {
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
|
-
const { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
34
|
+
const container = this._container, { angle } = gradient, speedFactor = 360, delayOffset = 1;
|
|
33
35
|
particle.gradient = {
|
|
34
36
|
angle: {
|
|
35
37
|
value: getRangeValue(angle.value),
|
|
36
38
|
enable: angle.animation.enable,
|
|
37
|
-
velocity: (getRangeValue(angle.animation.speed) / speedFactor) *
|
|
39
|
+
velocity: (getRangeValue(angle.animation.speed) / speedFactor) * container.retina.reduceFactor,
|
|
38
40
|
decay: delayOffset - getRangeValue(angle.animation.decay),
|
|
39
41
|
delayTime: getRangeValue(angle.animation.delay) * millisecondsToSeconds,
|
|
40
42
|
max: doublePI,
|
|
@@ -61,11 +63,11 @@ export class GradientUpdater {
|
|
|
61
63
|
}
|
|
62
64
|
const reduceDuplicates = particle.options.reduceDuplicates;
|
|
63
65
|
for (const grColor of gradient.colors) {
|
|
64
|
-
const grHslColor = rangeColorToHsl(this.
|
|
66
|
+
const grHslColor = rangeColorToHsl(this._pluginManager, grColor.value, particle.id, reduceDuplicates);
|
|
65
67
|
if (!grHslColor) {
|
|
66
68
|
continue;
|
|
67
69
|
}
|
|
68
|
-
const grHslAnimation = getHslAnimationFromHsl(grHslColor, grColor.value.animation,
|
|
70
|
+
const grHslAnimation = getHslAnimationFromHsl(grHslColor, grColor.value.animation, container.retina.reduceFactor), addColor = {
|
|
69
71
|
stop: grColor.stop,
|
|
70
72
|
value: grHslAnimation,
|
|
71
73
|
opacity: grColor.opacity
|
|
@@ -75,8 +77,7 @@ export class GradientUpdater {
|
|
|
75
77
|
min: getRangeMin(grColor.opacity.value),
|
|
76
78
|
status: AnimationStatus.increasing,
|
|
77
79
|
value: getRangeValue(grColor.opacity.value),
|
|
78
|
-
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) *
|
|
79
|
-
particle.container.retina.reduceFactor,
|
|
80
|
+
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) * container.retina.reduceFactor,
|
|
80
81
|
decay: delayOffset - getRangeValue(grColor.opacity.animation.decay),
|
|
81
82
|
delayTime: getRangeValue(grColor.opacity.animation.delay) * millisecondsToSeconds,
|
|
82
83
|
time: 0,
|
package/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export async function loadGradientUpdater(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-beta.
|
|
3
|
-
await engine.register(e => {
|
|
4
|
-
e.addParticleUpdater("gradient", async () => {
|
|
2
|
+
engine.checkVersion("4.0.0-beta.10");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addParticleUpdater("gradient", async (container) => {
|
|
5
5
|
const { GradientUpdater } = await import("./GradientUpdater.js");
|
|
6
|
-
return new GradientUpdater(e);
|
|
6
|
+
return new GradientUpdater(e.pluginManager, container);
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/updater-gradient",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.10",
|
|
4
4
|
"description": "tsParticles particles gradient updater",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -95,13 +95,12 @@
|
|
|
95
95
|
"browser": "./browser/index.js",
|
|
96
96
|
"import": "./esm/index.js",
|
|
97
97
|
"require": "./cjs/index.js",
|
|
98
|
-
"
|
|
99
|
-
"default": "./cjs/index.js"
|
|
98
|
+
"default": "./esm/index.js"
|
|
100
99
|
},
|
|
101
100
|
"./package.json": "./package.json"
|
|
102
101
|
},
|
|
103
|
-
"
|
|
104
|
-
"@tsparticles/engine": "4.0.0-beta.
|
|
102
|
+
"peerDependencies": {
|
|
103
|
+
"@tsparticles/engine": "4.0.0-beta.10"
|
|
105
104
|
},
|
|
106
105
|
"publishConfig": {
|
|
107
106
|
"access": "public"
|