@tsparticles/updater-destroy 3.0.0-alpha.1 → 3.0.0-beta.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.
@@ -1,5 +1,6 @@
1
- import { getRangeValue, getValue, itemFromSingleOrMultiple, loadParticlesOptions, randomInRange, setRangeValue, } from "@tsparticles/engine";
1
+ import { getRangeValue, } from "@tsparticles/engine";
2
2
  import { Destroy } from "./Options/Classes/Destroy";
3
+ import { split } from "./Utils";
3
4
  export class DestroyUpdater {
4
5
  constructor(engine, container) {
5
6
  this.engine = engine;
@@ -11,21 +12,22 @@ export class DestroyUpdater {
11
12
  return;
12
13
  }
13
14
  particle.splitCount = 0;
14
- const destroyBounds = destroyOptions.bounds;
15
+ const destroyBoundsOptions = destroyOptions.bounds;
15
16
  if (!particle.destroyBounds) {
16
17
  particle.destroyBounds = {};
17
18
  }
18
- if (destroyBounds.bottom) {
19
- particle.destroyBounds.bottom = (getRangeValue(destroyBounds.bottom) * container.canvas.size.height) / 100;
19
+ const { bottom, left, right, top } = destroyBoundsOptions, { destroyBounds } = particle, canvasSize = container.canvas.size;
20
+ if (bottom) {
21
+ destroyBounds.bottom = (getRangeValue(bottom) * canvasSize.height) / 100;
20
22
  }
21
- if (destroyBounds.left) {
22
- particle.destroyBounds.left = (getRangeValue(destroyBounds.left) * container.canvas.size.width) / 100;
23
+ if (left) {
24
+ destroyBounds.left = (getRangeValue(left) * canvasSize.width) / 100;
23
25
  }
24
- if (destroyBounds.right) {
25
- particle.destroyBounds.right = (getRangeValue(destroyBounds.right) * container.canvas.size.width) / 100;
26
+ if (right) {
27
+ destroyBounds.right = (getRangeValue(right) * canvasSize.width) / 100;
26
28
  }
27
- if (destroyBounds.top) {
28
- particle.destroyBounds.top = (getRangeValue(destroyBounds.top) * container.canvas.size.height) / 100;
29
+ if (top) {
30
+ destroyBounds.top = (getRangeValue(top) * canvasSize.height) / 100;
29
31
  }
30
32
  }
31
33
  isEnabled(particle) {
@@ -36,7 +38,7 @@ export class DestroyUpdater {
36
38
  options.destroy = new Destroy();
37
39
  }
38
40
  for (const source of sources) {
39
- options.destroy.load(source === null || source === void 0 ? void 0 : source.destroy);
41
+ options.destroy.load(source?.destroy);
40
42
  }
41
43
  }
42
44
  particleDestroyed(particle, override) {
@@ -45,7 +47,7 @@ export class DestroyUpdater {
45
47
  }
46
48
  const destroyOptions = particle.options.destroy;
47
49
  if (destroyOptions && destroyOptions.mode === "split") {
48
- this.split(particle);
50
+ split(this.engine, this.container, particle);
49
51
  }
50
52
  }
51
53
  update(particle) {
@@ -63,63 +65,4 @@ export class DestroyUpdater {
63
65
  particle.destroy();
64
66
  }
65
67
  }
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
68
  }
@@ -1,4 +1,4 @@
1
- import { deepExtend, executeOnSingleOrMultiple } from "@tsparticles/engine";
1
+ import { OptionsColor, deepExtend, executeOnSingleOrMultiple, } from "@tsparticles/engine";
2
2
  import { SplitFactor } from "./SplitFactor";
3
3
  import { SplitRate } from "./SplitRate";
4
4
  export class Split {
@@ -12,6 +12,9 @@ export class Split {
12
12
  if (!data) {
13
13
  return;
14
14
  }
15
+ if (data.color !== undefined) {
16
+ this.color = OptionsColor.create(this.color, data.color);
17
+ }
15
18
  if (data.count !== undefined) {
16
19
  this.count = data.count;
17
20
  }
@@ -23,5 +26,17 @@ export class Split {
23
26
  if (data.sizeOffset !== undefined) {
24
27
  this.sizeOffset = data.sizeOffset;
25
28
  }
29
+ if (data.colorOffset) {
30
+ this.colorOffset = this.colorOffset ?? {};
31
+ if (data.colorOffset.h !== undefined) {
32
+ this.colorOffset.h = data.colorOffset.h;
33
+ }
34
+ if (data.colorOffset.s !== undefined) {
35
+ this.colorOffset.s = data.colorOffset.s;
36
+ }
37
+ if (data.colorOffset.l !== undefined) {
38
+ this.colorOffset.l = data.colorOffset.l;
39
+ }
40
+ }
26
41
  }
27
42
  }
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/Utils.js ADDED
@@ -0,0 +1,74 @@
1
+ import { getRangeValue, getValue, isNumber, itemFromSingleOrMultiple, loadParticlesOptions, randomInRange, setRangeValue, } from "@tsparticles/engine";
2
+ function addSplitParticle(engine, container, parent, splitParticlesOptions) {
3
+ const destroyOptions = parent.options.destroy;
4
+ if (!destroyOptions) {
5
+ return;
6
+ }
7
+ const splitOptions = destroyOptions.split, options = loadParticlesOptions(engine, container, parent.options), factor = getValue(splitOptions.factor), parentColor = parent.getFillColor();
8
+ if (splitOptions.color) {
9
+ options.color.load(splitOptions.color);
10
+ }
11
+ else if (splitOptions.colorOffset && parentColor) {
12
+ options.color.load({
13
+ value: {
14
+ hsl: {
15
+ h: parentColor.h + getRangeValue(splitOptions.colorOffset.h ?? 0),
16
+ s: parentColor.s + getRangeValue(splitOptions.colorOffset.s ?? 0),
17
+ l: parentColor.l + getRangeValue(splitOptions.colorOffset.l ?? 0),
18
+ },
19
+ },
20
+ });
21
+ }
22
+ else {
23
+ options.color.load({
24
+ value: {
25
+ hsl: parent.getFillColor(),
26
+ },
27
+ });
28
+ }
29
+ options.move.load({
30
+ center: {
31
+ x: parent.position.x,
32
+ y: parent.position.y,
33
+ mode: "precise",
34
+ },
35
+ });
36
+ if (isNumber(options.size.value)) {
37
+ options.size.value /= factor;
38
+ }
39
+ else {
40
+ options.size.value.min /= factor;
41
+ options.size.value.max /= factor;
42
+ }
43
+ options.load(splitParticlesOptions);
44
+ const offset = splitOptions.sizeOffset ? setRangeValue(-parent.size.value, parent.size.value) : 0, position = {
45
+ x: parent.position.x + randomInRange(offset),
46
+ y: parent.position.y + randomInRange(offset),
47
+ };
48
+ return container.particles.addParticle(position, options, parent.group, (particle) => {
49
+ if (particle.size.value < 0.5) {
50
+ return false;
51
+ }
52
+ particle.velocity.length = randomInRange(setRangeValue(parent.velocity.length, particle.velocity.length));
53
+ particle.splitCount = (parent.splitCount ?? 0) + 1;
54
+ particle.unbreakable = true;
55
+ setTimeout(() => {
56
+ particle.unbreakable = false;
57
+ }, 500);
58
+ return true;
59
+ });
60
+ }
61
+ export function split(engine, container, particle) {
62
+ const destroyOptions = particle.options.destroy;
63
+ if (!destroyOptions) {
64
+ return;
65
+ }
66
+ const splitOptions = destroyOptions.split;
67
+ if (splitOptions.count >= 0 && (particle.splitCount === undefined || particle.splitCount++ > splitOptions.count)) {
68
+ return;
69
+ }
70
+ const rate = getValue(splitOptions.rate), particlesSplitOptions = itemFromSingleOrMultiple(splitOptions.particles);
71
+ for (let i = 0; i < rate; i++) {
72
+ addSplitParticle(engine, container, particle, particlesSplitOptions);
73
+ }
74
+ }
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { DestroyUpdater } from "./DestroyUpdater";
2
- export async function loadDestroyUpdater(engine) {
3
- await engine.addParticleUpdater("destroy", (container) => new DestroyUpdater(engine, container));
2
+ export async function loadDestroyUpdater(engine, refresh = true) {
3
+ await engine.addParticleUpdater("destroy", (container) => new DestroyUpdater(engine, container), refresh);
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/updater-destroy",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "tsParticles particles destroy updater",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -73,10 +73,11 @@
73
73
  "unpkg": "tsparticles.updater.destroy.min.js",
74
74
  "module": "esm/index.js",
75
75
  "types": "types/index.d.ts",
76
+ "sideEffects": false,
77
+ "dependencies": {
78
+ "@tsparticles/engine": "^3.0.0-beta.0"
79
+ },
76
80
  "publishConfig": {
77
81
  "access": "public"
78
- },
79
- "dependencies": {
80
- "@tsparticles/engine": "^3.0.0-alpha.1"
81
82
  }
82
- }
83
+ }