Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a94e5be954 | ||
|
|
b6d10339f6 | ||
|
|
89c8e0a1d8 | ||
|
|
9bbb94b789 | ||
|
|
6284f84d29 | ||
|
|
b299895730 | ||
|
|
32363d8c9b | ||
|
|
352a7668d7 | ||
|
|
3baa76d0cd | ||
|
|
a477705c7f |
No files matched your search
@@ -234,6 +234,129 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
|||||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||||
|
|
||||||
|
## v1.18.0:色板可以「钉住」+ 右列竖向收窄 + 撤销组搬进工具条
|
||||||
|
|
||||||
|
用户两句话:「这个弹出的调色气泡,加一个功能就是让他能够钉住,在需要调色的时候不用每次都要点开」
|
||||||
|
「右边的数值、常用色、最近色你看下能不能竖向排…顺序改为设置、常用色、最近,这三项不用标题,
|
||||||
|
用细横线分割」;另加「这几个图标移动到工具栏的最右边」(撤销 / 重做 / 还原)。
|
||||||
|
|
||||||
|
**钉住**:色板弹层右上角一颗图钉(`data-action="pinColorPop"`)。
|
||||||
|
|
||||||
|
- 钉住时点画布、点别处都不收起 —— 这就是它存在的全部意义(要收就再点一次图钉或按 Esc)。
|
||||||
|
- 状态写 `ctx.settings.colorPopPinned`,跨会话记住:钉过一次就一直钉着,下次打开仍是钉住的。
|
||||||
|
- 图钉用**绝对定位**钉在头部右上角(头部留 `padding-right: 26px` 让位),
|
||||||
|
这样「无」按钮的显隐不会把它挤来挤去。
|
||||||
|
- 激活态用琥珀色描边 + 淡底,不旋转角度:45° 的图钉在 13px 下看着像歪掉的问号。
|
||||||
|
|
||||||
|
**右列竖向**:原来「吸管+HEX | 常用色 | 最近」是横向并排、靠小标题分组,
|
||||||
|
弹层宽 630px 且「常用色 / 最近」各占一行标题。现在三块竖着叠、块间 1px 细线、**不要标题**:
|
||||||
|
|
||||||
|
```
|
||||||
|
[ 取色器 ] │ [吸管 #FF4444] ← 设置
|
||||||
|
│ ─────────────
|
||||||
|
│ ●●●●●● ●●●●●● ← 常用色(6 列 × 2 行)
|
||||||
|
│ ─────────────
|
||||||
|
│ ●●●●●● ← 最近(6 列,上限收到 6 个正好一行)
|
||||||
|
```
|
||||||
|
|
||||||
|
弹层从 **630×157 → 380×153**:宽度砍掉 40%,高度基本不变(标题行省下来的高度被 6 列更窄的网格吃掉)。
|
||||||
|
色块 22px → 18px;「最近」上限 8 → 6,否则 8 个会折成第二行,把面板顶高 23px,和「更紧凑」相反。
|
||||||
|
|
||||||
|
同一份 DOM 右栏常驻面板也在用,那边靠 `.iwb-editor-colors .iwb-color-pop-side { display: contents }`
|
||||||
|
把新加的 `.iwb-color-pop-side` 这层拆掉,走自己原来的竖排,pin 按钮在右栏 `display: none`。
|
||||||
|
|
||||||
|
**撤销组搬位**:撤销 / 重做 / 还原从顶栏 `.iwb-editor-history` 移到画布底部工具栏最右(视图快捷之后)。
|
||||||
|
理由是这三个是画画时会连着按的操作,手在画布上,不该抬头去顶栏找。顶栏只剩会话组(新建/覆盖/退出)与输出。
|
||||||
|
三个按钮本来就和工具按钮同为 32×32 `.iwb-editor-action` 样式,搬过去不用改尺寸。
|
||||||
|
|
||||||
|
**验证**:harness 228 项(新增 5 项:右列竖排几何 + 1px 分隔线 + 无标题、弹层尺寸 ≤ 460×175、
|
||||||
|
钉住后点画布不收起且写进 settings、取消钉住后点画布立即收起、撤销组是 tools 最后子元素且与工具同轴)。
|
||||||
|
改了两条老断言:顶栏不再有 `.iwb-editor-history`;`[data-action="reset"]` 的查询范围从 header 改成 tools。
|
||||||
|
|
||||||
|
## v1.17.0:描边也能是「无色」+ 一边无色时 Shift+X 照样交换
|
||||||
|
|
||||||
|
用户两句话:「让矢量图形与钢笔的描边色也可以去掉」「描边与填充有一个是无色的时候可以交换,
|
||||||
|
现在是不可以的」。
|
||||||
|
|
||||||
|
### 描边的第三态
|
||||||
|
|
||||||
|
以前描边只有「什么颜色」,没有「有没有」。现在形状对象多一个 `strokeOn`(缺省 = 有,
|
||||||
|
老对象与历史快照没有这个字段一律当有描边,不需要数据迁移):
|
||||||
|
|
||||||
|
- `drawShape()` 里所有 `ctx.stroke()` 都按 `strokeOn` 跳过。**不能用 `lineWidth = 0` 实现**——
|
||||||
|
canvas 会忽略 0 并保留上一次的线宽,且改回需要记住原值;
|
||||||
|
- 「无」按钮出现在**描边槽**(色板头部 / 右栏面板同一份 DOM),点一下只关外框、颜色留着,
|
||||||
|
下次选色直接恢复(与「文字描边宽度 0 时选色自动给 6px」同一条逻辑,选色共用一张快照,撤销一步);
|
||||||
|
- 「只描边」的形状去掉描边会整体消失,所以**顺手切实心** —— 结果是「一个没有框的色块」,
|
||||||
|
而不是「对象凭空没了」;反过来在选项栏点「描边」也会自动恢复 `strokeOn`;
|
||||||
|
- 只有**「去掉后还看得见」才给「无」**:矩形/圆形、闭合钢笔可以;箭头、未闭合钢笔不给
|
||||||
|
(判据复用 `fillSlotOn()`,与「填充槽存不存在」同一份逻辑);
|
||||||
|
- 视觉:工具栏描边格与色板 tab 画红斜杠(复用 `.is-none`),选项栏描边色块置灰(`.is-off`)。
|
||||||
|
|
||||||
|
### Shift+X:交换的是「颜色 + 有无」
|
||||||
|
|
||||||
|
以前只交换颜色值,所以「无填充」时按 X 看不出任何变化(只有一个颜色,被判定为「无需交换」)。
|
||||||
|
现在交换整份状态:
|
||||||
|
|
||||||
|
- 两边都有色 → 颜色对调,开关不动(v1.13.1 的语义保留);
|
||||||
|
- 只有一边有色 → 有色那边连同颜色整体换到另一边(无填充 + 有色描边 ⇄ 有色填充 + 无描边);
|
||||||
|
- 填充色还在「跟随描边色」(`fillColor=null`)→ 只换有无,颜色继续跟随,不拆成独立色;
|
||||||
|
- 两边都无色、或箭头/未闭合钢笔(换完什么都不剩)→ toast 提示,不写历史。
|
||||||
|
|
||||||
|
`__debug().shapes` 增加 `strokeOn`,harness 补 7 条(描边像素清零、三处 UI 斜杠态、
|
||||||
|
「无描边」后再点「无填充」的对称保护、选色恢复描边、钢笔闭合可去描边、
|
||||||
|
未闭合不给入口、一边无色可交换并回退)。
|
||||||
|
|
||||||
|
### v1.17.1:对称保护
|
||||||
|
|
||||||
|
「无描边」后再去点「无填充」,两者都无色会让对象彻底隐形。填充的「无」现在也会检查描边:
|
||||||
|
若描边已关就自动恢复,与「无描边时顺手切实心」正好对称 —— 两条路径都不会产出看不见的对象。
|
||||||
|
|
||||||
|
## v1.16.0:右栏常驻调色面板 + 可拖宽度 + 整体字号提升
|
||||||
|
|
||||||
|
用户三句话拆成四件事:面板文字偏小、右栏要能拖宽、把调色面板(含常用色)搬进右栏、
|
||||||
|
顶部能切换当前元素要调的颜色。
|
||||||
|
|
||||||
|
### 调色面板进右栏(弹层保留)
|
||||||
|
|
||||||
|
调色面板不再是「只能弹出来」:右栏顶部常驻一份,工具栏色块点击仍然弹一份。
|
||||||
|
两处**是同一份 DOM**(`dom.js#colorSurfaceHtml()`),靠 `data-color-surface` 区分:
|
||||||
|
|
||||||
|
- `bindColorSurface(surface)` 每块面板各绑一次交互(tab / 无 / 常用色 / 最近色 / HEX / 吸管 / SV 拖动);
|
||||||
|
- `updateColorUI()` 里原本单点的 `querySelector` 全改成 `querySelectorAll` 遍历——
|
||||||
|
HEX 回填、SV 背景与指示点、色相指示点、「无」按钮显隐,两处一起刷。
|
||||||
|
|
||||||
|
复制两段 HTML 的方案被否掉:这套控件有 4 组联动,复制就等于以后每个改动都要改两遍,
|
||||||
|
漏一处就是「一边变了另一边没变」——这个项目已经因为「同一概念两处各写一份」栽过几次。
|
||||||
|
|
||||||
|
顶部三格就是**当前元素可调的颜色项**,跟随选中对象变化:形状 = 描边/填充、
|
||||||
|
文字 = 文字/描边/底色、箭头与画笔 = 只有主色。
|
||||||
|
|
||||||
|
布局差异全在 CSS:弹层横排一行(SV 180×104 + HEX + 常用色 6×2 + 最近 4×2),
|
||||||
|
右栏窄所以改竖排(SV 全宽 118 高 → HEX 一行 → 常用色 → 最近)。
|
||||||
|
右栏色块用 `repeat(auto-fill, minmax(24px, 1fr))`,拖宽后一行自动多放几个。
|
||||||
|
|
||||||
|
### 右栏可拖宽度
|
||||||
|
|
||||||
|
- `.iwb-editor-side-resizer` 贴在右栏左边缘(9px 热区,悬停才亮橙线,避免和面板分隔线打架);
|
||||||
|
- 宽度统一写 CSS 变量 `--iwb-side-w`,原来三处硬编码的 240/240/220 全部改成读它;
|
||||||
|
- 范围 220–520,且不超过窗口 45%(窄窗口不把画布挤没);默认 280(220 时「温度/色调」会被压成两字);
|
||||||
|
- 双击手柄复位;松手写宿主 `settings.sideWidth`,下次打开恢复。
|
||||||
|
|
||||||
|
### 字号 +1 档
|
||||||
|
|
||||||
|
旧值大量是 10–11.5px(按 1440 宽屏定的),2K/4K 与系统缩放 125% 下发虚。
|
||||||
|
不逐条改原规则,改为在 CSS 末尾用 `#iwb-editor-overlay` 前缀集中覆盖一档:
|
||||||
|
面板行名 10 → 12.5、标题 11.5 → 13、状态栏 11 → 12、选项栏 12 → 13、
|
||||||
|
图层名 12 → 13、色板 tab 11.5 → 12.5。宿主画布外的节点浮条不在遮罩内,不受影响。
|
||||||
|
|
||||||
|
同时把「图片调节」的名称列 46 → 50px、数值框 36 → 40px,字号变大后不会挤成省略号。
|
||||||
|
|
||||||
|
### 回归
|
||||||
|
|
||||||
|
harness 新增 5 条:右栏面板结构、右栏选色后弹层同步高亮、拖宽生效、双击复位、字号计算值。
|
||||||
|
色板相关旧用例的选择器全部限定到 `.iwb-editor-color-pop`(否则右栏那份会命中 strict mode 冲突)。
|
||||||
|
|
||||||
## v1.15.1:修「换一张图调节,画面还原成上一张」
|
## v1.15.1:修「换一张图调节,画面还原成上一张」
|
||||||
|
|
||||||
### 病灶
|
### 病灶
|
||||||
|
|||||||
@@ -311,6 +311,8 @@ 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 迭代降质、下载、设置记忆;无队列 |
|
||||||
|
| 描边「无色」+ X 交换整份状态(v1.17.0 / v1.17.1) | ✅ 形状对象新增 `strokeOn`(缺省有描边,老对象/历史快照无此字段照旧),`drawShape()` 按它跳过 `ctx.stroke()`(不能用 `lineWidth=0`:canvas 忽略 0 且丢失原值);「无」按钮扩到**描边槽**,只关外框、颜色留着,选色即恢复(共用一张快照);去掉描边后会把「只描边」的形状顺手切实心,避免对象消失;箭头与未闭合钢笔不给入口(判据复用 `fillSlotOn()`)。Shift+X 从「只交换颜色」升级为**交换颜色 + 有无**:一边有色时连同颜色整体换到另一边,填充「跟随描边色」时只换有无不拆独立色,两边都无色或换完一无所有则提示不执行。v1.17.1 补对称保护:先无描边再点「无填充」时自动恢复描边,杜绝隐形对象 |
|
||||||
|
| 右栏调色面板 / 可拖宽度 / 字号(v1.16.0) | ✅ 调色面板从「只弹层」变成「右栏常驻 + 弹层保留」,两处共用同一份 DOM(`dom.js#colorSurfaceHtml`),按 `[data-color-surface]` 各绑一次交互、`updateColorUI` 改遍历同步(HEX / SV / 色相 / 「无」显隐 / 常用色与最近色高亮);右栏宽度统一到 CSS 变量 `--iwb-side-w`(原三处硬编码 240/240/220),手柄 9px 热区、范围 220–520 且 ≤ 窗口 45%、默认 280、双击复位、写 `settings.sideWidth` 记忆;字号在 CSS 末尾用 `#iwb-editor-overlay` 前缀集中 +1 档(面板行名 12.5 / 标题 13 / 状态栏 12 / 选项栏 13 / 颜色 tab 12.5),调节名称列 46→50、数值框 36→40 |
|
||||||
| 调节基准跨图串用修复(v1.15.1) | ✅ 退出编辑器后 `sourceCache`(key = `layer.id`,原图恒为 `'base'`)与 `S.adjust` 未清 ⇒ 第二张图一拖滑杆就把上一张图的像素重算上来,且 `ensureAdjustTarget()` 因 `layerId` 相同而跳过重拍基准。新增 `resetAdjustCache()`,在 `resetState()` 与 `releaseEditorMemory()` 双路径清空;`__debug()` 增 `adjustCacheSize` 观测口,harness 补「退出→重开」三条断言 |
|
| 调节基准跨图串用修复(v1.15.1) | ✅ 退出编辑器后 `sourceCache`(key = `layer.id`,原图恒为 `'base'`)与 `S.adjust` 未清 ⇒ 第二张图一拖滑杆就把上一张图的像素重算上来,且 `ensureAdjustTarget()` 因 `layerId` 相同而跳过重拍基准。新增 `resetAdjustCache()`,在 `resetState()` 与 `releaseEditorMemory()` 双路径清空;`__debug()` 增 `adjustCacheSize` 观测口,harness 补「退出→重开」三条断言 |
|
||||||
| 图片调节(v1.15.0) | ✅ 右侧栏新增 11 项连续调色:曝光(±2EV)/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度。走 `getImageData` 逐像素(CSS filter 做不到阴影高光的分区蒙版、白平衡的通道增益、锐化的卷积);拖动用长边 ≤900 的降采样预览(6.7ms),松手才全量(4000² 144ms)。`source` + 每层 `sourceCache` 保证永远从基准重算不叠加;撤销后滑块归零并重拍基准。顺带修强度:增强 brightness 1.12→1.4、高对比 contrast 1.4→1.6 |
|
| 图片调节(v1.15.0) | ✅ 右侧栏新增 11 项连续调色:曝光(±2EV)/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度。走 `getImageData` 逐像素(CSS filter 做不到阴影高光的分区蒙版、白平衡的通道增益、锐化的卷积);拖动用长边 ≤900 的降采样预览(6.7ms),松手才全量(4000² 144ms)。`source` + 每层 `sourceCache` 保证永远从基准重算不叠加;撤销后滑块归零并重拍基准。顺带修强度:增强 brightness 1.12→1.4、高对比 contrast 1.4→1.6 |
|
||||||
| 文字字体下拉修复(v1.14.1) | ✅ 选项栏 click 委托原用 `closest([data-opt-text])` 判断文字样式按钮,`<select data-opt-text="fontFamily">` 自带该属性 → 被当按钮 → 取 `dataset.value`(select 上没有)= undefined → `fontKeyOf` 脏值收敛成 `sans`,症状是「点开下拉看一眼字体就被打回黑体」。改为只认 `button[data-opt-text]` + select 早退;`syncOptionBar` 的 active 遍历同步收紧;change 后不再整体重绘(否则换掉刚操作的下拉节点、焦点丢失)。补 2 条真实 click 用例 —— 原用例用 `selectOption` 绕过 click 才漏掉 |
|
| 文字字体下拉修复(v1.14.1) | ✅ 选项栏 click 委托原用 `closest([data-opt-text])` 判断文字样式按钮,`<select data-opt-text="fontFamily">` 自带该属性 → 被当按钮 → 取 `dataset.value`(select 上没有)= undefined → `fontKeyOf` 脏值收敛成 `sans`,症状是「点开下拉看一眼字体就被打回黑体」。改为只认 `button[data-opt-text]` + select 早退;`syncOptionBar` 的 active 遍历同步收紧;change 后不再整体重绘(否则换掉刚操作的下拉节点、焦点丢失)。补 2 条真实 click 用例 —— 原用例用 `selectOption` 绕过 click 才漏掉 |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.15.1",
|
"version": "1.18.0",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -232,6 +232,10 @@
|
|||||||
gap: 4px;
|
gap: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 撤销 / 重做 / 还原(v1.18):搬进工具条末端后需要一个 flex 容器,
|
||||||
|
否则三个 button 之间是 inline-block 的空隙,和左边 4px gap 的工具按钮对不齐。 */
|
||||||
|
.iwb-editor-history { display: flex; align-items: center; gap: 4px; }
|
||||||
|
|
||||||
.iwb-editor-tool, .iwb-editor-action {
|
.iwb-editor-tool, .iwb-editor-action {
|
||||||
background: #313244;
|
background: #313244;
|
||||||
border: none;
|
border: none;
|
||||||
@@ -1218,7 +1222,9 @@
|
|||||||
|
|
||||||
/* 左栏:调色板在上,参数竖排,导出按钮底部 */
|
/* 左栏:调色板在上,参数竖排,导出按钮底部 */
|
||||||
.iwb-editor-left {
|
.iwb-editor-left {
|
||||||
width: 240px; min-width: 240px; flex: 0 0 240px;
|
/* v1.16:宽度唯一出处。拖拽手柄写 --iwb-side-w,下面两条历史规则也都读它,
|
||||||
|
不再各写一个 240/220 的魔数(以前三处硬编码,改一次要搜三次)。 */
|
||||||
|
width: var(--iwb-side-w, 280px); min-width: var(--iwb-side-w, 280px); flex: 0 0 var(--iwb-side-w, 280px);
|
||||||
display: flex; flex-direction: column; gap: 14px;
|
display: flex; flex-direction: column; gap: 14px;
|
||||||
padding: 12px; background: #181825; border-right: 1px solid #313244; overflow-y: auto;
|
padding: 12px; background: #181825; border-right: 1px solid #313244; overflow-y: auto;
|
||||||
}
|
}
|
||||||
@@ -1322,7 +1328,7 @@
|
|||||||
.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }
|
.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }
|
||||||
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 290px; min-width: 290px; width: 290px; }
|
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 290px; min-width: 290px; width: 290px; }
|
||||||
.iwb-editor-main > .iwb-editor-canvas-wrap { flex: 1 1 auto; min-width: 0; }
|
.iwb-editor-main > .iwb-editor-canvas-wrap { flex: 1 1 auto; min-width: 0; }
|
||||||
.iwb-editor-left { flex: 0 0 240px; min-width: 240px; width: 240px; }
|
.iwb-editor-left { flex: 0 0 var(--iwb-side-w, 280px); min-width: var(--iwb-side-w, 280px); width: var(--iwb-side-w, 280px); }
|
||||||
.iwb-editor-layer-panel .iwb-editor-layer-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
|
.iwb-editor-layer-panel .iwb-editor-layer-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
|
||||||
|
|
||||||
/* ======== 顶部布局 v5:左侧重置类 / 中间工具 / 右侧保存类 ======== */
|
/* ======== 顶部布局 v5:左侧重置类 / 中间工具 / 右侧保存类 ======== */
|
||||||
@@ -1529,7 +1535,7 @@
|
|||||||
}
|
}
|
||||||
.iwb-editor-main { padding-left: 0; }
|
.iwb-editor-main { padding-left: 0; }
|
||||||
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 260px !important; min-width: 260px !important; width: 260px !important; }
|
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 260px !important; min-width: 260px !important; width: 260px !important; }
|
||||||
.iwb-editor-left { flex: 0 0 220px !important; min-width: 220px !important; width: 220px !important; }
|
.iwb-editor-left { flex: 0 0 var(--iwb-side-w, 280px) !important; min-width: var(--iwb-side-w, 280px) !important; width: var(--iwb-side-w, 280px) !important; }
|
||||||
.iwb-editor-overlay.panels-collapsed .iwb-editor-layer-panel,
|
.iwb-editor-overlay.panels-collapsed .iwb-editor-layer-panel,
|
||||||
.iwb-editor-overlay.panels-collapsed .iwb-editor-left { display: none !important; }
|
.iwb-editor-overlay.panels-collapsed .iwb-editor-left { display: none !important; }
|
||||||
.iwb-editor-zoom-hint { display: none !important; }
|
.iwb-editor-zoom-hint { display: none !important; }
|
||||||
@@ -1781,8 +1787,8 @@
|
|||||||
|
|
||||||
|
|
||||||
.iwb-editor-color-pop {
|
.iwb-editor-color-pop {
|
||||||
position: absolute; z-index: 60; display: flex; flex-direction: column; align-items: stretch; gap: 9px;
|
position: absolute; z-index: 60; display: flex; flex-direction: column; align-items: stretch; gap: 7px;
|
||||||
padding: 10px 12px; border-radius: 12px;
|
padding: 9px 11px; 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);
|
||||||
@@ -1820,29 +1826,60 @@
|
|||||||
.iwb-color-pop-none:hover { border-color: #f38ba8; color: #f38ba8; }
|
.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.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-none[hidden] { display: none; }
|
||||||
.iwb-color-pop-body { display: flex; align-items: center; gap: 10px; }
|
.iwb-color-pop-body { display: flex; align-items: stretch; 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: 176px; height: 102px; flex: 0 0 176px; }
|
||||||
.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: 102px; flex: 0 0 16px; }
|
||||||
.iwb-color-pop-sep { width: 1px; align-self: stretch; background: #313244; flex: 0 0 auto; }
|
.iwb-color-pop-sep { width: 1px; align-self: stretch; background: #313244; flex: 0 0 auto; }
|
||||||
.iwb-color-pop-fields { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
|
|
||||||
|
/* ==== 右列(v1.18,用户 2026-11-10)====
|
||||||
|
设置 / 常用色 / 最近 三块竖着叠,块之间 1px 细线,不写小标题:
|
||||||
|
原来「常用色」「最近」各占一行标题 + 横向铺开,整块面板又宽又高。
|
||||||
|
现宽 133px(6 列 × 18px),三块高度加起来刚好填满左侧取色器的高度。 */
|
||||||
|
.iwb-color-pop-side {
|
||||||
|
display: flex; flex-direction: column; justify-content: space-between;
|
||||||
|
width: 133px; flex: 0 0 133px; gap: 0;
|
||||||
|
}
|
||||||
|
/* 细线分隔:只加在「块与块之间」,第一块前面不加,否则顶部多一条悬空的线 */
|
||||||
|
.iwb-color-pop-side > * + * {
|
||||||
|
border-top: 1px solid #313244; margin-top: 5px; padding-top: 5px;
|
||||||
|
}
|
||||||
|
.iwb-color-pop-fields { display: flex; align-items: center; gap: 5px; }
|
||||||
.iwb-editor-color-pop .iwb-editor-color-hex-input {
|
.iwb-editor-color-pop .iwb-editor-color-hex-input {
|
||||||
width: 86px; height: 28px; padding: 0 6px; text-align: center;
|
flex: 1 1 auto; width: 0; height: 26px; padding: 0 5px; text-align: center;
|
||||||
font: 600 12px monospace; border-radius: 6px; box-sizing: border-box;
|
font: 600 12px monospace; border-radius: 6px; box-sizing: border-box;
|
||||||
}
|
}
|
||||||
.iwb-editor-color-pop .iwb-editor-color-swatches {
|
.iwb-editor-color-pop .iwb-editor-color-swatches {
|
||||||
display: grid; grid-template-columns: repeat(6, 22px); grid-auto-rows: 22px;
|
display: grid; grid-template-columns: repeat(6, 18px); grid-auto-rows: 18px;
|
||||||
gap: 7px; flex: 0 0 auto; align-content: center;
|
gap: 5px; flex: 0 0 auto; align-content: center;
|
||||||
}
|
}
|
||||||
.iwb-editor-color-pop .iwb-editor-color-panel-swatch {
|
.iwb-editor-color-pop .iwb-editor-color-panel-swatch {
|
||||||
width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
|
width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
|
||||||
transition: transform 0.08s ease;
|
transition: transform 0.08s ease;
|
||||||
}
|
}
|
||||||
.iwb-editor-color-pop .iwb-editor-color-panel-swatch:hover { transform: scale(1.12); }
|
.iwb-editor-color-pop .iwb-editor-color-panel-swatch:hover { transform: scale(1.14); }
|
||||||
.iwb-editor-color-pop .iwb-editor-color-panel-swatch.active {
|
.iwb-editor-color-pop .iwb-editor-color-panel-swatch.active {
|
||||||
outline: 2px solid #fff; outline-offset: 2px;
|
outline: 2px solid #fff; outline-offset: 2px;
|
||||||
}
|
}
|
||||||
.iwb-editor-color-pop .iwb-editor-color-eye { width: 28px; height: 28px; border-radius: 6px; }
|
.iwb-editor-color-pop .iwb-editor-color-eye { width: 26px; height: 26px; border-radius: 6px; flex: 0 0 auto; }
|
||||||
|
|
||||||
|
/* ==== 钉住(v1.18)====
|
||||||
|
绝对定位到头部右上角:这样「无」按钮显隐都不会把图钉挤来挤去,
|
||||||
|
头部加 padding-right 让出位置,两者不会叠在一起。 */
|
||||||
|
.iwb-color-pop-head { position: relative; padding-right: 26px; }
|
||||||
|
.iwb-color-pop-pin {
|
||||||
|
position: absolute; right: 0; top: 50%; transform: translateY(-50%);
|
||||||
|
width: 22px; height: 22px; padding: 0;
|
||||||
|
display: inline-flex; align-items: center; justify-content: center;
|
||||||
|
border: 1px solid transparent; border-radius: 6px; background: transparent;
|
||||||
|
color: #9aa0b4; cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-color-pop-pin:hover { background: #313244; color: #cdd6f4; }
|
||||||
|
/* 钉住态:琥珀色描边 + 淡底。用颜色而不是旋转表达「已钉住」,
|
||||||
|
旋转 45° 的图钉在 13px 下看起来像歪掉的问号。 */
|
||||||
|
.iwb-color-pop-pin.active {
|
||||||
|
background: rgba(232, 167, 53, 0.16); border-color: #e8a735; color: #f0b752;
|
||||||
|
}
|
||||||
|
|
||||||
/* ================================================================
|
/* ================================================================
|
||||||
v1.4:侧栏「快速效果」
|
v1.4:侧栏「快速效果」
|
||||||
@@ -2070,10 +2107,11 @@
|
|||||||
/* 选项栏里色块旁边的分组标签,和「描边 / 底色」这类双字按钮区分开 */
|
/* 选项栏里色块旁边的分组标签,和「描边 / 底色」这类双字按钮区分开 */
|
||||||
.iwb-opt-swatch-label { color: #7f849c; font-size: 11px; flex: 0 0 auto; }
|
.iwb-opt-swatch-label { color: #7f849c; font-size: 11px; flex: 0 0 auto; }
|
||||||
|
|
||||||
/* 「最近使用」:色板弹层里 4 列 × 2 行,空的时候整块隐藏(不占位) */
|
/* 「最近使用」:色板弹层里与常用色同一套 6 列 18px 网格(v1.18 起上限 6 个,正好一行),
|
||||||
|
空的时候整块隐藏(不占位)。 */
|
||||||
.iwb-editor-color-pop .iwb-editor-recent-colors {
|
.iwb-editor-color-pop .iwb-editor-recent-colors {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(4, 18px);
|
grid-template-columns: repeat(6, 18px);
|
||||||
grid-auto-rows: 18px;
|
grid-auto-rows: 18px;
|
||||||
gap: 5px;
|
gap: 5px;
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
@@ -2096,3 +2134,139 @@
|
|||||||
|
|
||||||
/* 选项栏按钮里是中文双字标签(常规/特粗/底色),不给 nowrap 会被挤成竖排 */
|
/* 选项栏按钮里是中文双字标签(常规/特粗/底色),不给 nowrap 会被挤成竖排 */
|
||||||
.iwb-editor-optionbar-body .iwb-opt-btn { white-space: nowrap; }
|
.iwb-editor-optionbar-body .iwb-opt-btn { white-space: nowrap; }
|
||||||
|
|
||||||
|
/* ================================================================
|
||||||
|
v1.16:右栏常驻调色面板 + 可拖宽度 + 整体字号提升一档
|
||||||
|
需求(用户 2026-11-09):① 面板文字偏小 ② 右栏要能拖宽
|
||||||
|
③ 把调色面板(含常用色)搬进右栏 ④ 顶部切换当前元素可调的颜色项
|
||||||
|
================================================================ */
|
||||||
|
|
||||||
|
/* ---- 1) 右栏宽度手柄:贴在侧栏左边缘(侧栏在画布右侧) ----
|
||||||
|
必须放在 left:0 而不是负值:侧栏本身 overflow-x:hidden,探出去的部分会被裁掉。 */
|
||||||
|
.iwb-editor-side-resizer {
|
||||||
|
position: absolute; left: 0; top: 0; bottom: 0; width: 9px;
|
||||||
|
z-index: 46; cursor: col-resize; touch-action: none;
|
||||||
|
}
|
||||||
|
/* 平时完全隐形,悬停/拖动时才亮一条橙线:
|
||||||
|
常驻一条竖线会和「画布/面板」的分隔线打架,看起来像两条边界。 */
|
||||||
|
.iwb-editor-side-resizer::after {
|
||||||
|
content: ''; position: absolute; left: 3px; top: 0; bottom: 0; width: 2px;
|
||||||
|
border-radius: 1px; background: transparent; transition: background 0.12s ease;
|
||||||
|
}
|
||||||
|
.iwb-editor-side-resizer:hover::after,
|
||||||
|
.iwb-editor-side-resizer.is-dragging::after { background: #e8a735; }
|
||||||
|
|
||||||
|
/* ---- 2) 右栏调色面板 ---- */
|
||||||
|
.iwb-editor-colors {
|
||||||
|
display: flex; flex-direction: column; gap: 9px;
|
||||||
|
padding: 9px 10px 10px; border-radius: 10px;
|
||||||
|
background: #1e1e2c; border: 1px solid #2f2f42;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
.iwb-editor-colors-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
|
||||||
|
.iwb-editor-colors-title { font-size: 13px; font-weight: 600; color: #cdd6f4; }
|
||||||
|
.iwb-editor-colors-hint { font-size: 11.5px; color: #7f87a3; }
|
||||||
|
|
||||||
|
/* 弹层是横排一行;右栏窄,改成竖排:调色器全宽 → HEX 一行 → 常用色 → 最近。
|
||||||
|
结构完全一样(同一份 DOM),差异全在这里用容器选择器覆盖。 */
|
||||||
|
.iwb-editor-colors .iwb-color-pop-head { flex-wrap: wrap; gap: 5px; padding-right: 0; }
|
||||||
|
/* 右栏不需要「钉住」(它本来就常驻),也不需要 v1.18 那层 side 容器:
|
||||||
|
display:contents 把它拆掉,子元素直接参与 body 的竖排 flex,和改版前一样。 */
|
||||||
|
.iwb-editor-colors .iwb-color-pop-pin { display: none; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-side { display: contents; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-tab { padding: 0 8px; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-body { flex-direction: column; align-items: stretch; gap: 8px; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-sep { display: none; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-picker { width: 100%; gap: 6px; }
|
||||||
|
.iwb-editor-colors .iwb-color-sv { flex: 1 1 auto; width: auto; height: 118px; }
|
||||||
|
.iwb-editor-colors .iwb-color-hue { width: 16px; height: 118px; flex: 0 0 16px; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-fields { width: 100%; gap: 6px; }
|
||||||
|
.iwb-editor-colors .iwb-editor-color-hex-input { flex: 1 1 auto; width: auto; height: 28px; }
|
||||||
|
.iwb-editor-colors .iwb-editor-color-eye { width: 30px; height: 28px; border-radius: 6px; flex: 0 0 auto; }
|
||||||
|
|
||||||
|
/* 分组:右栏显示「常用色 / 最近」小标题,弹层里隐藏(那里横向排得下,加标题反而占高) */
|
||||||
|
.iwb-color-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 0 0 auto; }
|
||||||
|
.iwb-color-group-label { font-size: 11.5px; color: #7f87a3; letter-spacing: 0.3px; }
|
||||||
|
.iwb-editor-color-pop .iwb-color-group { gap: 0; }
|
||||||
|
.iwb-editor-color-pop .iwb-color-group-label { display: none; }
|
||||||
|
/* display:flex 会盖掉 [hidden] 的默认 display:none,必须显式写一条 */
|
||||||
|
.iwb-color-group[hidden] { display: none; }
|
||||||
|
|
||||||
|
/* 右栏色块:网格按容器宽度自适应,拖宽后一行能多放几个 */
|
||||||
|
.iwb-editor-colors .iwb-editor-color-swatches {
|
||||||
|
display: grid; grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
|
||||||
|
gap: 6px; width: 100%;
|
||||||
|
}
|
||||||
|
.iwb-editor-colors .iwb-editor-recent-colors {
|
||||||
|
display: grid; grid-template-columns: repeat(auto-fill, minmax(22px, 1fr));
|
||||||
|
gap: 6px; width: 100%;
|
||||||
|
}
|
||||||
|
.iwb-editor-colors .iwb-editor-color-panel-swatch {
|
||||||
|
width: 100%; aspect-ratio: 1 / 1; min-height: 22px; padding: 0; border: 0;
|
||||||
|
border-radius: 50%; cursor: pointer; transition: transform 0.08s ease;
|
||||||
|
}
|
||||||
|
.iwb-editor-colors .iwb-editor-color-panel-swatch:hover { transform: scale(1.1); }
|
||||||
|
.iwb-editor-colors .iwb-editor-color-panel-swatch.active { outline: 2px solid #fff; outline-offset: 2px; }
|
||||||
|
|
||||||
|
/* ---- 3) 字号 +1 档 ----
|
||||||
|
旧值大量是 10–11.5px(按 1440 宽屏定的),在 2K/4K 与系统缩放 125% 下发虚。
|
||||||
|
集中用 #iwb-editor-overlay 前缀覆盖而不是逐条改原规则:字号以后只在这块调。
|
||||||
|
宿主画布外的节点浮条(.iwb-node-floatbar 等)不在遮罩内,不受影响。 */
|
||||||
|
#iwb-editor-overlay { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-title em.iwb-editor-doc-size { font-size: 12px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-header > .iwb-editor-session .iwb-editor-btn,
|
||||||
|
#iwb-editor-overlay .iwb-editor-header .iwb-editor-export-actions .iwb-editor-btn { font-size: 12.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-export-settings-btn { font-size: 12.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-export-row > span,
|
||||||
|
#iwb-editor-overlay .iwb-editor-export-note,
|
||||||
|
#iwb-editor-overlay .iwb-editor-more-menu kbd { font-size: 12px; }
|
||||||
|
|
||||||
|
/* 选项栏 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-optionbar { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-opt-label,
|
||||||
|
#iwb-editor-overlay .iwb-opt-current,
|
||||||
|
#iwb-editor-overlay .iwb-opt-btn,
|
||||||
|
#iwb-editor-overlay .iwb-opt-num,
|
||||||
|
#iwb-editor-overlay .iwb-opt-select { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-opt-num { width: 50px; }
|
||||||
|
#iwb-editor-overlay .iwb-opt-hint,
|
||||||
|
#iwb-editor-overlay .iwb-editor-optionbar-tip,
|
||||||
|
#iwb-editor-overlay .iwb-opt-unit,
|
||||||
|
#iwb-editor-overlay .iwb-opt-swatch-label { font-size: 12px; }
|
||||||
|
|
||||||
|
/* 状态栏 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-statusbar { font-size: 12px; height: 28px; min-height: 28px; }
|
||||||
|
|
||||||
|
/* 图层面板 */
|
||||||
|
#iwb-editor-overlay .iwb-layer-name { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-layer-name-input { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-layer-paint { font-size: 12px; }
|
||||||
|
#iwb-editor-overlay .iwb-layer-op,
|
||||||
|
#iwb-editor-overlay .iwb-layer-op-val { font-size: 11.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-layer-op-val { width: 36px; }
|
||||||
|
|
||||||
|
/* 右栏:图片调节 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-title { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-target { font-size: 11.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-reset { font: 500 12px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; padding: 3px 8px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-row { grid-template-columns: 50px 1fr 40px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-name { font-size: 12.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-val { width: 40px; font: 500 12px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-tip { font-size: 11.5px; }
|
||||||
|
|
||||||
|
/* 右栏:快速效果 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-title { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-target { font-size: 11.5px; max-width: 150px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-btn { font: 500 12px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; padding: 8px 2px 7px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-tip { font-size: 11.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-adj-name,
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-adj-val { font-size: 12px; }
|
||||||
|
|
||||||
|
/* 右栏:缩放 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-val,
|
||||||
|
#iwb-editor-overlay .iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-fit { font-size: 12px; }
|
||||||
|
|
||||||
|
/* 调色面板本体 */
|
||||||
|
#iwb-editor-overlay .iwb-color-pop-tab,
|
||||||
|
#iwb-editor-overlay .iwb-color-pop-none { font-size: 12.5px; height: 26px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-color-pop .iwb-editor-color-hex-input { font-size: 13px; }
|
||||||
@@ -10,6 +10,63 @@ import { S, runtime } from './state.js'
|
|||||||
import { bindEvents } from './events.js'
|
import { bindEvents } from './events.js'
|
||||||
|
|
||||||
|
|
||||||
|
// ============ 调色面板(两处共用) ============
|
||||||
|
/**
|
||||||
|
* v1.16:调色面板从「只能弹层」变成「右栏常驻 + 弹层保留」,两处用同一份 DOM。
|
||||||
|
*
|
||||||
|
* 为什么抽成函数而不是复制两段 HTML:这套控件有 4 组联动(tab 高亮、SV/色相指示点、
|
||||||
|
* HEX 回填、常用色/最近色的 active 圈),复制两段 = 以后每加一种颜色语义都要改两遍,
|
||||||
|
* 漏一处就是「一边改了另一边不变」。同一份结构 + 按 `[data-color-surface]` 遍历,
|
||||||
|
* 才可能保证一致(events.js#updateColorUI 就是按 surface 逐个刷的)。
|
||||||
|
*
|
||||||
|
* 布局差异全部交给 CSS:弹层是横排一行,右栏窄,改成竖排(picker 全宽、色块自动换行)。
|
||||||
|
*/
|
||||||
|
const COMMON_COLORS = [
|
||||||
|
'#ff4444', '#ff8a00', '#ffd400', '#4cd964', '#00bfa5', '#4488ff',
|
||||||
|
'#aa44ff', '#ff66aa', '#ffffff', '#d0d0d0', '#808080', '#000000'
|
||||||
|
]
|
||||||
|
|
||||||
|
function colorSurfaceHtml() {
|
||||||
|
return `
|
||||||
|
<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>
|
||||||
|
<!-- 钉住(v1.18,用户 2026-11-10):调色常常要连着改好几处,每次点开色板太碎。
|
||||||
|
钉住后点画布 / 点别处都不收起,只有再点一次图钉、按 Esc、或点吸管才收。
|
||||||
|
图标是竖向图钉(头朝上),激活态整颗变琥珀色。 -->
|
||||||
|
<button type="button" class="iwb-color-pop-pin" data-action="pinColorPop" aria-pressed="false" title="钉住色板:一直开着,点画布也不收起(再点一次取消)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17v5"/><path d="M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z"/></svg></button>
|
||||||
|
</div>
|
||||||
|
<div class="iwb-color-pop-body">
|
||||||
|
<div class="iwb-color-pop-picker">
|
||||||
|
<div class="iwb-color-sv"><span></span></div>
|
||||||
|
<div class="iwb-color-hue"><span></span></div>
|
||||||
|
</div>
|
||||||
|
<span class="iwb-color-pop-sep"></span>
|
||||||
|
<!-- 右侧竖列(v1.18):设置 → 常用色 → 最近,三块上下叠,块间用 1px 细线分隔,
|
||||||
|
不再写「常用色 / 最近」小标题 —— 标题各占一行,是这块面板最浪费的高度。
|
||||||
|
右栏常驻面板复用同一份 DOM,那边用 display:contents 拆掉这一层,走自己的竖排。 -->
|
||||||
|
<div class="iwb-color-pop-side">
|
||||||
|
<div class="iwb-color-pop-fields">
|
||||||
|
<button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:切到吸管工具,在画布上点一下取色"><svg width="13" height="13" 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>
|
||||||
|
<input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7" spellcheck="false" autocomplete="off" title="十六进制颜色,回车生效">
|
||||||
|
</div>
|
||||||
|
<div class="iwb-color-group">
|
||||||
|
<span class="iwb-color-group-label">常用色</span>
|
||||||
|
<div class="iwb-editor-color-swatches">
|
||||||
|
${COMMON_COLORS.map(c => `<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="${c}"></button>`).join('')}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="iwb-color-group">
|
||||||
|
<span class="iwb-color-group-label">最近</span>
|
||||||
|
<div class="iwb-editor-recent-colors" hidden title="最近使用"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ============ DOM 创建 ============
|
// ============ DOM 创建 ============
|
||||||
export function createEl() {
|
export function createEl() {
|
||||||
if (runtime.el) return
|
if (runtime.el) return
|
||||||
@@ -26,11 +83,9 @@ import { bindEvents } from './events.js'
|
|||||||
<button class="iwb-editor-btn iwb-editor-btn-replace" data-action="replace" title="用当前编辑结果覆盖原图">覆盖</button>
|
<button class="iwb-editor-btn iwb-editor-btn-replace" data-action="replace" title="用当前编辑结果覆盖原图">覆盖</button>
|
||||||
<button class="iwb-editor-btn iwb-editor-btn-cancel" data-action="cancel" title="放弃修改并退出">退出</button>
|
<button class="iwb-editor-btn iwb-editor-btn-cancel" data-action="cancel" title="放弃修改并退出">退出</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-history">
|
<!-- 撤销/重做/还原(v1.18,用户 2026-11-10):从顶栏搬到画布底部工具栏最右侧。
|
||||||
<button class="iwb-editor-action" data-action="undo" title="撤销 (Ctrl+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg></button>
|
理由:这三个是「画画时会连着按」的操作,手在画布上,不该抬头去顶栏找。
|
||||||
<button class="iwb-editor-action" data-action="redo" title="重做 (Ctrl+Shift+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>
|
顶栏只留会话组(新建/覆盖/退出)与输出。 -->
|
||||||
<button class="iwb-editor-action iwb-editor-action-reset" data-action="reset" title="还原原图:删掉所有标注/图层,回到打开时的样子(Ctrl+Z 可撤销)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/></svg></button>
|
|
||||||
</div>
|
|
||||||
<!-- 顶栏命令带已清空(v1.13):
|
<!-- 顶栏命令带已清空(v1.13):
|
||||||
四个「置顶/上移/下移/置底」按钮删除(图层面板可拖动 + Ctrl+]/[ 已覆盖);
|
四个「置顶/上移/下移/置底」按钮删除(图层面板可拖动 + Ctrl+]/[ 已覆盖);
|
||||||
「适应窗口 / 收起侧栏」搬到画布底部工具栏最右侧,离画布更近。
|
「适应窗口 / 收起侧栏」搬到画布底部工具栏最右侧,离画布更近。
|
||||||
@@ -164,11 +219,34 @@ import { bindEvents } from './events.js'
|
|||||||
<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="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>
|
<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>
|
||||||
|
|
||||||
|
<!-- 撤销 / 重做 / 还原(v1.18):从顶栏移到工具条最右。
|
||||||
|
放在视图快捷之后,是整条工具栏真正的末端 —— 手在画布区时离得最近。 -->
|
||||||
|
<span class="iwb-editor-divider"></span>
|
||||||
|
<div class="iwb-editor-history">
|
||||||
|
<button class="iwb-editor-action" data-action="undo" title="撤销 (Ctrl+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg></button>
|
||||||
|
<button class="iwb-editor-action" data-action="redo" title="重做 (Ctrl+Shift+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>
|
||||||
|
<button class="iwb-editor-action 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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
||||||
|
|
||||||
<aside class="iwb-editor-left">
|
<aside class="iwb-editor-left">
|
||||||
|
<!-- v1.16:侧栏宽度拖拽手柄。贴在侧栏左边缘(它在画布右侧),
|
||||||
|
双击复位。宽度写进 CSS 变量 --iwb-side-w,由 --iwb-side-w 统一裁各条 width 规则。 -->
|
||||||
|
<div class="iwb-editor-side-resizer" data-side-resizer="1" title="拖动调整侧栏宽度,双击复位"></div>
|
||||||
|
<!-- 调色面板(v1.16):从弹层搬进来常驻一份,弹层保留。
|
||||||
|
两处是同一份 DOM(dom.js#colorSurfaceHtml),靠 data-color-surface 区分与遍历,
|
||||||
|
不存在「一边改了另一边不变」。顶部色格 = 当前元素可调的颜色项,
|
||||||
|
跟随选中对象变化:形状=描边/填充,文字=文字/描边/底色,箭头=只要描边。 -->
|
||||||
|
<section class="iwb-editor-colors" data-color-surface="side">
|
||||||
|
<div class="iwb-editor-colors-head">
|
||||||
|
<span class="iwb-editor-colors-title">颜色</span>
|
||||||
|
<span class="iwb-editor-colors-hint" title="点上面的色格选择要调哪个颜色">点色格切换</span>
|
||||||
|
</div>
|
||||||
|
${colorSurfaceHtml()}
|
||||||
|
</section>
|
||||||
<!-- 调色板已迁到工具栏弹层(v1.3,用户裁定 2026-11-05):
|
<!-- 调色板已迁到工具栏弹层(v1.3,用户裁定 2026-11-05):
|
||||||
侧栏只留快速效果 + 缩放;色板 DOM 在 modal 末尾的 .iwb-editor-color-pop -->
|
侧栏只留快速效果 + 缩放;色板 DOM 在 modal 末尾的 .iwb-editor-color-pop -->
|
||||||
<!-- 图片调节(v1.15):连续调色,作用于当前位图图层(默认原图)。
|
<!-- 图片调节(v1.15):连续调色,作用于当前位图图层(默认原图)。
|
||||||
@@ -242,47 +320,12 @@ import { bindEvents } from './events.js'
|
|||||||
<span class="iwb-editor-status-layer">当前层:原图</span>
|
<span class="iwb-editor-status-layer">当前层:原图</span>
|
||||||
<span class="iwb-editor-status-tool">画笔</span>
|
<span class="iwb-editor-status-tool">画笔</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- 色板弹层(v1.3):工具栏色点点击展开。
|
<!-- 色板弹层(v1.3;v1.16 起与右栏常驻面板共用同一份 DOM):
|
||||||
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
工具栏色块点击展开。必须挂在 modal 下、不能塞进 .iwb-editor-tools ——
|
||||||
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
工具栏是 overflow-x:auto,canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;
|
||||||
<div class="iwb-editor-color-pop" hidden>
|
定位由 events.js 计算。 -->
|
||||||
<!-- 弹层头部(v1.11 两格 → v1.12 文字三格):标明「现在调的是哪个颜色」,
|
<div class="iwb-editor-color-pop" data-color-surface="pop" hidden>
|
||||||
并可直接切换。与工具栏那几个色块是同一组槽位,两边高亮完全一致。
|
${colorSurfaceHtml()}
|
||||||
「无」只对「可以没有」的颜色有意义:文字色没有无,描边/底色/填充才有。 -->
|
|
||||||
<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-sv"><span></span></div>
|
|
||||||
<div class="iwb-color-hue"><span></span></div>
|
|
||||||
</div>
|
|
||||||
<span class="iwb-color-pop-sep"></span>
|
|
||||||
<div class="iwb-color-pop-fields">
|
|
||||||
<button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:切到吸管工具,在画布上点一下取色"><svg width="13" height="13" 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>
|
|
||||||
<input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7" spellcheck="false" autocomplete="off" title="十六进制颜色,回车生效">
|
|
||||||
</div>
|
|
||||||
<span class="iwb-color-pop-sep"></span>
|
|
||||||
<!-- 最近使用(v1.9):由 recent-colors.js 动态填充,空的时候整行隐藏 -->
|
|
||||||
<div class="iwb-editor-recent-colors" hidden title="最近使用"></div>
|
|
||||||
<div class="iwb-editor-color-swatches">
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff4444" style="background:#ff4444" title="#ff4444"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff8a00" style="background:#ff8a00" title="#ff8a00"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffd400" style="background:#ffd400" title="#ffd400"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#4cd964" style="background:#4cd964" title="#4cd964"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#00bfa5" style="background:#00bfa5" title="#00bfa5"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#4488ff" style="background:#4488ff" title="#4488ff"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#aa44ff" style="background:#aa44ff" title="#aa44ff"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff66aa" style="background:#ff66aa" title="#ff66aa"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffffff" style="background:#ffffff" title="#ffffff"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#d0d0d0" style="background:#d0d0d0" title="#d0d0d0"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#808080" style="background:#808080" title="#808080"></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 class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ import { applyQuickEffect, setEffectValue } from './effects.js'
|
|||||||
import { applyAdjust, ensureAdjustTarget, mountAdjustPanel, resetAdjust, setAdjustValue, syncAdjustControls } from './adjust.js'
|
import { applyAdjust, ensureAdjustTarget, mountAdjustPanel, resetAdjust, setAdjustValue, syncAdjustControls } from './adjust.js'
|
||||||
import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||||
|
|
||||||
|
/* 右栏宽度(v1.16):默认 280 —— 220 放 11 项调节时「温度/色调」会被压成两字,
|
||||||
|
而这是用户最常拖的滑杆区。上限还要跟窗口宽度取小,窄窗口不把画布挤没。 */
|
||||||
|
export const SIDE_DEFAULT = 280
|
||||||
|
export const SIDE_MIN = 220
|
||||||
|
export const SIDE_MAX = 520
|
||||||
|
|
||||||
|
|
||||||
// ============ 鼠标事件 ============
|
// ============ 鼠标事件 ============
|
||||||
/**
|
/**
|
||||||
@@ -543,6 +549,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
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,
|
||||||
|
strokeOn: S.shapeStrokeOn !== false,
|
||||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
visible: true
|
visible: true
|
||||||
@@ -748,6 +755,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
fillColor: S.shapeFillColor, // null = 跟随描边色(改主色时整块跟着变)
|
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,
|
||||||
|
strokeOn: S.shapeStrokeOn !== false,
|
||||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
visible: true,
|
visible: true,
|
||||||
@@ -893,6 +901,16 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 「无描边」(v1.17)能不能给:只有「去掉描边后画面还看得见」才给。
|
||||||
|
* 判据就是 fillSlotOn() —— 能填充才谈得上不要描边:
|
||||||
|
* 箭头没有内部、未闭合的钢笔没有面积,去掉描边等于把这个对象删掉,
|
||||||
|
* 这两种情况宁可不给按钮,也别让用户点出一个「看不见的对象」。
|
||||||
|
* 文字不在此列:文字描边是第二格「描边」,早就有「无」了。 */
|
||||||
|
function strokeSlotCanBeNone() {
|
||||||
|
const ctx = colorContext()
|
||||||
|
return ctx.kind === 'shape' && fillSlotOn()
|
||||||
|
}
|
||||||
|
|
||||||
/** 文字的三个颜色槽(v1.12)。
|
/** 文字的三个颜色槽(v1.12)。
|
||||||
* 文字对象本来就有三个颜色字段:color(文字本身)/ strokeColor(字的外描边)/
|
* 文字对象本来就有三个颜色字段:color(文字本身)/ strokeColor(字的外描边)/
|
||||||
* bgColor(文本框底色)。上一版把它们硬塞进「描边 / 填充」两格,第二格其实是
|
* bgColor(文本框底色)。上一版把它们硬塞进「描边 / 填充」两格,第二格其实是
|
||||||
@@ -929,9 +947,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const fillOn = sh
|
const fillOn = sh
|
||||||
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
|
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
|
||||||
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
|
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
|
||||||
|
// v1.17:描边也有「有 / 无」两态。老对象没有 strokeOn 字段 ⇒ 视为有描边。
|
||||||
|
// 只有 shape 上下文才谈得上无描边:箭头/画笔那一格是「唯一颜色」,
|
||||||
|
// 显示成斜杠会让人以为画笔也画不出颜色。
|
||||||
|
const strokeOn = ctx.kind !== 'shape'
|
||||||
|
? true
|
||||||
|
: (sh ? (sh.strokeOn !== false) : (S.shapeStrokeOn !== false))
|
||||||
return {
|
return {
|
||||||
mode: ctx.kind === 'shape' ? 'shape' : 'single',
|
mode: ctx.kind === 'shape' ? 'shape' : 'single',
|
||||||
stroke, fill: rawFill || stroke, fillOn, follow: !rawFill,
|
stroke, strokeOn, fill: rawFill || stroke, fillOn, follow: !rawFill,
|
||||||
bg: null, bgOn: false, bgAlpha: 1,
|
bg: null, bgOn: false, bgAlpha: 1,
|
||||||
strokeName: '描边', fillName: '填充', bgName: '底色'
|
strokeName: '描边', fillName: '填充', bgName: '底色'
|
||||||
}
|
}
|
||||||
@@ -966,11 +990,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const dot = strokeBtn.querySelector('i')
|
const dot = strokeBtn.querySelector('i')
|
||||||
if (dot) dot.style.backgroundColor = sl.stroke
|
if (dot) dot.style.backgroundColor = sl.stroke
|
||||||
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
||||||
|
// v1.17:无描边时色块画红斜杠,和「无填充」同一套视觉语言
|
||||||
|
strokeBtn.classList.toggle('is-none', !isText && sl.strokeOn === false)
|
||||||
strokeBtn.title = isText
|
strokeBtn.title = isText
|
||||||
? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)`
|
? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)`
|
||||||
: (second
|
: (sl.strokeOn === false
|
||||||
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色`
|
? '描边:无(只有填充)。点开选色会自动恢复描边'
|
||||||
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`)
|
: (second
|
||||||
|
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色,「无」= 去掉描边`
|
||||||
|
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`))
|
||||||
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
|
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
||||||
}
|
}
|
||||||
@@ -1024,20 +1052,25 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
: (isText ? '正在调文字色(文字本身的颜色)' : '正在调描边色'))
|
: (isText ? '正在调文字色(文字本身的颜色)' : '正在调描边色'))
|
||||||
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !second }
|
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !second }
|
||||||
if (isBg) { tab.classList.toggle('is-none', !sl.bgOn); tab.hidden = !isText }
|
if (isBg) { tab.classList.toggle('is-none', !sl.bgOn); tab.hidden = !isText }
|
||||||
|
// 描边格:文字的「描边」是第二格(上面已处理),文字色/单槽上下文不允许「无」
|
||||||
|
if (!isFill && !isBg) tab.classList.toggle('is-none', !isText && sl.strokeOn === false)
|
||||||
})
|
})
|
||||||
// 「无」:形状 = 无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
// 「无」:形状/钢笔 = 无描边或无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
||||||
// (文字色没有「无」—— 字没有颜色就等于把字删了,不该给这个按钮)
|
// (文字色与箭头单槽没有「无」—— 去掉就等于把对象删了,不该给这个按钮)
|
||||||
const noneBtn = runtime.el.querySelector('[data-color-none]')
|
// v1.16:右栏与弹层各有一个「无」,必须按集合刷,否则只有先出现的那个对
|
||||||
if (noneBtn) {
|
const onBg = S.colorTarget === 'bg' && isText
|
||||||
const onBg = S.colorTarget === 'bg' && isText
|
const onFill = S.colorTarget === 'fill' && second
|
||||||
const onFill = S.colorTarget === 'fill' && second
|
const onStroke = S.colorTarget === 'stroke' && !isText && strokeSlotCanBeNone()
|
||||||
const show = onBg || onFill
|
const showNone = onBg || onFill || onStroke
|
||||||
noneBtn.hidden = !show
|
runtime.el.querySelectorAll('[data-color-none]').forEach(noneBtn => {
|
||||||
noneBtn.classList.toggle('active', show && (onBg ? !sl.bgOn : !sl.fillOn))
|
noneBtn.hidden = !showNone
|
||||||
|
noneBtn.classList.toggle('active', showNone && (onBg ? !sl.bgOn : (onFill ? !sl.fillOn : !sl.strokeOn)))
|
||||||
noneBtn.title = onBg
|
noneBtn.title = onBg
|
||||||
? '无底色:文字后面完全透明'
|
? '无底色:文字后面完全透明'
|
||||||
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边')
|
: (onStroke
|
||||||
}
|
? (sl.strokeOn === false ? '当前已是无描边;点选颜色可恢复描边' : '无描边:去掉形状外框,只留内部填充')
|
||||||
|
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边'))
|
||||||
|
})
|
||||||
|
|
||||||
const cur = activeColor()
|
const cur = activeColor()
|
||||||
let matchPreset = false
|
let matchPreset = false
|
||||||
@@ -1046,28 +1079,34 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
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')
|
// v1.16:hex / 调色器在两处面板各有一份 → 一律按集合刷
|
||||||
const hexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
runtime.el.querySelectorAll('.iwb-editor-color-hex').forEach(el => { el.textContent = cur.toUpperCase() })
|
||||||
if (hexInput && document.activeElement !== hexInput) hexInput.value = cur.toUpperCase()
|
runtime.el.querySelectorAll('.iwb-editor-color-hex-input').forEach(inp => {
|
||||||
|
if (document.activeElement !== inp) inp.value = cur.toUpperCase()
|
||||||
|
})
|
||||||
runtime.el.querySelectorAll('.iwb-editor-color-panel-swatch').forEach(sw => sw.classList.toggle('active', (sw.dataset.panelColor || '').toLowerCase() === cur.toLowerCase()))
|
runtime.el.querySelectorAll('.iwb-editor-color-panel-swatch').forEach(sw => sw.classList.toggle('active', (sw.dataset.panelColor || '').toLowerCase() === cur.toLowerCase()))
|
||||||
if (panelHex) panelHex.textContent = cur.toUpperCase()
|
|
||||||
const rgb = hexToRgb(cur)
|
const rgb = hexToRgb(cur)
|
||||||
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
|
||||||
if (d) { if (max === rgb.r / 255) h = 60 * (((rgb.g - rgb.b) / 255 / d) % 6); else if (max === rgb.g / 255) h = 60 * ((rgb.b - rgb.r) / 255 / d + 2); else h = 60 * ((rgb.r - rgb.g) / 255 / d + 4) }
|
if (d) { if (max === rgb.r / 255) h = 60 * (((rgb.g - rgb.b) / 255 / d) % 6); else if (max === rgb.g / 255) h = 60 * ((rgb.b - rgb.r) / 255 / d + 2); else h = 60 * ((rgb.r - rgb.g) / 255 / d + 4) }
|
||||||
if (h < 0) h += 360
|
if (h < 0) h += 360
|
||||||
const sv = runtime.el.querySelector('.iwb-color-sv'), hue = runtime.el.querySelector('.iwb-color-hue')
|
const sat = max ? d / max : 0
|
||||||
if (sv) sv.style.backgroundColor = `hsl(${h} 100% 50%)`
|
runtime.el.querySelectorAll('.iwb-color-sv').forEach(sv => {
|
||||||
if (hue) hue.dataset.hue = h
|
sv.style.backgroundColor = `hsl(${h} 100% 50%)`
|
||||||
const hueMarker = hue && hue.querySelector('span'); if (hueMarker) hueMarker.style.top = (h / 360 * 100) + '%'
|
const m = sv.querySelector('span')
|
||||||
const svMarker = sv && sv.querySelector('span'); if (svMarker) { const sat = max ? d / max : 0; svMarker.style.left = (sat * 100) + '%'; svMarker.style.top = ((1 - max) * 100) + '%' }
|
if (m) { m.style.left = (sat * 100) + '%'; m.style.top = ((1 - max) * 100) + '%' }
|
||||||
const custom = runtime.el.querySelector('.iwb-editor-color-custom')
|
})
|
||||||
if (custom) {
|
runtime.el.querySelectorAll('.iwb-color-hue').forEach(hue => {
|
||||||
|
hue.dataset.hue = h
|
||||||
|
const m = hue.querySelector('span')
|
||||||
|
if (m) m.style.top = (h / 360 * 100) + '%'
|
||||||
|
})
|
||||||
|
runtime.el.querySelectorAll('.iwb-editor-color-custom').forEach(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 = cur
|
if (inp) inp.value = cur
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 画笔大小/硬度/透明曾经在侧栏也有一份,2026-11-04 起只保留工具选项栏一处,
|
/** 画笔大小/硬度/透明曾经在侧栏也有一份,2026-11-04 起只保留工具选项栏一处,
|
||||||
@@ -1150,7 +1189,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
|
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
|
||||||
const sl = colorSlots()
|
const sl = colorSlots()
|
||||||
let html = '<span class="iwb-opt-label">描边</span>'
|
let html = '<span class="iwb-opt-label">描边</span>'
|
||||||
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`
|
+ `<input type="color" class="iwb-opt-color${sl.strokeOn === false ? ' is-off' : ''}" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样${sl.strokeOn === false ? ';当前无描边,选色会自动恢复' : ''}">`
|
||||||
if (owner) {
|
if (owner) {
|
||||||
html += '<span class="iwb-opt-label">填充</span>'
|
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 ? '' : ';当前无填充,选色会自动切成实心'}">`
|
+ `<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 ? '' : ';当前无填充,选色会自动切成实心'}">`
|
||||||
@@ -1429,7 +1468,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
? '填充色:与工具栏右下的填充色块是同一份'
|
? '填充色:与工具栏右下的填充色块是同一份'
|
||||||
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
|
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
|
||||||
} else {
|
} else {
|
||||||
inp.title = '描边色:与工具栏左上的描边色块是同一份'
|
// v1.17:无描边时描边色块也要置灰(和「无填充」同一套提示)
|
||||||
|
const off = sl.strokeOn === false
|
||||||
|
inp.classList.toggle('is-off', off)
|
||||||
|
inp.title = off
|
||||||
|
? '当前无描边(只有填充)。选色会自动恢复描边,也可点工具栏描边色块选「无」'
|
||||||
|
: '描边色:与工具栏左上的描边色块是同一份'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
|
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
|
||||||
@@ -1568,9 +1612,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派):
|
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派;v1.17 起描边也支持):
|
||||||
* 形状填充 → 内部透明;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
* 形状填充 → 内部透明;形状描边 → 不画外框;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
||||||
* 三种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
* 四种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
||||||
function applyColorNone() {
|
function applyColorNone() {
|
||||||
const sl = colorSlots()
|
const sl = colorSlots()
|
||||||
if (sl.mode === 'text') {
|
if (sl.mode === 'text') {
|
||||||
@@ -1580,9 +1624,33 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (S.colorTarget === 'stroke') { applyStrokeNone(); return }
|
||||||
applyShapeColor('none')
|
applyShapeColor('none')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 无描边(v1.17):只关外框,描边色留着,下次选色直接恢复。
|
||||||
|
* 「只描边」的形状去掉描边会整体消失 —— 顺手切实心,
|
||||||
|
* 让结果是「一个没有框的色块」而不是「对象凭空没了」。 */
|
||||||
|
function applyStrokeNone() {
|
||||||
|
if (!strokeSlotCanBeNone()) return
|
||||||
|
S.colorTarget = 'stroke'
|
||||||
|
S.shapeStrokeOn = false
|
||||||
|
const sh = getSelectedShape()
|
||||||
|
if (sh && !sh.locked && sh.strokeOn !== false) {
|
||||||
|
saveSnapshot('无描边')
|
||||||
|
sh.strokeOn = false
|
||||||
|
if (!sh.fill && (sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && sh.closed))) {
|
||||||
|
sh.fill = true
|
||||||
|
if (sh.type === 'pen') S.penFill = true
|
||||||
|
else S.rectFill = true
|
||||||
|
}
|
||||||
|
renderObjects()
|
||||||
|
}
|
||||||
|
updateFillUI()
|
||||||
|
updateColorUI()
|
||||||
|
syncOptionBar()
|
||||||
|
}
|
||||||
|
|
||||||
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
|
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
|
||||||
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
||||||
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
||||||
@@ -1600,6 +1668,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (sh && !sh.locked && sh.fill) {
|
if (sh && !sh.locked && sh.fill) {
|
||||||
if (!skipHistory) saveSnapshot('无填充')
|
if (!skipHistory) saveSnapshot('无填充')
|
||||||
sh.fill = false
|
sh.fill = false
|
||||||
|
// 与「无描边」对称:描边也是无的话对象就彻底看不见了,恢复描边兜底
|
||||||
|
if (sh.strokeOn === false) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||||
renderObjects()
|
renderObjects()
|
||||||
}
|
}
|
||||||
updateColorUI()
|
updateColorUI()
|
||||||
@@ -1610,6 +1680,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
||||||
if (kind === 'stroke') {
|
if (kind === 'stroke') {
|
||||||
S.colorTarget = 'stroke'
|
S.colorTarget = 'stroke'
|
||||||
|
// 新建默认值也恢复描边:否则「无描边」状态下改一次描边色,
|
||||||
|
// 下一个新形状仍然是没框的,用户会以为设置没生效
|
||||||
|
S.shapeStrokeOn = true
|
||||||
applyColorChange(hex, opts)
|
applyColorChange(hex, opts)
|
||||||
if (skipHistory) syncOptionBarSoon()
|
if (skipHistory) syncOptionBarSoon()
|
||||||
else syncOptionBar()
|
else syncOptionBar()
|
||||||
@@ -1690,30 +1763,52 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
saveSnapshot('填充')
|
saveSnapshot('填充')
|
||||||
// 未闭合的钢笔路径没有可填区域:保持描边,不动视觉结果
|
// 未闭合的钢笔路径没有可填区域:保持描边,不动视觉结果
|
||||||
sh.fill = isPen ? (!!S.penFill && !!sh.closed) : !!S.rectFill
|
sh.fill = isPen ? (!!S.penFill && !!sh.closed) : !!S.rectFill
|
||||||
|
// 用户明确点了「描边」= 要看见框:无描边的对象顺手恢复,否则点完毫无变化
|
||||||
|
if (!sh.fill && sh.strokeOn === false) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||||
renderObjects()
|
renderObjects()
|
||||||
// 对象的 fill 更新在 sync 之后,选择工具下按钮的激活态要再刷一次
|
// 对象的 fill 更新在 sync 之后,选择工具下按钮的激活态要再刷一次
|
||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** PS 的 X 语义(v1.13.1):把选中形状的「填充色」与「描边色」对调。
|
/** PS 的 X 语义:把选中形状的「描边」与「填充」对调。
|
||||||
* 以前 Shift+X 绑的是「实心 ↔ 只描边」开关 —— 按下去填充被关掉、描边纹丝不动,
|
* v1.13.1:以前 Shift+X 绑的是「实心 ↔ 只描边」开关,按下去填充被关掉、
|
||||||
* 用户的主观体验就是「填充色丢了」,再按一次才回来。用户要的是**交换两个颜色**:
|
* 描边纹丝不动,用户的主观体验就是「填充色丢了」。改为**交换两个颜色**。
|
||||||
* 填充色换到描边的位置、描边色换到填充的位置,填充的开关状态不变(交换的是颜色,不是有无)。
|
* v1.17:交换的是整份状态(颜色 + 有/无),不只是颜色 ——
|
||||||
* 填充色仍「跟随描边色」(fillColor=null)时只有一个颜色,没有可交换的对象,只提示不动数据。 */
|
* 「无填充 + 有色描边」按一下 → 「有色填充 + 无描边」,反之亦然。
|
||||||
|
* 这样「有一边是无色」时也能用(用户反馈的第二个问题);
|
||||||
|
* 两边都有色且填充还在跟随描边时只有一个颜色,才提示不动。
|
||||||
|
* 「未闭合钢笔 / 箭头」没有可填内部:交换后整条路径会消失,直接提示不执行。 */
|
||||||
function swapShapeColors() {
|
function swapShapeColors() {
|
||||||
const sh = getSelectedShape()
|
const sh = getSelectedShape()
|
||||||
if (!sh || sh.locked) return false
|
if (!sh || sh.locked) return false
|
||||||
if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true }
|
if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true }
|
||||||
const stroke = sh.color || S.color
|
const canFill = sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
||||||
const fill = sh.fillColor || null
|
const strokeOn = sh.strokeOn !== false
|
||||||
if (!fill) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
const fillOn = !!sh.fill
|
||||||
|
const strokeColor = sh.color || S.color
|
||||||
|
const fillColor = sh.fillColor || null // null = 跟随描边色
|
||||||
|
if (!canFill && !fillOn) { toast('这条路径没有可填内部,交换后什么都看不见', 'info'); return true }
|
||||||
|
if (!strokeOn && !fillOn) { toast('描边与填充都是无色,没有可交换的颜色', 'info'); return true }
|
||||||
|
if (strokeOn && fillOn && !fillColor) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
||||||
|
|
||||||
saveSnapshot('交换填充与描边色')
|
saveSnapshot('交换填充与描边色')
|
||||||
sh.color = fill
|
// 1) 交换「有 / 无」:哪边有色,交换后就跑到另一边去
|
||||||
S.color = fill // 描边色与主色永远同一份(v1.10 的约定)
|
sh.strokeOn = fillOn
|
||||||
sh.fillColor = stroke
|
sh.fill = strokeOn && canFill
|
||||||
S.shapeFillColor = stroke // 交换后就是独立填充色了,不再跟随描边
|
S.shapeStrokeOn = fillOn
|
||||||
|
if (sh.type === 'pen') S.penFill = !!(sh.fill && sh.closed)
|
||||||
|
else if (sh.type === 'rect' || sh.type === 'circle') S.rectFill = !!sh.fill
|
||||||
|
// 2) 交换颜色。填充原来「跟随描边色」(fillColor=null)就继续跟随 ——
|
||||||
|
// 跟随值恰好就是原描边色,换过去还是同一个颜色,不必把它拆成独立色。
|
||||||
|
if (fillColor) {
|
||||||
|
sh.color = fillColor
|
||||||
|
S.color = fillColor
|
||||||
|
sh.fillColor = strokeColor
|
||||||
|
S.shapeFillColor = strokeColor
|
||||||
|
}
|
||||||
renderObjects()
|
renderObjects()
|
||||||
|
updateFillUI()
|
||||||
updateColorUI()
|
updateColorUI()
|
||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
return true
|
return true
|
||||||
@@ -2060,9 +2155,81 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
bindExportActions()
|
bindExportActions()
|
||||||
bindWheelZoom()
|
bindWheelZoom()
|
||||||
bindTextInput()
|
bindTextInput()
|
||||||
|
bindSideResize()
|
||||||
bindGlobalListeners()
|
bindGlobalListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ============ 右栏宽度(v1.16) ============ */
|
||||||
|
|
||||||
|
/** 应用宽度:夹在 [SIDE_MIN, min(SIDE_MAX, 窗口 45%)],写 CSS 变量 */
|
||||||
|
export function applySideWidth(w) {
|
||||||
|
if (!runtime.el) return S.sideWidth || SIDE_DEFAULT
|
||||||
|
const cap = Math.min(SIDE_MAX, Math.max(SIDE_MIN, Math.floor((window.innerWidth || 1440) * 0.45)))
|
||||||
|
const v = Math.round(Math.min(cap, Math.max(SIDE_MIN, Number(w) || SIDE_DEFAULT)))
|
||||||
|
runtime.el.style.setProperty('--iwb-side-w', v + 'px')
|
||||||
|
S.sideWidth = v
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 打开编辑器时恢复上次宽度(没存过就用默认值) */
|
||||||
|
export function loadSideWidth() {
|
||||||
|
const st = S.callbacks && S.callbacks.settings
|
||||||
|
let w = 0
|
||||||
|
if (st && typeof st.get === 'function') { try { w = Number(st.get('sideWidth')) || 0 } catch (e) { /* ignore */ } }
|
||||||
|
return applySideWidth(w > 0 ? w : SIDE_DEFAULT)
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveSideWidth() {
|
||||||
|
const st = S.callbacks && S.callbacks.settings
|
||||||
|
if (st && typeof st.set === 'function') { try { st.set('sideWidth', S.sideWidth) } catch (e) { /* ignore */ } }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拖拽右栏宽度。
|
||||||
|
* 侧栏在画布右侧,所以指针左移 = 变宽(startW - dx),别写反。
|
||||||
|
* 用 pointer capture:指针拖出 7px 宽的手柄后事件仍然回到手柄上,
|
||||||
|
* 否则鼠标一快就跟丢、宽度卡住。
|
||||||
|
*/
|
||||||
|
function bindSideResize() {
|
||||||
|
const handle = runtime.el && runtime.el.querySelector('[data-side-resizer]')
|
||||||
|
if (!handle) return
|
||||||
|
let dragging = false
|
||||||
|
let startX = 0
|
||||||
|
let startW = 0
|
||||||
|
const endDrag = () => {
|
||||||
|
if (!dragging) return
|
||||||
|
dragging = false
|
||||||
|
handle.classList.remove('is-dragging')
|
||||||
|
document.body.style.cursor = ''
|
||||||
|
document.body.style.userSelect = ''
|
||||||
|
saveSideWidth()
|
||||||
|
}
|
||||||
|
handle.addEventListener('pointerdown', (e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
dragging = true
|
||||||
|
startX = e.clientX
|
||||||
|
startW = S.sideWidth || SIDE_DEFAULT
|
||||||
|
handle.classList.add('is-dragging')
|
||||||
|
document.body.style.cursor = 'col-resize'
|
||||||
|
document.body.style.userSelect = 'none'
|
||||||
|
try { handle.setPointerCapture(e.pointerId) } catch (err) { /* 老浏览器退回普通事件 */ }
|
||||||
|
})
|
||||||
|
handle.addEventListener('pointermove', (e) => {
|
||||||
|
if (!dragging) return
|
||||||
|
applySideWidth(startW - (e.clientX - startX))
|
||||||
|
})
|
||||||
|
handle.addEventListener('pointerup', endDrag)
|
||||||
|
handle.addEventListener('pointercancel', endDrag)
|
||||||
|
handle.addEventListener('lostpointercapture', endDrag)
|
||||||
|
// 双击复位:拖窄了想回去,不用精确拖回 280
|
||||||
|
handle.addEventListener('dblclick', (e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
applySideWidth(SIDE_DEFAULT)
|
||||||
|
saveSideWidth()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** 工具条按钮:点击切换当前工具(选区命令按钮也借用 .iwb-editor-tool 样式,靠 data-tool 过滤掉) */
|
/** 工具条按钮:点击切换当前工具(选区命令按钮也借用 .iwb-editor-tool 样式,靠 data-tool 过滤掉) */
|
||||||
function bindToolButtons() {
|
function bindToolButtons() {
|
||||||
// 工具
|
// 工具
|
||||||
@@ -2073,6 +2240,37 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** v1.18 钉住(用户 2026-11-10):色板弹层常开,点画布 / 点别处都不收起。
|
||||||
|
* 状态存宿主 KV —— 钉住是一种「这段时间我要连着调色」的使用习惯,
|
||||||
|
* 不该每次开编辑器都重新钉一遍。 */
|
||||||
|
export function loadColorPopPinned() {
|
||||||
|
const st = S.callbacks && S.callbacks.settings
|
||||||
|
let on = false
|
||||||
|
if (st && typeof st.get === 'function') { try { on = !!st.get('colorPopPinned') } catch (e) { /* 宿主 KV 不可用就当没钉 */ } }
|
||||||
|
S.colorPopPinned = on
|
||||||
|
syncPinUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
function setColorPopPinned(on) {
|
||||||
|
S.colorPopPinned = !!on
|
||||||
|
const st = S.callbacks && S.callbacks.settings
|
||||||
|
if (st && typeof st.set === 'function') {
|
||||||
|
try { st.set('colorPopPinned', S.colorPopPinned) } catch (e) { /* 存不下就只管本次会话 */ }
|
||||||
|
}
|
||||||
|
syncPinUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncPinUI() {
|
||||||
|
if (!runtime.el) return
|
||||||
|
runtime.el.querySelectorAll('[data-action="pinColorPop"]').forEach(btn => {
|
||||||
|
btn.classList.toggle('active', !!S.colorPopPinned)
|
||||||
|
btn.setAttribute('aria-pressed', String(!!S.colorPopPinned))
|
||||||
|
btn.title = S.colorPopPinned
|
||||||
|
? '已钉住:点画布不会收起色板(再点一次取消钉住)'
|
||||||
|
: '钉住色板:一直开着,点画布也不收起(再点一次取消)'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** 关闭色板弹层;返回「关之前是开着的」,供 Esc 决定要不要吞掉这次按键 */
|
/** 关闭色板弹层;返回「关之前是开着的」,供 Esc 决定要不要吞掉这次按键 */
|
||||||
export function closeColorPop() {
|
export function closeColorPop() {
|
||||||
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
@@ -2122,8 +2320,10 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 色板弹层(v1.3;v1.11 起同时服务描边与填充两个槽):
|
/** 调色面板(v1.3 弹层 → v1.16 弹层 + 右栏常驻):
|
||||||
* 工具栏两个色块开关;tab / hex / 吸管 / 推荐色 / 调色器 / 无填充都在这一个弹层里 */
|
* 两处是同一份 DOM(dom.js#colorSurfaceHtml),按 [data-color-surface] 逐个绑定。
|
||||||
|
* 每个 surface 各自持有一份 HSV 拖拽状态,但取值一律从 activeColor() 现算,
|
||||||
|
* 所以「在右栏取色、再去弹层拖 SV」不会跳色。 */
|
||||||
function bindColorPanel() {
|
function bindColorPanel() {
|
||||||
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')]
|
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')]
|
||||||
@@ -2132,37 +2332,54 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
btn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop(btn.dataset.colorSlot) })
|
btn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop(btn.dataset.colorSlot) })
|
||||||
})
|
})
|
||||||
if (pop) {
|
if (pop) {
|
||||||
pop.addEventListener('mousedown', (e) => e.stopPropagation())
|
|
||||||
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
|
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
|
||||||
// 冒泡阶段拿不到「点了外面」这件事。
|
// 冒泡阶段拿不到「点了外面」这件事。右栏面板常驻,不参与关闭。
|
||||||
|
// 钉住时一律不关:这就是「钉住」的全部意义(要收就再点一次图钉,或按 Esc)。
|
||||||
document.addEventListener('mousedown', (e) => {
|
document.addEventListener('mousedown', (e) => {
|
||||||
|
if (S.colorPopPinned) return
|
||||||
const onBtn = colorBtns.some(b => b.contains(e.target))
|
const onBtn = colorBtns.some(b => b.contains(e.target))
|
||||||
if (!pop.hidden && !pop.contains(e.target) && !onBtn) closeColorPop()
|
if (!pop.hidden && !pop.contains(e.target) && !onBtn) closeColorPop()
|
||||||
}, true)
|
}, true)
|
||||||
window.addEventListener('resize', positionColorPop)
|
window.addEventListener('resize', positionColorPop)
|
||||||
}
|
}
|
||||||
|
runtime.el.querySelectorAll('[data-color-surface]').forEach(surface => bindColorSurface(surface))
|
||||||
|
}
|
||||||
|
|
||||||
// 弹层头部:切描边/填充,或直接置为「无填充」
|
/** 一块调色面板的全部交互:弹层与右栏各一份,代码只有这一处 */
|
||||||
if (pop) {
|
function bindColorSurface(surface) {
|
||||||
pop.addEventListener('click', (e) => {
|
const isPop = surface.classList.contains('iwb-editor-color-pop')
|
||||||
const tab = e.target.closest('[data-color-slot]')
|
surface.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
if (tab && tab.classList.contains('iwb-color-pop-tab')) {
|
// tab 切换目标槽 / 「无」 / 常用色与最近色,统一委托:
|
||||||
e.stopPropagation()
|
// 静态 12 色 + 动态插入的「最近使用」都要能点,一次性 querySelectorAll 会漏掉后者
|
||||||
setColorTarget(tab.dataset.colorSlot)
|
surface.addEventListener('click', (e) => {
|
||||||
positionColorPop()
|
const pin = e.target.closest('[data-action="pinColorPop"]')
|
||||||
return
|
if (pin) { e.stopPropagation(); setColorPopPinned(!S.colorPopPinned); return }
|
||||||
}
|
const tab = e.target.closest('.iwb-color-pop-tab[data-color-slot]')
|
||||||
const none = e.target.closest('[data-color-none]')
|
if (tab) {
|
||||||
if (none) {
|
e.stopPropagation()
|
||||||
e.stopPropagation()
|
setColorTarget(tab.dataset.colorSlot)
|
||||||
applyColorNone()
|
if (isPop) positionColorPop() // 换 tab 后弹层宽度会变,重新贴一次
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const none = e.target.closest('[data-color-none]')
|
||||||
|
if (none) { e.stopPropagation(); applyColorNone(); return }
|
||||||
|
const sw = e.target.closest('[data-panel-color]')
|
||||||
|
if (sw) { e.stopPropagation(); applyPanelColor(sw.dataset.panelColor) }
|
||||||
|
})
|
||||||
|
|
||||||
|
const hexInput = surface.querySelector('.iwb-editor-color-hex-input')
|
||||||
|
if (hexInput) {
|
||||||
|
hexInput.addEventListener('change', () => {
|
||||||
|
if (/^#[0-9a-f]{6}$/i.test(hexInput.value)) applyPanelColor(hexInput.value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const palettePick = surface.querySelector('[data-action="palettePick"]')
|
||||||
|
if (palettePick) {
|
||||||
|
palettePick.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
|
// 取色要回画布点,弹层必须先收起,否则它会挡住取样点(右栏面板在画布外,不挡)
|
||||||
|
palettePick.addEventListener('click', () => { closeColorPop(); setTool('picker') })
|
||||||
|
}
|
||||||
|
|
||||||
// 独立颜色面板:按当前目标槽写色(描边 → 主色,填充 → 形状 fillColor)
|
|
||||||
const setPanelColor = (color) => applyPanelColor(color)
|
|
||||||
// 拖动取色期间只拍一次快照:applyColorChange 每改一次颜色都会 saveSnapshot,
|
// 拖动取色期间只拍一次快照:applyColorChange 每改一次颜色都会 saveSnapshot,
|
||||||
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
|
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
|
||||||
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
|
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
|
||||||
@@ -2177,26 +2394,10 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
}
|
}
|
||||||
applyPanelColor(color, { skipHistory: true })
|
applyPanelColor(color, { skipHistory: true })
|
||||||
}
|
}
|
||||||
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) })
|
const sv = surface.querySelector('.iwb-color-sv')
|
||||||
// 色块统一走委托:静态 12 色 + 动态插入的「最近使用」都要能点,
|
const hue = surface.querySelector('.iwb-color-hue')
|
||||||
// 一次性 querySelectorAll 绑定会漏掉后来插进来的按钮
|
if (!sv || !hue) return
|
||||||
if (pop) {
|
|
||||||
pop.addEventListener('click', (e) => {
|
|
||||||
const btn = e.target.closest('[data-panel-color]')
|
|
||||||
if (!btn) return
|
|
||||||
e.stopPropagation()
|
|
||||||
setPanelColor(btn.dataset.panelColor)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const palettePick = runtime.el.querySelector('[data-action="palettePick"]')
|
|
||||||
if (palettePick) {
|
|
||||||
palettePick.addEventListener('mousedown', (e) => e.stopPropagation())
|
|
||||||
// 取色要回画布点,弹层必须先收起,否则它会挡住取样点
|
|
||||||
palettePick.addEventListener('click', () => { closeColorPop(); setTool('picker') })
|
|
||||||
}
|
|
||||||
const sv = runtime.el.querySelector('.iwb-color-sv')
|
|
||||||
const hue = runtime.el.querySelector('.iwb-color-hue')
|
|
||||||
const initHsv = (() => {
|
const initHsv = (() => {
|
||||||
const { r, g, b } = hexToRgb(activeColor())
|
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
|
||||||
@@ -2426,7 +2627,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, fillColor: S.shapeFillColor, 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, strokeOn: S.shapeStrokeOn !== false, 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)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import { createEl, loadImage } from './dom.js'
|
|||||||
import { renderObjects, hideTextInput, textBounds } from './objects.js'
|
import { renderObjects, hideTextInput, textBounds } from './objects.js'
|
||||||
import { setupCanvas } from './viewport.js'
|
import { setupCanvas } from './viewport.js'
|
||||||
import { resetOverlayTransform } from './scale.js'
|
import { resetOverlayTransform } from './scale.js'
|
||||||
import { updateAllUI, bindLiteUI, renderOptionBar, updateStatusbar } from './events.js'
|
import { updateAllUI, bindLiteUI, renderOptionBar, updateStatusbar, loadSideWidth, loadColorPopPinned } from './events.js'
|
||||||
import { disposeSelection, renderSelection, selectionInfo, syncAnts, registerSelectionCommands } from './selection.js'
|
import { disposeSelection, renderSelection, selectionInfo, syncAnts, registerSelectionCommands } from './selection.js'
|
||||||
import { bindFloating, positionFloating, hideSelectionContext } from './floating.js'
|
import { bindFloating, positionFloating, hideSelectionContext } from './floating.js'
|
||||||
import { renderFxPanel } from './effects.js'
|
import { renderFxPanel } from './effects.js'
|
||||||
@@ -69,10 +69,15 @@ import { toast } from './commands.js'
|
|||||||
registerSelectionCommands()
|
registerSelectionCommands()
|
||||||
loadExportOptions()
|
loadExportOptions()
|
||||||
loadRecentColors()
|
loadRecentColors()
|
||||||
|
// v1.18:色板「钉住」状态也来自宿主 KV,和常用色/最近色一起恢复
|
||||||
|
loadColorPopPinned()
|
||||||
bindLiteUI()
|
bindLiteUI()
|
||||||
bindFloating()
|
bindFloating()
|
||||||
bindExportUI()
|
bindExportUI()
|
||||||
initPanels()
|
initPanels()
|
||||||
|
// 右栏宽度跟着用户上次拖的位置(v1.16);必须在 initPanels 之后——
|
||||||
|
// 侧栏收起时元素虽 display:none,写 CSS 变量仍然有效,下次展开直接生效
|
||||||
|
loadSideWidth()
|
||||||
renderAll()
|
renderAll()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[IWB编辑器] 打开失败:', e)
|
console.error('[IWB编辑器] 打开失败:', e)
|
||||||
@@ -335,7 +340,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, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
|
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, strokeOn: s.strokeOn !== false, 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, fontFamily: t.fontFamily, align: t.align, lineHeight: t.lineHeight,
|
fontWeight: t.fontWeight, fontFamily: t.fontFamily, align: t.align, lineHeight: t.lineHeight,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* recent-colors.js - 最近使用颜色(v1.9)
|
/* recent-colors.js - 最近使用颜色(v1.9)
|
||||||
*
|
*
|
||||||
* 只依赖 state.js(叶子模块):tools.js 在改色时调用 rememberColor(),
|
* 只依赖 state.js(叶子模块):tools.js 在改色时调用 rememberColor(),
|
||||||
* color pop 打开时 renderRecentColors() 把最近 8 个色块铺出来。
|
* color pop 打开时 renderRecentColors() 把最近 6 个色块铺出来。
|
||||||
* 持久化走宿主 ctx.settings(小 KV,不放像素,符合宿主存储约定)。
|
* 持久化走宿主 ctx.settings(小 KV,不放像素,符合宿主存储约定)。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
import { S, runtime } from './state.js'
|
import { S, runtime } from './state.js'
|
||||||
|
|
||||||
const MAX = 8
|
// v1.18:上限从 8 收到 6 —— 色板弹层右列改成 6 列网格(和「常用色」同一套),
|
||||||
|
// 6 个正好一行;8 个会折成第二行,把整块面板撑高 23px,和「更紧凑」的目标相反。
|
||||||
|
const MAX = 6
|
||||||
const KEY = 'recentColors'
|
const KEY = 'recentColors'
|
||||||
|
|
||||||
function valid(hex) {
|
function valid(hex) {
|
||||||
@@ -29,7 +31,7 @@ import { S, runtime } from './state.js'
|
|||||||
renderRecentColors()
|
renderRecentColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 记一个颜色:去重后置顶,最多 8 个 */
|
/** 记一个颜色:去重后置顶,最多 MAX 个 */
|
||||||
export function rememberColor(hex) {
|
export function rememberColor(hex) {
|
||||||
if (!valid(hex)) return
|
if (!valid(hex)) return
|
||||||
const c = String(hex).toLowerCase()
|
const c = String(hex).toLowerCase()
|
||||||
@@ -43,12 +45,21 @@ import { S, runtime } from './state.js'
|
|||||||
renderRecentColors()
|
renderRecentColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderRecentColors() {
|
export function renderRecentColors() {
|
||||||
const wrap = runtime.el && runtime.el.querySelector('.iwb-editor-recent-colors')
|
if (!runtime.el) return
|
||||||
if (!wrap) return
|
// v1.16:右栏常驻面板与工具栏弹层各有一份,按集合刷
|
||||||
const list = S.recentColors || []
|
const wraps = runtime.el.querySelectorAll('.iwb-editor-recent-colors')
|
||||||
wrap.innerHTML = list.map(c =>
|
if (!wraps.length) return
|
||||||
`<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="最近使用 ${c}"></button>`
|
const list = S.recentColors || []
|
||||||
).join('')
|
const html = list.map(c =>
|
||||||
|
`<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="最近使用 ${c}"></button>`
|
||||||
|
).join('')
|
||||||
|
wraps.forEach(wrap => {
|
||||||
|
wrap.innerHTML = html
|
||||||
wrap.hidden = !list.length
|
wrap.hidden = !list.length
|
||||||
}
|
// v1.16:右栏给了一组加了「最近」小标题,没有最近色时整组一起藏,
|
||||||
|
// 否则标题下面留一块空白,看起来像没加载出来。
|
||||||
|
const group = wrap.closest('.iwb-color-group')
|
||||||
|
if (group) group.hidden = !list.length
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -45,6 +45,9 @@
|
|||||||
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
||||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||||
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
||||||
|
// v1.17:默认是否画描边。关掉后形状只剩填充(「无描边」),
|
||||||
|
// 对象上另存 strokeOn,老对象没有这个字段一律视为有描边。
|
||||||
|
shapeStrokeOn: true,
|
||||||
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||||
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||||
@@ -53,6 +56,12 @@
|
|||||||
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
|
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
|
||||||
// 否则「三个地方各调各的颜色」会一直存在。
|
// 否则「三个地方各调各的颜色」会一直存在。
|
||||||
colorTarget: 'stroke', // stroke | fill
|
colorTarget: 'stroke', // stroke | fill
|
||||||
|
// v1.18:色板弹层是否「钉住」。钉住后点画布/点别处都不收起,方便连着调几处颜色。
|
||||||
|
// 存宿主 KV(跨会话记住):钉过一次就一直钉着,下次打开仍生效。
|
||||||
|
colorPopPinned: false,
|
||||||
|
// v1.16:右侧栏宽度(px)。0 = 按默认值走,打开编辑器时从宿主 KV 恢复。
|
||||||
|
// 宽度统一落在 CSS 变量 --iwb-side-w 上,不再各条规则各写一个魔数。
|
||||||
|
sideWidth: 0,
|
||||||
textSize: 32, // 新建文字的字号 px
|
textSize: 32, // 新建文字的字号 px
|
||||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
textWeight: 'bold', // bold | normal | 900
|
textWeight: 'bold', // bold | normal | 900
|
||||||
@@ -64,7 +73,7 @@
|
|||||||
textBgFill: TEXT_DEFAULTS.bgFill, // 底色块
|
textBgFill: TEXT_DEFAULTS.bgFill, // 底色块
|
||||||
textBgColor: TEXT_DEFAULTS.bgColor, // 中性近黑,不再是纯黑 #000000
|
textBgColor: TEXT_DEFAULTS.bgColor, // 中性近黑,不再是纯黑 #000000
|
||||||
textBgAlpha: TEXT_DEFAULTS.bgAlpha, // 底色透明度(色块按这个不透明度显示,所见即所得)
|
textBgAlpha: TEXT_DEFAULTS.bgAlpha, // 底色透明度(色块按这个不透明度显示,所见即所得)
|
||||||
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
// 最近使用颜色(最多 6 个,存 ctx.settings,跨会话保留)
|
||||||
recentColors: [],
|
recentColors: [],
|
||||||
// 图层系统
|
// 图层系统
|
||||||
layers: [], // 位图图层数组 [{ id, name, canvas, ctx, opacity, visible, z }]
|
layers: [], // 位图图层数组 [{ id, name, canvas, ctx, opacity, visible, z }]
|
||||||
|
|||||||
@@ -201,9 +201,18 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
ctx.lineWidth = s.lw
|
ctx.lineWidth = s.lw
|
||||||
ctx.lineCap = 'round'
|
ctx.lineCap = 'round'
|
||||||
ctx.lineJoin = 'round'
|
ctx.lineJoin = 'round'
|
||||||
|
// v1.17:无描边(strokeOn === false)。老对象没有这个字段,一律当有描边。
|
||||||
|
// 注意不能靠 lineWidth = 0 实现:canvas 会忽略 0 从而保持上一次的值。
|
||||||
|
const strokeOn = s.strokeOn !== false
|
||||||
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 = fillOf(s); 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() }
|
||||||
|
if (strokeOn) 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)
|
||||||
@@ -211,10 +220,10 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
||||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
if (strokeOn) ctx.stroke()
|
||||||
} else {
|
} else {
|
||||||
if (s.fill) { ctx.fillStyle = fillOf(s); 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)
|
if (strokeOn) ctx.strokeRect(rx, ry, rw, rh)
|
||||||
}
|
}
|
||||||
} else if (s.type === 'circle') {
|
} else if (s.type === 'circle') {
|
||||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2)
|
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2)
|
||||||
@@ -222,8 +231,9 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
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 = fillOf(s); ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
if (strokeOn) ctx.stroke()
|
||||||
} else {
|
} else if (strokeOn) {
|
||||||
|
// 箭头:没有可填内部,去掉描边等于不画(UI 也不提供这个入口)
|
||||||
ctx.fillStyle = strokeOf(s)
|
ctx.fillStyle = strokeOf(s)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(s.x1, s.y1)
|
ctx.moveTo(s.x1, s.y1)
|
||||||
@@ -424,9 +434,13 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
renderObjects()
|
renderObjects()
|
||||||
}
|
}
|
||||||
const sh = getSelectedShape()
|
const sh = getSelectedShape()
|
||||||
if (sh && !sh.locked && S.tool !== 'text' && sh.color !== S.color) {
|
if (sh && !sh.locked && S.tool !== 'text' && (sh.color !== S.color || sh.strokeOn === false)) {
|
||||||
|
// v1.17:给「无描边」的形状选颜色 = 想再看见描边,顺手打开。
|
||||||
|
// 与改色共用同一张快照,撤销一步就能回到「无描边 + 旧色」。
|
||||||
|
const revive = sh.strokeOn === false
|
||||||
if (!skipHistory) saveSnapshot()
|
if (!skipHistory) saveSnapshot()
|
||||||
sh.color = S.color
|
sh.color = S.color
|
||||||
|
if (revive) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||||
renderObjects()
|
renderObjects()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2651
-138
File diff suppressed because it is too large.
Load diff
@@ -217,6 +217,65 @@ if (!SKIP_PASTE) {
|
|||||||
(await page.locator('.iwb-editor-adj-target').textContent()) !== '无图层',
|
(await page.locator('.iwb-editor-adj-target').textContent()) !== '无图层',
|
||||||
await page.locator('.iwb-editor-adj-target').textContent())
|
await page.locator('.iwb-editor-adj-target').textContent())
|
||||||
|
|
||||||
|
// v1.16:右栏常驻调色面板 + 可拖宽度。真站里 DOM 与 CSS 是分别打包的,
|
||||||
|
// 只验面板在不在、拖宽后宽度有没有真的变 —— 样式漏打包时这里会直接露出来。
|
||||||
|
const sideColor = await page.evaluate(() => {
|
||||||
|
const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]')
|
||||||
|
if (!side) return null
|
||||||
|
return {
|
||||||
|
tabs: side.querySelectorAll('.iwb-color-pop-tab').length,
|
||||||
|
swatches: side.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]').length,
|
||||||
|
sv: !!side.querySelector('.iwb-color-sv')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('右栏常驻调色面板(色格切换 + 调色器 + 12 个常用色)',
|
||||||
|
Boolean(sideColor) && sideColor.tabs === 3 && sideColor.swatches === 12 && sideColor.sv,
|
||||||
|
JSON.stringify(sideColor))
|
||||||
|
|
||||||
|
const sideBefore = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||||
|
const sideGrip = await page.locator('.iwb-editor-side-resizer').boundingBox()
|
||||||
|
if (sideGrip) {
|
||||||
|
await page.mouse.move(sideGrip.x + 3, sideGrip.y + 120)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(sideGrip.x + 3 - 70, sideGrip.y + 120, { steps: 6 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
}
|
||||||
|
const sideAfter = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||||
|
check('右栏可以拖宽(不再固定 220)', sideAfter >= sideBefore + 60, sideBefore + ' → ' + sideAfter)
|
||||||
|
await page.locator('.iwb-editor-side-resizer').dblclick()
|
||||||
|
await page.waitForTimeout(150)
|
||||||
|
|
||||||
|
// v1.17:描边可以是「无色」。真站要验的是按钮真的出现在描边槽、点完对象上真的关了,
|
||||||
|
// 而不只是 CSS 里多了个类 —— 形状消失与否只有跑起来才知道。
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
|
await page.mouse.move(imgBox.x + imgBox.width * 0.12, imgBox.y + imgBox.height * 0.12)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(imgBox.x + imgBox.width * 0.30, imgBox.y + imgBox.height * 0.30, { steps: 6 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await page.waitForTimeout(250)
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
|
await page.mouse.click(imgBox.x + imgBox.width * 0.21, imgBox.y + imgBox.height * 0.21)
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(250)
|
||||||
|
const noneOnStroke = await page.evaluate(() => {
|
||||||
|
const n = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
||||||
|
return Boolean(n) && !n.hidden
|
||||||
|
})
|
||||||
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const noStrokeState = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes.find((x) => x.id === d.selectedShapeId)
|
||||||
|
return s ? { strokeOn: s.strokeOn, fill: s.fill } : null
|
||||||
|
})
|
||||||
|
check('真站:描边能置「无」(去掉描边顺手切实心,对象不会消失)',
|
||||||
|
noneOnStroke && Boolean(noStrokeState) && noStrokeState.strokeOn === false && noStrokeState.fill === true,
|
||||||
|
JSON.stringify({ noneOnStroke, noStrokeState }))
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
|
||||||
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
||||||
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
||||||
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||||||
|
|||||||
@@ -193,6 +193,71 @@ check('色板弹层默认收起;点工具栏色点弹出、且整块在视口
|
|||||||
return inView && !(await pop.isVisible()) ? true : 'box=' + JSON.stringify(box)
|
return inView && !(await pop.isVisible()) ? true : 'box=' + JSON.stringify(box)
|
||||||
})())
|
})())
|
||||||
|
|
||||||
|
// ---------- v1.18 色板弹层:钉住 + 右列竖排(用户 2026-11-10) ----------
|
||||||
|
// 需求原话:「加一个钉住,在需要调色的时候不用每次都要点开」「右边的数值、常用色、最近色
|
||||||
|
// 竖向排」「顺序改为设置、常用色、最近,这三项不用标题,用细横线分割」。
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() // 用选择工具点画布,不落像素
|
||||||
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(140)
|
||||||
|
const popLayout = await page.evaluate(() => {
|
||||||
|
const pop = document.querySelector('.iwb-editor-color-pop')
|
||||||
|
const picker = pop.querySelector('.iwb-color-pop-picker')
|
||||||
|
const side = pop.querySelector('.iwb-color-pop-side')
|
||||||
|
const fields = pop.querySelector('.iwb-color-pop-fields')
|
||||||
|
const groups = [...side.querySelectorAll('.iwb-color-group')]
|
||||||
|
const r = (el) => el.getBoundingClientRect()
|
||||||
|
const pr = r(picker)
|
||||||
|
const sr = r(side)
|
||||||
|
const fr = r(fields)
|
||||||
|
const g0 = r(groups[0])
|
||||||
|
// 「最近」组在没有历史色时整块 hidden,rect 全是 0 —— 不能拿它参与几何比较
|
||||||
|
const g1el = groups[1]
|
||||||
|
const g1 = g1el && !g1el.hidden ? r(g1el) : null
|
||||||
|
return {
|
||||||
|
w: Math.round(r(pop).width),
|
||||||
|
h: Math.round(r(pop).height),
|
||||||
|
sideInRight: Math.round(sr.left) >= Math.round(pr.right), // 右列在取色器右边
|
||||||
|
threeStacked: fr.bottom <= g0.top + 1 && (!g1 || g0.bottom <= g1.top + 1), // 设置→常用→最近 自上而下
|
||||||
|
sameColumn: Math.abs(fr.left - g0.left) < 2 && (!g1 || Math.abs(g0.left - g1.left) < 2),
|
||||||
|
dividers: groups.map((g) => getComputedStyle(g).borderTopWidth),
|
||||||
|
labelsVisible: [...pop.querySelectorAll('.iwb-color-group-label')].filter((l) => l.offsetParent !== null).length,
|
||||||
|
swatch: Math.round(r(pop.querySelector('.iwb-editor-color-panel-swatch')).width),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('色板右列竖排:设置 → 常用色 → 最近 同一列,1px 细线分隔且没有小标题',
|
||||||
|
popLayout.sideInRight && popLayout.threeStacked && popLayout.sameColumn &&
|
||||||
|
popLayout.labelsVisible === 0 && popLayout.dividers.every((d) => d === '1px'),
|
||||||
|
JSON.stringify(popLayout))
|
||||||
|
check('竖排后弹层比横排版更紧凑(宽度收窄、总高不超过 175px)',
|
||||||
|
popLayout.w < 460 && popLayout.h <= 175, 'w=' + popLayout.w + ' h=' + popLayout.h)
|
||||||
|
// 开发用:ANNOT_SHOT=/tmp/pop.png 出一张色板弹层截图(验证 v1.18 布局)
|
||||||
|
if (process.env.ANNOT_SHOT) await page.locator('.iwb-editor-color-pop').screenshot({ path: process.env.ANNOT_SHOT })
|
||||||
|
|
||||||
|
const pinBtn = page.locator('.iwb-editor-color-pop [data-action="pinColorPop"]')
|
||||||
|
await pinBtn.click()
|
||||||
|
await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(imgBox.x + imgBox.width * 0.5, imgBox.y + imgBox.height * 0.5)
|
||||||
|
await page.waitForTimeout(140)
|
||||||
|
const pinned = await page.evaluate(() => ({
|
||||||
|
open: !document.querySelector('.iwb-editor-color-pop').hidden,
|
||||||
|
active: document.querySelector('.iwb-editor-color-pop [data-action="pinColorPop"]').classList.contains('active'),
|
||||||
|
saved: window.__settings.colorPopPinned === true,
|
||||||
|
}))
|
||||||
|
check('钉住后点画布不收起,状态写进宿主 settings(下次打开仍钉着)',
|
||||||
|
pinned.open && pinned.active && pinned.saved, JSON.stringify(pinned))
|
||||||
|
|
||||||
|
await pinBtn.click()
|
||||||
|
await page.waitForTimeout(70)
|
||||||
|
await page.mouse.click(imgBox.x + imgBox.width * 0.35, imgBox.y + imgBox.height * 0.4)
|
||||||
|
await page.waitForTimeout(140)
|
||||||
|
const unpinned = await page.evaluate(() => ({
|
||||||
|
open: !document.querySelector('.iwb-editor-color-pop').hidden,
|
||||||
|
saved: window.__settings.colorPopPinned,
|
||||||
|
active: document.querySelector('.iwb-editor-color-pop [data-action="pinColorPop"]').classList.contains('active'),
|
||||||
|
}))
|
||||||
|
check('取消钉住后点画布立即收起(状态回到 false)',
|
||||||
|
!unpinned.open && unpinned.saved === false && !unpinned.active, JSON.stringify(unpinned))
|
||||||
|
|
||||||
const drag = async (x1, y1, x2, y2) => {
|
const drag = async (x1, y1, x2, y2) => {
|
||||||
await page.mouse.move(x1, y1)
|
await page.mouse.move(x1, y1)
|
||||||
await page.mouse.down()
|
await page.mouse.down()
|
||||||
@@ -672,10 +737,9 @@ check('适应窗口后图片底边不被工具条遮挡', await page.evaluate(()
|
|||||||
check('顶栏输出/导出按钮组贴最右侧(用户裁定 2026-11-04)', await page.evaluate(() => {
|
check('顶栏输出/导出按钮组贴最右侧(用户裁定 2026-11-04)', await page.evaluate(() => {
|
||||||
const hdr = document.querySelector('.iwb-editor-header')
|
const hdr = document.querySelector('.iwb-editor-header')
|
||||||
const ex = document.querySelector('.iwb-editor-header > .iwb-editor-export-actions')
|
const ex = document.querySelector('.iwb-editor-header > .iwb-editor-export-actions')
|
||||||
const hist = document.querySelector('.iwb-editor-header > .iwb-editor-history')
|
if (!hdr || !ex) return false
|
||||||
if (!hdr || !ex || !hist) return false
|
|
||||||
const h = hdr.getBoundingClientRect(), e = ex.getBoundingClientRect()
|
const h = hdr.getBoundingClientRect(), e = ex.getBoundingClientRect()
|
||||||
return h.right - e.right <= 14 && e.left > hist.getBoundingClientRect().right
|
return h.right - e.right <= 14
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// 橡皮:1.2.2 回归 —— events.js 少 import getActiveLayer,一按下就 ReferenceError,表现为「橡皮不能擦」
|
// 橡皮:1.2.2 回归 —— events.js 少 import getActiveLayer,一按下就 ReferenceError,表现为「橡皮不能擦」
|
||||||
@@ -743,11 +807,15 @@ check('顶栏不再有图层层级按钮;视图快捷搬到画布工具栏最
|
|||||||
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"]')
|
||||||
const tools = document.querySelector('.iwb-editor-canvas-wrap > .iwb-editor-tools')
|
const tools = document.querySelector('.iwb-editor-canvas-wrap > .iwb-editor-tools')
|
||||||
const kids = tools ? [...tools.children] : []
|
const kids = tools ? [...tools.children] : []
|
||||||
const lastTwo = kids.slice(-2).map(el => el.dataset && el.dataset.action)
|
// v1.18:撤销组搬进来后是 tools 的最后一个子元素,视图快捷退到它前面两位
|
||||||
|
// (中间还夹了一条分隔线 span,没有 data-action,过滤掉)
|
||||||
|
const histEl = kids.find(el => el.classList && el.classList.contains('iwb-editor-history')) || null
|
||||||
|
const lastTwo = kids.filter(el => el !== histEl && el.dataset && el.dataset.action)
|
||||||
|
.slice(-2).map(el => el.dataset.action)
|
||||||
return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') &&
|
return !q('.iwb-editor-more-wrap') && !q('[data-action="toggleMore"]') &&
|
||||||
hdrLayerBtns === 0 && !hdrAdd && addBtns === 4 &&
|
hdrLayerBtns === 0 && !hdrAdd && addBtns === 4 &&
|
||||||
!q('.iwb-editor-header [data-action="zoomFit"]') && !q('.iwb-editor-header [data-action="togglePanels"]') &&
|
!q('.iwb-editor-header [data-action="zoomFit"]') && !q('.iwb-editor-header [data-action="togglePanels"]') &&
|
||||||
lastTwo.join(',') === 'zoomFit,togglePanels' &&
|
lastTwo.join(',') === 'zoomFit,togglePanels' && kids[kids.length - 1] === histEl &&
|
||||||
q('.iwb-editor-layer-panel-header [data-action="addBlankLayer"]') &&
|
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"]') &&
|
||||||
@@ -755,7 +823,7 @@ check('顶栏不再有图层层级按钮;视图快捷搬到画布工具栏最
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
check('「还原原图」图标是循环重置(refresh)而不是垃圾桶', await page.evaluate(() => {
|
check('「还原原图」图标是循环重置(refresh)而不是垃圾桶', await page.evaluate(() => {
|
||||||
const svg = document.querySelector('.iwb-editor-header [data-action="reset"] svg')
|
const svg = document.querySelector('.iwb-editor-tools [data-action="reset"] svg')
|
||||||
if (!svg) return false
|
if (!svg) return false
|
||||||
const paths = svg.querySelectorAll('path').length
|
const paths = svg.querySelectorAll('path').length
|
||||||
const polys = Array.from(svg.querySelectorAll('polyline')).map(p => p.getAttribute('points')).join('|')
|
const polys = Array.from(svg.querySelectorAll('polyline')).map(p => p.getAttribute('points')).join('|')
|
||||||
@@ -1001,7 +1069,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
|
|||||||
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"][data-color-slot="stroke"]').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-editor-color-pop .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()
|
||||||
await page.mouse.move(sv.x + sv.width * 0.9, sv.y + sv.height * 0.85, { steps: 20 })
|
await page.mouse.move(sv.x + sv.width * 0.9, sv.y + sv.height * 0.85, { steps: 20 })
|
||||||
@@ -1018,24 +1086,45 @@ await page.keyboard.press('Control+z') // 撤销上一步新建的矩形,恢
|
|||||||
|
|
||||||
// ---- v1.2.9:会话组(新建/覆盖/退出)移到顶栏最左 + 图层 PS 快捷键 ----
|
// ---- v1.2.9:会话组(新建/覆盖/退出)移到顶栏最左 + 图层 PS 快捷键 ----
|
||||||
|
|
||||||
check('顶栏:标题最前 → 新建/覆盖/退出(统一中性色)→ 竖分隔 → 撤销组,右侧只剩 输出+导出', await page.evaluate(() => {
|
check('顶栏:标题 → 新建/覆盖/退出(统一中性色),撤销组已搬去工具条,右侧只剩 输出+导出', await page.evaluate(() => {
|
||||||
const q = (s) => document.querySelector(s)
|
const q = (s) => document.querySelector(s)
|
||||||
const session = q('.iwb-editor-header > .iwb-editor-session')
|
const session = q('.iwb-editor-header > .iwb-editor-session')
|
||||||
const title = q('.iwb-editor-header > .iwb-editor-title')
|
const title = q('.iwb-editor-header > .iwb-editor-title')
|
||||||
const hist = q('.iwb-editor-header > .iwb-editor-history')
|
|
||||||
const dl = q('.iwb-editor-header [data-action="download"]')
|
const dl = q('.iwb-editor-header [data-action="download"]')
|
||||||
if (!session || !title || !hist || !dl) return false
|
if (!session || !title || !dl) return false
|
||||||
const t = title.getBoundingClientRect(), s = session.getBoundingClientRect(), h = hist.getBoundingClientRect()
|
const t = title.getBoundingClientRect(), s = session.getBoundingClientRect()
|
||||||
const btns = Array.from(session.querySelectorAll('.iwb-editor-btn')).map(b => b.dataset.action).join(',')
|
const btns = Array.from(session.querySelectorAll('.iwb-editor-btn')).map(b => b.dataset.action).join(',')
|
||||||
const bg = (sel) => getComputedStyle(q(sel)).backgroundColor
|
const bg = (sel) => getComputedStyle(q(sel)).backgroundColor
|
||||||
const unified = bg('.iwb-editor-header .iwb-editor-btn-new') === bg('.iwb-editor-header .iwb-editor-btn-replace') &&
|
const unified = bg('.iwb-editor-header .iwb-editor-btn-new') === bg('.iwb-editor-header .iwb-editor-btn-replace') &&
|
||||||
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 &&
|
||||||
|
!q('.iwb-editor-header > .iwb-editor-history') && // v1.18 搬去工具条最右
|
||||||
!q('.iwb-editor-header > .iwb-editor-commands') &&
|
!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"]')
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// v1.18(用户 2026-11-10):撤销 / 重做 / 还原从顶栏搬到画布底部工具栏最右 —— 手在画布上时够得到
|
||||||
|
check('撤销 / 重做 / 还原 在工具条最右(视图快捷之后,是 tools 的最后一个子元素)', await page.evaluate(() => {
|
||||||
|
const tools = document.querySelector('.iwb-editor-tools')
|
||||||
|
const hist = tools && tools.querySelector('.iwb-editor-history')
|
||||||
|
const fit = tools && tools.querySelector('[data-action="zoomFit"]')
|
||||||
|
const panels = tools && tools.querySelector('[data-action="togglePanels"]')
|
||||||
|
const crop = tools && tools.querySelector('[data-tool="crop"]')
|
||||||
|
if (!hist || !fit || !panels || !crop) return false
|
||||||
|
const acts = [...hist.querySelectorAll('[data-action]')].map((b) => b.dataset.action).join(',')
|
||||||
|
const c = crop.getBoundingClientRect()
|
||||||
|
const f = fit.getBoundingClientRect()
|
||||||
|
const p = panels.getBoundingClientRect()
|
||||||
|
const h = hist.getBoundingClientRect()
|
||||||
|
return acts === 'undo,redo,reset' &&
|
||||||
|
tools.lastElementChild === hist &&
|
||||||
|
c.right <= f.left && f.right <= p.left && p.right <= h.left &&
|
||||||
|
Math.abs(h.top - c.top) < 2 // 与工具按钮同一条水平线,没有掉到第二行
|
||||||
|
}))
|
||||||
|
// 开发用:ANNOT_SHOT_BAR=/tmp/bar.png 出一张工具条截图(验证撤销组落在最右、没有换行)
|
||||||
|
if (process.env.ANNOT_SHOT_BAR) await page.locator('.iwb-editor-tools').screenshot({ path: process.env.ANNOT_SHOT_BAR })
|
||||||
check('画笔选项栏:推荐大小只留 4 个快捷点,硬度补 5 个快捷点且滑杆加宽', await (async () => {
|
check('画笔选项栏:推荐大小只留 4 个快捷点,硬度补 5 个快捷点且滑杆加宽', await (async () => {
|
||||||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||||||
const ok = await page.evaluate(() => {
|
const ok = await page.evaluate(() => {
|
||||||
@@ -1983,7 +2072,7 @@ check('点文字的「描边」格:色板目标是描边(tab 写「描边」
|
|||||||
popTextTarget.bgVisible && popTextTarget.noneVisible, JSON.stringify(popTextTarget))
|
popTextTarget.bgVisible && popTextTarget.noneVisible, JSON.stringify(popTextTarget))
|
||||||
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||||
el.value = '#00a3ff'
|
el.value = '#00a3ff'
|
||||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
})
|
})
|
||||||
@@ -2019,7 +2108,7 @@ const popBgTarget = await page.evaluate(() => {
|
|||||||
check('点文字的「底色」格:色板切到底色', popBgTarget.bgActive && popBgTarget.label === '底色', JSON.stringify(popBgTarget))
|
check('点文字的「底色」格:色板切到底色', popBgTarget.bgActive && popBgTarget.label === '底色', JSON.stringify(popBgTarget))
|
||||||
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||||
el.value = '#123456'
|
el.value = '#123456'
|
||||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
})
|
})
|
||||||
@@ -2045,7 +2134,7 @@ check('底色格显示真实颜色(半透明显示,不是实心块)',
|
|||||||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
await page.waitForTimeout(200)
|
await page.waitForTimeout(200)
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||||
el.value = '#ff00aa'
|
el.value = '#ff00aa'
|
||||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
})
|
})
|
||||||
@@ -2062,12 +2151,12 @@ check('文字色 / 描边色 / 底色三格互不串(改一格不动另外两
|
|||||||
// 「无」在底色格 = 关掉底色块,颜色留着
|
// 「无」在底色格 = 关掉底色块,颜色留着
|
||||||
await page.locator('.iwb-editor-color-btn[data-color-slot="bg"]').click()
|
await page.locator('.iwb-editor-color-btn[data-color-slot="bg"]').click()
|
||||||
await page.waitForTimeout(200)
|
await page.waitForTimeout(200)
|
||||||
await page.evaluate(() => document.querySelector('[data-color-none]').click())
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
await page.waitForTimeout(260)
|
await page.waitForTimeout(260)
|
||||||
const bgNone = await page.evaluate(() => {
|
const bgNone = await page.evaluate(() => {
|
||||||
const t = window.__iwbEditor.__debug().texts[0]
|
const t = window.__iwbEditor.__debug().texts[0]
|
||||||
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="bg"]')
|
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') }
|
return { bgFill: t.bgFill, bgColor: t.bgColor, cls: chip.className, noneActive: document.querySelector('.iwb-editor-color-pop [data-color-none]').classList.contains('active') }
|
||||||
})
|
})
|
||||||
check('底色格点「无」:关掉底色块、颜色留着,格子回到斜杠态',
|
check('底色格点「无」:关掉底色块、颜色留着,格子回到斜杠态',
|
||||||
bgNone.bgFill === false && bgNone.bgColor === '#123456' && /is-none/.test(bgNone.cls) && bgNone.noneActive,
|
bgNone.bgFill === false && bgNone.bgColor === '#123456' && /is-none/.test(bgNone.cls) && bgNone.noneActive,
|
||||||
@@ -2264,7 +2353,7 @@ 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)
|
||||||
const recents = (await dbg()).recentColors
|
const recents = (await dbg()).recentColors
|
||||||
const recentsInPop = await page.locator('.iwb-editor-recent-colors [data-panel-color]').count()
|
const recentsInPop = await page.locator('.iwb-editor-color-pop .iwb-editor-recent-colors [data-panel-color]').count()
|
||||||
await page.keyboard.press('Escape')
|
await page.keyboard.press('Escape')
|
||||||
await page.waitForTimeout(120)
|
await page.waitForTimeout(120)
|
||||||
check('选过的颜色进入「最近使用」并出现在色板弹层',
|
check('选过的颜色进入「最近使用」并出现在色板弹层',
|
||||||
@@ -2415,7 +2504,7 @@ check('点填充槽打开色板:目标是填充,并出现「无」按钮',
|
|||||||
// 拿黄色/绿色统计会数到别的图形,永远清不到 0。
|
// 拿黄色/绿色统计会数到别的图形,永远清不到 0。
|
||||||
const mainBefore = await page.evaluate(() => window.__iwbEditor.__debug().color)
|
const mainBefore = await page.evaluate(() => window.__iwbEditor.__debug().color)
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||||
el.value = '#a014b2'
|
el.value = '#a014b2'
|
||||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
})
|
})
|
||||||
@@ -2432,13 +2521,13 @@ check('色板里选色写进填充、主色(描边)不动,工具栏填充
|
|||||||
|
|
||||||
// 「无」:关填充,画面清空,但颜色留着
|
// 「无」:关填充,画面清空,但颜色留着
|
||||||
const purpleBefore = await countColorInVec([160, 20, 178], 10)
|
const purpleBefore = await countColorInVec([160, 20, 178], 10)
|
||||||
await page.evaluate(() => document.querySelector('[data-color-none]').click())
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
await page.waitForTimeout(320)
|
await page.waitForTimeout(320)
|
||||||
const afterNone = await page.evaluate(() => {
|
const afterNone = await page.evaluate(() => {
|
||||||
const d = window.__iwbEditor.__debug()
|
const d = window.__iwbEditor.__debug()
|
||||||
const s = d.shapes[d.shapes.length - 1]
|
const s = d.shapes[d.shapes.length - 1]
|
||||||
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
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') }
|
return { fill: s.fill, fillColor: s.fillColor, btnCls: fillBtn.className, noneActive: document.querySelector('.iwb-editor-color-pop [data-color-none]').classList.contains('active') }
|
||||||
})
|
})
|
||||||
const purpleAfter = await countColorInVec([160, 20, 178], 10)
|
const purpleAfter = await countColorInVec([160, 20, 178], 10)
|
||||||
check('「无」把填充关掉:画面清空、颜色留着(下次点颜色还是它)',
|
check('「无」把填充关掉:画面清空、颜色留着(下次点颜色还是它)',
|
||||||
@@ -2532,6 +2621,174 @@ const shiftXSwap = await (async () => {
|
|||||||
})()
|
})()
|
||||||
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// v1.17:描边也能是「无色」;只要有一边无色,Shift+X 照样能交换
|
||||||
|
// ================================================================
|
||||||
|
// 用户原话:「让矢量图形与钢笔的描边色也可以去掉」
|
||||||
|
// 「让描边与填充,有一个是无色的时候,可以交换,现在是不可以的」
|
||||||
|
const setOptColor = (slot, hex) => page.evaluate(({ slot, hex }) => {
|
||||||
|
const el = document.querySelector(`.iwb-editor-optionbar-body [data-shape-color="${slot}"]`)
|
||||||
|
el.value = hex
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
}, { slot, hex })
|
||||||
|
|
||||||
|
async function drawRectAt(x1, y1, x2, y2) {
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
|
const a = { x: imgBox.x + imgBox.width * x1, y: imgBox.y + imgBox.height * y1 }
|
||||||
|
const b = { x: imgBox.x + imgBox.width * x2, y: imgBox.y + imgBox.height * y2 }
|
||||||
|
await page.mouse.move(a.x, a.y); await page.mouse.down()
|
||||||
|
await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up()
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
|
await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2)
|
||||||
|
await page.waitForTimeout(160)
|
||||||
|
return { a, b }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取选中形状 + 三处 UI 的「无」状态,后面几条都用它
|
||||||
|
const selectedShapeState = () => page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes.find(x => x.id === d.selectedShapeId)
|
||||||
|
const btn = document.querySelector('.iwb-editor-color-pair [data-color-slot="stroke"]')
|
||||||
|
const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
||||||
|
const none = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
||||||
|
return {
|
||||||
|
type: s && s.type, closed: s && s.closed,
|
||||||
|
strokeOn: s && s.strokeOn, fill: s && s.fill,
|
||||||
|
color: s && s.color, fillColor: s && s.fillColor,
|
||||||
|
strokeBtnNone: !!btn && btn.classList.contains('is-none'),
|
||||||
|
optOff: !!opt && opt.classList.contains('is-off'),
|
||||||
|
noneHidden: !none || none.hidden,
|
||||||
|
noneActive: !!none && none.classList.contains('active')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// ---- 形状:去掉描边 ----
|
||||||
|
// 描边给一个画布上没出现过的洋红,靠像素数证明「框真的没了」而不是只改了数据
|
||||||
|
await drawRectAt(0.55, 0.52, 0.82, 0.74)
|
||||||
|
await setOptColor('fill', '#0aa6c8')
|
||||||
|
await page.waitForTimeout(160)
|
||||||
|
await setOptColor('stroke', '#ff00aa')
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
// 按画布分别数:画布上还躺着别的早期用例留下的同色对象(文字就用了 #ff00aa),
|
||||||
|
// 全局求和会把它们算进来 —— 只认「某一个画布从有变没有」才说得清这条描边真的没了
|
||||||
|
const magentaPerCanvas = () => page.evaluate(() => [...document.querySelectorAll('.iwb-editor-vec-canvas')].map(cv => {
|
||||||
|
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||||||
|
let n = 0
|
||||||
|
for (let i = 0; i < d.length; i += 4) {
|
||||||
|
if (d[i + 3] > 200 && Math.abs(d[i] - 255) < 8 && d[i + 1] < 8 && Math.abs(d[i + 2] - 170) < 8) n++
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}))
|
||||||
|
const magentaBefore = await magentaPerCanvas()
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const noneShownOnStroke = await page.evaluate(() =>
|
||||||
|
!document.querySelector('.iwb-editor-color-pop [data-color-none]').hidden)
|
||||||
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const noStroke = await selectedShapeState()
|
||||||
|
const magentaAfter = await magentaPerCanvas()
|
||||||
|
const cyanStill = await countColorInVec([10, 166, 200], 8)
|
||||||
|
const strokeGone = magentaBefore.some((n, i) => n > 300 && magentaAfter[i] === 0)
|
||||||
|
const noNewMagenta = magentaAfter.every((n, i) => n <= magentaBefore[i])
|
||||||
|
check('形状可以去掉描边:描边像素清零,填充色与描边色都留着',
|
||||||
|
noneShownOnStroke && strokeGone && noNewMagenta &&
|
||||||
|
noStroke.strokeOn === false && noStroke.fill === true &&
|
||||||
|
noStroke.color === '#ff00aa' && cyanStill > 300,
|
||||||
|
JSON.stringify({ noneShownOnStroke, magentaBefore, magentaAfter, cyanStill, ...noStroke }))
|
||||||
|
check('无描边时工具栏描边格画斜杠、选项栏描边色块置灰、色板「无」高亮',
|
||||||
|
noStroke.strokeBtnNone === true && noStroke.optOff === true && noStroke.noneActive === true,
|
||||||
|
JSON.stringify({ btn: noStroke.strokeBtnNone, opt: noStroke.optOff, none: noStroke.noneActive }))
|
||||||
|
|
||||||
|
// 对称保护:已经无描边、再把填充也点掉 → 对象会彻底隐形,应当自动把描边还回来
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const bothNone = await selectedShapeState()
|
||||||
|
check('「无描边」后再点「无填充」:自动恢复描边,不会留下一个看不见的对象',
|
||||||
|
bothNone.fill === false && bothNone.strokeOn === true,
|
||||||
|
JSON.stringify({ fill: bothNone.fill, strokeOn: bothNone.strokeOn }))
|
||||||
|
// 回到「无描边」状态给下一条用例用(色板此时停在填充槽,先切回描边)
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
|
await page.waitForTimeout(280)
|
||||||
|
|
||||||
|
// 选色即恢复描边:与「文字描边宽度 0 时选色自动给 6px」同一条逻辑,
|
||||||
|
// 否则用户选了颜色画面没变化,会以为颜色设置坏了
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||||
|
el.value = '#ff00aa'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const revivedStroke = await selectedShapeState()
|
||||||
|
const magentaRevived = await magentaPerCanvas()
|
||||||
|
const strokeBack = magentaRevived.some((n, i) => n > 300 && magentaAfter[i] === 0)
|
||||||
|
check('无描边时再选一次颜色 → 自动恢复描边(选了色一定有变化)',
|
||||||
|
revivedStroke.strokeOn === true && revivedStroke.color === '#ff00aa' && strokeBack,
|
||||||
|
JSON.stringify({ ...revivedStroke, strokeBack, magentaAfter, magentaRevived }))
|
||||||
|
|
||||||
|
// ---- 钢笔闭合路径:同样能去掉描边 ----
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||||||
|
const t1 = { x: imgBox.x + imgBox.width * 0.34, y: imgBox.y + imgBox.height * 0.16 }
|
||||||
|
const t2 = { x: imgBox.x + imgBox.width * 0.46, y: imgBox.y + imgBox.height * 0.16 }
|
||||||
|
const t3 = { x: imgBox.x + imgBox.width * 0.40, y: imgBox.y + imgBox.height * 0.34 }
|
||||||
|
await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(t2.x, t2.y); await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(t3.x, t3.y); await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(280) // 回到起点 = 闭合
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const penNoStroke = await selectedShapeState()
|
||||||
|
check('钢笔闭合路径也能去掉描边(去掉后只剩填充面,不会整个消失)',
|
||||||
|
penNoStroke.type === 'pen' && penNoStroke.closed === true &&
|
||||||
|
penNoStroke.strokeOn === false && penNoStroke.fill === true,
|
||||||
|
JSON.stringify(penNoStroke))
|
||||||
|
|
||||||
|
// 未闭合路径没有可填内部:去掉描边 = 这条线没了,索性不给「无」
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||||||
|
await page.mouse.click(imgBox.x + imgBox.width * 0.62, imgBox.y + imgBox.height * 0.36)
|
||||||
|
await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(imgBox.x + imgBox.width * 0.76, imgBox.y + imgBox.height * 0.42)
|
||||||
|
await page.waitForTimeout(90)
|
||||||
|
await page.keyboard.press('Enter') // 回车结束开放路径
|
||||||
|
await page.waitForTimeout(280)
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const openPen = await selectedShapeState()
|
||||||
|
check('未闭合钢笔不给「无描边」(去掉等于把这条线删了)',
|
||||||
|
openPen.type === 'pen' && openPen.closed === false && openPen.noneHidden === true,
|
||||||
|
JSON.stringify(openPen))
|
||||||
|
|
||||||
|
// ---- 一边无色也能交换(用户反馈的第二个问题)----
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await drawRectAt(0.08, 0.10, 0.30, 0.30)
|
||||||
|
// 先做成「只有描边」:fill 关掉,描边给独立色
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const btn = document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="stroke"]')
|
||||||
|
if (btn) btn.click()
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
await setOptColor('stroke', '#ff00aa')
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const onlyStroke = await selectedShapeState()
|
||||||
|
await page.keyboard.press('Shift+x')
|
||||||
|
await page.waitForTimeout(260)
|
||||||
|
const afterSwap1 = await selectedShapeState()
|
||||||
|
await page.keyboard.press('Shift+x')
|
||||||
|
await page.waitForTimeout(260)
|
||||||
|
const afterSwap2 = await selectedShapeState()
|
||||||
|
check('一边无色也能交换:只描边 → 只填充(描边关、填充开),再按回到原样',
|
||||||
|
onlyStroke.strokeOn === true && onlyStroke.fill === false &&
|
||||||
|
afterSwap1.strokeOn === false && afterSwap1.fill === true &&
|
||||||
|
afterSwap2.strokeOn === true && afterSwap2.fill === false,
|
||||||
|
JSON.stringify({ 原: onlyStroke, 按一次: afterSwap1, 再按: afterSwap2 }))
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// v1.15 图片调节(放最后:会改像素,放中间会污染依赖像素的用例)
|
// v1.15 图片调节(放最后:会改像素,放中间会污染依赖像素的用例)
|
||||||
// ================================================================
|
// ================================================================
|
||||||
@@ -2553,6 +2810,73 @@ check('右侧栏出现「图片调节」,11 项齐全且顺序固定',
|
|||||||
adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度',
|
adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度',
|
||||||
'rows=' + adjRowCount + ' ' + adjNames.join('/'))
|
'rows=' + adjRowCount + ' ' + adjNames.join('/'))
|
||||||
|
|
||||||
|
// ---------- v1.16:右栏常驻调色面板 / 两处同步 / 可拖宽度 / 字号 ----------
|
||||||
|
const sideSurface = await page.evaluate(() => {
|
||||||
|
const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]')
|
||||||
|
if (!side) return null
|
||||||
|
const tabs = [...side.querySelectorAll('.iwb-color-pop-tab')]
|
||||||
|
return {
|
||||||
|
tabs: tabs.length,
|
||||||
|
visibleTabs: tabs.filter(t => !t.hidden).length,
|
||||||
|
swatches: side.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]').length,
|
||||||
|
sv: !!side.querySelector('.iwb-color-sv'),
|
||||||
|
hue: !!side.querySelector('.iwb-color-hue'),
|
||||||
|
hex: !!side.querySelector('.iwb-editor-color-hex-input')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('右栏有常驻调色面板:可调颜色项 + 调色器 + 12 个常用色',
|
||||||
|
Boolean(sideSurface) && sideSurface.tabs === 3 && sideSurface.visibleTabs >= 1 &&
|
||||||
|
sideSurface.swatches === 12 && sideSurface.sv && sideSurface.hue && sideSurface.hex,
|
||||||
|
JSON.stringify(sideSurface))
|
||||||
|
|
||||||
|
// 在右栏点常用色 → 弹层里同一色块也必须高亮(两处共用一份颜色状态)
|
||||||
|
await page.locator('.iwb-editor-left [data-color-surface="side"] [data-panel-color="#00bfa5"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const colorSync = await page.evaluate(() => {
|
||||||
|
// 只看「常用色」网格:最近使用里同色也会高亮,那是正常的两处提示,不该算进断言
|
||||||
|
const activeIn = (root) => [...root.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
|
||||||
|
.filter(b => b.classList.contains('active')).map(b => b.dataset.panelColor)
|
||||||
|
const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]')
|
||||||
|
const pop = document.querySelector('.iwb-editor-color-pop')
|
||||||
|
return { side: activeIn(side), pop: activeIn(pop), color: window.__iwbEditor.__debug().color }
|
||||||
|
})
|
||||||
|
check('右栏选色后弹层同一色块同步高亮(不是两套各管各的)',
|
||||||
|
colorSync.side.length === 1 && colorSync.side[0] === '#00bfa5' &&
|
||||||
|
colorSync.pop.length === 1 && colorSync.pop[0] === '#00bfa5' && colorSync.color === '#00bfa5',
|
||||||
|
JSON.stringify(colorSync))
|
||||||
|
|
||||||
|
// 拖右栏宽度:侧栏在画布右侧,指针左移 80px ⇒ 宽 80px
|
||||||
|
const sideW0 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||||
|
const grip = await page.locator('.iwb-editor-side-resizer').boundingBox()
|
||||||
|
await page.mouse.move(grip.x + grip.width / 2, grip.y + grip.height / 2)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(grip.x + grip.width / 2 - 80, grip.y + grip.height / 2, { steps: 8 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
const sideW1 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||||
|
check('拖右栏手柄:宽度随拖动变大(不是固定 220)',
|
||||||
|
sideW1 >= sideW0 + 70 && sideW1 <= 520, sideW0 + ' → ' + sideW1)
|
||||||
|
|
||||||
|
await page.locator('.iwb-editor-side-resizer').dblclick()
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
const sideW2 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||||
|
// 注意:aside 是 content-box,width 280 + 左右 padding 24 ⇒ rect 约 304/305。
|
||||||
|
// 这里跟「拖之前」比才对,写死 280 会误判。
|
||||||
|
check('双击手柄复位到默认宽度(回到拖动前)', Math.abs(sideW2 - sideW0) <= 2, sideW0 + ' ← ' + sideW2)
|
||||||
|
|
||||||
|
const fontSizes = await page.evaluate(() => ({
|
||||||
|
adjName: getComputedStyle(document.querySelector('.iwb-editor-adj-name')).fontSize,
|
||||||
|
adjTitle: getComputedStyle(document.querySelector('.iwb-editor-adj-title')).fontSize,
|
||||||
|
statusbar: getComputedStyle(document.querySelector('.iwb-editor-statusbar')).fontSize,
|
||||||
|
optionbar: getComputedStyle(document.querySelector('.iwb-editor-optionbar')).fontSize,
|
||||||
|
layerName: document.querySelector('.iwb-layer-name') ? getComputedStyle(document.querySelector('.iwb-layer-name')).fontSize : null
|
||||||
|
}))
|
||||||
|
check('整体字号提升一档(面板行名 12.5 / 标题 13 / 状态栏 12 / 选项栏 13)',
|
||||||
|
fontSizes.adjName === '12.5px' && fontSizes.adjTitle === '13px' &&
|
||||||
|
fontSizes.statusbar === '12px' && fontSizes.optionbar === '13px' &&
|
||||||
|
(!fontSizes.layerName || fontSizes.layerName === '13px'),
|
||||||
|
JSON.stringify(fontSizes))
|
||||||
|
|
||||||
/** 合成整幅可见像素后统计:平均亮度 / 灰像素占比 / R、B 均值 */
|
/** 合成整幅可见像素后统计:平均亮度 / 灰像素占比 / R、B 均值 */
|
||||||
const adjStat = () => page.evaluate(() => {
|
const adjStat = () => page.evaluate(() => {
|
||||||
const list = [...document.querySelectorAll('.iwb-editor-layer-canvas')]
|
const list = [...document.querySelectorAll('.iwb-editor-layer-canvas')]
|
||||||
|
|||||||
@@ -28,9 +28,12 @@ v0.2 换 potrace,并且按用户要求**只做单色 / 灰度**(不做彩色
|
|||||||
背景默认白)+「带底」勾选(决定背景色是否写进导出)
|
背景默认白)+「带底」勾选(决定背景色是否写进导出)
|
||||||
- **按孤岛拆分**(默认开):每个连通块输出为一个独立 `<path>` 元素,粘到 Figma 就是多个
|
- **按孤岛拆分**(默认开):每个连通块输出为一个独立 `<path>` 元素,粘到 Figma 就是多个
|
||||||
可单独选中的图层;关掉则整图合并成一个 path(便于整体缩放/移动)
|
可单独选中的图层;关掉则整图合并成一个 path(便于整体缩放/移动)
|
||||||
- 预览:按住空格对比原图;面板显示元素数 / 层数 / 体积 / 耗时
|
- 预览:按住空格对比原图;**滚轮/捏合缩放、左键拖动平移、双击复位**(0.2×–8×);面板显示元素数 / 层数 / 体积 / 耗时
|
||||||
- 输出:**复制 SVG**(写 `image/svg+xml` + `text/html` + `text/plain` 三种剪贴板口味,
|
- 顶栏按钮(左 → 右):**保存为节点** · **复制 SVG** · **下载 SVG** · 取消(四颗统一描边配色,不用绿色主按钮)
|
||||||
Figma / Illustrator 粘进去就是真矢量)· **下载 SVG** · **保存为节点**(PNG,按输出倍率 1–4× 从矢量重绘)
|
- **保存为节点**:PNG,按输出倍率 1–4× 从矢量重绘后写回画布
|
||||||
|
- **复制 SVG**:写 `image/svg+xml` + `text/html` + `text/plain` 三种剪贴板口味,
|
||||||
|
Figma / Illustrator 粘进去就是真矢量
|
||||||
|
- **下载 SVG**:存成文件
|
||||||
|
|
||||||
## 按孤岛拆分(v0.3)
|
## 按孤岛拆分(v0.3)
|
||||||
|
|
||||||
@@ -84,6 +87,34 @@ potrace 出厂把**整张图所有轮廓**塞进同一个 `<path>` 的 d 里(8
|
|||||||
白底 + 白底稿(菜单、白底商品图)会看不出画面边界,所以预览图本身留了一圈 1px 极淡描边 +
|
白底 + 白底稿(菜单、白底商品图)会看不出画面边界,所以预览图本身留了一圈 1px 极淡描边 +
|
||||||
细阴影;这是唯一一处「为了看清边界」而加的装饰。
|
细阴影;这是唯一一处「为了看清边界」而加的装饰。
|
||||||
|
|
||||||
|
## 预览缩放 / 平移(v0.4)
|
||||||
|
|
||||||
|
描摹结果要放大看细节(笔画接缝、圆角有没有被拟合成直线),所以预览区是一块可缩放画布:
|
||||||
|
|
||||||
|
| 操作 | 行为 |
|
||||||
|
|---|---|
|
||||||
|
| 鼠标滚轮 / 触控板捏合 | 以**光标位置为锚点**缩放(0.2×–8×) |
|
||||||
|
| 按住左键拖动 / 按住中键拖动 | 平移画布(100% 时也能拖) |
|
||||||
|
| 水平滚动(`Shift` + 滚轮也是这种) | 只平移,不改倍率 |
|
||||||
|
| 双击 / 点右下角「172% 复位」/ 按 `0` | 回到 100% 等比铺满 |
|
||||||
|
| `+` / `-` | 以画面中心缩放 |
|
||||||
|
|
||||||
|
三个实现上的取舍:
|
||||||
|
|
||||||
|
- **视图状态写进 `.vz-preview` 的 CSS 变量**(`--vz-zoom` / `--vz-pan-x` / `--vz-pan-y`),
|
||||||
|
由两张 `<img>`(矢量 + 原图)各自 `transform: var(...)` 引用。按住空格切原图时视图**纹丝不动** ——
|
||||||
|
要是每张图各存一份状态,切过去那一刻画面就会跳。harness 有断言锁这个行为。
|
||||||
|
- **锚点缩放**才有「指哪放大哪」的感觉。推导:图片中心恒在「预览区中心 + pan」,屏幕点 P 的图上偏移
|
||||||
|
`d = (P − C − pan) / zoom`,要让 P 不动需 `pan′ = pan + d·(zoom − zoom′)`。
|
||||||
|
- **滚轮一律缩放,不猜设备**。第一版想区分「鼠标滚轮 vs 触控板双指滑动」,判定条件写成
|
||||||
|
「`deltaY` 是 ±100 这类整数且 ≥48」—— 结果鼠标开着平滑滚动、或高精度滚轮给小数步长时,
|
||||||
|
滚轮被当成双指滑动,表现成**拖图不放大**(用户实测踩到)。现在只按主导轴分:
|
||||||
|
垂直 → 缩放,水平 → 平移。步长按幅度分两档(≥40 用 0.0018,细碎小数用 0.012),
|
||||||
|
让鼠标一格约 1.2×、触控板小步也跟手。
|
||||||
|
|
||||||
|
布局上 `.vz-stage` 从 flex 居中改成 `position: absolute` + `translate(-50%, -50%)`:
|
||||||
|
缩放锚点要求元素的变换中心稳稳落在预览区正中,flex 居中下图片尺寸一变中心就会漂。
|
||||||
|
|
||||||
## 复制到剪贴板为什么写三种口味
|
## 复制到剪贴板为什么写三种口味
|
||||||
|
|
||||||
剪贴板不像文件,只有一个「格式」——它同时可以装多份不同 MIME 的数据,读的一方自己挑。
|
剪贴板不像文件,只有一个「格式」——它同时可以装多份不同 MIME 的数据,读的一方自己挑。
|
||||||
@@ -105,7 +136,7 @@ potrace 与其 JS 移植都是 **GPL-2.0**(见 `plugin/vendor/potrace/LICENSE`
|
|||||||
```bash
|
```bash
|
||||||
npm run build -- image-vectorize # plugin/ → src/index.js(esbuild IIFE)
|
npm run build -- image-vectorize # plugin/ → src/index.js(esbuild IIFE)
|
||||||
npm run validate # 契约校验
|
npm run validate # 契约校验
|
||||||
node image-vectorize/tools/harness.mjs # 本地端到端(合成宿主 + 真 Chromium,47 项)
|
node image-vectorize/tools/harness.mjs # 本地端到端(合成宿主 + 真 Chromium,64 项)
|
||||||
node image-vectorize/tools/e2e-site.mjs # 真站(KV / SRI / CSP / 真实画布桥)
|
node image-vectorize/tools/e2e-site.mjs # 真站(KV / SRI / CSP / 真实画布桥)
|
||||||
|
|
||||||
# 拿真实素材调参数(不进 CI,最快看到效果):
|
# 拿真实素材调参数(不进 CI,最快看到效果):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-vectorize",
|
"name": "@iwb-plugin/image-vectorize",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.3.1",
|
"version": "0.4.2",
|
||||||
"description": "位图转矢量:potrace(纯 JS)单色/灰度描摹,输出 SVG 与 PNG 节点;对文字、logo、线稿保形好,不需要 wasm",
|
"description": "位图转矢量:potrace(纯 JS)单色/灰度描摹,输出 SVG 与 PNG 节点;对文字、logo、线稿保形好,不需要 wasm",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-vectorize",
|
"id": "image-vectorize",
|
||||||
|
|||||||
@@ -75,14 +75,8 @@
|
|||||||
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
||||||
.vz-btn:active { background: #2f2f3a; }
|
.vz-btn:active { background: #2f2f3a; }
|
||||||
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
||||||
|
/* 顶栏四颗按钮统一走上面这套描边配色(曾经有一颗 .vz-btn-primary 绿色主按钮,
|
||||||
.vz-btn-primary {
|
2026-11-09 用户要求「颜色都用取消按钮的配色」,已去掉)。 */
|
||||||
background: #1f7a52;
|
|
||||||
border-color: #27875c;
|
|
||||||
color: #eafff5;
|
|
||||||
}
|
|
||||||
.vz-btn-primary:hover { background: #248a5d; border-color: #2f9c69; }
|
|
||||||
.vz-btn-primary:disabled { background: #24503e; border-color: #2a5c47; }
|
|
||||||
|
|
||||||
/* ---------- 主体 ---------- */
|
/* ---------- 主体 ---------- */
|
||||||
.vz-body {
|
.vz-body {
|
||||||
@@ -104,15 +98,41 @@
|
|||||||
棋盘格既干扰判断形状,也让深色细笔画看起来发虚(实测用户第一反应是「糊」)。
|
棋盘格既干扰判断形状,也让深色细笔画看起来发虚(实测用户第一反应是「糊」)。
|
||||||
矢量 SVG 本身仍不含背景矩形,导出/复制到 Figma 依旧是透明底。 */
|
矢量 SVG 本身仍不含背景矩形,导出/复制到 Figma 依旧是透明底。 */
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
|
/* 缩放 / 平移的**唯一真源**:矢量图与原图两张 img 共用这套变量,
|
||||||
|
所以按住空格对比时,视图完全不动(各自存一份状态迟早会对不上)。
|
||||||
|
量纲:zoom 无单位;pan 是**屏幕像素**(先 scale 后 translate,平移量不被缩放放大)。 */
|
||||||
|
--vz-zoom: 1;
|
||||||
|
--vz-pan-x: 0px;
|
||||||
|
--vz-pan-y: 0px;
|
||||||
|
cursor: grab;
|
||||||
|
/* 触屏 / 触控板手势全部自己处理,别让浏览器抢去做页面滚动 */
|
||||||
|
touch-action: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vz-preview.is-panning { cursor: grabbing; }
|
||||||
|
|
||||||
/* 白底之上用一圈极淡的描边 + 细阴影标出画面边界:
|
/* 白底之上用一圈极淡的描边 + 细阴影标出画面边界:
|
||||||
白底稿(如菜单/白底商品图)与预览区同色时,否则看不出图到哪里 */
|
白底稿(如菜单/白底商品图)与预览区同色时,否则看不出图到哪里。
|
||||||
|
绝对定位 + 50%/50% 是为了让 transform 的中心锚点稳定落在预览区正中(缩放锚点计算依赖这一点);
|
||||||
|
max-* 用 calc(100% - 40px) 抵掉 .vz-preview 的 20px padding(百分比相对 padding box 算)。 */
|
||||||
.vz-stage {
|
.vz-stage {
|
||||||
max-width: 100%;
|
position: absolute;
|
||||||
max-height: 100%;
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
max-width: calc(100% - 40px);
|
||||||
|
max-height: calc(100% - 40px);
|
||||||
display: block;
|
display: block;
|
||||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.07);
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.07);
|
||||||
|
transform:
|
||||||
|
translate(-50%, -50%)
|
||||||
|
translate(var(--vz-pan-x), var(--vz-pan-y))
|
||||||
|
scale(var(--vz-zoom));
|
||||||
|
transform-origin: 50% 50%;
|
||||||
|
/* 拖动时每帧改 transform,提前提层,避免整块重绘掉帧(最多两张图,内存代价可忽略) */
|
||||||
|
will-change: transform;
|
||||||
|
/* 拖动时别触发 img 的原生拖拽(会拽出一个半透明缩略图,手势直接断掉) */
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-drag: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.vz-stage[hidden] { display: none; }
|
.vz-stage[hidden] { display: none; }
|
||||||
@@ -148,6 +168,32 @@
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 缩放倍率:只有真的缩放过才出现(100% 时挂 hidden,不占视线)。
|
||||||
|
它同时是「现在没在 1:1」的唯一视觉信号 —— 用户放大看细节后容易忘记自己还缩着。 */
|
||||||
|
.vz-zoom {
|
||||||
|
position: absolute;
|
||||||
|
right: 14px;
|
||||||
|
bottom: 14px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 4px 9px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: rgba(255, 255, 255, 0.94);
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.12);
|
||||||
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
color: #45454f;
|
||||||
|
font-size: 11px;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.vz-zoom[hidden] { display: none; }
|
||||||
|
.vz-zoom b { font-weight: 600; }
|
||||||
|
.vz-zoom span { color: #9a9aa8; }
|
||||||
|
.vz-zoom:hover { border-color: rgba(0, 0, 0, 0.22); }
|
||||||
|
.vz-zoom:hover span { color: #45454f; }
|
||||||
|
|
||||||
/* 描摹中/出错的浮层 */
|
/* 描摹中/出错的浮层 */
|
||||||
.vz-status {
|
.vz-status {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -128,18 +128,21 @@ function viewHTML(name) {
|
|||||||
'<header class="vz-header">' +
|
'<header class="vz-header">' +
|
||||||
'<span class="vz-title">位图转矢量<em data-meta>' + esc(name) + '</em></span>' +
|
'<span class="vz-title">位图转矢量<em data-meta>' + esc(name) + '</em></span>' +
|
||||||
'<div class="vz-spacer"></div>' +
|
'<div class="vz-spacer"></div>' +
|
||||||
'<button type="button" class="vz-btn" data-act="cancel">取消</button>' +
|
// 顺序:主操作在左,取消在最右(用户 2026-11-09 要求与原先互换)。
|
||||||
|
// 四颗按钮同一套描边配色,不再给主操作上绿色填充 —— 用户口径「颜色都用取消按钮的配色」。
|
||||||
|
'<button type="button" class="vz-btn" data-act="save">保存为节点</button>' +
|
||||||
'<button type="button" class="vz-btn" data-act="copy">复制 SVG</button>' +
|
'<button type="button" class="vz-btn" data-act="copy">复制 SVG</button>' +
|
||||||
'<button type="button" class="vz-btn" data-act="svg">下载 SVG</button>' +
|
'<button type="button" class="vz-btn" data-act="svg">下载 SVG</button>' +
|
||||||
'<button type="button" class="vz-btn vz-btn-primary" data-act="save">保存为节点</button>' +
|
'<button type="button" class="vz-btn" data-act="cancel">取消</button>' +
|
||||||
'</header>' +
|
'</header>' +
|
||||||
'<div class="vz-body">' +
|
'<div class="vz-body">' +
|
||||||
'<div class="vz-preview">' +
|
'<div class="vz-preview" data-preview>' +
|
||||||
'<img class="vz-stage" data-stage="vector" alt="矢量预览">' +
|
'<img class="vz-stage" data-stage="vector" alt="矢量预览" draggable="false">' +
|
||||||
'<img class="vz-stage" data-stage="original" alt="原图" hidden>' +
|
'<img class="vz-stage" data-stage="original" alt="原图" draggable="false" hidden>' +
|
||||||
'<div class="vz-badge" data-badge>矢量预览</div>' +
|
'<div class="vz-badge" data-badge>矢量预览</div>' +
|
||||||
'<div class="vz-status" data-status hidden><i class="vz-dot"></i><span data-status-text></span></div>' +
|
'<div class="vz-status" data-status hidden><i class="vz-dot"></i><span data-status-text></span></div>' +
|
||||||
'<div class="vz-hint">空格 对比原图 · 「复制 SVG」可直接粘到 Figma</div>' +
|
'<div class="vz-hint">空格 对比原图 · 滚轮缩放 · 拖动平移 · 双击复位</div>' +
|
||||||
|
'<div class="vz-zoom" data-zoom-chip hidden title="点击回到 100%"><b data-zoom-val>100%</b><span>复位</span></div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'<aside class="vz-panel" data-panel></aside>' +
|
'<aside class="vz-panel" data-panel></aside>' +
|
||||||
'</div></div></div>'
|
'</div></div></div>'
|
||||||
@@ -171,6 +174,11 @@ export function createVectorizer(options) {
|
|||||||
let seq = 0
|
let seq = 0
|
||||||
let debounceTimer = 0
|
let debounceTimer = 0
|
||||||
let spaceDown = false
|
let spaceDown = false
|
||||||
|
// 预览视图(缩放 + 平移):zoom=1 / pan=0 就是原始「等比铺满」,双击或点倍率胶囊复位
|
||||||
|
let zoom = 1
|
||||||
|
let panX = 0
|
||||||
|
let panY = 0
|
||||||
|
let drag = null
|
||||||
|
|
||||||
// ---------- 设置读写 ----------
|
// ---------- 设置读写 ----------
|
||||||
|
|
||||||
@@ -323,6 +331,112 @@ export function createVectorizer(options) {
|
|||||||
els.badge.textContent = spaceDown ? '原图' : '矢量预览'
|
els.badge.textContent = spaceDown ? '原图' : '矢量预览'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- 预览视图:缩放 / 平移 ----------
|
||||||
|
//
|
||||||
|
// 为什么把状态写进 CSS 变量而不是直接改每张图的 style.transform:
|
||||||
|
// 预览里有「矢量」和「原图」两张 img 靠显隐切换做对比,各存一份视图状态迟早对不上
|
||||||
|
// (按住空格那一瞬间画面会跳)。变量挂在 .vz-preview 上,两张图共用,天然同步。
|
||||||
|
|
||||||
|
const ZOOM_MIN = 0.2
|
||||||
|
const ZOOM_MAX = 8
|
||||||
|
|
||||||
|
function applyView() {
|
||||||
|
if (!els || !els.preview) return
|
||||||
|
els.preview.style.setProperty('--vz-zoom', String(zoom))
|
||||||
|
els.preview.style.setProperty('--vz-pan-x', panX + 'px')
|
||||||
|
els.preview.style.setProperty('--vz-pan-y', panY + 'px')
|
||||||
|
const changed = zoom !== 1 || panX !== 0 || panY !== 0
|
||||||
|
if (els.zoomVal) els.zoomVal.textContent = Math.round(zoom * 100) + '%'
|
||||||
|
// 倍率胶囊只在真的缩放过时出现:100% 状态挂个「100% 复位」纯属噪音
|
||||||
|
if (els.zoomChip) els.zoomChip.hidden = !changed
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetView() {
|
||||||
|
zoom = 1
|
||||||
|
panX = 0
|
||||||
|
panY = 0
|
||||||
|
drag = null
|
||||||
|
if (els && els.preview) els.preview.classList.remove('is-panning')
|
||||||
|
applyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以屏幕点 (clientX, clientY) 为锚点缩放 —— 鼠标下的像素在缩放前后停在原处,
|
||||||
|
* 否则「想放大看这个字」会变成「放大完还得把它找回来」。
|
||||||
|
*
|
||||||
|
* 推导:图片中心恒在「预览区中心 + pan」,屏幕点 P 对应的图上偏移 d = (P - C - pan) / zoom,
|
||||||
|
* 要让 P 不动即 C + pan + d·zoom = C + pan' + d·zoom′ ⇒ pan′ = pan + d·(zoom − zoom′)。
|
||||||
|
*/
|
||||||
|
function zoomAt(clientX, clientY, factor) {
|
||||||
|
if (!els || !els.preview) return
|
||||||
|
const next = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, zoom * factor))
|
||||||
|
if (Math.abs(next - zoom) < 1e-4) return
|
||||||
|
const rect = els.preview.getBoundingClientRect()
|
||||||
|
const dx = (clientX - (rect.left + rect.width / 2) - panX) / zoom
|
||||||
|
const dy = (clientY - (rect.top + rect.height / 2) - panY) / zoom
|
||||||
|
panX -= dx * (next - zoom)
|
||||||
|
panY -= dy * (next - zoom)
|
||||||
|
zoom = next
|
||||||
|
applyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
function zoomAtCenter(factor) {
|
||||||
|
if (!els || !els.preview) return
|
||||||
|
const rect = els.preview.getBoundingClientRect()
|
||||||
|
zoomAt(rect.left + rect.width / 2, rect.top + rect.height / 2, factor)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPreviewWheel(event) {
|
||||||
|
event.preventDefault()
|
||||||
|
// 滚轮 = 缩放,无条件(用户口径:中键滚轮就是放大缩小)。
|
||||||
|
// 早先靠「deltaY 是 ±100 整数」猜设备来区分鼠标滚轮与触控板双指滑动,结果鼠标驱动
|
||||||
|
// 一旦给小数步长(平滑滚动 / 高精度滚轮)就落进平移分支,表现成「滚轮拖图不放大」。
|
||||||
|
// 现在只按主导轴分:水平滚动(含 Shift+滚轮,Chrome 会转成 deltaX)才平移。
|
||||||
|
if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) {
|
||||||
|
panX += event.deltaX
|
||||||
|
applyView()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!event.deltaY) return
|
||||||
|
// 步长分两档:鼠标滚轮一格 ±100,触控板是细碎小数步 —— 后者要给更大增益才跟得上手
|
||||||
|
const step = event.ctrlKey ? 0.01 : Math.abs(event.deltaY) >= 40 ? 0.0018 : 0.012
|
||||||
|
zoomAt(event.clientX, event.clientY, Math.exp(-event.deltaY * step))
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPreviewPointerDown(event) {
|
||||||
|
if (!els || !els.preview) return
|
||||||
|
// 左键拖动 = 平移;中键拖动也平移(设计软件的肌肉记忆,顺手)
|
||||||
|
if (event.button !== 0 && event.button !== 1) return
|
||||||
|
if (event.target.closest('.vz-zoom')) return
|
||||||
|
// 挡掉 img 原生拖拽与中键自动滚动(Windows 上会弹四向圆盘,手势直接断掉)
|
||||||
|
event.preventDefault()
|
||||||
|
drag = { x: event.clientX, y: event.clientY, panX: panX, panY: panY, id: event.pointerId }
|
||||||
|
els.preview.classList.add('is-panning')
|
||||||
|
try { els.preview.setPointerCapture(event.pointerId) } catch (e) { /* 没有 capture 也能拖,只是移出元素会断 */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPreviewPointerMove(event) {
|
||||||
|
if (!drag || !els || !els.preview || event.pointerId !== drag.id) return
|
||||||
|
panX = drag.panX + (event.clientX - drag.x)
|
||||||
|
panY = drag.panY + (event.clientY - drag.y)
|
||||||
|
applyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPreviewPointerUp(event) {
|
||||||
|
if (!drag) return
|
||||||
|
if (event && event.pointerId !== undefined && event.pointerId !== drag.id) return
|
||||||
|
if (els && els.preview) {
|
||||||
|
els.preview.classList.remove('is-panning')
|
||||||
|
try { els.preview.releasePointerCapture(drag.id) } catch (e) { /* 已经释放过 */ }
|
||||||
|
}
|
||||||
|
drag = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPreviewDblClick(event) {
|
||||||
|
if (event.target.closest('.vz-zoom')) return
|
||||||
|
resetView()
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- 描摹 ----------
|
// ---------- 描摹 ----------
|
||||||
|
|
||||||
function retrace() {
|
function retrace() {
|
||||||
@@ -602,6 +716,13 @@ export function createVectorizer(options) {
|
|||||||
close()
|
close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 视图快捷键:0 复位、+/- 以中心缩放。在滑杆 / 数字框里打字时不抢键
|
||||||
|
const keyTag = (event.target && event.target.tagName) || ''
|
||||||
|
if (keyTag !== 'INPUT' && keyTag !== 'TEXTAREA' && keyTag !== 'SELECT') {
|
||||||
|
if (event.key === '0') { event.preventDefault(); resetView(); return }
|
||||||
|
if (event.key === '+' || event.key === '=') { event.preventDefault(); zoomAtCenter(1.25); return }
|
||||||
|
if (event.key === '-' || event.key === '_') { event.preventDefault(); zoomAtCenter(0.8); return }
|
||||||
|
}
|
||||||
if (event.code === 'Space' && !spaceDown && !event.repeat) {
|
if (event.code === 'Space' && !spaceDown && !event.repeat) {
|
||||||
const tag = (event.target && event.target.tagName) || ''
|
const tag = (event.target && event.target.tagName) || ''
|
||||||
if (tag === 'INPUT' || tag === 'TEXTAREA') return
|
if (tag === 'INPUT' || tag === 'TEXTAREA') return
|
||||||
@@ -633,6 +754,11 @@ export function createVectorizer(options) {
|
|||||||
const node = root
|
const node = root
|
||||||
root = null
|
root = null
|
||||||
els = null
|
els = null
|
||||||
|
// 视图状态跟着会话走:下次打开从「等比铺满」开始
|
||||||
|
zoom = 1
|
||||||
|
panX = 0
|
||||||
|
panY = 0
|
||||||
|
drag = null
|
||||||
node.remove()
|
node.remove()
|
||||||
if (typeof onClose === 'function') onClose()
|
if (typeof onClose === 'function') onClose()
|
||||||
}
|
}
|
||||||
@@ -663,6 +789,8 @@ export function createVectorizer(options) {
|
|||||||
vector: root.querySelector('[data-stage="vector"]'),
|
vector: root.querySelector('[data-stage="vector"]'),
|
||||||
original: root.querySelector('[data-stage="original"]'),
|
original: root.querySelector('[data-stage="original"]'),
|
||||||
badge: root.querySelector('[data-badge]'),
|
badge: root.querySelector('[data-badge]'),
|
||||||
|
zoomChip: root.querySelector('[data-zoom-chip]'),
|
||||||
|
zoomVal: root.querySelector('[data-zoom-val]'),
|
||||||
status: root.querySelector('[data-status]'),
|
status: root.querySelector('[data-status]'),
|
||||||
statusText: root.querySelector('[data-status-text]'),
|
statusText: root.querySelector('[data-status-text]'),
|
||||||
meta: root.querySelector('[data-meta]'),
|
meta: root.querySelector('[data-meta]'),
|
||||||
@@ -672,6 +800,18 @@ export function createVectorizer(options) {
|
|||||||
els.panel.innerHTML = panelHTML(params, preset, outScale, advOpen)
|
els.panel.innerHTML = panelHTML(params, preset, outScale, advOpen)
|
||||||
|
|
||||||
root.addEventListener('click', onRootClick)
|
root.addEventListener('click', onRootClick)
|
||||||
|
// 预览视图手势:滚轮/捏合缩放、拖动平移、双击复位、点倍率胶囊复位
|
||||||
|
els.preview.addEventListener('wheel', onPreviewWheel, { passive: false })
|
||||||
|
els.preview.addEventListener('pointerdown', onPreviewPointerDown)
|
||||||
|
els.preview.addEventListener('pointermove', onPreviewPointerMove)
|
||||||
|
els.preview.addEventListener('pointerup', onPreviewPointerUp)
|
||||||
|
els.preview.addEventListener('pointercancel', onPreviewPointerUp)
|
||||||
|
// capture 被系统抢走(切窗口、拖出屏幕)时也要收尾,否则光标会一直卡在 grabbing
|
||||||
|
els.preview.addEventListener('lostpointercapture', onPreviewPointerUp)
|
||||||
|
els.preview.addEventListener('dblclick', onPreviewDblClick)
|
||||||
|
els.preview.addEventListener('click', function (event) {
|
||||||
|
if (event.target.closest('.vz-zoom')) resetView()
|
||||||
|
})
|
||||||
els.panel.addEventListener('input', onPanelInput)
|
els.panel.addEventListener('input', onPanelInput)
|
||||||
els.panel.addEventListener('click', onPanelClick)
|
els.panel.addEventListener('click', onPanelClick)
|
||||||
document.addEventListener('keydown', onKeyDown, true)
|
document.addEventListener('keydown', onKeyDown, true)
|
||||||
@@ -680,6 +820,7 @@ export function createVectorizer(options) {
|
|||||||
|
|
||||||
syncControls()
|
syncControls()
|
||||||
setStats(null)
|
setStats(null)
|
||||||
|
resetView()
|
||||||
retrace()
|
retrace()
|
||||||
return { close }
|
return { close }
|
||||||
}
|
}
|
||||||
|
|||||||
+179
-13
@@ -9,7 +9,7 @@
|
|||||||
var __IWB_VECTORIZE_MANIFEST__ = {
|
var __IWB_VECTORIZE_MANIFEST__ = {
|
||||||
id: 'image-vectorize',
|
id: 'image-vectorize',
|
||||||
name: '位图转矢量',
|
name: '位图转矢量',
|
||||||
version: '0.3.1',
|
version: '0.4.2',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
@@ -2082,14 +2082,8 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
||||||
.vz-btn:active { background: #2f2f3a; }
|
.vz-btn:active { background: #2f2f3a; }
|
||||||
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
||||||
|
/* 顶栏四颗按钮统一走上面这套描边配色(曾经有一颗 .vz-btn-primary 绿色主按钮,
|
||||||
.vz-btn-primary {
|
2026-11-09 用户要求「颜色都用取消按钮的配色」,已去掉)。 */
|
||||||
background: #1f7a52;
|
|
||||||
border-color: #27875c;
|
|
||||||
color: #eafff5;
|
|
||||||
}
|
|
||||||
.vz-btn-primary:hover { background: #248a5d; border-color: #2f9c69; }
|
|
||||||
.vz-btn-primary:disabled { background: #24503e; border-color: #2a5c47; }
|
|
||||||
|
|
||||||
/* ---------- 主体 ---------- */
|
/* ---------- 主体 ---------- */
|
||||||
.vz-body {
|
.vz-body {
|
||||||
@@ -2111,15 +2105,41 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
棋盘格既干扰判断形状,也让深色细笔画看起来发虚(实测用户第一反应是「糊」)。
|
棋盘格既干扰判断形状,也让深色细笔画看起来发虚(实测用户第一反应是「糊」)。
|
||||||
矢量 SVG 本身仍不含背景矩形,导出/复制到 Figma 依旧是透明底。 */
|
矢量 SVG 本身仍不含背景矩形,导出/复制到 Figma 依旧是透明底。 */
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
|
/* 缩放 / 平移的**唯一真源**:矢量图与原图两张 img 共用这套变量,
|
||||||
|
所以按住空格对比时,视图完全不动(各自存一份状态迟早会对不上)。
|
||||||
|
量纲:zoom 无单位;pan 是**屏幕像素**(先 scale 后 translate,平移量不被缩放放大)。 */
|
||||||
|
--vz-zoom: 1;
|
||||||
|
--vz-pan-x: 0px;
|
||||||
|
--vz-pan-y: 0px;
|
||||||
|
cursor: grab;
|
||||||
|
/* 触屏 / 触控板手势全部自己处理,别让浏览器抢去做页面滚动 */
|
||||||
|
touch-action: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vz-preview.is-panning { cursor: grabbing; }
|
||||||
|
|
||||||
/* 白底之上用一圈极淡的描边 + 细阴影标出画面边界:
|
/* 白底之上用一圈极淡的描边 + 细阴影标出画面边界:
|
||||||
白底稿(如菜单/白底商品图)与预览区同色时,否则看不出图到哪里 */
|
白底稿(如菜单/白底商品图)与预览区同色时,否则看不出图到哪里。
|
||||||
|
绝对定位 + 50%/50% 是为了让 transform 的中心锚点稳定落在预览区正中(缩放锚点计算依赖这一点);
|
||||||
|
max-* 用 calc(100% - 40px) 抵掉 .vz-preview 的 20px padding(百分比相对 padding box 算)。 */
|
||||||
.vz-stage {
|
.vz-stage {
|
||||||
max-width: 100%;
|
position: absolute;
|
||||||
max-height: 100%;
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
max-width: calc(100% - 40px);
|
||||||
|
max-height: calc(100% - 40px);
|
||||||
display: block;
|
display: block;
|
||||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.07);
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.07);
|
||||||
|
transform:
|
||||||
|
translate(-50%, -50%)
|
||||||
|
translate(var(--vz-pan-x), var(--vz-pan-y))
|
||||||
|
scale(var(--vz-zoom));
|
||||||
|
transform-origin: 50% 50%;
|
||||||
|
/* 拖动时每帧改 transform,提前提层,避免整块重绘掉帧(最多两张图,内存代价可忽略) */
|
||||||
|
will-change: transform;
|
||||||
|
/* 拖动时别触发 img 的原生拖拽(会拽出一个半透明缩略图,手势直接断掉) */
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-drag: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.vz-stage[hidden] { display: none; }
|
.vz-stage[hidden] { display: none; }
|
||||||
@@ -2155,6 +2175,32 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 缩放倍率:只有真的缩放过才出现(100% 时挂 hidden,不占视线)。
|
||||||
|
它同时是「现在没在 1:1」的唯一视觉信号 —— 用户放大看细节后容易忘记自己还缩着。 */
|
||||||
|
.vz-zoom {
|
||||||
|
position: absolute;
|
||||||
|
right: 14px;
|
||||||
|
bottom: 14px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 4px 9px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: rgba(255, 255, 255, 0.94);
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.12);
|
||||||
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
color: #45454f;
|
||||||
|
font-size: 11px;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.vz-zoom[hidden] { display: none; }
|
||||||
|
.vz-zoom b { font-weight: 600; }
|
||||||
|
.vz-zoom span { color: #9a9aa8; }
|
||||||
|
.vz-zoom:hover { border-color: rgba(0, 0, 0, 0.22); }
|
||||||
|
.vz-zoom:hover span { color: #45454f; }
|
||||||
|
|
||||||
/* 描摹中/出错的浮层 */
|
/* 描摹中/出错的浮层 */
|
||||||
.vz-status {
|
.vz-status {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -2970,7 +3016,7 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
}).join("") + '</div></div><div class="vz-row vz-row-switch"><div class="vz-row-text">按孤岛拆分<span>每个连通块一个图层,粘到 Figma 可单独选中;笔画不连的汉字会分成几块</span></div><label class="vz-switch"><input type="checkbox" data-check="splitIslands"' + (params.splitIslands ? " checked" : "") + '><i></i></label></div></div><div class="vz-group"><div class="vz-stats"><span><b data-stat="elements">–</b> 元素</span><span><b data-stat="levels">–</b> 层</span><span><b data-stat="bytes">–</b></span><span><b data-stat="ms">–</b></span></div></div><div class="vz-group"><button type="button" class="vz-adv-toggle" data-act="adv" aria-expanded="' + (advOpen ? "true" : "false") + '">高级参数<span data-adv-caret>' + (advOpen ? "▴" : "▾") + '</span></button><div class="vz-adv" data-adv' + (advOpen ? "" : " hidden") + '><div class="vz-row"><div class="vz-row-label">阈值<span>自动按直方图取,手动可救极端图</span></div><div class="vz-seg" data-seg-group="thrMode"><button type="button" data-seg="thrMode" data-value="auto">自动</button><button type="button" data-seg="thrMode" data-value="manual">手动</button></div></div><div data-thr-row hidden>' + rangeHTML("threshold", "阈值取值", 0, 255, 1, params.threshold >= 0 ? params.threshold : 128, "") + '</div><div class="vz-row"><div class="vz-row-label">反相<span>黑底白字时打开</span></div><div class="vz-seg" data-seg-group="invert">' + segHTML("invert", [["0", "正片"], ["1", "负片"]], params.invert ? 1 : 0) + '</div></div><div class="vz-row"><div class="vz-row-label">填充 / 背景<span>填充仅「纯单色」生效 · 背景作预览底</span></div><div class="vz-swatches"><input type="color" class="vz-color" data-color="color" value="' + esc(params.color) + '" title="填充色(纯单色生效)"><input type="color" class="vz-color" data-color="bg" value="' + esc(params.bg) + '" title="背景色(预览底;勾「带底」写入导出)"><label class="vz-mini" title="导出 / 复制时把背景色一起写进 SVG(默认不带,粘到 Figma 是透明底)"><input type="checkbox" data-check="bgExport"' + (params.bgExport ? " checked" : "") + "><span>带底</span></label></div></div></div></div>";
|
}).join("") + '</div></div><div class="vz-row vz-row-switch"><div class="vz-row-text">按孤岛拆分<span>每个连通块一个图层,粘到 Figma 可单独选中;笔画不连的汉字会分成几块</span></div><label class="vz-switch"><input type="checkbox" data-check="splitIslands"' + (params.splitIslands ? " checked" : "") + '><i></i></label></div></div><div class="vz-group"><div class="vz-stats"><span><b data-stat="elements">–</b> 元素</span><span><b data-stat="levels">–</b> 层</span><span><b data-stat="bytes">–</b></span><span><b data-stat="ms">–</b></span></div></div><div class="vz-group"><button type="button" class="vz-adv-toggle" data-act="adv" aria-expanded="' + (advOpen ? "true" : "false") + '">高级参数<span data-adv-caret>' + (advOpen ? "▴" : "▾") + '</span></button><div class="vz-adv" data-adv' + (advOpen ? "" : " hidden") + '><div class="vz-row"><div class="vz-row-label">阈值<span>自动按直方图取,手动可救极端图</span></div><div class="vz-seg" data-seg-group="thrMode"><button type="button" data-seg="thrMode" data-value="auto">自动</button><button type="button" data-seg="thrMode" data-value="manual">手动</button></div></div><div data-thr-row hidden>' + rangeHTML("threshold", "阈值取值", 0, 255, 1, params.threshold >= 0 ? params.threshold : 128, "") + '</div><div class="vz-row"><div class="vz-row-label">反相<span>黑底白字时打开</span></div><div class="vz-seg" data-seg-group="invert">' + segHTML("invert", [["0", "正片"], ["1", "负片"]], params.invert ? 1 : 0) + '</div></div><div class="vz-row"><div class="vz-row-label">填充 / 背景<span>填充仅「纯单色」生效 · 背景作预览底</span></div><div class="vz-swatches"><input type="color" class="vz-color" data-color="color" value="' + esc(params.color) + '" title="填充色(纯单色生效)"><input type="color" class="vz-color" data-color="bg" value="' + esc(params.bg) + '" title="背景色(预览底;勾「带底」写入导出)"><label class="vz-mini" title="导出 / 复制时把背景色一起写进 SVG(默认不带,粘到 Figma 是透明底)"><input type="checkbox" data-check="bgExport"' + (params.bgExport ? " checked" : "") + "><span>带底</span></label></div></div></div></div>";
|
||||||
}
|
}
|
||||||
function viewHTML(name) {
|
function viewHTML(name) {
|
||||||
return '<div class="vz-root"><div class="vz-modal" role="dialog" aria-modal="true" aria-label="位图转矢量"><header class="vz-header"><span class="vz-title">位图转矢量<em data-meta>' + esc(name) + '</em></span><div class="vz-spacer"></div><button type="button" class="vz-btn" data-act="cancel">取消</button><button type="button" class="vz-btn" data-act="copy">复制 SVG</button><button type="button" class="vz-btn" data-act="svg">下载 SVG</button><button type="button" class="vz-btn vz-btn-primary" data-act="save">保存为节点</button></header><div class="vz-body"><div class="vz-preview"><img class="vz-stage" data-stage="vector" alt="矢量预览"><img class="vz-stage" data-stage="original" alt="原图" hidden><div class="vz-badge" data-badge>矢量预览</div><div class="vz-status" data-status hidden><i class="vz-dot"></i><span data-status-text></span></div><div class="vz-hint">空格 对比原图 · 「复制 SVG」可直接粘到 Figma</div></div><aside class="vz-panel" data-panel></aside></div></div></div>';
|
return '<div class="vz-root"><div class="vz-modal" role="dialog" aria-modal="true" aria-label="位图转矢量"><header class="vz-header"><span class="vz-title">位图转矢量<em data-meta>' + esc(name) + '</em></span><div class="vz-spacer"></div><button type="button" class="vz-btn" data-act="save">保存为节点</button><button type="button" class="vz-btn" data-act="copy">复制 SVG</button><button type="button" class="vz-btn" data-act="svg">下载 SVG</button><button type="button" class="vz-btn" data-act="cancel">取消</button></header><div class="vz-body"><div class="vz-preview" data-preview><img class="vz-stage" data-stage="vector" alt="矢量预览" draggable="false"><img class="vz-stage" data-stage="original" alt="原图" draggable="false" hidden><div class="vz-badge" data-badge>矢量预览</div><div class="vz-status" data-status hidden><i class="vz-dot"></i><span data-status-text></span></div><div class="vz-hint">空格 对比原图 · 滚轮缩放 · 拖动平移 · 双击复位</div><div class="vz-zoom" data-zoom-chip hidden title="点击回到 100%"><b data-zoom-val>100%</b><span>复位</span></div></div><aside class="vz-panel" data-panel></aside></div></div></div>';
|
||||||
}
|
}
|
||||||
var ALPHA_TONE = { hard: 0.4, normal: 1, round: 1.2 };
|
var ALPHA_TONE = { hard: 0.4, normal: 1, round: 1.2 };
|
||||||
var toneOf = (alphaMax) => alphaMax <= 0.6 ? "hard" : alphaMax >= 1.1 ? "round" : "normal";
|
var toneOf = (alphaMax) => alphaMax <= 0.6 ? "hard" : alphaMax >= 1.1 ? "round" : "normal";
|
||||||
@@ -2994,6 +3040,10 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
let seq = 0;
|
let seq = 0;
|
||||||
let debounceTimer = 0;
|
let debounceTimer = 0;
|
||||||
let spaceDown = false;
|
let spaceDown = false;
|
||||||
|
let zoom = 1;
|
||||||
|
let panX = 0;
|
||||||
|
let panY = 0;
|
||||||
|
let drag = null;
|
||||||
function readSettings() {
|
function readSettings() {
|
||||||
const out = {};
|
const out = {};
|
||||||
if (!settings || typeof settings.get !== "function") return out;
|
if (!settings || typeof settings.get !== "function") return out;
|
||||||
@@ -3138,6 +3188,87 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
els.original.hidden = !spaceDown;
|
els.original.hidden = !spaceDown;
|
||||||
els.badge.textContent = spaceDown ? "原图" : "矢量预览";
|
els.badge.textContent = spaceDown ? "原图" : "矢量预览";
|
||||||
}
|
}
|
||||||
|
const ZOOM_MIN = 0.2;
|
||||||
|
const ZOOM_MAX = 8;
|
||||||
|
function applyView() {
|
||||||
|
if (!els || !els.preview) return;
|
||||||
|
els.preview.style.setProperty("--vz-zoom", String(zoom));
|
||||||
|
els.preview.style.setProperty("--vz-pan-x", panX + "px");
|
||||||
|
els.preview.style.setProperty("--vz-pan-y", panY + "px");
|
||||||
|
const changed = zoom !== 1 || panX !== 0 || panY !== 0;
|
||||||
|
if (els.zoomVal) els.zoomVal.textContent = Math.round(zoom * 100) + "%";
|
||||||
|
if (els.zoomChip) els.zoomChip.hidden = !changed;
|
||||||
|
}
|
||||||
|
function resetView() {
|
||||||
|
zoom = 1;
|
||||||
|
panX = 0;
|
||||||
|
panY = 0;
|
||||||
|
drag = null;
|
||||||
|
if (els && els.preview) els.preview.classList.remove("is-panning");
|
||||||
|
applyView();
|
||||||
|
}
|
||||||
|
function zoomAt(clientX, clientY, factor) {
|
||||||
|
if (!els || !els.preview) return;
|
||||||
|
const next = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, zoom * factor));
|
||||||
|
if (Math.abs(next - zoom) < 1e-4) return;
|
||||||
|
const rect = els.preview.getBoundingClientRect();
|
||||||
|
const dx = (clientX - (rect.left + rect.width / 2) - panX) / zoom;
|
||||||
|
const dy = (clientY - (rect.top + rect.height / 2) - panY) / zoom;
|
||||||
|
panX -= dx * (next - zoom);
|
||||||
|
panY -= dy * (next - zoom);
|
||||||
|
zoom = next;
|
||||||
|
applyView();
|
||||||
|
}
|
||||||
|
function zoomAtCenter(factor) {
|
||||||
|
if (!els || !els.preview) return;
|
||||||
|
const rect = els.preview.getBoundingClientRect();
|
||||||
|
zoomAt(rect.left + rect.width / 2, rect.top + rect.height / 2, factor);
|
||||||
|
}
|
||||||
|
function onPreviewWheel(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) {
|
||||||
|
panX += event.deltaX;
|
||||||
|
applyView();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!event.deltaY) return;
|
||||||
|
const step = event.ctrlKey ? 0.01 : Math.abs(event.deltaY) >= 40 ? 18e-4 : 0.012;
|
||||||
|
zoomAt(event.clientX, event.clientY, Math.exp(-event.deltaY * step));
|
||||||
|
}
|
||||||
|
function onPreviewPointerDown(event) {
|
||||||
|
if (!els || !els.preview) return;
|
||||||
|
if (event.button !== 0 && event.button !== 1) return;
|
||||||
|
if (event.target.closest(".vz-zoom")) return;
|
||||||
|
event.preventDefault();
|
||||||
|
drag = { x: event.clientX, y: event.clientY, panX, panY, id: event.pointerId };
|
||||||
|
els.preview.classList.add("is-panning");
|
||||||
|
try {
|
||||||
|
els.preview.setPointerCapture(event.pointerId);
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function onPreviewPointerMove(event) {
|
||||||
|
if (!drag || !els || !els.preview || event.pointerId !== drag.id) return;
|
||||||
|
panX = drag.panX + (event.clientX - drag.x);
|
||||||
|
panY = drag.panY + (event.clientY - drag.y);
|
||||||
|
applyView();
|
||||||
|
}
|
||||||
|
function onPreviewPointerUp(event) {
|
||||||
|
if (!drag) return;
|
||||||
|
if (event && event.pointerId !== void 0 && event.pointerId !== drag.id) return;
|
||||||
|
if (els && els.preview) {
|
||||||
|
els.preview.classList.remove("is-panning");
|
||||||
|
try {
|
||||||
|
els.preview.releasePointerCapture(drag.id);
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drag = null;
|
||||||
|
}
|
||||||
|
function onPreviewDblClick(event) {
|
||||||
|
if (event.target.closest(".vz-zoom")) return;
|
||||||
|
resetView();
|
||||||
|
}
|
||||||
function retrace() {
|
function retrace() {
|
||||||
if (!source) return;
|
if (!source) return;
|
||||||
const ticket = ++seq;
|
const ticket = ++seq;
|
||||||
@@ -3409,6 +3540,24 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
close();
|
close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const keyTag = event.target && event.target.tagName || "";
|
||||||
|
if (keyTag !== "INPUT" && keyTag !== "TEXTAREA" && keyTag !== "SELECT") {
|
||||||
|
if (event.key === "0") {
|
||||||
|
event.preventDefault();
|
||||||
|
resetView();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key === "+" || event.key === "=") {
|
||||||
|
event.preventDefault();
|
||||||
|
zoomAtCenter(1.25);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key === "-" || event.key === "_") {
|
||||||
|
event.preventDefault();
|
||||||
|
zoomAtCenter(0.8);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (event.code === "Space" && !spaceDown && !event.repeat) {
|
if (event.code === "Space" && !spaceDown && !event.repeat) {
|
||||||
const tag = event.target && event.target.tagName || "";
|
const tag = event.target && event.target.tagName || "";
|
||||||
if (tag === "INPUT" || tag === "TEXTAREA") return;
|
if (tag === "INPUT" || tag === "TEXTAREA") return;
|
||||||
@@ -3440,6 +3589,10 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
const node = root;
|
const node = root;
|
||||||
root = null;
|
root = null;
|
||||||
els = null;
|
els = null;
|
||||||
|
zoom = 1;
|
||||||
|
panX = 0;
|
||||||
|
panY = 0;
|
||||||
|
drag = null;
|
||||||
node.remove();
|
node.remove();
|
||||||
if (typeof onClose === "function") onClose();
|
if (typeof onClose === "function") onClose();
|
||||||
}
|
}
|
||||||
@@ -3465,6 +3618,8 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
vector: root.querySelector('[data-stage="vector"]'),
|
vector: root.querySelector('[data-stage="vector"]'),
|
||||||
original: root.querySelector('[data-stage="original"]'),
|
original: root.querySelector('[data-stage="original"]'),
|
||||||
badge: root.querySelector("[data-badge]"),
|
badge: root.querySelector("[data-badge]"),
|
||||||
|
zoomChip: root.querySelector("[data-zoom-chip]"),
|
||||||
|
zoomVal: root.querySelector("[data-zoom-val]"),
|
||||||
status: root.querySelector("[data-status]"),
|
status: root.querySelector("[data-status]"),
|
||||||
statusText: root.querySelector("[data-status-text]"),
|
statusText: root.querySelector("[data-status-text]"),
|
||||||
meta: root.querySelector("[data-meta]")
|
meta: root.querySelector("[data-meta]")
|
||||||
@@ -3473,6 +3628,16 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
els.meta.textContent = name + " · " + source.srcW + "×" + source.srcH;
|
els.meta.textContent = name + " · " + source.srcW + "×" + source.srcH;
|
||||||
els.panel.innerHTML = panelHTML(params, preset, outScale, advOpen);
|
els.panel.innerHTML = panelHTML(params, preset, outScale, advOpen);
|
||||||
root.addEventListener("click", onRootClick);
|
root.addEventListener("click", onRootClick);
|
||||||
|
els.preview.addEventListener("wheel", onPreviewWheel, { passive: false });
|
||||||
|
els.preview.addEventListener("pointerdown", onPreviewPointerDown);
|
||||||
|
els.preview.addEventListener("pointermove", onPreviewPointerMove);
|
||||||
|
els.preview.addEventListener("pointerup", onPreviewPointerUp);
|
||||||
|
els.preview.addEventListener("pointercancel", onPreviewPointerUp);
|
||||||
|
els.preview.addEventListener("lostpointercapture", onPreviewPointerUp);
|
||||||
|
els.preview.addEventListener("dblclick", onPreviewDblClick);
|
||||||
|
els.preview.addEventListener("click", function(event) {
|
||||||
|
if (event.target.closest(".vz-zoom")) resetView();
|
||||||
|
});
|
||||||
els.panel.addEventListener("input", onPanelInput);
|
els.panel.addEventListener("input", onPanelInput);
|
||||||
els.panel.addEventListener("click", onPanelClick);
|
els.panel.addEventListener("click", onPanelClick);
|
||||||
document.addEventListener("keydown", onKeyDown, true);
|
document.addEventListener("keydown", onKeyDown, true);
|
||||||
@@ -3480,6 +3645,7 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
window.addEventListener("blur", onBlur);
|
window.addEventListener("blur", onBlur);
|
||||||
syncControls();
|
syncControls();
|
||||||
setStats(null);
|
setStats(null);
|
||||||
|
resetView();
|
||||||
retrace();
|
retrace();
|
||||||
return { close };
|
return { close };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,6 +139,15 @@ check('样式注入生效(CSP unsafe-inline)', await page.evaluate(() => {
|
|||||||
return Boolean(s && s.textContent.indexOf('.vz-') >= 0)
|
return Boolean(s && s.textContent.indexOf('.vz-') >= 0)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// 用户 2026-11-09:取消与保存为节点互换,四颗按钮同一套描边配色(绿色主按钮已去掉)。
|
||||||
|
// 这条同时是「线上真的是新版」的活体证据 —— 光看版本号挡不住产物没重建。
|
||||||
|
check('顶栏顺序 保存为节点→复制→下载→取消,四颗同色', await page.evaluate(() => {
|
||||||
|
const btns = [...document.querySelectorAll('.vz-header .vz-btn')]
|
||||||
|
if (btns.map((b) => b.dataset.act).join(',') !== 'save,copy,svg,cancel') return false
|
||||||
|
const colors = new Set(btns.map((b) => getComputedStyle(b).backgroundColor + '|' + getComputedStyle(b).color))
|
||||||
|
return colors.size === 1
|
||||||
|
}))
|
||||||
|
|
||||||
// ---------- 5) 真站 CSP 下引擎能跑 ----------
|
// ---------- 5) 真站 CSP 下引擎能跑 ----------
|
||||||
const paths = await poll(async () => {
|
const paths = await poll(async () => {
|
||||||
// 统计项是「元素」,合并模式下会带后缀「(N 孤岛合并)」,只取前面的数字
|
// 统计项是「元素」,合并模式下会带后缀「(N 孤岛合并)」,只取前面的数字
|
||||||
@@ -184,6 +193,45 @@ check('「填充 / 背景」两个色块并排在同一行', await page.evaluate
|
|||||||
return Math.abs(ra.top - rb.top) < 2 && rb.left > ra.right - 1
|
return Math.abs(ra.top - rb.top) < 2 && rb.left > ra.right - 1
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// v0.4.0:预览缩放 / 平移(真站上鼠标手势得真能走通,不能只信本地合成宿主)
|
||||||
|
const pvBox = await page.locator('.vz-preview').boundingBox()
|
||||||
|
await page.mouse.move(pvBox.x + pvBox.width / 2 + 40, pvBox.y + pvBox.height / 2 - 20)
|
||||||
|
await page.mouse.wheel(0, -300)
|
||||||
|
await sleep(220)
|
||||||
|
// 断言「换算比例」而不是「比容器大」:正方形图 fit 进宽屏预览后本来就比容器窄,
|
||||||
|
// 拿 rect.width > clientWidth 会比较,放大了也可能不成立(实测真站 549 vs 1011)
|
||||||
|
check('滚轮放大预览、倍率胶囊出现', await page.evaluate(() => {
|
||||||
|
const p = document.querySelector('.vz-preview')
|
||||||
|
const v = document.querySelector('[data-stage="vector"]')
|
||||||
|
const z = Number(p.style.getPropertyValue('--vz-zoom') || 1)
|
||||||
|
const chip = document.querySelector('[data-zoom-chip]')
|
||||||
|
const ratio = v.getBoundingClientRect().width / v.clientWidth
|
||||||
|
return z > 1.1 && Boolean(chip) && !chip.hidden && Math.abs(ratio - z) < 0.02
|
||||||
|
}))
|
||||||
|
await page.mouse.dblclick(pvBox.x + pvBox.width / 2, pvBox.y + pvBox.height / 2)
|
||||||
|
await sleep(220)
|
||||||
|
check('双击复位回 100%', await page.evaluate(() => {
|
||||||
|
const p = document.querySelector('.vz-preview')
|
||||||
|
return Number(p.style.getPropertyValue('--vz-zoom') || 1) === 1
|
||||||
|
}))
|
||||||
|
|
||||||
|
// 回归:平滑滚轮(小数 deltaY)在真站也必须缩放。旧逻辑靠整数步长识别鼠标,会把这类滚轮当平移。
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const p = document.querySelector('.vz-preview')
|
||||||
|
const r = p.getBoundingClientRect()
|
||||||
|
p.dispatchEvent(new WheelEvent('wheel', {
|
||||||
|
deltaY: -12.5, deltaMode: 0, bubbles: true, cancelable: true,
|
||||||
|
clientX: r.left + r.width / 2, clientY: r.top + r.height / 2,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
await sleep(160)
|
||||||
|
check('真站:小数步长滚轮照样放大', await page.evaluate(() => {
|
||||||
|
const p = document.querySelector('.vz-preview')
|
||||||
|
return Number(p.style.getPropertyValue('--vz-zoom') || 1) > 1.001
|
||||||
|
}))
|
||||||
|
await page.mouse.dblclick(pvBox.x + pvBox.width / 2, pvBox.y + pvBox.height / 2)
|
||||||
|
await sleep(160)
|
||||||
|
|
||||||
// ---------- 5.6) 复制到剪贴板(真写,读回校验口味) ----------
|
// ---------- 5.6) 复制到剪贴板(真写,读回校验口味) ----------
|
||||||
await page.locator('[data-act="copy"]').click()
|
await page.locator('[data-act="copy"]').click()
|
||||||
await sleep(400)
|
await sleep(400)
|
||||||
|
|||||||
@@ -153,6 +153,15 @@ check('模态打开:预览区 + 参数面板 + 四个动作按钮齐全', awai
|
|||||||
document.querySelector('[data-act="save"]') && document.querySelector('[data-act="svg"]') &&
|
document.querySelector('[data-act="save"]') && document.querySelector('[data-act="svg"]') &&
|
||||||
document.querySelector('[data-act="copy"]') && document.querySelector('[data-act="cancel"]'))))
|
document.querySelector('[data-act="copy"]') && document.querySelector('[data-act="cancel"]'))))
|
||||||
|
|
||||||
|
// 用户 2026-11-09:顶栏「取消」与「保存为节点」互换(主操作在左、取消在最右),
|
||||||
|
// 且不再给主操作上绿色 —— 四颗按钮用同一套描边配色。
|
||||||
|
check('顶栏顺序:保存为节点 → 复制 → 下载 → 取消,且四颗同色', await page.evaluate(() => {
|
||||||
|
const btns = [...document.querySelectorAll('.vz-header .vz-btn')]
|
||||||
|
if (btns.map((b) => b.dataset.act).join(',') !== 'save,copy,svg,cancel') return false
|
||||||
|
const colors = new Set(btns.map((b) => getComputedStyle(b).backgroundColor + '|' + getComputedStyle(b).color))
|
||||||
|
return colors.size === 1
|
||||||
|
}))
|
||||||
|
|
||||||
// 高级参数默认展开:用户 2026-11-05 明确要求「不用隐藏」(低频项也一眼能看到)
|
// 高级参数默认展开:用户 2026-11-05 明确要求「不用隐藏」(低频项也一眼能看到)
|
||||||
check('高级参数默认展开', await page.evaluate(() => {
|
check('高级参数默认展开', await page.evaluate(() => {
|
||||||
const box = document.querySelector('[data-adv]')
|
const box = document.querySelector('[data-adv]')
|
||||||
@@ -186,6 +195,87 @@ check('预览区白底、无棋盘格', await page.evaluate(() => {
|
|||||||
return lum > 240 && cs.backgroundImage === 'none'
|
return lum > 240 && cs.backgroundImage === 'none'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// ---------- 预览视图:缩放 / 平移(2026-11-09 用户需求) ----------
|
||||||
|
const viewState = () => page.evaluate(() => {
|
||||||
|
const p = document.querySelector('[data-preview]')
|
||||||
|
return {
|
||||||
|
zoom: Number(p.style.getPropertyValue('--vz-zoom') || 1),
|
||||||
|
panX: parseFloat(p.style.getPropertyValue('--vz-pan-x') || '0'),
|
||||||
|
panY: parseFloat(p.style.getPropertyValue('--vz-pan-y') || '0'),
|
||||||
|
chip: !document.querySelector('[data-zoom-chip]').hidden,
|
||||||
|
label: document.querySelector('[data-zoom-val]').textContent,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const fit = await viewState()
|
||||||
|
check('默认等比铺满(100%),倍率胶囊不出现', fit.zoom === 1 && fit.panX === 0 && fit.panY === 0 && !fit.chip)
|
||||||
|
|
||||||
|
const pv = await page.locator('[data-preview]').boundingBox()
|
||||||
|
const cx = pv.x + pv.width / 2
|
||||||
|
const cy = pv.y + pv.height / 2
|
||||||
|
// 鼠标刻意偏离中心,用来验证「以光标为锚点」而不是「以中心缩放」
|
||||||
|
await page.mouse.move(cx + 60, cy - 40)
|
||||||
|
await page.mouse.wheel(0, -300)
|
||||||
|
await sleep(140)
|
||||||
|
const zoomed = await viewState()
|
||||||
|
check('滚轮向上放大', zoomed.zoom > 1.1 && zoomed.chip, 'zoom=' + zoomed.zoom)
|
||||||
|
check('缩放锚在光标处(偏离中心缩放会带动平移)',
|
||||||
|
Math.abs(zoomed.panX) > 1 || Math.abs(zoomed.panY) > 1,
|
||||||
|
'pan=' + zoomed.panX.toFixed(1) + ',' + zoomed.panY.toFixed(1))
|
||||||
|
check('倍率胶囊显示当前百分比', /^\d+%$/.test(zoomed.label) && zoomed.label !== '100%', zoomed.label)
|
||||||
|
|
||||||
|
await page.mouse.move(cx, cy)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(cx + 50, cy + 30, { steps: 6 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await sleep(140)
|
||||||
|
const panned = await viewState()
|
||||||
|
check('拖动平移(位移跟手,1:1 不缩放)',
|
||||||
|
Math.abs(panned.panX - zoomed.panX - 50) < 3 && Math.abs(panned.panY - zoomed.panY - 30) < 3,
|
||||||
|
'pan=' + panned.panX.toFixed(1) + ',' + panned.panY.toFixed(1))
|
||||||
|
// 开发用:VZ_SHOT=/tmp/vz-zoom.png 出一张「放大 + 平移」状态的截图
|
||||||
|
if (process.env.VZ_SHOT) await page.locator('.vz-modal').screenshot({ path: process.env.VZ_SHOT })
|
||||||
|
|
||||||
|
await page.mouse.dblclick(cx, cy)
|
||||||
|
await sleep(140)
|
||||||
|
const reset = await viewState()
|
||||||
|
check('双击复位回 100% 且胶囊消失',
|
||||||
|
reset.zoom === 1 && reset.panX === 0 && reset.panY === 0 && !reset.chip)
|
||||||
|
|
||||||
|
// 回归:滚轮必须无条件缩放。早先靠「deltaY 是 ±100 整数」识别鼠标滚轮,
|
||||||
|
// 平滑滚动/高精度滚轮给小数步长时会被判成触控板滑动 → 退化成平移,用户看到「滚轮不放大」。
|
||||||
|
const wheelBy = (deltaY, deltaX) => page.evaluate(([dy, dx]) => {
|
||||||
|
const p = document.querySelector('[data-preview]')
|
||||||
|
const r = p.getBoundingClientRect()
|
||||||
|
p.dispatchEvent(new WheelEvent('wheel', {
|
||||||
|
deltaY: dy, deltaX: dx, deltaMode: 0, bubbles: true, cancelable: true,
|
||||||
|
clientX: r.left + r.width / 2, clientY: r.top + r.height / 2,
|
||||||
|
}))
|
||||||
|
}, [deltaY, deltaX])
|
||||||
|
await wheelBy(-12.5, 0) // 小数步长 = 平滑滚轮 / 触控板
|
||||||
|
await sleep(90)
|
||||||
|
const smooth = await viewState()
|
||||||
|
check('滚轮给小数步长也缩放(不被误判成触控板滑动)', smooth.zoom > 1.001, 'zoom=' + smooth.zoom)
|
||||||
|
await wheelBy(0, -60) // 纯水平滚动(Shift+滚轮在 Chrome 里就是这种)
|
||||||
|
await sleep(90)
|
||||||
|
const horiz = await viewState()
|
||||||
|
check('水平滚动只平移、不改倍率', horiz.zoom === smooth.zoom && Math.abs(horiz.panX - smooth.panX) > 20,
|
||||||
|
'panX=' + horiz.panX.toFixed(1))
|
||||||
|
|
||||||
|
await page.mouse.dblclick(cx, cy)
|
||||||
|
await sleep(120)
|
||||||
|
await page.mouse.move(cx, cy)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(cx + 40, cy + 20, { steps: 5 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await sleep(90)
|
||||||
|
const dragAt1x = await viewState()
|
||||||
|
check('100% 状态左键也能拖图(不要求先放大)',
|
||||||
|
dragAt1x.zoom === 1 && Math.abs(dragAt1x.panX - 40) < 3 && Math.abs(dragAt1x.panY - 20) < 3,
|
||||||
|
'pan=' + dragAt1x.panX.toFixed(1) + ',' + dragAt1x.panY.toFixed(1))
|
||||||
|
|
||||||
|
await page.mouse.dblclick(cx, cy)
|
||||||
|
await sleep(120)
|
||||||
|
|
||||||
const monoPaths = Number(await pathsNow(page))
|
const monoPaths = Number(await pathsNow(page))
|
||||||
const monoMs = Number((await page.locator('[data-stat="ms"]').textContent()).replace(/[^\d]/g, ''))
|
const monoMs = Number((await page.locator('[data-stat="ms"]').textContent()).replace(/[^\d]/g, ''))
|
||||||
check('单色描摹产出元素(文字图形都在)', monoPaths >= 1 && monoPaths <= 80, 'elements=' + monoPaths)
|
check('单色描摹产出元素(文字图形都在)', monoPaths >= 1 && monoPaths <= 80, 'elements=' + monoPaths)
|
||||||
@@ -335,8 +425,9 @@ await page.evaluate(() => {
|
|||||||
})
|
})
|
||||||
await sleep(400)
|
await sleep(400)
|
||||||
check('改单色填充色写进 SVG', await page.evaluate(() => /#c0392b/i.test(window.__lastSvg || '')), '')
|
check('改单色填充色写进 SVG', await page.evaluate(() => /#c0392b/i.test(window.__lastSvg || '')), '')
|
||||||
// 开发用:VZ_SHOT=/tmp/vz-panel.png 出一张面板截图(验证「填充 / 背景」这排没挤坏布局)
|
// 开发用:VZ_SHOT_PANEL=/tmp/vz-panel.png 出一张面板截图(验证「填充 / 背景」这排没挤坏布局)
|
||||||
if (process.env.VZ_SHOT) await page.locator('.vz-modal').screenshot({ path: process.env.VZ_SHOT })
|
// ⚠️ 别和上面的 VZ_SHOT 共用同一个变量 —— 两处都写同一路径时,后一张会把前一张覆盖掉
|
||||||
|
if (process.env.VZ_SHOT_PANEL) await page.locator('.vz-modal').screenshot({ path: process.env.VZ_SHOT_PANEL })
|
||||||
|
|
||||||
// ---------- 背景色 / 带底(v0.3.1) ----------
|
// ---------- 背景色 / 带底(v0.3.1) ----------
|
||||||
const setBg = async (hex) => {
|
const setBg = async (hex) => {
|
||||||
@@ -432,6 +523,14 @@ check('重新打开沿用上次参数(mode=mono、颜色 #c0392b)', await pa
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
// ---------- 空格对比 / Esc ----------
|
// ---------- 空格对比 / Esc ----------
|
||||||
|
// 先缩放到非 1x:验证「按住空格切原图时视图不跳」—— 两张 img 共用同一套变量才做得到。
|
||||||
|
// 注意不能拿 vector 的 computed transform 跟 original 比:display:none 的元素 compute 出来是 none。
|
||||||
|
const pv2 = await page.locator('[data-preview]').boundingBox()
|
||||||
|
await page.mouse.move(pv2.x + pv2.width / 2, pv2.y + pv2.height / 2)
|
||||||
|
await page.mouse.wheel(0, -300)
|
||||||
|
await sleep(150)
|
||||||
|
const viewBefore = await page.evaluate(() =>
|
||||||
|
getComputedStyle(document.querySelector('[data-stage="vector"]')).transform)
|
||||||
await page.evaluate(() => document.body.focus())
|
await page.evaluate(() => document.body.focus())
|
||||||
await page.keyboard.down('Space')
|
await page.keyboard.down('Space')
|
||||||
await sleep(150)
|
await sleep(150)
|
||||||
@@ -439,6 +538,16 @@ check('按住空格对比原图', await page.evaluate(() => {
|
|||||||
const o = document.querySelector('[data-stage="original"]')
|
const o = document.querySelector('[data-stage="original"]')
|
||||||
return Boolean(o && !o.hidden)
|
return Boolean(o && !o.hidden)
|
||||||
}))
|
}))
|
||||||
|
const spaceCmp = await page.evaluate(() => {
|
||||||
|
const p = document.querySelector('[data-preview]')
|
||||||
|
return {
|
||||||
|
z: Number(p.style.getPropertyValue('--vz-zoom') || 1),
|
||||||
|
t: getComputedStyle(document.querySelector('[data-stage="original"]')).transform,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('缩放状态下切原图,视图完全不跳(两图共用变量)',
|
||||||
|
spaceCmp.z > 1 && spaceCmp.t === viewBefore,
|
||||||
|
'zoom=' + spaceCmp.z.toFixed(2) + ' ' + spaceCmp.t + ' vs ' + viewBefore)
|
||||||
await page.keyboard.up('Space')
|
await page.keyboard.up('Space')
|
||||||
await sleep(120)
|
await sleep(120)
|
||||||
check('松开空格回到矢量', await page.evaluate(() => {
|
check('松开空格回到矢量', await page.evaluate(() => {
|
||||||
|
|||||||
Reference in new issue
Block a user