From 08642ee315e90d346aeb555b189f7b183dda91aa Mon Sep 17 00:00:00 2001 From: Pooja0504 Date: Fri, 27 Jun 2025 17:00:29 +0530 Subject: [PATCH] AXE-1720 : distinguishable-link enhancements --- lib/commons/color/get-foreground-color.js | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/commons/color/get-foreground-color.js b/lib/commons/color/get-foreground-color.js index dca800421..d4ed670b2 100644 --- a/lib/commons/color/get-foreground-color.js +++ b/lib/commons/color/get-foreground-color.js @@ -39,26 +39,42 @@ export default function getForegroundColor(node, _, bgColor, options = {}) { } fgColors = fgColors.concat(color); - - if (color.alpha === 1) { + // If any color in the array is fully opaque, break + if (Array.isArray(color)) { + if (color.some(c => c && c.alpha === 1)) { + break; + } + } else if (color.alpha === 1) { break; } } + if (!fgColors.length) { + // Could not determine foreground color + incompleteData.set('fgColor', 'No foreground color found'); + return null; + } + const fgColor = fgColors.reduce((source, backdrop) => { return flattenColors(source, backdrop); }); // Lastly blend the background bgColor ??= getBackgroundColor(node, []); + if (bgColor === null) { - const reason = incompleteData.get('bgColor'); - incompleteData.set('fgColor', reason); - return null; + // Return the foreground color as-is if background color is not found + return fgColor; } const stackingContexts = getStackingContext(node); const context = findNodeInContexts(stackingContexts, node); + + // If context is not found, fallback to blending with bgColor only + if (!context) { + return flattenColors(fgColor, bgColor); + } + return flattenColors( calculateBlendedForegroundColor(fgColor, context, stackingContexts), // default page background