color-map 2.2.0 → 2.3.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 (366) hide show
  1. package/.claude-plugin/plugin.json +12 -0
  2. package/.codex-plugin/plugin.json +12 -0
  3. package/.cursor-plugin/plugin.json +12 -0
  4. package/CHANGELOG.md +94 -0
  5. package/README.md +71 -8
  6. package/bin/cli-CNBftDBE.js +6414 -0
  7. package/bin/color-map.js +9 -0
  8. package/bin/index.js +1 -0
  9. package/cjs/color/index.d.ts +5 -0
  10. package/cjs/color/index.js +52 -0
  11. package/cjs/color-wNrkrhC7.js +374 -0
  12. package/cjs/color-wNrkrhC7.js.map +1 -0
  13. package/cjs/contrast-XjF5Rwui.js +293 -0
  14. package/cjs/contrast-XjF5Rwui.js.map +1 -0
  15. package/cjs/gamut-CG1J2aat.d.ts +158 -0
  16. package/cjs/gamut-CG1J2aat.d.ts.map +1 -0
  17. package/cjs/index-BcEqCPHz.d.ts +137 -0
  18. package/cjs/index-BcEqCPHz.d.ts.map +1 -0
  19. package/cjs/index-CGKCqRqD.d.ts +111 -0
  20. package/cjs/index-CGKCqRqD.d.ts.map +1 -0
  21. package/cjs/index-Cv3iUUYE.d.ts +171 -0
  22. package/cjs/index-Cv3iUUYE.d.ts.map +1 -0
  23. package/cjs/index-Dw43Hj4v.d.ts +41 -0
  24. package/cjs/index-Dw43Hj4v.d.ts.map +1 -0
  25. package/cjs/index-Dy8UARqO.d.ts +72 -0
  26. package/cjs/index-Dy8UARqO.d.ts.map +1 -0
  27. package/cjs/index.d.ts +26 -36
  28. package/cjs/index.d.ts.map +1 -1
  29. package/cjs/index.js +83 -62
  30. package/cjs/index.js.map +1 -1
  31. package/cjs/legacy/index.d.ts +2 -0
  32. package/cjs/legacy/index.js +75 -0
  33. package/cjs/legacy/index.js.map +1 -0
  34. package/cjs/mix-Cs4owSbW.js +158 -0
  35. package/cjs/mix-Cs4owSbW.js.map +1 -0
  36. package/cjs/mix-DGlKoUw4.d.ts +31 -0
  37. package/cjs/mix-DGlKoUw4.d.ts.map +1 -0
  38. package/cjs/palette/index.d.ts +3 -0
  39. package/cjs/palette/index.js +8 -0
  40. package/cjs/palette-DyFV_KoJ.js +332 -0
  41. package/cjs/palette-DyFV_KoJ.js.map +1 -0
  42. package/cjs/parse-8mt2OMKf.js +1508 -0
  43. package/cjs/parse-8mt2OMKf.js.map +1 -0
  44. package/cjs/scale/index.d.ts +2 -0
  45. package/cjs/scale/index.js +11 -0
  46. package/cjs/scale-Cq9pXrc1.js +318 -0
  47. package/cjs/scale-Cq9pXrc1.js.map +1 -0
  48. package/cjs/semantic-CrEIo8tS.d.ts +52 -0
  49. package/cjs/semantic-CrEIo8tS.d.ts.map +1 -0
  50. package/cjs/serialize-C69DAmoE.d.ts +25 -0
  51. package/cjs/serialize-C69DAmoE.d.ts.map +1 -0
  52. package/cjs/serialize-Ci2X0cPN.js +103 -0
  53. package/cjs/serialize-Ci2X0cPN.js.map +1 -0
  54. package/cjs/tokens/index.d.ts +2 -0
  55. package/cjs/tokens/index.js +6 -0
  56. package/cjs/tokens-CzXxaMgM.js +168 -0
  57. package/cjs/tokens-CzXxaMgM.js.map +1 -0
  58. package/cjs/tone-BAhu-QzQ.js +118 -0
  59. package/cjs/tone-BAhu-QzQ.js.map +1 -0
  60. package/dist/color-map.es5.js.map +1 -1
  61. package/esm/color/a98-rgb.d.ts +7 -0
  62. package/esm/color/a98-rgb.d.ts.map +1 -0
  63. package/esm/color/a98-rgb.js +13 -0
  64. package/esm/color/a98-rgb.js.map +1 -0
  65. package/esm/color/argb.d.ts +6 -0
  66. package/esm/color/argb.d.ts.map +1 -0
  67. package/esm/color/argb.js +25 -0
  68. package/esm/color/argb.js.map +1 -0
  69. package/esm/color/calc.js +82 -0
  70. package/esm/color/calc.js.map +1 -0
  71. package/esm/color/compare.d.ts +20 -0
  72. package/esm/color/compare.d.ts.map +1 -0
  73. package/esm/color/compare.js +46 -0
  74. package/esm/color/compare.js.map +1 -0
  75. package/esm/color/contrast.d.ts +107 -0
  76. package/esm/color/contrast.d.ts.map +1 -0
  77. package/esm/color/contrast.js +242 -0
  78. package/esm/color/contrast.js.map +1 -0
  79. package/esm/color/convert.d.ts +9 -0
  80. package/esm/color/convert.d.ts.map +1 -0
  81. package/esm/color/convert.js +45 -0
  82. package/esm/color/convert.js.map +1 -0
  83. package/esm/color/display-p3-linear.d.ts +7 -0
  84. package/esm/color/display-p3-linear.d.ts.map +1 -0
  85. package/esm/color/display-p3-linear.js +12 -0
  86. package/esm/color/display-p3-linear.js.map +1 -0
  87. package/esm/color/display-p3.d.ts +7 -0
  88. package/esm/color/display-p3.d.ts.map +1 -0
  89. package/esm/color/display-p3.js +12 -0
  90. package/esm/color/display-p3.js.map +1 -0
  91. package/esm/color/expr.d.ts +43 -0
  92. package/esm/color/expr.d.ts.map +1 -0
  93. package/esm/color/expr.js +160 -0
  94. package/esm/color/expr.js.map +1 -0
  95. package/esm/color/gamut.d.ts +31 -0
  96. package/esm/color/gamut.d.ts.map +1 -0
  97. package/esm/color/gamut.js +210 -0
  98. package/esm/color/gamut.js.map +1 -0
  99. package/esm/color/hsl.d.ts +7 -0
  100. package/esm/color/hsl.d.ts.map +1 -0
  101. package/esm/color/hsl.js +67 -0
  102. package/esm/color/hsl.js.map +1 -0
  103. package/esm/color/hwb.d.ts +7 -0
  104. package/esm/color/hwb.d.ts.map +1 -0
  105. package/esm/color/hwb.js +40 -0
  106. package/esm/color/hwb.js.map +1 -0
  107. package/esm/color/index.d.ts +28 -0
  108. package/esm/color/index.js +27 -0
  109. package/esm/color/lab.d.ts +7 -0
  110. package/esm/color/lab.d.ts.map +1 -0
  111. package/esm/color/lab.js +33 -0
  112. package/esm/color/lab.js.map +1 -0
  113. package/esm/color/lch.d.ts +7 -0
  114. package/esm/color/lch.d.ts.map +1 -0
  115. package/esm/color/lch.js +11 -0
  116. package/esm/color/lch.js.map +1 -0
  117. package/esm/color/math.js +32 -0
  118. package/esm/color/math.js.map +1 -0
  119. package/esm/color/matrices.js +180 -0
  120. package/esm/color/matrices.js.map +1 -0
  121. package/esm/color/mix.d.ts +30 -0
  122. package/esm/color/mix.d.ts.map +1 -0
  123. package/esm/color/mix.js +152 -0
  124. package/esm/color/mix.js.map +1 -0
  125. package/esm/color/named.js +11 -0
  126. package/esm/color/named.js.map +1 -0
  127. package/esm/color/oklab.d.ts +7 -0
  128. package/esm/color/oklab.d.ts.map +1 -0
  129. package/esm/color/oklab.js +21 -0
  130. package/esm/color/oklab.js.map +1 -0
  131. package/esm/color/oklch.d.ts +7 -0
  132. package/esm/color/oklch.d.ts.map +1 -0
  133. package/esm/color/oklch.js +11 -0
  134. package/esm/color/oklch.js.map +1 -0
  135. package/esm/color/parse.d.ts +9 -0
  136. package/esm/color/parse.d.ts.map +1 -0
  137. package/esm/color/parse.js +452 -0
  138. package/esm/color/parse.js.map +1 -0
  139. package/esm/color/polar.js +27 -0
  140. package/esm/color/polar.js.map +1 -0
  141. package/esm/color/prophoto-rgb.d.ts +7 -0
  142. package/esm/color/prophoto-rgb.d.ts.map +1 -0
  143. package/esm/color/prophoto-rgb.js +18 -0
  144. package/esm/color/prophoto-rgb.js.map +1 -0
  145. package/esm/color/rec2020.d.ts +7 -0
  146. package/esm/color/rec2020.d.ts.map +1 -0
  147. package/esm/color/rec2020.js +13 -0
  148. package/esm/color/rec2020.js.map +1 -0
  149. package/esm/color/resolve.d.ts +18 -0
  150. package/esm/color/resolve.d.ts.map +1 -0
  151. package/esm/color/resolve.js +98 -0
  152. package/esm/color/resolve.js.map +1 -0
  153. package/esm/color/rgb.js +20 -0
  154. package/esm/color/rgb.js.map +1 -0
  155. package/esm/color/serialize.d.ts +24 -0
  156. package/esm/color/serialize.d.ts.map +1 -0
  157. package/esm/color/serialize.js +88 -0
  158. package/esm/color/serialize.js.map +1 -0
  159. package/esm/color/spaces.d.ts +6 -0
  160. package/esm/color/spaces.d.ts.map +1 -0
  161. package/esm/color/spaces.js +42 -0
  162. package/esm/color/spaces.js.map +1 -0
  163. package/esm/color/srgb-linear.d.ts +7 -0
  164. package/esm/color/srgb-linear.d.ts.map +1 -0
  165. package/esm/color/srgb-linear.js +12 -0
  166. package/esm/color/srgb-linear.js.map +1 -0
  167. package/esm/color/srgb.d.ts +7 -0
  168. package/esm/color/srgb.d.ts.map +1 -0
  169. package/esm/color/srgb.js +12 -0
  170. package/esm/color/srgb.js.map +1 -0
  171. package/esm/color/transfer.js +11 -0
  172. package/esm/color/transfer.js.map +1 -0
  173. package/esm/color/types.d.ts +23 -0
  174. package/esm/color/types.d.ts.map +1 -0
  175. package/esm/color/unknown-name.js +16 -0
  176. package/esm/color/unknown-name.js.map +1 -0
  177. package/esm/color/xyz-d50.d.ts +7 -0
  178. package/esm/color/xyz-d50.d.ts.map +1 -0
  179. package/esm/color/xyz-d50.js +15 -0
  180. package/esm/color/xyz-d50.js.map +1 -0
  181. package/esm/color/xyz-d65.d.ts +4 -0
  182. package/esm/color/xyz-d65.d.ts.map +1 -0
  183. package/esm/color/xyz-d65.js +10 -0
  184. package/esm/color/xyz-d65.js.map +1 -0
  185. package/esm/index.d.ts +63 -6
  186. package/esm/index.d.ts.map +1 -0
  187. package/esm/index.js +54 -5
  188. package/esm/index.js.map +1 -0
  189. package/esm/legacy/createColors.d.ts +9 -0
  190. package/esm/legacy/createColors.d.ts.map +1 -0
  191. package/esm/{createColors.js → legacy/createColors.js} +7 -2
  192. package/esm/legacy/createColors.js.map +1 -0
  193. package/esm/legacy/createColorsFromMap.d.ts +9 -0
  194. package/esm/legacy/createColorsFromMap.d.ts.map +1 -0
  195. package/esm/{createColorsFromMap.js → legacy/createColorsFromMap.js} +4 -2
  196. package/esm/legacy/createColorsFromMap.js.map +1 -0
  197. package/esm/legacy/index.d.ts +6 -0
  198. package/esm/legacy/index.js +5 -0
  199. package/esm/legacy/interfaces.d.ts +19 -0
  200. package/esm/legacy/interfaces.d.ts.map +1 -0
  201. package/esm/{rgbHex.d.ts → legacy/rgbHex.d.ts} +1 -4
  202. package/esm/legacy/rgbHex.d.ts.map +1 -0
  203. package/esm/{rgbHex.js → legacy/rgbHex.js} +1 -2
  204. package/esm/legacy/rgbHex.js.map +1 -0
  205. package/esm/legacy/rgbaString.d.ts +4 -0
  206. package/esm/{rgbaString.d.ts.map → legacy/rgbaString.d.ts.map} +1 -1
  207. package/esm/legacy/rgbaString.js +8 -0
  208. package/esm/legacy/rgbaString.js.map +1 -0
  209. package/esm/palette/dark.d.ts +23 -0
  210. package/esm/palette/dark.d.ts.map +1 -0
  211. package/esm/palette/dark.js +54 -0
  212. package/esm/palette/dark.js.map +1 -0
  213. package/esm/palette/harmony.d.ts +56 -0
  214. package/esm/palette/harmony.d.ts.map +1 -0
  215. package/esm/palette/harmony.js +115 -0
  216. package/esm/palette/harmony.js.map +1 -0
  217. package/esm/palette/index.d.ts +5 -0
  218. package/esm/palette/index.js +5 -0
  219. package/esm/palette/semantic.d.ts +53 -0
  220. package/esm/palette/semantic.d.ts.map +1 -0
  221. package/esm/palette/semantic.js +96 -0
  222. package/esm/palette/semantic.js.map +1 -0
  223. package/esm/palette/validate.d.ts +39 -0
  224. package/esm/palette/validate.d.ts.map +1 -0
  225. package/esm/palette/validate.js +56 -0
  226. package/esm/palette/validate.js.map +1 -0
  227. package/esm/scale/brand.d.ts +21 -0
  228. package/esm/scale/brand.d.ts.map +1 -0
  229. package/esm/scale/brand.js +63 -0
  230. package/esm/scale/brand.js.map +1 -0
  231. package/esm/scale/contrast-scale.d.ts +33 -0
  232. package/esm/scale/contrast-scale.d.ts.map +1 -0
  233. package/esm/scale/contrast-scale.js +26 -0
  234. package/esm/scale/contrast-scale.js.map +1 -0
  235. package/esm/scale/gradient.d.ts +38 -0
  236. package/esm/scale/gradient.d.ts.map +1 -0
  237. package/esm/scale/gradient.js +73 -0
  238. package/esm/scale/gradient.js.map +1 -0
  239. package/esm/scale/index.d.ts +6 -0
  240. package/esm/scale/index.js +6 -0
  241. package/esm/scale/scale.d.ts +31 -0
  242. package/esm/scale/scale.d.ts.map +1 -0
  243. package/esm/scale/scale.js +152 -0
  244. package/esm/scale/scale.js.map +1 -0
  245. package/esm/scale/tone.d.ts +25 -0
  246. package/esm/scale/tone.d.ts.map +1 -0
  247. package/esm/scale/tone.js +96 -0
  248. package/esm/scale/tone.js.map +1 -0
  249. package/esm/tokens/css.d.ts +18 -0
  250. package/esm/tokens/css.d.ts.map +1 -0
  251. package/esm/tokens/css.js +23 -0
  252. package/esm/tokens/css.js.map +1 -0
  253. package/esm/tokens/dtcg.d.ts +33 -0
  254. package/esm/tokens/dtcg.d.ts.map +1 -0
  255. package/esm/tokens/dtcg.js +42 -0
  256. package/esm/tokens/dtcg.js.map +1 -0
  257. package/esm/tokens/index.d.ts +5 -0
  258. package/esm/tokens/index.js +4 -0
  259. package/esm/tokens/tailwind.d.ts +19 -0
  260. package/esm/tokens/tailwind.d.ts.map +1 -0
  261. package/esm/tokens/tailwind.js +19 -0
  262. package/esm/tokens/tailwind.js.map +1 -0
  263. package/esm/tokens/tokens.d.ts +11 -0
  264. package/esm/tokens/tokens.d.ts.map +1 -0
  265. package/esm/tokens/tokens.js +77 -0
  266. package/esm/tokens/tokens.js.map +1 -0
  267. package/llms.txt +29 -0
  268. package/package.json +276 -64
  269. package/plugin.json +18 -0
  270. package/schemas/contrast.schema.json +24 -0
  271. package/schemas/convert.schema.json +60 -0
  272. package/schemas/export.schema.json +106 -0
  273. package/schemas/find-contrast.schema.json +51 -0
  274. package/schemas/harmony.schema.json +58 -0
  275. package/schemas/mix.schema.json +72 -0
  276. package/schemas/palette.schema.json +56 -0
  277. package/schemas/scale.schema.json +86 -0
  278. package/skills/color-map/SKILL.md +38 -0
  279. package/src/cli/bin.ts +11 -0
  280. package/src/cli/cli.ts +40 -0
  281. package/src/cli/commands/contrast.ts +36 -0
  282. package/src/cli/commands/convert.ts +37 -0
  283. package/src/cli/commands/export.ts +102 -0
  284. package/src/cli/commands/find-contrast.ts +37 -0
  285. package/src/cli/commands/harmony.ts +30 -0
  286. package/src/cli/commands/mix.ts +29 -0
  287. package/src/cli/commands/palette.ts +66 -0
  288. package/src/cli/commands/scale.ts +75 -0
  289. package/src/cli/index.ts +2 -0
  290. package/src/cli/schema-command.ts +31 -0
  291. package/src/cli/schemas.ts +86 -0
  292. package/src/cli/shared.ts +72 -0
  293. package/src/cli/testing.ts +27 -0
  294. package/src/color/a98-rgb.ts +11 -0
  295. package/src/color/argb.ts +21 -0
  296. package/src/color/calc.ts +84 -0
  297. package/src/color/compare.ts +53 -0
  298. package/src/color/contrast.ts +277 -0
  299. package/src/color/convert.ts +43 -0
  300. package/src/color/display-p3-linear.ts +9 -0
  301. package/src/color/display-p3.ts +9 -0
  302. package/src/color/expr.ts +158 -0
  303. package/src/color/gamut.ts +215 -0
  304. package/src/color/hsl.ts +57 -0
  305. package/src/color/hwb.ts +26 -0
  306. package/src/color/index.ts +43 -0
  307. package/src/color/lab.ts +29 -0
  308. package/src/color/lch.ts +8 -0
  309. package/src/color/math.ts +30 -0
  310. package/src/color/matrices.ts +91 -0
  311. package/src/color/mix.ts +158 -0
  312. package/src/color/named.ts +13 -0
  313. package/src/color/oklab.ts +19 -0
  314. package/src/color/oklch.ts +8 -0
  315. package/src/color/parse.ts +355 -0
  316. package/src/color/polar.ts +17 -0
  317. package/src/color/prophoto-rgb.ts +18 -0
  318. package/src/color/rec2020.ts +11 -0
  319. package/src/color/resolve.ts +87 -0
  320. package/src/color/rgb.ts +20 -0
  321. package/src/color/serialize.ts +96 -0
  322. package/src/color/spaces.ts +42 -0
  323. package/src/color/srgb-linear.ts +9 -0
  324. package/src/color/srgb.ts +9 -0
  325. package/src/color/test-utils.ts +10 -0
  326. package/src/color/transfer.ts +14 -0
  327. package/src/color/types.ts +41 -0
  328. package/src/color/unknown-name.ts +15 -0
  329. package/src/color/xyz-d50.ts +13 -0
  330. package/src/color/xyz-d65.ts +8 -0
  331. package/src/index.ts +37 -0
  332. package/{ts → src/legacy}/createColors.ts +6 -0
  333. package/{ts → src/legacy}/createColorsFromMap.ts +3 -0
  334. package/{ts → src/legacy}/interfaces.ts +4 -0
  335. package/{ts → src/legacy}/rgbaString.ts +1 -0
  336. package/src/palette/dark.ts +55 -0
  337. package/src/palette/harmony.ts +107 -0
  338. package/src/palette/index.ts +18 -0
  339. package/src/palette/semantic.ts +120 -0
  340. package/src/palette/validate.ts +82 -0
  341. package/src/scale/brand.ts +50 -0
  342. package/src/scale/contrast-scale.ts +48 -0
  343. package/src/scale/gradient.ts +91 -0
  344. package/src/scale/index.ts +5 -0
  345. package/src/scale/scale.ts +127 -0
  346. package/src/scale/tone.ts +69 -0
  347. package/src/tokens/css.ts +32 -0
  348. package/src/tokens/dtcg.ts +62 -0
  349. package/src/tokens/index.ts +11 -0
  350. package/src/tokens/tailwind.ts +24 -0
  351. package/src/tokens/tokens.ts +82 -0
  352. package/esm/createColors.d.ts +0 -6
  353. package/esm/createColors.d.ts.map +0 -1
  354. package/esm/createColors.js.map +0 -1
  355. package/esm/createColorsFromMap.d.ts +0 -9
  356. package/esm/createColorsFromMap.d.ts.map +0 -1
  357. package/esm/createColorsFromMap.js.map +0 -1
  358. package/esm/interfaces.d.ts +0 -18
  359. package/esm/interfaces.d.ts.map +0 -1
  360. package/esm/rgbHex.d.ts.map +0 -1
  361. package/esm/rgbHex.js.map +0 -1
  362. package/esm/rgbaString.d.ts +0 -6
  363. package/esm/rgbaString.js +0 -8
  364. package/esm/rgbaString.js.map +0 -1
  365. /package/{ts → src/legacy}/index.ts +0 -0
  366. /package/{ts → src/legacy}/rgbHex.ts +0 -0
