@lakuna/color 1.0.0 → 1.1.1

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 (51) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/names/getName.d.ts +1 -0
  7. package/dist/names/getName.d.ts.map +1 -1
  8. package/dist/names/getName.js +5 -1
  9. package/dist/names/getName.js.map +1 -1
  10. package/dist/names/tcapi.d.ts +9 -0
  11. package/dist/names/tcapi.d.ts.map +1 -0
  12. package/dist/names/tcapi.js +1849 -0
  13. package/dist/names/tcapi.js.map +1 -0
  14. package/dist/utility/cmyToCmyk.js +2 -2
  15. package/dist/utility/cmyToCmyk.js.map +1 -1
  16. package/dist/utility/deltaCmc.d.ts.map +1 -1
  17. package/dist/utility/deltaCmc.js +13 -9
  18. package/dist/utility/deltaCmc.js.map +1 -1
  19. package/dist/utility/deltaE00.d.ts.map +1 -1
  20. package/dist/utility/deltaE00.js +19 -18
  21. package/dist/utility/deltaE00.js.map +1 -1
  22. package/dist/utility/hexToRgb.d.ts +1 -1
  23. package/dist/utility/hexToRgb.js +1 -1
  24. package/dist/utility/hslToRgb.d.ts.map +1 -1
  25. package/dist/utility/hslToRgb.js +7 -8
  26. package/dist/utility/hslToRgb.js.map +1 -1
  27. package/dist/utility/hsvToRgb.d.ts.map +1 -1
  28. package/dist/utility/hsvToRgb.js +3 -1
  29. package/dist/utility/hsvToRgb.js.map +1 -1
  30. package/dist/utility/rgbToHex.d.ts +9 -0
  31. package/dist/utility/rgbToHex.d.ts.map +1 -0
  32. package/dist/utility/rgbToHex.js +10 -0
  33. package/dist/utility/rgbToHex.js.map +1 -0
  34. package/dist/utility/rgbToHsl.js +6 -7
  35. package/dist/utility/rgbToHsl.js.map +1 -1
  36. package/dist/utility/rgbToHsv.d.ts.map +1 -1
  37. package/dist/utility/rgbToHsv.js +12 -7
  38. package/dist/utility/rgbToHsv.js.map +1 -1
  39. package/package.json +14 -18
  40. package/src/index.ts +2 -0
  41. package/src/names/getName.ts +6 -1
  42. package/src/names/tcapi.ts +1851 -0
  43. package/src/utility/cmyToCmyk.ts +3 -3
  44. package/src/utility/deltaCmc.ts +17 -13
  45. package/src/utility/deltaE00.ts +24 -23
  46. package/src/utility/hexToRgb.ts +1 -1
  47. package/src/utility/hslToRgb.ts +10 -8
  48. package/src/utility/hsvToRgb.ts +5 -1
  49. package/src/utility/rgbToHex.ts +11 -0
  50. package/src/utility/rgbToHsl.ts +8 -8
  51. package/src/utility/rgbToHsv.ts +13 -8
@@ -17,7 +17,7 @@ export default function cmyToCmyk(color: Cmy): Cmyk {
17
17
 
18
18
  const k = Math.min(c, m, y, 1);
19
19
 
20
- return k === 1
21
- ? [0, 0, 0, 1]
22
- : [(c - k) / (1 - k), (m - k) / (1 - k), (y - k) / (1 - k), k];
20
+ return k === 1 ?
21
+ [0, 0, 0, 1]
22
+ : [(c - k) / (1 - k), (m - k) / (1 - k), (y - k) / (1 - k), k];
23
23
  }
