@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/umd/Infecter.js CHANGED
@@ -4,12 +4,14 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Infecter = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const minStage = 0, minDuration = 0;
13
15
  class Infecter {
14
16
  constructor(container) {
15
17
  this._nextInfectionStage = (particle) => {
@@ -18,7 +20,7 @@
18
20
  return;
19
21
  }
20
22
  const stagesCount = infectionOptions.stages.length;
21
- if (stagesCount <= 0 || infection.stage === undefined) {
23
+ if (stagesCount <= minStage || infection.stage === undefined) {
22
24
  return;
23
25
  }
24
26
  infection.time = 0;
@@ -26,7 +28,6 @@
26
28
  if (infectionOptions.cure) {
27
29
  delete infection.stage;
28
30
  delete infection.time;
29
- return;
30
31
  }
31
32
  else {
32
33
  infection.stage = 0;
@@ -42,7 +43,7 @@
42
43
  return;
43
44
  }
44
45
  const stages = infectionOptions.stages, stagesCount = stages.length;
45
- if (stage > stagesCount || stage < 0) {
46
+ if (stage > stagesCount || stage < minStage) {
46
47
  return;
47
48
  }
48
49
  infection.delay = 0;
@@ -56,10 +57,10 @@
56
57
  const stages = infectionOptions.stages, stagesCount = stages.length;
57
58
  if (infection.delay !== undefined && infection.delayStage !== undefined) {
58
59
  const stage = infection.delayStage;
59
- if (stage > stagesCount || stage < 0) {
60
+ if (stage > stagesCount || stage < minStage) {
60
61
  return;
61
62
  }
62
- if (infection.delay >= infectionOptions.delay * 1000) {
63
+ if (infection.delay >= infectionOptions.delay * engine_1.millisecondsToSeconds) {
63
64
  infection.stage = stage;
64
65
  infection.time = 0;
65
66
  delete infection.delay;
@@ -75,8 +76,8 @@
75
76
  }
76
77
  if (infection.stage !== undefined && infection.time !== undefined) {
77
78
  const infectionStage = stages[infection.stage];
78
- if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
79
- if (infection.time > infectionStage.duration * 1000) {
79
+ if (infectionStage.duration !== undefined && infectionStage.duration >= minDuration) {
80
+ if (infection.time > infectionStage.duration * engine_1.millisecondsToSeconds) {
80
81
  this._nextInfectionStage(particle);
81
82
  }
82
83
  else {
@@ -98,7 +99,7 @@
98
99
  return;
99
100
  }
100
101
  const stagesCount = options.infection.stages.length;
101
- if (stage > stagesCount || stage < 0 || (infection.stage !== undefined && infection.stage > stage)) {
102
+ if (stage > stagesCount || stage < minStage || (infection.stage !== undefined && infection.stage > stage)) {
102
103
  return;
103
104
  }
104
105
  infection.stage = stage;
@@ -12,6 +12,7 @@
12
12
  exports.InfectionInstance = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  const Infecter_js_1 = require("./Infecter.js");
15
+ const minStage = 0;
15
16
  class InfectionInstance {
16
17
  constructor(container) {
17
18
  this._container = container;
@@ -42,7 +43,7 @@
42
43
  return infP.infection.stage === undefined;
43
44
  });
44
45
  const infected = (0, engine_1.itemFromArray)(notInfected);
45
- this._container.infecter?.startInfection(infected, 0);
46
+ this._container.infecter?.startInfection(infected, minStage);
46
47
  }
47
48
  }
48
49
  }
@@ -0,0 +1,61 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
14
+ }) : function(o, v) {
15
+ o["default"] = v;
16
+ });
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
24
+ (function (factory) {
25
+ if (typeof module === "object" && typeof module.exports === "object") {
26
+ var v = factory(require, exports);
27
+ if (v !== undefined) module.exports = v;
28
+ }
29
+ else if (typeof define === "function" && define.amd) {
30
+ define(["require", "exports", "./Options/Classes/Infection.js"], factory);
31
+ }
32
+ })(function (require, exports) {
33
+ "use strict";
34
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.InfectionPlugin = void 0;
37
+ const Infection_js_1 = require("./Options/Classes/Infection.js");
38
+ class InfectionPlugin {
39
+ constructor() {
40
+ this.id = "infection";
41
+ }
42
+ async getPlugin(container) {
43
+ const { InfectionInstance } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./InfectionInstance.js"))) : new Promise((resolve_1, reject_1) => { require(["./InfectionInstance.js"], resolve_1, reject_1); }).then(__importStar));
44
+ return new InfectionInstance(container);
45
+ }
46
+ loadOptions(options, source) {
47
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
48
+ return;
49
+ }
50
+ let infectionOptions = options.infection;
51
+ if (infectionOptions?.load === undefined) {
52
+ options.infection = infectionOptions = new Infection_js_1.Infection();
53
+ }
54
+ infectionOptions.load(source?.infection);
55
+ }
56
+ needsPlugin(options) {
57
+ return options?.infection?.enable ?? false;
58
+ }
59
+ }
60
+ exports.InfectionPlugin = InfectionPlugin;
61
+ });
@@ -11,6 +11,7 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ParticlesInfecter = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
+ const minStagesCount = 1, double = 2;
14
15
  class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
15
16
  constructor(container) {
16
17
  super(container);
@@ -29,10 +30,10 @@
29
30
  return;
30
31
  }
31
32
  const container = this.container, options = container.actualOptions, infectionOptions = options.infection;
32
- if (!infectionOptions?.enable || infectionOptions.stages.length < 1) {
33
+ if (!infectionOptions?.enable || infectionOptions.stages.length < minStagesCount) {
33
34
  return;
34
35
  }
35
- 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;
36
+ 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;
36
37
  for (const p2 of query) {
37
38
  const infP2 = p2;
38
39
  if (infP2 === p1 ||
@@ -54,6 +55,7 @@
54
55
  infecter.updateInfectionStage(p1, infectedStage2);
55
56
  }
56
57
  }
58
+ await Promise.resolve();
57
59
  }
58
60
  isEnabled() {
59
61
  return this.container.actualOptions?.infection?.enable ?? false;
package/umd/index.js CHANGED
@@ -9,6 +9,18 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
9
9
  if (k2 === undefined) k2 = k;
10
10
  o[k2] = m[k];
11
11
  }));
12
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
14
+ }) : function(o, v) {
15
+ o["default"] = v;
16
+ });
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
12
24
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
25
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
26
  };
