@tsparticles/engine 4.0.0-alpha.4 → 4.0.0-alpha.8
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/794.min.js +1 -1
- package/794.min.js.LICENSE.txt +1 -1
- package/browser/Core/Canvas.js +25 -19
- package/browser/Core/Engine.js +32 -39
- package/browser/Core/Particle.js +22 -6
- package/browser/Core/Utils/Constants.js +1 -1
- package/browser/Enums/Types/EasingType.js +18 -3
- package/browser/Utils/CanvasUtils.js +0 -12
- package/browser/Utils/Utils.js +8 -4
- package/cjs/Core/Canvas.js +25 -19
- package/cjs/Core/Engine.js +32 -39
- package/cjs/Core/Particle.js +22 -6
- package/cjs/Core/Utils/Constants.js +1 -1
- package/cjs/Enums/Types/EasingType.js +18 -3
- package/cjs/Utils/CanvasUtils.js +0 -12
- package/cjs/Utils/Utils.js +8 -4
- package/dist_browser_Core_Container_js.js +3 -3
- package/esm/Core/Canvas.js +25 -19
- package/esm/Core/Engine.js +32 -39
- package/esm/Core/Particle.js +22 -6
- package/esm/Core/Utils/Constants.js +1 -1
- package/esm/Enums/Types/EasingType.js +18 -3
- package/esm/Utils/CanvasUtils.js +0 -12
- package/esm/Utils/Utils.js +8 -4
- package/package.json +1 -1
- package/report.html +3 -3
- package/tsparticles.engine.js +8 -8
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +0 -2
- package/types/Core/Engine.d.ts +5 -1
- package/types/Core/Interfaces/IContainerPlugin.d.ts +4 -0
- package/types/Core/Particle.d.ts +1 -0
- package/types/Core/Utils/Constants.d.ts +1 -1
- package/types/Enums/Types/EasingType.d.ts +20 -5
- package/types/Utils/CanvasUtils.d.ts +0 -2
- package/umd/Core/Canvas.js +24 -18
- package/umd/Core/Engine.js +32 -39
- package/umd/Core/Particle.js +21 -5
- package/umd/Core/Utils/Constants.js +2 -2
- package/umd/Enums/Types/EasingType.js +18 -3
- package/umd/Utils/CanvasUtils.js +0 -14
- package/umd/Utils/Utils.js +8 -4
package/esm/Core/Engine.js
CHANGED
|
@@ -57,7 +57,10 @@ export class Engine {
|
|
|
57
57
|
this._domArray = [];
|
|
58
58
|
this._eventDispatcher = new EventDispatcher();
|
|
59
59
|
this._initialized = false;
|
|
60
|
+
this._isRunningLoaders = false;
|
|
60
61
|
this._loadPromises = new Set();
|
|
62
|
+
this._allLoadersSet = new Set();
|
|
63
|
+
this._executedSet = new Set();
|
|
61
64
|
this.plugins = [];
|
|
62
65
|
this.colorManagers = new Map();
|
|
63
66
|
this.easingFunctions = new Map();
|
|
@@ -83,7 +86,7 @@ export class Engine {
|
|
|
83
86
|
return this._domArray;
|
|
84
87
|
}
|
|
85
88
|
get version() {
|
|
86
|
-
return "4.0.0-alpha.
|
|
89
|
+
return "4.0.0-alpha.8";
|
|
87
90
|
}
|
|
88
91
|
addColorManager(manager) {
|
|
89
92
|
this.colorManagers.set(manager.key, manager);
|
|
@@ -184,40 +187,21 @@ export class Engine {
|
|
|
184
187
|
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
185
188
|
}
|
|
186
189
|
async init() {
|
|
187
|
-
if (this._initialized)
|
|
190
|
+
if (this._initialized || this._isRunningLoaders)
|
|
188
191
|
return;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
if (executed.has(loader)) {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
executed.add(loader);
|
|
200
|
-
const inner = [], origRegister = this.register.bind(this);
|
|
201
|
-
this.register = (...loaders) => {
|
|
202
|
-
inner.push(...loaders);
|
|
203
|
-
for (const loader of loaders) {
|
|
204
|
-
allLoaders.add(loader);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
try {
|
|
208
|
-
await loader(this);
|
|
192
|
+
this._isRunningLoaders = true;
|
|
193
|
+
this._executedSet = new Set();
|
|
194
|
+
this._allLoadersSet = new Set(this._loadPromises);
|
|
195
|
+
try {
|
|
196
|
+
for (const loader of this._allLoadersSet) {
|
|
197
|
+
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
209
198
|
}
|
|
210
|
-
finally {
|
|
211
|
-
this.register = origRegister;
|
|
212
|
-
}
|
|
213
|
-
stack.unshift(...inner);
|
|
214
|
-
this._loadPromises.delete(loader);
|
|
215
199
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.
|
|
200
|
+
finally {
|
|
201
|
+
this._loadPromises.clear();
|
|
202
|
+
this._isRunningLoaders = false;
|
|
203
|
+
this._initialized = true;
|
|
219
204
|
}
|
|
220
|
-
this._initialized = true;
|
|
221
205
|
}
|
|
222
206
|
item(index) {
|
|
223
207
|
const { items } = this, item = items[index];
|
|
@@ -229,10 +213,7 @@ export class Engine {
|
|
|
229
213
|
}
|
|
230
214
|
async load(params) {
|
|
231
215
|
await this.init();
|
|
232
|
-
this.
|
|
233
|
-
const { Container } = await import("./Container.js"), id = params.id ??
|
|
234
|
-
params.element?.id ??
|
|
235
|
-
`tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container(this, id, currentOptions);
|
|
216
|
+
const { Container } = await import("./Container.js"), id = params.id ?? params.element?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container(this, id, currentOptions);
|
|
236
217
|
if (oldIndex >= loadMinIndex) {
|
|
237
218
|
const old = this.item(oldIndex), deleteCount = old ? one : none;
|
|
238
219
|
if (old && !old.destroyed) {
|
|
@@ -261,15 +242,27 @@ export class Engine {
|
|
|
261
242
|
}
|
|
262
243
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
263
244
|
}
|
|
264
|
-
register(...
|
|
245
|
+
async register(...loaders) {
|
|
265
246
|
if (this._initialized) {
|
|
266
|
-
throw new Error(
|
|
247
|
+
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
267
248
|
}
|
|
268
|
-
for (const
|
|
269
|
-
this.
|
|
249
|
+
for (const loader of loaders) {
|
|
250
|
+
if (this._isRunningLoaders) {
|
|
251
|
+
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
this._loadPromises.add(loader);
|
|
255
|
+
}
|
|
270
256
|
}
|
|
271
257
|
}
|
|
272
258
|
removeEventListener(type, listener) {
|
|
273
259
|
this._eventDispatcher.removeEventListener(type, listener);
|
|
274
260
|
}
|
|
261
|
+
async _runLoader(loader, executed, allLoaders) {
|
|
262
|
+
if (executed.has(loader))
|
|
263
|
+
return;
|
|
264
|
+
executed.add(loader);
|
|
265
|
+
allLoaders.add(loader);
|
|
266
|
+
await loader(this);
|
|
267
|
+
}
|
|
275
268
|
}
|
package/esm/Core/Particle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Vector, Vector3d } from "./Utils/Vectors.js";
|
|
2
2
|
import { calcExactPositionOrRandomFromSize, clamp, degToRad, getParticleBaseVelocity, getParticleDirectionAngle, getRandom, getRangeValue, randomInRangeValue, setRangeValue, } from "../Utils/MathUtils.js";
|
|
3
|
-
import { decayOffset, defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, half, identity, millisecondsToSeconds, minZ,
|
|
3
|
+
import { decayOffset, defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, doublePI, half, identity, millisecondsToSeconds, minZ, randomColorValue, squareExp, triple, tryCountIncrement, zIndexFactorOffset, } from "./Utils/Constants.js";
|
|
4
4
|
import { deepExtend, getPosition, initParticleNumericAnimationValue, isInArray, itemFromSingleOrMultiple, } from "../Utils/Utils.js";
|
|
5
5
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
6
6
|
import { MoveDirection } from "../Enums/Directions/MoveDirection.js";
|
|
@@ -124,8 +124,7 @@ export class Particle {
|
|
|
124
124
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
125
125
|
return color;
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
if (!rolled) {
|
|
127
|
+
if (!this.isShowingBack()) {
|
|
129
128
|
return color;
|
|
130
129
|
}
|
|
131
130
|
if (this.backColor) {
|
|
@@ -286,9 +285,7 @@ export class Particle {
|
|
|
286
285
|
const availableShapes = [...this.container.shapeDrawers.keys()];
|
|
287
286
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
288
287
|
}
|
|
289
|
-
this.effectData = this.effect
|
|
290
|
-
? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates)
|
|
291
|
-
: undefined;
|
|
288
|
+
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
292
289
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
293
290
|
particlesOptions.load(overrideOptions);
|
|
294
291
|
const effectData = this.effectData;
|
|
@@ -378,6 +375,25 @@ export class Particle {
|
|
|
378
375
|
position.y <= canvasSize.height + radius &&
|
|
379
376
|
position.x <= canvasSize.width + radius);
|
|
380
377
|
}
|
|
378
|
+
isShowingBack() {
|
|
379
|
+
if (!this.roll) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
const angle = this.roll.angle;
|
|
383
|
+
if (this.roll.horizontal && this.roll.vertical) {
|
|
384
|
+
const normalizedAngle = angle % doublePI, adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + doublePI : normalizedAngle;
|
|
385
|
+
return adjustedAngle >= Math.PI * half && adjustedAngle < Math.PI * triple * half;
|
|
386
|
+
}
|
|
387
|
+
if (this.roll.horizontal) {
|
|
388
|
+
const normalizedAngle = (angle + Math.PI * half) % (Math.PI * double), adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + Math.PI * double : normalizedAngle;
|
|
389
|
+
return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * double;
|
|
390
|
+
}
|
|
391
|
+
if (this.roll.vertical) {
|
|
392
|
+
const normalizedAngle = angle % (Math.PI * double), adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + Math.PI * double : normalizedAngle;
|
|
393
|
+
return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * double;
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
381
397
|
isVisible() {
|
|
382
398
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
383
399
|
}
|
|
@@ -7,4 +7,4 @@ export const generatedAttribute = "generated", resizeEvent = "resize", visibilit
|
|
|
7
7
|
b: 0,
|
|
8
8
|
c: 0,
|
|
9
9
|
d: 1,
|
|
10
|
-
}, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, inverseFactorNumerator = 1.0, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0,
|
|
10
|
+
}, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, inverseFactorNumerator = 1.0, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0, minZ = 0, defaultRadius = 0, posOffset = -quarter, sizeFactor = 1.5, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, touchDelay = 500, manualDefaultPosition = 50, defaultAngle = 0, identity = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0;
|
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
export var EasingType;
|
|
2
2
|
(function (EasingType) {
|
|
3
3
|
EasingType["easeInBack"] = "ease-in-back";
|
|
4
|
+
EasingType["easeInBounce"] = "ease-in-bounce";
|
|
4
5
|
EasingType["easeInCirc"] = "ease-in-circ";
|
|
5
6
|
EasingType["easeInCubic"] = "ease-in-cubic";
|
|
7
|
+
EasingType["easeInElastic"] = "ease-in-elastic";
|
|
8
|
+
EasingType["easeInExpo"] = "ease-in-expo";
|
|
9
|
+
EasingType["easeInGaussian"] = "ease-in-gaussian";
|
|
6
10
|
EasingType["easeInLinear"] = "ease-in-linear";
|
|
7
11
|
EasingType["easeInQuad"] = "ease-in-quad";
|
|
8
12
|
EasingType["easeInQuart"] = "ease-in-quart";
|
|
9
13
|
EasingType["easeInQuint"] = "ease-in-quint";
|
|
10
|
-
EasingType["
|
|
14
|
+
EasingType["easeInSigmoid"] = "ease-in-sigmoid";
|
|
11
15
|
EasingType["easeInSine"] = "ease-in-sine";
|
|
16
|
+
EasingType["easeInSmoothstep"] = "ease-in-smoothstep";
|
|
12
17
|
EasingType["easeOutBack"] = "ease-out-back";
|
|
18
|
+
EasingType["easeOutBounce"] = "ease-out-bounce";
|
|
13
19
|
EasingType["easeOutCirc"] = "ease-out-circ";
|
|
14
20
|
EasingType["easeOutCubic"] = "ease-out-cubic";
|
|
21
|
+
EasingType["easeOutElastic"] = "ease-out-elastic";
|
|
22
|
+
EasingType["easeOutExpo"] = "ease-out-expo";
|
|
23
|
+
EasingType["easeOutGaussian"] = "ease-out-gaussian";
|
|
15
24
|
EasingType["easeOutLinear"] = "ease-out-linear";
|
|
16
25
|
EasingType["easeOutQuad"] = "ease-out-quad";
|
|
17
26
|
EasingType["easeOutQuart"] = "ease-out-quart";
|
|
18
27
|
EasingType["easeOutQuint"] = "ease-out-quint";
|
|
19
|
-
EasingType["
|
|
28
|
+
EasingType["easeOutSigmoid"] = "ease-out-sigmoid";
|
|
20
29
|
EasingType["easeOutSine"] = "ease-out-sine";
|
|
30
|
+
EasingType["easeOutSmoothstep"] = "ease-out-smoothstep";
|
|
21
31
|
EasingType["easeInOutBack"] = "ease-in-out-back";
|
|
32
|
+
EasingType["easeInOutBounce"] = "ease-in-out-bounce";
|
|
22
33
|
EasingType["easeInOutCirc"] = "ease-in-out-circ";
|
|
23
34
|
EasingType["easeInOutCubic"] = "ease-in-out-cubic";
|
|
35
|
+
EasingType["easeInOutElastic"] = "ease-in-out-elastic";
|
|
36
|
+
EasingType["easeInOutExpo"] = "ease-in-out-expo";
|
|
37
|
+
EasingType["easeInOutGaussian"] = "ease-in-out-gaussian";
|
|
24
38
|
EasingType["easeInOutLinear"] = "ease-in-out-linear";
|
|
25
39
|
EasingType["easeInOutQuad"] = "ease-in-out-quad";
|
|
26
40
|
EasingType["easeInOutQuart"] = "ease-in-out-quart";
|
|
27
41
|
EasingType["easeInOutQuint"] = "ease-in-out-quint";
|
|
28
|
-
EasingType["
|
|
42
|
+
EasingType["easeInOutSigmoid"] = "ease-in-out-sigmoid";
|
|
29
43
|
EasingType["easeInOutSine"] = "ease-in-out-sine";
|
|
44
|
+
EasingType["easeInOutSmoothstep"] = "ease-in-out-smoothstep";
|
|
30
45
|
})(EasingType || (EasingType = {}));
|
package/esm/Utils/CanvasUtils.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { lFactor, minStrokeWidth, originPoint } from "../Core/Utils/Constants.js";
|
|
2
2
|
import { AlterType } from "../Enums/Types/AlterType.js";
|
|
3
|
-
export function clearDrawPlugin(context, plugin, delta) {
|
|
4
|
-
if (!plugin.clearDraw) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
plugin.clearDraw(context, delta);
|
|
8
|
-
}
|
|
9
3
|
export function drawLine(context, begin, end) {
|
|
10
4
|
context.beginPath();
|
|
11
5
|
context.moveTo(begin.x, begin.y);
|
|
@@ -121,12 +115,6 @@ export function drawShapeBeforeDraw(container, data) {
|
|
|
121
115
|
}
|
|
122
116
|
drawer.beforeDraw(data);
|
|
123
117
|
}
|
|
124
|
-
export function drawPlugin(context, plugin, delta) {
|
|
125
|
-
if (!plugin.draw) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
plugin.draw(context, delta);
|
|
129
|
-
}
|
|
130
118
|
export function drawParticlePlugin(context, plugin, particle, delta) {
|
|
131
119
|
if (!plugin.drawParticle) {
|
|
132
120
|
return;
|
package/esm/Utils/Utils.js
CHANGED
|
@@ -98,11 +98,15 @@ export function deepExtend(destination, ...sources) {
|
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
100
|
const sourceIsArray = Array.isArray(source);
|
|
101
|
-
if (sourceIsArray
|
|
102
|
-
destination
|
|
101
|
+
if (sourceIsArray) {
|
|
102
|
+
if (!Array.isArray(destination)) {
|
|
103
|
+
destination = [];
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
|
-
else
|
|
105
|
-
destination
|
|
106
|
+
else {
|
|
107
|
+
if (!isObject(destination) || Array.isArray(destination)) {
|
|
108
|
+
destination = {};
|
|
109
|
+
}
|
|
106
110
|
}
|
|
107
111
|
for (const key in source) {
|
|
108
112
|
if (key === "__proto__") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/engine",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.8",
|
|
4
4
|
"description": "Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"scripts": {
|