@tsparticles/engine 4.0.0-alpha.8 → 4.0.0-beta.1

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 (307) hide show
  1. package/155.min.js +1 -0
  2. package/README.md +41 -28
  3. package/browser/Core/CanvasManager.js +303 -0
  4. package/browser/Core/Container.js +134 -101
  5. package/browser/Core/Engine.js +29 -162
  6. package/browser/Core/Particle.js +197 -183
  7. package/browser/Core/ParticlesManager.js +363 -0
  8. package/browser/Core/RenderManager.js +303 -0
  9. package/browser/Core/Retina.js +6 -6
  10. package/browser/Core/Utils/Constants.js +2 -2
  11. package/browser/Core/Utils/EventListeners.js +67 -63
  12. package/browser/Core/Utils/PluginManager.js +145 -0
  13. package/browser/Core/Utils/Ranges.js +29 -10
  14. package/browser/Core/Utils/SpatialHashGrid.js +102 -0
  15. package/browser/Core/Utils/Vectors.js +17 -18
  16. package/browser/Options/Classes/AnimatableColor.js +1 -0
  17. package/browser/Options/Classes/AnimationOptions.js +8 -0
  18. package/browser/Options/Classes/Background/Background.js +6 -0
  19. package/browser/Options/Classes/ColorAnimation.js +12 -1
  20. package/browser/Options/Classes/FullScreen/FullScreen.js +2 -0
  21. package/browser/Options/Classes/HslAnimation.js +4 -5
  22. package/browser/Options/Classes/Options.js +67 -8
  23. package/browser/Options/Classes/OptionsColor.js +1 -0
  24. package/browser/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
  25. package/browser/Options/Classes/Particles/Effect/Effect.js +3 -4
  26. package/browser/Options/Classes/Particles/Fill.js +28 -0
  27. package/browser/Options/Classes/Particles/Move/Move.js +17 -3
  28. package/browser/Options/Classes/Particles/Move/MoveAngle.js +2 -0
  29. package/browser/Options/Classes/Particles/Move/MoveCenter.js +4 -0
  30. package/browser/Options/Classes/Particles/Move/MoveGravity.js +4 -0
  31. package/browser/Options/Classes/Particles/Move/OutModes.js +5 -0
  32. package/browser/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
  33. package/browser/Options/Classes/Particles/Move/Spin.js +3 -0
  34. package/browser/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
  35. package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
  36. package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
  37. package/browser/Options/Classes/Particles/Opacity/Opacity.js +1 -0
  38. package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
  39. package/browser/Options/Classes/Particles/ParticlesOptions.js +29 -9
  40. package/browser/Options/Classes/Particles/Shape/Shape.js +3 -4
  41. package/browser/Options/Classes/Particles/Size/Size.js +1 -0
  42. package/browser/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
  43. package/browser/Options/Classes/Particles/Stroke.js +3 -0
  44. package/browser/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
  45. package/browser/Options/Classes/ResizeEvent.js +2 -0
  46. package/browser/Options/Classes/ValueWithRandom.js +3 -4
  47. package/browser/Utils/CanvasUtils.js +44 -51
  48. package/browser/Utils/ColorUtils.js +51 -40
  49. package/browser/Utils/EventDispatcher.js +1 -0
  50. package/browser/Utils/LogUtils.js +1 -0
  51. package/browser/Utils/MathUtils.js +12 -7
  52. package/browser/Utils/OptionsUtils.js +2 -2
  53. package/browser/Utils/Utils.js +109 -31
  54. package/browser/exports.js +1 -2
  55. package/cjs/Core/CanvasManager.js +303 -0
  56. package/cjs/Core/Container.js +134 -101
  57. package/cjs/Core/Engine.js +29 -162
  58. package/cjs/Core/Particle.js +197 -183
  59. package/cjs/Core/ParticlesManager.js +363 -0
  60. package/cjs/Core/RenderManager.js +303 -0
  61. package/cjs/Core/Retina.js +6 -6
  62. package/cjs/Core/Utils/Constants.js +2 -2
  63. package/cjs/Core/Utils/EventListeners.js +67 -63
  64. package/cjs/Core/Utils/PluginManager.js +145 -0
  65. package/cjs/Core/Utils/Ranges.js +29 -10
  66. package/cjs/Core/Utils/SpatialHashGrid.js +102 -0
  67. package/cjs/Core/Utils/Vectors.js +17 -18
  68. package/cjs/Options/Classes/AnimatableColor.js +1 -0
  69. package/cjs/Options/Classes/AnimationOptions.js +8 -0
  70. package/cjs/Options/Classes/Background/Background.js +6 -0
  71. package/cjs/Options/Classes/ColorAnimation.js +12 -1
  72. package/cjs/Options/Classes/FullScreen/FullScreen.js +2 -0
  73. package/cjs/Options/Classes/HslAnimation.js +4 -5
  74. package/cjs/Options/Classes/Options.js +67 -8
  75. package/cjs/Options/Classes/OptionsColor.js +1 -0
  76. package/cjs/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
  77. package/cjs/Options/Classes/Particles/Effect/Effect.js +3 -4
  78. package/cjs/Options/Classes/Particles/Fill.js +28 -0
  79. package/cjs/Options/Classes/Particles/Move/Move.js +17 -3
  80. package/cjs/Options/Classes/Particles/Move/MoveAngle.js +2 -0
  81. package/cjs/Options/Classes/Particles/Move/MoveCenter.js +4 -0
  82. package/cjs/Options/Classes/Particles/Move/MoveGravity.js +4 -0
  83. package/cjs/Options/Classes/Particles/Move/OutModes.js +5 -0
  84. package/cjs/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
  85. package/cjs/Options/Classes/Particles/Move/Spin.js +3 -0
  86. package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
  87. package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
  88. package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
  89. package/cjs/Options/Classes/Particles/Opacity/Opacity.js +1 -0
  90. package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
  91. package/cjs/Options/Classes/Particles/ParticlesOptions.js +29 -9
  92. package/cjs/Options/Classes/Particles/Shape/Shape.js +3 -4
  93. package/cjs/Options/Classes/Particles/Size/Size.js +1 -0
  94. package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
  95. package/cjs/Options/Classes/Particles/Stroke.js +3 -0
  96. package/cjs/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
  97. package/cjs/Options/Classes/ResizeEvent.js +2 -0
  98. package/cjs/Options/Classes/ValueWithRandom.js +3 -4
  99. package/cjs/Utils/CanvasUtils.js +44 -51
  100. package/cjs/Utils/ColorUtils.js +51 -40
  101. package/cjs/Utils/EventDispatcher.js +1 -0
  102. package/cjs/Utils/LogUtils.js +1 -0
  103. package/cjs/Utils/MathUtils.js +12 -7
  104. package/cjs/Utils/OptionsUtils.js +2 -2
  105. package/cjs/Utils/Utils.js +109 -31
  106. package/cjs/exports.js +1 -2
  107. package/dist_browser_Core_Container_js.js +30 -20
  108. package/esm/Core/CanvasManager.js +303 -0
  109. package/esm/Core/Container.js +134 -101
  110. package/esm/Core/Engine.js +29 -162
  111. package/esm/Core/Particle.js +197 -183
  112. package/esm/Core/ParticlesManager.js +363 -0
  113. package/esm/Core/RenderManager.js +303 -0
  114. package/esm/Core/Retina.js +6 -6
  115. package/esm/Core/Utils/Constants.js +2 -2
  116. package/esm/Core/Utils/EventListeners.js +67 -63
  117. package/esm/Core/Utils/PluginManager.js +145 -0
  118. package/esm/Core/Utils/Ranges.js +29 -10
  119. package/esm/Core/Utils/SpatialHashGrid.js +102 -0
  120. package/esm/Core/Utils/Vectors.js +17 -18
  121. package/esm/Options/Classes/AnimatableColor.js +1 -0
  122. package/esm/Options/Classes/AnimationOptions.js +8 -0
  123. package/esm/Options/Classes/Background/Background.js +6 -0
  124. package/esm/Options/Classes/ColorAnimation.js +12 -1
  125. package/esm/Options/Classes/FullScreen/FullScreen.js +2 -0
  126. package/esm/Options/Classes/HslAnimation.js +4 -5
  127. package/esm/Options/Classes/Options.js +67 -8
  128. package/esm/Options/Classes/OptionsColor.js +1 -0
  129. package/esm/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
  130. package/esm/Options/Classes/Particles/Effect/Effect.js +3 -4
  131. package/esm/Options/Classes/Particles/Fill.js +28 -0
  132. package/esm/Options/Classes/Particles/Move/Move.js +17 -3
  133. package/esm/Options/Classes/Particles/Move/MoveAngle.js +2 -0
  134. package/esm/Options/Classes/Particles/Move/MoveCenter.js +4 -0
  135. package/esm/Options/Classes/Particles/Move/MoveGravity.js +4 -0
  136. package/esm/Options/Classes/Particles/Move/OutModes.js +5 -0
  137. package/esm/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
  138. package/esm/Options/Classes/Particles/Move/Spin.js +3 -0
  139. package/esm/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
  140. package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
  141. package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
  142. package/esm/Options/Classes/Particles/Opacity/Opacity.js +1 -0
  143. package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
  144. package/esm/Options/Classes/Particles/ParticlesOptions.js +29 -9
  145. package/esm/Options/Classes/Particles/Shape/Shape.js +3 -4
  146. package/esm/Options/Classes/Particles/Size/Size.js +1 -0
  147. package/esm/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
  148. package/esm/Options/Classes/Particles/Stroke.js +3 -0
  149. package/esm/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
  150. package/esm/Options/Classes/ResizeEvent.js +2 -0
  151. package/esm/Options/Classes/ValueWithRandom.js +3 -4
  152. package/esm/Utils/CanvasUtils.js +44 -51
  153. package/esm/Utils/ColorUtils.js +51 -40
  154. package/esm/Utils/EventDispatcher.js +1 -0
  155. package/esm/Utils/LogUtils.js +1 -0
  156. package/esm/Utils/MathUtils.js +12 -7
  157. package/esm/Utils/OptionsUtils.js +2 -2
  158. package/esm/Utils/Utils.js +109 -31
  159. package/esm/exports.js +1 -2
  160. package/package.json +1 -1
  161. package/report.html +84 -29
  162. package/scripts/install.js +4 -20
  163. package/tsparticles.engine.js +98 -86
  164. package/tsparticles.engine.min.js +2 -2
  165. package/types/Core/CanvasManager.d.ts +39 -0
  166. package/types/Core/Container.d.ts +29 -14
  167. package/types/Core/Engine.d.ts +2 -61
  168. package/types/Core/Interfaces/IColorManager.d.ts +0 -1
  169. package/types/Core/Interfaces/IContainerPlugin.d.ts +10 -8
  170. package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
  171. package/types/Core/Interfaces/IPalette.d.ts +7 -0
  172. package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
  173. package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
  174. package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
  175. package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
  176. package/types/Core/Interfaces/IShapeDrawData.d.ts +10 -1
  177. package/types/Core/Interfaces/IShapeDrawer.d.ts +0 -1
  178. package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
  179. package/types/Core/Particle.d.ts +7 -11
  180. package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +15 -14
  181. package/types/Core/RenderManager.d.ts +49 -0
  182. package/types/Core/Retina.d.ts +0 -2
  183. package/types/Core/Utils/Constants.d.ts +2 -2
  184. package/types/Core/Utils/PluginManager.d.ts +62 -0
  185. package/types/Core/Utils/Ranges.d.ts +4 -1
  186. package/types/Core/Utils/SpatialHashGrid.d.ts +25 -0
  187. package/types/Core/Utils/Vectors.d.ts +8 -10
  188. package/types/Options/Classes/ColorAnimation.d.ts +3 -1
  189. package/types/Options/Classes/HslAnimation.d.ts +3 -4
  190. package/types/Options/Classes/Options.d.ts +5 -3
  191. package/types/Options/Classes/Particles/Effect/Effect.d.ts +0 -1
  192. package/types/Options/Classes/Particles/Fill.d.ts +12 -0
  193. package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
  194. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +5 -5
  195. package/types/Options/Classes/Particles/Shape/Shape.d.ts +0 -1
  196. package/types/Options/Classes/ValueWithRandom.d.ts +0 -1
  197. package/types/Options/Interfaces/IColorAnimation.d.ts +2 -0
  198. package/types/Options/Interfaces/IOptions.d.ts +1 -0
  199. package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +0 -1
  200. package/types/Options/Interfaces/Particles/IFill.d.ts +9 -0
  201. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -2
  202. package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -2
  203. package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
  204. package/types/Options/Interfaces/Particles/Shape/IShape.d.ts +0 -1
  205. package/types/Types/CanvasContextType.d.ts +1 -0
  206. package/types/Types/EngineInitializers.d.ts +6 -3
  207. package/types/Utils/CanvasUtils.d.ts +13 -16
  208. package/types/Utils/ColorUtils.d.ts +11 -10
  209. package/types/Utils/LogUtils.d.ts +1 -0
  210. package/types/Utils/MathUtils.d.ts +2 -0
  211. package/types/Utils/OptionsUtils.d.ts +2 -2
  212. package/types/Utils/Utils.d.ts +8 -1
  213. package/types/export-types.d.ts +7 -7
  214. package/types/exports.d.ts +1 -2
  215. package/umd/Core/CanvasManager.js +317 -0
  216. package/umd/Core/Container.js +134 -101
  217. package/umd/Core/Engine.js +28 -161
  218. package/umd/Core/Particle.js +198 -184
  219. package/umd/Core/{Particles.js → ParticlesManager.js} +186 -167
  220. package/umd/Core/RenderManager.js +317 -0
  221. package/umd/Core/Retina.js +6 -6
  222. package/umd/Core/Utils/Constants.js +3 -3
  223. package/umd/Core/Utils/EventListeners.js +67 -63
  224. package/umd/Core/Utils/PluginManager.js +159 -0
  225. package/umd/Core/Utils/Ranges.js +28 -9
  226. package/umd/Core/Utils/SpatialHashGrid.js +116 -0
  227. package/umd/Core/Utils/Vectors.js +17 -18
  228. package/umd/Options/Classes/AnimatableColor.js +1 -0
  229. package/umd/Options/Classes/AnimationOptions.js +8 -0
  230. package/umd/Options/Classes/Background/Background.js +6 -0
  231. package/umd/Options/Classes/ColorAnimation.js +12 -1
  232. package/umd/Options/Classes/FullScreen/FullScreen.js +2 -0
  233. package/umd/Options/Classes/HslAnimation.js +5 -6
  234. package/umd/Options/Classes/Options.js +67 -8
  235. package/umd/Options/Classes/OptionsColor.js +1 -0
  236. package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
  237. package/umd/Options/Classes/Particles/Effect/Effect.js +3 -4
  238. package/umd/Options/Classes/Particles/Fill.js +42 -0
  239. package/umd/Options/Classes/Particles/Move/Move.js +18 -4
  240. package/umd/Options/Classes/Particles/Move/MoveAngle.js +2 -0
  241. package/umd/Options/Classes/Particles/Move/MoveCenter.js +4 -0
  242. package/umd/Options/Classes/Particles/Move/MoveGravity.js +4 -0
  243. package/umd/Options/Classes/Particles/Move/OutModes.js +5 -0
  244. package/umd/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
  245. package/umd/Options/Classes/Particles/Move/Spin.js +3 -0
  246. package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
  247. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
  248. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
  249. package/umd/Options/Classes/Particles/Opacity/Opacity.js +1 -0
  250. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
  251. package/umd/Options/Classes/Particles/ParticlesOptions.js +30 -10
  252. package/umd/Options/Classes/Particles/Shape/Shape.js +3 -4
  253. package/umd/Options/Classes/Particles/Size/Size.js +1 -0
  254. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
  255. package/umd/Options/Classes/Particles/Stroke.js +3 -0
  256. package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
  257. package/umd/Options/Classes/ResizeEvent.js +2 -0
  258. package/umd/Options/Classes/ValueWithRandom.js +3 -4
  259. package/umd/Utils/CanvasUtils.js +44 -53
  260. package/umd/Utils/ColorUtils.js +51 -39
  261. package/umd/Utils/EventDispatcher.js +1 -0
  262. package/umd/Utils/LogUtils.js +1 -0
  263. package/umd/Utils/MathUtils.js +14 -7
  264. package/umd/Utils/OptionsUtils.js +2 -2
  265. package/umd/Utils/Utils.js +111 -32
  266. package/umd/exports.js +2 -3
  267. package/794.min.js +0 -2
  268. package/794.min.js.LICENSE.txt +0 -1
  269. package/browser/Core/Canvas.js +0 -469
  270. package/browser/Core/Particles.js +0 -344
  271. package/browser/Core/Utils/Point.js +0 -6
  272. package/browser/Core/Utils/QuadTree.js +0 -59
  273. package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -33
  274. package/cjs/Core/Canvas.js +0 -469
  275. package/cjs/Core/Particles.js +0 -344
  276. package/cjs/Core/Utils/Point.js +0 -6
  277. package/cjs/Core/Utils/QuadTree.js +0 -59
  278. package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -33
  279. package/esm/Core/Canvas.js +0 -469
  280. package/esm/Core/Particles.js +0 -344
  281. package/esm/Core/Utils/Point.js +0 -6
  282. package/esm/Core/Utils/QuadTree.js +0 -59
  283. package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -33
  284. package/tsparticles.engine.min.js.LICENSE.txt +0 -1
  285. package/types/Core/Canvas.d.ts +0 -55
  286. package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -10
  287. package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
  288. package/types/Core/Utils/Point.d.ts +0 -7
  289. package/types/Core/Utils/QuadTree.d.ts +0 -18
  290. package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
  291. package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
  292. package/umd/Core/Canvas.js +0 -483
  293. package/umd/Core/Utils/Point.js +0 -20
  294. package/umd/Core/Utils/QuadTree.js +0 -73
  295. package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -47
  296. /package/browser/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  297. /package/browser/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  298. /package/browser/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
  299. /package/cjs/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  300. /package/cjs/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  301. /package/cjs/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
  302. /package/esm/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  303. /package/esm/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  304. /package/esm/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
  305. /package/umd/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  306. /package/umd/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  307. /package/umd/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