@@ -18,40 +30,20 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
30
  if (v !== undefined) module.exports = v;
19
31
  }
20
32
  else if (typeof define === "function" && define.amd) {
21
- define(["require", "exports", "./Options/Classes/Infection.js", "./InfectionInstance.js", "./ParticlesInfecter.js", "./Options/Interfaces/IInfection.js", "./Options/Interfaces/IInfectionStage.js"], factory);
33
+ define(["require", "exports", "./Options/Interfaces/IInfection.js", "./Options/Interfaces/IInfectionStage.js"], factory);
22
34
  }
23
35
  })(function (require, exports) {
24
36
  "use strict";
37
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
25
38
  Object.defineProperty(exports, "__esModule", { value: true });
26
39
  exports.loadInfectionPlugin = void 0;
27
- const Infection_js_1 = require("./Options/Classes/Infection.js");
28
- const InfectionInstance_js_1 = require("./InfectionInstance.js");
29
- const ParticlesInfecter_js_1 = require("./ParticlesInfecter.js");
30
- class InfectionPlugin {
31
- constructor() {
32
- this.id = "infection";
33
- }
34
- getPlugin(container) {
35
- return new InfectionInstance_js_1.InfectionInstance(container);
36
- }
37
- loadOptions(options, source) {
38
- if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
39
- return;
40
- }
41
- let infectionOptions = options.infection;
42
- if (infectionOptions?.load === undefined) {
43
- options.infection = infectionOptions = new Infection_js_1.Infection();
44
- }
45
- infectionOptions.load(source?.infection);
46
- }
47
- needsPlugin(options) {
48
- return options?.infection?.enable ?? false;
49
- }
50
- }
51
40
  async function loadInfectionPlugin(engine, refresh = true) {
52
- const plugin = new InfectionPlugin();
41
+ const { InfectionPlugin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./InfectionPlugin.js"))) : new Promise((resolve_1, reject_1) => { require(["./InfectionPlugin.js"], resolve_1, reject_1); }).then(__importStar)), plugin = new InfectionPlugin();
53
42
  await engine.addPlugin(plugin, refresh);
54
- await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter_js_1.ParticlesInfecter(container), refresh);
43
+ await engine.addInteractor("particlesInfection", async (container) => {
44
+ const { ParticlesInfecter } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./ParticlesInfecter.js"))) : new Promise((resolve_2, reject_2) => { require(["./ParticlesInfecter.js"], resolve_2, reject_2); }).then(__importStar));
45
+ return new ParticlesInfecter(container);
46
+ }, refresh);
55
47
  }
56
48
  exports.loadInfectionPlugin = loadInfectionPlugin;
57
49
  __exportStar(require("./Options/Interfaces/IInfection.js"), exports);