UNPKG

@thangk/easythemer

Version:

Easily generate shades from a colour palette for use in your app

18 lines (17 loc) 637 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // inspired by https://www.jameslmilner.com/posts/converting-rgb-hex-hsl-colors/ function HSLToHex(source) { let { h, s, l } = source; l /= 100; const a = (s * Math.min(l, 1 - l)) / 100; const f = (n) => { const k = (n + h / 30) % 12; const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1); return Math.round(255 * color) .toString(16) .padStart(2, "0"); // convert to Hex and prefix "0" if needed }; return `#${f(0)}${f(8)}${f(4)}`; } exports.default = HSLToHex;