@tsparticles/engine 4.0.0-alpha.26 → 4.0.0-alpha.27

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.
Files changed (101) hide show
  1. package/164.min.js +1 -0
  2. package/README.md +1 -1
  3. package/browser/Core/Canvas.js +7 -4
  4. package/browser/Core/Engine.js +8 -1
  5. package/browser/Core/Interfaces/IPalette.js +1 -0
  6. package/browser/Core/Particle.js +8 -12
  7. package/browser/Core/Utils/Constants.js +1 -1
  8. package/browser/Options/Classes/ColorAnimation.js +11 -1
  9. package/browser/Options/Classes/HslAnimation.js +4 -3
  10. package/browser/Options/Classes/Options.js +38 -1
  11. package/browser/Options/Classes/Particles/Effect/Effect.js +0 -5
  12. package/browser/Options/Classes/Particles/Fill.js +28 -0
  13. package/browser/Options/Classes/Particles/ParticlesOptions.js +12 -6
  14. package/browser/Options/Classes/Particles/Shape/Shape.js +0 -5
  15. package/browser/Options/Interfaces/Particles/IFill.js +1 -0
  16. package/browser/Utils/CanvasUtils.js +5 -5
  17. package/browser/Utils/ColorUtils.js +22 -19
  18. package/browser/Utils/Utils.js +86 -13
  19. package/browser/exports.js +1 -0
  20. package/cjs/Core/Canvas.js +7 -4
  21. package/cjs/Core/Engine.js +8 -1
  22. package/cjs/Core/Interfaces/IPalette.js +1 -0
  23. package/cjs/Core/Particle.js +8 -12
  24. package/cjs/Core/Utils/Constants.js +1 -1
  25. package/cjs/Options/Classes/ColorAnimation.js +11 -1
  26. package/cjs/Options/Classes/HslAnimation.js +4 -3
  27. package/cjs/Options/Classes/Options.js +38 -1
  28. package/cjs/Options/Classes/Particles/Effect/Effect.js +0 -5
  29. package/cjs/Options/Classes/Particles/Fill.js +28 -0
  30. package/cjs/Options/Classes/Particles/ParticlesOptions.js +12 -6
  31. package/cjs/Options/Classes/Particles/Shape/Shape.js +0 -5
  32. package/cjs/Options/Interfaces/Particles/IFill.js +1 -0
  33. package/cjs/Utils/CanvasUtils.js +5 -5
  34. package/cjs/Utils/ColorUtils.js +22 -19
  35. package/cjs/Utils/Utils.js +86 -13
  36. package/cjs/exports.js +1 -0
  37. package/dist_browser_Core_Container_js.js +3 -3
  38. package/esm/Core/Canvas.js +7 -4
  39. package/esm/Core/Engine.js +8 -1
  40. package/esm/Core/Interfaces/IPalette.js +1 -0
  41. package/esm/Core/Particle.js +8 -12
  42. package/esm/Core/Utils/Constants.js +1 -1
  43. package/esm/Options/Classes/ColorAnimation.js +11 -1
  44. package/esm/Options/Classes/HslAnimation.js +4 -3
  45. package/esm/Options/Classes/Options.js +38 -1
  46. package/esm/Options/Classes/Particles/Effect/Effect.js +0 -5
  47. package/esm/Options/Classes/Particles/Fill.js +28 -0
  48. package/esm/Options/Classes/Particles/ParticlesOptions.js +12 -6
  49. package/esm/Options/Classes/Particles/Shape/Shape.js +0 -5
  50. package/esm/Options/Interfaces/Particles/IFill.js +1 -0
  51. package/esm/Utils/CanvasUtils.js +5 -5
  52. package/esm/Utils/ColorUtils.js +22 -19
  53. package/esm/Utils/Utils.js +86 -13
  54. package/esm/exports.js +1 -0
  55. package/package.json +1 -1
  56. package/report.html +1 -1
  57. package/scripts/install.js +2 -18
  58. package/tsparticles.engine.js +30 -20
  59. package/tsparticles.engine.min.js +2 -2
  60. package/types/Core/Engine.d.ts +4 -0
  61. package/types/Core/Interfaces/IPalette.d.ts +7 -0
  62. package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
  63. package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
  64. package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
  65. package/types/Core/Particle.d.ts +3 -3
  66. package/types/Core/Utils/Constants.d.ts +1 -1
  67. package/types/Options/Classes/ColorAnimation.d.ts +3 -1
  68. package/types/Options/Classes/Options.d.ts +2 -0
  69. package/types/Options/Classes/Particles/Effect/Effect.d.ts +0 -1
  70. package/types/Options/Classes/Particles/Fill.d.ts +12 -0
  71. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +2 -2
  72. package/types/Options/Classes/Particles/Shape/Shape.d.ts +0 -1
  73. package/types/Options/Interfaces/IColorAnimation.d.ts +2 -0
  74. package/types/Options/Interfaces/IOptions.d.ts +1 -0
  75. package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +0 -1
  76. package/types/Options/Interfaces/Particles/IFill.d.ts +9 -0
  77. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -2
  78. package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -2
  79. package/types/Options/Interfaces/Particles/Shape/IShape.d.ts +0 -1
  80. package/types/Utils/ColorUtils.d.ts +1 -2
  81. package/types/Utils/Utils.d.ts +7 -0
  82. package/types/export-types.d.ts +2 -1
  83. package/types/exports.d.ts +1 -0
  84. package/umd/Core/Canvas.js +6 -3
  85. package/umd/Core/Engine.js +8 -1
  86. package/umd/Core/Interfaces/IPalette.js +12 -0
  87. package/umd/Core/Particle.js +8 -12
  88. package/umd/Core/Utils/Constants.js +2 -2
  89. package/umd/Options/Classes/ColorAnimation.js +11 -1
  90. package/umd/Options/Classes/HslAnimation.js +5 -4
  91. package/umd/Options/Classes/Options.js +38 -1
  92. package/umd/Options/Classes/Particles/Effect/Effect.js +0 -5
  93. package/umd/Options/Classes/Particles/Fill.js +42 -0
  94. package/umd/Options/Classes/Particles/ParticlesOptions.js +13 -7
  95. package/umd/Options/Classes/Particles/Shape/Shape.js +0 -5
  96. package/umd/Options/Interfaces/Particles/IFill.js +12 -0
  97. package/umd/Utils/CanvasUtils.js +5 -5
  98. package/umd/Utils/ColorUtils.js +21 -18
  99. package/umd/Utils/Utils.js +87 -13
  100. package/umd/exports.js +2 -1
  101. package/622.min.js +0 -1
