@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
|
@@ -0,0 +1,261 @@
|
|
|
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.0.0-alpha.0
|
|
8
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
|
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
|
20
|
+
/******/ "use strict";
|
|
21
|
+
/******/ var __webpack_modules__ = ({
|
|
22
|
+
|
|
23
|
+
/***/ 533:
|
|
24
|
+
/***/ ((module) => {
|
|
25
|
+
|
|
26
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
/******/ });
|
|
31
|
+
/************************************************************************/
|
|
32
|
+
/******/ // The module cache
|
|
33
|
+
/******/ var __webpack_module_cache__ = {};
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // The require function
|
|
36
|
+
/******/ function __webpack_require__(moduleId) {
|
|
37
|
+
/******/ // Check if module is in cache
|
|
38
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
39
|
+
/******/ if (cachedModule !== undefined) {
|
|
40
|
+
/******/ return cachedModule.exports;
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ // Create a new module (and put it into the cache)
|
|
43
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
44
|
+
/******/ // no module.id needed
|
|
45
|
+
/******/ // no module.loaded needed
|
|
46
|
+
/******/ exports: {}
|
|
47
|
+
/******/ };
|
|
48
|
+
/******/
|
|
49
|
+
/******/ // Execute the module function
|
|
50
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // Return the exports of the module
|
|
53
|
+
/******/ return module.exports;
|
|
54
|
+
/******/ }
|
|
55
|
+
/******/
|
|
56
|
+
/************************************************************************/
|
|
57
|
+
/******/ /* webpack/runtime/define property getters */
|
|
58
|
+
/******/ (() => {
|
|
59
|
+
/******/ // define getter functions for harmony exports
|
|
60
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
61
|
+
/******/ for(var key in definition) {
|
|
62
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
63
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
64
|
+
/******/ }
|
|
65
|
+
/******/ }
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/ })();
|
|
68
|
+
/******/
|
|
69
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
70
|
+
/******/ (() => {
|
|
71
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
72
|
+
/******/ })();
|
|
73
|
+
/******/
|
|
74
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
75
|
+
/******/ (() => {
|
|
76
|
+
/******/ // define __esModule on exports
|
|
77
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
78
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
79
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
80
|
+
/******/ }
|
|
81
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
82
|
+
/******/ };
|
|
83
|
+
/******/ })();
|
|
84
|
+
/******/
|
|
85
|
+
/************************************************************************/
|
|
86
|
+
var __webpack_exports__ = {};
|
|
87
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
88
|
+
(() => {
|
|
89
|
+
// ESM COMPAT FLAG
|
|
90
|
+
__webpack_require__.r(__webpack_exports__);
|
|
91
|
+
|
|
92
|
+
// EXPORTS
|
|
93
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
+
"loadLifeUpdater": () => (/* binding */ loadLifeUpdater)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
98
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
99
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/LifeDelay.js
|
|
100
|
+
|
|
101
|
+
class LifeDelay extends engine_root_window_.ValueWithRandom {
|
|
102
|
+
constructor() {
|
|
103
|
+
super();
|
|
104
|
+
this.sync = false;
|
|
105
|
+
}
|
|
106
|
+
load(data) {
|
|
107
|
+
if (!data) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
super.load(data);
|
|
111
|
+
if (data.sync !== undefined) {
|
|
112
|
+
this.sync = data.sync;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/LifeDuration.js
|
|
117
|
+
|
|
118
|
+
class LifeDuration extends engine_root_window_.ValueWithRandom {
|
|
119
|
+
constructor() {
|
|
120
|
+
super();
|
|
121
|
+
this.random.minimumValue = 0.0001;
|
|
122
|
+
this.sync = false;
|
|
123
|
+
}
|
|
124
|
+
load(data) {
|
|
125
|
+
if (!data) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
super.load(data);
|
|
129
|
+
if (data.sync !== undefined) {
|
|
130
|
+
this.sync = data.sync;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Life.js
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class Life {
|
|
138
|
+
constructor() {
|
|
139
|
+
this.count = 0;
|
|
140
|
+
this.delay = new LifeDelay();
|
|
141
|
+
this.duration = new LifeDuration();
|
|
142
|
+
}
|
|
143
|
+
load(data) {
|
|
144
|
+
if (!data) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (data.count !== undefined) {
|
|
148
|
+
this.count = data.count;
|
|
149
|
+
}
|
|
150
|
+
this.delay.load(data.delay);
|
|
151
|
+
this.duration.load(data.duration);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
;// CONCATENATED MODULE: ./dist/browser/LifeUpdater.js
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class LifeUpdater {
|
|
158
|
+
constructor(container) {
|
|
159
|
+
this.container = container;
|
|
160
|
+
}
|
|
161
|
+
init(particle) {
|
|
162
|
+
const container = this.container,
|
|
163
|
+
particlesOptions = particle.options,
|
|
164
|
+
lifeOptions = particlesOptions.life;
|
|
165
|
+
if (!lifeOptions) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
particle.life = {
|
|
169
|
+
delay: container.retina.reduceFactor ? (0,engine_root_window_.getRangeValue)(lifeOptions.delay.value) * (lifeOptions.delay.sync ? 1 : (0,engine_root_window_.getRandom)()) / container.retina.reduceFactor * 1000 : 0,
|
|
170
|
+
delayTime: 0,
|
|
171
|
+
duration: container.retina.reduceFactor ? (0,engine_root_window_.getRangeValue)(lifeOptions.duration.value) * (lifeOptions.duration.sync ? 1 : (0,engine_root_window_.getRandom)()) / container.retina.reduceFactor * 1000 : 0,
|
|
172
|
+
time: 0,
|
|
173
|
+
count: lifeOptions.count
|
|
174
|
+
};
|
|
175
|
+
if (particle.life.duration <= 0) {
|
|
176
|
+
particle.life.duration = -1;
|
|
177
|
+
}
|
|
178
|
+
if (particle.life.count <= 0) {
|
|
179
|
+
particle.life.count = -1;
|
|
180
|
+
}
|
|
181
|
+
if (particle.life) {
|
|
182
|
+
particle.spawning = particle.life.delay > 0;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
isEnabled(particle) {
|
|
186
|
+
return !particle.destroyed;
|
|
187
|
+
}
|
|
188
|
+
loadOptions(options, ...sources) {
|
|
189
|
+
if (!options.life) {
|
|
190
|
+
options.life = new Life();
|
|
191
|
+
}
|
|
192
|
+
for (const source of sources) {
|
|
193
|
+
options.life.load(source === null || source === void 0 ? void 0 : source.life);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
update(particle, delta) {
|
|
197
|
+
if (!this.isEnabled(particle) || !particle.life) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const life = particle.life;
|
|
201
|
+
let justSpawned = false;
|
|
202
|
+
if (particle.spawning) {
|
|
203
|
+
life.delayTime += delta.value;
|
|
204
|
+
if (life.delayTime >= particle.life.delay) {
|
|
205
|
+
justSpawned = true;
|
|
206
|
+
particle.spawning = false;
|
|
207
|
+
life.delayTime = 0;
|
|
208
|
+
life.time = 0;
|
|
209
|
+
} else {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (life.duration === -1) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (particle.spawning) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (justSpawned) {
|
|
220
|
+
life.time = 0;
|
|
221
|
+
} else {
|
|
222
|
+
life.time += delta.value;
|
|
223
|
+
}
|
|
224
|
+
if (life.time < life.duration) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
life.time = 0;
|
|
228
|
+
if (particle.life.count > 0) {
|
|
229
|
+
particle.life.count--;
|
|
230
|
+
}
|
|
231
|
+
if (particle.life.count === 0) {
|
|
232
|
+
particle.destroy();
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const canvasSize = this.container.canvas.size,
|
|
236
|
+
widthRange = (0,engine_root_window_.setRangeValue)(0, canvasSize.width),
|
|
237
|
+
heightRange = (0,engine_root_window_.setRangeValue)(0, canvasSize.width);
|
|
238
|
+
particle.position.x = (0,engine_root_window_.randomInRange)(widthRange);
|
|
239
|
+
particle.position.y = (0,engine_root_window_.randomInRange)(heightRange);
|
|
240
|
+
particle.spawning = true;
|
|
241
|
+
life.delayTime = 0;
|
|
242
|
+
life.time = 0;
|
|
243
|
+
particle.reset();
|
|
244
|
+
const lifeOptions = particle.options.life;
|
|
245
|
+
if (lifeOptions) {
|
|
246
|
+
life.delay = (0,engine_root_window_.getRangeValue)(lifeOptions.delay.value) * 1000;
|
|
247
|
+
life.duration = (0,engine_root_window_.getRangeValue)(lifeOptions.duration.value) * 1000;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
252
|
+
|
|
253
|
+
async function loadLifeUpdater(engine) {
|
|
254
|
+
await engine.addParticleUpdater("life", container => new LifeUpdater(container));
|
|
255
|
+
}
|
|
256
|
+
})();
|
|
257
|
+
|
|
258
|
+
/******/ return __webpack_exports__;
|
|
259
|
+
/******/ })()
|
|
260
|
+
;
|
|
261
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.updater.life.min.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var n="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},n={};function i(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,i),a.exports}i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{i.r(o),i.d(o,{loadLifeUpdater:()=>s});var e=i(533);class t extends e.ValueWithRandom{constructor(){super(),this.sync=!1}load(e){e&&(super.load(e),void 0!==e.sync&&(this.sync=e.sync))}}class n extends e.ValueWithRandom{constructor(){super(),this.random.minimumValue=1e-4,this.sync=!1}load(e){e&&(super.load(e),void 0!==e.sync&&(this.sync=e.sync))}}class a{constructor(){this.count=0,this.delay=new t,this.duration=new n}load(e){e&&(void 0!==e.count&&(this.count=e.count),this.delay.load(e.delay),this.duration.load(e.duration))}}class r{constructor(e){this.container=e}init(t){const n=this.container,i=t.options.life;i&&(t.life={delay:n.retina.reduceFactor?(0,e.getRangeValue)(i.delay.value)*(i.delay.sync?1:(0,e.getRandom)())/n.retina.reduceFactor*1e3:0,delayTime:0,duration:n.retina.reduceFactor?(0,e.getRangeValue)(i.duration.value)*(i.duration.sync?1:(0,e.getRandom)())/n.retina.reduceFactor*1e3:0,time:0,count:i.count},t.life.duration<=0&&(t.life.duration=-1),t.life.count<=0&&(t.life.count=-1),t.life&&(t.spawning=t.life.delay>0))}isEnabled(e){return!e.destroyed}loadOptions(e,...t){e.life||(e.life=new a);for(const n of t)e.life.load(null==n?void 0:n.life)}update(t,n){if(!this.isEnabled(t)||!t.life)return;const i=t.life;let o=!1;if(t.spawning){if(i.delayTime+=n.value,!(i.delayTime>=t.life.delay))return;o=!0,t.spawning=!1,i.delayTime=0,i.time=0}if(-1===i.duration)return;if(t.spawning)return;if(o?i.time=0:i.time+=n.value,i.time<i.duration)return;if(i.time=0,t.life.count>0&&t.life.count--,0===t.life.count)return void t.destroy();const a=this.container.canvas.size,r=(0,e.setRangeValue)(0,a.width),s=(0,e.setRangeValue)(0,a.width);t.position.x=(0,e.randomInRange)(r),t.position.y=(0,e.randomInRange)(s),t.spawning=!0,i.delayTime=0,i.time=0,t.reset();const l=t.options.life;l&&(i.delay=1e3*(0,e.getRangeValue)(l.delay.value),i.duration=1e3*(0,e.getRangeValue)(l.duration.value))}}async function s(e){await e.addParticleUpdater("life",(e=>new r(e)))}})(),o})()));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Container, IDelta, IParticleUpdater, IParticlesOptions, Particle, ParticlesOptions, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ILife } from "./Options/Interfaces/ILife";
|
|
3
|
+
import { Life } from "./Options/Classes/Life";
|
|
4
|
+
interface IParticleLife {
|
|
5
|
+
count: number;
|
|
6
|
+
delay: number;
|
|
7
|
+
delayTime: number;
|
|
8
|
+
duration: number;
|
|
9
|
+
time: number;
|
|
10
|
+
}
|
|
11
|
+
type ILifeParticlesOptions = IParticlesOptions & {
|
|
12
|
+
life?: ILife;
|
|
13
|
+
};
|
|
14
|
+
type LifeParticlesOptions = ParticlesOptions & {
|
|
15
|
+
life?: Life;
|
|
16
|
+
};
|
|
17
|
+
type LifeParticle = Particle & {
|
|
18
|
+
life?: IParticleLife;
|
|
19
|
+
options: LifeParticlesOptions;
|
|
20
|
+
};
|
|
21
|
+
export declare class LifeUpdater implements IParticleUpdater {
|
|
22
|
+
private readonly container;
|
|
23
|
+
constructor(container: Container);
|
|
24
|
+
init(particle: LifeParticle): void;
|
|
25
|
+
isEnabled(particle: Particle): boolean;
|
|
26
|
+
loadOptions(options: LifeParticlesOptions, ...sources: (RecursivePartial<ILifeParticlesOptions> | undefined)[]): void;
|
|
27
|
+
update(particle: LifeParticle, delta: IDelta): void;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ILife } from "../Interfaces/ILife";
|
|
3
|
+
import { LifeDelay } from "./LifeDelay";
|
|
4
|
+
import { LifeDuration } from "./LifeDuration";
|
|
5
|
+
export declare class Life implements ILife, IOptionLoader<ILife> {
|
|
6
|
+
count: number;
|
|
7
|
+
delay: LifeDelay;
|
|
8
|
+
duration: LifeDuration;
|
|
9
|
+
constructor();
|
|
10
|
+
load(data?: RecursivePartial<ILife>): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ILifeDelay } from "../Interfaces/ILifeDelay";
|
|
3
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
4
|
+
export declare class LifeDelay extends ValueWithRandom implements ILifeDelay, IOptionLoader<ILifeDelay> {
|
|
5
|
+
sync: boolean;
|
|
6
|
+
constructor();
|
|
7
|
+
load(data?: RecursivePartial<ILifeDelay>): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ILifeDuration } from "../Interfaces/ILifeDuration";
|
|
3
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
4
|
+
export declare class LifeDuration extends ValueWithRandom implements ILifeDuration, IOptionLoader<ILifeDuration> {
|
|
5
|
+
sync: boolean;
|
|
6
|
+
constructor();
|
|
7
|
+
load(data?: RecursivePartial<ILifeDuration>): void;
|
|
8
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Life"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LifeUpdater = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const Life_1 = require("./Options/Classes/Life");
|
|
15
|
+
class LifeUpdater {
|
|
16
|
+
constructor(container) {
|
|
17
|
+
this.container = container;
|
|
18
|
+
}
|
|
19
|
+
init(particle) {
|
|
20
|
+
const container = this.container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
21
|
+
if (!lifeOptions) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
particle.life = {
|
|
25
|
+
delay: container.retina.reduceFactor
|
|
26
|
+
? (((0, engine_1.getRangeValue)(lifeOptions.delay.value) * (lifeOptions.delay.sync ? 1 : (0, engine_1.getRandom)())) /
|
|
27
|
+
container.retina.reduceFactor) *
|
|
28
|
+
1000
|
|
29
|
+
: 0,
|
|
30
|
+
delayTime: 0,
|
|
31
|
+
duration: container.retina.reduceFactor
|
|
32
|
+
? (((0, engine_1.getRangeValue)(lifeOptions.duration.value) * (lifeOptions.duration.sync ? 1 : (0, engine_1.getRandom)())) /
|
|
33
|
+
container.retina.reduceFactor) *
|
|
34
|
+
1000
|
|
35
|
+
: 0,
|
|
36
|
+
time: 0,
|
|
37
|
+
count: lifeOptions.count,
|
|
38
|
+
};
|
|
39
|
+
if (particle.life.duration <= 0) {
|
|
40
|
+
particle.life.duration = -1;
|
|
41
|
+
}
|
|
42
|
+
if (particle.life.count <= 0) {
|
|
43
|
+
particle.life.count = -1;
|
|
44
|
+
}
|
|
45
|
+
if (particle.life) {
|
|
46
|
+
particle.spawning = particle.life.delay > 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
isEnabled(particle) {
|
|
50
|
+
return !particle.destroyed;
|
|
51
|
+
}
|
|
52
|
+
loadOptions(options, ...sources) {
|
|
53
|
+
if (!options.life) {
|
|
54
|
+
options.life = new Life_1.Life();
|
|
55
|
+
}
|
|
56
|
+
for (const source of sources) {
|
|
57
|
+
options.life.load(source === null || source === void 0 ? void 0 : source.life);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
update(particle, delta) {
|
|
61
|
+
if (!this.isEnabled(particle) || !particle.life) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const life = particle.life;
|
|
65
|
+
let justSpawned = false;
|
|
66
|
+
if (particle.spawning) {
|
|
67
|
+
life.delayTime += delta.value;
|
|
68
|
+
if (life.delayTime >= particle.life.delay) {
|
|
69
|
+
justSpawned = true;
|
|
70
|
+
particle.spawning = false;
|
|
71
|
+
life.delayTime = 0;
|
|
72
|
+
life.time = 0;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (life.duration === -1) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (particle.spawning) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (justSpawned) {
|
|
85
|
+
life.time = 0;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
life.time += delta.value;
|
|
89
|
+
}
|
|
90
|
+
if (life.time < life.duration) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
life.time = 0;
|
|
94
|
+
if (particle.life.count > 0) {
|
|
95
|
+
particle.life.count--;
|
|
96
|
+
}
|
|
97
|
+
if (particle.life.count === 0) {
|
|
98
|
+
particle.destroy();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const canvasSize = this.container.canvas.size, widthRange = (0, engine_1.setRangeValue)(0, canvasSize.width), heightRange = (0, engine_1.setRangeValue)(0, canvasSize.width);
|
|
102
|
+
particle.position.x = (0, engine_1.randomInRange)(widthRange);
|
|
103
|
+
particle.position.y = (0, engine_1.randomInRange)(heightRange);
|
|
104
|
+
particle.spawning = true;
|
|
105
|
+
life.delayTime = 0;
|
|
106
|
+
life.time = 0;
|
|
107
|
+
particle.reset();
|
|
108
|
+
const lifeOptions = particle.options.life;
|
|
109
|
+
if (lifeOptions) {
|
|
110
|
+
life.delay = (0, engine_1.getRangeValue)(lifeOptions.delay.value) * 1000;
|
|
111
|
+
life.duration = (0, engine_1.getRangeValue)(lifeOptions.duration.value) * 1000;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.LifeUpdater = LifeUpdater;
|
|
116
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./LifeDelay", "./LifeDuration"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Life = void 0;
|
|
13
|
+
const LifeDelay_1 = require("./LifeDelay");
|
|
14
|
+
const LifeDuration_1 = require("./LifeDuration");
|
|
15
|
+
class Life {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.count = 0;
|
|
18
|
+
this.delay = new LifeDelay_1.LifeDelay();
|
|
19
|
+
this.duration = new LifeDuration_1.LifeDuration();
|
|
20
|
+
}
|
|
21
|
+
load(data) {
|
|
22
|
+
if (!data) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (data.count !== undefined) {
|
|
26
|
+
this.count = data.count;
|
|
27
|
+
}
|
|
28
|
+
this.delay.load(data.delay);
|
|
29
|
+
this.duration.load(data.duration);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Life = Life;
|
|
33
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LifeDelay = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class LifeDelay extends engine_1.ValueWithRandom {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.sync = false;
|
|
18
|
+
}
|
|
19
|
+
load(data) {
|
|
20
|
+
if (!data) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
super.load(data);
|
|
24
|
+
if (data.sync !== undefined) {
|
|
25
|
+
this.sync = data.sync;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.LifeDelay = LifeDelay;
|
|
30
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LifeDuration = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class LifeDuration extends engine_1.ValueWithRandom {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.random.minimumValue = 0.0001;
|
|
18
|
+
this.sync = false;
|
|
19
|
+
}
|
|
20
|
+
load(data) {
|
|
21
|
+
if (!data) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
super.load(data);
|
|
25
|
+
if (data.sync !== undefined) {
|
|
26
|
+
this.sync = data.sync;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.LifeDuration = LifeDuration;
|
|
31
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./LifeUpdater"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadLifeUpdater = void 0;
|
|
13
|
+
const LifeUpdater_1 = require("./LifeUpdater");
|
|
14
|
+
async function loadLifeUpdater(engine) {
|
|
15
|
+
await engine.addParticleUpdater("life", (container) => new LifeUpdater_1.LifeUpdater(container));
|
|
16
|
+
}
|
|
17
|
+
exports.loadLifeUpdater = loadLifeUpdater;
|
|
18
|
+
});
|