diff --git a/tools/fidelity.mjs b/tools/fidelity.mjs index 0a19368..29b0602 100644 --- a/tools/fidelity.mjs +++ b/tools/fidelity.mjs @@ -97,16 +97,40 @@ for (const name of targets) { failed++; continue; } - // ③ diff,超「该屏校准阈值」即红 ran++; - try { - execFileSync('node', [diff, proto, golden, out, - '--threshold', String(s.threshold), '--tolerance', values.tolerance], - { stdio: 'inherit' }); - console.log(`[fidelity] ✅ ${name}·${theme} ≤ 阈值 ${(s.threshold * 100).toFixed(1)}%`); - } catch { - console.error(`[fidelity] ❌ ${name}·${theme} 超阈 ${(s.threshold * 100).toFixed(1)}% — 看 ${out}`); - failed++; + if (s.zones && s.zones.length) { + // 分区域判定:全屏 diff 仅参考(不判定,避免内容区差异淹没局部错位), + // 真正判定逐 zone(顶栏/侧栏/状态栏各自紧阈),抓全屏百分比看不到的局部偏移。 + try { + execFileSync('node', [diff, proto, golden, out, + '--threshold', '1', '--tolerance', values.tolerance], { stdio: 'pipe' }); + } catch { /* 全屏仅参考 */ } + let zoneFail = 0; + for (const z of s.zones) { + const zout = join(diffDir, `${s.prefix}_${theme}_${z.name}_diff.png`); + const crop = [z.x * s.dpr, z.y * s.dpr, z.w * s.dpr, z.h * s.dpr].join(','); + try { + execFileSync('node', [diff, proto, golden, zout, + '--threshold', String(z.threshold), '--tolerance', values.tolerance, + '--crop', crop], { stdio: 'inherit' }); + console.log(`[fidelity] ✅ ${name}·${theme}·${z.name} ≤ ${(z.threshold * 100).toFixed(1)}%`); + } catch { + console.error(`[fidelity] ❌ ${name}·${theme}·${z.name} 超阈 ${(z.threshold * 100).toFixed(1)}% — 看 ${zout}`); + zoneFail++; + } + } + if (zoneFail) failed++; + } else { + // ③ 整屏 diff,超「该屏校准阈值」即红 + try { + execFileSync('node', [diff, proto, golden, out, + '--threshold', String(s.threshold), '--tolerance', values.tolerance], + { stdio: 'inherit' }); + console.log(`[fidelity] ✅ ${name}·${theme} ≤ 阈值 ${(s.threshold * 100).toFixed(1)}%`); + } catch { + console.error(`[fidelity] ❌ ${name}·${theme} 超阈 ${(s.threshold * 100).toFixed(1)}% — 看 ${out}`); + failed++; + } } } } diff --git a/tools/screens.mjs b/tools/screens.mjs index 1ae67f5..f17d8f2 100644 --- a/tools/screens.mjs +++ b/tools/screens.mjs @@ -11,15 +11,23 @@ // waitFor 原型截图前等待的选择器 // threshold fidelity 该屏校准阈值(差异像素比例上限);人工目检「像」后定 // shell true=外壳(顶栏/侧栏/状态栏整框),与普通屏一同对比 +// zones 分区域阈值(逻辑坐标):把屏切带各自判定,抓「全屏百分比淹没」的局部错位 +// (如顶栏元素水平偏移)。x/y/w/h 为逻辑像素,fidelity 按 dpr 换算。 export const SCREENS = { - // 外壳:顶栏(两级品牌+主题器+通知) + 侧栏(分组) + 状态栏。Phase 1 重建后校准阈值。 + // 外壳:顶栏(两级品牌+主题器+通知) + 侧栏(分组) + 状态栏。 + // 全屏阈值松(内容区空白 vs 原型满表),真正判定看 zones(顶栏带收紧到 4%)。 shell: { html: '.superpowers/prototype/screens/inventory.html', // 外壳含在每个全框屏里,借库存页取整框 prefix: 'app_shell', width: 1280, height: 900, dpr: 2, waitFor: '.app', - threshold: 0.20, + threshold: 0.20, // 全屏仅参考;判定以 zones 为准 shell: true, + zones: [ + { name: 'top', x: 0, y: 0, w: 1280, h: 56, threshold: 0.04 }, + { name: 'side', x: 0, y: 56, w: 218, h: 810, threshold: 0.14 }, + { name: 'status', x: 0, y: 866, w: 1280, h: 34, threshold: 0.10 }, + ], }, inventory: { html: '.superpowers/prototype/screens/inventory.html',