@oscarpalmer/atoms 0.202.0 → 0.204.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 (187) hide show
  1. package/dist/array/difference.d.mts +4 -5
  2. package/dist/array/exists.d.mts +5 -6
  3. package/dist/array/filter.d.mts +10 -11
  4. package/dist/array/filter.mjs +0 -1
  5. package/dist/array/find.d.mts +10 -11
  6. package/dist/array/find.mjs +0 -1
  7. package/dist/array/first.d.mts +10 -11
  8. package/dist/array/first.mjs +0 -1
  9. package/dist/array/flatten.d.mts +2 -3
  10. package/dist/array/from.d.mts +7 -8
  11. package/dist/array/group-by.d.mts +7 -8
  12. package/dist/array/group-by.mjs +0 -1
  13. package/dist/array/insert.d.mts +3 -4
  14. package/dist/array/intersection.d.mts +4 -5
  15. package/dist/array/last.d.mts +10 -11
  16. package/dist/array/last.mjs +0 -1
  17. package/dist/array/move.d.mts +9 -10
  18. package/dist/array/move.mjs +0 -4
  19. package/dist/array/partition.d.mts +5 -6
  20. package/dist/array/push.d.mts +2 -3
  21. package/dist/array/reverse.d.mts +2 -3
  22. package/dist/array/select.d.mts +11 -12
  23. package/dist/array/select.mjs +0 -1
  24. package/dist/array/single.d.mts +4 -5
  25. package/dist/array/slice.d.mts +12 -13
  26. package/dist/array/sort.d.mts +31 -32
  27. package/dist/array/sort.mjs +38 -39
  28. package/dist/array/splice.d.mts +5 -6
  29. package/dist/array/swap.d.mts +8 -9
  30. package/dist/array/swap.mjs +0 -1
  31. package/dist/array/to-map.d.mts +7 -8
  32. package/dist/array/to-map.mjs +0 -1
  33. package/dist/array/to-record.d.mts +7 -8
  34. package/dist/array/to-record.mjs +0 -1
  35. package/dist/array/to-set.d.mts +4 -5
  36. package/dist/array/toggle.d.mts +4 -5
  37. package/dist/array/union.d.mts +4 -5
  38. package/dist/array/unique.d.mts +4 -5
  39. package/dist/array/update.d.mts +4 -5
  40. package/dist/beacon.d.mts +8 -9
  41. package/dist/beacon.mjs +96 -71
  42. package/dist/color/constants.d.mts +14 -13
  43. package/dist/color/constants.mjs +9 -2
  44. package/dist/color/index.d.mts +2 -2
  45. package/dist/color/instance.d.mts +3 -3
  46. package/dist/color/instance.mjs +91 -69
  47. package/dist/color/misc/alpha.d.mts +7 -6
  48. package/dist/color/misc/alpha.mjs +8 -2
  49. package/dist/color/misc/format.d.mts +6 -7
  50. package/dist/color/misc/format.mjs +15 -12
  51. package/dist/color/misc/get.d.mts +14 -15
  52. package/dist/color/misc/is.d.mts +16 -17
  53. package/dist/color/misc/is.mjs +7 -7
  54. package/dist/color/misc/state.d.mts +33 -10
  55. package/dist/color/misc/state.mjs +28 -48
  56. package/dist/color/models.d.mts +25 -19
  57. package/dist/color/space/hex.d.mts +14 -11
  58. package/dist/color/space/hex.mjs +21 -2
  59. package/dist/color/space/hsl.d.mts +13 -10
  60. package/dist/color/space/hsl.mjs +25 -4
  61. package/dist/color/space/hwb.d.mts +14 -11
  62. package/dist/color/space/hwb.mjs +24 -3
  63. package/dist/color/space/rgb.d.mts +16 -13
  64. package/dist/color/space/rgb.mjs +41 -20
  65. package/dist/function/limit.d.mts +9 -8
  66. package/dist/function/limit.mjs +5 -7
  67. package/dist/function/once.d.mts +26 -6
  68. package/dist/function/once.mjs +129 -76
  69. package/dist/function/retry.d.mts +5 -6
  70. package/dist/function/retry.mjs +3 -4
  71. package/dist/index.d.mts +184 -60
  72. package/dist/index.mjs +1292 -970
  73. package/dist/internal/aborter.d.mts +9 -0
  74. package/dist/internal/{abort.mjs → aborter.mjs} +1 -1
  75. package/dist/internal/array/callbacks.d.mts +4 -5
  76. package/dist/internal/array/chunk.d.mts +2 -3
  77. package/dist/internal/array/compact.d.mts +3 -4
  78. package/dist/internal/array/find.d.mts +10 -11
  79. package/dist/internal/array/get.d.mts +7 -8
  80. package/dist/internal/array/get.mjs +3 -2
  81. package/dist/internal/array/group.d.mts +2 -3
  82. package/dist/internal/array/index-of.d.mts +10 -11
  83. package/dist/internal/array/index-of.mjs +0 -1
  84. package/dist/internal/array/insert.d.mts +5 -6
  85. package/dist/internal/array/match.d.mts +17 -18
  86. package/dist/internal/array/overlap.d.mts +2 -3
  87. package/dist/internal/array/sets.d.mts +5 -6
  88. package/dist/internal/array/shuffle.d.mts +2 -3
  89. package/dist/internal/array/update.d.mts +2 -3
  90. package/dist/internal/defaults.d.mts +3 -4
  91. package/dist/internal/function/assert.d.mts +10 -11
  92. package/dist/internal/function/assert.mjs +0 -7
  93. package/dist/internal/function/limit.d.mts +41 -0
  94. package/dist/internal/function/limit.mjs +106 -0
  95. package/dist/internal/function/memoize.d.mts +4 -5
  96. package/dist/internal/function/memoize.mjs +55 -31
  97. package/dist/internal/function/misc.d.mts +2 -3
  98. package/dist/internal/function/work.d.mts +53 -54
  99. package/dist/internal/function/work.mjs +0 -2
  100. package/dist/internal/herald.d.mts +8 -9
  101. package/dist/internal/herald.mjs +38 -27
  102. package/dist/internal/is.d.mts +19 -20
  103. package/dist/internal/math/aggregate.d.mts +14 -15
  104. package/dist/internal/math/misc.d.mts +3 -4
  105. package/dist/internal/number.d.mts +4 -5
  106. package/dist/internal/random.d.mts +3 -4
  107. package/dist/internal/result/misc.d.mts +29 -14
  108. package/dist/internal/result/misc.mjs +4 -3
  109. package/dist/internal/result/models.d.mts +9 -10
  110. package/dist/internal/sized/map.d.mts +2 -3
  111. package/dist/internal/sized/misc.d.mts +2 -3
  112. package/dist/internal/string/case.d.mts +9 -10
  113. package/dist/internal/string/misc.d.mts +8 -9
  114. package/dist/internal/subscription.d.mts +10 -11
  115. package/dist/internal/subscription.mjs +72 -58
  116. package/dist/internal/value/compare.d.mts +17 -9
  117. package/dist/internal/value/compare.mjs +6 -11
  118. package/dist/internal/value/equal.d.mts +34 -15
  119. package/dist/internal/value/equal.mjs +20 -13
  120. package/dist/internal/value/get.d.mts +3 -4
  121. package/dist/internal/value/handlers.d.mts +19 -9
  122. package/dist/internal/value/handlers.mjs +48 -50
  123. package/dist/internal/value/has.d.mts +6 -7
  124. package/dist/internal/value/has.mjs +0 -1
  125. package/dist/internal/value/misc.d.mts +6 -7
  126. package/dist/internal/value/misc.mjs +4 -3
  127. package/dist/internal/value/partial.d.mts +3 -4
  128. package/dist/internal/value/partial.mjs +2 -1
  129. package/dist/internal/value/set.d.mts +4 -5
  130. package/dist/internal/value/set.mjs +2 -1
  131. package/dist/is.d.mts +13 -13
  132. package/dist/logger.d.mts +5 -4
  133. package/dist/logger.mjs +72 -64
  134. package/dist/math.d.mts +20 -20
  135. package/dist/models.d.mts +45 -49
  136. package/dist/promise/constants.d.mts +14 -15
  137. package/dist/promise/delay.d.mts +3 -4
  138. package/dist/promise/delay.mjs +5 -5
  139. package/dist/promise/helpers.d.mts +7 -8
  140. package/dist/promise/helpers.mjs +4 -3
  141. package/dist/promise/index.d.mts +13 -14
  142. package/dist/promise/index.mjs +1 -2
  143. package/dist/promise/misc.d.mts +7 -7
  144. package/dist/promise/models.d.mts +17 -18
  145. package/dist/promise/timed.d.mts +4 -5
  146. package/dist/promise/timed.mjs +6 -6
  147. package/dist/query.d.mts +3 -4
  148. package/dist/queue.d.mts +14 -15
  149. package/dist/queue.mjs +198 -136
  150. package/dist/random.d.mts +8 -8
  151. package/dist/result/index.d.mts +8 -9
  152. package/dist/result/index.mjs +0 -1
  153. package/dist/result/match.d.mts +6 -7
  154. package/dist/result/match.mjs +0 -1
  155. package/dist/result/misc.d.mts +3 -3
  156. package/dist/result/work/flow.d.mts +28 -29
  157. package/dist/result/work/flow.mjs +0 -1
  158. package/dist/result/work/pipe.d.mts +24 -25
  159. package/dist/result/work/pipe.mjs +0 -1
  160. package/dist/sized/set.d.mts +2 -3
  161. package/dist/string/fuzzy.d.mts +21 -12
  162. package/dist/string/fuzzy.mjs +77 -52
  163. package/dist/string/index.d.mts +8 -8
  164. package/dist/string/match.d.mts +4 -5
  165. package/dist/string/normalize.d.mts +8 -9
  166. package/dist/string/normalize.mjs +9 -5
  167. package/dist/string/template.d.mts +9 -9
  168. package/dist/string/template.mjs +11 -5
  169. package/dist/value/clone.d.mts +21 -13
  170. package/dist/value/clone.mjs +19 -25
  171. package/dist/value/collection.d.mts +4 -5
  172. package/dist/value/diff.d.mts +5 -6
  173. package/dist/value/freeze.d.mts +18 -19
  174. package/dist/value/freeze.mjs +1 -5
  175. package/dist/value/merge.d.mts +13 -14
  176. package/dist/value/merge.mjs +21 -7
  177. package/dist/value/omit.d.mts +2 -3
  178. package/dist/value/pick.d.mts +2 -3
  179. package/dist/value/shake.d.mts +3 -4
  180. package/dist/value/smush.d.mts +3 -4
  181. package/dist/value/transform.d.mts +15 -10
  182. package/dist/value/transform.mjs +12 -8
  183. package/dist/value/unsmush.d.mts +3 -4
  184. package/package.json +2 -2
  185. package/dist/internal/abort.d.mts +0 -10
  186. package/dist/internal/function/timer.d.mts +0 -10
  187. package/dist/internal/function/timer.mjs +0 -87
