Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e76f2792e | ||
|
|
7c2e23e4e3 |
No files matched your search
@@ -3,6 +3,11 @@ name: validate
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
# 只改文档/CI 自身不触发:额度按 job 分钟累计(HANDBOOK 第八节 8.2 第 3 条)
|
||||||
|
paths-ignore:
|
||||||
|
- '**/*.md'
|
||||||
|
- 'docs/**'
|
||||||
|
- '.github/**'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|||||||
@@ -234,6 +234,46 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
|||||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||||
|
|
||||||
|
## v1.7:图层面板补齐(缩略图 / 改名 / 不透明度)
|
||||||
|
|
||||||
|
发布后通读全仓(10 个模块 9368 行)发现的缺口,按「改完就能天天用到」的顺序处理。
|
||||||
|
|
||||||
|
### 不透明度终于能调了
|
||||||
|
|
||||||
|
`opacity` 字段一直在(合成、合并、导出、快照都读它),但面板上没有任何控件能写它,
|
||||||
|
roadmap 里标着「✅ 已有」与实际不符。现在选中图层后,该项下方展开一条滑杆:
|
||||||
|
|
||||||
|
| 项 | 行为 |
|
||||||
|
| --- | --- |
|
||||||
|
| 载体 | 位图走 canvas 的 CSS `opacity`(像素不动);文字/形状改完重绘矢量层 |
|
||||||
|
| 导出 / 合并 | 位图在合成时乘 `globalAlpha`,与屏幕所见一致 |
|
||||||
|
| 撤销 | 一次拖动只拍 1 张快照(`input` 先到才拍,松手不再重复) |
|
||||||
|
| 复位 | 双击滑杆回 100%;非 100% 且未选中的层在名字旁挂 `55%` 角标 |
|
||||||
|
|
||||||
|
**矢量层不重复乘 alpha**:`drawVectorToCanvas` / `drawShape` 已经把 `opacity` 画进像素,
|
||||||
|
`getCompositeCanvas` 与 `composeUnitsInto` 再乘一次就是双倍透明 —— 两处都改成只对位图乘。
|
||||||
|
|
||||||
|
### 缩略图与重命名
|
||||||
|
|
||||||
|
- 每项左侧 22px 缩略图(设备像素 44,高分屏不糊),把图层 canvas 等比缩进框内;
|
||||||
|
空图层没内容时缩略图透明,垫在下面的类型图标就露出来当兜底。
|
||||||
|
- 画缩略图**合批 90ms**:连续选中 / 拖动时不会每次 `renderLayerPanel` 都重画几十张。
|
||||||
|
- 双击图层名进入改名(Enter 提交、Esc 放弃,自动拍快照)。重命名期间禁用整项拖动,
|
||||||
|
否则在输入框里拖选文字会变成拖动图层排序。
|
||||||
|
- 双击判定是**自己算的**:点一下名字就 `setActiveLayer` → `renderLayerPanel` 重建整块
|
||||||
|
`innerHTML`,第二次点击落在新节点上,浏览器不会再派发 `dblclick`(和 v1.5 画布双击同一个坑)。
|
||||||
|
顺带让 `setActiveLayer` 在「已经是它」时直接返回,少一次无谓重建。
|
||||||
|
|
||||||
|
### 顺手清掉的三处
|
||||||
|
|
||||||
|
1. **删掉两个永远看不见的控件**:面板里 `.iwb-layer-color` / `.iwb-layer-width` 被 CSS
|
||||||
|
`display:none !important` 连写三遍隐藏(v1.2 把颜色/线宽搬去选项栏后的遗留),
|
||||||
|
绑定还在,每次 `input` 都 `renderLayerPanel()` 把整块 DOM 换掉 —— 一旦哪天取消隐藏,
|
||||||
|
取色器会当场断开、数字框打不进两位数。连同绑定与死样式一起删除。
|
||||||
|
2. **`pasteImageFromUrl` 不再用 `window.alert`**:改走 `toast`,阻塞弹窗在宿主里会卡住整页。
|
||||||
|
3. **`resetState()` 补齐跨会话残留**:`layerMulti` / `hoverPos` / `lastClick` / `lastNameClick` /
|
||||||
|
`altPicker` 之前不清,重开编辑器时会指向上一张图已经不存在的图层。
|
||||||
|
|
||||||
## 入口
|
## 入口
|
||||||
|
|
||||||
- **节点漂浮菜单**「标注 / 修图」(**仅 `ref` 图片输入节点**)
|
- **节点漂浮菜单**「标注 / 修图」(**仅 `ref` 图片输入节点**)
|
||||||
@@ -297,14 +337,27 @@ npm run validate # 契约校验
|
|||||||
|
|
||||||
> 注意:banner 的**注释**里也不能出现 id + 冒号 + 单引号的组合,否则会被校验器当成 manifest 抢走(踩过一次)。
|
> 注意:banner 的**注释**里也不能出现 id + 冒号 + 单引号的组合,否则会被校验器当成 manifest 抢走(踩过一次)。
|
||||||
|
|
||||||
## 发布
|
## 发布(按 HANDBOOK 第八节:先提交 → 合主干 → 再发布)
|
||||||
```bash
|
```bash
|
||||||
|
# 1) 源码与产物先落库,并确保 HEAD 已在 origin/main(脚本会强制校验这两条)
|
||||||
|
cd /Users/qiqi/open/github/iwb-plugins
|
||||||
|
npm run build -- image-annotate && npm run validate
|
||||||
|
git add image-annotate && git commit -m "feat(image-annotate): v1.7.0 ..." && git push
|
||||||
|
git switch main && git merge --ff-only <你的分支> && git push
|
||||||
|
|
||||||
|
# 2) 用带守卫的发布脚本(旧 plugins-publish.mjs 会绕过校验,不要再用)
|
||||||
cd /Users/qiqi/open/github/image-workbench-web
|
cd /Users/qiqi/open/github/image-workbench-web
|
||||||
cp /Users/qiqi/open/github/iwb-plugins/image-annotate/src/index.js /tmp/plugin-image-annotate.js
|
scripts/plugins-publish.sh image-annotate \
|
||||||
node scripts/plugins-publish.mjs /tmp/plugin-image-annotate.js --version image-annotate=1.0.5 # 先 dry-run,检查后加 --upload
|
/Users/qiqi/open/github/iwb-plugins/image-annotate/src/index.js 1.7.0
|
||||||
|
|
||||||
|
# 3) 脚本会打 annotated tag 但不会推,手动补
|
||||||
|
git -C /Users/qiqi/open/github/iwb-plugins push origin [email protected]
|
||||||
```
|
```
|
||||||
发布脚本**默认与线上清单合并**(本次没传的插件原样保留),只传自己的文件即可;`--prune` 才会缩减清单(别用)。
|
脚本的三道前置校验:工作区干净、HEAD 是 `origin/main` 的祖先、`wrangler.toml` 有 KV namespace。
|
||||||
版本两处一起改:`package.json`(构建时注入 manifest)+ `--version`。上传后回读校验清单与本地一致。
|
任一条不满足直接拒发(紧急热修才用 `IWB_PUBLISH_SKIP_CHECKS=1`,事后必须补合并与 tag)。
|
||||||
|
|
||||||
|
发布脚本**默认与线上清单合并**(本次没传的插件原样保留),只传自己的文件即可;`--remove` 才是从清单移除。
|
||||||
|
版本两处一起改:`package.json`(构建时注入 manifest)+ 脚本第 3 个参数。上传后回读校验清单与本地一致。
|
||||||
发布后刷新即生效(KV 为测试站/正式站共享;新插件在插件管理里**默认未启用**,需手动开启)。
|
发布后刷新即生效(KV 为测试站/正式站共享;新插件在插件管理里**默认未启用**,需手动开启)。
|
||||||
|
|
||||||
## 验证(可选,开发用)
|
## 验证(可选,开发用)
|
||||||
|
|||||||
@@ -60,8 +60,8 @@
|
|||||||
| 选框 / 套索 / 魔棒 | ✅ 矩形、椭圆、多边形、自由套索;魔棒放二期 |
|
| 选框 / 套索 / 魔棒 | ✅ 矩形、椭圆、多边形、自由套索;魔棒放二期 |
|
||||||
| 选区变换 / 加减 / 反选 / 羽化 | ✅ 一期全做(羽化用 Canvas filter) |
|
| 选区变换 / 加减 / 反选 / 羽化 | ✅ 一期全做(羽化用 Canvas filter) |
|
||||||
| 复制 / 剪切到新图层、清除、填充、描边 | ✅ 核心,且做成选区旁的浮动操作条 |
|
| 复制 / 剪切到新图层、清除、填充、描边 | ✅ 核心,且做成选区旁的浮动操作条 |
|
||||||
| 图层 / 显隐 / 锁定 / 不透明度 / 排序 | ✅ 已有 |
|
| 图层 / 显隐 / 锁定 / 不透明度 / 排序 | ✅ 已有(不透明度 v1.7 才真正可调,之前只有字段没有控件) |
|
||||||
| 混合模式 / 图层蒙版 / 编组 / 缩略图 | 🟡 P3 补 |
|
| 混合模式 / 图层蒙版 / 编组 / 缩略图 | 🟡 缩略图与重命名 v1.7 已补;混合模式 / 蒙版 / 编组仍待做 |
|
||||||
| 裁剪 / 画布大小 / 图像大小 / 旋转翻转 | 🟡 P2 补,且改为可撤销 |
|
| 裁剪 / 画布大小 / 图像大小 / 旋转翻转 | 🟡 P2 补,且改为可撤销 |
|
||||||
| 自由变换(Ctrl+T) | 🟡 已有选中对象的移动/缩放/旋转,P2 扩展到选区内容 |
|
| 自由变换(Ctrl+T) | 🟡 已有选中对象的移动/缩放/旋转,P2 扩展到选区内容 |
|
||||||
| 画笔 / 橡皮 / 文字 / 形状 / 吸管 / 抓手 | ✅ 已有,不重写 |
|
| 画笔 / 橡皮 / 文字 / 形状 / 吸管 / 抓手 | ✅ 已有,不重写 |
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
| ---------------------- | ------------------------------------------------------------------- | ------------- |
|
| ---------------------- | ------------------------------------------------------------------- | ------------- |
|
||||||
| 裁剪即 flatten | `confirmCrop()` 合成所有可见层 → 重建 `base`/`draw`,图层结构全部丢失 | P2 |
|
| 裁剪即 flatten | `confirmCrop()` 合成所有可见层 → 重建 `base`/`draw`,图层结构全部丢失 | P2 |
|
||||||
| 裁剪不可撤销 | `S.history = []; S.redoStack = []` | P2 |
|
| 裁剪不可撤销 | `S.history = []; S.redoStack = []` | P2 |
|
||||||
| 裁剪丢变换信息 | 只对 `textLayers`/`shapeLayers` 映射 x/y/lw/fontSize,**没处理 `rotation`** | P2 |
|
| 裁剪丢变换信息 | 已核查(v1.7):`drawShape`/文字都用**由几何派生**的包围盒中心做旋转轴,裁剪缩放了几何就等于缩放了轴心,角度本身不随缩放变化 ⇒ 形状的旋转不需要单独处理。残留近似:文字在**非等比**缩放下只按 `scaleX` 缩放字号(等比裁剪精确) | P2(降级为已知近似) |
|
||||||
| 无「画布大小」/「图像大小」 | 只能靠裁剪栏的「尺寸约束」间接缩放 | P2 |
|
| 无「画布大小」/「图像大小」 | 只能靠裁剪栏的「尺寸约束」间接缩放 | P2 |
|
||||||
| 无 90° 旋转 / 水平垂直翻转 / 拉直 | 基础图像操作缺失 | P2 |
|
| 无 90° 旋转 / 水平垂直翻转 / 拉直 | 基础图像操作缺失 | P2 |
|
||||||
| 全幅画布模型 | 每个图层都被钉死在 imgW×imgH,裁剪必须重画所有层 | P0 设计 / P2 实施 |
|
| 全幅画布模型 | 每个图层都被钉死在 imgW×imgH,裁剪必须重画所有层 | P0 设计 / P2 实施 |
|
||||||
@@ -120,10 +120,10 @@
|
|||||||
|
|
||||||
| 缺口 | 说明 | 优先级 |
|
| 缺口 | 说明 | 优先级 |
|
||||||
| ------------------ | ----------------------------------------------------------------------------------------------- | ---------- |
|
| ------------------ | ----------------------------------------------------------------------------------------------- | ---------- |
|
||||||
| 无缩略图 | 图层多了分不清哪张是哪张 | P3 |
|
| ~~无缩略图~~ | ✅ v1.7:22px 缩略图 + 90ms 合批;空图层回落到类型图标 | 已完成 |
|
||||||
| 无混合模式 | 正片叠底/滤色/叠加是合成常用 | P3 |
|
| 无混合模式 | 正片叠底/滤色/叠加是合成常用 | P3 |
|
||||||
| 无图层蒙版 | 抠图只能破坏性擦除,不能反悔 | P3 |
|
| 无图层蒙版 | 抠图只能破坏性擦除,不能反悔 | P3 |
|
||||||
| 无重命名 / 多选 / 编组 | 复杂图难管理 | P3 |
|
| ~~无重命名 / 多选~~ / 编组 | ✅ v1.7:双击名字改名(自算双击)、⌘/Ctrl 点击多选合并;编组仍待做 | 部分完成 |
|
||||||
| `resetDraw()` 语义歧义 | 「清空标注」只清非 base 层像素,留下空白粘贴层(1.0.5 遗留)⇒ **已裁定改为「全部还原」**:删所有非 base 层 + 清绘制 + 复位变换,一步可撤销;按钮改名「还原原图」 | P0 定语义(已定) |
|
| `resetDraw()` 语义歧义 | 「清空标注」只清非 base 层像素,留下空白粘贴层(1.0.5 遗留)⇒ **已裁定改为「全部还原」**:删所有非 base 层 + 清绘制 + 复位变换,一步可撤销;按钮改名「还原原图」 | P0 定语义(已定) |
|
||||||
|
|
||||||
### 3.4 输出(单张)
|
### 3.4 输出(单张)
|
||||||
@@ -296,7 +296,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| **P4 单张输出** | PNG/JPG/WebP + 质量 + ≤500KB 策略 + 背景切换 + 下载/剪贴板 + 记住上次预设 | 单张导出尺寸/体积达标;透明像素正确;导出不污染画布;**无队列、无批量入口** |
|
| **P4 单张输出** | PNG/JPG/WebP + 质量 + ≤500KB 策略 + 背景切换 + 下载/剪贴板 + 记住上次预设 | 单张导出尺寸/体积达标;透明像素正确;导出不污染画布;**无队列、无批量入口** |
|
||||||
| **P5 打磨** | 右键菜单补全、全量快捷键、草稿、亮色主题、响应式、无障碍 | 窄窗口可用;草稿只存元数据不存像素 |
|
| **P5 打磨** | 右键菜单补全、全量快捷键、草稿、亮色主题、响应式、无障碍 | 窄窗口可用;草稿只存元数据不存像素 |
|
||||||
|
|
||||||
每一期都走同一条发布链:`plugin/editor/*.js` → `npm run build -- image-annotate` → `npm run validate` → 宿主仓 `plugins-publish.mjs --upload` → 真站 e2e(带 CSP)→ 两仓提交。版本两处同步(`package.json` + `--version`),禁止手改 `plugins/index.json`。
|
每一期都走同一条发布链:`plugin/editor/*.js` → `npm run build -- image-annotate` → `npm run validate` → **先提交源码并合进 `origin/main`** → 宿主仓 `scripts/plugins-publish.sh image-annotate <插件路径> <版本>`(带守卫,拒发脏工作区/未合主干)→ 补推 tag → 真站 e2e(带 CSP)。版本两处同步(`package.json` + 脚本参数),禁止手改 `plugins/index.json`。
|
||||||
|
|
||||||
### 6.1 实施进度(v1.1.0,2026-11-04 已交付)
|
### 6.1 实施进度(v1.1.0,2026-11-04 已交付)
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| P1 选区 | ✅ 矩形/椭圆/套索、羽化、反选/全选/取消、蚂蚁线、复制/剪切到新层、Delete(单层)、填充、画笔/橡皮受选区约束;加减选与选区变换留二期 |
|
| P1 选区 | ✅ 矩形/椭圆/套索、羽化、反选/全选/取消、蚂蚁线、复制/剪切到新层、Delete(单层)、填充、画笔/橡皮受选区约束;加减选与选区变换留二期 |
|
||||||
| P2 非破坏性裁剪 | ✅ v1.2.0:不再 flatten、不再清历史;逐图层搬运 + `resizeWorkspace()` 换尺寸,`restoreState()` 先复位尺寸再回填像素,可 Ctrl+Z / Ctrl+Shift+Z |
|
| P2 非破坏性裁剪 | ✅ v1.2.0:不再 flatten、不再清历史;逐图层搬运 + `resizeWorkspace()` 换尺寸,`restoreState()` 先复位尺寸再回填像素,可 Ctrl+Z / Ctrl+Shift+Z |
|
||||||
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
||||||
| P3 图层增强 | ⏳ 未做(缩略图 / 混合模式 / 蒙版) |
|
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
||||||
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
||||||
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
||||||
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
||||||
@@ -330,7 +330,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 草稿持久化 | `ctx.storage` 是 localStorage 命名空间小 KV(`get/set/remove/keys`),**不能塞像素**;`ctx.settings` 适合存输出预设与面板开合。若要做工程草稿,只能存元数据 + 宿主节点引用;真要存图层像素需插件自建 IndexedDB 库(必须自带 `onupgradeneeded` 建表,宿主踩过这个坑)或与宿主协商新能力 |
|
| 草稿持久化 | `ctx.storage` 是 localStorage 命名空间小 KV(`get/set/remove/keys`),**不能塞像素**;`ctx.settings` 适合存输出预设与面板开合。若要做工程草稿,只能存元数据 + 宿主节点引用;真要存图层像素需插件自建 IndexedDB 库(必须自带 `onupgradeneeded` 建表,宿主踩过这个坑)或与宿主协商新能力 |
|
||||||
| 节点模型 | 宿主 `setNodeImage` / `createImageNode` 只收一张图;导出即扁平化。要做「可继续编辑的工程」需要宿主侧支持节点附加数据 ⇒ 属于跨仓变更,P5 再评估 |
|
| 节点模型 | 宿主 `setNodeImage` / `createImageNode` 只收一张图;导出即扁平化。要做「可继续编辑的工程」需要宿主侧支持节点附加数据 ⇒ 属于跨仓变更,P5 再评估 |
|
||||||
| 上游关系 | 编辑器移植自 `iwb-plaus/iwb-cutout-extension`,README 已警告 1.0.5 的 z 序修复不能整目录覆盖回去。P0 的大改等于正式分叉,应在 README 明确改为「一次性移植 + 独立演进」,避免以后误回灌 |
|
| 上游关系 | 编辑器移植自 `iwb-plaus/iwb-cutout-extension`,README 已警告 1.0.5 的 z 序修复不能整目录覆盖回去。P0 的大改等于正式分叉,应在 README 明确改为「一次性移植 + 独立演进」,避免以后误回灌 |
|
||||||
| 发布契约 | 文件名 `plugin-image-annotate.js`、id 一致、SRI、内容寻址名、`--upload` 合并清单、三步验收;gc 时 `--keep ai-chat` |
|
| 发布契约 | 文件名 `plugin-image-annotate.js`、id 一致、SRI、内容寻址名、清单合并、tag 反查;脚本守卫强制「工作区干净 + HEAD 已在 origin/main」 |
|
||||||
| 测试 | 本地 mock 探针(直接注入 `src/index.js` + mock host)用于发布前验证;真站 e2e(CSP / KV / SRI)用于发布后验证;两者都保留 |
|
| 测试 | 本地 mock 探针(直接注入 `src/index.js` + mock host)用于发布前验证;真站 e2e(CSP / KV / SRI)用于发布后验证;两者都保留 |
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -366,7 +366,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 命令层 + 状态机 | 新增 2 模块 + 全部编辑入口 | 中高:触碰所有工具,必须逐工具回归 |
|
| 命令层 + 状态机 | 新增 2 模块 + 全部编辑入口 | 中高:触碰所有工具,必须逐工具回归 |
|
||||||
| Overlay 分层 | `crop.js` / `viewport.js` / `placement.js` / `objects.js` | 中:坐标基准 `getPos()` 不能变 |
|
| Overlay 分层 | `crop.js` / `viewport.js` / `placement.js` / `objects.js` | 中:坐标基准 `getPos()` 不能变 |
|
||||||
| 选区模型 + 像素操作 | 新增 `selection.js` + `layers.js` / `history.js` / `tools.js` | 高:内存、撤销、锁层、跨域边界都在这里 |
|
| 选区模型 + 像素操作 | 新增 `selection.js` + `layers.js` / `history.js` / `tools.js` | 高:内存、撤销、锁层、跨域边界都在这里 |
|
||||||
| 非破坏性裁剪(路线 1) | `crop.js` / `history.js` | 中:注意文字/形状 `rotation` 与越界透明 |
|
| 非破坏性裁剪(路线 1) | `crop.js` / `history.js` | 中:越界透明;旋转中心由几何派生(v1.7 已核查),文字非等比缩放属已知近似 |
|
||||||
| 输出管道(单张) | `index.js` / `glue.js` | 低:接口可保持兼容 |
|
| 输出管道(单张) | `index.js` / `glue.js` | 低:接口可保持兼容 |
|
||||||
| 图层蒙版 / 混合模式 | `layers.js` / `tools.js#getCompositeCanvas` | 中高:合成与导出必须用同一套逻辑 |
|
| 图层蒙版 / 混合模式 | `layers.js` / `tools.js#getCompositeCanvas` | 中高:合成与导出必须用同一套逻辑 |
|
||||||
| 工程草稿 / 跨仓 | 宿主 + 插件 | 高:需要宿主侧协商,建议最后做 |
|
| 工程草稿 / 跨仓 | 宿主 + 插件 | 高:需要宿主侧协商,建议最后做 |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.6.0",
|
"version": "1.7.0",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -753,17 +753,21 @@
|
|||||||
padding: 4px;
|
padding: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 图层项 */
|
/* 图层项:整项改成「行 + 可选的不透明度行」,两行都靠 .iwb-layer-row 保持原来的横向排布 */
|
||||||
.iwb-layer-item {
|
.iwb-layer-item {
|
||||||
display: flex;
|
display: block;
|
||||||
align-items: center;
|
padding: 5px 8px;
|
||||||
gap: 6px;
|
|
||||||
padding: 6px 8px;
|
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.12s;
|
transition: background 0.12s;
|
||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
}
|
}
|
||||||
|
.iwb-layer-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
.iwb-layer-item:hover { background: #313244; }
|
.iwb-layer-item:hover { background: #313244; }
|
||||||
.iwb-layer-item.active {
|
.iwb-layer-item.active {
|
||||||
background: #313244;
|
background: #313244;
|
||||||
@@ -775,9 +779,71 @@
|
|||||||
.iwb-layer-item.drop-target { outline: 1px dashed #e8a735; background: rgba(232, 167, 53, 0.16); }
|
.iwb-layer-item.drop-target { outline: 1px dashed #e8a735; background: rgba(232, 167, 53, 0.16); }
|
||||||
/* 画笔/橡皮作用目标:与「选中」分离,避免出现两个图层同时高亮 */
|
/* 画笔/橡皮作用目标:与「选中」分离,避免出现两个图层同时高亮 */
|
||||||
.iwb-layer-paint { flex: 0 0 auto; color: #a6adc8; font-size: 11px; opacity: 0.85; }
|
.iwb-layer-paint { flex: 0 0 auto; color: #a6adc8; font-size: 11px; opacity: 0.85; }
|
||||||
.iwb-layer-color { width: 22px; height: 22px; padding: 0; border: 1px solid #45475a; border-radius: 50%; background: transparent; cursor: pointer; flex: 0 0 auto; }
|
/* 不透明度角标:只有非 100% 才出现,一眼看出哪层被调淡了 */
|
||||||
.iwb-layer-width { width: 42px; height: 22px; padding: 2px 3px; border: 1px solid #45475a; border-radius: 4px; background: #1e1e2e; color: #e8a735; font-size: 11px; text-align: center; flex: 0 0 auto; }
|
.iwb-layer-op { flex: 0 0 auto; font-size: 10px; color: #a6adc8; font-variant-numeric: tabular-nums; }
|
||||||
.iwb-layer-width:focus { outline: none; border-color: #e8a735; }
|
|
||||||
|
/* 缩略图:canvas 画内容,类型图标垫在下面当兜底(空图层的缩略图是全透明的) */
|
||||||
|
.iwb-layer-thumb {
|
||||||
|
position: relative;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
border-radius: 3px;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: #1e1e2e;
|
||||||
|
background-image: linear-gradient(45deg, #33334a 25%, transparent 25%), linear-gradient(-45deg, #33334a 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #33334a 75%), linear-gradient(-45deg, transparent 75%, #33334a 75%);
|
||||||
|
background-size: 8px 8px;
|
||||||
|
background-position: 0 0, 0 4px, 4px -4px, -4px 0;
|
||||||
|
box-shadow: inset 0 0 0 1px #45475a;
|
||||||
|
}
|
||||||
|
.iwb-layer-thumb canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
|
||||||
|
.iwb-layer-thumb .iwb-layer-icon {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: #7f849c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 不透明度行:只出现在选中项下,拖动时不能被重绘打断 */
|
||||||
|
.iwb-layer-op-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
margin: 4px 0 1px 26px;
|
||||||
|
}
|
||||||
|
.iwb-layer-opacity {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-width: 0;
|
||||||
|
height: 14px;
|
||||||
|
accent-color: #e8a735;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-layer-op-val {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 32px;
|
||||||
|
text-align: right;
|
||||||
|
font-size: 10px;
|
||||||
|
color: #a6adc8;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 可重命名的图层名:悬停给个提示,进入编辑时换成输入框 */
|
||||||
|
.iwb-layer-name.renamable:hover { color: #e8a735; }
|
||||||
|
.iwb-layer-name-input {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 1px 4px;
|
||||||
|
border: 1px solid #e8a735;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: #1e1e2e;
|
||||||
|
color: #cdd6f4;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: inherit;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
.iwb-layer-vis {
|
.iwb-layer-vis {
|
||||||
background: none;
|
background: none;
|
||||||
@@ -865,7 +931,6 @@
|
|||||||
.iwb-editor-panel-width { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: #a6adc8; font-size: 11px; }
|
.iwb-editor-panel-width { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: #a6adc8; font-size: 11px; }
|
||||||
.iwb-editor-panel-width-range { flex: 1; min-width: 60px; }
|
.iwb-editor-panel-width-range { flex: 1; min-width: 60px; }
|
||||||
.iwb-editor-panel-width-num { width: 42px; padding: 3px; background: #313244; color: #e8a735; border: 1px solid #45475a; border-radius: 4px; text-align: center; }
|
.iwb-editor-panel-width-num { width: 42px; padding: 3px; background: #313244; color: #e8a735; border: 1px solid #45475a; border-radius: 4px; text-align: center; }
|
||||||
.iwb-layer-color, .iwb-layer-width { display: none !important; }
|
|
||||||
|
|
||||||
/* 顶部独立操作区,避免操作按钮被竖向工具栏裁切 */
|
/* 顶部独立操作区,避免操作按钮被竖向工具栏裁切 */
|
||||||
.iwb-editor-actions { display: flex; align-items: center; gap: 5px; margin-left: auto; flex: 0 0 auto; }
|
.iwb-editor-actions { display: flex; align-items: center; gap: 5px; margin-left: auto; flex: 0 0 auto; }
|
||||||
@@ -917,12 +982,10 @@
|
|||||||
.iwb-editor-export-actions { display: flex; align-items: center; gap: 6px; margin-left: 10px; flex: 0 0 auto; }
|
.iwb-editor-export-actions { display: flex; align-items: center; gap: 6px; margin-left: 10px; flex: 0 0 auto; }
|
||||||
.iwb-editor-export-actions .iwb-editor-btn { padding: 6px 10px; font-size: 11px; }
|
.iwb-editor-export-actions .iwb-editor-btn { padding: 6px 10px; font-size: 11px; }
|
||||||
.iwb-editor-footer { display: none !important; }
|
.iwb-editor-footer { display: none !important; }
|
||||||
.iwb-layer-color, .iwb-layer-width { display: none !important; }
|
|
||||||
|
|
||||||
.iwb-editor-export-actions { display: flex; align-items: center; gap: 6px; margin-left: 10px; flex: 0 0 auto; }
|
.iwb-editor-export-actions { display: flex; align-items: center; gap: 6px; margin-left: 10px; flex: 0 0 auto; }
|
||||||
.iwb-editor-export-actions .iwb-editor-btn { padding: 6px 10px; font-size: 11px; }
|
.iwb-editor-export-actions .iwb-editor-btn { padding: 6px 10px; font-size: 11px; }
|
||||||
.iwb-editor-footer { display: none !important; }
|
.iwb-editor-footer { display: none !important; }
|
||||||
.iwb-layer-color, .iwb-layer-width { display: none !important; }
|
|
||||||
|
|
||||||
/* 顶部七个操作按钮统一文本按钮样式,自适应中文宽度。 */
|
/* 顶部七个操作按钮统一文本按钮样式,自适应中文宽度。 */
|
||||||
.iwb-editor-actions { gap: 6px; }
|
.iwb-editor-actions { gap: 6px; }
|
||||||
|
|||||||
@@ -2097,7 +2097,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (/^(https?:\/\/\S+|data:image\/\S+)$/i.test(text)) { e.preventDefault(); e.stopImmediatePropagation(); pasteImageFromUrl(text); return }
|
if (/^(https?:\/\/\S+|data:image\/\S+)$/i.test(text)) { e.preventDefault(); e.stopImmediatePropagation(); pasteImageFromUrl(text); return }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 把 URL / data URL 的图片取回并贴为新图层;失败时给出可见提示(console + alert,编辑器没有 toast) */
|
/** 把 URL / data URL 的图片取回并贴为新图层;失败时走 toast(阻塞式 alert 在宿主里会卡住整页) */
|
||||||
async function pasteImageFromUrl(url) {
|
async function pasteImageFromUrl(url) {
|
||||||
try {
|
try {
|
||||||
let dataUrl = url
|
let dataUrl = url
|
||||||
@@ -2116,6 +2116,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
addBitmapLayer(await loadImage(dataUrl))
|
addBitmapLayer(await loadImage(dataUrl))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[IWB编辑器] 粘贴图片链接失败:', err)
|
console.error('[IWB编辑器] 粘贴图片链接失败:', err)
|
||||||
try { window.alert('粘贴失败:' + ((err && err.message) || '无法读取剪贴板里的图片链接')) } catch (e) { /* 忽略 */ }
|
toast('粘贴失败:' + ((err && err.message) || '无法读取剪贴板里的图片链接'), 'error')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,6 +113,12 @@ import { toast } from './commands.js'
|
|||||||
// 编辑器 DOM 复用,重开时旧的位图选中 id 指向已删除的图层,必须清掉
|
// 编辑器 DOM 复用,重开时旧的位图选中 id 指向已删除的图层,必须清掉
|
||||||
S.selectedLayerId = null
|
S.selectedLayerId = null
|
||||||
S.bitmapDrag = null
|
S.bitmapDrag = null
|
||||||
|
// 跨会话残留:多选合并集合、悬停点、双击判定都会指向上一张图的图层
|
||||||
|
S.layerMulti.length = 0
|
||||||
|
S.hoverPos = null
|
||||||
|
S.lastClick = null
|
||||||
|
S.lastNameClick = null
|
||||||
|
S.altPicker = false
|
||||||
S.zCounter = Math.max(S.layers.length - 1, 0)
|
S.zCounter = Math.max(S.layers.length - 1, 0)
|
||||||
S.placingImage = null
|
S.placingImage = null
|
||||||
S.placingHandle = null
|
S.placingHandle = null
|
||||||
@@ -289,7 +295,12 @@ import { toast } from './commands.js'
|
|||||||
doc: { w: S.imgW, h: S.imgH },
|
doc: { w: S.imgW, h: S.imgH },
|
||||||
zoom: S.zoom,
|
zoom: S.zoom,
|
||||||
fit: { w: Math.round(S.fitW || 0), h: Math.round(S.fitH || 0) },
|
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 })),
|
layers: S.layers.map(l => ({
|
||||||
|
id: l.id, name: l.name, z: l.z, locked: !!l.locked, visible: l.visible !== false,
|
||||||
|
// 不透明度有两个面:数据字段(导出/合并用)与 CSS(屏幕上看到的),两者必须一致
|
||||||
|
opacity: l.opacity == null ? 1 : l.opacity,
|
||||||
|
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
||||||
|
})),
|
||||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color })),
|
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color })),
|
||||||
texts: S.textLayers.map(t => ({ id: t.id, text: t.text })),
|
texts: S.textLayers.map(t => ({ id: t.id, text: t.text })),
|
||||||
selectedShapeId: S.selectedShapeId,
|
selectedShapeId: S.selectedShapeId,
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { boxCorners, clamp, drawRotationHandles, hitRotationHandle, rotPt, unrot
|
|||||||
import { drawShape } from './tools.js'
|
import { drawShape } from './tools.js'
|
||||||
import { saveSnapshot, snapshotState } from './history.js'
|
import { saveSnapshot, snapshotState } from './history.js'
|
||||||
import { placeImageDirectly } from './placement.js'
|
import { placeImageDirectly } from './placement.js'
|
||||||
import { updateBrushParamUI, updateColorUI, refreshBrushRing } from './events.js'
|
|
||||||
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||||
|
|
||||||
|
|
||||||
@@ -310,8 +309,12 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
|
|
||||||
/** 切换画笔/橡皮作用的活动图层 */
|
/** 切换画笔/橡皮作用的活动图层 */
|
||||||
export function setActiveLayer(id) {
|
export function setActiveLayer(id) {
|
||||||
|
// 已经既活跃又选中时不必重建面板:renderLayerPanel 会换掉整块 innerHTML,
|
||||||
|
// 每次点击都重建会让「点第二下改名」这类连续交互彻底失效(v1.7)
|
||||||
|
const changed = S.activeLayerId !== id || S.selectedLayerId !== id
|
||||||
S.activeLayerId = id
|
S.activeLayerId = id
|
||||||
selectUnit('bitmap', id)
|
selectUnit('bitmap', id)
|
||||||
|
if (!changed) return
|
||||||
renderLayerPanel()
|
renderLayerPanel()
|
||||||
renderObjects()
|
renderObjects()
|
||||||
}
|
}
|
||||||
@@ -485,6 +488,8 @@ export function setActiveLayer(id) {
|
|||||||
layer.canvas.style.height = h + 'px'
|
layer.canvas.style.height = h + 'px'
|
||||||
layer.canvas.style.left = offset + 'px'
|
layer.canvas.style.left = offset + 'px'
|
||||||
layer.canvas.style.top = offset + 'px'
|
layer.canvas.style.top = offset + 'px'
|
||||||
|
// 位图图层的不透明度走 CSS(像素不动):画面上看到的效果才和导出/合并一致
|
||||||
|
layer.canvas.style.opacity = String(layer.opacity == null ? 1 : layer.opacity)
|
||||||
}
|
}
|
||||||
styleVectorViewport(w, h, offset)
|
styleVectorViewport(w, h, offset)
|
||||||
}
|
}
|
||||||
@@ -501,6 +506,39 @@ export function setActiveLayer(id) {
|
|||||||
|
|
||||||
// ============ 图层面板 UI ============
|
// ============ 图层面板 UI ============
|
||||||
|
|
||||||
|
/** HTML 转义:图层名可能来自用户输入的文字内容(含 < > & "),拼进模板会破坏结构 */
|
||||||
|
function esc(v) {
|
||||||
|
return String(v == null ? '' : v)
|
||||||
|
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 0~1 的不透明度 → 面板展示用的整数百分比 */
|
||||||
|
function opacityPct(v) {
|
||||||
|
const n = v == null ? 1 : v
|
||||||
|
return Math.max(0, Math.min(100, Math.round(n * 100)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按 id/type 找到图层单元对应的对象(位图 / 文字 / 形状共用一套面板控件) */
|
||||||
|
function findPanelTarget(type, id) {
|
||||||
|
if (type === 'bitmap') return S.layers.find(l => l.id === id) || null
|
||||||
|
if (type === 'text') return S.textLayers.find(t => t.id === id) || null
|
||||||
|
if (type === 'shape') return S.shapeLayers.find(s => s.id === id) || null
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 图层不透明度落到画面上:
|
||||||
|
* 位图走 canvas 的 CSS opacity(像素不动,导出时由合成环节乘 globalAlpha);
|
||||||
|
* 文字/形状的不透明度在 drawShape / drawVectorToCanvas 里已经烘进像素,
|
||||||
|
* 改完只需重绘矢量层,不能再叠一层 CSS,否则就是双倍透明。 */
|
||||||
|
function applyOpacityVisual(type, obj) {
|
||||||
|
if (type === 'bitmap' && obj && obj.canvas) {
|
||||||
|
obj.canvas.style.opacity = String(obj.opacity == null ? 1 : obj.opacity)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (type === 'text' || type === 'shape') renderObjects()
|
||||||
|
}
|
||||||
|
|
||||||
export function renderLayerPanel() {
|
export function renderLayerPanel() {
|
||||||
const list = runtime.el.querySelector('.iwb-editor-layer-list')
|
const list = runtime.el.querySelector('.iwb-editor-layer-list')
|
||||||
if (!list) return
|
if (!list) return
|
||||||
@@ -565,17 +603,28 @@ export function setActiveLayer(id) {
|
|||||||
? '<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="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg>'
|
? '<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="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg>'
|
||||||
: '<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="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 7-2"/></svg>'
|
: '<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="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 7-2"/></svg>'
|
||||||
const delSvg = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>'
|
const delSvg = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>'
|
||||||
|
// 不透明度百分比:0~100 整数。选中项下面的滑杆已经显示数值,角标只给未选中的层做提醒,
|
||||||
|
// 免得窄面板里「名字 + ✎ + 角标 + 锁 + 删除」把图层名挤成几个字
|
||||||
|
const pct = opacityPct(item.opacity)
|
||||||
|
const canRename = item.type === 'bitmap'
|
||||||
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" draggable="${item.id !== 'base'}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" draggable="${item.id !== 'base'}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
||||||
|
<div class="iwb-layer-row">
|
||||||
<button class="iwb-layer-vis" data-vis-id="${item.id}" data-vis-type="${item.type}" title="${item.visible ? '隐藏' : '显示'}">${visSvg}</button>
|
<button class="iwb-layer-vis" data-vis-id="${item.id}" data-vis-type="${item.type}" title="${item.visible ? '隐藏' : '显示'}">${visSvg}</button>
|
||||||
<span class="iwb-layer-icon">${typeIconSvg}</span>
|
<span class="iwb-layer-thumb"><canvas width="44" height="44" data-thumb-id="${item.id}" data-thumb-type="${item.type}"></canvas><span class="iwb-layer-icon">${typeIconSvg}</span></span>
|
||||||
<span class="iwb-layer-name">${item.name}</span>${item.paintTarget ? '<span class="iwb-layer-paint" title="当前画笔 / 橡皮作用图层">✎</span>' : ''}
|
<span class="iwb-layer-name${canRename ? ' renamable' : ''}" data-name-id="${item.id}" data-name-type="${item.type}" title="${esc(item.name)}${canRename ? ' · 双击重命名' : ''}">${esc(item.name)}</span>
|
||||||
${(item.type === 'bitmap' || item.type === 'shape') ? `<input class="iwb-layer-color" type="color" value="${item.color}" data-color-id="${item.id}" data-color-type="${item.type}" title="调整颜色">` : ''}
|
${item.paintTarget ? '<span class="iwb-layer-paint" title="当前画笔 / 橡皮作用图层">✎</span>' : ''}
|
||||||
${(item.type === 'bitmap' || item.type === 'shape') ? `<input class="iwb-layer-width" type="number" min="1" max="300" value="${Math.round(item.lineWidth)}" data-width-id="${item.id}" data-width-type="${item.type}" title="调整边框粗细">` : ''}
|
${(pct < 100 && !item.active) ? `<span class="iwb-layer-op" title="不透明度 ${pct}%(选中该层可调)">${pct}%</span>` : ''}
|
||||||
<button class="iwb-layer-lock${item.locked ? ' active' : ''}" data-lock-id="${item.id}" data-lock-type="${item.type}" title="${item.locked ? '解锁图层' : '锁定图层'}">${lockSvg}</button>
|
<button class="iwb-layer-lock${item.locked ? ' active' : ''}" data-lock-id="${item.id}" data-lock-type="${item.type}" title="${item.locked ? '解锁图层' : '锁定图层'}">${lockSvg}</button>
|
||||||
${item.canDelete ? `<button class="iwb-layer-del" data-del-id="${item.id}" data-del-type="${item.type}" title="删除图层">${delSvg}</button>` : ''}
|
${item.canDelete ? `<button class="iwb-layer-del" data-del-id="${item.id}" data-del-type="${item.type}" title="删除图层">${delSvg}</button>` : ''}
|
||||||
|
</div>
|
||||||
|
${item.active ? `<div class="iwb-layer-op-row">
|
||||||
|
<input class="iwb-layer-opacity" type="range" min="0" max="100" step="1" value="${pct}" data-op-id="${item.id}" data-op-type="${item.type}" title="不透明度:拖动调整,双击复位 100%">
|
||||||
|
<span class="iwb-layer-op-val">${pct}%</span>
|
||||||
|
</div>` : ''}
|
||||||
</div>`
|
</div>`
|
||||||
}
|
}
|
||||||
list.innerHTML = html
|
list.innerHTML = html
|
||||||
|
scheduleThumbs()
|
||||||
|
|
||||||
// 侧栏「快速效果」的目标层名:效果和画笔共用同一个目标层,这里一起刷,
|
// 侧栏「快速效果」的目标层名:效果和画笔共用同一个目标层,这里一起刷,
|
||||||
// 免得切层后标签还停在上一个图层名上。
|
// 免得切层后标签还停在上一个图层名上。
|
||||||
@@ -618,7 +667,8 @@ export function setActiveLayer(id) {
|
|||||||
if (!list) return
|
if (!list) return
|
||||||
|
|
||||||
bindLayerItemEvents(list)
|
bindLayerItemEvents(list)
|
||||||
bindLayerStyleInputs(list)
|
bindLayerNameRename(list)
|
||||||
|
bindLayerOpacityInputs(list)
|
||||||
bindLayerVisButtons(list)
|
bindLayerVisButtons(list)
|
||||||
bindLayerLockButtons(list)
|
bindLayerLockButtons(list)
|
||||||
bindLayerDelButtons(list)
|
bindLayerDelButtons(list)
|
||||||
@@ -635,6 +685,8 @@ export function setActiveLayer(id) {
|
|||||||
item.addEventListener('drop', (e) => { e.preventDefault(); reorderPanelItem(e.dataTransfer.getData('text/plain'), item.dataset.layerId) })
|
item.addEventListener('drop', (e) => { e.preventDefault(); reorderPanelItem(e.dataTransfer.getData('text/plain'), item.dataset.layerId) })
|
||||||
item.addEventListener('click', (e) => {
|
item.addEventListener('click', (e) => {
|
||||||
if (e.target.closest('.iwb-layer-vis') || e.target.closest('.iwb-layer-lock') || e.target.closest('.iwb-layer-del')) return
|
if (e.target.closest('.iwb-layer-vis') || e.target.closest('.iwb-layer-lock') || e.target.closest('.iwb-layer-del')) return
|
||||||
|
// 拖动不透明度滑杆 / 正在改名:都不能触发整块重绘,否则控件节点会被换掉
|
||||||
|
if (e.target.closest('.iwb-layer-opacity') || e.target.closest('.iwb-layer-name-input') || e.target.closest('.iwb-layer-op-row')) return
|
||||||
const id = item.dataset.layerId
|
const id = item.dataset.layerId
|
||||||
const type = item.dataset.layerType
|
const type = item.dataset.layerType
|
||||||
// ⌘/Ctrl 点击:加入/移出合并集合(不改变画笔目标与单选高亮)
|
// ⌘/Ctrl 点击:加入/移出合并集合(不改变画笔目标与单选高亮)
|
||||||
@@ -657,29 +709,139 @@ export function setActiveLayer(id) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 图层颜色与边框粗细输入:修改后立即刷新画布和面板 */
|
/**
|
||||||
function bindLayerStyleInputs(list) {
|
* 双击图层名重命名(v1.7)。
|
||||||
// 图层颜色与边框粗细:修改后立即刷新画布和面板。
|
*
|
||||||
list.querySelectorAll('.iwb-layer-color').forEach(input => {
|
* 为什么自己算双击而不是用 dblclick:点一下图层名就会 setActiveLayer → renderLayerPanel
|
||||||
|
* 重建整块 innerHTML,第 2 次点击落在新节点上,浏览器不会再派发 dblclick。
|
||||||
|
* 这里用「两次 mousedown 间隔 <400ms 且同一个图层」自行判定,重绘不影响识别。
|
||||||
|
*/
|
||||||
|
function bindLayerNameRename(list) {
|
||||||
|
list.querySelectorAll('.iwb-layer-name.renamable').forEach(el => {
|
||||||
|
el.addEventListener('mousedown', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
const id = el.dataset.nameId
|
||||||
|
const now = Date.now()
|
||||||
|
const prev = S.lastNameClick
|
||||||
|
if (prev && prev.id === id && now - prev.t < 400) {
|
||||||
|
S.lastNameClick = null
|
||||||
|
beginRename(id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
S.lastNameClick = { id, t: now }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 把图层名的 span 换成输入框;Enter / 失焦提交,Esc 取消 */
|
||||||
|
function beginRename(id) {
|
||||||
|
const list = runtime.el.querySelector('.iwb-editor-layer-list')
|
||||||
|
const layer = S.layers.find(l => l.id === id)
|
||||||
|
if (!list || !layer) return
|
||||||
|
const item = list.querySelector('.iwb-layer-item[data-layer-id="' + id + '"]')
|
||||||
|
const span = item && item.querySelector('.iwb-layer-name')
|
||||||
|
if (!span || !span.parentNode) return
|
||||||
|
|
||||||
|
const input = document.createElement('input')
|
||||||
|
input.className = 'iwb-layer-name-input'
|
||||||
|
input.type = 'text'
|
||||||
|
input.value = layer.name
|
||||||
|
input.maxLength = 40
|
||||||
|
span.replaceWith(input)
|
||||||
|
// 重命名期间禁用整项拖动,否则在输入框里拖选文字会变成拖动图层排序
|
||||||
|
item.draggable = false
|
||||||
|
|
||||||
|
let done = false
|
||||||
|
const finish = (commit) => {
|
||||||
|
if (done) return
|
||||||
|
done = true
|
||||||
|
const next = input.value.trim()
|
||||||
|
if (commit && next && next !== layer.name) {
|
||||||
|
saveSnapshot('重命名图层')
|
||||||
|
layer.name = next
|
||||||
|
}
|
||||||
|
renderLayerPanel()
|
||||||
|
}
|
||||||
input.addEventListener('mousedown', (e) => e.stopPropagation())
|
input.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
|
input.addEventListener('click', (e) => e.stopPropagation())
|
||||||
|
input.addEventListener('keydown', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
if (e.key === 'Enter') { e.preventDefault(); finish(true) }
|
||||||
|
else if (e.key === 'Escape') { e.preventDefault(); finish(false) }
|
||||||
|
})
|
||||||
|
input.addEventListener('blur', () => finish(true))
|
||||||
|
input.focus()
|
||||||
|
input.select()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不透明度滑杆(v1.7)。拖动期间绝不能调用 renderLayerPanel():
|
||||||
|
* 它会把整块 innerHTML 换掉,滑杆节点被销毁 → 拖动直接中断(这也是老代码里
|
||||||
|
* 「改完颜色取色器就断开、数字框打不进两位」的根因,那些控件现在已删)。
|
||||||
|
* 所以这里只改对象 + 就地刷标值,一次拖动只拍一张快照。
|
||||||
|
*/
|
||||||
|
function bindLayerOpacityInputs(list) {
|
||||||
|
list.querySelectorAll('.iwb-layer-opacity').forEach(input => {
|
||||||
|
input.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
|
input.addEventListener('click', (e) => e.stopPropagation())
|
||||||
|
// 双击滑块复位 100%(PS 里双击「不透明度」标题即可复位,这里沿用同一习惯)
|
||||||
|
input.addEventListener('dblclick', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
input.value = '100'
|
||||||
|
applyOpacityFromInput(input)
|
||||||
|
})
|
||||||
input.addEventListener('input', (e) => {
|
input.addEventListener('input', (e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
const id = input.dataset.colorId
|
applyOpacityFromInput(input)
|
||||||
const type = input.dataset.colorType
|
|
||||||
const obj = type === 'bitmap' ? S.layers.find(l => l.id === id) : S.shapeLayers.find(s => s.id === id)
|
|
||||||
if (obj) { obj.color = input.value; S.color = input.value; updateColorUI(); renderObjects(); renderLayerPanel(); S.pickerComposite = null }
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
list.querySelectorAll('.iwb-layer-width').forEach(input => {
|
}
|
||||||
input.addEventListener('mousedown', (e) => e.stopPropagation())
|
|
||||||
input.addEventListener('input', (e) => {
|
function applyOpacityFromInput(input) {
|
||||||
e.stopPropagation()
|
const type = input.dataset.opType
|
||||||
const id = input.dataset.widthId
|
const obj = findPanelTarget(type, input.dataset.opId)
|
||||||
const type = input.dataset.widthType
|
if (!obj) return
|
||||||
const value = clamp(parseInt(input.value, 10) || 1, 1, 300)
|
const pct = clamp(parseInt(input.value, 10) || 0, 0, 100)
|
||||||
const obj = type === 'bitmap' ? S.layers.find(l => l.id === id) : S.shapeLayers.find(s => s.id === id)
|
if (!input._opSnapTaken) {
|
||||||
if (obj) { obj.lineWidth = value; if (type === 'shape') obj.lw = value; else { S.brushSize = value; refreshBrushRing() } renderObjects(); updateBrushParamUI(); renderLayerPanel() }
|
// 第一格拖动才拍快照:一次拖动 = 一次撤销,不会产生几十张全幅像素快照
|
||||||
})
|
input._opSnapTaken = true
|
||||||
|
saveSnapshot('调整不透明度')
|
||||||
|
}
|
||||||
|
obj.opacity = pct / 100
|
||||||
|
applyOpacityVisual(type, obj)
|
||||||
|
S.pickerComposite = null
|
||||||
|
const val = input.parentNode && input.parentNode.querySelector('.iwb-layer-op-val')
|
||||||
|
if (val) val.textContent = pct + '%'
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 缩略图:合并 90ms 内的多次请求,避免连续选中/拖动时反复整块重画 */
|
||||||
|
let _thumbTimer = 0
|
||||||
|
function scheduleThumbs() {
|
||||||
|
if (_thumbTimer) return
|
||||||
|
_thumbTimer = setTimeout(() => { _thumbTimer = 0; paintThumbs() }, 90)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 把每个图层画布缩到 22px 缩略图(设备像素 44,避免高分屏发虚) */
|
||||||
|
function paintThumbs() {
|
||||||
|
if (!runtime.el) return
|
||||||
|
const list = runtime.el.querySelector('.iwb-editor-layer-list')
|
||||||
|
if (!list) return
|
||||||
|
list.querySelectorAll('.iwb-layer-thumb canvas').forEach(cv => {
|
||||||
|
const type = cv.dataset.thumbType
|
||||||
|
const obj = findPanelTarget(type, cv.dataset.thumbId)
|
||||||
|
const src = obj ? (type === 'bitmap' ? obj.canvas : obj._canvas) : null
|
||||||
|
const g = cv.getContext('2d')
|
||||||
|
if (!g) return
|
||||||
|
g.clearRect(0, 0, cv.width, cv.height)
|
||||||
|
if (!src || !src.width || !src.height) return
|
||||||
|
// 等比缩放到缩略框内并居中:背景是透明格子时不会变形
|
||||||
|
const k = Math.min(cv.width / src.width, cv.height / src.height)
|
||||||
|
const dw = Math.max(1, Math.round(src.width * k))
|
||||||
|
const dh = Math.max(1, Math.round(src.height * k))
|
||||||
|
try {
|
||||||
|
g.imageSmoothingQuality = 'high'
|
||||||
|
g.drawImage(src, Math.round((cv.width - dw) / 2), Math.round((cv.height - dh) / 2), dw, dh)
|
||||||
|
} catch (e) { /* 画布已释放等异常不阻断其余缩略图 */ }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,7 +938,9 @@ export function setActiveLayer(id) {
|
|||||||
export function clearLayerMulti() { S.layerMulti.length = 0 }
|
export function clearLayerMulti() { S.layerMulti.length = 0 }
|
||||||
|
|
||||||
/** 把一组单元按 z 从低到高叠进目标位图层的像素。
|
/** 把一组单元按 z 从低到高叠进目标位图层的像素。
|
||||||
* alpha 规则与 getCompositeCanvas(导出/吸管)保持一致,保证「合并后看到的就是导出结果」。 */
|
* alpha 规则与 getCompositeCanvas(导出/吸管)保持一致,保证「合并后看到的就是导出结果」。
|
||||||
|
* 只有位图层的 opacity 需要在合成时乘 globalAlpha —— 文字/形状的不透明度在
|
||||||
|
* drawVectorToCanvas / drawShape 里已经烘进像素,这里再乘一次就是双倍透明。 */
|
||||||
function composeUnitsInto(layer, units) {
|
function composeUnitsInto(layer, units) {
|
||||||
const tmp = document.createElement('canvas')
|
const tmp = document.createElement('canvas')
|
||||||
tmp.width = S.imgW
|
tmp.width = S.imgW
|
||||||
@@ -785,7 +949,7 @@ export function setActiveLayer(id) {
|
|||||||
for (const u of units) {
|
for (const u of units) {
|
||||||
const el = u.kind === 'bitmap' ? u.obj.canvas : u.obj._canvas
|
const el = u.kind === 'bitmap' ? u.obj.canvas : u.obj._canvas
|
||||||
if (!el || el.nodeType !== 1) continue
|
if (!el || el.nodeType !== 1) continue
|
||||||
tctx.globalAlpha = u.obj.opacity == null ? 1 : u.obj.opacity
|
tctx.globalAlpha = u.kind === 'bitmap' ? (u.obj.opacity == null ? 1 : u.obj.opacity) : 1
|
||||||
tctx.drawImage(el, 0, 0)
|
tctx.drawImage(el, 0, 0)
|
||||||
}
|
}
|
||||||
tctx.globalAlpha = 1
|
tctx.globalAlpha = 1
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
// 否则光标环会停在旧尺寸,直到用户再动一下鼠标才更新(v1.6)
|
// 否则光标环会停在旧尺寸,直到用户再动一下鼠标才更新(v1.6)
|
||||||
hoverPos: null,
|
hoverPos: null,
|
||||||
lastClick: null, // 上一次画布按下 {t,x,y}:自算双击用(dblclick 在画布上不可靠)
|
lastClick: null, // 上一次画布按下 {t,x,y}:自算双击用(dblclick 在画布上不可靠)
|
||||||
|
// 上一次点击图层名 {id,t}:图层面板重命名也走自算双击(点一下就会重绘面板,
|
||||||
|
// 浏览器不会在同一个节点上派发 dblclick)
|
||||||
|
lastNameClick: null,
|
||||||
altPicker: false, // 按住 Alt 的临时吸管(画笔/橡皮下),松开 Alt 回到原工具
|
altPicker: false, // 按住 Alt 的临时吸管(画笔/橡皮下),松开 Alt 回到原工具
|
||||||
pickerComposite: null, // 吸管取样用的合成画布缓存(切工具/画布变化时失效)
|
pickerComposite: null, // 吸管取样用的合成画布缓存(切工具/画布变化时失效)
|
||||||
rectFill: false, // 矩形/圆形是否实心填充
|
rectFill: false, // 矩形/圆形是否实心填充
|
||||||
|
|||||||
@@ -266,7 +266,8 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (u.obj.visible === false) continue
|
if (u.obj.visible === false) continue
|
||||||
const el = u.kind === 'bitmap' ? u.obj.canvas : u.obj._canvas
|
const el = u.kind === 'bitmap' ? u.obj.canvas : u.obj._canvas
|
||||||
if (!el) continue
|
if (!el) continue
|
||||||
cx.globalAlpha = u.obj.opacity == null ? 1 : u.obj.opacity
|
// 位图的 opacity 由 CSS 显示、这里乘 alpha;矢量对象的不透明度已经画进像素
|
||||||
|
cx.globalAlpha = u.kind === 'bitmap' ? (u.obj.opacity == null ? 1 : u.obj.opacity) : 1
|
||||||
cx.drawImage(el, 0, 0)
|
cx.drawImage(el, 0, 0)
|
||||||
}
|
}
|
||||||
cx.globalAlpha = 1
|
cx.globalAlpha = 1
|
||||||
|
|||||||
+170
-45
@@ -9,7 +9,7 @@
|
|||||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||||
id: 'image-annotate',
|
id: 'image-annotate',
|
||||||
name: '标注 / 修图',
|
name: '标注 / 修图',
|
||||||
version: '1.6.0',
|
version: '1.7.0',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
@@ -44,6 +44,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
hoverPos: null,
|
hoverPos: null,
|
||||||
lastClick: null,
|
lastClick: null,
|
||||||
// 上一次画布按下 {t,x,y}:自算双击用(dblclick 在画布上不可靠)
|
// 上一次画布按下 {t,x,y}:自算双击用(dblclick 在画布上不可靠)
|
||||||
|
// 上一次点击图层名 {id,t}:图层面板重命名也走自算双击(点一下就会重绘面板,
|
||||||
|
// 浏览器不会在同一个节点上派发 dblclick)
|
||||||
|
lastNameClick: null,
|
||||||
altPicker: false,
|
altPicker: false,
|
||||||
// 按住 Alt 的临时吸管(画笔/橡皮下),松开 Alt 回到原工具
|
// 按住 Alt 的临时吸管(画笔/橡皮下),松开 Alt 回到原工具
|
||||||
pickerComposite: null,
|
pickerComposite: null,
|
||||||
@@ -673,7 +676,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (u.obj.visible === false) continue;
|
if (u.obj.visible === false) continue;
|
||||||
const el = u.kind === "bitmap" ? u.obj.canvas : u.obj._canvas;
|
const el = u.kind === "bitmap" ? u.obj.canvas : u.obj._canvas;
|
||||||
if (!el) continue;
|
if (!el) continue;
|
||||||
cx.globalAlpha = u.obj.opacity == null ? 1 : u.obj.opacity;
|
cx.globalAlpha = u.kind === "bitmap" ? u.obj.opacity == null ? 1 : u.obj.opacity : 1;
|
||||||
cx.drawImage(el, 0, 0);
|
cx.drawImage(el, 0, 0);
|
||||||
}
|
}
|
||||||
cx.globalAlpha = 1;
|
cx.globalAlpha = 1;
|
||||||
@@ -1837,8 +1840,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
redrawBitmapLayer(layer);
|
redrawBitmapLayer(layer);
|
||||||
}
|
}
|
||||||
function setActiveLayer(id) {
|
function setActiveLayer(id) {
|
||||||
|
const changed = S.activeLayerId !== id || S.selectedLayerId !== id;
|
||||||
S.activeLayerId = id;
|
S.activeLayerId = id;
|
||||||
selectUnit("bitmap", id);
|
selectUnit("bitmap", id);
|
||||||
|
if (!changed) return;
|
||||||
renderLayerPanel();
|
renderLayerPanel();
|
||||||
renderObjects();
|
renderObjects();
|
||||||
}
|
}
|
||||||
@@ -1995,6 +2000,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
layer.canvas.style.height = h + "px";
|
layer.canvas.style.height = h + "px";
|
||||||
layer.canvas.style.left = offset + "px";
|
layer.canvas.style.left = offset + "px";
|
||||||
layer.canvas.style.top = offset + "px";
|
layer.canvas.style.top = offset + "px";
|
||||||
|
layer.canvas.style.opacity = String(layer.opacity == null ? 1 : layer.opacity);
|
||||||
}
|
}
|
||||||
styleVectorViewport(w, h, offset);
|
styleVectorViewport(w, h, offset);
|
||||||
}
|
}
|
||||||
@@ -2007,6 +2013,26 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
obj._canvas.style.top = offset + "px";
|
obj._canvas.style.top = offset + "px";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function esc(v) {
|
||||||
|
return String(v == null ? "" : v).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||||
|
}
|
||||||
|
function opacityPct(v) {
|
||||||
|
const n = v == null ? 1 : v;
|
||||||
|
return Math.max(0, Math.min(100, Math.round(n * 100)));
|
||||||
|
}
|
||||||
|
function findPanelTarget(type, id) {
|
||||||
|
if (type === "bitmap") return S.layers.find((l) => l.id === id) || null;
|
||||||
|
if (type === "text") return S.textLayers.find((t) => t.id === id) || null;
|
||||||
|
if (type === "shape") return S.shapeLayers.find((s) => s.id === id) || null;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function applyOpacityVisual(type, obj) {
|
||||||
|
if (type === "bitmap" && obj && obj.canvas) {
|
||||||
|
obj.canvas.style.opacity = String(obj.opacity == null ? 1 : obj.opacity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type === "text" || type === "shape") renderObjects();
|
||||||
|
}
|
||||||
function renderLayerPanel() {
|
function renderLayerPanel() {
|
||||||
const list = runtime.el.querySelector(".iwb-editor-layer-list");
|
const list = runtime.el.querySelector(".iwb-editor-layer-list");
|
||||||
if (!list) return;
|
if (!list) return;
|
||||||
@@ -2070,17 +2096,26 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const visSvg = item.visible ? '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>' : '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" y1="2" x2="22" y2="22"/></svg>';
|
const visSvg = item.visible ? '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>' : '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" y1="2" x2="22" y2="22"/></svg>';
|
||||||
const lockSvg = item.locked ? '<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="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg>' : '<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="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 7-2"/></svg>';
|
const lockSvg = item.locked ? '<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="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg>' : '<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="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 7-2"/></svg>';
|
||||||
const delSvg = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
|
const delSvg = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
|
||||||
|
const pct = opacityPct(item.opacity);
|
||||||
|
const canRename = item.type === "bitmap";
|
||||||
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" draggable="${item.id !== "base"}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" draggable="${item.id !== "base"}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
||||||
|
<div class="iwb-layer-row">
|
||||||
<button class="iwb-layer-vis" data-vis-id="${item.id}" data-vis-type="${item.type}" title="${item.visible ? "隐藏" : "显示"}">${visSvg}</button>
|
<button class="iwb-layer-vis" data-vis-id="${item.id}" data-vis-type="${item.type}" title="${item.visible ? "隐藏" : "显示"}">${visSvg}</button>
|
||||||
<span class="iwb-layer-icon">${typeIconSvg}</span>
|
<span class="iwb-layer-thumb"><canvas width="44" height="44" data-thumb-id="${item.id}" data-thumb-type="${item.type}"></canvas><span class="iwb-layer-icon">${typeIconSvg}</span></span>
|
||||||
<span class="iwb-layer-name">${item.name}</span>${item.paintTarget ? '<span class="iwb-layer-paint" title="当前画笔 / 橡皮作用图层">✎</span>' : ""}
|
<span class="iwb-layer-name${canRename ? " renamable" : ""}" data-name-id="${item.id}" data-name-type="${item.type}" title="${esc(item.name)}${canRename ? " · 双击重命名" : ""}">${esc(item.name)}</span>
|
||||||
${item.type === "bitmap" || item.type === "shape" ? `<input class="iwb-layer-color" type="color" value="${item.color}" data-color-id="${item.id}" data-color-type="${item.type}" title="调整颜色">` : ""}
|
${item.paintTarget ? '<span class="iwb-layer-paint" title="当前画笔 / 橡皮作用图层">✎</span>' : ""}
|
||||||
${item.type === "bitmap" || item.type === "shape" ? `<input class="iwb-layer-width" type="number" min="1" max="300" value="${Math.round(item.lineWidth)}" data-width-id="${item.id}" data-width-type="${item.type}" title="调整边框粗细">` : ""}
|
${pct < 100 && !item.active ? `<span class="iwb-layer-op" title="不透明度 ${pct}%(选中该层可调)">${pct}%</span>` : ""}
|
||||||
<button class="iwb-layer-lock${item.locked ? " active" : ""}" data-lock-id="${item.id}" data-lock-type="${item.type}" title="${item.locked ? "解锁图层" : "锁定图层"}">${lockSvg}</button>
|
<button class="iwb-layer-lock${item.locked ? " active" : ""}" data-lock-id="${item.id}" data-lock-type="${item.type}" title="${item.locked ? "解锁图层" : "锁定图层"}">${lockSvg}</button>
|
||||||
${item.canDelete ? `<button class="iwb-layer-del" data-del-id="${item.id}" data-del-type="${item.type}" title="删除图层">${delSvg}</button>` : ""}
|
${item.canDelete ? `<button class="iwb-layer-del" data-del-id="${item.id}" data-del-type="${item.type}" title="删除图层">${delSvg}</button>` : ""}
|
||||||
|
</div>
|
||||||
|
${item.active ? `<div class="iwb-layer-op-row">
|
||||||
|
<input class="iwb-layer-opacity" type="range" min="0" max="100" step="1" value="${pct}" data-op-id="${item.id}" data-op-type="${item.type}" title="不透明度:拖动调整,双击复位 100%">
|
||||||
|
<span class="iwb-layer-op-val">${pct}%</span>
|
||||||
|
</div>` : ""}
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
list.innerHTML = html;
|
list.innerHTML = html;
|
||||||
|
scheduleThumbs();
|
||||||
const fxTarget = runtime.el.querySelector(".iwb-editor-fx-target");
|
const fxTarget = runtime.el.querySelector(".iwb-editor-fx-target");
|
||||||
if (fxTarget) {
|
if (fxTarget) {
|
||||||
const active = getActiveLayer();
|
const active = getActiveLayer();
|
||||||
@@ -2116,7 +2151,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const list = runtime.el.querySelector(".iwb-editor-layer-list");
|
const list = runtime.el.querySelector(".iwb-editor-layer-list");
|
||||||
if (!list) return;
|
if (!list) return;
|
||||||
bindLayerItemEvents(list);
|
bindLayerItemEvents(list);
|
||||||
bindLayerStyleInputs(list);
|
bindLayerNameRename(list);
|
||||||
|
bindLayerOpacityInputs(list);
|
||||||
bindLayerVisButtons(list);
|
bindLayerVisButtons(list);
|
||||||
bindLayerLockButtons(list);
|
bindLayerLockButtons(list);
|
||||||
bindLayerDelButtons(list);
|
bindLayerDelButtons(list);
|
||||||
@@ -2140,6 +2176,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
});
|
});
|
||||||
item.addEventListener("click", (e) => {
|
item.addEventListener("click", (e) => {
|
||||||
if (e.target.closest(".iwb-layer-vis") || e.target.closest(".iwb-layer-lock") || e.target.closest(".iwb-layer-del")) return;
|
if (e.target.closest(".iwb-layer-vis") || e.target.closest(".iwb-layer-lock") || e.target.closest(".iwb-layer-del")) return;
|
||||||
|
if (e.target.closest(".iwb-layer-opacity") || e.target.closest(".iwb-layer-name-input") || e.target.closest(".iwb-layer-op-row")) return;
|
||||||
const id = item.dataset.layerId;
|
const id = item.dataset.layerId;
|
||||||
const type = item.dataset.layerType;
|
const type = item.dataset.layerType;
|
||||||
if (e.metaKey || e.ctrlKey) {
|
if (e.metaKey || e.ctrlKey) {
|
||||||
@@ -2159,45 +2196,122 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function bindLayerStyleInputs(list) {
|
function bindLayerNameRename(list) {
|
||||||
list.querySelectorAll(".iwb-layer-color").forEach((input) => {
|
list.querySelectorAll(".iwb-layer-name.renamable").forEach((el) => {
|
||||||
|
el.addEventListener("mousedown", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
const id = el.dataset.nameId;
|
||||||
|
const now = Date.now();
|
||||||
|
const prev = S.lastNameClick;
|
||||||
|
if (prev && prev.id === id && now - prev.t < 400) {
|
||||||
|
S.lastNameClick = null;
|
||||||
|
beginRename(id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
S.lastNameClick = { id, t: now };
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function beginRename(id) {
|
||||||
|
const list = runtime.el.querySelector(".iwb-editor-layer-list");
|
||||||
|
const layer = S.layers.find((l) => l.id === id);
|
||||||
|
if (!list || !layer) return;
|
||||||
|
const item = list.querySelector('.iwb-layer-item[data-layer-id="' + id + '"]');
|
||||||
|
const span = item && item.querySelector(".iwb-layer-name");
|
||||||
|
if (!span || !span.parentNode) return;
|
||||||
|
const input = document.createElement("input");
|
||||||
|
input.className = "iwb-layer-name-input";
|
||||||
|
input.type = "text";
|
||||||
|
input.value = layer.name;
|
||||||
|
input.maxLength = 40;
|
||||||
|
span.replaceWith(input);
|
||||||
|
item.draggable = false;
|
||||||
|
let done = false;
|
||||||
|
const finish = (commit) => {
|
||||||
|
if (done) return;
|
||||||
|
done = true;
|
||||||
|
const next = input.value.trim();
|
||||||
|
if (commit && next && next !== layer.name) {
|
||||||
|
saveSnapshot("重命名图层");
|
||||||
|
layer.name = next;
|
||||||
|
}
|
||||||
|
renderLayerPanel();
|
||||||
|
};
|
||||||
input.addEventListener("mousedown", (e) => e.stopPropagation());
|
input.addEventListener("mousedown", (e) => e.stopPropagation());
|
||||||
|
input.addEventListener("click", (e) => e.stopPropagation());
|
||||||
|
input.addEventListener("keydown", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
finish(true);
|
||||||
|
} else if (e.key === "Escape") {
|
||||||
|
e.preventDefault();
|
||||||
|
finish(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.addEventListener("blur", () => finish(true));
|
||||||
|
input.focus();
|
||||||
|
input.select();
|
||||||
|
}
|
||||||
|
function bindLayerOpacityInputs(list) {
|
||||||
|
list.querySelectorAll(".iwb-layer-opacity").forEach((input) => {
|
||||||
|
input.addEventListener("mousedown", (e) => e.stopPropagation());
|
||||||
|
input.addEventListener("click", (e) => e.stopPropagation());
|
||||||
|
input.addEventListener("dblclick", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
input.value = "100";
|
||||||
|
applyOpacityFromInput(input);
|
||||||
|
});
|
||||||
input.addEventListener("input", (e) => {
|
input.addEventListener("input", (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const id = input.dataset.colorId;
|
applyOpacityFromInput(input);
|
||||||
const type = input.dataset.colorType;
|
});
|
||||||
const obj = type === "bitmap" ? S.layers.find((l) => l.id === id) : S.shapeLayers.find((s) => s.id === id);
|
});
|
||||||
if (obj) {
|
}
|
||||||
obj.color = input.value;
|
function applyOpacityFromInput(input) {
|
||||||
S.color = input.value;
|
const type = input.dataset.opType;
|
||||||
updateColorUI();
|
const obj = findPanelTarget(type, input.dataset.opId);
|
||||||
renderObjects();
|
if (!obj) return;
|
||||||
renderLayerPanel();
|
const pct = clamp(parseInt(input.value, 10) || 0, 0, 100);
|
||||||
|
if (!input._opSnapTaken) {
|
||||||
|
input._opSnapTaken = true;
|
||||||
|
saveSnapshot("调整不透明度");
|
||||||
|
}
|
||||||
|
obj.opacity = pct / 100;
|
||||||
|
applyOpacityVisual(type, obj);
|
||||||
S.pickerComposite = null;
|
S.pickerComposite = null;
|
||||||
|
const val = input.parentNode && input.parentNode.querySelector(".iwb-layer-op-val");
|
||||||
|
if (val) val.textContent = pct + "%";
|
||||||
}
|
}
|
||||||
});
|
var _thumbTimer = 0;
|
||||||
});
|
function scheduleThumbs() {
|
||||||
list.querySelectorAll(".iwb-layer-width").forEach((input) => {
|
if (_thumbTimer) return;
|
||||||
input.addEventListener("mousedown", (e) => e.stopPropagation());
|
_thumbTimer = setTimeout(() => {
|
||||||
input.addEventListener("input", (e) => {
|
_thumbTimer = 0;
|
||||||
e.stopPropagation();
|
paintThumbs();
|
||||||
const id = input.dataset.widthId;
|
}, 90);
|
||||||
const type = input.dataset.widthType;
|
|
||||||
const value = clamp(parseInt(input.value, 10) || 1, 1, 300);
|
|
||||||
const obj = type === "bitmap" ? S.layers.find((l) => l.id === id) : S.shapeLayers.find((s) => s.id === id);
|
|
||||||
if (obj) {
|
|
||||||
obj.lineWidth = value;
|
|
||||||
if (type === "shape") obj.lw = value;
|
|
||||||
else {
|
|
||||||
S.brushSize = value;
|
|
||||||
refreshBrushRing();
|
|
||||||
}
|
}
|
||||||
renderObjects();
|
function paintThumbs() {
|
||||||
updateBrushParamUI();
|
if (!runtime.el) return;
|
||||||
renderLayerPanel();
|
const list = runtime.el.querySelector(".iwb-editor-layer-list");
|
||||||
|
if (!list) return;
|
||||||
|
list.querySelectorAll(".iwb-layer-thumb canvas").forEach((cv) => {
|
||||||
|
const type = cv.dataset.thumbType;
|
||||||
|
const obj = findPanelTarget(type, cv.dataset.thumbId);
|
||||||
|
const src = obj ? type === "bitmap" ? obj.canvas : obj._canvas : null;
|
||||||
|
const g = cv.getContext("2d");
|
||||||
|
if (!g) return;
|
||||||
|
g.clearRect(0, 0, cv.width, cv.height);
|
||||||
|
if (!src || !src.width || !src.height) return;
|
||||||
|
const k = Math.min(cv.width / src.width, cv.height / src.height);
|
||||||
|
const dw = Math.max(1, Math.round(src.width * k));
|
||||||
|
const dh = Math.max(1, Math.round(src.height * k));
|
||||||
|
try {
|
||||||
|
g.imageSmoothingQuality = "high";
|
||||||
|
g.drawImage(src, Math.round((cv.width - dw) / 2), Math.round((cv.height - dh) / 2), dw, dh);
|
||||||
|
} catch (e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
function bindLayerVisButtons(list) {
|
function bindLayerVisButtons(list) {
|
||||||
list.querySelectorAll(".iwb-layer-vis").forEach((btn) => {
|
list.querySelectorAll(".iwb-layer-vis").forEach((btn) => {
|
||||||
@@ -2293,7 +2407,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
for (const u of units) {
|
for (const u of units) {
|
||||||
const el = u.kind === "bitmap" ? u.obj.canvas : u.obj._canvas;
|
const el = u.kind === "bitmap" ? u.obj.canvas : u.obj._canvas;
|
||||||
if (!el || el.nodeType !== 1) continue;
|
if (!el || el.nodeType !== 1) continue;
|
||||||
tctx.globalAlpha = u.obj.opacity == null ? 1 : u.obj.opacity;
|
tctx.globalAlpha = u.kind === "bitmap" ? u.obj.opacity == null ? 1 : u.obj.opacity : 1;
|
||||||
tctx.drawImage(el, 0, 0);
|
tctx.drawImage(el, 0, 0);
|
||||||
}
|
}
|
||||||
tctx.globalAlpha = 1;
|
tctx.globalAlpha = 1;
|
||||||
@@ -5310,10 +5424,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
addBitmapLayer(await loadImage(dataUrl));
|
addBitmapLayer(await loadImage(dataUrl));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[IWB编辑器] 粘贴图片链接失败:", err);
|
console.error("[IWB编辑器] 粘贴图片链接失败:", err);
|
||||||
try {
|
toast("粘贴失败:" + (err && err.message || "无法读取剪贴板里的图片链接"), "error");
|
||||||
window.alert("粘贴失败:" + (err && err.message || "无法读取剪贴板里的图片链接"));
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6578,6 +6689,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
S.penDragPending = null;
|
S.penDragPending = null;
|
||||||
S.selectedLayerId = null;
|
S.selectedLayerId = null;
|
||||||
S.bitmapDrag = null;
|
S.bitmapDrag = null;
|
||||||
|
S.layerMulti.length = 0;
|
||||||
|
S.hoverPos = null;
|
||||||
|
S.lastClick = null;
|
||||||
|
S.lastNameClick = null;
|
||||||
|
S.altPicker = false;
|
||||||
S.zCounter = Math.max(S.layers.length - 1, 0);
|
S.zCounter = Math.max(S.layers.length - 1, 0);
|
||||||
S.placingImage = null;
|
S.placingImage = null;
|
||||||
S.placingHandle = null;
|
S.placingHandle = null;
|
||||||
@@ -6726,7 +6842,16 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
doc: { w: S.imgW, h: S.imgH },
|
doc: { w: S.imgW, h: S.imgH },
|
||||||
zoom: S.zoom,
|
zoom: S.zoom,
|
||||||
fit: { w: Math.round(S.fitW || 0), h: Math.round(S.fitH || 0) },
|
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 })),
|
layers: S.layers.map((l) => ({
|
||||||
|
id: l.id,
|
||||||
|
name: l.name,
|
||||||
|
z: l.z,
|
||||||
|
locked: !!l.locked,
|
||||||
|
visible: l.visible !== false,
|
||||||
|
// 不透明度有两个面:数据字段(导出/合并用)与 CSS(屏幕上看到的),两者必须一致
|
||||||
|
opacity: l.opacity == null ? 1 : l.opacity,
|
||||||
|
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || "1") : null
|
||||||
|
})),
|
||||||
shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color })),
|
shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color })),
|
||||||
texts: S.textLayers.map((t) => ({ id: t.id, text: t.text })),
|
texts: S.textLayers.map((t) => ({ id: t.id, text: t.text })),
|
||||||
selectedShapeId: S.selectedShapeId,
|
selectedShapeId: S.selectedShapeId,
|
||||||
@@ -6786,7 +6911,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// image-annotate/plugin/editor.css
|
// image-annotate/plugin/editor.css
|
||||||
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
|
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
|
||||||
|
|
||||||
// image-annotate/plugin/glue.js
|
// image-annotate/plugin/glue.js
|
||||||
function createGlue(ctx, css) {
|
function createGlue(ctx, css) {
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|||||||
const REPO = path.resolve(HERE, '../..')
|
const REPO = path.resolve(HERE, '../..')
|
||||||
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
|
||||||
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js')
|
||||||
|
// 版本真源是 package.json(构建时注入 manifest),探针不再硬编码,免得每次发版都要改测试
|
||||||
|
const PKG_VERSION = JSON.parse(readFileSync(path.resolve(HERE, '../package.json'), 'utf8')).version
|
||||||
|
|
||||||
let chromium = null
|
let chromium = null
|
||||||
for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) {
|
for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) {
|
||||||
@@ -96,7 +98,7 @@ const boot = await page.evaluate((png) => {
|
|||||||
window.__commands['annotate-selected'].run().catch(() => {})
|
window.__commands['annotate-selected'].run().catch(() => {})
|
||||||
return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) }
|
return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) }
|
||||||
}, PNG)
|
}, PNG)
|
||||||
check('产物可执行(循环打包未炸)', boot.version === '1.6.0', 'version=' + boot.version)
|
check('产物可执行(循环打包未炸)', boot.version === PKG_VERSION, 'version=' + boot.version + ' 期望 ' + PKG_VERSION)
|
||||||
check('manifest 声明输出预设设置项', boot.settingsSchema.includes('exportPreset') && boot.settingsSchema.includes('panelsCollapsed'), boot.settingsSchema.join(','))
|
check('manifest 声明输出预设设置项', boot.settingsSchema.includes('exportPreset') && boot.settingsSchema.includes('panelsCollapsed'), boot.settingsSchema.join(','))
|
||||||
|
|
||||||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
||||||
@@ -1292,6 +1294,72 @@ check('合并可见图层:隐藏层原样保留,可见层合成一层', awai
|
|||||||
: 'hidden=' + stillHidden + ' visible ' + visibleBefore + '→' + visibleAfter + ' layers=' + d1.layers.length
|
: 'hidden=' + stillHidden + ' visible ' + visibleBefore + '→' + visibleAfter + ' layers=' + d1.layers.length
|
||||||
})())
|
})())
|
||||||
|
|
||||||
|
check('图层面板:缩略图画出了图层内容(不是空框)', await (async () => {
|
||||||
|
await page.waitForTimeout(260) // 缩略图有 90ms 合批延迟
|
||||||
|
const n = await page.evaluate(() => {
|
||||||
|
const cv = document.querySelector('.iwb-layer-thumb canvas[data-thumb-id="base"]')
|
||||||
|
if (!cv) return -1
|
||||||
|
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||||||
|
let k = 0
|
||||||
|
for (let i = 3; i < d.length; i += 4) if (d[i] > 8) k++
|
||||||
|
return k
|
||||||
|
})
|
||||||
|
return n > 10 ? true : '缩略图不透明像素=' + n
|
||||||
|
})())
|
||||||
|
|
||||||
|
check('图层重命名:双击名字进入编辑,Enter 提交后生效', await (async () => {
|
||||||
|
await page.keyboard.press('Control+Shift+n')
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
const id = (await dbg()).activeLayerId
|
||||||
|
const nameEl = page.locator('.iwb-layer-name[data-name-id="' + id + '"]')
|
||||||
|
await nameEl.click()
|
||||||
|
await nameEl.click() // 400ms 内两次按下 → 自算双击(点一下会重绘面板)
|
||||||
|
const input = page.locator('.iwb-layer-name-input')
|
||||||
|
if (!(await input.count())) return '未进入重命名态'
|
||||||
|
await input.fill('主体层')
|
||||||
|
await input.press('Enter')
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
const nm = (await dbg()).layers.find(l => l.id === id)
|
||||||
|
return nm && nm.name === '主体层' && !(await page.locator('.iwb-layer-name-input').count())
|
||||||
|
? true
|
||||||
|
: '名字=' + (nm && nm.name)
|
||||||
|
})())
|
||||||
|
|
||||||
|
check('图层不透明度:滑杆到 40% 立刻生效,一次拖动只记 1 条撤销', await (async () => {
|
||||||
|
await page.keyboard.press('Control+Shift+n')
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
const id = (await dbg()).activeLayerId
|
||||||
|
const row = await page.locator('.iwb-layer-item[data-layer-id="' + id + '"] .iwb-layer-op-row').count()
|
||||||
|
if (!row) return '选中项下没有不透明度行'
|
||||||
|
const h0 = (await dbg()).history
|
||||||
|
for (const v of [70, 55, 40]) {
|
||||||
|
await page.evaluate((val) => {
|
||||||
|
const el = document.querySelector('.iwb-layer-opacity')
|
||||||
|
el.value = String(val)
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
}, v)
|
||||||
|
}
|
||||||
|
const d = await dbg()
|
||||||
|
const l = d.layers.find(x => x.id === id)
|
||||||
|
const val = await page.locator('.iwb-layer-op-val').first().textContent()
|
||||||
|
if (!l) return '图层丢失'
|
||||||
|
if (Math.abs(l.opacity - 0.4) > 0.001) return 'opacity=' + l.opacity
|
||||||
|
if (Math.abs(l.cssOpacity - 0.4) > 0.001) return 'cssOpacity=' + l.cssOpacity + '(画面没跟上)'
|
||||||
|
if ((val || '').trim() !== '40%') return '标值=' + val
|
||||||
|
if (d.history - h0 !== 1) return '撤销条数=' + (d.history - h0) + '(一次拖动应只拍 1 张快照)'
|
||||||
|
return true
|
||||||
|
})())
|
||||||
|
|
||||||
|
check('图层不透明度:Ctrl+Z 回到 100%,画面同步', await (async () => {
|
||||||
|
await page.keyboard.press('Control+z')
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const d = await dbg()
|
||||||
|
const l = d.layers[d.layers.length - 1]
|
||||||
|
return l && Math.abs(l.opacity - 1) < 0.001 && Math.abs(l.cssOpacity - 1) < 0.001
|
||||||
|
? true
|
||||||
|
: 'opacity=' + (l && l.opacity) + ' css=' + (l && l.cssOpacity)
|
||||||
|
})())
|
||||||
|
|
||||||
check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (async () => {
|
check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (async () => {
|
||||||
await page.keyboard.press('Escape') // 清掉可能残留的选中态
|
await page.keyboard.press('Escape') // 清掉可能残留的选中态
|
||||||
await page.keyboard.press('Control+]')
|
await page.keyboard.press('Control+]')
|
||||||
|
|||||||
Reference in new issue
Block a user