@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
@@ -1,407 +0,0 @@
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", "./Utils/Constants.js", "../Enums/Types/EventType.js", "../Enums/Modes/LimitMode.js", "./Particle.js", "./Utils/SpatialHashGrid.js", "../Utils/LogUtils.js", "../Utils/OptionsUtils.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Particles = void 0;
13
- const Constants_js_1 = require("./Utils/Constants.js");
14
- const EventType_js_1 = require("../Enums/Types/EventType.js");
15
- const LimitMode_js_1 = require("../Enums/Modes/LimitMode.js");
16
- const Particle_js_1 = require("./Particle.js");
17
- const SpatialHashGrid_js_1 = require("./Utils/SpatialHashGrid.js");
18
- const LogUtils_js_1 = require("../Utils/LogUtils.js");
19
- const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
20
- class Particles {
21
- checkParticlePositionPlugins;
22
- effectDrawers;
23
- grid;
24
- shapeDrawers;
25
- updaters;
26
- _array;
27
- _container;
28
- _engine;
29
- _groupLimits;
30
- _limit;
31
- _maxZIndex;
32
- _minZIndex;
33
- _needsSort;
34
- _nextId;
35
- _particleResetPlugins;
36
- _particleUpdatePlugins;
37
- _pool;
38
- _postParticleUpdatePlugins;
39
- _postUpdatePlugins;
40
- _resizeFactor;
41
- _updatePlugins;
42
- _zArray;
43
- constructor(engine, container) {
44
- this._engine = engine;
45
- this._container = container;
46
- this._nextId = 0;
47
- this._array = [];
48
- this._zArray = [];
49
- this._pool = [];
50
- this._limit = 0;
51
- this._groupLimits = new Map();
52
- this._needsSort = false;
53
- this._minZIndex = 0;
54
- this._maxZIndex = 0;
55
- this.grid = new SpatialHashGrid_js_1.SpatialHashGrid(Constants_js_1.spatialHashGridCellSize);
56
- this.effectDrawers = new Map();
57
- this.shapeDrawers = new Map();
58
- this.updaters = [];
59
- this.checkParticlePositionPlugins = [];
60
- this._particleResetPlugins = [];
61
- this._particleUpdatePlugins = [];
62
- this._postUpdatePlugins = [];
63
- this._postParticleUpdatePlugins = [];
64
- this._updatePlugins = [];
65
- }
66
- get count() {
67
- return this._array.length;
68
- }
69
- addParticle(position, overrideOptions, group, initializer) {
70
- const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
71
- if (limit > Constants_js_1.minLimit) {
72
- switch (limitMode) {
73
- case LimitMode_js_1.LimitMode.delete: {
74
- const countToRemove = currentCount + Constants_js_1.countOffset - limit;
75
- if (countToRemove > Constants_js_1.minCount) {
76
- this.removeQuantity(countToRemove);
77
- }
78
- break;
79
- }
80
- case LimitMode_js_1.LimitMode.wait:
81
- if (currentCount >= limit) {
82
- return;
83
- }
84
- break;
85
- default:
86
- break;
87
- }
88
- }
89
- try {
90
- const particle = this._pool.pop() ?? new Particle_js_1.Particle(this._engine, this._container);
91
- particle.init(this._nextId, position, overrideOptions, group);
92
- let canAdd = true;
93
- if (initializer) {
94
- canAdd = initializer(particle);
95
- }
96
- if (!canAdd) {
97
- this._pool.push(particle);
98
- return;
99
- }
100
- this._array.push(particle);
101
- this._zArray.push(particle);
102
- this._nextId++;
103
- this._engine.dispatchEvent(EventType_js_1.EventType.particleAdded, {
104
- container: this._container,
105
- data: {
106
- particle,
107
- },
108
- });
109
- return particle;
110
- }
111
- catch (e) {
112
- (0, LogUtils_js_1.getLogger)().warning(`error adding particle: ${e}`);
113
- }
114
- return undefined;
115
- }
116
- clear() {
117
- this._array = [];
118
- this._zArray = [];
119
- }
120
- destroy() {
121
- const container = this._container;
122
- for (const [, effectDrawer] of this.effectDrawers) {
123
- effectDrawer.destroy?.(container);
124
- }
125
- for (const [, shapeDrawer] of this.shapeDrawers) {
126
- shapeDrawer.destroy?.(container);
127
- }
128
- this._array = [];
129
- this._pool.length = 0;
130
- this._zArray = [];
131
- this.effectDrawers = new Map();
132
- this.shapeDrawers = new Map();
133
- this.updaters = [];
134
- this.checkParticlePositionPlugins = [];
135
- this._particleResetPlugins = [];
136
- this._particleUpdatePlugins = [];
137
- this._postUpdatePlugins = [];
138
- this._postParticleUpdatePlugins = [];
139
- this._updatePlugins = [];
140
- }
141
- drawParticles(delta) {
142
- for (const particle of this._zArray) {
143
- particle.draw(delta);
144
- }
145
- }
146
- filter(condition) {
147
- return this._array.filter(condition);
148
- }
149
- find(condition) {
150
- return this._array.find(condition);
151
- }
152
- get(index) {
153
- return this._array[index];
154
- }
155
- async init() {
156
- const container = this._container, options = container.actualOptions;
157
- this._minZIndex = 0;
158
- this._maxZIndex = 0;
159
- this._needsSort = false;
160
- this.checkParticlePositionPlugins = [];
161
- this._updatePlugins = [];
162
- this._particleUpdatePlugins = [];
163
- this._postUpdatePlugins = [];
164
- this._particleResetPlugins = [];
165
- this._postParticleUpdatePlugins = [];
166
- this.grid = new SpatialHashGrid_js_1.SpatialHashGrid(Constants_js_1.spatialHashGridCellSize * container.retina.pixelRatio);
167
- for (const plugin of container.plugins) {
168
- if (plugin.redrawInit) {
169
- await plugin.redrawInit();
170
- }
171
- if (plugin.checkParticlePosition) {
172
- this.checkParticlePositionPlugins.push(plugin);
173
- }
174
- if (plugin.update) {
175
- this._updatePlugins.push(plugin);
176
- }
177
- if (plugin.particleUpdate) {
178
- this._particleUpdatePlugins.push(plugin);
179
- }
180
- if (plugin.postUpdate) {
181
- this._postUpdatePlugins.push(plugin);
182
- }
183
- if (plugin.particleReset) {
184
- this._particleResetPlugins.push(plugin);
185
- }
186
- if (plugin.postParticleUpdate) {
187
- this._postParticleUpdatePlugins.push(plugin);
188
- }
189
- }
190
- await this.initPlugins();
191
- for (const drawer of this.effectDrawers.values()) {
192
- await drawer.init?.(container);
193
- }
194
- for (const drawer of this.shapeDrawers.values()) {
195
- await drawer.init?.(container);
196
- }
197
- let handled = false;
198
- for (const plugin of container.plugins) {
199
- handled = plugin.particlesInitialization?.() ?? handled;
200
- if (handled) {
201
- break;
202
- }
203
- }
204
- if (!handled) {
205
- const particlesOptions = options.particles, groups = particlesOptions.groups;
206
- for (const group in groups) {
207
- const groupOptions = groups[group];
208
- if (!groupOptions) {
209
- continue;
210
- }
211
- for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
212
- this.addParticle(undefined, groupOptions, group);
213
- }
214
- }
215
- for (let i = this.count; i < particlesOptions.number.value; i++) {
216
- this.addParticle();
217
- }
218
- }
219
- }
220
- async initPlugins() {
221
- const container = this._container;
222
- this.effectDrawers = await this._engine.getEffectDrawers(container, true);
223
- this.shapeDrawers = await this._engine.getShapeDrawers(container, true);
224
- this.updaters = await this._engine.getUpdaters(container, true);
225
- }
226
- push(nb, position, overrideOptions, group) {
227
- for (let i = 0; i < nb; i++) {
228
- this.addParticle(position, overrideOptions, group);
229
- }
230
- }
231
- async redraw() {
232
- this.clear();
233
- await this.init();
234
- this._container.canvas.drawParticles({ value: 0, factor: 0 });
235
- }
236
- remove(particle, group, override) {
237
- this.removeAt(this._array.indexOf(particle), undefined, group, override);
238
- }
239
- removeAt(index, quantity = Constants_js_1.defaultRemoveQuantity, group, override) {
240
- if (index < Constants_js_1.minIndex || index > this.count) {
241
- return;
242
- }
243
- let deleted = 0;
244
- for (let i = index; deleted < quantity && i < this.count; i++) {
245
- if (this._removeParticle(i, group, override)) {
246
- i--;
247
- deleted++;
248
- }
249
- }
250
- }
251
- removeQuantity(quantity, group) {
252
- this.removeAt(Constants_js_1.minIndex, quantity, group);
253
- }
254
- setDensity() {
255
- const options = this._container.actualOptions, groups = options.particles.groups;
256
- let pluginsCount = 0;
257
- for (const plugin of this._container.plugins) {
258
- if (plugin.particlesDensityCount) {
259
- pluginsCount += plugin.particlesDensityCount();
260
- }
261
- }
262
- for (const group in groups) {
263
- const groupData = groups[group];
264
- if (!groupData) {
265
- continue;
266
- }
267
- const groupDataOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._engine, this._container, groupData);
268
- this._applyDensity(groupDataOptions, pluginsCount, group);
269
- }
270
- this._applyDensity(options.particles, pluginsCount);
271
- }
272
- setLastZIndex(zIndex) {
273
- this._needsSort ||= zIndex >= this._maxZIndex || (zIndex > this._minZIndex && zIndex < this._maxZIndex);
274
- }
275
- setResizeFactor(factor) {
276
- this._resizeFactor = factor;
277
- }
278
- update(delta) {
279
- const particlesToDelete = new Set();
280
- this.grid.clear();
281
- for (const plugin of this._updatePlugins) {
282
- plugin.update?.(delta);
283
- }
284
- const resizeFactor = this._resizeFactor;
285
- for (const particle of this._array) {
286
- if (resizeFactor && !particle.ignoresResizeRatio) {
287
- particle.position.x *= resizeFactor.width;
288
- particle.position.y *= resizeFactor.height;
289
- particle.initialPosition.x *= resizeFactor.width;
290
- particle.initialPosition.y *= resizeFactor.height;
291
- }
292
- particle.ignoresResizeRatio = false;
293
- for (const plugin of this._particleResetPlugins) {
294
- plugin.particleReset?.(particle);
295
- }
296
- for (const plugin of this._particleUpdatePlugins) {
297
- if (particle.destroyed) {
298
- break;
299
- }
300
- plugin.particleUpdate?.(particle, delta);
301
- }
302
- if (particle.destroyed) {
303
- particlesToDelete.add(particle);
304
- continue;
305
- }
306
- this.grid.insert(particle);
307
- }
308
- if (particlesToDelete.size) {
309
- const checkDelete = (p) => !particlesToDelete.has(p);
310
- this._array = this.filter(checkDelete);
311
- this._zArray = this._zArray.filter(checkDelete);
312
- for (const particle of particlesToDelete) {
313
- this._engine.dispatchEvent(EventType_js_1.EventType.particleRemoved, {
314
- container: this._container,
315
- data: {
316
- particle,
317
- },
318
- });
319
- }
320
- this._addToPool(...particlesToDelete);
321
- }
322
- for (const plugin of this._postUpdatePlugins) {
323
- plugin.postUpdate?.(delta);
324
- }
325
- for (const particle of this._array) {
326
- for (const updater of this.updaters) {
327
- updater.update(particle, delta);
328
- }
329
- if (!particle.destroyed && !particle.spawning) {
330
- for (const plugin of this._postParticleUpdatePlugins) {
331
- plugin.postParticleUpdate?.(particle, delta);
332
- }
333
- }
334
- }
335
- delete this._resizeFactor;
336
- if (this._needsSort) {
337
- const zArray = this._zArray;
338
- zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
339
- const firstItem = zArray[Constants_js_1.minIndex], lastItem = zArray[zArray.length - Constants_js_1.lengthOffset];
340
- if (!firstItem || !lastItem) {
341
- return;
342
- }
343
- this._maxZIndex = firstItem.position.z;
344
- this._minZIndex = lastItem.position.z;
345
- this._needsSort = false;
346
- }
347
- }
348
- _addToPool = (...particles) => {
349
- this._pool.push(...particles);
350
- };
351
- _applyDensity = (options, pluginsCount, group, groupOptions) => {
352
- const numberOptions = options.number;
353
- if (!numberOptions.density.enable) {
354
- if (group === undefined) {
355
- this._limit = numberOptions.limit.value;
356
- }
357
- else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
358
- this._groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
359
- }
360
- return;
361
- }
362
- const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > Constants_js_1.minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
363
- if (group === undefined) {
364
- this._limit = numberOptions.limit.value * densityFactor;
365
- }
366
- else {
367
- this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
368
- }
369
- if (particlesCount < particlesNumber) {
370
- this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
371
- }
372
- else if (particlesCount > particlesNumber) {
373
- this.removeQuantity(particlesCount - particlesNumber, group);
374
- }
375
- };
376
- _initDensityFactor = densityOptions => {
377
- const container = this._container;
378
- if (!container.canvas.element || !densityOptions.enable) {
379
- return Constants_js_1.defaultDensityFactor;
380
- }
381
- const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
382
- return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** Constants_js_1.squareExp);
383
- };
384
- _removeParticle = (index, group, override) => {
385
- const particle = this._array[index];
386
- if (!particle) {
387
- return false;
388
- }
389
- if (particle.group !== group) {
390
- return false;
391
- }
392
- const zIdx = this._zArray.indexOf(particle);
393
- this._array.splice(index, Constants_js_1.deleteCount);
394
- this._zArray.splice(zIdx, Constants_js_1.deleteCount);
395
- particle.destroy(override);
396
- this._engine.dispatchEvent(EventType_js_1.EventType.particleRemoved, {
397
- container: this._container,
398
- data: {
399
- particle,
400
- },
401
- });
402
- this._addToPool(particle);
403
- return true;
404
- };
405
- }
406
- exports.Particles = Particles;
407
- });
@@ -1,52 +0,0 @@
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", "./Utils/Constants.js", "../Utils/MathUtils.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Retina = void 0;
13
- const Constants_js_1 = require("./Utils/Constants.js");
14
- const MathUtils_js_1 = require("../Utils/MathUtils.js");
15
- class Retina {
16
- container;
17
- maxSpeed;
18
- pixelRatio;
19
- reduceFactor;
20
- sizeAnimationSpeed;
21
- constructor(container) {
22
- this.container = container;
23
- this.pixelRatio = Constants_js_1.defaultRatio;
24
- this.reduceFactor = Constants_js_1.defaultReduceFactor;
25
- }
26
- init() {
27
- const container = this.container, options = container.actualOptions;
28
- this.pixelRatio = options.detectRetina ? devicePixelRatio : Constants_js_1.defaultRatio;
29
- this.reduceFactor = Constants_js_1.defaultReduceFactor;
30
- const ratio = this.pixelRatio, canvas = container.canvas;
31
- if (canvas.element) {
32
- const element = canvas.element;
33
- canvas.size.width = element.offsetWidth * ratio;
34
- canvas.size.height = element.offsetHeight * ratio;
35
- }
36
- const particles = options.particles, moveOptions = particles.move;
37
- this.maxSpeed = (0, MathUtils_js_1.getRangeValue)(moveOptions.gravity.maxSpeed) * ratio;
38
- this.sizeAnimationSpeed = (0, MathUtils_js_1.getRangeValue)(particles.size.animation.speed) * ratio;
39
- }
40
- initParticle(particle) {
41
- const options = particle.options, ratio = this.pixelRatio, moveOptions = options.move, moveDistance = moveOptions.distance, props = particle.retina;
42
- props.moveDrift = (0, MathUtils_js_1.getRangeValue)(moveOptions.drift) * ratio;
43
- props.moveSpeed = (0, MathUtils_js_1.getRangeValue)(moveOptions.speed) * ratio;
44
- props.sizeAnimationSpeed = (0, MathUtils_js_1.getRangeValue)(options.size.animation.speed) * ratio;
45
- const maxDistance = props.maxDistance;
46
- maxDistance.horizontal = moveDistance.horizontal !== undefined ? moveDistance.horizontal * ratio : undefined;
47
- maxDistance.vertical = moveDistance.vertical !== undefined ? moveDistance.vertical * ratio : undefined;
48
- props.maxSpeed = (0, MathUtils_js_1.getRangeValue)(moveOptions.gravity.maxSpeed) * ratio;
49
- }
50
- }
51
- exports.Retina = Retina;
52
- });
@@ -1,23 +0,0 @@
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
- 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.deleteCount = exports.defaultDensityFactor = exports.lengthOffset = exports.minIndex = exports.minCount = exports.countOffset = exports.minLimit = exports.minZ = exports.tryCountIncrement = exports.decayOffset = exports.none = exports.one = exports.loadMinIndex = exports.loadRandomFactor = exports.canvasFirstIndex = exports.minFpsLimit = exports.defaultFpsLimit = exports.removeMinIndex = exports.removeDeleteCount = exports.defaultOpacity = exports.zIndexFactorOffset = 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.defaultReduceFactor = exports.defaultRatio = exports.defaultRemoveQuantity = exports.spatialHashGridCellSize = 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
- x: 0,
15
- y: 0,
16
- z: 0,
17
- }, exports.defaultTransform = {
18
- a: 1,
19
- b: 0,
20
- c: 0,
21
- d: 1,
22
- }, exports.randomColorValue = "random", exports.midColorValue = "mid", exports.double = 2, exports.doublePI = Math.PI * exports.double, exports.defaultFps = 60, exports.defaultAlpha = 1, exports.generatedTrue = "true", exports.generatedFalse = "false", exports.canvasTag = "canvas", exports.defaultRetryCount = 0, exports.squareExp = 2, exports.spatialHashGridCellSize = 100, exports.defaultRemoveQuantity = 1, exports.defaultRatio = 1, exports.defaultReduceFactor = 1, exports.inverseFactorNumerator = 1, exports.rgbMax = 255, exports.hMax = 360, exports.sMax = 100, exports.lMax = 100, exports.hMin = 0, exports.sMin = 0, exports.hPhase = 60, exports.empty = 0, exports.quarter = 0.25, exports.threeQuarter = exports.half + exports.quarter, exports.minVelocity = 0, exports.defaultTransformValue = 1, exports.minimumSize = 0, exports.zIndexFactorOffset = 1, exports.defaultOpacity = 1, exports.removeDeleteCount = 1, exports.removeMinIndex = 0, exports.defaultFpsLimit = 120, exports.minFpsLimit = 0, exports.canvasFirstIndex = 0, exports.loadRandomFactor = 10000, exports.loadMinIndex = 0, exports.one = 1, exports.none = 0, exports.decayOffset = 1, exports.tryCountIncrement = 1, exports.minZ = 0, exports.minLimit = 0, exports.countOffset = 1, exports.minCount = 0, exports.minIndex = 0, exports.lengthOffset = 1, exports.defaultDensityFactor = 1, exports.deleteCount = 1, exports.defaultAngle = 0, exports.identity = 1, exports.minStrokeWidth = 0, exports.lFactor = 1, exports.lMin = 0, exports.triple = 3, exports.sextuple = 6, exports.sNormalizedOffset = 1, exports.phaseNumerator = 1, exports.defaultRgbMin = 0, exports.defaultVelocity = 0, exports.defaultLoops = 0, exports.defaultTime = 0, exports.defaultZoom = 1;
23
- });
@@ -1,102 +0,0 @@
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", "../../Utils/Utils.js", "./Constants.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.EventListeners = void 0;
13
- const Utils_js_1 = require("../../Utils/Utils.js");
14
- const Constants_js_1 = require("./Constants.js");
15
- class EventListeners {
16
- container;
17
- _handlers;
18
- _resizeObserver;
19
- _resizeTimeout;
20
- constructor(container) {
21
- this.container = container;
22
- this._handlers = {
23
- visibilityChange: () => {
24
- this._handleVisibilityChange();
25
- },
26
- resize: () => {
27
- this._handleWindowResize();
28
- },
29
- };
30
- }
31
- addListeners() {
32
- this._manageListeners(true);
33
- }
34
- removeListeners() {
35
- this._manageListeners(false);
36
- }
37
- _handleVisibilityChange = () => {
38
- const container = this.container, options = container.actualOptions;
39
- if (!options.pauseOnBlur) {
40
- return;
41
- }
42
- if ((0, Utils_js_1.safeDocument)().hidden) {
43
- container.pageHidden = true;
44
- container.pause();
45
- }
46
- else {
47
- container.pageHidden = false;
48
- if (container.animationStatus) {
49
- container.play(true);
50
- }
51
- else {
52
- container.draw(true);
53
- }
54
- }
55
- };
56
- _handleWindowResize = () => {
57
- if (this._resizeTimeout) {
58
- clearTimeout(this._resizeTimeout);
59
- delete this._resizeTimeout;
60
- }
61
- const handleResize = async () => {
62
- const canvas = this.container.canvas;
63
- await canvas.windowResize();
64
- };
65
- this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.resize.delay * Constants_js_1.millisecondsToSeconds);
66
- };
67
- _manageListeners = add => {
68
- const handlers = this._handlers;
69
- this._manageResize(add);
70
- (0, Utils_js_1.manageListener)(document, Constants_js_1.visibilityChangeEvent, handlers.visibilityChange, add, false);
71
- };
72
- _manageResize = add => {
73
- const handlers = this._handlers, container = this.container, options = container.actualOptions;
74
- if (!options.resize.enable) {
75
- return;
76
- }
77
- if (typeof ResizeObserver === "undefined") {
78
- (0, Utils_js_1.manageListener)(globalThis, Constants_js_1.resizeEvent, handlers.resize, add);
79
- return;
80
- }
81
- const canvasEl = container.canvas.element;
82
- if (this._resizeObserver && !add) {
83
- if (canvasEl) {
84
- this._resizeObserver.unobserve(canvasEl);
85
- }
86
- this._resizeObserver.disconnect();
87
- delete this._resizeObserver;
88
- }
89
- else if (!this._resizeObserver && add && canvasEl) {
90
- this._resizeObserver = new ResizeObserver((entries) => {
91
- const entry = entries.find(e => e.target === canvasEl);
92
- if (!entry) {
93
- return;
94
- }
95
- this._handleWindowResize();
96
- });
97
- this._resizeObserver.observe(canvasEl);
98
- }
99
- };
100
- }
101
- exports.EventListeners = EventListeners;
102
- });
@@ -1,91 +0,0 @@
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", "../../Enums/RangeType.js", "../../Utils/MathUtils.js", "./Constants.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Rectangle = exports.Circle = exports.BaseRange = void 0;
13
- const RangeType_js_1 = require("../../Enums/RangeType.js");
14
- const MathUtils_js_1 = require("../../Utils/MathUtils.js");
15
- const Constants_js_1 = require("./Constants.js");
16
- class BaseRange {
17
- position;
18
- type;
19
- constructor(x, y, type) {
20
- this.position = {
21
- x: x,
22
- y: y,
23
- };
24
- this.type = type;
25
- }
26
- _resetPosition(x, y) {
27
- this.position.x = x;
28
- this.position.y = y;
29
- }
30
- }
31
- exports.BaseRange = BaseRange;
32
- class Circle extends BaseRange {
33
- radius;
34
- constructor(x, y, radius) {
35
- super(x, y, RangeType_js_1.RangeType.circle);
36
- this.radius = radius;
37
- }
38
- contains(point) {
39
- return (0, MathUtils_js_1.checkDistance)(point, this.position, this.radius);
40
- }
41
- intersects(range) {
42
- const pos1 = this.position, pos2 = range.position, r = this.radius, dx = Math.abs(pos2.x - pos1.x), dy = Math.abs(pos2.y - pos1.y);
43
- if (range instanceof Circle || range.type === RangeType_js_1.RangeType.circle) {
44
- const circleRange = range, rSum = r + circleRange.radius, dist = Math.hypot(dx, dy);
45
- return rSum > dist;
46
- }
47
- else if (range instanceof Rectangle || range.type === RangeType_js_1.RangeType.rectangle) {
48
- const rectRange = range, { width, height } = rectRange.size, edges = Math.pow(dx - width, Constants_js_1.squareExp) + Math.pow(dy - height, Constants_js_1.squareExp);
49
- return edges <= r ** Constants_js_1.squareExp || (dx <= r + width && dy <= r + height) || dx <= width || dy <= height;
50
- }
51
- return false;
52
- }
53
- reset(x, y, radius) {
54
- this._resetPosition(x, y);
55
- this.radius = radius;
56
- return this;
57
- }
58
- }
59
- exports.Circle = Circle;
60
- class Rectangle extends BaseRange {
61
- size;
62
- constructor(x, y, width, height) {
63
- super(x, y, RangeType_js_1.RangeType.rectangle);
64
- this.size = {
65
- height: height,
66
- width: width,
67
- };
68
- }
69
- contains(point) {
70
- const w = this.size.width, h = this.size.height, pos = this.position;
71
- return point.x >= pos.x && point.x <= pos.x + w && point.y >= pos.y && point.y <= pos.y + h;
72
- }
73
- intersects(range) {
74
- if (range instanceof Circle) {
75
- return range.intersects(this);
76
- }
77
- if (!(range instanceof Rectangle)) {
78
- return false;
79
- }
80
- const w = this.size.width, h = this.size.height, pos1 = this.position, pos2 = range.position, size2 = range.size, w2 = size2.width, h2 = size2.height;
81
- return pos2.x < pos1.x + w && pos2.x + w2 > pos1.x && pos2.y < pos1.y + h && pos2.y + h2 > pos1.y;
82
- }
83
- reset(x, y, width, height) {
84
- this._resetPosition(x, y);
85
- this.size.width = width;
86
- this.size.height = height;
87
- return this;
88
- }
89
- }
90
- exports.Rectangle = Rectangle;
91
- });