Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Apr 5, 2023
1 parent fe74b82 commit 8d84004
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/commons/color/get-foreground-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export default function getForegroundColor(node, _, bgColor, options = {}) {
];
let fgColors = [];

for (let i = 0; i < colorStack.length; i++) {
const color = colorStack[i]();
for (const colorFn of colorStack) {
const color = colorFn();
if (!color) {
continue;
}
Expand All @@ -58,7 +58,7 @@ export default function getForegroundColor(node, _, bgColor, options = {}) {
}

const stackingContexts = getStackingContext(node);
const context = findContext(stackingContexts, node);
const context = findNodeInContexts(stackingContexts, node);
return flattenColors(
calculateBlendedForegroundColor(fgColor, context, stackingContexts),
// default page background
Expand Down Expand Up @@ -136,7 +136,6 @@ function calculateBlendedForegroundColor(fgColor, context, stackingContexts) {
);

fgColor = flattenColors(fgColor, bgColor);

context = context.ancestor;
}

Expand All @@ -149,14 +148,13 @@ function calculateBlendedForegroundColor(fgColor, context, stackingContexts) {
* @param {Element} node
* @returns {Object}
*/
function findContext(contexts, node) {
for (let i = 0; i < contexts.length; i++) {
const context = contexts[i];
function findNodeInContexts(contexts, node) {
for (const context of contexts) {
if (context.vNode?.actualNode === node) {
return context;
}

const found = findContext(context.descendants, node);
const found = findNodeInContexts(context.descendants, node);
if (found) {
return found;
}
Expand Down

0 comments on commit 8d84004

Please sign in to comment.