MCPcopy
hub / github.com/GitbookIO/gitbook / shadesOfColor

Function shadesOfColor

packages/colors/src/transformations.ts:109–150  ·  view source on GitHub ↗
(hex: string, halfShades = false)

Source from the content-addressed store, hash-verified

107 * @returns {{[key: number]: string}}
108 */
109export function shadesOfColor(hex: string, halfShades = false) {
110 const baseColor = hex;
111
112 const shades = [
113 50,
114 100,
115 200,
116 300,
117 400,
118 500,
119 600,
120 700,
121 800,
122 900,
123 ...(halfShades ? [150, 250, 350, 450, 550, 650, 750, 850] : []),
124 ].sort();
125
126 const result: ColorShades = {};
127
128 for (const shade of shades) {
129 const key = shade.toString();
130
131 if (shade === 500) {
132 result[key] = hex;
133 continue;
134 }
135
136 let shadeIndex = shade;
137 const isDarkShade = shadeIndex > 500;
138 if (isDarkShade) {
139 shadeIndex -= 500;
140 }
141
142 const percentage = shadeIndex / 500;
143 const startColor = isDarkShade ? DARK_BASE : baseColor;
144 const endColor = isDarkShade ? baseColor : LIGHT_BASE;
145
146 result[key] = getColor(percentage, hexToRgbArray(startColor), hexToRgbArray(endColor));
147 }
148
149 return result;
150}
151
152export type ColorScaleOptions = {
153 /** If set to `true`, inverts the scale (so 1 is black instead of white) and uses `colorMixMapping.dark` with different mix ratios per step. */

Callers 1

generateShadesFunction · 0.90

Calls 3

getColorFunction · 0.85
hexToRgbArrayFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected