Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
244fc9c2b2 | ||
|
|
546999fdf9 | ||
|
|
bf32ec6ddb | ||
|
|
31866a2407 |
No files matched your search
@@ -234,6 +234,217 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
|||||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||||
|
|
||||||
|
## v1.14.0:文字可以选字体(黑 / 宋 / 楷 / 圆)
|
||||||
|
|
||||||
|
需求:「文字工具能不能选字体」。可以,而且成本很低 —— 但**只做了系统字体族**,没有内置字体文件,
|
||||||
|
原因见下。
|
||||||
|
|
||||||
|
### 怎么用
|
||||||
|
|
||||||
|
选中文字(或切到文字工具、不选任何东西)→ 选项栏「字体」下拉,四档:
|
||||||
|
|
||||||
|
| 档位 | 字体栈(按命中顺序) | 适合 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 黑体 | PingFang SC → Microsoft YaHei → Heiti SC → 思源黑体 → sans-serif | 默认。现代无衬线,信息密度高 |
|
||||||
|
| 宋体 | Songti SC → SimSun → 思源宋体 → serif | 正式、印刷感,标题压得住 |
|
||||||
|
| 楷体 | Kaiti SC → KaiTi → STKaiti → serif | 手写感,批注、签名、便签 |
|
||||||
|
| 圆体 | Yuanti SC → YouYuan → 苹方 → sans-serif | 柔和,促销、亲子、轻食 |
|
||||||
|
|
||||||
|
选中文字时立刻生效;没选中时改的是「下一段文字的默认字体」——与字重 / 对齐 / 行距同一套逻辑。
|
||||||
|
双击编辑文字时,输入框的字形和字重也跟着这段文字走,不会出现「输入时是黑体、确认后变宋体」。
|
||||||
|
|
||||||
|
### 为什么不内置字体文件
|
||||||
|
|
||||||
|
三条硬约束:
|
||||||
|
|
||||||
|
1. **CSP 拦死了第三方字体**。宿主 `_headers` 是 `default-src 'self'`,`font-src` 回落它,
|
||||||
|
`https:` 只放给了 `img-src` / `connect-src`。Google Fonts 或任何字体 CDN 都会被浏览器直接拒绝。
|
||||||
|
2. **中文字体太大**。本机参照:宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB;插件产物现在 392KB,
|
||||||
|
内联等于涨 5–150 倍。子集化到 3500 常用字约 0.8–1.5MB/个,能接受,但要放宿主静态目录,
|
||||||
|
发布链得一起改。
|
||||||
|
3. **异步字体的时序坑**。Web 字体异步加载,字体没 ready 就 `measureText`,量出来的是 fallback
|
||||||
|
的宽度 —— 选中框和实际字形错位,导出还可能画成 fallback。系统字体同步可用,没有这个问题。
|
||||||
|
|
||||||
|
### 性能:字体不是瓶颈
|
||||||
|
|
||||||
|
1000×1000 画布、30 个文字对象(每个对象一张整图画布,见 `layers.js#vecCanvasFor`):
|
||||||
|
|
||||||
|
| | 首次绘制 | 热重绘 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 现在(`sans-serif`) | 42.1 ms | 0.2 ms |
|
||||||
|
| 苹方 | 13.5 ms | 0.1 ms |
|
||||||
|
| 宋体 | 13.2 ms | 0.1 ms |
|
||||||
|
| 楷体 | 22.2 ms | 0.1 ms |
|
||||||
|
| 圆体 | 21.2 ms | 0.1 ms |
|
||||||
|
|
||||||
|
换字体只在**首次**多一次字形光栅化(13–42ms,一到两帧),之后走字形缓存,比现状还略快。
|
||||||
|
|
||||||
|
顺带记一条既有开销(与本版无关,但图大了要注意):每个文字对象占一张 imgW×imgH 的画布,
|
||||||
|
1000² 是 3.8MB、4000² 是 61MB;20 个文字对象在 4000² 图上约 1.2GB。
|
||||||
|
|
||||||
|
### 一个反直觉的事实
|
||||||
|
|
||||||
|
**中文是全角等宽,换字体不改字宽**。同一段 10 个字在 6 种字体下 `measureText` 全是 480px
|
||||||
|
(48px × 10)。所以切换字体不会让已有标注的版面跳动,只有拉丁字母和数字会伸缩 ——
|
||||||
|
这也是锚点继续用「左上角」而不是居中的理由。
|
||||||
|
|
||||||
|
### 兼容性
|
||||||
|
|
||||||
|
- 老文字对象没有 `fontFamily` 字段 → `fontKeyOf()` 回退到 `sans`,行为与旧版一致。
|
||||||
|
- 不认识的值(外部写入、脏数据)也收敛回 `sans`,不会把非法字符串塞进 `ctx.font`
|
||||||
|
—— 那会让整串字体失效、静默退回浏览器默认字体,画面上看不出报错,极难排查。
|
||||||
|
- 默认档的字体栈比旧的 `sans-serif` 更明确(苹方优先),**英文和数字的字形会有细微变化**,
|
||||||
|
中文基本无感。这是「让字体可控」的代价,比留着跨平台不可控的 `sans-serif` 要好。
|
||||||
|
|
||||||
|
回归:harness 192 → 197 条(新增 5 条,含脏值收敛与「换字体不改中文宽度」);`npm run validate` 9/9。
|
||||||
|
|
||||||
|
## v1.13.1:Shift+X 改成「交换填充色与描边色」
|
||||||
|
|
||||||
|
反馈:「矩形 圆形 钢笔,切换填充与描边色的时候,会导致填充丢掉」→ 补一句关键信息
|
||||||
|
「shift+x 切换填充与描边色的时候,就会出现丢失填充色的问题……再按这个快捷键填色又回来了,
|
||||||
|
但是描边一直不变」。
|
||||||
|
|
||||||
|
### 不是颜色被清空,是快捷键语义错了
|
||||||
|
|
||||||
|
先把能想到的入口全实测了一遍(工具栏两个色槽、色板头部 tab、SV 拖动、hex 输入、选项栏原生
|
||||||
|
色块、切换工具往返、矩形/圆形/钢笔、钢笔闭合与未闭合):**`fillColor` 从来没被清空,画面像素
|
||||||
|
也没有丢**。真正的错在 **Shift+X 的语义**:
|
||||||
|
|
||||||
|
| | 旧行为 | 用户期望 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 按一次 | 填充开关被关掉(只剩描边),描边色不动 | 填充色与描边色**对调** |
|
||||||
|
| 再按一次 | 填充开关恢复,描边色仍然不动 | 换回来 |
|
||||||
|
|
||||||
|
用户看到的正是「填充没了、描边一直不变,再按一次填充又回来」—— 那是**开关**的行为,
|
||||||
|
而 PS 里 `X` 是**交换前景/背景色**。所以这不是"颜色丢了",是把颜色交换做成了开关。
|
||||||
|
|
||||||
|
### 改法
|
||||||
|
|
||||||
|
新增 `swapShapeColors()`(`events.js`),Shift+X 改为调它:
|
||||||
|
|
||||||
|
- 描边色 ↔ 填充色对调:`sh.color ⇄ sh.fillColor`,同时同步主色 `S.color` 与默认填充色
|
||||||
|
`S.shapeFillColor`(v1.10 起这两个就是同一份真相源,不另存)
|
||||||
|
- **填充的开关状态不动**:交换的是颜色,不是有无。实心图形交换后仍是实心
|
||||||
|
- 箭头没有内部,直接 toast 说明;填充还在「跟随描边色」(`fillColor=null`,两边同一个值)
|
||||||
|
时也只提示,不改数据
|
||||||
|
- 一步历史:`saveSnapshot('交换填充与描边色')`,`Ctrl+Z` 一次回退
|
||||||
|
|
||||||
|
实心/描边的切换**没有丢**,仍在选项栏那两个按钮上(`data-opt-toggle`),只是不再占 Shift+X;
|
||||||
|
按钮的 tooltip 里原来写着「(Shift+X 切换)」,容易让人以为 Shift+X 是开关,已改成说明交换语义。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` 里那条旧用例(断言按 Shift+X 后 `fill` 变 true)换成新的交换用例,
|
||||||
|
断言「描边/填充两个色值互换、`fill` 开关不变、再按一次回到原样」。这条用例放在文件末尾跑 ——
|
||||||
|
交换会把「下一个图形的填充色」也写成具体色值,夹在中间会污染后面「新建图形填充默认跟随描边色」的断言。
|
||||||
|
|
||||||
|
## v1.13.0:顶栏瘦身 / 视图按钮归位 / R·O·L 快捷键 / 填充色实时 / 图层解封
|
||||||
|
|
||||||
|
五条调整,前四条是界面与手感,最后一条是能力解禁(原型是 PS,但「原图不许压」这条并不是 PS 的规矩)。
|
||||||
|
|
||||||
|
### 1. 顶栏去掉四个层级按钮
|
||||||
|
|
||||||
|
置顶 / 上移 / 下移 / 置底那四个箭头,在有了图层面板拖动和 `Ctrl+]` `Ctrl+[` 之后就是纯冗余 —— 而且
|
||||||
|
它们只能作用在**选中**对象上,够不到位图层。整套 `.iwb-editor-commands` 连同里面的分隔线一起删掉,
|
||||||
|
`updateLayerUI()` 与 `bindLayerOrderButtons()` 两个函数也一并清除(不留死代码)。
|
||||||
|
顶栏现在只剩:标题 · 新建 / 覆盖 / 退出 · 撤销 / 重做 / 还原;右侧输出设置 + 复制 + 导出。
|
||||||
|
|
||||||
|
### 2. 「适应窗口」「收起侧栏」挪到工具栏最右
|
||||||
|
|
||||||
|
这两个是**视图**操作,跟绘制工具不是一类,原来挤在顶栏右边,与「复制」「导出」贴着容易被误点。
|
||||||
|
移过去没有用任何特殊定位 —— 工具栏是 `position:absolute; left:50%; translateX(-50%)` 的
|
||||||
|
**shrink-to-fit** 容器,所以「放在 DOM 最后」天然就是「视觉最右」。中间补一条 `.iwb-editor-divider`
|
||||||
|
和工具区隔开。
|
||||||
|
|
||||||
|
### 3. 快捷键:`R` 矩形、`O` 圆形、`L` 箭头
|
||||||
|
|
||||||
|
原来 `R` 没被占用(矩形只有 `U`),`O` 也没有,`L` 是套索。按需求:
|
||||||
|
|
||||||
|
| 键 | 工具 | 备注 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `R` | 矩形 | 与 `U` 并存,老的 `U` 和 `Shift+U` 循环保留 |
|
||||||
|
| `O` | 圆形 | 同上,不抢 `U` 的手感 |
|
||||||
|
| `L` | 箭头 | 原本是套索 |
|
||||||
|
| `A` | 套索 | 从 `L` 迁过来(不丢能力) |
|
||||||
|
|
||||||
|
顺手修了一个老毛病:中文输入法下按 `[` `]` 会被 IME 吃成 `【` `】`,只匹配 `e.key` 会失灵,
|
||||||
|
键盘处理里改成**优先匹配 `e.code`**。
|
||||||
|
|
||||||
|
### 4. 填充色改动实时上图
|
||||||
|
|
||||||
|
反馈是「填充色状态不能实时在矢量图形上显示颜色变化」。查下来有两条独立原因:
|
||||||
|
|
||||||
|
- **色板 SV 拖动本来就是实时的** —— 每帧都写 `fillColor` 再 `renderObjects()`,像素确实在变
|
||||||
|
(探测:`fillRect` 从 `#572424` 到 `#665c5c`)。这条不用改。
|
||||||
|
- **真正不实时的是选项栏那两个原生 `<input type="color">`** —— 原生色块只派发两个事件:`input`
|
||||||
|
(取色器**拉开拖动中**)和 `change`(关闭取色器)。原来只接了 `change`,于是系统取色器开着的时候
|
||||||
|
画布一动不动,关掉才「啪」一下变色,主观感受就是「不实时」。
|
||||||
|
|
||||||
|
改法是 `input` 与 `change` 都接,但历史记一步:`input` 阶段用 `skipHistory` 直接写状态 + 重绘
|
||||||
|
(`nativeColorSnapped` 标记只在第一次 `input` 时 `saveSnapshot()`),`change` 收尾时才落一次
|
||||||
|
可撤销的提交。实测拖一整轮色谱只产生 **1 步**撤销,`Ctrl+Z` 一次回到原点。
|
||||||
|
|
||||||
|
### 5. 图层可以拖到原图下面
|
||||||
|
|
||||||
|
原来「原图」被钉在 z 最底层,五处代码各钉一遍:`planPanelOrder()` 把它 `unshift` 到最前、
|
||||||
|
`updateSortTarget()` 拿它当锚点、`onSortEnd()` 把它补回末尾、`moveLayer()` 用
|
||||||
|
`baseIdx >= 0 ? 1 : 0` 把最小值抬到 1、`mergeUnits()` 把合并结果 `rest.unshift` 到底。
|
||||||
|
现在五处全部拆掉:原图就是一个普通 `base` 图层,只是**自己不能被拖**(行上仍然 `return`),
|
||||||
|
别人的 z 可以任意跨过它;合并时也按 z 插回原位而不是塞到最底。
|
||||||
|
|
||||||
|
面板提示同步改成「原图(其他图层可以拖到它下面)」。回归用例验证:把第一行拖到最底行下半区后,
|
||||||
|
`base` 的 z 从 0 变成 1、被拖的层变成 0 —— 原图被成功压到下面,`Ctrl+Z` 能复原。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` 由 140 → **192 条**(文字三色 11 条 + 本节 5 条改动各自的正反断言:
|
||||||
|
顶栏层级按钮数为 0、工具栏末两个子元素是 `zoomFit/togglePanels`、快捷键表 `V M A L B E P T R O U C I H`、
|
||||||
|
原生色块只发 `input` 也能实时变色、拖动一次只记 1 步撤销、原图可被压到下面)。
|
||||||
|
|
||||||
|
## v1.12.0:文字的三个颜色各自可调(文字 / 描边 / 底色)
|
||||||
|
|
||||||
|
用户反馈:「文本的内容需要描边与文字颜色的设定,还多一个文本框的底色,这里 3 个颜色你来
|
||||||
|
修正下,现在文本不支持描边与字体色切换」。
|
||||||
|
|
||||||
|
一查是**真的不通**,不是没找到入口:文字对象本来就有三个颜色字段(`color` / `strokeColor` /
|
||||||
|
`bgColor`),但工具栏只有「描边 / 填充」两格,而这两格是按**形状**算的 —— 选中文字时第二格
|
||||||
|
指向的是形状的 `fillColor` 与 `rectFill`,点它、选色、拖 SV,画面上一点变化都没有。文字的两个
|
||||||
|
颜色只能从选项栏里那两个小色块改,且「描边色」在描边宽度为 0 时改了什么也看不见。
|
||||||
|
|
||||||
|
### 1. 先回答「现在有几个颜色」这个问题(`colorContext()`)
|
||||||
|
|
||||||
|
以前这个判断散在各处:`fillSlotOn()` 只看 `S.tool`,`textCtx` 又另算一遍(`S.tool === 'text'
|
||||||
|
|| selectedTextId`),两处口径不同就会出现「工具栏觉得是形状、选项栏觉得是文字」。现在收成
|
||||||
|
一个函数、三档上下文:
|
||||||
|
|
||||||
|
| 上下文 | 触发条件 | 颜色格 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `text` | 选中文字,或文字工具下还没落字 | 文字 / 描边 / 底色(三格横排) |
|
||||||
|
| `shape` | 选中矩形·圆·钢笔,或这几个工具下 | 描边 / 填充(两格叠放,同 v1.11) |
|
||||||
|
| `strokeOnly` | 画笔·橡皮·箭头·没选中东西 | 只有一格(画笔色 / 描边色) |
|
||||||
|
|
||||||
|
`colorSlots()` 按上下文返回三个颜色值 + 每格「当前生效吗」,仍是工具栏、色板头部、hex、
|
||||||
|
调色器、吸管**唯一的取值处**。
|
||||||
|
|
||||||
|
### 2. 三格各写各的字段
|
||||||
|
|
||||||
|
- **文字色** = 主色 `S.color`(与画笔色同一个值,仍是「一个主色」的约定),选中文字时写它自己的 `color`
|
||||||
|
- **描边色** = `strokeColor`;选色时若描边宽度是 0,自动补 6px —— 否则「选了颜色画面不变」
|
||||||
|
又会被当成坏了
|
||||||
|
- **底色** = `bgColor`;选色时若底色块没开,自动打开(半透明色块按 `bgAlpha` 真实显示)
|
||||||
|
|
||||||
|
三条写回路径合并成一入口 `applyTextColor(key, color, opts)`,支持色板里拖 SV 时的
|
||||||
|
`skipHistory`(一次拖动只算一步撤销)。选项栏那两个原生色块走的是同一份状态,两边永远一致。
|
||||||
|
|
||||||
|
### 3. 「无」
|
||||||
|
|
||||||
|
同一颗「无」按钮按当前格分派:填充 → `fill=false`(内部透明);文字描边 → 描边宽度 0;
|
||||||
|
文字底色 → 关掉色块。三种都只关开关、**颜色留着**。文字色没有「无」—— 字没有颜色等于把字删了。
|
||||||
|
|
||||||
|
### 4. 一格没生效就画斜杠
|
||||||
|
|
||||||
|
描边宽度 0 / 底色关闭时,对应格子显示为灰底红斜杠(不再露着上次的颜色),一眼能看出这格现在
|
||||||
|
没生效;半透明底色格按真实不透明度显示,看起来才像「垫了一块板」。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` 新增 11 条(三格可见性、描边色自动补宽度、底色自动开启、三格互不串、
|
||||||
|
「无」在底色格上的语义、切回矩形工具第三格收起),共 190 条全通。
|
||||||
|
|
||||||
## v1.11.0:工具栏变成「描边 + 填充」两格,填充可以设「无」
|
## v1.11.0:工具栏变成「描边 + 填充」两格,填充可以设「无」
|
||||||
|
|
||||||
用户这次的反馈是「工具栏的调色、描边、填充 3 个位置调色有问题,应该是 2 个调色,
|
用户这次的反馈是「工具栏的调色、描边、填充 3 个位置调色有问题,应该是 2 个调色,
|
||||||
|
|||||||
@@ -311,7 +311,11 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
||||||
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
||||||
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
||||||
| 颜色体系与矢量属性 | ✅ v1.11.0:颜色收敛为**描边 / 填充两格**——工具栏改 PS 式双色槽(`S.colorTarget` 决定色板写哪一格),选项栏两色块与工具栏双向同步,`colorSlots()` 成为唯一取值处;填充支持**无**(`fill=false`,颜色保留,槽位画灰底红斜杠);画笔/文字/箭头等无填充概念的工具只显示一格 |
|
| 文字字体选择 | ✅ v1.14.0:文字对象新增 `fontFamily`(预设 key:`sans` 黑体 / `serif` 宋体 / `kai` 楷体 / `round` 圆体),`fontOf()` 从硬编码 `sans-serif` 改为读 `TEXT_FONTS[key].stack` 的跨平台字体栈;选项栏加「字体」下拉(`select[data-opt-text]`,走 `change` 委托,其余文字样式仍走 `click`),复用 `TEXT_STYLE_STATE_KEY` 一条写回路径;输入框同步字体族与字重;`fontKeyOf()` 把脏值收敛回默认。**明确不做内置字体**:宿主 CSP `default-src 'self'` 拦第三方字体、CJK 字体 2–64MB 无法内联、异步字体有 measureText 时序坑。实测换字体仅首次多 13–42ms 字形光栅化,热重绘 0.1–0.2ms;中文全角等宽,换字体不改字宽(1000²/30 对象内存 114MB 属既有架构,与字体无关) |
|
||||||
|
| 快捷键语义修正(v1.13.1) | ✅ v1.13.1:Shift+X 从「实心 ↔ 只描边」开关改成**交换填充色与描边色**(PS 的 X 语义)。旧行为下按一次填充被关掉、描边色不动,用户看到的就是「填充丢了」。新 `swapShapeColors()` 对调 `sh.color ⇄ sh.fillColor` 并同步 `S.color` / `S.shapeFillColor`,**填充开关不动**(交换颜色不改有无),箭头跳过、跟随态只提示,一步历史。实心/描边切换仍留在选项栏按钮上 |
|
||||||
|
| 界面瘦身 / 快捷键 / 实时预览 / 图层解封 | ✅ v1.13.0:顶栏删掉四个层级按钮(`.iwb-editor-commands` 整块移除,`updateLayerUI()` / `bindLayerOrderButtons()` 一并清除);「适应窗口 / 收起侧栏」移到工具栏 DOM 末尾(shrink-to-fit 天然最右);快捷键 `R` 矩形 / `O` 圆形 / `L` 箭头(套索迁 `A`,`U` 保留),键盘处理改为优先匹配 `e.code` 以兼容中文输入法;原生 `<input type="color">` 补接 `input` 做实时预览(`skipHistory` + `nativeColorSnapped`,一次拖动仍只记 1 步撤销);原图不再钉底——`planPanelOrder` / `updateSortTarget` / `onSortEnd` / `moveLayer` / `mergeUnits` 五处解封,其他图层可拖到原图下方 |
|
||||||
|
| 颜色体系与矢量属性 | ✅ v1.12.0:颜色上下文收敛成 `colorContext()` 三档(文字 / 形状 / 只有主色),文字上下文给**三格**(文字 / 描边 / 底色,`data-color-mode="triple"`),`applyTextColor()` 统管描边色与底色的写回(含 `skipHistory` 拖拽);「无」按当前格分派(无填充 / 无描边 / 无底色);原文「文本不支持描边与字体色切换」已修 |
|
||||||
|
| 颜色体系与矢量属性(v1.11) | ✅ v1.11.0:颜色收敛为**描边 / 填充两格**——工具栏改 PS 式双色槽(`S.colorTarget` 决定色板写哪一格),选项栏两色块与工具栏双向同步,`colorSlots()` 成为唯一取值处;填充支持**无**(`fill=false`,颜色保留,槽位画灰底红斜杠);画笔/文字/箭头等无填充概念的工具只显示一格(v1.12 起文字改三格) |
|
||||||
| 颜色体系与矢量属性(v1.10) | ✅ v1.10.0:默认值收口到 `TEXT_DEFAULTS`(文字底色去掉纯黑);三个色块标记「生效/未生效」(未生效显示灰色斜纹);对象选中框改实线(虚线只留给像素选区);选区命令归位到矩形/套索选区工具;矢量图形新增独立 `fillColor`,描边色复用主色,选项栏出 `描边 ■ / 填充 ■` 色块,填充缺省跟随描边 |
|
| 颜色体系与矢量属性(v1.10) | ✅ v1.10.0:默认值收口到 `TEXT_DEFAULTS`(文字底色去掉纯黑);三个色块标记「生效/未生效」(未生效显示灰色斜纹);对象选中框改实线(虚线只留给像素选区);选区命令归位到矩形/套索选区工具;矢量图形新增独立 `fillColor`,描边色复用主色,选项栏出 `描边 ■ / 填充 ■` 色块,填充缺省跟随描边 |
|
||||||
| 文字样式与吸附 | ✅ v1.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
|
| 文字样式与吸附 | ✅ v1.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
|
||||||
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.11.0",
|
"version": "1.14.0",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -1458,6 +1458,14 @@
|
|||||||
width: 46px; padding: 2px 4px; background: #313244; color: #e8a735;
|
width: 46px; padding: 2px 4px; background: #313244; color: #e8a735;
|
||||||
border: 1px solid #45475a; border-radius: 5px; text-align: center; font-size: 12px;
|
border: 1px solid #45475a; border-radius: 5px; text-align: center; font-size: 12px;
|
||||||
}
|
}
|
||||||
|
/* 字体下拉:flex:0 0 auto 不能被压 —— 选项文字是 2 个汉字宽,压窄后会被截成「黑…」,
|
||||||
|
用户没法确认自己选的是哪一档。 */
|
||||||
|
.iwb-opt-select {
|
||||||
|
flex: 0 0 auto; padding: 2px 4px; background: #313244; color: #cdd6f4;
|
||||||
|
border: 1px solid #45475a; border-radius: 5px; font-size: 12px; cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-opt-select:hover { background: #45475a; }
|
||||||
|
.iwb-opt-select option { background: #1e1e2e; color: #cdd6f4; }
|
||||||
.iwb-opt-current { color: #e8a735; font-weight: 600; white-space: nowrap; }
|
.iwb-opt-current { color: #e8a735; font-weight: 600; white-space: nowrap; }
|
||||||
/* hint 是「说明」不是「控件」:不许被压缩。
|
/* hint 是「说明」不是「控件」:不许被压缩。
|
||||||
早先带 text-overflow:ellipsis,在 36px 高的选项栏里会被压成「双击改…」这种半截文案,
|
早先带 text-overflow:ellipsis,在 36px 高的选项栏里会被压成「双击改…」这种半截文案,
|
||||||
@@ -1751,6 +1759,27 @@
|
|||||||
}
|
}
|
||||||
.iwb-editor-color-pair[data-color-mode="single"] [data-color-slot="stroke"] i { width: 20px; height: 20px; border-radius: 6px; }
|
.iwb-editor-color-pair[data-color-mode="single"] [data-color-slot="stroke"] i { width: 20px; height: 20px; border-radius: 6px; }
|
||||||
|
|
||||||
|
/* ---- v1.12:文字上下文的第三格「文本框底色」 ----
|
||||||
|
文字对象天生三个颜色(文字 / 描边 / 底色),两格叠放塞不下第三个。
|
||||||
|
文字上下文三格横排,各 18px,谁在调谁戴橙圈。
|
||||||
|
选择器必须带上 .iwb-editor-canvas-wrap > .iwb-editor-tools 前缀:上面那条
|
||||||
|
30px 宽的定位规则是三段选择器,少了前缀优先级压不过它,格子会被挤成 10px。 */
|
||||||
|
.iwb-editor-color-pair [data-color-slot="bg"] { display: none; }
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair[data-color-mode="triple"] {
|
||||||
|
width: 62px; display: flex; align-items: center; justify-content: space-between;
|
||||||
|
}
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair[data-color-mode="triple"] [data-color-slot] {
|
||||||
|
position: relative; left: auto; top: auto; right: auto; bottom: auto; z-index: 1;
|
||||||
|
display: inline-flex; flex: 0 0 auto; width: 18px; height: 18px; border-radius: 5px;
|
||||||
|
}
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair[data-color-mode="triple"] [data-color-slot="bg"] {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair[data-color-mode="triple"] .iwb-editor-color-btn i {
|
||||||
|
width: 11px; height: 11px; border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.iwb-editor-color-pop {
|
.iwb-editor-color-pop {
|
||||||
position: absolute; z-index: 60; display: flex; flex-direction: column; align-items: stretch; gap: 9px;
|
position: absolute; z-index: 60; display: flex; flex-direction: column; align-items: stretch; gap: 9px;
|
||||||
padding: 10px 12px; border-radius: 12px;
|
padding: 10px 12px; border-radius: 12px;
|
||||||
|
|||||||
@@ -31,21 +31,10 @@ import { bindEvents } from './events.js'
|
|||||||
<button class="iwb-editor-action" data-action="redo" title="重做 (Ctrl+Shift+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>
|
<button class="iwb-editor-action" 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"><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>
|
<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>
|
</div>
|
||||||
<span class="iwb-editor-divider"></span>
|
<!-- 顶栏命令带已清空(v1.13):
|
||||||
<!-- 顶栏命令带(v1.2.6):撤销/重做/还原 | 顺序 | 视图;图层新建/导入回图层面板标题栏 -->
|
四个「置顶/上移/下移/置底」按钮删除(图层面板可拖动 + Ctrl+]/[ 已覆盖);
|
||||||
<div class="iwb-editor-commands">
|
「适应窗口 / 收起侧栏」搬到画布底部工具栏最右侧,离画布更近。
|
||||||
<div class="iwb-editor-cmdgroup" data-group="order" title="调整选中元素的图层顺序">
|
整个 .iwb-editor-commands 容器一并移除,不留一条空分隔线。 -->
|
||||||
<button class="iwb-editor-layer-btn" data-layer="top" title="置顶:选中元素移到最上层 (Ctrl+Shift+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="5" x2="20" y2="5"/><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="up" title="上移一层 (Ctrl+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="down" title="下移一层 (Ctrl+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="bottom" title="置底:选中元素移到最下层 (Ctrl+Shift+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/><line x1="4" y1="19" x2="20" y2="19"/></svg></button>
|
|
||||||
</div>
|
|
||||||
<span class="iwb-editor-divider"></span>
|
|
||||||
<div class="iwb-editor-cmdgroup" data-group="view">
|
|
||||||
<button class="iwb-editor-action" data-action="zoomFit" title="适应窗口 (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-export-actions">
|
<div class="iwb-editor-export-actions">
|
||||||
<div class="iwb-editor-export-settings-wrap">
|
<div class="iwb-editor-export-settings-wrap">
|
||||||
@@ -130,20 +119,23 @@ import { bindEvents } from './events.js'
|
|||||||
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-tools">
|
<div class="iwb-editor-tools">
|
||||||
<!-- 颜色(v1.11):描边 + 填充 两个槽叠放在一个按钮位里(PS 式前/背景色)。
|
<!-- 颜色(v1.11 两格 → v1.12 文字三格):
|
||||||
点哪个槽就调哪个:色板只有一套,写谁由 S.colorTarget 决定。
|
形状下是「描边 + 填充」两格叠放在一个按钮位里(PS 式前/背景色);
|
||||||
这样全项目只有「描边色 / 填充色」两个颜色概念,不再有第三个主色。
|
文字下是「文字 / 描边 / 底色」三格横排 —— 文字对象天生就有三个颜色,
|
||||||
填充块在无填充时画斜杠,跟随描边色时带一个小三角角标。 -->
|
只给两格必然有一格无处安放(用户反馈「文本不支持描边与字体色切换」)。
|
||||||
|
点哪格就调哪格:色板只有一套,写谁由 S.colorTarget 决定。
|
||||||
|
关掉的那格画斜杠,跟随描边色的填充块带一个小三角角标。 -->
|
||||||
<div class="iwb-editor-color-pair" data-color-mode="single">
|
<div class="iwb-editor-color-pair" data-color-mode="single">
|
||||||
<button type="button" class="iwb-editor-color-btn" data-color-slot="stroke" data-action="toggleColorPop" aria-expanded="false" title="描边色:形状描边 / 画笔 / 文字都用它。点开色板调色"><i></i></button>
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="stroke" data-action="toggleColorPop" aria-expanded="false" title="描边色:形状描边 / 画笔 / 文字都用它。点开色板调色"><i></i></button>
|
||||||
<button type="button" class="iwb-editor-color-btn" data-color-slot="fill" data-action="toggleColorPop" aria-expanded="false" title="填充色:形状内部颜色。点开色板调色,色板里可切换「无填充」"><i></i></button>
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="fill" data-action="toggleColorPop" aria-expanded="false" title="填充色:形状内部颜色。点开色板调色,色板里可切换「无填充」"><i></i></button>
|
||||||
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="bg" data-action="toggleColorPop" aria-expanded="false" title="文本框底色:垫在文字下面的一块半透明色板。点开调色,可选「无」"><i></i></button>
|
||||||
</div>
|
</div>
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
<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>
|
<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>
|
<span class="iwb-editor-divider"></span>
|
||||||
|
|
||||||
<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="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" data-tool="lasso" title="套索 (A):按住拖动自由圈选,松手闭合"><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="画笔 (B):] 增大 / [ 减小笔刷;按住 Alt 临时吸色"><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):] 增大 / [ 减小笔刷;按住 Alt 临时吸色"><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>
|
||||||
|
|
||||||
@@ -153,11 +145,11 @@ import { bindEvents } from './events.js'
|
|||||||
|
|
||||||
<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="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="矩形 (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="rect" title="矩形 (R):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="圆形 (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="circle" title="圆形 (O):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="箭头 (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="arrow" title="箭头 (L):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="吸管 (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="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>
|
||||||
|
|
||||||
@@ -167,7 +159,11 @@ import { bindEvents } from './events.js'
|
|||||||
|
|
||||||
<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>
|
<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>
|
||||||
|
|
||||||
|
<!-- 视图快捷(v1.13):从顶栏搬过来,贴在工具条最右侧的「|」之后。
|
||||||
|
工具条本身是 shrink-to-fit 且居中,所以这一组天然就是「最右边」。 -->
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
|
<button class="iwb-editor-tool iwb-editor-view-btn" 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-tool iwb-editor-view-btn" 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>
|
</div>
|
||||||
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
||||||
@@ -237,12 +233,13 @@ import { bindEvents } from './events.js'
|
|||||||
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
||||||
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
||||||
<div class="iwb-editor-color-pop" hidden>
|
<div class="iwb-editor-color-pop" hidden>
|
||||||
<!-- 弹层头部(v1.11):标明「现在调的是哪个颜色」,并可直接切换。
|
<!-- 弹层头部(v1.11 两格 → v1.12 文字三格):标明「现在调的是哪个颜色」,
|
||||||
与工具栏那两个色块是同一组槽位,两边高亮完全一致。
|
并可直接切换。与工具栏那几个色块是同一组槽位,两边高亮完全一致。
|
||||||
「无」只对填充有意义:描边关掉会让形状彻底消失,不是用户要的。 -->
|
「无」只对「可以没有」的颜色有意义:文字色没有无,描边/底色/填充才有。 -->
|
||||||
<div class="iwb-color-pop-head">
|
<div class="iwb-color-pop-head">
|
||||||
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
|
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
|
||||||
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
|
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色 / 文字描边色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
|
||||||
|
<button type="button" class="iwb-color-pop-tab" data-color-slot="bg" hidden title="正在调文本框底色(垫在文字下面)"><i></i><span class="iwb-color-pop-tab-label">底色</span></button>
|
||||||
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="无填充:形状内部透明,只留描边"><span></span>无</button>
|
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="无填充:形状内部透明,只留描边"><span></span>无</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-color-pop-body">
|
<div class="iwb-color-pop-body">
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { showSelectionContext, hideSelectionContext } from './floating.js'
|
|||||||
import { applyConstraintDrag, cancelCrop, clearOverlay, confirmCrop, drawCropPreview, hideCropBar, hitCropHandle, insideRect, resizeCropRect, setConstraint, showCropBar, updateCropInfo } from './crop.js'
|
import { applyConstraintDrag, cancelCrop, clearOverlay, confirmCrop, drawCropPreview, hideCropBar, hitCropHandle, insideRect, resizeCropRect, setConstraint, showCropBar, updateCropInfo } from './crop.js'
|
||||||
import { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, otherObjectBoxes, renderObjects, selectNeighborLayer, selectUnit, shapeBounds, showTextInput, textBounds } from './objects.js'
|
import { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, otherObjectBoxes, renderObjects, selectNeighborLayer, selectUnit, shapeBounds, showTextInput, textBounds } from './objects.js'
|
||||||
import { snapMove } from './snap.js'
|
import { snapMove } from './snap.js'
|
||||||
import { TEXT_DEFAULTS, TEXT_LINE_HEIGHT } from './text.js'
|
import { TEXT_DEFAULTS, TEXT_FONTS, TEXT_FONT_KEYS, TEXT_LINE_HEIGHT, fontKeyOf } from './text.js'
|
||||||
import { rememberColor } from './recent-colors.js'
|
import { rememberColor } from './recent-colors.js'
|
||||||
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
|
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
|
||||||
import { close, copyResult, exportResult } from './index.js'
|
import { close, copyResult, exportResult } from './index.js'
|
||||||
@@ -798,7 +798,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
updateBrushUI()
|
updateBrushUI()
|
||||||
updateBrushParamUI()
|
updateBrushParamUI()
|
||||||
updateFillUI()
|
updateFillUI()
|
||||||
updateLayerUI()
|
|
||||||
updateZoomUI()
|
updateZoomUI()
|
||||||
hidePickerTip()
|
hidePickerTip()
|
||||||
runtime.el.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(b => b.classList.remove('active'))
|
runtime.el.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(b => b.classList.remove('active'))
|
||||||
@@ -865,58 +864,112 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 当前上下文里「填充」这个概念到底存不存在。
|
/** 当前颜色上下文(v1.12):决定工具栏给几格颜色、每格叫什么。
|
||||||
|
* 三类:
|
||||||
|
* text —— 文字:文字色 / 描边色 / 文本框底色,天生三个颜色
|
||||||
|
* shape —— 矩形/圆形/钢笔:描边色 + 填充色
|
||||||
|
* strokeOnly —— 画笔/橡皮/箭头/没选中任何东西:只有一格主色
|
||||||
|
* **全项目唯一**判断「现在有几个颜色」的地方,以后要加颜色只改这里。 */
|
||||||
|
function colorContext() {
|
||||||
|
const t = getSelectedText()
|
||||||
|
// 文字工具下即使还没落成对象,也是在调「下一段文字」的三个颜色
|
||||||
|
if (t || S.tool === 'text') return { kind: 'text', text: t || null }
|
||||||
|
const sh = getSelectedShape()
|
||||||
|
if (sh) return { kind: sh.type === 'arrow' ? 'strokeOnly' : 'shape', shape: sh }
|
||||||
|
if (S.tool === 'rect' || S.tool === 'circle' || S.tool === 'pen') return { kind: 'shape', shape: null }
|
||||||
|
return { kind: 'strokeOnly', shape: null }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 第二格(形状的填充 / 文字的描边)在当前上下文里到底存不存在。
|
||||||
* 箭头只有一条线没有内部;未闭合的钢笔路径也没有可填面积 —— 这两种情况
|
* 箭头只有一条线没有内部;未闭合的钢笔路径也没有可填面积 —— 这两种情况
|
||||||
* 不该给填充色块,否则用户设了颜色画面上没有任何变化,又是一次「坏了」。 */
|
* 不该给填充色块,否则用户设了颜色画面上没有任何变化,又是一次「坏了」。 */
|
||||||
function fillSlotOn() {
|
function fillSlotOn() {
|
||||||
const sh = getSelectedShape()
|
const ctx = colorContext()
|
||||||
if (sh) return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
if (ctx.kind === 'text') return true
|
||||||
return S.tool === 'rect' || S.tool === 'circle' || S.tool === 'pen'
|
if (ctx.kind !== 'shape') return false
|
||||||
|
const sh = ctx.shape
|
||||||
|
if (!sh) return true
|
||||||
|
return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 描边 / 填充两个槽的显示值(v1.11)。
|
/** 文字的三个颜色槽(v1.12)。
|
||||||
|
* 文字对象本来就有三个颜色字段:color(文字本身)/ strokeColor(字的外描边)/
|
||||||
|
* bgColor(文本框底色)。上一版把它们硬塞进「描边 / 填充」两格,第二格其实是
|
||||||
|
* 形状的填充色,选中文字后点它没有任何反应 —— 用户说的「文本不支持描边与
|
||||||
|
* 字体色切换」就是这么来的。这里把三个颜色各自摆开,各自可点。 */
|
||||||
|
function textColorSlots(t) {
|
||||||
|
const color = (t ? t.color : S.color) || S.color
|
||||||
|
const strokeColor = ((t ? t.strokeColor : S.textStrokeColor) || TEXT_DEFAULTS.strokeColor)
|
||||||
|
const sw = Number(t ? t.strokeWidth : S.textStrokeWidth) || 0
|
||||||
|
const bgColor = ((t ? t.bgColor : S.textBgColor) || TEXT_DEFAULTS.bgColor)
|
||||||
|
const bgFill = !!(t ? t.bgFill : S.textBgFill)
|
||||||
|
const bgAlpha = Number(t
|
||||||
|
? (t.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : t.bgAlpha)
|
||||||
|
: S.textBgAlpha) || TEXT_DEFAULTS.bgAlpha
|
||||||
|
return {
|
||||||
|
mode: 'text',
|
||||||
|
stroke: color, fill: strokeColor, fillOn: sw > 0, follow: false,
|
||||||
|
bg: bgColor, bgOn: bgFill, bgAlpha,
|
||||||
|
strokeName: '文字', fillName: '描边', bgName: '底色'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 三个颜色槽的显示值(v1.11 起是两格,v1.12 起文字多一格底色)。
|
||||||
* **唯一的取值处**:工具栏色块、色板头部、hex、SV 调色器全从这里读,
|
* **唯一的取值处**:工具栏色块、色板头部、hex、SV 调色器全从这里读,
|
||||||
* 避免「一个概念三种颜色」再次出现。
|
* 避免「一个概念三种颜色」再次出现。
|
||||||
* 描边 = 主色(选中形状时读它自己的);填充 = 形状自己的 fillColor,
|
* 文字:stroke=文字色 / fill=描边色 / bg=底色;
|
||||||
* 没单独设过(null)就跟随描边色,此时 follow=true。 */
|
* 形状:stroke=描边色 / fill=填充色(没单独设过就跟随描边色,follow=true)。 */
|
||||||
export function colorSlots() {
|
export function colorSlots() {
|
||||||
const sh = getSelectedShape()
|
const ctx = colorContext()
|
||||||
|
if (ctx.kind === 'text') return textColorSlots(ctx.text)
|
||||||
|
const sh = ctx.shape
|
||||||
const stroke = (sh && sh.color) || S.color
|
const stroke = (sh && sh.color) || S.color
|
||||||
const rawFill = sh ? (sh.fillColor || null) : S.shapeFillColor
|
const rawFill = sh ? (sh.fillColor || null) : S.shapeFillColor
|
||||||
const fillOn = sh
|
const fillOn = sh
|
||||||
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
|
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
|
||||||
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
|
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
|
||||||
return { stroke, fill: rawFill || stroke, fillOn, follow: !rawFill }
|
return {
|
||||||
|
mode: ctx.kind === 'shape' ? 'shape' : 'single',
|
||||||
|
stroke, fill: rawFill || stroke, fillOn, follow: !rawFill,
|
||||||
|
bg: null, bgOn: false, bgAlpha: 1,
|
||||||
|
strokeName: '描边', fillName: '填充', bgName: '底色'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 色板/hex/吸管要写的那一格颜色 */
|
/** 色板/hex/吸管要写的那一格颜色 */
|
||||||
function activeColor() {
|
function activeColor() {
|
||||||
const sl = colorSlots()
|
const sl = colorSlots()
|
||||||
return S.colorTarget === 'fill' ? sl.fill : sl.stroke
|
if (S.colorTarget === 'bg') return sl.bg || sl.stroke
|
||||||
|
if (S.colorTarget === 'fill' && fillSlotOn()) return sl.fill || sl.stroke
|
||||||
|
return sl.stroke
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateColorUI() {
|
export function updateColorUI() {
|
||||||
const sl = colorSlots()
|
const sl = colorSlots()
|
||||||
const fillable = fillSlotOn()
|
const isText = sl.mode === 'text'
|
||||||
// 当前上下文没有填充(切到画笔/文字/箭头,或选中了箭头):把「正在调填充」的状态
|
const second = isText ? true : fillSlotOn()
|
||||||
// 归位,否则工具栏会高亮一个已经隐藏的槽,色板也停在一个不存在的目标上。
|
// 当前正在调的那一格在新上下文里不存在(比如调着「底色」时切回画笔),
|
||||||
if (!fillable && S.colorTarget === 'fill') S.colorTarget = 'stroke'
|
// 就把目标归位,否则工具栏会高亮一个已经隐藏的格子,色板也停在不存在的目标上。
|
||||||
// 工具栏:两个槽都按真实值上色,填充关掉时画斜杠、跟随描边时带角标
|
if (S.colorTarget !== 'stroke' && !second) S.colorTarget = 'stroke'
|
||||||
|
if (S.colorTarget === 'bg' && !isText) S.colorTarget = 'stroke'
|
||||||
|
// 工具栏:三格(文字)/ 两格(形状)/ 一格(只有主色)
|
||||||
const pair = runtime.el.querySelector('.iwb-editor-color-pair')
|
const pair = runtime.el.querySelector('.iwb-editor-color-pair')
|
||||||
if (pair) pair.dataset.colorMode = fillable ? 'pair' : 'single'
|
if (pair) pair.dataset.colorMode = isText ? 'triple' : (second ? 'pair' : 'single')
|
||||||
const strokeBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="stroke"]')
|
const strokeBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="stroke"]')
|
||||||
const fillBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="fill"]')
|
const fillBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="fill"]')
|
||||||
// 同一个槽在不同工具下叫法不同:调文字时它改的是文字色,调画笔时是画笔色。
|
const bgBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="bg"]')
|
||||||
|
// 同一个格子在不同上下文里名字不同:文字下第一格是「文字色」,画笔下是「画笔色」。
|
||||||
// 一律写「描边」会让人在文字工具下以为这个颜色跟文字没关系。
|
// 一律写「描边」会让人在文字工具下以为这个颜色跟文字没关系。
|
||||||
const textCtx = S.tool === 'text' || (!!S.selectedTextId && S.tool === 'select')
|
const strokeName = isText ? '文字' : (S.tool === 'brush' || S.tool === 'eraser' ? '画笔' : '描边')
|
||||||
const strokeName = textCtx ? '文字' : (S.tool === 'brush' || S.tool === 'eraser' ? '画笔' : '描边')
|
|
||||||
if (strokeBtn) {
|
if (strokeBtn) {
|
||||||
const dot = strokeBtn.querySelector('i')
|
const dot = strokeBtn.querySelector('i')
|
||||||
if (dot) dot.style.backgroundColor = sl.stroke
|
if (dot) dot.style.backgroundColor = sl.stroke
|
||||||
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
||||||
strokeBtn.title = fillable
|
strokeBtn.title = isText
|
||||||
? `描边色 ${sl.stroke.toUpperCase()}:形状描边也用这个值。点开色板调色`
|
? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)`
|
||||||
: `${strokeName}色 ${sl.stroke.toUpperCase()}:点开色板调色`
|
: (second
|
||||||
|
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色`
|
||||||
|
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`)
|
||||||
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
|
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
||||||
}
|
}
|
||||||
@@ -926,26 +979,63 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
fillBtn.classList.toggle('is-none', !sl.fillOn)
|
fillBtn.classList.toggle('is-none', !sl.fillOn)
|
||||||
fillBtn.classList.toggle('is-follow', sl.follow && sl.fillOn)
|
fillBtn.classList.toggle('is-follow', sl.follow && sl.fillOn)
|
||||||
fillBtn.classList.toggle('active', S.colorTarget === 'fill')
|
fillBtn.classList.toggle('active', S.colorTarget === 'fill')
|
||||||
fillBtn.title = !sl.fillOn
|
const fc = String(sl.fill).toUpperCase()
|
||||||
? '填充:无(形状内部透明)。点开色板选色即可填充'
|
fillBtn.title = isText
|
||||||
: (sl.follow ? '填充色:跟随描边色 ' + sl.fill.toUpperCase() + ',点开可单独指定' : '填充色 ' + sl.fill.toUpperCase() + ',点开调色')
|
? (sl.fillOn
|
||||||
|
? `文字描边色 ${fc}:沿字形外沿描一圈。点开调色,「无」= 去掉描边`
|
||||||
|
: '文字描边:无(描边宽度 0)。点开选色会自动给 6px 描边')
|
||||||
|
: (!sl.fillOn
|
||||||
|
? '填充:无(形状内部透明)。点开色板选色即可填充'
|
||||||
|
: (sl.follow ? '填充色:跟随描边色 ' + fc + ',点开可单独指定' : '填充色 ' + fc + ',点开调色'))
|
||||||
}
|
}
|
||||||
// 色板头部:两个 tab 与工具栏两个槽同步高亮,「无」只在调填充时出现
|
if (bgBtn) {
|
||||||
|
const dot = bgBtn.querySelector('i')
|
||||||
|
if (dot) {
|
||||||
|
dot.style.backgroundColor = sl.bg || 'transparent'
|
||||||
|
// 底色是半透明的:色块按真实不透明度显示,否则看起来像一块实心色
|
||||||
|
dot.style.opacity = sl.bgOn ? String(sl.bgAlpha) : ''
|
||||||
|
}
|
||||||
|
bgBtn.classList.toggle('is-none', !sl.bgOn)
|
||||||
|
bgBtn.classList.toggle('active', S.colorTarget === 'bg')
|
||||||
|
bgBtn.title = sl.bgOn
|
||||||
|
? `文本框底色 ${String(sl.bg || '').toUpperCase()}(${Math.round(sl.bgAlpha * 100)}% 不透明):垫在文字下面,「无」= 去掉底色`
|
||||||
|
: '文本框底色:无(透明)。点开选色会自动开启底色'
|
||||||
|
bgBtn.setAttribute('aria-expanded', String(!!(runtime.el.querySelector('.iwb-editor-color-pop:not([hidden])') && S.colorTarget === 'bg')))
|
||||||
|
}
|
||||||
|
// 色板头部:tab 与工具栏的格子一一对应,谁在调谁高亮
|
||||||
runtime.el.querySelectorAll('.iwb-color-pop-tab').forEach(tab => {
|
runtime.el.querySelectorAll('.iwb-color-pop-tab').forEach(tab => {
|
||||||
const isFill = tab.dataset.colorSlot === 'fill'
|
const slot = tab.dataset.colorSlot
|
||||||
tab.classList.toggle('active', S.colorTarget === (isFill ? 'fill' : 'stroke'))
|
const isFill = slot === 'fill'
|
||||||
|
const isBg = slot === 'bg'
|
||||||
|
tab.classList.toggle('active', S.colorTarget === slot)
|
||||||
const dot = tab.querySelector('i')
|
const dot = tab.querySelector('i')
|
||||||
if (dot) dot.style.backgroundColor = isFill ? sl.fill : sl.stroke
|
if (dot) {
|
||||||
|
dot.style.backgroundColor = isBg ? (sl.bg || 'transparent') : (isFill ? sl.fill : sl.stroke)
|
||||||
|
if (isBg) dot.style.opacity = sl.bgOn ? String(sl.bgAlpha) : ''
|
||||||
|
}
|
||||||
const label = tab.querySelector('.iwb-color-pop-tab-label')
|
const label = tab.querySelector('.iwb-color-pop-tab-label')
|
||||||
// 只有一根槽时,标题写「描边」会显得莫名其妙:这时它就是当前的唯一颜色
|
// 只有一根槽时,标题写「描边」会显得莫名其妙:这时它就是当前的唯一颜色
|
||||||
if (label) label.textContent = isFill ? '填充' : (fillable ? '描边' : strokeName)
|
if (label) label.textContent = isBg ? '底色' : (isFill ? (isText ? '描边' : '填充') : strokeName)
|
||||||
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !fillable }
|
tab.title = isBg
|
||||||
|
? '正在调文本框底色(垫在文字下面)'
|
||||||
|
: (isFill
|
||||||
|
? (isText ? '正在调文字描边色(沿字形外沿)' : '正在调填充色(形状内部颜色)')
|
||||||
|
: (isText ? '正在调文字色(文字本身的颜色)' : '正在调描边色'))
|
||||||
|
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !second }
|
||||||
|
if (isBg) { tab.classList.toggle('is-none', !sl.bgOn); tab.hidden = !isText }
|
||||||
})
|
})
|
||||||
|
// 「无」:形状 = 无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
||||||
|
// (文字色没有「无」—— 字没有颜色就等于把字删了,不该给这个按钮)
|
||||||
const noneBtn = runtime.el.querySelector('[data-color-none]')
|
const noneBtn = runtime.el.querySelector('[data-color-none]')
|
||||||
if (noneBtn) {
|
if (noneBtn) {
|
||||||
const show = fillable && S.colorTarget === 'fill'
|
const onBg = S.colorTarget === 'bg' && isText
|
||||||
|
const onFill = S.colorTarget === 'fill' && second
|
||||||
|
const show = onBg || onFill
|
||||||
noneBtn.hidden = !show
|
noneBtn.hidden = !show
|
||||||
noneBtn.classList.toggle('active', show && !sl.fillOn)
|
noneBtn.classList.toggle('active', show && (onBg ? !sl.bgOn : !sl.fillOn))
|
||||||
|
noneBtn.title = onBg
|
||||||
|
? '无底色:文字后面完全透明'
|
||||||
|
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边')
|
||||||
}
|
}
|
||||||
|
|
||||||
const cur = activeColor()
|
const cur = activeColor()
|
||||||
@@ -994,13 +1084,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (b) b.classList.toggle('active', !!S.rectFill)
|
if (b) b.classList.toggle('active', !!S.rectFill)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 图层按钮可用态:有选中元素才可用 */
|
|
||||||
export function updateLayerUI() {
|
|
||||||
const hasSel = !!(S.selectedTextId || S.selectedShapeId || S.layers.some(l => l.id === S.selectedLayerId && l.id !== 'base' && !l.locked))
|
|
||||||
runtime.el.querySelectorAll('.iwb-editor-layer-btn').forEach(b => {
|
|
||||||
b.disabled = !hasSel
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ 便利版 UI:就地选项栏 / 状态栏 / 更多菜单 ============
|
// ============ 便利版 UI:就地选项栏 / 状态栏 / 更多菜单 ============
|
||||||
|
|
||||||
@@ -1080,8 +1163,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const own = !!sh && (owner === 'pen' ? sh.type === 'pen' : (sh.type === 'rect' || sh.type === 'circle'))
|
const own = !!sh && (owner === 'pen' ? sh.type === 'pen' : (sh.type === 'rect' || sh.type === 'circle'))
|
||||||
const fill = own ? !!sh.fill : (owner === 'pen' ? S.penFill : S.rectFill)
|
const fill = own ? !!sh.fill : (owner === 'pen' ? S.penFill : S.rectFill)
|
||||||
return `<span class="iwb-opt-label">样式</span>
|
return `<span class="iwb-opt-label">样式</span>
|
||||||
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边 (Shift+X 切换)">描边</button>
|
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边:内部透明,只留描边(快捷键 Shift+X 是交换填充/描边色)">描边</button>
|
||||||
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`
|
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充:内部用填充色(快捷键 Shift+X 是交换填充/描边色)">实心</button>`
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
|
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
|
||||||
@@ -1090,7 +1173,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
// 控件既作用于「当前选中的文字」,也写回「新建文字的默认值」:
|
// 控件既作用于「当前选中的文字」,也写回「新建文字的默认值」:
|
||||||
// 没选中时光调参数就是调下一次输入的样子,选中后调则立刻改这一段。
|
// 没选中时光调参数就是调下一次输入的样子,选中后调则立刻改这一段。
|
||||||
const TEXT_STYLE_STATE_KEY = {
|
const TEXT_STYLE_STATE_KEY = {
|
||||||
fontWeight: 'textWeight', align: 'textAlign', lineHeight: 'textLineHeight',
|
fontWeight: 'textWeight', fontFamily: 'textFamily', align: 'textAlign', lineHeight: 'textLineHeight',
|
||||||
strokeWidth: 'textStrokeWidth', strokeColor: 'textStrokeColor',
|
strokeWidth: 'textStrokeWidth', strokeColor: 'textStrokeColor',
|
||||||
bgFill: 'textBgFill', bgColor: 'textBgColor'
|
bgFill: 'textBgFill', bgColor: 'textBgColor'
|
||||||
}
|
}
|
||||||
@@ -1103,6 +1186,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
|
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
|
||||||
|
// 字体走 fontKeyOf 收敛:老对象没有 fontFamily,或存了不认识的 key,都落回默认黑体
|
||||||
|
fontFamily: fontKeyOf({ fontFamily: pick('fontFamily', 'textFamily', 'sans') }),
|
||||||
align: pick('align', 'textAlign', 'left'),
|
align: pick('align', 'textAlign', 'left'),
|
||||||
lineHeight: Number(pick('lineHeight', 'textLineHeight', TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
lineHeight: Number(pick('lineHeight', 'textLineHeight', TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
||||||
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', TEXT_DEFAULTS.strokeWidth)) || 0),
|
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', TEXT_DEFAULTS.strokeWidth)) || 0),
|
||||||
@@ -1120,6 +1205,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const aBtn = (val, label, title) =>
|
const aBtn = (val, label, title) =>
|
||||||
`<button class="iwb-opt-btn${v.align === val ? ' active' : ''}" data-opt-text="align" data-value="${val}" title="${title}">${label}</button>`
|
`<button class="iwb-opt-btn${v.align === val ? ' active' : ''}" data-opt-text="align" data-value="${val}" title="${title}">${label}</button>`
|
||||||
return `<span class="iwb-opt-sep"></span>
|
return `<span class="iwb-opt-sep"></span>
|
||||||
|
<span class="iwb-opt-label">字体</span>
|
||||||
|
<select class="iwb-opt-select" data-opt-text="fontFamily" title="字体:改选中的这段文字,同时作为下一段新文字的默认字体">${TEXT_FONT_KEYS.map(k =>
|
||||||
|
`<option value="${k}"${v.fontFamily === k ? ' selected' : ''}>${TEXT_FONTS[k].label}</option>`).join('')}</select>
|
||||||
<span class="iwb-opt-label">字重</span>${wBtn('normal', '常规', '常规字重')}${wBtn('bold', '粗', '粗体(默认)')}${wBtn('900', '特粗', '特粗,封面标题用')}
|
<span class="iwb-opt-label">字重</span>${wBtn('normal', '常规', '常规字重')}${wBtn('bold', '粗', '粗体(默认)')}${wBtn('900', '特粗', '特粗,封面标题用')}
|
||||||
<span class="iwb-opt-label">对齐</span>${aBtn('left', '左', '多行时按左缘对齐')}${aBtn('center', '中', '多行时居中')}${aBtn('right', '右', '多行时按右缘对齐')}
|
<span class="iwb-opt-label">对齐</span>${aBtn('left', '左', '多行时按左缘对齐')}${aBtn('center', '中', '多行时居中')}${aBtn('right', '右', '多行时按右缘对齐')}
|
||||||
<span class="iwb-opt-label">行距</span>
|
<span class="iwb-opt-label">行距</span>
|
||||||
@@ -1176,7 +1264,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
return `<span class="iwb-opt-current">已选中:文字</span>`
|
return `<span class="iwb-opt-current">已选中:文字</span>`
|
||||||
+ rangeOpt('textSize', '字号', 8, 400, Math.round(text.fontSize || S.textSize), 'px')
|
+ rangeOpt('textSize', '字号', 8, 400, Math.round(text.fontSize || S.textSize), 'px')
|
||||||
+ textStyleHTML(text)
|
+ textStyleHTML(text)
|
||||||
+ '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>'
|
+ '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放 · 左上三格 = 文字色 / 描边 / 底色</span>'
|
||||||
}
|
}
|
||||||
// 选区命令是全局的,跟「有没有选中元素」无关:没选中时也必须能全选/反选/取消。
|
// 选区命令是全局的,跟「有没有选中元素」无关:没选中时也必须能全选/反选/取消。
|
||||||
// 关键是必须排在 hint **之前** —— hint 带 margin-left:auto,放它后面会被一路
|
// 关键是必须排在 hint **之前** —— hint 带 margin-left:auto,放它后面会被一路
|
||||||
@@ -1405,6 +1493,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
let value = raw
|
let value = raw
|
||||||
// data-value 是字符串:'0' 也是真值,必须显式判,不能直接 !!raw
|
// data-value 是字符串:'0' 也是真值,必须显式判,不能直接 !!raw
|
||||||
if (key === 'bgFill') value = raw === true || raw === 1 || raw === '1' || raw === 'true'
|
if (key === 'bgFill') value = raw === true || raw === 1 || raw === '1' || raw === 'true'
|
||||||
|
// 字体只收已知 key:下拉理论上不会给出脏值,但快捷键/外部调用可能,收敛一次更安全
|
||||||
|
else if (key === 'fontFamily') value = fontKeyOf({ fontFamily: raw })
|
||||||
else if (key === 'lineHeight') value = clamp(Number(raw) || 125, 80, 300) / 100
|
else if (key === 'lineHeight') value = clamp(Number(raw) || 125, 80, 300) / 100
|
||||||
else if (key === 'strokeWidth') value = clamp(Number(raw) || 0, 0, 40)
|
else if (key === 'strokeWidth') value = clamp(Number(raw) || 0, 0, 40)
|
||||||
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase()
|
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase()
|
||||||
@@ -1440,6 +1530,56 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (committed) radiusSnapDone = false
|
if (committed) radiusSnapDone = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let textColorSnapDone = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文字描边色 / 底色(v1.12):工具栏三格、色板 tab、色板调色器、吸管、推荐色
|
||||||
|
* 全部走这一条写回路径,与选项栏那两个原生色块(applyTextStyle)改的是同一份值。
|
||||||
|
* 与 applyTextStyle 分开的原因只有一个:色板里拖 SV 会每帧调用,需要
|
||||||
|
* skipHistory 支持(拖动开始由调用方拍一张快照,之后每帧只改对象)。
|
||||||
|
*/
|
||||||
|
function applyTextColor(key, color, opts) {
|
||||||
|
const skipHistory = !!(opts && opts.skipHistory)
|
||||||
|
const stateKey = TEXT_STYLE_STATE_KEY[key]
|
||||||
|
if (!stateKey) return
|
||||||
|
const hex = String(color || '').toLowerCase()
|
||||||
|
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
||||||
|
if (!skipHistory) rememberColor(hex)
|
||||||
|
S[stateKey] = hex
|
||||||
|
// 颜色选好了但画面上什么都不变(描边宽 0 / 底色没开)会被当成「颜色坏了」:
|
||||||
|
// 顺手把开关打开,所见即所得。
|
||||||
|
if (key === 'strokeColor' && !(Number(S.textStrokeWidth) > 0)) S.textStrokeWidth = 6
|
||||||
|
if (key === 'bgColor' && !S.textBgFill) S.textBgFill = true
|
||||||
|
|
||||||
|
const t = getSelectedText()
|
||||||
|
if (t && !t.locked) {
|
||||||
|
if (!skipHistory && !textColorSnapDone) { saveSnapshot('文字颜色'); textColorSnapDone = true }
|
||||||
|
t[key] = hex
|
||||||
|
if (key === 'strokeColor' && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth
|
||||||
|
if (key === 'bgColor' && !t.bgFill) t.bgFill = true
|
||||||
|
renderObjects()
|
||||||
|
}
|
||||||
|
updateColorUI()
|
||||||
|
if (skipHistory) { syncOptionBarSoon(); return }
|
||||||
|
textColorSnapDone = false
|
||||||
|
syncOptionBar()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派):
|
||||||
|
* 形状填充 → 内部透明;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
||||||
|
* 三种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
||||||
|
function applyColorNone() {
|
||||||
|
const sl = colorSlots()
|
||||||
|
if (sl.mode === 'text') {
|
||||||
|
if (S.colorTarget === 'bg') applyTextStyle('bgFill', '0', true)
|
||||||
|
else if (S.colorTarget === 'fill') applyTextStyle('strokeWidth', 0, true)
|
||||||
|
updateColorUI()
|
||||||
|
syncOptionBar()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
applyShapeColor('none')
|
||||||
|
}
|
||||||
|
|
||||||
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
|
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
|
||||||
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
||||||
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
||||||
@@ -1498,6 +1638,16 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
* 「填充」只能从选项栏那个小色块改 —— 用户看到的就是「三个地方调色,
|
* 「填充」只能从选项栏那个小色块改 —— 用户看到的就是「三个地方调色,
|
||||||
* 有一处跟别处不通」。现在按 S.colorTarget 分派,色板调到哪一格就是哪一格。 */
|
* 有一处跟别处不通」。现在按 S.colorTarget 分派,色板调到哪一格就是哪一格。 */
|
||||||
function applyPanelColor(color, opts) {
|
function applyPanelColor(color, opts) {
|
||||||
|
const sl = colorSlots()
|
||||||
|
// 文字:三格各自写自己的字段。第一格(文字色)就是主色,走 applyColorChange。
|
||||||
|
if (sl.mode === 'text') {
|
||||||
|
if (S.colorTarget === 'fill') { applyTextColor('strokeColor', color, opts); return }
|
||||||
|
if (S.colorTarget === 'bg') { applyTextColor('bgColor', color, opts); return }
|
||||||
|
applyColorChange(color, opts)
|
||||||
|
if (opts && opts.skipHistory) syncOptionBarSoon()
|
||||||
|
else syncOptionBar()
|
||||||
|
return
|
||||||
|
}
|
||||||
if (S.colorTarget === 'fill' && fillSlotOn()) { applyShapeColor('fill', color, opts); return }
|
if (S.colorTarget === 'fill' && fillSlotOn()) { applyShapeColor('fill', color, opts); return }
|
||||||
if (S.colorTarget === 'fill') S.colorTarget = 'stroke' // 当前没有填充语义:退回描边,别让调色静默失效
|
if (S.colorTarget === 'fill') S.colorTarget = 'stroke' // 当前没有填充语义:退回描边,别让调色静默失效
|
||||||
applyColorChange(color, opts)
|
applyColorChange(color, opts)
|
||||||
@@ -1505,9 +1655,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
else syncOptionBar()
|
else syncOptionBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 切换色板正在编辑哪一格(工具栏两个色块 / 色板头部两个 tab 共用) */
|
/** 切换色板正在编辑哪一格(工具栏色块 / 色板头部 tab 共用) */
|
||||||
function setColorTarget(slot) {
|
function setColorTarget(slot) {
|
||||||
S.colorTarget = slot === 'fill' ? 'fill' : 'stroke'
|
S.colorTarget = slot === 'fill' ? 'fill' : (slot === 'bg' ? 'bg' : 'stroke')
|
||||||
updateColorUI()
|
updateColorUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1543,6 +1693,29 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** PS 的 X 语义(v1.13.1):把选中形状的「填充色」与「描边色」对调。
|
||||||
|
* 以前 Shift+X 绑的是「实心 ↔ 只描边」开关 —— 按下去填充被关掉、描边纹丝不动,
|
||||||
|
* 用户的主观体验就是「填充色丢了」,再按一次才回来。用户要的是**交换两个颜色**:
|
||||||
|
* 填充色换到描边的位置、描边色换到填充的位置,填充的开关状态不变(交换的是颜色,不是有无)。
|
||||||
|
* 填充色仍「跟随描边色」(fillColor=null)时只有一个颜色,没有可交换的对象,只提示不动数据。 */
|
||||||
|
function swapShapeColors() {
|
||||||
|
const sh = getSelectedShape()
|
||||||
|
if (!sh || sh.locked) return false
|
||||||
|
if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true }
|
||||||
|
const stroke = sh.color || S.color
|
||||||
|
const fill = sh.fillColor || null
|
||||||
|
if (!fill) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
||||||
|
saveSnapshot('交换填充与描边色')
|
||||||
|
sh.color = fill
|
||||||
|
S.color = fill // 描边色与主色永远同一份(v1.10 的约定)
|
||||||
|
sh.fillColor = stroke
|
||||||
|
S.shapeFillColor = stroke // 交换后就是独立填充色了,不再跟随描边
|
||||||
|
renderObjects()
|
||||||
|
updateColorUI()
|
||||||
|
syncOptionBar()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
function setOptionFromControl(el, committed) {
|
function setOptionFromControl(el, committed) {
|
||||||
const key = el && el.dataset ? el.dataset.opt : ''
|
const key = el && el.dataset ? el.dataset.opt : ''
|
||||||
if (!key) return
|
if (!key) return
|
||||||
@@ -1655,26 +1828,49 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const body = root.querySelector('.iwb-editor-optionbar-body')
|
const body = root.querySelector('.iwb-editor-optionbar-body')
|
||||||
if (body) {
|
if (body) {
|
||||||
body.addEventListener('mousedown', (e) => e.stopPropagation())
|
body.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
|
// 原生 <input type="color"> 在系统取色器里连续拖色时只会派发 input,关闭取色器才派发 change。
|
||||||
|
// 以前只接 change,于是「取色器开着的整段时间画布一动不动,松手才变色」——用户说的
|
||||||
|
// 「填充色不能实时在矢量图形上显示颜色变化」就是这个(v1.13 修)。
|
||||||
|
// 现在:input = 实时预览(首帧拍一次快照,避免拖一路存几百张全画质快照),
|
||||||
|
// change = 收尾(补记「最近使用」、把选项栏刷干净)。
|
||||||
|
let nativeColorSnapped = false
|
||||||
|
const nativeColorOf = (t) => (t && t.closest ? (t.closest('[data-shape-color]') || t.closest('[data-opt-color]')) : null)
|
||||||
|
const applyNativeColor = (el, preview) => {
|
||||||
|
const isShape = el.hasAttribute('data-shape-color')
|
||||||
|
const key = isShape ? el.dataset.shapeColor : el.dataset.optColor
|
||||||
|
if (!nativeColorSnapped) {
|
||||||
|
const t = getSelectedText(), sh = getSelectedShape()
|
||||||
|
if ((t && !t.locked) || (sh && !sh.locked)) {
|
||||||
|
saveSnapshot(isShape ? '填充颜色' : '文字颜色')
|
||||||
|
nativeColorSnapped = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 预览阶段统一 skipHistory:快照已在上面拍过,不能每帧再拍
|
||||||
|
if (isShape) applyShapeColor(key, el.value, { skipHistory: true })
|
||||||
|
else applyTextColor(key, el.value, { skipHistory: true })
|
||||||
|
if (preview) { syncOptionBarSoon(); return }
|
||||||
|
if (nativeColorSnapped) rememberColor(String(el.value || '').toLowerCase())
|
||||||
|
nativeColorSnapped = false
|
||||||
|
syncOptionBar()
|
||||||
|
}
|
||||||
// 滑杆拖动中(input)与松手/失焦(change)走同一条写回路径,
|
// 滑杆拖动中(input)与松手/失焦(change)走同一条写回路径,
|
||||||
// committed 只决定「要不要顺手记一步历史」,不影响参数生效。
|
// committed 只决定「要不要顺手记一步历史」,不影响参数生效。
|
||||||
body.addEventListener('input', (e) => setOptionFromControl(e.target, false))
|
body.addEventListener('input', (e) => {
|
||||||
|
const colorEl = nativeColorOf(e.target)
|
||||||
|
if (colorEl) { e.stopPropagation(); applyNativeColor(colorEl, true); return }
|
||||||
|
setOptionFromControl(e.target, false)
|
||||||
|
})
|
||||||
body.addEventListener('change', (e) => {
|
body.addEventListener('change', (e) => {
|
||||||
// 原生颜色框:拖动时只派发 input、关闭取色器才派发 change。
|
// 字体下拉:唯一走 change 而不是 click 的文字样式控件(<select> 没有 click 语义)
|
||||||
// 只认 change,保证「改一次颜色 = 一步撤销」,不在拖动途中连拍快照。
|
const textSel = e.target && e.target.closest ? e.target.closest('select[data-opt-text]') : null
|
||||||
const colorEl = e.target.closest ? e.target.closest('[data-opt-color]') : null
|
if (textSel) {
|
||||||
if (colorEl) {
|
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
applyTextStyle(colorEl.dataset.optColor, colorEl.value, true)
|
applyTextStyle(textSel.dataset.optText, textSel.value, true)
|
||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 矢量图形的描边/填充色块(原生取色器关闭时才派发 change)
|
const colorEl = nativeColorOf(e.target)
|
||||||
const shapeColorEl = e.target.closest ? e.target.closest('[data-shape-color]') : null
|
if (colorEl) { e.stopPropagation(); applyNativeColor(colorEl, false); return }
|
||||||
if (shapeColorEl) {
|
|
||||||
e.stopPropagation()
|
|
||||||
applyShapeColor(shapeColorEl.dataset.shapeColor, shapeColorEl.value)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setOptionFromControl(e.target, true)
|
setOptionFromControl(e.target, true)
|
||||||
})
|
})
|
||||||
body.addEventListener('click', (e) => {
|
body.addEventListener('click', (e) => {
|
||||||
@@ -1785,7 +1981,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
bindColorPanel()
|
bindColorPanel()
|
||||||
bindColorPalette()
|
bindColorPalette()
|
||||||
bindFillToggle()
|
bindFillToggle()
|
||||||
bindLayerOrderButtons()
|
|
||||||
bindZoomButtons()
|
bindZoomButtons()
|
||||||
bindHistoryActions()
|
bindHistoryActions()
|
||||||
bindLayerAddActions()
|
bindLayerAddActions()
|
||||||
@@ -1841,7 +2036,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
function toggleColorPop(slot) {
|
function toggleColorPop(slot) {
|
||||||
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
if (!pop) return
|
if (!pop) return
|
||||||
const want = slot === 'fill' ? 'fill' : 'stroke'
|
const want = slot === 'fill' ? 'fill' : (slot === 'bg' ? 'bg' : 'stroke')
|
||||||
if (!pop.hidden && S.colorTarget === want) { closeColorPop(); return }
|
if (!pop.hidden && S.colorTarget === want) { closeColorPop(); return }
|
||||||
S.colorTarget = want
|
S.colorTarget = want
|
||||||
if (pop.hidden) {
|
if (pop.hidden) {
|
||||||
@@ -1887,7 +2082,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const none = e.target.closest('[data-color-none]')
|
const none = e.target.closest('[data-color-none]')
|
||||||
if (none) {
|
if (none) {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
applyShapeColor('none')
|
applyColorNone()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -2017,15 +2212,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 图层顺序调节按钮(上移/下移/置顶/置底) */
|
|
||||||
function bindLayerOrderButtons() {
|
|
||||||
// 图层顺序调节
|
|
||||||
runtime.el.querySelectorAll('.iwb-editor-layer-btn').forEach(btn => {
|
|
||||||
btn.addEventListener('mousedown', (e) => e.stopPropagation())
|
|
||||||
btn.addEventListener('click', () => moveLayer(btn.dataset.layer))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 缩放按钮:缩小 / 放大 / 适应窗口 */
|
/** 缩放按钮:缩小 / 放大 / 适应窗口 */
|
||||||
function bindZoomButtons() {
|
function bindZoomButtons() {
|
||||||
// 缩放按钮
|
// 缩放按钮
|
||||||
@@ -2367,11 +2553,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const key = String(e.key || '').toLowerCase()
|
const key = String(e.key || '').toLowerCase()
|
||||||
|
|
||||||
// ================= PS 同款快捷键 =================
|
// ================= PS 同款快捷键 =================
|
||||||
// 无修饰键:工具(V 移动 / M 选框 / L 套索 / B 画笔 / E 橡皮 / P 钢笔 / T 文字 / U 形状 / C 裁剪 / I 吸管 / H 抓手)
|
// 无修饰键:工具(V 移动 / M 选框 / A 套索 / B 画笔 / E 橡皮 / P 钢笔 / T 文字 / R 矩形 / O 圆形 / L 箭头 / C 裁剪 / I 吸管 / H 抓手)
|
||||||
// 数字键 1–0 的老映射已按 PS 习惯移除(PS 里数字键是图层不透明度)。
|
// 数字键 1–0 的老映射已按 PS 习惯移除(PS 里数字键是图层不透明度)。
|
||||||
|
// v1.13 用户裁定:矩形 = R,圆形 = O,箭头 = L(原来的 L 是套索,套索改到 A)。
|
||||||
|
// U 保留为「同组循环」键:单独按仍是矩形,Shift+U 在 矩形/圆形/箭头 之间轮换。
|
||||||
const letterTools = {
|
const letterTools = {
|
||||||
v: 'select', m: 'marquee', l: 'lasso', b: 'brush', e: 'eraser', p: 'pen',
|
v: 'select', m: 'marquee', a: 'lasso', l: 'arrow', b: 'brush', e: 'eraser', p: 'pen',
|
||||||
t: 'text', u: 'rect', c: 'crop', i: 'picker', h: 'hand'
|
t: 'text', r: 'rect', o: 'circle', u: 'rect', c: 'crop', i: 'picker', h: 'hand'
|
||||||
}
|
}
|
||||||
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(letterTools, key)) {
|
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(letterTools, key)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -2396,14 +2584,11 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// PS 风格:Shift+X 切换选中形状的 描边/实心(与选项栏按钮共用 setShapeFill)
|
// PS 同款:Shift+X 交换选中形状的「填充色」与「描边色」(v1.13.1)。
|
||||||
if (!mod && e.shiftKey && key === 'x') {
|
// 以前这里绑的是「实心 ↔ 只描边」开关,用户按下去看到的是「填充色丢了、描边没变」——
|
||||||
const sh = getSelectedShape()
|
// 语义错了,不是颜色没了。实心/描边仍可从选项栏那两个按钮切。
|
||||||
if (sh && !sh.locked) {
|
if (!mod && !e.altKey && e.shiftKey && key === 'x') {
|
||||||
e.preventDefault()
|
if (swapShapeColors()) e.preventDefault()
|
||||||
if (sh.type === 'arrow') { toast('箭头没有实心样式', 'info'); return }
|
|
||||||
setShapeFill(!sh.fill, sh.type === 'pen' ? 'pen' : 'rect')
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ import { toast } from './commands.js'
|
|||||||
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, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
|
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, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
|
||||||
texts: S.textLayers.map(t => ({
|
texts: S.textLayers.map(t => ({
|
||||||
id: t.id, text: t.text, x: t.x, y: t.y, fontSize: t.fontSize, color: t.color,
|
id: t.id, text: t.text, x: t.x, y: t.y, fontSize: t.fontSize, color: t.color,
|
||||||
fontWeight: t.fontWeight, align: t.align, lineHeight: t.lineHeight,
|
fontWeight: t.fontWeight, fontFamily: t.fontFamily, align: t.align, lineHeight: t.lineHeight,
|
||||||
strokeWidth: t.strokeWidth, strokeColor: t.strokeColor, bgFill: !!t.bgFill, bgColor: t.bgColor,
|
strokeWidth: t.strokeWidth, strokeColor: t.strokeColor, bgFill: !!t.bgFill, bgColor: t.bgColor,
|
||||||
// 包围盒:吸附/多行/底色/描边的断言都靠它,和绘制共用同一套度量
|
// 包围盒:吸附/多行/底色/描边的断言都靠它,和绘制共用同一套度量
|
||||||
box: (() => { const b = textBounds(t); return { x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h) } })()
|
box: (() => { const b = textBounds(t); return { x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h) } })()
|
||||||
@@ -335,12 +335,15 @@ import { toast } from './commands.js'
|
|||||||
guides: S.guides ? S.guides.map(g => ({ axis: g.axis, at: Math.round(g.at * 10) / 10 })) : [],
|
guides: S.guides ? S.guides.map(g => ({ axis: g.axis, at: Math.round(g.at * 10) / 10 })) : [],
|
||||||
recentColors: (S.recentColors || []).slice(),
|
recentColors: (S.recentColors || []).slice(),
|
||||||
textDefaults: {
|
textDefaults: {
|
||||||
weight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
|
weight: S.textWeight, family: S.textFamily, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||||
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
||||||
bgFill: S.textBgFill, bgColor: S.textBgColor, bgAlpha: S.textBgAlpha
|
bgFill: S.textBgFill, bgColor: S.textBgColor, bgAlpha: S.textBgAlpha
|
||||||
},
|
},
|
||||||
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
|
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
|
||||||
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null }, selectedShapeId: S.selectedShapeId,
|
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null },
|
||||||
|
// 色板当前在调哪一格:stroke / fill / bg(文字上下文里 fill=描边、bg=底色)
|
||||||
|
colorTarget: S.colorTarget,
|
||||||
|
selectedShapeId: S.selectedShapeId,
|
||||||
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
||||||
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
||||||
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
|
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
|
||||||
|
|||||||
@@ -614,7 +614,7 @@ export function setActiveLayer(id) {
|
|||||||
const canRename = item.type === 'bitmap'
|
const canRename = item.type === 'bitmap'
|
||||||
// 注意:整项不能用 HTML5 draggable —— 它会把子元素上的原生拖动一起接管,
|
// 注意:整项不能用 HTML5 draggable —— 它会把子元素上的原生拖动一起接管,
|
||||||
// 不透明度滑杆因此「只能点、不能拖」。排序改由 bindLayerDragSort 自己实现。
|
// 不透明度滑杆因此「只能点、不能拖」。排序改由 bindLayerDragSort 自己实现。
|
||||||
const sortHint = item.id === 'base' ? '原图(固定在最底层)' : '拖动调整叠放顺序'
|
const sortHint = item.id === 'base' ? '原图(其他图层可以拖到它下面)' : '拖动调整叠放顺序'
|
||||||
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
||||||
<div class="iwb-layer-row">
|
<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>
|
||||||
@@ -669,9 +669,9 @@ export function setActiveLayer(id) {
|
|||||||
ordered.push(u)
|
ordered.push(u)
|
||||||
}
|
}
|
||||||
if (!ordered.length || byKey.size) return null
|
if (!ordered.length || byKey.size) return null
|
||||||
// 原图永远压在最底层:它被合进画面底图,跑到别的层上面只会让人以为图没了
|
// v1.13:原图不再强制压在最底层(用户裁定「希望能移动到原图下方」)。
|
||||||
const baseIdx = ordered.findIndex(u => u.obj.id === 'base')
|
// 典型用法是垫一张纯色/背景层到原图底下。原图行本身仍不可拖(见 bindLayerDragSort),
|
||||||
if (baseIdx > 0) { const [b] = ordered.splice(baseIdx, 1); ordered.unshift(b) }
|
// 但其他层可以任意穿过它 —— 顺序完全由面板说了算。
|
||||||
const before = units.map(u => u.obj.id).join('|')
|
const before = units.map(u => u.obj.id).join('|')
|
||||||
return { ordered, changed: before !== ordered.map(u => u.obj.id).join('|') }
|
return { ordered, changed: before !== ordered.map(u => u.obj.id).join('|') }
|
||||||
}
|
}
|
||||||
@@ -708,7 +708,7 @@ export function setActiveLayer(id) {
|
|||||||
if (e.button !== 0 || _sortDrag) return
|
if (e.button !== 0 || _sortDrag) return
|
||||||
const item = e.target.closest('.iwb-layer-item')
|
const item = e.target.closest('.iwb-layer-item')
|
||||||
if (!item || !list.contains(item)) return
|
if (!item || !list.contains(item)) return
|
||||||
if (item.dataset.layerId === 'base') return // 原图固定最底
|
if (item.dataset.layerId === 'base') return // 原图行不拖:它下面要不要垫层,拖别的层过去即可
|
||||||
// 控件、不透明度滑杆行、改名输入框都不参与排序:
|
// 控件、不透明度滑杆行、改名输入框都不参与排序:
|
||||||
// 否则滑杆刚按下就被判成「拖图层」,又回到只能点不能拖的老问题
|
// 否则滑杆刚按下就被判成「拖图层」,又回到只能点不能拖的老问题
|
||||||
if (e.target.closest('.iwb-layer-op-row, input, button, .iwb-layer-name-input')) return
|
if (e.target.closest('.iwb-layer-op-row, input, button, .iwb-layer-name-input')) return
|
||||||
@@ -755,11 +755,11 @@ export function setActiveLayer(id) {
|
|||||||
if (d.y < lr.top + 18) list.scrollTop -= 8
|
if (d.y < lr.top + 18) list.scrollTop -= 8
|
||||||
else if (d.y > lr.bottom - 18) list.scrollTop += 8
|
else if (d.y > lr.bottom - 18) list.scrollTop += 8
|
||||||
|
|
||||||
// 落点:指针越过哪一行的中线,就把自己挪到那一行之前(原图永远最后)
|
// 落点:指针越过哪一行的中线,就把自己挪到那一行之前。
|
||||||
|
// v1.13 起不再把「原图」当固定锚点 —— 拖到原图下半区就真的落到它下面(垫背景层用)。
|
||||||
const rows = Array.from(list.querySelectorAll('.iwb-layer-item'))
|
const rows = Array.from(list.querySelectorAll('.iwb-layer-item'))
|
||||||
const baseEl = rows.find(el => el.dataset.layerId === 'base') || null
|
const movable = rows.filter(el => el !== d.item)
|
||||||
const movable = rows.filter(el => el !== baseEl && el !== d.item)
|
let anchor = null // null = 落到最底(可能是原图之下)
|
||||||
let anchor = baseEl || null // 默认落到最底(原图之上)
|
|
||||||
for (const el of movable) {
|
for (const el of movable) {
|
||||||
const r = el.getBoundingClientRect()
|
const r = el.getBoundingClientRect()
|
||||||
if (d.y < r.top + r.height / 2) { anchor = el; break }
|
if (d.y < r.top + r.height / 2) { anchor = el; break }
|
||||||
@@ -787,9 +787,8 @@ export function setActiveLayer(id) {
|
|||||||
|
|
||||||
const rows = Array.from(d.list.querySelectorAll('.iwb-layer-item'))
|
const rows = Array.from(d.list.querySelectorAll('.iwb-layer-item'))
|
||||||
const keyOf = (el) => el.dataset.layerType + ':' + el.dataset.layerId
|
const keyOf = (el) => el.dataset.layerType + ':' + el.dataset.layerId
|
||||||
const baseEl = rows.find(el => el.dataset.layerId === 'base') || null
|
// v1.13:面板顺序就是最终顺序(原图可以被压在下面),不再把它补到末尾
|
||||||
const desc = rows.filter(el => el !== baseEl).map(keyOf)
|
const desc = rows.map(keyOf)
|
||||||
if (baseEl) desc.push(keyOf(baseEl))
|
|
||||||
|
|
||||||
// 拖动即选中:拖完直接能在下面调不透明度/继续操作,不用再点一次
|
// 拖动即选中:拖完直接能在下面调不透明度/继续操作,不用再点一次
|
||||||
if (d.type === 'bitmap') {
|
if (d.type === 'bitmap') {
|
||||||
@@ -1173,6 +1172,8 @@ export function setActiveLayer(id) {
|
|||||||
const insertAt = all.slice(0, Math.max(lowIdx, 0)).filter(u => !chosenSet.has(u.obj)).length
|
const insertAt = all.slice(0, Math.max(lowIdx, 0)).filter(u => !chosenSet.has(u.obj)).length
|
||||||
|
|
||||||
let carrier
|
let carrier
|
||||||
|
// 原图原来的 z:合并后要落回原位(v1.13 起原图不再被强制压到最底,不能 unshift)
|
||||||
|
const baseZ = baseUnit ? (baseUnit.obj.z || 0) : 0
|
||||||
if (baseUnit) {
|
if (baseUnit) {
|
||||||
carrier = baseUnit.obj
|
carrier = baseUnit.obj
|
||||||
// 合并后它就是纯像素层:断掉 image/sourceCanvas,避免后续按原图重新重绘
|
// 合并后它就是纯像素层:断掉 image/sourceCanvas,避免后续按原图重新重绘
|
||||||
@@ -1190,9 +1191,10 @@ export function setActiveLayer(id) {
|
|||||||
carrier._bounds = undefined
|
carrier._bounds = undefined
|
||||||
composeUnitsInto(carrier, sorted)
|
composeUnitsInto(carrier, sorted)
|
||||||
for (const u of sorted) if (u.obj !== carrier) dropUnit(u)
|
for (const u of sorted) if (u.obj !== carrier) dropUnit(u)
|
||||||
// base 永远压在最底,其余层保持原有相对顺序
|
// 落回原图原来的叠放位置:低于它的层留在它下面(v1.13 允许原图上面压着别的层)
|
||||||
const rest = layerUnits().filter(u => u.obj !== carrier)
|
const rest = layerUnits().filter(u => u.obj !== carrier)
|
||||||
rest.unshift({ kind: 'bitmap', obj: carrier })
|
const at = rest.filter(u => (u.obj.z || 0) < baseZ).length
|
||||||
|
rest.splice(Math.min(at, rest.length), 0, { kind: 'bitmap', obj: carrier })
|
||||||
assignLayerZ(rest)
|
assignLayerZ(rest)
|
||||||
} else {
|
} else {
|
||||||
const canvas = createLayerCanvas()
|
const canvas = createLayerCanvas()
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import { drawPlacementPreview } from './placement.js'
|
|||||||
import { drawShape, setTool } from './tools.js'
|
import { drawShape, setTool } from './tools.js'
|
||||||
import { saveSnapshot, snapshotState } from './history.js'
|
import { saveSnapshot, snapshotState } from './history.js'
|
||||||
import { toast } from './commands.js'
|
import { toast } from './commands.js'
|
||||||
import { renderOptionBar, updateLayerUI } from './events.js'
|
import { renderOptionBar } from './events.js'
|
||||||
import { fontOf, newTextStyle, textBox } from './text.js'
|
import { fontOf, fontStackOf, newTextStyle, textBox, weightOf } from './text.js'
|
||||||
import { drawGuides } from './snap.js'
|
import { drawGuides } from './snap.js'
|
||||||
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||||
|
|
||||||
@@ -251,12 +251,11 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
if (!sel) { toast('先在画布或图层面板选中要调整的元素', 'info'); return }
|
if (!sel) { toast('先在画布或图层面板选中要调整的元素', 'info'); return }
|
||||||
if (sel.obj.locked || sel.obj.id === 'base') return
|
if (sel.obj.locked || sel.obj.id === 'base') return
|
||||||
const units = layerUnits()
|
const units = layerUnits()
|
||||||
// base 是锁定且不透明的底图,固定在最下层;任何元素都不许置底到它下面(否则等于消失)
|
// v1.13:不再把原图钉在最底层 —— 「置底」可以真的沉到原图下面(垫背景层的常见用法)。
|
||||||
const baseIdx = units.findIndex(u => u.obj.id === 'base')
|
// 原图行本身仍不可参与(上面已 return),避免把底图整层挪走。
|
||||||
if (baseIdx > 0) { const [b] = units.splice(baseIdx, 1); units.unshift(b) }
|
|
||||||
const from = units.findIndex(u => u.obj === sel.obj)
|
const from = units.findIndex(u => u.obj === sel.obj)
|
||||||
if (from < 0) return
|
if (from < 0) return
|
||||||
const min = baseIdx >= 0 ? 1 : 0
|
const min = 0
|
||||||
let to
|
let to
|
||||||
if (dir === 'up') to = Math.min(from + 1, units.length - 1)
|
if (dir === 'up') to = Math.min(from + 1, units.length - 1)
|
||||||
else if (dir === 'down') to = Math.max(from - 1, min)
|
else if (dir === 'down') to = Math.max(from - 1, min)
|
||||||
@@ -500,7 +499,6 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const penShape = getPenEditingShape()
|
const penShape = getPenEditingShape()
|
||||||
if (penShape) drawPenEditOverlay(penShape)
|
if (penShape) drawPenEditOverlay(penShape)
|
||||||
if (S.cropRect) drawCropPreview()
|
if (S.cropRect) drawCropPreview()
|
||||||
updateLayerUI()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ 钢笔二次编辑(移动/添加/删除节点) ============
|
// ============ 钢笔二次编辑(移动/添加/删除节点) ============
|
||||||
@@ -610,6 +608,12 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
input.value = ''
|
input.value = ''
|
||||||
S.textEditingId = null
|
S.textEditingId = null
|
||||||
}
|
}
|
||||||
|
// 输入时看到的字形要和提交后一致:字体族与字重跟随这段文字自己的样式
|
||||||
|
// (新建时跟随「下一段文字的默认值」)。字号仍按 CSS 的 14px —— 那是输入框的可读性取舍,
|
||||||
|
// 跟字体不同:字体不一致会让人以为「选错字体了」,字号不一致只是大小不同。
|
||||||
|
const styleSrc = layer || { fontFamily: S.textFamily, fontWeight: S.textWeight }
|
||||||
|
input.style.fontFamily = fontStackOf(styleSrc)
|
||||||
|
input.style.fontWeight = weightOf(styleSrc)
|
||||||
input.focus()
|
input.focus()
|
||||||
input.select()
|
input.select()
|
||||||
input.dataset.x = x
|
input.dataset.x = x
|
||||||
@@ -663,7 +667,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
fontSize: Math.max(8, S.textSize),
|
fontSize: Math.max(8, S.textSize),
|
||||||
// 样式一次性随默认值落进对象:老对象没有这些字段,text.js 会各自回退到等价默认值
|
// 样式一次性随默认值落进对象:老对象没有这些字段,text.js 会各自回退到等价默认值
|
||||||
...newTextStyle({
|
...newTextStyle({
|
||||||
fontWeight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
|
fontWeight: S.textWeight, fontFamily: S.textFamily, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||||
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
||||||
bgFill: S.textBgFill, bgColor: S.textBgColor
|
bgFill: S.textBgFill, bgColor: S.textBgColor
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
textSize: 32, // 新建文字的字号 px
|
textSize: 32, // 新建文字的字号 px
|
||||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
textWeight: 'bold', // bold | normal | 900
|
textWeight: 'bold', // bold | normal | 900
|
||||||
|
textFamily: 'sans', // v1.14 字体预设 key:sans 黑体 | serif 宋体 | kai 楷体 | round 圆体
|
||||||
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
||||||
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
||||||
textStrokeWidth: TEXT_DEFAULTS.strokeWidth, // 描边宽度 px,0 = 无描边
|
textStrokeWidth: TEXT_DEFAULTS.strokeWidth, // 描边宽度 px,0 = 无描边
|
||||||
|
|||||||
@@ -54,9 +54,56 @@
|
|||||||
return w == null || w === '' ? 'bold' : String(w)
|
return w == null || w === '' ? 'bold' : String(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字体预设(v1.14):key → { label, stack }。
|
||||||
|
*
|
||||||
|
* 为什么只做「系统字体族」而不是内置字体文件:
|
||||||
|
* 1. 宿主 CSP 是 `default-src 'self'`,font-src 回落它,第三方字体 CDN 会被浏览器直接拦;
|
||||||
|
* 2. 中文字体动辄 2–64MB(本机宋体 2.3MB / 楷体 2.2MB / 苹方全字重 64MB),
|
||||||
|
* 插件产物现在才 389KB,内联等于体积涨 5–150 倍;
|
||||||
|
* 3. 系统字体同步可用,没有「字体没加载完就 measureText」导致框和字错位的时序问题。
|
||||||
|
* 每个 stack 都是跨平台候选队列:macOS 先命中苹方/宋体,Windows 命中雅黑/宋体,
|
||||||
|
* 全不命中时退到通用的 sans-serif / serif —— 永远不会渲染失败。
|
||||||
|
*
|
||||||
|
* 注意:中文是全角等宽,换字体不改字宽(实测 10 字 48px 在 6 种字体下都是 480px),
|
||||||
|
* 所以切换不会引起版面跳动;只有拉丁字母和数字会伸缩。
|
||||||
|
*/
|
||||||
|
export const TEXT_FONTS = {
|
||||||
|
sans: {
|
||||||
|
label: '黑体',
|
||||||
|
stack: '"PingFang SC", "Microsoft YaHei", "Heiti SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans SC", sans-serif'
|
||||||
|
},
|
||||||
|
serif: {
|
||||||
|
label: '宋体',
|
||||||
|
stack: '"Songti SC", "SimSun", "STSong", "Source Han Serif SC", "Noto Serif SC", serif'
|
||||||
|
},
|
||||||
|
kai: {
|
||||||
|
label: '楷体',
|
||||||
|
stack: '"Kaiti SC", "KaiTi", "STKaiti", "AR PL UKai CN", "Noto Serif SC", serif'
|
||||||
|
},
|
||||||
|
round: {
|
||||||
|
label: '圆体',
|
||||||
|
stack: '"Yuanti SC", "YouYuan", "STYuanti", "PingFang SC", sans-serif'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TEXT_FONT_KEYS = ['sans', 'serif', 'kai', 'round']
|
||||||
|
export const TEXT_FONT_DEFAULT = 'sans'
|
||||||
|
|
||||||
|
/** 把任意输入收敛成已知的字体 key:老对象没有 fontFamily、或存了脏值,都回退到默认 */
|
||||||
|
export function fontKeyOf(t) {
|
||||||
|
const k = t && t.fontFamily
|
||||||
|
return TEXT_FONTS[k] ? k : TEXT_FONT_DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 字体栈串(不含字号字重),选项栏下拉与预览都用它 */
|
||||||
|
export function fontStackOf(t) {
|
||||||
|
return TEXT_FONTS[fontKeyOf(t)].stack
|
||||||
|
}
|
||||||
|
|
||||||
export function fontOf(t) {
|
export function fontOf(t) {
|
||||||
const size = Math.max(4, Number(t && t.fontSize) || 32)
|
const size = Math.max(4, Number(t && t.fontSize) || 32)
|
||||||
return weightOf(t) + ' ' + size + 'px sans-serif'
|
return weightOf(t) + ' ' + size + 'px ' + fontStackOf(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 文字的排布度量:分行、每行宽度、行高、底色 padding、描边宽度 */
|
/** 文字的排布度量:分行、每行宽度、行高、底色 padding、描边宽度 */
|
||||||
@@ -163,6 +210,9 @@
|
|||||||
const s = src || {}
|
const s = src || {}
|
||||||
return {
|
return {
|
||||||
fontWeight: weightOf(s),
|
fontWeight: weightOf(s),
|
||||||
|
// 字体 key 过一遍收敛:外部传进来不认识的字符串不会进 ctx.font(脏值会让整个
|
||||||
|
// 字体串失效、静默退回浏览器默认,文件本身看不出问题,极难排查)
|
||||||
|
fontFamily: fontKeyOf(s),
|
||||||
align: alignOf(s),
|
align: alignOf(s),
|
||||||
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
||||||
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
||||||
|
|||||||
+304
-108
@@ -9,7 +9,7 @@
|
|||||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||||
id: 'image-annotate',
|
id: 'image-annotate',
|
||||||
name: '标注 / 修图',
|
name: '标注 / 修图',
|
||||||
version: '1.11.0',
|
version: '1.14.0',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
@@ -49,9 +49,36 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const w = t && t.fontWeight;
|
const w = t && t.fontWeight;
|
||||||
return w == null || w === "" ? "bold" : String(w);
|
return w == null || w === "" ? "bold" : String(w);
|
||||||
}
|
}
|
||||||
|
var TEXT_FONTS = {
|
||||||
|
sans: {
|
||||||
|
label: "黑体",
|
||||||
|
stack: '"PingFang SC", "Microsoft YaHei", "Heiti SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans SC", sans-serif'
|
||||||
|
},
|
||||||
|
serif: {
|
||||||
|
label: "宋体",
|
||||||
|
stack: '"Songti SC", "SimSun", "STSong", "Source Han Serif SC", "Noto Serif SC", serif'
|
||||||
|
},
|
||||||
|
kai: {
|
||||||
|
label: "楷体",
|
||||||
|
stack: '"Kaiti SC", "KaiTi", "STKaiti", "AR PL UKai CN", "Noto Serif SC", serif'
|
||||||
|
},
|
||||||
|
round: {
|
||||||
|
label: "圆体",
|
||||||
|
stack: '"Yuanti SC", "YouYuan", "STYuanti", "PingFang SC", sans-serif'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var TEXT_FONT_KEYS = ["sans", "serif", "kai", "round"];
|
||||||
|
var TEXT_FONT_DEFAULT = "sans";
|
||||||
|
function fontKeyOf(t) {
|
||||||
|
const k = t && t.fontFamily;
|
||||||
|
return TEXT_FONTS[k] ? k : TEXT_FONT_DEFAULT;
|
||||||
|
}
|
||||||
|
function fontStackOf(t) {
|
||||||
|
return TEXT_FONTS[fontKeyOf(t)].stack;
|
||||||
|
}
|
||||||
function fontOf(t) {
|
function fontOf(t) {
|
||||||
const size = Math.max(4, Number(t && t.fontSize) || 32);
|
const size = Math.max(4, Number(t && t.fontSize) || 32);
|
||||||
return weightOf(t) + " " + size + "px sans-serif";
|
return weightOf(t) + " " + size + "px " + fontStackOf(t);
|
||||||
}
|
}
|
||||||
function textMetrics(t) {
|
function textMetrics(t) {
|
||||||
const ctx = measureCtx();
|
const ctx = measureCtx();
|
||||||
@@ -139,6 +166,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const s = src || {};
|
const s = src || {};
|
||||||
return {
|
return {
|
||||||
fontWeight: weightOf(s),
|
fontWeight: weightOf(s),
|
||||||
|
// 字体 key 过一遍收敛:外部传进来不认识的字符串不会进 ctx.font(脏值会让整个
|
||||||
|
// 字体串失效、静默退回浏览器默认,文件本身看不出问题,极难排查)
|
||||||
|
fontFamily: fontKeyOf(s),
|
||||||
align: alignOf(s),
|
align: alignOf(s),
|
||||||
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
||||||
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
||||||
@@ -203,6 +233,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
textWeight: "bold",
|
textWeight: "bold",
|
||||||
// bold | normal | 900
|
// bold | normal | 900
|
||||||
|
textFamily: "sans",
|
||||||
|
// v1.14 字体预设 key:sans 黑体 | serif 宋体 | kai 楷体 | round 圆体
|
||||||
textAlign: "left",
|
textAlign: "left",
|
||||||
// left | center | right(多行时各行按块宽对齐)
|
// left | center | right(多行时各行按块宽对齐)
|
||||||
textLineHeight: 1.25,
|
textLineHeight: 1.25,
|
||||||
@@ -1395,14 +1427,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
}
|
}
|
||||||
if (sel.obj.locked || sel.obj.id === "base") return;
|
if (sel.obj.locked || sel.obj.id === "base") return;
|
||||||
const units = layerUnits();
|
const units = layerUnits();
|
||||||
const baseIdx = units.findIndex((u) => u.obj.id === "base");
|
|
||||||
if (baseIdx > 0) {
|
|
||||||
const [b] = units.splice(baseIdx, 1);
|
|
||||||
units.unshift(b);
|
|
||||||
}
|
|
||||||
const from = units.findIndex((u) => u.obj === sel.obj);
|
const from = units.findIndex((u) => u.obj === sel.obj);
|
||||||
if (from < 0) return;
|
if (from < 0) return;
|
||||||
const min = baseIdx >= 0 ? 1 : 0;
|
const min = 0;
|
||||||
let to;
|
let to;
|
||||||
if (dir === "up") to = Math.min(from + 1, units.length - 1);
|
if (dir === "up") to = Math.min(from + 1, units.length - 1);
|
||||||
else if (dir === "down") to = Math.max(from - 1, min);
|
else if (dir === "down") to = Math.max(from - 1, min);
|
||||||
@@ -1647,7 +1674,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const penShape = getPenEditingShape();
|
const penShape = getPenEditingShape();
|
||||||
if (penShape) drawPenEditOverlay(penShape);
|
if (penShape) drawPenEditOverlay(penShape);
|
||||||
if (S.cropRect) drawCropPreview();
|
if (S.cropRect) drawCropPreview();
|
||||||
updateLayerUI();
|
|
||||||
}
|
}
|
||||||
function getPenEditingShape() {
|
function getPenEditingShape() {
|
||||||
if (!S.penEditId) return null;
|
if (!S.penEditId) return null;
|
||||||
@@ -1745,6 +1771,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
input.value = "";
|
input.value = "";
|
||||||
S.textEditingId = null;
|
S.textEditingId = null;
|
||||||
}
|
}
|
||||||
|
const styleSrc = layer || { fontFamily: S.textFamily, fontWeight: S.textWeight };
|
||||||
|
input.style.fontFamily = fontStackOf(styleSrc);
|
||||||
|
input.style.fontWeight = weightOf(styleSrc);
|
||||||
input.focus();
|
input.focus();
|
||||||
input.select();
|
input.select();
|
||||||
input.dataset.x = x;
|
input.dataset.x = x;
|
||||||
@@ -1798,6 +1827,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
// 样式一次性随默认值落进对象:老对象没有这些字段,text.js 会各自回退到等价默认值
|
// 样式一次性随默认值落进对象:老对象没有这些字段,text.js 会各自回退到等价默认值
|
||||||
...newTextStyle({
|
...newTextStyle({
|
||||||
fontWeight: S.textWeight,
|
fontWeight: S.textWeight,
|
||||||
|
fontFamily: S.textFamily,
|
||||||
align: S.textAlign,
|
align: S.textAlign,
|
||||||
lineHeight: S.textLineHeight,
|
lineHeight: S.textLineHeight,
|
||||||
strokeWidth: S.textStrokeWidth,
|
strokeWidth: S.textStrokeWidth,
|
||||||
@@ -2422,7 +2452,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
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 pct = opacityPct(item.opacity);
|
||||||
const canRename = item.type === "bitmap";
|
const canRename = item.type === "bitmap";
|
||||||
const sortHint = item.id === "base" ? "原图(固定在最底层)" : "拖动调整叠放顺序";
|
const sortHint = item.id === "base" ? "原图(其他图层可以拖到它下面)" : "拖动调整叠放顺序";
|
||||||
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
||||||
<div class="iwb-layer-row">
|
<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>
|
||||||
@@ -2460,11 +2490,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ordered.push(u);
|
ordered.push(u);
|
||||||
}
|
}
|
||||||
if (!ordered.length || byKey.size) return null;
|
if (!ordered.length || byKey.size) return null;
|
||||||
const baseIdx = ordered.findIndex((u) => u.obj.id === "base");
|
|
||||||
if (baseIdx > 0) {
|
|
||||||
const [b] = ordered.splice(baseIdx, 1);
|
|
||||||
ordered.unshift(b);
|
|
||||||
}
|
|
||||||
const before = units.map((u) => u.obj.id).join("|");
|
const before = units.map((u) => u.obj.id).join("|");
|
||||||
return { ordered, changed: before !== ordered.map((u) => u.obj.id).join("|") };
|
return { ordered, changed: before !== ordered.map((u) => u.obj.id).join("|") };
|
||||||
}
|
}
|
||||||
@@ -2531,9 +2556,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (d.y < lr.top + 18) list.scrollTop -= 8;
|
if (d.y < lr.top + 18) list.scrollTop -= 8;
|
||||||
else if (d.y > lr.bottom - 18) list.scrollTop += 8;
|
else if (d.y > lr.bottom - 18) list.scrollTop += 8;
|
||||||
const rows = Array.from(list.querySelectorAll(".iwb-layer-item"));
|
const rows = Array.from(list.querySelectorAll(".iwb-layer-item"));
|
||||||
const baseEl = rows.find((el) => el.dataset.layerId === "base") || null;
|
const movable = rows.filter((el) => el !== d.item);
|
||||||
const movable = rows.filter((el) => el !== baseEl && el !== d.item);
|
let anchor = null;
|
||||||
let anchor = baseEl || null;
|
|
||||||
for (const el of movable) {
|
for (const el of movable) {
|
||||||
const r2 = el.getBoundingClientRect();
|
const r2 = el.getBoundingClientRect();
|
||||||
if (d.y < r2.top + r2.height / 2) {
|
if (d.y < r2.top + r2.height / 2) {
|
||||||
@@ -2558,9 +2582,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (!d.active) return;
|
if (!d.active) return;
|
||||||
const rows = Array.from(d.list.querySelectorAll(".iwb-layer-item"));
|
const rows = Array.from(d.list.querySelectorAll(".iwb-layer-item"));
|
||||||
const keyOf = (el) => el.dataset.layerType + ":" + el.dataset.layerId;
|
const keyOf = (el) => el.dataset.layerType + ":" + el.dataset.layerId;
|
||||||
const baseEl = rows.find((el) => el.dataset.layerId === "base") || null;
|
const desc = rows.map(keyOf);
|
||||||
const desc = rows.filter((el) => el !== baseEl).map(keyOf);
|
|
||||||
if (baseEl) desc.push(keyOf(baseEl));
|
|
||||||
if (d.type === "bitmap") {
|
if (d.type === "bitmap") {
|
||||||
if (S.layers.some((l) => l.id === d.id)) S.selectedLayerId = d.id;
|
if (S.layers.some((l) => l.id === d.id)) S.selectedLayerId = d.id;
|
||||||
} else if (d.type === "text" || d.type === "shape") {
|
} else if (d.type === "text" || d.type === "shape") {
|
||||||
@@ -2885,6 +2907,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const chosenSet = new Set(sorted.map((u) => u.obj));
|
const chosenSet = new Set(sorted.map((u) => u.obj));
|
||||||
const insertAt = all.slice(0, Math.max(lowIdx, 0)).filter((u) => !chosenSet.has(u.obj)).length;
|
const insertAt = all.slice(0, Math.max(lowIdx, 0)).filter((u) => !chosenSet.has(u.obj)).length;
|
||||||
let carrier;
|
let carrier;
|
||||||
|
const baseZ = baseUnit ? baseUnit.obj.z || 0 : 0;
|
||||||
if (baseUnit) {
|
if (baseUnit) {
|
||||||
carrier = baseUnit.obj;
|
carrier = baseUnit.obj;
|
||||||
carrier.image = null;
|
carrier.image = null;
|
||||||
@@ -2902,7 +2925,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
composeUnitsInto(carrier, sorted);
|
composeUnitsInto(carrier, sorted);
|
||||||
for (const u of sorted) if (u.obj !== carrier) dropUnit(u);
|
for (const u of sorted) if (u.obj !== carrier) dropUnit(u);
|
||||||
const rest = layerUnits().filter((u) => u.obj !== carrier);
|
const rest = layerUnits().filter((u) => u.obj !== carrier);
|
||||||
rest.unshift({ kind: "bitmap", obj: carrier });
|
const at = rest.filter((u) => (u.obj.z || 0) < baseZ).length;
|
||||||
|
rest.splice(Math.min(at, rest.length), 0, { kind: "bitmap", obj: carrier });
|
||||||
assignLayerZ(rest);
|
assignLayerZ(rest);
|
||||||
} else {
|
} else {
|
||||||
const canvas = createLayerCanvas();
|
const canvas = createLayerCanvas();
|
||||||
@@ -3465,21 +3489,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
<button class="iwb-editor-action" data-action="redo" title="重做 (Ctrl+Shift+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>
|
<button class="iwb-editor-action" data-action="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"><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>
|
<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>
|
</div>
|
||||||
<span class="iwb-editor-divider"></span>
|
<!-- 顶栏命令带已清空(v1.13):
|
||||||
<!-- 顶栏命令带(v1.2.6):撤销/重做/还原 | 顺序 | 视图;图层新建/导入回图层面板标题栏 -->
|
四个「置顶/上移/下移/置底」按钮删除(图层面板可拖动 + Ctrl+]/[ 已覆盖);
|
||||||
<div class="iwb-editor-commands">
|
「适应窗口 / 收起侧栏」搬到画布底部工具栏最右侧,离画布更近。
|
||||||
<div class="iwb-editor-cmdgroup" data-group="order" title="调整选中元素的图层顺序">
|
整个 .iwb-editor-commands 容器一并移除,不留一条空分隔线。 -->
|
||||||
<button class="iwb-editor-layer-btn" data-layer="top" title="置顶:选中元素移到最上层 (Ctrl+Shift+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="5" x2="20" y2="5"/><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="up" title="上移一层 (Ctrl+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="down" title="下移一层 (Ctrl+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="bottom" title="置底:选中元素移到最下层 (Ctrl+Shift+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/><line x1="4" y1="19" x2="20" y2="19"/></svg></button>
|
|
||||||
</div>
|
|
||||||
<span class="iwb-editor-divider"></span>
|
|
||||||
<div class="iwb-editor-cmdgroup" data-group="view">
|
|
||||||
<button class="iwb-editor-action" data-action="zoomFit" title="适应窗口 (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-export-actions">
|
<div class="iwb-editor-export-actions">
|
||||||
<div class="iwb-editor-export-settings-wrap">
|
<div class="iwb-editor-export-settings-wrap">
|
||||||
@@ -3564,20 +3577,23 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-tools">
|
<div class="iwb-editor-tools">
|
||||||
<!-- 颜色(v1.11):描边 + 填充 两个槽叠放在一个按钮位里(PS 式前/背景色)。
|
<!-- 颜色(v1.11 两格 → v1.12 文字三格):
|
||||||
点哪个槽就调哪个:色板只有一套,写谁由 S.colorTarget 决定。
|
形状下是「描边 + 填充」两格叠放在一个按钮位里(PS 式前/背景色);
|
||||||
这样全项目只有「描边色 / 填充色」两个颜色概念,不再有第三个主色。
|
文字下是「文字 / 描边 / 底色」三格横排 —— 文字对象天生就有三个颜色,
|
||||||
填充块在无填充时画斜杠,跟随描边色时带一个小三角角标。 -->
|
只给两格必然有一格无处安放(用户反馈「文本不支持描边与字体色切换」)。
|
||||||
|
点哪格就调哪格:色板只有一套,写谁由 S.colorTarget 决定。
|
||||||
|
关掉的那格画斜杠,跟随描边色的填充块带一个小三角角标。 -->
|
||||||
<div class="iwb-editor-color-pair" data-color-mode="single">
|
<div class="iwb-editor-color-pair" data-color-mode="single">
|
||||||
<button type="button" class="iwb-editor-color-btn" data-color-slot="stroke" data-action="toggleColorPop" aria-expanded="false" title="描边色:形状描边 / 画笔 / 文字都用它。点开色板调色"><i></i></button>
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="stroke" data-action="toggleColorPop" aria-expanded="false" title="描边色:形状描边 / 画笔 / 文字都用它。点开色板调色"><i></i></button>
|
||||||
<button type="button" class="iwb-editor-color-btn" data-color-slot="fill" data-action="toggleColorPop" aria-expanded="false" title="填充色:形状内部颜色。点开色板调色,色板里可切换「无填充」"><i></i></button>
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="fill" data-action="toggleColorPop" aria-expanded="false" title="填充色:形状内部颜色。点开色板调色,色板里可切换「无填充」"><i></i></button>
|
||||||
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="bg" data-action="toggleColorPop" aria-expanded="false" title="文本框底色:垫在文字下面的一块半透明色板。点开调色,可选「无」"><i></i></button>
|
||||||
</div>
|
</div>
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
<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>
|
<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>
|
<span class="iwb-editor-divider"></span>
|
||||||
|
|
||||||
<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="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" data-tool="lasso" title="套索 (A):按住拖动自由圈选,松手闭合"><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="画笔 (B):] 增大 / [ 减小笔刷;按住 Alt 临时吸色"><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):] 增大 / [ 减小笔刷;按住 Alt 临时吸色"><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>
|
||||||
|
|
||||||
@@ -3587,11 +3603,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
|
|
||||||
<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="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="矩形 (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="rect" title="矩形 (R):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="圆形 (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="circle" title="圆形 (O):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="箭头 (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="arrow" title="箭头 (L):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="吸管 (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="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>
|
||||||
|
|
||||||
@@ -3601,7 +3617,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
|
|
||||||
<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>
|
<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>
|
||||||
|
|
||||||
|
<!-- 视图快捷(v1.13):从顶栏搬过来,贴在工具条最右侧的「|」之后。
|
||||||
|
工具条本身是 shrink-to-fit 且居中,所以这一组天然就是「最右边」。 -->
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
|
<button class="iwb-editor-tool iwb-editor-view-btn" 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-tool iwb-editor-view-btn" 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>
|
</div>
|
||||||
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
||||||
@@ -3671,12 +3691,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
||||||
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
||||||
<div class="iwb-editor-color-pop" hidden>
|
<div class="iwb-editor-color-pop" hidden>
|
||||||
<!-- 弹层头部(v1.11):标明「现在调的是哪个颜色」,并可直接切换。
|
<!-- 弹层头部(v1.11 两格 → v1.12 文字三格):标明「现在调的是哪个颜色」,
|
||||||
与工具栏那两个色块是同一组槽位,两边高亮完全一致。
|
并可直接切换。与工具栏那几个色块是同一组槽位,两边高亮完全一致。
|
||||||
「无」只对填充有意义:描边关掉会让形状彻底消失,不是用户要的。 -->
|
「无」只对「可以没有」的颜色有意义:文字色没有无,描边/底色/填充才有。 -->
|
||||||
<div class="iwb-color-pop-head">
|
<div class="iwb-color-pop-head">
|
||||||
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
|
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
|
||||||
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
|
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色 / 文字描边色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
|
||||||
|
<button type="button" class="iwb-color-pop-tab" data-color-slot="bg" hidden title="正在调文本框底色(垫在文字下面)"><i></i><span class="iwb-color-pop-tab-label">底色</span></button>
|
||||||
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="无填充:形状内部透明,只留描边"><span></span>无</button>
|
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="无填充:形状内部透明,只留描边"><span></span>无</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-color-pop-body">
|
<div class="iwb-color-pop-body">
|
||||||
@@ -4767,7 +4788,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
updateBrushUI();
|
updateBrushUI();
|
||||||
updateBrushParamUI();
|
updateBrushParamUI();
|
||||||
updateFillUI();
|
updateFillUI();
|
||||||
updateLayerUI();
|
|
||||||
updateZoomUI();
|
updateZoomUI();
|
||||||
hidePickerTip();
|
hidePickerTip();
|
||||||
runtime.el.querySelectorAll(".iwb-editor-constraint-btn[data-ratio]").forEach((b) => b.classList.remove("active"));
|
runtime.el.querySelectorAll(".iwb-editor-constraint-btn[data-ratio]").forEach((b) => b.classList.remove("active"));
|
||||||
@@ -4830,37 +4850,87 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
layer.canvas.style.cursor = cur;
|
layer.canvas.style.cursor = cur;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function fillSlotOn() {
|
function colorContext() {
|
||||||
|
const t = getSelectedText();
|
||||||
|
if (t || S.tool === "text") return { kind: "text", text: t || null };
|
||||||
const sh = getSelectedShape();
|
const sh = getSelectedShape();
|
||||||
if (sh) return sh.type === "rect" || sh.type === "circle" || sh.type === "pen" && !!sh.closed;
|
if (sh) return { kind: sh.type === "arrow" ? "strokeOnly" : "shape", shape: sh };
|
||||||
return S.tool === "rect" || S.tool === "circle" || S.tool === "pen";
|
if (S.tool === "rect" || S.tool === "circle" || S.tool === "pen") return { kind: "shape", shape: null };
|
||||||
|
return { kind: "strokeOnly", shape: null };
|
||||||
|
}
|
||||||
|
function fillSlotOn() {
|
||||||
|
const ctx = colorContext();
|
||||||
|
if (ctx.kind === "text") return true;
|
||||||
|
if (ctx.kind !== "shape") return false;
|
||||||
|
const sh = ctx.shape;
|
||||||
|
if (!sh) return true;
|
||||||
|
return sh.type === "rect" || sh.type === "circle" || sh.type === "pen" && !!sh.closed;
|
||||||
|
}
|
||||||
|
function textColorSlots(t) {
|
||||||
|
const color = (t ? t.color : S.color) || S.color;
|
||||||
|
const strokeColor = (t ? t.strokeColor : S.textStrokeColor) || TEXT_DEFAULTS.strokeColor;
|
||||||
|
const sw = Number(t ? t.strokeWidth : S.textStrokeWidth) || 0;
|
||||||
|
const bgColor = (t ? t.bgColor : S.textBgColor) || TEXT_DEFAULTS.bgColor;
|
||||||
|
const bgFill = !!(t ? t.bgFill : S.textBgFill);
|
||||||
|
const bgAlpha = Number(t ? t.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : t.bgAlpha : S.textBgAlpha) || TEXT_DEFAULTS.bgAlpha;
|
||||||
|
return {
|
||||||
|
mode: "text",
|
||||||
|
stroke: color,
|
||||||
|
fill: strokeColor,
|
||||||
|
fillOn: sw > 0,
|
||||||
|
follow: false,
|
||||||
|
bg: bgColor,
|
||||||
|
bgOn: bgFill,
|
||||||
|
bgAlpha,
|
||||||
|
strokeName: "文字",
|
||||||
|
fillName: "描边",
|
||||||
|
bgName: "底色"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
function colorSlots() {
|
function colorSlots() {
|
||||||
const sh = getSelectedShape();
|
const ctx = colorContext();
|
||||||
|
if (ctx.kind === "text") return textColorSlots(ctx.text);
|
||||||
|
const sh = ctx.shape;
|
||||||
const stroke = sh && sh.color || S.color;
|
const stroke = sh && sh.color || S.color;
|
||||||
const rawFill = sh ? sh.fillColor || null : S.shapeFillColor;
|
const rawFill = sh ? sh.fillColor || null : S.shapeFillColor;
|
||||||
const fillOn = sh ? sh.type === "pen" ? !!sh.fill && !!sh.closed : !!sh.fill : S.tool === "pen" ? !!S.penFill : !!S.rectFill;
|
const fillOn = sh ? sh.type === "pen" ? !!sh.fill && !!sh.closed : !!sh.fill : S.tool === "pen" ? !!S.penFill : !!S.rectFill;
|
||||||
return { stroke, fill: rawFill || stroke, fillOn, follow: !rawFill };
|
return {
|
||||||
|
mode: ctx.kind === "shape" ? "shape" : "single",
|
||||||
|
stroke,
|
||||||
|
fill: rawFill || stroke,
|
||||||
|
fillOn,
|
||||||
|
follow: !rawFill,
|
||||||
|
bg: null,
|
||||||
|
bgOn: false,
|
||||||
|
bgAlpha: 1,
|
||||||
|
strokeName: "描边",
|
||||||
|
fillName: "填充",
|
||||||
|
bgName: "底色"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
function activeColor() {
|
function activeColor() {
|
||||||
const sl = colorSlots();
|
const sl = colorSlots();
|
||||||
return S.colorTarget === "fill" ? sl.fill : sl.stroke;
|
if (S.colorTarget === "bg") return sl.bg || sl.stroke;
|
||||||
|
if (S.colorTarget === "fill" && fillSlotOn()) return sl.fill || sl.stroke;
|
||||||
|
return sl.stroke;
|
||||||
}
|
}
|
||||||
function updateColorUI() {
|
function updateColorUI() {
|
||||||
const sl = colorSlots();
|
const sl = colorSlots();
|
||||||
const fillable = fillSlotOn();
|
const isText = sl.mode === "text";
|
||||||
if (!fillable && S.colorTarget === "fill") S.colorTarget = "stroke";
|
const second = isText ? true : fillSlotOn();
|
||||||
|
if (S.colorTarget !== "stroke" && !second) S.colorTarget = "stroke";
|
||||||
|
if (S.colorTarget === "bg" && !isText) S.colorTarget = "stroke";
|
||||||
const pair = runtime.el.querySelector(".iwb-editor-color-pair");
|
const pair = runtime.el.querySelector(".iwb-editor-color-pair");
|
||||||
if (pair) pair.dataset.colorMode = fillable ? "pair" : "single";
|
if (pair) pair.dataset.colorMode = isText ? "triple" : second ? "pair" : "single";
|
||||||
const strokeBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="stroke"]');
|
const strokeBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="stroke"]');
|
||||||
const fillBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="fill"]');
|
const fillBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="fill"]');
|
||||||
const textCtx = S.tool === "text" || !!S.selectedTextId && S.tool === "select";
|
const bgBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="bg"]');
|
||||||
const strokeName = textCtx ? "文字" : S.tool === "brush" || S.tool === "eraser" ? "画笔" : "描边";
|
const strokeName = isText ? "文字" : S.tool === "brush" || S.tool === "eraser" ? "画笔" : "描边";
|
||||||
if (strokeBtn) {
|
if (strokeBtn) {
|
||||||
const dot = strokeBtn.querySelector("i");
|
const dot = strokeBtn.querySelector("i");
|
||||||
if (dot) dot.style.backgroundColor = sl.stroke;
|
if (dot) dot.style.backgroundColor = sl.stroke;
|
||||||
strokeBtn.classList.toggle("active", S.colorTarget === "stroke");
|
strokeBtn.classList.toggle("active", S.colorTarget === "stroke");
|
||||||
strokeBtn.title = fillable ? `描边色 ${sl.stroke.toUpperCase()}:形状描边也用这个值。点开色板调色` : `${strokeName}色 ${sl.stroke.toUpperCase()}:点开色板调色`;
|
strokeBtn.title = isText ? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)` : second ? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色` : `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`;
|
||||||
const popEl = runtime.el.querySelector(".iwb-editor-color-pop");
|
const popEl = runtime.el.querySelector(".iwb-editor-color-pop");
|
||||||
strokeBtn.setAttribute("aria-expanded", String(!!(popEl && !popEl.hidden && S.colorTarget === "stroke")));
|
strokeBtn.setAttribute("aria-expanded", String(!!(popEl && !popEl.hidden && S.colorTarget === "stroke")));
|
||||||
}
|
}
|
||||||
@@ -4870,25 +4940,50 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
fillBtn.classList.toggle("is-none", !sl.fillOn);
|
fillBtn.classList.toggle("is-none", !sl.fillOn);
|
||||||
fillBtn.classList.toggle("is-follow", sl.follow && sl.fillOn);
|
fillBtn.classList.toggle("is-follow", sl.follow && sl.fillOn);
|
||||||
fillBtn.classList.toggle("active", S.colorTarget === "fill");
|
fillBtn.classList.toggle("active", S.colorTarget === "fill");
|
||||||
fillBtn.title = !sl.fillOn ? "填充:无(形状内部透明)。点开色板选色即可填充" : sl.follow ? "填充色:跟随描边色 " + sl.fill.toUpperCase() + ",点开可单独指定" : "填充色 " + sl.fill.toUpperCase() + ",点开调色";
|
const fc = String(sl.fill).toUpperCase();
|
||||||
|
fillBtn.title = isText ? sl.fillOn ? `文字描边色 ${fc}:沿字形外沿描一圈。点开调色,「无」= 去掉描边` : "文字描边:无(描边宽度 0)。点开选色会自动给 6px 描边" : !sl.fillOn ? "填充:无(形状内部透明)。点开色板选色即可填充" : sl.follow ? "填充色:跟随描边色 " + fc + ",点开可单独指定" : "填充色 " + fc + ",点开调色";
|
||||||
|
}
|
||||||
|
if (bgBtn) {
|
||||||
|
const dot = bgBtn.querySelector("i");
|
||||||
|
if (dot) {
|
||||||
|
dot.style.backgroundColor = sl.bg || "transparent";
|
||||||
|
dot.style.opacity = sl.bgOn ? String(sl.bgAlpha) : "";
|
||||||
|
}
|
||||||
|
bgBtn.classList.toggle("is-none", !sl.bgOn);
|
||||||
|
bgBtn.classList.toggle("active", S.colorTarget === "bg");
|
||||||
|
bgBtn.title = sl.bgOn ? `文本框底色 ${String(sl.bg || "").toUpperCase()}(${Math.round(sl.bgAlpha * 100)}% 不透明):垫在文字下面,「无」= 去掉底色` : "文本框底色:无(透明)。点开选色会自动开启底色";
|
||||||
|
bgBtn.setAttribute("aria-expanded", String(!!(runtime.el.querySelector(".iwb-editor-color-pop:not([hidden])") && S.colorTarget === "bg")));
|
||||||
}
|
}
|
||||||
runtime.el.querySelectorAll(".iwb-color-pop-tab").forEach((tab) => {
|
runtime.el.querySelectorAll(".iwb-color-pop-tab").forEach((tab) => {
|
||||||
const isFill = tab.dataset.colorSlot === "fill";
|
const slot = tab.dataset.colorSlot;
|
||||||
tab.classList.toggle("active", S.colorTarget === (isFill ? "fill" : "stroke"));
|
const isFill = slot === "fill";
|
||||||
|
const isBg = slot === "bg";
|
||||||
|
tab.classList.toggle("active", S.colorTarget === slot);
|
||||||
const dot = tab.querySelector("i");
|
const dot = tab.querySelector("i");
|
||||||
if (dot) dot.style.backgroundColor = isFill ? sl.fill : sl.stroke;
|
if (dot) {
|
||||||
|
dot.style.backgroundColor = isBg ? sl.bg || "transparent" : isFill ? sl.fill : sl.stroke;
|
||||||
|
if (isBg) dot.style.opacity = sl.bgOn ? String(sl.bgAlpha) : "";
|
||||||
|
}
|
||||||
const label = tab.querySelector(".iwb-color-pop-tab-label");
|
const label = tab.querySelector(".iwb-color-pop-tab-label");
|
||||||
if (label) label.textContent = isFill ? "填充" : fillable ? "描边" : strokeName;
|
if (label) label.textContent = isBg ? "底色" : isFill ? isText ? "描边" : "填充" : strokeName;
|
||||||
|
tab.title = isBg ? "正在调文本框底色(垫在文字下面)" : isFill ? isText ? "正在调文字描边色(沿字形外沿)" : "正在调填充色(形状内部颜色)" : isText ? "正在调文字色(文字本身的颜色)" : "正在调描边色";
|
||||||
if (isFill) {
|
if (isFill) {
|
||||||
tab.classList.toggle("is-none", !sl.fillOn);
|
tab.classList.toggle("is-none", !sl.fillOn);
|
||||||
tab.hidden = !fillable;
|
tab.hidden = !second;
|
||||||
|
}
|
||||||
|
if (isBg) {
|
||||||
|
tab.classList.toggle("is-none", !sl.bgOn);
|
||||||
|
tab.hidden = !isText;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const noneBtn = runtime.el.querySelector("[data-color-none]");
|
const noneBtn = runtime.el.querySelector("[data-color-none]");
|
||||||
if (noneBtn) {
|
if (noneBtn) {
|
||||||
const show = fillable && S.colorTarget === "fill";
|
const onBg = S.colorTarget === "bg" && isText;
|
||||||
|
const onFill = S.colorTarget === "fill" && second;
|
||||||
|
const show = onBg || onFill;
|
||||||
noneBtn.hidden = !show;
|
noneBtn.hidden = !show;
|
||||||
noneBtn.classList.toggle("active", show && !sl.fillOn);
|
noneBtn.classList.toggle("active", show && (onBg ? !sl.bgOn : !sl.fillOn));
|
||||||
|
noneBtn.title = onBg ? "无底色:文字后面完全透明" : isText ? "无描边:把描边宽度置 0,只留文字本身" : "无填充:形状内部透明,只留描边";
|
||||||
}
|
}
|
||||||
const cur = activeColor();
|
const cur = activeColor();
|
||||||
let matchPreset = false;
|
let matchPreset = false;
|
||||||
@@ -4940,12 +5035,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const b = runtime.el.querySelector('[data-action="toggleFill"]');
|
const b = runtime.el.querySelector('[data-action="toggleFill"]');
|
||||||
if (b) b.classList.toggle("active", !!S.rectFill);
|
if (b) b.classList.toggle("active", !!S.rectFill);
|
||||||
}
|
}
|
||||||
function updateLayerUI() {
|
|
||||||
const hasSel = !!(S.selectedTextId || S.selectedShapeId || S.layers.some((l) => l.id === S.selectedLayerId && l.id !== "base" && !l.locked));
|
|
||||||
runtime.el.querySelectorAll(".iwb-editor-layer-btn").forEach((b) => {
|
|
||||||
b.disabled = !hasSel;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
var TOOL_NAMES = {
|
var TOOL_NAMES = {
|
||||||
select: "选择 / 移动",
|
select: "选择 / 移动",
|
||||||
marquee: "框选",
|
marquee: "框选",
|
||||||
@@ -5010,12 +5099,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const own = !!sh && (owner === "pen" ? sh.type === "pen" : sh.type === "rect" || sh.type === "circle");
|
const own = !!sh && (owner === "pen" ? sh.type === "pen" : sh.type === "rect" || sh.type === "circle");
|
||||||
const fill = own ? !!sh.fill : owner === "pen" ? S.penFill : S.rectFill;
|
const fill = own ? !!sh.fill : owner === "pen" ? S.penFill : S.rectFill;
|
||||||
return `<span class="iwb-opt-label">样式</span>
|
return `<span class="iwb-opt-label">样式</span>
|
||||||
<button class="iwb-opt-btn${fill ? "" : " active"}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边 (Shift+X 切换)">描边</button>
|
<button class="iwb-opt-btn${fill ? "" : " active"}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边:内部透明,只留描边(快捷键 Shift+X 是交换填充/描边色)">描边</button>
|
||||||
<button class="iwb-opt-btn${fill ? " active" : ""}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`;
|
<button class="iwb-opt-btn${fill ? " active" : ""}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充:内部用填充色(快捷键 Shift+X 是交换填充/描边色)">实心</button>`;
|
||||||
}
|
}
|
||||||
var SHAPE_NAMES = { rect: "矩形", circle: "圆形", arrow: "箭头", pen: "钢笔路径" };
|
var SHAPE_NAMES = { rect: "矩形", circle: "圆形", arrow: "箭头", pen: "钢笔路径" };
|
||||||
var TEXT_STYLE_STATE_KEY = {
|
var TEXT_STYLE_STATE_KEY = {
|
||||||
fontWeight: "textWeight",
|
fontWeight: "textWeight",
|
||||||
|
fontFamily: "textFamily",
|
||||||
align: "textAlign",
|
align: "textAlign",
|
||||||
lineHeight: "textLineHeight",
|
lineHeight: "textLineHeight",
|
||||||
strokeWidth: "textStrokeWidth",
|
strokeWidth: "textStrokeWidth",
|
||||||
@@ -5030,6 +5120,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
fontWeight: String(pick("fontWeight", "textWeight", "bold")),
|
fontWeight: String(pick("fontWeight", "textWeight", "bold")),
|
||||||
|
// 字体走 fontKeyOf 收敛:老对象没有 fontFamily,或存了不认识的 key,都落回默认黑体
|
||||||
|
fontFamily: fontKeyOf({ fontFamily: pick("fontFamily", "textFamily", "sans") }),
|
||||||
align: pick("align", "textAlign", "left"),
|
align: pick("align", "textAlign", "left"),
|
||||||
lineHeight: Number(pick("lineHeight", "textLineHeight", TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
lineHeight: Number(pick("lineHeight", "textLineHeight", TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
||||||
strokeWidth: Math.max(0, Number(pick("strokeWidth", "textStrokeWidth", TEXT_DEFAULTS.strokeWidth)) || 0),
|
strokeWidth: Math.max(0, Number(pick("strokeWidth", "textStrokeWidth", TEXT_DEFAULTS.strokeWidth)) || 0),
|
||||||
@@ -5044,6 +5136,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const wBtn = (val, label, title) => `<button class="iwb-opt-btn${v.fontWeight === val ? " active" : ""}" data-opt-text="fontWeight" data-value="${val}" title="${title}">${label}</button>`;
|
const wBtn = (val, label, title) => `<button class="iwb-opt-btn${v.fontWeight === val ? " active" : ""}" data-opt-text="fontWeight" data-value="${val}" title="${title}">${label}</button>`;
|
||||||
const aBtn = (val, label, title) => `<button class="iwb-opt-btn${v.align === val ? " active" : ""}" data-opt-text="align" data-value="${val}" title="${title}">${label}</button>`;
|
const aBtn = (val, label, title) => `<button class="iwb-opt-btn${v.align === val ? " active" : ""}" data-opt-text="align" data-value="${val}" title="${title}">${label}</button>`;
|
||||||
return `<span class="iwb-opt-sep"></span>
|
return `<span class="iwb-opt-sep"></span>
|
||||||
|
<span class="iwb-opt-label">字体</span>
|
||||||
|
<select class="iwb-opt-select" data-opt-text="fontFamily" title="字体:改选中的这段文字,同时作为下一段新文字的默认字体">${TEXT_FONT_KEYS.map((k) => `<option value="${k}"${v.fontFamily === k ? " selected" : ""}>${TEXT_FONTS[k].label}</option>`).join("")}</select>
|
||||||
<span class="iwb-opt-label">字重</span>${wBtn("normal", "常规", "常规字重")}${wBtn("bold", "粗", "粗体(默认)")}${wBtn("900", "特粗", "特粗,封面标题用")}
|
<span class="iwb-opt-label">字重</span>${wBtn("normal", "常规", "常规字重")}${wBtn("bold", "粗", "粗体(默认)")}${wBtn("900", "特粗", "特粗,封面标题用")}
|
||||||
<span class="iwb-opt-label">对齐</span>${aBtn("left", "左", "多行时按左缘对齐")}${aBtn("center", "中", "多行时居中")}${aBtn("right", "右", "多行时按右缘对齐")}
|
<span class="iwb-opt-label">对齐</span>${aBtn("left", "左", "多行时按左缘对齐")}${aBtn("center", "中", "多行时居中")}${aBtn("right", "右", "多行时按右缘对齐")}
|
||||||
<span class="iwb-opt-label">行距</span>
|
<span class="iwb-opt-label">行距</span>
|
||||||
@@ -5076,7 +5170,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
}
|
}
|
||||||
const text = getSelectedText();
|
const text = getSelectedText();
|
||||||
if (text) {
|
if (text) {
|
||||||
return `<span class="iwb-opt-current">已选中:文字</span>` + rangeOpt("textSize", "字号", 8, 400, Math.round(text.fontSize || S.textSize), "px") + textStyleHTML(text) + '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>';
|
return `<span class="iwb-opt-current">已选中:文字</span>` + rangeOpt("textSize", "字号", 8, 400, Math.round(text.fontSize || S.textSize), "px") + textStyleHTML(text) + '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放 · 左上三格 = 文字色 / 描边 / 底色</span>';
|
||||||
}
|
}
|
||||||
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>` + selCmdHTML() + '<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里出现它的描边、实心与粗细</span>';
|
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>` + selCmdHTML() + '<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里出现它的描边、实心与粗细</span>';
|
||||||
}
|
}
|
||||||
@@ -5251,6 +5345,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (!stateKey) return;
|
if (!stateKey) return;
|
||||||
let value = raw;
|
let value = raw;
|
||||||
if (key === "bgFill") value = raw === true || raw === 1 || raw === "1" || raw === "true";
|
if (key === "bgFill") value = raw === true || raw === 1 || raw === "1" || raw === "true";
|
||||||
|
else if (key === "fontFamily") value = fontKeyOf({ fontFamily: raw });
|
||||||
else if (key === "lineHeight") value = clamp(Number(raw) || 125, 80, 300) / 100;
|
else if (key === "lineHeight") value = clamp(Number(raw) || 125, 80, 300) / 100;
|
||||||
else if (key === "strokeWidth") value = clamp(Number(raw) || 0, 0, 40);
|
else if (key === "strokeWidth") value = clamp(Number(raw) || 0, 0, 40);
|
||||||
else if (key === "strokeColor" || key === "bgColor") value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase();
|
else if (key === "strokeColor" || key === "bgColor") value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase();
|
||||||
@@ -5290,6 +5385,47 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
renderObjects();
|
renderObjects();
|
||||||
if (committed) radiusSnapDone = false;
|
if (committed) radiusSnapDone = false;
|
||||||
}
|
}
|
||||||
|
var textColorSnapDone = false;
|
||||||
|
function applyTextColor(key, color, opts) {
|
||||||
|
const skipHistory = !!(opts && opts.skipHistory);
|
||||||
|
const stateKey = TEXT_STYLE_STATE_KEY[key];
|
||||||
|
if (!stateKey) return;
|
||||||
|
const hex = String(color || "").toLowerCase();
|
||||||
|
if (!/^#[0-9a-f]{6}$/.test(hex)) return;
|
||||||
|
if (!skipHistory) rememberColor(hex);
|
||||||
|
S[stateKey] = hex;
|
||||||
|
if (key === "strokeColor" && !(Number(S.textStrokeWidth) > 0)) S.textStrokeWidth = 6;
|
||||||
|
if (key === "bgColor" && !S.textBgFill) S.textBgFill = true;
|
||||||
|
const t = getSelectedText();
|
||||||
|
if (t && !t.locked) {
|
||||||
|
if (!skipHistory && !textColorSnapDone) {
|
||||||
|
saveSnapshot("文字颜色");
|
||||||
|
textColorSnapDone = true;
|
||||||
|
}
|
||||||
|
t[key] = hex;
|
||||||
|
if (key === "strokeColor" && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth;
|
||||||
|
if (key === "bgColor" && !t.bgFill) t.bgFill = true;
|
||||||
|
renderObjects();
|
||||||
|
}
|
||||||
|
updateColorUI();
|
||||||
|
if (skipHistory) {
|
||||||
|
syncOptionBarSoon();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
textColorSnapDone = false;
|
||||||
|
syncOptionBar();
|
||||||
|
}
|
||||||
|
function applyColorNone() {
|
||||||
|
const sl = colorSlots();
|
||||||
|
if (sl.mode === "text") {
|
||||||
|
if (S.colorTarget === "bg") applyTextStyle("bgFill", "0", true);
|
||||||
|
else if (S.colorTarget === "fill") applyTextStyle("strokeWidth", 0, true);
|
||||||
|
updateColorUI();
|
||||||
|
syncOptionBar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
applyShapeColor("none");
|
||||||
|
}
|
||||||
function applyShapeColor(kind, raw, opts) {
|
function applyShapeColor(kind, raw, opts) {
|
||||||
const skipHistory = !!(opts && opts.skipHistory);
|
const skipHistory = !!(opts && opts.skipHistory);
|
||||||
const sh = getSelectedShape();
|
const sh = getSelectedShape();
|
||||||
@@ -5337,6 +5473,21 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
else syncOptionBar();
|
else syncOptionBar();
|
||||||
}
|
}
|
||||||
function applyPanelColor(color, opts) {
|
function applyPanelColor(color, opts) {
|
||||||
|
const sl = colorSlots();
|
||||||
|
if (sl.mode === "text") {
|
||||||
|
if (S.colorTarget === "fill") {
|
||||||
|
applyTextColor("strokeColor", color, opts);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (S.colorTarget === "bg") {
|
||||||
|
applyTextColor("bgColor", color, opts);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
applyColorChange(color, opts);
|
||||||
|
if (opts && opts.skipHistory) syncOptionBarSoon();
|
||||||
|
else syncOptionBar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (S.colorTarget === "fill" && fillSlotOn()) {
|
if (S.colorTarget === "fill" && fillSlotOn()) {
|
||||||
applyShapeColor("fill", color, opts);
|
applyShapeColor("fill", color, opts);
|
||||||
return;
|
return;
|
||||||
@@ -5347,7 +5498,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
else syncOptionBar();
|
else syncOptionBar();
|
||||||
}
|
}
|
||||||
function setColorTarget(slot) {
|
function setColorTarget(slot) {
|
||||||
S.colorTarget = slot === "fill" ? "fill" : "stroke";
|
S.colorTarget = slot === "fill" ? "fill" : slot === "bg" ? "bg" : "stroke";
|
||||||
updateColorUI();
|
updateColorUI();
|
||||||
}
|
}
|
||||||
var optionBarSyncRaf = 0;
|
var optionBarSyncRaf = 0;
|
||||||
@@ -5374,6 +5525,29 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
syncOptionBar();
|
syncOptionBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function swapShapeColors() {
|
||||||
|
const sh = getSelectedShape();
|
||||||
|
if (!sh || sh.locked) return false;
|
||||||
|
if (sh.type === "arrow") {
|
||||||
|
toast("箭头只有描边色,没有可交换的填充色", "info");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const stroke = sh.color || S.color;
|
||||||
|
const fill = sh.fillColor || null;
|
||||||
|
if (!fill) {
|
||||||
|
toast("填充色正跟随描边色(两者同一个颜色),无需交换", "info");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
saveSnapshot("交换填充与描边色");
|
||||||
|
sh.color = fill;
|
||||||
|
S.color = fill;
|
||||||
|
sh.fillColor = stroke;
|
||||||
|
S.shapeFillColor = stroke;
|
||||||
|
renderObjects();
|
||||||
|
updateColorUI();
|
||||||
|
syncOptionBar();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
function setOptionFromControl(el, committed) {
|
function setOptionFromControl(el, committed) {
|
||||||
const key = el && el.dataset ? el.dataset.opt : "";
|
const key = el && el.dataset ? el.dataset.opt : "";
|
||||||
if (!key) return;
|
if (!key) return;
|
||||||
@@ -5475,19 +5649,49 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const body = root.querySelector(".iwb-editor-optionbar-body");
|
const body = root.querySelector(".iwb-editor-optionbar-body");
|
||||||
if (body) {
|
if (body) {
|
||||||
body.addEventListener("mousedown", (e) => e.stopPropagation());
|
body.addEventListener("mousedown", (e) => e.stopPropagation());
|
||||||
body.addEventListener("input", (e) => setOptionFromControl(e.target, false));
|
let nativeColorSnapped = false;
|
||||||
body.addEventListener("change", (e) => {
|
const nativeColorOf = (t) => t && t.closest ? t.closest("[data-shape-color]") || t.closest("[data-opt-color]") : null;
|
||||||
const colorEl = e.target.closest ? e.target.closest("[data-opt-color]") : null;
|
const applyNativeColor = (el, preview) => {
|
||||||
|
const isShape = el.hasAttribute("data-shape-color");
|
||||||
|
const key = isShape ? el.dataset.shapeColor : el.dataset.optColor;
|
||||||
|
if (!nativeColorSnapped) {
|
||||||
|
const t = getSelectedText(), sh = getSelectedShape();
|
||||||
|
if (t && !t.locked || sh && !sh.locked) {
|
||||||
|
saveSnapshot(isShape ? "填充颜色" : "文字颜色");
|
||||||
|
nativeColorSnapped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isShape) applyShapeColor(key, el.value, { skipHistory: true });
|
||||||
|
else applyTextColor(key, el.value, { skipHistory: true });
|
||||||
|
if (preview) {
|
||||||
|
syncOptionBarSoon();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (nativeColorSnapped) rememberColor(String(el.value || "").toLowerCase());
|
||||||
|
nativeColorSnapped = false;
|
||||||
|
syncOptionBar();
|
||||||
|
};
|
||||||
|
body.addEventListener("input", (e) => {
|
||||||
|
const colorEl = nativeColorOf(e.target);
|
||||||
if (colorEl) {
|
if (colorEl) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
applyTextStyle(colorEl.dataset.optColor, colorEl.value, true);
|
applyNativeColor(colorEl, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setOptionFromControl(e.target, false);
|
||||||
|
});
|
||||||
|
body.addEventListener("change", (e) => {
|
||||||
|
const textSel = e.target && e.target.closest ? e.target.closest("select[data-opt-text]") : null;
|
||||||
|
if (textSel) {
|
||||||
|
e.stopPropagation();
|
||||||
|
applyTextStyle(textSel.dataset.optText, textSel.value, true);
|
||||||
syncOptionBar();
|
syncOptionBar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const shapeColorEl = e.target.closest ? e.target.closest("[data-shape-color]") : null;
|
const colorEl = nativeColorOf(e.target);
|
||||||
if (shapeColorEl) {
|
if (colorEl) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
applyShapeColor(shapeColorEl.dataset.shapeColor, shapeColorEl.value);
|
applyNativeColor(colorEl, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setOptionFromControl(e.target, true);
|
setOptionFromControl(e.target, true);
|
||||||
@@ -5593,7 +5797,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
bindColorPanel();
|
bindColorPanel();
|
||||||
bindColorPalette();
|
bindColorPalette();
|
||||||
bindFillToggle();
|
bindFillToggle();
|
||||||
bindLayerOrderButtons();
|
|
||||||
bindZoomButtons();
|
bindZoomButtons();
|
||||||
bindHistoryActions();
|
bindHistoryActions();
|
||||||
bindLayerAddActions();
|
bindLayerAddActions();
|
||||||
@@ -5637,7 +5840,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
function toggleColorPop(slot) {
|
function toggleColorPop(slot) {
|
||||||
const pop = runtime.el.querySelector(".iwb-editor-color-pop");
|
const pop = runtime.el.querySelector(".iwb-editor-color-pop");
|
||||||
if (!pop) return;
|
if (!pop) return;
|
||||||
const want = slot === "fill" ? "fill" : "stroke";
|
const want = slot === "fill" ? "fill" : slot === "bg" ? "bg" : "stroke";
|
||||||
if (!pop.hidden && S.colorTarget === want) {
|
if (!pop.hidden && S.colorTarget === want) {
|
||||||
closeColorPop();
|
closeColorPop();
|
||||||
return;
|
return;
|
||||||
@@ -5682,7 +5885,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const none = e.target.closest("[data-color-none]");
|
const none = e.target.closest("[data-color-none]");
|
||||||
if (none) {
|
if (none) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
applyShapeColor("none");
|
applyColorNone();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -5838,12 +6041,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function bindLayerOrderButtons() {
|
|
||||||
runtime.el.querySelectorAll(".iwb-editor-layer-btn").forEach((btn) => {
|
|
||||||
btn.addEventListener("mousedown", (e) => e.stopPropagation());
|
|
||||||
btn.addEventListener("click", () => moveLayer(btn.dataset.layer));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function bindZoomButtons() {
|
function bindZoomButtons() {
|
||||||
bindIf('[data-action="zoomOut"]', "click", (e) => {
|
bindIf('[data-action="zoomOut"]', "click", (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -6179,11 +6376,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const letterTools = {
|
const letterTools = {
|
||||||
v: "select",
|
v: "select",
|
||||||
m: "marquee",
|
m: "marquee",
|
||||||
l: "lasso",
|
a: "lasso",
|
||||||
|
l: "arrow",
|
||||||
b: "brush",
|
b: "brush",
|
||||||
e: "eraser",
|
e: "eraser",
|
||||||
p: "pen",
|
p: "pen",
|
||||||
t: "text",
|
t: "text",
|
||||||
|
r: "rect",
|
||||||
|
o: "circle",
|
||||||
u: "rect",
|
u: "rect",
|
||||||
c: "crop",
|
c: "crop",
|
||||||
i: "picker",
|
i: "picker",
|
||||||
@@ -6209,16 +6409,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
togglePanelsCollapsed();
|
togglePanelsCollapsed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!mod && e.shiftKey && key === "x") {
|
if (!mod && !e.altKey && e.shiftKey && key === "x") {
|
||||||
const sh = getSelectedShape();
|
if (swapShapeColors()) e.preventDefault();
|
||||||
if (sh && !sh.locked) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (sh.type === "arrow") {
|
|
||||||
toast("箭头没有实心样式", "info");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setShapeFill(!sh.fill, sh.type === "pen" ? "pen" : "rect");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const isBracket = e.key === "[" || e.key === "]" || e.code === "BracketLeft" || e.code === "BracketRight";
|
const isBracket = e.key === "[" || e.key === "]" || e.code === "BracketLeft" || e.code === "BracketRight";
|
||||||
@@ -7943,6 +8135,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
fontSize: t.fontSize,
|
fontSize: t.fontSize,
|
||||||
color: t.color,
|
color: t.color,
|
||||||
fontWeight: t.fontWeight,
|
fontWeight: t.fontWeight,
|
||||||
|
fontFamily: t.fontFamily,
|
||||||
align: t.align,
|
align: t.align,
|
||||||
lineHeight: t.lineHeight,
|
lineHeight: t.lineHeight,
|
||||||
strokeWidth: t.strokeWidth,
|
strokeWidth: t.strokeWidth,
|
||||||
@@ -7960,6 +8153,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
recentColors: (S.recentColors || []).slice(),
|
recentColors: (S.recentColors || []).slice(),
|
||||||
textDefaults: {
|
textDefaults: {
|
||||||
weight: S.textWeight,
|
weight: S.textWeight,
|
||||||
|
family: S.textFamily,
|
||||||
align: S.textAlign,
|
align: S.textAlign,
|
||||||
lineHeight: S.textLineHeight,
|
lineHeight: S.textLineHeight,
|
||||||
strokeWidth: S.textStrokeWidth,
|
strokeWidth: S.textStrokeWidth,
|
||||||
@@ -7970,6 +8164,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
},
|
},
|
||||||
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
|
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
|
||||||
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null },
|
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null },
|
||||||
|
// 色板当前在调哪一格:stroke / fill / bg(文字上下文里 fill=描边、bg=底色)
|
||||||
|
colorTarget: S.colorTarget,
|
||||||
selectedShapeId: S.selectedShapeId,
|
selectedShapeId: S.selectedShapeId,
|
||||||
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
||||||
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
||||||
@@ -8069,7 +8265,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) {
|
||||||
|
|||||||
@@ -176,20 +176,68 @@ if (!SKIP_PASTE) {
|
|||||||
check('点击「截图+图形」重叠区选中最上层截图(不被下方图形抢走)',
|
check('点击「截图+图形」重叠区选中最上层截图(不被下方图形抢走)',
|
||||||
Boolean(activeItem && activeItem.type === 'bitmap' && /图层/.test(activeItem.name)), JSON.stringify(activeItem))
|
Boolean(activeItem && activeItem.type === 'bitmap' && /图层/.test(activeItem.name)), JSON.stringify(activeItem))
|
||||||
|
|
||||||
|
// v1.13 起顶栏四个层级按钮已删除(改为图层拖动 + Ctrl+]/[ 快捷键),
|
||||||
|
// 这里改为断言「按钮确实没了」+ 用快捷键验证排序仍然可用。
|
||||||
|
check('顶栏不再有层级排序按钮(改用图层拖动 + Ctrl+]/[)',
|
||||||
|
(await page.locator('.iwb-editor-layer-btn').count()) === 0 &&
|
||||||
|
(await page.locator('.iwb-editor-header .iwb-editor-commands').count()) === 0,
|
||||||
|
'layerBtn=' + await page.locator('.iwb-editor-layer-btn').count())
|
||||||
|
|
||||||
|
const toolsTail = await page.evaluate(() => Array.from(document.querySelectorAll('.iwb-editor-tools > *'))
|
||||||
|
.slice(-2).map((n) => n.dataset.action || n.className))
|
||||||
|
check('工具栏最右两个按钮是「适应窗口 / 收起侧栏」',
|
||||||
|
JSON.stringify(toolsTail) === JSON.stringify(['zoomFit', 'togglePanels']), JSON.stringify(toolsTail))
|
||||||
|
|
||||||
const before = await panelSeq()
|
const before = await panelSeq()
|
||||||
await page.locator('.iwb-editor-layer-btn[data-layer="down"]').click()
|
const activeName = await page.evaluate(() => document.querySelector('.iwb-editor-layer-list .iwb-layer-item.active .iwb-layer-name')?.textContent)
|
||||||
|
await page.keyboard.press('Control+[') // 下移一层
|
||||||
const afterDown = await panelSeq()
|
const afterDown = await panelSeq()
|
||||||
check('「下移一层」改变图层顺序', before !== afterDown, before + ' → ' + afterDown)
|
check('Ctrl+[ 下移一层改变图层顺序', before !== afterDown, before + ' → ' + afterDown)
|
||||||
await page.locator('.iwb-editor-layer-btn[data-layer="up"]').click()
|
await page.keyboard.press('Control+]') // 上移一层
|
||||||
check('「上移一层」恢复原顺序', (await panelSeq()) === before, await panelSeq())
|
check('Ctrl+] 上移一层恢复原顺序', (await panelSeq()) === before, await panelSeq())
|
||||||
await page.locator('.iwb-editor-layer-btn[data-layer="bottom"]').click()
|
|
||||||
|
await page.keyboard.press('Control+Shift+[') // 置底
|
||||||
const afterBottom = await panelSeq()
|
const afterBottom = await panelSeq()
|
||||||
check('「置底」生效且原图仍在最底(元素不会消失)',
|
check('Ctrl+Shift+[ 置底生效(元素不会消失)',
|
||||||
afterBottom !== before && afterBottom.endsWith('原图'), afterBottom)
|
afterBottom !== before && afterBottom.endsWith(String(activeName)), afterBottom)
|
||||||
await page.locator('.iwb-editor-layer-btn[data-layer="top"]').click()
|
check('置底后原图不再被钉在最底 —— 图层可以压到原图下面(v1.13 解封)',
|
||||||
check('「置顶」生效', (await panelSeq()) !== afterBottom, await panelSeq())
|
!afterBottom.endsWith('原图'), afterBottom)
|
||||||
|
await page.keyboard.press('Control+Shift+]') // 置顶
|
||||||
|
check('Ctrl+Shift+] 置顶生效', (await panelSeq()) !== afterBottom, await panelSeq())
|
||||||
check('排序后仍只有一个选中项', (await activeCount()) === 1, 'active=' + await activeCount())
|
check('排序后仍只有一个选中项', (await activeCount()) === 1, 'active=' + await activeCount())
|
||||||
|
|
||||||
|
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
||||||
|
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
||||||
|
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||||||
|
const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]'
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||||||
|
const famBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||||||
|
await page.mouse.click(famBox.x + 60, famBox.y + 60)
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-text-input')
|
||||||
|
if (!el) return
|
||||||
|
el.focus()
|
||||||
|
el.value = '字体测试'
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.keyboard.press('Enter')
|
||||||
|
await page.waitForTimeout(400)
|
||||||
|
|
||||||
|
const famOpts = await page.locator(FAM_SEL + ' option').allTextContents()
|
||||||
|
check('真站选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体',
|
||||||
|
famOpts.length === 4, JSON.stringify(famOpts))
|
||||||
|
|
||||||
|
const wSans = ((await famDbg()).texts.find((t) => t.text === '字体测试') || {}).box
|
||||||
|
await page.selectOption(FAM_SEL, 'serif')
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const tSerif = (await famDbg()).texts.find((t) => t.text === '字体测试')
|
||||||
|
check('真站切换宋体生效,且中文宽度不变(全角等宽,版面不跳动)',
|
||||||
|
Boolean(tSerif && tSerif.fontFamily === 'serif' && wSans && Math.abs(tSerif.box.w - wSans.w) <= 1),
|
||||||
|
(wSans ? wSans.w : '?') + ' → ' + (tSerif ? tSerif.box.w : '?'))
|
||||||
|
await page.keyboard.press('Delete')
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
|
||||||
// 复原成画笔工具,避免影响后面「覆盖」链路的画笔取样
|
// 复原成画笔工具,避免影响后面「覆盖」链路的画笔取样
|
||||||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ check('编辑器打开 + 便利 UI 五区齐全(v1.2.4 起命令带取代「
|
|||||||
const q = (s) => Boolean(document.querySelector(s))
|
const q = (s) => Boolean(document.querySelector(s))
|
||||||
return q('.iwb-editor-optionbar') && q('.iwb-editor-statusbar') && q('.iwb-editor-sel-bar') &&
|
return q('.iwb-editor-optionbar') && q('.iwb-editor-statusbar') && q('.iwb-editor-sel-bar') &&
|
||||||
q('.iwb-editor-toast') && q('.iwb-editor-selection-overlay') && q('.iwb-editor-cursor-overlay') &&
|
q('.iwb-editor-toast') && q('.iwb-editor-selection-overlay') && q('.iwb-editor-cursor-overlay') &&
|
||||||
q('[data-action="download"]') && q('.iwb-editor-commands')
|
q('[data-action="download"]') && q('.iwb-editor-color-pair')
|
||||||
}))
|
}))
|
||||||
check('新增选区工具按钮', (await page.locator('.iwb-editor-tool[data-tool="marquee"]').count()) === 1 &&
|
check('新增选区工具按钮', (await page.locator('.iwb-editor-tool[data-tool="marquee"]').count()) === 1 &&
|
||||||
(await page.locator('.iwb-editor-tool[data-tool="lasso"]').count()) === 1)
|
(await page.locator('.iwb-editor-tool[data-tool="lasso"]').count()) === 1)
|
||||||
@@ -733,19 +733,25 @@ await page.keyboard.press('Control+z') // 撤销还原,恢复图层结构
|
|||||||
|
|
||||||
// ---- v1.2.4:顶栏命令带(「更多」图标化)/ 选择工具就地改形状参数 ----
|
// ---- v1.2.4:顶栏命令带(「更多」图标化)/ 选择工具就地改形状参数 ----
|
||||||
|
|
||||||
check('「更多」菜单已移除;顶栏只留顺序/视图命令,图层新建/导入/合并在图层面板标题栏', await page.evaluate(() => {
|
// v1.13 用户裁定:顶栏四个「置顶/上移/下移/置底」删掉(图层面板可拖 + Ctrl+]/[ 已覆盖),
|
||||||
|
// 「适应窗口 / 收起侧栏」搬到画布底部工具栏的最右侧。
|
||||||
|
check('顶栏不再有图层层级按钮;视图快捷搬到画布工具栏最右;图层新建/导入/合并仍在面板标题栏', await page.evaluate(() => {
|
||||||
const q = (s) => Boolean(document.querySelector(s))
|
const q = (s) => Boolean(document.querySelector(s))
|
||||||
const hdrCmds = document.querySelectorAll('.iwb-editor-header .iwb-editor-commands .iwb-editor-layer-btn').length
|
const hdrLayerBtns = document.querySelectorAll('.iwb-editor-header .iwb-editor-layer-btn').length
|
||||||
const titleBar = document.querySelector('.iwb-editor-layer-panel-header')
|
const titleBar = document.querySelector('.iwb-editor-layer-panel-header')
|
||||||
const addBtns = titleBar ? titleBar.querySelectorAll('.iwb-editor-layer-add-btn').length : 0
|
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"]')
|
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 &&
|
const tools = document.querySelector('.iwb-editor-canvas-wrap > .iwb-editor-tools')
|
||||||
addBtns === 4 && q('.iwb-editor-layer-panel-header [data-action="addBlankLayer"]') &&
|
const kids = tools ? [...tools.children] : []
|
||||||
|
const lastTwo = kids.slice(-2).map(el => el.dataset && el.dataset.action)
|
||||||
|
return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') &&
|
||||||
|
hdrLayerBtns === 0 && !hdrAdd && addBtns === 4 &&
|
||||||
|
!q('.iwb-editor-header [data-action="zoomFit"]') && !q('.iwb-editor-header [data-action="togglePanels"]') &&
|
||||||
|
lastTwo.join(',') === 'zoomFit,togglePanels' &&
|
||||||
|
q('.iwb-editor-layer-panel-header [data-action="addBlankLayer"]') &&
|
||||||
q('.iwb-editor-layer-panel-header [data-action="addBitmapLayer"]') &&
|
q('.iwb-editor-layer-panel-header [data-action="addBitmapLayer"]') &&
|
||||||
q('.iwb-editor-layer-panel-header [data-action="mergeLayers"]') &&
|
q('.iwb-editor-layer-panel-header [data-action="mergeLayers"]') &&
|
||||||
q('.iwb-editor-layer-panel-header [data-action="mergeVisible"]') &&
|
q('.iwb-editor-layer-panel-header [data-action="mergeVisible"]')
|
||||||
q('.iwb-editor-header [data-action="zoomFit"]') &&
|
|
||||||
q('.iwb-editor-header [data-action="togglePanels"]')
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
check('「还原原图」图标是循环重置(refresh)而不是垃圾桶', await page.evaluate(() => {
|
check('「还原原图」图标是循环重置(refresh)而不是垃圾桶', await page.evaluate(() => {
|
||||||
@@ -760,16 +766,17 @@ check('适应窗口按钮真的生效(放大后点它回到 fit 基线并居
|
|||||||
await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click()
|
await page.locator('.iwb-editor-zoom-btn[data-action="zoomIn"]').click()
|
||||||
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
|
const zoomed = (await dbg()).zoom
|
||||||
await page.locator('.iwb-editor-header [data-action="zoomFit"]').click()
|
await page.locator('.iwb-editor-tools [data-action="zoomFit"]').click()
|
||||||
const fitted = (await dbg()).zoom
|
const fitted = (await dbg()).zoom
|
||||||
return zoomed > 1 && Math.abs(fitted - 1) < 0.001
|
return zoomed > 1 && Math.abs(fitted - 1) < 0.001
|
||||||
})())
|
})())
|
||||||
|
|
||||||
check('PS 快捷键:V/M/L/B/E/P/T/U/C/I/H 切工具', await (async () => {
|
check('PS 快捷键:V/M/A/L/B/E/P/T/R/O/U/C/I/H 切工具', await (async () => {
|
||||||
// 先点一下工具按钮,保证焦点不在输入框里(isTyping() 会吞掉无修饰键快捷键)
|
// 先点一下工具按钮,保证焦点不在输入框里(isTyping() 会吞掉无修饰键快捷键)
|
||||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
const seq = [['v', 'select'], ['m', 'marquee'], ['l', 'lasso'], ['b', 'brush'], ['e', 'eraser'],
|
// v1.13 用户裁定:R = 矩形,O = 圆形,L = 箭头(套索从 L 让位到 A)
|
||||||
['p', 'pen'], ['t', 'text'], ['u', 'rect'], ['c', 'crop'], ['i', 'picker'], ['h', 'hand']]
|
const seq = [['v', 'select'], ['m', 'marquee'], ['a', 'lasso'], ['l', 'arrow'], ['b', 'brush'], ['e', 'eraser'],
|
||||||
|
['p', 'pen'], ['t', 'text'], ['r', 'rect'], ['o', 'circle'], ['u', 'rect'], ['c', 'crop'], ['i', 'picker'], ['h', 'hand']]
|
||||||
for (const [k, tool] of seq) {
|
for (const [k, tool] of seq) {
|
||||||
await page.keyboard.press(k)
|
await page.keyboard.press(k)
|
||||||
if ((await dbg()).tool !== tool) return false
|
if ((await dbg()).tool !== tool) return false
|
||||||
@@ -858,18 +865,8 @@ selShapeDbg = await dbg()
|
|||||||
check('选中矩形就地改线宽 9', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].lw === 9,
|
check('选中矩形就地改线宽 9', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].lw === 9,
|
||||||
JSON.stringify(selShapeDbg.shapes.slice(-1)))
|
JSON.stringify(selShapeDbg.shapes.slice(-1)))
|
||||||
|
|
||||||
// Shift+X:选中形状切 描边/实心(PS 风格;数字框输完值直接按也必须生效)
|
// Shift+X 的用例在文件末尾(它会把「下一个图形的填充色」也写成具体色值,
|
||||||
check('Shift+X 切换选中形状 描边/实心(对象与选项栏按钮同步)', await (async () => {
|
// 落在中间会污染后面「新建图形填充默认跟随描边色」那条断言)
|
||||||
await page.keyboard.press('Shift+x')
|
|
||||||
const d = await dbg()
|
|
||||||
const sh = d.shapes.find(s => s.id === d.selectedShapeId)
|
|
||||||
const btnActive = await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active'))
|
|
||||||
const flipped = sh && sh.fill === true && btnActive
|
|
||||||
await page.keyboard.press('Shift+x') // 切回描边,恢复现场
|
|
||||||
const d2 = await dbg()
|
|
||||||
const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId)
|
|
||||||
return flipped && sh2 && sh2.fill === false
|
|
||||||
})())
|
|
||||||
|
|
||||||
// 钢笔:闭合路径选中后同样可切描边/实心
|
// 钢笔:闭合路径选中后同样可切描边/实心
|
||||||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||||||
@@ -1035,7 +1032,7 @@ check('顶栏:标题最前 → 新建/覆盖/退出(统一中性色)→
|
|||||||
bg('.iwb-editor-header .iwb-editor-btn-replace') === bg('.iwb-editor-header .iwb-editor-btn-cancel')
|
bg('.iwb-editor-header .iwb-editor-btn-replace') === bg('.iwb-editor-header .iwb-editor-btn-cancel')
|
||||||
return btns === 'newNode,replace,cancel' &&
|
return btns === 'newNode,replace,cancel' &&
|
||||||
t.left < s.left && s.right < h.left &&
|
t.left < s.left && s.right < h.left &&
|
||||||
Boolean(q('.iwb-editor-header > .iwb-editor-divider')) &&
|
!q('.iwb-editor-header > .iwb-editor-commands') &&
|
||||||
unified && dl.textContent.trim() === '导出' &&
|
unified && dl.textContent.trim() === '导出' &&
|
||||||
!q('.iwb-editor-export-actions [data-action="newNode"]')
|
!q('.iwb-editor-export-actions [data-action="newNode"]')
|
||||||
}))
|
}))
|
||||||
@@ -1075,7 +1072,7 @@ check('画笔按住 Alt 临时吸色,松开 Alt 回到画笔(可连续取色
|
|||||||
: 'up: tool=' + d3.tool + ' alt=' + d3.altPicker
|
: 'up: tool=' + d3.tool + ' alt=' + d3.altPicker
|
||||||
})())
|
})())
|
||||||
|
|
||||||
// Shift+X:选中形状切 描边/实心(PS 风格,用户裁定 2026-11-04 晚)
|
// Shift+X 的用例见上面「Shift+X 交换填充色与描边色」(v1.13.1 起是交换语义,不再是实心/描边开关)
|
||||||
|
|
||||||
// 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层
|
// 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层
|
||||||
// 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z)
|
// 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z)
|
||||||
@@ -1434,17 +1431,26 @@ check('图层拖动排序:向下拖过下一行中线真的换位,z 同步
|
|||||||
return back.join(',') === before.join(',') ? true : 'Ctrl+Z 未复原 ' + back.join(',')
|
return back.join(',') === before.join(',') ? true : 'Ctrl+Z 未复原 ' + back.join(',')
|
||||||
})())
|
})())
|
||||||
|
|
||||||
check('图层拖动排序:拖到最底停在「原图」之上,原图永远压在最底层', await (async () => {
|
// v1.13(用户裁定「图层现在不能移动到原图的下面,这个需要解封」):
|
||||||
|
// 原图不再被钉在最底层,拖到原图那一行就能真的沉到它下面(典型用途:垫一张背景色层)。
|
||||||
|
check('图层拖动排序:可以拖到「原图」下面(原图不再是不可穿越的底)', await (async () => {
|
||||||
const before = await panelIds()
|
const before = await panelIds()
|
||||||
const movedId = before[0]
|
const movedId = before[0]
|
||||||
const baseKey = before[before.length - 1]
|
const baseKey = before[before.length - 1]
|
||||||
if (baseKey !== 'base') return '原图不在面板最底:' + before.join(',')
|
if (baseKey !== 'base') return '前置条件不成立,原图不在面板最底:' + before.join(',')
|
||||||
await dragRow(0, before.length - 1, true) // 一路拖到底(原图那一行)
|
await dragRow(0, before.length - 1, true) // 一路拖到底(原图那一行)
|
||||||
const after = await panelIds()
|
const after = await panelIds()
|
||||||
if (after[after.length - 1] !== 'base') return '原图没留在最底 ' + after.join(',')
|
const okBottom = after[after.length - 1] === movedId
|
||||||
if (after[after.length - 2] !== movedId) return '没落到原图之上 ' + after.join(',')
|
const okBase = after[after.length - 2] === 'base'
|
||||||
const zBase = await zOf('base')
|
const zBase = await zOf('base')
|
||||||
return zBase === 0 ? true : '原图 z=' + zBase + '(应恒为 0)'
|
// 后续用例默认「原图在最底」,这里撤销回原状,不给后面留暗坑
|
||||||
|
await page.keyboard.press('Control+z')
|
||||||
|
await page.waitForTimeout(260)
|
||||||
|
const back = await panelIds()
|
||||||
|
if (!okBottom) return '被拖的层没到最底 ' + after.join(',')
|
||||||
|
if (!okBase) return '原图没被压到倒数第二格 ' + after.join(',')
|
||||||
|
if (!(zBase > 0)) return '原图 z=' + zBase + '(应 > 0)'
|
||||||
|
return back.join(',') === before.join(',') ? true : '撤销未复原 ' + back.join(',')
|
||||||
})())
|
})())
|
||||||
|
|
||||||
check('图层拖动排序:位移不足 4px 算点击(不误判成拖动,顺序不变)', await (async () => {
|
check('图层拖动排序:位移不足 4px 算点击(不误判成拖动,顺序不变)', await (async () => {
|
||||||
@@ -1721,6 +1727,84 @@ check('文字支持多行(Shift+Enter 换行,包围盒高 ≈ 两行)',
|
|||||||
multiLine && vdbg.texts[0].box.h >= singleH * 2 - 2,
|
multiLine && vdbg.texts[0].box.h >= singleH * 2 - 2,
|
||||||
multiLine ? 'h=' + vdbg.texts[0].box.h + ' 单行=' + Math.round(singleH) : JSON.stringify(vdbg.texts))
|
multiLine ? 'h=' + vdbg.texts[0].box.h + ' 单行=' + Math.round(singleH) : JSON.stringify(vdbg.texts))
|
||||||
|
|
||||||
|
// ---- v1.14 字体选择:系统字体族(黑 / 宋 / 楷 / 圆)----
|
||||||
|
// 为什么只做系统字体:宿主 CSP 是 default-src 'self',font-src 回落它,第三方字体 CDN
|
||||||
|
// 会被浏览器直接拦掉;中文字体 2–64MB(本机宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB),
|
||||||
|
// 内联进 389KB 的插件不现实。系统字体栈 0 字节、同步可用,没有「字体没加载完就
|
||||||
|
// measureText」导致选中框和字形错位的时序问题 —— 这是内置字体方案最大的坑。
|
||||||
|
const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]'
|
||||||
|
const FAM_KEYS = ['sans', 'serif', 'kai', 'round']
|
||||||
|
const famCount = await page.locator(FAM_SEL).count()
|
||||||
|
const famOpts = famCount ? await page.locator(FAM_SEL + ' option').allTextContents() : []
|
||||||
|
check('选中文字后选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体',
|
||||||
|
famCount === 1 && famOpts.join(',') === '黑体,宋体,楷体,圆体',
|
||||||
|
'count=' + famCount + ' opts=' + famOpts.join(','))
|
||||||
|
|
||||||
|
// 切换字体要同时做两件事:写进选中的这段文字 + 成为下一段新文字的默认值
|
||||||
|
await page.selectOption(FAM_SEL, 'kai')
|
||||||
|
await page.waitForTimeout(240)
|
||||||
|
let famDbg = await dbg()
|
||||||
|
check('下拉切换字体写到选中文字,并同步「新建文字默认字体」',
|
||||||
|
famDbg.texts[0].fontFamily === 'kai' && famDbg.textDefaults.family === 'kai',
|
||||||
|
'obj=' + famDbg.texts[0].fontFamily + ' default=' + famDbg.textDefaults.family)
|
||||||
|
|
||||||
|
// 一次切换 = 一步历史
|
||||||
|
// 注意断言只查对象、不查 textDefaults:快照(history.js#snapshotState)只存
|
||||||
|
// texts/shapes/bitmaps/layerOrder,不含「新建文字默认值」—— 字重、对齐、行距
|
||||||
|
// 都是同一行为,撤销回到对象上一步的样子,但"下一段文字用什么样式"不会跟着回退。
|
||||||
|
await page.keyboard.press('Control+z')
|
||||||
|
await page.waitForTimeout(240)
|
||||||
|
famDbg = await dbg()
|
||||||
|
check('Ctrl+Z 撤销字体切换,文字对象回到上一个字体',
|
||||||
|
famDbg.texts[0].fontFamily === 'sans',
|
||||||
|
'obj=' + famDbg.texts[0].fontFamily)
|
||||||
|
|
||||||
|
// 中文是全角等宽:换字体不改字宽,所以切字体不会让已有的标注版面跳动。
|
||||||
|
// (拉丁字母和数字是比例宽,会伸缩 —— 这也是选择「左上角锚定」而不是居中的理由。)
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||||||
|
const cnPt = await imgToScreen(4, 30)
|
||||||
|
await page.mouse.click(cnPt.x, cnPt.y)
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-text-input')
|
||||||
|
el.focus()
|
||||||
|
el.value = '测试'
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.keyboard.press('Enter')
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const cnBefore = ((await dbg()).texts.find(t => t.text === '测试') || {}).box
|
||||||
|
await page.selectOption(FAM_SEL, 'serif')
|
||||||
|
await page.waitForTimeout(240)
|
||||||
|
const cnAfter = ((await dbg()).texts.find(t => t.text === '测试') || {}).box
|
||||||
|
check('换字体不改变中文宽度(全角等宽,版面不跳动)',
|
||||||
|
cnBefore && cnAfter && Math.abs(cnAfter.w - cnBefore.w) <= 1,
|
||||||
|
(cnBefore ? cnBefore.w : '?') + ' → ' + (cnAfter ? cnAfter.w : '?'))
|
||||||
|
|
||||||
|
// 脏值防御:不认识的 fontFamily 必须收敛回默认。否则整串 ctx.font 会失效、
|
||||||
|
// 静默退回浏览器默认字体 —— 画面上看不出报错,排查成本极高。
|
||||||
|
const badDispatch = await page.evaluate(() => {
|
||||||
|
const s = document.querySelector('.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]')
|
||||||
|
if (!s) return 'no-select'
|
||||||
|
const o = document.createElement('option')
|
||||||
|
o.value = 'NotAFont'
|
||||||
|
o.textContent = 'NotAFont'
|
||||||
|
s.appendChild(o)
|
||||||
|
s.value = 'NotAFont'
|
||||||
|
s.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
return 'dispatched'
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
const badDbg = await dbg()
|
||||||
|
check('不认识的字体值被收敛回默认(脏值不会写进 ctx.font)',
|
||||||
|
badDispatch === 'dispatched' && badDbg.texts.length > 0 &&
|
||||||
|
badDbg.texts.every(t => FAM_KEYS.indexOf(t.fontFamily) >= 0),
|
||||||
|
JSON.stringify(badDbg.texts.map(t => t.fontFamily)))
|
||||||
|
|
||||||
|
// 清理:这一小段是为字体用例新建的,删掉避免污染后面的像素断言
|
||||||
|
await page.keyboard.press('Delete')
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
|
||||||
// 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。
|
// 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。
|
||||||
// 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区,
|
// 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区,
|
||||||
// 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。
|
// 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。
|
||||||
@@ -1835,6 +1919,153 @@ const offStates = await page.evaluate(() => [...document.querySelectorAll('.iwb-
|
|||||||
check('描边宽度为 0 / 底色关闭时,对应色块标记为「未启用」(不再显示颜色本身)',
|
check('描边宽度为 0 / 底色关闭时,对应色块标记为「未启用」(不再显示颜色本身)',
|
||||||
offStates.length === 2 && offStates.every(o => o.off), JSON.stringify(offStates))
|
offStates.length === 2 && offStates.every(o => o.off), JSON.stringify(offStates))
|
||||||
|
|
||||||
|
// ---- v1.12:文字的三个颜色(文字 / 描边 / 底色)各自可调 ----
|
||||||
|
// 用户原话:「文本的内容需要描边与文字颜色的设定,还多一个文本框的底色,这里 3 个
|
||||||
|
// 颜色你来修正下,现在文本不支持描边与字体色切换」。文字对象本来就有三个颜色字段,
|
||||||
|
// 上一版把它们塞进「描边 / 填充」两格,第二格其实是形状的填充,点了毫无反应。
|
||||||
|
const textPair = await page.evaluate(() => {
|
||||||
|
const pair = document.querySelector('.iwb-editor-color-pair')
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
return {
|
||||||
|
mode: pair.dataset.colorMode,
|
||||||
|
tool: d.tool, selText: d.selectedTextId, target: d.colorTarget, texts: d.texts.length,
|
||||||
|
visible: [...pair.querySelectorAll('.iwb-editor-color-btn')].filter(b => b.offsetParent !== null).map(b => b.dataset.colorSlot)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('选中文字时工具栏给出「文字 / 描边 / 底色」三格',
|
||||||
|
textPair.mode === 'triple' && textPair.visible.join(',') === 'stroke,fill,bg', JSON.stringify(textPair))
|
||||||
|
|
||||||
|
const textChips = await page.evaluate(() => {
|
||||||
|
const cls = s => document.querySelector('.iwb-editor-color-pair [data-color-slot="' + s + '"]').className
|
||||||
|
return { fill: cls('fill'), bg: cls('bg') }
|
||||||
|
})
|
||||||
|
check('描边宽度 0 / 底色关闭时,文字的描边与底色格是「无」斜杠态(不露颜色本身)',
|
||||||
|
/is-none/.test(textChips.fill) && /is-none/.test(textChips.bg), JSON.stringify(textChips))
|
||||||
|
|
||||||
|
const textColorBefore = (await dbg()).texts[0].color
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const popTextTarget = await page.evaluate(() => {
|
||||||
|
const pop = document.querySelector('.iwb-editor-color-pop')
|
||||||
|
const tab = pop.querySelector('.iwb-color-pop-tab[data-color-slot="fill"]')
|
||||||
|
const bgTab = pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]')
|
||||||
|
return {
|
||||||
|
open: !pop.hidden,
|
||||||
|
fillActive: tab.classList.contains('active'),
|
||||||
|
fillLabel: tab.querySelector('.iwb-color-pop-tab-label').textContent,
|
||||||
|
bgVisible: !bgTab.hidden,
|
||||||
|
noneVisible: !pop.querySelector('[data-color-none]').hidden
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('点文字的「描边」格:色板目标是描边(tab 写「描边」),底色 tab 同时可选',
|
||||||
|
popTextTarget.open && popTextTarget.fillActive && popTextTarget.fillLabel === '描边' &&
|
||||||
|
popTextTarget.bgVisible && popTextTarget.noneVisible, JSON.stringify(popTextTarget))
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||||
|
el.value = '#00a3ff'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const textStroke = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const t = d.texts[0]
|
||||||
|
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
||||||
|
const opt = document.querySelector('.iwb-editor-optionbar-body [data-opt-color="strokeColor"]')
|
||||||
|
return {
|
||||||
|
sw: t.strokeWidth, sc: t.strokeColor, color: t.color, main: d.color, target: d.colorTarget,
|
||||||
|
chipBg: chip.querySelector('i').style.backgroundColor, chipCls: chip.className,
|
||||||
|
optVal: opt.value, optOff: opt.classList.contains('is-off')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('给文字选描边色:写进 strokeColor,描边宽度自动补 6px,文字色不受影响',
|
||||||
|
textStroke.sc === '#00a3ff' && textStroke.sw === 6 && textStroke.color === textColorBefore &&
|
||||||
|
textStroke.main !== '#00a3ff' && textStroke.optVal === '#00a3ff' && textStroke.optOff === false,
|
||||||
|
JSON.stringify(textStroke) + ' 文字色改前=' + textColorBefore)
|
||||||
|
check('描边格脱离斜杠态并显示真实颜色(工具栏与选项栏同一份值)',
|
||||||
|
!/is-none/.test(textStroke.chipCls) && /0, 163, 255/.test(textStroke.chipBg), textStroke.chipCls)
|
||||||
|
|
||||||
|
// 底色:同一套色板,第三格独立写 bgColor
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="bg"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const popBgTarget = await page.evaluate(() => {
|
||||||
|
const pop = document.querySelector('.iwb-editor-color-pop')
|
||||||
|
return {
|
||||||
|
bgActive: pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]').classList.contains('active'),
|
||||||
|
label: pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"] .iwb-color-pop-tab-label').textContent
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('点文字的「底色」格:色板切到底色', popBgTarget.bgActive && popBgTarget.label === '底色', JSON.stringify(popBgTarget))
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||||
|
el.value = '#123456'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const textBg = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const t = d.texts[0]
|
||||||
|
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="bg"]')
|
||||||
|
const bgBtn = document.querySelector('.iwb-editor-optionbar-body [data-opt-text="bgFill"]')
|
||||||
|
return {
|
||||||
|
bgColor: t.bgColor, bgFill: t.bgFill, sc: t.strokeColor,
|
||||||
|
chipBg: chip.querySelector('i').style.backgroundColor, chipCls: chip.className,
|
||||||
|
bgBtnOn: bgBtn.classList.contains('active')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('给文字选底色:写进 bgColor 并自动开启底色块(选项栏「底色」按钮同步点亮)',
|
||||||
|
textBg.bgColor === '#123456' && textBg.bgFill === true && textBg.sc === '#00a3ff' && textBg.bgBtnOn,
|
||||||
|
JSON.stringify(textBg))
|
||||||
|
check('底色格显示真实颜色(半透明显示,不是实心块)',
|
||||||
|
!/is-none/.test(textBg.chipCls) && /18, 52, 86/.test(textBg.chipBg), textBg.chipCls)
|
||||||
|
|
||||||
|
// 第一格「文字色」:改它不能顺手动到描边色
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||||
|
el.value = '#ff00aa'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const textColorSet = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const t = d.texts[0]
|
||||||
|
return { color: t.color, main: d.color, sc: t.strokeColor, bg: t.bgColor }
|
||||||
|
})
|
||||||
|
check('文字色 / 描边色 / 底色三格互不串(改一格不动另外两格)',
|
||||||
|
textColorSet.color === '#ff00aa' && textColorSet.main === '#ff00aa' &&
|
||||||
|
textColorSet.sc === '#00a3ff' && textColorSet.bg === '#123456', JSON.stringify(textColorSet))
|
||||||
|
|
||||||
|
// 「无」在底色格 = 关掉底色块,颜色留着
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="bg"]').click()
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
await page.evaluate(() => document.querySelector('[data-color-none]').click())
|
||||||
|
await page.waitForTimeout(260)
|
||||||
|
const bgNone = await page.evaluate(() => {
|
||||||
|
const t = window.__iwbEditor.__debug().texts[0]
|
||||||
|
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="bg"]')
|
||||||
|
return { bgFill: t.bgFill, bgColor: t.bgColor, cls: chip.className, noneActive: document.querySelector('[data-color-none]').classList.contains('active') }
|
||||||
|
})
|
||||||
|
check('底色格点「无」:关掉底色块、颜色留着,格子回到斜杠态',
|
||||||
|
bgNone.bgFill === false && bgNone.bgColor === '#123456' && /is-none/.test(bgNone.cls) && bgNone.noneActive,
|
||||||
|
JSON.stringify(bgNone))
|
||||||
|
|
||||||
|
// 切回形状 / 画笔:第三格必须收起来,别留一个空位让人猜
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const rectPairMode = await page.evaluate(() => {
|
||||||
|
const pair = document.querySelector('.iwb-editor-color-pair')
|
||||||
|
return {
|
||||||
|
mode: pair.dataset.colorMode,
|
||||||
|
visible: [...pair.querySelectorAll('.iwb-editor-color-btn')].filter(b => b.offsetParent !== null).map(b => b.dataset.colorSlot)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('切回矩形工具:工具栏回到「描边 + 填充」两格,底色格收起',
|
||||||
|
rectPairMode.mode === 'pair' && rectPairMode.visible.join(',') === 'stroke,fill', JSON.stringify(rectPairMode))
|
||||||
|
|
||||||
// 选区命令(全选/反选/取消)属于像素选区,必须待在选区工具里
|
// 选区命令(全选/反选/取消)属于像素选区,必须待在选区工具里
|
||||||
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||||||
await page.waitForTimeout(160)
|
await page.waitForTimeout(160)
|
||||||
@@ -2089,6 +2320,36 @@ check('填充色块随之变为「生效」态(不再是灰色斜纹)',
|
|||||||
shapeFilled.fillSwatchOff === false && shapeFilled.fillBtnOn === true,
|
shapeFilled.fillSwatchOff === false && shapeFilled.fillBtnOn === true,
|
||||||
JSON.stringify({ off: shapeFilled.fillSwatchOff, btn: shapeFilled.fillBtnOn }))
|
JSON.stringify({ off: shapeFilled.fillSwatchOff, btn: shapeFilled.fillBtnOn }))
|
||||||
|
|
||||||
|
// v1.13 用户反馈「填充色状态不能实时在矢量图形上显示颜色变化」:
|
||||||
|
// 原生 <input type="color"> 在系统取色器里拖色时只派发 input,关闭取色器才派发 change。
|
||||||
|
// 以前只接 change ⇒ 取色器开着的整段时间画布一动不动。这里只发 input(模拟拖色中),
|
||||||
|
// 断言画布像素当场就变 —— 不发 change 也不许等。
|
||||||
|
const purpleBeforeLive = await countColorInVec([122, 31, 162], 8)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||||||
|
el.value = '#7a1fa2'
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
const liveFill = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes[d.shapes.length - 1]
|
||||||
|
return { fillColor: s.fillColor, fill: s.fill }
|
||||||
|
})
|
||||||
|
const purpleAfterLive = await countColorInVec([122, 31, 162], 8)
|
||||||
|
check('填充色块只发 input(取色器还开着)画布就实时变色,不必等 change',
|
||||||
|
liveFill.fillColor === '#7a1fa2' && purpleAfterLive > 200, JSON.stringify(liveFill) + ' 紫色像素 ' + purpleBeforeLive + '→' + purpleAfterLive)
|
||||||
|
|
||||||
|
// 拖动结束:change 收尾,历史只多一条(拖动中不逐帧拍快照)
|
||||||
|
const hBeforeNative = (await dbg()).history
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
check('原生取色器拖动一次只记 1 步撤销(预览不逐帧拍快照)',
|
||||||
|
(await dbg()).history - hBeforeNative === 0, 'history +' + ((await dbg()).history - hBeforeNative))
|
||||||
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
||||||
el.value = '#3388ff'
|
el.value = '#3388ff'
|
||||||
@@ -2206,6 +2467,50 @@ check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (asy
|
|||||||
return t.indexOf('选中') >= 0
|
return t.indexOf('选中') >= 0
|
||||||
})())
|
})())
|
||||||
|
|
||||||
|
// ---- v1.13.1:Shift+X 改成「交换填充色与描边色」(以前是 实心/描边 开关)----
|
||||||
|
// 旧语义下按一次,填充被关掉、描边纹丝不动 —— 用户的原话是「丢失填充色」。
|
||||||
|
// 放在最后跑:交换会把「下一个图形的填充色」也写成具体色值,前面有条断言要求它是 null。
|
||||||
|
const shiftXSwap = await (async () => {
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
|
const a = { x: imgBox.x + imgBox.width * 0.10, y: imgBox.y + imgBox.height * 0.10 }
|
||||||
|
const b = { x: imgBox.x + imgBox.width * 0.30, y: imgBox.y + imgBox.height * 0.30 }
|
||||||
|
await page.mouse.move(a.x, a.y); await page.mouse.down()
|
||||||
|
await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up()
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
|
await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2)
|
||||||
|
await page.waitForTimeout(150)
|
||||||
|
// 给个独立填充色,描边色保持主色,两边不同才看得出交换
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||||||
|
el.value = '#22cc55'
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
const d0 = await dbg()
|
||||||
|
const sh0 = d0.shapes.find(s => s.id === d0.selectedShapeId)
|
||||||
|
if (!sh0) return { ok: false, detail: '没选中形状' }
|
||||||
|
const stroke0 = sh0.color, fill0 = sh0.fillColor, fillOn0 = sh0.fill
|
||||||
|
await page.keyboard.press('Shift+x')
|
||||||
|
const d1 = await dbg()
|
||||||
|
const sh1 = d1.shapes.find(s => s.id === d1.selectedShapeId)
|
||||||
|
const swapped = Boolean(sh1 && sh1.color === fill0 && sh1.fillColor === stroke0 && sh1.fill === fillOn0)
|
||||||
|
await page.keyboard.press('Shift+x') // 再按一次回到原样
|
||||||
|
const d2 = await dbg()
|
||||||
|
const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId)
|
||||||
|
const back = Boolean(sh2 && sh2.color === stroke0 && sh2.fillColor === fill0 && sh2.fill === fillOn0)
|
||||||
|
return {
|
||||||
|
ok: swapped && back,
|
||||||
|
detail: JSON.stringify({
|
||||||
|
原: { 描边: stroke0, 填充: fill0, 填充开: fillOn0 },
|
||||||
|
交换后: sh1 && { 描边: sh1.color, 填充: sh1.fillColor, 填充开: sh1.fill },
|
||||||
|
再按: sh2 && { 描边: sh2.color, 填充: sh2.fillColor }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
||||||
|
|
||||||
await page.locator('[data-action="cancel"]').click()
|
await page.locator('[data-action="cancel"]').click()
|
||||||
const openState = await poll(async () => page.evaluate(() => window.__openState))
|
const openState = await poll(async () => page.evaluate(() => window.__openState))
|
||||||
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',
|
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',
|
||||||
|
|||||||
Reference in new issue
Block a user