@tsparticles/engine 3.0.3 → 3.1.0
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/README.md +265 -145
- package/browser/Core/Canvas.js +19 -19
- package/browser/Core/Container.js +45 -34
- package/browser/Core/Engine.js +36 -20
- package/browser/Core/Particle.js +35 -36
- package/browser/Core/Particles.js +30 -24
- package/browser/Core/Retina.js +5 -4
- package/browser/Core/Utils/Circle.js +4 -3
- package/browser/Core/Utils/Constants.js +3 -0
- package/browser/Core/Utils/EventListeners.js +18 -15
- package/browser/Core/Utils/ExternalInteractorBase.js +1 -1
- package/browser/Core/Utils/InteractionManager.js +14 -6
- package/browser/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/browser/Core/Utils/QuadTree.js +5 -3
- package/browser/Core/Utils/Vector.js +7 -2
- package/browser/Core/Utils/Vector3d.js +14 -9
- package/browser/Options/Classes/ManualParticle.js +3 -2
- package/browser/Options/Classes/Options.js +3 -0
- package/browser/Utils/CanvasUtils.js +36 -26
- package/browser/Utils/ColorUtils.js +124 -45
- package/browser/Utils/EventDispatcher.js +6 -5
- package/browser/Utils/HslColorManager.js +5 -5
- package/browser/Utils/NumberUtils.js +35 -23
- package/browser/Utils/RgbColorManager.js +5 -5
- package/browser/Utils/Utils.js +102 -19
- package/cjs/Core/Canvas.js +19 -19
- package/cjs/Core/Container.js +45 -34
- package/cjs/Core/Engine.js +36 -20
- package/cjs/Core/Particle.js +34 -35
- package/cjs/Core/Particles.js +30 -24
- package/cjs/Core/Retina.js +5 -4
- package/cjs/Core/Utils/Circle.js +4 -3
- package/cjs/Core/Utils/Constants.js +4 -1
- package/cjs/Core/Utils/EventListeners.js +17 -14
- package/cjs/Core/Utils/ExternalInteractorBase.js +1 -1
- package/cjs/Core/Utils/InteractionManager.js +14 -6
- package/cjs/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/cjs/Core/Utils/QuadTree.js +5 -3
- package/cjs/Core/Utils/Vector.js +7 -2
- package/cjs/Core/Utils/Vector3d.js +14 -9
- package/cjs/Options/Classes/ManualParticle.js +3 -2
- package/cjs/Options/Classes/Options.js +3 -0
- package/cjs/Utils/CanvasUtils.js +36 -26
- package/cjs/Utils/ColorUtils.js +126 -45
- package/cjs/Utils/EventDispatcher.js +6 -5
- package/cjs/Utils/HslColorManager.js +5 -5
- package/cjs/Utils/NumberUtils.js +37 -24
- package/cjs/Utils/RgbColorManager.js +5 -5
- package/cjs/Utils/Utils.js +103 -19
- package/esm/Core/Canvas.js +19 -19
- package/esm/Core/Container.js +45 -34
- package/esm/Core/Engine.js +36 -20
- package/esm/Core/Particle.js +35 -36
- package/esm/Core/Particles.js +30 -24
- package/esm/Core/Retina.js +5 -4
- package/esm/Core/Utils/Circle.js +4 -3
- package/esm/Core/Utils/Constants.js +3 -0
- package/esm/Core/Utils/EventListeners.js +18 -15
- package/esm/Core/Utils/ExternalInteractorBase.js +1 -1
- package/esm/Core/Utils/InteractionManager.js +14 -6
- package/esm/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/esm/Core/Utils/QuadTree.js +5 -3
- package/esm/Core/Utils/Vector.js +7 -2
- package/esm/Core/Utils/Vector3d.js +14 -9
- package/esm/Options/Classes/ManualParticle.js +3 -2
- package/esm/Options/Classes/Options.js +3 -0
- package/esm/Utils/CanvasUtils.js +36 -26
- package/esm/Utils/ColorUtils.js +124 -45
- package/esm/Utils/EventDispatcher.js +6 -5
- package/esm/Utils/HslColorManager.js +5 -5
- package/esm/Utils/NumberUtils.js +35 -23
- package/esm/Utils/RgbColorManager.js +5 -5
- package/esm/Utils/Utils.js +102 -19
- package/package.json +1 -1
- package/report.html +2 -2
- package/tsparticles.engine.js +693 -334
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Interfaces/IParticleHslAnimation.d.ts +4 -4
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +4 -0
- package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -2
- package/types/Core/Utils/Constants.d.ts +3 -0
- package/types/Core/Utils/ExternalInteractorBase.d.ts +1 -1
- package/types/Core/Utils/InteractionManager.d.ts +1 -1
- package/types/Core/Utils/ParticlesInteractorBase.d.ts +1 -1
- package/types/Core/Utils/Point.d.ts +1 -1
- package/types/Options/Classes/Options.d.ts +1 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +1 -2
- package/types/Options/Classes/Particles/Move/OutModes.d.ts +1 -2
- package/types/Options/Interfaces/IOptions.d.ts +1 -0
- package/types/Options/Interfaces/Interactivity/Modes/IModes.d.ts +1 -3
- package/types/Types/CustomEventArgs.d.ts +2 -2
- package/types/Types/ExportResult.d.ts +2 -2
- package/types/Types/ParticlesGroups.d.ts +1 -3
- package/types/Types/PathOptions.d.ts +1 -3
- package/types/Types/ShapeData.d.ts +1 -3
- package/types/Utils/CanvasUtils.d.ts +3 -2
- package/types/Utils/ColorUtils.d.ts +5 -0
- package/types/Utils/NumberUtils.d.ts +2 -2
- package/types/Utils/Utils.d.ts +9 -6
- package/umd/Core/Canvas.js +19 -19
- package/umd/Core/Container.js +46 -35
- package/umd/Core/Engine.js +36 -20
- package/umd/Core/Particle.js +35 -36
- package/umd/Core/Particles.js +30 -24
- package/umd/Core/Retina.js +5 -4
- package/umd/Core/Utils/Circle.js +4 -3
- package/umd/Core/Utils/Constants.js +4 -1
- package/umd/Core/Utils/EventListeners.js +17 -14
- package/umd/Core/Utils/ExternalInteractorBase.js +1 -1
- package/umd/Core/Utils/InteractionManager.js +14 -6
- package/umd/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/umd/Core/Utils/QuadTree.js +5 -3
- package/umd/Core/Utils/Vector.js +7 -2
- package/umd/Core/Utils/Vector3d.js +14 -9
- package/umd/Options/Classes/ManualParticle.js +3 -2
- package/umd/Options/Classes/Options.js +3 -0
- package/umd/Utils/CanvasUtils.js +36 -26
- package/umd/Utils/ColorUtils.js +127 -46
- package/umd/Utils/EventDispatcher.js +6 -5
- package/umd/Utils/HslColorManager.js +5 -5
- package/umd/Utils/NumberUtils.js +38 -25
- package/umd/Utils/RgbColorManager.js +5 -5
- package/umd/Utils/Utils.js +104 -20
package/cjs/Utils/NumberUtils.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseAlpha = exports.calcExactPositionOrRandomFromSizeRanged = exports.calcExactPositionOrRandomFromSize = exports.calcPositionOrRandomFromSizeRanged = exports.calcPositionOrRandomFromSize = exports.calcPositionFromSize = exports.collisionVelocity = exports.getParticleBaseVelocity = exports.getParticleDirectionAngle = exports.getDistance = exports.getDistances = exports.setRangeValue = exports.getRangeMax = exports.getRangeMin = exports.getRangeValue = exports.randomInRange = exports.mix = exports.clamp = exports.getRandom = exports.setRandom = exports.getEasing = exports.addEasing = void 0;
|
|
3
|
+
exports.parseAlpha = exports.calcExactPositionOrRandomFromSizeRanged = exports.calcExactPositionOrRandomFromSize = exports.calcPositionOrRandomFromSizeRanged = exports.calcPositionOrRandomFromSize = exports.calcPositionFromSize = exports.collisionVelocity = exports.getParticleBaseVelocity = exports.getParticleDirectionAngle = exports.degToRad = exports.getDistance = exports.getDistances = exports.setRangeValue = exports.getRangeMax = exports.getRangeMin = exports.getRangeValue = exports.randomInRange = exports.mix = exports.clamp = exports.getRandom = exports.setRandom = exports.getEasing = exports.addEasing = void 0;
|
|
4
4
|
const Vector_js_1 = require("../Core/Utils/Vector.js");
|
|
5
5
|
const Utils_js_1 = require("./Utils.js");
|
|
6
|
+
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
6
7
|
let _random = Math.random;
|
|
7
|
-
const easings = new Map();
|
|
8
|
+
const easings = new Map(), double = 2, doublePI = Math.PI * double;
|
|
8
9
|
function addEasing(name, easing) {
|
|
9
10
|
if (easings.get(name)) {
|
|
10
11
|
return;
|
|
@@ -13,7 +14,7 @@ function addEasing(name, easing) {
|
|
|
13
14
|
}
|
|
14
15
|
exports.addEasing = addEasing;
|
|
15
16
|
function getEasing(name) {
|
|
16
|
-
return easings.get(name)
|
|
17
|
+
return easings.get(name) ?? ((value) => value);
|
|
17
18
|
}
|
|
18
19
|
exports.getEasing = getEasing;
|
|
19
20
|
function setRandom(rnd = Math.random) {
|
|
@@ -21,7 +22,8 @@ function setRandom(rnd = Math.random) {
|
|
|
21
22
|
}
|
|
22
23
|
exports.setRandom = setRandom;
|
|
23
24
|
function getRandom() {
|
|
24
|
-
|
|
25
|
+
const min = 0, max = 1;
|
|
26
|
+
return clamp(_random(), min, max - Number.EPSILON);
|
|
25
27
|
}
|
|
26
28
|
exports.getRandom = getRandom;
|
|
27
29
|
function clamp(num, min, max) {
|
|
@@ -33,10 +35,10 @@ function mix(comp1, comp2, weight1, weight2) {
|
|
|
33
35
|
}
|
|
34
36
|
exports.mix = mix;
|
|
35
37
|
function randomInRange(r) {
|
|
36
|
-
const max = getRangeMax(r);
|
|
38
|
+
const max = getRangeMax(r), minOffset = 0;
|
|
37
39
|
let min = getRangeMin(r);
|
|
38
40
|
if (max === min) {
|
|
39
|
-
min =
|
|
41
|
+
min = minOffset;
|
|
40
42
|
}
|
|
41
43
|
return getRandom() * (max - min) + min;
|
|
42
44
|
}
|
|
@@ -67,41 +69,47 @@ function setRangeValue(source, value) {
|
|
|
67
69
|
}
|
|
68
70
|
exports.setRangeValue = setRangeValue;
|
|
69
71
|
function getDistances(pointA, pointB) {
|
|
70
|
-
const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
|
|
71
|
-
return { dx: dx, dy: dy, distance: Math.sqrt(dx **
|
|
72
|
+
const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y, squareExp = 2;
|
|
73
|
+
return { dx: dx, dy: dy, distance: Math.sqrt(dx ** squareExp + dy ** squareExp) };
|
|
72
74
|
}
|
|
73
75
|
exports.getDistances = getDistances;
|
|
74
76
|
function getDistance(pointA, pointB) {
|
|
75
77
|
return getDistances(pointA, pointB).distance;
|
|
76
78
|
}
|
|
77
79
|
exports.getDistance = getDistance;
|
|
80
|
+
function degToRad(degrees) {
|
|
81
|
+
const PIDeg = 180;
|
|
82
|
+
return (degrees * Math.PI) / PIDeg;
|
|
83
|
+
}
|
|
84
|
+
exports.degToRad = degToRad;
|
|
78
85
|
function getParticleDirectionAngle(direction, position, center) {
|
|
79
86
|
if ((0, Utils_js_1.isNumber)(direction)) {
|
|
80
|
-
return (direction
|
|
87
|
+
return degToRad(direction);
|
|
81
88
|
}
|
|
89
|
+
const empty = 0, half = 0.5, quarter = 0.25, threeQuarter = half + quarter;
|
|
82
90
|
switch (direction) {
|
|
83
91
|
case "top":
|
|
84
|
-
return -Math.PI *
|
|
92
|
+
return -Math.PI * half;
|
|
85
93
|
case "top-right":
|
|
86
|
-
return -Math.PI *
|
|
94
|
+
return -Math.PI * quarter;
|
|
87
95
|
case "right":
|
|
88
|
-
return
|
|
96
|
+
return empty;
|
|
89
97
|
case "bottom-right":
|
|
90
|
-
return Math.PI *
|
|
98
|
+
return Math.PI * quarter;
|
|
91
99
|
case "bottom":
|
|
92
|
-
return Math.PI *
|
|
100
|
+
return Math.PI * half;
|
|
93
101
|
case "bottom-left":
|
|
94
|
-
return Math.PI *
|
|
102
|
+
return Math.PI * threeQuarter;
|
|
95
103
|
case "left":
|
|
96
104
|
return Math.PI;
|
|
97
105
|
case "top-left":
|
|
98
|
-
return -Math.PI *
|
|
106
|
+
return -Math.PI * threeQuarter;
|
|
99
107
|
case "inside":
|
|
100
108
|
return Math.atan2(center.y - position.y, center.x - position.x);
|
|
101
109
|
case "outside":
|
|
102
110
|
return Math.atan2(position.y - center.y, position.x - center.x);
|
|
103
111
|
default:
|
|
104
|
-
return getRandom() *
|
|
112
|
+
return getRandom() * doublePI;
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
exports.getParticleDirectionAngle = getParticleDirectionAngle;
|
|
@@ -113,22 +121,23 @@ function getParticleBaseVelocity(direction) {
|
|
|
113
121
|
}
|
|
114
122
|
exports.getParticleBaseVelocity = getParticleBaseVelocity;
|
|
115
123
|
function collisionVelocity(v1, v2, m1, m2) {
|
|
116
|
-
|
|
124
|
+
const double = 2;
|
|
125
|
+
return Vector_js_1.Vector.create((v1.x * (m1 - m2)) / (m1 + m2) + (v2.x * double * m2) / (m1 + m2), v1.y);
|
|
117
126
|
}
|
|
118
127
|
exports.collisionVelocity = collisionVelocity;
|
|
119
128
|
function calcPositionFromSize(data) {
|
|
120
|
-
return data.position
|
|
129
|
+
return data.position?.x !== undefined && data.position.y !== undefined
|
|
121
130
|
? {
|
|
122
|
-
x: (data.position.x * data.size.width) /
|
|
123
|
-
y: (data.position.y * data.size.height) /
|
|
131
|
+
x: (data.position.x * data.size.width) / Constants_js_1.percentDenominator,
|
|
132
|
+
y: (data.position.y * data.size.height) / Constants_js_1.percentDenominator,
|
|
124
133
|
}
|
|
125
134
|
: undefined;
|
|
126
135
|
}
|
|
127
136
|
exports.calcPositionFromSize = calcPositionFromSize;
|
|
128
137
|
function calcPositionOrRandomFromSize(data) {
|
|
129
138
|
return {
|
|
130
|
-
x: ((data.position?.x ?? getRandom() *
|
|
131
|
-
y: ((data.position?.y ?? getRandom() *
|
|
139
|
+
x: ((data.position?.x ?? getRandom() * Constants_js_1.percentDenominator) * data.size.width) / Constants_js_1.percentDenominator,
|
|
140
|
+
y: ((data.position?.y ?? getRandom() * Constants_js_1.percentDenominator) * data.size.height) / Constants_js_1.percentDenominator,
|
|
132
141
|
};
|
|
133
142
|
}
|
|
134
143
|
exports.calcPositionOrRandomFromSize = calcPositionOrRandomFromSize;
|
|
@@ -156,6 +165,10 @@ function calcExactPositionOrRandomFromSizeRanged(data) {
|
|
|
156
165
|
}
|
|
157
166
|
exports.calcExactPositionOrRandomFromSizeRanged = calcExactPositionOrRandomFromSizeRanged;
|
|
158
167
|
function parseAlpha(input) {
|
|
159
|
-
|
|
168
|
+
const defaultAlpha = 1;
|
|
169
|
+
if (!input) {
|
|
170
|
+
return defaultAlpha;
|
|
171
|
+
}
|
|
172
|
+
return input.endsWith("%") ? parseFloat(input) / Constants_js_1.percentDenominator : parseFloat(input);
|
|
160
173
|
}
|
|
161
174
|
exports.parseAlpha = parseAlpha;
|
|
@@ -27,13 +27,13 @@ class RgbColorManager {
|
|
|
27
27
|
if (!input.startsWith(this.stringPrefix)) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
const regex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.%]+)\s*)?\)/i, result = regex.exec(input);
|
|
30
|
+
const regex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.%]+)\s*)?\)/i, result = regex.exec(input), radix = 10, minLength = 4, defaultAlpha = 1;
|
|
31
31
|
return result
|
|
32
32
|
? {
|
|
33
|
-
a: result.length >
|
|
34
|
-
b: parseInt(result[3],
|
|
35
|
-
g: parseInt(result[2],
|
|
36
|
-
r: parseInt(result[1],
|
|
33
|
+
a: result.length > minLength ? (0, NumberUtils_js_1.parseAlpha)(result[5]) : defaultAlpha,
|
|
34
|
+
b: parseInt(result[3], radix),
|
|
35
|
+
g: parseInt(result[2], radix),
|
|
36
|
+
r: parseInt(result[1], radix),
|
|
37
37
|
}
|
|
38
38
|
: undefined;
|
|
39
39
|
}
|
package/cjs/Utils/Utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isArray = exports.isObject = exports.isFunction = exports.isNumber = exports.isString = exports.isBoolean = exports.getSize = exports.getPosition = exports.initParticleNumericAnimationValue = exports.findItemFromSingleOrMultiple = exports.itemFromSingleOrMultiple = exports.executeOnSingleOrMultiple = exports.rectBounce = exports.circleBounce = exports.circleBounceDataFromParticle = exports.divMode = exports.singleDivModeExecute = exports.divModeExecute = exports.isDivModeEnabled = exports.deepExtend = exports.calculateBounds = exports.areBoundsInside = exports.isPointInside = exports.itemFromArray = exports.arrayRandomIndex = exports.loadFont = exports.isInArray = exports.safeMutationObserver = exports.safeIntersectionObserver = exports.safeMatchMedia = exports.hasMatchMedia = exports.isSsr = exports.getLogger = exports.setLogger = void 0;
|
|
3
|
+
exports.updateAnimation = exports.isArray = exports.isObject = exports.isFunction = exports.isNumber = exports.isString = exports.isBoolean = exports.getSize = exports.getPosition = exports.initParticleNumericAnimationValue = exports.findItemFromSingleOrMultiple = exports.itemFromSingleOrMultiple = exports.executeOnSingleOrMultiple = exports.rectBounce = exports.circleBounce = exports.circleBounceDataFromParticle = exports.divMode = exports.singleDivModeExecute = exports.divModeExecute = exports.isDivModeEnabled = exports.deepExtend = exports.calculateBounds = exports.areBoundsInside = exports.isPointInside = exports.itemFromArray = exports.arrayRandomIndex = exports.loadFont = exports.isInArray = exports.safeMutationObserver = exports.safeIntersectionObserver = exports.safeMatchMedia = exports.hasMatchMedia = exports.isSsr = exports.getLogger = exports.setLogger = void 0;
|
|
4
4
|
const NumberUtils_js_1 = require("./NumberUtils.js");
|
|
5
|
+
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
5
6
|
const Vector_js_1 = require("../Core/Utils/Vector.js");
|
|
6
7
|
const _logger = {
|
|
7
8
|
debug: console.debug,
|
|
@@ -25,15 +26,15 @@ function getLogger() {
|
|
|
25
26
|
}
|
|
26
27
|
exports.getLogger = getLogger;
|
|
27
28
|
function rectSideBounce(data) {
|
|
28
|
-
const res = { bounced: false }, { pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor } = data;
|
|
29
|
+
const res = { bounced: false }, { pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor } = data, half = 0.5, minVelocity = 0;
|
|
29
30
|
if (pOtherSide.min < rectOtherSide.min ||
|
|
30
31
|
pOtherSide.min > rectOtherSide.max ||
|
|
31
32
|
pOtherSide.max < rectOtherSide.min ||
|
|
32
33
|
pOtherSide.max > rectOtherSide.max) {
|
|
33
34
|
return res;
|
|
34
35
|
}
|
|
35
|
-
if ((pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) *
|
|
36
|
-
(pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) *
|
|
36
|
+
if ((pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) * half && velocity > minVelocity) ||
|
|
37
|
+
(pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) * half && velocity < minVelocity)) {
|
|
37
38
|
res.velocity = velocity * -factor;
|
|
38
39
|
res.bounced = true;
|
|
39
40
|
}
|
|
@@ -75,7 +76,8 @@ function safeMutationObserver(callback) {
|
|
|
75
76
|
}
|
|
76
77
|
exports.safeMutationObserver = safeMutationObserver;
|
|
77
78
|
function isInArray(value, array) {
|
|
78
|
-
|
|
79
|
+
const invalidIndex = -1;
|
|
80
|
+
return value === array || (isArray(array) && array.indexOf(value) > invalidIndex);
|
|
79
81
|
}
|
|
80
82
|
exports.isInArray = isInArray;
|
|
81
83
|
async function loadFont(font, weight) {
|
|
@@ -95,7 +97,8 @@ function itemFromArray(array, index, useIndex = true) {
|
|
|
95
97
|
}
|
|
96
98
|
exports.itemFromArray = itemFromArray;
|
|
97
99
|
function isPointInside(point, size, offset, radius, direction) {
|
|
98
|
-
|
|
100
|
+
const minRadius = 0;
|
|
101
|
+
return areBoundsInside(calculateBounds(point, radius ?? minRadius), size, offset, direction);
|
|
99
102
|
}
|
|
100
103
|
exports.isPointInside = isPointInside;
|
|
101
104
|
function areBoundsInside(bounds, size, offset, direction) {
|
|
@@ -194,8 +197,8 @@ function circleBounceDataFromParticle(p) {
|
|
|
194
197
|
}
|
|
195
198
|
exports.circleBounceDataFromParticle = circleBounceDataFromParticle;
|
|
196
199
|
function circleBounce(p1, p2) {
|
|
197
|
-
const { x: xVelocityDiff, y: yVelocityDiff } = p1.velocity.sub(p2.velocity), [pos1, pos2] = [p1.position, p2.position], { dx: xDist, dy: yDist } = (0, NumberUtils_js_1.getDistances)(pos2, pos1);
|
|
198
|
-
if (xVelocityDiff * xDist + yVelocityDiff * yDist <
|
|
200
|
+
const { x: xVelocityDiff, y: yVelocityDiff } = p1.velocity.sub(p2.velocity), [pos1, pos2] = [p1.position, p2.position], { dx: xDist, dy: yDist } = (0, NumberUtils_js_1.getDistances)(pos2, pos1), minimumDistance = 0;
|
|
201
|
+
if (xVelocityDiff * xDist + yVelocityDiff * yDist < minimumDistance) {
|
|
199
202
|
return;
|
|
200
203
|
}
|
|
201
204
|
const angle = -Math.atan2(yDist, xDist), m1 = p1.mass, m2 = p2.mass, u1 = p1.velocity.rotate(angle), u2 = p2.velocity.rotate(angle), v1 = (0, NumberUtils_js_1.collisionVelocity)(u1, u2, m1, m2), v2 = (0, NumberUtils_js_1.collisionVelocity)(u2, u1, m1, m2), vFinal1 = v1.rotate(-angle), vFinal2 = v2.rotate(-angle);
|
|
@@ -265,7 +268,8 @@ function rectBounce(particle, divBounds) {
|
|
|
265
268
|
}
|
|
266
269
|
exports.rectBounce = rectBounce;
|
|
267
270
|
function executeOnSingleOrMultiple(obj, callback) {
|
|
268
|
-
|
|
271
|
+
const defaultIndex = 0;
|
|
272
|
+
return isArray(obj) ? obj.map((item, index) => callback(item, index)) : callback(obj, defaultIndex);
|
|
269
273
|
}
|
|
270
274
|
exports.executeOnSingleOrMultiple = executeOnSingleOrMultiple;
|
|
271
275
|
function itemFromSingleOrMultiple(obj, index, useIndex) {
|
|
@@ -273,12 +277,16 @@ function itemFromSingleOrMultiple(obj, index, useIndex) {
|
|
|
273
277
|
}
|
|
274
278
|
exports.itemFromSingleOrMultiple = itemFromSingleOrMultiple;
|
|
275
279
|
function findItemFromSingleOrMultiple(obj, callback) {
|
|
276
|
-
|
|
280
|
+
if (isArray(obj)) {
|
|
281
|
+
return obj.find((t, index) => callback(t, index));
|
|
282
|
+
}
|
|
283
|
+
const defaultIndex = 0;
|
|
284
|
+
return callback(obj, defaultIndex) ? obj : undefined;
|
|
277
285
|
}
|
|
278
286
|
exports.findItemFromSingleOrMultiple = findItemFromSingleOrMultiple;
|
|
279
287
|
function initParticleNumericAnimationValue(options, pxRatio) {
|
|
280
288
|
const valueRange = options.value, animationOptions = options.animation, res = {
|
|
281
|
-
delayTime: (0, NumberUtils_js_1.getRangeValue)(animationOptions.delay) *
|
|
289
|
+
delayTime: (0, NumberUtils_js_1.getRangeValue)(animationOptions.delay) * Constants_js_1.millisecondsToSeconds,
|
|
282
290
|
enable: animationOptions.enable,
|
|
283
291
|
value: (0, NumberUtils_js_1.getRangeValue)(options.value) * pxRatio,
|
|
284
292
|
max: (0, NumberUtils_js_1.getRangeMax)(valueRange) * pxRatio,
|
|
@@ -286,9 +294,9 @@ function initParticleNumericAnimationValue(options, pxRatio) {
|
|
|
286
294
|
loops: 0,
|
|
287
295
|
maxLoops: (0, NumberUtils_js_1.getRangeValue)(animationOptions.count),
|
|
288
296
|
time: 0,
|
|
289
|
-
};
|
|
297
|
+
}, decayOffset = 1;
|
|
290
298
|
if (animationOptions.enable) {
|
|
291
|
-
res.decay =
|
|
299
|
+
res.decay = decayOffset - (0, NumberUtils_js_1.getRangeValue)(animationOptions.decay);
|
|
292
300
|
switch (animationOptions.mode) {
|
|
293
301
|
case "increase":
|
|
294
302
|
res.status = "increasing";
|
|
@@ -297,7 +305,7 @@ function initParticleNumericAnimationValue(options, pxRatio) {
|
|
|
297
305
|
res.status = "decreasing";
|
|
298
306
|
break;
|
|
299
307
|
case "random":
|
|
300
|
-
res.status = (0, NumberUtils_js_1.getRandom)() >=
|
|
308
|
+
res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.halfRandom ? "increasing" : "decreasing";
|
|
301
309
|
break;
|
|
302
310
|
}
|
|
303
311
|
const autoStatus = animationOptions.mode === "auto";
|
|
@@ -318,7 +326,7 @@ function initParticleNumericAnimationValue(options, pxRatio) {
|
|
|
318
326
|
default:
|
|
319
327
|
res.value = (0, NumberUtils_js_1.randomInRange)(res);
|
|
320
328
|
if (autoStatus) {
|
|
321
|
-
res.status = (0, NumberUtils_js_1.getRandom)() >=
|
|
329
|
+
res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.halfRandom ? "increasing" : "decreasing";
|
|
322
330
|
}
|
|
323
331
|
break;
|
|
324
332
|
}
|
|
@@ -336,14 +344,14 @@ function getPositionOrSize(positionOrSize, canvasSize) {
|
|
|
336
344
|
const isPosition = "x" in positionOrSize;
|
|
337
345
|
if (isPosition) {
|
|
338
346
|
return {
|
|
339
|
-
x: (positionOrSize.x /
|
|
340
|
-
y: (positionOrSize.y /
|
|
347
|
+
x: (positionOrSize.x / Constants_js_1.percentDenominator) * canvasSize.width,
|
|
348
|
+
y: (positionOrSize.y / Constants_js_1.percentDenominator) * canvasSize.height,
|
|
341
349
|
};
|
|
342
350
|
}
|
|
343
351
|
else {
|
|
344
352
|
return {
|
|
345
|
-
width: (positionOrSize.width /
|
|
346
|
-
height: (positionOrSize.height /
|
|
353
|
+
width: (positionOrSize.width / Constants_js_1.percentDenominator) * canvasSize.width,
|
|
354
|
+
height: (positionOrSize.height / Constants_js_1.percentDenominator) * canvasSize.height,
|
|
347
355
|
};
|
|
348
356
|
}
|
|
349
357
|
}
|
|
@@ -379,3 +387,79 @@ function isArray(arg) {
|
|
|
379
387
|
return Array.isArray(arg);
|
|
380
388
|
}
|
|
381
389
|
exports.isArray = isArray;
|
|
390
|
+
function checkDestroy(particle, destroyType, value, minValue, maxValue) {
|
|
391
|
+
switch (destroyType) {
|
|
392
|
+
case "max":
|
|
393
|
+
if (value >= maxValue) {
|
|
394
|
+
particle.destroy();
|
|
395
|
+
}
|
|
396
|
+
break;
|
|
397
|
+
case "min":
|
|
398
|
+
if (value <= minValue) {
|
|
399
|
+
particle.destroy();
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function updateAnimation(particle, data, changeDirection, destroyType, delta) {
|
|
405
|
+
const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minDecay = 1;
|
|
406
|
+
if (particle.destroyed ||
|
|
407
|
+
!data ||
|
|
408
|
+
!data.enable ||
|
|
409
|
+
((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const velocity = (data.velocity ?? minVelocity) * delta.factor, minValue = data.min, maxValue = data.max, decay = data.decay ?? minDecay;
|
|
413
|
+
if (!data.time) {
|
|
414
|
+
data.time = 0;
|
|
415
|
+
}
|
|
416
|
+
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
417
|
+
data.time += delta.value;
|
|
418
|
+
}
|
|
419
|
+
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
switch (data.status) {
|
|
423
|
+
case "increasing":
|
|
424
|
+
if (data.value >= maxValue) {
|
|
425
|
+
if (changeDirection) {
|
|
426
|
+
data.status = "decreasing";
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
data.value -= maxValue;
|
|
430
|
+
}
|
|
431
|
+
if (!data.loops) {
|
|
432
|
+
data.loops = minLoops;
|
|
433
|
+
}
|
|
434
|
+
data.loops++;
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
data.value += velocity;
|
|
438
|
+
}
|
|
439
|
+
break;
|
|
440
|
+
case "decreasing":
|
|
441
|
+
if (data.value <= minValue) {
|
|
442
|
+
if (changeDirection) {
|
|
443
|
+
data.status = "increasing";
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
data.value += maxValue;
|
|
447
|
+
}
|
|
448
|
+
if (!data.loops) {
|
|
449
|
+
data.loops = minLoops;
|
|
450
|
+
}
|
|
451
|
+
data.loops++;
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
data.value -= velocity;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (data.velocity && decay !== identity) {
|
|
458
|
+
data.velocity *= decay;
|
|
459
|
+
}
|
|
460
|
+
checkDestroy(particle, destroyType, data.value, minValue, maxValue);
|
|
461
|
+
if (!particle.destroyed) {
|
|
462
|
+
data.value = (0, NumberUtils_js_1.clamp)(data.value, minValue, maxValue);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
exports.updateAnimation = updateAnimation;
|
package/esm/Core/Canvas.js
CHANGED
|
@@ -3,9 +3,9 @@ import { deepExtend, getLogger, safeMutationObserver } from "../Utils/Utils.js";
|
|
|
3
3
|
import { getStyleFromHsl, getStyleFromRgb, rangeColorToHsl, rangeColorToRgb } from "../Utils/ColorUtils.js";
|
|
4
4
|
import { generatedAttribute } from "./Utils/Constants.js";
|
|
5
5
|
function setTransformValue(factor, newFactor, key) {
|
|
6
|
-
const newValue = newFactor[key];
|
|
6
|
+
const newValue = newFactor[key], defaultValue = 1;
|
|
7
7
|
if (newValue !== undefined) {
|
|
8
|
-
factor[key] = (factor[key] ??
|
|
8
|
+
factor[key] = (factor[key] ?? defaultValue) * newValue;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
export class Canvas {
|
|
@@ -13,7 +13,7 @@ export class Canvas {
|
|
|
13
13
|
this.container = container;
|
|
14
14
|
this._applyPostDrawUpdaters = (particle) => {
|
|
15
15
|
for (const updater of this._postDrawUpdaters) {
|
|
16
|
-
updater.afterDraw
|
|
16
|
+
updater.afterDraw?.(particle);
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
this._applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
@@ -33,12 +33,12 @@ export class Canvas {
|
|
|
33
33
|
setTransformValue(transform, updaterTransform, key);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
updater.beforeDraw
|
|
36
|
+
updater.beforeDraw?.(particle);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
this._applyResizePlugins = () => {
|
|
40
40
|
for (const plugin of this._resizePlugins) {
|
|
41
|
-
plugin.resize
|
|
41
|
+
plugin.resize?.();
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
this._getPluginParticleColors = (particle) => {
|
|
@@ -94,17 +94,17 @@ export class Canvas {
|
|
|
94
94
|
if (!trail.enable) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
+
const factorNumerator = 1, opacity = factorNumerator / trail.length;
|
|
97
98
|
if (trailFill.color) {
|
|
98
99
|
const fillColor = rangeColorToRgb(trailFill.color);
|
|
99
100
|
if (!fillColor) {
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
|
-
const trail = options.particles.move.trail;
|
|
103
103
|
this._trailFill = {
|
|
104
104
|
color: {
|
|
105
105
|
...fillColor,
|
|
106
106
|
},
|
|
107
|
-
opacity
|
|
107
|
+
opacity,
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
else {
|
|
@@ -116,7 +116,7 @@ export class Canvas {
|
|
|
116
116
|
img.addEventListener("load", () => {
|
|
117
117
|
this._trailFill = {
|
|
118
118
|
image: img,
|
|
119
|
-
opacity
|
|
119
|
+
opacity,
|
|
120
120
|
};
|
|
121
121
|
resolve();
|
|
122
122
|
});
|
|
@@ -167,9 +167,9 @@ export class Canvas {
|
|
|
167
167
|
if (!element) {
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
170
|
-
const priority = "important", style = element.style;
|
|
170
|
+
const priority = "important", style = element.style, radix = 10;
|
|
171
171
|
style.setProperty("position", "fixed", priority);
|
|
172
|
-
style.setProperty("z-index", this.container.actualOptions.fullScreen.zIndex.toString(
|
|
172
|
+
style.setProperty("z-index", this.container.actualOptions.fullScreen.zIndex.toString(radix), priority);
|
|
173
173
|
style.setProperty("top", "0", priority);
|
|
174
174
|
style.setProperty("left", "0", priority);
|
|
175
175
|
style.setProperty("width", "100%", priority);
|
|
@@ -190,11 +190,11 @@ export class Canvas {
|
|
|
190
190
|
return this.container.actualOptions.fullScreen.enable;
|
|
191
191
|
}
|
|
192
192
|
clear() {
|
|
193
|
-
const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill;
|
|
193
|
+
const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill, minimumLength = 0;
|
|
194
194
|
if (options.backgroundMask.enable) {
|
|
195
195
|
this.paint();
|
|
196
196
|
}
|
|
197
|
-
else if (trail.enable && trail.length >
|
|
197
|
+
else if (trail.enable && trail.length > minimumLength && trailFill) {
|
|
198
198
|
if (trailFill.color) {
|
|
199
199
|
this._paintBase(getStyleFromRgb(trailFill.color, trailFill.opacity));
|
|
200
200
|
}
|
|
@@ -212,7 +212,7 @@ export class Canvas {
|
|
|
212
212
|
this.stop();
|
|
213
213
|
if (this._generated) {
|
|
214
214
|
const element = this.element;
|
|
215
|
-
element
|
|
215
|
+
element?.remove();
|
|
216
216
|
}
|
|
217
217
|
else {
|
|
218
218
|
this._resetOriginalStyle();
|
|
@@ -233,8 +233,8 @@ export class Canvas {
|
|
|
233
233
|
if (particle.spawning || particle.destroyed) {
|
|
234
234
|
return;
|
|
235
235
|
}
|
|
236
|
-
const radius = particle.getRadius();
|
|
237
|
-
if (radius <=
|
|
236
|
+
const radius = particle.getRadius(), minimumSize = 0;
|
|
237
|
+
if (radius <= minimumSize) {
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
240
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor() ?? pfColor;
|
|
@@ -249,7 +249,7 @@ export class Canvas {
|
|
|
249
249
|
return;
|
|
250
250
|
}
|
|
251
251
|
this.draw((ctx) => {
|
|
252
|
-
const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex,
|
|
252
|
+
const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactorOffset = 1, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, defaultOpacity = 1, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
|
|
253
253
|
fill: fColor ? getStyleFromHsl(fColor, zOpacity) : undefined,
|
|
254
254
|
};
|
|
255
255
|
colorStyles.stroke = sColor ? getStyleFromHsl(sColor, zStrokeOpacity) : colorStyles.fill;
|
|
@@ -262,7 +262,7 @@ export class Canvas {
|
|
|
262
262
|
colorStyles,
|
|
263
263
|
backgroundMask: options.backgroundMask.enable,
|
|
264
264
|
composite: options.backgroundMask.composite,
|
|
265
|
-
radius: radius *
|
|
265
|
+
radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
|
|
266
266
|
opacity: zOpacity,
|
|
267
267
|
shadow: particle.options.shadow,
|
|
268
268
|
transform,
|
|
@@ -332,7 +332,7 @@ export class Canvas {
|
|
|
332
332
|
if (plugin.resize) {
|
|
333
333
|
this._resizePlugins.push(plugin);
|
|
334
334
|
}
|
|
335
|
-
if (plugin.particleFillColor
|
|
335
|
+
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
336
336
|
this._colorPlugins.push(plugin);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
@@ -344,7 +344,7 @@ export class Canvas {
|
|
|
344
344
|
if (updater.afterDraw) {
|
|
345
345
|
this._postDrawUpdaters.push(updater);
|
|
346
346
|
}
|
|
347
|
-
if (updater.getColorStyles
|
|
347
|
+
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
348
348
|
this._preDrawUpdaters.push(updater);
|
|
349
349
|
}
|
|
350
350
|
}
|