fix(footer): 联系我们图标与首行文字同中线
旧写法用固定 mt-0.5 给图标手拍偏移,而本项目 --line-height-relaxed 是 1.85(非 Tailwind 默认 1.625),根字号又有 16/17/18 三档 ⇒ 图标中心比文字行盒中心高 3.319/3.134/2.950px (地址行)与 3.313/3.133/2.945px(邮箱行)。 改为结构对齐:地址行图标包进高 = 行盒高(--line-height-relaxed × --font-size-sm)的 items-center 单元格,换行后仍对齐首行;邮箱行是单行链接,整行 items-center。 行高/字号/页高零变化,只移动两个图标。
This commit is contained in:
1 parent
03be1c9e36
commit
a63cf38c62
10 files changed
+690
-3
No files matched your search
@@ -0,0 +1,150 @@
|
||||
# 页脚「联系我们」图标与首行文字中线对齐(2026-10-26)
|
||||
|
||||
## 结论
|
||||
|
||||
- **几何**:修复前三档视口下图标中心比文字行盒中心高 **3.319 / 3.134 / 2.950px**(地址行,根字号
|
||||
18/17/16),邮箱行 **3.313 / 3.133 / 2.945px**;修复后两行三档实测 **|Δ| ≤ 0.0125px**。
|
||||
- **不改文字度量**:行高、字号、页高、所有文字像素位置零变化 —— 只移动了两个图标。
|
||||
- **视觉基线**:重采 **90 张**(75 全页 + 5 页脚 + 10 首页主题),逐张机器核验「宽高严格相等 +
|
||||
差异团块只落在两个图标盒内(14.7–17 × 58–66 CSS px)」;只读复跑全绿:
|
||||
**PR 口径(HEAD 的 15 路由清单)125 passed / 0 failed**,工作树口径 225 passed / 0 failed。
|
||||
三轮读数见 `visual-runs.txt`。
|
||||
- **守卫**:新增 `e2e/footer-contact-align.spec.ts`,按盒子几何判三档视口,四引擎通过。
|
||||
|
||||
## 根因
|
||||
|
||||
`src/components/layout/footer.tsx` 旧写法用 `flex items-start` + 图标固定 `mt-0.5`(0.125rem)
|
||||
去"对首行"。但本项目:
|
||||
|
||||
| 事实 | 位置 | 值 |
|
||||
|------|------|-----|
|
||||
| `leading-relaxed` 被重映射 | `tailwind.config.js:156-162` → `globals.css:236` | `--line-height-relaxed: 1.85`(不是 Tailwind 默认 1.625) |
|
||||
| `text-sm` | `globals.css:219` | `0.875rem` |
|
||||
| 根字号三档 | `globals.css:542-558` | 16 → 17 (≥640) → 18 (≥1024) |
|
||||
| 页脚链接 `min-h-6` | `footer.tsx:45` | `1.5rem` |
|
||||
| `ul` 行高继承 | `globals.css:637-639` | 邮箱链接也拿到 1.85 |
|
||||
|
||||
⇒ 行盒高 = 1.85 × 0.875rem = **25.9 / 27.52 / 29.14px**,而图标中心固定落在 `0.125rem + 半图标`
|
||||
⇒ 每档都偏 3px 上下,且随视口变化。线上 HTML/CSS 与 `HEAD` 一致,不是旧构建。
|
||||
|
||||
## 修复前后读数
|
||||
|
||||
`e2e/footer-contact-align.spec.ts`(红 → 绿),桌面 chromium:
|
||||
|
||||
```
|
||||
修复前 desktop-1440 root18 address -3.319 email -3.313
|
||||
tablet-834 root17 address -3.134 email -3.133
|
||||
mobile-390 root16 address -2.950 email -2.945 → 3 failed
|
||||
修复后 desktop-1440 -0.0063 / 0.0000
|
||||
tablet-834 -0.0094 / -0.0078
|
||||
mobile-390 -0.0125 / -0.0078 → 12 passed(4 引擎 × 3 档)
|
||||
```
|
||||
|
||||
完整读数与裁图:`measure-after.json`、`contact-desktop-1440.png`、`contact-tablet-834.png`、
|
||||
`contact-mobile-390.png`(`node measure-align.mjs <baseURL>` 重新生成)。
|
||||
|
||||
## 改动
|
||||
|
||||
1. `src/components/layout/footer.tsx`:地址行的图标包进高 = 行盒高
|
||||
(`h-[calc(var(--line-height-relaxed)*var(--font-size-sm))]` = 1.61875rem)的 `items-center`
|
||||
单元格;邮箱行是单行链接,整行 `items-center`。换行地址仍对齐首行;高度全部由令牌推导,
|
||||
随根字号等比。生成后的 CSS 实测:
|
||||
`.h-\[calc\(var\(--line-height-relaxed\)\*var\(--font-size-sm\)\)\]{height:calc(var(--line-height-relaxed) * var(--font-size-sm))}`。
|
||||
2. `e2e/footer-contact-align.spec.ts`:三档视口 × 2 行几何守卫,带分母(行数=2)、非空、行高、
|
||||
根字号分档断言,避免空集假绿。
|
||||
3. 视觉基线重采 90 张(见下)。
|
||||
|
||||
## 视觉基线核验
|
||||
|
||||
`verify-baseline-diff.py`(`/usr/bin/python3`,Pillow 只在该解释器下可用)逐张对比 `HEAD` blob
|
||||
与工作树文件:
|
||||
|
||||
- 阈值:单通道 **> 60**(首页 hero 粒子场跨 run 有低幅漂移,thr>10 近万 px、thr>30 数百 px,
|
||||
但 pixelmatch 判绿;而字形/布局位移的边缘差远超 60)。
|
||||
- 只统计 **≥4px 的 8 连通团块**:粒子噪点会留 1–2 个孤立像素,不过滤会把包围盒撑到整页
|
||||
(webkit 首页实测:团块全在页脚,孤立 2px 在 hero 区)。
|
||||
- 判据:宽高严格相等;团块包围盒宽 ≤ 26、高 ≤ 74 CSS px;孤立像素 ≤ 20px。
|
||||
- 自证:负对照 A(整幅下移 10 CSS px)判红、负对照 B(非图标区小块横移 2px)判红、
|
||||
正对照(真实新图)通过 → `SELFTEST PASS`。
|
||||
|
||||
结果:
|
||||
|
||||
```
|
||||
核验 90 张有 HEAD 参照的基线(阈值:单通道 > 60;包围盒 ≤ 26.0×74.0 CSS px)
|
||||
可参照基线全部通过:90/90 张只差在联系区两个图标盒内,且尺寸零变化
|
||||
bbox 分布:16×66 ×20 / 17×65 ×18 / 16×65 ×16 / 16×62.5 ×11 / 14.7×58 ×11 / 16×62 ×7 / 14.7×58.3 ×7
|
||||
```
|
||||
|
||||
5 张 `footer-section-*.png` 已逐张读图(桌面 / 平板 / 手机 / firefox / webkit):两行图标与首行文字
|
||||
居中、文字笔画零位移、备案行未动。另抽读新基线 `/cases` 全页图,确认不是错误浮层/空壳。
|
||||
|
||||
## 仪器坑(本轮新增,已写入下方 lessons 草稿)
|
||||
|
||||
1. `Range.getClientRects()` **不是行盒**:高度是字体 ascent+descent,top 还整数量化,与行盒中心
|
||||
有 0.45px 级字体相关偏置。判据应取盒子 + `computed lineHeight`。
|
||||
2. **webkit desktop 的 DPR 是 2**(`devices['Desktop Safari']`,基线宽 2548 = 1274×2)。初版按 1 算,
|
||||
把 16×65 的图标包围盒读成 34×130,误判成"文字被动过"。
|
||||
3. **孤立噪点会把包围盒撑满整页**:必须先做连通团块过滤,再谈包围盒。
|
||||
4. `maxDiffPixels: 200` 对 3px 图标位移是"刚好越线":同一批 175 张全页图里,桌面 chromium 有
|
||||
21 张判绿 14 张判红。指望像素门限替几何判据兜底不成立。
|
||||
|
||||
## 复跑
|
||||
|
||||
端口 3000 被本机 `auth-center` 容器占用;Playwright 的 `isURLAvailable` 对 401 也返回 true
|
||||
(`>=200 && <404`),会静默复用那个服务。绕开方式:
|
||||
|
||||
```bash
|
||||
npx next dev -p 3001 # 或 E2E_TARGET=production 时自己起产物
|
||||
E2E_BASE_URL=http://localhost:3001 npm run test:visual:all -- --update-snapshots=none
|
||||
cd e2e && E2E_BASE_URL=http://localhost:3001 npx playwright test footer-contact-align.spec.ts \
|
||||
--project=chromium --project=chromium-mobile --project=firefox --project=webkit
|
||||
/usr/bin/python3 docs/acceptance/2026-10-26-footer-icon-align/verify-baseline-diff.py --allow-untracked
|
||||
```
|
||||
|
||||
## 范围说明(工作树里不属于本批的东西)
|
||||
|
||||
- 工作树里另有 **100 张未入库基线**,它们是 `e2e/visual-regression.spec.ts` 里 **20 个新路由**
|
||||
(同样未提交)的配套。`HEAD` 的视觉清单只有 15 条路由 = 75 张已入库全页图,一一对应
|
||||
⇒ 这些孤儿基线不在本批入库,随那批路由扩容一起提交。
|
||||
- `docs/lessons-learned.md` 当前工作树里已有未提交的 §5.52(Gitea 品牌批),因此 §5.53 本轮
|
||||
不写进该文件,草稿见下,随那批一起入库。
|
||||
|
||||
## 待入库:lessons §5.53 草稿
|
||||
|
||||
```markdown
|
||||
### 5.53 行内图标对齐是行盒问题;`Range` 矩形不是行盒(2026-10-26)
|
||||
|
||||
**现象**:页脚「联系我们」的定位/邮件图标比右侧文字高约 3px,业务侧一眼看出(截图 784×328,
|
||||
等效缩放 ≈2.34;地址行墨迹中心差 6.5px ÷ 2.34 ≈ 2.8 CSS px,与计算值一致)。
|
||||
|
||||
**机理**:`footer.tsx` 用 `flex items-start` + 图标固定 `mt-0.5`(0.125rem)去"对首行"。
|
||||
但本项目把 `leading-relaxed` 重映射成 `--line-height-relaxed: 1.85`(`globals.css:236`,
|
||||
不是 Tailwind 默认 1.625),`text-sm` = 0.875rem,根字号又有 16/17/18 三档(`globals.css:542-558`)。
|
||||
行盒高 = 25.9 / 27.52 / 29.14px,图标中心固定落在 0.125rem + 半图标 ⇒ 三档分别偏高
|
||||
**3.319 / 3.134 / 2.950px**(地址行;邮箱行 3.313 / 3.133 / 2.945,其行高从 `ul` 规则继承 1.85)。
|
||||
固定 px 手拍在"行高是令牌、根字号是变量"的站点上,每一档都会偏,且偏得不一样。
|
||||
|
||||
**修法**:让偏移成为结构而不是数字。可换行的地址行:图标包进一个高 = 行盒高
|
||||
(`h-[calc(var(--line-height-relaxed)*var(--font-size-sm))]`)的 `items-center` 单元格,换行后仍
|
||||
对齐首行;邮箱是单行链接,整行 `items-center` 就够。修后三档 |Δ| ≤ 0.0125px。关键是**不动行高/
|
||||
字号**:页高与全部文字像素零位移,全页截图尺寸不变(否则 90 张基线全部尺寸失配)。
|
||||
在 CSS 里 `height:calc(number * length)` 这种含嵌套 var 的任意值 Tailwind 3.4 能正常生成;
|
||||
生成失败时守卫会以 Δ≈3px 判红,不会静默通过。
|
||||
|
||||
**判据**:`Range.getClientRects()` **不是行盒** —— 它返回字体 ascent+descent(14px 字给约 17px),
|
||||
top 还有整数量化,与行盒中心有 0.45px 级字体相关偏置;拿它当参照,0.5px 容差只剩 0.05px 余量,
|
||||
换字体就时红时绿。正确参照是盒子:普通块 = `rect.top + computed lineHeight/2`,
|
||||
`inline-flex + items-center` 的链接 = 盒中心。判据还要有可失败的分母(行数=2、文本非空、
|
||||
根字号分档),否则 `every`/空集会给出假绿。
|
||||
|
||||
**成本**:3px 图标位移在 `maxDiffPixels: 200` 下是"刚好越线"——同一批 175 张全页图里桌面 chromium
|
||||
21 绿 14 红(模拟单图 diff ≈213px),移动端 DPR3 则必然判红。一次正确的对齐修正因此要重采全部
|
||||
含页脚的基线(本批 90 张)。⇒ 碰全局组件(页脚/页头)的小视觉修正,先按"所有全页基线都要重采"
|
||||
估成本与授权,再动手;重采后按「尺寸不变 + 差异团块只落在目标元素内」逐张机器核验,并给仪器
|
||||
配正/负对照(整幅位移、非目标区改动都必须判红)。
|
||||
|
||||
**附带三条仪器坑**:① webkit desktop 的 DPR 是 2(`devices['Desktop Safari']`,基线宽 2548=1274×2),
|
||||
按 1 算会把 16×65 读成 34×130;② 孤立 1–2px 噪点会把 diff 包围盒撑到整页 ⇒ 先做 ≥4px 连通团块
|
||||
过滤再取 bbox;③ 首页 hero 粒子场跨 run 有低幅漂移(thr>10 近万 px、thr>30 数百 px 却判绿)⇒
|
||||
阈值取单通道 > 60,靠"字形边缘满对比差"保证对文字/布局位移敏感。
|
||||
```
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
@@ -0,0 +1,92 @@
|
||||
[
|
||||
{
|
||||
"viewport": {
|
||||
"name": "desktop-1440",
|
||||
"width": 1440,
|
||||
"height": 900
|
||||
},
|
||||
"rootFontSize": 18,
|
||||
"rows": [
|
||||
{
|
||||
"tag": "SPAN",
|
||||
"text": "中国四川省成都市龙泉驿区幸福路12号",
|
||||
"iconHeight": 18,
|
||||
"iconTop": 6879.922,
|
||||
"lineHeight": 29.1375,
|
||||
"cellHeight": 29.125,
|
||||
"lineCenter": 6888.928,
|
||||
"delta": -0.0063
|
||||
},
|
||||
{
|
||||
"tag": "A",
|
||||
"text": "contact@novalon.cn",
|
||||
"iconHeight": 18,
|
||||
"iconTop": 6927.047,
|
||||
"lineHeight": 29.1375,
|
||||
"cellHeight": 29.125,
|
||||
"lineCenter": 6936.047,
|
||||
"delta": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"viewport": {
|
||||
"name": "tablet-834",
|
||||
"width": 834,
|
||||
"height": 1194
|
||||
},
|
||||
"rootFontSize": 17,
|
||||
"rows": [
|
||||
{
|
||||
"tag": "SPAN",
|
||||
"text": "中国四川省成都市龙泉驿区幸福路12号",
|
||||
"iconHeight": 17,
|
||||
"iconTop": 7784.672,
|
||||
"lineHeight": 27.5187,
|
||||
"cellHeight": 27.5156,
|
||||
"lineCenter": 7793.181,
|
||||
"delta": -0.0094
|
||||
},
|
||||
{
|
||||
"tag": "A",
|
||||
"text": "contact@novalon.cn",
|
||||
"iconHeight": 17,
|
||||
"iconTop": 7829.188,
|
||||
"lineHeight": 27.5187,
|
||||
"cellHeight": 27.5156,
|
||||
"lineCenter": 7837.695,
|
||||
"delta": -0.0078
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"viewport": {
|
||||
"name": "mobile-390",
|
||||
"width": 390,
|
||||
"height": 844
|
||||
},
|
||||
"rootFontSize": 16,
|
||||
"rows": [
|
||||
{
|
||||
"tag": "SPAN",
|
||||
"text": "中国四川省成都市龙泉驿区幸福路12号",
|
||||
"iconHeight": 16,
|
||||
"iconTop": 7977.125,
|
||||
"lineHeight": 25.9,
|
||||
"cellHeight": 25.8906,
|
||||
"lineCenter": 7985.137,
|
||||
"delta": -0.0125
|
||||
},
|
||||
{
|
||||
"tag": "A",
|
||||
"text": "contact@novalon.cn",
|
||||
"iconHeight": 16,
|
||||
"iconTop": 8019.016,
|
||||
"lineHeight": 25.9,
|
||||
"cellHeight": 25.8906,
|
||||
"lineCenter": 8027.023,
|
||||
"delta": -0.0078
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 页脚「联系我们」图标-文字中线取证(2026-10-26)。
|
||||
* 用法:node docs/acceptance/2026-10-26-footer-icon-align/measure-align.mjs [baseURL]
|
||||
* 判据与 e2e/footer-contact-align.spec.ts 同源:盒子中心,不用 Range rect。
|
||||
* 同时把联系卡片裁图存到同目录,便于和用户原图对照。
|
||||
*/
|
||||
import { chromium } from 'playwright';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
const base = process.argv[2] || process.env.E2E_BASE_URL || 'http://localhost:3001';
|
||||
|
||||
const VIEWPORTS = [
|
||||
{ name: 'desktop-1440', width: 1440, height: 900 },
|
||||
{ name: 'tablet-834', width: 834, height: 1194 },
|
||||
{ name: 'mobile-390', width: 390, height: 844 },
|
||||
];
|
||||
|
||||
const browser = await chromium.launch();
|
||||
const results = [];
|
||||
for (const vp of VIEWPORTS) {
|
||||
const page = await browser.newPage({ viewport: { width: vp.width, height: vp.height } });
|
||||
await page.goto(base + '/', { waitUntil: 'domcontentloaded' });
|
||||
await page.evaluate(() => document.fonts.ready.then(() => undefined));
|
||||
const data = await page.evaluate(() => {
|
||||
const rows = Array.from(document.querySelectorAll('[data-testid="card-contact"] li'));
|
||||
return {
|
||||
rootFontSize: parseFloat(getComputedStyle(document.documentElement).fontSize),
|
||||
rows: rows.map((li) => {
|
||||
const svg = li.querySelector('svg');
|
||||
const text = li.querySelector('span:last-child, a');
|
||||
const cell = svg?.parentElement;
|
||||
const icon = svg.getBoundingClientRect();
|
||||
const box = text.getBoundingClientRect();
|
||||
const cs = getComputedStyle(text);
|
||||
const lineHeight = parseFloat(cs.lineHeight);
|
||||
const lineCenter = text.tagName === 'A' ? box.top + box.height / 2 : box.top + lineHeight / 2;
|
||||
return {
|
||||
tag: text.tagName,
|
||||
text: (text.textContent || '').trim(),
|
||||
iconHeight: icon.height,
|
||||
iconTop: +icon.top.toFixed(3),
|
||||
lineHeight,
|
||||
cellHeight: cell ? +cell.getBoundingClientRect().height.toFixed(4) : null,
|
||||
lineCenter: +lineCenter.toFixed(3),
|
||||
delta: +(icon.top + icon.height / 2 - lineCenter).toFixed(4),
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
results.push({ viewport: vp, ...data });
|
||||
await page.locator('[data-testid="card-contact"]').screenshot({
|
||||
path: path.join(here, `contact-${vp.name}.png`),
|
||||
});
|
||||
await page.close();
|
||||
}
|
||||
await browser.close();
|
||||
console.log(JSON.stringify(results, null, 2));
|
||||
@@ -0,0 +1,251 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
页脚图标对齐修复(2026-10-26)的视觉基线核验:证明每张被重采的 PNG 只有联系区两个图标在变。
|
||||
|
||||
判据(逐张,对比 HEAD blob 与工作树文件):
|
||||
1. 宽高严格相等 —— 若页高/文字度量变了,全页图尺寸就会变;
|
||||
2. 差异像素数 > 0 —— 该图确实被这条改动影响;
|
||||
3. 差异包围盒(CSS px)= bbox / DPR,宽 ≤ 26、高 ≤ 74 ——
|
||||
两个图标 18px 高、行距 47.14px、图标下移 3.32px ⇒ 真实包围盒约 18×68.5 CSS px;
|
||||
文字一旦位移,宽度会立刻涨到上百 px;页脚整体位移,高度会越界。
|
||||
|
||||
差异阈值取「单通道 > 60」(可用 DIFF_THRESHOLD 覆盖):首页 hero 粒子场跨 run 有低幅漂移
|
||||
(实测 thr>10 有近万 px、thr>30 数百 px,但 Playwright/pixelmatch 判绿),用 4 会把这类噪声
|
||||
当成越界;而任何字形/布局位移在边缘处都是满对比差(远超 60),不会漏。
|
||||
另外只看「≥4px 的连通团块」:粒子噪点会留下 1–2 个孤立像素,不按团块过滤就会把包围盒撑到整页
|
||||
(webkit 首页实测:团块全部落在页脚,孤立像素 2 个、坐标在 hero 区)。
|
||||
|
||||
HEAD 里没有的基线(10-24 扩容后未入库的 20 路由 × 5 project = 100 张)无法做前后比对:
|
||||
默认按「未授权的新增基线」判红(退出码 3),加 --allow-untracked 才降级为告警。
|
||||
|
||||
DPR 按 project 目录取(Playwright 设备表):desktop/firefox/webkit = 1,tablet = 2,mobile = 3。
|
||||
|
||||
退出码分档(lessons §5.40 口径):
|
||||
0 = 全部通过;1 = 核验判红(含负对照未按预期失败);3 = 存在未入库基线且未授权;2 = 脚本/环境崩溃。
|
||||
|
||||
用法:
|
||||
/usr/bin/python3 docs/acceptance/2026-10-26-footer-icon-align/verify-baseline-diff.py [--allow-untracked]
|
||||
/usr/bin/python3 .../verify-baseline-diff.py --selftest # 先跑正/负对照自证
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
try:
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print(f"SETUP-ERROR: 需要 /usr/bin/python3 的 Pillow/numpy({exc})", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
REPO = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
|
||||
SNAPSHOT_DIR = "e2e/visual-snapshots"
|
||||
DPR_BY_PROJECT = {
|
||||
"visual-chromium-desktop": 1,
|
||||
"visual-chromium-tablet": 2,
|
||||
"visual-chromium-mobile": 3,
|
||||
"visual-firefox-desktop": 1,
|
||||
# Playwright 的 devices['Desktop Safari'] 带 deviceScaleFactor: 2 —— 实测基线宽 2548 = 1274×2。
|
||||
# 按 1 算会把 16×65 的图标包围盒读成 34×130,误判成"文字被动过"。
|
||||
"visual-webkit-desktop": 2,
|
||||
}
|
||||
PIXEL_THRESHOLD = int(os.environ.get("DIFF_THRESHOLD", "60"))
|
||||
MAX_BBOX_WIDTH_CSS = 26.0
|
||||
MAX_BBOX_HEIGHT_CSS = 74.0
|
||||
MIN_COMPONENT_PIXELS = 4 # 小于 4px 的团块视为跨 run 的孤立噪点(见 check_pair 注释)
|
||||
MAX_NOISE_PIXELS = 20
|
||||
|
||||
|
||||
def run(cmd: list[str]) -> bytes:
|
||||
out = subprocess.run(cmd, cwd=REPO, capture_output=True)
|
||||
if out.returncode != 0:
|
||||
raise RuntimeError(f"{' '.join(cmd)} 失败: {out.stderr.decode('utf-8', 'replace')[:400]}")
|
||||
return out.stdout
|
||||
|
||||
|
||||
def changed_pngs() -> list[str]:
|
||||
raw = run(["git", "status", "--porcelain", "-z", "--", SNAPSHOT_DIR])
|
||||
paths = []
|
||||
for entry in raw.split(b"\0"):
|
||||
if not entry:
|
||||
continue
|
||||
text = entry.decode("utf-8")
|
||||
path = text[3:]
|
||||
if path.endswith(".png"):
|
||||
paths.append(path)
|
||||
return sorted(paths)
|
||||
|
||||
|
||||
def load_head(path: str) -> Image.Image | None:
|
||||
"""HEAD 里没有这张基线时返回 None(10-24 扩容后未入库的那批)。"""
|
||||
probe = subprocess.run(["git", "cat-file", "-e", f"HEAD:{path}"], cwd=REPO, capture_output=True)
|
||||
if probe.returncode != 0:
|
||||
return None
|
||||
return Image.open(io.BytesIO(run(["git", "show", f"HEAD:{path}"]))).convert("RGB")
|
||||
|
||||
|
||||
def diff_mask(old: Image.Image, new: Image.Image):
|
||||
a = np.asarray(old, dtype=np.int16)
|
||||
b = np.asarray(new, dtype=np.int16)
|
||||
return (np.abs(a - b) > PIXEL_THRESHOLD).any(axis=2)
|
||||
|
||||
|
||||
def components(mask):
|
||||
"""8 连通的差异团块(mask 覆盖率很低,逐点 flood fill 足够快)。"""
|
||||
seen = np.zeros(mask.shape, dtype=bool)
|
||||
comps = []
|
||||
ys, xs = np.where(mask)
|
||||
for y0, x0 in zip(ys.tolist(), xs.tolist()):
|
||||
if seen[y0, x0]:
|
||||
continue
|
||||
stack = [(y0, x0)]
|
||||
seen[y0, x0] = True
|
||||
pts = []
|
||||
while stack:
|
||||
y, x = stack.pop()
|
||||
pts.append((y, x))
|
||||
for dy in (-1, 0, 1):
|
||||
for dx in (-1, 0, 1):
|
||||
ny, nx = y + dy, x + dx
|
||||
if 0 <= ny < mask.shape[0] and 0 <= nx < mask.shape[1] and mask[ny, nx] and not seen[ny, nx]:
|
||||
seen[ny, nx] = True
|
||||
stack.append((ny, nx))
|
||||
comps.append(pts)
|
||||
return comps
|
||||
|
||||
|
||||
def check_pair(path: str, old: Image.Image, new: Image.Image) -> list[str]:
|
||||
"""返回问题列表;空列表=通过。
|
||||
|
||||
只看「团块 ≥ MIN_COMPONENT_PIXELS」的差异:首页 hero 粒子场跨 run 会留 1–2 个孤立像素,
|
||||
它们会把 bbox 撑到整页,但并不是布局/文字位移。孤立像素单独计数并打印,超过
|
||||
MAX_NOISE_PIXELS 同样判红(噪声变多也可能是渲染真的变了)。
|
||||
"""
|
||||
problems: list[str] = []
|
||||
if old.size != new.size:
|
||||
problems.append(f"尺寸变了:HEAD {old.size} → 现在 {new.size}(页高/文字度量被改动)")
|
||||
return problems
|
||||
|
||||
dpr = DPR_BY_PROJECT.get(path.split(os.sep)[2], 1)
|
||||
mask = diff_mask(old, new)
|
||||
if not mask.any():
|
||||
problems.append("没有任何差异像素:这张图没被改动影响,不该出现在重采清单里")
|
||||
return problems
|
||||
|
||||
comps = components(mask)
|
||||
significant = [c for c in comps if len(c) >= MIN_COMPONENT_PIXELS]
|
||||
noise_pixels = sum(len(c) for c in comps if len(c) < MIN_COMPONENT_PIXELS)
|
||||
if noise_pixels > MAX_NOISE_PIXELS:
|
||||
problems.append(f"孤立差异像素 {noise_pixels} > {MAX_NOISE_PIXELS}(噪声多到无法归因)")
|
||||
if not significant:
|
||||
problems.append(f"只有 {noise_pixels} 个孤立差异像素,没有形成团块")
|
||||
return problems
|
||||
|
||||
ys = [p[0] for c in significant for p in c]
|
||||
xs = [p[1] for c in significant for p in c]
|
||||
x0, y0, x1, y1 = min(xs), min(ys), max(xs), max(ys)
|
||||
w_css = (x1 - x0 + 1) / dpr
|
||||
h_css = (y1 - y0 + 1) / dpr
|
||||
if w_css > MAX_BBOX_WIDTH_CSS:
|
||||
problems.append(f"差异宽 {w_css:.1f} CSS px > {MAX_BBOX_WIDTH_CSS}(图标右侧/文字被动过)")
|
||||
if h_css > MAX_BBOX_HEIGHT_CSS:
|
||||
problems.append(f"差异高 {h_css:.1f} CSS px > {MAX_BBOX_HEIGHT_CSS}(页脚/整段被判位移)")
|
||||
print(
|
||||
f" {path.split(os.sep)[-1]:<62} dpr={dpr} diff={mask.sum():>6}px 团块={len(significant)} "
|
||||
f"孤立={noise_pixels:>2}px bbox={w_css:.1f}x{h_css:.1f} CSS px @({x0/dpr:.0f},{y0/dpr:.0f})"
|
||||
)
|
||||
return problems
|
||||
|
||||
|
||||
def shift_content(img: Image.Image, dy_css: float, dpr: int) -> Image.Image:
|
||||
"""整张内容下移 dy_css(模拟页脚整体位移),画布尺寸不变。"""
|
||||
dx = int(round(dy_css * dpr))
|
||||
canvas = Image.new("RGB", img.size, img.getpixel((0, 0)))
|
||||
canvas.paste(img, (0, dx))
|
||||
return canvas
|
||||
|
||||
|
||||
def nudge_patch(img: Image.Image, dpr: int) -> Image.Image:
|
||||
"""把一处非图标区的小块横向挪 2 CSS px(模拟文字被动过)。"""
|
||||
w, h = img.size
|
||||
pw, ph = int(200 * dpr), int(24 * dpr)
|
||||
x, y = int(w * 0.15), int(h * 0.5)
|
||||
patch = img.crop((x, y, x + pw, y + ph))
|
||||
out = img.copy()
|
||||
out.paste(patch, (x + int(2 * dpr), y))
|
||||
return out
|
||||
|
||||
|
||||
def main() -> int:
|
||||
paths = changed_pngs()
|
||||
if not paths:
|
||||
print("SETUP-ERROR: 工作树里没有改动的 PNG —— 先生成改动再核验", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
tracked = []
|
||||
untracked = []
|
||||
pairs = []
|
||||
for path in paths:
|
||||
old = load_head(path)
|
||||
new = Image.open(os.path.join(REPO, path)).convert("RGB")
|
||||
if old is None:
|
||||
untracked.append(path)
|
||||
else:
|
||||
tracked.append(path)
|
||||
pairs.append((path, old, new))
|
||||
|
||||
if "--selftest" in sys.argv:
|
||||
if not pairs:
|
||||
print("SETUP-ERROR: 没有可做前后比对的基线,负对照无法运行", file=sys.stderr)
|
||||
return 2
|
||||
path, old, new = pairs[0]
|
||||
dpr = DPR_BY_PROJECT.get(path.split(os.sep)[2], 1)
|
||||
print(f"负对照 A(内容下移 10 CSS px,应判红):{path}")
|
||||
a_problems = check_pair(path, old, shift_content(new, 10, dpr))
|
||||
print(f" 判红={'是' if a_problems else '否 —— 仪器对整体位移不敏感'}")
|
||||
print(f"负对照 B(非图标区小块横移 2 CSS px,应判红):{path}")
|
||||
b_problems = check_pair(path, old, nudge_patch(new, dpr))
|
||||
print(f" 判红={'是' if b_problems else '否 —— 仪器对非图标改动不敏感'}")
|
||||
print("正对照(真实新图,应通过):")
|
||||
c_problems = check_pair(path, old, new)
|
||||
print(f" 通过={'是' if not c_problems else '否'}")
|
||||
ok = bool(a_problems) and bool(b_problems) and not c_problems
|
||||
print(f"SELFTEST {'PASS' if ok else 'FAIL'}")
|
||||
return 0 if ok else 1
|
||||
|
||||
failures: list[str] = []
|
||||
print(f"核验 {len(pairs)} 张有 HEAD 参照的基线(阈值:单通道 > {PIXEL_THRESHOLD};包围盒 ≤ "
|
||||
f"{MAX_BBOX_WIDTH_CSS}×{MAX_BBOX_HEIGHT_CSS} CSS px)")
|
||||
for path, old, new in pairs:
|
||||
problems = check_pair(path, old, new)
|
||||
if problems:
|
||||
failures.append(f"{path}: " + ";".join(problems))
|
||||
|
||||
if untracked:
|
||||
print(f"\n未入库基线 {len(untracked)} 张(HEAD 无参照,无法做前后比对):")
|
||||
for path in untracked:
|
||||
print(f" NO-REFERENCE {path}")
|
||||
|
||||
print()
|
||||
if failures:
|
||||
print(f"判定红:{len(failures)}/{len(pairs)} 张越界")
|
||||
for line in failures:
|
||||
print(" - " + line)
|
||||
return 1
|
||||
print(f"可参照基线全部通过:{len(pairs)}/{len(pairs)} 张只差在联系区两个图标盒内,且尺寸零变化")
|
||||
if untracked and "--allow-untracked" not in sys.argv:
|
||||
print(f"存在 {len(untracked)} 张未入库基线:未经授权不得入库,退出码 3", file=sys.stderr)
|
||||
return 3
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print(f"SETUP-ERROR: {exc}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
@@ -0,0 +1,27 @@
|
||||
# 视觉回归三轮读数(2026-10-26)
|
||||
|
||||
命令统一为:`E2E_BASE_URL=http://localhost:3001 npm run test:visual:all -- --update-snapshots=none`
|
||||
(端口 3000 被本机 auth-center 容器占着,Playwright 对 401 也判"服务已就绪",会静默复用,故绕到 3001)
|
||||
|
||||
## 1. 重采前(工作树口径:35 路由,含另一批未提交的 20 路由扩容)
|
||||
|
||||
`/tmp/visual-before.log` → **137 failed / 88 passed(225 例,15.1m)**
|
||||
|
||||
- 分项目失败数:chromium-desktop 14、chromium-tablet 35、chromium-mobile 35、
|
||||
firefox-desktop 18、webkit-desktop 35
|
||||
- 其中 5 张 `footer-section` 与 5 张 `theme-*-main` 也在红集里(主题图取 `main`,
|
||||
而 `main` 包住页脚:`client-layout.tsx:15` 在根布局包住整个营销布局,`footer` 在 `<main>` 内)
|
||||
- 桌面 chromium 35 张全页图里 **21 绿 / 14 红** —— 3px 图标位移对 `maxDiffPixels: 200`
|
||||
是"刚好越线",像素门限不能替几何判据兜底
|
||||
|
||||
## 2. 重采后(同上口径)
|
||||
|
||||
`/tmp/visual-after.log` → **225 passed / 0 failed(9.9m)**
|
||||
|
||||
## 3. PR 口径(HEAD 的视觉清单:15 路由;把 `e2e/visual-regression.spec.ts` 临时换回 HEAD 版本)
|
||||
|
||||
`/tmp/visual-prstate.log` → **125 passed / 0 failed(6.0m)**
|
||||
|
||||
- 运行前把工作树版本备份到 `/tmp/visual-spec-wt.ts`(sha256 `cd266b11…`),跑完按原样还原并校验 sha256
|
||||
- HEAD 清单 15 路由 × 5 project = 75 张全页图,与已入库的 75 张 tracked 全页基线一一对应;
|
||||
工作树里那 100 张未入库基线属于未提交的 20 路由扩容,不在本批入库范围
|
||||
@@ -0,0 +1,98 @@
|
||||
import { test, expect, type Page } from './fixtures';
|
||||
|
||||
/**
|
||||
* 页脚「联系我们」两行的图标必须与首行文字的水平中线重合(lessons §5.53)。
|
||||
*
|
||||
* 旧写法是 `flex items-start` + 图标固定 `mt-0.5`(0.125rem)。本项目把 Tailwind 的
|
||||
* `leading-relaxed` 重映射成 `--line-height-relaxed: 1.85`(不是默认 1.625),根字号又有
|
||||
* 16 / 17 / 18 三档(globals.css:542-558)⇒ 手拍的固定偏移在每档都比文字中线高 3px 上下,
|
||||
* 且随视口变化。像素门限(maxDiffPixels 200)对 3px 的图标位移只给出「刚好越线」的读数,
|
||||
* 指望它判红会时红时绿,所以这里按几何单独判一次。
|
||||
*
|
||||
* 判据取**盒子**,不取 `Range.getClientRects()`:后者的高度是字体 ascent+descent(不是行盒),
|
||||
* top 还被整数量化,与行盒中心存在 0.45px 级的字体相关偏置 —— 拿它当参照会既可能假红也可能假绿。
|
||||
*/
|
||||
|
||||
const ROWS = '[data-testid="card-contact"] li';
|
||||
const TOLERANCE = 0.5; // px;修复前偏差 2.0–3.3px,修复后应 ≈0
|
||||
|
||||
type RowMeasurement = {
|
||||
text: string;
|
||||
iconHeight: number;
|
||||
lineHeight: number;
|
||||
/** 图标盒中心 − 首行文字中线(正数=图标偏低) */
|
||||
delta: number;
|
||||
tag: string;
|
||||
};
|
||||
|
||||
async function measureContactRows(page: Page): Promise<RowMeasurement[]> {
|
||||
return page.evaluate((sel) => {
|
||||
return Array.from(document.querySelectorAll(sel)).map((li) => {
|
||||
const svg = li.querySelector('svg');
|
||||
const textEl = li.querySelector('span:last-child, a');
|
||||
if (!svg || !textEl) {
|
||||
return { text: '', iconHeight: 0, lineHeight: 0, delta: Number.NaN, tag: '' };
|
||||
}
|
||||
const icon = svg.getBoundingClientRect();
|
||||
const box = textEl.getBoundingClientRect();
|
||||
const lineHeight = parseFloat(getComputedStyle(textEl).lineHeight);
|
||||
// 地址是普通块级文本:内容盒顶 + 行高/2 = 首行行盒中心(换行后首行依然成立)。
|
||||
// 邮箱是 inline-flex + items-center 的链接:文字在盒内垂直居中 ⇒ 取盒中心。
|
||||
const lineCenter =
|
||||
textEl.tagName === 'A' ? box.top + box.height / 2 : box.top + lineHeight / 2;
|
||||
return {
|
||||
text: (textEl.textContent ?? '').trim(),
|
||||
iconHeight: icon.height,
|
||||
lineHeight,
|
||||
delta: icon.top + icon.height / 2 - lineCenter,
|
||||
tag: textEl.tagName,
|
||||
};
|
||||
});
|
||||
}, ROWS);
|
||||
}
|
||||
|
||||
const VIEWPORTS = [
|
||||
{ name: 'desktop-1440(根字号 18)', width: 1440, height: 900, rootFontSize: 18 },
|
||||
{ name: 'tablet-834(根字号 17)', width: 834, height: 1194, rootFontSize: 17 },
|
||||
{ name: 'mobile-390(根字号 16)', width: 390, height: 844, rootFontSize: 16 },
|
||||
] as const;
|
||||
|
||||
test.describe('页脚联系方式:图标与首行文字同中线', { tag: '@regression' }, () => {
|
||||
for (const vp of VIEWPORTS) {
|
||||
test(vp.name, async ({ page }) => {
|
||||
await page.setViewportSize({ width: vp.width, height: vp.height });
|
||||
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
||||
await page.evaluate(() => document.fonts.ready.then(() => undefined));
|
||||
|
||||
// 判据本身的分母:先证明这次测到的是「三档根字号」里的这一档,
|
||||
// 否则断言的是一张没走到目标断点的页面。
|
||||
const rootFontSize = await page.evaluate(
|
||||
() => parseFloat(getComputedStyle(document.documentElement).fontSize),
|
||||
);
|
||||
expect(rootFontSize, `视口 ${vp.width}px 的根字号应为 ${vp.rootFontSize}px`).toBe(
|
||||
vp.rootFontSize,
|
||||
);
|
||||
|
||||
const rows = await measureContactRows(page);
|
||||
|
||||
// 防空转:行数必须正好两行(地址 + 邮箱),缺一行下面的逐行断言就会在空集上放行。
|
||||
expect(rows.length, 'card-contact 必须正好两行(地址 + 邮箱)').toBe(2);
|
||||
|
||||
// 逐行收集而不是逐行 expect:红的时候要一次看到两行、三档的读数,否则排查只能一档一档试。
|
||||
const problems: string[] = [];
|
||||
for (const [index, row] of rows.entries()) {
|
||||
const label = `第 ${index + 1} 行(${row.tag || '缺 svg/文本'})`;
|
||||
if (row.text.length === 0) problems.push(`${label} 文本为空 ⇒ 行盒塌陷(site-config 默认 address 为空串)`);
|
||||
if (row.iconHeight <= 0) problems.push(`${label} 没有可量的 svg`);
|
||||
if (row.lineHeight <= 0) problems.push(`${label} 没有解析出 px 行高`);
|
||||
if (Math.abs(row.delta) > TOLERANCE) {
|
||||
problems.push(
|
||||
`${label} 图标中心与首行文字中线偏差 ${row.delta.toFixed(3)}px(容差 ${TOLERANCE}px;` +
|
||||
`文本=${row.text.slice(0, 12)},图标高=${row.iconHeight},行高=${row.lineHeight})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
expect(problems, `根字号 ${rootFontSize}px · 视口 ${vp.width}px\n${problems.join('\n')}`).toEqual([]);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -71,11 +71,21 @@ export function Footer() {
|
||||
<div className="font-semibold text-sm mb-5 text-dark-text-primary tracking-widest uppercase">联系我们</div>
|
||||
<ul className="space-y-4 mb-8 [&_li]:p-0 [&_li]:m-0 [&_li]:static [&_li::before]:hidden">
|
||||
<li className="flex items-start gap-3">
|
||||
<MapPin className="w-4 h-4 text-dark-text-muted mt-0.5 shrink-0" />
|
||||
{/* 图标与首行文字共用一个行盒:高 = --line-height-relaxed × --font-size-sm
|
||||
(本项目把 relaxed 重映射成 1.85,不是 Tailwind 默认的 1.625),图标在其中
|
||||
items-center。旧写法是固定 mt-0.5 手拍,在三档根字号下都比文字中线高
|
||||
3.319 / 3.134 / 2.950px(root 18/17/16,见 e2e/footer-contact-align.spec.ts)。
|
||||
高度用令牌而非裸 px:地址换行时仍对齐首行,且随根字号等比。 */}
|
||||
<span className="h-[calc(var(--line-height-relaxed)*var(--font-size-sm))] flex w-4 shrink-0 items-center justify-center">
|
||||
<MapPin className="w-4 h-4 text-dark-text-muted" />
|
||||
</span>
|
||||
<span className="text-dark-text-secondary text-sm leading-relaxed">{config.address}</span>
|
||||
</li>
|
||||
<li className="flex items-start gap-3">
|
||||
<Mail className="w-4 h-4 text-dark-text-muted mt-0.5 shrink-0" />
|
||||
<li className="flex items-center gap-3">
|
||||
{/* 邮箱是单行链接(无断行点):行高由 globals.css:637-639 的 ul 规则继承为
|
||||
--line-height-relaxed,整行 items-center 就让图标与链接盒中心同高,
|
||||
不需要上面那种行盒常量。若日后换成可断行的长文本,改回行盒写法。 */}
|
||||
<Mail className="w-4 h-4 text-dark-text-muted shrink-0" />
|
||||
<a
|
||||
href={`mailto:${config.email}`}
|
||||
className="text-dark-text-secondary hover:text-dark-text-primary transition-colors duration-200 text-sm"
|
||||
|
||||
Reference in new issue
Block a user