@tsparticles/updater-life 3.0.3 → 3.2.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/103.min.js +2 -0
- package/103.min.js.LICENSE.txt +1 -0
- package/16.min.js +2 -0
- package/16.min.js.LICENSE.txt +1 -0
- package/browser/LifeUpdater.js +20 -65
- package/browser/Utils.js +56 -0
- package/browser/index.js +4 -2
- package/cjs/LifeUpdater.js +42 -64
- package/cjs/Utils.js +60 -0
- package/cjs/index.js +27 -2
- package/dist_browser_LifeUpdater_js.js +60 -0
- package/dist_browser_Utils_js.js +30 -0
- package/esm/LifeUpdater.js +20 -65
- package/esm/Utils.js +56 -0
- package/esm/index.js +4 -2
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.updater.life.js +241 -175
- package/tsparticles.updater.life.min.js +1 -1
- package/tsparticles.updater.life.min.js.LICENSE.txt +1 -1
- package/types/LifeUpdater.d.ts +2 -2
- package/types/Utils.d.ts +3 -0
- package/umd/LifeUpdater.js +43 -64
- package/umd/Utils.js +70 -0
- package/umd/index.js +29 -3
package/esm/LifeUpdater.js
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
import { getRandom, getRangeValue,
|
|
1
|
+
import { getRandom, getRangeValue, millisecondsToSeconds, } from "@tsparticles/engine";
|
|
2
2
|
import { Life } from "./Options/Classes/Life.js";
|
|
3
|
+
const noTime = 0, identity = 1, infiniteValue = -1;
|
|
3
4
|
export class LifeUpdater {
|
|
4
5
|
constructor(container) {
|
|
5
6
|
this.container = container;
|
|
6
7
|
}
|
|
7
|
-
init(particle) {
|
|
8
|
+
async init(particle) {
|
|
8
9
|
const container = this.container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
9
10
|
if (!lifeOptions) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
particle.life = {
|
|
13
14
|
delay: container.retina.reduceFactor
|
|
14
|
-
? ((getRangeValue(lifeOptions.delay.value) * (lifeOptions.delay.sync ?
|
|
15
|
+
? ((getRangeValue(lifeOptions.delay.value) * (lifeOptions.delay.sync ? identity : getRandom())) /
|
|
15
16
|
container.retina.reduceFactor) *
|
|
16
|
-
|
|
17
|
-
:
|
|
18
|
-
delayTime:
|
|
17
|
+
millisecondsToSeconds
|
|
18
|
+
: noTime,
|
|
19
|
+
delayTime: noTime,
|
|
19
20
|
duration: container.retina.reduceFactor
|
|
20
|
-
? ((getRangeValue(lifeOptions.duration.value) * (lifeOptions.duration.sync ?
|
|
21
|
+
? ((getRangeValue(lifeOptions.duration.value) * (lifeOptions.duration.sync ? identity : getRandom())) /
|
|
21
22
|
container.retina.reduceFactor) *
|
|
22
|
-
|
|
23
|
-
:
|
|
24
|
-
time:
|
|
23
|
+
millisecondsToSeconds
|
|
24
|
+
: noTime,
|
|
25
|
+
time: noTime,
|
|
25
26
|
count: lifeOptions.count,
|
|
26
27
|
};
|
|
27
|
-
if (particle.life.duration <=
|
|
28
|
-
particle.life.duration =
|
|
28
|
+
if (particle.life.duration <= noTime) {
|
|
29
|
+
particle.life.duration = infiniteValue;
|
|
29
30
|
}
|
|
30
|
-
if (particle.life.count <=
|
|
31
|
-
particle.life.count =
|
|
31
|
+
if (particle.life.count <= noTime) {
|
|
32
|
+
particle.life.count = infiniteValue;
|
|
32
33
|
}
|
|
33
34
|
if (particle.life) {
|
|
34
|
-
particle.spawning = particle.life.delay >
|
|
35
|
+
particle.spawning = particle.life.delay > noTime;
|
|
35
36
|
}
|
|
37
|
+
await Promise.resolve();
|
|
36
38
|
}
|
|
37
39
|
isEnabled(particle) {
|
|
38
40
|
return !particle.destroyed;
|
|
@@ -45,58 +47,11 @@ export class LifeUpdater {
|
|
|
45
47
|
options.life.load(source?.life);
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
|
-
update(particle, delta) {
|
|
50
|
+
async update(particle, delta) {
|
|
49
51
|
if (!this.isEnabled(particle) || !particle.life) {
|
|
50
52
|
return;
|
|
51
53
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
if (particle.spawning) {
|
|
55
|
-
life.delayTime += delta.value;
|
|
56
|
-
if (life.delayTime >= particle.life.delay) {
|
|
57
|
-
justSpawned = true;
|
|
58
|
-
particle.spawning = false;
|
|
59
|
-
life.delayTime = 0;
|
|
60
|
-
life.time = 0;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (life.duration === -1) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (particle.spawning) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (justSpawned) {
|
|
73
|
-
life.time = 0;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
life.time += delta.value;
|
|
77
|
-
}
|
|
78
|
-
if (life.time < life.duration) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
life.time = 0;
|
|
82
|
-
if (particle.life.count > 0) {
|
|
83
|
-
particle.life.count--;
|
|
84
|
-
}
|
|
85
|
-
if (particle.life.count === 0) {
|
|
86
|
-
particle.destroy();
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const canvasSize = this.container.canvas.size, widthRange = setRangeValue(0, canvasSize.width), heightRange = setRangeValue(0, canvasSize.width);
|
|
90
|
-
particle.position.x = randomInRange(widthRange);
|
|
91
|
-
particle.position.y = randomInRange(heightRange);
|
|
92
|
-
particle.spawning = true;
|
|
93
|
-
life.delayTime = 0;
|
|
94
|
-
life.time = 0;
|
|
95
|
-
particle.reset();
|
|
96
|
-
const lifeOptions = particle.options.life;
|
|
97
|
-
if (lifeOptions) {
|
|
98
|
-
life.delay = getRangeValue(lifeOptions.delay.value) * 1000;
|
|
99
|
-
life.duration = getRangeValue(lifeOptions.duration.value) * 1000;
|
|
100
|
-
}
|
|
54
|
+
const { updateLife } = await import("./Utils.js");
|
|
55
|
+
updateLife(particle, delta, this.container.canvas.size);
|
|
101
56
|
}
|
|
102
57
|
}
|
package/esm/Utils.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getRangeValue, millisecondsToSeconds, randomInRange, setRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
const noTime = 0, infiniteValue = -1, noLife = 0, minCanvasSize = 0;
|
|
3
|
+
export function updateLife(particle, delta, canvasSize) {
|
|
4
|
+
if (!particle.life) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const life = particle.life;
|
|
8
|
+
let justSpawned = false;
|
|
9
|
+
if (particle.spawning) {
|
|
10
|
+
life.delayTime += delta.value;
|
|
11
|
+
if (life.delayTime >= particle.life.delay) {
|
|
12
|
+
justSpawned = true;
|
|
13
|
+
particle.spawning = false;
|
|
14
|
+
life.delayTime = noTime;
|
|
15
|
+
life.time = noTime;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (life.duration === infiniteValue) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (particle.spawning) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (justSpawned) {
|
|
28
|
+
life.time = noTime;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
life.time += delta.value;
|
|
32
|
+
}
|
|
33
|
+
if (life.time < life.duration) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
life.time = noTime;
|
|
37
|
+
if (particle.life.count > noLife) {
|
|
38
|
+
particle.life.count--;
|
|
39
|
+
}
|
|
40
|
+
if (particle.life.count === noLife) {
|
|
41
|
+
particle.destroy();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.width);
|
|
45
|
+
particle.position.x = randomInRange(widthRange);
|
|
46
|
+
particle.position.y = randomInRange(heightRange);
|
|
47
|
+
particle.spawning = true;
|
|
48
|
+
life.delayTime = noTime;
|
|
49
|
+
life.time = noTime;
|
|
50
|
+
particle.reset();
|
|
51
|
+
const lifeOptions = particle.options.life;
|
|
52
|
+
if (lifeOptions) {
|
|
53
|
+
life.delay = getRangeValue(lifeOptions.delay.value) * millisecondsToSeconds;
|
|
54
|
+
life.duration = getRangeValue(lifeOptions.duration.value) * millisecondsToSeconds;
|
|
55
|
+
}
|
|
56
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { LifeUpdater } from "./LifeUpdater.js";
|
|
2
1
|
export async function loadLifeUpdater(engine, refresh = true) {
|
|
3
|
-
await engine.addParticleUpdater("life", (container) =>
|
|
2
|
+
await engine.addParticleUpdater("life", async (container) => {
|
|
3
|
+
const { LifeUpdater } = await import("./LifeUpdater.js");
|
|
4
|
+
return new LifeUpdater(container);
|
|
5
|
+
}, refresh);
|
|
4
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/updater-life",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "tsParticles particles life updater",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"./package.json": "./package.json"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "^3.0
|
|
90
|
+
"@tsparticles/engine": "^3.2.0"
|
|
91
91
|
},
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
package/report.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8"/>
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
6
|
-
<title>@tsparticles/updater-life [
|
|
6
|
+
<title>@tsparticles/updater-life [31 Jan 2024 at 02:10]</title>
|
|
7
7
|
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7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dsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
|
|
8
8
|
|
|
9
9
|
<script>
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
<body>
|
|
32
32
|
<div id="app"></div>
|
|
33
33
|
<script>
|
|
34
|
-
window.chartData = [
|
|
35
|
-
window.entrypoints = ["tsparticles.updater.life
|
|
34
|
+
window.chartData = [];
|
|
35
|
+
window.entrypoints = ["tsparticles.updater.life.min"];
|
|
36
36
|
window.defaultSizes = "parsed";
|
|
37
37
|
</script>
|
|
38
38
|
</body>
|