feat(image-annotate): v1.2.9 图层 PS 快捷键 + 顶栏会话组左移
- 图层快捷键(PS 同款,e.code 匹配防中文输入法吞键): Ctrl+]/[ 上/下移一层、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 向上/向下选层 - Delete 删除选中的位图图层(原图锁定除外) - moveLayer 无选中时 toast 提示,不再无声失败 - 顶栏「新建/覆盖/退出」移到最左会话组;右侧只留 输出+导出,下载改文案「导出」 - [ / ] 笔刷大小同时匹配 e.code,中文输入法下不再失灵 - __debug().shapes 补 z 字段;harness 新增 6 项断言(113 项全绿)
This commit is contained in:
1 parent
e1465b9d68
commit
9d923aed26
9 files changed
+255
-88
No files matched your search
@@ -1487,6 +1487,7 @@
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.iwb-opt-hint, .iwb-editor-optionbar-tip { display: none; }
|
||||
.iwb-editor-session .iwb-editor-btn-cancel,
|
||||
.iwb-editor-export-actions .iwb-editor-btn-cancel { display: none; }
|
||||
}
|
||||
|
||||
@@ -1586,3 +1587,12 @@
|
||||
display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
|
||||
}
|
||||
.iwb-opt-selcmd:hover { background: #45475a; }
|
||||
|
||||
/* ================================================================
|
||||
v1.2.9:顶栏「新建/覆盖/退出」移到最左(用户裁定 2026-11-04)
|
||||
布局:⟨新建·覆盖·退出⟩ 标题 | 撤销·重做·还原 | 顺序·视图 | …… | 输出·导出
|
||||
会话组不设 order(默认 0 且是 header 第一个子元素)→ 与标题同序时按 DOM 排最前
|
||||
================================================================ */
|
||||
.iwb-editor-header > .iwb-editor-session { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
|
||||
.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; }
|
||||
@@ -19,6 +19,12 @@ import { bindEvents } from './events.js'
|
||||
runtime.el.innerHTML = `
|
||||
<div class="iwb-editor-modal">
|
||||
<div class="iwb-editor-header">
|
||||
<!-- 会话组(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>
|
||||
@@ -72,10 +78,7 @@ import { bindEvents } from './events.js'
|
||||
<div class="iwb-editor-export-note">一次只输出一个结果;设置会记住</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="iwb-editor-btn iwb-editor-btn-download" data-action="download" title="下载当前这一张(不关闭编辑器)">下载</button>
|
||||
<button class="iwb-editor-btn iwb-editor-btn-new" data-action="newNode">新建</button>
|
||||
<button class="iwb-editor-btn iwb-editor-btn-replace" data-action="replace">覆盖</button>
|
||||
<button class="iwb-editor-btn iwb-editor-btn-cancel" data-action="cancel">退出</button>
|
||||
<button class="iwb-editor-btn iwb-editor-btn-download" data-action="download" title="导出当前这一张(不关闭编辑器)">导出</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="iwb-editor-optionbar">
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
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, ensureWritableLayer, getActiveCtx, getActiveLayer, hitBitmapHandle, removeVecCanvas, renderLayerPanel } from './layers.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 { beginMarquee, updateMarquee, endMarquee, beginLasso, updateLasso, endLasso, clearMarquee, syncAnts, renderSelection } from './selection.js'
|
||||
import { runCommand, toast } from './commands.js'
|
||||
import { showSelectionContext, hideSelectionContext } from './floating.js'
|
||||
import { applyConstraintDrag, cancelCrop, clearOverlay, confirmCrop, drawCropPreview, hideCropBar, hitCropHandle, insideRect, resizeCropRect, setConstraint, showCropBar, updateCropInfo } from './crop.js'
|
||||
import { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, renderObjects, selectUnit, shapeBounds, showTextInput } from './objects.js'
|
||||
import { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, renderObjects, selectNeighborLayer, selectUnit, shapeBounds, showTextInput } from './objects.js'
|
||||
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
|
||||
import { close, exportResult } from './index.js'
|
||||
import { loadImage } from './dom.js'
|
||||
@@ -1741,7 +1741,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
|
||||
// PS:] 增大 / [ 减小画笔大小(画笔与橡皮共用,光标环即时反馈)
|
||||
if (!mod && !e.altKey && (e.key === '[' || e.key === ']')) {
|
||||
// 同时匹配 e.code(BracketLeft/Right):中文输入法下 e.key 会变成「【」「】」,只看 e.key 会失灵
|
||||
const isBracket = e.key === '[' || e.key === ']' || e.code === 'BracketLeft' || e.code === 'BracketRight'
|
||||
if (!mod && !e.altKey && isBracket) {
|
||||
e.preventDefault()
|
||||
const step = S.brushSize >= 64 ? 8 : S.brushSize >= 24 ? 4 : S.brushSize >= 8 ? 2 : 1
|
||||
S.brushSize = clamp(S.brushSize + (e.key === ']' ? step : -step), 1, 300)
|
||||
@@ -1799,17 +1801,34 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
if (S.selectedTextId) { e.preventDefault(); deleteSelectedText(); renderLayerPanel(); return }
|
||||
if (S.selectedShapeId) { e.preventDefault(); deleteSelectedShape(); renderLayerPanel(); return }
|
||||
// PS 习惯:选中位图层(非原图)时 Delete 直接删除该图层
|
||||
if (S.selectedLayerId && S.selectedLayerId !== 'base') {
|
||||
e.preventDefault()
|
||||
deleteLayer(S.selectedLayerId)
|
||||
renderLayerPanel()
|
||||
return
|
||||
}
|
||||
}
|
||||
if (e.code === 'Space') {
|
||||
e.preventDefault()
|
||||
if (!S.spaceDown) { S.spaceDown = true; updateCursor() }
|
||||
return
|
||||
}
|
||||
if (mod && (e.key === ']' || e.key === '[')) {
|
||||
e.preventDefault()
|
||||
const up = e.key === ']'
|
||||
moveLayer(e.shiftKey ? (up ? 'top' : 'bottom') : (up ? 'up' : 'down'))
|
||||
return
|
||||
// ---- 图层快捷键(PS 同款,统一用 e.code 匹配防中文输入法吞键)----
|
||||
// Ctrl+] / Ctrl+[ 上移/下移一层;Ctrl+Shift+] / Ctrl+Shift+[ 置顶/置底;
|
||||
// Alt+] / Alt+[ 向上/向下选择图层(Mac 上 Cmd+]/[ 被浏览器前进/后退占用,用 Ctrl)
|
||||
if (e.code === 'BracketLeft' || e.code === 'BracketRight') {
|
||||
const up = e.code === 'BracketRight'
|
||||
if (mod) {
|
||||
e.preventDefault()
|
||||
moveLayer(e.shiftKey ? (up ? 'top' : 'bottom') : (up ? 'up' : 'down'))
|
||||
return
|
||||
}
|
||||
if (e.altKey) {
|
||||
e.preventDefault()
|
||||
selectNeighborLayer(up)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (mod && key === 'z') {
|
||||
e.preventDefault()
|
||||
|
||||
@@ -288,7 +288,7 @@ import { toast } from './commands.js'
|
||||
zoom: S.zoom,
|
||||
fit: { w: Math.round(S.fitW || 0), h: Math.round(S.fitH || 0) },
|
||||
layers: S.layers.map(l => ({ id: l.id, name: l.name, z: l.z, locked: !!l.locked, visible: l.visible !== false })),
|
||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed })),
|
||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z })),
|
||||
texts: S.textLayers.map(t => ({ id: t.id, text: t.text })),
|
||||
selectedShapeId: S.selectedShapeId,
|
||||
selectedTextId: S.selectedTextId,
|
||||
|
||||
@@ -383,8 +383,8 @@ export function setActiveLayer(id) {
|
||||
renderLayerPanel()
|
||||
}
|
||||
|
||||
/** 删除图层 */
|
||||
function deleteLayer(id) {
|
||||
/** 删除图层(图层面板按钮与 Delete 快捷键共用) */
|
||||
export function deleteLayer(id) {
|
||||
const idx = S.layers.findIndex(l => l.id === id)
|
||||
if (idx < 0) return
|
||||
// 不允许删除最后一个图层
|
||||
|
||||
@@ -13,6 +13,7 @@ import { drawBitmapSelection, drawVectorToCanvas, hitBitmapAt, removeVecCanvas,
|
||||
import { drawPlacementPreview } from './placement.js'
|
||||
import { drawShape } from './tools.js'
|
||||
import { saveSnapshot, snapshotState } from './history.js'
|
||||
import { toast } from './commands.js'
|
||||
import { renderOptionBar, updateLayerUI } from './events.js'
|
||||
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
|
||||
@@ -226,7 +227,9 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
const layer = S.layers.find(l => l.id === S.selectedLayerId && l.id !== 'base' && !l.locked)
|
||||
if (layer) sel = { kind: 'bitmap', obj: layer }
|
||||
}
|
||||
if (!sel || sel.obj.locked || sel.obj.id === 'base') return
|
||||
// 快捷键(Ctrl+]/[)与按钮共用此入口:没选中时给出可见反馈,不再无声失败
|
||||
if (!sel) { toast('先在画布或图层面板选中要调整的元素', 'info'); return }
|
||||
if (sel.obj.locked || sel.obj.id === 'base') return
|
||||
const units = layerUnits()
|
||||
// base 是锁定且不透明的底图,固定在最下层;任何元素都不许置底到它下面(否则等于消失)
|
||||
const baseIdx = units.findIndex(u => u.obj.id === 'base')
|
||||
@@ -251,6 +254,24 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
renderLayerPanel()
|
||||
}
|
||||
|
||||
/** PS: Alt+] / Alt+[ 向上/向下选择图层(位图与矢量同一份 z 列表)。
|
||||
* 当前没有任何选中时:向上选最顶层、向下选最底层,让用户能用键盘从头开始遍历。 */
|
||||
export function selectNeighborLayer(up) {
|
||||
const units = layerUnits()
|
||||
if (!units.length) return
|
||||
const sel = getSelectedObject()
|
||||
let cur = -1
|
||||
if (sel) cur = units.findIndex(u => u.obj === sel.obj)
|
||||
else if (S.selectedLayerId) cur = units.findIndex(u => u.kind === 'bitmap' && u.obj.id === S.selectedLayerId)
|
||||
const idx = cur < 0
|
||||
? (up ? units.length - 1 : 0)
|
||||
: (up ? Math.min(cur + 1, units.length - 1) : Math.max(cur - 1, 0))
|
||||
const u = units[idx]
|
||||
if (!u) return
|
||||
selectUnit(u.kind, u.obj.id)
|
||||
renderLayerPanel()
|
||||
}
|
||||
|
||||
function shapeHandlePoints(s) {
|
||||
const b = shapeBounds(s)
|
||||
if (s.type === 'pen') {
|
||||
|
||||
Reference in new issue
Block a user