@oscarpalmer/atoms 0.190.0 → 0.191.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 (42) hide show
  1. package/dist/color/constants.d.mts +7 -1
  2. package/dist/color/constants.mjs +7 -1
  3. package/dist/color/index.d.mts +3 -3
  4. package/dist/color/index.mjs +2 -2
  5. package/dist/color/instance.mjs +27 -25
  6. package/dist/color/misc/alpha.d.mts +1 -1
  7. package/dist/color/misc/alpha.mjs +10 -7
  8. package/dist/color/misc/format.d.mts +7 -0
  9. package/dist/color/misc/format.mjs +20 -0
  10. package/dist/color/misc/get.mjs +16 -16
  11. package/dist/color/misc/is.d.mts +0 -36
  12. package/dist/color/misc/is.mjs +1 -37
  13. package/dist/color/misc/state.d.mts +3 -2
  14. package/dist/color/misc/state.mjs +69 -83
  15. package/dist/color/models.d.mts +28 -5
  16. package/dist/color/space/hex.d.mts +3 -2
  17. package/dist/color/space/hex.mjs +13 -1
  18. package/dist/color/space/hsl.d.mts +3 -2
  19. package/dist/color/space/hsl.mjs +13 -1
  20. package/dist/color/space/hwb.d.mts +3 -2
  21. package/dist/color/space/hwb.mjs +13 -1
  22. package/dist/color/space/rgb.d.mts +3 -2
  23. package/dist/color/space/rgb.mjs +14 -2
  24. package/dist/index.d.mts +23 -29
  25. package/dist/index.mjs +198 -184
  26. package/package.json +4 -4
  27. package/src/color/constants.ts +12 -0
  28. package/src/color/index.ts +26 -8
  29. package/src/color/instance.ts +60 -45
  30. package/src/color/misc/alpha.ts +12 -6
  31. package/src/color/misc/format.ts +29 -0
  32. package/src/color/misc/get.ts +20 -13
  33. package/src/color/misc/is.ts +7 -37
  34. package/src/color/misc/state.ts +115 -127
  35. package/src/color/models.ts +32 -4
  36. package/src/color/space/hex.ts +34 -1
  37. package/src/color/space/hsl.ts +40 -2
  38. package/src/color/space/hwb.ts +32 -2
  39. package/src/color/space/rgb.ts +33 -3
  40. package/dist/color/misc/index.d.mts +0 -7
  41. package/dist/color/misc/index.mjs +0 -15
  42. package/src/color/misc/index.ts +0 -29
@@ -8,9 +8,14 @@ import {
8
8
  KEYS_RGB,
9
9
  LENGTH_LONG,
10
10
  MAX_PERCENT,
11
+ TYPE_HEX,
12
+ TYPE_HSL,
13
+ TYPE_HWB,
14
+ TYPE_RGB,
11
15
  } from '../constants';
