@tsparticles/plugin-infection 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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/Infecter.js +97 -0
  4. package/browser/InfectionInstance.js +37 -0
  5. package/browser/Options/Classes/Infection.js +35 -0
  6. package/browser/Options/Classes/InfectionStage.js +25 -0
  7. package/browser/Options/Interfaces/IInfection.js +1 -0
  8. package/browser/Options/Interfaces/IInfectionStage.js +1 -0
  9. package/browser/ParticlesInfecter.js +54 -0
  10. package/browser/Types.js +1 -0
  11. package/browser/index.js +32 -0
  12. package/cjs/Infecter.js +101 -0
  13. package/cjs/InfectionInstance.js +41 -0
  14. package/cjs/Options/Classes/Infection.js +39 -0
  15. package/cjs/Options/Classes/InfectionStage.js +29 -0
  16. package/cjs/Options/Interfaces/IInfection.js +2 -0
  17. package/cjs/Options/Interfaces/IInfectionStage.js +2 -0
  18. package/cjs/ParticlesInfecter.js +69 -0
  19. package/cjs/Types.js +2 -0
  20. package/cjs/index.js +61 -0
  21. package/esm/Infecter.js +97 -0
  22. package/esm/InfectionInstance.js +37 -0
  23. package/esm/Options/Classes/Infection.js +35 -0
  24. package/esm/Options/Classes/InfectionStage.js +25 -0
  25. package/esm/Options/Interfaces/IInfection.js +1 -0
  26. package/esm/Options/Interfaces/IInfectionStage.js +1 -0
  27. package/esm/ParticlesInfecter.js +54 -0
  28. package/esm/Types.js +1 -0
  29. package/esm/index.js +32 -0
  30. package/package.json +91 -0
  31. package/report.html +39 -0
  32. package/tsparticles.plugin.infection.js +387 -0
  33. package/tsparticles.plugin.infection.min.js +2 -0
  34. package/tsparticles.plugin.infection.min.js.LICENSE.txt +8 -0
  35. package/types/Infecter.d.ts +9 -0
  36. package/types/InfectionInstance.d.ts +9 -0
  37. package/types/Options/Classes/Infection.d.ts +12 -0
  38. package/types/Options/Classes/InfectionStage.d.ts +12 -0
  39. package/types/Options/Interfaces/IInfection.d.ts +8 -0
  40. package/types/Options/Interfaces/IInfectionStage.d.ts +8 -0
  41. package/types/ParticlesInfecter.d.ts +11 -0
  42. package/types/Types.d.ts +24 -0
  43. package/types/index.d.ts +4 -0
  44. package/umd/Infecter.js +111 -0
  45. package/umd/InfectionInstance.js +51 -0
  46. package/umd/Options/Classes/Infection.js +49 -0
  47. package/umd/Options/Classes/InfectionStage.js +39 -0
  48. package/umd/Options/Interfaces/IInfection.js +12 -0
  49. package/umd/Options/Interfaces/IInfectionStage.js +12 -0
  50. package/umd/ParticlesInfecter.js +68 -0
  51. package/umd/Types.js +12 -0
  52. package/umd/index.js +60 -0
