@tsparticles/updater-life 3.9.0 → 4.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/85.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 85.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_life=this.webpackChunk_tsparticles_updater_life||[]).push([[85],{85(e,i,t){t.d(i,{LifeUpdater:()=>l});var n=t(303);class a extends n.ValueWithRandom{constructor(){super(),this.sync=!1}load(e){(0,n.isNull)(e)||(super.load(e),void 0!==e.sync&&(this.sync=e.sync))}}class o extends n.ValueWithRandom{constructor(){super(),this.sync=!1}load(e){(0,n.isNull)(e)||(super.load(e),void 0!==e.sync&&(this.sync=e.sync))}}class s{constructor(){this.count=0,this.delay=new a,this.duration=new o}load(e){(0,n.isNull)(e)||(void 0!==e.count&&(this.count=e.count),this.delay.load(e.delay),this.duration.load(e.duration))}}class l{constructor(e){this.container=e}init(e){const i=this.container,t=e.options.life;t&&(e.life={delay:i.retina.reduceFactor?(0,n.getRangeValue)(t.delay.value)*(t.delay.sync?1:(0,n.getRandom)())/i.retina.reduceFactor*n.millisecondsToSeconds:0,delayTime:0,duration:i.retina.reduceFactor?(0,n.getRangeValue)(t.duration.value)*(t.duration.sync?1:(0,n.getRandom)())/i.retina.reduceFactor*n.millisecondsToSeconds:0,time:0,count:t.count},e.life.duration<=0&&(e.life.duration=-1),e.life.count<=0&&(e.life.count=-1),e.spawning=e.life.delay>0)}isEnabled(e){return!e.destroyed}loadOptions(e,...i){e.life??=new s;for(const t of i)e.life.load(t?.life)}update(e,i){this.isEnabled(e)&&e.life&&function(e,i,t){if(!e.life)return;const a=e.life;let o=!1;if(e.spawning){if(a.delayTime+=i.value,!(a.delayTime>=e.life.delay))return;o=!0,e.spawning=!1,a.delayTime=0,a.time=0}if(-1===a.duration)return;if(o?a.time=0:a.time+=i.value,a.time<a.duration)return;if(a.time=0,e.life.count>0&&e.life.count--,0===e.life.count)return void e.destroy();const s=(0,n.setRangeValue)(0,t.width),l=(0,n.setRangeValue)(0,t.width);e.position.x=(0,n.randomInRangeValue)(s),e.position.y=(0,n.randomInRangeValue)(l),e.spawning=!0,a.delayTime=0,a.time=0,e.reset();const d=e.options.life;d&&(a.delay=(0,n.getRangeValue)(d.delay.value)*n.millisecondsToSeconds,a.duration=(0,n.getRangeValue)(d.duration.value)*n.millisecondsToSeconds)}(e,i,this.container.canvas.size)}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Life Updater v4.0.0-alpha.0 by Matteo Bruni */
@@ -32,17 +32,13 @@ export class LifeUpdater {
32
32
  if (particle.life.count <= noTime) {
33
33
  particle.life.count = infiniteValue;
34
34
  }
35
- if (particle.life) {
36
- particle.spawning = particle.life.delay > noTime;
37
- }
35
+ particle.spawning = particle.life.delay > noTime;
38
36
  }
39
37
  isEnabled(particle) {
40
38
  return !particle.destroyed;
41
39
  }
42
40
  loadOptions(options, ...sources) {
43
- if (!options.life) {
44
- options.life = new Life();
45
- }
41
+ options.life ??= new Life();
46
42
  for (const source of sources) {
47
43
  options.life.load(source?.life);
48
44
  }
package/browser/Utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getRangeValue, millisecondsToSeconds, randomInRange, setRangeValue, } from "@tsparticles/engine";
1
+ import { getRangeValue, millisecondsToSeconds, randomInRangeValue, setRangeValue, } from "@tsparticles/engine";
2
2
  const noTime = 0, infiniteValue = -1, noLife = 0, minCanvasSize = 0;
3
3
  export function updateLife(particle, delta, canvasSize) {
4
4
  if (!particle.life) {
@@ -21,9 +21,6 @@ export function updateLife(particle, delta, canvasSize) {
21
21
  if (life.duration === infiniteValue) {
22
22
  return;
23
23
  }
24
- if (particle.spawning) {
25
- return;
26
- }
27
24
  if (justSpawned) {
28
25
  life.time = noTime;
29
26
  }
@@ -42,8 +39,8 @@ export function updateLife(particle, delta, canvasSize) {
42
39
  return;
43
40
  }
44
41
  const widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.width);
45
- particle.position.x = randomInRange(widthRange);
46
- particle.position.y = randomInRange(heightRange);
42
+ particle.position.x = randomInRangeValue(widthRange);
43
+ particle.position.y = randomInRangeValue(heightRange);
47
44
  particle.spawning = true;
48
45
  life.delayTime = noTime;
49
46
  life.time = noTime;
package/browser/index.js CHANGED
@@ -1,7 +1,9 @@
1
- import { LifeUpdater } from "./LifeUpdater.js";
2
- export async function loadLifeUpdater(engine, refresh = true) {
3
- engine.checkVersion("3.9.0");
4
- await engine.addParticleUpdater("life", async (container) => {
5
- return Promise.resolve(new LifeUpdater(container));
6
- }, refresh);
1
+ export function loadLifeUpdater(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(e => {
4
+ e.addParticleUpdater("life", async (container) => {
5
+ const { LifeUpdater } = await import("./LifeUpdater.js");
6
+ return new LifeUpdater(container);
7
+ });
8
+ });
7
9
  }
@@ -1,11 +1,8 @@
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_js_1 = require("./Options/Classes/Life.js");
6
- const Utils_js_1 = require("./Utils.js");
1
+ import { getRandom, getRangeValue, millisecondsToSeconds, } from "@tsparticles/engine";
2
+ import { Life } from "./Options/Classes/Life.js";
3
+ import { updateLife } from "./Utils.js";
7
4
  const noTime = 0, identity = 1, infiniteValue = -1;
8
- class LifeUpdater {
5
+ export class LifeUpdater {
9
6
  constructor(container) {
10
7
  this.container = container;
11
8
  }
@@ -16,15 +13,15 @@ class LifeUpdater {
16
13
  }
17
14
  particle.life = {
18
15
  delay: container.retina.reduceFactor
19
- ? (((0, engine_1.getRangeValue)(lifeOptions.delay.value) * (lifeOptions.delay.sync ? identity : (0, engine_1.getRandom)())) /
16
+ ? ((getRangeValue(lifeOptions.delay.value) * (lifeOptions.delay.sync ? identity : getRandom())) /
20
17
  container.retina.reduceFactor) *
21
- engine_1.millisecondsToSeconds
18
+ millisecondsToSeconds
22
19
  : noTime,
23
20
  delayTime: noTime,
24
21
  duration: container.retina.reduceFactor
25
- ? (((0, engine_1.getRangeValue)(lifeOptions.duration.value) * (lifeOptions.duration.sync ? identity : (0, engine_1.getRandom)())) /
22
+ ? ((getRangeValue(lifeOptions.duration.value) * (lifeOptions.duration.sync ? identity : getRandom())) /
26
23
  container.retina.reduceFactor) *
27
- engine_1.millisecondsToSeconds
24
+ millisecondsToSeconds
28
25
  : noTime,
29
26
  time: noTime,
30
27
  count: lifeOptions.count,
@@ -35,17 +32,13 @@ class LifeUpdater {
35
32
  if (particle.life.count <= noTime) {
36
33
  particle.life.count = infiniteValue;
37
34
  }
38
- if (particle.life) {
39
- particle.spawning = particle.life.delay > noTime;
40
- }
35
+ particle.spawning = particle.life.delay > noTime;
41
36
  }
42
37
  isEnabled(particle) {
43
38
  return !particle.destroyed;
44
39
  }
45
40
  loadOptions(options, ...sources) {
46
- if (!options.life) {
47
- options.life = new Life_js_1.Life();
48
- }
41
+ options.life ??= new Life();
49
42
  for (const source of sources) {
50
43
  options.life.load(source?.life);
51
44
  }
@@ -54,7 +47,6 @@ class LifeUpdater {
54
47
  if (!this.isEnabled(particle) || !particle.life) {
55
48
  return;
56
49
  }
57
- (0, Utils_js_1.updateLife)(particle, delta, this.container.canvas.size);
50
+ updateLife(particle, delta, this.container.canvas.size);
58
51
  }
59
52
  }
60
- exports.LifeUpdater = LifeUpdater;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Life = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const LifeDelay_js_1 = require("./LifeDelay.js");
6
- const LifeDuration_js_1 = require("./LifeDuration.js");
7
- class Life {
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { LifeDelay } from "./LifeDelay.js";
3
+ import { LifeDuration } from "./LifeDuration.js";
4
+ export class Life {
8
5
  constructor() {
9
6
  this.count = 0;
10
- this.delay = new LifeDelay_js_1.LifeDelay();
11
- this.duration = new LifeDuration_js_1.LifeDuration();
7
+ this.delay = new LifeDelay();
8
+ this.duration = new LifeDuration();
12
9
  }
13
10
  load(data) {
14
- if ((0, engine_1.isNull)(data)) {
11
+ if (isNull(data)) {
15
12
  return;
16
13
  }
17
14
  if (data.count !== undefined) {
@@ -21,4 +18,3 @@ class Life {
21
18
  this.duration.load(data.duration);
22
19
  }
23
20
  }
24
- exports.Life = Life;
@@ -1,14 +1,11 @@
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 {
1
+ import { ValueWithRandom, isNull } from "@tsparticles/engine";
2
+ export class LifeDelay extends ValueWithRandom {
6
3
  constructor() {
7
4
  super();
8
5
  this.sync = false;
9
6
  }
10
7
  load(data) {
11
- if ((0, engine_1.isNull)(data)) {
8
+ if (isNull(data)) {
12
9
  return;
13
10
  }
14
11
  super.load(data);
@@ -17,4 +14,3 @@ class LifeDelay extends engine_1.ValueWithRandom {
17
14
  }
18
15
  }
19
16
  }
20
- exports.LifeDelay = LifeDelay;
@@ -1,14 +1,11 @@
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 {
1
+ import { ValueWithRandom, isNull } from "@tsparticles/engine";
2
+ export class LifeDuration extends ValueWithRandom {
6
3
  constructor() {
7
4
  super();
8
5
  this.sync = false;
9
6
  }
10
7
  load(data) {
11
- if ((0, engine_1.isNull)(data)) {
8
+ if (isNull(data)) {
12
9
  return;
13
10
  }
14
11
  super.load(data);
@@ -17,4 +14,3 @@ class LifeDuration extends engine_1.ValueWithRandom {
17
14
  }
18
15
  }
19
16
  }
20
- exports.LifeDuration = LifeDuration;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/Types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/Utils.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateLife = updateLife;
4
- const engine_1 = require("@tsparticles/engine");
1
+ import { getRangeValue, millisecondsToSeconds, randomInRangeValue, setRangeValue, } from "@tsparticles/engine";
5
2
  const noTime = 0, infiniteValue = -1, noLife = 0, minCanvasSize = 0;
6
- function updateLife(particle, delta, canvasSize) {
3
+ export function updateLife(particle, delta, canvasSize) {
7
4
  if (!particle.life) {
8
5
  return;
9
6
  }
@@ -24,9 +21,6 @@ function updateLife(particle, delta, canvasSize) {
24
21
  if (life.duration === infiniteValue) {
25
22
  return;
26
23
  }
27
- if (particle.spawning) {
28
- return;
29
- }
30
24
  if (justSpawned) {
31
25
  life.time = noTime;
32
26
  }
@@ -44,16 +38,16 @@ function updateLife(particle, delta, canvasSize) {
44
38
  particle.destroy();
45
39
  return;
46
40
  }
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);
41
+ const widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.width);
42
+ particle.position.x = randomInRangeValue(widthRange);
43
+ particle.position.y = randomInRangeValue(heightRange);
50
44
  particle.spawning = true;
51
45
  life.delayTime = noTime;
52
46
  life.time = noTime;
53
47
  particle.reset();
54
48
  const lifeOptions = particle.options.life;
55
49
  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;
50
+ life.delay = getRangeValue(lifeOptions.delay.value) * millisecondsToSeconds;
51
+ life.duration = getRangeValue(lifeOptions.duration.value) * millisecondsToSeconds;
58
52
  }
59
53
  }
package/cjs/index.js CHANGED
@@ -1,10 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadLifeUpdater = loadLifeUpdater;
4
- const LifeUpdater_js_1 = require("./LifeUpdater.js");
5
- async function loadLifeUpdater(engine, refresh = true) {
6
- engine.checkVersion("3.9.0");
7
- await engine.addParticleUpdater("life", async (container) => {
8
- return Promise.resolve(new LifeUpdater_js_1.LifeUpdater(container));
9
- }, refresh);
1
+ export function loadLifeUpdater(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(e => {
4
+ e.addParticleUpdater("life", async (container) => {
5
+ const { LifeUpdater } = await import("./LifeUpdater.js");
6
+ return new LifeUpdater(container);
7
+ });
8
+ });
10
9
  }
@@ -0,0 +1,70 @@
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
+ * v4.0.0-alpha.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___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 _Options_Classes_Life_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Life.js */ \"./dist/browser/Options/Classes/Life.js\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\n\nconst noTime = 0,\n identity = 1,\n infiniteValue = -1;\nclass LifeUpdater {\n constructor(container) {\n this.container = container;\n }\n 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 particle.spawning = particle.life.delay > noTime;\n }\n isEnabled(particle) {\n return !particle.destroyed;\n }\n loadOptions(options, ...sources) {\n options.life ??= new _Options_Classes_Life_js__WEBPACK_IMPORTED_MODULE_1__.Life();\n for (const source of sources) {\n options.life.load(source?.life);\n }\n }\n update(particle, delta) {\n if (!this.isEnabled(particle) || !particle.life) {\n return;\n }\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_2__.updateLife)(particle, delta, this.container.canvas.size);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-life/./dist/browser/LifeUpdater.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/Options/Classes/Life.js"
31
+ /*!**********************************************!*\
32
+ !*** ./dist/browser/Options/Classes/Life.js ***!
33
+ \**********************************************/
34
+ (__unused_webpack___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 _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _LifeDelay_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./LifeDelay.js */ \"./dist/browser/Options/Classes/LifeDelay.js\");\n/* harmony import */ var _LifeDuration_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./LifeDuration.js */ \"./dist/browser/Options/Classes/LifeDuration.js\");\n\n\n\nclass Life {\n constructor() {\n this.count = 0;\n this.delay = new _LifeDelay_js__WEBPACK_IMPORTED_MODULE_1__.LifeDelay();\n this.duration = new _LifeDuration_js__WEBPACK_IMPORTED_MODULE_2__.LifeDuration();\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(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?\n}");
37
+
38
+ /***/ },
39
+
40
+ /***/ "./dist/browser/Options/Classes/LifeDelay.js"
41
+ /*!***************************************************!*\
42
+ !*** ./dist/browser/Options/Classes/LifeDelay.js ***!
43
+ \***************************************************/
44
+ (__unused_webpack___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\nclass LifeDelay extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ValueWithRandom {\n constructor() {\n super();\n this.sync = false;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(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?\n}");
47
+
48
+ /***/ },
49
+
50
+ /***/ "./dist/browser/Options/Classes/LifeDuration.js"
51
+ /*!******************************************************!*\
52
+ !*** ./dist/browser/Options/Classes/LifeDuration.js ***!
53
+ \******************************************************/
54
+ (__unused_webpack___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\nclass LifeDuration extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ValueWithRandom {\n constructor() {\n super();\n this.sync = false;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(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?\n}");
57
+
58
+ /***/ },
59
+
60
+ /***/ "./dist/browser/Utils.js"
61
+ /*!*******************************!*\
62
+ !*** ./dist/browser/Utils.js ***!
63
+ \*******************************/
64
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
65
+
66
+ 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\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 (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__.randomInRangeValue)(widthRange);\n particle.position.y = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.randomInRangeValue)(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?\n}");
67
+
68
+ /***/ }
69
+
70
+ }]);
@@ -32,17 +32,13 @@ export class LifeUpdater {
32
32
  if (particle.life.count <= noTime) {
33
33
  particle.life.count = infiniteValue;
34
34
  }
35
- if (particle.life) {
36
- particle.spawning = particle.life.delay > noTime;
37
- }
35
+ particle.spawning = particle.life.delay > noTime;
38
36
  }
39
37
  isEnabled(particle) {
40
38
  return !particle.destroyed;
41
39
  }
42
40
  loadOptions(options, ...sources) {
43
- if (!options.life) {
44
- options.life = new Life();
45
- }
41
+ options.life ??= new Life();
46
42
  for (const source of sources) {
47
43
  options.life.load(source?.life);
48
44
  }
package/esm/Utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getRangeValue, millisecondsToSeconds, randomInRange, setRangeValue, } from "@tsparticles/engine";
1
+ import { getRangeValue, millisecondsToSeconds, randomInRangeValue, setRangeValue, } from "@tsparticles/engine";
2
2
  const noTime = 0, infiniteValue = -1, noLife = 0, minCanvasSize = 0;
3
3
  export function updateLife(particle, delta, canvasSize) {
4
4
  if (!particle.life) {
@@ -21,9 +21,6 @@ export function updateLife(particle, delta, canvasSize) {
21
21
  if (life.duration === infiniteValue) {
22
22
  return;
23
23
  }
24
- if (particle.spawning) {
25
- return;
26
- }
27
24
  if (justSpawned) {
28
25
  life.time = noTime;
29
26
  }
@@ -42,8 +39,8 @@ export function updateLife(particle, delta, canvasSize) {
42
39
  return;
43
40
  }
44
41
  const widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.width);
45
- particle.position.x = randomInRange(widthRange);
46
- particle.position.y = randomInRange(heightRange);
42
+ particle.position.x = randomInRangeValue(widthRange);
43
+ particle.position.y = randomInRangeValue(heightRange);
47
44
  particle.spawning = true;
48
45
  life.delayTime = noTime;
49
46
  life.time = noTime;
package/esm/index.js CHANGED
@@ -1,7 +1,9 @@
1
- import { LifeUpdater } from "./LifeUpdater.js";
2
- export async function loadLifeUpdater(engine, refresh = true) {
3
- engine.checkVersion("3.9.0");
4
- await engine.addParticleUpdater("life", async (container) => {
5
- return Promise.resolve(new LifeUpdater(container));
6
- }, refresh);
1
+ export function loadLifeUpdater(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(e => {
4
+ e.addParticleUpdater("life", async (container) => {
5
+ const { LifeUpdater } = await import("./LifeUpdater.js");
6
+ return new LifeUpdater(container);
7
+ });
8
+ });
7
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/updater-life",
3
- "version": "3.9.0",
3
+ "version": "4.0.0-alpha.0",
4
4
  "description": "tsParticles particles life updater",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -87,9 +87,10 @@
87
87
  "./package.json": "./package.json"
88
88
  },
89
89
  "dependencies": {
90
- "@tsparticles/engine": "3.9.0"
90
+ "@tsparticles/engine": "4.0.0-alpha.0"
91
91
  },
92
92
  "publishConfig": {
93
93
  "access": "public"
94
- }
94
+ },
95
+ "type": "module"
95
96
  }