@tsparticles/engine 3.6.0 → 3.7.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.
Files changed (63) hide show
  1. package/README.md +6 -1
  2. package/browser/Core/Canvas.js +32 -21
  3. package/browser/Core/Container.js +1 -1
  4. package/browser/Core/Engine.js +17 -1
  5. package/browser/Core/Particle.js +1 -1
  6. package/browser/Types/EasingFunction.js +1 -0
  7. package/browser/Utils/ColorUtils.js +25 -45
  8. package/browser/Utils/NumberUtils.js +1 -10
  9. package/browser/Utils/Utils.js +6 -0
  10. package/browser/exports.js +0 -2
  11. package/browser/init.js +0 -6
  12. package/cjs/Core/Canvas.js +32 -21
  13. package/cjs/Core/Container.js +1 -1
  14. package/cjs/Core/Engine.js +17 -1
  15. package/cjs/Core/Particle.js +1 -1
  16. package/cjs/Types/EasingFunction.js +2 -0
  17. package/cjs/Utils/ColorUtils.js +25 -46
  18. package/cjs/Utils/NumberUtils.js +1 -12
  19. package/cjs/Utils/Utils.js +7 -0
  20. package/cjs/exports.js +0 -2
  21. package/cjs/init.js +0 -6
  22. package/esm/Core/Canvas.js +32 -21
  23. package/esm/Core/Container.js +1 -1
  24. package/esm/Core/Engine.js +17 -1
  25. package/esm/Core/Particle.js +1 -1
  26. package/esm/Types/EasingFunction.js +1 -0
  27. package/esm/Utils/ColorUtils.js +25 -45
  28. package/esm/Utils/NumberUtils.js +1 -10
  29. package/esm/Utils/Utils.js +6 -0
  30. package/esm/exports.js +0 -2
  31. package/esm/init.js +0 -6
  32. package/package.json +1 -1
  33. package/report.html +1 -1
  34. package/tsparticles.engine.js +11 -31
  35. package/tsparticles.engine.min.js +1 -1
  36. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  37. package/types/Core/Canvas.d.ts +4 -1
  38. package/types/Core/Engine.d.ts +9 -1
  39. package/types/Types/EasingFunction.d.ts +1 -0
  40. package/types/Utils/ColorUtils.d.ts +8 -9
  41. package/types/Utils/NumberUtils.d.ts +0 -5
  42. package/types/Utils/Utils.d.ts +2 -0
  43. package/types/exports.d.ts +0 -2
  44. package/umd/Core/Canvas.js +32 -21
  45. package/umd/Core/Container.js +1 -1
  46. package/umd/Core/Engine.js +17 -1
  47. package/umd/Core/Particle.js +1 -1
  48. package/umd/Types/EasingFunction.js +12 -0
  49. package/umd/Utils/ColorUtils.js +25 -46
  50. package/umd/Utils/NumberUtils.js +1 -12
  51. package/umd/Utils/Utils.js +7 -0
  52. package/umd/exports.js +1 -3
  53. package/umd/init.js +1 -7
  54. package/browser/Utils/HslColorManager.js +0 -45
  55. package/browser/Utils/RgbColorManager.js +0 -44
  56. package/cjs/Utils/HslColorManager.js +0 -49
  57. package/cjs/Utils/RgbColorManager.js +0 -48
  58. package/esm/Utils/HslColorManager.js +0 -45
  59. package/esm/Utils/RgbColorManager.js +0 -44
  60. package/types/Utils/HslColorManager.d.ts +0 -10
  61. package/types/Utils/RgbColorManager.d.ts +0 -10
  62. package/umd/Utils/HslColorManager.js +0 -59
  63. package/umd/Utils/RgbColorManager.js +0 -58
package/README.md CHANGED
@@ -898,6 +898,12 @@ flowchart TD
898
898
  subgraph all-plugins [Plugins]
899
899
  plugin-canvas-mask[Canvas Mask]
