diff --git a/lib/commons/color/get-foreground-color.js b/lib/commons/color/get-foreground-color.js index 999e8908f8..dca800421e 100644 --- a/lib/commons/color/get-foreground-color.js +++ b/lib/commons/color/get-foreground-color.js @@ -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; } @@ -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 @@ -136,7 +136,6 @@ function calculateBlendedForegroundColor(fgColor, context, stackingContexts) { ); fgColor = flattenColors(fgColor, bgColor); - context = context.ancestor; } @@ -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; }