Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions lib/commons/color/get-foreground-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading