@tsparticles/updater-destroy 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/DestroyUpdater.js +125 -0
- package/browser/Enums/DestroyMode.js +1 -0
- package/browser/Options/Classes/Destroy.js +21 -0
- package/browser/Options/Classes/DestroyBounds.js +20 -0
- package/browser/Options/Classes/Split.js +27 -0
- package/browser/Options/Classes/SplitFactor.js +7 -0
- package/browser/Options/Classes/SplitRate.js +7 -0
- package/browser/Options/Interfaces/IDestroy.js +1 -0
- package/browser/Options/Interfaces/IDestroyBounds.js +1 -0
- package/browser/Options/Interfaces/ISplit.js +1 -0
- package/browser/index.js +4 -0
- package/cjs/DestroyUpdater.js +129 -0
- package/cjs/Enums/DestroyMode.js +2 -0
- package/cjs/Options/Classes/Destroy.js +25 -0
- package/cjs/Options/Classes/DestroyBounds.js +24 -0
- package/cjs/Options/Classes/Split.js +31 -0
- package/cjs/Options/Classes/SplitFactor.js +11 -0
- package/cjs/Options/Classes/SplitRate.js +11 -0
- package/cjs/Options/Interfaces/IDestroy.js +2 -0
- package/cjs/Options/Interfaces/IDestroyBounds.js +2 -0
- package/cjs/Options/Interfaces/ISplit.js +2 -0
- package/cjs/index.js +19 -0
- package/esm/DestroyUpdater.js +125 -0
- package/esm/Enums/DestroyMode.js +1 -0
- package/esm/Options/Classes/Destroy.js +21 -0
- package/esm/Options/Classes/DestroyBounds.js +20 -0
- package/esm/Options/Classes/Split.js +27 -0
- package/esm/Options/Classes/SplitFactor.js +7 -0
- package/esm/Options/Classes/SplitRate.js +7 -0
- package/esm/Options/Interfaces/IDestroy.js +1 -0
- package/esm/Options/Interfaces/IDestroyBounds.js +1 -0
- package/esm/Options/Interfaces/ISplit.js +1 -0
- package/esm/index.js +4 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.updater.destroy.js +327 -0
- package/tsparticles.updater.destroy.min.js +2 -0
- package/tsparticles.updater.destroy.min.js.LICENSE.txt +8 -0
- package/types/DestroyUpdater.d.ts +27 -0
- package/types/Enums/DestroyMode.d.ts +4 -0
- package/types/Options/Classes/Destroy.d.ts +12 -0
- package/types/Options/Classes/DestroyBounds.d.ts +9 -0
- package/types/Options/Classes/Split.d.ts +13 -0
- package/types/Options/Classes/SplitFactor.d.ts +4 -0
- package/types/Options/Classes/SplitRate.d.ts +4 -0
- package/types/Options/Interfaces/IDestroy.d.ts +8 -0
- package/types/Options/Interfaces/IDestroyBounds.d.ts +7 -0
- package/types/Options/Interfaces/ISplit.d.ts +8 -0
- package/types/index.d.ts +2 -0
- package/umd/DestroyUpdater.js +139 -0
- package/umd/Enums/DestroyMode.js +12 -0
- package/umd/Options/Classes/Destroy.js +35 -0
- package/umd/Options/Classes/DestroyBounds.js +34 -0
- package/umd/Options/Classes/Split.js +41 -0
- package/umd/Options/Classes/SplitFactor.js +21 -0
- package/umd/Options/Classes/SplitRate.js +21 -0
- package/umd/Options/Interfaces/IDestroy.js +12 -0
- package/umd/Options/Interfaces/IDestroyBounds.js +12 -0
- package/umd/Options/Interfaces/ISplit.js +12 -0
- package/umd/index.js +18 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { getRangeValue, getValue, itemFromSingleOrMultiple, loadParticlesOptions, randomInRange, setRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
import { Destroy } from "./Options/Classes/Destroy";
|
|
3
|
+
export class DestroyUpdater {
|
|
4
|
+
constructor(engine, container) {
|
|
5
|
+
this.engine = engine;
|
|
6
|
+
this.container = container;
|
|
7
|
+
}
|
|
8
|
+
init(particle) {
|
|
9
|
+
const container = this.container, particlesOptions = particle.options, destroyOptions = particlesOptions.destroy;
|
|
10
|
+
if (!destroyOptions) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
particle.splitCount = 0;
|
|
14
|
+
const destroyBounds = destroyOptions.bounds;
|
|
15
|
+
if (!particle.destroyBounds) {
|
|
16
|
+
particle.destroyBounds = {};
|
|
17
|
+
}
|
|
18
|
+
if (destroyBounds.bottom) {
|
|
19
|
+
particle.destroyBounds.bottom = (getRangeValue(destroyBounds.bottom) * container.canvas.size.height) / 100;
|
|
20
|
+
}
|
|
21
|
+
if (destroyBounds.left) {
|
|
22
|
+
particle.destroyBounds.left = (getRangeValue(destroyBounds.left) * container.canvas.size.width) / 100;
|
|
23
|
+
}
|
|
24
|
+
if (destroyBounds.right) {
|
|
25
|
+
particle.destroyBounds.right = (getRangeValue(destroyBounds.right) * container.canvas.size.width) / 100;
|
|
26
|
+
}
|
|
27
|
+
if (destroyBounds.top) {
|
|
28
|
+
particle.destroyBounds.top = (getRangeValue(destroyBounds.top) * container.canvas.size.height) / 100;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
isEnabled(particle) {
|
|
32
|
+
return !particle.destroyed;
|
|
33
|
+
}
|
|
34
|
+
loadOptions(options, ...sources) {
|
|
35
|
+
if (!options.destroy) {
|
|
36
|
+
options.destroy = new Destroy();
|
|
37
|
+
}
|
|
38
|
+
for (const source of sources) {
|
|
39
|
+
options.destroy.load(source === null || source === void 0 ? void 0 : source.destroy);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
particleDestroyed(particle, override) {
|
|
43
|
+
if (override) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const destroyOptions = particle.options.destroy;
|
|
47
|
+
if (destroyOptions && destroyOptions.mode === "split") {
|
|
48
|
+
this.split(particle);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
update(particle) {
|
|
52
|
+
if (!this.isEnabled(particle)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const position = particle.getPosition(), bounds = particle.destroyBounds;
|
|
56
|
+
if (!bounds) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if ((bounds.bottom !== undefined && position.y >= bounds.bottom) ||
|
|
60
|
+
(bounds.left !== undefined && position.x <= bounds.left) ||
|
|
61
|
+
(bounds.right !== undefined && position.x >= bounds.right) ||
|
|
62
|
+
(bounds.top !== undefined && position.y <= bounds.top)) {
|
|
63
|
+
particle.destroy();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
addSplitParticle(parent, splitParticlesOptions) {
|
|
67
|
+
const destroyOptions = parent.options.destroy;
|
|
68
|
+
if (!destroyOptions) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const splitOptions = destroyOptions.split, options = loadParticlesOptions(this.engine, this.container, parent.options), factor = getValue(splitOptions.factor);
|
|
72
|
+
options.color.load({
|
|
73
|
+
value: {
|
|
74
|
+
hsl: parent.getFillColor(),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
options.move.load({
|
|
78
|
+
center: {
|
|
79
|
+
x: parent.position.x,
|
|
80
|
+
y: parent.position.y,
|
|
81
|
+
mode: "precise",
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
if (typeof options.size.value === "number") {
|
|
85
|
+
options.size.value /= factor;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
options.size.value.min /= factor;
|
|
89
|
+
options.size.value.max /= factor;
|
|
90
|
+
}
|
|
91
|
+
options.load(splitParticlesOptions);
|
|
92
|
+
const offset = splitOptions.sizeOffset ? setRangeValue(-parent.size.value, parent.size.value) : 0, position = {
|
|
93
|
+
x: parent.position.x + randomInRange(offset),
|
|
94
|
+
y: parent.position.y + randomInRange(offset),
|
|
95
|
+
};
|
|
96
|
+
return this.container.particles.addParticle(position, options, parent.group, (particle) => {
|
|
97
|
+
var _a;
|
|
98
|
+
if (particle.size.value < 0.5) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
particle.velocity.length = randomInRange(setRangeValue(parent.velocity.length, particle.velocity.length));
|
|
102
|
+
particle.splitCount = ((_a = parent.splitCount) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
103
|
+
particle.unbreakable = true;
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
particle.unbreakable = false;
|
|
106
|
+
}, 500);
|
|
107
|
+
return true;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
split(particle) {
|
|
111
|
+
const destroyOptions = particle.options.destroy;
|
|
112
|
+
if (!destroyOptions) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const splitOptions = destroyOptions.split;
|
|
116
|
+
if (splitOptions.count >= 0 &&
|
|
117
|
+
(particle.splitCount === undefined || particle.splitCount++ > splitOptions.count)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const rate = getValue(splitOptions.rate), particlesSplitOptions = itemFromSingleOrMultiple(splitOptions.particles);
|
|
121
|
+
for (let i = 0; i < rate; i++) {
|
|
122
|
+
this.addSplitParticle(particle, particlesSplitOptions);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DestroyBounds } from "./DestroyBounds";
|
|
2
|
+
import { Split } from "./Split";
|
|
3
|
+
export class Destroy {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.bounds = new DestroyBounds();
|
|
6
|
+
this.mode = "none";
|
|
7
|
+
this.split = new Split();
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (!data) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.mode) {
|
|
14
|
+
this.mode = data.mode;
|
|
15
|
+
}
|
|
16
|
+
if (data.bounds) {
|
|
17
|
+
this.bounds.load(data.bounds);
|
|
18
|
+
}
|
|
19
|
+
this.split.load(data.split);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
export class DestroyBounds {
|
|
3
|
+
load(data) {
|
|
4
|
+
if (!data) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (data.bottom !== undefined) {
|
|
8
|
+
this.bottom = setRangeValue(data.bottom);
|
|
9
|
+
}
|
|
10
|
+
if (data.left !== undefined) {
|
|
11
|
+
this.left = setRangeValue(data.left);
|
|
12
|
+
}
|
|
13
|
+
if (data.right !== undefined) {
|
|
14
|
+
this.right = setRangeValue(data.right);
|
|
15
|
+
}
|
|
16
|
+
if (data.top !== undefined) {
|
|
17
|
+
this.top = setRangeValue(data.top);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { deepExtend, executeOnSingleOrMultiple } from "@tsparticles/engine";
|
|
2
|
+
import { SplitFactor } from "./SplitFactor";
|
|
3
|
+
import { SplitRate } from "./SplitRate";
|
|
4
|
+
export class Split {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.count = 1;
|
|
7
|
+
this.factor = new SplitFactor();
|
|
8
|
+
this.rate = new SplitRate();
|
|
9
|
+
this.sizeOffset = true;
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (data.count !== undefined) {
|
|
16
|
+
this.count = data.count;
|
|
17
|
+
}
|
|
18
|
+
this.factor.load(data.factor);
|
|
19
|
+
this.rate.load(data.rate);
|
|
20
|
+
this.particles = executeOnSingleOrMultiple(data.particles, (particles) => {
|
|
21
|
+
return deepExtend({}, particles);
|
|
22
|
+
});
|
|
23
|
+
if (data.sizeOffset !== undefined) {
|
|
24
|
+
this.sizeOffset = data.sizeOffset;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsparticles/updater-destroy",
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
|
+
"description": "tsParticles particles destroy updater",
|
|
5
|
+
"homepage": "https://particles.js.org",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/matteobruni/tsparticles.git",
|
|
9
|
+
"directory": "updaters/destroy"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"front-end",
|
|
13
|
+
"frontend",
|
|
14
|
+
"tsparticles",
|
|
15
|
+
"particles.js",
|
|
16
|
+
"particlesjs",
|
|
17
|
+
"particles",
|
|
18
|
+
"particle",
|
|
19
|
+
"canvas",
|
|
20
|
+
"jsparticles",
|
|
21
|
+
"xparticles",
|
|
22
|
+
"particles-js",
|
|
23
|
+
"particles-bg",
|
|
24
|
+
"particles-bg-vue",
|
|
25
|
+
"particles-ts",
|
|
26
|
+
"particles.ts",
|
|
27
|
+
"react-particles-js",
|
|
28
|
+
"react-particles.js",
|
|
29
|
+
"react-particles",
|
|
30
|
+
"react",
|
|
31
|
+
"reactjs",
|
|
32
|
+
"vue-particles",
|
|
33
|
+
"ngx-particles",
|
|
34
|
+
"angular-particles",
|
|
35
|
+
"particleground",
|
|
36
|
+
"vue",
|
|
37
|
+
"vuejs",
|
|
38
|
+
"preact",
|
|
39
|
+
"preactjs",
|
|
40
|
+
"jquery",
|
|
41
|
+
"angularjs",
|
|
42
|
+
"angular",
|
|
43
|
+
"typescript",
|
|
44
|
+
"javascript",
|
|
45
|
+
"animation",
|
|
46
|
+
"web",
|
|
47
|
+
"html5",
|
|
48
|
+
"web-design",
|
|
49
|
+
"webdesign",
|
|
50
|
+
"css",
|
|
51
|
+
"html",
|
|
52
|
+
"css3",
|
|
53
|
+
"animated",
|
|
54
|
+
"background",
|
|
55
|
+
"confetti",
|
|
56
|
+
"canvas",
|
|
57
|
+
"fireworks",
|
|
58
|
+
"fireworks-js",
|
|
59
|
+
"confetti-js",
|
|
60
|
+
"confettijs",
|
|
61
|
+
"fireworksjs",
|
|
62
|
+
"canvas-confetti",
|
|
63
|
+
"@tsparticles/plugin",
|
|
64
|
+
"@tsparticles/updater"
|
|
65
|
+
],
|
|
66
|
+
"author": "Matteo Bruni <matteo.bruni@me.com>",
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/matteobruni/tsparticles/issues"
|
|
70
|
+
},
|
|
71
|
+
"main": "cjs/index.js",
|
|
72
|
+
"jsdelivr": "tsparticles.updater.destroy.min.js",
|
|
73
|
+
"unpkg": "tsparticles.updater.destroy.min.js",
|
|
74
|
+
"module": "esm/index.js",
|
|
75
|
+
"types": "types/index.d.ts",
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public"
|
|
78
|
+
},
|
|
79
|
+
"dependencies": {
|
|
80
|
+
"@tsparticles/engine": "^3.0.0-alpha.0"
|
|
81
|
+
}
|
|
82
|
+
}
|