UNPKG

@actinc/dls

Version:

Design Language System (DLS) for ACT & Encoura front-end projects.

111 lines 3.23 kB
/** * Copyright (c) ACT, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ /* * Do not modify these values unless UX give us new values, * they are used to generate our Figma palette */ var brightnessCoefficient = [ { brightness: 0.9, colorIndex: 50, }, { brightness: 0.69, colorIndex: 100, }, { brightness: 0.54, colorIndex: 200, }, { brightness: 0.33, colorIndex: 300, }, { brightness: 0.2, colorIndex: 400, }, { brightness: 0, colorIndex: 500, }, { brightness: -0.09, colorIndex: 600, }, { brightness: -0.29, colorIndex: 700, }, { brightness: -0.45, colorIndex: 800, }, { brightness: -0.58, colorIndex: 900, }, ]; export var hexToRGB = function (color) { var r = ''; var g = ''; var b = ''; if ((color.length !== 4 && color.length !== 7) || color[0] !== '#') return undefined; if (color.length === 4) { r = "0x".concat(color[1]).concat(color[1]); g = "0x".concat(color[2]).concat(color[2]); b = "0x".concat(color[3]).concat(color[3]); } else if (color.length === 7) { r = "0x".concat(color[1]).concat(color[2]); g = "0x".concat(color[3]).concat(color[4]); b = "0x".concat(color[5]).concat(color[6]); } return [Number(r), Number(g), Number(b)]; }; export var RGBToHex = function (r, g, b) { var R = r.toString(16); var G = g.toString(16); var B = b.toString(16); if (R.length === 1) R = "0".concat(R); if (G.length === 1) G = "0".concat(G); if (B.length === 1) B = "0".concat(B); return "#".concat(R.slice(0, 2)).concat(G.slice(0, 2)).concat(B.slice(0, 2)); }; export var lightenRGB = function (color, percentage) { var RGBColor = hexToRGB(color); if (!RGBColor) return undefined; if (percentage === 0) return color; if (percentage > 0) { return RGBToHex(Math.round(RGBColor[0] + ((255 - RGBColor[0]) * percentage) / 100), Math.round(RGBColor[1] + ((255 - RGBColor[1]) * percentage) / 100), Math.round(RGBColor[2] + ((255 - RGBColor[2]) * percentage) / 100)); } return RGBToHex(Math.round(RGBColor[0] * (1 + percentage / 100)), Math.round(RGBColor[1] * (1 + percentage / 100)), Math.round(RGBColor[2] * (1 + percentage / 100))); }; export var figmaColorGenerator = function (color) { var colorPalette = {}; brightnessCoefficient.forEach(function (_a) { var brightness = _a.brightness, colorIndex = _a.colorIndex; var generatedColor = lightenRGB(color, brightness * 100); if (generatedColor) colorPalette[colorIndex] = generatedColor; }); return colorPalette; }; export var generatePaletteColors = function (colors) { var colorPalette = {}; colors.forEach(function (color) { colorPalette[color.colorName] = figmaColorGenerator(color.colorHEX); }); return colorPalette; }; //# sourceMappingURL=index.js.map