Files
workspace/code/g3soft-libs/packages/ui/probe-boundary.mjs
T
2026-10-15 17:31:35 +08:00

66 lines
2.4 KiB
JavaScript

import { chromium } from '@playwright/test'
/**
* 收敛范围:找出「容器小到装不下内容」的那个临界高度。
* 表头 34 + 一行 30 = 64px(加外框上下各 1px → 66px)。
* 低于这个高度,表格就是病态输入(连一行都放不下)。
*/
const BASE = process.env.PROBE_URL || 'http://localhost:5200'
const browser = await chromium.launch()
const page = await browser.newPage({ viewport: { width: 1400, height: 1200 } })
await page.goto(BASE, { waitUntil: 'networkidle' })
const clipSample = async (x, y, w, h) => {
const shot = await page.screenshot({ clip: { x, y, width: w, height: h } })
return page.evaluate(async (dataUrl) => {
const img = new Image()
await new Promise((res) => {
img.onload = res
img.src = dataUrl
})
const cv = document.createElement('canvas')
cv.width = img.width
cv.height = img.height
const ctx = cv.getContext('2d')
ctx.drawImage(img, 0, 0)
const d = ctx.getImageData(0, 0, img.width, img.height).data
const out = []
for (let i = 0; i < d.length; i += 4) out.push([d[i], d[i + 1], d[i + 2]])
return out
}, `data:image/png;base64,${shot.toString('base64')}`)
}
const heights = [100, 95, 90, 85, 80, 75, 70, 68, 66, 64, 60]
for (const h of heights) {
await page.evaluate((hh) => {
document.querySelector('[data-testid="table-wrap"]').style.height = `${hh}px`
}, h)
await page.waitForTimeout(420)
await page.locator('[data-testid="table-wrap"]').scrollIntoViewIfNeeded()
await page.waitForTimeout(160)
const g = await page.evaluate(() => {
const wrap = document.querySelector('[data-testid="table-wrap"]')
const root = wrap.querySelector('.g3-table')
const inner = wrap.querySelector('.stk-table')
const r = root.getBoundingClientRect()
return {
left: Math.round(r.left),
bottom: Math.round(r.bottom),
overflow: inner.scrollHeight > inner.clientHeight + 1,
scrollH: inner.scrollHeight,
clientH: inner.clientHeight,
}
})
const y = Math.max(0, g.bottom - 4)
if (1200 - y < 10) continue
const px = await clipSample(g.left + 300, y, 1, 10)
const vec = px.map(([r, gg, b]) => (r < 246 || gg < 246 || b < 246 ? 1 : 0))
const n = vec.reduce((a, b) => a + b, 0)
console.log(
`h=${String(h).padStart(3)} 溢出=${String(g.overflow).padStart(5)} (scrollH ${g.scrollH} / clientH ${g.clientH}) 底部 ${vec.join('')} (${n}条) ${n === 1 ? '✅' : '❌'}`,
)
}
await browser.close()