UNPKG

@react-md/utils

Version:
49 lines 1.52 kB
var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; import { hexToRGB } from "./hexToRGB"; var RED_MULTIPLIER = 0.2126; var GREEN_MULTIPLIER = 0.7152; var BLUE_MULTIPLIER = 0.0722; /** * I really couldn't figure out how to name these "magic" numbers since the * formula doesn't really describe it much: * * @see https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests * @internal */ function get8BitColor(color) { color /= 255; if (color <= 0.03928) { return color / 12.92; } return Math.pow(((color + 0.055) / 1.055), 2.4); } /** * A number closest to 0 should be closest to black while a number closest to 1 * should be closest to white. * * @see https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests * @internal */ export function getLuminance(color) { var _a = __read(hexToRGB(color), 3), r = _a[0], g = _a[1], b = _a[2]; var red = get8BitColor(r) * RED_MULTIPLIER; var green = get8BitColor(g) * GREEN_MULTIPLIER; var blue = get8BitColor(b) * BLUE_MULTIPLIER; return red + green + blue; } //# sourceMappingURL=getLuminance.js.map