Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(branding): don't report a near-white tint as the primary color (#5103)
Abimael Martell024ff054a425
diff --git a/apps/api/src/__tests__/lib/branding/color-roles.test.ts b/apps/api/src/__tests__/lib/branding/color-roles.test.tsindex a57917a78..e2dcff155 100644--- a/apps/api/src/__tests__/lib/branding/color-roles.test.ts+++ b/apps/api/src/__tests__/lib/branding/color-roles.test.ts@@ -346,3 +346,41 @@ describe("browser link colors from the model", () => {expect(merged.colors?.secondary).toBe("#2E7D32");});});++describe("near-white primaries", () => {+ it("keeps the brand color when the model answers with a pale section background", () => {+ const merged = mergeBrandingResults(+ { colorScheme: "light", colors: { primary: "#533AFD" } },+ {+ ...emptyLlm,+ colorRoles: {+ primaryColor: "#E5EDF5",+ accentColor: "#533AFD",+ backgroundColor: "#FFFFFF",+ textPrimary: "#0A2540",+ confidence: 0.9,+ },+ },+ [],+ );+ expect(merged.colors?.primary).toBe("#533AFD");+ });++ it("skips a pale tint when picking the primary on a light page", () => {+ expect(+ pickBrandPrimary(["#F0F6FF", "#0056D2", "#FFFFFF"], {+ background: "#FFFFFF",+ colorScheme: "light",+ }),+ ).toBe("#0056D2");+ });++ it("keeps a light brand color on a dark page", () => {+ expect(+ pickBrandPrimary(["#E7DBFF", "#0A0A0A"], {+ background: "#0A0A0A",+ colorScheme: "dark",+ }),+ ).toBe("#E7DBFF");+ });+});diff --git a/apps/api/src/lib/branding/color-roles.ts b/apps/api/src/lib/branding/color-roles.tsindex 9907c79ff..76bc2e7dd 100644--- a/apps/api/src/lib/branding/color-roles.ts+++ b/apps/api/src/lib/branding/color-roles.ts@@ -51,13 +51,24 @@ export function colorDistance(a?: string | null, b?: string | null): number {return Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]);}-/** Chromatic brand color — not gray chrome, and not a near-black nav on light pages. */+/**+ * Nearly white, whatever its tint (#E5EDF5, #F2E8E1): on a light page that is+ * a section background, not a brand color.+ */+export function isPale(hex: string): boolean {+ const h = hex.replace("#", "");+ if (h.length < 6) return false;+ const channels = [0, 2, 4].map(i => parseInt(h.slice(i, i + 2), 16));+ return (Math.max(...channels) + Math.min(...channels)) / 2 / 255 > 0.9;+}++/** Chromatic brand color — not gray chrome, and not near-black or near-white chrome on light pages. */export function isUsableBrandPrimary(hex: string,colorScheme?: "light" | "dark",): boolean {if (isGrayish(hex)) return false;- if (colorScheme !== "dark" && isNearBlack(hex)) return false;+ if (colorScheme !== "dark" && (isNearBlack(hex) || isPale(hex))) return false;return true;}@@ -102,7 +113,7 @@ export function pickBrandPrimary(const chromatic = ranked.find(h => {if (skip.has(h) || isGrayish(h)) return false;- if (lightPage && isNearBlack(h)) return false;+ if (lightPage && (isNearBlack(h) || isPale(h))) return false;return true;});if (chromatic) return chromatic;