@tsparticles/engine 4.0.0-beta.0 → 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 -965
- package/browser/Core/CanvasManager.js +303 -0
- package/browser/Core/Container.js +61 -34
- package/browser/Core/Engine.js +26 -138
- package/browser/Core/Particle.js +29 -28
- package/{cjs/Core/Particles.js → browser/Core/ParticlesManager.js} +27 -57
- package/browser/Core/RenderManager.js +303 -0
- package/browser/Core/Retina.js +3 -8
- package/browser/Core/Utils/PluginManager.js +145 -0
- package/browser/Options/Classes/Options.js +8 -21
- package/browser/Options/Classes/Particles/Paint.js +20 -0
- package/browser/Options/Classes/Particles/ParticlesOptions.js +65 -27
- package/browser/Options/Interfaces/Particles/IPaint.js +1 -0
- package/browser/Types/CanvasContextType.js +1 -0
- package/browser/Utils/CanvasUtils.js +4 -4
- package/browser/Utils/ColorUtils.js +21 -21
- package/browser/Utils/LogUtils.js +1 -0
- package/browser/Utils/OptionsUtils.js +2 -2
- package/browser/Utils/Utils.js +16 -10
- package/browser/exports.js +1 -0
- package/cjs/Core/CanvasManager.js +303 -0
- package/cjs/Core/Container.js +61 -34
- package/cjs/Core/Engine.js +26 -138
- package/cjs/Core/Particle.js +29 -28
- package/{esm/Core/Particles.js → cjs/Core/ParticlesManager.js} +27 -57
- package/cjs/Core/RenderManager.js +303 -0
- package/cjs/Core/Retina.js +3 -8
- package/cjs/Core/Utils/PluginManager.js +145 -0
- package/cjs/Options/Classes/Options.js +8 -21
- package/cjs/Options/Classes/Particles/Paint.js +20 -0
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +65 -27
- package/cjs/Options/Interfaces/Particles/IPaint.js +1 -0
- package/cjs/Types/CanvasContextType.js +1 -0
- package/cjs/Utils/CanvasUtils.js +4 -4
- package/cjs/Utils/ColorUtils.js +21 -21
- package/cjs/Utils/LogUtils.js +1 -0
- package/cjs/Utils/OptionsUtils.js +2 -2
- package/cjs/Utils/Utils.js +16 -10
- package/cjs/exports.js +1 -0
- package/dist_browser_Core_Container_js.js +24 -14
- package/esm/Core/CanvasManager.js +303 -0
- package/esm/Core/Container.js +61 -34
- package/esm/Core/Engine.js +26 -138
- package/esm/Core/Particle.js +29 -28
- package/{browser/Core/Particles.js → esm/Core/ParticlesManager.js} +27 -57
- package/esm/Core/RenderManager.js +303 -0
- package/esm/Core/Retina.js +3 -8
- package/esm/Core/Utils/PluginManager.js +145 -0
- package/esm/Options/Classes/Options.js +8 -21
- package/esm/Options/Classes/Particles/Paint.js +20 -0
- package/esm/Options/Classes/Particles/ParticlesOptions.js +65 -27
- package/esm/Options/Interfaces/Particles/IPaint.js +1 -0
- package/esm/Types/CanvasContextType.js +1 -0
- package/esm/Utils/CanvasUtils.js +4 -4
- package/esm/Utils/ColorUtils.js +21 -21
- package/esm/Utils/LogUtils.js +1 -0
- package/esm/Utils/OptionsUtils.js +2 -2
- package/esm/Utils/Utils.js +16 -10
- package/esm/exports.js +1 -0
- package/package.json +2 -3
- package/report.html +84 -29
- package/tsparticles.engine.js +31 -11
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/CanvasManager.d.ts +39 -0
- package/types/Core/Container.d.ts +26 -7
- package/types/Core/Engine.d.ts +2 -54
- package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -7
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
- package/types/Core/Interfaces/IPalette.d.ts +15 -2
- package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
- package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -1
- package/types/Core/Particle.d.ts +4 -4
- package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +4 -11
- package/types/Core/{Canvas.d.ts → RenderManager.d.ts} +12 -33
- package/types/Core/Retina.d.ts +0 -2
- package/types/Core/Utils/PluginManager.d.ts +62 -0
- package/types/Options/Classes/Options.d.ts +3 -3
- package/types/Options/Classes/Particles/Paint.d.ts +10 -0
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +7 -7
- package/types/Options/Interfaces/Particles/IPaint.d.ts +6 -0
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +3 -4
- package/types/Types/CanvasContextType.d.ts +1 -0
- package/types/Utils/CanvasUtils.d.ts +8 -5
- package/types/Utils/ColorUtils.d.ts +8 -8
- package/types/Utils/LogUtils.d.ts +1 -0
- package/types/Utils/OptionsUtils.d.ts +2 -2
- package/types/export-types.d.ts +5 -2
- package/types/exports.d.ts +1 -0
- package/164.min.js +0 -1
- package/browser/Core/Canvas.js +0 -570
- package/cjs/Core/Canvas.js +0 -570
- package/esm/Core/Canvas.js +0 -570
- package/umd/Core/Canvas.js +0 -584
- package/umd/Core/Container.js +0 -356
- package/umd/Core/Engine.js +0 -295
- 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 -432
- package/umd/Core/Particles.js +0 -407
- package/umd/Core/Retina.js +0 -52
- package/umd/Core/Utils/Constants.js +0 -23
- package/umd/Core/Utils/EventListeners.js +0 -102
- 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/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 -36
- 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
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { clear, drawParticle, drawParticlePlugin, paintBase, paintImage } from "../Utils/CanvasUtils.js";
|
|
2
|
+
import { defaultCompositeValue, defaultTransformValue, minimumSize, zIndexFactorOffset } from "./Utils/Constants.js";
|
|
3
|
+
import { getStyleFromHsl, rangeColorToHsl } from "../Utils/ColorUtils.js";
|
|
4
|
+
const fColorIndex = 0, sColorIndex = 1;
|
|
5
|
+
function setTransformValue(factor, newFactor, key) {
|
|
6
|
+
const newValue = newFactor[key];
|
|
7
|
+
if (newValue !== undefined) {
|
|
8
|
+
factor[key] = (factor[key] ?? defaultTransformValue) * newValue;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class RenderManager {
|
|
12
|
+
_canvasClearPlugins;
|
|
13
|
+
_canvasManager;
|
|
14
|
+
_canvasPaintPlugins;
|
|
15
|
+
_clearDrawPlugins;
|
|
16
|
+
_colorPlugins;
|
|
17
|
+
_container;
|
|
18
|
+
_context;
|
|
19
|
+
_contextSettings;
|
|
20
|
+
_drawParticlePlugins;
|
|
21
|
+
_drawParticlesCleanupPlugins;
|
|
22
|
+
_drawParticlesSetupPlugins;
|
|
23
|
+
_drawPlugins;
|
|
24
|
+
_drawSettingsCleanupPlugins;
|
|
25
|
+
_drawSettingsSetupPlugins;
|
|
26
|
+
_pluginManager;
|
|
27
|
+
_postDrawUpdaters;
|
|
28
|
+
_preDrawUpdaters;
|
|
29
|
+
_reusableColorStyles = {};
|
|
30
|
+
_reusablePluginColors = [undefined, undefined];
|
|
31
|
+
_reusableTransform = {};
|
|
32
|
+
constructor(pluginManager, container, canvasManager) {
|
|
33
|
+
this._pluginManager = pluginManager;
|
|
34
|
+
this._container = container;
|
|
35
|
+
this._canvasManager = canvasManager;
|
|
36
|
+
this._context = null;
|
|
37
|
+
this._preDrawUpdaters = [];
|
|
38
|
+
this._postDrawUpdaters = [];
|
|
39
|
+
this._colorPlugins = [];
|
|
40
|
+
this._canvasClearPlugins = [];
|
|
41
|
+
this._canvasPaintPlugins = [];
|
|
42
|
+
this._clearDrawPlugins = [];
|
|
43
|
+
this._drawParticlePlugins = [];
|
|
44
|
+
this._drawParticlesCleanupPlugins = [];
|
|
45
|
+
this._drawParticlesSetupPlugins = [];
|
|
46
|
+
this._drawPlugins = [];
|
|
47
|
+
this._drawSettingsSetupPlugins = [];
|
|
48
|
+
this._drawSettingsCleanupPlugins = [];
|
|
49
|
+
}
|
|
50
|
+
get settings() {
|
|
51
|
+
return this._contextSettings;
|
|
52
|
+
}
|
|
53
|
+
canvasClear() {
|
|
54
|
+
if (!this._container.actualOptions.clear) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.draw(ctx => {
|
|
58
|
+
clear(ctx, this._canvasManager.size);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
clear() {
|
|
62
|
+
let pluginHandled = false;
|
|
63
|
+
for (const plugin of this._canvasClearPlugins) {
|
|
64
|
+
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
65
|
+
if (pluginHandled) {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (pluginHandled) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.canvasClear();
|
|
73
|
+
}
|
|
74
|
+
destroy() {
|
|
75
|
+
this.stop();
|
|
76
|
+
this._preDrawUpdaters = [];
|
|
77
|
+
this._postDrawUpdaters = [];
|
|
78
|
+
this._colorPlugins = [];
|
|
79
|
+
this._canvasClearPlugins = [];
|
|
80
|
+
this._canvasPaintPlugins = [];
|
|
81
|
+
this._clearDrawPlugins = [];
|
|
82
|
+
this._drawParticlePlugins = [];
|
|
83
|
+
this._drawParticlesCleanupPlugins = [];
|
|
84
|
+
this._drawParticlesSetupPlugins = [];
|
|
85
|
+
this._drawPlugins = [];
|
|
86
|
+
this._drawSettingsSetupPlugins = [];
|
|
87
|
+
this._drawSettingsCleanupPlugins = [];
|
|
88
|
+
}
|
|
89
|
+
draw(cb) {
|
|
90
|
+
const ctx = this._context;
|
|
91
|
+
if (!ctx) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
return cb(ctx);
|
|
95
|
+
}
|
|
96
|
+
drawParticle(particle, delta) {
|
|
97
|
+
if (particle.spawning || particle.destroyed) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const radius = particle.getRadius();
|
|
101
|
+
if (radius <= minimumSize) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
105
|
+
let [fColor, sColor] = this._getPluginParticleColors(particle);
|
|
106
|
+
fColor ??= pfColor;
|
|
107
|
+
sColor ??= psColor;
|
|
108
|
+
if (!fColor && !sColor) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const container = this._container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity * opacity) : fill;
|
|
112
|
+
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
113
|
+
colorStyles.fill = fill;
|
|
114
|
+
colorStyles.stroke = stroke;
|
|
115
|
+
this.draw((context) => {
|
|
116
|
+
for (const plugin of this._drawParticlesSetupPlugins) {
|
|
117
|
+
plugin.drawParticleSetup?.(context, particle, delta);
|
|
118
|
+
}
|
|
119
|
+
this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
120
|
+
drawParticle({
|
|
121
|
+
container,
|
|
122
|
+
context,
|
|
123
|
+
particle,
|
|
124
|
+
delta,
|
|
125
|
+
colorStyles,
|
|
126
|
+
radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
|
|
127
|
+
opacity: opacity,
|
|
128
|
+
transform,
|
|
129
|
+
});
|
|
130
|
+
this._applyPostDrawUpdaters(particle);
|
|
131
|
+
for (const plugin of this._drawParticlesCleanupPlugins) {
|
|
132
|
+
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
drawParticlePlugins(particle, delta) {
|
|
137
|
+
this.draw(ctx => {
|
|
138
|
+
for (const plugin of this._drawParticlePlugins) {
|
|
139
|
+
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
drawParticles(delta) {
|
|
144
|
+
const { particles } = this._container;
|
|
145
|
+
this.clear();
|
|
146
|
+
particles.update(delta);
|
|
147
|
+
this.draw(ctx => {
|
|
148
|
+
for (const plugin of this._drawSettingsSetupPlugins) {
|
|
149
|
+
plugin.drawSettingsSetup?.(ctx, delta);
|
|
150
|
+
}
|
|
151
|
+
for (const plugin of this._drawPlugins) {
|
|
152
|
+
plugin.draw?.(ctx, delta);
|
|
153
|
+
}
|
|
154
|
+
particles.drawParticles(delta);
|
|
155
|
+
for (const plugin of this._clearDrawPlugins) {
|
|
156
|
+
plugin.clearDraw?.(ctx, delta);
|
|
157
|
+
}
|
|
158
|
+
for (const plugin of this._drawSettingsCleanupPlugins) {
|
|
159
|
+
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
init() {
|
|
164
|
+
this.initUpdaters();
|
|
165
|
+
this.initPlugins();
|
|
166
|
+
this.paint();
|
|
167
|
+
}
|
|
168
|
+
initPlugins() {
|
|
169
|
+
this._colorPlugins = [];
|
|
170
|
+
this._canvasClearPlugins = [];
|
|
171
|
+
this._canvasPaintPlugins = [];
|
|
172
|
+
this._clearDrawPlugins = [];
|
|
173
|
+
this._drawParticlePlugins = [];
|
|
174
|
+
this._drawParticlesSetupPlugins = [];
|
|
175
|
+
this._drawParticlesCleanupPlugins = [];
|
|
176
|
+
this._drawPlugins = [];
|
|
177
|
+
this._drawSettingsSetupPlugins = [];
|
|
178
|
+
this._drawSettingsCleanupPlugins = [];
|
|
179
|
+
for (const plugin of this._container.plugins) {
|
|
180
|
+
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
181
|
+
this._colorPlugins.push(plugin);
|
|
182
|
+
}
|
|
183
|
+
if (plugin.canvasClear) {
|
|
184
|
+
this._canvasClearPlugins.push(plugin);
|
|
185
|
+
}
|
|
186
|
+
if (plugin.canvasPaint) {
|
|
187
|
+
this._canvasPaintPlugins.push(plugin);
|
|
188
|
+
}
|
|
189
|
+
if (plugin.drawParticle) {
|
|
190
|
+
this._drawParticlePlugins.push(plugin);
|
|
191
|
+
}
|
|
192
|
+
if (plugin.drawParticleSetup) {
|
|
193
|
+
this._drawParticlesSetupPlugins.push(plugin);
|
|
194
|
+
}
|
|
195
|
+
if (plugin.drawParticleCleanup) {
|
|
196
|
+
this._drawParticlesCleanupPlugins.push(plugin);
|
|
197
|
+
}
|
|
198
|
+
if (plugin.draw) {
|
|
199
|
+
this._drawPlugins.push(plugin);
|
|
200
|
+
}
|
|
201
|
+
if (plugin.drawSettingsSetup) {
|
|
202
|
+
this._drawSettingsSetupPlugins.push(plugin);
|
|
203
|
+
}
|
|
204
|
+
if (plugin.drawSettingsCleanup) {
|
|
205
|
+
this._drawSettingsCleanupPlugins.push(plugin);
|
|
206
|
+
}
|
|
207
|
+
if (plugin.clearDraw) {
|
|
208
|
+
this._clearDrawPlugins.push(plugin);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
initUpdaters() {
|
|
213
|
+
this._preDrawUpdaters = [];
|
|
214
|
+
this._postDrawUpdaters = [];
|
|
215
|
+
for (const updater of this._container.particleUpdaters) {
|
|
216
|
+
if (updater.afterDraw) {
|
|
217
|
+
this._postDrawUpdaters.push(updater);
|
|
218
|
+
}
|
|
219
|
+
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
220
|
+
this._preDrawUpdaters.push(updater);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
paint() {
|
|
225
|
+
let handled = false;
|
|
226
|
+
for (const plugin of this._canvasPaintPlugins) {
|
|
227
|
+
handled = plugin.canvasPaint?.() ?? false;
|
|
228
|
+
if (handled) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (handled) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
this.paintBase();
|
|
236
|
+
}
|
|
237
|
+
paintBase(baseColor) {
|
|
238
|
+
this.draw(ctx => {
|
|
239
|
+
paintBase(ctx, this._canvasManager.size, baseColor);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
paintImage(image, opacity) {
|
|
243
|
+
this.draw(ctx => {
|
|
244
|
+
paintImage(ctx, this._canvasManager.size, image, opacity);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
setContext(context) {
|
|
248
|
+
this._context = context;
|
|
249
|
+
if (this._context) {
|
|
250
|
+
this._context.globalCompositeOperation = defaultCompositeValue;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
setContextSettings(settings) {
|
|
254
|
+
this._contextSettings = settings;
|
|
255
|
+
}
|
|
256
|
+
stop() {
|
|
257
|
+
this.draw(ctx => {
|
|
258
|
+
clear(ctx, this._canvasManager.size);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
_applyPostDrawUpdaters = particle => {
|
|
262
|
+
for (const updater of this._postDrawUpdaters) {
|
|
263
|
+
updater.afterDraw?.(particle);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
_applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
267
|
+
for (const updater of this._preDrawUpdaters) {
|
|
268
|
+
if (updater.getColorStyles) {
|
|
269
|
+
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
270
|
+
if (fill) {
|
|
271
|
+
colorStyles.fill = fill;
|
|
272
|
+
}
|
|
273
|
+
if (stroke) {
|
|
274
|
+
colorStyles.stroke = stroke;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (updater.getTransformValues) {
|
|
278
|
+
const updaterTransform = updater.getTransformValues(particle);
|
|
279
|
+
for (const key in updaterTransform) {
|
|
280
|
+
setTransformValue(transform, updaterTransform, key);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
updater.beforeDraw?.(particle);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
_getPluginParticleColors = particle => {
|
|
287
|
+
let fColor, sColor;
|
|
288
|
+
for (const plugin of this._colorPlugins) {
|
|
289
|
+
if (!fColor && plugin.particleFillColor) {
|
|
290
|
+
fColor = rangeColorToHsl(this._pluginManager, plugin.particleFillColor(particle));
|
|
291
|
+
}
|
|
292
|
+
if (!sColor && plugin.particleStrokeColor) {
|
|
293
|
+
sColor = rangeColorToHsl(this._pluginManager, plugin.particleStrokeColor(particle));
|
|
294
|
+
}
|
|
295
|
+
if (fColor && sColor) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
this._reusablePluginColors[fColorIndex] = fColor;
|
|
300
|
+
this._reusablePluginColors[sColorIndex] = sColor;
|
|
301
|
+
return this._reusablePluginColors;
|
|
302
|
+
};
|
|
303
|
+
}
|
package/esm/Core/Retina.js
CHANGED
|
@@ -2,10 +2,8 @@ import { defaultRatio, defaultReduceFactor } from "./Utils/Constants.js";
|
|
|
2
2
|
import { getRangeValue } from "../Utils/MathUtils.js";
|
|
3
3
|
export class Retina {
|
|
4
4
|
container;
|
|
5
|
-
maxSpeed;
|
|
6
5
|
pixelRatio;
|
|
7
6
|
reduceFactor;
|
|
8
|
-
sizeAnimationSpeed;
|
|
9
7
|
constructor(container) {
|
|
10
8
|
this.container = container;
|
|
11
9
|
this.pixelRatio = defaultRatio;
|
|
@@ -21,18 +19,15 @@ export class Retina {
|
|
|
21
19
|
canvas.size.width = element.offsetWidth * ratio;
|
|
22
20
|
canvas.size.height = element.offsetHeight * ratio;
|
|
23
21
|
}
|
|
24
|
-
const particles = options.particles, moveOptions = particles.move;
|
|
25
|
-
this.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
26
|
-
this.sizeAnimationSpeed = getRangeValue(particles.size.animation.speed) * ratio;
|
|
27
22
|
}
|
|
28
23
|
initParticle(particle) {
|
|
29
24
|
const options = particle.options, ratio = this.pixelRatio, moveOptions = options.move, moveDistance = moveOptions.distance, props = particle.retina;
|
|
25
|
+
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
30
26
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
31
27
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
32
28
|
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
33
29
|
const maxDistance = props.maxDistance;
|
|
34
|
-
maxDistance.horizontal = moveDistance.horizontal
|
|
35
|
-
maxDistance.vertical = moveDistance.vertical
|
|
36
|
-
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
30
|
+
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
31
|
+
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
37
32
|
}
|
|
38
33
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { getItemMapFromInitializer, getItemsFromInitializer } from "../../Utils/Utils.js";
|
|
2
|
+
import { EventType } from "../../Enums/Types/EventType.js";
|
|
3
|
+
export class PluginManager {
|
|
4
|
+
colorManagers = new Map();
|
|
5
|
+
easingFunctions = new Map();
|
|
6
|
+
effectDrawers = new Map();
|
|
7
|
+
initializers = {
|
|
8
|
+
effects: new Map(),
|
|
9
|
+
shapes: new Map(),
|
|
10
|
+
updaters: new Map(),
|
|
11
|
+
};
|
|
12
|
+
palettes = new Map();
|
|
13
|
+
plugins = [];
|
|
14
|
+
presets = new Map();
|
|
15
|
+
shapeDrawers = new Map();
|
|
16
|
+
updaters = new Map();
|
|
17
|
+
_allLoadersSet = new Set();
|
|
18
|
+
_configs = new Map();
|
|
19
|
+
_engine;
|
|
20
|
+
_executedSet = new Set();
|
|
21
|
+
_initialized = false;
|
|
22
|
+
_isRunningLoaders = false;
|
|
23
|
+
_loadPromises = new Set();
|
|
24
|
+
constructor(engine) {
|
|
25
|
+
this._engine = engine;
|
|
26
|
+
}
|
|
27
|
+
get configs() {
|
|
28
|
+
const res = {};
|
|
29
|
+
for (const [name, config] of this._configs) {
|
|
30
|
+
res[name] = config;
|
|
31
|
+
}
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
34
|
+
addColorManager(name, manager) {
|
|
35
|
+
this.colorManagers.set(name, manager);
|
|
36
|
+
}
|
|
37
|
+
addConfig(config) {
|
|
38
|
+
const key = config.key ?? config.name ?? "default";
|
|
39
|
+
this._configs.set(key, config);
|
|
40
|
+
this._engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
41
|
+
}
|
|
42
|
+
addEasing(name, easing) {
|
|
43
|
+
if (this.easingFunctions.get(name)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.easingFunctions.set(name, easing);
|
|
47
|
+
}
|
|
48
|
+
addEffect(effect, drawer) {
|
|
49
|
+
this.initializers.effects.set(effect, drawer);
|
|
50
|
+
}
|
|
51
|
+
addPalette(name, palette) {
|
|
52
|
+
this.palettes.set(name, palette);
|
|
53
|
+
}
|
|
54
|
+
addParticleUpdater(name, updaterInitializer) {
|
|
55
|
+
this.initializers.updaters.set(name, updaterInitializer);
|
|
56
|
+
}
|
|
57
|
+
addPlugin(plugin) {
|
|
58
|
+
if (this.getPlugin(plugin.id)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.plugins.push(plugin);
|
|
62
|
+
}
|
|
63
|
+
addPreset(preset, options, override = false) {
|
|
64
|
+
if (!(override || !this.getPreset(preset))) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.presets.set(preset, options);
|
|
68
|
+
}
|
|
69
|
+
addShape(shapes, drawer) {
|
|
70
|
+
for (const shape of shapes) {
|
|
71
|
+
this.initializers.shapes.set(shape, drawer);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
clearPlugins(container) {
|
|
75
|
+
this.effectDrawers.delete(container);
|
|
76
|
+
this.shapeDrawers.delete(container);
|
|
77
|
+
this.updaters.delete(container);
|
|
78
|
+
}
|
|
79
|
+
getEasing(name) {
|
|
80
|
+
return this.easingFunctions.get(name) ?? ((value) => value);
|
|
81
|
+
}
|
|
82
|
+
getEffectDrawers(container, force = false) {
|
|
83
|
+
return getItemMapFromInitializer(container, this.effectDrawers, this.initializers.effects, force);
|
|
84
|
+
}
|
|
85
|
+
getPalette(name) {
|
|
86
|
+
return this.palettes.get(name);
|
|
87
|
+
}
|
|
88
|
+
getPlugin(plugin) {
|
|
89
|
+
return this.plugins.find(t => t.id === plugin);
|
|
90
|
+
}
|
|
91
|
+
getPreset(preset) {
|
|
92
|
+
return this.presets.get(preset);
|
|
93
|
+
}
|
|
94
|
+
async getShapeDrawers(container, force = false) {
|
|
95
|
+
return getItemMapFromInitializer(container, this.shapeDrawers, this.initializers.shapes, force);
|
|
96
|
+
}
|
|
97
|
+
async getUpdaters(container, force = false) {
|
|
98
|
+
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
99
|
+
}
|
|
100
|
+
async init() {
|
|
101
|
+
if (this._initialized || this._isRunningLoaders) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this._isRunningLoaders = true;
|
|
105
|
+
this._executedSet = new Set();
|
|
106
|
+
this._allLoadersSet = new Set(this._loadPromises);
|
|
107
|
+
try {
|
|
108
|
+
for (const loader of this._allLoadersSet) {
|
|
109
|
+
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
this._loadPromises.clear();
|
|
114
|
+
this._isRunningLoaders = false;
|
|
115
|
+
this._initialized = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
119
|
+
const updaters = this.updaters.get(container);
|
|
120
|
+
if (!updaters) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
124
|
+
}
|
|
125
|
+
async register(...loaders) {
|
|
126
|
+
if (this._initialized) {
|
|
127
|
+
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
128
|
+
}
|
|
129
|
+
for (const loader of loaders) {
|
|
130
|
+
if (this._isRunningLoaders) {
|
|
131
|
+
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this._loadPromises.add(loader);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async _runLoader(loader, executed, allLoaders) {
|
|
139
|
+
if (executed.has(loader))
|
|
140
|
+
return;
|
|
141
|
+
executed.add(loader);
|
|
142
|
+
allLoaders.add(loader);
|
|
143
|
+
await loader(this._engine);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -28,9 +28,9 @@ export class Options {
|
|
|
28
28
|
style;
|
|
29
29
|
zLayers;
|
|
30
30
|
_container;
|
|
31
|
-
|
|
32
|
-
constructor(
|
|
33
|
-
this.
|
|
31
|
+
_pluginManager;
|
|
32
|
+
constructor(pluginManager, container) {
|
|
33
|
+
this._pluginManager = pluginManager;
|
|
34
34
|
this._container = container;
|
|
35
35
|
this.autoPlay = true;
|
|
36
36
|
this.background = new Background();
|
|
@@ -42,7 +42,7 @@ export class Options {
|
|
|
42
42
|
this.duration = 0;
|
|
43
43
|
this.fpsLimit = 120;
|
|
44
44
|
this.hdr = true;
|
|
45
|
-
this.particles = loadParticlesOptions(this.
|
|
45
|
+
this.particles = loadParticlesOptions(this._pluginManager, this._container);
|
|
46
46
|
this.pauseOnBlur = true;
|
|
47
47
|
this.pauseOnOutsideViewport = true;
|
|
48
48
|
this.resize = new ResizeEvent();
|
|
@@ -116,12 +116,12 @@ export class Options {
|
|
|
116
116
|
if (data.smooth !== undefined) {
|
|
117
117
|
this.smooth = data.smooth;
|
|
118
118
|
}
|
|
119
|
-
this.
|
|
119
|
+
this._pluginManager.plugins.forEach(plugin => {
|
|
120
120
|
plugin.loadOptions(this._container, this, data);
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
_importPalette = palette => {
|
|
124
|
-
const paletteData = this.
|
|
124
|
+
const paletteData = this._pluginManager.getPalette(palette);
|
|
125
125
|
if (!paletteData) {
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
@@ -134,24 +134,11 @@ 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
|
};
|
|
154
141
|
_importPreset = preset => {
|
|
155
|
-
this.load(this.
|
|
142
|
+
this.load(this._pluginManager.getPreset(preset));
|
|
156
143
|
};
|
|
157
144
|
}
|
|
@@ -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
|
+
}
|