from __future__ import annotations import re from collections import defaultdict from typing import Iterable from bs4 import BeautifulSoup, Tag from .schemas import FieldKind, SurveyField, SurveyPage _SPACE_RE = re.compile(r"\s+") def _norm(s: str | None) -> str: return _SPACE_RE.sub(" ", (s or "").strip()) def _el_text_near(el: Tag, max_len: int = 160) -> str: """Best-effort label extraction for cleaned DOM (no