@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.
Files changed (129) hide show
  1. package/dist/array/difference.d.mts +0 -1
  2. package/dist/array/exists.d.mts +0 -1
  3. package/dist/array/filter.d.mts +0 -1
  4. package/dist/array/find.d.mts +0 -1
  5. package/dist/array/first.d.mts +0 -1
  6. package/dist/array/flatten.d.mts +0 -1
  7. package/dist/array/get.d.mts +0 -1
  8. package/dist/array/group-by.d.mts +0 -1
  9. package/dist/array/last.d.mts +0 -1
  10. package/dist/array/match.d.mts +0 -1
  11. package/dist/array/match.mjs +3 -3
  12. package/dist/array/move.d.mts +0 -1
  13. package/dist/array/partition.d.mts +0 -1
  14. package/dist/array/select.d.mts +0 -1
  15. package/dist/array/select.mjs +2 -1
  16. package/dist/array/single.d.mts +0 -1
  17. package/dist/array/slice.d.mts +0 -1
  18. package/dist/array/sort.d.mts +1 -2
  19. package/dist/array/sort.mjs +0 -1
  20. package/dist/array/swap.d.mts +0 -1
  21. package/dist/array/to-map.d.mts +0 -1
  22. package/dist/array/to-record.d.mts +0 -1
  23. package/dist/array/to-set.d.mts +0 -1
  24. package/dist/array/toggle.d.mts +0 -1
  25. package/dist/array/unique.d.mts +0 -1
  26. package/dist/array/update.d.mts +0 -1
  27. package/dist/color/constants.d.mts +9 -10
  28. package/dist/color/constants.mjs +15 -7
  29. package/dist/color/index.d.mts +9 -9
  30. package/dist/color/index.mjs +8 -7
  31. package/dist/color/instance.d.mts +35 -8
  32. package/dist/color/instance.mjs +53 -13
  33. package/dist/color/misc/alpha.d.mts +0 -1
  34. package/dist/color/misc/alpha.mjs +5 -5
  35. package/dist/color/misc/get.d.mts +42 -13
  36. package/dist/color/misc/get.mjs +45 -24
  37. package/dist/color/misc/index.d.mts +4 -4
  38. package/dist/color/misc/index.mjs +12 -12
  39. package/dist/color/misc/is.d.mts +56 -3
  40. package/dist/color/misc/is.mjs +72 -4
  41. package/dist/color/misc/state.d.mts +2 -2
  42. package/dist/color/misc/state.mjs +79 -43
  43. package/dist/color/models.d.mts +18 -2
  44. package/dist/color/space/hex.d.mts +38 -5
  45. package/dist/color/space/hex.mjs +57 -9
  46. package/dist/color/space/hsl.d.mts +33 -7
  47. package/dist/color/space/hsl.mjs +65 -14
  48. package/dist/color/space/hwb.d.mts +52 -0
  49. package/dist/color/space/hwb.mjs +99 -0
  50. package/dist/color/space/rgb.d.mts +26 -5
  51. package/dist/color/space/rgb.mjs +82 -28
  52. package/dist/function/assert.d.mts +1 -2
  53. package/dist/function/limit.d.mts +0 -1
  54. package/dist/function/memoize.d.mts +0 -1
  55. package/dist/function/once.d.mts +0 -1
  56. package/dist/function/retry.d.mts +0 -1
  57. package/dist/function/work.d.mts +0 -1
  58. package/dist/herald.d.mts +0 -1
  59. package/dist/index.d.mts +296 -51
  60. package/dist/index.mjs +657 -259
  61. package/dist/internal/array/callbacks.d.mts +0 -1
  62. package/dist/internal/array/callbacks.mjs +0 -1
  63. package/dist/internal/array/group.d.mts +0 -1
  64. package/dist/internal/array/index-of.d.mts +0 -1
  65. package/dist/internal/function/timer.d.mts +0 -1
  66. package/dist/internal/is.d.mts +0 -1
  67. package/dist/internal/is.mjs +1 -1
  68. package/dist/internal/math/aggregate.d.mts +0 -1
  69. package/dist/internal/math/misc.d.mts +12 -0
  70. package/dist/internal/math/misc.mjs +19 -0
  71. package/dist/internal/result.d.mts +0 -1
  72. package/dist/internal/value/compare.d.mts +0 -1
  73. package/dist/internal/value/equal.d.mts +0 -1
  74. package/dist/internal/value/get.d.mts +0 -1
  75. package/dist/internal/value/handlers.d.mts +0 -1
  76. package/dist/internal/value/has.d.mts +0 -1
  77. package/dist/internal/value/misc.d.mts +0 -1
  78. package/dist/internal/value/set.d.mts +0 -1
  79. package/dist/is.d.mts +0 -1
  80. package/dist/math.d.mts +1 -9
  81. package/dist/math.mjs +1 -16
  82. package/dist/models.d.mts +6 -6
  83. package/dist/promise/delay.d.mts +0 -1
  84. package/dist/promise/helpers.d.mts +0 -1
  85. package/dist/promise/index.d.mts +0 -1
  86. package/dist/promise/misc.d.mts +0 -1
  87. package/dist/promise/models.d.mts +4 -5
  88. package/dist/promise/models.mjs +1 -1
  89. package/dist/promise/timed.d.mts +0 -1
  90. package/dist/query.d.mts +0 -1
  91. package/dist/query.mjs +1 -1
  92. package/dist/queue.d.mts +0 -1
  93. package/dist/random.d.mts +0 -1
  94. package/dist/result/index.d.mts +0 -1
  95. package/dist/result/index.mjs +2 -1
  96. package/dist/result/match.d.mts +0 -1
  97. package/dist/result/misc.d.mts +0 -1
  98. package/dist/result/models.d.mts +0 -1
  99. package/dist/result/work/flow.d.mts +0 -1
  100. package/dist/result/work/pipe.d.mts +0 -1
  101. package/dist/string/fuzzy.d.mts +0 -1
  102. package/dist/string/index.d.mts +0 -1
  103. package/dist/string/index.mjs +1 -1
  104. package/dist/string/template.d.mts +0 -1
  105. package/dist/value/clone.d.mts +0 -1
  106. package/dist/value/freeze.d.mts +1 -2
  107. package/dist/value/merge.d.mts +0 -1
  108. package/dist/value/omit.d.mts +0 -1
  109. package/dist/value/pick.d.mts +0 -1
  110. package/dist/value/shake.d.mts +1 -2
  111. package/dist/value/smush.d.mts +1 -2
  112. package/dist/value/transform.d.mts +1 -2
  113. package/dist/value/unsmush.d.mts +1 -2
  114. package/package.json +5 -5
  115. package/src/color/constants.ts +17 -13
  116. package/src/color/index.ts +21 -6
  117. package/src/color/instance.ts +67 -14
  118. package/src/color/misc/alpha.ts +6 -10
  119. package/src/color/misc/get.ts +70 -16
  120. package/src/color/misc/index.ts +18 -17
  121. package/src/color/misc/is.ts +86 -3
  122. package/src/color/misc/state.ts +126 -40
  123. package/src/color/models.ts +19 -1
  124. package/src/color/space/hex.ts +55 -8
  125. package/src/color/space/hsl.ts +80 -14
  126. package/src/color/space/hwb.ts +123 -0
  127. package/src/color/space/rgb.ts +108 -27
  128. package/src/internal/math/misc.ts +28 -0
  129. package/src/math.ts +2 -29
