chromonym 1.0.1 → 1.1.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 (74) hide show
  1. package/README.md +165 -3
  2. package/dist/colorspaces/index.d.ts +4 -0
  3. package/dist/colorspaces/index.d.ts.map +1 -0
  4. package/dist/colorspaces/index.js +4 -0
  5. package/dist/colorspaces/index.js.map +1 -0
  6. package/dist/colorspaces/pantone.d.ts +919 -0
  7. package/dist/colorspaces/pantone.d.ts.map +1 -0
  8. package/dist/colorspaces/pantone.js +918 -0
  9. package/dist/colorspaces/pantone.js.map +1 -0
  10. package/dist/colorspaces/web.d.ts +156 -0
  11. package/dist/colorspaces/web.d.ts.map +1 -0
  12. package/dist/colorspaces/web.js +155 -0
  13. package/dist/colorspaces/web.js.map +1 -0
  14. package/dist/colorspaces/x11.d.ts +667 -0
  15. package/dist/colorspaces/x11.d.ts.map +1 -0
  16. package/dist/colorspaces/x11.js +666 -0
  17. package/dist/colorspaces/x11.js.map +1 -0
  18. package/dist/conversions/hex.d.ts +13 -0
  19. package/dist/conversions/hex.d.ts.map +1 -0
  20. package/dist/conversions/hex.js +39 -0
  21. package/dist/conversions/hex.js.map +1 -0
  22. package/dist/conversions/hsl.d.ts +12 -0
  23. package/dist/conversions/hsl.d.ts.map +1 -0
  24. package/dist/conversions/hsl.js +90 -0
  25. package/dist/conversions/hsl.js.map +1 -0
  26. package/dist/conversions/hsv.d.ts +12 -0
  27. package/dist/conversions/hsv.d.ts.map +1 -0
  28. package/dist/conversions/hsv.js +85 -0
  29. package/dist/conversions/hsv.js.map +1 -0
  30. package/dist/conversions/index.d.ts +6 -0
  31. package/dist/conversions/index.d.ts.map +1 -0
  32. package/dist/conversions/index.js +6 -0
  33. package/dist/conversions/index.js.map +1 -0
  34. package/dist/conversions/pantone.d.ts +14 -0
  35. package/dist/conversions/pantone.d.ts.map +1 -0
  36. package/dist/conversions/pantone.js +63 -0
  37. package/dist/conversions/pantone.js.map +1 -0
  38. package/dist/conversions/rgb.d.ts +13 -0
  39. package/dist/conversions/rgb.d.ts.map +1 -0
  40. package/dist/conversions/rgb.js +46 -0
  41. package/dist/conversions/rgb.js.map +1 -0
  42. package/dist/convert.d.ts +10 -0
  43. package/dist/convert.d.ts.map +1 -0
  44. package/dist/convert.js +51 -0
  45. package/dist/convert.js.map +1 -0
  46. package/dist/detectFormat.d.ts +9 -0
  47. package/dist/detectFormat.d.ts.map +1 -0
  48. package/dist/detectFormat.js +47 -0
  49. package/dist/detectFormat.js.map +1 -0
  50. package/dist/identify.d.ts +12 -0
  51. package/dist/identify.d.ts.map +1 -0
  52. package/dist/identify.js +44 -0
  53. package/dist/identify.js.map +1 -0
  54. package/dist/index.d.ts +14 -337
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +15 -267
  57. package/dist/index.js.map +1 -1
  58. package/dist/math/euclideanDistance.d.ts +9 -0
  59. package/dist/math/euclideanDistance.d.ts.map +1 -0
  60. package/dist/math/euclideanDistance.js +13 -0
  61. package/dist/math/euclideanDistance.js.map +1 -0
  62. package/dist/math/index.d.ts +2 -0
  63. package/dist/math/index.d.ts.map +1 -0
  64. package/dist/math/index.js +4 -0
  65. package/dist/math/index.js.map +1 -0
  66. package/dist/resolve.d.ts +14 -0
  67. package/dist/resolve.d.ts.map +1 -0
  68. package/dist/resolve.js +49 -0
  69. package/dist/resolve.js.map +1 -0
  70. package/dist/types.d.ts +42 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +4 -0
  73. package/dist/types.js.map +1 -0
  74. package/package.json +2 -1
package/README.md CHANGED
@@ -1,17 +1,166 @@
1
1
  # chromonym
2
2
 
