旧写法用固定 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。 行高/字号/页高零变化,只移动两个图标。
60 lines
2.4 KiB
JavaScript
60 lines
2.4 KiB
JavaScript
/**
|
|
* 页脚「联系我们」图标-文字中线取证(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));
|