isometric-react
Version:
Isometric styling library made in React with as much flexibility over customization as possible. Rewrite of https://morgancaron.github.io/IsometricSass/ .
52 lines (51 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function HEXToRGB(hex) {
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) || [
"255",
"255",
"255",
];
return {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
};
}
function darken(hex) {
const RGB = HEXToRGB(hex);
let r = RGB.r;
let g = RGB.g;
let b = RGB.b;
(r /= 255), (g /= 255), (b /= 255);
let max = Math.max(r, g, b);
let min = Math.min(r, g, b);
let h = (max + min) / 2;
let s = (max + min) / 2;
let l = (max + min) / 2;
if (max == min) {
h = s = 0;
}
else {
var d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r:
h = (g - b) / d + (g < b ? 6 : 0);
break;
case g:
h = (b - r) / d + 2;
break;
case b:
h = (r - g) / d + 4;
break;
}
h /= 6;
}
return `hsl(${Math.floor(h * 360)}, ${Math.floor(s * 100)}%, ${Math.floor(l * 100) < 20 ? Math.floor(l * 100) : Math.floor(l * 100) - 20}%)`;
}
exports.default = darken;