@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,432 +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/Vectors.js", "../Utils/ColorUtils.js", "../Utils/MathUtils.js", "../Utils/Utils.js", "./Utils/Constants.js", "../Enums/Types/EventType.js", "../Enums/Directions/MoveDirection.js", "../Enums/Modes/OutMode.js", "../Enums/Types/ParticleOutType.js", "../Utils/OptionsUtils.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Particle = void 0;
13
- const Vectors_js_1 = require("./Utils/Vectors.js");
14
- const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
15
- const MathUtils_js_1 = require("../Utils/MathUtils.js");
16
- const Utils_js_1 = require("../Utils/Utils.js");
17
- const Constants_js_1 = require("./Utils/Constants.js");
18
- const EventType_js_1 = require("../Enums/Types/EventType.js");
19
- const MoveDirection_js_1 = require("../Enums/Directions/MoveDirection.js");
20
- const OutMode_js_1 = require("../Enums/Modes/OutMode.js");
21
- const ParticleOutType_js_1 = require("../Enums/Types/ParticleOutType.js");
22
- const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
23
- function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
24
- const effectData = effectOptions.options[effect];
25
- return (0, Utils_js_1.deepExtend)({
26
- close: effectOptions.close,
27
- }, (0, Utils_js_1.itemFromSingleOrMultiple)(effectData, id, reduceDuplicates));
28
- }
29
- function loadShapeData(shape, shapeOptions, id, reduceDuplicates) {
30
- const shapeData = shapeOptions.options[shape];
31
- return (0, Utils_js_1.deepExtend)({
32
- close: shapeOptions.close,
33
- }, (0, Utils_js_1.itemFromSingleOrMultiple)(shapeData, id, reduceDuplicates));
34
- }
35
- function fixOutMode(data) {
36
- if (!(0, Utils_js_1.isInArray)(data.outMode, data.checkModes)) {
37
- return;
38
- }
39
- const diameter = data.radius * Constants_js_1.double;
40
- if (data.coord > data.maxCoord - diameter) {
41
- data.setCb(-data.radius);
42
- }
43
- else if (data.coord < diameter) {
44
- data.setCb(data.radius);
45
- }
46
- }
47
- class Particle {
48
- container;
49
- backColor;
50
- bubble;
51
- destroyed;
52
- direction;
53
- effect;
54
- effectClose;
55
- effectData;
56
- fillColor;
57
- fillEnabled;
58
- fillOpacity;
59
- group;
60
- id;
61
- ignoresResizeRatio;
62
- initialPosition;
63
- initialVelocity;
64
- isRotating;
65
- lastPathTime;
66
- misplaced;
67
- moveCenter;
68
- offset;
69
- opacity;
70
- options;
71
- outType;
72
- pathRotation;
73
- position;
74
- randomIndexData;
75
- retina;
76
- roll;
77
- rotation;
78
- shape;
79
- shapeClose;
80
- shapeData;
81
- sides;
82
- size;
83
- slow;
84
- spawning;
85
- strokeColor;
86
- strokeOpacity;
87
- strokeWidth;
88
- unbreakable;
89
- velocity;
90
- zIndexFactor;
91
- _cachedOpacityData = {
92
- fillOpacity: Constants_js_1.defaultOpacity,
93
- opacity: Constants_js_1.defaultOpacity,
94
- strokeOpacity: Constants_js_1.defaultOpacity,
95
- };
96
- _cachedPosition = Vectors_js_1.Vector3d.origin;
97
- _cachedRotateData = { sin: 0, cos: 0 };
98
- _cachedTransform = {
99
- a: 1,
100
- b: 0,
101
- c: 0,
102
- d: 1,
103
- };
104
- _engine;
105
- constructor(engine, container) {
106
- this.container = container;
107
- this._engine = engine;
108
- }
109
- destroy(override) {
110
- if (this.unbreakable || this.destroyed) {
111
- return;
112
- }
113
- this.destroyed = true;
114
- this.bubble.inRange = false;
115
- this.slow.inRange = false;
116
- const container = this.container, shapeDrawer = this.shape ? container.particles.shapeDrawers.get(this.shape) : undefined;
117
- shapeDrawer?.particleDestroy?.(this);
118
- for (const plugin of container.particleDestroyedPlugins) {
119
- plugin.particleDestroyed?.(this, override);
120
- }
121
- for (const updater of container.particles.updaters) {
122
- updater.particleDestroyed?.(this, override);
123
- }
124
- this._engine.dispatchEvent(EventType_js_1.EventType.particleDestroyed, {
125
- container: this.container,
126
- data: {
127
- particle: this,
128
- },
129
- });
130
- }
131
- draw(delta) {
132
- const container = this.container, canvas = container.canvas;
133
- canvas.drawParticlePlugins(this, delta);
134
- canvas.drawParticle(this, delta);
135
- }
136
- getAngle() {
137
- return this.rotation + (this.pathRotation ? this.velocity.angle : Constants_js_1.defaultAngle);
138
- }
139
- getFillColor() {
140
- return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.fillColor));
141
- }
142
- getMass() {
143
- return this.getRadius() ** Constants_js_1.squareExp * Math.PI * Constants_js_1.half;
144
- }
145
- getOpacity() {
146
- const zIndexOptions = this.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? (0, MathUtils_js_1.getRangeValue)(this.opacity?.value ?? Constants_js_1.defaultOpacity), fillOpacity = this.fillOpacity ?? Constants_js_1.defaultOpacity, strokeOpacity = this.strokeOpacity ?? Constants_js_1.defaultOpacity;
147
- this._cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
148
- this._cachedOpacityData.opacity = opacity * zOpacityFactor;
149
- this._cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
150
- return this._cachedOpacityData;
151
- }
152
- getPosition() {
153
- this._cachedPosition.x = this.position.x + this.offset.x;
154
- this._cachedPosition.y = this.position.y + this.offset.y;
155
- this._cachedPosition.z = this.position.z;
156
- return this._cachedPosition;
157
- }
158
- getRadius() {
159
- return this.bubble.radius ?? this.size.value;
160
- }
161
- getRotateData() {
162
- const angle = this.getAngle();
163
- this._cachedRotateData.sin = Math.sin(angle);
164
- this._cachedRotateData.cos = Math.cos(angle);
165
- return this._cachedRotateData;
166
- }
167
- getStrokeColor() {
168
- return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.strokeColor));
169
- }
170
- getTransformData(externalTransform) {
171
- const rotateData = this.getRotateData(), rotating = this.isRotating;
172
- this._cachedTransform.a = rotateData.cos * (externalTransform.a ?? Constants_js_1.defaultTransform.a);
173
- this._cachedTransform.b = rotating
174
- ? rotateData.sin * (externalTransform.b ?? Constants_js_1.identity)
175
- : (externalTransform.b ?? Constants_js_1.defaultTransform.b);
176
- this._cachedTransform.c = rotating
177
- ? -rotateData.sin * (externalTransform.c ?? Constants_js_1.identity)
178
- : (externalTransform.c ?? Constants_js_1.defaultTransform.c);
179
- this._cachedTransform.d = rotateData.cos * (externalTransform.d ?? Constants_js_1.defaultTransform.d);
180
- return this._cachedTransform;
181
- }
182
- init(id, position, overrideOptions, group) {
183
- const container = this.container;
184
- this.id = id;
185
- this.group = group;
186
- this.effectClose = true;
187
- this.shapeClose = true;
188
- this.pathRotation = false;
189
- this.lastPathTime = 0;
190
- this.destroyed = false;
191
- this.unbreakable = false;
192
- this.isRotating = false;
193
- this.rotation = 0;
194
- this.misplaced = false;
195
- this.retina = {
196
- maxDistance: {},
197
- };
198
- this.outType = ParticleOutType_js_1.ParticleOutType.normal;
199
- this.ignoresResizeRatio = true;
200
- const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._engine, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
201
- this.effect = (0, Utils_js_1.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);
202
- this.shape = (0, Utils_js_1.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);
203
- const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
204
- if (overrideOptions) {
205
- if (overrideOptions.effect?.type) {
206
- const overrideEffectType = overrideOptions.effect.type, effect = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideEffectType, this.id, reduceDuplicates);
207
- if (effect) {
208
- this.effect = effect;
209
- effectOptions.load(overrideOptions.effect);
210
- }
211
- }
212
- if (overrideOptions.shape?.type) {
213
- const overrideShapeType = overrideOptions.shape.type, shape = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideShapeType, this.id, reduceDuplicates);
214
- if (shape) {
215
- this.shape = shape;
216
- shapeOptions.load(overrideOptions.shape);
217
- }
218
- }
219
- }
220
- if (this.effect === Constants_js_1.randomColorValue) {
221
- const availableEffects = [...this.container.particles.effectDrawers.keys()];
222
- this.effect = availableEffects[Math.floor((0, MathUtils_js_1.getRandom)() * availableEffects.length)];
223
- }
224
- if (this.shape === Constants_js_1.randomColorValue) {
225
- const availableShapes = [...this.container.particles.shapeDrawers.keys()];
226
- this.shape = availableShapes[Math.floor((0, MathUtils_js_1.getRandom)() * availableShapes.length)];
227
- }
228
- this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
229
- this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
230
- particlesOptions.load(overrideOptions);
231
- const effectData = this.effectData;
232
- if (effectData) {
233
- particlesOptions.load(effectData.particles);
234
- }
235
- const shapeData = this.shapeData;
236
- if (shapeData) {
237
- particlesOptions.load(shapeData.particles);
238
- }
239
- this.effectClose = effectData?.close ?? particlesOptions.effect.close;
240
- this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
241
- this.options = particlesOptions;
242
- container.retina.initParticle(this);
243
- this.size = (0, Utils_js_1.initParticleNumericAnimationValue)(this.options.size, pxRatio);
244
- this.bubble = {
245
- inRange: false,
246
- };
247
- this.slow = {
248
- inRange: false,
249
- factor: 1,
250
- };
251
- this._initPosition(position);
252
- this.initialVelocity = this._calculateVelocity();
253
- this.velocity = this.initialVelocity.copy();
254
- const particles = container.particles;
255
- particles.setLastZIndex(this.position.z);
256
- this.zIndexFactor = this.position.z / container.zLayers;
257
- this.sides = 24;
258
- let effectDrawer, shapeDrawer;
259
- if (this.effect) {
260
- effectDrawer = container.particles.effectDrawers.get(this.effect);
261
- }
262
- if (effectDrawer?.loadEffect) {
263
- effectDrawer.loadEffect(this);
264
- }
265
- if (this.shape) {
266
- shapeDrawer = container.particles.shapeDrawers.get(this.shape);
267
- }
268
- if (shapeDrawer?.loadShape) {
269
- shapeDrawer.loadShape(this);
270
- }
271
- const sideCountFunc = shapeDrawer?.getSidesCount;
272
- if (sideCountFunc) {
273
- this.sides = sideCountFunc(this);
274
- }
275
- this.spawning = false;
276
- for (const updater of particles.updaters) {
277
- updater.init(this);
278
- }
279
- effectDrawer?.particleInit?.(container, this);
280
- shapeDrawer?.particleInit?.(container, this);
281
- for (const plugin of container.particleCreatedPlugins) {
282
- plugin.particleCreated?.(this);
283
- }
284
- }
285
- isInsideCanvas() {
286
- const radius = this.getRadius(), canvasSize = this.container.canvas.size, position = this.position;
287
- return (position.x >= -radius &&
288
- position.y >= -radius &&
289
- position.y <= canvasSize.height + radius &&
290
- position.x <= canvasSize.width + radius);
291
- }
292
- isShowingBack() {
293
- if (!this.roll) {
294
- return false;
295
- }
296
- const angle = this.roll.angle;
297
- if (this.roll.horizontal && this.roll.vertical) {
298
- const normalizedAngle = angle % Constants_js_1.doublePI, adjustedAngle = normalizedAngle < Constants_js_1.defaultAngle ? normalizedAngle + Constants_js_1.doublePI : normalizedAngle;
299
- return adjustedAngle >= Math.PI * Constants_js_1.half && adjustedAngle < Math.PI * Constants_js_1.triple * Constants_js_1.half;
300
- }
301
- if (this.roll.horizontal) {
302
- const normalizedAngle = (angle + Math.PI * Constants_js_1.half) % (Math.PI * Constants_js_1.double), adjustedAngle = normalizedAngle < Constants_js_1.defaultAngle ? normalizedAngle + Math.PI * Constants_js_1.double : normalizedAngle;
303
- return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * Constants_js_1.double;
304
- }
305
- if (this.roll.vertical) {
306
- const normalizedAngle = angle % (Math.PI * Constants_js_1.double), adjustedAngle = normalizedAngle < Constants_js_1.defaultAngle ? normalizedAngle + Math.PI * Constants_js_1.double : normalizedAngle;
307
- return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * Constants_js_1.double;
308
- }
309
- return false;
310
- }
311
- isVisible() {
312
- return !this.destroyed && !this.spawning && this.isInsideCanvas();
313
- }
314
- reset() {
315
- for (const updater of this.container.particles.updaters) {
316
- updater.reset?.(this);
317
- }
318
- }
319
- _calcPosition = (position, zIndex) => {
320
- let tryCount = Constants_js_1.defaultRetryCount, posVec = position ? Vectors_js_1.Vector3d.create(position.x, position.y, zIndex) : undefined;
321
- const container = this.container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
322
- while (!signal.aborted) {
323
- for (const plugin of plugins) {
324
- const pluginPos = plugin.particlePosition?.(posVec, this);
325
- if (pluginPos) {
326
- return Vectors_js_1.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
327
- }
328
- }
329
- const exactPosition = (0, MathUtils_js_1.calcExactPositionOrRandomFromSize)({
330
- size: canvasSize,
331
- position: posVec,
332
- }), pos = Vectors_js_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
333
- this._fixHorizontal(pos, radius, outModes.left ?? outModes.default);
334
- this._fixHorizontal(pos, radius, outModes.right ?? outModes.default);
335
- this._fixVertical(pos, radius, outModes.top ?? outModes.default);
336
- this._fixVertical(pos, radius, outModes.bottom ?? outModes.default);
337
- let isValidPosition = true;
338
- for (const plugin of container.particles.checkParticlePositionPlugins) {
339
- isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
340
- if (!isValidPosition) {
341
- break;
342
- }
343
- }
344
- if (isValidPosition) {
345
- return pos;
346
- }
347
- tryCount += Constants_js_1.tryCountIncrement;
348
- posVec = undefined;
349
- }
350
- return posVec;
351
- };
352
- _calculateVelocity = () => {
353
- const baseVelocity = (0, MathUtils_js_1.getParticleBaseVelocity)(this.direction), res = baseVelocity.copy(), moveOptions = this.options.move;
354
- if (moveOptions.direction === MoveDirection_js_1.MoveDirection.inside || moveOptions.direction === MoveDirection_js_1.MoveDirection.outside) {
355
- return res;
356
- }
357
- const rad = (0, MathUtils_js_1.degToRad)((0, MathUtils_js_1.getRangeValue)(moveOptions.angle.value)), radOffset = (0, MathUtils_js_1.degToRad)((0, MathUtils_js_1.getRangeValue)(moveOptions.angle.offset)), range = {
358
- left: radOffset - rad * Constants_js_1.half,
359
- right: radOffset + rad * Constants_js_1.half,
360
- };
361
- if (!moveOptions.straight) {
362
- res.angle += (0, MathUtils_js_1.randomInRangeValue)((0, MathUtils_js_1.setRangeValue)(range.left, range.right));
363
- }
364
- if (moveOptions.random && typeof moveOptions.speed === "number") {
365
- res.length *= (0, MathUtils_js_1.getRandom)();
366
- }
367
- return res;
368
- };
369
- _fixHorizontal = (pos, radius, outMode) => {
370
- fixOutMode({
371
- outMode,
372
- checkModes: [OutMode_js_1.OutMode.bounce],
373
- coord: pos.x,
374
- maxCoord: this.container.canvas.size.width,
375
- setCb: (value) => (pos.x += value),
376
- radius,
377
- });
378
- };
379
- _fixVertical = (pos, radius, outMode) => {
380
- fixOutMode({
381
- outMode,
382
- checkModes: [OutMode_js_1.OutMode.bounce],
383
- coord: pos.y,
384
- maxCoord: this.container.canvas.size.height,
385
- setCb: (value) => (pos.y += value),
386
- radius,
387
- });
388
- };
389
- _getRollColor = color => {
390
- if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
391
- return color;
392
- }
393
- if (!this.isShowingBack()) {
394
- return color;
395
- }
396
- if (this.backColor) {
397
- return this.backColor;
398
- }
399
- if (this.roll.alter) {
400
- return (0, ColorUtils_js_1.alterHsl)(color, this.roll.alter.type, this.roll.alter.value);
401
- }
402
- return color;
403
- };
404
- _initPosition = position => {
405
- const container = this.container, zIndexValue = (0, MathUtils_js_1.getRangeValue)(this.options.zIndex.value), initialPosition = this._calcPosition(position, (0, MathUtils_js_1.clamp)(zIndexValue, Constants_js_1.minZ, container.zLayers));
406
- if (!initialPosition) {
407
- throw new Error("a valid position cannot be found for particle");
408
- }
409
- this.position = initialPosition;
410
- this.initialPosition = this.position.copy();
411
- const canvasSize = container.canvas.size;
412
- this.moveCenter = {
413
- ...(0, Utils_js_1.getPosition)(this.options.move.center, canvasSize),
414
- radius: this.options.move.center.radius,
415
- mode: this.options.move.center.mode,
416
- };
417
- this.direction = (0, MathUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
418
- switch (this.options.move.direction) {
419
- case MoveDirection_js_1.MoveDirection.inside:
420
- this.outType = ParticleOutType_js_1.ParticleOutType.inside;
421
- break;
422
- case MoveDirection_js_1.MoveDirection.outside:
423
- this.outType = ParticleOutType_js_1.ParticleOutType.outside;
424
- break;
425
- default:
426
- break;
427
- }
428
- this.offset = Vectors_js_1.Vector.origin;
429
- };
430
- }
431
- exports.Particle = Particle;
432
- });