@tsparticles/updater-life 3.1.0 → 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 ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 103.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_life=this.webpackChunk_tsparticles_updater_life||[]).push([[103],{103:(e,i,n)=>{n.d(i,{updateLife:()=>u});var t=n(533);const a=0,l=-1,o=0,s=0;function u(e,i,n){if(!e.life)return;const u=e.life;let d=!1;if(e.spawning){if(u.delayTime+=i.value,!(u.delayTime>=e.life.delay))return;d=!0,e.spawning=!1,u.delayTime=a,u.time=a}if(u.duration===l)return;if(e.spawning)return;if(d?u.time=a:u.time+=i.value,u.time<u.duration)return;if(u.time=a,e.life.count>o&&e.life.count--,e.life.count===o)return void e.destroy();const r=(0,t.setRangeValue)(s,n.width),f=(0,t.setRangeValue)(s,n.width);e.position.x=(0,t.randomInRange)(r),e.position.y=(0,t.randomInRange)(f),e.spawning=!0,u.delayTime=a,u.time=a,e.reset();const c=e.options.life;c&&(u.delay=(0,t.getRangeValue)(c.delay.value)*t.millisecondsToSeconds,u.duration=(0,t.getRangeValue)(c.duration.value)*t.millisecondsToSeconds)}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Life Updater v3.2.0 by Matteo Bruni */
package/16.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 16.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_life=this.webpackChunk_tsparticles_updater_life||[]).push([[16],{16:(e,t,i)=>{i.d(t,{LifeUpdater:()=>c});var n=i(533);class a extends n.ValueWithRandom{constructor(){super(),this.sync=!1}load(e){e&&(super.load(e),void 0!==e.sync&&(this.sync=e.sync))}}class s extends n.ValueWithRandom{constructor(){super(),this.sync=!1}load(e){e&&(super.load(e),void 0!==e.sync&&(this.sync=e.sync))}}class o{constructor(){this.count=0,this.delay=new a,this.duration=new s}load(e){e&&(void 0!==e.count&&(this.count=e.count),this.delay.load(e.delay),this.duration.load(e.duration))}}class c{constructor(e){this.container=e}async init(e){const t=this.container,i=e.options.life;i&&(e.life={delay:t.retina.reduceFactor?(0,n.getRangeValue)(i.delay.value)*(i.delay.sync?1:(0,n.getRandom)())/t.retina.reduceFactor*n.millisecondsToSeconds:0,delayTime:0,duration:t.retina.reduceFactor?(0,n.getRangeValue)(i.duration.value)*(i.duration.sync?1:(0,n.getRandom)())/t.retina.reduceFactor*n.millisecondsToSeconds:0,time:0,count:i.count},e.life.duration<=0&&(e.life.duration=-1),e.life.count<=0&&(e.life.count=-1),e.life&&(e.spawning=e.life.delay>0),await Promise.resolve())}isEnabled(e){return!e.destroyed}loadOptions(e,...t){e.life||(e.life=new o);for(const i of t)e.life.load(i?.life)}async update(e,t){if(!this.isEnabled(e)||!e.life)return;const{updateLife:n}=await i.e(103).then(i.bind(i,103));n(e,t,this.container.canvas.size)}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Life Updater v3.2.0 by Matteo Bruni */
@@ -1,11 +1,11 @@
1
- import { getRandom, getRangeValue, millisecondsToSeconds, randomInRange, setRangeValue, } from "@tsparticles/engine";
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, noLife = 0, minCanvasSize = 0;
3
+ const noTime = 0, identity = 1, infiniteValue = -1;
4
4
  export class LifeUpdater {
5
5
  constructor(container) {
6
6
  this.container = container;
7
7
  }
8
- init(particle) {
8
+ async init(particle) {
9
9
  const container = this.container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
10
10
  if (!lifeOptions) {
11
11
  return;
@@ -34,6 +34,7 @@ export class LifeUpdater {
34
34
  if (particle.life) {
35
35
  particle.spawning = particle.life.delay > noTime;
36
36
  }
37
+ await Promise.resolve();
37
38
  }
38
39
  isEnabled(particle) {
39
40
  return !particle.destroyed;
@@ -46,58 +47,11 @@ export class LifeUpdater {
46
47
  options.life.load(source?.life);
47
48
  }
48
49
  }
49
- update(particle, delta) {
50
+ async update(particle, delta) {
50
51
  if (!this.isEnabled(particle) || !particle.life) {
51
52
  return;
52
53
  }
53
- const life = particle.life;
54
- let justSpawned = false;
55
- if (particle.spawning) {
56
- life.delayTime += delta.value;
57
- if (life.delayTime >= particle.life.delay) {
58
- justSpawned = true;
59
- particle.spawning = false;
60
- life.delayTime = noTime;
61
- life.time = noTime;
62
- }
63
- else {
64
- return;
65
- }
66
- }
67
- if (life.duration === infiniteValue) {
68
- return;
69
- }
70
- if (particle.spawning) {
71
- return;
72
- }
73
- if (justSpawned) {
74
- life.time = noTime;
75
- }
76
- else {
77
- life.time += delta.value;
78
- }
79
- if (life.time < life.duration) {
80
- return;
81
- }
82
- life.time = noTime;
83
- if (particle.life.count > noLife) {
84
- particle.life.count--;
85
- }
86
- if (particle.life.count === noLife) {
87
- particle.destroy();
88
- return;
89
- }
90
- const canvasSize = this.container.canvas.size, widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.width);
91
- particle.position.x = randomInRange(widthRange);
92
- particle.position.y = randomInRange(heightRange);
93
- particle.spawning = true;
94
- life.delayTime = noTime;
95
- life.time = noTime;
96
- particle.reset();
97
- const lifeOptions = particle.options.life;
98
- if (lifeOptions) {
99
- life.delay = getRangeValue(lifeOptions.delay.value) * millisecondsToSeconds;
100
- life.duration = getRangeValue(lifeOptions.duration.value) * millisecondsToSeconds;
101
- }
54
+ const { updateLife } = await import("./Utils.js");
55
+ updateLife(particle, delta, this.container.canvas.size);
102
56
  }
103
57
  }
@@ -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/browser/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) => new LifeUpdater(container), refresh);
2
+ await engine.addParticleUpdater("life", async (container) => {
3
+ const { LifeUpdater } = await import("./LifeUpdater.js");
4
+ return new LifeUpdater(container);
5
+ }, refresh);
4
6
  }
@@ -1,14 +1,37 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.LifeUpdater = void 0;
4
27
  const engine_1 = require("@tsparticles/engine");
5
28
  const Life_js_1 = require("./Options/Classes/Life.js");
6
- const noTime = 0, identity = 1, infiniteValue = -1, noLife = 0, minCanvasSize = 0;
29
+ const noTime = 0, identity = 1, infiniteValue = -1;
7
30
  class LifeUpdater {
8
31
  constructor(container) {
9
32
  this.container = container;
10
33
  }
11
- init(particle) {
34
+ async init(particle) {
12
35
  const container = this.container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
13
36
  if (!lifeOptions) {
14
37
  return;
@@ -37,6 +60,7 @@ class LifeUpdater {
37
60
  if (particle.life) {
38
61
  particle.spawning = particle.life.delay > noTime;
39
62
  }
63
+ await Promise.resolve();
40
64
  }
41
65
  isEnabled(particle) {
42
66
  return !particle.destroyed;
@@ -49,59 +73,12 @@ class LifeUpdater {
49
73
  options.life.load(source?.life);
50
74
  }
51
75
  }
52
- update(particle, delta) {
76
+ async update(particle, delta) {
53
77
  if (!this.isEnabled(particle) || !particle.life) {
54
78
  return;
55
79
  }
56
- const life = particle.life;
57
- let justSpawned = false;
58
- if (particle.spawning) {
59
- life.delayTime += delta.value;
60
- if (life.delayTime >= particle.life.delay) {
61
- justSpawned = true;
62
- particle.spawning = false;
63
- life.delayTime = noTime;
64
- life.time = noTime;
65
- }
66
- else {
67
- return;
68
- }
69
- }
70
- if (life.duration === infiniteValue) {
71
- return;
72
- }
73
- if (particle.spawning) {
74
- return;
75
- }
76
- if (justSpawned) {
77
- life.time = noTime;
78
- }
79
- else {
80
- life.time += delta.value;
81
- }
82
- if (life.time < life.duration) {
83
- return;
84
- }
85
- life.time = noTime;
86
- if (particle.life.count > noLife) {
87
- particle.life.count--;
88
- }
89
- if (particle.life.count === noLife) {
90
- particle.destroy();
91
- return;
92
- }
93
- const canvasSize = this.container.canvas.size, widthRange = (0, engine_1.setRangeValue)(minCanvasSize, canvasSize.width), heightRange = (0, engine_1.setRangeValue)(minCanvasSize, canvasSize.width);
94
- particle.position.x = (0, engine_1.randomInRange)(widthRange);
95
- particle.position.y = (0, engine_1.randomInRange)(heightRange);
96
- particle.spawning = true;
97
- life.delayTime = noTime;
98
- life.time = noTime;
99
- particle.reset();
100
- const lifeOptions = particle.options.life;
101
- if (lifeOptions) {
102
- life.delay = (0, engine_1.getRangeValue)(lifeOptions.delay.value) * engine_1.millisecondsToSeconds;
103
- life.duration = (0, engine_1.getRangeValue)(lifeOptions.duration.value) * engine_1.millisecondsToSeconds;
104
- }
80
+ const { updateLife } = await Promise.resolve().then(() => __importStar(require("./Utils.js")));
81
+ updateLife(particle, delta, this.container.canvas.size);
105
82
  }
106
83
  }
107
84
  exports.LifeUpdater = LifeUpdater;
package/cjs/Utils.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateLife = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ const noTime = 0, infiniteValue = -1, noLife = 0, minCanvasSize = 0;
6
+ function updateLife(particle, delta, canvasSize) {
7
+ if (!particle.life) {
8
+ return;
9
+ }
10
+ const life = particle.life;
11
+ let justSpawned = false;
12
+ if (particle.spawning) {
13
+ life.delayTime += delta.value;
14
+ if (life.delayTime >= particle.life.delay) {
15
+ justSpawned = true;
16
+ particle.spawning = false;
17
+ life.delayTime = noTime;
18
+ life.time = noTime;
19
+ }
20
+ else {
21
+ return;
22
+ }
23
+ }
24
+ if (life.duration === infiniteValue) {
25
+ return;
26
+ }
27
+ if (particle.spawning) {
28
+ return;
29
+ }
30
+ if (justSpawned) {
31
+ life.time = noTime;
32
+ }
33
+ else {
34
+ life.time += delta.value;
35
+ }
36
+ if (life.time < life.duration) {
37
+ return;
38
+ }
39
+ life.time = noTime;
40
+ if (particle.life.count > noLife) {
41
+ particle.life.count--;
42
+ }
43
+ if (particle.life.count === noLife) {
44
+ particle.destroy();
45
+ return;
46
+ }
47
+ const widthRange = (0, engine_1.setRangeValue)(minCanvasSize, canvasSize.width), heightRange = (0, engine_1.setRangeValue)(minCanvasSize, canvasSize.width);
48
+ particle.position.x = (0, engine_1.randomInRange)(widthRange);
49
+ particle.position.y = (0, engine_1.randomInRange)(heightRange);
50
+ particle.spawning = true;
51
+ life.delayTime = noTime;
52
+ life.time = noTime;
53
+ particle.reset();
54
+ const lifeOptions = particle.options.life;
55
+ if (lifeOptions) {
56
+ life.delay = (0, engine_1.getRangeValue)(lifeOptions.delay.value) * engine_1.millisecondsToSeconds;
57
+ life.duration = (0, engine_1.getRangeValue)(lifeOptions.duration.value) * engine_1.millisecondsToSeconds;
58
+ }
59
+ }
60
+ exports.updateLife = updateLife;
package/cjs/index.js CHANGED
@@ -1,8 +1,33 @@
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.loadLifeUpdater = void 0;
4
- const LifeUpdater_js_1 = require("./LifeUpdater.js");
5
27
  async function loadLifeUpdater(engine, refresh = true) {
6
- await engine.addParticleUpdater("life", (container) => new LifeUpdater_js_1.LifeUpdater(container), refresh);
28
+ await engine.addParticleUpdater("life", async (container) => {
29
+ const { LifeUpdater } = await Promise.resolve().then(() => __importStar(require("./LifeUpdater.js")));
30
+ return new LifeUpdater(container);
31
+ }, refresh);
7
32
  }
8
33
  exports.loadLifeUpdater = loadLifeUpdater;
@@ -0,0 +1,60 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.2.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_updater_life"] = this["webpackChunk_tsparticles_updater_life"] || []).push([["dist_browser_LifeUpdater_js"],{
19
+
20
+ /***/ "./dist/browser/LifeUpdater.js":
21
+ /*!*************************************!*\
22
+ !*** ./dist/browser/LifeUpdater.js ***!
23
+ \*************************************/
24
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25
+
26
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ LifeUpdater: () => (/* binding */ LifeUpdater)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _Options_Classes_Life_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Life.js */ \"./dist/browser/Options/Classes/Life.js\");\n\n\nconst noTime = 0,\n identity = 1,\n infiniteValue = -1;\nclass LifeUpdater {\n constructor(container) {\n this.container = container;\n }\n async init(particle) {\n const container = this.container,\n particlesOptions = particle.options,\n lifeOptions = particlesOptions.life;\n if (!lifeOptions) {\n return;\n }\n particle.life = {\n delay: container.retina.reduceFactor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(lifeOptions.delay.value) * (lifeOptions.delay.sync ? identity : (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)()) / container.retina.reduceFactor * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds : noTime,\n delayTime: noTime,\n duration: container.retina.reduceFactor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(lifeOptions.duration.value) * (lifeOptions.duration.sync ? identity : (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)()) / container.retina.reduceFactor * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds : noTime,\n time: noTime,\n count: lifeOptions.count\n };\n if (particle.life.duration <= noTime) {\n particle.life.duration = infiniteValue;\n }\n if (particle.life.count <= noTime) {\n particle.life.count = infiniteValue;\n }\n if (particle.life) {\n particle.spawning = particle.life.delay > noTime;\n }\n await Promise.resolve();\n }\n isEnabled(particle) {\n return !particle.destroyed;\n }\n loadOptions(options, ...sources) {\n if (!options.life) {\n options.life = new _Options_Classes_Life_js__WEBPACK_IMPORTED_MODULE_1__.Life();\n }\n for (const source of sources) {\n options.life.load(source?.life);\n }\n }\n async update(particle, delta) {\n if (!this.isEnabled(particle) || !particle.life) {\n return;\n }\n const {\n updateLife\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_Utils_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./Utils.js */ \"./dist/browser/Utils.js\"));\n updateLife(particle, delta, this.container.canvas.size);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-life/./dist/browser/LifeUpdater.js?");
27
+
28
+ /***/ }),
29
+
30
+ /***/ "./dist/browser/Options/Classes/Life.js":
31
+ /*!**********************************************!*\
32
+ !*** ./dist/browser/Options/Classes/Life.js ***!
33
+ \**********************************************/
34
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
35
+
36
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Life: () => (/* binding */ Life)\n/* harmony export */ });\n/* harmony import */ var _LifeDelay_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./LifeDelay.js */ \"./dist/browser/Options/Classes/LifeDelay.js\");\n/* harmony import */ var _LifeDuration_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./LifeDuration.js */ \"./dist/browser/Options/Classes/LifeDuration.js\");\n\n\nclass Life {\n constructor() {\n this.count = 0;\n this.delay = new _LifeDelay_js__WEBPACK_IMPORTED_MODULE_0__.LifeDelay();\n this.duration = new _LifeDuration_js__WEBPACK_IMPORTED_MODULE_1__.LifeDuration();\n }\n load(data) {\n if (!data) {\n return;\n }\n if (data.count !== undefined) {\n this.count = data.count;\n }\n this.delay.load(data.delay);\n this.duration.load(data.duration);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-life/./dist/browser/Options/Classes/Life.js?");
37
+
38
+ /***/ }),
39
+
40
+ /***/ "./dist/browser/Options/Classes/LifeDelay.js":
41
+ /*!***************************************************!*\
42
+ !*** ./dist/browser/Options/Classes/LifeDelay.js ***!
43
+ \***************************************************/
44
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
45
+
46
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ LifeDelay: () => (/* binding */ LifeDelay)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass LifeDelay extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ValueWithRandom {\n constructor() {\n super();\n this.sync = false;\n }\n load(data) {\n if (!data) {\n return;\n }\n super.load(data);\n if (data.sync !== undefined) {\n this.sync = data.sync;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-life/./dist/browser/Options/Classes/LifeDelay.js?");
47
+
48
+ /***/ }),
49
+
50
+ /***/ "./dist/browser/Options/Classes/LifeDuration.js":
51
+ /*!******************************************************!*\
52
+ !*** ./dist/browser/Options/Classes/LifeDuration.js ***!
53
+ \******************************************************/
54
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
55
+
56
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ LifeDuration: () => (/* binding */ LifeDuration)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass LifeDuration extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ValueWithRandom {\n constructor() {\n super();\n this.sync = false;\n }\n load(data) {\n if (!data) {\n return;\n }\n super.load(data);\n if (data.sync !== undefined) {\n this.sync = data.sync;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-life/./dist/browser/Options/Classes/LifeDuration.js?");
57
+
58
+ /***/ })
59
+
60
+ }]);
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.2.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_updater_life"] = this["webpackChunk_tsparticles_updater_life"] || []).push([["dist_browser_Utils_js"],{
19
+
20
+ /***/ "./dist/browser/Utils.js":
21
+ /*!*******************************!*\
22
+ !*** ./dist/browser/Utils.js ***!
23
+ \*******************************/
24
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25
+
26
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ updateLife: () => (/* binding */ updateLife)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nconst noTime = 0,\n infiniteValue = -1,\n noLife = 0,\n minCanvasSize = 0;\nfunction updateLife(particle, delta, canvasSize) {\n if (!particle.life) {\n return;\n }\n const life = particle.life;\n let justSpawned = false;\n if (particle.spawning) {\n life.delayTime += delta.value;\n if (life.delayTime >= particle.life.delay) {\n justSpawned = true;\n particle.spawning = false;\n life.delayTime = noTime;\n life.time = noTime;\n } else {\n return;\n }\n }\n if (life.duration === infiniteValue) {\n return;\n }\n if (particle.spawning) {\n return;\n }\n if (justSpawned) {\n life.time = noTime;\n } else {\n life.time += delta.value;\n }\n if (life.time < life.duration) {\n return;\n }\n life.time = noTime;\n if (particle.life.count > noLife) {\n particle.life.count--;\n }\n if (particle.life.count === noLife) {\n particle.destroy();\n return;\n }\n const widthRange = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(minCanvasSize, canvasSize.width),\n heightRange = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(minCanvasSize, canvasSize.width);\n particle.position.x = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.randomInRange)(widthRange);\n particle.position.y = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.randomInRange)(heightRange);\n particle.spawning = true;\n life.delayTime = noTime;\n life.time = noTime;\n particle.reset();\n const lifeOptions = particle.options.life;\n if (lifeOptions) {\n life.delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(lifeOptions.delay.value) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds;\n life.duration = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(lifeOptions.duration.value) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-life/./dist/browser/Utils.js?");
27
+
28
+ /***/ })
29
+
30
+ }]);
@@ -1,11 +1,11 @@
1
- import { getRandom, getRangeValue, millisecondsToSeconds, randomInRange, setRangeValue, } from "@tsparticles/engine";
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, noLife = 0, minCanvasSize = 0;
3
+ const noTime = 0, identity = 1, infiniteValue = -1;
4
4
  export class LifeUpdater {
5
5
  constructor(container) {
6
6
  this.container = container;
7
7
  }
8
- init(particle) {
8
+ async init(particle) {
9
9
  const container = this.container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
10
10
  if (!lifeOptions) {
11
11
  return;
@@ -34,6 +34,7 @@ export class LifeUpdater {
34
34
  if (particle.life) {
35
35
  particle.spawning = particle.life.delay > noTime;
36
36
  }
37
+ await Promise.resolve();
37
38
  }
38
39
  isEnabled(particle) {
39
40
  return !particle.destroyed;
@@ -46,58 +47,11 @@ export class LifeUpdater {
46
47
  options.life.load(source?.life);
47
48
  }
48
49
  }
49
- update(particle, delta) {
50
+ async update(particle, delta) {
50
51
  if (!this.isEnabled(particle) || !particle.life) {
51
52
  return;
52
53
  }
53
- const life = particle.life;
54
- let justSpawned = false;
55
- if (particle.spawning) {
56
- life.delayTime += delta.value;
57
- if (life.delayTime >= particle.life.delay) {
58
- justSpawned = true;
59
- particle.spawning = false;
60
- life.delayTime = noTime;
61
- life.time = noTime;
62
- }
63
- else {
64
- return;
65
- }
66
- }
67
- if (life.duration === infiniteValue) {
68
- return;
69
- }
70
- if (particle.spawning) {
71
- return;
72
- }
73
- if (justSpawned) {
74
- life.time = noTime;
75
- }
76
- else {
77
- life.time += delta.value;
78
- }
79
- if (life.time < life.duration) {
80
- return;
81
- }
82
- life.time = noTime;
83
- if (particle.life.count > noLife) {
84
- particle.life.count--;
85
- }
86
- if (particle.life.count === noLife) {
87
- particle.destroy();
88
- return;
89
- }
90
- const canvasSize = this.container.canvas.size, widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.width);
91
- particle.position.x = randomInRange(widthRange);
92
- particle.position.y = randomInRange(heightRange);
93
- particle.spawning = true;
94
- life.delayTime = noTime;
95
- life.time = noTime;
96
- particle.reset();
97
- const lifeOptions = particle.options.life;
98
- if (lifeOptions) {
99
- life.delay = getRangeValue(lifeOptions.delay.value) * millisecondsToSeconds;
100
- life.duration = getRangeValue(lifeOptions.duration.value) * millisecondsToSeconds;
101
- }
54
+ const { updateLife } = await import("./Utils.js");
55
+ updateLife(particle, delta, this.container.canvas.size);
102
56
  }
103
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) => new LifeUpdater(container), refresh);
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.1.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.1.0"
90
+ "@tsparticles/engine": "^3.2.0"
91
91
  },
92
92
  "publishConfig": {
93
93
  "access": "public"