@tsparticles/updater-destroy 4.0.0-alpha.8 → 4.0.0-beta.1
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/513.min.js +1 -0
- package/browser/DestroyUpdater.js +10 -7
- package/browser/Options/Classes/Destroy.js +3 -0
- package/browser/Options/Classes/DestroyBounds.js +4 -0
- package/browser/Options/Classes/Split.js +34 -10
- package/browser/Utils.js +60 -32
- package/browser/index.js +4 -4
- package/cjs/DestroyUpdater.js +10 -7
- package/cjs/Options/Classes/Destroy.js +3 -0
- package/cjs/Options/Classes/DestroyBounds.js +4 -0
- package/cjs/Options/Classes/Split.js +34 -10
- package/cjs/Utils.js +60 -32
- package/cjs/index.js +4 -4
- package/dist_browser_DestroyUpdater_js.js +9 -9
- package/esm/DestroyUpdater.js +10 -7
- package/esm/Options/Classes/Destroy.js +3 -0
- package/esm/Options/Classes/DestroyBounds.js +4 -0
- package/esm/Options/Classes/Split.js +34 -10
- package/esm/Utils.js +60 -32
- package/esm/index.js +4 -4
- package/package.json +2 -2
- package/report.html +84 -29
- package/tsparticles.updater.destroy.js +31 -19
- package/tsparticles.updater.destroy.min.js +2 -2
- package/types/DestroyUpdater.d.ts +4 -4
- package/types/Options/Classes/Split.d.ts +4 -2
- package/types/Options/Interfaces/ISplit.d.ts +4 -2
- package/types/Types.d.ts +1 -0
- package/types/Utils.d.ts +2 -2
- package/umd/DestroyUpdater.js +10 -7
- package/umd/Options/Classes/Destroy.js +3 -0
- package/umd/Options/Classes/DestroyBounds.js +4 -0
- package/umd/Options/Classes/Split.js +34 -10
- package/umd/Utils.js +59 -31
- package/umd/index.js +4 -4
- package/72.min.js +0 -2
- package/72.min.js.LICENSE.txt +0 -1
- package/tsparticles.updater.destroy.min.js.LICENSE.txt +0 -1
package/513.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_updater_destroy=this.webpackChunk_tsparticles_updater_destroy||[]).push([[513],{513(e,t,o){o.d(t,{DestroyUpdater:()=>d});var l,s,i=o(303);class r{bottom;left;right;top;load(e){(0,i.isNull)(e)||(void 0!==e.bottom&&(this.bottom=(0,i.setRangeValue)(e.bottom)),void 0!==e.left&&(this.left=(0,i.setRangeValue)(e.left)),void 0!==e.right&&(this.right=(0,i.setRangeValue)(e.right)),void 0!==e.top&&(this.top=(0,i.setRangeValue)(e.top)))}}(l=s||(s={})).none="none",l.split="split";class a extends i.ValueWithRandom{constructor(){super(),this.value=3}}class n extends i.ValueWithRandom{constructor(){super(),this.value={min:4,max:9}}}class f{count;factor;fillColor;fillColorOffset;particles;rate;sizeOffset;strokeColor;strokeColorOffset;constructor(){this.count=1,this.factor=new a,this.rate=new n,this.sizeOffset=!0}load(e){!(0,i.isNull)(e)&&(void 0!==e.fillColor&&(this.fillColor=i.OptionsColor.create(this.fillColor,e.fillColor)),void 0!==e.strokeColor&&(this.strokeColor=i.OptionsColor.create(this.strokeColor,e.strokeColor)),void 0!==e.count&&(this.count=e.count),this.factor.load(e.factor),this.rate.load(e.rate),this.particles=(0,i.executeOnSingleOrMultiple)(e.particles,e=>(0,i.deepExtend)({},e)),void 0!==e.sizeOffset&&(this.sizeOffset=e.sizeOffset),e.fillColorOffset&&(this.fillColorOffset=this.fillColorOffset??{},void 0!==e.fillColorOffset.h&&(this.fillColorOffset.h=e.fillColorOffset.h),void 0!==e.fillColorOffset.s&&(this.fillColorOffset.s=e.fillColorOffset.s),void 0!==e.fillColorOffset.l&&(this.fillColorOffset.l=e.fillColorOffset.l)),e.strokeColorOffset&&(this.strokeColorOffset=this.strokeColorOffset??{},void 0!==e.strokeColorOffset.h&&(this.strokeColorOffset.h=e.strokeColorOffset.h),void 0!==e.strokeColorOffset.s&&(this.strokeColorOffset.s=e.strokeColorOffset.s),void 0!==e.strokeColorOffset.l&&(this.strokeColorOffset.l=e.strokeColorOffset.l)))}}class u{bounds;mode;split;constructor(){this.bounds=new r,this.mode=s.none,this.split=new f}load(e){(0,i.isNull)(e)||(e.mode&&(this.mode=e.mode),e.bounds&&this.bounds.load(e.bounds),this.split.load(e.split))}}class d{_container;_pluginManager;constructor(e,t){this._container=t,this._pluginManager=e}init(e){let t=this._container,o=e.options.destroy;if(!o)return;e.splitCount=0;let l=o.bounds;e.destroyBounds??={};let{bottom:s,left:r,right:a,top:n}=l,{destroyBounds:f}=e,u=t.canvas.size;s&&(f.bottom=(0,i.getRangeValue)(s)*u.height/i.percentDenominator),r&&(f.left=(0,i.getRangeValue)(r)*u.width/i.percentDenominator),a&&(f.right=(0,i.getRangeValue)(a)*u.width/i.percentDenominator),n&&(f.top=(0,i.getRangeValue)(n)*u.height/i.percentDenominator)}isEnabled(e){return!e.destroyed}loadOptions(e,...t){for(let o of(e.destroy??=new u,t))e.destroy.load(o?.destroy)}particleDestroyed(e,t){if(t)return;let o=e.options.destroy;o?.mode===s.split&&function(e,t,o){let l=o.options.destroy;if(!l)return;let s=l.split;if(s.count>=0){if(void 0===o.splitCount||o.splitCount>s.count)return;o.splitCount++}let r=(0,i.getRangeValue)(s.rate.value),a=(0,i.itemFromSingleOrMultiple)(s.particles);for(let l=0;l<r;l++)!function(e,t,o,l){let s=o.options.destroy;if(!s)return;let r=s.split,a=(0,i.loadParticlesOptions)(e,t,o.options),n=(0,i.itemFromSingleOrMultiple)(a.fill),f=(0,i.itemFromSingleOrMultiple)(a.stroke);if(n?.enable){let e=i.AnimatableColor.create(void 0,n.color),t=o.getFillColor();e.value?e.load(r.fillColor):r.fillColorOffset&&t?e.load({value:{hsl:{h:t.h+(0,i.getRangeValue)(r.fillColorOffset.h??0),s:t.s+(0,i.getRangeValue)(r.fillColorOffset.s??0),l:t.l+(0,i.getRangeValue)(r.fillColorOffset.l??0)}}}):e.load({value:{hsl:o.getFillColor()}})}if(f?.width){let e=i.AnimatableColor.create(void 0,f.color),t=o.getStrokeColor();e.value?e.load(r.strokeColor):r.strokeColorOffset&&t?e.load({value:{hsl:{h:t.h+(0,i.getRangeValue)(r.strokeColorOffset.h??0),s:t.s+(0,i.getRangeValue)(r.strokeColorOffset.s??0),l:t.l+(0,i.getRangeValue)(r.strokeColorOffset.l??0)}}}):e.load({value:{hsl:o.getStrokeColor()}})}a.move.load({center:{x:o.position.x,y:o.position.y,mode:i.PixelMode.precise}});let u=i.identity/(0,i.getRangeValue)(r.factor.value);(0,i.isNumber)(a.size.value)?a.size.value*=u:(a.size.value.min*=u,a.size.value.max*=u),a.load(l);let d=r.sizeOffset?(0,i.setRangeValue)(-o.size.value,o.size.value):0,h={x:o.position.x+(0,i.randomInRangeValue)(d),y:o.position.y+(0,i.randomInRangeValue)(d)};t.particles.addParticle(h,a,o.group,e=>!(e.size.value<.5)&&(e.velocity.length=(0,i.randomInRangeValue)((0,i.setRangeValue)(o.velocity.length,e.velocity.length)),e.splitCount=(o.splitCount??0)+1,e.unbreakable=!0,e.unbreakableUntil=performance.now()+500,!0))}(e,t,o,a)}(this._pluginManager,this._container,e)}update(e){void 0!==e.unbreakableUntil&&performance.now()>=e.unbreakableUntil&&(e.unbreakable=!1,e.unbreakableUntil=void 0);let t=e.getPosition(),o=e.destroyBounds;o&&(void 0!==o.bottom&&t.y>=o.bottom||void 0!==o.left&&t.x<=o.left||void 0!==o.right&&t.x>=o.right||void 0!==o.top&&t.y<=o.top)&&e.destroy()}}}}]);
|
|
@@ -3,12 +3,14 @@ import { Destroy } from "./Options/Classes/Destroy.js";
|
|
|
3
3
|
import { DestroyMode } from "./Enums/DestroyMode.js";
|
|
4
4
|
import { split } from "./Utils.js";
|
|
5
5
|
export class DestroyUpdater {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
_container;
|
|
7
|
+
_pluginManager;
|
|
8
|
+
constructor(pluginManager, container) {
|
|
9
|
+
this._container = container;
|
|
10
|
+
this._pluginManager = pluginManager;
|
|
9
11
|
}
|
|
10
12
|
init(particle) {
|
|
11
|
-
const container = this.
|
|
13
|
+
const container = this._container, particlesOptions = particle.options, destroyOptions = particlesOptions.destroy;
|
|
12
14
|
if (!destroyOptions) {
|
|
13
15
|
return;
|
|
14
16
|
}
|
|
@@ -44,12 +46,13 @@ export class DestroyUpdater {
|
|
|
44
46
|
}
|
|
45
47
|
const destroyOptions = particle.options.destroy;
|
|
46
48
|
if (destroyOptions?.mode === DestroyMode.split) {
|
|
47
|
-
split(this.
|
|
49
|
+
split(this._pluginManager, this._container, particle);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
update(particle) {
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
+
if (particle.unbreakableUntil !== undefined && performance.now() >= particle.unbreakableUntil) {
|
|
54
|
+
particle.unbreakable = false;
|
|
55
|
+
particle.unbreakableUntil = undefined;
|
|
53
56
|
}
|
|
54
57
|
const position = particle.getPosition(), bounds = particle.destroyBounds;
|
|
55
58
|
if (!bounds) {
|
|
@@ -3,6 +3,9 @@ import { DestroyBounds } from "./DestroyBounds.js";
|
|
|
3
3
|
import { DestroyMode } from "../../Enums/DestroyMode.js";
|
|
4
4
|
import { Split } from "./Split.js";
|
|
5
5
|
export class Destroy {
|
|
6
|
+
bounds;
|
|
7
|
+
mode;
|
|
8
|
+
split;
|
|
6
9
|
constructor() {
|
|
7
10
|
this.bounds = new DestroyBounds();
|
|
8
11
|
this.mode = DestroyMode.none;
|
|
@@ -2,6 +2,15 @@ import { OptionsColor, deepExtend, executeOnSingleOrMultiple, isNull, } from "@t
|
|
|
2
2
|
import { SplitFactor } from "./SplitFactor.js";
|
|
3
3
|
import { SplitRate } from "./SplitRate.js";
|
|
4
4
|
export class Split {
|
|
5
|
+
count;
|
|
6
|
+
factor;
|
|
7
|
+
fillColor;
|
|
8
|
+
fillColorOffset;
|
|
9
|
+
particles;
|
|
10
|
+
rate;
|
|
11
|
+
sizeOffset;
|
|
12
|
+
strokeColor;
|
|
13
|
+
strokeColorOffset;
|
|
5
14
|
constructor() {
|
|
6
15
|
this.count = 1;
|
|
7
16
|
this.factor = new SplitFactor();
|
|
@@ -12,8 +21,11 @@ export class Split {
|
|
|
12
21
|
if (isNull(data)) {
|
|
13
22
|
return;
|
|
14
23
|
}
|
|
15
|
-
if (data.
|
|
16
|
-
this.
|
|
24
|
+
if (data.fillColor !== undefined) {
|
|
25
|
+
this.fillColor = OptionsColor.create(this.fillColor, data.fillColor);
|
|
26
|
+
}
|
|
27
|
+
if (data.strokeColor !== undefined) {
|
|
28
|
+
this.strokeColor = OptionsColor.create(this.strokeColor, data.strokeColor);
|
|
17
29
|
}
|
|
18
30
|
if (data.count !== undefined) {
|
|
19
31
|
this.count = data.count;
|
|
@@ -26,16 +38,28 @@ export class Split {
|
|
|
26
38
|
if (data.sizeOffset !== undefined) {
|
|
27
39
|
this.sizeOffset = data.sizeOffset;
|
|
28
40
|
}
|
|
29
|
-
if (data.
|
|
30
|
-
this.
|
|
31
|
-
if (data.
|
|
32
|
-
this.
|
|
41
|
+
if (data.fillColorOffset) {
|
|
42
|
+
this.fillColorOffset = this.fillColorOffset ?? {};
|
|
43
|
+
if (data.fillColorOffset.h !== undefined) {
|
|
44
|
+
this.fillColorOffset.h = data.fillColorOffset.h;
|
|
45
|
+
}
|
|
46
|
+
if (data.fillColorOffset.s !== undefined) {
|
|
47
|
+
this.fillColorOffset.s = data.fillColorOffset.s;
|
|
48
|
+
}
|
|
49
|
+
if (data.fillColorOffset.l !== undefined) {
|
|
50
|
+
this.fillColorOffset.l = data.fillColorOffset.l;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (data.strokeColorOffset) {
|
|
54
|
+
this.strokeColorOffset = this.strokeColorOffset ?? {};
|
|
55
|
+
if (data.strokeColorOffset.h !== undefined) {
|
|
56
|
+
this.strokeColorOffset.h = data.strokeColorOffset.h;
|
|
33
57
|
}
|
|
34
|
-
if (data.
|
|
35
|
-
this.
|
|
58
|
+
if (data.strokeColorOffset.s !== undefined) {
|
|
59
|
+
this.strokeColorOffset.s = data.strokeColorOffset.s;
|
|
36
60
|
}
|
|
37
|
-
if (data.
|
|
38
|
-
this.
|
|
61
|
+
if (data.strokeColorOffset.l !== undefined) {
|
|
62
|
+
this.strokeColorOffset.l = data.strokeColorOffset.l;
|
|
39
63
|
}
|
|
40
64
|
}
|
|
41
65
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -1,31 +1,58 @@
|
|
|
1
|
-
import { PixelMode, getRangeValue, isNumber, itemFromSingleOrMultiple, loadParticlesOptions, randomInRangeValue, setRangeValue, } from "@tsparticles/engine";
|
|
1
|
+
import { AnimatableColor, PixelMode, getRangeValue, identity, isNumber, itemFromSingleOrMultiple, loadParticlesOptions, randomInRangeValue, setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
const defaultOffset = 0, minDestroySize = 0.5, defaultSplitCount = 0, increment = 1, unbreakableTime = 500, minSplitCount = 0;
|
|
3
|
-
function addSplitParticle(
|
|
3
|
+
function addSplitParticle(pluginManager, container, parent, splitParticlesOptions) {
|
|
4
4
|
const destroyOptions = parent.options.destroy;
|
|
5
5
|
if (!destroyOptions) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
const splitOptions = destroyOptions.split, options = loadParticlesOptions(
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const splitOptions = destroyOptions.split, options = loadParticlesOptions(pluginManager, container, parent.options), fillOptions = itemFromSingleOrMultiple(options.fill), strokeOptions = itemFromSingleOrMultiple(options.stroke);
|
|
9
|
+
if (fillOptions?.enable) {
|
|
10
|
+
const fillColor = AnimatableColor.create(undefined, fillOptions.color), parentFillColor = parent.getFillColor();
|
|
11
|
+
if (fillColor.value) {
|
|
12
|
+
fillColor.load(splitOptions.fillColor);
|
|
13
|
+
}
|
|
14
|
+
else if (splitOptions.fillColorOffset && parentFillColor) {
|
|
15
|
+
fillColor.load({
|
|
16
|
+
value: {
|
|
17
|
+
hsl: {
|
|
18
|
+
h: parentFillColor.h + getRangeValue(splitOptions.fillColorOffset.h ?? defaultOffset),
|
|
19
|
+
s: parentFillColor.s + getRangeValue(splitOptions.fillColorOffset.s ?? defaultOffset),
|
|
20
|
+
l: parentFillColor.l + getRangeValue(splitOptions.fillColorOffset.l ?? defaultOffset),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
fillColor.load({
|
|
27
|
+
value: {
|
|
28
|
+
hsl: parent.getFillColor(),
|
|
19
29
|
},
|
|
20
|
-
}
|
|
21
|
-
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
if (strokeOptions?.width) {
|
|
34
|
+
const strokeColor = AnimatableColor.create(undefined, strokeOptions.color), parentStrokeColor = parent.getStrokeColor();
|
|
35
|
+
if (strokeColor.value) {
|
|
36
|
+
strokeColor.load(splitOptions.strokeColor);
|
|
37
|
+
}
|
|
38
|
+
else if (splitOptions.strokeColorOffset && parentStrokeColor) {
|
|
39
|
+
strokeColor.load({
|
|
40
|
+
value: {
|
|
41
|
+
hsl: {
|
|
42
|
+
h: parentStrokeColor.h + getRangeValue(splitOptions.strokeColorOffset.h ?? defaultOffset),
|
|
43
|
+
s: parentStrokeColor.s + getRangeValue(splitOptions.strokeColorOffset.s ?? defaultOffset),
|
|
44
|
+
l: parentStrokeColor.l + getRangeValue(splitOptions.strokeColorOffset.l ?? defaultOffset),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
strokeColor.load({
|
|
51
|
+
value: {
|
|
52
|
+
hsl: parent.getStrokeColor(),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
29
56
|
}
|
|
30
57
|
options.move.load({
|
|
31
58
|
center: {
|
|
@@ -34,12 +61,13 @@ function addSplitParticle(engine, container, parent, splitParticlesOptions) {
|
|
|
34
61
|
mode: PixelMode.precise,
|
|
35
62
|
},
|
|
36
63
|
});
|
|
64
|
+
const factor = identity / getRangeValue(splitOptions.factor.value);
|
|
37
65
|
if (isNumber(options.size.value)) {
|
|
38
|
-
options.size.value
|
|
66
|
+
options.size.value *= factor;
|
|
39
67
|
}
|
|
40
68
|
else {
|
|
41
|
-
options.size.value.min
|
|
42
|
-
options.size.value.max
|
|
69
|
+
options.size.value.min *= factor;
|
|
70
|
+
options.size.value.max *= factor;
|
|
43
71
|
}
|
|
44
72
|
options.load(splitParticlesOptions);
|
|
45
73
|
const offset = splitOptions.sizeOffset ? setRangeValue(-parent.size.value, parent.size.value) : defaultOffset, position = {
|
|
@@ -53,24 +81,24 @@ function addSplitParticle(engine, container, parent, splitParticlesOptions) {
|
|
|
53
81
|
particle.velocity.length = randomInRangeValue(setRangeValue(parent.velocity.length, particle.velocity.length));
|
|
54
82
|
particle.splitCount = (parent.splitCount ?? defaultSplitCount) + increment;
|
|
55
83
|
particle.unbreakable = true;
|
|
56
|
-
|
|
57
|
-
particle.unbreakable = false;
|
|
58
|
-
}, unbreakableTime);
|
|
84
|
+
particle.unbreakableUntil = performance.now() + unbreakableTime;
|
|
59
85
|
return true;
|
|
60
86
|
});
|
|
61
87
|
}
|
|
62
|
-
export function split(
|
|
88
|
+
export function split(pluginManager, container, particle) {
|
|
63
89
|
const destroyOptions = particle.options.destroy;
|
|
64
90
|
if (!destroyOptions) {
|
|
65
91
|
return;
|
|
66
92
|
}
|
|
67
93
|
const splitOptions = destroyOptions.split;
|
|
68
|
-
if (splitOptions.count >= minSplitCount
|
|
69
|
-
(particle.splitCount === undefined || particle.splitCount
|
|
70
|
-
|
|
94
|
+
if (splitOptions.count >= minSplitCount) {
|
|
95
|
+
if (particle.splitCount === undefined || particle.splitCount > splitOptions.count) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
particle.splitCount++;
|
|
71
99
|
}
|
|
72
100
|
const rate = getRangeValue(splitOptions.rate.value), particlesSplitOptions = itemFromSingleOrMultiple(splitOptions.particles);
|
|
73
101
|
for (let i = 0; i < rate; i++) {
|
|
74
|
-
addSplitParticle(
|
|
102
|
+
addSplitParticle(pluginManager, container, particle, particlesSplitOptions);
|
|
75
103
|
}
|
|
76
104
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export async function loadDestroyUpdater(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
3
|
-
await engine.register(e => {
|
|
4
|
-
e.addParticleUpdater("destroy", async (container) => {
|
|
2
|
+
engine.checkVersion("4.0.0-beta.1");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addParticleUpdater("destroy", async (container) => {
|
|
5
5
|
const { DestroyUpdater } = await import("./DestroyUpdater.js");
|
|
6
|
-
return new DestroyUpdater(e, container);
|
|
6
|
+
return new DestroyUpdater(e.pluginManager, container);
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|
package/cjs/DestroyUpdater.js
CHANGED
|
@@ -3,12 +3,14 @@ import { Destroy } from "./Options/Classes/Destroy.js";
|
|
|
3
3
|
import { DestroyMode } from "./Enums/DestroyMode.js";
|
|
4
4
|
import { split } from "./Utils.js";
|
|
5
5
|
export class DestroyUpdater {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
_container;
|
|
7
|
+
_pluginManager;
|
|
8
|
+
constructor(pluginManager, container) {
|
|
9
|
+
this._container = container;
|
|
10
|
+
this._pluginManager = pluginManager;
|
|
9
11
|
}
|
|
10
12
|
init(particle) {
|
|
11
|
-
const container = this.
|
|
13
|
+
const container = this._container, particlesOptions = particle.options, destroyOptions = particlesOptions.destroy;
|
|
12
14
|
if (!destroyOptions) {
|
|
13
15
|
return;
|
|
14
16
|
}
|
|
@@ -44,12 +46,13 @@ export class DestroyUpdater {
|
|
|
44
46
|
}
|
|
45
47
|
const destroyOptions = particle.options.destroy;
|
|
46
48
|
if (destroyOptions?.mode === DestroyMode.split) {
|
|
47
|
-
split(this.
|
|
49
|
+
split(this._pluginManager, this._container, particle);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
update(particle) {
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
+
if (particle.unbreakableUntil !== undefined && performance.now() >= particle.unbreakableUntil) {
|
|
54
|
+
particle.unbreakable = false;
|
|
55
|
+
particle.unbreakableUntil = undefined;
|
|
53
56
|
}
|
|
54
57
|
const position = particle.getPosition(), bounds = particle.destroyBounds;
|
|
55
58
|
if (!bounds) {
|
|
@@ -3,6 +3,9 @@ import { DestroyBounds } from "./DestroyBounds.js";
|
|
|
3
3
|
import { DestroyMode } from "../../Enums/DestroyMode.js";
|
|
4
4
|
import { Split } from "./Split.js";
|
|
5
5
|
export class Destroy {
|
|
6
|
+
bounds;
|
|
7
|
+
mode;
|
|
8
|
+
split;
|
|
6
9
|
constructor() {
|
|
7
10
|
this.bounds = new DestroyBounds();
|
|
8
11
|
this.mode = DestroyMode.none;
|
|
@@ -2,6 +2,15 @@ import { OptionsColor, deepExtend, executeOnSingleOrMultiple, isNull, } from "@t
|
|
|
2
2
|
import { SplitFactor } from "./SplitFactor.js";
|
|
3
3
|
import { SplitRate } from "./SplitRate.js";
|
|
4
4
|
export class Split {
|
|
5
|
+
count;
|
|
6
|
+
factor;
|
|
7
|
+
fillColor;
|
|
8
|
+
fillColorOffset;
|
|
9
|
+
particles;
|
|
10
|
+
rate;
|
|
11
|
+
sizeOffset;
|
|
12
|
+
strokeColor;
|
|
13
|
+
strokeColorOffset;
|
|
5
14
|
constructor() {
|
|
6
15
|
this.count = 1;
|
|
7
16
|
this.factor = new SplitFactor();
|
|
@@ -12,8 +21,11 @@ export class Split {
|
|
|
12
21
|
if (isNull(data)) {
|
|
13
22
|
return;
|
|
14
23
|
}
|
|
15
|
-
if (data.
|
|
16
|
-
this.
|
|
24
|
+
if (data.fillColor !== undefined) {
|
|
25
|
+
this.fillColor = OptionsColor.create(this.fillColor, data.fillColor);
|
|
26
|
+
}
|
|
27
|
+
if (data.strokeColor !== undefined) {
|
|
28
|
+
this.strokeColor = OptionsColor.create(this.strokeColor, data.strokeColor);
|
|
17
29
|
}
|
|
18
30
|
if (data.count !== undefined) {
|
|
19
31
|
this.count = data.count;
|
|
@@ -26,16 +38,28 @@ export class Split {
|
|
|
26
38
|
if (data.sizeOffset !== undefined) {
|
|
27
39
|
this.sizeOffset = data.sizeOffset;
|
|
28
40
|
}
|
|
29
|
-
if (data.
|
|
30
|
-
this.
|
|
31
|
-
if (data.
|
|
32
|
-
this.
|
|
41
|
+
if (data.fillColorOffset) {
|
|
42
|
+
this.fillColorOffset = this.fillColorOffset ?? {};
|
|
43
|
+
if (data.fillColorOffset.h !== undefined) {
|
|
44
|
+
this.fillColorOffset.h = data.fillColorOffset.h;
|
|
45
|
+
}
|
|
46
|
+
if (data.fillColorOffset.s !== undefined) {
|
|
47
|
+
this.fillColorOffset.s = data.fillColorOffset.s;
|
|
48
|
+
}
|
|
49
|
+
if (data.fillColorOffset.l !== undefined) {
|
|
50
|
+
this.fillColorOffset.l = data.fillColorOffset.l;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (data.strokeColorOffset) {
|
|
54
|
+
this.strokeColorOffset = this.strokeColorOffset ?? {};
|
|
55
|
+
if (data.strokeColorOffset.h !== undefined) {
|
|
56
|
+
this.strokeColorOffset.h = data.strokeColorOffset.h;
|
|
33
57
|
}
|
|
34
|
-
if (data.
|
|
35
|
-
this.
|
|
58
|
+
if (data.strokeColorOffset.s !== undefined) {
|
|
59
|
+
this.strokeColorOffset.s = data.strokeColorOffset.s;
|
|
36
60
|
}
|
|
37
|
-
if (data.
|
|
38
|
-
this.
|
|
61
|
+
if (data.strokeColorOffset.l !== undefined) {
|
|
62
|
+
this.strokeColorOffset.l = data.strokeColorOffset.l;
|
|
39
63
|
}
|
|
40
64
|
}
|
|
41
65
|
}
|
package/cjs/Utils.js
CHANGED
|
@@ -1,31 +1,58 @@
|
|
|
1
|
-
import { PixelMode, getRangeValue, isNumber, itemFromSingleOrMultiple, loadParticlesOptions, randomInRangeValue, setRangeValue, } from "@tsparticles/engine";
|
|
1
|
+
import { AnimatableColor, PixelMode, getRangeValue, identity, isNumber, itemFromSingleOrMultiple, loadParticlesOptions, randomInRangeValue, setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
const defaultOffset = 0, minDestroySize = 0.5, defaultSplitCount = 0, increment = 1, unbreakableTime = 500, minSplitCount = 0;
|
|
3
|
-
function addSplitParticle(
|
|
3
|
+
function addSplitParticle(pluginManager, container, parent, splitParticlesOptions) {
|
|
4
4
|
const destroyOptions = parent.options.destroy;
|
|
5
5
|
if (!destroyOptions) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
const splitOptions = destroyOptions.split, options = loadParticlesOptions(
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const splitOptions = destroyOptions.split, options = loadParticlesOptions(pluginManager, container, parent.options), fillOptions = itemFromSingleOrMultiple(options.fill), strokeOptions = itemFromSingleOrMultiple(options.stroke);
|
|
9
|
+
if (fillOptions?.enable) {
|
|
10
|
+
const fillColor = AnimatableColor.create(undefined, fillOptions.color), parentFillColor = parent.getFillColor();
|
|
11
|
+
if (fillColor.value) {
|
|
12
|
+
fillColor.load(splitOptions.fillColor);
|
|
13
|
+
}
|
|
14
|
+
else if (splitOptions.fillColorOffset && parentFillColor) {
|
|
15
|
+
fillColor.load({
|
|
16
|
+
value: {
|
|
17
|
+
hsl: {
|
|
18
|
+
h: parentFillColor.h + getRangeValue(splitOptions.fillColorOffset.h ?? defaultOffset),
|
|
19
|
+
s: parentFillColor.s + getRangeValue(splitOptions.fillColorOffset.s ?? defaultOffset),
|
|
20
|
+
l: parentFillColor.l + getRangeValue(splitOptions.fillColorOffset.l ?? defaultOffset),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
fillColor.load({
|
|
27
|
+
value: {
|
|
28
|
+
hsl: parent.getFillColor(),
|
|
19
29
|
},
|
|
20
|
-
}
|
|
21
|
-
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
if (strokeOptions?.width) {
|
|
34
|
+
const strokeColor = AnimatableColor.create(undefined, strokeOptions.color), parentStrokeColor = parent.getStrokeColor();
|
|
35
|
+
if (strokeColor.value) {
|
|
36
|
+
strokeColor.load(splitOptions.strokeColor);
|
|
37
|
+
}
|
|
38
|
+
else if (splitOptions.strokeColorOffset && parentStrokeColor) {
|
|
39
|
+
strokeColor.load({
|
|
40
|
+
value: {
|
|
41
|
+
hsl: {
|
|
42
|
+
h: parentStrokeColor.h + getRangeValue(splitOptions.strokeColorOffset.h ?? defaultOffset),
|
|
43
|
+
s: parentStrokeColor.s + getRangeValue(splitOptions.strokeColorOffset.s ?? defaultOffset),
|
|
44
|
+
l: parentStrokeColor.l + getRangeValue(splitOptions.strokeColorOffset.l ?? defaultOffset),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
strokeColor.load({
|
|
51
|
+
value: {
|
|
52
|
+
hsl: parent.getStrokeColor(),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
29
56
|
}
|
|
30
57
|
options.move.load({
|
|
31
58
|
center: {
|
|
@@ -34,12 +61,13 @@ function addSplitParticle(engine, container, parent, splitParticlesOptions) {
|
|
|
34
61
|
mode: PixelMode.precise,
|
|
35
62
|
},
|
|
36
63
|
});
|
|
64
|
+
const factor = identity / getRangeValue(splitOptions.factor.value);
|
|
37
65
|
if (isNumber(options.size.value)) {
|
|
38
|
-
options.size.value
|
|
66
|
+
options.size.value *= factor;
|
|
39
67
|
}
|
|
40
68
|
else {
|
|
41
|
-
options.size.value.min
|
|
42
|
-
options.size.value.max
|
|
69
|
+
options.size.value.min *= factor;
|
|
70
|
+
options.size.value.max *= factor;
|
|
43
71
|
}
|
|
44
72
|
options.load(splitParticlesOptions);
|
|
45
73
|
const offset = splitOptions.sizeOffset ? setRangeValue(-parent.size.value, parent.size.value) : defaultOffset, position = {
|
|
@@ -53,24 +81,24 @@ function addSplitParticle(engine, container, parent, splitParticlesOptions) {
|
|
|
53
81
|
particle.velocity.length = randomInRangeValue(setRangeValue(parent.velocity.length, particle.velocity.length));
|
|
54
82
|
particle.splitCount = (parent.splitCount ?? defaultSplitCount) + increment;
|
|
55
83
|
particle.unbreakable = true;
|
|
56
|
-
|
|
57
|
-
particle.unbreakable = false;
|
|
58
|
-
}, unbreakableTime);
|
|
84
|
+
particle.unbreakableUntil = performance.now() + unbreakableTime;
|
|
59
85
|
return true;
|
|
60
86
|
});
|
|
61
87
|
}
|
|
62
|
-
export function split(
|
|
88
|
+
export function split(pluginManager, container, particle) {
|
|
63
89
|
const destroyOptions = particle.options.destroy;
|
|
64
90
|
if (!destroyOptions) {
|
|
65
91
|
return;
|
|
66
92
|
}
|
|
67
93
|
const splitOptions = destroyOptions.split;
|
|
68
|
-
if (splitOptions.count >= minSplitCount
|
|
69
|
-
(particle.splitCount === undefined || particle.splitCount
|
|
70
|
-
|
|
94
|
+
if (splitOptions.count >= minSplitCount) {
|
|
95
|
+
if (particle.splitCount === undefined || particle.splitCount > splitOptions.count) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
particle.splitCount++;
|
|
71
99
|
}
|
|
72
100
|
const rate = getRangeValue(splitOptions.rate.value), particlesSplitOptions = itemFromSingleOrMultiple(splitOptions.particles);
|
|
73
101
|
for (let i = 0; i < rate; i++) {
|
|
74
|
-
addSplitParticle(
|
|
102
|
+
addSplitParticle(pluginManager, container, particle, particlesSplitOptions);
|
|
75
103
|
}
|
|
76
104
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export async function loadDestroyUpdater(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
3
|
-
await engine.register(e => {
|
|
4
|
-
e.addParticleUpdater("destroy", async (container) => {
|
|
2
|
+
engine.checkVersion("4.0.0-beta.1");
|
|
3
|
+
await engine.pluginManager.register(e => {
|
|
4
|
+
e.pluginManager.addParticleUpdater("destroy", async (container) => {
|
|
5
5
|
const { DestroyUpdater } = await import("./DestroyUpdater.js");
|
|
6
|
-
return new DestroyUpdater(e, container);
|
|
6
|
+
return new DestroyUpdater(e.pluginManager, container);
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
}
|