@@ -1,11 +1,10 @@
1
- import { COLOR_DEFAULTS, COLOR_KEYS, COLOR_LENGTHS, COLOR_MAX, COLOR_TYPE } from "../constants.mjs";
1
+ import { COLOR_DEFAULTS, COLOR_KEYS, COLOR_LENGTHS, COLOR_MAX, COLOR_SYMBOL, COLOR_TYPE } from "../constants.mjs";
2
2
  import { getAlpha } from "./alpha.mjs";
3
- import { getDegrees, getHexValue, getPercentage } from "./get.mjs";
4
- import { isColor, isHexColor, isHslLike, isHwbLike, isRgbLike } from "./is.mjs";
5
- import { getColorFromRgb, getRgbValue } from "../space/rgb.mjs";
3
+ import { isColor } from "./is.mjs";
4
+ import { getColorFromRgb, getRgbValues } from "../space/rgb.mjs";
6
5
  import { getColorFromHex, getNormalizedHex } from "../space/hex.mjs";
7
- import { getColorFromHsl, getHslValue } from "../space/hsl.mjs";
8
- import { getColorFromHwb, getHwbValue } from "../space/hwb.mjs";
6
+ import { getColorFromHsl, getHslValues } from "../space/hsl.mjs";
7
+ import { getColorFromHwb, getHwbValues } from "../space/hwb.mjs";
9
8
  //#region src/color/misc/state.ts
