diff --git a/image-annotate/README.md b/image-annotate/README.md index 89d875b..6d9f438 100644 --- a/image-annotate/README.md +++ b/image-annotate/README.md @@ -234,6 +234,44 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。 - 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。 - 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。 +## v1.13.1:Shift+X 改成「交换填充色与描边色」 + +反馈:「矩形 圆形 钢笔,切换填充与描边色的时候,会导致填充丢掉」→ 补一句关键信息 +「shift+x 切换填充与描边色的时候,就会出现丢失填充色的问题……再按这个快捷键填色又回来了, +但是描边一直不变」。 + +### 不是颜色被清空,是快捷键语义错了 + +先把能想到的入口全实测了一遍(工具栏两个色槽、色板头部 tab、SV 拖动、hex 输入、选项栏原生 +色块、切换工具往返、矩形/圆形/钢笔、钢笔闭合与未闭合):**`fillColor` 从来没被清空,画面像素 +也没有丢**。真正的错在 **Shift+X 的语义**: + +| | 旧行为 | 用户期望 | +| --- | --- | --- | +| 按一次 | 填充开关被关掉(只剩描边),描边色不动 | 填充色与描边色**对调** | +| 再按一次 | 填充开关恢复,描边色仍然不动 | 换回来 | + +用户看到的正是「填充没了、描边一直不变,再按一次填充又回来」—— 那是**开关**的行为, +而 PS 里 `X` 是**交换前景/背景色**。所以这不是"颜色丢了",是把颜色交换做成了开关。 + +### 改法 + +新增 `swapShapeColors()`(`events.js`),Shift+X 改为调它: + +- 描边色 ↔ 填充色对调:`sh.color ⇄ sh.fillColor`,同时同步主色 `S.color` 与默认填充色 + `S.shapeFillColor`(v1.10 起这两个就是同一份真相源,不另存) +- **填充的开关状态不动**:交换的是颜色,不是有无。实心图形交换后仍是实心 +- 箭头没有内部,直接 toast 说明;填充还在「跟随描边色」(`fillColor=null`,两边同一个值) + 时也只提示,不改数据 +- 一步历史:`saveSnapshot('交换填充与描边色')`,`Ctrl+Z` 一次回退 + +实心/描边的切换**没有丢**,仍在选项栏那两个按钮上(`data-opt-toggle`),只是不再占 Shift+X; +按钮的 tooltip 里原来写着「(Shift+X 切换)」,容易让人以为 Shift+X 是开关,已改成说明交换语义。 + +回归:`tools/harness.mjs` 里那条旧用例(断言按 Shift+X 后 `fill` 变 true)换成新的交换用例, +断言「描边/填充两个色值互换、`fill` 开关不变、再按一次回到原样」。这条用例放在文件末尾跑 —— +交换会把「下一个图形的填充色」也写成具体色值,夹在中间会污染后面「新建图形填充默认跟随描边色」的断言。 + ## v1.13.0:顶栏瘦身 / 视图按钮归位 / R·O·L 快捷键 / 填充色实时 / 图层解封 五条调整,前四条是界面与手感,最后一条是能力解禁(原型是 PS,但「原图不许压」这条并不是 PS 的规矩)。 diff --git a/image-annotate/docs/PS_LITE_ROADMAP.md b/image-annotate/docs/PS_LITE_ROADMAP.md index eec5e28..b474679 100644 --- a/image-annotate/docs/PS_LITE_ROADMAP.md +++ b/image-annotate/docs/PS_LITE_ROADMAP.md @@ -311,6 +311,7 @@ getCompositeCanvas() // 当前这一张 | 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 | | P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 | | P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 | +| 快捷键语义修正(v1.13.1) | ✅ v1.13.1:Shift+X 从「实心 ↔ 只描边」开关改成**交换填充色与描边色**(PS 的 X 语义)。旧行为下按一次填充被关掉、描边色不动,用户看到的就是「填充丢了」。新 `swapShapeColors()` 对调 `sh.color ⇄ sh.fillColor` 并同步 `S.color` / `S.shapeFillColor`,**填充开关不动**(交换颜色不改有无),箭头跳过、跟随态只提示,一步历史。实心/描边切换仍留在选项栏按钮上 | | 界面瘦身 / 快捷键 / 实时预览 / 图层解封 | ✅ v1.13.0:顶栏删掉四个层级按钮(`.iwb-editor-commands` 整块移除,`updateLayerUI()` / `bindLayerOrderButtons()` 一并清除);「适应窗口 / 收起侧栏」移到工具栏 DOM 末尾(shrink-to-fit 天然最右);快捷键 `R` 矩形 / `O` 圆形 / `L` 箭头(套索迁 `A`,`U` 保留),键盘处理改为优先匹配 `e.code` 以兼容中文输入法;原生 `` 补接 `input` 做实时预览(`skipHistory` + `nativeColorSnapped`,一次拖动仍只记 1 步撤销);原图不再钉底——`planPanelOrder` / `updateSortTarget` / `onSortEnd` / `moveLayer` / `mergeUnits` 五处解封,其他图层可拖到原图下方 | | 颜色体系与矢量属性 | ✅ v1.12.0:颜色上下文收敛成 `colorContext()` 三档(文字 / 形状 / 只有主色),文字上下文给**三格**(文字 / 描边 / 底色,`data-color-mode="triple"`),`applyTextColor()` 统管描边色与底色的写回(含 `skipHistory` 拖拽);「无」按当前格分派(无填充 / 无描边 / 无底色);原文「文本不支持描边与字体色切换」已修 | | 颜色体系与矢量属性(v1.11) | ✅ v1.11.0:颜色收敛为**描边 / 填充两格**——工具栏改 PS 式双色槽(`S.colorTarget` 决定色板写哪一格),选项栏两色块与工具栏双向同步,`colorSlots()` 成为唯一取值处;填充支持**无**(`fill=false`,颜色保留,槽位画灰底红斜杠);画笔/文字/箭头等无填充概念的工具只显示一格(v1.12 起文字改三格) | diff --git a/image-annotate/package.json b/image-annotate/package.json index e3c9aa0..0ba6e58 100644 --- a/image-annotate/package.json +++ b/image-annotate/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/image-annotate", "private": true, - "version": "1.13.0", + "version": "1.13.1", "description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)", "ibwPlugin": { "id": "image-annotate", diff --git a/image-annotate/plugin/editor/events.js b/image-annotate/plugin/editor/events.js index 8ab7f63..7627577 100644 --- a/image-annotate/plugin/editor/events.js +++ b/image-annotate/plugin/editor/events.js @@ -1163,8 +1163,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' const own = !!sh && (owner === 'pen' ? sh.type === 'pen' : (sh.type === 'rect' || sh.type === 'circle')) const fill = own ? !!sh.fill : (owner === 'pen' ? S.penFill : S.rectFill) return `样式 - - ` + + ` } const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' } @@ -1686,6 +1686,29 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' } } + /** PS 的 X 语义(v1.13.1):把选中形状的「填充色」与「描边色」对调。 + * 以前 Shift+X 绑的是「实心 ↔ 只描边」开关 —— 按下去填充被关掉、描边纹丝不动, + * 用户的主观体验就是「填充色丢了」,再按一次才回来。用户要的是**交换两个颜色**: + * 填充色换到描边的位置、描边色换到填充的位置,填充的开关状态不变(交换的是颜色,不是有无)。 + * 填充色仍「跟随描边色」(fillColor=null)时只有一个颜色,没有可交换的对象,只提示不动数据。 */ + function swapShapeColors() { + const sh = getSelectedShape() + if (!sh || sh.locked) return false + if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true } + const stroke = sh.color || S.color + const fill = sh.fillColor || null + if (!fill) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true } + saveSnapshot('交换填充与描边色') + sh.color = fill + S.color = fill // 描边色与主色永远同一份(v1.10 的约定) + sh.fillColor = stroke + S.shapeFillColor = stroke // 交换后就是独立填充色了,不再跟随描边 + renderObjects() + updateColorUI() + syncOptionBar() + return true + } + function setOptionFromControl(el, committed) { const key = el && el.dataset ? el.dataset.opt : '' if (!key) return @@ -2546,14 +2569,11 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' return } - // PS 风格:Shift+X 切换选中形状的 描边/实心(与选项栏按钮共用 setShapeFill) - if (!mod && e.shiftKey && key === 'x') { - const sh = getSelectedShape() - if (sh && !sh.locked) { - e.preventDefault() - if (sh.type === 'arrow') { toast('箭头没有实心样式', 'info'); return } - setShapeFill(!sh.fill, sh.type === 'pen' ? 'pen' : 'rect') - } + // PS 同款:Shift+X 交换选中形状的「填充色」与「描边色」(v1.13.1)。 + // 以前这里绑的是「实心 ↔ 只描边」开关,用户按下去看到的是「填充色丢了、描边没变」—— + // 语义错了,不是颜色没了。实心/描边仍可从选项栏那两个按钮切。 + if (!mod && !e.altKey && e.shiftKey && key === 'x') { + if (swapShapeColors()) e.preventDefault() return } diff --git a/image-annotate/src/index.js b/image-annotate/src/index.js index 075fd57..e9d2ff1 100644 --- a/image-annotate/src/index.js +++ b/image-annotate/src/index.js @@ -9,7 +9,7 @@ var __IWB_ANNOTATE_MANIFEST__ = { id: 'image-annotate', name: '标注 / 修图', - version: '1.13.0', + version: '1.13.1', apiVersion: 1, capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'], settings: { @@ -5063,8 +5063,8 @@ var __IWB_ANNOTATE_MANIFEST__ = { const own = !!sh && (owner === "pen" ? sh.type === "pen" : sh.type === "rect" || sh.type === "circle"); const fill = own ? !!sh.fill : owner === "pen" ? S.penFill : S.rectFill; return `样式 - - `; + + `; } var SHAPE_NAMES = { rect: "矩形", circle: "圆形", arrow: "箭头", pen: "钢笔路径" }; var TEXT_STYLE_STATE_KEY = { @@ -5483,6 +5483,29 @@ var __IWB_ANNOTATE_MANIFEST__ = { syncOptionBar(); } } + function swapShapeColors() { + const sh = getSelectedShape(); + if (!sh || sh.locked) return false; + if (sh.type === "arrow") { + toast("箭头只有描边色,没有可交换的填充色", "info"); + return true; + } + const stroke = sh.color || S.color; + const fill = sh.fillColor || null; + if (!fill) { + toast("填充色正跟随描边色(两者同一个颜色),无需交换", "info"); + return true; + } + saveSnapshot("交换填充与描边色"); + sh.color = fill; + S.color = fill; + sh.fillColor = stroke; + S.shapeFillColor = stroke; + renderObjects(); + updateColorUI(); + syncOptionBar(); + return true; + } function setOptionFromControl(el, committed) { const key = el && el.dataset ? el.dataset.opt : ""; if (!key) return; @@ -6337,16 +6360,8 @@ var __IWB_ANNOTATE_MANIFEST__ = { togglePanelsCollapsed(); return; } - if (!mod && e.shiftKey && key === "x") { - const sh = getSelectedShape(); - if (sh && !sh.locked) { - e.preventDefault(); - if (sh.type === "arrow") { - toast("箭头没有实心样式", "info"); - return; - } - setShapeFill(!sh.fill, sh.type === "pen" ? "pen" : "rect"); - } + if (!mod && !e.altKey && e.shiftKey && key === "x") { + if (swapShapeColors()) e.preventDefault(); return; } const isBracket = e.key === "[" || e.key === "]" || e.code === "BracketLeft" || e.code === "BracketRight"; diff --git a/image-annotate/tools/harness.mjs b/image-annotate/tools/harness.mjs index bf57132..038cea4 100644 --- a/image-annotate/tools/harness.mjs +++ b/image-annotate/tools/harness.mjs @@ -865,18 +865,8 @@ selShapeDbg = await dbg() check('选中矩形就地改线宽 9', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].lw === 9, JSON.stringify(selShapeDbg.shapes.slice(-1))) -// Shift+X:选中形状切 描边/实心(PS 风格;数字框输完值直接按也必须生效) -check('Shift+X 切换选中形状 描边/实心(对象与选项栏按钮同步)', await (async () => { - await page.keyboard.press('Shift+x') - const d = await dbg() - const sh = d.shapes.find(s => s.id === d.selectedShapeId) - const btnActive = await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active')) - const flipped = sh && sh.fill === true && btnActive - await page.keyboard.press('Shift+x') // 切回描边,恢复现场 - const d2 = await dbg() - const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId) - return flipped && sh2 && sh2.fill === false -})()) +// Shift+X 的用例在文件末尾(它会把「下一个图形的填充色」也写成具体色值, +// 落在中间会污染后面「新建图形填充默认跟随描边色」那条断言) // 钢笔:闭合路径选中后同样可切描边/实心 await page.locator('.iwb-editor-tool[data-tool="pen"]').click() @@ -1082,7 +1072,7 @@ check('画笔按住 Alt 临时吸色,松开 Alt 回到画笔(可连续取色 : 'up: tool=' + d3.tool + ' alt=' + d3.altPicker })()) -// Shift+X:选中形状切 描边/实心(PS 风格,用户裁定 2026-11-04 晚) +// Shift+X 的用例见上面「Shift+X 交换填充色与描边色」(v1.13.1 起是交换语义,不再是实心/描边开关) // 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层 // 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z) @@ -2399,6 +2389,50 @@ check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (asy 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) + await page.locator('[data-action="cancel"]').click() const openState = await poll(async () => page.evaluate(() => window.__openState)) check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',