@lakuna/color 1.0.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 (288) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/index.d.ts +57 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +46 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/names/bang.d.ts +9 -0
  8. package/dist/names/bang.d.ts.map +1 -0
  9. package/dist/names/bang.js +481 -0
  10. package/dist/names/bang.js.map +1 -0
  11. package/dist/names/cne.d.ts +9 -0
  12. package/dist/names/cne.d.ts.map +1 -0
  13. package/dist/names/cne.js +875 -0
  14. package/dist/names/cne.js.map +1 -0
  15. package/dist/names/crayola.d.ts +9 -0
  16. package/dist/names/crayola.d.ts.map +1 -0
  17. package/dist/names/crayola.js +130 -0
  18. package/dist/names/crayola.js.map +1 -0
  19. package/dist/names/getName.d.ts +20 -0
  20. package/dist/names/getName.d.ts.map +1 -0
  21. package/dist/names/getName.js +34 -0
  22. package/dist/names/getName.js.map +1 -0
  23. package/dist/names/hollasch.d.ts +9 -0
  24. package/dist/names/hollasch.d.ts.map +1 -0
  25. package/dist/names/hollasch.js +201 -0
  26. package/dist/names/hollasch.js.map +1 -0
  27. package/dist/names/nbs.d.ts +9 -0
  28. package/dist/names/nbs.d.ts.map +1 -0
  29. package/dist/names/nbs.js +277 -0
  30. package/dist/names/nbs.js.map +1 -0
  31. package/dist/names/ntc.d.ts +9 -0
  32. package/dist/names/ntc.d.ts.map +1 -0
  33. package/dist/names/ntc.js +1576 -0
  34. package/dist/names/ntc.js.map +1 -0
  35. package/dist/names/resene.d.ts +9 -0
  36. package/dist/names/resene.d.ts.map +1 -0
  37. package/dist/names/resene.js +1388 -0
  38. package/dist/names/resene.js.map +1 -0
  39. package/dist/names/x11.d.ts +9 -0
  40. package/dist/names/x11.d.ts.map +1 -0
  41. package/dist/names/x11.js +465 -0
  42. package/dist/names/x11.js.map +1 -0
  43. package/dist/names/xkcd.d.ts +9 -0
  44. package/dist/names/xkcd.d.ts.map +1 -0
  45. package/dist/names/xkcd.js +932 -0
  46. package/dist/names/xkcd.js.map +1 -0
  47. package/dist/types/Adobe.d.ts +15 -0
  48. package/dist/types/Adobe.d.ts.map +1 -0
  49. package/dist/types/Adobe.js +2 -0
  50. package/dist/types/Adobe.js.map +1 -0
  51. package/dist/types/Cmy.d.ts +15 -0
  52. package/dist/types/Cmy.d.ts.map +1 -0
  53. package/dist/types/Cmy.js +2 -0
  54. package/dist/types/Cmy.js.map +1 -0
  55. package/dist/types/Cmyk.d.ts +17 -0
  56. package/dist/types/Cmyk.d.ts.map +1 -0
  57. package/dist/types/Cmyk.js +2 -0
  58. package/dist/types/Cmyk.js.map +1 -0
  59. package/dist/types/Color.d.ts +6 -0
  60. package/dist/types/Color.d.ts.map +1 -0
  61. package/dist/types/Color.js +2 -0
  62. package/dist/types/Color.js.map +1 -0
  63. package/dist/types/Hsl.d.ts +15 -0
  64. package/dist/types/Hsl.d.ts.map +1 -0
  65. package/dist/types/Hsl.js +2 -0
  66. package/dist/types/Hsl.js.map +1 -0
  67. package/dist/types/Hsv.d.ts +15 -0
  68. package/dist/types/Hsv.d.ts.map +1 -0
  69. package/dist/types/Hsv.js +2 -0
  70. package/dist/types/Hsv.js.map +1 -0
  71. package/dist/types/Hunter.d.ts +15 -0
  72. package/dist/types/Hunter.d.ts.map +1 -0
  73. package/dist/types/Hunter.js +2 -0
  74. package/dist/types/Hunter.js.map +1 -0
  75. package/dist/types/Lab.d.ts +15 -0
  76. package/dist/types/Lab.d.ts.map +1 -0
  77. package/dist/types/Lab.js +2 -0
  78. package/dist/types/Lab.js.map +1 -0
  79. package/dist/types/Lch.d.ts +16 -0
  80. package/dist/types/Lch.d.ts.map +1 -0
  81. package/dist/types/Lch.js +2 -0
  82. package/dist/types/Lch.js.map +1 -0
  83. package/dist/types/Luv.d.ts +15 -0
  84. package/dist/types/Luv.d.ts.map +1 -0
  85. package/dist/types/Luv.js +2 -0
  86. package/dist/types/Luv.js.map +1 -0
  87. package/dist/types/Rgb.d.ts +15 -0
  88. package/dist/types/Rgb.d.ts.map +1 -0
  89. package/dist/types/Rgb.js +2 -0
  90. package/dist/types/Rgb.js.map +1 -0
  91. package/dist/types/Xyz.d.ts +15 -0
  92. package/dist/types/Xyz.d.ts.map +1 -0
  93. package/dist/types/Xyz.js +2 -0
  94. package/dist/types/Xyz.js.map +1 -0
  95. package/dist/types/Yxy.d.ts +15 -0
  96. package/dist/types/Yxy.d.ts.map +1 -0
  97. package/dist/types/Yxy.js +2 -0
  98. package/dist/types/Yxy.js.map +1 -0
  99. package/dist/utility/StandardIlluminant.d.ts +89 -0
  100. package/dist/utility/StandardIlluminant.d.ts.map +1 -0
  101. package/dist/utility/StandardIlluminant.js +90 -0
  102. package/dist/utility/StandardIlluminant.js.map +1 -0
  103. package/dist/utility/adobeToXyz.d.ts +10 -0
  104. package/dist/utility/adobeToXyz.d.ts.map +1 -0
  105. package/dist/utility/adobeToXyz.js +17 -0
  106. package/dist/utility/adobeToXyz.js.map +1 -0
  107. package/dist/utility/cmyToCmyk.d.ts +10 -0
  108. package/dist/utility/cmyToCmyk.d.ts.map +1 -0
  109. package/dist/utility/cmyToCmyk.js +19 -0
  110. package/dist/utility/cmyToCmyk.js.map +1 -0
  111. package/dist/utility/cmyToRgb.d.ts +10 -0
  112. package/dist/utility/cmyToRgb.d.ts.map +1 -0
  113. package/dist/utility/cmyToRgb.js +10 -0
  114. package/dist/utility/cmyToRgb.js.map +1 -0
  115. package/dist/utility/cmykToCmy.d.ts +10 -0
  116. package/dist/utility/cmykToCmy.d.ts.map +1 -0
  117. package/dist/utility/cmykToCmy.js +16 -0
  118. package/dist/utility/cmykToCmy.js.map +1 -0
  119. package/dist/utility/contrast.d.ts +12 -0
  120. package/dist/utility/contrast.d.ts.map +1 -0
  121. package/dist/utility/contrast.js +17 -0
  122. package/dist/utility/contrast.js.map +1 -0
  123. package/dist/utility/deltaC.d.ts +21 -0
  124. package/dist/utility/deltaC.d.ts.map +1 -0
  125. package/dist/utility/deltaC.js +4 -0
  126. package/dist/utility/deltaC.js.map +1 -0
  127. package/dist/utility/deltaCmc.d.ts +13 -0
  128. package/dist/utility/deltaCmc.d.ts.map +1 -0
  129. package/dist/utility/deltaCmc.js +46 -0
  130. package/dist/utility/deltaCmc.js.map +1 -0
  131. package/dist/utility/deltaE00.d.ts +13 -0
  132. package/dist/utility/deltaE00.d.ts.map +1 -0
  133. package/dist/utility/deltaE00.js +90 -0
  134. package/dist/utility/deltaE00.js.map +1 -0
  135. package/dist/utility/deltaE76.d.ts +21 -0
  136. package/dist/utility/deltaE76.d.ts.map +1 -0
  137. package/dist/utility/deltaE76.js +4 -0
  138. package/dist/utility/deltaE76.js.map +1 -0
  139. package/dist/utility/deltaE94.d.ts +13 -0
  140. package/dist/utility/deltaE94.d.ts.map +1 -0
  141. package/dist/utility/deltaE94.js +29 -0
  142. package/dist/utility/deltaE94.js.map +1 -0
  143. package/dist/utility/deltaH.d.ts +21 -0
  144. package/dist/utility/deltaH.d.ts.map +1 -0
  145. package/dist/utility/deltaH.js +14 -0
  146. package/dist/utility/deltaH.js.map +1 -0
  147. package/dist/utility/getReference.d.ts +9 -0
  148. package/dist/utility/getReference.d.ts.map +1 -0
  149. package/dist/utility/getReference.js +92 -0
  150. package/dist/utility/getReference.js.map +1 -0
  151. package/dist/utility/hexToRgb.d.ts +9 -0
  152. package/dist/utility/hexToRgb.d.ts.map +1 -0
  153. package/dist/utility/hexToRgb.js +10 -0
  154. package/dist/utility/hexToRgb.js.map +1 -0
  155. package/dist/utility/hslToRgb.d.ts +10 -0
  156. package/dist/utility/hslToRgb.d.ts.map +1 -0
  157. package/dist/utility/hslToRgb.js +46 -0
  158. package/dist/utility/hslToRgb.js.map +1 -0
  159. package/dist/utility/hsvToRgb.d.ts +10 -0
  160. package/dist/utility/hsvToRgb.d.ts.map +1 -0
  161. package/dist/utility/hsvToRgb.js +34 -0
  162. package/dist/utility/hsvToRgb.js.map +1 -0
  163. package/dist/utility/hunterToXyz.d.ts +11 -0
  164. package/dist/utility/hunterToXyz.d.ts.map +1 -0
  165. package/dist/utility/hunterToXyz.js +26 -0
  166. package/dist/utility/hunterToXyz.js.map +1 -0
  167. package/dist/utility/labToLch.d.ts +11 -0
  168. package/dist/utility/labToLch.d.ts.map +1 -0
  169. package/dist/utility/labToLch.js +19 -0
  170. package/dist/utility/labToLch.js.map +1 -0
  171. package/dist/utility/labToXyz.d.ts +11 -0
  172. package/dist/utility/labToXyz.d.ts.map +1 -0
  173. package/dist/utility/labToXyz.js +23 -0
  174. package/dist/utility/labToXyz.js.map +1 -0
  175. package/dist/utility/lchToLab.d.ts +11 -0
  176. package/dist/utility/lchToLab.d.ts.map +1 -0
  177. package/dist/utility/lchToLab.js +14 -0
  178. package/dist/utility/lchToLab.js.map +1 -0
  179. package/dist/utility/luvToXyz.d.ts +11 -0
  180. package/dist/utility/luvToXyz.d.ts.map +1 -0
  181. package/dist/utility/luvToXyz.js +28 -0
  182. package/dist/utility/luvToXyz.js.map +1 -0
  183. package/dist/utility/relativeLuminance.d.ts +10 -0
  184. package/dist/utility/relativeLuminance.d.ts.map +1 -0
  185. package/dist/utility/relativeLuminance.js +20 -0
  186. package/dist/utility/relativeLuminance.js.map +1 -0
  187. package/dist/utility/rgbToCmy.d.ts +10 -0
  188. package/dist/utility/rgbToCmy.d.ts.map +1 -0
  189. package/dist/utility/rgbToCmy.js +10 -0
  190. package/dist/utility/rgbToCmy.js.map +1 -0
  191. package/dist/utility/rgbToHsl.d.ts +10 -0
  192. package/dist/utility/rgbToHsl.d.ts.map +1 -0
  193. package/dist/utility/rgbToHsl.js +32 -0
  194. package/dist/utility/rgbToHsl.js.map +1 -0
  195. package/dist/utility/rgbToHsv.d.ts +10 -0
  196. package/dist/utility/rgbToHsv.d.ts.map +1 -0
  197. package/dist/utility/rgbToHsv.js +29 -0
  198. package/dist/utility/rgbToHsv.js.map +1 -0
  199. package/dist/utility/rgbToXyz.d.ts +10 -0
  200. package/dist/utility/rgbToXyz.d.ts.map +1 -0
  201. package/dist/utility/rgbToXyz.js +20 -0
  202. package/dist/utility/rgbToXyz.js.map +1 -0
  203. package/dist/utility/xyzToAdobe.d.ts +10 -0
  204. package/dist/utility/xyzToAdobe.d.ts.map +1 -0
  205. package/dist/utility/xyzToAdobe.js +17 -0
  206. package/dist/utility/xyzToAdobe.js.map +1 -0
  207. package/dist/utility/xyzToHunter.d.ts +11 -0
  208. package/dist/utility/xyzToHunter.d.ts.map +1 -0
  209. package/dist/utility/xyzToHunter.js +25 -0
  210. package/dist/utility/xyzToHunter.js.map +1 -0
  211. package/dist/utility/xyzToLab.d.ts +11 -0
  212. package/dist/utility/xyzToLab.d.ts.map +1 -0
  213. package/dist/utility/xyzToLab.js +21 -0
  214. package/dist/utility/xyzToLab.js.map +1 -0
  215. package/dist/utility/xyzToLuv.d.ts +11 -0
  216. package/dist/utility/xyzToLuv.d.ts.map +1 -0
  217. package/dist/utility/xyzToLuv.js +30 -0
  218. package/dist/utility/xyzToLuv.js.map +1 -0
  219. package/dist/utility/xyzToRgb.d.ts +10 -0
  220. package/dist/utility/xyzToRgb.d.ts.map +1 -0
  221. package/dist/utility/xyzToRgb.js +20 -0
  222. package/dist/utility/xyzToRgb.js.map +1 -0
  223. package/dist/utility/xyzToYxy.d.ts +10 -0
  224. package/dist/utility/xyzToYxy.d.ts.map +1 -0
  225. package/dist/utility/xyzToYxy.js +16 -0
  226. package/dist/utility/xyzToYxy.js.map +1 -0
  227. package/dist/utility/yxyToXyz.d.ts +10 -0
  228. package/dist/utility/yxyToXyz.d.ts.map +1 -0
  229. package/dist/utility/yxyToXyz.js +16 -0
  230. package/dist/utility/yxyToXyz.js.map +1 -0
  231. package/package.json +59 -0
  232. package/src/index.ts +61 -0
  233. package/src/names/bang.ts +483 -0
  234. package/src/names/cne.ts +877 -0
  235. package/src/names/crayola.ts +132 -0
  236. package/src/names/getName.ts +51 -0
  237. package/src/names/hollasch.ts +203 -0
  238. package/src/names/nbs.ts +279 -0
  239. package/src/names/ntc.ts +1578 -0
  240. package/src/names/resene.ts +1390 -0
  241. package/src/names/x11.ts +467 -0
  242. package/src/names/xkcd.ts +934 -0
  243. package/src/types/Adobe.ts +17 -0
  244. package/src/types/Cmy.ts +17 -0
  245. package/src/types/Cmyk.ts +20 -0
  246. package/src/types/Color.ts +5 -0
  247. package/src/types/Hsl.ts +17 -0
  248. package/src/types/Hsv.ts +17 -0
  249. package/src/types/Hunter.ts +17 -0
  250. package/src/types/Lab.ts +17 -0
  251. package/src/types/Lch.ts +18 -0
  252. package/src/types/Luv.ts +17 -0
  253. package/src/types/Rgb.ts +17 -0
  254. package/src/types/Xyz.ts +17 -0
  255. package/src/types/Yxy.ts +17 -0
  256. package/src/utility/StandardIlluminant.ts +128 -0
  257. package/src/utility/adobeToXyz.ts +20 -0
  258. package/src/utility/cmyToCmyk.ts +23 -0
  259. package/src/utility/cmyToRgb.ts +12 -0
  260. package/src/utility/cmykToCmy.ts +19 -0
  261. package/src/utility/contrast.ts +19 -0
  262. package/src/utility/deltaC.ts +26 -0
  263. package/src/utility/deltaCmc.ts +59 -0
  264. package/src/utility/deltaE00.ts +105 -0
  265. package/src/utility/deltaE76.ts +30 -0
  266. package/src/utility/deltaE94.ts +41 -0
  267. package/src/utility/deltaH.ts +39 -0
  268. package/src/utility/getReference.ts +95 -0
  269. package/src/utility/hexToRgb.ts +11 -0
  270. package/src/utility/hslToRgb.ts +53 -0
  271. package/src/utility/hsvToRgb.ts +44 -0
  272. package/src/utility/hunterToXyz.ts +33 -0
  273. package/src/utility/labToLch.ts +24 -0
  274. package/src/utility/labToXyz.ts +29 -0
  275. package/src/utility/lchToLab.ts +18 -0
  276. package/src/utility/luvToXyz.ts +35 -0
  277. package/src/utility/relativeLuminance.ts +25 -0
  278. package/src/utility/rgbToCmy.ts +12 -0
  279. package/src/utility/rgbToHsl.ts +38 -0
  280. package/src/utility/rgbToHsv.ts +35 -0
  281. package/src/utility/rgbToXyz.ts +23 -0
  282. package/src/utility/xyzToAdobe.ts +20 -0
  283. package/src/utility/xyzToHunter.ts +32 -0
  284. package/src/utility/xyzToLab.ts +27 -0
  285. package/src/utility/xyzToLuv.ts +38 -0
  286. package/src/utility/xyzToRgb.ts +23 -0
  287. package/src/utility/xyzToYxy.ts +19 -0
  288. package/src/utility/yxyToXyz.ts +19 -0
@@ -0,0 +1,30 @@
1
+ import type Lab from "../types/Lab.js";
2
+ import type Luv from "../types/Luv.js";
3
+
4
+ /**
5
+ * Calculates the ΔE* CIE (CIE 1976) between two CIELAB values. Based on the EasyRGB pseudocode.
6
+ * @param color0 - The first color.
7
+ * @param color1 - The second color.
8
+ * @returns The difference between the colors.
9
+ * @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
10
+ * @public
11
+ */
12
+ export default function deltaE76(color0: Lab, color1: Lab): number;
13
+
14
+ /**
15
+ * Calculates the ΔE* CIE (CIE 1976) between two CIELUV values. Based on the EasyRGB pseudocode.
16
+ * @param color0 - The first color.
17
+ * @param color1 - The second color.
18
+ * @returns The difference between the colors.
19
+ * @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
20
+ * @public
21
+ */
22
+ export default function deltaE76(color0: Luv, color1: Luv): number;
23
+
24
+ export default function deltaE76(color0: Lab | Luv, color1: Lab | Luv): number {
25
+ return Math.hypot(
26
+ color0[0] - color1[0],
27
+ color0[1] - color1[1],
28
+ color0[2] - color1[2]
29
+ );
30
+ }
@@ -0,0 +1,41 @@
1
+ import type Lab from "../types/Lab.js";
2
+ import type Lch from "../types/Lch.js";
3
+
4
+ /**
5
+ * Calculates the ΔE* 1994 between two CIELAB values. Based on the EasyRGB pseudocode.
6
+ * @param color0 - The first color.
7
+ * @param color1 - The second color.
8
+ * @param weight - The CIELCH weights. Defaults to all ones.
9
+ * @returns The difference between the colors.
10
+ * @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
11
+ * @public
12
+ */
13
+ export default function deltaE94(
14
+ color0: Lab,
15
+ color1: Lab,
16
+ weight: Lch = [1, 1, 1]
17
+ ): number {
18
+ // eslint-disable-next-line prefer-destructuring
19
+ const l0 = color0[0];
20
+ // eslint-disable-next-line prefer-destructuring
21
+ const a0 = color0[1];
22
+ // eslint-disable-next-line prefer-destructuring
23
+ const b0 = color0[2];
24
+ // eslint-disable-next-line prefer-destructuring
25
+ const l1 = color1[0];
26
+ // eslint-disable-next-line prefer-destructuring
27
+ const a1 = color1[1];
28
+ // eslint-disable-next-line prefer-destructuring
29
+ const b1 = color1[2];
30
+
31
+ const i0 = Math.hypot(a0, b0);
32
+ const i1 = l1 - l0;
33
+ const i2 = Math.hypot(a1, b1) - i0;
34
+ const i3 = Math.hypot(l0 - l1, a0 - a1, b0 - b1) ** 2 - i1 ** 2 - i2 ** 2;
35
+
36
+ return Math.hypot(
37
+ i1 / weight[0],
38
+ i2 / (weight[1] * (1 + 0.045 * i0)),
39
+ (i3 > 0 ? Math.sqrt(i3) : 0) / (weight[2] * (1 + 0.015 * i0))
40
+ );
41
+ }
@@ -0,0 +1,39 @@
1
+ import type Lab from "../types/Lab.js";
2
+ import type Luv from "../types/Luv.js";
3
+
4
+ /**
5
+ * Calculates the ΔH* between two CIELAB values. Based on the EasyRGB pseudocode.
6
+ * @param color0 - The first color.
7
+ * @param color1 - The second color.
8
+ * @returns The difference between the colors.
9
+ * @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
10
+ * @public
11
+ */
12
+ export default function deltaH(color0: Lab, color1: Lab): number;
13
+
14
+ /**
15
+ * Calculates the ΔH* between two CIELUV values. Based on the EasyRGB pseudocode.
16
+ * @param color0 - The first color.
17
+ * @param color1 - The second color.
18
+ * @returns The difference between the colors.
19
+ * @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
20
+ * @public
21
+ */
22
+ export default function deltaH(color0: Luv, color1: Luv): number;
23
+
24
+ export default function deltaH(color0: Lab | Luv, color1: Lab | Luv): number {
25
+ // eslint-disable-next-line prefer-destructuring
26
+ const a0 = color0[1];
27
+ // eslint-disable-next-line prefer-destructuring
28
+ const b0 = color0[2];
29
+ // eslint-disable-next-line prefer-destructuring
30
+ const a1 = color1[1];
31
+ // eslint-disable-next-line prefer-destructuring
32
+ const b1 = color1[2];
33
+
34
+ return Math.sqrt(
35
+ (a1 - a0) ** 2 +
36
+ (b1 - b0) ** 2 -
37
+ (Math.hypot(a1, b1) - Math.hypot(a0, b0)) ** 2
38
+ );
39
+ }
@@ -0,0 +1,95 @@
1
+ import StandardIlluminant from "./StandardIlluminant.js";
2
+ import type Xyz from "../types/Xyz.js";
3
+
4
+ /**
5
+ * Get an XYZ (tristimulus) reference value of a perfect reflecting diffuser, scaled such that the white point has a Y value of 100.
6
+ * @param standardIlluminant - The standard illuminant and observer pair.
7
+ * @returns An XYZ (tristimulus) reference value of a perfect reflecting diffuser.
8
+ */
9
+ export default function getReference(
10
+ standardIlluminant: StandardIlluminant
11
+ ): Xyz {
12
+ switch (standardIlluminant) {
13
+ case StandardIlluminant.A_10:
14
+ return [111.144, 100, 35.2];
15
+ case StandardIlluminant.A_2:
16
+ return [109.85, 100, 35.585];
17
+ case StandardIlluminant.B_10:
18
+ return [99.178, 100, 84.3493];
19
+ case StandardIlluminant.B_2:
20
+ return [99.0927, 100, 85.313];
21
+ case StandardIlluminant.C_10:
22
+ return [97.285, 100, 116.145];
23
+ case StandardIlluminant.C_2:
24
+ return [98.074, 100, 118.232];
25
+ case StandardIlluminant.D50_10:
26
+ return [96.72, 100, 81.427];
27
+ case StandardIlluminant.D50_2:
28
+ return [96.422, 100, 82.521];
29
+ case StandardIlluminant.D55_10:
30
+ return [95.799, 100, 90.926];
31
+ case StandardIlluminant.D55_2:
32
+ return [95.682, 100, 92.149];
33
+ case StandardIlluminant.D65_10:
34
+ return [94.811, 100, 107.304];
35
+ case StandardIlluminant.D65_2:
36
+ return [95.047, 100, 108.883];
37
+ case StandardIlluminant.D75_10:
38
+ return [94.416, 100, 120.641];
39
+ case StandardIlluminant.D75_2:
40
+ return [94.972, 100, 122.638];
41
+ case StandardIlluminant.E_10:
42
+ case StandardIlluminant.E_2:
43
+ return [100, 100, 100];
44
+ case StandardIlluminant.F1_10:
45
+ return [94.791, 100, 103.191];
46
+ case StandardIlluminant.F1_2:
47
+ return [92.834, 100, 103.665];
48
+ case StandardIlluminant.F2_10:
49
+ return [103.28, 100, 69.026];
50
+ case StandardIlluminant.F2_2:
51
+ return [99.187, 100, 67.395];
52
+ case StandardIlluminant.F3_10:
53
+ return [108.968, 100, 51.965];
54
+ case StandardIlluminant.F3_2:
55
+ return [103.754, 100, 49.861];
56
+ case StandardIlluminant.F4_10:
57
+ return [114.961, 100, 40.963];
58
+ case StandardIlluminant.F4_2:
59
+ return [109.147, 100, 38.813];
60
+ case StandardIlluminant.F5_10:
61
+ return [93.369, 100, 98.636];
62
+ case StandardIlluminant.F5_2:
63
+ return [90.872, 100, 98.723];
64
+ case StandardIlluminant.F6_10:
65
+ return [102.148, 100, 62.074];
66
+ case StandardIlluminant.F6_2:
67
+ return [97.309, 100, 60.191];
68
+ case StandardIlluminant.F7_10:
69
+ return [95.792, 100, 107.687];
70
+ case StandardIlluminant.F7_2:
71
+ return [95.044, 100, 108.755];
72
+ case StandardIlluminant.F8_10:
73
+ return [97.115, 100, 81.135];
74
+ case StandardIlluminant.F8_2:
75
+ return [96.413, 100, 82.333];
76
+ case StandardIlluminant.F9_10:
77
+ return [102.116, 100, 67.826];
78
+ case StandardIlluminant.F9_2:
79
+ return [100.365, 100, 67.868];
80
+ case StandardIlluminant.F10_10:
81
+ return [99.001, 100, 83.134];
82
+ case StandardIlluminant.F10_2:
83
+ return [96.174, 100, 81.712];
84
+ case StandardIlluminant.F11_10:
85
+ return [103.866, 100, 65.627];
86
+ case StandardIlluminant.F11_2:
87
+ return [100.966, 100, 64.37];
88
+ case StandardIlluminant.F12_10:
89
+ return [111.428, 100, 40.353];
90
+ case StandardIlluminant.F12_2:
91
+ return [108.046, 100, 39.228];
92
+ default:
93
+ throw new RangeError("Unknown enumeration value.");
94
+ }
95
+ }
@@ -0,0 +1,11 @@
1
+ import type Rgb from "../types/Rgb.js";
2
+
3
+ /**
4
+ * Split a hexadecimal value into sRGB values.
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.
7
+ * @public
8
+ */
9
+ export default function hexToRgb(hex: number): Rgb {
10
+ return [(hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff];
11
+ }
@@ -0,0 +1,53 @@
1
+ import type Hsl from "../types/Hsl.js";
2
+ import type Rgb from "../types/Rgb.js";
3
+
4
+ /**
5
+ * Converts the given hue data to RGB data.
6
+ * @param v0 - The first piecewise value.
7
+ * @param v1 - The second piecewise value.
8
+ * @param h - The third piecewise value.
9
+ * @returns The piecewise result.
10
+ * @internal
11
+ */
12
+ const hueToRgb = (v0: number, v1: number, h: number): number => {
13
+ const i0 = h < 0 ? h + 1 : h > 1 ? h - 1 : h;
14
+ const i1 = 6 * i0;
15
+ 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;
23
+ };
24
+
25
+ /**
26
+ * Convert the given HSL color to an sRGB color. Based on the EasyRGB pseudo-code.
27
+ * @param color - The HSL color.
28
+ * @returns An sRGB color.
29
+ * @public
30
+ */
31
+ export default function hslToRgb(color: Hsl): Rgb {
32
+ // eslint-disable-next-line prefer-destructuring
33
+ const h = color[0];
34
+ // eslint-disable-next-line prefer-destructuring
35
+ const s = color[1];
36
+ // eslint-disable-next-line prefer-destructuring
37
+ const l = color[2];
38
+
39
+ const i0 = l * 0xff;
40
+
41
+ if (s === 0) {
42
+ return [i0, i0, i0];
43
+ }
44
+
45
+ const i1 = l < 0.5 ? l * (1 + s) : l + s - s * l;
46
+ const i2 = 2 * l - i1;
47
+
48
+ return [
49
+ 0xff * hueToRgb(i2, i1, h + 1 / 3),
50
+ 0xff * hueToRgb(i2, i1, h),
51
+ 0xff * hueToRgb(i2, i1, h - 1 / 3)
52
+ ];
53
+ }
@@ -0,0 +1,44 @@
1
+ import type Hsv from "../types/Hsv.js";
2
+ import type Rgb from "../types/Rgb.js";
3
+
4
+ /**
5
+ * Convert the given HSV color to an sRGB color. Based on the EasyRGB pseudo-code.
6
+ * @param color - The HSV color.
7
+ * @returns An sRGB color.
8
+ * @public
9
+ */
10
+ export default function hsvToRgb(color: Hsv): Rgb {
11
+ // eslint-disable-next-line prefer-destructuring
12
+ const s = color[1];
13
+ // eslint-disable-next-line prefer-destructuring
14
+ const v = color[2];
15
+
16
+ const i0 = v * 0xff;
17
+
18
+ if (s === 0) {
19
+ return [i0, i0, i0];
20
+ }
21
+
22
+ const i1 = color[0] * 6;
23
+ const i2 = i1 === 6 ? 0 : i1;
24
+ const i3 = Math.floor(i2);
25
+ const i4 = i2 - i3;
26
+ const i5 = v * (1 - s * (1 - i4)) * 0xff;
27
+ const i6 = v * (1 - s) * 0xff;
28
+
29
+ if (i3 === 0) {
30
+ return [i0, i5, i6];
31
+ }
32
+
33
+ if (i3 === 2) {
34
+ return [i6, i0, i5];
35
+ }
36
+
37
+ if (i3 === 4) {
38
+ return [i5, i6, i0];
39
+ }
40
+
41
+ const i7 = v * (1 - s * i4) * 0xff;
42
+
43
+ return i3 === 1 ? [i7, i0, i6] : i3 === 3 ? [i6, i7, i0] : [i0, i6, i7];
44
+ }
@@ -0,0 +1,33 @@
1
+ import type Hunter from "../types/Hunter.js";
2
+ import StandardIlluminant from "./StandardIlluminant.js";
3
+ import type Xyz from "../types/Xyz.js";
4
+ import getReference from "./getReference.js";
5
+
6
+ /**
7
+ * Convert the given Hunter Lab color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
8
+ * @param color - The Hunter Lab color.
9
+ * @param ref - A standard illuminant that represents the white point.
10
+ * @returns A CIEXYZ color.
11
+ * @public
12
+ */
13
+ export default function hunterToXyz(
14
+ color: Hunter,
15
+ ref: Xyz = getReference(StandardIlluminant.D65_2)
16
+ ): Xyz {
17
+ // eslint-disable-next-line prefer-destructuring
18
+ const rx = ref[0];
19
+ // eslint-disable-next-line prefer-destructuring
20
+ const ry = ref[1];
21
+ // eslint-disable-next-line prefer-destructuring
22
+ const rz = ref[2];
23
+
24
+ const y = (color[0] / ry) ** 2 * 100;
25
+ const i0 = y / ry;
26
+ const i1 = Math.sqrt(i0);
27
+
28
+ return [
29
+ ((color[1] / (0.88365987 * (ry + rx))) * i1 + i0) * rx, // `175 / 198.04`
30
+ y,
31
+ -((color[2] / (0.32093898 * (ry + rz))) * i1 - i0) * rz // `70 / 218.11`
32
+ ];
33
+ }
@@ -0,0 +1,24 @@
1
+ import type Lab from "../types/Lab.js";
2
+ import type Lch from "../types/Lch.js";
3
+ import type Luv from "../types/Luv.js";
4
+
5
+ /**
6
+ * Convert the given CIELAB or CIELUV color to a CIELCh(ab) or CIELCh(uv) (respectively) color. Based on the EasyRGB pseudo-code.
7
+ * @param color - The CIELAB or CIELUV color.
8
+ * @returns A CIELCh color.
9
+ * @public
10
+ */
11
+ export default function labToLch(color: Lab | Luv): Lch {
12
+ // eslint-disable-next-line prefer-destructuring
13
+ const a = color[1];
14
+ // eslint-disable-next-line prefer-destructuring
15
+ const b = color[2];
16
+
17
+ const i0 = Math.atan2(b, a);
18
+
19
+ return [
20
+ color[0],
21
+ Math.hypot(a, b),
22
+ i0 > 0 ? i0 * 57.29577951 : 360 - Math.abs(i0) * 57.29577951 // `180 / Math.PI`
23
+ ];
24
+ }
@@ -0,0 +1,29 @@
1
+ import type Lab from "../types/Lab.js";
2
+ import StandardIlluminant from "./StandardIlluminant.js";
3
+ import type Xyz from "../types/Xyz.js";
4
+ import getReference from "./getReference.js";
5
+
6
+ /**
7
+ * Convert the given CIELAB color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
8
+ * @param color - The CIELAB color.
9
+ * @param ref - A standard illuminant that represents the white point.
10
+ * @returns A CIEXYZ color.
11
+ * @public
12
+ */
13
+ export default function labToXyz(
14
+ color: Lab,
15
+ ref: Xyz = getReference(StandardIlluminant.D65_2)
16
+ ): Xyz {
17
+ const i0 = (color[0] + 16) / 116;
18
+ const i1 = i0 ** 3;
19
+ const i2 = color[1] / 500 + i0;
20
+ const i3 = i2 ** 3;
21
+ const i4 = i0 - color[2] / 200;
22
+ const i5 = i4 ** 3;
23
+
24
+ return [
25
+ (i3 > 0.008856 ? i3 : (i2 - 0.13793103) / 7.787) * ref[0], // `16 / 116`
26
+ (i1 > 0.008856 ? i1 : (i0 - 0.13793103) / 7.787) * ref[1], // `16 / 116`
27
+ (i5 > 0.008856 ? i5 : (i4 - 0.13793103) / 7.787) * ref[2] // `16 / 116`
28
+ ];
29
+ }
@@ -0,0 +1,18 @@
1
+ import type Lab from "../types/Lab.js";
2
+ import type Lch from "../types/Lch.js";
3
+ import type Luv from "../types/Luv.js";
4
+
5
+ /**
6
+ * Convert the given CIELCh(ab) or CIELCh(uv) color to a CIELAB or CIELUV (respectively) color. Based on the EasyRGB pseudo-code.
7
+ * @param color - The CIELCh color.
8
+ * @returns A CIELAB or CIELUV color.
9
+ * @public
10
+ */
11
+ export default function lchToLab(color: Lch): Lab | Luv {
12
+ // eslint-disable-next-line prefer-destructuring
13
+ const c = color[1];
14
+ // eslint-disable-next-line prefer-destructuring
15
+ const h = color[2];
16
+
17
+ return [color[0], Math.cos(h * 0.01745329) * c, Math.sin(h * 0.01745329) * c]; // `Math.PI / 180`
18
+ }
@@ -0,0 +1,35 @@
1
+ import type Luv from "../types/Luv.js";
2
+ import StandardIlluminant from "./StandardIlluminant.js";
3
+ import type Xyz from "../types/Xyz.js";
4
+ import getReference from "./getReference.js";
5
+
6
+ /**
7
+ * Convert the given CIELUV color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
8
+ * @param color - The CIELUV color.
9
+ * @param ref - A standard illuminant that represents the white point.
10
+ * @returns A CIEXYZ color.
11
+ * @public
12
+ */
13
+ export default function luvToXyz(
14
+ color: Luv,
15
+ ref: Xyz = getReference(StandardIlluminant.D65_2)
16
+ ): Xyz {
17
+ // eslint-disable-next-line prefer-destructuring
18
+ const l = color[0];
19
+ // eslint-disable-next-line prefer-destructuring
20
+ const rx = ref[0];
21
+ // eslint-disable-next-line prefer-destructuring
22
+ const ry = ref[1];
23
+
24
+ const i0 = (l + 16) / 116;
25
+ const i1 = i0 ** 3;
26
+ const i2 = 13 * l;
27
+ const i3 = rx + 15 * ry + 3 * ref[2];
28
+ const i4 = color[1] / i2 + (4 * rx) / i3;
29
+ const i5 = color[2] / i2 + (9 * ry) / i3;
30
+ const y = (i1 > 0.008856 ? i1 : (i0 - 0.13793103) / 7.787) * 100; // `16 / 166`
31
+ const i6 = 9 * y;
32
+ const x = -(i6 * i4) / ((i4 - 4) * i5 - i4 * i5);
33
+
34
+ return [x, y, (i6 - 15 * i5 * y - i5 * x) / (3 * i5)];
35
+ }
@@ -0,0 +1,25 @@
1
+ import type Rgb from "../types/Rgb.js";
2
+
3
+ /**
4
+ * The piecewise function that is used internally for calculating relative luminance.
5
+ * @param a - The value in a channel of a color.
6
+ * @returns The piecewise value.
7
+ * @internal
8
+ */
9
+ const piecewise = (a: number) =>
10
+ a > 0.04045 ? ((a + 0.055) / 1.055) ** 2.4 : a / 12.92;
11
+
12
+ /**
13
+ * Calculate the relative luminance of an sRGB color.
14
+ * @param color - The sRGB color.
15
+ * @returns The relative luminance of the sRGB color.
16
+ * @see {@link https://www.w3.org/WAI/GL/wiki/Relative_luminance | Relative luminance}
17
+ * @public
18
+ */
19
+ export default function relativeLuminance(color: Rgb): number {
20
+ return (
21
+ 0.2126 * piecewise(color[0] / 0xff) +
22
+ 0.7152 * piecewise(color[1] / 0xff) +
23
+ 0.0722 * piecewise(color[2] / 0xff)
24
+ );
25
+ }
@@ -0,0 +1,12 @@
1
+ import type Cmy from "../types/Cmy.js";
2
+ import type Rgb from "../types/Rgb.js";
3
+
4
+ /**
5
+ * Convert the given sRGB color to a CMY color. Based on the EasyRGB pseudo-code.
6
+ * @param color - The sRGB color.
7
+ * @returns A CMY color.
8
+ * @public
9
+ */
10
+ export default function rgbToCmy(color: Rgb): Cmy {
11
+ return [1 - color[0] / 0xff, 1 - color[1] / 0xff, 1 - color[2] / 0xff];
12
+ }
@@ -0,0 +1,38 @@
1
+ import type Hsl from "../types/Hsl.js";
2
+ import type Rgb from "../types/Rgb.js";
3
+
4
+ /**
5
+ * Convert the given sRGB color to an HSL color. Based on the EasyRGB pseudo-code.
6
+ * @param color - The sRGB color.
7
+ * @returns An HSL color.
8
+ * @public
9
+ */
10
+ export default function rgbToHsl(color: Rgb): Hsl {
11
+ const i0 = color[0] / 0xff;
12
+ const i1 = color[1] / 0xff;
13
+ const i2 = color[2] / 0xff;
14
+ const i3 = Math.min(i0, i1, i2);
15
+ const i4 = Math.max(i0, i1, i2);
16
+ const l = (i4 + i3) / 2;
17
+ const i5 = i4 - i3;
18
+
19
+ if (i5 === 0) {
20
+ return [0, 0, l];
21
+ }
22
+
23
+ const s = l < 0.5 ? i5 / (i4 + i3) : i5 / (2 - i4 - i3);
24
+ const i6 = ((i4 - i0) / 6 + i5 / 2) / i5;
25
+ const i7 = ((i4 - i1) / 6 + i5 / 2) / i5;
26
+ const i8 = ((i4 - i2) / 6 + i5 / 2) / i5;
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;
36
+
37
+ return [h, s, l];
38
+ }
@@ -0,0 +1,35 @@
1
+ import type Hsv from "../types/Hsv.js";
2
+ import type Rgb from "../types/Rgb.js";
3
+
4
+ /**
5
+ * Convert the given sRGB color to an HSV color. Based on the EasyRGB pseudo-code.
6
+ * @param color - The sRGB color.
7
+ * @returns An HSV color.
8
+ * @public
9
+ */
10
+ export default function rgbToHsv(color: Rgb): Hsv {
11
+ const i0 = color[0] / 0xff;
12
+ const i1 = color[1] / 0xff;
13
+ const i2 = color[2] / 0xff;
14
+ const v = Math.max(i0, i1, i2);
15
+ const i3 = v - Math.min(i0, i1, i2);
16
+
17
+ if (i3 === 0) {
18
+ return [0, 0, v];
19
+ }
20
+
21
+ const i4 = i3 / 2;
22
+ const i5 = ((v - i0) / 6 + i4) / i3;
23
+ const i6 = ((v - i1) / 6 + i4) / i3;
24
+ const i7 = ((v - i2) / 6 + i4) / i3;
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;
33
+
34
+ return [i8 < 0 ? i8 + 1 : i8 > 1 ? i8 - 1 : i8, i3 / v, v];
35
+ }
@@ -0,0 +1,23 @@
1
+ import type Rgb from "../types/Rgb.js";
2
+ import type Xyz from "../types/Xyz.js";
3
+
4
+ /**
5
+ * Convert the given sRGB color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
6
+ * @param color - The sRGB color.
7
+ * @returns A CIEXYZ color.
8
+ * @public
9
+ */
10
+ export default function rgbToXyz(color: Rgb): Xyz {
11
+ const i0 = color[0] / 0xff;
12
+ const i1 = color[1] / 0xff;
13
+ const i2 = color[2] / 0xff;
14
+ const i3 = (i0 > 0.04045 ? ((i0 + 0.055) / 1.055) ** 2.4 : i0 / 12.92) * 100;
15
+ const i4 = (i1 > 0.04045 ? ((i1 + 0.055) / 1.055) ** 2.4 : i1 / 12.92) * 100;
16
+ const i5 = (i2 > 0.04045 ? ((i2 + 0.055) / 1.055) ** 2.4 : i2 / 12.92) * 100;
17
+
18
+ return [
19
+ i3 * 0.4124 + i4 * 0.3576 + i5 * 0.1805,
20
+ i3 * 0.2126 + i4 * 0.7152 + i5 * 0.0722,
21
+ i3 * 0.0193 + i4 * 0.1192 + i5 * 0.9505
22
+ ];
23
+ }
@@ -0,0 +1,20 @@
1
+ import type Adobe from "../types/Adobe.js";
2
+ import type Xyz from "../types/Xyz.js";
3
+
4
+ /**
5
+ * Convert the given CIEXYZ D65/2° standard illuminant color to an Adobe RGB color. Based on the EasyRGB pseudo-code.
6
+ * @param color - The CIEXYZ color.
7
+ * @returns An Adobe RGB color.
8
+ * @public
9
+ */
10
+ export default function xyzToAdobe(color: Xyz): Adobe {
11
+ const i0 = color[0] / 100;
12
+ const i1 = color[1] / 100;
13
+ const i2 = color[2] / 100;
14
+
15
+ return [
16
+ (i0 * 2.04137 + i1 * -0.56495 + i2 * -0.34469) ** 0.45470693 * 0xff, // `1 / 2.19921875`
17
+ (i0 * -0.96927 + i1 * 1.87601 + i2 * 0.04156) ** 0.45470693 * 0xff, // `1 / 2.19921875`
18
+ (i0 * 0.01345 + i1 * -0.11839 + i2 * 1.01541) ** 0.45470693 * 0xff // `1 / 2.19921875`
19
+ ];
20
+ }
@@ -0,0 +1,32 @@
1
+ import type Hunter from "../types/Hunter.js";
2
+ import StandardIlluminant from "./StandardIlluminant.js";
3
+ import type Xyz from "../types/Xyz.js";
4
+ import getReference from "./getReference.js";
5
+
6
+ /**
7
+ * Convert the given CIEXYZ color to a Hunter Lab color. Based on the EasyRGB pseudo-code.
8
+ * @param color - The CIEXYZ color.
9
+ * @param ref - A standard illuminant that represents the white point.
10
+ * @returns A Hunter Lab color.
11
+ * @public
12
+ */
13
+ export default function xyzToHunter(
14
+ color: Xyz,
15
+ ref: Xyz = getReference(StandardIlluminant.D65_2)
16
+ ): Hunter {
17
+ // eslint-disable-next-line prefer-destructuring
18
+ const rx = ref[0];
19
+ // eslint-disable-next-line prefer-destructuring
20
+ const ry = ref[1];
21
+ // eslint-disable-next-line prefer-destructuring
22
+ const rz = ref[2];
23
+
24
+ const i2 = color[1] / ry;
25
+ const i3 = Math.sqrt(i2);
26
+
27
+ return [
28
+ 100 * i3,
29
+ 0.88365987 * (ry + rx) * ((color[0] / rx - i2) / i3), // `175 / 198.04`
30
+ 0.32093898 * (ry + rz) * ((i2 - color[2] / rz) / i3) // `70 / 218.11`
31
+ ];
32
+ }