Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix: issue with color format handling, resolves #3104

Amruth Pillai273e17c0d34c
diff --git a/packages/utils/src/color.test.ts b/packages/utils/src/color.test.ts
index 35427288a..113ddd7f6 100644
--- a/packages/utils/src/color.test.ts
+++ b/packages/utils/src/color.test.ts
@@ -21,6 +21,11 @@ describe("rgbaStringToHex", () => {
it("converts arbitrary mid-range color", () => {
expect(rgbaStringToHex("rgb(128, 64, 200)")).toBe("#8040c8");
});
+
+ it("preserves 6-digit hex colors", () => {
+ expect(rgbaStringToHex("#F1F5F9")).toBe("#f1f5f9");
+ expect(rgbaStringToHex("#0F172A")).toBe("#0f172a");
+ });
});
describe("parseColorString", () => {
diff --git a/packages/utils/src/color.ts b/packages/utils/src/color.ts
index b86313cbc..57a7ab911 100644
--- a/packages/utils/src/color.ts
+++ b/packages/utils/src/color.ts
@@ -2,10 +2,17 @@ import type { ColorResult } from "@uiw/color-convert";
import { hsvaToHex, rgbaStringToHsva } from "@uiw/color-convert";
export function rgbaStringToHex(rgba: string): string {
+ const color = parseColorString(rgba);
+ if (color) return `#${toHexComponent(color.r)}${toHexComponent(color.g)}${toHexComponent(color.b)}`;
+
const hsva = rgbaStringToHsva(rgba);
return hsvaToHex(hsva);
}
+function toHexComponent(value: number): string {
+ return Math.max(0, Math.min(255, value)).toString(16).padStart(2, "0");
+}
+
export function parseColorString(value: string): ColorResult["rgba"] | null {
const trimmed = value.trim();