@oscarpalmer/atoms 0.188.0 → 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 (130) 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 +664 -265
  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 +8 -7
  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
  130. package/src/string/index.ts +13 -11
@@ -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 rgb = isRgbLike(value) ? getRgbValue(value) : { ...DEFAULT_RGB };
22
- const blue = rgb.blue / 255;
23
- const green = rgb.green / 255;
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 = (maxHex - lightness) / Math.min(lightness, 1 - lightness);
33
- switch (maxHex) {
34
- case blue:
35
- hue = (red - green) / delta + 4;
36
- break;
37
- case green:
38
- hue = (blue - red) / delta + 2;
39
- break;
40
- case red:
41
- hue = (green - blue) / delta + (green < blue ? 6 : 0);
42
- break;
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
- alpha: getAlphaValue(value.alpha ?? 1),
48
- hue: +hue.toFixed(2),
49
- lightness: +(lightness * 100).toFixed(2),
50
- saturation: +(saturation * 100).toFixed(2)
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 HSL color will be returned_
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 with an alpha channel (opacity) of `0` will be returned_
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> } : never : Path extends keyof Value ? { [Key in Path]: Value[Key] } : never : never;
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
  *
@@ -1,5 +1,4 @@
1
1
  import { AsyncCancelableCallback, CancelableCallback, GenericAsyncCallback, GenericCallback } from "../models.mjs";
2
-
3
2
  //#region src/function/limit.d.ts
4
3
  /**
5
4
  * Debounce a function, ensuring it is only called after `time` milliseconds have passed
@@ -1,5 +1,4 @@
1
1
  import { GenericCallback } from "../models.mjs";
2
-
3
2
  //#region src/function/memoize.d.ts
4
3
  /**
5
4
  * A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_
@@ -1,5 +1,4 @@
1
1
  import { GenericAsyncCallback, GenericCallback, OnceAsyncCallback, OnceCallback } from "../models.mjs";
2
-
3
2
  //#region src/function/once.d.ts
4
3
  /**
5
4
  * Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
@@ -1,5 +1,4 @@
1
1
  import { GenericAsyncCallback, GenericCallback } from "../models.mjs";
2
-
3
2
  //#region src/function/retry.d.ts
4
3
  /**
5
4
  * An error thrown when a retry fails
@@ -1,6 +1,5 @@
1
1
  import { GenericCallback } from "../models.mjs";
2
2
  import { UnwrapValue } from "../result/models.mjs";
3
-
4
3
  //#region src/function/work.d.ts
5
4
  /**
6
5
  * A synchronous _Flow_, a function that pipe a value through a series of functions
package/dist/herald.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { GenericCallback } from "./models.mjs";
2
-
3
2
  //#region src/herald.d.ts
4
3
  declare class Events<Map extends Record<string, GenericCallback>> {
5
4
  #private;