Files
Harvey_Team_Page/design/dark-palette/verify-shipped.py
T
FastD da710c4686 Accents, page edits and planet tuning; drop Pencil backups
Design: add the orange second accent from the UZURON palette and split the
colour roles (orange marks, green acts) in both themes; soften the dark green
and lift the dark cards toward the page background. Background options for the
next review are in design/background-options-2026-10-13/.

Page: replace the process block with an individual-approach section; drop the
budget form field; rename the contact field to a preferred channel; add a
submit confirmation dialog, studio links (mail, VK, RuStore), the First Step
Radio card, portfolio filters by platform, stack, genre and status, a cookie
bar and a removable hero ticker. Cards keep the mascot face; the member window
gains the real photo and the city.

Planet: fold the speed knobs into SPEED_TAU and SPEED_MIN with a hard stop
below the threshold; the pill is the only hover target and the summary card is
inert.

Repo: remove .pen backups from the index, ignore backups and Python artefacts,
drop generated pen-sync exports.
2026-10-13 22:08:24 +03:00

168 lines
7.1 KiB
Python

"""Verify the SHIPPED palettes: parse tokens from src/index.html, re-measure WCAG AA for
BOTH themes, and cross-check the values written in design/spec.md (§10.9.1 dark, §10.25 accents).
Запуск: python design/dark-palette/verify-shipped.py
Exit 0 — все пары проходят и spec совпадает с продом; exit 1 — расхождение.
Источник значений — сам прод (src/index.html), а не таблица в документации:
если кто-то поправит токен в HTML и забудет spec, скрипт это покажет.
Волна 2026-10-13: проверяются ОБЕ темы (было — только тёмная), добавлены пары оранжевого акцента.
"""
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
HTML = ROOT / "src" / "index.html"
SPEC = ROOT / "design" / "spec.md"
TEXT_MIN, UI_MIN = 4.5, 3.0
# ------------------------------------------------------------------ helpers
def rgb(h):
h = h.lstrip('#')
if len(h) == 3: # --input-bg светлой темы задан как `#fff`
h = ''.join(c * 2 for c in h)
return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))
def _lin(c):
c = c / 255.0
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
def lum(h):
r, g, b = rgb(h)
return 0.2126 * _lin(r) + 0.7152 * _lin(g) + 0.0722 * _lin(b)
def ratio(fg, bg):
a, b = lum(fg), lum(bg)
hi, lo = max(a, b), min(a, b)
return (hi + 0.05) / (lo + 0.05)
def block(css, selector):
m = re.search(re.escape(selector) + r"\s*\{(.*?)\}", css, re.S)
if not m:
raise SystemExit(f"selector not found: {selector}")
out = {}
for name, value in re.findall(r"(--[a-z0-9-]+)\s*:\s*([^;]+);", m.group(1)):
out[name] = value.strip()
return out
# ------------------------------------------------------------------ parse
css = HTML.read_text(encoding="utf-8")
light = block(css, ":root")
dark = block(css, '[data-theme="dark"]')
PAIRS = [
("text", "--text-1", "--bg"), ("text", "--text-1", "--card"), ("text", "--text-1", "--input-bg"),
("text", "--text-2", "--bg"), ("text", "--text-2", "--card"), ("text", "--text-2", "--input-bg"),
("text", "--text-3", "--bg"), ("text", "--text-3", "--card"), ("text", "--text-3", "--input-bg"),
("text", "--brand-deep", "--bg"), ("text", "--brand-deep", "--card"), ("text", "--brand-deep", "--input-bg"),
("text", "--accent-deep", "--bg"), ("text", "--accent-deep", "--card"), ("text", "--accent-deep", "--input-bg"),
("ui", "--line-strong", "--bg"), ("ui", "--line-strong", "--card"), ("ui", "--line-strong", "--input-bg"),
("text", "--danger", "--bg"), ("text", "--danger", "--card"),
("text", "--on-brand", "--brand"),
("text", "--on-accent", "--accent"),
("text", "--on-deep", "--brand-deep"),
]
EXTRA = [
("--on-brand / --brand-strong", "--on-brand", "--brand-strong", TEXT_MIN),
("--on-brand / --brand-active", "--on-brand", "--brand-active", TEXT_MIN),
]
fails = []
print(f"src/index.html :root({len(light)} tokens) [data-theme=dark]({len(dark)} tokens)")
for theme_name, tokens in (("light :root", light), ("dark [data-theme=dark]", dark)):
print(f"\n=== {theme_name} ===")
print(f"{'pair':52s} {'value':>8s} {'min':>4s} verdict")
for kind, fg, bg in PAIRS:
fg_v, bg_v = tokens.get(fg), tokens.get(bg)
if fg_v is None or bg_v is None:
fails.append(f"{theme_name}: missing token {fg if fg_v is None else bg}")
print(f"{fg} / {bg:12s} MISSING")
continue
r = ratio(fg_v, bg_v)
mn = TEXT_MIN if kind == "text" else UI_MIN
ok = r >= mn
if not ok:
fails.append(f"{theme_name}: {fg} {fg_v} on {bg} {bg_v} = {r:.2f} < {mn}")
print(f"{(fg + ' ' + fg_v + ' on ' + bg + ' ' + bg_v):52s} {r:8.2f} {mn:4.1f} {'PASS' if ok else 'FAIL'}")
print()
for label, fg, bg, mn in EXTRA:
r = ratio(tokens[fg], tokens[bg])
ok = r >= mn
if not ok:
fails.append(f"{theme_name}: {label} = {r:.2f} < {mn}")
print(f"{label:52s} {r:8.2f} {mn:4.1f} {'PASS' if ok else 'FAIL'}")
print()
for label, fn in (
("--bg / --card (surface step)", lambda t: ratio(t["--bg"], t["--card"])),
("--card / --input-bg (surface step)", lambda t: ratio(t["--card"], t["--input-bg"])),
("--hairline / --bg (decoration)", lambda t: ratio(t["--hairline"], t["--bg"])),
("--brand fill / --bg", lambda t: ratio(t["--brand"], t["--bg"])),
("--accent fill / --bg", lambda t: ratio(t["--accent"], t["--bg"])),
):
print(f"{label:52s} {fn(tokens):8.3f}")
# ------------------------------------------------- spec ↔ production cross-check
spec = SPEC.read_text(encoding="utf-8")
sec = re.search(r"#### 10\.9\.1 .*?(?=\n#### )", spec, re.S)
if not sec:
raise SystemExit("spec.md §10.9.1 section not found")
spec_rows = dict((m[0], m[1].upper()) for m in re.findall(
r"^\|\s*`(--[a-z0-9-]+)`\s*\|[^|]*\|\s*\*\*`(#[0-9A-Fa-f]{6}|rgba\([^)]*\))`\*\*", sec.group(0), re.M))
print(f"\nspec.md §10.9.1 (dark) tokens parsed: {len(spec_rows)}")
checked = 0
for tok, spec_val in spec_rows.items():
prod_val = dark.get(tok)
if prod_val is None:
fails.append(f"spec lists {tok} but prod dark block has none")
print(f" {tok:26s} spec {spec_val:24s} prod MISSING")
continue
checked += 1
same = prod_val.replace(' ', '').upper() == spec_val.replace(' ', '').upper()
if not same:
fails.append(f"§10.9.1 prod mismatch {tok}: spec {spec_val} prod {prod_val}")
print(f" {tok:26s} spec {spec_val:24s} prod {prod_val:24s} {'match' if same else 'MISMATCH'}")
sec2 = re.search(r"### 10\.26 .*?(?=\n### |\Z)", spec, re.S)
if not sec2:
raise SystemExit("spec.md §10.26 section not found")
rows = re.findall(
r"^\|\s*`(--[a-z0-9-]+)`\s*\|\s*`(#[0-9A-Fa-f]{6}|rgba\([^)]*\))`\s*"
r"\|\s*\*\*`(#[0-9A-Fa-f]{6}|rgba\([^)]*\))`\*\*", sec2.group(0), re.M)
print(f"\nspec.md §10.26 tokens parsed: {len(rows)}")
checked2 = 0
for tok, spec_light, spec_dark in rows:
for theme, prod, spec_val in (("light", light, spec_light), ("dark", dark, spec_dark)):
prod_val = prod.get(tok)
if prod_val is None:
fails.append(f"§10.26 lists {tok} but prod {theme} block has none")
print(f" {tok:22s} {theme:5s} spec {spec_val:22s} prod MISSING")
continue
checked2 += 1
same = prod_val.replace(' ', '').upper() == spec_val.replace(' ', '').upper()
if not same:
fails.append(f"§10.26 prod mismatch {tok} ({theme}): spec {spec_val} prod {prod_val}")
print(f" {tok:22s} {theme:5s} spec {spec_val:22s} prod {prod_val:22s} {'match' if same else 'MISMATCH'}")
print(f"\nchecked {checked} §10.9.1 rows + {checked2} §10.26 rows against prod")
if fails:
print("\nFAILURES:")
for f in fails:
print(" -", f)
sys.exit(1)
print("\nOK: both shipped themes pass AA and spec.md (§10.9.1, §10.26) matches src/index.html")