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

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 (242) hide show
  1. package/67.min.js +1 -0
  2. package/README.md +53 -965
  3. package/browser/Core/CanvasManager.js +303 -0
  4. package/browser/Core/Container.js +61 -34
  5. package/browser/Core/Engine.js +26 -138
  6. package/browser/Core/Particle.js +29 -28
  7. package/{cjs/Core/Particles.js → browser/Core/ParticlesManager.js} +27 -57
  8. package/browser/Core/RenderManager.js +303 -0
  9. package/browser/Core/Retina.js +3 -8
  10. package/browser/Core/Utils/PluginManager.js +145 -0
  11. package/browser/Options/Classes/Options.js +8 -21
  12. package/browser/Options/Classes/Particles/Paint.js +20 -0
  13. package/browser/Options/Classes/Particles/ParticlesOptions.js +65 -27
  14. package/browser/Options/Interfaces/Particles/IPaint.js +1 -0
  15. package/browser/Types/CanvasContextType.js +1 -0
  16. package/browser/Utils/CanvasUtils.js +4 -4
  17. package/browser/Utils/ColorUtils.js +21 -21
  18. package/browser/Utils/LogUtils.js +1 -0
  19. package/browser/Utils/OptionsUtils.js +2 -2
  20. package/browser/Utils/Utils.js +16 -10
  21. package/browser/exports.js +1 -0
  22. package/cjs/Core/CanvasManager.js +303 -0
  23. package/cjs/Core/Container.js +61 -34
  24. package/cjs/Core/Engine.js +26 -138
  25. package/cjs/Core/Particle.js +29 -28
  26. package/{esm/Core/Particles.js → cjs/Core/ParticlesManager.js} +27 -57
  27. package/cjs/Core/RenderManager.js +303 -0
  28. package/cjs/Core/Retina.js +3 -8
  29. package/cjs/Core/Utils/PluginManager.js +145 -0
  30. package/cjs/Options/Classes/Options.js +8 -21
  31. package/cjs/Options/Classes/Particles/Paint.js +20 -0
  32. package/cjs/Options/Classes/Particles/ParticlesOptions.js +65 -27
  33. package/cjs/Options/Interfaces/Particles/IPaint.js +1 -0
  34. package/cjs/Types/CanvasContextType.js +1 -0
  35. package/cjs/Utils/CanvasUtils.js +4 -4
  36. package/cjs/Utils/ColorUtils.js +21 -21
  37. package/cjs/Utils/LogUtils.js +1 -0
  38. package/cjs/Utils/OptionsUtils.js +2 -2
  39. package/cjs/Utils/Utils.js +16 -10
  40. package/cjs/exports.js +1 -0
  41. package/dist_browser_Core_Container_js.js +24 -14
  42. package/esm/Core/CanvasManager.js +303 -0
  43. package/esm/Core/Container.js +61 -34
  44. package/esm/Core/Engine.js +26 -138
  45. package/esm/Core/Particle.js +29 -28
  46. package/{browser/Core/Particles.js → esm/Core/ParticlesManager.js} +27 -57
  47. package/esm/Core/RenderManager.js +303 -0
  48. package/esm/Core/Retina.js +3 -8
  49. package/esm/Core/Utils/PluginManager.js +145 -0
  50. package/esm/Options/Classes/Options.js +8 -21
  51. package/esm/Options/Classes/Particles/Paint.js +20 -0
  52. package/esm/Options/Classes/Particles/ParticlesOptions.js +65 -27
  53. package/esm/Options/Interfaces/Particles/IPaint.js +1 -0
  54. package/esm/Types/CanvasContextType.js +1 -0
  55. package/esm/Utils/CanvasUtils.js +4 -4
  56. package/esm/Utils/ColorUtils.js +21 -21
  57. package/esm/Utils/LogUtils.js +1 -0
  58. package/esm/Utils/OptionsUtils.js +2 -2
  59. package/esm/Utils/Utils.js +16 -10
  60. package/esm/exports.js +1 -0
  61. package/package.json +2 -3
  62. package/report.html +84 -29
  63. package/tsparticles.engine.js +31 -11
  64. package/tsparticles.engine.min.js +2 -2
  65. package/types/Core/CanvasManager.d.ts +39 -0
  66. package/types/Core/Container.d.ts +26 -7
  67. package/types/Core/Engine.d.ts +2 -54
  68. package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -7
  69. package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
  70. package/types/Core/Interfaces/IPalette.d.ts +15 -2
  71. package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
  72. package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
  73. package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -1
  74. package/types/Core/Particle.d.ts +4 -4
  75. package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +4 -11
  76. package/types/Core/{Canvas.d.ts → RenderManager.d.ts} +12 -33
  77. package/types/Core/Retina.d.ts +0 -2
  78. package/types/Core/Utils/PluginManager.d.ts +62 -0
  79. package/types/Options/Classes/Options.d.ts +3 -3
  80. package/types/Options/Classes/Particles/Paint.d.ts +10 -0
  81. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +7 -7
  82. package/types/Options/Interfaces/Particles/IPaint.d.ts +6 -0
  83. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +3 -4
  84. package/types/Types/CanvasContextType.d.ts +1 -0
  85. package/types/Utils/CanvasUtils.d.ts +8 -5
  86. package/types/Utils/ColorUtils.d.ts +8 -8
  87. package/types/Utils/LogUtils.d.ts +1 -0
  88. package/types/Utils/OptionsUtils.d.ts +2 -2
  89. package/types/export-types.d.ts +5 -2
  90. package/types/exports.d.ts +1 -0
  91. package/164.min.js +0 -1
  92. package/browser/Core/Canvas.js +0 -570
  93. package/cjs/Core/Canvas.js +0 -570
  94. package/esm/Core/Canvas.js +0 -570
  95. package/umd/Core/Canvas.js +0 -584
  96. package/umd/Core/Container.js +0 -356
  97. package/umd/Core/Engine.js +0 -295
  98. package/umd/Core/Interfaces/Colors.js +0 -12
  99. package/umd/Core/Interfaces/IBounds.js +0 -12
  100. package/umd/Core/Interfaces/IBubbleParticleData.js +0 -12
  101. package/umd/Core/Interfaces/ICircleBouncer.js +0 -12
  102. package/umd/Core/Interfaces/IColorManager.js +0 -12
  103. package/umd/Core/Interfaces/IContainerPlugin.js +0 -12
  104. package/umd/Core/Interfaces/ICoordinates.js +0 -12
  105. package/umd/Core/Interfaces/IDelta.js +0 -12
  106. package/umd/Core/Interfaces/IDimension.js +0 -12
  107. package/umd/Core/Interfaces/IDistance.js +0 -12
  108. package/umd/Core/Interfaces/IDrawParticleParams.js +0 -12
  109. package/umd/Core/Interfaces/IEffectDrawer.js +0 -12
  110. package/umd/Core/Interfaces/ILoadParams.js +0 -12
  111. package/umd/Core/Interfaces/IPalette.js +0 -12
  112. package/umd/Core/Interfaces/IParticleColorStyle.js +0 -12
  113. package/umd/Core/Interfaces/IParticleHslAnimation.js +0 -12
  114. package/umd/Core/Interfaces/IParticleLife.js +0 -12
  115. package/umd/Core/Interfaces/IParticleOpacityData.js +0 -12
  116. package/umd/Core/Interfaces/IParticleRetinaProps.js +0 -12
  117. package/umd/Core/Interfaces/IParticleRoll.js +0 -12
  118. package/umd/Core/Interfaces/IParticleRotateData.js +0 -12
  119. package/umd/Core/Interfaces/IParticleTransformValues.js +0 -12
  120. package/umd/Core/Interfaces/IParticleUpdater.js +0 -12
  121. package/umd/Core/Interfaces/IParticleValueAnimation.js +0 -12
  122. package/umd/Core/Interfaces/IPlugin.js +0 -12
  123. package/umd/Core/Interfaces/IPositionFromSizeParams.js +0 -12
  124. package/umd/Core/Interfaces/IRangeValue.js +0 -12
  125. package/umd/Core/Interfaces/IShapeDrawData.js +0 -12
  126. package/umd/Core/Interfaces/IShapeDrawer.js +0 -12
  127. package/umd/Core/Interfaces/IShapeValues.js +0 -12
  128. package/umd/Core/Interfaces/ISlowParticleData.js +0 -12
  129. package/umd/Core/Particle.js +0 -432
  130. package/umd/Core/Particles.js +0 -407
  131. package/umd/Core/Retina.js +0 -52
  132. package/umd/Core/Utils/Constants.js +0 -23
  133. package/umd/Core/Utils/EventListeners.js +0 -102
  134. package/umd/Core/Utils/Ranges.js +0 -91
  135. package/umd/Core/Utils/SpatialHashGrid.js +0 -116
  136. package/umd/Core/Utils/Vectors.js +0 -126
  137. package/umd/Enums/AnimationStatus.js +0 -18
  138. package/umd/Enums/Directions/MoveDirection.js +0 -27
  139. package/umd/Enums/Directions/OutModeDirection.js +0 -20
  140. package/umd/Enums/Directions/RotateDirection.js +0 -19
  141. package/umd/Enums/Modes/AnimationMode.js +0 -20
  142. package/umd/Enums/Modes/LimitMode.js +0 -18
  143. package/umd/Enums/Modes/OutMode.js +0 -21
  144. package/umd/Enums/Modes/PixelMode.js +0 -18
  145. package/umd/Enums/RangeType.js +0 -18
  146. package/umd/Enums/Types/AlterType.js +0 -18
  147. package/umd/Enums/Types/DestroyType.js +0 -19
  148. package/umd/Enums/Types/EasingType.js +0 -58
  149. package/umd/Enums/Types/EventType.js +0 -28
  150. package/umd/Enums/Types/GradientType.js +0 -19
  151. package/umd/Enums/Types/ParticleOutType.js +0 -19
  152. package/umd/Enums/Types/StartValueType.js +0 -19
  153. package/umd/Options/Classes/AnimatableColor.js +0 -52
  154. package/umd/Options/Classes/AnimationOptions.js +0 -79
  155. package/umd/Options/Classes/Background/Background.js +0 -56
  156. package/umd/Options/Classes/ColorAnimation.js +0 -44
  157. package/umd/Options/Classes/FullScreen/FullScreen.js +0 -34
  158. package/umd/Options/Classes/HslAnimation.js +0 -30
  159. package/umd/Options/Classes/Options.js +0 -171
  160. package/umd/Options/Classes/OptionsColor.js +0 -42
  161. package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +0 -31
  162. package/umd/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -21
  163. package/umd/Options/Classes/Particles/Effect/Effect.js +0 -46
  164. package/umd/Options/Classes/Particles/Fill.js +0 -42
  165. package/umd/Options/Classes/Particles/Move/Move.js +0 -120
  166. package/umd/Options/Classes/Particles/Move/MoveAngle.js +0 -35
  167. package/umd/Options/Classes/Particles/Move/MoveCenter.js +0 -45
  168. package/umd/Options/Classes/Particles/Move/MoveGravity.js +0 -45
  169. package/umd/Options/Classes/Particles/Move/OutModes.js +0 -38
  170. package/umd/Options/Classes/Particles/Move/Path/MovePath.js +0 -46
  171. package/umd/Options/Classes/Particles/Move/Spin.js +0 -40
  172. package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +0 -41
  173. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +0 -37
  174. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +0 -35
  175. package/umd/Options/Classes/Particles/Opacity/Opacity.js +0 -35
  176. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -34
  177. package/umd/Options/Classes/Particles/ParticlesOptions.js +0 -116
  178. package/umd/Options/Classes/Particles/Shape/Shape.js +0 -46
  179. package/umd/Options/Classes/Particles/Size/Size.js +0 -35
  180. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +0 -34
  181. package/umd/Options/Classes/Particles/Stroke.js +0 -39
  182. package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +0 -42
  183. package/umd/Options/Classes/ResizeEvent.js +0 -34
  184. package/umd/Options/Classes/ValueWithRandom.js +0 -56
  185. package/umd/Options/Interfaces/Background/IBackground.js +0 -12
  186. package/umd/Options/Interfaces/FullScreen/IFullScreen.js +0 -12
  187. package/umd/Options/Interfaces/IAnimatable.js +0 -12
  188. package/umd/Options/Interfaces/IAnimatableColor.js +0 -12
  189. package/umd/Options/Interfaces/IAnimation.js +0 -12
  190. package/umd/Options/Interfaces/IColorAnimation.js +0 -12
  191. package/umd/Options/Interfaces/IHslAnimation.js +0 -12
  192. package/umd/Options/Interfaces/IOptionLoader.js +0 -12
  193. package/umd/Options/Interfaces/IOptions.js +0 -12
  194. package/umd/Options/Interfaces/IOptionsColor.js +0 -12
  195. package/umd/Options/Interfaces/IResizeEvent.js +0 -12
  196. package/umd/Options/Interfaces/IValueWithRandom.js +0 -12
  197. package/umd/Options/Interfaces/Particles/Bounce/IParticlesBounce.js +0 -12
  198. package/umd/Options/Interfaces/Particles/Effect/IEffect.js +0 -12
  199. package/umd/Options/Interfaces/Particles/IFill.js +0 -12
  200. package/umd/Options/Interfaces/Particles/IParticlesOptions.js +0 -12
  201. package/umd/Options/Interfaces/Particles/IStroke.js +0 -12
  202. package/umd/Options/Interfaces/Particles/Move/IMove.js +0 -12
  203. package/umd/Options/Interfaces/Particles/Move/IMoveAngle.js +0 -12
  204. package/umd/Options/Interfaces/Particles/Move/IMoveCenter.js +0 -12
  205. package/umd/Options/Interfaces/Particles/Move/IMoveGravity.js +0 -12
  206. package/umd/Options/Interfaces/Particles/Move/IOutModes.js +0 -12
  207. package/umd/Options/Interfaces/Particles/Move/ISpin.js +0 -12
  208. package/umd/Options/Interfaces/Particles/Move/Path/IMovePath.js +0 -12
  209. package/umd/Options/Interfaces/Particles/Number/IParticlesDensity.js +0 -12
  210. package/umd/Options/Interfaces/Particles/Number/IParticlesNumber.js +0 -12
  211. package/umd/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +0 -12
  212. package/umd/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -12
  213. package/umd/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -12
  214. package/umd/Options/Interfaces/Particles/Shape/IShape.js +0 -12
  215. package/umd/Options/Interfaces/Particles/Size/ISize.js +0 -12
  216. package/umd/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -12
  217. package/umd/Options/Interfaces/Particles/ZIndex/IZIndex.js +0 -12
  218. package/umd/Types/CustomEventArgs.js +0 -12
  219. package/umd/Types/CustomEventListener.js +0 -12
  220. package/umd/Types/EasingFunction.js +0 -12
  221. package/umd/Types/EngineInitializers.js +0 -12
  222. package/umd/Types/ExportResult.js +0 -12
  223. package/umd/Types/ISourceOptions.js +0 -12
  224. package/umd/Types/ParticlesGroups.js +0 -12
  225. package/umd/Types/PathOptions.js +0 -12
  226. package/umd/Types/RangeValue.js +0 -12
  227. package/umd/Types/RecursivePartial.js +0 -12
  228. package/umd/Types/ShapeData.js +0 -12
  229. package/umd/Types/SingleOrMultiple.js +0 -12
  230. package/umd/Utils/CanvasUtils.js +0 -145
  231. package/umd/Utils/ColorUtils.js +0 -395
  232. package/umd/Utils/EventDispatcher.js +0 -63
  233. package/umd/Utils/LogUtils.js +0 -36
  234. package/umd/Utils/MathUtils.js +0 -203
  235. package/umd/Utils/OptionsUtils.js +0 -25
  236. package/umd/Utils/TypeUtils.js +0 -40
  237. package/umd/Utils/Utils.js +0 -484
  238. package/umd/bundle.js +0 -32
  239. package/umd/export-types.js +0 -12
  240. package/umd/exports.js +0 -82
  241. package/umd/index.js +0 -32
  242. package/umd/initEngine.js +0 -17
