@tsparticles/updater-stroke-color 3.0.0-alpha.1 → 3.0.0-beta.1
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/StrokeColorUpdater.js +11 -72
- package/browser/Types.js +1 -0
- package/browser/Utils.js +63 -0
- package/browser/index.js +3 -3
- package/browser/package.json +1 -0
- package/cjs/StrokeColorUpdater.js +11 -72
- package/cjs/Types.js +2 -0
- package/cjs/Utils.js +67 -0
- package/cjs/index.js +3 -14
- package/cjs/package.json +1 -0
- package/esm/StrokeColorUpdater.js +11 -72
- package/esm/Types.js +1 -0
- package/esm/Utils.js +63 -0
- package/esm/index.js +3 -3
- package/esm/package.json +1 -0
- package/package.json +19 -6
- package/report.html +4 -4
- package/tsparticles.updater.stroke-color.js +45 -26
- package/tsparticles.updater.stroke-color.min.js +1 -1
- package/tsparticles.updater.stroke-color.min.js.LICENSE.txt +1 -8
- package/types/StrokeColorUpdater.d.ts +2 -5
- package/types/Types.d.ts +4 -0
- package/types/Utils.d.ts +3 -0
- package/types/index.d.ts +1 -1
- package/umd/StrokeColorUpdater.js +12 -73
- package/umd/Types.js +12 -0
- package/umd/Utils.js +77 -0
- package/umd/index.js +4 -4
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles Stroke Color Updater
|
|
4
4
|
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/updater-stroke-color)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/updater-stroke-color)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/updater-stroke-color) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for stroke color animations.
|
|
10
10
|
|
|
@@ -26,7 +26,7 @@ Once the scripts are loaded you can set up `tsParticles` and the updater plugin
|
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
28
|
(async () => {
|
|
29
|
-
await loadStrokeColorUpdater();
|
|
29
|
+
await loadStrokeColorUpdater(tsParticles);
|
|
30
30
|
|
|
31
31
|
await tsParticles.load({
|
|
32
32
|
id: "tsparticles",
|
|
@@ -42,29 +42,33 @@ Once the scripts are loaded you can set up `tsParticles` and the updater plugin
|
|
|
42
42
|
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
43
|
|
|
44
44
|
```shell
|
|
45
|
-
$ npm install tsparticles
|
|
45
|
+
$ npm install @tsparticles/updater-stroke-color
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
or
|
|
49
49
|
|
|
50
50
|
```shell
|
|
51
|
-
$ yarn add tsparticles
|
|
51
|
+
$ yarn add @tsparticles/updater-stroke-color
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Then you need to import it in the app, like this:
|
|
55
55
|
|
|
56
56
|
```javascript
|
|
57
|
-
const { tsParticles } = require("tsparticles
|
|
58
|
-
const { loadStrokeColorUpdater } = require("tsparticles
|
|
57
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
58
|
+
const { loadStrokeColorUpdater } = require("@tsparticles/updater-stroke-color");
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
(async () => {
|
|
61
|
+
await loadStrokeColorUpdater(tsParticles);
|
|
62
|
+
})();
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
or
|
|
64
66
|
|
|
65
67
|
```javascript
|
|
66
|
-
import { tsParticles } from "tsparticles
|
|
67
|
-
import { loadStrokeColorUpdater } from "tsparticles
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
|
+
import { loadStrokeColorUpdater } from "@tsparticles/updater-stroke-color";
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
(async () => {
|
|
72
|
+
await loadStrokeColorUpdater(tsParticles);
|
|
73
|
+
})();
|
|
70
74
|
```
|
|
@@ -1,89 +1,28 @@
|
|
|
1
|
-
import { getHslAnimationFromHsl, getRangeValue, itemFromSingleOrMultiple,
|
|
2
|
-
|
|
3
|
-
var _a, _b;
|
|
4
|
-
const colorValue = value;
|
|
5
|
-
if (!colorValue ||
|
|
6
|
-
!colorValue.enable ||
|
|
7
|
-
(colorValue.loops !== undefined &&
|
|
8
|
-
colorValue.maxLoops !== undefined &&
|
|
9
|
-
colorValue.maxLoops > 0 &&
|
|
10
|
-
colorValue.loops >= colorValue.maxLoops)) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const offset = randomInRange(valueAnimation.offset), velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor + offset * 3.6, decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
|
|
14
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
15
|
-
colorValue.value += velocity;
|
|
16
|
-
if (colorValue.value > max) {
|
|
17
|
-
if (!colorValue.loops) {
|
|
18
|
-
colorValue.loops = 0;
|
|
19
|
-
}
|
|
20
|
-
colorValue.loops++;
|
|
21
|
-
if (decrease) {
|
|
22
|
-
colorValue.status = "decreasing";
|
|
23
|
-
colorValue.value -= colorValue.value % max;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
colorValue.value -= velocity;
|
|
29
|
-
if (colorValue.value < 0) {
|
|
30
|
-
if (!colorValue.loops) {
|
|
31
|
-
colorValue.loops = 0;
|
|
32
|
-
}
|
|
33
|
-
colorValue.loops++;
|
|
34
|
-
colorValue.status = "increasing";
|
|
35
|
-
colorValue.value += colorValue.value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (colorValue.velocity && decay !== 1) {
|
|
39
|
-
colorValue.velocity *= decay;
|
|
40
|
-
}
|
|
41
|
-
if (colorValue.value > max) {
|
|
42
|
-
colorValue.value %= max;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function updateStrokeColor(particle, delta) {
|
|
46
|
-
if (!particle.strokeColor || !particle.strokeAnimation) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const h = particle.strokeColor.h;
|
|
50
|
-
if (h) {
|
|
51
|
-
updateColorValue(delta, h, particle.strokeAnimation.h, 360, false);
|
|
52
|
-
}
|
|
53
|
-
const s = particle.strokeColor.s;
|
|
54
|
-
if (s) {
|
|
55
|
-
updateColorValue(delta, s, particle.strokeAnimation.s, 100, true);
|
|
56
|
-
}
|
|
57
|
-
const l = particle.strokeColor.l;
|
|
58
|
-
if (l) {
|
|
59
|
-
updateColorValue(delta, l, particle.strokeAnimation.l, 100, true);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
import { getHslAnimationFromHsl, getRangeValue, itemFromSingleOrMultiple, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
|
+
import { updateStrokeColor } from "./Utils.js";
|
|
62
3
|
export class StrokeColorUpdater {
|
|
63
4
|
constructor(container) {
|
|
64
5
|
this.container = container;
|
|
65
6
|
}
|
|
66
7
|
init(particle) {
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const stroke = itemFromSingleOrMultiple(particle.options.stroke, particle.id, particle.options.reduceDuplicates);
|
|
8
|
+
const container = this.container, options = particle.options;
|
|
9
|
+
const stroke = itemFromSingleOrMultiple(options.stroke, particle.id, options.reduceDuplicates);
|
|
70
10
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
71
|
-
particle.strokeOpacity = getRangeValue(
|
|
72
|
-
particle.strokeAnimation =
|
|
73
|
-
const strokeHslColor =
|
|
11
|
+
particle.strokeOpacity = getRangeValue(stroke.opacity ?? 1);
|
|
12
|
+
particle.strokeAnimation = stroke.color?.animation;
|
|
13
|
+
const strokeHslColor = rangeColorToHsl(stroke.color) ?? particle.getFillColor();
|
|
74
14
|
if (strokeHslColor) {
|
|
75
15
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
76
16
|
}
|
|
77
17
|
}
|
|
78
18
|
isEnabled(particle) {
|
|
79
|
-
|
|
80
|
-
const color = particle.strokeAnimation;
|
|
19
|
+
const color = particle.strokeAnimation, { strokeColor } = particle;
|
|
81
20
|
return (!particle.destroyed &&
|
|
82
21
|
!particle.spawning &&
|
|
83
22
|
!!color &&
|
|
84
|
-
((
|
|
85
|
-
(
|
|
86
|
-
(
|
|
23
|
+
((strokeColor?.h.value !== undefined && strokeColor.h.enable) ||
|
|
24
|
+
(strokeColor?.s.value !== undefined && strokeColor.s.enable) ||
|
|
25
|
+
(strokeColor?.l.value !== undefined && strokeColor.l.enable)));
|
|
87
26
|
}
|
|
88
27
|
update(particle, delta) {
|
|
89
28
|
if (!this.isEnabled(particle)) {
|
package/browser/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/Utils.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { randomInRange, } from "@tsparticles/engine";
|
|
2
|
+
function updateColorValue(delta, colorValue, valueAnimation, max, decrease) {
|
|
3
|
+
if (!colorValue ||
|
|
4
|
+
!valueAnimation.enable ||
|
|
5
|
+
((colorValue.maxLoops ?? 0) > 0 && (colorValue.loops ?? 0) > (colorValue.maxLoops ?? 0))) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (!colorValue.time) {
|
|
9
|
+
colorValue.time = 0;
|
|
10
|
+
}
|
|
11
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
12
|
+
colorValue.time += delta.value;
|
|
13
|
+
}
|
|
14
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const offset = randomInRange(valueAnimation.offset), velocity = (colorValue.velocity ?? 0) * delta.factor + offset * 3.6, decay = colorValue.decay ?? 1;
|
|
18
|
+
if (!decrease || colorValue.status === "increasing") {
|
|
19
|
+
colorValue.value += velocity;
|
|
20
|
+
if (colorValue.value > max) {
|
|
21
|
+
if (!colorValue.loops) {
|
|
22
|
+
colorValue.loops = 0;
|
|
23
|
+
}
|
|
24
|
+
colorValue.loops++;
|
|
25
|
+
if (decrease) {
|
|
26
|
+
colorValue.status = "decreasing";
|
|
27
|
+
colorValue.value -= colorValue.value % max;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
colorValue.value -= velocity;
|
|
33
|
+
if (colorValue.value < 0) {
|
|
34
|
+
if (!colorValue.loops) {
|
|
35
|
+
colorValue.loops = 0;
|
|
36
|
+
}
|
|
37
|
+
colorValue.loops++;
|
|
38
|
+
colorValue.status = "increasing";
|
|
39
|
+
colorValue.value += colorValue.value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (colorValue.velocity && decay !== 1) {
|
|
43
|
+
colorValue.velocity *= decay;
|
|
44
|
+
}
|
|
45
|
+
if (colorValue.value > max) {
|
|
46
|
+
colorValue.value %= max;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function updateStrokeColor(particle, delta) {
|
|
50
|
+
if (!particle.strokeColor || !particle.strokeAnimation) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const { h, s, l } = particle.strokeColor, { h: hAnimation, s: sAnimation, l: lAnimation } = particle.strokeAnimation;
|
|
54
|
+
if (h) {
|
|
55
|
+
updateColorValue(delta, h, hAnimation, 360, false);
|
|
56
|
+
}
|
|
57
|
+
if (s) {
|
|
58
|
+
updateColorValue(delta, s, sAnimation, 100, true);
|
|
59
|
+
}
|
|
60
|
+
if (l) {
|
|
61
|
+
updateColorValue(delta, l, lAnimation, 100, true);
|
|
62
|
+
}
|
|
63
|
+
}
|
package/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StrokeColorUpdater } from "./StrokeColorUpdater";
|
|
2
|
-
export async function loadStrokeColorUpdater(engine) {
|
|
3
|
-
await engine.addParticleUpdater("strokeColor", (container) => new StrokeColorUpdater(container));
|
|
1
|
+
import { StrokeColorUpdater } from "./StrokeColorUpdater.js";
|
|
2
|
+
export async function loadStrokeColorUpdater(engine, refresh = true) {
|
|
3
|
+
await engine.addParticleUpdater("strokeColor", (container) => new StrokeColorUpdater(container), refresh);
|
|
4
4
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
|
@@ -2,97 +2,36 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StrokeColorUpdater = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
|
|
6
|
-
var _a, _b;
|
|
7
|
-
const colorValue = value;
|
|
8
|
-
if (!colorValue ||
|
|
9
|
-
!colorValue.enable ||
|
|
10
|
-
(colorValue.loops !== undefined &&
|
|
11
|
-
colorValue.maxLoops !== undefined &&
|
|
12
|
-
colorValue.maxLoops > 0 &&
|
|
13
|
-
colorValue.loops >= colorValue.maxLoops)) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const offset = (0, engine_1.randomInRange)(valueAnimation.offset), velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor + offset * 3.6, decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
|
|
17
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
18
|
-
colorValue.value += velocity;
|
|
19
|
-
if (colorValue.value > max) {
|
|
20
|
-
if (!colorValue.loops) {
|
|
21
|
-
colorValue.loops = 0;
|
|
22
|
-
}
|
|
23
|
-
colorValue.loops++;
|
|
24
|
-
if (decrease) {
|
|
25
|
-
colorValue.status = "decreasing";
|
|
26
|
-
colorValue.value -= colorValue.value % max;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
colorValue.value -= velocity;
|
|
32
|
-
if (colorValue.value < 0) {
|
|
33
|
-
if (!colorValue.loops) {
|
|
34
|
-
colorValue.loops = 0;
|
|
35
|
-
}
|
|
36
|
-
colorValue.loops++;
|
|
37
|
-
colorValue.status = "increasing";
|
|
38
|
-
colorValue.value += colorValue.value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (colorValue.velocity && decay !== 1) {
|
|
42
|
-
colorValue.velocity *= decay;
|
|
43
|
-
}
|
|
44
|
-
if (colorValue.value > max) {
|
|
45
|
-
colorValue.value %= max;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function updateStrokeColor(particle, delta) {
|
|
49
|
-
if (!particle.strokeColor || !particle.strokeAnimation) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const h = particle.strokeColor.h;
|
|
53
|
-
if (h) {
|
|
54
|
-
updateColorValue(delta, h, particle.strokeAnimation.h, 360, false);
|
|
55
|
-
}
|
|
56
|
-
const s = particle.strokeColor.s;
|
|
57
|
-
if (s) {
|
|
58
|
-
updateColorValue(delta, s, particle.strokeAnimation.s, 100, true);
|
|
59
|
-
}
|
|
60
|
-
const l = particle.strokeColor.l;
|
|
61
|
-
if (l) {
|
|
62
|
-
updateColorValue(delta, l, particle.strokeAnimation.l, 100, true);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
5
|
+
const Utils_js_1 = require("./Utils.js");
|
|
65
6
|
class StrokeColorUpdater {
|
|
66
7
|
constructor(container) {
|
|
67
8
|
this.container = container;
|
|
68
9
|
}
|
|
69
10
|
init(particle) {
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const stroke = (0, engine_1.itemFromSingleOrMultiple)(particle.options.stroke, particle.id, particle.options.reduceDuplicates);
|
|
11
|
+
const container = this.container, options = particle.options;
|
|
12
|
+
const stroke = (0, engine_1.itemFromSingleOrMultiple)(options.stroke, particle.id, options.reduceDuplicates);
|
|
73
13
|
particle.strokeWidth = (0, engine_1.getRangeValue)(stroke.width) * container.retina.pixelRatio;
|
|
74
|
-
particle.strokeOpacity = (0, engine_1.getRangeValue)(
|
|
75
|
-
particle.strokeAnimation =
|
|
76
|
-
const strokeHslColor = (
|
|
14
|
+
particle.strokeOpacity = (0, engine_1.getRangeValue)(stroke.opacity ?? 1);
|
|
15
|
+
particle.strokeAnimation = stroke.color?.animation;
|
|
16
|
+
const strokeHslColor = (0, engine_1.rangeColorToHsl)(stroke.color) ?? particle.getFillColor();
|
|
77
17
|
if (strokeHslColor) {
|
|
78
18
|
particle.strokeColor = (0, engine_1.getHslAnimationFromHsl)(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
79
19
|
}
|
|
80
20
|
}
|
|
81
21
|
isEnabled(particle) {
|
|
82
|
-
|
|
83
|
-
const color = particle.strokeAnimation;
|
|
22
|
+
const color = particle.strokeAnimation, { strokeColor } = particle;
|
|
84
23
|
return (!particle.destroyed &&
|
|
85
24
|
!particle.spawning &&
|
|
86
25
|
!!color &&
|
|
87
|
-
((
|
|
88
|
-
(
|
|
89
|
-
(
|
|
26
|
+
((strokeColor?.h.value !== undefined && strokeColor.h.enable) ||
|
|
27
|
+
(strokeColor?.s.value !== undefined && strokeColor.s.enable) ||
|
|
28
|
+
(strokeColor?.l.value !== undefined && strokeColor.l.enable)));
|
|
90
29
|
}
|
|
91
30
|
update(particle, delta) {
|
|
92
31
|
if (!this.isEnabled(particle)) {
|
|
93
32
|
return;
|
|
94
33
|
}
|
|
95
|
-
updateStrokeColor(particle, delta);
|
|
34
|
+
(0, Utils_js_1.updateStrokeColor)(particle, delta);
|
|
96
35
|
}
|
|
97
36
|
}
|
|
98
37
|
exports.StrokeColorUpdater = StrokeColorUpdater;
|
package/cjs/Types.js
ADDED
package/cjs/Utils.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateStrokeColor = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
function updateColorValue(delta, colorValue, valueAnimation, max, decrease) {
|
|
6
|
+
if (!colorValue ||
|
|
7
|
+
!valueAnimation.enable ||
|
|
8
|
+
((colorValue.maxLoops ?? 0) > 0 && (colorValue.loops ?? 0) > (colorValue.maxLoops ?? 0))) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (!colorValue.time) {
|
|
12
|
+
colorValue.time = 0;
|
|
13
|
+
}
|
|
14
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
15
|
+
colorValue.time += delta.value;
|
|
16
|
+
}
|
|
17
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const offset = (0, engine_1.randomInRange)(valueAnimation.offset), velocity = (colorValue.velocity ?? 0) * delta.factor + offset * 3.6, decay = colorValue.decay ?? 1;
|
|
21
|
+
if (!decrease || colorValue.status === "increasing") {
|
|
22
|
+
colorValue.value += velocity;
|
|
23
|
+
if (colorValue.value > max) {
|
|
24
|
+
if (!colorValue.loops) {
|
|
25
|
+
colorValue.loops = 0;
|
|
26
|
+
}
|
|
27
|
+
colorValue.loops++;
|
|
28
|
+
if (decrease) {
|
|
29
|
+
colorValue.status = "decreasing";
|
|
30
|
+
colorValue.value -= colorValue.value % max;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
colorValue.value -= velocity;
|
|
36
|
+
if (colorValue.value < 0) {
|
|
37
|
+
if (!colorValue.loops) {
|
|
38
|
+
colorValue.loops = 0;
|
|
39
|
+
}
|
|
40
|
+
colorValue.loops++;
|
|
41
|
+
colorValue.status = "increasing";
|
|
42
|
+
colorValue.value += colorValue.value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (colorValue.velocity && decay !== 1) {
|
|
46
|
+
colorValue.velocity *= decay;
|
|
47
|
+
}
|
|
48
|
+
if (colorValue.value > max) {
|
|
49
|
+
colorValue.value %= max;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function updateStrokeColor(particle, delta) {
|
|
53
|
+
if (!particle.strokeColor || !particle.strokeAnimation) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { h, s, l } = particle.strokeColor, { h: hAnimation, s: sAnimation, l: lAnimation } = particle.strokeAnimation;
|
|
57
|
+
if (h) {
|
|
58
|
+
updateColorValue(delta, h, hAnimation, 360, false);
|
|
59
|
+
}
|
|
60
|
+
if (s) {
|
|
61
|
+
updateColorValue(delta, s, sAnimation, 100, true);
|
|
62
|
+
}
|
|
63
|
+
if (l) {
|
|
64
|
+
updateColorValue(delta, l, lAnimation, 100, true);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.updateStrokeColor = updateStrokeColor;
|
package/cjs/index.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.loadStrokeColorUpdater = void 0;
|
|
13
|
-
const
|
|
14
|
-
function loadStrokeColorUpdater(engine) {
|
|
15
|
-
|
|
16
|
-
yield engine.addParticleUpdater("strokeColor", (container) => new StrokeColorUpdater_1.StrokeColorUpdater(container));
|
|
17
|
-
});
|
|
4
|
+
const StrokeColorUpdater_js_1 = require("./StrokeColorUpdater.js");
|
|
5
|
+
async function loadStrokeColorUpdater(engine, refresh = true) {
|
|
6
|
+
await engine.addParticleUpdater("strokeColor", (container) => new StrokeColorUpdater_js_1.StrokeColorUpdater(container), refresh);
|
|
18
7
|
}
|
|
19
8
|
exports.loadStrokeColorUpdater = loadStrokeColorUpdater;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -1,89 +1,28 @@
|
|
|
1
|
-
import { getHslAnimationFromHsl, getRangeValue, itemFromSingleOrMultiple,
|
|
2
|
-
|
|
3
|
-
var _a, _b;
|
|
4
|
-
const colorValue = value;
|
|
5
|
-
if (!colorValue ||
|
|
6
|
-
!colorValue.enable ||
|
|
7
|
-
(colorValue.loops !== undefined &&
|
|
8
|
-
colorValue.maxLoops !== undefined &&
|
|
9
|
-
colorValue.maxLoops > 0 &&
|
|
10
|
-
colorValue.loops >= colorValue.maxLoops)) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const offset = randomInRange(valueAnimation.offset), velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor + offset * 3.6, decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
|
|
14
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
15
|
-
colorValue.value += velocity;
|
|
16
|
-
if (colorValue.value > max) {
|
|
17
|
-
if (!colorValue.loops) {
|
|
18
|
-
colorValue.loops = 0;
|
|
19
|
-
}
|
|
20
|
-
colorValue.loops++;
|
|
21
|
-
if (decrease) {
|
|
22
|
-
colorValue.status = "decreasing";
|
|
23
|
-
colorValue.value -= colorValue.value % max;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
colorValue.value -= velocity;
|
|
29
|
-
if (colorValue.value < 0) {
|
|
30
|
-
if (!colorValue.loops) {
|
|
31
|
-
colorValue.loops = 0;
|
|
32
|
-
}
|
|
33
|
-
colorValue.loops++;
|
|
34
|
-
colorValue.status = "increasing";
|
|
35
|
-
colorValue.value += colorValue.value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (colorValue.velocity && decay !== 1) {
|
|
39
|
-
colorValue.velocity *= decay;
|
|
40
|
-
}
|
|
41
|
-
if (colorValue.value > max) {
|
|
42
|
-
colorValue.value %= max;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function updateStrokeColor(particle, delta) {
|
|
46
|
-
if (!particle.strokeColor || !particle.strokeAnimation) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const h = particle.strokeColor.h;
|
|
50
|
-
if (h) {
|
|
51
|
-
updateColorValue(delta, h, particle.strokeAnimation.h, 360, false);
|
|
52
|
-
}
|
|
53
|
-
const s = particle.strokeColor.s;
|
|
54
|
-
if (s) {
|
|
55
|
-
updateColorValue(delta, s, particle.strokeAnimation.s, 100, true);
|
|
56
|
-
}
|
|
57
|
-
const l = particle.strokeColor.l;
|
|
58
|
-
if (l) {
|
|
59
|
-
updateColorValue(delta, l, particle.strokeAnimation.l, 100, true);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
import { getHslAnimationFromHsl, getRangeValue, itemFromSingleOrMultiple, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
|
+
import { updateStrokeColor } from "./Utils.js";
|
|
62
3
|
export class StrokeColorUpdater {
|
|
63
4
|
constructor(container) {
|
|
64
5
|
this.container = container;
|
|
65
6
|
}
|
|
66
7
|
init(particle) {
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const stroke = itemFromSingleOrMultiple(particle.options.stroke, particle.id, particle.options.reduceDuplicates);
|
|
8
|
+
const container = this.container, options = particle.options;
|
|
9
|
+
const stroke = itemFromSingleOrMultiple(options.stroke, particle.id, options.reduceDuplicates);
|
|
70
10
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
71
|
-
particle.strokeOpacity = getRangeValue(
|
|
72
|
-
particle.strokeAnimation =
|
|
73
|
-
const strokeHslColor =
|
|
11
|
+
particle.strokeOpacity = getRangeValue(stroke.opacity ?? 1);
|
|
12
|
+
particle.strokeAnimation = stroke.color?.animation;
|
|
13
|
+
const strokeHslColor = rangeColorToHsl(stroke.color) ?? particle.getFillColor();
|
|
74
14
|
if (strokeHslColor) {
|
|
75
15
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
76
16
|
}
|
|
77
17
|
}
|
|
78
18
|
isEnabled(particle) {
|
|
79
|
-
|
|
80
|
-
const color = particle.strokeAnimation;
|
|
19
|
+
const color = particle.strokeAnimation, { strokeColor } = particle;
|
|
81
20
|
return (!particle.destroyed &&
|
|
82
21
|
!particle.spawning &&
|
|
83
22
|
!!color &&
|
|
84
|
-
((
|
|
85
|
-
(
|
|
86
|
-
(
|
|
23
|
+
((strokeColor?.h.value !== undefined && strokeColor.h.enable) ||
|
|
24
|
+
(strokeColor?.s.value !== undefined && strokeColor.s.enable) ||
|
|
25
|
+
(strokeColor?.l.value !== undefined && strokeColor.l.enable)));
|
|
87
26
|
}
|
|
88
27
|
update(particle, delta) {
|
|
89
28
|
if (!this.isEnabled(particle)) {
|
package/esm/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/Utils.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { randomInRange, } from "@tsparticles/engine";
|
|
2
|
+
function updateColorValue(delta, colorValue, valueAnimation, max, decrease) {
|
|
3
|
+
if (!colorValue ||
|
|
4
|
+
!valueAnimation.enable ||
|
|
5
|
+
((colorValue.maxLoops ?? 0) > 0 && (colorValue.loops ?? 0) > (colorValue.maxLoops ?? 0))) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (!colorValue.time) {
|
|
9
|
+
colorValue.time = 0;
|
|
10
|
+
}
|
|
11
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
12
|
+
colorValue.time += delta.value;
|
|
13
|
+
}
|
|
14
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const offset = randomInRange(valueAnimation.offset), velocity = (colorValue.velocity ?? 0) * delta.factor + offset * 3.6, decay = colorValue.decay ?? 1;
|
|
18
|
+
if (!decrease || colorValue.status === "increasing") {
|
|
19
|
+
colorValue.value += velocity;
|
|
20
|
+
if (colorValue.value > max) {
|
|
21
|
+
if (!colorValue.loops) {
|
|
22
|
+
colorValue.loops = 0;
|
|
23
|
+
}
|
|
24
|
+
colorValue.loops++;
|
|
25
|
+
if (decrease) {
|
|
26
|
+
colorValue.status = "decreasing";
|
|
27
|
+
colorValue.value -= colorValue.value % max;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
colorValue.value -= velocity;
|
|
33
|
+
if (colorValue.value < 0) {
|
|
34
|
+
if (!colorValue.loops) {
|
|
35
|
+
colorValue.loops = 0;
|
|
36
|
+
}
|
|
37
|
+
colorValue.loops++;
|
|
38
|
+
colorValue.status = "increasing";
|
|
39
|
+
colorValue.value += colorValue.value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (colorValue.velocity && decay !== 1) {
|
|
43
|
+
colorValue.velocity *= decay;
|
|
44
|
+
}
|
|
45
|
+
if (colorValue.value > max) {
|
|
46
|
+
colorValue.value %= max;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function updateStrokeColor(particle, delta) {
|
|
50
|
+
if (!particle.strokeColor || !particle.strokeAnimation) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const { h, s, l } = particle.strokeColor, { h: hAnimation, s: sAnimation, l: lAnimation } = particle.strokeAnimation;
|
|
54
|
+
if (h) {
|
|
55
|
+
updateColorValue(delta, h, hAnimation, 360, false);
|
|
56
|
+
}
|
|
57
|
+
if (s) {
|
|
58
|
+
updateColorValue(delta, s, sAnimation, 100, true);
|
|
59
|
+
}
|
|
60
|
+
if (l) {
|
|
61
|
+
updateColorValue(delta, l, lAnimation, 100, true);
|
|
62
|
+
}
|
|
63
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StrokeColorUpdater } from "./StrokeColorUpdater";
|
|
2
|
-
export async function loadStrokeColorUpdater(engine) {
|
|
3
|
-
await engine.addParticleUpdater("strokeColor", (container) => new StrokeColorUpdater(container));
|
|
1
|
+
import { StrokeColorUpdater } from "./StrokeColorUpdater.js";
|
|
2
|
+
export async function loadStrokeColorUpdater(engine, refresh = true) {
|
|
3
|
+
await engine.addParticleUpdater("strokeColor", (container) => new StrokeColorUpdater(container), refresh);
|
|
4
4
|
}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|