@tsparticles/updater-destroy 4.0.0-beta.9 → 4.0.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/browser/DestroyUpdater.js +44 -4
- package/browser/Enums/DestroyMode.js +1 -0
- package/browser/Options/Classes/Destroy.js +4 -0
- package/browser/Options/Classes/Explode.js +20 -0
- package/browser/Options/Interfaces/IExplode.js +1 -0
- package/browser/Utils.js +1 -1
- package/browser/browser.js +5 -0
- package/browser/index.js +4 -4
- package/browser/index.lazy.js +9 -0
- package/cjs/DestroyUpdater.js +44 -4
- package/cjs/Enums/DestroyMode.js +1 -0
- package/cjs/Options/Classes/Destroy.js +4 -0
- package/cjs/Options/Classes/Explode.js +20 -0
- package/cjs/Options/Interfaces/IExplode.js +1 -0
- package/cjs/Utils.js +1 -1
- package/cjs/browser.js +5 -0
- package/cjs/index.js +4 -4
- package/cjs/index.lazy.js +9 -0
- package/esm/DestroyUpdater.js +44 -4
- package/esm/Enums/DestroyMode.js +1 -0
- package/esm/Options/Classes/Destroy.js +4 -0
- package/esm/Options/Classes/Explode.js +20 -0
- package/esm/Options/Interfaces/IExplode.js +1 -0
- package/esm/Utils.js +1 -1
- package/esm/browser.js +5 -0
- package/esm/index.js +4 -4
- package/esm/index.lazy.js +9 -0
- package/package.json +9 -2
- package/report.html +4949 -94
- package/tsparticles.updater.destroy.js +371 -310
- package/tsparticles.updater.destroy.min.js +1 -2
- package/types/DestroyUpdater.d.ts +2 -2
- package/types/Enums/DestroyMode.d.ts +1 -0
- package/types/Options/Classes/Destroy.d.ts +2 -0
- package/types/Options/Classes/Explode.d.ts +8 -0
- package/types/Options/Interfaces/IDestroy.d.ts +2 -0
- package/types/Options/Interfaces/IExplode.d.ts +4 -0
- package/types/Types.d.ts +8 -0
- package/types/browser.d.ts +1 -0
- package/types/index.lazy.d.ts +2 -0
- package/960.min.js +0 -1
- package/dist_browser_DestroyUpdater_js.js +0 -100
|
@@ -2,6 +2,7 @@ import { getRangeValue, percentDenominator, } from "@tsparticles/engine";
|
|
|
2
2
|
import { Destroy } from "./Options/Classes/Destroy.js";
|
|
3
3
|
import { DestroyMode } from "./Enums/DestroyMode.js";
|
|
4
4
|
import { split } from "./Utils.js";
|
|
5
|
+
const defaultDeltaFactor = 1, fpsFactor = 60, minExplodeSpeed = 0.01, maxExplodeProgress = 1;
|
|
5
6
|
export class DestroyUpdater {
|
|
6
7
|
_container;
|
|
7
8
|
_pluginManager;
|
|
@@ -14,6 +15,7 @@ export class DestroyUpdater {
|
|
|
14
15
|
if (!destroyOptions) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
18
|
+
particle.exploding = undefined;
|
|
17
19
|
particle.splitCount = 0;
|
|
18
20
|
const destroyBoundsOptions = destroyOptions.bounds;
|
|
19
21
|
particle.destroyBounds ??= {};
|
|
@@ -32,7 +34,8 @@ export class DestroyUpdater {
|
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
isEnabled(particle) {
|
|
35
|
-
|
|
37
|
+
const destroyParticle = particle;
|
|
38
|
+
return !destroyParticle.destroyed || !!destroyParticle.exploding;
|
|
36
39
|
}
|
|
37
40
|
loadOptions(options, ...sources) {
|
|
38
41
|
options.destroy ??= new Destroy();
|
|
@@ -45,11 +48,48 @@ export class DestroyUpdater {
|
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
50
|
const destroyOptions = particle.options.destroy;
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
switch (destroyOptions?.mode) {
|
|
52
|
+
case DestroyMode.split:
|
|
53
|
+
split(this._pluginManager, this._container, particle);
|
|
54
|
+
break;
|
|
55
|
+
case DestroyMode.explode: {
|
|
56
|
+
if (particle.exploding) {
|
|
57
|
+
particle.destroyed = false;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
const { explode } = destroyOptions, initialSize = particle.size.value, maxSize = initialSize * explode.maxSizeFactor, opacity = particle.getOpacity();
|
|
61
|
+
particle.exploding = {
|
|
62
|
+
initialFillOpacity: opacity.fillOpacity,
|
|
63
|
+
initialSize,
|
|
64
|
+
initialStrokeOpacity: opacity.strokeOpacity,
|
|
65
|
+
maxSize,
|
|
66
|
+
progress: 0,
|
|
67
|
+
speed: Math.max(explode.speed, minExplodeSpeed),
|
|
68
|
+
};
|
|
69
|
+
particle.fillOpacity = opacity.fillOpacity;
|
|
70
|
+
particle.strokeOpacity = opacity.strokeOpacity;
|
|
71
|
+
particle.destroyed = false;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
break;
|
|
50
76
|
}
|
|
51
77
|
}
|
|
52
|
-
update(particle) {
|
|
78
|
+
update(particle, delta) {
|
|
79
|
+
if (particle.exploding) {
|
|
80
|
+
const explosionState = particle.exploding, deltaFactor = delta.factor || defaultDeltaFactor;
|
|
81
|
+
explosionState.progress = Math.min(maxExplodeProgress, explosionState.progress + (explosionState.speed * deltaFactor) / fpsFactor);
|
|
82
|
+
const progress = explosionState.progress;
|
|
83
|
+
particle.size.value =
|
|
84
|
+
explosionState.initialSize + (explosionState.maxSize - explosionState.initialSize) * progress;
|
|
85
|
+
particle.fillOpacity = explosionState.initialFillOpacity * (maxExplodeProgress - progress);
|
|
86
|
+
particle.strokeOpacity = explosionState.initialStrokeOpacity * (maxExplodeProgress - progress);
|
|
87
|
+
if (progress >= maxExplodeProgress) {
|
|
88
|
+
particle.exploding = undefined;
|
|
89
|
+
particle.destroy(true);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
53
93
|
if (particle.unbreakableUntil !== undefined && performance.now() >= particle.unbreakableUntil) {
|
|
54
94
|
particle.unbreakable = false;
|
|
55
95
|
particle.unbreakableUntil = undefined;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { isNull } from "@tsparticles/engine";
|
|
2
2
|
import { DestroyBounds } from "./DestroyBounds.js";
|
|
3
3
|
import { DestroyMode } from "../../Enums/DestroyMode.js";
|
|
4
|
+
import { Explode } from "./Explode.js";
|
|
4
5
|
import { Split } from "./Split.js";
|
|
5
6
|
export class Destroy {
|
|
6
7
|
bounds;
|
|
8
|
+
explode;
|
|
7
9
|
mode;
|
|
8
10
|
split;
|
|
9
11
|
constructor() {
|
|
10
12
|
this.bounds = new DestroyBounds();
|
|
13
|
+
this.explode = new Explode();
|
|
11
14
|
this.mode = DestroyMode.none;
|
|
12
15
|
this.split = new Split();
|
|
13
16
|
}
|
|
@@ -21,6 +24,7 @@ export class Destroy {
|
|
|
21
24
|
if (data.bounds) {
|
|
22
25
|
this.bounds.load(data.bounds);
|
|
23
26
|
}
|
|
27
|
+
this.explode.load(data.explode);
|
|
24
28
|
this.split.load(data.split);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class Explode {
|
|
3
|
+
maxSizeFactor;
|
|
4
|
+
speed;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.maxSizeFactor = 3;
|
|
7
|
+
this.speed = 2;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (isNull(data)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.maxSizeFactor !== undefined) {
|
|
14
|
+
this.maxSizeFactor = data.maxSizeFactor;
|
|
15
|
+
}
|
|
16
|
+
if (data.speed !== undefined) {
|
|
17
|
+
this.speed = data.speed;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/Utils.js
CHANGED
|
@@ -53,7 +53,7 @@ function addSplitParticle(pluginManager, container, parent, splitParticlesOption
|
|
|
53
53
|
splitParticleOptions.size.value.max *= factor;
|
|
54
54
|
}
|
|
55
55
|
splitParticleOptions.load(splitParticlesOptions);
|
|
56
|
-
const
|
|
56
|
+
const splitParticlePaintOptions = itemFromSingleOrMultiple(splitParticleOptions.paint), splitParticleFillOptions = splitParticlePaintOptions?.fill, splitParticleStrokeOptions = splitParticlePaintOptions?.stroke, fillColor = resolveSplitColor(splitOptions.fillColorOffset, splitFillColor, splitParticleFillOptions?.color, parentFillColor), strokeColor = resolveSplitColor(splitOptions.strokeColorOffset, splitStrokeColor, splitParticleStrokeOptions?.color, parentStrokeColor);
|
|
57
57
|
if (fillColor && splitParticleFillOptions) {
|
|
58
58
|
splitParticleFillOptions.color = fillColor;
|
|
59
59
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { DestroyUpdater } from "./DestroyUpdater.js";
|
|
1
2
|
export async function loadDestroyUpdater(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0
|
|
3
|
+
engine.checkVersion("4.0.0");
|
|
3
4
|
await engine.pluginManager.register(e => {
|
|
4
|
-
e.pluginManager.addParticleUpdater("destroy",
|
|
5
|
-
|
|
6
|
-
return new DestroyUpdater(e.pluginManager, container);
|
|
5
|
+
e.pluginManager.addParticleUpdater("destroy", container => {
|
|
6
|
+
return Promise.resolve(new DestroyUpdater(e.pluginManager, container));
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export async function loadDestroyUpdater(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addParticleUpdater("destroy", async (container) => {
|
|
5
|
+
const { DestroyUpdater } = await import("./DestroyUpdater.js");
|
|
6
|
+
return new DestroyUpdater(e.pluginManager, container);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
}
|
package/cjs/DestroyUpdater.js
CHANGED
|
@@ -2,6 +2,7 @@ import { getRangeValue, percentDenominator, } from "@tsparticles/engine";
|
|
|
2
2
|
import { Destroy } from "./Options/Classes/Destroy.js";
|
|
3
3
|
import { DestroyMode } from "./Enums/DestroyMode.js";
|
|
4
4
|
import { split } from "./Utils.js";
|
|
5
|
+
const defaultDeltaFactor = 1, fpsFactor = 60, minExplodeSpeed = 0.01, maxExplodeProgress = 1;
|
|
5
6
|
export class DestroyUpdater {
|
|
6
7
|
_container;
|
|
7
8
|
_pluginManager;
|
|
@@ -14,6 +15,7 @@ export class DestroyUpdater {
|
|
|
14
15
|
if (!destroyOptions) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
18
|
+
particle.exploding = undefined;
|
|
17
19
|
particle.splitCount = 0;
|
|
18
20
|
const destroyBoundsOptions = destroyOptions.bounds;
|
|
19
21
|
particle.destroyBounds ??= {};
|
|
@@ -32,7 +34,8 @@ export class DestroyUpdater {
|
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
isEnabled(particle) {
|
|
35
|
-
|
|
37
|
+
const destroyParticle = particle;
|
|
38
|
+
return !destroyParticle.destroyed || !!destroyParticle.exploding;
|
|
36
39
|
}
|
|
37
40
|
loadOptions(options, ...sources) {
|
|
38
41
|
options.destroy ??= new Destroy();
|
|
@@ -45,11 +48,48 @@ export class DestroyUpdater {
|
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
50
|
const destroyOptions = particle.options.destroy;
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
switch (destroyOptions?.mode) {
|
|
52
|
+
case DestroyMode.split:
|
|
53
|
+
split(this._pluginManager, this._container, particle);
|
|
54
|
+
break;
|
|
55
|
+
case DestroyMode.explode: {
|
|
56
|
+
if (particle.exploding) {
|
|
57
|
+
particle.destroyed = false;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
const { explode } = destroyOptions, initialSize = particle.size.value, maxSize = initialSize * explode.maxSizeFactor, opacity = particle.getOpacity();
|
|
61
|
+
particle.exploding = {
|
|
62
|
+
initialFillOpacity: opacity.fillOpacity,
|
|
63
|
+
initialSize,
|
|
64
|
+
initialStrokeOpacity: opacity.strokeOpacity,
|
|
65
|
+
maxSize,
|
|
66
|
+
progress: 0,
|
|
67
|
+
speed: Math.max(explode.speed, minExplodeSpeed),
|
|
68
|
+
};
|
|
69
|
+
particle.fillOpacity = opacity.fillOpacity;
|
|
70
|
+
particle.strokeOpacity = opacity.strokeOpacity;
|
|
71
|
+
particle.destroyed = false;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
break;
|
|
50
76
|
}
|
|
51
77
|
}
|
|
52
|
-
update(particle) {
|
|
78
|
+
update(particle, delta) {
|
|
79
|
+
if (particle.exploding) {
|
|
80
|
+
const explosionState = particle.exploding, deltaFactor = delta.factor || defaultDeltaFactor;
|
|
81
|
+
explosionState.progress = Math.min(maxExplodeProgress, explosionState.progress + (explosionState.speed * deltaFactor) / fpsFactor);
|
|
82
|
+
const progress = explosionState.progress;
|
|
83
|
+
particle.size.value =
|
|
84
|
+
explosionState.initialSize + (explosionState.maxSize - explosionState.initialSize) * progress;
|
|
85
|
+
particle.fillOpacity = explosionState.initialFillOpacity * (maxExplodeProgress - progress);
|
|
86
|
+
particle.strokeOpacity = explosionState.initialStrokeOpacity * (maxExplodeProgress - progress);
|
|
87
|
+
if (progress >= maxExplodeProgress) {
|
|
88
|
+
particle.exploding = undefined;
|
|
89
|
+
particle.destroy(true);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
53
93
|
if (particle.unbreakableUntil !== undefined && performance.now() >= particle.unbreakableUntil) {
|
|
54
94
|
particle.unbreakable = false;
|
|
55
95
|
particle.unbreakableUntil = undefined;
|
package/cjs/Enums/DestroyMode.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { isNull } from "@tsparticles/engine";
|
|
2
2
|
import { DestroyBounds } from "./DestroyBounds.js";
|
|
3
3
|
import { DestroyMode } from "../../Enums/DestroyMode.js";
|
|
4
|
+
import { Explode } from "./Explode.js";
|
|
4
5
|
import { Split } from "./Split.js";
|
|
5
6
|
export class Destroy {
|
|
6
7
|
bounds;
|
|
8
|
+
explode;
|
|
7
9
|
mode;
|
|
8
10
|
split;
|
|
9
11
|
constructor() {
|
|
10
12
|
this.bounds = new DestroyBounds();
|
|
13
|
+
this.explode = new Explode();
|
|
11
14
|
this.mode = DestroyMode.none;
|
|
12
15
|
this.split = new Split();
|
|
13
16
|
}
|
|
@@ -21,6 +24,7 @@ export class Destroy {
|
|
|
21
24
|
if (data.bounds) {
|
|
22
25
|
this.bounds.load(data.bounds);
|
|
23
26
|
}
|
|
27
|
+
this.explode.load(data.explode);
|
|
24
28
|
this.split.load(data.split);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class Explode {
|
|
3
|
+
maxSizeFactor;
|
|
4
|
+
speed;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.maxSizeFactor = 3;
|
|
7
|
+
this.speed = 2;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (isNull(data)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.maxSizeFactor !== undefined) {
|
|
14
|
+
this.maxSizeFactor = data.maxSizeFactor;
|
|
15
|
+
}
|
|
16
|
+
if (data.speed !== undefined) {
|
|
17
|
+
this.speed = data.speed;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/cjs/Utils.js
CHANGED
|
@@ -53,7 +53,7 @@ function addSplitParticle(pluginManager, container, parent, splitParticlesOption
|
|
|
53
53
|
splitParticleOptions.size.value.max *= factor;
|
|
54
54
|
}
|
|
55
55
|
splitParticleOptions.load(splitParticlesOptions);
|
|
56
|
-
const
|
|
56
|
+
const splitParticlePaintOptions = itemFromSingleOrMultiple(splitParticleOptions.paint), splitParticleFillOptions = splitParticlePaintOptions?.fill, splitParticleStrokeOptions = splitParticlePaintOptions?.stroke, fillColor = resolveSplitColor(splitOptions.fillColorOffset, splitFillColor, splitParticleFillOptions?.color, parentFillColor), strokeColor = resolveSplitColor(splitOptions.strokeColorOffset, splitStrokeColor, splitParticleStrokeOptions?.color, parentStrokeColor);
|
|
57
57
|
if (fillColor && splitParticleFillOptions) {
|
|
58
58
|
splitParticleFillOptions.color = fillColor;
|
|
59
59
|
}
|
package/cjs/browser.js
ADDED
package/cjs/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { DestroyUpdater } from "./DestroyUpdater.js";
|
|
1
2
|
export async function loadDestroyUpdater(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0
|
|
3
|
+
engine.checkVersion("4.0.0");
|
|
3
4
|
await engine.pluginManager.register(e => {
|
|
4
|
-
e.pluginManager.addParticleUpdater("destroy",
|
|
5
|
-
|
|
6
|
-
return new DestroyUpdater(e.pluginManager, container);
|
|
5
|
+
e.pluginManager.addParticleUpdater("destroy", container => {
|
|
6
|
+
return Promise.resolve(new DestroyUpdater(e.pluginManager, container));
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export async function loadDestroyUpdater(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addParticleUpdater("destroy", async (container) => {
|
|
5
|
+
const { DestroyUpdater } = await import("./DestroyUpdater.js");
|
|
6
|
+
return new DestroyUpdater(e.pluginManager, container);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
}
|
package/esm/DestroyUpdater.js
CHANGED
|
@@ -2,6 +2,7 @@ import { getRangeValue, percentDenominator, } from "@tsparticles/engine";
|
|
|
2
2
|
import { Destroy } from "./Options/Classes/Destroy.js";
|
|
3
3
|
import { DestroyMode } from "./Enums/DestroyMode.js";
|
|
4
4
|
import { split } from "./Utils.js";
|
|
5
|
+
const defaultDeltaFactor = 1, fpsFactor = 60, minExplodeSpeed = 0.01, maxExplodeProgress = 1;
|
|
5
6
|
export class DestroyUpdater {
|
|
6
7
|
_container;
|
|
7
8
|
_pluginManager;
|
|
@@ -14,6 +15,7 @@ export class DestroyUpdater {
|
|
|
14
15
|
if (!destroyOptions) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
18
|
+
particle.exploding = undefined;
|
|
17
19
|
particle.splitCount = 0;
|
|
18
20
|
const destroyBoundsOptions = destroyOptions.bounds;
|
|
19
21
|
particle.destroyBounds ??= {};
|
|
@@ -32,7 +34,8 @@ export class DestroyUpdater {
|
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
isEnabled(particle) {
|
|
35
|
-
|
|
37
|
+
const destroyParticle = particle;
|
|
38
|
+
return !destroyParticle.destroyed || !!destroyParticle.exploding;
|
|
36
39
|
}
|
|
37
40
|
loadOptions(options, ...sources) {
|
|
38
41
|
options.destroy ??= new Destroy();
|
|
@@ -45,11 +48,48 @@ export class DestroyUpdater {
|
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
50
|
const destroyOptions = particle.options.destroy;
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
switch (destroyOptions?.mode) {
|
|
52
|
+
case DestroyMode.split:
|
|
53
|
+
split(this._pluginManager, this._container, particle);
|
|
54
|
+
break;
|
|
55
|
+
case DestroyMode.explode: {
|
|
56
|
+
if (particle.exploding) {
|
|
57
|
+
particle.destroyed = false;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
const { explode } = destroyOptions, initialSize = particle.size.value, maxSize = initialSize * explode.maxSizeFactor, opacity = particle.getOpacity();
|
|
61
|
+
particle.exploding = {
|
|
62
|
+
initialFillOpacity: opacity.fillOpacity,
|
|
63
|
+
initialSize,
|
|
64
|
+
initialStrokeOpacity: opacity.strokeOpacity,
|
|
65
|
+
maxSize,
|
|
66
|
+
progress: 0,
|
|
67
|
+
speed: Math.max(explode.speed, minExplodeSpeed),
|
|
68
|
+
};
|
|
69
|
+
particle.fillOpacity = opacity.fillOpacity;
|
|
70
|
+
particle.strokeOpacity = opacity.strokeOpacity;
|
|
71
|
+
particle.destroyed = false;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
break;
|
|
50
76
|
}
|
|
51
77
|
}
|
|
52
|
-
update(particle) {
|
|
78
|
+
update(particle, delta) {
|
|
79
|
+
if (particle.exploding) {
|
|
80
|
+
const explosionState = particle.exploding, deltaFactor = delta.factor || defaultDeltaFactor;
|
|
81
|
+
explosionState.progress = Math.min(maxExplodeProgress, explosionState.progress + (explosionState.speed * deltaFactor) / fpsFactor);
|
|
82
|
+
const progress = explosionState.progress;
|
|
83
|
+
particle.size.value =
|
|
84
|
+
explosionState.initialSize + (explosionState.maxSize - explosionState.initialSize) * progress;
|
|
85
|
+
particle.fillOpacity = explosionState.initialFillOpacity * (maxExplodeProgress - progress);
|
|
86
|
+
particle.strokeOpacity = explosionState.initialStrokeOpacity * (maxExplodeProgress - progress);
|
|
87
|
+
if (progress >= maxExplodeProgress) {
|
|
88
|
+
particle.exploding = undefined;
|
|
89
|
+
particle.destroy(true);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
53
93
|
if (particle.unbreakableUntil !== undefined && performance.now() >= particle.unbreakableUntil) {
|
|
54
94
|
particle.unbreakable = false;
|
|
55
95
|
particle.unbreakableUntil = undefined;
|
package/esm/Enums/DestroyMode.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { isNull } from "@tsparticles/engine";
|
|
2
2
|
import { DestroyBounds } from "./DestroyBounds.js";
|
|
3
3
|
import { DestroyMode } from "../../Enums/DestroyMode.js";
|
|
4
|
+
import { Explode } from "./Explode.js";
|
|
4
5
|
import { Split } from "./Split.js";
|
|
5
6
|
export class Destroy {
|
|
6
7
|
bounds;
|
|
8
|
+
explode;
|
|
7
9
|
mode;
|
|
8
10
|
split;
|
|
9
11
|
constructor() {
|
|
10
12
|
this.bounds = new DestroyBounds();
|
|
13
|
+
this.explode = new Explode();
|
|
11
14
|
this.mode = DestroyMode.none;
|
|
12
15
|
this.split = new Split();
|
|
13
16
|
}
|
|
@@ -21,6 +24,7 @@ export class Destroy {
|
|
|
21
24
|
if (data.bounds) {
|
|
22
25
|
this.bounds.load(data.bounds);
|
|
23
26
|
}
|
|
27
|
+
this.explode.load(data.explode);
|
|
24
28
|
this.split.load(data.split);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class Explode {
|
|
3
|
+
maxSizeFactor;
|
|
4
|
+
speed;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.maxSizeFactor = 3;
|
|
7
|
+
this.speed = 2;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (isNull(data)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.maxSizeFactor !== undefined) {
|
|
14
|
+
this.maxSizeFactor = data.maxSizeFactor;
|
|
15
|
+
}
|
|
16
|
+
if (data.speed !== undefined) {
|
|
17
|
+
this.speed = data.speed;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/Utils.js
CHANGED
|
@@ -53,7 +53,7 @@ function addSplitParticle(pluginManager, container, parent, splitParticlesOption
|
|
|
53
53
|
splitParticleOptions.size.value.max *= factor;
|
|
54
54
|
}
|
|
55
55
|
splitParticleOptions.load(splitParticlesOptions);
|
|
56
|
-
const
|
|
56
|
+
const splitParticlePaintOptions = itemFromSingleOrMultiple(splitParticleOptions.paint), splitParticleFillOptions = splitParticlePaintOptions?.fill, splitParticleStrokeOptions = splitParticlePaintOptions?.stroke, fillColor = resolveSplitColor(splitOptions.fillColorOffset, splitFillColor, splitParticleFillOptions?.color, parentFillColor), strokeColor = resolveSplitColor(splitOptions.strokeColorOffset, splitStrokeColor, splitParticleStrokeOptions?.color, parentStrokeColor);
|
|
57
57
|
if (fillColor && splitParticleFillOptions) {
|
|
58
58
|
splitParticleFillOptions.color = fillColor;
|
|
59
59
|
}
|
package/esm/browser.js
ADDED
package/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { DestroyUpdater } from "./DestroyUpdater.js";
|
|
1
2
|
export async function loadDestroyUpdater(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0
|
|
3
|
+
engine.checkVersion("4.0.0");
|
|
3
4
|
await engine.pluginManager.register(e => {
|
|
4
|
-
e.pluginManager.addParticleUpdater("destroy",
|
|
5
|
-
|
|
6
|
-
return new DestroyUpdater(e.pluginManager, container);
|
|
5
|
+
e.pluginManager.addParticleUpdater("destroy", container => {
|
|
6
|
+
return Promise.resolve(new DestroyUpdater(e.pluginManager, container));
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export async function loadDestroyUpdater(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addParticleUpdater("destroy", async (container) => {
|
|
5
|
+
const { DestroyUpdater } = await import("./DestroyUpdater.js");
|
|
6
|
+
return new DestroyUpdater(e.pluginManager, container);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/updater-destroy",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "tsParticles particles destroy updater",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -83,10 +83,17 @@
|
|
|
83
83
|
"require": "./cjs/index.js",
|
|
84
84
|
"default": "./esm/index.js"
|
|
85
85
|
},
|
|
86
|
+
"./lazy": {
|
|
87
|
+
"types": "./types/index.lazy.d.ts",
|
|
88
|
+
"browser": "./browser/index.lazy.js",
|
|
89
|
+
"import": "./esm/index.lazy.js",
|
|
90
|
+
"require": "./cjs/index.lazy.js",
|
|
91
|
+
"default": "./esm/index.lazy.js"
|
|
92
|
+
},
|
|
86
93
|
"./package.json": "./package.json"
|
|
87
94
|
},
|
|
88
95
|
"peerDependencies": {
|
|
89
|
-
"@tsparticles/engine": "4.0.0
|
|
96
|
+
"@tsparticles/engine": "4.0.0"
|
|
90
97
|
},
|
|
91
98
|
"publishConfig": {
|
|
92
99
|
"access": "public"
|