@oscarpalmer/atoms 0.188.1 → 0.189.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/dist/array/difference.d.mts +0 -1
- package/dist/array/exists.d.mts +0 -1
- package/dist/array/filter.d.mts +0 -1
- package/dist/array/find.d.mts +0 -1
- package/dist/array/first.d.mts +0 -1
- package/dist/array/flatten.d.mts +0 -1
- package/dist/array/get.d.mts +0 -1
- package/dist/array/group-by.d.mts +0 -1
- package/dist/array/last.d.mts +0 -1
- package/dist/array/match.d.mts +0 -1
- package/dist/array/match.mjs +3 -3
- package/dist/array/move.d.mts +0 -1
- package/dist/array/partition.d.mts +0 -1
- package/dist/array/select.d.mts +0 -1
- package/dist/array/select.mjs +2 -1
- package/dist/array/single.d.mts +0 -1
- package/dist/array/slice.d.mts +0 -1
- package/dist/array/sort.d.mts +1 -2
- package/dist/array/sort.mjs +0 -1
- package/dist/array/swap.d.mts +0 -1
- package/dist/array/to-map.d.mts +0 -1
- package/dist/array/to-record.d.mts +0 -1
- package/dist/array/to-set.d.mts +0 -1
- package/dist/array/toggle.d.mts +0 -1
- package/dist/array/unique.d.mts +0 -1
- package/dist/array/update.d.mts +0 -1
- package/dist/color/constants.d.mts +9 -10
- package/dist/color/constants.mjs +15 -7
- package/dist/color/index.d.mts +9 -9
- package/dist/color/index.mjs +8 -7
- package/dist/color/instance.d.mts +35 -8
- package/dist/color/instance.mjs +53 -13
- package/dist/color/misc/alpha.d.mts +0 -1
- package/dist/color/misc/alpha.mjs +5 -5
- package/dist/color/misc/get.d.mts +42 -13
- package/dist/color/misc/get.mjs +45 -24
- package/dist/color/misc/index.d.mts +4 -4
- package/dist/color/misc/index.mjs +12 -12
- package/dist/color/misc/is.d.mts +56 -3
- package/dist/color/misc/is.mjs +72 -4
- package/dist/color/misc/state.d.mts +2 -2
- package/dist/color/misc/state.mjs +79 -43
- package/dist/color/models.d.mts +18 -2
- package/dist/color/space/hex.d.mts +38 -5
- package/dist/color/space/hex.mjs +57 -9
- package/dist/color/space/hsl.d.mts +33 -7
- package/dist/color/space/hsl.mjs +65 -14
- package/dist/color/space/hwb.d.mts +52 -0
- package/dist/color/space/hwb.mjs +99 -0
- package/dist/color/space/rgb.d.mts +26 -5
- package/dist/color/space/rgb.mjs +82 -28
- package/dist/function/assert.d.mts +1 -2
- package/dist/function/limit.d.mts +0 -1
- package/dist/function/memoize.d.mts +0 -1
- package/dist/function/once.d.mts +0 -1
- package/dist/function/retry.d.mts +0 -1
- package/dist/function/work.d.mts +0 -1
- package/dist/herald.d.mts +0 -1
- package/dist/index.d.mts +296 -51
- package/dist/index.mjs +657 -259
- package/dist/internal/array/callbacks.d.mts +0 -1
- package/dist/internal/array/callbacks.mjs +0 -1
- package/dist/internal/array/group.d.mts +0 -1
- package/dist/internal/array/index-of.d.mts +0 -1
- package/dist/internal/function/timer.d.mts +0 -1
- package/dist/internal/is.d.mts +0 -1
- package/dist/internal/is.mjs +1 -1
- package/dist/internal/math/aggregate.d.mts +0 -1
- package/dist/internal/math/misc.d.mts +12 -0
- package/dist/internal/math/misc.mjs +19 -0
- package/dist/internal/result.d.mts +0 -1
- package/dist/internal/value/compare.d.mts +0 -1
- package/dist/internal/value/equal.d.mts +0 -1
- package/dist/internal/value/get.d.mts +0 -1
- package/dist/internal/value/handlers.d.mts +0 -1
- package/dist/internal/value/has.d.mts +0 -1
- package/dist/internal/value/misc.d.mts +0 -1
- package/dist/internal/value/set.d.mts +0 -1
- package/dist/is.d.mts +0 -1
- package/dist/math.d.mts +1 -9
- package/dist/math.mjs +1 -16
- package/dist/models.d.mts +6 -6
- package/dist/promise/delay.d.mts +0 -1
- package/dist/promise/helpers.d.mts +0 -1
- package/dist/promise/index.d.mts +0 -1
- package/dist/promise/misc.d.mts +0 -1
- package/dist/promise/models.d.mts +4 -5
- package/dist/promise/models.mjs +1 -1
- package/dist/promise/timed.d.mts +0 -1
- package/dist/query.d.mts +0 -1
- package/dist/query.mjs +1 -1
- package/dist/queue.d.mts +0 -1
- package/dist/random.d.mts +0 -1
- package/dist/result/index.d.mts +0 -1
- package/dist/result/index.mjs +2 -1
- package/dist/result/match.d.mts +0 -1
- package/dist/result/misc.d.mts +0 -1
- package/dist/result/models.d.mts +0 -1
- package/dist/result/work/flow.d.mts +0 -1
- package/dist/result/work/pipe.d.mts +0 -1
- package/dist/string/fuzzy.d.mts +0 -1
- package/dist/string/index.d.mts +0 -1
- package/dist/string/index.mjs +1 -1
- package/dist/string/template.d.mts +0 -1
- package/dist/value/clone.d.mts +0 -1
- package/dist/value/freeze.d.mts +1 -2
- package/dist/value/merge.d.mts +0 -1
- package/dist/value/omit.d.mts +0 -1
- package/dist/value/pick.d.mts +0 -1
- package/dist/value/shake.d.mts +1 -2
- package/dist/value/smush.d.mts +1 -2
- package/dist/value/transform.d.mts +1 -2
- package/dist/value/unsmush.d.mts +1 -2
- package/package.json +5 -5
- package/src/color/constants.ts +17 -13
- package/src/color/index.ts +21 -6
- package/src/color/instance.ts +67 -14
- package/src/color/misc/alpha.ts +6 -10
- package/src/color/misc/get.ts +70 -16
- package/src/color/misc/index.ts +18 -17
- package/src/color/misc/is.ts +86 -3
- package/src/color/misc/state.ts +126 -40
- package/src/color/models.ts +19 -1
- package/src/color/space/hex.ts +55 -8
- package/src/color/space/hsl.ts +80 -14
- package/src/color/space/hwb.ts +123 -0
- package/src/color/space/rgb.ts +108 -27
- package/src/internal/math/misc.ts +28 -0
- package/src/math.ts +2 -29
package/dist/color/space/rgb.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { join } from "../../internal/string.mjs";
|
|
2
2
|
import { DEFAULT_RGB } from "../constants.mjs";
|
|
3
3
|
import { getAlpha, getAlphaValue } from "../misc/alpha.mjs";
|
|
4
|
-
import { isRgbLike } from "../misc/is.mjs";
|
|
5
4
|
import { getHexValue } from "../misc/get.mjs";
|
|
5
|
+
import { isRgbLike } from "../misc/is.mjs";
|
|
6
6
|
//#region src/color/space/rgb.ts
|
|
7
7
|
function convertRgbToHex(rgb, alpha) {
|
|
8
8
|
const hex = `${join([
|
|
@@ -18,38 +18,46 @@ function convertRgbToHex(rgb, alpha) {
|
|
|
18
18
|
return `${hex}${a}`;
|
|
19
19
|
}
|
|
20
20
|
function convertRgbToHsla(value) {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const red = rgb.red / 255;
|
|
25
|
-
const maxHex = Math.max(blue, green, red);
|
|
26
|
-
const minHex = Math.min(blue, green, red);
|
|
27
|
-
const delta = maxHex - minHex;
|
|
28
|
-
const lightness = (minHex + maxHex) / 2;
|
|
21
|
+
const values = getRgbValues(isRgbLike(value) ? getRgbValue(value) : { ...DEFAULT_RGB });
|
|
22
|
+
const { delta, max, min } = values;
|
|
23
|
+
const lightness = (min + max) / 2;
|
|
29
24
|
let hue = 0;
|
|
30
25
|
let saturation = 0;
|
|
31
26
|
if (delta !== 0) {
|
|
32
|
-
saturation = (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
saturation = (max - lightness) / Math.min(lightness, 1 - lightness);
|
|
28
|
+
hue = getRgbHue(values);
|
|
29
|
+
hue *= 60;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
hue,
|
|
33
|
+
saturation: saturation * 100,
|
|
34
|
+
lightness: lightness * 100,
|
|
35
|
+
alpha: getAlphaValue(value?.alpha ?? 100)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function convertRgbToHwba(value) {
|
|
39
|
+
const values = getRgbValues(isRgbLike(value) ? getRgbValue(value) : { ...DEFAULT_RGB });
|
|
40
|
+
const { delta, max, min } = values;
|
|
41
|
+
let hue = 0;
|
|
42
|
+
if (delta !== 0) {
|
|
43
|
+
hue = getRgbHue(values);
|
|
44
44
|
hue *= 60;
|
|
45
45
|
}
|
|
46
46
|
return {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
hue,
|
|
48
|
+
whiteness: min * 100,
|
|
49
|
+
blackness: (1 - max) * 100,
|
|
50
|
+
alpha: getAlphaValue(value?.alpha ?? 100)
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
+
function getRgbHue(values) {
|
|
54
|
+
const { blue, delta, green, max, red } = values;
|
|
55
|
+
switch (max) {
|
|
56
|
+
case blue: return (red - green) / delta + 4;
|
|
57
|
+
case green: return (blue - red) / delta + 2;
|
|
58
|
+
default: return (green - blue) / delta + (green < blue ? 6 : 0);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
53
61
|
function getRgbValue(value) {
|
|
54
62
|
return {
|
|
55
63
|
blue: getHexValue(value.blue),
|
|
@@ -57,6 +65,21 @@ function getRgbValue(value) {
|
|
|
57
65
|
red: getHexValue(value.red)
|
|
58
66
|
};
|
|
59
67
|
}
|
|
68
|
+
function getRgbValues(rgb) {
|
|
69
|
+
const blue = rgb.blue / 255;
|
|
70
|
+
const green = rgb.green / 255;
|
|
71
|
+
const red = rgb.red / 255;
|
|
72
|
+
const max = Math.max(blue, green, red);
|
|
73
|
+
const min = Math.min(blue, green, red);
|
|
74
|
+
return {
|
|
75
|
+
blue,
|
|
76
|
+
delta: max - min,
|
|
77
|
+
green,
|
|
78
|
+
max,
|
|
79
|
+
min,
|
|
80
|
+
red
|
|
81
|
+
};
|
|
82
|
+
}
|
|
60
83
|
/**
|
|
61
84
|
* Convert an _RGB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
|
|
62
85
|
*
|
|
@@ -72,7 +95,7 @@ function rgbToHex(rgb, alpha) {
|
|
|
72
95
|
/**
|
|
73
96
|
* Convert an _RGB(A)_ color to an _HSL_ color
|
|
74
97
|
*
|
|
75
|
-
* _If the value is unable to be converted, a black
|
|
98
|
+
* _If the value is unable to be converted, a black _HSL_ color will be returned_
|
|
76
99
|
*
|
|
77
100
|
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
|
78
101
|
*
|
|
@@ -90,7 +113,7 @@ function rgbToHsl(rgb) {
|
|
|
90
113
|
/**
|
|
91
114
|
* Convert an _RGB(A)_ color to an _HSLA_ color
|
|
92
115
|
*
|
|
93
|
-
* _If the value is unable to be converted, a black _HSLA_ color
|
|
116
|
+
* _If the value is unable to be converted, a black _HSLA_ color will be returned_
|
|
94
117
|
*
|
|
95
118
|
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
|
96
119
|
*
|
|
@@ -100,5 +123,36 @@ function rgbToHsl(rgb) {
|
|
|
100
123
|
function rgbToHsla(rgb) {
|
|
101
124
|
return convertRgbToHsla(rgb);
|
|
102
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Convert an _RGB(A)_ color to an _HWB_ color
|
|
128
|
+
*
|
|
129
|
+
* _If the value is unable to be converted, a black _HWB_ color will be returned_
|
|
130
|
+
*
|
|
131
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
|
132
|
+
*
|
|
133
|
+
* @param rgb _RGB(A)_ color
|
|
134
|
+
* @returns _HWB_ color
|
|
135
|
+
*/
|
|
136
|
+
function rgbToHwb(rgb) {
|
|
137
|
+
const { blackness, hue, whiteness } = convertRgbToHwba(rgb);
|
|
138
|
+
return {
|
|
139
|
+
hue,
|
|
140
|
+
whiteness,
|
|
141
|
+
blackness
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Convert an _RGB(A)_ color to an _HWBA_ color
|
|
146
|
+
|
|
147
|
+
* _If the value is unable to be converted, a black _HWBA_ color will be returned_
|
|
148
|
+
*
|
|
149
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
|
150
|
+
*
|
|
151
|
+
* @param rgb _RGB(A)_ color
|
|
152
|
+
* @returns _HWBA_ color
|
|
153
|
+
*/
|
|
154
|
+
function rgbToHwba(rgb) {
|
|
155
|
+
return convertRgbToHwba(rgb);
|
|
156
|
+
}
|
|
103
157
|
//#endregion
|
|
104
|
-
export { convertRgbToHex, convertRgbToHsla, getRgbValue, rgbToHex, rgbToHsl, rgbToHsla };
|
|
158
|
+
export { convertRgbToHex, convertRgbToHsla, convertRgbToHwba, getRgbValue, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Constructor, NestedKeys, NestedValue, PlainObject } from "../models.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/function/assert.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Asserter for a property of a value
|
|
@@ -9,7 +8,7 @@ type AssertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, A
|
|
|
9
8
|
* A function that asserts a value is of a specific type, throwing an error if it is not
|
|
10
9
|
*/
|
|
11
10
|
type Asserter<Value> = (value: unknown) => asserts value is Value;
|
|
12
|
-
type NestedPick<Value, Path extends string> = Value extends PlainObject ? Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Value ? { [Key in Head]: NestedPick<Value[Key], Rest
|
|
11
|
+
type NestedPick<Value, Path extends string> = Value extends PlainObject ? Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Value ? { [Key in Head]: NestedPick<Value[Key], Rest>; } : never : Path extends keyof Value ? { [Key in Path]: Value[Key]; } : never : never;
|
|
13
12
|
/**
|
|
14
13
|
* Asserts that a condition is true, throwing an error if it is not
|
|
15
14
|
*
|
package/dist/function/once.d.mts
CHANGED
package/dist/function/work.d.mts
CHANGED