@@ -30,6 +30,21 @@ type HSLColor = {
30
30
  */
31
31
  saturation: number;
32
32
  };
33
+ type HWBColor = {
34
+ /**
35
+ * Blackness of the color _(in percentage; 0-100)_
36
+ */
37
+ blackness: number;
38
+ /**
39
+ * Hue of the color _(in degrees; 0-360)_
40
+ */
41
+ hue: number;
42
+ /**
43
+ * Whiteness of the color _(in percentage; 0-100)_
44
+ */
45
+ whiteness: number;
46
+ };
47
+ type HWBAColor = HWBColor & ColorWithAlpha;
33
48
  /**
34
49
  * An _RGB_ color with an alpha channel _(opacity)_
35
50
  */
@@ -51,13 +66,14 @@ type RGBColor = {
51
66
  */
52
67
  red: number;
53
68
  };
54
- type ColorProperty = 'alpha' | 'blue' | 'green' | 'hue' | 'lightness' | 'red' | 'saturation';
69
+ type ColorProperty = 'alpha' | keyof HSLColor | keyof HWBColor | keyof RGBColor;
55
70
  type ColorSpace = 'hsl' | 'rgb';
56
71
  type ColorState = {
57
72
  alpha: Alpha;
58
73
  hex: string;
59
74
  hsl: HSLColor;
75
+ hwb: HWBColor;
60
76
  rgb: RGBColor;
61
77
  };
