@tsparticles/plugin-infection 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/Infecter.js +97 -0
- package/browser/InfectionInstance.js +37 -0
- package/browser/Options/Classes/Infection.js +35 -0
- package/browser/Options/Classes/InfectionStage.js +25 -0
- package/browser/Options/Interfaces/IInfection.js +1 -0
- package/browser/Options/Interfaces/IInfectionStage.js +1 -0
- package/browser/ParticlesInfecter.js +54 -0
- package/browser/Types.js +1 -0
- package/browser/index.js +32 -0
- package/cjs/Infecter.js +101 -0
- package/cjs/InfectionInstance.js +41 -0
- package/cjs/Options/Classes/Infection.js +39 -0
- package/cjs/Options/Classes/InfectionStage.js +29 -0
- package/cjs/Options/Interfaces/IInfection.js +2 -0
- package/cjs/Options/Interfaces/IInfectionStage.js +2 -0
- package/cjs/ParticlesInfecter.js +69 -0
- package/cjs/Types.js +2 -0
- package/cjs/index.js +61 -0
- package/esm/Infecter.js +97 -0
- package/esm/InfectionInstance.js +37 -0
- package/esm/Options/Classes/Infection.js +35 -0
- package/esm/Options/Classes/InfectionStage.js +25 -0
- package/esm/Options/Interfaces/IInfection.js +1 -0
- package/esm/Options/Interfaces/IInfectionStage.js +1 -0
- package/esm/ParticlesInfecter.js +54 -0
- package/esm/Types.js +1 -0
- package/esm/index.js +32 -0
- package/package.json +91 -0
- package/report.html +39 -0
- package/tsparticles.plugin.infection.js +387 -0
- package/tsparticles.plugin.infection.min.js +2 -0
- package/tsparticles.plugin.infection.min.js.LICENSE.txt +8 -0
- package/types/Infecter.d.ts +9 -0
- package/types/InfectionInstance.d.ts +9 -0
- package/types/Options/Classes/Infection.d.ts +12 -0
- package/types/Options/Classes/InfectionStage.d.ts +12 -0
- package/types/Options/Interfaces/IInfection.d.ts +8 -0
- package/types/Options/Interfaces/IInfectionStage.d.ts +8 -0
- package/types/ParticlesInfecter.d.ts +11 -0
- package/types/Types.d.ts +24 -0
- package/types/index.d.ts +4 -0
- package/umd/Infecter.js +111 -0
- package/umd/InfectionInstance.js +51 -0
- package/umd/Options/Classes/Infection.js +49 -0
- package/umd/Options/Classes/InfectionStage.js +39 -0
- package/umd/Options/Interfaces/IInfection.js +12 -0
- package/umd/Options/Interfaces/IInfectionStage.js +12 -0
- package/umd/ParticlesInfecter.js +68 -0
- package/umd/Types.js +12 -0
- package/umd/index.js +60 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./Infecter", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.InfectionInstance = void 0;
|
|
13
|
+
const Infecter_1 = require("./Infecter");
|
|
14
|
+
const engine_1 = require("@tsparticles/engine");
|
|
15
|
+
class InfectionInstance {
|
|
16
|
+
constructor(container) {
|
|
17
|
+
this.container = container;
|
|
18
|
+
this.container.infecter = new Infecter_1.Infecter(this.container);
|
|
19
|
+
}
|
|
20
|
+
particleFillColor(particle) {
|
|
21
|
+
const options = this.container.actualOptions;
|
|
22
|
+
if (!particle.infection || !options.infection) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const infectionStage = particle.infection.stage, infection = options.infection, infectionStages = infection.stages;
|
|
26
|
+
return infectionStage !== undefined ? infectionStages[infectionStage].color : undefined;
|
|
27
|
+
}
|
|
28
|
+
particleStrokeColor(particle) {
|
|
29
|
+
return this.particleFillColor(particle);
|
|
30
|
+
}
|
|
31
|
+
particlesSetup() {
|
|
32
|
+
var _a;
|
|
33
|
+
const options = this.container.actualOptions;
|
|
34
|
+
if (!options.infection) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
for (let i = 0; i < options.infection.infections; i++) {
|
|
38
|
+
const notInfected = this.container.particles.array.filter((p) => {
|
|
39
|
+
const infP = p;
|
|
40
|
+
if (!infP.infection) {
|
|
41
|
+
infP.infection = {};
|
|
42
|
+
}
|
|
43
|
+
return infP.infection.stage === undefined;
|
|
44
|
+
});
|
|
45
|
+
const infected = (0, engine_1.itemFromArray)(notInfected);
|
|
46
|
+
(_a = this.container.infecter) === null || _a === void 0 ? void 0 : _a.startInfection(infected, 0);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.InfectionInstance = InfectionInstance;
|
|
51
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./InfectionStage"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Infection = void 0;
|
|
13
|
+
const InfectionStage_1 = require("./InfectionStage");
|
|
14
|
+
class Infection {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.cure = false;
|
|
17
|
+
this.delay = 0;
|
|
18
|
+
this.enable = false;
|
|
19
|
+
this.infections = 0;
|
|
20
|
+
this.stages = [];
|
|
21
|
+
}
|
|
22
|
+
load(data) {
|
|
23
|
+
if (data === undefined) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (data.cure !== undefined) {
|
|
27
|
+
this.cure = data.cure;
|
|
28
|
+
}
|
|
29
|
+
if (data.delay !== undefined) {
|
|
30
|
+
this.delay = data.delay;
|
|
31
|
+
}
|
|
32
|
+
if (data.enable !== undefined) {
|
|
33
|
+
this.enable = data.enable;
|
|
34
|
+
}
|
|
35
|
+
if (data.infections !== undefined) {
|
|
36
|
+
this.infections = data.infections;
|
|
37
|
+
}
|
|
38
|
+
if (data.stages === undefined) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.stages = data.stages.map((t) => {
|
|
42
|
+
const s = new InfectionStage_1.InfectionStage();
|
|
43
|
+
s.load(t);
|
|
44
|
+
return s;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.Infection = Infection;
|
|
49
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.InfectionStage = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class InfectionStage {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.color = new engine_1.OptionsColor();
|
|
17
|
+
this.color.value = "#ff0000";
|
|
18
|
+
this.radius = 0;
|
|
19
|
+
this.rate = 1;
|
|
20
|
+
}
|
|
21
|
+
load(data) {
|
|
22
|
+
if (data === undefined) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (data.color !== undefined) {
|
|
26
|
+
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
27
|
+
}
|
|
28
|
+
this.duration = data.duration;
|
|
29
|
+
this.infectedStage = data.infectedStage;
|
|
30
|
+
if (data.radius !== undefined) {
|
|
31
|
+
this.radius = data.radius;
|
|
32
|
+
}
|
|
33
|
+
if (data.rate !== undefined) {
|
|
34
|
+
this.rate = data.rate;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.InfectionStage = InfectionStage;
|
|
39
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ParticlesInfecter = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
|
|
15
|
+
constructor(container) {
|
|
16
|
+
super(container);
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
}
|
|
20
|
+
init() {
|
|
21
|
+
}
|
|
22
|
+
async interact(p1, delta) {
|
|
23
|
+
var _a, _b, _c, _d, _e;
|
|
24
|
+
const infecter = this.container.infecter;
|
|
25
|
+
if (!infecter) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
infecter.updateInfection(p1, delta.value);
|
|
29
|
+
if (((_a = p1.infection) === null || _a === void 0 ? void 0 : _a.stage) === undefined) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const container = this.container, options = container.actualOptions, infectionOptions = options.infection;
|
|
33
|
+
if (!(infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.enable) || infectionOptions.stages.length < 1) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * 2 + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = (_b = infectionStage1.infectedStage) !== null && _b !== void 0 ? _b : p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
|
|
37
|
+
for (const p2 of query) {
|
|
38
|
+
const infP2 = p2;
|
|
39
|
+
if (infP2 === p1 ||
|
|
40
|
+
infP2.destroyed ||
|
|
41
|
+
infP2.spawning ||
|
|
42
|
+
!(((_c = infP2.infection) === null || _c === void 0 ? void 0 : _c.stage) === undefined || infP2.infection.stage !== p1.infection.stage)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if ((0, engine_1.getRandom)() < infections / neighbors) {
|
|
46
|
+
if (((_d = infP2.infection) === null || _d === void 0 ? void 0 : _d.stage) === undefined) {
|
|
47
|
+
infecter.startInfection(infP2, infectedStage1);
|
|
48
|
+
}
|
|
49
|
+
else if (infP2.infection.stage < p1.infection.stage) {
|
|
50
|
+
infecter.updateInfectionStage(infP2, infectedStage1);
|
|
51
|
+
}
|
|
52
|
+
else if (infP2.infection.stage > p1.infection.stage) {
|
|
53
|
+
const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
|
|
54
|
+
const infectedStage2 = (_e = infectionStage2 === null || infectionStage2 === void 0 ? void 0 : infectionStage2.infectedStage) !== null && _e !== void 0 ? _e : infP2.infection.stage;
|
|
55
|
+
infecter.updateInfectionStage(p1, infectedStage2);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
isEnabled() {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
return (_c = (_b = (_a = this.container.actualOptions) === null || _a === void 0 ? void 0 : _a.infection) === null || _b === void 0 ? void 0 : _b.enable) !== null && _c !== void 0 ? _c : false;
|
|
63
|
+
}
|
|
64
|
+
reset() {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ParticlesInfecter = ParticlesInfecter;
|
|
68
|
+
});
|
package/umd/Types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
|
+
};
|
|
15
|
+
(function (factory) {
|
|
16
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
17
|
+
var v = factory(require, exports);
|
|
18
|
+
if (v !== undefined) module.exports = v;
|
|
19
|
+
}
|
|
20
|
+
else if (typeof define === "function" && define.amd) {
|
|
21
|
+
define(["require", "exports", "./Options/Classes/Infection", "./InfectionInstance", "./ParticlesInfecter", "./Options/Interfaces/IInfection", "./Options/Interfaces/IInfectionStage"], factory);
|
|
22
|
+
}
|
|
23
|
+
})(function (require, exports) {
|
|
24
|
+
"use strict";
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.loadInfectionPlugin = void 0;
|
|
27
|
+
const Infection_1 = require("./Options/Classes/Infection");
|
|
28
|
+
const InfectionInstance_1 = require("./InfectionInstance");
|
|
29
|
+
const ParticlesInfecter_1 = require("./ParticlesInfecter");
|
|
30
|
+
class InfectionPlugin {
|
|
31
|
+
constructor() {
|
|
32
|
+
this.id = "infection";
|
|
33
|
+
}
|
|
34
|
+
getPlugin(container) {
|
|
35
|
+
return new InfectionInstance_1.InfectionInstance(container);
|
|
36
|
+
}
|
|
37
|
+
loadOptions(options, source) {
|
|
38
|
+
if (!this.needsPlugin(source)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
let infectionOptions = options.infection;
|
|
42
|
+
if ((infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.load) === undefined) {
|
|
43
|
+
options.infection = infectionOptions = new Infection_1.Infection();
|
|
44
|
+
}
|
|
45
|
+
infectionOptions.load(source === null || source === void 0 ? void 0 : source.infection);
|
|
46
|
+
}
|
|
47
|
+
needsPlugin(options) {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return (_b = (_a = options === null || options === void 0 ? void 0 : options.infection) === null || _a === void 0 ? void 0 : _a.enable) !== null && _b !== void 0 ? _b : false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function loadInfectionPlugin(engine) {
|
|
53
|
+
const plugin = new InfectionPlugin();
|
|
54
|
+
await engine.addPlugin(plugin);
|
|
55
|
+
await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter_1.ParticlesInfecter(container));
|
|
56
|
+
}
|
|
57
|
+
exports.loadInfectionPlugin = loadInfectionPlugin;
|
|
58
|
+
__exportStar(require("./Options/Interfaces/IInfection"), exports);
|
|
59
|
+
__exportStar(require("./Options/Interfaces/IInfectionStage"), exports);
|
|
60
|
+
});
|