@@ -0,0 +1,387 @@
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
+ "loadInfectionPlugin": () => (/* binding */ loadInfectionPlugin)
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/InfectionStage.js
100
+
101
+ class InfectionStage {
102
+ constructor() {
103
+ this.color = new engine_root_window_.OptionsColor();
104
+ this.color.value = "#ff0000";
105
+ this.radius = 0;
106
+ this.rate = 1;
107
+ }
108
+ load(data) {
109
+ if (data === undefined) {
110
+ return;
111
+ }
112
+ if (data.color !== undefined) {
113
+ this.color = engine_root_window_.OptionsColor.create(this.color, data.color);
114
+ }
115
+ this.duration = data.duration;
116
+ this.infectedStage = data.infectedStage;
117
+ if (data.radius !== undefined) {
118
+ this.radius = data.radius;
119
+ }
120
+ if (data.rate !== undefined) {
121
+ this.rate = data.rate;
122
+ }
123
+ }
124
+ }
125
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Infection.js
126
+
127
+ class Infection {
128
+ constructor() {
129
+ this.cure = false;
130
+ this.delay = 0;
131
+ this.enable = false;
132
+ this.infections = 0;
133
+ this.stages = [];
134
+ }
135
+ load(data) {
136
+ if (data === undefined) {
137
+ return;
138
+ }
139
+ if (data.cure !== undefined) {
140
+ this.cure = data.cure;
141
+ }
142
+ if (data.delay !== undefined) {
143
+ this.delay = data.delay;
144
+ }
145
+ if (data.enable !== undefined) {
146
+ this.enable = data.enable;
147
+ }
148
+ if (data.infections !== undefined) {
149
+ this.infections = data.infections;
150
+ }
151
+ if (data.stages === undefined) {
152
+ return;
153
+ }
154
+ this.stages = data.stages.map(t => {
155
+ const s = new InfectionStage();
156
+ s.load(t);
157
+ return s;
158
+ });
159
+ }
160
+ }
161
+ ;// CONCATENATED MODULE: ./dist/browser/Infecter.js
162
+ class Infecter {
163
+ constructor(container) {
164
+ this.container = container;
165
+ }
166
+ startInfection(particle, stage) {
167
+ const options = this.container.actualOptions;
168
+ if (!options.infection || !particle.infection) {
169
+ return;
170
+ }
171
+ const stages = options.infection.stages,
172
+ stagesCount = stages.length;
173
+ if (stage > stagesCount || stage < 0) {
174
+ return;
175
+ }
176
+ particle.infection.delay = 0;
177
+ particle.infection.delayStage = stage;
178
+ }
179
+ updateInfection(particle, delta) {
180
+ const infection = this.container.actualOptions.infection;
181
+ if (!infection || !particle.infection) {
182
+ return;
183
+ }
184
+ const stages = infection.stages,
185
+ stagesCount = stages.length;
186
+ if (particle.infection.delay !== undefined && particle.infection.delayStage !== undefined) {
187
+ const stage = particle.infection.delayStage;
188
+ if (stage > stagesCount || stage < 0) {
189
+ return;
190
+ }
191
+ if (particle.infection.delay >= infection.delay * 1000) {
192
+ particle.infection.stage = stage;
193
+ particle.infection.time = 0;
194
+ delete particle.infection.delay;
195
+ delete particle.infection.delayStage;
196
+ } else {
197
+ particle.infection.delay += delta;
198
+ }
199
+ } else {
200
+ delete particle.infection.delay;
201
+ delete particle.infection.delayStage;
202
+ }
203
+ if (particle.infection.stage !== undefined && particle.infection.time !== undefined) {
204
+ const infectionStage = stages[particle.infection.stage];
205
+ if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
206
+ if (particle.infection.time > infectionStage.duration * 1000) {
207
+ this.nextInfectionStage(particle);
208
+ } else {
209
+ particle.infection.time += delta;
210
+ }
211
+ } else {
212
+ particle.infection.time += delta;
213
+ }
214
+ } else {
215
+ delete particle.infection.stage;
216
+ delete particle.infection.time;
217
+ }
218
+ }
219
+ updateInfectionStage(particle, stage) {
220
+ const options = this.container.actualOptions;
221
+ if (!options.infection || !particle.infection) {
222
+ return;
223
+ }
224
+ const stagesCount = options.infection.stages.length;
225
+ if (stage > stagesCount || stage < 0 || particle.infection.stage !== undefined && particle.infection.stage > stage) {
226
+ return;
227
+ }
228
+ particle.infection.stage = stage;
229
+ particle.infection.time = 0;
230
+ }
231
+ nextInfectionStage(particle) {
232
+ const options = this.container.actualOptions;
233
+ if (!options.infection || !particle.infection) {
234
+ return;
235
+ }
236
+ const stagesCount = options.infection.stages.length;
237
+ if (stagesCount <= 0 || particle.infection.stage === undefined) {
238
+ return;
239
+ }
240
+ particle.infection.time = 0;
241
+ if (stagesCount <= ++particle.infection.stage) {
242
+ if (options.infection.cure) {
243
+ delete particle.infection.stage;
244
+ delete particle.infection.time;
245
+ return;
246
+ } else {
247
+ particle.infection.stage = 0;
248
+ particle.infection.time = 0;
249
+ }
250
+ }
251
+ }
252
+ }
253
+ ;// CONCATENATED MODULE: ./dist/browser/InfectionInstance.js
254
+
255
+
256
+ class InfectionInstance {
257
+ constructor(container) {
258
+ this.container = container;
259
+ this.container.infecter = new Infecter(this.container);
260
+ }
261
+ particleFillColor(particle) {
262
+ const options = this.container.actualOptions;
263
+ if (!particle.infection || !options.infection) {
264
+ return;
265
+ }
266
+ const infectionStage = particle.infection.stage,
267
+ infection = options.infection,
268
+ infectionStages = infection.stages;
269
+ return infectionStage !== undefined ? infectionStages[infectionStage].color : undefined;
270
+ }
271
+ particleStrokeColor(particle) {
272
+ return this.particleFillColor(particle);
273
+ }
274
+ particlesSetup() {
275
+ var _a;
276
+ const options = this.container.actualOptions;
277
+ if (!options.infection) {
278
+ return;
279
+ }
280
+ for (let i = 0; i < options.infection.infections; i++) {
281
+ const notInfected = this.container.particles.array.filter(p => {
282
+ const infP = p;
283
+ if (!infP.infection) {
284
+ infP.infection = {};
285
+ }
286
+ return infP.infection.stage === undefined;
287
+ });
288
+ const infected = (0,engine_root_window_.itemFromArray)(notInfected);
289
+ (_a = this.container.infecter) === null || _a === void 0 ? void 0 : _a.startInfection(infected, 0);
290
+ }
291
+ }
292
+ }
293
+ ;// CONCATENATED MODULE: ./dist/browser/ParticlesInfecter.js
294
+
295
+ class ParticlesInfecter extends engine_root_window_.ParticlesInteractorBase {
296
+ constructor(container) {
297
+ super(container);
298
+ }
299
+ clear() {}
300
+ init() {}
301
+ async interact(p1, delta) {
302
+ var _a, _b, _c, _d, _e;
303
+ const infecter = this.container.infecter;
304
+ if (!infecter) {
305
+ return;
306
+ }
307
+ infecter.updateInfection(p1, delta.value);
308
+ if (((_a = p1.infection) === null || _a === void 0 ? void 0 : _a.stage) === undefined) {
309
+ return;
310
+ }
311
+ const container = this.container,
312
+ options = container.actualOptions,
313
+ infectionOptions = options.infection;
314
+ if (!(infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.enable) || infectionOptions.stages.length < 1) {
315
+ return;
316
+ }
317
+ const infectionStage1 = infectionOptions.stages[p1.infection.stage],
318
+ pxRatio = container.retina.pixelRatio,
319
+ radius = p1.getRadius() * 2 + infectionStage1.radius * pxRatio,
320
+ pos = p1.getPosition(),
321
+ infectedStage1 = (_b = infectionStage1.infectedStage) !== null && _b !== void 0 ? _b : p1.infection.stage,
322
+ query = container.particles.quadTree.queryCircle(pos, radius),
323
+ infections = infectionStage1.rate,
324
+ neighbors = query.length;
325
+ for (const p2 of query) {
326
+ const infP2 = p2;
327
+ if (infP2 === p1 || infP2.destroyed || infP2.spawning || !(((_c = infP2.infection) === null || _c === void 0 ? void 0 : _c.stage) === undefined || infP2.infection.stage !== p1.infection.stage)) {
328
+ continue;
329
+ }
330
+ if ((0,engine_root_window_.getRandom)() < infections / neighbors) {
331
+ if (((_d = infP2.infection) === null || _d === void 0 ? void 0 : _d.stage) === undefined) {
332
+ infecter.startInfection(infP2, infectedStage1);
333
+ } else if (infP2.infection.stage < p1.infection.stage) {
334
+ infecter.updateInfectionStage(infP2, infectedStage1);
335
+ } else if (infP2.infection.stage > p1.infection.stage) {
336
+ const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
337
+ const infectedStage2 = (_e = infectionStage2 === null || infectionStage2 === void 0 ? void 0 : infectionStage2.infectedStage) !== null && _e !== void 0 ? _e : infP2.infection.stage;
338
+ infecter.updateInfectionStage(p1, infectedStage2);
339
+ }
340
+ }
341
+ }
342
+ }
343
+ isEnabled() {
344
+ var _a, _b, _c;
345
+ return (_c = (_b = (_a = this.container.actualOptions) === null || _a === void 0 ? void 0 : _a.infection) === null || _b === void 0 ? void 0 : _b.enable) !== null && _c !== void 0 ? _c : false;
346
+ }
347
+ reset() {}
348
+ }
349
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
350
+
351
+
352
+
353
+ class InfectionPlugin {
354
+ constructor() {
355
+ this.id = "infection";
356
+ }
357
+ getPlugin(container) {
358
+ return new InfectionInstance(container);
359
+ }
360
+ loadOptions(options, source) {
361
+ if (!this.needsPlugin(source)) {
362
+ return;
363
+ }
364
+ let infectionOptions = options.infection;
365
+ if ((infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.load) === undefined) {
366
+ options.infection = infectionOptions = new Infection();
367
+ }
368
+ infectionOptions.load(source === null || source === void 0 ? void 0 : source.infection);
369
+ }
370
+ needsPlugin(options) {
371
+ var _a, _b;
372
+ return (_b = (_a = options === null || options === void 0 ? void 0 : options.infection) === null || _a === void 0 ? void 0 : _a.enable) !== null && _b !== void 0 ? _b : false;
373
+ }
374
+ }
375
+ async function loadInfectionPlugin(engine) {
376
+ const plugin = new InfectionPlugin();
377
+ await engine.addPlugin(plugin);
378
+ await engine.addInteractor("particlesInfection", container => new ParticlesInfecter(container));
379
+ }
380
+
381
+
382
+ })();
383
+
384
+ /******/ return __webpack_exports__;
385
+ /******/ })()
386
+ ;
387
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.plugin.infection.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 i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var c=i[e]={exports:{}};return t[e](c,c.exports,n),c.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{loadInfectionPlugin:()=>l});var e=n(533);class t{constructor(){this.color=new e.OptionsColor,this.color.value="#ff0000",this.radius=0,this.rate=1}load(t){void 0!==t&&(void 0!==t.color&&(this.color=e.OptionsColor.create(this.color,t.color)),this.duration=t.duration,this.infectedStage=t.infectedStage,void 0!==t.radius&&(this.radius=t.radius),void 0!==t.rate&&(this.rate=t.rate))}}class i{constructor(){this.cure=!1,this.delay=0,this.enable=!1,this.infections=0,this.stages=[]}load(e){void 0!==e&&(void 0!==e.cure&&(this.cure=e.cure),void 0!==e.delay&&(this.delay=e.delay),void 0!==e.enable&&(this.enable=e.enable),void 0!==e.infections&&(this.infections=e.infections),void 0!==e.stages&&(this.stages=e.stages.map((e=>{const i=new t;return i.load(e),i}))))}}class c{constructor(e){this.container=e}startInfection(e,t){const i=this.container.actualOptions;if(!i.infection||!e.infection)return;t>i.infection.stages.length||t<0||(e.infection.delay=0,e.infection.delayStage=t)}updateInfection(e,t){const i=this.container.actualOptions.infection;if(!i||!e.infection)return;const n=i.stages,o=n.length;if(void 0!==e.infection.delay&&void 0!==e.infection.delayStage){const n=e.infection.delayStage;if(n>o||n<0)return;e.infection.delay>=1e3*i.delay?(e.infection.stage=n,e.infection.time=0,delete e.infection.delay,delete e.infection.delayStage):e.infection.delay+=t}else delete e.infection.delay,delete e.infection.delayStage;if(void 0!==e.infection.stage&&void 0!==e.infection.time){const i=n[e.infection.stage];void 0!==i.duration&&i.duration>=0&&e.infection.time>1e3*i.duration?this.nextInfectionStage(e):e.infection.time+=t}else delete e.infection.stage,delete e.infection.time}updateInfectionStage(e,t){const i=this.container.actualOptions;if(!i.infection||!e.infection)return;t>i.infection.stages.length||t<0||void 0!==e.infection.stage&&e.infection.stage>t||(e.infection.stage=t,e.infection.time=0)}nextInfectionStage(e){const t=this.container.actualOptions;if(!t.infection||!e.infection)return;const i=t.infection.stages.length;if(!(i<=0||void 0===e.infection.stage)&&(e.infection.time=0,i<=++e.infection.stage)){if(t.infection.cure)return delete e.infection.stage,void delete e.infection.time;e.infection.stage=0,e.infection.time=0}}}class a{constructor(e){this.container=e,this.container.infecter=new c(this.container)}particleFillColor(e){const t=this.container.actualOptions;if(!e.infection||!t.infection)return;const i=e.infection.stage,n=t.infection.stages;return void 0!==i?n[i].color:void 0}particleStrokeColor(e){return this.particleFillColor(e)}particlesSetup(){var t;const i=this.container.actualOptions;if(i.infection)for(let n=0;n<i.infection.infections;n++){const i=this.container.particles.array.filter((e=>{const t=e;return t.infection||(t.infection={}),void 0===t.infection.stage})),n=(0,e.itemFromArray)(i);null===(t=this.container.infecter)||void 0===t||t.startInfection(n,0)}}}class s extends e.ParticlesInteractorBase{constructor(e){super(e)}clear(){}init(){}async interact(t,i){var n,o,c,a,s;const r=this.container.infecter;if(!r)return;if(r.updateInfection(t,i.value),void 0===(null===(n=t.infection)||void 0===n?void 0:n.stage))return;const l=this.container,f=l.actualOptions.infection;if(!(null==f?void 0:f.enable)||f.stages.length<1)return;const d=f.stages[t.infection.stage],u=l.retina.pixelRatio,g=2*t.getRadius()+d.radius*u,v=t.getPosition(),p=null!==(o=d.infectedStage)&&void 0!==o?o:t.infection.stage,h=l.particles.quadTree.queryCircle(v,g),y=d.rate,S=h.length;for(const i of h){const n=i;if(!(n===t||n.destroyed||n.spawning||void 0!==(null===(c=n.infection)||void 0===c?void 0:c.stage)&&n.infection.stage===t.infection.stage)&&(0,e.getRandom)()<y/S)if(void 0===(null===(a=n.infection)||void 0===a?void 0:a.stage))r.startInfection(n,p);else if(n.infection.stage<t.infection.stage)r.updateInfectionStage(n,p);else if(n.infection.stage>t.infection.stage){const e=f.stages[n.infection.stage],i=null!==(s=null==e?void 0:e.infectedStage)&&void 0!==s?s:n.infection.stage;r.updateInfectionStage(t,i)}}}isEnabled(){var e,t,i;return null!==(i=null===(t=null===(e=this.container.actualOptions)||void 0===e?void 0:e.infection)||void 0===t?void 0:t.enable)&&void 0!==i&&i}reset(){}}class r{constructor(){this.id="infection"}getPlugin(e){return new a(e)}loadOptions(e,t){if(!this.needsPlugin(t))return;let n=e.infection;void 0===(null==n?void 0:n.load)&&(e.infection=n=new i),n.load(null==t?void 0:t.infection)}needsPlugin(e){var t,i;return null!==(i=null===(t=null==e?void 0:e.infection)||void 0===t?void 0:t.enable)&&void 0!==i&&i}}async function l(e){const t=new r;await e.addPlugin(t),await e.addInteractor("particlesInfection",(e=>new s(e)))}})(),o})()));
@@ -0,0 +1,8 @@
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
+ */
@@ -0,0 +1,9 @@
1
+ import type { InfectableContainer, InfectableParticle } from "./Types";
2
+ export declare class Infecter {
3
+ private readonly container;
4
+ constructor(container: InfectableContainer);
5
+ startInfection(particle: InfectableParticle, stage: number): void;
6
+ updateInfection(particle: InfectableParticle, delta: number): void;
7
+ updateInfectionStage(particle: InfectableParticle, stage: number): void;
8
+ private nextInfectionStage;
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { IContainerPlugin, IOptionsColor, Particle } from "@tsparticles/engine";
2
+ import type { InfectableContainer, InfectableParticle } from "./Types";
3
+ export declare class InfectionInstance implements IContainerPlugin {
4
+ private readonly container;
5
+ constructor(container: InfectableContainer);
6
+ particleFillColor(particle: InfectableParticle): string | IOptionsColor | undefined;
7
+ particleStrokeColor(particle: Particle): string | IOptionsColor | undefined;
8
+ particlesSetup(): void;
9
+ }
@@ -0,0 +1,12 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import type { IInfection } from "../Interfaces/IInfection";
3
+ import { InfectionStage } from "./InfectionStage";
4
+ export declare class Infection implements IInfection, IOptionLoader<IInfection> {
5
+ cure: boolean;
6
+ delay: number;
7
+ enable: boolean;
8
+ infections: number;
9
+ stages: InfectionStage[];
10
+ constructor();
11
+ load(data?: RecursivePartial<IInfection>): void;
12
+ }
@@ -0,0 +1,12 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import type { IInfectionStage } from "../Interfaces/IInfectionStage";
3
+ import { OptionsColor } from "@tsparticles/engine";
4
+ export declare class InfectionStage implements IInfectionStage, IOptionLoader<IInfectionStage> {
5
+ color: OptionsColor;
6
+ duration?: number;
7
+ infectedStage?: number;
8
+ radius: number;
9
+ rate: number;
10
+ constructor();
11
+ load(data?: RecursivePartial<IInfectionStage>): void;
12
+ }
@@ -0,0 +1,8 @@
1
+ import type { IInfectionStage } from "./IInfectionStage";
2
+ export interface IInfection {
3
+ cure: boolean;
4
+ delay: number;
5
+ enable: boolean;
6
+ infections: number;
7
+ stages: IInfectionStage[];
8
+ }
@@ -0,0 +1,8 @@
1
+ import type { IOptionsColor } from "@tsparticles/engine";
2
+ export interface IInfectionStage {
3
+ color: string | IOptionsColor;
4
+ duration?: number;
5
+ infectedStage?: number;
6
+ radius: number;
7
+ rate: number;
8
+ }
@@ -0,0 +1,11 @@
1
+ import type { InfectableContainer, InfectableParticle } from "./Types";
2
+ import { ParticlesInteractorBase } from "@tsparticles/engine";
3
+ import type { IDelta } from "@tsparticles/engine";
4
+ export declare class ParticlesInfecter extends ParticlesInteractorBase<InfectableContainer> {
5
+ constructor(container: InfectableContainer);
6
+ clear(): void;
7
+ init(): void;
8
+ interact(p1: InfectableParticle, delta: IDelta): Promise<void>;
9
+ isEnabled(): boolean;
10
+ reset(): void;
11
+ }
@@ -0,0 +1,24 @@
1
+ import type { Container, IOptions, IParticle, Options, Particle } from "@tsparticles/engine";
2
+ import type { IInfection } from "./Options/Interfaces/IInfection";
3
+ import type { Infecter } from "./Infecter";
4
+ import type { Infection } from "./Options/Classes/Infection";
5
+ export interface IParticleInfection {
6
+ delay?: number;
7
+ delayStage?: number;
8
+ stage?: number;
9
+ time?: number;
10
+ }
11
+ export type InfectableContainer = Container & {
12
+ actualOptions: InfectionOptions;
13
+ infecter?: Infecter;
14
+ };
15
+ export type IInfectableParticle = IParticle & {
16
+ infection?: IParticleInfection;
17
+ };
18
+ export type IInfectionOptions = IOptions & {
19
+ infection: IInfection;
20
+ };
21
+ export type InfectionOptions = Options & {
22
+ infection?: Infection;
23
+ };
24
+ export type InfectableParticle = Particle & IInfectableParticle;
@@ -0,0 +1,4 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadInfectionPlugin(engine: Engine): Promise<void>;
3
+ export * from "./Options/Interfaces/IInfection";
4
+ export * from "./Options/Interfaces/IInfectionStage";
@@ -0,0 +1,111 @@
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
+ exports.Infecter = void 0;
13
+ class Infecter {
14
+ constructor(container) {
15
+ this.container = container;
16
+ }
17
+ startInfection(particle, stage) {
18
+ const options = this.container.actualOptions;
19
+ if (!options.infection || !particle.infection) {
20
+ return;
21
+ }
22
+ const stages = options.infection.stages, stagesCount = stages.length;
23
+ if (stage > stagesCount || stage < 0) {
24
+ return;
25
+ }
26
+ particle.infection.delay = 0;
27
+ particle.infection.delayStage = stage;
28
+ }
29
+ updateInfection(particle, delta) {
30
+ const infection = this.container.actualOptions.infection;
31
+ if (!infection || !particle.infection) {
32
+ return;
33
+ }
34
+ const stages = infection.stages, stagesCount = stages.length;
35
+ if (particle.infection.delay !== undefined && particle.infection.delayStage !== undefined) {
36
+ const stage = particle.infection.delayStage;
37
+ if (stage > stagesCount || stage < 0) {
38
+ return;
39
+ }
40
+ if (particle.infection.delay >= infection.delay * 1000) {
41
+ particle.infection.stage = stage;
42
+ particle.infection.time = 0;
43
+ delete particle.infection.delay;
44
+ delete particle.infection.delayStage;
45
+ }
46
+ else {
47
+ particle.infection.delay += delta;
48
+ }
49
+ }
50
+ else {
51
+ delete particle.infection.delay;
52
+ delete particle.infection.delayStage;
53
+ }
54
+ if (particle.infection.stage !== undefined && particle.infection.time !== undefined) {
55
+ const infectionStage = stages[particle.infection.stage];
56
+ if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
57
+ if (particle.infection.time > infectionStage.duration * 1000) {
58
+ this.nextInfectionStage(particle);
59
+ }
60
+ else {
61
+ particle.infection.time += delta;
62
+ }
63
+ }
64
+ else {
65
+ particle.infection.time += delta;
66
+ }
67
+ }
68
+ else {
69
+ delete particle.infection.stage;
70
+ delete particle.infection.time;
71
+ }
72
+ }
73
+ updateInfectionStage(particle, stage) {
74
+ const options = this.container.actualOptions;
75
+ if (!options.infection || !particle.infection) {
76
+ return;
77
+ }
78
+ const stagesCount = options.infection.stages.length;
79
+ if (stage > stagesCount ||
80
+ stage < 0 ||
81
+ (particle.infection.stage !== undefined && particle.infection.stage > stage)) {
82
+ return;
83
+ }
84
+ particle.infection.stage = stage;
85
+ particle.infection.time = 0;
86
+ }
87
+ nextInfectionStage(particle) {
88
+ const options = this.container.actualOptions;
89
+ if (!options.infection || !particle.infection) {
90
+ return;
91
+ }
92
+ const stagesCount = options.infection.stages.length;
93
+ if (stagesCount <= 0 || particle.infection.stage === undefined) {
94
+ return;
95
+ }
96
+ particle.infection.time = 0;
97
+ if (stagesCount <= ++particle.infection.stage) {
98
+ if (options.infection.cure) {
99
+ delete particle.infection.stage;
100
+ delete particle.infection.time;
101
+ return;
102
+ }
103
+ else {
104
+ particle.infection.stage = 0;
105
+ particle.infection.time = 0;
106
+ }
107
+ }
108
+ }
109
+ }
110
+ exports.Infecter = Infecter;
111
+ });