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