/** * 页脚「联系我们」图标-文字中线取证(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));