@tsparticles/engine 3.0.2 → 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 +283 -163
- 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
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Vector3d = void 0;
|
|
4
4
|
const Constants_js_1 = require("./Constants.js");
|
|
5
5
|
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
6
|
+
const origin = {
|
|
7
|
+
x: 0,
|
|
8
|
+
y: 0,
|
|
9
|
+
z: 0,
|
|
10
|
+
}, squareExp = 2, inverseFactorNumerator = 1.0;
|
|
6
11
|
class Vector3d {
|
|
7
12
|
constructor(xOrCoords, y, z) {
|
|
8
13
|
this._updateFromAngle = (angle, length) => {
|
|
@@ -13,19 +18,19 @@ class Vector3d {
|
|
|
13
18
|
this.x = xOrCoords.x;
|
|
14
19
|
this.y = xOrCoords.y;
|
|
15
20
|
const coords3d = xOrCoords;
|
|
16
|
-
this.z = coords3d.z ? coords3d.z :
|
|
21
|
+
this.z = coords3d.z ? coords3d.z : origin.z;
|
|
17
22
|
}
|
|
18
23
|
else if (xOrCoords !== undefined && y !== undefined) {
|
|
19
24
|
this.x = xOrCoords;
|
|
20
25
|
this.y = y;
|
|
21
|
-
this.z = z ??
|
|
26
|
+
this.z = z ?? origin.z;
|
|
22
27
|
}
|
|
23
28
|
else {
|
|
24
29
|
throw new Error(`${Constants_js_1.errorPrefix} Vector3d not initialized correctly`);
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
static get origin() {
|
|
28
|
-
return Vector3d.create(
|
|
33
|
+
return Vector3d.create(origin.x, origin.y, origin.z);
|
|
29
34
|
}
|
|
30
35
|
get angle() {
|
|
31
36
|
return Math.atan2(this.y, this.x);
|
|
@@ -71,7 +76,7 @@ class Vector3d {
|
|
|
71
76
|
this.z /= n;
|
|
72
77
|
}
|
|
73
78
|
getLengthSq() {
|
|
74
|
-
return this.x **
|
|
79
|
+
return this.x ** squareExp + this.y ** squareExp;
|
|
75
80
|
}
|
|
76
81
|
mult(n) {
|
|
77
82
|
return Vector3d.create(this.x * n, this.y * n, this.z * n);
|
|
@@ -82,19 +87,19 @@ class Vector3d {
|
|
|
82
87
|
this.z *= n;
|
|
83
88
|
}
|
|
84
89
|
normalize() {
|
|
85
|
-
const length = this.length;
|
|
86
|
-
if (length !=
|
|
87
|
-
this.multTo(
|
|
90
|
+
const length = this.length, noLength = 0;
|
|
91
|
+
if (length != noLength) {
|
|
92
|
+
this.multTo(inverseFactorNumerator / length);
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
rotate(angle) {
|
|
91
|
-
return Vector3d.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle),
|
|
96
|
+
return Vector3d.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle), origin.z);
|
|
92
97
|
}
|
|
93
98
|
setTo(c) {
|
|
94
99
|
this.x = c.x;
|
|
95
100
|
this.y = c.y;
|
|
96
101
|
const v3d = c;
|
|
97
|
-
this.z = v3d.z ? v3d.z :
|
|
102
|
+
this.z = v3d.z ? v3d.z : origin.z;
|
|
98
103
|
}
|
|
99
104
|
sub(v) {
|
|
100
105
|
return Vector3d.create(this.x - v.x, this.y - v.y, this.z - v.z);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ManualParticle = void 0;
|
|
4
4
|
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
5
|
+
const defaultPosition = 50;
|
|
5
6
|
class ManualParticle {
|
|
6
7
|
load(data) {
|
|
7
8
|
if (!data) {
|
|
@@ -9,8 +10,8 @@ class ManualParticle {
|
|
|
9
10
|
}
|
|
10
11
|
if (data.position) {
|
|
11
12
|
this.position = {
|
|
12
|
-
x: data.position.x ??
|
|
13
|
-
y: data.position.y ??
|
|
13
|
+
x: data.position.x ?? defaultPosition,
|
|
14
|
+
y: data.position.y ?? defaultPosition,
|
|
14
15
|
mode: data.position.mode ?? "percent",
|
|
15
16
|
};
|
|
16
17
|
}
|
package/cjs/Utils/CanvasUtils.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.alterHsl = exports.drawParticlePlugin = exports.drawPlugin = exports.drawShapeAfterDraw = exports.drawShape = exports.drawEffect = exports.drawParticle = exports.clear = exports.paintImage = exports.paintBase = exports.drawLine = void 0;
|
|
4
4
|
const ColorUtils_js_1 = require("./ColorUtils.js");
|
|
5
|
+
const origin = { x: 0, y: 0 };
|
|
5
6
|
function drawLine(context, begin, end) {
|
|
6
7
|
context.beginPath();
|
|
7
8
|
context.moveTo(begin.x, begin.y);
|
|
@@ -11,7 +12,7 @@ function drawLine(context, begin, end) {
|
|
|
11
12
|
exports.drawLine = drawLine;
|
|
12
13
|
function paintBase(context, dimension, baseColor) {
|
|
13
14
|
context.fillStyle = baseColor ?? "rgba(0,0,0,0)";
|
|
14
|
-
context.fillRect(
|
|
15
|
+
context.fillRect(origin.x, origin.y, dimension.width, dimension.height);
|
|
15
16
|
}
|
|
16
17
|
exports.paintBase = paintBase;
|
|
17
18
|
function paintImage(context, dimension, image, opacity) {
|
|
@@ -19,24 +20,23 @@ function paintImage(context, dimension, image, opacity) {
|
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
context.globalAlpha = opacity;
|
|
22
|
-
context.drawImage(image,
|
|
23
|
+
context.drawImage(image, origin.x, origin.y, dimension.width, dimension.height);
|
|
23
24
|
context.globalAlpha = 1;
|
|
24
25
|
}
|
|
25
26
|
exports.paintImage = paintImage;
|
|
26
27
|
function clear(context, dimension) {
|
|
27
|
-
context.clearRect(
|
|
28
|
+
context.clearRect(origin.x, origin.y, dimension.width, dimension.height);
|
|
28
29
|
}
|
|
29
30
|
exports.clear = clear;
|
|
30
31
|
function drawParticle(data) {
|
|
31
|
-
const { container, context, particle, delta, colorStyles, backgroundMask, composite, radius, opacity, shadow, transform, } = data
|
|
32
|
-
const pos = particle.getPosition(), angle = particle.rotation + (particle.pathRotation ? particle.velocity.angle : 0), rotateData = {
|
|
32
|
+
const { container, context, particle, delta, colorStyles, backgroundMask, composite, radius, opacity, shadow, transform, } = data, pos = particle.getPosition(), defaultAngle = 0, angle = particle.rotation + (particle.pathRotation ? particle.velocity.angle : defaultAngle), rotateData = {
|
|
33
33
|
sin: Math.sin(angle),
|
|
34
34
|
cos: Math.cos(angle),
|
|
35
|
-
}, transformData = {
|
|
36
|
-
a: rotateData.cos * (transform.a ??
|
|
37
|
-
b: rotateData.sin * (transform.b ??
|
|
38
|
-
c: -rotateData.sin * (transform.c ??
|
|
39
|
-
d: rotateData.cos * (transform.d ??
|
|
35
|
+
}, defaultTransformFactor = 1, transformData = {
|
|
36
|
+
a: rotateData.cos * (transform.a ?? defaultTransformFactor),
|
|
37
|
+
b: rotateData.sin * (transform.b ?? defaultTransformFactor),
|
|
38
|
+
c: -rotateData.sin * (transform.c ?? defaultTransformFactor),
|
|
39
|
+
d: rotateData.cos * (transform.d ?? defaultTransformFactor),
|
|
40
40
|
};
|
|
41
41
|
context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
|
|
42
42
|
if (backgroundMask) {
|
|
@@ -52,27 +52,26 @@ function drawParticle(data) {
|
|
|
52
52
|
if (colorStyles.fill) {
|
|
53
53
|
context.fillStyle = colorStyles.fill;
|
|
54
54
|
}
|
|
55
|
-
const strokeWidth = particle.strokeWidth ??
|
|
55
|
+
const minStrokeWidth = 0, strokeWidth = particle.strokeWidth ?? minStrokeWidth;
|
|
56
56
|
context.lineWidth = strokeWidth;
|
|
57
57
|
if (colorStyles.stroke) {
|
|
58
58
|
context.strokeStyle = colorStyles.stroke;
|
|
59
59
|
}
|
|
60
|
-
const drawData = {
|
|
61
|
-
|
|
60
|
+
const drawData = {
|
|
61
|
+
container,
|
|
62
|
+
context,
|
|
63
|
+
particle,
|
|
64
|
+
radius,
|
|
65
|
+
opacity,
|
|
66
|
+
delta,
|
|
67
|
+
transformData,
|
|
68
|
+
strokeWidth,
|
|
69
|
+
};
|
|
62
70
|
drawShape(drawData);
|
|
63
|
-
if (particle.shapeClose) {
|
|
64
|
-
context.closePath();
|
|
65
|
-
}
|
|
66
|
-
if (strokeWidth > 0) {
|
|
67
|
-
context.stroke();
|
|
68
|
-
}
|
|
69
|
-
if (particle.shapeFill) {
|
|
70
|
-
context.fill();
|
|
71
|
-
}
|
|
72
71
|
drawShapeAfterDraw(drawData);
|
|
73
72
|
drawEffect(drawData);
|
|
74
73
|
context.globalCompositeOperation = "source-over";
|
|
75
|
-
context.
|
|
74
|
+
context.resetTransform();
|
|
76
75
|
}
|
|
77
76
|
exports.drawParticle = drawParticle;
|
|
78
77
|
function drawEffect(data) {
|
|
@@ -96,7 +95,7 @@ function drawEffect(data) {
|
|
|
96
95
|
}
|
|
97
96
|
exports.drawEffect = drawEffect;
|
|
98
97
|
function drawShape(data) {
|
|
99
|
-
const { container, context, particle, radius, opacity, delta, transformData } = data;
|
|
98
|
+
const { container, context, particle, radius, opacity, delta, strokeWidth, transformData } = data, minStrokeWidth = 0;
|
|
100
99
|
if (!particle.shape) {
|
|
101
100
|
return;
|
|
102
101
|
}
|
|
@@ -104,6 +103,7 @@ function drawShape(data) {
|
|
|
104
103
|
if (!drawer) {
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
106
|
+
context.beginPath();
|
|
107
107
|
drawer.draw({
|
|
108
108
|
context,
|
|
109
109
|
particle,
|
|
@@ -113,6 +113,15 @@ function drawShape(data) {
|
|
|
113
113
|
pixelRatio: container.retina.pixelRatio,
|
|
114
114
|
transformData: { ...transformData },
|
|
115
115
|
});
|
|
116
|
+
if (particle.shapeClose) {
|
|
117
|
+
context.closePath();
|
|
118
|
+
}
|
|
119
|
+
if (strokeWidth > minStrokeWidth) {
|
|
120
|
+
context.stroke();
|
|
121
|
+
}
|
|
122
|
+
if (particle.shapeFill) {
|
|
123
|
+
context.fill();
|
|
124
|
+
}
|
|
116
125
|
}
|
|
117
126
|
exports.drawShape = drawShape;
|
|
118
127
|
function drawShapeAfterDraw(data) {
|
|
@@ -121,7 +130,7 @@ function drawShapeAfterDraw(data) {
|
|
|
121
130
|
return;
|
|
122
131
|
}
|
|
123
132
|
const drawer = container.shapeDrawers.get(particle.shape);
|
|
124
|
-
if (!drawer
|
|
133
|
+
if (!drawer?.afterDraw) {
|
|
125
134
|
return;
|
|
126
135
|
}
|
|
127
136
|
drawer.afterDraw({
|
|
@@ -150,10 +159,11 @@ function drawParticlePlugin(context, plugin, particle, delta) {
|
|
|
150
159
|
}
|
|
151
160
|
exports.drawParticlePlugin = drawParticlePlugin;
|
|
152
161
|
function alterHsl(color, type, value) {
|
|
162
|
+
const lFactor = 1;
|
|
153
163
|
return {
|
|
154
164
|
h: color.h,
|
|
155
165
|
s: color.s,
|
|
156
|
-
l: color.l + (type === "darken" ? -
|
|
166
|
+
l: color.l + (type === "darken" ? -lFactor : lFactor) * value,
|
|
157
167
|
};
|
|
158
168
|
}
|
|
159
169
|
exports.alterHsl = alterHsl;
|
package/cjs/Utils/ColorUtils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHslAnimationFromHsl = exports.getHslFromAnimation = exports.getLinkRandomColor = exports.getLinkColor = exports.colorMix = exports.getStyleFromHsl = exports.getStyleFromRgb = exports.getRandomRgbColor = exports.hslaToRgba = exports.hslToRgb = exports.stringToRgb = exports.stringToAlpha = exports.rgbToHsl = exports.rangeColorToHsl = exports.colorToHsl = exports.colorToRgb = exports.rangeColorToRgb = exports.addColorManager = void 0;
|
|
3
|
+
exports.updateColor = exports.updateColorValue = exports.getHslAnimationFromHsl = exports.getHslFromAnimation = exports.getLinkRandomColor = exports.getLinkColor = exports.colorMix = exports.getStyleFromHsl = exports.getStyleFromRgb = exports.getRandomRgbColor = exports.hslaToRgba = exports.hslToRgb = exports.stringToRgb = exports.stringToAlpha = exports.rgbToHsl = exports.rangeColorToHsl = exports.colorToHsl = exports.colorToRgb = exports.rangeColorToRgb = exports.addColorManager = void 0;
|
|
4
4
|
const NumberUtils_js_1 = require("./NumberUtils.js");
|
|
5
5
|
const Utils_js_1 = require("./Utils.js");
|
|
6
|
+
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
6
7
|
const randomColorValue = "random", midColorValue = "mid", colorManagers = new Map();
|
|
7
8
|
function addColorManager(manager) {
|
|
8
9
|
colorManagers.set(manager.key, manager);
|
|
@@ -16,13 +17,15 @@ function stringToRgba(input) {
|
|
|
16
17
|
}
|
|
17
18
|
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexFixed = input.replace(shorthandRegex, (_, r, g, b, a) => {
|
|
18
19
|
return r + r + g + g + b + b + (a !== undefined ? a + a : "");
|
|
19
|
-
}), regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, result = regex.exec(hexFixed);
|
|
20
|
+
}), regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, result = regex.exec(hexFixed), radix = 16, defaultAlpha = 1, alphaFactor = 0xff;
|
|
20
21
|
return result
|
|
21
22
|
? {
|
|
22
|
-
a: result[4] !== undefined
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
a: result[4] !== undefined
|
|
24
|
+
? parseInt(result[4], radix) / alphaFactor
|
|
25
|
+
: defaultAlpha,
|
|
26
|
+
b: parseInt(result[3], radix),
|
|
27
|
+
g: parseInt(result[2], radix),
|
|
28
|
+
r: parseInt(result[1], radix),
|
|
26
29
|
}
|
|
27
30
|
: undefined;
|
|
28
31
|
}
|
|
@@ -79,26 +82,26 @@ function rangeColorToHsl(color, index, useIndex = true) {
|
|
|
79
82
|
}
|
|
80
83
|
exports.rangeColorToHsl = rangeColorToHsl;
|
|
81
84
|
function rgbToHsl(color) {
|
|
82
|
-
const r1 = color.r /
|
|
83
|
-
h:
|
|
84
|
-
l: (max + min) *
|
|
85
|
-
s:
|
|
85
|
+
const rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, half = 0.5, double = 2, r1 = color.r / rgbMax, g1 = color.g / rgbMax, b1 = color.b / rgbMax, max = Math.max(r1, g1, b1), min = Math.min(r1, g1, b1), res = {
|
|
86
|
+
h: hMin,
|
|
87
|
+
l: (max + min) * half,
|
|
88
|
+
s: sMin,
|
|
86
89
|
};
|
|
87
90
|
if (max !== min) {
|
|
88
|
-
res.s = res.l <
|
|
91
|
+
res.s = res.l < half ? (max - min) / (max + min) : (max - min) / (double - max - min);
|
|
89
92
|
res.h =
|
|
90
93
|
r1 === max
|
|
91
94
|
? (g1 - b1) / (max - min)
|
|
92
|
-
: (res.h = g1 === max ?
|
|
95
|
+
: (res.h = g1 === max ? double + (b1 - r1) / (max - min) : double * double + (r1 - g1) / (max - min));
|
|
93
96
|
}
|
|
94
|
-
res.l *=
|
|
95
|
-
res.s *=
|
|
96
|
-
res.h *=
|
|
97
|
-
if (res.h <
|
|
98
|
-
res.h +=
|
|
97
|
+
res.l *= lMax;
|
|
98
|
+
res.s *= sMax;
|
|
99
|
+
res.h *= hPhase;
|
|
100
|
+
if (res.h < hMin) {
|
|
101
|
+
res.h += hMax;
|
|
99
102
|
}
|
|
100
|
-
if (res.h >=
|
|
101
|
-
res.h -=
|
|
103
|
+
if (res.h >= hMax) {
|
|
104
|
+
res.h -= hMax;
|
|
102
105
|
}
|
|
103
106
|
return res;
|
|
104
107
|
}
|
|
@@ -112,29 +115,33 @@ function stringToRgb(input) {
|
|
|
112
115
|
}
|
|
113
116
|
exports.stringToRgb = stringToRgb;
|
|
114
117
|
function hslToRgb(hsl) {
|
|
115
|
-
const h = ((hsl.h %
|
|
116
|
-
if (s ===
|
|
117
|
-
const grayscaleValue = Math.round(lNormalized *
|
|
118
|
+
const hMax = 360, sMax = 100, lMax = 100, sMin = 0, lMin = 0, h = ((hsl.h % hMax) + hMax) % hMax, s = Math.max(sMin, Math.min(sMax, hsl.s)), l = Math.max(lMin, Math.min(lMax, hsl.l)), hNormalized = h / hMax, sNormalized = s / sMax, lNormalized = l / lMax, rgbFactor = 255, triple = 3;
|
|
119
|
+
if (s === sMin) {
|
|
120
|
+
const grayscaleValue = Math.round(lNormalized * rgbFactor);
|
|
118
121
|
return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
|
|
119
122
|
}
|
|
120
|
-
const channel = (temp1, temp2, temp3) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
const half = 0.5, double = 2, channel = (temp1, temp2, temp3) => {
|
|
124
|
+
const temp3Min = 0, temp3Max = 1, sextuple = 6;
|
|
125
|
+
if (temp3 < temp3Min) {
|
|
126
|
+
temp3++;
|
|
123
127
|
}
|
|
124
|
-
if (temp3 >
|
|
125
|
-
temp3
|
|
128
|
+
if (temp3 > temp3Max) {
|
|
129
|
+
temp3--;
|
|
126
130
|
}
|
|
127
|
-
if (temp3 *
|
|
128
|
-
return temp1 + (temp2 - temp1) *
|
|
131
|
+
if (temp3 * sextuple < temp3Max) {
|
|
132
|
+
return temp1 + (temp2 - temp1) * sextuple * temp3;
|
|
129
133
|
}
|
|
130
|
-
if (temp3 *
|
|
134
|
+
if (temp3 * double < temp3Max) {
|
|
131
135
|
return temp2;
|
|
132
136
|
}
|
|
133
|
-
if (temp3 *
|
|
134
|
-
|
|
137
|
+
if (temp3 * triple < temp3Max * double) {
|
|
138
|
+
const temp3Offset = double / triple;
|
|
139
|
+
return temp1 + (temp2 - temp1) * (temp3Offset - temp3) * sextuple;
|
|
135
140
|
}
|
|
136
141
|
return temp1;
|
|
137
|
-
},
|
|
142
|
+
}, sNormalizedOffset = 1, temp1 = lNormalized < half
|
|
143
|
+
? lNormalized * (sNormalizedOffset + sNormalized)
|
|
144
|
+
: lNormalized + sNormalized - lNormalized * sNormalized, temp2 = double * lNormalized - temp1, phaseNumerator = 1, phaseThird = phaseNumerator / triple, red = Math.min(rgbFactor, rgbFactor * channel(temp2, temp1, hNormalized + phaseThird)), green = Math.min(rgbFactor, rgbFactor * channel(temp2, temp1, hNormalized)), blue = Math.min(rgbFactor, rgbFactor * channel(temp2, temp1, hNormalized - phaseThird));
|
|
138
145
|
return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
|
|
139
146
|
}
|
|
140
147
|
exports.hslToRgb = hslToRgb;
|
|
@@ -149,20 +156,22 @@ function hslaToRgba(hsla) {
|
|
|
149
156
|
}
|
|
150
157
|
exports.hslaToRgba = hslaToRgba;
|
|
151
158
|
function getRandomRgbColor(min) {
|
|
152
|
-
const fixedMin = min ??
|
|
159
|
+
const defaultMin = 0, fixedMin = min ?? defaultMin, rgbMax = 256;
|
|
153
160
|
return {
|
|
154
|
-
b: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin,
|
|
155
|
-
g: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin,
|
|
156
|
-
r: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin,
|
|
161
|
+
b: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, rgbMax))),
|
|
162
|
+
g: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, rgbMax))),
|
|
163
|
+
r: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, rgbMax))),
|
|
157
164
|
};
|
|
158
165
|
}
|
|
159
166
|
exports.getRandomRgbColor = getRandomRgbColor;
|
|
160
167
|
function getStyleFromRgb(color, opacity) {
|
|
161
|
-
|
|
168
|
+
const defaultOpacity = 1;
|
|
169
|
+
return `rgba(${color.r}, ${color.g}, ${color.b}, ${opacity ?? defaultOpacity})`;
|
|
162
170
|
}
|
|
163
171
|
exports.getStyleFromRgb = getStyleFromRgb;
|
|
164
172
|
function getStyleFromHsl(color, opacity) {
|
|
165
|
-
|
|
173
|
+
const defaultOpacity = 1;
|
|
174
|
+
return `hsla(${color.h}, ${color.s}%, ${color.l}%, ${opacity ?? defaultOpacity})`;
|
|
166
175
|
}
|
|
167
176
|
exports.getStyleFromHsl = getStyleFromHsl;
|
|
168
177
|
function colorMix(color1, color2, size1, size2) {
|
|
@@ -259,21 +268,93 @@ function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
|
|
259
268
|
exports.getHslAnimationFromHsl = getHslAnimationFromHsl;
|
|
260
269
|
function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
|
261
270
|
colorValue.enable = colorAnimation.enable;
|
|
271
|
+
const defaultVelocity = 0, decayOffset = 1, defaultLoops = 0, defaultTime = 0;
|
|
262
272
|
if (colorValue.enable) {
|
|
263
|
-
colorValue.velocity = ((0, NumberUtils_js_1.getRangeValue)(colorAnimation.speed) /
|
|
264
|
-
colorValue.decay =
|
|
273
|
+
colorValue.velocity = ((0, NumberUtils_js_1.getRangeValue)(colorAnimation.speed) / Constants_js_1.percentDenominator) * reduceFactor;
|
|
274
|
+
colorValue.decay = decayOffset - (0, NumberUtils_js_1.getRangeValue)(colorAnimation.decay);
|
|
265
275
|
colorValue.status = "increasing";
|
|
266
|
-
colorValue.loops =
|
|
276
|
+
colorValue.loops = defaultLoops;
|
|
267
277
|
colorValue.maxLoops = (0, NumberUtils_js_1.getRangeValue)(colorAnimation.count);
|
|
268
|
-
colorValue.time =
|
|
269
|
-
colorValue.delayTime = (0, NumberUtils_js_1.getRangeValue)(colorAnimation.delay) *
|
|
278
|
+
colorValue.time = defaultTime;
|
|
279
|
+
colorValue.delayTime = (0, NumberUtils_js_1.getRangeValue)(colorAnimation.delay) * Constants_js_1.millisecondsToSeconds;
|
|
270
280
|
if (!colorAnimation.sync) {
|
|
271
281
|
colorValue.velocity *= (0, NumberUtils_js_1.getRandom)();
|
|
272
282
|
colorValue.value *= (0, NumberUtils_js_1.getRandom)();
|
|
273
283
|
}
|
|
274
284
|
colorValue.initialValue = colorValue.value;
|
|
285
|
+
colorValue.offset = (0, NumberUtils_js_1.setRangeValue)(colorAnimation.offset);
|
|
275
286
|
}
|
|
276
287
|
else {
|
|
277
|
-
colorValue.velocity =
|
|
288
|
+
colorValue.velocity = defaultVelocity;
|
|
278
289
|
}
|
|
279
290
|
}
|
|
291
|
+
function updateColorValue(data, range, decrease, delta) {
|
|
292
|
+
const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
|
|
293
|
+
if (!data ||
|
|
294
|
+
!data.enable ||
|
|
295
|
+
((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (!data.time) {
|
|
299
|
+
data.time = 0;
|
|
300
|
+
}
|
|
301
|
+
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
302
|
+
data.time += delta.value;
|
|
303
|
+
}
|
|
304
|
+
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const offset = data.offset ? (0, NumberUtils_js_1.randomInRange)(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = (0, NumberUtils_js_1.getRangeMax)(range), min = (0, NumberUtils_js_1.getRangeMin)(range);
|
|
308
|
+
if (!decrease || data.status === "increasing") {
|
|
309
|
+
data.value += velocity;
|
|
310
|
+
if (data.value > max) {
|
|
311
|
+
if (!data.loops) {
|
|
312
|
+
data.loops = 0;
|
|
313
|
+
}
|
|
314
|
+
data.loops++;
|
|
315
|
+
if (decrease) {
|
|
316
|
+
data.status = "decreasing";
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
data.value -= max;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
data.value -= velocity;
|
|
325
|
+
const minValue = 0;
|
|
326
|
+
if (data.value < minValue) {
|
|
327
|
+
if (!data.loops) {
|
|
328
|
+
data.loops = 0;
|
|
329
|
+
}
|
|
330
|
+
data.loops++;
|
|
331
|
+
data.status = "increasing";
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (data.velocity && decay !== identity) {
|
|
335
|
+
data.velocity *= decay;
|
|
336
|
+
}
|
|
337
|
+
data.value = (0, NumberUtils_js_1.clamp)(data.value, min, max);
|
|
338
|
+
}
|
|
339
|
+
exports.updateColorValue = updateColorValue;
|
|
340
|
+
function updateColor(color, delta) {
|
|
341
|
+
if (!color) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const { h, s, l } = color;
|
|
345
|
+
const ranges = {
|
|
346
|
+
h: { min: 0, max: 360 },
|
|
347
|
+
s: { min: 0, max: 100 },
|
|
348
|
+
l: { min: 0, max: 100 },
|
|
349
|
+
};
|
|
350
|
+
if (h) {
|
|
351
|
+
updateColorValue(h, ranges.h, false, delta);
|
|
352
|
+
}
|
|
353
|
+
if (s) {
|
|
354
|
+
updateColorValue(s, ranges.s, true, delta);
|
|
355
|
+
}
|
|
356
|
+
if (l) {
|
|
357
|
+
updateColorValue(l, ranges.l, true, delta);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
exports.updateColor = updateColor;
|
|
@@ -16,7 +16,7 @@ class EventDispatcher {
|
|
|
16
16
|
}
|
|
17
17
|
dispatchEvent(type, args) {
|
|
18
18
|
const listeners = this._listeners.get(type);
|
|
19
|
-
listeners
|
|
19
|
+
listeners?.forEach((handler) => handler(args));
|
|
20
20
|
}
|
|
21
21
|
hasEventListener(type) {
|
|
22
22
|
return !!this._listeners.get(type);
|
|
@@ -34,15 +34,16 @@ class EventDispatcher {
|
|
|
34
34
|
if (!arr) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const length = arr.length, idx = arr.indexOf(listener);
|
|
38
|
-
if (idx <
|
|
37
|
+
const length = arr.length, idx = arr.indexOf(listener), minIndex = 0;
|
|
38
|
+
if (idx < minIndex) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
const deleteCount = 1;
|
|
42
|
+
if (length === deleteCount) {
|
|
42
43
|
this._listeners.delete(type);
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
|
-
arr.splice(idx,
|
|
46
|
+
arr.splice(idx, deleteCount);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
}
|
|
@@ -28,13 +28,13 @@ class HslColorManager {
|
|
|
28
28
|
if (!input.startsWith("hsl")) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
const regex = /hsla?\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.%]+)\s*)?\)/i, result = regex.exec(input);
|
|
31
|
+
const regex = /hsla?\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.%]+)\s*)?\)/i, result = regex.exec(input), minLength = 4, defaultAlpha = 1, radix = 10;
|
|
32
32
|
return result
|
|
33
33
|
? (0, ColorUtils_js_1.hslaToRgba)({
|
|
34
|
-
a: result.length >
|
|
35
|
-
h: parseInt(result[1],
|
|
36
|
-
l: parseInt(result[3],
|
|
37
|
-
s: parseInt(result[2],
|
|
34
|
+
a: result.length > minLength ? (0, NumberUtils_js_1.parseAlpha)(result[5]) : defaultAlpha,
|
|
35
|
+
h: parseInt(result[1], radix),
|
|
36
|
+
l: parseInt(result[3], radix),
|
|
37
|
+
s: parseInt(result[2], radix),
|
|
38
38
|
})
|
|
39
39
|
: undefined;
|
|
40
40
|
}
|