3168 lines
174 KiB
JavaScript
3168 lines
174 KiB
JavaScript
// 标注插件本地端到端(开发用,不进 CI)。
|
||
//
|
||
// 为什么需要它:真站 e2e 要发布后才能跑;本探针直接把构建产物注入合成宿主,
|
||
// 在真实 Chromium 里验证「选区 / 命令层 / 撤销 / 还原原图 / 输出预设 / 便利 UI」
|
||
// 以及 ESM 循环打包后是否真的能跑起来。网络完全本地,不依赖线上 KV 与 CSP。
|
||
//
|
||
// 运行:node image-annotate/tools/harness.mjs
|
||
// 依赖:playwright(本仓/宿主仓 node_modules 均可;或用 IWB_PLAYWRIGHT_ROOT 指定)
|
||
import { createRequire } from 'node:module'
|
||
import { readFileSync } from 'node:fs'
|
||
import path from 'node:path'
|
||
import { fileURLToPath } from 'node:url'
|
||
|
||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||
const REPO = path.resolve(HERE, '../..')
|
||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
||
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
||
// 版本真源是 package.json(构建时注入 manifest),探针不再硬编码,免得每次发版都要改测试
|
||
const PKG_VERSION = JSON.parse(readFileSync(path.resolve(HERE, '../package.json'), 'utf8')).version
|
||
|
||
let chromium = null
|
||
for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) {
|
||
try { chromium = createRequire(path.join(base, 'package.json'))('playwright').chromium; break } catch { /* 试下一个 */ }
|
||
}
|
||
if (!chromium) {
|
||
console.error('✗ 找不到 playwright。请在含 node_modules 的目录执行,或指定 IWB_PLAYWRIGHT_ROOT')
|
||
process.exit(2)
|
||
}
|
||
|
||
let failed = 0
|
||
const check = (name, ok, detail) => {
|
||
if (!ok) failed++
|
||
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
||
}
|
||
const poll = async (fn, timeout = 8000, step = 80) => {
|
||
const end = Date.now() + timeout
|
||
for (;;) {
|
||
let v
|
||
try { v = await fn() } catch { v = false }
|
||
if (v) return v
|
||
if (Date.now() > end) return false
|
||
await new Promise((r) => setTimeout(r, step))
|
||
}
|
||
}
|
||
|
||
const browser = await chromium.launch()
|
||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 }, acceptDownloads: true })
|
||
const errors = []
|
||
page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()) })
|
||
page.on('pageerror', (e) => errors.push('pageerror: ' + e.message))
|
||
page.on('dialog', (d) => { errors.push('unexpected dialog: ' + d.message()); d.dismiss().catch(() => {}) })
|
||
|
||
await page.setContent('<!doctype html><html><head><meta charset="utf-8"></head><body><div id="host"></div></body></html>')
|
||
const PNG = await page.evaluate(() => {
|
||
const c = document.createElement('canvas')
|
||
c.width = 96; c.height = 64
|
||
const x = c.getContext('2d')
|
||
x.fillStyle = '#2f6fed'; x.fillRect(0, 0, 96, 64)
|
||
x.fillStyle = '#ffffff'; x.fillRect(20, 12, 56, 40)
|
||
return c.toDataURL('image/png')
|
||
})
|
||
|
||
// ---------- 合成宿主 ----------
|
||
await page.evaluate(() => {
|
||
window.IWBPluginHost = {
|
||
register(manifest, factory) { window.__manifest = manifest; window.__factory = factory },
|
||
snapshot() { return { initialized: true } },
|
||
list() { return [] }
|
||
}
|
||
window.__actions = {}
|
||
window.__commands = {}
|
||
window.__settings = {}
|
||
window.__writes = []
|
||
})
|
||
await page.addScriptTag({ path: PLUGIN_ENTRY })
|
||
|
||
const boot = await page.evaluate((png) => {
|
||
const ctx = {
|
||
id: 'image-annotate', manifest: window.__manifest, apiVersion: 1,
|
||
log() {},
|
||
settings: {
|
||
get(k) { return window.__settings[k] },
|
||
set(k, v) { window.__settings[k] = v },
|
||
all() { return { ...window.__settings } }
|
||
},
|
||
storage: { get() {}, set() {}, remove() {}, keys() { return [] } },
|
||
events: { on() { return () => {} }, emit() { return true } },
|
||
canvas: {
|
||
getNodeImage() { return { dataUrl: png } },
|
||
getSelectedNode() { return { id: 'r1', type: 'ref', name: 'src.png' } },
|
||
setNodeImage(id, dataUrl) { window.__writes.push({ kind: 'replace', id, len: String(dataUrl).length }); return true },
|
||
createImageNode(o) { window.__writes.push({ kind: 'newNode', len: String(o.dataUrl).length }); return { id: 'r2' } }
|
||
},
|
||
nodeActions: { register(r) { window.__actions[r.id] = r } },
|
||
commands: { register(r) { window.__commands[r.id] = r } }
|
||
}
|
||
window.__plugin = window.__factory(ctx)
|
||
window.__commands['annotate-selected'].run().catch(() => {})
|
||
return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) }
|
||
}, PNG)
|
||
check('产物可执行(循环打包未炸)', boot.version === PKG_VERSION, 'version=' + boot.version + ' 期望 ' + PKG_VERSION)
|
||
check('manifest 声明输出预设设置项', boot.settingsSchema.includes('exportPreset') && boot.settingsSchema.includes('panelsCollapsed'), boot.settingsSchema.join(','))
|
||
|
||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
||
const dbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||
const pixel = (cx, cy) => page.evaluate(({ x, y }) => {
|
||
const d = window.__iwbEditor.__debug()
|
||
return { base: d.pixel('base', x, y), draw: d.pixel('draw', x, y), layers: d.layers.map(l => ({ id: l.id, a: d.pixel(l.id, x, y) })) }
|
||
}, { x: cx, y: cy })
|
||
|
||
check('编辑器打开 + 便利 UI 五区齐全(v1.2.4 起命令带取代「更多」菜单)', await page.evaluate(() => {
|
||
const q = (s) => Boolean(document.querySelector(s))
|
||
return q('.iwb-editor-optionbar') && q('.iwb-editor-statusbar') && q('.iwb-editor-sel-bar') &&
|
||
q('.iwb-editor-toast') && q('.iwb-editor-selection-overlay') && q('.iwb-editor-cursor-overlay') &&
|
||
q('[data-action="download"]') && q('.iwb-editor-color-pair')
|
||
}))
|
||
check('新增选区工具按钮', (await page.locator('.iwb-editor-tool[data-tool="marquee"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-tool[data-tool="lasso"]').count()) === 1)
|
||
|
||
check('modal 铺满视口、状态栏贴在 modal 底部(防多余 </div> 把状态栏挤成 overlay 的 flex 兄弟)', await page.evaluate(() => {
|
||
const ov = document.querySelector('#iwb-editor-overlay')
|
||
const modal = ov.querySelector('.iwb-editor-modal')
|
||
const sb = ov.querySelector('.iwb-editor-statusbar')
|
||
if (!ov || !modal || !sb) return false
|
||
const vw = window.innerWidth
|
||
const m = modal.getBoundingClientRect(), s = sb.getBoundingClientRect(), o = ov.getBoundingClientRect()
|
||
const inside = (a, b) => a.left >= b.left - 1 && a.right <= b.right + 1 && a.top >= b.top - 1 && a.bottom <= b.bottom + 1
|
||
return Math.round(m.width) === vw && Math.round(o.width) === vw &&
|
||
Math.abs(s.bottom - m.bottom) < 3 && inside(m, o) && inside(s, m)
|
||
}))
|
||
|
||
const imgBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||
|
||
// ---------- 默认图层结构(用户裁定:默认不预建画笔标注层) ----------
|
||
check('打开编辑器默认只有「原图」1 层,且状态栏不再写「画笔标注」',
|
||
(await dbg()).layers.length === 1 &&
|
||
(await dbg()).layers[0].id === 'base' &&
|
||
!(await page.locator('.iwb-editor-status-layer').textContent()).includes('画笔标注'),
|
||
JSON.stringify((await dbg()).layers.map(l => l.name)))
|
||
|
||
// v1.3(用户裁定 2026-11-05):调色板从侧栏搬进工具栏弹层,侧栏只剩缩放
|
||
// v1.19(用户 2026-11-10):右栏那份常驻调色面板删掉,颜色只剩弹层一处
|
||
check('调色板只在工具栏弹层:右栏没有调色模块,SV/色相/去色 + 15 个常用色都在弹层里',
|
||
await page.evaluate(() => {
|
||
const q = (s) => Boolean(document.querySelector(s))
|
||
return !q('.iwb-editor-left [data-color-surface]') && !q('.iwb-editor-left .iwb-editor-colors') &&
|
||
q('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]') &&
|
||
q('.iwb-editor-color-pop .iwb-color-sv') && q('.iwb-editor-color-pop .iwb-color-hue') &&
|
||
// v1.20:去色进网格占第一格,所以 data-panel-color 只剩 15 个(+ 去色 = 16 格)
|
||
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-swatches [data-panel-color]').length === 15 &&
|
||
q('.iwb-editor-color-pop .iwb-editor-color-swatches [data-color-none]') &&
|
||
q('.iwb-editor-zoom') &&
|
||
!q('.iwb-editor-brush-size') && !q('.iwb-editor-brush-num') &&
|
||
document.querySelectorAll('.iwb-editor-brush-preset').length === 0
|
||
}))
|
||
|
||
// v1.4:侧栏「快速效果」(用户 2026-11-05 提出:反白 + 其它推荐效果)
|
||
check('侧栏快速效果:6 个效果按钮齐备,目标层标签指向当前层',
|
||
await page.evaluate(() => {
|
||
const keys = [...document.querySelectorAll('.iwb-editor-left .iwb-editor-fx-btn')].map(b => b.dataset.fx).join(',')
|
||
const label = document.querySelector('.iwb-editor-fx-target')
|
||
return keys === 'invert,gray,boost,contrast,soft,mosaic' && !!label && label.textContent.trim() === '原图'
|
||
}))
|
||
|
||
const fxInvert = await (async () => {
|
||
const read = () => page.evaluate(() => {
|
||
const c = document.querySelectorAll('.iwb-editor-layer-canvas')[0]
|
||
const d = c.getContext('2d').getImageData(2, 2, 1, 1).data
|
||
return d[0] + ',' + d[1] + ',' + d[2]
|
||
})
|
||
const before = await read()
|
||
await page.locator('.iwb-editor-left [data-fx="invert"]').click()
|
||
await page.waitForTimeout(180)
|
||
const after = await read()
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(180)
|
||
const back = await read()
|
||
return { ok: after !== before && back === before, detail: `before=${before} after=${after} undo=${back}` }
|
||
})()
|
||
check('反白真实反相且 Ctrl+Z 能复原(效果进历史链)', fxInvert.ok, fxInvert.detail)
|
||
|
||
check('色板弹层默认收起;点工具栏色点弹出、且整块在视口内(没被工具栏/画布的 overflow 裁掉)',
|
||
await (async () => {
|
||
const pop = page.locator('.iwb-editor-color-pop')
|
||
if (await pop.isVisible()) return 'pre: 弹层一开始就开着'
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(100)
|
||
if (!(await pop.isVisible())) return 'post: 点了没开'
|
||
const box = await pop.boundingBox()
|
||
const vp = page.viewportSize()
|
||
const inView = box && box.x >= 0 && box.y >= 0 &&
|
||
box.x + box.width <= vp.width + 1 && box.y + box.height <= vp.height + 1
|
||
// Esc 关掉(顺带验证 Esc 优先收弹层),不影响后面的用例
|
||
await page.keyboard.press('Escape')
|
||
await page.waitForTimeout(80)
|
||
return inView && !(await pop.isVisible()) ? true : 'box=' + JSON.stringify(box)
|
||
})())
|
||
|
||
// ---------- v1.18 / v1.19 / v1.20 色板弹层布局(用户 2026-11-10) ----------
|
||
// v1.18:「加钉住」「三项不写标题、用细横线分割」
|
||
// v1.19:「去色放钉住左边、竖线分割」「吸色与色值放在钉住那一排」「宽度再多一点,
|
||
// 颜色一排 8 个,常用色多加 4 个」「最近色放两排」
|
||
// v1.20:文字工具多出「底色」tab 时头部挤爆,把「去色」整颗抵没了 ——
|
||
// 改成去色占常用色第一格(永远在,不可用只置灰),头部元素全部定宽。
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() // 用选择工具点画布,不落像素
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(140)
|
||
const popLayout = await page.evaluate(() => {
|
||
const pop = document.querySelector('.iwb-editor-color-pop')
|
||
const r = (el) => el.getBoundingClientRect()
|
||
const none = pop.querySelector('[data-color-none]')
|
||
const grid = pop.querySelector('.iwb-editor-color-swatches')
|
||
const picker = r(pop.querySelector('.iwb-color-pop-picker'))
|
||
const side = r(pop.querySelector('.iwb-color-pop-side'))
|
||
const headEl = pop.querySelector('.iwb-color-pop-head')
|
||
const head = r(headEl)
|
||
const eye = pop.querySelector('[data-action="palettePick"]')
|
||
const hex = pop.querySelector('.iwb-editor-color-hex-input')
|
||
const pin = pop.querySelector('[data-action="pinColorPop"]')
|
||
const sw = [...pop.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
|
||
// 去色现在是常用色网格的第一格:位置固定、尺寸和其它色块一致
|
||
const noneFirstCell = grid.children[0] === none
|
||
const noneSameSize = Math.abs(r(none).width - r(sw[0]).width) < 1 &&
|
||
Math.abs(r(none).height - r(sw[0]).height) < 1
|
||
const noneRow1 = Math.round(r(none).top) === Math.round(r(sw[0]).top) &&
|
||
Math.round(r(none).left) < Math.round(r(sw[0]).left)
|
||
// 头部一行:吸管 / 色值 / 图钉 的竖直中心都必须落在头部这条线上
|
||
const cy = (el) => r(el).top + r(el).height / 2
|
||
const headOneRow = [eye, hex, pin].every((el) =>
|
||
Math.abs(cy(el) - (head.top + head.height / 2)) < 3 &&
|
||
r(el).left >= head.left - 1 && r(el).right <= head.right + 1)
|
||
// 定宽/不浮动验收(v1.20.1):文字工具会多出「底色」tab,
|
||
// 吸管 + 色值 + 图钉这一组**不能跟着 tab 左右浮** —— 用户明确要求「他不浮动」。
|
||
// 所以量「两 tab / 三 tab」两种上下文下的左边界签名,必须逐像素一致;
|
||
// 同时图钉右边缘要贴住头部右边界(整组右对齐的证据)。
|
||
const sig = () => [Math.round(r(eye).left), Math.round(r(hex).left),
|
||
Math.round(r(pin).left), Math.round(r(pin).right)].join(',')
|
||
const sig2 = sig()
|
||
const bgTab = pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]')
|
||
const bgWasHidden = bgTab.hidden
|
||
if (bgWasHidden) bgTab.hidden = false
|
||
const sig3 = sig()
|
||
const rightPinned = Math.abs(r(pin).right - head.right) < 1.5
|
||
// 注意用元素本身读 scrollWidth/clientWidth —— DOMRect 上没有这两个属性,写 head.scrollWidth
|
||
// 会拿到 undefined,比较恒为 false(本次就是这样白跑了两轮)
|
||
const headFitsThreeTabs = headEl.scrollWidth <= headEl.clientWidth + 1 && r(pin).right <= head.right + 1
|
||
const headDbg = {
|
||
client: headEl.clientWidth, scroll: headEl.scrollWidth,
|
||
tabs: [...pop.querySelectorAll('.iwb-color-pop-tab')].map((t) => Math.round(r(t).width)),
|
||
hex: Math.round(r(hex).width), hexLeft: Math.round(r(hex).left),
|
||
popW: Math.round(r(pop).width), headRight: Math.round(head.right),
|
||
sig2, sig3,
|
||
}
|
||
if (bgWasHidden) bgTab.hidden = true
|
||
const row1 = sw.slice(0, 7).map((b) => Math.round(r(b).top))
|
||
const row2 = sw.slice(7).map((b) => Math.round(r(b).top))
|
||
// 「最近」没有历史色时整组(含外层 group)都是 hidden,量不出网格;
|
||
// 这里临时铺满 16 个量完再还原 —— 只解 wrap 的 hidden 不够,外层还压着一层
|
||
const rec = pop.querySelector('.iwb-editor-recent-colors')
|
||
const recGroup = rec.closest('.iwb-color-group')
|
||
const recWasHidden = rec.hidden
|
||
const grpWasHidden = Boolean(recGroup && recGroup.hidden)
|
||
if (recWasHidden) {
|
||
rec.hidden = false
|
||
if (recGroup) recGroup.hidden = false
|
||
rec.innerHTML = '<button class="iwb-editor-color-panel-swatch"></button>'.repeat(16)
|
||
}
|
||
const recRows = new Set([...rec.querySelectorAll('.iwb-editor-color-panel-swatch')]
|
||
.map((b) => Math.round(r(b).top))).size
|
||
const recCols = new Set([...rec.querySelectorAll('.iwb-editor-color-panel-swatch')]
|
||
.map((b) => Math.round(r(b).left))).size
|
||
if (recWasHidden) {
|
||
rec.innerHTML = ''
|
||
rec.hidden = true
|
||
if (grpWasHidden && recGroup) recGroup.hidden = true
|
||
}
|
||
const out = {
|
||
w: Math.round(r(pop).width),
|
||
h: Math.round(r(pop).height),
|
||
headOneRow,
|
||
headRows: [head.top, head.bottom, head.left, head.right].map(Math.round),
|
||
items: [eye, hex, pin].map((el) => [r(el).top, r(el).bottom, r(el).left, r(el).right].map(Math.round)),
|
||
sideInRight: Math.round(side.left) >= Math.round(picker.right),
|
||
noneFirstCell, noneSameSize, noneRow1,
|
||
headFitsThreeTabs, headFixed: sig2 === sig3, rightPinned,
|
||
hexW: Math.round(r(hex).width), headDbg,
|
||
common: sw.length,
|
||
// 8 列 × 2 行:13 个常用色 + 第一格去色 = 16 格,两排各 8
|
||
twoRows: row1.length === 7 && row2.length === 8 &&
|
||
new Set(row1).size === 1 && new Set(row2).size === 1 && row1[0] < row2[0] &&
|
||
grid.children.length === 16,
|
||
cols: new Set(sw.map((b) => Math.round(r(b).left))).size,
|
||
recRows, recCols,
|
||
dividers: [...pop.querySelectorAll('.iwb-color-pop-side > * + *')].map((g) => getComputedStyle(g).borderTopWidth),
|
||
labelsVisible: [...pop.querySelectorAll('.iwb-color-group-label')].filter((l) => l.offsetParent !== null).length,
|
||
swatch: Math.round(r(sw[0]).width),
|
||
}
|
||
return out
|
||
})
|
||
check('色板头部:吸管 + 色值 + 图钉整组右对齐,加「底色」tab 后逐像素不浮动',
|
||
popLayout.headOneRow && popLayout.headFitsThreeTabs && popLayout.headFixed && popLayout.rightPinned,
|
||
JSON.stringify(popLayout.headDbg) + ' rightPinned=' + popLayout.rightPinned)
|
||
check('「去色」是常用色的第一格(20px 同尺寸、第一排最左),不再挂在头部',
|
||
popLayout.noneFirstCell && popLayout.noneSameSize && popLayout.noneRow1,
|
||
JSON.stringify({ first: popLayout.noneFirstCell, size: popLayout.noneSameSize, row: popLayout.noneRow1, sw: popLayout.swatch }))
|
||
check('常用色 8 列 × 2 行(去色 + 15 色 = 16 格),最近色也是 8 列两排,块间 1px 细线且无小标题',
|
||
popLayout.common === 15 && popLayout.twoRows && popLayout.cols === 8 &&
|
||
popLayout.recCols === 8 && popLayout.recRows === 2 &&
|
||
popLayout.labelsVisible === 0 && popLayout.dividers.every((d) => d === '1px'),
|
||
JSON.stringify(popLayout))
|
||
check('色块区在取色器右侧,弹层宽高在预期区间(比 v1.18 的 380×153 宽一档)',
|
||
popLayout.sideInRight && popLayout.w >= 410 && popLayout.w <= 470 && popLayout.h <= 178 &&
|
||
popLayout.swatch === 20,
|
||
'w=' + popLayout.w + ' h=' + popLayout.h + ' swatch=' + popLayout.swatch)
|
||
// 开发用:ANNOT_SHOT=/tmp/pop.png 出一张色板弹层截图(验证布局)
|
||
if (process.env.ANNOT_SHOT) await page.locator('.iwb-editor-color-pop').screenshot({ path: process.env.ANNOT_SHOT })
|
||
|
||
const pinBtn = page.locator('.iwb-editor-color-pop [data-action="pinColorPop"]')
|
||
await pinBtn.click()
|
||
await page.waitForTimeout(90)
|
||
await page.mouse.click(imgBox.x + imgBox.width * 0.5, imgBox.y + imgBox.height * 0.5)
|
||
await page.waitForTimeout(140)
|
||
const pinned = await page.evaluate(() => ({
|
||
open: !document.querySelector('.iwb-editor-color-pop').hidden,
|
||
active: document.querySelector('.iwb-editor-color-pop [data-action="pinColorPop"]').classList.contains('active'),
|
||
saved: window.__settings.colorPopPinned === true,
|
||
}))
|
||
check('钉住后点画布不收起,状态写进宿主 settings(下次打开仍钉着)',
|
||
pinned.open && pinned.active && pinned.saved, JSON.stringify(pinned))
|
||
|
||
await pinBtn.click()
|
||
await page.waitForTimeout(70)
|
||
await page.mouse.click(imgBox.x + imgBox.width * 0.35, imgBox.y + imgBox.height * 0.4)
|
||
await page.waitForTimeout(140)
|
||
const unpinned = await page.evaluate(() => ({
|
||
open: !document.querySelector('.iwb-editor-color-pop').hidden,
|
||
saved: window.__settings.colorPopPinned,
|
||
active: document.querySelector('.iwb-editor-color-pop [data-action="pinColorPop"]').classList.contains('active'),
|
||
}))
|
||
check('取消钉住后点画布立即收起(状态回到 false)',
|
||
!unpinned.open && unpinned.saved === false && !unpinned.active, JSON.stringify(unpinned))
|
||
|
||
const drag = async (x1, y1, x2, y2) => {
|
||
await page.mouse.move(x1, y1)
|
||
await page.mouse.down()
|
||
await page.mouse.move(x2, y2, { steps: 8 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(120)
|
||
}
|
||
|
||
// ---------- P1 选区 ----------
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await drag(imgBox.x + imgBox.width * 0.25, imgBox.y + imgBox.height * 0.25,
|
||
imgBox.x + imgBox.width * 0.7, imgBox.y + imgBox.height * 0.7)
|
||
const sel = (await dbg()).selection
|
||
check('拖出矩形选区 + 蚂蚁线启动', Boolean(sel && sel.w > 5 && sel.h > 5) && (await dbg()).ants, JSON.stringify(sel))
|
||
check('选区浮动操作条自动出现', await page.locator('.iwb-editor-sel-bar').isVisible())
|
||
const cx = Math.round(sel.x + sel.w / 2)
|
||
const cy = Math.round(sel.y + sel.h / 2)
|
||
const beforeFill = await pixel(cx, cy)
|
||
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click()
|
||
const afterFill = await pixel(cx, cy)
|
||
check('填充只写当前层(base 像素不变)',
|
||
afterFill.draw && afterFill.draw[3] > 0 && JSON.stringify(afterFill.base) === JSON.stringify(beforeFill.base),
|
||
'draw=' + JSON.stringify(afterFill.draw) + ' base=' + JSON.stringify(afterFill.base))
|
||
check('原图锁定时填充自动落「标注」层(不写进原图)',
|
||
(await dbg()).layers.some(l => l.id === 'draw' && l.name.indexOf('标注') === 0),
|
||
JSON.stringify((await dbg()).layers.map(l => l.name)))
|
||
|
||
const layersBeforeCopy = (await dbg()).layers.length
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.copy"]').click()
|
||
const afterCopy = await dbg()
|
||
check('复制为新层:像素落在选区原位、原层不变',
|
||
afterCopy.layers.length === layersBeforeCopy + 1 && (await pixel(cx, cy)).draw[3] > 0,
|
||
'层数 ' + layersBeforeCopy + ' → ' + afterCopy.layers.length)
|
||
check('复制来源为当前层:新层有填充像素', afterCopy.layers.some(l => l.name === '选区副本') &&
|
||
(await pixel(cx, cy)).layers.some(v => v.id !== 'base' && v.id !== 'draw' && v.a && v.a[3] > 0))
|
||
await page.keyboard.press('Control+z')
|
||
check('Ctrl+Z 撤销「复制为新层」(图层数可回退)', (await dbg()).layers.length === layersBeforeCopy, '层数=' + (await dbg()).layers.length)
|
||
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.delete"]').click()
|
||
const afterDelete = await pixel(cx, cy)
|
||
check('Delete 只清当前层:draw 挖空、base 与其它层原样',
|
||
afterDelete.draw[3] === 0 && JSON.stringify(afterDelete.base) === JSON.stringify(beforeFill.base),
|
||
'draw=' + JSON.stringify(afterDelete.draw) + ' base=' + JSON.stringify(afterDelete.base))
|
||
await page.keyboard.press('Control+z')
|
||
check('Ctrl+Z 恢复被清除的像素', (await pixel(cx, cy)).draw[3] > 0)
|
||
|
||
// 三入口共用命令层
|
||
await page.keyboard.press('Control+j')
|
||
const afterHotkey = await dbg()
|
||
check('快捷键 Ctrl+J 与浮动条共用 execute()',
|
||
afterHotkey.layers.length === layersBeforeCopy + 1 && afterHotkey.historyLabels.includes('复制为新层'),
|
||
'labels=' + JSON.stringify(afterHotkey.historyLabels.slice(-3)))
|
||
await page.keyboard.press('Control+z')
|
||
|
||
await page.mouse.click(imgBox.x + imgBox.width * 0.8, imgBox.y + imgBox.height * 0.2, { button: 'right' })
|
||
check('右键菜单复用同一条操作条', await page.locator('.iwb-editor-sel-bar.as-menu').count() === 1)
|
||
|
||
// ---------- 还原原图(用户裁定:全部还原 + 可撤销) ----------
|
||
await page.keyboard.press('Control+a') // 重建选区(右键/工具切换不会改像素)
|
||
await page.keyboard.press('Control+j') // 制造一个额外的选区副本层
|
||
const beforeReset = await dbg()
|
||
await page.locator('[data-action="reset"]').click()
|
||
const afterReset = await dbg()
|
||
check('还原原图:只剩「原图」单层(默认不再预建画笔层)',
|
||
afterReset.layers.length === 1 && afterReset.layers.some(l => l.id === 'base'),
|
||
JSON.stringify(afterReset.layers.map(l => l.name)))
|
||
check('还原原图清空矢量/选区但保留 base 像素',
|
||
!afterReset.selection && JSON.stringify((await pixel(cx, cy)).base) === JSON.stringify(beforeFill.base))
|
||
await page.keyboard.press('Control+z')
|
||
const afterUndoReset = await dbg()
|
||
check('Ctrl+Z 完整恢复还原前的图层结构(含被删的选区副本层)',
|
||
beforeReset.layers.length === 3 && afterUndoReset.layers.length === beforeReset.layers.length,
|
||
'还原前 ' + beforeReset.layers.length + ' → 还原后 ' + afterReset.layers.length + ' → 撤销后 ' + afterUndoReset.layers.length)
|
||
|
||
// ---------- 单张输出预设(≤500KB) ----------
|
||
await page.locator('[data-action="toggleExportSettings"]').click()
|
||
await page.locator('[data-export-key="preset"][data-export-value="ecom800"]').click()
|
||
const opt = (await dbg()).exportOptions
|
||
check('≤500KB 预设可切换并存 ctx.settings', opt.preset === 'ecom800' && opt.maxKB === 500 &&
|
||
(await page.evaluate(() => window.__settings.exportPreset)) === 'ecom800', JSON.stringify(opt))
|
||
await page.locator('[data-action="download"]').click()
|
||
const exported = await poll(async () => (await dbg()).lastExport)
|
||
check('下载只产一个结果:800×800 且 ≤500KB、编辑器不关闭',
|
||
Boolean(exported && exported.width === 800 && exported.height === 800 && exported.bytes <= 500 * 1024 &&
|
||
await page.locator('#iwb-editor-overlay').isVisible()), JSON.stringify(exported))
|
||
// 输出面板的可见性/文案探针:面板收起时子元素 display 不在布局里,
|
||
// 所以统一读 textContent 而不是 innerText(后者对隐藏元素返回空串)。
|
||
const summaryText = () => page.locator('.iwb-editor-export-summary').textContent()
|
||
const noteText = () => page.locator('.iwb-editor-export-note').textContent()
|
||
const ecomRowsVisible = () => page.evaluate(() => {
|
||
const rows = Array.from(document.querySelectorAll('[data-export-when="ecom800"]'))
|
||
return rows.length >= 2 && rows.every(r => !r.hidden)
|
||
})
|
||
|
||
check('电商预设:摘要写明尺寸/格式/背景/体积上限',
|
||
/800×800/.test(await summaryText()) && /≤500KB/.test(await summaryText()) && /透明/.test(await summaryText()),
|
||
await summaryText())
|
||
await page.locator('[data-action="toggleExportSettings"]').click() // 上一步点「下载」会自动收起面板
|
||
check('电商预设:边长与体积控件可见', await ecomRowsVisible())
|
||
|
||
await page.locator('[data-export-key="format"][data-export-value="jpeg"]').click()
|
||
const afterJpg = await dbg()
|
||
check('选 JPG:背景自动收敛为白底并写回 settings(不再「显示透明、实际白底」)',
|
||
afterJpg.exportOptions.bg === 'white' &&
|
||
(await page.evaluate(() => window.__settings.exportBg)) === 'white' &&
|
||
(await page.locator('[data-export-key="bg"][data-export-value="transparent"]').isDisabled()) === true,
|
||
JSON.stringify(afterJpg.exportOptions))
|
||
check('JPG 摘要显示白底', /白底/.test(await summaryText()), await summaryText())
|
||
await page.locator('[data-action="download"]').click()
|
||
const jpg = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.format === 'jpeg' ? d.lastExport : false })
|
||
check('格式/背景切换生效(JPG + 白底)', Boolean(jpg) && jpg.bg === 'white', JSON.stringify(jpg))
|
||
check('下载后摘要记录上次输出(尺寸 + 体积)',
|
||
/上次输出 800×800/.test(await noteText()), await noteText())
|
||
|
||
// 边长 / 体积上限:原来只有计算没有控件,改完必须能真的改到并生效
|
||
await page.locator('[data-action="toggleExportSettings"]').click()
|
||
await page.locator('[data-export-key="size"][data-export-value="1000"]').click()
|
||
await page.locator('[data-export-key="maxKB"][data-export-value="300"]').click()
|
||
const optSized = (await dbg()).exportOptions
|
||
check('边长/体积控件可改并持久化到 ctx.settings',
|
||
optSized.size === 1000 && optSized.maxKB === 300 &&
|
||
(await page.evaluate(() => window.__settings.exportSize)) === 1000 &&
|
||
(await page.evaluate(() => window.__settings.exportMaxKB)) === 300, JSON.stringify(optSized))
|
||
await page.locator('[data-action="download"]').click()
|
||
const sized = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.width === 1000 ? d.lastExport : false })
|
||
check('边长生效:输出 1000×1000 且体积 ≤300KB',
|
||
Boolean(sized) && sized.width === 1000 && sized.bytes <= 300 * 1024, JSON.stringify(sized))
|
||
|
||
await page.locator('[data-action="toggleExportSettings"]').click()
|
||
await page.locator('[data-export-key="preset"][data-export-value="original"]').click()
|
||
const optOriginal = (await dbg()).exportOptions
|
||
check('切回原尺寸:maxKB 归零并写回 settings(重开不会让限制「复活」)',
|
||
optOriginal.preset === 'original' && optOriginal.maxKB === 0 &&
|
||
(await page.evaluate(() => window.__settings.exportMaxKB)) === 0, JSON.stringify(optOriginal))
|
||
check('原尺寸下边长/体积控件隐藏', (await ecomRowsVisible()) === false)
|
||
check('原尺寸摘要显示实际像素尺寸', /原尺寸 96×64/.test(await summaryText()), await summaryText())
|
||
await page.locator('[data-action="toggleExportSettings"]').click() // 收起,恢复后续用例的初始态
|
||
|
||
// ---------- 选区与裁剪互斥 ----------
|
||
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
|
||
check('切到裁剪会清掉选区,裁剪参数出现在选项栏(不再有画布下方浮窗)',
|
||
!(await dbg()).selection &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-action="confirmCrop"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-ratio="1:1"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-crop-bar').count()) === 0)
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
check('切回选区:裁剪控件从选项栏消失、裁剪框取消',
|
||
await page.evaluate(() => !document.querySelector('[data-action="confirmCrop"]')))
|
||
|
||
// ---------- 回归:矢量对象经撤销/重做后仍可渲染(快照不得把 DOM 画布序列化成 {}) ----------
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await drag(imgBox.x + imgBox.width * 0.2, imgBox.y + imgBox.height * 0.2,
|
||
imgBox.x + imgBox.width * 0.45, imgBox.y + imgBox.height * 0.45)
|
||
await page.keyboard.press('Control+z')
|
||
await page.keyboard.press('Control+Shift+z')
|
||
check('矢量对象撤销/重做后画布正常重建', await page.evaluate(() =>
|
||
document.querySelectorAll('.iwb-editor-vec-canvas').length >= 1))
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
|
||
// ---------- 旧流程回归:粘贴一步落层 + 覆盖写回 ----------
|
||
const beforePaste = (await dbg()).layers.length
|
||
await page.evaluate((png) => {
|
||
const bin = atob(png.split(',')[1])
|
||
const bytes = new Uint8Array(bin.length)
|
||
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i)
|
||
const dt = new DataTransfer()
|
||
dt.items.add(new File([bytes], 'paste.png', { type: 'image/png' }))
|
||
document.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }))
|
||
}, PNG)
|
||
const pasted = await poll(async () => (await dbg()).layers.length === beforePaste + 1)
|
||
check('粘贴图片一步落层(不再需要 Enter 确认)', Boolean(pasted), '层数 ' + beforePaste + ' → ' + (await dbg()).layers.length)
|
||
await page.keyboard.press('Enter')
|
||
check('粘贴后按 Enter 不会重复落层', (await dbg()).layers.length === beforePaste + 1)
|
||
|
||
await page.locator('[data-action="replace"]').click()
|
||
const wrote = await poll(async () => page.evaluate(() => window.__writes.some(w => w.kind === 'replace')))
|
||
check('覆盖仍回写宿主节点并关闭编辑器', Boolean(wrote) &&
|
||
(await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false, JSON.stringify(await page.evaluate(() => window.__writes)))
|
||
|
||
// ---------- Round 2:P1 缺陷回归(新会话,逐条对应已确认缺陷) ----------
|
||
// 走 glue 的 openEditor:只有它能把「退出」与宿主 Promise 的结算连起来验证。
|
||
await page.evaluate(() => {
|
||
window.__openState = null
|
||
window.__commands['annotate-selected'].run().then(
|
||
(mode) => { window.__openState = { mode: String(mode) } },
|
||
(err) => { window.__openState = { error: String((err && err.message) || err) } }
|
||
)
|
||
})
|
||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
||
await page.waitForFunction(() => window.__iwbEditor.__debug().open === true)
|
||
const box2 = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||
const drag2 = async (x1, y1, x2, y2) => {
|
||
await page.mouse.move(x1, y1)
|
||
await page.mouse.down()
|
||
await page.mouse.move(x2, y2, { steps: 8 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(120)
|
||
}
|
||
|
||
// ---- Fix1:反选后 Delete / 复制必须作用整幅(与填充一致) ----
|
||
await page.keyboard.press('Control+a')
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click()
|
||
const fullFill = await pixel(6, 6)
|
||
check('Fix1 前置:全选填充整层', fullFill.draw[3] > 0)
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3,
|
||
box2.x + box2.width * 0.6, box2.y + box2.height * 0.6)
|
||
const sel2 = (await dbg()).selection
|
||
const cx2 = Math.round(sel2.x + sel2.w / 2)
|
||
const cy2 = Math.round(sel2.y + sel2.h / 2)
|
||
await page.keyboard.press('Control+Shift+i')
|
||
const inv = (await dbg()).selection
|
||
check('反选:标记 inverted 且蚂蚁线仍在', Boolean(inv && inv.inverted) && (await dbg()).ants, JSON.stringify(inv))
|
||
await page.keyboard.press('Delete')
|
||
const invKeep = await pixel(cx2, cy2)
|
||
const invGone = await pixel(6, 6)
|
||
check('反选 + Delete:原选区内保留、原选区外挖空、base 不变',
|
||
invGone.draw[3] === 0 && invKeep.draw[3] > 0 && JSON.stringify(invGone.base) === JSON.stringify(fullFill.base),
|
||
'inside=' + JSON.stringify(invKeep.draw) + ' outside=' + JSON.stringify(invGone.draw))
|
||
await page.keyboard.press('Control+z')
|
||
check('反选 + Delete 可 Ctrl+Z 回退(掩膜 tile 边界未偏移)', (await pixel(6, 6)).draw[3] > 0)
|
||
|
||
const layersBeforeInvCopy = (await dbg()).layers.length
|
||
await page.keyboard.press('Control+j')
|
||
const afterInvCopy = await dbg()
|
||
const invCopyLayer = afterInvCopy.layers[afterInvCopy.layers.length - 1]
|
||
const copyOutside = await pixel(6, 6)
|
||
const copyInside = await pixel(cx2, cy2)
|
||
const copyOutsidePx = copyOutside.layers.find(v => v.id === invCopyLayer.id).a
|
||
const copyInsidePx = copyInside.layers.find(v => v.id === invCopyLayer.id).a
|
||
check('反选 + Ctrl+J:新层只含原选区外像素,且与原层逐点对齐(不偏移)',
|
||
afterInvCopy.layers.length === layersBeforeInvCopy + 1 && invCopyLayer.name === '选区副本' &&
|
||
copyOutsidePx[3] > 0 && copyOutsidePx.join(',') === copyOutside.draw.join(',') && copyInsidePx[3] === 0,
|
||
'outside=' + JSON.stringify(copyOutsidePx) + ' draw=' + JSON.stringify(copyOutside.draw) + ' inside=' + JSON.stringify(copyInsidePx))
|
||
await page.keyboard.press('Control+z') // 撤销复制新层
|
||
await page.keyboard.press('Control+d') // 取消选区
|
||
|
||
// feather>0:整幅 tile 不能把羽化边界变成硬切
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('6')
|
||
await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3,
|
||
box2.x + box2.width * 0.6, box2.y + box2.height * 0.6)
|
||
const selF = (await dbg()).selection
|
||
await page.keyboard.press('Control+Shift+i')
|
||
const afterInvert = await dbg()
|
||
await page.keyboard.press('Delete')
|
||
const afterDel = await dbg()
|
||
const edgeAlphas = []
|
||
for (let dx = -6; dx <= 6; dx++) {
|
||
edgeAlphas.push((await pixel(Math.round(selF.x) + dx, Math.round(selF.y + selF.h / 2))).draw[3])
|
||
}
|
||
const edgeDbg = await dbg()
|
||
check('反选 + 羽化 6px:边界仍是渐变(羽化未因整幅掩膜失效)',
|
||
selF.feather === 6 && edgeAlphas.some(a => a > 0 && a < 255),
|
||
JSON.stringify(edgeAlphas) + ' feather=' + selF.feather + ' active=' + edgeDbg.activeLayerId +
|
||
' inv=' + (afterInvert.selection && afterInvert.selection.inverted) +
|
||
' hist=' + afterDel.historyLabels.slice(-2).join('/') +
|
||
' sel=' + JSON.stringify(afterDel.selection))
|
||
await page.keyboard.press('Control+z')
|
||
await page.keyboard.press('Control+d')
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('0')
|
||
|
||
// ---- Fix3:选中形状时建立像素选区,Delete 语义必须切到「清像素」 ----
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await drag2(box2.x + box2.width * 0.35, box2.y + box2.height * 0.35,
|
||
box2.x + box2.width * 0.65, box2.y + box2.height * 0.65)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click(box2.x + box2.width * 0.5, box2.y + box2.height * 0.5)
|
||
const shapeSelected = await dbg()
|
||
check('前置:形状已绘制并处于选中态',
|
||
shapeSelected.shapes.length === 1 && shapeSelected.selectedShapeId === shapeSelected.shapes[0].id,
|
||
JSON.stringify(shapeSelected.shapes))
|
||
await page.keyboard.press('Control+a')
|
||
const selAllShape = (await dbg()).selection
|
||
await page.keyboard.press('Delete')
|
||
const afterShapeDelete = await dbg()
|
||
const shapeDeletePixel = await pixel(cx2, cy2)
|
||
check('选中形状 → Ctrl+A → Delete ⇒ 形状仍在、当前层像素被清(全选语义)',
|
||
Boolean(selAllShape && selAllShape.w >= 96 && selAllShape.h >= 64) &&
|
||
afterShapeDelete.shapes.length === 1 && afterShapeDelete.selectedShapeId === null &&
|
||
shapeDeletePixel.draw[3] === 0,
|
||
'shapes=' + afterShapeDelete.shapes.length + ' draw=' + JSON.stringify(shapeDeletePixel.draw))
|
||
await page.keyboard.press('Control+z')
|
||
await page.keyboard.press('Control+d')
|
||
|
||
// ---- Fix2:裁剪与选区互斥(快捷键 / 顶栏全选图标 / 右键菜单三入口) + confirmCrop 清残留 ----
|
||
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
|
||
const cropStart = await dbg()
|
||
check('切到裁剪:旧选区被清、蚂蚁线停止', cropStart.selection === null && cropStart.ants === false)
|
||
await page.keyboard.press('Control+a')
|
||
const cropAfterA = await dbg()
|
||
check('裁剪中 Ctrl+A:不建选区、不启动蚂蚁线、浮动条不出现',
|
||
cropAfterA.selection === null && cropAfterA.ants === false &&
|
||
(await page.locator('.iwb-editor-sel-bar').isVisible()) === false)
|
||
check('裁剪模式下选项栏没有选区命令入口(selcmd 只属于选择工具)',
|
||
(await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()) === 0)
|
||
await page.mouse.click(box2.x + box2.width * 0.5, box2.y + box2.height * 0.5, { button: 'right' })
|
||
const menuShown = await page.locator('.iwb-editor-sel-bar.as-menu').count()
|
||
await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.all"]').click()
|
||
const cropAfterCtx = await dbg()
|
||
check('裁剪中右键菜单「全选」同样被拦',
|
||
menuShown === 1 && cropAfterCtx.selection === null && cropAfterCtx.ants === false)
|
||
|
||
await drag2(box2.x + box2.width * 0.1, box2.y + box2.height * 0.1,
|
||
box2.x + box2.width * 0.7, box2.y + box2.height * 0.7)
|
||
check('裁剪框可拉出(确认按钮可见)', await page.locator('[data-action="confirmCrop"]').isVisible())
|
||
await page.locator('[data-action="confirmCrop"]').click()
|
||
const cropped = await dbg()
|
||
check('确认裁剪:尺寸更新且无旧坐标系选区/蚂蚁线残留',
|
||
cropped.doc.w < 96 && cropped.doc.h < 64 && cropped.selection === null && cropped.ants === false,
|
||
JSON.stringify(cropped.doc))
|
||
await page.keyboard.press('Delete')
|
||
const afterCropDelete = await dbg()
|
||
check('裁剪后 Delete 不按旧 bbox 误擦(层数不变、底图仍有像素)',
|
||
afterCropDelete.layers.length === cropped.layers.length && (await pixel(5, 5)).base[3] > 0 &&
|
||
afterCropDelete.selection === null)
|
||
|
||
// ---- 裁剪进历史链(v1.2 非破坏性):可撤销、可重做、不 flatten ----
|
||
const cropLayers = cropped.layers.map(l => l.id)
|
||
await page.keyboard.press('Control+z')
|
||
const undoneCrop = await dbg()
|
||
check('裁剪可 Ctrl+Z:画布尺寸与图层结构都回到裁剪前',
|
||
undoneCrop.doc.w === 96 && undoneCrop.doc.h === 64 &&
|
||
undoneCrop.layers.length === cropLayers.length &&
|
||
cropLayers.every(id => undoneCrop.layers.some(l => l.id === id)),
|
||
'doc=' + JSON.stringify(undoneCrop.doc) + ' layers=' + undoneCrop.layers.map(l => l.id).join(','))
|
||
check('裁剪撤销后底图像素完整回填', (await pixel(5, 5)).base[3] > 0)
|
||
await page.keyboard.press('Control+Shift+z')
|
||
const redoneCrop = await dbg()
|
||
check('裁剪可重做:尺寸回到裁剪后',
|
||
redoneCrop.doc.w === cropped.doc.w && redoneCrop.doc.h === cropped.doc.h,
|
||
JSON.stringify(redoneCrop.doc))
|
||
|
||
// ---- 还原原图的「尺寸复位」分支:必须走统一重绘,摘要/蚂蚁线才跟着走 ----
|
||
// (该分支会 setupCanvas + 清历史,此前只调 updateAllUI,摘要停留在裁剪后尺寸)
|
||
const cropSummary = await summaryText()
|
||
await page.locator('[data-action="reset"]').click()
|
||
const restoredDoc = await dbg()
|
||
const restoredSummary = await summaryText()
|
||
check('还原原图复位尺寸后:输出摘要即时跟随(不停留在裁剪后尺寸)',
|
||
restoredDoc.doc.w === 96 && restoredDoc.doc.h === 64 &&
|
||
/原尺寸 96×64/.test(restoredSummary) && cropSummary !== restoredSummary,
|
||
cropSummary + ' → ' + restoredSummary)
|
||
check('还原原图复位尺寸后蚂蚁线已停、选区已清',
|
||
restoredDoc.ants === false && !restoredDoc.selection)
|
||
|
||
// ---- v1.2 选项栏:按工具出参数,形状线宽与画笔解耦 ----
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
check('画笔选项栏:大小 / 硬度 / 透明三个参数都在',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="brushSize"]').count()) >= 2 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="brushHardness"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="brushOpacity"]').count()) === 1)
|
||
const brushSizeBefore = (await dbg()).toolOptions.brushSize
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
check('矩形选项栏:线宽 + 描边/实心',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="shapeLineWidth"]').count()) >= 2 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"]').count()) === 1)
|
||
await page.locator('.iwb-editor-optionbar-body input[type="number"][data-opt="shapeLineWidth"]').fill('12')
|
||
const optAfterLw = (await dbg()).toolOptions
|
||
check('选项栏改线宽:只改形状线宽,画笔大小不受影响(已解耦)',
|
||
optAfterLw.shapeLineWidth === 12 && optAfterLw.brushSize === brushSizeBefore,
|
||
JSON.stringify(optAfterLw))
|
||
const shapesBefore = (await dbg()).shapes.length
|
||
const liveBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||
await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2,
|
||
liveBox.x + liveBox.width * 0.5, liveBox.y + liveBox.height * 0.5)
|
||
const shapesAfter = (await dbg()).shapes
|
||
check('新画的矩形直接用选项栏里的线宽 12',
|
||
shapesAfter.length === shapesBefore + 1 && shapesAfter[shapesAfter.length - 1].lw === 12,
|
||
JSON.stringify(shapesAfter.slice(-1)))
|
||
await page.keyboard.press('Control+z')
|
||
|
||
// isTyping 修正:参数数字框里按 Ctrl+A / Delete 应该走画布命令,而不是被当打字吞掉
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await page.locator('.iwb-editor-optionbar-body input[data-opt="feather"]').fill('3')
|
||
await page.keyboard.press('Control+a')
|
||
const selAfterCtrlA = await dbg()
|
||
check('参数数字框里按 Ctrl+A 仍能全选(不再被当打字吞掉)',
|
||
Boolean(selAfterCtrlA.selection) &&
|
||
selAfterCtrlA.selection.w === selAfterCtrlA.doc.w && selAfterCtrlA.selection.h === selAfterCtrlA.doc.h,
|
||
JSON.stringify(selAfterCtrlA.selection))
|
||
await page.keyboard.press('Control+d')
|
||
|
||
// ---- v1.2.2:手柄只在选择工具出现 / 高亮跟随绘制目标 / 选项栏快捷点 / 侧栏实心移除 ----
|
||
|
||
// 侧栏「实心」按钮移除(选项栏 rect 工具已有描边/实心切换)
|
||
check('侧栏「实心」按钮已移除(选项栏承担该功能)',
|
||
(await page.locator('[data-action="toggleFill"]').count()) === 0)
|
||
|
||
// 快捷点:画笔大小
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
check('画笔选项栏有 4 个大小快捷点(16/24/32 已按用户裁定移除)',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-preset="brushSize"]').count()) === 4)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-preset="brushSize"][data-value="12"]').click()
|
||
check('点快捷点 12:笔刷大小即时生效且选项栏数字框同步',
|
||
(await dbg()).toolOptions.brushSize === 12 &&
|
||
await page.evaluate(() => {
|
||
const n = document.querySelector('.iwb-editor-optionbar-body input[type="number"][data-opt="brushSize"]')
|
||
return n && Number(n.value) === 12
|
||
}))
|
||
|
||
// 快捷点:矢量描边
|
||
await page.locator('.iwb-editor-tool[data-tool="arrow"]').click()
|
||
check('箭头选项栏有 7 个线宽快捷点',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-preset="shapeLineWidth"]').count()) === 7)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-preset="shapeLineWidth"][data-value="6"]').click()
|
||
check('点线宽快捷点 6:shapeLineWidth 即时生效',
|
||
(await dbg()).toolOptions.shapeLineWidth === 6)
|
||
|
||
// 高亮跟随绘制目标:画一笔后面板选中层 == 画笔目标层
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.75,
|
||
liveBox.x + liveBox.width * 0.65, liveBox.y + liveBox.height * 0.85)
|
||
const syncDbg = await dbg()
|
||
check('画笔落笔后面板高亮层 == 绘制目标层(不再「没选中却能画」)',
|
||
syncDbg.selectedLayerId === syncDbg.activeLayerId,
|
||
'selected=' + syncDbg.selectedLayerId + ' active=' + syncDbg.activeLayerId)
|
||
|
||
// 变换手柄只在 select 工具出现:画笔态 overlay 无手柄像素,切到选择工具后出现
|
||
const overlayAlpha = () => page.evaluate(() => {
|
||
const c = document.querySelector('.iwb-editor-crop-overlay')
|
||
if (!c) return -1
|
||
const cx = c.getContext('2d')
|
||
const d = cx.getImageData(0, 0, c.width, c.height).data
|
||
let n = 0
|
||
for (let i = 3; i < d.length; i += 4) if (d[i] > 0) n++
|
||
return n
|
||
})
|
||
check('画笔工具下选中层不画变换手柄(overlay 干净)', (await overlayAlpha()) === 0)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
check('切到选择工具后变换框/手柄出现(overlay 有像素)', (await overlayAlpha()) > 0)
|
||
await page.keyboard.press('Escape') // 清选中,避免影响后续
|
||
|
||
// 裁剪:Esc 取消 / Enter 确认
|
||
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.15,
|
||
liveBox.x + liveBox.width * 0.6, liveBox.y + liveBox.height * 0.6)
|
||
check('拉出裁剪框后选项栏显示尺寸摘要',
|
||
(await page.locator('.iwb-editor-optionbar-body .iwb-editor-crop-info').textContent()) !== '--')
|
||
await page.keyboard.press('Escape')
|
||
check('Esc 取消裁剪(摘要复位为 --)',
|
||
(await page.locator('.iwb-editor-optionbar-body .iwb-editor-crop-info').textContent()) === '--')
|
||
await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.15,
|
||
liveBox.x + liveBox.width * 0.6, liveBox.y + liveBox.height * 0.6)
|
||
const docBeforeEnter = (await dbg()).doc
|
||
await page.keyboard.press('Enter')
|
||
const docAfterEnter = (await dbg()).doc
|
||
check('Enter 确认裁剪(画布尺寸变小、与按钮确认等效)',
|
||
docAfterEnter.w < docBeforeEnter.w && docAfterEnter.h < docBeforeEnter.h,
|
||
JSON.stringify(docBeforeEnter) + ' → ' + JSON.stringify(docAfterEnter))
|
||
await page.keyboard.press('Control+z')
|
||
|
||
// ---- v1.2.8:底部浮动工具栏(Figma 风格,用户裁定 2026-11-04) ----
|
||
check('工具栏移入画布容器、横排悬浮底部居中(不再在顶栏)', await page.evaluate(() => {
|
||
const wrap = document.querySelector('.iwb-editor-canvas-wrap')
|
||
const tools = wrap && wrap.querySelector(':scope > .iwb-editor-tools')
|
||
if (!tools) return false
|
||
const w = tools.getBoundingClientRect(), c = wrap.getBoundingClientRect()
|
||
return w.height < w.width &&
|
||
Math.abs((w.left + w.right) / 2 - (c.left + c.right) / 2) <= 8 &&
|
||
c.bottom - w.bottom <= 30 &&
|
||
!document.querySelector('.iwb-editor-header > .iwb-editor-tools')
|
||
}))
|
||
check('适应窗口后图片底边不被工具条遮挡', await page.evaluate(() => {
|
||
const img = document.querySelector('.iwb-editor-layer-canvas')
|
||
const tools = document.querySelector('.iwb-editor-canvas-wrap > .iwb-editor-tools')
|
||
if (!img || !tools) return false
|
||
const i = img.getBoundingClientRect(), t = tools.getBoundingClientRect()
|
||
return i.bottom <= t.top + 2
|
||
}))
|
||
|
||
// ---- v1.2.3:橡皮修复 / 钢笔描边实心 / 顶栏输出组右置 ----
|
||
|
||
// 顶栏输出组(输出+下载+新建+覆盖+退出)贴最右(header 右内边距 12px)
|
||
check('顶栏输出/导出按钮组贴最右侧(用户裁定 2026-11-04)', await page.evaluate(() => {
|
||
const hdr = document.querySelector('.iwb-editor-header')
|
||
const ex = document.querySelector('.iwb-editor-header > .iwb-editor-export-actions')
|
||
if (!hdr || !ex) return false
|
||
const h = hdr.getBoundingClientRect(), e = ex.getBoundingClientRect()
|
||
return h.right - e.right <= 14
|
||
}))
|
||
|
||
// 橡皮:1.2.2 回归 —— events.js 少 import getActiveLayer,一按下就 ReferenceError,表现为「橡皮不能擦」
|
||
// 注意 pixel() 探针要的是图片坐标,不是屏幕坐标:liveBox 上的比例 = 图片上的比例
|
||
const IMG = { x: Math.round((await dbg()).doc.w * 0.42), y: Math.round((await dbg()).doc.h * 0.5) }
|
||
const probe = (id) => page.evaluate(({ id, x, y }) => window.__iwbEditor.__debug().pixel(id, x, y), { id, x: IMG.x, y: IMG.y })
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
|
||
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
|
||
const stampLayerId = (await dbg()).activeLayerId
|
||
const stampPx = await probe(stampLayerId)
|
||
const stampBasePx = await probe('base')
|
||
check('画笔落笔自动落「标注」层且该点有像素', stampPx && stampPx[3] > 0,
|
||
'layer=' + stampLayerId + ' px=' + JSON.stringify(stampPx))
|
||
// 回归(2026-11-04 用户反馈):首笔自动建层时新 canvas 没套视图样式,
|
||
// 以原始像素尺寸贴在 stack 原点 → 第一笔显示错位,滚轮缩放后才正常
|
||
check('首笔自动建的层立刻获得视图样式(尺寸/偏移与原图层一致,不再裸贴原点)', await page.evaluate((baseId) => {
|
||
const cs = Array.from(document.querySelectorAll('.iwb-editor-layer-canvas'))
|
||
const base = cs.find(c => c.style.width && parseFloat(c.style.left) > 0)
|
||
const fresh = cs[cs.length - 1]
|
||
return base && fresh && fresh.style.width === base.style.width &&
|
||
fresh.style.left === base.style.left && fresh.style.top === base.style.top
|
||
}, stampLayerId))
|
||
await page.locator('.iwb-editor-tool[data-tool="eraser"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
|
||
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
|
||
const erasedPx = await probe(stampLayerId)
|
||
const basePxAfterErase = await probe('base')
|
||
check('橡皮沿同一笔迹擦除(不抛错、目标层挖空、base 原样)',
|
||
erasedPx && erasedPx[3] === 0 && JSON.stringify(basePxAfterErase) === JSON.stringify(stampBasePx),
|
||
'erased=' + JSON.stringify(erasedPx))
|
||
await page.keyboard.press('Control+z')
|
||
|
||
// 钢笔描边/实心切换(penFill 默认实心,只对闭合路径生效)
|
||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||
check('钢笔选项栏有 描边/实心 切换',
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"]').count()) === 2)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="pen"]').click()
|
||
const penFillOff = (await dbg()).toolOptions.penFill === false
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="pen"]').click()
|
||
check('钢笔样式切换写回 penFill(默认实心 → 描边 → 实心)',
|
||
penFillOff && (await dbg()).toolOptions.penFill === true)
|
||
|
||
// 橡皮兜底:只剩锁定的原图时用橡皮 → 明确提示而不是无声失败
|
||
await page.locator('[data-action="reset"]').click()
|
||
const layersAfterReset = (await dbg()).layers.length
|
||
await page.locator('.iwb-editor-tool[data-tool="eraser"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.5,
|
||
liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.5)
|
||
const toastText = await page.locator('.iwb-editor-toast').textContent()
|
||
check('原图锁定且无标注层时用橡皮:提示「先画再擦」且不建层',
|
||
layersAfterReset === 1 && (await dbg()).layers.length === 1 && toastText.indexOf('可擦') >= 0,
|
||
'layers=' + layersAfterReset + ' toast=' + toastText)
|
||
await page.keyboard.press('Control+z') // 撤销还原,恢复图层结构
|
||
|
||
// ---- v1.2.4:顶栏命令带(「更多」图标化)/ 选择工具就地改形状参数 ----
|
||
|
||
// v1.13 用户裁定:顶栏四个「置顶/上移/下移/置底」删掉(图层面板可拖 + Ctrl+]/[ 已覆盖),
|
||
// 「适应窗口 / 收起侧栏」搬到画布底部工具栏的最右侧。
|
||
check('顶栏不再有图层层级按钮;视图快捷搬到画布工具栏最右;图层新建/导入/合并仍在面板标题栏', await page.evaluate(() => {
|
||
const q = (s) => Boolean(document.querySelector(s))
|
||
const hdrLayerBtns = document.querySelectorAll('.iwb-editor-header .iwb-editor-layer-btn').length
|
||
const titleBar = document.querySelector('.iwb-editor-layer-panel-header')
|
||
const addBtns = titleBar ? titleBar.querySelectorAll('.iwb-editor-layer-add-btn').length : 0
|
||
const hdrAdd = document.querySelector('.iwb-editor-header [data-action="addBlankLayer"], .iwb-editor-header [data-action="addBitmapLayer"]')
|
||
const tools = document.querySelector('.iwb-editor-canvas-wrap > .iwb-editor-tools')
|
||
const kids = tools ? [...tools.children] : []
|
||
// v1.18:撤销组搬进来后是 tools 的最后一个子元素,视图快捷退到它前面两位
|
||
// (中间还夹了一条分隔线 span,没有 data-action,过滤掉)
|
||
const histEl = kids.find(el => el.classList && el.classList.contains('iwb-editor-history')) || null
|
||
const lastTwo = kids.filter(el => el !== histEl && el.dataset && el.dataset.action)
|
||
.slice(-2).map(el => el.dataset.action)
|
||
return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') &&
|
||
hdrLayerBtns === 0 && !hdrAdd && addBtns === 4 &&
|
||
!q('.iwb-editor-header [data-action="zoomFit"]') && !q('.iwb-editor-header [data-action="togglePanels"]') &&
|
||
lastTwo.join(',') === 'zoomFit,togglePanels' && kids[kids.length - 1] === histEl &&
|
||
q('.iwb-editor-layer-panel-header [data-action="addBlankLayer"]') &&
|
||
q('.iwb-editor-layer-panel-header [data-action="addBitmapLayer"]') &&
|
||
q('.iwb-editor-layer-panel-header [data-action="mergeLayers"]') &&
|
||
q('.iwb-editor-layer-panel-header [data-action="mergeVisible"]')
|
||
}))
|
||
|
||
check('「还原原图」图标是循环重置(refresh)而不是垃圾桶', await page.evaluate(() => {
|
||
const svg = document.querySelector('.iwb-editor-tools [data-action="reset"] svg')
|
||
if (!svg) return false
|
||
const paths = svg.querySelectorAll('path').length
|
||
const polys = Array.from(svg.querySelectorAll('polyline')).map(p => p.getAttribute('points')).join('|')
|
||
return paths >= 4 && polys.indexOf('3 6 5 6 21 6') < 0
|
||
}))
|
||
|
||
check('适应窗口按钮真的生效(放大后点它回到 fit 基线并居中)', await (async () => {
|
||
await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click()
|
||
await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click()
|
||
const zoomed = (await dbg()).zoom
|
||
await page.locator('.iwb-editor-tools [data-action="zoomFit"]').click()
|
||
const fitted = (await dbg()).zoom
|
||
return zoomed > 1 && Math.abs(fitted - 1) < 0.001
|
||
})())
|
||
|
||
check('PS 快捷键:V/M/A/L/B/E/P/T/R/O/U/C/I/H 切工具', await (async () => {
|
||
// 先点一下工具按钮,保证焦点不在输入框里(isTyping() 会吞掉无修饰键快捷键)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
// v1.13 用户裁定:R = 矩形,O = 圆形,L = 箭头(套索从 L 让位到 A)
|
||
const seq = [['v', 'select'], ['m', 'marquee'], ['a', 'lasso'], ['l', 'arrow'], ['b', 'brush'], ['e', 'eraser'],
|
||
['p', 'pen'], ['t', 'text'], ['r', 'rect'], ['o', 'circle'], ['u', 'rect'], ['c', 'crop'], ['i', 'picker'], ['h', 'hand']]
|
||
for (const [k, tool] of seq) {
|
||
await page.keyboard.press(k)
|
||
if ((await dbg()).tool !== tool) return false
|
||
}
|
||
return true
|
||
})())
|
||
|
||
check('Shift+U 在 矩形/圆形/箭头 间循环(PS 同类工具循环)', await (async () => {
|
||
await page.keyboard.press('u')
|
||
await page.keyboard.press('Shift+u')
|
||
const a = (await dbg()).tool
|
||
await page.keyboard.press('Shift+u')
|
||
const b = (await dbg()).tool
|
||
return a === 'circle' && b === 'arrow'
|
||
})())
|
||
|
||
check('Tab 收起 / 展开侧栏(PS 习惯)', await (async () => {
|
||
await page.keyboard.press('Tab')
|
||
const collapsed = await page.evaluate(() => document.querySelector('.iwb-editor-overlay').classList.contains('panels-collapsed'))
|
||
await page.keyboard.press('Tab')
|
||
const restored = await page.evaluate(() => document.querySelector('.iwb-editor-overlay').classList.contains('panels-collapsed'))
|
||
return collapsed === true && restored === false
|
||
})())
|
||
|
||
check('[ / ] 增减画笔大小(PS 习惯,画笔橡皮共用)', await (async () => {
|
||
await page.keyboard.press(']') // 3 → 5? 起始值不定,只验方向与 clamp
|
||
const up = (await dbg()).toolOptions.brushSize
|
||
await page.keyboard.press('[')
|
||
await page.keyboard.press('[')
|
||
const down = (await dbg()).toolOptions.brushSize
|
||
return up > down && down >= 1 && up <= 300
|
||
})())
|
||
|
||
check('Ctrl+1 = 100% 实际像素 / Ctrl+0 = 适应窗口', await (async () => {
|
||
await page.keyboard.press('Control+1')
|
||
const d1 = await dbg()
|
||
// S.zoom 是相对 fitW 的倍数:100% 实际像素 = doc.w / fit.w(小图会被放大铺满,所以可能 < 1)
|
||
const expect = d1.doc.w / d1.fit.w
|
||
const okActual = Math.abs(d1.zoom - expect) < 0.02
|
||
await page.keyboard.press('Control+0')
|
||
return okActual && Math.abs((await dbg()).zoom - 1) < 0.001
|
||
})())
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
check('选择工具的选项栏里有 全选/反选/取消 三个命令(竖工具条不再有)', await page.evaluate(() => {
|
||
const cmds = document.querySelectorAll('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more]')
|
||
const keys = Array.from(cmds).map(b => b.dataset.more).join(',')
|
||
return cmds.length === 3 && keys === 'sel.all,sel.invert,sel.none' &&
|
||
!document.querySelector('.iwb-editor-tools .iwb-editor-selcmd')
|
||
}))
|
||
|
||
await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more="sel.all"]').click()
|
||
const selAllDbg = await dbg()
|
||
check('点选项栏「全选」= Ctrl+A(选区生成)', Boolean(selAllDbg.selection && selAllDbg.selection.w === selAllDbg.doc.w),
|
||
JSON.stringify(selAllDbg.selection))
|
||
await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more="sel.none"]').click()
|
||
check('点选项栏「取消选区」清掉选区', !(await dbg()).selection)
|
||
|
||
// 画一个矩形 → 切选择工具点中它 → 选项栏就地改 描边/实心 + 线宽
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2,
|
||
liveBox.x + liveBox.width * 0.45, liveBox.y + liveBox.height * 0.45)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.3)
|
||
await page.waitForTimeout(150)
|
||
let selShapeDbg = await dbg()
|
||
check('选择工具选中矩形后选项栏出该形状的参数',
|
||
selShapeDbg.selectedShapeId &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="rect"]').count()) === 2 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="shapeLineWidth"]').count()) >= 2,
|
||
'selected=' + selShapeDbg.selectedShapeId)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').click()
|
||
selShapeDbg = await dbg()
|
||
check('选中矩形就地切「实心」(对象与按钮激活态一致)',
|
||
selShapeDbg.shapes[selShapeDbg.shapes.length - 1].fill === true &&
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active')),
|
||
JSON.stringify(selShapeDbg.shapes.slice(-1)))
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="rect"]').click()
|
||
selShapeDbg = await dbg()
|
||
check('再切回「描边」(按钮激活态跟随)',
|
||
selShapeDbg.shapes[selShapeDbg.shapes.length - 1].fill === false &&
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="rect"]').classList.contains('active')))
|
||
await page.locator('.iwb-editor-optionbar-body input[type="number"][data-opt="shapeLineWidth"]').fill('9')
|
||
await page.waitForTimeout(120)
|
||
selShapeDbg = await dbg()
|
||
check('选中矩形就地改线宽 9', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].lw === 9,
|
||
JSON.stringify(selShapeDbg.shapes.slice(-1)))
|
||
|
||
// Shift+X 的用例在文件末尾(它会把「下一个图形的填充色」也写成具体色值,
|
||
// 落在中间会污染后面「新建图形填充默认跟随描边色」那条断言)
|
||
|
||
// 钢笔:闭合路径选中后同样可切描边/实心
|
||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||
const pA = [liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.25]
|
||
const pB = [liveBox.x + liveBox.width * 0.75, liveBox.y + liveBox.height * 0.25]
|
||
const pC = [liveBox.x + liveBox.width * 0.75, liveBox.y + liveBox.height * 0.45]
|
||
const pD = [liveBox.x + liveBox.width * 0.55, liveBox.y + liveBox.height * 0.45]
|
||
for (const [x, y] of [pA, pB, pC, pD]) await page.mouse.click(x, y)
|
||
await page.mouse.click(pA[0], pA[1]) // 点回起点闭合
|
||
await page.waitForTimeout(120)
|
||
const penShapeDbg = await dbg()
|
||
check('钢笔闭合路径落成后自动回 V 并选中(v1.5 用户裁定)', Boolean(penShapeDbg.selectedShapeId) &&
|
||
penShapeDbg.tool === 'select' &&
|
||
penShapeDbg.shapes[penShapeDbg.shapes.length - 1].type === 'pen' &&
|
||
penShapeDbg.shapes[penShapeDbg.shapes.length - 1].closed === true,
|
||
JSON.stringify({ sel: penShapeDbg.selectedShapeId, tool: penShapeDbg.tool, last: penShapeDbg.shapes.slice(-1) }))
|
||
// 选中改为显式:切 V 再点路径内部
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click((pA[0] + pC[0]) / 2, (pA[1] + pC[1]) / 2)
|
||
await page.waitForTimeout(150)
|
||
check('V 选中钢笔路径后选项栏有 描边/实心(pen 归属)',
|
||
(await dbg()).selectedShapeId &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"]').count()) === 2,
|
||
'selected=' + (await dbg()).selectedShapeId)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="stroke"][data-fill-owner="pen"]').click()
|
||
let penSelDbg = await dbg()
|
||
check('选中钢笔路径就地切「描边」', penSelDbg.shapes[penSelDbg.shapes.length - 1].fill === false)
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="pen"]').click()
|
||
penSelDbg = await dbg()
|
||
check('再切回「实心」', penSelDbg.shapes[penSelDbg.shapes.length - 1].fill === true)
|
||
|
||
// v1.5:钢笔节点编辑统一走 V 双击(用户裁定 2026-11-05),P 下双击不再进编辑
|
||
check('V 下双击钢笔进入节点编辑,P 下双击不进入', await (async () => {
|
||
const dx = (pA[0] + pC[0]) / 2, dy = (pA[1] + pC[1]) / 2
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.dblclick(dx, dy)
|
||
await page.waitForTimeout(200)
|
||
const inEdit = (await dbg()).penEditId
|
||
await page.keyboard.press('Escape')
|
||
await page.waitForTimeout(120)
|
||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||
await page.mouse.dblclick(dx, dy)
|
||
await page.waitForTimeout(200)
|
||
const underPen = (await dbg()).penEditId
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
return inEdit && !underPen ? true : 'V=' + inEdit + ' P=' + underPen
|
||
})())
|
||
|
||
// v1.5:文字输入完成(Enter)后自动回 V 并选中该文字(用户裁定 2026-11-05)
|
||
check('文字输入完成后自动回 V 并选中,输入框已收起', await (async () => {
|
||
const before = (await dbg()).texts.length
|
||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.14, liveBox.y + liveBox.height * 0.12)
|
||
await page.waitForTimeout(150)
|
||
const open = await page.evaluate(() => { const el = document.querySelector('.iwb-editor-text-input'); return el && el.style.display !== 'none' })
|
||
if (!open) return 'pre: 输入框没出现'
|
||
await page.keyboard.type('V5')
|
||
await page.keyboard.press('Enter')
|
||
await page.waitForTimeout(260)
|
||
const d = await dbg()
|
||
const last = d.texts[d.texts.length - 1]
|
||
const ok = d.tool === 'select' && d.texts.length === before + 1 && d.selectedTextId === (last && last.id)
|
||
await page.keyboard.press('Escape') // 清掉选中
|
||
await page.keyboard.press('Control+z') // 撤掉这段文字,保持后续用例现场
|
||
await page.waitForTimeout(150)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
return ok ? true : 'tool=' + d.tool + ' texts=' + d.texts.length + ' selText=' + d.selectedTextId
|
||
})())
|
||
// 吸管:选中矢量形状后按 I 取色,颜色必须写回对象(2026-11-04 用户反馈:切吸管后颜色只进画笔、形状不变)
|
||
check('选中矢量形状后切吸管:选中态保留、取色写回形状、取完回到原工具', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
const selId = (await dbg()).selectedShapeId
|
||
if (!selId) return 'pre: 没有选中形状'
|
||
// 先换成一个可辨识的颜色,便于判断取色真的改了对象(v1.3:推荐色在弹层里,先点开色点)
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||
await page.locator('.iwb-editor-color-pop .iwb-editor-color-panel-swatch[data-panel-color="#4488ff"]').click()
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() // 收起,别挡住后面的画布取色点
|
||
const before = (await dbg()).shapes.find(s => s.id === selId)
|
||
if (!before || before.color !== '#4488ff') return 'pre: color=' + (before && before.color)
|
||
await page.keyboard.press('i') // 切吸管
|
||
const d1 = await dbg()
|
||
if (d1.tool !== 'picker' || d1.selectedShapeId !== selId) return 'picker: tool=' + d1.tool + ' sel=' + d1.selectedShapeId
|
||
// 点画面左下角(原图实色区,避开形状本身)
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.85)
|
||
await page.waitForTimeout(150)
|
||
const d2 = await dbg()
|
||
const after = d2.shapes.find(s => s.id === selId)
|
||
const shapeBar = await page.locator('.iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="pen"], .iwb-editor-optionbar-body [data-opt-toggle][data-fill-owner="rect"]').count()
|
||
return d2.tool === 'select' && after && after.color !== '#4488ff' && shapeBar > 0
|
||
? true
|
||
: 'post: tool=' + d2.tool + ' color=' + (after && after.color) + ' shapeBar=' + shapeBar
|
||
})())
|
||
|
||
await page.keyboard.press('Control+z') // 撤销最后一次填充
|
||
await page.keyboard.press('Control+z') // 撤销钢笔路径
|
||
await page.keyboard.press('Control+z') // 撤销矩形线宽
|
||
|
||
// ---- v1.3:矢量/文字工具不再具备选择功能(用户裁定 2026-11-05)----
|
||
// 核心回归:在已有矩形范围内再拉一个矩形,必须新增图形,而不是把旧矩形拖走
|
||
check('矩形工具在已有矩形上按下 → 新建第二个矩形,并自动回 V 选中它(v1.5)', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
const before = (await dbg()).shapes.length
|
||
await drag2(liveBox.x + liveBox.width * 0.22, liveBox.y + liveBox.height * 0.22,
|
||
liveBox.x + liveBox.width * 0.42, liveBox.y + liveBox.height * 0.42)
|
||
const after = await dbg()
|
||
const last = after.shapes[after.shapes.length - 1]
|
||
return after.shapes.length === before + 1 && after.selectedShapeId === last.id && after.tool === 'select'
|
||
? true
|
||
: 'shapes ' + before + '→' + after.shapes.length + ' sel=' + after.selectedShapeId + ' tool=' + after.tool
|
||
})())
|
||
|
||
check('切到 矩形/文字/钢笔 都会清掉选中态(选中只属于 V 与临时吸管)', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.3)
|
||
await page.waitForTimeout(120)
|
||
if (!(await dbg()).selectedShapeId) return 'pre: V 没选中形状'
|
||
const cleared = []
|
||
for (const t of ['rect', 'text', 'pen']) {
|
||
await page.locator(`.iwb-editor-tool[data-tool="${t}"]`).click()
|
||
const d = await dbg()
|
||
cleared.push(!d.selectedShapeId && !d.selectedTextId)
|
||
}
|
||
return cleared.every(Boolean) ? true : 'cleared=' + cleared.join(',')
|
||
})())
|
||
|
||
// 拖调色器改颜色只记一步历史(以前每移动一步就 saveSnapshot,4K 图直接吃掉几百 MB)
|
||
check('拖调色器改选中形状颜色:历史只增加 1 条', await (async () => {
|
||
await page.keyboard.press('Escape')
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.3, liveBox.y + liveBox.height * 0.3)
|
||
await page.waitForTimeout(120)
|
||
if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状'
|
||
const h0 = (await dbg()).history
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||
const sv = await page.locator('.iwb-editor-color-pop .iwb-color-sv').boundingBox()
|
||
await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2)
|
||
await page.mouse.down()
|
||
await page.mouse.move(sv.x + sv.width * 0.9, sv.y + sv.height * 0.85, { steps: 20 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(150)
|
||
const h1 = (await dbg()).history
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() // 收起
|
||
return h1 - h0 === 1 ? true : 'history ' + h0 + '→' + h1
|
||
})())
|
||
|
||
await page.keyboard.press('Escape') // 退出钢笔的半成品状态
|
||
await page.keyboard.press('Control+z') // 撤销拖动取色的那一步
|
||
await page.keyboard.press('Control+z') // 撤销上一步新建的矩形,恢复现场
|
||
|
||
// ---- v1.2.9:会话组(新建/覆盖/退出)移到顶栏最左 + 图层 PS 快捷键 ----
|
||
|
||
check('顶栏:标题 → 新建/覆盖/退出(统一中性色),撤销组已搬去工具条,右侧只剩 输出+导出', await page.evaluate(() => {
|
||
const q = (s) => document.querySelector(s)
|
||
const session = q('.iwb-editor-header > .iwb-editor-session')
|
||
const title = q('.iwb-editor-header > .iwb-editor-title')
|
||
const dl = q('.iwb-editor-header [data-action="download"]')
|
||
if (!session || !title || !dl) return false
|
||
const t = title.getBoundingClientRect(), s = session.getBoundingClientRect()
|
||
const btns = Array.from(session.querySelectorAll('.iwb-editor-btn')).map(b => b.dataset.action).join(',')
|
||
const bg = (sel) => getComputedStyle(q(sel)).backgroundColor
|
||
const unified = bg('.iwb-editor-header .iwb-editor-btn-new') === bg('.iwb-editor-header .iwb-editor-btn-replace') &&
|
||
bg('.iwb-editor-header .iwb-editor-btn-replace') === bg('.iwb-editor-header .iwb-editor-btn-cancel')
|
||
return btns === 'newNode,replace,cancel' &&
|
||
t.left < s.left &&
|
||
!q('.iwb-editor-header > .iwb-editor-history') && // v1.18 搬去工具条最右
|
||
!q('.iwb-editor-header > .iwb-editor-commands') &&
|
||
unified && dl.textContent.trim() === '导出' &&
|
||
!q('.iwb-editor-export-actions [data-action="newNode"]')
|
||
}))
|
||
|
||
// v1.18(用户 2026-11-10):撤销 / 重做 / 还原从顶栏搬到画布底部工具栏最右 —— 手在画布上时够得到
|
||
check('撤销 / 重做 / 还原 在工具条最右(视图快捷之后,是 tools 的最后一个子元素)', await page.evaluate(() => {
|
||
const tools = document.querySelector('.iwb-editor-tools')
|
||
const hist = tools && tools.querySelector('.iwb-editor-history')
|
||
const fit = tools && tools.querySelector('[data-action="zoomFit"]')
|
||
const panels = tools && tools.querySelector('[data-action="togglePanels"]')
|
||
const crop = tools && tools.querySelector('[data-tool="crop"]')
|
||
if (!hist || !fit || !panels || !crop) return false
|
||
const acts = [...hist.querySelectorAll('[data-action]')].map((b) => b.dataset.action).join(',')
|
||
const c = crop.getBoundingClientRect()
|
||
const f = fit.getBoundingClientRect()
|
||
const p = panels.getBoundingClientRect()
|
||
const h = hist.getBoundingClientRect()
|
||
return acts === 'undo,redo,reset' &&
|
||
tools.lastElementChild === hist &&
|
||
c.right <= f.left && f.right <= p.left && p.right <= h.left &&
|
||
Math.abs(h.top - c.top) < 2 // 与工具按钮同一条水平线,没有掉到第二行
|
||
}))
|
||
// 开发用:ANNOT_SHOT_BAR=/tmp/bar.png 出一张工具条截图(验证撤销组落在最右、没有换行)
|
||
if (process.env.ANNOT_SHOT_BAR) await page.locator('.iwb-editor-tools').screenshot({ path: process.env.ANNOT_SHOT_BAR })
|
||
check('画笔选项栏:推荐大小只留 4 个快捷点,硬度补 5 个快捷点且滑杆加宽', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
const ok = await page.evaluate(() => {
|
||
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||
if (!body) return false
|
||
const size = body.querySelectorAll('[data-opt-preset="brushSize"]').length
|
||
const hard = body.querySelectorAll('[data-opt-preset="brushHardness"]').length
|
||
const wide = Boolean(body.querySelector('input[data-opt="brushHardness"].iwb-opt-range-wide'))
|
||
return size === 4 && hard === 5 && wide
|
||
})
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
return ok
|
||
})())
|
||
|
||
// 按住 Alt 临时吸色(PS 手感):画笔下按住 Alt → 吸管 → 取色 → 松开回画笔
|
||
check('画笔按住 Alt 临时吸色,松开 Alt 回到画笔(可连续取色)', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
const color0 = (await dbg()).color
|
||
await page.keyboard.down('Alt')
|
||
const d1 = await dbg()
|
||
if (d1.tool !== 'picker' || !d1.altPicker) return 'down: tool=' + d1.tool + ' alt=' + d1.altPicker
|
||
// 取色:点画面右下角(实色区)
|
||
await page.mouse.click(liveBox.x + liveBox.width * 0.8, liveBox.y + liveBox.height * 0.85)
|
||
await page.waitForTimeout(120)
|
||
const d2 = await dbg()
|
||
// 取色后仍停在吸管(Alt 还按着),颜色已变
|
||
if (d2.tool !== 'picker') return 'pick: tool=' + d2.tool
|
||
if (d2.color === color0) return 'pick: color 未变 ' + d2.color
|
||
await page.keyboard.up('Alt')
|
||
await page.waitForTimeout(180)
|
||
const d3 = await dbg()
|
||
return d3.tool === 'brush' && !d3.altPicker
|
||
? true
|
||
: 'up: tool=' + d3.tool + ' alt=' + d3.altPicker
|
||
})())
|
||
|
||
// Shift+X 的用例见上面「Shift+X 交换填充色与描边色」(v1.13.1 起是交换语义,不再是实心/描边开关)
|
||
|
||
// 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层
|
||
// 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z)
|
||
check('图层 PS 快捷键:Ctrl+[/] 上下移一层、Ctrl+Shift+[/] 置底/置顶', await (async () => {
|
||
const before = (await dbg()).layers.length
|
||
await page.keyboard.press('Control+Shift+n') // 新建空白图层并选中(z 最高)
|
||
const d1 = await dbg()
|
||
const newId = d1.selectedLayerId
|
||
if (!newId || d1.layers.length !== before + 1) return false
|
||
const zOf = (d) => {
|
||
const bits = d.layers.map(l => ({ id: l.id, z: l.z }))
|
||
const vec = d.shapes.map(s => ({ id: s.id, z: s.z }))
|
||
const all = bits.concat(vec)
|
||
const me = all.find(u => u.id === newId)
|
||
return { me: me && me.z, max: Math.max(...all.map(u => u.z)), minNonBase: Math.min(...all.filter(u => u.id !== 'base').map(u => u.z)) }
|
||
}
|
||
if (zOf(d1).me !== zOf(d1).max) return false // 新层此刻在最上
|
||
await page.keyboard.press('Control+[') // 下移一层 → 不再最上
|
||
const d2 = await dbg()
|
||
if (zOf(d2).me >= zOf(d2).max) return false
|
||
await page.keyboard.press('Control+]') // 上移一层 → 回到最上
|
||
const d3 = await dbg()
|
||
if (zOf(d3).me !== zOf(d3).max) return false
|
||
await page.keyboard.press('Control+Shift+[') // 置底 → base 之上第一格
|
||
const d4 = await dbg()
|
||
if (zOf(d4).me !== zOf(d4).minNonBase) return false
|
||
await page.keyboard.press('Control+Shift+]') // 置顶 → 回到最上
|
||
const d5 = await dbg()
|
||
return zOf(d5).me === zOf(d5).max
|
||
})())
|
||
|
||
check('图层 PS 快捷键:Alt+[/] 向下/向上选择图层', await (async () => {
|
||
const d1 = await dbg()
|
||
const bits = d1.layers.map(l => ({ id: l.id, z: l.z }))
|
||
const topUnit = bits.concat(d1.shapes.map(s => ({ id: s.id, z: s.z }))).sort((a, b) => b.z - a.z)[0]
|
||
const topId = topUnit.id
|
||
if (d1.selectedLayerId !== topId) return 'pre: sel=' + d1.selectedLayerId + ' top=' + topId + ' bits=' + JSON.stringify(bits) + ' shapes=' + JSON.stringify(d1.shapes)
|
||
await page.keyboard.press('Alt+[') // 向下选 → 选到下一个单元(矩形 shape)
|
||
const d2 = await dbg()
|
||
if (!d2.selectedShapeId || d2.selectedLayerId !== null) return 'down: selLayer=' + d2.selectedLayerId + ' selShape=' + d2.selectedShapeId
|
||
await page.keyboard.press('Alt+]') // 向上选 → 回到位图新层
|
||
const d3 = await dbg()
|
||
if (d3.selectedLayerId !== topId || d3.selectedShapeId) return 'up: selLayer=' + d3.selectedLayerId + ' selShape=' + d3.selectedShapeId
|
||
return true
|
||
})())
|
||
|
||
check('Delete 删除选中的位图图层(PS 习惯)', await (async () => {
|
||
const d0 = await dbg()
|
||
const before = d0.layers.length
|
||
await page.keyboard.press('Delete')
|
||
const d = await dbg()
|
||
if (d.layers.length !== before - 1) return 'layers ' + before + '→' + d.layers.length + ' sel=' + d0.selectedLayerId + ' selShape=' + d0.selectedShapeId + ' tool=' + d0.tool + ' toast=' + await page.locator('.iwb-editor-toast').textContent()
|
||
return d.selectedLayerId === null ? true : 'sel 未清空: ' + d.selectedLayerId
|
||
})())
|
||
|
||
// ---- v1.6:笔刷环即时反馈(按 ] / [ 不必再动鼠标) ----
|
||
check('笔刷环:按 ] 后鼠标不动,环立刻变大', await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await page.mouse.move(liveBox.x + liveBox.width * 0.5, liveBox.y + liveBox.height * 0.5)
|
||
await page.waitForTimeout(150)
|
||
const ringWidth = () => page.evaluate(() => {
|
||
const c = document.querySelector('.iwb-editor-cursor-overlay')
|
||
const d = c.getContext('2d').getImageData(0, 0, c.width, c.height).data
|
||
let minX = 1e9, maxX = -1
|
||
for (let y = 0; y < c.height; y++) {
|
||
for (let x = 0; x < c.width; x++) {
|
||
if (d[(y * c.width + x) * 4 + 3] > 8) { if (x < minX) minX = x; if (x > maxX) maxX = x }
|
||
}
|
||
}
|
||
return maxX < 0 ? 0 : maxX - minX + 1
|
||
})
|
||
const w0 = await ringWidth()
|
||
const s0 = (await dbg()).toolOptions.brushSize
|
||
for (let i = 0; i < 3; i++) await page.keyboard.press(']')
|
||
await page.waitForTimeout(140)
|
||
const w1 = await ringWidth()
|
||
const s1 = (await dbg()).toolOptions.brushSize
|
||
for (let i = 0; i < 3; i++) await page.keyboard.press('[')
|
||
await page.waitForTimeout(120)
|
||
return w0 > 0 && s1 > s0 && w1 > w0 ? true : 'w ' + w0 + '→' + w1 + ' size ' + s0 + '→' + s1
|
||
})())
|
||
|
||
// ---- v1.6:图层合并(向下合并 / 多选合并 / 合并可见) ----
|
||
// 两笔分别落在左右半区,合并后同一层里两半都要有像素,才算真合并
|
||
const strokeHalves = async (id, w, h) => page.evaluate(({ id, w, h }) => {
|
||
const d = window.__iwbEditor.__debug()
|
||
return {
|
||
left: d.alphaIn(id, 0, 0, w / 2, h),
|
||
right: d.alphaIn(id, w / 2, 0, w, h)
|
||
}
|
||
}, { id, w, h })
|
||
|
||
check('图层合并:Ctrl+E 向下合并两层(两笔都在),Ctrl+Z 连像素一起回退', await (async () => {
|
||
await page.keyboard.press('Escape')
|
||
await page.keyboard.press('Control+d')
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
const doc = (await dbg()).doc
|
||
const n0 = (await dbg()).layers.length
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
const lowerId = (await dbg()).activeLayerId
|
||
await drag2(liveBox.x + liveBox.width * 0.22, liveBox.y + liveBox.height * 0.62,
|
||
liveBox.x + liveBox.width * 0.32, liveBox.y + liveBox.height * 0.72)
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
const upperId = (await dbg()).activeLayerId
|
||
await drag2(liveBox.x + liveBox.width * 0.66, liveBox.y + liveBox.height * 0.62,
|
||
liveBox.x + liveBox.width * 0.76, liveBox.y + liveBox.height * 0.72)
|
||
const d1 = await dbg()
|
||
if (d1.layers.length !== n0 + 2) return 'pre layers ' + d1.layers.length + ' expect ' + (n0 + 2)
|
||
await page.keyboard.press('Control+e')
|
||
await page.waitForTimeout(320)
|
||
const d2 = await dbg()
|
||
if (d2.layers.length !== n0 + 1) return 'merge layers ' + d2.layers.length + ' expect ' + (n0 + 1)
|
||
const px = await strokeHalves(d2.activeLayerId, doc.w, doc.h)
|
||
if (!(px.left > 0 && px.right > 0)) return 'pixels ' + JSON.stringify(px)
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(320)
|
||
const d3 = await dbg()
|
||
if (d3.layers.length !== n0 + 2) return 'undo layers ' + d3.layers.length + ' expect ' + (n0 + 2)
|
||
// 撤销必须把两笔还给各自原来的层,而不是留一份空层
|
||
const backLower = await strokeHalves(lowerId, doc.w, doc.h)
|
||
const backUpper = await strokeHalves(upperId, doc.w, doc.h)
|
||
if (!(backLower.left > 0 && backUpper.right > 0)) {
|
||
return 'undo pixels lower=' + JSON.stringify(backLower) + ' upper=' + JSON.stringify(backUpper)
|
||
}
|
||
return true
|
||
})())
|
||
|
||
check('图层多选合并:⌘/Ctrl 点击两项后合并按钮合成一层', await (async () => {
|
||
const d0 = await dbg()
|
||
const n0 = d0.layers.length
|
||
const items = page.locator('.iwb-editor-layer-list .iwb-layer-item')
|
||
await items.nth(0).click()
|
||
await items.nth(1).click({ modifiers: [process.platform === 'darwin' ? 'Meta' : 'Control'] })
|
||
await page.waitForTimeout(220)
|
||
const dm = await dbg()
|
||
const marked = await page.locator('.iwb-layer-item.multi').count()
|
||
if (dm.layerMulti.length !== 2 || marked !== 2) return 'multi ' + JSON.stringify(dm.layerMulti) + ' dom=' + marked
|
||
await page.locator('[data-action="mergeLayers"]').click()
|
||
await page.waitForTimeout(320)
|
||
const d1 = await dbg()
|
||
return d1.layers.length === n0 - 1 && d1.layerMulti.length === 0
|
||
? true
|
||
: 'after ' + d1.layers.length + '/' + n0 + ' multi=' + d1.layerMulti.length
|
||
})())
|
||
|
||
check('向下合并到「原图」:笔迹写进 base,Ctrl+Z 复原像素', await (async () => {
|
||
// 归一到「只剩原图」:先显示所有隐藏层,再合并可见
|
||
let d = await dbg()
|
||
for (const l of d.layers) {
|
||
if (!l.visible) {
|
||
await page.locator('.iwb-layer-vis[data-vis-id="' + l.id + '"]').click()
|
||
await page.waitForTimeout(90)
|
||
}
|
||
}
|
||
d = await dbg()
|
||
if (d.layers.length > 1) {
|
||
await page.keyboard.press('Control+Shift+e')
|
||
await page.waitForTimeout(320)
|
||
d = await dbg()
|
||
}
|
||
if (d.layers.length !== 1 || d.layers[0].id !== 'base') return 'normalize: ' + JSON.stringify(d.layers)
|
||
|
||
const doc = d.doc
|
||
const cx = Math.round(doc.w * 0.5), cy = Math.round(doc.h * 0.5)
|
||
const pxAt = () => page.evaluate(([x, y]) => window.__iwbEditor.__debug().pixel('base', x, y), [cx, cy])
|
||
const p0 = await pxAt()
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await page.locator('.iwb-editor-optionbar-body input.iwb-opt-num[data-opt="brushSize"]').fill('40')
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
// 斜穿中心的大笔画,避免采样点落空
|
||
await drag2(liveBox.x + liveBox.width * 0.15, liveBox.y + liveBox.height * 0.35,
|
||
liveBox.x + liveBox.width * 0.85, liveBox.y + liveBox.height * 0.65)
|
||
const d1 = await dbg()
|
||
if (d1.layers.length !== 2) return 'pre layers ' + d1.layers.length
|
||
await page.keyboard.press('Control+e')
|
||
await page.waitForTimeout(340)
|
||
const d2 = await dbg()
|
||
if (d2.layers.length !== 1 || d2.layers[0].id !== 'base') return 'merge layers ' + JSON.stringify(d2.layers.map(l => l.id))
|
||
const p1 = await pxAt()
|
||
if (!p1 || !p0 || (p1[0] === p0[0] && p1[1] === p0[1] && p1[2] === p0[2])) {
|
||
return 'base 像素未变 ' + JSON.stringify([p0, p1])
|
||
}
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(340)
|
||
const p2 = await pxAt()
|
||
const same = p2 && p0 && p2[0] === p0[0] && p2[1] === p0[1] && p2[2] === p0[2]
|
||
return same ? true : 'undo 像素 ' + JSON.stringify([p0, p2])
|
||
})())
|
||
|
||
check('合并可见图层:隐藏层原样保留,可见层合成一层', await (async () => {
|
||
// 保证至少 2 个可见层
|
||
let d = await dbg()
|
||
while (d.layers.filter(l => l.visible).length < 2) {
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
d = await dbg()
|
||
}
|
||
// 再新建一层并隐藏它,验证它不参与合并、也不会被删
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(160)
|
||
const hiddenId = (await dbg()).activeLayerId
|
||
await page.locator('.iwb-layer-vis[data-vis-id="' + hiddenId + '"]').click()
|
||
await page.waitForTimeout(180)
|
||
const visibleBefore = (await dbg()).layers.filter(l => l.visible).length
|
||
await page.keyboard.press('Control+Shift+e')
|
||
await page.waitForTimeout(360)
|
||
const d1 = await dbg()
|
||
const stillHidden = d1.layers.some(l => l.id === hiddenId && l.visible === false)
|
||
const visibleAfter = d1.layers.filter(l => l.visible).length
|
||
return stillHidden && visibleAfter === 1 && visibleBefore >= 2
|
||
? true
|
||
: 'hidden=' + stillHidden + ' visible ' + visibleBefore + '→' + visibleAfter + ' layers=' + d1.layers.length
|
||
})())
|
||
|
||
check('图层面板:缩略图画出了图层内容(不是空框)', await (async () => {
|
||
await page.waitForTimeout(260) // 缩略图有 90ms 合批延迟
|
||
const n = await page.evaluate(() => {
|
||
const cv = document.querySelector('.iwb-layer-thumb canvas[data-thumb-id="base"]')
|
||
if (!cv) return -1
|
||
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||
let k = 0
|
||
for (let i = 3; i < d.length; i += 4) if (d[i] > 8) k++
|
||
return k
|
||
})
|
||
return n > 10 ? true : '缩略图不透明像素=' + n
|
||
})())
|
||
|
||
check('图层重命名:双击名字进入编辑,Enter 提交后生效', await (async () => {
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(180)
|
||
const id = (await dbg()).activeLayerId
|
||
const nameEl = page.locator('.iwb-layer-name[data-name-id="' + id + '"]')
|
||
await nameEl.click()
|
||
await nameEl.click() // 400ms 内两次按下 → 自算双击(点一下会重绘面板)
|
||
const input = page.locator('.iwb-layer-name-input')
|
||
if (!(await input.count())) return '未进入重命名态'
|
||
await input.fill('主体层')
|
||
await input.press('Enter')
|
||
await page.waitForTimeout(180)
|
||
const nm = (await dbg()).layers.find(l => l.id === id)
|
||
return nm && nm.name === '主体层' && !(await page.locator('.iwb-layer-name-input').count())
|
||
? true
|
||
: '名字=' + (nm && nm.name)
|
||
})())
|
||
|
||
check('图层不透明度:滑杆到 40% 立刻生效,一次拖动只记 1 条撤销', await (async () => {
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(180)
|
||
const id = (await dbg()).activeLayerId
|
||
const row = await page.locator('.iwb-layer-item[data-layer-id="' + id + '"] .iwb-layer-op-row').count()
|
||
if (!row) return '选中项下没有不透明度行'
|
||
const h0 = (await dbg()).history
|
||
for (const v of [70, 55, 40]) {
|
||
await page.evaluate((val) => {
|
||
const el = document.querySelector('.iwb-layer-opacity')
|
||
el.value = String(val)
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
}, v)
|
||
}
|
||
const d = await dbg()
|
||
const l = d.layers.find(x => x.id === id)
|
||
const val = await page.locator('.iwb-layer-op-val').first().textContent()
|
||
if (!l) return '图层丢失'
|
||
if (Math.abs(l.opacity - 0.4) > 0.001) return 'opacity=' + l.opacity
|
||
if (Math.abs(l.cssOpacity - 0.4) > 0.001) return 'cssOpacity=' + l.cssOpacity + '(画面没跟上)'
|
||
if ((val || '').trim() !== '40%') return '标值=' + val
|
||
if (d.history - h0 !== 1) return '撤销条数=' + (d.history - h0) + '(一次拖动应只拍 1 张快照)'
|
||
return true
|
||
})())
|
||
|
||
check('图层不透明度:Ctrl+Z 回到 100%,画面同步', await (async () => {
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(320)
|
||
const d = await dbg()
|
||
const l = d.layers[d.layers.length - 1]
|
||
return l && Math.abs(l.opacity - 1) < 0.001 && Math.abs(l.cssOpacity - 1) < 0.001
|
||
? true
|
||
: 'opacity=' + (l && l.opacity) + ' css=' + (l && l.cssOpacity)
|
||
})())
|
||
|
||
// ---------- v1.8.3 图层面板交互:滑杆真能拖 + 图层真能拖排 ----------
|
||
// 面板顺序(最上层在前)与每层 id,供排序用例断言
|
||
const panelIds = () => page.evaluate(() => [...document.querySelectorAll('.iwb-layer-item')].map(el => el.dataset.layerId))
|
||
const zOf = (id) => page.evaluate((lid) => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const l = d.layers.find(x => x.id === lid)
|
||
return l ? l.z : null
|
||
}, id)
|
||
|
||
/** 真实鼠标把第 from 行拖到第 to 行中线之上/之下(below=true 表示越过中线) */
|
||
async function dragRow(from, to, below = true) {
|
||
const a = page.locator('.iwb-layer-item').nth(from)
|
||
const b = page.locator('.iwb-layer-item').nth(to)
|
||
const ba = await a.boundingBox()
|
||
const bb = await b.boundingBox()
|
||
const x = ba.x + 44 // 落在缩略图/名字区域,避开左侧显示按钮
|
||
const y = ba.y + 10 // 行首部:选中行的下半截是不透明度滑杆,别往那儿按
|
||
await page.mouse.move(x, y)
|
||
await page.mouse.down()
|
||
await page.mouse.move(x, y + 8, { steps: 3 }) // 先越过 4px 阈值
|
||
await page.mouse.move(bb.x + 44, below ? bb.y + bb.height - 3 : bb.y + 3, { steps: 10 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(200)
|
||
}
|
||
|
||
check('图层不透明度:真实鼠标拖动滑块,数值与画面一路跟随(不再只能点)', await (async () => {
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(180)
|
||
const id = (await dbg()).activeLayerId
|
||
const box = await page.locator('.iwb-layer-item[data-layer-id="' + id + '"] .iwb-layer-opacity').boundingBox()
|
||
if (!box) return '选中项下没有不透明度滑杆'
|
||
const y = box.y + box.height / 2
|
||
// 从 85% 处按下,连续拖到 20%:被整项 draggable 抢事件时只有按下那一下生效,之后纹丝不动
|
||
await page.mouse.move(box.x + box.width * 0.85, y)
|
||
await page.mouse.down()
|
||
const seen = []
|
||
for (const f of [0.7, 0.5, 0.35, 0.2]) {
|
||
await page.mouse.move(box.x + box.width * f, y, { steps: 4 })
|
||
const l = (await dbg()).layers.find(x => x.id === id)
|
||
seen.push(l ? l.opacity : -1)
|
||
}
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(120)
|
||
const l = (await dbg()).layers.find(x => x.id === id)
|
||
if (!l) return '图层丢失'
|
||
const follows = seen.every((v, i) => i === 0 || v < seen[i - 1] - 0.01)
|
||
if (!follows) return '拖动中数值没跟随 ' + JSON.stringify(seen.map(v => Math.round(v * 100)))
|
||
if (!(l.opacity < 0.35)) return '最终 opacity=' + l.opacity
|
||
if (Math.abs(l.cssOpacity - l.opacity) > 0.001) return '画面没跟上 css=' + l.cssOpacity
|
||
return true
|
||
})())
|
||
|
||
check('图层拖动排序:向下拖过下一行中线真的换位,z 同步、一次拖动一条撤销', await (async () => {
|
||
// 保证至少 3 个可移动层,才有「换位」可看
|
||
while ((await panelIds()).length < 4) {
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(140)
|
||
}
|
||
const before = await panelIds()
|
||
const movedId = before[0], targetId = before[1]
|
||
const h0 = (await dbg()).history
|
||
await dragRow(0, 1, true)
|
||
const after = await panelIds()
|
||
if (after[0] !== targetId || after[1] !== movedId) return '没换位 ' + before.join(',') + ' → ' + after.join(',')
|
||
const zMoved = await zOf(movedId), zTarget = await zOf(targetId)
|
||
if (!(zMoved < zTarget)) return 'z 没同步 moved=' + zMoved + ' target=' + zTarget
|
||
const h1 = (await dbg()).history
|
||
if (h1 - h0 !== 1) return '撤销条数=' + (h1 - h0) + '(一次拖动应只拍 1 张快照)'
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(280)
|
||
const back = await panelIds()
|
||
return back.join(',') === before.join(',') ? true : 'Ctrl+Z 未复原 ' + back.join(',')
|
||
})())
|
||
|
||
// v1.13(用户裁定「图层现在不能移动到原图的下面,这个需要解封」):
|
||
// 原图不再被钉在最底层,拖到原图那一行就能真的沉到它下面(典型用途:垫一张背景色层)。
|
||
check('图层拖动排序:可以拖到「原图」下面(原图不再是不可穿越的底)', await (async () => {
|
||
const before = await panelIds()
|
||
const movedId = before[0]
|
||
const baseKey = before[before.length - 1]
|
||
if (baseKey !== 'base') return '前置条件不成立,原图不在面板最底:' + before.join(',')
|
||
await dragRow(0, before.length - 1, true) // 一路拖到底(原图那一行)
|
||
const after = await panelIds()
|
||
const okBottom = after[after.length - 1] === movedId
|
||
const okBase = after[after.length - 2] === 'base'
|
||
const zBase = await zOf('base')
|
||
// 后续用例默认「原图在最底」,这里撤销回原状,不给后面留暗坑
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(260)
|
||
const back = await panelIds()
|
||
if (!okBottom) return '被拖的层没到最底 ' + after.join(',')
|
||
if (!okBase) return '原图没被压到倒数第二格 ' + after.join(',')
|
||
if (!(zBase > 0)) return '原图 z=' + zBase + '(应 > 0)'
|
||
return back.join(',') === before.join(',') ? true : '撤销未复原 ' + back.join(',')
|
||
})())
|
||
|
||
check('图层拖动排序:位移不足 4px 算点击(不误判成拖动,顺序不变)', await (async () => {
|
||
const before = await panelIds()
|
||
const a = await page.locator('.iwb-layer-item').nth(0).boundingBox()
|
||
await page.mouse.move(a.x + 44, a.y + a.height / 2)
|
||
await page.mouse.down()
|
||
await page.mouse.move(a.x + 44, a.y + a.height / 2 + 2, { steps: 2 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(160)
|
||
const after = await panelIds()
|
||
if (after.join(',') !== before.join(',')) return '顺序被改 ' + before.join(',') + ' → ' + after.join(',')
|
||
// 顺手确认这次按下仍然完成了「选中该层」
|
||
const sel = await page.evaluate(() => window.__iwbEditor.__debug().selectedLayerId)
|
||
return sel === before[0] ? true : '没选中 selectedLayerId=' + sel
|
||
})())
|
||
|
||
check('图层拖动排序:焦点在工具栏按钮上时也能拖(blur 兜底不误伤拖动)', await (async () => {
|
||
// 回归:window 捕获阶段的 blur 会连子元素失焦一起收到 —— 鼠标一按到图层行,
|
||
// 焦点从工具栏按钮挪走就会立刻把这次拖动取消。这条用例专门守住那个坑。
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await page.waitForTimeout(80)
|
||
const before = await panelIds()
|
||
await dragRow(0, 1, true)
|
||
const after = await panelIds()
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
return after[0] === before[1] && after[1] === before[0]
|
||
? true
|
||
: '没换位 ' + before.join(',') + ' → ' + after.join(',')
|
||
})())
|
||
|
||
// ---------- v1.8 快速效果:参数可调 ----------
|
||
// 造一个确定有内容的层(空层做效果没有可比像素)
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(180)
|
||
const fxLayerId = (await dbg()).activeLayerId
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await page.locator('.iwb-editor-optionbar-body input.iwb-opt-num[data-opt="brushSize"]').fill('60')
|
||
await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.3,
|
||
liveBox.x + liveBox.width * 0.8, liveBox.y + liveBox.height * 0.7)
|
||
await page.waitForTimeout(200)
|
||
|
||
const fxHash = () => page.evaluate((id) => window.__iwbEditor.__debug().layerHash(id), fxLayerId)
|
||
const fxSet = async (v) => {
|
||
await page.evaluate((val) => {
|
||
const el = document.querySelector('.iwb-editor-fx-range')
|
||
if (!el) return
|
||
el.value = String(val)
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
}, v)
|
||
await page.waitForTimeout(90)
|
||
}
|
||
|
||
check('快速效果:点马赛克后参数滑杆启用,单位是块大小', await (async () => {
|
||
const h0 = (await dbg()).history
|
||
await page.locator('[data-fx="mosaic"]').click()
|
||
await page.waitForTimeout(260)
|
||
const d = await dbg()
|
||
const range = page.locator('.iwb-editor-fx-range')
|
||
if (!d.fx.hasSource || d.fx.key !== 'mosaic') return 'fx=' + JSON.stringify(d.fx)
|
||
if (await range.isDisabled()) return '滑杆仍禁用'
|
||
const min = await range.getAttribute('min')
|
||
const max = await range.getAttribute('max')
|
||
const name = (await page.locator('.iwb-editor-fx-adj-name').textContent()) || ''
|
||
const val = (await page.locator('.iwb-editor-fx-adj-val').textContent()) || ''
|
||
if (min !== '2' || max !== '96') return 'range=' + min + '~' + max
|
||
if (name.indexOf('马赛克') < 0 || name.indexOf('块大小') < 0) return '标签=' + name
|
||
if (val.indexOf('px') < 0) return '数值=' + val
|
||
if (d.history - h0 !== 1) return '撤销条数=' + (d.history - h0) + '(点效果应只拍 1 张)'
|
||
return true
|
||
})())
|
||
|
||
check('马赛克:块 12 → 48 → 12 与首次 12 完全一致(从基准重算,不叠加)', await (async () => {
|
||
await fxSet(12)
|
||
const h12a = await fxHash()
|
||
await fxSet(48)
|
||
const h48 = await fxHash()
|
||
await fxSet(12)
|
||
const h12b = await fxHash()
|
||
if (!h12a) return '指纹读取失败'
|
||
if (h12a === h48) return '块大小变化没有改变像素'
|
||
if (h12a !== h12b) return '12px 两次结果不同,发生叠加: ' + h12a + ' vs ' + h12b
|
||
return true
|
||
})())
|
||
|
||
check('效果参数:连续拖动不新增撤销记录', await (async () => {
|
||
const h0 = (await dbg()).history
|
||
for (const v of [20, 36, 60]) await fxSet(v)
|
||
const h1 = (await dbg()).history
|
||
return h1 === h0 ? true : '撤销 ' + h0 + '→' + h1
|
||
})())
|
||
|
||
check('反白:50% 各通道趋近 128,100% 彻底反向(强度真的生效)', await (async () => {
|
||
await page.locator('[data-fx="invert"]').click()
|
||
await page.waitForTimeout(240)
|
||
await fxSet(50)
|
||
const c50 = await page.evaluate((id) => window.__iwbEditor.__debug().avgColor(id), fxLayerId)
|
||
await fxSet(100)
|
||
const c100 = await page.evaluate((id) => window.__iwbEditor.__debug().avgColor(id), fxLayerId)
|
||
if (!c50 || !c100) return '取色失败'
|
||
const near128 = c50.slice(0, 3).every(v => Math.abs(v - 128) <= 5)
|
||
if (!near128) return '50%=' + c50.slice(0, 3).join(',')
|
||
if (!(c100[0] <= 12 && c100[1] >= 160)) return '100%=' + c100.slice(0, 3).join(',')
|
||
return true
|
||
})())
|
||
|
||
check('同一效果再点=回默认参数,且不新增撤销记录', await (async () => {
|
||
await page.locator('[data-fx="mosaic"]').click()
|
||
await page.waitForTimeout(220)
|
||
await fxSet(64)
|
||
const before = await fxHash()
|
||
const h0 = (await dbg()).history
|
||
await page.locator('[data-fx="mosaic"]').click()
|
||
await page.waitForTimeout(260)
|
||
const d = await dbg()
|
||
const after = await fxHash()
|
||
if (d.history !== h0) return '撤销 +' + (d.history - h0)
|
||
if (before === after) return '点第二次毫无变化(应回默认块大小)'
|
||
return d.fx.key === 'mosaic' && d.fx.value !== 64 ? true : 'value=' + d.fx.value
|
||
})())
|
||
|
||
check('切到别的层:效果滑杆置灰;切回原层恢复可调', await (async () => {
|
||
await page.keyboard.press('Control+Shift+n')
|
||
await page.waitForTimeout(240)
|
||
const off = await page.locator('.iwb-editor-fx-range').isDisabled()
|
||
await page.locator('.iwb-layer-item[data-layer-id="' + fxLayerId + '"]').click()
|
||
await page.waitForTimeout(240)
|
||
const on = !(await page.locator('.iwb-editor-fx-range').isDisabled())
|
||
return off && on ? true : '切走禁用=' + off + ' 切回恢复=' + on
|
||
})())
|
||
|
||
check('形状控制点屏幕尺寸恒定(不随图片放大而膨胀)', await (async () => {
|
||
// 当前这张 96×64 的图被「适应窗口」放大 ~9 倍。旧实现按 5.5 / S.zoom 画,
|
||
// 屏幕尺寸实际是 11 * fitW/imgW ≈ 100px(截图里那种巨大发光点);
|
||
// 现在按 viewScale() 换算,应稳定在 11px 左右、与图片尺寸无关。
|
||
await page.locator('[data-tool="rect"]').click()
|
||
const b = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||
await page.mouse.move(b.x + b.width * 0.25, b.y + b.height * 0.25)
|
||
await page.mouse.down()
|
||
await page.mouse.move(b.x + b.width * 0.75, b.y + b.height * 0.75, { steps: 6 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(320)
|
||
const sizes = await page.evaluate(() => {
|
||
const oc = document.querySelector('.iwb-editor-crop-overlay')
|
||
const rect = oc.getBoundingClientRect()
|
||
const sw = Math.max(1, Math.round(rect.width)), sh = Math.max(1, Math.round(rect.height))
|
||
// 重采样到屏幕尺寸:overlay 内部是图片坐标,小图上控制点在画布里只有 1~2px
|
||
const tmp = document.createElement('canvas')
|
||
tmp.width = sw; tmp.height = sh
|
||
const t = tmp.getContext('2d')
|
||
t.imageSmoothingEnabled = false
|
||
t.drawImage(oc, 0, 0, sw, sh)
|
||
const d = t.getImageData(0, 0, sw, sh).data
|
||
const seen = new Uint8Array(sw * sh)
|
||
const white = (i) => d[i * 4] > 235 && d[i * 4 + 1] > 235 && d[i * 4 + 2] > 235 && d[i * 4 + 3] > 200
|
||
const out = []
|
||
for (let i = 0; i < sw * sh; i++) {
|
||
if (seen[i] || !white(i)) continue
|
||
const st = [i]; seen[i] = 1
|
||
let mnx = 1e9, mxx = -1, mny = 1e9, mxy = -1, n = 0
|
||
while (st.length) {
|
||
const p = st.pop(); const px = p % sw, py = (p - px) / sw; n++
|
||
if (px < mnx) mnx = px
|
||
if (px > mxx) mxx = px
|
||
if (py < mny) mny = py
|
||
if (py > mxy) mxy = py
|
||
for (const q of [p - 1, p + 1, p - sw, p + sw]) {
|
||
if (q < 0 || q >= sw * sh || seen[q]) continue
|
||
const qx = q % sw
|
||
if (Math.abs(qx - px) > 1) continue
|
||
if (white(q)) { seen[q] = 1; st.push(q) } else seen[q] = 1
|
||
}
|
||
}
|
||
if (n >= 25) out.push(Math.round(((mxx - mnx) + (mxy - mny)) / 2))
|
||
}
|
||
return out
|
||
})
|
||
const max = sizes.length ? Math.max(...sizes) : 0
|
||
return sizes.length >= 4 && max <= 16 ? true : '控制点屏幕尺寸=' + JSON.stringify(sizes)
|
||
})())
|
||
|
||
check('图层拖动排序:位图与矢量混排也能拖(面板顺序、z、DOM 叠放三者一致)', await (async () => {
|
||
// 位图和矢量走的是两套画布,排序落地后必须同时刷新 z 与 canvas-stack 的插入次序
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await drag2(liveBox.x + liveBox.width * 0.2, liveBox.y + liveBox.height * 0.2,
|
||
liveBox.x + liveBox.width * 0.45, liveBox.y + liveBox.height * 0.45)
|
||
await page.waitForTimeout(240)
|
||
const rows = await page.evaluate(() => [...document.querySelectorAll('.iwb-layer-item')]
|
||
.map(el => el.dataset.layerType + ':' + el.dataset.layerId))
|
||
const shapeKey = rows.find(k => k.indexOf('shape:') === 0)
|
||
if (!shapeKey) return '没造出形状图层'
|
||
if (rows[0] !== shapeKey) return '新形状不在面板最上层 ' + rows.join(',')
|
||
|
||
await dragRow(0, rows.length - 1, true) // 一路拖到最底
|
||
const rows2 = await page.evaluate(() => [...document.querySelectorAll('.iwb-layer-item')]
|
||
.map(el => el.dataset.layerType + ':' + el.dataset.layerId))
|
||
if (rows2[rows2.length - 1] !== 'bitmap:base') return '原图没留在最底 ' + rows2.join(',')
|
||
if (rows2[rows2.length - 2] !== shapeKey) return '形状没落到原图之上 ' + rows2.join(',')
|
||
|
||
const geo = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const sh = d.shapes[d.shapes.length - 1]
|
||
// canvas-stack 里矢量画布排在第几个(自底向上),应与 z 一致
|
||
const nodes = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas')]
|
||
const vecIdx = nodes.findIndex(n => n.className.indexOf('iwb-editor-vec-canvas') >= 0)
|
||
return { z: sh ? sh.z : null, baseZ: d.layers.find(l => l.id === 'base').z, vecIdx }
|
||
})
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
if (geo.baseZ !== 0) return '原图 z=' + geo.baseZ
|
||
if (geo.z !== 1) return '形状 z=' + geo.z + '(应紧贴原图 = 1)'
|
||
return geo.vecIdx >= 1 ? true : '矢量画布在 DOM 里排到了最底 vecIdx=' + geo.vecIdx
|
||
})())
|
||
|
||
// ---------- v1.9 文字样式 / 吸附参考线 / 圆角 / 最近色 / 复制 ----------
|
||
|
||
/** 图片坐标 → 屏幕坐标(用位图图层 canvas 的实际显示尺寸换算,别用 zoom 猜) */
|
||
async function imgToScreen(ix, iy) {
|
||
const b = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||
const d = await dbg()
|
||
return { x: b.x + ix * (b.width / d.doc.w), y: b.y + iy * (b.height / d.doc.h), box: b, doc: d.doc }
|
||
}
|
||
|
||
/** 吸附阈值(图片像素):与 snap.js 的 6 屏幕像素保持同一口径 */
|
||
async function snapTol() {
|
||
const d = await dbg()
|
||
const b = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||
return 6 / (b.width / d.doc.w)
|
||
}
|
||
|
||
// 文字输入框必须贴着点击点出现。早先用 canvasStack 的矩形换算,而 stack 尺寸是
|
||
// (imgW + 2*overlayPad)*scale、图片在 stack 内还额外偏移 pad*scale —— 比例偏小又漏偏移,
|
||
// 输入框整体跑到点击点的左上方。
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
const clearPt = await imgToScreen(90, 8)
|
||
await page.mouse.click(clearPt.x, clearPt.y)
|
||
await page.waitForTimeout(180)
|
||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||
await page.waitForTimeout(180)
|
||
// 测试画布只有 96×64,取左下角的空白区(已存在的两个矩形都在上半部)
|
||
const clickPt = await imgToScreen(12, 56)
|
||
await page.mouse.click(clickPt.x, clickPt.y)
|
||
await page.waitForTimeout(260)
|
||
const inpBox = await page.locator('.iwb-editor-text-input').boundingBox()
|
||
if (!inpBox) throw new Error('点了画布但文字输入框没有出现,后面的定位断言无从谈起')
|
||
// 输入框内「文字起点」= 左边框 2px + 左内边距 8px、上边框 2px + 上内边距 4px
|
||
const dxInp = inpBox.x + 10 - clickPt.x
|
||
const dyInp = inpBox.y + 6 - clickPt.y
|
||
check('文字输入框贴着点击点出现(不再偏到左上方)',
|
||
Math.abs(dxInp) <= 3 && Math.abs(dyInp) <= 3,
|
||
'dx=' + dxInp.toFixed(1) + ' dy=' + dyInp.toFixed(1))
|
||
await page.keyboard.press('Escape')
|
||
await page.waitForTimeout(180)
|
||
check('输入框按 Esc 取消后不留下空文字对象', (await dbg()).texts.length === 0,
|
||
'texts=' + (await dbg()).texts.length)
|
||
|
||
// 多行文字:Shift+Enter 换行(textarea)→ 落成两行,包围盒高度约为单行两倍
|
||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||
let p0 = await imgToScreen(8, 8)
|
||
await page.mouse.click(p0.x, p0.y)
|
||
await page.waitForTimeout(150)
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-text-input')
|
||
el.focus()
|
||
el.value = 'AB\nCD'
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
})
|
||
await page.keyboard.press('Enter')
|
||
await page.waitForTimeout(220)
|
||
let vdbg = await dbg()
|
||
const multiLine = vdbg.texts.length === 1 && vdbg.texts[0].text.indexOf('\n') > 0
|
||
const singleH = vdbg.texts.length ? vdbg.texts[0].fontSize * 1.25 : 0
|
||
check('文字支持多行(Shift+Enter 换行,包围盒高 ≈ 两行)',
|
||
multiLine && vdbg.texts[0].box.h >= singleH * 2 - 2,
|
||
multiLine ? 'h=' + vdbg.texts[0].box.h + ' 单行=' + Math.round(singleH) : JSON.stringify(vdbg.texts))
|
||
|
||
// ---- v1.14 字体选择:系统字体族(黑 / 宋 / 楷 / 圆)----
|
||
// 为什么只做系统字体:宿主 CSP 是 default-src 'self',font-src 回落它,第三方字体 CDN
|
||
// 会被浏览器直接拦掉;中文字体 2–64MB(本机宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB),
|
||
// 内联进 389KB 的插件不现实。系统字体栈 0 字节、同步可用,没有「字体没加载完就
|
||
// measureText」导致选中框和字形错位的时序问题 —— 这是内置字体方案最大的坑。
|
||
const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]'
|
||
const FAM_KEYS = ['sans', 'serif', 'kai', 'round']
|
||
const famCount = await page.locator(FAM_SEL).count()
|
||
const famOpts = famCount ? await page.locator(FAM_SEL + ' option').allTextContents() : []
|
||
check('选中文字后选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体',
|
||
famCount === 1 && famOpts.join(',') === '黑体,宋体,楷体,圆体',
|
||
'count=' + famCount + ' opts=' + famOpts.join(','))
|
||
|
||
// 切换字体要同时做两件事:写进选中的这段文字 + 成为下一段新文字的默认值
|
||
await page.selectOption(FAM_SEL, 'kai')
|
||
await page.waitForTimeout(240)
|
||
let famDbg = await dbg()
|
||
check('下拉切换字体写到选中文字,并同步「新建文字默认字体」',
|
||
famDbg.texts[0].fontFamily === 'kai' && famDbg.textDefaults.family === 'kai',
|
||
'obj=' + famDbg.texts[0].fontFamily + ' default=' + famDbg.textDefaults.family)
|
||
|
||
// 真实点击下拉框(不选任何项)不能改动字体。
|
||
// 这条是给 v1.14.1 兜底的:click 委托原先用 closest('[data-opt-text]') 判断「文字样式按钮」,
|
||
// <select> 自己带这个属性 → 被当成按钮 → 取 dataset.value(select 上没有)= undefined
|
||
// → applyTextStyle('fontFamily', undefined) → fontKeyOf 收敛成 'sans'。
|
||
// 症状是「点开下拉看一眼,字体就被打回黑体」,而程序化 selectOption 直接派发 change、
|
||
// 绕过了 click,所以 v1.14.0 的 5 条字体用例全绿却漏掉了它。
|
||
await page.evaluate((s) => { document.querySelector(s).__probeMark = 'origin' }, FAM_SEL)
|
||
await page.locator(FAM_SEL).click({ force: true })
|
||
await page.waitForTimeout(200)
|
||
const famClickDbg = await dbg()
|
||
const famNodeKept = await page.evaluate((s) => {
|
||
const el = document.querySelector(s)
|
||
return Boolean(el && el.__probeMark === 'origin')
|
||
}, FAM_SEL)
|
||
const famValKept = await page.locator(FAM_SEL).inputValue()
|
||
check('点开字体下拉不会改动字体(下拉不是按钮,不能被 click 委托当成开关)',
|
||
famClickDbg.texts[0].fontFamily === 'kai' && famValKept === 'kai',
|
||
'obj=' + famClickDbg.texts[0].fontFamily + ' select=' + famValKept)
|
||
check('切换字体不重建选项栏(连续切换不必反复重点、焦点不丢)', famNodeKept, 'node replaced=' + !famNodeKept)
|
||
await page.evaluate(() => { if (document.activeElement && document.activeElement.blur) document.activeElement.blur() })
|
||
|
||
// 一次切换 = 一步历史
|
||
// 注意断言只查对象、不查 textDefaults:快照(history.js#snapshotState)只存
|
||
// texts/shapes/bitmaps/layerOrder,不含「新建文字默认值」—— 字重、对齐、行距
|
||
// 都是同一行为,撤销回到对象上一步的样子,但"下一段文字用什么样式"不会跟着回退。
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(240)
|
||
famDbg = await dbg()
|
||
check('Ctrl+Z 撤销字体切换,文字对象回到上一个字体',
|
||
famDbg.texts[0].fontFamily === 'sans',
|
||
'obj=' + famDbg.texts[0].fontFamily)
|
||
|
||
// 中文是全角等宽:换字体不改字宽,所以切字体不会让已有的标注版面跳动。
|
||
// (拉丁字母和数字是比例宽,会伸缩 —— 这也是选择「左上角锚定」而不是居中的理由。)
|
||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||
const cnPt = await imgToScreen(4, 30)
|
||
await page.mouse.click(cnPt.x, cnPt.y)
|
||
await page.waitForTimeout(220)
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-text-input')
|
||
el.focus()
|
||
el.value = '测试'
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
})
|
||
await page.keyboard.press('Enter')
|
||
await page.waitForTimeout(320)
|
||
const cnBefore = ((await dbg()).texts.find(t => t.text === '测试') || {}).box
|
||
await page.selectOption(FAM_SEL, 'serif')
|
||
await page.waitForTimeout(240)
|
||
const cnAfter = ((await dbg()).texts.find(t => t.text === '测试') || {}).box
|
||
check('换字体不改变中文宽度(全角等宽,版面不跳动)',
|
||
cnBefore && cnAfter && Math.abs(cnAfter.w - cnBefore.w) <= 1,
|
||
(cnBefore ? cnBefore.w : '?') + ' → ' + (cnAfter ? cnAfter.w : '?'))
|
||
|
||
// 脏值防御:不认识的 fontFamily 必须收敛回默认。否则整串 ctx.font 会失效、
|
||
// 静默退回浏览器默认字体 —— 画面上看不出报错,排查成本极高。
|
||
const badDispatch = await page.evaluate(() => {
|
||
const s = document.querySelector('.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]')
|
||
if (!s) return 'no-select'
|
||
const o = document.createElement('option')
|
||
o.value = 'NotAFont'
|
||
o.textContent = 'NotAFont'
|
||
s.appendChild(o)
|
||
s.value = 'NotAFont'
|
||
s.dispatchEvent(new Event('change', { bubbles: true }))
|
||
return 'dispatched'
|
||
})
|
||
await page.waitForTimeout(200)
|
||
const badDbg = await dbg()
|
||
check('不认识的字体值被收敛回默认(脏值不会写进 ctx.font)',
|
||
badDispatch === 'dispatched' && badDbg.texts.length > 0 &&
|
||
badDbg.texts.every(t => FAM_KEYS.indexOf(t.fontFamily) >= 0),
|
||
JSON.stringify(badDbg.texts.map(t => t.fontFamily)))
|
||
|
||
// 清理:这一小段是为字体用例新建的,删掉避免污染后面的像素断言
|
||
await page.keyboard.press('Delete')
|
||
await page.waitForTimeout(200)
|
||
|
||
// 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。
|
||
// 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区,
|
||
// 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。
|
||
// 清选中用「切到别的工具再切回来」:画布上早就有别的用例留下的图形,
|
||
// 靠「点空白」清选中会点到它们(点位随用例顺序变化,很容易变成假失败)。
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await page.waitForTimeout(120)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.waitForTimeout(220)
|
||
const selIconNoSel = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||
check('选择工具未选中元素时仍有全选/反选/取消三个图标(且不重复)',
|
||
selIconNoSel === 3, 'count=' + selIconNoSel + ' 选中=' + (await dbg()).selectedShapeId)
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
p0 = await imgToScreen(10, 12)
|
||
await page.mouse.click(p0.x, p0.y)
|
||
await page.waitForTimeout(200)
|
||
vdbg = await dbg()
|
||
check('选中文字后选项栏出整套文字样式控件(字重/对齐/行距/描边/底色)',
|
||
Boolean(vdbg.selectedTextId) &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-text="fontWeight"]').count()) === 3 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-text="align"]').count()) === 3 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').count()) === 1 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt="textLineHeight"]').count()) >= 1 &&
|
||
(await page.locator('.iwb-editor-optionbar-body [data-opt-color]').count()) === 2)
|
||
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-text="fontWeight"][data-value="900"]').click()
|
||
await page.waitForTimeout(150)
|
||
vdbg = await dbg()
|
||
const boldBefore = vdbg.texts[0].fontWeight
|
||
check('点「特粗」改选中文字的字重', boldBefore === '900', 'fontWeight=' + boldBefore)
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(200)
|
||
vdbg = await dbg()
|
||
check('字重改动可撤销', vdbg.texts[0].fontWeight !== '900', 'fontWeight=' + vdbg.texts[0].fontWeight)
|
||
|
||
// 撤销会清掉选中态(历史恢复后不再高亮),要继续改样式得重新选中
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
p0 = await imgToScreen(10, 12)
|
||
await page.mouse.click(p0.x, p0.y)
|
||
await page.waitForTimeout(200)
|
||
vdbg = await dbg()
|
||
const hBefore = vdbg.texts[0].box.h
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="textStrokeWidth"]')
|
||
el.value = '6'
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(200)
|
||
vdbg = await dbg()
|
||
check('描边走选项栏生效且包围盒随之变大(含描边外扩)',
|
||
vdbg.texts[0].strokeWidth === 6 && vdbg.texts[0].box.h > hBefore,
|
||
'sw=' + vdbg.texts[0].strokeWidth + ' h ' + hBefore + '→' + vdbg.texts[0].box.h)
|
||
|
||
// 底色块
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click()
|
||
await page.waitForTimeout(200)
|
||
vdbg = await dbg()
|
||
const hBg = vdbg.texts[0].box.h
|
||
check('底色块开关生效(padding 让包围盒继续变大)',
|
||
vdbg.texts[0].bgFill === true && hBg > vdbg.texts[0].box.h - 1 && hBg > 0,
|
||
'bgFill=' + vdbg.texts[0].bgFill + ' h=' + hBg)
|
||
|
||
// 只改底色颜色、不点「底色」开关时,画布上原本什么都不会变 —— 用户会以为底色坏了
|
||
// 或被别的颜色盖住。现在选色即自动启用,按钮的 active 态也要跟着亮。
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click()
|
||
await page.waitForTimeout(180)
|
||
const bgOff = (await dbg()).texts[0].bgFill
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body [data-opt-color="bgColor"]')
|
||
el.value = '#ffd400'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(220)
|
||
vdbg = await dbg()
|
||
const bgBtnOn = await page.evaluate(() =>
|
||
document.querySelector('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').classList.contains('active'))
|
||
check('只选底色颜色就自动开启底色(不必先点开关)',
|
||
bgOff === false && vdbg.texts[0].bgFill === true && vdbg.texts[0].bgColor === '#ffd400' && bgBtnOn,
|
||
'关前=' + bgOff + ' 改色后 bgFill=' + vdbg.texts[0].bgFill +
|
||
' bgColor=' + vdbg.texts[0].bgColor + ' 按钮 active=' + bgBtnOn)
|
||
|
||
// ---- v1.10:三个色块的「生效 / 未生效」语义 ----
|
||
// 用户反馈「字体颜色有 3 个位置,那个黑色应该换成默认的参数」:底色默认曾是纯黑 #000000,
|
||
// 关闭时也显示成一块死黑,看起来就像「又多了一个字体颜色」。现在默认值单点定义,
|
||
// 且没生效的色块显示为灰色斜纹(不再显示颜色本身),语义变成「这里还没有颜色」。
|
||
const colorMeta = await page.evaluate(() => {
|
||
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||
const out = {}
|
||
body.querySelectorAll('[data-opt-color]').forEach(el => {
|
||
out[el.dataset.optColor] = { off: el.classList.contains('is-off'), value: el.value }
|
||
})
|
||
return { defaults: window.__iwbEditor.__debug().textDefaults, swatches: out }
|
||
})
|
||
check('文字底色默认不再是纯黑(默认值收口到 text.js,近黑 #101014 + 68% 透明)',
|
||
colorMeta.defaults.bgColor !== '#000000' && /^#[0-9a-f]{6}$/.test(colorMeta.defaults.bgColor) &&
|
||
Math.abs(colorMeta.defaults.bgAlpha - 0.68) < 1e-6,
|
||
JSON.stringify(colorMeta.defaults))
|
||
|
||
// 关掉底色 + 描边宽度归零 → 两个色块都应变成「未启用」
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click()
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="textStrokeWidth"]')
|
||
el.value = '0'
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(200)
|
||
const offStates = await page.evaluate(() => [...document.querySelectorAll('.iwb-editor-optionbar-body [data-opt-color]')]
|
||
.map(el => ({ k: el.dataset.optColor, off: el.classList.contains('is-off') })))
|
||
check('描边宽度为 0 / 底色关闭时,对应色块标记为「未启用」(不再显示颜色本身)',
|
||
offStates.length === 2 && offStates.every(o => o.off), JSON.stringify(offStates))
|
||
|
||
// ---- v1.12:文字的三个颜色(文字 / 描边 / 底色)各自可调 ----
|
||
// 用户原话:「文本的内容需要描边与文字颜色的设定,还多一个文本框的底色,这里 3 个
|
||
// 颜色你来修正下,现在文本不支持描边与字体色切换」。文字对象本来就有三个颜色字段,
|
||
// 上一版把它们塞进「描边 / 填充」两格,第二格其实是形状的填充,点了毫无反应。
|
||
const textPair = await page.evaluate(() => {
|
||
const pair = document.querySelector('.iwb-editor-color-pair')
|
||
const d = window.__iwbEditor.__debug()
|
||
return {
|
||
mode: pair.dataset.colorMode,
|
||
tool: d.tool, selText: d.selectedTextId, target: d.colorTarget, texts: d.texts.length,
|
||
visible: [...pair.querySelectorAll('.iwb-editor-color-btn')].filter(b => b.offsetParent !== null).map(b => b.dataset.colorSlot)
|
||
}
|
||
})
|
||
check('选中文字时工具栏给出「文字 / 描边 / 底色」三格',
|
||
textPair.mode === 'triple' && textPair.visible.join(',') === 'stroke,fill,bg', JSON.stringify(textPair))
|
||
|
||
const textChips = await page.evaluate(() => {
|
||
const cls = s => document.querySelector('.iwb-editor-color-pair [data-color-slot="' + s + '"]').className
|
||
return { fill: cls('fill'), bg: cls('bg') }
|
||
})
|
||
check('描边宽度 0 / 底色关闭时,文字的描边与底色格是「无」斜杠态(不露颜色本身)',
|
||
/is-none/.test(textChips.fill) && /is-none/.test(textChips.bg), JSON.stringify(textChips))
|
||
|
||
const textColorBefore = (await dbg()).texts[0].color
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
|
||
await page.waitForTimeout(220)
|
||
const popTextTarget = await page.evaluate(() => {
|
||
const pop = document.querySelector('.iwb-editor-color-pop')
|
||
const tab = pop.querySelector('.iwb-color-pop-tab[data-color-slot="fill"]')
|
||
const bgTab = pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]')
|
||
return {
|
||
open: !pop.hidden,
|
||
fillActive: tab.classList.contains('active'),
|
||
fillLabel: tab.querySelector('.iwb-color-pop-tab-label').textContent,
|
||
bgVisible: !bgTab.hidden,
|
||
// v1.20:去色不再 hidden,改成「在不在 + 能不能用」
|
||
noneVisible: !!pop.querySelector('[data-color-none]').offsetParent,
|
||
noneUsable: !pop.querySelector('[data-color-none]').disabled
|
||
}
|
||
})
|
||
check('点文字的「描边」格:色板目标是描边(tab 写「描边」),底色 tab 同时可选,去色可用',
|
||
popTextTarget.open && popTextTarget.fillActive && popTextTarget.fillLabel === '描边' &&
|
||
popTextTarget.bgVisible && popTextTarget.noneVisible && popTextTarget.noneUsable,
|
||
JSON.stringify(popTextTarget))
|
||
|
||
// v1.20(用户 2026-11-10 截图):文字色这一格去不掉色,但按钮必须**留在原位变灰**,
|
||
// 不能整颗消失 —— 消失会让色板每切一次工具就重排,位置记不住。
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(200)
|
||
const noneDisabledOnTextColor = await page.evaluate(() => {
|
||
const n = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
||
return {
|
||
visible: !!n.offsetParent, disabled: n.disabled, dim: Number(getComputedStyle(n).opacity),
|
||
title: n.title, bgTabStillHidden: document.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]').hidden
|
||
}
|
||
})
|
||
check('文字色上下文:去色仍在第一格、只是置灰 disabled(说明原因),不整颗消失',
|
||
noneDisabledOnTextColor.visible && noneDisabledOnTextColor.disabled &&
|
||
noneDisabledOnTextColor.dim < 0.6 && /去色不可用/.test(noneDisabledOnTextColor.title),
|
||
JSON.stringify(noneDisabledOnTextColor))
|
||
// 开发用:ANNOT_SHOT3=/tmp/pop-text.png 出「文字工具三 tab + 去色置灰」的效果图(用户截图那个场景)
|
||
if (process.env.ANNOT_SHOT3) await page.locator('.iwb-editor-color-pop').screenshot({ path: process.env.ANNOT_SHOT3 })
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
|
||
await page.waitForTimeout(200)
|
||
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||
el.value = '#00a3ff'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(300)
|
||
const textStroke = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const t = d.texts[0]
|
||
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
||
const opt = document.querySelector('.iwb-editor-optionbar-body [data-opt-color="strokeColor"]')
|
||
return {
|
||
sw: t.strokeWidth, sc: t.strokeColor, color: t.color, main: d.color, target: d.colorTarget,
|
||
chipBg: chip.querySelector('i').style.backgroundColor, chipCls: chip.className,
|
||
optVal: opt.value, optOff: opt.classList.contains('is-off')
|
||
}
|
||
})
|
||
check('给文字选描边色:写进 strokeColor,描边宽度自动补 6px,文字色不受影响',
|
||
textStroke.sc === '#00a3ff' && textStroke.sw === 6 && textStroke.color === textColorBefore &&
|
||
textStroke.main !== '#00a3ff' && textStroke.optVal === '#00a3ff' && textStroke.optOff === false,
|
||
JSON.stringify(textStroke) + ' 文字色改前=' + textColorBefore)
|
||
check('描边格脱离斜杠态并显示真实颜色(工具栏与选项栏同一份值)',
|
||
!/is-none/.test(textStroke.chipCls) && /0, 163, 255/.test(textStroke.chipBg), textStroke.chipCls)
|
||
|
||
// 底色:同一套色板,第三格独立写 bgColor
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="bg"]').click()
|
||
await page.waitForTimeout(220)
|
||
const popBgTarget = await page.evaluate(() => {
|
||
const pop = document.querySelector('.iwb-editor-color-pop')
|
||
return {
|
||
bgActive: pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]').classList.contains('active'),
|
||
label: pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"] .iwb-color-pop-tab-label').textContent
|
||
}
|
||
})
|
||
check('点文字的「底色」格:色板切到底色', popBgTarget.bgActive && popBgTarget.label === '底色', JSON.stringify(popBgTarget))
|
||
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||
el.value = '#123456'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(320)
|
||
const textBg = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const t = d.texts[0]
|
||
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="bg"]')
|
||
const bgBtn = document.querySelector('.iwb-editor-optionbar-body [data-opt-text="bgFill"]')
|
||
return {
|
||
bgColor: t.bgColor, bgFill: t.bgFill, sc: t.strokeColor,
|
||
chipBg: chip.querySelector('i').style.backgroundColor, chipCls: chip.className,
|
||
bgBtnOn: bgBtn.classList.contains('active')
|
||
}
|
||
})
|
||
check('给文字选底色:写进 bgColor 并自动开启底色块(选项栏「底色」按钮同步点亮)',
|
||
textBg.bgColor === '#123456' && textBg.bgFill === true && textBg.sc === '#00a3ff' && textBg.bgBtnOn,
|
||
JSON.stringify(textBg))
|
||
check('底色格显示真实颜色(半透明显示,不是实心块)',
|
||
!/is-none/.test(textBg.chipCls) && /18, 52, 86/.test(textBg.chipBg), textBg.chipCls)
|
||
|
||
// 第一格「文字色」:改它不能顺手动到描边色
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(200)
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||
el.value = '#ff00aa'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(300)
|
||
const textColorSet = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const t = d.texts[0]
|
||
return { color: t.color, main: d.color, sc: t.strokeColor, bg: t.bgColor }
|
||
})
|
||
check('文字色 / 描边色 / 底色三格互不串(改一格不动另外两格)',
|
||
textColorSet.color === '#ff00aa' && textColorSet.main === '#ff00aa' &&
|
||
textColorSet.sc === '#00a3ff' && textColorSet.bg === '#123456', JSON.stringify(textColorSet))
|
||
|
||
// 「无」在底色格 = 关掉底色块,颜色留着
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="bg"]').click()
|
||
await page.waitForTimeout(200)
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||
await page.waitForTimeout(260)
|
||
const bgNone = await page.evaluate(() => {
|
||
const t = window.__iwbEditor.__debug().texts[0]
|
||
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="bg"]')
|
||
return { bgFill: t.bgFill, bgColor: t.bgColor, cls: chip.className, noneActive: document.querySelector('.iwb-editor-color-pop [data-color-none]').classList.contains('active') }
|
||
})
|
||
check('底色格点「无」:关掉底色块、颜色留着,格子回到斜杠态',
|
||
bgNone.bgFill === false && bgNone.bgColor === '#123456' && /is-none/.test(bgNone.cls) && bgNone.noneActive,
|
||
JSON.stringify(bgNone))
|
||
|
||
// 切回形状 / 画笔:第三格必须收起来,别留一个空位让人猜
|
||
await page.keyboard.press('Escape')
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await page.waitForTimeout(220)
|
||
const rectPairMode = await page.evaluate(() => {
|
||
const pair = document.querySelector('.iwb-editor-color-pair')
|
||
return {
|
||
mode: pair.dataset.colorMode,
|
||
visible: [...pair.querySelectorAll('.iwb-editor-color-btn')].filter(b => b.offsetParent !== null).map(b => b.dataset.colorSlot)
|
||
}
|
||
})
|
||
check('切回矩形工具:工具栏回到「描边 + 填充」两格,底色格收起',
|
||
rectPairMode.mode === 'pair' && rectPairMode.visible.join(',') === 'stroke,fill', JSON.stringify(rectPairMode))
|
||
|
||
// 选区命令(全选/反选/取消)属于像素选区,必须待在选区工具里
|
||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||
await page.waitForTimeout(160)
|
||
const marqueeIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||
await page.locator('.iwb-editor-tool[data-tool="lasso"]').click()
|
||
await page.waitForTimeout(160)
|
||
const lassoIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||
check('选区工具(矩形 / 套索)都有全选、反选、取消选区三个按钮',
|
||
marqueeIcons === 3 && lassoIcons === 3, 'marquee=' + marqueeIcons + ' lasso=' + lassoIcons)
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
p0 = await imgToScreen(10, 12)
|
||
await page.mouse.click(p0.x, p0.y)
|
||
await page.waitForTimeout(220)
|
||
const textSelIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||
check('选中文字时选项栏不再冒出选区命令按钮(那三个命令跟文字对象无关)',
|
||
textSelIcons === 0, 'count=' + textSelIcons)
|
||
|
||
// 选中框必须是实线:虚线圈会被当成「莫名其妙多出来的像素选区」。
|
||
// 沿选中框顶边扫一行橙色像素,虚线(6/3)覆盖率约 0.6~0.7,实线接近 1。
|
||
const frameCoverage = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const cv = document.querySelector('.iwb-editor-crop-overlay')
|
||
if (!d.selectedTextId) return { err: 'no-selected-text' }
|
||
if (!cv) return { err: 'no-overlay' }
|
||
const ctx = cv.getContext('2d')
|
||
const img = ctx.getImageData(0, 0, cv.width, cv.height).data
|
||
const W = cv.width
|
||
// 不按图片坐标换算:overlay 画布含 overlayPad 外扩,直接全画布扫,
|
||
// 找第一条「橙色连续段」,再量这一段的覆盖率 —— 实线接近 1,6/3 虚线约 0.6~0.7。
|
||
const isOrange = (i) => img[i + 3] > 60 && img[i] > 170 && img[i + 1] > 100 && img[i + 2] < 130
|
||
for (let y = 0; y < cv.height; y++) {
|
||
const base = y * W * 4
|
||
let first = -1, last = -1, n = 0
|
||
for (let x = 0; x < W; x++) {
|
||
if (isOrange(base + x * 4)) { if (first < 0) first = x; last = x; n++ }
|
||
}
|
||
if (n >= 20 && last - first >= 40) {
|
||
return { ratio: +(n / (last - first + 1)).toFixed(2), n, span: last - first + 1, y }
|
||
}
|
||
}
|
||
return { err: 'no-orange-row' }
|
||
})
|
||
check('对象选中框是实线(虚线的语义是像素选区,会把用户绕晕)',
|
||
!!frameCoverage && frameCoverage.ratio >= 0.85, JSON.stringify(frameCoverage))
|
||
|
||
// 吸附:画一个实心矩形,拖到画布中心附近应被精确吸到中心并出现参考线
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await page.waitForTimeout(100)
|
||
if (await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').getAttribute('class').then(c => c.indexOf('active') < 0)) {
|
||
await page.locator('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').click()
|
||
}
|
||
let pa = await imgToScreen(6, 6)
|
||
let pb = await imgToScreen(26, 26)
|
||
await page.mouse.move(pa.x, pa.y)
|
||
await page.mouse.down()
|
||
await page.mouse.move(pb.x, pb.y, { steps: 6 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(200)
|
||
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
pa = await imgToScreen(16, 16)
|
||
await page.mouse.click(pa.x, pa.y)
|
||
// 等过 380ms 的双击窗口:同一个点连点会被判成双击(双击属于「进对象编辑」,
|
||
// 不该接管拖动),这里要测的是单击选中后的拖动
|
||
await page.waitForTimeout(420)
|
||
const rectGeo = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const s = d.shapes[d.shapes.length - 1]
|
||
return s ? { id: s.id } : null
|
||
})
|
||
const tol = await snapTol()
|
||
const sBox = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const cv = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas.iwb-editor-vec-canvas')]
|
||
return { doc: d.doc, shapes: d.shapes.length }
|
||
})
|
||
// 抓矩形中心,拖到「画布中心 + tol/2」:若吸附生效,中心会精确回到画布中心
|
||
const rectInfo = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const sel = d.selectedShapeId
|
||
return sel ? { sel, doc: d.doc } : { doc: d.doc }
|
||
})
|
||
const center = { x: sBox.doc.w / 2, y: sBox.doc.h / 2 }
|
||
// 用轴对齐假设取矩形中心:从墨迹范围读更稳(矩形是自己画的 6..26)
|
||
const inkBox = await page.evaluate(() => {
|
||
const cv = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas.iwb-editor-vec-canvas')]
|
||
let best = null
|
||
for (const c of cv) {
|
||
const cx = c.getContext('2d')
|
||
const d = cx.getImageData(0, 0, c.width, c.height).data
|
||
let minX = 1e9, minY = 1e9, maxX = -1, maxY = -1
|
||
for (let y = 0; y < c.height; y++) for (let x = 0; x < c.width; x++) {
|
||
if (d[(y * c.width + x) * 4 + 3] > 20) { if (x < minX) minX = x; if (x > maxX) maxX = x; if (y < minY) minY = y; if (y > maxY) maxY = y }
|
||
}
|
||
if (maxX >= 0) best = { minX, minY, maxX, maxY, w: maxX - minX + 1, h: maxY - minY + 1 }
|
||
}
|
||
return best
|
||
})
|
||
const rc = { x: (inkBox.minX + inkBox.maxX + 1) / 2, y: (inkBox.minY + inkBox.maxY + 1) / 2 }
|
||
const grab = await imgToScreen(rc.x, rc.y)
|
||
const destImg = { x: center.x + tol / 2, y: center.y + tol / 2 }
|
||
const dest = await imgToScreen(destImg.x, destImg.y)
|
||
await page.mouse.move(grab.x, grab.y)
|
||
await page.mouse.down()
|
||
await page.mouse.move(grab.x + 3, grab.y + 3, { steps: 3 })
|
||
await page.mouse.move(dest.x, dest.y, { steps: 8 })
|
||
await page.waitForTimeout(160)
|
||
const gMid = (await dbg()).guides
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(220)
|
||
const gEnd = (await dbg()).guides
|
||
|
||
// 松手后按墨迹中心核对:应该正好落在画布中心
|
||
const inkAfter = await page.evaluate(() => {
|
||
const cv = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas.iwb-editor-vec-canvas')]
|
||
let best = null
|
||
for (const c of cv) {
|
||
const cx = c.getContext('2d')
|
||
const d = cx.getImageData(0, 0, c.width, c.height).data
|
||
let minX = 1e9, minY = 1e9, maxX = -1, maxY = -1
|
||
for (let y = 0; y < c.height; y++) for (let x = 0; x < c.width; x++) {
|
||
if (d[(y * c.width + x) * 4 + 3] > 20) { if (x < minX) minX = x; if (x > maxX) maxX = x; if (y < minY) minY = y; if (y > maxY) maxY = y }
|
||
}
|
||
if (maxX >= 0) best = { minX, minY, maxX, maxY }
|
||
}
|
||
return best
|
||
})
|
||
const cAfter = { x: (inkAfter.minX + inkAfter.maxX + 1) / 2, y: (inkAfter.minY + inkAfter.maxY + 1) / 2 }
|
||
check('拖到画布中心附近会被精确吸附(中心误差 < 1px)',
|
||
gMid.length >= 1 && Math.abs(cAfter.x - center.x) < 1 && Math.abs(cAfter.y - center.y) < 1,
|
||
'guides=' + JSON.stringify(gMid) + ' 中心=' + Math.round(cAfter.x) + ',' + Math.round(cAfter.y) + ' 期望=' + center.x + ',' + center.y)
|
||
check('松手后参考线清除', gEnd.length === 0, JSON.stringify(gEnd))
|
||
|
||
// Alt 拖动不吸附
|
||
const grab2 = await imgToScreen(cAfter.x, cAfter.y)
|
||
await page.keyboard.down('Alt')
|
||
await page.mouse.move(grab2.x, grab2.y)
|
||
await page.mouse.down()
|
||
await page.mouse.move(grab2.x + 4, grab2.y + 4, { steps: 4 })
|
||
await page.waitForTimeout(140)
|
||
const gAlt = (await dbg()).guides
|
||
await page.mouse.up()
|
||
await page.keyboard.up('Alt')
|
||
check('按住 Alt 拖动时不吸附(无参考线)', gAlt.length === 0, JSON.stringify(gAlt))
|
||
|
||
// 圆角:设半径后角落被切掉,墨迹变少
|
||
// 所有矢量层墨迹的总和:前面用例画过别的矩形,只取「最大那层」会量错对象
|
||
const inkCount = () => page.evaluate(() => {
|
||
const cv = [...document.querySelectorAll('.iwb-editor-canvas-stack > canvas.iwb-editor-vec-canvas')]
|
||
let total = 0
|
||
for (const c of cv) {
|
||
const d = c.getContext('2d').getImageData(0, 0, c.width, c.height).data
|
||
for (let i = 3; i < d.length; i += 4) if (d[i] > 20) total++
|
||
}
|
||
return total
|
||
})
|
||
const inkSharp = await inkCount()
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="shapeRadius"]')
|
||
el.value = '6'
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(220)
|
||
const inkRound = await inkCount()
|
||
const radiusVal = (await dbg()).shapes.map(s => s.radius).filter(r => r > 0)
|
||
check('矩形圆角生效(角落被切,墨迹减少)',
|
||
radiusVal.length === 1 && inkRound < inkSharp,
|
||
'radius=' + JSON.stringify(radiusVal) + ' ink ' + inkSharp + '→' + inkRound)
|
||
|
||
// 最近使用颜色
|
||
await page.locator('[data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(150)
|
||
await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click()
|
||
await page.waitForTimeout(200)
|
||
const recents = (await dbg()).recentColors
|
||
const recentsInPop = await page.locator('.iwb-editor-color-pop .iwb-editor-recent-colors [data-panel-color]').count()
|
||
// 开发用:ANNOT_SHOT2=/tmp/pop-full.png 出一张「去色可见 + 最近色铺满两排」的完整效果图。
|
||
// 最近色要长期用才攒得满,这里临时补到 16 个纯为出图,不改 S.recentColors / settings。
|
||
if (process.env.ANNOT_SHOT2) {
|
||
await page.evaluate(() => {
|
||
const rec = document.querySelector('.iwb-editor-color-pop .iwb-editor-recent-colors')
|
||
const group = rec.closest('.iwb-color-group')
|
||
const list = ['#ffd400', '#e34d59', '#1677ff', '#0f9d58', '#6b4fbb', '#c0392b',
|
||
'#ff8a00', '#4cd964', '#00bfa5', '#4488ff', '#aa44ff', '#ff66aa',
|
||
'#d0d0d0', '#808080', '#ffffff', '#000000']
|
||
rec.innerHTML = list.map((c) =>
|
||
`<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="最近使用 ${c}"></button>`).join('')
|
||
rec.hidden = false
|
||
if (group) group.hidden = false
|
||
})
|
||
await page.waitForTimeout(120)
|
||
await page.locator('.iwb-editor-color-pop').screenshot({ path: process.env.ANNOT_SHOT2 })
|
||
}
|
||
await page.keyboard.press('Escape')
|
||
await page.waitForTimeout(120)
|
||
check('选过的颜色进入「最近使用」并出现在色板弹层',
|
||
recents[0] === '#ffd400' && recentsInPop >= 1,
|
||
JSON.stringify(recents) + ' 弹层色块=' + recentsInPop)
|
||
|
||
// 复制到剪贴板:harness 跑在 about:blank(非安全上下文),
|
||
// 这里只验「按钮存在 + 点击有明确反馈 + 不抛错」,真安全上下文由本地 http 探针覆盖
|
||
// ---- v1.10:矢量图形也有描边色 / 填充色 ----
|
||
// 用户要求「把其他的矢量图形也加上描边与填充色属性,工具栏上加描边色设置」。
|
||
// 设计:描边色 = 主色(左侧色板 / 吸管 / 选项栏一个真相源),填充色独立存形状的
|
||
// fillColor,没单独设过就跟随描边色 —— 于是「切实心 = 同色实心」,不会突兀。
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
await page.waitForTimeout(120)
|
||
const shapeColorUI = await page.evaluate(() => {
|
||
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||
return {
|
||
stroke: body.querySelectorAll('[data-shape-color="stroke"]').length,
|
||
fill: body.querySelectorAll('[data-shape-color="fill"]').length
|
||
}
|
||
})
|
||
check('矩形工具的选项栏就带描边色 / 填充色块(画之前就能定色)',
|
||
shapeColorUI.stroke === 1 && shapeColorUI.fill === 1, JSON.stringify(shapeColorUI))
|
||
|
||
pa = await imgToScreen(62, 6)
|
||
pb = await imgToScreen(90, 28)
|
||
await page.mouse.move(pa.x, pa.y)
|
||
await page.mouse.down()
|
||
await page.mouse.move(pb.x, pb.y, { steps: 6 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(300)
|
||
const shapeFresh = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
return d.shapes[d.shapes.length - 1]
|
||
})
|
||
check('新建图形的填充默认「跟随描边色」(fillColor=null),不是写死某个填充色',
|
||
shapeFresh.fillColor === null, JSON.stringify({ fill: shapeFresh.fill, fillColor: shapeFresh.fillColor }))
|
||
|
||
// 数「目标颜色」的像素:矢量画布含 overlayPad 外扩,按图片坐标换算单点会采到别处,
|
||
// 直接全画布统计同色像素最稳(0 → 上千,量级差别足够断言)
|
||
const countColorInVec = (rgb, tol) => page.evaluate(({ rgb, tol }) => {
|
||
let n = 0
|
||
for (const cv of [...document.querySelectorAll('.iwb-editor-vec-canvas')]) {
|
||
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||
for (let i = 0; i < d.length; i += 4) {
|
||
if (d[i + 3] > 200 && Math.abs(d[i] - rgb[0]) < tol && Math.abs(d[i + 1] - rgb[1]) < tol && Math.abs(d[i + 2] - rgb[2]) < tol) n++
|
||
}
|
||
}
|
||
return n
|
||
}, { rgb, tol })
|
||
|
||
const greenBefore = await countColorInVec([34, 204, 85], 8)
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||
el.value = '#22cc55'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(280)
|
||
const shapeFilled = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const s = d.shapes[d.shapes.length - 1]
|
||
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||
return {
|
||
fill: s.fill, fillColor: s.fillColor,
|
||
fillBtnOn: !!body.querySelector('[data-opt-toggle="fill"]').classList.contains('active'),
|
||
fillSwatchOff: body.querySelector('[data-shape-color="fill"]').classList.contains('is-off')
|
||
}
|
||
})
|
||
const greenAfter = await countColorInVec([34, 204, 85], 8)
|
||
check('选填充色即自动切实心,画面上真的是这个颜色(不是只改了个字段)',
|
||
shapeFilled.fill === true && shapeFilled.fillColor === '#22cc55' && greenBefore === 0 && greenAfter > 200,
|
||
JSON.stringify(shapeFilled) + ' 绿色像素 ' + greenBefore + '→' + greenAfter)
|
||
check('填充色块随之变为「生效」态(不再是灰色斜纹)',
|
||
shapeFilled.fillSwatchOff === false && shapeFilled.fillBtnOn === true,
|
||
JSON.stringify({ off: shapeFilled.fillSwatchOff, btn: shapeFilled.fillBtnOn }))
|
||
|
||
// v1.13 用户反馈「填充色状态不能实时在矢量图形上显示颜色变化」:
|
||
// 原生 <input type="color"> 在系统取色器里拖色时只派发 input,关闭取色器才派发 change。
|
||
// 以前只接 change ⇒ 取色器开着的整段时间画布一动不动。这里只发 input(模拟拖色中),
|
||
// 断言画布像素当场就变 —— 不发 change 也不许等。
|
||
const purpleBeforeLive = await countColorInVec([122, 31, 162], 8)
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||
el.value = '#7a1fa2'
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(200)
|
||
const liveFill = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const s = d.shapes[d.shapes.length - 1]
|
||
return { fillColor: s.fillColor, fill: s.fill }
|
||
})
|
||
const purpleAfterLive = await countColorInVec([122, 31, 162], 8)
|
||
check('填充色块只发 input(取色器还开着)画布就实时变色,不必等 change',
|
||
liveFill.fillColor === '#7a1fa2' && purpleAfterLive > 200, JSON.stringify(liveFill) + ' 紫色像素 ' + purpleBeforeLive + '→' + purpleAfterLive)
|
||
|
||
// 拖动结束:change 收尾,历史只多一条(拖动中不逐帧拍快照)
|
||
const hBeforeNative = (await dbg()).history
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(200)
|
||
check('原生取色器拖动一次只记 1 步撤销(预览不逐帧拍快照)',
|
||
(await dbg()).history - hBeforeNative === 0, 'history +' + ((await dbg()).history - hBeforeNative))
|
||
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
||
el.value = '#3388ff'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(280)
|
||
const shapeStroked = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const s = d.shapes[d.shapes.length - 1]
|
||
return { shapeColor: s.color, mainColor: d.color }
|
||
})
|
||
check('改图形描边色 = 改主色(色板 / 吸管 / 选项栏不会各说各话)',
|
||
shapeStroked.shapeColor === '#3388ff' && shapeStroked.mainColor === '#3388ff',
|
||
JSON.stringify(shapeStroked))
|
||
|
||
// ---- v1.11:颜色收敛成「描边 / 填充」两格,工具栏与选项栏读同一份 ----
|
||
// 用户原话:「3 个位置调色有问题,应该是 2 个调色」「请给工具栏加一个描边色,
|
||
// 工具选择的填充与描边与这里对应上」「填色里还需要添加一个取消颜色的按钮,就是无色状态」
|
||
const pairMode = await page.evaluate(() => {
|
||
const pair = document.querySelector('.iwb-editor-color-pair')
|
||
const btns = [...pair.querySelectorAll('.iwb-editor-color-btn')]
|
||
return { mode: pair.dataset.colorMode, visible: btns.filter(b => b.offsetParent !== null).map(b => b.dataset.colorSlot) }
|
||
})
|
||
check('工具栏给出「描边 + 填充」两格(形状工具下两格都在)',
|
||
pairMode.mode === 'pair' && pairMode.visible.join(',') === 'stroke,fill', JSON.stringify(pairMode))
|
||
|
||
// 从工具栏填充槽进色板:目标应当是填充,且出现「无」
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
|
||
await page.waitForTimeout(220)
|
||
const popTarget = await page.evaluate(() => {
|
||
const pop = document.querySelector('.iwb-editor-color-pop')
|
||
return {
|
||
open: !pop.hidden,
|
||
fillActive: pop.querySelector('.iwb-color-pop-tab[data-color-slot="fill"]').classList.contains('active'),
|
||
noneVisible: !!pop.querySelector('[data-color-none]').offsetParent,
|
||
noneUsable: !pop.querySelector('[data-color-none]').disabled
|
||
}
|
||
})
|
||
check('点填充槽打开色板:目标是填充,去色在第一格且可用',
|
||
popTarget.open && popTarget.fillActive && popTarget.noneVisible && popTarget.noneUsable,
|
||
JSON.stringify(popTarget))
|
||
|
||
// 用一个画布上不会出现的怪色(#a014b2)验收:12 个推荐色在前面用例里都用过,
|
||
// 拿黄色/绿色统计会数到别的图形,永远清不到 0。
|
||
const mainBefore = await page.evaluate(() => window.__iwbEditor.__debug().color)
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||
el.value = '#a014b2'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(300)
|
||
const fromPop = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const s = d.shapes[d.shapes.length - 1]
|
||
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
||
return { main: d.color, fillColor: s.fillColor, fill: s.fill, fillBtnBg: fillBtn.querySelector('i').style.backgroundColor }
|
||
})
|
||
check('色板里选色写进填充、主色(描边)不动,工具栏填充格同步变色',
|
||
fromPop.main === mainBefore && fromPop.fillColor === '#a014b2' && fromPop.fill === true &&
|
||
/160, 20, 178/.test(fromPop.fillBtnBg), JSON.stringify(fromPop))
|
||
|
||
// 「无」:关填充,画面清空,但颜色留着
|
||
const purpleBefore = await countColorInVec([160, 20, 178], 10)
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||
await page.waitForTimeout(320)
|
||
const afterNone = await page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const s = d.shapes[d.shapes.length - 1]
|
||
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
||
return { fill: s.fill, fillColor: s.fillColor, btnCls: fillBtn.className, noneActive: document.querySelector('.iwb-editor-color-pop [data-color-none]').classList.contains('active') }
|
||
})
|
||
const purpleAfter = await countColorInVec([160, 20, 178], 10)
|
||
check('「无」把填充关掉:画面清空、颜色留着(下次点颜色还是它)',
|
||
afterNone.fill === false && afterNone.fillColor === '#a014b2' && purpleBefore > 200 && purpleAfter === 0,
|
||
JSON.stringify(afterNone) + ' 紫色像素 ' + purpleBefore + '→' + purpleAfter)
|
||
check('无填充时工具栏填充格显示「无」(斜杠态,不露颜色本身)',
|
||
/is-none/.test(afterNone.btnCls) && afterNone.noneActive === true, JSON.stringify(afterNone))
|
||
|
||
// 反方向:选项栏改填充 → 工具栏填充格跟上
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||
el.value = '#22cc55'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(300)
|
||
const reverse = await page.evaluate(() => {
|
||
const pair = document.querySelector('.iwb-editor-color-pair')
|
||
const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||
return { fillBtnBg: pair.querySelector('[data-color-slot="fill"] i').style.backgroundColor, optVal: opt.value }
|
||
})
|
||
check('选项栏改填充色,工具栏填充格立刻跟上(两处同一份值)',
|
||
reverse.optVal === '#22cc55' && /34, 204, 85/.test(reverse.fillBtnBg), JSON.stringify(reverse))
|
||
|
||
// 画笔没有填充概念:只留一格
|
||
await page.keyboard.press('Escape')
|
||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||
await page.waitForTimeout(220)
|
||
const brushPair = await page.evaluate(() => {
|
||
const pair = document.querySelector('.iwb-editor-color-pair')
|
||
return { mode: pair.dataset.colorMode, visible: [...pair.querySelectorAll('.iwb-editor-color-btn')].filter(b => b.offsetParent !== null).length }
|
||
})
|
||
check('画笔工具下只留一格(画笔没有填充概念,不留空格让人猜)',
|
||
brushPair.mode === 'single' && brushPair.visible === 1, JSON.stringify(brushPair))
|
||
|
||
const copyExists = await page.locator('[data-action="copyClipboard"]').count()
|
||
await page.locator('[data-action="copyClipboard"]').click()
|
||
await page.waitForTimeout(400)
|
||
const copyToast = await page.locator('.iwb-editor-toast').textContent()
|
||
check('顶栏有「复制」且点击给出明确反馈(非静默失败)',
|
||
copyExists === 1 && /复制/.test(copyToast || ''),
|
||
'toast=' + JSON.stringify(copyToast))
|
||
|
||
check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (async () => {
|
||
await page.keyboard.press('Escape') // 清掉可能残留的选中态
|
||
await page.keyboard.press('Control+]')
|
||
const t = await page.locator('.iwb-editor-toast').textContent()
|
||
return t.indexOf('选中') >= 0
|
||
})())
|
||
|
||
// ---- v1.13.1:Shift+X 改成「交换填充色与描边色」(以前是 实心/描边 开关)----
|
||
// 旧语义下按一次,填充被关掉、描边纹丝不动 —— 用户的原话是「丢失填充色」。
|
||
// 放在最后跑:交换会把「下一个图形的填充色」也写成具体色值,前面有条断言要求它是 null。
|
||
const shiftXSwap = await (async () => {
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
const a = { x: imgBox.x + imgBox.width * 0.10, y: imgBox.y + imgBox.height * 0.10 }
|
||
const b = { x: imgBox.x + imgBox.width * 0.30, y: imgBox.y + imgBox.height * 0.30 }
|
||
await page.mouse.move(a.x, a.y); await page.mouse.down()
|
||
await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up()
|
||
await page.waitForTimeout(180)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2)
|
||
await page.waitForTimeout(150)
|
||
// 给个独立填充色,描边色保持主色,两边不同才看得出交换
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||
el.value = '#22cc55'
|
||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(180)
|
||
const d0 = await dbg()
|
||
const sh0 = d0.shapes.find(s => s.id === d0.selectedShapeId)
|
||
if (!sh0) return { ok: false, detail: '没选中形状' }
|
||
const stroke0 = sh0.color, fill0 = sh0.fillColor, fillOn0 = sh0.fill
|
||
await page.keyboard.press('Shift+x')
|
||
const d1 = await dbg()
|
||
const sh1 = d1.shapes.find(s => s.id === d1.selectedShapeId)
|
||
const swapped = Boolean(sh1 && sh1.color === fill0 && sh1.fillColor === stroke0 && sh1.fill === fillOn0)
|
||
await page.keyboard.press('Shift+x') // 再按一次回到原样
|
||
const d2 = await dbg()
|
||
const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId)
|
||
const back = Boolean(sh2 && sh2.color === stroke0 && sh2.fillColor === fill0 && sh2.fill === fillOn0)
|
||
return {
|
||
ok: swapped && back,
|
||
detail: JSON.stringify({
|
||
原: { 描边: stroke0, 填充: fill0, 填充开: fillOn0 },
|
||
交换后: sh1 && { 描边: sh1.color, 填充: sh1.fillColor, 填充开: sh1.fill },
|
||
再按: sh2 && { 描边: sh2.color, 填充: sh2.fillColor }
|
||
})
|
||
}
|
||
})()
|
||
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
||
|
||
// ================================================================
|
||
// v1.17:描边也能是「无色」;只要有一边无色,Shift+X 照样能交换
|
||
// ================================================================
|
||
// 用户原话:「让矢量图形与钢笔的描边色也可以去掉」
|
||
// 「让描边与填充,有一个是无色的时候,可以交换,现在是不可以的」
|
||
const setOptColor = (slot, hex) => page.evaluate(({ slot, hex }) => {
|
||
const el = document.querySelector(`.iwb-editor-optionbar-body [data-shape-color="${slot}"]`)
|
||
el.value = hex
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
}, { slot, hex })
|
||
|
||
async function drawRectAt(x1, y1, x2, y2) {
|
||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||
const a = { x: imgBox.x + imgBox.width * x1, y: imgBox.y + imgBox.height * y1 }
|
||
const b = { x: imgBox.x + imgBox.width * x2, y: imgBox.y + imgBox.height * y2 }
|
||
await page.mouse.move(a.x, a.y); await page.mouse.down()
|
||
await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up()
|
||
await page.waitForTimeout(180)
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2)
|
||
await page.waitForTimeout(160)
|
||
return { a, b }
|
||
}
|
||
|
||
// 取选中形状 + 三处 UI 的「无」状态,后面几条都用它
|
||
const selectedShapeState = () => page.evaluate(() => {
|
||
const d = window.__iwbEditor.__debug()
|
||
const s = d.shapes.find(x => x.id === d.selectedShapeId)
|
||
const btn = document.querySelector('.iwb-editor-color-pair [data-color-slot="stroke"]')
|
||
const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
||
const none = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
||
return {
|
||
type: s && s.type, closed: s && s.closed,
|
||
strokeOn: s && s.strokeOn, fill: s && s.fill,
|
||
color: s && s.color, fillColor: s && s.fillColor,
|
||
strokeBtnNone: !!btn && btn.classList.contains('is-none'),
|
||
optOff: !!opt && opt.classList.contains('is-off'),
|
||
// v1.20:去色永远在,只是不可用时 disabled(灰色),所以断言的是「能不能用」不是「在不在」
|
||
noneDisabled: !none || none.disabled,
|
||
noneActive: !!none && none.classList.contains('active')
|
||
}
|
||
})
|
||
|
||
// ---- 形状:去掉描边 ----
|
||
// 描边给一个画布上没出现过的洋红,靠像素数证明「框真的没了」而不是只改了数据
|
||
await drawRectAt(0.55, 0.52, 0.82, 0.74)
|
||
await setOptColor('fill', '#0aa6c8')
|
||
await page.waitForTimeout(160)
|
||
await setOptColor('stroke', '#ff00aa')
|
||
await page.waitForTimeout(220)
|
||
// 按画布分别数:画布上还躺着别的早期用例留下的同色对象(文字就用了 #ff00aa),
|
||
// 全局求和会把它们算进来 —— 只认「某一个画布从有变没有」才说得清这条描边真的没了
|
||
const magentaPerCanvas = () => page.evaluate(() => [...document.querySelectorAll('.iwb-editor-vec-canvas')].map(cv => {
|
||
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||
let n = 0
|
||
for (let i = 0; i < d.length; i += 4) {
|
||
if (d[i + 3] > 200 && Math.abs(d[i] - 255) < 8 && d[i + 1] < 8 && Math.abs(d[i + 2] - 170) < 8) n++
|
||
}
|
||
return n
|
||
}))
|
||
const magentaBefore = await magentaPerCanvas()
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(220)
|
||
const noneShownOnStroke = await page.evaluate(() =>
|
||
!document.querySelector('.iwb-editor-color-pop [data-color-none]').disabled)
|
||
// 开发用:ANNOT_SHOT4=/tmp/pop-none.png 出「去色可用态」的效果图(形状描边上下文)
|
||
if (process.env.ANNOT_SHOT4) await page.locator('.iwb-editor-color-pop').screenshot({ path: process.env.ANNOT_SHOT4 })
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||
await page.waitForTimeout(320)
|
||
const noStroke = await selectedShapeState()
|
||
const magentaAfter = await magentaPerCanvas()
|
||
const cyanStill = await countColorInVec([10, 166, 200], 8)
|
||
const strokeGone = magentaBefore.some((n, i) => n > 300 && magentaAfter[i] === 0)
|
||
const noNewMagenta = magentaAfter.every((n, i) => n <= magentaBefore[i])
|
||
check('形状可以去掉描边:描边像素清零,填充色与描边色都留着',
|
||
noneShownOnStroke && strokeGone && noNewMagenta &&
|
||
noStroke.strokeOn === false && noStroke.fill === true &&
|
||
noStroke.color === '#ff00aa' && cyanStill > 300,
|
||
JSON.stringify({ noneShownOnStroke, magentaBefore, magentaAfter, cyanStill, ...noStroke }))
|
||
check('无描边时工具栏描边格画斜杠、选项栏描边色块置灰、色板「无」高亮',
|
||
noStroke.strokeBtnNone === true && noStroke.optOff === true && noStroke.noneActive === true,
|
||
JSON.stringify({ btn: noStroke.strokeBtnNone, opt: noStroke.optOff, none: noStroke.noneActive }))
|
||
|
||
// 对称保护:已经无描边、再把填充也点掉 → 对象会彻底隐形,应当自动把描边还回来
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
|
||
await page.waitForTimeout(200)
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||
await page.waitForTimeout(300)
|
||
const bothNone = await selectedShapeState()
|
||
check('「无描边」后再点「无填充」:自动恢复描边,不会留下一个看不见的对象',
|
||
bothNone.fill === false && bothNone.strokeOn === true,
|
||
JSON.stringify({ fill: bothNone.fill, strokeOn: bothNone.strokeOn }))
|
||
// 回到「无描边」状态给下一条用例用(色板此时停在填充槽,先切回描边)
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(200)
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||
await page.waitForTimeout(280)
|
||
|
||
// 选色即恢复描边:与「文字描边宽度 0 时选色自动给 6px」同一条逻辑,
|
||
// 否则用户选了颜色画面没变化,会以为颜色设置坏了
|
||
await page.evaluate(() => {
|
||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||
el.value = '#ff00aa'
|
||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(320)
|
||
const revivedStroke = await selectedShapeState()
|
||
const magentaRevived = await magentaPerCanvas()
|
||
const strokeBack = magentaRevived.some((n, i) => n > 300 && magentaAfter[i] === 0)
|
||
check('无描边时再选一次颜色 → 自动恢复描边(选了色一定有变化)',
|
||
revivedStroke.strokeOn === true && revivedStroke.color === '#ff00aa' && strokeBack,
|
||
JSON.stringify({ ...revivedStroke, strokeBack, magentaAfter, magentaRevived }))
|
||
|
||
// ---- 钢笔闭合路径:同样能去掉描边 ----
|
||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||
const t1 = { x: imgBox.x + imgBox.width * 0.34, y: imgBox.y + imgBox.height * 0.16 }
|
||
const t2 = { x: imgBox.x + imgBox.width * 0.46, y: imgBox.y + imgBox.height * 0.16 }
|
||
const t3 = { x: imgBox.x + imgBox.width * 0.40, y: imgBox.y + imgBox.height * 0.34 }
|
||
await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(90)
|
||
await page.mouse.click(t2.x, t2.y); await page.waitForTimeout(90)
|
||
await page.mouse.click(t3.x, t3.y); await page.waitForTimeout(90)
|
||
await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(280) // 回到起点 = 闭合
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(220)
|
||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||
await page.waitForTimeout(320)
|
||
const penNoStroke = await selectedShapeState()
|
||
check('钢笔闭合路径也能去掉描边(去掉后只剩填充面,不会整个消失)',
|
||
penNoStroke.type === 'pen' && penNoStroke.closed === true &&
|
||
penNoStroke.strokeOn === false && penNoStroke.fill === true,
|
||
JSON.stringify(penNoStroke))
|
||
|
||
// 未闭合路径没有可填内部:去掉描边 = 这条线没了,索性不给「无」
|
||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||
await page.mouse.click(imgBox.x + imgBox.width * 0.62, imgBox.y + imgBox.height * 0.36)
|
||
await page.waitForTimeout(90)
|
||
await page.mouse.click(imgBox.x + imgBox.width * 0.76, imgBox.y + imgBox.height * 0.42)
|
||
await page.waitForTimeout(90)
|
||
await page.keyboard.press('Enter') // 回车结束开放路径
|
||
await page.waitForTimeout(280)
|
||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(220)
|
||
const openPen = await selectedShapeState()
|
||
check('未闭合钢笔不给「无描边」(去掉等于把这条线删了):去色留在原位但置灰',
|
||
openPen.type === 'pen' && openPen.closed === false && openPen.noneDisabled === true,
|
||
JSON.stringify(openPen))
|
||
|
||
// ---- 一边无色也能交换(用户反馈的第二个问题)----
|
||
await page.keyboard.press('Escape')
|
||
await drawRectAt(0.08, 0.10, 0.30, 0.30)
|
||
// 先做成「只有描边」:fill 关掉,描边给独立色
|
||
await page.evaluate(() => {
|
||
const btn = document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="stroke"]')
|
||
if (btn) btn.click()
|
||
})
|
||
await page.waitForTimeout(200)
|
||
await setOptColor('stroke', '#ff00aa')
|
||
await page.waitForTimeout(220)
|
||
const onlyStroke = await selectedShapeState()
|
||
await page.keyboard.press('Shift+x')
|
||
await page.waitForTimeout(260)
|
||
const afterSwap1 = await selectedShapeState()
|
||
await page.keyboard.press('Shift+x')
|
||
await page.waitForTimeout(260)
|
||
const afterSwap2 = await selectedShapeState()
|
||
check('一边无色也能交换:只描边 → 只填充(描边关、填充开),再按回到原样',
|
||
onlyStroke.strokeOn === true && onlyStroke.fill === false &&
|
||
afterSwap1.strokeOn === false && afterSwap1.fill === true &&
|
||
afterSwap2.strokeOn === true && afterSwap2.fill === false,
|
||
JSON.stringify({ 原: onlyStroke, 按一次: afterSwap1, 再按: afterSwap2 }))
|
||
|
||
// ================================================================
|
||
// v1.15 图片调节(放最后:会改像素,放中间会污染依赖像素的用例)
|
||
// ================================================================
|
||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||
await page.keyboard.press('Escape')
|
||
// 前面几条效果用例会把「原图」栅格化成副本层并把原层隐藏,这里先还原成干净的单层,
|
||
// 否则调节作用在一个隐藏层上 → 像素统计一动不动(第一次跑就踩了这个)
|
||
await page.locator('[data-action="reset"]').click()
|
||
await page.waitForTimeout(450)
|
||
await page.evaluate(() => {
|
||
const base = [...document.querySelectorAll('.iwb-layer-item')].find(el => /原图/.test(el.textContent || ''))
|
||
if (base) base.click()
|
||
})
|
||
await page.waitForTimeout(320)
|
||
|
||
const adjRowCount = await page.locator('.iwb-editor-adj-row').count()
|
||
const adjNames = await page.locator('.iwb-editor-adj-name').allTextContents()
|
||
check('右侧栏出现「图片调节」,11 项齐全且顺序固定',
|
||
adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度',
|
||
'rows=' + adjRowCount + ' ' + adjNames.join('/'))
|
||
|
||
// ---------- v1.19:右栏调色模块删除(用户 2026-11-10)/ 可拖宽度 / 字号 ----------
|
||
const sideFirst = await page.evaluate(() => {
|
||
const aside = document.querySelector('.iwb-editor-left')
|
||
const firstSection = aside && aside.querySelector(':scope > section')
|
||
return {
|
||
hasColor: Boolean(aside && aside.querySelector('[data-color-surface]')),
|
||
first: firstSection ? firstSection.className : '',
|
||
popCount: document.querySelectorAll('.iwb-editor-color-pop').length,
|
||
}
|
||
})
|
||
check('右栏调色模块已删:侧栏第一个模块是「图片调节」,颜色只剩弹层一处',
|
||
sideFirst.hasColor === false && /iwb-editor-adj/.test(sideFirst.first) && sideFirst.popCount === 1,
|
||
JSON.stringify(sideFirst))
|
||
|
||
// 弹层里选常用色:色块 active 圈 / HEX 输入 / 工具栏色点三处必须同时变
|
||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||
await page.waitForTimeout(120)
|
||
await page.locator('.iwb-editor-color-pop .iwb-editor-color-swatches [data-panel-color="#00bfa5"]').click()
|
||
await page.waitForTimeout(200)
|
||
const colorSync = await page.evaluate(() => {
|
||
const active = [...document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-swatches [data-panel-color]')]
|
||
.filter(b => b.classList.contains('active')).map(b => b.dataset.panelColor)
|
||
return {
|
||
active,
|
||
hex: document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input').value,
|
||
color: window.__iwbEditor.__debug().color,
|
||
}
|
||
})
|
||
check('弹层选色:常用色高亮 + HEX 回填 + 主色统一(三处不是各说各话)',
|
||
colorSync.active.length === 1 && colorSync.active[0] === '#00bfa5' &&
|
||
colorSync.hex.toLowerCase() === '#00bfa5' && colorSync.color === '#00bfa5',
|
||
JSON.stringify(colorSync))
|
||
await page.keyboard.press('Escape')
|
||
await page.waitForTimeout(90)
|
||
|
||
// 拖右栏宽度:侧栏在画布右侧,指针左移 80px ⇒ 宽 80px
|
||
const sideW0 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||
const grip = await page.locator('.iwb-editor-side-resizer').boundingBox()
|
||
await page.mouse.move(grip.x + grip.width / 2, grip.y + grip.height / 2)
|
||
await page.mouse.down()
|
||
await page.mouse.move(grip.x + grip.width / 2 - 80, grip.y + grip.height / 2, { steps: 8 })
|
||
await page.mouse.up()
|
||
await page.waitForTimeout(180)
|
||
const sideW1 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||
check('拖右栏手柄:宽度随拖动变大(不是固定 220)',
|
||
sideW1 >= sideW0 + 70 && sideW1 <= 520, sideW0 + ' → ' + sideW1)
|
||
|
||
await page.locator('.iwb-editor-side-resizer').dblclick()
|
||
await page.waitForTimeout(180)
|
||
const sideW2 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||
// 注意:aside 是 content-box,width 280 + 左右 padding 24 ⇒ rect 约 304/305。
|
||
// 这里跟「拖之前」比才对,写死 280 会误判。
|
||
check('双击手柄复位到默认宽度(回到拖动前)', Math.abs(sideW2 - sideW0) <= 2, sideW0 + ' ← ' + sideW2)
|
||
|
||
const fontSizes = await page.evaluate(() => ({
|
||
adjName: getComputedStyle(document.querySelector('.iwb-editor-adj-name')).fontSize,
|
||
adjTitle: getComputedStyle(document.querySelector('.iwb-editor-adj-title')).fontSize,
|
||
statusbar: getComputedStyle(document.querySelector('.iwb-editor-statusbar')).fontSize,
|
||
optionbar: getComputedStyle(document.querySelector('.iwb-editor-optionbar')).fontSize,
|
||
layerName: document.querySelector('.iwb-layer-name') ? getComputedStyle(document.querySelector('.iwb-layer-name')).fontSize : null
|
||
}))
|
||
check('整体字号提升一档(面板行名 12.5 / 标题 13 / 状态栏 12 / 选项栏 13)',
|
||
fontSizes.adjName === '12.5px' && fontSizes.adjTitle === '13px' &&
|
||
fontSizes.statusbar === '12px' && fontSizes.optionbar === '13px' &&
|
||
(!fontSizes.layerName || fontSizes.layerName === '13px'),
|
||
JSON.stringify(fontSizes))
|
||
|
||
/** 合成整幅可见像素后统计:平均亮度 / 灰像素占比 / R、B 均值 */
|
||
const adjStat = () => page.evaluate(() => {
|
||
const list = [...document.querySelectorAll('.iwb-editor-layer-canvas')]
|
||
if (!list.length) return null
|
||
const w = list[0].width, h = list[0].height
|
||
const c = document.createElement('canvas')
|
||
c.width = w; c.height = h
|
||
const x = c.getContext('2d')
|
||
for (const el of list) x.drawImage(el, 0, 0)
|
||
const d = x.getImageData(0, 0, w, h).data
|
||
let lum = 0, n = 0, gray = 0, r = 0, b = 0
|
||
for (let i = 0; i < d.length; i += 4) {
|
||
if (d[i + 3] === 0) continue
|
||
lum += (d[i] + d[i + 1] + d[i + 2]) / 3
|
||
if (Math.abs(d[i] - d[i + 1]) < 3 && Math.abs(d[i + 1] - d[i + 2]) < 3) gray++
|
||
r += d[i]; b += d[i + 2]; n++
|
||
}
|
||
return n ? { lum: Math.round(lum / n), gray: +(gray / n).toFixed(2), r: Math.round(r / n), b: Math.round(b / n) } : null
|
||
})
|
||
|
||
/** 设一个调节项的数值(模拟在数值框里输入并提交) */
|
||
const adjSet = async (key, val) => {
|
||
await page.evaluate(({ key, val }) => {
|
||
const row = document.querySelector(`.iwb-editor-adj-row[data-adj="${key}"]`)
|
||
const num = row.querySelector('.iwb-editor-adj-val')
|
||
num.value = String(val)
|
||
num.dispatchEvent(new Event('input', { bubbles: true }))
|
||
num.dispatchEvent(new Event('change', { bubbles: true }))
|
||
}, { key, val })
|
||
await page.waitForTimeout(240)
|
||
}
|
||
const adjReset = async () => {
|
||
const btn = page.locator('[data-adj-reset="all"]')
|
||
if (await btn.isEnabled()) { await btn.click(); await page.waitForTimeout(260) }
|
||
}
|
||
|
||
const adjBase = await adjStat()
|
||
|
||
await adjSet('exposure', 100)
|
||
const adjBright = await adjStat()
|
||
check('曝光 +100 明显提亮(不是「看不出变化」的强度)',
|
||
adjBright && adjBase && adjBright.lum > adjBase.lum + 25,
|
||
'亮度 ' + (adjBase && adjBase.lum) + ' → ' + (adjBright && adjBright.lum))
|
||
await adjReset()
|
||
|
||
await adjSet('saturation', -100)
|
||
const adjGray = await adjStat()
|
||
check('饱和度 -100 完全去色(灰像素接近 100%)',
|
||
adjGray && adjGray.gray > 0.9,
|
||
'灰占比 ' + (adjGray && adjGray.gray))
|
||
await adjReset()
|
||
|
||
await adjSet('temp', 100)
|
||
const adjWarm = await adjStat()
|
||
check('温度 +100 偏暖:R 通道升、B 通道降',
|
||
adjWarm && adjBase && adjWarm.r > adjBase.r && adjWarm.b < adjBase.b,
|
||
'R ' + (adjBase && adjBase.r) + '→' + (adjWarm && adjWarm.r) + ' B ' + (adjBase && adjBase.b) + '→' + (adjWarm && adjWarm.b))
|
||
|
||
const adjDirty = (await dbg()).adjust
|
||
check('调节参数写回状态(debug 可观测,供后续撤销断言)',
|
||
adjDirty.params && adjDirty.params.temp === 100 && adjDirty.hasSource,
|
||
JSON.stringify(adjDirty.params))
|
||
|
||
await adjReset()
|
||
const adjBack = await adjStat()
|
||
check('「复位」把所有项归零,像素回到原图',
|
||
adjBack && adjBase && Math.abs(adjBack.lum - adjBase.lum) <= 1 && Math.abs(adjBack.r - adjBase.r) <= 1,
|
||
'亮度 ' + (adjBack && adjBack.lum) + ' vs ' + (adjBase && adjBase.lum))
|
||
|
||
// 一次拖动 = 一步历史(6 次 input + 1 次 change)
|
||
// 注意不能比 history.length:历史栈有容量上限,push 到底后是「进一条、淘汰一条」,
|
||
// 长度永远不变(第一次跑就是被这个坑到)。数标签出现次数才准。
|
||
const adjLabelCount = async () => (await dbg()).historyLabels.filter(l => l === '图片调节').length
|
||
const adjH0 = await adjLabelCount()
|
||
for (const v of [20, 40, 60, 80, 90, 100]) {
|
||
await page.evaluate(({ v }) => {
|
||
const r = document.querySelector('.iwb-editor-adj-row[data-adj="exposure"] .iwb-editor-adj-range')
|
||
r.value = String(v)
|
||
r.dispatchEvent(new Event('input', { bubbles: true }))
|
||
}, { v })
|
||
}
|
||
await page.evaluate(() => {
|
||
const r = document.querySelector('.iwb-editor-adj-row[data-adj="exposure"] .iwb-editor-adj-range')
|
||
r.dispatchEvent(new Event('change', { bubbles: true }))
|
||
})
|
||
await page.waitForTimeout(320)
|
||
const adjH1 = await adjLabelCount()
|
||
check('拖一次滑杆只记 1 步历史(不是每帧一步)', adjH1 === adjH0 + 1, '图片调节 标签 ' + adjH0 + ' → ' + adjH1)
|
||
|
||
await page.keyboard.press('Control+z')
|
||
await page.waitForTimeout(320)
|
||
const adjUndo = (await dbg()).adjust
|
||
check('Ctrl+Z 撤销调节后滑块归零(参数不能和画面对不上)',
|
||
adjUndo.params && adjUndo.params.exposure === 0,
|
||
'exposure=' + (adjUndo.params && adjUndo.params.exposure))
|
||
|
||
// 切图层:面板 target 跟随,切回来参数恢复
|
||
await adjSet('exposure', 40)
|
||
const adjKept = (await dbg()).adjust.params.exposure
|
||
await page.locator('[data-action="addBlankLayer"]').click()
|
||
await page.waitForTimeout(400)
|
||
const adjTargetNew = await page.locator('.iwb-editor-adj-target').textContent()
|
||
const adjNewParams = (await dbg()).adjust.params
|
||
await page.evaluate(() => {
|
||
const base = [...document.querySelectorAll('.iwb-layer-item')].find(el => /原图/.test(el.textContent || ''))
|
||
if (base) base.click()
|
||
})
|
||
await page.waitForTimeout(420)
|
||
const adjBackParams = (await dbg()).adjust.params
|
||
check('切图层时调节面板跟随新层,切回原层参数恢复',
|
||
/空白图层/.test(adjTargetNew) && adjNewParams && adjNewParams.exposure === 0 && adjBackParams.exposure === adjKept,
|
||
'新层=' + adjTargetNew + ' 新层exp=' + (adjNewParams && adjNewParams.exposure) + ' 回到原图exp=' + adjBackParams.exposure)
|
||
|
||
await adjReset()
|
||
|
||
// 退出前先记一笔:此时调过曝光/温度,缓存里必然有 'base' 条目,
|
||
// 下面 Round 3 用它证明「退出确实把缓存清掉了」,而不是本来就没缓存。
|
||
const adjCacheBefore = (await dbg()).adjustCacheSize
|
||
check('前置:调过之后基准缓存里有条目', adjCacheBefore > 0, 'cache=' + adjCacheBefore)
|
||
|
||
await page.locator('[data-action="cancel"]').click()
|
||
const openState = await poll(async () => page.evaluate(() => window.__openState))
|
||
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',
|
||
Boolean(openState && openState.mode === 'cancel') &&
|
||
(await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false,
|
||
JSON.stringify(openState))
|
||
|
||
// ---------- Round 3:退出再打开,调节基准必须重建 ----------
|
||
// 原图图层的 id 是写死的 'base',而 adjust.js 的基准缓存以 layer.id 为 key。
|
||
// 退出时不清缓存 ⇒ 第二张图 captureFor('base') 命中上一张图的像素,
|
||
// 表现为「编辑另一张图时一调节,画面还原成上一张」—— 100% 复现,不是偶发。
|
||
await page.evaluate(() => {
|
||
window.__openState = null
|
||
window.__commands['annotate-selected'].run().then(
|
||
(mode) => { window.__openState = { mode: String(mode) } },
|
||
(err) => { window.__openState = { error: String((err && err.message) || err) } }
|
||
)
|
||
})
|
||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
||
await page.waitForFunction(() => window.__iwbEditor.__debug().open === true)
|
||
|
||
const adjFresh = await dbg()
|
||
check('退出重开:调节基准缓存清空、无残留 source 与 layerId(否则第二张图会串上一张的像素)',
|
||
adjFresh.adjustCacheSize === 0 && adjFresh.adjust.hasSource === false && adjFresh.adjust.layerId === null,
|
||
'cache=' + adjFresh.adjustCacheSize + ' layerId=' + adjFresh.adjust.layerId + ' hasSource=' + adjFresh.adjust.hasSource)
|
||
|
||
const adjBase2 = await adjStat()
|
||
await adjSet('exposure', 100)
|
||
const adjBright2 = await adjStat()
|
||
check('重开后调节以新图像素为基准:曝光 +100 正常提亮(不是把旧图重算上来)',
|
||
adjBase2 && adjBright2 && adjBright2.lum > adjBase2.lum + 25,
|
||
'亮度 ' + (adjBase2 && adjBase2.lum) + ' → ' + (adjBright2 && adjBright2.lum))
|
||
await adjReset()
|
||
|
||
await page.locator('[data-action="cancel"]').click()
|
||
|
||
check('无运行时错误 / 无弹窗', errors.length === 0, errors.slice(0, 3).join(' | '))
|
||
|
||
await browser.close()
|
||
console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过'))
|
||
process.exit(failed ? 1 : 0)
|