10
9
  function getColorFromState(state, type) {
11
10
  const { origin } = state;
@@ -28,13 +27,13 @@ function getColorState(value) {
28
27
  origin: void 0
29
28
  };
30
29
  if (COLOR_KEYS.hsl.every((key) => key in value)) {
31
- state.hsl = getHslValue(value);
30
+ state.hsl = getHslValues(value);
32
31
  state.origin = COLOR_TYPE.hsl;
33
32
  } else if (COLOR_KEYS.hwb.every((key) => key in value)) {
34
- state.hwb = getHwbValue(value);
33
+ state.hwb = getHwbValues(value);
35
34
  state.origin = COLOR_TYPE.hwb;
36
35
  } else if (COLOR_KEYS.rgb.every((key) => key in value)) {
37
- state.rgb = getRgbValue(value);
36
+ state.rgb = getRgbValues(value);
38
37
  state.origin = COLOR_TYPE.rgb;
39
38
  }
40
39
  if (state.origin != null) return state;
@@ -59,45 +58,26 @@ function getDefaultColorState() {
59
58
  origin: COLOR_TYPE.hex
60
59
  };
61
60
  }
62
- function setColorValue(color, state, changes, type, value, alpha) {
63
- state.hex = void 0;
64
- state.hsl = void 0;
65
- state.hwb = void 0;
66
- state.rgb = void 0;
67
- state.origin = type;
68
- state[type] = value;
69
- if (alpha != null) state.alpha = getAlpha(alpha, type === COLOR_TYPE.hex);
70
- for (const type of COLOR_TYPE.all) if (changes.observed(type)) changes.emit(type, color[type]);
71
- changes.emit(COLOR_TYPE.wildcard, color);
61
+ function getStateValue(instance, type, alpha) {
62
+ const { values } = instance[COLOR_SYMBOL];
63
+ const value = getColorFromState(values, type);
64
+ if (typeof value === "string") return alpha ? `${value}${values.alpha.hex}` : value;
65
+ return alpha ? {
66
+ ...value,
67
+ alpha: values.alpha.value
68
+ } : { ...value };
72
69
  }
73
- function setHexColor(color, state, changes, value, alpha) {
74
- if (!isHexColor(value) || !alpha && value === state.hex) return;
75
- const normalized = getNormalizedHex(value, true);
76
- setColorValue(color, state, changes, COLOR_TYPE.hex, normalized.slice(0, COLOR_LENGTHS.hexLong), alpha ? normalized.slice(COLOR_LENGTHS.hexLong) : void 0);
77
- }
78
- function setHSLColor(color, state, changes, value, alpha) {
79
- if (!isHslLike(value)) return;
80
- setColorValue(color, state, changes, COLOR_TYPE.hsl, {
81
- hue: getDegrees(value.hue),
82
- saturation: getPercentage(value.saturation),
83
- lightness: getPercentage(value.lightness)
84
- }, alpha ? value.alpha : void 0);
85
- }
86
- function setHWBColor(color, state, changes, value, alpha) {
87
- if (!isHwbLike(value)) return;
88
- setColorValue(color, state, changes, COLOR_TYPE.hwb, {
89
- hue: getDegrees(value.hue),
90
- whiteness: getPercentage(value.whiteness),
91
- blackness: getPercentage(value.blackness)
92
- }, alpha ? value.alpha : void 0);
93
- }
94
- function setRGBColor(color, state, changes, value, alpha) {
95
- if (!isRgbLike(value)) return;
96
- setColorValue(color, state, changes, COLOR_TYPE.rgb, {
97
- red: getHexValue(value.red),
98
- green: getHexValue(value.green),
99
- blue: getHexValue(value.blue)
100
- }, alpha ? value.alpha : void 0);
70
+ function setStateValue(instance, type, value, alpha) {
71
+ const { changes, values } = instance[COLOR_SYMBOL];
72
+ values.hex = void 0;
73
+ values.hsl = void 0;
74
+ values.hwb = void 0;
75
+ values.rgb = void 0;
76
+ values.origin = type;
77
+ values[type] = value;
78
+ if (alpha != null) values.alpha = getAlpha(alpha, type === COLOR_TYPE.hex);
79
+ for (const type of COLOR_TYPE.all) if (changes.observed(type)) changes.emit(type, instance[type]);
80
+ changes.emit(COLOR_TYPE.wildcard, instance);
101
81
  }
102
82
  const getters = {
103
83
  hex: getColorFromHex,
@@ -106,4 +86,4 @@ const getters = {
106
86
  rgb: getColorFromRgb
107
87
  };
108
88
  //#endregion
109
- export { getColorFromState, getColorState, setHSLColor, setHWBColor, setHexColor, setRGBColor };
89
+ export { getColorFromState, getColorState, getStateValue, setStateValue };
@@ -1,15 +1,15 @@
1
1
  import { Subscription } from "../internal/subscription.mjs";
2
- import { HeraldEvents } from "../internal/herald.mjs";
3
- import { COLOR_ALPHA } from "./constants.mjs";
2
+ import { Herald, HeraldEvents } from "../internal/herald.mjs";
3
+ import { COLOR_SYMBOL } from "./constants.mjs";
4
4
  //#region src/color/models.d.ts
5
- type Alpha = {
5
+ export type Alpha = {
6
6
  hex: string;
7
7
  value: number;
8
8
  };
9
9
  /**
10
10
  * A color that is represented in multiple color formats
11
11
  */
12
- type Color = {
12
+ export type Color = {
13
13
  /**
14
14
  *
15
15
  */
@@ -186,7 +186,7 @@ type Color = {
186
186
  */
187
187
  unsubscribe(): void;
188
188
  };
189
- type ColorChanges = {
189
+ export type ColorChanges = {
190
190
  '*': (value: Color) => void;
191
191
  alpha: (value: number) => void;
192
192
  hex: (value: string) => void;
@@ -207,11 +207,11 @@ type ColorWithAlpha = {
207
207
  /**
208
208
  * An _HSL_ color with an alpha channel _(opacity)_
209
209
  */
210
- type HSLAColor = HSLColor & ColorWithAlpha;
210
+ export type HSLAColor = HSLColor & ColorWithAlpha;
211
211
  /**
212
212
  * An _HSL_ color
213
213
  */
214
- type HSLColor = {
214
+ export type HSLColor = {
215
215
  /**
216
216
  * Hue of the color _(in degrees; 0-360)_
217
217
  */
@@ -225,7 +225,7 @@ type HSLColor = {
225
225
  */
226
226
  saturation: number;
227
227
  };
228
- type HWBColor = {
228
+ export type HWBColor = {
229
229
  /**
230
230
  * Blackness of the color _(in percentage; 0-100)_
231
231
  */
@@ -239,15 +239,22 @@ type HWBColor = {
239
239
  */
240
240
  whiteness: number;
241
241
  };
242
- type HWBAColor = HWBColor & ColorWithAlpha;
242
+ export type HWBAColor = HWBColor & ColorWithAlpha;
243
+ export type InternalColor = {
244
+ [COLOR_SYMBOL]: InternalColorState;
245
+ } & Color;
246
+ export type InternalColorState = {
247
+ changes: Herald<ColorChanges>;
248
+ values: ColorState;
249
+ };
243
250
  /**
244
251
  * An _RGB_ color with an alpha channel _(opacity)_
245
252
  */
246
- type RGBAColor = RGBColor & ColorWithAlpha;
253
+ export type RGBAColor = RGBColor & ColorWithAlpha;
247
254
  /**
248
255
  * An _RGB_ color
249
256
  */
250
- type RGBColor = {
257
+ export type RGBColor = {
251
258
  /**
252
259
  * Blue channel of the color _(in hexadecimal; 0-255)_
253
260
  */
@@ -261,8 +268,8 @@ type RGBColor = {
261
268
  */
262
269
  red: number;
263
270
  };
264
- type ColorProperty = typeof COLOR_ALPHA.name | keyof HSLColor | keyof HWBColor | keyof RGBColor;
265
- type ColorState = {
271
+ export type ColorProperty = 'alpha' | keyof HSLColor | keyof HWBColor | keyof RGBColor;
272
+ export type ColorState = {
266
273
  alpha: Alpha;
267
274
  hex?: string;
268
275
  hsl?: HSLColor;
@@ -273,18 +280,17 @@ type ColorState = {
273
280
  /**
274
281
  * Base color types
275
282
  */
276
- type ColorType = 'hex' | 'hsl' | 'hwb' | 'rgb';
283
+ export type ColorType = 'hex' | 'hsl' | 'hwb' | 'rgb';
277
284
  /**
278
285
  * Extended color types
279
286
  */
280
- type ColorTypeExtended = ColorType | 'hsla' | 'hwba' | 'rgba';
287
+ export type ColorTypeExtended = ColorType | 'hsla' | 'hwba' | 'rgba';
281
288
  /**
282
289
  * Base color values
283
290
  */
284
- type ColorValue = string | HSLColor | HWBColor | RGBColor;
291
+ export type ColorValue = string | HSLColor | HWBColor | RGBColor;
285
292
  /**
286
293
  * Extended color values
287
294
  */
288
- type ColorValueExtended = ColorValue | HSLAColor | HWBAColor | RGBAColor;
289
- //#endregion
290
- export { Alpha, Color, ColorChanges, ColorProperty, ColorState, ColorType, ColorTypeExtended, ColorValue, ColorValueExtended, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor };
295
+ export type ColorValueExtended = ColorValue | HSLAColor | HWBAColor | RGBAColor;
296
+ //#endregion
@@ -1,6 +1,8 @@
1
- import { ColorState, ColorType, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
1
+ import { ColorState, ColorType, HSLAColor, HSLColor, HWBAColor, HWBColor, InternalColor, RGBAColor, RGBColor } from "../models.mjs";
2
2
  //#region src/color/space/hex.d.ts
3
- declare function getColorFromHex<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
3
+ export declare function getColorFromHex<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
4
+ export declare function getHexColor(this: InternalColor): string;
5
+ export declare function getHexaColor(this: InternalColor): string;
4
6
  /**
5
7
  * Get the normalized hex color from a value
6
8
  *
@@ -10,7 +12,7 @@ declare function getColorFromHex<Type extends ColorType>(state: ColorState, type
10
12
  * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
11
13
  * @returns Normalized hex color
12
14
  */
13
- declare function getNormalizedHex(value: unknown, alpha?: boolean): string;
15
+ export declare function getNormalizedHex(value: unknown, alpha?: boolean): string;
14
16
  /**
15
17
  * Convert a hex color string to a _HSL_ color
16
18
  *
@@ -19,7 +21,7 @@ declare function getNormalizedHex(value: unknown, alpha?: boolean): string;
19
21
  * @param value Hex color string
20
22
  * @returns _HSL_ color
21
23
  */
22
- declare function hexToHsl(value: string): HSLColor;
24
+ export declare function hexToHsl(value: string): HSLColor;
23
25
  /**
24
26
  * Convert a hex color string to a _HSLA_ color
25
27
  *
@@ -28,7 +30,7 @@ declare function hexToHsl(value: string): HSLColor;
28
30
  * @param value Hex color string
29
31
  * @returns _HSLA_ color
30
32
  */
31
- declare function hexToHsla(value: string): HSLAColor;
33
+ export declare function hexToHsla(value: string): HSLAColor;
32
34
  /**
33
35
  * Convert a hex color string to a _HWB_ color
34
36
  *
@@ -37,7 +39,7 @@ declare function hexToHsla(value: string): HSLAColor;
37
39
  * @param value Hex color string
38
40
  * @returns _HWB_ color
39
41
  */
40
- declare function hexToHwb(value: string): HWBColor;
42
+ export declare function hexToHwb(value: string): HWBColor;
41
43
  /**
42
44
  * Convert a hex color string to a _HWBA_ color
43
45
  *
@@ -46,7 +48,7 @@ declare function hexToHwb(value: string): HWBColor;
46
48
  * @param value Hex color string
47
49
  * @returns _HWBA_ color
48
50
  */
49
- declare function hexToHwba(value: string): HWBAColor;
51
+ export declare function hexToHwba(value: string): HWBAColor;
50
52
  /**
51
53
  * Convert a hex color to an _RGB_ color
52
54
  *
@@ -55,7 +57,7 @@ declare function hexToHwba(value: string): HWBAColor;
55
57
  * @param value Original value
56
58
  * @returns _RGB_ color
57
59
  */
58
- declare function hexToRgb(value: string): RGBColor;
60
+ export declare function hexToRgb(value: string): RGBColor;
59
61
  /**
60
62
  * Convert a hex color to an _RGBA_ color
61
63
  *
@@ -64,6 +66,7 @@ declare function hexToRgb(value: string): RGBColor;
64
66
  * @param value Original value
65
67
  * @returns _RGBA_ color
66
68
  */
67
- declare function hexToRgba(value: string): RGBAColor;
68
- //#endregion
69
- export { getColorFromHex, getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba };
69
+ export declare function hexToRgba(value: string): RGBAColor;
70
+ export declare function setHexValue(this: InternalColor, value: string): void;
71
+ export declare function setHexaValue(this: InternalColor, value: string): void;
72
+ //#endregion
@@ -1,8 +1,9 @@
1
1
  import { join } from "../../internal/string/misc.mjs";
2
- import { COLOR_ALPHA, COLOR_DEFAULTS, COLOR_EXPRESSION, COLOR_LENGTHS, COLOR_MAX, COLOR_TYPE } from "../constants.mjs";
2
+ import { COLOR_ALPHA, COLOR_DEFAULTS, COLOR_EXPRESSION, COLOR_LENGTHS, COLOR_MAX, COLOR_SYMBOL, COLOR_TYPE } from "../constants.mjs";
3
3
  import { getHexValue, getPercentage } from "../misc/get.mjs";
4
4
  import { isHexColor } from "../misc/is.mjs";
5
5
  import { convertRgbToHsla, convertRgbToHwba } from "./rgb.mjs";
6
+ import { getStateValue, setStateValue } from "../misc/state.mjs";
6
7
  //#region src/color/space/hex.ts
7
8
  function convertHexToRgba(value) {
8
9
  const normalized = getNormalizedHex(value, true);
@@ -29,6 +30,12 @@ function getColorFromHex(state, type) {
29
30
  }
30
31
  return state[type];
31
32
  }
33
+ function getHexColor() {
34
+ return getStateValue(this, COLOR_TYPE.hex, false);
35
+ }
36
+ function getHexaColor() {
37
+ return getStateValue(this, COLOR_TYPE.hex, true);
38
+ }
32
39
  /**
33
40
  * Get the normalized hex color from a value
34
41
  *
@@ -130,5 +137,17 @@ function hexToRgb(value) {
130
137
  function hexToRgba(value) {
131
138
  return convertHexToRgba(value);
132
139
  }
140
+ function setHexValue(value) {
141
+ setHexValueInState(this, value, false);
142
+ }
143
+ function setHexValueInState(instance, value, alpha) {
144
+ const { values } = instance[COLOR_SYMBOL];
145
+ if (!isHexColor(value) || !alpha && value === values.hex) return;
146
+ const normalized = getNormalizedHex(value, true);
147
+ setStateValue(instance, COLOR_TYPE.hex, normalized.slice(0, COLOR_LENGTHS.hexLong), alpha ? normalized.slice(COLOR_LENGTHS.hexLong) : void 0);
148
+ }
149
+ function setHexaValue(value) {
150
+ setHexValueInState(this, value, true);
151
+ }
133
152
  //#endregion
134
- export { getColorFromHex, getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba };
153
+ export { getColorFromHex, getHexColor, getHexaColor, getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, setHexValue, setHexaValue };
@@ -1,7 +1,9 @@
1
- import { ColorState, ColorType, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
1
+ import { ColorState, ColorType, HSLAColor, HSLColor, HWBAColor, HWBColor, InternalColor, RGBAColor, RGBColor } from "../models.mjs";
2
2
  //#region src/color/space/hsl.d.ts
3
- declare function getColorFromHsl<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
4
- declare function getHslValue(value: Record<keyof HSLColor, unknown>): HSLColor;
3
+ export declare function getColorFromHsl<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
4
+ export declare function getHslValue(this: InternalColor): HSLColor;
5
+ export declare function getHslaValue(this: InternalColor): HSLAColor;
6
+ export declare function getHslValues(value: Record<keyof HSLColor, unknown>): HSLColor;
5
7
  /**
6
8
  * Convert an _HSL(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
7
9
  *
@@ -11,7 +13,7 @@ declare function getHslValue(value: Record<keyof HSLColor, unknown>): HSLColor;
11
13
  * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
12
14
  * @returns Hex color string
13
15
  */
14
- declare function hslToHex(hsl: HSLAColor | HSLColor, alpha?: boolean): string;
16
+ export declare function hslToHex(hsl: HSLAColor | HSLColor, alpha?: boolean): string;
15
17
  /**
16
18
  * Convert an _HSL(A)_ color to an _HWB_ color
17
19
  *
@@ -20,7 +22,7 @@ declare function hslToHex(hsl: HSLAColor | HSLColor, alpha?: boolean): string;
20
22
  * @param hsl HSL(A) color
21
23
  * @returns _HWB_ color
22
24
  */
23
- declare function hslToHwb(hsl: HSLAColor | HSLColor): HWBColor;
25
+ export declare function hslToHwb(hsl: HSLAColor | HSLColor): HWBColor;
24
26
  /**
25
27
  * Convert an _HSL(A)_ color to an _HWBA_ color
26
28
  *
@@ -29,7 +31,7 @@ declare function hslToHwb(hsl: HSLAColor | HSLColor): HWBColor;
29
31
  * @param hsl HSL(A) color
30
32
  * @returns _HWBA_ color
31
33
  */
32
- declare function hslToHwba(hsl: HSLAColor | HSLColor): HWBAColor;
34
+ export declare function hslToHwba(hsl: HSLAColor | HSLColor): HWBAColor;
33
35
  /**
34
36
  * Convert an _HSL(A)_ color to an _RGB_ color
35
37
  *
@@ -40,7 +42,7 @@ declare function hslToHwba(hsl: HSLAColor | HSLColor): HWBAColor;
40
42
  * @param hsl HSL(A) color
41
43
  * @returns _RGB_ color
42
44
  */
43
- declare function hslToRgb(hsl: HSLAColor | HSLColor): RGBColor;
45
+ export declare function hslToRgb(hsl: HSLAColor | HSLColor): RGBColor;
44
46
  /**
45
47
  * Convert an _HSL(A)_ color to an _RGBA_ color
46
48
  *
@@ -51,6 +53,7 @@ declare function hslToRgb(hsl: HSLAColor | HSLColor): RGBColor;
51
53
  * @param hsl HSL(A) color
52
54
  * @returns _RGBA_ color
53
55
  */
54
- declare function hslToRgba(hsl: HSLAColor | HSLColor): RGBAColor;
55
- //#endregion
56
- export { getColorFromHsl, getHslValue, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba };
56
+ export declare function hslToRgba(hsl: HSLAColor | HSLColor): RGBAColor;
57
+ export declare function setHslValue(this: InternalColor, value: unknown): void;
58
+ export declare function setHslaValue(this: InternalColor, value: unknown): void;
59
+ //#endregion
@@ -3,9 +3,10 @@ import { getAlphaValue } from "../misc/alpha.mjs";
3
3
  import { getDegrees, getHexValue, getPercentage } from "../misc/get.mjs";
4
4
  import { isHslLike } from "../misc/is.mjs";
5
5
  import { convertRgbToHex } from "./rgb.mjs";
6
+ import { getStateValue, setStateValue } from "../misc/state.mjs";
6
7
  //#region src/color/space/hsl.ts
7
8
  function convertHslToHwba(input) {
8
- let { hue, lightness, saturation } = isHslLike(input) ? getHslValue(input) : { ...COLOR_DEFAULTS.hsl };
9
+ let { hue, lightness, saturation } = isHslLike(input) ? getHslValues(input) : { ...COLOR_DEFAULTS.hsl };
9
10
  lightness /= COLOR_MAX.percent;
10
11
  saturation /= COLOR_MAX.percent;
11
12
  const value = lightness + saturation * Math.min(lightness, 1 - lightness);
@@ -20,7 +21,7 @@ function convertHslToHwba(input) {
20
21
  };
21
22
  }
22
23
  function convertHslToRgba(input) {
23
- const hsl = isHslLike(input) ? getHslValue(input) : { ...COLOR_DEFAULTS.hsl };
24
+ const hsl = isHslLike(input) ? getHslValues(input) : { ...COLOR_DEFAULTS.hsl };
24
25
  const hue = hsl.hue % COLOR_MAX.degree;
25
26
  const saturation = hsl.saturation / COLOR_MAX.percent;
26
27
  const lightness = hsl.lightness / COLOR_MAX.percent;
@@ -47,7 +48,13 @@ function getHexyValue(hue, lightness, saturation, value) {
47
48
  const part = (value + hue / 30) % 12;
48
49
  return (lightness - saturation * Math.min(lightness, 1 - lightness) * Math.max(-1, Math.min(part - 3, 9 - part, 1))) * COLOR_MAX.hex;
49
50
  }
50
- function getHslValue(value) {
51
+ function getHslValue() {
52
+ return getStateValue(this, COLOR_TYPE.hsl, false);
53
+ }
54
+ function getHslaValue() {
55
+ return getStateValue(this, COLOR_TYPE.hsl, true);
56
+ }
57
+ function getHslValues(value) {
51
58
  return {
52
59
  hue: getDegrees(value.hue),
53
60
  saturation: getPercentage(value.saturation),
@@ -124,5 +131,19 @@ function hslToRgb(hsl) {
124
131
  function hslToRgba(hsl) {
125
132
  return convertHslToRgba(hsl);
126
133
  }
134
+ function setHslValue(value) {
135
+ setHSLValueInState(this, value, false);
136
+ }
137
+ function setHSLValueInState(instance, value, alpha) {
138
+ if (!isHslLike(value)) return;
139
+ setStateValue(instance, COLOR_TYPE.hsl, {
140
+ hue: getDegrees(value.hue),
141
+ saturation: getPercentage(value.saturation),
142
+ lightness: getPercentage(value.lightness)
143
+ }, alpha ? value.alpha : void 0);
144
+ }
145
+ function setHslaValue(value) {
146
+ setHSLValueInState(this, value, true);
147
+ }
127
148
  //#endregion
128
- export { getColorFromHsl, getHslValue, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba };
149
+ export { getColorFromHsl, getHslValue, getHslValues, getHslaValue, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, setHslValue, setHslaValue };
@@ -1,8 +1,10 @@
1
- import { ColorState, ColorType, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
1
+ import { ColorState, ColorType, HSLAColor, HSLColor, HWBAColor, HWBColor, InternalColor, RGBAColor, RGBColor } from "../models.mjs";
2
2
  //#region src/color/space/hwb.d.ts
3
- declare function convertHwbToHsl(input: HWBAColor | HWBColor): HSLAColor;
4
- declare function getColorFromHwb<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
5
- declare function getHwbValue(value: Record<keyof HWBColor, unknown>): HWBColor;
3
+ export declare function convertHwbToHsl(input: HWBAColor | HWBColor): HSLAColor;
4
+ export declare function getColorFromHwb<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
5
+ export declare function getHwbValue(this: InternalColor): HWBColor;
6
+ export declare function getHwbaValue(this: InternalColor): HWBAColor;
7
+ export declare function getHwbValues(value: Record<keyof HWBColor, unknown>): HWBColor;
6
8
  /**
7
9
  * Convert an _HWB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
8
10
  *
@@ -12,7 +14,7 @@ declare function getHwbValue(value: Record<keyof HWBColor, unknown>): HWBColor;
12
14
  * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
13
15
  * @returns Hex color string
14
16
  */
15
- declare function hwbToHex(hwb: HWBAColor | HWBColor, alpha?: boolean): string;
17
+ export declare function hwbToHex(hwb: HWBAColor | HWBColor, alpha?: boolean): string;
16
18
  /**
17
19
  * Convert an _HWB(A)_ color to an _RGB_ color
18
20
  *
@@ -21,7 +23,7 @@ declare function hwbToHex(hwb: HWBAColor | HWBColor, alpha?: boolean): string;
21
23
  * @param hwb _HWB(A)_ color
22
24
  * @returns _RGB_ color
23
25
  */
24
- declare function hwbToHsl(hwb: HWBAColor | HWBColor): HSLColor;
26
+ export declare function hwbToHsl(hwb: HWBAColor | HWBColor): HSLColor;
25
27
  /**
26
28
  * Convert an _HWB(A)_ color to an _HSLA_ color
27
29
  *
@@ -30,7 +32,7 @@ declare function hwbToHsl(hwb: HWBAColor | HWBColor): HSLColor;
30
32
  * @param hwb _HWB(A)_ color
31
33
  * @returns _HSLA_ color
32
34
  */
33
- declare function hwbToHsla(hwb: HWBAColor | HWBColor): HSLAColor;
35
+ export declare function hwbToHsla(hwb: HWBAColor | HWBColor): HSLAColor;
34
36
  /**
35
37
  * Convert an _HWB(A)_ color to an _RGB_ color
36
38
  *
@@ -39,7 +41,7 @@ declare function hwbToHsla(hwb: HWBAColor | HWBColor): HSLAColor;
39
41
  * @param hwb _HWB(A)_ color
40
42
  * @returns _RGB_ color
41
43
  */
42
- declare function hwbToRgb(hwb: HWBAColor | HWBColor): RGBColor;
44
+ export declare function hwbToRgb(hwb: HWBAColor | HWBColor): RGBColor;
43
45
  /**
44
46
  * Convert an _HWB(A)_ color to an _RGBA_ color
45
47
  *
@@ -48,6 +50,7 @@ declare function hwbToRgb(hwb: HWBAColor | HWBColor): RGBColor;
48
50
  * @param hwb _HWB(A)_ color
49
51
  * @returns _RGBA_ color
50
52
  */
51
- declare function hwbToRgba(hwb: HWBAColor | HWBColor): RGBAColor;
52
- //#endregion
53
- export { convertHwbToHsl, getColorFromHwb, getHwbValue, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba };
53
+ export declare function hwbToRgba(hwb: HWBAColor | HWBColor): RGBAColor;
54
+ export declare function setHwbValue(this: InternalColor, value: unknown): void;
55
+ export declare function setHwbaValue(this: InternalColor, value: unknown): void;
56
+ //#endregion
@@ -4,9 +4,10 @@ import { getDegrees, getPercentage } from "../misc/get.mjs";
4
4
  import { isHwbLike } from "../misc/is.mjs";
5
5
  import { rgbToHex } from "./rgb.mjs";
6
6
  import { hslToRgb, hslToRgba } from "./hsl.mjs";
7
+ import { getStateValue, setStateValue } from "../misc/state.mjs";
7
8
  //#region src/color/space/hwb.ts
8
9
  function convertHwbToHsl(input) {
9
- let { blackness, hue, whiteness } = isHwbLike(input) ? getHwbValue(input) : COLOR_DEFAULTS.hwb;
10
+ let { blackness, hue, whiteness } = isHwbLike(input) ? getHwbValues(input) : COLOR_DEFAULTS.hwb;
10
11
  blackness /= COLOR_MAX.percent;
11
12
  whiteness /= COLOR_MAX.percent;
12
13
  if (blackness + whiteness > 1) {
@@ -39,7 +40,13 @@ function getHwbSaturation(blackness, whiteness, lightness) {
39
40
  if (hue <= 0) return 0;
40
41
  return hue / Math.min(2 * lightness, 2 - 2 * lightness);
41
42
  }
42
- function getHwbValue(value) {
43
+ function getHwbValue() {
44
+ return getStateValue(this, COLOR_TYPE.hwb, false);
45
+ }
46
+ function getHwbaValue() {
47
+ return getStateValue(this, COLOR_TYPE.hwb, true);
48
+ }
49
+ function getHwbValues(value) {
43
50
  return {
44
51
  hue: getDegrees(value.hue),
45
52
  whiteness: getPercentage(value.whiteness),
@@ -107,5 +114,19 @@ function hwbToRgb(hwb) {
107
114
  function hwbToRgba(hwb) {
108
115
  return hslToRgba(hwbToHsla(hwb));
109
116
  }
117
+ function setHwbValue(value) {
118
+ setHwbColorValueInState(this, value, false);
119
+ }
120
+ function setHwbColorValueInState(instance, value, alpha) {
121
+ if (!isHwbLike(value)) return;
122
+ setStateValue(instance, COLOR_TYPE.hwb, {
123
+ hue: getDegrees(value.hue),
124
+ whiteness: getPercentage(value.whiteness),
125
+ blackness: getPercentage(value.blackness)
126
+ }, alpha ? value.alpha : void 0);
127
+ }
128
+ function setHwbaValue(value) {
129
+ setHwbColorValueInState(this, value, true);
130
+ }
110
131
  //#endregion
111
- export { convertHwbToHsl, getColorFromHwb, getHwbValue, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba };
132
+ export { convertHwbToHsl, getColorFromHwb, getHwbValue, getHwbValues, getHwbaValue, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, setHwbValue, setHwbaValue };
@@ -1,10 +1,12 @@
1
- import { ColorState, ColorType, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
1
+ import { ColorState, ColorType, HSLAColor, HSLColor, HWBAColor, HWBColor, InternalColor, RGBAColor, RGBColor } from "../models.mjs";
2
2
  //#region src/color/space/rgb.d.ts
3
- declare function convertRgbToHex(rgb: RGBAColor | RGBColor, alpha: boolean): string;
4
- declare function convertRgbToHsla(value: unknown): HSLAColor;
5
- declare function convertRgbToHwba(value: unknown): HWBAColor;
6
- declare function getColorFromRgb<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
7
- declare function getRgbValue(value: Record<keyof RGBColor, unknown>): RGBColor;
3
+ export declare function convertRgbToHex(rgb: RGBAColor | RGBColor, alpha: boolean): string;
4
+ export declare function convertRgbToHsla(value: unknown): HSLAColor;
5
+ export declare function convertRgbToHwba(value: unknown): HWBAColor;
6
+ export declare function getColorFromRgb<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
7
+ export declare function getRgbColor(this: InternalColor): RGBColor;
8
+ export declare function getRgbaColor(this: InternalColor): RGBAColor;
9
+ export declare function getRgbValues(value: Record<keyof RGBColor, unknown>): RGBColor;
8
10
  /**
9
11
  * Convert an _RGB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
10
12
  *
@@ -14,7 +16,7 @@ declare function getRgbValue(value: Record<keyof RGBColor, unknown>): RGBColor;
14
16
  * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
15
17
  * @returns Hex color string
16
18
  */
17
- declare function rgbToHex(rgb: RGBAColor | RGBColor, alpha?: boolean): string;
19
+ export declare function rgbToHex(rgb: RGBAColor | RGBColor, alpha?: boolean): string;
18
20
  /**
19
21
  * Convert an _RGB(A)_ color to an _HSL_ color
20
22
  *
@@ -25,7 +27,7 @@ declare function rgbToHex(rgb: RGBAColor | RGBColor, alpha?: boolean): string;
25
27
  * @param rgb _RGB(A)_ color
26
28
  * @returns _HSL_ color
27
29
  */
28
- declare function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor;
30
+ export declare function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor;
29
31
  /**
30
32
  * Convert an _RGB(A)_ color to an _HSLA_ color
31
33
  *
@@ -36,7 +38,7 @@ declare function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor;
36
38
  * @param rgb _RGB(A)_ color
37
39
  * @returns _HSLA_ color
38
40
  */
39
- declare function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor;
41
+ export declare function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor;
40
42
  /**
41
43
  * Convert an _RGB(A)_ color to an _HWB_ color
42
44
  *
@@ -47,7 +49,7 @@ declare function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor;
47
49
  * @param rgb _RGB(A)_ color
48
50
  * @returns _HWB_ color
49
51
  */
50
- declare function rgbToHwb(rgb: RGBAColor | RGBColor): HWBColor;
52
+ export declare function rgbToHwb(rgb: RGBAColor | RGBColor): HWBColor;
51
53
  /**
52
54
  * Convert an _RGB(A)_ color to an _HWBA_ color
53
55
  * _If the value is unable to be converted, a black _HWBA_ color will be returned_
@@ -57,6 +59,7 @@ declare function rgbToHwb(rgb: RGBAColor | RGBColor): HWBColor;
57
59
  * @param rgb _RGB(A)_ color
58
60
  * @returns _HWBA_ color
59
61
  */
60
- declare function rgbToHwba(rgb: RGBAColor | RGBColor): HWBAColor;
61
- //#endregion
62
- export { convertRgbToHex, convertRgbToHsla, convertRgbToHwba, getColorFromRgb, getRgbValue, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };
62
+ export declare function rgbToHwba(rgb: RGBAColor | RGBColor): HWBAColor;
63
+ export declare function setRgbValue(this: InternalColor, value: unknown): void;
64
+ export declare function setRgbaValue(this: InternalColor, value: unknown): void;
65
+ //#endregion