12
16
  import type {
13
17
  ColorState,
18
+ ColorType,
14
19
  HSLAColor,
15
20
  HSLColor,
16
21
  HWBAColor,
@@ -18,114 +23,108 @@ import type {
18
23
  RGBAColor,
19
24
  RGBColor,
20
25
  } from '../models';
21
- import {getNormalizedHex, hexToHsl, hexToRgb} from '../space/hex';
22
- import {getHslValue, hslToHex, hslToHwb, hslToRgb} from '../space/hsl';
23
- import {getHwbValue, hwbToHex, hwbToHsl, hwbToRgb} from '../space/hwb';
24
- import {getRgbValue, rgbToHex, rgbToHsl, rgbToHwb} from '../space/rgb';
26
+ import {getColorFromHex, getNormalizedHex} from '../space/hex';
27
+ import {getColorFromHsl, getHslValue} from '../space/hsl';
28
+ import {getColorFromHwb, getHwbValue} from '../space/hwb';
29
+ import {getColorFromRgb, getRgbValue} from '../space/rgb';
25
30
  import {getAlpha} from './alpha';
26
31
  import {getDegrees, getHexValue, getPercentage} from './get';
27
32
  import {isColor, isHexColor, isHslLike, isHwbLike, isRgbLike} from './is';
28
33
 
29
34
  // #region Functions
30
35
 
36
+ export function getColorFromState<Type extends ColorType>(
37
+ state: ColorState,
38
+ type: Type,
39
+ ): NonNullable<ColorState[Type]> {
40
+ const {origin} = state;
41
+
42
+ if (type === origin) {
43
+ return state[origin] as NonNullable<ColorState[Type]>;
44
+ }
45
+
46
+ return state[type] ?? (getters[origin](state, type) as NonNullable<ColorState[Type]>);
47
+ }
48
+
31
49
  export function getColorState(value: unknown): ColorState {
32
50
  if (typeof value === 'string') {
33
51
  return getColorStateForHex(value);
34
52
  }
35
53
 
36
54
  if (isColor(value)) {
55
+ const {origin} = value;
56
+
37
57
  return {
38
- hex: value.hex,
39
- hsl: value.hsl,
40
- hwb: value.hwb,
41
- rgb: value.rgb,
42
- alpha: getAlpha(value.alpha),
58
+ origin,
59
+ [origin]: value[origin],
60
+ alpha: getAlpha(value.alpha, false),
43
61
  };
44
62
  }
45
63
 
46
- const state: Partial<ColorState> = {};
47
-
48
64
  if (typeof value === 'object' && value !== null) {
49
- state.alpha = getAlpha((value as HSLAColor).alpha);
65
+ const state: ColorState = {
66
+ alpha: getAlpha((value as HSLAColor).alpha, false),
67
+ origin: undefined as never,
68
+ };
50
69
 
51
70
  if (KEYS_HSL.every(key => key in value)) {
52
- return getColorStateForHsl(state, value as Record<keyof HSLColor, unknown>);
53
- }
54
-
55
- if (KEYS_HWB.every(key => key in value)) {
56
- return getColorStateForHwb(state, value as Record<keyof HWBColor, unknown>);
71
+ state.hsl = getHslValue(value as Record<keyof HSLColor, unknown>);
72
+ state.origin = TYPE_HSL;
73
+ } else if (KEYS_HWB.every(key => key in value)) {
74
+ state.hwb = getHwbValue(value as Record<keyof HWBColor, unknown>);
75
+ state.origin = TYPE_HWB;
76
+ } else if (KEYS_RGB.every(key => key in value)) {
77
+ state.rgb = getRgbValue(value as Record<keyof RGBColor, unknown>);
78
+ state.origin = TYPE_RGB;
57
79
  }
58
80
 
59
- if (KEYS_RGB.every(key => key in value)) {
60
- return getColorStateForRgb(state, value as Record<keyof RGBColor, unknown>);
81
+ if (state.origin != null) {
82
+ return state;
61
83
  }
62
84
  }
63
85
 
64
- return getDefaultColorState(state);
86
+ return getDefaultColorState();
65
87
  }
66
88
 
67
89
  function getColorStateForHex(value: string): ColorState {
68
90
  const normalized = getNormalizedHex(value, true);
69
91
  const hex = normalized.slice(0, LENGTH_LONG);
70
92
 
71
- const hsl = hexToHsl(hex);
72
-
73
93
  return {
74
94
  hex,
75
- hsl,
76
- alpha: getAlpha(normalized.slice(LENGTH_LONG)),
77
- hwb: hslToHwb(hsl),
78
- rgb: hslToRgb(hsl),
95
+ alpha: getAlpha(normalized.slice(LENGTH_LONG), true),
96
+ origin: TYPE_HEX,
79
97
  };
80
98
  }
81
99
 
82
- function getColorStateForHsl(
83
- state: Partial<ColorState>,
84
- value: Record<keyof HSLColor, unknown>,
85
- ): ColorState {
86
- state.hsl = getHslValue(value);
87
-
88
- state.rgb = hslToRgb(state.hsl);
89
- state.hex = hslToHex(state.hsl);
90
- state.hwb = hslToHwb(state.hsl);
91
-
92
- return state as ColorState;
93
- }
94
-
95
- function getColorStateForHwb(
96
- state: Partial<ColorState>,
97
- value: Record<keyof HWBColor, unknown>,
98
- ): ColorState {
99
- state.hwb = getHwbValue(value);
100
-
101
- state.hsl = hwbToHsl(state.hwb);
102
- state.rgb = hwbToRgb(state.hwb);
103
- state.hex = hwbToHex(state.hwb);
104
-
105
- return state as ColorState;
106
- }
107
-
108
- function getColorStateForRgb(
109
- state: Partial<ColorState>,
110
- value: Record<keyof RGBColor, unknown>,
111
- ): ColorState {
112
- state.rgb = getRgbValue(value);
113
-
114
- state.hex = rgbToHex(state.rgb);
115
- state.hsl = rgbToHsl(state.rgb);
116
- state.hwb = rgbToHwb(state.rgb);
117
-
118
- return state as ColorState;
100
+ function getDefaultColorState(): ColorState {
101
+ return {
102
+ alpha: getAlpha(MAX_PERCENT, false),
103
+ hex: HEX_BLACK,
104
+ hsl: {...DEFAULT_HSL},
105
+ hwb: {...DEFAULT_HWB},
106
+ rgb: {...DEFAULT_RGB},
107
+ origin: TYPE_HEX,
108
+ };
119
109
  }
120
110
 
121
- function getDefaultColorState(state: Partial<ColorState>): ColorState {
122
- state.alpha = getAlpha(MAX_PERCENT);
123
- state.hex = HEX_BLACK;
124
- state.hsl = {...DEFAULT_HSL};
125
- state.hwb = {...DEFAULT_HWB};
126
- state.rgb = {...DEFAULT_RGB};
127
-
128
- return state as ColorState;
111
+ function setColorValue<Type extends ColorType>(
112
+ state: ColorState,
113
+ type: Type,
114
+ value: ColorState[Type],
115
+ alpha?: number | string,
116
+ ): void {
117
+ state.hex = undefined;
118
+ state.hsl = undefined;
119
+ state.hwb = undefined;
120
+ state.rgb = undefined;
121
+
122
+ state.origin = type;
123
+ state[type] = value;
124
+
125
+ if (alpha != null) {
126
+ state.alpha = getAlpha(alpha, type === TYPE_HEX);
127
+ }
129
128
  }
130
129
 
131
130
  export function setHexColor(state: ColorState, value: string, alpha: boolean): void {
@@ -134,18 +133,13 @@ export function setHexColor(state: ColorState, value: string, alpha: boolean): v
134
133
  }
135
134
 
136
135
  const normalized = getNormalizedHex(value, true);
137
- const hex = normalized.slice(0, LENGTH_LONG);
138
- const hsl = hexToHsl(hex);
139
136
 
140
- state.hex = hex;
141
- state.hsl = hsl;
142
-
143
- state.rgb = hslToRgb(hsl);
144
- state.hwb = hslToHwb(hsl);
145
-
146
- if (alpha) {
147
- state.alpha = getAlpha(normalized.slice(LENGTH_LONG));
148
- }
137
+ setColorValue(
138
+ state,
139
+ TYPE_HEX,
140
+ normalized.slice(0, LENGTH_LONG),
141
+ alpha ? normalized.slice(LENGTH_LONG) : undefined,
142
+ );
149
143
  }
150
144
 
151
145
  export function setHSLColor(state: ColorState, value: unknown, alpha: boolean): void {
@@ -153,21 +147,16 @@ export function setHSLColor(state: ColorState, value: unknown, alpha: boolean):
153
147
  return;
154
148
  }
155
149
 
156
- const hsl = {
157
- hue: getDegrees((value as HSLColor).hue),
158
- saturation: getPercentage((value as HSLColor).saturation),
159
- lightness: getPercentage((value as HSLColor).lightness),
160
- };
161
-
162
- state.hsl = hsl;
163
-
164
- state.hex = hslToHex(hsl);
165
- state.hwb = hslToHwb(hsl);
166
- state.rgb = hslToRgb(hsl);
167
-
168
- if (alpha) {
169
- state.alpha = getAlpha((value as HSLAColor).alpha);
170
- }
150
+ setColorValue(
151
+ state,
152
+ TYPE_HSL,
153
+ {
154
+ hue: getDegrees((value as HSLColor).hue),
155
+ saturation: getPercentage((value as HSLColor).saturation),
156
+ lightness: getPercentage((value as HSLColor).lightness),
157
+ },
158
+ alpha ? (value as HSLAColor).alpha : undefined,
159
+ );
171
160
  }
172
161
 
173
162
  export function setHWBColor(state: ColorState, value: unknown, alpha: boolean): void {
@@ -175,21 +164,16 @@ export function setHWBColor(state: ColorState, value: unknown, alpha: boolean):
175
164
  return;
176
165
  }
177
166
 
178
- const hwb = {
179
- hue: getDegrees((value as HWBColor).hue),
180
- whiteness: getPercentage((value as HWBColor).whiteness),
181
- blackness: getPercentage((value as HWBColor).blackness),
182
- };
183
-
184
- state.hwb = hwb;
185
-
186
- state.hex = hwbToHex(hwb);
187
- state.hsl = hwbToHsl(hwb);
188
- state.rgb = hwbToRgb(hwb);
189
-
190
- if (alpha) {
191
- state.alpha = getAlpha((value as HWBAColor).alpha);
192
- }
167
+ setColorValue(
168
+ state,
169
+ TYPE_HWB,
170
+ {
171
+ hue: getDegrees((value as HWBColor).hue),
172
+ whiteness: getPercentage((value as HWBColor).whiteness),
173
+ blackness: getPercentage((value as HWBColor).blackness),
174
+ },
175
+ alpha ? (value as HWBAColor).alpha : undefined,
176
+ );
193
177
  }
194
178
 
195
179
  export function setRGBColor(state: ColorState, value: unknown, alpha: boolean): void {
@@ -197,23 +181,27 @@ export function setRGBColor(state: ColorState, value: unknown, alpha: boolean):
197
181
  return;
198
182
  }
199
183
 
200
- const rgb = {
201
- blue: getHexValue((value as RGBColor).blue),
202
- green: getHexValue((value as RGBColor).green),
203
- red: getHexValue((value as RGBColor).red),
204
- };
205
-
206
- const hsl = rgbToHsl(rgb);
184
+ setColorValue(
185
+ state,
186
+ TYPE_RGB,
187
+ {
188
+ red: getHexValue((value as RGBColor).red),
189
+ green: getHexValue((value as RGBColor).green),
190
+ blue: getHexValue((value as RGBColor).blue),
191
+ },
192
+ alpha ? (value as RGBAColor).alpha : undefined,
193
+ );
194
+ }
207
195
 