3
- Color naming tool — resolve RGB or Hex color input to a human-readable name.
3
+ [![CI](https://github.com/simiancraft/chromonym/actions/workflows/ci.yml/badge.svg)](https://github.com/simiancraft/chromonym/actions/workflows/ci.yml)
4
+ [![codecov](https://codecov.io/gh/simiancraft/chromonym/branch/main/graph/badge.svg)](https://codecov.io/gh/simiancraft/chromonym)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![semantic-release: conventional](https://img.shields.io/badge/semantic--release-conventional-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
7
+ [![Checked with Biome](https://img.shields.io/badge/Checked_with-Biome-60a5fa?style=flat&logo=biome)](https://biomejs.dev)
4
8
 
5
- > Scaffold stage — public API is not yet defined.
9
+ Identify, resolve, and convert colors across CSS, X11, and Pantone colorspaces.
10
+
11
+ ```ts
12
+ import { identify, resolve, convert } from 'chromonym';
13
+
14
+ identify('#ff0000') // 'red'
15
+ resolve('crimson') // '#dc143c'
16
+ resolve('185 C', { colorspace: 'pantone' }) // '#e4002b'
17
+ convert('#ff0000', { format: 'RGB' }) // 'rgb(255, 0, 0)'
18
+ convert({ r: 255, g: 0, b: 0 }, { format: 'HSL' })// 'hsl(0, 100%, 50%)'
19
+ ```
6
20
 
7
21
  ## Install
8
22
 
9
23
  ```sh
10
24
  bun add chromonym
11
- # or
12
25
  npm install chromonym
13
26
  ```
14
27
 
28
+ ## API
29
+
30
+ Three primary functions. All accept an optional `opts` object; defaults fire when omitted.
31
+
32
+ ### `identify(input, opts?)`
33
+
34
+ **Color → name.** Finds the nearest-match name in the chosen colorspace using Euclidean distance in RGB.
35
+
36
+ ```ts
37
+ function identify(
38
+ input: ColorInput,
39
+ opts?: { colorspace?: ColorspaceName },
40
+ ): string | null
41
+ ```
42
+
43
+ - **Default colorspace**: `'web'`.
44
+ - Returns the matched name, or `null` if input is unrecognized (`detectFormat` returns `'UNKNOWN'`).
45
+ - Ties are broken by the first entry encountered in the colorspace data.
46
+
47
+ ```ts
48
+ identify('#ff0000') // 'red'
49
+ identify([255, 0, 0]) // 'red'
50
+ identify({ r: 250, g: 20, b: 60 }) // 'crimson' (nearest)
51
+ identify('#ff0000', { colorspace: 'x11' }) // 'red' (or 'red1', X11 has numbered variants)
52
+ identify('#ff0000', { colorspace: 'pantone' }) // nearest Pantone C code, e.g. '185C'
53
+ ```
54
+
55
+ ### `resolve(name, opts?)`
56
+
57
+ **Name → color.** Normalizes the input (lowercases it, strips all non-alphanumeric characters), looks up the canonical key in the chosen colorspace, and returns the value in the chosen format.
58
+
59
+ ```ts
60
+ function resolve(
61
+ name: string,
62
+ opts?: { colorspace?: ColorspaceName; format?: ColorFormat },
63
+ ): ColorValue | null
64
+ ```
65
+
66
+ - **Default colorspace**: `'web'`.
67
+ - **Default format**: `'HEX'`.
68
+ - Returns `null` if the normalized name isn't in the colorspace.
69
+ - Normalization lets users pass `'Alice Blue'`, `'alice-blue'`, `'ALICEBLUE'`, `'Pantone 185 C'` etc. — all resolved identically.
70
+
71
+ ```ts
72
+ resolve('crimson') // '#dc143c'
73
+ resolve('Alice Blue') // '#f0f8ff'
74
+ resolve('alice-blue!') // '#f0f8ff'
75
+ resolve('185 C', { colorspace: 'pantone' }) // '#e4002b'
76
+ resolve('Pantone 185 C', { colorspace: 'pantone' })// '#e4002b' (same, normalized)
77
+ resolve('crimson', { format: 'RGB' }) // 'rgb(220, 20, 60)'
78
+ resolve('crimson', { format: 'RGBA' }) // { r: 220, g: 20, b: 60, a: 1 }
79
+ resolve('not-a-color') // null
80
+ ```
81
+
82
+ ### `convert(input, opts?)`
83
+
84
+ **Color → color in a different format.** Detects the input format, normalizes to the canonical internal `Rgba` representation, and returns the value in the target format. Colorspace-independent.
85
+
86
+ ```ts
87
+ function convert(
88
+ input: ColorInput,
89
+ opts?: { format?: ColorFormat },
90
+ ): ColorValue
91
+ ```
92
+
93
+ - **Default format**: `'HEX'`.
94
+ - Throws if input format is unrecognized.
95
+ - Alpha information is preserved when converting into RGBA/RGB(A) string forms, and discarded for HEX (6-digit) / HSL / HSV / PANTONE output.
96
+
97
+ ```ts
98
+ convert('#ff0000') // '#ff0000' (identity)
99
+ convert('#ff0000', { format: 'RGB' }) // 'rgb(255, 0, 0)'
100
+ convert('#ff0000', { format: 'RGBA' }) // { r: 255, g: 0, b: 0, a: 1 }
101
+ convert([255, 0, 0], { format: 'HEX' }) // '#ff0000'
102
+ convert('rgb(255, 0, 0)', { format: 'HSL' }) // 'hsl(0, 100%, 50%)'
103
+ convert({ h: 0, s: 100, l: 50 }, { format: 'HEX' })// '#ff0000'
104
+ convert('185 C', { format: 'HEX' }) // '#e4002b'
105
+ convert('#e4002b', { format: 'PANTONE' }) // '185C' (nearest Pantone C)
106
+ ```
107
+
108
+ ## Colorspaces
109
+
110
+ | Name | Entries | Source |
111
+ |---|---|---|
112
+ | `'web'` (default) | 148 | CSS Color Module Level 4 named colors |
113
+ | `'x11'` | 658 | X.Org `rgb.txt` (public domain) |
114
+ | `'pantone'` | 907 | Pantone Coated (C) — community approximations (not Pantone-licensed) |
115
+
116
+ Each colorspace is a pure data object: `Record<string, HexColor>`. Importable directly:
117
+
118
+ ```ts
119
+ import { web, x11, pantone } from 'chromonym';
120
+ web.crimson // '#dc143c'
121
+ ```
122
+
123
+ ## Formats
124
+
125
+ Format keys are SCREAMING_CAPS — they are used as dispatch keys internally.
126
+
127
+ | Key | Input accepted | Output shape |
128
+ |---|---|---|
129
+ | `'HEX'` | `'#rgb'`, `'#rrggbb'`, `'#rrggbbaa'` | `'#rrggbb'` string |
130
+ | `'RGB'` | `'rgb(r, g, b)'`, `[r, g, b]`, `{ r, g, b }` | `'rgb(r, g, b)'` string |
131
+ | `'RGBA'` | `'rgba(r, g, b, a)'`, `[r, g, b, a]`, `{ r, g, b, a }` | `{ r, g, b, a }` object |
132
+ | `'HSL'` | `'hsl(h, s%, l%)'`, `{ h, s, l }` | `'hsl(h, s%, l%)'` string |
133
+ | `'HSV'` | `'hsv(h, s%, v%)'`, `{ h, s, v }` | `'hsv(h, s%, v%)'` string |
134
+ | `'PANTONE'` | `'185 C'`, `'185C'`, `'Pantone 185 C'`, etc. | `'185C'`-style string |
135
+
136
+ The runtime set `COLOR_FORMATS` is exported for enumeration / membership checks.
137
+
138
+ ## Utilities
139
+
140
+ - **`detectFormat(input): DetectedFormat`** — runtime format detection. Returns one of the format keys or `'UNKNOWN'`.
141
+ - **`COLOR_FORMATS: ReadonlySet<ColorFormat>`** — the Set of valid format keys.
142
+ - **Per-format converters** (tree-shakeable) — `hexToRgba`, `rgbaToHex`, `rgbToRgba`, `rgbaToRgb`, `hslToRgba`, `rgbaToHsl`, `hsvToRgba`, `rgbaToHsv`, `pantoneToRgba`, `rgbaToPantone`. Use these directly if you only need one conversion and want maximum tree-shaking.
143
+
144
+ ## Tree-shaking
145
+
146
+ - `sideEffects: false` in `package.json`.
147
+ - All exports are named; no default export.
148
+ - Barrel uses explicit re-exports.
149
+ - Importing `{ resolve }` or `{ identify }` pulls in all three colorspaces (necessary for the string-keyed `colorspace` option). For strict tree-shaking of colorspace data, use the low-level converters and colorspace objects directly.
150
+
151
+ ## Types
152
+
153
+ All types are re-exported from the root:
154
+
155
+ ```ts
156
+ import type {
157
+ ColorInput, ColorValue, ColorFormat, ColorspaceName,
158
+ HexColor, Rgba, RgbInput, RgbaInput, HslInput, HsvInput, PantoneCode,
159
+ Colorspace,
160
+ WebColorName, X11ColorName, PantoneColorName,
161
+ } from 'chromonym';
162
+ ```
163
+
15
164
  ## Development
16
165
 
17
166
  ```sh
@@ -22,6 +171,19 @@ bun test
22
171
  bun run build
23
172
  ```
24
173
 
174
+ Regenerating colorspace data:
175
+
176
+ ```sh
177
+ bun run scripts/generate-x11.ts # reads /usr/share/X11/rgb.txt
178
+ bun run scripts/generate-pantone.ts # reads color_library (MIT dependency)
179
+ ```
180
+
181
+ ## Coverage
182
+
183
+ [![Coverage sunburst](https://codecov.io/github/simiancraft/chromonym/graphs/sunburst.svg?token=HYWM6G66YE)](https://codecov.io/github/simiancraft/chromonym)
184
+
185
+ Each ring is a directory; each leaf is a file. Green is covered, red is gaps.
186
+
25
187
  ## License
26
188
 
27
189
  MIT © [the-simian](https://github.com/the-simian)
@@ -0,0 +1,4 @@
1
+ export { type PantoneColorName, pantone } from './pantone';
2
+ export { type WebColorName, web } from './web';
3
+ export { type X11ColorName, x11 } from './x11';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/colorspaces/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,KAAK,YAAY,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { pantone } from './pantone';
2
+ export { web } from './web';
3
+ export { x11 } from './x11';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/colorspaces/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAqB,GAAG,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAqB,GAAG,EAAE,MAAM,OAAO,CAAC"}