feat(image-annotate): 1.2.6 图层新建/导入回面板标题栏 + 还原图标改循环重置 + 适应窗口真重算 fit + 全量 PS 快捷键(V/M/L/B/E/P/T/U/C/I/H, Ctrl+0/1/S/O/Shift+N, Tab, Shift+U/M)

This commit is contained in:
qiqi committed 2026-11-04 21:49:49 +08:00
1 parent c87cec659b
commit 9e50697dd6
7 files changed
+304 -90

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/image-annotate",
"private": true,
"version": "1.2.5",
"version": "1.2.6",
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
"ibwPlugin": {
"id": "image-annotate",
+25 -26
View File
@@ -23,15 +23,10 @@ import { bindEvents } from './events.js'
<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"><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-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>
<!-- 顶栏命令带(v1.2.4):原「更多 ▾」菜单全部铺开成图标,按 图层 / 顺序 / 视图 分三组 -->
<!-- 顶栏命令带(v1.2.6):撤销/重做/还原 | 顺序 | 视图;图层新建/导入回图层面板标题栏 -->
<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>
@@ -40,38 +35,38 @@ import { bindEvents } from './events.js'
</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>
<button class="iwb-editor-action" data-action="zoomFit" title="适应窗口 (Ctrl+0)"><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="收起 / 展开侧栏 (Tab)"><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>
<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="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><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>
<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>
<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="画笔"><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)"><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>
<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="pen" title="钢笔:点击添加节点,双击或 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>
<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>
<button class="iwb-editor-tool" data-tool="text" 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="4 7 4 3 20 3 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="3" x2="12" y2="20"/></svg></button>
<button class="iwb-editor-tool" data-tool="text" title="文字 (T)"><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="4 7 4 3 20 3 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="3" x2="12" y2="20"/></svg></button>
<button class="iwb-editor-tool" data-tool="rect" 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"/></svg></button>
<button class="iwb-editor-tool" data-tool="rect" title="矩形 (U):Shift+U 在矩形/圆形/箭头间循环"><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"/></svg></button>
<button class="iwb-editor-tool" data-tool="circle" title="圆形"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8"/></svg></button>
<button class="iwb-editor-tool" data-tool="circle" title="圆形 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8"/></svg></button>
<button class="iwb-editor-tool" data-tool="arrow" title="箭头"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
<button class="iwb-editor-tool" data-tool="arrow" title="箭头 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
<button class="iwb-editor-tool" data-tool="picker" 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="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<button class="iwb-editor-tool" data-tool="picker" title="吸管 (I):点击画布取色(悬停预览),取色后自动切回上一工具"><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="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<button class="iwb-editor-tool" data-tool="hand" 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="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"/><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v2"/><path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v8"/><path d="M18 10a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/></svg></button>
<button class="iwb-editor-tool" data-tool="hand" title="抓手 (H):拖拽自由移动画布(任意工具下按住空格或鼠标中键也可平移)"><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="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"/><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v2"/><path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v8"/><path d="M18 10a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/></svg></button>
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-tool" data-tool="crop" title="裁剪(参数在选项栏;Enter 确认 / Esc 取消)"><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="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<button class="iwb-editor-tool" data-tool="crop" title="裁剪 (C):参数在选项栏;Enter 确认 / Esc 取消"><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="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<span class="iwb-editor-divider"></span>
</div>
@@ -117,14 +112,18 @@ import { bindEvents } from './events.js'
<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>
<span class="iwb-editor-optionbar-tip">选区也可右键;Ctrl+J 复制 · Delete 清除 · Ctrl+D 取消</span>
</div>
<div class="iwb-editor-main">
<div class="iwb-editor-layer-panel">
<div class="iwb-editor-layer-panel-header">
<span class="iwb-editor-layer-panel-title">图层</span>
<!-- 新建图层 / 导入图片已上移到顶栏命令带(v1.2.4),面板只留标题,避免同一功能两个入口 -->
<!-- 图层的「新建 / 导入图片」回到标题栏右侧(用户裁定 2026-11-04:顶栏只留顺序与视图命令) -->
<div class="iwb-editor-layer-add-group">
<button class="iwb-editor-layer-add-btn" data-action="addBlankLayer" title="新建空白图层 (Ctrl+Shift+N)"><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>
<button class="iwb-editor-layer-add-btn" data-action="addBitmapLayer" title="导入图片为新图层 (Ctrl+O),也可直接 ⌘/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>
</div>
</div>
<!-- 图层顺序(置顶/上移/下移/置底)已移到顶栏命令带(v1.2.4) -->
@@ -161,9 +160,9 @@ import { bindEvents } from './events.js'
<!-- 描边粗细/快捷点已从侧栏移除(用户裁定 2026-11-04):都收进工具选项栏一处,
侧栏只保留调色板与缩放,避免「同一参数两个入口、数值还对不上」 -->
<div class="iwb-editor-zoom">
<button class="iwb-editor-zoom-btn" data-action="zoomOut" title="缩小 (滚轮向下)">−</button>
<button class="iwb-editor-zoom-btn" data-action="zoomOut" title="缩小 (Ctrl+- / 滚轮向下)">−</button>
<span class="iwb-editor-zoom-val" title="滚轮缩放">100%</span>
<button class="iwb-editor-zoom-btn" data-action="zoomIn" title="放大 (滚轮向上)">+</button>
<button class="iwb-editor-zoom-btn" data-action="zoomIn" title="放大 (Ctrl++ / 滚轮向上)">+</button>
<button class="iwb-editor-zoom-btn iwb-editor-zoom-fit" data-action="zoomFit" title="适应窗口">适应</button>
</div>
</aside>
+79 -15
View File
@@ -7,7 +7,7 @@
'use strict'
import { S, ZOOM_STEP, runtime } from './state.js'
import { ROT_CURSOR, clamp, getPos, isOverRotationHandle, setView, setZoomFit, zoomStep } from './viewport.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 { 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'
@@ -1104,6 +1104,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
syncOptionBar()
}
/** 收起 / 展开左右侧栏(顶栏按钮与 PS 习惯的 Tab 键共用,状态写回 settings) */
export function togglePanelsCollapsed() {
const root = runtime.el
if (!root) return
const collapsed = !root.classList.contains('panels-collapsed')
root.classList.toggle('panels-collapsed', collapsed)
const st = S.callbacks && S.callbacks.settings
if (st && typeof st.set === 'function') {
try { st.set('panelsCollapsed', collapsed) } catch (err) { /* ignore */ }
}
toast(collapsed ? '侧栏已收起' : '侧栏已展开', 'info')
}
/** 顶栏命令带 / 面板收起 / 选项栏控件:只绑定一次,DOM 重绘不丢事件(委托) */
export function bindLiteUI() {
const root = runtime.el
@@ -1134,13 +1147,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
btn.addEventListener('mousedown', (e) => e.stopPropagation())
btn.addEventListener('click', (e) => {
e.stopPropagation()
const collapsed = !root.classList.contains('panels-collapsed')
root.classList.toggle('panels-collapsed', collapsed)
const st = S.callbacks && S.callbacks.settings
if (st && typeof st.set === 'function') {
try { st.set('panelsCollapsed', collapsed) } catch (err) { /* ignore */ }
}
toast(collapsed ? '侧栏已收起' : '侧栏已展开', 'info')
togglePanelsCollapsed()
closeMenus()
})
})
@@ -1700,6 +1707,51 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const mod = e.ctrlKey || e.metaKey
const key = String(e.key || '').toLowerCase()
// ================= PS 同款快捷键 =================
// 无修饰键:工具(V 移动 / M 选框 / L 套索 / B 画笔 / E 橡皮 / P 钢笔 / T 文字 / U 形状 / C 裁剪 / I 吸管 / H 抓手)
// 数字键 1–0 的老映射已按 PS 习惯移除(PS 里数字键是图层不透明度)。
const letterTools = {
v: 'select', m: 'marquee', l: 'lasso', b: 'brush', e: 'eraser', p: 'pen',
t: 'text', u: 'rect', c: 'crop', i: 'picker', h: 'hand'
}
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(letterTools, key)) {
e.preventDefault()
if (e.shiftKey && key === 'u') {
// PS: Shift+U 在同类形状工具间循环
const cycle = { rect: 'circle', circle: 'arrow', arrow: 'rect' }
setTool(cycle[S.tool] || 'rect')
} else if (e.shiftKey && key === 'm') {
// PS: Shift+M 在矩形/椭圆选框间切换
S.selectionKind = S.selectionKind === 'ellipse' ? 'rect' : 'ellipse'
setTool('marquee')
toast('选区形状:' + (S.selectionKind === 'ellipse' ? '椭圆' : '矩形'), 'info')
renderOptionBar(true)
} else {
setTool(letterTools[key])
}
return
}
if (!mod && !e.altKey && key === 'tab') {
e.preventDefault()
togglePanelsCollapsed()
return
}
// 视图:Ctrl+0 适应窗口 / Ctrl+1 100% / Ctrl+± 缩放(PS 习惯)
if (mod && !e.shiftKey && e.key === '0') { e.preventDefault(); setZoomFit(); return }
if (mod && !e.shiftKey && e.key === '1') { e.preventDefault(); setZoomActual(); return }
if (mod && (e.key === '+' || e.key === '=')) {
e.preventDefault()
zoomStep(ZOOM_STEP, S.canvasWrap.clientWidth / 2, S.canvasWrap.clientHeight / 2)
return
}
if (mod && e.key === '-') {
e.preventDefault()
zoomStep(1 / ZOOM_STEP, S.canvasWrap.clientWidth / 2, S.canvasWrap.clientHeight / 2)
return
}
// ---- 选区快捷键:与浮动条 / 右键菜单共用同一命令层 ----
if (mod && key === 'a') { e.preventDefault(); runCommand('sel.all'); return }
if (mod && e.shiftKey && key === 'i') { e.preventDefault(); runCommand('sel.invert'); return }
@@ -1707,17 +1759,22 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (mod && key === 'j') { e.preventDefault(); runCommand('sel.copy'); return }
if (mod && key === 'x' && S.selection && S.selection.active) { e.preventDefault(); runCommand('sel.cut'); return }
// 数字键 1–0 保留兼容;另加 PS 习惯的字母键(无修饰键时才生效)
const toolByKey = { '1': 'select', '2': 'brush', '3': 'eraser', '4': 'pen', '5': 'text', '6': 'rect', '7': 'circle', '8': 'arrow', '9': 'picker', '0': 'crop' }
const letterTools = { m: 'marquee', l: 'lasso', v: 'select', b: 'brush', e: 'eraser', t: 'text', c: 'crop' }
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(toolByKey, e.key)) {
// 文件类:Ctrl+Shift+N 新建图层 / Ctrl+O 导入图片 / Ctrl+S 导出下载
if (mod && e.shiftKey && key === 'n') {
e.preventDefault()
setTool(toolByKey[e.key])
addBlankLayer()
return
}
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(letterTools, key)) {
if (mod && !e.shiftKey && key === 'o') {
e.preventDefault()
setTool(letterTools[key])
const b = runtime.el && runtime.el.querySelector('[data-action="addBitmapLayer"]')
if (b) b.click()
return
}
if (mod && key === 's') {
e.preventDefault()
const b = runtime.el && runtime.el.querySelector('[data-action="download"]')
if (b) b.click()
return
}
@@ -1745,6 +1802,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (mod && key === 'z') {
e.preventDefault()
if (e.shiftKey) redo(); else undo()
return
}
// PS: Ctrl+Y 也等于重做(Windows 习惯)
if (mod && key === 'y') {
e.preventDefault()
redo()
return
}
}
+2
View File
@@ -285,6 +285,8 @@ import { toast } from './commands.js'
open: S.open,
tool: S.tool,
doc: { w: S.imgW, h: S.imgH },
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 })),
texts: S.textLayers.map(t => ({ id: t.id, text: t.text })),
+13
View File
@@ -214,12 +214,25 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
applyView({ mx, my, px, py })
}
/**
* 适应窗口:先按当前容器尺寸重算基准显示尺寸,再回到 zoom=1 并居中。
* 只写 zoom=1 不够 —— 窗口/侧栏变过之后 fitW/fitH 还是旧值,点了看起来「没反应」。
*/
export function setZoomFit() {
computeFit()
S.zoom = 1
S.viewX = null
applyView()
}
/** 100% 实际像素(PS: Ctrl+1)。S.zoom 是相对 fitW 的倍数,所以要换算。 */
export function setZoomActual() {
computeFit()
S.zoom = clamp(S.fitW ? S.imgW / S.fitW : 1, ZOOM_MIN, ZOOM_MAX)
S.viewX = null
applyView()
}
export function clamp(v, min, max) { return Math.max(min, Math.min(max, v)) }
// ============ 旋转辅助 ============
+120 -43
View File
@@ -9,7 +9,7 @@
var __IWB_ANNOTATE_MANIFEST__ = {
id: 'image-annotate',
name: '标注 / 修图',
version: '1.2.5',
version: '1.2.6',
apiVersion: 1,
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
settings: {
@@ -2654,15 +2654,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<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"><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-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>
<!-- 顶栏命令带(v1.2.4):原「更多 ▾」菜单全部铺开成图标,按 图层 / 顺序 / 视图 分三组 -->
<!-- 顶栏命令带(v1.2.6):撤销/重做/还原 | 顺序 | 视图;图层新建/导入回图层面板标题栏 -->
<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>
@@ -2671,38 +2666,38 @@ var __IWB_ANNOTATE_MANIFEST__ = {
</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>
<button class="iwb-editor-action" data-action="zoomFit" title="适应窗口 (Ctrl+0)"><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="收起 / 展开侧栏 (Tab)"><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>
<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="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><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>
<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>
<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="画笔"><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)"><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>
<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="pen" title="钢笔:点击添加节点,双击或 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>
<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>
<button class="iwb-editor-tool" data-tool="text" 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="4 7 4 3 20 3 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="3" x2="12" y2="20"/></svg></button>
<button class="iwb-editor-tool" data-tool="text" title="文字 (T)"><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="4 7 4 3 20 3 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="3" x2="12" y2="20"/></svg></button>
<button class="iwb-editor-tool" data-tool="rect" 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"/></svg></button>
<button class="iwb-editor-tool" data-tool="rect" title="矩形 (U):Shift+U 在矩形/圆形/箭头间循环"><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"/></svg></button>
<button class="iwb-editor-tool" data-tool="circle" title="圆形"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8"/></svg></button>
<button class="iwb-editor-tool" data-tool="circle" title="圆形 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8"/></svg></button>
<button class="iwb-editor-tool" data-tool="arrow" title="箭头"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
<button class="iwb-editor-tool" data-tool="arrow" title="箭头 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
<button class="iwb-editor-tool" data-tool="picker" 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="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<button class="iwb-editor-tool" data-tool="picker" title="吸管 (I):点击画布取色(悬停预览),取色后自动切回上一工具"><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="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<button class="iwb-editor-tool" data-tool="hand" 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="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"/><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v2"/><path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v8"/><path d="M18 10a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/></svg></button>
<button class="iwb-editor-tool" data-tool="hand" title="抓手 (H):拖拽自由移动画布(任意工具下按住空格或鼠标中键也可平移)"><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="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"/><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v2"/><path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v8"/><path d="M18 10a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/></svg></button>
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-tool" data-tool="crop" title="裁剪(参数在选项栏;Enter 确认 / Esc 取消)"><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="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<button class="iwb-editor-tool" data-tool="crop" title="裁剪 (C):参数在选项栏;Enter 确认 / Esc 取消"><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="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<span class="iwb-editor-divider"></span>
</div>
@@ -2748,14 +2743,18 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<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>
<span class="iwb-editor-optionbar-tip">选区也可右键;Ctrl+J 复制 · Delete 清除 · Ctrl+D 取消</span>
</div>
<div class="iwb-editor-main">
<div class="iwb-editor-layer-panel">
<div class="iwb-editor-layer-panel-header">
<span class="iwb-editor-layer-panel-title">图层</span>
<!-- 新建图层 / 导入图片已上移到顶栏命令带(v1.2.4),面板只留标题,避免同一功能两个入口 -->
<!-- 图层的「新建 / 导入图片」回到标题栏右侧(用户裁定 2026-11-04:顶栏只留顺序与视图命令) -->
<div class="iwb-editor-layer-add-group">
<button class="iwb-editor-layer-add-btn" data-action="addBlankLayer" title="新建空白图层 (Ctrl+Shift+N)"><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>
<button class="iwb-editor-layer-add-btn" data-action="addBitmapLayer" title="导入图片为新图层 (Ctrl+O),也可直接 ⌘/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>
</div>
</div>
<!-- 图层顺序(置顶/上移/下移/置底)已移到顶栏命令带(v1.2.4) -->
@@ -2792,9 +2791,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<!-- 描边粗细/快捷点已从侧栏移除(用户裁定 2026-11-04):都收进工具选项栏一处,
侧栏只保留调色板与缩放,避免「同一参数两个入口、数值还对不上」 -->
<div class="iwb-editor-zoom">
<button class="iwb-editor-zoom-btn" data-action="zoomOut" title="缩小 (滚轮向下)">−</button>
<button class="iwb-editor-zoom-btn" data-action="zoomOut" title="缩小 (Ctrl+- / 滚轮向下)">−</button>
<span class="iwb-editor-zoom-val" title="滚轮缩放">100%</span>
<button class="iwb-editor-zoom-btn" data-action="zoomIn" title="放大 (滚轮向上)">+</button>
<button class="iwb-editor-zoom-btn" data-action="zoomIn" title="放大 (Ctrl++ / 滚轮向上)">+</button>
<button class="iwb-editor-zoom-btn iwb-editor-zoom-fit" data-action="zoomFit" title="适应窗口">适应</button>
</div>
</aside>
@@ -3885,6 +3884,20 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}
syncOptionBar();
}
function togglePanelsCollapsed() {
const root = runtime.el;
if (!root) return;
const collapsed = !root.classList.contains("panels-collapsed");
root.classList.toggle("panels-collapsed", collapsed);
const st = S.callbacks && S.callbacks.settings;
if (st && typeof st.set === "function") {
try {
st.set("panelsCollapsed", collapsed);
} catch (err) {
}
}
toast(collapsed ? "侧栏已收起" : "侧栏已展开", "info");
}
function bindLiteUI() {
const root = runtime.el;
if (!root || root.dataset.liteBound === "1") return;
@@ -3909,16 +3922,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
btn.addEventListener("mousedown", (e) => e.stopPropagation());
btn.addEventListener("click", (e) => {
e.stopPropagation();
const collapsed = !root.classList.contains("panels-collapsed");
root.classList.toggle("panels-collapsed", collapsed);
const st = S.callbacks && S.callbacks.settings;
if (st && typeof st.set === "function") {
try {
st.set("panelsCollapsed", collapsed);
} catch (err) {
}
}
toast(collapsed ? "侧栏已收起" : "侧栏已展开", "info");
togglePanelsCollapsed();
closeMenus();
});
});
@@ -4503,6 +4507,59 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (isTyping(e)) return;
const mod = e.ctrlKey || e.metaKey;
const key = String(e.key || "").toLowerCase();
const letterTools = {
v: "select",
m: "marquee",
l: "lasso",
b: "brush",
e: "eraser",
p: "pen",
t: "text",
u: "rect",
c: "crop",
i: "picker",
h: "hand"
};
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(letterTools, key)) {
e.preventDefault();
if (e.shiftKey && key === "u") {
const cycle = { rect: "circle", circle: "arrow", arrow: "rect" };
setTool(cycle[S.tool] || "rect");
} else if (e.shiftKey && key === "m") {
S.selectionKind = S.selectionKind === "ellipse" ? "rect" : "ellipse";
setTool("marquee");
toast("选区形状:" + (S.selectionKind === "ellipse" ? "椭圆" : "矩形"), "info");
renderOptionBar(true);
} else {
setTool(letterTools[key]);
}
return;
}
if (!mod && !e.altKey && key === "tab") {
e.preventDefault();
togglePanelsCollapsed();
return;
}
if (mod && !e.shiftKey && e.key === "0") {
e.preventDefault();
setZoomFit();
return;
}
if (mod && !e.shiftKey && e.key === "1") {
e.preventDefault();
setZoomActual();
return;
}
if (mod && (e.key === "+" || e.key === "=")) {
e.preventDefault();
zoomStep(ZOOM_STEP, S.canvasWrap.clientWidth / 2, S.canvasWrap.clientHeight / 2);
return;
}
if (mod && e.key === "-") {
e.preventDefault();
zoomStep(1 / ZOOM_STEP, S.canvasWrap.clientWidth / 2, S.canvasWrap.clientHeight / 2);
return;
}
if (mod && key === "a") {
e.preventDefault();
runCommand("sel.all");
@@ -4528,16 +4585,21 @@ var __IWB_ANNOTATE_MANIFEST__ = {
runCommand("sel.cut");
return;
}
const toolByKey = { "1": "select", "2": "brush", "3": "eraser", "4": "pen", "5": "text", "6": "rect", "7": "circle", "8": "arrow", "9": "picker", "0": "crop" };
const letterTools = { m: "marquee", l: "lasso", v: "select", b: "brush", e: "eraser", t: "text", c: "crop" };
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(toolByKey, e.key)) {
if (mod && e.shiftKey && key === "n") {
e.preventDefault();
setTool(toolByKey[e.key]);
addBlankLayer();
return;
}
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(letterTools, key)) {
if (mod && !e.shiftKey && key === "o") {
e.preventDefault();
setTool(letterTools[key]);
const b = runtime.el && runtime.el.querySelector('[data-action="addBitmapLayer"]');
if (b) b.click();
return;
}
if (mod && key === "s") {
e.preventDefault();
const b = runtime.el && runtime.el.querySelector('[data-action="download"]');
if (b) b.click();
return;
}
if (e.key === "Delete" || e.key === "Backspace") {
@@ -4577,6 +4639,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
e.preventDefault();
if (e.shiftKey) redo();
else undo();
return;
}
if (mod && key === "y") {
e.preventDefault();
redo();
return;
}
}
function onKeyup(e) {
@@ -4808,10 +4876,17 @@ var __IWB_ANNOTATE_MANIFEST__ = {
applyView({ mx, my, px, py });
}
function setZoomFit() {
computeFit();
S.zoom = 1;
S.viewX = null;
applyView();
}
function setZoomActual() {
computeFit();
S.zoom = clamp(S.fitW ? S.imgW / S.fitW : 1, ZOOM_MIN, ZOOM_MAX);
S.viewX = null;
applyView();
}
function clamp(v, min, max) {
return Math.max(min, Math.min(max, v));
}
@@ -6034,6 +6109,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
open: S.open,
tool: S.tool,
doc: { w: S.imgW, h: S.imgH },
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 })),
texts: S.textLayers.map((t) => ({ id: t.id, text: t.text })),
+64 -5
View File
@@ -96,7 +96,7 @@ const boot = await page.evaluate((png) => {
window.__commands['annotate-selected'].run().catch(() => {})
return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) }
}, PNG)
check('产物可执行(循环打包未炸)', boot.version === '1.2.5', 'version=' + boot.version)
check('产物可执行(循环打包未炸)', boot.version === '1.2.6', 'version=' + boot.version)
check('manifest 声明输出预设设置项', boot.settingsSchema.includes('exportPreset') && boot.settingsSchema.includes('panelsCollapsed'), boot.settingsSchema.join(','))
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
@@ -656,16 +656,75 @@ await page.keyboard.press('Control+z') // 撤销还原,恢复图层结构
// ---- v1.2.4:顶栏命令带(「更多」图标化)/ 选择工具就地改形状参数 ----
check('「更多」菜单已移除,新建/导入/顺序/视图图标进顶栏命令带', await page.evaluate(() => {
check('「更多」菜单已移除;顶栏只留顺序/视图命令,图层新建与导入回图层面板标题栏', await page.evaluate(() => {
const q = (s) => Boolean(document.querySelector(s))
const hdrCmds = document.querySelectorAll('.iwb-editor-header .iwb-editor-commands .iwb-editor-layer-btn').length
return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') && hdrCmds === 4 &&
q('.iwb-editor-header [data-action="addBitmapLayer"]') &&
q('.iwb-editor-header [data-action="addBlankLayer"]') &&
const titleBar = document.querySelector('.iwb-editor-layer-panel-header')
const addBtns = titleBar ? titleBar.querySelectorAll('.iwb-editor-layer-add-btn').length : 0
const hdrAdd = document.querySelector('.iwb-editor-header [data-action="addBlankLayer"], .iwb-editor-header [data-action="addBitmapLayer"]')
return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') && hdrCmds === 4 && !hdrAdd &&
addBtns === 2 && q('.iwb-editor-layer-panel-header [data-action="addBlankLayer"]') &&
q('.iwb-editor-layer-panel-header [data-action="addBitmapLayer"]') &&
q('.iwb-editor-header [data-action="zoomFit"]') &&
q('.iwb-editor-header [data-action="togglePanels"]')
}))
check('「还原原图」图标是循环重置(refresh)而不是垃圾桶', await page.evaluate(() => {
const svg = document.querySelector('.iwb-editor-header [data-action="reset"] svg')
if (!svg) return false
const paths = svg.querySelectorAll('path').length
const polys = Array.from(svg.querySelectorAll('polyline')).map(p => p.getAttribute('points')).join('|')
return paths >= 4 && polys.indexOf('3 6 5 6 21 6') < 0
}))
check('适应窗口按钮真的生效(放大后点它回到 fit 基线并居中)', await (async () => {
await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click()
await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click()
const zoomed = (await dbg()).zoom
await page.locator('.iwb-editor-header [data-action="zoomFit"]').click()
const fitted = (await dbg()).zoom
return zoomed > 1 && Math.abs(fitted - 1) < 0.001
})())
check('PS 快捷键:V/M/L/B/E/P/T/U/C/I/H 切工具', await (async () => {
// 先点一下工具按钮,保证焦点不在输入框里(isTyping() 会吞掉无修饰键快捷键)
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
const seq = [['v', 'select'], ['m', 'marquee'], ['l', 'lasso'], ['b', 'brush'], ['e', 'eraser'],
['p', 'pen'], ['t', 'text'], ['u', 'rect'], ['c', 'crop'], ['i', 'picker'], ['h', 'hand']]
for (const [k, tool] of seq) {
await page.keyboard.press(k)
if ((await dbg()).tool !== tool) return false
}
return true
})())
check('Shift+U 在 矩形/圆形/箭头 间循环(PS 同类工具循环)', await (async () => {
await page.keyboard.press('u')
await page.keyboard.press('Shift+u')
const a = (await dbg()).tool
await page.keyboard.press('Shift+u')
const b = (await dbg()).tool
return a === 'circle' && b === 'arrow'
})())
check('Tab 收起 / 展开侧栏(PS 习惯)', await (async () => {
await page.keyboard.press('Tab')
const collapsed = await page.evaluate(() => document.querySelector('.iwb-editor-overlay').classList.contains('panels-collapsed'))
await page.keyboard.press('Tab')
const restored = await page.evaluate(() => document.querySelector('.iwb-editor-overlay').classList.contains('panels-collapsed'))
return collapsed === true && restored === false
})())
check('Ctrl+1 = 100% 实际像素 / Ctrl+0 = 适应窗口', await (async () => {
await page.keyboard.press('Control+1')
const d1 = await dbg()
// S.zoom 是相对 fitW 的倍数:100% 实际像素 = doc.w / fit.w(小图会被放大铺满,所以可能 < 1)
const expect = d1.doc.w / d1.fit.w
const okActual = Math.abs(d1.zoom - expect) < 0.02
await page.keyboard.press('Control+0')
return okActual && Math.abs((await dbg()).zoom - 1) < 0.001
})())
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
check('选择工具的选项栏里有 全选/反选/取消 三个命令(竖工具条不再有)', await page.evaluate(() => {
const cmds = document.querySelectorAll('.iwb-editor-optionbar-body .iwb-opt-selcmd[data-more]')