@@ -175,14 +175,14 @@
175
175
  if (radius <= Constants_js_1.minimumSize) {
176
176
  return;
177
177
  }
178
- const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor() ?? pfColor;
178
+ const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
179
179
  let [fColor, sColor] = this._getPluginParticleColors(particle);
180
180
  fColor ??= pfColor;
181
181
  sColor ??= psColor;
182
182
  if (!fColor && !sColor) {
183
183
  return;
184
184
  }
185
- const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - particle.zIndexFactor, { opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, container.hdr, opacity) : undefined, stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, container.hdr, strokeOpacity) : fill;
185
+ const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, container.hdr, strokeOpacity * opacity) : fill;
186
186
  transform.a = transform.b = transform.c = transform.d = undefined;
187
187
  colorStyles.fill = fill;
188
188
  colorStyles.stroke = stroke;
@@ -369,6 +369,9 @@
369
369
  willReadFrequently: false,
370
370
  };
371
371
  this._context = this.element.getContext("2d", this._canvasSettings);
372
+ if (this._context) {
373
+ this._context.globalCompositeOperation = Constants_js_1.defaultCompositeValue;
374
+ }
372
375
  this._safeMutationObserver(obs => {
373
376
  obs.disconnect();
374
377
  });
@@ -526,7 +529,7 @@
526
529
  this._resetOriginalStyle();
527
530
  }
