One type system for the hero, proven in the .pen
- The Pencil frames had the term->value pairs as a single $font-body text node, so labels like КОМАНДА rendered in Roboto while every other label is Montserrat. They are now a frame with Термин ($font-heading 700/11 upper) and Описание ($font-body 400/14), same in V1/V2/390 frames. - The planet art in the five new frames is an image fill again instead of a black rectangle (the generator wrote a solid fill). - Nine hero roles pinned to production computed styles, written into DESIGN.md and checked by scripts/verify-pen.py: 0 violations on the canon. - .pen reserialised, previous state kept in archive/snapshot-2026-11-15-b.pen. src/ is untouched: production already matched the table, the drift was only in the design file.
This commit is contained in:
1 parent
5325b929cc
commit
446ed39da8
7 files changed
+28949
-999
No files matched your search
@@ -0,0 +1,184 @@
|
||||
#!/usr/bin/env python3
|
||||
# verify-pen.py — механическая проверка типографической системы hero в .pen (JSON 2.21).
|
||||
#
|
||||
# Правила (контракт карточки t_10311aff):
|
||||
# R1 ни одна метка/термин/заголовок не набран $font-body → «0 нарушений»
|
||||
# R2 пары «термин → значение» — два узла ($font-heading 700/11 + $font-body 400/14-15)
|
||||
# R3 в hero-кадрах ровно три строки (desktop), статы полосы в один ряд, тикер на кромке
|
||||
# R4 кегли/веса/интерлиньяжи совпадают с таблицей ролей (допуск 0 px)
|
||||
#
|
||||
# Запуск: py verify-pen.py <canon.pen>
|
||||
import json, sys, pathlib
|
||||
|
||||
HEAD, BODY = "$font-heading", "$font-body"
|
||||
|
||||
# роль → (family, weight, size|None, lh, ls) «None» = кегль зависит от кадра (см. EXPECT ниже)
|
||||
EXPECT = {
|
||||
"H1": (HEAD, "800", None, 1.1, 1),
|
||||
"Титул полосы": (HEAD, "700", None, 1.1, None),
|
||||
"Значение": (HEAD, "800", None, 1.0, 0),
|
||||
"Подпись": (HEAD, "600", 10, 1.5, None),
|
||||
"Заголовок плашки": (HEAD, "700", 12, 1.1, 1.2),
|
||||
"Термин": (HEAD, "700", 11, 1.5, 1),
|
||||
"Метка группы": (HEAD, "700", 11, 1.5, 1),
|
||||
"Чип-подпись": (HEAD, "600", 12, 1.5, 1),
|
||||
"Логотип": (HEAD, "800", None, 1.2, 1),
|
||||
"Тикер": (HEAD, "600", 14, 1.5, 1),
|
||||
"Лид полосы": (BODY, "400", 14, None, 0),
|
||||
"Лид плашки": (BODY, "400", None, None, 0),
|
||||
"Описание": (BODY, "400", None, None, 0),
|
||||
"Оффер": (BODY, "400", 19, 1.5, 0),
|
||||
}
|
||||
LABEL_ROLES = {"H1", "Титул полосы", "Значение", "Подпись", "Заголовок плашки", "Термин",
|
||||
"Метка группы", "Чип-подпись", "Логотип", "Тикер"}
|
||||
|
||||
# кегль роли по кадру (замер прода, px): кадр → роль → size
|
||||
SIZE_BY_FRAME = {
|
||||
"1440": {"Титул полосы": 18, "Значение": 23, "H1": 54, "Логотип": 20,
|
||||
"Лид плашки": 14, "Описание": 14},
|
||||
"1366": {"Титул полосы": 17, "Значение": 20, "H1": 54, "Логотип": 20,
|
||||
"Лид плашки": 14, "Описание": 14},
|
||||
"390": {"Титул полосы": 20, "Значение": 20, "H1": 34, "Логотип": 16,
|
||||
"Лид плашки": 15, "Описание": 15},
|
||||
}
|
||||
LH_BY_FRAME = {
|
||||
"1440": {"Лид полосы": 1.38, "Лид плашки": 1.36, "Описание": 1.36},
|
||||
"1366": {"Лид полосы": 1.32, "Лид плашки": 1.32, "Описание": 1.32},
|
||||
"390": {"Лид полосы": 1.55, "Лид плашки": 1.5, "Описание": 1.5},
|
||||
}
|
||||
|
||||
def frame_key(name):
|
||||
if "390" in name: return "390"
|
||||
if "1366" in name: return "1366"
|
||||
return "1440"
|
||||
|
||||
def walk(node, path=""):
|
||||
p = f"{path}/{node.get('name','?')}"
|
||||
yield node, p
|
||||
for c in node.get("children") or []:
|
||||
yield from walk(c, p)
|
||||
|
||||
def main():
|
||||
data = json.loads(pathlib.Path(sys.argv[1]).read_text(encoding="utf-8"))
|
||||
heroes = [c for c in data["children"] if str(c.get("name", "")).startswith("Hero — ")]
|
||||
violations, notes = [], []
|
||||
|
||||
if len(heroes) != 5:
|
||||
violations.append(f"кадров hero {len(heroes)}, ожидалось 5")
|
||||
|
||||
for frame in heroes:
|
||||
fname = frame.get("name")
|
||||
fk = frame_key(fname)
|
||||
sizes = SIZE_BY_FRAME[fk]
|
||||
lhs = LH_BY_FRAME[fk]
|
||||
texts = 0
|
||||
for node, path in walk(frame):
|
||||
if node.get("type") != "text":
|
||||
continue
|
||||
texts += 1
|
||||
nm = node.get("name", "")
|
||||
fam = node.get("fontFamily")
|
||||
content = str(node.get("content", ""))
|
||||
|
||||
# R1a — роль метки набрана прозой
|
||||
if nm in LABEL_ROLES and fam != HEAD:
|
||||
violations.append(f"R1 {fname} :: {path} — роль «{nm}» набрана {fam}")
|
||||
|
||||
# R1b — содержание в верхнем регистре (метка) не может быть Roboto
|
||||
letters = [ch for ch in content if ch.isalpha()]
|
||||
if letters and content == content.upper() and content != content.lower() and fam != HEAD:
|
||||
violations.append(f"R1 {fname} :: {path} — uppercase-метка {content[:28]!r} набрана {fam}")
|
||||
|
||||
# R2 — пара «термин → значение» одним узлом
|
||||
if nm.startswith("Пара ") and len(content) > 16:
|
||||
violations.append(f"R2 {fname} :: {path} — пара собрана одним текстовым узлом")
|
||||
|
||||
# R5 — вес записан числом (OpenPencil 0.16 строковый fontWeight отбрасывает → Regular)
|
||||
if not isinstance(node.get("fontWeight"), int):
|
||||
violations.append(f"R5 {fname} :: {path} — вес %r не число" % (node.get("fontWeight"),))
|
||||
|
||||
# R4 — соответствие таблице ролей
|
||||
if nm in EXPECT:
|
||||
exp_fam, exp_w, exp_size, exp_lh, exp_ls = EXPECT[nm]
|
||||
if fam != exp_fam:
|
||||
violations.append(f"R4 {fname} :: {path} — гарнитура {fam}, ожидалось {exp_fam}")
|
||||
if str(node.get("fontWeight")) != exp_w:
|
||||
violations.append(f"R4 {fname} :: {path} — вес {node.get('fontWeight')}, ожидалось {exp_w}")
|
||||
size = sizes.get(nm, exp_size)
|
||||
if size is not None and node.get("fontSize") != size:
|
||||
violations.append(f"R4 {fname} :: {path} — кегль {node.get('fontSize')}, ожидалось {size}")
|
||||
lh = lhs.get(nm, exp_lh)
|
||||
if lh is not None and abs(float(node.get("lineHeight", 0)) - lh) > 0.001:
|
||||
violations.append(f"R4 {fname} :: {path} — интерлиньяж {node.get('lineHeight')}, ожидалось {lh}")
|
||||
if exp_ls is not None and abs(float(node.get("letterSpacing", 0)) - exp_ls) > 0.001:
|
||||
violations.append(f"R4 {fname} :: {path} — трекинг {node.get('letterSpacing')}, ожидалось {exp_ls}")
|
||||
|
||||
# R3 — статы полосы в один ряд
|
||||
# конец обхода текстов
|
||||
|
||||
# R3 — три строки + тикер на кромке (desktop)
|
||||
hero_frame = next((n for n in frame.get("children") or [] if n.get("name") == "Hero"), None)
|
||||
tick = next((n for n in frame.get("children") or [] if n.get("name") == "Тикер первого экрана"), None)
|
||||
if fk != "390" and "3 полосы" in fname:
|
||||
if not hero_frame:
|
||||
violations.append(f"R3 {fname} — нет узла Hero")
|
||||
else:
|
||||
rows = [n for n in hero_frame.get("children") or []]
|
||||
if len(rows) != 3:
|
||||
violations.append(f"R3 {fname} — строк {len(rows)}, ожидалось 3: "
|
||||
f"{[r.get('name') for r in rows]}")
|
||||
for r in rows:
|
||||
if r.get("width") != 1200:
|
||||
violations.append(f"R3 {fname} — строка «{r.get('name')}» шириной {r.get('width')}, "
|
||||
f"ожидалось 1200")
|
||||
# статы полосы в один ряд
|
||||
bar = next((r for r in rows if r.get("name", "").startswith("Строка 2")), None)
|
||||
st = None
|
||||
if bar:
|
||||
st = next((n for n in bar.get("children") or [] if n.get("name") == "Статы"), None)
|
||||
if st:
|
||||
if st.get("layout") != "horizontal":
|
||||
violations.append(f"R3 {fname} — Статы не в ряд (layout={st.get('layout')})")
|
||||
if len(st.get("children") or []) != 4:
|
||||
violations.append(f"R3 {fname} — статов {len(st.get('children') or [])}, ожидалось 4")
|
||||
cell_h = 0
|
||||
for c in st.get("children") or []:
|
||||
cell_h = max(cell_h, (c.get("height") or 0))
|
||||
if st.get("height") and cell_h > st["height"] + 0.5:
|
||||
violations.append(f"R3 {fname} — статы переносятся: ячейка {cell_h} > ряд {st['height']}")
|
||||
else:
|
||||
violations.append(f"R3 {fname} — в полосе нет узла Статы")
|
||||
# плашки одной высоты
|
||||
cards = next((r for r in rows if r.get("name", "").startswith("Строка 3")), None)
|
||||
if cards:
|
||||
hs = {(c.get("height")) for c in cards.get("children") or []}
|
||||
if len(hs) > 1:
|
||||
violations.append(f"R3 {fname} — плашки разной высоты: {sorted(hs)}")
|
||||
ch_list = [(c.get("name"), c.get("height")) for c in cards.get("children") or []]
|
||||
if cards.get("height") and all(h is not None for _, h in ch_list):
|
||||
for nm_, h_ in ch_list:
|
||||
if h_ > cards["height"] + 0.5:
|
||||
violations.append(f"R3 {fname} — плашка «{nm_}» {h_} > строки {cards['height']}")
|
||||
if tick and fk != "390":
|
||||
kids = frame.get("children") or []
|
||||
total = sum((k.get("height") or 0) for k in kids)
|
||||
if abs(total - frame["height"]) > 0.5:
|
||||
violations.append(f"R3 {fname} — колонка кадра {total} ≠ высоте {frame['height']}: "
|
||||
f"тикер не на кромке")
|
||||
if kids[-1].get("name") != "Тикер первого экрана":
|
||||
violations.append(f"R3 {fname} — тикер не последний в колонке кадра")
|
||||
if not tick:
|
||||
violations.append(f"R3 {fname} — нет тикера")
|
||||
|
||||
# отчёт
|
||||
print("=" * 78)
|
||||
print(f"ФАЙЛ: {sys.argv[1]}")
|
||||
print(f"КАДРОВ HERO: {len(heroes)} — {', '.join(f['name'] for f in heroes)}")
|
||||
print(f"НАРУШЕНИЙ: {len(violations)}")
|
||||
for v in violations[:80]:
|
||||
print(" ✗", v)
|
||||
print("=" * 78)
|
||||
sys.exit(1 if violations else 0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user