feat: learn_theme — add analyze_styles, DEFAULTS, most_common_value, derive_darkmode integration

Excludes dominant text color from accent candidates; blockquote-first
quote_bg heuristic avoids picking up decorative divider colors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangzhuc 2026-04-01 01:56:28 +08:00
parent e457b4463b
commit 95ba69fd5a

View file

@ -290,6 +290,7 @@ def analyze_styles(grouped: dict) -> dict:
# --- primary (accent color) ------------------------------------------------
# Collect non-gray colors from strong/section/h1-h3/span; boost colors from
# elements whose font-size is ≥ 20 px (weight × 5).
# Exclude the dominant text color so near-black body text never wins.
accent_tags = {"strong", "section", "h1", "h2", "h3", "span"}
accent_counter: Counter = Counter()
for tag in accent_tags:
@ -300,6 +301,8 @@ def analyze_styles(grouped: dict) -> dict:
hex_c = rgb_to_hex(color_val)
if is_gray(hex_c):
continue
if hex_c == result["text"]:
continue
# Check font-size for boost
fs = d.get("font-size")
fs_px = _parse_px(fs) if fs else None