@@ -1,584 +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
- container;
55
- element;
56
- size;
57
- zoom = Constants_js_1.defaultZoom;
58
- _canvasClearPlugins;
59
- _canvasPaintPlugins;
60
- _canvasSettings;
61
- _clearDrawPlugins;
62
- _colorPlugins;
63
- _context;
64
- _drawParticlePlugins;
65
- _drawParticlesCleanupPlugins;
66
- _drawParticlesSetupPlugins;
67
- _drawPlugins;
68
- _drawSettingsCleanupPlugins;
69
- _drawSettingsSetupPlugins;
70
- _engine;
71
- _generated;
72
- _mutationObserver;
73
- _originalStyle;
74
- _pointerEvents;
75
- _postDrawUpdaters;
76
- _preDrawUpdaters;
77
- _resizePlugins;
78
- _reusableColorStyles = {};
79
- _reusablePluginColors = [undefined, undefined];
80
- _reusableTransform = {};
81
- _standardSize;
82
- _zoomCenter;
83
- constructor(container, engine) {
84
- this.container = container;
85
- this._engine = engine;
86
- this._standardSize = {
87
- height: 0,
88
- width: 0,
89
- };
90
- const pxRatio = container.retina.pixelRatio, stdSize = this._standardSize;
91
- this.size = {
92
- height: stdSize.height * pxRatio,
93
- width: stdSize.width * pxRatio,
94
- };
95
- this._context = null;
96
- this._generated = false;
97
- this._preDrawUpdaters = [];
98
- this._postDrawUpdaters = [];
99
- this._resizePlugins = [];
100
- this._colorPlugins = [];
101
- this._canvasClearPlugins = [];
102
- this._canvasPaintPlugins = [];
103
- this._clearDrawPlugins = [];
104
- this._drawParticlePlugins = [];
105
- this._drawParticlesCleanupPlugins = [];
106
- this._drawParticlesSetupPlugins = [];
107
- this._drawPlugins = [];
108
- this._drawSettingsSetupPlugins = [];
109
- this._drawSettingsCleanupPlugins = [];
110
- this._pointerEvents = "none";
111
- }
112
- get settings() {
113
- return this._canvasSettings;
114
- }
115
- get _fullScreen() {
116
- return this.container.actualOptions.fullScreen.enable;
117
- }
118
- canvasClear() {
119
- if (!this.container.actualOptions.clear) {
120
- return;
121
- }
122
- this.draw(ctx => {
123
- (0, CanvasUtils_js_1.clear)(ctx, this.size);
124
- });
125
- }
126
- clear() {
127
- let pluginHandled = false;
128
- for (const plugin of this._canvasClearPlugins) {
129
- pluginHandled = plugin.canvasClear?.() ?? false;
130
- if (pluginHandled) {
131
- break;
132
- }
133
- }
134
- if (pluginHandled) {
135
- return;
136
- }
137
- this.canvasClear();
138
- }
139
- destroy() {
140
- this.stop();
141
- if (this._generated) {
142
- const element = this.element;
143
- element?.remove();
144
- this.element = undefined;
145
- }
146
- else {
147
- this._resetOriginalStyle();
148
- }
149
- this._preDrawUpdaters = [];
150
- this._postDrawUpdaters = [];
151
- this._resizePlugins = [];
152
- this._colorPlugins = [];
153
- this._canvasClearPlugins = [];
154
- this._canvasPaintPlugins = [];
155
- this._clearDrawPlugins = [];
156
- this._drawParticlePlugins = [];
157
- this._drawParticlesCleanupPlugins = [];
158
- this._drawParticlesSetupPlugins = [];
159
- this._drawPlugins = [];
160
- this._drawSettingsSetupPlugins = [];
161
- this._drawSettingsCleanupPlugins = [];
162
- }
163
- draw(cb) {
164
- const ctx = this._context;
165
- if (!ctx) {
166
- return;
167
- }
168
- return cb(ctx);
169
- }
170
- drawParticle(particle, delta) {
171
- if (particle.spawning || particle.destroyed) {
172
- return;
173
- }
174
- const radius = particle.getRadius();
175
- if (radius <= Constants_js_1.minimumSize) {
176
- return;
177
- }
178
- const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
179
- let [fColor, sColor] = this._getPluginParticleColors(particle);
180
- fColor ??= pfColor;
181
- sColor ??= psColor;
182
- if (!fColor && !sColor) {
183
- return;
184
- }
185
- const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, container.hdr, strokeOpacity * opacity) : fill;
186
- transform.a = transform.b = transform.c = transform.d = undefined;
187
- colorStyles.fill = fill;
188
- colorStyles.stroke = stroke;
189
- this.draw((context) => {
190
- for (const plugin of this._drawParticlesSetupPlugins) {
191
- plugin.drawParticleSetup?.(context, particle, delta);
192
- }
193
- this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
194
- (0, CanvasUtils_js_1.drawParticle)({
195
- container,
196
- context,
197
- particle,
198
- delta,
199
- colorStyles,
200
- radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
201
- opacity: opacity,
202
- transform,
203
- });
204
- this._applyPostDrawUpdaters(particle);
205
- for (const plugin of this._drawParticlesCleanupPlugins) {
206
- plugin.drawParticleCleanup?.(context, particle, delta);
207
- }
208
- });
209
- }
210
- drawParticlePlugins(particle, delta) {
211
- this.draw(ctx => {
212
- for (const plugin of this._drawParticlePlugins) {
213
- (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta);
214
- }
215
- });
216
- }
217
- drawParticles(delta) {
218
- const { particles } = this.container;
219
- this.clear();
220
- particles.update(delta);
221
- this.draw(ctx => {
222
- for (const plugin of this._drawSettingsSetupPlugins) {
223
- plugin.drawSettingsSetup?.(ctx, delta);
224
- }
225
- for (const plugin of this._drawPlugins) {
226
- plugin.draw?.(ctx, delta);
227
- }
228
- particles.drawParticles(delta);
229
- for (const plugin of this._clearDrawPlugins) {
230
- plugin.clearDraw?.(ctx, delta);
231
- }
232
- for (const plugin of this._drawSettingsCleanupPlugins) {
233
- plugin.drawSettingsCleanup?.(ctx, delta);
234
- }
235
- });
236
- }
237
- getZoomCenter() {
238
- const pxRatio = this.container.retina.pixelRatio, { width, height } = this.size;
239
- if (this._zoomCenter) {
240
- return this._zoomCenter;
241
- }
242
- return {
243
- x: (width * Constants_js_1.half) / pxRatio,
244
- y: (height * Constants_js_1.half) / pxRatio,
245
- };
246
- }
247
- init() {
248
- this._safeMutationObserver(obs => {
249
- obs.disconnect();
250
- });
251
- this._mutationObserver = (0, Utils_js_1.safeMutationObserver)(records => {
252
- for (const record of records) {
253
- if (record.type === "attributes" && record.attributeName === "style") {
254
- this._repairStyle();
255
- }
256
- }
257
- });
258
- this.resize();
259
- this._initStyle();
260
- this.initBackground();
261
- this._safeMutationObserver(obs => {
262
- if (!this.element || !(this.element instanceof Node)) {
263
- return;
264
- }
265
- obs.observe(this.element, { attributes: true });
266
- });
267
- this.initUpdaters();
268
- this.initPlugins();
269
- this.paint();
270
- }
271
- initBackground() {
272
- const { container } = this, options = container.actualOptions, background = options.background, element = this.element;
273
- if (!element) {
274
- return;
275
- }
276
- const elementStyle = element.style, color = (0, ColorUtils_js_1.rangeColorToRgb)(this._engine, background.color);
277
- if (color) {
278
- elementStyle.backgroundColor = (0, ColorUtils_js_1.getStyleFromRgb)(color, container.hdr, background.opacity);
279
- }
280
- else {
281
- elementStyle.backgroundColor = "";
282
- }
283
- elementStyle.backgroundImage = background.image || "";
284
- elementStyle.backgroundPosition = background.position || "";
285
- elementStyle.backgroundRepeat = background.repeat || "";
286
- elementStyle.backgroundSize = background.size || "";
287
- }
288
- initPlugins() {
289
- this._resizePlugins = [];
290
- this._colorPlugins = [];
291
- this._canvasClearPlugins = [];
292
- this._canvasPaintPlugins = [];
293
- this._clearDrawPlugins = [];
294
- this._drawParticlePlugins = [];
295
- this._drawParticlesSetupPlugins = [];
296
- this._drawParticlesCleanupPlugins = [];
297
- this._drawPlugins = [];
298
- this._drawSettingsSetupPlugins = [];
299
- this._drawSettingsCleanupPlugins = [];
300
- for (const plugin of this.container.plugins) {
301
- if (plugin.resize) {
302
- this._resizePlugins.push(plugin);
303
- }
304
- if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
305
- this._colorPlugins.push(plugin);
306
- }
307
- if (plugin.canvasClear) {
308
- this._canvasClearPlugins.push(plugin);
309
- }
310
- if (plugin.canvasPaint) {
311
- this._canvasPaintPlugins.push(plugin);
312
- }
313
- if (plugin.drawParticle) {
314
- this._drawParticlePlugins.push(plugin);
315
- }
316
- if (plugin.drawParticleSetup) {
317
- this._drawParticlesSetupPlugins.push(plugin);
318
- }
319
- if (plugin.drawParticleCleanup) {
320
- this._drawParticlesCleanupPlugins.push(plugin);
321
- }
322
- if (plugin.draw) {
323
- this._drawPlugins.push(plugin);
324
- }
325
- if (plugin.drawSettingsSetup) {
326
- this._drawSettingsSetupPlugins.push(plugin);
327
- }
328
- if (plugin.drawSettingsCleanup) {
329
- this._drawSettingsCleanupPlugins.push(plugin);
330
- }
331
- if (plugin.clearDraw) {
332
- this._clearDrawPlugins.push(plugin);
333
- }
334
- }
335
- }
336
- initUpdaters() {
337
- this._preDrawUpdaters = [];
338
- this._postDrawUpdaters = [];
339
- for (const updater of this.container.particles.updaters) {
340
- if (updater.afterDraw) {
341
- this._postDrawUpdaters.push(updater);
342
- }
343
- if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
344
- this._preDrawUpdaters.push(updater);
345
- }
346
- }
347
- }
348
- loadCanvas(canvas) {
349
- if (this._generated && this.element) {
350
- this.element.remove();
351
- }
352
- const container = this.container;
353
- this._generated =
354
- Constants_js_1.generatedAttribute in canvas.dataset ? canvas.dataset[Constants_js_1.generatedAttribute] === "true" : this._generated;
355
- this.element = canvas;
356
- this.element.ariaHidden = "true";
357
- this._originalStyle = (0, Utils_js_1.cloneStyle)(this.element.style);
358
- const standardSize = this._standardSize;
359
- standardSize.height = canvas.offsetHeight;
360
- standardSize.width = canvas.offsetWidth;
361
- const pxRatio = this.container.retina.pixelRatio, retinaSize = this.size;
362
- canvas.height = retinaSize.height = standardSize.height * pxRatio;
363
- canvas.width = retinaSize.width = standardSize.width * pxRatio;
364
- const canSupportHdrQuery = (0, Utils_js_1.safeMatchMedia)("(color-gamut: p3)");
365
- this._canvasSettings = {
366
- alpha: true,
367
- colorSpace: canSupportHdrQuery?.matches && container.hdr ? "display-p3" : "srgb",
368
- desynchronized: true,
369
- willReadFrequently: false,
370
- };
371
- this._context = this.element.getContext("2d", this._canvasSettings);
372
- if (this._context) {
373
- this._context.globalCompositeOperation = Constants_js_1.defaultCompositeValue;
374
- }
375
- this._safeMutationObserver(obs => {
376
- obs.disconnect();
377
- });
378
- container.retina.init();
379
- this.initBackground();
380
- this._safeMutationObserver(obs => {
381
- if (!this.element || !(this.element instanceof Node)) {
382
- return;
383
- }
384
- obs.observe(this.element, { attributes: true });
385
- });
386
- }
387
- paint() {
388
- let handled = false;
389
- for (const plugin of this._canvasPaintPlugins) {
390
- handled = plugin.canvasPaint?.() ?? false;
391
- if (handled) {
392
- break;
393
- }
394
- }
395
- if (handled) {
396
- return;
397
- }
398
- this.paintBase();
399
- }
400
- paintBase(baseColor) {
401
- this.draw(ctx => {
402
- (0, CanvasUtils_js_1.paintBase)(ctx, this.size, baseColor);
403
- });
404
- }
405
- paintImage(image, opacity) {
406
- this.draw(ctx => {
407
- (0, CanvasUtils_js_1.paintImage)(ctx, this.size, image, opacity);
408
- });
409
- }
410
- resize() {
411
- if (!this.element) {
412
- return false;
413
- }
414
- const container = this.container, currentSize = container.canvas._standardSize, newSize = {
415
- width: this.element.offsetWidth,
416
- height: this.element.offsetHeight,
417
- }, pxRatio = container.retina.pixelRatio, retinaSize = {
418
- width: newSize.width * pxRatio,
419
- height: newSize.height * pxRatio,
420
- };
421
- if (newSize.height === currentSize.height &&
422
- newSize.width === currentSize.width &&
423
- retinaSize.height === this.element.height &&
424
- retinaSize.width === this.element.width) {
425
- return false;
426
- }
427
- const oldSize = { ...currentSize };
428
- currentSize.height = newSize.height;
429
- currentSize.width = newSize.width;
430
- const canvasSize = this.size;
431
- this.element.width = canvasSize.width = retinaSize.width;
432
- this.element.height = canvasSize.height = retinaSize.height;
433
- if (this.container.started) {
434
- container.particles.setResizeFactor({
435
- width: currentSize.width / oldSize.width,
436
- height: currentSize.height / oldSize.height,
437
- });
438
- }
439
- return true;
440
- }
441
- setPointerEvents(type) {
442
- const element = this.element;
443
- if (!element) {
444
- return;
445
- }
446
- this._pointerEvents = type;
447
- this._repairStyle();
448
- }
449
- setZoom(zoomLevel, center) {
450
- this.zoom = zoomLevel;
451
- this._zoomCenter = center;
452
- }
453
- stop() {
454
- this._safeMutationObserver(obs => {
455
- obs.disconnect();
456
- });
457
- this._mutationObserver = undefined;
458
- this.draw(ctx => {
459
- (0, CanvasUtils_js_1.clear)(ctx, this.size);
460
- });
461
- }
462
- async windowResize() {
463
- if (!this.element || !this.resize()) {
464
- return;
465
- }
466
- const container = this.container, needsRefresh = container.updateActualOptions();
467
- container.particles.setDensity();
468
- this._applyResizePlugins();
469
- if (needsRefresh) {
470
- await container.refresh();
471
- }
472
- }
473
- _applyPostDrawUpdaters = particle => {
474
- for (const updater of this._postDrawUpdaters) {
475
- updater.afterDraw?.(particle);
476
- }
477
- };
478
- _applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
479
- for (const updater of this._preDrawUpdaters) {
480
- if (updater.getColorStyles) {
481
- const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
482
- if (fill) {
483
- colorStyles.fill = fill;
484
- }
485
- if (stroke) {
486
- colorStyles.stroke = stroke;
487
- }
488
- }
489
- if (updater.getTransformValues) {
490
- const updaterTransform = updater.getTransformValues(particle);
491
- for (const key in updaterTransform) {
492
- setTransformValue(transform, updaterTransform, key);
493
- }
494
- }
495
- updater.beforeDraw?.(particle);
496
- }
497
- };
498
- _applyResizePlugins = () => {
499
- for (const plugin of this._resizePlugins) {
500
- plugin.resize?.();
501
- }
502
- };
503
- _getPluginParticleColors = particle => {
504
- let fColor, sColor;
505
- for (const plugin of this._colorPlugins) {
506
- if (!fColor && plugin.particleFillColor) {
507
- fColor = (0, ColorUtils_js_1.rangeColorToHsl)(this._engine, plugin.particleFillColor(particle));
508
- }
509
- if (!sColor && plugin.particleStrokeColor) {
510
- sColor = (0, ColorUtils_js_1.rangeColorToHsl)(this._engine, plugin.particleStrokeColor(particle));
511
- }
512
- if (fColor && sColor) {
513
- break;
514
- }
515
- }
516
- this._reusablePluginColors[fColorIndex] = fColor;
517
- this._reusablePluginColors[sColorIndex] = sColor;
518
- return this._reusablePluginColors;
519
- };
520
- _initStyle = () => {
521
- const element = this.element, options = this.container.actualOptions;
522
- if (!element) {
523
- return;
524
- }
525
- if (this._fullScreen) {
526
- this._setFullScreenStyle();
527
- }
528
- else {
529
- this._resetOriginalStyle();
530
- }
531
- for (const key in options.style) {
532
- if (!key || !(key in options.style)) {
533
- continue;
534
- }
535
- const value = options.style[key];
536
- if (!value) {
537
- continue;
538
- }
539
- element.style.setProperty(key, value, "important");
540
- }
541
- };
542
- _repairStyle = () => {
543
- const element = this.element;
544
- if (!element) {
545
- return;
546
- }
547
- this._safeMutationObserver(observer => {
548
- observer.disconnect();
549
- });
550
- this._initStyle();
551
- this.initBackground();
552
- const pointerEvents = this._pointerEvents;
553
- element.style.pointerEvents = pointerEvents;
554
- element.setAttribute("pointer-events", pointerEvents);
555
- this._safeMutationObserver(observer => {
556
- if (!(element instanceof Node)) {
557
- return;
558
- }
559
- observer.observe(element, { attributes: true });
560
- });
561
- };
562
- _resetOriginalStyle = () => {
563
- const element = this.element, originalStyle = this._originalStyle;
564
- if (!element || !originalStyle) {
565
- return;
566
- }
567
- setStyle(element, originalStyle, true);
568
- };
569
- _safeMutationObserver = callback => {
570
- if (!this._mutationObserver) {
571
- return;
572
- }
573
- callback(this._mutationObserver);
574
- };
575
- _setFullScreenStyle = () => {
576
- const element = this.element;
577
- if (!element) {
578
- return;
579
- }
580
- setStyle(element, (0, Utils_js_1.getFullScreenStyle)(this.container.actualOptions.fullScreen.zIndex), true);
581
- };
582
- }
583
- exports.Canvas = Canvas;
584
- });