@fbltd/math 1.0.45 → 1.0.47
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/dist/bin/src/colors/color.js +16 -5
- package/dist/bin/src/colors/gradient/base.gradient.js +0 -4
- package/dist/bin/src/colors/gradient/conic.gradient.js +7 -0
- package/dist/types/src/colors/color.d.ts +7 -1
- package/dist/types/src/colors/gradient/conic.gradient.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { validateType } from "../type.utils.js";
|
|
2
2
|
import { denormalizeShade } from "./utils.js";
|
|
3
|
+
export var ColorStringFormat;
|
|
4
|
+
(function (ColorStringFormat) {
|
|
5
|
+
ColorStringFormat["RGBA"] = "rgba";
|
|
6
|
+
ColorStringFormat["HEX"] = "hex";
|
|
7
|
+
})(ColorStringFormat || (ColorStringFormat = {}));
|
|
3
8
|
export class Color {
|
|
4
9
|
_red;
|
|
5
10
|
_green;
|
|
@@ -42,7 +47,7 @@ export class Color {
|
|
|
42
47
|
[Symbol.toPrimitive]() {
|
|
43
48
|
return this.toString();
|
|
44
49
|
}
|
|
45
|
-
toString(format =
|
|
50
|
+
toString(format = ColorStringFormat.HEX) {
|
|
46
51
|
return Color.representation(this, format);
|
|
47
52
|
}
|
|
48
53
|
toNumber() {
|
|
@@ -63,14 +68,20 @@ export class Color {
|
|
|
63
68
|
static areEquals(c1, c2) {
|
|
64
69
|
return Color.toNumber(c1) === Color.toNumber(c2);
|
|
65
70
|
}
|
|
66
|
-
static representation(color, format =
|
|
71
|
+
static representation(color, format = ColorStringFormat.HEX) {
|
|
67
72
|
switch (format) {
|
|
68
|
-
case
|
|
73
|
+
case ColorStringFormat.RGBA:
|
|
69
74
|
return `rgba(${color.red},${color.green},${color.blue},${color.alpha})`;
|
|
70
|
-
case
|
|
71
|
-
return `#${color.red
|
|
75
|
+
case ColorStringFormat.HEX:
|
|
76
|
+
return `#${this.shadeToHexDigitsDenormalized(color.red)}${this.shadeToHexDigitsDenormalized(color.green)}${this.shadeToHexDigitsDenormalized(color.blue)}${this.shadeToHexDigitsNormalized(color.alpha)}`;
|
|
72
77
|
default:
|
|
73
78
|
validateType(format);
|
|
74
79
|
}
|
|
75
80
|
}
|
|
81
|
+
static shadeToHexDigitsNormalized(shade) {
|
|
82
|
+
return this.shadeToHexDigitsDenormalized(denormalizeShade(shade));
|
|
83
|
+
}
|
|
84
|
+
static shadeToHexDigitsDenormalized(shade) {
|
|
85
|
+
return shade.toString(16).padStart(2, '0');
|
|
86
|
+
}
|
|
76
87
|
}
|
|
@@ -4,10 +4,6 @@ export class BaseGradient {
|
|
|
4
4
|
colors;
|
|
5
5
|
constructor(...colors) {
|
|
6
6
|
this.colors = [...colors].sort((a, b) => a.percentage - b.percentage);
|
|
7
|
-
this.colors.push({
|
|
8
|
-
percentage: 1,
|
|
9
|
-
color: this.colors[0].color
|
|
10
|
-
});
|
|
11
7
|
}
|
|
12
8
|
/**
|
|
13
9
|
* Получить цвет по углу от оси X по часовой стрелке
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { BaseGradient } from "./base.gradient.js";
|
|
2
2
|
export class ConicGradient extends BaseGradient {
|
|
3
|
+
constructor(...colors) {
|
|
4
|
+
super(...colors);
|
|
5
|
+
this.colors.push({
|
|
6
|
+
percentage: 1,
|
|
7
|
+
color: this.colors[0].color
|
|
8
|
+
});
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* Для использования метода, углы должны быть в Turn единицах измерения
|
|
5
12
|
*/
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export declare enum ColorStringFormat {
|
|
2
|
+
RGBA = "rgba",
|
|
3
|
+
HEX = "hex"
|
|
4
|
+
}
|
|
1
5
|
export declare class Color {
|
|
2
6
|
private _red;
|
|
3
7
|
private _green;
|
|
@@ -20,5 +24,7 @@ export declare class Color {
|
|
|
20
24
|
static ofNumberAlpha(value: number): Color;
|
|
21
25
|
static toNumber(color: Color): number;
|
|
22
26
|
static areEquals(c1: Color, c2: Color): boolean;
|
|
23
|
-
static representation(color: Color, format?:
|
|
27
|
+
static representation(color: Color, format?: ColorStringFormat): string;
|
|
28
|
+
static shadeToHexDigitsNormalized(shade: number): string;
|
|
29
|
+
static shadeToHexDigitsDenormalized(shade: number): string;
|
|
24
30
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { IPoint2 } from "../../figures/index.ts";
|
|
2
2
|
import { BaseGradient } from "./base.gradient.ts";
|
|
3
|
+
import { Color } from "../color.js";
|
|
3
4
|
export declare class ConicGradient extends BaseGradient {
|
|
5
|
+
constructor(...colors: {
|
|
6
|
+
percentage: number;
|
|
7
|
+
color: Color;
|
|
8
|
+
}[]);
|
|
4
9
|
/**
|
|
5
10
|
* Для использования метода, углы должны быть в Turn единицах измерения
|
|
6
11
|
*/
|