@tsparticles/engine 3.0.0-alpha.1 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +244 -188
- package/browser/Core/Canvas.js +271 -241
- package/browser/Core/Container.js +90 -106
- package/browser/Core/Engine.js +271 -0
- package/browser/Core/Particle.js +158 -165
- package/browser/Core/Particles.js +148 -143
- package/browser/Core/Retina.js +15 -13
- package/browser/Core/Utils/Circle.js +10 -6
- package/browser/Core/Utils/Constants.js +4 -3
- package/browser/Core/Utils/EventListeners.js +258 -234
- package/browser/Core/Utils/InteractionManager.js +6 -16
- package/browser/Core/Utils/QuadTree.js +14 -20
- package/browser/Core/Utils/Vector3d.js +17 -9
- package/browser/Options/Classes/AnimatableColor.js +2 -1
- package/browser/Options/Classes/AnimationOptions.js +4 -3
- package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
- package/browser/Options/Classes/ColorAnimation.js +4 -0
- package/browser/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
- package/browser/Options/Classes/Interactivity/Events/Events.js +5 -24
- package/browser/Options/Classes/Interactivity/Interactivity.js +1 -8
- package/browser/Options/Classes/Interactivity/Modes/Modes.js +11 -8
- package/browser/Options/Classes/ManualParticle.js +5 -6
- package/browser/Options/Classes/Options.js +19 -39
- package/browser/Options/Classes/OptionsColor.js +3 -2
- package/browser/Options/Classes/Particles/Collisions/Collisions.js +5 -0
- package/browser/Options/Classes/Particles/Move/Move.js +11 -41
- package/browser/Options/Classes/Particles/Move/MoveAttract.js +9 -20
- package/browser/Options/Classes/Particles/Move/MoveTrail.js +2 -8
- package/browser/Options/Classes/Particles/Move/OutModes.js +4 -5
- package/browser/Options/Classes/Particles/Move/Spin.js +3 -1
- package/browser/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
- package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
- package/browser/Options/Classes/Particles/Opacity/Opacity.js +11 -7
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
- package/browser/Options/Classes/Particles/ParticlesOptions.js +6 -11
- package/browser/Options/Classes/Particles/Shape/Shape.js +9 -10
- package/browser/Options/Classes/Particles/Size/Size.js +11 -7
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
- package/browser/Options/Classes/ValueWithRandom.js +4 -17
- package/browser/Utils/CanvasUtils.js +18 -54
- package/browser/Utils/ColorUtils.js +17 -19
- package/browser/Utils/EventDispatcher.js +7 -6
- package/browser/Utils/HslColorManager.js +2 -4
- package/browser/Utils/NumberUtils.js +41 -45
- package/browser/Utils/RgbColorManager.js +2 -4
- package/browser/Utils/Utils.js +133 -62
- package/browser/bundle.js +4 -97
- package/browser/export-types.js +97 -0
- package/browser/exports.js +89 -0
- package/browser/index.js +8 -199
- package/browser/init.js +12 -0
- package/cjs/Core/Canvas.js +269 -239
- package/cjs/Core/Container.js +90 -106
- package/cjs/Core/Engine.js +275 -0
- package/cjs/Core/Particle.js +157 -164
- package/cjs/Core/Particles.js +148 -143
- package/cjs/Core/Retina.js +15 -13
- package/cjs/Core/Utils/Circle.js +10 -6
- package/cjs/Core/Utils/Constants.js +5 -4
- package/cjs/Core/Utils/EventListeners.js +257 -233
- package/cjs/Core/Utils/InteractionManager.js +6 -16
- package/cjs/Core/Utils/QuadTree.js +14 -20
- package/cjs/Core/Utils/Vector3d.js +17 -9
- package/cjs/Options/Classes/AnimatableColor.js +2 -1
- package/cjs/Options/Classes/AnimationOptions.js +4 -3
- package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
- package/cjs/Options/Classes/ColorAnimation.js +4 -0
- package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
- package/cjs/Options/Classes/Interactivity/Events/Events.js +5 -24
- package/cjs/Options/Classes/Interactivity/Interactivity.js +1 -8
- package/cjs/Options/Classes/Interactivity/Modes/Modes.js +11 -8
- package/cjs/Options/Classes/ManualParticle.js +5 -6
- package/cjs/Options/Classes/Options.js +18 -38
- package/cjs/Options/Classes/OptionsColor.js +3 -2
- package/cjs/Options/Classes/Particles/Collisions/Collisions.js +5 -0
- package/cjs/Options/Classes/Particles/Move/Move.js +11 -41
- package/cjs/Options/Classes/Particles/Move/MoveAttract.js +9 -20
- package/cjs/Options/Classes/Particles/Move/MoveTrail.js +2 -8
- package/cjs/Options/Classes/Particles/Move/OutModes.js +4 -5
- package/cjs/Options/Classes/Particles/Move/Spin.js +3 -1
- package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
- package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
- package/cjs/Options/Classes/Particles/Opacity/Opacity.js +10 -6
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +6 -11
- package/cjs/Options/Classes/Particles/Shape/Shape.js +9 -10
- package/cjs/Options/Classes/Particles/Size/Size.js +11 -7
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
- package/cjs/Options/Classes/ValueWithRandom.js +4 -17
- package/cjs/Utils/CanvasUtils.js +21 -58
- package/cjs/Utils/ColorUtils.js +16 -18
- package/cjs/Utils/EventDispatcher.js +7 -6
- package/cjs/Utils/HslColorManager.js +2 -4
- package/cjs/Utils/NumberUtils.js +41 -45
- package/cjs/Utils/RgbColorManager.js +2 -4
- package/cjs/Utils/Utils.js +146 -66
- package/cjs/bundle.js +4 -97
- package/cjs/export-types.js +113 -0
- package/cjs/exports.js +105 -0
- package/cjs/index.js +8 -199
- package/cjs/init.js +16 -0
- package/esm/Core/Canvas.js +271 -241
- package/esm/Core/Container.js +90 -106
- package/esm/Core/Engine.js +271 -0
- package/esm/Core/Particle.js +158 -165
- package/esm/Core/Particles.js +148 -143
- package/esm/Core/Retina.js +15 -13
- package/esm/Core/Utils/Circle.js +10 -6
- package/esm/Core/Utils/Constants.js +4 -3
- package/esm/Core/Utils/EventListeners.js +258 -234
- package/esm/Core/Utils/InteractionManager.js +6 -16
- package/esm/Core/Utils/QuadTree.js +14 -20
- package/esm/Core/Utils/Vector3d.js +17 -9
- package/esm/Options/Classes/AnimatableColor.js +2 -1
- package/esm/Options/Classes/AnimationOptions.js +4 -3
- package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
- package/esm/Options/Classes/ColorAnimation.js +4 -0
- package/esm/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
- package/esm/Options/Classes/Interactivity/Events/Events.js +5 -24
- package/esm/Options/Classes/Interactivity/Interactivity.js +1 -8
- package/esm/Options/Classes/Interactivity/Modes/Modes.js +11 -8
- package/esm/Options/Classes/ManualParticle.js +5 -6
- package/esm/Options/Classes/Options.js +19 -39
- package/esm/Options/Classes/OptionsColor.js +3 -2
- package/esm/Options/Classes/Particles/Collisions/Collisions.js +5 -0
- package/esm/Options/Classes/Particles/Move/Move.js +11 -41
- package/esm/Options/Classes/Particles/Move/MoveAttract.js +9 -20
- package/esm/Options/Classes/Particles/Move/MoveTrail.js +2 -8
- package/esm/Options/Classes/Particles/Move/OutModes.js +4 -5
- package/esm/Options/Classes/Particles/Move/Spin.js +3 -1
- package/esm/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
- package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
- package/esm/Options/Classes/Particles/Opacity/Opacity.js +11 -7
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
- package/esm/Options/Classes/Particles/ParticlesOptions.js +6 -11
- package/esm/Options/Classes/Particles/Shape/Shape.js +9 -10
- package/esm/Options/Classes/Particles/Size/Size.js +11 -7
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
- package/esm/Options/Classes/ValueWithRandom.js +4 -17
- package/esm/Utils/CanvasUtils.js +18 -54
- package/esm/Utils/ColorUtils.js +17 -19
- package/esm/Utils/EventDispatcher.js +7 -6
- package/esm/Utils/HslColorManager.js +2 -4
- package/esm/Utils/NumberUtils.js +41 -45
- package/esm/Utils/RgbColorManager.js +2 -4
- package/esm/Utils/Utils.js +133 -62
- package/esm/bundle.js +4 -97
- package/esm/export-types.js +97 -0
- package/esm/exports.js +89 -0
- package/esm/index.js +8 -199
- package/esm/init.js +12 -0
- package/package.json +17 -2
- package/report.html +4 -4
- package/scripts/install.js +90 -33
- package/tsparticles.engine.js +1832 -2007
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -10
- package/types/Core/Canvas.d.ts +20 -16
- package/types/Core/Container.d.ts +10 -14
- package/types/Core/Engine.d.ts +71 -0
- package/types/Core/Interfaces/IContainerPlugin.d.ts +2 -0
- package/types/Core/Interfaces/ICoordinates.d.ts +2 -2
- package/types/Core/Interfaces/IDimension.d.ts +2 -2
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -1
- package/types/Core/Interfaces/IParticleUpdater.d.ts +0 -2
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +2 -0
- package/types/Core/Interfaces/IPlugin.d.ts +4 -3
- package/types/Core/Particle.d.ts +7 -7
- package/types/Core/Particles.d.ts +14 -11
- package/types/Core/Utils/Constants.d.ts +4 -3
- package/types/Core/Utils/EventListeners.d.ts +20 -18
- package/types/Core/Utils/InteractionManager.d.ts +1 -1
- package/types/Core/Utils/QuadTree.d.ts +2 -5
- package/types/Core/Utils/Vector3d.d.ts +2 -1
- package/types/Enums/Modes/{SizeMode.d.ts → PixelMode.d.ts} +1 -1
- package/types/Options/Classes/AnimationOptions.d.ts +1 -1
- package/types/Options/Classes/ColorAnimation.d.ts +1 -0
- package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +0 -6
- package/types/Options/Classes/Interactivity/Events/Events.d.ts +0 -6
- package/types/Options/Classes/Interactivity/Interactivity.d.ts +1 -3
- package/types/Options/Classes/Interactivity/Modes/Modes.d.ts +1 -1
- package/types/Options/Classes/Options.d.ts +5 -12
- package/types/Options/Classes/Particles/Collisions/Collisions.d.ts +2 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +0 -11
- package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -4
- package/types/Options/Classes/Particles/Move/MoveCenter.d.ts +2 -2
- package/types/Options/Classes/Particles/Move/MoveTrail.d.ts +0 -3
- package/types/Options/Classes/Particles/Number/ParticlesDensity.d.ts +0 -6
- package/types/Options/Classes/Particles/Number/ParticlesNumber.d.ts +0 -2
- package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +4 -4
- package/types/Options/Classes/Particles/Opacity/OpacityAnimation.d.ts +0 -2
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +1 -1
- package/types/Options/Classes/Particles/Size/Size.d.ts +4 -4
- package/types/Options/Classes/Particles/Size/SizeAnimation.d.ts +0 -2
- package/types/Options/Classes/Responsive.d.ts +3 -3
- package/types/Options/Classes/Theme/Theme.d.ts +2 -2
- package/types/Options/Classes/ValueWithRandom.d.ts +2 -6
- package/types/Options/Interfaces/IAnimation.d.ts +1 -1
- package/types/Options/Interfaces/IOptions.d.ts +1 -4
- package/types/Options/Interfaces/IResponsive.d.ts +4 -3
- package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +0 -3
- package/types/Options/Interfaces/Interactivity/Events/IEvents.d.ts +0 -3
- package/types/Options/Interfaces/Interactivity/IInteractivity.d.ts +0 -1
- package/types/Options/Interfaces/Interactivity/Modes/IModeDiv.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Collisions/ICollisions.d.ts +2 -0
- package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -1
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Move/IMoveTrail.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Number/IParticlesDensity.d.ts +0 -3
- package/types/Options/Interfaces/Particles/Number/IParticlesNumber.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Opacity/IOpacity.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Opacity/IOpacityAnimation.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Size/ISize.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Size/ISizeAnimation.d.ts +0 -1
- package/types/Options/Interfaces/Theme/ITheme.d.ts +3 -2
- package/types/Types/ExportResult.d.ts +5 -0
- package/types/Utils/CanvasUtils.d.ts +2 -5
- package/types/Utils/OptionsUtils.d.ts +1 -1
- package/types/Utils/Utils.d.ts +22 -4
- package/types/bundle.d.ts +2 -91
- package/types/export-types.d.ts +107 -0
- package/types/exports.d.ts +89 -0
- package/types/index.d.ts +3 -204
- package/types/init.d.ts +2 -0
- package/umd/Core/Canvas.js +269 -239
- package/umd/Core/Container.js +91 -107
- package/umd/Core/Engine.js +285 -0
- package/umd/Core/Particle.js +158 -165
- package/umd/Core/Particles.js +149 -144
- package/umd/Core/Retina.js +15 -13
- package/umd/Core/Utils/Circle.js +11 -7
- package/umd/Core/Utils/Constants.js +5 -4
- package/umd/Core/Utils/EventListeners.js +257 -233
- package/umd/Core/Utils/InteractionManager.js +6 -16
- package/umd/Core/Utils/QuadTree.js +14 -20
- package/umd/Core/Utils/Vector3d.js +18 -10
- package/umd/Options/Classes/AnimatableColor.js +3 -2
- package/umd/Options/Classes/AnimationOptions.js +4 -3
- package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +3 -2
- package/umd/Options/Classes/ColorAnimation.js +4 -0
- package/umd/Options/Classes/Interactivity/Events/DivEvent.js +1 -25
- package/umd/Options/Classes/Interactivity/Events/Events.js +6 -25
- package/umd/Options/Classes/Interactivity/Interactivity.js +1 -8
- package/umd/Options/Classes/Interactivity/Modes/Modes.js +11 -8
- package/umd/Options/Classes/ManualParticle.js +5 -6
- package/umd/Options/Classes/Options.js +18 -38
- package/umd/Options/Classes/OptionsColor.js +4 -3
- package/umd/Options/Classes/Particles/Collisions/Collisions.js +6 -1
- package/umd/Options/Classes/Particles/Move/Move.js +12 -42
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +9 -20
- package/umd/Options/Classes/Particles/Move/MoveTrail.js +2 -8
- package/umd/Options/Classes/Particles/Move/OutModes.js +4 -5
- package/umd/Options/Classes/Particles/Move/Spin.js +3 -1
- package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
- package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
- package/umd/Options/Classes/Particles/Opacity/Opacity.js +10 -6
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
- package/umd/Options/Classes/Particles/ParticlesOptions.js +6 -11
- package/umd/Options/Classes/Particles/Shape/Shape.js +9 -10
- package/umd/Options/Classes/Particles/Size/Size.js +12 -8
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
- package/umd/Options/Classes/ValueWithRandom.js +5 -18
- package/umd/Utils/CanvasUtils.js +21 -58
- package/umd/Utils/ColorUtils.js +16 -18
- package/umd/Utils/EventDispatcher.js +7 -6
- package/umd/Utils/HslColorManager.js +2 -4
- package/umd/Utils/NumberUtils.js +42 -46
- package/umd/Utils/RgbColorManager.js +2 -4
- package/umd/Utils/Utils.js +146 -66
- package/umd/bundle.js +5 -98
- package/umd/export-types.js +123 -0
- package/umd/exports.js +115 -0
- package/umd/index.js +9 -200
- package/umd/init.js +26 -0
- package/browser/Core/Utils/FrameManager.js +0 -42
- package/browser/Core/Utils/Plugins.js +0 -112
- package/browser/Options/Interfaces/Particles/Shape/IImageShape.js +0 -1
- package/browser/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -1
- package/browser/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -1
- package/browser/Options/Interfaces/Particles/Shape/IStarShape.js +0 -1
- package/browser/engine.js +0 -175
- package/cjs/Core/Utils/FrameManager.js +0 -46
- package/cjs/Core/Utils/Plugins.js +0 -116
- package/cjs/Enums/Modes/SizeMode.js +0 -2
- package/cjs/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -2
- package/cjs/Options/Interfaces/Particles/Shape/IImageShape.js +0 -2
- package/cjs/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -2
- package/cjs/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -17
- package/cjs/Options/Interfaces/Particles/Shape/IStarShape.js +0 -2
- package/cjs/engine.js +0 -179
- package/esm/Core/Interfaces/IParticleOverride.js +0 -1
- package/esm/Core/Interfaces/IParticlesMover.js +0 -1
- package/esm/Core/Utils/FrameManager.js +0 -42
- package/esm/Core/Utils/Plugins.js +0 -112
- package/esm/Enums/Modes/SizeMode.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/IImageShape.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/IStarShape.js +0 -1
- package/esm/engine.js +0 -175
- package/types/Core/Interfaces/IParticleOverride.d.ts +0 -6
- package/types/Core/Interfaces/IParticlesMover.d.ts +0 -7
- package/types/Core/Utils/FrameManager.d.ts +0 -6
- package/types/Core/Utils/Plugins.d.ts +0 -51
- package/types/Options/Interfaces/Particles/Shape/ICharacterShape.d.ts +0 -8
- package/types/Options/Interfaces/Particles/Shape/IImageShape.d.ts +0 -8
- package/types/Options/Interfaces/Particles/Shape/IPolygonShape.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Shape/IShapeValues.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Shape/IStarShape.d.ts +0 -6
- package/types/engine.d.ts +0 -39
- package/umd/Core/Utils/FrameManager.js +0 -56
- package/umd/Core/Utils/Plugins.js +0 -126
- package/umd/Enums/Modes/SizeMode.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/IImageShape.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -27
- package/umd/Options/Interfaces/Particles/Shape/IStarShape.js +0 -12
- package/umd/engine.js +0 -189
- /package/browser/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
- /package/browser/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
- /package/cjs/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
- /package/cjs/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
- /package/{browser/Enums/Modes/SizeMode.js → esm/Enums/Modes/PixelMode.js} +0 -0
- /package/{browser/Options/Interfaces/Particles/Shape/ICharacterShape.js → esm/Types/ExportResult.js} +0 -0
- /package/umd/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
- /package/umd/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
package/browser/Core/Canvas.js
CHANGED
|
@@ -1,17 +1,180 @@
|
|
|
1
|
-
import { clear,
|
|
2
|
-
import { deepExtend,
|
|
1
|
+
import { clear, drawParticle, drawParticlePlugin, drawPlugin, paintBase, paintImage } from "../Utils/CanvasUtils";
|
|
2
|
+
import { deepExtend, getLogger, safeMutationObserver } from "../Utils/Utils";
|
|
3
3
|
import { getStyleFromHsl, getStyleFromRgb, rangeColorToHsl, rangeColorToRgb } from "../Utils/ColorUtils";
|
|
4
4
|
import { generatedAttribute } from "./Utils/Constants";
|
|
5
5
|
function setTransformValue(factor, newFactor, key) {
|
|
6
|
-
var _a;
|
|
7
6
|
const newValue = newFactor[key];
|
|
8
7
|
if (newValue !== undefined) {
|
|
9
|
-
factor[key] = (
|
|
8
|
+
factor[key] = (factor[key] ?? 1) * newValue;
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
11
|
export class Canvas {
|
|
13
12
|
constructor(container) {
|
|
14
13
|
this.container = container;
|
|
14
|
+
this._applyPostDrawUpdaters = (particle) => {
|
|
15
|
+
for (const updater of this._postDrawUpdaters) {
|
|
16
|
+
updater.afterDraw && updater.afterDraw(particle);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
this._applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
20
|
+
for (const updater of this._preDrawUpdaters) {
|
|
21
|
+
if (updater.getColorStyles) {
|
|
22
|
+
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
23
|
+
if (fill) {
|
|
24
|
+
colorStyles.fill = fill;
|
|
25
|
+
}
|
|
26
|
+
if (stroke) {
|
|
27
|
+
colorStyles.stroke = stroke;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (updater.getTransformValues) {
|
|
31
|
+
const updaterTransform = updater.getTransformValues(particle);
|
|
32
|
+
for (const key in updaterTransform) {
|
|
33
|
+
setTransformValue(transform, updaterTransform, key);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
updater.beforeDraw && updater.beforeDraw(particle);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
this._applyResizePlugins = () => {
|
|
40
|
+
for (const plugin of this._resizePlugins) {
|
|
41
|
+
plugin.resize && plugin.resize();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
this._getPluginParticleColors = (particle) => {
|
|
45
|
+
let fColor, sColor;
|
|
46
|
+
for (const plugin of this._colorPlugins) {
|
|
47
|
+
if (!fColor && plugin.particleFillColor) {
|
|
48
|
+
fColor = rangeColorToHsl(plugin.particleFillColor(particle));
|
|
49
|
+
}
|
|
50
|
+
if (!sColor && plugin.particleStrokeColor) {
|
|
51
|
+
sColor = rangeColorToHsl(plugin.particleStrokeColor(particle));
|
|
52
|
+
}
|
|
53
|
+
if (fColor && sColor) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [fColor, sColor];
|
|
58
|
+
};
|
|
59
|
+
this._initCover = () => {
|
|
60
|
+
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color, coverRgb = rangeColorToRgb(color);
|
|
61
|
+
if (coverRgb) {
|
|
62
|
+
const coverColor = {
|
|
63
|
+
...coverRgb,
|
|
64
|
+
a: cover.opacity,
|
|
65
|
+
};
|
|
66
|
+
this._coverColorStyle = getStyleFromRgb(coverColor, coverColor.a);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this._initStyle = () => {
|
|
70
|
+
const element = this.element, options = this.container.actualOptions;
|
|
71
|
+
if (!element) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (this._fullScreen) {
|
|
75
|
+
this._originalStyle = deepExtend({}, element.style);
|
|
76
|
+
this._setFullScreenStyle();
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this._resetOriginalStyle();
|
|
80
|
+
}
|
|
81
|
+
for (const key in options.style) {
|
|
82
|
+
if (!key || !options.style) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const value = options.style[key];
|
|
86
|
+
if (!value) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
element.style.setProperty(key, value, "important");
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
this._initTrail = async () => {
|
|
93
|
+
const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = trail.fill;
|
|
94
|
+
if (!trail.enable) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (trailFill.color) {
|
|
98
|
+
const fillColor = rangeColorToRgb(trailFill.color);
|
|
99
|
+
if (!fillColor) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const trail = options.particles.move.trail;
|
|
103
|
+
this._trailFill = {
|
|
104
|
+
color: {
|
|
105
|
+
...fillColor,
|
|
106
|
+
},
|
|
107
|
+
opacity: 1 / trail.length,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
await new Promise((resolve, reject) => {
|
|
112
|
+
if (!trailFill.image) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const img = document.createElement("img");
|
|
116
|
+
img.addEventListener("load", () => {
|
|
117
|
+
this._trailFill = {
|
|
118
|
+
image: img,
|
|
119
|
+
opacity: 1 / trail.length,
|
|
120
|
+
};
|
|
121
|
+
resolve();
|
|
122
|
+
});
|
|
123
|
+
img.addEventListener("error", (evt) => {
|
|
124
|
+
reject(evt.error);
|
|
125
|
+
});
|
|
126
|
+
img.src = trailFill.image;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
this._paintBase = (baseColor) => {
|
|
131
|
+
this.draw((ctx) => paintBase(ctx, this.size, baseColor));
|
|
132
|
+
};
|
|
133
|
+
this._paintImage = (image, opacity) => {
|
|
134
|
+
this.draw((ctx) => paintImage(ctx, this.size, image, opacity));
|
|
135
|
+
};
|
|
136
|
+
this._repairStyle = () => {
|
|
137
|
+
const element = this.element;
|
|
138
|
+
if (!element) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this._safeMutationObserver((observer) => observer.disconnect());
|
|
142
|
+
this._initStyle();
|
|
143
|
+
this.initBackground();
|
|
144
|
+
this._safeMutationObserver((observer) => observer.observe(element, { attributes: true }));
|
|
145
|
+
};
|
|
146
|
+
this._resetOriginalStyle = () => {
|
|
147
|
+
const element = this.element, originalStyle = this._originalStyle;
|
|
148
|
+
if (!(element && originalStyle)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const style = element.style;
|
|
152
|
+
style.position = originalStyle.position;
|
|
153
|
+
style.zIndex = originalStyle.zIndex;
|
|
154
|
+
style.top = originalStyle.top;
|
|
155
|
+
style.left = originalStyle.left;
|
|
156
|
+
style.width = originalStyle.width;
|
|
157
|
+
style.height = originalStyle.height;
|
|
158
|
+
};
|
|
159
|
+
this._safeMutationObserver = (callback) => {
|
|
160
|
+
if (!this._mutationObserver) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
callback(this._mutationObserver);
|
|
164
|
+
};
|
|
165
|
+
this._setFullScreenStyle = () => {
|
|
166
|
+
const element = this.element;
|
|
167
|
+
if (!element) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const priority = "important", style = element.style;
|
|
171
|
+
style.setProperty("position", "fixed", priority);
|
|
172
|
+
style.setProperty("z-index", this.container.actualOptions.fullScreen.zIndex.toString(10), priority);
|
|
173
|
+
style.setProperty("top", "0", priority);
|
|
174
|
+
style.setProperty("left", "0", priority);
|
|
175
|
+
style.setProperty("width", "100%", priority);
|
|
176
|
+
style.setProperty("height", "100%", priority);
|
|
177
|
+
};
|
|
15
178
|
this.size = {
|
|
16
179
|
height: 0,
|
|
17
180
|
width: 0,
|
|
@@ -22,50 +185,51 @@ export class Canvas {
|
|
|
22
185
|
this._postDrawUpdaters = [];
|
|
23
186
|
this._resizePlugins = [];
|
|
24
187
|
this._colorPlugins = [];
|
|
25
|
-
this._mutationObserver =
|
|
26
|
-
!isSsr() && typeof MutationObserver !== "undefined"
|
|
27
|
-
? new MutationObserver((records) => {
|
|
28
|
-
for (const record of records) {
|
|
29
|
-
if (record.type === "attributes" && record.attributeName === "style") {
|
|
30
|
-
this._repairStyle();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
: undefined;
|
|
35
188
|
}
|
|
36
189
|
get _fullScreen() {
|
|
37
190
|
return this.container.actualOptions.fullScreen.enable;
|
|
38
191
|
}
|
|
39
192
|
clear() {
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
193
|
+
const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill;
|
|
194
|
+
if (options.backgroundMask.enable) {
|
|
195
|
+
this.paint();
|
|
196
|
+
}
|
|
197
|
+
else if (trail.enable && trail.length > 0 && trailFill) {
|
|
198
|
+
if (trailFill.color) {
|
|
199
|
+
this._paintBase(getStyleFromRgb(trailFill.color, trailFill.opacity));
|
|
200
|
+
}
|
|
201
|
+
else if (trailFill.image) {
|
|
202
|
+
this._paintImage(trailFill.image, trailFill.opacity);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
this.draw((ctx) => {
|
|
207
|
+
clear(ctx, this.size);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
43
210
|
}
|
|
44
211
|
destroy() {
|
|
45
|
-
|
|
46
|
-
(_a = this._mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
212
|
+
this.stop();
|
|
47
213
|
if (this._generated) {
|
|
48
|
-
|
|
214
|
+
const element = this.element;
|
|
215
|
+
element && element.remove();
|
|
49
216
|
}
|
|
50
217
|
else {
|
|
51
218
|
this._resetOriginalStyle();
|
|
52
219
|
}
|
|
53
|
-
this.draw((ctx) => {
|
|
54
|
-
clear(ctx, this.size);
|
|
55
|
-
});
|
|
56
220
|
this._preDrawUpdaters = [];
|
|
57
221
|
this._postDrawUpdaters = [];
|
|
58
222
|
this._resizePlugins = [];
|
|
59
223
|
this._colorPlugins = [];
|
|
60
224
|
}
|
|
61
225
|
draw(cb) {
|
|
62
|
-
|
|
226
|
+
const ctx = this._context;
|
|
227
|
+
if (!ctx) {
|
|
63
228
|
return;
|
|
64
229
|
}
|
|
65
|
-
return cb(
|
|
230
|
+
return cb(ctx);
|
|
66
231
|
}
|
|
67
232
|
drawParticle(particle, delta) {
|
|
68
|
-
var _a;
|
|
69
233
|
if (particle.spawning || particle.destroyed) {
|
|
70
234
|
return;
|
|
71
235
|
}
|
|
@@ -73,7 +237,7 @@ export class Canvas {
|
|
|
73
237
|
if (radius <= 0) {
|
|
74
238
|
return;
|
|
75
239
|
}
|
|
76
|
-
const pfColor = particle.getFillColor(), psColor =
|
|
240
|
+
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor() ?? pfColor;
|
|
77
241
|
let [fColor, sColor] = this._getPluginParticleColors(particle);
|
|
78
242
|
if (!fColor) {
|
|
79
243
|
fColor = pfColor;
|
|
@@ -85,14 +249,13 @@ export class Canvas {
|
|
|
85
249
|
return;
|
|
86
250
|
}
|
|
87
251
|
this.draw((ctx) => {
|
|
88
|
-
|
|
89
|
-
const options = this.container.actualOptions, zIndexOptions = particle.options.zIndex, zOpacityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.opacityRate, opacity = (_c = (_a = particle.bubble.opacity) !== null && _a !== void 0 ? _a : (_b = particle.opacity) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 1, strokeOpacity = (_d = particle.strokeOpacity) !== null && _d !== void 0 ? _d : opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
|
|
252
|
+
const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zOpacityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.opacityRate, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? 1, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
|
|
90
253
|
fill: fColor ? getStyleFromHsl(fColor, zOpacity) : undefined,
|
|
91
254
|
};
|
|
92
255
|
colorStyles.stroke = sColor ? getStyleFromHsl(sColor, zStrokeOpacity) : colorStyles.fill;
|
|
93
256
|
this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);
|
|
94
257
|
drawParticle({
|
|
95
|
-
container
|
|
258
|
+
container,
|
|
96
259
|
context: ctx,
|
|
97
260
|
particle,
|
|
98
261
|
delta,
|
|
@@ -108,119 +271,46 @@ export class Canvas {
|
|
|
108
271
|
});
|
|
109
272
|
}
|
|
110
273
|
drawParticlePlugin(plugin, particle, delta) {
|
|
111
|
-
this.draw((ctx) =>
|
|
112
|
-
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
113
|
-
});
|
|
274
|
+
this.draw((ctx) => drawParticlePlugin(ctx, plugin, particle, delta));
|
|
114
275
|
}
|
|
115
276
|
drawPlugin(plugin, delta) {
|
|
116
|
-
this.draw((ctx) =>
|
|
117
|
-
drawPlugin(ctx, plugin, delta);
|
|
118
|
-
});
|
|
277
|
+
this.draw((ctx) => drawPlugin(ctx, plugin, delta));
|
|
119
278
|
}
|
|
120
279
|
async init() {
|
|
121
|
-
|
|
122
|
-
this.
|
|
280
|
+
this._safeMutationObserver((obs) => obs.disconnect());
|
|
281
|
+
this._mutationObserver = safeMutationObserver((records) => {
|
|
282
|
+
for (const record of records) {
|
|
283
|
+
if (record.type === "attributes" && record.attributeName === "style") {
|
|
284
|
+
this._repairStyle();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
this.resize();
|
|
123
289
|
this._initStyle();
|
|
124
290
|
this._initCover();
|
|
125
291
|
try {
|
|
126
292
|
await this._initTrail();
|
|
127
293
|
}
|
|
128
294
|
catch (e) {
|
|
129
|
-
|
|
295
|
+
getLogger().error(e);
|
|
130
296
|
}
|
|
131
|
-
this.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this._initUpdaters();
|
|
136
|
-
this._initPlugins();
|
|
137
|
-
this._paint();
|
|
138
|
-
this.container.updateActualOptions();
|
|
139
|
-
this._resize();
|
|
140
|
-
this._initBackground();
|
|
141
|
-
}
|
|
142
|
-
loadCanvas(canvas) {
|
|
143
|
-
var _a, _b;
|
|
144
|
-
if (this._generated) {
|
|
145
|
-
(_a = this.element) === null || _a === void 0 ? void 0 : _a.remove();
|
|
146
|
-
}
|
|
147
|
-
this._generated =
|
|
148
|
-
canvas.dataset && generatedAttribute in canvas.dataset
|
|
149
|
-
? canvas.dataset[generatedAttribute] === "true"
|
|
150
|
-
: this._generated;
|
|
151
|
-
this.element = canvas;
|
|
152
|
-
this.element.ariaHidden = "true";
|
|
153
|
-
this._originalStyle = deepExtend({}, this.element.style);
|
|
154
|
-
this.size.height = canvas.offsetHeight;
|
|
155
|
-
this.size.width = canvas.offsetWidth;
|
|
156
|
-
this._context = getContext(canvas);
|
|
157
|
-
(_b = this._mutationObserver) === null || _b === void 0 ? void 0 : _b.observe(this.element, { attributes: true });
|
|
158
|
-
this.container.retina.init();
|
|
159
|
-
this._initBackground();
|
|
160
|
-
}
|
|
161
|
-
async windowResize() {
|
|
162
|
-
if (!this.element) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
this._resize();
|
|
166
|
-
const container = this.container, needsRefresh = container.updateActualOptions();
|
|
167
|
-
container.particles.setDensity();
|
|
168
|
-
this._applyResizePlugins();
|
|
169
|
-
if (needsRefresh) {
|
|
170
|
-
await container.refresh();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
_applyPostDrawUpdaters(particle) {
|
|
174
|
-
var _a;
|
|
175
|
-
for (const updater of this._postDrawUpdaters) {
|
|
176
|
-
(_a = updater.afterDraw) === null || _a === void 0 ? void 0 : _a.call(updater, particle);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
_applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform) {
|
|
180
|
-
var _a;
|
|
181
|
-
for (const updater of this._preDrawUpdaters) {
|
|
182
|
-
if (updater.getColorStyles) {
|
|
183
|
-
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
184
|
-
if (fill) {
|
|
185
|
-
colorStyles.fill = fill;
|
|
186
|
-
}
|
|
187
|
-
if (stroke) {
|
|
188
|
-
colorStyles.stroke = stroke;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (updater.getTransformValues) {
|
|
192
|
-
const updaterTransform = updater.getTransformValues(particle);
|
|
193
|
-
for (const key in updaterTransform) {
|
|
194
|
-
setTransformValue(transform, updaterTransform, key);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
(_a = updater.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(updater, particle);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
_applyResizePlugins() {
|
|
201
|
-
for (const plugin of this._resizePlugins) {
|
|
202
|
-
if (plugin.resize) {
|
|
203
|
-
plugin.resize();
|
|
297
|
+
this.initBackground();
|
|
298
|
+
this._safeMutationObserver((obs) => {
|
|
299
|
+
if (!this.element) {
|
|
300
|
+
return;
|
|
204
301
|
}
|
|
205
|
-
|
|
302
|
+
obs.observe(this.element, { attributes: true });
|
|
303
|
+
});
|
|
304
|
+
this.initUpdaters();
|
|
305
|
+
this.initPlugins();
|
|
306
|
+
this.paint();
|
|
206
307
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
fColor = rangeColorToHsl(plugin.particleFillColor(particle));
|
|
212
|
-
}
|
|
213
|
-
if (!sColor && plugin.particleStrokeColor) {
|
|
214
|
-
sColor = rangeColorToHsl(plugin.particleStrokeColor(particle));
|
|
215
|
-
}
|
|
216
|
-
if (fColor && sColor) {
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
308
|
+
initBackground() {
|
|
309
|
+
const options = this.container.actualOptions, background = options.background, element = this.element;
|
|
310
|
+
if (!element) {
|
|
311
|
+
return;
|
|
219
312
|
}
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
_initBackground() {
|
|
223
|
-
const options = this.container.actualOptions, background = options.background, element = this.element, elementStyle = element === null || element === void 0 ? void 0 : element.style;
|
|
313
|
+
const elementStyle = element.style;
|
|
224
314
|
if (!elementStyle) {
|
|
225
315
|
return;
|
|
226
316
|
}
|
|
@@ -236,19 +326,7 @@ export class Canvas {
|
|
|
236
326
|
elementStyle.backgroundRepeat = background.repeat || "";
|
|
237
327
|
elementStyle.backgroundSize = background.size || "";
|
|
238
328
|
}
|
|
239
|
-
|
|
240
|
-
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color, coverRgb = rangeColorToRgb(color);
|
|
241
|
-
if (coverRgb) {
|
|
242
|
-
const coverColor = {
|
|
243
|
-
r: coverRgb.r,
|
|
244
|
-
g: coverRgb.g,
|
|
245
|
-
b: coverRgb.b,
|
|
246
|
-
a: cover.opacity,
|
|
247
|
-
};
|
|
248
|
-
this._coverColorStyle = getStyleFromRgb(coverColor, coverColor.a);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
_initPlugins() {
|
|
329
|
+
initPlugins() {
|
|
252
330
|
this._resizePlugins = [];
|
|
253
331
|
for (const [, plugin] of this.container.plugins) {
|
|
254
332
|
if (plugin.resize) {
|
|
@@ -259,66 +337,7 @@ export class Canvas {
|
|
|
259
337
|
}
|
|
260
338
|
}
|
|
261
339
|
}
|
|
262
|
-
|
|
263
|
-
const element = this.element, options = this.container.actualOptions;
|
|
264
|
-
if (!element) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
if (this._fullScreen) {
|
|
268
|
-
this._originalStyle = deepExtend({}, element.style);
|
|
269
|
-
this._setFullScreenStyle();
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
this._resetOriginalStyle();
|
|
273
|
-
}
|
|
274
|
-
for (const key in options.style) {
|
|
275
|
-
if (!key || !options.style) {
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
const value = options.style[key];
|
|
279
|
-
if (!value) {
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
element.style.setProperty(key, value, "important");
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async _initTrail() {
|
|
286
|
-
const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = trail.fill;
|
|
287
|
-
if (!trail.enable) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (trailFill.color) {
|
|
291
|
-
const fillColor = rangeColorToRgb(trailFill.color);
|
|
292
|
-
if (!fillColor) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
const trail = options.particles.move.trail;
|
|
296
|
-
this._trailFill = {
|
|
297
|
-
color: Object.assign({}, fillColor),
|
|
298
|
-
opacity: 1 / trail.length,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
await new Promise((resolve, reject) => {
|
|
303
|
-
if (!trailFill.image) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const img = document.createElement("img");
|
|
307
|
-
img.addEventListener("load", () => {
|
|
308
|
-
this._trailFill = {
|
|
309
|
-
image: img,
|
|
310
|
-
opacity: 1 / trail.length,
|
|
311
|
-
};
|
|
312
|
-
resolve();
|
|
313
|
-
});
|
|
314
|
-
img.addEventListener("error", (evt) => {
|
|
315
|
-
reject(evt.error);
|
|
316
|
-
});
|
|
317
|
-
img.src = trailFill.image;
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
_initUpdaters() {
|
|
340
|
+
initUpdaters() {
|
|
322
341
|
this._preDrawUpdaters = [];
|
|
323
342
|
this._postDrawUpdaters = [];
|
|
324
343
|
for (const updater of this.container.particles.updaters) {
|
|
@@ -330,37 +349,44 @@ export class Canvas {
|
|
|
330
349
|
}
|
|
331
350
|
}
|
|
332
351
|
}
|
|
333
|
-
|
|
334
|
-
this.
|
|
335
|
-
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
_repairStyle() {
|
|
339
|
-
var _a, _b;
|
|
340
|
-
const element = this.element;
|
|
341
|
-
if (!element) {
|
|
342
|
-
return;
|
|
352
|
+
loadCanvas(canvas) {
|
|
353
|
+
if (this._generated && this.element) {
|
|
354
|
+
this.element.remove();
|
|
343
355
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
356
|
+
this._generated =
|
|
357
|
+
canvas.dataset && generatedAttribute in canvas.dataset
|
|
358
|
+
? canvas.dataset[generatedAttribute] === "true"
|
|
359
|
+
: this._generated;
|
|
360
|
+
this.element = canvas;
|
|
361
|
+
this.element.ariaHidden = "true";
|
|
362
|
+
this._originalStyle = deepExtend({}, this.element.style);
|
|
363
|
+
this.size.height = canvas.offsetHeight;
|
|
364
|
+
this.size.width = canvas.offsetWidth;
|
|
365
|
+
this._context = this.element.getContext("2d");
|
|
366
|
+
this._safeMutationObserver((obs) => {
|
|
367
|
+
if (!this.element) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
obs.observe(this.element, { attributes: true });
|
|
371
|
+
});
|
|
372
|
+
this.container.retina.init();
|
|
373
|
+
this.initBackground();
|
|
348
374
|
}
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
375
|
+
paint() {
|
|
376
|
+
const options = this.container.actualOptions;
|
|
377
|
+
this.draw((ctx) => {
|
|
378
|
+
if (options.backgroundMask.enable && options.backgroundMask.cover) {
|
|
379
|
+
clear(ctx, this.size);
|
|
380
|
+
this._paintBase(this._coverColorStyle);
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
this._paintBase();
|
|
384
|
+
}
|
|
385
|
+
});
|
|
360
386
|
}
|
|
361
|
-
|
|
387
|
+
resize() {
|
|
362
388
|
if (!this.element) {
|
|
363
|
-
return;
|
|
389
|
+
return false;
|
|
364
390
|
}
|
|
365
391
|
const container = this.container, pxRatio = container.retina.pixelRatio, size = container.canvas.size, newSize = {
|
|
366
392
|
width: this.element.offsetWidth * pxRatio,
|
|
@@ -370,9 +396,9 @@ export class Canvas {
|
|
|
370
396
|
newSize.width === size.width &&
|
|
371
397
|
newSize.height === this.element.height &&
|
|
372
398
|
newSize.width === this.element.width) {
|
|
373
|
-
return;
|
|
399
|
+
return false;
|
|
374
400
|
}
|
|
375
|
-
const oldSize =
|
|
401
|
+
const oldSize = { ...size };
|
|
376
402
|
this.element.width = size.width = this.element.offsetWidth * pxRatio;
|
|
377
403
|
this.element.height = size.height = this.element.offsetHeight * pxRatio;
|
|
378
404
|
if (this.container.started) {
|
|
@@ -381,18 +407,22 @@ export class Canvas {
|
|
|
381
407
|
height: size.height / oldSize.height,
|
|
382
408
|
};
|
|
383
409
|
}
|
|
410
|
+
return true;
|
|
384
411
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
412
|
+
stop() {
|
|
413
|
+
this._safeMutationObserver((obs) => obs.disconnect());
|
|
414
|
+
this._mutationObserver = undefined;
|
|
415
|
+
this.draw((ctx) => clear(ctx, this.size));
|
|
416
|
+
}
|
|
417
|
+
async windowResize() {
|
|
418
|
+
if (!this.element || !this.resize()) {
|
|
388
419
|
return;
|
|
389
420
|
}
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
element.style.setProperty("height", "100%", priority);
|
|
421
|
+
const container = this.container, needsRefresh = container.updateActualOptions();
|
|
422
|
+
container.particles.setDensity();
|
|
423
|
+
this._applyResizePlugins();
|
|
424
|
+
if (needsRefresh) {
|
|
425
|
+
await container.refresh();
|
|
426
|
+
}
|
|
397
427
|
}
|
|
398
428
|
}
|