@tsparticles/updater-destroy 4.0.0-alpha.8 → 4.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.
package/819.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_updater_destroy=this.webpackChunk_tsparticles_updater_destroy||[]).push([[819],{819(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;engine;constructor(e,t){this.container=t,this.engine=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.engine,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,6 +3,8 @@ 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
+ container;
7
+ engine;
6
8
  constructor(engine, container) {
7
9
  this.container = container;
8
10
  this.engine = engine;
@@ -48,8 +50,9 @@ export class DestroyUpdater {
48
50
  }
49
51
  }
50
52
  update(particle) {
51
- if (!this.isEnabled(particle)) {
52
- return;
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;
@@ -1,5 +1,9 @@
1
1
  import { isNull, setRangeValue } from "@tsparticles/engine";
2
2
  export class DestroyBounds {
3
+ bottom;
4
+ left;
5
+ right;
6
+ top;
3
7
  load(data) {
4
8
  if (isNull(data)) {
5
9
  return;
@@ -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.color !== undefined) {
16
- this.color = OptionsColor.create(this.color, data.color);
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.colorOffset) {
30
- this.colorOffset = this.colorOffset ?? {};
31
- if (data.colorOffset.h !== undefined) {
32
- this.colorOffset.h = data.colorOffset.h;
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.colorOffset.s !== undefined) {
35
- this.colorOffset.s = data.colorOffset.s;
58
+ if (data.strokeColorOffset.s !== undefined) {
59
+ this.strokeColorOffset.s = data.strokeColorOffset.s;
36
60
  }
37
- if (data.colorOffset.l !== undefined) {
38
- this.colorOffset.l = data.colorOffset.l;
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
3
  function addSplitParticle(engine, 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(engine, container, parent.options), factor = getRangeValue(splitOptions.factor.value), parentColor = parent.getFillColor();
9
- if (splitOptions.color) {
10
- options.color.load(splitOptions.color);
11
- }
12
- else if (splitOptions.colorOffset && parentColor) {
13
- options.color.load({
14
- value: {
15
- hsl: {
16
- h: parentColor.h + getRangeValue(splitOptions.colorOffset.h ?? defaultOffset),
17
- s: parentColor.s + getRangeValue(splitOptions.colorOffset.s ?? defaultOffset),
18
- l: parentColor.l + getRangeValue(splitOptions.colorOffset.l ?? defaultOffset),
8
+ const splitOptions = destroyOptions.split, options = loadParticlesOptions(engine, 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
- else {
24
- options.color.load({
25
- value: {
26
- hsl: parent.getFillColor(),
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 /= factor;
66
+ options.size.value *= factor;
39
67
  }
40
68
  else {
41
- options.size.value.min /= factor;
42
- options.size.value.max /= factor;
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,9 +81,7 @@ 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
- setTimeout(() => {
57
- particle.unbreakable = false;
58
- }, unbreakableTime);
84
+ particle.unbreakableUntil = performance.now() + unbreakableTime;
59
85
  return true;
60
86
  });
61
87
  }
@@ -65,9 +91,11 @@ export function split(engine, container, particle) {
65
91
  return;
66
92
  }
67
93
  const splitOptions = destroyOptions.split;
68
- if (splitOptions.count >= minSplitCount &&
69
- (particle.splitCount === undefined || particle.splitCount++ > splitOptions.count)) {
70
- return;
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++) {
package/browser/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export async function loadDestroyUpdater(engine) {
2
- engine.checkVersion("4.0.0-alpha.8");
2
+ engine.checkVersion("4.0.0-beta.0");
3
3
  await engine.register(e => {
4
4
  e.addParticleUpdater("destroy", async (container) => {
5
5
  const { DestroyUpdater } = await import("./DestroyUpdater.js");
@@ -3,6 +3,8 @@ 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
+ container;
7
+ engine;
6
8
  constructor(engine, container) {
7
9
  this.container = container;
8
10
  this.engine = engine;
@@ -48,8 +50,9 @@ export class DestroyUpdater {
48
50
  }
49
51
  }
50
52
  update(particle) {
51
- if (!this.isEnabled(particle)) {
52
- return;
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;
@@ -1,5 +1,9 @@
1
1
  import { isNull, setRangeValue } from "@tsparticles/engine";
2
2
  export class DestroyBounds {
3
+ bottom;
4
+ left;
5
+ right;
6
+ top;
3
7
  load(data) {
4
8
  if (isNull(data)) {
5
9
  return;
@@ -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.color !== undefined) {
16
- this.color = OptionsColor.create(this.color, data.color);
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.colorOffset) {
30
- this.colorOffset = this.colorOffset ?? {};
31
- if (data.colorOffset.h !== undefined) {
32
- this.colorOffset.h = data.colorOffset.h;
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.colorOffset.s !== undefined) {
35
- this.colorOffset.s = data.colorOffset.s;
58
+ if (data.strokeColorOffset.s !== undefined) {
59
+ this.strokeColorOffset.s = data.strokeColorOffset.s;
36
60
  }
37
- if (data.colorOffset.l !== undefined) {
38
- this.colorOffset.l = data.colorOffset.l;
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
3
  function addSplitParticle(engine, 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(engine, container, parent.options), factor = getRangeValue(splitOptions.factor.value), parentColor = parent.getFillColor();
9
- if (splitOptions.color) {
10
- options.color.load(splitOptions.color);
11
- }
12
- else if (splitOptions.colorOffset && parentColor) {
13
- options.color.load({
14
- value: {
15
- hsl: {
16
- h: parentColor.h + getRangeValue(splitOptions.colorOffset.h ?? defaultOffset),
17
- s: parentColor.s + getRangeValue(splitOptions.colorOffset.s ?? defaultOffset),
18
- l: parentColor.l + getRangeValue(splitOptions.colorOffset.l ?? defaultOffset),
8
+ const splitOptions = destroyOptions.split, options = loadParticlesOptions(engine, 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
- else {
24
- options.color.load({
25
- value: {
26
- hsl: parent.getFillColor(),
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 /= factor;
66
+ options.size.value *= factor;
39
67
  }
40
68
  else {
41
- options.size.value.min /= factor;
42
- options.size.value.max /= factor;
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,9 +81,7 @@ 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
- setTimeout(() => {
57
- particle.unbreakable = false;
58
- }, unbreakableTime);
84
+ particle.unbreakableUntil = performance.now() + unbreakableTime;
59
85
  return true;
60
86
  });
61
87
  }
@@ -65,9 +91,11 @@ export function split(engine, container, particle) {
65
91
  return;
66
92
  }
67
93
  const splitOptions = destroyOptions.split;
68
- if (splitOptions.count >= minSplitCount &&
69
- (particle.splitCount === undefined || particle.splitCount++ > splitOptions.count)) {
70
- return;
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++) {
package/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export async function loadDestroyUpdater(engine) {
2
- engine.checkVersion("4.0.0-alpha.8");
2
+ engine.checkVersion("4.0.0-beta.0");
3
3
  await engine.register(e => {
4
4
  e.addParticleUpdater("destroy", async (container) => {
5
5
  const { DestroyUpdater } = await import("./DestroyUpdater.js");