Source

style/generateProgressiveColorsOfSameHue.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var MAX_HUE = 360;
/**
 * Generate a set of colors from original color to changes of targetValue.
 * For example, generateProgressiveColorsOfSameHue(270, 10)
 * to generate 10 purple colors from darker to lighter
 * @param hue 0 - 360. If greater than 360, will use value of mod 360. Default to 270 (purple theme)
 * @param numberOfColors
 * @param options
 * @returns array of HSL color code
 * @category style
 * @module generateProgressiveColorsOfSameHue
 */
var generateProgressiveColorsOfSameHue = function (hue, numberOfColors, options) {
    if (hue === void 0) { hue = 270; }
    if (options === void 0) { options = {}; }
    var _a = options.lightness, lightness = _a === void 0 ? 50 : _a, _b = options.saturation, saturation = _b === void 0 ? 100 : _b, _c = options.mode, mode = _c === void 0 ? 'lightness' : _c, _d = options.targetValue, targetValue = _d === void 0 ? 80 : _d;
    var normalizedHue = hue % MAX_HUE;
    if (mode === 'saturation') {
        // Decrease saturation
        // Saturation diff between colors
        var saturationDiff_1 = numberOfColors > 1
            ? (targetValue - saturation) / (numberOfColors - 1)
            : 0;
        return new Array(numberOfColors).fill('')
            .map(function (d, index) { return ("hsl(".concat(normalizedHue, ", ").concat(saturation + (saturationDiff_1 * index), "%, ").concat(lightness, "%)")); });
    }
    // Decrease lightness
    // Lightness diff between color
    var lightnessDiff = numberOfColors > 1 ? (targetValue - lightness) / (numberOfColors - 1) : 0;
    return new Array(numberOfColors).fill('')
        .map(function (d, index) { return ("hsl(".concat(normalizedHue, ", ").concat(saturation, "%, ").concat(lightness + (lightnessDiff * index), "%)")); });
};
exports.default = generateProgressiveColorsOfSameHue;