208
- state.hsl = hsl;
209
- state.rgb = rgb;
196
+ // #endregion
210
197
 
211
- state.hex = hslToHex(hsl);
212
- state.hwb = hslToHwb(hsl);
198
+ // #region Variables
213
199
 
214
- if (alpha) {
215
- state.alpha = getAlpha((value as RGBAColor).alpha);
216
- }
217
- }
200
+ const getters: Record<ColorType, (state: ColorState, type: ColorType) => any> = {
201
+ hex: getColorFromHex,
202
+ hsl: getColorFromHsl,
203
+ hwb: getColorFromHwb,
204
+ rgb: getColorFromRgb,
205
+ };
218
206
 
219
207
  // #endregion
@@ -117,6 +117,13 @@ export type Color = {
117
117
  */
118
118
  set hwba(value: HWBAColor);
119
119
 
120
+ /**
121
+ * Last color format that was set on the color
122
+ *
123
+ * @returns Color type
124
+ */
125
+ get origin(): ColorType;
126
+
120
127
  /**
121
128
  * Get the color as an _RGB_ color
122
129
  *
@@ -259,10 +266,31 @@ export type ColorProperty = 'alpha' | keyof HSLColor | keyof HWBColor | keyof RG
259
266
 
260
267
  export type ColorState = {
261
268
  alpha: Alpha;
262
- hex: string;
263
- hsl: HSLColor;
264
- hwb: HWBColor;
265
- rgb: RGBColor;
269
+ hex?: string;
270
+ hsl?: HSLColor;
271
+ hwb?: HWBColor;
272
+ origin: ColorType;
273
+ rgb?: RGBColor;
266
274
  };
267
275
 
276
+ /**
277
+ * Base color types
278
+ */
279
+ export type ColorType = 'hex' | 'hsl' | 'hwb' | 'rgb';
280
+
281
+ /**
282
+ * Extended color types
283
+ */
284
+ export type ColorTypeExtended = ColorType | 'hsla' | 'hwba' | 'rgba';
285
+
286
+ /**
287
+ * Base color values
288
+ */
289
+ export type ColorValue = string | HSLColor | HWBColor | RGBColor;
290
+
291
+ /**
292
+ * Extended color values
293
+ */
294
+ export type ColorValueExtended = ColorValue | HSLAColor | HWBAColor | RGBAColor;
295
+
268
296
  // #endregion
@@ -8,10 +8,22 @@ import {
8
8
  LENGTH_LONG,
9
9
  LENGTH_SHORT,
10
10
  MAX_HEX,
11
+ TYPE_HSL,
12
+ TYPE_HWB,
13
+ TYPE_RGB,
11
14
  } from '../constants';
12
15
  import {getHexValue, getPercentage} from '../misc/get';
13
16
  import {isHexColor} from '../misc/is';
14
- import type {HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor} from '../models';
17
+ import type {
18
+ ColorState,
19
+ ColorType,
20
+ HSLAColor,
21
+ HSLColor,
22
+ HWBAColor,
23
+ HWBColor,
24
+ RGBAColor,
25
+ RGBColor,
26
+ } from '../models';
15
27
  import {convertRgbToHsla, convertRgbToHwba} from './rgb';
16
28
 
17
29
  // #region Functions
@@ -35,6 +47,27 @@ function convertHexToRgba(value: string): RGBAColor {
35
47
  };
36
48
  }
