@tsparticles/engine 4.0.0-beta.0 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/155.min.js +1 -0
  2. package/README.md +0 -21
  3. package/browser/Core/CanvasManager.js +303 -0
  4. package/browser/Core/Container.js +64 -34
  5. package/browser/Core/Engine.js +26 -138
  6. package/browser/Core/Interfaces/IPositionFromSizeParams.js +1 -1
  7. package/browser/Core/Particle.js +29 -28
  8. package/{cjs/Core/Particles.js → browser/Core/ParticlesManager.js} +28 -57
  9. package/browser/Core/RenderManager.js +303 -0
  10. package/browser/Core/Retina.js +3 -8
  11. package/browser/Core/Utils/PluginManager.js +145 -0
  12. package/browser/Options/Classes/Options.js +7 -7
  13. package/browser/Options/Classes/Particles/ParticlesOptions.js +5 -5
  14. package/browser/Types/CanvasContextType.js +1 -0
  15. package/browser/Utils/CanvasUtils.js +1 -1
  16. package/browser/Utils/ColorUtils.js +21 -21
  17. package/browser/Utils/LogUtils.js +1 -0
  18. package/browser/Utils/OptionsUtils.js +2 -2
  19. package/cjs/Core/CanvasManager.js +303 -0
  20. package/cjs/Core/Container.js +64 -34
  21. package/cjs/Core/Engine.js +26 -138
  22. package/cjs/Core/Interfaces/IPositionFromSizeParams.js +1 -1
  23. package/cjs/Core/Particle.js +29 -28
  24. package/{esm/Core/Particles.js → cjs/Core/ParticlesManager.js} +28 -57
  25. package/cjs/Core/RenderManager.js +303 -0
  26. package/cjs/Core/Retina.js +3 -8
  27. package/cjs/Core/Utils/PluginManager.js +145 -0
  28. package/cjs/Options/Classes/Options.js +7 -7
  29. package/cjs/Options/Classes/Particles/ParticlesOptions.js +5 -5
  30. package/cjs/Types/CanvasContextType.js +1 -0
  31. package/cjs/Utils/CanvasUtils.js +1 -1
  32. package/cjs/Utils/ColorUtils.js +21 -21
  33. package/cjs/Utils/LogUtils.js +1 -0
  34. package/cjs/Utils/OptionsUtils.js +2 -2
  35. package/dist_browser_Core_Container_js.js +24 -14
  36. package/esm/Core/CanvasManager.js +303 -0
  37. package/esm/Core/Container.js +64 -34
  38. package/esm/Core/Engine.js +26 -138
  39. package/esm/Core/Interfaces/IPositionFromSizeParams.js +1 -1
  40. package/esm/Core/Particle.js +29 -28
  41. package/{browser/Core/Particles.js → esm/Core/ParticlesManager.js} +28 -57
  42. package/esm/Core/RenderManager.js +303 -0
  43. package/esm/Core/Retina.js +3 -8
  44. package/esm/Core/Utils/PluginManager.js +145 -0
  45. package/esm/Options/Classes/Options.js +7 -7
  46. package/esm/Options/Classes/Particles/ParticlesOptions.js +5 -5
  47. package/esm/Types/CanvasContextType.js +1 -0
  48. package/esm/Utils/CanvasUtils.js +1 -1
  49. package/esm/Utils/ColorUtils.js +21 -21
  50. package/esm/Utils/LogUtils.js +1 -0
  51. package/esm/Utils/OptionsUtils.js +2 -2
  52. package/package.json +2 -3
  53. package/report.html +84 -29
  54. package/tsparticles.engine.js +18 -8
  55. package/tsparticles.engine.min.js +2 -2
  56. package/types/Core/CanvasManager.d.ts +39 -0
  57. package/types/Core/Container.d.ts +26 -7
  58. package/types/Core/Engine.d.ts +2 -54
  59. package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -7
  60. package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
  61. package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
  62. package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
  63. package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -1
  64. package/types/Core/Particle.d.ts +4 -4
  65. package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +4 -11
  66. package/types/Core/{Canvas.d.ts → RenderManager.d.ts} +12 -33
  67. package/types/Core/Retina.d.ts +0 -2
  68. package/types/Core/Utils/PluginManager.d.ts +62 -0
  69. package/types/Options/Classes/Options.d.ts +3 -3
  70. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +3 -3
  71. package/types/Types/CanvasContextType.d.ts +1 -0
  72. package/types/Utils/CanvasUtils.d.ts +8 -5
  73. package/types/Utils/ColorUtils.d.ts +8 -8
  74. package/types/Utils/LogUtils.d.ts +1 -0
  75. package/types/Utils/OptionsUtils.d.ts +2 -2
  76. package/types/export-types.d.ts +4 -2
  77. package/164.min.js +0 -1
  78. package/browser/Core/Canvas.js +0 -570
  79. package/cjs/Core/Canvas.js +0 -570
  80. package/esm/Core/Canvas.js +0 -570
  81. package/umd/Core/Canvas.js +0 -584
  82. package/umd/Core/Container.js +0 -356
  83. package/umd/Core/Engine.js +0 -295
  84. package/umd/Core/Interfaces/Colors.js +0 -12
  85. package/umd/Core/Interfaces/IBounds.js +0 -12
  86. package/umd/Core/Interfaces/IBubbleParticleData.js +0 -12
  87. package/umd/Core/Interfaces/ICircleBouncer.js +0 -12
  88. package/umd/Core/Interfaces/IColorManager.js +0 -12
  89. package/umd/Core/Interfaces/IContainerPlugin.js +0 -12
  90. package/umd/Core/Interfaces/ICoordinates.js +0 -12
  91. package/umd/Core/Interfaces/IDelta.js +0 -12
  92. package/umd/Core/Interfaces/IDimension.js +0 -12
  93. package/umd/Core/Interfaces/IDistance.js +0 -12
  94. package/umd/Core/Interfaces/IDrawParticleParams.js +0 -12
  95. package/umd/Core/Interfaces/IEffectDrawer.js +0 -12
  96. package/umd/Core/Interfaces/ILoadParams.js +0 -12
  97. package/umd/Core/Interfaces/IPalette.js +0 -12
  98. package/umd/Core/Interfaces/IParticleColorStyle.js +0 -12
  99. package/umd/Core/Interfaces/IParticleHslAnimation.js +0 -12
  100. package/umd/Core/Interfaces/IParticleLife.js +0 -12
  101. package/umd/Core/Interfaces/IParticleOpacityData.js +0 -12
  102. package/umd/Core/Interfaces/IParticleRetinaProps.js +0 -12
  103. package/umd/Core/Interfaces/IParticleRoll.js +0 -12
  104. package/umd/Core/Interfaces/IParticleRotateData.js +0 -12
  105. package/umd/Core/Interfaces/IParticleTransformValues.js +0 -12
  106. package/umd/Core/Interfaces/IParticleUpdater.js +0 -12
  107. package/umd/Core/Interfaces/IParticleValueAnimation.js +0 -12
  108. package/umd/Core/Interfaces/IPlugin.js +0 -12
  109. package/umd/Core/Interfaces/IPositionFromSizeParams.js +0 -12
  110. package/umd/Core/Interfaces/IRangeValue.js +0 -12
  111. package/umd/Core/Interfaces/IShapeDrawData.js +0 -12
  112. package/umd/Core/Interfaces/IShapeDrawer.js +0 -12
  113. package/umd/Core/Interfaces/IShapeValues.js +0 -12
  114. package/umd/Core/Interfaces/ISlowParticleData.js +0 -12
  115. package/umd/Core/Particle.js +0 -432
  116. package/umd/Core/Particles.js +0 -407
  117. package/umd/Core/Retina.js +0 -52
  118. package/umd/Core/Utils/Constants.js +0 -23
  119. package/umd/Core/Utils/EventListeners.js +0 -102
  120. package/umd/Core/Utils/Ranges.js +0 -91
  121. package/umd/Core/Utils/SpatialHashGrid.js +0 -116
  122. package/umd/Core/Utils/Vectors.js +0 -126
  123. package/umd/Enums/AnimationStatus.js +0 -18
  124. package/umd/Enums/Directions/MoveDirection.js +0 -27
  125. package/umd/Enums/Directions/OutModeDirection.js +0 -20
  126. package/umd/Enums/Directions/RotateDirection.js +0 -19
  127. package/umd/Enums/Modes/AnimationMode.js +0 -20
  128. package/umd/Enums/Modes/LimitMode.js +0 -18
  129. package/umd/Enums/Modes/OutMode.js +0 -21
  130. package/umd/Enums/Modes/PixelMode.js +0 -18
  131. package/umd/Enums/RangeType.js +0 -18
  132. package/umd/Enums/Types/AlterType.js +0 -18
  133. package/umd/Enums/Types/DestroyType.js +0 -19
  134. package/umd/Enums/Types/EasingType.js +0 -58
  135. package/umd/Enums/Types/EventType.js +0 -28
  136. package/umd/Enums/Types/GradientType.js +0 -19
  137. package/umd/Enums/Types/ParticleOutType.js +0 -19
  138. package/umd/Enums/Types/StartValueType.js +0 -19
  139. package/umd/Options/Classes/AnimatableColor.js +0 -52
  140. package/umd/Options/Classes/AnimationOptions.js +0 -79
  141. package/umd/Options/Classes/Background/Background.js +0 -56
  142. package/umd/Options/Classes/ColorAnimation.js +0 -44
  143. package/umd/Options/Classes/FullScreen/FullScreen.js +0 -34
  144. package/umd/Options/Classes/HslAnimation.js +0 -30
  145. package/umd/Options/Classes/Options.js +0 -171
  146. package/umd/Options/Classes/OptionsColor.js +0 -42
  147. package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +0 -31
  148. package/umd/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -21
  149. package/umd/Options/Classes/Particles/Effect/Effect.js +0 -46
  150. package/umd/Options/Classes/Particles/Fill.js +0 -42
  151. package/umd/Options/Classes/Particles/Move/Move.js +0 -120
  152. package/umd/Options/Classes/Particles/Move/MoveAngle.js +0 -35
  153. package/umd/Options/Classes/Particles/Move/MoveCenter.js +0 -45
  154. package/umd/Options/Classes/Particles/Move/MoveGravity.js +0 -45
  155. package/umd/Options/Classes/Particles/Move/OutModes.js +0 -38
  156. package/umd/Options/Classes/Particles/Move/Path/MovePath.js +0 -46
  157. package/umd/Options/Classes/Particles/Move/Spin.js +0 -40
  158. package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +0 -41
  159. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +0 -37
  160. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +0 -35
  161. package/umd/Options/Classes/Particles/Opacity/Opacity.js +0 -35
  162. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -34
  163. package/umd/Options/Classes/Particles/ParticlesOptions.js +0 -116
  164. package/umd/Options/Classes/Particles/Shape/Shape.js +0 -46
  165. package/umd/Options/Classes/Particles/Size/Size.js +0 -35
  166. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +0 -34
  167. package/umd/Options/Classes/Particles/Stroke.js +0 -39
  168. package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +0 -42
  169. package/umd/Options/Classes/ResizeEvent.js +0 -34
  170. package/umd/Options/Classes/ValueWithRandom.js +0 -56
  171. package/umd/Options/Interfaces/Background/IBackground.js +0 -12
  172. package/umd/Options/Interfaces/FullScreen/IFullScreen.js +0 -12
  173. package/umd/Options/Interfaces/IAnimatable.js +0 -12
  174. package/umd/Options/Interfaces/IAnimatableColor.js +0 -12
  175. package/umd/Options/Interfaces/IAnimation.js +0 -12
  176. package/umd/Options/Interfaces/IColorAnimation.js +0 -12
  177. package/umd/Options/Interfaces/IHslAnimation.js +0 -12
  178. package/umd/Options/Interfaces/IOptionLoader.js +0 -12
  179. package/umd/Options/Interfaces/IOptions.js +0 -12
  180. package/umd/Options/Interfaces/IOptionsColor.js +0 -12
  181. package/umd/Options/Interfaces/IResizeEvent.js +0 -12
  182. package/umd/Options/Interfaces/IValueWithRandom.js +0 -12
  183. package/umd/Options/Interfaces/Particles/Bounce/IParticlesBounce.js +0 -12
  184. package/umd/Options/Interfaces/Particles/Effect/IEffect.js +0 -12
  185. package/umd/Options/Interfaces/Particles/IFill.js +0 -12
  186. package/umd/Options/Interfaces/Particles/IParticlesOptions.js +0 -12
  187. package/umd/Options/Interfaces/Particles/IStroke.js +0 -12
  188. package/umd/Options/Interfaces/Particles/Move/IMove.js +0 -12
  189. package/umd/Options/Interfaces/Particles/Move/IMoveAngle.js +0 -12
  190. package/umd/Options/Interfaces/Particles/Move/IMoveCenter.js +0 -12
  191. package/umd/Options/Interfaces/Particles/Move/IMoveGravity.js +0 -12
  192. package/umd/Options/Interfaces/Particles/Move/IOutModes.js +0 -12
  193. package/umd/Options/Interfaces/Particles/Move/ISpin.js +0 -12
  194. package/umd/Options/Interfaces/Particles/Move/Path/IMovePath.js +0 -12
  195. package/umd/Options/Interfaces/Particles/Number/IParticlesDensity.js +0 -12
  196. package/umd/Options/Interfaces/Particles/Number/IParticlesNumber.js +0 -12
  197. package/umd/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +0 -12
  198. package/umd/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -12
  199. package/umd/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -12
  200. package/umd/Options/Interfaces/Particles/Shape/IShape.js +0 -12
  201. package/umd/Options/Interfaces/Particles/Size/ISize.js +0 -12
  202. package/umd/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -12
  203. package/umd/Options/Interfaces/Particles/ZIndex/IZIndex.js +0 -12
  204. package/umd/Types/CustomEventArgs.js +0 -12
  205. package/umd/Types/CustomEventListener.js +0 -12
  206. package/umd/Types/EasingFunction.js +0 -12
  207. package/umd/Types/EngineInitializers.js +0 -12
  208. package/umd/Types/ExportResult.js +0 -12
  209. package/umd/Types/ISourceOptions.js +0 -12
  210. package/umd/Types/ParticlesGroups.js +0 -12
  211. package/umd/Types/PathOptions.js +0 -12
  212. package/umd/Types/RangeValue.js +0 -12
  213. package/umd/Types/RecursivePartial.js +0 -12
  214. package/umd/Types/ShapeData.js +0 -12
  215. package/umd/Types/SingleOrMultiple.js +0 -12
  216. package/umd/Utils/CanvasUtils.js +0 -145
  217. package/umd/Utils/ColorUtils.js +0 -395
  218. package/umd/Utils/EventDispatcher.js +0 -63
  219. package/umd/Utils/LogUtils.js +0 -36
  220. package/umd/Utils/MathUtils.js +0 -203
  221. package/umd/Utils/OptionsUtils.js +0 -25
  222. package/umd/Utils/TypeUtils.js +0 -40
  223. package/umd/Utils/Utils.js +0 -484
  224. package/umd/bundle.js +0 -32
  225. package/umd/export-types.js +0 -12
  226. package/umd/exports.js +0 -82
  227. package/umd/index.js +0 -32
  228. package/umd/initEngine.js +0 -17
