@tsparticles/updater-gradient 3.2.2 → 3.4.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/browser/GradientUpdater.js +20 -21
- package/browser/Options/Classes/AnimatableGradient.js +3 -2
- package/browser/Options/Classes/GradientAngle.js +2 -2
- package/browser/Options/Classes/GradientColorOpacityAnimation.js +2 -2
- package/browser/Utils.js +3 -3
- package/browser/index.js +3 -3
- package/cjs/GradientUpdater.js +20 -44
- package/cjs/Options/Classes/AnimatableGradient.js +3 -2
- package/cjs/Options/Classes/GradientAngle.js +1 -1
- package/cjs/Options/Classes/GradientColorOpacityAnimation.js +1 -1
- package/cjs/Utils.js +2 -2
- package/cjs/index.js +3 -26
- package/esm/GradientUpdater.js +20 -21
- package/esm/Options/Classes/AnimatableGradient.js +3 -2
- package/esm/Options/Classes/GradientAngle.js +2 -2
- package/esm/Options/Classes/GradientColorOpacityAnimation.js +2 -2
- package/esm/Utils.js +3 -3
- package/esm/index.js +3 -3
- package/package.json +2 -2
- package/report.html +1 -1
- package/tsparticles.updater.gradient.js +82 -200
- package/tsparticles.updater.gradient.min.js +1 -1
- package/tsparticles.updater.gradient.min.js.LICENSE.txt +1 -1
- package/types/GradientUpdater.d.ts +2 -2
- package/umd/GradientUpdater.js +21 -46
- package/umd/Options/Classes/AnimatableGradient.js +4 -3
- package/umd/Options/Classes/GradientAngle.js +1 -1
- package/umd/Options/Classes/GradientColorOpacityAnimation.js +1 -1
- package/umd/Utils.js +2 -2
- package/umd/index.js +4 -28
- package/103.min.js +0 -2
- package/103.min.js.LICENSE.txt +0 -1
- package/914.min.js +0 -2
- package/914.min.js.LICENSE.txt +0 -1
- package/dist_browser_GradientUpdater_js.js +0 -90
- package/dist_browser_Utils_js.js +0 -30
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, halfRandom, itemFromSingleOrMultiple, millisecondsToSeconds, percentDenominator, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
1
|
+
import { AnimationStatus, GradientType, RotateDirection, StartValueType, executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, halfRandom, itemFromSingleOrMultiple, millisecondsToSeconds, percentDenominator, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
2
|
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
|
+
import { updateGradient } from "./Utils.js";
|
|
3
4
|
const double = 2, doublePI = Math.PI * double;
|
|
4
5
|
export class GradientUpdater {
|
|
5
6
|
getColorStyles(particle, context, radius, opacity) {
|
|
@@ -7,7 +8,7 @@ export class GradientUpdater {
|
|
|
7
8
|
if (!gradient) {
|
|
8
9
|
return {};
|
|
9
10
|
}
|
|
10
|
-
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type ===
|
|
11
|
+
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === GradientType.radial
|
|
11
12
|
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
12
13
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
13
14
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
@@ -19,7 +20,7 @@ export class GradientUpdater {
|
|
|
19
20
|
}
|
|
20
21
|
return { fill: fillGradient };
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
init(particle) {
|
|
23
24
|
const gradient = itemFromSingleOrMultiple(particle.options.gradient);
|
|
24
25
|
if (!gradient) {
|
|
25
26
|
return;
|
|
@@ -40,16 +41,16 @@ export class GradientUpdater {
|
|
|
40
41
|
colors: [],
|
|
41
42
|
};
|
|
42
43
|
let rotateDirection = gradient.angle.direction;
|
|
43
|
-
if (rotateDirection ===
|
|
44
|
-
rotateDirection = getRandom() > halfRandom ?
|
|
44
|
+
if (rotateDirection === RotateDirection.random) {
|
|
45
|
+
rotateDirection = getRandom() > halfRandom ? RotateDirection.counterClockwise : RotateDirection.clockwise;
|
|
45
46
|
}
|
|
46
47
|
switch (rotateDirection) {
|
|
47
|
-
case
|
|
48
|
+
case RotateDirection.counterClockwise:
|
|
48
49
|
case "counterClockwise":
|
|
49
|
-
particle.gradient.angle.status =
|
|
50
|
+
particle.gradient.angle.status = AnimationStatus.decreasing;
|
|
50
51
|
break;
|
|
51
|
-
case
|
|
52
|
-
particle.gradient.angle.status =
|
|
52
|
+
case RotateDirection.clockwise:
|
|
53
|
+
particle.gradient.angle.status = AnimationStatus.increasing;
|
|
53
54
|
break;
|
|
54
55
|
}
|
|
55
56
|
const reduceDuplicates = particle.options.reduceDuplicates;
|
|
@@ -66,7 +67,7 @@ export class GradientUpdater {
|
|
|
66
67
|
enable: grColor.opacity.animation.enable,
|
|
67
68
|
max: getRangeMax(grColor.opacity.value),
|
|
68
69
|
min: getRangeMin(grColor.opacity.value),
|
|
69
|
-
status:
|
|
70
|
+
status: AnimationStatus.increasing,
|
|
70
71
|
value: getRangeValue(grColor.opacity.value),
|
|
71
72
|
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) *
|
|
72
73
|
particle.container.retina.reduceFactor,
|
|
@@ -83,31 +84,30 @@ export class GradientUpdater {
|
|
|
83
84
|
addOpacity.max = getRangeMax(opacityRange);
|
|
84
85
|
const opacityAnimation = grColor.opacity.animation;
|
|
85
86
|
switch (opacityAnimation.startValue) {
|
|
86
|
-
case
|
|
87
|
+
case StartValueType.min:
|
|
87
88
|
addOpacity.value = addOpacity.min;
|
|
88
|
-
addOpacity.status =
|
|
89
|
+
addOpacity.status = AnimationStatus.increasing;
|
|
89
90
|
break;
|
|
90
|
-
case
|
|
91
|
+
case StartValueType.max:
|
|
91
92
|
addOpacity.value = addOpacity.max;
|
|
92
|
-
addOpacity.status =
|
|
93
|
+
addOpacity.status = AnimationStatus.decreasing;
|
|
93
94
|
break;
|
|
94
|
-
case
|
|
95
|
+
case StartValueType.random:
|
|
95
96
|
default:
|
|
96
97
|
addOpacity.value = randomInRange(addOpacity);
|
|
97
98
|
addOpacity.status =
|
|
98
|
-
getRandom() >= halfRandom ?
|
|
99
|
+
getRandom() >= halfRandom ? AnimationStatus.increasing : AnimationStatus.decreasing;
|
|
99
100
|
break;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
particle.gradient.colors.push(addColor);
|
|
103
104
|
}
|
|
104
|
-
await Promise.resolve();
|
|
105
105
|
}
|
|
106
106
|
isEnabled(particle) {
|
|
107
107
|
return (!particle.destroyed &&
|
|
108
108
|
!particle.spawning &&
|
|
109
109
|
(!!particle.gradient?.angle.enable ||
|
|
110
|
-
(particle.gradient?.colors.some(
|
|
110
|
+
(particle.gradient?.colors.some(c => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
111
111
|
false)));
|
|
112
112
|
}
|
|
113
113
|
loadOptions(options, ...sources) {
|
|
@@ -119,15 +119,14 @@ export class GradientUpdater {
|
|
|
119
119
|
if (!gradientToLoad) {
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
122
|
-
options.gradient = executeOnSingleOrMultiple(gradientToLoad,
|
|
122
|
+
options.gradient = executeOnSingleOrMultiple(gradientToLoad, gradient => {
|
|
123
123
|
const tmp = new AnimatableGradient();
|
|
124
124
|
tmp.load(gradient);
|
|
125
125
|
return tmp;
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
const { updateGradient } = await import("./Utils.js");
|
|
129
|
+
update(particle, delta) {
|
|
131
130
|
updateGradient(particle, delta);
|
|
132
131
|
}
|
|
133
132
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { GradientType } from "@tsparticles/engine";
|
|
1
2
|
import { AnimatableGradientColor } from "./AnimatableGradientColor.js";
|
|
2
3
|
import { GradientAngle } from "./GradientAngle.js";
|
|
3
4
|
export class AnimatableGradient {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.angle = new GradientAngle();
|
|
6
7
|
this.colors = [];
|
|
7
|
-
this.type =
|
|
8
|
+
this.type = GradientType.random;
|
|
8
9
|
}
|
|
9
10
|
load(data) {
|
|
10
11
|
if (!data) {
|
|
@@ -12,7 +13,7 @@ export class AnimatableGradient {
|
|
|
12
13
|
}
|
|
13
14
|
this.angle.load(data.angle);
|
|
14
15
|
if (data.colors !== undefined) {
|
|
15
|
-
this.colors = data.colors.map(
|
|
16
|
+
this.colors = data.colors.map(s => {
|
|
16
17
|
const tmp = new AnimatableGradientColor();
|
|
17
18
|
tmp.load(s);
|
|
18
19
|
return tmp;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { setRangeValue, } from "@tsparticles/engine";
|
|
1
|
+
import { RotateDirection, setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
import { GradientAngleAnimation } from "./GradientAngleAnimation.js";
|
|
3
3
|
export class GradientAngle {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.value = 0;
|
|
6
6
|
this.animation = new GradientAngleAnimation();
|
|
7
|
-
this.direction =
|
|
7
|
+
this.direction = RotateDirection.clockwise;
|
|
8
8
|
}
|
|
9
9
|
load(data) {
|
|
10
10
|
if (!data) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setRangeValue, } from "@tsparticles/engine";
|
|
1
|
+
import { StartValueType, setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
export class GradientColorOpacityAnimation {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.count = 0;
|
|
@@ -7,7 +7,7 @@ export class GradientColorOpacityAnimation {
|
|
|
7
7
|
this.decay = 0;
|
|
8
8
|
this.delay = 0;
|
|
9
9
|
this.sync = false;
|
|
10
|
-
this.startValue =
|
|
10
|
+
this.startValue = StartValueType.random;
|
|
11
11
|
}
|
|
12
12
|
load(data) {
|
|
13
13
|
if (!data) {
|
package/browser/Utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { updateAnimation, updateColor } from "@tsparticles/engine";
|
|
1
|
+
import { DestroyType, updateAnimation, updateColor } from "@tsparticles/engine";
|
|
2
2
|
export function updateGradient(particle, delta) {
|
|
3
3
|
const { gradient } = particle;
|
|
4
4
|
if (!gradient) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
-
updateAnimation(particle, gradient.angle, false,
|
|
7
|
+
updateAnimation(particle, gradient.angle, false, DestroyType.none, delta);
|
|
8
8
|
for (const color of gradient.colors) {
|
|
9
9
|
updateColor(color.value, delta);
|
|
10
10
|
if (color.opacity) {
|
|
11
|
-
updateAnimation(particle, color.opacity, true,
|
|
11
|
+
updateAnimation(particle, color.opacity, true, DestroyType.none, delta);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { GradientUpdater } from "./GradientUpdater.js";
|
|
1
2
|
export async function loadGradientUpdater(engine, refresh = true) {
|
|
2
|
-
await engine.addParticleUpdater("gradient",
|
|
3
|
-
|
|
4
|
-
return new GradientUpdater();
|
|
3
|
+
await engine.addParticleUpdater("gradient", () => {
|
|
4
|
+
return Promise.resolve(new GradientUpdater());
|
|
5
5
|
}, refresh);
|
|
6
6
|
}
|
package/cjs/GradientUpdater.js
CHANGED
|
@@ -1,31 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.GradientUpdater = void 0;
|
|
27
4
|
const engine_1 = require("@tsparticles/engine");
|
|
28
5
|
const AnimatableGradient_js_1 = require("./Options/Classes/AnimatableGradient.js");
|
|
6
|
+
const Utils_js_1 = require("./Utils.js");
|
|
29
7
|
const double = 2, doublePI = Math.PI * double;
|
|
30
8
|
class GradientUpdater {
|
|
31
9
|
getColorStyles(particle, context, radius, opacity) {
|
|
@@ -33,7 +11,7 @@ class GradientUpdater {
|
|
|
33
11
|
if (!gradient) {
|
|
34
12
|
return {};
|
|
35
13
|
}
|
|
36
|
-
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type ===
|
|
14
|
+
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === engine_1.GradientType.radial
|
|
37
15
|
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
38
16
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
39
17
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
@@ -45,7 +23,7 @@ class GradientUpdater {
|
|
|
45
23
|
}
|
|
46
24
|
return { fill: fillGradient };
|
|
47
25
|
}
|
|
48
|
-
|
|
26
|
+
init(particle) {
|
|
49
27
|
const gradient = (0, engine_1.itemFromSingleOrMultiple)(particle.options.gradient);
|
|
50
28
|
if (!gradient) {
|
|
51
29
|
return;
|
|
@@ -66,16 +44,16 @@ class GradientUpdater {
|
|
|
66
44
|
colors: [],
|
|
67
45
|
};
|
|
68
46
|
let rotateDirection = gradient.angle.direction;
|
|
69
|
-
if (rotateDirection ===
|
|
70
|
-
rotateDirection = (0, engine_1.getRandom)() > engine_1.halfRandom ?
|
|
47
|
+
if (rotateDirection === engine_1.RotateDirection.random) {
|
|
48
|
+
rotateDirection = (0, engine_1.getRandom)() > engine_1.halfRandom ? engine_1.RotateDirection.counterClockwise : engine_1.RotateDirection.clockwise;
|
|
71
49
|
}
|
|
72
50
|
switch (rotateDirection) {
|
|
73
|
-
case
|
|
51
|
+
case engine_1.RotateDirection.counterClockwise:
|
|
74
52
|
case "counterClockwise":
|
|
75
|
-
particle.gradient.angle.status =
|
|
53
|
+
particle.gradient.angle.status = engine_1.AnimationStatus.decreasing;
|
|
76
54
|
break;
|
|
77
|
-
case
|
|
78
|
-
particle.gradient.angle.status =
|
|
55
|
+
case engine_1.RotateDirection.clockwise:
|
|
56
|
+
particle.gradient.angle.status = engine_1.AnimationStatus.increasing;
|
|
79
57
|
break;
|
|
80
58
|
}
|
|
81
59
|
const reduceDuplicates = particle.options.reduceDuplicates;
|
|
@@ -92,7 +70,7 @@ class GradientUpdater {
|
|
|
92
70
|
enable: grColor.opacity.animation.enable,
|
|
93
71
|
max: (0, engine_1.getRangeMax)(grColor.opacity.value),
|
|
94
72
|
min: (0, engine_1.getRangeMin)(grColor.opacity.value),
|
|
95
|
-
status:
|
|
73
|
+
status: engine_1.AnimationStatus.increasing,
|
|
96
74
|
value: (0, engine_1.getRangeValue)(grColor.opacity.value),
|
|
97
75
|
velocity: ((0, engine_1.getRangeValue)(grColor.opacity.animation.speed) / engine_1.percentDenominator) *
|
|
98
76
|
particle.container.retina.reduceFactor,
|
|
@@ -109,31 +87,30 @@ class GradientUpdater {
|
|
|
109
87
|
addOpacity.max = (0, engine_1.getRangeMax)(opacityRange);
|
|
110
88
|
const opacityAnimation = grColor.opacity.animation;
|
|
111
89
|
switch (opacityAnimation.startValue) {
|
|
112
|
-
case
|
|
90
|
+
case engine_1.StartValueType.min:
|
|
113
91
|
addOpacity.value = addOpacity.min;
|
|
114
|
-
addOpacity.status =
|
|
92
|
+
addOpacity.status = engine_1.AnimationStatus.increasing;
|
|
115
93
|
break;
|
|
116
|
-
case
|
|
94
|
+
case engine_1.StartValueType.max:
|
|
117
95
|
addOpacity.value = addOpacity.max;
|
|
118
|
-
addOpacity.status =
|
|
96
|
+
addOpacity.status = engine_1.AnimationStatus.decreasing;
|
|
119
97
|
break;
|
|
120
|
-
case
|
|
98
|
+
case engine_1.StartValueType.random:
|
|
121
99
|
default:
|
|
122
100
|
addOpacity.value = (0, engine_1.randomInRange)(addOpacity);
|
|
123
101
|
addOpacity.status =
|
|
124
|
-
(0, engine_1.getRandom)() >= engine_1.halfRandom ?
|
|
102
|
+
(0, engine_1.getRandom)() >= engine_1.halfRandom ? engine_1.AnimationStatus.increasing : engine_1.AnimationStatus.decreasing;
|
|
125
103
|
break;
|
|
126
104
|
}
|
|
127
105
|
}
|
|
128
106
|
particle.gradient.colors.push(addColor);
|
|
129
107
|
}
|
|
130
|
-
await Promise.resolve();
|
|
131
108
|
}
|
|
132
109
|
isEnabled(particle) {
|
|
133
110
|
return (!particle.destroyed &&
|
|
134
111
|
!particle.spawning &&
|
|
135
112
|
(!!particle.gradient?.angle.enable ||
|
|
136
|
-
(particle.gradient?.colors.some(
|
|
113
|
+
(particle.gradient?.colors.some(c => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
137
114
|
false)));
|
|
138
115
|
}
|
|
139
116
|
loadOptions(options, ...sources) {
|
|
@@ -145,16 +122,15 @@ class GradientUpdater {
|
|
|
145
122
|
if (!gradientToLoad) {
|
|
146
123
|
continue;
|
|
147
124
|
}
|
|
148
|
-
options.gradient = (0, engine_1.executeOnSingleOrMultiple)(gradientToLoad,
|
|
125
|
+
options.gradient = (0, engine_1.executeOnSingleOrMultiple)(gradientToLoad, gradient => {
|
|
149
126
|
const tmp = new AnimatableGradient_js_1.AnimatableGradient();
|
|
150
127
|
tmp.load(gradient);
|
|
151
128
|
return tmp;
|
|
152
129
|
});
|
|
153
130
|
}
|
|
154
131
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
updateGradient(particle, delta);
|
|
132
|
+
update(particle, delta) {
|
|
133
|
+
(0, Utils_js_1.updateGradient)(particle, delta);
|
|
158
134
|
}
|
|
159
135
|
}
|
|
160
136
|
exports.GradientUpdater = GradientUpdater;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AnimatableGradient = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
4
5
|
const AnimatableGradientColor_js_1 = require("./AnimatableGradientColor.js");
|
|
5
6
|
const GradientAngle_js_1 = require("./GradientAngle.js");
|
|
6
7
|
class AnimatableGradient {
|
|
7
8
|
constructor() {
|
|
8
9
|
this.angle = new GradientAngle_js_1.GradientAngle();
|
|
9
10
|
this.colors = [];
|
|
10
|
-
this.type =
|
|
11
|
+
this.type = engine_1.GradientType.random;
|
|
11
12
|
}
|
|
12
13
|
load(data) {
|
|
13
14
|
if (!data) {
|
|
@@ -15,7 +16,7 @@ class AnimatableGradient {
|
|
|
15
16
|
}
|
|
16
17
|
this.angle.load(data.angle);
|
|
17
18
|
if (data.colors !== undefined) {
|
|
18
|
-
this.colors = data.colors.map(
|
|
19
|
+
this.colors = data.colors.map(s => {
|
|
19
20
|
const tmp = new AnimatableGradientColor_js_1.AnimatableGradientColor();
|
|
20
21
|
tmp.load(s);
|
|
21
22
|
return tmp;
|
package/cjs/Utils.js
CHANGED
|
@@ -7,11 +7,11 @@ function updateGradient(particle, delta) {
|
|
|
7
7
|
if (!gradient) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
|
-
(0, engine_1.updateAnimation)(particle, gradient.angle, false,
|
|
10
|
+
(0, engine_1.updateAnimation)(particle, gradient.angle, false, engine_1.DestroyType.none, delta);
|
|
11
11
|
for (const color of gradient.colors) {
|
|
12
12
|
(0, engine_1.updateColor)(color.value, delta);
|
|
13
13
|
if (color.opacity) {
|
|
14
|
-
(0, engine_1.updateAnimation)(particle, color.opacity, true,
|
|
14
|
+
(0, engine_1.updateAnimation)(particle, color.opacity, true, engine_1.DestroyType.none, delta);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.loadGradientUpdater = void 0;
|
|
4
|
+
const GradientUpdater_js_1 = require("./GradientUpdater.js");
|
|
27
5
|
async function loadGradientUpdater(engine, refresh = true) {
|
|
28
|
-
await engine.addParticleUpdater("gradient",
|
|
29
|
-
|
|
30
|
-
return new GradientUpdater();
|
|
6
|
+
await engine.addParticleUpdater("gradient", () => {
|
|
7
|
+
return Promise.resolve(new GradientUpdater_js_1.GradientUpdater());
|
|
31
8
|
}, refresh);
|
|
32
9
|
}
|
|
33
10
|
exports.loadGradientUpdater = loadGradientUpdater;
|
package/esm/GradientUpdater.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, halfRandom, itemFromSingleOrMultiple, millisecondsToSeconds, percentDenominator, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
1
|
+
import { AnimationStatus, GradientType, RotateDirection, StartValueType, executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, halfRandom, itemFromSingleOrMultiple, millisecondsToSeconds, percentDenominator, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
2
|
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
|
+
import { updateGradient } from "./Utils.js";
|
|
3
4
|
const double = 2, doublePI = Math.PI * double;
|
|
4
5
|
export class GradientUpdater {
|
|
5
6
|
getColorStyles(particle, context, radius, opacity) {
|
|
@@ -7,7 +8,7 @@ export class GradientUpdater {
|
|
|
7
8
|
if (!gradient) {
|
|
8
9
|
return {};
|
|
9
10
|
}
|
|
10
|
-
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type ===
|
|
11
|
+
const gradientAngle = gradient.angle.value, origin = { x: 0, y: 0 }, minRadius = 0, fillGradient = gradient.type === GradientType.radial
|
|
11
12
|
? context.createRadialGradient(origin.x, origin.y, minRadius, origin.x, origin.y, radius)
|
|
12
13
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
13
14
|
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
@@ -19,7 +20,7 @@ export class GradientUpdater {
|
|
|
19
20
|
}
|
|
20
21
|
return { fill: fillGradient };
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
init(particle) {
|
|
23
24
|
const gradient = itemFromSingleOrMultiple(particle.options.gradient);
|
|
24
25
|
if (!gradient) {
|
|
25
26
|
return;
|
|
@@ -40,16 +41,16 @@ export class GradientUpdater {
|
|
|
40
41
|
colors: [],
|
|
41
42
|
};
|
|
42
43
|
let rotateDirection = gradient.angle.direction;
|
|
43
|
-
if (rotateDirection ===
|
|
44
|
-
rotateDirection = getRandom() > halfRandom ?
|
|
44
|
+
if (rotateDirection === RotateDirection.random) {
|
|
45
|
+
rotateDirection = getRandom() > halfRandom ? RotateDirection.counterClockwise : RotateDirection.clockwise;
|
|
45
46
|
}
|
|
46
47
|
switch (rotateDirection) {
|
|
47
|
-
case
|
|
48
|
+
case RotateDirection.counterClockwise:
|
|
48
49
|
case "counterClockwise":
|
|
49
|
-
particle.gradient.angle.status =
|
|
50
|
+
particle.gradient.angle.status = AnimationStatus.decreasing;
|
|
50
51
|
break;
|
|
51
|
-
case
|
|
52
|
-
particle.gradient.angle.status =
|
|
52
|
+
case RotateDirection.clockwise:
|
|
53
|
+
particle.gradient.angle.status = AnimationStatus.increasing;
|
|
53
54
|
break;
|
|
54
55
|
}
|
|
55
56
|
const reduceDuplicates = particle.options.reduceDuplicates;
|
|
@@ -66,7 +67,7 @@ export class GradientUpdater {
|
|
|
66
67
|
enable: grColor.opacity.animation.enable,
|
|
67
68
|
max: getRangeMax(grColor.opacity.value),
|
|
68
69
|
min: getRangeMin(grColor.opacity.value),
|
|
69
|
-
status:
|
|
70
|
+
status: AnimationStatus.increasing,
|
|
70
71
|
value: getRangeValue(grColor.opacity.value),
|
|
71
72
|
velocity: (getRangeValue(grColor.opacity.animation.speed) / percentDenominator) *
|
|
72
73
|
particle.container.retina.reduceFactor,
|
|
@@ -83,31 +84,30 @@ export class GradientUpdater {
|
|
|
83
84
|
addOpacity.max = getRangeMax(opacityRange);
|
|
84
85
|
const opacityAnimation = grColor.opacity.animation;
|
|
85
86
|
switch (opacityAnimation.startValue) {
|
|
86
|
-
case
|
|
87
|
+
case StartValueType.min:
|
|
87
88
|
addOpacity.value = addOpacity.min;
|
|
88
|
-
addOpacity.status =
|
|
89
|
+
addOpacity.status = AnimationStatus.increasing;
|
|
89
90
|
break;
|
|
90
|
-
case
|
|
91
|
+
case StartValueType.max:
|
|
91
92
|
addOpacity.value = addOpacity.max;
|
|
92
|
-
addOpacity.status =
|
|
93
|
+
addOpacity.status = AnimationStatus.decreasing;
|
|
93
94
|
break;
|
|
94
|
-
case
|
|
95
|
+
case StartValueType.random:
|
|
95
96
|
default:
|
|
96
97
|
addOpacity.value = randomInRange(addOpacity);
|
|
97
98
|
addOpacity.status =
|
|
98
|
-
getRandom() >= halfRandom ?
|
|
99
|
+
getRandom() >= halfRandom ? AnimationStatus.increasing : AnimationStatus.decreasing;
|
|
99
100
|
break;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
particle.gradient.colors.push(addColor);
|
|
103
104
|
}
|
|
104
|
-
await Promise.resolve();
|
|
105
105
|
}
|
|
106
106
|
isEnabled(particle) {
|
|
107
107
|
return (!particle.destroyed &&
|
|
108
108
|
!particle.spawning &&
|
|
109
109
|
(!!particle.gradient?.angle.enable ||
|
|
110
|
-
(particle.gradient?.colors.some(
|
|
110
|
+
(particle.gradient?.colors.some(c => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
111
111
|
false)));
|
|
112
112
|
}
|
|
113
113
|
loadOptions(options, ...sources) {
|
|
@@ -119,15 +119,14 @@ export class GradientUpdater {
|
|
|
119
119
|
if (!gradientToLoad) {
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
122
|
-
options.gradient = executeOnSingleOrMultiple(gradientToLoad,
|
|
122
|
+
options.gradient = executeOnSingleOrMultiple(gradientToLoad, gradient => {
|
|
123
123
|
const tmp = new AnimatableGradient();
|
|
124
124
|
tmp.load(gradient);
|
|
125
125
|
return tmp;
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
const { updateGradient } = await import("./Utils.js");
|
|
129
|
+
update(particle, delta) {
|
|
131
130
|
updateGradient(particle, delta);
|
|
132
131
|
}
|
|
133
132
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { GradientType } from "@tsparticles/engine";
|
|
1
2
|
import { AnimatableGradientColor } from "./AnimatableGradientColor.js";
|
|
2
3
|
import { GradientAngle } from "./GradientAngle.js";
|
|
3
4
|
export class AnimatableGradient {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.angle = new GradientAngle();
|
|
6
7
|
this.colors = [];
|
|
7
|
-
this.type =
|
|
8
|
+
this.type = GradientType.random;
|
|
8
9
|
}
|
|
9
10
|
load(data) {
|
|
10
11
|
if (!data) {
|
|
@@ -12,7 +13,7 @@ export class AnimatableGradient {
|
|
|
12
13
|
}
|
|
13
14
|
this.angle.load(data.angle);
|
|
14
15
|
if (data.colors !== undefined) {
|
|
15
|
-
this.colors = data.colors.map(
|
|
16
|
+
this.colors = data.colors.map(s => {
|
|
16
17
|
const tmp = new AnimatableGradientColor();
|
|
17
18
|
tmp.load(s);
|
|
18
19
|
return tmp;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { setRangeValue, } from "@tsparticles/engine";
|
|
1
|
+
import { RotateDirection, setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
import { GradientAngleAnimation } from "./GradientAngleAnimation.js";
|
|
3
3
|
export class GradientAngle {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.value = 0;
|
|
6
6
|
this.animation = new GradientAngleAnimation();
|
|
7
|
-
this.direction =
|
|
7
|
+
this.direction = RotateDirection.clockwise;
|
|
8
8
|
}
|
|
9
9
|
load(data) {
|
|
10
10
|
if (!data) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setRangeValue, } from "@tsparticles/engine";
|
|
1
|
+
import { StartValueType, setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
export class GradientColorOpacityAnimation {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.count = 0;
|
|
@@ -7,7 +7,7 @@ export class GradientColorOpacityAnimation {
|
|
|
7
7
|
this.decay = 0;
|
|
8
8
|
this.delay = 0;
|
|
9
9
|
this.sync = false;
|
|
10
|
-
this.startValue =
|
|
10
|
+
this.startValue = StartValueType.random;
|
|
11
11
|
}
|
|
12
12
|
load(data) {
|
|
13
13
|
if (!data) {
|
package/esm/Utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { updateAnimation, updateColor } from "@tsparticles/engine";
|
|
1
|
+
import { DestroyType, updateAnimation, updateColor } from "@tsparticles/engine";
|
|
2
2
|
export function updateGradient(particle, delta) {
|
|
3
3
|
const { gradient } = particle;
|
|
4
4
|
if (!gradient) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
-
updateAnimation(particle, gradient.angle, false,
|
|
7
|
+
updateAnimation(particle, gradient.angle, false, DestroyType.none, delta);
|
|
8
8
|
for (const color of gradient.colors) {
|
|
9
9
|
updateColor(color.value, delta);
|
|
10
10
|
if (color.opacity) {
|
|
11
|
-
updateAnimation(particle, color.opacity, true,
|
|
11
|
+
updateAnimation(particle, color.opacity, true, DestroyType.none, delta);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { GradientUpdater } from "./GradientUpdater.js";
|
|
1
2
|
export async function loadGradientUpdater(engine, refresh = true) {
|
|
2
|
-
await engine.addParticleUpdater("gradient",
|
|
3
|
-
|
|
4
|
-
return new GradientUpdater();
|
|
3
|
+
await engine.addParticleUpdater("gradient", () => {
|
|
4
|
+
return Promise.resolve(new GradientUpdater());
|
|
5
5
|
}, refresh);
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/updater-gradient",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "tsParticles particles gradient updater",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"./package.json": "./package.json"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@tsparticles/engine": "^3.
|
|
104
|
+
"@tsparticles/engine": "^3.4.0"
|
|
105
105
|
},
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"access": "public"
|