chromonym 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +39 -0
- package/README.md +93 -8
- 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/conversions/hex.d.ts.map +1 -1
- package/dist/conversions/hex.js +6 -5
- package/dist/conversions/hex.js.map +1 -1
- package/dist/conversions/hsl.d.ts.map +1 -1
- package/dist/conversions/hsl.js +34 -52
- package/dist/conversions/hsl.js.map +1 -1
- package/dist/conversions/hsv.d.ts.map +1 -1
- package/dist/conversions/hsv.js +30 -48
- package/dist/conversions/hsv.js.map +1 -1
- package/dist/conversions/pantone.d.ts +5 -2
- package/dist/conversions/pantone.d.ts.map +1 -1
- package/dist/conversions/pantone.js +8 -44
- package/dist/conversions/pantone.js.map +1 -1
- package/dist/conversions/rgb.d.ts +4 -2
- package/dist/conversions/rgb.d.ts.map +1 -1
- package/dist/conversions/rgb.js +28 -17
- package/dist/conversions/rgb.js.map +1 -1
- package/dist/convert.d.ts +12 -1
- package/dist/convert.d.ts.map +1 -1
- package/dist/convert.js +24 -6
- package/dist/convert.js.map +1 -1
- package/dist/detectFormat.d.ts +8 -0
- package/dist/detectFormat.d.ts.map +1 -1
- package/dist/detectFormat.js +17 -5
- package/dist/detectFormat.js.map +1 -1
- package/dist/identify.d.ts +13 -5
- package/dist/identify.d.ts.map +1 -1
- package/dist/identify.js +20 -35
- package/dist/identify.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- 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 +55 -0
- package/dist/math/colorSpace.d.ts.map +1 -0
- package/dist/math/colorSpace.js +111 -0
- package/dist/math/colorSpace.js.map +1 -0
- package/dist/math/deltaE.d.ts +52 -0
- package/dist/math/deltaE.d.ts.map +1 -0
- package/dist/math/deltaE.js +190 -0
- package/dist/math/deltaE.js.map +1 -0
- package/dist/math/euclideanDistance.d.ts +7 -0
- package/dist/math/euclideanDistance.d.ts.map +1 -1
- package/dist/math/euclideanDistance.js +13 -4
- package/dist/math/euclideanDistance.js.map +1 -1
- 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.map +1 -1
- package/dist/resolve.js +11 -34
- package/dist/resolve.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +72 -8
- package/dist/math/index.d.ts +0 -2
- package/dist/math/index.d.ts.map +0 -1
- package/dist/math/index.js +0 -4
- package/dist/math/index.js.map +0 -1
|
@@ -1,34 +1,6 @@
|
|
|
1
1
|
import { pantone } from '../colorspaces/pantone';
|
|
2
|
-
import {
|
|
2
|
+
import { getNameIndex, nearest, pantoneNormalize } from '../indexing';
|
|
3
3
|
import { hexToRgba } from './hex';
|
|
4
|
-
// Strip casing, common prefixes ("Pantone", "PMS"), and all non-alphanumeric
|
|
5
|
-
// characters so that "185 C", "185c", "Pantone 185 C", "PMS185C" all match
|
|
6
|
-
// the stored canonical key "185C".
|
|
7
|
-
function normalize(s) {
|
|
8
|
-
return s
|
|
9
|
-
.toLowerCase()
|
|
10
|
-
.replace(/^(pantone|pms)\s*/, '')
|
|
11
|
-
.replace(/[^a-z0-9]/g, '');
|
|
12
|
-
}
|
|
13
|
-
// Lazy normalized-name -> canonical-key index.
|
|
14
|
-
let nameIndex = null;
|
|
15
|
-
function getNameIndex() {
|
|
16
|
-
if (!nameIndex) {
|
|
17
|
-
nameIndex = new Map();
|
|
18
|
-
for (const key of Object.keys(pantone)) {
|
|
19
|
-
nameIndex.set(normalize(key), key);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return nameIndex;
|
|
23
|
-
}
|
|
24
|
-
// Lazy canonical-key -> rgba index (precomputed to avoid per-lookup hex parsing).
|
|
25
|
-
let rgbaIndex = null;
|
|
26
|
-
function getRgbaIndex() {
|
|
27
|
-
if (!rgbaIndex) {
|
|
28
|
-
rgbaIndex = Object.entries(pantone).map(([code, hex]) => [code, hexToRgba(hex)]);
|
|
29
|
-
}
|
|
30
|
-
return rgbaIndex;
|
|
31
|
-
}
|
|
32
4
|
/**
|
|
33
5
|
* Resolve a Pantone code to Rgba.
|
|
34
6
|
* Accepts any casing, spacing, and common prefixes ("PMS", "Pantone")
|
|
@@ -36,28 +8,20 @@ function getRgbaIndex() {
|
|
|
36
8
|
* Throws on unknown codes.
|
|
37
9
|
*/
|
|
38
10
|
export function pantoneToRgba(code) {
|
|
39
|
-
const canonical = getNameIndex().get(
|
|
11
|
+
const canonical = getNameIndex(pantone, pantoneNormalize).get(pantoneNormalize(code));
|
|
40
12
|
if (canonical === undefined)
|
|
41
13
|
throw new Error(`Unknown Pantone code: ${code}`);
|
|
42
14
|
const hex = pantone[canonical];
|
|
43
15
|
return hexToRgba(hex);
|
|
44
16
|
}
|
|
45
17
|
/**
|
|
46
|
-
* Find the nearest Pantone code
|
|
47
|
-
*
|
|
18
|
+
* Find the nearest Pantone Coated code to the given Rgba. Uses ΔE*00
|
|
19
|
+
* (CIEDE2000) — the industry-standard perceptual metric — by default, since
|
|
20
|
+
* Pantone values cluster densely in the saturated blue/purple region where
|
|
21
|
+
* sRGB Euclidean distance gives visually wrong answers.
|
|
22
|
+
* Alpha is ignored. Always returns a code.
|
|
48
23
|
*/
|
|
49
24
|
export function rgbaToPantone(rgba) {
|
|
50
|
-
|
|
51
|
-
// Pantone colorspace has 907 entries; first-entry fallback is defensive.
|
|
52
|
-
let bestCode = entries[0]?.[0] ?? '';
|
|
53
|
-
let bestDistance = Infinity;
|
|
54
|
-
for (const [code, candidate] of entries) {
|
|
55
|
-
const d = euclideanDistance(rgba, candidate);
|
|
56
|
-
if (d < bestDistance) {
|
|
57
|
-
bestDistance = d;
|
|
58
|
-
bestCode = code;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return bestCode;
|
|
25
|
+
return nearest(rgba, pantone, 'deltaE2000');
|
|
62
26
|
}
|
|
63
27
|
//# sourceMappingURL=pantone.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pantone.js","sourceRoot":"","sources":["../../src/conversions/pantone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pantone.js","sourceRoot":"","sources":["../../src/conversions/pantone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAiB;IAC7C,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IACtF,IAAI,SAAS,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IAC9E,MAAM,GAAG,GAAG,OAAO,CAAC,SAAiC,CAAC,CAAC;IACvD,OAAO,SAAS,CAAC,GAAe,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAAU;IACtC,OAAO,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAgB,CAAC;AAC7D,CAAC"}
|
|
@@ -2,12 +2,14 @@ import type { Rgba, RgbaInput, RgbInput, RgbString } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Normalize any RGB/RGBA input shape (string, tuple, or object) into
|
|
4
4
|
* the canonical Rgba representation. Alpha defaults to 1 when absent.
|
|
5
|
+
* Rejects non-finite numeric inputs; clamps r/g/b to [0,255] and a to [0,1].
|
|
5
6
|
* Throws on malformed strings.
|
|
6
7
|
*/
|
|
7
8
|
export declare function rgbToRgba(input: RgbInput | RgbaInput): Rgba;
|
|
8
9
|
/**
|
|
9
|
-
* Emit an `rgb(r, g, b)` string. Alpha is dropped;
|
|
10
|
-
*
|
|
10
|
+
* Emit an `rgb(r, g, b)` string. Alpha is dropped; values are
|
|
11
|
+
* already-clamped by rgbToRgba, but we re-clamp defensively for direct
|
|
12
|
+
* Rgba-object callers who bypass the input normalizer.
|
|
11
13
|
*/
|
|
12
14
|
export declare function rgbaToRgb(rgba: Rgba): RgbString;
|
|
13
15
|
//# sourceMappingURL=rgb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rgb.d.ts","sourceRoot":"","sources":["../../src/conversions/rgb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rgb.d.ts","sourceRoot":"","sources":["../../src/conversions/rgb.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAa,SAAS,EAAE,MAAM,UAAU,CAAC;AAahF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,CA+B3D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAK/C"}
|
package/dist/conversions/rgb.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
+
import { clamp, requireFinite } from '../math/clamp';
|
|
1
2
|
const RGB_RE = /^rgba?\s*\(\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*(?:,\s*(\d*\.?\d+)\s*)?\)$/i;
|
|
3
|
+
function sanitizeChannel(n, label) {
|
|
4
|
+
return clamp(requireFinite(n, label), 0, 255);
|
|
5
|
+
}
|
|
6
|
+
function sanitizeAlpha(n) {
|
|
7
|
+
return clamp(requireFinite(n, 'alpha'), 0, 1);
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Normalize any RGB/RGBA input shape (string, tuple, or object) into
|
|
4
11
|
* the canonical Rgba representation. Alpha defaults to 1 when absent.
|
|
12
|
+
* Rejects non-finite numeric inputs; clamps r/g/b to [0,255] and a to [0,1].
|
|
5
13
|
* Throws on malformed strings.
|
|
6
14
|
*/
|
|
7
15
|
export function rgbToRgba(input) {
|
|
8
16
|
if (Array.isArray(input)) {
|
|
9
|
-
const
|
|
17
|
+
const rawA = input.length === 4 ? input[3] : 1;
|
|
10
18
|
return {
|
|
11
|
-
r: input[0],
|
|
12
|
-
g: input[1],
|
|
13
|
-
b: input[2],
|
|
14
|
-
a,
|
|
19
|
+
r: sanitizeChannel(input[0], 'r'),
|
|
20
|
+
g: sanitizeChannel(input[1], 'g'),
|
|
21
|
+
b: sanitizeChannel(input[2], 'b'),
|
|
22
|
+
a: sanitizeAlpha(rawA),
|
|
15
23
|
};
|
|
16
24
|
}
|
|
17
25
|
if (typeof input === 'string') {
|
|
@@ -19,28 +27,31 @@ export function rgbToRgba(input) {
|
|
|
19
27
|
if (!match)
|
|
20
28
|
throw new Error(`Invalid rgb(a) string: ${input}`);
|
|
21
29
|
return {
|
|
22
|
-
r: Number(match[1]),
|
|
23
|
-
g: Number(match[2]),
|
|
24
|
-
b: Number(match[3]),
|
|
25
|
-
a: match[4] !== undefined ? Number(match[4]) : 1,
|
|
30
|
+
r: sanitizeChannel(Number(match[1]), 'r'),
|
|
31
|
+
g: sanitizeChannel(Number(match[2]), 'g'),
|
|
32
|
+
b: sanitizeChannel(Number(match[3]), 'b'),
|
|
33
|
+
a: sanitizeAlpha(match[4] !== undefined ? Number(match[4]) : 1),
|
|
26
34
|
};
|
|
27
35
|
}
|
|
28
36
|
// Object form — TypeScript's Array.isArray narrowing doesn't exclude
|
|
29
37
|
// readonly tuple types from the union, so cast after the guards.
|
|
30
38
|
const obj = input;
|
|
31
39
|
return {
|
|
32
|
-
r: obj.r,
|
|
33
|
-
g: obj.g,
|
|
34
|
-
b: obj.b,
|
|
35
|
-
a: 'a' in obj ? obj.a : 1,
|
|
40
|
+
r: sanitizeChannel(obj.r, 'r'),
|
|
41
|
+
g: sanitizeChannel(obj.g, 'g'),
|
|
42
|
+
b: sanitizeChannel(obj.b, 'b'),
|
|
43
|
+
a: sanitizeAlpha('a' in obj ? obj.a : 1),
|
|
36
44
|
};
|
|
37
45
|
}
|
|
38
46
|
/**
|
|
39
|
-
* Emit an `rgb(r, g, b)` string. Alpha is dropped;
|
|
40
|
-
*
|
|
47
|
+
* Emit an `rgb(r, g, b)` string. Alpha is dropped; values are
|
|
48
|
+
* already-clamped by rgbToRgba, but we re-clamp defensively for direct
|
|
49
|
+
* Rgba-object callers who bypass the input normalizer.
|
|
41
50
|
*/
|
|
42
51
|
export function rgbaToRgb(rgba) {
|
|
43
|
-
const
|
|
44
|
-
|
|
52
|
+
const r = clamp(Math.round(rgba.r), 0, 255);
|
|
53
|
+
const g = clamp(Math.round(rgba.g), 0, 255);
|
|
54
|
+
const b = clamp(Math.round(rgba.b), 0, 255);
|
|
55
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
45
56
|
}
|
|
46
57
|
//# sourceMappingURL=rgb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rgb.js","sourceRoot":"","sources":["../../src/conversions/rgb.ts"],"names":[],"mappings":"
|
|
1
|
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E,GAAG,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAgB,CAAC;AAC9C,CAAC"}
|
package/dist/convert.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type DetectedFormat } from './detectFormat';
|
|
2
|
+
import type { ColorFormat, ColorInput, ColorValue, Rgba } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Normalize any recognized color input to canonical `Rgba`.
|
|
5
|
+
* Pass `knownFormat` when the caller has already run `detectFormat` to skip
|
|
6
|
+
* the redundant detection. Throws on `UNKNOWN` input.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toRgba(input: ColorInput, knownFormat?: DetectedFormat): Rgba;
|
|
9
|
+
/**
|
|
10
|
+
* Emit a canonical `Rgba` in the target format. Colorspace-independent.
|
|
11
|
+
*/
|
|
12
|
+
export declare function fromRgba(rgba: Rgba, format?: ColorFormat): ColorValue;
|
|
2
13
|
/**
|
|
3
14
|
* Detect the input color format, normalize to Rgba, and emit the result
|
|
4
15
|
* in the requested output format. Colorspace-independent.
|
package/dist/convert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,cAAc,EAAgB,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,UAAU,EAKV,IAAI,EAGL,MAAM,SAAS,CAAC;AAYjB;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,cAAc,GAAG,IAAI,CAkB5E;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,WAAmB,GAAG,UAAU,CAe5E;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GAAG,UAAU,CAE1F"}
|
package/dist/convert.js
CHANGED
|
@@ -4,8 +4,24 @@ import { hsvToRgba, rgbaToHsv } from './conversions/hsv';
|
|
|
4
4
|
import { pantoneToRgba, rgbaToPantone } from './conversions/pantone';
|
|
5
5
|
import { rgbaToRgb, rgbToRgba } from './conversions/rgb';
|
|
6
6
|
import { detectFormat } from './detectFormat';
|
|
7
|
-
function
|
|
8
|
-
|
|
7
|
+
function safeStringify(x) {
|
|
8
|
+
if (x === undefined)
|
|
9
|
+
return 'undefined';
|
|
10
|
+
try {
|
|
11
|
+
const s = JSON.stringify(x);
|
|
12
|
+
return s === undefined ? String(x) : s;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return Object.prototype.toString.call(x);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Normalize any recognized color input to canonical `Rgba`.
|
|
20
|
+
* Pass `knownFormat` when the caller has already run `detectFormat` to skip
|
|
21
|
+
* the redundant detection. Throws on `UNKNOWN` input.
|
|
22
|
+
*/
|
|
23
|
+
export function toRgba(input, knownFormat) {
|
|
24
|
+
const format = knownFormat ?? detectFormat(input);
|
|
9
25
|
switch (format) {
|
|
10
26
|
case 'HEX':
|
|
11
27
|
return hexToRgba(input);
|
|
@@ -20,10 +36,13 @@ function toRgba(input) {
|
|
|
20
36
|
case 'PANTONE':
|
|
21
37
|
return pantoneToRgba(input);
|
|
22
38
|
default:
|
|
23
|
-
throw new Error(`Unrecognized color input: ${
|
|
39
|
+
throw new Error(`Unrecognized color input: ${safeStringify(input)}`);
|
|
24
40
|
}
|
|
25
41
|
}
|
|
26
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Emit a canonical `Rgba` in the target format. Colorspace-independent.
|
|
44
|
+
*/
|
|
45
|
+
export function fromRgba(rgba, format = 'HEX') {
|
|
27
46
|
switch (format) {
|
|
28
47
|
case 'HEX':
|
|
29
48
|
return rgbaToHex(rgba);
|
|
@@ -45,7 +64,6 @@ function fromRgba(rgba, format) {
|
|
|
45
64
|
* Throws if the input isn't a recognized color shape.
|
|
46
65
|
*/
|
|
47
66
|
export function convert(input, opts = {}) {
|
|
48
|
-
|
|
49
|
-
return fromRgba(toRgba(input), format);
|
|
67
|
+
return fromRgba(toRgba(input), opts.format ?? 'HEX');
|
|
50
68
|
}
|
|
51
69
|
//# sourceMappingURL=convert.js.map
|
package/dist/convert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA,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,
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA,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,EAAuB,YAAY,EAAE,MAAM,g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YACR,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,KAAK,MAAM;YACT,OAAO,IAAI,CAAC;QACd,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAiB,EAAE,IAAI,GAA6B,EAAE;IAC5E,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;AACvD,CAAC"}
|
package/dist/detectFormat.d.ts
CHANGED
|
@@ -5,5 +5,13 @@ import type { ColorFormat, ColorInput } from './types';
|
|
|
5
5
|
* Used as the dispatch key for format-specific converters.
|
|
6
6
|
*/
|
|
7
7
|
export type DetectedFormat = ColorFormat | 'UNKNOWN';
|
|
8
|
+
/** Shared with `src/conversions/hex.ts`. Capture group is used there; .test() ignores it here. */
|
|
9
|
+
export declare const HEX_RE: RegExp;
|
|
10
|
+
/**
|
|
11
|
+
* Runtime type-guard — returns `true` if `input` looks like something any of
|
|
12
|
+
* chromonym's converters can parse. Cheaper than catching a `convert` throw
|
|
13
|
+
* and more ergonomic than hand-rolling `detectFormat(x) !== 'UNKNOWN'`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isColor(input: unknown): input is ColorInput;
|
|
8
16
|
export declare function detectFormat(input: ColorInput): DetectedFormat;
|
|
9
17
|
//# sourceMappingURL=detectFormat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectFormat.d.ts","sourceRoot":"","sources":["../src/detectFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"detectFormat.d.ts","sourceRoot":"","sources":["../src/detectFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,SAAS,CAAC;AAErD,kGAAkG;AAClG,eAAO,MAAM,MAAM,QAA8C,CAAC;AASlE;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAE3D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,cAAc,CA8B9D"}
|
package/dist/detectFormat.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/** Shared with `src/conversions/hex.ts`. Capture group is used there; .test() ignores it here. */
|
|
2
|
+
export const HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
2
3
|
const RGBA_STR_RE = /^rgba\s*\(/i;
|
|
3
4
|
const RGB_STR_RE = /^rgb\s*\(/i;
|
|
4
5
|
const HSL_STR_RE = /^hsl\s*\(/i;
|
|
@@ -6,6 +7,14 @@ const HSV_STR_RE = /^hsv\s*\(/i;
|
|
|
6
7
|
// Conservative: matches "<digits> C|U|M" with optional "Pantone" prefix.
|
|
7
8
|
// Refine once the real Pantone code list lands.
|
|
8
9
|
const PANTONE_RE = /^(?:pantone\s+)?\d+\s*[CUM]$/i;
|
|
10
|
+
/**
|
|
11
|
+
* Runtime type-guard — returns `true` if `input` looks like something any of
|
|
12
|
+
* chromonym's converters can parse. Cheaper than catching a `convert` throw
|
|
13
|
+
* and more ergonomic than hand-rolling `detectFormat(x) !== 'UNKNOWN'`.
|
|
14
|
+
*/
|
|
15
|
+
export function isColor(input) {
|
|
16
|
+
return detectFormat(input) !== 'UNKNOWN';
|
|
17
|
+
}
|
|
9
18
|
export function detectFormat(input) {
|
|
10
19
|
if (typeof input === 'string') {
|
|
11
20
|
if (input === '')
|
|
@@ -32,13 +41,16 @@ export function detectFormat(input) {
|
|
|
32
41
|
return 'UNKNOWN';
|
|
33
42
|
}
|
|
34
43
|
if (input !== null && typeof input === 'object') {
|
|
35
|
-
|
|
44
|
+
// Use Object.hasOwn — `in` walks the prototype chain and can be
|
|
45
|
+
// abused by attacker-controlled prototypes to misclassify inputs.
|
|
46
|
+
const has = Object.hasOwn;
|
|
47
|
+
if (has(input, 'h') && has(input, 'v'))
|
|
36
48
|
return 'HSV';
|
|
37
|
-
if ('h'
|
|
49
|
+
if (has(input, 'h') && has(input, 'l'))
|
|
38
50
|
return 'HSL';
|
|
39
|
-
if ('
|
|
51
|
+
if (has(input, 'r') && has(input, 'a'))
|
|
40
52
|
return 'RGBA';
|
|
41
|
-
if ('r'
|
|
53
|
+
if (has(input, 'r'))
|
|
42
54
|
return 'RGB';
|
|
43
55
|
return 'UNKNOWN';
|
|
44
56
|
}
|
package/dist/detectFormat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectFormat.js","sourceRoot":"","sources":["../src/detectFormat.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"detectFormat.js","sourceRoot":"","sources":["../src/detectFormat.ts"],"names":[],"mappings":"AASA,kGAAkG;AAClG,MAAM,CAAC,MAAM,MAAM,GAAG,2CAA2C,CAAC;AAClE,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,yEAAyE;AACzE,gDAAgD;AAChD,MAAM,UAAU,GAAG,+BAA+B,CAAC;AAEnD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO,YAA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AE,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACrD,IAAI,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC;YAAE,OAAO,MAAM,CAAC;QACtD,IAAI,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/identify.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toRgba } from './convert';
|
|
2
|
+
import type { ColorspaceName, DistanceMetric } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Identify the nearest-named color for any color input.
|
|
4
|
-
* Uses Euclidean distance in RGB (alpha is ignored).
|
|
5
|
-
* Returns `null` if the input isn't a recognized color shape.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* The distance metric defaults to the colorspace's recommended choice
|
|
7
|
+
* (web/x11: `deltaE76`, pantone: `deltaE2000`). Override with the `metric`
|
|
8
|
+
* option — e.g. `{ metric: 'euclidean-srgb' }` for maximum speed, or
|
|
9
|
+
* `{ metric: 'deltaE2000' }` for strictest perceptual accuracy.
|
|
10
|
+
*
|
|
11
|
+
* Returns `null` if the input isn't a recognized color shape or the
|
|
12
|
+
* colorspace name isn't one of `web` / `x11` / `pantone`.
|
|
13
|
+
*
|
|
14
|
+
* Defaults: colorspace = 'web', metric = DEFAULT_METRICS[colorspace].
|
|
8
15
|
*/
|
|
9
|
-
export declare function identify(input:
|
|
16
|
+
export declare function identify(input: Parameters<typeof toRgba>[0], opts?: {
|
|
10
17
|
colorspace?: ColorspaceName;
|
|
18
|
+
metric?: DistanceMetric;
|
|
11
19
|
}): string | null;
|
|
12
20
|
//# sourceMappingURL=identify.d.ts.map
|
package/dist/identify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identify.d.ts","sourceRoot":"","sources":["../src/identify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"identify.d.ts","sourceRoot":"","sources":["../src/identify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,EACnC,IAAI,GAAE;IAAE,UAAU,CAAC,EAAE,cAAc,CAAC;IAAC,MAAM,CAAC,EAAE,cAAc,CAAA;CAAO,GAClE,MAAM,GAAG,IAAI,CAUf"}
|
package/dist/identify.js
CHANGED
|
@@ -1,44 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { x11 } from './colorspaces/x11';
|
|
4
|
-
import { hexToRgba } from './conversions/hex';
|
|
5
|
-
import { convert } from './convert';
|
|
1
|
+
import { COLORSPACE_NAMES, COLORSPACES, DEFAULT_METRICS } from './colorspaces/registry';
|
|
2
|
+
import { toRgba } from './convert';
|
|
6
3
|
import { detectFormat } from './detectFormat';
|
|
7
|
-
import {
|
|
8
|
-
const COLORSPACES = { web, x11, pantone };
|
|
9
|
-
// Lazy per-colorspace rgba index — built on first lookup, reused thereafter.
|
|
10
|
-
const rgbaIndexes = new Map();
|
|
11
|
-
function getRgbaIndex(colorspace) {
|
|
12
|
-
let idx = rgbaIndexes.get(colorspace);
|
|
13
|
-
if (idx === undefined) {
|
|
14
|
-
const space = COLORSPACES[colorspace];
|
|
15
|
-
idx = Object.entries(space).map(([name, hex]) => [name, hexToRgba(hex)]);
|
|
16
|
-
rgbaIndexes.set(colorspace, idx);
|
|
17
|
-
}
|
|
18
|
-
return idx;
|
|
19
|
-
}
|
|
4
|
+
import { nearest } from './indexing';
|
|
20
5
|
/**
|
|
21
6
|
* Identify the nearest-named color for any color input.
|
|
22
|
-
* Uses Euclidean distance in RGB (alpha is ignored).
|
|
23
|
-
* Returns `null` if the input isn't a recognized color shape.
|
|
24
7
|
*
|
|
25
|
-
*
|
|
8
|
+
* The distance metric defaults to the colorspace's recommended choice
|
|
9
|
+
* (web/x11: `deltaE76`, pantone: `deltaE2000`). Override with the `metric`
|
|
10
|
+
* option — e.g. `{ metric: 'euclidean-srgb' }` for maximum speed, or
|
|
11
|
+
* `{ metric: 'deltaE2000' }` for strictest perceptual accuracy.
|
|
12
|
+
*
|
|
13
|
+
* Returns `null` if the input isn't a recognized color shape or the
|
|
14
|
+
* colorspace name isn't one of `web` / `x11` / `pantone`.
|
|
15
|
+
*
|
|
16
|
+
* Defaults: colorspace = 'web', metric = DEFAULT_METRICS[colorspace].
|
|
26
17
|
*/
|
|
27
18
|
export function identify(input, opts = {}) {
|
|
28
|
-
|
|
19
|
+
const format = detectFormat(input);
|
|
20
|
+
if (format === 'UNKNOWN')
|
|
21
|
+
return null;
|
|
22
|
+
const { colorspace = 'web', metric } = opts;
|
|
23
|
+
if (!COLORSPACE_NAMES.has(colorspace))
|
|
29
24
|
return null;
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
let bestName = null;
|
|
34
|
-
let bestDistance = Infinity;
|
|
35
|
-
for (const [name, candidate] of entries) {
|
|
36
|
-
const d = euclideanDistance(rgba, candidate);
|
|
37
|
-
if (d < bestDistance) {
|
|
38
|
-
bestDistance = d;
|
|
39
|
-
bestName = name;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return bestName;
|
|
25
|
+
const rgba = toRgba(input, format);
|
|
26
|
+
const name = nearest(rgba, COLORSPACES[colorspace], metric ?? DEFAULT_METRICS[colorspace]);
|
|
27
|
+
return name || null;
|
|
43
28
|
}
|
|
44
29
|
//# sourceMappingURL=identify.js.map
|
package/dist/identify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../src/identify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../src/identify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAmC,EACnC,IAAI,GAA6D,EAAE;IAEnE,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEtC,MAAM,EAAE,UAAU,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAEnD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;IAC3F,OAAO,IAAI,IAAI,IAAI,CAAC;AACtB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export { hslToRgba, rgbaToHsl } from './conversions/hsl';
|
|
|
6
6
|
export { hsvToRgba, rgbaToHsv } from './conversions/hsv';
|
|
7
7
|
export { pantoneToRgba, rgbaToPantone } from './conversions/pantone';
|
|
8
8
|
export { rgbaToRgb, rgbToRgba } from './conversions/rgb';
|
|
9
|
-
export { convert } from './convert';
|
|
10
|
-
export { type DetectedFormat, detectFormat } from './detectFormat';
|
|
9
|
+
export { convert, fromRgba, toRgba } from './convert';
|
|
10
|
+
export { type DetectedFormat, detectFormat, isColor } from './detectFormat';
|
|
11
11
|
export { identify } from './identify';
|
|
12
12
|
export { resolve } from './resolve';
|
|
13
13
|
export type { ColorFormat, ColorInput, Colorspace, ColorspaceName, ColorValue, HexColor, HslInput, HslObject, HslString, HsvInput, HsvObject, HsvString, PantoneCode, Rgba, RgbaInput, RgbaString, RgbaTuple, RgbInput, RgbObject, RgbString, RgbTuple, } from './types';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,KAAK,YAAY,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,KAAK,YAAY,EAAE,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,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,KAAK,YAAY,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,KAAK,YAAY,EAAE,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,EAAE,KAAK,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,EACR,SAAS,EACT,SAAS,EACT,WAAW,EACX,IAAI,EACJ,SAAS,EACT,UAAU,EACV,SAAS,EACT,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@ export { hslToRgba, rgbaToHsl } from './conversions/hsl';
|
|
|
8
8
|
export { hsvToRgba, rgbaToHsv } from './conversions/hsv';
|
|
9
9
|
export { pantoneToRgba, rgbaToPantone } from './conversions/pantone';
|
|
10
10
|
export { rgbaToRgb, rgbToRgba } from './conversions/rgb';
|
|
11
|
-
export { convert } from './convert';
|
|
12
|
-
export { detectFormat } from './detectFormat';
|
|
11
|
+
export { convert, fromRgba, toRgba } from './convert';
|
|
12
|
+
export { detectFormat, isColor } from './detectFormat';
|
|
13
13
|
export { identify } from './identify';
|
|
14
14
|
export { resolve } from './resolve';
|
|
15
15
|
export { COLOR_FORMATS } from './types';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,MAAM,WAAW,CAAC;
|
|
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"}
|