@@ -6,6 +6,7 @@ const _logger = {
6
6
  },
7
7
  info: console.info,
8
8
  log: console.log,
9
+ trace: console.trace,
9
10
  verbose: console.log,
10
11
  warning: console.warn,
11
12
  };
@@ -4,8 +4,8 @@ export function loadOptions(options, ...sourceOptionsArr) {
4
4
  options.load(sourceOptions);
5
5
  }
6
6
  }
7
- export function loadParticlesOptions(engine, container, ...sourceOptionsArr) {
8
- const options = new ParticlesOptions(engine, container);
7
+ export function loadParticlesOptions(pluginManager, container, ...sourceOptionsArr) {
8
+ const options = new ParticlesOptions(pluginManager, container);
9
9
  loadOptions(options, ...sourceOptionsArr);
10
10
  return options;
11
11
  }
@@ -0,0 +1,303 @@
1
+ import { cloneStyle, getFullScreenStyle, safeMatchMedia, safeMutationObserver } from "../Utils/Utils.js";
2
+ import { defaultZoom, generatedAttribute, half } from "./Utils/Constants.js";
3
+ import { getStyleFromRgb, rangeColorToRgb } from "../Utils/ColorUtils.js";
4
+ import { RenderManager } from "./RenderManager.js";
5
+ function setStyle(canvas, style, important = false) {
6
+ if (!style) {
7
+ return;
8
+ }
9
+ const element = canvas, elementStyle = element.style, keys = new Set();
10
+ for (let i = 0; i < elementStyle.length; i++) {
11
+ const key = elementStyle.item(i);
12
+ if (!key) {
13
+ continue;
14
+ }
15
+ keys.add(key);
16
+ }
17
+ for (let i = 0; i < style.length; i++) {
18
+ const key = style.item(i);
19
+ if (!key) {
20
+ continue;
21
+ }
22
+ keys.add(key);
23
+ }
24
+ for (const key of keys) {
25
+ const value = style.getPropertyValue(key);
26
+ if (value) {
27
+ elementStyle.setProperty(key, value, important ? "important" : "");
28
+ }
29
+ else {
30
+ elementStyle.removeProperty(key);
31
+ }
32
+ }
33
+ }
34
+ export class CanvasManager {
35
+ element;
36
+ render;
37
+ size;
38
+ zoom = defaultZoom;
39
+ _container;
40
+ _generated;
41
+ _mutationObserver;
42
+ _originalStyle;
43
+ _pluginManager;
44
+ _pointerEvents;
45
+ _resizePlugins;
46
+ _standardSize;
47
+ _zoomCenter;
48
+ constructor(pluginManager, container) {
49
+ this._pluginManager = pluginManager;
50
+ this._container = container;
51
+ this.render = new RenderManager(pluginManager, container, this);
52
+ this._standardSize = {
53
+ height: 0,
54
+ width: 0,
55
+ };
56
+ const pxRatio = container.retina.pixelRatio, stdSize = this._standardSize;
57
+ this.size = {
58
+ height: stdSize.height * pxRatio,
59
+ width: stdSize.width * pxRatio,
60
+ };
61
+ this._generated = false;
62
+ this._resizePlugins = [];
63
+ this._pointerEvents = "none";
64
+ }
65
+ get _fullScreen() {
66
+ return this._container.actualOptions.fullScreen.enable;
67
+ }
68
+ destroy() {
69
+ this.stop();
70
+ if (this._generated) {
71
+ const element = this.element;
72
+ element?.remove();
73
+ this.element = undefined;
74
+ }
75
+ else {
76
+ this._resetOriginalStyle();
77
+ }
78
+ this.render.destroy();
79
+ this._resizePlugins = [];
80
+ }
81
+ getZoomCenter() {
82
+ const pxRatio = this._container.retina.pixelRatio, { width, height } = this.size;
83
+ if (this._zoomCenter) {
84
+ return this._zoomCenter;
85
+ }
86
+ return {
87
+ x: (width * half) / pxRatio,
88
+ y: (height * half) / pxRatio,
89
+ };
90
+ }
91
+ init() {
92
+ this._safeMutationObserver(obs => {
93
+ obs.disconnect();
94
+ });
95
+ this._mutationObserver = safeMutationObserver(records => {
96
+ for (const record of records) {
97
+ if (record.type === "attributes" && record.attributeName === "style") {
98
+ this._repairStyle();
99
+ }
100
+ }
101
+ });
102
+ this.resize();
103
+ this._initStyle();
104
+ this.initBackground();
105
+ this._safeMutationObserver(obs => {
106
+ if (!this.element || !(this.element instanceof Node)) {
107
+ return;
108
+ }
109
+ obs.observe(this.element, { attributes: true });
110
+ });
111
+ this.initPlugins();
112
+ this.render.init();
113
+ }
114
+ initBackground() {
115
+ const { _container } = this, options = _container.actualOptions, background = options.background, element = this.element;
116
+ if (!element) {
117
+ return;
118
+ }
119
+ const elementStyle = element.style, color = rangeColorToRgb(this._pluginManager, background.color);
120
+ if (color) {
121
+ elementStyle.backgroundColor = getStyleFromRgb(color, _container.hdr, background.opacity);
122
+ }
123
+ else {
124
+ elementStyle.backgroundColor = "";
125
+ }
126
+ elementStyle.backgroundImage = background.image || "";
127
+ elementStyle.backgroundPosition = background.position || "";
128
+ elementStyle.backgroundRepeat = background.repeat || "";
129
+ elementStyle.backgroundSize = background.size || "";
130
+ }
131
+ initPlugins() {
132
+ this._resizePlugins = [];
133
+ for (const plugin of this._container.plugins) {
134
+ if (plugin.resize) {
135
+ this._resizePlugins.push(plugin);
136
+ }
137
+ }
138
+ }
139
+ loadCanvas(canvas) {
140
+ if (this._generated && this.element) {
141
+ this.element.remove();
142
+ }
143
+ const container = this._container;
144
+ this._generated =
145
+ generatedAttribute in canvas.dataset ? canvas.dataset[generatedAttribute] === "true" : this._generated;
146
+ this.element = canvas;
147
+ this.element.ariaHidden = "true";
148
+ this._originalStyle = cloneStyle(this.element.style);
149
+ const standardSize = this._standardSize;
150
+ standardSize.height = canvas.offsetHeight;
151
+ standardSize.width = canvas.offsetWidth;
152
+ const pxRatio = this._container.retina.pixelRatio, retinaSize = this.size;
153
+ canvas.height = retinaSize.height = standardSize.height * pxRatio;
154
+ canvas.width = retinaSize.width = standardSize.width * pxRatio;
155
+ const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
156
+ this.render.setContextSettings({
157
+ alpha: true,
158
+ colorSpace: canSupportHdrQuery?.matches && container.hdr ? "display-p3" : "srgb",
159
+ desynchronized: true,
160
+ willReadFrequently: false,
161
+ });
162
+ this.render.setContext(this.element.getContext("2d", this.render.settings));
163
+ this._safeMutationObserver(obs => {
164
+ obs.disconnect();
165
+ });
166
+ container.retina.init();
167
+ this.initBackground();
168
+ this._safeMutationObserver(obs => {
169
+ if (!this.element || !(this.element instanceof Node)) {
170
+ return;
171
+ }
172
+ obs.observe(this.element, { attributes: true });
173
+ });
174
+ }
175
+ resize() {
176
+ if (!this.element) {
177
+ return false;
178
+ }
179
+ const container = this._container, currentSize = container.canvas._standardSize, newSize = {
180
+ width: this.element.offsetWidth,
181
+ height: this.element.offsetHeight,
182
+ }, pxRatio = container.retina.pixelRatio, retinaSize = {
183
+ width: newSize.width * pxRatio,
184
+ height: newSize.height * pxRatio,
185
+ };
186
+ if (newSize.height === currentSize.height &&
187
+ newSize.width === currentSize.width &&
188
+ retinaSize.height === this.element.height &&
189
+ retinaSize.width === this.element.width) {
190
+ return false;
191
+ }
192
+ const oldSize = { ...currentSize };
193
+ currentSize.height = newSize.height;
194
+ currentSize.width = newSize.width;
195
+ const canvasSize = this.size;
196
+ this.element.width = canvasSize.width = retinaSize.width;
197
+ this.element.height = canvasSize.height = retinaSize.height;
198
+ if (this._container.started) {
199
+ container.particles.setResizeFactor({
200
+ width: currentSize.width / oldSize.width,
201
+ height: currentSize.height / oldSize.height,
202
+ });
203
+ }
204
+ return true;
205
+ }
206
+ setPointerEvents(type) {
207
+ const element = this.element;
208
+ if (!element) {
209
+ return;
210
+ }
211
+ this._pointerEvents = type;
212
+ this._repairStyle();
213
+ }
214
+ setZoom(zoomLevel, center) {
215
+ this.zoom = zoomLevel;
216
+ this._zoomCenter = center;
217
+ }
218
+ stop() {
219
+ this._safeMutationObserver(obs => {
220
+ obs.disconnect();
221
+ });
222
+ this._mutationObserver = undefined;
223
+ this.render.stop();
224
+ }
225
+ async windowResize() {
226
+ if (!this.element || !this.resize()) {
227
+ return;
228
+ }
229
+ const container = this._container, needsRefresh = container.updateActualOptions();
230
+ container.particles.setDensity();
231
+ this._applyResizePlugins();
232
+ if (needsRefresh) {
233
+ await container.refresh();
234
+ }
235
+ }
236
+ _applyResizePlugins = () => {
237
+ for (const plugin of this._resizePlugins) {
238
+ plugin.resize?.();
239
+ }
240
+ };
241
+ _initStyle = () => {
242
+ const element = this.element, options = this._container.actualOptions;
243
+ if (!element) {
244
+ return;
245
+ }
246
+ if (this._fullScreen) {
247
+ this._setFullScreenStyle();
248
+ }
249
+ else {
250
+ this._resetOriginalStyle();
251
+ }
252
+ for (const key in options.style) {
253
+ if (!key || !(key in options.style)) {
254
+ continue;
255
+ }
256
+ const value = options.style[key];
257
+ if (!value) {
258
+ continue;
259
+ }
260
+ element.style.setProperty(key, value, "important");
261
+ }
262
+ };
263
+ _repairStyle = () => {
264
+ const element = this.element;
265
+ if (!element) {
266
+ return;
267
+ }
268
+ this._safeMutationObserver(observer => {
269
+ observer.disconnect();
270
+ });
271
+ this._initStyle();
272
+ this.initBackground();
273
+ const pointerEvents = this._pointerEvents;
274
+ element.style.pointerEvents = pointerEvents;
275
+ element.setAttribute("pointer-events", pointerEvents);
276
+ this._safeMutationObserver(observer => {
277
+ if (!(element instanceof Node)) {
278
+ return;
279
+ }
280
+ observer.observe(element, { attributes: true });
281
+ });
282
+ };
283
+ _resetOriginalStyle = () => {
284
+ const element = this.element, originalStyle = this._originalStyle;
285
+ if (!element || !originalStyle) {
286
+ return;
287
+ }
288
+ setStyle(element, originalStyle, true);
289
+ };
290
+ _safeMutationObserver = callback => {
291
+ if (!this._mutationObserver) {
292
+ return;
293
+ }
294
+ callback(this._mutationObserver);
295
+ };
296
+ _setFullScreenStyle = () => {
297
+ const element = this.element;
298
+ if (!element) {
299
+ return;
300
+ }
301
+ setStyle(element, getFullScreenStyle(this._container.actualOptions.fullScreen.zIndex), true);
302
+ };
303
+ }
@@ -1,10 +1,13 @@
1
1
  import { animate, cancelAnimation, getRangeValue } from "../Utils/MathUtils.js";
2
- import { defaultFps, defaultFpsLimit, millisecondsToSeconds, minFpsLimit, removeDeleteCount, removeMinIndex, } from "./Utils/Constants.js";
3
- import { Canvas } from "./Canvas.js";
2
+ import { defaultFps, defaultFpsLimit, millisecondsToSeconds, minFpsLimit } from "./Utils/Constants.js";
3
+ import { CanvasManager } from "./CanvasManager.js";
4
4
  import { EventListeners } from "./Utils/EventListeners.js";
5
5
  import { EventType } from "../Enums/Types/EventType.js";
6
+ import {} from "./Interfaces/IEffectDrawer.js";
7
+ import {} from "./Interfaces/IParticleUpdater.js";
8
+ import {} from "./Interfaces/IShapeDrawer.js";
6
9
  import { Options } from "../Options/Classes/Options.js";
7
- import { Particles } from "./Particles.js";
10
+ import { ParticlesManager } from "./ParticlesManager.js";
8
11
  import { Retina } from "./Retina.js";
9
12
  import { getLogger } from "../Utils/LogUtils.js";
10
13
  import { loadOptions } from "../Utils/OptionsUtils.js";
@@ -15,8 +18,8 @@ function updateDelta(delta, value, fpsLimit = defaultFps, smooth = false) {
15
18
  delta.value = value;
16
19
  delta.factor = smooth ? defaultFps / fpsLimit : (defaultFps * value) / millisecondsToSeconds;
17
20
  }
18
- function loadContainerOptions(engine, container, ...sourceOptionsArr) {
19
- const options = new Options(engine, container);
21
+ function loadContainerOptions(pluginManager, container, ...sourceOptionsArr) {
22
+ const options = new Options(pluginManager, container);
20
23
  loadOptions(options, ...sourceOptionsArr);
21
24
  return options;
22
25
  }
@@ -24,6 +27,7 @@ export class Container {
24
27
  actualOptions;
25
28
  canvas;
26
29
  destroyed;
30
+ effectDrawers;
27
31
  fpsLimit;
28
32
  hdr;
29
33
  id;
@@ -31,28 +35,35 @@ export class Container {
31
35
  particleCreatedPlugins;
32
36
  particleDestroyedPlugins;
33
37
  particlePositionPlugins;
38
+ particleUpdaters;
34
39
  particles;
35
40
  plugins;
36
41
  retina;
42
+ shapeDrawers;
37
43
  started;
38
44
  zLayers;
39
45
  _delay;
40
46
  _delayTimeout;
41
47
  _delta = { value: 0, factor: 0 };
48
+ _dispatchCallback;
42
49
  _drawAnimationFrame;
43
50
  _duration;
44
- _engine;
45
51
  _eventListeners;
46
52
  _firstStart;
47
53
  _initialSourceOptions;
48
54
  _lastFrameTime;
49
55
  _lifeTime;
56
+ _onDestroy;
50
57
  _options;
51
58
  _paused;
59
+ _pluginManager;
52
60
  _smooth;
53
61
  _sourceOptions;
54
- constructor(engine, id, sourceOptions) {
55
- this._engine = engine;
62
+ constructor(params) {
63
+ const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
64
+ this._pluginManager = pluginManager;
65
+ this._dispatchCallback = dispatchCallback;
66
+ this._onDestroy = onDestroy;
56
67
  this.id = Symbol(id);
57
68
  this.fpsLimit = 120;
58
69
  this.hdr = false;
@@ -69,17 +80,20 @@ export class Container {
69
80
  this.pageHidden = false;
70
81
  this._sourceOptions = sourceOptions;
71
82
  this._initialSourceOptions = sourceOptions;
83
+ this.effectDrawers = new Map();
84
+ this.shapeDrawers = new Map();
85
+ this.particleUpdaters = [];
72
86
  this.retina = new Retina(this);
73
- this.canvas = new Canvas(this, this._engine);
74
- this.particles = new Particles(this._engine, this);
87
+ this.canvas = new CanvasManager(this._pluginManager, this);
88
+ this.particles = new ParticlesManager(this._pluginManager, this);
75
89
  this.plugins = [];
76
90
  this.particleDestroyedPlugins = [];
77
91
  this.particleCreatedPlugins = [];
78
92
  this.particlePositionPlugins = [];
79
- this._options = loadContainerOptions(this._engine, this);
80
- this.actualOptions = loadContainerOptions(this._engine, this);
93
+ this._options = loadContainerOptions(this._pluginManager, this);
94
+ this.actualOptions = loadContainerOptions(this._pluginManager, this);
81
95
  this._eventListeners = new EventListeners(this);
82
- this._engine.dispatchEvent(EventType.containerBuilt, { container: this });
96
+ this.dispatchEvent(EventType.containerBuilt);
83
97
  }
84
98
  get animationStatus() {
85
99
  return !this._paused && !this.pageHidden && guardCheck(this);
@@ -103,19 +117,29 @@ export class Container {
103
117
  this.stop();
104
118
  this.particles.destroy();
105
119
  this.canvas.destroy();
120
+ for (const [, effectDrawer] of this.effectDrawers) {
121
+ effectDrawer.destroy?.(this);
122
+ }
123
+ for (const [, shapeDrawer] of this.shapeDrawers) {
124
+ shapeDrawer.destroy?.(this);
125
+ }
106
126
  for (const plugin of this.plugins) {
107
127
  plugin.destroy?.();
108
128
  }
129
+ this.effectDrawers = new Map();
130
+ this.shapeDrawers = new Map();
131
+ this.particleUpdaters = [];
109
132
  this.plugins.length = 0;
110
- this._engine.clearPlugins(this);
133
+ this._pluginManager.clearPlugins(this);
111
134
  this.destroyed = true;
112
- if (remove) {
113
- const mainArr = this._engine.items, idx = mainArr.indexOf(this);
114
- if (idx >= removeMinIndex) {
115
- mainArr.splice(idx, removeDeleteCount);
116
- }
117
- }
118
- this._engine.dispatchEvent(EventType.containerDestroyed, { container: this });
135
+ this._onDestroy(remove);
136
+ this.dispatchEvent(EventType.containerDestroyed);
137
+ }
138
+ dispatchEvent(type, data) {
139
+ this._dispatchCallback(type, {
140
+ container: this,
141
+ data,
142
+ });
119
143
  }
120
144
  draw(force) {
121
145
  if (!guardCheck(this)) {
@@ -149,16 +173,16 @@ export class Container {
149
173
  return;
150
174
  }
151
175
  const allContainerPlugins = new Map();
152
- for (const plugin of this._engine.plugins) {
176
+ for (const plugin of this._pluginManager.plugins) {
153
177
  const containerPlugin = await plugin.getPlugin(this);
154
178
  if (containerPlugin.preInit) {
155
179
  await containerPlugin.preInit();
156
180
  }
157
181
  allContainerPlugins.set(plugin, containerPlugin);
158
182
  }
159
- await this.particles.initPlugins();
160
- this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
161
- this.actualOptions = loadContainerOptions(this._engine, this, this._options);
183
+ await this.initDrawersAndUpdaters();
184
+ this._options = loadContainerOptions(this._pluginManager, this, this._initialSourceOptions, this.sourceOptions);
185
+ this.actualOptions = loadContainerOptions(this._pluginManager, this, this._options);
162
186
  this.plugins.length = 0;
163
187
  this.particleDestroyedPlugins.length = 0;
164
188
  this.particleCreatedPlugins.length = 0;
@@ -194,12 +218,18 @@ export class Container {
194
218
  await plugin.init?.();
195
219
  }
196
220
  await this.particles.init();
197
- this._engine.dispatchEvent(EventType.containerInit, { container: this });
221
+ this.dispatchEvent(EventType.containerInit);
198
222
  this.particles.setDensity();
199
223
  for (const plugin of this.plugins) {
200
224
  plugin.particlesSetup?.();
201
225
  }
202
- this._engine.dispatchEvent(EventType.particlesSetup, { container: this });
226
+ this.dispatchEvent(EventType.particlesSetup);
227
+ }
228
+ async initDrawersAndUpdaters() {
229
+ const pluginManager = this._pluginManager;
230
+ this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
231
+ this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
232
+ this.particleUpdaters = await pluginManager.getUpdaters(this, true);
203
233
  }
204
234
  pause() {
205
235
  if (!guardCheck(this)) {
@@ -218,7 +248,7 @@ export class Container {
218
248
  if (!this.pageHidden) {
219
249
  this._paused = true;
220
250
  }
221
- this._engine.dispatchEvent(EventType.containerPaused, { container: this });
251
+ this.dispatchEvent(EventType.containerPaused);
222
252
  }
223
253
  play(force) {
224
254
  if (!guardCheck(this)) {
@@ -239,7 +269,7 @@ export class Container {
239
269
  }
240
270
  }
241
271
  }
242
- this._engine.dispatchEvent(EventType.containerPlay, { container: this });
272
+ this.dispatchEvent(EventType.containerPlay);
243
273
  this.draw(needsUpdate ?? false);
244
274
  }
245
275
  async refresh() {
@@ -255,8 +285,8 @@ export class Container {
255
285
  }
256
286
  this._initialSourceOptions = sourceOptions;
257
287
  this._sourceOptions = sourceOptions;
258
- this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
259
- this.actualOptions = loadContainerOptions(this._engine, this, this._options);
288
+ this._options = loadContainerOptions(this._pluginManager, this, this._initialSourceOptions, this.sourceOptions);
289
+ this.actualOptions = loadContainerOptions(this._pluginManager, this, this._options);
260
290
  return this.refresh();
261
291
  }
262
292
  async start() {
@@ -271,7 +301,7 @@ export class Container {
271
301
  for (const plugin of this.plugins) {
272
302
  await plugin.start?.();
273
303
  }
274
- this._engine.dispatchEvent(EventType.containerStarted, { container: this });
304
+ this.dispatchEvent(EventType.containerStarted);
275
305
  this.play();
276
306
  resolve();
277
307
  };
@@ -299,7 +329,7 @@ export class Container {
299
329
  this.particleDestroyedPlugins.length = 0;
300
330
  this.particlePositionPlugins.length = 0;
301
331
  this._sourceOptions = this._options;
302
- this._engine.dispatchEvent(EventType.containerStopped, { container: this });
332
+ this.dispatchEvent(EventType.containerStopped);
303
333
  }
304
334
  updateActualOptions() {
305
335
  let refresh = false;
@@ -326,7 +356,7 @@ export class Container {
326
356
  this.draw(false);
327
357
  return;
328
358
  }
329
- this.canvas.drawParticles(this._delta);
359
+ this.canvas.render.drawParticles(this._delta);
330
360
  if (!this.alive()) {
331
361
  this.destroy();
332
362
  return;