@@ -1,483 +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/CanvasUtils.js", "../Utils/Utils.js", "./Utils/Constants.js", "../Utils/ColorUtils.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Canvas = void 0;
13
- const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
14
- const Utils_js_1 = require("../Utils/Utils.js");
15
- const Constants_js_1 = require("./Utils/Constants.js");
16
- const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
17
- const fColorIndex = 0, sColorIndex = 1;
18
- function setTransformValue(factor, newFactor, key) {
19
- const newValue = newFactor[key];
20
- if (newValue !== undefined) {
21
- factor[key] = (factor[key] ?? Constants_js_1.defaultTransformValue) * newValue;
22
- }
23
- }
24
- function setStyle(canvas, style, important = false) {
25
- if (!style) {
26
- return;
27
- }
28
- const element = canvas, elementStyle = element.style, keys = new Set();
29
- for (let i = 0; i < elementStyle.length; i++) {
30
- const key = elementStyle.item(i);
31
- if (!key) {
32
- continue;
33
- }
34
- keys.add(key);
35
- }
36
- for (let i = 0; i < style.length; i++) {
37
- const key = style.item(i);
38
- if (!key) {
39
- continue;
40
- }
41
- keys.add(key);
42
- }
43
- for (const key of keys) {
44
- const value = style.getPropertyValue(key);
45
- if (value) {
46
- elementStyle.setProperty(key, value, important ? "important" : "");
47
- }
48
- else {
49
- elementStyle.removeProperty(key);
50
- }
51
- }
52
- }
53
- class Canvas {
54
- constructor(container, engine) {
55
- this.container = container;
56
- this._reusableColorStyles = {};
57
- this._reusablePluginColors = [undefined, undefined];
58
- this._reusableTransform = {};
59
- this._applyPostDrawUpdaters = particle => {
60
- for (const updater of this._postDrawUpdaters) {
61
- updater.afterDraw?.(particle);
62
- }
63
- };
64
- this._applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
65
- for (const updater of this._preDrawUpdaters) {
66
- if (updater.getColorStyles) {
67
- const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
68
- if (fill) {
69
- colorStyles.fill = fill;
70
- }
71
- if (stroke) {
72
- colorStyles.stroke = stroke;
73
- }
74
- }
75
- if (updater.getTransformValues) {
76
- const updaterTransform = updater.getTransformValues(particle);
77
- for (const key in updaterTransform) {
78
- setTransformValue(transform, updaterTransform, key);
79
- }
80
- }
81
- updater.beforeDraw?.(particle);
82
- }
83
- };
84
- this._applyResizePlugins = () => {
85
- for (const plugin of this._resizePlugins) {
86
- plugin.resize?.();
87
- }
88
- };
89
- this._getPluginParticleColors = particle => {
90
- let fColor, sColor;
91
- for (const plugin of this._colorPlugins) {
92
- if (!fColor && plugin.particleFillColor) {
93
- fColor = (0, ColorUtils_js_1.rangeColorToHsl)(this._engine, plugin.particleFillColor(particle));
94
- }
95
- if (!sColor && plugin.particleStrokeColor) {
96
- sColor = (0, ColorUtils_js_1.rangeColorToHsl)(this._engine, plugin.particleStrokeColor(particle));
97
- }
98
- if (fColor && sColor) {
99
- break;
100
- }
101
- }
102
- this._reusablePluginColors[fColorIndex] = fColor;
103
- this._reusablePluginColors[sColorIndex] = sColor;
104
- return this._reusablePluginColors;
105
- };
106
- this._initStyle = () => {
107
- const element = this.element, options = this.container.actualOptions;
108
- if (!element) {
109
- return;
110
- }
111
- if (this._fullScreen) {
112
- this._setFullScreenStyle();
113
- }
114
- else {
115
- this._resetOriginalStyle();
116
- }
117
- for (const key in options.style) {
118
- if (!key || !Object.hasOwn(options.style, key)) {
119
- continue;
120
- }
121
- const value = options.style[key];
122
- if (!value) {
123
- continue;
124
- }
125
- element.style.setProperty(key, value, "important");
126
- }
127
- };
128
- this._repairStyle = () => {
129
- const element = this.element;
130
- if (!element) {
131
- return;
132
- }
133
- this._safeMutationObserver(observer => {
134
- observer.disconnect();
135
- });
136
- this._initStyle();
137
- this.initBackground();
138
- const pointerEvents = this._pointerEvents;
139
- element.style.pointerEvents = pointerEvents;
140
- element.setAttribute("pointer-events", pointerEvents);
141
- this._safeMutationObserver(observer => {
142
- if (!(element instanceof Node)) {
143
- return;
144
- }
145
- observer.observe(element, { attributes: true });
146
- });
147
- };
148
- this._resetOriginalStyle = () => {
149
- const element = this.element, originalStyle = this._originalStyle;
150
- if (!element || !originalStyle) {
151
- return;
152
- }
153
- setStyle(element, originalStyle, true);
154
- };
155
- this._safeMutationObserver = callback => {
156
- if (!this._mutationObserver) {
157
- return;
158
- }
159
- callback(this._mutationObserver);
160
- };
161
- this._setFullScreenStyle = () => {
162
- const element = this.element;
163
- if (!element) {
164
- return;
165
- }
166
- setStyle(element, (0, Utils_js_1.getFullScreenStyle)(this.container.actualOptions.fullScreen.zIndex), true);
167
- };
168
- this._engine = engine;
169
- this._standardSize = {
170
- height: 0,
171
- width: 0,
172
- };
173
- const pxRatio = container.retina.pixelRatio, stdSize = this._standardSize;
174
- this.size = {
175
- height: stdSize.height * pxRatio,
176
- width: stdSize.width * pxRatio,
177
- };
178
- this._context = null;
179
- this._generated = false;
180
- this._preDrawUpdaters = [];
181
- this._postDrawUpdaters = [];
182
- this._resizePlugins = [];
183
- this._colorPlugins = [];
184
- this._pointerEvents = "none";
185
- }
186
- get _fullScreen() {
187
- return this.container.actualOptions.fullScreen.enable;
188
- }
189
- canvasClear() {
190
- if (!this.container.actualOptions.clear) {
191
- return;
192
- }
193
- this.draw(ctx => {
194
- (0, CanvasUtils_js_1.clear)(ctx, this.size);
195
- });
196
- }
197
- clear() {
198
- let pluginHandled = false;
199
- for (const plugin of this.container.plugins) {
200
- if (!pluginHandled && plugin.canvasClear) {
201
- pluginHandled = plugin.canvasClear();
202
- }
203
- }
204
- if (pluginHandled) {
205
- return;
206
- }
207
- this.canvasClear();
208
- }
209
- destroy() {
210
- this.stop();
211
- if (this._generated) {
212
- const element = this.element;
213
- element?.remove();
214
- this.element = undefined;
215
- }
216
- else {
217
- this._resetOriginalStyle();
218
- }
219
- this._preDrawUpdaters = [];
220
- this._postDrawUpdaters = [];
221
- this._resizePlugins = [];
222
- this._colorPlugins = [];
223
- }
224
- draw(cb) {
225
- const ctx = this._context;
226
- if (!ctx) {
227
- return;
228
- }
229
- return cb(ctx);
230
- }
231
- drawParticle(particle, delta) {
232
- if (particle.spawning || particle.destroyed) {
233
- return;
234
- }
235
- const radius = particle.getRadius();
236
- if (radius <= Constants_js_1.minimumSize) {
237
- return;
238
- }
239
- const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor() ?? pfColor;
240
- let [fColor, sColor] = this._getPluginParticleColors(particle);
241
- fColor ??= pfColor;
242
- sColor ??= psColor;
243
- if (!fColor && !sColor) {
244
- return;
245
- }
246
- const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - particle.zIndexFactor, { opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, container.hdr, opacity) : undefined, stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, container.hdr, strokeOpacity) : fill;
247
- transform.a = transform.b = transform.c = transform.d = undefined;
248
- colorStyles.fill = fill;
249
- colorStyles.stroke = stroke;
250
- this.draw((context) => {
251
- for (const plugin of container.plugins) {
252
- if (plugin.drawParticleSetup) {
253
- plugin.drawParticleSetup(context, particle, delta);
254
- }
255
- }
256
- this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
257
- (0, CanvasUtils_js_1.drawParticle)({
258
- container,
259
- context,
260
- particle,
261
- delta,
262
- colorStyles,
263
- radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
264
- opacity: opacity,
265
- transform,
266
- });
267
- this._applyPostDrawUpdaters(particle);
268
- for (const plugin of container.plugins) {
269
- if (plugin.drawParticleCleanup) {
270
- plugin.drawParticleCleanup(context, particle, delta);
271
- }
272
- }
273
- });
274
- }
275
- drawParticlePlugin(plugin, particle, delta) {
276
- this.draw(ctx => {
277
- (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta);
278
- });
279
- }
280
- drawParticles(delta) {
281
- const { particles, plugins } = this.container;
282
- this.clear();
283
- particles.update(delta);
284
- this.draw(ctx => {
285
- for (const plugin of plugins) {
286
- plugin.drawSettingsSetup?.(ctx, delta);
287
- }
288
- for (const plugin of plugins) {
289
- plugin.draw?.(ctx, delta);
290
- }
291
- particles.drawParticles(delta);
292
- for (const plugin of plugins) {
293
- plugin.clearDraw?.(ctx, delta);
294
- }
295
- for (const plugin of plugins) {
296
- plugin.drawSettingsCleanup?.(ctx, delta);
297
- }
298
- });
299
- }
300
- init() {
301
- this._safeMutationObserver(obs => {
302
- obs.disconnect();
303
- });
304
- this._mutationObserver = (0, Utils_js_1.safeMutationObserver)(records => {
305
- for (const record of records) {
306
- if (record.type === "attributes" && record.attributeName === "style") {
307
- this._repairStyle();
308
- }
309
- }
310
- });
311
- this.resize();
312
- this._initStyle();
313
- this.initBackground();
314
- this._safeMutationObserver(obs => {
315
- if (!this.element || !(this.element instanceof Node)) {
316
- return;
317
- }
318
- obs.observe(this.element, { attributes: true });
319
- });
320
- this.initUpdaters();
321
- this.initPlugins();
322
- this.paint();
323
- }
324
- initBackground() {
325
- const { container } = this, options = container.actualOptions, background = options.background, element = this.element;
326
- if (!element) {
327
- return;
328
- }
329
- const elementStyle = element.style, color = (0, ColorUtils_js_1.rangeColorToRgb)(this._engine, background.color);
330
- if (color) {
331
- elementStyle.backgroundColor = (0, ColorUtils_js_1.getStyleFromRgb)(color, container.hdr, background.opacity);
332
- }
333
- else {
334
- elementStyle.backgroundColor = "";
335
- }
336
- elementStyle.backgroundImage = background.image || "";
337
- elementStyle.backgroundPosition = background.position || "";
338
- elementStyle.backgroundRepeat = background.repeat || "";
339
- elementStyle.backgroundSize = background.size || "";
340
- }
341
- initPlugins() {
342
- this._resizePlugins = [];
343
- for (const plugin of this.container.plugins) {
344
- if (plugin.resize) {
345
- this._resizePlugins.push(plugin);
346
- }
347
- if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
348
- this._colorPlugins.push(plugin);
349
- }
350
- }
351
- }
352
- initUpdaters() {
353
- this._preDrawUpdaters = [];
354
- this._postDrawUpdaters = [];
355
- for (const updater of this.container.particles.updaters) {
356
- if (updater.afterDraw) {
357
- this._postDrawUpdaters.push(updater);
358
- }
359
- if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
360
- this._preDrawUpdaters.push(updater);
361
- }
362
- }
363
- }
364
- loadCanvas(canvas) {
365
- if (this._generated && this.element) {
366
- this.element.remove();
367
- }
368
- const container = this.container;
369
- this._generated =
370
- Constants_js_1.generatedAttribute in canvas.dataset ? canvas.dataset[Constants_js_1.generatedAttribute] === "true" : this._generated;
371
- this.element = canvas;
372
- this.element.ariaHidden = "true";
373
- this._originalStyle = (0, Utils_js_1.cloneStyle)(this.element.style);
374
- const standardSize = this._standardSize;
375
- standardSize.height = canvas.offsetHeight;
376
- standardSize.width = canvas.offsetWidth;
377
- const pxRatio = this.container.retina.pixelRatio, retinaSize = this.size;
378
- canvas.height = retinaSize.height = standardSize.height * pxRatio;
379
- canvas.width = retinaSize.width = standardSize.width * pxRatio;
380
- const canSupportHdrQuery = (0, Utils_js_1.safeMatchMedia)("(color-gamut: p3)");
381
- this._context = this.element.getContext("2d", {
382
- alpha: true,
383
- colorSpace: canSupportHdrQuery?.matches && container.hdr ? "display-p3" : "srgb",
384
- desynchronized: true,
385
- willReadFrequently: false,
386
- });
387
- this._safeMutationObserver(obs => {
388
- obs.disconnect();
389
- });
390
- container.retina.init();
391
- this.initBackground();
392
- this._safeMutationObserver(obs => {
393
- if (!this.element || !(this.element instanceof Node)) {
394
- return;
395
- }
396
- obs.observe(this.element, { attributes: true });
397
- });
398
- }
399
- paint() {
400
- let handled = false;
401
- for (const plugin of this.container.plugins) {
402
- if (handled) {
403
- break;
404
- }
405
- handled = plugin.canvasPaint?.() ?? false;
406
- }
407
- if (handled) {
408
- return;
409
- }
410
- this.paintBase();
411
- }
412
- paintBase(baseColor) {
413
- this.draw(ctx => {
414
- (0, CanvasUtils_js_1.paintBase)(ctx, this.size, baseColor);
415
- });
416
- }
417
- paintImage(image, opacity) {
418
- this.draw(ctx => {
419
- (0, CanvasUtils_js_1.paintImage)(ctx, this.size, image, opacity);
420
- });
421
- }
422
- resize() {
423
- if (!this.element) {
424
- return false;
425
- }
426
- const container = this.container, currentSize = container.canvas._standardSize, newSize = {
427
- width: this.element.offsetWidth,
428
- height: this.element.offsetHeight,
429
- }, pxRatio = container.retina.pixelRatio, retinaSize = {
430
- width: newSize.width * pxRatio,
431
- height: newSize.height * pxRatio,
432
- };
433
- if (newSize.height === currentSize.height &&
434
- newSize.width === currentSize.width &&
435
- retinaSize.height === this.element.height &&
436
- retinaSize.width === this.element.width) {
437
- return false;
438
- }
439
- const oldSize = { ...currentSize };
440
- currentSize.height = newSize.height;
441
- currentSize.width = newSize.width;
442
- const canvasSize = this.size;
443
- this.element.width = canvasSize.width = retinaSize.width;
444
- this.element.height = canvasSize.height = retinaSize.height;
445
- if (this.container.started) {
446
- container.particles.setResizeFactor({
447
- width: currentSize.width / oldSize.width,
448
- height: currentSize.height / oldSize.height,
449
- });
450
- }
451
- return true;
452
- }
453
- setPointerEvents(type) {
454
- const element = this.element;
455
- if (!element) {
456
- return;
457
- }
458
- this._pointerEvents = type;
459
- this._repairStyle();
460
- }
461
- stop() {
462
- this._safeMutationObserver(obs => {
463
- obs.disconnect();
464
- });
465
- this._mutationObserver = undefined;
466
- this.draw(ctx => {
467
- (0, CanvasUtils_js_1.clear)(ctx, this.size);
468
- });
469
- }
470
- async windowResize() {
471
- if (!this.element || !this.resize()) {
472
- return;
473
- }
474
- const container = this.container, needsRefresh = container.updateActualOptions();
475
- container.particles.setDensity();
476
- this._applyResizePlugins();
477
- if (needsRefresh) {
478
- await container.refresh();
479
- }
480
- }
481
- }
482
- exports.Canvas = Canvas;
483
- });
@@ -1,20 +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.Point = void 0;
13
- class Point {
14
- constructor(position, particle) {
15
- this.position = position;
16
- this.particle = particle;
17
- }
18
- }
19
- exports.Point = Point;
20
- });
@@ -1,73 +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", "./Ranges.js", "./Constants.js", "../../Utils/MathUtils.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.QuadTree = void 0;
13
- const Ranges_js_1 = require("./Ranges.js");
14
- const Constants_js_1 = require("./Constants.js");
15
- const MathUtils_js_1 = require("../../Utils/MathUtils.js");
16
- class QuadTree {
17
- constructor(rectangle, capacity) {
18
- this.rectangle = rectangle;
19
- this.capacity = capacity;
20
- this._subdivide = () => {
21
- const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
22
- for (let i = 0; i < Constants_js_1.subdivideCount; i++) {
23
- const fixedIndex = i % Constants_js_1.double;
24
- this._subs.push(new QuadTree(new Ranges_js_1.Rectangle(x + width * Constants_js_1.half * fixedIndex, y + height * Constants_js_1.half * (Math.round(i * Constants_js_1.half) - fixedIndex), width * Constants_js_1.half, height * Constants_js_1.half), capacity));
25
- }
26
- this._divided = true;
27
- };
28
- this._points = [];
29
- this._divided = false;
30
- this._subs = [];
31
- }
32
- insert(point) {
33
- if (!this.rectangle.contains(point.position)) {
34
- return false;
35
- }
36
- if (this._points.length < this.capacity) {
37
- this._points.push(point);
38
- return true;
39
- }
40
- if (!this._divided) {
41
- this._subdivide();
42
- }
43
- return this._subs.some(sub => sub.insert(point));
44
- }
45
- query(range, check) {
46
- const res = [];
47
- if (!range.intersects(this.rectangle)) {
48
- return [];
49
- }
50
- for (const p of this._points) {
51
- if (!range.contains(p.position) &&
52
- (0, MathUtils_js_1.getDistance)(range.position, p.position) > p.particle.getRadius() &&
53
- (!check || check(p.particle))) {
54
- continue;
55
- }
56
- res.push(p.particle);
57
- }
58
- if (this._divided) {
59
- for (const sub of this._subs) {
60
- res.push(...sub.query(range, check));
61
- }
62
- }
63
- return res;
64
- }
65
- queryCircle(position, radius, check) {
66
- return this.query(new Ranges_js_1.Circle(position.x, position.y, radius), check);
67
- }
68
- queryRectangle(position, size, check) {
69
- return this.query(new Ranges_js_1.Rectangle(position.x, position.y, size.width, size.height), check);
70
- }
71
- }
72
- exports.QuadTree = QuadTree;
73
- });
@@ -1,47 +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/TypeUtils.js", "../../../../Utils/MathUtils.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MoveAttract = void 0;
13
- const TypeUtils_js_1 = require("../../../../Utils/TypeUtils.js");
14
- const MathUtils_js_1 = require("../../../../Utils/MathUtils.js");
15
- class MoveAttract {
16
- constructor() {
17
- this.distance = 200;
18
- this.enable = false;
19
- this.rotate = {
20
- x: 3000,
21
- y: 3000,
22
- };
23
- }
24
- load(data) {
25
- if ((0, TypeUtils_js_1.isNull)(data)) {
26
- return;
27
- }
28
- if (data.distance !== undefined) {
29
- this.distance = (0, MathUtils_js_1.setRangeValue)(data.distance);
30
- }
31
- if (data.enable !== undefined) {
32
- this.enable = data.enable;
33
- }
34
- if (data.rotate) {
35
- const rotateX = data.rotate.x;
36
- if (rotateX !== undefined) {
37
- this.rotate.x = rotateX;
38
- }
39
- const rotateY = data.rotate.y;
40
- if (rotateY !== undefined) {
41
- this.rotate.y = rotateY;
42
- }
43
- }
44
- }
45
- }
46
- exports.MoveAttract = MoveAttract;
47
- });