900
900
 
901
+ subgraph all-plugins-colors [Colors]
902
+ plugin-hsv-color[HSV Color]
903
+ plugin-named-color[Named Color]
904
+ plugin-oklch-color[Oklch Color]
905
+ end
906
+
901
907
  subgraph all-plugins-easings [Easings]
902
908
  plugin-easing-back[Back]
903
909
  plugin-easing-circ[Circ]
@@ -921,7 +927,6 @@ flowchart TD
921
927
  plugin-export-video[Video]
922
928
  end
923
929
 
924
- plugin-hsv-color[HSV Color]
925
930
  plugin-infection[Infection]
926
931
  plugin-motion[Motion]
927
932
  plugin-poisson-disc[Poisson Disc]
@@ -26,7 +26,7 @@ function setStyle(canvas, style, important = false) {
26
26
  }
27
27
  }
28
28
  export class Canvas {
29
- constructor(container) {
29
+ constructor(container, engine) {
30
30
  this.container = container;
31
31
  this._applyPostDrawUpdaters = particle => {
32
32
  for (const updater of this._postDrawUpdaters) {
@@ -62,10 +62,10 @@ export class Canvas {
62
62
  let fColor, sColor;
63
63
  for (const plugin of this._colorPlugins) {
64
64
  if (!fColor && plugin.particleFillColor) {
65
- fColor = rangeColorToHsl(plugin.particleFillColor(particle));
65
+ fColor = rangeColorToHsl(this._engine, plugin.particleFillColor(particle));
66
66
  }
67
67
  if (!sColor && plugin.particleStrokeColor) {
68
- sColor = rangeColorToHsl(plugin.particleStrokeColor(particle));
68
+ sColor = rangeColorToHsl(this._engine, plugin.particleStrokeColor(particle));
69
69
  }
70
70
  if (fColor && sColor) {
71
71
  break;
@@ -76,7 +76,7 @@ export class Canvas {
76
76
  this._initCover = async () => {
77
77
  const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color;
78
78
  if (color) {
79
- const coverRgb = rangeColorToRgb(color);
79
+ const coverRgb = rangeColorToRgb(this._engine, color);
80
80
  if (coverRgb) {
81
81
  const coverColor = {
82
82
  ...coverRgb,
@@ -135,7 +135,7 @@ export class Canvas {
135
135
  }
136
136
  const factorNumerator = 1, opacity = factorNumerator / trail.length;
137
137
  if (trailFill.color) {
138
- const fillColor = rangeColorToRgb(trailFill.color);
138
+ const fillColor = rangeColorToRgb(this._engine, trailFill.color);
139
139
  if (!fillColor) {
140
140
  return;
141
141
  }
@@ -216,10 +216,16 @@ export class Canvas {
216
216
  height: "100%",
217
217
  }, true);
218
218
  };
219
- this.size = {
219
+ this._engine = engine;
220
+ this._standardSize = {
220
221
  height: 0,
221
222
  width: 0,
222
223
  };
224
+ const pxRatio = container.retina.pixelRatio, stdSize = this._standardSize;
225
+ this.size = {
226
+ height: stdSize.height * pxRatio,
227
+ width: stdSize.width * pxRatio,
228
+ };
223
229
  this._context = null;
224
230
  this._generated = false;
225
231
  this._preDrawUpdaters = [];
@@ -363,7 +369,7 @@ export class Canvas {
363
369
  return;
364
370
  }
365
371
  if (background.color) {
366
- const color = rangeColorToRgb(background.color);
372
+ const color = rangeColorToRgb(this._engine, background.color);
367
373
  elementStyle.backgroundColor = color ? getStyleFromRgb(color, background.opacity) : "";
368
374
  }
369
375
  else {
@@ -408,8 +414,13 @@ export class Canvas {
408
414
  this.element = canvas;
409
415
  this.element.ariaHidden = "true";
410
416
  this._originalStyle = deepExtend({}, this.element.style);
411
- this.size.height = canvas.offsetHeight;
412
- this.size.width = canvas.offsetWidth;
417
+ const standardSize = this._standardSize;
418
+ standardSize.height = canvas.offsetHeight;
419
+ standardSize.width = canvas.offsetWidth;
420
+ const pxRatio = this.container.retina.pixelRatio;
421
+ const retinaSize = this.size;
422
+ retinaSize.height = standardSize.height * pxRatio;
423
+ retinaSize.width = standardSize.width * pxRatio;
413
424
  this._context = this.element.getContext("2d");
414
425
  this._safeMutationObserver(obs => {
415
426
  if (!this.element || !(this.element instanceof Node)) {
@@ -444,23 +455,23 @@ export class Canvas {
444
455
  if (!this.element) {
445
456
  return false;
446
457
  }
447
- const container = this.container, pxRatio = container.retina.pixelRatio, size = container.canvas.size, newSize = {
448
- width: this.element.offsetWidth * pxRatio,
449
- height: this.element.offsetHeight * pxRatio,
458
+ const container = this.container, currentSize = container.canvas._standardSize, newSize = {
459
+ width: this.element.offsetWidth,
460
+ height: this.element.offsetHeight,
450
461
  };
451
- if (newSize.height === size.height &&
452
- newSize.width === size.width &&
453
- newSize.height === this.element.height &&
454
- newSize.width === this.element.width) {
462
+ if (newSize.height === currentSize.height && newSize.width === currentSize.width) {
455
463
  return false;
456
464
  }
457
- const oldSize = { ...size };
458
- this.element.width = size.width = this.element.offsetWidth * pxRatio;
459
- this.element.height = size.height = this.element.offsetHeight * pxRatio;
465
+ const oldSize = { ...currentSize }, pxRatio = container.retina.pixelRatio;
466
+ currentSize.height = newSize.height;
467
+ currentSize.width = newSize.width;
468
+ const retinaSize = this.size;
469
+ this.element.width = retinaSize.width = currentSize.width * pxRatio;
470
+ this.element.height = retinaSize.height = currentSize.height * pxRatio;
460
471
  if (this.container.started) {
461
472
  container.particles.setResizeFactor({
462
- width: size.width / oldSize.width,
463
- height: size.height / oldSize.height,
473
+ width: currentSize.width / oldSize.width,
474
+ height: currentSize.height / oldSize.height,
464
475
  });
465
476
  }
466
477
  return true;
@@ -88,7 +88,7 @@ export class Container {
88
88
  this._sourceOptions = sourceOptions;
89
89
  this._initialSourceOptions = sourceOptions;
90
90
  this.retina = new Retina(this);
91
- this.canvas = new Canvas(this);
91
+ this.canvas = new Canvas(this, this._engine);
92
92
  this.particles = new Particles(this._engine, this);
93
93
  this.pathGenerators = new Map();
94
94
  this.interactivity = {
@@ -71,6 +71,8 @@ export class Engine {
71
71
  this._eventDispatcher = new EventDispatcher();
72
72
  this._initialized = false;
73
73
  this.plugins = [];
74
+ this.colorManagers = new Map();
75
+ this.easingFunctions = new Map();
74
76
  this._initializers = {
75
77
  interactors: new Map(),
76
78
  movers: new Map(),
@@ -95,13 +97,24 @@ export class Engine {
95
97
  return this._domArray;
96
98
  }
97
99
  get version() {
98
- return "3.6.0";
100
+ return "3.7.0";
101
+ }
102
+ async addColorManager(manager, refresh = true) {
103
+ this.colorManagers.set(manager.key, manager);
104
+ await this.refresh(refresh);
99
105
  }
100
106
  addConfig(config) {
101
107
  const key = config.key ?? config.name ?? "default";
102
108
  this._configs.set(key, config);
103
109
  this._eventDispatcher.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
104
110
  }
111
+ async addEasing(name, easing, refresh = true) {
112
+ if (this.getEasing(name)) {
113
+ return;
114
+ }
115
+ this.easingFunctions.set(name, easing);
116
+ await this.refresh(refresh);
117
+ }
105
118
  async addEffect(effect, drawer, refresh = true) {
106
119
  executeOnSingleOrMultiple(effect, type => {
107
120
  if (!this.getEffectDrawer(type)) {
@@ -175,6 +188,9 @@ export class Engine {
175
188
  }
176
189
  return res;
177
190
  }
191
+ getEasing(name) {
192
+ return this.easingFunctions.get(name) ?? ((value) => value);
193
+ }
178
194
  getEffectDrawer(type) {
179
195
  return this.effectDrawers.get(type);
180
196
  }
@@ -325,7 +325,7 @@ export class Particle {
325
325
  this.sides = sideCountFunc(this);
326
326
  }
327
327
  this.spawning = false;
328
- this.shadowColor = rangeColorToRgb(this.options.shadow.color);
328
+ this.shadowColor = rangeColorToRgb(this._engine, this.options.shadow.color);
329
329
  for (const updater of particles.updaters) {
330
330
  updater.init(this);
331
331
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -3,83 +3,63 @@ import { isArray, isString } from "./TypeUtils.js";
3
3
  import { millisecondsToSeconds, percentDenominator } from "../Core/Utils/Constants.js";
4
4
  import { AnimationStatus } from "../Enums/AnimationStatus.js";
5
5
  import { itemFromArray } from "./Utils.js";
6
- var RgbIndexes;
7
- (function (RgbIndexes) {
8
- RgbIndexes[RgbIndexes["r"] = 1] = "r";
9
- RgbIndexes[RgbIndexes["g"] = 2] = "g";
10
- RgbIndexes[RgbIndexes["b"] = 3] = "b";
11
- RgbIndexes[RgbIndexes["a"] = 4] = "a";
12
- })(RgbIndexes || (RgbIndexes = {}));
13
- const randomColorValue = "random", midColorValue = "mid", colorManagers = new Map();
14
- export function addColorManager(manager) {
15
- colorManagers.set(manager.key, manager);
16
- }
17
- function stringToRgba(input) {
18
- for (const manager of colorManagers.values()) {
6
+ const randomColorValue = "random", midColorValue = "mid";
7
+ function stringToRgba(engine, input) {
8
+ if (!input) {
9
+ return;
10
+ }
11
+ for (const manager of engine.colorManagers.values()) {
19
12
  if (input.startsWith(manager.stringPrefix)) {
20
13
  return manager.parseString(input);
21
14
  }
22
15
  }
23
- const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexFixed = input.replace(shorthandRegex, (_, r, g, b, a) => {
24
- return r + r + g + g + b + b + (a !== undefined ? a + a : "");
25
- }), regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, result = regex.exec(hexFixed), radix = 16, defaultAlpha = 1, alphaFactor = 0xff;
26
- return result
27
- ? {
28
- a: result[RgbIndexes.a] !== undefined
29
- ? parseInt(result[RgbIndexes.a], radix) / alphaFactor
30
- : defaultAlpha,
31
- b: parseInt(result[RgbIndexes.b], radix),
32
- g: parseInt(result[RgbIndexes.g], radix),
33
- r: parseInt(result[RgbIndexes.r], radix),
34
- }
35
- : undefined;
36
16
  }
37
- export function rangeColorToRgb(input, index, useIndex = true) {
17
+ export function rangeColorToRgb(engine, input, index, useIndex = true) {
38
18
  if (!input) {
39
19
  return;
40
20
  }
41
21
  const color = isString(input) ? { value: input } : input;
42
22
  if (isString(color.value)) {
43
- return colorToRgb(color.value, index, useIndex);
23
+ return colorToRgb(engine, color.value, index, useIndex);
44
24
  }
45
25
  if (isArray(color.value)) {
46
- return rangeColorToRgb({
26
+ return rangeColorToRgb(engine, {
47
27
  value: itemFromArray(color.value, index, useIndex),
48
28
  });
49
29
  }
50
- for (const manager of colorManagers.values()) {
30
+ for (const manager of engine.colorManagers.values()) {
51
31
  const res = manager.handleRangeColor(color);
52
32
  if (res) {
53
33
  return res;
54
34
  }
55
35
  }
56
36
  }
57
- export function colorToRgb(input, index, useIndex = true) {
37
+ export function colorToRgb(engine, input, index, useIndex = true) {
58
38
  if (!input) {
59
39
  return;
60
40
  }
61
41
  const color = isString(input) ? { value: input } : input;
62
42
  if (isString(color.value)) {
63
- return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(color.value);
43
+ return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(engine, color.value);
64
44
  }
65
45
  if (isArray(color.value)) {
66
- return colorToRgb({
46
+ return colorToRgb(engine, {
67
47
  value: itemFromArray(color.value, index, useIndex),
68
48
  });
69
49
  }
70
- for (const manager of colorManagers.values()) {
50
+ for (const manager of engine.colorManagers.values()) {
71
51
  const res = manager.handleColor(color);
72
52
  if (res) {
73
53
  return res;
74
54
  }
75
55
  }
76
56
  }
77
- export function colorToHsl(color, index, useIndex = true) {
78
- const rgb = colorToRgb(color, index, useIndex);
57
+ export function colorToHsl(engine, color, index, useIndex = true) {
58
+ const rgb = colorToRgb(engine, color, index, useIndex);
79
59
  return rgb ? rgbToHsl(rgb) : undefined;
80
60
  }
81
- export function rangeColorToHsl(color, index, useIndex = true) {
82
- const rgb = rangeColorToRgb(color, index, useIndex);
61
+ export function rangeColorToHsl(engine, color, index, useIndex = true) {
62
+ const rgb = rangeColorToRgb(engine, color, index, useIndex);
83
63
  return rgb ? rgbToHsl(rgb) : undefined;
84
64
  }
85
65
  export function rgbToHsl(color) {
@@ -106,11 +86,11 @@ export function rgbToHsl(color) {
106
86
  }
107
87
  return res;
108
88
  }
109
- export function stringToAlpha(input) {
110
- return stringToRgba(input)?.a;
89
+ export function stringToAlpha(engine, input) {
90
+ return stringToRgba(engine, input)?.a;
111
91
  }
112
- export function stringToRgb(input) {
113
- return stringToRgba(input);
92
+ export function stringToRgb(engine, input) {
93
+ return stringToRgba(engine, input);
114
94
  }
115
95
  export function hslToRgb(hsl) {
116
96
  const hMax = 360, sMax = 100, lMax = 100, sMin = 0, lMin = 0, h = ((hsl.h % hMax) + hMax) % hMax, s = Math.max(sMin, Math.min(sMax, hsl.s)), l = Math.max(lMin, Math.min(lMax, hsl.l)), hNormalized = h / hMax, sNormalized = s / sMax, lNormalized = l / lMax, rgbFactor = 255, triple = 3;
@@ -201,11 +181,11 @@ export function getLinkColor(p1, p2, linkColor) {
201
181
  return linkColor;
202
182
  }
203
183
  }
204
- export function getLinkRandomColor(optColor, blink, consent) {
184
+ export function getLinkRandomColor(engine, optColor, blink, consent) {
205
185
  const color = isString(optColor) ? optColor : optColor.value;
206
186
  if (color === randomColorValue) {
207
187
  if (consent) {
208
- return rangeColorToRgb({
188
+ return rangeColorToRgb(engine, {
209
189
  value: color,
210
190
  });
211
191
  }
@@ -218,7 +198,7 @@ export function getLinkRandomColor(optColor, blink, consent) {
218
198
  return midColorValue;
219
199
  }
220
200
  else {
221
- return rangeColorToRgb({
201
+ return rangeColorToRgb(engine, {
222
202
  value: color,
223
203
  });
224
204
  }
@@ -6,16 +6,7 @@ let _random = Math.random;
6
6
  const _animationLoop = {
7
7
  nextFrame: (cb) => requestAnimationFrame(cb),
8
8
  cancel: (idx) => cancelAnimationFrame(idx),
9
- }, easingFunctions = new Map(), double = 2, doublePI = Math.PI * double;
10
- export function addEasing(name, easing) {
11
- if (easingFunctions.get(name)) {
12
- return;
13
- }
14
- easingFunctions.set(name, easing);
15
- }
16
- export function getEasing(name) {
17
- return easingFunctions.get(name) ?? ((value) => value);
18
- }
9
+ }, double = 2, doublePI = Math.PI * double;
19
10
  export function setRandom(rnd = Math.random) {
20
11
  _random = rnd;
21
12
  }
@@ -414,3 +414,9 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
414
414
  data.value = clamp(data.value, minValue, maxValue);
415
415
  }
416
416
  }
417
+ export function assertValidVersion(engine, pluginVersion) {
418
+ if (engine.version === pluginVersion) {
419
+ return;
420
+ }
421
+ throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${engine.version}. Plugins version: ${pluginVersion}`);
422
+ }
@@ -78,9 +78,7 @@ export * from "./Options/Classes/Theme/ThemeDefault.js";
78
78
  export * from "./Options/Classes/ValueWithRandom.js";
79
79
  export * from "./Utils/CanvasUtils.js";
80
80
  export * from "./Utils/ColorUtils.js";
81
- export * from "./Utils/HslColorManager.js";
82
81
  export * from "./Utils/NumberUtils.js";
83
82
  export * from "./Utils/OptionsUtils.js";
84
- export * from "./Utils/RgbColorManager.js";
85
83
  export * from "./Utils/Utils.js";
86
84
  export * from "./Utils/TypeUtils.js";
package/browser/init.js CHANGED
@@ -1,11 +1,5 @@
1
1
  import { Engine } from "./Core/Engine.js";
2
- import { HslColorManager } from "./Utils/HslColorManager.js";
3
- import { RgbColorManager } from "./Utils/RgbColorManager.js";
4
- import { addColorManager } from "./Utils/ColorUtils.js";
5
2
  export function init() {
6
- const rgbColorManager = new RgbColorManager(), hslColorManager = new HslColorManager();
7
- addColorManager(rgbColorManager);
8
- addColorManager(hslColorManager);
9
3
  const engine = new Engine();
10
4
  engine.init();
11
5
  return engine;
@@ -29,7 +29,7 @@ function setStyle(canvas, style, important = false) {
29
29
  }
30
30
  }
31
31
  class Canvas {
32
- constructor(container) {
32
+ constructor(container, engine) {
33
33
  this.container = container;
34
34
  this._applyPostDrawUpdaters = particle => {
35
35
  for (const updater of this._postDrawUpdaters) {
@@ -65,10 +65,10 @@ class Canvas {
65
65
  let fColor, sColor;
66
66
  for (const plugin of this._colorPlugins) {
67
67
  if (!fColor && plugin.particleFillColor) {
68
- fColor = (0, ColorUtils_js_1.rangeColorToHsl)(plugin.particleFillColor(particle));
68
+ fColor = (0, ColorUtils_js_1.rangeColorToHsl)(this._engine, plugin.particleFillColor(particle));
69
69
  }
70
70
  if (!sColor && plugin.particleStrokeColor) {
71
- sColor = (0, ColorUtils_js_1.rangeColorToHsl)(plugin.particleStrokeColor(particle));
71
+ sColor = (0, ColorUtils_js_1.rangeColorToHsl)(this._engine, plugin.particleStrokeColor(particle));
72
72
  }
73
73
  if (fColor && sColor) {
74
74
  break;
@@ -79,7 +79,7 @@ class Canvas {
79
79
  this._initCover = async () => {
80
80
  const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color;
81
81
  if (color) {
82
- const coverRgb = (0, ColorUtils_js_1.rangeColorToRgb)(color);
82
+ const coverRgb = (0, ColorUtils_js_1.rangeColorToRgb)(this._engine, color);
83
83
  if (coverRgb) {
84
84
  const coverColor = {
85
85
  ...coverRgb,
@@ -138,7 +138,7 @@ class Canvas {
138
138
  }
139
139
  const factorNumerator = 1, opacity = factorNumerator / trail.length;
140
140
  if (trailFill.color) {
141
- const fillColor = (0, ColorUtils_js_1.rangeColorToRgb)(trailFill.color);
141
+ const fillColor = (0, ColorUtils_js_1.rangeColorToRgb)(this._engine, trailFill.color);
142
142
  if (!fillColor) {
143
143
  return;
144
144
  }
@@ -219,10 +219,16 @@ class Canvas {
219
219
  height: "100%",
220
220
  }, true);
221
221
  };
222
- this.size = {
222
+ this._engine = engine;
223
+ this._standardSize = {
223
224
  height: 0,
224
225
  width: 0,
225
226
  };
227
+ const pxRatio = container.retina.pixelRatio, stdSize = this._standardSize;
228
+ this.size = {
229
+ height: stdSize.height * pxRatio,
230
+ width: stdSize.width * pxRatio,
231
+ };
226
232
  this._context = null;
227
233
  this._generated = false;
228
234
  this._preDrawUpdaters = [];
@@ -366,7 +372,7 @@ class Canvas {
366
372
  return;
367
373
  }
368
374
  if (background.color) {
369
- const color = (0, ColorUtils_js_1.rangeColorToRgb)(background.color);
375
+ const color = (0, ColorUtils_js_1.rangeColorToRgb)(this._engine, background.color);
370
376
  elementStyle.backgroundColor = color ? (0, ColorUtils_js_1.getStyleFromRgb)(color, background.opacity) : "";
371
377
  }
372
378
  else {
@@ -411,8 +417,13 @@ class Canvas {
411
417
  this.element = canvas;
412
418
  this.element.ariaHidden = "true";
413
419
  this._originalStyle = (0, Utils_js_1.deepExtend)({}, this.element.style);
414
- this.size.height = canvas.offsetHeight;
415
- this.size.width = canvas.offsetWidth;
420
+ const standardSize = this._standardSize;
421
+ standardSize.height = canvas.offsetHeight;
422
+ standardSize.width = canvas.offsetWidth;
423
+ const pxRatio = this.container.retina.pixelRatio;
424
+ const retinaSize = this.size;
425
+ retinaSize.height = standardSize.height * pxRatio;
426
+ retinaSize.width = standardSize.width * pxRatio;
416
427
  this._context = this.element.getContext("2d");
417
428
  this._safeMutationObserver(obs => {
418
429
  if (!this.element || !(this.element instanceof Node)) {
@@ -447,23 +458,23 @@ class Canvas {
447
458
  if (!this.element) {
448
459
  return false;
449
460
  }
450
- const container = this.container, pxRatio = container.retina.pixelRatio, size = container.canvas.size, newSize = {
451
- width: this.element.offsetWidth * pxRatio,
452
- height: this.element.offsetHeight * pxRatio,
461
+ const container = this.container, currentSize = container.canvas._standardSize, newSize = {
462
+ width: this.element.offsetWidth,
463
+ height: this.element.offsetHeight,
453
464
  };
454
- if (newSize.height === size.height &&
455
- newSize.width === size.width &&
456
- newSize.height === this.element.height &&
457
- newSize.width === this.element.width) {
465
+ if (newSize.height === currentSize.height && newSize.width === currentSize.width) {
458
466
  return false;
459
467
  }
460
- const oldSize = { ...size };
461
- this.element.width = size.width = this.element.offsetWidth * pxRatio;
462
- this.element.height = size.height = this.element.offsetHeight * pxRatio;
468
+ const oldSize = { ...currentSize }, pxRatio = container.retina.pixelRatio;
469
+ currentSize.height = newSize.height;
470
+ currentSize.width = newSize.width;
471
+ const retinaSize = this.size;
472
+ this.element.width = retinaSize.width = currentSize.width * pxRatio;
473
+ this.element.height = retinaSize.height = currentSize.height * pxRatio;
463
474
  if (this.container.started) {
464
475
  container.particles.setResizeFactor({
465
- width: size.width / oldSize.width,
466
- height: size.height / oldSize.height,
476
+ width: currentSize.width / oldSize.width,
477
+ height: currentSize.height / oldSize.height,
467
478
  });
468
479
  }
469
480
  return true;
@@ -91,7 +91,7 @@ class Container {
91
91
  this._sourceOptions = sourceOptions;
92
92
  this._initialSourceOptions = sourceOptions;
93
93
  this.retina = new Retina_js_1.Retina(this);
94
- this.canvas = new Canvas_js_1.Canvas(this);
94
+ this.canvas = new Canvas_js_1.Canvas(this, this._engine);
95
95
  this.particles = new Particles_js_1.Particles(this._engine, this);
96
96
  this.pathGenerators = new Map();
97
97
  this.interactivity = {
@@ -74,6 +74,8 @@ class Engine {
74
74
  this._eventDispatcher = new EventDispatcher_js_1.EventDispatcher();
75
75
  this._initialized = false;
76
76
  this.plugins = [];
77
+ this.colorManagers = new Map();
78
+ this.easingFunctions = new Map();
77
79
  this._initializers = {
78
80
  interactors: new Map(),
79
81
  movers: new Map(),
@@ -98,13 +100,24 @@ class Engine {
98
100
  return this._domArray;
99
101
  }
100
102
  get version() {
101
- return "3.6.0";
103
+ return "3.7.0";
104
+ }
105
+ async addColorManager(manager, refresh = true) {
106
+ this.colorManagers.set(manager.key, manager);
107
+ await this.refresh(refresh);
102
108
  }
103
109
  addConfig(config) {
104
110
  const key = config.key ?? config.name ?? "default";
105
111
  this._configs.set(key, config);
106
112
  this._eventDispatcher.dispatchEvent(EventType_js_1.EventType.configAdded, { data: { name: key, config } });
107
113
  }
114
+ async addEasing(name, easing, refresh = true) {
115
+ if (this.getEasing(name)) {
116
+ return;
117
+ }
118
+ this.easingFunctions.set(name, easing);
119
+ await this.refresh(refresh);
120
+ }
108
121
  async addEffect(effect, drawer, refresh = true) {
109
122
  (0, Utils_js_1.executeOnSingleOrMultiple)(effect, type => {
110
123
  if (!this.getEffectDrawer(type)) {
@@ -178,6 +191,9 @@ class Engine {
178
191
  }
179
192
  return res;
180
193
  }
194
+ getEasing(name) {
195
+ return this.easingFunctions.get(name) ?? ((value) => value);
196
+ }
181
197
  getEffectDrawer(type) {
182
198
  return this.effectDrawers.get(type);
183
199
  }
@@ -328,7 +328,7 @@ class Particle {
328
328
  this.sides = sideCountFunc(this);
329
329
  }
330
330
  this.spawning = false;
331
- this.shadowColor = (0, ColorUtils_js_1.rangeColorToRgb)(this.options.shadow.color);
331
+ this.shadowColor = (0, ColorUtils_js_1.rangeColorToRgb)(this._engine, this.options.shadow.color);
332
332
  for (const updater of particles.updaters) {
333
333
  updater.init(this);
334
334
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });