feat(image-annotate): 1.2.4 选择态就地改形状参数(描边/实心/线宽) + 顶栏命令带(更多菜单图标化: 新建/导入图层、置顶/上/下/置底、适应窗口、收起侧栏) + 选区命令入竖工具条

This commit is contained in:
qiqi committed 2026-11-04 21:12:36 +08:00
1 parent b83b8f3755
commit 77b4f7d5fe
8 files changed
+307 -147

No files matched your search

+23
View File
@@ -1546,3 +1546,26 @@
/* ---- v1.2.3:侧栏只留调色板 + 缩放 ---- */
/* 笔刷粗细/快捷点从侧栏移除后,缩放条直接挂在 aside 下:贴底,与调色板拉开距离 */
.iwb-editor-left > .iwb-editor-zoom { margin-top: auto; border-top: 1px solid #313244; padding-top: 10px; }
/* ================================================================
v1.2.4:顶栏命令带(原「更多 ▾」图标化)
布局:标题 | 撤销·重做·还原 | ⟨图层 新建/导入⟩ ⟨顺序 置顶/上移/下移/置底⟩ ⟨视图 适应/侧栏⟩ | …… | 输出·下载·新建·覆盖·退出
================================================================ */
.iwb-editor-header > .iwb-editor-history { order: 1; }
.iwb-editor-header > .iwb-editor-commands { order: 3; display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.iwb-editor-header > .iwb-editor-commands .iwb-editor-divider { width: 1px; height: 20px; background: #313244; flex: 0 0 auto; }
.iwb-editor-cmdgroup { display: flex; align-items: center; gap: 4px; }
.iwb-editor-cmdgroup[data-group="order"] { gap: 2px; }
/* 顶栏里的命令按钮统一 30×30 方角,和撤销/重做同款 */
.iwb-editor-header > .iwb-editor-commands .iwb-editor-action,
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn {
width: 30px; height: 30px; min-width: 30px; padding: 0; border: 0; border-radius: 8px;
background: #313244; color: #cdd6f4;
display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.iwb-editor-header > .iwb-editor-commands .iwb-editor-action:hover:not(:disabled),
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:hover:not(:disabled) { background: #45475a; }
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:disabled { opacity: 0.35; cursor: not-allowed; }
/* 竖工具条里的选区命令(全选/反选/取消)与工具按钮区分一点点:命令用中性色底 */
.iwb-editor-header > .iwb-editor-tools .iwb-editor-selcmd { background: #26263a; }
.iwb-editor-header > .iwb-editor-tools .iwb-editor-selcmd:hover { background: #45475a; }
+26 -26
View File
@@ -25,25 +25,35 @@ import { bindEvents } from './events.js'
<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"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg></button>
</div>
<div class="iwb-editor-more-wrap">
<button class="iwb-editor-more-btn" data-action="toggleMore" aria-expanded="false">更多 ▾</button>
<div class="iwb-editor-more-menu">
<button data-more="sel.all">全选 <kbd>Ctrl+A</kbd></button>
<button data-more="sel.invert">反选 <kbd>Ctrl+Shift+I</kbd></button>
<button data-more="sel.none">取消选区 <kbd>Esc</kbd></button>
<span class="iwb-editor-more-sep"></span>
<button data-more="addBlankLayer">新建空白图层</button>
<button data-more="addBitmapLayer">导入图片为图层</button>
<button data-more="zoomFit">适应窗口</button>
<button data-more="reset">还原原图</button>
<span class="iwb-editor-more-sep"></span>
<button data-action="togglePanels">收起 / 展开侧栏</button>
<!-- 顶栏命令带(v1.2.4):原「更多 ▾」菜单全部铺开成图标,按 图层 / 顺序 / 视图 分三组 -->
<div class="iwb-editor-commands">
<div class="iwb-editor-cmdgroup" data-group="layers">
<button class="iwb-editor-action" data-action="addBlankLayer" title="新建空白图层"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg></button>
<button class="iwb-editor-action" data-action="addBitmapLayer" title="导入图片为图层(也可直接 ⌘/Ctrl+V 粘贴剪贴板图片)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21"/><line x1="19" y1="8" x2="19" y2="14"/><line x1="22" y1="11" x2="16" y2="11"/></svg></button>
</div>
<span class="iwb-editor-divider"></span>
<div class="iwb-editor-cmdgroup" data-group="order" title="调整选中元素的图层顺序">
<button class="iwb-editor-layer-btn" data-layer="top" title="置顶:选中元素移到最上层 (Ctrl+Shift+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="5" x2="20" y2="5"/><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="up" title="上移一层 (Ctrl+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="down" title="下移一层 (Ctrl+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="bottom" title="置底:选中元素移到最下层 (Ctrl+Shift+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/><line x1="4" y1="19" x2="20" y2="19"/></svg></button>
</div>
<span class="iwb-editor-divider"></span>
<div class="iwb-editor-cmdgroup" data-group="view">
<button class="iwb-editor-action" data-action="zoomFit" title="适应窗口"><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="9 3 3 3 3 9"/><polyline points="15 3 21 3 21 9"/><polyline points="3 15 3 21 9 21"/><polyline points="21 15 21 21 15 21"/></svg></button>
<button class="iwb-editor-action" data-action="togglePanels" title="收起 / 展开侧栏(画布优先)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="9" y1="4" x2="9" y2="20"/></svg></button>
</div>
</div>
<button class="iwb-editor-panel-toggle" data-action="togglePanels" title="收起 / 展开侧栏(画布优先)">⇥</button>
<div class="iwb-editor-tools">
<button class="iwb-editor-tool" data-tool="select" title="选择/移动:点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><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="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg></button>
<!-- 选区命令紧跟「选择」工具(用户裁定 2026-11-04:从「更多」里拿出来,不再藏二级) -->
<button class="iwb-editor-tool iwb-editor-selcmd" data-more="sel.all" title="全选 (Ctrl+A)"><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="3 2"><rect x="3.5" y="3.5" width="17" height="17" rx="1"/></svg></button>
<button class="iwb-editor-tool iwb-editor-selcmd" data-more="sel.invert" title="反选 (Ctrl+Shift+I)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="3.5" width="17" height="17" rx="1" stroke-dasharray="3 2"/><rect x="8" y="8" width="8" height="8" rx="1" fill="currentColor" stroke="none"/></svg></button>
<button class="iwb-editor-tool iwb-editor-selcmd" data-more="sel.none" title="取消选区 (Esc / Ctrl+D)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="3.5" width="17" height="17" rx="1" stroke-dasharray="3 2"/><line x1="4" y1="20" x2="20" y2="4"/></svg></button>
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-tool" data-tool="marquee" title="框选:拖出矩形/椭圆选区,松手后旁边出现操作条(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>
@@ -71,7 +81,6 @@ import { bindEvents } from './events.js'
<span class="iwb-editor-divider"></span>
</div>
<span class="iwb-editor-divider"></span>
<div class="iwb-editor-export-actions">
<div class="iwb-editor-export-settings-wrap">
@@ -121,19 +130,10 @@ import { bindEvents } from './events.js'
<div class="iwb-editor-layer-panel">
<div class="iwb-editor-layer-panel-header">
<span class="iwb-editor-layer-panel-title">图层</span>
<div class="iwb-editor-layer-add-group">
<button class="iwb-editor-layer-add-btn" data-action="addBitmapLayer" title="导入图片为新图层(也可直接 ⌘/Ctrl+V 粘贴剪贴板图片)"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21"/><line x1="19" y1="8" x2="19" y2="14"/><line x1="22" y1="11" x2="16" y2="11"/></svg></button>
<button class="iwb-editor-layer-add-btn" data-action="addBlankLayer" title="新建空白图层"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg></button>
</div>
<!-- 新建图层 / 导入图片已上移到顶栏命令带(v1.2.4),面板只留标题,避免同一功能两个入口 -->
</div>
<div class="iwb-editor-layer-group" title="调整选中元素的图层顺序">
<span class="iwb-editor-constraint-label">图层</span>
<button class="iwb-editor-layer-btn" data-layer="top" title="置顶:选中元素移到最上层 (Ctrl+Shift+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="5" x2="20" y2="5"/><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="up" title="上移一层 (Ctrl+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="down" title="下移一层 (Ctrl+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="bottom" title="置底:选中元素移到最下层 (Ctrl+Shift+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/><line x1="4" y1="19" x2="20" y2="19"/></svg></button>
</div>
<!-- 图层顺序(置顶/上移/下移/置底)已移到顶栏命令带(v1.2.4) -->
<div class="iwb-editor-layer-list"></div>
</div>
<div class="iwb-editor-canvas-wrap">
+80 -43
View File
@@ -859,9 +859,41 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill">实心</button>`
}
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
/** 选择工具:只有选中了元素才出该元素的参数。
* 用户裁定 2026-11-04:选中矩形/钢笔后要能就地切描边/实心、改描边粗细,
* 不必再切回绘制工具 —— 所以这里复用绘制工具同一套控件与写回路径。 */
function selectOptionHTML() {
const sh = getSelectedShape()
if (sh) {
const t = sh.type
if (t === 'rect' || t === 'circle' || t === 'pen' || t === 'arrow') {
const owner = t === 'pen' ? 'pen' : 'rect'
const lw = Math.max(1, Math.round(sh.lw || S.shapeLineWidth))
return `<span class="iwb-opt-current">已选中:${SHAPE_NAMES[t] || t}</span>`
+ rangeOpt('shapeLineWidth', '线宽', 1, 60, lw, '')
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
+ (t === 'arrow' ? '' : fillStyleHTML(owner))
+ (t === 'pen' && !sh.closed
? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>'
: '')
}
}
const text = getSelectedText()
if (text) {
return `<span class="iwb-opt-current">已选中:文字</span>`
+ rangeOpt('textSize', '字号', 8, 400, Math.round(text.fontSize || S.textSize), 'px')
+ '<span class="iwb-opt-hint">双击文字改内容,拖动移动,手柄缩放</span>'
}
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>
<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里会出现它的描边、实心与粗细</span>`
}
/** 每个工具只露最常用的 2–4 个参数,全部直接写回 S(右侧参数面板同步) */
function optionBarHTML(tool) {
if (tool === 'crop') return cropOptionHTML()
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])
@@ -912,7 +944,10 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (!body) return
// 工具没变就只同步数值:renderAll 每次操作都会走到这里,全量重建 innerHTML
// 会打断正在拖的滑杆和正在输入的数字框(静态审查 P2-11)。
if (!force && body.dataset.tool === S.tool) { syncOptionBar(); return }
// 签名里带上选中对象 id:选择工具下换选一个形状,参数区必须整体重建。
const sig = S.tool + '|' + (S.selectedShapeId || '') + '|' + (S.selectedTextId || '')
if (!force && body.dataset.sig === sig) { syncOptionBar(); return }
body.dataset.sig = sig
body.dataset.tool = S.tool
body.innerHTML = optionBarHTML(S.tool)
if (S.tool === 'crop') updateCropInfo() // 重渲染后裁剪尺寸摘要要立即就位
@@ -923,12 +958,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
export function syncOptionBar() {
const body = runtime.el && runtime.el.querySelector('.iwb-editor-optionbar-body')
if (!body) return
// 选择工具下参数显示的是「选中对象自己的值」,不是新建默认值
const selShape = S.tool === 'select' ? getSelectedShape() : null
const selText = S.tool === 'select' ? getSelectedText() : null
const val = (key) => {
if (key === 'brushSize') return S.brushSize
if (key === 'brushHardness') return S.brushHardness
if (key === 'brushOpacity') return Math.round(S.brushOpacity * 100)
if (key === 'shapeLineWidth') return S.shapeLineWidth
if (key === 'textSize') return S.textSize
if (key === 'shapeLineWidth') return selShape ? Math.max(1, Math.round(selShape.lw || S.shapeLineWidth)) : S.shapeLineWidth
if (key === 'textSize') return selText ? Math.round(selText.fontSize || S.textSize) : S.textSize
if (key === 'feather') return S.selectionFeather
return ''
}
@@ -945,7 +983,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
btn.classList.toggle('active', S.selectionKind === btn.dataset.value)
})
body.querySelectorAll('[data-opt-toggle]').forEach(btn => {
const cur = btn.dataset.fillOwner === 'pen' ? S.penFill : S.rectFill
const owner = btn.dataset.fillOwner === 'pen' ? 'pen' : 'rect'
let cur = owner === 'pen' ? S.penFill : S.rectFill
// 选中态以对象自身的 fill 为准,否则按钮显示会和画面相反
if (selShape && (owner === 'pen' ? selShape.type === 'pen' : (selShape.type === 'rect' || selShape.type === 'circle'))) {
cur = !!selShape.fill
}
btn.classList.toggle('active', !!cur === (btn.dataset.value === 'fill'))
})
}
@@ -1010,6 +1053,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
// 未闭合的钢笔路径没有可填区域:保持描边,不动视觉结果
sh.fill = isPen ? (!!S.penFill && !!sh.closed) : !!S.rectFill
renderObjects()
// 对象的 fill 更新在 sync 之后,选择工具下按钮的激活态要再刷一次
syncOptionBar()
}
}
@@ -1043,47 +1088,31 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
syncOptionBar()
}
/** 更多菜单 / 面板收起 / 选项栏控件:只绑定一次,DOM 重绘不丢事件(委托) */
/** 顶栏命令带 / 面板收起 / 选项栏控件:只绑定一次,DOM 重绘不丢事件(委托) */
export function bindLiteUI() {
const root = runtime.el
if (!root || root.dataset.liteBound === '1') return
root.dataset.liteBound = '1'
const moreBtn = root.querySelector('[data-action="toggleMore"]')
const moreMenu = root.querySelector('.iwb-editor-more-menu')
const closeMenus = () => {
if (moreMenu) moreMenu.classList.remove('open')
if (moreBtn) moreBtn.setAttribute('aria-expanded', 'false')
const panel = root.querySelector('.iwb-editor-export-settings')
if (panel) panel.classList.remove('open')
const toggle = root.querySelector('[data-action="toggleExportSettings"]')
if (toggle) toggle.setAttribute('aria-expanded', 'false')
}
if (moreBtn && moreMenu) {
moreBtn.addEventListener('mousedown', (e) => e.stopPropagation())
moreBtn.addEventListener('click', (e) => {
e.stopPropagation()
const open = moreMenu.classList.toggle('open')
moreBtn.setAttribute('aria-expanded', String(open))
})
}
if (moreMenu) {
moreMenu.addEventListener('mousedown', (e) => e.stopPropagation())
moreMenu.addEventListener('click', (e) => {
const btn = e.target.closest('button')
if (!btn) return
e.stopPropagation()
const key = btn.dataset.more
if (key && key.indexOf('sel.') === 0) runCommand(key)
else if (key === 'addBlankLayer') addBlankLayer()
else if (key === 'addBitmapLayer') {
const b = root.querySelector('.iwb-editor-layer-add-btn[data-action="addBitmapLayer"]')
if (b) b.click()
} else if (key === 'zoomFit') setZoomFit()
else if (key === 'reset') restoreAll()
closeMenus()
})
}
// 选区命令(全选/反选/取消)已从「更多 ▾」搬到竖工具条「选择」后面,改走事件委托:
// 三个按钮不切换工具,只调命令层(与快捷键、右键菜单同一条路径)。
root.addEventListener('click', (e) => {
const btn = e.target.closest('[data-more]')
if (!btn) return
e.stopPropagation()
const key = btn.dataset.more
if (key && key.indexOf('sel.') === 0) runCommand(key)
else if (key === 'addBlankLayer') addBlankLayer()
else if (key === 'zoomFit') setZoomFit()
else if (key === 'reset') restoreAll()
})
root.querySelectorAll('[data-action="togglePanels"]').forEach(btn => {
btn.addEventListener('mousedown', (e) => e.stopPropagation())
@@ -1166,11 +1195,11 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
})
}
// 点画布 / 面板其它地方收起下拉。必须用捕获阶段:modal 自身有个
// 点画布 / 面板其它地方收起输出设置下拉。必须用捕获阶段:modal 自身有个
// mousedown stopPropagation(阻止宿主抢事件),冒泡阶段收不到。
const modal = root.querySelector('.iwb-editor-modal') || root
modal.addEventListener('mousedown', (e) => {
if (!e.target.closest('.iwb-editor-more-wrap') && !e.target.closest('.iwb-editor-export-settings-wrap')) closeMenus()
if (!e.target.closest('.iwb-editor-export-settings-wrap')) closeMenus()
}, true)
}
@@ -1194,6 +1223,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
return el
}
/** 同一个动作在顶栏/侧栏/面板都可能出现一个按钮(如「适应窗口」),全部绑上 */
function bindAll(selector, type, handler) {
const list = runtime.el.querySelectorAll(selector)
list.forEach(el => el.addEventListener(type, handler))
return list.length
}
export function bindEvents() {
bindToolButtons()
bindColorPanel()
@@ -1209,10 +1245,11 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
bindGlobalListeners()
}
/** 工具条按钮:点击切换当前工具 */
/** 工具条按钮:点击切换当前工具(选区命令按钮也借用 .iwb-editor-tool 样式,靠 data-tool 过滤掉) */
function bindToolButtons() {
// 工具
runtime.el.querySelectorAll('.iwb-editor-tool').forEach(btn => {
if (!btn.dataset.tool) return
btn.addEventListener('mousedown', (e) => e.stopPropagation())
btn.addEventListener('click', () => setTool(btn.dataset.tool))
})
@@ -1313,7 +1350,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
e.stopPropagation()
zoomStep(ZOOM_STEP, S.canvasWrap.clientWidth / 2, S.canvasWrap.clientHeight / 2)
})
bindIf('[data-action="zoomFit"]', 'click', (e) => {
bindAll('[data-action="zoomFit"]', 'click', (e) => {
e.stopPropagation()
setZoomFit()
})
@@ -1338,11 +1375,11 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
/** 裁剪确认/取消已迁入选项栏(bindLiteUI 委托),旧直连绑定移除。 */
/** 添加位图图层(导入图片)与新建空白图层 */
/** 添加位图图层(导入图片)与新建空白图层:顶栏与其它入口统一绑,取第一个会漏按钮 */
function bindLayerAddActions() {
// 添加位图图层(导入图片)
bindIf('[data-action="addBitmapLayer"]', 'mousedown', (e) => e.stopPropagation())
bindIf('[data-action="addBitmapLayer"]', 'click', () => {
bindAll('[data-action="addBitmapLayer"]', 'mousedown', (e) => e.stopPropagation())
bindAll('[data-action="addBitmapLayer"]', 'click', () => {
const fileInput = document.createElement('input')
fileInput.type = 'file'
fileInput.accept = 'image/*'
@@ -1364,8 +1401,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
})
// 新建空白图层
bindIf('[data-action="addBlankLayer"]', 'mousedown', (e) => e.stopPropagation())
bindIf('[data-action="addBlankLayer"]', 'click', () => {
bindAll('[data-action="addBlankLayer"]', 'mousedown', (e) => e.stopPropagation())
bindAll('[data-action="addBlankLayer"]', 'click', () => {
addBlankLayer()
})
}
+1 -1
View File
@@ -286,7 +286,7 @@ import { toast } from './commands.js'
tool: S.tool,
doc: { w: S.imgW, h: S.imgH },
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 })),
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed })),
texts: S.textLayers.map(t => ({ id: t.id, text: t.text })),
selectedShapeId: S.selectedShapeId,
selectedTextId: S.selectedTextId,
+3 -1
View File
@@ -13,7 +13,7 @@ import { drawBitmapSelection, drawVectorToCanvas, hitBitmapAt, removeVecCanvas,
import { drawPlacementPreview } from './placement.js'
import { drawShape } from './tools.js'
import { saveSnapshot, snapshotState } from './history.js'
import { updateLayerUI } from './events.js'
import { renderOptionBar, updateLayerUI } from './events.js'
import { isDrawableLayer } from '../vendor/layer-logic.js'
@@ -175,6 +175,8 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
S.textDrag = null
S.shapeDrag = null
S.bitmapDrag = null
// 选中态变了,选项栏要跟着换成该对象的参数(选择工具下改描边/实心/线宽/字号)
renderOptionBar()
}
/** 判定一个图层单元是否命中该点(位图用矩形/像素,矢量用包围盒/形状) */