@tsparticles/engine 4.0.0-alpha.4 → 4.0.0-alpha.8
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.
- package/794.min.js +1 -1
- package/794.min.js.LICENSE.txt +1 -1
- package/browser/Core/Canvas.js +25 -19
- package/browser/Core/Engine.js +32 -39
- package/browser/Core/Particle.js +22 -6
- package/browser/Core/Utils/Constants.js +1 -1
- package/browser/Enums/Types/EasingType.js +18 -3
- package/browser/Utils/CanvasUtils.js +0 -12
- package/browser/Utils/Utils.js +8 -4
- package/cjs/Core/Canvas.js +25 -19
- package/cjs/Core/Engine.js +32 -39
- package/cjs/Core/Particle.js +22 -6
- package/cjs/Core/Utils/Constants.js +1 -1
- package/cjs/Enums/Types/EasingType.js +18 -3
- package/cjs/Utils/CanvasUtils.js +0 -12
- package/cjs/Utils/Utils.js +8 -4
- package/dist_browser_Core_Container_js.js +3 -3
- package/esm/Core/Canvas.js +25 -19
- package/esm/Core/Engine.js +32 -39
- package/esm/Core/Particle.js +22 -6
- package/esm/Core/Utils/Constants.js +1 -1
- package/esm/Enums/Types/EasingType.js +18 -3
- package/esm/Utils/CanvasUtils.js +0 -12
- package/esm/Utils/Utils.js +8 -4
- package/package.json +1 -1
- package/report.html +3 -3
- package/tsparticles.engine.js +8 -8
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +0 -2
- package/types/Core/Engine.d.ts +5 -1
- package/types/Core/Interfaces/IContainerPlugin.d.ts +4 -0
- package/types/Core/Particle.d.ts +1 -0
- package/types/Core/Utils/Constants.d.ts +1 -1
- package/types/Enums/Types/EasingType.d.ts +20 -5
- package/types/Utils/CanvasUtils.d.ts +0 -2
- package/umd/Core/Canvas.js +24 -18
- package/umd/Core/Engine.js +32 -39
- package/umd/Core/Particle.js +21 -5
- package/umd/Core/Utils/Constants.js +2 -2
- package/umd/Enums/Types/EasingType.js +18 -3
- package/umd/Utils/CanvasUtils.js +0 -14
- package/umd/Utils/Utils.js +8 -4
package/cjs/Core/Engine.js
CHANGED
|
@@ -57,7 +57,10 @@ export class Engine {
|
|
|
57
57
|
this._domArray = [];
|
|
58
58
|
this._eventDispatcher = new EventDispatcher();
|
|
59
59
|
this._initialized = false;
|
|
60
|
+
this._isRunningLoaders = false;
|
|
60
61
|
this._loadPromises = new Set();
|
|
62
|
+
this._allLoadersSet = new Set();
|
|
63
|
+
this._executedSet = new Set();
|
|
61
64
|
this.plugins = [];
|
|
62
65
|
this.colorManagers = new Map();
|
|
63
66
|
this.easingFunctions = new Map();
|
|
@@ -83,7 +86,7 @@ export class Engine {
|
|
|
83
86
|
return this._domArray;
|
|
84
87
|
}
|
|
85
88
|
get version() {
|
|
86
|
-
return "4.0.0-alpha.
|
|
89
|
+
return "4.0.0-alpha.8";
|
|
87
90
|
}
|
|
88
91
|
addColorManager(manager) {
|
|
89
92
|
this.colorManagers.set(manager.key, manager);
|
|
@@ -184,40 +187,21 @@ export class Engine {
|
|
|
184
187
|
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
185
188
|
}
|
|
186
189
|
async init() {
|
|
187
|
-
if (this._initialized)
|
|
190
|
+
if (this._initialized || this._isRunningLoaders)
|
|
188
191
|
return;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
if (executed.has(loader)) {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
executed.add(loader);
|
|
200
|
-
const inner = [], origRegister = this.register.bind(this);
|
|
201
|
-
this.register = (...loaders) => {
|
|
202
|
-
inner.push(...loaders);
|
|
203
|
-
for (const loader of loaders) {
|
|
204
|
-
allLoaders.add(loader);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
try {
|
|
208
|
-
await loader(this);
|
|
192
|
+
this._isRunningLoaders = true;
|
|
193
|
+
this._executedSet = new Set();
|
|
194
|
+
this._allLoadersSet = new Set(this._loadPromises);
|
|
195
|
+
try {
|
|
196
|
+
for (const loader of this._allLoadersSet) {
|
|
197
|
+
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
209
198
|
}
|
|
210
|
-
finally {
|
|
211
|
-
this.register = origRegister;
|
|
212
|
-
}
|
|
213
|
-
stack.unshift(...inner);
|
|
214
|
-
this._loadPromises.delete(loader);
|
|
215
199
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.
|
|
200
|
+
finally {
|
|
201
|
+
this._loadPromises.clear();
|
|
202
|
+
this._isRunningLoaders = false;
|
|
203
|
+
this._initialized = true;
|
|
219
204
|
}
|
|
220
|
-
this._initialized = true;
|
|
221
205
|
}
|
|
222
206
|
item(index) {
|
|
223
207
|
const { items } = this, item = items[index];
|
|
@@ -229,10 +213,7 @@ export class Engine {
|
|
|
229
213
|
}
|
|
230
214
|
async load(params) {
|
|
231
215
|
await this.init();
|
|
232
|
-
this.
|
|
233
|
-
const { Container } = await import("./Container.js"), id = params.id ??
|
|
234
|
-
params.element?.id ??
|
|
235
|
-
`tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container(this, id, currentOptions);
|
|
216
|
+
const { Container } = await import("./Container.js"), id = params.id ?? params.element?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container(this, id, currentOptions);
|
|
236
217
|
if (oldIndex >= loadMinIndex) {
|
|
237
218
|
const old = this.item(oldIndex), deleteCount = old ? one : none;
|
|
238
219
|
if (old && !old.destroyed) {
|
|
@@ -261,15 +242,27 @@ export class Engine {
|
|
|
261
242
|
}
|
|
262
243
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
263
244
|
}
|
|
264
|
-
register(...
|
|
245
|
+
async register(...loaders) {
|
|
265
246
|
if (this._initialized) {
|
|
266
|
-
throw new Error(
|
|
247
|
+
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
267
248
|
}
|
|
268
|
-
for (const
|
|
269
|
-
this.
|
|
249
|
+
for (const loader of loaders) {
|
|
250
|
+
if (this._isRunningLoaders) {
|
|
251
|
+
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
this._loadPromises.add(loader);
|
|
255
|
+
}
|
|
270
256
|
}
|
|
271
257
|
}
|
|
272
258
|
removeEventListener(type, listener) {
|
|
273
259
|
this._eventDispatcher.removeEventListener(type, listener);
|
|
274
260
|
}
|
|
261
|
+
async _runLoader(loader, executed, allLoaders) {
|
|
262
|
+
if (executed.has(loader))
|
|
263
|
+
return;
|
|
264
|
+
executed.add(loader);
|
|
265
|
+
allLoaders.add(loader);
|
|
266
|
+
await loader(this);
|
|
267
|
+
}
|
|
275
268
|
}
|
package/cjs/Core/Particle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Vector, Vector3d } from "./Utils/Vectors.js";
|
|
2
2
|
import { calcExactPositionOrRandomFromSize, clamp, degToRad, getParticleBaseVelocity, getParticleDirectionAngle, getRandom, getRangeValue, randomInRangeValue, setRangeValue, } from "../Utils/MathUtils.js";
|
|
3
|
-
import { decayOffset, defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, half, identity, millisecondsToSeconds, minZ,
|
|
3
|
+
import { decayOffset, defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, doublePI, half, identity, millisecondsToSeconds, minZ, randomColorValue, squareExp, triple, tryCountIncrement, zIndexFactorOffset, } from "./Utils/Constants.js";
|
|
4
4
|
import { deepExtend, getPosition, initParticleNumericAnimationValue, isInArray, itemFromSingleOrMultiple, } from "../Utils/Utils.js";
|
|
5
5
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
6
6
|
import { MoveDirection } from "../Enums/Directions/MoveDirection.js";
|
|
@@ -124,8 +124,7 @@ export class Particle {
|
|
|
124
124
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
125
125
|
return color;
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
if (!rolled) {
|
|
127
|
+
if (!this.isShowingBack()) {
|
|
129
128
|
return color;
|
|
130
129
|
}
|
|
131
130
|
if (this.backColor) {
|
|
@@ -286,9 +285,7 @@ export class Particle {
|
|
|
286
285
|
const availableShapes = [...this.container.shapeDrawers.keys()];
|
|
287
286
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
288
287
|
}
|
|
289
|
-
this.effectData = this.effect
|
|
290
|
-
? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates)
|
|
291
|
-
: undefined;
|
|
288
|
+
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
292
289
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
293
290
|
particlesOptions.load(overrideOptions);
|
|
294
291
|
const effectData = this.effectData;
|
|
@@ -378,6 +375,25 @@ export class Particle {
|
|
|
378
375
|
position.y <= canvasSize.height + radius &&
|
|
379
376
|
position.x <= canvasSize.width + radius);
|
|
380
377
|
}
|
|
378
|
+
isShowingBack() {
|
|
379
|
+
if (!this.roll) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
const angle = this.roll.angle;
|
|
383
|
+
if (this.roll.horizontal && this.roll.vertical) {
|
|
384
|
+
const normalizedAngle = angle % doublePI, adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + doublePI : normalizedAngle;
|
|
385
|
+
return adjustedAngle >= Math.PI * half && adjustedAngle < Math.PI * triple * half;
|
|
386
|
+
}
|
|
387
|
+
if (this.roll.horizontal) {
|
|
388
|
+
const normalizedAngle = (angle + Math.PI * half) % (Math.PI * double), adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + Math.PI * double : normalizedAngle;
|
|
389
|
+
return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * double;
|
|
390
|
+
}
|
|
391
|
+
if (this.roll.vertical) {
|
|
392
|
+
const normalizedAngle = angle % (Math.PI * double), adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + Math.PI * double : normalizedAngle;
|
|
393
|
+
return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * double;
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
381
397
|
isVisible() {
|
|
382
398
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
383
399
|
}
|
|
@@ -7,4 +7,4 @@ export const generatedAttribute = "generated", resizeEvent = "resize", visibilit
|
|
|
7
7
|
b: 0,
|
|
8
8
|
c: 0,
|
|
9
9
|
d: 1,
|
|
10
|
-
}, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, inverseFactorNumerator = 1.0, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0,
|
|
10
|
+
}, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, inverseFactorNumerator = 1.0, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0, minZ = 0, defaultRadius = 0, posOffset = -quarter, sizeFactor = 1.5, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, touchDelay = 500, manualDefaultPosition = 50, defaultAngle = 0, identity = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0;
|
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
export var EasingType;
|
|
2
2
|
(function (EasingType) {
|
|
3
3
|
EasingType["easeInBack"] = "ease-in-back";
|
|
4
|
+
EasingType["easeInBounce"] = "ease-in-bounce";
|
|
4
5
|
EasingType["easeInCirc"] = "ease-in-circ";
|
|
5
6
|
EasingType["easeInCubic"] = "ease-in-cubic";
|
|
7
|
+
EasingType["easeInElastic"] = "ease-in-elastic";
|
|
8
|
+
EasingType["easeInExpo"] = "ease-in-expo";
|
|
9
|
+
EasingType["easeInGaussian"] = "ease-in-gaussian";
|
|
6
10
|
EasingType["easeInLinear"] = "ease-in-linear";
|
|
7
11
|
EasingType["easeInQuad"] = "ease-in-quad";
|
|
8
12
|
EasingType["easeInQuart"] = "ease-in-quart";
|
|
9
13
|
EasingType["easeInQuint"] = "ease-in-quint";
|
|
10
|
-
EasingType["
|
|
14
|
+
EasingType["easeInSigmoid"] = "ease-in-sigmoid";
|
|
11
15
|
EasingType["easeInSine"] = "ease-in-sine";
|
|
16
|
+
EasingType["easeInSmoothstep"] = "ease-in-smoothstep";
|
|
12
17
|
EasingType["easeOutBack"] = "ease-out-back";
|
|
18
|
+
EasingType["easeOutBounce"] = "ease-out-bounce";
|
|
13
19
|
EasingType["easeOutCirc"] = "ease-out-circ";
|
|
14
20
|
EasingType["easeOutCubic"] = "ease-out-cubic";
|
|
21
|
+
EasingType["easeOutElastic"] = "ease-out-elastic";
|
|
22
|
+
EasingType["easeOutExpo"] = "ease-out-expo";
|
|
23
|
+
EasingType["easeOutGaussian"] = "ease-out-gaussian";
|
|
15
24
|
EasingType["easeOutLinear"] = "ease-out-linear";
|
|
16
25
|
EasingType["easeOutQuad"] = "ease-out-quad";
|
|
17
26
|
EasingType["easeOutQuart"] = "ease-out-quart";
|
|
18
27
|
EasingType["easeOutQuint"] = "ease-out-quint";
|
|
19
|
-
EasingType["
|
|
28
|
+
EasingType["easeOutSigmoid"] = "ease-out-sigmoid";
|
|
20
29
|
EasingType["easeOutSine"] = "ease-out-sine";
|
|
30
|
+
EasingType["easeOutSmoothstep"] = "ease-out-smoothstep";
|
|
21
31
|
EasingType["easeInOutBack"] = "ease-in-out-back";
|
|
32
|
+
EasingType["easeInOutBounce"] = "ease-in-out-bounce";
|
|
22
33
|
EasingType["easeInOutCirc"] = "ease-in-out-circ";
|
|
23
34
|
EasingType["easeInOutCubic"] = "ease-in-out-cubic";
|
|
35
|
+
EasingType["easeInOutElastic"] = "ease-in-out-elastic";
|
|
36
|
+
EasingType["easeInOutExpo"] = "ease-in-out-expo";
|
|
37
|
+
EasingType["easeInOutGaussian"] = "ease-in-out-gaussian";
|
|
24
38
|
EasingType["easeInOutLinear"] = "ease-in-out-linear";
|
|
25
39
|
EasingType["easeInOutQuad"] = "ease-in-out-quad";
|
|
26
40
|
EasingType["easeInOutQuart"] = "ease-in-out-quart";
|
|
27
41
|
EasingType["easeInOutQuint"] = "ease-in-out-quint";
|
|
28
|
-
EasingType["
|
|
42
|
+
EasingType["easeInOutSigmoid"] = "ease-in-out-sigmoid";
|
|
29
43
|
EasingType["easeInOutSine"] = "ease-in-out-sine";
|
|
44
|
+
EasingType["easeInOutSmoothstep"] = "ease-in-out-smoothstep";
|
|
30
45
|
})(EasingType || (EasingType = {}));
|
package/cjs/Utils/CanvasUtils.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { lFactor, minStrokeWidth, originPoint } from "../Core/Utils/Constants.js";
|
|
2
2
|
import { AlterType } from "../Enums/Types/AlterType.js";
|
|
3
|
-
export function clearDrawPlugin(context, plugin, delta) {
|
|
4
|
-
if (!plugin.clearDraw) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
plugin.clearDraw(context, delta);
|
|
8
|
-
}
|
|
9
3
|
export function drawLine(context, begin, end) {
|
|
10
4
|
context.beginPath();
|
|
11
5
|
context.moveTo(begin.x, begin.y);
|
|
@@ -121,12 +115,6 @@ export function drawShapeBeforeDraw(container, data) {
|
|
|
121
115
|
}
|
|
122
116
|
drawer.beforeDraw(data);
|
|
123
117
|
}
|
|
124
|
-
export function drawPlugin(context, plugin, delta) {
|
|
125
|
-
if (!plugin.draw) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
plugin.draw(context, delta);
|
|
129
|
-
}
|
|
130
118
|
export function drawParticlePlugin(context, plugin, particle, delta) {
|
|
131
119
|
if (!plugin.drawParticle) {
|
|
132
120
|
return;
|
package/cjs/Utils/Utils.js
CHANGED
|
@@ -98,11 +98,15 @@ export function deepExtend(destination, ...sources) {
|
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
100
|
const sourceIsArray = Array.isArray(source);
|
|
101
|
-
if (sourceIsArray
|
|
102
|
-
destination
|
|
101
|
+
if (sourceIsArray) {
|
|
102
|
+
if (!Array.isArray(destination)) {
|
|
103
|
+
destination = [];
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
|
-
else
|
|
105
|
-
destination
|
|
106
|
+
else {
|
|
107
|
+
if (!isObject(destination) || Array.isArray(destination)) {
|
|
108
|
+
destination = {};
|
|
109
|
+
}
|
|
106
110
|
}
|
|
107
111
|
for (const key in source) {
|
|
108
112
|
if (key === "__proto__") {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* tsParticles Engine v4.0.0-alpha.
|
|
2
|
+
* tsParticles Engine v4.0.0-alpha.8
|
|
3
3
|
* Author: Matteo Bruni
|
|
4
4
|
* MIT license: https://opensource.org/licenses/MIT
|
|
5
5
|
* Website: https://particles.js.org/
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
\*************************************/
|
|
26
26
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
27
27
|
|
|
28
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Canvas: () => (/* binding */ Canvas)\n/* harmony export */ });\n/* harmony import */ var _Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Utils/CanvasUtils.js */ \"./dist/browser/Utils/CanvasUtils.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n/* harmony import */ var _Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../Utils/ColorUtils.js */ \"./dist/browser/Utils/ColorUtils.js\");\n\n\n\n\nconst fColorIndex = 0,\n sColorIndex = 1;\nfunction setTransformValue(factor, newFactor, key) {\n const newValue = newFactor[key];\n if (newValue !== undefined) {\n factor[key] = (factor[key] ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransformValue) * newValue;\n }\n}\nfunction setStyle(canvas, style, important = false) {\n if (!style) {\n return;\n }\n const element = canvas,\n elementStyle = element.style,\n keys = new Set();\n for (let i = 0; i < elementStyle.length; i++) {\n const key = elementStyle.item(i);\n if (!key) {\n continue;\n }\n keys.add(key);\n }\n for (let i = 0; i < style.length; i++) {\n const key = style.item(i);\n if (!key) {\n continue;\n }\n keys.add(key);\n }\n for (const key of keys) {\n const value = style.getPropertyValue(key);\n if (value) {\n elementStyle.setProperty(key, value, important ? \"important\" : \"\");\n } else {\n elementStyle.removeProperty(key);\n }\n }\n}\nclass Canvas {\n constructor(container, engine) {\n this.container = container;\n this._reusableColorStyles = {};\n this._reusablePluginColors = [undefined, undefined];\n this._reusableTransform = {};\n this._applyPostDrawUpdaters = particle => {\n for (const updater of this._postDrawUpdaters) {\n updater.afterDraw?.(particle);\n }\n };\n this._applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {\n for (const updater of this._preDrawUpdaters) {\n if (updater.getColorStyles) {\n const {\n fill,\n stroke\n } = updater.getColorStyles(particle, ctx, radius, zOpacity);\n if (fill) {\n colorStyles.fill = fill;\n }\n if (stroke) {\n colorStyles.stroke = stroke;\n }\n }\n if (updater.getTransformValues) {\n const updaterTransform = updater.getTransformValues(particle);\n for (const key in updaterTransform) {\n setTransformValue(transform, updaterTransform, key);\n }\n }\n updater.beforeDraw?.(particle);\n }\n };\n this._applyResizePlugins = () => {\n for (const plugin of this._resizePlugins) {\n plugin.resize?.();\n }\n };\n this._getPluginParticleColors = particle => {\n let fColor, sColor;\n for (const plugin of this._colorPlugins) {\n if (!fColor && plugin.particleFillColor) {\n fColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.rangeColorToHsl)(this._engine, plugin.particleFillColor(particle));\n }\n if (!sColor && plugin.particleStrokeColor) {\n sColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.rangeColorToHsl)(this._engine, plugin.particleStrokeColor(particle));\n }\n if (fColor && sColor) {\n break;\n }\n }\n this._reusablePluginColors[fColorIndex] = fColor;\n this._reusablePluginColors[sColorIndex] = sColor;\n return this._reusablePluginColors;\n };\n this._initStyle = () => {\n const element = this.element,\n options = this.container.actualOptions;\n if (!element) {\n return;\n }\n if (this._fullScreen) {\n this._setFullScreenStyle();\n } else {\n this._resetOriginalStyle();\n }\n for (const key in options.style) {\n if (!key || !Object.hasOwn(options.style, key)) {\n continue;\n }\n const value = options.style[key];\n if (!value) {\n continue;\n }\n element.style.setProperty(key, value, \"important\");\n }\n };\n this._repairStyle = () => {\n const element = this.element;\n if (!element) {\n return;\n }\n this._safeMutationObserver(observer => {\n observer.disconnect();\n });\n this._initStyle();\n this.initBackground();\n const pointerEvents = this._pointerEvents;\n element.style.pointerEvents = pointerEvents;\n element.setAttribute(\"pointer-events\", pointerEvents);\n this._safeMutationObserver(observer => {\n if (!(element instanceof Node)) {\n return;\n }\n observer.observe(element, {\n attributes: true\n });\n });\n };\n this._resetOriginalStyle = () => {\n const element = this.element,\n originalStyle = this._originalStyle;\n if (!element || !originalStyle) {\n return;\n }\n setStyle(element, originalStyle, true);\n };\n this._safeMutationObserver = callback => {\n if (!this._mutationObserver) {\n return;\n }\n callback(this._mutationObserver);\n };\n this._setFullScreenStyle = () => {\n const element = this.element;\n if (!element) {\n return;\n }\n setStyle(element, (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.getFullScreenStyle)(this.container.actualOptions.fullScreen.zIndex), true);\n };\n this._engine = engine;\n this._standardSize = {\n height: 0,\n width: 0\n };\n const pxRatio = container.retina.pixelRatio,\n stdSize = this._standardSize;\n this.size = {\n height: stdSize.height * pxRatio,\n width: stdSize.width * pxRatio\n };\n this._context = null;\n this._generated = false;\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n this._resizePlugins = [];\n this._colorPlugins = [];\n this._pointerEvents = \"none\";\n }\n get _fullScreen() {\n return this.container.actualOptions.fullScreen.enable;\n }\n canvasClear() {\n if (!this.container.actualOptions.clear) {\n return;\n }\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.clear)(ctx, this.size);\n });\n }\n clear() {\n let pluginHandled = false;\n for (const plugin of this.container.plugins) {\n if (!pluginHandled && plugin.canvasClear) {\n pluginHandled = plugin.canvasClear();\n }\n }\n if (pluginHandled) {\n return;\n }\n this.canvasClear();\n }\n clearDrawPlugin(plugin, delta) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.clearDrawPlugin)(ctx, plugin, delta);\n });\n }\n destroy() {\n this.stop();\n if (this._generated) {\n const element = this.element;\n element?.remove();\n this.element = undefined;\n } else {\n this._resetOriginalStyle();\n }\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n this._resizePlugins = [];\n this._colorPlugins = [];\n }\n draw(cb) {\n const ctx = this._context;\n if (!ctx) {\n return;\n }\n return cb(ctx);\n }\n drawParticle(particle, delta) {\n if (particle.spawning || particle.destroyed) {\n return;\n }\n const radius = particle.getRadius();\n if (radius <= _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.minimumSize) {\n return;\n }\n const pfColor = particle.getFillColor(),\n psColor = particle.getStrokeColor() ?? pfColor;\n let [fColor, sColor] = this._getPluginParticleColors(particle);\n fColor ??= pfColor;\n sColor ??= psColor;\n if (!fColor && !sColor) {\n return;\n }\n const container = this.container,\n zIndexOptions = particle.options.zIndex,\n zIndexFactor = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.zIndexFactorOffset - particle.zIndexFactor,\n {\n opacity,\n strokeOpacity\n } = particle.getOpacity(),\n transform = this._reusableTransform,\n colorStyles = this._reusableColorStyles,\n fill = fColor ? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.getStyleFromHsl)(fColor, container.hdr, opacity) : undefined,\n stroke = sColor ? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.getStyleFromHsl)(sColor, container.hdr, strokeOpacity) : fill;\n transform.a = transform.b = transform.c = transform.d = undefined;\n colorStyles.fill = fill;\n colorStyles.stroke = stroke;\n this.draw(context => {\n this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.drawParticle)({\n container,\n context,\n particle,\n delta,\n colorStyles,\n radius: radius * zIndexFactor ** zIndexOptions.sizeRate,\n opacity: opacity,\n transform\n });\n });\n this._applyPostDrawUpdaters(particle);\n }\n drawParticlePlugin(plugin, particle, delta) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.drawParticlePlugin)(ctx, plugin, particle, delta);\n });\n }\n drawParticles(delta) {\n const {\n particles,\n plugins\n } = this.container;\n this.clear();\n particles.update(delta);\n for (const plugin of plugins.values()) {\n this.drawPlugin(plugin, delta);\n }\n this.draw(() => {\n particles.drawParticles(delta);\n });\n for (const plugin of plugins.values()) {\n this.clearDrawPlugin(plugin, delta);\n }\n }\n drawPlugin(plugin, delta) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.drawPlugin)(ctx, plugin, delta);\n });\n }\n init() {\n this._safeMutationObserver(obs => {\n obs.disconnect();\n });\n this._mutationObserver = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.safeMutationObserver)(records => {\n for (const record of records) {\n if (record.type === \"attributes\" && record.attributeName === \"style\") {\n this._repairStyle();\n }\n }\n });\n this.resize();\n this._initStyle();\n this.initBackground();\n this._safeMutationObserver(obs => {\n if (!this.element || !(this.element instanceof Node)) {\n return;\n }\n obs.observe(this.element, {\n attributes: true\n });\n });\n this.initUpdaters();\n this.initPlugins();\n this.paint();\n }\n initBackground() {\n const {\n container\n } = this,\n options = container.actualOptions,\n background = options.background,\n element = this.element;\n if (!element) {\n return;\n }\n const elementStyle = element.style,\n color = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.rangeColorToRgb)(this._engine, background.color);\n if (color) {\n elementStyle.backgroundColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.getStyleFromRgb)(color, container.hdr, background.opacity);\n } else {\n elementStyle.backgroundColor = \"\";\n }\n elementStyle.backgroundImage = background.image || \"\";\n elementStyle.backgroundPosition = background.position || \"\";\n elementStyle.backgroundRepeat = background.repeat || \"\";\n elementStyle.backgroundSize = background.size || \"\";\n }\n initPlugins() {\n this._resizePlugins = [];\n for (const plugin of this.container.plugins) {\n if (plugin.resize) {\n this._resizePlugins.push(plugin);\n }\n if (plugin.particleFillColor ?? plugin.particleStrokeColor) {\n this._colorPlugins.push(plugin);\n }\n }\n }\n initUpdaters() {\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n for (const updater of this.container.particles.updaters) {\n if (updater.afterDraw) {\n this._postDrawUpdaters.push(updater);\n }\n if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {\n this._preDrawUpdaters.push(updater);\n }\n }\n }\n loadCanvas(canvas) {\n if (this._generated && this.element) {\n this.element.remove();\n }\n const container = this.container;\n this._generated = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.generatedAttribute in canvas.dataset ? canvas.dataset[_Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.generatedAttribute] === \"true\" : this._generated;\n this.element = canvas;\n this.element.ariaHidden = \"true\";\n this._originalStyle = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.cloneStyle)(this.element.style);\n const standardSize = this._standardSize;\n standardSize.height = canvas.offsetHeight;\n standardSize.width = canvas.offsetWidth;\n const pxRatio = this.container.retina.pixelRatio,\n retinaSize = this.size;\n canvas.height = retinaSize.height = standardSize.height * pxRatio;\n canvas.width = retinaSize.width = standardSize.width * pxRatio;\n const canSupportHdrQuery = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.safeMatchMedia)(\"(color-gamut: p3)\");\n this._context = this.element.getContext(\"2d\", {\n alpha: true,\n colorSpace: canSupportHdrQuery?.matches && container.hdr ? \"display-p3\" : \"srgb\",\n desynchronized: true,\n willReadFrequently: false\n });\n this._safeMutationObserver(obs => {\n obs.disconnect();\n });\n container.retina.init();\n this.initBackground();\n this._safeMutationObserver(obs => {\n if (!this.element || !(this.element instanceof Node)) {\n return;\n }\n obs.observe(this.element, {\n attributes: true\n });\n });\n }\n paint() {\n let handled = false;\n for (const plugin of this.container.plugins) {\n if (handled) {\n break;\n }\n handled = plugin.canvasPaint?.() ?? false;\n }\n if (handled) {\n return;\n }\n this.paintBase();\n }\n paintBase(baseColor) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.paintBase)(ctx, this.size, baseColor);\n });\n }\n paintImage(image, opacity) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.paintImage)(ctx, this.size, image, opacity);\n });\n }\n resize() {\n if (!this.element) {\n return false;\n }\n const container = this.container,\n currentSize = container.canvas._standardSize,\n newSize = {\n width: this.element.offsetWidth,\n height: this.element.offsetHeight\n },\n pxRatio = container.retina.pixelRatio,\n retinaSize = {\n width: newSize.width * pxRatio,\n height: newSize.height * pxRatio\n };\n if (newSize.height === currentSize.height && newSize.width === currentSize.width && retinaSize.height === this.element.height && retinaSize.width === this.element.width) {\n return false;\n }\n const oldSize = {\n ...currentSize\n };\n currentSize.height = newSize.height;\n currentSize.width = newSize.width;\n const canvasSize = this.size;\n this.element.width = canvasSize.width = retinaSize.width;\n this.element.height = canvasSize.height = retinaSize.height;\n if (this.container.started) {\n container.particles.setResizeFactor({\n width: currentSize.width / oldSize.width,\n height: currentSize.height / oldSize.height\n });\n }\n return true;\n }\n setPointerEvents(type) {\n const element = this.element;\n if (!element) {\n return;\n }\n this._pointerEvents = type;\n this._repairStyle();\n }\n stop() {\n this._safeMutationObserver(obs => {\n obs.disconnect();\n });\n this._mutationObserver = undefined;\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.clear)(ctx, this.size);\n });\n }\n async windowResize() {\n if (!this.element || !this.resize()) {\n return;\n }\n const container = this.container,\n needsRefresh = container.updateActualOptions();\n container.particles.setDensity();\n this._applyResizePlugins();\n if (needsRefresh) {\n await container.refresh();\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Canvas.js?\n}");
|
|
28
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Canvas: () => (/* binding */ Canvas)\n/* harmony export */ });\n/* harmony import */ var _Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Utils/CanvasUtils.js */ \"./dist/browser/Utils/CanvasUtils.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n/* harmony import */ var _Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../Utils/ColorUtils.js */ \"./dist/browser/Utils/ColorUtils.js\");\n\n\n\n\nconst fColorIndex = 0,\n sColorIndex = 1;\nfunction setTransformValue(factor, newFactor, key) {\n const newValue = newFactor[key];\n if (newValue !== undefined) {\n factor[key] = (factor[key] ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransformValue) * newValue;\n }\n}\nfunction setStyle(canvas, style, important = false) {\n if (!style) {\n return;\n }\n const element = canvas,\n elementStyle = element.style,\n keys = new Set();\n for (let i = 0; i < elementStyle.length; i++) {\n const key = elementStyle.item(i);\n if (!key) {\n continue;\n }\n keys.add(key);\n }\n for (let i = 0; i < style.length; i++) {\n const key = style.item(i);\n if (!key) {\n continue;\n }\n keys.add(key);\n }\n for (const key of keys) {\n const value = style.getPropertyValue(key);\n if (value) {\n elementStyle.setProperty(key, value, important ? \"important\" : \"\");\n } else {\n elementStyle.removeProperty(key);\n }\n }\n}\nclass Canvas {\n constructor(container, engine) {\n this.container = container;\n this._reusableColorStyles = {};\n this._reusablePluginColors = [undefined, undefined];\n this._reusableTransform = {};\n this._applyPostDrawUpdaters = particle => {\n for (const updater of this._postDrawUpdaters) {\n updater.afterDraw?.(particle);\n }\n };\n this._applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {\n for (const updater of this._preDrawUpdaters) {\n if (updater.getColorStyles) {\n const {\n fill,\n stroke\n } = updater.getColorStyles(particle, ctx, radius, zOpacity);\n if (fill) {\n colorStyles.fill = fill;\n }\n if (stroke) {\n colorStyles.stroke = stroke;\n }\n }\n if (updater.getTransformValues) {\n const updaterTransform = updater.getTransformValues(particle);\n for (const key in updaterTransform) {\n setTransformValue(transform, updaterTransform, key);\n }\n }\n updater.beforeDraw?.(particle);\n }\n };\n this._applyResizePlugins = () => {\n for (const plugin of this._resizePlugins) {\n plugin.resize?.();\n }\n };\n this._getPluginParticleColors = particle => {\n let fColor, sColor;\n for (const plugin of this._colorPlugins) {\n if (!fColor && plugin.particleFillColor) {\n fColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.rangeColorToHsl)(this._engine, plugin.particleFillColor(particle));\n }\n if (!sColor && plugin.particleStrokeColor) {\n sColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.rangeColorToHsl)(this._engine, plugin.particleStrokeColor(particle));\n }\n if (fColor && sColor) {\n break;\n }\n }\n this._reusablePluginColors[fColorIndex] = fColor;\n this._reusablePluginColors[sColorIndex] = sColor;\n return this._reusablePluginColors;\n };\n this._initStyle = () => {\n const element = this.element,\n options = this.container.actualOptions;\n if (!element) {\n return;\n }\n if (this._fullScreen) {\n this._setFullScreenStyle();\n } else {\n this._resetOriginalStyle();\n }\n for (const key in options.style) {\n if (!key || !Object.hasOwn(options.style, key)) {\n continue;\n }\n const value = options.style[key];\n if (!value) {\n continue;\n }\n element.style.setProperty(key, value, \"important\");\n }\n };\n this._repairStyle = () => {\n const element = this.element;\n if (!element) {\n return;\n }\n this._safeMutationObserver(observer => {\n observer.disconnect();\n });\n this._initStyle();\n this.initBackground();\n const pointerEvents = this._pointerEvents;\n element.style.pointerEvents = pointerEvents;\n element.setAttribute(\"pointer-events\", pointerEvents);\n this._safeMutationObserver(observer => {\n if (!(element instanceof Node)) {\n return;\n }\n observer.observe(element, {\n attributes: true\n });\n });\n };\n this._resetOriginalStyle = () => {\n const element = this.element,\n originalStyle = this._originalStyle;\n if (!element || !originalStyle) {\n return;\n }\n setStyle(element, originalStyle, true);\n };\n this._safeMutationObserver = callback => {\n if (!this._mutationObserver) {\n return;\n }\n callback(this._mutationObserver);\n };\n this._setFullScreenStyle = () => {\n const element = this.element;\n if (!element) {\n return;\n }\n setStyle(element, (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.getFullScreenStyle)(this.container.actualOptions.fullScreen.zIndex), true);\n };\n this._engine = engine;\n this._standardSize = {\n height: 0,\n width: 0\n };\n const pxRatio = container.retina.pixelRatio,\n stdSize = this._standardSize;\n this.size = {\n height: stdSize.height * pxRatio,\n width: stdSize.width * pxRatio\n };\n this._context = null;\n this._generated = false;\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n this._resizePlugins = [];\n this._colorPlugins = [];\n this._pointerEvents = \"none\";\n }\n get _fullScreen() {\n return this.container.actualOptions.fullScreen.enable;\n }\n canvasClear() {\n if (!this.container.actualOptions.clear) {\n return;\n }\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.clear)(ctx, this.size);\n });\n }\n clear() {\n let pluginHandled = false;\n for (const plugin of this.container.plugins) {\n if (!pluginHandled && plugin.canvasClear) {\n pluginHandled = plugin.canvasClear();\n }\n }\n if (pluginHandled) {\n return;\n }\n this.canvasClear();\n }\n destroy() {\n this.stop();\n if (this._generated) {\n const element = this.element;\n element?.remove();\n this.element = undefined;\n } else {\n this._resetOriginalStyle();\n }\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n this._resizePlugins = [];\n this._colorPlugins = [];\n }\n draw(cb) {\n const ctx = this._context;\n if (!ctx) {\n return;\n }\n return cb(ctx);\n }\n drawParticle(particle, delta) {\n if (particle.spawning || particle.destroyed) {\n return;\n }\n const radius = particle.getRadius();\n if (radius <= _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.minimumSize) {\n return;\n }\n const pfColor = particle.getFillColor(),\n psColor = particle.getStrokeColor() ?? pfColor;\n let [fColor, sColor] = this._getPluginParticleColors(particle);\n fColor ??= pfColor;\n sColor ??= psColor;\n if (!fColor && !sColor) {\n return;\n }\n const container = this.container,\n zIndexOptions = particle.options.zIndex,\n zIndexFactor = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.zIndexFactorOffset - particle.zIndexFactor,\n {\n opacity,\n strokeOpacity\n } = particle.getOpacity(),\n transform = this._reusableTransform,\n colorStyles = this._reusableColorStyles,\n fill = fColor ? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.getStyleFromHsl)(fColor, container.hdr, opacity) : undefined,\n stroke = sColor ? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.getStyleFromHsl)(sColor, container.hdr, strokeOpacity) : fill;\n transform.a = transform.b = transform.c = transform.d = undefined;\n colorStyles.fill = fill;\n colorStyles.stroke = stroke;\n this.draw(context => {\n for (const plugin of container.plugins) {\n if (plugin.drawParticleSetup) {\n plugin.drawParticleSetup(context, particle, delta);\n }\n }\n this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.drawParticle)({\n container,\n context,\n particle,\n delta,\n colorStyles,\n radius: radius * zIndexFactor ** zIndexOptions.sizeRate,\n opacity: opacity,\n transform\n });\n this._applyPostDrawUpdaters(particle);\n for (const plugin of container.plugins) {\n if (plugin.drawParticleCleanup) {\n plugin.drawParticleCleanup(context, particle, delta);\n }\n }\n });\n }\n drawParticlePlugin(plugin, particle, delta) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.drawParticlePlugin)(ctx, plugin, particle, delta);\n });\n }\n drawParticles(delta) {\n const {\n particles,\n plugins\n } = this.container;\n this.clear();\n particles.update(delta);\n this.draw(ctx => {\n for (const plugin of plugins) {\n plugin.drawSettingsSetup?.(ctx, delta);\n }\n for (const plugin of plugins) {\n plugin.draw?.(ctx, delta);\n }\n particles.drawParticles(delta);\n for (const plugin of plugins) {\n plugin.clearDraw?.(ctx, delta);\n }\n for (const plugin of plugins) {\n plugin.drawSettingsCleanup?.(ctx, delta);\n }\n });\n }\n init() {\n this._safeMutationObserver(obs => {\n obs.disconnect();\n });\n this._mutationObserver = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.safeMutationObserver)(records => {\n for (const record of records) {\n if (record.type === \"attributes\" && record.attributeName === \"style\") {\n this._repairStyle();\n }\n }\n });\n this.resize();\n this._initStyle();\n this.initBackground();\n this._safeMutationObserver(obs => {\n if (!this.element || !(this.element instanceof Node)) {\n return;\n }\n obs.observe(this.element, {\n attributes: true\n });\n });\n this.initUpdaters();\n this.initPlugins();\n this.paint();\n }\n initBackground() {\n const {\n container\n } = this,\n options = container.actualOptions,\n background = options.background,\n element = this.element;\n if (!element) {\n return;\n }\n const elementStyle = element.style,\n color = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.rangeColorToRgb)(this._engine, background.color);\n if (color) {\n elementStyle.backgroundColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.getStyleFromRgb)(color, container.hdr, background.opacity);\n } else {\n elementStyle.backgroundColor = \"\";\n }\n elementStyle.backgroundImage = background.image || \"\";\n elementStyle.backgroundPosition = background.position || \"\";\n elementStyle.backgroundRepeat = background.repeat || \"\";\n elementStyle.backgroundSize = background.size || \"\";\n }\n initPlugins() {\n this._resizePlugins = [];\n for (const plugin of this.container.plugins) {\n if (plugin.resize) {\n this._resizePlugins.push(plugin);\n }\n if (plugin.particleFillColor ?? plugin.particleStrokeColor) {\n this._colorPlugins.push(plugin);\n }\n }\n }\n initUpdaters() {\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n for (const updater of this.container.particles.updaters) {\n if (updater.afterDraw) {\n this._postDrawUpdaters.push(updater);\n }\n if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {\n this._preDrawUpdaters.push(updater);\n }\n }\n }\n loadCanvas(canvas) {\n if (this._generated && this.element) {\n this.element.remove();\n }\n const container = this.container;\n this._generated = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.generatedAttribute in canvas.dataset ? canvas.dataset[_Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.generatedAttribute] === \"true\" : this._generated;\n this.element = canvas;\n this.element.ariaHidden = \"true\";\n this._originalStyle = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.cloneStyle)(this.element.style);\n const standardSize = this._standardSize;\n standardSize.height = canvas.offsetHeight;\n standardSize.width = canvas.offsetWidth;\n const pxRatio = this.container.retina.pixelRatio,\n retinaSize = this.size;\n canvas.height = retinaSize.height = standardSize.height * pxRatio;\n canvas.width = retinaSize.width = standardSize.width * pxRatio;\n const canSupportHdrQuery = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.safeMatchMedia)(\"(color-gamut: p3)\");\n this._context = this.element.getContext(\"2d\", {\n alpha: true,\n colorSpace: canSupportHdrQuery?.matches && container.hdr ? \"display-p3\" : \"srgb\",\n desynchronized: true,\n willReadFrequently: false\n });\n this._safeMutationObserver(obs => {\n obs.disconnect();\n });\n container.retina.init();\n this.initBackground();\n this._safeMutationObserver(obs => {\n if (!this.element || !(this.element instanceof Node)) {\n return;\n }\n obs.observe(this.element, {\n attributes: true\n });\n });\n }\n paint() {\n let handled = false;\n for (const plugin of this.container.plugins) {\n if (handled) {\n break;\n }\n handled = plugin.canvasPaint?.() ?? false;\n }\n if (handled) {\n return;\n }\n this.paintBase();\n }\n paintBase(baseColor) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.paintBase)(ctx, this.size, baseColor);\n });\n }\n paintImage(image, opacity) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.paintImage)(ctx, this.size, image, opacity);\n });\n }\n resize() {\n if (!this.element) {\n return false;\n }\n const container = this.container,\n currentSize = container.canvas._standardSize,\n newSize = {\n width: this.element.offsetWidth,\n height: this.element.offsetHeight\n },\n pxRatio = container.retina.pixelRatio,\n retinaSize = {\n width: newSize.width * pxRatio,\n height: newSize.height * pxRatio\n };\n if (newSize.height === currentSize.height && newSize.width === currentSize.width && retinaSize.height === this.element.height && retinaSize.width === this.element.width) {\n return false;\n }\n const oldSize = {\n ...currentSize\n };\n currentSize.height = newSize.height;\n currentSize.width = newSize.width;\n const canvasSize = this.size;\n this.element.width = canvasSize.width = retinaSize.width;\n this.element.height = canvasSize.height = retinaSize.height;\n if (this.container.started) {\n container.particles.setResizeFactor({\n width: currentSize.width / oldSize.width,\n height: currentSize.height / oldSize.height\n });\n }\n return true;\n }\n setPointerEvents(type) {\n const element = this.element;\n if (!element) {\n return;\n }\n this._pointerEvents = type;\n this._repairStyle();\n }\n stop() {\n this._safeMutationObserver(obs => {\n obs.disconnect();\n });\n this._mutationObserver = undefined;\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_0__.clear)(ctx, this.size);\n });\n }\n async windowResize() {\n if (!this.element || !this.resize()) {\n return;\n }\n const container = this.container,\n needsRefresh = container.updateActualOptions();\n container.particles.setDensity();\n this._applyResizePlugins();\n if (needsRefresh) {\n await container.refresh();\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Canvas.js?\n}");
|
|
29
29
|
|
|
30
30
|
/***/ },
|
|
31
31
|
|
|
@@ -45,7 +45,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
45
45
|
\***************************************/
|
|
46
46
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
47
47
|
|
|
48
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Particle: () => (/* binding */ Particle)\n/* harmony export */ });\n/* harmony import */ var _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Utils/Vectors.js */ \"./dist/browser/Core/Utils/Vectors.js\");\n/* harmony import */ var _Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Utils/MathUtils.js */ \"./dist/browser/Utils/MathUtils.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../Enums/Types/EventType.js */ \"./dist/browser/Enums/Types/EventType.js\");\n/* harmony import */ var _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Enums/Directions/MoveDirection.js */ \"./dist/browser/Enums/Directions/MoveDirection.js\");\n/* harmony import */ var _Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../Enums/Modes/OutMode.js */ \"./dist/browser/Enums/Modes/OutMode.js\");\n/* harmony import */ var _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../Enums/Types/ParticleOutType.js */ \"./dist/browser/Enums/Types/ParticleOutType.js\");\n/* harmony import */ var _Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../Utils/CanvasUtils.js */ \"./dist/browser/Utils/CanvasUtils.js\");\n/* harmony import */ var _Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../Utils/ColorUtils.js */ \"./dist/browser/Utils/ColorUtils.js\");\n/* harmony import */ var _Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../Utils/OptionsUtils.js */ \"./dist/browser/Utils/OptionsUtils.js\");\n\n\n\n\n\n\n\n\n\n\n\nfunction loadEffectData(effect, effectOptions, id, reduceDuplicates) {\n const effectData = effectOptions.options[effect];\n return (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.deepExtend)({\n close: effectOptions.close,\n fill: effectOptions.fill\n }, (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(effectData, id, reduceDuplicates));\n}\nfunction loadShapeData(shape, shapeOptions, id, reduceDuplicates) {\n const shapeData = shapeOptions.options[shape];\n return (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.deepExtend)({\n close: shapeOptions.close,\n fill: shapeOptions.fill\n }, (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(shapeData, id, reduceDuplicates));\n}\nfunction fixOutMode(data) {\n if (!(0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.isInArray)(data.outMode, data.checkModes)) {\n return;\n }\n const diameter = data.radius * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double;\n if (data.coord > data.maxCoord - diameter) {\n data.setCb(-data.radius);\n } else if (data.coord < diameter) {\n data.setCb(data.radius);\n }\n}\nclass Particle {\n constructor(engine, container) {\n this.container = container;\n this._cachedOpacityData = {\n opacity: _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultOpacity,\n strokeOpacity: _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultOpacity\n };\n this._cachedPosition = _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.origin;\n this._cachedRotateData = {\n sin: 0,\n cos: 0\n };\n this._cachedTransform = {\n a: 1,\n b: 0,\n c: 0,\n d: 1\n };\n this._calcPosition = (position, zIndex) => {\n let tryCount = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultRetryCount,\n posVec = position ? _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.create(position.x, position.y, zIndex) : undefined;\n const container = this.container,\n plugins = Array.from(container.plugins),\n outModes = this.options.move.outModes,\n radius = this.getRadius(),\n canvasSize = container.canvas.size,\n abortController = new AbortController(),\n {\n signal\n } = abortController;\n while (!signal.aborted) {\n for (const plugin of plugins) {\n const pluginPos = plugin.particlePosition?.(posVec, this);\n if (pluginPos) {\n return _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);\n }\n }\n const exactPosition = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.calcExactPositionOrRandomFromSize)({\n size: canvasSize,\n position: posVec\n }),\n pos = _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.create(exactPosition.x, exactPosition.y, zIndex);\n this._fixHorizontal(pos, radius, outModes.left ?? outModes.default);\n this._fixHorizontal(pos, radius, outModes.right ?? outModes.default);\n this._fixVertical(pos, radius, outModes.top ?? outModes.default);\n this._fixVertical(pos, radius, outModes.bottom ?? outModes.default);\n let isValidPosition = true;\n for (const plugin of plugins) {\n isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;\n if (!isValidPosition) {\n break;\n }\n }\n if (isValidPosition) {\n return pos;\n }\n tryCount += _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.tryCountIncrement;\n posVec = undefined;\n }\n return posVec;\n };\n this._calculateVelocity = () => {\n const baseVelocity = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getParticleBaseVelocity)(this.direction),\n res = baseVelocity.copy(),\n moveOptions = this.options.move;\n if (moveOptions.direction === _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__.MoveDirection.inside || moveOptions.direction === _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__.MoveDirection.outside) {\n return res;\n }\n const rad = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.degToRad)((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(moveOptions.angle.value)),\n radOffset = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.degToRad)((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(moveOptions.angle.offset)),\n range = {\n left: radOffset - rad * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half,\n right: radOffset + rad * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half\n };\n if (!moveOptions.straight) {\n res.angle += (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.randomInRangeValue)((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.setRangeValue)(range.left, range.right));\n }\n if (moveOptions.random && typeof moveOptions.speed === \"number\") {\n res.length *= (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRandom)();\n }\n return res;\n };\n this._fixHorizontal = (pos, radius, outMode) => {\n fixOutMode({\n outMode,\n checkModes: [_Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_6__.OutMode.bounce],\n coord: pos.x,\n maxCoord: this.container.canvas.size.width,\n setCb: value => pos.x += value,\n radius\n });\n };\n this._fixVertical = (pos, radius, outMode) => {\n fixOutMode({\n outMode,\n checkModes: [_Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_6__.OutMode.bounce],\n coord: pos.y,\n maxCoord: this.container.canvas.size.height,\n setCb: value => pos.y += value,\n radius\n });\n };\n this._getRollColor = color => {\n if (!color || !this.roll || !this.backColor && !this.roll.alter) {\n return color;\n }\n const backFactor = this.roll.horizontal && this.roll.vertical ? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.rollFactor : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.rollFactor,\n backSum = this.roll.horizontal ? Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.none,\n rolled = Math.floor((this.roll.angle + backSum) / (Math.PI / backFactor)) % _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double;\n if (!rolled) {\n return color;\n }\n if (this.backColor) {\n return this.backColor;\n }\n if (this.roll.alter) {\n return (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_8__.alterHsl)(color, this.roll.alter.type, this.roll.alter.value);\n }\n return color;\n };\n this._initPosition = position => {\n const container = this.container,\n zIndexValue = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(this.options.zIndex.value);\n const initialPosition = this._calcPosition(position, (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.clamp)(zIndexValue, _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.minZ, container.zLayers));\n if (!initialPosition) {\n throw new Error(\"a valid position cannot be found for particle\");\n }\n this.position = initialPosition;\n this.initialPosition = this.position.copy();\n const canvasSize = container.canvas.size;\n this.moveCenter = {\n ...(0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.getPosition)(this.options.move.center, canvasSize),\n radius: this.options.move.center.radius,\n mode: this.options.move.center.mode\n };\n this.direction = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);\n switch (this.options.move.direction) {\n case _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__.MoveDirection.inside:\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_7__.ParticleOutType.inside;\n break;\n case _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__.MoveDirection.outside:\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_7__.ParticleOutType.outside;\n break;\n }\n this.offset = _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n };\n this._engine = engine;\n }\n destroy(override) {\n if (this.unbreakable || this.destroyed) {\n return;\n }\n this.destroyed = true;\n this.bubble.inRange = false;\n this.slow.inRange = false;\n const container = this.container,\n pathGenerator = this.pathGenerator,\n shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;\n shapeDrawer?.particleDestroy?.(this);\n for (const plugin of container.plugins) {\n plugin.particleDestroyed?.(this, override);\n }\n for (const updater of container.particles.updaters) {\n updater.particleDestroyed?.(this, override);\n }\n pathGenerator?.reset(this);\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.particleDestroyed, {\n container: this.container,\n data: {\n particle: this\n }\n });\n }\n draw(delta) {\n const container = this.container,\n canvas = container.canvas;\n for (const plugin of container.plugins) {\n canvas.drawParticlePlugin(plugin, this, delta);\n }\n canvas.drawParticle(this, delta);\n }\n getAngle() {\n return this.rotation + (this.pathRotation ? this.velocity.angle : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultAngle);\n }\n getFillColor() {\n return this._getRollColor(this.bubble.color ?? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_9__.getHslFromAnimation)(this.color));\n }\n getMass() {\n return this.getRadius() ** _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.squareExp * Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half;\n }\n getOpacity() {\n const zIndexOptions = this.options.zIndex,\n zIndexFactor = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.zIndexFactorOffset - this.zIndexFactor,\n zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate,\n opacity = this.bubble.opacity ?? (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(this.opacity?.value ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultOpacity),\n strokeOpacity = this.strokeOpacity ?? opacity;\n this._cachedOpacityData.opacity = opacity * zOpacityFactor;\n this._cachedOpacityData.strokeOpacity = strokeOpacity * zOpacityFactor;\n return this._cachedOpacityData;\n }\n getPosition() {\n this._cachedPosition.x = this.position.x + this.offset.x;\n this._cachedPosition.y = this.position.y + this.offset.y;\n this._cachedPosition.z = this.position.z;\n return this._cachedPosition;\n }\n getRadius() {\n return this.bubble.radius ?? this.size.value;\n }\n getRotateData() {\n const angle = this.getAngle();\n this._cachedRotateData.sin = Math.sin(angle);\n this._cachedRotateData.cos = Math.cos(angle);\n return this._cachedRotateData;\n }\n getStrokeColor() {\n return this._getRollColor(this.bubble.color ?? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_9__.getHslFromAnimation)(this.strokeColor));\n }\n getTransformData(externalTransform) {\n const rotateData = this.getRotateData(),\n rotating = this.isRotating;\n this._cachedTransform.a = rotateData.cos * (externalTransform.a ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransform.a);\n this._cachedTransform.b = rotating ? rotateData.sin * (externalTransform.b ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.identity) : externalTransform.b ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransform.b;\n this._cachedTransform.c = rotating ? -rotateData.sin * (externalTransform.c ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.identity) : externalTransform.c ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransform.c;\n this._cachedTransform.d = rotateData.cos * (externalTransform.d ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransform.d);\n return this._cachedTransform;\n }\n init(id, position, overrideOptions, group) {\n const container = this.container;\n this.id = id;\n this.group = group;\n this.effectClose = true;\n this.effectFill = true;\n this.shapeClose = true;\n this.shapeFill = true;\n this.pathRotation = false;\n this.lastPathTime = 0;\n this.destroyed = false;\n this.unbreakable = false;\n this.isRotating = false;\n this.rotation = 0;\n this.misplaced = false;\n this.retina = {\n maxDistance: {}\n };\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_7__.ParticleOutType.normal;\n this.ignoresResizeRatio = true;\n const pxRatio = container.retina.pixelRatio,\n mainOptions = container.actualOptions,\n particlesOptions = (0,_Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_10__.loadParticlesOptions)(this._engine, container, mainOptions.particles),\n reduceDuplicates = particlesOptions.reduceDuplicates,\n effectType = particlesOptions.effect.type,\n shapeType = particlesOptions.shape.type;\n this.effect = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);\n this.shape = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);\n const effectOptions = particlesOptions.effect,\n shapeOptions = particlesOptions.shape;\n if (overrideOptions) {\n if (overrideOptions.effect?.type) {\n const overrideEffectType = overrideOptions.effect.type,\n effect = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(overrideEffectType, this.id, reduceDuplicates);\n if (effect) {\n this.effect = effect;\n effectOptions.load(overrideOptions.effect);\n }\n }\n if (overrideOptions.shape?.type) {\n const overrideShapeType = overrideOptions.shape.type,\n shape = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(overrideShapeType, this.id, reduceDuplicates);\n if (shape) {\n this.shape = shape;\n shapeOptions.load(overrideOptions.shape);\n }\n }\n }\n if (this.effect === _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.randomColorValue) {\n const availableEffects = [...this.container.effectDrawers.keys()];\n this.effect = availableEffects[Math.floor((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRandom)() * availableEffects.length)];\n }\n if (this.shape === _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.randomColorValue) {\n const availableShapes = [...this.container.shapeDrawers.keys()];\n this.shape = availableShapes[Math.floor((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRandom)() * availableShapes.length)];\n }\n this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;\n this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;\n particlesOptions.load(overrideOptions);\n const effectData = this.effectData;\n if (effectData) {\n particlesOptions.load(effectData.particles);\n }\n const shapeData = this.shapeData;\n if (shapeData) {\n particlesOptions.load(shapeData.particles);\n }\n this.effectFill = effectData?.fill ?? particlesOptions.effect.fill;\n this.effectClose = effectData?.close ?? particlesOptions.effect.close;\n this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;\n this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;\n this.options = particlesOptions;\n const pathOptions = this.options.move.path;\n this.pathDelay = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(pathOptions.delay.value) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.millisecondsToSeconds;\n if (pathOptions.generator) {\n this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);\n if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {\n this.pathGenerator.init(container);\n }\n }\n container.retina.initParticle(this);\n this.size = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.initParticleNumericAnimationValue)(this.options.size, pxRatio);\n this.bubble = {\n inRange: false\n };\n this.slow = {\n inRange: false,\n factor: 1\n };\n this._initPosition(position);\n this.initialVelocity = this._calculateVelocity();\n this.velocity = this.initialVelocity.copy();\n this.moveDecay = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.decayOffset - (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(this.options.move.decay);\n const particles = container.particles;\n particles.setLastZIndex(this.position.z);\n this.zIndexFactor = this.position.z / container.zLayers;\n this.sides = 24;\n let effectDrawer, shapeDrawer;\n if (this.effect) {\n effectDrawer = container.effectDrawers.get(this.effect);\n if (!effectDrawer) {\n effectDrawer = this._engine.getEffectDrawer(this.effect);\n if (effectDrawer) {\n container.effectDrawers.set(this.effect, effectDrawer);\n }\n }\n }\n if (effectDrawer?.loadEffect) {\n effectDrawer.loadEffect(this);\n }\n if (this.shape) {\n shapeDrawer = container.shapeDrawers.get(this.shape);\n if (!shapeDrawer) {\n shapeDrawer = this._engine.getShapeDrawer(this.shape);\n if (shapeDrawer) {\n container.shapeDrawers.set(this.shape, shapeDrawer);\n }\n }\n }\n if (shapeDrawer?.loadShape) {\n shapeDrawer.loadShape(this);\n }\n const sideCountFunc = shapeDrawer?.getSidesCount;\n if (sideCountFunc) {\n this.sides = sideCountFunc(this);\n }\n this.spawning = false;\n for (const updater of particles.updaters) {\n updater.init(this);\n }\n for (const mover of particles.movers) {\n mover.init(this);\n }\n effectDrawer?.particleInit?.(container, this);\n shapeDrawer?.particleInit?.(container, this);\n for (const plugin of container.plugins) {\n plugin.particleCreated?.(this);\n }\n }\n isInsideCanvas() {\n const radius = this.getRadius(),\n canvasSize = this.container.canvas.size,\n position = this.position;\n return position.x >= -radius && position.y >= -radius && position.y <= canvasSize.height + radius && position.x <= canvasSize.width + radius;\n }\n isVisible() {\n return !this.destroyed && !this.spawning && this.isInsideCanvas();\n }\n reset() {\n for (const updater of this.container.particles.updaters) {\n updater.reset?.(this);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Particle.js?\n}");
|
|
48
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Particle: () => (/* binding */ Particle)\n/* harmony export */ });\n/* harmony import */ var _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Utils/Vectors.js */ \"./dist/browser/Core/Utils/Vectors.js\");\n/* harmony import */ var _Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Utils/MathUtils.js */ \"./dist/browser/Utils/MathUtils.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../Enums/Types/EventType.js */ \"./dist/browser/Enums/Types/EventType.js\");\n/* harmony import */ var _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Enums/Directions/MoveDirection.js */ \"./dist/browser/Enums/Directions/MoveDirection.js\");\n/* harmony import */ var _Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../Enums/Modes/OutMode.js */ \"./dist/browser/Enums/Modes/OutMode.js\");\n/* harmony import */ var _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../Enums/Types/ParticleOutType.js */ \"./dist/browser/Enums/Types/ParticleOutType.js\");\n/* harmony import */ var _Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../Utils/CanvasUtils.js */ \"./dist/browser/Utils/CanvasUtils.js\");\n/* harmony import */ var _Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../Utils/ColorUtils.js */ \"./dist/browser/Utils/ColorUtils.js\");\n/* harmony import */ var _Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../Utils/OptionsUtils.js */ \"./dist/browser/Utils/OptionsUtils.js\");\n\n\n\n\n\n\n\n\n\n\n\nfunction loadEffectData(effect, effectOptions, id, reduceDuplicates) {\n const effectData = effectOptions.options[effect];\n return (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.deepExtend)({\n close: effectOptions.close,\n fill: effectOptions.fill\n }, (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(effectData, id, reduceDuplicates));\n}\nfunction loadShapeData(shape, shapeOptions, id, reduceDuplicates) {\n const shapeData = shapeOptions.options[shape];\n return (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.deepExtend)({\n close: shapeOptions.close,\n fill: shapeOptions.fill\n }, (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(shapeData, id, reduceDuplicates));\n}\nfunction fixOutMode(data) {\n if (!(0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.isInArray)(data.outMode, data.checkModes)) {\n return;\n }\n const diameter = data.radius * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double;\n if (data.coord > data.maxCoord - diameter) {\n data.setCb(-data.radius);\n } else if (data.coord < diameter) {\n data.setCb(data.radius);\n }\n}\nclass Particle {\n constructor(engine, container) {\n this.container = container;\n this._cachedOpacityData = {\n opacity: _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultOpacity,\n strokeOpacity: _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultOpacity\n };\n this._cachedPosition = _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.origin;\n this._cachedRotateData = {\n sin: 0,\n cos: 0\n };\n this._cachedTransform = {\n a: 1,\n b: 0,\n c: 0,\n d: 1\n };\n this._calcPosition = (position, zIndex) => {\n let tryCount = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultRetryCount,\n posVec = position ? _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.create(position.x, position.y, zIndex) : undefined;\n const container = this.container,\n plugins = Array.from(container.plugins),\n outModes = this.options.move.outModes,\n radius = this.getRadius(),\n canvasSize = container.canvas.size,\n abortController = new AbortController(),\n {\n signal\n } = abortController;\n while (!signal.aborted) {\n for (const plugin of plugins) {\n const pluginPos = plugin.particlePosition?.(posVec, this);\n if (pluginPos) {\n return _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);\n }\n }\n const exactPosition = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.calcExactPositionOrRandomFromSize)({\n size: canvasSize,\n position: posVec\n }),\n pos = _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.create(exactPosition.x, exactPosition.y, zIndex);\n this._fixHorizontal(pos, radius, outModes.left ?? outModes.default);\n this._fixHorizontal(pos, radius, outModes.right ?? outModes.default);\n this._fixVertical(pos, radius, outModes.top ?? outModes.default);\n this._fixVertical(pos, radius, outModes.bottom ?? outModes.default);\n let isValidPosition = true;\n for (const plugin of plugins) {\n isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;\n if (!isValidPosition) {\n break;\n }\n }\n if (isValidPosition) {\n return pos;\n }\n tryCount += _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.tryCountIncrement;\n posVec = undefined;\n }\n return posVec;\n };\n this._calculateVelocity = () => {\n const baseVelocity = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getParticleBaseVelocity)(this.direction),\n res = baseVelocity.copy(),\n moveOptions = this.options.move;\n if (moveOptions.direction === _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__.MoveDirection.inside || moveOptions.direction === _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__.MoveDirection.outside) {\n return res;\n }\n const rad = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.degToRad)((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(moveOptions.angle.value)),\n radOffset = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.degToRad)((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(moveOptions.angle.offset)),\n range = {\n left: radOffset - rad * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half,\n right: radOffset + rad * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half\n };\n if (!moveOptions.straight) {\n res.angle += (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.randomInRangeValue)((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.setRangeValue)(range.left, range.right));\n }\n if (moveOptions.random && typeof moveOptions.speed === \"number\") {\n res.length *= (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRandom)();\n }\n return res;\n };\n this._fixHorizontal = (pos, radius, outMode) => {\n fixOutMode({\n outMode,\n checkModes: [_Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_6__.OutMode.bounce],\n coord: pos.x,\n maxCoord: this.container.canvas.size.width,\n setCb: value => pos.x += value,\n radius\n });\n };\n this._fixVertical = (pos, radius, outMode) => {\n fixOutMode({\n outMode,\n checkModes: [_Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_6__.OutMode.bounce],\n coord: pos.y,\n maxCoord: this.container.canvas.size.height,\n setCb: value => pos.y += value,\n radius\n });\n };\n this._getRollColor = color => {\n if (!color || !this.roll || !this.backColor && !this.roll.alter) {\n return color;\n }\n if (!this.isShowingBack()) {\n return color;\n }\n if (this.backColor) {\n return this.backColor;\n }\n if (this.roll.alter) {\n return (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_8__.alterHsl)(color, this.roll.alter.type, this.roll.alter.value);\n }\n return color;\n };\n this._initPosition = position => {\n const container = this.container,\n zIndexValue = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(this.options.zIndex.value);\n const initialPosition = this._calcPosition(position, (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.clamp)(zIndexValue, _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.minZ, container.zLayers));\n if (!initialPosition) {\n throw new Error(\"a valid position cannot be found for particle\");\n }\n this.position = initialPosition;\n this.initialPosition = this.position.copy();\n const canvasSize = container.canvas.size;\n this.moveCenter = {\n ...(0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.getPosition)(this.options.move.center, canvasSize),\n radius: this.options.move.center.radius,\n mode: this.options.move.center.mode\n };\n this.direction = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);\n switch (this.options.move.direction) {\n case _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__.MoveDirection.inside:\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_7__.ParticleOutType.inside;\n break;\n case _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_5__.MoveDirection.outside:\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_7__.ParticleOutType.outside;\n break;\n }\n this.offset = _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n };\n this._engine = engine;\n }\n destroy(override) {\n if (this.unbreakable || this.destroyed) {\n return;\n }\n this.destroyed = true;\n this.bubble.inRange = false;\n this.slow.inRange = false;\n const container = this.container,\n pathGenerator = this.pathGenerator,\n shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;\n shapeDrawer?.particleDestroy?.(this);\n for (const plugin of container.plugins) {\n plugin.particleDestroyed?.(this, override);\n }\n for (const updater of container.particles.updaters) {\n updater.particleDestroyed?.(this, override);\n }\n pathGenerator?.reset(this);\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.particleDestroyed, {\n container: this.container,\n data: {\n particle: this\n }\n });\n }\n draw(delta) {\n const container = this.container,\n canvas = container.canvas;\n for (const plugin of container.plugins) {\n canvas.drawParticlePlugin(plugin, this, delta);\n }\n canvas.drawParticle(this, delta);\n }\n getAngle() {\n return this.rotation + (this.pathRotation ? this.velocity.angle : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultAngle);\n }\n getFillColor() {\n return this._getRollColor(this.bubble.color ?? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_9__.getHslFromAnimation)(this.color));\n }\n getMass() {\n return this.getRadius() ** _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.squareExp * Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half;\n }\n getOpacity() {\n const zIndexOptions = this.options.zIndex,\n zIndexFactor = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.zIndexFactorOffset - this.zIndexFactor,\n zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate,\n opacity = this.bubble.opacity ?? (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(this.opacity?.value ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultOpacity),\n strokeOpacity = this.strokeOpacity ?? opacity;\n this._cachedOpacityData.opacity = opacity * zOpacityFactor;\n this._cachedOpacityData.strokeOpacity = strokeOpacity * zOpacityFactor;\n return this._cachedOpacityData;\n }\n getPosition() {\n this._cachedPosition.x = this.position.x + this.offset.x;\n this._cachedPosition.y = this.position.y + this.offset.y;\n this._cachedPosition.z = this.position.z;\n return this._cachedPosition;\n }\n getRadius() {\n return this.bubble.radius ?? this.size.value;\n }\n getRotateData() {\n const angle = this.getAngle();\n this._cachedRotateData.sin = Math.sin(angle);\n this._cachedRotateData.cos = Math.cos(angle);\n return this._cachedRotateData;\n }\n getStrokeColor() {\n return this._getRollColor(this.bubble.color ?? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_9__.getHslFromAnimation)(this.strokeColor));\n }\n getTransformData(externalTransform) {\n const rotateData = this.getRotateData(),\n rotating = this.isRotating;\n this._cachedTransform.a = rotateData.cos * (externalTransform.a ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransform.a);\n this._cachedTransform.b = rotating ? rotateData.sin * (externalTransform.b ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.identity) : externalTransform.b ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransform.b;\n this._cachedTransform.c = rotating ? -rotateData.sin * (externalTransform.c ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.identity) : externalTransform.c ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransform.c;\n this._cachedTransform.d = rotateData.cos * (externalTransform.d ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultTransform.d);\n return this._cachedTransform;\n }\n init(id, position, overrideOptions, group) {\n const container = this.container;\n this.id = id;\n this.group = group;\n this.effectClose = true;\n this.effectFill = true;\n this.shapeClose = true;\n this.shapeFill = true;\n this.pathRotation = false;\n this.lastPathTime = 0;\n this.destroyed = false;\n this.unbreakable = false;\n this.isRotating = false;\n this.rotation = 0;\n this.misplaced = false;\n this.retina = {\n maxDistance: {}\n };\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_7__.ParticleOutType.normal;\n this.ignoresResizeRatio = true;\n const pxRatio = container.retina.pixelRatio,\n mainOptions = container.actualOptions,\n particlesOptions = (0,_Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_10__.loadParticlesOptions)(this._engine, container, mainOptions.particles),\n reduceDuplicates = particlesOptions.reduceDuplicates,\n effectType = particlesOptions.effect.type,\n shapeType = particlesOptions.shape.type;\n this.effect = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);\n this.shape = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);\n const effectOptions = particlesOptions.effect,\n shapeOptions = particlesOptions.shape;\n if (overrideOptions) {\n if (overrideOptions.effect?.type) {\n const overrideEffectType = overrideOptions.effect.type,\n effect = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(overrideEffectType, this.id, reduceDuplicates);\n if (effect) {\n this.effect = effect;\n effectOptions.load(overrideOptions.effect);\n }\n }\n if (overrideOptions.shape?.type) {\n const overrideShapeType = overrideOptions.shape.type,\n shape = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.itemFromSingleOrMultiple)(overrideShapeType, this.id, reduceDuplicates);\n if (shape) {\n this.shape = shape;\n shapeOptions.load(overrideOptions.shape);\n }\n }\n }\n if (this.effect === _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.randomColorValue) {\n const availableEffects = [...this.container.effectDrawers.keys()];\n this.effect = availableEffects[Math.floor((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRandom)() * availableEffects.length)];\n }\n if (this.shape === _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.randomColorValue) {\n const availableShapes = [...this.container.shapeDrawers.keys()];\n this.shape = availableShapes[Math.floor((0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRandom)() * availableShapes.length)];\n }\n this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;\n this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;\n particlesOptions.load(overrideOptions);\n const effectData = this.effectData;\n if (effectData) {\n particlesOptions.load(effectData.particles);\n }\n const shapeData = this.shapeData;\n if (shapeData) {\n particlesOptions.load(shapeData.particles);\n }\n this.effectFill = effectData?.fill ?? particlesOptions.effect.fill;\n this.effectClose = effectData?.close ?? particlesOptions.effect.close;\n this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;\n this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;\n this.options = particlesOptions;\n const pathOptions = this.options.move.path;\n this.pathDelay = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(pathOptions.delay.value) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.millisecondsToSeconds;\n if (pathOptions.generator) {\n this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);\n if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {\n this.pathGenerator.init(container);\n }\n }\n container.retina.initParticle(this);\n this.size = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.initParticleNumericAnimationValue)(this.options.size, pxRatio);\n this.bubble = {\n inRange: false\n };\n this.slow = {\n inRange: false,\n factor: 1\n };\n this._initPosition(position);\n this.initialVelocity = this._calculateVelocity();\n this.velocity = this.initialVelocity.copy();\n this.moveDecay = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.decayOffset - (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(this.options.move.decay);\n const particles = container.particles;\n particles.setLastZIndex(this.position.z);\n this.zIndexFactor = this.position.z / container.zLayers;\n this.sides = 24;\n let effectDrawer, shapeDrawer;\n if (this.effect) {\n effectDrawer = container.effectDrawers.get(this.effect);\n if (!effectDrawer) {\n effectDrawer = this._engine.getEffectDrawer(this.effect);\n if (effectDrawer) {\n container.effectDrawers.set(this.effect, effectDrawer);\n }\n }\n }\n if (effectDrawer?.loadEffect) {\n effectDrawer.loadEffect(this);\n }\n if (this.shape) {\n shapeDrawer = container.shapeDrawers.get(this.shape);\n if (!shapeDrawer) {\n shapeDrawer = this._engine.getShapeDrawer(this.shape);\n if (shapeDrawer) {\n container.shapeDrawers.set(this.shape, shapeDrawer);\n }\n }\n }\n if (shapeDrawer?.loadShape) {\n shapeDrawer.loadShape(this);\n }\n const sideCountFunc = shapeDrawer?.getSidesCount;\n if (sideCountFunc) {\n this.sides = sideCountFunc(this);\n }\n this.spawning = false;\n for (const updater of particles.updaters) {\n updater.init(this);\n }\n for (const mover of particles.movers) {\n mover.init(this);\n }\n effectDrawer?.particleInit?.(container, this);\n shapeDrawer?.particleInit?.(container, this);\n for (const plugin of container.plugins) {\n plugin.particleCreated?.(this);\n }\n }\n isInsideCanvas() {\n const radius = this.getRadius(),\n canvasSize = this.container.canvas.size,\n position = this.position;\n return position.x >= -radius && position.y >= -radius && position.y <= canvasSize.height + radius && position.x <= canvasSize.width + radius;\n }\n isShowingBack() {\n if (!this.roll) {\n return false;\n }\n const angle = this.roll.angle;\n if (this.roll.horizontal && this.roll.vertical) {\n const normalizedAngle = angle % _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.doublePI,\n adjustedAngle = normalizedAngle < _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultAngle ? normalizedAngle + _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.doublePI : normalizedAngle;\n return adjustedAngle >= Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half && adjustedAngle < Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.triple * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half;\n }\n if (this.roll.horizontal) {\n const normalizedAngle = (angle + Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.half) % (Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double),\n adjustedAngle = normalizedAngle < _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultAngle ? normalizedAngle + Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double : normalizedAngle;\n return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double;\n }\n if (this.roll.vertical) {\n const normalizedAngle = angle % (Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double),\n adjustedAngle = normalizedAngle < _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultAngle ? normalizedAngle + Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double : normalizedAngle;\n return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.double;\n }\n return false;\n }\n isVisible() {\n return !this.destroyed && !this.spawning && this.isInsideCanvas();\n }\n reset() {\n for (const updater of this.container.particles.updaters) {\n updater.reset?.(this);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Particle.js?\n}");
|
|
49
49
|
|
|
50
50
|
/***/ },
|
|
51
51
|
|
package/esm/Core/Canvas.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clear,
|
|
1
|
+
import { clear, drawParticle, drawParticlePlugin, paintBase, paintImage } from "../Utils/CanvasUtils.js";
|
|
2
2
|
import { cloneStyle, getFullScreenStyle, safeMatchMedia, safeMutationObserver } from "../Utils/Utils.js";
|
|
3
3
|
import { defaultTransformValue, generatedAttribute, minimumSize, zIndexFactorOffset } from "./Utils/Constants.js";
|
|
4
4
|
import { getStyleFromHsl, getStyleFromRgb, rangeColorToHsl, rangeColorToRgb } from "../Utils/ColorUtils.js";
|
|
@@ -194,11 +194,6 @@ export class Canvas {
|
|
|
194
194
|
}
|
|
195
195
|
this.canvasClear();
|
|
196
196
|
}
|
|
197
|
-
clearDrawPlugin(plugin, delta) {
|
|
198
|
-
this.draw(ctx => {
|
|
199
|
-
clearDrawPlugin(ctx, plugin, delta);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
197
|
destroy() {
|
|
203
198
|
this.stop();
|
|
204
199
|
if (this._generated) {
|
|
@@ -241,6 +236,11 @@ export class Canvas {
|
|
|
241
236
|
colorStyles.fill = fill;
|
|
242
237
|
colorStyles.stroke = stroke;
|
|
243
238
|
this.draw((context) => {
|
|
239
|
+
for (const plugin of container.plugins) {
|
|
240
|
+
if (plugin.drawParticleSetup) {
|
|
241
|
+
plugin.drawParticleSetup(context, particle, delta);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
244
|
this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
245
245
|
drawParticle({
|
|
246
246
|
container,
|
|
@@ -252,8 +252,13 @@ export class Canvas {
|
|
|
252
252
|
opacity: opacity,
|
|
253
253
|
transform,
|
|
254
254
|
});
|
|
255
|
+
this._applyPostDrawUpdaters(particle);
|
|
256
|
+
for (const plugin of container.plugins) {
|
|
257
|
+
if (plugin.drawParticleCleanup) {
|
|
258
|
+
plugin.drawParticleCleanup(context, particle, delta);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
255
261
|
});
|
|
256
|
-
this._applyPostDrawUpdaters(particle);
|
|
257
262
|
}
|
|
258
263
|
drawParticlePlugin(plugin, particle, delta) {
|
|
259
264
|
this.draw(ctx => {
|
|
@@ -264,19 +269,20 @@ export class Canvas {
|
|
|
264
269
|
const { particles, plugins } = this.container;
|
|
265
270
|
this.clear();
|
|
266
271
|
particles.update(delta);
|
|
267
|
-
for (const plugin of plugins.values()) {
|
|
268
|
-
this.drawPlugin(plugin, delta);
|
|
269
|
-
}
|
|
270
|
-
this.draw(() => {
|
|
271
|
-
particles.drawParticles(delta);
|
|
272
|
-
});
|
|
273
|
-
for (const plugin of plugins.values()) {
|
|
274
|
-
this.clearDrawPlugin(plugin, delta);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
drawPlugin(plugin, delta) {
|
|
278
272
|
this.draw(ctx => {
|
|
279
|
-
|
|
273
|
+
for (const plugin of plugins) {
|
|
274
|
+
plugin.drawSettingsSetup?.(ctx, delta);
|
|
275
|
+
}
|
|
276
|
+
for (const plugin of plugins) {
|
|
277
|
+
plugin.draw?.(ctx, delta);
|
|
278
|
+
}
|
|
279
|
+
particles.drawParticles(delta);
|
|
280
|
+
for (const plugin of plugins) {
|
|
281
|
+
plugin.clearDraw?.(ctx, delta);
|
|
282
|
+
}
|
|
283
|
+
for (const plugin of plugins) {
|
|
284
|
+
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
285
|
+
}
|
|
280
286
|
});
|
|
281
287
|
}
|
|
282
288
|
init() {
|