@tsparticles/engine 4.0.0-beta.0 → 4.0.0-beta.2
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/155.min.js +1 -0
- package/README.md +0 -21
- package/browser/Core/CanvasManager.js +303 -0
- package/browser/Core/Container.js +64 -34
- package/browser/Core/Engine.js +26 -138
- package/browser/Core/Interfaces/IPositionFromSizeParams.js +1 -1
- package/browser/Core/Particle.js +29 -28
- package/{cjs/Core/Particles.js → browser/Core/ParticlesManager.js} +28 -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 +7 -7
- package/browser/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/browser/Types/CanvasContextType.js +1 -0
- package/browser/Utils/CanvasUtils.js +1 -1
- package/browser/Utils/ColorUtils.js +21 -21
- package/browser/Utils/LogUtils.js +1 -0
- package/browser/Utils/OptionsUtils.js +2 -2
- package/cjs/Core/CanvasManager.js +303 -0
- package/cjs/Core/Container.js +64 -34
- package/cjs/Core/Engine.js +26 -138
- package/cjs/Core/Interfaces/IPositionFromSizeParams.js +1 -1
- package/cjs/Core/Particle.js +29 -28
- package/{esm/Core/Particles.js → cjs/Core/ParticlesManager.js} +28 -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 +7 -7
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/cjs/Types/CanvasContextType.js +1 -0
- package/cjs/Utils/CanvasUtils.js +1 -1
- package/cjs/Utils/ColorUtils.js +21 -21
- package/cjs/Utils/LogUtils.js +1 -0
- package/cjs/Utils/OptionsUtils.js +2 -2
- package/dist_browser_Core_Container_js.js +24 -14
- package/esm/Core/CanvasManager.js +303 -0
- package/esm/Core/Container.js +64 -34
- package/esm/Core/Engine.js +26 -138
- package/esm/Core/Interfaces/IPositionFromSizeParams.js +1 -1
- package/esm/Core/Particle.js +29 -28
- package/{browser/Core/Particles.js → esm/Core/ParticlesManager.js} +28 -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 +7 -7
- package/esm/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/esm/Types/CanvasContextType.js +1 -0
- package/esm/Utils/CanvasUtils.js +1 -1
- package/esm/Utils/ColorUtils.js +21 -21
- package/esm/Utils/LogUtils.js +1 -0
- package/esm/Utils/OptionsUtils.js +2 -2
- package/package.json +2 -3
- package/report.html +84 -29
- package/tsparticles.engine.js +18 -8
- 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/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/ParticlesOptions.d.ts +3 -3
- 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 +4 -2
- 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
package/browser/Core/Canvas.js
DELETED
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
import { clear, drawParticle, drawParticlePlugin, paintBase, paintImage } from "../Utils/CanvasUtils.js";
|
|
2
|
-
import { cloneStyle, getFullScreenStyle, safeMatchMedia, safeMutationObserver } from "../Utils/Utils.js";
|
|
3
|
-
import { defaultCompositeValue, defaultTransformValue, defaultZoom, generatedAttribute, half, minimumSize, zIndexFactorOffset, } from "./Utils/Constants.js";
|
|
4
|
-
import { getStyleFromHsl, getStyleFromRgb, rangeColorToHsl, rangeColorToRgb } from "../Utils/ColorUtils.js";
|
|
5
|
-
const fColorIndex = 0, sColorIndex = 1;
|
|
6
|
-
function setTransformValue(factor, newFactor, key) {
|
|
7
|
-
const newValue = newFactor[key];
|
|
8
|
-
if (newValue !== undefined) {
|
|
9
|
-
factor[key] = (factor[key] ?? defaultTransformValue) * newValue;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function setStyle(canvas, style, important = false) {
|
|
13
|
-
if (!style) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const element = canvas, elementStyle = element.style, keys = new Set();
|
|
17
|
-
for (let i = 0; i < elementStyle.length; i++) {
|
|
18
|
-
const key = elementStyle.item(i);
|
|
19
|
-
if (!key) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
keys.add(key);
|
|
23
|
-
}
|
|
24
|
-
for (let i = 0; i < style.length; i++) {
|
|
25
|
-
const key = style.item(i);
|
|
26
|
-
if (!key) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
keys.add(key);
|
|
30
|
-
}
|
|
31
|
-
for (const key of keys) {
|
|
32
|
-
const value = style.getPropertyValue(key);
|
|
33
|
-
if (value) {
|
|
34
|
-
elementStyle.setProperty(key, value, important ? "important" : "");
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
elementStyle.removeProperty(key);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export class Canvas {
|
|
42
|
-
container;
|
|
43
|
-
element;
|
|
44
|
-
size;
|
|
45
|
-
zoom = defaultZoom;
|
|
46
|
-
_canvasClearPlugins;
|
|
47
|
-
_canvasPaintPlugins;
|
|
48
|
-
_canvasSettings;
|
|
49
|
-
_clearDrawPlugins;
|
|
50
|
-
_colorPlugins;
|
|
51
|
-
_context;
|
|
52
|
-
_drawParticlePlugins;
|
|
53
|
-
_drawParticlesCleanupPlugins;
|
|
54
|
-
_drawParticlesSetupPlugins;
|
|
55
|
-
_drawPlugins;
|
|
56
|
-
_drawSettingsCleanupPlugins;
|
|
57
|
-
_drawSettingsSetupPlugins;
|
|
58
|
-
_engine;
|
|
59
|
-
_generated;
|
|
60
|
-
_mutationObserver;
|
|
61
|
-
_originalStyle;
|
|
62
|
-
_pointerEvents;
|
|
63
|
-
_postDrawUpdaters;
|
|
64
|
-
_preDrawUpdaters;
|
|
65
|
-
_resizePlugins;
|
|
66
|
-
_reusableColorStyles = {};
|
|
67
|
-
_reusablePluginColors = [undefined, undefined];
|
|
68
|
-
_reusableTransform = {};
|
|
69
|
-
_standardSize;
|
|
70
|
-
_zoomCenter;
|
|
71
|
-
constructor(container, engine) {
|
|
72
|
-
this.container = container;
|
|
73
|
-
this._engine = engine;
|
|
74
|
-
this._standardSize = {
|
|
75
|
-
height: 0,
|
|
76
|
-
width: 0,
|
|
77
|
-
};
|
|
78
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this._standardSize;
|
|
79
|
-
this.size = {
|
|
80
|
-
height: stdSize.height * pxRatio,
|
|
81
|
-
width: stdSize.width * pxRatio,
|
|
82
|
-
};
|
|
83
|
-
this._context = null;
|
|
84
|
-
this._generated = false;
|
|
85
|
-
this._preDrawUpdaters = [];
|
|
86
|
-
this._postDrawUpdaters = [];
|
|
87
|
-
this._resizePlugins = [];
|
|
88
|
-
this._colorPlugins = [];
|
|
89
|
-
this._canvasClearPlugins = [];
|
|
90
|
-
this._canvasPaintPlugins = [];
|
|
91
|
-
this._clearDrawPlugins = [];
|
|
92
|
-
this._drawParticlePlugins = [];
|
|
93
|
-
this._drawParticlesCleanupPlugins = [];
|
|
94
|
-
this._drawParticlesSetupPlugins = [];
|
|
95
|
-
this._drawPlugins = [];
|
|
96
|
-
this._drawSettingsSetupPlugins = [];
|
|
97
|
-
this._drawSettingsCleanupPlugins = [];
|
|
98
|
-
this._pointerEvents = "none";
|
|
99
|
-
}
|
|
100
|
-
get settings() {
|
|
101
|
-
return this._canvasSettings;
|
|
102
|
-
}
|
|
103
|
-
get _fullScreen() {
|
|
104
|
-
return this.container.actualOptions.fullScreen.enable;
|
|
105
|
-
}
|
|
106
|
-
canvasClear() {
|
|
107
|
-
if (!this.container.actualOptions.clear) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.draw(ctx => {
|
|
111
|
-
clear(ctx, this.size);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
clear() {
|
|
115
|
-
let pluginHandled = false;
|
|
116
|
-
for (const plugin of this._canvasClearPlugins) {
|
|
117
|
-
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
118
|
-
if (pluginHandled) {
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (pluginHandled) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
this.canvasClear();
|
|
126
|
-
}
|
|
127
|
-
destroy() {
|
|
128
|
-
this.stop();
|
|
129
|
-
if (this._generated) {
|
|
130
|
-
const element = this.element;
|
|
131
|
-
element?.remove();
|
|
132
|
-
this.element = undefined;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
this._resetOriginalStyle();
|
|
136
|
-
}
|
|
137
|
-
this._preDrawUpdaters = [];
|
|
138
|
-
this._postDrawUpdaters = [];
|
|
139
|
-
this._resizePlugins = [];
|
|
140
|
-
this._colorPlugins = [];
|
|
141
|
-
this._canvasClearPlugins = [];
|
|
142
|
-
this._canvasPaintPlugins = [];
|
|
143
|
-
this._clearDrawPlugins = [];
|
|
144
|
-
this._drawParticlePlugins = [];
|
|
145
|
-
this._drawParticlesCleanupPlugins = [];
|
|
146
|
-
this._drawParticlesSetupPlugins = [];
|
|
147
|
-
this._drawPlugins = [];
|
|
148
|
-
this._drawSettingsSetupPlugins = [];
|
|
149
|
-
this._drawSettingsCleanupPlugins = [];
|
|
150
|
-
}
|
|
151
|
-
draw(cb) {
|
|
152
|
-
const ctx = this._context;
|
|
153
|
-
if (!ctx) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
return cb(ctx);
|
|
157
|
-
}
|
|
158
|
-
drawParticle(particle, delta) {
|
|
159
|
-
if (particle.spawning || particle.destroyed) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const radius = particle.getRadius();
|
|
163
|
-
if (radius <= minimumSize) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
167
|
-
let [fColor, sColor] = this._getPluginParticleColors(particle);
|
|
168
|
-
fColor ??= pfColor;
|
|
169
|
-
sColor ??= psColor;
|
|
170
|
-
if (!fColor && !sColor) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
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;
|
|
174
|
-
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
175
|
-
colorStyles.fill = fill;
|
|
176
|
-
colorStyles.stroke = stroke;
|
|
177
|
-
this.draw((context) => {
|
|
178
|
-
for (const plugin of this._drawParticlesSetupPlugins) {
|
|
179
|
-
plugin.drawParticleSetup?.(context, particle, delta);
|
|
180
|
-
}
|
|
181
|
-
this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
182
|
-
drawParticle({
|
|
183
|
-
container,
|
|
184
|
-
context,
|
|
185
|
-
particle,
|
|
186
|
-
delta,
|
|
187
|
-
colorStyles,
|
|
188
|
-
radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
|
|
189
|
-
opacity: opacity,
|
|
190
|
-
transform,
|
|
191
|
-
});
|
|
192
|
-
this._applyPostDrawUpdaters(particle);
|
|
193
|
-
for (const plugin of this._drawParticlesCleanupPlugins) {
|
|
194
|
-
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
drawParticlePlugins(particle, delta) {
|
|
199
|
-
this.draw(ctx => {
|
|
200
|
-
for (const plugin of this._drawParticlePlugins) {
|
|
201
|
-
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
drawParticles(delta) {
|
|
206
|
-
const { particles } = this.container;
|
|
207
|
-
this.clear();
|
|
208
|
-
particles.update(delta);
|
|
209
|
-
this.draw(ctx => {
|
|
210
|
-
for (const plugin of this._drawSettingsSetupPlugins) {
|
|
211
|
-
plugin.drawSettingsSetup?.(ctx, delta);
|
|
212
|
-
}
|
|
213
|
-
for (const plugin of this._drawPlugins) {
|
|
214
|
-
plugin.draw?.(ctx, delta);
|
|
215
|
-
}
|
|
216
|
-
particles.drawParticles(delta);
|
|
217
|
-
for (const plugin of this._clearDrawPlugins) {
|
|
218
|
-
plugin.clearDraw?.(ctx, delta);
|
|
219
|
-
}
|
|
220
|
-
for (const plugin of this._drawSettingsCleanupPlugins) {
|
|
221
|
-
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
getZoomCenter() {
|
|
226
|
-
const pxRatio = this.container.retina.pixelRatio, { width, height } = this.size;
|
|
227
|
-
if (this._zoomCenter) {
|
|
228
|
-
return this._zoomCenter;
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
x: (width * half) / pxRatio,
|
|
232
|
-
y: (height * half) / pxRatio,
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
init() {
|
|
236
|
-
this._safeMutationObserver(obs => {
|
|
237
|
-
obs.disconnect();
|
|
238
|
-
});
|
|
239
|
-
this._mutationObserver = safeMutationObserver(records => {
|
|
240
|
-
for (const record of records) {
|
|
241
|
-
if (record.type === "attributes" && record.attributeName === "style") {
|
|
242
|
-
this._repairStyle();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
this.resize();
|
|
247
|
-
this._initStyle();
|
|
248
|
-
this.initBackground();
|
|
249
|
-
this._safeMutationObserver(obs => {
|
|
250
|
-
if (!this.element || !(this.element instanceof Node)) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
obs.observe(this.element, { attributes: true });
|
|
254
|
-
});
|
|
255
|
-
this.initUpdaters();
|
|
256
|
-
this.initPlugins();
|
|
257
|
-
this.paint();
|
|
258
|
-
}
|
|
259
|
-
initBackground() {
|
|
260
|
-
const { container } = this, options = container.actualOptions, background = options.background, element = this.element;
|
|
261
|
-
if (!element) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
const elementStyle = element.style, color = rangeColorToRgb(this._engine, background.color);
|
|
265
|
-
if (color) {
|
|
266
|
-
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
elementStyle.backgroundColor = "";
|
|
270
|
-
}
|
|
271
|
-
elementStyle.backgroundImage = background.image || "";
|
|
272
|
-
elementStyle.backgroundPosition = background.position || "";
|
|
273
|
-
elementStyle.backgroundRepeat = background.repeat || "";
|
|
274
|
-
elementStyle.backgroundSize = background.size || "";
|
|
275
|
-
}
|
|
276
|
-
initPlugins() {
|
|
277
|
-
this._resizePlugins = [];
|
|
278
|
-
this._colorPlugins = [];
|
|
279
|
-
this._canvasClearPlugins = [];
|
|
280
|
-
this._canvasPaintPlugins = [];
|
|
281
|
-
this._clearDrawPlugins = [];
|
|
282
|
-
this._drawParticlePlugins = [];
|
|
283
|
-
this._drawParticlesSetupPlugins = [];
|
|
284
|
-
this._drawParticlesCleanupPlugins = [];
|
|
285
|
-
this._drawPlugins = [];
|
|
286
|
-
this._drawSettingsSetupPlugins = [];
|
|
287
|
-
this._drawSettingsCleanupPlugins = [];
|
|
288
|
-
for (const plugin of this.container.plugins) {
|
|
289
|
-
if (plugin.resize) {
|
|
290
|
-
this._resizePlugins.push(plugin);
|
|
291
|
-
}
|
|
292
|
-
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
293
|
-
this._colorPlugins.push(plugin);
|
|
294
|
-
}
|
|
295
|
-
if (plugin.canvasClear) {
|
|
296
|
-
this._canvasClearPlugins.push(plugin);
|
|
297
|
-
}
|
|
298
|
-
if (plugin.canvasPaint) {
|
|
299
|
-
this._canvasPaintPlugins.push(plugin);
|
|
300
|
-
}
|
|
301
|
-
if (plugin.drawParticle) {
|
|
302
|
-
this._drawParticlePlugins.push(plugin);
|
|
303
|
-
}
|
|
304
|
-
if (plugin.drawParticleSetup) {
|
|
305
|
-
this._drawParticlesSetupPlugins.push(plugin);
|
|
306
|
-
}
|
|
307
|
-
if (plugin.drawParticleCleanup) {
|
|
308
|
-
this._drawParticlesCleanupPlugins.push(plugin);
|
|
309
|
-
}
|
|
310
|
-
if (plugin.draw) {
|
|
311
|
-
this._drawPlugins.push(plugin);
|
|
312
|
-
}
|
|
313
|
-
if (plugin.drawSettingsSetup) {
|
|
314
|
-
this._drawSettingsSetupPlugins.push(plugin);
|
|
315
|
-
}
|
|
316
|
-
if (plugin.drawSettingsCleanup) {
|
|
317
|
-
this._drawSettingsCleanupPlugins.push(plugin);
|
|
318
|
-
}
|
|
319
|
-
if (plugin.clearDraw) {
|
|
320
|
-
this._clearDrawPlugins.push(plugin);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
initUpdaters() {
|
|
325
|
-
this._preDrawUpdaters = [];
|
|
326
|
-
this._postDrawUpdaters = [];
|
|
327
|
-
for (const updater of this.container.particles.updaters) {
|
|
328
|
-
if (updater.afterDraw) {
|
|
329
|
-
this._postDrawUpdaters.push(updater);
|
|
330
|
-
}
|
|
331
|
-
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
332
|
-
this._preDrawUpdaters.push(updater);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
loadCanvas(canvas) {
|
|
337
|
-
if (this._generated && this.element) {
|
|
338
|
-
this.element.remove();
|
|
339
|
-
}
|
|
340
|
-
const container = this.container;
|
|
341
|
-
this._generated =
|
|
342
|
-
generatedAttribute in canvas.dataset ? canvas.dataset[generatedAttribute] === "true" : this._generated;
|
|
343
|
-
this.element = canvas;
|
|
344
|
-
this.element.ariaHidden = "true";
|
|
345
|
-
this._originalStyle = cloneStyle(this.element.style);
|
|
346
|
-
const standardSize = this._standardSize;
|
|
347
|
-
standardSize.height = canvas.offsetHeight;
|
|
348
|
-
standardSize.width = canvas.offsetWidth;
|
|
349
|
-
const pxRatio = this.container.retina.pixelRatio, retinaSize = this.size;
|
|
350
|
-
canvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
351
|
-
canvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
352
|
-
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
353
|
-
this._canvasSettings = {
|
|
354
|
-
alpha: true,
|
|
355
|
-
colorSpace: canSupportHdrQuery?.matches && container.hdr ? "display-p3" : "srgb",
|
|
356
|
-
desynchronized: true,
|
|
357
|
-
willReadFrequently: false,
|
|
358
|
-
};
|
|
359
|
-
this._context = this.element.getContext("2d", this._canvasSettings);
|
|
360
|
-
if (this._context) {
|
|
361
|
-
this._context.globalCompositeOperation = defaultCompositeValue;
|
|
362
|
-
}
|
|
363
|
-
this._safeMutationObserver(obs => {
|
|
364
|
-
obs.disconnect();
|
|
365
|
-
});
|
|
366
|
-
container.retina.init();
|
|
367
|
-
this.initBackground();
|
|
368
|
-
this._safeMutationObserver(obs => {
|
|
369
|
-
if (!this.element || !(this.element instanceof Node)) {
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
obs.observe(this.element, { attributes: true });
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
paint() {
|
|
376
|
-
let handled = false;
|
|
377
|
-
for (const plugin of this._canvasPaintPlugins) {
|
|
378
|
-
handled = plugin.canvasPaint?.() ?? false;
|
|
379
|
-
if (handled) {
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
if (handled) {
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
this.paintBase();
|
|
387
|
-
}
|
|
388
|
-
paintBase(baseColor) {
|
|
389
|
-
this.draw(ctx => {
|
|
390
|
-
paintBase(ctx, this.size, baseColor);
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
paintImage(image, opacity) {
|
|
394
|
-
this.draw(ctx => {
|
|
395
|
-
paintImage(ctx, this.size, image, opacity);
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
resize() {
|
|
399
|
-
if (!this.element) {
|
|
400
|
-
return false;
|
|
401
|
-
}
|
|
402
|
-
const container = this.container, currentSize = container.canvas._standardSize, newSize = {
|
|
403
|
-
width: this.element.offsetWidth,
|
|
404
|
-
height: this.element.offsetHeight,
|
|
405
|
-
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
406
|
-
width: newSize.width * pxRatio,
|
|
407
|
-
height: newSize.height * pxRatio,
|
|
408
|
-
};
|
|
409
|
-
if (newSize.height === currentSize.height &&
|
|
410
|
-
newSize.width === currentSize.width &&
|
|
411
|
-
retinaSize.height === this.element.height &&
|
|
412
|
-
retinaSize.width === this.element.width) {
|
|
413
|
-
return false;
|
|
414
|
-
}
|
|
415
|
-
const oldSize = { ...currentSize };
|
|
416
|
-
currentSize.height = newSize.height;
|
|
417
|
-
currentSize.width = newSize.width;
|
|
418
|
-
const canvasSize = this.size;
|
|
419
|
-
this.element.width = canvasSize.width = retinaSize.width;
|
|
420
|
-
this.element.height = canvasSize.height = retinaSize.height;
|
|
421
|
-
if (this.container.started) {
|
|
422
|
-
container.particles.setResizeFactor({
|
|
423
|
-
width: currentSize.width / oldSize.width,
|
|
424
|
-
height: currentSize.height / oldSize.height,
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
setPointerEvents(type) {
|
|
430
|
-
const element = this.element;
|
|
431
|
-
if (!element) {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
this._pointerEvents = type;
|
|
435
|
-
this._repairStyle();
|
|
436
|
-
}
|
|
437
|
-
setZoom(zoomLevel, center) {
|
|
438
|
-
this.zoom = zoomLevel;
|
|
439
|
-
this._zoomCenter = center;
|
|
440
|
-
}
|
|
441
|
-
stop() {
|
|
442
|
-
this._safeMutationObserver(obs => {
|
|
443
|
-
obs.disconnect();
|
|
444
|
-
});
|
|
445
|
-
this._mutationObserver = undefined;
|
|
446
|
-
this.draw(ctx => {
|
|
447
|
-
clear(ctx, this.size);
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
async windowResize() {
|
|
451
|
-
if (!this.element || !this.resize()) {
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
const container = this.container, needsRefresh = container.updateActualOptions();
|
|
455
|
-
container.particles.setDensity();
|
|
456
|
-
this._applyResizePlugins();
|
|
457
|
-
if (needsRefresh) {
|
|
458
|
-
await container.refresh();
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
_applyPostDrawUpdaters = particle => {
|
|
462
|
-
for (const updater of this._postDrawUpdaters) {
|
|
463
|
-
updater.afterDraw?.(particle);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
_applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
467
|
-
for (const updater of this._preDrawUpdaters) {
|
|
468
|
-
if (updater.getColorStyles) {
|
|
469
|
-
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
470
|
-
if (fill) {
|
|
471
|
-
colorStyles.fill = fill;
|
|
472
|
-
}
|
|
473
|
-
if (stroke) {
|
|
474
|
-
colorStyles.stroke = stroke;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
if (updater.getTransformValues) {
|
|
478
|
-
const updaterTransform = updater.getTransformValues(particle);
|
|
479
|
-
for (const key in updaterTransform) {
|
|
480
|
-
setTransformValue(transform, updaterTransform, key);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
updater.beforeDraw?.(particle);
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
_applyResizePlugins = () => {
|
|
487
|
-
for (const plugin of this._resizePlugins) {
|
|
488
|
-
plugin.resize?.();
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
_getPluginParticleColors = particle => {
|
|
492
|
-
let fColor, sColor;
|
|
493
|
-
for (const plugin of this._colorPlugins) {
|
|
494
|
-
if (!fColor && plugin.particleFillColor) {
|
|
495
|
-
fColor = rangeColorToHsl(this._engine, plugin.particleFillColor(particle));
|
|
496
|
-
}
|
|
497
|
-
if (!sColor && plugin.particleStrokeColor) {
|
|
498
|
-
sColor = rangeColorToHsl(this._engine, plugin.particleStrokeColor(particle));
|
|
499
|
-
}
|
|
500
|
-
if (fColor && sColor) {
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
this._reusablePluginColors[fColorIndex] = fColor;
|
|
505
|
-
this._reusablePluginColors[sColorIndex] = sColor;
|
|
506
|
-
return this._reusablePluginColors;
|
|
507
|
-
};
|
|
508
|
-
_initStyle = () => {
|
|
509
|
-
const element = this.element, options = this.container.actualOptions;
|
|
510
|
-
if (!element) {
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
if (this._fullScreen) {
|
|
514
|
-
this._setFullScreenStyle();
|
|
515
|
-
}
|
|
516
|
-
else {
|
|
517
|
-
this._resetOriginalStyle();
|
|
518
|
-
}
|
|
519
|
-
for (const key in options.style) {
|
|
520
|
-
if (!key || !(key in options.style)) {
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
const value = options.style[key];
|
|
524
|
-
if (!value) {
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
|
-
element.style.setProperty(key, value, "important");
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
_repairStyle = () => {
|
|
531
|
-
const element = this.element;
|
|
532
|
-
if (!element) {
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
this._safeMutationObserver(observer => {
|
|
536
|
-
observer.disconnect();
|
|
537
|
-
});
|
|
538
|
-
this._initStyle();
|
|
539
|
-
this.initBackground();
|
|
540
|
-
const pointerEvents = this._pointerEvents;
|
|
541
|
-
element.style.pointerEvents = pointerEvents;
|
|
542
|
-
element.setAttribute("pointer-events", pointerEvents);
|
|
543
|
-
this._safeMutationObserver(observer => {
|
|
544
|
-
if (!(element instanceof Node)) {
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
observer.observe(element, { attributes: true });
|
|
548
|
-
});
|
|
549
|
-
};
|
|
550
|
-
_resetOriginalStyle = () => {
|
|
551
|
-
const element = this.element, originalStyle = this._originalStyle;
|
|
552
|
-
if (!element || !originalStyle) {
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
setStyle(element, originalStyle, true);
|
|
556
|
-
};
|
|
557
|
-
_safeMutationObserver = callback => {
|
|
558
|
-
if (!this._mutationObserver) {
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
|
-
callback(this._mutationObserver);
|
|
562
|
-
};
|
|
563
|
-
_setFullScreenStyle = () => {
|
|
564
|
-
const element = this.element;
|
|
565
|
-
if (!element) {
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
setStyle(element, getFullScreenStyle(this.container.actualOptions.fullScreen.zIndex), true);
|
|
569
|
-
};
|
|
570
|
-
}
|