feat(image-vectorize): v0.3.1 预览改白底 + 填充/背景色并排(带底可选写入导出)

This commit is contained in:
qiqi committed 2026-11-05 09:11:19 +08:00
1 parent 866c420c5c
commit 4ab12be15d
9 files changed
+281 -70

No files matched your search

+14
View File
@@ -169,6 +169,20 @@ check('精度默认「精细」', await page.evaluate(() => {
const a = document.querySelector('[data-seg-group="precision"] button.active')
return Boolean(a && a.dataset.value === 'fine')
}))
// v0.3.1:预览白底 + 填充/背景并排(真站 CSP 下 CSS 得真生效,不能只信本地)
check('预览区白底、无棋盘格', await page.evaluate(() => {
const cs = getComputedStyle(document.querySelector('.vz-preview'))
const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(cs.backgroundColor)
return Boolean(m) && Number(m[1]) > 240 && cs.backgroundImage === 'none'
}))
check('「填充 / 背景」两个色块并排在同一行', await page.evaluate(() => {
const a = document.querySelector('[data-color="color"]')
const b = document.querySelector('[data-color="bg"]')
if (!a || !b) return false
const ra = a.getBoundingClientRect()
const rb = b.getBoundingClientRect()
return Math.abs(ra.top - rb.top) < 2 && rb.left > ra.right - 1
}))
// ---------- 5.6) 复制到剪贴板(真写,读回校验口味) ----------
await page.locator('[data-act="copy"]').click()
+43 -6
View File
@@ -176,14 +176,14 @@ check('预览是矢量(blob: SVG 且不是原图)', await page.evaluate(() =
const v = document.querySelector('[data-stage="vector"]')
return Boolean(v && /^blob:/.test(v.src) && !v.hidden)
}))
// 透明区必须是中性灰棋盘:电商素材大量是黑字/深色 logo,深色棋盘会把内容直接吞掉,
// 看起来像「描摹失败」(这个坑上一版实测踩过一次)
check('预览透明底用浅色棋盘(深色内容不会被吞)', await page.evaluate(() => {
const bg = getComputedStyle(document.querySelector('.vz-preview')).backgroundColor
const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(bg)
// v0.3.1 起预览区改纯白底(用户要求「直接用白色,不用透明背景展示」),
// 同时断言没有残留棋盘(background-image 必须是 none),并顺带确认导出 SVG 仍透明
check('预览区白底、无棋盘格', await page.evaluate(() => {
const cs = getComputedStyle(document.querySelector('.vz-preview'))
const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(cs.backgroundColor)
if (!m) return false
const lum = (Number(m[1]) + Number(m[2]) + Number(m[3])) / 3
return lum > 150
return lum > 240 && cs.backgroundImage === 'none'
}))
const monoPaths = Number(await pathsNow(page))
@@ -335,6 +335,41 @@ await page.evaluate(() => {
})
await sleep(400)
check('改单色填充色写进 SVG', await page.evaluate(() => /#c0392b/i.test(window.__lastSvg || '')), '')
// 开发用:VZ_SHOT=/tmp/vz-panel.png 出一张面板截图(验证「填充 / 背景」这排没挤坏布局)
if (process.env.VZ_SHOT) await page.locator('.vz-modal').screenshot({ path: process.env.VZ_SHOT })
// ---------- 背景色 / 带底(v0.3.1) ----------
const setBg = async (hex) => {
await page.evaluate((v) => {
const c = document.querySelector('[data-color="bg"]')
c.value = v
c.dispatchEvent(new Event('input', { bubbles: true }))
}, hex)
await sleep(320)
}
const hasBgRect = () => page.evaluate(() => /<rect[^>]*width="100%"[^>]*fill="#efefef"/i.test(window.__lastSvg || ''))
const seqBeforeBg = await page.evaluate(() => window.__svgSeq)
await setBg('#efefef')
check('改背景色:预览底色跟着变(不用重新描摹)', await page.evaluate(() => {
const bg = getComputedStyle(document.querySelector('.vz-preview')).backgroundColor
return /239,\s*239,\s*239/.test(bg)
}))
check('改背景色不触发重描摹(底色不参与轮廓计算)',
await page.evaluate(() => window.__svgSeq) === seqBeforeBg)
check('默认「带底」关:导出仍是透明底', !(await hasBgRect()))
const elementsBeforeBg = await page.evaluate(() => document.querySelector('[data-stat="elements"]').textContent)
await page.locator('[data-check="bgExport"]').check()
await sleep(450)
check('勾「带底」后 SVG 里铺了背景矩形', await hasBgRect())
check('带底不影响元素数(背景矩形不算一个元素)',
(await page.evaluate(() => document.querySelector('[data-stat="elements"]').textContent)) === elementsBeforeBg)
await page.locator('[data-check="bgExport"]').uncheck()
await sleep(450)
check('取消「带底」后回到透明导出', !(await hasBgRect()))
await setBg('#ffffff')
// ---------- 输出 ----------
// 复制到剪贴板:about:blank 是非安全上下文,没有真的 Clipboard API,
@@ -386,6 +421,8 @@ check('保存后模态自动关闭', (await page.locator('.vz-root').count()) ==
// ---------- 参数记忆 ----------
const mem = await page.evaluate(() => window.__settings)
check('参数记忆写回宿主 settings', mem && mem.mode === 'mono' && Number(mem.turdSize) === 3 && String(mem.color).toLowerCase() === '#c0392b', JSON.stringify(mem))
check('背景色 / 带底 也进记忆', String(mem.bg).toLowerCase() === '#ffffff' && mem.bgExport === false,
'bg=' + mem.bg + ' bgExport=' + mem.bgExport)
await page.evaluate(() => { window.__actions['vectorize-node'].run({ id: 'r1', type: 'ref', name: 'src.png' }) })
await page.locator('.vz-modal').waitFor({ state: 'visible', timeout: 15000 })
check('重新打开沿用上次参数(mode=mono、颜色 #c0392b)', await page.evaluate(() => {