"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getColorContrast = exports.getColorFromToken = exports.getNextColor = exports.DataVizPalette = void 0;
var d3_color_1 = require("d3-color");
exports.DataVizPalette = {
    color1: 'qualitative.1',
    color2: 'qualitative.2',
    color3: 'qualitative.3',
    color4: 'qualitative.4',
    color5: 'qualitative.5',
    color6: 'qualitative.6',
    color7: 'qualitative.7',
    color8: 'qualitative.8',
    color9: 'qualitative.9',
    color10: 'qualitative.10',
    color11: 'qualitative.11',
    color12: 'qualitative.12',
    color13: 'qualitative.13',
    color14: 'qualitative.14',
    color15: 'qualitative.15',
    color16: 'qualitative.16',
    color17: 'qualitative.17',
    color18: 'qualitative.18',
    color19: 'qualitative.19',
    color20: 'qualitative.20',
    color21: 'qualitative.21',
    color22: 'qualitative.22',
    color23: 'qualitative.23',
    color24: 'qualitative.24',
    color25: 'qualitative.25',
    color26: 'qualitative.26',
    color27: 'qualitative.27',
    color28: 'qualitative.28',
    color29: 'qualitative.29',
    color30: 'qualitative.30',
    color31: 'qualitative.31',
    color32: 'qualitative.32',
    color33: 'qualitative.33',
    color34: 'qualitative.34',
    color35: 'qualitative.35',
    color36: 'qualitative.36',
    color37: 'qualitative.37',
    color38: 'qualitative.38',
    color39: 'qualitative.39',
    color40: 'qualitative.40',
    info: 'semantic.info',
    disabled: 'semantic.disabled',
    highError: 'semantic.highError',
    error: 'semantic.error',
    warning: 'semantic.warning',
    success: 'semantic.success',
    highSuccess: 'semantic.highSuccess',
};
var QualitativePalette = {
    '1': ['#637cef'], // [cornflower.tint10],
    '2': ['#e3008c'], // [hotPink.primary],
    '3': ['#2aa0a4'], // [teal.tint20],
    '4': ['#9373c0'], // [orchid.tint10],
    '5': ['#13a10e'], // [lightGreen.primary],
    '6': ['#3a96dd'], // [lightBlue.primary],
    '7': ['#ca5010'], // [pumpkin.primary],
    '8': ['#57811b'], // [lime.shade20],
    '9': ['#b146c2'], // [lilac.primary],
    '10': ['#ae8c00'], // [gold.shade10],
    '11': ['#3c51b4', '#93a4f4'], // [cornflower.shade20, cornflower.tint30],
    '12': ['#ad006a', '#ee5fb7'], // [hotPink.shade20, hotPink.tint30],
    '13': ['#026467', '#4cb4b7'], // [teal.shade20, teal.tint30],
    '14': ['#674c8c', '#a083c9'], // [orchid.shade20, orchid.tint20],
    '15': ['#0e7a0b', '#27ac22'], // [lightGreen.shade20, lightGreen.tint10],
    '16': ['#2c72a8', '#4fa1e1'], // [lightBlue.shade20, lightBlue.tint10],
    '17': ['#9a3d0c', '#d77440'], // [pumpkin.shade20, pumpkin.tint20],
    '18': ['#405f14', '#73aa24'], // [lime.shade30, lime.primary],
    '19': ['#863593', '#c36bd1'], // [lilac.shade20, lilac.tint20],
    '20': ['#6d5700', '#d0b232'], // [gold.shade30, gold.tint20],
    '21': ['#4f6bed'], // [cornflower.primary],
    '22': ['#ea38a6'], // [hotPink.tint20],
    '23': ['#038387'], // [teal.primary],
    '24': ['#8764b8'], // [orchid.primary],
    '25': ['#11910d'], // [lightGreen.shade10],
    '26': ['#3487c7'], // [lightBlue.shade10],
    '27': ['#d06228'], // [pumpkin.tint10],
    '28': ['#689920'], // [lime.shade10],
    '29': ['#ba58c9'], // [lilac.tint10],
    '30': ['#937700', '#c19c00'], // [gold.shade20, gold.primary],
    '31': ['#2c3c85', '#c8d1fa'], // [cornflower.shade30, cornflower.tint40],
    '32': ['#7f004e', '#f7adda'], // [hotPink.shade30, hotPink.tint40],
    '33': ['#02494c', '#9bd9db'], // [teal.shade30, teal.tint40],
    '34': ['#4c3867', '#b29ad4'], // [orchid.shade30, orchid.tint30],
    '35': ['#0b5a08', '#a7e3a5'], // [lightGreen.shade30, lightGreen.tint40],
    '36': ['#20547c', '#83bdeb'], // [lightBlue.shade30, lightBlue.tint30],
    '37': ['#712d09', '#df8e64'], // [pumpkin.shade30, pumpkin.tint30],
    '38': ['#23330b', '#a4cc6c'], // [lime.shade40, lime.tint30],
    '39': ['#63276d', '#cf87da'], // [lilac.shade30, lilac.tint30],
    '40': ['#3a2f00', '#dac157'], // [gold.shade40, gold.tint30],
};
var SemanticPalette = {
    info: ['#015cda'],
    disabled: ['#dbdbdb', '#4d4d4d'], // [grey[86], grey[30]]
    highError: ['#6e0811', '#cc2635'], // [cranberry.shade30, cranberry.tint10],
    error: ['#c50f1f', '#dc626d'], // [cranberry.primary, cranberry.tint30],
    warning: ['#f7630c', '#f87528'], // [orange.primary, orange.tint10],
    success: ['#107c10', '#54b054'], // [green.primary, green.tint30],
    highSuccess: ['#094509', '#218c21'], // [green.shade30, green.tint10],
};
var Colors = {
    qualitative: QualitativePalette,
    semantic: SemanticPalette,
};
var QUALITATIVE_COLORS = Object.values(QualitativePalette);
var TOKENS = Object.values(exports.DataVizPalette);
var getThemeSpecificColor = function (colors, isDarkTheme) {
    if (colors.length === 0) {
        return '';
    }
    var colorIdx = Number(isDarkTheme);
    if (colorIdx < colors.length) {
        return colors[colorIdx];
    }
    return colors[0];
};
var getNextColor = function (index, offset, isDarkTheme) {
    if (offset === void 0) { offset = 0; }
    if (isDarkTheme === void 0) { isDarkTheme = false; }
    var colors = QUALITATIVE_COLORS[(index + offset) % QUALITATIVE_COLORS.length];
    return getThemeSpecificColor(colors, isDarkTheme);
};
exports.getNextColor = getNextColor;
var getColorFromToken = function (token, isDarkTheme) {
    if (isDarkTheme === void 0) { isDarkTheme = false; }
    if (TOKENS.indexOf(token) >= 0) {
        var _a = token.split('.'), paletteName = _a[0], colorCode = _a[1];
        var colors = Colors[paletteName][colorCode];
        return getThemeSpecificColor(colors, isDarkTheme);
    }
    return token;
};
exports.getColorFromToken = getColorFromToken;
//For reference to how these numbers are calculated, refer https://www.w3.org/TR/WCAG/#dfn-contrast-ratio
var rgbLrgb1 = function (v) {
    return v <= 0.04045 ? v / 12.92 : Math.pow(((v + 0.055) / 1.055), 2.4);
};
var rgbLrgb = function (_a) {
    var r = _a.r, g = _a.g, b = _a.b;
    return {
        r: rgbLrgb1(r / 255),
        g: rgbLrgb1(g / 255),
        b: rgbLrgb1(b / 255),
    };
};
var lrgbLuminance = function (_a) {
    var r = _a.r, g = _a.g, b = _a.b;
    return 0.2126 * r + 0.7152 * g + 0.0722 * b;
};
var getColorContrast = function (c1, c2) {
    var l1 = lrgbLuminance(rgbLrgb((0, d3_color_1.rgb)(c1)));
    var l2 = lrgbLuminance(rgbLrgb((0, d3_color_1.rgb)(c2)));
    return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
};
exports.getColorContrast = getColorContrast;
//# sourceMappingURL=colors.js.map