@tsparticles/updater-destroy 3.0.0-alpha.0 → 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.
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
7
+ * v3.0.0-beta.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,7 +91,7 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "loadDestroyUpdater": () => (/* binding */ loadDestroyUpdater)
94
+ loadDestroyUpdater: () => (/* binding */ loadDestroyUpdater)
95
95
  });
96
96
 
97
97
  // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
@@ -151,6 +151,9 @@ class Split {
151
151
  if (!data) {
152
152
  return;
153
153
  }
154
+ if (data.color !== undefined) {
155
+ this.color = engine_root_window_.OptionsColor.create(this.color, data.color);
156
+ }
154
157
  if (data.count !== undefined) {
155
158
  this.count = data.count;
156
159
  }
@@ -162,6 +165,18 @@ class Split {
162
165
  if (data.sizeOffset !== undefined) {
163
166
  this.sizeOffset = data.sizeOffset;
164
167
  }
168
+ if (data.colorOffset) {
169
+ this.colorOffset = this.colorOffset ?? {};
170
+ if (data.colorOffset.h !== undefined) {
171
+ this.colorOffset.h = data.colorOffset.h;
172
+ }
173
+ if (data.colorOffset.s !== undefined) {
174
+ this.colorOffset.s = data.colorOffset.s;
175
+ }
176
+ if (data.colorOffset.l !== undefined) {
177
+ this.colorOffset.l = data.colorOffset.l;
178
+ }
179
+ }
165
180
  }
166
181
  }
167
182
  ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Destroy.js
@@ -186,9 +201,87 @@ class Destroy {
186
201
  this.split.load(data.split);
187
202
  }
188
203
  }
204
+ ;// CONCATENATED MODULE: ./dist/browser/Utils.js
205
+
206
+ function addSplitParticle(engine, container, parent, splitParticlesOptions) {
207
+ const destroyOptions = parent.options.destroy;
208
+ if (!destroyOptions) {
209
+ return;
210
+ }
211
+ const splitOptions = destroyOptions.split,
212
+ options = (0,engine_root_window_.loadParticlesOptions)(engine, container, parent.options),
213
+ factor = (0,engine_root_window_.getValue)(splitOptions.factor),
214
+ parentColor = parent.getFillColor();
215
+ if (splitOptions.color) {
216
+ options.color.load(splitOptions.color);
217
+ } else if (splitOptions.colorOffset && parentColor) {
218
+ options.color.load({
219
+ value: {
220
+ hsl: {
221
+ h: parentColor.h + (0,engine_root_window_.getRangeValue)(splitOptions.colorOffset.h ?? 0),
222
+ s: parentColor.s + (0,engine_root_window_.getRangeValue)(splitOptions.colorOffset.s ?? 0),
223
+ l: parentColor.l + (0,engine_root_window_.getRangeValue)(splitOptions.colorOffset.l ?? 0)
224
+ }
225
+ }
226
+ });
227
+ } else {
228
+ options.color.load({
229
+ value: {
230
+ hsl: parent.getFillColor()
231
+ }
232
+ });
233
+ }
234
+ options.move.load({
235
+ center: {
236
+ x: parent.position.x,
237
+ y: parent.position.y,
238
+ mode: "precise"
239
+ }
240
+ });
241
+ if ((0,engine_root_window_.isNumber)(options.size.value)) {
242
+ options.size.value /= factor;
243
+ } else {
244
+ options.size.value.min /= factor;
245
+ options.size.value.max /= factor;
246
+ }
247
+ options.load(splitParticlesOptions);
248
+ const offset = splitOptions.sizeOffset ? (0,engine_root_window_.setRangeValue)(-parent.size.value, parent.size.value) : 0,
249
+ position = {
250
+ x: parent.position.x + (0,engine_root_window_.randomInRange)(offset),
251
+ y: parent.position.y + (0,engine_root_window_.randomInRange)(offset)
252
+ };
253
+ return container.particles.addParticle(position, options, parent.group, particle => {
254
+ if (particle.size.value < 0.5) {
255
+ return false;
256
+ }
257
+ particle.velocity.length = (0,engine_root_window_.randomInRange)((0,engine_root_window_.setRangeValue)(parent.velocity.length, particle.velocity.length));
258
+ particle.splitCount = (parent.splitCount ?? 0) + 1;
259
+ particle.unbreakable = true;
260
+ setTimeout(() => {
261
+ particle.unbreakable = false;
262
+ }, 500);
263
+ return true;
264
+ });
265
+ }
266
+ function split(engine, container, particle) {
267
+ const destroyOptions = particle.options.destroy;
268
+ if (!destroyOptions) {
269
+ return;
270
+ }
271
+ const splitOptions = destroyOptions.split;
272
+ if (splitOptions.count >= 0 && (particle.splitCount === undefined || particle.splitCount++ > splitOptions.count)) {
273
+ return;
274
+ }
275
+ const rate = (0,engine_root_window_.getValue)(splitOptions.rate),
276
+ particlesSplitOptions = (0,engine_root_window_.itemFromSingleOrMultiple)(splitOptions.particles);
277
+ for (let i = 0; i < rate; i++) {
278
+ addSplitParticle(engine, container, particle, particlesSplitOptions);
279
+ }
280
+ }
189
281
  ;// CONCATENATED MODULE: ./dist/browser/DestroyUpdater.js
