MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / getColorInfo

Function getColorInfo

packages/backend/src/tailwind/conversionTables.ts:176–242  ·  view source on GitHub ↗
(fill: SolidPaint | ColorStop)

Source from the content-addressed store, hash-verified

174 * Returns type, name, hex and meta values
175 */
176export function getColorInfo(fill: SolidPaint | ColorStop) {
177 // variables
178 let colorName: string;
179 let colorType: "arbitrary" | "tailwind" | "variable";
180 let hex: string = "#" + rgbTo6hex(fill.color);
181 let meta: string = "";
182
183 // variable
184 if ((fill as any).variableColorName) {
185 // Use pre-computed variable name if available
186 colorName = (fill as any).variableColorName; // || variableToColorName(fill.boundVariables.color);
187 colorType = "variable";
188 meta = "custom";
189
190 return {
191 colorType,
192 colorName,
193 hex,
194 meta,
195 };
196 }
197
198 // Check for pure black/white first
199 if (fill.color.r === 0 && fill.color.g === 0 && fill.color.b === 0) {
200 return {
201 colorType: "tailwind",
202 colorName: "black",
203 hex: "#000000",
204 meta: "",
205 };
206 } else if (fill.color.r === 1 && fill.color.g === 1 && fill.color.b === 1) {
207 return {
208 colorType: "tailwind",
209 colorName: "white",
210 hex: "#ffffff",
211 meta: "",
212 };
213 } else {
214 // get tailwind color as comparison
215 const { name, value } = nearestColorFromRgb(fill.color);
216
217 // round color
218 if (localTailwindSettings.roundTailwindColors || hex === value) {
219 colorName = name;
220 colorType = "tailwind";
221 if (hex !== value) {
222 meta = "rounded";
223 }
224
225 // must come last, as previous comparison
226 hex = value;
227 }
228
229 // exact color
230 else {
231 colorName = `[${hex}]`;
232 colorType = "arbitrary";
233 }

Callers 3

tailwindColorFunction · 0.90
tailwindSolidColorFunction · 0.90
tailwindGradientStopFunction · 0.90

Calls 2

rgbTo6hexFunction · 0.90
nearestColorFromRgbFunction · 0.85

Tested by

no test coverage detected