@tsparticles/engine 3.0.0-beta.1 → 3.0.0-beta.3
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/README.md +8 -8
- package/browser/Core/Container.js +3 -5
- package/browser/Core/Engine.js +10 -50
- package/browser/Core/Particle.js +13 -13
- package/browser/Core/Particles.js +3 -2
- package/browser/Utils/CanvasUtils.js +9 -6
- package/browser/Utils/Utils.js +6 -0
- package/browser/export-types.js +0 -2
- package/cjs/Core/Container.js +3 -5
- package/cjs/Core/Engine.js +9 -49
- package/cjs/Core/Particle.js +13 -13
- package/cjs/Core/Particles.js +3 -2
- package/cjs/Utils/CanvasUtils.js +9 -6
- package/cjs/Utils/Utils.js +8 -1
- package/cjs/export-types.js +0 -2
- package/esm/Core/Container.js +3 -5
- package/esm/Core/Engine.js +10 -50
- package/esm/Core/Particle.js +13 -13
- package/esm/Core/Particles.js +3 -2
- package/esm/Utils/CanvasUtils.js +9 -6
- package/esm/Utils/Utils.js +6 -0
- package/esm/export-types.js +0 -2
- package/package.json +3 -3
- package/report.html +23 -5
- package/scripts/install.js +8 -8
- package/tsparticles.engine.js +83 -72
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Container.d.ts +2 -2
- package/types/Core/Engine.d.ts +3 -4
- package/types/Core/Interfaces/IShapeDrawer.d.ts +19 -9
- package/types/Core/Particle.d.ts +1 -3
- package/types/Enums/Types/EventType.d.ts +1 -0
- package/types/Types/CustomEventArgs.d.ts +1 -1
- package/types/Utils/CanvasUtils.d.ts +11 -2
- package/types/Utils/ColorUtils.d.ts +2 -2
- package/types/Utils/Utils.d.ts +4 -3
- package/types/export-types.d.ts +0 -2
- package/umd/Core/Container.js +4 -6
- package/umd/Core/Engine.js +9 -49
- package/umd/Core/Particle.js +13 -13
- package/umd/Core/Particles.js +3 -2
- package/umd/Utils/CanvasUtils.js +9 -6
- package/umd/Utils/Utils.js +8 -1
- package/umd/export-types.js +1 -3
- package/browser/Core/Interfaces/IParticle.js +0 -1
- package/browser/Types/ShapeDrawerFunctions.js +0 -1
- package/cjs/Core/Interfaces/IParticle.js +0 -2
- package/cjs/Types/ShapeDrawerFunctions.js +0 -2
- package/esm/Core/Interfaces/IParticle.js +0 -1
- package/esm/Types/ShapeDrawerFunctions.js +0 -1
- package/types/Core/Interfaces/IParticle.d.ts +0 -48
- package/types/Types/ShapeDrawerFunctions.d.ts +0 -10
- package/umd/Core/Interfaces/IParticle.js +0 -12
- package/umd/Types/ShapeDrawerFunctions.js +0 -12
package/esm/Core/Engine.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { errorPrefix, generatedAttribute } from "./Utils/Constants.js";
|
|
2
|
-
import { executeOnSingleOrMultiple, getLogger,
|
|
2
|
+
import { executeOnSingleOrMultiple, getLogger, itemFromSingleOrMultiple } from "../Utils/Utils.js";
|
|
3
3
|
import { Container } from "./Container.js";
|
|
4
4
|
import { EventDispatcher } from "../Utils/EventDispatcher.js";
|
|
5
5
|
import { getRandom } from "../Utils/NumberUtils.js";
|
|
@@ -50,18 +50,12 @@ export class Engine {
|
|
|
50
50
|
return res;
|
|
51
51
|
}
|
|
52
52
|
get version() {
|
|
53
|
-
return "3.0.0-beta.
|
|
53
|
+
return "3.0.0-beta.3";
|
|
54
54
|
}
|
|
55
|
-
addConfig(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this._configs.set(nameOrConfig, config);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
this._configs.set(nameOrConfig.name ?? "default", nameOrConfig);
|
|
64
|
-
}
|
|
55
|
+
addConfig(config) {
|
|
56
|
+
const name = config.name ?? "default";
|
|
57
|
+
this._configs.set(name, config);
|
|
58
|
+
this._eventDispatcher.dispatchEvent("configAdded", { data: { name, config } });
|
|
65
59
|
}
|
|
66
60
|
addEventListener(type, listener) {
|
|
67
61
|
this._eventDispatcher.addEventListener(type, listener);
|
|
@@ -90,45 +84,11 @@ export class Engine {
|
|
|
90
84
|
(override || !this.getPreset(preset)) && this.presets.set(preset, options);
|
|
91
85
|
await this.refresh(refresh);
|
|
92
86
|
}
|
|
93
|
-
async addShape(shape, drawer,
|
|
94
|
-
let customDrawer;
|
|
95
|
-
let realRefresh = refresh, realInit, realAfterEffect, realDestroy;
|
|
96
|
-
if (isBoolean(initOrRefresh)) {
|
|
97
|
-
realRefresh = initOrRefresh;
|
|
98
|
-
realInit = undefined;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
realInit = initOrRefresh;
|
|
102
|
-
}
|
|
103
|
-
if (isBoolean(afterEffectOrRefresh)) {
|
|
104
|
-
realRefresh = afterEffectOrRefresh;
|
|
105
|
-
realAfterEffect = undefined;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
realAfterEffect = afterEffectOrRefresh;
|
|
109
|
-
}
|
|
110
|
-
if (isBoolean(destroyOrRefresh)) {
|
|
111
|
-
realRefresh = destroyOrRefresh;
|
|
112
|
-
realDestroy = undefined;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
realDestroy = destroyOrRefresh;
|
|
116
|
-
}
|
|
117
|
-
if (isFunction(drawer)) {
|
|
118
|
-
customDrawer = {
|
|
119
|
-
afterEffect: realAfterEffect,
|
|
120
|
-
destroy: realDestroy,
|
|
121
|
-
draw: drawer,
|
|
122
|
-
init: realInit,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
customDrawer = drawer;
|
|
127
|
-
}
|
|
87
|
+
async addShape(shape, drawer, refresh = true) {
|
|
128
88
|
executeOnSingleOrMultiple(shape, (type) => {
|
|
129
|
-
!this.getShapeDrawer(type) && this.drawers.set(type,
|
|
89
|
+
!this.getShapeDrawer(type) && this.drawers.set(type, drawer);
|
|
130
90
|
});
|
|
131
|
-
await this.refresh(
|
|
91
|
+
await this.refresh(refresh);
|
|
132
92
|
}
|
|
133
93
|
clearPlugins(container) {
|
|
134
94
|
this.updaters.delete(container);
|
|
@@ -194,7 +154,7 @@ export class Engine {
|
|
|
194
154
|
domContainer.id = id;
|
|
195
155
|
document.body.append(domContainer);
|
|
196
156
|
}
|
|
197
|
-
const currentOptions = itemFromSingleOrMultiple(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id === id);
|
|
157
|
+
const currentOptions = itemFromSingleOrMultiple(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id.description === id);
|
|
198
158
|
if (oldIndex >= 0) {
|
|
199
159
|
const old = this.domItem(oldIndex);
|
|
200
160
|
if (old && !old.destroyed) {
|
package/esm/Core/Particle.js
CHANGED
|
@@ -7,7 +7,17 @@ import { Vector3d } from "./Utils/Vector3d.js";
|
|
|
7
7
|
import { alterHsl } from "../Utils/CanvasUtils.js";
|
|
8
8
|
import { errorPrefix } from "./Utils/Constants.js";
|
|
9
9
|
import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
|
|
10
|
-
|
|
10
|
+
function loadShapeData(shape, shapeOptions, id, reduceDuplicates) {
|
|
11
|
+
const shapeData = shapeOptions.options[shape];
|
|
12
|
+
if (!shapeData) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
return deepExtend({
|
|
16
|
+
close: shapeOptions.close,
|
|
17
|
+
fill: shapeOptions.fill,
|
|
18
|
+
}, itemFromSingleOrMultiple(shapeData, id, reduceDuplicates));
|
|
19
|
+
}
|
|
20
|
+
function fixOutMode(data) {
|
|
11
21
|
if (!isInArray(data.outMode, data.checkModes)) {
|
|
12
22
|
return;
|
|
13
23
|
}
|
|
@@ -18,7 +28,7 @@ const fixOutMode = (data) => {
|
|
|
18
28
|
else if (data.coord < diameter) {
|
|
19
29
|
data.setCb(data.radius);
|
|
20
30
|
}
|
|
21
|
-
}
|
|
31
|
+
}
|
|
22
32
|
export class Particle {
|
|
23
33
|
constructor(engine, id, container, position, overrideOptions, group) {
|
|
24
34
|
this.container = container;
|
|
@@ -129,16 +139,6 @@ export class Particle {
|
|
|
129
139
|
}
|
|
130
140
|
this.offset = Vector.origin;
|
|
131
141
|
};
|
|
132
|
-
this._loadShapeData = (shapeOptions, reduceDuplicates) => {
|
|
133
|
-
const shapeData = shapeOptions.options[this.shape];
|
|
134
|
-
if (!shapeData) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
return deepExtend({
|
|
138
|
-
close: shapeOptions.close,
|
|
139
|
-
fill: shapeOptions.fill,
|
|
140
|
-
}, itemFromSingleOrMultiple(shapeData, this.id, reduceDuplicates));
|
|
141
|
-
};
|
|
142
142
|
this._engine = engine;
|
|
143
143
|
this.init(id, position, overrideOptions, group);
|
|
144
144
|
}
|
|
@@ -217,7 +217,7 @@ export class Particle {
|
|
|
217
217
|
shapeOptions.load(overrideOptions.shape);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
-
this.shapeData = this.
|
|
220
|
+
this.shapeData = loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates);
|
|
221
221
|
particlesOptions.load(overrideOptions);
|
|
222
222
|
const shapeData = this.shapeData;
|
|
223
223
|
if (shapeData) {
|
package/esm/Core/Particles.js
CHANGED
|
@@ -70,8 +70,9 @@ export class Particles {
|
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
72
|
particle.destroy(override);
|
|
73
|
+
const zIdx = this._zArray.indexOf(particle);
|
|
73
74
|
this._array.splice(index, 1);
|
|
74
|
-
this._zArray
|
|
75
|
+
this._zArray.splice(zIdx, 1);
|
|
75
76
|
this.pool.push(particle);
|
|
76
77
|
this._engine.dispatchEvent("particleRemoved", {
|
|
77
78
|
container: this._container,
|
|
@@ -172,7 +173,7 @@ export class Particles {
|
|
|
172
173
|
}
|
|
173
174
|
this.addManualParticles();
|
|
174
175
|
if (!handled) {
|
|
175
|
-
const particlesOptions = options.particles, groups =
|
|
176
|
+
const particlesOptions = options.particles, groups = particlesOptions.groups;
|
|
176
177
|
for (const group in groups) {
|
|
177
178
|
const groupOptions = groups[group];
|
|
178
179
|
for (let i = this.count, j = 0; j < groupOptions.number?.value && i < particlesOptions.number.value; i++, j++) {
|
package/esm/Utils/CanvasUtils.js
CHANGED
|
@@ -58,7 +58,8 @@ export function drawParticle(data) {
|
|
|
58
58
|
if (colorStyles.stroke) {
|
|
59
59
|
context.strokeStyle = colorStyles.stroke;
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
const drawData = { container, context, particle, radius, opacity, delta };
|
|
62
|
+
drawShape(drawData);
|
|
62
63
|
if (strokeWidth > 0) {
|
|
63
64
|
context.stroke();
|
|
64
65
|
}
|
|
@@ -68,11 +69,12 @@ export function drawParticle(data) {
|
|
|
68
69
|
if (particle.fill) {
|
|
69
70
|
context.fill();
|
|
70
71
|
}
|
|
71
|
-
drawShapeAfterEffect(
|
|
72
|
+
drawShapeAfterEffect(drawData);
|
|
72
73
|
context.globalCompositeOperation = "source-over";
|
|
73
74
|
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
74
75
|
}
|
|
75
|
-
export function drawShape(
|
|
76
|
+
export function drawShape(data) {
|
|
77
|
+
const { container, context, particle, radius, opacity, delta } = data;
|
|
76
78
|
if (!particle.shape) {
|
|
77
79
|
return;
|
|
78
80
|
}
|
|
@@ -80,9 +82,10 @@ export function drawShape(container, context, particle, radius, opacity, delta)
|
|
|
80
82
|
if (!drawer) {
|
|
81
83
|
return;
|
|
82
84
|
}
|
|
83
|
-
drawer.draw(context, particle, radius, opacity, delta, container.retina.pixelRatio);
|
|
85
|
+
drawer.draw({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
|
|
84
86
|
}
|
|
85
|
-
export function drawShapeAfterEffect(
|
|
87
|
+
export function drawShapeAfterEffect(data) {
|
|
88
|
+
const { container, context, particle, radius, opacity, delta } = data;
|
|
86
89
|
if (!particle.shape) {
|
|
87
90
|
return;
|
|
88
91
|
}
|
|
@@ -90,7 +93,7 @@ export function drawShapeAfterEffect(container, context, particle, radius, opaci
|
|
|
90
93
|
if (!drawer || !drawer.afterEffect) {
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
|
-
drawer.afterEffect(context, particle, radius, opacity, delta, container.retina.pixelRatio);
|
|
96
|
+
drawer.afterEffect({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
|
|
94
97
|
}
|
|
95
98
|
export function drawPlugin(context, plugin, delta) {
|
|
96
99
|
if (!plugin.draw) {
|
package/esm/Utils/Utils.js
CHANGED
|
@@ -52,6 +52,12 @@ export function safeMatchMedia(query) {
|
|
|
52
52
|
}
|
|
53
53
|
return matchMedia(query);
|
|
54
54
|
}
|
|
55
|
+
export function safeIntersectionObserver(callback) {
|
|
56
|
+
if (isSsr() || typeof IntersectionObserver === "undefined") {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
return new IntersectionObserver(callback);
|
|
60
|
+
}
|
|
55
61
|
export function safeMutationObserver(callback) {
|
|
56
62
|
if (isSsr() || typeof MutationObserver === "undefined") {
|
|
57
63
|
return;
|
package/esm/export-types.js
CHANGED
|
@@ -15,7 +15,6 @@ export * from "./Core/Interfaces/IInteractor.js";
|
|
|
15
15
|
export * from "./Core/Interfaces/ILoadParams.js";
|
|
16
16
|
export * from "./Core/Interfaces/IMouseData.js";
|
|
17
17
|
export * from "./Core/Interfaces/IMovePathGenerator.js";
|
|
18
|
-
export * from "./Core/Interfaces/IParticle.js";
|
|
19
18
|
export * from "./Core/Interfaces/IParticleColorStyle.js";
|
|
20
19
|
export * from "./Core/Interfaces/IParticleHslAnimation.js";
|
|
21
20
|
export * from "./Core/Interfaces/IParticleLife.js";
|
|
@@ -93,5 +92,4 @@ export * from "./Types/PathOptions.js";
|
|
|
93
92
|
export * from "./Types/RangeValue.js";
|
|
94
93
|
export * from "./Types/RecursivePartial.js";
|
|
95
94
|
export * from "./Types/ShapeData.js";
|
|
96
|
-
export * from "./Types/ShapeDrawerFunctions.js";
|
|
97
95
|
export * from "./Types/SingleOrMultiple.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/engine",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.3",
|
|
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": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com/tsparticles/tsparticles.git",
|
|
12
12
|
"directory": "engine"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"author": "Matteo Bruni <matteo.bruni@me.com>",
|
|
68
68
|
"license": "MIT",
|
|
69
69
|
"bugs": {
|
|
70
|
-
"url": "https://github.com/
|
|
70
|
+
"url": "https://github.com/tsparticles/tsparticles/issues"
|
|
71
71
|
},
|
|
72
72
|
"funding": [
|
|
73
73
|
{
|