@@ -30,16 +30,20 @@ export default function deltaCmc(
30
30
  const i1 = i0 ** 4;
31
31
  const i2 = Math.sqrt(i1 / (i1 + 1900));
32
32
  const i3 =
33
- b0 === 0
34
- ? a0 < 0
35
- ? 180
36
- : 0
37
- : a0 === 0
38
- ? b0 < 0
39
- ? 270
40
- : 90
41
- : Math.atan(b0 / a0) * 57.29577951 + // `180 / Math.PI`
42
- (a0 > 0 ? (b0 > 0 ? 0 : 360) : 180);
33
+ b0 === 0 ?
34
+ a0 < 0 ?
35
+ 180
36
+ : 0
37
+ : a0 === 0 ?
38
+ b0 < 0 ?
39
+ 270
40
+ : 90
41
+ : Math.atan(b0 / a0) * 57.29577951 + // `180 / Math.PI`
42
+ (a0 > 0 ?
43
+ b0 > 0 ?
44
+ 0
45
+ : 360
46
+ : 180);
43
47
  const i4 = (0.0638 * i0) / (1 + 0.0131 * i0) + 0.638;
44
48
  const i5 = Math.hypot(a1, b1) - i0;
45
49
 
@@ -49,9 +53,9 @@ export default function deltaCmc(
49
53
  i5 / (weight[1] * i4),
50
54
  Math.sqrt((a1 - a0) ** 2 + (b1 - b0) ** 2 - i5 ** 2) /
51
55
  ((i2 *
52
- (i3 < 164 || i3 > 345
53
- ? 0.36 + Math.abs(0.4 * Math.cos((35 + i3) * 0.01745329)) // `Math.PI / 180`
54
- : 0.56 + Math.abs(0.2 * Math.cos((168 + i3) * 0.01745329))) + // `Math.PI / 180`
56
+ (i3 < 164 || i3 > 345 ?
57
+ 0.36 + Math.abs(0.4 * Math.cos((35 + i3) * 0.01745329)) // `Math.PI / 180`
58
+ : 0.56 + Math.abs(0.2 * Math.cos((168 + i3) * 0.01745329))) + // `Math.PI / 180`
55
59
  1 -
56
60
  i2) *
57
61
  i4)
@@ -9,15 +9,20 @@ import type Lch from "../types/Lch.js";
9
9
  * @internal
10
10
  */
11
11
  const cieLabToHue = (a: number, b: number): number =>
12
- b === 0
13
- ? a < 0
14
- ? 180
15
- : 0
16
- : a === 0
17
- ? b < 0
18
- ? 270
19
- : 90
20
- : Math.atan(b / a) * 57.29577951 + (a > 0 ? (b > 0 ? 0 : 360) : 180); // `180 / Math.PI`
12
+ b === 0 ?
13
+ a < 0 ?
14
+ 180
15
+ : 0
16
+ : a === 0 ?
17
+ b < 0 ?
18
+ 270
19
+ : 90
20
+ : Math.atan(b / a) * 57.29577951 +
21
+ (a > 0 ?
22
+ b > 0 ?
23
+ 0
24
+ : 360
25
+ : 180); // `180 / Math.PI`
21
26
 
22
27
  /**
23
28
  * Calculates the ΔE* 2000 (also called the CIEDE2000) between two CIELAB values. Based on the EasyRGB pseudocode.
@@ -58,26 +63,22 @@ export default function deltaE00(
58
63
  const i9 = i3 * i6;
59
64
  const i10 = i4 + i7;
60
65
  const i11 =
61
- i9 === 0
62
- ? i10
63
- : Math.abs(i4 - i7) > 180
64
- ? i10 < 360
65
- ? (i10 + 360) / 2
66
- : (i10 - 360) / 2
67
- : i10 / 2;
66
+ i9 === 0 ? i10
67
+ : Math.abs(i4 - i7) > 180 ?
68
+ i10 < 360 ?
69
+ (i10 + 360) / 2
70
+ : (i10 - 360) / 2
71
+ : i10 / 2;
68
72
  const i12 = (i6 - i3) / (weight[1] * (1 + 0.045 * i8));
69
73
  const i13 = i7 - i4;
70
74
  const i14 =
71
75
  (2 *
72
76
  Math.sqrt(i9) *
73
77
  Math.sin(
74
- ((i9 === 0
75
- ? 0
76
- : Math.abs(i13) <= 180
77
- ? i13
78
- : i13 > 180
79
- ? i13 - 360
80
- : i13 + 360) /
78
+ ((i9 === 0 ? 0
79
+ : Math.abs(i13) <= 180 ? i13
80
+ : i13 > 180 ? i13 - 360
81
+ : i13 + 360) /
81
82
  2) *
82
83
  0.01745329 // `Math.PI / 180`
83
84
  )) /
@@ -3,7 +3,7 @@ import type Rgb from "../types/Rgb.js";
3
3
  /**
4
4
  * Split a hexadecimal value into sRGB values.
5
5
  * @param hex - The hexidecimal representation of the number (i.e. `0x50c878`).
6
- * @returns R, G, and B sRGB values (each in the range `[0x00,0xff]`), in that order.
6
+ * @returns An sRGB color.
7
7
  * @public
8
8
  */
9
9
  export default function hexToRgb(hex: number): Rgb {
@@ -10,16 +10,18 @@ import type Rgb from "../types/Rgb.js";
10
10
  * @internal
11
11
  */
12
12
  const hueToRgb = (v0: number, v1: number, h: number): number => {
13
- const i0 = h < 0 ? h + 1 : h > 1 ? h - 1 : h;
13
+ const i0 =
14
+ h < 0 ? h + 1
15
+ : h > 1 ? h - 1
16
+ : h;
14
17
  const i1 = 6 * i0;
15
18
  const i2 = v1 - v0;
16
- return i1 < 1
17
- ? v0 + i2 * i1
18
- : 2 * i0 < 1
19
- ? v1
20
- : 3 * i0 < 2
21
- ? v0 + i2 * (2 / 3 - i0) * 6
22
- : v0;
19
+ return (
20
+ i1 < 1 ? v0 + i2 * i1
21
+ : 2 * i0 < 1 ? v1
22
+ : 3 * i0 < 2 ? v0 + i2 * (2 / 3 - i0) * 6
23
+ : v0
24
+ );
23
25
  };
24
26
 
25
27
  /**
@@ -40,5 +40,9 @@ export default function hsvToRgb(color: Hsv): Rgb {
40
40
 
41
41
  const i7 = v * (1 - s * i4) * 0xff;
42
42
 
43
- return i3 === 1 ? [i7, i0, i6] : i3 === 3 ? [i6, i7, i0] : [i0, i6, i7];
43
+ return (
44
+ i3 === 1 ? [i7, i0, i6]
45
+ : i3 === 3 ? [i6, i7, i0]
46
+ : [i0, i6, i7]
47
+ );
44
48
  }
@@ -0,0 +1,11 @@
1
+ import type Rgb from "../types/Rgb.js";
2
+
3
+ /**
4
+ * Convert sRGB values into the numerical hexadecimal representation of the color.
5
+ * @param rgb - The sRGB representation of the number.
6
+ * @returns The numerical hexadecimal representation of the color.
7
+ * @public
8
+ */
9
+ export default function rgbToHex(rgb: Rgb): number {
10
+ return rgb[0] * 0x10000 + rgb[1] * 0x100 + rgb[2];
11
+ }
@@ -25,14 +25,14 @@ export default function rgbToHsl(color: Rgb): Hsl {
25
25
  const i7 = ((i4 - i1) / 6 + i5 / 2) / i5;
26
26
  const i8 = ((i4 - i2) / 6 + i5 / 2) / i5;
27
27
  const i9 =
28
- i0 === i4
29
- ? i8 - i7
30
- : i1 === i4
31
- ? 1 / 3 + i6 - i8
32
- : i2 === i4
33
- ? 2 / 3 + i7 - i6
34
- : 0;
35
- const h = i9 < 0 ? i9 + 1 : i9 > 1 ? i9 - 1 : i9;
28
+ i0 === i4 ? i8 - i7
29
+ : i1 === i4 ? 1 / 3 + i6 - i8
30
+ : i2 === i4 ? 2 / 3 + i7 - i6
31
+ : 0;
32
+ const h =
33
+ i9 < 0 ? i9 + 1
34
+ : i9 > 1 ? i9 - 1
35
+ : i9;
36
36
 
37
37
  return [h, s, l];
38
38
  }
@@ -23,13 +23,18 @@ export default function rgbToHsv(color: Rgb): Hsv {
23
23
  const i6 = ((v - i1) / 6 + i4) / i3;
24
24
  const i7 = ((v - i2) / 6 + i4) / i3;
25
25
  const i8 =
26
- i0 === v
27
- ? i7 - i6
28
- : i1 === v
29
- ? 0.33333333 + i5 - i7 // `1 / 3`
30
- : i2 === v
31
- ? 0.66666666 + i6 - i5 // `2 / 3`
32
- : 0;
26
+ i0 === v ? i7 - i6
27
+ : i1 === v ?
28
+ 0.33333333 + i5 - i7 // `1 / 3`
29
+ : i2 === v ?
30
+ 0.66666666 + i6 - i5 // `2 / 3`
31
+ : 0;
33
32
 
34
- return [i8 < 0 ? i8 + 1 : i8 > 1 ? i8 - 1 : i8, i3 / v, v];
33
+ return [
34
+ i8 < 0 ? i8 + 1
35
+ : i8 > 1 ? i8 - 1
36
+ : i8,
37
+ i3 / v,
38
+ v
39
+ ];
35
40
  }