37
49
 
50
+ export function getColorFromHex<Type extends ColorType>(
51
+ state: ColorState,
52
+ type: Type,
53
+ ): NonNullable<ColorState[Type]> {
54
+ switch (type) {
55
+ case TYPE_HSL:
56
+ state.hsl ??= hexToHsl(state.hex!);
57
+ break;
58
+
59
+ case TYPE_HWB:
60
+ state.hwb ??= hexToHwb(state.hex!);
61
+ break;
62
+
63
+ case TYPE_RGB:
64
+ state.rgb ??= hexToRgb(state.hex!);
65
+ break;
66
+ }
67
+
68
+ return state[type]!;
69
+ }
70
+
38
71
  /**
39
72
  * Get the normalized hex color from a value
40
73
  *
@@ -1,8 +1,25 @@
1
- import {DEFAULT_HSL, MAX_DEGREE, MAX_HEX, MAX_PERCENT} from '../constants';
1
+ import {
2
+ DEFAULT_HSL,
3
+ MAX_DEGREE,
4
+ MAX_HEX,
5
+ MAX_PERCENT,
6
+ TYPE_HEX,
7
+ TYPE_HWB,
8
+ TYPE_RGB,
9
+ } from '../constants';
2
10
  import {getAlphaValue} from '../misc/alpha';
3
11
  import {getDegrees, getHexValue, getPercentage} from '../misc/get';
4
12
  import {isHslLike} from '../misc/is';
5
- import type {HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor} from '../models';
13
+ import type {
14
+ ColorState,
15
+ ColorType,
16
+ HSLAColor,
17
+ HSLColor,
18
+ HWBAColor,
19
+ HWBColor,
20
+ RGBAColor,
21
+ RGBColor,
22
+ } from '../models';
6
23
  import {convertRgbToHex} from './rgb';
7
24
 
8
25
  // #region Functions
@@ -49,6 +66,27 @@ function convertHslToRgba(input: unknown): RGBAColor {
49
66
  };
50
67
  }
51
68
 
69
+ export function getColorFromHsl<Type extends ColorType>(
70
+ state: ColorState,
71
+ type: Type,
72
+ ): NonNullable<ColorState[Type]> {
73
+ switch (type) {
74
+ case TYPE_HEX:
75
+ state.hex = hslToHex(state.hsl!);
76
+ break;
77
+
78
+ case TYPE_HWB:
79
+ state.hwb = hslToHwb(state.hsl!);
80
+ break;
81
+
82
+ case TYPE_RGB:
83
+ state.rgb = hslToRgb(state.hsl!);
84
+ break;
85
+ }
86
+
87
+ return state[type]!;
88
+ }
89
+
52
90
  function getHexyValue(hue: number, lightness: number, saturation: number, value: number): number {
53
91
  const part = (value + hue / 30) % 12;
54
92
  const mod = saturation * Math.min(lightness, 1 - lightness);
@@ -1,8 +1,17 @@
1
- import {DEFAULT_HWB, MAX_PERCENT} from '../constants';
1
+ import {DEFAULT_HWB, MAX_PERCENT, TYPE_HEX, TYPE_HSL, TYPE_RGB} from '../constants';
2
2
  import {getAlphaValue} from '../misc/alpha';
3
3
  import {getDegrees, getPercentage} from '../misc/get';
4
4
  import {isHwbLike} from '../misc/is';
5
- import type {HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor} from '../models';
5
+ import type {
6
+ ColorState,
7
+ ColorType,
8
+ HSLAColor,
9
+ HSLColor,
10
+ HWBAColor,
11
+ HWBColor,
12
+ RGBAColor,
13
+ RGBColor,
14
+ } from '../models';
6
15
  import {hslToRgb, hslToRgba} from './hsl';
7
16
  import {rgbToHex} from './rgb';
8
17
 
@@ -33,6 +42,27 @@ export function convertHwbToHsl(input: HWBAColor | HWBColor): HSLAColor {
33
42
  };
34
43
  }
35
44
 
45
+ export function getColorFromHwb<Type extends ColorType>(
46
+ state: ColorState,
47
+ type: Type,
48
+ ): NonNullable<ColorState[Type]> {
49
+ switch (type) {
50
+ case TYPE_HEX:
51
+ state.hex = hwbToHex(state.hwb!);
52
+ break;
53
+
54
+ case TYPE_HSL:
55
+ state.hsl = hwbToHsl(state.hwb!);
56
+ break;
57
+
58
+ case TYPE_RGB:
59
+ state.rgb = hwbToRgb(state.hwb!);
60
+ break;
61
+ }
62
+
63
+ return state[type]!;
64
+ }
65
+
36
66
  function getHwbSaturation(blackness: number, whiteness: number, lightness: number): number {
37
67
  const value = 1 - blackness;
38
68
 
@@ -1,9 +1,18 @@
1
1
  import {join} from '../../internal/string';
2
- import {DEFAULT_RGB, MAX_HEX, MAX_PERCENT} from '../constants';
2
+ import {DEFAULT_RGB, MAX_HEX, MAX_PERCENT, TYPE_HEX, TYPE_HSL, TYPE_HWB} from '../constants';
3
3
  import {getAlpha, getAlphaValue} from '../misc/alpha';
4
4
  import {getHexValue} from '../misc/get';
5
5
  import {isRgbLike} from '../misc/is';
6
- import type {HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor} from '../models';
6
+ import type {
7
+ ColorState,
8
+ ColorType,
9
+ HSLAColor,
10
+ HSLColor,
11
+ HWBAColor,
12
+ HWBColor,
13
+ RGBAColor,
14
+ RGBColor,
15
+ } from '../models';
7
16
 
8
17
  // #region Types
9
18
 
@@ -32,7 +41,7 @@ export function convertRgbToHex(rgb: RGBAColor | RGBColor, alpha: boolean): stri
32
41
  let a = '';
33
42
 
34
43
  if (typeof alpha === 'boolean' && alpha) {
35
- a = getAlpha((rgb as RGBAColor).alpha).hex;
44
+ a = getAlpha((rgb as RGBAColor).alpha, false).hex;
36
45
  }
37
46
 
38
47
  return `${hex}${a}`;
@@ -87,6 +96,27 @@ export function convertRgbToHwba(value: unknown): HWBAColor {
87
96
  };
88
97
  }
89
98
 
99
+ export function getColorFromRgb<Type extends ColorType>(
100
+ state: ColorState,
101
+ type: Type,
102
+ ): NonNullable<ColorState[Type]> {
103
+ switch (type) {
104
+ case TYPE_HEX:
105
+ state.hex = rgbToHex(state.rgb!);
106
+ break;
107
+
108
+ case TYPE_HSL:
109
+ state.hsl = rgbToHsl(state.rgb!);
110
+ break;
111
+
112
+ case TYPE_HWB:
113
+ state.hwb = rgbToHwb(state.rgb!);
114
+ break;
115
+ }
116
+
117
+ return state[type]!;
118
+ }
119
+
90
120
  function getRgbHue(values: RgbValues): number {
91
121
  const {blue, delta, green, max, red} = values;
92
122
 
@@ -1,7 +0,0 @@
1
- import { ColorState } from "../models.mjs";
2
- //#region src/color/misc/index.d.ts
3
- declare function formatHslColor(state: ColorState, alpha: boolean): string;
4
- declare function formatHwbColor(state: ColorState, alpha: boolean): string;
5
- declare function formatRgbColor(state: ColorState, alpha: boolean): string;
6
- //#endregion
7
- export { formatHslColor, formatHwbColor, formatRgbColor };
@@ -1,15 +0,0 @@
1
- //#region src/color/misc/index.ts
2
- function formatHslColor(state, alpha) {
3
- const { hue, lightness, saturation } = state.hsl;
4
- return `hsl(${hue}deg ${saturation}% ${lightness}%${alpha ? ` / ${state.alpha.value}%` : ""})`;
5
- }
6
- function formatHwbColor(state, alpha) {
7
- const { blackness, hue, whiteness } = state.hwb;
8
- return `hwb(${hue}deg ${whiteness}% ${blackness}%${alpha ? ` / ${state.alpha.value}%` : ""})`;
9
- }
10
- function formatRgbColor(state, alpha) {
11
- const { blue, green, red } = state.rgb;
12
- return `rgb(${red} ${green} ${blue}${alpha ? ` / ${state.alpha.value}%` : ""})`;
13
- }
14
- //#endregion
15
- export { formatHslColor, formatHwbColor, formatRgbColor };
@@ -1,29 +0,0 @@
1
- import type {ColorState} from '../models';
2
-
3
- // #region Functions
4
-
5
- export function formatHslColor(state: ColorState, alpha: boolean): string {
6
- const {hue, lightness, saturation} = state.hsl;
7
-
8
- const suffix = alpha ? ` / ${state.alpha.value}%` : '';
9
-
10
- return `hsl(${hue}deg ${saturation}% ${lightness}%${suffix})`;
11
- }
12
-
13
- export function formatHwbColor(state: ColorState, alpha: boolean): string {
14
- const {blackness, hue, whiteness} = state.hwb;
15
-
16
- const suffix = alpha ? ` / ${state.alpha.value}%` : '';
17
-
18
- return `hwb(${hue}deg ${whiteness}% ${blackness}%${suffix})`;
19
- }
20
-
21
- export function formatRgbColor(state: ColorState, alpha: boolean): string {
22
- const {blue, green, red} = state.rgb;
23
-
24
- const suffix = alpha ? ` / ${state.alpha.value}%` : '';
25
-
26
- return `rgb(${red} ${green} ${blue}${suffix})`;
27
- }
28
-
29
- // #endregion