@tsparticles/engine 4.0.0-beta.1 → 4.0.0-beta.10
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/67.min.js +1 -0
- package/README.md +53 -944
- package/browser/Core/Engine.js +1 -1
- package/browser/Options/Classes/Options.js +1 -14
- package/browser/Options/Classes/Particles/Paint.js +20 -0
- package/browser/Options/Classes/Particles/ParticlesOptions.js +60 -22
- package/browser/Options/Interfaces/Particles/IPaint.js +1 -0
- package/browser/Utils/CanvasUtils.js +3 -3
- package/browser/Utils/Utils.js +16 -10
- package/browser/exports.js +1 -0
- package/cjs/Core/Engine.js +1 -1
- package/cjs/Options/Classes/Options.js +1 -14
- package/cjs/Options/Classes/Particles/Paint.js +20 -0
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +60 -22
- package/cjs/Options/Interfaces/Particles/IPaint.js +1 -0
- package/cjs/Utils/CanvasUtils.js +3 -3
- package/cjs/Utils/Utils.js +16 -10
- package/cjs/exports.js +1 -0
- package/dist_browser_Core_Container_js.js +1 -1
- package/esm/Core/Engine.js +1 -1
- package/esm/Options/Classes/Options.js +1 -14
- package/esm/Options/Classes/Particles/Paint.js +20 -0
- package/esm/Options/Classes/Particles/ParticlesOptions.js +60 -22
- package/esm/Options/Interfaces/Particles/IPaint.js +1 -0
- package/esm/Utils/CanvasUtils.js +3 -3
- package/esm/Utils/Utils.js +16 -10
- package/esm/exports.js +1 -0
- package/package.json +2 -3
- package/report.html +1 -1
- package/tsparticles.engine.js +18 -8
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/Interfaces/IPalette.d.ts +15 -2
- package/types/Options/Classes/Particles/Paint.d.ts +10 -0
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +4 -4
- package/types/Options/Interfaces/Particles/IPaint.d.ts +6 -0
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +3 -4
- package/types/export-types.d.ts +1 -0
- package/types/exports.d.ts +1 -0
- package/155.min.js +0 -1
- package/umd/Core/CanvasManager.js +0 -317
- package/umd/Core/Container.js +0 -383
- package/umd/Core/Engine.js +0 -183
- package/umd/Core/Interfaces/Colors.js +0 -12
- package/umd/Core/Interfaces/IBounds.js +0 -12
- package/umd/Core/Interfaces/IBubbleParticleData.js +0 -12
- package/umd/Core/Interfaces/ICircleBouncer.js +0 -12
- package/umd/Core/Interfaces/IColorManager.js +0 -12
- package/umd/Core/Interfaces/IContainerPlugin.js +0 -12
- package/umd/Core/Interfaces/ICoordinates.js +0 -12
- package/umd/Core/Interfaces/IDelta.js +0 -12
- package/umd/Core/Interfaces/IDimension.js +0 -12
- package/umd/Core/Interfaces/IDistance.js +0 -12
- package/umd/Core/Interfaces/IDrawParticleParams.js +0 -12
- package/umd/Core/Interfaces/IEffectDrawer.js +0 -12
- package/umd/Core/Interfaces/ILoadParams.js +0 -12
- package/umd/Core/Interfaces/IPalette.js +0 -12
- package/umd/Core/Interfaces/IParticleColorStyle.js +0 -12
- package/umd/Core/Interfaces/IParticleHslAnimation.js +0 -12
- package/umd/Core/Interfaces/IParticleLife.js +0 -12
- package/umd/Core/Interfaces/IParticleOpacityData.js +0 -12
- package/umd/Core/Interfaces/IParticleRetinaProps.js +0 -12
- package/umd/Core/Interfaces/IParticleRoll.js +0 -12
- package/umd/Core/Interfaces/IParticleRotateData.js +0 -12
- package/umd/Core/Interfaces/IParticleTransformValues.js +0 -12
- package/umd/Core/Interfaces/IParticleUpdater.js +0 -12
- package/umd/Core/Interfaces/IParticleValueAnimation.js +0 -12
- package/umd/Core/Interfaces/IPlugin.js +0 -12
- package/umd/Core/Interfaces/IPositionFromSizeParams.js +0 -12
- package/umd/Core/Interfaces/IRangeValue.js +0 -12
- package/umd/Core/Interfaces/IShapeDrawData.js +0 -12
- package/umd/Core/Interfaces/IShapeDrawer.js +0 -12
- package/umd/Core/Interfaces/IShapeValues.js +0 -12
- package/umd/Core/Interfaces/ISlowParticleData.js +0 -12
- package/umd/Core/Particle.js +0 -433
- package/umd/Core/ParticlesManager.js +0 -377
- package/umd/Core/RenderManager.js +0 -317
- package/umd/Core/Retina.js +0 -47
- package/umd/Core/Utils/Constants.js +0 -23
- package/umd/Core/Utils/EventListeners.js +0 -102
- package/umd/Core/Utils/PluginManager.js +0 -159
- package/umd/Core/Utils/Ranges.js +0 -91
- package/umd/Core/Utils/SpatialHashGrid.js +0 -116
- package/umd/Core/Utils/Vectors.js +0 -126
- package/umd/Enums/AnimationStatus.js +0 -18
- package/umd/Enums/Directions/MoveDirection.js +0 -27
- package/umd/Enums/Directions/OutModeDirection.js +0 -20
- package/umd/Enums/Directions/RotateDirection.js +0 -19
- package/umd/Enums/Modes/AnimationMode.js +0 -20
- package/umd/Enums/Modes/LimitMode.js +0 -18
- package/umd/Enums/Modes/OutMode.js +0 -21
- package/umd/Enums/Modes/PixelMode.js +0 -18
- package/umd/Enums/RangeType.js +0 -18
- package/umd/Enums/Types/AlterType.js +0 -18
- package/umd/Enums/Types/DestroyType.js +0 -19
- package/umd/Enums/Types/EasingType.js +0 -58
- package/umd/Enums/Types/EventType.js +0 -28
- package/umd/Enums/Types/GradientType.js +0 -19
- package/umd/Enums/Types/ParticleOutType.js +0 -19
- package/umd/Enums/Types/StartValueType.js +0 -19
- package/umd/Options/Classes/AnimatableColor.js +0 -52
- package/umd/Options/Classes/AnimationOptions.js +0 -79
- package/umd/Options/Classes/Background/Background.js +0 -56
- package/umd/Options/Classes/ColorAnimation.js +0 -44
- package/umd/Options/Classes/FullScreen/FullScreen.js +0 -34
- package/umd/Options/Classes/HslAnimation.js +0 -30
- package/umd/Options/Classes/Options.js +0 -171
- package/umd/Options/Classes/OptionsColor.js +0 -42
- package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +0 -31
- package/umd/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -21
- package/umd/Options/Classes/Particles/Effect/Effect.js +0 -46
- package/umd/Options/Classes/Particles/Fill.js +0 -42
- package/umd/Options/Classes/Particles/Move/Move.js +0 -120
- package/umd/Options/Classes/Particles/Move/MoveAngle.js +0 -35
- package/umd/Options/Classes/Particles/Move/MoveCenter.js +0 -45
- package/umd/Options/Classes/Particles/Move/MoveGravity.js +0 -45
- package/umd/Options/Classes/Particles/Move/OutModes.js +0 -38
- package/umd/Options/Classes/Particles/Move/Path/MovePath.js +0 -46
- package/umd/Options/Classes/Particles/Move/Spin.js +0 -40
- package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +0 -41
- package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +0 -37
- package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +0 -35
- package/umd/Options/Classes/Particles/Opacity/Opacity.js +0 -35
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -34
- package/umd/Options/Classes/Particles/ParticlesOptions.js +0 -116
- package/umd/Options/Classes/Particles/Shape/Shape.js +0 -46
- package/umd/Options/Classes/Particles/Size/Size.js +0 -35
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +0 -34
- package/umd/Options/Classes/Particles/Stroke.js +0 -39
- package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +0 -42
- package/umd/Options/Classes/ResizeEvent.js +0 -34
- package/umd/Options/Classes/ValueWithRandom.js +0 -56
- package/umd/Options/Interfaces/Background/IBackground.js +0 -12
- package/umd/Options/Interfaces/FullScreen/IFullScreen.js +0 -12
- package/umd/Options/Interfaces/IAnimatable.js +0 -12
- package/umd/Options/Interfaces/IAnimatableColor.js +0 -12
- package/umd/Options/Interfaces/IAnimation.js +0 -12
- package/umd/Options/Interfaces/IColorAnimation.js +0 -12
- package/umd/Options/Interfaces/IHslAnimation.js +0 -12
- package/umd/Options/Interfaces/IOptionLoader.js +0 -12
- package/umd/Options/Interfaces/IOptions.js +0 -12
- package/umd/Options/Interfaces/IOptionsColor.js +0 -12
- package/umd/Options/Interfaces/IResizeEvent.js +0 -12
- package/umd/Options/Interfaces/IValueWithRandom.js +0 -12
- package/umd/Options/Interfaces/Particles/Bounce/IParticlesBounce.js +0 -12
- package/umd/Options/Interfaces/Particles/Effect/IEffect.js +0 -12
- package/umd/Options/Interfaces/Particles/IFill.js +0 -12
- package/umd/Options/Interfaces/Particles/IParticlesOptions.js +0 -12
- package/umd/Options/Interfaces/Particles/IStroke.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IMove.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IMoveAngle.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IMoveCenter.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IMoveGravity.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/IOutModes.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/ISpin.js +0 -12
- package/umd/Options/Interfaces/Particles/Move/Path/IMovePath.js +0 -12
- package/umd/Options/Interfaces/Particles/Number/IParticlesDensity.js +0 -12
- package/umd/Options/Interfaces/Particles/Number/IParticlesNumber.js +0 -12
- package/umd/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +0 -12
- package/umd/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -12
- package/umd/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/IShape.js +0 -12
- package/umd/Options/Interfaces/Particles/Size/ISize.js +0 -12
- package/umd/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -12
- package/umd/Options/Interfaces/Particles/ZIndex/IZIndex.js +0 -12
- package/umd/Types/CanvasContextType.js +0 -12
- package/umd/Types/CustomEventArgs.js +0 -12
- package/umd/Types/CustomEventListener.js +0 -12
- package/umd/Types/EasingFunction.js +0 -12
- package/umd/Types/EngineInitializers.js +0 -12
- package/umd/Types/ExportResult.js +0 -12
- package/umd/Types/ISourceOptions.js +0 -12
- package/umd/Types/ParticlesGroups.js +0 -12
- package/umd/Types/PathOptions.js +0 -12
- package/umd/Types/RangeValue.js +0 -12
- package/umd/Types/RecursivePartial.js +0 -12
- package/umd/Types/ShapeData.js +0 -12
- package/umd/Types/SingleOrMultiple.js +0 -12
- package/umd/Utils/CanvasUtils.js +0 -145
- package/umd/Utils/ColorUtils.js +0 -395
- package/umd/Utils/EventDispatcher.js +0 -63
- package/umd/Utils/LogUtils.js +0 -37
- package/umd/Utils/MathUtils.js +0 -203
- package/umd/Utils/OptionsUtils.js +0 -25
- package/umd/Utils/TypeUtils.js +0 -40
- package/umd/Utils/Utils.js +0 -484
- package/umd/bundle.js +0 -32
- package/umd/export-types.js +0 -12
- package/umd/exports.js +0 -82
- package/umd/index.js +0 -32
- package/umd/initEngine.js +0 -17
package/browser/Core/Engine.js
CHANGED
|
@@ -134,20 +134,7 @@ export class Options {
|
|
|
134
134
|
mode: paletteData.blendMode,
|
|
135
135
|
},
|
|
136
136
|
particles: {
|
|
137
|
-
|
|
138
|
-
color: paletteData.fill
|
|
139
|
-
? {
|
|
140
|
-
value: paletteData.colors,
|
|
141
|
-
}
|
|
142
|
-
: undefined,
|
|
143
|
-
enable: paletteData.fill,
|
|
144
|
-
},
|
|
145
|
-
stroke: !paletteData.fill
|
|
146
|
-
? paletteData.colors.map(color => ({
|
|
147
|
-
color: { value: color },
|
|
148
|
-
width: 1,
|
|
149
|
-
}))
|
|
150
|
-
: undefined,
|
|
137
|
+
palette,
|
|
151
138
|
},
|
|
152
139
|
});
|
|
153
140
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fill } from "./Fill.js";
|
|
2
|
+
import { Stroke } from "./Stroke.js";
|
|
3
|
+
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
4
|
+
export class Paint {
|
|
5
|
+
fill;
|
|
6
|
+
stroke;
|
|
7
|
+
load(data) {
|
|
8
|
+
if (isNull(data)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.fill !== undefined) {
|
|
12
|
+
this.fill ??= new Fill();
|
|
13
|
+
this.fill.load(data.fill);
|
|
14
|
+
}
|
|
15
|
+
if (data.stroke !== undefined) {
|
|
16
|
+
this.stroke ??= new Stroke();
|
|
17
|
+
this.stroke.load(data.stroke);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { deepExtend, executeOnSingleOrMultiple } from "../../../Utils/Utils.js";
|
|
2
|
+
import { isArray, isNull } from "../../../Utils/TypeUtils.js";
|
|
2
3
|
import { Effect } from "./Effect/Effect.js";
|
|
3
|
-
import { Fill } from "./Fill.js";
|
|
4
4
|
import { Move } from "./Move/Move.js";
|
|
5
5
|
import { Opacity } from "./Opacity/Opacity.js";
|
|
6
|
+
import { Paint } from "./Paint.js";
|
|
6
7
|
import { ParticlesBounce } from "./Bounce/ParticlesBounce.js";
|
|
7
8
|
import { ParticlesNumber } from "./Number/ParticlesNumber.js";
|
|
8
9
|
import { Shape } from "./Shape/Shape.js";
|
|
9
10
|
import { Size } from "./Size/Size.js";
|
|
10
|
-
import { Stroke } from "./Stroke.js";
|
|
11
11
|
import { ZIndex } from "./ZIndex/ZIndex.js";
|
|
12
|
-
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
13
12
|
export class ParticlesOptions {
|
|
14
13
|
bounce;
|
|
15
14
|
effect;
|
|
16
|
-
fill;
|
|
17
15
|
groups;
|
|
18
16
|
move;
|
|
19
17
|
number;
|
|
20
18
|
opacity;
|
|
19
|
+
paint;
|
|
20
|
+
palette;
|
|
21
21
|
reduceDuplicates;
|
|
22
22
|
shape;
|
|
23
23
|
size;
|
|
24
|
-
stroke;
|
|
25
24
|
zIndex;
|
|
26
25
|
_container;
|
|
27
26
|
_pluginManager;
|
|
@@ -30,21 +29,24 @@ export class ParticlesOptions {
|
|
|
30
29
|
this._container = container;
|
|
31
30
|
this.bounce = new ParticlesBounce();
|
|
32
31
|
this.effect = new Effect();
|
|
33
|
-
this.fill = new Fill();
|
|
34
32
|
this.groups = {};
|
|
35
33
|
this.move = new Move();
|
|
36
34
|
this.number = new ParticlesNumber();
|
|
37
35
|
this.opacity = new Opacity();
|
|
36
|
+
this.paint = new Paint();
|
|
38
37
|
this.reduceDuplicates = false;
|
|
39
38
|
this.shape = new Shape();
|
|
40
39
|
this.size = new Size();
|
|
41
|
-
this.stroke = new Stroke();
|
|
42
40
|
this.zIndex = new ZIndex();
|
|
43
41
|
}
|
|
44
42
|
load(data) {
|
|
45
43
|
if (isNull(data)) {
|
|
46
44
|
return;
|
|
47
45
|
}
|
|
46
|
+
if (data.palette) {
|
|
47
|
+
this.palette = data.palette;
|
|
48
|
+
this._importPalette(this.palette);
|
|
49
|
+
}
|
|
48
50
|
if (data.groups !== undefined) {
|
|
49
51
|
for (const group of Object.keys(data.groups)) {
|
|
50
52
|
if (!(group in data.groups)) {
|
|
@@ -64,25 +66,17 @@ export class ParticlesOptions {
|
|
|
64
66
|
this.move.load(data.move);
|
|
65
67
|
this.number.load(data.number);
|
|
66
68
|
this.opacity.load(data.opacity);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (fillToLoad) {
|
|
72
|
-
this.fill = executeOnSingleOrMultiple(fillToLoad, t => {
|
|
73
|
-
const tmp = new Fill();
|
|
74
|
-
tmp.load(t);
|
|
75
|
-
return tmp;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const strokeToLoad = data.stroke;
|
|
79
|
-
if (strokeToLoad) {
|
|
80
|
-
this.stroke = executeOnSingleOrMultiple(strokeToLoad, t => {
|
|
81
|
-
const tmp = new Stroke();
|
|
69
|
+
const paintToLoad = data.paint;
|
|
70
|
+
if (paintToLoad) {
|
|
71
|
+
this.paint = executeOnSingleOrMultiple(paintToLoad, t => {
|
|
72
|
+
const tmp = new Paint();
|
|
82
73
|
tmp.load(t);
|
|
83
74
|
return tmp;
|
|
84
75
|
});
|
|
85
76
|
}
|
|
77
|
+
this.shape.load(data.shape);
|
|
78
|
+
this.size.load(data.size);
|
|
79
|
+
this.zIndex.load(data.zIndex);
|
|
86
80
|
if (this._container) {
|
|
87
81
|
for (const plugin of this._pluginManager.plugins) {
|
|
88
82
|
if (plugin.loadParticlesOptions) {
|
|
@@ -99,4 +93,48 @@ export class ParticlesOptions {
|
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
95
|
}
|
|
96
|
+
_importPalette = (palette) => {
|
|
97
|
+
const paletteData = this._pluginManager.getPalette(palette);
|
|
98
|
+
if (!paletteData) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const paletteColors = paletteData.colors, paletteFill = paletteColors.fill, paletteStroke = paletteColors.stroke, defaultPaintStrokeIndex = 0, defaultPaintStrokeWidth = 0, palettePaint = {
|
|
102
|
+
fill: paletteFill
|
|
103
|
+
? {
|
|
104
|
+
color: {
|
|
105
|
+
value: paletteFill.value,
|
|
106
|
+
},
|
|
107
|
+
enable: paletteFill.enable,
|
|
108
|
+
}
|
|
109
|
+
: undefined,
|
|
110
|
+
};
|
|
111
|
+
if (paletteStroke) {
|
|
112
|
+
if (isArray(paletteStroke)) {
|
|
113
|
+
const firstStroke = paletteStroke[defaultPaintStrokeIndex];
|
|
114
|
+
if (firstStroke) {
|
|
115
|
+
palettePaint.stroke = {
|
|
116
|
+
color: {
|
|
117
|
+
value: firstStroke.value,
|
|
118
|
+
},
|
|
119
|
+
width: firstStroke.width || defaultPaintStrokeWidth,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
palettePaint.stroke = {
|
|
125
|
+
color: {
|
|
126
|
+
value: paletteStroke.value,
|
|
127
|
+
},
|
|
128
|
+
width: paletteStroke.width,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.load({
|
|
133
|
+
paint: palettePaint,
|
|
134
|
+
blend: {
|
|
135
|
+
enable: true,
|
|
136
|
+
mode: paletteData.blendMode,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
};
|
|
102
140
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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/browser/Utils/Utils.js
CHANGED
|
@@ -326,6 +326,19 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
|
|
|
326
326
|
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
327
327
|
return;
|
|
328
328
|
}
|
|
329
|
+
switch (data.status) {
|
|
330
|
+
case AnimationStatus.increasing:
|
|
331
|
+
data.value += velocity;
|
|
332
|
+
break;
|
|
333
|
+
case AnimationStatus.decreasing:
|
|
334
|
+
data.value -= velocity;
|
|
335
|
+
break;
|
|
336
|
+
default:
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
if (data.velocity && decay !== identity) {
|
|
340
|
+
data.velocity *= decay;
|
|
341
|
+
}
|
|
329
342
|
switch (data.status) {
|
|
330
343
|
case AnimationStatus.increasing:
|
|
331
344
|
if (data.value >= maxValue) {
|
|
@@ -338,9 +351,6 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
|
|
|
338
351
|
data.loops ??= minLoops;
|
|
339
352
|
data.loops++;
|
|
340
353
|
}
|
|
341
|
-
else {
|
|
342
|
-
data.value += velocity;
|
|
343
|
-
}
|
|
344
354
|
break;
|
|
345
355
|
case AnimationStatus.decreasing:
|
|
346
356
|
if (data.value <= minValue) {
|
|
@@ -353,18 +363,14 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
|
|
|
353
363
|
data.loops ??= minLoops;
|
|
354
364
|
data.loops++;
|
|
355
365
|
}
|
|
356
|
-
else {
|
|
357
|
-
data.value -= velocity;
|
|
358
|
-
}
|
|
359
366
|
break;
|
|
360
367
|
default:
|
|
361
368
|
break;
|
|
362
369
|
}
|
|
363
|
-
if (data.velocity && decay !== identity) {
|
|
364
|
-
data.velocity *= decay;
|
|
365
|
-
}
|
|
366
370
|
checkDestroy(particle, destroyType, data.value, minValue, maxValue);
|
|
367
|
-
|
|
371
|
+
if (!particle.destroyed) {
|
|
372
|
+
data.value = clamp(data.value, minValue, maxValue);
|
|
373
|
+
}
|
|
368
374
|
}
|
|
369
375
|
export function cloneStyle(style) {
|
|
370
376
|
const clonedStyle = safeDocument().createElement("div").style;
|
package/browser/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/cjs/Core/Engine.js
CHANGED
|
@@ -134,20 +134,7 @@ export class Options {
|
|
|
134
134
|
mode: paletteData.blendMode,
|
|
135
135
|
},
|
|
136
136
|
particles: {
|
|
137
|
-
|
|
138
|
-
color: paletteData.fill
|
|
139
|
-
? {
|
|
140
|
-
value: paletteData.colors,
|
|
141
|
-
}
|
|
142
|
-
: undefined,
|
|
143
|
-
enable: paletteData.fill,
|
|
144
|
-
},
|
|
145
|
-
stroke: !paletteData.fill
|
|
146
|
-
? paletteData.colors.map(color => ({
|
|
147
|
-
color: { value: color },
|
|
148
|
-
width: 1,
|
|
149
|
-
}))
|
|
150
|
-
: undefined,
|
|
137
|
+
palette,
|
|
151
138
|
},
|
|
152
139
|
});
|
|
153
140
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fill } from "./Fill.js";
|
|
2
|
+
import { Stroke } from "./Stroke.js";
|
|
3
|
+
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
4
|
+
export class Paint {
|
|
5
|
+
fill;
|
|
6
|
+
stroke;
|
|
7
|
+
load(data) {
|
|
8
|
+
if (isNull(data)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.fill !== undefined) {
|
|
12
|
+
this.fill ??= new Fill();
|
|
13
|
+
this.fill.load(data.fill);
|
|
14
|
+
}
|
|
15
|
+
if (data.stroke !== undefined) {
|
|
16
|
+
this.stroke ??= new Stroke();
|
|
17
|
+
this.stroke.load(data.stroke);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { deepExtend, executeOnSingleOrMultiple } from "../../../Utils/Utils.js";
|
|
2
|
+
import { isArray, isNull } from "../../../Utils/TypeUtils.js";
|
|
2
3
|
import { Effect } from "./Effect/Effect.js";
|
|
3
|
-
import { Fill } from "./Fill.js";
|
|
4
4
|
import { Move } from "./Move/Move.js";
|
|
5
5
|
import { Opacity } from "./Opacity/Opacity.js";
|
|
6
|
+
import { Paint } from "./Paint.js";
|
|
6
7
|
import { ParticlesBounce } from "./Bounce/ParticlesBounce.js";
|
|
7
8
|
import { ParticlesNumber } from "./Number/ParticlesNumber.js";
|
|
8
9
|
import { Shape } from "./Shape/Shape.js";
|
|
9
10
|
import { Size } from "./Size/Size.js";
|
|
10
|
-
import { Stroke } from "./Stroke.js";
|
|
11
11
|
import { ZIndex } from "./ZIndex/ZIndex.js";
|
|
12
|
-
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
13
12
|
export class ParticlesOptions {
|
|
14
13
|
bounce;
|
|
15
14
|
effect;
|
|
16
|
-
fill;
|
|
17
15
|
groups;
|
|
18
16
|
move;
|
|
19
17
|
number;
|
|
20
18
|
opacity;
|
|
19
|
+
paint;
|
|
20
|
+
palette;
|
|
21
21
|
reduceDuplicates;
|
|
22
22
|
shape;
|
|
23
23
|
size;
|
|
24
|
-
stroke;
|
|
25
24
|
zIndex;
|
|
26
25
|
_container;
|
|
27
26
|
_pluginManager;
|
|
@@ -30,21 +29,24 @@ export class ParticlesOptions {
|
|
|
30
29
|
this._container = container;
|
|
31
30
|
this.bounce = new ParticlesBounce();
|
|
32
31
|
this.effect = new Effect();
|
|
33
|
-
this.fill = new Fill();
|
|
34
32
|
this.groups = {};
|
|
35
33
|
this.move = new Move();
|
|
36
34
|
this.number = new ParticlesNumber();
|
|
37
35
|
this.opacity = new Opacity();
|
|
36
|
+
this.paint = new Paint();
|
|
38
37
|
this.reduceDuplicates = false;
|
|
39
38
|
this.shape = new Shape();
|
|
40
39
|
this.size = new Size();
|
|
41
|
-
this.stroke = new Stroke();
|
|
42
40
|
this.zIndex = new ZIndex();
|
|
43
41
|
}
|
|
44
42
|
load(data) {
|
|
45
43
|
if (isNull(data)) {
|
|
46
44
|
return;
|
|
47
45
|
}
|
|
46
|
+
if (data.palette) {
|
|
47
|
+
this.palette = data.palette;
|
|
48
|
+
this._importPalette(this.palette);
|
|
49
|
+
}
|
|
48
50
|
if (data.groups !== undefined) {
|
|
49
51
|
for (const group of Object.keys(data.groups)) {
|
|
50
52
|
if (!(group in data.groups)) {
|
|
@@ -64,25 +66,17 @@ export class ParticlesOptions {
|
|
|
64
66
|
this.move.load(data.move);
|
|
65
67
|
this.number.load(data.number);
|
|
66
68
|
this.opacity.load(data.opacity);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (fillToLoad) {
|
|
72
|
-
this.fill = executeOnSingleOrMultiple(fillToLoad, t => {
|
|
73
|
-
const tmp = new Fill();
|
|
74
|
-
tmp.load(t);
|
|
75
|
-
return tmp;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const strokeToLoad = data.stroke;
|
|
79
|
-
if (strokeToLoad) {
|
|
80
|
-
this.stroke = executeOnSingleOrMultiple(strokeToLoad, t => {
|
|
81
|
-
const tmp = new Stroke();
|
|
69
|
+
const paintToLoad = data.paint;
|
|
70
|
+
if (paintToLoad) {
|
|
71
|
+
this.paint = executeOnSingleOrMultiple(paintToLoad, t => {
|
|
72
|
+
const tmp = new Paint();
|
|
82
73
|
tmp.load(t);
|
|
83
74
|
return tmp;
|
|
84
75
|
});
|
|
85
76
|
}
|
|
77
|
+
this.shape.load(data.shape);
|
|
78
|
+
this.size.load(data.size);
|
|
79
|
+
this.zIndex.load(data.zIndex);
|
|
86
80
|
if (this._container) {
|
|
87
81
|
for (const plugin of this._pluginManager.plugins) {
|
|
88
82
|
if (plugin.loadParticlesOptions) {
|
|
@@ -99,4 +93,48 @@ export class ParticlesOptions {
|
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
95
|
}
|
|
96
|
+
_importPalette = (palette) => {
|
|
97
|
+
const paletteData = this._pluginManager.getPalette(palette);
|
|
98
|
+
if (!paletteData) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const paletteColors = paletteData.colors, paletteFill = paletteColors.fill, paletteStroke = paletteColors.stroke, defaultPaintStrokeIndex = 0, defaultPaintStrokeWidth = 0, palettePaint = {
|
|
102
|
+
fill: paletteFill
|
|
103
|
+
? {
|
|
104
|
+
color: {
|
|
105
|
+
value: paletteFill.value,
|
|
106
|
+
},
|
|
107
|
+
enable: paletteFill.enable,
|
|
108
|
+
}
|
|
109
|
+
: undefined,
|
|
110
|
+
};
|
|
111
|
+
if (paletteStroke) {
|
|
112
|
+
if (isArray(paletteStroke)) {
|
|
113
|
+
const firstStroke = paletteStroke[defaultPaintStrokeIndex];
|
|
114
|
+
if (firstStroke) {
|
|
115
|
+
palettePaint.stroke = {
|
|
116
|
+
color: {
|
|
117
|
+
value: firstStroke.value,
|
|
118
|
+
},
|
|
119
|
+
width: firstStroke.width || defaultPaintStrokeWidth,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
palettePaint.stroke = {
|
|
125
|
+
color: {
|
|
126
|
+
value: paletteStroke.value,
|
|
127
|
+
},
|
|
128
|
+
width: paletteStroke.width,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.load({
|
|
133
|
+
paint: palettePaint,
|
|
134
|
+
blend: {
|
|
135
|
+
enable: true,
|
|
136
|
+
mode: paletteData.blendMode,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
};
|
|
102
140
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/cjs/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/cjs/Utils/Utils.js
CHANGED
|
@@ -326,6 +326,19 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
|
|
|
326
326
|
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
327
327
|
return;
|
|
328
328
|
}
|
|
329
|
+
switch (data.status) {
|
|
330
|
+
case AnimationStatus.increasing:
|
|
331
|
+
data.value += velocity;
|
|
332
|
+
break;
|
|
333
|
+
case AnimationStatus.decreasing:
|
|
334
|
+
data.value -= velocity;
|
|
335
|
+
break;
|
|
336
|
+
default:
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
if (data.velocity && decay !== identity) {
|
|
340
|
+
data.velocity *= decay;
|
|
341
|
+
}
|
|
329
342
|
switch (data.status) {
|
|
330
343
|
case AnimationStatus.increasing:
|
|
331
344
|
if (data.value >= maxValue) {
|
|
@@ -338,9 +351,6 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
|
|
|
338
351
|
data.loops ??= minLoops;
|
|
339
352
|
data.loops++;
|
|
340
353
|
}
|
|
341
|
-
else {
|
|
342
|
-
data.value += velocity;
|
|
343
|
-
}
|
|
344
354
|
break;
|
|
345
355
|
case AnimationStatus.decreasing:
|
|
346
356
|
if (data.value <= minValue) {
|
|
@@ -353,18 +363,14 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
|
|
|
353
363
|
data.loops ??= minLoops;
|
|
354
364
|
data.loops++;
|
|
355
365
|
}
|
|
356
|
-
else {
|
|
357
|
-
data.value -= velocity;
|
|
358
|
-
}
|
|
359
366
|
break;
|
|
360
367
|
default:
|
|
361
368
|
break;
|
|
362
369
|
}
|
|
363
|
-
if (data.velocity && decay !== identity) {
|
|
364
|
-
data.velocity *= decay;
|
|
365
|
-
}
|
|
366
370
|
checkDestroy(particle, destroyType, data.value, minValue, maxValue);
|
|
367
|
-
|
|
371
|
+
if (!particle.destroyed) {
|
|
372
|
+
data.value = clamp(data.value, minValue, maxValue);
|
|
373
|
+
}
|
|
368
374
|
}
|
|
369
375
|
export function cloneStyle(style) {
|
|
370
376
|
const clonedStyle = safeDocument().createElement("div").style;
|
package/cjs/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/Core/Engine.js
CHANGED
|
@@ -134,20 +134,7 @@ export class Options {
|
|
|
134
134
|
mode: paletteData.blendMode,
|
|
135
135
|
},
|
|
136
136
|
particles: {
|
|
137
|
-
|
|
138
|
-
color: paletteData.fill
|
|
139
|
-
? {
|
|
140
|
-
value: paletteData.colors,
|
|
141
|
-
}
|
|
142
|
-
: undefined,
|
|
143
|
-
enable: paletteData.fill,
|
|
144
|
-
},
|
|
145
|
-
stroke: !paletteData.fill
|
|
146
|
-
? paletteData.colors.map(color => ({
|
|
147
|
-
color: { value: color },
|
|
148
|
-
width: 1,
|
|
149
|
-
}))
|
|
150
|
-
: undefined,
|
|
137
|
+
palette,
|
|
151
138
|
},
|
|
152
139
|
});
|
|
153
140
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Fill } from "./Fill.js";
|
|
2
|
+
import { Stroke } from "./Stroke.js";
|
|
3
|
+
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
4
|
+
export class Paint {
|
|
5
|
+
fill;
|
|
6
|
+
stroke;
|
|
7
|
+
load(data) {
|
|
8
|
+
if (isNull(data)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.fill !== undefined) {
|
|
12
|
+
this.fill ??= new Fill();
|
|
13
|
+
this.fill.load(data.fill);
|
|
14
|
+
}
|
|
15
|
+
if (data.stroke !== undefined) {
|
|
16
|
+
this.stroke ??= new Stroke();
|
|
17
|
+
this.stroke.load(data.stroke);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|