feat(image-annotate): v1.2.11 选中框手柄/旋转手柄/顶栏与选项栏打磨

- 缩放手柄 17px→11px(形状/文字/位图/放置四处统一),命中半径同步收小
- 旋转手柄重绘:细弧+末端小箭头(旋转语义更直观),线更细、色 #f0b34e
- Shift+X 切换选中形状 描边/实心(箭头无实心给提示);isTyping 放行 Shift 组合键,
  参数数字框里按 Shift+X 不再被吞
- 硬度:滑杆 84→140px + 5 个快捷点(0/25/50/75/100);笔刷推荐大小 7→4 个
- 顶栏:标题在最前,新建/覆盖/退出跟其后且三键统一中性色;标题后与撤销组后各加竖分隔
- harness 更新/新增断言(115 项全绿)
This commit is contained in:
qiqi committed 2026-11-04 23:06:39 +08:00
1 parent 0d161d6ded
commit c176744846
10 files changed
+153 -59

No files matched your search

+3 -2
View File
@@ -19,18 +19,19 @@ import { bindEvents } from './events.js'
runtime.el.innerHTML = `
<div class="iwb-editor-modal">
<div class="iwb-editor-header">
<!-- 会话组(v1.2.9):新建/覆盖/退出从顶栏最右移到最左(用户裁定 2026-11-04) -->
<span class="iwb-editor-title">图片编辑 <em class="iwb-editor-doc-size">—</em></span>
<!-- 会话组(v1.2.9):标题是标题、按钮是按钮 —— 新建/覆盖/退出跟在标题后(用户裁定 2026-11-04 晚) -->
<div class="iwb-editor-session">
<button class="iwb-editor-btn iwb-editor-btn-new" data-action="newNode" title="把当前编辑结果新建为节点(不关闭编辑器)">新建</button>
<button class="iwb-editor-btn iwb-editor-btn-replace" data-action="replace" title="用当前编辑结果覆盖原图">覆盖</button>
<button class="iwb-editor-btn iwb-editor-btn-cancel" data-action="cancel" title="放弃修改并退出">退出</button>
</div>
<span class="iwb-editor-title">图片编辑 <em class="iwb-editor-doc-size">—</em></span>
<div class="iwb-editor-history">
<button class="iwb-editor-action" data-action="undo" title="撤销 (Ctrl+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg></button>
<button class="iwb-editor-action" data-action="redo" title="重做 (Ctrl+Shift+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>
<button class="iwb-editor-action iwb-editor-action-reset" data-action="reset" title="还原原图:删掉所有标注/图层,回到打开时的样子(Ctrl+Z 可撤销)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/></svg></button>
</div>
<span class="iwb-editor-divider"></span>
<!-- 顶栏命令带(v1.2.6):撤销/重做/还原 | 顺序 | 视图;图层新建/导入回图层面板标题栏 -->
<div class="iwb-editor-commands">
<div class="iwb-editor-cmdgroup" data-group="order" title="调整选中元素的图层顺序">
+17 -5
View File
@@ -857,8 +857,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
function fillStyleHTML(owner) {
const fill = owner === 'pen' ? S.penFill : S.rectFill
return `<span class="iwb-opt-label">样式</span>
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke">描边</button>
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill">实心</button>`
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="描边 (Shift+X 切换)">描边</button>
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心 (Shift+X 切换)">实心</button>`
}
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
@@ -914,13 +914,14 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (tool === 'select') return selectOptionHTML()
if (tool === 'brush' || tool === 'eraser') {
return rangeOpt('brushSize', '大小', 1, 300, S.brushSize, '')
+ presetDots('brushSize', [2, 4, 8, 12, 16, 24, 32])
+ presetDots('brushSize', [2, 4, 8, 12])
+ `<span class="iwb-opt-label">硬度</span>
<input type="range" class="iwb-opt-range" data-opt="brushHardness" min="0" max="100" step="1" value="${S.brushHardness}">
<input type="range" class="iwb-opt-range iwb-opt-range-wide" data-opt="brushHardness" min="0" max="100" step="1" value="${S.brushHardness}">
<span class="iwb-opt-val" data-opt-val="brushHardness">${S.brushHardness}</span>
<span class="iwb-opt-label">透明</span>
<input type="range" class="iwb-opt-range" data-opt="brushOpacity" min="5" max="100" step="1" value="${Math.round(S.brushOpacity * 100)}">
<span class="iwb-opt-val" data-opt-val="brushOpacity">${Math.round(S.brushOpacity * 100)}%</span>`
+ presetDots('brushHardness', [0, 25, 50, 75, 100])
}
if (tool === 'rect' || tool === 'circle') {
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
@@ -1673,7 +1674,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const cls = t.classList
if (cls && (cls.contains('iwb-editor-text-input') || cls.contains('iwb-editor-color-hex-input'))) return true
// 以下是参数控件(数字框 / 滑杆)
if (e.ctrlKey || e.metaKey || e.altKey) return false
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) return false
if (e.key === 'Delete' || e.key === 'Escape') return false
return true
}
@@ -1740,6 +1741,17 @@ 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')
}
return
}
// PS:] 增大 / [ 减小画笔大小(画笔与橡皮共用,光标环即时反馈)
// 同时匹配 e.code(BracketLeft/Right):中文输入法下 e.key 会变成「【」「】」,只看 e.key 会失灵
const isBracket = e.key === '[' || e.key === ']' || e.code === 'BracketLeft' || e.code === 'BracketRight'
+1 -1
View File
@@ -202,7 +202,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
if (!(box.w > 0 && box.h > 0)) return
const ctx = S.overlayCtx
const rot = layer.rotation || 0
const hs = 7 / S.zoom
const hs = 5.5 / S.zoom
ctx.save()
ctx.strokeStyle = '#e8a735'
ctx.lineWidth = 1.5 / S.zoom
+3 -3
View File
@@ -309,7 +309,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
if (hitRotationHandle(lp, b)) return 'rotate'
const pts = shapeHandlePoints(s)
const offset = 8 / S.zoom
const R = Math.max(18 / S.zoom, 11)
const R = Math.max(14 / S.zoom, 9)
let best = null, bestDist = 1e9
for (const name in pts) {
const px = pts[name][0] + (name.includes('w') ? -offset : name.includes('e') ? offset : 0)
@@ -405,7 +405,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
octx.closePath()
octx.stroke()
octx.setLineDash([])
const hs = 8.5 / S.zoom
const hs = 5.5 / S.zoom
octx.fillStyle = '#ffffff'
octx.strokeStyle = '#e8a735'
const pts = shapeHandleWorld(s)
@@ -460,7 +460,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
octx.closePath()
octx.stroke()
octx.setLineDash([])
const hs = 7 / S.zoom
const hs = 5.5 / S.zoom
octx.fillStyle = '#ffffff'
octx.strokeStyle = '#e8a735'
const pts = textHandlePoints(sel)
+1 -1
View File
@@ -140,7 +140,7 @@ import { updateCursor } from './events.js'
ctx.stroke()
ctx.setLineDash([])
// 8 个缩放手柄(旋转后位置)
const hs = 8 / S.zoom
const hs = 5.5 / S.zoom
ctx.fillStyle = '#fff'
ctx.strokeStyle = '#4488ff'
ctx.lineWidth = 1.5 / S.zoom
+21 -6
View File
@@ -260,25 +260,40 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
/** 命中旋转手柄(传局部坐标点) */
export function hitRotationHandle(lp, b) {
const pts = rotationHandlesLocal(b)
const R = Math.max(13 / Math.max(S.zoom, 0.0001), 9)
const R = Math.max(11 / Math.max(S.zoom, 0.0001), 8)
for (const pt of pts) {
if (Math.hypot(lp[0] - pt[0], lp[1] - pt[1]) < R) return true
}
return false
}
/** 绘制四个角外侧的圆弧旋转手柄 */
/** 绘制四个角外侧的旋转手柄:细弧 + 末端小箭头(旋转语义,比裸 C 弧更可读) */
export function drawRotationHandles(ctx, b, rot) {
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
const pts = rotationHandlesLocal(b)
const r = Math.max(8 / Math.max(S.zoom, 0.0001), 6)
const k = Math.max(S.zoom, 0.0001)
const r = Math.max(6.5 / k, 5)
const lw = 1.5 / k
const ah = Math.max(3 / k, 2.6) // 箭头长度
const A0 = Math.PI * 0.2, A1 = Math.PI * 1.72
ctx.save()
ctx.strokeStyle = '#e8a735'
ctx.lineWidth = 2 / Math.max(S.zoom, 0.0001)
ctx.strokeStyle = '#f0b34e'
ctx.fillStyle = '#f0b34e'
ctx.lineWidth = lw
ctx.lineCap = 'round'
for (const pt of pts) {
const w = rotPt(pt[0], pt[1], cx, cy, rot || 0)
ctx.beginPath()
ctx.arc(w[0], w[1], r, Math.PI * 0.15, Math.PI * 1.85)
ctx.arc(w[0], w[1], r, A0, A1)
ctx.stroke()
// 弧末端顺时针切线方向的小箭头
const ex = w[0] + Math.cos(A1) * r, ey = w[1] + Math.sin(A1) * r
const ta = A1 + Math.PI / 2
ctx.beginPath()
ctx.moveTo(ex + Math.cos(ta) * ah * 1.4, ey + Math.sin(ta) * ah * 1.4)
ctx.lineTo(ex + Math.cos(ta + 2.4) * ah, ey + Math.sin(ta + 2.4) * ah)
ctx.lineTo(ex + Math.cos(ta - 2.4) * ah, ey + Math.sin(ta - 2.4) * ah)
ctx.closePath()
ctx.fill()
}
ctx.restore()
}