@tsparticles/engine 4.0.0-alpha.24 → 4.0.0-alpha.26
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/622.min.js +1 -0
- package/README.md +2 -2
- package/browser/Core/Engine.js +1 -18
- package/browser/Core/Particle.js +2 -23
- package/browser/Core/Particles.js +8 -37
- package/browser/Core/Utils/Constants.js +1 -1
- package/browser/Core/Utils/Ranges.js +2 -2
- package/browser/Core/Utils/SpatialHashGrid.js +82 -0
- package/browser/Core/Utils/Vectors.js +12 -16
- package/browser/Options/Classes/Particles/Move/Move.js +0 -4
- package/browser/Utils/CanvasUtils.js +29 -32
- package/browser/Utils/MathUtils.js +8 -1
- package/browser/Utils/Utils.js +10 -14
- package/browser/exports.js +0 -2
- package/cjs/Core/Engine.js +1 -18
- package/cjs/Core/Particle.js +2 -23
- package/cjs/Core/Particles.js +8 -37
- package/cjs/Core/Utils/Constants.js +1 -1
- package/cjs/Core/Utils/Ranges.js +2 -2
- package/cjs/Core/Utils/SpatialHashGrid.js +82 -0
- package/cjs/Core/Utils/Vectors.js +12 -16
- package/cjs/Options/Classes/Particles/Move/Move.js +0 -4
- package/cjs/Utils/CanvasUtils.js +29 -32
- package/cjs/Utils/MathUtils.js +8 -1
- package/cjs/Utils/Utils.js +10 -14
- package/cjs/exports.js +0 -2
- package/dist_browser_Core_Container_js.js +8 -8
- package/esm/Core/Engine.js +1 -18
- package/esm/Core/Particle.js +2 -23
- package/esm/Core/Particles.js +8 -37
- package/esm/Core/Utils/Constants.js +1 -1
- package/esm/Core/Utils/Ranges.js +2 -2
- package/esm/Core/Utils/SpatialHashGrid.js +82 -0
- package/esm/Core/Utils/Vectors.js +12 -16
- package/esm/Options/Classes/Particles/Move/Move.js +0 -4
- package/esm/Utils/CanvasUtils.js +29 -32
- package/esm/Utils/MathUtils.js +8 -1
- package/esm/Utils/Utils.js +10 -14
- package/esm/exports.js +0 -2
- package/package.json +1 -1
- package/report.html +1 -1
- package/scripts/install.js +2 -2
- package/tsparticles.engine.js +11 -31
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/Engine.d.ts +1 -9
- package/types/Core/Particle.d.ts +0 -4
- package/types/Core/Particles.d.ts +2 -7
- package/types/Core/Utils/Constants.d.ts +1 -1
- package/types/Core/Utils/SpatialHashGrid.d.ts +18 -0
- package/types/Core/Utils/Vectors.d.ts +8 -10
- package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
- package/types/Types/EngineInitializers.d.ts +0 -6
- package/types/Utils/CanvasUtils.d.ts +6 -7
- package/types/Utils/MathUtils.d.ts +2 -0
- package/types/export-types.d.ts +1 -4
- package/types/exports.d.ts +0 -2
- package/umd/Core/Engine.js +1 -18
- package/umd/Core/Particle.js +3 -24
- package/umd/Core/Particles.js +8 -37
- package/umd/Core/Utils/Constants.js +2 -2
- package/umd/Core/Utils/Ranges.js +1 -1
- package/umd/Core/Utils/SpatialHashGrid.js +96 -0
- package/umd/Core/Utils/Vectors.js +12 -16
- package/umd/Options/Classes/Particles/Move/Move.js +1 -5
- package/umd/Utils/CanvasUtils.js +29 -32
- package/umd/Utils/MathUtils.js +10 -1
- package/umd/Utils/Utils.js +10 -14
- package/umd/exports.js +1 -3
- package/515.min.js +0 -1
- package/browser/Core/Interfaces/IMovePathGenerator.js +0 -1
- package/browser/Core/Interfaces/IParticleMover.js +0 -1
- package/browser/Core/Utils/Point.js +0 -8
- package/browser/Core/Utils/QuadTree.js +0 -85
- package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -36
- package/browser/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
- package/cjs/Core/Interfaces/IMovePathGenerator.js +0 -1
- package/cjs/Core/Interfaces/IParticleMover.js +0 -1
- package/cjs/Core/Utils/Point.js +0 -8
- package/cjs/Core/Utils/QuadTree.js +0 -85
- package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -36
- package/cjs/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
- package/esm/Core/Interfaces/IMovePathGenerator.js +0 -1
- package/esm/Core/Interfaces/IParticleMover.js +0 -1
- package/esm/Core/Utils/Point.js +0 -8
- package/esm/Core/Utils/QuadTree.js +0 -85
- package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -36
- package/esm/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -9
- package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
- package/types/Core/Utils/Point.d.ts +0 -7
- package/types/Core/Utils/QuadTree.d.ts +0 -17
- package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
- package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
- package/umd/Core/Interfaces/IMovePathGenerator.js +0 -12
- package/umd/Core/Interfaces/IParticleMover.js +0 -12
- package/umd/Core/Utils/Point.js +0 -22
- package/umd/Core/Utils/QuadTree.js +0 -99
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -50
- package/umd/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -12
package/umd/Core/Particle.js
CHANGED
|
@@ -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", "./Utils/Vectors.js", "../Utils/ColorUtils.js", "../Utils/MathUtils.js", "
|
|
7
|
+
define(["require", "exports", "./Utils/Vectors.js", "../Utils/ColorUtils.js", "../Utils/MathUtils.js", "../Utils/Utils.js", "./Utils/Constants.js", "../Enums/Types/EventType.js", "../Enums/Directions/MoveDirection.js", "../Enums/Modes/OutMode.js", "../Enums/Types/ParticleOutType.js", "../Utils/OptionsUtils.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
const Vectors_js_1 = require("./Utils/Vectors.js");
|
|
14
14
|
const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
|
|
15
15
|
const MathUtils_js_1 = require("../Utils/MathUtils.js");
|
|
16
|
-
const Constants_js_1 = require("./Utils/Constants.js");
|
|
17
16
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
17
|
+
const Constants_js_1 = require("./Utils/Constants.js");
|
|
18
18
|
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
19
19
|
const MoveDirection_js_1 = require("../Enums/Directions/MoveDirection.js");
|
|
20
20
|
const OutMode_js_1 = require("../Enums/Modes/OutMode.js");
|
|
@@ -66,13 +66,10 @@
|
|
|
66
66
|
lastPathTime;
|
|
67
67
|
misplaced;
|
|
68
68
|
moveCenter;
|
|
69
|
-
moveDecay;
|
|
70
69
|
offset;
|
|
71
70
|
opacity;
|
|
72
71
|
options;
|
|
73
72
|
outType;
|
|
74
|
-
pathDelay;
|
|
75
|
-
pathGenerator;
|
|
76
73
|
pathRotation;
|
|
77
74
|
position;
|
|
78
75
|
randomIndexData;
|
|
@@ -117,7 +114,7 @@
|
|
|
117
114
|
this.destroyed = true;
|
|
118
115
|
this.bubble.inRange = false;
|
|
119
116
|
this.slow.inRange = false;
|
|
120
|
-
const container = this.container,
|
|
117
|
+
const container = this.container, shapeDrawer = this.shape ? container.particles.shapeDrawers.get(this.shape) : undefined;
|
|
121
118
|
shapeDrawer?.particleDestroy?.(this);
|
|
122
119
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
123
120
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -125,7 +122,6 @@
|
|
|
125
122
|
for (const updater of container.particles.updaters) {
|
|
126
123
|
updater.particleDestroyed?.(this, override);
|
|
127
124
|
}
|
|
128
|
-
pathGenerator?.reset(this);
|
|
129
125
|
this._engine.dispatchEvent(EventType_js_1.EventType.particleDestroyed, {
|
|
130
126
|
container: this.container,
|
|
131
127
|
data: {
|
|
@@ -247,19 +243,6 @@
|
|
|
247
243
|
this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;
|
|
248
244
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
249
245
|
this.options = particlesOptions;
|
|
250
|
-
const pathOptions = this.options.move.path;
|
|
251
|
-
this.pathDelay = (0, MathUtils_js_1.getRangeValue)(pathOptions.delay.value) * Constants_js_1.millisecondsToSeconds;
|
|
252
|
-
if (pathOptions.generator) {
|
|
253
|
-
let pathGenerator = this.container.particles.pathGenerators.get(pathOptions.generator);
|
|
254
|
-
if (!pathGenerator) {
|
|
255
|
-
pathGenerator = this.container.particles.availablePathGenerators.get(pathOptions.generator);
|
|
256
|
-
if (pathGenerator) {
|
|
257
|
-
this.container.particles.pathGenerators.set(pathOptions.generator, pathGenerator);
|
|
258
|
-
pathGenerator.init();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
this.pathGenerator = pathGenerator;
|
|
262
|
-
}
|
|
263
246
|
container.retina.initParticle(this);
|
|
264
247
|
this.size = (0, Utils_js_1.initParticleNumericAnimationValue)(this.options.size, pxRatio);
|
|
265
248
|
this.bubble = {
|
|
@@ -272,7 +255,6 @@
|
|
|
272
255
|
this._initPosition(position);
|
|
273
256
|
this.initialVelocity = this._calculateVelocity();
|
|
274
257
|
this.velocity = this.initialVelocity.copy();
|
|
275
|
-
this.moveDecay = Constants_js_1.decayOffset - (0, MathUtils_js_1.getRangeValue)(this.options.move.decay);
|
|
276
258
|
const particles = container.particles;
|
|
277
259
|
particles.setLastZIndex(this.position.z);
|
|
278
260
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
@@ -298,9 +280,6 @@
|
|
|
298
280
|
for (const updater of particles.updaters) {
|
|
299
281
|
updater.init(this);
|
|
300
282
|
}
|
|
301
|
-
for (const mover of particles.movers) {
|
|
302
|
-
mover.init(this);
|
|
303
|
-
}
|
|
304
283
|
effectDrawer?.particleInit?.(container, this);
|
|
305
284
|
shapeDrawer?.particleInit?.(container, this);
|
|
306
285
|
for (const plugin of container.particleCreatedPlugins) {
|
package/umd/Core/Particles.js
CHANGED
|
@@ -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", "./Utils/Constants.js", "../Enums/Types/EventType.js", "../Enums/Modes/LimitMode.js", "./Particle.js", "./Utils/
|
|
7
|
+
define(["require", "exports", "./Utils/Constants.js", "../Enums/Types/EventType.js", "../Enums/Modes/LimitMode.js", "./Particle.js", "./Utils/SpatialHashGrid.js", "../Utils/LogUtils.js", "../Utils/OptionsUtils.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -14,22 +14,13 @@
|
|
|
14
14
|
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
15
15
|
const LimitMode_js_1 = require("../Enums/Modes/LimitMode.js");
|
|
16
16
|
const Particle_js_1 = require("./Particle.js");
|
|
17
|
-
const
|
|
18
|
-
const QuadTree_js_1 = require("./Utils/QuadTree.js");
|
|
19
|
-
const Ranges_js_1 = require("./Utils/Ranges.js");
|
|
17
|
+
const SpatialHashGrid_js_1 = require("./Utils/SpatialHashGrid.js");
|
|
20
18
|
const LogUtils_js_1 = require("../Utils/LogUtils.js");
|
|
21
19
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
22
|
-
const qTreeRectangle = (canvasSize) => {
|
|
23
|
-
const { height, width } = canvasSize;
|
|
24
|
-
return new Ranges_js_1.Rectangle(Constants_js_1.posOffset * width, Constants_js_1.posOffset * height, Constants_js_1.sizeFactor * width, Constants_js_1.sizeFactor * height);
|
|
25
|
-
};
|
|
26
20
|
class Particles {
|
|
27
|
-
availablePathGenerators;
|
|
28
21
|
checkParticlePositionPlugins;
|
|
29
22
|
effectDrawers;
|
|
30
|
-
|
|
31
|
-
pathGenerators;
|
|
32
|
-
quadTree;
|
|
23
|
+
grid;
|
|
33
24
|
shapeDrawers;
|
|
34
25
|
updaters;
|
|
35
26
|
_array;
|
|
@@ -61,12 +52,8 @@
|
|
|
61
52
|
this._needsSort = false;
|
|
62
53
|
this._minZIndex = 0;
|
|
63
54
|
this._maxZIndex = 0;
|
|
64
|
-
|
|
65
|
-
this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), Constants_js_1.qTreeCapacity);
|
|
55
|
+
this.grid = new SpatialHashGrid_js_1.SpatialHashGrid(Constants_js_1.spatialHashGridCellSize);
|
|
66
56
|
this.effectDrawers = new Map();
|
|
67
|
-
this.movers = [];
|
|
68
|
-
this.availablePathGenerators = new Map();
|
|
69
|
-
this.pathGenerators = new Map();
|
|
70
57
|
this.shapeDrawers = new Map();
|
|
71
58
|
this.updaters = [];
|
|
72
59
|
this.checkParticlePositionPlugins = [];
|
|
@@ -142,9 +129,6 @@
|
|
|
142
129
|
this._pool.length = 0;
|
|
143
130
|
this._zArray = [];
|
|
144
131
|
this.effectDrawers = new Map();
|
|
145
|
-
this.movers = [];
|
|
146
|
-
this.availablePathGenerators = new Map();
|
|
147
|
-
this.pathGenerators = new Map();
|
|
148
132
|
this.shapeDrawers = new Map();
|
|
149
133
|
this.updaters = [];
|
|
150
134
|
this.checkParticlePositionPlugins = [];
|
|
@@ -179,6 +163,7 @@
|
|
|
179
163
|
this._postUpdatePlugins = [];
|
|
180
164
|
this._particleResetPlugins = [];
|
|
181
165
|
this._postParticleUpdatePlugins = [];
|
|
166
|
+
this.grid = new SpatialHashGrid_js_1.SpatialHashGrid(Constants_js_1.spatialHashGridCellSize * container.retina.pixelRatio);
|
|
182
167
|
for (const plugin of container.plugins) {
|
|
183
168
|
if (plugin.redrawInit) {
|
|
184
169
|
await plugin.redrawInit();
|
|
@@ -235,14 +220,8 @@
|
|
|
235
220
|
async initPlugins() {
|
|
236
221
|
const container = this._container;
|
|
237
222
|
this.effectDrawers = await this._engine.getEffectDrawers(container, true);
|
|
238
|
-
this.movers = await this._engine.getMovers(container, true);
|
|
239
|
-
this.availablePathGenerators = await this._engine.getPathGenerators(container, true);
|
|
240
|
-
this.pathGenerators = new Map();
|
|
241
223
|
this.shapeDrawers = await this._engine.getShapeDrawers(container, true);
|
|
242
224
|
this.updaters = await this._engine.getUpdaters(container, true);
|
|
243
|
-
for (const pathGenerator of this.pathGenerators.values()) {
|
|
244
|
-
pathGenerator.init();
|
|
245
|
-
}
|
|
246
225
|
}
|
|
247
226
|
push(nb, position, overrideOptions, group) {
|
|
248
227
|
for (let i = 0; i < nb; i++) {
|
|
@@ -297,11 +276,8 @@
|
|
|
297
276
|
this._resizeFactor = factor;
|
|
298
277
|
}
|
|
299
278
|
update(delta) {
|
|
300
|
-
const
|
|
301
|
-
this.
|
|
302
|
-
for (const pathGenerator of this.pathGenerators.values()) {
|
|
303
|
-
pathGenerator.update();
|
|
304
|
-
}
|
|
279
|
+
const particlesToDelete = new Set();
|
|
280
|
+
this.grid.clear();
|
|
305
281
|
for (const plugin of this._updatePlugins) {
|
|
306
282
|
plugin.update?.(delta);
|
|
307
283
|
}
|
|
@@ -323,16 +299,11 @@
|
|
|
323
299
|
}
|
|
324
300
|
plugin.particleUpdate?.(particle, delta);
|
|
325
301
|
}
|
|
326
|
-
for (const mover of this.movers) {
|
|
327
|
-
if (mover.isEnabled(particle)) {
|
|
328
|
-
mover.move(particle, delta);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
302
|
if (particle.destroyed) {
|
|
332
303
|
particlesToDelete.add(particle);
|
|
333
304
|
continue;
|
|
334
305
|
}
|
|
335
|
-
this.
|
|
306
|
+
this.grid.insert(particle);
|
|
336
307
|
}
|
|
337
308
|
if (particlesToDelete.size) {
|
|
338
309
|
const checkDelete = (p) => !particlesToDelete.has(p);
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.defaultZoom = exports.defaultTime = exports.defaultLoops = exports.defaultVelocity = exports.defaultRgbMin = exports.phaseNumerator = exports.sNormalizedOffset = exports.sextuple = exports.triple = exports.lMin = exports.lFactor = exports.minStrokeWidth = exports.identity = exports.defaultAngle = exports.manualDefaultPosition = exports.touchDelay = exports.deleteCount = exports.defaultDensityFactor = exports.lengthOffset = exports.minIndex = exports.minCount = exports.countOffset = exports.minLimit = exports.sizeFactor = exports.posOffset = exports.defaultRadius = exports.minZ = exports.minRetries = exports.tryCountIncrement = exports.decayOffset = exports.none = exports.one = exports.loadMinIndex = exports.loadRandomFactor = exports.canvasFirstIndex = exports.minFpsLimit = exports.defaultFpsLimit = exports.removeMinIndex = exports.removeDeleteCount = exports.minCoordinate = exports.touchEndLengthOffset = exports.clickRadius = exports.defaultOpacity = exports.zIndexFactorOffset = exports.minimumLength = exports.minimumSize = exports.defaultTransformValue = exports.minVelocity = exports.threeQuarter = exports.quarter = exports.empty = exports.hPhase = exports.sMin = exports.hMin = exports.lMax = exports.sMax = exports.hMax = exports.rgbMax = exports.inverseFactorNumerator = exports.subdivideCount = exports.defaultReduceFactor = exports.defaultRatio = exports.defaultRemoveQuantity = exports.qTreeCapacity = exports.squareExp = exports.defaultRetryCount = exports.canvasTag = exports.generatedFalse = exports.generatedTrue = exports.defaultAlpha = exports.defaultFps = exports.doublePI = exports.double = exports.midColorValue = exports.randomColorValue = exports.defaultTransform = exports.originPoint = exports.millisecondsToSeconds = exports.half = exports.percentDenominator = exports.visibilityChangeEvent = exports.resizeEvent = exports.generatedAttribute = void 0;
|
|
12
|
+
exports.defaultZoom = exports.defaultTime = exports.defaultLoops = exports.defaultVelocity = exports.defaultRgbMin = exports.phaseNumerator = exports.sNormalizedOffset = exports.sextuple = exports.triple = exports.lMin = exports.lFactor = exports.minStrokeWidth = exports.identity = exports.defaultAngle = exports.manualDefaultPosition = exports.touchDelay = exports.deleteCount = exports.defaultDensityFactor = exports.lengthOffset = exports.minIndex = exports.minCount = exports.countOffset = exports.minLimit = exports.sizeFactor = exports.posOffset = exports.defaultRadius = exports.minZ = exports.minRetries = exports.tryCountIncrement = exports.decayOffset = exports.none = exports.one = exports.loadMinIndex = exports.loadRandomFactor = exports.canvasFirstIndex = exports.minFpsLimit = exports.defaultFpsLimit = exports.removeMinIndex = exports.removeDeleteCount = exports.minCoordinate = exports.touchEndLengthOffset = exports.clickRadius = exports.defaultOpacity = exports.zIndexFactorOffset = exports.minimumLength = exports.minimumSize = exports.defaultTransformValue = exports.minVelocity = exports.threeQuarter = exports.quarter = exports.empty = exports.hPhase = exports.sMin = exports.hMin = exports.lMax = exports.sMax = exports.hMax = exports.rgbMax = exports.inverseFactorNumerator = exports.subdivideCount = exports.defaultReduceFactor = exports.defaultRatio = exports.defaultRemoveQuantity = exports.spatialHashGridCellSize = exports.qTreeCapacity = exports.squareExp = exports.defaultRetryCount = exports.canvasTag = exports.generatedFalse = exports.generatedTrue = exports.defaultAlpha = exports.defaultFps = exports.doublePI = exports.double = exports.midColorValue = exports.randomColorValue = exports.defaultTransform = exports.originPoint = exports.millisecondsToSeconds = exports.half = exports.percentDenominator = exports.visibilityChangeEvent = exports.resizeEvent = exports.generatedAttribute = void 0;
|
|
13
13
|
exports.generatedAttribute = "generated", exports.resizeEvent = "resize", exports.visibilityChangeEvent = "visibilitychange", exports.percentDenominator = 100, exports.half = 0.5, exports.millisecondsToSeconds = 1000, exports.originPoint = {
|
|
14
14
|
x: 0,
|
|
15
15
|
y: 0,
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
b: 0,
|
|
20
20
|
c: 0,
|
|
21
21
|
d: 1,
|
|
22
|
-
}, exports.randomColorValue = "random", exports.midColorValue = "mid", exports.double = 2, exports.doublePI = Math.PI * exports.double, exports.defaultFps = 60, exports.defaultAlpha = 1, exports.generatedTrue = "true", exports.generatedFalse = "false", exports.canvasTag = "canvas", exports.defaultRetryCount = 0, exports.squareExp = 2, exports.qTreeCapacity = 4, exports.defaultRemoveQuantity = 1, exports.defaultRatio = 1, exports.defaultReduceFactor = 1, exports.subdivideCount = 4, exports.inverseFactorNumerator = 1, exports.rgbMax = 255, exports.hMax = 360, exports.sMax = 100, exports.lMax = 100, exports.hMin = 0, exports.sMin = 0, exports.hPhase = 60, exports.empty = 0, exports.quarter = 0.25, exports.threeQuarter = exports.half + exports.quarter, exports.minVelocity = 0, exports.defaultTransformValue = 1, exports.minimumSize = 0, exports.minimumLength = 0, exports.zIndexFactorOffset = 1, exports.defaultOpacity = 1, exports.clickRadius = 1, exports.touchEndLengthOffset = 1, exports.minCoordinate = 0, exports.removeDeleteCount = 1, exports.removeMinIndex = 0, exports.defaultFpsLimit = 120, exports.minFpsLimit = 0, exports.canvasFirstIndex = 0, exports.loadRandomFactor = 10000, exports.loadMinIndex = 0, exports.one = 1, exports.none = 0, exports.decayOffset = 1, exports.tryCountIncrement = 1, exports.minRetries = 0, exports.minZ = 0, exports.defaultRadius = 0, exports.posOffset = -exports.quarter, exports.sizeFactor = 1.5, exports.minLimit = 0, exports.countOffset = 1, exports.minCount = 0, exports.minIndex = 0, exports.lengthOffset = 1, exports.defaultDensityFactor = 1, exports.deleteCount = 1, exports.touchDelay = 500, exports.manualDefaultPosition = 50, exports.defaultAngle = 0, exports.identity = 1, exports.minStrokeWidth = 0, exports.lFactor = 1, exports.lMin = 0, exports.triple = 3, exports.sextuple = 6, exports.sNormalizedOffset = 1, exports.phaseNumerator = 1, exports.defaultRgbMin = 0, exports.defaultVelocity = 0, exports.defaultLoops = 0, exports.defaultTime = 0, exports.defaultZoom = 1;
|
|
22
|
+
}, exports.randomColorValue = "random", exports.midColorValue = "mid", exports.double = 2, exports.doublePI = Math.PI * exports.double, exports.defaultFps = 60, exports.defaultAlpha = 1, exports.generatedTrue = "true", exports.generatedFalse = "false", exports.canvasTag = "canvas", exports.defaultRetryCount = 0, exports.squareExp = 2, exports.qTreeCapacity = 4, exports.spatialHashGridCellSize = 100, exports.defaultRemoveQuantity = 1, exports.defaultRatio = 1, exports.defaultReduceFactor = 1, exports.subdivideCount = 4, exports.inverseFactorNumerator = 1, exports.rgbMax = 255, exports.hMax = 360, exports.sMax = 100, exports.lMax = 100, exports.hMin = 0, exports.sMin = 0, exports.hPhase = 60, exports.empty = 0, exports.quarter = 0.25, exports.threeQuarter = exports.half + exports.quarter, exports.minVelocity = 0, exports.defaultTransformValue = 1, exports.minimumSize = 0, exports.minimumLength = 0, exports.zIndexFactorOffset = 1, exports.defaultOpacity = 1, exports.clickRadius = 1, exports.touchEndLengthOffset = 1, exports.minCoordinate = 0, exports.removeDeleteCount = 1, exports.removeMinIndex = 0, exports.defaultFpsLimit = 120, exports.minFpsLimit = 0, exports.canvasFirstIndex = 0, exports.loadRandomFactor = 10000, exports.loadMinIndex = 0, exports.one = 1, exports.none = 0, exports.decayOffset = 1, exports.tryCountIncrement = 1, exports.minRetries = 0, exports.minZ = 0, exports.defaultRadius = 0, exports.posOffset = -exports.quarter, exports.sizeFactor = 1.5, exports.minLimit = 0, exports.countOffset = 1, exports.minCount = 0, exports.minIndex = 0, exports.lengthOffset = 1, exports.defaultDensityFactor = 1, exports.deleteCount = 1, exports.touchDelay = 500, exports.manualDefaultPosition = 50, exports.defaultAngle = 0, exports.identity = 1, exports.minStrokeWidth = 0, exports.lFactor = 1, exports.lMin = 0, exports.triple = 3, exports.sextuple = 6, exports.sNormalizedOffset = 1, exports.phaseNumerator = 1, exports.defaultRgbMin = 0, exports.defaultVelocity = 0, exports.defaultLoops = 0, exports.defaultTime = 0, exports.defaultZoom = 1;
|
|
23
23
|
});
|
package/umd/Core/Utils/Ranges.js
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
this.radius = radius;
|
|
33
33
|
}
|
|
34
34
|
contains(point) {
|
|
35
|
-
return (0, MathUtils_js_1.
|
|
35
|
+
return (0, MathUtils_js_1.checkDistance)(point, this.position, this.radius);
|
|
36
36
|
}
|
|
37
37
|
intersects(range) {
|
|
38
38
|
const pos1 = this.position, pos2 = range.position, distPos = { x: Math.abs(pos2.x - pos1.x), y: Math.abs(pos2.y - pos1.y) }, r = this.radius;
|
|
@@ -0,0 +1,96 @@
|
|
|
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", "./Ranges.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SpatialHashGrid = void 0;
|
|
13
|
+
const Ranges_js_1 = require("./Ranges.js");
|
|
14
|
+
class SpatialHashGrid {
|
|
15
|
+
_cellSize;
|
|
16
|
+
_cells = new Map();
|
|
17
|
+
_pendingCellSize;
|
|
18
|
+
constructor(cellSize) {
|
|
19
|
+
this._cellSize = cellSize;
|
|
20
|
+
}
|
|
21
|
+
clear() {
|
|
22
|
+
this._cells.clear();
|
|
23
|
+
const pendingCellSize = this._pendingCellSize;
|
|
24
|
+
if (pendingCellSize) {
|
|
25
|
+
this._cellSize = pendingCellSize;
|
|
26
|
+
}
|
|
27
|
+
this._pendingCellSize = undefined;
|
|
28
|
+
}
|
|
29
|
+
insert(particle) {
|
|
30
|
+
const { x, y } = particle.getPosition(), key = this._cellKeyFromCoords(x, y);
|
|
31
|
+
if (!this._cells.has(key)) {
|
|
32
|
+
this._cells.set(key, []);
|
|
33
|
+
}
|
|
34
|
+
this._cells.get(key)?.push(particle);
|
|
35
|
+
}
|
|
36
|
+
query(range, check, out = []) {
|
|
37
|
+
const bounds = this._getRangeBounds(range);
|
|
38
|
+
if (!bounds) {
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
const minCellX = Math.floor(bounds.minX / this._cellSize), maxCellX = Math.floor(bounds.maxX / this._cellSize), minCellY = Math.floor(bounds.minY / this._cellSize), maxCellY = Math.floor(bounds.maxY / this._cellSize);
|
|
42
|
+
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
43
|
+
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
44
|
+
const key = `${cx}_${cy}`, cellParticles = this._cells.get(key);
|
|
45
|
+
if (!cellParticles) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
for (const p of cellParticles) {
|
|
49
|
+
if (check && !check(p)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (range.contains(p.getPosition())) {
|
|
53
|
+
out.push(p);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
queryCircle(position, radius, check, out = []) {
|
|
61
|
+
return this.query(new Ranges_js_1.Circle(position.x, position.y, radius), check, out);
|
|
62
|
+
}
|
|
63
|
+
queryRectangle(position, size, check, out = []) {
|
|
64
|
+
return this.query(new Ranges_js_1.Rectangle(position.x, position.y, size.width, size.height), check, out);
|
|
65
|
+
}
|
|
66
|
+
setCellSize(cellSize) {
|
|
67
|
+
this._pendingCellSize = cellSize;
|
|
68
|
+
}
|
|
69
|
+
_cellKeyFromCoords(x, y) {
|
|
70
|
+
const cellX = Math.floor(x / this._cellSize), cellY = Math.floor(y / this._cellSize);
|
|
71
|
+
return `${cellX}_${cellY}`;
|
|
72
|
+
}
|
|
73
|
+
_getRangeBounds(range) {
|
|
74
|
+
if (range instanceof Ranges_js_1.Circle) {
|
|
75
|
+
const r = range.radius, { x, y } = range.position;
|
|
76
|
+
return {
|
|
77
|
+
minX: x - r,
|
|
78
|
+
maxX: x + r,
|
|
79
|
+
minY: y - r,
|
|
80
|
+
maxY: y + r,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (range instanceof Ranges_js_1.Rectangle) {
|
|
84
|
+
const { x, y } = range.position, { width, height } = range.size;
|
|
85
|
+
return {
|
|
86
|
+
minX: x,
|
|
87
|
+
maxX: x + width,
|
|
88
|
+
minY: y,
|
|
89
|
+
maxY: y + height,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.SpatialHashGrid = SpatialHashGrid;
|
|
96
|
+
});
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Vector = exports.Vector3d = void 0;
|
|
13
13
|
const Constants_js_1 = require("./Constants.js");
|
|
14
|
+
function getZ(source) {
|
|
15
|
+
return "z" in source ? source.z : Constants_js_1.originPoint.z;
|
|
16
|
+
}
|
|
14
17
|
class Vector3d {
|
|
15
18
|
x;
|
|
16
19
|
y;
|
|
@@ -36,31 +39,25 @@
|
|
|
36
39
|
this._updateFromAngle(this.angle, length);
|
|
37
40
|
}
|
|
38
41
|
static clone(source) {
|
|
39
|
-
return Vector3d.create(source.x, source.y, source
|
|
42
|
+
return Vector3d.create(source.x, source.y, getZ(source));
|
|
40
43
|
}
|
|
41
44
|
static create(x, y, z) {
|
|
42
45
|
if (typeof x === "number") {
|
|
43
46
|
return new Vector3d(x, y ?? Constants_js_1.originPoint.y, z ?? Constants_js_1.originPoint.z);
|
|
44
47
|
}
|
|
45
|
-
return new Vector3d(x.x, x.y,
|
|
48
|
+
return new Vector3d(x.x, x.y, getZ(x));
|
|
46
49
|
}
|
|
47
50
|
add(v) {
|
|
48
|
-
return Vector3d.create(this.x + v.x, this.y + v.y, this.z + v
|
|
51
|
+
return Vector3d.create(this.x + v.x, this.y + v.y, this.z + getZ(v));
|
|
49
52
|
}
|
|
50
53
|
addTo(v) {
|
|
51
54
|
this.x += v.x;
|
|
52
55
|
this.y += v.y;
|
|
53
|
-
this.z += v
|
|
56
|
+
this.z += getZ(v);
|
|
54
57
|
}
|
|
55
58
|
copy() {
|
|
56
59
|
return Vector3d.clone(this);
|
|
57
60
|
}
|
|
58
|
-
distanceTo(v) {
|
|
59
|
-
return this.sub(v).length;
|
|
60
|
-
}
|
|
61
|
-
distanceToSq(v) {
|
|
62
|
-
return this.sub(v).getLengthSq();
|
|
63
|
-
}
|
|
64
61
|
div(n) {
|
|
65
62
|
return Vector3d.create(this.x / n, this.y / n, this.z / n);
|
|
66
63
|
}
|
|
@@ -92,21 +89,20 @@
|
|
|
92
89
|
setTo(c) {
|
|
93
90
|
this.x = c.x;
|
|
94
91
|
this.y = c.y;
|
|
95
|
-
|
|
96
|
-
this.z = v3d.z ? v3d.z : Constants_js_1.originPoint.z;
|
|
92
|
+
this.z = getZ(c);
|
|
97
93
|
}
|
|
98
94
|
sub(v) {
|
|
99
|
-
return Vector3d.create(this.x - v.x, this.y - v.y, this.z - v
|
|
95
|
+
return Vector3d.create(this.x - v.x, this.y - v.y, this.z - getZ(v));
|
|
100
96
|
}
|
|
101
97
|
subFrom(v) {
|
|
102
98
|
this.x -= v.x;
|
|
103
99
|
this.y -= v.y;
|
|
104
|
-
this.z -= v
|
|
100
|
+
this.z -= getZ(v);
|
|
105
101
|
}
|
|
106
|
-
_updateFromAngle
|
|
102
|
+
_updateFromAngle(angle, length) {
|
|
107
103
|
this.x = Math.cos(angle) * length;
|
|
108
104
|
this.y = Math.sin(angle) * length;
|
|
109
|
-
}
|
|
105
|
+
}
|
|
110
106
|
}
|
|
111
107
|
exports.Vector3d = Vector3d;
|
|
112
108
|
class Vector extends Vector3d {
|
|
@@ -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", "../../../../Enums/Directions/MoveDirection.js", "../../../../Utils/TypeUtils.js", "./MoveAngle.js", "./
|
|
7
|
+
define(["require", "exports", "../../../../Enums/Directions/MoveDirection.js", "../../../../Utils/TypeUtils.js", "./MoveAngle.js", "./MoveCenter.js", "./MoveGravity.js", "./Path/MovePath.js", "./OutModes.js", "./Spin.js", "../../../../Utils/MathUtils.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
const MoveDirection_js_1 = require("../../../../Enums/Directions/MoveDirection.js");
|
|
14
14
|
const TypeUtils_js_1 = require("../../../../Utils/TypeUtils.js");
|
|
15
15
|
const MoveAngle_js_1 = require("./MoveAngle.js");
|
|
16
|
-
const MoveAttract_js_1 = require("./MoveAttract.js");
|
|
17
16
|
const MoveCenter_js_1 = require("./MoveCenter.js");
|
|
18
17
|
const MoveGravity_js_1 = require("./MoveGravity.js");
|
|
19
18
|
const MovePath_js_1 = require("./Path/MovePath.js");
|
|
@@ -22,7 +21,6 @@
|
|
|
22
21
|
const MathUtils_js_1 = require("../../../../Utils/MathUtils.js");
|
|
23
22
|
class Move {
|
|
24
23
|
angle;
|
|
25
|
-
attract;
|
|
26
24
|
center;
|
|
27
25
|
decay;
|
|
28
26
|
direction;
|
|
@@ -41,7 +39,6 @@
|
|
|
41
39
|
warp;
|
|
42
40
|
constructor() {
|
|
43
41
|
this.angle = new MoveAngle_js_1.MoveAngle();
|
|
44
|
-
this.attract = new MoveAttract_js_1.MoveAttract();
|
|
45
42
|
this.center = new MoveCenter_js_1.MoveCenter();
|
|
46
43
|
this.decay = 0;
|
|
47
44
|
this.distance = {};
|
|
@@ -64,7 +61,6 @@
|
|
|
64
61
|
return;
|
|
65
62
|
}
|
|
66
63
|
this.angle.load((0, TypeUtils_js_1.isNumber)(data.angle) ? { value: data.angle } : data.angle);
|
|
67
|
-
this.attract.load(data.attract);
|
|
68
64
|
this.center.load(data.center);
|
|
69
65
|
if (data.decay !== undefined) {
|
|
70
66
|
this.decay = (0, MathUtils_js_1.setRangeValue)(data.decay);
|
package/umd/Utils/CanvasUtils.js
CHANGED
|
@@ -28,15 +28,16 @@
|
|
|
28
28
|
if (!image) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
+
const prevAlpha = context.globalAlpha;
|
|
31
32
|
context.globalAlpha = opacity;
|
|
32
33
|
context.drawImage(image, Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
|
|
33
|
-
context.globalAlpha =
|
|
34
|
+
context.globalAlpha = prevAlpha;
|
|
34
35
|
}
|
|
35
36
|
function clear(context, dimension) {
|
|
36
37
|
context.clearRect(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
|
|
37
38
|
}
|
|
38
39
|
function drawParticle(data) {
|
|
39
|
-
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = Constants_js_1.defaultZoom, drawPosition = {
|
|
40
|
+
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container.particles, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = Constants_js_1.defaultZoom, drawPosition = {
|
|
40
41
|
x: pos.x,
|
|
41
42
|
y: pos.y,
|
|
42
43
|
};
|
|
@@ -67,42 +68,40 @@
|
|
|
67
68
|
for (const plugin of container.plugins) {
|
|
68
69
|
plugin.drawParticleTransform?.(drawData);
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const effect = particle.effect ? effectDrawers.get(particle.effect) : undefined, shape = particle.shape ? shapeDrawers.get(particle.shape) : undefined;
|
|
72
|
+
drawBeforeEffect(effect, drawData);
|
|
73
|
+
drawShapeBeforeDraw(shape, drawData);
|
|
74
|
+
drawShape(shape, drawData);
|
|
75
|
+
drawShapeAfterDraw(shape, drawData);
|
|
76
|
+
drawAfterEffect(effect, drawData);
|
|
75
77
|
context.resetTransform();
|
|
76
78
|
}
|
|
77
|
-
function drawAfterEffect(
|
|
79
|
+
function drawAfterEffect(drawer, data) {
|
|
80
|
+
if (!drawer?.drawAfter) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
78
83
|
const { particle } = data;
|
|
79
84
|
if (!particle.effect) {
|
|
80
85
|
return;
|
|
81
86
|
}
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
drawer.drawAfter(data);
|
|
88
|
+
}
|
|
89
|
+
function drawBeforeEffect(drawer, data) {
|
|
90
|
+
if (!drawer?.drawBefore) {
|
|
84
91
|
return;
|
|
85
92
|
}
|
|
86
|
-
drawFunc(data);
|
|
87
|
-
}
|
|
88
|
-
function drawBeforeEffect(container, data) {
|
|
89
93
|
const { particle } = data;
|
|
90
94
|
if (!particle.effect) {
|
|
91
95
|
return;
|
|
92
96
|
}
|
|
93
|
-
const drawer = container.particles.effectDrawers.get(particle.effect);
|
|
94
|
-
if (!drawer?.drawBefore) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
97
|
drawer.drawBefore(data);
|
|
98
98
|
}
|
|
99
|
-
function drawShape(
|
|
100
|
-
|
|
101
|
-
if (!particle.shape) {
|
|
99
|
+
function drawShape(drawer, data) {
|
|
100
|
+
if (!drawer) {
|
|
102
101
|
return;
|
|
103
102
|
}
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
103
|
+
const { context, particle, stroke } = data;
|
|
104
|
+
if (!particle.shape) {
|
|
106
105
|
return;
|
|
107
106
|
}
|
|
108
107
|
context.beginPath();
|
|
@@ -117,26 +116,24 @@
|
|
|
117
116
|
context.fill();
|
|
118
117
|
}
|
|
119
118
|
}
|
|
120
|
-
function drawShapeAfterDraw(
|
|
121
|
-
const { particle } = data;
|
|
122
|
-
if (!particle.shape) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const drawer = container.particles.shapeDrawers.get(particle.shape);
|
|
119
|
+
function drawShapeAfterDraw(drawer, data) {
|
|
126
120
|
if (!drawer?.afterDraw) {
|
|
127
121
|
return;
|
|
128
122
|
}
|
|
129
|
-
drawer.afterDraw(data);
|
|
130
|
-
}
|
|
131
|
-
function drawShapeBeforeDraw(container, data) {
|
|
132
123
|
const { particle } = data;
|
|
133
124
|
if (!particle.shape) {
|
|
134
125
|
return;
|
|
135
126
|
}
|
|
136
|
-
|
|
127
|
+
drawer.afterDraw(data);
|
|
128
|
+
}
|
|
129
|
+
function drawShapeBeforeDraw(drawer, data) {
|
|
137
130
|
if (!drawer?.beforeDraw) {
|
|
138
131
|
return;
|
|
139
132
|
}
|
|
133
|
+
const { particle } = data;
|
|
134
|
+
if (!particle.shape) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
140
137
|
drawer.beforeDraw(data);
|
|
141
138
|
}
|
|
142
139
|
function drawParticlePlugin(context, plugin, particle, delta) {
|
package/umd/Utils/MathUtils.js
CHANGED
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
exports.getRangeMax = getRangeMax;
|
|
24
24
|
exports.setRangeValue = setRangeValue;
|
|
25
25
|
exports.getDistances = getDistances;
|
|
26
|
+
exports.getDistanceSq = getDistanceSq;
|
|
26
27
|
exports.getDistance = getDistance;
|
|
28
|
+
exports.checkDistance = checkDistance;
|
|
27
29
|
exports.degToRad = degToRad;
|
|
28
30
|
exports.getParticleDirectionAngle = getParticleDirectionAngle;
|
|
29
31
|
exports.getParticleBaseVelocity = getParticleBaseVelocity;
|
|
@@ -105,8 +107,15 @@
|
|
|
105
107
|
const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
|
|
106
108
|
return { dx: dx, dy: dy, distance: Math.hypot(dx, dy) };
|
|
107
109
|
}
|
|
110
|
+
function getDistanceSq(pointA, pointB) {
|
|
111
|
+
const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
|
|
112
|
+
return dx * dx + dy * dy;
|
|
113
|
+
}
|
|
108
114
|
function getDistance(pointA, pointB) {
|
|
109
|
-
return
|
|
115
|
+
return Math.sqrt(getDistanceSq(pointA, pointB));
|
|
116
|
+
}
|
|
117
|
+
function checkDistance(pointA, pointB, distance) {
|
|
118
|
+
return getDistanceSq(pointA, pointB) <= distance * distance;
|
|
110
119
|
}
|
|
111
120
|
function degToRad(degrees) {
|
|
112
121
|
return degrees * degToRadFactor;
|
package/umd/Utils/Utils.js
CHANGED
|
@@ -120,33 +120,29 @@
|
|
|
120
120
|
}
|
|
121
121
|
function deepExtend(destination, ...sources) {
|
|
122
122
|
for (const source of sources) {
|
|
123
|
-
if (
|
|
123
|
+
if ((0, TypeUtils_js_1.isNull)(source)) {
|
|
124
124
|
continue;
|
|
125
125
|
}
|
|
126
126
|
if (!(0, TypeUtils_js_1.isObject)(source)) {
|
|
127
127
|
destination = source;
|
|
128
128
|
continue;
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
if (sourceIsArray) {
|
|
130
|
+
if (Array.isArray(source)) {
|
|
132
131
|
if (!Array.isArray(destination)) {
|
|
133
132
|
destination = [];
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
|
-
else {
|
|
137
|
-
|
|
138
|
-
destination = {};
|
|
139
|
-
}
|
|
135
|
+
else if (!(0, TypeUtils_js_1.isObject)(destination) || Array.isArray(destination)) {
|
|
136
|
+
destination = {};
|
|
140
137
|
}
|
|
141
|
-
for (const key
|
|
142
|
-
if (key === "__proto__") {
|
|
138
|
+
for (const key of Object.keys(source)) {
|
|
139
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
143
140
|
continue;
|
|
144
141
|
}
|
|
145
|
-
const sourceDict = source, value = sourceDict[key]
|
|
146
|
-
destDict[key] =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
: deepExtend(destDict[key], value);
|
|
142
|
+
const sourceDict = source, destDict = destination, value = sourceDict[key];
|
|
143
|
+
destDict[key] = Array.isArray(value)
|
|
144
|
+
? value.map(v => deepExtend(undefined, v))
|
|
145
|
+
: deepExtend(destDict[key], value);
|
|
150
146
|
}
|
|
151
147
|
}
|
|
152
148
|
return destination;
|