Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdfb4ed603 | ||
|
|
929b7ec2a1 | ||
|
|
a94e5be954 | ||
|
|
b6d10339f6 | ||
|
|
89c8e0a1d8 | ||
|
|
9bbb94b789 | ||
|
|
6284f84d29 | ||
|
|
b299895730 | ||
|
|
32363d8c9b | ||
|
|
352a7668d7 | ||
|
|
3baa76d0cd | ||
|
|
a477705c7f | ||
|
|
6a14f900df | ||
|
|
e10ccee8ad | ||
|
|
240d02684a | ||
|
|
1dc423c025 |
No files matched your search
@@ -234,8 +234,303 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||
|
||||
## v1.19.0:右栏调色模块退场 / 头部一行装完 / 常用色 16 个 + 最近两排
|
||||
|
||||
用户一段话:「右边栏的调色模块就可以去掉了,然后还去一个去色按钮,可以放在钉住按钮的左边,
|
||||
用竖线分割,然后我希望最近色多几个…把吸色与色值数放在钉住按钮的一排,那下面的最近色就可以放两排了。
|
||||
后宽度可以再多一点点,就是让颜色按钮一排可以放 8 个,那你就需要多加 4 个常用色」。
|
||||
|
||||
**1) 右栏常驻调色面板删除。**
|
||||
色板现在只有工具栏弹层一处。v1.16 加它是因为「不想每次点开弹层」,但 v1.18 的钉住已经解决了同一件事——
|
||||
弹层钉住后本来就是一个常开的浮层,右栏那份是同样内容的第二个副本,还占着最显眼的位置。
|
||||
顺带少了一层「同一份 DOM 两套 CSS 布局」的分支,改色板不用再担心改了这头没那头。
|
||||
|
||||
**2) 头部一行装完**:调色槽 │ 吸管 + 色值 │ 去色 │ 图钉
|
||||
|
||||
```
|
||||
[描边●][填充●] │ ⌖ [ #FFD400 ] │ [⊘ 去色] │ 📌
|
||||
```
|
||||
|
||||
- 吸管与色值从右列搬到头部,body 的整块高度都留给色块 —— 这是「最近色能放两排」的前提。
|
||||
- 「无」改名**去色**,挪到图钉左边、用 1px 竖线隔开:调色时「这一项不上色」和「钉住」都是随手要按的开关。
|
||||
对描边/填充/底色都生效,title 随当前槽变。
|
||||
- 没有可去色的上下文(没选中对象、文字色这种单槽)时它本来就隐藏,**它前面那条竖线跟着一起藏**
|
||||
(`:has(> .iwb-color-pop-none[hidden])`),否则头部右侧会留一截悬空的「||」。
|
||||
- 「去色 | 图钉」整组用 `margin-left: auto` 贴最右,色值框固定 150px 不被拉成长条
|
||||
(拉长后视觉重心全跑到输入框上,色块反倒成了配角)。tab 加 `flex: 0 0 auto; white-space: nowrap`——
|
||||
宽度不够时该缩的是色值框,不是把「描边」压成竖排两个字。
|
||||
|
||||
**3) 色块 8 列 × 2 行,常用色 12 → 16,最近色 6 → 16。**
|
||||
|
||||
第一行是 8 个饱和亮色,第二行是 4 个中性色 + 4 个同色系「深一档」:
|
||||
|
||||
```
|
||||
亮:#ff4444 #ff8a00 #ffd400 #4cd964 #00bfa5 #4488ff #aa44ff #ff66aa
|
||||
常:#ffffff #d0d0d0 #808080 #000000 #c0392b #0f9d58 #1677ff #6b4fbb
|
||||
```
|
||||
|
||||
加的那 4 个(深红/深绿/深蓝/深紫)在浅色底图上比亮色稳,做描边不刺眼。色块 18 → 20px。
|
||||
弹层 **380×153 → 440×157**(宽度 +16%,高度只 +4px —— 多出来的一排被「吸管+色值上移」抵掉了)。
|
||||
|
||||
两个刻意的决定:
|
||||
|
||||
- **弹层宽度写死 440px**。绝对定位元素是 shrink-to-fit,宽度会跟着最长内容走:
|
||||
文字工具多出「底色」tab 时头部变宽,弹层当场变宽 17px 再跳回来,定位还得重算。
|
||||
- **分隔线从 `#313244` 提到 `#3b3b4e`**。没有小标题时,这条线是唯一能看出「常用 / 最近」分界的东西,
|
||||
按原色画在深底上几乎看不见。
|
||||
|
||||
**验证**:harness 229 项、真站 e2e 见下。新增 harness 断言:头部四个控件同一水平线 + 去色在图钉左边 +
|
||||
两者之间有竖线 + 三 tab(文字工具)时头部不横向溢出、常用色 16 个严格 8 列 2 行、最近色网格 8 列 2 排、
|
||||
弹层宽高区间、右栏第一个模块是「图片调节」且无 `[data-color-surface]`。
|
||||
|
||||
## 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:修「换一张图调节,画面还原成上一张」
|
||||
|
||||
### 病灶
|
||||
|
||||
原图图层的 id 是**写死的 `'base'`**,而 `adjust.js` 里「调节前基准像素」的缓存
|
||||
`sourceCache` 以 `layer.id` 为 key。退出编辑器走 `releaseEditorMemory()`,
|
||||
它释放了图层画布与 `S.fx`,却**漏了 `sourceCache` 和 `S.adjust`** ——
|
||||
于是第二张图打开后 `captureFor('base')` 直接命中上一张图的像素,
|
||||
一拖滑杆就把旧图重算到新图上。id 固定 ⇒ 100% 复现,不是偶发。
|
||||
|
||||
同一个疏漏还有第二层:`S.adjust.layerId` 残留 `'base'` 且 `source` 非空时,
|
||||
`ensureAdjustTarget()` 认为「目标没变,不用重拍基准」,连 `switchTarget()` 都跳过。
|
||||
|
||||
### 修法
|
||||
|
||||
新增 `adjust.js#resetAdjustCache()`:清空 `sourceCache` + 把 `S.adjust` 归零。
|
||||
两处调用,**开与关都兜住**:
|
||||
|
||||
- `resetState()`(每次 `open()`)—— 防住「关闭路径没走到/提前抛错」的边缘;
|
||||
- `releaseEditorMemory()`(`close()`)—— 立即释放两份全幅位图,不等下次打开。
|
||||
|
||||
`__debug()` 增加 `adjustCacheSize` 观测口,回归用例如实断言「退出后为 0」。
|
||||
|
||||
### 回归
|
||||
|
||||
harness 新增 Round 3:退出前确认 `adjustCacheSize > 0`(前置)→ 退出 → 重开 →
|
||||
断言 `cache === 0 && layerId === null && hasSource === false` → 重开后曝光 +100
|
||||
仍正常提亮(亮度 177 → 241),证明用的是新图基准。
|
||||
|
||||
## v1.15.0:右侧栏「图片调节」11 项 + 快速效果强度修正
|
||||
|
||||
需求:在右侧栏加基本的图片调节能力(曝光/明度/对比度/阴影/高光/色相/饱和度/白平衡/锐度/清晰度),
|
||||
同时「现在的效果弱了一些」。
|
||||
|
||||
### 图片调节面板
|
||||
|
||||
右侧栏「快速效果」上方新增「图片调节」,作用于**当前位图图层**(默认原图),顶部实时显示层名:
|
||||
|
||||
| 项 | 范围 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| 曝光 | ±100 | ±2 档(×4 / ÷4),线性乘 |
|
||||
| 明度 | ±100 | 整体加减,±45% 亮度 |
|
||||
| 对比度 | ±100 | 绕 0.5 中灰缩放,-100 全灰、+100 两倍 |
|
||||
| 阴影 | ±100 | 按 (1-亮度)² 软蒙版提亮/压暗暗部 |
|
||||
| 高光 | ±100 | 按 亮度² 软蒙版压暗/提亮亮部 |
|
||||
| 色相 | ±180° | RGB 绕亮度轴旋转(与 CSS hue-rotate 同系数) |
|
||||
| 饱和度 | ±100 | 向亮度插值,-100 = 完全去色 |
|
||||
| 温度 | ±100 | 白平衡:R/B 通道反向增益(暖/冷) |
|
||||
| 色调 | ±100 | 白平衡:偏品红 / 偏绿 |
|
||||
| 锐度 | 0~100 | USM,1px 半径,找边缘 |
|
||||
| 清晰度 | ±100 | USM 大半径低强度,找中间调体积感;负值 = 柔化 |
|
||||
|
||||
操作:拖滑杆实时预览、松手出精细结果;双击名称或滑杆归零;右上「复位」全部归零。
|
||||
`Ctrl+Z` 可撤销,撤销后滑块同步归零(调整写在像素上,基准变了就不能留旧参数)。
|
||||
|
||||
### 为什么不用 CSS filter
|
||||
|
||||
`ctx.filter` 只有 brightness/contrast/saturate/hue-rotate/blur,做不到阴影/高光(要按亮度分区)、
|
||||
白平衡(要通道分别增益)、锐化(要卷积)。所以走 `getImageData` 逐像素处理。
|
||||
|
||||
代价是耗时随像素线性增长(实测):
|
||||
|
||||
| 边长 | 像素 | 全量耗时 |
|
||||
| --- | --- | --- |
|
||||
| 800² | 0.6M | 6.7 ms |
|
||||
| 1200² | 1.4M | 12.8 ms |
|
||||
| 2000² | 4.0M | 36.8 ms |
|
||||
| 4000² | 16M | 144.6 ms |
|
||||
|
||||
因此拖动时用「降采样预览」(长边 ≤900 的副本反复算),松手才用原尺寸算一次。
|
||||
预览与全量在亮度上完全一致(实测 241 vs 241),差别只在放大后的细节锐度。
|
||||
|
||||
### 两个必须守住的坑
|
||||
|
||||
1. **不能叠加**:`source` 存「开始调节前」的像素,每次参数变化都从它重算。否则来回拖滑杆
|
||||
会层层累积(effects.js 里同样记过)。每层的基准另存 `sourceCache`,切层往返也不会拿
|
||||
「调过的像素」当新基准。
|
||||
2. **撤销后必须归零**:历史只存像素快照、不存调节基准。撤销把像素还原了而滑块还停在 +80,
|
||||
再拖一次就会从错误基准重算,等于调两遍。规则:撤销一步 = 调整作废、滑块归零、基准重拍。
|
||||
|
||||
### 快速效果强度修正
|
||||
|
||||
「增强」原来拉满只有 `brightness(1.12) contrast(1.1) saturate(1.06)` —— 截图对比几乎看不出变化,
|
||||
这正是「效果弱」的来源。改为 `brightness(1.4) contrast(1.25) saturate(1.2)`;
|
||||
「高对比」的 contrast 从 1.4 提到 1.6。再往上会把高光直接切掉,不建议。
|
||||
|
||||
回归:harness 199 → 208 全通,新增 9 条(面板 11 项 / 曝光提亮 / 饱和度去色 / 温度偏暖 /
|
||||
复位还原 / 一次拖动一步历史 / 撤销归零 / 切层跟随与参数恢复)。
|
||||
|
||||
## v1.14.1:修「点一下字体下拉,字体就被打回黑体」
|
||||
|
||||
v1.14.0 的字体下拉有个只有真人点得出来的 bug:**点开下拉(甚至不选任何项),选中文字的
|
||||
字体立刻变回黑体**;再选别的字体看着生效了,下次点开又变回去,观感就是「不能切换字体」。
|
||||
|
||||
### 根因
|
||||
|
||||
选项栏的 click 委托用 `closest('[data-opt-text]')` 判断「文字样式按钮」,而
|
||||
`<select data-opt-text="fontFamily">` 自己带这个属性 —— 点下拉时它被当成按钮处理:
|
||||
|
||||
```js
|
||||
applyTextStyle(textBtn.dataset.optText, textBtn.dataset.value, true)
|
||||
// <select> 没有 data-value → undefined
|
||||
// → applyTextStyle('fontFamily', undefined) → fontKeyOf 收敛成 'sans'
|
||||
```
|
||||
|
||||
`fontKeyOf` 的脏值收敛本来是防御措施,在这里反而把「没有值」当脏值静默改成了默认字体。
|
||||
|
||||
### 改法
|
||||
|
||||
- click 委托只认 `button[data-opt-text]`,并让 `select[data-opt-text]` 直接早退
|
||||
- `syncOptionBar()` 里遍历 active 态同样收紧为 `button[data-opt-text]`(select 没有 `data-value`,
|
||||
混进去永远不亮,也不该被当成开关)
|
||||
- change 处理后不再调 `syncOptionBar()`:那会整体重绘选项栏、把刚操作的下拉换成新节点,
|
||||
焦点丢失、连续切换字体要反复重点。字体只影响画布,不影响其他控件取值,没必要重绘
|
||||
|
||||
### 为什么 v1.14.0 的用例没抓到
|
||||
|
||||
回归用例用的是 `page.selectOption()`,它直接设值 + 派发 `change`,**绕过了 click**。
|
||||
真实用户必须先点开下拉,那一步才踩雷。已补两条用例:真实 `click()` 到下拉上之后字体必须不变、
|
||||
下拉节点不被重建。199 条全通。
|
||||
|
||||
## v1.14.0:文字可以选字体(黑 / 宋 / 楷 / 圆)
|
||||
|
||||
|
||||
|
||||
需求:「文字工具能不能选字体」。可以,而且成本很低 —— 但**只做了系统字体族**,没有内置字体文件,
|
||||
原因见下。
|
||||
|
||||
|
||||
@@ -311,6 +311,11 @@ getCompositeCanvas() // 当前这一张
|
||||
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
||||
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
||||
| 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.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.0:文字对象新增 `fontFamily`(预设 key:`sans` 黑体 / `serif` 宋体 / `kai` 楷体 / `round` 圆体),`fontOf()` 从硬编码 `sans-serif` 改为读 `TEXT_FONTS[key].stack` 的跨平台字体栈;选项栏加「字体」下拉(`select[data-opt-text]`,走 `change` 委托,其余文字样式仍走 `click`),复用 `TEXT_STYLE_STATE_KEY` 一条写回路径;输入框同步字体族与字重;`fontKeyOf()` 把脏值收敛回默认。**明确不做内置字体**:宿主 CSP `default-src 'self'` 拦第三方字体、CJK 字体 2–64MB 无法内联、异步字体有 measureText 时序坑。实测换字体仅首次多 13–42ms 字形光栅化,热重绘 0.1–0.2ms;中文全角等宽,换字体不改字宽(1000²/30 对象内存 114MB 属既有架构,与字体无关) |
|
||||
| 快捷键语义修正(v1.13.1) | ✅ v1.13.1:Shift+X 从「实心 ↔ 只描边」开关改成**交换填充色与描边色**(PS 的 X 语义)。旧行为下按一次填充被关掉、描边色不动,用户看到的就是「填充丢了」。新 `swapShapeColors()` 对调 `sh.color ⇄ sh.fillColor` 并同步 `S.color` / `S.shapeFillColor`,**填充开关不动**(交换颜色不改有无),箭头跳过、跟随态只提示,一步历史。实心/描边切换仍留在选项栏按钮上 |
|
||||
| 界面瘦身 / 快捷键 / 实时预览 / 图层解封 | ✅ v1.13.0:顶栏删掉四个层级按钮(`.iwb-editor-commands` 整块移除,`updateLayerUI()` / `bindLayerOrderButtons()` 一并清除);「适应窗口 / 收起侧栏」移到工具栏 DOM 末尾(shrink-to-fit 天然最右);快捷键 `R` 矩形 / `O` 圆形 / `L` 箭头(套索迁 `A`,`U` 保留),键盘处理改为优先匹配 `e.code` 以兼容中文输入法;原生 `<input type="color">` 补接 `input` 做实时预览(`skipHistory` + `nativeColorSnapped`,一次拖动仍只记 1 步撤销);原图不再钉底——`planPanelOrder` / `updateSortTarget` / `onSortEnd` / `moveLayer` / `mergeUnits` 五处解封,其他图层可拖到原图下方 |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/image-annotate",
|
||||
"private": true,
|
||||
"version": "1.14.0",
|
||||
"version": "1.19.0",
|
||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||
"ibwPlugin": {
|
||||
"id": "image-annotate",
|
||||
|
||||
@@ -232,6 +232,10 @@
|
||||
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 {
|
||||
background: #313244;
|
||||
border: none;
|
||||
@@ -273,7 +277,6 @@
|
||||
.iwb-editor-params .iwb-editor-zoom { margin-left: auto; order: 20; }
|
||||
.iwb-editor-top-colors { display: none; }
|
||||
|
||||
.iwb-editor-colors { display: flex; gap: 4px; }
|
||||
.iwb-editor-color {
|
||||
width: 20px; height: 20px;
|
||||
border-radius: 50%;
|
||||
@@ -1218,7 +1221,9 @@
|
||||
|
||||
/* 左栏:调色板在上,参数竖排,导出按钮底部 */
|
||||
.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;
|
||||
padding: 12px; background: #181825; border-right: 1px solid #313244; overflow-y: auto;
|
||||
}
|
||||
@@ -1322,7 +1327,7 @@
|
||||
.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-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; }
|
||||
|
||||
/* ======== 顶部布局 v5:左侧重置类 / 中间工具 / 右侧保存类 ======== */
|
||||
@@ -1529,7 +1534,7 @@
|
||||
}
|
||||
.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-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-left { display: none !important; }
|
||||
.iwb-editor-zoom-hint { display: none !important; }
|
||||
@@ -1781,17 +1786,36 @@
|
||||
|
||||
|
||||
.iwb-editor-color-pop {
|
||||
position: absolute; z-index: 60; display: flex; flex-direction: column; align-items: stretch; gap: 9px;
|
||||
padding: 10px 12px; border-radius: 12px;
|
||||
position: absolute; z-index: 60; display: flex; flex-direction: column; align-items: stretch; gap: 7px;
|
||||
/* 固定宽度(不是让内容撑):绝对定位元素是 shrink-to-fit,宽度会跟着最长内容走 ——
|
||||
文字工具多出「底色」tab 时头部变宽,弹层当场变宽 17px 再跳回来,定位也要重算。
|
||||
440 = 内容 416(SV 176 + 8 + 色相 16 + 10 + 1 + 10 + 色块 195)+ 左右 padding 22 + 边框 2。 */
|
||||
box-sizing: border-box; width: 440px;
|
||||
padding: 9px 11px; border-radius: 12px;
|
||||
background: rgba(24, 24, 37, 0.97); border: 1px solid #313244;
|
||||
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
|
||||
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
|
||||
}
|
||||
.iwb-editor-color-pop[hidden] { display: none; }
|
||||
/* 弹层头部:说明现在调的是描边还是填充,并可直接换;右侧是「无」(仅填充) */
|
||||
/* 弹层头部(v1.19 一行装完):
|
||||
调哪个槽(描边/填充/底色)│ 吸管 + 色值 │ 去色 │ 图钉
|
||||
原来「吸管 + 色值」在右列占一整块,现在提到头部,body 的整块高度都留给色块。 */
|
||||
.iwb-color-pop-head { display: flex; align-items: center; gap: 6px; }
|
||||
/* 竖线:分隔「调哪个槽 / 取色工具 / 去色·钉住」三组,比空白更清楚,又不加边框重量 */
|
||||
.iwb-color-pop-bar { width: 1px; height: 16px; background: #313244; flex: 0 0 auto; }
|
||||
/* 「去色 | 图钉」整组贴最右(margin-left:auto)。这样色值框不用拉成一条长条去填空,
|
||||
头部是「左边调色槽与工具 / 右边两个开关」两段式,扫视时不会把 HEX 当成主角。 */
|
||||
.iwb-color-pop-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
|
||||
/* 没有可去色的上下文(未选中对象 / 文字色这种单槽)时「去色」是隐藏的,
|
||||
它前面那条竖线要一起藏掉,否则头部右侧会留下一截悬空的「||」;
|
||||
两条都藏掉后整组只剩图钉,竖线也不再夹在「色值 | 图钉」之间显得多余 */
|
||||
.iwb-color-pop-tools:has(> .iwb-color-pop-none[hidden]) > .iwb-color-pop-bar { display: none; }
|
||||
|
||||
.iwb-color-pop-tab {
|
||||
display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
|
||||
/* 不许被压缩、不许折行:头部一行要同时装下 tab + 吸管 + 色值 + 去色 + 图钉,
|
||||
宽度不够时该缩的是色值框(flex:0 1),不是把「描边」压成竖排两个字 */
|
||||
flex: 0 0 auto; white-space: nowrap;
|
||||
border: 1px solid transparent; border-radius: 7px; background: #232334;
|
||||
color: #a6adc8; font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||
cursor: pointer;
|
||||
@@ -1808,41 +1832,81 @@
|
||||
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||
}
|
||||
.iwb-color-pop-tab[hidden] { display: none; }
|
||||
/* 去色(v1.19):原来的「无」改名挪位。虚线框 + 红斜圈,和「实心色块」区分开;
|
||||
它是开关不是色块,所以不用填充色表达状态,只换边框/文字色。 */
|
||||
.iwb-color-pop-none {
|
||||
margin-left: auto; display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
|
||||
flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px;
|
||||
border: 1px dashed #585b70; border-radius: 7px; background: transparent; color: #a6adc8;
|
||||
font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; cursor: pointer;
|
||||
}
|
||||
.iwb-color-pop-none span {
|
||||
width: 11px; height: 11px; border-radius: 3px; display: block; background-color: #45475a;
|
||||
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||
}
|
||||
.iwb-color-pop-none svg { flex: 0 0 auto; }
|
||||
.iwb-color-pop-none:hover { border-color: #f38ba8; color: #f38ba8; }
|
||||
.iwb-color-pop-none.active { border-style: solid; border-color: #f38ba8; color: #f38ba8; background: rgba(243, 139, 168, 0.12); }
|
||||
.iwb-color-pop-none[hidden] { display: none; }
|
||||
.iwb-color-pop-body { display: flex; align-items: center; gap: 10px; }
|
||||
.iwb-color-pop-body { display: flex; align-items: stretch; gap: 10px; }
|
||||
.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: 104px; flex: 0 0 176px; }
|
||||
.iwb-editor-color-pop .iwb-color-hue { width: 16px; height: 104px; flex: 0 0 16px; }
|
||||
.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.19,用户 2026-11-10)====
|
||||
常用色 8×2 在上、最近色 8×2 在下,块间 1px 细线,不写小标题。
|
||||
8 列 20px = 195px;两排色块(45 + 11 + 45 = 101)刚好填满左侧取色器 104 的高度,
|
||||
所以整个弹层只有头部 + 取色器两层,没有多余留白。 */
|
||||
.iwb-color-pop-side {
|
||||
display: flex; flex-direction: column; justify-content: center;
|
||||
width: 195px; flex: 0 0 195px; gap: 0;
|
||||
}
|
||||
/* 细线分隔:只加在「块与块之间」,第一块前面不加,否则顶部多一条悬空的线。
|
||||
色号比背景亮两档(#3b3b4e):没有小标题时,这条线是唯一能看出「常用 / 最近」分界的东西,
|
||||
按 #313244 画在深底上几乎看不见。 */
|
||||
.iwb-color-pop-side > * + * {
|
||||
border-top: 1px solid #3b3b4e; margin-top: 5px; padding-top: 5px;
|
||||
}
|
||||
.iwb-color-group { display: flex; flex-direction: column; gap: 0; min-width: 0; flex: 0 0 auto; }
|
||||
/* 标题不显示:「常用色 / 最近」各占一行是这块面板最浪费的高度,
|
||||
色块自己的 title 已经写明是哪一个、哪一个最近用过 */
|
||||
.iwb-editor-color-pop .iwb-color-group-label { display: none; }
|
||||
/* display:flex 会盖掉 [hidden] 的默认 display:none,必须显式写一条 */
|
||||
.iwb-color-group[hidden] { display: none; }
|
||||
|
||||
/* 色值输入固定 150px:够显示 #RRGGBB 还有余量,又不会被 flex-grow 拉成一条长条
|
||||
(拉长后视觉重心全跑到输入框上,色块反倒成了配角)。
|
||||
文字工具多出「底色」tab 时按 0 1 150 自动收缩,min-width 保证七个字符看得全。 */
|
||||
.iwb-editor-color-pop .iwb-editor-color-hex-input {
|
||||
width: 86px; height: 28px; padding: 0 6px; text-align: center;
|
||||
flex: 0 1 150px; width: 150px; min-width: 58px; height: 26px; padding: 0 5px; text-align: center;
|
||||
font: 600 12px monospace; border-radius: 6px; box-sizing: border-box;
|
||||
}
|
||||
.iwb-editor-color-pop .iwb-editor-color-swatches {
|
||||
display: grid; grid-template-columns: repeat(6, 22px); grid-auto-rows: 22px;
|
||||
gap: 7px; flex: 0 0 auto; align-content: center;
|
||||
display: grid; grid-template-columns: repeat(8, 20px); grid-auto-rows: 20px;
|
||||
gap: 5px; flex: 0 0 auto; align-content: center;
|
||||
}
|
||||
.iwb-editor-color-pop .iwb-editor-color-panel-swatch {
|
||||
width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
|
||||
width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
|
||||
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 {
|
||||
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 / v1.19 改为流式)====
|
||||
v1.18 是绝对定位贴右上角(躲开「无」按钮显隐带来的位移);
|
||||
v1.19「吸管 + 色值」也进了头部,头部本来就是一排可变宽控件,
|
||||
图钉跟着流走反而更稳 —— 竖线已经把「去色 | 图钉」和左边隔开,位置不会再被误读。 */
|
||||
.iwb-color-pop-pin {
|
||||
flex: 0 0 auto; width: 24px; height: 24px; 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:侧栏「快速效果」
|
||||
@@ -1946,6 +2010,76 @@
|
||||
.iwb-editor-fx-range:disabled::-moz-range-thumb { background: #585b70; }
|
||||
.iwb-editor-fx-range:focus-visible { outline: 2px solid #89b4fa; outline-offset: 2px; }
|
||||
|
||||
/* ================================================================
|
||||
v1.15:图片调节面板
|
||||
11 项挤在 240px 侧栏里,必须单行紧凑:名称 46 / 滑杆 flex / 数值 36。
|
||||
调过的项把名称染成橙色 —— 一屏 11 项,不标出来根本看不出哪几项被动过。
|
||||
================================================================ */
|
||||
.iwb-editor-adj {
|
||||
display: flex; flex-direction: column; gap: 7px;
|
||||
padding: 9px 10px 8px; border-radius: 10px;
|
||||
background: #1e1e2c; border: 1px solid #2f2f42;
|
||||
}
|
||||
.iwb-editor-adj-head {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
}
|
||||
.iwb-editor-adj-title {
|
||||
font-size: 11.5px; font-weight: 600; color: #cdd6f4; flex: 0 0 auto;
|
||||
}
|
||||
.iwb-editor-adj-target {
|
||||
font-size: 10px; color: #7f87a3; flex: 1 1 auto;
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
.iwb-editor-adj-reset {
|
||||
flex: 0 0 auto; padding: 2px 7px; border-radius: 5px;
|
||||
background: #26263a; border: 1px solid #3a3a52; color: #b9c0d8;
|
||||
font: 500 10px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||
cursor: pointer; transition: background 0.12s ease, color 0.12s ease;
|
||||
}
|
||||
.iwb-editor-adj-reset:hover:not(:disabled) { background: #33334c; color: #f3dcb0; border-color: #e8a735; }
|
||||
.iwb-editor-adj-reset:disabled { opacity: 0.4; cursor: default; }
|
||||
.iwb-editor-adj.is-dirty .iwb-editor-adj-title { color: #e8a735; }
|
||||
.iwb-editor-adj-list { display: flex; flex-direction: column; gap: 1px; }
|
||||
.iwb-editor-adj-row {
|
||||
display: grid; grid-template-columns: 46px 1fr 36px;
|
||||
align-items: center; gap: 6px; padding: 1px 0;
|
||||
}
|
||||
.iwb-editor-adj-name {
|
||||
font-size: 10px; color: #b9c0d8; white-space: nowrap;
|
||||
cursor: pointer; user-select: none; overflow: hidden; text-overflow: ellipsis;
|
||||
}
|
||||
.iwb-editor-adj-row.is-set .iwb-editor-adj-name { color: #e8a735; }
|
||||
.iwb-editor-adj-range {
|
||||
-webkit-appearance: none; appearance: none;
|
||||
width: 100%; height: 14px; margin: 0; background: transparent; cursor: pointer;
|
||||
}
|
||||
.iwb-editor-adj-range::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: #313244; }
|
||||
.iwb-editor-adj-range::-webkit-slider-thumb {
|
||||
-webkit-appearance: none; appearance: none;
|
||||
width: 11px; height: 11px; margin-top: -3.5px; border-radius: 50%;
|
||||
background: #e8a735; border: 1px solid #1e1e2c;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
.iwb-editor-adj-range::-moz-range-track { height: 4px; border-radius: 2px; background: #313244; }
|
||||
.iwb-editor-adj-range::-moz-range-thumb {
|
||||
width: 11px; height: 11px; border-radius: 50%; background: #e8a735; border: 1px solid #1e1e2c;
|
||||
}
|
||||
.iwb-editor-adj-range:focus-visible { outline: 2px solid #89b4fa; outline-offset: 2px; }
|
||||
.iwb-editor-adj-val {
|
||||
width: 36px; padding: 1px 2px; text-align: center;
|
||||
background: #26263a; border: 1px solid #3a3a52; border-radius: 4px;
|
||||
color: #cdd6f4; font: 500 10px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||
font-variant-numeric: tabular-nums;
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
.iwb-editor-adj-val::-webkit-outer-spin-button,
|
||||
.iwb-editor-adj-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
|
||||
.iwb-editor-adj-val:focus { outline: none; border-color: #89b4fa; }
|
||||
.iwb-editor-adj-row.is-set .iwb-editor-adj-val { color: #f3dcb0; border-color: #4a4433; }
|
||||
.iwb-editor-adj-tip {
|
||||
margin: 0; font-size: 9.5px; line-height: 1.4; color: #6c7390;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
v1.6:图层面板多选(⌘/Ctrl 点击)+ 合并按钮
|
||||
多选用青色侧条与单选(橙色 #e8a735)区分:一个图层可以「被选中但不在合并集合里」,
|
||||
@@ -2000,19 +2134,20 @@
|
||||
/* 选项栏里色块旁边的分组标签,和「描边 / 底色」这类双字按钮区分开 */
|
||||
.iwb-opt-swatch-label { color: #7f849c; font-size: 11px; flex: 0 0 auto; }
|
||||
|
||||
/* 「最近使用」:色板弹层里 4 列 × 2 行,空的时候整块隐藏(不占位) */
|
||||
/* 「最近使用」:与常用色同一套 8 列 20px 网格(v1.19 起最多 16 个 = 铺满两排),
|
||||
空的时候整块隐藏(不占位)。 */
|
||||
.iwb-editor-color-pop .iwb-editor-recent-colors {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 18px);
|
||||
grid-auto-rows: 18px;
|
||||
grid-template-columns: repeat(8, 20px);
|
||||
grid-auto-rows: 20px;
|
||||
gap: 5px;
|
||||
flex: 0 0 auto;
|
||||
align-content: center;
|
||||
}
|
||||
.iwb-editor-recent-colors[hidden] { display: none; }
|
||||
.iwb-editor-color-pop .iwb-editor-recent-colors .iwb-editor-color-panel-swatch {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
@@ -2026,3 +2161,94 @@
|
||||
|
||||
/* 选项栏按钮里是中文双字标签(常规/特粗/底色),不给 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) 右栏调色面板:已删(v1.19,用户 2026-11-10) ----
|
||||
颜色只剩工具栏弹层一处。弹层钉住后本来就常开,右栏那份只是重复占位。
|
||||
原来这里的 .iwb-editor-colors / .iwb-editor-colors-head / 以及一批
|
||||
`.iwb-editor-colors .iwb-color-pop-*` 覆盖规则(弹层横排、右栏竖排)全部移除 ——
|
||||
少一层「同一份 DOM 两套布局」的分支,改色板不会再出现「改了一处另一处没跟上」。 */
|
||||
|
||||
|
||||
/* ---- 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; }
|
||||
@@ -0,0 +1,526 @@
|
||||
/* adjust.js - 图片调节(v1.15)
|
||||
*
|
||||
* 和 effects.js 的分工:
|
||||
* effects.js = 一键效果(反白/灰度/马赛克……),语义是「换成另一种图」;
|
||||
* adjust.js = 连续调色(曝光/对比度/白平衡……),语义是「把这张图调好看」。
|
||||
* 两者都作用在当前位图图层,都保留 source 只重算不叠加。
|
||||
*
|
||||
* === 为什么不用 ctx.filter ===
|
||||
* CSS filter 只有 brightness/contrast/saturate/hue-rotate/blur 这几种全局线性变换,做不到:
|
||||
* · 阴影 / 高光 —— 需要按亮度做软蒙版分区提亮压暗;
|
||||
* · 白平衡温度 / 色调 —— 需要 R/B、G/M 通道分别增益;
|
||||
* · 锐度 / 清晰度 —— USM 反遮罩,需要卷积。
|
||||
* 所以走 getImageData 逐像素。代价是耗时随像素数线性增长(实测):
|
||||
* 800² 6.7ms · 1200² 12.8ms · 2000² 36.8ms · 4000² 144.6ms
|
||||
* 因此拖动滑杆时用「降采样预览」(长边 ≤ PREVIEW_SIDE,一张小图反复算),
|
||||
* 松手(change)才用原尺寸算一次。这是 PS 的常规做法,观感上只在松手瞬间有一帧停顿。
|
||||
*
|
||||
* === 非破坏性怎么保证 ===
|
||||
* S.adjust.source 存「开始调节前」的原尺寸像素,preview 存它的降采样副本。
|
||||
* 每次参数变化都从 source 重算,绝不在上一次结果上叠加 —— 否则来回拖滑杆会
|
||||
* 层层累积、越拖越糊(effects.js 里同样的坑,注释里记过)。
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
import { S, runtime } from './state.js'
|
||||
import { saveSnapshot } from './history.js'
|
||||
import { getActiveLayer, renderLayerPanel } from './layers.js'
|
||||
import { needsPixelSnapshot } from '../vendor/layer-logic.js'
|
||||
import { toast } from './commands.js'
|
||||
|
||||
/** 拖动预览用的最长边:0.6M 像素,实测 6.7ms,够 60fps */
|
||||
const PREVIEW_SIDE = 900
|
||||
/** 图本身小于这个边长就无需降采样,直接全量算 */
|
||||
const DIRECT_SIDE = 1100
|
||||
|
||||
/**
|
||||
* 参数表。范围按「拉满要有明显变化」定,不是摆设:
|
||||
* 曝光 ±100 = ±2 档(×4 / ÷4),对比度 ±100 = 0~2 倍,饱和度 ±100 = 0~2 倍。
|
||||
* 上一版快速效果「增强」拉满只有 brightness(1.12),用户反馈「效果弱」就是这么来的。
|
||||
*/
|
||||
export const ADJUST_DEFS = [
|
||||
{ key: 'exposure', label: '曝光', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'brightness', label: '明度', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'contrast', label: '对比度', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'shadows', label: '阴影', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'highlights', label: '高光', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'hue', label: '色相', min: -180, max: 180, step: 1, def: 0, suffix: '°' },
|
||||
{ key: 'saturation', label: '饱和度', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'temp', label: '温度', title: '白平衡温度:往右偏暖(黄),往左偏冷(蓝)', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'tint', label: '色调', title: '白平衡色调:往右偏品红,往左偏绿', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'sharpen', label: '锐度', min: 0, max: 100, step: 1, def: 0 },
|
||||
{ key: 'clarity', label: '清晰度', min: -100, max: 100, step: 1, def: 0 }
|
||||
]
|
||||
|
||||
export const ADJUST_KEYS = ADJUST_DEFS.map(d => d.key)
|
||||
|
||||
export function zeroAdjust() {
|
||||
const o = {}
|
||||
for (const k of ADJUST_KEYS) o[k] = 0
|
||||
return o
|
||||
}
|
||||
|
||||
/** 全部参数都是 0 = 没调过,直接跳过整趟像素运算 */
|
||||
export function isNeutral(p) {
|
||||
if (!p) return true
|
||||
for (const k of ADJUST_KEYS) if (p[k]) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/** 调节目标:当前活跃位图图层;没有就退回「原图」(与 effects.js 同规则) */
|
||||
function adjustTarget() {
|
||||
const active = getActiveLayer()
|
||||
if (active) return active
|
||||
return S.layers.find(l => l.id === 'base') || null
|
||||
}
|
||||
|
||||
function copyCanvas(src, maxSide) {
|
||||
const w0 = src.width, h0 = src.height
|
||||
let w = w0, h = h0
|
||||
if (maxSide && Math.max(w0, h0) > maxSide) {
|
||||
const k = maxSide / Math.max(w0, h0)
|
||||
w = Math.max(1, Math.round(w0 * k))
|
||||
h = Math.max(1, Math.round(h0 * k))
|
||||
}
|
||||
const c = document.createElement('canvas')
|
||||
c.width = w
|
||||
c.height = h
|
||||
const ctx = c.getContext('2d', { willReadFrequently: true })
|
||||
ctx.imageSmoothingEnabled = true
|
||||
ctx.imageSmoothingQuality = 'high'
|
||||
ctx.drawImage(src, 0, 0, w, h)
|
||||
return c
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 像素调色 */
|
||||
|
||||
/**
|
||||
* 逐像素处理。顺序有讲究:
|
||||
* 白平衡 → 曝光 → 阴影/高光 → 对比度 → 饱和度 → 色相
|
||||
* 先修色偏再谈明暗,先把动态范围拉开再调饱和,否则「先加饱和后压对比」会把
|
||||
* 颜色压成一片灰。色相放最后,因为它作用在已经很干净的色相上。
|
||||
*/
|
||||
function adjustPixels(ctx, w, h, p) {
|
||||
const img = ctx.getImageData(0, 0, w, h)
|
||||
const d = img.data
|
||||
|
||||
const ev = p.exposure ? Math.pow(2, p.exposure / 50) : 1
|
||||
const add = (p.brightness / 100) * 0.45
|
||||
const con = 1 + p.contrast / 100
|
||||
const sh = p.shadows / 100
|
||||
const hi = p.highlights / 100
|
||||
const sat = 1 + p.saturation / 100
|
||||
const wbR = 1 + p.temp / 250 + p.tint / 500
|
||||
const wbG = 1 - p.tint / 400
|
||||
const wbB = 1 - p.temp / 250 + p.tint / 500
|
||||
const wb = Boolean(p.temp || p.tint)
|
||||
const needSh = Boolean(sh)
|
||||
const needHi = Boolean(hi)
|
||||
const needCon = Boolean(p.contrast)
|
||||
const needSat = Boolean(p.saturation)
|
||||
const needHue = Boolean(p.hue)
|
||||
|
||||
// 色相旋转矩阵(与 CSS hue-rotate 同一套系数),预算好避免每像素算三角函数
|
||||
let h0 = 0, h1 = 0, h2 = 0, h3 = 0, h4 = 0, h5 = 0, h6 = 0, h7 = 0, h8 = 0
|
||||
if (needHue) {
|
||||
const a = (p.hue * Math.PI) / 180
|
||||
const c = Math.cos(a), s = Math.sin(a)
|
||||
h0 = 0.213 + c * 0.787 - s * 0.213
|
||||
h1 = 0.715 - c * 0.715 - s * 0.715
|
||||
h2 = 0.072 - c * 0.072 + s * 0.928
|
||||
h3 = 0.213 - c * 0.213 + s * 0.143
|
||||
h4 = 0.715 + c * 0.285 + s * 0.140
|
||||
h5 = 0.072 - c * 0.072 - s * 0.283
|
||||
h6 = 0.213 - c * 0.213 - s * 0.787
|
||||
h7 = 0.715 - c * 0.715 + s * 0.715
|
||||
h8 = 0.072 + c * 0.928 + s * 0.072
|
||||
}
|
||||
|
||||
// 全部为 0 的短路:只做一次遍历判断,省掉逐像素分支
|
||||
const trivial = !wb && !p.exposure && !add && !needSh && !needHi && !needCon && !needSat && !needHue
|
||||
if (trivial) return
|
||||
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
let r = d[i] / 255, g = d[i + 1] / 255, b = d[i + 2] / 255
|
||||
|
||||
if (wb) { r *= wbR; g *= wbG; b *= wbB }
|
||||
if (ev !== 1) { r *= ev; g *= ev; b *= ev }
|
||||
if (add) { r += add; g += add; b += add }
|
||||
|
||||
// 阴影/高光:按当前亮度给一个软蒙版。阴影权重 (1-l)²,高光 l²,
|
||||
// 这样中间调几乎不动,只有暗部/亮部两端被推 —— 硬阈值会在边界留下可见台阶。
|
||||
if (needSh || needHi) {
|
||||
const l = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||
if (needSh) {
|
||||
const m = (1 - l) * (1 - l) * sh * 0.85
|
||||
r += m; g += m; b += m
|
||||
}
|
||||
if (needHi) {
|
||||
const m = l * l * hi * 0.85
|
||||
r += m; g += m; b += m
|
||||
}
|
||||
}
|
||||
|
||||
if (needCon) {
|
||||
r = (r - 0.5) * con + 0.5
|
||||
g = (g - 0.5) * con + 0.5
|
||||
b = (b - 0.5) * con + 0.5
|
||||
}
|
||||
|
||||
if (needSat) {
|
||||
const l = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||
r = l + (r - l) * sat
|
||||
g = l + (g - l) * sat
|
||||
b = l + (b - l) * sat
|
||||
}
|
||||
|
||||
if (needHue) {
|
||||
const nr = h0 * r + h1 * g + h2 * b
|
||||
const ng = h3 * r + h4 * g + h5 * b
|
||||
const nb = h6 * r + h7 * g + h8 * b
|
||||
r = nr; g = ng; b = nb
|
||||
}
|
||||
|
||||
d[i] = r <= 0 ? 0 : (r >= 1 ? 255 : r * 255)
|
||||
d[i + 1] = g <= 0 ? 0 : (g >= 1 ? 255 : g * 255)
|
||||
d[i + 2] = b <= 0 ? 0 : (b >= 1 ? 255 : b * 255)
|
||||
}
|
||||
ctx.putImageData(img, 0, 0)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 锐化 */
|
||||
|
||||
/**
|
||||
* USM 反遮罩:result = src + (src - blur) * amount。
|
||||
* 锐度用 1px 半径(找边缘),清晰度用更大的半径 + 更低强度(找中间调的体积感)。
|
||||
* 降采样预览时半径要跟着缩放,否则 900px 的预览用 1px 和原图 1px 视觉上不是一回事。
|
||||
*/
|
||||
function unsharp(canvas, radius, amount) {
|
||||
if (!(amount > 0)) return
|
||||
const w = canvas.width, h = canvas.height
|
||||
const blur = document.createElement('canvas')
|
||||
blur.width = w
|
||||
blur.height = h
|
||||
const bc = blur.getContext('2d', { willReadFrequently: true })
|
||||
bc.filter = 'blur(' + radius.toFixed(2) + 'px)'
|
||||
bc.drawImage(canvas, 0, 0)
|
||||
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true })
|
||||
const src = ctx.getImageData(0, 0, w, h)
|
||||
const bl = bc.getImageData(0, 0, w, h)
|
||||
const a = src.data, b = bl.data
|
||||
for (let i = 0; i < a.length; i += 4) {
|
||||
// 透明像素不参与(位图层的空白区域),否则边缘会被锐出一圈黑边
|
||||
if (a[i + 3] === 0) continue
|
||||
for (let c = 0; c < 3; c++) {
|
||||
const v = a[i + c] + (a[i + c] - b[i + c]) * amount
|
||||
a[i + c] = v <= 0 ? 0 : (v >= 255 ? 255 : v)
|
||||
}
|
||||
}
|
||||
ctx.putImageData(src, 0, 0)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 渲染 */
|
||||
|
||||
/** 把参数应用到一张画布上(画布尺寸决定锐化半径的缩放) */
|
||||
function paint(canvas, p, refSide) {
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true })
|
||||
adjustPixels(ctx, canvas.width, canvas.height, p)
|
||||
|
||||
const k = Math.max(canvas.width, canvas.height) / (refSide || Math.max(canvas.width, canvas.height))
|
||||
if (p.sharpen > 0) unsharp(canvas, Math.max(0.6, 1 * k), (p.sharpen / 100) * 1.1)
|
||||
if (p.clarity) {
|
||||
// 负清晰度 = 柔化中间调,同样走 USM,只是 amount 为负
|
||||
unsharp(canvas, Math.max(1.5, 6 * k), (p.clarity / 100) * 0.55)
|
||||
}
|
||||
}
|
||||
|
||||
function blit(target, src) {
|
||||
const ctx = target.getContext('2d')
|
||||
ctx.save()
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||
ctx.globalAlpha = 1
|
||||
ctx.globalCompositeOperation = 'copy'
|
||||
ctx.filter = 'none'
|
||||
ctx.imageSmoothingEnabled = true
|
||||
ctx.imageSmoothingQuality = 'high'
|
||||
ctx.drawImage(src, 0, 0, target.width, target.height)
|
||||
ctx.restore()
|
||||
target._bounds = undefined
|
||||
S.pickerComposite = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 source 重算并写回目标层。
|
||||
* preview=true 走降采样:拖动滑杆时只要「看得出往哪边变」,不需要像素级准确。
|
||||
*/
|
||||
function renderAdjust(preview) {
|
||||
const st = S.adjust
|
||||
if (!st || !st.source) return false
|
||||
const target = S.layers.find(l => l.id === st.layerId)
|
||||
if (!target) return false
|
||||
|
||||
const src = preview && st.previewCanvas ? st.previewCanvas : st.source
|
||||
const work = copyCanvas(src)
|
||||
paint(work, st.params, Math.max(st.source.width, st.source.height))
|
||||
blit(target.canvas, work)
|
||||
return true
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 对外 */
|
||||
|
||||
/**
|
||||
* 每层的「调节前基准像素」缓存。
|
||||
* 为什么需要它:A 层调过 → 切到 B 层调 → 切回 A 层再调。此时 A 的 canvas 里已经
|
||||
* 是调节后的像素,若拿它当新基准,第二次调整就叠在第一次结果上(来回拖会越调越脏,
|
||||
* effects.js 注释里记过同样的坑)。缓存不进图层对象,因此不会被历史快照深拷贝。
|
||||
*/
|
||||
const sourceCache = new Map()
|
||||
|
||||
function captureFor(layer) {
|
||||
const hit = sourceCache.get(layer.id)
|
||||
if (hit) return hit
|
||||
const rec = {
|
||||
source: copyCanvas(layer.canvas, 0),
|
||||
previewCanvas: copyCanvas(layer.canvas, PREVIEW_SIDE)
|
||||
}
|
||||
sourceCache.set(layer.id, rec)
|
||||
return rec
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出编辑器 / 重新打开时清空基准缓存(v1.15.1 修)。
|
||||
*
|
||||
* 必须清的原因:缓存的 key 是 layer.id,而原图层的 id 是写死的 'base'。
|
||||
* 退出编辑器时 releaseEditorMemory() 释放了图层画布,却没清这张 Map,
|
||||
* 于是下一张图打开后 captureFor() 直接命中上一张图的像素,
|
||||
* 表现为「调第二张图,画面变回第一张」。id 固定 ⇒ 100% 复现,不是偶发。
|
||||
*
|
||||
* 顺带把 S.adjust 也归零:残留的 params 会让新图的滑杆一进来就显示 +80,
|
||||
* 而画面是未调状态,参数与画面对不上。
|
||||
*/
|
||||
export function resetAdjustCache() {
|
||||
sourceCache.clear()
|
||||
S.adjust = { layerId: null, source: null, previewCanvas: null, params: zeroAdjust() }
|
||||
}
|
||||
|
||||
/** 观测口:回归用例用它断言「退出后缓存确实清空了」 */
|
||||
export function adjustCacheSize() {
|
||||
return sourceCache.size
|
||||
}
|
||||
|
||||
/** 切换调节目标:旧层基准入缓存,新层取缓存或现拍,参数按层恢复 */
|
||||
function switchTarget(layer) {
|
||||
const st = S.adjust
|
||||
if (st && st.layerId && st.source) {
|
||||
sourceCache.set(st.layerId, { source: st.source, previewCanvas: st.previewCanvas })
|
||||
}
|
||||
const rec = captureFor(layer)
|
||||
S.adjust = {
|
||||
layerId: layer.id,
|
||||
source: rec.source,
|
||||
previewCanvas: rec.previewCanvas,
|
||||
params: layer.adjustParams ? { ...layer.adjustParams } : zeroAdjust()
|
||||
}
|
||||
}
|
||||
|
||||
/** 参数写回图层对象:切层回来能显示「这层调成了什么样」 */
|
||||
function persistParams() {
|
||||
const st = S.adjust
|
||||
if (!st || !st.layerId || !st.params) return
|
||||
const layer = S.layers.find(l => l.id === st.layerId)
|
||||
if (layer) layer.adjustParams = { ...st.params }
|
||||
}
|
||||
|
||||
/** 确保当前目标层有一份可重算的基准像素 */
|
||||
export function ensureAdjustTarget() {
|
||||
let layer = adjustTarget()
|
||||
if (!layer) { toast('没有可调节的图层'); return null }
|
||||
if (layer.visible === false) {
|
||||
toast('「' + layer.name + '」已隐藏,先显示再调节')
|
||||
return null
|
||||
}
|
||||
|
||||
if (!needsPixelSnapshot(layer)) layer = rasterizeForAdjust(layer)
|
||||
if (!layer) { toast('栅格化失败,调节未应用'); return null }
|
||||
|
||||
if (!S.adjust || S.adjust.layerId !== layer.id || !S.adjust.source) switchTarget(layer)
|
||||
return layer
|
||||
}
|
||||
|
||||
/** 导入图片层原地改像素会被下次重绘冲掉 —— 先复制一层普通位图(与 effects.js 同策略) */
|
||||
function rasterizeForAdjust(layer) {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = S.imgW
|
||||
canvas.height = S.imgH
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true })
|
||||
ctx.drawImage(layer.canvas, 0, 0)
|
||||
|
||||
const copy = {
|
||||
id: 'adj' + Date.now() + Math.floor(Math.random() * 1000),
|
||||
name: layer.name + ' · 调节',
|
||||
canvas, ctx,
|
||||
opacity: layer.opacity == null ? 1 : layer.opacity,
|
||||
visible: true, locked: false,
|
||||
x: 0, y: 0, w: S.imgW, h: S.imgH,
|
||||
rotation: 0,
|
||||
z: (layer.z || 0) + 0.5
|
||||
}
|
||||
S.layers.push(copy)
|
||||
layer.visible = false
|
||||
if (S.selectedLayerId === layer.id) S.selectedLayerId = copy.id
|
||||
S.activeLayerId = copy.id
|
||||
renderLayerPanel()
|
||||
return copy
|
||||
}
|
||||
|
||||
/** 参数变了:重算并画到画布上。preview=true 用降采样 */
|
||||
export function applyAdjust(preview) {
|
||||
if (!S.adjust || !S.adjust.source) return false
|
||||
const ok = renderAdjust(Boolean(preview))
|
||||
if (ok) {
|
||||
persistParams()
|
||||
if (S.renderAll) S.renderAll()
|
||||
}
|
||||
renderAdjustPanel()
|
||||
return ok
|
||||
}
|
||||
|
||||
/** 单个参数变化 */
|
||||
export function setAdjustValue(key, value, preview) {
|
||||
const st = S.adjust
|
||||
if (!st || !st.source) return false
|
||||
const def = ADJUST_DEFS.find(d => d.key === key)
|
||||
if (!def) return false
|
||||
const v = Math.min(def.max, Math.max(def.min, Number(value) || 0))
|
||||
st.params[key] = v
|
||||
applyAdjust(preview)
|
||||
return true
|
||||
}
|
||||
|
||||
/** 复位:单条 or 全部 */
|
||||
export function resetAdjust(key) {
|
||||
const st = S.adjust
|
||||
if (!st || !st.source) return false
|
||||
saveSnapshot('调节复位')
|
||||
if (key) st.params[key] = 0
|
||||
else st.params = zeroAdjust()
|
||||
applyAdjust(false)
|
||||
syncAdjustControls()
|
||||
return true
|
||||
}
|
||||
|
||||
/** 有没有调过(用于「复位」按钮的可用态与标题提示) */
|
||||
export function adjustDirty() {
|
||||
return Boolean(S.adjust && S.adjust.source && !isNeutral(S.adjust.params))
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- UI */
|
||||
|
||||
/**
|
||||
* 按 ADJUST_DEFS 生成 11 行控件,只做一次(面板是静态的,之后只改 value / 类名)。
|
||||
* 单行紧凑布局:名称 46px + 滑杆 flex + 数值 36px —— 240px 侧栏里 11 项只占约 240px 高,
|
||||
* 不需要把侧栏撑成一整屏滚动。
|
||||
*/
|
||||
export function mountAdjustPanel() {
|
||||
if (!runtime.el) return
|
||||
const list = runtime.el.querySelector('.iwb-editor-adj-list')
|
||||
if (!list || list.childElementCount) return
|
||||
list.innerHTML = ADJUST_DEFS.map(d => `
|
||||
<div class="iwb-editor-adj-row" data-adj="${d.key}">
|
||||
<span class="iwb-editor-adj-name" title="${d.title || d.label}${d.suffix ? '' : ''}(双击归零)">${d.label}</span>
|
||||
<input type="range" class="iwb-editor-adj-range" min="${d.min}" max="${d.max}" step="${d.step}" value="${d.def}" aria-label="${d.title || d.label}">
|
||||
<input type="number" class="iwb-editor-adj-val" min="${d.min}" max="${d.max}" step="${d.step}" value="${d.def}" aria-label="${d.title || d.label}数值">
|
||||
</div>`).join('')
|
||||
renderAdjustPanel()
|
||||
}
|
||||
|
||||
/** 面板里的 target 层名 + 复位按钮可用态 */
|
||||
export function renderAdjustPanel() {
|
||||
if (!runtime.el) return
|
||||
const sec = runtime.el.querySelector('.iwb-editor-adj')
|
||||
if (!sec) return
|
||||
const layer = adjustTarget()
|
||||
|
||||
// 目标层被切走:面板跟着换到新层(参数按层恢复、新的基准),旧层的像素不动。
|
||||
// 必须在这里兜住 —— 图层切换走的是 layers.js,那边不能 import 本模块(会形成循环)。
|
||||
if (layer && S.adjust && S.adjust.layerId && S.adjust.layerId !== layer.id) {
|
||||
switchTarget(layer)
|
||||
syncAdjustControls()
|
||||
return
|
||||
}
|
||||
|
||||
const nameEl = sec.querySelector('.iwb-editor-adj-target')
|
||||
if (nameEl) {
|
||||
const name = layer ? layer.name : '无图层'
|
||||
nameEl.textContent = name
|
||||
nameEl.title = layer ? '调节作用于「' + name + '」' : '没有可调节的位图图层'
|
||||
}
|
||||
const dirty = adjustDirty()
|
||||
sec.classList.toggle('is-dirty', dirty)
|
||||
const reset = sec.querySelector('[data-adj-reset="all"]')
|
||||
if (reset) reset.disabled = !dirty
|
||||
sec.querySelectorAll('.iwb-editor-adj-row').forEach(row => {
|
||||
const k = row.dataset.adj
|
||||
const v = S.adjust && S.adjust.params ? S.adjust.params[k] || 0 : 0
|
||||
row.classList.toggle('is-set', Boolean(v))
|
||||
})
|
||||
}
|
||||
|
||||
/** 把 S.adjust.params 写回所有滑杆与数值框(复位后调用) */
|
||||
export function syncAdjustControls() {
|
||||
if (!runtime.el) return
|
||||
const sec = runtime.el.querySelector('.iwb-editor-adj')
|
||||
if (!sec || !S.adjust || !S.adjust.params) return
|
||||
sec.querySelectorAll('.iwb-editor-adj-row').forEach(row => {
|
||||
const k = row.dataset.adj
|
||||
const v = S.adjust.params[k] || 0
|
||||
const range = row.querySelector('.iwb-editor-adj-range')
|
||||
const val = row.querySelector('.iwb-editor-adj-val')
|
||||
if (range) range.value = String(v)
|
||||
if (val) val.value = String(v)
|
||||
})
|
||||
renderAdjustPanel()
|
||||
}
|
||||
|
||||
/** 进入编辑器 / 切换目标层时重建基准 */
|
||||
export function refreshAdjustTarget() {
|
||||
// 只在目标层真的变了才重置基准,否则每次重绘都丢参数
|
||||
const layer = adjustTarget()
|
||||
if (!layer) return
|
||||
const st = S.adjust
|
||||
if (st.source && st.layerId === layer.id) return
|
||||
S.adjust = { layerId: null, source: null, previewCanvas: null, params: zeroAdjust() }
|
||||
renderAdjustPanel()
|
||||
syncAdjustControls()
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销 / 重做之后。
|
||||
*
|
||||
* 为什么必须归零:调整是「写进像素」的破坏性操作,历史里只存了像素快照,没存
|
||||
* 「调节前的基准」。撤销把像素还原了,但 source 对应的已经不是这个状态 —— 留着
|
||||
* 旧参数只会出现「滑块显示 +80、画面其实没调」。更糟的是下一次拖动会从错误的
|
||||
* 基准重算,等于把调整叠加两遍。
|
||||
*
|
||||
* 所以规则很简单也很可预测:**撤销一步 = 调整作废,滑块归零,基准重拍当前像素**。
|
||||
* 想再调就从现在这张画面上重新调。
|
||||
*/
|
||||
export function onHistoryRestore() {
|
||||
sourceCache.clear()
|
||||
const layer = adjustTarget()
|
||||
if (!layer) {
|
||||
S.adjust = { layerId: null, source: null, previewCanvas: null, params: zeroAdjust() }
|
||||
syncAdjustControls()
|
||||
return
|
||||
}
|
||||
if (layer.adjustParams) delete layer.adjustParams
|
||||
S.adjust = {
|
||||
layerId: layer.id,
|
||||
source: copyCanvas(layer.canvas, 0),
|
||||
previewCanvas: copyCanvas(layer.canvas, PREVIEW_SIDE),
|
||||
params: zeroAdjust()
|
||||
}
|
||||
syncAdjustControls()
|
||||
}
|
||||
@@ -10,6 +10,77 @@ import { S, runtime } from './state.js'
|
||||
import { bindEvents } from './events.js'
|
||||
|
||||
|
||||
// ============ 调色面板(工具栏弹层) ============
|
||||
/**
|
||||
* v1.19:右栏常驻面板删掉,只剩工具栏弹层这一份(钉住后它本来就是常开的)。
|
||||
* 仍抽成函数而不是写在模板里:这套控件有 4 组联动(tab 高亮、SV/色相指示点、
|
||||
* HEX 回填、常用色/最近色的 active 圈),events.js#updateColorUI 按
|
||||
* `[data-color-surface]` 逐个刷 —— 留着这层抽象,将来若再加一处面板不用重写联动。
|
||||
*/
|
||||
/* 16 个常用色 = 色板里 8 列 × 2 行(v1.19)。
|
||||
排布刻意成对:第一行是 8 个饱和亮色(红橙黄绿青蓝紫粉),
|
||||
第二行是 4 个中性色(白/浅灰/中灰/黑)+ 4 个同色系「深一档」,
|
||||
深红/深绿/深蓝/深紫 在浅色底图上比亮色稳,做描边不刺眼。 */
|
||||
const COMMON_COLORS = [
|
||||
'#ff4444', '#ff8a00', '#ffd400', '#4cd964', '#00bfa5', '#4488ff', '#aa44ff', '#ff66aa',
|
||||
'#ffffff', '#d0d0d0', '#808080', '#000000', '#c0392b', '#0f9d58', '#1677ff', '#6b4fbb'
|
||||
]
|
||||
|
||||
/** 色板面板(v1.19 起只有工具栏弹层一份,右栏常驻面板已删)
|
||||
*
|
||||
* 头部一行:调哪个槽(描边/填充/底色)│ 吸管 + 色值 │ 去色 │ 图钉
|
||||
* 把「吸管 + 色值」提到头部,是为了让下面整块高度都留给色块:
|
||||
* 常用色 2 排 + 最近色 2 排,一屏就能点到,不用滚动、也不用二次点开。
|
||||
*/
|
||||
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>
|
||||
<span class="iwb-color-pop-bar"></span>
|
||||
<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="十六进制颜色,回车生效">
|
||||
<!-- 去色(v1.19,用户 2026-11-10):就是原来的「无」,挪到图钉左边并用竖线隔开。
|
||||
调色时「这一项我不上色」和「钉住」都是随手要按的开关,放在同一侧最顺。
|
||||
对描边 / 填充 / 底色都生效,具体含义随当前槽变(见 updateColorUI 的 title)。
|
||||
外面这层 .iwb-color-pop-tools 用 margin-left:auto 把整组推到最右:
|
||||
色值框因此不会被拉成一整条(见 CSS 的 max-width)。 -->
|
||||
<span class="iwb-color-pop-tools">
|
||||
<span class="iwb-color-pop-bar"></span>
|
||||
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="去色:当前这一项不上色(描边/填充/底色按上下文透明)"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="m5.6 5.6 12.8 12.8"/></svg>去色</button>
|
||||
<span class="iwb-color-pop-bar"></span>
|
||||
<!-- 钉住(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>
|
||||
</span>
|
||||
</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.19):常用色 8×2 在上、最近色 8×2 在下,中间 1px 细线分隔。
|
||||
不写「常用色 / 最近」小标题 —— 每个色块的 title 已经写明是哪一个,
|
||||
而标题要各占一行,是这块面板最浪费的高度(v1.18 已这么定,v1.19 沿用)。 -->
|
||||
<div class="iwb-color-pop-side">
|
||||
<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 创建 ============
|
||||
export function createEl() {
|
||||
if (runtime.el) return
|
||||
@@ -26,11 +97,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-cancel" data-action="cancel" title="放弃修改并退出">退出</button>
|
||||
</div>
|
||||
<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>
|
||||
<!-- 撤销/重做/还原(v1.18,用户 2026-11-10):从顶栏搬到画布底部工具栏最右侧。
|
||||
理由:这三个是「画画时会连着按」的操作,手在画布上,不该抬头去顶栏找。
|
||||
顶栏只留会话组(新建/覆盖/退出)与输出。 -->
|
||||
<!-- 顶栏命令带已清空(v1.13):
|
||||
四个「置顶/上移/下移/置底」按钮删除(图层面板可拖动 + Ctrl+]/[ 已覆盖);
|
||||
「适应窗口 / 收起侧栏」搬到画布底部工具栏最右侧,离画布更近。
|
||||
@@ -164,13 +233,41 @@ import { bindEvents } from './events.js'
|
||||
<span class="iwb-editor-divider"></span>
|
||||
<button class="iwb-editor-tool iwb-editor-view-btn" data-action="zoomFit" title="适应窗口 (Ctrl+0):整张图缩放到刚好放得下"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 3 3 3 3 9"/><polyline points="15 3 21 3 21 9"/><polyline points="3 15 3 21 9 21"/><polyline points="21 15 21 21 15 21"/></svg></button>
|
||||
<button class="iwb-editor-tool iwb-editor-view-btn" data-action="togglePanels" title="收起 / 展开侧栏 (Tab)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="9" y1="4" x2="9" y2="20"/></svg></button>
|
||||
|
||||
<!-- 撤销 / 重做 / 还原(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 class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
||||
|
||||
<aside class="iwb-editor-left">
|
||||
<!-- 调色板已迁到工具栏弹层(v1.3,用户裁定 2026-11-05):
|
||||
侧栏只留快速效果 + 缩放;色板 DOM 在 modal 末尾的 .iwb-editor-color-pop -->
|
||||
<!-- v1.16:侧栏宽度拖拽手柄。贴在侧栏左边缘(它在画布右侧),
|
||||
双击复位。宽度写进 CSS 变量 --iwb-side-w,由 --iwb-side-w 统一裁各条 width 规则。 -->
|
||||
<div class="iwb-editor-side-resizer" data-side-resizer="1" title="拖动调整侧栏宽度,双击复位"></div>
|
||||
<!-- 右栏常驻调色面板已删(v1.19,用户 2026-11-10:「右边栏的调色模块就可以去掉了」)。
|
||||
理由:弹层钉住之后它一直是开着的,右栏那份同样内容只是在跟弹层抢注意力,
|
||||
还白占一块最显眼的位置。颜色只剩弹层一处(modal 末尾 .iwb-editor-color-pop),
|
||||
右栏现在从「图片调节」直接开始。 -->
|
||||
|
||||
<!-- 图片调节(v1.15):连续调色,作用于当前位图图层(默认原图)。
|
||||
行由 adjust.js#mountAdjustPanel() 按 ADJUST_DEFS 生成 —— 参数表只维护一份,
|
||||
不在 DOM 里再抄一遍(这个项目已经因为「同一个概念两处各写一份」栽过几次)。
|
||||
和下方「快速效果」的分工:这里是精细连续调,那边是一键换风格。 -->
|
||||
<section class="iwb-editor-adj">
|
||||
<div class="iwb-editor-adj-head">
|
||||
<span class="iwb-editor-adj-title">图片调节</span>
|
||||
<span class="iwb-editor-adj-target" title="调节作用于当前位图图层">原图</span>
|
||||
<button type="button" class="iwb-editor-adj-reset" data-adj-reset="all" disabled title="把所有调节项归零(Ctrl+Z 可撤销)">复位</button>
|
||||
</div>
|
||||
<div class="iwb-editor-adj-list"></div>
|
||||
<p class="iwb-editor-adj-tip">拖动实时预览,松手出精细结果 · 双击滑杆归零</p>
|
||||
</section>
|
||||
<!-- 快速效果(v1.4):作用于当前位图图层,点一下就应用,Ctrl+Z 撤销。
|
||||
目标层名由 effects.js 的 updateFxTargetLabel() 实时刷新。 -->
|
||||
<section class="iwb-editor-fx">
|
||||
@@ -229,47 +326,12 @@ import { bindEvents } from './events.js'
|
||||
<span class="iwb-editor-status-layer">当前层:原图</span>
|
||||
<span class="iwb-editor-status-tool">画笔</span>
|
||||
</div>
|
||||
<!-- 色板弹层(v1.3):工具栏色点点击展开。
|
||||
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
||||
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
||||
<div class="iwb-editor-color-pop" hidden>
|
||||
<!-- 弹层头部(v1.11 两格 → v1.12 文字三格):标明「现在调的是哪个颜色」,
|
||||
并可直接切换。与工具栏那几个色块是同一组槽位,两边高亮完全一致。
|
||||
「无」只对「可以没有」的颜色有意义:文字色没有无,描边/底色/填充才有。 -->
|
||||
<div class="iwb-color-pop-head">
|
||||
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
|
||||
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色 / 文字描边色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
|
||||
<button type="button" class="iwb-color-pop-tab" data-color-slot="bg" hidden title="正在调文本框底色(垫在文字下面)"><i></i><span class="iwb-color-pop-tab-label">底色</span></button>
|
||||
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="无填充:形状内部透明,只留描边"><span></span>无</button>
|
||||
</div>
|
||||
<div class="iwb-color-pop-body">
|
||||
<div class="iwb-color-pop-picker">
|
||||
<div class="iwb-color-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>
|
||||
<!-- 色板弹层(v1.3;v1.16 起与右栏常驻面板共用同一份 DOM):
|
||||
工具栏色块点击展开。必须挂在 modal 下、不能塞进 .iwb-editor-tools ——
|
||||
工具栏是 overflow-x:auto,canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;
|
||||
定位由 events.js 计算。 -->
|
||||
<div class="iwb-editor-color-pop" data-color-surface="pop" hidden>
|
||||
${colorSurfaceHtml()}
|
||||
</div>
|
||||
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
||||
</div>
|
||||
|
||||
+6
-3
@@ -54,12 +54,15 @@ import { toast } from './commands.js'
|
||||
render: (canvas, v) => { if (v > 0) filterCanvas(canvas, 'grayscale(' + (v / 100) + ')') }
|
||||
},
|
||||
boost: {
|
||||
label: '增强', hint: '提亮并略加对比,适合发灰的截图',
|
||||
label: '增强', hint: '提亮并加对比,适合发灰的截图',
|
||||
param: '强度', unit: '%', min: 0, max: 100, step: 1, def: () => 100,
|
||||
render: (canvas, v) => {
|
||||
if (v <= 0) return
|
||||
const k = v / 100
|
||||
filterCanvas(canvas, 'brightness(' + (1 + 0.12 * k).toFixed(3) + ') contrast(' + (1 + 0.1 * k).toFixed(3) + ') saturate(' + (1 + 0.06 * k).toFixed(3) + ')')
|
||||
// v1.15:旧系数 1+0.12k / 1+0.1k / 1+0.06k 拉满只有 1.12 倍亮度,肉眼看不出变化
|
||||
// (用户反馈「效果现在弱了一些」)。现在拉满 = 1.4 倍亮度 / 1.25 倍对比 / 1.2 倍饱和,
|
||||
// 对应「一眼能看出变亮变通透」,但仍然不过曝 —— 再往上压会先把高光切掉。
|
||||
filterCanvas(canvas, 'brightness(' + (1 + 0.4 * k).toFixed(3) + ') contrast(' + (1 + 0.25 * k).toFixed(3) + ') saturate(' + (1 + 0.2 * k).toFixed(3) + ')')
|
||||
}
|
||||
},
|
||||
contrast: {
|
||||
@@ -68,7 +71,7 @@ import { toast } from './commands.js'
|
||||
render: (canvas, v) => {
|
||||
if (v <= 0) return
|
||||
const k = v / 100
|
||||
filterCanvas(canvas, 'grayscale(' + k.toFixed(3) + ') contrast(' + (1 + 1.4 * k).toFixed(3) + ')')
|
||||
filterCanvas(canvas, 'grayscale(' + k.toFixed(3) + ') contrast(' + (1 + 1.6 * k).toFixed(3) + ')')
|
||||
}
|
||||
},
|
||||
soft: {
|
||||
|
||||
@@ -24,8 +24,15 @@ import { close, copyResult, exportResult } from './index.js'
|
||||
import { loadImage } from './dom.js'
|
||||
import { pushHistory, redo, resetDraw, restoreOriginal, restoreAll, saveSnapshot, snapshotState, undo } from './history.js'
|
||||
import { applyQuickEffect, setEffectValue } from './effects.js'
|
||||
import { applyAdjust, ensureAdjustTarget, mountAdjustPanel, resetAdjust, setAdjustValue, syncAdjustControls } from './adjust.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
|
||||
|
||||
|
||||
// ============ 鼠标事件 ============
|
||||
/**
|
||||
@@ -542,6 +549,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
lw: Math.max(1, S.shapeLineWidth),
|
||||
lineWidth: Math.max(1, S.shapeLineWidth),
|
||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||
strokeOn: S.shapeStrokeOn !== false,
|
||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||
opacity: 1,
|
||||
visible: true
|
||||
@@ -747,6 +755,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
fillColor: S.shapeFillColor, // null = 跟随描边色(改主色时整块跟着变)
|
||||
lw: Math.max(1, S.shapeLineWidth),
|
||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||
strokeOn: S.shapeStrokeOn !== false,
|
||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||
opacity: 1,
|
||||
visible: true,
|
||||
@@ -892,6 +901,16 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
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)。
|
||||
* 文字对象本来就有三个颜色字段:color(文字本身)/ strokeColor(字的外描边)/
|
||||
* bgColor(文本框底色)。上一版把它们硬塞进「描边 / 填充」两格,第二格其实是
|
||||
@@ -928,9 +947,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
const fillOn = sh
|
||||
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
|
||||
: (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 {
|
||||
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,
|
||||
strokeName: '描边', fillName: '填充', bgName: '底色'
|
||||
}
|
||||
@@ -965,11 +990,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
const dot = strokeBtn.querySelector('i')
|
||||
if (dot) dot.style.backgroundColor = sl.stroke
|
||||
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
||||
// v1.17:无描边时色块画红斜杠,和「无填充」同一套视觉语言
|
||||
strokeBtn.classList.toggle('is-none', !isText && sl.strokeOn === false)
|
||||
strokeBtn.title = isText
|
||||
? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)`
|
||||
: (second
|
||||
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色`
|
||||
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`)
|
||||
: (sl.strokeOn === false
|
||||
? '描边:无(只有填充)。点开选色会自动恢复描边'
|
||||
: (second
|
||||
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色,「无」= 去掉描边`
|
||||
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`))
|
||||
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
||||
}
|
||||
@@ -1023,20 +1052,25 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
: (isText ? '正在调文字色(文字本身的颜色)' : '正在调描边色'))
|
||||
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !second }
|
||||
if (isBg) { tab.classList.toggle('is-none', !sl.bgOn); tab.hidden = !isText }
|
||||
// 描边格:文字的「描边」是第二格(上面已处理),文字色/单槽上下文不允许「无」
|
||||
if (!isFill && !isBg) tab.classList.toggle('is-none', !isText && sl.strokeOn === false)
|
||||
})
|
||||
// 「无」:形状 = 无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
||||
// (文字色没有「无」—— 字没有颜色就等于把字删了,不该给这个按钮)
|
||||
const noneBtn = runtime.el.querySelector('[data-color-none]')
|
||||
if (noneBtn) {
|
||||
const onBg = S.colorTarget === 'bg' && isText
|
||||
const onFill = S.colorTarget === 'fill' && second
|
||||
const show = onBg || onFill
|
||||
noneBtn.hidden = !show
|
||||
noneBtn.classList.toggle('active', show && (onBg ? !sl.bgOn : !sl.fillOn))
|
||||
// 「去色」(v1.19 前叫「无」):形状/钢笔 = 无描边或无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
||||
// (文字色与箭头单槽没有「去色」—— 去掉就等于把对象删了,不该给这个按钮)
|
||||
// 按集合刷(原来是右栏 + 弹层各一个,现在只剩弹层一个,写法保持不变以免将来再加面板时漏刷)
|
||||
const onBg = S.colorTarget === 'bg' && isText
|
||||
const onFill = S.colorTarget === 'fill' && second
|
||||
const onStroke = S.colorTarget === 'stroke' && !isText && strokeSlotCanBeNone()
|
||||
const showNone = onBg || onFill || onStroke
|
||||
runtime.el.querySelectorAll('[data-color-none]').forEach(noneBtn => {
|
||||
noneBtn.hidden = !showNone
|
||||
noneBtn.classList.toggle('active', showNone && (onBg ? !sl.bgOn : (onFill ? !sl.fillOn : !sl.strokeOn)))
|
||||
noneBtn.title = onBg
|
||||
? '无底色:文字后面完全透明'
|
||||
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边')
|
||||
}
|
||||
? '去色:文字后面完全透明(无底色)'
|
||||
: (onStroke
|
||||
? (sl.strokeOn === false ? '当前已是无描边;点选颜色可恢复描边' : '去色:去掉形状外框,只留内部填充')
|
||||
: (isText ? '去色:把描边宽度置 0,只留文字本身' : '去色:形状内部透明,只留描边'))
|
||||
})
|
||||
|
||||
const cur = activeColor()
|
||||
let matchPreset = false
|
||||
@@ -1045,28 +1079,34 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (on) matchPreset = true
|
||||
s.classList.toggle('active', on)
|
||||
})
|
||||
const panelHex = runtime.el.querySelector('.iwb-editor-color-hex')
|
||||
const hexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
||||
if (hexInput && document.activeElement !== hexInput) hexInput.value = cur.toUpperCase()
|
||||
// hex / 调色器按集合刷(现在只有弹层一处,写法保持不变以免将来加面板时漏刷)
|
||||
runtime.el.querySelectorAll('.iwb-editor-color-hex').forEach(el => { el.textContent = 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()))
|
||||
if (panelHex) panelHex.textContent = cur.toUpperCase()
|
||||
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 d = max - min
|
||||
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 (h < 0) h += 360
|
||||
const sv = runtime.el.querySelector('.iwb-color-sv'), hue = runtime.el.querySelector('.iwb-color-hue')
|
||||
if (sv) sv.style.backgroundColor = `hsl(${h} 100% 50%)`
|
||||
if (hue) hue.dataset.hue = h
|
||||
const hueMarker = hue && hue.querySelector('span'); if (hueMarker) hueMarker.style.top = (h / 360 * 100) + '%'
|
||||
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) + '%' }
|
||||
const custom = runtime.el.querySelector('.iwb-editor-color-custom')
|
||||
if (custom) {
|
||||
const sat = max ? d / max : 0
|
||||
runtime.el.querySelectorAll('.iwb-color-sv').forEach(sv => {
|
||||
sv.style.backgroundColor = `hsl(${h} 100% 50%)`
|
||||
const m = sv.querySelector('span')
|
||||
if (m) { m.style.left = (sat * 100) + '%'; m.style.top = ((1 - max) * 100) + '%' }
|
||||
})
|
||||
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)
|
||||
const inp = custom.querySelector('input')
|
||||
if (inp) inp.value = cur
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 画笔大小/硬度/透明曾经在侧栏也有一份,2026-11-04 起只保留工具选项栏一处,
|
||||
@@ -1149,7 +1189,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
|
||||
const sl = colorSlots()
|
||||
let html = '<span class="iwb-opt-label">描边</span>'
|
||||
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`
|
||||
+ `<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) {
|
||||
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 ? '' : ';当前无填充,选色会自动切成实心'}">`
|
||||
@@ -1389,8 +1429,10 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
btn.classList.toggle('active', !!cur === (btn.dataset.value === 'fill'))
|
||||
})
|
||||
// 文字样式按钮组与两个颜色框:选中对象的值优先,没选中就显示新建默认值
|
||||
// 只认 <button>:<select data-opt-text="fontFamily"> 没有 data-value,
|
||||
// 混进来会被算成「value 不匹配」而永远不亮,也不该被当成开关处理
|
||||
const sv = textStyleValues(selText)
|
||||
body.querySelectorAll('[data-opt-text]').forEach(btn => {
|
||||
body.querySelectorAll('button[data-opt-text]').forEach(btn => {
|
||||
const k = btn.dataset.optText
|
||||
// bgFill 是开关:active 直接看当前状态,data-value 必须随之翻面。
|
||||
// 只在 HTML 里写死 ${v.bgFill ? '0' : '1'} 而这里不更新的话,
|
||||
@@ -1426,7 +1468,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
? '填充色:与工具栏右下的填充色块是同一份'
|
||||
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
|
||||
} else {
|
||||
inp.title = '描边色:与工具栏左上的描边色块是同一份'
|
||||
// v1.17:无描边时描边色块也要置灰(和「无填充」同一套提示)
|
||||
const off = sl.strokeOn === false
|
||||
inp.classList.toggle('is-off', off)
|
||||
inp.title = off
|
||||
? '当前无描边(只有填充)。选色会自动恢复描边,也可点工具栏描边色块选「无」'
|
||||
: '描边色:与工具栏左上的描边色块是同一份'
|
||||
}
|
||||
})
|
||||
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
|
||||
@@ -1565,9 +1612,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
syncOptionBar()
|
||||
}
|
||||
|
||||
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派):
|
||||
* 形状填充 → 内部透明;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
||||
* 三种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
||||
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派;v1.17 起描边也支持):
|
||||
* 形状填充 → 内部透明;形状描边 → 不画外框;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
||||
* 四种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
||||
function applyColorNone() {
|
||||
const sl = colorSlots()
|
||||
if (sl.mode === 'text') {
|
||||
@@ -1577,9 +1624,33 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
syncOptionBar()
|
||||
return
|
||||
}
|
||||
if (S.colorTarget === 'stroke') { applyStrokeNone(); return }
|
||||
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 起同时承接「无填充」)。
|
||||
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
||||
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
||||
@@ -1597,6 +1668,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (sh && !sh.locked && sh.fill) {
|
||||
if (!skipHistory) saveSnapshot('无填充')
|
||||
sh.fill = false
|
||||
// 与「无描边」对称:描边也是无的话对象就彻底看不见了,恢复描边兜底
|
||||
if (sh.strokeOn === false) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||
renderObjects()
|
||||
}
|
||||
updateColorUI()
|
||||
@@ -1607,6 +1680,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
||||
if (kind === 'stroke') {
|
||||
S.colorTarget = 'stroke'
|
||||
// 新建默认值也恢复描边:否则「无描边」状态下改一次描边色,
|
||||
// 下一个新形状仍然是没框的,用户会以为设置没生效
|
||||
S.shapeStrokeOn = true
|
||||
applyColorChange(hex, opts)
|
||||
if (skipHistory) syncOptionBarSoon()
|
||||
else syncOptionBar()
|
||||
@@ -1687,30 +1763,52 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
saveSnapshot('填充')
|
||||
// 未闭合的钢笔路径没有可填区域:保持描边,不动视觉结果
|
||||
sh.fill = isPen ? (!!S.penFill && !!sh.closed) : !!S.rectFill
|
||||
// 用户明确点了「描边」= 要看见框:无描边的对象顺手恢复,否则点完毫无变化
|
||||
if (!sh.fill && sh.strokeOn === false) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||
renderObjects()
|
||||
// 对象的 fill 更新在 sync 之后,选择工具下按钮的激活态要再刷一次
|
||||
syncOptionBar()
|
||||
}
|
||||
}
|
||||
|
||||
/** PS 的 X 语义(v1.13.1):把选中形状的「填充色」与「描边色」对调。
|
||||
* 以前 Shift+X 绑的是「实心 ↔ 只描边」开关 —— 按下去填充被关掉、描边纹丝不动,
|
||||
* 用户的主观体验就是「填充色丢了」,再按一次才回来。用户要的是**交换两个颜色**:
|
||||
* 填充色换到描边的位置、描边色换到填充的位置,填充的开关状态不变(交换的是颜色,不是有无)。
|
||||
* 填充色仍「跟随描边色」(fillColor=null)时只有一个颜色,没有可交换的对象,只提示不动数据。 */
|
||||
/** PS 的 X 语义:把选中形状的「描边」与「填充」对调。
|
||||
* v1.13.1:以前 Shift+X 绑的是「实心 ↔ 只描边」开关,按下去填充被关掉、
|
||||
* 描边纹丝不动,用户的主观体验就是「填充色丢了」。改为**交换两个颜色**。
|
||||
* v1.17:交换的是整份状态(颜色 + 有/无),不只是颜色 ——
|
||||
* 「无填充 + 有色描边」按一下 → 「有色填充 + 无描边」,反之亦然。
|
||||
* 这样「有一边是无色」时也能用(用户反馈的第二个问题);
|
||||
* 两边都有色且填充还在跟随描边时只有一个颜色,才提示不动。
|
||||
* 「未闭合钢笔 / 箭头」没有可填内部:交换后整条路径会消失,直接提示不执行。 */
|
||||
function swapShapeColors() {
|
||||
const sh = getSelectedShape()
|
||||
if (!sh || sh.locked) return false
|
||||
if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true }
|
||||
const stroke = sh.color || S.color
|
||||
const fill = sh.fillColor || null
|
||||
if (!fill) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
||||
const canFill = sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
||||
const strokeOn = sh.strokeOn !== false
|
||||
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('交换填充与描边色')
|
||||
sh.color = fill
|
||||
S.color = fill // 描边色与主色永远同一份(v1.10 的约定)
|
||||
sh.fillColor = stroke
|
||||
S.shapeFillColor = stroke // 交换后就是独立填充色了,不再跟随描边
|
||||
// 1) 交换「有 / 无」:哪边有色,交换后就跑到另一边去
|
||||
sh.strokeOn = fillOn
|
||||
sh.fill = strokeOn && canFill
|
||||
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()
|
||||
updateFillUI()
|
||||
updateColorUI()
|
||||
syncOptionBar()
|
||||
return true
|
||||
@@ -1773,6 +1871,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (!root || root.dataset.liteBound === '1') return
|
||||
root.dataset.liteBound = '1'
|
||||
|
||||
// 图片调节面板的行由参数表生成(只做一次),DOM 里只留空容器
|
||||
mountAdjustPanel()
|
||||
|
||||
const closeMenus = () => {
|
||||
const panel = root.querySelector('.iwb-editor-export-settings')
|
||||
if (panel) panel.classList.remove('open')
|
||||
@@ -1783,6 +1884,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
// 选区命令(全选/反选/取消)在「选择」工具的选项栏里,与竖工具条时代一样走根级事件委托:
|
||||
// 三个按钮不切换工具,只调命令层(与快捷键、右键菜单同一条路径)。
|
||||
root.addEventListener('click', (e) => {
|
||||
// 图片调节「复位」:所有项归零,同时拍一步历史(resetAdjust 内部做)
|
||||
const adjReset = e.target.closest('[data-adj-reset]')
|
||||
if (adjReset) {
|
||||
e.stopPropagation()
|
||||
if (!adjReset.disabled) resetAdjust()
|
||||
return
|
||||
}
|
||||
// 快速效果(侧栏):点一下即应用,目标层与撤销由 effects.js 负责
|
||||
const fxBtn = e.target.closest('[data-fx]')
|
||||
if (fxBtn) {
|
||||
@@ -1812,17 +1920,71 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
// 快速效果强度滑杆(v1.8):input 只改像素与该行数字 —— 拖动中每帧重建图层面板会闪,
|
||||
// 缩略图与状态栏交给松开时的 renderAll。用 class 精确匹配,别误伤图层不透明度滑杆。
|
||||
const fxRangeOf = (e) => (e.target && e.target.closest ? e.target.closest('.iwb-editor-fx-range') : null)
|
||||
|
||||
// 图片调节(v1.15):滑杆与数值框共用一条写回路径。
|
||||
// 历史粒度 = 一次拖动一步:第一次 input 拍快照,change 后复位标志(否则整段拖动会
|
||||
// 留下几十步历史,Ctrl+Z 要点半天才回到调之前)。
|
||||
let adjSnapDone = false
|
||||
const adjRowOf = (el) => (el && el.closest ? el.closest('.iwb-editor-adj-row') : null)
|
||||
const adjBegin = () => {
|
||||
if (S.adjust && S.adjust.source) return true
|
||||
return Boolean(ensureAdjustTarget())
|
||||
}
|
||||
const adjSyncTwin = (row, el) => {
|
||||
const range = row.querySelector('.iwb-editor-adj-range')
|
||||
const num = row.querySelector('.iwb-editor-adj-val')
|
||||
if (!range || !num) return
|
||||
if (el === range) num.value = range.value
|
||||
else range.value = String(Number(num.value) || 0)
|
||||
}
|
||||
|
||||
root.addEventListener('input', (e) => {
|
||||
const range = fxRangeOf(e)
|
||||
if (!range) return
|
||||
if (range) {
|
||||
e.stopPropagation()
|
||||
setEffectValue(parseFloat(range.value))
|
||||
return
|
||||
}
|
||||
const adj = e.target.closest ? (e.target.closest('.iwb-editor-adj-range') || e.target.closest('.iwb-editor-adj-val')) : null
|
||||
if (!adj) return
|
||||
const row = adjRowOf(adj)
|
||||
if (!row) return
|
||||
e.stopPropagation()
|
||||
setEffectValue(parseFloat(range.value))
|
||||
if (!adjBegin()) return
|
||||
if (!adjSnapDone) { saveSnapshot('图片调节'); adjSnapDone = true }
|
||||
adjSyncTwin(row, adj)
|
||||
// preview=true:降采样算(长边 900 以内),拖动时不拖慢帧率
|
||||
setAdjustValue(row.dataset.adj, adj.value, true)
|
||||
})
|
||||
root.addEventListener('change', (e) => {
|
||||
const range = fxRangeOf(e)
|
||||
if (!range) return
|
||||
if (range) {
|
||||
e.stopPropagation()
|
||||
if (S.renderAll) S.renderAll()
|
||||
return
|
||||
}
|
||||
const adj = e.target.closest ? (e.target.closest('.iwb-editor-adj-range') || e.target.closest('.iwb-editor-adj-val')) : null
|
||||
if (!adj) return
|
||||
const row = adjRowOf(adj)
|
||||
if (!row) return
|
||||
e.stopPropagation()
|
||||
if (S.renderAll) S.renderAll()
|
||||
if (!S.adjust || !S.adjust.source) return
|
||||
adjSyncTwin(row, adj)
|
||||
// 松手:用原尺寸算一次,出精细结果(大图这一段会有几十~一百多 ms 的停顿,正常)
|
||||
setAdjustValue(row.dataset.adj, adj.value, false)
|
||||
adjSnapDone = false
|
||||
})
|
||||
// 双击名称或滑杆 = 该项归零(截图那种调色面板的通用手势)
|
||||
root.addEventListener('dblclick', (e) => {
|
||||
const hit = e.target.closest ? (e.target.closest('.iwb-editor-adj-name') || e.target.closest('.iwb-editor-adj-range')) : null
|
||||
if (!hit) return
|
||||
const row = adjRowOf(hit)
|
||||
if (!row) return
|
||||
e.stopPropagation()
|
||||
if (!S.adjust || !S.adjust.source) return
|
||||
saveSnapshot('调节归零')
|
||||
setAdjustValue(row.dataset.adj, 0, false)
|
||||
syncAdjustControls()
|
||||
})
|
||||
|
||||
const body = root.querySelector('.iwb-editor-optionbar-body')
|
||||
@@ -1861,12 +2023,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
setOptionFromControl(e.target, false)
|
||||
})
|
||||
body.addEventListener('change', (e) => {
|
||||
// 字体下拉:唯一走 change 而不是 click 的文字样式控件(<select> 没有 click 语义)
|
||||
// 字体下拉:唯一走 change 而不是 click 的文字样式控件(<select> 没有 click 语义)。
|
||||
// 这里**不能**再调 syncOptionBar():那会整体重绘选项栏、把刚操作过的 <select>
|
||||
// 换成新节点,焦点丢失、连续切换字体要反复重点。字体只影响画布,不影响其他控件取值。
|
||||
const textSel = e.target && e.target.closest ? e.target.closest('select[data-opt-text]') : null
|
||||
if (textSel) {
|
||||
e.stopPropagation()
|
||||
applyTextStyle(textSel.dataset.optText, textSel.value, true)
|
||||
syncOptionBar()
|
||||
return
|
||||
}
|
||||
const colorEl = nativeColorOf(e.target)
|
||||
@@ -1874,8 +2037,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
setOptionFromControl(e.target, true)
|
||||
})
|
||||
body.addEventListener('click', (e) => {
|
||||
// 文字样式按钮(字重 / 对齐 / 底色开关)
|
||||
const textBtn = e.target.closest('[data-opt-text]')
|
||||
// 字体下拉被点开时直接放行:它自己带 data-opt-text,早先这里用
|
||||
// closest('[data-opt-text]') 会把它当成按钮,取 dataset.value(select 上没有)= undefined
|
||||
// → applyTextStyle('fontFamily', undefined) → fontKeyOf 收敛成 'sans'。
|
||||
// 表现为「点开下拉看一眼,字体就被打回黑体」,用户报的「不能切换字体」就是这个。
|
||||
if (e.target && e.target.closest && e.target.closest('select[data-opt-text]')) return
|
||||
// 文字样式按钮(字重 / 对齐 / 底色开关)—— 只认 <button>,别把下拉框也卷进来
|
||||
const textBtn = e.target.closest('button[data-opt-text]')
|
||||
if (textBtn) {
|
||||
e.stopPropagation()
|
||||
const k = textBtn.dataset.optText
|
||||
@@ -1987,9 +2155,81 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
bindExportActions()
|
||||
bindWheelZoom()
|
||||
bindTextInput()
|
||||
bindSideResize()
|
||||
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 过滤掉) */
|
||||
function bindToolButtons() {
|
||||
// 工具
|
||||
@@ -2000,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 决定要不要吞掉这次按键 */
|
||||
export function closeColorPop() {
|
||||
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
||||
@@ -2049,8 +2320,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
}
|
||||
|
||||
/** 色板弹层(v1.3;v1.11 起同时服务描边与填充两个槽):
|
||||
* 工具栏两个色块开关;tab / hex / 吸管 / 推荐色 / 调色器 / 无填充都在这一个弹层里 */
|
||||
/** 调色面板(v1.3 弹层 → v1.16 弹层 + 右栏常驻 → v1.19 只剩弹层):
|
||||
* 结构来自 dom.js#colorSurfaceHtml,按 [data-color-surface] 逐个绑定。
|
||||
* 每个 surface 各自持有一份 HSV 拖拽状态,但取值一律从 activeColor() 现算。 */
|
||||
function bindColorPanel() {
|
||||
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')]
|
||||
@@ -2059,37 +2331,54 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
btn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop(btn.dataset.colorSlot) })
|
||||
})
|
||||
if (pop) {
|
||||
pop.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
|
||||
// 冒泡阶段拿不到「点了外面」这件事。
|
||||
// 钉住时一律不关:这就是「钉住」的全部意义(要收就再点一次图钉,或按 Esc)。
|
||||
document.addEventListener('mousedown', (e) => {
|
||||
if (S.colorPopPinned) return
|
||||
const onBtn = colorBtns.some(b => b.contains(e.target))
|
||||
if (!pop.hidden && !pop.contains(e.target) && !onBtn) closeColorPop()
|
||||
}, true)
|
||||
window.addEventListener('resize', positionColorPop)
|
||||
}
|
||||
runtime.el.querySelectorAll('[data-color-surface]').forEach(surface => bindColorSurface(surface))
|
||||
}
|
||||
|
||||
// 弹层头部:切描边/填充,或直接置为「无填充」
|
||||
if (pop) {
|
||||
pop.addEventListener('click', (e) => {
|
||||
const tab = e.target.closest('[data-color-slot]')
|
||||
if (tab && tab.classList.contains('iwb-color-pop-tab')) {
|
||||
e.stopPropagation()
|
||||
setColorTarget(tab.dataset.colorSlot)
|
||||
positionColorPop()
|
||||
return
|
||||
}
|
||||
const none = e.target.closest('[data-color-none]')
|
||||
if (none) {
|
||||
e.stopPropagation()
|
||||
applyColorNone()
|
||||
return
|
||||
}
|
||||
/** 一块调色面板的全部交互:弹层与右栏各一份,代码只有这一处 */
|
||||
function bindColorSurface(surface) {
|
||||
const isPop = surface.classList.contains('iwb-editor-color-pop')
|
||||
surface.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||
// tab 切换目标槽 / 「无」 / 常用色与最近色,统一委托:
|
||||
// 静态 12 色 + 动态插入的「最近使用」都要能点,一次性 querySelectorAll 会漏掉后者
|
||||
surface.addEventListener('click', (e) => {
|
||||
const pin = e.target.closest('[data-action="pinColorPop"]')
|
||||
if (pin) { e.stopPropagation(); setColorPopPinned(!S.colorPopPinned); return }
|
||||
const tab = e.target.closest('.iwb-color-pop-tab[data-color-slot]')
|
||||
if (tab) {
|
||||
e.stopPropagation()
|
||||
setColorTarget(tab.dataset.colorSlot)
|
||||
if (isPop) positionColorPop() // 换 tab 后弹层宽度会变,重新贴一次
|
||||
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,
|
||||
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
|
||||
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
|
||||
@@ -2104,26 +2393,10 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
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) })
|
||||
// 色块统一走委托:静态 12 色 + 动态插入的「最近使用」都要能点,
|
||||
// 一次性 querySelectorAll 绑定会漏掉后来插进来的按钮
|
||||
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 sv = surface.querySelector('.iwb-color-sv')
|
||||
const hue = surface.querySelector('.iwb-color-hue')
|
||||
if (!sv || !hue) return
|
||||
const initHsv = (() => {
|
||||
const { r, g, b } = hexToRgb(activeColor())
|
||||
const rr = r / 255, gg = g / 255, bb = b / 255
|
||||
@@ -2353,7 +2626,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
function commitPenPath() {
|
||||
if (!S.penPath || S.penPath.pts.length < 2) { S.penPath = null; renderObjects(); return }
|
||||
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 下双击
|
||||
S.shapeLayers.push(shape); S.penPath = null; renderObjects(); renderLayerPanel()
|
||||
finishCreateTool('shape', shape.id)
|
||||
|
||||
@@ -266,6 +266,7 @@ import { toast } from './commands.js'
|
||||
if (S.history.length === 0) { toast('没有可撤销的操作'); return }
|
||||
pushHistory(S.redoStack, snapshotState())
|
||||
restoreState(S.history.pop())
|
||||
if (S.onHistoryRestore) S.onHistoryRestore()
|
||||
if (S.renderAll) S.renderAll()
|
||||
}
|
||||
|
||||
@@ -275,6 +276,7 @@ import { toast } from './commands.js'
|
||||
if (S.redoStack.length === 0) { toast('没有可重做的操作'); return }
|
||||
pushHistory(S.history, snapshotState())
|
||||
restoreState(S.redoStack.pop())
|
||||
if (S.onHistoryRestore) S.onHistoryRestore()
|
||||
if (S.renderAll) S.renderAll()
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,11 @@ import { createEl, loadImage } from './dom.js'
|
||||
import { renderObjects, hideTextInput, textBounds } from './objects.js'
|
||||
import { setupCanvas } from './viewport.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 { bindFloating, positionFloating, hideSelectionContext } from './floating.js'
|
||||
import { renderFxPanel } from './effects.js'
|
||||
import { adjustCacheSize, onHistoryRestore as onAdjustHistoryRestore, renderAdjustPanel, resetAdjustCache } from './adjust.js'
|
||||
import { loadExportOptions, prepareOutput, downloadBlob, copyBlobToClipboard, bindExportUI, renderExportUI } from './export.js'
|
||||
import { loadRecentColors } from './recent-colors.js'
|
||||
import { toast } from './commands.js'
|
||||
@@ -50,6 +51,9 @@ import { toast } from './commands.js'
|
||||
S.renderAll = renderAll
|
||||
S.positionFloating = positionFloating
|
||||
S.renderFxPanel = renderFxPanel
|
||||
S.renderAdjustPanel = renderAdjustPanel
|
||||
// 撤销/重做后调节参数必须归零(详见 adjust.js#onHistoryRestore 的注释)
|
||||
S.onHistoryRestore = onAdjustHistoryRestore
|
||||
|
||||
try {
|
||||
const img = await loadImage(options.imageBase64)
|
||||
@@ -65,10 +69,15 @@ import { toast } from './commands.js'
|
||||
registerSelectionCommands()
|
||||
loadExportOptions()
|
||||
loadRecentColors()
|
||||
// v1.18:色板「钉住」状态也来自宿主 KV,和常用色/最近色一起恢复
|
||||
loadColorPopPinned()
|
||||
bindLiteUI()
|
||||
bindFloating()
|
||||
bindExportUI()
|
||||
initPanels()
|
||||
// 右栏宽度跟着用户上次拖的位置(v1.16);必须在 initPanels 之后——
|
||||
// 侧栏收起时元素虽 display:none,写 CSS 变量仍然有效,下次展开直接生效
|
||||
loadSideWidth()
|
||||
renderAll()
|
||||
} catch (e) {
|
||||
console.error('[IWB编辑器] 打开失败:', e)
|
||||
@@ -126,6 +135,9 @@ import { toast } from './commands.js'
|
||||
S.altPicker = false
|
||||
// 快速效果的基准像素属于上一张图,重开必须清掉(否则滑杆会往新图上写旧像素)
|
||||
S.fx = { key: null, value: 0, layerId: null, source: null }
|
||||
// 图片调节的基准像素同理,而且更致命:缓存 key 是图层 id,原图恒为 'base',
|
||||
// 不清就一定命中上一张图的像素(v1.15.1 修「调新图变回旧图」)
|
||||
resetAdjustCache()
|
||||
S.zCounter = Math.max(S.layers.length - 1, 0)
|
||||
S.placingImage = null
|
||||
S.placingHandle = null
|
||||
@@ -154,6 +166,8 @@ import { toast } from './commands.js'
|
||||
renderObjects()
|
||||
renderLayerPanel()
|
||||
renderFxPanel()
|
||||
// 调节面板跟着图层走:新建/切换/删除图层都要刷新 target 与滑块值
|
||||
renderAdjustPanel()
|
||||
renderOptionBar()
|
||||
updateStatusbar()
|
||||
renderExportUI()
|
||||
@@ -218,6 +232,9 @@ import { toast } from './commands.js'
|
||||
S.pickerComposite = null
|
||||
// 2b) 快速效果的基准像素:又一张全幅位图,不释放就白占一份图大小的内存
|
||||
S.fx = { key: null, value: 0, layerId: null, source: null }
|
||||
// 2c) 图片调节的基准像素与预览副本(两张全幅位图)+ 按 layer.id 的缓存 Map。
|
||||
// 缓存必须清,否则下次打开新图时 'base' 会命中这份旧像素(v1.15.1)
|
||||
resetAdjustCache()
|
||||
// 3) 交互态复位:关闭后 window mouseup 等全局监听仍活着,靠标志位保证不落到绘制路径
|
||||
S.isDrawing = false
|
||||
S.panning = false
|
||||
@@ -323,7 +340,7 @@ import { toast } from './commands.js'
|
||||
opacity: l.opacity == null ? 1 : l.opacity,
|
||||
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
||||
})),
|
||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color, 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 => ({
|
||||
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,
|
||||
@@ -373,6 +390,14 @@ import { toast } from './commands.js'
|
||||
lastExport: S.lastExport ? { ...S.lastExport } : null,
|
||||
// 快速效果的可重调状态:hasSource=false 表示还没点过效果(滑杆应置灰)
|
||||
fx: { key: S.fx.key, value: S.fx.value, layerId: S.fx.layerId, hasSource: Boolean(S.fx.source) },
|
||||
// v1.15 图片调节:params 是 11 项当前值,hasSource 决定面板是否可用
|
||||
adjust: {
|
||||
layerId: S.adjust ? S.adjust.layerId : null,
|
||||
hasSource: Boolean(S.adjust && S.adjust.source),
|
||||
params: S.adjust && S.adjust.params ? { ...S.adjust.params } : null
|
||||
},
|
||||
// 调节基准缓存条数:退出编辑器后必须是 0(否则下一张图会拿到上一张的像素)
|
||||
adjustCacheSize: adjustCacheSize(),
|
||||
interaction: S.interaction,
|
||||
ants: !!S._antFrame,
|
||||
view: S.viewX !== null ? [Math.round(S.viewX), Math.round(S.viewY)] : null,
|
||||
|
||||
@@ -334,6 +334,8 @@ export function setActiveLayer(id) {
|
||||
// 否则用户会在新层上拖出一个属于旧层的像素结果(v1.8)。
|
||||
// 走注入而不是直接 import effects.js —— 后者已经 import 本模块,硬连会成环。
|
||||
if (S.renderFxPanel) S.renderFxPanel()
|
||||
// 图片调节面板同样按「当前层」走:切层后 target 名与滑块值都要换成新层的
|
||||
if (S.renderAdjustPanel) S.renderAdjustPanel()
|
||||
}
|
||||
|
||||
/** 添加位图图层(导入图片)— 便利版:一步落层,不再需要 Enter 二次确认
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* recent-colors.js - 最近使用颜色(v1.9)
|
||||
*
|
||||
* 只依赖 state.js(叶子模块):tools.js 在改色时调用 rememberColor(),
|
||||
* color pop 打开时 renderRecentColors() 把最近 8 个色块铺出来。
|
||||
* color pop 打开时 renderRecentColors() 把最近的色块铺出来。
|
||||
* 持久化走宿主 ctx.settings(小 KV,不放像素,符合宿主存储约定)。
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
|
||||
import { S, runtime } from './state.js'
|
||||
|
||||
const MAX = 8
|
||||
// v1.19:上限 6 → 16。色板弹层改成 8 列网格,16 个正好铺满两排
|
||||
// (v1.18 为「更紧凑」收到 6,是因为当时只有一排的空间;吸管+色值移到头部后省出这一排)。
|
||||
const MAX = 16
|
||||
const KEY = 'recentColors'
|
||||
|
||||
function valid(hex) {
|
||||
@@ -29,7 +31,7 @@ import { S, runtime } from './state.js'
|
||||
renderRecentColors()
|
||||
}
|
||||
|
||||
/** 记一个颜色:去重后置顶,最多 8 个 */
|
||||
/** 记一个颜色:去重后置顶,最多 MAX 个 */
|
||||
export function rememberColor(hex) {
|
||||
if (!valid(hex)) return
|
||||
const c = String(hex).toLowerCase()
|
||||
@@ -43,12 +45,19 @@ import { S, runtime } from './state.js'
|
||||
renderRecentColors()
|
||||
}
|
||||
|
||||
export function renderRecentColors() {
|
||||
const wrap = runtime.el && runtime.el.querySelector('.iwb-editor-recent-colors')
|
||||
if (!wrap) return
|
||||
const list = S.recentColors || []
|
||||
wrap.innerHTML = list.map(c =>
|
||||
`<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="最近使用 ${c}"></button>`
|
||||
).join('')
|
||||
export function renderRecentColors() {
|
||||
if (!runtime.el) return
|
||||
const wraps = runtime.el.querySelectorAll('.iwb-editor-recent-colors')
|
||||
if (!wraps.length) return
|
||||
const list = S.recentColors || []
|
||||
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
|
||||
}
|
||||
// 没有最近色时整组一起藏,否则下面留一块空白,看起来像没加载出来
|
||||
const group = wrap.closest('.iwb-color-group')
|
||||
if (group) group.hidden = !list.length
|
||||
})
|
||||
}
|
||||
@@ -36,11 +36,18 @@
|
||||
// 拖强度滑杆时一律从 source 重算,绝不在上一次结果上叠加(否则来回拖会越拖越糊)。
|
||||
// layerId 用于判断源是否还对得上当前目标层:切层后滑杆自动置灰,切回即恢复。
|
||||
fx: { key: null, value: 0, layerId: null, source: null },
|
||||
// v1.15 图片调节:连续调色(曝光/对比度/白平衡…)。source 是原尺寸基准,
|
||||
// previewCanvas 是它的降采样副本 —— 拖动滑杆用小的算(6.7ms),松手才用原图算(几十~上百 ms)。
|
||||
// 两者都只做「输入」,结果永远从基准重算,不在上一次结果上叠加。
|
||||
adjust: { layerId: null, source: null, previewCanvas: null, params: null },
|
||||
rectFill: false, // 矩形/圆形是否实心填充
|
||||
penFill: true, // 钢笔闭合路径是否实心填充(只对闭合路径有意义)
|
||||
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
||||
// v1.17:默认是否画描边。关掉后形状只剩填充(「无描边」),
|
||||
// 对象上另存 strokeOn,老对象没有这个字段一律视为有描边。
|
||||
shapeStrokeOn: true,
|
||||
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||
@@ -49,6 +56,12 @@
|
||||
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
|
||||
// 否则「三个地方各调各的颜色」会一直存在。
|
||||
colorTarget: 'stroke', // stroke | fill
|
||||
// v1.18:色板弹层是否「钉住」。钉住后点画布/点别处都不收起,方便连着调几处颜色。
|
||||
// 存宿主 KV(跨会话记住):钉过一次就一直钉着,下次打开仍生效。
|
||||
colorPopPinned: false,
|
||||
// v1.16:右侧栏宽度(px)。0 = 按默认值走,打开编辑器时从宿主 KV 恢复。
|
||||
// 宽度统一落在 CSS 变量 --iwb-side-w 上,不再各条规则各写一个魔数。
|
||||
sideWidth: 0,
|
||||
textSize: 32, // 新建文字的字号 px
|
||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||
textWeight: 'bold', // bold | normal | 900
|
||||
@@ -60,7 +73,7 @@
|
||||
textBgFill: TEXT_DEFAULTS.bgFill, // 底色块
|
||||
textBgColor: TEXT_DEFAULTS.bgColor, // 中性近黑,不再是纯黑 #000000
|
||||
textBgAlpha: TEXT_DEFAULTS.bgAlpha, // 底色透明度(色块按这个不透明度显示,所见即所得)
|
||||
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
||||
// 最近使用颜色(最多 6 个,存 ctx.settings,跨会话保留)
|
||||
recentColors: [],
|
||||
// 图层系统
|
||||
layers: [], // 位图图层数组 [{ id, name, canvas, ctx, opacity, visible, z }]
|
||||
@@ -136,6 +149,10 @@
|
||||
exportOptions: null, // { preset, format, bg, maxKB, size },来自 ctx.settings
|
||||
interaction: 'idle', // 轻量交互状态机:idle | marquee | lasso | placing | cropping
|
||||
renderAll: null, // 由 index.js 注入的统一重绘出口
|
||||
// 撤销/重做后由 history.js 调用:调节基准与参数必须跟着历史走,
|
||||
// 否则「撤销把像素还原了、滑杆还显示 +80」—— 参数与画面对不上,再拖一次就叠加。
|
||||
// 用回调而不是直接 import,避免 history ↔ adjust 循环依赖。
|
||||
onHistoryRestore: null,
|
||||
guides: null, // 拖动吸附参考线(图片坐标,松手清空):[{axis:'x'|'y', at, from, to}]
|
||||
lastExport: null // 观测口:{ bytes, width, height, format, preset }
|
||||
}
|
||||
|
||||
@@ -201,9 +201,18 @@ import { rememberColor } from './recent-colors.js'
|
||||
ctx.lineWidth = s.lw
|
||||
ctx.lineCap = 'round'
|
||||
ctx.lineJoin = 'round'
|
||||
// v1.17:无描边(strokeOn === false)。老对象没有这个字段,一律当有描边。
|
||||
// 注意不能靠 lineWidth = 0 实现:canvas 会忽略 0 从而保持上一次的值。
|
||||
const strokeOn = s.strokeOn !== false
|
||||
if (s.type === 'pen') {
|
||||
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') {
|
||||
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)
|
||||
@@ -211,10 +220,10 @@ import { rememberColor } from './recent-colors.js'
|
||||
ctx.beginPath()
|
||||
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||
ctx.stroke()
|
||||
if (strokeOn) ctx.stroke()
|
||||
} else {
|
||||
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') {
|
||||
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.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() }
|
||||
ctx.stroke()
|
||||
} else {
|
||||
if (strokeOn) ctx.stroke()
|
||||
} else if (strokeOn) {
|
||||
// 箭头:没有可填内部,去掉描边等于不画(UI 也不提供这个入口)
|
||||
ctx.fillStyle = strokeOf(s)
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(s.x1, s.y1)
|
||||
@@ -424,9 +434,13 @@ import { rememberColor } from './recent-colors.js'
|
||||
renderObjects()
|
||||
}
|
||||
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()
|
||||
sh.color = S.color
|
||||
if (revive) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||
renderObjects()
|
||||
}
|
||||
}
|
||||
|
||||
+869
-150
File diff suppressed because it is too large.
Load diff
@@ -183,10 +183,24 @@ if (!SKIP_PASTE) {
|
||||
(await page.locator('.iwb-editor-header .iwb-editor-commands').count()) === 0,
|
||||
'layerBtn=' + await page.locator('.iwb-editor-layer-btn').count())
|
||||
|
||||
const toolsTail = await page.evaluate(() => Array.from(document.querySelectorAll('.iwb-editor-tools > *'))
|
||||
.slice(-2).map((n) => n.dataset.action || n.className))
|
||||
check('工具栏最右两个按钮是「适应窗口 / 收起侧栏」',
|
||||
JSON.stringify(toolsTail) === JSON.stringify(['zoomFit', 'togglePanels']), JSON.stringify(toolsTail))
|
||||
// v1.18(用户 2026-11-10):撤销 / 重做 / 还原 从顶栏搬到工具条最右,
|
||||
// 「适应窗口 / 收起侧栏」退到它前面两位。这里断言「末尾是撤销组、视图按钮在其前」
|
||||
// —— 光看版本号挡不住产物没重建。
|
||||
const toolsOrder = await page.evaluate(() => {
|
||||
const kids = Array.from(document.querySelectorAll('.iwb-editor-tools > *'))
|
||||
const acts = kids.filter((n) => n.dataset && n.dataset.action).map((n) => n.dataset.action)
|
||||
const hist = kids[kids.length - 1]
|
||||
return {
|
||||
tail: acts.slice(-2),
|
||||
lastIsHistory: Boolean(hist && hist.classList.contains('iwb-editor-history')),
|
||||
histActs: [...(hist ? hist.querySelectorAll('[data-action]') : [])].map((b) => b.dataset.action),
|
||||
headerHasHistory: Boolean(document.querySelector('.iwb-editor-header .iwb-editor-history')),
|
||||
}
|
||||
})
|
||||
check('工具栏最右是「撤销/重做/还原」组(视图按钮在其前)',
|
||||
JSON.stringify(toolsOrder.tail) === JSON.stringify(['zoomFit', 'togglePanels']) &&
|
||||
toolsOrder.lastIsHistory && toolsOrder.histActs.join(',') === 'undo,redo,reset' &&
|
||||
!toolsOrder.headerHasHistory, JSON.stringify(toolsOrder))
|
||||
|
||||
const before = await panelSeq()
|
||||
const activeName = await page.evaluate(() => document.querySelector('.iwb-editor-layer-list .iwb-layer-item.active .iwb-layer-name')?.textContent)
|
||||
@@ -206,6 +220,102 @@ if (!SKIP_PASTE) {
|
||||
check('Ctrl+Shift+] 置顶生效', (await panelSeq()) !== afterBottom, await panelSeq())
|
||||
check('排序后仍只有一个选中项', (await activeCount()) === 1, 'active=' + await activeCount())
|
||||
|
||||
// v1.15 图片调节:真站确认面板存在、11 项按参数表生成(DOM 由 adjust.js 生成,
|
||||
// 构建时漏带就会是 0 行 —— 这类「打包产物缺模块」只有真站能发现)
|
||||
const adjRowCount = await page.locator('.iwb-editor-adj-row').count()
|
||||
const adjNames = await page.locator('.iwb-editor-adj-name').allTextContents()
|
||||
check('右侧栏「图片调节」11 项齐全',
|
||||
adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度',
|
||||
'rows=' + adjRowCount + ' ' + adjNames.join('/'))
|
||||
check('调节面板认到了作用层(不是「无图层」)',
|
||||
(await page.locator('.iwb-editor-adj-target').textContent()) !== '无图层',
|
||||
await page.locator('.iwb-editor-adj-target').textContent())
|
||||
|
||||
// v1.19:右栏常驻调色面板已删(用户 2026-11-10),颜色只剩工具栏弹层一处。
|
||||
// 真站里 DOM 与 CSS 分别打包,这里同时验「右栏干净」和「弹层头部一行 / 16 色 8 列」——
|
||||
// 样式漏打包时,头部会退回竖排或色块掉成 6 列,这条会直接露出来。
|
||||
const sideColor = await page.evaluate(() => ({
|
||||
hasSide: Boolean(document.querySelector('.iwb-editor-left [data-color-surface]')),
|
||||
firstSection: (document.querySelector('.iwb-editor-left > section') || {}).className || '',
|
||||
}))
|
||||
check('右栏调色模块已删(第一个模块是图片调节)',
|
||||
sideColor.hasSide === false && /iwb-editor-adj/.test(sideColor.firstSection),
|
||||
JSON.stringify(sideColor))
|
||||
|
||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||
await page.waitForTimeout(240)
|
||||
const popShape = await page.evaluate(() => {
|
||||
const pop = document.querySelector('.iwb-editor-color-pop')
|
||||
if (!pop) return null
|
||||
const r = (el) => el.getBoundingClientRect()
|
||||
const head = r(pop.querySelector('.iwb-color-pop-head'))
|
||||
const items = [pop.querySelector('[data-action="palettePick"]'),
|
||||
pop.querySelector('.iwb-editor-color-hex-input'),
|
||||
pop.querySelector('[data-action="pinColorPop"]')].map((el) => {
|
||||
const b = r(el)
|
||||
return { c: b.top + b.height / 2, l: b.left, r: b.right }
|
||||
})
|
||||
const sw = [...pop.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
|
||||
return {
|
||||
w: Math.round(r(pop).width),
|
||||
sameRow: items.every((it) =>
|
||||
Math.abs(it.c - (head.top + head.height / 2)) < 3 && it.l >= head.left - 1 && it.r <= head.right + 1),
|
||||
common: sw.length,
|
||||
cols: new Set(sw.map((b) => Math.round(r(b).left))).size,
|
||||
swatch: sw.length ? Math.round(r(sw[0]).width) : 0,
|
||||
}
|
||||
})
|
||||
check('色板弹层:头部一行(吸管 / 色值 / 图钉同排)+ 常用色 16 个 8 列',
|
||||
Boolean(popShape) && popShape.sameRow && popShape.common === 16 &&
|
||||
popShape.cols === 8 && popShape.swatch === 20 && popShape.w === 440,
|
||||
JSON.stringify(popShape))
|
||||
await page.keyboard.press('Escape')
|
||||
await page.waitForTimeout(140)
|
||||
|
||||
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 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
||||
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
||||
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||||
|
||||
@@ -139,13 +139,14 @@ check('打开编辑器默认只有「原图」1 层,且状态栏不再写「
|
||||
JSON.stringify((await dbg()).layers.map(l => l.name)))
|
||||
|
||||
// v1.3(用户裁定 2026-11-05):调色板从侧栏搬进工具栏弹层,侧栏只剩缩放
|
||||
check('调色板已搬进工具栏:侧栏只剩缩放,SV/色相/推荐色都在弹层里',
|
||||
// v1.19(用户 2026-11-10):右栏那份常驻调色面板删掉,颜色只剩弹层一处
|
||||
check('调色板只在工具栏弹层:右栏没有调色模块,SV/色相/16 个常用色都在弹层里',
|
||||
await page.evaluate(() => {
|
||||
const q = (s) => Boolean(document.querySelector(s))
|
||||
return !q('.iwb-editor-left .iwb-editor-color-panel') &&
|
||||
return !q('.iwb-editor-left [data-color-surface]') && !q('.iwb-editor-left .iwb-editor-colors') &&
|
||||
q('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]') &&
|
||||
q('.iwb-editor-color-pop .iwb-color-sv') && q('.iwb-editor-color-pop .iwb-color-hue') &&
|
||||
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-panel-swatch').length === 12 &&
|
||||
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-swatches [data-panel-color]').length === 16 &&
|
||||
q('.iwb-editor-zoom') &&
|
||||
!q('.iwb-editor-brush-size') && !q('.iwb-editor-brush-num') &&
|
||||
document.querySelectorAll('.iwb-editor-brush-preset').length === 0
|
||||
@@ -193,6 +194,141 @@ check('色板弹层默认收起;点工具栏色点弹出、且整块在视口
|
||||
return inView && !(await pop.isVisible()) ? true : 'box=' + JSON.stringify(box)
|
||||
})())
|
||||
|
||||
// ---------- v1.18 / v1.19 色板弹层布局(用户 2026-11-10) ----------
|
||||
// v1.18:「加钉住」「三项不写标题、用细横线分割」
|
||||
// v1.19:「去色放钉住左边、竖线分割」「吸色与色值放在钉住那一排」「宽度再多一点,
|
||||
// 颜色一排 8 个,常用色多加 4 个」「最近色放两排」
|
||||
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 r = (el) => el.getBoundingClientRect()
|
||||
const none = pop.querySelector('[data-color-none]')
|
||||
// 空画布(没选中对象)时「去色」是隐藏的(只有可去色的上下文才给这个按钮),
|
||||
// 这里临时显出来量几何,量完还原 —— 否则 rect 全是 0,位置断言恒假。
|
||||
const noneWasHidden = none.hidden
|
||||
if (noneWasHidden) none.hidden = false
|
||||
const picker = r(pop.querySelector('.iwb-color-pop-picker'))
|
||||
const side = r(pop.querySelector('.iwb-color-pop-side'))
|
||||
const head = r(pop.querySelector('.iwb-color-pop-head'))
|
||||
const eye = pop.querySelector('[data-action="palettePick"]')
|
||||
const hex = pop.querySelector('.iwb-editor-color-hex-input')
|
||||
const pin = pop.querySelector('[data-action="pinColorPop"]')
|
||||
// 头部一行:吸管 / 色值 / 去色 / 图钉 的竖直中心都必须落在头部这条线上
|
||||
const cy = (el) => r(el).top + r(el).height / 2
|
||||
const headOneRow = [eye, hex, none, pin].every((el) =>
|
||||
Math.abs(cy(el) - (head.top + head.height / 2)) < 3 &&
|
||||
r(el).left >= head.left - 1 && r(el).right <= head.right + 1)
|
||||
const bars = [...pop.querySelectorAll('.iwb-color-pop-bar')].map(r)
|
||||
const noneLeftOfPin = r(none).right <= r(pin).left
|
||||
const barBetweenNonePin = bars.some((b) =>
|
||||
b.left >= r(none).right - 1 && b.right <= r(pin).left + 1 && b.height > 8)
|
||||
// 文字工具会多出「底色」tab(三格同显):临时显出来验头部不横扫溢出,
|
||||
// 否则「吸管 + 色值 + 去色 + 图钉」在窄面板里会把图钉挤出弹层。
|
||||
const bgTab = pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]')
|
||||
const bgWasHidden = bgTab.hidden
|
||||
const headEl = pop.querySelector('.iwb-color-pop-head')
|
||||
if (bgWasHidden) bgTab.hidden = false
|
||||
// 注意用元素本身读 scrollWidth/clientWidth —— DOMRect 上没有这两个属性,写 head.scrollWidth
|
||||
// 会拿到 undefined,比较恒为 false(本次就是这样白跑了两轮)
|
||||
const headFitsThreeTabs = headEl.scrollWidth <= headEl.clientWidth + 1 &&
|
||||
[none, pin].every((el) => r(el).right <= head.right + 1)
|
||||
const headThreeTabsWidth = headEl.scrollWidth
|
||||
const headDbg = {
|
||||
client: pop.querySelector('.iwb-color-pop-head').clientWidth,
|
||||
scroll: pop.querySelector('.iwb-color-pop-head').scrollWidth,
|
||||
tabs: [...pop.querySelectorAll('.iwb-color-pop-tab')].map((t) => Math.round(r(t).width)),
|
||||
hex: Math.round(r(hex).width),
|
||||
popW: Math.round(r(pop).width),
|
||||
headRight: Math.round(head.right), noneR: Math.round(r(none).right), pinR: Math.round(r(pin).right),
|
||||
}
|
||||
if (bgWasHidden) bgTab.hidden = true
|
||||
const sw = [...pop.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
|
||||
const row1 = sw.slice(0, 8).map((b) => Math.round(r(b).top))
|
||||
const row2 = sw.slice(8).map((b) => Math.round(r(b).top))
|
||||
// 「最近」没有历史色时整组(含外层 group)都是 hidden,量不出网格;
|
||||
// 这里临时铺满 16 个量完再还原 —— 只解 wrap 的 hidden 不够,外层还压着一层
|
||||
const rec = pop.querySelector('.iwb-editor-recent-colors')
|
||||
const recGroup = rec.closest('.iwb-color-group')
|
||||
const recWasHidden = rec.hidden
|
||||
const grpWasHidden = Boolean(recGroup && recGroup.hidden)
|
||||
if (recWasHidden) {
|
||||
rec.hidden = false
|
||||
if (recGroup) recGroup.hidden = false
|
||||
rec.innerHTML = '<button class="iwb-editor-color-panel-swatch"></button>'.repeat(16)
|
||||
}
|
||||
const recRows = new Set([...rec.querySelectorAll('.iwb-editor-color-panel-swatch')]
|
||||
.map((b) => Math.round(r(b).top))).size
|
||||
const recCols = new Set([...rec.querySelectorAll('.iwb-editor-color-panel-swatch')]
|
||||
.map((b) => Math.round(r(b).left))).size
|
||||
if (recWasHidden) {
|
||||
rec.innerHTML = ''
|
||||
rec.hidden = true
|
||||
if (grpWasHidden && recGroup) recGroup.hidden = true
|
||||
}
|
||||
const out = {
|
||||
w: Math.round(r(pop).width),
|
||||
h: Math.round(r(pop).height),
|
||||
headOneRow,
|
||||
headRows: [head.top, head.bottom, head.left, head.right].map(Math.round),
|
||||
items: [eye, hex, none, pin].map((el) => [r(el).top, r(el).bottom, r(el).left, r(el).right].map(Math.round)),
|
||||
sideInRight: Math.round(side.left) >= Math.round(picker.right),
|
||||
noneLeftOfPin,
|
||||
barBetweenNonePin,
|
||||
headFitsThreeTabs, headThreeTabsWidth, headDbg,
|
||||
common: sw.length,
|
||||
twoRows: row1.length === 8 && row2.length === 8 &&
|
||||
new Set(row1).size === 1 && new Set(row2).size === 1 && row1[0] < row2[0],
|
||||
cols: new Set(sw.map((b) => Math.round(r(b).left))).size,
|
||||
recRows, recCols,
|
||||
dividers: [...pop.querySelectorAll('.iwb-color-pop-side > * + *')].map((g) => getComputedStyle(g).borderTopWidth),
|
||||
labelsVisible: [...pop.querySelectorAll('.iwb-color-group-label')].filter((l) => l.offsetParent !== null).length,
|
||||
swatch: Math.round(r(sw[0]).width),
|
||||
}
|
||||
if (noneWasHidden) none.hidden = true
|
||||
return out
|
||||
})
|
||||
check('色板头部一行装完:吸管 + 色值 + 去色 + 图钉同一排,「去色」在图钉左边且有竖线隔开',
|
||||
popLayout.headOneRow && popLayout.noneLeftOfPin && popLayout.barBetweenNonePin && popLayout.headFitsThreeTabs,
|
||||
JSON.stringify(popLayout))
|
||||
check('常用色 8 列 × 2 行(16 个),最近色也是 8 列两排,块间 1px 细线且无小标题',
|
||||
popLayout.common === 16 && popLayout.twoRows && popLayout.cols === 8 &&
|
||||
popLayout.recCols === 8 && popLayout.recRows === 2 &&
|
||||
popLayout.labelsVisible === 0 && popLayout.dividers.every((d) => d === '1px'),
|
||||
JSON.stringify(popLayout))
|
||||
check('色块区在取色器右侧,弹层宽高在预期区间(比 v1.18 的 380×153 宽一档)',
|
||||
popLayout.sideInRight && popLayout.w >= 410 && popLayout.w <= 470 && popLayout.h <= 178 &&
|
||||
popLayout.swatch === 20,
|
||||
'w=' + popLayout.w + ' h=' + popLayout.h + ' swatch=' + popLayout.swatch)
|
||||
// 开发用:ANNOT_SHOT=/tmp/pop.png 出一张色板弹层截图(验证布局)
|
||||
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) => {
|
||||
await page.mouse.move(x1, y1)
|
||||
await page.mouse.down()
|
||||
@@ -672,10 +808,9 @@ check('适应窗口后图片底边不被工具条遮挡', await page.evaluate(()
|
||||
check('顶栏输出/导出按钮组贴最右侧(用户裁定 2026-11-04)', await page.evaluate(() => {
|
||||
const hdr = document.querySelector('.iwb-editor-header')
|
||||
const ex = document.querySelector('.iwb-editor-header > .iwb-editor-export-actions')
|
||||
const hist = document.querySelector('.iwb-editor-header > .iwb-editor-history')
|
||||
if (!hdr || !ex || !hist) return false
|
||||
if (!hdr || !ex) return false
|
||||
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,表现为「橡皮不能擦」
|
||||
@@ -743,11 +878,15 @@ check('顶栏不再有图层层级按钮;视图快捷搬到画布工具栏最
|
||||
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 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"]') &&
|
||||
hdrLayerBtns === 0 && !hdrAdd && addBtns === 4 &&
|
||||
!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="addBitmapLayer"]') &&
|
||||
q('.iwb-editor-layer-panel-header [data-action="mergeLayers"]') &&
|
||||
@@ -755,7 +894,7 @@ check('顶栏不再有图层层级按钮;视图快捷搬到画布工具栏最
|
||||
}))
|
||||
|
||||
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
|
||||
const paths = svg.querySelectorAll('path').length
|
||||
const polys = Array.from(svg.querySelectorAll('polyline')).map(p => p.getAttribute('points')).join('|')
|
||||
@@ -1001,7 +1140,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
|
||||
if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状'
|
||||
const h0 = (await dbg()).history
|
||||
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.down()
|
||||
await page.mouse.move(sv.x + sv.width * 0.9, sv.y + sv.height * 0.85, { steps: 20 })
|
||||
@@ -1018,24 +1157,45 @@ await page.keyboard.press('Control+z') // 撤销上一步新建的矩形,恢
|
||||
|
||||
// ---- v1.2.9:会话组(新建/覆盖/退出)移到顶栏最左 + 图层 PS 快捷键 ----
|
||||
|
||||
check('顶栏:标题最前 → 新建/覆盖/退出(统一中性色)→ 竖分隔 → 撤销组,右侧只剩 输出+导出', await page.evaluate(() => {
|
||||
check('顶栏:标题 → 新建/覆盖/退出(统一中性色),撤销组已搬去工具条,右侧只剩 输出+导出', await page.evaluate(() => {
|
||||
const q = (s) => document.querySelector(s)
|
||||
const session = q('.iwb-editor-header > .iwb-editor-session')
|
||||
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"]')
|
||||
if (!session || !title || !hist || !dl) return false
|
||||
const t = title.getBoundingClientRect(), s = session.getBoundingClientRect(), h = hist.getBoundingClientRect()
|
||||
if (!session || !title || !dl) return false
|
||||
const t = title.getBoundingClientRect(), s = session.getBoundingClientRect()
|
||||
const btns = Array.from(session.querySelectorAll('.iwb-editor-btn')).map(b => b.dataset.action).join(',')
|
||||
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') &&
|
||||
bg('.iwb-editor-header .iwb-editor-btn-replace') === bg('.iwb-editor-header .iwb-editor-btn-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') &&
|
||||
unified && dl.textContent.trim() === '导出' &&
|
||||
!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 () => {
|
||||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||||
const ok = await page.evaluate(() => {
|
||||
@@ -1748,6 +1908,27 @@ check('下拉切换字体写到选中文字,并同步「新建文字默认字
|
||||
famDbg.texts[0].fontFamily === 'kai' && famDbg.textDefaults.family === 'kai',
|
||||
'obj=' + famDbg.texts[0].fontFamily + ' default=' + famDbg.textDefaults.family)
|
||||
|
||||
// 真实点击下拉框(不选任何项)不能改动字体。
|
||||
// 这条是给 v1.14.1 兜底的:click 委托原先用 closest('[data-opt-text]') 判断「文字样式按钮」,
|
||||
// <select> 自己带这个属性 → 被当成按钮 → 取 dataset.value(select 上没有)= undefined
|
||||
// → applyTextStyle('fontFamily', undefined) → fontKeyOf 收敛成 'sans'。
|
||||
// 症状是「点开下拉看一眼,字体就被打回黑体」,而程序化 selectOption 直接派发 change、
|
||||
// 绕过了 click,所以 v1.14.0 的 5 条字体用例全绿却漏掉了它。
|
||||
await page.evaluate((s) => { document.querySelector(s).__probeMark = 'origin' }, FAM_SEL)
|
||||
await page.locator(FAM_SEL).click({ force: true })
|
||||
await page.waitForTimeout(200)
|
||||
const famClickDbg = await dbg()
|
||||
const famNodeKept = await page.evaluate((s) => {
|
||||
const el = document.querySelector(s)
|
||||
return Boolean(el && el.__probeMark === 'origin')
|
||||
}, FAM_SEL)
|
||||
const famValKept = await page.locator(FAM_SEL).inputValue()
|
||||
check('点开字体下拉不会改动字体(下拉不是按钮,不能被 click 委托当成开关)',
|
||||
famClickDbg.texts[0].fontFamily === 'kai' && famValKept === 'kai',
|
||||
'obj=' + famClickDbg.texts[0].fontFamily + ' select=' + famValKept)
|
||||
check('切换字体不重建选项栏(连续切换不必反复重点、焦点不丢)', famNodeKept, 'node replaced=' + !famNodeKept)
|
||||
await page.evaluate(() => { if (document.activeElement && document.activeElement.blur) document.activeElement.blur() })
|
||||
|
||||
// 一次切换 = 一步历史
|
||||
// 注意断言只查对象、不查 textDefaults:快照(history.js#snapshotState)只存
|
||||
// texts/shapes/bitmaps/layerOrder,不含「新建文字默认值」—— 字重、对齐、行距
|
||||
@@ -1962,7 +2143,7 @@ check('点文字的「描边」格:色板目标是描边(tab 写「描边」
|
||||
popTextTarget.bgVisible && popTextTarget.noneVisible, JSON.stringify(popTextTarget))
|
||||
|
||||
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.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
@@ -1998,7 +2179,7 @@ const popBgTarget = await page.evaluate(() => {
|
||||
check('点文字的「底色」格:色板切到底色', popBgTarget.bgActive && popBgTarget.label === '底色', JSON.stringify(popBgTarget))
|
||||
|
||||
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.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
@@ -2024,7 +2205,7 @@ check('底色格显示真实颜色(半透明显示,不是实心块)',
|
||||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||
await page.waitForTimeout(200)
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||
el.value = '#ff00aa'
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
@@ -2041,12 +2222,12 @@ check('文字色 / 描边色 / 底色三格互不串(改一格不动另外两
|
||||
// 「无」在底色格 = 关掉底色块,颜色留着
|
||||
await page.locator('.iwb-editor-color-btn[data-color-slot="bg"]').click()
|
||||
await page.waitForTimeout(200)
|
||||
await page.evaluate(() => document.querySelector('[data-color-none]').click())
|
||||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||
await page.waitForTimeout(260)
|
||||
const bgNone = await page.evaluate(() => {
|
||||
const t = window.__iwbEditor.__debug().texts[0]
|
||||
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="bg"]')
|
||||
return { bgFill: t.bgFill, bgColor: t.bgColor, cls: chip.className, noneActive: document.querySelector('[data-color-none]').classList.contains('active') }
|
||||
return { bgFill: t.bgFill, bgColor: t.bgColor, cls: chip.className, noneActive: document.querySelector('.iwb-editor-color-pop [data-color-none]').classList.contains('active') }
|
||||
})
|
||||
check('底色格点「无」:关掉底色块、颜色留着,格子回到斜杠态',
|
||||
bgNone.bgFill === false && bgNone.bgColor === '#123456' && /is-none/.test(bgNone.cls) && bgNone.noneActive,
|
||||
@@ -2243,7 +2424,24 @@ await page.waitForTimeout(150)
|
||||
await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click()
|
||||
await page.waitForTimeout(200)
|
||||
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()
|
||||
// 开发用:ANNOT_SHOT2=/tmp/pop-full.png 出一张「去色可见 + 最近色铺满两排」的完整效果图。
|
||||
// 最近色要长期用才攒得满,这里临时补到 16 个纯为出图,不改 S.recentColors / settings。
|
||||
if (process.env.ANNOT_SHOT2) {
|
||||
await page.evaluate(() => {
|
||||
const rec = document.querySelector('.iwb-editor-color-pop .iwb-editor-recent-colors')
|
||||
const group = rec.closest('.iwb-color-group')
|
||||
const list = ['#ffd400', '#e34d59', '#1677ff', '#0f9d58', '#6b4fbb', '#c0392b',
|
||||
'#ff8a00', '#4cd964', '#00bfa5', '#4488ff', '#aa44ff', '#ff66aa',
|
||||
'#d0d0d0', '#808080', '#ffffff', '#000000']
|
||||
rec.innerHTML = list.map((c) =>
|
||||
`<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="最近使用 ${c}"></button>`).join('')
|
||||
rec.hidden = false
|
||||
if (group) group.hidden = false
|
||||
})
|
||||
await page.waitForTimeout(120)
|
||||
await page.locator('.iwb-editor-color-pop').screenshot({ path: process.env.ANNOT_SHOT2 })
|
||||
}
|
||||
await page.keyboard.press('Escape')
|
||||
await page.waitForTimeout(120)
|
||||
check('选过的颜色进入「最近使用」并出现在色板弹层',
|
||||
@@ -2394,7 +2592,7 @@ check('点填充槽打开色板:目标是填充,并出现「无」按钮',
|
||||
// 拿黄色/绿色统计会数到别的图形,永远清不到 0。
|
||||
const mainBefore = await page.evaluate(() => window.__iwbEditor.__debug().color)
|
||||
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.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
@@ -2411,13 +2609,13 @@ check('色板里选色写进填充、主色(描边)不动,工具栏填充
|
||||
|
||||
// 「无」:关填充,画面清空,但颜色留着
|
||||
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)
|
||||
const afterNone = await page.evaluate(() => {
|
||||
const d = window.__iwbEditor.__debug()
|
||||
const s = d.shapes[d.shapes.length - 1]
|
||||
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
||||
return { fill: s.fill, fillColor: s.fillColor, btnCls: fillBtn.className, noneActive: document.querySelector('[data-color-none]').classList.contains('active') }
|
||||
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)
|
||||
check('「无」把填充关掉:画面清空、颜色留着(下次点颜色还是它)',
|
||||
@@ -2511,6 +2709,382 @@ const shiftXSwap = await (async () => {
|
||||
})()
|
||||
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 图片调节(放最后:会改像素,放中间会污染依赖像素的用例)
|
||||
// ================================================================
|
||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||
await page.keyboard.press('Escape')
|
||||
// 前面几条效果用例会把「原图」栅格化成副本层并把原层隐藏,这里先还原成干净的单层,
|
||||
// 否则调节作用在一个隐藏层上 → 像素统计一动不动(第一次跑就踩了这个)
|
||||
await page.locator('[data-action="reset"]').click()
|
||||
await page.waitForTimeout(450)
|
||||
await page.evaluate(() => {
|
||||
const base = [...document.querySelectorAll('.iwb-layer-item')].find(el => /原图/.test(el.textContent || ''))
|
||||
if (base) base.click()
|
||||
})
|
||||
await page.waitForTimeout(320)
|
||||
|
||||
const adjRowCount = await page.locator('.iwb-editor-adj-row').count()
|
||||
const adjNames = await page.locator('.iwb-editor-adj-name').allTextContents()
|
||||
check('右侧栏出现「图片调节」,11 项齐全且顺序固定',
|
||||
adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度',
|
||||
'rows=' + adjRowCount + ' ' + adjNames.join('/'))
|
||||
|
||||
// ---------- v1.19:右栏调色模块删除(用户 2026-11-10)/ 可拖宽度 / 字号 ----------
|
||||
const sideFirst = await page.evaluate(() => {
|
||||
const aside = document.querySelector('.iwb-editor-left')
|
||||
const firstSection = aside && aside.querySelector(':scope > section')
|
||||
return {
|
||||
hasColor: Boolean(aside && aside.querySelector('[data-color-surface]')),
|
||||
first: firstSection ? firstSection.className : '',
|
||||
popCount: document.querySelectorAll('.iwb-editor-color-pop').length,
|
||||
}
|
||||
})
|
||||
check('右栏调色模块已删:侧栏第一个模块是「图片调节」,颜色只剩弹层一处',
|
||||
sideFirst.hasColor === false && /iwb-editor-adj/.test(sideFirst.first) && sideFirst.popCount === 1,
|
||||
JSON.stringify(sideFirst))
|
||||
|
||||
// 弹层里选常用色:色块 active 圈 / HEX 输入 / 工具栏色点三处必须同时变
|
||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||
await page.waitForTimeout(120)
|
||||
await page.locator('.iwb-editor-color-pop .iwb-editor-color-swatches [data-panel-color="#00bfa5"]').click()
|
||||
await page.waitForTimeout(200)
|
||||
const colorSync = await page.evaluate(() => {
|
||||
const active = [...document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-swatches [data-panel-color]')]
|
||||
.filter(b => b.classList.contains('active')).map(b => b.dataset.panelColor)
|
||||
return {
|
||||
active,
|
||||
hex: document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input').value,
|
||||
color: window.__iwbEditor.__debug().color,
|
||||
}
|
||||
})
|
||||
check('弹层选色:常用色高亮 + HEX 回填 + 主色统一(三处不是各说各话)',
|
||||
colorSync.active.length === 1 && colorSync.active[0] === '#00bfa5' &&
|
||||
colorSync.hex.toLowerCase() === '#00bfa5' && colorSync.color === '#00bfa5',
|
||||
JSON.stringify(colorSync))
|
||||
await page.keyboard.press('Escape')
|
||||
await page.waitForTimeout(90)
|
||||
|
||||
// 拖右栏宽度:侧栏在画布右侧,指针左移 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 均值 */
|
||||
const adjStat = () => page.evaluate(() => {
|
||||
const list = [...document.querySelectorAll('.iwb-editor-layer-canvas')]
|
||||
if (!list.length) return null
|
||||
const w = list[0].width, h = list[0].height
|
||||
const c = document.createElement('canvas')
|
||||
c.width = w; c.height = h
|
||||
const x = c.getContext('2d')
|
||||
for (const el of list) x.drawImage(el, 0, 0)
|
||||
const d = x.getImageData(0, 0, w, h).data
|
||||
let lum = 0, n = 0, gray = 0, r = 0, b = 0
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
if (d[i + 3] === 0) continue
|
||||
lum += (d[i] + d[i + 1] + d[i + 2]) / 3
|
||||
if (Math.abs(d[i] - d[i + 1]) < 3 && Math.abs(d[i + 1] - d[i + 2]) < 3) gray++
|
||||
r += d[i]; b += d[i + 2]; n++
|
||||
}
|
||||
return n ? { lum: Math.round(lum / n), gray: +(gray / n).toFixed(2), r: Math.round(r / n), b: Math.round(b / n) } : null
|
||||
})
|
||||
|
||||
/** 设一个调节项的数值(模拟在数值框里输入并提交) */
|
||||
const adjSet = async (key, val) => {
|
||||
await page.evaluate(({ key, val }) => {
|
||||
const row = document.querySelector(`.iwb-editor-adj-row[data-adj="${key}"]`)
|
||||
const num = row.querySelector('.iwb-editor-adj-val')
|
||||
num.value = String(val)
|
||||
num.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
num.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
}, { key, val })
|
||||
await page.waitForTimeout(240)
|
||||
}
|
||||
const adjReset = async () => {
|
||||
const btn = page.locator('[data-adj-reset="all"]')
|
||||
if (await btn.isEnabled()) { await btn.click(); await page.waitForTimeout(260) }
|
||||
}
|
||||
|
||||
const adjBase = await adjStat()
|
||||
|
||||
await adjSet('exposure', 100)
|
||||
const adjBright = await adjStat()
|
||||
check('曝光 +100 明显提亮(不是「看不出变化」的强度)',
|
||||
adjBright && adjBase && adjBright.lum > adjBase.lum + 25,
|
||||
'亮度 ' + (adjBase && adjBase.lum) + ' → ' + (adjBright && adjBright.lum))
|
||||
await adjReset()
|
||||
|
||||
await adjSet('saturation', -100)
|
||||
const adjGray = await adjStat()
|
||||
check('饱和度 -100 完全去色(灰像素接近 100%)',
|
||||
adjGray && adjGray.gray > 0.9,
|
||||
'灰占比 ' + (adjGray && adjGray.gray))
|
||||
await adjReset()
|
||||
|
||||
await adjSet('temp', 100)
|
||||
const adjWarm = await adjStat()
|
||||
check('温度 +100 偏暖:R 通道升、B 通道降',
|
||||
adjWarm && adjBase && adjWarm.r > adjBase.r && adjWarm.b < adjBase.b,
|
||||
'R ' + (adjBase && adjBase.r) + '→' + (adjWarm && adjWarm.r) + ' B ' + (adjBase && adjBase.b) + '→' + (adjWarm && adjWarm.b))
|
||||
|
||||
const adjDirty = (await dbg()).adjust
|
||||
check('调节参数写回状态(debug 可观测,供后续撤销断言)',
|
||||
adjDirty.params && adjDirty.params.temp === 100 && adjDirty.hasSource,
|
||||
JSON.stringify(adjDirty.params))
|
||||
|
||||
await adjReset()
|
||||
const adjBack = await adjStat()
|
||||
check('「复位」把所有项归零,像素回到原图',
|
||||
adjBack && adjBase && Math.abs(adjBack.lum - adjBase.lum) <= 1 && Math.abs(adjBack.r - adjBase.r) <= 1,
|
||||
'亮度 ' + (adjBack && adjBack.lum) + ' vs ' + (adjBase && adjBase.lum))
|
||||
|
||||
// 一次拖动 = 一步历史(6 次 input + 1 次 change)
|
||||
// 注意不能比 history.length:历史栈有容量上限,push 到底后是「进一条、淘汰一条」,
|
||||
// 长度永远不变(第一次跑就是被这个坑到)。数标签出现次数才准。
|
||||
const adjLabelCount = async () => (await dbg()).historyLabels.filter(l => l === '图片调节').length
|
||||
const adjH0 = await adjLabelCount()
|
||||
for (const v of [20, 40, 60, 80, 90, 100]) {
|
||||
await page.evaluate(({ v }) => {
|
||||
const r = document.querySelector('.iwb-editor-adj-row[data-adj="exposure"] .iwb-editor-adj-range')
|
||||
r.value = String(v)
|
||||
r.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
}, { v })
|
||||
}
|
||||
await page.evaluate(() => {
|
||||
const r = document.querySelector('.iwb-editor-adj-row[data-adj="exposure"] .iwb-editor-adj-range')
|
||||
r.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
await page.waitForTimeout(320)
|
||||
const adjH1 = await adjLabelCount()
|
||||
check('拖一次滑杆只记 1 步历史(不是每帧一步)', adjH1 === adjH0 + 1, '图片调节 标签 ' + adjH0 + ' → ' + adjH1)
|
||||
|
||||
await page.keyboard.press('Control+z')
|
||||
await page.waitForTimeout(320)
|
||||
const adjUndo = (await dbg()).adjust
|
||||
check('Ctrl+Z 撤销调节后滑块归零(参数不能和画面对不上)',
|
||||
adjUndo.params && adjUndo.params.exposure === 0,
|
||||
'exposure=' + (adjUndo.params && adjUndo.params.exposure))
|
||||
|
||||
// 切图层:面板 target 跟随,切回来参数恢复
|
||||
await adjSet('exposure', 40)
|
||||
const adjKept = (await dbg()).adjust.params.exposure
|
||||
await page.locator('[data-action="addBlankLayer"]').click()
|
||||
await page.waitForTimeout(400)
|
||||
const adjTargetNew = await page.locator('.iwb-editor-adj-target').textContent()
|
||||
const adjNewParams = (await dbg()).adjust.params
|
||||
await page.evaluate(() => {
|
||||
const base = [...document.querySelectorAll('.iwb-layer-item')].find(el => /原图/.test(el.textContent || ''))
|
||||
if (base) base.click()
|
||||
})
|
||||
await page.waitForTimeout(420)
|
||||
const adjBackParams = (await dbg()).adjust.params
|
||||
check('切图层时调节面板跟随新层,切回原层参数恢复',
|
||||
/空白图层/.test(adjTargetNew) && adjNewParams && adjNewParams.exposure === 0 && adjBackParams.exposure === adjKept,
|
||||
'新层=' + adjTargetNew + ' 新层exp=' + (adjNewParams && adjNewParams.exposure) + ' 回到原图exp=' + adjBackParams.exposure)
|
||||
|
||||
await adjReset()
|
||||
|
||||
// 退出前先记一笔:此时调过曝光/温度,缓存里必然有 'base' 条目,
|
||||
// 下面 Round 3 用它证明「退出确实把缓存清掉了」,而不是本来就没缓存。
|
||||
const adjCacheBefore = (await dbg()).adjustCacheSize
|
||||
check('前置:调过之后基准缓存里有条目', adjCacheBefore > 0, 'cache=' + adjCacheBefore)
|
||||
|
||||
await page.locator('[data-action="cancel"]').click()
|
||||
const openState = await poll(async () => page.evaluate(() => window.__openState))
|
||||
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',
|
||||
@@ -2518,6 +3092,35 @@ check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',
|
||||
(await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false,
|
||||
JSON.stringify(openState))
|
||||
|
||||
// ---------- Round 3:退出再打开,调节基准必须重建 ----------
|
||||
// 原图图层的 id 是写死的 'base',而 adjust.js 的基准缓存以 layer.id 为 key。
|
||||
// 退出时不清缓存 ⇒ 第二张图 captureFor('base') 命中上一张图的像素,
|
||||
// 表现为「编辑另一张图时一调节,画面还原成上一张」—— 100% 复现,不是偶发。
|
||||
await page.evaluate(() => {
|
||||
window.__openState = null
|
||||
window.__commands['annotate-selected'].run().then(
|
||||
(mode) => { window.__openState = { mode: String(mode) } },
|
||||
(err) => { window.__openState = { error: String((err && err.message) || err) } }
|
||||
)
|
||||
})
|
||||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
||||
await page.waitForFunction(() => window.__iwbEditor.__debug().open === true)
|
||||
|
||||
const adjFresh = await dbg()
|
||||
check('退出重开:调节基准缓存清空、无残留 source 与 layerId(否则第二张图会串上一张的像素)',
|
||||
adjFresh.adjustCacheSize === 0 && adjFresh.adjust.hasSource === false && adjFresh.adjust.layerId === null,
|
||||
'cache=' + adjFresh.adjustCacheSize + ' layerId=' + adjFresh.adjust.layerId + ' hasSource=' + adjFresh.adjust.hasSource)
|
||||
|
||||
const adjBase2 = await adjStat()
|
||||
await adjSet('exposure', 100)
|
||||
const adjBright2 = await adjStat()
|
||||
check('重开后调节以新图像素为基准:曝光 +100 正常提亮(不是把旧图重算上来)',
|
||||
adjBase2 && adjBright2 && adjBright2.lum > adjBase2.lum + 25,
|
||||
'亮度 ' + (adjBase2 && adjBase2.lum) + ' → ' + (adjBright2 && adjBright2.lum))
|
||||
await adjReset()
|
||||
|
||||
await page.locator('[data-action="cancel"]').click()
|
||||
|
||||
check('无运行时错误 / 无弹窗', errors.length === 0, errors.slice(0, 3).join(' | '))
|
||||
|
||||
await browser.close()
|
||||
|
||||
@@ -28,9 +28,12 @@ v0.2 换 potrace,并且按用户要求**只做单色 / 灰度**(不做彩色
|
||||
背景默认白)+「带底」勾选(决定背景色是否写进导出)
|
||||
- **按孤岛拆分**(默认开):每个连通块输出为一个独立 `<path>` 元素,粘到 Figma 就是多个
|
||||
可单独选中的图层;关掉则整图合并成一个 path(便于整体缩放/移动)
|
||||
- 预览:按住空格对比原图;面板显示元素数 / 层数 / 体积 / 耗时
|
||||
- 输出:**复制 SVG**(写 `image/svg+xml` + `text/html` + `text/plain` 三种剪贴板口味,
|
||||
Figma / Illustrator 粘进去就是真矢量)· **下载 SVG** · **保存为节点**(PNG,按输出倍率 1–4× 从矢量重绘)
|
||||
- 预览:按住空格对比原图;**滚轮/捏合缩放、左键拖动平移、双击复位**(0.2×–8×);面板显示元素数 / 层数 / 体积 / 耗时
|
||||
- 顶栏按钮(左 → 右):**保存为节点** · **复制 SVG** · **下载 SVG** · 取消(四颗统一描边配色,不用绿色主按钮)
|
||||
- **保存为节点**:PNG,按输出倍率 1–4× 从矢量重绘后写回画布
|
||||
- **复制 SVG**:写 `image/svg+xml` + `text/html` + `text/plain` 三种剪贴板口味,
|
||||
Figma / Illustrator 粘进去就是真矢量
|
||||
- **下载 SVG**:存成文件
|
||||
|
||||
## 按孤岛拆分(v0.3)
|
||||
|
||||
@@ -84,6 +87,34 @@ potrace 出厂把**整张图所有轮廓**塞进同一个 `<path>` 的 d 里(8
|
||||
白底 + 白底稿(菜单、白底商品图)会看不出画面边界,所以预览图本身留了一圈 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 的数据,读的一方自己挑。
|
||||
@@ -105,7 +136,7 @@ potrace 与其 JS 移植都是 **GPL-2.0**(见 `plugin/vendor/potrace/LICENSE`
|
||||
```bash
|
||||
npm run build -- image-vectorize # plugin/ → src/index.js(esbuild IIFE)
|
||||
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 / 真实画布桥)
|
||||
|
||||
# 拿真实素材调参数(不进 CI,最快看到效果):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/image-vectorize",
|
||||
"private": true,
|
||||
"version": "0.3.1",
|
||||
"version": "0.4.2",
|
||||
"description": "位图转矢量:potrace(纯 JS)单色/灰度描摹,输出 SVG 与 PNG 节点;对文字、logo、线稿保形好,不需要 wasm",
|
||||
"ibwPlugin": {
|
||||
"id": "image-vectorize",
|
||||
|
||||
@@ -75,14 +75,8 @@
|
||||
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
||||
.vz-btn:active { background: #2f2f3a; }
|
||||
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
||||
|
||||
.vz-btn-primary {
|
||||
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-btn-primary 绿色主按钮,
|
||||
2026-11-09 用户要求「颜色都用取消按钮的配色」,已去掉)。 */
|
||||
|
||||
/* ---------- 主体 ---------- */
|
||||
.vz-body {
|
||||
@@ -104,15 +98,41 @@
|
||||
棋盘格既干扰判断形状,也让深色细笔画看起来发虚(实测用户第一反应是「糊」)。
|
||||
矢量 SVG 本身仍不含背景矩形,导出/复制到 Figma 依旧是透明底。 */
|
||||
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 {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
max-width: calc(100% - 40px);
|
||||
max-height: calc(100% - 40px);
|
||||
display: block;
|
||||
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; }
|
||||
@@ -148,6 +168,32 @@
|
||||
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 {
|
||||
position: absolute;
|
||||
|
||||
@@ -128,18 +128,21 @@ function viewHTML(name) {
|
||||
'<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>' +
|
||||
// 顺序:主操作在左,取消在最右(用户 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="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>' +
|
||||
'<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-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">空格 对比原图 · 「复制 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>' +
|
||||
'<aside class="vz-panel" data-panel></aside>' +
|
||||
'</div></div></div>'
|
||||
@@ -171,6 +174,11 @@ export function createVectorizer(options) {
|
||||
let seq = 0
|
||||
let debounceTimer = 0
|
||||
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 ? '原图' : '矢量预览'
|
||||
}
|
||||
|
||||
// ---------- 预览视图:缩放 / 平移 ----------
|
||||
//
|
||||
// 为什么把状态写进 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() {
|
||||
@@ -602,6 +716,13 @@ export function createVectorizer(options) {
|
||||
close()
|
||||
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) {
|
||||
const tag = (event.target && event.target.tagName) || ''
|
||||
if (tag === 'INPUT' || tag === 'TEXTAREA') return
|
||||
@@ -633,6 +754,11 @@ export function createVectorizer(options) {
|
||||
const node = root
|
||||
root = null
|
||||
els = null
|
||||
// 视图状态跟着会话走:下次打开从「等比铺满」开始
|
||||
zoom = 1
|
||||
panX = 0
|
||||
panY = 0
|
||||
drag = null
|
||||
node.remove()
|
||||
if (typeof onClose === 'function') onClose()
|
||||
}
|
||||
@@ -663,6 +789,8 @@ export function createVectorizer(options) {
|
||||
vector: root.querySelector('[data-stage="vector"]'),
|
||||
original: root.querySelector('[data-stage="original"]'),
|
||||
badge: root.querySelector('[data-badge]'),
|
||||
zoomChip: root.querySelector('[data-zoom-chip]'),
|
||||
zoomVal: root.querySelector('[data-zoom-val]'),
|
||||
status: root.querySelector('[data-status]'),
|
||||
statusText: root.querySelector('[data-status-text]'),
|
||||
meta: root.querySelector('[data-meta]'),
|
||||
@@ -672,6 +800,18 @@ export function createVectorizer(options) {
|
||||
els.panel.innerHTML = panelHTML(params, preset, outScale, advOpen)
|
||||
|
||||
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('click', onPanelClick)
|
||||
document.addEventListener('keydown', onKeyDown, true)
|
||||
@@ -680,6 +820,7 @@ export function createVectorizer(options) {
|
||||
|
||||
syncControls()
|
||||
setStats(null)
|
||||
resetView()
|
||||
retrace()
|
||||
return { close }
|
||||
}
|
||||
|
||||
+179
-13
@@ -9,7 +9,7 @@
|
||||
var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
id: 'image-vectorize',
|
||||
name: '位图转矢量',
|
||||
version: '0.3.1',
|
||||
version: '0.4.2',
|
||||
apiVersion: 1,
|
||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||
settings: {
|
||||
@@ -2082,14 +2082,8 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
.vz-btn:hover { background: #34343f; border-color: #4a4a5c; }
|
||||
.vz-btn:active { background: #2f2f3a; }
|
||||
.vz-btn:disabled { opacity: 0.45; cursor: default; }
|
||||
|
||||
.vz-btn-primary {
|
||||
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-btn-primary 绿色主按钮,
|
||||
2026-11-09 用户要求「颜色都用取消按钮的配色」,已去掉)。 */
|
||||
|
||||
/* ---------- 主体 ---------- */
|
||||
.vz-body {
|
||||
@@ -2111,15 +2105,41 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
棋盘格既干扰判断形状,也让深色细笔画看起来发虚(实测用户第一反应是「糊」)。
|
||||
矢量 SVG 本身仍不含背景矩形,导出/复制到 Figma 依旧是透明底。 */
|
||||
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 {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
max-width: calc(100% - 40px);
|
||||
max-height: calc(100% - 40px);
|
||||
display: block;
|
||||
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; }
|
||||
@@ -2155,6 +2175,32 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
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 {
|
||||
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>";
|
||||
}
|
||||
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 toneOf = (alphaMax) => alphaMax <= 0.6 ? "hard" : alphaMax >= 1.1 ? "round" : "normal";
|
||||
@@ -2994,6 +3040,10 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
let seq = 0;
|
||||
let debounceTimer = 0;
|
||||
let spaceDown = false;
|
||||
let zoom = 1;
|
||||
let panX = 0;
|
||||
let panY = 0;
|
||||
let drag = null;
|
||||
function readSettings() {
|
||||
const out = {};
|
||||
if (!settings || typeof settings.get !== "function") return out;
|
||||
@@ -3138,6 +3188,87 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
els.original.hidden = !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() {
|
||||
if (!source) return;
|
||||
const ticket = ++seq;
|
||||
@@ -3409,6 +3540,24 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
close();
|
||||
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) {
|
||||
const tag = event.target && event.target.tagName || "";
|
||||
if (tag === "INPUT" || tag === "TEXTAREA") return;
|
||||
@@ -3440,6 +3589,10 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
const node = root;
|
||||
root = null;
|
||||
els = null;
|
||||
zoom = 1;
|
||||
panX = 0;
|
||||
panY = 0;
|
||||
drag = null;
|
||||
node.remove();
|
||||
if (typeof onClose === "function") onClose();
|
||||
}
|
||||
@@ -3465,6 +3618,8 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
vector: root.querySelector('[data-stage="vector"]'),
|
||||
original: root.querySelector('[data-stage="original"]'),
|
||||
badge: root.querySelector("[data-badge]"),
|
||||
zoomChip: root.querySelector("[data-zoom-chip]"),
|
||||
zoomVal: root.querySelector("[data-zoom-val]"),
|
||||
status: root.querySelector("[data-status]"),
|
||||
statusText: root.querySelector("[data-status-text]"),
|
||||
meta: root.querySelector("[data-meta]")
|
||||
@@ -3473,6 +3628,16 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
els.meta.textContent = name + " · " + source.srcW + "×" + source.srcH;
|
||||
els.panel.innerHTML = panelHTML(params, preset, outScale, advOpen);
|
||||
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("click", onPanelClick);
|
||||
document.addEventListener("keydown", onKeyDown, true);
|
||||
@@ -3480,6 +3645,7 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
||||
window.addEventListener("blur", onBlur);
|
||||
syncControls();
|
||||
setStats(null);
|
||||
resetView();
|
||||
retrace();
|
||||
return { close };
|
||||
}
|
||||
|
||||
@@ -139,6 +139,15 @@ check('样式注入生效(CSP unsafe-inline)', await page.evaluate(() => {
|
||||
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 下引擎能跑 ----------
|
||||
const paths = await poll(async () => {
|
||||
// 统计项是「元素」,合并模式下会带后缀「(N 孤岛合并)」,只取前面的数字
|
||||
@@ -184,6 +193,45 @@ check('「填充 / 背景」两个色块并排在同一行', await page.evaluate
|
||||
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) 复制到剪贴板(真写,读回校验口味) ----------
|
||||
await page.locator('[data-act="copy"]').click()
|
||||
await sleep(400)
|
||||
|
||||
@@ -153,6 +153,15 @@ check('模态打开:预览区 + 参数面板 + 四个动作按钮齐全', awai
|
||||
document.querySelector('[data-act="save"]') && document.querySelector('[data-act="svg"]') &&
|
||||
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 明确要求「不用隐藏」(低频项也一眼能看到)
|
||||
check('高级参数默认展开', await page.evaluate(() => {
|
||||
const box = document.querySelector('[data-adv]')
|
||||
@@ -186,6 +195,87 @@ check('预览区白底、无棋盘格', await page.evaluate(() => {
|
||||
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 monoMs = Number((await page.locator('[data-stat="ms"]').textContent()).replace(/[^\d]/g, ''))
|
||||
check('单色描摹产出元素(文字图形都在)', monoPaths >= 1 && monoPaths <= 80, 'elements=' + monoPaths)
|
||||
@@ -335,8 +425,9 @@ await page.evaluate(() => {
|
||||
})
|
||||
await sleep(400)
|
||||
check('改单色填充色写进 SVG', await page.evaluate(() => /#c0392b/i.test(window.__lastSvg || '')), '')
|
||||
// 开发用:VZ_SHOT=/tmp/vz-panel.png 出一张面板截图(验证「填充 / 背景」这排没挤坏布局)
|
||||
if (process.env.VZ_SHOT) await page.locator('.vz-modal').screenshot({ path: process.env.VZ_SHOT })
|
||||
// 开发用:VZ_SHOT_PANEL=/tmp/vz-panel.png 出一张面板截图(验证「填充 / 背景」这排没挤坏布局)
|
||||
// ⚠️ 别和上面的 VZ_SHOT 共用同一个变量 —— 两处都写同一路径时,后一张会把前一张覆盖掉
|
||||
if (process.env.VZ_SHOT_PANEL) await page.locator('.vz-modal').screenshot({ path: process.env.VZ_SHOT_PANEL })
|
||||
|
||||
// ---------- 背景色 / 带底(v0.3.1) ----------
|
||||
const setBg = async (hex) => {
|
||||
@@ -432,6 +523,14 @@ check('重新打开沿用上次参数(mode=mono、颜色 #c0392b)', await pa
|
||||
}))
|
||||
|
||||
// ---------- 空格对比 / 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.keyboard.down('Space')
|
||||
await sleep(150)
|
||||
@@ -439,6 +538,16 @@ check('按住空格对比原图', await page.evaluate(() => {
|
||||
const o = document.querySelector('[data-stage="original"]')
|
||||
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 sleep(120)
|
||||
check('松开空格回到矢量', await page.evaluate(() => {
|
||||
|
||||
Reference in new issue
Block a user