@@ -39,26 +39,42 @@ export default function getForegroundColor(node, _, bgColor, options = {}) {
3939 }
4040
4141 fgColors = fgColors . concat ( color ) ;
42-
43- if ( color . alpha === 1 ) {
42+ // If any color in the array is fully opaque, break
43+ if ( Array . isArray ( color ) ) {
44+ if ( color . some ( c => c && c . alpha === 1 ) ) {
45+ break ;
46+ }
47+ } else if ( color . alpha === 1 ) {
4448 break ;
4549 }
4650 }
4751
52+ if ( ! fgColors . length ) {
53+ // Could not determine foreground color
54+ incompleteData . set ( 'fgColor' , 'No foreground color found' ) ;
55+ return null ;
56+ }
57+
4858 const fgColor = fgColors . reduce ( ( source , backdrop ) => {
4959 return flattenColors ( source , backdrop ) ;
5060 } ) ;
5161
5262 // Lastly blend the background
5363 bgColor ??= getBackgroundColor ( node , [ ] ) ;
64+
5465 if ( bgColor === null ) {
55- const reason = incompleteData . get ( 'bgColor' ) ;
56- incompleteData . set ( 'fgColor' , reason ) ;
57- return null ;
66+ // Return the foreground color as-is if background color is not found
67+ return fgColor ;
5868 }
5969
6070 const stackingContexts = getStackingContext ( node ) ;
6171 const context = findNodeInContexts ( stackingContexts , node ) ;
72+
73+ // If context is not found, fallback to blending with bgColor only
74+ if ( ! context ) {
75+ return flattenColors ( fgColor , bgColor ) ;
76+ }
77+
6278 return flattenColors (
6379 calculateBlendedForegroundColor ( fgColor , context , stackingContexts ) ,
6480 // default page background
0 commit comments