feat(image-annotate): v1.2.12 画笔/橡皮按住 Alt 临时吸色(PS 手感)
- 画笔或橡皮下按住 Alt 立即切吸管,点击取色后仍保持吸管(可连续取色),松开 Alt 回到原工具 - S.altPicker 标记区分「真按 I 切吸管」与临时吸管;exitPicker 在 altPicker 下只清缓存不退出 - 兜底:窗口 blur / 主动切别的工具都会结束临时吸管,避免工具卡在 picker - Alt keydown preventDefault(防 Windows 浏览器把单独 Alt 当菜单激活) - __debug 补 color / altPicker;harness 新增 Alt 吸色回归断言(116 项全绿)
This commit is contained in:
1 parent
c176744846
commit
3080916c62
8 files changed
+106
-12
No files matched your search
@@ -132,9 +132,9 @@ import { bindEvents } from './events.js'
|
||||
<button class="iwb-editor-tool" data-tool="marquee" title="选框 (M):拖出矩形/椭圆选区,松手后旁边出现操作条;Shift+M 切换矩形/椭圆"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4 3"><rect x="3" y="4" width="18" height="16" rx="1"/></svg></button>
|
||||
<button class="iwb-editor-tool" data-tool="lasso" title="套索 (L):按住拖动自由圈选,松手闭合"><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="M4 12c0-4 3.6-7 8-7s8 3 8 7-3.6 7-8 7c-2 0-3.8-.6-5.2-1.6"/><path d="M6.8 17.4 4 20l1.2-3.2"/><circle cx="20" cy="19" r="2"/></svg></button>
|
||||
|
||||
<button class="iwb-editor-tool active" data-tool="brush" title="画笔 (B):] 增大 / [ 减小笔刷"><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="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg></button>
|
||||
<button class="iwb-editor-tool active" data-tool="brush" title="画笔 (B):] 增大 / [ 减小笔刷;按住 Alt 临时吸色"><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="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg></button>
|
||||
|
||||
<button class="iwb-editor-tool" data-tool="eraser" title="橡皮 (E):] 增大 / [ 减小笔刷;擦除当前活跃图层,与画笔共用大小/硬度/透明度"><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="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/></svg></button>
|
||||
<button class="iwb-editor-tool" data-tool="eraser" title="橡皮 (E):] 增大 / [ 减小笔刷;擦除当前活跃图层,与画笔共用大小/硬度/透明度;按住 Alt 临时吸色"><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="m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21"/><path d="M22 21H7"/><path d="m5 11 9 9"/></svg></button>
|
||||
|
||||
<button class="iwb-editor-tool" data-tool="pen" title="钢笔 (P):点击添加节点,双击或 Enter 完成自定义形状"><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="m12 19 7-7 3 3-7 7-3-3z"/><path d="m18 13-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/><path d="m2 2 7.586 7.586"/><circle cx="11" cy="11" r="2"/></svg></button>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import { S, ZOOM_STEP, runtime } from './state.js'
|
||||
import { ROT_CURSOR, clamp, getPos, isOverRotationHandle, setView, setZoomActual, setZoomFit, zoomStep } from './viewport.js'
|
||||
import { addBitmapLayer, addBlankLayer, applyBitmapDrag, beginBitmapDrag, clearSelection, deleteLayer, ensureWritableLayer, getActiveCtx, getActiveLayer, hitBitmapHandle, removeVecCanvas, renderLayerPanel } from './layers.js'
|
||||
import { applyColorChange, beginStroke, clearToolRing, drawToolRing, endStroke, eraseSegment, exitPicker, hidePickerTip, sampleColor, setTool, showPickerTip, strokeSegment } from './tools.js'
|
||||
import { applyColorChange, beginAltPicker, beginStroke, clearToolRing, drawToolRing, endAltPicker, endStroke, eraseSegment, exitPicker, hidePickerTip, sampleColor, setTool, showPickerTip, strokeSegment } from './tools.js'
|
||||
import { beginMarquee, updateMarquee, endMarquee, beginLasso, updateLasso, endLasso, clearMarquee, syncAnts, renderSelection } from './selection.js'
|
||||
import { runCommand, toast } from './commands.js'
|
||||
import { showSelectionContext, hideSelectionContext } from './floating.js'
|
||||
@@ -1475,6 +1475,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (S.spaceDown) { S.spaceDown = false; updateCursor() }
|
||||
if (S.panning) { S.panning = false; S.panStart = null; updateCursor() }
|
||||
S._shiftDown = false
|
||||
// Alt 的 keyup 可能落在窗口外,兜底结束临时吸管,避免工具卡在 picker
|
||||
endAltPicker()
|
||||
})
|
||||
|
||||
// 阻止 modal 内部点击冒泡
|
||||
@@ -1687,6 +1689,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (e.key === 'Escape') { e.preventDefault(); cancelImagePlacement(); return }
|
||||
}
|
||||
if (e.key === 'Shift') S._shiftDown = true
|
||||
// PS:画笔 / 橡皮下按住 Alt 临时吸管(点击取色,松开 Alt 回到原工具)
|
||||
if (e.key === 'Alt' && !e.ctrlKey && !e.metaKey) {
|
||||
e.preventDefault() // 防 Windows 浏览器把单独 Alt 当作菜单栏激活
|
||||
beginAltPicker()
|
||||
return
|
||||
}
|
||||
if (e.key === 'Enter' && S.tool === 'pen' && S.penPath) { e.preventDefault(); commitPenPath(); return }
|
||||
// 裁剪:Enter 确认 / Esc 取消(用户裁定,替代浮窗上的两个按钮 —— 按钮也保留在选项栏)
|
||||
if (e.key === 'Enter' && S.tool === 'crop' && S.cropRect) { e.preventDefault(); confirmCrop(); return }
|
||||
@@ -1857,6 +1865,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
|
||||
function onKeyup(e) {
|
||||
if (e.key === 'Shift') S._shiftDown = false
|
||||
// PS:松开 Alt 结束临时吸管,回到画笔 / 橡皮
|
||||
if (e.key === 'Alt') endAltPicker()
|
||||
if (e.code === 'Space' && S.spaceDown) {
|
||||
S.spaceDown = false
|
||||
updateCursor()
|
||||
|
||||
@@ -284,6 +284,8 @@ import { toast } from './commands.js'
|
||||
const __debug = () => ({
|
||||
open: S.open,
|
||||
tool: S.tool,
|
||||
color: S.color,
|
||||
altPicker: !!S.altPicker,
|
||||
doc: { w: S.imgW, h: S.imgH },
|
||||
zoom: S.zoom,
|
||||
fit: { w: Math.round(S.fitW || 0), h: Math.round(S.fitH || 0) },
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
brushHardness: 100, // 画笔硬度 0~100:100=硬边描边,<100=径向渐变软边章
|
||||
brushOpacity: 1, // 画笔透明度 0.05~1(一笔整体透明度,笔划内不叠加)
|
||||
prevTool: null, // 吸管工具激活前的工具(取色后切回)
|
||||
altPicker: false, // 按住 Alt 的临时吸管(画笔/橡皮下),松开 Alt 回到原工具
|
||||
pickerComposite: null, // 吸管取样用的合成画布缓存(切工具/画布变化时失效)
|
||||
rectFill: false, // 矩形/圆形是否实心填充
|
||||
penFill: true, // 钢笔闭合路径是否实心填充(只对闭合路径有意义)
|
||||
|
||||
@@ -321,6 +321,13 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
||||
|
||||
/** 取色完成:切回吸管激活前的工具 */
|
||||
export function exitPicker() {
|
||||
// 按住 Alt 的临时吸管:取色后不退出(PS 手感:Alt 按住期间可连续吸色),
|
||||
// 由 keyup / 窗口失焦时的 endAltPicker() 统一收尾回到原工具
|
||||
if (S.altPicker) {
|
||||
S.pickerComposite = null
|
||||
hidePickerTip()
|
||||
return
|
||||
}
|
||||
S.tool = (S.prevTool && S.prevTool !== 'picker') ? S.prevTool : 'brush'
|
||||
S.prevTool = null
|
||||
// 回到的若不是选择/形状类工具,选中态按 setTool 同一套规则清掉,避免画布残留选中框
|
||||
@@ -343,8 +350,27 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
||||
renderObjects()
|
||||
}
|
||||
|
||||
/** 统一颜色应用:设置当前色 + 同步选中文字/形状颜色 */
|
||||
export function applyColorChange(color) {
|
||||
/**
|
||||
* PS 手感:画笔 / 橡皮下按住 Alt 临时变成吸管,松开 Alt 回到原工具。
|
||||
* 只在这两个绘制工具下生效;正在描笔时(isDrawing)不打断。
|
||||
* 取色后不退出吸管(见 exitPicker 的 altPicker 分支),可以按住 Alt 连续吸色。
|
||||
*/
|
||||
export function beginAltPicker() {
|
||||
if (S.altPicker) return
|
||||
if (S.tool !== 'brush' && S.tool !== 'eraser') return
|
||||
if (S.isDrawing) return
|
||||
S.altPicker = true
|
||||
setTool('picker') // setTool 会把原工具存进 prevTool,松开 Alt 时用它还原
|
||||
}
|
||||
|
||||
/** 松开 Alt / 窗口失焦:结束临时吸管并回到原工具 */
|
||||
export function endAltPicker() {
|
||||
if (!S.altPicker) return
|
||||
S.altPicker = false
|
||||
exitPicker()
|
||||
}
|
||||
|
||||
/** 统一颜色应用:设置当前色 + 同步选中文字/形状颜色 */ export function applyColorChange(color) {
|
||||
S.color = color
|
||||
updateColorUI()
|
||||
const t = getSelectedText()
|
||||
@@ -365,6 +391,8 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
||||
export function setTool(tool) {
|
||||
if (S.placingImage) cancelImagePlacement()
|
||||
commitTextInput()
|
||||
// 用户主动切到别的工具 = 放弃「按住 Alt 临时吸管」,否则松 Alt 会把工具抢回去
|
||||
if (tool !== 'picker') S.altPicker = false
|
||||
if (tool !== 'select' && tool !== 'pen') { S.penEditId = null; S.penDragPt = -1; S.penDragPending = null }
|
||||
if (tool === 'picker' && S.tool !== 'picker') S.prevTool = S.tool
|
||||
if (tool !== 'pen') S.penPath = null
|
||||
|
||||
Reference in new issue
Block a user