This commit is contained in:
Josh at WLTechBlog
2025-12-09 14:58:00 -07:00
parent 77d1061ae7
commit 87e5e0555d
6 changed files with 159 additions and 41 deletions

View File

@@ -20,10 +20,10 @@ After the initial fix, the tool became too aggressive:
### Issue 3: Wrong Text Color for Elements with Child Spans
The tool used parent element colors instead of actual visible text colors:
- **Example:** `<a>` element with `color: blue` containing `<span>` with `color: rgb(12, 90, 201)`
- **Reported:** Used the `<a>`'s color
- **Reality:** The visible text uses the `<span>`'s color
- **Root Cause:** Tool only checked the matched element's color, not child elements that contain the actual text
- **Example:** `<a style="color: rgb(12, 113, 195)"><span style="color: #ffffff;">314-560-7171</span><br></a>`
- **Reported:** Used the `<a>`'s color (blue rgb(12, 113, 195)) = 4.17:1 contrast
- **Reality:** The visible text uses the `<span>`'s color (white rgb(255, 255, 255)) = 21.00:1 contrast
- **Root Cause:** Tool only checked the matched element's color, not descendant elements that contain the actual text
## Solutions
@@ -134,34 +134,58 @@ After deploying the fix, test on:
3. Restart the cremote daemon (deployment-specific process)
4. Restart the MCP server or Augment extension to pick up changes
#### 3. Enhanced Text Color Detection (Lines 9257-9322)
#### 3. Enhanced Text Color Detection (Lines 9301-9354)
**Before:** Always used the matched element's text color
**After:**
- Checks if the element has visible child elements with text
- If child elements exist, uses the first child's color
- This ensures we get the actual visible text color, not the parent container's color
- Recursively searches all descendant elements to find the one with the most text content
- Uses that element's color for contrast checking
- Handles complex structures like `<a><span>text</span><br></a>`
- Skips invisible elements (display: none, visibility: hidden)
```javascript
// Get the actual text-bearing element for accurate color detection
let textElement = element;
let textStyle = style;
// Recursively find the element with the most text content
function findTextBearingElement(el) {
const descendants = el.querySelectorAll('*');
let bestElement = el;
let maxTextLength = 0;
// Check if element has child elements (not just text nodes)
const childElements = Array.from(element.children).filter(child => {
const childText = child.textContent.trim();
if (!childText) return false;
const childStyle = window.getComputedStyle(child);
return childStyle.display !== 'none' && childStyle.visibility !== 'hidden';
});
// Check the element itself first
const directText = Array.from(el.childNodes)
.filter(node => node.nodeType === Node.TEXT_NODE)
.map(node => node.textContent.trim())
.join('').length;
// If there are visible child elements with text, use the first one's color
if (childElements.length > 0) {
textElement = childElements[0];
textStyle = window.getComputedStyle(textElement);
if (directText > maxTextLength) {
maxTextLength = directText;
bestElement = el;
}
// Check all descendants
for (const desc of descendants) {
const descStyle = window.getComputedStyle(desc);
if (descStyle.display === 'none' || descStyle.visibility === 'hidden') {
continue;
}
const descText = Array.from(desc.childNodes)
.filter(node => node.nodeType === Node.TEXT_NODE)
.map(node => node.textContent.trim())
.join('').length;
if (descText > maxTextLength) {
maxTextLength = descText;
bestElement = desc;
}
}
return bestElement;
}
// Find the element with the most text content
textElement = findTextBearingElement(element);
textStyle = window.getComputedStyle(textElement);
const fgColor = textStyle.color;
```
@@ -169,5 +193,5 @@ const fgColor = textStyle.color;
- `daemon/daemon.go` - Lines 9152-9220 (gradient analysis function)
- `daemon/daemon.go` - Lines 9305-9340 (background detection logic)
- `daemon/daemon.go` - Lines 9257-9322 (text color detection enhancement)
- `daemon/daemon.go` - Lines 9301-9354 (text color detection enhancement with recursive search)