feat(image-annotate): 选区编辑 + 便利版 UI + 单张输出预设(1.1.0)
This commit is contained in:
1 parent
b9ace636ef
commit
662d7eae77
22 files changed
+3795
-343
No files matched your search
@@ -19,16 +19,34 @@ import { bindEvents } from './events.js'
|
||||
runtime.el.innerHTML = `
|
||||
<div class="iwb-editor-modal">
|
||||
<div class="iwb-editor-header">
|
||||
<span class="iwb-editor-title">图片编辑</span>
|
||||
<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" data-action="reset" 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="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>
|
||||
<button class="iwb-editor-action iwb-editor-action-restore" data-action="restore" 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" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></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>
|
||||
</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>
|
||||
|
||||
<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>
|
||||
|
||||
<button class="iwb-editor-tool active" data-tool="brush" 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="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="橡皮:擦除当前活跃图层的内容(画笔标注或原图),与画笔共用大小/硬度/透明度"><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>
|
||||
@@ -58,11 +76,36 @@ import { bindEvents } from './events.js'
|
||||
<span class="iwb-editor-divider"></span>
|
||||
|
||||
<div class="iwb-editor-export-actions">
|
||||
<div class="iwb-editor-export-settings-wrap">
|
||||
<button class="iwb-editor-export-settings-btn" data-action="toggleExportSettings" aria-expanded="false">输出 <span class="iwb-editor-export-summary">原尺寸 PNG</span> ▾</button>
|
||||
<div class="iwb-editor-export-settings">
|
||||
<div class="iwb-editor-export-row"><span>预设</span>
|
||||
<button data-export-key="preset" data-export-value="original">原尺寸</button>
|
||||
<button data-export-key="preset" data-export-value="ecom800">电商 800² ≤500KB</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-row"><span>格式</span>
|
||||
<button data-export-key="format" data-export-value="png">PNG</button>
|
||||
<button data-export-key="format" data-export-value="jpeg">JPG</button>
|
||||
<button data-export-key="format" data-export-value="webp">WebP</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-row"><span>背景</span>
|
||||
<button data-export-key="bg" data-export-value="transparent">透明</button>
|
||||
<button data-export-key="bg" data-export-value="white">白底</button>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="iwb-editor-optionbar">
|
||||
<span class="iwb-editor-optionbar-label">工具选项</span>
|
||||
<div class="iwb-editor-optionbar-body"></div>
|
||||
<span class="iwb-editor-optionbar-tip">选区操作也可以右键,或用 Ctrl+J / Delete / Esc</span>
|
||||
</div>
|
||||
<div class="iwb-editor-main">
|
||||
|
||||
<div class="iwb-editor-layer-panel">
|
||||
@@ -90,6 +133,8 @@ import { bindEvents } from './events.js'
|
||||
<canvas class="iwb-editor-stroke"></canvas>
|
||||
<canvas class="iwb-editor-text"></canvas>
|
||||
<canvas class="iwb-editor-crop-overlay"></canvas>
|
||||
<canvas class="iwb-editor-selection-overlay"></canvas>
|
||||
<canvas class="iwb-editor-cursor-overlay"></canvas>
|
||||
</div>
|
||||
<input class="iwb-editor-text-input" type="text" placeholder="输入文字,Enter确认,Esc取消">
|
||||
<div class="iwb-editor-picker-tip"><span class="iwb-editor-picker-chip"></span><span class="iwb-editor-picker-hex">#ffffff</span></div>
|
||||
@@ -116,6 +161,16 @@ import { bindEvents } from './events.js'
|
||||
<button class="iwb-editor-crop-cancel" data-action="cancelCrop">✗ 取消</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="iwb-editor-sel-bar">
|
||||
<span class="iwb-editor-sel-info">未框选</span>
|
||||
<button data-sel-cmd="sel.copy" data-needs-sel="1" title="把当前图层选区复制为新图层 (Ctrl+J)">复制</button>
|
||||
<button data-sel-cmd="sel.cut" data-needs-sel="1" title="剪切到新图层 (Ctrl+X)">剪切</button>
|
||||
<button data-sel-cmd="sel.delete" data-needs-sel="1" title="只清除当前图层选区内容 (Delete)">删除</button>
|
||||
<button data-sel-cmd="sel.fill" data-needs-sel="1" title="用当前颜色填充选区">填充</button>
|
||||
<button data-sel-cmd="sel.invert" data-needs-sel="1" title="反选 (Ctrl+Shift+I)">反选</button>
|
||||
<button data-sel-cmd="sel.all" title="全选 (Ctrl+A)">全选</button>
|
||||
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
||||
|
||||
@@ -161,6 +216,15 @@ import { bindEvents } from './events.js'
|
||||
<div class="iwb-editor-footer">
|
||||
|
||||
</div>
|
||||
<div class="iwb-editor-statusbar">
|
||||
<span class="iwb-editor-status-zoom">100%</span>
|
||||
<span class="iwb-editor-status-size">—</span>
|
||||
<span class="iwb-editor-status-pos">x — y —</span>
|
||||
<span class="iwb-editor-status-sel">无选区</span>
|
||||
<span class="iwb-editor-status-layer">当前层:画笔标注</span>
|
||||
<span class="iwb-editor-status-tool">画笔</span>
|
||||
</div>
|
||||
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
||||
</div>
|
||||
`
|
||||
document.body.appendChild(runtime.el)
|
||||
@@ -171,9 +235,13 @@ import { bindEvents } from './events.js'
|
||||
S.textCanvas = runtime.el.querySelector('.iwb-editor-text')
|
||||
S.strokeCanvas = runtime.el.querySelector('.iwb-editor-stroke')
|
||||
S.overlayCanvas = runtime.el.querySelector('.iwb-editor-crop-overlay')
|
||||
S.selectionCanvas = runtime.el.querySelector('.iwb-editor-selection-overlay')
|
||||
S.cursorCanvas = runtime.el.querySelector('.iwb-editor-cursor-overlay')
|
||||
S.textCtx = S.textCanvas.getContext('2d')
|
||||
S.strokeCtx = S.strokeCanvas.getContext('2d')
|
||||
S.overlayCtx = S.overlayCanvas.getContext('2d')
|
||||
S.selectionCtx = S.selectionCanvas.getContext('2d')
|
||||
S.cursorCtx = S.cursorCanvas.getContext('2d')
|
||||
|
||||
bindEvents()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user