color-map 2.2.0 → 2.3.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 (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 +100 -0
  5. package/README.md +71 -8
  6. package/bin/cli-CELmx3Y9.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 +48 -0
  268. package/package.json +277 -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 +3 -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,98 @@
1
+ import { evaluate } from "./calc.js";
2
+ import { wcag2 } from "./contrast.js";
3
+ import { parseExpr } from "./expr.js";
4
+ import { mix } from "./mix.js";
5
+ import { ALPHA, FUNCTIONS, UNIT, channel, fail } from "./parse.js";
6
+ import { componentsIn } from "./spaces.js";
7
+ // src/color/resolve.ts
8
+ /** The names a relative color's channel keywords have, by space, one letter each. The RGB spaces use `rgb`. */
9
+ const KEYWORDS = {
10
+ __proto__: null,
11
+ hsl: "hsl",
12
+ hwb: "hwb",
13
+ lab: "lab",
14
+ lch: "lch",
15
+ oklab: "lab",
16
+ oklch: "lch",
17
+ "xyz-d50": "xyz",
18
+ "xyz-d65": "xyz"
19
+ };
20
+ const SIMPLE = /^(?:none|[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?[a-z%]*)$/;
21
+ const WHITE = {
22
+ colorSpace: "srgb",
23
+ components: [
24
+ 1,
25
+ 1,
26
+ 1
27
+ ]
28
+ };
29
+ const BLACK = {
30
+ colorSpace: "srgb",
31
+ components: [
32
+ 0,
33
+ 0,
34
+ 0
35
+ ]
36
+ };
37
+ /** WCAG 2 choice between white and black: whichever contrasts more with the color. */
38
+ function contrastColor(color) {
39
+ return wcag2(WHITE, color) >= wcag2(BLACK, color) ? WHITE : BLACK;
40
+ }
41
+ function resolveRelative(node, context) {
42
+ const origin = resolve(node.from, context);
43
+ const c = componentsIn(origin, node.space);
44
+ const scale = node.fn === "rgb" ? 255 : 1;
45
+ const names = KEYWORDS[node.space] ?? "rgb";
46
+ const vars = { alpha: origin.alpha === void 0 ? 1 : origin.alpha ?? 0 };
47
+ for (let i = 0; i < 3; i++) vars[names[i]] = (c[i] ?? 0) * scale;
48
+ const specs = node.fn === "color" ? [
49
+ UNIT,
50
+ UNIT,
51
+ UNIT
52
+ ] : FUNCTIONS[node.fn].channels;
53
+ const value = (token, spec) => channel(SIMPLE.test(token) ? token : String(evaluate(token, vars)), spec, token);
54
+ const result = {
55
+ colorSpace: node.space,
56
+ components: node.channels.map((t, i) => value(t, specs[i]))
57
+ };
58
+ const alpha = node.alpha === void 0 ? origin.alpha : value(node.alpha, ALPHA);
59
+ if (alpha !== void 0) result.alpha = alpha;
60
+ return result;
61
+ }
62
+ function resolveMix(node, context) {
63
+ const [first, second] = node.items;
64
+ const p1 = first.percent ?? (second.percent === void 0 ? 50 : 100 - second.percent);
65
+ const p2 = second.percent ?? 100 - p1;
66
+ const sum = p1 + p2;
67
+ if (sum <= 0) return fail("color-mix()", "the percentages must add up to more than 0");
68
+ const options = node.hue === void 0 ? { in: node.space } : {
69
+ in: node.space,
70
+ hue: node.hue
71
+ };
72
+ const result = mix(resolve(first.color, context), resolve(second.color, context), p2 / sum, options);
73
+ if (sum < 100 && result.alpha !== null) result.alpha = (result.alpha ?? 1) * (sum / 100);
74
+ return result;
75
+ }
76
+ /**
77
+ * Turns a color, a CSS string or a {@link ColorExpr} into a concrete {@link Color}.
78
+ * `currentcolor`, system colors and `light-dark()` read `context`; nothing is
79
+ * guessed, so a missing entry throws and names the value.
80
+ */
81
+ function resolve(input, context = {}) {
82
+ const expr = typeof input === "string" ? parseExpr(input) : input;
83
+ if ("colorSpace" in expr) return expr;
84
+ if (expr.type === "light-dark") return resolve(context.colorScheme === "dark" ? expr.dark : expr.light, context);
85
+ if (expr.type === "color-mix") return resolveMix(expr, context);
86
+ if (expr.type === "relative") return resolveRelative(expr, context);
87
+ if (expr.type === "contrast-color") return contrastColor(resolve(expr.color, context));
88
+ const name = expr.type === "currentcolor" ? "currentcolor" : expr.name;
89
+ const value = expr.type === "currentcolor" ? context.currentColor : context.systemColors?.[name];
90
+ if (value === void 0) return fail(name, `needs ${expr.type === "currentcolor" ? "currentColor" : `systemColors.${name}`} to resolve`);
91
+ return resolve(value, {
92
+ ...context,
93
+ currentColor: void 0
94
+ });
95
+ }
96
+ export { resolve };
97
+
98
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","names":[],"sources":["../../src/color/resolve.ts"],"sourcesContent":["import { evaluate } from './calc.js'\nimport { wcag2 } from './contrast.js'\nimport { type ColorExpr, parseExpr } from './expr.js'\nimport { mix } from './mix.js'\nimport { ALPHA, channel, FUNCTIONS, fail, UNIT } from './parse.js'\nimport { componentsIn } from './spaces.js'\nimport type { Color, Component } from './types.js'\n\n/** What `resolve` needs from its surroundings to settle `currentcolor`, `light-dark()` and system colors. */\nexport interface ResolveContext {\n\t/** What `currentcolor` means. */\n\tcurrentColor?: string | ColorExpr\n\t/** Which side `light-dark()` takes. Default `light`. */\n\tcolorScheme?: 'light' | 'dark'\n\t/** What each system color (`canvas`, `buttontext`, ...) means, by lowercase name. */\n\tsystemColors?: Record<string, string | ColorExpr>\n}\n\n/** The names a relative color's channel keywords have, by space, one letter each. The RGB spaces use `rgb`. */\nconst KEYWORDS: Record<string, string> = {\n\t__proto__: null as never,\n\thsl: 'hsl',\n\thwb: 'hwb',\n\tlab: 'lab',\n\tlch: 'lch',\n\toklab: 'lab',\n\toklch: 'lch',\n\t'xyz-d50': 'xyz',\n\t'xyz-d65': 'xyz'\n}\nconst SIMPLE = /^(?:none|[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?[a-z%]*)$/\n\nconst WHITE: Color = { colorSpace: 'srgb', components: [1, 1, 1] }\nconst BLACK: Color = { colorSpace: 'srgb', components: [0, 0, 0] }\n\n/** WCAG 2 choice between white and black: whichever contrasts more with the color. */\nfunction contrastColor(color: Color): Color {\n\treturn wcag2(WHITE, color) >= wcag2(BLACK, color) ? WHITE : BLACK\n}\n\nfunction resolveRelative(node: Extract<ColorExpr, { type: 'relative' }>, context: ResolveContext): Color {\n\tconst origin = resolve(node.from, context)\n\tconst c = componentsIn(origin, node.space)\n\tconst scale = node.fn === 'rgb' ? 255 : 1\n\tconst names = KEYWORDS[node.space] ?? 'rgb'\n\tconst vars: Record<string, number> = { alpha: origin.alpha === undefined ? 1 : (origin.alpha ?? 0) }\n\tfor (let i = 0; i < 3; i++) vars[names[i]] = (c[i] ?? 0) * scale\n\tconst specs = node.fn === 'color' ? [UNIT, UNIT, UNIT] : FUNCTIONS[node.fn].channels\n\tconst value = (token: string, spec: typeof ALPHA): Component =>\n\t\tchannel(SIMPLE.test(token) ? token : String(evaluate(token, vars)), spec, token)\n\tconst result: Color = { colorSpace: node.space, components: node.channels.map((t, i) => value(t, specs[i])) }\n\tconst alpha = node.alpha === undefined ? origin.alpha : value(node.alpha, ALPHA)\n\tif (alpha !== undefined) result.alpha = alpha\n\treturn result\n}\n\nfunction resolveMix(node: Extract<ColorExpr, { type: 'color-mix' }>, context: ResolveContext): Color {\n\tconst [first, second] = node.items\n\tconst p1 = first.percent ?? (second.percent === undefined ? 50 : 100 - second.percent)\n\tconst p2 = second.percent ?? 100 - p1\n\tconst sum = p1 + p2\n\tif (sum <= 0) return fail('color-mix()', 'the percentages must add up to more than 0')\n\tconst options = node.hue === undefined ? { in: node.space } : { in: node.space, hue: node.hue }\n\tconst result = mix(resolve(first.color, context), resolve(second.color, context), p2 / sum, options)\n\t// Percentages adding up to less than 100% make the result translucent.\n\tif (sum < 100 && result.alpha !== null) result.alpha = (result.alpha ?? 1) * (sum / 100)\n\treturn result\n}\n\n/**\n * Turns a color, a CSS string or a {@link ColorExpr} into a concrete {@link Color}.\n * `currentcolor`, system colors and `light-dark()` read `context`; nothing is\n * guessed, so a missing entry throws and names the value.\n */\nexport function resolve(input: string | ColorExpr, context: ResolveContext = {}): Color {\n\tconst expr = typeof input === 'string' ? parseExpr(input) : input\n\tif ('colorSpace' in expr) return expr\n\tif (expr.type === 'light-dark') return resolve(context.colorScheme === 'dark' ? expr.dark : expr.light, context)\n\tif (expr.type === 'color-mix') return resolveMix(expr, context)\n\tif (expr.type === 'relative') return resolveRelative(expr, context)\n\tif (expr.type === 'contrast-color') return contrastColor(resolve(expr.color, context))\n\tconst name = expr.type === 'currentcolor' ? 'currentcolor' : expr.name\n\tconst value = expr.type === 'currentcolor' ? context.currentColor : context.systemColors?.[name]\n\tif (value === undefined)\n\t\treturn fail(name, `needs ${expr.type === 'currentcolor' ? 'currentColor' : `systemColors.${name}`} to resolve`)\n\treturn resolve(value, { ...context, currentColor: undefined })\n}\n"],"mappings":";;;;;;;;AAmBA,MAAM,WAAmC;CACxC,WAAW;CACX,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,OAAO;CACP,OAAO;CACP,WAAW;CACX,WAAW;AACZ;AACA,MAAM,SAAS;AAEf,MAAM,QAAe;CAAE,YAAY;CAAQ,YAAY;EAAC;EAAG;EAAG;CAAC;AAAE;AACjE,MAAM,QAAe;CAAE,YAAY;CAAQ,YAAY;EAAC;EAAG;EAAG;CAAC;AAAE;;AAGjE,SAAS,cAAc,OAAqB;CAC3C,OAAO,MAAM,OAAO,KAAK,KAAK,MAAM,OAAO,KAAK,IAAI,QAAQ;AAC7D;AAEA,SAAS,gBAAgB,MAAgD,SAAgC;CACxG,MAAM,SAAS,QAAQ,KAAK,MAAM,OAAO;CACzC,MAAM,IAAI,aAAa,QAAQ,KAAK,KAAK;CACzC,MAAM,QAAQ,KAAK,OAAO,QAAQ,MAAM;CACxC,MAAM,QAAQ,SAAS,KAAK,UAAU;CACtC,MAAM,OAA+B,EAAE,OAAO,OAAO,UAAU,KAAA,IAAY,IAAK,OAAO,SAAS,EAAG;CACnG,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK,KAAK,MAAM,OAAO,EAAE,MAAM,KAAK;CAC3D,MAAM,QAAQ,KAAK,OAAO,UAAU;EAAC;EAAM;EAAM;CAAI,IAAI,UAAU,KAAK,GAAG,CAAC;CAC5E,MAAM,SAAS,OAAe,SAC7B,QAAQ,OAAO,KAAK,KAAK,IAAI,QAAQ,OAAO,SAAS,OAAO,IAAI,CAAC,GAAG,MAAM,KAAK;CAChF,MAAM,SAAgB;EAAE,YAAY,KAAK;EAAO,YAAY,KAAK,SAAS,KAAK,GAAG,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;CAAE;CAC5G,MAAM,QAAQ,KAAK,UAAU,KAAA,IAAY,OAAO,QAAQ,MAAM,KAAK,OAAO,KAAK;CAC/E,IAAI,UAAU,KAAA,GAAW,OAAO,QAAQ;CACxC,OAAO;AACR;AAEA,SAAS,WAAW,MAAiD,SAAgC;CACpG,MAAM,CAAC,OAAO,UAAU,KAAK;CAC7B,MAAM,KAAK,MAAM,YAAY,OAAO,YAAY,KAAA,IAAY,KAAK,MAAM,OAAO;CAC9E,MAAM,KAAK,OAAO,WAAW,MAAM;CACnC,MAAM,MAAM,KAAK;CACjB,IAAI,OAAO,GAAG,OAAO,KAAK,eAAe,4CAA4C;CACrF,MAAM,UAAU,KAAK,QAAQ,KAAA,IAAY,EAAE,IAAI,KAAK,MAAM,IAAI;EAAE,IAAI,KAAK;EAAO,KAAK,KAAK;CAAI;CAC9F,MAAM,SAAS,IAAI,QAAQ,MAAM,OAAO,OAAO,GAAG,QAAQ,OAAO,OAAO,OAAO,GAAG,KAAK,KAAK,OAAO;CAEnG,IAAI,MAAM,OAAO,OAAO,UAAU,MAAM,OAAO,SAAS,OAAO,SAAS,MAAM,MAAM;CACpF,OAAO;AACR;;;;;;AAOA,SAAgB,QAAQ,OAA2B,UAA0B,CAAC,GAAU;CACvF,MAAM,OAAO,OAAO,UAAU,WAAW,UAAU,KAAK,IAAI;CAC5D,IAAI,gBAAgB,MAAM,OAAO;CACjC,IAAI,KAAK,SAAS,cAAc,OAAO,QAAQ,QAAQ,gBAAgB,SAAS,KAAK,OAAO,KAAK,OAAO,OAAO;CAC/G,IAAI,KAAK,SAAS,aAAa,OAAO,WAAW,MAAM,OAAO;CAC9D,IAAI,KAAK,SAAS,YAAY,OAAO,gBAAgB,MAAM,OAAO;CAClE,IAAI,KAAK,SAAS,kBAAkB,OAAO,cAAc,QAAQ,KAAK,OAAO,OAAO,CAAC;CACrF,MAAM,OAAO,KAAK,SAAS,iBAAiB,iBAAiB,KAAK;CAClE,MAAM,QAAQ,KAAK,SAAS,iBAAiB,QAAQ,eAAe,QAAQ,eAAe;CAC3F,IAAI,UAAU,KAAA,GACb,OAAO,KAAK,MAAM,SAAS,KAAK,SAAS,iBAAiB,iBAAiB,gBAAgB,OAAO,YAAY;CAC/G,OAAO,QAAQ,OAAO;EAAE,GAAG;EAAS,cAAc,KAAA;CAAU,CAAC;AAC9D"}
@@ -0,0 +1,20 @@
1
+ import { multiply } from "./math.js";
2
+ // src/color/rgb.ts
3
+ /** An RGB space: a transfer function, then a matrix to XYZ-D65. */
4
+ function rgbSpace(id, toLinear, toGamma, toXyz, fromXyz) {
5
+ return {
6
+ id,
7
+ toXyz: (c) => multiply(toXyz, toLinear(c[0]), toLinear(c[1]), toLinear(c[2])),
8
+ fromXyz: (xyz) => {
9
+ const v = multiply(fromXyz, xyz[0], xyz[1], xyz[2]);
10
+ return [
11
+ toGamma(v[0]),
12
+ toGamma(v[1]),
13
+ toGamma(v[2])
14
+ ];
15
+ }
16
+ };
17
+ }
18
+ export { rgbSpace };
19
+
20
+ //# sourceMappingURL=rgb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rgb.js","names":[],"sources":["../../src/color/rgb.ts"],"sourcesContent":["import { type Matrix, multiply } from './math.js'\nimport type { ColorSpaceId, Space } from './types.js'\n\n/** An RGB space: a transfer function, then a matrix to XYZ-D65. */\nexport function rgbSpace(\n\tid: ColorSpaceId,\n\ttoLinear: (n: number) => number,\n\ttoGamma: (n: number) => number,\n\ttoXyz: Matrix,\n\tfromXyz: Matrix\n): Space {\n\treturn {\n\t\tid,\n\t\ttoXyz: (c) => multiply(toXyz, toLinear(c[0]), toLinear(c[1]), toLinear(c[2])),\n\t\tfromXyz: (xyz) => {\n\t\t\tconst v = multiply(fromXyz, xyz[0], xyz[1], xyz[2])\n\t\t\treturn [toGamma(v[0]), toGamma(v[1]), toGamma(v[2])]\n\t\t}\n\t}\n}\n"],"mappings":";;;AAIA,SAAgB,SACf,IACA,UACA,SACA,OACA,SACQ;CACR,OAAO;EACN;EACA,QAAQ,MAAM,SAAS,OAAO,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,EAAE,CAAC;EAC5E,UAAU,QAAQ;GACjB,MAAM,IAAI,SAAS,SAAS,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;GAClD,OAAO;IAAC,QAAQ,EAAE,EAAE;IAAG,QAAQ,EAAE,EAAE;IAAG,QAAQ,EAAE,EAAE;GAAC;EACpD;CACD;AACD"}
@@ -0,0 +1,24 @@
1
+ import { Color, Space } from "./types.js";
2
+ /** Options for `toCss`. */
3
+ export interface ToCssOptions {
4
+ /** Decimal places kept in every number. Default 5. */
5
+ precision?: number;
6
+ }
7
+ /**
8
+ * Serializes a color as CSS. `srgb` and `hsl` print in the comma syntax
9
+ * (`rgb(255, 0, 0)`, `rgba(...)`) unless a component is `none`; the other
10
+ * spaces print in the space syntax (`oklch(0.7 0.1 200 / 0.5)`,
11
+ * `color(display-p3 1 0 0)`). Out-of-gamut values are kept, not clipped.
12
+ */
13
+ export declare function toCss(color: Color, options?: ToCssOptions): string;
14
+ /**
15
+ * The hex form of a color, `#rrggbb` or `#rrggbbaa` when it is not opaque.
16
+ * Colors outside sRGB are converted and clipped, so map them with `toGamut` first.
17
+ */
18
+ export declare function toHex(color: Color): string;
19
+ /**
20
+ * Builds {@link toHex} over the spaces given, plus `srgb`, so a bundle contains
21
+ * only those. A color in a space not given throws, naming that space.
22
+ */
23
+ export declare function createToHex(...spaces: Space[]): (color: Color) => string;
24
+ //# sourceMappingURL=serialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize.d.ts","names":[],"sources":["../../src/color/serialize.ts"],"mappings":";;iBAMiB;;EAEhB;;;;;;;;wBA2Ce,MAAM,OAAO,OAAO,UAAS;;;;;wBA2B7B,MAAM,OAAO;;;;;wBAcb,eAAe,QAAQ,WAAW,OAAO"}
@@ -0,0 +1,88 @@
1
+ import { componentsOver } from "./convert.js";
2
+ import { componentsIn } from "./spaces.js";
3
+ import { srgb } from "./srgb.js";
4
+ // src/color/serialize.ts
5
+ const POWERS = Array.from({ length: 23 }, (_, i) => Number(`1e${i}`));
6
+ /**
7
+ * `Number(n.toFixed(precision))`, without building the string. `toFixed` rounds
8
+ * the exact value of `n` half up (away from zero), and the number it then reads
9
+ * is `k / 10^precision` for that integer `k`, which one division gives exactly.
10
+ * `k` comes from `t = |n| * 10^precision`. The product is rounded, but a tie
11
+ * (`t` ending in .5) is a double, and rounding is monotonic, so any `t` that
12
+ * is not exactly a tie lies on the same side of it as the exact product: only
13
+ * `t` ending in .5 is left to `toFixed`. So are NaN, the infinities, products
14
+ * of 1e9 and up, and precisions that `POWERS` lacks.
15
+ */
16
+ function roundTo(n, precision) {
17
+ const scale = POWERS[precision];
18
+ const t = Math.abs(n) * scale;
19
+ const whole = Math.floor(t);
20
+ const rest = t - whole;
21
+ if (t < 1e9 && rest !== .5) {
22
+ const r = (rest > .5 ? whole + 1 : whole) / scale;
23
+ return n < 0 ? -r : r;
24
+ }
25
+ return Number(n.toFixed(precision));
26
+ }
27
+ /** Prints a number with at most `precision` decimals, without `-0` or trailing zeros. */
28
+ function num(n, precision) {
29
+ return String(roundTo(n, precision) + 0);
30
+ }
31
+ const part = (c, precision, scale = 1, suffix = "") => c === null ? "none" : num(c * scale, precision) + suffix;
32
+ const RECTANGULAR = /* @__PURE__ */ new Set([
33
+ "hsl",
34
+ "hwb",
35
+ "lab",
36
+ "lch",
37
+ "oklab",
38
+ "oklch"
39
+ ]);
40
+ /**
41
+ * Serializes a color as CSS. `srgb` and `hsl` print in the comma syntax
42
+ * (`rgb(255, 0, 0)`, `rgba(...)`) unless a component is `none`; the other
43
+ * spaces print in the space syntax (`oklch(0.7 0.1 200 / 0.5)`,
44
+ * `color(display-p3 1 0 0)`). Out-of-gamut values are kept, not clipped.
45
+ */
46
+ function toCss(color, options = {}) {
47
+ const { precision = 5 } = options;
48
+ const id = color.colorSpace;
49
+ const [c0, c1, c2] = color.components;
50
+ const p = (c, scale, suffix) => part(c, precision, scale, suffix);
51
+ const a = color.alpha !== void 0 && color.alpha !== 1 ? p(color.alpha) : void 0;
52
+ const percent = id === "hsl" || id === "hwb" ? "%" : "";
53
+ const scale = id === "srgb" ? 255 : 1;
54
+ const args = [
55
+ p(c0, scale),
56
+ p(c1, scale, percent),
57
+ p(c2, scale, percent)
58
+ ];
59
+ if ((id === "srgb" || id === "hsl") && color.alpha !== null && !color.components.includes(null)) {
60
+ const name = id === "srgb" ? "rgb" : "hsl";
61
+ return a === void 0 ? `${name}(${args.join(", ")})` : `${name}a(${args.join(", ")}, ${a})`;
62
+ }
63
+ return `${id === "srgb" ? "rgb(" : RECTANGULAR.has(id) ? `${id}(` : `color(${id} `}${args.join(" ")}${a === void 0 ? "" : ` / ${a}`})`;
64
+ }
65
+ const hexByte = (n) => Math.min(255, Math.max(0, Math.round(n * 255))).toString(16).padStart(2, "0");
66
+ /**
67
+ * The hex form of a color, `#rrggbb` or `#rrggbbaa` when it is not opaque.
68
+ * Colors outside sRGB are converted and clipped, so map them with `toGamut` first.
69
+ */
70
+ function toHex(color) {
71
+ return hexWith(componentsIn, color);
72
+ }
73
+ function hexWith(componentsIn, color) {
74
+ const [r, g, b] = componentsIn(color, "srgb");
75
+ const alpha = color.alpha ?? 1;
76
+ return `#${hexByte(r)}${hexByte(g)}${hexByte(b)}${alpha === 1 ? "" : hexByte(alpha)}`;
77
+ }
78
+ /**
79
+ * Builds {@link toHex} over the spaces given, plus `srgb`, so a bundle contains
80
+ * only those. A color in a space not given throws, naming that space.
81
+ */
82
+ function createToHex(...spaces) {
83
+ const over = componentsOver([srgb, ...spaces]);
84
+ return (color) => hexWith(over, color);
85
+ }
86
+ export { createToHex, roundTo, toCss, toHex };
87
+
88
+ //# sourceMappingURL=serialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize.js","names":[],"sources":["../../src/color/serialize.ts"],"sourcesContent":["import { type ComponentsIn, componentsOver } from './convert.js'\nimport { componentsIn } from './spaces.js'\nimport { srgb } from './srgb.js'\nimport type { Color, ColorSpaceId, Component, Space } from './types.js'\n\n/** Options for `toCss`. */\nexport interface ToCssOptions {\n\t/** Decimal places kept in every number. Default 5. */\n\tprecision?: number\n}\n\nconst POWERS = Array.from({ length: 23 }, (_, i) => Number(`1e${i}`))\n\n/**\n * `Number(n.toFixed(precision))`, without building the string. `toFixed` rounds\n * the exact value of `n` half up (away from zero), and the number it then reads\n * is `k / 10^precision` for that integer `k`, which one division gives exactly.\n * `k` comes from `t = |n| * 10^precision`. The product is rounded, but a tie\n * (`t` ending in .5) is a double, and rounding is monotonic, so any `t` that\n * is not exactly a tie lies on the same side of it as the exact product: only\n * `t` ending in .5 is left to `toFixed`. So are NaN, the infinities, products\n * of 1e9 and up, and precisions that `POWERS` lacks.\n */\nexport function roundTo(n: number, precision: number): number {\n\tconst scale = POWERS[precision]\n\tconst t = Math.abs(n) * scale\n\tconst whole = Math.floor(t)\n\tconst rest = t - whole\n\tif (t < 1e9 && rest !== 0.5) {\n\t\tconst r = (rest > 0.5 ? whole + 1 : whole) / scale\n\t\treturn n < 0 ? -r : r\n\t}\n\treturn Number(n.toFixed(precision))\n}\n\n/** Prints a number with at most `precision` decimals, without `-0` or trailing zeros. */\nfunction num(n: number, precision: number): string {\n\treturn String(roundTo(n, precision) + 0)\n}\n\nconst part = (c: Component, precision: number, scale = 1, suffix = ''): string =>\n\tc === null ? 'none' : num(c * scale, precision) + suffix\n\nconst RECTANGULAR = new Set<ColorSpaceId>(['hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'])\n\n/**\n * Serializes a color as CSS. `srgb` and `hsl` print in the comma syntax\n * (`rgb(255, 0, 0)`, `rgba(...)`) unless a component is `none`; the other\n * spaces print in the space syntax (`oklch(0.7 0.1 200 / 0.5)`,\n * `color(display-p3 1 0 0)`). Out-of-gamut values are kept, not clipped.\n */\nexport function toCss(color: Color, options: ToCssOptions = {}): string {\n\tconst { precision = 5 } = options\n\tconst id = color.colorSpace\n\tconst [c0, c1, c2] = color.components\n\tconst p = (c: Component, scale?: number, suffix?: string): string => part(c, precision, scale, suffix)\n\tconst hasAlpha = color.alpha !== undefined && color.alpha !== 1\n\tconst a = hasAlpha ? p(color.alpha as Component) : undefined\n\tconst percent = id === 'hsl' || id === 'hwb' ? '%' : ''\n\tconst scale = id === 'srgb' ? 255 : 1\n\tconst args = [p(c0, scale), p(c1, scale, percent), p(c2, scale, percent)]\n\tif ((id === 'srgb' || id === 'hsl') && color.alpha !== null && !color.components.includes(null)) {\n\t\tconst name = id === 'srgb' ? 'rgb' : 'hsl'\n\t\treturn a === undefined ? `${name}(${args.join(', ')})` : `${name}a(${args.join(', ')}, ${a})`\n\t}\n\tconst head = id === 'srgb' ? 'rgb(' : RECTANGULAR.has(id) ? `${id}(` : `color(${id} `\n\treturn `${head}${args.join(' ')}${a === undefined ? '' : ` / ${a}`})`\n}\n\nconst hexByte = (n: number): string =>\n\tMath.min(255, Math.max(0, Math.round(n * 255)))\n\t\t.toString(16)\n\t\t.padStart(2, '0')\n\n/**\n * The hex form of a color, `#rrggbb` or `#rrggbbaa` when it is not opaque.\n * Colors outside sRGB are converted and clipped, so map them with `toGamut` first.\n */\nexport function toHex(color: Color): string {\n\treturn hexWith(componentsIn, color)\n}\n\nfunction hexWith(componentsIn: ComponentsIn, color: Color): string {\n\tconst [r, g, b] = componentsIn(color, 'srgb') as number[]\n\tconst alpha = color.alpha ?? 1\n\treturn `#${hexByte(r)}${hexByte(g)}${hexByte(b)}${alpha === 1 ? '' : hexByte(alpha)}`\n}\n\n/**\n * Builds {@link toHex} over the spaces given, plus `srgb`, so a bundle contains\n * only those. A color in a space not given throws, naming that space.\n */\nexport function createToHex(...spaces: Space[]): (color: Color) => string {\n\tconst over = componentsOver([srgb, ...spaces])\n\treturn (color) => hexWith(over, color)\n}\n"],"mappings":";;;;AAWA,MAAM,SAAS,MAAM,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,MAAM,OAAO,KAAK,GAAG,CAAC;;;;;;;;;;;AAYpE,SAAgB,QAAQ,GAAW,WAA2B;CAC7D,MAAM,QAAQ,OAAO;CACrB,MAAM,IAAI,KAAK,IAAI,CAAC,IAAI;CACxB,MAAM,QAAQ,KAAK,MAAM,CAAC;CAC1B,MAAM,OAAO,IAAI;CACjB,IAAI,IAAI,OAAO,SAAS,IAAK;EAC5B,MAAM,KAAK,OAAO,KAAM,QAAQ,IAAI,SAAS;EAC7C,OAAO,IAAI,IAAI,CAAC,IAAI;CACrB;CACA,OAAO,OAAO,EAAE,QAAQ,SAAS,CAAC;AACnC;;AAGA,SAAS,IAAI,GAAW,WAA2B;CAClD,OAAO,OAAO,QAAQ,GAAG,SAAS,IAAI,CAAC;AACxC;AAEA,MAAM,QAAQ,GAAc,WAAmB,QAAQ,GAAG,SAAS,OAClE,MAAM,OAAO,SAAS,IAAI,IAAI,OAAO,SAAS,IAAI;AAEnD,MAAM,8BAAc,IAAI,IAAkB;CAAC;CAAO;CAAO;CAAO;CAAO;CAAS;AAAO,CAAC;;;;;;;AAQxF,SAAgB,MAAM,OAAc,UAAwB,CAAC,GAAW;CACvE,MAAM,EAAE,YAAY,MAAM;CAC1B,MAAM,KAAK,MAAM;CACjB,MAAM,CAAC,IAAI,IAAI,MAAM,MAAM;CAC3B,MAAM,KAAK,GAAc,OAAgB,WAA4B,KAAK,GAAG,WAAW,OAAO,MAAM;CAErG,MAAM,IADW,MAAM,UAAU,KAAA,KAAa,MAAM,UAAU,IACzC,EAAE,MAAM,KAAkB,IAAI,KAAA;CACnD,MAAM,UAAU,OAAO,SAAS,OAAO,QAAQ,MAAM;CACrD,MAAM,QAAQ,OAAO,SAAS,MAAM;CACpC,MAAM,OAAO;EAAC,EAAE,IAAI,KAAK;EAAG,EAAE,IAAI,OAAO,OAAO;EAAG,EAAE,IAAI,OAAO,OAAO;CAAC;CACxE,KAAK,OAAO,UAAU,OAAO,UAAU,MAAM,UAAU,QAAQ,CAAC,MAAM,WAAW,SAAS,IAAI,GAAG;EAChG,MAAM,OAAO,OAAO,SAAS,QAAQ;EACrC,OAAO,MAAM,KAAA,IAAY,GAAG,KAAK,GAAG,KAAK,KAAK,IAAI,EAAE,KAAK,GAAG,KAAK,IAAI,KAAK,KAAK,IAAI,EAAE,IAAI,EAAE;CAC5F;CAEA,OAAO,GADM,OAAO,SAAS,SAAS,YAAY,IAAI,EAAE,IAAI,GAAG,GAAG,KAAK,SAAS,GAAG,KAClE,KAAK,KAAK,GAAG,IAAI,MAAM,KAAA,IAAY,KAAK,MAAM,IAAI;AACpE;AAEA,MAAM,WAAW,MAChB,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAC7C,SAAS,EAAE,CAAC,CACZ,SAAS,GAAG,GAAG;;;;;AAMlB,SAAgB,MAAM,OAAsB;CAC3C,OAAO,QAAQ,cAAc,KAAK;AACnC;AAEA,SAAS,QAAQ,cAA4B,OAAsB;CAClE,MAAM,CAAC,GAAG,GAAG,KAAK,aAAa,OAAO,MAAM;CAC5C,MAAM,QAAQ,MAAM,SAAS;CAC7B,OAAO,IAAI,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,UAAU,IAAI,KAAK,QAAQ,KAAK;AACnF;;;;;AAMA,SAAgB,YAAY,GAAG,QAA2C;CACzE,MAAM,OAAO,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC;CAC7C,QAAQ,UAAU,QAAQ,MAAM,KAAK;AACtC"}
@@ -0,0 +1,6 @@
1
+ import { Color, ColorSpaceId, Space } from "./types.js";
2
+ /** Every space. Importing this pulls them all in; import single spaces to avoid that. */
3
+ export declare const spaces: Record<ColorSpaceId, Space>;
4
+ /** Converts a color to any of the 15 spaces. */
5
+ export declare const convert: (color: Color, to: ColorSpaceId) => Color;
6
+ //# sourceMappingURL=spaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spaces.d.ts","names":["_$__types_js0.Color"],"sources":["../../src/color/spaces.ts"],"mappings":";;qBAmBa,QAAQ,OAAO,cAAc;;qBAsB7B,UAAO,OAAPA,OAAO,IAAA,iBAAAA"}
@@ -0,0 +1,42 @@
1
+ import { a98Rgb } from "./a98-rgb.js";
2
+ import { componentsOver, createConverter } from "./convert.js";
3
+ import { displayP3 } from "./display-p3.js";
4
+ import { displayP3Linear } from "./display-p3-linear.js";
5
+ import { hsl } from "./hsl.js";
6
+ import { hwb } from "./hwb.js";
7
+ import { lab } from "./lab.js";
8
+ import { lch } from "./lch.js";
9
+ import { oklab } from "./oklab.js";
10
+ import { oklch } from "./oklch.js";
11
+ import { prophotoRgb } from "./prophoto-rgb.js";
12
+ import { rec2020 } from "./rec2020.js";
13
+ import { srgb } from "./srgb.js";
14
+ import { srgbLinear } from "./srgb-linear.js";
15
+ import { xyzD50 } from "./xyz-d50.js";
16
+ import { xyzD65 } from "./xyz-d65.js";
17
+ // src/color/spaces.ts
18
+ /** Every space. Importing this pulls them all in; import single spaces to avoid that. */
19
+ const spaces = {
20
+ srgb,
21
+ "srgb-linear": srgbLinear,
22
+ hsl,
23
+ hwb,
24
+ lab,
25
+ lch,
26
+ oklab,
27
+ oklch,
28
+ "display-p3": displayP3,
29
+ "display-p3-linear": displayP3Linear,
30
+ "a98-rgb": a98Rgb,
31
+ "prophoto-rgb": prophotoRgb,
32
+ rec2020,
33
+ "xyz-d50": xyzD50,
34
+ "xyz-d65": xyzD65
35
+ };
36
+ /** A color's components in any of the 15 spaces, as `convert` gives them, without the color object. */
37
+ const componentsIn = componentsOver(Object.values(spaces));
38
+ /** Converts a color to any of the 15 spaces. */
39
+ const convert = createConverter(...Object.values(spaces));
40
+ export { componentsIn, convert, spaces };
41
+
42
+ //# sourceMappingURL=spaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spaces.js","names":[],"sources":["../../src/color/spaces.ts"],"sourcesContent":["import { a98Rgb } from './a98-rgb.js'\nimport { componentsOver, createConverter } from './convert.js'\nimport { displayP3 } from './display-p3.js'\nimport { displayP3Linear } from './display-p3-linear.js'\nimport { hsl } from './hsl.js'\nimport { hwb } from './hwb.js'\nimport { lab } from './lab.js'\nimport { lch } from './lch.js'\nimport { oklab } from './oklab.js'\nimport { oklch } from './oklch.js'\nimport { prophotoRgb } from './prophoto-rgb.js'\nimport { rec2020 } from './rec2020.js'\nimport { srgb } from './srgb.js'\nimport { srgbLinear } from './srgb-linear.js'\nimport type { ColorSpaceId, Space } from './types.js'\nimport { xyzD50 } from './xyz-d50.js'\nimport { xyzD65 } from './xyz-d65.js'\n\n/** Every space. Importing this pulls them all in; import single spaces to avoid that. */\nexport const spaces: Record<ColorSpaceId, Space> = {\n\tsrgb,\n\t'srgb-linear': srgbLinear,\n\thsl,\n\thwb,\n\tlab,\n\tlch,\n\toklab,\n\toklch,\n\t'display-p3': displayP3,\n\t'display-p3-linear': displayP3Linear,\n\t'a98-rgb': a98Rgb,\n\t'prophoto-rgb': prophotoRgb,\n\trec2020,\n\t'xyz-d50': xyzD50,\n\t'xyz-d65': xyzD65\n}\n\n/** A color's components in any of the 15 spaces, as `convert` gives them, without the color object. */\nexport const componentsIn = componentsOver(Object.values(spaces))\n\n/** Converts a color to any of the 15 spaces. */\nexport const convert = createConverter(...Object.values(spaces))\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAa,SAAsC;CAClD;CACA,eAAe;CACf;CACA;CACA;CACA;CACA;CACA;CACA,cAAc;CACd,qBAAqB;CACrB,WAAW;CACX,gBAAgB;CAChB;CACA,WAAW;CACX,WAAW;AACZ;;AAGA,MAAa,eAAe,eAAe,OAAO,OAAO,MAAM,CAAC;;AAGhE,MAAa,UAAU,gBAAgB,GAAG,OAAO,OAAO,MAAM,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Space } from "./types.js";
2
+ /**
3
+ * The CSS `srgb-linear` space: sRGB primaries without a transfer curve. Components are red, green and blue in 0 to 1.
4
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
5
+ */
6
+ export declare const srgbLinear: Space;
7
+ //# sourceMappingURL=srgb-linear.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"srgb-linear.d.ts","names":["_$__types_js0.Space"],"sources":["../../src/color/srgb-linear.ts"],"mappings":";;;;;qBAQa,YAAAA"}
@@ -0,0 +1,12 @@
1
+ import { srgbToXyz, xyzToSrgb } from "./matrices.js";
2
+ import { rgbSpace } from "./rgb.js";
3
+ import { identity } from "./transfer.js";
4
+ // src/color/srgb-linear.ts
5
+ /**
6
+ * The CSS `srgb-linear` space: sRGB primaries without a transfer curve. Components are red, green and blue in 0 to 1.
7
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
8
+ */
9
+ const srgbLinear = rgbSpace("srgb-linear", identity, identity, srgbToXyz, xyzToSrgb);
10
+ export { srgbLinear };
11
+
12
+ //# sourceMappingURL=srgb-linear.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"srgb-linear.js","names":[],"sources":["../../src/color/srgb-linear.ts"],"sourcesContent":["import { srgbToXyz, xyzToSrgb } from './matrices.js'\nimport { rgbSpace } from './rgb.js'\nimport { identity } from './transfer.js'\n\n/**\n * The CSS `srgb-linear` space: sRGB primaries without a transfer curve. Components are red, green and blue in 0 to 1.\n * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.\n */\nexport const srgbLinear = rgbSpace('srgb-linear', identity, identity, srgbToXyz, xyzToSrgb)\n"],"mappings":";;;;;;;;AAQA,MAAa,aAAa,SAAS,eAAe,UAAU,UAAU,WAAW,SAAS"}
@@ -0,0 +1,7 @@
1
+ import { Space } from "./types.js";
2
+ /**
3
+ * The CSS `srgb` space. Components are red, green and blue in 0 to 1, with the sRGB transfer curve.
4
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
5
+ */
6
+ export declare const srgb: Space;
7
+ //# sourceMappingURL=srgb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"srgb.d.ts","names":["_$__types_js0.Space"],"sources":["../../src/color/srgb.ts"],"mappings":";;;;;qBAQa,MAAAA"}
@@ -0,0 +1,12 @@
1
+ import { srgbToXyz, xyzToSrgb } from "./matrices.js";
2
+ import { rgbSpace } from "./rgb.js";
3
+ import { srgbToGamma, srgbToLinear } from "./transfer.js";
4
+ // src/color/srgb.ts
5
+ /**
6
+ * The CSS `srgb` space. Components are red, green and blue in 0 to 1, with the sRGB transfer curve.
7
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
8
+ */
9
+ const srgb = rgbSpace("srgb", srgbToLinear, srgbToGamma, srgbToXyz, xyzToSrgb);
10
+ export { srgb };
11
+
12
+ //# sourceMappingURL=srgb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"srgb.js","names":[],"sources":["../../src/color/srgb.ts"],"sourcesContent":["import { srgbToXyz, xyzToSrgb } from './matrices.js'\nimport { rgbSpace } from './rgb.js'\nimport { srgbToGamma, srgbToLinear } from './transfer.js'\n\n/**\n * The CSS `srgb` space. Components are red, green and blue in 0 to 1, with the sRGB transfer curve.\n * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.\n */\nexport const srgb = rgbSpace('srgb', srgbToLinear, srgbToGamma, srgbToXyz, xyzToSrgb)\n"],"mappings":";;;;;;;;AAQA,MAAa,OAAO,SAAS,QAAQ,cAAc,aAAa,WAAW,SAAS"}
@@ -0,0 +1,11 @@
1
+ import { signed } from "./math.js";
2
+ // src/color/transfer.ts
3
+ const identity = (n) => n;
4
+ const srgbToLinear = signed((a) => a <= .04045 ? a / 12.92 : ((a + .055) / 1.055) ** 2.4);
5
+ const srgbToGamma = signed((a) => a > .0031308 ? 1.055 * a ** (1 / 2.4) - .055 : 12.92 * a);
6
+ const power = (gamma) => [signed((a) => a ** gamma), signed((a) => a ** (1 / gamma))];
7
+ const prophotoToLinear = signed((a) => a <= 16 / 512 ? a / 16 : a ** 1.8);
8
+ const prophotoToGamma = signed((a) => a >= 1 / 512 ? a ** (1 / 1.8) : 16 * a);
9
+ export { identity, power, prophotoToGamma, prophotoToLinear, srgbToGamma, srgbToLinear };
10
+
11
+ //# sourceMappingURL=transfer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer.js","names":[],"sources":["../../src/color/transfer.ts"],"sourcesContent":["import { signed } from './math.js'\n\nexport const identity = (n: number): number => n\n\nexport const srgbToLinear = signed((a) => (a <= 0.04045 ? a / 12.92 : ((a + 0.055) / 1.055) ** 2.4))\nexport const srgbToGamma = signed((a) => (a > 0.0031308 ? 1.055 * a ** (1 / 2.4) - 0.055 : 12.92 * a))\n\nexport const power = (gamma: number): [(n: number) => number, (n: number) => number] => [\n\tsigned((a) => a ** gamma),\n\tsigned((a) => a ** (1 / gamma))\n]\n\nexport const prophotoToLinear = signed((a) => (a <= 16 / 512 ? a / 16 : a ** 1.8))\nexport const prophotoToGamma = signed((a) => (a >= 1 / 512 ? a ** (1 / 1.8) : 16 * a))\n"],"mappings":";;AAEA,MAAa,YAAY,MAAsB;AAE/C,MAAa,eAAe,QAAQ,MAAO,KAAK,SAAU,IAAI,UAAU,IAAI,QAAS,UAAU,GAAI;AACnG,MAAa,cAAc,QAAQ,MAAO,IAAI,WAAY,QAAQ,MAAM,IAAI,OAAO,OAAQ,QAAQ,CAAE;AAErG,MAAa,SAAS,UAAkE,CACvF,QAAQ,MAAM,KAAK,KAAK,GACxB,QAAQ,MAAM,MAAM,IAAI,MAAM,CAC/B;AAEA,MAAa,mBAAmB,QAAQ,MAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,GAAI;AACjF,MAAa,kBAAkB,QAAQ,MAAO,KAAK,IAAI,MAAM,MAAM,IAAI,OAAO,KAAK,CAAE"}
@@ -0,0 +1,23 @@
1
+ /** The spaces a {@link Color} can be in. Names are the CSS ones. */
2
+ export type ColorSpaceId = 'srgb' | 'srgb-linear' | 'hsl' | 'hwb' | 'lab' | 'lch' | 'oklab' | 'oklch' | 'display-p3' | 'display-p3-linear' | 'a98-rgb' | 'prophoto-rgb' | 'rec2020' | 'xyz-d50' | 'xyz-d65';
3
+ /** A component value. `null` stands for the CSS keyword `none`. */
4
+ export type Component = number | null;
5
+ /**
6
+ * A color as plain JSON. Component ranges follow CSS: `srgb` is 0 to 1, `hsl`
7
+ * and `hwb` take hue in degrees and the rest in 0 to 100, `lab` and `lch` take
8
+ * L in 0 to 100, `oklab` and `oklch` take L in 0 to 1. A missing `alpha` is 1.
9
+ */
10
+ export interface Color {
11
+ colorSpace: ColorSpaceId;
12
+ components: Component[];
13
+ alpha?: Component;
14
+ }
15
+ /** Three numbers: the components of a color without alpha, or a point in XYZ. */
16
+ export type Vec3 = [number, number, number];
17
+ /** A color space, defined by its conversion to and from the XYZ-D65 hub. */
18
+ export interface Space {
19
+ id: ColorSpaceId;
20
+ toXyz(c: Vec3): Vec3;
21
+ fromXyz(xyz: Vec3): Vec3;
22
+ }
23
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/color/types.ts"],"mappings":";YACY;;YAkBA;;;;;;iBAOK;EAChB,YAAY;EACZ,YAAY;EACZ,QAAQ;;;YAIG;;iBAGK;EAChB,IAAI;EACJ,MAAM,GAAG,OAAO;EAChB,QAAQ,KAAK,OAAO"}
@@ -0,0 +1,16 @@
1
+ // src/color/unknown-name.ts
2
+ /**
3
+ * The error for a name a caller wrote that the library does not know: it names
4
+ * the value and lists the valid ones, in the style of `unknown color space`.
5
+ */
6
+ function unknownName(what, value, valid) {
7
+ return /* @__PURE__ */ new Error(`color-map: unknown ${what} "${String(value)}"${valid.length ? `; use one of ${valid.join(", ")}` : ""}`);
8
+ }
9
+ /** `mode` itself when it is `light` or `dark`; any other value is an unknown mode. */
10
+ function checkMode(mode) {
11
+ if (mode !== "light" && mode !== "dark") throw unknownName("mode", mode, ["light", "dark"]);
12
+ return mode;
13
+ }
14
+ export { checkMode, unknownName };
15
+
16
+ //# sourceMappingURL=unknown-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown-name.js","names":[],"sources":["../../src/color/unknown-name.ts"],"sourcesContent":["/**\n * The error for a name a caller wrote that the library does not know: it names\n * the value and lists the valid ones, in the style of `unknown color space`.\n */\nexport function unknownName(what: string, value: unknown, valid: readonly string[]): Error {\n\treturn new Error(\n\t\t`color-map: unknown ${what} \"${String(value)}\"${valid.length ? `; use one of ${valid.join(', ')}` : ''}`\n\t)\n}\n\n/** `mode` itself when it is `light` or `dark`; any other value is an unknown mode. */\nexport function checkMode<T>(mode: T): T {\n\tif (mode !== 'light' && mode !== 'dark') throw unknownName('mode', mode, ['light', 'dark'])\n\treturn mode\n}\n"],"mappings":";;;;;AAIA,SAAgB,YAAY,MAAc,OAAgB,OAAiC;CAC1F,uBAAO,IAAI,MACV,sBAAsB,KAAK,IAAI,OAAO,KAAK,EAAE,GAAG,MAAM,SAAS,gBAAgB,MAAM,KAAK,IAAI,MAAM,IACrG;AACD;;AAGA,SAAgB,UAAa,MAAY;CACxC,IAAI,SAAS,WAAW,SAAS,QAAQ,MAAM,YAAY,QAAQ,MAAM,CAAC,SAAS,MAAM,CAAC;CAC1F,OAAO;AACR"}
@@ -0,0 +1,7 @@
1
+ import { Space } from "./types.js";
2
+ /**
3
+ * The CSS `xyz-d50` space (CIE XYZ, D50 white). Components are X, Y and Z, where Y is 1 for white.
4
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
5
+ */
6
+ export declare const xyzD50: Space;
7
+ //# sourceMappingURL=xyz-d50.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xyz-d50.d.ts","names":[],"sources":["../../src/color/xyz-d50.ts"],"mappings":";;;;;qBAQa,QAAQ"}
@@ -0,0 +1,15 @@
1
+ import { multiply } from "./math.js";
2
+ import { d50ToD65, d65ToD50 } from "./matrices.js";
3
+ // src/color/xyz-d50.ts
4
+ /**
5
+ * The CSS `xyz-d50` space (CIE XYZ, D50 white). Components are X, Y and Z, where Y is 1 for white.
6
+ * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.
7
+ */
8
+ const xyzD50 = {
9
+ id: "xyz-d50",
10
+ toXyz: (c) => multiply(d50ToD65, c[0], c[1], c[2]),
11
+ fromXyz: (xyz) => multiply(d65ToD50, xyz[0], xyz[1], xyz[2])
12
+ };
13
+ export { xyzD50 };
14
+
15
+ //# sourceMappingURL=xyz-d50.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xyz-d50.js","names":[],"sources":["../../src/color/xyz-d50.ts"],"sourcesContent":["import { multiply } from './math.js'\nimport { d50ToD65, d65ToD50 } from './matrices.js'\nimport type { Space } from './types.js'\n\n/**\n * The CSS `xyz-d50` space (CIE XYZ, D50 white). Components are X, Y and Z, where Y is 1 for white.\n * Pass it to `createConverter` and to the narrow helpers such as `createMix` and `createToGamut`.\n */\nexport const xyzD50: Space = {\n\tid: 'xyz-d50',\n\ttoXyz: (c) => multiply(d50ToD65, c[0], c[1], c[2]),\n\tfromXyz: (xyz) => multiply(d65ToD50, xyz[0], xyz[1], xyz[2])\n}\n"],"mappings":";;;;;;;AAQA,MAAa,SAAgB;CAC5B,IAAI;CACJ,QAAQ,MAAM,SAAS,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;CACjD,UAAU,QAAQ,SAAS,UAAU,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;AAC5D"}
@@ -0,0 +1,4 @@
1
+ import { Space } from "./types.js";
2
+ /** The hub every other space converts through. */
3
+ export declare const xyzD65: Space;
4
+ //# sourceMappingURL=xyz-d65.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xyz-d65.d.ts","names":[],"sources":["../../src/color/xyz-d65.ts"],"mappings":";;qBAGa,QAAQ"}
@@ -0,0 +1,10 @@
1
+ // src/color/xyz-d65.ts
2
+ /** The hub every other space converts through. */
3
+ const xyzD65 = {
4
+ id: "xyz-d65",
5
+ toXyz: (c) => c,
6
+ fromXyz: (xyz) => xyz
7
+ };
8
+ export { xyzD65 };
9
+
10
+ //# sourceMappingURL=xyz-d65.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xyz-d65.js","names":[],"sources":["../../src/color/xyz-d65.ts"],"sourcesContent":["import type { Space } from './types.js'\n\n/** The hub every other space converts through. */\nexport const xyzD65: Space = {\n\tid: 'xyz-d65',\n\ttoXyz: (c) => c,\n\tfromXyz: (xyz) => xyz\n}\n"],"mappings":";;AAGA,MAAa,SAAgB;CAC5B,IAAI;CACJ,QAAQ,MAAM;CACd,UAAU,QAAQ;AACnB"}
package/esm/index.d.ts CHANGED
@@ -1,6 +1,63 @@
1
- import { Alpha, ColorMap, RGB, RGBA } from "./interfaces.js";
2
- import { createColors } from "./createColors.js";
3
- import { createColorsFromMap } from "./createColorsFromMap.js";
4
- import { rgbaString } from "./rgbaString.js";
5
- import { rgbHex } from "./rgbHex.js";
6
- export { type Alpha, type ColorMap, type RGB, type RGBA, createColors, createColorsFromMap, rgbHex, rgbaString };
1
+ import { Color, ColorSpaceId, Component, Space, Vec3 } from "./color/types.js";
2
+ import { a98Rgb } from "./color/a98-rgb.js";
3
+ import { fromArgb, toArgb } from "./color/argb.js";
4
+ import { convertComponents, createConverter } from "./color/convert.js";
5
+ import { createDeltaEOk, createEquals, deltaEOk, equals } from "./color/compare.js";
6
+ import { ContrastAlgorithm, ContrastFn, ContrastOption, FindContrastOptions, FoundContrast, OnColorOptions, contrast, createContrast, createFindContrast, createMeets, createOnColor, findContrast, meets, onColor, wcag2 } from "./color/contrast.js";
7
+ import { displayP3 } from "./color/display-p3.js";
8
+ import { displayP3Linear } from "./color/display-p3-linear.js";
9
+ import { HueMethod, MixOptions, createMix, mix } from "./color/mix.js";
10
+ import { ColorExpr, parseExpr } from "./color/expr.js";
11
+ import { GamutId, ToGamutOptions, createInGamut, createToGamut, inGamut, toGamut } from "./color/gamut.js";
12
+ import { hsl } from "./color/hsl.js";
13
+ import { hwb } from "./color/hwb.js";
14
+ import { lab } from "./color/lab.js";
15
+ import { lch } from "./color/lch.js";
16
+ import { oklab } from "./color/oklab.js";
17
+ import { oklch } from "./color/oklch.js";
18
+ import { parse } from "./color/parse.js";
19
+ import { prophotoRgb } from "./color/prophoto-rgb.js";
20
+ import { rec2020 } from "./color/rec2020.js";
21
+ import { ResolveContext, resolve } from "./color/resolve.js";
22
+ import { ToCssOptions, createToHex, toCss, toHex } from "./color/serialize.js";
23
+ import { convert, spaces } from "./color/spaces.js";
24
+ import { srgb } from "./color/srgb.js";
25
+ import { srgbLinear } from "./color/srgb-linear.js";
26
+ import { xyzD50 } from "./color/xyz-d50.js";
27
+ import { xyzD65 } from "./color/xyz-d65.js";
28
+ import { Alpha as Alpha$1, ColorMap as ColorMap$1, RGB as RGB$1, RGBA as RGBA$1 } from "./legacy/interfaces.js";
29
+ import { createColors as createColors$1 } from "./legacy/createColors.js";
30
+ import { createColorsFromMap as createColorsFromMap$1 } from "./legacy/createColorsFromMap.js";
31
+ import { rgbaString as rgbaString$1 } from "./legacy/rgbaString.js";
32
+ import { rgbHex as rgbHex$1 } from "./legacy/rgbHex.js";
33
+ import { DarkStrategy, DarkVariantOptions, darkVariant } from "./palette/dark.js";
34
+ import { HarmonizeOptions, HarmonyOptions, HarmonyScheme, HarmonySpace, harmonize, harmony, inverse } from "./palette/harmony.js";
35
+ import { RolePair, SemanticPalette, SemanticPaletteOptions, SemanticRole, semanticPalette } from "./palette/semantic.js";
36
+ import { PaletteIssue, PaletteLike, ValidateOptions, ValidateResult, validate } from "./palette/validate.js";
37
+ import { BrandScaleOptions, scaleFromBrand } from "./scale/brand.js";
38
+ import { ContrastScaleOptions, ContrastStep, createContrastScale } from "./scale/contrast-scale.js";
39
+ import { GradientOptions, GradientStop, createGradient } from "./scale/gradient.js";
40
+ import { ScaleOptions, ScalePreset, createScale } from "./scale/scale.js";
41
+ import { MATERIAL_TONES, TonalPaletteOptions, lstar, tonalPalette, toneColor } from "./scale/tone.js";
42
+ import { TokenTree } from "./tokens/tokens.js";
43
+ import { CssVariablesOptions, toCssVariables } from "./tokens/css.js";
44
+ import { DtcgColorValue, DtcgGroup, DtcgOptions, DtcgToken, toDtcg, toDtcgValue } from "./tokens/dtcg.js";
45
+ import { TailwindThemeOptions, toTailwindTheme } from "./tokens/tailwind.js";
46
+ /** @deprecated Import it from `color-map/legacy`. The root stops exporting it in 3.0. */
47
+ export declare const createColors: typeof createColors$1;
48
+ /** @deprecated Use `createGradient` from `color-map`, or import it from `color-map/legacy`. The root stops exporting it in 3.0. */
49
+ export declare const createColorsFromMap: typeof createColorsFromMap$1;
50
+ /** @deprecated Import it from `color-map/legacy`, or use `toHex` from `color-map`. The root stops exporting it in 3.0. */
51
+ export declare const rgbHex: typeof rgbHex$1;
52
+ /** @deprecated Import it from `color-map/legacy`, or use `toCss` from `color-map`. The root stops exporting it in 3.0. */
53
+ export declare const rgbaString: typeof rgbaString$1;
54
+ /** @deprecated Import it from `color-map/legacy`. The root stops exporting it in 3.0. */
55
+ export type Alpha = Alpha$1;
56
+ /** @deprecated Import it from `color-map/legacy`. The root stops exporting it in 3.0. */
57
+ export type ColorMap = ColorMap$1;
58
+ /** @deprecated Import it from `color-map/legacy`. The root stops exporting it in 3.0. */
59
+ export type RGB = RGB$1;
60
+ /** @deprecated Import it from `color-map/legacy`. The root stops exporting it in 3.0. */
61
+ export type RGBA = RGBA$1;
62
+ export { type BrandScaleOptions, type Color, type ColorExpr, type ColorSpaceId, type Component, type ContrastAlgorithm, type ContrastFn, type ContrastOption, type ContrastScaleOptions, type ContrastStep, type CssVariablesOptions, type DarkStrategy, type DarkVariantOptions, type DtcgColorValue, type DtcgGroup, type DtcgOptions, type DtcgToken, type FindContrastOptions, type FoundContrast, type GamutId, type GradientOptions, type GradientStop, type HarmonizeOptions, type HarmonyOptions, type HarmonyScheme, type HarmonySpace, type HueMethod, MATERIAL_TONES, type MixOptions, type OnColorOptions, type PaletteIssue, type PaletteLike, type ResolveContext, type RolePair, type ScaleOptions, type ScalePreset, type SemanticPalette, type SemanticPaletteOptions, type SemanticRole, type Space, type TailwindThemeOptions, type ToCssOptions, type ToGamutOptions, type TokenTree, type TonalPaletteOptions, type ValidateOptions, type ValidateResult, type Vec3, a98Rgb, contrast, convert, convertComponents, createContrast, createContrastScale, createConverter, createDeltaEOk, createEquals, createFindContrast, createGradient, createInGamut, createMeets, createMix, createOnColor, createScale, createToGamut, createToHex, darkVariant, deltaEOk, displayP3, displayP3Linear, equals, findContrast, fromArgb, harmonize, harmony, hsl, hwb, inGamut, inverse, lab, lch, lstar, meets, mix, oklab, oklch, onColor, parse, parseExpr, prophotoRgb, rec2020, resolve, scaleFromBrand, semanticPalette, spaces, srgb, srgbLinear, toArgb, toCss, toCssVariables, toDtcg, toDtcgValue, toGamut, toHex, toTailwindTheme, tonalPalette, toneColor, validate, wcag2, xyzD50, xyzD65 };
63
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":["legacyCreateColors","legacyCreateColorsFromMap","legacyRgbHex","legacyRgbaString","LegacyAlpha","LegacyColorMap","LegacyRGB","LegacyRGBA"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAqBa,qBAAYA;;qBAEZ,4BAAmBC;;qBAEnB,eAAMC;;qBAEN,mBAAUC;;YAGX,QAAQC;;YAER,WAAWC;;YAEX,MAAMC;;YAEN,OAAOC"}