fix: TEXT 被 IMAGE 包含时也移除(aria-label 等隐藏文字)

This commit is contained in:
李进
2026-07-24 18:29:06 +08:00
parent d4d86eb1da
commit 5035647c91
+6 -2
View File
@@ -641,12 +641,16 @@ async function convert(input) {
for (var i = sg.children.length - 1; i >= 0; i--) { for (var i = sg.children.length - 1; i >= 0; i--) {
var ci = sg.children[i]; var ci = sg.children[i];
if (!ci.rect) continue; if (!ci.rect) continue;
// TEXT 节点被 IMAGE 完全覆盖时移除 // TEXT 节点被 IMAGE 完全覆盖或包含时移除
if (ci.type === 'TEXT') { if (ci.type === 'TEXT') {
var cx = Math.round(ci.rect.x), cy = Math.round(ci.rect.y); var cx = Math.round(ci.rect.x), cy = Math.round(ci.rect.y);
var cw = Math.round(ci.rect.w), ch = Math.round(ci.rect.h); var cw = Math.round(ci.rect.w), ch = Math.round(ci.rect.h);
for (var ir of imageRects) { for (var ir of imageRects) {
if (Math.abs(cx - ir.x) < 3 && Math.abs(cy - ir.y) < 3 && Math.abs(cw - ir.w) < 3 && Math.abs(ch - ir.h) < 3) { // 完全重叠
var exactMatch = Math.abs(cx - ir.x) < 3 && Math.abs(cy - ir.y) < 3 && Math.abs(cw - ir.w) < 3 && Math.abs(ch - ir.h) < 3;
// TEXT 被 IMAGE 包含(IMAGE 在 TEXT 内部)
var contained = ir.x >= cx - 5 && ir.y >= cy - 5 && ir.x + ir.w <= cx + cw + 5 && ir.y + ir.h <= cy + ch + 5;
if (exactMatch || contained) {
overlapRemove.add(ci.id); overlapRemove.add(ci.id);
break; break;
} }