@tsparticles/updater-destroy 3.0.0-alpha.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/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/DestroyUpdater.js +125 -0
- package/browser/Enums/DestroyMode.js +1 -0
- package/browser/Options/Classes/Destroy.js +21 -0
- package/browser/Options/Classes/DestroyBounds.js +20 -0
- package/browser/Options/Classes/Split.js +27 -0
- package/browser/Options/Classes/SplitFactor.js +7 -0
- package/browser/Options/Classes/SplitRate.js +7 -0
- package/browser/Options/Interfaces/IDestroy.js +1 -0
- package/browser/Options/Interfaces/IDestroyBounds.js +1 -0
- package/browser/Options/Interfaces/ISplit.js +1 -0
- package/browser/index.js +4 -0
- package/cjs/DestroyUpdater.js +129 -0
- package/cjs/Enums/DestroyMode.js +2 -0
- package/cjs/Options/Classes/Destroy.js +25 -0
- package/cjs/Options/Classes/DestroyBounds.js +24 -0
- package/cjs/Options/Classes/Split.js +31 -0
- package/cjs/Options/Classes/SplitFactor.js +11 -0
- package/cjs/Options/Classes/SplitRate.js +11 -0
- package/cjs/Options/Interfaces/IDestroy.js +2 -0
- package/cjs/Options/Interfaces/IDestroyBounds.js +2 -0
- package/cjs/Options/Interfaces/ISplit.js +2 -0
- package/cjs/index.js +19 -0
- package/esm/DestroyUpdater.js +125 -0
- package/esm/Enums/DestroyMode.js +1 -0
- package/esm/Options/Classes/Destroy.js +21 -0
- package/esm/Options/Classes/DestroyBounds.js +20 -0
- package/esm/Options/Classes/Split.js +27 -0
- package/esm/Options/Classes/SplitFactor.js +7 -0
- package/esm/Options/Classes/SplitRate.js +7 -0
- package/esm/Options/Interfaces/IDestroy.js +1 -0
- package/esm/Options/Interfaces/IDestroyBounds.js +1 -0
- package/esm/Options/Interfaces/ISplit.js +1 -0
- package/esm/index.js +4 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.updater.destroy.js +327 -0
- package/tsparticles.updater.destroy.min.js +2 -0
- package/tsparticles.updater.destroy.min.js.LICENSE.txt +8 -0
- package/types/DestroyUpdater.d.ts +27 -0
- package/types/Enums/DestroyMode.d.ts +4 -0
- package/types/Options/Classes/Destroy.d.ts +12 -0
- package/types/Options/Classes/DestroyBounds.d.ts +9 -0
- package/types/Options/Classes/Split.d.ts +13 -0
- package/types/Options/Classes/SplitFactor.d.ts +4 -0
- package/types/Options/Classes/SplitRate.d.ts +4 -0
- package/types/Options/Interfaces/IDestroy.d.ts +8 -0
- package/types/Options/Interfaces/IDestroyBounds.d.ts +7 -0
- package/types/Options/Interfaces/ISplit.d.ts +8 -0
- package/types/index.d.ts +2 -0
- package/umd/DestroyUpdater.js +139 -0
- package/umd/Enums/DestroyMode.js +12 -0
- package/umd/Options/Classes/Destroy.js +35 -0
- package/umd/Options/Classes/DestroyBounds.js +34 -0
- package/umd/Options/Classes/Split.js +41 -0
- package/umd/Options/Classes/SplitFactor.js +21 -0
- package/umd/Options/Classes/SplitRate.js +21 -0
- package/umd/Options/Interfaces/IDestroy.js +12 -0
- package/umd/Options/Interfaces/IDestroyBounds.js +12 -0
- package/umd/Options/Interfaces/ISplit.js +12 -0
- package/umd/index.js +18 -0
|
@@ -0,0 +1,327 @@
|
|
|
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
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
|
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
|
20
|
+
/******/ "use strict";
|
|
21
|
+
/******/ var __webpack_modules__ = ({
|
|
22
|
+
|
|
23
|
+
/***/ 533:
|
|
24
|
+
/***/ ((module) => {
|
|
25
|
+
|
|
26
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
/******/ });
|
|
31
|
+
/************************************************************************/
|
|
32
|
+
/******/ // The module cache
|
|
33
|
+
/******/ var __webpack_module_cache__ = {};
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // The require function
|
|
36
|
+
/******/ function __webpack_require__(moduleId) {
|
|
37
|
+
/******/ // Check if module is in cache
|
|
38
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
39
|
+
/******/ if (cachedModule !== undefined) {
|
|
40
|
+
/******/ return cachedModule.exports;
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ // Create a new module (and put it into the cache)
|
|
43
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
44
|
+
/******/ // no module.id needed
|
|
45
|
+
/******/ // no module.loaded needed
|
|
46
|
+
/******/ exports: {}
|
|
47
|
+
/******/ };
|
|
48
|
+
/******/
|
|
49
|
+
/******/ // Execute the module function
|
|
50
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // Return the exports of the module
|
|
53
|
+
/******/ return module.exports;
|
|
54
|
+
/******/ }
|
|
55
|
+
/******/
|
|
56
|
+
/************************************************************************/
|
|
57
|
+
/******/ /* webpack/runtime/define property getters */
|
|
58
|
+
/******/ (() => {
|
|
59
|
+
/******/ // define getter functions for harmony exports
|
|
60
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
61
|
+
/******/ for(var key in definition) {
|
|
62
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
63
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
64
|
+
/******/ }
|
|
65
|
+
/******/ }
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/ })();
|
|
68
|
+
/******/
|
|
69
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
70
|
+
/******/ (() => {
|
|
71
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
72
|
+
/******/ })();
|
|
73
|
+
/******/
|
|
74
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
75
|
+
/******/ (() => {
|
|
76
|
+
/******/ // define __esModule on exports
|
|
77
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
78
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
79
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
80
|
+
/******/ }
|
|
81
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
82
|
+
/******/ };
|
|
83
|
+
/******/ })();
|
|
84
|
+
/******/
|
|
85
|
+
/************************************************************************/
|
|
86
|
+
var __webpack_exports__ = {};
|
|
87
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
88
|
+
(() => {
|
|
89
|
+
// ESM COMPAT FLAG
|
|
90
|
+
__webpack_require__.r(__webpack_exports__);
|
|
91
|
+
|
|
92
|
+
// EXPORTS
|
|
93
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
+
"loadDestroyUpdater": () => (/* binding */ loadDestroyUpdater)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
98
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
99
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/DestroyBounds.js
|
|
100
|
+
|
|
101
|
+
class DestroyBounds {
|
|
102
|
+
load(data) {
|
|
103
|
+
if (!data) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (data.bottom !== undefined) {
|
|
107
|
+
this.bottom = (0,engine_root_window_.setRangeValue)(data.bottom);
|
|
108
|
+
}
|
|
109
|
+
if (data.left !== undefined) {
|
|
110
|
+
this.left = (0,engine_root_window_.setRangeValue)(data.left);
|
|
111
|
+
}
|
|
112
|
+
if (data.right !== undefined) {
|
|
113
|
+
this.right = (0,engine_root_window_.setRangeValue)(data.right);
|
|
114
|
+
}
|
|
115
|
+
if (data.top !== undefined) {
|
|
116
|
+
this.top = (0,engine_root_window_.setRangeValue)(data.top);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/SplitFactor.js
|
|
121
|
+
|
|
122
|
+
class SplitFactor extends engine_root_window_.ValueWithRandom {
|
|
123
|
+
constructor() {
|
|
124
|
+
super();
|
|
125
|
+
this.value = 3;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/SplitRate.js
|
|
129
|
+
|
|
130
|
+
class SplitRate extends engine_root_window_.ValueWithRandom {
|
|
131
|
+
constructor() {
|
|
132
|
+
super();
|
|
133
|
+
this.value = {
|
|
134
|
+
min: 4,
|
|
135
|
+
max: 9
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Split.js
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class Split {
|
|
144
|
+
constructor() {
|
|
145
|
+
this.count = 1;
|
|
146
|
+
this.factor = new SplitFactor();
|
|
147
|
+
this.rate = new SplitRate();
|
|
148
|
+
this.sizeOffset = true;
|
|
149
|
+
}
|
|
150
|
+
load(data) {
|
|
151
|
+
if (!data) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (data.count !== undefined) {
|
|
155
|
+
this.count = data.count;
|
|
156
|
+
}
|
|
157
|
+
this.factor.load(data.factor);
|
|
158
|
+
this.rate.load(data.rate);
|
|
159
|
+
this.particles = (0,engine_root_window_.executeOnSingleOrMultiple)(data.particles, particles => {
|
|
160
|
+
return (0,engine_root_window_.deepExtend)({}, particles);
|
|
161
|
+
});
|
|
162
|
+
if (data.sizeOffset !== undefined) {
|
|
163
|
+
this.sizeOffset = data.sizeOffset;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Destroy.js
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class Destroy {
|
|
171
|
+
constructor() {
|
|
172
|
+
this.bounds = new DestroyBounds();
|
|
173
|
+
this.mode = "none";
|
|
174
|
+
this.split = new Split();
|
|
175
|
+
}
|
|
176
|
+
load(data) {
|
|
177
|
+
if (!data) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (data.mode) {
|
|
181
|
+
this.mode = data.mode;
|
|
182
|
+
}
|
|
183
|
+
if (data.bounds) {
|
|
184
|
+
this.bounds.load(data.bounds);
|
|
185
|
+
}
|
|
186
|
+
this.split.load(data.split);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
;// CONCATENATED MODULE: ./dist/browser/DestroyUpdater.js
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class DestroyUpdater {
|
|
193
|
+
constructor(engine, container) {
|
|
194
|
+
this.engine = engine;
|
|
195
|
+
this.container = container;
|
|
196
|
+
}
|
|
197
|
+
init(particle) {
|
|
198
|
+
const container = this.container,
|
|
199
|
+
particlesOptions = particle.options,
|
|
200
|
+
destroyOptions = particlesOptions.destroy;
|
|
201
|
+
if (!destroyOptions) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
particle.splitCount = 0;
|
|
205
|
+
const destroyBounds = destroyOptions.bounds;
|
|
206
|
+
if (!particle.destroyBounds) {
|
|
207
|
+
particle.destroyBounds = {};
|
|
208
|
+
}
|
|
209
|
+
if (destroyBounds.bottom) {
|
|
210
|
+
particle.destroyBounds.bottom = (0,engine_root_window_.getRangeValue)(destroyBounds.bottom) * container.canvas.size.height / 100;
|
|
211
|
+
}
|
|
212
|
+
if (destroyBounds.left) {
|
|
213
|
+
particle.destroyBounds.left = (0,engine_root_window_.getRangeValue)(destroyBounds.left) * container.canvas.size.width / 100;
|
|
214
|
+
}
|
|
215
|
+
if (destroyBounds.right) {
|
|
216
|
+
particle.destroyBounds.right = (0,engine_root_window_.getRangeValue)(destroyBounds.right) * container.canvas.size.width / 100;
|
|
217
|
+
}
|
|
218
|
+
if (destroyBounds.top) {
|
|
219
|
+
particle.destroyBounds.top = (0,engine_root_window_.getRangeValue)(destroyBounds.top) * container.canvas.size.height / 100;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
isEnabled(particle) {
|
|
223
|
+
return !particle.destroyed;
|
|
224
|
+
}
|
|
225
|
+
loadOptions(options, ...sources) {
|
|
226
|
+
if (!options.destroy) {
|
|
227
|
+
options.destroy = new Destroy();
|
|
228
|
+
}
|
|
229
|
+
for (const source of sources) {
|
|
230
|
+
options.destroy.load(source === null || source === void 0 ? void 0 : source.destroy);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
particleDestroyed(particle, override) {
|
|
234
|
+
if (override) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const destroyOptions = particle.options.destroy;
|
|
238
|
+
if (destroyOptions && destroyOptions.mode === "split") {
|
|
239
|
+
this.split(particle);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
update(particle) {
|
|
243
|
+
if (!this.isEnabled(particle)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const position = particle.getPosition(),
|
|
247
|
+
bounds = particle.destroyBounds;
|
|
248
|
+
if (!bounds) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (bounds.bottom !== undefined && position.y >= bounds.bottom || bounds.left !== undefined && position.x <= bounds.left || bounds.right !== undefined && position.x >= bounds.right || bounds.top !== undefined && position.y <= bounds.top) {
|
|
252
|
+
particle.destroy();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
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
|
+
}
|
|
317
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
318
|
+
|
|
319
|
+
async function loadDestroyUpdater(engine) {
|
|
320
|
+
await engine.addParticleUpdater("destroy", container => new DestroyUpdater(engine, container));
|
|
321
|
+
}
|
|
322
|
+
})();
|
|
323
|
+
|
|
324
|
+
/******/ return __webpack_exports__;
|
|
325
|
+
/******/ })()
|
|
326
|
+
;
|
|
327
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
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})()));
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
};
|
|
15
|
+
export declare class DestroyUpdater implements IParticleUpdater {
|
|
16
|
+
private readonly engine;
|
|
17
|
+
private readonly container;
|
|
18
|
+
constructor(engine: Engine, container: Container);
|
|
19
|
+
init(particle: DestroyParticle): void;
|
|
20
|
+
isEnabled(particle: Particle): boolean;
|
|
21
|
+
loadOptions(options: DestroyParticlesOptions, ...sources: (RecursivePartial<IDestroyParticlesOptions> | undefined)[]): void;
|
|
22
|
+
particleDestroyed(particle: DestroyParticle, override?: boolean): void;
|
|
23
|
+
update(particle: DestroyParticle): void;
|
|
24
|
+
private addSplitParticle;
|
|
25
|
+
private split;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import { DestroyBounds } from "./DestroyBounds";
|
|
3
|
+
import { DestroyMode } from "../../Enums/DestroyMode";
|
|
4
|
+
import type { IDestroy } from "../Interfaces/IDestroy";
|
|
5
|
+
import { Split } from "./Split";
|
|
6
|
+
export declare class Destroy implements IDestroy, IOptionLoader<IDestroy> {
|
|
7
|
+
bounds: DestroyBounds;
|
|
8
|
+
mode: DestroyMode | keyof typeof DestroyMode;
|
|
9
|
+
split: Split;
|
|
10
|
+
constructor();
|
|
11
|
+
load(data?: RecursivePartial<IDestroy>): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { IDestroyBounds } from "../Interfaces/IDestroyBounds";
|
|
3
|
+
export declare class DestroyBounds implements IDestroyBounds, IOptionLoader<IDestroyBounds> {
|
|
4
|
+
bottom?: RangeValue;
|
|
5
|
+
left?: RangeValue;
|
|
6
|
+
right?: RangeValue;
|
|
7
|
+
top?: RangeValue;
|
|
8
|
+
load(data?: RecursivePartial<IDestroyBounds>): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IOptionLoader, IParticlesOptions, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
|
|
2
|
+
import type { ISplit } from "../Interfaces/ISplit";
|
|
3
|
+
import { SplitFactor } from "./SplitFactor";
|
|
4
|
+
import { SplitRate } from "./SplitRate";
|
|
5
|
+
export declare class Split implements ISplit, IOptionLoader<ISplit> {
|
|
6
|
+
count: number;
|
|
7
|
+
factor: SplitFactor;
|
|
8
|
+
particles?: SingleOrMultiple<RecursivePartial<IParticlesOptions>>;
|
|
9
|
+
rate: SplitRate;
|
|
10
|
+
sizeOffset: boolean;
|
|
11
|
+
constructor();
|
|
12
|
+
load(data?: RecursivePartial<ISplit>): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DestroyMode } from "../../Enums/DestroyMode";
|
|
2
|
+
import type { IDestroyBounds } from "./IDestroyBounds";
|
|
3
|
+
import type { ISplit } from "./ISplit";
|
|
4
|
+
export interface IDestroy {
|
|
5
|
+
bounds: IDestroyBounds;
|
|
6
|
+
mode: DestroyMode | keyof typeof DestroyMode;
|
|
7
|
+
split: ISplit;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IParticlesOptions, IValueWithRandom, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
|
|
2
|
+
export interface ISplit {
|
|
3
|
+
count: number;
|
|
4
|
+
factor: IValueWithRandom;
|
|
5
|
+
particles?: SingleOrMultiple<RecursivePartial<IParticlesOptions>>;
|
|
6
|
+
rate: IValueWithRandom;
|
|
7
|
+
sizeOffset: boolean;
|
|
8
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
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", "./Options/Classes/Destroy"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DestroyUpdater = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const Destroy_1 = require("./Options/Classes/Destroy");
|
|
15
|
+
class DestroyUpdater {
|
|
16
|
+
constructor(engine, container) {
|
|
17
|
+
this.engine = engine;
|
|
18
|
+
this.container = container;
|
|
19
|
+
}
|
|
20
|
+
init(particle) {
|
|
21
|
+
const container = this.container, particlesOptions = particle.options, destroyOptions = particlesOptions.destroy;
|
|
22
|
+
if (!destroyOptions) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
particle.splitCount = 0;
|
|
26
|
+
const destroyBounds = destroyOptions.bounds;
|
|
27
|
+
if (!particle.destroyBounds) {
|
|
28
|
+
particle.destroyBounds = {};
|
|
29
|
+
}
|
|
30
|
+
if (destroyBounds.bottom) {
|
|
31
|
+
particle.destroyBounds.bottom = ((0, engine_1.getRangeValue)(destroyBounds.bottom) * container.canvas.size.height) / 100;
|
|
32
|
+
}
|
|
33
|
+
if (destroyBounds.left) {
|
|
34
|
+
particle.destroyBounds.left = ((0, engine_1.getRangeValue)(destroyBounds.left) * container.canvas.size.width) / 100;
|
|
35
|
+
}
|
|
36
|
+
if (destroyBounds.right) {
|
|
37
|
+
particle.destroyBounds.right = ((0, engine_1.getRangeValue)(destroyBounds.right) * container.canvas.size.width) / 100;
|
|
38
|
+
}
|
|
39
|
+
if (destroyBounds.top) {
|
|
40
|
+
particle.destroyBounds.top = ((0, engine_1.getRangeValue)(destroyBounds.top) * container.canvas.size.height) / 100;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
isEnabled(particle) {
|
|
44
|
+
return !particle.destroyed;
|
|
45
|
+
}
|
|
46
|
+
loadOptions(options, ...sources) {
|
|
47
|
+
if (!options.destroy) {
|
|
48
|
+
options.destroy = new Destroy_1.Destroy();
|
|
49
|
+
}
|
|
50
|
+
for (const source of sources) {
|
|
51
|
+
options.destroy.load(source === null || source === void 0 ? void 0 : source.destroy);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
particleDestroyed(particle, override) {
|
|
55
|
+
if (override) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const destroyOptions = particle.options.destroy;
|
|
59
|
+
if (destroyOptions && destroyOptions.mode === "split") {
|
|
60
|
+
this.split(particle);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
update(particle) {
|
|
64
|
+
if (!this.isEnabled(particle)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const position = particle.getPosition(), bounds = particle.destroyBounds;
|
|
68
|
+
if (!bounds) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if ((bounds.bottom !== undefined && position.y >= bounds.bottom) ||
|
|
72
|
+
(bounds.left !== undefined && position.x <= bounds.left) ||
|
|
73
|
+
(bounds.right !== undefined && position.x >= bounds.right) ||
|
|
74
|
+
(bounds.top !== undefined && position.y <= bounds.top)) {
|
|
75
|
+
particle.destroy();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
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
|
+
}
|
|
138
|
+
exports.DestroyUpdater = DestroyUpdater;
|
|
139
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
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", "./DestroyBounds", "./Split"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Destroy = void 0;
|
|
13
|
+
const DestroyBounds_1 = require("./DestroyBounds");
|
|
14
|
+
const Split_1 = require("./Split");
|
|
15
|
+
class Destroy {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.bounds = new DestroyBounds_1.DestroyBounds();
|
|
18
|
+
this.mode = "none";
|
|
19
|
+
this.split = new Split_1.Split();
|
|
20
|
+
}
|
|
21
|
+
load(data) {
|
|
22
|
+
if (!data) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (data.mode) {
|
|
26
|
+
this.mode = data.mode;
|
|
27
|
+
}
|
|
28
|
+
if (data.bounds) {
|
|
29
|
+
this.bounds.load(data.bounds);
|
|
30
|
+
}
|
|
31
|
+
this.split.load(data.split);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Destroy = Destroy;
|
|
35
|
+
});
|