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:
1 parent
0d161d6ded
commit
c176744846
10 files changed
+153
-59
No files matched your search
@@ -1546,6 +1546,9 @@
|
||||
border: 1px solid #45475a; border-radius: 4px;
|
||||
}
|
||||
.iwb-editor-optionbar-body .iwb-editor-size-input:focus { outline: none; border-color: #4488ff; }
|
||||
/* 硬度滑杆加宽:参数太密时默认 84px 拉不开,用户反馈「软度调节不明显」(2026-11-04) */
|
||||
.iwb-editor-optionbar-body .iwb-opt-range-wide { width: 140px; }
|
||||
.iwb-editor-optionbar-body .iwb-opt-dots { margin-left: 2px; }
|
||||
.iwb-editor-optionbar-body .iwb-editor-size-input::-webkit-inner-spin-button { -webkit-appearance: none; }
|
||||
.iwb-editor-optionbar-body .iwb-editor-crop-confirm,
|
||||
.iwb-editor-optionbar-body .iwb-editor-crop-cancel {
|
||||
@@ -1589,10 +1592,19 @@
|
||||
.iwb-opt-selcmd:hover { background: #45475a; }
|
||||
|
||||
/* ================================================================
|
||||
v1.2.9:顶栏「新建/覆盖/退出」移到最左(用户裁定 2026-11-04)
|
||||
布局:⟨新建·覆盖·退出⟩ 标题 | 撤销·重做·还原 | 顺序·视图 | …… | 输出·导出
|
||||
会话组不设 order(默认 0 且是 header 第一个子元素)→ 与标题同序时按 DOM 排最前
|
||||
v1.2.11:顶栏次序与配色(用户裁定 2026-11-04 晚)
|
||||
布局:标题 | ⟨新建·覆盖·退出⟩ | 撤销·重做·还原 | 顺序·视图 | …… | 输出·导出
|
||||
标题在前(它是标题,不能跑到按钮后面);会话组三键统一中性色,不再花
|
||||
================================================================ */
|
||||
.iwb-editor-header > .iwb-editor-session { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
|
||||
.iwb-editor-header > .iwb-editor-title { order: 0; }
|
||||
.iwb-editor-header > .iwb-editor-session { order: 1; display: flex; align-items: center; gap: 6px; flex: 0 0 auto; margin-left: 8px; }
|
||||
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn { padding: 6px 10px; font-size: 11px; min-width: 56px; white-space: nowrap; }
|
||||
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn-download { min-width: 72px; }
|
||||
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn-new,
|
||||
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn-replace,
|
||||
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn-cancel { background: #45475a; color: #cdd6f4; }
|
||||
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn-new:hover,
|
||||
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn-replace:hover,
|
||||
.iwb-editor-header > .iwb-editor-session .iwb-editor-btn-cancel:hover { background: #585b70; }
|
||||
/* 标题与会话组之间、撤销组与命令带之间的竖分隔 */
|
||||
.iwb-editor-header > .iwb-editor-session { margin-right: 4px; }
|
||||
.iwb-editor-header > .iwb-editor-divider { width: 1px; height: 20px; background: #313244; flex: 0 0 auto; margin: 0 4px; }
|
||||
@@ -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="调整选中元素的图层顺序">
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user