@@ -0,0 +1,28 @@
1
+ import { a98Rgb } from "./a98-rgb.js";
2
+ import { fromArgb, toArgb } from "./argb.js";
3
+ import { createDeltaEOk, createEquals, deltaEOk, equals } from "./compare.js";
4
+ import { ContrastAlgorithm, ContrastFn, ContrastOption, FindContrastOptions, FoundContrast, OnColorOptions, contrast, createContrast, createFindContrast, createMeets, createOnColor, findContrast, meets, onColor, wcag2 } from "./contrast.js";
5
+ import { convertComponents, createConverter } from "./convert.js";
6
+ import { displayP3 } from "./display-p3.js";
7
+ import { displayP3Linear } from "./display-p3-linear.js";
8
+ import { ColorExpr, parseExpr } from "./expr.js";
9
+ import { GamutId, ToGamutOptions, createInGamut, createToGamut, inGamut, toGamut } from "./gamut.js";
10
+ import { hsl } from "./hsl.js";
11
+ import { hwb } from "./hwb.js";
12
+ import { lab } from "./lab.js";
13
+ import { lch } from "./lch.js";
14
+ import { HueMethod, MixOptions, createMix, mix } from "./mix.js";
15
+ import { oklab } from "./oklab.js";
16
+ import { oklch } from "./oklch.js";
17
+ import { parse } from "./parse.js";
18
+ import { prophotoRgb } from "./prophoto-rgb.js";
19
+ import { rec2020 } from "./rec2020.js";
20
+ import { ResolveContext, resolve } from "./resolve.js";
21
+ import { ToCssOptions, createToHex, toCss, toHex } from "./serialize.js";
22
+ import { convert, spaces } from "./spaces.js";
23
+ import { srgb } from "./srgb.js";
24
+ import { srgbLinear } from "./srgb-linear.js";
25
+ import { Color, ColorSpaceId, Component, Space, Vec3 } from "./types.js";
26
+ import { xyzD50 } from "./xyz-d50.js";
27
+ import { xyzD65 } from "./xyz-d65.js";
28
+ export { type Color, type ColorExpr, type ColorSpaceId, type Component, type ContrastAlgorithm, type ContrastFn, type ContrastOption, type FindContrastOptions, type FoundContrast, type GamutId, type HueMethod, type MixOptions, type OnColorOptions, type ResolveContext, type Space, type ToCssOptions, type ToGamutOptions, type Vec3, a98Rgb, contrast, convert, convertComponents, createContrast, createConverter, createDeltaEOk, createEquals, createFindContrast, createInGamut, createMeets, createMix, createOnColor, createToGamut, createToHex, deltaEOk, displayP3, displayP3Linear, equals, findContrast, fromArgb, hsl, hwb, inGamut, lab, lch, meets, mix, oklab, oklch, onColor, parse, parseExpr, prophotoRgb, rec2020, resolve, spaces, srgb, srgbLinear, toArgb, toCss, toGamut, toHex, wcag2, xyzD50, xyzD65 };
@@ -0,0 +1,27 @@
1
+ import { a98Rgb } from "./a98-rgb.js";
2
+ import { fromArgb, toArgb } from "./argb.js";
3
+ import { createDeltaEOk, createEquals, deltaEOk, equals } from "./compare.js";
4
+ import { contrast, createContrast, createFindContrast, createMeets, createOnColor, findContrast, meets, onColor, wcag2 } from "./contrast.js";
5
+ import { convertComponents, createConverter } from "./convert.js";
6
+ import { displayP3 } from "./display-p3.js";
7
+ import { displayP3Linear } from "./display-p3-linear.js";
8
+ import { parseExpr } from "./expr.js";
9
+ import { createInGamut, createToGamut, inGamut, toGamut } from "./gamut.js";
10
+ import { hsl } from "./hsl.js";
11
+ import { hwb } from "./hwb.js";
12
+ import { lab } from "./lab.js";
13
+ import { lch } from "./lch.js";
14
+ import { createMix, mix } from "./mix.js";
15
+ import { oklab } from "./oklab.js";
16
+ import { oklch } from "./oklch.js";
17
+ import { parse } from "./parse.js";
18
+ import { prophotoRgb } from "./prophoto-rgb.js";
19
+ import { rec2020 } from "./rec2020.js";
20
+ import { resolve } from "./resolve.js";
21
+ import { createToHex, toCss, toHex } from "./serialize.js";
22
+ import { convert, spaces } from "./spaces.js";
23
+ import { srgb } from "./srgb.js";
24
+ import { srgbLinear } from "./srgb-linear.js";
25
+ import { xyzD50 } from "./xyz-d50.js";
26
+ import { xyzD65 } from "./xyz-d65.js";
27
+ export { a98Rgb, contrast, convert, convertComponents, createContrast, createConverter, createDeltaEOk, createEquals, createFindContrast, createInGamut, createMeets, createMix, createOnColor, createToGamut, createToHex, deltaEOk, displayP3, displayP3Linear, equals, findContrast, fromArgb, hsl, hwb, inGamut, lab, lch, meets, mix, oklab, oklch, onColor, parse, parseExpr, prophotoRgb, rec2020, resolve, spaces, srgb, srgbLinear, toArgb, toCss, toGamut, toHex, wcag2, xyzD50, xyzD65 };
@@ -0,0 +1,7 @@
1
+ import { Space } from "./types.js";
2
+ /**
3
+ * The CSS `lab` space (CIE Lab, D50 white). Components are lightness in 0 to 100, then the a and b axes, which are not bounded but stay near -125 to 125 for real colors.
4
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
5
+ */
6
+ export declare const lab: Space;
7
+ //# sourceMappingURL=lab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lab.d.ts","names":[],"sources":["../../src/color/lab.ts"],"mappings":";;;;;qBAca,KAAK"}
@@ -0,0 +1,33 @@
1
+ import { D50, multiply } from "./math.js";
2
+ import { d50ToD65, d65ToD50 } from "./matrices.js";
3
+ // src/color/lab.ts
4
+ const EPSILON = 216 / 24389;
5
+ const KAPPA = 24389 / 27;
6
+ const finv = (f) => f ** 3 > EPSILON ? f ** 3 : (116 * f - 16) / KAPPA;
7
+ const forward = (v) => v > EPSILON ? Math.cbrt(v) : (KAPPA * v + 16) / 116;
8
+ /**
9
+ * The CSS `lab` space (CIE Lab, D50 white). Components are lightness in 0 to 100, then the a and b axes, which are not bounded but stay near -125 to 125 for real colors.
10
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
11
+ */
12
+ const lab = {
13
+ id: "lab",
14
+ toXyz: ([l, a, b]) => {
15
+ const fy = (l + 16) / 116;
16
+ const y = l > KAPPA * EPSILON ? fy ** 3 : l / KAPPA;
17
+ const x = finv(fy + a / 500);
18
+ const z = finv(fy - b / 200);
19
+ return multiply(d50ToD65, x * D50[0], y * D50[1], z * D50[2]);
20
+ },
21
+ fromXyz: (xyz) => {
22
+ const [x, y, z] = multiply(d65ToD50, xyz[0], xyz[1], xyz[2]);
23
+ const fy = forward(y / D50[1]);
24
+ return [
25
+ 116 * fy - 16,
26
+ 500 * (forward(x / D50[0]) - fy),
27
+ 200 * (fy - forward(z / D50[2]))
28
+ ];
29
+ }
30
+ };
31
+ export { lab };
32
+
33
+ //# sourceMappingURL=lab.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lab.js","names":[],"sources":["../../src/color/lab.ts"],"sourcesContent":["import { D50, multiply } from './math.js'\nimport { d50ToD65, d65ToD50 } from './matrices.js'\nimport type { Space } from './types.js'\n\nconst EPSILON = 216 / 24389\nconst KAPPA = 24389 / 27\n\nconst finv = (f: number): number => (f ** 3 > EPSILON ? f ** 3 : (116 * f - 16) / KAPPA)\nconst forward = (v: number): number => (v > EPSILON ? Math.cbrt(v) : (KAPPA * v + 16) / 116)\n\n/**\n * The CSS `lab` space (CIE Lab, D50 white). Components are lightness in 0 to 100, then the a and b axes, which are not bounded but stay near -125 to 125 for real colors.\n * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.\n */\nexport const lab: Space = {\n\tid: 'lab',\n\ttoXyz: ([l, a, b]) => {\n\t\tconst fy = (l + 16) / 116\n\t\tconst y = l > KAPPA * EPSILON ? fy ** 3 : l / KAPPA\n\t\tconst x = finv(fy + a / 500)\n\t\tconst z = finv(fy - b / 200)\n\t\treturn multiply(d50ToD65, x * D50[0], y * D50[1], z * D50[2])\n\t},\n\tfromXyz: (xyz) => {\n\t\tconst [x, y, z] = multiply(d65ToD50, xyz[0], xyz[1], xyz[2])\n\t\tconst fy = forward(y / D50[1])\n\t\treturn [116 * fy - 16, 500 * (forward(x / D50[0]) - fy), 200 * (fy - forward(z / D50[2]))]\n\t}\n}\n"],"mappings":";;;AAIA,MAAM,UAAU,MAAM;AACtB,MAAM,QAAQ,QAAQ;AAEtB,MAAM,QAAQ,MAAuB,KAAK,IAAI,UAAU,KAAK,KAAK,MAAM,IAAI,MAAM;AAClF,MAAM,WAAW,MAAuB,IAAI,UAAU,KAAK,KAAK,CAAC,KAAK,QAAQ,IAAI,MAAM;;;;;AAMxF,MAAa,MAAa;CACzB,IAAI;CACJ,QAAQ,CAAC,GAAG,GAAG,OAAO;EACrB,MAAM,MAAM,IAAI,MAAM;EACtB,MAAM,IAAI,IAAI,QAAQ,UAAU,MAAM,IAAI,IAAI;EAC9C,MAAM,IAAI,KAAK,KAAK,IAAI,GAAG;EAC3B,MAAM,IAAI,KAAK,KAAK,IAAI,GAAG;EAC3B,OAAO,SAAS,UAAU,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;CAC7D;CACA,UAAU,QAAQ;EACjB,MAAM,CAAC,GAAG,GAAG,KAAK,SAAS,UAAU,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;EAC3D,MAAM,KAAK,QAAQ,IAAI,IAAI,EAAE;EAC7B,OAAO;GAAC,MAAM,KAAK;GAAI,OAAO,QAAQ,IAAI,IAAI,EAAE,IAAI;GAAK,OAAO,KAAK,QAAQ,IAAI,IAAI,EAAE;EAAE;CAC1F;AACD"}
@@ -0,0 +1,7 @@
1
+ import { Space } from "./types.js";
2
+ /**
3
+ * The CSS `lch` space, the polar form of `lab`. Components are lightness in 0 to 100, chroma (not bounded, about 0 to 150) and hue in degrees.
4
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
5
+ */
6
+ export declare const lch: Space;
7
+ //# sourceMappingURL=lch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lch.d.ts","names":["_$__types_js0.Space"],"sources":["../../src/color/lch.ts"],"mappings":";;;;;qBAOa,KAAAA"}
@@ -0,0 +1,11 @@
1
+ import { lab } from "./lab.js";
2
+ import { polarSpace } from "./polar.js";
3
+ // src/color/lch.ts
4
+ /**
5
+ * The CSS `lch` space, the polar form of `lab`. Components are lightness in 0 to 100, chroma (not bounded, about 0 to 150) and hue in degrees.
6
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
7
+ */
8
+ const lch = polarSpace("lch", lab);
9
+ export { lch };
10
+
11
+ //# sourceMappingURL=lch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lch.js","names":[],"sources":["../../src/color/lch.ts"],"sourcesContent":["import { lab } from './lab.js'\nimport { polarSpace } from './polar.js'\n\n/**\n * The CSS `lch` space, the polar form of `lab`. Components are lightness in 0 to 100, chroma (not bounded, about 0 to 150) and hue in degrees.\n * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.\n */\nexport const lch = polarSpace('lch', lab)\n"],"mappings":";;;;;;;AAOA,MAAa,MAAM,WAAW,OAAO,GAAG"}
@@ -0,0 +1,32 @@
1
+ // src/color/math.ts
2
+ /** `m` times the column vector (x, y, z). Takes numbers rather than a Vec3, so callers need no array. */
3
+ function multiply(m, x, y, z) {
4
+ return [
5
+ m[0] * x + m[1] * y + m[2] * z,
6
+ m[3] * x + m[4] * y + m[5] * z,
7
+ m[6] * x + m[7] * y + m[8] * z
8
+ ];
9
+ }
10
+ /** Keeps the sign, so out-of-gamut values survive the transfer function. */
11
+ function signed(f) {
12
+ return (n) => n < 0 ? -f(-n) : f(n);
13
+ }
14
+ function normalizeHue(h) {
15
+ return (h % 360 + 360) % 360;
16
+ }
17
+ const D50 = [
18
+ .3457 / .3585,
19
+ 1,
20
+ .2958 / .3585
21
+ ];
22
+ /** The product of 3x3 matrices, left to right: `product(a, b)` applies `b` first. */
23
+ function product(...ms) {
24
+ return ms.reduce((a, b) => {
25
+ const out = [];
26
+ for (let i = 0; i < 3; i++) for (let j = 0; j < 3; j++) out.push(a[i * 3] * b[j] + a[i * 3 + 1] * b[3 + j] + a[i * 3 + 2] * b[6 + j]);
27
+ return out;
28
+ });
29
+ }
30
+ export { D50, multiply, normalizeHue, product, signed };
31
+
32
+ //# sourceMappingURL=math.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.js","names":[],"sources":["../../src/color/math.ts"],"sourcesContent":["import type { Vec3 } from './types.js'\n\n/** A 3x3 matrix, flat, row by row. */\nexport type Matrix = readonly [number, number, number, number, number, number, number, number, number]\n\n/** `m` times the column vector (x, y, z). Takes numbers rather than a Vec3, so callers need no array. */\nexport function multiply(m: Matrix, x: number, y: number, z: number): Vec3 {\n\treturn [m[0] * x + m[1] * y + m[2] * z, m[3] * x + m[4] * y + m[5] * z, m[6] * x + m[7] * y + m[8] * z]\n}\n\n/** Keeps the sign, so out-of-gamut values survive the transfer function. */\nexport function signed(f: (abs: number) => number): (n: number) => number {\n\treturn (n) => (n < 0 ? -f(-n) : f(n))\n}\n\nexport function normalizeHue(h: number): number {\n\treturn ((h % 360) + 360) % 360\n}\n\nexport const D50: Vec3 = [0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585]\n\n/** The product of 3x3 matrices, left to right: `product(a, b)` applies `b` first. */\nexport function product(...ms: Matrix[]): Matrix {\n\treturn ms.reduce((a, b) => {\n\t\tconst out: number[] = []\n\t\tfor (let i = 0; i < 3; i++)\n\t\t\tfor (let j = 0; j < 3; j++) out.push(a[i * 3] * b[j] + a[i * 3 + 1] * b[3 + j] + a[i * 3 + 2] * b[6 + j])\n\t\treturn out as unknown as Matrix\n\t})\n}\n"],"mappings":";;AAMA,SAAgB,SAAS,GAAW,GAAW,GAAW,GAAiB;CAC1E,OAAO;EAAC,EAAE,KAAK,IAAI,EAAE,KAAK,IAAI,EAAE,KAAK;EAAG,EAAE,KAAK,IAAI,EAAE,KAAK,IAAI,EAAE,KAAK;EAAG,EAAE,KAAK,IAAI,EAAE,KAAK,IAAI,EAAE,KAAK;CAAC;AACvG;;AAGA,SAAgB,OAAO,GAAmD;CACzE,QAAQ,MAAO,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACpC;AAEA,SAAgB,aAAa,GAAmB;CAC/C,QAAS,IAAI,MAAO,OAAO;AAC5B;AAEA,MAAa,MAAY;CAAC,QAAS;CAAQ;CAAI,QAAuB;AAAM;;AAG5E,SAAgB,QAAQ,GAAG,IAAsB;CAChD,OAAO,GAAG,QAAQ,GAAG,MAAM;EAC1B,MAAM,MAAgB,CAAC;EACvB,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KACtB,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK,IAAI,KAAK,EAAE,IAAI,KAAK,EAAE,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,IAAI,EAAE;EACzG,OAAO;CACR,CAAC;AACF"}
@@ -0,0 +1,180 @@
1
+ // src/color/matrices.ts
2
+ const srgbToXyz = [
3
+ 506752 / 1228815,
4
+ 87881 / 245763,
5
+ 12673 / 70218,
6
+ 87098 / 409605,
7
+ 175762 / 245763,
8
+ 12673 / 175545,
9
+ 7918 / 409605,
10
+ 87881 / 737289,
11
+ 1001167 / 1053270
12
+ ];
13
+ const xyzToSrgb = [
14
+ 12831 / 3959,
15
+ -329 / 214,
16
+ -1974 / 3959,
17
+ -851781 / 878810,
18
+ 1648619 / 878810,
19
+ 36519 / 878810,
20
+ 705 / 12673,
21
+ -2585 / 12673,
22
+ 705 / 667
23
+ ];
24
+ const p3ToXyz = [
25
+ 608311 / 1250200,
26
+ 189793 / 714400,
27
+ 198249 / 1000160,
28
+ 35783 / 156275,
29
+ 247089 / 357200,
30
+ 198249 / 2500400,
31
+ 0,
32
+ 32229 / 714400,
33
+ 5220557 / 5000800
34
+ ];
35
+ const xyzToP3 = [
36
+ 446124 / 178915,
37
+ -333277 / 357830,
38
+ -72051 / 178915,
39
+ -14852 / 17905,
40
+ 63121 / 35810,
41
+ 423 / 17905,
42
+ 11844 / 330415,
43
+ -50337 / 660830,
44
+ 316169 / 330415
45
+ ];
46
+ const a98ToXyz = [
47
+ 573536 / 994567,
48
+ 263643 / 1420810,
49
+ 187206 / 994567,
50
+ 591459 / 1989134,
51
+ 6239551 / 9945670,
52
+ 374412 / 4972835,
53
+ 53769 / 1989134,
54
+ 351524 / 4972835,
55
+ 4929758 / 4972835
56
+ ];
57
+ const xyzToA98 = [
58
+ 1829569 / 896150,
59
+ -506331 / 896150,
60
+ -308931 / 896150,
61
+ -851781 / 878810,
62
+ 1648619 / 878810,
63
+ 36519 / 878810,
64
+ 16779 / 1248040,
65
+ -147721 / 1248040,
66
+ 1266979 / 1248040
67
+ ];
68
+ const prophotoToXyzD50 = [
69
+ .7977666449006423,
70
+ .13518129740053308,
71
+ .0313477341283922,
72
+ .2880748288194013,
73
+ .711835234241873,
74
+ 8993693872564e-17,
75
+ 0,
76
+ 0,
77
+ .8251046025104602
78
+ ];
79
+ const xyzD50ToProphoto = [
80
+ 1.3457868816471583,
81
+ -.25557208737979464,
82
+ -.05110186497554526,
83
+ -.5446307051249019,
84
+ 1.5082477428451468,
85
+ .02052744743642139,
86
+ 0,
87
+ 0,
88
+ 1.2119675456389452
89
+ ];
90
+ const rec2020ToXyz = [
91
+ 63426534 / 99577255,
92
+ 20160776 / 139408157,
93
+ 47086771 / 278816314,
94
+ 26158966 / 99577255,
95
+ 472592308 / 697040785,
96
+ 8267143 / 139408157,
97
+ 0,
98
+ 19567812 / 697040785,
99
+ 295819943 / 278816314
100
+ ];
101
+ const xyzToRec2020 = [
102
+ 30757411 / 17917100,
103
+ -6372589 / 17917100,
104
+ -4539589 / 17917100,
105
+ -19765991 / 29648200,
106
+ 47925759 / 29648200,
107
+ 467509 / 29648200,
108
+ 792561 / 44930125,
109
+ -1921689 / 44930125,
110
+ 42328811 / 44930125
111
+ ];
112
+ const d65ToD50 = [
113
+ 1.0479297925449969,
114
+ .022946870601609652,
115
+ -.05019226628920524,
116
+ .02962780877005599,
117
+ .9904344267538799,
118
+ -.017073799063418826,
119
+ -.009243040646204504,
120
+ .015055191490298152,
121
+ .7518742814281371
122
+ ];
123
+ const d50ToD65 = [
124
+ .955473421488075,
125
+ -.02309845494876471,
126
+ .06325924320057072,
127
+ -.0283697093338637,
128
+ 1.0099953980813041,
129
+ .021041441191917323,
130
+ .012314014864481998,
131
+ -.020507649298898964,
132
+ 1.330365926242124
133
+ ];
134
+ const xyzToLms = [
135
+ .819022437996703,
136
+ .3619062600528904,
137
+ -.1288737815209879,
138
+ .0329836539323885,
139
+ .9292868615863434,
140
+ .0361446663506424,
141
+ .0481771893596242,
142
+ .2642395317527308,
143
+ .6335478284694309
144
+ ];
145
+ const lmsToOklab = [
146
+ .210454268309314,
147
+ .7936177747023054,
148
+ -.0040720430116193,
149
+ 1.9779985324311684,
150
+ -2.42859224204858,
151
+ .450593709617411,
152
+ .0259040424655478,
153
+ .7827717124575296,
154
+ -.8086757549230774
155
+ ];
156
+ const lmsToXyz = [
157
+ 1.2268798758459243,
158
+ -.5578149944602171,
159
+ .2813910456659647,
160
+ -.0405757452148008,
161
+ 1.112286803280317,
162
+ -.0717110580655164,
163
+ -.0763729366746601,
164
+ -.4214933324022432,
165
+ 1.5869240198367816
166
+ ];
167
+ const oklabToLms = [
168
+ 1,
169
+ .3963377773761749,
170
+ .2158037573099136,
171
+ 1,
172
+ -.1055613458156586,
173
+ -.0638541728258133,
174
+ 1,
175
+ -.0894841775298119,
176
+ -1.2914855480194092
177
+ ];
178
+ export { a98ToXyz, d50ToD65, d65ToD50, lmsToOklab, lmsToXyz, oklabToLms, p3ToXyz, prophotoToXyzD50, rec2020ToXyz, srgbToXyz, xyzD50ToProphoto, xyzToA98, xyzToLms, xyzToP3, xyzToRec2020, xyzToSrgb };
179
+
180
+ //# sourceMappingURL=matrices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrices.js","names":[],"sources":["../../src/color/matrices.ts"],"sourcesContent":["// biome-ignore-all format: each matrix is written as its three rows\n// CSS Color 4, section 19 (sample code for color conversions). Each matrix is\n// flat, row by row.\nimport type { Matrix } from './math.js'\n\nexport const srgbToXyz: Matrix = [\n\t506752 / 1228815, 87881 / 245763, 12673 / 70218,\n\t87098 / 409605, 175762 / 245763, 12673 / 175545,\n\t7918 / 409605, 87881 / 737289, 1001167 / 1053270\n]\nexport const xyzToSrgb: Matrix = [\n\t12831 / 3959, -329 / 214, -1974 / 3959,\n\t-851781 / 878810, 1648619 / 878810, 36519 / 878810,\n\t705 / 12673, -2585 / 12673, 705 / 667\n]\n\nexport const p3ToXyz: Matrix = [\n\t608311 / 1250200, 189793 / 714400, 198249 / 1000160,\n\t35783 / 156275, 247089 / 357200, 198249 / 2500400,\n\t0, 32229 / 714400, 5220557 / 5000800\n]\nexport const xyzToP3: Matrix = [\n\t446124 / 178915, -333277 / 357830, -72051 / 178915,\n\t-14852 / 17905, 63121 / 35810, 423 / 17905,\n\t11844 / 330415, -50337 / 660830, 316169 / 330415\n]\n\nexport const a98ToXyz: Matrix = [\n\t573536 / 994567, 263643 / 1420810, 187206 / 994567,\n\t591459 / 1989134, 6239551 / 9945670, 374412 / 4972835,\n\t53769 / 1989134, 351524 / 4972835, 4929758 / 4972835\n]\nexport const xyzToA98: Matrix = [\n\t1829569 / 896150, -506331 / 896150, -308931 / 896150,\n\t-851781 / 878810, 1648619 / 878810, 36519 / 878810,\n\t16779 / 1248040, -147721 / 1248040, 1266979 / 1248040\n]\n\nexport const prophotoToXyzD50: Matrix = [\n\t0.7977666449006423, 0.13518129740053308, 0.0313477341283922,\n\t0.2880748288194013, 0.711835234241873, 0.00008993693872564,\n\t0, 0, 0.8251046025104602\n]\nexport const xyzD50ToProphoto: Matrix = [\n\t1.3457868816471583, -0.25557208737979464, -0.05110186497554526,\n\t-0.5446307051249019, 1.5082477428451468, 0.02052744743642139,\n\t0, 0, 1.2119675456389452\n]\n\nexport const rec2020ToXyz: Matrix = [\n\t63426534 / 99577255, 20160776 / 139408157, 47086771 / 278816314,\n\t26158966 / 99577255, 472592308 / 697040785, 8267143 / 139408157,\n\t0, 19567812 / 697040785, 295819943 / 278816314\n]\nexport const xyzToRec2020: Matrix = [\n\t30757411 / 17917100, -6372589 / 17917100, -4539589 / 17917100,\n\t-19765991 / 29648200, 47925759 / 29648200, 467509 / 29648200,\n\t792561 / 44930125, -1921689 / 44930125, 42328811 / 44930125\n]\n\nexport const d65ToD50: Matrix = [\n\t1.0479297925449969, 0.022946870601609652, -0.05019226628920524,\n\t0.02962780877005599, 0.9904344267538799, -0.017073799063418826,\n\t-0.009243040646204504, 0.015055191490298152, 0.7518742814281371\n]\nexport const d50ToD65: Matrix = [\n\t0.955473421488075, -0.02309845494876471, 0.06325924320057072,\n\t-0.0283697093338637, 1.0099953980813041, 0.021041441191917323,\n\t0.012314014864481998, -0.020507649298898964, 1.330365926242124\n]\n\nexport const xyzToLms: Matrix = [\n\t0.819022437996703, 0.3619062600528904, -0.1288737815209879,\n\t0.0329836539323885, 0.9292868615863434, 0.0361446663506424,\n\t0.0481771893596242, 0.2642395317527308, 0.6335478284694309\n]\nexport const lmsToOklab: Matrix = [\n\t0.210454268309314, 0.7936177747023054, -0.0040720430116193,\n\t1.9779985324311684, -2.42859224204858, 0.450593709617411,\n\t0.0259040424655478, 0.7827717124575296, -0.8086757549230774\n]\nexport const lmsToXyz: Matrix = [\n\t1.2268798758459243, -0.5578149944602171, 0.2813910456659647,\n\t-0.0405757452148008, 1.112286803280317, -0.0717110580655164,\n\t-0.0763729366746601, -0.4214933324022432, 1.5869240198367816\n]\nexport const oklabToLms: Matrix = [\n\t1, 0.3963377773761749, 0.2158037573099136,\n\t1, -0.1055613458156586, -0.0638541728258133,\n\t1, -0.0894841775298119, -1.2914855480194092\n]\n"],"mappings":";AAKA,MAAa,YAAoB;CAChC,SAAS;CAAS,QAAQ;CAAQ,QAAQ;CAC1C,QAAQ;CAAQ,SAAS;CAAQ,QAAQ;CACzC,OAAO;CAAQ,QAAQ;CAAQ,UAAU;AAC1C;AACA,MAAa,YAAoB;CAChC,QAAQ;CAAM,OAAO;CAAK,QAAQ;CAClC,UAAU;CAAQ,UAAU;CAAQ,QAAQ;CAC5C,MAAM;CAAO,QAAQ;CAAO,MAAM;AACnC;AAEA,MAAa,UAAkB;CAC9B,SAAS;CAAS,SAAS;CAAQ,SAAS;CAC5C,QAAQ;CAAQ,SAAS;CAAQ,SAAS;CAC1C;CAAG,QAAQ;CAAQ,UAAU;AAC9B;AACA,MAAa,UAAkB;CAC9B,SAAS;CAAQ,UAAU;CAAQ,SAAS;CAC5C,SAAS;CAAO,QAAQ;CAAO,MAAM;CACrC,QAAQ;CAAQ,SAAS;CAAQ,SAAS;AAC3C;AAEA,MAAa,WAAmB;CAC/B,SAAS;CAAQ,SAAS;CAAS,SAAS;CAC5C,SAAS;CAAS,UAAU;CAAS,SAAS;CAC9C,QAAQ;CAAS,SAAS;CAAS,UAAU;AAC9C;AACA,MAAa,WAAmB;CAC/B,UAAU;CAAQ,UAAU;CAAQ,UAAU;CAC9C,UAAU;CAAQ,UAAU;CAAQ,QAAQ;CAC5C,QAAQ;CAAS,UAAU;CAAS,UAAU;AAC/C;AAEA,MAAa,mBAA2B;CACvC;CAAoB;CAAqB;CACzC;CAAoB;CAAmB;CACvC;CAAG;CAAG;AACP;AACA,MAAa,mBAA2B;CACvC;CAAoB;CAAsB;CAC1C;CAAqB;CAAoB;CACzC;CAAG;CAAG;AACP;AAEA,MAAa,eAAuB;CACnC,WAAW;CAAU,WAAW;CAAW,WAAW;CACtD,WAAW;CAAU,YAAY;CAAW,UAAU;CACtD;CAAG,WAAW;CAAW,YAAY;AACtC;AACA,MAAa,eAAuB;CACnC,WAAW;CAAU,WAAW;CAAU,WAAW;CACrD,YAAY;CAAU,WAAW;CAAU,SAAS;CACpD,SAAS;CAAU,WAAW;CAAU,WAAW;AACpD;AAEA,MAAa,WAAmB;CAC/B;CAAoB;CAAsB;CAC1C;CAAqB;CAAoB;CACzC;CAAuB;CAAsB;AAC9C;AACA,MAAa,WAAmB;CAC/B;CAAmB;CAAsB;CACzC;CAAqB;CAAoB;CACzC;CAAsB;CAAuB;AAC9C;AAEA,MAAa,WAAmB;CAC/B;CAAmB;CAAoB;CACvC;CAAoB;CAAoB;CACxC;CAAoB;CAAoB;AACzC;AACA,MAAa,aAAqB;CACjC;CAAmB;CAAoB;CACvC;CAAoB;CAAmB;CACvC;CAAoB;CAAoB;AACzC;AACA,MAAa,WAAmB;CAC/B;CAAoB;CAAqB;CACzC;CAAqB;CAAmB;CACxC;CAAqB;CAAqB;AAC3C;AACA,MAAa,aAAqB;CACjC;CAAG;CAAoB;CACvB;CAAG;CAAqB;CACxB;CAAG;CAAqB;AACzB"}
@@ -0,0 +1,30 @@
1
+ import { Color, ColorSpaceId, Space } from "./types.js";
2
+ /** How `mix` travels around the hue circle (CSS Color 4 section 12.4). */
3
+ export type HueMethod = 'shorter' | 'longer' | 'increasing' | 'decreasing';
4
+ /** Options for `mix` and the function `createMix` returns. */
5
+ export interface MixOptions {
6
+ /** The space to interpolate in. Default `oklab`, which is what `color-mix()` uses. */
7
+ in?: ColorSpaceId;
8
+ /** How hues are interpolated, in the polar spaces. Default `shorter`. */
9
+ hue?: HueMethod;
10
+ }
11
+ /**
12
+ * Interpolates two colors the way CSS does (Color 4 section 13): in the space
13
+ * `in`, with premultiplied alpha, `none` taking the other color's value, and
14
+ * the chosen hue method. `t` is the weight of `b`, 0 to 1 (outside it
15
+ * extrapolates). Strings are parsed with `parse`.
16
+ *
17
+ * A hue that conversion makes powerless (chroma under 8e-6 in `oklch`, 0.0025
18
+ * in `lch`, saturation under 1e-4 in `hsl`, whiteness plus blackness filling `hwb`; for example white) becomes `none`, so it takes the other color's
19
+ * hue. A hue you wrote in the target space stays as written.
20
+ */
21
+ export declare function mix(a: Color | string, b: Color | string, t?: number, options?: MixOptions): Color;
22
+ /**
23
+ * Builds {@link mix} over the spaces given, plus `oklab`, the default `in`, so
24
+ * a bundle contains only those. Give the `in` space too when it is not
25
+ * `oklab`. It takes color objects, not strings, so it does not carry `parse`;
26
+ * pass strings through `parse` first. A color in a space not given throws,
27
+ * naming that space.
28
+ */
29
+ export declare function createMix(...spaces: Space[]): (a: Color, b: Color, t?: number, options?: MixOptions) => Color;
30
+ //# sourceMappingURL=mix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mix.d.ts","names":[],"sources":["../../src/color/mix.ts"],"mappings":";;YASY;;iBAGK;;EAEhB,KAAK;;EAEL,MAAM;;;;;;;;;;;;wBA4FS,IAAI,GAAG,gBAAgB,GAAG,gBAAgB,YAAS,UAAS,aAAkB;;;;;;;;wBAW9E,aAAa,QAAQ,WAAW,GAAG,OAAO,GAAG,OAAO,YAAY,UAAU,eAAe"}
@@ -0,0 +1,152 @@
1
+ import { componentsOver, convertWith } from "./convert.js";
2
+ import { normalizeHue } from "./math.js";
3
+ import { oklab } from "./oklab.js";
4
+ import { toColor } from "./parse.js";
5
+ import { componentsIn } from "./spaces.js";
6
+ import { unknownName } from "./unknown-name.js";
7
+ // src/color/mix.ts
8
+ /** Index of the hue component, for the polar spaces. */
9
+ const HUE_AT = {
10
+ __proto__: null,
11
+ hsl: 0,
12
+ hwb: 0,
13
+ lch: 2,
14
+ oklch: 2
15
+ };
16
+ /**
17
+ * Which components are "analogous" (CSS Color 4 section 4.4): a `none` in one
18
+ * space carries to the analogous component of another. One letter per
19
+ * component; the RGB spaces share `RGB` and the XYZ ones `XYZ`.
20
+ */
21
+ const ANALOGOUS = {
22
+ __proto__: null,
23
+ hsl: "hcl",
24
+ hwb: "hwk",
25
+ lab: "lab",
26
+ lch: "lch",
27
+ oklab: "lab",
28
+ oklch: "lch",
29
+ "xyz-d50": "XYZ",
30
+ "xyz-d65": "XYZ"
31
+ };
32
+ const analogous = (id) => ANALOGOUS[id] ?? "RGB";
33
+ /** Converts, keeping `none` on components that have an analogous one in the source. */
34
+ function convertKeepingNone(componentsIn, color, space) {
35
+ const out = convertWith(componentsIn, color, space);
36
+ if (color.colorSpace !== space && color.components.includes(null)) {
37
+ const from = analogous(color.colorSpace);
38
+ const to = analogous(space);
39
+ out.components = out.components.map((c, i) => color.components[from.indexOf(to[i])] === null ? null : c);
40
+ }
41
+ return out;
42
+ }
43
+ /**
44
+ * Chroma below which a converted hue is powerless and so `none`, per polar
45
+ * space. Follows colorjs.io, which treats a hue as powerless when both Lab
46
+ * axes are under 1/100000 of their reference extent: 0.8 for Oklab (a, b in
47
+ * -0.4 to 0.4) gives 8e-6, 250 for Lab (-125 to 125) gives 0.0025.
48
+ */
49
+ const POWERLESS = {
50
+ __proto__: null,
51
+ oklch: 8e-6,
52
+ lch: .0025,
53
+ hsl: 1e-4
54
+ };
55
+ /**
56
+ * Converts for interpolation. A hue that conversion produced for a gray
57
+ * becomes `none`, so it takes the other color's hue; a hue the author wrote
58
+ * (the color already in `space`) stays as written.
59
+ */
60
+ function prepare(componentsIn, color, space) {
61
+ const out = convertKeepingNone(componentsIn, color, space);
62
+ if (color.colorSpace === space || space !== "hwb" && POWERLESS[space] === void 0) return out;
63
+ const [, x, y] = out.components;
64
+ const epsilon = POWERLESS[space];
65
+ if (typeof x === "number" && (space === "hwb" ? typeof y === "number" && x + y > 99.9999 : epsilon !== void 0 && x < epsilon)) out.components[HUE_AT[space]] = null;
66
+ return out;
67
+ }
68
+ const HUE_METHODS = [
69
+ "shorter",
70
+ "longer",
71
+ "increasing",
72
+ "decreasing"
73
+ ];
74
+ /** Fixes up two hues so they interpolate by `method` (section 12.4). */
75
+ function fixHues(h1, h2, method) {
76
+ let a = normalizeHue(h1);
77
+ let b = normalizeHue(h2);
78
+ const d = b - a;
79
+ if (method === "shorter") {
80
+ if (d > 180) a += 360;
81
+ else if (d < -180) b += 360;
82
+ } else if (method === "longer") {
83
+ if (d > 0 && d < 180) a += 360;
84
+ else if (d > -180 && d <= 0) b += 360;
85
+ } else if (method === "increasing") {
86
+ if (b < a) b += 360;
87
+ } else if (method !== "decreasing") throw unknownName("hue method", method, HUE_METHODS);
88
+ else if (a < b) a += 360;
89
+ return [a, b];
90
+ }
91
+ /**
92
+ * Interpolates two colors the way CSS does (Color 4 section 13): in the space
93
+ * `in`, with premultiplied alpha, `none` taking the other color's value, and
94
+ * the chosen hue method. `t` is the weight of `b`, 0 to 1 (outside it
95
+ * extrapolates). Strings are parsed with `parse`.
96
+ *
97
+ * A hue that conversion makes powerless (chroma under 8e-6 in `oklch`, 0.0025
98
+ * in `lch`, saturation under 1e-4 in `hsl`, whiteness plus blackness filling `hwb`; for example white) becomes `none`, so it takes the other color's
99
+ * hue. A hue you wrote in the target space stays as written.
100
+ */
101
+ function mix(a, b, t = .5, options = {}) {
102
+ return mixWith(componentsIn, toColor(a), toColor(b), t, options);
103
+ }
104
+ /**
105
+ * Builds {@link mix} over the spaces given, plus `oklab`, the default `in`, so
106
+ * a bundle contains only those. Give the `in` space too when it is not
107
+ * `oklab`. It takes color objects, not strings, so it does not carry `parse`;
108
+ * pass strings through `parse` first. A color in a space not given throws,
109
+ * naming that space.
110
+ */
111
+ function createMix(...spaces) {
112
+ const over = componentsOver([oklab, ...spaces]);
113
+ return (a, b, t = .5, options = {}) => mixWith(over, a, b, t, options);
114
+ }
115
+ /** {@link mix} of two colors over the spaces `componentsIn` knows. */
116
+ function mixWith(componentsIn, a, b, t, options) {
117
+ const space = options.in ?? "oklab";
118
+ const c1 = prepare(componentsIn, a, space);
119
+ const c2 = prepare(componentsIn, b, space);
120
+ const alpha1 = c1.alpha === void 0 ? 1 : c1.alpha;
121
+ const alpha2 = c2.alpha === void 0 ? 1 : c2.alpha;
122
+ const a1 = alpha1 ?? alpha2;
123
+ const p1 = a1 ?? 1;
124
+ const p2 = alpha2 ?? alpha1 ?? 1;
125
+ const alpha = p1 * (1 - t) + p2 * t;
126
+ const hueAt = HUE_AT[space];
127
+ const method = options.hue ?? "shorter";
128
+ const components = [];
129
+ for (let i = 0; i < c1.components.length; i++) {
130
+ const x = c1.components[i];
131
+ const y = c2.components[i];
132
+ const u = x ?? y;
133
+ const v = y ?? x;
134
+ if (u === null || v === null) components.push(null);
135
+ else if (i === hueAt) {
136
+ const [h1, h2] = fixHues(u, v, method);
137
+ components.push(normalizeHue(h1 * (1 - t) + h2 * t));
138
+ } else {
139
+ const premultiplied = u * p1 * (1 - t) + v * p2 * t;
140
+ components.push(alpha === 0 ? premultiplied : premultiplied / alpha);
141
+ }
142
+ }
143
+ const result = {
144
+ colorSpace: space,
145
+ components
146
+ };
147
+ if (a1 === null || alpha !== 1) result.alpha = a1 === null ? null : alpha;
148
+ return result;
149
+ }
150
+ export { createMix, mix };
151
+
152
+ //# sourceMappingURL=mix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mix.js","names":[],"sources":["../../src/color/mix.ts"],"sourcesContent":["import { type ComponentsIn, componentsOver, convertWith } from './convert.js'\nimport { normalizeHue } from './math.js'\nimport { oklab } from './oklab.js'\nimport { toColor } from './parse.js'\nimport { componentsIn } from './spaces.js'\nimport type { Color, ColorSpaceId, Component, Space } from './types.js'\nimport { unknownName } from './unknown-name.js'\n\n/** How `mix` travels around the hue circle (CSS Color 4 section 12.4). */\nexport type HueMethod = 'shorter' | 'longer' | 'increasing' | 'decreasing'\n\n/** Options for `mix` and the function `createMix` returns. */\nexport interface MixOptions {\n\t/** The space to interpolate in. Default `oklab`, which is what `color-mix()` uses. */\n\tin?: ColorSpaceId\n\t/** How hues are interpolated, in the polar spaces. Default `shorter`. */\n\thue?: HueMethod\n}\n\n/** Index of the hue component, for the polar spaces. */\nconst HUE_AT: Record<string, number> = { __proto__: null as never, hsl: 0, hwb: 0, lch: 2, oklch: 2 }\n\n/**\n * Which components are \"analogous\" (CSS Color 4 section 4.4): a `none` in one\n * space carries to the analogous component of another. One letter per\n * component; the RGB spaces share `RGB` and the XYZ ones `XYZ`.\n */\nconst ANALOGOUS: Record<string, string> = {\n\t__proto__: null as never,\n\thsl: 'hcl',\n\thwb: 'hwk',\n\tlab: 'lab',\n\tlch: 'lch',\n\toklab: 'lab',\n\toklch: 'lch',\n\t'xyz-d50': 'XYZ',\n\t'xyz-d65': 'XYZ'\n}\nconst analogous = (id: ColorSpaceId): string => ANALOGOUS[id] ?? 'RGB'\n\n/** Converts, keeping `none` on components that have an analogous one in the source. */\nfunction convertKeepingNone(componentsIn: ComponentsIn, color: Color, space: ColorSpaceId): Color {\n\tconst out = convertWith(componentsIn, color, space)\n\t// Nothing to carry when no component is `none`, the common case.\n\tif (color.colorSpace !== space && color.components.includes(null)) {\n\t\tconst from = analogous(color.colorSpace)\n\t\tconst to = analogous(space)\n\t\tout.components = out.components.map((c, i) => (color.components[from.indexOf(to[i])] === null ? null : c))\n\t}\n\treturn out\n}\n\n/**\n * Chroma below which a converted hue is powerless and so `none`, per polar\n * space. Follows colorjs.io, which treats a hue as powerless when both Lab\n * axes are under 1/100000 of their reference extent: 0.8 for Oklab (a, b in\n * -0.4 to 0.4) gives 8e-6, 250 for Lab (-125 to 125) gives 0.0025.\n */\nconst POWERLESS: Record<string, number> = { __proto__: null as never, oklch: 8e-6, lch: 0.0025, hsl: 1e-4 }\n\n/**\n * Converts for interpolation. A hue that conversion produced for a gray\n * becomes `none`, so it takes the other color's hue; a hue the author wrote\n * (the color already in `space`) stays as written.\n */\nfunction prepare(componentsIn: ComponentsIn, color: Color, space: ColorSpaceId): Color {\n\tconst out = convertKeepingNone(componentsIn, color, space)\n\t// A space with no powerless entry (and not `hwb`) has no hue to lose.\n\tif (color.colorSpace === space || (space !== 'hwb' && POWERLESS[space] === undefined)) return out\n\tconst [, x, y] = out.components\n\tconst epsilon = POWERLESS[space]\n\tconst gray =\n\t\ttypeof x === 'number' &&\n\t\t(space === 'hwb' ? typeof y === 'number' && x + y > 100 - 1e-4 : epsilon !== undefined && x < epsilon)\n\tif (gray) out.components[HUE_AT[space] as number] = null\n\treturn out\n}\n\nconst HUE_METHODS = ['shorter', 'longer', 'increasing', 'decreasing']\n\n/** Fixes up two hues so they interpolate by `method` (section 12.4). */\nfunction fixHues(h1: number, h2: number, method: HueMethod): [number, number] {\n\tlet a = normalizeHue(h1)\n\tlet b = normalizeHue(h2)\n\tconst d = b - a\n\tif (method === 'shorter') {\n\t\tif (d > 180) a += 360\n\t\telse if (d < -180) b += 360\n\t} else if (method === 'longer') {\n\t\tif (d > 0 && d < 180) a += 360\n\t\telse if (d > -180 && d <= 0) b += 360\n\t} else if (method === 'increasing') {\n\t\tif (b < a) b += 360\n\t} else if (method !== 'decreasing') throw unknownName('hue method', method, HUE_METHODS)\n\telse if (a < b) a += 360\n\treturn [a, b]\n}\n\n/**\n * Interpolates two colors the way CSS does (Color 4 section 13): in the space\n * `in`, with premultiplied alpha, `none` taking the other color's value, and\n * the chosen hue method. `t` is the weight of `b`, 0 to 1 (outside it\n * extrapolates). Strings are parsed with `parse`.\n *\n * A hue that conversion makes powerless (chroma under 8e-6 in `oklch`, 0.0025\n * in `lch`, saturation under 1e-4 in `hsl`, whiteness plus blackness filling `hwb`; for example white) becomes `none`, so it takes the other color's\n * hue. A hue you wrote in the target space stays as written.\n */\nexport function mix(a: Color | string, b: Color | string, t = 0.5, options: MixOptions = {}): Color {\n\treturn mixWith(componentsIn, toColor(a), toColor(b), t, options)\n}\n\n/**\n * Builds {@link mix} over the spaces given, plus `oklab`, the default `in`, so\n * a bundle contains only those. Give the `in` space too when it is not\n * `oklab`. It takes color objects, not strings, so it does not carry `parse`;\n * pass strings through `parse` first. A color in a space not given throws,\n * naming that space.\n */\nexport function createMix(...spaces: Space[]): (a: Color, b: Color, t?: number, options?: MixOptions) => Color {\n\tconst over = componentsOver([oklab, ...spaces])\n\treturn (a, b, t = 0.5, options = {}) => mixWith(over, a, b, t, options)\n}\n\n/** {@link mix} of two colors over the spaces `componentsIn` knows. */\nfunction mixWith(componentsIn: ComponentsIn, a: Color, b: Color, t: number, options: MixOptions): Color {\n\tconst space = options.in ?? 'oklab'\n\tconst c1 = prepare(componentsIn, a, space)\n\tconst c2 = prepare(componentsIn, b, space)\n\t// A `none` takes the other side's value; both `none` stays `none`.\n\tconst alpha1 = c1.alpha === undefined ? 1 : c1.alpha\n\tconst alpha2 = c2.alpha === undefined ? 1 : c2.alpha\n\tconst a1 = alpha1 ?? alpha2\n\tconst p1 = a1 ?? 1\n\tconst p2 = alpha2 ?? alpha1 ?? 1\n\tconst alpha = p1 * (1 - t) + p2 * t\n\tconst hueAt = HUE_AT[space]\n\tconst method = options.hue ?? 'shorter'\n\tconst components: Component[] = []\n\tfor (let i = 0; i < c1.components.length; i++) {\n\t\tconst x = c1.components[i] as Component\n\t\tconst y = c2.components[i] as Component\n\t\tconst u = x ?? y\n\t\tconst v = y ?? x\n\t\tif (u === null || v === null) {\n\t\t\tcomponents.push(null)\n\t\t} else if (i === hueAt) {\n\t\t\tconst [h1, h2] = fixHues(u, v, method)\n\t\t\tcomponents.push(normalizeHue(h1 * (1 - t) + h2 * t))\n\t\t} else {\n\t\t\tconst premultiplied = u * p1 * (1 - t) + v * p2 * t\n\t\t\tcomponents.push(alpha === 0 ? premultiplied : premultiplied / alpha)\n\t\t}\n\t}\n\tconst result: Color = { colorSpace: space, components }\n\tif (a1 === null || alpha !== 1) result.alpha = a1 === null ? null : alpha\n\treturn result\n}\n"],"mappings":";;;;;;;;AAoBA,MAAM,SAAiC;CAAE,WAAW;CAAe,KAAK;CAAG,KAAK;CAAG,KAAK;CAAG,OAAO;AAAE;;;;;;AAOpG,MAAM,YAAoC;CACzC,WAAW;CACX,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,OAAO;CACP,OAAO;CACP,WAAW;CACX,WAAW;AACZ;AACA,MAAM,aAAa,OAA6B,UAAU,OAAO;;AAGjE,SAAS,mBAAmB,cAA4B,OAAc,OAA4B;CACjG,MAAM,MAAM,YAAY,cAAc,OAAO,KAAK;CAElD,IAAI,MAAM,eAAe,SAAS,MAAM,WAAW,SAAS,IAAI,GAAG;EAClE,MAAM,OAAO,UAAU,MAAM,UAAU;EACvC,MAAM,KAAK,UAAU,KAAK;EAC1B,IAAI,aAAa,IAAI,WAAW,KAAK,GAAG,MAAO,MAAM,WAAW,KAAK,QAAQ,GAAG,EAAE,OAAO,OAAO,OAAO,CAAE;CAC1G;CACA,OAAO;AACR;;;;;;;AAQA,MAAM,YAAoC;CAAE,WAAW;CAAe,OAAO;CAAM,KAAK;CAAQ,KAAK;AAAK;;;;;;AAO1G,SAAS,QAAQ,cAA4B,OAAc,OAA4B;CACtF,MAAM,MAAM,mBAAmB,cAAc,OAAO,KAAK;CAEzD,IAAI,MAAM,eAAe,SAAU,UAAU,SAAS,UAAU,WAAW,KAAA,GAAY,OAAO;CAC9F,MAAM,GAAG,GAAG,KAAK,IAAI;CACrB,MAAM,UAAU,UAAU;CAI1B,IAFC,OAAO,MAAM,aACZ,UAAU,QAAQ,OAAO,MAAM,YAAY,IAAI,IAAI,UAAa,YAAY,KAAA,KAAa,IAAI,UACrF,IAAI,WAAW,OAAO,UAAoB;CACpD,OAAO;AACR;AAEA,MAAM,cAAc;CAAC;CAAW;CAAU;CAAc;AAAY;;AAGpE,SAAS,QAAQ,IAAY,IAAY,QAAqC;CAC7E,IAAI,IAAI,aAAa,EAAE;CACvB,IAAI,IAAI,aAAa,EAAE;CACvB,MAAM,IAAI,IAAI;CACd,IAAI,WAAW,WAAW;EACzB,IAAI,IAAI,KAAK,KAAK;OACb,IAAI,IAAI,MAAM,KAAK;CACzB,OAAO,IAAI,WAAW,UAAU;EAC/B,IAAI,IAAI,KAAK,IAAI,KAAK,KAAK;OACtB,IAAI,IAAI,QAAQ,KAAK,GAAG,KAAK;CACnC,OAAO,IAAI,WAAW,cACjB;MAAA,IAAI,GAAG,KAAK;CAAA,OACV,IAAI,WAAW,cAAc,MAAM,YAAY,cAAc,QAAQ,WAAW;MAClF,IAAI,IAAI,GAAG,KAAK;CACrB,OAAO,CAAC,GAAG,CAAC;AACb;;;;;;;;;;;AAYA,SAAgB,IAAI,GAAmB,GAAmB,IAAI,IAAK,UAAsB,CAAC,GAAU;CACnG,OAAO,QAAQ,cAAc,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,GAAG,OAAO;AAChE;;;;;;;;AASA,SAAgB,UAAU,GAAG,QAAkF;CAC9G,MAAM,OAAO,eAAe,CAAC,OAAO,GAAG,MAAM,CAAC;CAC9C,QAAQ,GAAG,GAAG,IAAI,IAAK,UAAU,CAAC,MAAM,QAAQ,MAAM,GAAG,GAAG,GAAG,OAAO;AACvE;;AAGA,SAAS,QAAQ,cAA4B,GAAU,GAAU,GAAW,SAA4B;CACvG,MAAM,QAAQ,QAAQ,MAAM;CAC5B,MAAM,KAAK,QAAQ,cAAc,GAAG,KAAK;CACzC,MAAM,KAAK,QAAQ,cAAc,GAAG,KAAK;CAEzC,MAAM,SAAS,GAAG,UAAU,KAAA,IAAY,IAAI,GAAG;CAC/C,MAAM,SAAS,GAAG,UAAU,KAAA,IAAY,IAAI,GAAG;CAC/C,MAAM,KAAK,UAAU;CACrB,MAAM,KAAK,MAAM;CACjB,MAAM,KAAK,UAAU,UAAU;CAC/B,MAAM,QAAQ,MAAM,IAAI,KAAK,KAAK;CAClC,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,QAAQ,OAAO;CAC9B,MAAM,aAA0B,CAAC;CACjC,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,WAAW,QAAQ,KAAK;EAC9C,MAAM,IAAI,GAAG,WAAW;EACxB,MAAM,IAAI,GAAG,WAAW;EACxB,MAAM,IAAI,KAAK;EACf,MAAM,IAAI,KAAK;EACf,IAAI,MAAM,QAAQ,MAAM,MACvB,WAAW,KAAK,IAAI;OACd,IAAI,MAAM,OAAO;GACvB,MAAM,CAAC,IAAI,MAAM,QAAQ,GAAG,GAAG,MAAM;GACrC,WAAW,KAAK,aAAa,MAAM,IAAI,KAAK,KAAK,CAAC,CAAC;EACpD,OAAO;GACN,MAAM,gBAAgB,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK;GAClD,WAAW,KAAK,UAAU,IAAI,gBAAgB,gBAAgB,KAAK;EACpE;CACD;CACA,MAAM,SAAgB;EAAE,YAAY;EAAO;CAAW;CACtD,IAAI,OAAO,QAAQ,UAAU,GAAG,OAAO,QAAQ,OAAO,OAAO,OAAO;CACpE,OAAO;AACR"}
@@ -0,0 +1,11 @@
1
+ // src/color/named.ts
2
+ const DATA = "aliceblue:f0f8ff,antiquewhite:faebd7,aqua:00ffff,aquamarine:7fffd4,azure:f0ffff,beige:f5f5dc,bisque:ffe4c4,black:000000,blanchedalmond:ffebcd,blue:0000ff,blueviolet:8a2be2,brown:a52a2a,burlywood:deb887,cadetblue:5f9ea0,chartreuse:7fff00,chocolate:d2691e,coral:ff7f50,cornflowerblue:6495ed,cornsilk:fff8dc,crimson:dc143c,cyan:00ffff,darkblue:00008b,darkcyan:008b8b,darkgoldenrod:b8860b,darkgray:a9a9a9,darkgreen:006400,darkgrey:a9a9a9,darkkhaki:bdb76b,darkmagenta:8b008b,darkolivegreen:556b2f,darkorange:ff8c00,darkorchid:9932cc,darkred:8b0000,darksalmon:e9967a,darkseagreen:8fbc8f,darkslateblue:483d8b,darkslategray:2f4f4f,darkslategrey:2f4f4f,darkturquoise:00ced1,darkviolet:9400d3,deeppink:ff1493,deepskyblue:00bfff,dimgray:696969,dimgrey:696969,dodgerblue:1e90ff,firebrick:b22222,floralwhite:fffaf0,forestgreen:228b22,fuchsia:ff00ff,gainsboro:dcdcdc,ghostwhite:f8f8ff,gold:ffd700,goldenrod:daa520,gray:808080,green:008000,greenyellow:adff2f,grey:808080,honeydew:f0fff0,hotpink:ff69b4,indianred:cd5c5c,indigo:4b0082,ivory:fffff0,khaki:f0e68c,lavender:e6e6fa,lavenderblush:fff0f5,lawngreen:7cfc00,lemonchiffon:fffacd,lightblue:add8e6,lightcoral:f08080,lightcyan:e0ffff,lightgoldenrodyellow:fafad2,lightgray:d3d3d3,lightgreen:90ee90,lightgrey:d3d3d3,lightpink:ffb6c1,lightsalmon:ffa07a,lightseagreen:20b2aa,lightskyblue:87cefa,lightslategray:778899,lightslategrey:778899,lightsteelblue:b0c4de,lightyellow:ffffe0,lime:00ff00,limegreen:32cd32,linen:faf0e6,magenta:ff00ff,maroon:800000,mediumaquamarine:66cdaa,mediumblue:0000cd,mediumorchid:ba55d3,mediumpurple:9370db,mediumseagreen:3cb371,mediumslateblue:7b68ee,mediumspringgreen:00fa9a,mediumturquoise:48d1cc,mediumvioletred:c71585,midnightblue:191970,mintcream:f5fffa,mistyrose:ffe4e1,moccasin:ffe4b5,navajowhite:ffdead,navy:000080,oldlace:fdf5e6,olive:808000,olivedrab:6b8e23,orange:ffa500,orangered:ff4500,orchid:da70d6,palegoldenrod:eee8aa,palegreen:98fb98,paleturquoise:afeeee,palevioletred:db7093,papayawhip:ffefd5,peachpuff:ffdab9,peru:cd853f,pink:ffc0cb,plum:dda0dd,powderblue:b0e0e6,purple:800080,rebeccapurple:663399,red:ff0000,rosybrown:bc8f8f,royalblue:4169e1,saddlebrown:8b4513,salmon:fa8072,sandybrown:f4a460,seagreen:2e8b57,seashell:fff5ee,sienna:a0522d,silver:c0c0c0,skyblue:87ceeb,slateblue:6a5acd,slategray:708090,slategrey:708090,snow:fffafa,springgreen:00ff7f,steelblue:4682b4,tan:d2b48c,teal:008080,thistle:d8bfd8,tomato:ff6347,turquoise:40e0d0,violet:ee82ee,wheat:f5deb3,white:ffffff,whitesmoke:f5f5f5,yellow:ffff00,yellowgreen:9acd32";
3
+ let table;
4
+ /** The 0xRRGGBB value of a CSS named color, or undefined. Built on first use. */
5
+ function namedColor(name) {
6
+ table ??= new Map(DATA.split(",").map((p) => [p.slice(0, p.indexOf(":")), Number.parseInt(p.slice(p.indexOf(":") + 1), 16)]));
7
+ return table.get(name);
8
+ }
9
+ export { namedColor };
10
+
11
+ //# sourceMappingURL=named.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"named.js","names":[],"sources":["../../src/color/named.ts"],"sourcesContent":["// The 148 CSS named colors (CSS Color 4 section 6.1), as `name:rrggbb` pairs.\nconst DATA =\n\t'aliceblue:f0f8ff,antiquewhite:faebd7,aqua:00ffff,aquamarine:7fffd4,azure:f0ffff,beige:f5f5dc,bisque:ffe4c4,black:000000,blanchedalmond:ffebcd,blue:0000ff,blueviolet:8a2be2,brown:a52a2a,burlywood:deb887,cadetblue:5f9ea0,chartreuse:7fff00,chocolate:d2691e,coral:ff7f50,cornflowerblue:6495ed,cornsilk:fff8dc,crimson:dc143c,cyan:00ffff,darkblue:00008b,darkcyan:008b8b,darkgoldenrod:b8860b,darkgray:a9a9a9,darkgreen:006400,darkgrey:a9a9a9,darkkhaki:bdb76b,darkmagenta:8b008b,darkolivegreen:556b2f,darkorange:ff8c00,darkorchid:9932cc,darkred:8b0000,darksalmon:e9967a,darkseagreen:8fbc8f,darkslateblue:483d8b,darkslategray:2f4f4f,darkslategrey:2f4f4f,darkturquoise:00ced1,darkviolet:9400d3,deeppink:ff1493,deepskyblue:00bfff,dimgray:696969,dimgrey:696969,dodgerblue:1e90ff,firebrick:b22222,floralwhite:fffaf0,forestgreen:228b22,fuchsia:ff00ff,gainsboro:dcdcdc,ghostwhite:f8f8ff,gold:ffd700,goldenrod:daa520,gray:808080,green:008000,greenyellow:adff2f,grey:808080,honeydew:f0fff0,hotpink:ff69b4,indianred:cd5c5c,indigo:4b0082,ivory:fffff0,khaki:f0e68c,lavender:e6e6fa,lavenderblush:fff0f5,lawngreen:7cfc00,lemonchiffon:fffacd,lightblue:add8e6,lightcoral:f08080,lightcyan:e0ffff,lightgoldenrodyellow:fafad2,lightgray:d3d3d3,lightgreen:90ee90,lightgrey:d3d3d3,lightpink:ffb6c1,lightsalmon:ffa07a,lightseagreen:20b2aa,lightskyblue:87cefa,lightslategray:778899,lightslategrey:778899,lightsteelblue:b0c4de,lightyellow:ffffe0,lime:00ff00,limegreen:32cd32,linen:faf0e6,magenta:ff00ff,maroon:800000,mediumaquamarine:66cdaa,mediumblue:0000cd,mediumorchid:ba55d3,mediumpurple:9370db,mediumseagreen:3cb371,mediumslateblue:7b68ee,mediumspringgreen:00fa9a,mediumturquoise:48d1cc,mediumvioletred:c71585,midnightblue:191970,mintcream:f5fffa,mistyrose:ffe4e1,moccasin:ffe4b5,navajowhite:ffdead,navy:000080,oldlace:fdf5e6,olive:808000,olivedrab:6b8e23,orange:ffa500,orangered:ff4500,orchid:da70d6,palegoldenrod:eee8aa,palegreen:98fb98,paleturquoise:afeeee,palevioletred:db7093,papayawhip:ffefd5,peachpuff:ffdab9,peru:cd853f,pink:ffc0cb,plum:dda0dd,powderblue:b0e0e6,purple:800080,rebeccapurple:663399,red:ff0000,rosybrown:bc8f8f,royalblue:4169e1,saddlebrown:8b4513,salmon:fa8072,sandybrown:f4a460,seagreen:2e8b57,seashell:fff5ee,sienna:a0522d,silver:c0c0c0,skyblue:87ceeb,slateblue:6a5acd,slategray:708090,slategrey:708090,snow:fffafa,springgreen:00ff7f,steelblue:4682b4,tan:d2b48c,teal:008080,thistle:d8bfd8,tomato:ff6347,turquoise:40e0d0,violet:ee82ee,wheat:f5deb3,white:ffffff,whitesmoke:f5f5f5,yellow:ffff00,yellowgreen:9acd32'\n\nlet table: Map<string, number> | undefined\n\n/** The 0xRRGGBB value of a CSS named color, or undefined. Built on first use. */\nexport function namedColor(name: string): number | undefined {\n\ttable ??= new Map(\n\t\tDATA.split(',').map((p) => [p.slice(0, p.indexOf(':')), Number.parseInt(p.slice(p.indexOf(':') + 1), 16)])\n\t)\n\treturn table.get(name)\n}\n"],"mappings":";AACA,MAAM,OACL;AAED,IAAI;;AAGJ,SAAgB,WAAW,MAAkC;CAC5D,UAAU,IAAI,IACb,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,EAAE,MAAM,GAAG,EAAE,QAAQ,GAAG,CAAC,GAAG,OAAO,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAC1G;CACA,OAAO,MAAM,IAAI,IAAI;AACtB"}
@@ -0,0 +1,7 @@
1
+ import { Space } from "./types.js";
2
+ /**
3
+ * The CSS `oklab` space. Components are lightness in 0 to 1, then the a and b axes, which stay within about -0.4 to 0.4 for real colors.
4
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
5
+ */
6
+ export declare const oklab: Space;
7
+ //# sourceMappingURL=oklab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oklab.d.ts","names":[],"sources":["../../src/color/oklab.ts"],"mappings":";;;;;qBAQa,OAAO"}
@@ -0,0 +1,21 @@
1
+ import { multiply } from "./math.js";
2
+ import { lmsToOklab, lmsToXyz, oklabToLms, xyzToLms } from "./matrices.js";
3
+ // src/color/oklab.ts
4
+ /**
5
+ * The CSS `oklab` space. Components are lightness in 0 to 1, then the a and b axes, which stay within about -0.4 to 0.4 for real colors.
6
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
7
+ */
8
+ const oklab = {
9
+ id: "oklab",
10
+ toXyz: (c) => {
11
+ const v = multiply(oklabToLms, c[0], c[1], c[2]);
12
+ return multiply(lmsToXyz, v[0] ** 3, v[1] ** 3, v[2] ** 3);
13
+ },
14
+ fromXyz: (xyz) => {
15
+ const v = multiply(xyzToLms, xyz[0], xyz[1], xyz[2]);
16
+ return multiply(lmsToOklab, Math.cbrt(v[0]), Math.cbrt(v[1]), Math.cbrt(v[2]));
17
+ }
18
+ };
19
+ export { oklab };
20
+
21
+ //# sourceMappingURL=oklab.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oklab.js","names":[],"sources":["../../src/color/oklab.ts"],"sourcesContent":["import { multiply } from './math.js'\nimport { lmsToOklab, lmsToXyz, oklabToLms, xyzToLms } from './matrices.js'\nimport type { Space } from './types.js'\n\n/**\n * The CSS `oklab` space. Components are lightness in 0 to 1, then the a and b axes, which stay within about -0.4 to 0.4 for real colors.\n * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.\n */\nexport const oklab: Space = {\n\tid: 'oklab',\n\ttoXyz: (c) => {\n\t\tconst v = multiply(oklabToLms, c[0], c[1], c[2])\n\t\treturn multiply(lmsToXyz, v[0] ** 3, v[1] ** 3, v[2] ** 3)\n\t},\n\tfromXyz: (xyz) => {\n\t\tconst v = multiply(xyzToLms, xyz[0], xyz[1], xyz[2])\n\t\treturn multiply(lmsToOklab, Math.cbrt(v[0]), Math.cbrt(v[1]), Math.cbrt(v[2]))\n\t}\n}\n"],"mappings":";;;;;;;AAQA,MAAa,QAAe;CAC3B,IAAI;CACJ,QAAQ,MAAM;EACb,MAAM,IAAI,SAAS,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;EAC/C,OAAO,SAAS,UAAU,EAAE,MAAM,GAAG,EAAE,MAAM,GAAG,EAAE,MAAM,CAAC;CAC1D;CACA,UAAU,QAAQ;EACjB,MAAM,IAAI,SAAS,UAAU,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;EACnD,OAAO,SAAS,YAAY,KAAK,KAAK,EAAE,EAAE,GAAG,KAAK,KAAK,EAAE,EAAE,GAAG,KAAK,KAAK,EAAE,EAAE,CAAC;CAC9E;AACD"}