@tsparticles/plugin-infection 3.0.3 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/431.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 431.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_infection=this.webpackChunk_tsparticles_plugin_infection||[]).push([[431],{431:(i,t,e)=>{e.d(t,{InfectionPlugin:()=>a});var n=e(533);class s{constructor(){this.color=new n.OptionsColor,this.color.value="#ff0000",this.radius=0,this.rate=1}load(i){void 0!==i&&(void 0!==i.color&&(this.color=n.OptionsColor.create(this.color,i.color)),this.duration=i.duration,this.infectedStage=i.infectedStage,void 0!==i.radius&&(this.radius=i.radius),void 0!==i.rate&&(this.rate=i.rate))}}class o{constructor(){this.cure=!1,this.delay=0,this.enable=!1,this.infections=0,this.stages=[]}load(i){void 0!==i&&(void 0!==i.cure&&(this.cure=i.cure),void 0!==i.delay&&(this.delay=i.delay),void 0!==i.enable&&(this.enable=i.enable),void 0!==i.infections&&(this.infections=i.infections),void 0!==i.stages&&(this.stages=i.stages.map((i=>{const t=new s;return t.load(i),t}))))}}class a{constructor(){this.id="infection"}async getPlugin(i){const{InfectionInstance:t}=await e.e(733).then(e.bind(e,733));return new t(i)}loadOptions(i,t){if(!this.needsPlugin(i)&&!this.needsPlugin(t))return;let e=i.infection;void 0===e?.load&&(i.infection=e=new o),e.load(t?.infection)}needsPlugin(i){return i?.infection?.enable??!1}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Infection Plugin v3.2.0 by Matteo Bruni */
package/733.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 733.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_infection=this.webpackChunk_tsparticles_plugin_infection||[]).push([[733],{733:(t,e,i)=>{i.d(e,{InfectionInstance:()=>s});var n=i(533);class o{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 s{constructor(t){this._container=t,this._container.infecter=new o(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?n[i].color:void 0}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||(e.infection={}),void 0===e.infection.stage})),e=(0,n.itemFromArray)(t);this._container.infecter?.startInfection(e,0)}}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Infection Plugin v3.2.0 by Matteo Bruni */
package/854.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 854.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_infection=this.webpackChunk_tsparticles_plugin_infection||[]).push([[854],{854:(e,t,n)=>{n.d(t,{ParticlesInfecter:()=>a});var i=n(533);class a extends i.ParticlesInteractorBase{constructor(e){super(e)}clear(){}init(){}async interact(e,t){const n=this.container.infecter;if(!n)return;if(n.updateInfection(e,t.value),void 0===e.infection?.stage)return;const a=this.container,s=a.actualOptions.infection;if(!s?.enable||s.stages.length<1)return;const c=s.stages[e.infection.stage],o=a.retina.pixelRatio,r=2*e.getRadius()+c.radius*o,f=e.getPosition(),g=c.infectedStage??e.infection.stage,l=a.particles.quadTree.queryCircle(f,r),u=c.rate,d=l.length;for(const t of l){const a=t;if(!(a===e||a.destroyed||a.spawning||void 0!==a.infection?.stage&&a.infection.stage===e.infection.stage||(0,i.getRandom)()>=u/d))if(void 0===a.infection?.stage)n.startInfection(a,g);else if(a.infection.stage<e.infection.stage)n.updateInfectionStage(a,g);else if(a.infection.stage>e.infection.stage){const t=s.stages[a.infection.stage],i=t?.infectedStage??a.infection.stage;n.updateInfectionStage(e,i)}}await Promise.resolve()}isEnabled(){return this.container.actualOptions?.infection?.enable??!1}reset(){}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Infection Plugin v3.2.0 by Matteo Bruni */
@@ -1,3 +1,5 @@
1
+ import { millisecondsToSeconds } from "@tsparticles/engine";
2
+ const minStage = 0, minDuration = 0;
1
3
  export class Infecter {
2
4
  constructor(container) {
3
5
  this._nextInfectionStage = (particle) => {
@@ -6,7 +8,7 @@ export class Infecter {
6
8
  return;
7
9
  }
8
10
  const stagesCount = infectionOptions.stages.length;
9
- if (stagesCount <= 0 || infection.stage === undefined) {
11
+ if (stagesCount <= minStage || infection.stage === undefined) {
10
12
  return;
11
13
  }
12
14
  infection.time = 0;
@@ -14,7 +16,6 @@ export class Infecter {
14
16
  if (infectionOptions.cure) {
15
17
  delete infection.stage;
16
18
  delete infection.time;
17
- return;
18
19
  }
19
20
  else {
20
21
  infection.stage = 0;
@@ -30,7 +31,7 @@ export class Infecter {
30
31
  return;
31
32
  }
32
33
  const stages = infectionOptions.stages, stagesCount = stages.length;
33
- if (stage > stagesCount || stage < 0) {
34
+ if (stage > stagesCount || stage < minStage) {
34
35
  return;
35
36
  }
36
37
  infection.delay = 0;
@@ -44,10 +45,10 @@ export class Infecter {
44
45
  const stages = infectionOptions.stages, stagesCount = stages.length;
45
46
  if (infection.delay !== undefined && infection.delayStage !== undefined) {
46
47
  const stage = infection.delayStage;
47
- if (stage > stagesCount || stage < 0) {
48
+ if (stage > stagesCount || stage < minStage) {
48
49
  return;
49
50
  }
50
- if (infection.delay >= infectionOptions.delay * 1000) {
51
+ if (infection.delay >= infectionOptions.delay * millisecondsToSeconds) {
51
52
  infection.stage = stage;
52
53
  infection.time = 0;
53
54
  delete infection.delay;
@@ -63,8 +64,8 @@ export class Infecter {
63
64
  }
64
65
  if (infection.stage !== undefined && infection.time !== undefined) {
65
66
  const infectionStage = stages[infection.stage];
66
- if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
67
- if (infection.time > infectionStage.duration * 1000) {
67
+ if (infectionStage.duration !== undefined && infectionStage.duration >= minDuration) {
68
+ if (infection.time > infectionStage.duration * millisecondsToSeconds) {
68
69
  this._nextInfectionStage(particle);
69
70
  }
70
71
  else {
@@ -86,7 +87,7 @@ export class Infecter {
86
87
  return;
87
88
  }
88
89
  const stagesCount = options.infection.stages.length;
89
- if (stage > stagesCount || stage < 0 || (infection.stage !== undefined && infection.stage > stage)) {
90
+ if (stage > stagesCount || stage < minStage || (infection.stage !== undefined && infection.stage > stage)) {
90
91
  return;
91
92
  }
92
93
  infection.stage = stage;
@@ -1,5 +1,6 @@
1
1
  import { itemFromArray } from "@tsparticles/engine";
2
2
  import { Infecter } from "./Infecter.js";
3
+ const minStage = 0;
3
4
  export class InfectionInstance {
4
5
  constructor(container) {
5
6
  this._container = container;
@@ -30,7 +31,7 @@ export class InfectionInstance {
30
31
  return infP.infection.stage === undefined;
31
32
  });
32
33
  const infected = itemFromArray(notInfected);
33
- this._container.infecter?.startInfection(infected, 0);
34
+ this._container.infecter?.startInfection(infected, minStage);
34
35
  }
35
36
  }
36
37
  }
@@ -0,0 +1,23 @@
1
+ import { Infection } from "./Options/Classes/Infection.js";
2
+ export class InfectionPlugin {
3
+ constructor() {
4
+ this.id = "infection";
5
+ }
6
+ async getPlugin(container) {
7
+ const { InfectionInstance } = await import("./InfectionInstance.js");
8
+ return new InfectionInstance(container);
9
+ }
10
+ loadOptions(options, source) {
11
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
12
+ return;
13
+ }
14
+ let infectionOptions = options.infection;
15
+ if (infectionOptions?.load === undefined) {
16
+ options.infection = infectionOptions = new Infection();
17
+ }
18
+ infectionOptions.load(source?.infection);
19
+ }
20
+ needsPlugin(options) {
21
+ return options?.infection?.enable ?? false;
22
+ }
23
+ }
@@ -1,4 +1,5 @@
1
1
  import { ParticlesInteractorBase, getRandom } from "@tsparticles/engine";
2
+ const minStagesCount = 1, double = 2;
2
3
  export class ParticlesInfecter extends ParticlesInteractorBase {
3
4
  constructor(container) {
4
5
  super(container);
@@ -17,10 +18,10 @@ export class ParticlesInfecter extends ParticlesInteractorBase {
17
18
  return;
18
19
  }
19
20
  const container = this.container, options = container.actualOptions, infectionOptions = options.infection;
20
- if (!infectionOptions?.enable || infectionOptions.stages.length < 1) {
21
+ if (!infectionOptions?.enable || infectionOptions.stages.length < minStagesCount) {
21
22
  return;
22
23
  }
23
- const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * 2 + 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], 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
25
  for (const p2 of query) {
25
26
  const infP2 = p2;
26
27
  if (infP2 === p1 ||
@@ -42,6 +43,7 @@ export class ParticlesInfecter extends ParticlesInteractorBase {
42
43
  infecter.updateInfectionStage(p1, infectedStage2);
43
44
  }
44
45
  }
46
+ await Promise.resolve();
45
47
  }
46
48
  isEnabled() {
47
49
  return this.container.actualOptions?.infection?.enable ?? false;
package/browser/index.js CHANGED
@@ -1,31 +1,10 @@
1
- import { Infection } from "./Options/Classes/Infection.js";
2
- import { InfectionInstance } from "./InfectionInstance.js";
3
- import { ParticlesInfecter } from "./ParticlesInfecter.js";
4
- class InfectionPlugin {
5
- constructor() {
6
- this.id = "infection";
7
- }
8
- getPlugin(container) {
9
- return new InfectionInstance(container);
10
- }
11
- loadOptions(options, source) {
12
- if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
13
- return;
14
- }
15
- let infectionOptions = options.infection;
16
- if (infectionOptions?.load === undefined) {
17
- options.infection = infectionOptions = new Infection();
18
- }
19
- infectionOptions.load(source?.infection);
20
- }
21
- needsPlugin(options) {
22
- return options?.infection?.enable ?? false;
23
- }
24
- }
25
1
  export async function loadInfectionPlugin(engine, refresh = true) {
26
- const plugin = new InfectionPlugin();
2
+ const { InfectionPlugin } = await import("./InfectionPlugin.js"), plugin = new InfectionPlugin();
27
3
  await engine.addPlugin(plugin, refresh);
28
- await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter(container), refresh);
4
+ await engine.addInteractor("particlesInfection", async (container) => {
5
+ const { ParticlesInfecter } = await import("./ParticlesInfecter.js");
6
+ return new ParticlesInfecter(container);
7
+ }, refresh);
29
8
  }
30
9
  export * from "./Options/Interfaces/IInfection.js";
31
10
  export * from "./Options/Interfaces/IInfectionStage.js";
package/cjs/Infecter.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Infecter = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ const minStage = 0, minDuration = 0;
4
6
  class Infecter {
5
7
  constructor(container) {
6
8
  this._nextInfectionStage = (particle) => {
@@ -9,7 +11,7 @@ class Infecter {
9
11
  return;
10
12
  }
11
13
  const stagesCount = infectionOptions.stages.length;
12
- if (stagesCount <= 0 || infection.stage === undefined) {
14
+ if (stagesCount <= minStage || infection.stage === undefined) {
13
15
  return;
14
16
  }
15
17
  infection.time = 0;
@@ -17,7 +19,6 @@ class Infecter {
17
19
  if (infectionOptions.cure) {
18
20
  delete infection.stage;
19
21
  delete infection.time;
20
- return;
21
22
  }
22
23
  else {
23
24
  infection.stage = 0;
@@ -33,7 +34,7 @@ class Infecter {
33
34
  return;
34
35
  }
35
36
  const stages = infectionOptions.stages, stagesCount = stages.length;
36
- if (stage > stagesCount || stage < 0) {
37
+ if (stage > stagesCount || stage < minStage) {
37
38
  return;
38
39
  }
39
40
  infection.delay = 0;
@@ -47,10 +48,10 @@ class Infecter {
47
48
  const stages = infectionOptions.stages, stagesCount = stages.length;
48
49
  if (infection.delay !== undefined && infection.delayStage !== undefined) {
49
50
  const stage = infection.delayStage;
50
- if (stage > stagesCount || stage < 0) {
51
+ if (stage > stagesCount || stage < minStage) {
51
52
  return;
52
53
  }
53
- if (infection.delay >= infectionOptions.delay * 1000) {
54
+ if (infection.delay >= infectionOptions.delay * engine_1.millisecondsToSeconds) {
54
55
  infection.stage = stage;
55
56
  infection.time = 0;
56
57
  delete infection.delay;
@@ -66,8 +67,8 @@ class Infecter {
66
67
  }
67
68
  if (infection.stage !== undefined && infection.time !== undefined) {
68
69
  const infectionStage = stages[infection.stage];
69
- if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
70
- if (infection.time > infectionStage.duration * 1000) {
70
+ if (infectionStage.duration !== undefined && infectionStage.duration >= minDuration) {
71
+ if (infection.time > infectionStage.duration * engine_1.millisecondsToSeconds) {
71
72
  this._nextInfectionStage(particle);
72
73
  }
73
74
  else {
@@ -89,7 +90,7 @@ class Infecter {
89
90
  return;
90
91
  }
91
92
  const stagesCount = options.infection.stages.length;
92
- if (stage > stagesCount || stage < 0 || (infection.stage !== undefined && infection.stage > stage)) {
93
+ if (stage > stagesCount || stage < minStage || (infection.stage !== undefined && infection.stage > stage)) {
93
94
  return;
94
95
  }
95
96
  infection.stage = stage;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InfectionInstance = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  const Infecter_js_1 = require("./Infecter.js");
6
+ const minStage = 0;
6
7
  class InfectionInstance {
7
8
  constructor(container) {
8
9
  this._container = container;
@@ -33,7 +34,7 @@ class InfectionInstance {
33
34
  return infP.infection.stage === undefined;
34
35
  });
35
36
  const infected = (0, engine_1.itemFromArray)(notInfected);
36
- this._container.infecter?.startInfection(infected, 0);
37
+ this._container.infecter?.startInfection(infected, minStage);
37
38
  }
38
39
  }
39
40
  }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.InfectionPlugin = void 0;
27
+ const Infection_js_1 = require("./Options/Classes/Infection.js");
28
+ class InfectionPlugin {
29
+ constructor() {
30
+ this.id = "infection";
31
+ }
32
+ async getPlugin(container) {
33
+ const { InfectionInstance } = await Promise.resolve().then(() => __importStar(require("./InfectionInstance.js")));
34
+ return new InfectionInstance(container);
35
+ }
36
+ loadOptions(options, source) {
37
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
38
+ return;
39
+ }
40
+ let infectionOptions = options.infection;
41
+ if (infectionOptions?.load === undefined) {
42
+ options.infection = infectionOptions = new Infection_js_1.Infection();
43
+ }
44
+ infectionOptions.load(source?.infection);
45
+ }
46
+ needsPlugin(options) {
47
+ return options?.infection?.enable ?? false;
48
+ }
49
+ }
50
+ exports.InfectionPlugin = InfectionPlugin;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParticlesInfecter = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
+ const minStagesCount = 1, double = 2;
5
6
  class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
6
7
  constructor(container) {
7
8
  super(container);
@@ -20,10 +21,10 @@ class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
20
21
  return;
21
22
  }
22
23
  const container = this.container, options = container.actualOptions, infectionOptions = options.infection;
23
- if (!infectionOptions?.enable || infectionOptions.stages.length < 1) {
24
+ if (!infectionOptions?.enable || infectionOptions.stages.length < minStagesCount) {
24
25
  return;
25
26
  }
26
- const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * 2 + 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;
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;
27
28
  for (const p2 of query) {
28
29
  const infP2 = p2;
29
30
  if (infP2 === p1 ||
@@ -45,6 +46,7 @@ class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
45
46
  infecter.updateInfectionStage(p1, infectedStage2);
46
47
  }
47
48
  }
49
+ await Promise.resolve();
48
50
  }
49
51
  isEnabled() {
50
52
  return this.container.actualOptions?.infection?.enable ?? false;
package/cjs/index.js CHANGED
@@ -10,39 +10,30 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
13
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
27
  };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
17
29
  exports.loadInfectionPlugin = void 0;
18
- const Infection_js_1 = require("./Options/Classes/Infection.js");
19
- const InfectionInstance_js_1 = require("./InfectionInstance.js");
20
- const ParticlesInfecter_js_1 = require("./ParticlesInfecter.js");
21
- class InfectionPlugin {
22
- constructor() {
23
- this.id = "infection";
24
- }
25
- getPlugin(container) {
26
- return new InfectionInstance_js_1.InfectionInstance(container);
27
- }
28
- loadOptions(options, source) {
29
- if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
30
- return;
31
- }
32
- let infectionOptions = options.infection;
33
- if (infectionOptions?.load === undefined) {
34
- options.infection = infectionOptions = new Infection_js_1.Infection();
35
- }
36
- infectionOptions.load(source?.infection);
37
- }
38
- needsPlugin(options) {
39
- return options?.infection?.enable ?? false;
40
- }
41
- }
42
30
  async function loadInfectionPlugin(engine, refresh = true) {
43
- const plugin = new InfectionPlugin();
31
+ const { InfectionPlugin } = await Promise.resolve().then(() => __importStar(require("./InfectionPlugin.js"))), plugin = new InfectionPlugin();
44
32
  await engine.addPlugin(plugin, refresh);
45
- await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter_js_1.ParticlesInfecter(container), refresh);
33
+ await engine.addInteractor("particlesInfection", async (container) => {
34
+ const { ParticlesInfecter } = await Promise.resolve().then(() => __importStar(require("./ParticlesInfecter.js")));
35
+ return new ParticlesInfecter(container);
36
+ }, refresh);
46
37
  }
47
38
  exports.loadInfectionPlugin = loadInfectionPlugin;
48
39
  __exportStar(require("./Options/Interfaces/IInfection.js"), exports);
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.2.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_plugin_infection"] = this["webpackChunk_tsparticles_plugin_infection"] || []).push([["dist_browser_InfectionInstance_js"],{
19
+
20
+ /***/ "./dist/browser/Infecter.js":
21
+ /*!**********************************!*\
22
+ !*** ./dist/browser/Infecter.js ***!
23
+ \**********************************/
24
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25
+
26
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Infecter: () => (/* binding */ Infecter)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nconst 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?");
27
+
28
+ /***/ }),
29
+
30
+ /***/ "./dist/browser/InfectionInstance.js":
31
+ /*!*******************************************!*\
32
+ !*** ./dist/browser/InfectionInstance.js ***!
33
+ \*******************************************/
34
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
35
+
36
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ 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 _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\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 ? infectionStages[infectionStage].color : undefined;\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 if (!infP.infection) {\n infP.infection = {};\n }\n return infP.infection.stage === undefined;\n });\n const infected = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromArray)(notInfected);\n this._container.infecter?.startInfection(infected, minStage);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-infection/./dist/browser/InfectionInstance.js?");
37
+
38
+ /***/ })
39
+
40
+ }]);
@@ -0,0 +1,50 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.2.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_plugin_infection"] = this["webpackChunk_tsparticles_plugin_infection"] || []).push([["dist_browser_InfectionPlugin_js"],{
19
+
20
+ /***/ "./dist/browser/InfectionPlugin.js":
21
+ /*!*****************************************!*\
22
+ !*** ./dist/browser/InfectionPlugin.js ***!
23
+ \*****************************************/
24
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25
+
26
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ 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\nclass InfectionPlugin {\n constructor() {\n this.id = \"infection\";\n }\n async getPlugin(container) {\n const {\n InfectionInstance\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_InfectionInstance_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./InfectionInstance.js */ \"./dist/browser/InfectionInstance.js\"));\n return new 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?");
27
+
28
+ /***/ }),
29
+
30
+ /***/ "./dist/browser/Options/Classes/Infection.js":
31
+ /*!***************************************************!*\
32
+ !*** ./dist/browser/Options/Classes/Infection.js ***!
33
+ \***************************************************/
34
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
35
+
36
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Infection: () => (/* binding */ Infection)\n/* harmony export */ });\n/* harmony import */ var _InfectionStage_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./InfectionStage.js */ \"./dist/browser/Options/Classes/InfectionStage.js\");\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 (data === undefined) {\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_0__.InfectionStage();\n s.load(t);\n return s;\n });\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-infection/./dist/browser/Options/Classes/Infection.js?");
37
+
38
+ /***/ }),
39
+
40
+ /***/ "./dist/browser/Options/Classes/InfectionStage.js":
41
+ /*!********************************************************!*\
42
+ !*** ./dist/browser/Options/Classes/InfectionStage.js ***!
43
+ \********************************************************/
44
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
45
+
46
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ InfectionStage: () => (/* binding */ InfectionStage)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass 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 (data === undefined) {\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?");
47
+
48
+ /***/ })
49
+
50
+ }]);
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.2.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_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_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/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\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 async 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 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 const infectedStage2 = infectionStage2?.infectedStage ?? infP2.infection.stage;\n infecter.updateInfectionStage(p1, infectedStage2);\n }\n }\n await Promise.resolve();\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?");
27
+
28
+ /***/ })
29
+
30
+ }]);
package/esm/Infecter.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { millisecondsToSeconds } from "@tsparticles/engine";
2
+ const minStage = 0, minDuration = 0;
1
3
  export class Infecter {
2
4
  constructor(container) {
3
5
  this._nextInfectionStage = (particle) => {
@@ -6,7 +8,7 @@ export class Infecter {
6
8
  return;
7
9
  }
8
10
  const stagesCount = infectionOptions.stages.length;
9
- if (stagesCount <= 0 || infection.stage === undefined) {
11
+ if (stagesCount <= minStage || infection.stage === undefined) {
10
12
  return;
11
13
  }
12
14
  infection.time = 0;
@@ -14,7 +16,6 @@ export class Infecter {
14
16
  if (infectionOptions.cure) {
15
17
  delete infection.stage;
16
18
  delete infection.time;
17
- return;
18
19
  }
19
20
  else {
20
21
  infection.stage = 0;
@@ -30,7 +31,7 @@ export class Infecter {
30
31
  return;
31
32
  }
32
33
  const stages = infectionOptions.stages, stagesCount = stages.length;
33
- if (stage > stagesCount || stage < 0) {
34
+ if (stage > stagesCount || stage < minStage) {
34
35
  return;
35
36
  }
36
37
  infection.delay = 0;
@@ -44,10 +45,10 @@ export class Infecter {
44
45
  const stages = infectionOptions.stages, stagesCount = stages.length;
45
46
  if (infection.delay !== undefined && infection.delayStage !== undefined) {
46
47
  const stage = infection.delayStage;
47
- if (stage > stagesCount || stage < 0) {
48
+ if (stage > stagesCount || stage < minStage) {
48
49
  return;
49
50
  }
50
- if (infection.delay >= infectionOptions.delay * 1000) {
51
+ if (infection.delay >= infectionOptions.delay * millisecondsToSeconds) {
51
52
  infection.stage = stage;
52
53
  infection.time = 0;
53
54
  delete infection.delay;
@@ -63,8 +64,8 @@ export class Infecter {
63
64
  }
64
65
  if (infection.stage !== undefined && infection.time !== undefined) {
65
66
  const infectionStage = stages[infection.stage];
66
- if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
67
- if (infection.time > infectionStage.duration * 1000) {
67
+ if (infectionStage.duration !== undefined && infectionStage.duration >= minDuration) {
68
+ if (infection.time > infectionStage.duration * millisecondsToSeconds) {
68
69
  this._nextInfectionStage(particle);
69
70
  }
70
71
  else {
@@ -86,7 +87,7 @@ export class Infecter {
86
87
  return;
87
88
  }
88
89
  const stagesCount = options.infection.stages.length;
89
- if (stage > stagesCount || stage < 0 || (infection.stage !== undefined && infection.stage > stage)) {
90
+ if (stage > stagesCount || stage < minStage || (infection.stage !== undefined && infection.stage > stage)) {
90
91
  return;
91
92
  }
92
93
  infection.stage = stage;