chromonym 1.0.1 → 1.2.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.
- package/NOTICE.md +39 -0
- package/README.md +240 -3
- package/dist/colorspaces/index.d.ts +4 -0
- package/dist/colorspaces/index.d.ts.map +1 -0
- package/dist/colorspaces/index.js +4 -0
- package/dist/colorspaces/index.js.map +1 -0
- package/dist/colorspaces/pantone.d.ts +919 -0
- package/dist/colorspaces/pantone.d.ts.map +1 -0
- package/dist/colorspaces/pantone.js +918 -0
- package/dist/colorspaces/pantone.js.map +1 -0
- package/dist/colorspaces/registry.d.ts +26 -0
- package/dist/colorspaces/registry.d.ts.map +1 -0
- package/dist/colorspaces/registry.js +36 -0
- package/dist/colorspaces/registry.js.map +1 -0
- package/dist/colorspaces/web.d.ts +156 -0
- package/dist/colorspaces/web.d.ts.map +1 -0
- package/dist/colorspaces/web.js +155 -0
- package/dist/colorspaces/web.js.map +1 -0
- package/dist/colorspaces/x11.d.ts +667 -0
- package/dist/colorspaces/x11.d.ts.map +1 -0
- package/dist/colorspaces/x11.js +666 -0
- package/dist/colorspaces/x11.js.map +1 -0
- package/dist/conversions/hex.d.ts +13 -0
- package/dist/conversions/hex.d.ts.map +1 -0
- package/dist/conversions/hex.js +40 -0
- package/dist/conversions/hex.js.map +1 -0
- package/dist/conversions/hsl.d.ts +12 -0
- package/dist/conversions/hsl.d.ts.map +1 -0
- package/dist/conversions/hsl.js +72 -0
- package/dist/conversions/hsl.js.map +1 -0
- package/dist/conversions/hsv.d.ts +12 -0
- package/dist/conversions/hsv.d.ts.map +1 -0
- package/dist/conversions/hsv.js +67 -0
- package/dist/conversions/hsv.js.map +1 -0
- package/dist/conversions/index.d.ts +6 -0
- package/dist/conversions/index.d.ts.map +1 -0
- package/dist/conversions/index.js +6 -0
- package/dist/conversions/index.js.map +1 -0
- package/dist/conversions/pantone.d.ts +17 -0
- package/dist/conversions/pantone.d.ts.map +1 -0
- package/dist/conversions/pantone.js +27 -0
- package/dist/conversions/pantone.js.map +1 -0
- package/dist/conversions/rgb.d.ts +15 -0
- package/dist/conversions/rgb.d.ts.map +1 -0
- package/dist/conversions/rgb.js +57 -0
- package/dist/conversions/rgb.js.map +1 -0
- package/dist/convert.d.ts +21 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +69 -0
- package/dist/convert.js.map +1 -0
- package/dist/detectFormat.d.ts +17 -0
- package/dist/detectFormat.d.ts.map +1 -0
- package/dist/detectFormat.js +59 -0
- package/dist/detectFormat.js.map +1 -0
- package/dist/identify.d.ts +20 -0
- package/dist/identify.d.ts.map +1 -0
- package/dist/identify.js +29 -0
- package/dist/identify.js.map +1 -0
- package/dist/index.d.ts +14 -337
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -267
- package/dist/index.js.map +1 -1
- package/dist/indexing.d.ts +44 -0
- package/dist/indexing.d.ts.map +1 -0
- package/dist/indexing.js +140 -0
- package/dist/indexing.js.map +1 -0
- package/dist/math/clamp.d.ts +11 -0
- package/dist/math/clamp.d.ts.map +1 -0
- package/dist/math/clamp.js +18 -0
- package/dist/math/clamp.js.map +1 -0
- package/dist/math/colorSpace.d.ts +39 -0
- package/dist/math/colorSpace.d.ts.map +1 -0
- package/dist/math/colorSpace.js +85 -0
- package/dist/math/colorSpace.js.map +1 -0
- package/dist/math/deltaE.d.ts +47 -0
- package/dist/math/deltaE.d.ts.map +1 -0
- package/dist/math/deltaE.js +185 -0
- package/dist/math/deltaE.js.map +1 -0
- package/dist/math/euclideanDistance.d.ts +16 -0
- package/dist/math/euclideanDistance.d.ts.map +1 -0
- package/dist/math/euclideanDistance.js +22 -0
- package/dist/math/euclideanDistance.js.map +1 -0
- package/dist/math/hueSector.d.ts +15 -0
- package/dist/math/hueSector.d.ts.map +1 -0
- package/dist/math/hueSector.js +27 -0
- package/dist/math/hueSector.js.map +1 -0
- package/dist/resolve.d.ts +14 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +26 -0
- package/dist/resolve.js.map +1 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -5
package/dist/index.js
CHANGED
|
@@ -1,268 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'rgb(255,153,51)',
|
|
17
|
-
'rgb(255,178,102)',
|
|
18
|
-
'rgb(255,204,153)',
|
|
19
|
-
],
|
|
20
|
-
yellow: [
|
|
21
|
-
'rgb(102,102,0)',
|
|
22
|
-
'rgb(153,153,0)',
|
|
23
|
-
'rgb(204,204,0)',
|
|
24
|
-
'rgb(255,255,0)',
|
|
25
|
-
'rgb(255,255,51)',
|
|
26
|
-
'rgb(255,255,102)',
|
|
27
|
-
'rgb(255,255,153)',
|
|
28
|
-
'rgb(255,255,204)',
|
|
29
|
-
],
|
|
30
|
-
green: [
|
|
31
|
-
'rgb(124,252,0)',
|
|
32
|
-
'rgb(127,255,0)',
|
|
33
|
-
'rgb(50,205,50)',
|
|
34
|
-
'rgb(0,255,0)',
|
|
35
|
-
'rgb(34,139,34)',
|
|
36
|
-
'rgb(0,128,0)',
|
|
37
|
-
'rgb(0,100,0)',
|
|
38
|
-
'rgb(173,255,47)',
|
|
39
|
-
'rgb(154,205,50)',
|
|
40
|
-
'rgb(0,255,127)',
|
|
41
|
-
'rgb(0,250,154)',
|
|
42
|
-
'rgb(144,238,144)',
|
|
43
|
-
'rgb(152,251,152)',
|
|
44
|
-
'rgb(143,188,143)',
|
|
45
|
-
'rgb(60,179,113)',
|
|
46
|
-
'rgb(46,139,87)',
|
|
47
|
-
'rgb(128,128,0)',
|
|
48
|
-
'rgb(85,107,47)',
|
|
49
|
-
'rgb(107,142,35)',
|
|
50
|
-
'rgb(2,166,165)',
|
|
51
|
-
'rgb(13,125,126)',
|
|
52
|
-
],
|
|
53
|
-
blue: [
|
|
54
|
-
'rgb(0,0,102)',
|
|
55
|
-
'rgb(0,0,153)',
|
|
56
|
-
'rgb(0,0,255)',
|
|
57
|
-
'rgb(51,51,255)',
|
|
58
|
-
'rgb(102,102,255)',
|
|
59
|
-
'rgb(0,51,102)',
|
|
60
|
-
'rgb(0,76,153)',
|
|
61
|
-
'rgb(0,102,204)',
|
|
62
|
-
'rgb(0,128,255)',
|
|
63
|
-
'rgb(51,153,255)',
|
|
64
|
-
'rgb(102,178,255)',
|
|
65
|
-
'rgb(0,204,204)',
|
|
66
|
-
'rgb(0,255,255)',
|
|
67
|
-
'rgb(51,255,255)',
|
|
68
|
-
'rgb(153,255,255)',
|
|
69
|
-
'rgb(204,229,255)',
|
|
70
|
-
'rgb(196,218,242)',
|
|
71
|
-
],
|
|
72
|
-
white: [
|
|
73
|
-
'rgb(255,255,255)',
|
|
74
|
-
'rgb(255,250,250)',
|
|
75
|
-
'rgb(240,255,240)',
|
|
76
|
-
'rgb(245,255,250)',
|
|
77
|
-
'rgb(255,255,240)',
|
|
78
|
-
'rgb(196,222,237)',
|
|
79
|
-
'rgb(254,249,191)',
|
|
80
|
-
'rgb(169,199,209)',
|
|
81
|
-
],
|
|
82
|
-
pink: [
|
|
83
|
-
'rgb(51,0,51)',
|
|
84
|
-
'rgb(102,0,102)',
|
|
85
|
-
'rgb(153,0,153)',
|
|
86
|
-
'rgb(204,0,204)',
|
|
87
|
-
'rgb(255,0,255)',
|
|
88
|
-
'rgb(255,51,255)',
|
|
89
|
-
'rgb(255,102,255)',
|
|
90
|
-
'rgb(255,153,255)',
|
|
91
|
-
'rgb(255,204,255)',
|
|
92
|
-
'rgb(251,140,173)',
|
|
93
|
-
'rgb(211,78,125)',
|
|
94
|
-
],
|
|
95
|
-
black: ['rgb(0,0,0)', 'rgb(32,32,32)'],
|
|
96
|
-
grey: [
|
|
97
|
-
'rgb(64,64,64)',
|
|
98
|
-
'rgb(96,96,96)',
|
|
99
|
-
'rgb(128,128,128)',
|
|
100
|
-
'rgb(160,160,160)',
|
|
101
|
-
'rgb(192,192,192)',
|
|
102
|
-
],
|
|
103
|
-
purple: [
|
|
104
|
-
'rgb(51,0,102)',
|
|
105
|
-
'rgb(76,0,153)',
|
|
106
|
-
'rgb(102,0,204)',
|
|
107
|
-
'rgb(127,0,255)',
|
|
108
|
-
'rgb(153,51,255)',
|
|
109
|
-
'rgb(178,102,255)',
|
|
110
|
-
'rgb(204,153,255)',
|
|
111
|
-
],
|
|
112
|
-
};
|
|
113
|
-
export const cssColorList = {
|
|
114
|
-
aliceblue: '#f0f8ff',
|
|
115
|
-
antiquewhite: '#faebd7',
|
|
116
|
-
aqua: '#00ffff',
|
|
117
|
-
aquamarine: '#7fffd4',
|
|
118
|
-
azure: '#f0ffff',
|
|
119
|
-
beige: '#f5f5dc',
|
|
120
|
-
bisque: '#ffe4c4',
|
|
121
|
-
black: '#000000',
|
|
122
|
-
blanchedalmond: '#ffebcd',
|
|
123
|
-
blue: '#0000ff',
|
|
124
|
-
blueviolet: '#8a2be2',
|
|
125
|
-
brown: '#a52a2a',
|
|
126
|
-
burlywood: '#deb887',
|
|
127
|
-
cadetblue: '#5f9ea0',
|
|
128
|
-
chartreuse: '#7fff00',
|
|
129
|
-
chocolate: '#d2691e',
|
|
130
|
-
coral: '#ff7f50',
|
|
131
|
-
cornflowerblue: '#6495ed',
|
|
132
|
-
cornsilk: '#fff8dc',
|
|
133
|
-
crimson: '#dc143c',
|
|
134
|
-
cyan: '#00ffff',
|
|
135
|
-
darkblue: '#00008b',
|
|
136
|
-
darkcyan: '#008b8b',
|
|
137
|
-
darkgoldenrod: '#b8860b',
|
|
138
|
-
darkgray: '#a9a9a9',
|
|
139
|
-
darkgreen: '#006400',
|
|
140
|
-
darkgrey: '#a9a9a9',
|
|
141
|
-
darkkhaki: '#bdb76b',
|
|
142
|
-
darkmagenta: '#8b008b',
|
|
143
|
-
darkolivegreen: '#556b2f',
|
|
144
|
-
darkorange: '#ff8c00',
|
|
145
|
-
darkorchid: '#9932cc',
|
|
146
|
-
darkred: '#8b0000',
|
|
147
|
-
darksalmon: '#e9967a',
|
|
148
|
-
darkseagreen: '#8fbc8f',
|
|
149
|
-
darkslateblue: '#483d8b',
|
|
150
|
-
darkslategray: '#2f4f4f',
|
|
151
|
-
darkslategrey: '#2f4f4f',
|
|
152
|
-
darkturquoise: '#00ced1',
|
|
153
|
-
darkviolet: '#9400d3',
|
|
154
|
-
deeppink: '#ff1493',
|
|
155
|
-
deepskyblue: '#00bfff',
|
|
156
|
-
dimgray: '#696969',
|
|
157
|
-
dimgrey: '#696969',
|
|
158
|
-
dodgerblue: '#1e90ff',
|
|
159
|
-
firebrick: '#b22222',
|
|
160
|
-
floralwhite: '#fffaf0',
|
|
161
|
-
forestgreen: '#228b22',
|
|
162
|
-
fuchsia: '#ff00ff',
|
|
163
|
-
gainsboro: '#dcdcdc',
|
|
164
|
-
ghostwhite: '#f8f8ff',
|
|
165
|
-
goldenrod: '#daa520',
|
|
166
|
-
gold: '#ffd700',
|
|
167
|
-
gray: '#808080',
|
|
168
|
-
green: '#008000',
|
|
169
|
-
greenyellow: '#adff2f',
|
|
170
|
-
grey: '#808080',
|
|
171
|
-
honeydew: '#f0fff0',
|
|
172
|
-
hotpink: '#ff69b4',
|
|
173
|
-
indianred: '#cd5c5c',
|
|
174
|
-
indigo: '#4b0082',
|
|
175
|
-
ivory: '#fffff0',
|
|
176
|
-
khaki: '#f0e68c',
|
|
177
|
-
lavenderblush: '#fff0f5',
|
|
178
|
-
lavender: '#e6e6fa',
|
|
179
|
-
lawngreen: '#7cfc00',
|
|
180
|
-
lemonchiffon: '#fffacd',
|
|
181
|
-
lightblue: '#add8e6',
|
|
182
|
-
lightcoral: '#f08080',
|
|
183
|
-
lightcyan: '#e0ffff',
|
|
184
|
-
lightgoldenrodyellow: '#fafad2',
|
|
185
|
-
lightgray: '#d3d3d3',
|
|
186
|
-
lightgreen: '#90ee90',
|
|
187
|
-
lightgrey: '#d3d3d3',
|
|
188
|
-
lightpink: '#ffb6c1',
|
|
189
|
-
lightsalmon: '#ffa07a',
|
|
190
|
-
lightseagreen: '#20b2aa',
|
|
191
|
-
lightskyblue: '#87cefa',
|
|
192
|
-
lightslategray: '#778899',
|
|
193
|
-
lightslategrey: '#778899',
|
|
194
|
-
lightsteelblue: '#b0c4de',
|
|
195
|
-
lightyellow: '#ffffe0',
|
|
196
|
-
lime: '#00ff00',
|
|
197
|
-
limegreen: '#32cd32',
|
|
198
|
-
linen: '#faf0e6',
|
|
199
|
-
magenta: '#ff00ff',
|
|
200
|
-
maroon: '#800000',
|
|
201
|
-
mediumaquamarine: '#66cdaa',
|
|
202
|
-
mediumblue: '#0000cd',
|
|
203
|
-
mediumorchid: '#ba55d3',
|
|
204
|
-
mediumpurple: '#9370db',
|
|
205
|
-
mediumseagreen: '#3cb371',
|
|
206
|
-
mediumslateblue: '#7b68ee',
|
|
207
|
-
mediumspringgreen: '#00fa9a',
|
|
208
|
-
mediumturquoise: '#48d1cc',
|
|
209
|
-
mediumvioletred: '#c71585',
|
|
210
|
-
midnightblue: '#191970',
|
|
211
|
-
mintcream: '#f5fffa',
|
|
212
|
-
mistyrose: '#ffe4e1',
|
|
213
|
-
moccasin: '#ffe4b5',
|
|
214
|
-
navajowhite: '#ffdead',
|
|
215
|
-
navy: '#000080',
|
|
216
|
-
oldlace: '#fdf5e6',
|
|
217
|
-
olive: '#808000',
|
|
218
|
-
olivedrab: '#6b8e23',
|
|
219
|
-
orange: '#ffa500',
|
|
220
|
-
orangered: '#ff4500',
|
|
221
|
-
orchid: '#da70d6',
|
|
222
|
-
palegoldenrod: '#eee8aa',
|
|
223
|
-
palegreen: '#98fb98',
|
|
224
|
-
paleturquoise: '#afeeee',
|
|
225
|
-
palevioletred: '#db7093',
|
|
226
|
-
papayawhip: '#ffefd5',
|
|
227
|
-
peachpuff: '#ffdab9',
|
|
228
|
-
peru: '#cd853f',
|
|
229
|
-
pink: '#ffc0cb',
|
|
230
|
-
plum: '#dda0dd',
|
|
231
|
-
powderblue: '#b0e0e6',
|
|
232
|
-
purple: '#800080',
|
|
233
|
-
rebeccapurple: '#663399',
|
|
234
|
-
red: '#ff0000',
|
|
235
|
-
rosybrown: '#bc8f8f',
|
|
236
|
-
royalblue: '#4169e1',
|
|
237
|
-
saddlebrown: '#8b4513',
|
|
238
|
-
salmon: '#fa8072',
|
|
239
|
-
sandybrown: '#f4a460',
|
|
240
|
-
seagreen: '#2e8b57',
|
|
241
|
-
seashell: '#fff5ee',
|
|
242
|
-
sienna: '#a0522d',
|
|
243
|
-
silver: '#c0c0c0',
|
|
244
|
-
skyblue: '#87ceeb',
|
|
245
|
-
slateblue: '#6a5acd',
|
|
246
|
-
slategray: '#708090',
|
|
247
|
-
slategrey: '#708090',
|
|
248
|
-
snow: '#fffafa',
|
|
249
|
-
springgreen: '#00ff7f',
|
|
250
|
-
steelblue: '#4682b4',
|
|
251
|
-
tan: '#d2b48c',
|
|
252
|
-
teal: '#008080',
|
|
253
|
-
thistle: '#d8bfd8',
|
|
254
|
-
tomato: '#ff6347',
|
|
255
|
-
turquoise: '#40e0d0',
|
|
256
|
-
violet: '#ee82ee',
|
|
257
|
-
wheat: '#f5deb3',
|
|
258
|
-
white: '#ffffff',
|
|
259
|
-
whitesmoke: '#f5f5f5',
|
|
260
|
-
yellow: '#ffff00',
|
|
261
|
-
yellowgreen: '#9acd32',
|
|
262
|
-
};
|
|
263
|
-
export const colors = {
|
|
264
|
-
...colorGroups,
|
|
265
|
-
cssColorList,
|
|
266
|
-
};
|
|
267
|
-
export default colors;
|
|
1
|
+
// Public API barrel — explicit named re-exports only (tree-shake friendly).
|
|
2
|
+
// No default export; no side effects at module scope.
|
|
3
|
+
export { pantone } from './colorspaces/pantone';
|
|
4
|
+
export { web } from './colorspaces/web';
|
|
5
|
+
export { x11 } from './colorspaces/x11';
|
|
6
|
+
export { hexToRgba, rgbaToHex } from './conversions/hex';
|
|
7
|
+
export { hslToRgba, rgbaToHsl } from './conversions/hsl';
|
|
8
|
+
export { hsvToRgba, rgbaToHsv } from './conversions/hsv';
|
|
9
|
+
export { pantoneToRgba, rgbaToPantone } from './conversions/pantone';
|
|
10
|
+
export { rgbaToRgb, rgbToRgba } from './conversions/rgb';
|
|
11
|
+
export { convert, fromRgba, toRgba } from './convert';
|
|
12
|
+
export { detectFormat, isColor } from './detectFormat';
|
|
13
|
+
export { identify } from './identify';
|
|
14
|
+
export { resolve } from './resolve';
|
|
15
|
+
export { COLOR_FORMATS } from './types';
|
|
268
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,sDAAsD;AAEtD,OAAO,EAAyB,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAqB,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAqB,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAuB,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwBpC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Colorspace, DistanceMetric, Rgba } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Name normalization and per-colorspace lookup indexes.
|
|
4
|
+
*
|
|
5
|
+
* Tree-shaking note: this module never imports colorspace data itself.
|
|
6
|
+
* Callers pass their own colorspace in, so importing (say) `pantoneToRgba`
|
|
7
|
+
* never drags in `web` or `x11` through here.
|
|
8
|
+
*
|
|
9
|
+
* Caches are keyed by the colorspace object reference (WeakMap), so each
|
|
10
|
+
* colorspace's index is built once per process and reused by every caller.
|
|
11
|
+
*/
|
|
12
|
+
export type NormalizeFn = (name: string) => string;
|
|
13
|
+
/** Lowercase + strip non-alphanumeric. Used for web and x11. */
|
|
14
|
+
export declare const standardNormalize: NormalizeFn;
|
|
15
|
+
/**
|
|
16
|
+
* Pantone: also strip a leading "Pantone" or "PMS" prefix so that
|
|
17
|
+
* "185 C", "185c", "Pantone 185 C", "PMS185C" all map to "185c".
|
|
18
|
+
*/
|
|
19
|
+
export declare const pantoneNormalize: NormalizeFn;
|
|
20
|
+
/**
|
|
21
|
+
* Normalized-name → canonical-key map for a given colorspace.
|
|
22
|
+
* Each (colorspace, normalize) pair must be stable — callers are
|
|
23
|
+
* expected to always pair a given colorspace with the same normalizer.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getNameIndex(space: Colorspace, normalize: NormalizeFn): Map<string, string>;
|
|
26
|
+
/**
|
|
27
|
+
* Canonical-key → Rgba entries for a given colorspace, built by parsing
|
|
28
|
+
* each hex value once. Used by nearest-match lookups (identify, rgbaToPantone).
|
|
29
|
+
*/
|
|
30
|
+
export declare function getRgbaIndex(space: Colorspace): Array<readonly [string, Rgba]>;
|
|
31
|
+
/**
|
|
32
|
+
* Find the nearest-named entry in a colorspace to the given Rgba, using
|
|
33
|
+
* squared Euclidean distance in sRGB (alpha ignored). Used by `identify`
|
|
34
|
+
* and `rgbaToPantone` when metric === 'euclidean-srgb'.
|
|
35
|
+
*/
|
|
36
|
+
export declare function nearestByRgb(target: Rgba, space: Colorspace): string;
|
|
37
|
+
/**
|
|
38
|
+
* Find the nearest-named entry in a colorspace under the specified distance
|
|
39
|
+
* metric. Dispatches to the right index (rgba / linear-rgb / Lab) and
|
|
40
|
+
* the right distance function. See `DistanceMetric` in types.ts for how
|
|
41
|
+
* to pick a metric.
|
|
42
|
+
*/
|
|
43
|
+
export declare function nearest(target: Rgba, space: Colorspace, metric?: DistanceMetric): string;
|
|
44
|
+
//# sourceMappingURL=indexing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexing.d.ts","sourceRoot":"","sources":["../src/indexing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAY,IAAI,EAAE,MAAM,SAAS,CAAC;AAE1E;;;;;;;;;GASG;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AAEnD,gEAAgE;AAChE,eAAO,MAAM,iBAAiB,EAAE,WAA8D,CAAC;AAE/F;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAID,CAAC;AAK/B;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAU3F;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAO9E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAYpE;AAsED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,UAAU,EACjB,MAAM,GAAE,cAAiC,GACxC,MAAM,CAaR"}
|
package/dist/indexing.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { hexToRgba } from './conversions/hex';
|
|
2
|
+
import { rgbaToLab, rgbaToLinearRgb, rgbaToOklab } from './math/colorSpace';
|
|
3
|
+
import { deltaE76Squared, deltaE94, deltaE2000, deltaEokSquared } from './math/deltaE';
|
|
4
|
+
import { squaredDistanceRgb } from './math/euclideanDistance';
|
|
5
|
+
/** Lowercase + strip non-alphanumeric. Used for web and x11. */
|
|
6
|
+
export const standardNormalize = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
7
|
+
/**
|
|
8
|
+
* Pantone: also strip a leading "Pantone" or "PMS" prefix so that
|
|
9
|
+
* "185 C", "185c", "Pantone 185 C", "PMS185C" all map to "185c".
|
|
10
|
+
*/
|
|
11
|
+
export const pantoneNormalize = (s) => s
|
|
12
|
+
.toLowerCase()
|
|
13
|
+
.replace(/^(pantone|pms)\s*/, '')
|
|
14
|
+
.replace(/[^a-z0-9]/g, '');
|
|
15
|
+
const nameIndexCache = new WeakMap();
|
|
16
|
+
const rgbaIndexCache = new WeakMap();
|
|
17
|
+
/**
|
|
18
|
+
* Normalized-name → canonical-key map for a given colorspace.
|
|
19
|
+
* Each (colorspace, normalize) pair must be stable — callers are
|
|
20
|
+
* expected to always pair a given colorspace with the same normalizer.
|
|
21
|
+
*/
|
|
22
|
+
export function getNameIndex(space, normalize) {
|
|
23
|
+
let idx = nameIndexCache.get(space);
|
|
24
|
+
if (idx === undefined) {
|
|
25
|
+
idx = new Map();
|
|
26
|
+
for (const key of Object.keys(space)) {
|
|
27
|
+
idx.set(normalize(key), key);
|
|
28
|
+
}
|
|
29
|
+
nameIndexCache.set(space, idx);
|
|
30
|
+
}
|
|
31
|
+
return idx;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Canonical-key → Rgba entries for a given colorspace, built by parsing
|
|
35
|
+
* each hex value once. Used by nearest-match lookups (identify, rgbaToPantone).
|
|
36
|
+
*/
|
|
37
|
+
export function getRgbaIndex(space) {
|
|
38
|
+
let idx = rgbaIndexCache.get(space);
|
|
39
|
+
if (idx === undefined) {
|
|
40
|
+
idx = Object.entries(space).map(([name, hex]) => [name, hexToRgba(hex)]);
|
|
41
|
+
rgbaIndexCache.set(space, idx);
|
|
42
|
+
}
|
|
43
|
+
return idx;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Find the nearest-named entry in a colorspace to the given Rgba, using
|
|
47
|
+
* squared Euclidean distance in sRGB (alpha ignored). Used by `identify`
|
|
48
|
+
* and `rgbaToPantone` when metric === 'euclidean-srgb'.
|
|
49
|
+
*/
|
|
50
|
+
export function nearestByRgb(target, space) {
|
|
51
|
+
const entries = getRgbaIndex(space);
|
|
52
|
+
let bestName = entries[0]?.[0] ?? '';
|
|
53
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
54
|
+
for (const [name, candidate] of entries) {
|
|
55
|
+
const d = squaredDistanceRgb(target, candidate);
|
|
56
|
+
if (d < bestDistance) {
|
|
57
|
+
bestDistance = d;
|
|
58
|
+
bestName = name;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return bestName;
|
|
62
|
+
}
|
|
63
|
+
const labIndexCache = new WeakMap();
|
|
64
|
+
function getLabIndex(space) {
|
|
65
|
+
let idx = labIndexCache.get(space);
|
|
66
|
+
if (idx === undefined) {
|
|
67
|
+
idx = getRgbaIndex(space).map(([name, rgba]) => [name, rgbaToLab(rgba)]);
|
|
68
|
+
labIndexCache.set(space, idx);
|
|
69
|
+
}
|
|
70
|
+
return idx;
|
|
71
|
+
}
|
|
72
|
+
// Precomputed linear-RGB entries for euclidean-linear metric.
|
|
73
|
+
const linearIndexCache = new WeakMap();
|
|
74
|
+
function getLinearIndex(space) {
|
|
75
|
+
let idx = linearIndexCache.get(space);
|
|
76
|
+
if (idx === undefined) {
|
|
77
|
+
idx = getRgbaIndex(space).map(([name, rgba]) => [name, rgbaToLinearRgb(rgba)]);
|
|
78
|
+
linearIndexCache.set(space, idx);
|
|
79
|
+
}
|
|
80
|
+
return idx;
|
|
81
|
+
}
|
|
82
|
+
// Precomputed OKLAB entries for deltaEok metric.
|
|
83
|
+
const oklabIndexCache = new WeakMap();
|
|
84
|
+
function getOklabIndex(space) {
|
|
85
|
+
let idx = oklabIndexCache.get(space);
|
|
86
|
+
if (idx === undefined) {
|
|
87
|
+
idx = getRgbaIndex(space).map(([name, rgba]) => [name, rgbaToOklab(rgba)]);
|
|
88
|
+
oklabIndexCache.set(space, idx);
|
|
89
|
+
}
|
|
90
|
+
return idx;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Generic argmin over an `[name, value]` entries array with a custom
|
|
94
|
+
* distance function. Factored so the three metric branches in `nearest`
|
|
95
|
+
* share one loop body instead of duplicating it three times.
|
|
96
|
+
*/
|
|
97
|
+
function argminBy(entries, target, dist) {
|
|
98
|
+
let bestName = entries[0]?.[0] ?? '';
|
|
99
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
100
|
+
for (const [name, candidate] of entries) {
|
|
101
|
+
const d = dist(target, candidate);
|
|
102
|
+
if (d < bestDistance) {
|
|
103
|
+
bestDistance = d;
|
|
104
|
+
bestName = name;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return bestName;
|
|
108
|
+
}
|
|
109
|
+
// Squared Euclidean on a [number, number, number] triple. Used for the
|
|
110
|
+
// linear-RGB metric (sharing shape with Lab but different meaning).
|
|
111
|
+
function squaredDistanceTriple(a, b) {
|
|
112
|
+
const d0 = a[0] - b[0];
|
|
113
|
+
const d1 = a[1] - b[1];
|
|
114
|
+
const d2 = a[2] - b[2];
|
|
115
|
+
return d0 * d0 + d1 * d1 + d2 * d2;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Find the nearest-named entry in a colorspace under the specified distance
|
|
119
|
+
* metric. Dispatches to the right index (rgba / linear-rgb / Lab) and
|
|
120
|
+
* the right distance function. See `DistanceMetric` in types.ts for how
|
|
121
|
+
* to pick a metric.
|
|
122
|
+
*/
|
|
123
|
+
export function nearest(target, space, metric = 'euclidean-srgb') {
|
|
124
|
+
if (metric === 'euclidean-srgb')
|
|
125
|
+
return nearestByRgb(target, space);
|
|
126
|
+
if (metric === 'euclidean-linear') {
|
|
127
|
+
return argminBy(getLinearIndex(space), rgbaToLinearRgb(target), squaredDistanceTriple);
|
|
128
|
+
}
|
|
129
|
+
if (metric === 'deltaEok') {
|
|
130
|
+
return argminBy(getOklabIndex(space), rgbaToOklab(target), deltaEokSquared);
|
|
131
|
+
}
|
|
132
|
+
const labTarget = rgbaToLab(target);
|
|
133
|
+
const labIndex = getLabIndex(space);
|
|
134
|
+
if (metric === 'deltaE76')
|
|
135
|
+
return argminBy(labIndex, labTarget, deltaE76Squared);
|
|
136
|
+
if (metric === 'deltaE94')
|
|
137
|
+
return argminBy(labIndex, labTarget, deltaE94);
|
|
138
|
+
return argminBy(labIndex, labTarget, deltaE2000);
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=indexing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexing.js","sourceRoot":"","sources":["../src/indexing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAgB9D,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAgB,CA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OAAO,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;IACjF,IAAI,MAAM,KAAK,UAAU;QAAE,OAAO,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC1E,OAAO,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamp n to [lo, hi]. Caller must ensure n is a finite number.
|
|
3
|
+
*/
|
|
4
|
+
export declare function clamp(n: number, lo: number, hi: number): number;
|
|
5
|
+
/**
|
|
6
|
+
* Require a finite number at an API boundary; throws otherwise.
|
|
7
|
+
* Used by converter entry points to reject NaN, Infinity, and non-numeric
|
|
8
|
+
* values before they propagate through color math.
|
|
9
|
+
*/
|
|
10
|
+
export declare function requireFinite(n: unknown, label: string): number;
|
|
11
|
+
//# sourceMappingURL=clamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp.d.ts","sourceRoot":"","sources":["../../src/math/clamp.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK/D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamp n to [lo, hi]. Caller must ensure n is a finite number.
|
|
3
|
+
*/
|
|
4
|
+
export function clamp(n, lo, hi) {
|
|
5
|
+
return Math.max(lo, Math.min(hi, n));
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Require a finite number at an API boundary; throws otherwise.
|
|
9
|
+
* Used by converter entry points to reject NaN, Infinity, and non-numeric
|
|
10
|
+
* values before they propagate through color math.
|
|
11
|
+
*/
|
|
12
|
+
export function requireFinite(n, label) {
|
|
13
|
+
if (typeof n !== 'number' || !Number.isFinite(n)) {
|
|
14
|
+
throw new Error(`Expected finite number for ${label}, got ${typeof n}: ${String(n)}`);
|
|
15
|
+
}
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=clamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clamp.js","sourceRoot":"","sources":["../../src/math/clamp.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,CAAS,EAAE,EAAU,EAAE,EAAU;IACrD,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,CAAU,EAAE,KAAa;IACrD,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,SAAS,OAAO,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Rgba } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Color-space conversions needed by the perceptual distance metrics.
|
|
4
|
+
*
|
|
5
|
+
* Pipeline: sRGB (0..255) → linear RGB (0..1) → XYZ (D65) → Lab
|
|
6
|
+
*
|
|
7
|
+
* References:
|
|
8
|
+
* sRGB EOTF / companding: IEC 61966-2-1
|
|
9
|
+
* sRGB → XYZ (D65): Bruce Lindbloom, http://www.brucelindbloom.com/
|
|
10
|
+
* XYZ → Lab: CIE 15: 2004
|
|
11
|
+
*/
|
|
12
|
+
/** sRGB → linear for a single channel in [0, 255]. Returns [0, 1]. */
|
|
13
|
+
export declare function srgbToLinear(channel: number): number;
|
|
14
|
+
/** Linear → sRGB for a single channel in [0, 1]. Returns [0, 1] (scale by 255 if needed). */
|
|
15
|
+
export declare function linearToSrgb(linear: number): number;
|
|
16
|
+
/** Rgba → linear RGB triple in [0, 1] (alpha dropped). */
|
|
17
|
+
export declare function rgbaToLinearRgb(rgba: Rgba): [number, number, number];
|
|
18
|
+
/**
|
|
19
|
+
* Linear RGB (D65) → CIE XYZ (D65), using the standard sRGB matrix.
|
|
20
|
+
* Input and output both in [0, 1] on each axis (approximately; Y = 1 is white).
|
|
21
|
+
*/
|
|
22
|
+
export declare function linearRgbToXyz(r: number, g: number, b: number): [number, number, number];
|
|
23
|
+
/** CIE XYZ (D65) → CIE Lab. L ∈ [0, 100] approx; a,b unbounded but typically [-128, 127]. */
|
|
24
|
+
export declare function xyzToLab(x: number, y: number, z: number): [number, number, number];
|
|
25
|
+
/** Rgba (sRGB, 0..255) → CIE Lab. Canonical pipeline for perceptual distance. */
|
|
26
|
+
export declare function rgbaToLab(rgba: Rgba): [number, number, number];
|
|
27
|
+
/**
|
|
28
|
+
* Linear sRGB → OKLAB (Björn Ottosson, 2020). OKLAB is strictly more
|
|
29
|
+
* perceptually uniform than CIELAB, especially in the blue/purple region
|
|
30
|
+
* where even CIEDE2000 has residual error. Distance in OKLAB is plain
|
|
31
|
+
* Euclidean — no weighting formula needed, because the space itself is
|
|
32
|
+
* designed around uniformity.
|
|
33
|
+
*
|
|
34
|
+
* Reference: https://bottosson.github.io/posts/oklab/
|
|
35
|
+
*/
|
|
36
|
+
export declare function linearRgbToOklab(r: number, g: number, b: number): [number, number, number];
|
|
37
|
+
/** Rgba (sRGB, 0..255) → OKLAB. */
|
|
38
|
+
export declare function rgbaToOklab(rgba: Rgba): [number, number, number];
|
|
39
|
+
//# sourceMappingURL=colorSpace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorSpace.d.ts","sourceRoot":"","sources":["../../src/math/colorSpace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAErC;;;;;;;;;GASG;AAEH,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,0DAA0D;AAC1D,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAEpE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAKxF;AAaD,6FAA6F;AAC7F,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAQlF;AAED,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAI9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAa1F;AAED,mCAAmC;AACnC,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAGhE"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color-space conversions needed by the perceptual distance metrics.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline: sRGB (0..255) → linear RGB (0..1) → XYZ (D65) → Lab
|
|
5
|
+
*
|
|
6
|
+
* References:
|
|
7
|
+
* sRGB EOTF / companding: IEC 61966-2-1
|
|
8
|
+
* sRGB → XYZ (D65): Bruce Lindbloom, http://www.brucelindbloom.com/
|
|
9
|
+
* XYZ → Lab: CIE 15: 2004
|
|
10
|
+
*/
|
|
11
|
+
/** sRGB → linear for a single channel in [0, 255]. Returns [0, 1]. */
|
|
12
|
+
export function srgbToLinear(channel) {
|
|
13
|
+
const s = channel / 255;
|
|
14
|
+
return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
15
|
+
}
|
|
16
|
+
/** Linear → sRGB for a single channel in [0, 1]. Returns [0, 1] (scale by 255 if needed). */
|
|
17
|
+
export function linearToSrgb(linear) {
|
|
18
|
+
return linear <= 0.0031308 ? 12.92 * linear : 1.055 * linear ** (1 / 2.4) - 0.055;
|
|
19
|
+
}
|
|
20
|
+
/** Rgba → linear RGB triple in [0, 1] (alpha dropped). */
|
|
21
|
+
export function rgbaToLinearRgb(rgba) {
|
|
22
|
+
return [srgbToLinear(rgba.r), srgbToLinear(rgba.g), srgbToLinear(rgba.b)];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Linear RGB (D65) → CIE XYZ (D65), using the standard sRGB matrix.
|
|
26
|
+
* Input and output both in [0, 1] on each axis (approximately; Y = 1 is white).
|
|
27
|
+
*/
|
|
28
|
+
export function linearRgbToXyz(r, g, b) {
|
|
29
|
+
const x = r * 0.4124564 + g * 0.3575761 + b * 0.1804375;
|
|
30
|
+
const y = r * 0.2126729 + g * 0.7151522 + b * 0.072175;
|
|
31
|
+
const z = r * 0.0193339 + g * 0.119192 + b * 0.9503041;
|
|
32
|
+
return [x, y, z];
|
|
33
|
+
}
|
|
34
|
+
// D65 white reference (CIE 1931 2° observer).
|
|
35
|
+
const XN = 0.95047;
|
|
36
|
+
const YN = 1.0;
|
|
37
|
+
const ZN = 1.08883;
|
|
38
|
+
// f(t) in the CIE Lab formula; cube-root with a linear toe near origin.
|
|
39
|
+
function labF(t) {
|
|
40
|
+
const DELTA = 6 / 29;
|
|
41
|
+
return t > DELTA ** 3 ? Math.cbrt(t) : t / (3 * DELTA ** 2) + 4 / 29;
|
|
42
|
+
}
|
|
43
|
+
/** CIE XYZ (D65) → CIE Lab. L ∈ [0, 100] approx; a,b unbounded but typically [-128, 127]. */
|
|
44
|
+
export function xyzToLab(x, y, z) {
|
|
45
|
+
const fx = labF(x / XN);
|
|
46
|
+
const fy = labF(y / YN);
|
|
47
|
+
const fz = labF(z / ZN);
|
|
48
|
+
const l = 116 * fy - 16;
|
|
49
|
+
const a = 500 * (fx - fy);
|
|
50
|
+
const b = 200 * (fy - fz);
|
|
51
|
+
return [l, a, b];
|
|
52
|
+
}
|
|
53
|
+
/** Rgba (sRGB, 0..255) → CIE Lab. Canonical pipeline for perceptual distance. */
|
|
54
|
+
export function rgbaToLab(rgba) {
|
|
55
|
+
const [r, g, b] = rgbaToLinearRgb(rgba);
|
|
56
|
+
const [x, y, z] = linearRgbToXyz(r, g, b);
|
|
57
|
+
return xyzToLab(x, y, z);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Linear sRGB → OKLAB (Björn Ottosson, 2020). OKLAB is strictly more
|
|
61
|
+
* perceptually uniform than CIELAB, especially in the blue/purple region
|
|
62
|
+
* where even CIEDE2000 has residual error. Distance in OKLAB is plain
|
|
63
|
+
* Euclidean — no weighting formula needed, because the space itself is
|
|
64
|
+
* designed around uniformity.
|
|
65
|
+
*
|
|
66
|
+
* Reference: https://bottosson.github.io/posts/oklab/
|
|
67
|
+
*/
|
|
68
|
+
export function linearRgbToOklab(r, g, b) {
|
|
69
|
+
const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
|
|
70
|
+
const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
|
|
71
|
+
const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
|
|
72
|
+
const l_ = Math.cbrt(l);
|
|
73
|
+
const m_ = Math.cbrt(m);
|
|
74
|
+
const s_ = Math.cbrt(s);
|
|
75
|
+
const L = 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_;
|
|
76
|
+
const a = 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_;
|
|
77
|
+
const b2 = 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_;
|
|
78
|
+
return [L, a, b2];
|
|
79
|
+
}
|
|
80
|
+
/** Rgba (sRGB, 0..255) → OKLAB. */
|
|
81
|
+
export function rgbaToOklab(rgba) {
|
|
82
|
+
const [r, g, b] = rgbaToLinearRgb(rgba);
|
|
83
|
+
return linearRgbToOklab(r, g, b);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=colorSpace.js.map
|