@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.
@@ -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/esm/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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/plugin-infection",
3
- "version": "3.0.3",
3
+ "version": "3.2.0",
4
4
  "description": "tsParticles infection plugin",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -100,7 +100,7 @@
100
100
  "./package.json": "./package.json"
101
101
  },
102
102
  "dependencies": {
103
- "@tsparticles/engine": "^3.0.3"
103
+ "@tsparticles/engine": "^3.2.0"
104
104
  },
105
105
  "publishConfig": {
106
106
  "access": "public"
package/report.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8"/>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
- <title>@tsparticles/plugin-infection [26 Dec 2023 at 19:29]</title>
6
+ <title>@tsparticles/plugin-infection [31 Jan 2024 at 02:08]</title>
7
7
  <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6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fAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
8
8
 
9
9
  <script>
@@ -31,8 +31,8 @@
31
31
  <body>
32
32
  <div id="app"></div>
33
33
  <script>
34
- window.chartData = [{"label":"tsparticles.plugin.infection.js","isAsset":true,"statSize":8773,"parsedSize":12446,"gzipSize":3005,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":8731,"groups":[{"id":222,"label":"index.js + 5 modules (concatenated)","path":"./dist/browser/index.js + 5 modules (concatenated)","statSize":8731,"parsedSize":12446,"gzipSize":3005,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser","statSize":8731,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/index.js","statSize":1107,"parsedSize":1578,"gzipSize":381,"inaccurateSizes":true},{"id":null,"label":"InfectionInstance.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/InfectionInstance.js","statSize":1251,"parsedSize":1783,"gzipSize":430,"inaccurateSizes":true},{"label":"Options/Classes","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Options/Classes","statSize":1387,"groups":[{"id":null,"label":"Infection.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Options/Classes/Infection.js","statSize":770,"parsedSize":1097,"gzipSize":265,"inaccurateSizes":true},{"id":null,"label":"InfectionStage.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Options/Classes/InfectionStage.js","statSize":617,"parsedSize":879,"gzipSize":212,"inaccurateSizes":true}],"parsedSize":1977,"gzipSize":477,"inaccurateSizes":true},{"id":null,"label":"ParticlesInfecter.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/ParticlesInfecter.js","statSize":2017,"parsedSize":2875,"gzipSize":694,"inaccurateSizes":true},{"id":null,"label":"Infecter.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Infecter.js","statSize":2969,"parsedSize":4232,"gzipSize":1021,"inaccurateSizes":true}],"parsedSize":12446,"gzipSize":3005,"inaccurateSizes":true}]}],"parsedSize":12446,"gzipSize":3005},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":533,"label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.plugin.infection":true}}];
35
- window.entrypoints = ["tsparticles.plugin.infection","tsparticles.plugin.infection.min"];
34
+ window.chartData = [];
35
+ window.entrypoints = ["tsparticles.plugin.infection.min"];
36
36
  window.defaultSizes = "parsed";
37
37
  </script>
38
38
  </body>