@tsparticles/engine 4.0.0-beta.1 → 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 (190) hide show
  1. package/67.min.js +1 -0
  2. package/README.md +53 -944
  3. package/browser/Core/Engine.js +1 -1
  4. package/browser/Options/Classes/Options.js +1 -14
  5. package/browser/Options/Classes/Particles/Paint.js +20 -0
  6. package/browser/Options/Classes/Particles/ParticlesOptions.js +60 -22
  7. package/browser/Options/Interfaces/Particles/IPaint.js +1 -0
  8. package/browser/Utils/CanvasUtils.js +3 -3
  9. package/browser/Utils/Utils.js +16 -10
  10. package/browser/exports.js +1 -0
  11. package/cjs/Core/Engine.js +1 -1
  12. package/cjs/Options/Classes/Options.js +1 -14
  13. package/cjs/Options/Classes/Particles/Paint.js +20 -0
  14. package/cjs/Options/Classes/Particles/ParticlesOptions.js +60 -22
  15. package/cjs/Options/Interfaces/Particles/IPaint.js +1 -0
  16. package/cjs/Utils/CanvasUtils.js +3 -3
  17. package/cjs/Utils/Utils.js +16 -10
  18. package/cjs/exports.js +1 -0
  19. package/dist_browser_Core_Container_js.js +1 -1
  20. package/esm/Core/Engine.js +1 -1
  21. package/esm/Options/Classes/Options.js +1 -14
  22. package/esm/Options/Classes/Particles/Paint.js +20 -0
  23. package/esm/Options/Classes/Particles/ParticlesOptions.js +60 -22
  24. package/esm/Options/Interfaces/Particles/IPaint.js +1 -0
  25. package/esm/Utils/CanvasUtils.js +3 -3
  26. package/esm/Utils/Utils.js +16 -10
  27. package/esm/exports.js +1 -0
  28. package/package.json +2 -3
  29. package/report.html +1 -1
  30. package/tsparticles.engine.js +18 -8
  31. package/tsparticles.engine.min.js +2 -2
  32. package/types/Core/Interfaces/IPalette.d.ts +15 -2
  33. package/types/Options/Classes/Particles/Paint.d.ts +10 -0
  34. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +4 -4
  35. package/types/Options/Interfaces/Particles/IPaint.d.ts +6 -0
  36. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +3 -4
  37. package/types/export-types.d.ts +1 -0
  38. package/types/exports.d.ts +1 -0
  39. package/155.min.js +0 -1
  40. package/umd/Core/CanvasManager.js +0 -317
  41. package/umd/Core/Container.js +0 -383
  42. package/umd/Core/Engine.js +0 -183
  43. package/umd/Core/Interfaces/Colors.js +0 -12
  44. package/umd/Core/Interfaces/IBounds.js +0 -12
  45. package/umd/Core/Interfaces/IBubbleParticleData.js +0 -12
  46. package/umd/Core/Interfaces/ICircleBouncer.js +0 -12
  47. package/umd/Core/Interfaces/IColorManager.js +0 -12
  48. package/umd/Core/Interfaces/IContainerPlugin.js +0 -12
  49. package/umd/Core/Interfaces/ICoordinates.js +0 -12
  50. package/umd/Core/Interfaces/IDelta.js +0 -12
  51. package/umd/Core/Interfaces/IDimension.js +0 -12
  52. package/umd/Core/Interfaces/IDistance.js +0 -12
  53. package/umd/Core/Interfaces/IDrawParticleParams.js +0 -12
  54. package/umd/Core/Interfaces/IEffectDrawer.js +0 -12
  55. package/umd/Core/Interfaces/ILoadParams.js +0 -12
  56. package/umd/Core/Interfaces/IPalette.js +0 -12
  57. package/umd/Core/Interfaces/IParticleColorStyle.js +0 -12
  58. package/umd/Core/Interfaces/IParticleHslAnimation.js +0 -12
  59. package/umd/Core/Interfaces/IParticleLife.js +0 -12
  60. package/umd/Core/Interfaces/IParticleOpacityData.js +0 -12
  61. package/umd/Core/Interfaces/IParticleRetinaProps.js +0 -12
  62. package/umd/Core/Interfaces/IParticleRoll.js +0 -12
  63. package/umd/Core/Interfaces/IParticleRotateData.js +0 -12
  64. package/umd/Core/Interfaces/IParticleTransformValues.js +0 -12
  65. package/umd/Core/Interfaces/IParticleUpdater.js +0 -12
  66. package/umd/Core/Interfaces/IParticleValueAnimation.js +0 -12
  67. package/umd/Core/Interfaces/IPlugin.js +0 -12
  68. package/umd/Core/Interfaces/IPositionFromSizeParams.js +0 -12
  69. package/umd/Core/Interfaces/IRangeValue.js +0 -12
  70. package/umd/Core/Interfaces/IShapeDrawData.js +0 -12
  71. package/umd/Core/Interfaces/IShapeDrawer.js +0 -12
  72. package/umd/Core/Interfaces/IShapeValues.js +0 -12
  73. package/umd/Core/Interfaces/ISlowParticleData.js +0 -12
  74. package/umd/Core/Particle.js +0 -433
  75. package/umd/Core/ParticlesManager.js +0 -377
  76. package/umd/Core/RenderManager.js +0 -317
  77. package/umd/Core/Retina.js +0 -47
  78. package/umd/Core/Utils/Constants.js +0 -23
  79. package/umd/Core/Utils/EventListeners.js +0 -102
  80. package/umd/Core/Utils/PluginManager.js +0 -159
  81. package/umd/Core/Utils/Ranges.js +0 -91
  82. package/umd/Core/Utils/SpatialHashGrid.js +0 -116
  83. package/umd/Core/Utils/Vectors.js +0 -126
  84. package/umd/Enums/AnimationStatus.js +0 -18
  85. package/umd/Enums/Directions/MoveDirection.js +0 -27
  86. package/umd/Enums/Directions/OutModeDirection.js +0 -20
  87. package/umd/Enums/Directions/RotateDirection.js +0 -19
  88. package/umd/Enums/Modes/AnimationMode.js +0 -20
  89. package/umd/Enums/Modes/LimitMode.js +0 -18
  90. package/umd/Enums/Modes/OutMode.js +0 -21
  91. package/umd/Enums/Modes/PixelMode.js +0 -18
  92. package/umd/Enums/RangeType.js +0 -18
  93. package/umd/Enums/Types/AlterType.js +0 -18
  94. package/umd/Enums/Types/DestroyType.js +0 -19
  95. package/umd/Enums/Types/EasingType.js +0 -58
  96. package/umd/Enums/Types/EventType.js +0 -28
  97. package/umd/Enums/Types/GradientType.js +0 -19
  98. package/umd/Enums/Types/ParticleOutType.js +0 -19
  99. package/umd/Enums/Types/StartValueType.js +0 -19
  100. package/umd/Options/Classes/AnimatableColor.js +0 -52
  101. package/umd/Options/Classes/AnimationOptions.js +0 -79
  102. package/umd/Options/Classes/Background/Background.js +0 -56
  103. package/umd/Options/Classes/ColorAnimation.js +0 -44
  104. package/umd/Options/Classes/FullScreen/FullScreen.js +0 -34
  105. package/umd/Options/Classes/HslAnimation.js +0 -30
  106. package/umd/Options/Classes/Options.js +0 -171
  107. package/umd/Options/Classes/OptionsColor.js +0 -42
  108. package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +0 -31
  109. package/umd/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -21
  110. package/umd/Options/Classes/Particles/Effect/Effect.js +0 -46
  111. package/umd/Options/Classes/Particles/Fill.js +0 -42
  112. package/umd/Options/Classes/Particles/Move/Move.js +0 -120
  113. package/umd/Options/Classes/Particles/Move/MoveAngle.js +0 -35
  114. package/umd/Options/Classes/Particles/Move/MoveCenter.js +0 -45
  115. package/umd/Options/Classes/Particles/Move/MoveGravity.js +0 -45
  116. package/umd/Options/Classes/Particles/Move/OutModes.js +0 -38
  117. package/umd/Options/Classes/Particles/Move/Path/MovePath.js +0 -46
  118. package/umd/Options/Classes/Particles/Move/Spin.js +0 -40
  119. package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +0 -41
  120. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +0 -37
  121. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +0 -35
  122. package/umd/Options/Classes/Particles/Opacity/Opacity.js +0 -35
  123. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -34
  124. package/umd/Options/Classes/Particles/ParticlesOptions.js +0 -116
  125. package/umd/Options/Classes/Particles/Shape/Shape.js +0 -46
  126. package/umd/Options/Classes/Particles/Size/Size.js +0 -35
  127. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +0 -34
  128. package/umd/Options/Classes/Particles/Stroke.js +0 -39
  129. package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +0 -42
  130. package/umd/Options/Classes/ResizeEvent.js +0 -34
  131. package/umd/Options/Classes/ValueWithRandom.js +0 -56
  132. package/umd/Options/Interfaces/Background/IBackground.js +0 -12
  133. package/umd/Options/Interfaces/FullScreen/IFullScreen.js +0 -12
  134. package/umd/Options/Interfaces/IAnimatable.js +0 -12
  135. package/umd/Options/Interfaces/IAnimatableColor.js +0 -12
  136. package/umd/Options/Interfaces/IAnimation.js +0 -12
  137. package/umd/Options/Interfaces/IColorAnimation.js +0 -12
  138. package/umd/Options/Interfaces/IHslAnimation.js +0 -12
  139. package/umd/Options/Interfaces/IOptionLoader.js +0 -12
  140. package/umd/Options/Interfaces/IOptions.js +0 -12
  141. package/umd/Options/Interfaces/IOptionsColor.js +0 -12
  142. package/umd/Options/Interfaces/IResizeEvent.js +0 -12
  143. package/umd/Options/Interfaces/IValueWithRandom.js +0 -12
  144. package/umd/Options/Interfaces/Particles/Bounce/IParticlesBounce.js +0 -12
  145. package/umd/Options/Interfaces/Particles/Effect/IEffect.js +0 -12
  146. package/umd/Options/Interfaces/Particles/IFill.js +0 -12
  147. package/umd/Options/Interfaces/Particles/IParticlesOptions.js +0 -12
  148. package/umd/Options/Interfaces/Particles/IStroke.js +0 -12
  149. package/umd/Options/Interfaces/Particles/Move/IMove.js +0 -12
  150. package/umd/Options/Interfaces/Particles/Move/IMoveAngle.js +0 -12
  151. package/umd/Options/Interfaces/Particles/Move/IMoveCenter.js +0 -12
  152. package/umd/Options/Interfaces/Particles/Move/IMoveGravity.js +0 -12
  153. package/umd/Options/Interfaces/Particles/Move/IOutModes.js +0 -12
  154. package/umd/Options/Interfaces/Particles/Move/ISpin.js +0 -12
  155. package/umd/Options/Interfaces/Particles/Move/Path/IMovePath.js +0 -12
  156. package/umd/Options/Interfaces/Particles/Number/IParticlesDensity.js +0 -12
  157. package/umd/Options/Interfaces/Particles/Number/IParticlesNumber.js +0 -12
  158. package/umd/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +0 -12
  159. package/umd/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -12
  160. package/umd/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -12
  161. package/umd/Options/Interfaces/Particles/Shape/IShape.js +0 -12
  162. package/umd/Options/Interfaces/Particles/Size/ISize.js +0 -12
  163. package/umd/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -12
  164. package/umd/Options/Interfaces/Particles/ZIndex/IZIndex.js +0 -12
  165. package/umd/Types/CanvasContextType.js +0 -12
  166. package/umd/Types/CustomEventArgs.js +0 -12
  167. package/umd/Types/CustomEventListener.js +0 -12
  168. package/umd/Types/EasingFunction.js +0 -12
  169. package/umd/Types/EngineInitializers.js +0 -12
  170. package/umd/Types/ExportResult.js +0 -12
  171. package/umd/Types/ISourceOptions.js +0 -12
  172. package/umd/Types/ParticlesGroups.js +0 -12
  173. package/umd/Types/PathOptions.js +0 -12
  174. package/umd/Types/RangeValue.js +0 -12
  175. package/umd/Types/RecursivePartial.js +0 -12
  176. package/umd/Types/ShapeData.js +0 -12
  177. package/umd/Types/SingleOrMultiple.js +0 -12
  178. package/umd/Utils/CanvasUtils.js +0 -145
  179. package/umd/Utils/ColorUtils.js +0 -395
  180. package/umd/Utils/EventDispatcher.js +0 -63
  181. package/umd/Utils/LogUtils.js +0 -37
  182. package/umd/Utils/MathUtils.js +0 -203
  183. package/umd/Utils/OptionsUtils.js +0 -25
  184. package/umd/Utils/TypeUtils.js +0 -40
  185. package/umd/Utils/Utils.js +0 -484
  186. package/umd/bundle.js +0 -32
  187. package/umd/export-types.js +0 -12
  188. package/umd/exports.js +0 -82
  189. package/umd/index.js +0 -32
  190. package/umd/initEngine.js +0 -17
