@tsparticles/engine 4.0.0-beta.8 → 4.0.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/browser/Core/CanvasManager.js +74 -37
- package/browser/Core/Engine.js +23 -8
- package/browser/Core/Particle.js +3 -3
- package/browser/Core/ParticlesManager.js +157 -78
- package/browser/Core/Retina.js +2 -3
- package/browser/Core/Utils/EventListeners.js +1 -1
- package/browser/Options/Classes/Particles/Fill.js +0 -2
- package/browser/Options/Classes/Particles/Paint.js +25 -0
- package/browser/Options/Classes/Particles/ParticlesOptions.js +59 -36
- package/browser/Utils/CanvasUtils.js +3 -3
- package/browser/Utils/LogUtils.js +32 -15
- package/browser/Utils/Utils.js +1 -0
- package/browser/browser.js +5 -0
- package/browser/exports.js +1 -0
- package/browser/index.js +0 -1
- package/cjs/Core/CanvasManager.js +74 -37
- package/cjs/Core/Engine.js +23 -8
- package/cjs/Core/Particle.js +3 -3
- package/cjs/Core/ParticlesManager.js +157 -78
- package/cjs/Core/Retina.js +2 -3
- package/cjs/Core/Utils/EventListeners.js +1 -1
- package/cjs/Options/Classes/Particles/Fill.js +0 -2
- package/cjs/Options/Classes/Particles/Paint.js +25 -0
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +59 -36
- package/cjs/Utils/CanvasUtils.js +3 -3
- package/cjs/Utils/LogUtils.js +32 -15
- package/cjs/Utils/Utils.js +1 -0
- package/cjs/browser.js +5 -0
- package/cjs/exports.js +1 -0
- package/cjs/index.js +0 -1
- package/esm/Core/CanvasManager.js +74 -37
- package/esm/Core/Engine.js +23 -8
- package/esm/Core/Particle.js +3 -3
- package/esm/Core/ParticlesManager.js +157 -78
- package/esm/Core/Retina.js +2 -3
- package/esm/Core/Utils/EventListeners.js +1 -1
- package/esm/Options/Classes/Particles/Fill.js +0 -2
- package/esm/Options/Classes/Particles/Paint.js +25 -0
- package/esm/Options/Classes/Particles/ParticlesOptions.js +59 -36
- package/esm/Utils/CanvasUtils.js +3 -3
- package/esm/Utils/LogUtils.js +32 -15
- package/esm/Utils/Utils.js +1 -0
- package/esm/browser.js +5 -0
- package/esm/exports.js +1 -0
- package/esm/index.js +0 -1
- package/package.json +8 -1
- package/report.html +4949 -94
- package/scripts/install.js +321 -220
- package/tsparticles.engine.js +5293 -939
- package/tsparticles.engine.min.js +1 -2
- package/types/Core/CanvasManager.d.ts +3 -2
- package/types/Core/Container.d.ts +1 -2
- package/types/Core/Interfaces/IContainerPlugin.d.ts +7 -8
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +1 -2
- package/types/Core/Interfaces/ILoadParams.d.ts +1 -1
- package/types/Core/Interfaces/IPalette.d.ts +17 -2
- package/types/Core/Interfaces/IParticleUpdater.d.ts +1 -2
- package/types/Core/Interfaces/IShapeDrawData.d.ts +1 -2
- package/types/Core/Particle.d.ts +1 -0
- package/types/Core/ParticlesManager.d.ts +11 -5
- package/types/Core/RenderManager.d.ts +2 -3
- package/types/Core/Utils/PluginManager.d.ts +5 -6
- package/types/Options/Classes/Options.d.ts +1 -2
- package/types/Options/Classes/Particles/Fill.d.ts +1 -1
- package/types/Options/Classes/Particles/Paint.d.ts +12 -0
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +2 -4
- package/types/Options/Interfaces/Particles/IPaint.d.ts +10 -0
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -4
- package/types/Utils/CanvasUtils.d.ts +4 -5
- package/types/Utils/LogUtils.d.ts +2 -3
- package/types/Utils/Utils.d.ts +1 -2
- package/types/browser.d.ts +1 -0
- package/types/export-types.d.ts +1 -1
- package/types/exports.d.ts +1 -0
- package/types/{bundle.d.ts → index.lazy.d.ts} +1 -0
- package/67.min.js +0 -1
- package/dist_browser_Core_Container_js.js +0 -102
- package/types/Types/CanvasContextType.d.ts +0 -1
- /package/browser/{Types/CanvasContextType.js → Options/Interfaces/Particles/IPaint.js} +0 -0
- /package/browser/{bundle.js → index.lazy.js} +0 -0
- /package/cjs/{Types/CanvasContextType.js → Options/Interfaces/Particles/IPaint.js} +0 -0
- /package/cjs/{bundle.js → index.lazy.js} +0 -0
- /package/esm/{Types/CanvasContextType.js → Options/Interfaces/Particles/IPaint.js} +0 -0
- /package/esm/{bundle.js → index.lazy.js} +0 -0
package/esm/Core/Retina.js
CHANGED
|
@@ -13,9 +13,8 @@ export class Retina {
|
|
|
13
13
|
const container = this.container, options = container.actualOptions;
|
|
14
14
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
15
15
|
this.reduceFactor = defaultReduceFactor;
|
|
16
|
-
const ratio = this.pixelRatio, canvas = container.canvas;
|
|
17
|
-
if (
|
|
18
|
-
const element = canvas.element;
|
|
16
|
+
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
17
|
+
if (element) {
|
|
19
18
|
canvas.size.width = element.offsetWidth * ratio;
|
|
20
19
|
canvas.size.height = element.offsetHeight * ratio;
|
|
21
20
|
}
|
|
@@ -66,7 +66,7 @@ export class EventListeners {
|
|
|
66
66
|
manageListener(globalThis, resizeEvent, handlers.resize, add);
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
-
const canvasEl = container.canvas.
|
|
69
|
+
const canvasEl = container.canvas.domElement;
|
|
70
70
|
if (this._resizeObserver && !add) {
|
|
71
71
|
if (canvasEl) {
|
|
72
72
|
this._resizeObserver.unobserve(canvasEl);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AnimatableColor } from "../AnimatableColor.js";
|
|
2
|
+
import { Fill } from "./Fill.js";
|
|
3
|
+
import { Stroke } from "./Stroke.js";
|
|
4
|
+
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
5
|
+
export class Paint {
|
|
6
|
+
color;
|
|
7
|
+
fill;
|
|
8
|
+
stroke;
|
|
9
|
+
load(data) {
|
|
10
|
+
if (isNull(data)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.color !== undefined) {
|
|
14
|
+
this.color = AnimatableColor.create(this.color, data.color);
|
|
15
|
+
}
|
|
16
|
+
if (data.fill !== undefined) {
|
|
17
|
+
this.fill ??= new Fill();
|
|
18
|
+
this.fill.load(data.fill);
|
|
19
|
+
}
|
|
20
|
+
if (data.stroke !== undefined) {
|
|
21
|
+
this.stroke ??= new Stroke();
|
|
22
|
+
this.stroke.load(data.stroke);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { deepExtend, executeOnSingleOrMultiple } from "../../../Utils/Utils.js";
|
|
2
|
+
import { isArray, isNull } from "../../../Utils/TypeUtils.js";
|
|
3
|
+
import { AnimatableColor } from "../AnimatableColor.js";
|
|
2
4
|
import { Effect } from "./Effect/Effect.js";
|
|
3
5
|
import { Fill } from "./Fill.js";
|
|
4
6
|
import { Move } from "./Move/Move.js";
|
|
5
7
|
import { Opacity } from "./Opacity/Opacity.js";
|
|
8
|
+
import { Paint } from "./Paint.js";
|
|
6
9
|
import { ParticlesBounce } from "./Bounce/ParticlesBounce.js";
|
|
7
10
|
import { ParticlesNumber } from "./Number/ParticlesNumber.js";
|
|
8
11
|
import { Shape } from "./Shape/Shape.js";
|
|
9
12
|
import { Size } from "./Size/Size.js";
|
|
10
|
-
import { Stroke } from "./Stroke.js";
|
|
11
13
|
import { ZIndex } from "./ZIndex/ZIndex.js";
|
|
12
|
-
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
13
14
|
export class ParticlesOptions {
|
|
14
15
|
bounce;
|
|
15
16
|
effect;
|
|
16
|
-
fill;
|
|
17
17
|
groups;
|
|
18
18
|
move;
|
|
19
19
|
number;
|
|
20
20
|
opacity;
|
|
21
|
+
paint;
|
|
21
22
|
palette;
|
|
22
23
|
reduceDuplicates;
|
|
23
24
|
shape;
|
|
24
25
|
size;
|
|
25
|
-
stroke;
|
|
26
26
|
zIndex;
|
|
27
27
|
_container;
|
|
28
28
|
_pluginManager;
|
|
@@ -31,15 +31,18 @@ export class ParticlesOptions {
|
|
|
31
31
|
this._container = container;
|
|
32
32
|
this.bounce = new ParticlesBounce();
|
|
33
33
|
this.effect = new Effect();
|
|
34
|
-
this.fill = new Fill();
|
|
35
34
|
this.groups = {};
|
|
36
35
|
this.move = new Move();
|
|
37
36
|
this.number = new ParticlesNumber();
|
|
38
37
|
this.opacity = new Opacity();
|
|
38
|
+
this.paint = new Paint();
|
|
39
|
+
this.paint.color = new AnimatableColor();
|
|
40
|
+
this.paint.color.value = "#fff";
|
|
41
|
+
this.paint.fill = new Fill();
|
|
42
|
+
this.paint.fill.enable = true;
|
|
39
43
|
this.reduceDuplicates = false;
|
|
40
44
|
this.shape = new Shape();
|
|
41
45
|
this.size = new Size();
|
|
42
|
-
this.stroke = new Stroke();
|
|
43
46
|
this.zIndex = new ZIndex();
|
|
44
47
|
}
|
|
45
48
|
load(data) {
|
|
@@ -69,25 +72,26 @@ export class ParticlesOptions {
|
|
|
69
72
|
this.move.load(data.move);
|
|
70
73
|
this.number.load(data.number);
|
|
71
74
|
this.opacity.load(data.opacity);
|
|
75
|
+
const paintToLoad = data.paint;
|
|
76
|
+
if (paintToLoad) {
|
|
77
|
+
if (isArray(paintToLoad)) {
|
|
78
|
+
this.paint = executeOnSingleOrMultiple(paintToLoad, t => {
|
|
79
|
+
const tmp = new Paint();
|
|
80
|
+
tmp.load(t);
|
|
81
|
+
return tmp;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else if (isArray(this.paint)) {
|
|
85
|
+
this.paint = new Paint();
|
|
86
|
+
this.paint.load(paintToLoad);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this.paint.load(paintToLoad);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
72
92
|
this.shape.load(data.shape);
|
|
73
93
|
this.size.load(data.size);
|
|
74
94
|
this.zIndex.load(data.zIndex);
|
|
75
|
-
const fillToLoad = data.fill;
|
|
76
|
-
if (fillToLoad) {
|
|
77
|
-
this.fill = executeOnSingleOrMultiple(fillToLoad, t => {
|
|
78
|
-
const tmp = new Fill();
|
|
79
|
-
tmp.load(t);
|
|
80
|
-
return tmp;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
const strokeToLoad = data.stroke;
|
|
84
|
-
if (strokeToLoad) {
|
|
85
|
-
this.stroke = executeOnSingleOrMultiple(strokeToLoad, t => {
|
|
86
|
-
const tmp = new Stroke();
|
|
87
|
-
tmp.load(t);
|
|
88
|
-
return tmp;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
95
|
if (this._container) {
|
|
92
96
|
for (const plugin of this._pluginManager.plugins) {
|
|
93
97
|
if (plugin.loadParticlesOptions) {
|
|
@@ -109,21 +113,40 @@ export class ParticlesOptions {
|
|
|
109
113
|
if (!paletteData) {
|
|
110
114
|
return;
|
|
111
115
|
}
|
|
116
|
+
const paletteColors = paletteData.colors, defaultPaintStrokeWidth = 0, defaultPaintVariantsLength = 1, firstPaintVariantIndex = 0, defaultPalettePaintVariant = {}, colorVariants = isArray(paletteColors) ? paletteColors : [paletteColors], palettePaintVariants = colorVariants.flatMap(variant => {
|
|
117
|
+
const paletteFill = variant.fill, paletteStroke = variant.stroke, fillPart = paletteFill
|
|
118
|
+
? {
|
|
119
|
+
color: {
|
|
120
|
+
value: paletteFill.value,
|
|
121
|
+
},
|
|
122
|
+
enable: paletteFill.enable,
|
|
123
|
+
opacity: paletteFill.opacity,
|
|
124
|
+
}
|
|
125
|
+
: undefined;
|
|
126
|
+
if (!paletteStroke) {
|
|
127
|
+
return [
|
|
128
|
+
{
|
|
129
|
+
fill: fillPart,
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
return [
|
|
134
|
+
{
|
|
135
|
+
fill: fillPart,
|
|
136
|
+
stroke: {
|
|
137
|
+
color: {
|
|
138
|
+
value: paletteStroke.value,
|
|
139
|
+
},
|
|
140
|
+
opacity: paletteStroke.opacity,
|
|
141
|
+
width: paletteStroke.width || defaultPaintStrokeWidth,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
}), palettePaint = palettePaintVariants.length > defaultPaintVariantsLength
|
|
146
|
+
? palettePaintVariants
|
|
147
|
+
: (palettePaintVariants[firstPaintVariantIndex] ?? defaultPalettePaintVariant);
|
|
112
148
|
this.load({
|
|
113
|
-
|
|
114
|
-
color: paletteData.fill
|
|
115
|
-
? {
|
|
116
|
-
value: paletteData.colors,
|
|
117
|
-
}
|
|
118
|
-
: undefined,
|
|
119
|
-
enable: paletteData.fill,
|
|
120
|
-
},
|
|
121
|
-
stroke: paletteData.fill
|
|
122
|
-
? undefined
|
|
123
|
-
: paletteData.colors.map(color => ({
|
|
124
|
-
color: { value: color },
|
|
125
|
-
width: 1,
|
|
126
|
-
})),
|
|
149
|
+
paint: palettePaint,
|
|
127
150
|
blend: {
|
|
128
151
|
enable: true,
|
|
129
152
|
mode: paletteData.blendMode,
|
package/esm/Utils/CanvasUtils.js
CHANGED
|
@@ -88,12 +88,12 @@ export function drawShape(drawer, data) {
|
|
|
88
88
|
if (particle.shapeClose) {
|
|
89
89
|
context.closePath();
|
|
90
90
|
}
|
|
91
|
-
if (stroke) {
|
|
92
|
-
context.stroke();
|
|
93
|
-
}
|
|
94
91
|
if (fill) {
|
|
95
92
|
context.fill();
|
|
96
93
|
}
|
|
94
|
+
if (stroke) {
|
|
95
|
+
context.stroke();
|
|
96
|
+
}
|
|
97
97
|
}
|
|
98
98
|
export function drawShapeAfterDraw(drawer, data) {
|
|
99
99
|
if (!drawer?.afterDraw) {
|
package/esm/Utils/LogUtils.js
CHANGED
|
@@ -1,22 +1,39 @@
|
|
|
1
1
|
const errorPrefix = "tsParticles - Error";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const wrap = (fn) => (...args) => {
|
|
3
|
+
fn(...args);
|
|
4
|
+
}, _logger = {
|
|
5
|
+
debug: wrap(console.debug),
|
|
6
|
+
error: (message, ...optionalParams) => {
|
|
7
|
+
console.error(`${errorPrefix} - ${message}`, ...optionalParams);
|
|
6
8
|
},
|
|
7
|
-
info: console.info,
|
|
8
|
-
log: console.log,
|
|
9
|
-
trace: console.trace,
|
|
10
|
-
verbose: console.log,
|
|
11
|
-
warning: console.warn,
|
|
9
|
+
info: wrap(console.info),
|
|
10
|
+
log: wrap(console.log),
|
|
11
|
+
trace: wrap(console.trace),
|
|
12
|
+
verbose: wrap(console.log),
|
|
13
|
+
warning: wrap(console.warn),
|
|
12
14
|
};
|
|
13
15
|
export function setLogger(logger) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (logger.debug) {
|
|
17
|
+
_logger.debug = wrap(logger.debug);
|
|
18
|
+
}
|
|
19
|
+
if (logger.error) {
|
|
20
|
+
_logger.error = wrap(logger.error);
|
|
21
|
+
}
|
|
22
|
+
if (logger.info) {
|
|
23
|
+
_logger.info = wrap(logger.info);
|
|
24
|
+
}
|
|
25
|
+
if (logger.log) {
|
|
26
|
+
_logger.log = wrap(logger.log);
|
|
27
|
+
}
|
|
28
|
+
if (logger.trace) {
|
|
29
|
+
_logger.trace = wrap(logger.trace);
|
|
30
|
+
}
|
|
31
|
+
if (logger.verbose) {
|
|
32
|
+
_logger.verbose = wrap(logger.verbose);
|
|
33
|
+
}
|
|
34
|
+
if (logger.warning) {
|
|
35
|
+
_logger.warning = wrap(logger.warning);
|
|
36
|
+
}
|
|
20
37
|
}
|
|
21
38
|
export function getLogger() {
|
|
22
39
|
return _logger;
|
package/esm/Utils/Utils.js
CHANGED
package/esm/browser.js
ADDED
package/esm/exports.js
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./Options/Classes/Particles/Bounce/ParticlesBounce.js";
|
|
|
28
28
|
export * from "./Options/Classes/Particles/Bounce/ParticlesBounceFactor.js";
|
|
29
29
|
export * from "./Options/Classes/Particles/ParticlesOptions.js";
|
|
30
30
|
export * from "./Options/Classes/Particles/Fill.js";
|
|
31
|
+
export * from "./Options/Classes/Particles/Paint.js";
|
|
31
32
|
export * from "./Options/Classes/Particles/Stroke.js";
|
|
32
33
|
export * from "./Options/Classes/Particles/Move/Move.js";
|
|
33
34
|
export * from "./Options/Classes/Particles/Move/MoveAngle.js";
|
package/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/engine",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
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": {
|
|
@@ -98,6 +98,13 @@
|
|
|
98
98
|
"require": "./cjs/index.js",
|
|
99
99
|
"default": "./esm/index.js"
|
|
100
100
|
},
|
|
101
|
+
"./lazy": {
|
|
102
|
+
"types": "./types/index.lazy.d.ts",
|
|
103
|
+
"browser": "./browser/index.lazy.js",
|
|
104
|
+
"import": "./esm/index.lazy.js",
|
|
105
|
+
"require": "./cjs/index.lazy.js",
|
|
106
|
+
"default": "./esm/index.lazy.js"
|
|
107
|
+
},
|
|
101
108
|
"./package.json": "./package.json"
|
|
102
109
|
},
|
|
103
110
|
"publishConfig": {
|