202 lines
9.8 KiB
Python
202 lines
9.8 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""同行内容换行探针:一行放不下时该换行的是**整块**,不是里面的字(UI规范 §7 · 用户第 2 条)。
|
|||
|
|
|
|||
|
|
两条判据,同一个道理的两面:
|
|||
|
|
判据① `BTNROWS`(用户第 2 条「同一概念按钮组不要乱跨行」):
|
|||
|
|
每颗 <ActionGroup> 里的子项必须待在同一行;
|
|||
|
|
判据② `HEAD_BREAK`(第 17 轮补):卡头那一行放不下标题 + 右端动作时,
|
|||
|
|
必须是**整块动作**掉到第二行,而不是把标题切成两行。
|
|||
|
|
|
|||
|
|
为什么单独一道闸:「同一概念的几颗按钮不许乱跨行」是用户反复点名的毛病,
|
|||
|
|
而它恰好掉在两张已有闸门的缝里——
|
|||
|
|
· visualcheck 的 wrap 断言只在 >=1024 的档位做,而它实际跑的宽度是
|
|||
|
|
1440/992/768/430,等于**只有 1440 一档**在守这条规矩;
|
|||
|
|
· gridcheck 管的是「同族控件右边缘齐不齐」,按钮族和胶囊流整体豁免。
|
|||
|
|
于是中间档里「两排 2+1」这种破法一直没人报:实测分镜导入的
|
|||
|
|
「文本预览 → 导入预演(含图片匹配)→ 正式导入」1024 折成 2+1、860 折成三行,
|
|||
|
|
时间线 1024 掉一颗「补齐缺失配音」,全是从 1440 直接跳 992 漏掉的宽度。
|
|||
|
|
|
|||
|
|
判据:量渲染结果,不读 class——同一个 .nex-action-group 里可见子项的
|
|||
|
|
垂直中心落在两条以上水平线 = 这组被劈开(比中心不比 top:两行高的按钮
|
|||
|
|
和一颗单行按钮同排时 top 本来就错开)。
|
|||
|
|
豁免(只有一条,在代码里有名有姓):
|
|||
|
|
· `ant-flex-vertical`:竖排等宽是刻意的「这一组」,不是参差
|
|||
|
|
(页面写死的 `stack` 与 ActionGroup 的自动竖排都长这样)。
|
|||
|
|
曾经有第二条「父级是 `<header>` 的页头那组在 <1024 允许分行」,第 17 轮删了:
|
|||
|
|
门牌卡改造把 PageHead 从 `<header>` 换成了 `Panel`,这条豁免于是匹配不上任何东西,
|
|||
|
|
而它描述的那套窄屏方案(`max-lg:[&>button]:flex-1` 按钮等分)本来就是坏的——
|
|||
|
|
`natural()` 见子项 flex-grow>0 直接返回 0,自动竖排永远不触发,三颗主操作照旧
|
|||
|
|
折成 2 + 1(实测 576 档 /review 与 430 档 /library、/review 共 3 处)。页头改用
|
|||
|
|
kit 的自动档(满宽那一行仍放不下整组 → 整组竖排等宽)后,它落进上面那条豁免。
|
|||
|
|
|
|||
|
|
判据② 的量法:卡头里第一段文字(标题本体,副标题折行是合法的)的 Range
|
|||
|
|
拿到两条以上 client rect = 标题被切了;此时标题**没有占满整行**,说明行里还有
|
|||
|
|
一整块可以挪下去,却拿断词换宽度 → 立案。标题占满整行的那一档豁免:
|
|||
|
|
那时候没有任何整块可挪,长句子在自己那一行里折行是排版,不是切字。
|
|||
|
|
症状(修前实测):430 档 /assets「人物母版」切成「人物母 / 版」两行,
|
|||
|
|
430 与 480 档 /projects/:id/dispatch「模型配置已迁移至独立管理中心」断两行。
|
|||
|
|
原因:`.ant-card-head-title` 是 `flex:1 1 0`,折行判定看 flex-basis,
|
|||
|
|
浏览器永远认为 extra 放得下,shrink 的全落在标题上——光给 wrapper 加
|
|||
|
|
flex-wrap 不解决(那条注释在 app.css,写着「掉到第二行」却没人验证)。
|
|||
|
|
修法在 kit:Panel 在 <576(Grid.useBreakpoint 的 sm 以下)给 Card 挂
|
|||
|
|
`nex-head-stack`,CSS 把 extra 收成 `flex:1 1 100%` 自己占一行。
|
|||
|
|
|
|||
|
|
用法:
|
|||
|
|
NEX_WIDTHS=1440,1024,860 NEX_THEMES=light .venv/bin/python scripts/ui/btnrowcheck.py
|
|||
|
|
退出码:0 = 两条判据都干净;1 = 有点名。
|
|||
|
|
"""
|
|||
|
|
import os
|
|||
|
|
import sys
|
|||
|
|
from playwright.sync_api import sync_playwright
|
|||
|
|
|
|||
|
|
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
|
|||
|
|
WIDTHS = [int(x) for x in os.environ.get("NEX_WIDTHS", "1440,1280,1024,860,768,576,430").split(",")]
|
|||
|
|
THEMES = os.environ.get("NEX_THEMES", "light").split(",")
|
|||
|
|
ROUTES = [r for r in os.environ.get(
|
|||
|
|
"NEX_ROUTES",
|
|||
|
|
"/,/assets,/models,/projects/{id}/overview,/projects/{id}/library,"
|
|||
|
|
"/projects/{id}/storyboard,/projects/{id}/dispatch,/projects/{id}/review,"
|
|||
|
|
"/projects/{id}/timeline,/projects/{id}/delivery,"
|
|||
|
|
"/account,/users,/help").split(",") if r]
|
|||
|
|
USER, PWD = os.environ.get("NEX_USER", "admin"), os.environ.get("NEX_PASS", "admin1234")
|
|||
|
|
|
|||
|
|
# 项目子页量「镜头最多」的项目:空项目全是空态,按钮组根本不渲染(同 visualcheck)
|
|||
|
|
PROJECT_JS = r"""async () => {
|
|||
|
|
const t = localStorage.getItem('nex-auth');
|
|||
|
|
const tok = t ? (JSON.parse(t)?.state?.token || JSON.parse(t)?.token) || '' : '';
|
|||
|
|
const h = {headers: {Authorization: 'Bearer ' + tok}};
|
|||
|
|
const j = await (await fetch('/api/projects', h)).json();
|
|||
|
|
const list = j.projects || j.items || j.data || (Array.isArray(j) ? j : []);
|
|||
|
|
let best = list[0]?.id || 1, n = -1;
|
|||
|
|
for (const p of list) {
|
|||
|
|
const s = await (await fetch(`/api/projects/${p.id}/shots`, h)).json();
|
|||
|
|
const c = s.count ?? (s.shots || []).length;
|
|||
|
|
if (c > n) { n = c; best = p.id; }
|
|||
|
|
}
|
|||
|
|
return best;
|
|||
|
|
}"""
|
|||
|
|
|
|||
|
|
# 豁免命中计数:豁免只能挂在一个可数的类名上,且每轮都要报出它跳过了多少组——
|
|||
|
|
# 「死掉的豁免」比没有豁免更坏(第 17 轮那条 <header> 豁免就是这么悄悄放走问题的)。
|
|||
|
|
COUNT = r"""() => {
|
|||
|
|
const groups = document.querySelectorAll('.nex-action-group').length;
|
|||
|
|
const stacked = document.querySelectorAll('.nex-action-group.ant-flex-vertical').length;
|
|||
|
|
return [groups, stacked];
|
|||
|
|
}"""
|
|||
|
|
|
|||
|
|
JS = r"""() => {
|
|||
|
|
const bad = [];
|
|||
|
|
for (const el of document.querySelectorAll('.nex-action-group')) {
|
|||
|
|
const cls = typeof el.className === 'string' ? el.className : '';
|
|||
|
|
if (cls.indexOf('ant-flex-vertical') >= 0) continue; // 竖排等宽:刻意的「这一组」
|
|||
|
|
const kids = [...el.children].filter((k) => {
|
|||
|
|
const r = k.getBoundingClientRect();
|
|||
|
|
return r.width > 1 && r.height > 1;
|
|||
|
|
});
|
|||
|
|
if (kids.length < 2) continue;
|
|||
|
|
const lines = [];
|
|||
|
|
for (const k of kids) {
|
|||
|
|
const r = k.getBoundingClientRect();
|
|||
|
|
const y = r.top + r.height / 2;
|
|||
|
|
if (!lines.some((v) => Math.abs(v - y) < 8)) lines.push(y);
|
|||
|
|
}
|
|||
|
|
if (lines.length < 2) continue;
|
|||
|
|
const box = el.getBoundingClientRect();
|
|||
|
|
const texts = kids.map((k) => (k.innerText || k.getAttribute('aria-label') || k.tagName)
|
|||
|
|
.trim().replace(/\s+/g, ' ').slice(0, 12));
|
|||
|
|
bad.push({
|
|||
|
|
el: cls.trim().split(/\s+/).slice(0, 3).join('.') + ' :: ' + texts.join('|'),
|
|||
|
|
at: Math.round(box.top + window.scrollY),
|
|||
|
|
w: Math.round(box.width),
|
|||
|
|
lines: lines.length,
|
|||
|
|
tops: kids.map((k) => Math.round(k.getBoundingClientRect().top)),
|
|||
|
|
texts,
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
return bad;
|
|||
|
|
}"""
|
|||
|
|
|
|||
|
|
# 判据②:卡头标题不许被切成两行(详见文件头)
|
|||
|
|
HEAD = r"""() => {
|
|||
|
|
const bad = [];
|
|||
|
|
for (const w of document.querySelectorAll('.ant-card-head-wrapper')) {
|
|||
|
|
const t = w.querySelector('.ant-card-head-title');
|
|||
|
|
const e = w.querySelector('.ant-card-extra');
|
|||
|
|
if (!t || !e) continue;
|
|||
|
|
let tn = null; // 标题本体 = 第一段文字
|
|||
|
|
const walk = (n) => {
|
|||
|
|
if (tn) return;
|
|||
|
|
for (const c of n.childNodes) {
|
|||
|
|
if (c.nodeType === 3 && c.textContent.trim()) { tn = c; return; }
|
|||
|
|
if (c.nodeType === 1) walk(c);
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
walk(t);
|
|||
|
|
if (!tn) continue;
|
|||
|
|
const rg = document.createRange();
|
|||
|
|
rg.selectNodeContents(tn);
|
|||
|
|
const lines = [...rg.getClientRects()].filter((r) => r.width > 1).length;
|
|||
|
|
if (lines < 2) continue;
|
|||
|
|
const wb = w.getBoundingClientRect();
|
|||
|
|
const tb = t.getBoundingClientRect();
|
|||
|
|
const eb = e.getBoundingClientRect();
|
|||
|
|
// 标题已经占满整行 = 没有「一整块」可以再挪下去了,长句子在自己行里折行是排版
|
|||
|
|
if (wb.width - tb.width <= 8) continue;
|
|||
|
|
bad.push({
|
|||
|
|
el: 'head::' + tn.textContent.trim().replace(/\s+/g, ' ').slice(0, 24),
|
|||
|
|
at: Math.round(tb.top + window.scrollY),
|
|||
|
|
w: Math.round(tb.width), ew: Math.round(eb.width), lines,
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
return bad;
|
|||
|
|
}"""
|
|||
|
|
|
|||
|
|
|
|||
|
|
def main() -> int:
|
|||
|
|
violations = 0
|
|||
|
|
breaks = 0
|
|||
|
|
groups = 0
|
|||
|
|
stacked = 0
|
|||
|
|
with sync_playwright() as pw:
|
|||
|
|
b = pw.chromium.launch()
|
|||
|
|
pg = b.new_context(viewport={"width": 1440, "height": 1000}).new_page()
|
|||
|
|
pg.set_default_timeout(20000)
|
|||
|
|
pg.goto(f"{BASE}/login")
|
|||
|
|
pg.wait_for_selector("#login-user")
|
|||
|
|
pg.fill("#login-user", USER)
|
|||
|
|
pg.fill("#login-pass", PWD)
|
|||
|
|
pg.click("button[type=submit]")
|
|||
|
|
pg.wait_for_url(lambda u: "/login" not in u, timeout=15000)
|
|||
|
|
pid = os.environ.get("NEX_PROJECT_ID") or pg.evaluate(PROJECT_JS)
|
|||
|
|
for theme in THEMES:
|
|||
|
|
pg.evaluate("t => localStorage.setItem('nex-the', t)", theme)
|
|||
|
|
for w in WIDTHS:
|
|||
|
|
pg.set_viewport_size({"width": w, "height": 1000})
|
|||
|
|
for route in ROUTES:
|
|||
|
|
path = route.replace("{id}", str(pid))
|
|||
|
|
pg.goto(BASE + path)
|
|||
|
|
pg.wait_for_timeout(1200)
|
|||
|
|
g, st = pg.evaluate(COUNT)
|
|||
|
|
groups += g
|
|||
|
|
stacked += st
|
|||
|
|
for item in pg.evaluate(JS):
|
|||
|
|
violations += 1
|
|||
|
|
print(f"VIOLATION {theme} {w}px {path} y={item['at']} "
|
|||
|
|
f"w={item['w']} lines={item['lines']} tops={item['tops']} "
|
|||
|
|
f":: {' / '.join(item['texts'])}")
|
|||
|
|
for item in pg.evaluate(HEAD):
|
|||
|
|
breaks += 1
|
|||
|
|
print(f"HEAD_BREAK {theme} {w}px {path} y={item['at']} "
|
|||
|
|
f"titlew={item['w']} extraw={item['ew']} "
|
|||
|
|
f"lines={item['lines']} :: {item['el']}")
|
|||
|
|
print(f"BTNROWS_GROUPS {groups} EXEMPT_STACK {stacked}")
|
|||
|
|
print(f"BTNROWS_TOTAL {violations}")
|
|||
|
|
print(f"HEAD_BREAK_TOTAL {breaks}")
|
|||
|
|
b.close()
|
|||
|
|
return 1 if (violations or breaks) else 0
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
sys.exit(main())
|