528
531
  for (const key in options.style) {
529
- if (!key || !Object.hasOwn(options.style, key)) {
532
+ if (!key || !(key in options.style)) {
530
533
  continue;
531
534
  }
532
535
  const value = options.style[key];
@@ -106,6 +106,7 @@ var __importStar = (this && this.__importStar) || (function () {
106
106
  shapes: new Map(),
107
107
  updaters: new Map(),
108
108
  };
109
+ palettes = new Map();
109
110
  plugins = [];
110
111
  presets = new Map();
111
112
  shapeDrawers = new Map();
@@ -129,7 +130,7 @@ var __importStar = (this && this.__importStar) || (function () {
129
130
  return this._domArray;
130
131
  }
131
132
  get version() {
132
- return "4.0.0-alpha.26";
133
+ return "4.0.0-alpha.27";
133
134
  }
134
135
  addColorManager(name, manager) {
135
136
  this.colorManagers.set(name, manager);
@@ -151,6 +152,9 @@ var __importStar = (this && this.__importStar) || (function () {
151
152
  addEventListener(type, listener) {
152
153
  this._eventDispatcher.addEventListener(type, listener);
153
154
  }
155
+ addPalette(name, palette) {
156
+ this.palettes.set(name, palette);
157
+ }
154
158
  addParticleUpdater(name, updaterInitializer) {
155
159
  this.initializers.updaters.set(name, updaterInitializer);
156
160
  }
@@ -191,6 +195,9 @@ var __importStar = (this && this.__importStar) || (function () {
191
195
  getEffectDrawers(container, force = false) {
192
196
  return (0, Utils_js_1.getItemMapFromInitializer)(container, this.effectDrawers, this.initializers.effects, force);
193
197
  }
198
+ getPalette(name) {
199
+ return this.palettes.get(name);
200
+ }
194
201
  getPlugin(plugin) {
195
202
  return this.plugins.find(t => t.id === plugin);
196
203
  }
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -24,14 +24,12 @@
24
24
  const effectData = effectOptions.options[effect];
25
25
  return (0, Utils_js_1.deepExtend)({
26
26
  close: effectOptions.close,
27
- fill: effectOptions.fill,
28
27
  }, (0, Utils_js_1.itemFromSingleOrMultiple)(effectData, id, reduceDuplicates));
29
28
  }
30
29
  function loadShapeData(shape, shapeOptions, id, reduceDuplicates) {
31
30
  const shapeData = shapeOptions.options[shape];
32
31
  return (0, Utils_js_1.deepExtend)({
33
32
  close: shapeOptions.close,
34
- fill: shapeOptions.fill,
35
33
  }, (0, Utils_js_1.itemFromSingleOrMultiple)(shapeData, id, reduceDuplicates));
36
34
  }
37
35
  function fixOutMode(data) {
@@ -50,13 +48,14 @@
50
48
  container;
51
49
  backColor;
52
50
  bubble;
53
- color;
54
51
  destroyed;
55
52
  direction;
56
53
  effect;
57
54
  effectClose;
58
55
  effectData;
59
- effectFill;
56
+ fillColor;
57
+ fillEnabled;
58
+ fillOpacity;
60
59
  group;
61
60
  id;
62
61
  ignoresResizeRatio;
@@ -79,7 +78,6 @@
79
78
  shape;
80
79
  shapeClose;
81
80
  shapeData;
82
- shapeFill;
83
81
  sides;
84
82
  size;
85
83
  slow;
@@ -91,6 +89,7 @@
91
89
  velocity;
92
90
  zIndexFactor;
93
91
  _cachedOpacityData = {
92
+ fillOpacity: Constants_js_1.defaultOpacity,
94
93
  opacity: Constants_js_1.defaultOpacity,
95
94
  strokeOpacity: Constants_js_1.defaultOpacity,
96
95
  };
@@ -138,15 +137,16 @@
138
137
  return this.rotation + (this.pathRotation ? this.velocity.angle : Constants_js_1.defaultAngle);
139
138
  }
140
139
  getFillColor() {
141
- return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
140
+ return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.fillColor));
142
141
  }
143
142
  getMass() {
144
143
  return this.getRadius() ** Constants_js_1.squareExp * Math.PI * Constants_js_1.half;
145
144
  }
146
145
  getOpacity() {
147
- const zIndexOptions = this.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? (0, MathUtils_js_1.getRangeValue)(this.opacity?.value ?? Constants_js_1.defaultOpacity), strokeOpacity = this.strokeOpacity ?? opacity;
146
+ const zIndexOptions = this.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? (0, MathUtils_js_1.getRangeValue)(this.opacity?.value ?? Constants_js_1.defaultOpacity), fillOpacity = this.fillOpacity ?? Constants_js_1.defaultOpacity, strokeOpacity = this.strokeOpacity ?? Constants_js_1.defaultOpacity;
147
+ this._cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
148
148
  this._cachedOpacityData.opacity = opacity * zOpacityFactor;
149
- this._cachedOpacityData.strokeOpacity = strokeOpacity * zOpacityFactor;
149
+ this._cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
150
150
  return this._cachedOpacityData;
151
151
  }
152
152
  getPosition() {
@@ -184,9 +184,7 @@
184
184
  this.id = id;
185
185
  this.group = group;
186
186
  this.effectClose = true;
187
- this.effectFill = true;
188
187
  this.shapeClose = true;
189
- this.shapeFill = true;
190
188
  this.pathRotation = false;
191
189
  this.lastPathTime = 0;
192
190
  this.destroyed = false;
@@ -238,9 +236,7 @@
238
236
  if (shapeData) {
239
237
  particlesOptions.load(shapeData.particles);
240
238
  }
241
- this.effectFill = effectData?.fill ?? particlesOptions.effect.fill;
242
239
  this.effectClose = effectData?.close ?? particlesOptions.effect.close;
243
- this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;
244
240
  this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
245
241
  this.options = particlesOptions;
246
242
  container.retina.initParticle(this);
@@ -9,8 +9,8 @@
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.defaultZoom = exports.defaultTime = exports.defaultLoops = exports.defaultVelocity = exports.defaultRgbMin = exports.phaseNumerator = exports.sNormalizedOffset = exports.sextuple = exports.triple = exports.lMin = exports.lFactor = exports.minStrokeWidth = exports.identity = exports.defaultAngle = exports.manualDefaultPosition = exports.touchDelay = exports.deleteCount = exports.defaultDensityFactor = exports.lengthOffset = exports.minIndex = exports.minCount = exports.countOffset = exports.minLimit = exports.sizeFactor = exports.posOffset = exports.defaultRadius = exports.minZ = exports.minRetries = exports.tryCountIncrement = exports.decayOffset = exports.none = exports.one = exports.loadMinIndex = exports.loadRandomFactor = exports.canvasFirstIndex = exports.minFpsLimit = exports.defaultFpsLimit = exports.removeMinIndex = exports.removeDeleteCount = exports.minCoordinate = exports.touchEndLengthOffset = exports.clickRadius = exports.defaultOpacity = exports.zIndexFactorOffset = exports.minimumLength = exports.minimumSize = exports.defaultTransformValue = exports.minVelocity = exports.threeQuarter = exports.quarter = exports.empty = exports.hPhase = exports.sMin = exports.hMin = exports.lMax = exports.sMax = exports.hMax = exports.rgbMax = exports.inverseFactorNumerator = exports.subdivideCount = exports.defaultReduceFactor = exports.defaultRatio = exports.defaultRemoveQuantity = exports.spatialHashGridCellSize = exports.qTreeCapacity = exports.squareExp = exports.defaultRetryCount = exports.canvasTag = exports.generatedFalse = exports.generatedTrue = exports.defaultAlpha = exports.defaultFps = exports.doublePI = exports.double = exports.midColorValue = exports.randomColorValue = exports.defaultTransform = exports.originPoint = exports.millisecondsToSeconds = exports.half = exports.percentDenominator = exports.visibilityChangeEvent = exports.resizeEvent = exports.generatedAttribute = void 0;
13
- exports.generatedAttribute = "generated", exports.resizeEvent = "resize", exports.visibilityChangeEvent = "visibilitychange", exports.percentDenominator = 100, exports.half = 0.5, exports.millisecondsToSeconds = 1000, exports.originPoint = {
12
+ exports.defaultZoom = exports.defaultTime = exports.defaultLoops = exports.defaultVelocity = exports.defaultRgbMin = exports.phaseNumerator = exports.sNormalizedOffset = exports.sextuple = exports.triple = exports.lMin = exports.lFactor = exports.minStrokeWidth = exports.identity = exports.defaultAngle = exports.manualDefaultPosition = exports.touchDelay = exports.deleteCount = exports.defaultDensityFactor = exports.lengthOffset = exports.minIndex = exports.minCount = exports.countOffset = exports.minLimit = exports.sizeFactor = exports.posOffset = exports.defaultRadius = exports.minZ = exports.minRetries = exports.tryCountIncrement = exports.decayOffset = exports.none = exports.one = exports.loadMinIndex = exports.loadRandomFactor = exports.canvasFirstIndex = exports.minFpsLimit = exports.defaultFpsLimit = exports.removeMinIndex = exports.removeDeleteCount = exports.minCoordinate = exports.touchEndLengthOffset = exports.clickRadius = exports.defaultOpacity = exports.zIndexFactorOffset = exports.minimumLength = exports.minimumSize = exports.defaultTransformValue = exports.minVelocity = exports.threeQuarter = exports.quarter = exports.empty = exports.hPhase = exports.sMin = exports.hMin = exports.lMax = exports.sMax = exports.hMax = exports.rgbMax = exports.inverseFactorNumerator = exports.subdivideCount = exports.defaultReduceFactor = exports.defaultRatio = exports.defaultRemoveQuantity = exports.spatialHashGridCellSize = exports.qTreeCapacity = exports.squareExp = exports.defaultRetryCount = exports.canvasTag = exports.generatedFalse = exports.generatedTrue = exports.defaultAlpha = exports.defaultFps = exports.doublePI = exports.double = exports.midColorValue = exports.randomColorValue = exports.defaultTransform = exports.originPoint = exports.millisecondsToSeconds = exports.half = exports.percentDenominator = exports.visibilityChangeEvent = exports.resizeEvent = exports.defaultCompositeValue = exports.generatedAttribute = void 0;
13
+ exports.generatedAttribute = "generated", exports.defaultCompositeValue = "source-over", exports.resizeEvent = "resize", exports.visibilityChangeEvent = "visibilitychange", exports.percentDenominator = 100, exports.half = 0.5, exports.millisecondsToSeconds = 1000, exports.originPoint = {
14
14
  x: 0,
15
15
  y: 0,
16
16
  z: 0,
@@ -14,9 +14,13 @@
14
14
  const TypeUtils_js_1 = require("../../Utils/TypeUtils.js");
15
15
  const MathUtils_js_1 = require("../../Utils/MathUtils.js");
16
16
  class ColorAnimation extends AnimationOptions_js_1.AnimationOptions {
17
+ max;
18
+ min;
17
19
  offset;
18
- constructor() {
20
+ constructor(min, max) {
19
21
  super();
22
+ this.min = min;
23
+ this.max = max;
20
24
  this.offset = 0;
21
25
  this.sync = true;
22
26
  }
@@ -25,6 +29,12 @@
25
29
  if ((0, TypeUtils_js_1.isNull)(data)) {
26
30
  return;
27
31
  }
32
+ if (data.max !== undefined) {
33
+ this.max = data.max;
34
+ }
35
+ if (data.min !== undefined) {
36
+ this.min = data.min;
37
+ }
28
38
  if (data.offset !== undefined) {
29
39
  this.offset = (0, MathUtils_js_1.setRangeValue)(data.offset);
30
40
  }
@@ -4,18 +4,19 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./ColorAnimation.js", "../../Utils/TypeUtils.js"], factory);
7
+ define(["require", "exports", "../../Core/Utils/Constants.js", "./ColorAnimation.js", "../../Utils/TypeUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.HslAnimation = void 0;
13
+ const Constants_js_1 = require("../../Core/Utils/Constants.js");
13
14
  const ColorAnimation_js_1 = require("./ColorAnimation.js");
14
15
  const TypeUtils_js_1 = require("../../Utils/TypeUtils.js");
15
16
  class HslAnimation {
16
- h = new ColorAnimation_js_1.ColorAnimation();
17
- l = new ColorAnimation_js_1.ColorAnimation();
18
- s = new ColorAnimation_js_1.ColorAnimation();
17
+ h = new ColorAnimation_js_1.ColorAnimation(Constants_js_1.hMin, Constants_js_1.hMax);
18
+ l = new ColorAnimation_js_1.ColorAnimation(Constants_js_1.lMin, Constants_js_1.lMax);
19
+ s = new ColorAnimation_js_1.ColorAnimation(Constants_js_1.sMin, Constants_js_1.sMax);
19
20
  load(data) {
20
21
  if ((0, TypeUtils_js_1.isNull)(data)) {
21
22
  return;
@@ -30,6 +30,7 @@
30
30
  hdr;
31
31
  key;
32
32
  name;
33
+ palette;
33
34
  particles;
34
35
  pauseOnBlur;
35
36
  pauseOnOutsideViewport;
@@ -66,10 +67,15 @@
66
67
  return;
67
68
  }
68
69
  if (data.preset !== undefined) {
69
- (0, Utils_js_1.executeOnSingleOrMultiple)(data.preset, preset => {
70
+ this.preset = data.preset;
71
+ (0, Utils_js_1.executeOnSingleOrMultiple)(this.preset, preset => {
70
72
  this._importPreset(preset);
71
73
  });
72
74
  }
75
+ if (data.palette !== undefined) {
76
+ this.palette = data.palette;
77
+ this._importPalette(this.palette);
78
+ }
73
79
  if (data.autoPlay !== undefined) {
74
80
  this.autoPlay = data.autoPlay;
75
81
  }
@@ -126,6 +132,37 @@
126
132
  plugin.loadOptions(this._container, this, data);
127
133
  });
128
134
  }
135
+ _importPalette = palette => {
136
+ const paletteData = this._engine.getPalette(palette);
137
+ if (!paletteData) {
138
+ return;
139
+ }
140
+ this.load({
141
+ background: {
142
+ color: paletteData.background,
143
+ },
144
+ blend: {
145
+ enable: true,
146
+ mode: paletteData.blendMode,
147
+ },
148
+ particles: {
149
+ fill: {
150
+ color: paletteData.fill
151
+ ? {
152
+ value: paletteData.colors,
153
+ }
154
+ : undefined,
155
+ enable: paletteData.fill,
156
+ },
157
+ stroke: !paletteData.fill
158
+ ? paletteData.colors.map(color => ({
159
+ color: { value: color },
160
+ width: 1,
161
+ }))
162
+ : undefined,
163
+ },
164
+ });
165
+ };
129
166
  _importPreset = preset => {
130
167
  this.load(this._engine.getPreset(preset));
131
168
  };
@@ -14,12 +14,10 @@
14
14
  const TypeUtils_js_1 = require("../../../../Utils/TypeUtils.js");
15
15
  class Effect {
16
16
  close;
17
- fill;
18
17
  options;
19
18
  type;
20
19
  constructor() {
21
20
  this.close = true;
22
- this.fill = true;
23
21
  this.options = {};
24
22
  this.type = [];
25
23
  }
@@ -39,9 +37,6 @@
39
37
  if (data.close !== undefined) {
40
38
  this.close = data.close;
41
39
  }
42
- if (data.fill !== undefined) {
43
- this.fill = data.fill;
44
- }
45
40
  if (data.type !== undefined) {
46
41
  this.type = data.type;
47
42
  }
@@ -0,0 +1,42 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../AnimatableColor.js", "../../../Utils/TypeUtils.js", "../../../Utils/MathUtils.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Fill = void 0;
13
+ const AnimatableColor_js_1 = require("../AnimatableColor.js");
14
+ const TypeUtils_js_1 = require("../../../Utils/TypeUtils.js");
15
+ const MathUtils_js_1 = require("../../../Utils/MathUtils.js");
16
+ class Fill {
17
+ color;
18
+ enable;
19
+ opacity;
20
+ constructor() {
21
+ this.enable = true;
22
+ this.color = new AnimatableColor_js_1.AnimatableColor();
23
+ this.color.value = "#fff";
24
+ this.opacity = 1;
25
+ }
26
+ load(data) {
27
+ if ((0, TypeUtils_js_1.isNull)(data)) {
28
+ return;
29
+ }
30
+ if (data.color !== undefined) {
31
+ this.color = AnimatableColor_js_1.AnimatableColor.create(this.color, data.color);
32
+ }
33
+ if (data.enable !== undefined) {
34
+ this.enable = data.enable;
35
+ }
36
+ if (data.opacity !== undefined) {
37
+ this.opacity = (0, MathUtils_js_1.setRangeValue)(data.opacity);
38
+ }
39
+ }
40
+ }
41
+ exports.Fill = Fill;
42
+ });
@@ -4,15 +4,15 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../../../Utils/Utils.js", "../AnimatableColor.js", "./Effect/Effect.js", "./Move/Move.js", "./Opacity/Opacity.js", "./Bounce/ParticlesBounce.js", "./Number/ParticlesNumber.js", "./Shape/Shape.js", "./Size/Size.js", "./Stroke.js", "./ZIndex/ZIndex.js", "../../../Utils/TypeUtils.js"], factory);
7
+ define(["require", "exports", "../../../Utils/Utils.js", "./Effect/Effect.js", "./Fill.js", "./Move/Move.js", "./Opacity/Opacity.js", "./Bounce/ParticlesBounce.js", "./Number/ParticlesNumber.js", "./Shape/Shape.js", "./Size/Size.js", "./Stroke.js", "./ZIndex/ZIndex.js", "../../../Utils/TypeUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ParticlesOptions = void 0;
13
13
  const Utils_js_1 = require("../../../Utils/Utils.js");
14
- const AnimatableColor_js_1 = require("../AnimatableColor.js");
15
14
  const Effect_js_1 = require("./Effect/Effect.js");
15
+ const Fill_js_1 = require("./Fill.js");
16
16
  const Move_js_1 = require("./Move/Move.js");
17
17
  const Opacity_js_1 = require("./Opacity/Opacity.js");
18
18
  const ParticlesBounce_js_1 = require("./Bounce/ParticlesBounce.js");
@@ -24,8 +24,8 @@
24
24
  const TypeUtils_js_1 = require("../../../Utils/TypeUtils.js");
25
25
  class ParticlesOptions {
26
26
  bounce;
27
- color;
28
27
  effect;
28
+ fill;
29
29
  groups;
30
30
  move;
31
31
  number;
@@ -41,9 +41,8 @@
41
41
  this._engine = engine;
42
42
  this._container = container;
43
43
  this.bounce = new ParticlesBounce_js_1.ParticlesBounce();
44
- this.color = new AnimatableColor_js_1.AnimatableColor();
45
- this.color.value = "#fff";
46
44
  this.effect = new Effect_js_1.Effect();
45
+ this.fill = new Fill_js_1.Fill();
47
46
  this.groups = {};
48
47
  this.move = new Move_js_1.Move();
49
48
  this.number = new ParticlesNumber_js_1.ParticlesNumber();
@@ -60,7 +59,7 @@
60
59
  }
61
60
  if (data.groups !== undefined) {
62
61
  for (const group of Object.keys(data.groups)) {
63
- if (!Object.hasOwn(data.groups, group)) {
62
+ if (!(group in data.groups)) {
64
63
  continue;
65
64
  }
66
65
  const item = data.groups[group];
@@ -73,7 +72,6 @@
73
72
  this.reduceDuplicates = data.reduceDuplicates;
74
73
  }
75
74
  this.bounce.load(data.bounce);
76
- this.color.load(AnimatableColor_js_1.AnimatableColor.create(this.color, data.color));
77
75
  this.effect.load(data.effect);
78
76
  this.move.load(data.move);
79
77
  this.number.load(data.number);
@@ -81,6 +79,14 @@
81
79
  this.shape.load(data.shape);
82
80
  this.size.load(data.size);
83
81
  this.zIndex.load(data.zIndex);
82
+ const fillToLoad = data.fill;
83
+ if (fillToLoad) {
84
+ this.fill = (0, Utils_js_1.executeOnSingleOrMultiple)(fillToLoad, t => {
85
+ const tmp = new Fill_js_1.Fill();
86
+ tmp.load(t);
87
+ return tmp;
88
+ });
89
+ }
84
90
  const strokeToLoad = data.stroke;
85
91
  if (strokeToLoad) {
86
92
  this.stroke = (0, Utils_js_1.executeOnSingleOrMultiple)(strokeToLoad, t => {
@@ -14,12 +14,10 @@
14
14
  const TypeUtils_js_1 = require("../../../../Utils/TypeUtils.js");
15
15
  class Shape {
16
16
  close;
17
- fill;
18
17
  options;
19
18
  type;
20
19
  constructor() {
21
20
  this.close = true;
22
- this.fill = true;
23
21
  this.options = {};
24
22
  this.type = "circle";
25
23
  }
@@ -39,9 +37,6 @@
39
37
  if (data.close !== undefined) {
40
38
  this.close = data.close;
41
39
  }
42
- if (data.fill !== undefined) {
43
- this.fill = data.fill;
44
- }
45
40
  if (data.type !== undefined) {
46
41
  this.type = data.type;
47
42
  }
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -45,7 +45,7 @@
45
45
  if (colorStyles.fill) {
46
46
  context.fillStyle = colorStyles.fill;
47
47
  }
48
- const strokeWidth = particle.strokeWidth ?? Constants_js_1.minStrokeWidth;
48
+ const fillEnabled = !!particle.fillEnabled, strokeWidth = particle.strokeWidth ?? Constants_js_1.minStrokeWidth;
49
49
  context.lineWidth = strokeWidth;
50
50
  if (colorStyles.stroke) {
51
51
  context.strokeStyle = colorStyles.stroke;
@@ -58,8 +58,8 @@
58
58
  opacity,
59
59
  delta,
60
60
  pixelRatio: container.retina.pixelRatio,
61
- fill: particle.shapeFill,
62
- stroke: strokeWidth > Constants_js_1.minStrokeWidth || !particle.shapeFill,
61
+ fill: fillEnabled,
62
+ stroke: strokeWidth > Constants_js_1.minStrokeWidth,
63
63
  transformData,
64
64
  position: { ...pos },
65
65
  drawPosition,
@@ -100,7 +100,7 @@
100
100
  if (!drawer) {
101
101
  return;
102
102
  }
103
- const { context, particle, stroke } = data;
103
+ const { context, fill, particle, stroke } = data;
104
104
  if (!particle.shape) {
105
105
  return;
106
106
  }
@@ -112,7 +112,7 @@
112
112
  if (stroke) {
113
113
  context.stroke();
114
114
  }
115
- if (particle.shapeFill) {
115
+ if (fill) {
116
116
  context.fill();
117
117
  }
118
118
  }
@@ -221,10 +221,10 @@
221
221
  }
222
222
  function colorMix(color1, color2, size1, size2) {
223
223
  let rgb1 = color1, rgb2 = color2;
224
- if (!Object.hasOwn(rgb1, "r")) {
224
+ if (!("r" in rgb1)) {
225
225
  rgb1 = hslToRgb(color1);
226
226
  }
227
- if (!Object.hasOwn(rgb2, "r")) {
227
+ if (!("r" in rgb2)) {
228
228
  rgb2 = hslToRgb(color2);
229
229
  }
230
230
  return {
@@ -277,27 +277,33 @@
277
277
  }
278
278
  }
279
279
  function getHslFromAnimation(animation) {
280
- return animation !== undefined
281
- ? {
280
+ return animation === undefined
281
+ ? undefined
282
+ : {
282
283
  h: animation.h.value,
283
284
  s: animation.s.value,
284
285
  l: animation.l.value,
285
- }
286
- : undefined;
286
+ };
287
287
  }
288
288
  function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
289
289
  const resColor = {
290
290
  h: {
291
291
  enable: false,
292
292
  value: hsl.h,
293
+ min: Constants_js_1.hMin,
294
+ max: Constants_js_1.hMax,
293
295
  },
294
296
  s: {
295
297
  enable: false,
296
298
  value: hsl.s,
299
+ min: Constants_js_1.sMin,
300
+ max: Constants_js_1.sMax,
297
301
  },
298
302
  l: {
299
303
  enable: false,
300
304
  value: hsl.l,
305
+ min: Constants_js_1.lMin,
306
+ max: Constants_js_1.lMax,
301
307
  },
302
308
  };
303
309
  if (animationOptions) {
@@ -309,6 +315,8 @@
309
315
  }
310
316
  function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
311
317
  colorValue.enable = colorAnimation.enable;
318
+ colorValue.min = colorAnimation.min;
319
+ colorValue.max = colorAnimation.max;
312
320
  if (colorValue.enable) {
313
321
  colorValue.velocity = ((0, MathUtils_js_1.getRangeValue)(colorAnimation.speed) / Constants_js_1.percentDenominator) * reduceFactor;
314
322
  colorValue.decay = Constants_js_1.decayOffset - (0, MathUtils_js_1.getRangeValue)(colorAnimation.decay);
@@ -328,7 +336,7 @@
328
336
  colorValue.velocity = Constants_js_1.defaultVelocity;
329
337
  }
330
338
  }
331
- function updateColorValue(data, range, decrease, delta) {
339
+ function updateColorValue(data, decrease, delta) {
332
340
  const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
333
341
  if (!data.enable ||
334
342
  ((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
@@ -341,7 +349,7 @@
341
349
  if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
342
350
  return;
343
351
  }
344
- const offset = data.offset ? (0, MathUtils_js_1.randomInRangeValue)(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = (0, MathUtils_js_1.getRangeMax)(range), min = (0, MathUtils_js_1.getRangeMin)(range);
352
+ const offset = data.offset ? (0, MathUtils_js_1.randomInRangeValue)(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = data.max, min = data.min;
345
353
  if (!decrease || data.status === AnimationStatus_js_1.AnimationStatus.increasing) {
346
354
  data.value += velocity;
347
355
  if (data.value > max) {
@@ -357,8 +365,7 @@
357
365
  }
358
366
  else {
359
367
  data.value -= velocity;
360
- const minValue = 0;
361
- if (data.value < minValue) {
368
+ if (data.value < min) {
362
369
  data.loops ??= 0;
363
370
  data.loops++;
364
371
  data.status = AnimationStatus_js_1.AnimationStatus.increasing;
@@ -373,14 +380,10 @@
373
380
  if (!color) {
374
381
  return;
375
382
  }
376
- const { h, s, l } = color, ranges = {
377
- h: { min: Constants_js_1.hMin, max: Constants_js_1.hMax },
378
- s: { min: Constants_js_1.sMin, max: Constants_js_1.sMax },
379
- l: { min: Constants_js_1.lMin, max: Constants_js_1.lMax },
380
- };
381
- updateColorValue(h, ranges.h, false, delta);
382
- updateColorValue(s, ranges.s, true, delta);
383
- updateColorValue(l, ranges.l, true, delta);
383
+ const { h, s, l } = color;
384
+ updateColorValue(h, false, delta);
385
+ updateColorValue(s, true, delta);
386
+ updateColorValue(l, true, delta);
384
387
  }
385
388
  function alterHsl(color, type, value) {
386
389
  return {