@tsparticles/updater-life 3.0.0-alpha.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/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/LifeUpdater.js +102 -0
- package/browser/Options/Classes/Life.js +19 -0
- package/browser/Options/Classes/LifeDelay.js +16 -0
- package/browser/Options/Classes/LifeDuration.js +17 -0
- package/browser/Options/Interfaces/ILife.js +1 -0
- package/browser/Options/Interfaces/ILifeDelay.js +1 -0
- package/browser/Options/Interfaces/ILifeDuration.js +1 -0
- package/browser/index.js +4 -0
- package/cjs/LifeUpdater.js +106 -0
- package/cjs/Options/Classes/Life.js +23 -0
- package/cjs/Options/Classes/LifeDelay.js +20 -0
- package/cjs/Options/Classes/LifeDuration.js +21 -0
- package/cjs/Options/Interfaces/ILife.js +2 -0
- package/cjs/Options/Interfaces/ILifeDelay.js +2 -0
- package/cjs/Options/Interfaces/ILifeDuration.js +2 -0
- package/cjs/index.js +19 -0
- package/esm/LifeUpdater.js +102 -0
- package/esm/Options/Classes/Life.js +19 -0
- package/esm/Options/Classes/LifeDelay.js +16 -0
- package/esm/Options/Classes/LifeDuration.js +17 -0
- package/esm/Options/Interfaces/ILife.js +1 -0
- package/esm/Options/Interfaces/ILifeDelay.js +1 -0
- package/esm/Options/Interfaces/ILifeDuration.js +1 -0
- package/esm/index.js +4 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.updater.life.js +261 -0
- package/tsparticles.updater.life.min.js +2 -0
- package/tsparticles.updater.life.min.js.LICENSE.txt +8 -0
- package/types/LifeUpdater.d.ts +29 -0
- package/types/Options/Classes/Life.d.ts +11 -0
- package/types/Options/Classes/LifeDelay.d.ts +8 -0
- package/types/Options/Classes/LifeDuration.d.ts +8 -0
- package/types/Options/Interfaces/ILife.d.ts +7 -0
- package/types/Options/Interfaces/ILifeDelay.d.ts +4 -0
- package/types/Options/Interfaces/ILifeDuration.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/umd/LifeUpdater.js +116 -0
- package/umd/Options/Classes/Life.js +33 -0
- package/umd/Options/Classes/LifeDelay.js +30 -0
- package/umd/Options/Classes/LifeDuration.js +31 -0
- package/umd/Options/Interfaces/ILife.js +12 -0
- package/umd/Options/Interfaces/ILifeDelay.js +12 -0
- package/umd/Options/Interfaces/ILifeDuration.js +12 -0
- package/umd/index.js +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Life Updater
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/tsparticles-updater-life)
|
|
6
|
+
[](https://www.npmjs.com/package/tsparticles-updater-life)
|
|
7
|
+
[](https://www.npmjs.com/package/tsparticles-updater-life) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for life animations.
|
|
10
|
+
|
|
11
|
+
## How to use it
|
|
12
|
+
|
|
13
|
+
### CDN / Vanilla JS / jQuery
|
|
14
|
+
|
|
15
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
|
+
|
|
17
|
+
Including the `tsparticles.updater.life.min.js` file will export the function to load the updater plugin:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
loadLifeUpdater;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the updater plugin like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadLifeUpdater();
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ESM / CommonJS
|
|
41
|
+
|
|
42
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
$ npm install tsparticles-updater-life
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add tsparticles-updater-life
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then you need to import it in the app, like this:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const { tsParticles } = require("tsparticles-engine");
|
|
58
|
+
const { loadLifeUpdater } = require("tsparticles-updater-life");
|
|
59
|
+
|
|
60
|
+
loadLifeUpdater(tsParticles);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { tsParticles } from "tsparticles-engine";
|
|
67
|
+
import { loadLifeUpdater } from "tsparticles-updater-life";
|
|
68
|
+
|
|
69
|
+
loadLifeUpdater(tsParticles);
|
|
70
|
+
```
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getRandom, getRangeValue, randomInRange, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { Life } from "./Options/Classes/Life";
|
|
3
|
+
export class LifeUpdater {
|
|
4
|
+
constructor(container) {
|
|
5
|
+
this.container = container;
|
|
6
|
+
}
|
|
7
|
+
init(particle) {
|
|
8
|
+
const container = this.container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
9
|
+
if (!lifeOptions) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
particle.life = {
|
|
13
|
+
delay: container.retina.reduceFactor
|
|
14
|
+
? ((getRangeValue(lifeOptions.delay.value) * (lifeOptions.delay.sync ? 1 : getRandom())) /
|
|
15
|
+
container.retina.reduceFactor) *
|
|
16
|
+
1000
|
|
17
|
+
: 0,
|
|
18
|
+
delayTime: 0,
|
|
19
|
+
duration: container.retina.reduceFactor
|
|
20
|
+
? ((getRangeValue(lifeOptions.duration.value) * (lifeOptions.duration.sync ? 1 : getRandom())) /
|
|
21
|
+
container.retina.reduceFactor) *
|
|
22
|
+
1000
|
|
23
|
+
: 0,
|
|
24
|
+
time: 0,
|
|
25
|
+
count: lifeOptions.count,
|
|
26
|
+
};
|
|
27
|
+
if (particle.life.duration <= 0) {
|
|
28
|
+
particle.life.duration = -1;
|
|
29
|
+
}
|
|
30
|
+
if (particle.life.count <= 0) {
|
|
31
|
+
particle.life.count = -1;
|
|
32
|
+
}
|
|
33
|
+
if (particle.life) {
|
|
34
|
+
particle.spawning = particle.life.delay > 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
isEnabled(particle) {
|
|
38
|
+
return !particle.destroyed;
|
|
39
|
+
}
|
|
40
|
+
loadOptions(options, ...sources) {
|
|
41
|
+
if (!options.life) {
|
|
42
|
+
options.life = new Life();
|
|
43
|
+
}
|
|
44
|
+
for (const source of sources) {
|
|
45
|
+
options.life.load(source === null || source === void 0 ? void 0 : source.life);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
update(particle, delta) {
|
|
49
|
+
if (!this.isEnabled(particle) || !particle.life) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const life = particle.life;
|
|
53
|
+
let justSpawned = false;
|
|
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
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LifeDelay } from "./LifeDelay";
|
|
2
|
+
import { LifeDuration } from "./LifeDuration";
|
|
3
|
+
export class Life {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.count = 0;
|
|
6
|
+
this.delay = new LifeDelay();
|
|
7
|
+
this.duration = new LifeDuration();
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (!data) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.count !== undefined) {
|
|
14
|
+
this.count = data.count;
|
|
15
|
+
}
|
|
16
|
+
this.delay.load(data.delay);
|
|
17
|
+
this.duration.load(data.duration);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
2
|
+
export class LifeDelay extends ValueWithRandom {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.sync = false;
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (!data) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
super.load(data);
|
|
12
|
+
if (data.sync !== undefined) {
|
|
13
|
+
this.sync = data.sync;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
2
|
+
export class LifeDuration extends ValueWithRandom {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.random.minimumValue = 0.0001;
|
|
6
|
+
this.sync = false;
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (!data) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
super.load(data);
|
|
13
|
+
if (data.sync !== undefined) {
|
|
14
|
+
this.sync = data.sync;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LifeUpdater = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const Life_1 = require("./Options/Classes/Life");
|
|
6
|
+
class LifeUpdater {
|
|
7
|
+
constructor(container) {
|
|
8
|
+
this.container = container;
|
|
9
|
+
}
|
|
10
|
+
init(particle) {
|
|
11
|
+
const container = this.container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
12
|
+
if (!lifeOptions) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
particle.life = {
|
|
16
|
+
delay: container.retina.reduceFactor
|
|
17
|
+
? (((0, engine_1.getRangeValue)(lifeOptions.delay.value) * (lifeOptions.delay.sync ? 1 : (0, engine_1.getRandom)())) /
|
|
18
|
+
container.retina.reduceFactor) *
|
|
19
|
+
1000
|
|
20
|
+
: 0,
|
|
21
|
+
delayTime: 0,
|
|
22
|
+
duration: container.retina.reduceFactor
|
|
23
|
+
? (((0, engine_1.getRangeValue)(lifeOptions.duration.value) * (lifeOptions.duration.sync ? 1 : (0, engine_1.getRandom)())) /
|
|
24
|
+
container.retina.reduceFactor) *
|
|
25
|
+
1000
|
|
26
|
+
: 0,
|
|
27
|
+
time: 0,
|
|
28
|
+
count: lifeOptions.count,
|
|
29
|
+
};
|
|
30
|
+
if (particle.life.duration <= 0) {
|
|
31
|
+
particle.life.duration = -1;
|
|
32
|
+
}
|
|
33
|
+
if (particle.life.count <= 0) {
|
|
34
|
+
particle.life.count = -1;
|
|
35
|
+
}
|
|
36
|
+
if (particle.life) {
|
|
37
|
+
particle.spawning = particle.life.delay > 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
isEnabled(particle) {
|
|
41
|
+
return !particle.destroyed;
|
|
42
|
+
}
|
|
43
|
+
loadOptions(options, ...sources) {
|
|
44
|
+
if (!options.life) {
|
|
45
|
+
options.life = new Life_1.Life();
|
|
46
|
+
}
|
|
47
|
+
for (const source of sources) {
|
|
48
|
+
options.life.load(source === null || source === void 0 ? void 0 : source.life);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
update(particle, delta) {
|
|
52
|
+
if (!this.isEnabled(particle) || !particle.life) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const life = particle.life;
|
|
56
|
+
let justSpawned = false;
|
|
57
|
+
if (particle.spawning) {
|
|
58
|
+
life.delayTime += delta.value;
|
|
59
|
+
if (life.delayTime >= particle.life.delay) {
|
|
60
|
+
justSpawned = true;
|
|
61
|
+
particle.spawning = false;
|
|
62
|
+
life.delayTime = 0;
|
|
63
|
+
life.time = 0;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (life.duration === -1) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (particle.spawning) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (justSpawned) {
|
|
76
|
+
life.time = 0;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
life.time += delta.value;
|
|
80
|
+
}
|
|
81
|
+
if (life.time < life.duration) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
life.time = 0;
|
|
85
|
+
if (particle.life.count > 0) {
|
|
86
|
+
particle.life.count--;
|
|
87
|
+
}
|
|
88
|
+
if (particle.life.count === 0) {
|
|
89
|
+
particle.destroy();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const canvasSize = this.container.canvas.size, widthRange = (0, engine_1.setRangeValue)(0, canvasSize.width), heightRange = (0, engine_1.setRangeValue)(0, canvasSize.width);
|
|
93
|
+
particle.position.x = (0, engine_1.randomInRange)(widthRange);
|
|
94
|
+
particle.position.y = (0, engine_1.randomInRange)(heightRange);
|
|
95
|
+
particle.spawning = true;
|
|
96
|
+
life.delayTime = 0;
|
|
97
|
+
life.time = 0;
|
|
98
|
+
particle.reset();
|
|
99
|
+
const lifeOptions = particle.options.life;
|
|
100
|
+
if (lifeOptions) {
|
|
101
|
+
life.delay = (0, engine_1.getRangeValue)(lifeOptions.delay.value) * 1000;
|
|
102
|
+
life.duration = (0, engine_1.getRangeValue)(lifeOptions.duration.value) * 1000;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.LifeUpdater = LifeUpdater;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Life = void 0;
|
|
4
|
+
const LifeDelay_1 = require("./LifeDelay");
|
|
5
|
+
const LifeDuration_1 = require("./LifeDuration");
|
|
6
|
+
class Life {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.count = 0;
|
|
9
|
+
this.delay = new LifeDelay_1.LifeDelay();
|
|
10
|
+
this.duration = new LifeDuration_1.LifeDuration();
|
|
11
|
+
}
|
|
12
|
+
load(data) {
|
|
13
|
+
if (!data) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (data.count !== undefined) {
|
|
17
|
+
this.count = data.count;
|
|
18
|
+
}
|
|
19
|
+
this.delay.load(data.delay);
|
|
20
|
+
this.duration.load(data.duration);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.Life = Life;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LifeDelay = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class LifeDelay extends engine_1.ValueWithRandom {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.sync = false;
|
|
9
|
+
}
|
|
10
|
+
load(data) {
|
|
11
|
+
if (!data) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
super.load(data);
|
|
15
|
+
if (data.sync !== undefined) {
|
|
16
|
+
this.sync = data.sync;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.LifeDelay = LifeDelay;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LifeDuration = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class LifeDuration extends engine_1.ValueWithRandom {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.random.minimumValue = 0.0001;
|
|
9
|
+
this.sync = false;
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
super.load(data);
|
|
16
|
+
if (data.sync !== undefined) {
|
|
17
|
+
this.sync = data.sync;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.LifeDuration = LifeDuration;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadLifeUpdater = void 0;
|
|
13
|
+
const LifeUpdater_1 = require("./LifeUpdater");
|
|
14
|
+
function loadLifeUpdater(engine) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
yield engine.addParticleUpdater("life", (container) => new LifeUpdater_1.LifeUpdater(container));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.loadLifeUpdater = loadLifeUpdater;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getRandom, getRangeValue, randomInRange, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { Life } from "./Options/Classes/Life";
|
|
3
|
+
export class LifeUpdater {
|
|
4
|
+
constructor(container) {
|
|
5
|
+
this.container = container;
|
|
6
|
+
}
|
|
7
|
+
init(particle) {
|
|
8
|
+
const container = this.container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
9
|
+
if (!lifeOptions) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
particle.life = {
|
|
13
|
+
delay: container.retina.reduceFactor
|
|
14
|
+
? ((getRangeValue(lifeOptions.delay.value) * (lifeOptions.delay.sync ? 1 : getRandom())) /
|
|
15
|
+
container.retina.reduceFactor) *
|
|
16
|
+
1000
|
|
17
|
+
: 0,
|
|
18
|
+
delayTime: 0,
|
|
19
|
+
duration: container.retina.reduceFactor
|
|
20
|
+
? ((getRangeValue(lifeOptions.duration.value) * (lifeOptions.duration.sync ? 1 : getRandom())) /
|
|
21
|
+
container.retina.reduceFactor) *
|
|
22
|
+
1000
|
|
23
|
+
: 0,
|
|
24
|
+
time: 0,
|
|
25
|
+
count: lifeOptions.count,
|
|
26
|
+
};
|
|
27
|
+
if (particle.life.duration <= 0) {
|
|
28
|
+
particle.life.duration = -1;
|
|
29
|
+
}
|
|
30
|
+
if (particle.life.count <= 0) {
|
|
31
|
+
particle.life.count = -1;
|
|
32
|
+
}
|
|
33
|
+
if (particle.life) {
|
|
34
|
+
particle.spawning = particle.life.delay > 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
isEnabled(particle) {
|
|
38
|
+
return !particle.destroyed;
|
|
39
|
+
}
|
|
40
|
+
loadOptions(options, ...sources) {
|
|
41
|
+
if (!options.life) {
|
|
42
|
+
options.life = new Life();
|
|
43
|
+
}
|
|
44
|
+
for (const source of sources) {
|
|
45
|
+
options.life.load(source === null || source === void 0 ? void 0 : source.life);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
update(particle, delta) {
|
|
49
|
+
if (!this.isEnabled(particle) || !particle.life) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const life = particle.life;
|
|
53
|
+
let justSpawned = false;
|
|
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
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LifeDelay } from "./LifeDelay";
|
|
2
|
+
import { LifeDuration } from "./LifeDuration";
|
|
3
|
+
export class Life {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.count = 0;
|
|
6
|
+
this.delay = new LifeDelay();
|
|
7
|
+
this.duration = new LifeDuration();
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (!data) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.count !== undefined) {
|
|
14
|
+
this.count = data.count;
|
|
15
|
+
}
|
|
16
|
+
this.delay.load(data.delay);
|
|
17
|
+
this.duration.load(data.duration);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
2
|
+
export class LifeDelay extends ValueWithRandom {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.sync = false;
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (!data) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
super.load(data);
|
|
12
|
+
if (data.sync !== undefined) {
|
|
13
|
+
this.sync = data.sync;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
2
|
+
export class LifeDuration extends ValueWithRandom {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this.random.minimumValue = 0.0001;
|
|
6
|
+
this.sync = false;
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (!data) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
super.load(data);
|
|
13
|
+
if (data.sync !== undefined) {
|
|
14
|
+
this.sync = data.sync;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.js
ADDED