@oscarpalmer/atoms 0.186.2 → 0.187.1
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/array/filter.d.mts +4 -4
- package/dist/array/find.d.mts +4 -4
- package/dist/array/first.d.mts +4 -4
- package/dist/array/get.d.mts +27 -1
- package/dist/array/get.mjs +5 -3
- package/dist/array/group-by.d.mts +6 -6
- package/dist/array/last.d.mts +4 -4
- package/dist/array/match.d.mts +7 -6
- package/dist/array/move.d.mts +7 -7
- package/dist/array/move.mjs +1 -1
- package/dist/array/select.d.mts +1 -0
- package/dist/array/slice.d.mts +3 -3
- package/dist/array/sort.d.mts +10 -7
- package/dist/array/sort.mjs +4 -3
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/swap.mjs +1 -1
- package/dist/array/to-map.d.mts +32 -32
- package/dist/array/to-record.d.mts +6 -6
- package/dist/array/to-set.d.mts +6 -6
- package/dist/beacon.d.mts +6 -0
- package/dist/beacon.mjs +3 -0
- package/dist/color/index.d.mts +6 -2
- package/dist/color/index.mjs +6 -2
- package/dist/color/instance.d.mts +78 -14
- package/dist/color/instance.mjs +78 -14
- package/dist/color/misc/get.d.mts +39 -11
- package/dist/color/misc/get.mjs +39 -11
- package/dist/color/misc/is.d.mts +26 -11
- package/dist/color/misc/is.mjs +26 -11
- package/dist/color/misc/state.mjs +1 -1
- package/dist/color/models.d.mts +7 -4
- package/dist/color/space/hex.d.mts +15 -6
- package/dist/color/space/hex.mjs +15 -6
- package/dist/color/space/hsl.d.mts +10 -4
- package/dist/color/space/hsl.mjs +10 -4
- package/dist/color/space/rgb.d.mts +21 -12
- package/dist/color/space/rgb.mjs +21 -12
- package/dist/function/assert.d.mts +20 -14
- package/dist/function/assert.mjs +19 -13
- package/dist/function/limit.d.mts +8 -6
- package/dist/function/limit.mjs +8 -6
- package/dist/function/memoize.d.mts +15 -4
- package/dist/function/memoize.mjs +18 -4
- package/dist/function/once.d.mts +5 -3
- package/dist/function/once.mjs +5 -3
- package/dist/function/retry.d.mts +5 -2
- package/dist/function/retry.mjs +3 -1
- package/dist/function/work.d.mts +146 -98
- package/dist/{kalas.d.mts → herald.d.mts} +17 -8
- package/dist/{kalas.mjs → herald.mjs} +22 -13
- package/dist/index.d.mts +1464 -708
- package/dist/index.mjs +703 -342
- package/dist/internal/array/index-of.d.mts +4 -4
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/shuffle.d.mts +1 -0
- package/dist/internal/array/shuffle.mjs +2 -1
- package/dist/internal/is.d.mts +26 -8
- package/dist/internal/is.mjs +26 -8
- package/dist/internal/math/aggregate.d.mts +9 -9
- package/dist/internal/number.d.mts +13 -2
- package/dist/internal/number.mjs +13 -2
- package/dist/internal/random.d.mts +4 -2
- package/dist/internal/random.mjs +7 -5
- package/dist/internal/result.d.mts +17 -11
- package/dist/internal/result.mjs +10 -14
- package/dist/internal/string.d.mts +16 -1
- package/dist/internal/string.mjs +24 -1
- package/dist/internal/value/compare.d.mts +5 -2
- package/dist/internal/value/compare.mjs +5 -2
- package/dist/internal/value/equal.d.mts +12 -3
- package/dist/internal/value/equal.mjs +7 -4
- package/dist/internal/value/get.d.mts +17 -17
- package/dist/internal/value/has.d.mts +55 -11
- package/dist/internal/value/set.d.mts +24 -0
- package/dist/internal/value/set.mjs +1 -1
- package/dist/is.d.mts +12 -0
- package/dist/is.mjs +16 -1
- package/dist/logger.d.mts +7 -6
- package/dist/logger.mjs +6 -5
- package/dist/math.d.mts +36 -18
- package/dist/math.mjs +6 -3
- package/dist/models.d.mts +3 -3
- package/dist/promise/delay.d.mts +2 -0
- package/dist/promise/helpers.d.mts +6 -4
- package/dist/promise/helpers.mjs +6 -4
- package/dist/promise/index.d.mts +49 -38
- package/dist/promise/misc.d.mts +10 -7
- package/dist/promise/misc.mjs +4 -3
- package/dist/promise/models.d.mts +18 -19
- package/dist/promise/models.mjs +4 -3
- package/dist/promise/timed.d.mts +8 -6
- package/dist/query.d.mts +2 -0
- package/dist/query.mjs +27 -17
- package/dist/queue.d.mts +15 -4
- package/dist/queue.mjs +10 -3
- package/dist/random.d.mts +9 -2
- package/dist/random.mjs +7 -2
- package/dist/result/index.d.mts +14 -8
- package/dist/result/match.d.mts +18 -10
- package/dist/result/misc.d.mts +14 -7
- package/dist/result/misc.mjs +4 -2
- package/dist/result/models.d.mts +2 -0
- package/dist/result/work/flow.d.mts +86 -62
- package/dist/result/work/pipe.d.mts +55 -33
- package/dist/sized/map.d.mts +19 -16
- package/dist/sized/map.mjs +4 -4
- package/dist/sized/set.d.mts +20 -16
- package/dist/sized/set.mjs +8 -7
- package/dist/string/case.d.mts +8 -0
- package/dist/string/case.mjs +8 -0
- package/dist/string/fuzzy.d.mts +19 -5
- package/dist/string/fuzzy.mjs +7 -0
- package/dist/string/index.d.mts +17 -2
- package/dist/string/index.mjs +7 -9
- package/dist/string/match.d.mts +3 -0
- package/dist/string/match.mjs +3 -0
- package/dist/string/normalize.d.mts +6 -2
- package/dist/string/normalize.mjs +5 -2
- package/dist/string/template.d.mts +38 -9
- package/dist/string/template.mjs +19 -19
- package/dist/value/clone.d.mts +25 -4
- package/dist/value/clone.mjs +36 -22
- package/dist/value/collection.d.mts +9 -6
- package/dist/value/collection.mjs +3 -2
- package/dist/value/diff.d.mts +3 -1
- package/dist/value/diff.mjs +1 -0
- package/dist/value/freeze.d.mts +118 -9
- package/dist/value/freeze.mjs +56 -14
- package/dist/value/index.d.mts +1 -2
- package/dist/value/index.mjs +1 -2
- package/dist/value/merge.d.mts +11 -5
- package/dist/value/merge.mjs +2 -2
- package/dist/value/omit.d.mts +1 -0
- package/dist/value/omit.mjs +1 -0
- package/dist/value/pick.d.mts +1 -0
- package/dist/value/pick.mjs +1 -0
- package/dist/value/shake.d.mts +1 -0
- package/dist/value/shake.mjs +1 -0
- package/dist/value/smush.d.mts +1 -0
- package/dist/value/smush.mjs +1 -0
- package/dist/value/transform.d.mts +7 -3
- package/dist/value/unsmush.d.mts +1 -0
- package/dist/value/unsmush.mjs +1 -0
- package/package.json +12 -8
- package/src/array/filter.ts +4 -4
- package/src/array/find.ts +4 -4
- package/src/array/first.ts +4 -4
- package/src/array/get.ts +40 -5
- package/src/array/group-by.ts +6 -6
- package/src/array/last.ts +4 -4
- package/src/array/match.ts +7 -6
- package/src/array/move.ts +7 -7
- package/src/array/select.ts +1 -0
- package/src/array/slice.ts +3 -3
- package/src/array/sort.ts +15 -10
- package/src/array/swap.ts +1 -1
- package/src/array/to-map.ts +32 -32
- package/src/array/to-record.ts +6 -6
- package/src/array/to-set.ts +6 -6
- package/src/beacon.ts +6 -0
- package/src/color/index.ts +6 -2
- package/src/color/instance.ts +78 -14
- package/src/color/misc/get.ts +39 -11
- package/src/color/misc/is.ts +26 -11
- package/src/color/misc/state.ts +1 -1
- package/src/color/models.ts +7 -4
- package/src/color/space/hex.ts +15 -6
- package/src/color/space/hsl.ts +10 -4
- package/src/color/space/rgb.ts +21 -12
- package/src/function/assert.ts +20 -14
- package/src/function/limit.ts +8 -6
- package/src/function/memoize.ts +24 -5
- package/src/function/once.ts +5 -3
- package/src/function/retry.ts +7 -3
- package/src/function/work.ts +146 -98
- package/src/{kalas.ts → herald.ts} +23 -14
- package/src/index.ts +3 -2
- package/src/internal/array/index-of.ts +4 -4
- package/src/internal/array/insert.ts +1 -1
- package/src/internal/array/shuffle.ts +2 -1
- package/src/internal/is.ts +26 -8
- package/src/internal/math/aggregate.ts +9 -9
- package/src/internal/number.ts +13 -2
- package/src/internal/random.ts +10 -4
- package/src/internal/result.ts +30 -29
- package/src/internal/string.ts +28 -0
- package/src/internal/value/compare.ts +5 -2
- package/src/internal/value/equal.ts +13 -4
- package/src/internal/value/get.ts +17 -17
- package/src/internal/value/has.ts +54 -11
- package/src/internal/value/set.ts +25 -1
- package/src/is.ts +15 -1
- package/src/logger.ts +8 -7
- package/src/math.ts +36 -18
- package/src/models.ts +3 -3
- package/src/promise/delay.ts +2 -0
- package/src/promise/helpers.ts +6 -4
- package/src/promise/index.ts +49 -38
- package/src/promise/misc.ts +10 -7
- package/src/promise/models.ts +18 -19
- package/src/promise/timed.ts +8 -6
- package/src/query.ts +39 -28
- package/src/queue.ts +15 -4
- package/src/random.ts +8 -1
- package/src/result/index.ts +14 -8
- package/src/result/match.ts +18 -10
- package/src/result/misc.ts +17 -9
- package/src/result/models.ts +2 -0
- package/src/result/work/flow.ts +86 -62
- package/src/result/work/pipe.ts +55 -33
- package/src/sized/map.ts +20 -17
- package/src/sized/set.ts +21 -17
- package/src/string/case.ts +8 -0
- package/src/string/fuzzy.ts +19 -5
- package/src/string/index.ts +18 -15
- package/src/string/match.ts +3 -0
- package/src/string/normalize.ts +6 -2
- package/src/string/template.ts +69 -18
- package/src/value/clone.ts +51 -26
- package/src/value/collection.ts +9 -6
- package/src/value/diff.ts +3 -1
- package/src/value/freeze.ts +239 -25
- package/src/value/index.ts +0 -1
- package/src/value/merge.ts +11 -5
- package/src/value/omit.ts +1 -0
- package/src/value/pick.ts +1 -0
- package/src/value/shake.ts +1 -0
- package/src/value/smush.ts +1 -0
- package/src/value/transform.ts +7 -3
- package/src/value/unsmush.ts +1 -0
package/dist/color/instance.mjs
CHANGED
|
@@ -9,55 +9,86 @@ import { getColorState, setHSLColor, setHexColor, setRGBColor } from "./misc/sta
|
|
|
9
9
|
var Color = class {
|
|
10
10
|
#state;
|
|
11
11
|
/**
|
|
12
|
-
* Get the alpha channel
|
|
12
|
+
* Get the alpha channel _(opacity)_ of the color
|
|
13
|
+
*
|
|
14
|
+
* @returns Current alpha channel value between `0` and `1`
|
|
13
15
|
*/
|
|
14
16
|
get alpha() {
|
|
15
17
|
return this.#state.alpha.value;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
|
-
* Set the alpha channel
|
|
20
|
+
* Set the alpha channel _(opacity)_ of the color, as:
|
|
21
|
+
*
|
|
22
|
+
* - A number between `0` and `1`, where `0` is fully transparent and `1` is fully opaque
|
|
23
|
+
* - A number between `0` and `100`, where `0` is fully transparent and `100` is fully opaque
|
|
24
|
+
*
|
|
25
|
+
* @param value New alpha channel value
|
|
19
26
|
*/
|
|
20
27
|
set alpha(value) {
|
|
21
28
|
if (typeof value === "number" && !Number.isNaN(value)) this.#state.alpha = getAlpha(value);
|
|
22
29
|
}
|
|
23
30
|
/**
|
|
24
|
-
* Get the color as a hex color
|
|
31
|
+
* Get the color as a hex color string
|
|
32
|
+
*
|
|
33
|
+
* _Hex color string is returned with no `#`-prefix or alpha channel (opacity)_
|
|
34
|
+
*
|
|
35
|
+
* @returns Current color as a hex color string
|
|
25
36
|
*/
|
|
26
37
|
get hex() {
|
|
27
38
|
return this.#state.hex;
|
|
28
39
|
}
|
|
29
40
|
/**
|
|
30
|
-
* Set
|
|
41
|
+
* Set the color from a hex color string
|
|
42
|
+
*
|
|
43
|
+
* - `#`-prefix is optional
|
|
44
|
+
* - Alpha channel _(opacity)_ will be ignored
|
|
45
|
+
*
|
|
46
|
+
* @param value New hex color string
|
|
31
47
|
*/
|
|
32
48
|
set hex(value) {
|
|
33
49
|
setHexColor(this.#state, value, false);
|
|
34
50
|
}
|
|
35
51
|
/**
|
|
36
|
-
* Get the color as a hex color with an alpha channel
|
|
52
|
+
* Get the color as a hex color with an alpha channel _(opacity)_
|
|
53
|
+
*
|
|
54
|
+
* _Hex color string is returned with alpha channel (opacity), but without `#`-prefix_
|
|
55
|
+
*
|
|
56
|
+
* @returns Current color as a hex color string
|
|
37
57
|
*/
|
|
38
58
|
get hexa() {
|
|
39
59
|
return `${this.#state.hex}${this.#state.alpha.hex}`;
|
|
40
60
|
}
|
|
41
61
|
/**
|
|
42
|
-
* Set
|
|
62
|
+
* Set the color from a hex color string with an alpha channel _(opacity)_
|
|
63
|
+
*
|
|
64
|
+
* - `#`-prefix is optional
|
|
65
|
+
* - Alpha channel _(opacity)_ will be respected
|
|
66
|
+
*
|
|
67
|
+
* @param value New hex color string
|
|
43
68
|
*/
|
|
44
69
|
set hexa(value) {
|
|
45
70
|
setHexColor(this.#state, value, true);
|
|
46
71
|
}
|
|
47
72
|
/**
|
|
48
|
-
* Get the color as an
|
|
73
|
+
* Get the color as an _HSL_ color
|
|
74
|
+
*
|
|
75
|
+
* @returns Current color as an _HSL_ color
|
|
49
76
|
*/
|
|
50
77
|
get hsl() {
|
|
51
78
|
return this.#state.hsl;
|
|
52
79
|
}
|
|
53
80
|
/**
|
|
54
|
-
* Set colors from an
|
|
81
|
+
* Set colors from an _HSL_ color
|
|
82
|
+
*
|
|
83
|
+
* @param value New _HSL_ color
|
|
55
84
|
*/
|
|
56
85
|
set hsl(value) {
|
|
57
86
|
setHSLColor(this.#state, value, false);
|
|
58
87
|
}
|
|
59
88
|
/**
|
|
60
|
-
* Get the color as an
|
|
89
|
+
* Get the color as an _HSLA_ color
|
|
90
|
+
*
|
|
91
|
+
* @returns Current color as an _HSLA_ color
|
|
61
92
|
*/
|
|
62
93
|
get hsla() {
|
|
63
94
|
return {
|
|
@@ -66,25 +97,33 @@ var Color = class {
|
|
|
66
97
|
};
|
|
67
98
|
}
|
|
68
99
|
/**
|
|
69
|
-
* Set colors and alpha from an
|
|
100
|
+
* Set colors and alpha from an _HSLA_ color
|
|
101
|
+
*
|
|
102
|
+
* @param value New _HSLA_ color
|
|
70
103
|
*/
|
|
71
104
|
set hsla(value) {
|
|
72
105
|
setHSLColor(this.#state, value, true);
|
|
73
106
|
}
|
|
74
107
|
/**
|
|
75
|
-
* Get the color as an
|
|
108
|
+
* Get the color as an _RGB_ color
|
|
109
|
+
*
|
|
110
|
+
* @returns Current color as an _RGB_ color
|
|
76
111
|
*/
|
|
77
112
|
get rgb() {
|
|
78
113
|
return this.#state.rgb;
|
|
79
114
|
}
|
|
80
115
|
/**
|
|
81
|
-
* Set colors from an
|
|
116
|
+
* Set colors from an _RGB_ color
|
|
117
|
+
*
|
|
118
|
+
* @param value New _RGB_ color
|
|
82
119
|
*/
|
|
83
120
|
set rgb(value) {
|
|
84
121
|
setRGBColor(this.#state, value, false);
|
|
85
122
|
}
|
|
86
123
|
/**
|
|
87
|
-
* Get the color as an
|
|
124
|
+
* Get the color as an _RGBA_ color
|
|
125
|
+
*
|
|
126
|
+
* @returns Current color as an _RGBA_ color
|
|
88
127
|
*/
|
|
89
128
|
get rgba() {
|
|
90
129
|
return {
|
|
@@ -93,7 +132,9 @@ var Color = class {
|
|
|
93
132
|
};
|
|
94
133
|
}
|
|
95
134
|
/**
|
|
96
|
-
* Set colors and alpha from an
|
|
135
|
+
* Set colors and alpha from an _RGBA_ color
|
|
136
|
+
*
|
|
137
|
+
* @param value New _RGBA_ color
|
|
97
138
|
*/
|
|
98
139
|
set rgba(value) {
|
|
99
140
|
setRGBColor(this.#state, value, true);
|
|
@@ -102,15 +143,38 @@ var Color = class {
|
|
|
102
143
|
this.#state = getColorState(value);
|
|
103
144
|
Object.defineProperty(this, "$color", { value: true });
|
|
104
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Get the color as a hex string
|
|
148
|
+
*
|
|
149
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
150
|
+
* @returns Hex color string
|
|
151
|
+
*/
|
|
105
152
|
toHexString(alpha) {
|
|
106
153
|
return `#${alpha === true ? this.hexa : this.hex}`;
|
|
107
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Get the color as an _HSL(A)_ string
|
|
157
|
+
*
|
|
158
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
159
|
+
* @returns _HSL(A)_ color string
|
|
160
|
+
*/
|
|
108
161
|
toHslString(alpha) {
|
|
109
162
|
return formatColor("hsl", this, alpha === true);
|
|
110
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Get the color as an _RGB(A)_ string
|
|
166
|
+
*
|
|
167
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
168
|
+
* @returns _RGB(A)_ color string
|
|
169
|
+
*/
|
|
111
170
|
toRgbString(alpha) {
|
|
112
171
|
return formatColor("rgb", this, alpha === true);
|
|
113
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Get the color as a hex color string
|
|
175
|
+
*
|
|
176
|
+
* @returns Hex color string
|
|
177
|
+
*/
|
|
114
178
|
toString() {
|
|
115
179
|
return this.toHexString();
|
|
116
180
|
}
|
|
@@ -4,47 +4,75 @@ import { Color } from "../instance.mjs";
|
|
|
4
4
|
//#region src/color/misc/get.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Get a foreground color _(usually text)_ based on a background color's luminance
|
|
7
|
+
*
|
|
8
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
9
|
+
* - If the value cannot be parsed, a white foreground color will be returned
|
|
10
|
+
*
|
|
7
11
|
* @param value Original value
|
|
8
12
|
* @returns Foreground color
|
|
9
13
|
*/
|
|
10
14
|
declare function getForegroundColor(value: unknown): Color;
|
|
11
15
|
/**
|
|
12
|
-
* Get the hex color _(with alpha channel)_ from any kind of value
|
|
16
|
+
* Get the hex color _(with alpha channel, i.e., opacity)_ from any kind of value
|
|
17
|
+
*
|
|
18
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
19
|
+
* - If the value cannot be parsed, a black hex color with an alpha channel of `0` will be returned
|
|
20
|
+
*
|
|
13
21
|
* @param value Original value
|
|
14
|
-
* @returns Hex color
|
|
22
|
+
* @returns Hex color string
|
|
15
23
|
*/
|
|
16
24
|
declare function getHexaColor(value: unknown): string;
|
|
17
25
|
/**
|
|
18
26
|
* Get the hex color from any kind of value
|
|
27
|
+
*
|
|
28
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
29
|
+
* - If the value cannot be parsed, a black hex color will be returned
|
|
30
|
+
*
|
|
19
31
|
* @param value Original value
|
|
20
|
-
* @returns Hex color
|
|
32
|
+
* @returns Hex color string
|
|
21
33
|
*/
|
|
22
34
|
declare function getHexColor(value: unknown): string;
|
|
23
35
|
declare function getHexValue(value: unknown): number;
|
|
24
36
|
declare function getDegrees(value: unknown): number;
|
|
25
37
|
/**
|
|
26
|
-
* Get the
|
|
38
|
+
* Get the _HSLA_ color from any kind of value
|
|
39
|
+
*
|
|
40
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
41
|
+
* - If the value cannot be parsed, a black _HSLA_ color with an alpha channel _(opacity)_ of `0` will be returned
|
|
42
|
+
*
|
|
27
43
|
* @param value Original value
|
|
28
|
-
* @returns
|
|
44
|
+
* @returns _HSLA_ color
|
|
29
45
|
*/
|
|
30
46
|
declare function getHslaColor(value: unknown): HSLAColor;
|
|
31
47
|
/**
|
|
32
|
-
* Get the
|
|
48
|
+
* Get the _HSL_ color from any kind of value
|
|
49
|
+
*
|
|
50
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
51
|
+
* - If the value cannot be parsed, a black _HSL_ color will be returned
|
|
52
|
+
*
|
|
33
53
|
* @param value Original value
|
|
34
|
-
* @returns
|
|
54
|
+
* @returns _HSL_ color
|
|
35
55
|
*/
|
|
36
56
|
declare function getHslColor(value: unknown): HSLColor;
|
|
37
57
|
declare function getPercentage(value: unknown): number;
|
|
38
58
|
/**
|
|
39
|
-
* Get the
|
|
59
|
+
* Get the _RGBA_ color from any kind of value
|
|
60
|
+
*
|
|
61
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
62
|
+
* - If the value cannot be parsed, a black _RGBA_ color with an alpha channel _(opacity)_ of `0` will be returned
|
|
63
|
+
*
|
|
40
64
|
* @param value Original value
|
|
41
|
-
* @returns
|
|
65
|
+
* @returns _RGBA_ color
|
|
42
66
|
*/
|
|
43
67
|
declare function getRgbaColor(value: unknown): RGBAColor;
|
|
44
68
|
/**
|
|
45
|
-
* Get the
|
|
69
|
+
* Get the _RGB_ color from any kind of value
|
|
70
|
+
*
|
|
71
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
72
|
+
* - If the value cannot be parsed, a black _RGB_ color will be returned
|
|
73
|
+
*
|
|
46
74
|
* @param value Original value
|
|
47
|
-
* @returns
|
|
75
|
+
* @returns _RGB_ color
|
|
48
76
|
*/
|
|
49
77
|
declare function getRgbColor(value: unknown): RGBColor;
|
|
50
78
|
//#endregion
|
package/dist/color/misc/get.mjs
CHANGED
|
@@ -8,6 +8,10 @@ function getClampedValue(value, minimum, maximum) {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Get a foreground color _(usually text)_ based on a background color's luminance
|
|
11
|
+
*
|
|
12
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
13
|
+
* - If the value cannot be parsed, a white foreground color will be returned
|
|
14
|
+
*
|
|
11
15
|
* @param value Original value
|
|
12
16
|
* @returns Foreground color
|
|
13
17
|
*/
|
|
@@ -27,9 +31,13 @@ function getForegroundColor(value) {
|
|
|
27
31
|
return new Color(.2126 * values[2] + .7152 * values[1] + .0722 * values[0] > .625 ? HEX_BLACK : HEX_WHITE);
|
|
28
32
|
}
|
|
29
33
|
/**
|
|
30
|
-
* Get the hex color _(with alpha channel)_ from any kind of value
|
|
34
|
+
* Get the hex color _(with alpha channel, i.e., opacity)_ from any kind of value
|
|
35
|
+
*
|
|
36
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
37
|
+
* - If the value cannot be parsed, a black hex color with an alpha channel of `0` will be returned
|
|
38
|
+
*
|
|
31
39
|
* @param value Original value
|
|
32
|
-
* @returns Hex color
|
|
40
|
+
* @returns Hex color string
|
|
33
41
|
*/
|
|
34
42
|
function getHexaColor(value) {
|
|
35
43
|
const { alpha, hex } = getColorState(value);
|
|
@@ -37,8 +45,12 @@ function getHexaColor(value) {
|
|
|
37
45
|
}
|
|
38
46
|
/**
|
|
39
47
|
* Get the hex color from any kind of value
|
|
48
|
+
*
|
|
49
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
50
|
+
* - If the value cannot be parsed, a black hex color will be returned
|
|
51
|
+
*
|
|
40
52
|
* @param value Original value
|
|
41
|
-
* @returns Hex color
|
|
53
|
+
* @returns Hex color string
|
|
42
54
|
*/
|
|
43
55
|
function getHexColor(value) {
|
|
44
56
|
return getColorState(value).hex;
|
|
@@ -50,9 +62,13 @@ function getDegrees(value) {
|
|
|
50
62
|
return getClampedValue(value, 0, 360);
|
|
51
63
|
}
|
|
52
64
|
/**
|
|
53
|
-
* Get the
|
|
65
|
+
* Get the _HSLA_ color from any kind of value
|
|
66
|
+
*
|
|
67
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
68
|
+
* - If the value cannot be parsed, a black _HSLA_ color with an alpha channel _(opacity)_ of `0` will be returned
|
|
69
|
+
*
|
|
54
70
|
* @param value Original value
|
|
55
|
-
* @returns
|
|
71
|
+
* @returns _HSLA_ color
|
|
56
72
|
*/
|
|
57
73
|
function getHslaColor(value) {
|
|
58
74
|
const { alpha, hsl } = getColorState(value);
|
|
@@ -62,9 +78,13 @@ function getHslaColor(value) {
|
|
|
62
78
|
};
|
|
63
79
|
}
|
|
64
80
|
/**
|
|
65
|
-
* Get the
|
|
81
|
+
* Get the _HSL_ color from any kind of value
|
|
82
|
+
*
|
|
83
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
84
|
+
* - If the value cannot be parsed, a black _HSL_ color will be returned
|
|
85
|
+
*
|
|
66
86
|
* @param value Original value
|
|
67
|
-
* @returns
|
|
87
|
+
* @returns _HSL_ color
|
|
68
88
|
*/
|
|
69
89
|
function getHslColor(value) {
|
|
70
90
|
return getColorState(value).hsl;
|
|
@@ -73,9 +93,13 @@ function getPercentage(value) {
|
|
|
73
93
|
return getClampedValue(value, 0, 100);
|
|
74
94
|
}
|
|
75
95
|
/**
|
|
76
|
-
* Get the
|
|
96
|
+
* Get the _RGBA_ color from any kind of value
|
|
97
|
+
*
|
|
98
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
99
|
+
* - If the value cannot be parsed, a black _RGBA_ color with an alpha channel _(opacity)_ of `0` will be returned
|
|
100
|
+
*
|
|
77
101
|
* @param value Original value
|
|
78
|
-
* @returns
|
|
102
|
+
* @returns _RGBA_ color
|
|
79
103
|
*/
|
|
80
104
|
function getRgbaColor(value) {
|
|
81
105
|
const { alpha, rgb } = getColorState(value);
|
|
@@ -85,9 +109,13 @@ function getRgbaColor(value) {
|
|
|
85
109
|
};
|
|
86
110
|
}
|
|
87
111
|
/**
|
|
88
|
-
* Get the
|
|
112
|
+
* Get the _RGB_ color from any kind of value
|
|
113
|
+
*
|
|
114
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
115
|
+
* - If the value cannot be parsed, a black _RGB_ color will be returned
|
|
116
|
+
*
|
|
89
117
|
* @param value Original value
|
|
90
|
-
* @returns
|
|
118
|
+
* @returns _RGB_ color
|
|
91
119
|
*/
|
|
92
120
|
function getRgbColor(value) {
|
|
93
121
|
return getColorState(value).rgb;
|
package/dist/color/misc/is.d.mts
CHANGED
|
@@ -3,41 +3,56 @@ import { Color } from "../instance.mjs";
|
|
|
3
3
|
|
|
4
4
|
//#region src/color/misc/is.d.ts
|
|
5
5
|
/**
|
|
6
|
-
* Is the value a
|
|
6
|
+
* Is the value a _Color_?
|
|
7
|
+
*
|
|
7
8
|
* @param value Value to check
|
|
8
|
-
* @returns `true` if the value is a
|
|
9
|
+
* @returns `true` if the value is a _Color_, otherwise `false`
|
|
9
10
|
*/
|
|
10
11
|
declare function isColor(value: unknown): value is Color;
|
|
11
12
|
/**
|
|
12
13
|
* Is the value a hex color?
|
|
14
|
+
*
|
|
13
15
|
* @param value Value to check
|
|
14
|
-
* @param alpha Allow alpha channel? _(defaults to `true`)_
|
|
16
|
+
* @param alpha Allow alpha channel _(opacity)_? _(defaults to `true`)_
|
|
15
17
|
* @returns `true` if the value is a hex color, otherwise `false`
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* isHexColor('ff0000'); // => true
|
|
22
|
+
* isHexColor('#ff0000'); // => true
|
|
23
|
+
*
|
|
24
|
+
* isHexColor('#ff000050'); // => true
|
|
25
|
+
* isHexColor('#ff000050', false); // => false
|
|
26
|
+
* ```
|
|
16
27
|
*/
|
|
17
28
|
declare function isHexColor(value: unknown, alpha?: boolean): value is string;
|
|
18
29
|
/**
|
|
19
|
-
* Is the value an
|
|
30
|
+
* Is the value an _HSLA_ color?
|
|
31
|
+
*
|
|
20
32
|
* @param value Value to check
|
|
21
|
-
* @returns `true` if the value is an
|
|
33
|
+
* @returns `true` if the value is an _HSLA_ color, otherwise `false`
|
|
22
34
|
*/
|
|
23
35
|
declare function isHslaColor(value: unknown): value is HSLAColor;
|
|
24
36
|
/**
|
|
25
|
-
* Is the value an
|
|
37
|
+
* Is the value an _HSL_ color?
|
|
38
|
+
*
|
|
26
39
|
* @param value Value to check
|
|
27
|
-
* @returns `true` if the value is an
|
|
40
|
+
* @returns `true` if the value is an _HSL_ color, otherwise `false`
|
|
28
41
|
*/
|
|
29
42
|
declare function isHslColor(value: unknown): value is HSLColor;
|
|
30
43
|
declare function isHslLike(value: unknown): value is Record<keyof HSLColor, unknown>;
|
|
31
44
|
/**
|
|
32
|
-
* Is the value an
|
|
45
|
+
* Is the value an _RGBA_ color?
|
|
46
|
+
*
|
|
33
47
|
* @param value Value to check
|
|
34
|
-
* @returns `true` if the value is an
|
|
48
|
+
* @returns `true` if the value is an _RGBA_ color, otherwise `false`
|
|
35
49
|
*/
|
|
36
50
|
declare function isRgbaColor(value: unknown): value is RGBAColor;
|
|
37
51
|
/**
|
|
38
|
-
* Is the value an
|
|
52
|
+
* Is the value an _RGB_ color?
|
|
53
|
+
*
|
|
39
54
|
* @param value Value to check
|
|
40
|
-
* @returns `true` if the value is an
|
|
55
|
+
* @returns `true` if the value is an _RGB_ color, otherwise `false`
|
|
41
56
|
*/
|
|
42
57
|
declare function isRgbColor(value: unknown): value is RGBColor;
|
|
43
58
|
declare function isRgbLike(value: unknown): value is Record<keyof RGBColor, unknown>;
|
package/dist/color/misc/is.mjs
CHANGED
|
@@ -11,9 +11,10 @@ function isBytey(value) {
|
|
|
11
11
|
return typeof value === "number" && between(value, 0, 255);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Is the value a
|
|
14
|
+
* Is the value a _Color_?
|
|
15
|
+
*
|
|
15
16
|
* @param value Value to check
|
|
16
|
-
* @returns `true` if the value is a
|
|
17
|
+
* @returns `true` if the value is a _Color_, otherwise `false`
|
|
17
18
|
*/
|
|
18
19
|
function isColor(value) {
|
|
19
20
|
return typeof value === "object" && value !== null && "$color" in value && value.$color === true;
|
|
@@ -34,9 +35,19 @@ function isDegree(value) {
|
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Is the value a hex color?
|
|
38
|
+
*
|
|
37
39
|
* @param value Value to check
|
|
38
|
-
* @param alpha Allow alpha channel? _(defaults to `true`)_
|
|
40
|
+
* @param alpha Allow alpha channel _(opacity)_? _(defaults to `true`)_
|
|
39
41
|
* @returns `true` if the value is a hex color, otherwise `false`
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* isHexColor('ff0000'); // => true
|
|
46
|
+
* isHexColor('#ff0000'); // => true
|
|
47
|
+
*
|
|
48
|
+
* isHexColor('#ff000050'); // => true
|
|
49
|
+
* isHexColor('#ff000050', false); // => false
|
|
50
|
+
* ```
|
|
40
51
|
*/
|
|
41
52
|
function isHexColor(value, alpha) {
|
|
42
53
|
if (typeof value !== "string") return false;
|
|
@@ -45,17 +56,19 @@ function isHexColor(value, alpha) {
|
|
|
45
56
|
return true;
|
|
46
57
|
}
|
|
47
58
|
/**
|
|
48
|
-
* Is the value an
|
|
59
|
+
* Is the value an _HSLA_ color?
|
|
60
|
+
*
|
|
49
61
|
* @param value Value to check
|
|
50
|
-
* @returns `true` if the value is an
|
|
62
|
+
* @returns `true` if the value is an _HSLA_ color, otherwise `false`
|
|
51
63
|
*/
|
|
52
64
|
function isHslaColor(value) {
|
|
53
65
|
return isColorValue(value, KEYS_HSLA);
|
|
54
66
|
}
|
|
55
67
|
/**
|
|
56
|
-
* Is the value an
|
|
68
|
+
* Is the value an _HSL_ color?
|
|
69
|
+
*
|
|
57
70
|
* @param value Value to check
|
|
58
|
-
* @returns `true` if the value is an
|
|
71
|
+
* @returns `true` if the value is an _HSL_ color, otherwise `false`
|
|
59
72
|
*/
|
|
60
73
|
function isHslColor(value) {
|
|
61
74
|
return isColorValue(value, KEYS_HSLA) || isColorValue(value, KEYS_HSL);
|
|
@@ -64,17 +77,19 @@ function isHslLike(value) {
|
|
|
64
77
|
return hasKeys(value, KEYS_HSL);
|
|
65
78
|
}
|
|
66
79
|
/**
|
|
67
|
-
* Is the value an
|
|
80
|
+
* Is the value an _RGBA_ color?
|
|
81
|
+
*
|
|
68
82
|
* @param value Value to check
|
|
69
|
-
* @returns `true` if the value is an
|
|
83
|
+
* @returns `true` if the value is an _RGBA_ color, otherwise `false`
|
|
70
84
|
*/
|
|
71
85
|
function isRgbaColor(value) {
|
|
72
86
|
return isColorValue(value, KEYS_RGBA);
|
|
73
87
|
}
|
|
74
88
|
/**
|
|
75
|
-
* Is the value an
|
|
89
|
+
* Is the value an _RGB_ color?
|
|
90
|
+
*
|
|
76
91
|
* @param value Value to check
|
|
77
|
-
* @returns `true` if the value is an
|
|
92
|
+
* @returns `true` if the value is an _RGB_ color, otherwise `false`
|
|
78
93
|
*/
|
|
79
94
|
function isRgbColor(value) {
|
|
80
95
|
return isColorValue(value, KEYS_RGBA) || isColorValue(value, KEYS_RGB);
|
package/dist/color/models.d.mts
CHANGED
|
@@ -4,14 +4,17 @@ type Alpha = {
|
|
|
4
4
|
value: number;
|
|
5
5
|
};
|
|
6
6
|
type ColorWithAlpha = {
|
|
7
|
+
/**
|
|
8
|
+
* Alpha channel _(opacity)_ of the color _(in percentage; 0-100)_
|
|
9
|
+
*/
|
|
7
10
|
alpha: number;
|
|
8
11
|
};
|
|
9
12
|
/**
|
|
10
|
-
* An _HSL_
|
|
13
|
+
* An _HSL_ color with an alpha channel _(opacity)_
|
|
11
14
|
*/
|
|
12
15
|
type HSLAColor = HSLColor & ColorWithAlpha;
|
|
13
16
|
/**
|
|
14
|
-
* An _HSL_
|
|
17
|
+
* An _HSL_ color
|
|
15
18
|
*/
|
|
16
19
|
type HSLColor = {
|
|
17
20
|
/**
|
|
@@ -28,11 +31,11 @@ type HSLColor = {
|
|
|
28
31
|
saturation: number;
|
|
29
32
|
};
|
|
30
33
|
/**
|
|
31
|
-
* An _RGB_
|
|
34
|
+
* An _RGB_ color with an alpha channel _(opacity)_
|
|
32
35
|
*/
|
|
33
36
|
type RGBAColor = RGBColor & ColorWithAlpha;
|
|
34
37
|
/**
|
|
35
|
-
* An _RGB_
|
|
38
|
+
* An _RGB_ color
|
|
36
39
|
*/
|
|
37
40
|
type RGBColor = {
|
|
38
41
|
/**
|
|
@@ -3,23 +3,32 @@ import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "../models.mjs";
|
|
|
3
3
|
//#region src/color/space/hex.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Get the normalized hex color from a value
|
|
6
|
+
*
|
|
7
|
+
* _If the value is unable to be parsed or normalized, a hex color of `000000` will be returned, with the alpha channel _(opacity)_ value `0` included, if specified_
|
|
8
|
+
*
|
|
6
9
|
* @param value Value to normalize
|
|
7
|
-
* @param alpha Include alpha channel? _(defaults to `false`)_
|
|
8
|
-
* @returns Normalized hex color
|
|
10
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
11
|
+
* @returns Normalized hex color
|
|
9
12
|
*/
|
|
10
13
|
declare function getNormalizedHex(value: unknown, alpha?: boolean): string;
|
|
11
14
|
declare function hexToHsl(value: string): HSLColor;
|
|
12
15
|
declare function hexToHsla(value: string): HSLAColor;
|
|
13
16
|
/**
|
|
14
|
-
* Convert a hex color to an
|
|
17
|
+
* Convert a hex color to an _RGB_ color
|
|
18
|
+
*
|
|
19
|
+
* _If the value is unable to be converted, a black RGB color will be returned_
|
|
20
|
+
*
|
|
15
21
|
* @param value Original value
|
|
16
|
-
* @returns
|
|
22
|
+
* @returns _RGB_ color
|
|
17
23
|
*/
|
|
18
24
|
declare function hexToRgb(value: string): RGBColor;
|
|
19
25
|
/**
|
|
20
|
-
* Convert a hex color to an
|
|
26
|
+
* Convert a hex color to an _RGBA_ color
|
|
27
|
+
*
|
|
28
|
+
* _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_
|
|
29
|
+
*
|
|
21
30
|
* @param value Original value
|
|
22
|
-
* @returns
|
|
31
|
+
* @returns _RGBA_ color
|
|
23
32
|
*/
|
|
24
33
|
declare function hexToRgba(value: string): RGBAColor;
|
|
25
34
|
//#endregion
|
package/dist/color/space/hex.mjs
CHANGED
|
@@ -18,9 +18,12 @@ function convertHexToRgba(value) {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Get the normalized hex color from a value
|
|
21
|
+
*
|
|
22
|
+
* _If the value is unable to be parsed or normalized, a hex color of `000000` will be returned, with the alpha channel _(opacity)_ value `0` included, if specified_
|
|
23
|
+
*
|
|
21
24
|
* @param value Value to normalize
|
|
22
|
-
* @param alpha Include alpha channel? _(defaults to `false`)_
|
|
23
|
-
* @returns Normalized hex color
|
|
25
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
26
|
+
* @returns Normalized hex color
|
|
24
27
|
*/
|
|
25
28
|
function getNormalizedHex(value, alpha) {
|
|
26
29
|
const includeAlpha = alpha ?? false;
|
|
@@ -41,9 +44,12 @@ function hexToHsla(value) {
|
|
|
41
44
|
return convertRgbToHsla(convertHexToRgba(value));
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
|
-
* Convert a hex color to an
|
|
47
|
+
* Convert a hex color to an _RGB_ color
|
|
48
|
+
*
|
|
49
|
+
* _If the value is unable to be converted, a black RGB color will be returned_
|
|
50
|
+
*
|
|
45
51
|
* @param value Original value
|
|
46
|
-
* @returns
|
|
52
|
+
* @returns _RGB_ color
|
|
47
53
|
*/
|
|
48
54
|
function hexToRgb(value) {
|
|
49
55
|
const { blue, green, red } = convertHexToRgba(value);
|
|
@@ -54,9 +60,12 @@ function hexToRgb(value) {
|
|
|
54
60
|
};
|
|
55
61
|
}
|
|
56
62
|
/**
|
|
57
|
-
* Convert a hex color to an
|
|
63
|
+
* Convert a hex color to an _RGBA_ color
|
|
64
|
+
*
|
|
65
|
+
* _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_
|
|
66
|
+
*
|
|
58
67
|
* @param value Original value
|
|
59
|
-
* @returns
|
|
68
|
+
* @returns _RGBA_ color
|
|
60
69
|
*/
|
|
61
70
|
function hexToRgba(value) {
|
|
62
71
|
return convertHexToRgba(value);
|
|
@@ -4,17 +4,23 @@ import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "../models.mjs";
|
|
|
4
4
|
declare function getHslValue(value: Record<keyof HSLColor, unknown>): HSLColor;
|
|
5
5
|
declare function hslToHex(hsl: HSLAColor | HSLColor, alpha?: boolean): string;
|
|
6
6
|
/**
|
|
7
|
-
* Convert an
|
|
7
|
+
* Convert an _HSL(A)_ color to an _RGB_ color
|
|
8
|
+
*
|
|
9
|
+
* _If the value is unable to be converted, a black RGB color will be returned_
|
|
10
|
+
*
|
|
11
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
|
|
8
12
|
*
|
|
9
|
-
* Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
|
|
10
13
|
* @param hsl HSL(A) color
|
|
11
14
|
* @returns RGB color
|
|
12
15
|
*/
|
|
13
16
|
declare function hslToRgb(hsl: HSLAColor | HSLColor): RGBColor;
|
|
14
17
|
/**
|
|
15
|
-
* Convert an
|
|
18
|
+
* Convert an _HSL(A)_ color to an _RGBA_ color
|
|
19
|
+
*
|
|
20
|
+
* _If the value is unable to be converted, a black RGBA color with an alpha channel (opactiy) of `0` will be returned_
|
|
21
|
+
*
|
|
22
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
|
|
16
23
|
*
|
|
17
|
-
* Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
|
|
18
24
|
* @param hsl HSL(A) color
|
|
19
25
|
* @returns RGBA color
|
|
20
26
|
*/
|