Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31866a2407 | ||
|
|
9c938887c1 | ||
|
|
b63771f6e4 | ||
|
|
73a29715d3 |
No files matched your search
@@ -234,6 +234,230 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
|||||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||||
|
|
||||||
|
## 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:工具栏变成「描边 + 填充」两格,填充可以设「无」
|
||||||
|
|
||||||
|
用户这次的反馈是「工具栏的调色、描边、填充 3 个位置调色有问题,应该是 2 个调色,
|
||||||
|
就是描边与填充,但现在没跟工具栏的调色关联上」,以及「填色里还要一个取消颜色的按钮」。
|
||||||
|
|
||||||
|
### 1. 颜色从三处收敛成两处
|
||||||
|
|
||||||
|
以前工具栏只有一个色点(主色),选项栏另有两个色块(描边 / 填充)。看起来是三个调色口,
|
||||||
|
其中工具栏那个**不参与填充**,于是「填充跟工具栏没关系」。现在工具栏就是
|
||||||
|
**描边 + 填充两个槽**(PS 式前/背景色叠放):点哪个槽,色板就调哪个槽。
|
||||||
|
|
||||||
|
- 描边槽 = `S.color`(也是画笔色、文字色、形状描边色,仍然一个值)
|
||||||
|
- 填充槽 = 形状自己的 `fillColor`,没单独设过就跟随描边色(右下角一个蓝三角)
|
||||||
|
- 色板新增当前目标切换(描边 / 填充),调色器、吸管、hex、推荐色、最近色全部按目标写
|
||||||
|
- 选项栏那两个色块与工具栏**双向同步**:改哪边,另一边立刻跟上
|
||||||
|
- 只有一笔颜色概念的工具(画笔、橡皮、文字、箭头)只显示一个槽,不留空格
|
||||||
|
|
||||||
|
### 2. 填充可以设「无」
|
||||||
|
|
||||||
|
色板里多了「无」按钮(只在调填充时出现):点它把 `fill` 关掉,形状内部透明、只留描边;
|
||||||
|
**颜色本身保留**,下次再选颜色还是它。无填充时工具栏填充槽显示为**灰底红斜杠**,
|
||||||
|
不露颜色 —— 露着上次的颜色会被当成「现在填的就是它」。
|
||||||
|
|
||||||
|
`S.colorTarget` 记录当前在调哪一格,`source` 只有一处:`colorSlots()` 同时供给工具栏、
|
||||||
|
色板头部、hex 与调色器,避免「一个概念两种颜色」再次出现。
|
||||||
|
|
||||||
|
## v1.10.0:颜色语义统一 / 选中框改实线 / 选区命令归位 / 矢量图形补描边与填充
|
||||||
|
|
||||||
|
这一版全部来自同一张界面截图上的四个疑问:「字体颜色有 3 个位置」「那个黑色应该换成
|
||||||
|
默认的参数」「字体这里有选区,这个不该出现」「选区工具反而没有这些按钮」。
|
||||||
|
四个都是真实缺陷,不是偏好。
|
||||||
|
|
||||||
|
### 1. 三处颜色各司其职(不再是三个长得一样的色块)
|
||||||
|
|
||||||
|
以前 `#ff4444` / `#ffffff` / `#000000` / `0.68` 这些默认值散在 `state.js`、`text.js`、
|
||||||
|
`events.js` 三处,改一处另两处不跟,界面上就出现「同一个概念三种颜色」。现在:
|
||||||
|
|
||||||
|
- `text.js` 导出 `TEXT_DEFAULTS`,**默认值单点定义**,`state.js` 与选项栏都从这里取;
|
||||||
|
- 描边色 / 底色 / 图形描边色的色块**统一外观**,但**标记生效状态**:
|
||||||
|
描边宽度为 0、底色关闭、图形处于「描边模式」时,色块显示为**灰色斜纹**
|
||||||
|
(不是颜色本身),语义是「这里还没有颜色」。以前半透明灰化不够——深色照样是一块黑方块,
|
||||||
|
用户会以为「设了个黑色没生效」;
|
||||||
|
- 文字底色默认从纯黑 `#000000` 改为中性近黑 `#101014`(68% 透明),色块按真实不透明度显示,
|
||||||
|
所见即所得,不再是一块死黑;
|
||||||
|
- 选描边色时若宽度为 0,自动给 6px(与「选底色即开底色」同一条原则:选了就是要用)。
|
||||||
|
|
||||||
|
### 2. 选中框从虚线改成实线
|
||||||
|
|
||||||
|
虚线在修图软件里的语义是**像素选区(蚂蚁线)**。文字/图形外面套一圈虚线,
|
||||||
|
用户会以为「莫名其妙多出来一个选区」,还删不掉。现在对象选中一律实线 + 四角手柄
|
||||||
|
(`objects.js` 的文字/形状、`layers.js` 的位图图层三处同步),虚线只留给真正的像素选区。
|
||||||
|
|
||||||
|
### 3. 选区命令(全选/反选/取消)归位到选区工具
|
||||||
|
|
||||||
|
那三个命令操作的是像素选区,跟文字对象没关系。以前它们挂在「选中文字/图形」的选项栏里,
|
||||||
|
选中一段文字就冒出来,看着像文字自带了选区;而真正的**矩形/套索选区工具**反而没有。
|
||||||
|
现在:选区工具(矩形、套索)有,选择工具「未选中任何元素」时也有,选中对象时不再出现。
|
||||||
|
|
||||||
|
### 4. 矢量图形补上描边色与填充色
|
||||||
|
|
||||||
|
- 每个形状新增独立的 `fillColor`;**描边色不再另起一份**,直接就是主色
|
||||||
|
(左侧色板 / 吸管 / 选项栏一个真相源,四处永远同步);
|
||||||
|
- `fillColor === null` 表示「跟随描边色」,于是新画的实心图形是**同色实心**,
|
||||||
|
换主色整块跟着变;一旦单独选过填充色就固定下来;
|
||||||
|
- 矩形/圆形/钢笔/箭头的选项栏都出现 `描边 ■` / `填充 ■` 色块(箭头没有填充区域,只给描边色),
|
||||||
|
选中已有图形时读它自己的值,没选中时改的是「下一次新建」的默认值;
|
||||||
|
- 选填充色即自动切到实心,色块随之从斜纹变成实际颜色;「样式 描边/实心」按钮
|
||||||
|
也改成读**选中对象自己**的 `fill`(以前只看全局默认值,选中一个已实心的矩形,
|
||||||
|
按钮却高亮「描边」,和画面反着来)。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` **172 条全部通过**(新增 10 条:默认色不写死、色块生效态、
|
||||||
|
选区命令归位、选中框实线覆盖率 ≥0.85、图形描边/填充色与实际像素)。
|
||||||
|
|
||||||
|
## v1.9.1:输入框贴住点击点 / 选区图标归位 / 底色一选就亮
|
||||||
|
|
||||||
|
v1.9.0 上线后用户反馈的三处「操作与实际反应不相符」。
|
||||||
|
|
||||||
|
### 1. 文字输入框跑到点击点的左上方
|
||||||
|
|
||||||
|
`showTextInput()` 用 `canvasStack` 的矩形换算屏幕坐标,但 stack 的尺寸是
|
||||||
|
`(imgW + 2 × overlayPad) × scale`,图片在 stack 内部还额外偏移了 `pad × scale`
|
||||||
|
(图层 canvas 的 `left/top`)。拿它算比例会偏小、又漏掉这段偏移,两个误差同向叠加,
|
||||||
|
输入框就整体挪到了左上。改为用 `textCanvas` 的矩形(与图层 canvas 同基准,
|
||||||
|
精确等于图片显示区域),并按 `textarea` 的边框 2px + 内边距 8/4px 反向偏移,
|
||||||
|
让「输入框里文字的起点」正好压在点击点上——提交后 `drawTextObject` 也从 `t.x/t.y` 起画,
|
||||||
|
两者位置一致。
|
||||||
|
|
||||||
|
### 2. 选「选择」工具那三个选区图标就不见了
|
||||||
|
|
||||||
|
两个原因叠在一起:
|
||||||
|
|
||||||
|
- 兜底分支里 `selCmdHTML()` 排在 `hint` **之后**,而 `.iwb-opt-hint` 带 `margin-left: auto`,
|
||||||
|
会把自己和后面的一切推到最右;
|
||||||
|
- 更关键的是 `.iwb-opt-sep` 写成了 `margin: 0 4px 0 auto`——分隔线自带 `auto`,
|
||||||
|
会把**分隔线之后的内容整组**推到最右侧。选项栏一旦排满(文字样式那一行),
|
||||||
|
这组按钮就被顶出可视区。
|
||||||
|
|
||||||
|
修法:分隔线只负责分组(`margin: 0 2px`),留白交给末尾的 `hint`;
|
||||||
|
选区按钮排在 `hint` 之前。现在「文字」和「选择」两个工具下都是同一组三个图标,
|
||||||
|
且未选中任何元素时也在(选区命令本来就是全局的)。
|
||||||
|
|
||||||
|
### 3. 设了文字底色却看不到
|
||||||
|
|
||||||
|
底色其实一直在画,问题是:**只改颜色、没点「底色」开关**时 `bgFill` 仍是 `false`,
|
||||||
|
画布上什么都不会变。用户于是以为底色没生效,或者被别的颜色盖住了。
|
||||||
|
|
||||||
|
- 改 `bgColor` 时自动把 `bgFill` 打开(选了颜色就是要用它),按钮的 `active` 同步亮起;
|
||||||
|
- 顺带修掉一个更硬的 bug:**「底色」按钮只能开、不能关**。它的 `data-value`
|
||||||
|
在生成 HTML 时就写死成 `${v.bgFill ? '0' : '1'}`,状态变了没人更新,
|
||||||
|
于是每次点击都传「开启」。现在 `syncOptionBar()` 会按当前状态翻面。
|
||||||
|
- 默认底色透明度 0.55 → 0.68:浅色/花色底图上 0.55 太透,容易被当成没生效。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` **162 条全部通过**(新增输入框落点误差 ≤3px、
|
||||||
|
Esc 取消不留空对象、选择工具未选中仍有 3 个图标、只选颜色即自动开底色 4 条)。
|
||||||
|
|
||||||
## v1.9.0:文字样式包 / 吸附参考线 / 圆角与最近色 / 复制到剪贴板
|
## v1.9.0:文字样式包 / 吸附参考线 / 圆角与最近色 / 复制到剪贴板
|
||||||
|
|
||||||
一次补齐四个高频缺口,都属于「没有它就得切回 PS」的那类。
|
一次补齐四个高频缺口,都属于「没有它就得切回 PS」的那类。
|
||||||
|
|||||||
@@ -311,6 +311,10 @@ 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.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.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
|
| 文字样式与吸附 | ✅ v1.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
|
||||||
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
||||||
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
||||||
@@ -329,6 +333,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 魔棒 | 宿主 CSP 未放行 `worker-src blob:` ⇒ 不能用 Worker 做连通域;放二期,主线程分块 + 让出帧,且限制最大像素数 |
|
| 魔棒 | 宿主 CSP 未放行 `worker-src blob:` ⇒ 不能用 Worker 做连通域;放二期,主线程分块 + 让出帧,且限制最大像素数 |
|
||||||
| CSP | 单文件经典脚本 IIFE;禁 `eval` / `new Function` / ESM / CDN;样式 JS 注入 `<style>`;`toBlob` 要求 origin-clean ⇒ 远程图片必须 `fetch → blob → dataURL`(现有 `onPaste` 已按此实现) |
|
| CSP | 单文件经典脚本 IIFE;禁 `eval` / `new Function` / ESM / CDN;样式 JS 注入 `<style>`;`toBlob` 要求 origin-clean ⇒ 远程图片必须 `fetch → blob → dataURL`(现有 `onPaste` 已按此实现) |
|
||||||
| 宿主争抢 paste | 宿主在 window 气泡阶段也监听粘贴(建 ref 节点 + 下载)。编辑器继续在 document 捕获阶段 `stopImmediatePropagation()`。新增「复制选区到系统剪贴板」需要 `ClipboardItem` + 用户手势 + 权限,失败必须有 toast 降级 |
|
| 宿主争抢 paste | 宿主在 window 气泡阶段也监听粘贴(建 ref 节点 + 下载)。编辑器继续在 document 捕获阶段 `stopImmediatePropagation()`。新增「复制选区到系统剪贴板」需要 `ClipboardItem` + 用户手势 + 权限,失败必须有 toast 降级 |
|
||||||
|
| 选项栏横向排布 | `.iwb-editor-optionbar-body` 是 `overflow-x: auto` 的 flex。**任何 `margin-left: auto` 都会把其后内容整组推到最右**,排满时直接滚出可视区 —— `v1.9.1` 就是 `.iwb-opt-sep` 带了 `auto`,导致选区按钮在选择工具下「消失」。留白只允许放在末尾的 `.iwb-opt-hint`;中文双字按钮必须 `white-space: nowrap`,否则会竖排 |
|
||||||
| 草稿持久化 | `ctx.storage` 是 localStorage 命名空间小 KV(`get/set/remove/keys`),**不能塞像素**;`ctx.settings` 适合存输出预设与面板开合。若要做工程草稿,只能存元数据 + 宿主节点引用;真要存图层像素需插件自建 IndexedDB 库(必须自带 `onupgradeneeded` 建表,宿主踩过这个坑)或与宿主协商新能力 |
|
| 草稿持久化 | `ctx.storage` 是 localStorage 命名空间小 KV(`get/set/remove/keys`),**不能塞像素**;`ctx.settings` 适合存输出预设与面板开合。若要做工程草稿,只能存元数据 + 宿主节点引用;真要存图层像素需插件自建 IndexedDB 库(必须自带 `onupgradeneeded` 建表,宿主踩过这个坑)或与宿主协商新能力 |
|
||||||
| 节点模型 | 宿主 `setNodeImage` / `createImageNode` 只收一张图;导出即扁平化。要做「可继续编辑的工程」需要宿主侧支持节点附加数据 ⇒ 属于跨仓变更,P5 再评估 |
|
| 节点模型 | 宿主 `setNodeImage` / `createImageNode` 只收一张图;导出即扁平化。要做「可继续编辑的工程」需要宿主侧支持节点附加数据 ⇒ 属于跨仓变更,P5 再评估 |
|
||||||
| 上游关系 | 编辑器移植自 `iwb-plaus/iwb-cutout-extension`,README 已警告 1.0.5 的 z 序修复不能整目录覆盖回去。P0 的大改等于正式分叉,应在 README 明确改为「一次性移植 + 独立演进」,避免以后误回灌 |
|
| 上游关系 | 编辑器移植自 `iwb-plaus/iwb-cutout-extension`,README 已警告 1.0.5 的 z 序修复不能整目录覆盖回去。P0 的大改等于正式分叉,应在 README 明确改为「一次性移植 + 独立演进」,避免以后误回灌 |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.9.0",
|
"version": "1.13.0",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -1674,7 +1674,11 @@
|
|||||||
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:hover:not(:disabled) { background: #45475a; }
|
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:hover:not(:disabled) { background: #45475a; }
|
||||||
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
||||||
/* 选区命令(全选/反选/取消):v1.2.5 起放在「选择」工具的选项栏里,不再占竖工具条 */
|
/* 选区命令(全选/反选/取消):v1.2.5 起放在「选择」工具的选项栏里,不再占竖工具条 */
|
||||||
.iwb-opt-sep { width: 1px; height: 18px; background: #313244; margin: 0 4px 0 auto; flex: 0 0 auto; }
|
/* 分隔线只负责「分组」,不负责「推到右边」。
|
||||||
|
原来写的是 margin: 0 4px 0 auto —— auto 会把分隔线之后的内容整组推到最右侧,
|
||||||
|
在选项栏已经排满的情况下(文字样式那一行)直接把后面的选区按钮顶出可视区,
|
||||||
|
看起来就是「这个工具下没有那几个按钮」。留白交给末尾的 .iwb-opt-hint。 */
|
||||||
|
.iwb-opt-sep { width: 1px; height: 18px; background: #313244; margin: 0 2px; flex: 0 0 auto; }
|
||||||
.iwb-opt-selcmd {
|
.iwb-opt-selcmd {
|
||||||
width: 26px; height: 26px; min-width: 26px; padding: 0; border: 0; border-radius: 7px;
|
width: 26px; height: 26px; min-width: 26px; padding: 0; border: 0; border-radius: 7px;
|
||||||
background: #26263a; color: #cdd6f4; flex: 0 0 auto;
|
background: #26263a; color: #cdd6f4; flex: 0 0 auto;
|
||||||
@@ -1709,26 +1713,106 @@
|
|||||||
================================================================ */
|
================================================================ */
|
||||||
.iwb-editor-modal { position: relative; }
|
.iwb-editor-modal { position: relative; }
|
||||||
|
|
||||||
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn {
|
/* ---- v1.11:工具栏颜色双槽(描边 + 填充) ----
|
||||||
width: 32px; height: 32px; min-width: 32px; flex: 0 0 auto; padding: 0;
|
一个 30px 的按钮位上叠两颗:左上 19px 是描边,右下 19px 是填充。
|
||||||
border: 0; border-radius: 9px; background: #313244; cursor: pointer;
|
描边压在上面(最常用),填充露出右下角,一眼能看出是两格、谁是上级。
|
||||||
display: inline-flex; align-items: center; justify-content: center;
|
只有「描边」概念的工具(画笔/文字/箭头)把填充槽藏起来,描边槽放大占满,
|
||||||
|
不留一个空位让人猜。 */
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair {
|
||||||
|
position: relative; width: 30px; height: 30px; flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn:hover,
|
.iwb-editor-color-pair .iwb-editor-color-btn {
|
||||||
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn.active { background: #45475a; }
|
position: absolute; width: 19px; height: 19px; min-width: 0; padding: 0;
|
||||||
.iwb-editor-color-btn i {
|
border: 0; border-radius: 6px; background: #181825; cursor: pointer;
|
||||||
width: 18px; height: 18px; border-radius: 50%; display: block; background: #ff4444;
|
display: inline-flex; align-items: center; justify-content: center;
|
||||||
box-shadow: 0 0 0 2px #181825, 0 0 0 3px #585b70;
|
box-shadow: 0 0 0 1.5px #585b70;
|
||||||
|
}
|
||||||
|
.iwb-editor-color-pair [data-color-slot="stroke"] { left: 0; top: 0; z-index: 2; }
|
||||||
|
.iwb-editor-color-pair [data-color-slot="fill"] { right: 0; bottom: 0; z-index: 1; }
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn:hover { box-shadow: 0 0 0 2px #89b4fa; }
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn.active { box-shadow: 0 0 0 2px #e8a735; }
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn i {
|
||||||
|
width: 12px; height: 12px; border-radius: 3px; display: block;
|
||||||
|
background-color: #ff4444; background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
/* 无填充:不露颜色本身,画一道红斜杠 —— 留着上次的颜色会被当成「现在填的就是它」 */
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn.is-none i {
|
||||||
|
background-color: #45475a !important;
|
||||||
|
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||||
|
}
|
||||||
|
/* 填充色还在「跟随描边色」:右下角一个小三角,表示它不是自己指定的 */
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn.is-follow::after {
|
||||||
|
content: ''; position: absolute; right: 0; bottom: 0;
|
||||||
|
border-left: 4px solid transparent; border-bottom: 4px solid #89b4fa;
|
||||||
|
}
|
||||||
|
.iwb-editor-color-pair[data-color-mode="single"] [data-color-slot="fill"] { display: none; }
|
||||||
|
.iwb-editor-color-pair[data-color-mode="single"] [data-color-slot="stroke"] {
|
||||||
|
left: 1px; top: 1px; width: 28px; height: 28px; border-radius: 8px;
|
||||||
|
}
|
||||||
|
.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; align-items: center; gap: 10px;
|
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;
|
||||||
background: rgba(24, 24, 37, 0.97); border: 1px solid #313244;
|
background: rgba(24, 24, 37, 0.97); border: 1px solid #313244;
|
||||||
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
|
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
|
||||||
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
|
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
|
||||||
}
|
}
|
||||||
.iwb-editor-color-pop[hidden] { display: none; }
|
.iwb-editor-color-pop[hidden] { display: none; }
|
||||||
|
/* 弹层头部:说明现在调的是描边还是填充,并可直接换;右侧是「无」(仅填充) */
|
||||||
|
.iwb-color-pop-head { display: flex; align-items: center; gap: 6px; }
|
||||||
|
.iwb-color-pop-tab {
|
||||||
|
display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
|
||||||
|
border: 1px solid transparent; border-radius: 7px; background: #232334;
|
||||||
|
color: #a6adc8; font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab i {
|
||||||
|
width: 11px; height: 11px; border-radius: 3px; display: block;
|
||||||
|
background-color: #ff4444; background-size: 100% 100%;
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab:hover { background: #313244; color: #cdd6f4; }
|
||||||
|
.iwb-color-pop-tab.active { background: #313244; color: #fff; border-color: #e8a735; }
|
||||||
|
.iwb-color-pop-tab.is-none i {
|
||||||
|
background-color: #45475a !important;
|
||||||
|
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab[hidden] { display: none; }
|
||||||
|
.iwb-color-pop-none {
|
||||||
|
margin-left: auto; display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
|
||||||
|
border: 1px dashed #585b70; border-radius: 7px; background: transparent; color: #a6adc8;
|
||||||
|
font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-color-pop-none span {
|
||||||
|
width: 11px; height: 11px; border-radius: 3px; display: block; background-color: #45475a;
|
||||||
|
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||||
|
}
|
||||||
|
.iwb-color-pop-none:hover { border-color: #f38ba8; color: #f38ba8; }
|
||||||
|
.iwb-color-pop-none.active { border-style: solid; border-color: #f38ba8; color: #f38ba8; background: rgba(243, 139, 168, 0.12); }
|
||||||
|
.iwb-color-pop-none[hidden] { display: none; }
|
||||||
|
.iwb-color-pop-body { display: flex; align-items: center; gap: 10px; }
|
||||||
.iwb-color-pop-picker { display: flex; gap: 8px; flex: 0 0 auto; }
|
.iwb-color-pop-picker { display: flex; gap: 8px; flex: 0 0 auto; }
|
||||||
.iwb-editor-color-pop .iwb-color-sv { width: 180px; height: 104px; flex: 0 0 180px; }
|
.iwb-editor-color-pop .iwb-color-sv { width: 180px; height: 104px; flex: 0 0 180px; }
|
||||||
.iwb-editor-color-pop .iwb-color-hue { width: 16px; height: 104px; flex: 0 0 16px; }
|
.iwb-editor-color-pop .iwb-color-hue { width: 16px; height: 104px; flex: 0 0 16px; }
|
||||||
@@ -1892,6 +1976,21 @@
|
|||||||
}
|
}
|
||||||
.iwb-opt-color::-webkit-color-swatch-wrapper { padding: 2px; }
|
.iwb-opt-color::-webkit-color-swatch-wrapper { padding: 2px; }
|
||||||
.iwb-opt-color::-webkit-color-swatch { border: 0; border-radius: 3px; }
|
.iwb-opt-color::-webkit-color-swatch { border: 0; border-radius: 3px; }
|
||||||
|
/* 底色是半透明的:色块按真实不透明度显示(--sw-a),看起来和画布上的效果一致,
|
||||||
|
不再是一块实心纯黑让人以为「又多了一个字体颜色」 */
|
||||||
|
.iwb-opt-color { opacity: var(--sw-a, 1); }
|
||||||
|
/* 该颜色当前没生效(描边宽度 0 / 底色未开 / 图形是描边模式):
|
||||||
|
不再显示那块颜色本身,而是显示为一块灰色斜纹 —— 语义是「这里还没有颜色」。
|
||||||
|
只做半透明灰化的话,纯黑/深色照样是一块黑方块,用户仍会以为「设了个黑色没生效」。 */
|
||||||
|
.iwb-opt-color.is-off {
|
||||||
|
opacity: 1;
|
||||||
|
border-style: dashed;
|
||||||
|
border-color: #4b4f66;
|
||||||
|
background: repeating-linear-gradient(45deg, #353849 0 3px, #262939 3px 6px);
|
||||||
|
}
|
||||||
|
.iwb-opt-color.is-off::-webkit-color-swatch { opacity: 0; }
|
||||||
|
/* 选项栏里色块旁边的分组标签,和「描边 / 底色」这类双字按钮区分开 */
|
||||||
|
.iwb-opt-swatch-label { color: #7f849c; font-size: 11px; flex: 0 0 auto; }
|
||||||
|
|
||||||
/* 「最近使用」:色板弹层里 4 列 × 2 行,空的时候整块隐藏(不占位) */
|
/* 「最近使用」:色板弹层里 4 列 × 2 行,空的时候整块隐藏(不占位) */
|
||||||
.iwb-editor-color-pop .iwb-editor-recent-colors {
|
.iwb-editor-color-pop .iwb-editor-recent-colors {
|
||||||
|
|||||||
@@ -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,14 +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.3):点开就是完整色板,侧栏不再放调色板 -->
|
<!-- 颜色(v1.11 两格 → v1.12 文字三格):
|
||||||
<button type="button" class="iwb-editor-color-btn" data-action="toggleColorPop" aria-expanded="false" title="颜色:点开色板(调色器 / 吸管 / 推荐色)"><i></i></button>
|
形状下是「描边 + 填充」两格叠放在一个按钮位里(PS 式前/背景色);
|
||||||
|
文字下是「文字 / 描边 / 底色」三格横排 —— 文字对象天生就有三个颜色,
|
||||||
|
只给两格必然有一格无处安放(用户反馈「文本不支持描边与字体色切换」)。
|
||||||
|
点哪格就调哪格:色板只有一套,写谁由 S.colorTarget 决定。
|
||||||
|
关掉的那格画斜杠,跟随描边色的填充块带一个小三角角标。 -->
|
||||||
|
<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="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>
|
||||||
<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>
|
||||||
|
|
||||||
@@ -147,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>
|
||||||
|
|
||||||
@@ -161,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>
|
||||||
@@ -231,6 +233,16 @@ 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.12 文字三格):标明「现在调的是哪个颜色」,
|
||||||
|
并可直接切换。与工具栏那几个色块是同一组槽位,两边高亮完全一致。
|
||||||
|
「无」只对「可以没有」的颜色有意义:文字色没有无,描边/底色/填充才有。 -->
|
||||||
|
<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" 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>
|
||||||
|
</div>
|
||||||
|
<div class="iwb-color-pop-body">
|
||||||
<div class="iwb-color-pop-picker">
|
<div class="iwb-color-pop-picker">
|
||||||
<div class="iwb-color-sv"><span></span></div>
|
<div class="iwb-color-sv"><span></span></div>
|
||||||
<div class="iwb-color-hue"><span></span></div>
|
<div class="iwb-color-hue"><span></span></div>
|
||||||
@@ -258,6 +270,7 @@ import { bindEvents } from './events.js'
|
|||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#000000" style="background:#000000" title="#000000"></button>
|
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#000000" style="background:#000000" title="#000000"></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ 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 { 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'
|
||||||
import { loadImage } from './dom.js'
|
import { loadImage } from './dom.js'
|
||||||
@@ -255,11 +257,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
showTextInput(pos.x, pos.y)
|
showTextInput(pos.x, pos.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 吸管工具的按下:取样并应用颜色后退出吸管模式 */
|
/** 吸管工具的按下:取样并应用颜色后退出吸管模式。
|
||||||
|
* v1.11:按当前目标槽写(吸管取色 = 给正在调的那一格上色,而不是永远改主色)。 */
|
||||||
function onPickerMouseDown(pos) {
|
function onPickerMouseDown(pos) {
|
||||||
const s = sampleColor(pos)
|
const s = sampleColor(pos)
|
||||||
if (s && s.a > 0) {
|
if (s && s.a > 0) {
|
||||||
applyColorChange(rgbToHex(s.r, s.g, s.b))
|
applyPanelColor(rgbToHex(s.r, s.g, s.b))
|
||||||
}
|
}
|
||||||
exitPicker()
|
exitPicker()
|
||||||
return
|
return
|
||||||
@@ -535,6 +538,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
x1: S.startX, y1: S.startY,
|
x1: S.startX, y1: S.startY,
|
||||||
x2: pos.x, y2: pos.y,
|
x2: pos.x, y2: pos.y,
|
||||||
color: S.color,
|
color: S.color,
|
||||||
|
fillColor: S.shapeFillColor,
|
||||||
lw: Math.max(1, S.shapeLineWidth),
|
lw: Math.max(1, S.shapeLineWidth),
|
||||||
lineWidth: Math.max(1, S.shapeLineWidth),
|
lineWidth: Math.max(1, S.shapeLineWidth),
|
||||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||||
@@ -740,6 +744,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
x1: S.startX, y1: S.startY,
|
x1: S.startX, y1: S.startY,
|
||||||
x2: pos.x, y2: pos.y,
|
x2: pos.x, y2: pos.y,
|
||||||
color: S.color,
|
color: S.color,
|
||||||
|
fillColor: S.shapeFillColor, // null = 跟随描边色(改主色时整块跟着变)
|
||||||
lw: Math.max(1, S.shapeLineWidth),
|
lw: Math.max(1, S.shapeLineWidth),
|
||||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||||
@@ -793,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'))
|
||||||
@@ -860,22 +864,193 @@ 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() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 文字的三个颜色槽(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 调色器全从这里读,
|
||||||
|
* 避免「一个概念三种颜色」再次出现。
|
||||||
|
* 文字:stroke=文字色 / fill=描边色 / bg=底色;
|
||||||
|
* 形状:stroke=描边色 / fill=填充色(没单独设过就跟随描边色,follow=true)。 */
|
||||||
|
export function colorSlots() {
|
||||||
|
const ctx = colorContext()
|
||||||
|
if (ctx.kind === 'text') return textColorSlots(ctx.text)
|
||||||
|
const sh = ctx.shape
|
||||||
|
const stroke = (sh && sh.color) || S.color
|
||||||
|
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)
|
||||||
|
return {
|
||||||
|
mode: ctx.kind === 'shape' ? 'shape' : 'single',
|
||||||
|
stroke, fill: rawFill || stroke, fillOn, follow: !rawFill,
|
||||||
|
bg: null, bgOn: false, bgAlpha: 1,
|
||||||
|
strokeName: '描边', fillName: '填充', bgName: '底色'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 色板/hex/吸管要写的那一格颜色 */
|
||||||
|
function activeColor() {
|
||||||
|
const sl = colorSlots()
|
||||||
|
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 isText = sl.mode === 'text'
|
||||||
|
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')
|
||||||
|
if (pair) pair.dataset.colorMode = isText ? 'triple' : (second ? 'pair' : 'single')
|
||||||
|
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 bgBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="bg"]')
|
||||||
|
// 同一个格子在不同上下文里名字不同:文字下第一格是「文字色」,画笔下是「画笔色」。
|
||||||
|
// 一律写「描边」会让人在文字工具下以为这个颜色跟文字没关系。
|
||||||
|
const strokeName = isText ? '文字' : (S.tool === 'brush' || S.tool === 'eraser' ? '画笔' : '描边')
|
||||||
|
if (strokeBtn) {
|
||||||
|
const dot = strokeBtn.querySelector('i')
|
||||||
|
if (dot) dot.style.backgroundColor = sl.stroke
|
||||||
|
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
||||||
|
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')
|
||||||
|
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
||||||
|
}
|
||||||
|
if (fillBtn) {
|
||||||
|
const dot = fillBtn.querySelector('i')
|
||||||
|
if (dot) dot.style.backgroundColor = sl.fill
|
||||||
|
fillBtn.classList.toggle('is-none', !sl.fillOn)
|
||||||
|
fillBtn.classList.toggle('is-follow', sl.follow && sl.fillOn)
|
||||||
|
fillBtn.classList.toggle('active', S.colorTarget === 'fill')
|
||||||
|
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')))
|
||||||
|
}
|
||||||
|
// 色板头部:tab 与工具栏的格子一一对应,谁在调谁高亮
|
||||||
|
runtime.el.querySelectorAll('.iwb-color-pop-tab').forEach(tab => {
|
||||||
|
const slot = tab.dataset.colorSlot
|
||||||
|
const isFill = slot === 'fill'
|
||||||
|
const isBg = slot === 'bg'
|
||||||
|
tab.classList.toggle('active', S.colorTarget === slot)
|
||||||
|
const dot = tab.querySelector('i')
|
||||||
|
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')
|
||||||
|
// 只有一根槽时,标题写「描边」会显得莫名其妙:这时它就是当前的唯一颜色
|
||||||
|
if (label) label.textContent = isBg ? '底色' : (isFill ? (isText ? '描边' : '填充') : strokeName)
|
||||||
|
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]')
|
||||||
|
if (noneBtn) {
|
||||||
|
const onBg = S.colorTarget === 'bg' && isText
|
||||||
|
const onFill = S.colorTarget === 'fill' && second
|
||||||
|
const show = onBg || onFill
|
||||||
|
noneBtn.hidden = !show
|
||||||
|
noneBtn.classList.toggle('active', show && (onBg ? !sl.bgOn : !sl.fillOn))
|
||||||
|
noneBtn.title = onBg
|
||||||
|
? '无底色:文字后面完全透明'
|
||||||
|
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边')
|
||||||
|
}
|
||||||
|
|
||||||
|
const cur = activeColor()
|
||||||
let matchPreset = false
|
let matchPreset = false
|
||||||
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
|
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
|
||||||
const on = (s.dataset.color || '').toLowerCase() === S.color.toLowerCase()
|
const on = (s.dataset.color || '').toLowerCase() === cur.toLowerCase()
|
||||||
if (on) matchPreset = true
|
if (on) matchPreset = true
|
||||||
s.classList.toggle('active', on)
|
s.classList.toggle('active', on)
|
||||||
})
|
})
|
||||||
const panelHex = runtime.el.querySelector('.iwb-editor-color-hex')
|
const panelHex = runtime.el.querySelector('.iwb-editor-color-hex')
|
||||||
const hexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
const hexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
||||||
if (hexInput && document.activeElement !== hexInput) hexInput.value = S.color.toUpperCase()
|
if (hexInput && document.activeElement !== hexInput) hexInput.value = cur.toUpperCase()
|
||||||
// 工具栏色点:色板收起时它就是唯一的颜色指示,必须始终跟随 S.color
|
runtime.el.querySelectorAll('.iwb-editor-color-panel-swatch').forEach(sw => sw.classList.toggle('active', (sw.dataset.panelColor || '').toLowerCase() === cur.toLowerCase()))
|
||||||
const colorDot = runtime.el.querySelector('.iwb-editor-color-btn i')
|
if (panelHex) panelHex.textContent = cur.toUpperCase()
|
||||||
if (colorDot) colorDot.style.background = S.color
|
const rgb = hexToRgb(cur)
|
||||||
runtime.el.querySelectorAll('.iwb-editor-color-panel-swatch').forEach(sw => sw.classList.toggle('active', (sw.dataset.panelColor || '').toLowerCase() === S.color.toLowerCase()))
|
|
||||||
if (panelHex) panelHex.textContent = S.color.toUpperCase()
|
|
||||||
const rgb = hexToRgb(S.color)
|
|
||||||
const max = Math.max(rgb.r, rgb.g, rgb.b) / 255, min = Math.min(rgb.r, rgb.g, rgb.b) / 255
|
const max = Math.max(rgb.r, rgb.g, rgb.b) / 255, min = Math.min(rgb.r, rgb.g, rgb.b) / 255
|
||||||
const d = max - min
|
const d = max - min
|
||||||
let h = 0
|
let h = 0
|
||||||
@@ -890,7 +1065,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (custom) {
|
if (custom) {
|
||||||
custom.classList.toggle('active', !matchPreset)
|
custom.classList.toggle('active', !matchPreset)
|
||||||
const inp = custom.querySelector('input')
|
const inp = custom.querySelector('input')
|
||||||
if (inp) inp.value = S.color
|
if (inp) inp.value = cur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -909,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:就地选项栏 / 状态栏 / 更多菜单 ============
|
||||||
|
|
||||||
@@ -972,11 +1140,31 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
|
|
||||||
/** 描边/实心切换按钮组:owner 区分两套默认值(rect=矩形/圆,pen=钢笔)。
|
/** 描边/实心切换按钮组:owner 区分两套默认值(rect=矩形/圆,pen=钢笔)。
|
||||||
* 钢笔只在闭合路径上才有填充面积,但开关本身一直可点,便于先选后画。 */
|
* 钢笔只在闭合路径上才有填充面积,但开关本身一直可点,便于先选后画。 */
|
||||||
function fillStyleHTML(owner) {
|
/** 矢量图形的描边色 / 填充色块(v1.10)。
|
||||||
const fill = owner === 'pen' ? S.penFill : S.rectFill
|
* 描边色就是主色 S.color —— 左侧色板、吸管、选项栏三处读写同一个值,
|
||||||
|
* 不再为「形状描边」单独造一个色,否则又是一处「同一个概念两个颜色」。
|
||||||
|
* 填充色独立存在形状自己的 fillColor 上,没单独设过就跟随描边色(同色实心)。
|
||||||
|
* 填充关着的时候色块置灰(is-off),一眼能看出哪个颜色正在生效。 */
|
||||||
|
function shapeColorHTML(sh, owner) {
|
||||||
|
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
|
||||||
|
const sl = colorSlots()
|
||||||
|
let html = '<span class="iwb-opt-label">描边</span>'
|
||||||
|
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`
|
||||||
|
if (owner) {
|
||||||
|
html += '<span class="iwb-opt-label">填充</span>'
|
||||||
|
+ `<input type="color" class="iwb-opt-color${sl.fillOn ? '' : ' is-off'}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? '' : ';当前无填充,选色会自动切成实心'}">`
|
||||||
|
}
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillStyleHTML(owner, sh) {
|
||||||
|
// 选中对象时以它自己的 fill 为准:以前只看全局 S.rectFill,
|
||||||
|
// 选中一个已经实心的矩形,选项栏却高亮「描边」,按钮和画面反着来。
|
||||||
|
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)
|
||||||
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: '钢笔路径' }
|
||||||
@@ -999,11 +1187,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
return {
|
return {
|
||||||
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
|
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
|
||||||
align: pick('align', 'textAlign', 'left'),
|
align: pick('align', 'textAlign', 'left'),
|
||||||
lineHeight: Number(pick('lineHeight', 'textLineHeight', 1.25)) || 1.25,
|
lineHeight: Number(pick('lineHeight', 'textLineHeight', TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
||||||
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', 0)) || 0),
|
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', TEXT_DEFAULTS.strokeWidth)) || 0),
|
||||||
strokeColor: pick('strokeColor', 'textStrokeColor', '#ffffff'),
|
strokeColor: pick('strokeColor', 'textStrokeColor', TEXT_DEFAULTS.strokeColor),
|
||||||
bgFill: !!pick('bgFill', 'textBgFill', false),
|
bgFill: !!pick('bgFill', 'textBgFill', TEXT_DEFAULTS.bgFill),
|
||||||
bgColor: pick('bgColor', 'textBgColor', '#000000')
|
bgColor: pick('bgColor', 'textBgColor', TEXT_DEFAULTS.bgColor),
|
||||||
|
bgAlpha: Number(pick('bgAlpha', 'textBgAlpha', TEXT_DEFAULTS.bgAlpha)) || TEXT_DEFAULTS.bgAlpha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1021,9 +1210,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
<span class="iwb-opt-sep"></span>
|
<span class="iwb-opt-sep"></span>
|
||||||
<span class="iwb-opt-label">描边</span>
|
<span class="iwb-opt-label">描边</span>
|
||||||
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
|
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
|
||||||
<input type="color" class="iwb-opt-color" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色">
|
<input type="color" class="iwb-opt-color${v.strokeWidth > 0 ? '' : ' is-off'}" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色${v.strokeWidth > 0 ? '' : ';描边宽度是 0,选色会自动给 6px'}">
|
||||||
<button class="iwb-opt-btn${v.bgFill ? ' active' : ''}" data-opt-text="bgFill" data-value="${v.bgFill ? '0' : '1'}" title="给文字加一块半透明底色,压在花背景上也能看清">底色</button>
|
<button class="iwb-opt-btn${v.bgFill ? ' active' : ''}" data-opt-text="bgFill" data-value="${v.bgFill ? '0' : '1'}" title="给文字加一块底色,压在花背景上也能看清">底色</button>
|
||||||
<input type="color" class="iwb-opt-color" data-opt-color="bgColor" value="${v.bgColor}" title="底色颜色(55% 透明)">`
|
<input type="color" class="iwb-opt-color${v.bgFill ? '' : ' is-off'}" data-opt-color="bgColor" value="${v.bgColor}" style="--sw-a:${v.bgAlpha}" title="底色 ${Math.round(v.bgAlpha * 100)}% 不透明(色块按真实半透明显示);选色会自动开启底色">`
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 选择工具:只有选中了元素才出该元素的参数。
|
/** 选择工具:只有选中了元素才出该元素的参数。
|
||||||
@@ -1054,26 +1243,30 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
||||||
// 圆角只对矩形有意义(圆形本来就是圆的,箭头/钢笔没有这个概念)
|
// 圆角只对矩形有意义(圆形本来就是圆的,箭头/钢笔没有这个概念)
|
||||||
+ (t === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, Math.round(sh.radius || 0), 'px') : '')
|
+ (t === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, Math.round(sh.radius || 0), 'px') : '')
|
||||||
+ (t === 'arrow' ? '' : fillStyleHTML(owner))
|
// 描边色 / 填充色:箭头没有填充区域,只给描边色
|
||||||
|
+ shapeColorHTML(sh, t === 'arrow' ? null : owner)
|
||||||
|
+ (t === 'arrow' ? '' : fillStyleHTML(owner, sh))
|
||||||
+ (t === 'pen' && !sh.closed
|
+ (t === 'pen' && !sh.closed
|
||||||
? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>'
|
? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>'
|
||||||
: '')
|
: '')
|
||||||
+ selCmdHTML()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const text = getSelectedText()
|
const text = getSelectedText()
|
||||||
if (text) {
|
if (text) {
|
||||||
|
// v1.10:这里**不再**放「全选/反选/取消选区」那三个按钮。
|
||||||
|
// 用户反馈:选中一段文字时选项栏冒出选区命令,看着像「文字自带了一个选区」;
|
||||||
|
// 那三个命令操作的是像素选区(蚂蚁线),跟文字对象没关系,已归位到选区工具。
|
||||||
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>'
|
||||||
// 真放不下时宁可把 hint 滚出视野,也不能把「复制/取消选区」这些按钮顶没了
|
|
||||||
+ selCmdHTML()
|
|
||||||
+ '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>'
|
|
||||||
}
|
}
|
||||||
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>
|
// 选区命令是全局的,跟「有没有选中元素」无关:没选中时也必须能全选/反选/取消。
|
||||||
<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里会出现它的描边、实心与粗细</span>`
|
// 关键是必须排在 hint **之前** —— hint 带 margin-left:auto,放它后面会被一路
|
||||||
|
// 推到最右侧,窄屏上直接滚出可视区,看起来就成了「选择工具下没有这三个按钮」。
|
||||||
|
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>`
|
||||||
+ selCmdHTML()
|
+ selCmdHTML()
|
||||||
|
+ '<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里出现它的描边、实心与粗细</span>'
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 每个工具只露最常用的 2–4 个参数,全部直接写回 S(右侧参数面板同步) */
|
/** 每个工具只露最常用的 2–4 个参数,全部直接写回 S(右侧参数面板同步) */
|
||||||
@@ -1095,16 +1288,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
||||||
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
||||||
+ (tool === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, S.shapeRadius, 'px') : '')
|
+ (tool === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, S.shapeRadius, 'px') : '')
|
||||||
|
+ shapeColorHTML(null, 'rect')
|
||||||
+ fillStyleHTML('rect')
|
+ fillStyleHTML('rect')
|
||||||
}
|
}
|
||||||
if (tool === 'arrow') {
|
if (tool === 'arrow') {
|
||||||
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
||||||
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
||||||
|
+ shapeColorHTML(null, null)
|
||||||
+ '<span class="iwb-opt-hint">拖出箭头,松手完成</span>'
|
+ '<span class="iwb-opt-hint">拖出箭头,松手完成</span>'
|
||||||
}
|
}
|
||||||
if (tool === 'pen') {
|
if (tool === 'pen') {
|
||||||
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
||||||
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
||||||
|
+ shapeColorHTML(null, 'pen')
|
||||||
+ fillStyleHTML('pen')
|
+ fillStyleHTML('pen')
|
||||||
+ '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>'
|
+ '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>'
|
||||||
}
|
}
|
||||||
@@ -1114,15 +1310,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
+ '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>'
|
+ '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>'
|
||||||
}
|
}
|
||||||
if (tool === 'marquee') {
|
if (tool === 'marquee') {
|
||||||
|
// 选区命令归位(v1.10):全选/反选/取消选区属于「像素选区」,就该待在选区工具里,
|
||||||
|
// 而不是跟着文字/图形选中态到处跑。必须排在 hint 之前(hint 带 margin-left:auto)。
|
||||||
return `<span class="iwb-opt-label">形状</span>
|
return `<span class="iwb-opt-label">形状</span>
|
||||||
<button class="iwb-opt-btn${S.selectionKind === 'rect' ? ' active' : ''}" data-opt="shape" data-value="rect">矩形</button>
|
<button class="iwb-opt-btn${S.selectionKind === 'rect' ? ' active' : ''}" data-opt="shape" data-value="rect">矩形</button>
|
||||||
<button class="iwb-opt-btn${S.selectionKind === 'ellipse' ? ' active' : ''}" data-opt="shape" data-value="ellipse">椭圆</button>
|
<button class="iwb-opt-btn${S.selectionKind === 'ellipse' ? ' active' : ''}" data-opt="shape" data-value="ellipse">椭圆</button>
|
||||||
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>
|
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>`
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`
|
+ selCmdHTML()
|
||||||
|
+ `<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`
|
||||||
}
|
}
|
||||||
if (tool === 'lasso') {
|
if (tool === 'lasso') {
|
||||||
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>
|
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>`
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`
|
+ selCmdHTML()
|
||||||
|
+ `<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`
|
||||||
}
|
}
|
||||||
return `<span class="iwb-opt-current">当前工具:${TOOL_NAMES[tool] || tool}</span>
|
return `<span class="iwb-opt-current">当前工具:${TOOL_NAMES[tool] || tool}</span>
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS[tool] || '选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层'}</span>`
|
<span class="iwb-opt-hint">${OPT_HINTS[tool] || '选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层'}</span>`
|
||||||
@@ -1187,14 +1387,47 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const sv = textStyleValues(selText)
|
const sv = textStyleValues(selText)
|
||||||
body.querySelectorAll('[data-opt-text]').forEach(btn => {
|
body.querySelectorAll('[data-opt-text]').forEach(btn => {
|
||||||
const k = btn.dataset.optText
|
const k = btn.dataset.optText
|
||||||
const cur = k === 'bgFill' ? (sv.bgFill ? '1' : '0') : String(sv[k])
|
// bgFill 是开关:active 直接看当前状态,data-value 必须随之翻面。
|
||||||
btn.classList.toggle('active', cur === btn.dataset.value)
|
// 只在 HTML 里写死 ${v.bgFill ? '0' : '1'} 而这里不更新的话,
|
||||||
|
// 点一次能开、再点还是传「开」——按钮永远关不掉。
|
||||||
|
if (k === 'bgFill') {
|
||||||
|
btn.classList.toggle('active', !!sv.bgFill)
|
||||||
|
btn.dataset.value = sv.bgFill ? '0' : '1'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
btn.classList.toggle('active', String(sv[k]) === btn.dataset.value)
|
||||||
})
|
})
|
||||||
body.querySelectorAll('[data-opt-color]').forEach(inp => {
|
body.querySelectorAll('[data-opt-color]').forEach(inp => {
|
||||||
if (document.activeElement === inp) return
|
const k = inp.dataset.optColor
|
||||||
const v = sv[inp.dataset.optColor]
|
if (document.activeElement !== inp) {
|
||||||
|
const v = sv[k]
|
||||||
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
||||||
|
}
|
||||||
|
// 「正在生效」态:描边宽度 0 时描边色没起作用,底色没开时底色没起作用。
|
||||||
|
// 三个色块长得一模一样是上一版最误导的地方 —— 用户会以为「字体颜色有三处」。
|
||||||
|
if (k === 'strokeColor') inp.classList.toggle('is-off', !(sv.strokeWidth > 0))
|
||||||
|
if (k === 'bgColor') inp.classList.toggle('is-off', !sv.bgFill)
|
||||||
})
|
})
|
||||||
|
// 矢量图形的描边/填充色块(选中对象读对象自己的值,没选中读新建默认值)
|
||||||
|
body.querySelectorAll('[data-shape-color]').forEach(inp => {
|
||||||
|
const kind = inp.dataset.shapeColor
|
||||||
|
const sl = colorSlots()
|
||||||
|
const v = kind === 'fill' ? sl.fill : sl.stroke
|
||||||
|
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
||||||
|
if (kind === 'fill') {
|
||||||
|
// 无填充时也标成「未生效」:色块上留着上次的颜色很容易被当成「现在就是填充色」
|
||||||
|
inp.classList.toggle('is-off', !sl.fillOn)
|
||||||
|
inp.title = sl.fillOn
|
||||||
|
? '填充色:与工具栏右下的填充色块是同一份'
|
||||||
|
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
|
||||||
|
} else {
|
||||||
|
inp.title = '描边色:与工具栏左上的描边色块是同一份'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
|
||||||
|
// 否则会出现「选中一个矩形 → 选项栏显示它的颜色 → 工具栏还停在上一格」。
|
||||||
|
// updateColorUI 不回调 syncOptionBar,不会递归。
|
||||||
|
updateColorUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 状态栏:缩放 / 尺寸 / 光标 / 选区 / 当前层 / 工具 */
|
/** 状态栏:缩放 / 尺寸 / 光标 / 选区 / 当前层 / 工具 */
|
||||||
@@ -1257,15 +1490,24 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
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 === '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 || '#000000').toLowerCase()
|
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase()
|
||||||
else value = String(raw)
|
else value = String(raw)
|
||||||
|
|
||||||
S[stateKey] = value
|
S[stateKey] = value
|
||||||
|
// 「选了颜色就说明想用它」:描边宽度 0 / 底色没开的时候选色,画布上一点变化都没有,
|
||||||
|
// 会被当成「颜色坏了 / 被别的图层盖住」。顺手把开关打开,所见即所得。
|
||||||
|
if (key === 'strokeColor' && !(Number(S.textStrokeWidth) > 0)) S.textStrokeWidth = 6
|
||||||
|
if (key === 'bgColor' && !S.textBgFill) S.textBgFill = true
|
||||||
|
|
||||||
const t = getSelectedText()
|
const t = getSelectedText()
|
||||||
if (!t || t.locked) { textStyleSnapDone = false; return }
|
if (!t || t.locked) { textStyleSnapDone = false; syncOptionBar(); return }
|
||||||
if (committed || !textStyleSnapDone) { saveSnapshot('文字样式'); textStyleSnapDone = true }
|
if (committed || !textStyleSnapDone) { saveSnapshot('文字样式'); textStyleSnapDone = true }
|
||||||
t[key] = value
|
t[key] = value
|
||||||
|
if (key === 'strokeColor' && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth
|
||||||
|
if (key === 'bgColor' && !t.bgFill) t.bgFill = true
|
||||||
renderObjects()
|
renderObjects()
|
||||||
|
// 自动打开描边/底色后,按钮 active 态与色块取值都要跟着刷新
|
||||||
|
if (key === 'bgColor' || key === 'strokeColor') syncOptionBar()
|
||||||
if (committed) textStyleSnapDone = false
|
if (committed) textStyleSnapDone = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1281,6 +1523,148 @@ 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 起同时承接「无填充」)。
|
||||||
|
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
||||||
|
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
||||||
|
* 填充色写形状自己的 fillColor;还没切实心时选填充色顺手切实心(与文字底色同一逻辑)。
|
||||||
|
* kind='none' = 无填充:只关 fill,颜色留着不动,下次点颜色还是它。 */
|
||||||
|
function applyShapeColor(kind, raw, opts) {
|
||||||
|
const skipHistory = !!(opts && opts.skipHistory)
|
||||||
|
const sh = getSelectedShape()
|
||||||
|
const owner = sh ? (sh.type === 'pen' ? 'pen' : 'rect') : (S.tool === 'pen' ? 'pen' : 'rect')
|
||||||
|
if (kind === 'none') {
|
||||||
|
if (!fillSlotOn()) return
|
||||||
|
S.colorTarget = 'fill'
|
||||||
|
if (owner === 'pen') S.penFill = false
|
||||||
|
else S.rectFill = false
|
||||||
|
if (sh && !sh.locked && sh.fill) {
|
||||||
|
if (!skipHistory) saveSnapshot('无填充')
|
||||||
|
sh.fill = false
|
||||||
|
renderObjects()
|
||||||
|
}
|
||||||
|
updateColorUI()
|
||||||
|
syncOptionBar()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const hex = String(raw || '').toLowerCase()
|
||||||
|
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
||||||
|
if (kind === 'stroke') {
|
||||||
|
S.colorTarget = 'stroke'
|
||||||
|
applyColorChange(hex, opts)
|
||||||
|
if (skipHistory) syncOptionBarSoon()
|
||||||
|
else syncOptionBar()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
S.colorTarget = 'fill'
|
||||||
|
if (skipHistory) {
|
||||||
|
// 拖 SV 时每帧都会进来:不刷「最近使用」,也不每帧拍快照
|
||||||
|
} else {
|
||||||
|
rememberColor(hex)
|
||||||
|
}
|
||||||
|
S.shapeFillColor = hex
|
||||||
|
if (owner === 'pen') S.penFill = true
|
||||||
|
else S.rectFill = true
|
||||||
|
updateFillUI()
|
||||||
|
if (sh && !sh.locked) {
|
||||||
|
if (!skipHistory) saveSnapshot('填充颜色')
|
||||||
|
sh.fillColor = hex
|
||||||
|
sh.fill = owner === 'pen' ? !!sh.closed : true
|
||||||
|
renderObjects()
|
||||||
|
}
|
||||||
|
updateColorUI()
|
||||||
|
if (skipHistory) syncOptionBarSoon()
|
||||||
|
else syncOptionBar()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 色板 / hex / 吸管 / 推荐色统一的写入口(v1.11)。
|
||||||
|
* 之前这些路径一律调 applyColorChange 写主色,于是「描边」能被色板改动、
|
||||||
|
* 「填充」只能从选项栏那个小色块改 —— 用户看到的就是「三个地方调色,
|
||||||
|
* 有一处跟别处不通」。现在按 S.colorTarget 分派,色板调到哪一格就是哪一格。 */
|
||||||
|
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') S.colorTarget = 'stroke' // 当前没有填充语义:退回描边,别让调色静默失效
|
||||||
|
applyColorChange(color, opts)
|
||||||
|
if (opts && opts.skipHistory) syncOptionBarSoon()
|
||||||
|
else syncOptionBar()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 切换色板正在编辑哪一格(工具栏色块 / 色板头部 tab 共用) */
|
||||||
|
function setColorTarget(slot) {
|
||||||
|
S.colorTarget = slot === 'fill' ? 'fill' : (slot === 'bg' ? 'bg' : 'stroke')
|
||||||
|
updateColorUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 选项栏刷新合并到下一帧:拖 SV 调色时每帧重建选项栏纯属浪费,
|
||||||
|
* 但拖动结束(没有 pointerup 处理)必须保证最终值落到选项栏上。 */
|
||||||
|
let optionBarSyncRaf = 0
|
||||||
|
function syncOptionBarSoon() {
|
||||||
|
if (optionBarSyncRaf) return
|
||||||
|
optionBarSyncRaf = (typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (fn) => setTimeout(fn, 16))(() => {
|
||||||
|
optionBarSyncRaf = 0
|
||||||
|
syncOptionBar()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个。
|
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个。
|
||||||
* owner='rect' 作用于矩形/圆,owner='pen' 作用于钢笔闭合路径。 */
|
* owner='rect' 作用于矩形/圆,owner='pen' 作用于钢笔闭合路径。 */
|
||||||
function setShapeFill(fill, owner) {
|
function setShapeFill(fill, owner) {
|
||||||
@@ -1288,6 +1672,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (isPen) S.penFill = !!fill
|
if (isPen) S.penFill = !!fill
|
||||||
else S.rectFill = !!fill
|
else S.rectFill = !!fill
|
||||||
updateFillUI()
|
updateFillUI()
|
||||||
|
updateColorUI() // 填充块的斜杠(无填充)要跟着变
|
||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
const sh = getSelectedShape()
|
const sh = getSelectedShape()
|
||||||
const types = isPen ? ['pen'] : ['rect', 'circle']
|
const types = isPen ? ['pen'] : ['rect', 'circle']
|
||||||
@@ -1413,19 +1798,41 @@ 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。
|
const colorEl = nativeColorOf(e.target)
|
||||||
// 只认 change,保证「改一次颜色 = 一步撤销」,不在拖动途中连拍快照。
|
if (colorEl) { e.stopPropagation(); applyNativeColor(colorEl, false); return }
|
||||||
const colorEl = e.target.closest ? e.target.closest('[data-opt-color]') : null
|
|
||||||
if (colorEl) {
|
|
||||||
e.stopPropagation()
|
|
||||||
applyTextStyle(colorEl.dataset.optColor, colorEl.value, true)
|
|
||||||
syncOptionBar()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setOptionFromControl(e.target, true)
|
setOptionFromControl(e.target, true)
|
||||||
})
|
})
|
||||||
body.addEventListener('click', (e) => {
|
body.addEventListener('click', (e) => {
|
||||||
@@ -1536,7 +1943,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
bindColorPanel()
|
bindColorPanel()
|
||||||
bindColorPalette()
|
bindColorPalette()
|
||||||
bindFillToggle()
|
bindFillToggle()
|
||||||
bindLayerOrderButtons()
|
|
||||||
bindZoomButtons()
|
bindZoomButtons()
|
||||||
bindHistoryActions()
|
bindHistoryActions()
|
||||||
bindLayerAddActions()
|
bindLayerAddActions()
|
||||||
@@ -1561,17 +1967,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
if (!pop || pop.hidden) return false
|
if (!pop || pop.hidden) return false
|
||||||
pop.hidden = true
|
pop.hidden = true
|
||||||
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]')
|
runtime.el.querySelectorAll('[data-action="toggleColorPop"]').forEach(btn => {
|
||||||
if (btn) { btn.classList.remove('active'); btn.setAttribute('aria-expanded', 'false') }
|
btn.classList.remove('active')
|
||||||
|
btn.setAttribute('aria-expanded', 'false')
|
||||||
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 弹层定位:贴工具栏色点上方、左对齐;上方放不下翻到下方,左右夹在 modal 内。
|
/** 弹层定位:贴当前那一格色块上方、左对齐;上方放不下翻到下方,左右夹在 modal 内。
|
||||||
* 坐标用「按钮矩形 − modal 矩形」算,弹层是 modal 的绝对定位子节点,
|
* 坐标用「按钮矩形 − modal 矩形」算,弹层是 modal 的绝对定位子节点,
|
||||||
* 这样宿主页面有 transform 时也不会错位。 */
|
* 这样宿主页面有 transform 时也不会错位。 */
|
||||||
function positionColorPop() {
|
function positionColorPop() {
|
||||||
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
const btn = runtime.el && runtime.el.querySelector('[data-action="toggleColorPop"]')
|
const btn = runtime.el && runtime.el.querySelector(`.iwb-editor-color-btn[data-color-slot="${S.colorTarget}"]`)
|
||||||
const modal = runtime.el && runtime.el.querySelector('.iwb-editor-modal')
|
const modal = runtime.el && runtime.el.querySelector('.iwb-editor-modal')
|
||||||
if (!pop || !btn || !modal || pop.hidden) return
|
if (!pop || !btn || !modal || pop.hidden) return
|
||||||
const mr = modal.getBoundingClientRect()
|
const mr = modal.getBoundingClientRect()
|
||||||
@@ -1585,40 +1993,65 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
pop.style.top = Math.round(top) + 'px'
|
pop.style.top = Math.round(top) + 'px'
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleColorPop() {
|
/** 点工具栏色块:同一格再点一次收起;点另一格直接换编辑目标(不收起),
|
||||||
|
* 这样「描边改完顺手改填充」不用开关两次弹层。 */
|
||||||
|
function toggleColorPop(slot) {
|
||||||
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]')
|
if (!pop) return
|
||||||
if (!pop || !btn) return
|
const want = slot === 'fill' ? 'fill' : (slot === 'bg' ? 'bg' : 'stroke')
|
||||||
|
if (!pop.hidden && S.colorTarget === want) { closeColorPop(); return }
|
||||||
|
S.colorTarget = want
|
||||||
if (pop.hidden) {
|
if (pop.hidden) {
|
||||||
pop.hidden = false // 先显示再量:hidden 元素 getBoundingClientRect 全是 0
|
pop.hidden = false // 先显示再量:hidden 元素 getBoundingClientRect 全是 0
|
||||||
btn.classList.add('active')
|
updateColorUI()
|
||||||
btn.setAttribute('aria-expanded', 'true')
|
|
||||||
positionColorPop()
|
positionColorPop()
|
||||||
} else {
|
} else {
|
||||||
closeColorPop()
|
updateColorUI()
|
||||||
|
positionColorPop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 色板弹层(v1.3):工具栏色点开关;hex/吸管/推荐色/调色器都在这一个弹层里 */
|
/** 色板弹层(v1.3;v1.11 起同时服务描边与填充两个槽):
|
||||||
|
* 工具栏两个色块开关;tab / hex / 吸管 / 推荐色 / 调色器 / 无填充都在这一个弹层里 */
|
||||||
function bindColorPanel() {
|
function bindColorPanel() {
|
||||||
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
const colorBtn = runtime.el.querySelector('[data-action="toggleColorPop"]')
|
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')]
|
||||||
if (colorBtn) {
|
colorBtns.forEach(btn => {
|
||||||
colorBtn.addEventListener('mousedown', (e) => e.stopPropagation())
|
btn.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
colorBtn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop() })
|
btn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop(btn.dataset.colorSlot) })
|
||||||
}
|
})
|
||||||
if (pop) {
|
if (pop) {
|
||||||
pop.addEventListener('mousedown', (e) => e.stopPropagation())
|
pop.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
|
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
|
||||||
// 冒泡阶段拿不到「点了外面」这件事。
|
// 冒泡阶段拿不到「点了外面」这件事。
|
||||||
document.addEventListener('mousedown', (e) => {
|
document.addEventListener('mousedown', (e) => {
|
||||||
if (!pop.hidden && !pop.contains(e.target) && !(colorBtn && colorBtn.contains(e.target))) closeColorPop()
|
const onBtn = colorBtns.some(b => b.contains(e.target))
|
||||||
|
if (!pop.hidden && !pop.contains(e.target) && !onBtn) closeColorPop()
|
||||||
}, true)
|
}, true)
|
||||||
window.addEventListener('resize', positionColorPop)
|
window.addEventListener('resize', positionColorPop)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 独立颜色面板:颜色选择后同步当前工具颜色。
|
// 弹层头部:切描边/填充,或直接置为「无填充」
|
||||||
const setPanelColor = (color) => applyColorChange(color)
|
if (pop) {
|
||||||
|
pop.addEventListener('click', (e) => {
|
||||||
|
const tab = e.target.closest('[data-color-slot]')
|
||||||
|
if (tab && tab.classList.contains('iwb-color-pop-tab')) {
|
||||||
|
e.stopPropagation()
|
||||||
|
setColorTarget(tab.dataset.colorSlot)
|
||||||
|
positionColorPop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const none = e.target.closest('[data-color-none]')
|
||||||
|
if (none) {
|
||||||
|
e.stopPropagation()
|
||||||
|
applyColorNone()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 独立颜色面板:按当前目标槽写色(描边 → 主色,填充 → 形状 fillColor)
|
||||||
|
const setPanelColor = (color) => applyPanelColor(color)
|
||||||
// 拖动取色期间只拍一次快照:applyColorChange 每改一次颜色都会 saveSnapshot,
|
// 拖动取色期间只拍一次快照:applyColorChange 每改一次颜色都会 saveSnapshot,
|
||||||
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
|
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
|
||||||
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
|
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
|
||||||
@@ -1631,7 +2064,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (!dragSnapped) {
|
if (!dragSnapped) {
|
||||||
if (hasColorTarget()) { saveSnapshot(); dragSnapped = true }
|
if (hasColorTarget()) { saveSnapshot(); dragSnapped = true }
|
||||||
}
|
}
|
||||||
applyColorChange(color, { skipHistory: true })
|
applyPanelColor(color, { skipHistory: true })
|
||||||
}
|
}
|
||||||
const panelHexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
const panelHexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
||||||
if (panelHexInput) panelHexInput.addEventListener('change', () => { if (/^#[0-9a-f]{6}$/i.test(panelHexInput.value)) setPanelColor(panelHexInput.value) })
|
if (panelHexInput) panelHexInput.addEventListener('change', () => { if (/^#[0-9a-f]{6}$/i.test(panelHexInput.value)) setPanelColor(panelHexInput.value) })
|
||||||
@@ -1654,7 +2087,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const sv = runtime.el.querySelector('.iwb-color-sv')
|
const sv = runtime.el.querySelector('.iwb-color-sv')
|
||||||
const hue = runtime.el.querySelector('.iwb-color-hue')
|
const hue = runtime.el.querySelector('.iwb-color-hue')
|
||||||
const initHsv = (() => {
|
const initHsv = (() => {
|
||||||
const { r, g, b } = hexToRgb(S.color)
|
const { r, g, b } = hexToRgb(activeColor())
|
||||||
const rr = r / 255, gg = g / 255, bb = b / 255
|
const rr = r / 255, gg = g / 255, bb = b / 255
|
||||||
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min
|
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min
|
||||||
let h = 0
|
let h = 0
|
||||||
@@ -1680,9 +2113,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
setDragColor(hsvToHex(hueValue, satValue, valValue))
|
setDragColor(hsvToHex(hueValue, satValue, valValue))
|
||||||
}
|
}
|
||||||
// 推荐色 / hex / 吸管改色时,闭包里的 h/s/v 会过期(v1.3 修:以前点了绿色再拖 SV 会跳回红色)。
|
// 推荐色 / hex / 吸管改色时,闭包里的 h/s/v 会过期(v1.3 修:以前点了绿色再拖 SV 会跳回红色)。
|
||||||
// 每次按下前从 S.color 重新同步;灰阶(d=0,如 #000)反推不出色相,就沿用旧色相。
|
// 每次按下前从当前槽的颜色重新同步;灰阶(d=0,如 #000)反推不出色相,就沿用旧色相。
|
||||||
const syncFromColor = () => {
|
const syncFromColor = () => {
|
||||||
const { r, g, b } = hexToRgb(S.color)
|
const { r, g, b } = hexToRgb(activeColor())
|
||||||
const rr = r / 255, gg = g / 255, bb = b / 255
|
const rr = r / 255, gg = g / 255, bb = b / 255
|
||||||
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min
|
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min
|
||||||
if (d > 0) {
|
if (d > 0) {
|
||||||
@@ -1709,18 +2142,18 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
|
|
||||||
/** 裁剪约束控件已迁入选项栏(bindLiteUI 的点击委托统一处理),旧的直连绑定移除。 */
|
/** 裁剪约束控件已迁入选项栏(bindLiteUI 的点击委托统一处理),旧的直连绑定移除。 */
|
||||||
|
|
||||||
/** 调色板色块与自定义取色 input */
|
/** 调色板色块与自定义取色 input(旧侧栏,现已迁到弹层,保留兜底) */
|
||||||
function bindColorPalette() {
|
function bindColorPalette() {
|
||||||
// 颜色
|
// 颜色
|
||||||
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
|
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
|
||||||
s.addEventListener('mousedown', (e) => e.stopPropagation())
|
s.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
s.addEventListener('click', () => applyColorChange(s.dataset.color))
|
s.addEventListener('click', () => applyPanelColor(s.dataset.color))
|
||||||
})
|
})
|
||||||
|
|
||||||
const colorInput = runtime.el.querySelector('.iwb-editor-color-picker-input')
|
const colorInput = runtime.el.querySelector('.iwb-editor-color-picker-input')
|
||||||
if (colorInput) {
|
if (colorInput) {
|
||||||
colorInput.addEventListener('mousedown', (e) => e.stopPropagation())
|
colorInput.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
colorInput.addEventListener('input', () => applyColorChange(colorInput.value))
|
colorInput.addEventListener('input', () => applyPanelColor(colorInput.value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1741,15 +2174,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() {
|
||||||
// 缩放按钮
|
// 缩放按钮
|
||||||
@@ -1891,7 +2315,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
function commitPenPath() {
|
function commitPenPath() {
|
||||||
if (!S.penPath || S.penPath.pts.length < 2) { S.penPath = null; renderObjects(); return }
|
if (!S.penPath || S.penPath.pts.length < 2) { S.penPath = null; renderObjects(); return }
|
||||||
saveSnapshot()
|
saveSnapshot()
|
||||||
const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter }
|
const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, fillColor: S.shapeFillColor, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter }
|
||||||
// 路径落成即回 V 并选中(v1.5):连续画多条就再按一次 P;节点编辑仍走 V 下双击
|
// 路径落成即回 V 并选中(v1.5):连续画多条就再按一次 P;节点编辑仍走 V 下双击
|
||||||
S.shapeLayers.push(shape); S.penPath = null; renderObjects(); renderLayerPanel()
|
S.shapeLayers.push(shape); S.penPath = null; renderObjects(); renderLayerPanel()
|
||||||
finishCreateTool('shape', shape.id)
|
finishCreateTool('shape', shape.id)
|
||||||
@@ -2091,11 +2515,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()
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ import { toast } from './commands.js'
|
|||||||
opacity: l.opacity == null ? 1 : l.opacity,
|
opacity: l.opacity == null ? 1 : l.opacity,
|
||||||
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
||||||
})),
|
})),
|
||||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color, 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, align: t.align, lineHeight: t.lineHeight,
|
||||||
@@ -337,8 +337,13 @@ import { toast } from './commands.js'
|
|||||||
textDefaults: {
|
textDefaults: {
|
||||||
weight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
|
weight: S.textWeight, 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, bgAlpha: S.textBgAlpha
|
||||||
}, selectedShapeId: S.selectedShapeId,
|
},
|
||||||
|
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
|
||||||
|
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 说明点到了控制点
|
||||||
|
|||||||
@@ -208,14 +208,13 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.strokeStyle = '#e8a735'
|
ctx.strokeStyle = '#e8a735'
|
||||||
ctx.lineWidth = 1.5 / viewScale()
|
ctx.lineWidth = 1.5 / viewScale()
|
||||||
ctx.setLineDash([6 / viewScale(), 3 / viewScale()])
|
// 图层/对象选中一律实线(虚线是像素选区的语义,见 objects.js 同处注释)
|
||||||
const corners = boxCorners(box.x, box.y, box.w, box.h, rot)
|
const corners = boxCorners(box.x, box.y, box.w, box.h, rot)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(corners[0][0], corners[0][1])
|
ctx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
||||||
ctx.closePath()
|
ctx.closePath()
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
ctx.setLineDash([])
|
|
||||||
ctx.fillStyle = '#fff'
|
ctx.fillStyle = '#fff'
|
||||||
ctx.strokeStyle = '#e8a735'
|
ctx.strokeStyle = '#e8a735'
|
||||||
const pts = frameHandlePoints(box, rot)
|
const pts = frameHandlePoints(box, rot)
|
||||||
@@ -615,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>
|
||||||
@@ -670,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('|') }
|
||||||
}
|
}
|
||||||
@@ -709,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
|
||||||
@@ -756,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 }
|
||||||
@@ -788,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') {
|
||||||
@@ -1174,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,避免后续按原图重新重绘
|
||||||
@@ -1191,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,7 +15,7 @@ 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, newTextStyle, textBox } 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)
|
||||||
@@ -418,14 +417,14 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
octx.save()
|
octx.save()
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
octx.lineWidth = 1.5 / viewScale()
|
octx.lineWidth = 1.5 / viewScale()
|
||||||
octx.setLineDash([6 / viewScale(), 3 / viewScale()])
|
// v1.10:对象选中框用**实线**。虚线在 PS 语义里是「像素选区(蚂蚁线)」,
|
||||||
|
// 用户看到文字/图形外面一圈虚线会当成「莫名其妙多出来的选区」。
|
||||||
const corners = boxCorners(b.x, b.y, b.w, b.h, rot)
|
const corners = boxCorners(b.x, b.y, b.w, b.h, rot)
|
||||||
octx.beginPath()
|
octx.beginPath()
|
||||||
octx.moveTo(corners[0][0], corners[0][1])
|
octx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
||||||
octx.closePath()
|
octx.closePath()
|
||||||
octx.stroke()
|
octx.stroke()
|
||||||
octx.setLineDash([])
|
|
||||||
const hs = 5.5 / viewScale()
|
const hs = 5.5 / viewScale()
|
||||||
octx.fillStyle = '#ffffff'
|
octx.fillStyle = '#ffffff'
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
@@ -475,14 +474,13 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
octx.save()
|
octx.save()
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
octx.lineWidth = 1.5 / viewScale()
|
octx.lineWidth = 1.5 / viewScale()
|
||||||
octx.setLineDash([6 / viewScale(), 3 / viewScale()])
|
// 同上:对象选中是实线(虚线只留给像素选区的蚂蚁线)
|
||||||
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot)
|
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot)
|
||||||
octx.beginPath()
|
octx.beginPath()
|
||||||
octx.moveTo(corners[0][0], corners[0][1])
|
octx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
||||||
octx.closePath()
|
octx.closePath()
|
||||||
octx.stroke()
|
octx.stroke()
|
||||||
octx.setLineDash([])
|
|
||||||
const hs = 5.5 / viewScale()
|
const hs = 5.5 / viewScale()
|
||||||
octx.fillStyle = '#ffffff'
|
octx.fillStyle = '#ffffff'
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
@@ -501,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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ 钢笔二次编辑(移动/添加/删除节点) ============
|
// ============ 钢笔二次编辑(移动/添加/删除节点) ============
|
||||||
@@ -589,12 +586,20 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
// ============ 文字输入框 ============
|
// ============ 文字输入框 ============
|
||||||
export function showTextInput(x, y, layer) {
|
export function showTextInput(x, y, layer) {
|
||||||
const input = runtime.el.querySelector('.iwb-editor-text-input')
|
const input = runtime.el.querySelector('.iwb-editor-text-input')
|
||||||
const rect = S.canvasStack.getBoundingClientRect()
|
|
||||||
const wrapRect = S.canvasWrap.getBoundingClientRect()
|
const wrapRect = S.canvasWrap.getBoundingClientRect()
|
||||||
const sx = rect.width / S.imgW
|
// 不能用 canvasStack 的矩形换算:stack 的尺寸是 (imgW + 2*overlayPad) * scale,
|
||||||
const sy = rect.height / S.imgH
|
// 图片在 stack 内部还额外偏移了 pad*scale(图层 canvas 的 left/top)。
|
||||||
input.style.left = (rect.left - wrapRect.left + x * sx) + 'px'
|
// 拿它算比例会偏小、又漏掉这段偏移,输入框就整体跑到点击点的左上方。
|
||||||
input.style.top = (rect.top - wrapRect.top + y * sy) + 'px'
|
// textCanvas 与图层 canvas 同基准,矩形精确等于「图片显示区域」。
|
||||||
|
const box = (S.textCanvas || S.canvasStack).getBoundingClientRect()
|
||||||
|
const sx = S.imgW ? box.width / S.imgW : 1
|
||||||
|
const sy = S.imgH ? box.height / S.imgH : 1
|
||||||
|
// textarea 有 2px 边框 + 8/4px 内边距,反向抵消后「输入框里的字起点」正压在点击点上,
|
||||||
|
// 与提交后 drawTextObject 从 t.x/t.y 起画的位置完全一致(所见即所得)。
|
||||||
|
const INSET_X = 10
|
||||||
|
const INSET_Y = 6
|
||||||
|
input.style.left = (box.left - wrapRect.left + x * sx - INSET_X) + 'px'
|
||||||
|
input.style.top = (box.top - wrapRect.top + y * sy - INSET_Y) + 'px'
|
||||||
input.style.display = 'block'
|
input.style.display = 'block'
|
||||||
if (layer) {
|
if (layer) {
|
||||||
input.value = layer.text
|
input.value = layer.text
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
// text.js 是零依赖叶子模块,这里引它的默认值常量不会形成循环
|
||||||
|
import { TEXT_DEFAULTS } from './text.js'
|
||||||
|
|
||||||
export const ZOOM_MIN = 0.1
|
export const ZOOM_MIN = 0.1
|
||||||
export const ZOOM_MAX = 10
|
export const ZOOM_MAX = 10
|
||||||
export const ZOOM_STEP = 1.15
|
export const ZOOM_STEP = 1.15
|
||||||
@@ -39,15 +42,23 @@
|
|||||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||||
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
||||||
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||||
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
|
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||||
|
shapeFillColor: null,
|
||||||
|
// v1.11:工具栏色板当前在调哪个颜色。描边与填充是同一个控件上的两个槽,
|
||||||
|
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
|
||||||
|
// 否则「三个地方各调各的颜色」会一直存在。
|
||||||
|
colorTarget: 'stroke', // stroke | fill
|
||||||
textSize: 32, // 新建文字的字号 px
|
textSize: 32, // 新建文字的字号 px
|
||||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
textWeight: 'bold', // bold | normal | 900
|
textWeight: 'bold', // bold | normal | 900
|
||||||
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
||||||
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
||||||
textStrokeWidth: 0, // 描边宽度 px,0 = 无描边
|
textStrokeWidth: TEXT_DEFAULTS.strokeWidth, // 描边宽度 px,0 = 无描边
|
||||||
textStrokeColor: '#ffffff',
|
textStrokeColor: TEXT_DEFAULTS.strokeColor,
|
||||||
textBgFill: false, // 底色块
|
textBgFill: TEXT_DEFAULTS.bgFill, // 底色块
|
||||||
textBgColor: '#000000',
|
textBgColor: TEXT_DEFAULTS.bgColor, // 中性近黑,不再是纯黑 #000000
|
||||||
|
textBgAlpha: TEXT_DEFAULTS.bgAlpha, // 底色透明度(色块按这个不透明度显示,所见即所得)
|
||||||
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
||||||
recentColors: [],
|
recentColors: [],
|
||||||
// 图层系统
|
// 图层系统
|
||||||
|
|||||||
@@ -15,6 +15,23 @@
|
|||||||
/** 默认行高倍数:必须等于老版的 fontSize×1.25,否则单行文字的选中框会变高 */
|
/** 默认行高倍数:必须等于老版的 fontSize×1.25,否则单行文字的选中框会变高 */
|
||||||
export const TEXT_LINE_HEIGHT = 1.25
|
export const TEXT_LINE_HEIGHT = 1.25
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文字默认样式:**唯一的真相源**。
|
||||||
|
* 以前 '#ff4444' / '#ffffff' / '#000000' / 0.68 散落在 state.js、text.js、
|
||||||
|
* events.js 三处,改一处另两处不跟,界面上就会出现「同一个概念三种颜色」——
|
||||||
|
* 用户实测反馈「字体颜色有 3 个位置,那个黑色应该换成默认的参数」正是这么来的。
|
||||||
|
* 底色默认也不再是纯黑 #000000:纯黑在深色/花色底图上像抠了个洞,
|
||||||
|
* 而且和「文字色」看起来像是同一件事。改成中性近黑 #101014 + 68% 透明。
|
||||||
|
*/
|
||||||
|
export const TEXT_DEFAULTS = {
|
||||||
|
color: '#ff4444',
|
||||||
|
strokeWidth: 0,
|
||||||
|
strokeColor: '#ffffff',
|
||||||
|
bgFill: false,
|
||||||
|
bgColor: '#101014',
|
||||||
|
bgAlpha: 0.68
|
||||||
|
}
|
||||||
|
|
||||||
/** 底色块相对字号的 padding 系数 */
|
/** 底色块相对字号的 padding 系数 */
|
||||||
const BG_PAD_RATIO = 0.3
|
const BG_PAD_RATIO = 0.3
|
||||||
|
|
||||||
@@ -100,8 +117,10 @@
|
|||||||
// 底色块:先于文字画,圆角按字号比例给一点(纯直角贴小字会很硬)
|
// 底色块:先于文字画,圆角按字号比例给一点(纯直角贴小字会很硬)
|
||||||
if (t.bgFill) {
|
if (t.bgFill) {
|
||||||
const r = Math.min(m.pad + 2, Math.min(boxW, m.h + m.pad * 2) / 2)
|
const r = Math.min(m.pad + 2, Math.min(boxW, m.h + m.pad * 2) / 2)
|
||||||
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? 0.55 : t.bgAlpha)
|
// 0.55 在浅色/花色底图上偏透,用户容易以为「底色没生效」;0.68 既压得住底图,
|
||||||
ctx.fillStyle = t.bgColor || '#000000'
|
// 也还看得见一点背景,是「垫一块板让字立起来」的常用手感。
|
||||||
|
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : t.bgAlpha)
|
||||||
|
ctx.fillStyle = t.bgColor || TEXT_DEFAULTS.bgColor
|
||||||
const bx = t.x, by = t.y
|
const bx = t.x, by = t.y
|
||||||
const bw = boxW, bh = m.h + m.pad * 2
|
const bw = boxW, bh = m.h + m.pad * 2
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
@@ -130,10 +149,10 @@
|
|||||||
const y = t.y + m.pad + i * m.lh
|
const y = t.y + m.pad + i * m.lh
|
||||||
if (m.sw > 0) {
|
if (m.sw > 0) {
|
||||||
ctx.lineWidth = m.sw
|
ctx.lineWidth = m.sw
|
||||||
ctx.strokeStyle = t.strokeColor || '#ffffff'
|
ctx.strokeStyle = t.strokeColor || TEXT_DEFAULTS.strokeColor
|
||||||
ctx.strokeText(m.lines[i], ox, y)
|
ctx.strokeText(m.lines[i], ox, y)
|
||||||
}
|
}
|
||||||
ctx.fillStyle = t.color || '#ff4444'
|
ctx.fillStyle = t.color || TEXT_DEFAULTS.color
|
||||||
ctx.fillText(m.lines[i], ox, y)
|
ctx.fillText(m.lines[i], ox, y)
|
||||||
}
|
}
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
@@ -147,9 +166,9 @@
|
|||||||
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),
|
||||||
strokeColor: s.strokeColor || '#ffffff',
|
strokeColor: s.strokeColor || TEXT_DEFAULTS.strokeColor,
|
||||||
bgFill: !!s.bgFill,
|
bgFill: !!s.bgFill,
|
||||||
bgColor: s.bgColor || '#000000',
|
bgColor: s.bgColor || TEXT_DEFAULTS.bgColor,
|
||||||
bgAlpha: s.bgAlpha == null ? 0.55 : Number(s.bgAlpha)
|
bgAlpha: s.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : Number(s.bgAlpha)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,6 +180,12 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 按形状对象绘制(矩形/箭头),预览与最终渲染共用 */
|
/** 按形状对象绘制(矩形/箭头),预览与最终渲染共用 */
|
||||||
|
/** 形状描边色:每个形状自己存 color(v1.10 起选项栏可单独调) */
|
||||||
|
export function strokeOf(s) { return (s && s.color) || S.color }
|
||||||
|
|
||||||
|
/** 形状填充色:自己设过 fillColor 就用它,否则跟随描边色(同色实心是默认手感) */
|
||||||
|
export function fillOf(s) { return (s && s.fillColor) || strokeOf(s) }
|
||||||
|
|
||||||
export function drawShape(ctx, s) {
|
export function drawShape(ctx, s) {
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.globalAlpha = s.opacity != null ? s.opacity : 1
|
ctx.globalAlpha = s.opacity != null ? s.opacity : 1
|
||||||
@@ -191,23 +197,23 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
ctx.rotate(rot * Math.PI / 180)
|
ctx.rotate(rot * Math.PI / 180)
|
||||||
ctx.translate(-cx, -cy)
|
ctx.translate(-cx, -cy)
|
||||||
}
|
}
|
||||||
ctx.strokeStyle = s.color
|
ctx.strokeStyle = strokeOf(s)
|
||||||
ctx.lineWidth = s.lw
|
ctx.lineWidth = s.lw
|
||||||
ctx.lineCap = 'round'
|
ctx.lineCap = 'round'
|
||||||
ctx.lineJoin = 'round'
|
ctx.lineJoin = 'round'
|
||||||
if (s.type === 'pen') {
|
if (s.type === 'pen') {
|
||||||
const pts = Array.isArray(s.pts) ? s.pts : []
|
const pts = Array.isArray(s.pts) ? s.pts : []
|
||||||
if (pts.length > 1) { ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y); for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); if (s.closed) ctx.closePath(); if (s.closed && s.fill) { ctx.fillStyle = s.color; ctx.fill() } ctx.stroke() }
|
if (pts.length > 1) { ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y); for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); if (s.closed) ctx.closePath(); if (s.closed && s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() } ctx.stroke() }
|
||||||
} else if (s.type === 'rect') {
|
} else if (s.type === 'rect') {
|
||||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
||||||
const radius = roundedRadius(s, rw, rh)
|
const radius = roundedRadius(s, rw, rh)
|
||||||
if (radius > 0) {
|
if (radius > 0) {
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
||||||
if (s.fill) { ctx.fillStyle = s.color; ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
} else {
|
} else {
|
||||||
if (s.fill) { ctx.fillStyle = s.color; ctx.fillRect(rx, ry, rw, rh) }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fillRect(rx, ry, rw, rh) }
|
||||||
ctx.strokeRect(rx, ry, rw, rh)
|
ctx.strokeRect(rx, ry, rw, rh)
|
||||||
}
|
}
|
||||||
} else if (s.type === 'circle') {
|
} else if (s.type === 'circle') {
|
||||||
@@ -215,10 +221,10 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
const rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
const rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2)
|
ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2)
|
||||||
if (s.fill) { ctx.fillStyle = s.color; ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
} else {
|
} else {
|
||||||
ctx.fillStyle = s.color
|
ctx.fillStyle = strokeOf(s)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(s.x1, s.y1)
|
ctx.moveTo(s.x1, s.y1)
|
||||||
ctx.lineTo(s.x2, s.y2)
|
ctx.lineTo(s.x2, s.y2)
|
||||||
|
|||||||
+626
-264
File diff suppressed because it is too large.
Load diff
@@ -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)
|
||||||
@@ -143,7 +143,7 @@ check('调色板已搬进工具栏:侧栏只剩缩放,SV/色相/推荐色都
|
|||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
const q = (s) => Boolean(document.querySelector(s))
|
const q = (s) => Boolean(document.querySelector(s))
|
||||||
return !q('.iwb-editor-left .iwb-editor-color-panel') &&
|
return !q('.iwb-editor-left .iwb-editor-color-panel') &&
|
||||||
q('.iwb-editor-tools [data-action="toggleColorPop"]') &&
|
q('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]') &&
|
||||||
q('.iwb-editor-color-pop .iwb-color-sv') && q('.iwb-editor-color-pop .iwb-color-hue') &&
|
q('.iwb-editor-color-pop .iwb-color-sv') && q('.iwb-editor-color-pop .iwb-color-hue') &&
|
||||||
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-panel-swatch').length === 12 &&
|
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-panel-swatch').length === 12 &&
|
||||||
q('.iwb-editor-zoom') &&
|
q('.iwb-editor-zoom') &&
|
||||||
@@ -180,7 +180,7 @@ check('色板弹层默认收起;点工具栏色点弹出、且整块在视口
|
|||||||
await (async () => {
|
await (async () => {
|
||||||
const pop = page.locator('.iwb-editor-color-pop')
|
const pop = page.locator('.iwb-editor-color-pop')
|
||||||
if (await pop.isVisible()) return 'pre: 弹层一开始就开着'
|
if (await pop.isVisible()) return 'pre: 弹层一开始就开着'
|
||||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click()
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||||
await page.waitForTimeout(100)
|
await page.waitForTimeout(100)
|
||||||
if (!(await pop.isVisible())) return 'post: 点了没开'
|
if (!(await pop.isVisible())) return 'post: 点了没开'
|
||||||
const box = await pop.boundingBox()
|
const box = await pop.boundingBox()
|
||||||
@@ -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
|
||||||
@@ -944,9 +951,9 @@ check('选中矢量形状后切吸管:选中态保留、取色写回形状、
|
|||||||
const selId = (await dbg()).selectedShapeId
|
const selId = (await dbg()).selectedShapeId
|
||||||
if (!selId) return 'pre: 没有选中形状'
|
if (!selId) return 'pre: 没有选中形状'
|
||||||
// 先换成一个可辨识的颜色,便于判断取色真的改了对象(v1.3:推荐色在弹层里,先点开色点)
|
// 先换成一个可辨识的颜色,便于判断取色真的改了对象(v1.3:推荐色在弹层里,先点开色点)
|
||||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click()
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||||
await page.locator('.iwb-editor-color-pop .iwb-editor-color-panel-swatch[data-panel-color="#4488ff"]').click()
|
await page.locator('.iwb-editor-color-pop .iwb-editor-color-panel-swatch[data-panel-color="#4488ff"]').click()
|
||||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click() // 收起,别挡住后面的画布取色点
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() // 收起,别挡住后面的画布取色点
|
||||||
const before = (await dbg()).shapes.find(s => s.id === selId)
|
const before = (await dbg()).shapes.find(s => s.id === selId)
|
||||||
if (!before || before.color !== '#4488ff') return 'pre: color=' + (before && before.color)
|
if (!before || before.color !== '#4488ff') return 'pre: color=' + (before && before.color)
|
||||||
await page.keyboard.press('i') // 切吸管
|
await page.keyboard.press('i') // 切吸管
|
||||||
@@ -1003,7 +1010,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
|
|||||||
await page.waitForTimeout(120)
|
await page.waitForTimeout(120)
|
||||||
if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状'
|
if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状'
|
||||||
const h0 = (await dbg()).history
|
const h0 = (await dbg()).history
|
||||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click()
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||||
const sv = await page.locator('.iwb-color-sv').boundingBox()
|
const sv = await page.locator('.iwb-color-sv').boundingBox()
|
||||||
await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2)
|
await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2)
|
||||||
await page.mouse.down()
|
await page.mouse.down()
|
||||||
@@ -1011,7 +1018,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
|
|||||||
await page.mouse.up()
|
await page.mouse.up()
|
||||||
await page.waitForTimeout(150)
|
await page.waitForTimeout(150)
|
||||||
const h1 = (await dbg()).history
|
const h1 = (await dbg()).history
|
||||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click() // 收起
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() // 收起
|
||||||
return h1 - h0 === 1 ? true : 'history ' + h0 + '→' + h1
|
return h1 - h0 === 1 ? true : 'history ' + h0 + '→' + h1
|
||||||
})())
|
})())
|
||||||
|
|
||||||
@@ -1035,7 +1042,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"]')
|
||||||
}))
|
}))
|
||||||
@@ -1434,17 +1441,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 () => {
|
||||||
@@ -1675,6 +1691,32 @@ async function snapTol() {
|
|||||||
return 6 / (b.width / d.doc.w)
|
return 6 / (b.width / d.doc.w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 文字输入框必须贴着点击点出现。早先用 canvasStack 的矩形换算,而 stack 尺寸是
|
||||||
|
// (imgW + 2*overlayPad)*scale、图片在 stack 内还额外偏移 pad*scale —— 比例偏小又漏偏移,
|
||||||
|
// 输入框整体跑到点击点的左上方。
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
|
const clearPt = await imgToScreen(90, 8)
|
||||||
|
await page.mouse.click(clearPt.x, clearPt.y)
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
// 测试画布只有 96×64,取左下角的空白区(已存在的两个矩形都在上半部)
|
||||||
|
const clickPt = await imgToScreen(12, 56)
|
||||||
|
await page.mouse.click(clickPt.x, clickPt.y)
|
||||||
|
await page.waitForTimeout(260)
|
||||||
|
const inpBox = await page.locator('.iwb-editor-text-input').boundingBox()
|
||||||
|
if (!inpBox) throw new Error('点了画布但文字输入框没有出现,后面的定位断言无从谈起')
|
||||||
|
// 输入框内「文字起点」= 左边框 2px + 左内边距 8px、上边框 2px + 上内边距 4px
|
||||||
|
const dxInp = inpBox.x + 10 - clickPt.x
|
||||||
|
const dyInp = inpBox.y + 6 - clickPt.y
|
||||||
|
check('文字输入框贴着点击点出现(不再偏到左上方)',
|
||||||
|
Math.abs(dxInp) <= 3 && Math.abs(dyInp) <= 3,
|
||||||
|
'dx=' + dxInp.toFixed(1) + ' dy=' + dyInp.toFixed(1))
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
check('输入框按 Esc 取消后不留下空文字对象', (await dbg()).texts.length === 0,
|
||||||
|
'texts=' + (await dbg()).texts.length)
|
||||||
|
|
||||||
// 多行文字:Shift+Enter 换行(textarea)→ 落成两行,包围盒高度约为单行两倍
|
// 多行文字:Shift+Enter 换行(textarea)→ 落成两行,包围盒高度约为单行两倍
|
||||||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||||||
let p0 = await imgToScreen(8, 8)
|
let p0 = await imgToScreen(8, 8)
|
||||||
@@ -1695,6 +1737,19 @@ 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))
|
||||||
|
|
||||||
|
// 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。
|
||||||
|
// 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区,
|
||||||
|
// 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。
|
||||||
|
// 清选中用「切到别的工具再切回来」:画布上早就有别的用例留下的图形,
|
||||||
|
// 靠「点空白」清选中会点到它们(点位随用例顺序变化,很容易变成假失败)。
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const selIconNoSel = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||||||
|
check('选择工具未选中元素时仍有全选/反选/取消三个图标(且不重复)',
|
||||||
|
selIconNoSel === 3, 'count=' + selIconNoSel + ' 选中=' + (await dbg()).selectedShapeId)
|
||||||
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
p0 = await imgToScreen(10, 12)
|
p0 = await imgToScreen(10, 12)
|
||||||
await page.mouse.click(p0.x, p0.y)
|
await page.mouse.click(p0.x, p0.y)
|
||||||
@@ -1746,6 +1801,249 @@ check('底色块开关生效(padding 让包围盒继续变大)',
|
|||||||
vdbg.texts[0].bgFill === true && hBg > vdbg.texts[0].box.h - 1 && hBg > 0,
|
vdbg.texts[0].bgFill === true && hBg > vdbg.texts[0].box.h - 1 && hBg > 0,
|
||||||
'bgFill=' + vdbg.texts[0].bgFill + ' h=' + hBg)
|
'bgFill=' + vdbg.texts[0].bgFill + ' h=' + hBg)
|
||||||
|
|
||||||
|
// 只改底色颜色、不点「底色」开关时,画布上原本什么都不会变 —— 用户会以为底色坏了
|
||||||
|
// 或被别的颜色盖住。现在选色即自动启用,按钮的 active 态也要跟着亮。
|
||||||
|
await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click()
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
const bgOff = (await dbg()).texts[0].bgFill
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-opt-color="bgColor"]')
|
||||||
|
el.value = '#ffd400'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
vdbg = await dbg()
|
||||||
|
const bgBtnOn = await page.evaluate(() =>
|
||||||
|
document.querySelector('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').classList.contains('active'))
|
||||||
|
check('只选底色颜色就自动开启底色(不必先点开关)',
|
||||||
|
bgOff === false && vdbg.texts[0].bgFill === true && vdbg.texts[0].bgColor === '#ffd400' && bgBtnOn,
|
||||||
|
'关前=' + bgOff + ' 改色后 bgFill=' + vdbg.texts[0].bgFill +
|
||||||
|
' bgColor=' + vdbg.texts[0].bgColor + ' 按钮 active=' + bgBtnOn)
|
||||||
|
|
||||||
|
// ---- v1.10:三个色块的「生效 / 未生效」语义 ----
|
||||||
|
// 用户反馈「字体颜色有 3 个位置,那个黑色应该换成默认的参数」:底色默认曾是纯黑 #000000,
|
||||||
|
// 关闭时也显示成一块死黑,看起来就像「又多了一个字体颜色」。现在默认值单点定义,
|
||||||
|
// 且没生效的色块显示为灰色斜纹(不再显示颜色本身),语义变成「这里还没有颜色」。
|
||||||
|
const colorMeta = await page.evaluate(() => {
|
||||||
|
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||||||
|
const out = {}
|
||||||
|
body.querySelectorAll('[data-opt-color]').forEach(el => {
|
||||||
|
out[el.dataset.optColor] = { off: el.classList.contains('is-off'), value: el.value }
|
||||||
|
})
|
||||||
|
return { defaults: window.__iwbEditor.__debug().textDefaults, swatches: out }
|
||||||
|
})
|
||||||
|
check('文字底色默认不再是纯黑(默认值收口到 text.js,近黑 #101014 + 68% 透明)',
|
||||||
|
colorMeta.defaults.bgColor !== '#000000' && /^#[0-9a-f]{6}$/.test(colorMeta.defaults.bgColor) &&
|
||||||
|
Math.abs(colorMeta.defaults.bgAlpha - 0.68) < 1e-6,
|
||||||
|
JSON.stringify(colorMeta.defaults))
|
||||||
|
|
||||||
|
// 关掉底色 + 描边宽度归零 → 两个色块都应变成「未启用」
|
||||||
|
await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click()
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="textStrokeWidth"]')
|
||||||
|
el.value = '0'
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
const offStates = await page.evaluate(() => [...document.querySelectorAll('.iwb-editor-optionbar-body [data-opt-color]')]
|
||||||
|
.map(el => ({ k: el.dataset.optColor, off: el.classList.contains('is-off') })))
|
||||||
|
check('描边宽度为 0 / 底色关闭时,对应色块标记为「未启用」(不再显示颜色本身)',
|
||||||
|
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.waitForTimeout(160)
|
||||||
|
const marqueeIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="lasso"]').click()
|
||||||
|
await page.waitForTimeout(160)
|
||||||
|
const lassoIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||||||
|
check('选区工具(矩形 / 套索)都有全选、反选、取消选区三个按钮',
|
||||||
|
marqueeIcons === 3 && lassoIcons === 3, 'marquee=' + marqueeIcons + ' lasso=' + lassoIcons)
|
||||||
|
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
|
p0 = await imgToScreen(10, 12)
|
||||||
|
await page.mouse.click(p0.x, p0.y)
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const textSelIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||||||
|
check('选中文字时选项栏不再冒出选区命令按钮(那三个命令跟文字对象无关)',
|
||||||
|
textSelIcons === 0, 'count=' + textSelIcons)
|
||||||
|
|
||||||
|
// 选中框必须是实线:虚线圈会被当成「莫名其妙多出来的像素选区」。
|
||||||
|
// 沿选中框顶边扫一行橙色像素,虚线(6/3)覆盖率约 0.6~0.7,实线接近 1。
|
||||||
|
const frameCoverage = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const cv = document.querySelector('.iwb-editor-crop-overlay')
|
||||||
|
if (!d.selectedTextId) return { err: 'no-selected-text' }
|
||||||
|
if (!cv) return { err: 'no-overlay' }
|
||||||
|
const ctx = cv.getContext('2d')
|
||||||
|
const img = ctx.getImageData(0, 0, cv.width, cv.height).data
|
||||||
|
const W = cv.width
|
||||||
|
// 不按图片坐标换算:overlay 画布含 overlayPad 外扩,直接全画布扫,
|
||||||
|
// 找第一条「橙色连续段」,再量这一段的覆盖率 —— 实线接近 1,6/3 虚线约 0.6~0.7。
|
||||||
|
const isOrange = (i) => img[i + 3] > 60 && img[i] > 170 && img[i + 1] > 100 && img[i + 2] < 130
|
||||||
|
for (let y = 0; y < cv.height; y++) {
|
||||||
|
const base = y * W * 4
|
||||||
|
let first = -1, last = -1, n = 0
|
||||||
|
for (let x = 0; x < W; x++) {
|
||||||
|
if (isOrange(base + x * 4)) { if (first < 0) first = x; last = x; n++ }
|
||||||
|
}
|
||||||
|
if (n >= 20 && last - first >= 40) {
|
||||||
|
return { ratio: +(n / (last - first + 1)).toFixed(2), n, span: last - first + 1, y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { err: 'no-orange-row' }
|
||||||
|
})
|
||||||
|
check('对象选中框是实线(虚线的语义是像素选区,会把用户绕晕)',
|
||||||
|
!!frameCoverage && frameCoverage.ratio >= 0.85, JSON.stringify(frameCoverage))
|
||||||
|
|
||||||
// 吸附:画一个实心矩形,拖到画布中心附近应被精确吸到中心并出现参考线
|
// 吸附:画一个实心矩形,拖到画布中心附近应被精确吸到中心并出现参考线
|
||||||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
await page.waitForTimeout(100)
|
await page.waitForTimeout(100)
|
||||||
@@ -1872,7 +2170,7 @@ check('矩形圆角生效(角落被切,墨迹减少)',
|
|||||||
'radius=' + JSON.stringify(radiusVal) + ' ink ' + inkSharp + '→' + inkRound)
|
'radius=' + JSON.stringify(radiusVal) + ' ink ' + inkSharp + '→' + inkRound)
|
||||||
|
|
||||||
// 最近使用颜色
|
// 最近使用颜色
|
||||||
await page.locator('[data-action="toggleColorPop"]').click()
|
await page.locator('[data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||||
await page.waitForTimeout(150)
|
await page.waitForTimeout(150)
|
||||||
await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click()
|
await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click()
|
||||||
await page.waitForTimeout(200)
|
await page.waitForTimeout(200)
|
||||||
@@ -1886,6 +2184,206 @@ check('选过的颜色进入「最近使用」并出现在色板弹层',
|
|||||||
|
|
||||||
// 复制到剪贴板:harness 跑在 about:blank(非安全上下文),
|
// 复制到剪贴板:harness 跑在 about:blank(非安全上下文),
|
||||||
// 这里只验「按钮存在 + 点击有明确反馈 + 不抛错」,真安全上下文由本地 http 探针覆盖
|
// 这里只验「按钮存在 + 点击有明确反馈 + 不抛错」,真安全上下文由本地 http 探针覆盖
|
||||||
|
// ---- v1.10:矢量图形也有描边色 / 填充色 ----
|
||||||
|
// 用户要求「把其他的矢量图形也加上描边与填充色属性,工具栏上加描边色设置」。
|
||||||
|
// 设计:描边色 = 主色(左侧色板 / 吸管 / 选项栏一个真相源),填充色独立存形状的
|
||||||
|
// fillColor,没单独设过就跟随描边色 —— 于是「切实心 = 同色实心」,不会突兀。
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
const shapeColorUI = await page.evaluate(() => {
|
||||||
|
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||||||
|
return {
|
||||||
|
stroke: body.querySelectorAll('[data-shape-color="stroke"]').length,
|
||||||
|
fill: body.querySelectorAll('[data-shape-color="fill"]').length
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('矩形工具的选项栏就带描边色 / 填充色块(画之前就能定色)',
|
||||||
|
shapeColorUI.stroke === 1 && shapeColorUI.fill === 1, JSON.stringify(shapeColorUI))
|
||||||
|
|
||||||
|
pa = await imgToScreen(62, 6)
|
||||||
|
pb = await imgToScreen(90, 28)
|
||||||
|
await page.mouse.move(pa.x, pa.y)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(pb.x, pb.y, { steps: 6 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const shapeFresh = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
return d.shapes[d.shapes.length - 1]
|
||||||
|
})
|
||||||
|
check('新建图形的填充默认「跟随描边色」(fillColor=null),不是写死某个填充色',
|
||||||
|
shapeFresh.fillColor === null, JSON.stringify({ fill: shapeFresh.fill, fillColor: shapeFresh.fillColor }))
|
||||||
|
|
||||||
|
// 数「目标颜色」的像素:矢量画布含 overlayPad 外扩,按图片坐标换算单点会采到别处,
|
||||||
|
// 直接全画布统计同色像素最稳(0 → 上千,量级差别足够断言)
|
||||||
|
const countColorInVec = (rgb, tol) => page.evaluate(({ rgb, tol }) => {
|
||||||
|
let n = 0
|
||||||
|
for (const cv of [...document.querySelectorAll('.iwb-editor-vec-canvas')]) {
|
||||||
|
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||||||
|
for (let i = 0; i < d.length; i += 4) {
|
||||||
|
if (d[i + 3] > 200 && Math.abs(d[i] - rgb[0]) < tol && Math.abs(d[i + 1] - rgb[1]) < tol && Math.abs(d[i + 2] - rgb[2]) < tol) n++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}, { rgb, tol })
|
||||||
|
|
||||||
|
const greenBefore = await countColorInVec([34, 204, 85], 8)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||||||
|
el.value = '#22cc55'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(280)
|
||||||
|
const shapeFilled = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes[d.shapes.length - 1]
|
||||||
|
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||||||
|
return {
|
||||||
|
fill: s.fill, fillColor: s.fillColor,
|
||||||
|
fillBtnOn: !!body.querySelector('[data-opt-toggle="fill"]').classList.contains('active'),
|
||||||
|
fillSwatchOff: body.querySelector('[data-shape-color="fill"]').classList.contains('is-off')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const greenAfter = await countColorInVec([34, 204, 85], 8)
|
||||||
|
check('选填充色即自动切实心,画面上真的是这个颜色(不是只改了个字段)',
|
||||||
|
shapeFilled.fill === true && shapeFilled.fillColor === '#22cc55' && greenBefore === 0 && greenAfter > 200,
|
||||||
|
JSON.stringify(shapeFilled) + ' 绿色像素 ' + greenBefore + '→' + greenAfter)
|
||||||
|
check('填充色块随之变为「生效」态(不再是灰色斜纹)',
|
||||||
|
shapeFilled.fillSwatchOff === false && shapeFilled.fillBtnOn === true,
|
||||||
|
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(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
||||||
|
el.value = '#3388ff'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(280)
|
||||||
|
const shapeStroked = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes[d.shapes.length - 1]
|
||||||
|
return { shapeColor: s.color, mainColor: d.color }
|
||||||
|
})
|
||||||
|
check('改图形描边色 = 改主色(色板 / 吸管 / 选项栏不会各说各话)',
|
||||||
|
shapeStroked.shapeColor === '#3388ff' && shapeStroked.mainColor === '#3388ff',
|
||||||
|
JSON.stringify(shapeStroked))
|
||||||
|
|
||||||
|
// ---- v1.11:颜色收敛成「描边 / 填充」两格,工具栏与选项栏读同一份 ----
|
||||||
|
// 用户原话:「3 个位置调色有问题,应该是 2 个调色」「请给工具栏加一个描边色,
|
||||||
|
// 工具选择的填充与描边与这里对应上」「填色里还需要添加一个取消颜色的按钮,就是无色状态」
|
||||||
|
const pairMode = await page.evaluate(() => {
|
||||||
|
const pair = document.querySelector('.iwb-editor-color-pair')
|
||||||
|
const btns = [...pair.querySelectorAll('.iwb-editor-color-btn')]
|
||||||
|
return { mode: pair.dataset.colorMode, visible: btns.filter(b => b.offsetParent !== null).map(b => b.dataset.colorSlot) }
|
||||||
|
})
|
||||||
|
check('工具栏给出「描边 + 填充」两格(形状工具下两格都在)',
|
||||||
|
pairMode.mode === 'pair' && pairMode.visible.join(',') === 'stroke,fill', JSON.stringify(pairMode))
|
||||||
|
|
||||||
|
// 从工具栏填充槽进色板:目标应当是填充,且出现「无」
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const popTarget = await page.evaluate(() => {
|
||||||
|
const pop = document.querySelector('.iwb-editor-color-pop')
|
||||||
|
return {
|
||||||
|
open: !pop.hidden,
|
||||||
|
fillActive: pop.querySelector('.iwb-color-pop-tab[data-color-slot="fill"]').classList.contains('active'),
|
||||||
|
noneVisible: !pop.querySelector('[data-color-none]').hidden
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('点填充槽打开色板:目标是填充,并出现「无」按钮',
|
||||||
|
popTarget.open && popTarget.fillActive && popTarget.noneVisible, JSON.stringify(popTarget))
|
||||||
|
|
||||||
|
// 用一个画布上不会出现的怪色(#a014b2)验收:12 个推荐色在前面用例里都用过,
|
||||||
|
// 拿黄色/绿色统计会数到别的图形,永远清不到 0。
|
||||||
|
const mainBefore = await page.evaluate(() => window.__iwbEditor.__debug().color)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||||
|
el.value = '#a014b2'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const fromPop = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes[d.shapes.length - 1]
|
||||||
|
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
||||||
|
return { main: d.color, fillColor: s.fillColor, fill: s.fill, fillBtnBg: fillBtn.querySelector('i').style.backgroundColor }
|
||||||
|
})
|
||||||
|
check('色板里选色写进填充、主色(描边)不动,工具栏填充格同步变色',
|
||||||
|
fromPop.main === mainBefore && fromPop.fillColor === '#a014b2' && fromPop.fill === true &&
|
||||||
|
/160, 20, 178/.test(fromPop.fillBtnBg), JSON.stringify(fromPop))
|
||||||
|
|
||||||
|
// 「无」:关填充,画面清空,但颜色留着
|
||||||
|
const purpleBefore = await countColorInVec([160, 20, 178], 10)
|
||||||
|
await page.evaluate(() => document.querySelector('[data-color-none]').click())
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const afterNone = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes[d.shapes.length - 1]
|
||||||
|
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
||||||
|
return { fill: s.fill, fillColor: s.fillColor, btnCls: fillBtn.className, noneActive: document.querySelector('[data-color-none]').classList.contains('active') }
|
||||||
|
})
|
||||||
|
const purpleAfter = await countColorInVec([160, 20, 178], 10)
|
||||||
|
check('「无」把填充关掉:画面清空、颜色留着(下次点颜色还是它)',
|
||||||
|
afterNone.fill === false && afterNone.fillColor === '#a014b2' && purpleBefore > 200 && purpleAfter === 0,
|
||||||
|
JSON.stringify(afterNone) + ' 紫色像素 ' + purpleBefore + '→' + purpleAfter)
|
||||||
|
check('无填充时工具栏填充格显示「无」(斜杠态,不露颜色本身)',
|
||||||
|
/is-none/.test(afterNone.btnCls) && afterNone.noneActive === true, JSON.stringify(afterNone))
|
||||||
|
|
||||||
|
// 反方向:选项栏改填充 → 工具栏填充格跟上
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||||||
|
el.value = '#22cc55'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const reverse = await page.evaluate(() => {
|
||||||
|
const pair = document.querySelector('.iwb-editor-color-pair')
|
||||||
|
const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||||||
|
return { fillBtnBg: pair.querySelector('[data-color-slot="fill"] i').style.backgroundColor, optVal: opt.value }
|
||||||
|
})
|
||||||
|
check('选项栏改填充色,工具栏填充格立刻跟上(两处同一份值)',
|
||||||
|
reverse.optVal === '#22cc55' && /34, 204, 85/.test(reverse.fillBtnBg), JSON.stringify(reverse))
|
||||||
|
|
||||||
|
// 画笔没有填充概念:只留一格
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const brushPair = 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).length }
|
||||||
|
})
|
||||||
|
check('画笔工具下只留一格(画笔没有填充概念,不留空格让人猜)',
|
||||||
|
brushPair.mode === 'single' && brushPair.visible === 1, JSON.stringify(brushPair))
|
||||||
|
|
||||||
const copyExists = await page.locator('[data-action="copyClipboard"]').count()
|
const copyExists = await page.locator('[data-action="copyClipboard"]').count()
|
||||||
await page.locator('[data-action="copyClipboard"]').click()
|
await page.locator('[data-action="copyClipboard"]').click()
|
||||||
await page.waitForTimeout(400)
|
await page.waitForTimeout(400)
|
||||||
|
|||||||
Reference in new issue
Block a user