@tsparticles/plugin-infection 3.9.1 → 4.0.0-alpha.1

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/492.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 492.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_infection=this.webpackChunk_tsparticles_plugin_infection||[]).push([[492],{492(t,e,i){i.d(e,{InfectionPlugin:()=>r});var n=i(303);class o{constructor(){this.color=new n.OptionsColor,this.color.value="#ff0000",this.radius=0,this.rate=1}load(t){(0,n.isNull)(t)||(void 0!==t.color&&(this.color=n.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 s{constructor(){this.cure=!1,this.delay=0,this.enable=!1,this.infections=0,this.stages=[]}load(t){(0,n.isNull)(t)||(void 0!==t.cure&&(this.cure=t.cure),void 0!==t.delay&&(this.delay=t.delay),void 0!==t.enable&&(this.enable=t.enable),void 0!==t.infections&&(this.infections=t.infections),void 0!==t.stages&&(this.stages=t.stages.map((t=>{const e=new o;return e.load(t),e}))))}}class a{constructor(t){this._nextInfectionStage=t=>{const e=this._container.actualOptions.infection,{infection:i}=t;if(!e||!i)return;const n=e.stages.length;n<=0||void 0===i.stage||(i.time=0,n<=++i.stage&&(e.cure?(delete i.stage,delete i.time):(i.stage=0,i.time=0)))},this._container=t}startInfection(t,e){const i=this._container.actualOptions.infection,{infection:n}=t;if(!i||!n)return;e>i.stages.length||e<0||(n.delay=0,n.delayStage=e)}updateInfection(t,e){const i=this._container.actualOptions.infection,{infection:o}=t;if(!i||!o)return;const s=i.stages,a=s.length;if(void 0!==o.delay&&void 0!==o.delayStage){const t=o.delayStage;if(t>a||t<0)return;o.delay>=i.delay*n.millisecondsToSeconds?(o.stage=t,o.time=0,delete o.delay,delete o.delayStage):o.delay+=e}else delete o.delay,delete o.delayStage;if(void 0!==o.stage&&void 0!==o.time){const i=s[o.stage];void 0!==i?.duration&&i.duration>=0&&o.time>i.duration*n.millisecondsToSeconds?this._nextInfectionStage(t):o.time+=e}else delete o.stage,delete o.time}updateInfectionStage(t,e){const i=this._container.actualOptions,{infection:n}=t;if(!i.infection||!n)return;e>i.infection.stages.length||e<0||void 0!==n.stage&&n.stage>e||(n.stage=e,n.time=0)}}class c{constructor(t){this._container=t,this._container.infecter=new a(this._container)}particleFillColor(t){const e=this._container.actualOptions;if(!t.infection||!e.infection)return;const i=t.infection.stage,n=e.infection.stages;return void 0===i?void 0:n[i]?.color}particleStrokeColor(t){return this.particleFillColor(t)}particlesSetup(){const t=this._container.actualOptions;if(t.infection)for(let e=0;e<t.infection.infections;e++){const t=this._container.particles.filter((t=>{const e=t;return e.infection??={},void 0===e.infection.stage})),e=(0,n.itemFromArray)(t);e&&this._container.infecter?.startInfection(e,0)}}}class r{constructor(){this.id="infection"}getPlugin(t){return Promise.resolve(new c(t))}loadOptions(t,e){if(!this.needsPlugin(t)&&!this.needsPlugin(e))return;let i=t.infection;void 0===i?.load&&(t.infection=i=new s),i.load(e?.infection)}needsPlugin(t){return t?.infection?.enable??!1}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Infection Plugin v4.0.0-alpha.1 by Matteo Bruni */
package/796.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 796.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_infection=this.webpackChunk_tsparticles_plugin_infection||[]).push([[796],{796(t,e,n){n.d(e,{ParticlesInfecter:()=>s});var i=n(303);class s extends i.ParticlesInteractorBase{constructor(t){super(t)}clear(){}init(){}interact(t,e){const n=this.container.infecter;if(!n)return;if(n.updateInfection(t,e.value),void 0===t.infection?.stage)return;const s=this.container,a=s.actualOptions.infection;if(!a?.enable||a.stages.length<1)return;const c=a.stages[t.infection.stage];if(!c)return;const o=s.retina.pixelRatio,r=2*t.getRadius()+c.radius*o,f=t.getPosition(),g=c.infectedStage??t.infection.stage,u=s.particles.quadTree.queryCircle(f,r),l=c.rate,d=u.length;for(const e of u){const s=e;if(!(s===t||s.destroyed||s.spawning||void 0!==s.infection?.stage&&s.infection.stage===t.infection.stage||(0,i.getRandom)()>=l/d))if(void 0===s.infection?.stage)n.startInfection(s,g);else if(s.infection.stage<t.infection.stage)n.updateInfectionStage(s,g);else if(s.infection.stage>t.infection.stage){const e=a.stages[s.infection.stage];if(!e)continue;const i=e.infectedStage??s.infection.stage;n.updateInfectionStage(t,i)}}}isEnabled(){return this.container.actualOptions.infection?.enable??!1}reset(){}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Infection Plugin v4.0.0-alpha.1 by Matteo Bruni */
@@ -64,7 +64,7 @@ export class Infecter {
64
64
  }
65
65
  if (infection.stage !== undefined && infection.time !== undefined) {
66
66
  const infectionStage = stages[infection.stage];
67
- if (infectionStage.duration !== undefined && infectionStage.duration >= minDuration) {
67
+ if (infectionStage?.duration !== undefined && infectionStage.duration >= minDuration) {
68
68
  if (infection.time > infectionStage.duration * millisecondsToSeconds) {
69
69
  this._nextInfectionStage(particle);
70
70
  }
@@ -12,7 +12,7 @@ export class InfectionInstance {
12
12
  return;
13
13
  }
14
14
  const infectionStage = particle.infection.stage, infection = options.infection, infectionStages = infection.stages;
15
- return infectionStage !== undefined ? infectionStages[infectionStage].color : undefined;
15
+ return infectionStage === undefined ? undefined : infectionStages[infectionStage]?.color;
16
16
  }
17
17
  particleStrokeColor(particle) {
18
18
  return this.particleFillColor(particle);
@@ -25,12 +25,13 @@ export class InfectionInstance {
25
25
  for (let i = 0; i < options.infection.infections; i++) {
26
26
  const notInfected = this._container.particles.filter(p => {
27
27
  const infP = p;
28
- if (!infP.infection) {
29
- infP.infection = {};
30
- }
28
+ infP.infection ??= {};
31
29
  return infP.infection.stage === undefined;
32
30
  });
33
31
  const infected = itemFromArray(notInfected);
32
+ if (!infected) {
33
+ continue;
34
+ }
34
35
  this._container.infecter?.startInfection(infected, minStage);
35
36
  }
36
37
  }
@@ -21,7 +21,11 @@ export class ParticlesInfecter extends ParticlesInteractorBase {
21
21
  if (!infectionOptions?.enable || infectionOptions.stages.length < minStagesCount) {
22
22
  return;
23
23
  }
24
- const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * double + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
24
+ const infectionStage1 = infectionOptions.stages[p1.infection.stage];
25
+ if (!infectionStage1) {
26
+ return;
27
+ }
28
+ const pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * double + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
25
29
  for (const p2 of query) {
26
30
  const infP2 = p2;
27
31
  if (infP2 === p1 ||
@@ -39,13 +43,16 @@ export class ParticlesInfecter extends ParticlesInteractorBase {
39
43
  }
40
44
  else if (infP2.infection.stage > p1.infection.stage) {
41
45
  const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
42
- const infectedStage2 = infectionStage2?.infectedStage ?? infP2.infection.stage;
46
+ if (!infectionStage2) {
47
+ continue;
48
+ }
49
+ const infectedStage2 = infectionStage2.infectedStage ?? infP2.infection.stage;
43
50
  infecter.updateInfectionStage(p1, infectedStage2);
44
51
  }
45
52
  }
46
53
  }
47
54
  isEnabled() {
48
- return this.container.actualOptions?.infection?.enable ?? false;
55
+ return this.container.actualOptions.infection?.enable ?? false;
49
56
  }
50
57
  reset() {
51
58
  }
package/browser/index.js CHANGED
@@ -1,12 +1,11 @@
1
- import { InfectionPlugin } from "./InfectionPlugin.js";
2
- import { ParticlesInfecter } from "./ParticlesInfecter.js";
3
- export async function loadInfectionPlugin(engine, refresh = true) {
4
- engine.checkVersion("3.9.1");
5
- const plugin = new InfectionPlugin();
6
- await engine.addPlugin(plugin, refresh);
7
- await engine.addInteractor("particlesInfection", container => {
8
- return Promise.resolve(new ParticlesInfecter(container));
9
- }, refresh);
1
+ export function loadInfectionPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.1");
3
+ engine.register(async (e) => {
4
+ const { InfectionPlugin } = await import("./InfectionPlugin.js");
5
+ e.addPlugin(new InfectionPlugin());
6
+ e.addInteractor("particlesInfection", async (container) => {
7
+ const { ParticlesInfecter } = await import("./ParticlesInfecter.js");
8
+ return new ParticlesInfecter(container);
9
+ });
10
+ });
10
11
  }
11
- export * from "./Options/Interfaces/IInfection.js";
12
- export * from "./Options/Interfaces/IInfectionStage.js";
package/cjs/Infecter.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Infecter = void 0;
4
- const engine_1 = require("@tsparticles/engine");
1
+ import { millisecondsToSeconds } from "@tsparticles/engine";
5
2
  const minStage = 0, minDuration = 0;
6
- class Infecter {
3
+ export class Infecter {
7
4
  constructor(container) {
8
5
  this._nextInfectionStage = particle => {
9
6
  const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
@@ -51,7 +48,7 @@ class Infecter {
51
48
  if (stage > stagesCount || stage < minStage) {
52
49
  return;
53
50
  }
54
- if (infection.delay >= infectionOptions.delay * engine_1.millisecondsToSeconds) {
51
+ if (infection.delay >= infectionOptions.delay * millisecondsToSeconds) {
55
52
  infection.stage = stage;
56
53
  infection.time = 0;
57
54
  delete infection.delay;
@@ -67,8 +64,8 @@ class Infecter {
67
64
  }
68
65
  if (infection.stage !== undefined && infection.time !== undefined) {
69
66
  const infectionStage = stages[infection.stage];
70
- if (infectionStage.duration !== undefined && infectionStage.duration >= minDuration) {
71
- if (infection.time > infectionStage.duration * engine_1.millisecondsToSeconds) {
67
+ if (infectionStage?.duration !== undefined && infectionStage.duration >= minDuration) {
68
+ if (infection.time > infectionStage.duration * millisecondsToSeconds) {
72
69
  this._nextInfectionStage(particle);
73
70
  }
74
71
  else {
@@ -97,4 +94,3 @@ class Infecter {
97
94
  infection.time = 0;
98
95
  }
99
96
  }
100
- exports.Infecter = Infecter;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InfectionInstance = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const Infecter_js_1 = require("./Infecter.js");
1
+ import { itemFromArray } from "@tsparticles/engine";
2
+ import { Infecter } from "./Infecter.js";
6
3
  const minStage = 0;
7
- class InfectionInstance {
4
+ export class InfectionInstance {
8
5
  constructor(container) {
9
6
  this._container = container;
10
- this._container.infecter = new Infecter_js_1.Infecter(this._container);
7
+ this._container.infecter = new Infecter(this._container);
11
8
  }
12
9
  particleFillColor(particle) {
13
10
  const options = this._container.actualOptions;
@@ -15,7 +12,7 @@ class InfectionInstance {
15
12
  return;
16
13
  }
17
14
  const infectionStage = particle.infection.stage, infection = options.infection, infectionStages = infection.stages;
18
- return infectionStage !== undefined ? infectionStages[infectionStage].color : undefined;
15
+ return infectionStage === undefined ? undefined : infectionStages[infectionStage]?.color;
19
16
  }
20
17
  particleStrokeColor(particle) {
21
18
  return this.particleFillColor(particle);
@@ -28,14 +25,14 @@ class InfectionInstance {
28
25
  for (let i = 0; i < options.infection.infections; i++) {
29
26
  const notInfected = this._container.particles.filter(p => {
30
27
  const infP = p;
31
- if (!infP.infection) {
32
- infP.infection = {};
33
- }
28
+ infP.infection ??= {};
34
29
  return infP.infection.stage === undefined;
35
30
  });
36
- const infected = (0, engine_1.itemFromArray)(notInfected);
31
+ const infected = itemFromArray(notInfected);
32
+ if (!infected) {
33
+ continue;
34
+ }
37
35
  this._container.infecter?.startInfection(infected, minStage);
38
36
  }
39
37
  }
40
38
  }
41
- exports.InfectionInstance = InfectionInstance;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InfectionPlugin = void 0;
4
- const Infection_js_1 = require("./Options/Classes/Infection.js");
5
- const InfectionInstance_js_1 = require("./InfectionInstance.js");
6
- class InfectionPlugin {
1
+ import { Infection } from "./Options/Classes/Infection.js";
2
+ import { InfectionInstance } from "./InfectionInstance.js";
3
+ export class InfectionPlugin {
7
4
  constructor() {
8
5
  this.id = "infection";
9
6
  }
10
7
  getPlugin(container) {
11
- return Promise.resolve(new InfectionInstance_js_1.InfectionInstance(container));
8
+ return Promise.resolve(new InfectionInstance(container));
12
9
  }
13
10
  loadOptions(options, source) {
14
11
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
@@ -16,7 +13,7 @@ class InfectionPlugin {
16
13
  }
17
14
  let infectionOptions = options.infection;
18
15
  if (infectionOptions?.load === undefined) {
19
- options.infection = infectionOptions = new Infection_js_1.Infection();
16
+ options.infection = infectionOptions = new Infection();
20
17
  }
21
18
  infectionOptions.load(source?.infection);
22
19
  }
@@ -24,4 +21,3 @@ class InfectionPlugin {
24
21
  return options?.infection?.enable ?? false;
25
22
  }
26
23
  }
27
- exports.InfectionPlugin = InfectionPlugin;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Infection = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const InfectionStage_js_1 = require("./InfectionStage.js");
6
- class Infection {
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { InfectionStage } from "./InfectionStage.js";
3
+ export class Infection {
7
4
  constructor() {
8
5
  this.cure = false;
9
6
  this.delay = 0;
@@ -12,7 +9,7 @@ class Infection {
12
9
  this.stages = [];
13
10
  }
14
11
  load(data) {
15
- if ((0, engine_1.isNull)(data)) {
12
+ if (isNull(data)) {
16
13
  return;
17
14
  }
18
15
  if (data.cure !== undefined) {
@@ -31,10 +28,9 @@ class Infection {
31
28
  return;
32
29
  }
33
30
  this.stages = data.stages.map(t => {
34
- const s = new InfectionStage_js_1.InfectionStage();
31
+ const s = new InfectionStage();
35
32
  s.load(t);
36
33
  return s;
37
34
  });
38
35
  }
39
36
  }
40
- exports.Infection = Infection;
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InfectionStage = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- class InfectionStage {
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
+ export class InfectionStage {
6
3
  constructor() {
7
- this.color = new engine_1.OptionsColor();
4
+ this.color = new OptionsColor();
8
5
  this.color.value = "#ff0000";
9
6
  this.radius = 0;
10
7
  this.rate = 1;
11
8
  }
12
9
  load(data) {
13
- if ((0, engine_1.isNull)(data)) {
10
+ if (isNull(data)) {
14
11
  return;
15
12
  }
16
13
  if (data.color !== undefined) {
17
- this.color = engine_1.OptionsColor.create(this.color, data.color);
14
+ this.color = OptionsColor.create(this.color, data.color);
18
15
  }
19
16
  this.duration = data.duration;
20
17
  this.infectedStage = data.infectedStage;
@@ -26,4 +23,3 @@ class InfectionStage {
26
23
  }
27
24
  }
28
25
  }
29
- exports.InfectionStage = InfectionStage;
@@ -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,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParticlesInfecter = void 0;
4
- const engine_1 = require("@tsparticles/engine");
1
+ import { ParticlesInteractorBase, getRandom } from "@tsparticles/engine";
5
2
  const minStagesCount = 1, double = 2;
6
- class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
3
+ export class ParticlesInfecter extends ParticlesInteractorBase {
7
4
  constructor(container) {
8
5
  super(container);
9
6
  }
@@ -24,14 +21,18 @@ class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
24
21
  if (!infectionOptions?.enable || infectionOptions.stages.length < minStagesCount) {
25
22
  return;
26
23
  }
27
- const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * double + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
24
+ const infectionStage1 = infectionOptions.stages[p1.infection.stage];
25
+ if (!infectionStage1) {
26
+ return;
27
+ }
28
+ const pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * double + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
28
29
  for (const p2 of query) {
29
30
  const infP2 = p2;
30
31
  if (infP2 === p1 ||
31
32
  infP2.destroyed ||
32
33
  infP2.spawning ||
33
34
  !(infP2.infection?.stage === undefined || infP2.infection.stage !== p1.infection.stage) ||
34
- (0, engine_1.getRandom)() >= infections / neighbors) {
35
+ getRandom() >= infections / neighbors) {
35
36
  continue;
36
37
  }
37
38
  if (infP2.infection?.stage === undefined) {
@@ -42,15 +43,17 @@ class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
42
43
  }
43
44
  else if (infP2.infection.stage > p1.infection.stage) {
44
45
  const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
45
- const infectedStage2 = infectionStage2?.infectedStage ?? infP2.infection.stage;
46
+ if (!infectionStage2) {
47
+ continue;
48
+ }
49
+ const infectedStage2 = infectionStage2.infectedStage ?? infP2.infection.stage;
46
50
  infecter.updateInfectionStage(p1, infectedStage2);
47
51
  }
48
52
  }
49
53
  }
50
54
  isEnabled() {
51
- return this.container.actualOptions?.infection?.enable ?? false;
55
+ return this.container.actualOptions.infection?.enable ?? false;
52
56
  }
53
57
  reset() {
54
58
  }
55
59
  }
56
- exports.ParticlesInfecter = ParticlesInfecter;
package/cjs/Types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/index.js CHANGED
@@ -1,29 +1,11 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.loadInfectionPlugin = loadInfectionPlugin;
18
- const InfectionPlugin_js_1 = require("./InfectionPlugin.js");
19
- const ParticlesInfecter_js_1 = require("./ParticlesInfecter.js");
20
- async function loadInfectionPlugin(engine, refresh = true) {
21
- engine.checkVersion("3.9.1");
22
- const plugin = new InfectionPlugin_js_1.InfectionPlugin();
23
- await engine.addPlugin(plugin, refresh);
24
- await engine.addInteractor("particlesInfection", container => {
25
- return Promise.resolve(new ParticlesInfecter_js_1.ParticlesInfecter(container));
26
- }, refresh);
1
+ export function loadInfectionPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.1");
3
+ engine.register(async (e) => {
4
+ const { InfectionPlugin } = await import("./InfectionPlugin.js");
5
+ e.addPlugin(new InfectionPlugin());
6
+ e.addInteractor("particlesInfection", async (container) => {
7
+ const { ParticlesInfecter } = await import("./ParticlesInfecter.js");
8
+ return new ParticlesInfecter(container);
9
+ });
10
+ });
27
11
  }
28
- __exportStar(require("./Options/Interfaces/IInfection.js"), exports);
29
- __exportStar(require("./Options/Interfaces/IInfectionStage.js"), exports);
@@ -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.1
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_plugin_infection"] = this["webpackChunk_tsparticles_plugin_infection"] || []).push([["dist_browser_InfectionPlugin_js"],{
19
+
20
+ /***/ "./dist/browser/Infecter.js"
21
+ /*!**********************************!*\
22
+ !*** ./dist/browser/Infecter.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 */ Infecter: () => (/* binding */ Infecter)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst minStage = 0,\n minDuration = 0;\nclass Infecter {\n constructor(container) {\n this._nextInfectionStage = particle => {\n const infectionOptions = this._container.actualOptions.infection,\n {\n infection\n } = particle;\n if (!infectionOptions || !infection) {\n return;\n }\n const stagesCount = infectionOptions.stages.length;\n if (stagesCount <= minStage || infection.stage === undefined) {\n return;\n }\n infection.time = 0;\n if (stagesCount <= ++infection.stage) {\n if (infectionOptions.cure) {\n delete infection.stage;\n delete infection.time;\n } else {\n infection.stage = 0;\n infection.time = 0;\n }\n }\n };\n this._container = container;\n }\n startInfection(particle, stage) {\n const infectionOptions = this._container.actualOptions.infection,\n {\n infection\n } = particle;\n if (!infectionOptions || !infection) {\n return;\n }\n const stages = infectionOptions.stages,\n stagesCount = stages.length;\n if (stage > stagesCount || stage < minStage) {\n return;\n }\n infection.delay = 0;\n infection.delayStage = stage;\n }\n updateInfection(particle, delta) {\n const infectionOptions = this._container.actualOptions.infection,\n {\n infection\n } = particle;\n if (!infectionOptions || !infection) {\n return;\n }\n const stages = infectionOptions.stages,\n stagesCount = stages.length;\n if (infection.delay !== undefined && infection.delayStage !== undefined) {\n const stage = infection.delayStage;\n if (stage > stagesCount || stage < minStage) {\n return;\n }\n if (infection.delay >= infectionOptions.delay * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds) {\n infection.stage = stage;\n infection.time = 0;\n delete infection.delay;\n delete infection.delayStage;\n } else {\n infection.delay += delta;\n }\n } else {\n delete infection.delay;\n delete infection.delayStage;\n }\n if (infection.stage !== undefined && infection.time !== undefined) {\n const infectionStage = stages[infection.stage];\n if (infectionStage?.duration !== undefined && infectionStage.duration >= minDuration) {\n if (infection.time > infectionStage.duration * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds) {\n this._nextInfectionStage(particle);\n } else {\n infection.time += delta;\n }\n } else {\n infection.time += delta;\n }\n } else {\n delete infection.stage;\n delete infection.time;\n }\n }\n updateInfectionStage(particle, stage) {\n const options = this._container.actualOptions,\n {\n infection\n } = particle;\n if (!options.infection || !infection) {\n return;\n }\n const stagesCount = options.infection.stages.length;\n if (stage > stagesCount || stage < minStage || infection.stage !== undefined && infection.stage > stage) {\n return;\n }\n infection.stage = stage;\n infection.time = 0;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-infection/./dist/browser/Infecter.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/InfectionInstance.js"
31
+ /*!*******************************************!*\
32
+ !*** ./dist/browser/InfectionInstance.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 */ InfectionInstance: () => (/* binding */ InfectionInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Infecter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Infecter.js */ \"./dist/browser/Infecter.js\");\n\n\nconst minStage = 0;\nclass InfectionInstance {\n constructor(container) {\n this._container = container;\n this._container.infecter = new _Infecter_js__WEBPACK_IMPORTED_MODULE_1__.Infecter(this._container);\n }\n particleFillColor(particle) {\n const options = this._container.actualOptions;\n if (!particle.infection || !options.infection) {\n return;\n }\n const infectionStage = particle.infection.stage,\n infection = options.infection,\n infectionStages = infection.stages;\n return infectionStage === undefined ? undefined : infectionStages[infectionStage]?.color;\n }\n particleStrokeColor(particle) {\n return this.particleFillColor(particle);\n }\n particlesSetup() {\n const options = this._container.actualOptions;\n if (!options.infection) {\n return;\n }\n for (let i = 0; i < options.infection.infections; i++) {\n const notInfected = this._container.particles.filter(p => {\n const infP = p;\n infP.infection ??= {};\n return infP.infection.stage === undefined;\n });\n const infected = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromArray)(notInfected);\n if (!infected) {\n continue;\n }\n this._container.infecter?.startInfection(infected, minStage);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-infection/./dist/browser/InfectionInstance.js?\n}");
37
+
38
+ /***/ },
39
+
40
+ /***/ "./dist/browser/InfectionPlugin.js"
41
+ /*!*****************************************!*\
42
+ !*** ./dist/browser/InfectionPlugin.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 */ InfectionPlugin: () => (/* binding */ InfectionPlugin)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Infection_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Infection.js */ \"./dist/browser/Options/Classes/Infection.js\");\n/* harmony import */ var _InfectionInstance_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./InfectionInstance.js */ \"./dist/browser/InfectionInstance.js\");\n\n\nclass InfectionPlugin {\n constructor() {\n this.id = \"infection\";\n }\n getPlugin(container) {\n return Promise.resolve(new _InfectionInstance_js__WEBPACK_IMPORTED_MODULE_1__.InfectionInstance(container));\n }\n loadOptions(options, source) {\n if (!this.needsPlugin(options) && !this.needsPlugin(source)) {\n return;\n }\n let infectionOptions = options.infection;\n if (infectionOptions?.load === undefined) {\n options.infection = infectionOptions = new _Options_Classes_Infection_js__WEBPACK_IMPORTED_MODULE_0__.Infection();\n }\n infectionOptions.load(source?.infection);\n }\n needsPlugin(options) {\n return options?.infection?.enable ?? false;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-infection/./dist/browser/InfectionPlugin.js?\n}");
47
+
48
+ /***/ },
49
+
50
+ /***/ "./dist/browser/Options/Classes/Infection.js"
51
+ /*!***************************************************!*\
52
+ !*** ./dist/browser/Options/Classes/Infection.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 */ Infection: () => (/* binding */ Infection)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _InfectionStage_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./InfectionStage.js */ \"./dist/browser/Options/Classes/InfectionStage.js\");\n\n\nclass Infection {\n constructor() {\n this.cure = false;\n this.delay = 0;\n this.enable = false;\n this.infections = 0;\n this.stages = [];\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.cure !== undefined) {\n this.cure = data.cure;\n }\n if (data.delay !== undefined) {\n this.delay = data.delay;\n }\n if (data.enable !== undefined) {\n this.enable = data.enable;\n }\n if (data.infections !== undefined) {\n this.infections = data.infections;\n }\n if (data.stages === undefined) {\n return;\n }\n this.stages = data.stages.map(t => {\n const s = new _InfectionStage_js__WEBPACK_IMPORTED_MODULE_1__.InfectionStage();\n s.load(t);\n return s;\n });\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-infection/./dist/browser/Options/Classes/Infection.js?\n}");
57
+
58
+ /***/ },
59
+
60
+ /***/ "./dist/browser/Options/Classes/InfectionStage.js"
61
+ /*!********************************************************!*\
62
+ !*** ./dist/browser/Options/Classes/InfectionStage.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 */ InfectionStage: () => (/* binding */ InfectionStage)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass InfectionStage {\n constructor() {\n this.color = new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.OptionsColor();\n this.color.value = \"#ff0000\";\n this.radius = 0;\n this.rate = 1;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.color !== undefined) {\n this.color = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.OptionsColor.create(this.color, data.color);\n }\n this.duration = data.duration;\n this.infectedStage = data.infectedStage;\n if (data.radius !== undefined) {\n this.radius = data.radius;\n }\n if (data.rate !== undefined) {\n this.rate = data.rate;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-infection/./dist/browser/Options/Classes/InfectionStage.js?\n}");
67
+
68
+ /***/ }
69
+
70
+ }]);
@@ -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
+ * v4.0.0-alpha.1
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_plugin_infection"] = this["webpackChunk_tsparticles_plugin_infection"] || []).push([["dist_browser_ParticlesInfecter_js"],{
19
+
20
+ /***/ "./dist/browser/ParticlesInfecter.js"
21
+ /*!*******************************************!*\
22
+ !*** ./dist/browser/ParticlesInfecter.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 */ ParticlesInfecter: () => (/* binding */ ParticlesInfecter)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst minStagesCount = 1,\n double = 2;\nclass ParticlesInfecter extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ParticlesInteractorBase {\n constructor(container) {\n super(container);\n }\n clear() {}\n init() {}\n interact(p1, delta) {\n const infecter = this.container.infecter;\n if (!infecter) {\n return;\n }\n infecter.updateInfection(p1, delta.value);\n if (p1.infection?.stage === undefined) {\n return;\n }\n const container = this.container,\n options = container.actualOptions,\n infectionOptions = options.infection;\n if (!infectionOptions?.enable || infectionOptions.stages.length < minStagesCount) {\n return;\n }\n const infectionStage1 = infectionOptions.stages[p1.infection.stage];\n if (!infectionStage1) {\n return;\n }\n const pxRatio = container.retina.pixelRatio,\n radius = p1.getRadius() * double + infectionStage1.radius * pxRatio,\n pos = p1.getPosition(),\n infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage,\n query = container.particles.quadTree.queryCircle(pos, radius),\n infections = infectionStage1.rate,\n neighbors = query.length;\n for (const p2 of query) {\n const infP2 = p2;\n if (infP2 === p1 || infP2.destroyed || infP2.spawning || !(infP2.infection?.stage === undefined || infP2.infection.stage !== p1.infection.stage) || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() >= infections / neighbors) {\n continue;\n }\n if (infP2.infection?.stage === undefined) {\n infecter.startInfection(infP2, infectedStage1);\n } else if (infP2.infection.stage < p1.infection.stage) {\n infecter.updateInfectionStage(infP2, infectedStage1);\n } else if (infP2.infection.stage > p1.infection.stage) {\n const infectionStage2 = infectionOptions.stages[infP2.infection.stage];\n if (!infectionStage2) {\n continue;\n }\n const infectedStage2 = infectionStage2.infectedStage ?? infP2.infection.stage;\n infecter.updateInfectionStage(p1, infectedStage2);\n }\n }\n }\n isEnabled() {\n return this.container.actualOptions.infection?.enable ?? false;\n }\n reset() {}\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-infection/./dist/browser/ParticlesInfecter.js?\n}");
27
+
28
+ /***/ }
29
+
30
+ }]);
package/esm/Infecter.js CHANGED
@@ -64,7 +64,7 @@ export class Infecter {
64
64
  }
65
65
  if (infection.stage !== undefined && infection.time !== undefined) {
66
66
  const infectionStage = stages[infection.stage];
67
- if (infectionStage.duration !== undefined && infectionStage.duration >= minDuration) {
67
+ if (infectionStage?.duration !== undefined && infectionStage.duration >= minDuration) {
68
68
  if (infection.time > infectionStage.duration * millisecondsToSeconds) {
69
69
  this._nextInfectionStage(particle);
70
70
  }
@@ -12,7 +12,7 @@ export class InfectionInstance {
12
12
  return;
13
13
  }
14
14
  const infectionStage = particle.infection.stage, infection = options.infection, infectionStages = infection.stages;
15
- return infectionStage !== undefined ? infectionStages[infectionStage].color : undefined;
15
+ return infectionStage === undefined ? undefined : infectionStages[infectionStage]?.color;
16
16
  }
17
17
  particleStrokeColor(particle) {
18
18
  return this.particleFillColor(particle);
@@ -25,12 +25,13 @@ export class InfectionInstance {
25
25
  for (let i = 0; i < options.infection.infections; i++) {
26
26
  const notInfected = this._container.particles.filter(p => {
27
27
  const infP = p;
28
- if (!infP.infection) {
29
- infP.infection = {};
30
- }
28
+ infP.infection ??= {};
31
29
  return infP.infection.stage === undefined;
32
30
  });
33
31
  const infected = itemFromArray(notInfected);
32
+ if (!infected) {
33
+ continue;
34
+ }
34
35
  this._container.infecter?.startInfection(infected, minStage);
35
36
  }
36
37
  }
@@ -21,7 +21,11 @@ export class ParticlesInfecter extends ParticlesInteractorBase {
21
21
  if (!infectionOptions?.enable || infectionOptions.stages.length < minStagesCount) {
22
22
  return;
23
23
  }
24
- const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * double + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
24
+ const infectionStage1 = infectionOptions.stages[p1.infection.stage];
25
+ if (!infectionStage1) {
26
+ return;
27
+ }
28
+ const pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * double + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
25
29
  for (const p2 of query) {
26
30
  const infP2 = p2;
27
31
  if (infP2 === p1 ||
@@ -39,13 +43,16 @@ export class ParticlesInfecter extends ParticlesInteractorBase {
39
43
  }
40
44
  else if (infP2.infection.stage > p1.infection.stage) {
41
45
  const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
42
- const infectedStage2 = infectionStage2?.infectedStage ?? infP2.infection.stage;
46
+ if (!infectionStage2) {
47
+ continue;
48
+ }
49
+ const infectedStage2 = infectionStage2.infectedStage ?? infP2.infection.stage;
43
50
  infecter.updateInfectionStage(p1, infectedStage2);
44
51
  }
45
52
  }
46
53
  }
47
54
  isEnabled() {
48
- return this.container.actualOptions?.infection?.enable ?? false;
55
+ return this.container.actualOptions.infection?.enable ?? false;
49
56
  }
50
57
  reset() {
51
58
  }
package/esm/index.js CHANGED
@@ -1,12 +1,11 @@
1
- import { InfectionPlugin } from "./InfectionPlugin.js";
2
- import { ParticlesInfecter } from "./ParticlesInfecter.js";
3
- export async function loadInfectionPlugin(engine, refresh = true) {
4
- engine.checkVersion("3.9.1");
5
- const plugin = new InfectionPlugin();
6
- await engine.addPlugin(plugin, refresh);
7
- await engine.addInteractor("particlesInfection", container => {
8
- return Promise.resolve(new ParticlesInfecter(container));
9
- }, refresh);
1
+ export function loadInfectionPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.1");
3
+ engine.register(async (e) => {
4
+ const { InfectionPlugin } = await import("./InfectionPlugin.js");
5
+ e.addPlugin(new InfectionPlugin());
6
+ e.addInteractor("particlesInfection", async (container) => {
7
+ const { ParticlesInfecter } = await import("./ParticlesInfecter.js");
8
+ return new ParticlesInfecter(container);
9
+ });
10
+ });
10
11
  }
11
- export * from "./Options/Interfaces/IInfection.js";
12
- export * from "./Options/Interfaces/IInfectionStage.js";