MCPcopy Create free account
hub / github.com/adobe/react-spectrum / nearestColor

Function nearestColor

scripts/convertAnatomy.js:57–69  ·  view source on GitHub ↗
(target)

Source from the content-addressed store, hash-verified

55
56// return nearest color from array
57function nearestColor(target) {
58 var lowest = Number.POSITIVE_INFINITY;
59 var tmp;
60 let res;
61 for (let color in colors) {
62 tmp = distance(target, hexToRgb(color));
63 if (tmp < lowest) {
64 lowest = tmp;
65 res = color;
66 }
67 }
68 return colors[res];
69}
70
71function hexToRgb(hex) {
72 var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;

Callers 1

convertAnatomy.jsFile · 0.85

Calls 2

distanceFunction · 0.85
hexToRgbFunction · 0.85

Tested by

no test coverage detected