62
78
  //#endregion
63
- export { Alpha, ColorProperty, ColorSpace, ColorState, HSLAColor, HSLColor, RGBAColor, RGBColor };
79
+ export { Alpha, ColorProperty, ColorSpace, ColorState, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor };
@@ -1,5 +1,4 @@
1
- import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "../models.mjs";
2
-
1
+ import { HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
3
2
  //#region src/color/space/hex.d.ts
4
3
  /**
5
4
  * Get the normalized hex color from a value
@@ -11,12 +10,46 @@ import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "../models.mjs";
11
10
  * @returns Normalized hex color
12
11
  */
13
12
  declare function getNormalizedHex(value: unknown, alpha?: boolean): string;
13
+ /**
14
+ * Convert a hex color string to a _HSL_ color
15
+ *
16
+ * _If the value is unable to be converted, a black _HSL_ color will be returned_
17
+ *
18
+ * @param value Hex color string
19
+ * @returns _HSL_ color
20
+ */
14
21
  declare function hexToHsl(value: string): HSLColor;
22
+ /**
23
+ * Convert a hex color string to a _HSLA_ color
24
+ *
25
+ * _If the value is unable to be converted, a black _HSLA_ color will be returned_
26
+ *
27
+ * @param value Hex color string
28
+ * @returns _HSLA_ color
29
+ */
15
30
  declare function hexToHsla(value: string): HSLAColor;
31
+ /**
32
+ * Convert a hex color string to a _HWB_ color
33
+ *
34
+ * _If the value is unable to be converted, a black _HWB_ color will be returned_
35
+ *
36
+ * @param value Hex color string
37
+ * @returns _HWB_ color
38
+ */
39
+ declare function hexToHwb(value: string): HWBColor;
40
+ /**
41
+ * Convert a hex color string to a _HWBA_ color
42
+ *
43
+ * _If the value is unable to be converted, a black _HWBA_ color will be returned_
44
+ *
45
+ * @param value Hex color string
46
+ * @returns _HWBA_ color
47
+ */
48
+ declare function hexToHwba(value: string): HWBAColor;
16
49
  /**
17
50
  * Convert a hex color to an _RGB_ color
18
51
  *
19
- * _If the value is unable to be converted, a black RGB color will be returned_
52
+ * _If the value is unable to be converted, a black _RGB_ color will be returned_
20
53
  *
21
54
  * @param value Original value
22
55
  * @returns _RGB_ color
@@ -25,11 +58,11 @@ declare function hexToRgb(value: string): RGBColor;
25
58
  /**
26
59
  * Convert a hex color to an _RGBA_ color
27
60
  *
28
- * _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_
61
+ * _If the value is unable to be converted, a black _RGBA_ color will be returned_
29
62
  *
30
63
  * @param value Original value
31
64
  * @returns _RGBA_ color
32
65
  */
33
66
  declare function hexToRgba(value: string): RGBAColor;
34
67
  //#endregion
35
- export { getNormalizedHex, hexToHsl, hexToHsla, hexToRgb, hexToRgba };
68
+ export { getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba };
@@ -1,7 +1,8 @@
1
1
  import { join } from "../../internal/string.mjs";
2
2
  import { ALPHA_FULL_HEX_LONG, EXPRESSION_HEX_LONG, EXPRESSION_PREFIX, HEX_BLACK } from "../constants.mjs";
3
+ import { getHexValue, getPercentage } from "../misc/get.mjs";
3
4
  import { isHexColor } from "../misc/is.mjs";
4
- import { convertRgbToHsla } from "./rgb.mjs";
5
+ import { convertRgbToHsla, convertRgbToHwba } from "./rgb.mjs";
5
6
  //#region src/color/space/hex.ts
6
7
  function convertHexToRgba(value) {
7
8
  const normalized = getNormalizedHex(value, true);
@@ -10,10 +11,10 @@ function convertHexToRgba(value) {
10
11
  const { length } = pairs;
11
12
  for (let index = 1; index < length; index += 1) values.push(Number.parseInt(pairs[index], 16));
12
13
  return {
13
- alpha: values[3] / 255,
14
- blue: values[2],
15
- green: values[1],
16
- red: values[0]
14
+ alpha: getPercentage(values[3] / 255 * 100),
15
+ blue: getHexValue(values[2]),
16
+ green: getHexValue(values[1]),
17
+ red: getHexValue(values[0])
17
18
  };
18
19
  }
19
20
  /**
@@ -29,9 +30,21 @@ function getNormalizedHex(value, alpha) {
29
30
  const includeAlpha = alpha ?? false;
30
31
  if (!isHexColor(value)) return `${HEX_BLACK}${includeAlpha ? ALPHA_FULL_HEX_LONG : ""}`;
31
32
  const normalized = value.replace(EXPRESSION_PREFIX, "");
32
- if (normalized.length < 6) return join(`${normalized.slice(0, 3)}${includeAlpha ? normalized[3] ?? "f" : ""}`.split("").map((character) => character.repeat(2)));
33
+ if (normalized.length < 6) {
34
+ const hex = normalized.slice(0, 3);
35
+ const a = includeAlpha ? normalized[3] ?? "f" : "";
36
+ return join(`${hex}${a}`.split("").map((character) => character.repeat(2)));
37
+ }
33
38
  return `${normalized.slice(0, 6)}${includeAlpha ? normalized.slice(6) || ALPHA_FULL_HEX_LONG : ""}`;
34
39
  }
40
+ /**
41
+ * Convert a hex color string to a _HSL_ color
42
+ *
43
+ * _If the value is unable to be converted, a black _HSL_ color will be returned_
44
+ *
45
+ * @param value Hex color string
46
+ * @returns _HSL_ color
47
+ */
35
48
  function hexToHsl(value) {
36
49
  const { hue, lightness, saturation } = hexToHsla(value);
37
50
  return {
@@ -40,13 +53,48 @@ function hexToHsl(value) {
40
53
  saturation
41
54
  };
42
55
  }
56
+ /**
57
+ * Convert a hex color string to a _HSLA_ color
58
+ *
59
+ * _If the value is unable to be converted, a black _HSLA_ color will be returned_
60
+ *
61
+ * @param value Hex color string
62
+ * @returns _HSLA_ color
63
+ */
43
64
  function hexToHsla(value) {
44
65
  return convertRgbToHsla(convertHexToRgba(value));
45
66
  }
46
67
  /**
68
+ * Convert a hex color string to a _HWB_ color
69
+ *
70
+ * _If the value is unable to be converted, a black _HWB_ color will be returned_
71
+ *
72
+ * @param value Hex color string
73
+ * @returns _HWB_ color
74
+ */
75
+ function hexToHwb(value) {
76
+ const { blackness, hue, whiteness } = hexToHwba(value);
77
+ return {
78
+ hue,
79
+ whiteness,
80
+ blackness
81
+ };
82
+ }
83
+ /**
84
+ * Convert a hex color string to a _HWBA_ color
85
+ *
86
+ * _If the value is unable to be converted, a black _HWBA_ color will be returned_
87
+ *
88
+ * @param value Hex color string
89
+ * @returns _HWBA_ color
90
+ */
91
+ function hexToHwba(value) {
92
+ return convertRgbToHwba(convertHexToRgba(value));
93
+ }
94
+ /**
47
95
  * Convert a hex color to an _RGB_ color
48
96
  *
49
- * _If the value is unable to be converted, a black RGB color will be returned_
97
+ * _If the value is unable to be converted, a black _RGB_ color will be returned_
50
98
  *
51
99
  * @param value Original value
52
100
  * @returns _RGB_ color
@@ -62,7 +110,7 @@ function hexToRgb(value) {
62
110
  /**
63
111
  * Convert a hex color to an _RGBA_ color
64
112
  *
65
- * _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_
113
+ * _If the value is unable to be converted, a black _RGBA_ color will be returned_
66
114
  *
67
115
  * @param value Original value
68
116
  * @returns _RGBA_ color
@@ -71,4 +119,4 @@ function hexToRgba(value) {
71
119
  return convertHexToRgba(value);
72
120
  }
73
121
  //#endregion
74
- export { getNormalizedHex, hexToHsl, hexToHsla, hexToRgb, hexToRgba };
122
+ export { getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba };
@@ -1,29 +1,55 @@
1
- import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "../models.mjs";
2
-
1
+ import { HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
3
2
  //#region src/color/space/hsl.d.ts
4
3
  declare function getHslValue(value: Record<keyof HSLColor, unknown>): HSLColor;
4
+ /**
5
+ * Convert an _HSL(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
6
+ *
7
+ * _If the value is unable to be converted, a black hex color will be returned_
8
+ *
9
+ * @param hsl _HSL(A)_ color
10
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
11
+ * @returns Hex color string
12
+ */
5
13
  declare function hslToHex(hsl: HSLAColor | HSLColor, alpha?: boolean): string;
14
+ /**
15
+ * Convert an _HSL(A)_ color to an _HWB_ color
16
+ *
17
+ * _If the value is unable to be converted, a black _HWB_ color will be returned_
18
+ *
19
+ * @param hsl HSL(A) color
20
+ * @returns _HWB_ color
21
+ */
22
+ declare function hslToHwb(hsl: HSLAColor | HSLColor): HWBColor;
23
+ /**
24
+ * Convert an _HSL(A)_ color to an _HWBA_ color
25
+ *
26
+ * _If the value is unable to be converted, a black _HWBA_ color will be returned_
27
+ *
28
+ * @param hsl HSL(A) color
29
+ * @returns _HWBA_ color
30
+ */
31
+ declare function hslToHwba(hsl: HSLAColor | HSLColor): HWBAColor;
6
32
  /**
7
33
  * Convert an _HSL(A)_ color to an _RGB_ color
8
34
  *
9
- * _If the value is unable to be converted, a black RGB color will be returned_
35
+ * _If the value is unable to be converted, a black _RGB_ color will be returned_
10
36
  *
11
37
  * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
12
38
  *
13
39
  * @param hsl HSL(A) color
14
- * @returns RGB color
40
+ * @returns _RGB_ color
15
41
  */
16
42
  declare function hslToRgb(hsl: HSLAColor | HSLColor): RGBColor;
17
43
  /**
18
44
  * Convert an _HSL(A)_ color to an _RGBA_ color
19
45
  *
20
- * _If the value is unable to be converted, a black RGBA color with an alpha channel (opactiy) of `0` will be returned_
46
+ * _If the value is unable to be converted, a black _RGBA_ color will be returned_
21
47
  *
22
48
  * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
23
49
  *
24
50
  * @param hsl HSL(A) color
25
- * @returns RGBA color
51
+ * @returns _RGBA_ color
26
52
  */
27
53
  declare function hslToRgba(hsl: HSLAColor | HSLColor): RGBAColor;
28
54
  //#endregion
29
- export { getHslValue, hslToHex, hslToRgb, hslToRgba };
55
+ export { getHslValue, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba };
@@ -1,19 +1,34 @@
1
1
  import { DEFAULT_HSL } from "../constants.mjs";
2
2
  import { getAlphaValue } from "../misc/alpha.mjs";
3
- import { isHslLike } from "../misc/is.mjs";
4
3
  import { getDegrees, getHexValue, getPercentage } from "../misc/get.mjs";
4
+ import { isHslLike } from "../misc/is.mjs";
5
5
  import { convertRgbToHex } from "./rgb.mjs";
6
6
  //#region src/color/space/hsl.ts
7
- function convertHslToRgba(value) {
8
- const hsl = isHslLike(value) ? getHslValue(value) : { ...DEFAULT_HSL };
7
+ function convertHslToHwba(input) {
8
+ let { hue, lightness, saturation } = isHslLike(input) ? getHslValue(input) : { ...DEFAULT_HSL };
9
+ lightness /= 100;
10
+ saturation /= 100;
11
+ const value = lightness + saturation * Math.min(lightness, 1 - lightness);
12
+ if (value === 0) saturation = 0;
13
+ else saturation = 2 * (1 - lightness / value);
14
+ const blackness = 1 - value;
15
+ return {
16
+ hue,
17
+ whiteness: (1 - saturation) * value * 100,
18
+ blackness: blackness * 100,
19
+ alpha: getAlphaValue(input?.alpha ?? 100)
20
+ };
21
+ }
22
+ function convertHslToRgba(input) {
23
+ const hsl = isHslLike(input) ? getHslValue(input) : { ...DEFAULT_HSL };
9
24
  const hue = hsl.hue % 360;
10
25
  const saturation = hsl.saturation / 100;
11
26
  const lightness = hsl.lightness / 100;
12
27
  return {
13
- alpha: getAlphaValue(value.alpha ?? 1),
14
- blue: getHexValue(Math.round(getHexyValue(hue, lightness, saturation, 4))),
15
- green: getHexValue(Math.round(getHexyValue(hue, lightness, saturation, 8))),
16
- red: getHexValue(Math.round(getHexyValue(hue, lightness, saturation, 0)))
28
+ alpha: getAlphaValue(input?.alpha ?? 100),
29
+ blue: getHexValue(getHexyValue(hue, lightness, saturation, 4)),
30
+ green: getHexValue(getHexyValue(hue, lightness, saturation, 8)),
31
+ red: getHexValue(getHexyValue(hue, lightness, saturation, 0))
17
32
  };
18
33
  }
19
34
  function getHexyValue(hue, lightness, saturation, value) {
@@ -23,22 +38,58 @@ function getHexyValue(hue, lightness, saturation, value) {
23
38
  function getHslValue(value) {
24
39
  return {
25
40
  hue: getDegrees(value.hue),
26
- lightness: getPercentage(value.lightness),
27
- saturation: getPercentage(value.saturation)
41
+ saturation: getPercentage(value.saturation),
42
+ lightness: getPercentage(value.lightness)
28
43
  };
29
44
  }
45
+ /**
46
+ * Convert an _HSL(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
47
+ *
48
+ * _If the value is unable to be converted, a black hex color will be returned_
49
+ *
50
+ * @param hsl _HSL(A)_ color
51
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
52
+ * @returns Hex color string
53
+ */
30
54
  function hslToHex(hsl, alpha) {
31
55
  return convertRgbToHex(convertHslToRgba(hsl), alpha ?? false);
32
56
  }
33
57
  /**
58
+ * Convert an _HSL(A)_ color to an _HWB_ color
59
+ *
60
+ * _If the value is unable to be converted, a black _HWB_ color will be returned_
61
+ *
62
+ * @param hsl HSL(A) color
63
+ * @returns _HWB_ color
64
+ */
65
+ function hslToHwb(hsl) {
66
+ const { blackness, hue, whiteness } = convertHslToHwba(hsl);
67
+ return {
68
+ hue,
69
+ whiteness,
70
+ blackness
71
+ };
72
+ }
73
+ /**
74
+ * Convert an _HSL(A)_ color to an _HWBA_ color
75
+ *
76
+ * _If the value is unable to be converted, a black _HWBA_ color will be returned_
77
+ *
78
+ * @param hsl HSL(A) color
79
+ * @returns _HWBA_ color
80
+ */
81
+ function hslToHwba(hsl) {
82
+ return convertHslToHwba(hsl);
83
+ }
84
+ /**
34
85
  * Convert an _HSL(A)_ color to an _RGB_ color
35
86
  *
36
- * _If the value is unable to be converted, a black RGB color will be returned_
87
+ * _If the value is unable to be converted, a black _RGB_ color will be returned_
37
88
  *
38
89
  * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
39
90
  *
40
91
  * @param hsl HSL(A) color
41
- * @returns RGB color
92
+ * @returns _RGB_ color
42
93
  */
43
94
  function hslToRgb(hsl) {
44
95
  const { blue, green, red } = convertHslToRgba(hsl);
@@ -51,15 +102,15 @@ function hslToRgb(hsl) {
51
102
  /**
52
103
  * Convert an _HSL(A)_ color to an _RGBA_ color
53
104
  *
54
- * _If the value is unable to be converted, a black RGBA color with an alpha channel (opactiy) of `0` will be returned_
105
+ * _If the value is unable to be converted, a black _RGBA_ color will be returned_
55
106
  *
56
107
  * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
57
108
  *
58
109
  * @param hsl HSL(A) color
59
- * @returns RGBA color
110
+ * @returns _RGBA_ color
60
111
  */
61
112
  function hslToRgba(hsl) {
62
113
  return convertHslToRgba(hsl);
63
114
  }
64
115
  //#endregion
65
- export { getHslValue, hslToHex, hslToRgb, hslToRgba };
116
+ export { getHslValue, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba };
@@ -0,0 +1,52 @@
1
+ import { HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
2
+ //#region src/color/space/hwb.d.ts
3
+ declare function convertHwbToHsl(input: HWBAColor | HWBColor): HSLAColor;
4
+ declare function getHwbValue(value: Record<keyof HWBColor, unknown>): HWBColor;
5
+ /**
6
+ * Convert an _HWB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
7
+ *
8
+ * _If the value is unable to be converted, a black hex color will be returned_
9
+ *
10
+ * @param hwb _HWB(A)_ color
11
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
12
+ * @returns Hex color string
13
+ */
14
+ declare function hwbToHex(hwb: HWBAColor | HWBColor, alpha?: boolean): string;
15
+ /**
16
+ * Convert an _HWB(A)_ color to an _RGB_ color
17
+ *
18
+ * _If the value is unable to be converted, a black _RGB_ color will be returned_
19
+ *
20
+ * @param hwb _HWB(A)_ color
21
+ * @returns _RGB_ color
22
+ */
23
+ declare function hwbToHsl(hwb: HWBAColor | HWBColor): HSLColor;
24
+ /**
25
+ * Convert an _HWB(A)_ color to an _HSLA_ color
26
+ *
27
+ * _If the value is unable to be converted, a black _HSLA_ color will be returned_
28
+ *
29
+ * @param hwb _HWB(A)_ color
30
+ * @returns _HSLA_ color
31
+ */
32
+ declare function hwbToHsla(hwb: HWBAColor | HWBColor): HSLAColor;
33
+ /**
34
+ * Convert an _HWB(A)_ color to an _RGB_ color
35
+ *
36
+ * _If the value is unable to be converted, a black _RGB_ color will be returned_
37
+ *
38
+ * @param hwb _HWB(A)_ color
39
+ * @returns _RGB_ color
40
+ */
41
+ declare function hwbToRgb(hwb: HWBAColor | HWBColor): RGBColor;
42
+ /**
43
+ * Convert an _HWB(A)_ color to an _RGBA_ color
44
+ *
45
+ * _If the value is unable to be converted, a black _RGBA_ color will be returned_
46
+ *
47
+ * @param hwb _HWB(A)_ color
48
+ * @returns _RGBA_ color
49
+ */
50
+ declare function hwbToRgba(hwb: HWBAColor | HWBColor): RGBAColor;
51
+ //#endregion
52
+ export { convertHwbToHsl, getHwbValue, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba };
@@ -0,0 +1,99 @@
1
+ import { DEFAULT_HWB } from "../constants.mjs";
2
+ import { getAlphaValue } from "../misc/alpha.mjs";
3
+ import { getDegrees, getPercentage } from "../misc/get.mjs";
4
+ import { isHwbLike } from "../misc/is.mjs";
5
+ import { rgbToHex } from "./rgb.mjs";
6
+ import { hslToRgb, hslToRgba } from "./hsl.mjs";
7
+ //#region src/color/space/hwb.ts
8
+ function convertHwbToHsl(input) {
9
+ let { blackness, hue, whiteness } = isHwbLike(input) ? getHwbValue(input) : DEFAULT_HWB;
10
+ blackness /= 100;
11
+ whiteness /= 100;
12
+ if (blackness + whiteness > 1) {
13
+ const total = blackness + whiteness;
14
+ blackness /= total;
15
+ whiteness /= total;
16
+ }
17
+ const lightness = (1 - blackness + whiteness) / 2;
18
+ return {
19
+ hue,
20
+ saturation: getHwbSaturation(blackness, whiteness, lightness) * 100,
21
+ lightness: lightness * 100,
22
+ alpha: getAlphaValue(input?.alpha ?? 100)
23
+ };
24
+ }
25
+ function getHwbSaturation(blackness, whiteness, lightness) {
26
+ const hue = 1 - blackness - whiteness;
27
+ if (hue <= 0) return 0;
28
+ return hue / Math.min(2 * lightness, 2 - 2 * lightness);
29
+ }
30
+ function getHwbValue(value) {
31
+ return {
32
+ hue: getDegrees(value.hue),
33
+ whiteness: getPercentage(value.whiteness),
34
+ blackness: getPercentage(value.blackness)
35
+ };
36
+ }
37
+ /**
38
+ * Convert an _HWB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
39
+ *
40
+ * _If the value is unable to be converted, a black hex color will be returned_
41
+ *
42
+ * @param hwb _HWB(A)_ color
43
+ * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
44
+ * @returns Hex color string
45
+ */
46
+ function hwbToHex(hwb, alpha) {
47
+ return rgbToHex(hwbToRgb(hwb), alpha);
48
+ }
49
+ /**
50
+ * Convert an _HWB(A)_ color to an _RGB_ color
51
+ *
52
+ * _If the value is unable to be converted, a black _RGB_ color will be returned_
53
+ *
54
+ * @param hwb _HWB(A)_ color
55
+ * @returns _RGB_ color
56
+ */
57
+ function hwbToHsl(hwb) {
58
+ const { hue, lightness, saturation } = convertHwbToHsl(hwb);
59
+ return {
60
+ hue,
61
+ lightness,
62
+ saturation
63
+ };
64
+ }
65
+ /**
66
+ * Convert an _HWB(A)_ color to an _HSLA_ color
67
+ *
68
+ * _If the value is unable to be converted, a black _HSLA_ color will be returned_
69
+ *
70
+ * @param hwb _HWB(A)_ color
71
+ * @returns _HSLA_ color
72
+ */
73
+ function hwbToHsla(hwb) {
74
+ return convertHwbToHsl(hwb);
75
+ }
76
+ /**
77
+ * Convert an _HWB(A)_ color to an _RGB_ color
78
+ *
79
+ * _If the value is unable to be converted, a black _RGB_ color will be returned_
80
+ *
81
+ * @param hwb _HWB(A)_ color
82
+ * @returns _RGB_ color
83
+ */
84
+ function hwbToRgb(hwb) {
85
+ return hslToRgb(hwbToHsl(hwb));
86
+ }
87
+ /**
88
+ * Convert an _HWB(A)_ color to an _RGBA_ color
89
+ *
90
+ * _If the value is unable to be converted, a black _RGBA_ color will be returned_
91
+ *
92
+ * @param hwb _HWB(A)_ color
93
+ * @returns _RGBA_ color
94
+ */
95
+ function hwbToRgba(hwb) {
96
+ return hslToRgba(hwbToHsla(hwb));
97
+ }
98
+ //#endregion
99
+ export { convertHwbToHsl, getHwbValue, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba };
@@ -1,8 +1,8 @@
1
- import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "../models.mjs";
2
-
1
+ import { HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
3
2
  //#region src/color/space/rgb.d.ts
4
3
  declare function convertRgbToHex(rgb: RGBAColor | RGBColor, alpha: boolean): string;
5
4
  declare function convertRgbToHsla(value: unknown): HSLAColor;
5
+ declare function convertRgbToHwba(value: unknown): HWBAColor;
6
6
  declare function getRgbValue(value: Record<keyof RGBColor, unknown>): RGBColor;
7
7
  /**
8
8
  * Convert an _RGB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
@@ -17,7 +17,7 @@ declare function rgbToHex(rgb: RGBAColor | RGBColor, alpha?: boolean): string;
17
17
  /**
18
18
  * Convert an _RGB(A)_ color to an _HSL_ color
19
19
  *
20
- * _If the value is unable to be converted, a black HSL color will be returned_
20
+ * _If the value is unable to be converted, a black _HSL_ color will be returned_
21
21
  *
22
22
  * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
23
23
  *
@@ -28,7 +28,7 @@ declare function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor;
28
28
  /**
29
29
  * Convert an _RGB(A)_ color to an _HSLA_ color
30
30
  *
31
- * _If the value is unable to be converted, a black _HSLA_ color with an alpha channel (opacity) of `0` will be returned_
31
+ * _If the value is unable to be converted, a black _HSLA_ color will be returned_
32
32
  *
33
33
  * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
34
34
  *
@@ -36,5 +36,26 @@ declare function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor;
36
36
  * @returns _HSLA_ color
37
37
  */
38
38
  declare function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor;
39
+ /**
40
+ * Convert an _RGB(A)_ color to an _HWB_ color
41
+ *
42
+ * _If the value is unable to be converted, a black _HWB_ color will be returned_
43
+ *
44
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
45
+ *
46
+ * @param rgb _RGB(A)_ color
47
+ * @returns _HWB_ color
48
+ */
49
+ declare function rgbToHwb(rgb: RGBAColor | RGBColor): HWBColor;
50
+ /**
51
+ * Convert an _RGB(A)_ color to an _HWBA_ color
52
+ * _If the value is unable to be converted, a black _HWBA_ color will be returned_
53
+ *
54
+ * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
55
+ *
56
+ * @param rgb _RGB(A)_ color
57
+ * @returns _HWBA_ color
58
+ */
59
+ declare function rgbToHwba(rgb: RGBAColor | RGBColor): HWBAColor;
39
60
  //#endregion
40
- export { convertRgbToHex, convertRgbToHsla, getRgbValue, rgbToHex, rgbToHsl, rgbToHsla };
61
+ export { convertRgbToHex, convertRgbToHsla, convertRgbToHwba, getRgbValue, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };