@lakuna/color 1.1.2 → 1.2.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 (379) hide show
  1. package/LICENSE +1 -1
  2. package/dist/{utility → convert}/adobeToXyz.d.ts +1 -1
  3. package/dist/convert/adobeToXyz.d.ts.map +1 -0
  4. package/dist/{utility → convert}/adobeToXyz.js +5 -3
  5. package/dist/convert/adobeToXyz.js.map +1 -0
  6. package/dist/{utility → convert}/cmyToCmyk.d.ts +1 -1
  7. package/dist/convert/cmyToCmyk.d.ts.map +1 -0
  8. package/dist/{utility → convert}/cmyToCmyk.js +0 -3
  9. package/dist/convert/cmyToCmyk.js.map +1 -0
  10. package/dist/{utility → convert}/cmyToRgb.d.ts +1 -1
  11. package/dist/convert/cmyToRgb.d.ts.map +1 -0
  12. package/dist/convert/cmyToRgb.js.map +1 -0
  13. package/dist/{utility → convert}/cmykToCmy.d.ts +1 -1
  14. package/dist/convert/cmykToCmy.d.ts.map +1 -0
  15. package/dist/{utility → convert}/cmykToCmy.js +0 -1
  16. package/dist/convert/cmykToCmy.js.map +1 -0
  17. package/dist/{utility → convert}/hexToRgb.d.ts +1 -1
  18. package/dist/convert/hexToRgb.d.ts.map +1 -0
  19. package/dist/{utility → convert}/hexToRgb.js.map +1 -1
  20. package/dist/{utility → convert}/hslToRgb.d.ts +1 -1
  21. package/dist/convert/hslToRgb.d.ts.map +1 -0
  22. package/dist/{utility → convert}/hslToRgb.js +5 -6
  23. package/dist/convert/hslToRgb.js.map +1 -0
  24. package/dist/{utility → convert}/hsvToRgb.d.ts +1 -1
  25. package/dist/convert/hsvToRgb.d.ts.map +1 -0
  26. package/dist/{utility → convert}/hsvToRgb.js +0 -2
  27. package/dist/convert/hsvToRgb.js.map +1 -0
  28. package/dist/{utility → convert}/hunterToXyz.d.ts +1 -1
  29. package/dist/convert/hunterToXyz.d.ts.map +1 -0
  30. package/dist/{utility → convert}/hunterToXyz.js +6 -7
  31. package/dist/convert/hunterToXyz.js.map +1 -0
  32. package/dist/convert/labToLch.d.ts +19 -0
  33. package/dist/convert/labToLch.d.ts.map +1 -0
  34. package/dist/convert/labToLch.js +12 -0
  35. package/dist/convert/labToLch.js.map +1 -0
  36. package/dist/{utility → convert}/labToXyz.d.ts +1 -1
  37. package/dist/convert/labToXyz.d.ts.map +1 -0
  38. package/dist/{utility → convert}/labToXyz.js +8 -5
  39. package/dist/convert/labToXyz.js.map +1 -0
  40. package/dist/convert/lchToLab.d.ts +19 -0
  41. package/dist/convert/lchToLab.d.ts.map +1 -0
  42. package/dist/convert/lchToLab.js +7 -0
  43. package/dist/convert/lchToLab.js.map +1 -0
  44. package/dist/{utility → convert}/luvToXyz.d.ts +1 -1
  45. package/dist/convert/luvToXyz.d.ts.map +1 -0
  46. package/dist/{utility → convert}/luvToXyz.js +4 -6
  47. package/dist/convert/luvToXyz.js.map +1 -0
  48. package/dist/{utility → convert}/rgbToCmy.d.ts +1 -1
  49. package/dist/convert/rgbToCmy.d.ts.map +1 -0
  50. package/dist/convert/rgbToCmy.js.map +1 -0
  51. package/dist/{utility → convert}/rgbToHex.d.ts +1 -1
  52. package/dist/{utility → convert}/rgbToHex.d.ts.map +1 -1
  53. package/dist/{utility → convert}/rgbToHex.js +3 -1
  54. package/dist/convert/rgbToHex.js.map +1 -0
  55. package/dist/convert/rgbToHsi.d.ts +10 -0
  56. package/dist/convert/rgbToHsi.d.ts.map +1 -0
  57. package/dist/convert/rgbToHsi.js +36 -0
  58. package/dist/convert/rgbToHsi.js.map +1 -0
  59. package/dist/{utility → convert}/rgbToHsl.d.ts +1 -1
  60. package/dist/convert/rgbToHsl.d.ts.map +1 -0
  61. package/dist/convert/rgbToHsl.js +37 -0
  62. package/dist/convert/rgbToHsl.js.map +1 -0
  63. package/dist/{utility → convert}/rgbToHsv.d.ts +1 -1
  64. package/dist/convert/rgbToHsv.d.ts.map +1 -0
  65. package/dist/{utility → convert}/rgbToHsv.js +11 -11
  66. package/dist/convert/rgbToHsv.js.map +1 -0
  67. package/dist/{utility → convert}/rgbToXyz.d.ts +1 -1
  68. package/dist/convert/rgbToXyz.d.ts.map +1 -0
  69. package/dist/{utility → convert}/rgbToXyz.js +9 -3
  70. package/dist/convert/rgbToXyz.js.map +1 -0
  71. package/dist/{utility → convert}/xyzToAdobe.d.ts +1 -1
  72. package/dist/convert/xyzToAdobe.d.ts.map +1 -0
  73. package/dist/{utility → convert}/xyzToAdobe.js +5 -3
  74. package/dist/convert/xyzToAdobe.js.map +1 -0
  75. package/dist/{utility → convert}/xyzToHunter.d.ts +2 -2
  76. package/dist/convert/xyzToHunter.d.ts.map +1 -0
  77. package/dist/{utility → convert}/xyzToHunter.js +7 -8
  78. package/dist/convert/xyzToHunter.js.map +1 -0
  79. package/dist/{utility → convert}/xyzToLab.d.ts +1 -1
  80. package/dist/convert/xyzToLab.d.ts.map +1 -0
  81. package/dist/{utility → convert}/xyzToLab.js +9 -5
  82. package/dist/convert/xyzToLab.js.map +1 -0
  83. package/dist/{utility → convert}/xyzToLuv.d.ts +1 -1
  84. package/dist/convert/xyzToLuv.d.ts.map +1 -0
  85. package/dist/{utility → convert}/xyzToLuv.js +5 -7
  86. package/dist/convert/xyzToLuv.js.map +1 -0
  87. package/dist/{utility → convert}/xyzToRgb.d.ts +1 -1
  88. package/dist/convert/xyzToRgb.d.ts.map +1 -0
  89. package/dist/{utility → convert}/xyzToRgb.js +8 -3
  90. package/dist/convert/xyzToRgb.js.map +1 -0
  91. package/dist/{utility → convert}/xyzToYxy.d.ts +1 -1
  92. package/dist/convert/xyzToYxy.d.ts.map +1 -0
  93. package/dist/{utility → convert}/xyzToYxy.js +0 -3
  94. package/dist/convert/xyzToYxy.js.map +1 -0
  95. package/dist/{utility → convert}/yxyToXyz.d.ts +1 -1
  96. package/dist/convert/yxyToXyz.d.ts.map +1 -0
  97. package/dist/{utility → convert}/yxyToXyz.js +0 -3
  98. package/dist/convert/yxyToXyz.js.map +1 -0
  99. package/dist/{utility → delta}/deltaC.d.ts +2 -2
  100. package/dist/delta/deltaC.d.ts.map +1 -0
  101. package/dist/{utility → delta}/deltaC.js.map +1 -1
  102. package/dist/{utility → delta}/deltaCmc.d.ts +2 -2
  103. package/dist/delta/deltaCmc.d.ts.map +1 -0
  104. package/dist/{utility → delta}/deltaCmc.js +5 -8
  105. package/dist/delta/deltaCmc.js.map +1 -0
  106. package/dist/{utility → delta}/deltaE00.d.ts +2 -2
  107. package/dist/delta/deltaE00.d.ts.map +1 -0
  108. package/dist/{utility → delta}/deltaE00.js +13 -17
  109. package/dist/delta/deltaE00.js.map +1 -0
  110. package/dist/{utility → delta}/deltaE76.d.ts +2 -2
  111. package/dist/delta/deltaE76.d.ts.map +1 -0
  112. package/dist/{utility → delta}/deltaE76.js.map +1 -1
  113. package/dist/{utility → delta}/deltaE94.d.ts +2 -2
  114. package/dist/delta/deltaE94.d.ts.map +1 -0
  115. package/dist/{utility → delta}/deltaE94.js +0 -6
  116. package/dist/delta/deltaE94.js.map +1 -0
  117. package/dist/{utility → delta}/deltaH.d.ts +2 -2
  118. package/dist/delta/deltaH.d.ts.map +1 -0
  119. package/dist/{utility → delta}/deltaH.js +0 -4
  120. package/dist/delta/deltaH.js.map +1 -0
  121. package/dist/index.d.ts +41 -31
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +41 -30
  124. package/dist/index.js.map +1 -1
  125. package/dist/names/bang.d.ts +2 -2
  126. package/dist/names/bang.d.ts.map +1 -1
  127. package/dist/names/bang.js +471 -471
  128. package/dist/names/bang.js.map +1 -1
  129. package/dist/names/cne.d.ts +1 -1
  130. package/dist/names/cne.d.ts.map +1 -1
  131. package/dist/names/cne.js +843 -843
  132. package/dist/names/cne.js.map +1 -1
  133. package/dist/names/crayola.d.ts +1 -1
  134. package/dist/names/crayola.d.ts.map +1 -1
  135. package/dist/names/crayola.js +110 -110
  136. package/dist/names/crayola.js.map +1 -1
  137. package/dist/names/getName.d.ts +2 -2
  138. package/dist/names/getName.d.ts.map +1 -1
  139. package/dist/names/getName.js +3 -3
  140. package/dist/names/getName.js.map +1 -1
  141. package/dist/names/hollasch.d.ts +1 -1
  142. package/dist/names/hollasch.d.ts.map +1 -1
  143. package/dist/names/hollasch.js +179 -179
  144. package/dist/names/hollasch.js.map +1 -1
  145. package/dist/names/nbs.d.ts +1 -1
  146. package/dist/names/nbs.d.ts.map +1 -1
  147. package/dist/names/nbs.js +266 -266
  148. package/dist/names/nbs.js.map +1 -1
  149. package/dist/names/ntc.d.ts +1 -1
  150. package/dist/names/ntc.d.ts.map +1 -1
  151. package/dist/names/ntc.js +1519 -1519
  152. package/dist/names/ntc.js.map +1 -1
  153. package/dist/names/resene.d.ts +1 -1
  154. package/dist/names/resene.d.ts.map +1 -1
  155. package/dist/names/resene.js +1331 -1331
  156. package/dist/names/resene.js.map +1 -1
  157. package/dist/names/tcapi.d.ts +1 -1
  158. package/dist/names/tcapi.d.ts.map +1 -1
  159. package/dist/names/tcapi.js +1840 -1840
  160. package/dist/names/tcapi.js.map +1 -1
  161. package/dist/names/x11.d.ts +1 -1
  162. package/dist/names/x11.d.ts.map +1 -1
  163. package/dist/names/x11.js +445 -445
  164. package/dist/names/x11.js.map +1 -1
  165. package/dist/names/xkcd.d.ts +1 -1
  166. package/dist/names/xkcd.d.ts.map +1 -1
  167. package/dist/names/xkcd.js +897 -897
  168. package/dist/names/xkcd.js.map +1 -1
  169. package/dist/palette/analogous.d.ts +28 -0
  170. package/dist/palette/analogous.d.ts.map +1 -0
  171. package/dist/palette/analogous.js +15 -0
  172. package/dist/palette/analogous.js.map +1 -0
  173. package/dist/palette/analogousLch.d.ts +19 -0
  174. package/dist/palette/analogousLch.d.ts.map +1 -0
  175. package/dist/palette/analogousLch.js +15 -0
  176. package/dist/palette/analogousLch.js.map +1 -0
  177. package/dist/palette/complement.d.ts +28 -0
  178. package/dist/palette/complement.d.ts.map +1 -0
  179. package/dist/palette/complement.js +15 -0
  180. package/dist/palette/complement.js.map +1 -0
  181. package/dist/palette/complementLch.d.ts +19 -0
  182. package/dist/palette/complementLch.d.ts.map +1 -0
  183. package/dist/palette/complementLch.js +15 -0
  184. package/dist/palette/complementLch.js.map +1 -0
  185. package/dist/palette/splitComplement.d.ts +28 -0
  186. package/dist/palette/splitComplement.d.ts.map +1 -0
  187. package/dist/palette/splitComplement.js +15 -0
  188. package/dist/palette/splitComplement.js.map +1 -0
  189. package/dist/palette/splitComplementLch.d.ts +19 -0
  190. package/dist/palette/splitComplementLch.d.ts.map +1 -0
  191. package/dist/palette/splitComplementLch.js +15 -0
  192. package/dist/palette/splitComplementLch.js.map +1 -0
  193. package/dist/types/Adobe.d.ts.map +1 -1
  194. package/dist/types/Cmy.d.ts.map +1 -1
  195. package/dist/types/Cmyk.d.ts.map +1 -1
  196. package/dist/types/Hsi.d.ts +15 -0
  197. package/dist/types/Hsi.d.ts.map +1 -0
  198. package/dist/types/Hsi.js +2 -0
  199. package/dist/types/Hsi.js.map +1 -0
  200. package/dist/types/Hsl.d.ts +1 -1
  201. package/dist/types/Hsl.d.ts.map +1 -1
  202. package/dist/types/Hsv.d.ts +1 -1
  203. package/dist/types/Hsv.d.ts.map +1 -1
  204. package/dist/types/Hunter.d.ts.map +1 -1
  205. package/dist/types/Lab.d.ts +2 -2
  206. package/dist/types/Lab.d.ts.map +1 -1
  207. package/dist/types/Lchab.d.ts +15 -0
  208. package/dist/types/Lchab.d.ts.map +1 -0
  209. package/dist/types/Lchab.js +2 -0
  210. package/dist/types/Lchab.js.map +1 -0
  211. package/dist/types/Lchuv.d.ts +15 -0
  212. package/dist/types/Lchuv.d.ts.map +1 -0
  213. package/dist/types/Lchuv.js +2 -0
  214. package/dist/types/Lchuv.js.map +1 -0
  215. package/dist/types/Luv.d.ts +1 -1
  216. package/dist/types/Luv.d.ts.map +1 -1
  217. package/dist/types/Rgb.d.ts.map +1 -1
  218. package/dist/types/Xyz.d.ts.map +1 -1
  219. package/dist/types/Yxy.d.ts.map +1 -1
  220. package/dist/utility/StandardIlluminant.d.ts.map +1 -1
  221. package/dist/utility/StandardIlluminant.js.map +1 -1
  222. package/dist/utility/contrast.d.ts +1 -1
  223. package/dist/utility/contrast.d.ts.map +1 -1
  224. package/dist/utility/contrast.js.map +1 -1
  225. package/dist/utility/getReference.d.ts +2 -2
  226. package/dist/utility/getReference.d.ts.map +1 -1
  227. package/dist/utility/getReference.js +39 -39
  228. package/dist/utility/getReference.js.map +1 -1
  229. package/dist/utility/isWebSafe.d.ts +10 -0
  230. package/dist/utility/isWebSafe.d.ts.map +1 -0
  231. package/dist/utility/isWebSafe.js +11 -0
  232. package/dist/utility/isWebSafe.js.map +1 -0
  233. package/dist/utility/relativeLuminance.d.ts +1 -1
  234. package/dist/utility/relativeLuminance.d.ts.map +1 -1
  235. package/dist/utility/relativeLuminance.js.map +1 -1
  236. package/package.json +34 -36
  237. package/src/{utility → convert}/adobeToXyz.ts +10 -4
  238. package/src/{utility → convert}/cmyToCmyk.ts +5 -4
  239. package/src/{utility → convert}/cmyToRgb.ts +3 -1
  240. package/src/{utility → convert}/cmykToCmy.ts +3 -2
  241. package/src/{utility → convert}/hexToRgb.ts +1 -1
  242. package/src/{utility → convert}/hslToRgb.ts +11 -7
  243. package/src/{utility → convert}/hsvToRgb.ts +4 -3
  244. package/src/{utility → convert}/hunterToXyz.ts +13 -10
  245. package/src/convert/labToLch.ts +40 -0
  246. package/src/{utility → convert}/labToXyz.ts +13 -8
  247. package/src/convert/lchToLab.ts +34 -0
  248. package/src/{utility → convert}/luvToXyz.ts +11 -9
  249. package/src/{utility → convert}/rgbToCmy.ts +3 -1
  250. package/src/{utility → convert}/rgbToHex.ts +6 -2
  251. package/src/convert/rgbToHsi.ts +45 -0
  252. package/src/convert/rgbToHsl.ts +46 -0
  253. package/src/{utility → convert}/rgbToHsv.ts +16 -13
  254. package/src/{utility → convert}/rgbToXyz.ts +13 -4
  255. package/src/convert/xyzToAdobe.ts +25 -0
  256. package/src/{utility → convert}/xyzToHunter.ts +14 -11
  257. package/src/{utility → convert}/xyzToLab.ts +14 -8
  258. package/src/{utility → convert}/xyzToLuv.ts +13 -11
  259. package/src/{utility → convert}/xyzToRgb.ts +12 -4
  260. package/src/{utility → convert}/xyzToYxy.ts +5 -4
  261. package/src/{utility → convert}/yxyToXyz.ts +5 -4
  262. package/src/{utility → delta}/deltaC.ts +12 -5
  263. package/src/{utility → delta}/deltaCmc.ts +14 -12
  264. package/src/{utility → delta}/deltaE00.ts +23 -20
  265. package/src/{utility → delta}/deltaE76.ts +12 -5
  266. package/src/{utility → delta}/deltaE94.ts +9 -10
  267. package/src/{utility → delta}/deltaH.ts +15 -9
  268. package/src/index.ts +47 -31
  269. package/src/names/bang.ts +476 -472
  270. package/src/names/cne.ts +848 -844
  271. package/src/names/crayola.ts +115 -111
  272. package/src/names/getName.ts +7 -6
  273. package/src/names/hollasch.ts +184 -180
  274. package/src/names/nbs.ts +271 -267
  275. package/src/names/ntc.ts +1524 -1520
  276. package/src/names/resene.ts +1336 -1332
  277. package/src/names/tcapi.ts +1845 -1841
  278. package/src/names/x11.ts +450 -446
  279. package/src/names/xkcd.ts +902 -898
  280. package/src/palette/analogous.ts +61 -0
  281. package/src/palette/analogousLch.ts +49 -0
  282. package/src/palette/complement.ts +65 -0
  283. package/src/palette/complementLch.ts +50 -0
  284. package/src/palette/splitComplement.ts +61 -0
  285. package/src/palette/splitComplementLch.ts +48 -0
  286. package/src/types/Adobe.ts +3 -0
  287. package/src/types/Cmy.ts +3 -0
  288. package/src/types/Cmyk.ts +4 -0
  289. package/src/types/Hsi.ts +20 -0
  290. package/src/types/Hsl.ts +4 -1
  291. package/src/types/Hsv.ts +4 -1
  292. package/src/types/Hunter.ts +3 -0
  293. package/src/types/Lab.ts +5 -2
  294. package/src/types/Lchab.ts +20 -0
  295. package/src/types/Lchuv.ts +20 -0
  296. package/src/types/Luv.ts +4 -1
  297. package/src/types/Rgb.ts +3 -0
  298. package/src/types/Xyz.ts +3 -0
  299. package/src/types/Yxy.ts +3 -0
  300. package/src/utility/StandardIlluminant.ts +40 -40
  301. package/src/utility/contrast.ts +5 -1
  302. package/src/utility/getReference.ts +42 -41
  303. package/src/utility/isWebSafe.ts +14 -0
  304. package/src/utility/relativeLuminance.ts +2 -2
  305. package/dist/types/Lch.d.ts +0 -16
  306. package/dist/types/Lch.d.ts.map +0 -1
  307. package/dist/types/Lch.js +0 -2
  308. package/dist/types/Lch.js.map +0 -1
  309. package/dist/utility/adobeToXyz.d.ts.map +0 -1
  310. package/dist/utility/adobeToXyz.js.map +0 -1
  311. package/dist/utility/cmyToCmyk.d.ts.map +0 -1
  312. package/dist/utility/cmyToCmyk.js.map +0 -1
  313. package/dist/utility/cmyToRgb.d.ts.map +0 -1
  314. package/dist/utility/cmyToRgb.js.map +0 -1
  315. package/dist/utility/cmykToCmy.d.ts.map +0 -1
  316. package/dist/utility/cmykToCmy.js.map +0 -1
  317. package/dist/utility/deltaC.d.ts.map +0 -1
  318. package/dist/utility/deltaCmc.d.ts.map +0 -1
  319. package/dist/utility/deltaCmc.js.map +0 -1
  320. package/dist/utility/deltaE00.d.ts.map +0 -1
  321. package/dist/utility/deltaE00.js.map +0 -1
  322. package/dist/utility/deltaE76.d.ts.map +0 -1
  323. package/dist/utility/deltaE94.d.ts.map +0 -1
  324. package/dist/utility/deltaE94.js.map +0 -1
  325. package/dist/utility/deltaH.d.ts.map +0 -1
  326. package/dist/utility/deltaH.js.map +0 -1
  327. package/dist/utility/hexToRgb.d.ts.map +0 -1
  328. package/dist/utility/hslToRgb.d.ts.map +0 -1
  329. package/dist/utility/hslToRgb.js.map +0 -1
  330. package/dist/utility/hsvToRgb.d.ts.map +0 -1
  331. package/dist/utility/hsvToRgb.js.map +0 -1
  332. package/dist/utility/hunterToXyz.d.ts.map +0 -1
  333. package/dist/utility/hunterToXyz.js.map +0 -1
  334. package/dist/utility/labToLch.d.ts +0 -11
  335. package/dist/utility/labToLch.d.ts.map +0 -1
  336. package/dist/utility/labToLch.js +0 -19
  337. package/dist/utility/labToLch.js.map +0 -1
  338. package/dist/utility/labToXyz.d.ts.map +0 -1
  339. package/dist/utility/labToXyz.js.map +0 -1
  340. package/dist/utility/lchToLab.d.ts +0 -11
  341. package/dist/utility/lchToLab.d.ts.map +0 -1
  342. package/dist/utility/lchToLab.js +0 -14
  343. package/dist/utility/lchToLab.js.map +0 -1
  344. package/dist/utility/luvToXyz.d.ts.map +0 -1
  345. package/dist/utility/luvToXyz.js.map +0 -1
  346. package/dist/utility/rgbToCmy.d.ts.map +0 -1
  347. package/dist/utility/rgbToCmy.js.map +0 -1
  348. package/dist/utility/rgbToHex.js.map +0 -1
  349. package/dist/utility/rgbToHsl.d.ts.map +0 -1
  350. package/dist/utility/rgbToHsl.js +0 -31
  351. package/dist/utility/rgbToHsl.js.map +0 -1
  352. package/dist/utility/rgbToHsv.d.ts.map +0 -1
  353. package/dist/utility/rgbToHsv.js.map +0 -1
  354. package/dist/utility/rgbToXyz.d.ts.map +0 -1
  355. package/dist/utility/rgbToXyz.js.map +0 -1
  356. package/dist/utility/xyzToAdobe.d.ts.map +0 -1
  357. package/dist/utility/xyzToAdobe.js.map +0 -1
  358. package/dist/utility/xyzToHunter.d.ts.map +0 -1
  359. package/dist/utility/xyzToHunter.js.map +0 -1
  360. package/dist/utility/xyzToLab.d.ts.map +0 -1
  361. package/dist/utility/xyzToLab.js.map +0 -1
  362. package/dist/utility/xyzToLuv.d.ts.map +0 -1
  363. package/dist/utility/xyzToLuv.js.map +0 -1
  364. package/dist/utility/xyzToRgb.d.ts.map +0 -1
  365. package/dist/utility/xyzToRgb.js.map +0 -1
  366. package/dist/utility/xyzToYxy.d.ts.map +0 -1
  367. package/dist/utility/xyzToYxy.js.map +0 -1
  368. package/dist/utility/yxyToXyz.d.ts.map +0 -1
  369. package/dist/utility/yxyToXyz.js.map +0 -1
  370. package/src/types/Lch.ts +0 -18
  371. package/src/utility/labToLch.ts +0 -24
  372. package/src/utility/lchToLab.ts +0 -18
  373. package/src/utility/rgbToHsl.ts +0 -38
  374. package/src/utility/xyzToAdobe.ts +0 -20
  375. /package/dist/{utility → convert}/cmyToRgb.js +0 -0
  376. /package/dist/{utility → convert}/hexToRgb.js +0 -0
  377. /package/dist/{utility → convert}/rgbToCmy.js +0 -0
  378. /package/dist/{utility → delta}/deltaC.js +0 -0
  379. /package/dist/{utility → delta}/deltaE76.js +0 -0
@@ -1,7 +1,11 @@
1
1
  import type Hunter from "../types/Hunter.js";
2
- import StandardIlluminant from "./StandardIlluminant.js";
3
2
  import type Xyz from "../types/Xyz.js";
4
- import getReference from "./getReference.js";
3
+
4
+ import getReference from "../utility/getReference.js";
5
+ import StandardIlluminant from "../utility/StandardIlluminant.js";
6
+
7
+ const c0 = 175 / 198.04;
8
+ const c1 = 70 / 218.11;
5
9
 
6
10
  /**
7
11
  * Convert the given Hunter Lab color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
@@ -11,14 +15,13 @@ import getReference from "./getReference.js";
11
15
  * @public
12
16
  */
13
17
  export default function hunterToXyz(
14
- color: Hunter,
15
- ref: Xyz = getReference(StandardIlluminant.D65_2)
16
- ): Xyz {
17
- // eslint-disable-next-line prefer-destructuring
18
+ color: Readonly<Hunter>,
19
+ ref: Readonly<Xyz> = getReference(StandardIlluminant.D65_2)
20
+ ): [number, number, number] & Xyz {
18
21
  const rx = ref[0];
19
- // eslint-disable-next-line prefer-destructuring
22
+
20
23
  const ry = ref[1];
21
- // eslint-disable-next-line prefer-destructuring
24
+
22
25
  const rz = ref[2];
23
26
 
24
27
  const y = (color[0] / ry) ** 2 * 100;
@@ -26,8 +29,8 @@ export default function hunterToXyz(
26
29
  const i1 = Math.sqrt(i0);
27
30
 
28
31
  return [
29
- ((color[1] / (0.88365987 * (ry + rx))) * i1 + i0) * rx, // `175 / 198.04`
32
+ ((color[1] / (c0 * (ry + rx))) * i1 + i0) * rx,
30
33
  y,
31
- -((color[2] / (0.32093898 * (ry + rz))) * i1 - i0) * rz // `70 / 218.11`
34
+ -((color[2] / (c1 * (ry + rz))) * i1 - i0) * rz
32
35
  ];
33
36
  }
@@ -0,0 +1,40 @@
1
+ import type Lab from "../types/Lab.js";
2
+ import type Lchab from "../types/Lchab.js";
3
+ import type Lchuv from "../types/Lchuv.js";
4
+ import type Luv from "../types/Luv.js";
5
+
6
+ const c0 = 180 / Math.PI;
7
+
8
+ /**
9
+ * Convert the given CIELAB color to a CIELCh(ab) color. Based on the EasyRGB pseudo-code.
10
+ * @param color - The CIELAB color.
11
+ * @returns A CIELCh color.
12
+ * @public
13
+ */
14
+ export default function labToLch(
15
+ color: Readonly<Lab>
16
+ ): [number, number, number] & Lchab;
17
+ /**
18
+ * Convert the given CIELUV color to a CIELCh(uv) color. Based on the EasyRGB pseudo-code.
19
+ * @param color - The CIELUV color.
20
+ * @returns A CIELCh color.
21
+ * @public
22
+ */
23
+ export default function labToLch(
24
+ color: Readonly<Luv>
25
+ ): [number, number, number] & Lchuv;
26
+ export default function labToLch(
27
+ color: Readonly<Lab | Luv>
28
+ ): [number, number, number] & (Lchab | Lchuv) {
29
+ const a = color[1];
30
+
31
+ const b = color[2];
32
+
33
+ const i0 = Math.atan2(b, a);
34
+
35
+ return [
36
+ color[0],
37
+ Math.hypot(a, b),
38
+ i0 > 0 ? i0 * c0 : 360 - Math.abs(i0) * c0
39
+ ];
40
+ }
@@ -1,7 +1,12 @@
1
1
  import type Lab from "../types/Lab.js";
2
- import StandardIlluminant from "./StandardIlluminant.js";
3
2
  import type Xyz from "../types/Xyz.js";
4
- import getReference from "./getReference.js";
3
+
4
+ import getReference from "../utility/getReference.js";
5
+ import StandardIlluminant from "../utility/StandardIlluminant.js";
6
+
7
+ const c0 = 0.008856;
8
+ const c1 = 16 / 116;
9
+ const c2 = 7.787;
5
10
 
6
11
  /**
7
12
  * Convert the given CIELAB color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
@@ -11,9 +16,9 @@ import getReference from "./getReference.js";
11
16
  * @public
12
17
  */
13
18
  export default function labToXyz(
14
- color: Lab,
15
- ref: Xyz = getReference(StandardIlluminant.D65_2)
16
- ): Xyz {
19
+ color: Readonly<Lab>,
20
+ ref: Readonly<Xyz> = getReference(StandardIlluminant.D65_2)
21
+ ): [number, number, number] & Xyz {
17
22
  const i0 = (color[0] + 16) / 116;
18
23
  const i1 = i0 ** 3;
19
24
  const i2 = color[1] / 500 + i0;
@@ -22,8 +27,8 @@ export default function labToXyz(
22
27
  const i5 = i4 ** 3;
23
28
 
24
29
  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`
30
+ (i3 > c0 ? i3 : (i2 - c1) / c2) * ref[0],
31
+ (i1 > c0 ? i1 : (i0 - c1) / c2) * ref[1],
32
+ (i5 > c0 ? i5 : (i4 - c1) / c2) * ref[2]
28
33
  ];
29
34
  }
@@ -0,0 +1,34 @@
1
+ import type Lab from "../types/Lab.js";
2
+ import type Lchab from "../types/Lchab.js";
3
+ import type Lchuv from "../types/Lchuv.js";
4
+ import type Luv from "../types/Luv.js";
5
+
6
+ const c0 = Math.PI / 180;
7
+
8
+ /**
9
+ * Convert the given CIELCh(ab) color to a CIELAB color. Based on the EasyRGB pseudo-code.
10
+ * @param color - The CIELCh color.
11
+ * @returns A CIELAB color.
12
+ * @public
13
+ */
14
+ export default function lchToLab(
15
+ color: Readonly<Lchab>
16
+ ): [number, number, number] & Lab;
17
+ /**
18
+ * Convert the given CIELCh(uv) color to a CIELUV color. Based on the EasyRGB pseudo-code.
19
+ * @param color - The CIELCh color.
20
+ * @returns A CIELUV color.
21
+ * @public
22
+ */
23
+ export default function lchToLab(
24
+ color: Readonly<Lchuv>
25
+ ): [number, number, number] & Luv;
26
+ export default function lchToLab(
27
+ color: Readonly<Lchab | Lchuv>
28
+ ): [number, number, number] & (Lab | Luv) {
29
+ const c = color[1];
30
+
31
+ const h = color[2];
32
+
33
+ return [color[0], Math.cos(h * c0) * c, Math.sin(h * c0) * c];
34
+ }
@@ -1,7 +1,10 @@
1
1
  import type Luv from "../types/Luv.js";
2
- import StandardIlluminant from "./StandardIlluminant.js";
3
2
  import type Xyz from "../types/Xyz.js";
4
- import getReference from "./getReference.js";
3
+
4
+ import getReference from "../utility/getReference.js";
5
+ import StandardIlluminant from "../utility/StandardIlluminant.js";
6
+
7
+ const c0 = 16 / 116;
5
8
 
6
9
  /**
7
10
  * Convert the given CIELUV color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
@@ -11,14 +14,13 @@ import getReference from "./getReference.js";
11
14
  * @public
12
15
  */
13
16
  export default function luvToXyz(
14
- color: Luv,
15
- ref: Xyz = getReference(StandardIlluminant.D65_2)
16
- ): Xyz {
17
- // eslint-disable-next-line prefer-destructuring
17
+ color: Readonly<Luv>,
18
+ ref: Readonly<Xyz> = getReference(StandardIlluminant.D65_2)
19
+ ): [number, number, number] & Xyz {
18
20
  const l = color[0];
19
- // eslint-disable-next-line prefer-destructuring
21
+
20
22
  const rx = ref[0];
21
- // eslint-disable-next-line prefer-destructuring
23
+
22
24
  const ry = ref[1];
23
25
 
24
26
  const i0 = (l + 16) / 116;
@@ -27,7 +29,7 @@ export default function luvToXyz(
27
29
  const i3 = rx + 15 * ry + 3 * ref[2];
28
30
  const i4 = color[1] / i2 + (4 * rx) / i3;
29
31
  const i5 = color[2] / i2 + (9 * ry) / i3;
30
- const y = (i1 > 0.008856 ? i1 : (i0 - 0.13793103) / 7.787) * 100; // `16 / 166`
32
+ const y = (i1 > 0.008856 ? i1 : (i0 - c0) / 7.787) * 100; // `16 / 166`
31
33
  const i6 = 9 * y;
32
34
  const x = -(i6 * i4) / ((i4 - 4) * i5 - i4 * i5);
33
35
 
@@ -7,6 +7,8 @@ import type Rgb from "../types/Rgb.js";
7
7
  * @returns A CMY color.
8
8
  * @public
9
9
  */
10
- export default function rgbToCmy(color: Rgb): Cmy {
10
+ export default function rgbToCmy(
11
+ color: Readonly<Rgb>
12
+ ): [number, number, number] & Cmy {
11
13
  return [1 - color[0] / 0xff, 1 - color[1] / 0xff, 1 - color[2] / 0xff];
12
14
  }
@@ -6,6 +6,10 @@ import type Rgb from "../types/Rgb.js";
6
6
  * @returns The numerical hexadecimal representation of the color.
7
7
  * @public
8
8
  */
9
- export default function rgbToHex(rgb: Rgb): number {
10
- return rgb[0] * 0x10000 + rgb[1] * 0x100 + rgb[2];
9
+ export default function rgbToHex(rgb: Readonly<Rgb>): number {
10
+ return (
11
+ Math.round(rgb[0] * 0x10000) +
12
+ Math.round(rgb[1] * 0x100) +
13
+ Math.round(rgb[2])
14
+ );
11
15
  }
@@ -0,0 +1,45 @@
1
+ import type Hsi from "../types/Hsi.js";
2
+ import type Rgb from "../types/Rgb.js";
3
+
4
+ const c0 = 1 / 3;
5
+ const c1 = 2 / 3;
6
+
7
+ /**
8
+ * Convert the given sRGB color to an HSI color.
9
+ * @param color - The sRGB color.
10
+ * @returns An HSI color.
11
+ * @public
12
+ */
13
+ export default function rgbToHsi(
14
+ color: Readonly<Rgb>
15
+ ): [number, number, number] & Hsi {
16
+ const i0 = color[0] / 0xff;
17
+ const i1 = color[1] / 0xff;
18
+ const i2 = color[2] / 0xff;
19
+ const i = (i0 + i1 + i2) / 3;
20
+ const v = Math.max(i0, i1, i2);
21
+ const m = Math.min(i0, i1, i2);
22
+ const c = v - m;
23
+
24
+ if (c === 0) {
25
+ return [0, 0, i];
26
+ }
27
+
28
+ const i4 = c / 2;
29
+ const i5 = ((v - i0) / 6 + i4) / c;
30
+ const i6 = ((v - i1) / 6 + i4) / c;
31
+ const i7 = ((v - i2) / 6 + i4) / c;
32
+ const i8 =
33
+ i0 === v ? i7 - i6
34
+ : i1 === v ? c0 + i5 - i7
35
+ : i2 === v ? c1 + i6 - i5
36
+ : 0;
37
+
38
+ return [
39
+ i8 < 0 ? i8 + 1
40
+ : i8 > 1 ? i8 - 1
41
+ : i8,
42
+ i === 0 ? 0 : 1 - m / i,
43
+ i
44
+ ];
45
+ }
@@ -0,0 +1,46 @@
1
+ import type Hsl from "../types/Hsl.js";
2
+ import type Rgb from "../types/Rgb.js";
3
+
4
+ const c0 = 1 / 3;
5
+ const c1 = 2 / 3;
6
+
7
+ /**
8
+ * Convert the given sRGB color to an HSL color. Based on the EasyRGB pseudo-code.
9
+ * @param color - The sRGB color.
10
+ * @returns An HSL color.
11
+ * @public
12
+ */
13
+ export default function rgbToHsl(
14
+ color: Readonly<Rgb>
15
+ ): [number, number, number] & Hsl {
16
+ const i0 = color[0] / 0xff;
17
+ const i1 = color[1] / 0xff;
18
+ const i2 = color[2] / 0xff;
19
+ const i3 = Math.min(i0, i1, i2);
20
+ const i4 = Math.max(i0, i1, i2);
21
+ const i5 = i4 + i3;
22
+ const l = i5 / 2;
23
+ const i6 = i4 - i3;
24
+
25
+ if (i6 === 0) {
26
+ return [0, 0, l];
27
+ }
28
+
29
+ const i7 = i6 / 2;
30
+ const i8 = ((i4 - i0) / 6 + i7) / i6;
31
+ const i9 = ((i4 - i1) / 6 + i7) / i6;
32
+ const i10 = ((i4 - i2) / 6 + i7) / i6;
33
+ const i11 =
34
+ i0 === i4 ? i10 - i9
35
+ : i1 === i4 ? c0 + i8 - i10
36
+ : i2 === i4 ? c1 + i9 - i8
37
+ : 0;
38
+
39
+ return [
40
+ i11 < 0 ? i11 + 1
41
+ : i11 > 1 ? i11 - 1
42
+ : i11,
43
+ l < 0.5 ? i6 / i5 : i6 / (2 - i4 - i3),
44
+ l
45
+ ];
46
+ }
@@ -1,40 +1,43 @@
1
1
  import type Hsv from "../types/Hsv.js";
2
2
  import type Rgb from "../types/Rgb.js";
3
3
 
4
+ const c0 = 1 / 3;
5
+ const c1 = 2 / 3;
6
+
4
7
  /**
5
8
  * Convert the given sRGB color to an HSV color. Based on the EasyRGB pseudo-code.
6
9
  * @param color - The sRGB color.
7
10
  * @returns An HSV color.
8
11
  * @public
9
12
  */
10
- export default function rgbToHsv(color: Rgb): Hsv {
13
+ export default function rgbToHsv(
14
+ color: Readonly<Rgb>
15
+ ): [number, number, number] & Hsv {
11
16
  const i0 = color[0] / 0xff;
12
17
  const i1 = color[1] / 0xff;
13
18
  const i2 = color[2] / 0xff;
14
19
  const v = Math.max(i0, i1, i2);
15
- const i3 = v - Math.min(i0, i1, i2);
20
+ const c = v - Math.min(i0, i1, i2);
16
21
 
17
- if (i3 === 0) {
22
+ if (c === 0) {
18
23
  return [0, 0, v];
19
24
  }
20
25
 
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;
26
+ const i4 = c / 2;
27
+ const i5 = ((v - i0) / 6 + i4) / c;
28
+ const i6 = ((v - i1) / 6 + i4) / c;
29
+ const i7 = ((v - i2) / 6 + i4) / c;
25
30
  const i8 =
26
31
  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;
32
+ : i1 === v ? c0 + i5 - i7
33
+ : i2 === v ? c1 + i6 - i5
34
+ : 0;
32
35
 
33
36
  return [
34
37
  i8 < 0 ? i8 + 1
35
38
  : i8 > 1 ? i8 - 1
36
39
  : i8,
37
- i3 / v,
40
+ v === 0 ? 0 : c / v,
38
41
  v
39
42
  ];
40
43
  }
@@ -1,19 +1,28 @@
1
1
  import type Rgb from "../types/Rgb.js";
2
2
  import type Xyz from "../types/Xyz.js";
3
3
 
4
+ const c0 = 0.04045;
5
+ const c1 = 0.055;
6
+ const c2 = 1.055;
7
+ const c3 = 2.4;
8
+ const c4 = 12.92;
9
+ const c5 = 100;
10
+
4
11
  /**
5
12
  * Convert the given sRGB color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
6
13
  * @param color - The sRGB color.
7
14
  * @returns A CIEXYZ color.
8
15
  * @public
9
16
  */
10
- export default function rgbToXyz(color: Rgb): Xyz {
17
+ export default function rgbToXyz(
18
+ color: Readonly<Rgb>
19
+ ): [number, number, number] & Xyz {
11
20
  const i0 = color[0] / 0xff;
12
21
  const i1 = color[1] / 0xff;
13
22
  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;
23
+ const i3 = (i0 > c0 ? ((i0 + c1) / c2) ** c3 : i0 / c4) * c5;
24
+ const i4 = (i1 > c0 ? ((i1 + c1) / c2) ** c3 : i1 / c4) * c5;
25
+ const i5 = (i2 > c0 ? ((i2 + c1) / c2) ** c3 : i2 / c4) * c5;
17
26
 
18
27
  return [
19
28
  i3 * 0.4124 + i4 * 0.3576 + i5 * 0.1805,
@@ -0,0 +1,25 @@
1
+ import type Adobe from "../types/Adobe.js";
2
+ import type Xyz from "../types/Xyz.js";
3
+
4
+ const gamma = 0x233 / 0x100; // https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf
5
+ const c0 = 1 / gamma;
6
+
7
+ /**
8
+ * Convert the given CIEXYZ D65/2° standard illuminant color to an Adobe RGB color. Based on the EasyRGB pseudo-code.
9
+ * @param color - The CIEXYZ color.
10
+ * @returns An Adobe RGB color.
11
+ * @public
12
+ */
13
+ export default function xyzToAdobe(
14
+ color: Readonly<Xyz>
15
+ ): [number, number, number] & Adobe {
16
+ const i0 = color[0] / 100;
17
+ const i1 = color[1] / 100;
18
+ const i2 = color[2] / 100;
19
+
20
+ return [
21
+ (i0 * 2.04137 + i1 * -0.56495 + i2 * -0.34469) ** c0 * 0xff,
22
+ (i0 * -0.96927 + i1 * 1.87601 + i2 * 0.04156) ** c0 * 0xff,
23
+ (i0 * 0.01345 + i1 * -0.11839 + i2 * 1.01541) ** c0 * 0xff
24
+ ];
25
+ }
@@ -1,24 +1,27 @@
1
1
  import type Hunter from "../types/Hunter.js";
2
- import StandardIlluminant from "./StandardIlluminant.js";
3
2
  import type Xyz from "../types/Xyz.js";
4
- import getReference from "./getReference.js";
3
+
4
+ import getReference from "../utility/getReference.js";
5
+ import StandardIlluminant from "../utility/StandardIlluminant.js";
6
+
7
+ const c0 = 175 / 198.04;
8
+ const c1 = 70 / 218.11;
5
9
 
6
10
  /**
7
11
  * Convert the given CIEXYZ color to a Hunter Lab color. Based on the EasyRGB pseudo-code.
8
12
  * @param color - The CIEXYZ color.
9
- * @param ref - A standard illuminant that represents the white point.
13
+ * @param ref - A standard illuminant that represents the white point. This color space was originally used with standard illuminant C.
10
14
  * @returns A Hunter Lab color.
11
15
  * @public
12
16
  */
13
17
  export default function xyzToHunter(
14
- color: Xyz,
15
- ref: Xyz = getReference(StandardIlluminant.D65_2)
16
- ): Hunter {
17
- // eslint-disable-next-line prefer-destructuring
18
+ color: Readonly<Xyz>,
19
+ ref: Readonly<Xyz> = getReference(StandardIlluminant.D65_2)
20
+ ): [number, number, number] & Hunter {
18
21
  const rx = ref[0];
19
- // eslint-disable-next-line prefer-destructuring
22
+
20
23
  const ry = ref[1];
21
- // eslint-disable-next-line prefer-destructuring
24
+
22
25
  const rz = ref[2];
23
26
 
24
27
  const i2 = color[1] / ry;
@@ -26,7 +29,7 @@ export default function xyzToHunter(
26
29
 
27
30
  return [
28
31
  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`
32
+ c0 * (ry + rx) * ((color[0] / rx - i2) / i3),
33
+ c1 * (ry + rz) * ((i2 - color[2] / rz) / i3)
31
34
  ];
32
35
  }
@@ -1,7 +1,13 @@
1
1
  import type Lab from "../types/Lab.js";
2
- import StandardIlluminant from "./StandardIlluminant.js";
3
2
  import type Xyz from "../types/Xyz.js";
4
- import getReference from "./getReference.js";
3
+
4
+ import getReference from "../utility/getReference.js";
5
+ import StandardIlluminant from "../utility/StandardIlluminant.js";
6
+
7
+ const c0 = 1 / 3;
8
+ const c1 = 16 / 116;
9
+ const c2 = 0.008856;
10
+ const c3 = 7.787;
5
11
 
6
12
  /**
7
13
  * Convert the given CIEXYZ color to a CIELAB color. Based on the EasyRGB pseudo-code.
@@ -11,17 +17,17 @@ import getReference from "./getReference.js";
11
17
  * @public
12
18
  */
13
19
  export default function xyzToLab(
14
- color: Xyz,
15
- ref: Xyz = getReference(StandardIlluminant.D65_2)
16
- ): Lab {
20
+ color: Readonly<Xyz>,
21
+ ref: Readonly<Xyz> = getReference(StandardIlluminant.D65_2)
22
+ ): [number, number, number] & Lab {
17
23
  const i0 = color[0] / ref[0];
18
24
  const i1 = color[1] / ref[1];
19
25
  const i2 = color[2] / ref[2];
20
- const i3 = i1 > 0.008856 ? i1 ** 0.33333333 : 7.787 * i1 + 0.13793103; // `1 / 3`; `16 / 116`
26
+ const i3 = i1 > c2 ? i1 ** c0 : c3 * i1 + c1;
21
27
 
22
28
  return [
23
29
  116 * i3 - 16,
24
- 500 * ((i0 > 0.008856 ? i0 ** 0.33333333 : 7.787 * i0 + 0.13793103) - i3), // `1 / 3`; `16 / 116`
25
- 200 * (i3 - (i2 > 0.008856 ? i2 ** 0.33333333 : 7.787 * i2 + 0.13793103)) // `1 / 3`; `16 / 116`
30
+ 500 * ((i0 > c2 ? i0 ** c0 : c3 * i0 + c1) - i3),
31
+ 200 * (i3 - (i2 > c2 ? i2 ** c0 : c3 * i2 + c1))
26
32
  ];
27
33
  }
@@ -1,7 +1,11 @@
1
1
  import type Luv from "../types/Luv.js";
2
- import StandardIlluminant from "./StandardIlluminant.js";
3
2
  import type Xyz from "../types/Xyz.js";
4
- import getReference from "./getReference.js";
3
+
4
+ import getReference from "../utility/getReference.js";
5
+ import StandardIlluminant from "../utility/StandardIlluminant.js";
6
+
7
+ const c0 = 1 / 3;
8
+ const c1 = 16 / 116;
5
9
 
6
10
  /**
7
11
  * Convert the given CIEXYZ color to a CIELUV color. Based on the EasyRGB pseudo-code.
@@ -11,23 +15,21 @@ import getReference from "./getReference.js";
11
15
  * @public
12
16
  */
13
17
  export default function xyzToLuv(
14
- color: Xyz,
15
- ref: Xyz = getReference(StandardIlluminant.D65_2)
16
- ): Luv {
17
- // eslint-disable-next-line prefer-destructuring
18
+ color: Readonly<Xyz>,
19
+ ref: Readonly<Xyz> = getReference(StandardIlluminant.D65_2)
20
+ ): [number, number, number] & Luv {
18
21
  const x = color[0];
19
- // eslint-disable-next-line prefer-destructuring
22
+
20
23
  const y = color[1];
21
- // eslint-disable-next-line prefer-destructuring
24
+
22
25
  const rx = ref[0];
23
- // eslint-disable-next-line prefer-destructuring
26
+
24
27
  const ry = ref[1];
25
28
 
26
29
  const i0 = x + 15 * y + 3 * color[2];
27
30
  const i1 = rx + 15 * ry + 3 * ref[2];
28
31
  const i2 = y / 100;
29
- const l =
30
- 116 * (i2 > 0.008856 ? i2 ** 0.33333333 : 7.787 * i2 + 0.13793103) - 16; // `1 / 3`; `16 / 116`
32
+ const l = 116 * (i2 > 0.008856 ? i2 ** c0 : 7.787 * i2 + c1) - 16;
31
33
  const i3 = 13 * l;
32
34
 
33
35
  return [
@@ -1,13 +1,21 @@
1
1
  import type Rgb from "../types/Rgb.js";
2
2
  import type Xyz from "../types/Xyz.js";
3
3
 
4
+ const c0 = 0.0031308;
5
+ const c1 = 1.055;
6
+ const c2 = 1 / 2.4;
7
+ const c3 = 0.055;
8
+ const c4 = 12.92;
9
+
4
10
  /**
5
11
  * Convert the given CIEXYZ D65/2° standard illuminant color to an sRGB color. Based on the EasyRGB pseudo-code.
6
12
  * @param color - The CIEXYZ color.
7
13
  * @returns An sRGB color.
8
14
  * @public
9
15
  */
10
- export default function xyzToRgb(color: Xyz): Rgb {
16
+ export default function xyzToRgb(
17
+ color: Readonly<Xyz>
18
+ ): [number, number, number] & Rgb {
11
19
  const i0 = color[0] / 100;
12
20
  const i1 = color[1] / 100;
13
21
  const i2 = color[2] / 100;
@@ -16,8 +24,8 @@ export default function xyzToRgb(color: Xyz): Rgb {
16
24
  const i5 = i0 * 0.0557 + i1 * -0.204 + i2 * 1.057;
17
25
 
18
26
  return [
19
- (i3 > 0.0031308 ? 1.055 * i3 ** 0.41666666 - 0.055 : i3 * 12.92) * 0xff, // `1 / 2.4`
20
- (i4 > 0.0031308 ? 1.055 * i4 ** 0.41666666 - 0.055 : i4 * 12.92) * 0xff, // `1 / 2.4`
21
- (i5 > 0.0031308 ? 1.055 * i5 ** 0.41666666 - 0.055 : i5 * 12.92) * 0xff // `1 / 2.4`
27
+ (i3 > c0 ? c1 * i3 ** c2 - c3 : i3 * c4) * 0xff,
28
+ (i4 > c0 ? c1 * i4 ** c2 - c3 : i4 * c4) * 0xff,
29
+ (i5 > c0 ? c1 * i5 ** c2 - c3 : i5 * c4) * 0xff
22
30
  ];
23
31
  }
@@ -7,12 +7,13 @@ import type Yxy from "../types/Yxy.js";
7
7
  * @returns The CIEXYZ color in yxy format.
8
8
  * @public
9
9
  */
10
- export default function xyzToYxy(color: Xyz): Yxy {
11
- // eslint-disable-next-line prefer-destructuring
10
+ export default function xyzToYxy(
11
+ color: Readonly<Xyz>
12
+ ): [number, number, number] & Yxy {
12
13
  const X = color[0];
13
- // eslint-disable-next-line prefer-destructuring
14
+
14
15
  const Y = color[1];
15
- // eslint-disable-next-line prefer-destructuring
16
+
16
17
  const Z = color[2];
17
18
 
18
19
  return [Y, X / (X + Y + Z), Y / (X + Y + Z)];
@@ -7,12 +7,13 @@ import type Yxy from "../types/Yxy.js";
7
7
  * @returns A CIEXYZ color.
8
8
  * @public
9
9
  */
10
- export default function yxyToXyz(color: Yxy): Xyz {
11
- // eslint-disable-next-line prefer-destructuring
10
+ export default function yxyToXyz(
11
+ color: Readonly<Yxy>
12
+ ): [number, number, number] & Xyz {
12
13
  const Y = color[0];
13
- // eslint-disable-next-line prefer-destructuring
14
+
14
15
  const x = color[1];
15
- // eslint-disable-next-line prefer-destructuring
16
+
16
17
  const y = color[2];
17
18
 
18
19
  return [x * (Y / y), Y, (1 - x - y) * (Y / y)];
@@ -9,8 +9,10 @@ import type Luv from "../types/Luv.js";
9
9
  * @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
10
10
  * @public
11
11
  */
12
- export default function deltaC(color0: Lab, color1: Lab): number;
13
-
12
+ export default function deltaC(
13
+ color0: Readonly<Lab>,
14
+ color1: Readonly<Lab>
15
+ ): number;
14
16
  /**
15
17
  * Calculates the ΔC* between two CIELUV values. Based on the EasyRGB pseudocode.
16
18
  * @param color0 - The first color.
@@ -19,8 +21,13 @@ export default function deltaC(color0: Lab, color1: Lab): number;
19
21
  * @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
20
22
  * @public
21
23
  */
22
- export default function deltaC(color0: Luv, color1: Luv): number;
23
-
24
- export default function deltaC(color0: Lab | Luv, color1: Lab | Luv): number {
24
+ export default function deltaC(
25
+ color0: Readonly<Luv>,
26
+ color1: Readonly<Luv>
27
+ ): number;
28
+ export default function deltaC(
29
+ color0: Readonly<Lab | Luv>,
30
+ color1: Readonly<Lab | Luv>
31
+ ): number {
25
32
  return Math.hypot(color1[1], color1[2]) - Math.hypot(color0[1], color0[2]);
26
33
  }