190
282
 
191
283
 
284
+
192
285
  class DestroyUpdater {
193
286
  constructor(engine, container) {
194
287
  this.engine = engine;
@@ -202,21 +295,31 @@ class DestroyUpdater {
202
295
  return;
203
296
  }
204
297
  particle.splitCount = 0;
205
- const destroyBounds = destroyOptions.bounds;
298
+ const destroyBoundsOptions = destroyOptions.bounds;
206
299
  if (!particle.destroyBounds) {
207
300
  particle.destroyBounds = {};
208
301
  }
209
- if (destroyBounds.bottom) {
210
- particle.destroyBounds.bottom = (0,engine_root_window_.getRangeValue)(destroyBounds.bottom) * container.canvas.size.height / 100;
302
+ const {
303
+ bottom,
304
+ left,
305
+ right,
306
+ top
307
+ } = destroyBoundsOptions,
308
+ {
309
+ destroyBounds
310
+ } = particle,
311
+ canvasSize = container.canvas.size;
312
+ if (bottom) {
313
+ destroyBounds.bottom = (0,engine_root_window_.getRangeValue)(bottom) * canvasSize.height / 100;
211
314
  }
212
- if (destroyBounds.left) {
213
- particle.destroyBounds.left = (0,engine_root_window_.getRangeValue)(destroyBounds.left) * container.canvas.size.width / 100;
315
+ if (left) {
316
+ destroyBounds.left = (0,engine_root_window_.getRangeValue)(left) * canvasSize.width / 100;
214
317
  }
215
- if (destroyBounds.right) {
216
- particle.destroyBounds.right = (0,engine_root_window_.getRangeValue)(destroyBounds.right) * container.canvas.size.width / 100;
318
+ if (right) {
319
+ destroyBounds.right = (0,engine_root_window_.getRangeValue)(right) * canvasSize.width / 100;
217
320
  }
218
- if (destroyBounds.top) {
219
- particle.destroyBounds.top = (0,engine_root_window_.getRangeValue)(destroyBounds.top) * container.canvas.size.height / 100;
321
+ if (top) {
322
+ destroyBounds.top = (0,engine_root_window_.getRangeValue)(top) * canvasSize.height / 100;
220
323
  }
221
324
  }
222
325
  isEnabled(particle) {
@@ -227,7 +330,7 @@ class DestroyUpdater {
227
330
  options.destroy = new Destroy();
228
331
  }
229
332
  for (const source of sources) {
230
- options.destroy.load(source === null || source === void 0 ? void 0 : source.destroy);
333
+ options.destroy.load(source?.destroy);
231
334
  }
232
335
  }
233
336
  particleDestroyed(particle, override) {
@@ -236,7 +339,7 @@ class DestroyUpdater {
236
339
  }
237
340
  const destroyOptions = particle.options.destroy;
238
341
  if (destroyOptions && destroyOptions.mode === "split") {
239
- this.split(particle);
342
+ split(this.engine, this.container, particle);
240
343
  }
241
344
  }
242
345
  update(particle) {
@@ -252,72 +355,11 @@ class DestroyUpdater {
252
355
  particle.destroy();
253
356
  }
254
357
  }
255
- addSplitParticle(parent, splitParticlesOptions) {
256
- const destroyOptions = parent.options.destroy;
257
- if (!destroyOptions) {
258
- return;
259
- }
260
- const splitOptions = destroyOptions.split,
261
- options = (0,engine_root_window_.loadParticlesOptions)(this.engine, this.container, parent.options),
262
- factor = (0,engine_root_window_.getValue)(splitOptions.factor);
263
- options.color.load({
264
- value: {
265
- hsl: parent.getFillColor()
266
- }
267
- });
268
- options.move.load({
269
- center: {
270
- x: parent.position.x,
271
- y: parent.position.y,
272
- mode: "precise"
273
- }
274
- });
275
- if (typeof options.size.value === "number") {
276
- options.size.value /= factor;
277
- } else {
278
- options.size.value.min /= factor;
279
- options.size.value.max /= factor;
280
- }
281
- options.load(splitParticlesOptions);
282
- const offset = splitOptions.sizeOffset ? (0,engine_root_window_.setRangeValue)(-parent.size.value, parent.size.value) : 0,
283
- position = {
284
- x: parent.position.x + (0,engine_root_window_.randomInRange)(offset),
285
- y: parent.position.y + (0,engine_root_window_.randomInRange)(offset)
286
- };
287
- return this.container.particles.addParticle(position, options, parent.group, particle => {
288
- var _a;
289
- if (particle.size.value < 0.5) {
290
- return false;
291
- }
292
- particle.velocity.length = (0,engine_root_window_.randomInRange)((0,engine_root_window_.setRangeValue)(parent.velocity.length, particle.velocity.length));
293
- particle.splitCount = ((_a = parent.splitCount) !== null && _a !== void 0 ? _a : 0) + 1;
294
- particle.unbreakable = true;
295
- setTimeout(() => {
296
- particle.unbreakable = false;
297
- }, 500);
298
- return true;
299
- });
300
- }
301
- split(particle) {
302
- const destroyOptions = particle.options.destroy;
303
- if (!destroyOptions) {
304
- return;
305
- }
306
- const splitOptions = destroyOptions.split;
307
- if (splitOptions.count >= 0 && (particle.splitCount === undefined || particle.splitCount++ > splitOptions.count)) {
308
- return;
309
- }
310
- const rate = (0,engine_root_window_.getValue)(splitOptions.rate),
311
- particlesSplitOptions = (0,engine_root_window_.itemFromSingleOrMultiple)(splitOptions.particles);
312
- for (let i = 0; i < rate; i++) {
313
- this.addSplitParticle(particle, particlesSplitOptions);
314
- }
315
- }
316
358
  }
317
359
  ;// CONCATENATED MODULE: ./dist/browser/index.js
318
360
 
319
- async function loadDestroyUpdater(engine) {
320
- await engine.addParticleUpdater("destroy", container => new DestroyUpdater(engine, container));
361
+ async function loadDestroyUpdater(engine, refresh = true) {
362
+ await engine.addParticleUpdater("destroy", container => new DestroyUpdater(engine, container), refresh);
321
363
  }
322
364
  })();
323
365
 
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.updater.destroy.min.js.LICENSE.txt */
2
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var o="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var s in o)("object"==typeof exports?exports:t)[s]=o[s]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},o={};function s(t){var i=o[t];if(void 0!==i)return i.exports;var n=o[t]={exports:{}};return e[t](n,n.exports,s),n.exports}s.d=(t,e)=>{for(var o in e)s.o(e,o)&&!s.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{s.r(i),s.d(i,{loadDestroyUpdater:()=>d});var t=s(533);class e{load(e){e&&(void 0!==e.bottom&&(this.bottom=(0,t.setRangeValue)(e.bottom)),void 0!==e.left&&(this.left=(0,t.setRangeValue)(e.left)),void 0!==e.right&&(this.right=(0,t.setRangeValue)(e.right)),void 0!==e.top&&(this.top=(0,t.setRangeValue)(e.top)))}}class o extends t.ValueWithRandom{constructor(){super(),this.value=3}}class n extends t.ValueWithRandom{constructor(){super(),this.value={min:4,max:9}}}class r{constructor(){this.count=1,this.factor=new o,this.rate=new n,this.sizeOffset=!0}load(e){e&&(void 0!==e.count&&(this.count=e.count),this.factor.load(e.factor),this.rate.load(e.rate),this.particles=(0,t.executeOnSingleOrMultiple)(e.particles,(e=>(0,t.deepExtend)({},e))),void 0!==e.sizeOffset&&(this.sizeOffset=e.sizeOffset))}}class a{constructor(){this.bounds=new e,this.mode="none",this.split=new r}load(t){t&&(t.mode&&(this.mode=t.mode),t.bounds&&this.bounds.load(t.bounds),this.split.load(t.split))}}class l{constructor(t,e){this.engine=t,this.container=e}init(e){const o=this.container,s=e.options.destroy;if(!s)return;e.splitCount=0;const i=s.bounds;e.destroyBounds||(e.destroyBounds={}),i.bottom&&(e.destroyBounds.bottom=(0,t.getRangeValue)(i.bottom)*o.canvas.size.height/100),i.left&&(e.destroyBounds.left=(0,t.getRangeValue)(i.left)*o.canvas.size.width/100),i.right&&(e.destroyBounds.right=(0,t.getRangeValue)(i.right)*o.canvas.size.width/100),i.top&&(e.destroyBounds.top=(0,t.getRangeValue)(i.top)*o.canvas.size.height/100)}isEnabled(t){return!t.destroyed}loadOptions(t,...e){t.destroy||(t.destroy=new a);for(const o of e)t.destroy.load(null==o?void 0:o.destroy)}particleDestroyed(t,e){if(e)return;const o=t.options.destroy;o&&"split"===o.mode&&this.split(t)}update(t){if(!this.isEnabled(t))return;const e=t.getPosition(),o=t.destroyBounds;o&&(void 0!==o.bottom&&e.y>=o.bottom||void 0!==o.left&&e.x<=o.left||void 0!==o.right&&e.x>=o.right||void 0!==o.top&&e.y<=o.top)&&t.destroy()}addSplitParticle(e,o){const s=e.options.destroy;if(!s)return;const i=s.split,n=(0,t.loadParticlesOptions)(this.engine,this.container,e.options),r=(0,t.getValue)(i.factor);n.color.load({value:{hsl:e.getFillColor()}}),n.move.load({center:{x:e.position.x,y:e.position.y,mode:"precise"}}),"number"==typeof n.size.value?n.size.value/=r:(n.size.value.min/=r,n.size.value.max/=r),n.load(o);const a=i.sizeOffset?(0,t.setRangeValue)(-e.size.value,e.size.value):0,l={x:e.position.x+(0,t.randomInRange)(a),y:e.position.y+(0,t.randomInRange)(a)};return this.container.particles.addParticle(l,n,e.group,(o=>{var s;return!(o.size.value<.5)&&(o.velocity.length=(0,t.randomInRange)((0,t.setRangeValue)(e.velocity.length,o.velocity.length)),o.splitCount=(null!==(s=e.splitCount)&&void 0!==s?s:0)+1,o.unbreakable=!0,setTimeout((()=>{o.unbreakable=!1}),500),!0)}))}split(e){const o=e.options.destroy;if(!o)return;const s=o.split;if(s.count>=0&&(void 0===e.splitCount||e.splitCount++>s.count))return;const i=(0,t.getValue)(s.rate),n=(0,t.itemFromSingleOrMultiple)(s.particles);for(let t=0;t<i;t++)this.addSplitParticle(e,n)}}async function d(t){await t.addParticleUpdater("destroy",(e=>new l(t,e)))}})(),i})()));
2
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var o="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var s in o)("object"==typeof exports?exports:t)[s]=o[s]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},o={};function s(t){var i=o[t];if(void 0!==i)return i.exports;var r=o[t]={exports:{}};return e[t](r,r.exports,s),r.exports}s.d=(t,e)=>{for(var o in e)s.o(e,o)&&!s.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{s.r(i),s.d(i,{loadDestroyUpdater:()=>d});var t=s(533);class e{load(e){e&&(void 0!==e.bottom&&(this.bottom=(0,t.setRangeValue)(e.bottom)),void 0!==e.left&&(this.left=(0,t.setRangeValue)(e.left)),void 0!==e.right&&(this.right=(0,t.setRangeValue)(e.right)),void 0!==e.top&&(this.top=(0,t.setRangeValue)(e.top)))}}class o extends t.ValueWithRandom{constructor(){super(),this.value=3}}class r extends t.ValueWithRandom{constructor(){super(),this.value={min:4,max:9}}}class n{constructor(){this.count=1,this.factor=new o,this.rate=new r,this.sizeOffset=!0}load(e){e&&(void 0!==e.color&&(this.color=t.OptionsColor.create(this.color,e.color)),void 0!==e.count&&(this.count=e.count),this.factor.load(e.factor),this.rate.load(e.rate),this.particles=(0,t.executeOnSingleOrMultiple)(e.particles,(e=>(0,t.deepExtend)({},e))),void 0!==e.sizeOffset&&(this.sizeOffset=e.sizeOffset),e.colorOffset&&(this.colorOffset=this.colorOffset??{},void 0!==e.colorOffset.h&&(this.colorOffset.h=e.colorOffset.h),void 0!==e.colorOffset.s&&(this.colorOffset.s=e.colorOffset.s),void 0!==e.colorOffset.l&&(this.colorOffset.l=e.colorOffset.l)))}}class l{constructor(){this.bounds=new e,this.mode="none",this.split=new n}load(t){t&&(t.mode&&(this.mode=t.mode),t.bounds&&this.bounds.load(t.bounds),this.split.load(t.split))}}function a(e,o,s,i){const r=s.options.destroy;if(!r)return;const n=r.split,l=(0,t.loadParticlesOptions)(e,o,s.options),a=(0,t.getValue)(n.factor),c=s.getFillColor();n.color?l.color.load(n.color):n.colorOffset&&c?l.color.load({value:{hsl:{h:c.h+(0,t.getRangeValue)(n.colorOffset.h??0),s:c.s+(0,t.getRangeValue)(n.colorOffset.s??0),l:c.l+(0,t.getRangeValue)(n.colorOffset.l??0)}}}):l.color.load({value:{hsl:s.getFillColor()}}),l.move.load({center:{x:s.position.x,y:s.position.y,mode:"precise"}}),(0,t.isNumber)(l.size.value)?l.size.value/=a:(l.size.value.min/=a,l.size.value.max/=a),l.load(i);const d=n.sizeOffset?(0,t.setRangeValue)(-s.size.value,s.size.value):0,u={x:s.position.x+(0,t.randomInRange)(d),y:s.position.y+(0,t.randomInRange)(d)};return o.particles.addParticle(u,l,s.group,(e=>!(e.size.value<.5)&&(e.velocity.length=(0,t.randomInRange)((0,t.setRangeValue)(s.velocity.length,e.velocity.length)),e.splitCount=(s.splitCount??0)+1,e.unbreakable=!0,setTimeout((()=>{e.unbreakable=!1}),500),!0)))}class c{constructor(t,e){this.engine=t,this.container=e}init(e){const o=this.container,s=e.options.destroy;if(!s)return;e.splitCount=0;const i=s.bounds;e.destroyBounds||(e.destroyBounds={});const{bottom:r,left:n,right:l,top:a}=i,{destroyBounds:c}=e,d=o.canvas.size;r&&(c.bottom=(0,t.getRangeValue)(r)*d.height/100),n&&(c.left=(0,t.getRangeValue)(n)*d.width/100),l&&(c.right=(0,t.getRangeValue)(l)*d.width/100),a&&(c.top=(0,t.getRangeValue)(a)*d.height/100)}isEnabled(t){return!t.destroyed}loadOptions(t,...e){t.destroy||(t.destroy=new l);for(const o of e)t.destroy.load(o?.destroy)}particleDestroyed(e,o){if(o)return;const s=e.options.destroy;s&&"split"===s.mode&&function(e,o,s){const i=s.options.destroy;if(!i)return;const r=i.split;if(r.count>=0&&(void 0===s.splitCount||s.splitCount++>r.count))return;const n=(0,t.getValue)(r.rate),l=(0,t.itemFromSingleOrMultiple)(r.particles);for(let t=0;t<n;t++)a(e,o,s,l)}(this.engine,this.container,e)}update(t){if(!this.isEnabled(t))return;const e=t.getPosition(),o=t.destroyBounds;o&&(void 0!==o.bottom&&e.y>=o.bottom||void 0!==o.left&&e.x<=o.left||void 0!==o.right&&e.x>=o.right||void 0!==o.top&&e.y<=o.top)&&t.destroy()}}async function d(t,e=!0){await t.addParticleUpdater("destroy",(e=>new c(t,e)),e)}})(),i})()));
@@ -1,8 +1 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
8
- */
1
+ /*! tsParticles Destroy Updater v3.0.0-beta.0 by Matteo Bruni */
@@ -1,17 +1,5 @@
1
- import type { Container, Engine, IBounds, IParticleUpdater, IParticlesOptions, Particle, ParticlesOptions, RecursivePartial } from "@tsparticles/engine";
2
- import { Destroy } from "./Options/Classes/Destroy";
3
- import type { IDestroy } from "./Options/Interfaces/IDestroy";
4
- type IDestroyParticlesOptions = IParticlesOptions & {
5
- destroy?: IDestroy;
6
- };
7
- type DestroyParticlesOptions = ParticlesOptions & {
8
- destroy?: Destroy;
9
- };
10
- type DestroyParticle = Particle & {
11
- destroyBounds?: Partial<IBounds>;
12
- options: DestroyParticlesOptions;
13
- splitCount?: number;
14
- };
1
+ import { type Container, type Engine, type IParticleUpdater, type Particle, type RecursivePartial } from "@tsparticles/engine";
2
+ import type { DestroyParticle, DestroyParticlesOptions, IDestroyParticlesOptions } from "./Types";
15
3
  export declare class DestroyUpdater implements IParticleUpdater {
16
4
  private readonly engine;
17
5
  private readonly container;
@@ -21,7 +9,4 @@ export declare class DestroyUpdater implements IParticleUpdater {
21
9
  loadOptions(options: DestroyParticlesOptions, ...sources: (RecursivePartial<IDestroyParticlesOptions> | undefined)[]): void;
22
10
  particleDestroyed(particle: DestroyParticle, override?: boolean): void;
23
11
  update(particle: DestroyParticle): void;
24
- private addSplitParticle;
25
- private split;
26
12
  }
27
- export {};
@@ -1,4 +1,4 @@
1
- import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
1
+ import { type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine";
2
2
  import type { IDestroyBounds } from "../Interfaces/IDestroyBounds";
3
3
  export declare class DestroyBounds implements IDestroyBounds, IOptionLoader<IDestroyBounds> {
4
4
  bottom?: RangeValue;
@@ -1,8 +1,10 @@
1
- import type { IOptionLoader, IParticlesOptions, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
1
+ import { type IOptionLoader, type IParticlesOptions, type IRangeHsl, OptionsColor, type RecursivePartial, type SingleOrMultiple } from "@tsparticles/engine";
2
2
  import type { ISplit } from "../Interfaces/ISplit";
3
3
  import { SplitFactor } from "./SplitFactor";
4
4
  import { SplitRate } from "./SplitRate";
5
5
  export declare class Split implements ISplit, IOptionLoader<ISplit> {
6
+ color?: OptionsColor;
7
+ colorOffset?: Partial<IRangeHsl>;
6
8
  count: number;
7
9
  factor: SplitFactor;
8
10
  particles?: SingleOrMultiple<RecursivePartial<IParticlesOptions>>;
@@ -1,5 +1,7 @@
1
- import type { IParticlesOptions, IValueWithRandom, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
1
+ import type { IOptionsColor, IParticlesOptions, IRangeHsl, IValueWithRandom, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
2
2
  export interface ISplit {
3
+ color?: string | IOptionsColor;
4
+ colorOffset?: Partial<IRangeHsl>;
3
5
  count: number;
4
6
  factor: IValueWithRandom;
5
7
  particles?: SingleOrMultiple<RecursivePartial<IParticlesOptions>>;
@@ -0,0 +1,14 @@
1
+ import type { IBounds, IParticlesOptions, Particle, ParticlesOptions } from "@tsparticles/engine";
2
+ import type { Destroy } from "./Options/Classes/Destroy";
3
+ import type { IDestroy } from "./Options/Interfaces/IDestroy";
4
+ export type IDestroyParticlesOptions = IParticlesOptions & {
5
+ destroy?: IDestroy;
6
+ };
7
+ export type DestroyParticlesOptions = ParticlesOptions & {
8
+ destroy?: Destroy;
9
+ };
10
+ export type DestroyParticle = Particle & {
11
+ destroyBounds?: Partial<IBounds>;
12
+ options: DestroyParticlesOptions;
13
+ splitCount?: number;
14
+ };
@@ -0,0 +1,3 @@
1
+ import { type Container, type Engine } from "@tsparticles/engine";
2
+ import type { DestroyParticle } from "./Types";
3
+ export declare function split(engine: Engine, container: Container, particle: DestroyParticle): void;
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadDestroyUpdater(engine: Engine): Promise<void>;
2
+ export declare function loadDestroyUpdater(engine: Engine, refresh?: boolean): Promise<void>;
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Destroy"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Destroy", "./Utils"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -12,6 +12,7 @@
12
12
  exports.DestroyUpdater = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  const Destroy_1 = require("./Options/Classes/Destroy");
15
+ const Utils_1 = require("./Utils");
15
16
  class DestroyUpdater {
16
17
  constructor(engine, container) {
17
18
  this.engine = engine;
@@ -23,21 +24,22 @@
23
24
  return;
24
25
  }
25
26
  particle.splitCount = 0;
26
- const destroyBounds = destroyOptions.bounds;
27
+ const destroyBoundsOptions = destroyOptions.bounds;
27
28
  if (!particle.destroyBounds) {
28
29
  particle.destroyBounds = {};
29
30
  }
30
- if (destroyBounds.bottom) {
31
- particle.destroyBounds.bottom = ((0, engine_1.getRangeValue)(destroyBounds.bottom) * container.canvas.size.height) / 100;
31
+ const { bottom, left, right, top } = destroyBoundsOptions, { destroyBounds } = particle, canvasSize = container.canvas.size;
32
+ if (bottom) {
33
+ destroyBounds.bottom = ((0, engine_1.getRangeValue)(bottom) * canvasSize.height) / 100;
32
34
  }
33
- if (destroyBounds.left) {
34
- particle.destroyBounds.left = ((0, engine_1.getRangeValue)(destroyBounds.left) * container.canvas.size.width) / 100;
35
+ if (left) {
36
+ destroyBounds.left = ((0, engine_1.getRangeValue)(left) * canvasSize.width) / 100;
35
37
  }
36
- if (destroyBounds.right) {
37
- particle.destroyBounds.right = ((0, engine_1.getRangeValue)(destroyBounds.right) * container.canvas.size.width) / 100;
38
+ if (right) {
39
+ destroyBounds.right = ((0, engine_1.getRangeValue)(right) * canvasSize.width) / 100;
38
40
  }
39
- if (destroyBounds.top) {
40
- particle.destroyBounds.top = ((0, engine_1.getRangeValue)(destroyBounds.top) * container.canvas.size.height) / 100;
41
+ if (top) {
42
+ destroyBounds.top = ((0, engine_1.getRangeValue)(top) * canvasSize.height) / 100;
41
43
  }
42
44
  }
43
45
  isEnabled(particle) {
@@ -48,7 +50,7 @@
48
50
  options.destroy = new Destroy_1.Destroy();
49
51
  }
50
52
  for (const source of sources) {
51
- options.destroy.load(source === null || source === void 0 ? void 0 : source.destroy);
53
+ options.destroy.load(source?.destroy);
52
54
  }
53
55
  }
54
56
  particleDestroyed(particle, override) {
@@ -57,7 +59,7 @@
57
59
  }
58
60
  const destroyOptions = particle.options.destroy;
59
61
  if (destroyOptions && destroyOptions.mode === "split") {
60
- this.split(particle);
62
+ (0, Utils_1.split)(this.engine, this.container, particle);
61
63
  }
62
64
  }
63
65
  update(particle) {
@@ -75,65 +77,6 @@
75
77
  particle.destroy();
76
78
  }
77
79
  }
78
- addSplitParticle(parent, splitParticlesOptions) {
79
- const destroyOptions = parent.options.destroy;
80
- if (!destroyOptions) {
81
- return;
82
- }
83
- const splitOptions = destroyOptions.split, options = (0, engine_1.loadParticlesOptions)(this.engine, this.container, parent.options), factor = (0, engine_1.getValue)(splitOptions.factor);
84
- options.color.load({
85
- value: {
86
- hsl: parent.getFillColor(),
87
- },
88
- });
89
- options.move.load({
90
- center: {
91
- x: parent.position.x,
92
- y: parent.position.y,
93
- mode: "precise",
94
- },
95
- });
96
- if (typeof options.size.value === "number") {
97
- options.size.value /= factor;
98
- }
99
- else {
100
- options.size.value.min /= factor;
101
- options.size.value.max /= factor;
102
- }
103
- options.load(splitParticlesOptions);
104
- const offset = splitOptions.sizeOffset ? (0, engine_1.setRangeValue)(-parent.size.value, parent.size.value) : 0, position = {
105
- x: parent.position.x + (0, engine_1.randomInRange)(offset),
106
- y: parent.position.y + (0, engine_1.randomInRange)(offset),
107
- };
108
- return this.container.particles.addParticle(position, options, parent.group, (particle) => {
109
- var _a;
110
- if (particle.size.value < 0.5) {
111
- return false;
112
- }
113
- particle.velocity.length = (0, engine_1.randomInRange)((0, engine_1.setRangeValue)(parent.velocity.length, particle.velocity.length));
114
- particle.splitCount = ((_a = parent.splitCount) !== null && _a !== void 0 ? _a : 0) + 1;
115
- particle.unbreakable = true;
116
- setTimeout(() => {
117
- particle.unbreakable = false;
118
- }, 500);
119
- return true;
120
- });
121
- }
122
- split(particle) {
123
- const destroyOptions = particle.options.destroy;
124
- if (!destroyOptions) {
125
- return;
126
- }
127
- const splitOptions = destroyOptions.split;
128
- if (splitOptions.count >= 0 &&
129
- (particle.splitCount === undefined || particle.splitCount++ > splitOptions.count)) {
130
- return;
131
- }
132
- const rate = (0, engine_1.getValue)(splitOptions.rate), particlesSplitOptions = (0, engine_1.itemFromSingleOrMultiple)(splitOptions.particles);
133
- for (let i = 0; i < rate; i++) {
134
- this.addSplitParticle(particle, particlesSplitOptions);
135
- }
136
- }
137
80
  }
138
81
  exports.DestroyUpdater = DestroyUpdater;
139
82
  });
@@ -24,6 +24,9 @@
24
24
  if (!data) {
25
25
  return;
26
26
  }
27
+ if (data.color !== undefined) {
28
+ this.color = engine_1.OptionsColor.create(this.color, data.color);
29
+ }
27
30
  if (data.count !== undefined) {
28
31
  this.count = data.count;
29
32
  }
@@ -35,6 +38,18 @@
35
38
  if (data.sizeOffset !== undefined) {
36
39
  this.sizeOffset = data.sizeOffset;
37
40
  }
41
+ if (data.colorOffset) {
42
+ this.colorOffset = this.colorOffset ?? {};
43
+ if (data.colorOffset.h !== undefined) {
44
+ this.colorOffset.h = data.colorOffset.h;
45
+ }
46
+ if (data.colorOffset.s !== undefined) {
47
+ this.colorOffset.s = data.colorOffset.s;
48
+ }
49
+ if (data.colorOffset.l !== undefined) {
50
+ this.colorOffset.l = data.colorOffset.l;
51
+ }
52
+ }
38
53
  }
39
54
  }
40
55
  exports.Split = Split;
package/umd/Types.js ADDED
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
package/umd/Utils.js ADDED
@@ -0,0 +1,88 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.split = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ function addSplitParticle(engine, container, parent, splitParticlesOptions) {
15
+ const destroyOptions = parent.options.destroy;
16
+ if (!destroyOptions) {
17
+ return;
18
+ }
19
+ const splitOptions = destroyOptions.split, options = (0, engine_1.loadParticlesOptions)(engine, container, parent.options), factor = (0, engine_1.getValue)(splitOptions.factor), parentColor = parent.getFillColor();
20
+ if (splitOptions.color) {
21
+ options.color.load(splitOptions.color);
22
+ }
23
+ else if (splitOptions.colorOffset && parentColor) {
24
+ options.color.load({
25
+ value: {
26
+ hsl: {
27
+ h: parentColor.h + (0, engine_1.getRangeValue)(splitOptions.colorOffset.h ?? 0),
28
+ s: parentColor.s + (0, engine_1.getRangeValue)(splitOptions.colorOffset.s ?? 0),
29
+ l: parentColor.l + (0, engine_1.getRangeValue)(splitOptions.colorOffset.l ?? 0),
30
+ },
31
+ },
32
+ });
33
+ }
34
+ else {
35
+ options.color.load({
36
+ value: {
37
+ hsl: parent.getFillColor(),
38
+ },
39
+ });
40
+ }
41
+ options.move.load({
42
+ center: {
43
+ x: parent.position.x,
44
+ y: parent.position.y,
45
+ mode: "precise",
46
+ },
47
+ });
48
+ if ((0, engine_1.isNumber)(options.size.value)) {
49
+ options.size.value /= factor;
50
+ }
51
+ else {
52
+ options.size.value.min /= factor;
53
+ options.size.value.max /= factor;
54
+ }
55
+ options.load(splitParticlesOptions);
56
+ const offset = splitOptions.sizeOffset ? (0, engine_1.setRangeValue)(-parent.size.value, parent.size.value) : 0, position = {
57
+ x: parent.position.x + (0, engine_1.randomInRange)(offset),
58
+ y: parent.position.y + (0, engine_1.randomInRange)(offset),
59
+ };
60
+ return container.particles.addParticle(position, options, parent.group, (particle) => {
61
+ if (particle.size.value < 0.5) {
62
+ return false;
63
+ }
64
+ particle.velocity.length = (0, engine_1.randomInRange)((0, engine_1.setRangeValue)(parent.velocity.length, particle.velocity.length));
65
+ particle.splitCount = (parent.splitCount ?? 0) + 1;
66
+ particle.unbreakable = true;
67
+ setTimeout(() => {
68
+ particle.unbreakable = false;
69
+ }, 500);
70
+ return true;
71
+ });
72
+ }
73
+ function split(engine, container, particle) {
74
+ const destroyOptions = particle.options.destroy;
75
+ if (!destroyOptions) {
76
+ return;
77
+ }
78
+ const splitOptions = destroyOptions.split;
79
+ if (splitOptions.count >= 0 && (particle.splitCount === undefined || particle.splitCount++ > splitOptions.count)) {
80
+ return;
81
+ }
82
+ const rate = (0, engine_1.getValue)(splitOptions.rate), particlesSplitOptions = (0, engine_1.itemFromSingleOrMultiple)(splitOptions.particles);
83
+ for (let i = 0; i < rate; i++) {
84
+ addSplitParticle(engine, container, particle, particlesSplitOptions);
85
+ }
86
+ }
87
+ exports.split = split;
88
+ });
package/umd/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadDestroyUpdater = void 0;
13
13
  const DestroyUpdater_1 = require("./DestroyUpdater");
14
- async function loadDestroyUpdater(engine) {
15
- await engine.addParticleUpdater("destroy", (container) => new DestroyUpdater_1.DestroyUpdater(engine, container));
14
+ async function loadDestroyUpdater(engine, refresh = true) {
15
+ await engine.addParticleUpdater("destroy", (container) => new DestroyUpdater_1.DestroyUpdater(engine, container), refresh);
16
16
  }
17
17
  exports.loadDestroyUpdater = loadDestroyUpdater;
18
18
  });