@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
31 lines (30 loc) • 870 B
JavaScript
import { max, min } from "../../utils/index.js";
import unpack from "../../utils/unpack.js";
const rgb2hsl = (...args) => {
args = unpack(args, "rgba");
let [r, g, b] = args;
r /= 255;
g /= 255;
b /= 255;
const minRgb = min(r, g, b);
const maxRgb = max(r, g, b);
const l = (maxRgb + minRgb) / 2;
let s, h;
if (maxRgb === minRgb) {
s = 0;
h = Number.NaN;
} else {
s = l < 0.5 ? (maxRgb - minRgb) / (maxRgb + minRgb) : (maxRgb - minRgb) / (2 - maxRgb - minRgb);
}
if (r == maxRgb) h = (g - b) / (maxRgb - minRgb);
else if (g == maxRgb) h = 2 + (b - r) / (maxRgb - minRgb);
else if (b == maxRgb) h = 4 + (r - g) / (maxRgb - minRgb);
h *= 60;
if (h < 0) h += 360;
if (args.length > 3 && args[3] !== void 0) return [h, s, l, args[3]];
return [h, s, l];
};
export {
rgb2hsl as default
};
//# sourceMappingURL=rgb2hsl.js.map