fix: 兼容无维度名颜色摘要归位 (#268)

This commit is contained in:
chengma
2026-08-18 14:42:41 +08:00
parent 233ff16d41
commit ad9f4e6eea
3 changed files with 265 additions and 3 deletions
+83 -3
View File
@@ -277,10 +277,10 @@ def _has_visible_color_region(root: ET.Element) -> bool:
def _needs_color_region_restore(root: ET.Element) -> bool:
"""只有第二规格已出现且颜色摘要仍存在时,才判定面板停在中部。"""
"""用维度名或强结构证据判断颜色区域是否已经滑出视口。"""
labels = [_label(node).strip() for node in root.iter("node")]
has_color_summary = any(
has_named_color_summary = any(
label.replace(" ", "").startswith(
("请选择", "請選擇", "已选", "已選", "已选择", "已選擇")
)
@@ -291,7 +291,87 @@ def _needs_color_region_restore(root: ET.Element) -> bool:
_dimension_heading(label) in _SECOND_DIMENSION_HEADINGS
for label in labels
)
return has_color_summary and has_second_heading
if not has_second_heading:
return False
if has_named_color_summary:
return True
# 部分 PDD 面板的摘要只写“已选:具体颜色 具体尺码”,不再带
# “颜色分类”维度名。只有唯一纵向容器内、第二规格标题上方同时
# 存在至少两个完整可点击卡片时,才把它认作已滚动的第一规格。
has_plain_selected_summary = any(
label.replace(" ", "").startswith(
("已选", "已選", "已选择", "已選擇")
)
for label in labels
)
return has_plain_selected_summary and _has_first_dimension_structure(root)
def _has_first_dimension_structure(root: ET.Element) -> bool:
"""确认唯一纵向容器的第二规格标题上方仍有多个第一规格卡片。"""
region = _purchase_panel_scroll_region(root)
if region is None:
return False
width = region[2] - region[0]
height = region[3] - region[1]
if height < width * 0.70:
return False
second_heading_tops = [
bounds[1]
for node in root.iter("node")
if _dimension_heading(_label(node)) in _SECOND_DIMENSION_HEADINGS
if (bounds := _parse_bounds(node.get("bounds", ""))) is not None
if region[0] <= bounds[0]
and region[1] <= bounds[1]
and bounds[2] <= region[2]
and bounds[3] <= region[3]
]
if not second_heading_tops:
return False
second_heading_top = min(second_heading_tops)
excluded = {
"增加数量",
"减少数量",
"提交订单",
"确定",
"打开大图",
}
candidate_bounds: set[Bounds] = set()
for node in root.iter("node"):
if (
node.get("clickable") != "true"
or node.get("enabled", "true") == "false"
or node.get("visible-to-user", "true") == "false"
):
continue
bounds = _parse_bounds(node.get("bounds", ""))
label = _label(node).strip()
if not label or bounds is None:
continue
if not (
region[0] <= bounds[0]
and region[1] <= bounds[1]
and bounds[2] <= region[2]
and bounds[3] <= second_heading_top
):
continue
compact = label.replace(" ", "")
if (
compact.startswith(
("请选择", "請選擇", "已选", "已選", "选择", "選擇")
)
or any(marker in compact for marker in excluded)
or _dimension_heading(label) in (
_COLOR_DIMENSION_HEADINGS | _SECOND_DIMENSION_HEADINGS
)
):
continue
candidate_bounds.add(bounds)
return len(candidate_bounds) >= 2
def _purchase_panel_scroll_region(root: ET.Element) -> Optional[Bounds]: