@tsparticles/engine 4.0.0-alpha.1 → 4.0.0-alpha.3
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/638.min.js +1 -1
- package/638.min.js.LICENSE.txt +1 -1
- package/browser/Core/Canvas.js +15 -19
- package/browser/Core/Container.js +10 -15
- package/browser/Core/Engine.js +34 -14
- package/browser/Core/Interfaces/IParticleOpacityData.js +1 -0
- package/browser/Core/Interfaces/IParticleRotateData.js +1 -0
- package/browser/Core/Particle.js +95 -49
- package/browser/Utils/CanvasUtils.js +26 -83
- package/browser/Utils/ColorUtils.js +15 -2
- package/browser/Utils/MathUtils.js +3 -2
- package/browser/Utils/Utils.js +1 -1
- package/cjs/Core/Canvas.js +15 -19
- package/cjs/Core/Container.js +10 -15
- package/cjs/Core/Engine.js +34 -14
- package/cjs/Core/Interfaces/IParticleOpacityData.js +1 -0
- package/cjs/Core/Interfaces/IParticleRotateData.js +1 -0
- package/cjs/Core/Particle.js +95 -49
- package/cjs/Utils/CanvasUtils.js +26 -83
- package/cjs/Utils/ColorUtils.js +15 -2
- package/cjs/Utils/MathUtils.js +3 -2
- package/cjs/Utils/Utils.js +1 -1
- package/dist_browser_Core_Container_js.js +4 -4
- package/esm/Core/Canvas.js +15 -19
- package/esm/Core/Container.js +10 -15
- package/esm/Core/Engine.js +34 -14
- package/esm/Core/Interfaces/IParticleOpacityData.js +1 -0
- package/esm/Core/Interfaces/IParticleRotateData.js +1 -0
- package/esm/Core/Particle.js +95 -49
- package/esm/Utils/CanvasUtils.js +26 -83
- package/esm/Utils/ColorUtils.js +15 -2
- package/esm/Utils/MathUtils.js +3 -2
- package/esm/Utils/Utils.js +1 -1
- package/package.json +1 -1
- package/report.html +1 -1
- package/scripts/install.js +28 -9
- package/tsparticles.engine.js +6 -6
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +3 -0
- package/types/Core/Container.d.ts +1 -0
- package/types/Core/Engine.d.ts +1 -1
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +1 -1
- package/types/Core/Interfaces/IParticleOpacityData.d.ts +4 -0
- package/types/Core/Interfaces/IParticleRotateData.d.ts +4 -0
- package/types/Core/Interfaces/IParticleTransformValues.d.ts +4 -4
- package/types/Core/Interfaces/IParticleUpdater.d.ts +1 -1
- package/types/Core/Particle.d.ts +12 -0
- package/types/Types/CustomEventListener.d.ts +1 -1
- package/types/Utils/CanvasUtils.d.ts +6 -21
- package/types/Utils/EventDispatcher.d.ts +1 -1
- package/umd/Core/Canvas.js +14 -18
- package/umd/Core/Container.js +10 -15
- package/umd/Core/Engine.js +34 -14
- package/umd/Core/Interfaces/IParticleOpacityData.js +12 -0
- package/umd/Core/Interfaces/IParticleRotateData.js +12 -0
- package/umd/Core/Particle.js +94 -48
- package/umd/Utils/CanvasUtils.js +25 -82
- package/umd/Utils/ColorUtils.js +15 -2
- package/umd/Utils/MathUtils.js +3 -2
- package/umd/Utils/Utils.js +1 -1
package/cjs/Utils/CanvasUtils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lFactor, minStrokeWidth, originPoint } from "../Core/Utils/Constants.js";
|
|
2
2
|
import { AlterType } from "../Enums/Types/AlterType.js";
|
|
3
3
|
export function clearDrawPlugin(context, plugin, delta) {
|
|
4
4
|
if (!plugin.clearDraw) {
|
|
@@ -28,15 +28,7 @@ export function clear(context, dimension) {
|
|
|
28
28
|
context.clearRect(originPoint.x, originPoint.y, dimension.width, dimension.height);
|
|
29
29
|
}
|
|
30
30
|
export function drawParticle(data) {
|
|
31
|
-
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, pos = particle.getPosition(),
|
|
32
|
-
sin: Math.sin(angle),
|
|
33
|
-
cos: Math.cos(angle),
|
|
34
|
-
}, rotating = particle.isRotating, transformData = {
|
|
35
|
-
a: rotateData.cos * (transform.a ?? defaultTransform.a),
|
|
36
|
-
b: rotating ? rotateData.sin * (transform.b ?? identity) : (transform.b ?? defaultTransform.b),
|
|
37
|
-
c: rotating ? -rotateData.sin * (transform.c ?? identity) : (transform.c ?? defaultTransform.c),
|
|
38
|
-
d: rotateData.cos * (transform.d ?? defaultTransform.d),
|
|
39
|
-
};
|
|
31
|
+
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, pos = particle.getPosition(), transformData = particle.getTransformData(transform);
|
|
40
32
|
context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
|
|
41
33
|
if (colorStyles.fill) {
|
|
42
34
|
context.fillStyle = colorStyles.fill;
|
|
@@ -47,24 +39,25 @@ export function drawParticle(data) {
|
|
|
47
39
|
context.strokeStyle = colorStyles.stroke;
|
|
48
40
|
}
|
|
49
41
|
const drawData = {
|
|
50
|
-
container,
|
|
51
42
|
context,
|
|
52
43
|
particle,
|
|
53
44
|
radius,
|
|
54
45
|
opacity,
|
|
55
46
|
delta,
|
|
47
|
+
pixelRatio: container.retina.pixelRatio,
|
|
48
|
+
fill: particle.shapeFill,
|
|
49
|
+
stroke: strokeWidth > minStrokeWidth || !particle.shapeFill,
|
|
56
50
|
transformData,
|
|
57
|
-
strokeWidth,
|
|
58
51
|
};
|
|
59
|
-
drawBeforeEffect(drawData);
|
|
60
|
-
drawShapeBeforeDraw(drawData);
|
|
61
|
-
drawShape(drawData);
|
|
62
|
-
drawShapeAfterDraw(drawData);
|
|
63
|
-
drawAfterEffect(drawData);
|
|
52
|
+
drawBeforeEffect(container, drawData);
|
|
53
|
+
drawShapeBeforeDraw(container, drawData);
|
|
54
|
+
drawShape(container, drawData);
|
|
55
|
+
drawShapeAfterDraw(container, drawData);
|
|
56
|
+
drawAfterEffect(container, drawData);
|
|
64
57
|
context.resetTransform();
|
|
65
58
|
}
|
|
66
|
-
export function drawAfterEffect(data) {
|
|
67
|
-
const {
|
|
59
|
+
export function drawAfterEffect(container, data) {
|
|
60
|
+
const { particle } = data;
|
|
68
61
|
if (!particle.effect) {
|
|
69
62
|
return;
|
|
70
63
|
}
|
|
@@ -72,20 +65,10 @@ export function drawAfterEffect(data) {
|
|
|
72
65
|
if (!drawFunc) {
|
|
73
66
|
return;
|
|
74
67
|
}
|
|
75
|
-
drawFunc(
|
|
76
|
-
context,
|
|
77
|
-
particle,
|
|
78
|
-
radius,
|
|
79
|
-
opacity,
|
|
80
|
-
delta,
|
|
81
|
-
pixelRatio: container.retina.pixelRatio,
|
|
82
|
-
fill: particle.shapeFill,
|
|
83
|
-
stroke: strokeWidth > minStrokeWidth || !particle.shapeFill,
|
|
84
|
-
transformData: { ...transformData },
|
|
85
|
-
});
|
|
68
|
+
drawFunc(data);
|
|
86
69
|
}
|
|
87
|
-
export function drawBeforeEffect(data) {
|
|
88
|
-
const {
|
|
70
|
+
export function drawBeforeEffect(container, data) {
|
|
71
|
+
const { particle } = data;
|
|
89
72
|
if (!particle.effect) {
|
|
90
73
|
return;
|
|
91
74
|
}
|
|
@@ -93,20 +76,10 @@ export function drawBeforeEffect(data) {
|
|
|
93
76
|
if (!drawer?.drawBefore) {
|
|
94
77
|
return;
|
|
95
78
|
}
|
|
96
|
-
drawer.drawBefore(
|
|
97
|
-
context,
|
|
98
|
-
particle,
|
|
99
|
-
radius,
|
|
100
|
-
opacity,
|
|
101
|
-
delta,
|
|
102
|
-
pixelRatio: container.retina.pixelRatio,
|
|
103
|
-
fill: particle.shapeFill,
|
|
104
|
-
stroke: strokeWidth > minStrokeWidth || !particle.shapeFill,
|
|
105
|
-
transformData: { ...transformData },
|
|
106
|
-
});
|
|
79
|
+
drawer.drawBefore(data);
|
|
107
80
|
}
|
|
108
|
-
export function drawShape(data) {
|
|
109
|
-
const {
|
|
81
|
+
export function drawShape(container, data) {
|
|
82
|
+
const { context, particle, stroke } = data;
|
|
110
83
|
if (!particle.shape) {
|
|
111
84
|
return;
|
|
112
85
|
}
|
|
@@ -115,29 +88,19 @@ export function drawShape(data) {
|
|
|
115
88
|
return;
|
|
116
89
|
}
|
|
117
90
|
context.beginPath();
|
|
118
|
-
drawer.draw(
|
|
119
|
-
context,
|
|
120
|
-
particle,
|
|
121
|
-
radius,
|
|
122
|
-
opacity,
|
|
123
|
-
delta,
|
|
124
|
-
pixelRatio: container.retina.pixelRatio,
|
|
125
|
-
fill: particle.shapeFill,
|
|
126
|
-
stroke: strokeWidth > minStrokeWidth || !particle.shapeFill,
|
|
127
|
-
transformData: { ...transformData },
|
|
128
|
-
});
|
|
91
|
+
drawer.draw(data);
|
|
129
92
|
if (particle.shapeClose) {
|
|
130
93
|
context.closePath();
|
|
131
94
|
}
|
|
132
|
-
if (
|
|
95
|
+
if (stroke) {
|
|
133
96
|
context.stroke();
|
|
134
97
|
}
|
|
135
98
|
if (particle.shapeFill) {
|
|
136
99
|
context.fill();
|
|
137
100
|
}
|
|
138
101
|
}
|
|
139
|
-
export function drawShapeAfterDraw(data) {
|
|
140
|
-
const {
|
|
102
|
+
export function drawShapeAfterDraw(container, data) {
|
|
103
|
+
const { particle } = data;
|
|
141
104
|
if (!particle.shape) {
|
|
142
105
|
return;
|
|
143
106
|
}
|
|
@@ -145,20 +108,10 @@ export function drawShapeAfterDraw(data) {
|
|
|
145
108
|
if (!drawer?.afterDraw) {
|
|
146
109
|
return;
|
|
147
110
|
}
|
|
148
|
-
drawer.afterDraw(
|
|
149
|
-
context,
|
|
150
|
-
particle,
|
|
151
|
-
radius,
|
|
152
|
-
opacity,
|
|
153
|
-
delta,
|
|
154
|
-
pixelRatio: container.retina.pixelRatio,
|
|
155
|
-
fill: particle.shapeFill,
|
|
156
|
-
stroke: strokeWidth > minStrokeWidth || !particle.shapeFill,
|
|
157
|
-
transformData: { ...transformData },
|
|
158
|
-
});
|
|
111
|
+
drawer.afterDraw(data);
|
|
159
112
|
}
|
|
160
|
-
export function drawShapeBeforeDraw(data) {
|
|
161
|
-
const {
|
|
113
|
+
export function drawShapeBeforeDraw(container, data) {
|
|
114
|
+
const { particle } = data;
|
|
162
115
|
if (!particle.shape) {
|
|
163
116
|
return;
|
|
164
117
|
}
|
|
@@ -166,17 +119,7 @@ export function drawShapeBeforeDraw(data) {
|
|
|
166
119
|
if (!drawer?.beforeDraw) {
|
|
167
120
|
return;
|
|
168
121
|
}
|
|
169
|
-
drawer.beforeDraw(
|
|
170
|
-
context,
|
|
171
|
-
particle,
|
|
172
|
-
radius,
|
|
173
|
-
opacity,
|
|
174
|
-
delta,
|
|
175
|
-
pixelRatio: container.retina.pixelRatio,
|
|
176
|
-
fill: particle.shapeFill,
|
|
177
|
-
stroke: strokeWidth > minStrokeWidth || !particle.shapeFill,
|
|
178
|
-
transformData: { ...transformData },
|
|
179
|
-
});
|
|
122
|
+
drawer.beforeDraw(data);
|
|
180
123
|
}
|
|
181
124
|
export function drawPlugin(context, plugin, delta) {
|
|
182
125
|
if (!plugin.draw) {
|
package/cjs/Utils/ColorUtils.js
CHANGED
|
@@ -3,6 +3,17 @@ import { decayOffset, defaultLoops, defaultOpacity, defaultRgbMin, defaultTime,
|
|
|
3
3
|
import { isArray, isString } from "./TypeUtils.js";
|
|
4
4
|
import { AnimationStatus } from "../Enums/AnimationStatus.js";
|
|
5
5
|
import { itemFromArray } from "./Utils.js";
|
|
6
|
+
const styleCache = new Map(), maxCacheSize = 1000;
|
|
7
|
+
function getCachedStyle(key, generator) {
|
|
8
|
+
let cached = styleCache.get(key);
|
|
9
|
+
if (!cached) {
|
|
10
|
+
cached = generator();
|
|
11
|
+
if (styleCache.size < maxCacheSize) {
|
|
12
|
+
styleCache.set(key, cached);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return cached;
|
|
16
|
+
}
|
|
6
17
|
function stringToRgba(engine, input) {
|
|
7
18
|
if (!input) {
|
|
8
19
|
return;
|
|
@@ -155,7 +166,8 @@ export function getRandomRgbColor(min) {
|
|
|
155
166
|
};
|
|
156
167
|
}
|
|
157
168
|
export function getStyleFromRgb(color, hdr, opacity) {
|
|
158
|
-
|
|
169
|
+
const op = opacity ?? defaultOpacity, key = `rgb-${color.r.toString()}-${color.g.toString()}-${color.b.toString()}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
|
|
170
|
+
return getCachedStyle(key, () => (hdr ? getHdrStyleFromRgb(color, opacity) : getSdrStyleFromRgb(color, opacity)));
|
|
159
171
|
}
|
|
160
172
|
function getHdrStyleFromRgb(color, opacity) {
|
|
161
173
|
return `color(display-p3 ${(color.r / rgbMax).toString()} ${(color.g / rgbMax).toString()} ${(color.b / rgbMax).toString()} / ${(opacity ?? defaultOpacity).toString()})`;
|
|
@@ -164,7 +176,8 @@ function getSdrStyleFromRgb(color, opacity) {
|
|
|
164
176
|
return `rgba(${color.r.toString()}, ${color.g.toString()}, ${color.b.toString()}, ${(opacity ?? defaultOpacity).toString()})`;
|
|
165
177
|
}
|
|
166
178
|
export function getStyleFromHsl(color, hdr, opacity) {
|
|
167
|
-
|
|
179
|
+
const op = opacity ?? defaultOpacity, key = `hsl-${color.h.toString()}-${color.s.toString()}-${color.l.toString()}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
|
|
180
|
+
return getCachedStyle(key, () => (hdr ? getHdrStyleFromHsl(color, opacity) : getSdrStyleFromHsl(color, opacity)));
|
|
168
181
|
}
|
|
169
182
|
function getHdrStyleFromHsl(color, opacity) {
|
|
170
183
|
return getHdrStyleFromRgb(hslToRgb(color), opacity);
|
package/cjs/Utils/MathUtils.js
CHANGED
|
@@ -137,9 +137,10 @@ export function calcPositionOrRandomFromSizeRanged(data) {
|
|
|
137
137
|
return calcPositionOrRandomFromSize({ size: data.size, position });
|
|
138
138
|
}
|
|
139
139
|
export function calcExactPositionOrRandomFromSize(data) {
|
|
140
|
+
const { position, size } = data;
|
|
140
141
|
return {
|
|
141
|
-
x:
|
|
142
|
-
y:
|
|
142
|
+
x: position?.x ?? getRandom() * size.width,
|
|
143
|
+
y: position?.y ?? getRandom() * size.height,
|
|
143
144
|
};
|
|
144
145
|
}
|
|
145
146
|
export function calcExactPositionOrRandomFromSizeRanged(data) {
|
package/cjs/Utils/Utils.js
CHANGED
|
@@ -328,7 +328,7 @@ export function cloneStyle(style) {
|
|
|
328
328
|
const clonedStyle = safeDocument().createElement("div").style;
|
|
329
329
|
for (const key in style) {
|
|
330
330
|
const styleKey = style[key];
|
|
331
|
-
if (!Object.
|
|
331
|
+
if (!Object.hasOwn(style, key) || isNull(styleKey)) {
|
|
332
332
|
continue;
|
|
333
333
|
}
|
|
334
334
|
const styleValue = style.getPropertyValue?.(styleKey);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* tsParticles Engine v4.0.0-alpha.
|
|
2
|
+
* tsParticles Engine v4.0.0-alpha.3
|
|
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\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._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 return [fColor, sColor];\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.prototype.hasOwnProperty.call(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.values()) {\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 zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate,\n opacity = particle.bubble.opacity ?? particle.opacity?.value ?? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultOpacity,\n strokeOpacity = particle.strokeOpacity ?? opacity,\n zOpacity = opacity * zOpacityFactor,\n zStrokeOpacity = strokeOpacity * zOpacityFactor,\n transform = {},\n getFillStyle = () => {\n if (!fColor) {\n return;\n }\n return (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.getStyleFromHsl)(fColor, container.hdr, zOpacity);\n },\n colorStyles = {\n fill: getFillStyle()\n },\n getStrokestyle = () => {\n if (!sColor) {\n return colorStyles.fill;\n }\n return (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_3__.getStyleFromHsl)(sColor, container.hdr, zStrokeOpacity);\n };\n colorStyles.stroke = getStrokestyle();\n this.draw(context => {\n this._applyPreDrawUpdaters(context, particle, radius, zOpacity, 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: zOpacity,\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.values()) {\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.values()) {\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.values()) {\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.values()) {\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.values()) {\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
|
|
|
@@ -35,7 +35,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
35
35
|
\****************************************/
|
|
36
36
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
37
37
|
|
|
38
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Container: () => (/* binding */ Container)\n/* harmony export */ });\n/* harmony import */ var _Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Utils/MathUtils.js */ \"./dist/browser/Utils/MathUtils.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n/* harmony import */ var _Canvas_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Canvas.js */ \"./dist/browser/Core/Canvas.js\");\n/* harmony import */ var _Utils_EventListeners_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Utils/EventListeners.js */ \"./dist/browser/Core/Utils/EventListeners.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 _Options_Classes_Options_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Options/Classes/Options.js */ \"./dist/browser/Options/Classes/Options.js\");\n/* harmony import */ var _Particles_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Particles.js */ \"./dist/browser/Core/Particles.js\");\n/* harmony import */ var _Retina_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Retina.js */ \"./dist/browser/Core/Retina.js\");\n/* harmony import */ var _Utils_LogUtils_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../Utils/LogUtils.js */ \"./dist/browser/Utils/LogUtils.js\");\n/* harmony import */ var _Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../Utils/OptionsUtils.js */ \"./dist/browser/Utils/OptionsUtils.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n\n\n\n\n\n\n\n\n\n\n\nfunction guardCheck(container) {\n return !container.destroyed;\n}\nfunction initDelta(value, fpsLimit = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.defaultFps, smooth = false) {\n return {\n value,\n factor: smooth ? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.defaultFps / fpsLimit : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.defaultFps * value / _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds\n };\n}\nfunction loadContainerOptions(engine, container, ...sourceOptionsArr) {\n const options = new _Options_Classes_Options_js__WEBPACK_IMPORTED_MODULE_5__.Options(engine, container);\n (0,_Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_9__.loadOptions)(options, ...sourceOptionsArr);\n return options;\n}\nclass Container {\n constructor(engine, id, sourceOptions) {\n this._intersectionManager = entries => {\n if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {\n return;\n }\n for (const entry of entries) {\n if (entry.target !== this.interactivity.element) {\n continue;\n }\n if (entry.isIntersecting) {\n this.play();\n } else {\n this.pause();\n }\n }\n };\n this._nextFrame = timestamp => {\n try {\n if (!this._smooth && this._lastFrameTime !== undefined && timestamp < this._lastFrameTime + _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds / this.fpsLimit) {\n this.draw(false);\n return;\n }\n this._lastFrameTime ??= timestamp;\n const delta = initDelta(timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);\n this.addLifeTime(delta.value);\n this._lastFrameTime = timestamp;\n if (delta.value > _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds) {\n this.draw(false);\n return;\n }\n this.canvas.drawParticles(delta);\n if (!this.alive()) {\n this.destroy();\n return;\n }\n if (this.animationStatus) {\n this.draw(false);\n }\n } catch (e) {\n (0,_Utils_LogUtils_js__WEBPACK_IMPORTED_MODULE_8__.getLogger)().error(\"error in animation loop\", e);\n }\n };\n this._engine = engine;\n this.id = Symbol(id);\n this.fpsLimit = 120;\n this.hdr = false;\n this._smooth = false;\n this._delay = 0;\n this._duration = 0;\n this._lifeTime = 0;\n this._firstStart = true;\n this.started = false;\n this.destroyed = false;\n this._paused = true;\n this._lastFrameTime = 0;\n this.zLayers = 100;\n this.pageHidden = false;\n this._clickHandlers = new Map();\n this._sourceOptions = sourceOptions;\n this._initialSourceOptions = sourceOptions;\n this.retina = new _Retina_js__WEBPACK_IMPORTED_MODULE_7__.Retina(this);\n this.canvas = new _Canvas_js__WEBPACK_IMPORTED_MODULE_2__.Canvas(this, this._engine);\n this.particles = new _Particles_js__WEBPACK_IMPORTED_MODULE_6__.Particles(this._engine, this);\n this.pathGenerators = new Map();\n this.interactivity = {\n mouse: {\n clicking: false,\n inside: false\n }\n };\n this.plugins = new Map();\n this.effectDrawers = new Map();\n this.shapeDrawers = new Map();\n this._options = loadContainerOptions(this._engine, this);\n this.actualOptions = loadContainerOptions(this._engine, this);\n this._eventListeners = new _Utils_EventListeners_js__WEBPACK_IMPORTED_MODULE_3__.EventListeners(this);\n this._intersectionObserver = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_10__.safeIntersectionObserver)(entries => {\n this._intersectionManager(entries);\n });\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerBuilt, {\n container: this\n });\n }\n get animationStatus() {\n return !this._paused && !this.pageHidden && guardCheck(this);\n }\n get options() {\n return this._options;\n }\n get sourceOptions() {\n return this._sourceOptions;\n }\n addClickHandler(callback) {\n if (!guardCheck(this)) {\n return;\n }\n const el = this.interactivity.element;\n if (!el) {\n return;\n }\n const clickOrTouchHandler = (e, pos, radius) => {\n if (!guardCheck(this)) {\n return;\n }\n const pxRatio = this.retina.pixelRatio,\n posRetina = {\n x: pos.x * pxRatio,\n y: pos.y * pxRatio\n },\n particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);\n callback(e, particles);\n },\n clickHandler = e => {\n if (!guardCheck(this)) {\n return;\n }\n const mouseEvent = e,\n pos = {\n x: mouseEvent.offsetX || mouseEvent.clientX,\n y: mouseEvent.offsetY || mouseEvent.clientY\n };\n clickOrTouchHandler(e, pos, _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.clickRadius);\n },\n touchStartHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touched = true;\n touchMoved = false;\n },\n touchMoveHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touchMoved = true;\n },\n touchEndHandler = e => {\n if (!guardCheck(this)) {\n return;\n }\n if (touched && !touchMoved) {\n const touchEvent = e,\n lastTouch = touchEvent.touches[touchEvent.touches.length - _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.touchEndLengthOffset];\n if (!lastTouch) {\n return;\n }\n const element = this.canvas.element,\n canvasRect = element ? element.getBoundingClientRect() : undefined,\n pos = {\n x: lastTouch.clientX - (canvasRect ? canvasRect.left : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.minCoordinate),\n y: lastTouch.clientY - (canvasRect ? canvasRect.top : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.minCoordinate)\n };\n clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));\n }\n touched = false;\n touchMoved = false;\n },\n touchCancelHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touched = false;\n touchMoved = false;\n };\n let touched = false,\n touchMoved = false;\n this._clickHandlers.set(\"click\", clickHandler);\n this._clickHandlers.set(\"touchstart\", touchStartHandler);\n this._clickHandlers.set(\"touchmove\", touchMoveHandler);\n this._clickHandlers.set(\"touchend\", touchEndHandler);\n this._clickHandlers.set(\"touchcancel\", touchCancelHandler);\n for (const [key, handler] of this._clickHandlers) {\n el.addEventListener(key, handler);\n }\n }\n addLifeTime(value) {\n this._lifeTime += value;\n }\n addPath(key, generator, override = false) {\n if (!guardCheck(this) || !override && this.pathGenerators.has(key)) {\n return false;\n }\n this.pathGenerators.set(key, generator);\n return true;\n }\n alive() {\n return !this._duration || this._lifeTime <= this._duration;\n }\n clearClickHandlers() {\n if (!guardCheck(this)) {\n return;\n }\n for (const [key, handler] of this._clickHandlers) {\n this.interactivity.element?.removeEventListener(key, handler);\n }\n this._clickHandlers.clear();\n }\n destroy(remove = true) {\n if (!guardCheck(this)) {\n return;\n }\n this.stop();\n this.clearClickHandlers();\n this.particles.destroy();\n this.canvas.destroy();\n for (const effectDrawer of this.effectDrawers.values()) {\n effectDrawer.destroy?.(this);\n }\n for (const shapeDrawer of this.shapeDrawers.values()) {\n shapeDrawer.destroy?.(this);\n }\n for (const key of this.effectDrawers.keys()) {\n this.effectDrawers.delete(key);\n }\n for (const key of this.shapeDrawers.keys()) {\n this.shapeDrawers.delete(key);\n }\n this._engine.clearPlugins(this);\n this.destroyed = true;\n if (remove) {\n const mainArr = this._engine.items,\n idx = mainArr.findIndex(t => t === this);\n if (idx >= _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.removeMinIndex) {\n mainArr.splice(idx, _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.removeDeleteCount);\n }\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerDestroyed, {\n container: this\n });\n }\n draw(force) {\n if (!guardCheck(this)) {\n return;\n }\n let refreshTime = force;\n const frame = timestamp => {\n if (refreshTime) {\n this._lastFrameTime = undefined;\n refreshTime = false;\n }\n this._nextFrame(timestamp);\n };\n this._drawAnimationFrame = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__.animate)(timestamp => {\n frame(timestamp);\n });\n }\n async export(type, options = {}) {\n for (const plugin of this.plugins.values()) {\n if (!plugin.export) {\n continue;\n }\n const res = await plugin.export(type, options);\n if (!res.supported) {\n continue;\n }\n return res.blob;\n }\n (0,_Utils_LogUtils_js__WEBPACK_IMPORTED_MODULE_8__.getLogger)().error(`Export plugin with type ${type} not found`);\n return undefined;\n }\n handleClickMode(mode) {\n if (!guardCheck(this)) {\n return;\n }\n this.particles.handleClickMode(mode);\n for (const plugin of this.plugins.values()) {\n plugin.handleClickMode?.(mode);\n }\n }\n async init() {\n if (!guardCheck(this)) {\n return;\n }\n const effects = this._engine.getSupportedEffects();\n for (const type of effects) {\n const drawer = this._engine.getEffectDrawer(type);\n if (drawer) {\n this.effectDrawers.set(type, drawer);\n }\n }\n const shapes = this._engine.getSupportedShapes();\n for (const type of shapes) {\n const drawer = this._engine.getShapeDrawer(type);\n if (drawer) {\n this.shapeDrawers.set(type, drawer);\n }\n }\n await this.particles.initPlugins();\n this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);\n this.actualOptions = loadContainerOptions(this._engine, this, this._options);\n const availablePlugins = await this._engine.getAvailablePlugins(this);\n for (const [id, plugin] of availablePlugins) {\n this.plugins.set(id, plugin);\n }\n this.retina.init();\n this.canvas.init();\n this.updateActualOptions();\n this.canvas.initBackground();\n this.canvas.resize();\n const {\n delay,\n duration,\n fpsLimit,\n hdr,\n smooth,\n zLayers\n } = this.actualOptions;\n this.hdr = hdr;\n this.zLayers = zLayers;\n this._duration = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(duration) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds;\n this._delay = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(delay) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds;\n this._lifeTime = 0;\n this.fpsLimit = fpsLimit > _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.minFpsLimit ? fpsLimit : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.defaultFpsLimit;\n this._smooth = smooth;\n for (const drawer of this.effectDrawers.values()) {\n await drawer.init?.(this);\n }\n for (const drawer of this.shapeDrawers.values()) {\n await drawer.init?.(this);\n }\n for (const plugin of this.plugins.values()) {\n await plugin.init?.();\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerInit, {\n container: this\n });\n await this.particles.init();\n this.particles.setDensity();\n for (const plugin of this.plugins.values()) {\n plugin.particlesSetup?.();\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.particlesSetup, {\n container: this\n });\n }\n async loadTheme(name) {\n if (!guardCheck(this)) {\n return;\n }\n this._currentTheme = name;\n await this.refresh();\n }\n pause() {\n if (!guardCheck(this)) {\n return;\n }\n if (this._drawAnimationFrame !== undefined) {\n (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__.cancelAnimation)(this._drawAnimationFrame);\n delete this._drawAnimationFrame;\n }\n if (this._paused) {\n return;\n }\n for (const plugin of this.plugins.values()) {\n plugin.pause?.();\n }\n if (!this.pageHidden) {\n this._paused = true;\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerPaused, {\n container: this\n });\n }\n play(force) {\n if (!guardCheck(this)) {\n return;\n }\n const needsUpdate = this._paused || force;\n if (this._firstStart && !this.actualOptions.autoPlay) {\n this._firstStart = false;\n return;\n }\n if (this._paused) {\n this._paused = false;\n }\n if (needsUpdate) {\n for (const plugin of this.plugins.values()) {\n if (plugin.play) {\n plugin.play();\n }\n }\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerPlay, {\n container: this\n });\n this.draw(needsUpdate ?? false);\n }\n async refresh() {\n if (!guardCheck(this)) {\n return;\n }\n this.stop();\n return this.start();\n }\n async reset(sourceOptions) {\n if (!guardCheck(this)) {\n return;\n }\n this._initialSourceOptions = sourceOptions;\n this._sourceOptions = sourceOptions;\n this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);\n this.actualOptions = loadContainerOptions(this._engine, this, this._options);\n return this.refresh();\n }\n async start() {\n if (!guardCheck(this) || this.started) {\n return;\n }\n await this.init();\n this.started = true;\n await new Promise(resolve => {\n const start = async () => {\n this._eventListeners.addListeners();\n if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {\n this._intersectionObserver.observe(this.interactivity.element);\n }\n for (const plugin of this.plugins.values()) {\n await plugin.start?.();\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerStarted, {\n container: this\n });\n this.play();\n resolve();\n };\n this._delayTimeout = setTimeout(() => void start(), this._delay);\n });\n }\n stop() {\n if (!guardCheck(this) || !this.started) {\n return;\n }\n if (this._delayTimeout) {\n clearTimeout(this._delayTimeout);\n delete this._delayTimeout;\n }\n this._firstStart = true;\n this.started = false;\n this._eventListeners.removeListeners();\n this.pause();\n this.particles.clear();\n this.canvas.stop();\n if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {\n this._intersectionObserver.unobserve(this.interactivity.element);\n }\n for (const plugin of this.plugins.values()) {\n plugin.stop?.();\n }\n for (const key of this.plugins.keys()) {\n this.plugins.delete(key);\n }\n this._sourceOptions = this._options;\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerStopped, {\n container: this\n });\n }\n updateActualOptions() {\n this.actualOptions.responsive = [];\n const newMaxWidth = this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);\n this.actualOptions.setTheme(this._currentTheme);\n if (this._responsiveMaxWidth === newMaxWidth) {\n return false;\n }\n this._responsiveMaxWidth = newMaxWidth;\n return true;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Container.js?\n}");
|
|
38
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Container: () => (/* binding */ Container)\n/* harmony export */ });\n/* harmony import */ var _Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Utils/MathUtils.js */ \"./dist/browser/Utils/MathUtils.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n/* harmony import */ var _Canvas_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Canvas.js */ \"./dist/browser/Core/Canvas.js\");\n/* harmony import */ var _Utils_EventListeners_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Utils/EventListeners.js */ \"./dist/browser/Core/Utils/EventListeners.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 _Options_Classes_Options_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Options/Classes/Options.js */ \"./dist/browser/Options/Classes/Options.js\");\n/* harmony import */ var _Particles_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Particles.js */ \"./dist/browser/Core/Particles.js\");\n/* harmony import */ var _Retina_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Retina.js */ \"./dist/browser/Core/Retina.js\");\n/* harmony import */ var _Utils_LogUtils_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../Utils/LogUtils.js */ \"./dist/browser/Utils/LogUtils.js\");\n/* harmony import */ var _Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../Utils/OptionsUtils.js */ \"./dist/browser/Utils/OptionsUtils.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n\n\n\n\n\n\n\n\n\n\n\nfunction guardCheck(container) {\n return !container.destroyed;\n}\nfunction updateDelta(delta, value, fpsLimit = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.defaultFps, smooth = false) {\n delta.value = value;\n delta.factor = smooth ? _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.defaultFps / fpsLimit : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.defaultFps * value / _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds;\n}\nfunction loadContainerOptions(engine, container, ...sourceOptionsArr) {\n const options = new _Options_Classes_Options_js__WEBPACK_IMPORTED_MODULE_5__.Options(engine, container);\n (0,_Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_9__.loadOptions)(options, ...sourceOptionsArr);\n return options;\n}\nclass Container {\n constructor(engine, id, sourceOptions) {\n this._delta = {\n value: 0,\n factor: 0\n };\n this._intersectionManager = entries => {\n if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {\n return;\n }\n for (const entry of entries) {\n if (entry.target !== this.interactivity.element) {\n continue;\n }\n if (entry.isIntersecting) {\n this.play();\n } else {\n this.pause();\n }\n }\n };\n this._nextFrame = timestamp => {\n try {\n if (!this._smooth && this._lastFrameTime !== undefined && timestamp < this._lastFrameTime + _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds / this.fpsLimit) {\n this.draw(false);\n return;\n }\n this._lastFrameTime ??= timestamp;\n updateDelta(this._delta, timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);\n this.addLifeTime(this._delta.value);\n this._lastFrameTime = timestamp;\n if (this._delta.value > _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds) {\n this.draw(false);\n return;\n }\n this.canvas.drawParticles(this._delta);\n if (!this.alive()) {\n this.destroy();\n return;\n }\n if (this.animationStatus) {\n this.draw(false);\n }\n } catch (e) {\n (0,_Utils_LogUtils_js__WEBPACK_IMPORTED_MODULE_8__.getLogger)().error(\"error in animation loop\", e);\n }\n };\n this._engine = engine;\n this.id = Symbol(id);\n this.fpsLimit = 120;\n this.hdr = false;\n this._smooth = false;\n this._delay = 0;\n this._duration = 0;\n this._lifeTime = 0;\n this._firstStart = true;\n this.started = false;\n this.destroyed = false;\n this._paused = true;\n this._lastFrameTime = 0;\n this.zLayers = 100;\n this.pageHidden = false;\n this._clickHandlers = new Map();\n this._sourceOptions = sourceOptions;\n this._initialSourceOptions = sourceOptions;\n this.retina = new _Retina_js__WEBPACK_IMPORTED_MODULE_7__.Retina(this);\n this.canvas = new _Canvas_js__WEBPACK_IMPORTED_MODULE_2__.Canvas(this, this._engine);\n this.particles = new _Particles_js__WEBPACK_IMPORTED_MODULE_6__.Particles(this._engine, this);\n this.pathGenerators = new Map();\n this.interactivity = {\n mouse: {\n clicking: false,\n inside: false\n }\n };\n this.plugins = new Map();\n this.effectDrawers = new Map();\n this.shapeDrawers = new Map();\n this._options = loadContainerOptions(this._engine, this);\n this.actualOptions = loadContainerOptions(this._engine, this);\n this._eventListeners = new _Utils_EventListeners_js__WEBPACK_IMPORTED_MODULE_3__.EventListeners(this);\n this._intersectionObserver = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_10__.safeIntersectionObserver)(entries => {\n this._intersectionManager(entries);\n });\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerBuilt, {\n container: this\n });\n }\n get animationStatus() {\n return !this._paused && !this.pageHidden && guardCheck(this);\n }\n get options() {\n return this._options;\n }\n get sourceOptions() {\n return this._sourceOptions;\n }\n addClickHandler(callback) {\n if (!guardCheck(this)) {\n return;\n }\n const el = this.interactivity.element;\n if (!el) {\n return;\n }\n const clickOrTouchHandler = (e, pos, radius) => {\n if (!guardCheck(this)) {\n return;\n }\n const pxRatio = this.retina.pixelRatio,\n posRetina = {\n x: pos.x * pxRatio,\n y: pos.y * pxRatio\n },\n particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);\n callback(e, particles);\n },\n clickHandler = e => {\n if (!guardCheck(this)) {\n return;\n }\n const mouseEvent = e,\n pos = {\n x: mouseEvent.offsetX || mouseEvent.clientX,\n y: mouseEvent.offsetY || mouseEvent.clientY\n };\n clickOrTouchHandler(e, pos, _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.clickRadius);\n },\n touchStartHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touched = true;\n touchMoved = false;\n },\n touchMoveHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touchMoved = true;\n },\n touchEndHandler = e => {\n if (!guardCheck(this)) {\n return;\n }\n if (touched && !touchMoved) {\n const touchEvent = e,\n lastTouch = touchEvent.touches[touchEvent.touches.length - _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.touchEndLengthOffset];\n if (!lastTouch) {\n return;\n }\n const element = this.canvas.element,\n canvasRect = element ? element.getBoundingClientRect() : undefined,\n pos = {\n x: lastTouch.clientX - (canvasRect ? canvasRect.left : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.minCoordinate),\n y: lastTouch.clientY - (canvasRect ? canvasRect.top : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.minCoordinate)\n };\n clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));\n }\n touched = false;\n touchMoved = false;\n },\n touchCancelHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touched = false;\n touchMoved = false;\n };\n let touched = false,\n touchMoved = false;\n this._clickHandlers.set(\"click\", clickHandler);\n this._clickHandlers.set(\"touchstart\", touchStartHandler);\n this._clickHandlers.set(\"touchmove\", touchMoveHandler);\n this._clickHandlers.set(\"touchend\", touchEndHandler);\n this._clickHandlers.set(\"touchcancel\", touchCancelHandler);\n for (const [key, handler] of this._clickHandlers) {\n el.addEventListener(key, handler);\n }\n }\n addLifeTime(value) {\n this._lifeTime += value;\n }\n addPath(key, generator, override = false) {\n if (!guardCheck(this) || !override && this.pathGenerators.has(key)) {\n return false;\n }\n this.pathGenerators.set(key, generator);\n return true;\n }\n alive() {\n return !this._duration || this._lifeTime <= this._duration;\n }\n clearClickHandlers() {\n if (!guardCheck(this)) {\n return;\n }\n for (const [key, handler] of this._clickHandlers) {\n this.interactivity.element?.removeEventListener(key, handler);\n }\n this._clickHandlers.clear();\n }\n destroy(remove = true) {\n if (!guardCheck(this)) {\n return;\n }\n this.stop();\n this.clearClickHandlers();\n this.particles.destroy();\n this.canvas.destroy();\n for (const effectDrawer of this.effectDrawers.values()) {\n effectDrawer.destroy?.(this);\n }\n this.effectDrawers.clear();\n for (const shapeDrawer of this.shapeDrawers.values()) {\n shapeDrawer.destroy?.(this);\n }\n this.shapeDrawers.clear();\n this._engine.clearPlugins(this);\n this.destroyed = true;\n if (remove) {\n const mainArr = this._engine.items,\n idx = mainArr.findIndex(t => t === this);\n if (idx >= _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.removeMinIndex) {\n mainArr.splice(idx, _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.removeDeleteCount);\n }\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerDestroyed, {\n container: this\n });\n }\n draw(force) {\n if (!guardCheck(this)) {\n return;\n }\n let refreshTime = force;\n const frame = timestamp => {\n if (refreshTime) {\n this._lastFrameTime = undefined;\n refreshTime = false;\n }\n this._nextFrame(timestamp);\n };\n this._drawAnimationFrame = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__.animate)(timestamp => {\n frame(timestamp);\n });\n }\n async export(type, options = {}) {\n for (const plugin of this.plugins.values()) {\n if (!plugin.export) {\n continue;\n }\n const res = await plugin.export(type, options);\n if (!res.supported) {\n continue;\n }\n return res.blob;\n }\n (0,_Utils_LogUtils_js__WEBPACK_IMPORTED_MODULE_8__.getLogger)().error(`Export plugin with type ${type} not found`);\n return undefined;\n }\n handleClickMode(mode) {\n if (!guardCheck(this)) {\n return;\n }\n this.particles.handleClickMode(mode);\n for (const plugin of this.plugins.values()) {\n plugin.handleClickMode?.(mode);\n }\n }\n async init() {\n if (!guardCheck(this)) {\n return;\n }\n const effects = this._engine.getSupportedEffects();\n for (const type of effects) {\n const drawer = this._engine.getEffectDrawer(type);\n if (drawer) {\n this.effectDrawers.set(type, drawer);\n }\n }\n const shapes = this._engine.getSupportedShapes();\n for (const type of shapes) {\n const drawer = this._engine.getShapeDrawer(type);\n if (drawer) {\n this.shapeDrawers.set(type, drawer);\n }\n }\n await this.particles.initPlugins();\n this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);\n this.actualOptions = loadContainerOptions(this._engine, this, this._options);\n const availablePlugins = await this._engine.getAvailablePlugins(this);\n for (const [id, plugin] of availablePlugins) {\n this.plugins.set(id, plugin);\n }\n this.retina.init();\n this.canvas.init();\n this.updateActualOptions();\n this.canvas.initBackground();\n this.canvas.resize();\n const {\n delay,\n duration,\n fpsLimit,\n hdr,\n smooth,\n zLayers\n } = this.actualOptions;\n this.hdr = hdr;\n this.zLayers = zLayers;\n this._duration = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(duration) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds;\n this._delay = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(delay) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds;\n this._lifeTime = 0;\n this.fpsLimit = fpsLimit > _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.minFpsLimit ? fpsLimit : _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_1__.defaultFpsLimit;\n this._smooth = smooth;\n for (const drawer of this.effectDrawers.values()) {\n await drawer.init?.(this);\n }\n for (const drawer of this.shapeDrawers.values()) {\n await drawer.init?.(this);\n }\n for (const plugin of this.plugins.values()) {\n await plugin.init?.();\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerInit, {\n container: this\n });\n await this.particles.init();\n this.particles.setDensity();\n for (const plugin of this.plugins.values()) {\n plugin.particlesSetup?.();\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.particlesSetup, {\n container: this\n });\n }\n async loadTheme(name) {\n if (!guardCheck(this)) {\n return;\n }\n this._currentTheme = name;\n await this.refresh();\n }\n pause() {\n if (!guardCheck(this)) {\n return;\n }\n if (this._drawAnimationFrame !== undefined) {\n (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_0__.cancelAnimation)(this._drawAnimationFrame);\n delete this._drawAnimationFrame;\n }\n if (this._paused) {\n return;\n }\n for (const plugin of this.plugins.values()) {\n plugin.pause?.();\n }\n if (!this.pageHidden) {\n this._paused = true;\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerPaused, {\n container: this\n });\n }\n play(force) {\n if (!guardCheck(this)) {\n return;\n }\n const needsUpdate = this._paused || force;\n if (this._firstStart && !this.actualOptions.autoPlay) {\n this._firstStart = false;\n return;\n }\n if (this._paused) {\n this._paused = false;\n }\n if (needsUpdate) {\n for (const plugin of this.plugins.values()) {\n if (plugin.play) {\n plugin.play();\n }\n }\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerPlay, {\n container: this\n });\n this.draw(needsUpdate ?? false);\n }\n async refresh() {\n if (!guardCheck(this)) {\n return;\n }\n this.stop();\n return this.start();\n }\n async reset(sourceOptions) {\n if (!guardCheck(this)) {\n return;\n }\n this._initialSourceOptions = sourceOptions;\n this._sourceOptions = sourceOptions;\n this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);\n this.actualOptions = loadContainerOptions(this._engine, this, this._options);\n return this.refresh();\n }\n async start() {\n if (!guardCheck(this) || this.started) {\n return;\n }\n await this.init();\n this.started = true;\n await new Promise(resolve => {\n const start = async () => {\n this._eventListeners.addListeners();\n if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {\n this._intersectionObserver.observe(this.interactivity.element);\n }\n for (const plugin of this.plugins.values()) {\n await plugin.start?.();\n }\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerStarted, {\n container: this\n });\n this.play();\n resolve();\n };\n this._delayTimeout = setTimeout(() => void start(), this._delay);\n });\n }\n stop() {\n if (!guardCheck(this) || !this.started) {\n return;\n }\n if (this._delayTimeout) {\n clearTimeout(this._delayTimeout);\n delete this._delayTimeout;\n }\n this._firstStart = true;\n this.started = false;\n this._eventListeners.removeListeners();\n this.pause();\n this.particles.clear();\n this.canvas.stop();\n if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {\n this._intersectionObserver.unobserve(this.interactivity.element);\n }\n for (const plugin of this.plugins.values()) {\n plugin.stop?.();\n }\n for (const key of this.plugins.keys()) {\n this.plugins.delete(key);\n }\n this._sourceOptions = this._options;\n this._engine.dispatchEvent(_Enums_Types_EventType_js__WEBPACK_IMPORTED_MODULE_4__.EventType.containerStopped, {\n container: this\n });\n }\n updateActualOptions() {\n this.actualOptions.responsive = [];\n const newMaxWidth = this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);\n this.actualOptions.setTheme(this._currentTheme);\n if (this._responsiveMaxWidth === newMaxWidth) {\n return false;\n }\n this._responsiveMaxWidth = newMaxWidth;\n return true;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Container.js?\n}");
|
|
39
39
|
|
|
40
40
|
/***/ },
|
|
41
41
|
|
|
@@ -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 _Options_Classes_Interactivity_Interactivity_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Options/Classes/Interactivity/Interactivity.js */ \"./dist/browser/Options/Classes/Interactivity/Interactivity.js\");\n/* harmony import */ var _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../Enums/Directions/MoveDirection.js */ \"./dist/browser/Enums/Directions/MoveDirection.js\");\n/* harmony import */ var _Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../Enums/Modes/OutMode.js */ \"./dist/browser/Enums/Modes/OutMode.js\");\n/* harmony import */ var _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../Enums/Types/ParticleOutType.js */ \"./dist/browser/Enums/Types/ParticleOutType.js\");\n/* harmony import */ var _Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../Utils/CanvasUtils.js */ \"./dist/browser/Utils/CanvasUtils.js\");\n/* harmony import */ var _Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../Utils/ColorUtils.js */ \"./dist/browser/Utils/ColorUtils.js\");\n/* harmony import */ var _Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../Utils/OptionsUtils.js */ \"./dist/browser/Utils/OptionsUtils.js\");\n\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._calcPosition = (container, position, zIndex, tryCount = _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.defaultRetryCount) => {\n const plugins = container.plugins.values();\n for (const plugin of plugins) {\n const pluginPos = plugin.particlePosition?.(position, this);\n if (pluginPos) {\n return _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);\n }\n }\n const canvasSize = container.canvas.size,\n exactPosition = (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.calcExactPositionOrRandomFromSize)({\n size: canvasSize,\n position: position\n }),\n pos = _Utils_Vectors_js__WEBPACK_IMPORTED_MODULE_0__.Vector3d.create(exactPosition.x, exactPosition.y, zIndex),\n radius = this.getRadius(),\n outModes = this.options.move.outModes,\n fixHorizontal = outMode => {\n fixOutMode({\n outMode,\n checkModes: [_Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_7__.OutMode.bounce],\n coord: pos.x,\n maxCoord: container.canvas.size.width,\n setCb: value => pos.x += value,\n radius\n });\n },\n fixVertical = outMode => {\n fixOutMode({\n outMode,\n checkModes: [_Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_7__.OutMode.bounce],\n coord: pos.y,\n maxCoord: container.canvas.size.height,\n setCb: value => pos.y += value,\n radius\n });\n };\n fixHorizontal(outModes.left ?? outModes.default);\n fixHorizontal(outModes.right ?? outModes.default);\n fixVertical(outModes.top ?? outModes.default);\n fixVertical(outModes.bottom ?? outModes.default);\n let isValidPosition = true;\n for (const plugin of plugins) {\n isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount);\n if (isValidPosition === false) {\n break;\n }\n }\n if (!isValidPosition) {\n return this._calcPosition(container, undefined, zIndex, tryCount + _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.tryCountIncrement);\n }\n return pos;\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_6__.MoveDirection.inside || moveOptions.direction === _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_6__.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._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_9__.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 this.position = this._calcPosition(container, position, (0,_Utils_MathUtils_js__WEBPACK_IMPORTED_MODULE_1__.clamp)(zIndexValue, _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.minZ, container.zLayers));\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_6__.MoveDirection.inside:\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_8__.ParticleOutType.inside;\n break;\n case _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_6__.MoveDirection.outside:\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_8__.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.values()) {\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.values()) {\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_10__.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 getPosition() {\n return {\n x: this.position.x + this.offset.x,\n y: this.position.y + this.offset.y,\n z: this.position.z\n };\n }\n getRadius() {\n return this.bubble.radius ?? this.size.value;\n }\n getStrokeColor() {\n return this._getRollColor(this.bubble.color ?? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_10__.getHslFromAnimation)(this.strokeColor));\n }\n init(id, position, overrideOptions, group) {\n const container = this.container,\n engine = this._engine;\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_8__.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_11__.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 const interactivity = new _Options_Classes_Interactivity_Interactivity_js__WEBPACK_IMPORTED_MODULE_5__.Interactivity(engine, container);\n interactivity.load(container.actualOptions.interactivity);\n interactivity.load(particlesOptions.interactivity);\n this.interactivity = interactivity;\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.values()) {\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 _Options_Classes_Interactivity_Interactivity_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Options/Classes/Interactivity/Interactivity.js */ \"./dist/browser/Options/Classes/Interactivity/Interactivity.js\");\n/* harmony import */ var _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../Enums/Directions/MoveDirection.js */ \"./dist/browser/Enums/Directions/MoveDirection.js\");\n/* harmony import */ var _Enums_Modes_OutMode_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../Enums/Modes/OutMode.js */ \"./dist/browser/Enums/Modes/OutMode.js\");\n/* harmony import */ var _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../Enums/Types/ParticleOutType.js */ \"./dist/browser/Enums/Types/ParticleOutType.js\");\n/* harmony import */ var _Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../Utils/CanvasUtils.js */ \"./dist/browser/Utils/CanvasUtils.js\");\n/* harmony import */ var _Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../Utils/ColorUtils.js */ \"./dist/browser/Utils/ColorUtils.js\");\n/* harmony import */ var _Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../Utils/OptionsUtils.js */ \"./dist/browser/Utils/OptionsUtils.js\");\n\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.values()),\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_6__.MoveDirection.inside || moveOptions.direction === _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_6__.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_7__.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_7__.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_9__.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_6__.MoveDirection.inside:\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_8__.ParticleOutType.inside;\n break;\n case _Enums_Directions_MoveDirection_js__WEBPACK_IMPORTED_MODULE_6__.MoveDirection.outside:\n this.outType = _Enums_Types_ParticleOutType_js__WEBPACK_IMPORTED_MODULE_8__.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.values()) {\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.values()) {\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_10__.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_10__.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 engine = this._engine;\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_8__.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_11__.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 const interactivity = new _Options_Classes_Interactivity_Interactivity_js__WEBPACK_IMPORTED_MODULE_5__.Interactivity(engine, container);\n interactivity.load(container.actualOptions.interactivity);\n interactivity.load(particlesOptions.interactivity);\n this.interactivity = interactivity;\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.values()) {\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}");
|
|
49
49
|
|
|
50
50
|
/***/ },
|
|
51
51
|
|
package/esm/Core/Canvas.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { clear, clearDrawPlugin, drawParticle, drawParticlePlugin, drawPlugin, paintBase, paintImage, } from "../Utils/CanvasUtils.js";
|
|
2
2
|
import { cloneStyle, getFullScreenStyle, safeMatchMedia, safeMutationObserver } from "../Utils/Utils.js";
|
|
3
|
-
import {
|
|
3
|
+
import { defaultTransformValue, generatedAttribute, minimumSize, zIndexFactorOffset } from "./Utils/Constants.js";
|
|
4
4
|
import { getStyleFromHsl, getStyleFromRgb, rangeColorToHsl, rangeColorToRgb } from "../Utils/ColorUtils.js";
|
|
5
|
+
const fColorIndex = 0, sColorIndex = 1;
|
|
5
6
|
function setTransformValue(factor, newFactor, key) {
|
|
6
7
|
const newValue = newFactor[key];
|
|
7
8
|
if (newValue !== undefined) {
|
|
@@ -40,6 +41,9 @@ function setStyle(canvas, style, important = false) {
|
|
|
40
41
|
export class Canvas {
|
|
41
42
|
constructor(container, engine) {
|
|
42
43
|
this.container = container;
|
|
44
|
+
this._reusableColorStyles = {};
|
|
45
|
+
this._reusablePluginColors = [undefined, undefined];
|
|
46
|
+
this._reusableTransform = {};
|
|
43
47
|
this._applyPostDrawUpdaters = particle => {
|
|
44
48
|
for (const updater of this._postDrawUpdaters) {
|
|
45
49
|
updater.afterDraw?.(particle);
|
|
@@ -83,7 +87,9 @@ export class Canvas {
|
|
|
83
87
|
break;
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
|
-
|
|
90
|
+
this._reusablePluginColors[fColorIndex] = fColor;
|
|
91
|
+
this._reusablePluginColors[sColorIndex] = sColor;
|
|
92
|
+
return this._reusablePluginColors;
|
|
87
93
|
};
|
|
88
94
|
this._initStyle = () => {
|
|
89
95
|
const element = this.element, options = this.container.actualOptions;
|
|
@@ -97,7 +103,7 @@ export class Canvas {
|
|
|
97
103
|
this._resetOriginalStyle();
|
|
98
104
|
}
|
|
99
105
|
for (const key in options.style) {
|
|
100
|
-
if (!key || !Object.
|
|
106
|
+
if (!key || !Object.hasOwn(options.style, key)) {
|
|
101
107
|
continue;
|
|
102
108
|
}
|
|
103
109
|
const value = options.style[key];
|
|
@@ -230,22 +236,12 @@ export class Canvas {
|
|
|
230
236
|
if (!fColor && !sColor) {
|
|
231
237
|
return;
|
|
232
238
|
}
|
|
233
|
-
const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return getStyleFromHsl(fColor, container.hdr, zOpacity);
|
|
238
|
-
}, colorStyles = {
|
|
239
|
-
fill: getFillStyle(),
|
|
240
|
-
}, getStrokestyle = () => {
|
|
241
|
-
if (!sColor) {
|
|
242
|
-
return colorStyles.fill;
|
|
243
|
-
}
|
|
244
|
-
return getStyleFromHsl(sColor, container.hdr, zStrokeOpacity);
|
|
245
|
-
};
|
|
246
|
-
colorStyles.stroke = getStrokestyle();
|
|
239
|
+
const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity) : fill;
|
|
240
|
+
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
241
|
+
colorStyles.fill = fill;
|
|
242
|
+
colorStyles.stroke = stroke;
|
|
247
243
|
this.draw((context) => {
|
|
248
|
-
this._applyPreDrawUpdaters(context, particle, radius,
|
|
244
|
+
this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
249
245
|
drawParticle({
|
|
250
246
|
container,
|
|
251
247
|
context,
|
|
@@ -253,7 +249,7 @@ export class Canvas {
|
|
|
253
249
|
delta,
|
|
254
250
|
colorStyles,
|
|
255
251
|
radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
|
|
256
|
-
opacity:
|
|
252
|
+
opacity: opacity,
|
|
257
253
|
transform,
|
|
258
254
|
});
|
|
259
255
|
});
|