@@ -1,433 +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
- backColor;
49
- bubble;
50
- destroyed;
51
- direction;
52
- effect;
53
- effectClose;
54
- effectData;
55
- fillColor;
56
- fillEnabled;
57
- fillOpacity;
58
- group;
59
- id;
60
- ignoresResizeRatio;
61
- initialPosition;
62
- initialVelocity;
63
- isRotating;
64
- lastPathTime;
65
- misplaced;
66
- moveCenter;
67
- offset;
68
- opacity;
69
- options;
70
- outType;
71
- pathRotation;
72
- position;
73
- randomIndexData;
74
- retina;
75
- roll;
76
- rotation;
77
- shape;
78
- shapeClose;
79
- shapeData;
80
- sides;
81
- size;
82
- slow;
83
- spawning;
84
- strokeColor;
85
- strokeOpacity;
86
- strokeWidth;
87
- unbreakable;
88
- velocity;
89
- zIndexFactor;
90
- _cachedOpacityData = {
91
- fillOpacity: Constants_js_1.defaultOpacity,
92
- opacity: Constants_js_1.defaultOpacity,
93
- strokeOpacity: Constants_js_1.defaultOpacity,
94
- };
95
- _cachedPosition = Vectors_js_1.Vector3d.origin;
96
- _cachedRotateData = { sin: 0, cos: 0 };
97
- _cachedTransform = {
98
- a: 1,
99
- b: 0,
100
- c: 0,
101
- d: 1,
102
- };
103
- _container;
104
- _pluginManager;
105
- constructor(pluginManager, container) {
106
- this._pluginManager = pluginManager;
107
- this._container = container;
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.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.particleUpdaters) {
122
- updater.particleDestroyed?.(this, override);
123
- }
124
- this._container.dispatchEvent(EventType_js_1.EventType.particleDestroyed, {
125
- particle: this,
126
- });
127
- }
128
- draw(delta) {
129
- const container = this._container, render = container.canvas.render;
130
- render.drawParticlePlugins(this, delta);
131
- render.drawParticle(this, delta);
132
- }
133
- getAngle() {
134
- return this.rotation + (this.pathRotation ? this.velocity.angle : Constants_js_1.defaultAngle);
135
- }
136
- getFillColor() {
137
- return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.fillColor));
138
- }
139
- getMass() {
140
- return this.getRadius() ** Constants_js_1.squareExp * Math.PI * Constants_js_1.half;
141
- }
142
- getOpacity() {
143
- 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;
144
- this._cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
145
- this._cachedOpacityData.opacity = opacity * zOpacityFactor;
146
- this._cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
147
- return this._cachedOpacityData;
148
- }
149
- getPosition() {
150
- this._cachedPosition.x = this.position.x + this.offset.x;
151
- this._cachedPosition.y = this.position.y + this.offset.y;
152
- this._cachedPosition.z = this.position.z;
153
- return this._cachedPosition;
154
- }
155
- getRadius() {
156
- return this.bubble.radius ?? this.size.value;
157
- }
158
- getRotateData() {
159
- const angle = this.getAngle();
160
- this._cachedRotateData.sin = Math.sin(angle);
161
- this._cachedRotateData.cos = Math.cos(angle);
162
- return this._cachedRotateData;
163
- }
164
- getStrokeColor() {
165
- return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.strokeColor));
166
- }
167
- getTransformData(externalTransform) {
168
- const rotateData = this.getRotateData(), rotating = this.isRotating;
169
- this._cachedTransform.a = rotateData.cos * (externalTransform.a ?? Constants_js_1.defaultTransform.a);
170
- this._cachedTransform.b = rotating
171
- ? rotateData.sin * (externalTransform.b ?? Constants_js_1.identity)
172
- : (externalTransform.b ?? Constants_js_1.defaultTransform.b);
173
- this._cachedTransform.c = rotating
174
- ? -rotateData.sin * (externalTransform.c ?? Constants_js_1.identity)
175
- : (externalTransform.c ?? Constants_js_1.defaultTransform.c);
176
- this._cachedTransform.d = rotateData.cos * (externalTransform.d ?? Constants_js_1.defaultTransform.d);
177
- return this._cachedTransform;
178
- }
179
- init(id, position, overrideOptions, group) {
180
- const container = this._container;
181
- this.id = id;
182
- this.group = group;
183
- this.effectClose = true;
184
- this.shapeClose = true;
185
- this.pathRotation = false;
186
- this.lastPathTime = 0;
187
- this.destroyed = false;
188
- this.unbreakable = false;
189
- this.isRotating = false;
190
- this.rotation = 0;
191
- this.misplaced = false;
192
- this.retina = {
193
- maxDistance: {},
194
- maxSpeed: 0,
195
- moveDrift: 0,
196
- moveSpeed: 0,
197
- sizeAnimationSpeed: 0,
198
- };
199
- this.outType = ParticleOutType_js_1.ParticleOutType.normal;
200
- this.ignoresResizeRatio = true;
201
- const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
202
- this.effect = (0, Utils_js_1.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);
203
- this.shape = (0, Utils_js_1.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);
204
- const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
205
- if (overrideOptions) {
206
- if (overrideOptions.effect?.type) {
207
- const overrideEffectType = overrideOptions.effect.type, effect = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideEffectType, this.id, reduceDuplicates);
208
- if (effect) {
209
- this.effect = effect;
210
- effectOptions.load(overrideOptions.effect);
211
- }
212
- }
213
- if (overrideOptions.shape?.type) {
214
- const overrideShapeType = overrideOptions.shape.type, shape = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideShapeType, this.id, reduceDuplicates);
215
- if (shape) {
216
- this.shape = shape;
217
- shapeOptions.load(overrideOptions.shape);
218
- }
219
- }
220
- }
221
- if (this.effect === Constants_js_1.randomColorValue) {
222
- const availableEffects = [...this._container.effectDrawers.keys()];
223
- this.effect = availableEffects[Math.floor((0, MathUtils_js_1.getRandom)() * availableEffects.length)];
224
- }
225
- if (this.shape === Constants_js_1.randomColorValue) {
226
- const availableShapes = [...this._container.shapeDrawers.keys()];
227
- this.shape = availableShapes[Math.floor((0, MathUtils_js_1.getRandom)() * availableShapes.length)];
228
- }
229
- this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
230
- this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
231
- particlesOptions.load(overrideOptions);
232
- const effectData = this.effectData;
233
- if (effectData) {
234
- particlesOptions.load(effectData.particles);
235
- }
236
- const shapeData = this.shapeData;
237
- if (shapeData) {
238
- particlesOptions.load(shapeData.particles);
239
- }
240
- this.effectClose = effectData?.close ?? particlesOptions.effect.close;
241
- this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
242
- this.options = particlesOptions;
243
- container.retina.initParticle(this);
244
- this.size = (0, Utils_js_1.initParticleNumericAnimationValue)(this.options.size, pxRatio);
245
- this.bubble = {
246
- inRange: false,
247
- };
248
- this.slow = {
249
- inRange: false,
250
- factor: 1,
251
- };
252
- this._initPosition(position);
253
- this.initialVelocity = this._calculateVelocity();
254
- this.velocity = this.initialVelocity.copy();
255
- const particles = container.particles;
256
- particles.setLastZIndex(this.position.z);
257
- this.zIndexFactor = this.position.z / container.zLayers;
258
- this.sides = 24;
259
- let effectDrawer, shapeDrawer;
260
- if (this.effect) {
261
- effectDrawer = container.effectDrawers.get(this.effect);
262
- }
263
- if (effectDrawer?.loadEffect) {
264
- effectDrawer.loadEffect(this);
265
- }
266
- if (this.shape) {
267
- shapeDrawer = container.shapeDrawers.get(this.shape);
268
- }
269
- if (shapeDrawer?.loadShape) {
270
- shapeDrawer.loadShape(this);
271
- }
272
- const sideCountFunc = shapeDrawer?.getSidesCount;
273
- if (sideCountFunc) {
274
- this.sides = sideCountFunc(this);
275
- }
276
- this.spawning = false;
277
- for (const updater of container.particleUpdaters) {
278
- updater.init(this);
279
- }
280
- effectDrawer?.particleInit?.(container, this);
281
- shapeDrawer?.particleInit?.(container, this);
282
- for (const plugin of container.particleCreatedPlugins) {
283
- plugin.particleCreated?.(this);
284
- }
285
- }
286
- isInsideCanvas() {
287
- const radius = this.getRadius(), canvasSize = this._container.canvas.size, position = this.position;
288
- return (position.x >= -radius &&
289
- position.y >= -radius &&
290
- position.y <= canvasSize.height + radius &&
291
- position.x <= canvasSize.width + radius);
292
- }
293
- isShowingBack() {
294
- if (!this.roll) {
295
- return false;
296
- }
297
- const angle = this.roll.angle;
298
- if (this.roll.horizontal && this.roll.vertical) {
299
- const normalizedAngle = angle % Constants_js_1.doublePI, adjustedAngle = normalizedAngle < Constants_js_1.defaultAngle ? normalizedAngle + Constants_js_1.doublePI : normalizedAngle;
300
- return adjustedAngle >= Math.PI * Constants_js_1.half && adjustedAngle < Math.PI * Constants_js_1.triple * Constants_js_1.half;
301
- }
302
- if (this.roll.horizontal) {
303
- 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;
304
- return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * Constants_js_1.double;
305
- }
306
- if (this.roll.vertical) {
307
- const normalizedAngle = angle % (Math.PI * Constants_js_1.double), adjustedAngle = normalizedAngle < Constants_js_1.defaultAngle ? normalizedAngle + Math.PI * Constants_js_1.double : normalizedAngle;
308
- return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * Constants_js_1.double;
309
- }
310
- return false;
311
- }
312
- isVisible() {
313
- return !this.destroyed && !this.spawning && this.isInsideCanvas();
314
- }
315
- reset() {
316
- for (const updater of this._container.particleUpdaters) {
317
- updater.reset?.(this);
318
- }
319
- }
320
- _calcPosition = (position, zIndex) => {
321
- let tryCount = Constants_js_1.defaultRetryCount, posVec = position ? Vectors_js_1.Vector3d.create(position.x, position.y, zIndex) : undefined;
322
- const container = this._container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
323
- while (!signal.aborted) {
324
- for (const plugin of plugins) {
325
- const pluginPos = plugin.particlePosition?.(posVec, this);
326
- if (pluginPos) {
327
- return Vectors_js_1.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
328
- }
329
- }
330
- const exactPosition = (0, MathUtils_js_1.calcExactPositionOrRandomFromSize)({
331
- size: canvasSize,
332
- position: posVec,
333
- }), pos = Vectors_js_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
334
- this._fixHorizontal(pos, radius, outModes.left ?? outModes.default);
335
- this._fixHorizontal(pos, radius, outModes.right ?? outModes.default);
336
- this._fixVertical(pos, radius, outModes.top ?? outModes.default);
337
- this._fixVertical(pos, radius, outModes.bottom ?? outModes.default);
338
- let isValidPosition = true;
339
- for (const plugin of container.particles.checkParticlePositionPlugins) {
340
- isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
341
- if (!isValidPosition) {
342
- break;
343
- }
344
- }
345
- if (isValidPosition) {
346
- return pos;
347
- }
348
- tryCount += Constants_js_1.tryCountIncrement;
349
- posVec = undefined;
350
- }
351
- return posVec;
352
- };
353
- _calculateVelocity = () => {
354
- const baseVelocity = (0, MathUtils_js_1.getParticleBaseVelocity)(this.direction), res = baseVelocity.copy(), moveOptions = this.options.move;
355
- if (moveOptions.direction === MoveDirection_js_1.MoveDirection.inside || moveOptions.direction === MoveDirection_js_1.MoveDirection.outside) {
356
- return res;
357
- }
358
- 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 = {
359
- left: radOffset - rad * Constants_js_1.half,
360
- right: radOffset + rad * Constants_js_1.half,
361
- };
362
- if (!moveOptions.straight) {
363
- res.angle += (0, MathUtils_js_1.randomInRangeValue)((0, MathUtils_js_1.setRangeValue)(range.left, range.right));
364
- }
365
- if (moveOptions.random && typeof moveOptions.speed === "number") {
366
- res.length *= (0, MathUtils_js_1.getRandom)();
367
- }
368
- return res;
369
- };
370
- _fixHorizontal = (pos, radius, outMode) => {
371
- fixOutMode({
372
- outMode,
373
- checkModes: [OutMode_js_1.OutMode.bounce],
374
- coord: pos.x,
375
- maxCoord: this._container.canvas.size.width,
376
- setCb: (value) => (pos.x += value),
377
- radius,
378
- });
379
- };
380
- _fixVertical = (pos, radius, outMode) => {
381
- fixOutMode({
382
- outMode,
383
- checkModes: [OutMode_js_1.OutMode.bounce],
384
- coord: pos.y,
385
- maxCoord: this._container.canvas.size.height,
386
- setCb: (value) => (pos.y += value),
387
- radius,
388
- });
389
- };
390
- _getRollColor = color => {
391
- if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
392
- return color;
393
- }
394
- if (!this.isShowingBack()) {
395
- return color;
396
- }
397
- if (this.backColor) {
398
- return this.backColor;
399
- }
400
- if (this.roll.alter) {
401
- return (0, ColorUtils_js_1.alterHsl)(color, this.roll.alter.type, this.roll.alter.value);
402
- }
403
- return color;
404
- };
405
- _initPosition = position => {
406
- 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));
407
- if (!initialPosition) {
408
- throw new Error("a valid position cannot be found for particle");
409
- }
410
- this.position = initialPosition;
411
- this.initialPosition = this.position.copy();
412
- const canvasSize = container.canvas.size;
413
- this.moveCenter = {
414
- ...(0, Utils_js_1.getPosition)(this.options.move.center, canvasSize),
415
- radius: this.options.move.center.radius,
416
- mode: this.options.move.center.mode,
417
- };
418
- this.direction = (0, MathUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
419
- switch (this.options.move.direction) {
420
- case MoveDirection_js_1.MoveDirection.inside:
421
- this.outType = ParticleOutType_js_1.ParticleOutType.inside;
422
- break;
423
- case MoveDirection_js_1.MoveDirection.outside:
424
- this.outType = ParticleOutType_js_1.ParticleOutType.outside;
425
- break;
426
- default:
427
- break;
428
- }
429
- this.offset = Vectors_js_1.Vector.origin;
430
- };
431
- }
432
- exports.Particle = Particle;
433
- });