Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a477705c7f | ||
|
|
6a14f900df | ||
|
|
e10ccee8ad | ||
|
|
240d02684a | ||
|
|
1dc423c025 | ||
|
|
244fc9c2b2 | ||
|
|
546999fdf9 | ||
|
|
bf32ec6ddb | ||
|
|
31866a2407 | ||
|
|
9c938887c1 | ||
|
|
b63771f6e4 | ||
|
|
73a29715d3 | ||
|
|
e699c22fa0 | ||
|
|
040b08fe28 | ||
|
|
6e1685998f |
No files matched your search
@@ -234,6 +234,632 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
|||||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||||
|
|
||||||
|
## 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:文字可以选字体(黑 / 宋 / 楷 / 圆)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
需求:「文字工具能不能选字体」。可以,而且成本很低 —— 但**只做了系统字体族**,没有内置字体文件,
|
||||||
|
原因见下。
|
||||||
|
|
||||||
|
### 怎么用
|
||||||
|
|
||||||
|
选中文字(或切到文字工具、不选任何东西)→ 选项栏「字体」下拉,四档:
|
||||||
|
|
||||||
|
| 档位 | 字体栈(按命中顺序) | 适合 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 黑体 | PingFang SC → Microsoft YaHei → Heiti SC → 思源黑体 → sans-serif | 默认。现代无衬线,信息密度高 |
|
||||||
|
| 宋体 | Songti SC → SimSun → 思源宋体 → serif | 正式、印刷感,标题压得住 |
|
||||||
|
| 楷体 | Kaiti SC → KaiTi → STKaiti → serif | 手写感,批注、签名、便签 |
|
||||||
|
| 圆体 | Yuanti SC → YouYuan → 苹方 → sans-serif | 柔和,促销、亲子、轻食 |
|
||||||
|
|
||||||
|
选中文字时立刻生效;没选中时改的是「下一段文字的默认字体」——与字重 / 对齐 / 行距同一套逻辑。
|
||||||
|
双击编辑文字时,输入框的字形和字重也跟着这段文字走,不会出现「输入时是黑体、确认后变宋体」。
|
||||||
|
|
||||||
|
### 为什么不内置字体文件
|
||||||
|
|
||||||
|
三条硬约束:
|
||||||
|
|
||||||
|
1. **CSP 拦死了第三方字体**。宿主 `_headers` 是 `default-src 'self'`,`font-src` 回落它,
|
||||||
|
`https:` 只放给了 `img-src` / `connect-src`。Google Fonts 或任何字体 CDN 都会被浏览器直接拒绝。
|
||||||
|
2. **中文字体太大**。本机参照:宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB;插件产物现在 392KB,
|
||||||
|
内联等于涨 5–150 倍。子集化到 3500 常用字约 0.8–1.5MB/个,能接受,但要放宿主静态目录,
|
||||||
|
发布链得一起改。
|
||||||
|
3. **异步字体的时序坑**。Web 字体异步加载,字体没 ready 就 `measureText`,量出来的是 fallback
|
||||||
|
的宽度 —— 选中框和实际字形错位,导出还可能画成 fallback。系统字体同步可用,没有这个问题。
|
||||||
|
|
||||||
|
### 性能:字体不是瓶颈
|
||||||
|
|
||||||
|
1000×1000 画布、30 个文字对象(每个对象一张整图画布,见 `layers.js#vecCanvasFor`):
|
||||||
|
|
||||||
|
| | 首次绘制 | 热重绘 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 现在(`sans-serif`) | 42.1 ms | 0.2 ms |
|
||||||
|
| 苹方 | 13.5 ms | 0.1 ms |
|
||||||
|
| 宋体 | 13.2 ms | 0.1 ms |
|
||||||
|
| 楷体 | 22.2 ms | 0.1 ms |
|
||||||
|
| 圆体 | 21.2 ms | 0.1 ms |
|
||||||
|
|
||||||
|
换字体只在**首次**多一次字形光栅化(13–42ms,一到两帧),之后走字形缓存,比现状还略快。
|
||||||
|
|
||||||
|
顺带记一条既有开销(与本版无关,但图大了要注意):每个文字对象占一张 imgW×imgH 的画布,
|
||||||
|
1000² 是 3.8MB、4000² 是 61MB;20 个文字对象在 4000² 图上约 1.2GB。
|
||||||
|
|
||||||
|
### 一个反直觉的事实
|
||||||
|
|
||||||
|
**中文是全角等宽,换字体不改字宽**。同一段 10 个字在 6 种字体下 `measureText` 全是 480px
|
||||||
|
(48px × 10)。所以切换字体不会让已有标注的版面跳动,只有拉丁字母和数字会伸缩 ——
|
||||||
|
这也是锚点继续用「左上角」而不是居中的理由。
|
||||||
|
|
||||||
|
### 兼容性
|
||||||
|
|
||||||
|
- 老文字对象没有 `fontFamily` 字段 → `fontKeyOf()` 回退到 `sans`,行为与旧版一致。
|
||||||
|
- 不认识的值(外部写入、脏数据)也收敛回 `sans`,不会把非法字符串塞进 `ctx.font`
|
||||||
|
—— 那会让整串字体失效、静默退回浏览器默认字体,画面上看不出报错,极难排查。
|
||||||
|
- 默认档的字体栈比旧的 `sans-serif` 更明确(苹方优先),**英文和数字的字形会有细微变化**,
|
||||||
|
中文基本无感。这是「让字体可控」的代价,比留着跨平台不可控的 `sans-serif` 要好。
|
||||||
|
|
||||||
|
回归:harness 192 → 197 条(新增 5 条,含脏值收敛与「换字体不改中文宽度」);`npm run validate` 9/9。
|
||||||
|
|
||||||
|
## v1.13.1:Shift+X 改成「交换填充色与描边色」
|
||||||
|
|
||||||
|
反馈:「矩形 圆形 钢笔,切换填充与描边色的时候,会导致填充丢掉」→ 补一句关键信息
|
||||||
|
「shift+x 切换填充与描边色的时候,就会出现丢失填充色的问题……再按这个快捷键填色又回来了,
|
||||||
|
但是描边一直不变」。
|
||||||
|
|
||||||
|
### 不是颜色被清空,是快捷键语义错了
|
||||||
|
|
||||||
|
先把能想到的入口全实测了一遍(工具栏两个色槽、色板头部 tab、SV 拖动、hex 输入、选项栏原生
|
||||||
|
色块、切换工具往返、矩形/圆形/钢笔、钢笔闭合与未闭合):**`fillColor` 从来没被清空,画面像素
|
||||||
|
也没有丢**。真正的错在 **Shift+X 的语义**:
|
||||||
|
|
||||||
|
| | 旧行为 | 用户期望 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 按一次 | 填充开关被关掉(只剩描边),描边色不动 | 填充色与描边色**对调** |
|
||||||
|
| 再按一次 | 填充开关恢复,描边色仍然不动 | 换回来 |
|
||||||
|
|
||||||
|
用户看到的正是「填充没了、描边一直不变,再按一次填充又回来」—— 那是**开关**的行为,
|
||||||
|
而 PS 里 `X` 是**交换前景/背景色**。所以这不是"颜色丢了",是把颜色交换做成了开关。
|
||||||
|
|
||||||
|
### 改法
|
||||||
|
|
||||||
|
新增 `swapShapeColors()`(`events.js`),Shift+X 改为调它:
|
||||||
|
|
||||||
|
- 描边色 ↔ 填充色对调:`sh.color ⇄ sh.fillColor`,同时同步主色 `S.color` 与默认填充色
|
||||||
|
`S.shapeFillColor`(v1.10 起这两个就是同一份真相源,不另存)
|
||||||
|
- **填充的开关状态不动**:交换的是颜色,不是有无。实心图形交换后仍是实心
|
||||||
|
- 箭头没有内部,直接 toast 说明;填充还在「跟随描边色」(`fillColor=null`,两边同一个值)
|
||||||
|
时也只提示,不改数据
|
||||||
|
- 一步历史:`saveSnapshot('交换填充与描边色')`,`Ctrl+Z` 一次回退
|
||||||
|
|
||||||
|
实心/描边的切换**没有丢**,仍在选项栏那两个按钮上(`data-opt-toggle`),只是不再占 Shift+X;
|
||||||
|
按钮的 tooltip 里原来写着「(Shift+X 切换)」,容易让人以为 Shift+X 是开关,已改成说明交换语义。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` 里那条旧用例(断言按 Shift+X 后 `fill` 变 true)换成新的交换用例,
|
||||||
|
断言「描边/填充两个色值互换、`fill` 开关不变、再按一次回到原样」。这条用例放在文件末尾跑 ——
|
||||||
|
交换会把「下一个图形的填充色」也写成具体色值,夹在中间会污染后面「新建图形填充默认跟随描边色」的断言。
|
||||||
|
|
||||||
|
## v1.13.0:顶栏瘦身 / 视图按钮归位 / R·O·L 快捷键 / 填充色实时 / 图层解封
|
||||||
|
|
||||||
|
五条调整,前四条是界面与手感,最后一条是能力解禁(原型是 PS,但「原图不许压」这条并不是 PS 的规矩)。
|
||||||
|
|
||||||
|
### 1. 顶栏去掉四个层级按钮
|
||||||
|
|
||||||
|
置顶 / 上移 / 下移 / 置底那四个箭头,在有了图层面板拖动和 `Ctrl+]` `Ctrl+[` 之后就是纯冗余 —— 而且
|
||||||
|
它们只能作用在**选中**对象上,够不到位图层。整套 `.iwb-editor-commands` 连同里面的分隔线一起删掉,
|
||||||
|
`updateLayerUI()` 与 `bindLayerOrderButtons()` 两个函数也一并清除(不留死代码)。
|
||||||
|
顶栏现在只剩:标题 · 新建 / 覆盖 / 退出 · 撤销 / 重做 / 还原;右侧输出设置 + 复制 + 导出。
|
||||||
|
|
||||||
|
### 2. 「适应窗口」「收起侧栏」挪到工具栏最右
|
||||||
|
|
||||||
|
这两个是**视图**操作,跟绘制工具不是一类,原来挤在顶栏右边,与「复制」「导出」贴着容易被误点。
|
||||||
|
移过去没有用任何特殊定位 —— 工具栏是 `position:absolute; left:50%; translateX(-50%)` 的
|
||||||
|
**shrink-to-fit** 容器,所以「放在 DOM 最后」天然就是「视觉最右」。中间补一条 `.iwb-editor-divider`
|
||||||
|
和工具区隔开。
|
||||||
|
|
||||||
|
### 3. 快捷键:`R` 矩形、`O` 圆形、`L` 箭头
|
||||||
|
|
||||||
|
原来 `R` 没被占用(矩形只有 `U`),`O` 也没有,`L` 是套索。按需求:
|
||||||
|
|
||||||
|
| 键 | 工具 | 备注 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `R` | 矩形 | 与 `U` 并存,老的 `U` 和 `Shift+U` 循环保留 |
|
||||||
|
| `O` | 圆形 | 同上,不抢 `U` 的手感 |
|
||||||
|
| `L` | 箭头 | 原本是套索 |
|
||||||
|
| `A` | 套索 | 从 `L` 迁过来(不丢能力) |
|
||||||
|
|
||||||
|
顺手修了一个老毛病:中文输入法下按 `[` `]` 会被 IME 吃成 `【` `】`,只匹配 `e.key` 会失灵,
|
||||||
|
键盘处理里改成**优先匹配 `e.code`**。
|
||||||
|
|
||||||
|
### 4. 填充色改动实时上图
|
||||||
|
|
||||||
|
反馈是「填充色状态不能实时在矢量图形上显示颜色变化」。查下来有两条独立原因:
|
||||||
|
|
||||||
|
- **色板 SV 拖动本来就是实时的** —— 每帧都写 `fillColor` 再 `renderObjects()`,像素确实在变
|
||||||
|
(探测:`fillRect` 从 `#572424` 到 `#665c5c`)。这条不用改。
|
||||||
|
- **真正不实时的是选项栏那两个原生 `<input type="color">`** —— 原生色块只派发两个事件:`input`
|
||||||
|
(取色器**拉开拖动中**)和 `change`(关闭取色器)。原来只接了 `change`,于是系统取色器开着的时候
|
||||||
|
画布一动不动,关掉才「啪」一下变色,主观感受就是「不实时」。
|
||||||
|
|
||||||
|
改法是 `input` 与 `change` 都接,但历史记一步:`input` 阶段用 `skipHistory` 直接写状态 + 重绘
|
||||||
|
(`nativeColorSnapped` 标记只在第一次 `input` 时 `saveSnapshot()`),`change` 收尾时才落一次
|
||||||
|
可撤销的提交。实测拖一整轮色谱只产生 **1 步**撤销,`Ctrl+Z` 一次回到原点。
|
||||||
|
|
||||||
|
### 5. 图层可以拖到原图下面
|
||||||
|
|
||||||
|
原来「原图」被钉在 z 最底层,五处代码各钉一遍:`planPanelOrder()` 把它 `unshift` 到最前、
|
||||||
|
`updateSortTarget()` 拿它当锚点、`onSortEnd()` 把它补回末尾、`moveLayer()` 用
|
||||||
|
`baseIdx >= 0 ? 1 : 0` 把最小值抬到 1、`mergeUnits()` 把合并结果 `rest.unshift` 到底。
|
||||||
|
现在五处全部拆掉:原图就是一个普通 `base` 图层,只是**自己不能被拖**(行上仍然 `return`),
|
||||||
|
别人的 z 可以任意跨过它;合并时也按 z 插回原位而不是塞到最底。
|
||||||
|
|
||||||
|
面板提示同步改成「原图(其他图层可以拖到它下面)」。回归用例验证:把第一行拖到最底行下半区后,
|
||||||
|
`base` 的 z 从 0 变成 1、被拖的层变成 0 —— 原图被成功压到下面,`Ctrl+Z` 能复原。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` 由 140 → **192 条**(文字三色 11 条 + 本节 5 条改动各自的正反断言:
|
||||||
|
顶栏层级按钮数为 0、工具栏末两个子元素是 `zoomFit/togglePanels`、快捷键表 `V M A L B E P T R O U C I H`、
|
||||||
|
原生色块只发 `input` 也能实时变色、拖动一次只记 1 步撤销、原图可被压到下面)。
|
||||||
|
|
||||||
|
## v1.12.0:文字的三个颜色各自可调(文字 / 描边 / 底色)
|
||||||
|
|
||||||
|
用户反馈:「文本的内容需要描边与文字颜色的设定,还多一个文本框的底色,这里 3 个颜色你来
|
||||||
|
修正下,现在文本不支持描边与字体色切换」。
|
||||||
|
|
||||||
|
一查是**真的不通**,不是没找到入口:文字对象本来就有三个颜色字段(`color` / `strokeColor` /
|
||||||
|
`bgColor`),但工具栏只有「描边 / 填充」两格,而这两格是按**形状**算的 —— 选中文字时第二格
|
||||||
|
指向的是形状的 `fillColor` 与 `rectFill`,点它、选色、拖 SV,画面上一点变化都没有。文字的两个
|
||||||
|
颜色只能从选项栏里那两个小色块改,且「描边色」在描边宽度为 0 时改了什么也看不见。
|
||||||
|
|
||||||
|
### 1. 先回答「现在有几个颜色」这个问题(`colorContext()`)
|
||||||
|
|
||||||
|
以前这个判断散在各处:`fillSlotOn()` 只看 `S.tool`,`textCtx` 又另算一遍(`S.tool === 'text'
|
||||||
|
|| selectedTextId`),两处口径不同就会出现「工具栏觉得是形状、选项栏觉得是文字」。现在收成
|
||||||
|
一个函数、三档上下文:
|
||||||
|
|
||||||
|
| 上下文 | 触发条件 | 颜色格 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `text` | 选中文字,或文字工具下还没落字 | 文字 / 描边 / 底色(三格横排) |
|
||||||
|
| `shape` | 选中矩形·圆·钢笔,或这几个工具下 | 描边 / 填充(两格叠放,同 v1.11) |
|
||||||
|
| `strokeOnly` | 画笔·橡皮·箭头·没选中东西 | 只有一格(画笔色 / 描边色) |
|
||||||
|
|
||||||
|
`colorSlots()` 按上下文返回三个颜色值 + 每格「当前生效吗」,仍是工具栏、色板头部、hex、
|
||||||
|
调色器、吸管**唯一的取值处**。
|
||||||
|
|
||||||
|
### 2. 三格各写各的字段
|
||||||
|
|
||||||
|
- **文字色** = 主色 `S.color`(与画笔色同一个值,仍是「一个主色」的约定),选中文字时写它自己的 `color`
|
||||||
|
- **描边色** = `strokeColor`;选色时若描边宽度是 0,自动补 6px —— 否则「选了颜色画面不变」
|
||||||
|
又会被当成坏了
|
||||||
|
- **底色** = `bgColor`;选色时若底色块没开,自动打开(半透明色块按 `bgAlpha` 真实显示)
|
||||||
|
|
||||||
|
三条写回路径合并成一入口 `applyTextColor(key, color, opts)`,支持色板里拖 SV 时的
|
||||||
|
`skipHistory`(一次拖动只算一步撤销)。选项栏那两个原生色块走的是同一份状态,两边永远一致。
|
||||||
|
|
||||||
|
### 3. 「无」
|
||||||
|
|
||||||
|
同一颗「无」按钮按当前格分派:填充 → `fill=false`(内部透明);文字描边 → 描边宽度 0;
|
||||||
|
文字底色 → 关掉色块。三种都只关开关、**颜色留着**。文字色没有「无」—— 字没有颜色等于把字删了。
|
||||||
|
|
||||||
|
### 4. 一格没生效就画斜杠
|
||||||
|
|
||||||
|
描边宽度 0 / 底色关闭时,对应格子显示为灰底红斜杠(不再露着上次的颜色),一眼能看出这格现在
|
||||||
|
没生效;半透明底色格按真实不透明度显示,看起来才像「垫了一块板」。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` 新增 11 条(三格可见性、描边色自动补宽度、底色自动开启、三格互不串、
|
||||||
|
「无」在底色格上的语义、切回矩形工具第三格收起),共 190 条全通。
|
||||||
|
|
||||||
|
## v1.11.0:工具栏变成「描边 + 填充」两格,填充可以设「无」
|
||||||
|
|
||||||
|
用户这次的反馈是「工具栏的调色、描边、填充 3 个位置调色有问题,应该是 2 个调色,
|
||||||
|
就是描边与填充,但现在没跟工具栏的调色关联上」,以及「填色里还要一个取消颜色的按钮」。
|
||||||
|
|
||||||
|
### 1. 颜色从三处收敛成两处
|
||||||
|
|
||||||
|
以前工具栏只有一个色点(主色),选项栏另有两个色块(描边 / 填充)。看起来是三个调色口,
|
||||||
|
其中工具栏那个**不参与填充**,于是「填充跟工具栏没关系」。现在工具栏就是
|
||||||
|
**描边 + 填充两个槽**(PS 式前/背景色叠放):点哪个槽,色板就调哪个槽。
|
||||||
|
|
||||||
|
- 描边槽 = `S.color`(也是画笔色、文字色、形状描边色,仍然一个值)
|
||||||
|
- 填充槽 = 形状自己的 `fillColor`,没单独设过就跟随描边色(右下角一个蓝三角)
|
||||||
|
- 色板新增当前目标切换(描边 / 填充),调色器、吸管、hex、推荐色、最近色全部按目标写
|
||||||
|
- 选项栏那两个色块与工具栏**双向同步**:改哪边,另一边立刻跟上
|
||||||
|
- 只有一笔颜色概念的工具(画笔、橡皮、文字、箭头)只显示一个槽,不留空格
|
||||||
|
|
||||||
|
### 2. 填充可以设「无」
|
||||||
|
|
||||||
|
色板里多了「无」按钮(只在调填充时出现):点它把 `fill` 关掉,形状内部透明、只留描边;
|
||||||
|
**颜色本身保留**,下次再选颜色还是它。无填充时工具栏填充槽显示为**灰底红斜杠**,
|
||||||
|
不露颜色 —— 露着上次的颜色会被当成「现在填的就是它」。
|
||||||
|
|
||||||
|
`S.colorTarget` 记录当前在调哪一格,`source` 只有一处:`colorSlots()` 同时供给工具栏、
|
||||||
|
色板头部、hex 与调色器,避免「一个概念两种颜色」再次出现。
|
||||||
|
|
||||||
|
## v1.10.0:颜色语义统一 / 选中框改实线 / 选区命令归位 / 矢量图形补描边与填充
|
||||||
|
|
||||||
|
这一版全部来自同一张界面截图上的四个疑问:「字体颜色有 3 个位置」「那个黑色应该换成
|
||||||
|
默认的参数」「字体这里有选区,这个不该出现」「选区工具反而没有这些按钮」。
|
||||||
|
四个都是真实缺陷,不是偏好。
|
||||||
|
|
||||||
|
### 1. 三处颜色各司其职(不再是三个长得一样的色块)
|
||||||
|
|
||||||
|
以前 `#ff4444` / `#ffffff` / `#000000` / `0.68` 这些默认值散在 `state.js`、`text.js`、
|
||||||
|
`events.js` 三处,改一处另两处不跟,界面上就出现「同一个概念三种颜色」。现在:
|
||||||
|
|
||||||
|
- `text.js` 导出 `TEXT_DEFAULTS`,**默认值单点定义**,`state.js` 与选项栏都从这里取;
|
||||||
|
- 描边色 / 底色 / 图形描边色的色块**统一外观**,但**标记生效状态**:
|
||||||
|
描边宽度为 0、底色关闭、图形处于「描边模式」时,色块显示为**灰色斜纹**
|
||||||
|
(不是颜色本身),语义是「这里还没有颜色」。以前半透明灰化不够——深色照样是一块黑方块,
|
||||||
|
用户会以为「设了个黑色没生效」;
|
||||||
|
- 文字底色默认从纯黑 `#000000` 改为中性近黑 `#101014`(68% 透明),色块按真实不透明度显示,
|
||||||
|
所见即所得,不再是一块死黑;
|
||||||
|
- 选描边色时若宽度为 0,自动给 6px(与「选底色即开底色」同一条原则:选了就是要用)。
|
||||||
|
|
||||||
|
### 2. 选中框从虚线改成实线
|
||||||
|
|
||||||
|
虚线在修图软件里的语义是**像素选区(蚂蚁线)**。文字/图形外面套一圈虚线,
|
||||||
|
用户会以为「莫名其妙多出来一个选区」,还删不掉。现在对象选中一律实线 + 四角手柄
|
||||||
|
(`objects.js` 的文字/形状、`layers.js` 的位图图层三处同步),虚线只留给真正的像素选区。
|
||||||
|
|
||||||
|
### 3. 选区命令(全选/反选/取消)归位到选区工具
|
||||||
|
|
||||||
|
那三个命令操作的是像素选区,跟文字对象没关系。以前它们挂在「选中文字/图形」的选项栏里,
|
||||||
|
选中一段文字就冒出来,看着像文字自带了选区;而真正的**矩形/套索选区工具**反而没有。
|
||||||
|
现在:选区工具(矩形、套索)有,选择工具「未选中任何元素」时也有,选中对象时不再出现。
|
||||||
|
|
||||||
|
### 4. 矢量图形补上描边色与填充色
|
||||||
|
|
||||||
|
- 每个形状新增独立的 `fillColor`;**描边色不再另起一份**,直接就是主色
|
||||||
|
(左侧色板 / 吸管 / 选项栏一个真相源,四处永远同步);
|
||||||
|
- `fillColor === null` 表示「跟随描边色」,于是新画的实心图形是**同色实心**,
|
||||||
|
换主色整块跟着变;一旦单独选过填充色就固定下来;
|
||||||
|
- 矩形/圆形/钢笔/箭头的选项栏都出现 `描边 ■` / `填充 ■` 色块(箭头没有填充区域,只给描边色),
|
||||||
|
选中已有图形时读它自己的值,没选中时改的是「下一次新建」的默认值;
|
||||||
|
- 选填充色即自动切到实心,色块随之从斜纹变成实际颜色;「样式 描边/实心」按钮
|
||||||
|
也改成读**选中对象自己**的 `fill`(以前只看全局默认值,选中一个已实心的矩形,
|
||||||
|
按钮却高亮「描边」,和画面反着来)。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` **172 条全部通过**(新增 10 条:默认色不写死、色块生效态、
|
||||||
|
选区命令归位、选中框实线覆盖率 ≥0.85、图形描边/填充色与实际像素)。
|
||||||
|
|
||||||
|
## v1.9.1:输入框贴住点击点 / 选区图标归位 / 底色一选就亮
|
||||||
|
|
||||||
|
v1.9.0 上线后用户反馈的三处「操作与实际反应不相符」。
|
||||||
|
|
||||||
|
### 1. 文字输入框跑到点击点的左上方
|
||||||
|
|
||||||
|
`showTextInput()` 用 `canvasStack` 的矩形换算屏幕坐标,但 stack 的尺寸是
|
||||||
|
`(imgW + 2 × overlayPad) × scale`,图片在 stack 内部还额外偏移了 `pad × scale`
|
||||||
|
(图层 canvas 的 `left/top`)。拿它算比例会偏小、又漏掉这段偏移,两个误差同向叠加,
|
||||||
|
输入框就整体挪到了左上。改为用 `textCanvas` 的矩形(与图层 canvas 同基准,
|
||||||
|
精确等于图片显示区域),并按 `textarea` 的边框 2px + 内边距 8/4px 反向偏移,
|
||||||
|
让「输入框里文字的起点」正好压在点击点上——提交后 `drawTextObject` 也从 `t.x/t.y` 起画,
|
||||||
|
两者位置一致。
|
||||||
|
|
||||||
|
### 2. 选「选择」工具那三个选区图标就不见了
|
||||||
|
|
||||||
|
两个原因叠在一起:
|
||||||
|
|
||||||
|
- 兜底分支里 `selCmdHTML()` 排在 `hint` **之后**,而 `.iwb-opt-hint` 带 `margin-left: auto`,
|
||||||
|
会把自己和后面的一切推到最右;
|
||||||
|
- 更关键的是 `.iwb-opt-sep` 写成了 `margin: 0 4px 0 auto`——分隔线自带 `auto`,
|
||||||
|
会把**分隔线之后的内容整组**推到最右侧。选项栏一旦排满(文字样式那一行),
|
||||||
|
这组按钮就被顶出可视区。
|
||||||
|
|
||||||
|
修法:分隔线只负责分组(`margin: 0 2px`),留白交给末尾的 `hint`;
|
||||||
|
选区按钮排在 `hint` 之前。现在「文字」和「选择」两个工具下都是同一组三个图标,
|
||||||
|
且未选中任何元素时也在(选区命令本来就是全局的)。
|
||||||
|
|
||||||
|
### 3. 设了文字底色却看不到
|
||||||
|
|
||||||
|
底色其实一直在画,问题是:**只改颜色、没点「底色」开关**时 `bgFill` 仍是 `false`,
|
||||||
|
画布上什么都不会变。用户于是以为底色没生效,或者被别的颜色盖住了。
|
||||||
|
|
||||||
|
- 改 `bgColor` 时自动把 `bgFill` 打开(选了颜色就是要用它),按钮的 `active` 同步亮起;
|
||||||
|
- 顺带修掉一个更硬的 bug:**「底色」按钮只能开、不能关**。它的 `data-value`
|
||||||
|
在生成 HTML 时就写死成 `${v.bgFill ? '0' : '1'}`,状态变了没人更新,
|
||||||
|
于是每次点击都传「开启」。现在 `syncOptionBar()` 会按当前状态翻面。
|
||||||
|
- 默认底色透明度 0.55 → 0.68:浅色/花色底图上 0.55 太透,容易被当成没生效。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` **162 条全部通过**(新增输入框落点误差 ≤3px、
|
||||||
|
Esc 取消不留空对象、选择工具未选中仍有 3 个图标、只选颜色即自动开底色 4 条)。
|
||||||
|
|
||||||
|
## v1.9.0:文字样式包 / 吸附参考线 / 圆角与最近色 / 复制到剪贴板
|
||||||
|
|
||||||
|
一次补齐四个高频缺口,都属于「没有它就得切回 PS」的那类。
|
||||||
|
|
||||||
|
### 1. 文字从「字号 + 颜色」扩到完整样式
|
||||||
|
|
||||||
|
`字号 / 字重(常规·粗·特粗)/ 对齐(左·中·右)/ 行距 / 描边 / 底色块 / 多行`。
|
||||||
|
|
||||||
|
关键是把「量出来的框」和「画出来的字」合成一处:新增叶子模块 `text.js`,
|
||||||
|
`fontOf / textMetrics / textBox / drawTextObject` 是唯一事实来源,
|
||||||
|
`objects.js`(预览、命中、包围盒)与 `layers.js`(栅格化进矢量层)都调它。
|
||||||
|
此前量 `measureText` 一套、画 `fillText` 一套,一旦加描边和底色必然错位。
|
||||||
|
|
||||||
|
- 描边与底色会**撑大包围盒**(`textBox()` 计入 `strokeWidth/2` 与 padding),
|
||||||
|
选择框、吸附、缩放手柄随之变化,不会出现「字比框大」。
|
||||||
|
- 输入框从 `<input>` 换成 `<textarea rows="1">`:Enter 提交、**Shift+Enter 换行**、
|
||||||
|
Esc 取消,`input` 时按 `scrollHeight` 自适应高度。
|
||||||
|
- 单行 + 无描边 + 无底色的老文字,`textBox()` 与旧实现逐像素一致 ——
|
||||||
|
已有作业打开不变形。
|
||||||
|
- 新建文字继承当前默认样式(`S.textWeight` 等),不必每段重调。
|
||||||
|
|
||||||
|
### 2. 拖动吸附(画布中心/边缘 + 其他元素对齐)
|
||||||
|
|
||||||
|
`snap.js` 只做纯计算:给一个盒子和「别人的盒子」,返回最小位移与命中的参考线。
|
||||||
|
|
||||||
|
- 目标线 = 画布 `0 / 中 / 满` + 其他**可见**元素的左/中/右、上/中/下。
|
||||||
|
- 阈值 `6` 屏幕像素,按 `viewScale()` 折回图片像素再比较 —— **磁力不随缩放变大**,
|
||||||
|
放到 400% 也不会一拖就黏。
|
||||||
|
- 命中后画洋红参考线(`#ff2d95`,刻意区别于选中框的橙 `#e8a735`),松手清空。
|
||||||
|
- **按住 Alt 全程禁用**,需要精细摆放时不用去关开关。
|
||||||
|
- 位图 / 文字 / 形状三条拖动路径都接了。文字因为 `textBox()` 相对原点有偏移,
|
||||||
|
必须把 `b.x - t.x` 补回坐标再算,否则吸附中心会偏半个描边。
|
||||||
|
|
||||||
|
### 3. 矩形圆角 + 最近使用颜色
|
||||||
|
|
||||||
|
- `shapeRadius` 进 `drawShape`,半径夹到 `min(w, h)/2`;路径手写 `moveTo + 4×arcTo`,
|
||||||
|
不用 `ctx.roundRect`(老内核没有)。
|
||||||
|
- 最近使用颜色最多 8 个,去重、新的在前,存 `ctx.settings`(**跨会话保留**)。
|
||||||
|
只有**落定**的改色才记录,拖色板滑杆过程中的中间色不会灌进来。
|
||||||
|
- 色板改事件委托:最近色色块是动态插入的,直接逐个绑定会漏。
|
||||||
|
|
||||||
|
### 4. 导出「复制到剪贴板」
|
||||||
|
|
||||||
|
顶栏「导出」左边新增「复制」:把当前结果编码成 PNG 塞进 `ClipboardItem`,
|
||||||
|
可直接粘到聊天窗口 / 后台上传框,**不关闭编辑器**。
|
||||||
|
|
||||||
|
- 走 `toPngBlob()`,优先 `createImageBitmap` —— 宿主页 CSP 常禁 `img-src: blob:`,
|
||||||
|
用 `new Image()` 解码会直接失败。
|
||||||
|
- 失败必须**说清楚**:非安全上下文(如 `about:blank`)没有 `navigator.clipboard`,
|
||||||
|
提示「当前浏览器不支持复制图片,请用「导出」下载」,而不是静默无反应。
|
||||||
|
真实 https / localhost 下已验证可用(`navigator.clipboard.read()` 能读回 `image/png`)。
|
||||||
|
|
||||||
|
### 两条踩过的坑
|
||||||
|
|
||||||
|
1. **esbuild 打成 IIFE 后,循环 import 会变成 `undefined`**。新逻辑一律放只 import
|
||||||
|
`state.js` 的叶子模块(`text.js` / `snap.js` / `recent-colors.js`),
|
||||||
|
不要为省一个文件把它们并进 `objects.js`。
|
||||||
|
2. **选项栏里的中文双字标签必须 `white-space: nowrap`**,否则挤进 36px 高的一行会竖排
|
||||||
|
成「常/规」。另外说明文字(hint)要排在按钮**之后**:真放不下时宁可让说明滚出视野,
|
||||||
|
也不能把「复制 / 取消选区」这类按钮顶没。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` 由 140 条增到 **158 条,全部通过**(新增多行包围盒、
|
||||||
|
字重/描边/底色生效并可撤销、吸附误差 < 1px、Alt 禁用、参考线松手清除、
|
||||||
|
圆角切角、最近色入弹层、复制有明确反馈等)。
|
||||||
|
|
||||||
|
## v1.8.3:图层面板交互修复(滑杆能拖、图层能拖排)
|
||||||
|
|
||||||
|
线上两个反馈,根子在同一个属性上:
|
||||||
|
|
||||||
|
1. **不透明度滑杆只能点、不能拖** —— 点了滑杆轨道数值会跳,但按住拖动毫无反应。
|
||||||
|
2. **图层拖不动排序** —— 拖了松手顺序不变,看起来像没实现。
|
||||||
|
|
||||||
|
### 根因
|
||||||
|
|
||||||
|
图层项写了 `draggable="true"`。HTML5 原生拖动是**祖先级**的:在任何子元素上按住拖动,
|
||||||
|
浏览器会先把它当成「拖动这个祖先」,于 range 滑杆的拇指永远收不到拖动事件(只剩点击能改值)。
|
||||||
|
排序那套 `dragstart/drop` 本身能跑,但插入位置按「目标项索引」算 ——
|
||||||
|
先把自己从数组里删掉再取目标索引,向下拖一格时索引正好回退,结果等于原地不动;
|
||||||
|
加上没有任何落点反馈(`.drop-target` 样式写了却没人加),最终观感就是「拖了没反应」。
|
||||||
|
|
||||||
|
### 修法
|
||||||
|
|
||||||
|
- **整项去掉 `draggable`**,排序改由 `bindLayerDragSort()` 用指针事件自己实现:
|
||||||
|
`pointerdown` 记录起点 → 位移超 4px 才算拖动(否则仍是一次点击选中)→
|
||||||
|
`pointermove` 越过哪一行的中线就真的 `insertBefore` 到那一行前面,其余行实时让位 →
|
||||||
|
`pointerup` 直接读 DOM 顺序落地。
|
||||||
|
- **不再自己算索引**:落点顺序就是最终 DOM 顺序,从根上消掉「上下方向语义不一致」这类错。
|
||||||
|
- **滑杆/按钮/改名输入框不参与排序**(`closest` 排除),拖动滑杆时图层像素实时跟随(CSS `opacity`)。
|
||||||
|
- 一次拖动 = 一条撤销;顺序没变则不拍快照、不留空撤销。
|
||||||
|
- `原图` 固定最底层:拖到最底只能停在它上面,不会被拖到看不见的地方。
|
||||||
|
- 拖动中整行浮起(描橙边、不透明,避免与下方行文字叠成一团),列表光标 `grabbing`。
|
||||||
|
|
||||||
|
### 一个必须记住的坑
|
||||||
|
|
||||||
|
`window.addEventListener('blur', …, true)` **会收到子元素的 blur**(blur 不冒泡但捕获能收)。
|
||||||
|
用它做「窗口失焦就取消拖动」的兜底时,鼠标一按到图层行、焦点从工具栏按钮挪走就会立刻
|
||||||
|
取消这次拖动 —— 表现为「先点过按钮再拖必然失败」。必须判 `e.target === window`。
|
||||||
|
harness 里专门有一条用例守着它。
|
||||||
|
|
||||||
|
测试:`node image-annotate/tools/harness.mjs` 146 项(新增 6 项:真实鼠标拖滑杆、
|
||||||
|
向下换位与 z 同步、拖到最底、位移不足算点击、焦点在工具栏时也能拖、位图与矢量混排)。
|
||||||
|
|
||||||
|
## v1.8.2:选择框控制点尺寸固定为屏幕像素
|
||||||
|
|
||||||
|
选中图形 / 文字 / 位图时,控制点、旋转手柄、虚线间距、命中半径原本一律写成
|
||||||
|
`5.5 / S.zoom`。但 `S.zoom` 是「**相对 fitW 的倍数**」,不是「图片像素 → 屏幕像素」的比例。
|
||||||
|
叠上 overlay 画布按 viewScale 拉伸后,控制点的真实屏幕尺寸变成 `11 × fitW / imgW`:
|
||||||
|
**只跟图片尺寸走,和缩放完全无关**。小图被「适应窗口」放大 5~10 倍时,控制点会膨胀成
|
||||||
|
100px 的发光团(截图里那种),大图则缩成看不见的点。
|
||||||
|
|
||||||
|
修法:新增 `plugin/editor/scale.js`(零依赖叶子模块)
|
||||||
|
|
||||||
|
| 导出 | 含义 |
|
||||||
|
| --- | --- |
|
||||||
|
| `viewScale()` | `fitW × zoom / imgW` —— 1 个图片像素 = 多少屏幕 CSS 像素 |
|
||||||
|
| `overlayScale()` | `clamp(fitW / imgW, 1, 4)` —— overlay 画布的像素倍率 |
|
||||||
|
| `resetOverlayTransform(cx)` | 清屏后把 ctx 恢复成「图片坐标 + pad + 倍率」 |
|
||||||
|
|
||||||
|
- 所有「屏幕上恒定」的量改成 `X / viewScale()`:控制点 11px、虚线 1.5px、命中半径 11~16px
|
||||||
|
- 原先 `Math.max(X / zoom, N)` 的托底值 `N` 是**图片单位**,放大时会变成巨大的命中区(误触),一并去掉
|
||||||
|
- `viewScale()` 必须来自叶子模块:viewport 与 crop / objects / layers 互相 import,
|
||||||
|
把换算放在循环里,esbuild 打成 IIFE 后另一侧会拿到 undefined(实测报
|
||||||
|
`resetOverlayTransform is not defined`,编辑器直接打不开)
|
||||||
|
|
||||||
|
顺带修第二个问题:overlay 画布的像素缓冲原本等于图片尺寸,小图放大后控制点糊成一片光斑。
|
||||||
|
现在按 `overlayScale()` 建缓冲(96×64 → 1152×1024),绘制坐标仍是图片单位
|
||||||
|
(transform 里已含倍率),所以全部绘制代码不用改。上限 4 是为内存,缓冲面积按平方增长。
|
||||||
|
|
||||||
|
**实测**(Playwright 按屏幕分辨率重采样后量像素):96×64 / 800×600 / 2400×1800 三张图,
|
||||||
|
控制点屏幕尺寸 7~10px(视觉 11px —— 纯白内区比外框小 1.5px 描边):
|
||||||
|
旧实现分别是 **101.5 / 12.2 / 4.1px**。harness 新增 1 项断言守住这条。
|
||||||
|
|
||||||
## v1.8.1:修复 SRI 加载失败(发布通道改内容寻址)
|
## v1.8.1:修复 SRI 加载失败(发布通道改内容寻址)
|
||||||
|
|
||||||
v1.8.0 上线后线上报「脚本完整性校验失败(integrity 不符或加载失败)」,插件直接不可用。
|
v1.8.0 上线后线上报「脚本完整性校验失败(integrity 不符或加载失败)」,插件直接不可用。
|
||||||
|
|||||||
@@ -124,6 +124,7 @@
|
|||||||
| 无混合模式 | 正片叠底/滤色/叠加是合成常用 | P3 |
|
| 无混合模式 | 正片叠底/滤色/叠加是合成常用 | P3 |
|
||||||
| 无图层蒙版 | 抠图只能破坏性擦除,不能反悔 | P3 |
|
| 无图层蒙版 | 抠图只能破坏性擦除,不能反悔 | P3 |
|
||||||
| ~~无重命名 / 多选~~ / 编组 | ✅ v1.7:双击名字改名(自算双击)、⌘/Ctrl 点击多选合并;编组仍待做 | 部分完成 |
|
| ~~无重命名 / 多选~~ / 编组 | ✅ v1.7:双击名字改名(自算双击)、⌘/Ctrl 点击多选合并;编组仍待做 | 部分完成 |
|
||||||
|
| ~~拖动排序不生效~~ | ✅ v1.8.3:整项 `draggable` 会吃掉子元素的原生拖动(滑杆只能点不能拖)、向下拖一格索引回退等于原地不动。改为指针拖动 + 实时插位,松手读 DOM 顺序落地 | 已完成 |
|
||||||
| `resetDraw()` 语义歧义 | 「清空标注」只清非 base 层像素,留下空白粘贴层(1.0.5 遗留)⇒ **已裁定改为「全部还原」**:删所有非 base 层 + 清绘制 + 复位变换,一步可撤销;按钮改名「还原原图」 | P0 定语义(已定) |
|
| `resetDraw()` 语义歧义 | 「清空标注」只清非 base 层像素,留下空白粘贴层(1.0.5 遗留)⇒ **已裁定改为「全部还原」**:删所有非 base 层 + 清绘制 + 复位变换,一步可撤销;按钮改名「还原原图」 | P0 定语义(已定) |
|
||||||
|
|
||||||
### 3.4 输出(单张)
|
### 3.4 输出(单张)
|
||||||
@@ -133,7 +134,7 @@
|
|||||||
| 只有 PNG | 无 JPG/WebP、无质量控制 | P4 |
|
| 只有 PNG | 无 JPG/WebP、无质量控制 | P4 |
|
||||||
| 无背景切换(透明 / 白底) | 电商出图要手工来回切换 | P4 |
|
| 无背景切换(透明 / 白底) | 电商出图要手工来回切换 | P4 |
|
||||||
| 无体积上限策略 | 无法保证 ≤500KB 这类交付规范 ⇒ **已裁定做成可切换预设**(800×800 / 长边 640 / 质量迭代 ≤500KB,存 `ctx.settings`) | P4(随 P1 带上) |
|
| 无体积上限策略 | 无法保证 ≤500KB 这类交付规范 ⇒ **已裁定做成可切换预设**(800×800 / 长边 640 / 质量迭代 ≤500KB,存 `ctx.settings`) | P4(随 P1 带上) |
|
||||||
| 无下载 / 复制到系统剪贴板 | 只能回写宿主节点 | P4 |
|
| ~~无下载 / 复制到系统剪贴板~~ | ✅ v1.9.0:顶栏「导出」下载;「复制」把结果编成 PNG 写 `ClipboardItem`,粘进聊天窗口/后台上传框,不关闭编辑器。非安全上下文无 `navigator.clipboard` 时明确提示改用导出 | 已完成 |
|
||||||
| 导出步骤偏多 | 覆盖 / 新建 / 退出三个按钮分散,没有「记住上次选择」 | P0 / P4 |
|
| 导出步骤偏多 | 覆盖 / 新建 / 退出三个按钮分散,没有「记住上次选择」 | P0 / P4 |
|
||||||
| 导出后图层信息丢失 | 节点里是一张扁平 PNG,下次打开要从头来 | P5(需宿主配合) |
|
| 导出后图层信息丢失 | 节点里是一张扁平 PNG,下次打开要从头来 | P5(需宿主配合) |
|
||||||
|
|
||||||
@@ -310,6 +311,17 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
||||||
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
||||||
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
||||||
|
| 右栏调色面板 / 可拖宽度 / 字号(v1.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` 五处解封,其他图层可拖到原图下方 |
|
||||||
|
| 颜色体系与矢量属性 | ✅ v1.12.0:颜色上下文收敛成 `colorContext()` 三档(文字 / 形状 / 只有主色),文字上下文给**三格**(文字 / 描边 / 底色,`data-color-mode="triple"`),`applyTextColor()` 统管描边色与底色的写回(含 `skipHistory` 拖拽);「无」按当前格分派(无填充 / 无描边 / 无底色);原文「文本不支持描边与字体色切换」已修 |
|
||||||
|
| 颜色体系与矢量属性(v1.11) | ✅ v1.11.0:颜色收敛为**描边 / 填充两格**——工具栏改 PS 式双色槽(`S.colorTarget` 决定色板写哪一格),选项栏两色块与工具栏双向同步,`colorSlots()` 成为唯一取值处;填充支持**无**(`fill=false`,颜色保留,槽位画灰底红斜杠);画笔/文字/箭头等无填充概念的工具只显示一格(v1.12 起文字改三格) |
|
||||||
|
| 颜色体系与矢量属性(v1.10) | ✅ v1.10.0:默认值收口到 `TEXT_DEFAULTS`(文字底色去掉纯黑);三个色块标记「生效/未生效」(未生效显示灰色斜纹);对象选中框改实线(虚线只留给像素选区);选区命令归位到矩形/套索选区工具;矢量图形新增独立 `fillColor`,描边色复用主色,选项栏出 `描边 ■ / 填充 ■` 色块,填充缺省跟随描边 |
|
||||||
|
| 文字样式与吸附 | ✅ v1.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
|
||||||
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
||||||
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
||||||
|
|
||||||
@@ -327,6 +339,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 魔棒 | 宿主 CSP 未放行 `worker-src blob:` ⇒ 不能用 Worker 做连通域;放二期,主线程分块 + 让出帧,且限制最大像素数 |
|
| 魔棒 | 宿主 CSP 未放行 `worker-src blob:` ⇒ 不能用 Worker 做连通域;放二期,主线程分块 + 让出帧,且限制最大像素数 |
|
||||||
| CSP | 单文件经典脚本 IIFE;禁 `eval` / `new Function` / ESM / CDN;样式 JS 注入 `<style>`;`toBlob` 要求 origin-clean ⇒ 远程图片必须 `fetch → blob → dataURL`(现有 `onPaste` 已按此实现) |
|
| CSP | 单文件经典脚本 IIFE;禁 `eval` / `new Function` / ESM / CDN;样式 JS 注入 `<style>`;`toBlob` 要求 origin-clean ⇒ 远程图片必须 `fetch → blob → dataURL`(现有 `onPaste` 已按此实现) |
|
||||||
| 宿主争抢 paste | 宿主在 window 气泡阶段也监听粘贴(建 ref 节点 + 下载)。编辑器继续在 document 捕获阶段 `stopImmediatePropagation()`。新增「复制选区到系统剪贴板」需要 `ClipboardItem` + 用户手势 + 权限,失败必须有 toast 降级 |
|
| 宿主争抢 paste | 宿主在 window 气泡阶段也监听粘贴(建 ref 节点 + 下载)。编辑器继续在 document 捕获阶段 `stopImmediatePropagation()`。新增「复制选区到系统剪贴板」需要 `ClipboardItem` + 用户手势 + 权限,失败必须有 toast 降级 |
|
||||||
|
| 选项栏横向排布 | `.iwb-editor-optionbar-body` 是 `overflow-x: auto` 的 flex。**任何 `margin-left: auto` 都会把其后内容整组推到最右**,排满时直接滚出可视区 —— `v1.9.1` 就是 `.iwb-opt-sep` 带了 `auto`,导致选区按钮在选择工具下「消失」。留白只允许放在末尾的 `.iwb-opt-hint`;中文双字按钮必须 `white-space: nowrap`,否则会竖排 |
|
||||||
| 草稿持久化 | `ctx.storage` 是 localStorage 命名空间小 KV(`get/set/remove/keys`),**不能塞像素**;`ctx.settings` 适合存输出预设与面板开合。若要做工程草稿,只能存元数据 + 宿主节点引用;真要存图层像素需插件自建 IndexedDB 库(必须自带 `onupgradeneeded` 建表,宿主踩过这个坑)或与宿主协商新能力 |
|
| 草稿持久化 | `ctx.storage` 是 localStorage 命名空间小 KV(`get/set/remove/keys`),**不能塞像素**;`ctx.settings` 适合存输出预设与面板开合。若要做工程草稿,只能存元数据 + 宿主节点引用;真要存图层像素需插件自建 IndexedDB 库(必须自带 `onupgradeneeded` 建表,宿主踩过这个坑)或与宿主协商新能力 |
|
||||||
| 节点模型 | 宿主 `setNodeImage` / `createImageNode` 只收一张图;导出即扁平化。要做「可继续编辑的工程」需要宿主侧支持节点附加数据 ⇒ 属于跨仓变更,P5 再评估 |
|
| 节点模型 | 宿主 `setNodeImage` / `createImageNode` 只收一张图;导出即扁平化。要做「可继续编辑的工程」需要宿主侧支持节点附加数据 ⇒ 属于跨仓变更,P5 再评估 |
|
||||||
| 上游关系 | 编辑器移植自 `iwb-plaus/iwb-cutout-extension`,README 已警告 1.0.5 的 z 序修复不能整目录覆盖回去。P0 的大改等于正式分叉,应在 README 明确改为「一次性移植 + 独立演进」,避免以后误回灌 |
|
| 上游关系 | 编辑器移植自 `iwb-plaus/iwb-cutout-extension`,README 已警告 1.0.5 的 z 序修复不能整目录覆盖回去。P0 的大改等于正式分叉,应在 README 明确改为「一次性移植 + 独立演进」,避免以后误回灌 |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.8.1",
|
"version": "1.16.0",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -563,10 +563,17 @@
|
|||||||
border: 2px solid #4488ff;
|
border: 2px solid #4488ff;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
line-height: 1.35;
|
||||||
|
/* textarea:默认会显示右下角拖拽柄与滚动条,画布上的就地输入框都不要 */
|
||||||
|
resize: none;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: pre;
|
||||||
background: rgba(255, 255, 255, 0.95);
|
background: rgba(255, 255, 255, 0.95);
|
||||||
color: #1e1e2e;
|
color: #1e1e2e;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
min-width: 120px;
|
min-width: 120px;
|
||||||
|
min-height: 30px;
|
||||||
|
font-family: inherit;
|
||||||
}
|
}
|
||||||
.iwb-editor-text-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(68, 136, 255, 0.3); }
|
.iwb-editor-text-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(68, 136, 255, 0.3); }
|
||||||
|
|
||||||
@@ -751,6 +758,8 @@
|
|||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
|
/* 拖动排序的插入线是绝对定位的,锚点必须在列表上(随滚动一起移动) */
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 图层项:整项改成「行 + 可选的不透明度行」,两行都靠 .iwb-layer-row 保持原来的横向排布 */
|
/* 图层项:整项改成「行 + 可选的不透明度行」,两行都靠 .iwb-layer-row 保持原来的横向排布 */
|
||||||
@@ -758,7 +767,8 @@
|
|||||||
display: block;
|
display: block;
|
||||||
padding: 5px 8px;
|
padding: 5px 8px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
cursor: pointer;
|
cursor: grab;
|
||||||
|
user-select: none;
|
||||||
transition: background 0.12s;
|
transition: background 0.12s;
|
||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
}
|
}
|
||||||
@@ -774,9 +784,18 @@
|
|||||||
box-shadow: inset 2px 0 0 #e8a735;
|
box-shadow: inset 2px 0 0 #e8a735;
|
||||||
}
|
}
|
||||||
.iwb-layer-item.hidden { opacity: 0.5; }
|
.iwb-layer-item.hidden { opacity: 0.5; }
|
||||||
.iwb-layer-item[draggable="true"] { cursor: grab; }
|
/* 拖动中:整行跟着指针浮起,压住相邻行;其余行由 JS 实时让位(落点反馈) */
|
||||||
.iwb-layer-item.dragging { opacity: 0.45; }
|
.iwb-layer-item.dragging {
|
||||||
.iwb-layer-item.drop-target { outline: 1px dashed #e8a735; background: rgba(232, 167, 53, 0.16); }
|
position: relative;
|
||||||
|
z-index: 3;
|
||||||
|
opacity: 1;
|
||||||
|
background: #3a3d55;
|
||||||
|
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5), inset 0 0 0 1px #e8a735;
|
||||||
|
transition: none;
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
.iwb-editor-layer-list.sorting,
|
||||||
|
.iwb-editor-layer-list.sorting .iwb-layer-item { cursor: grabbing; }
|
||||||
/* 画笔/橡皮作用目标:与「选中」分离,避免出现两个图层同时高亮 */
|
/* 画笔/橡皮作用目标:与「选中」分离,避免出现两个图层同时高亮 */
|
||||||
.iwb-layer-paint { flex: 0 0 auto; color: #a6adc8; font-size: 11px; opacity: 0.85; }
|
.iwb-layer-paint { flex: 0 0 auto; color: #a6adc8; font-size: 11px; opacity: 0.85; }
|
||||||
/* 不透明度角标:只有非 100% 才出现,一眼看出哪层被调淡了 */
|
/* 不透明度角标:只有非 100% 才出现,一眼看出哪层被调淡了 */
|
||||||
@@ -1199,7 +1218,9 @@
|
|||||||
|
|
||||||
/* 左栏:调色板在上,参数竖排,导出按钮底部 */
|
/* 左栏:调色板在上,参数竖排,导出按钮底部 */
|
||||||
.iwb-editor-left {
|
.iwb-editor-left {
|
||||||
width: 240px; min-width: 240px; flex: 0 0 240px;
|
/* v1.16:宽度唯一出处。拖拽手柄写 --iwb-side-w,下面两条历史规则也都读它,
|
||||||
|
不再各写一个 240/220 的魔数(以前三处硬编码,改一次要搜三次)。 */
|
||||||
|
width: var(--iwb-side-w, 280px); min-width: var(--iwb-side-w, 280px); flex: 0 0 var(--iwb-side-w, 280px);
|
||||||
display: flex; flex-direction: column; gap: 14px;
|
display: flex; flex-direction: column; gap: 14px;
|
||||||
padding: 12px; background: #181825; border-right: 1px solid #313244; overflow-y: auto;
|
padding: 12px; background: #181825; border-right: 1px solid #313244; overflow-y: auto;
|
||||||
}
|
}
|
||||||
@@ -1303,7 +1324,7 @@
|
|||||||
.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }
|
.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }
|
||||||
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 290px; min-width: 290px; width: 290px; }
|
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 290px; min-width: 290px; width: 290px; }
|
||||||
.iwb-editor-main > .iwb-editor-canvas-wrap { flex: 1 1 auto; min-width: 0; }
|
.iwb-editor-main > .iwb-editor-canvas-wrap { flex: 1 1 auto; min-width: 0; }
|
||||||
.iwb-editor-left { flex: 0 0 240px; min-width: 240px; width: 240px; }
|
.iwb-editor-left { flex: 0 0 var(--iwb-side-w, 280px); min-width: var(--iwb-side-w, 280px); width: var(--iwb-side-w, 280px); }
|
||||||
.iwb-editor-layer-panel .iwb-editor-layer-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
|
.iwb-editor-layer-panel .iwb-editor-layer-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
|
||||||
|
|
||||||
/* ======== 顶部布局 v5:左侧重置类 / 中间工具 / 右侧保存类 ======== */
|
/* ======== 顶部布局 v5:左侧重置类 / 中间工具 / 右侧保存类 ======== */
|
||||||
@@ -1422,6 +1443,12 @@
|
|||||||
}
|
}
|
||||||
.iwb-editor-optionbar-label { color: #7f849c; font-weight: 600; white-space: nowrap; }
|
.iwb-editor-optionbar-label { color: #7f849c; font-weight: 600; white-space: nowrap; }
|
||||||
.iwb-editor-optionbar-body { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
|
.iwb-editor-optionbar-body { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
|
||||||
|
/* 右端通用快捷键提示。原来只有 @media 里的 display:none,没有任何基础样式,
|
||||||
|
于是它作为裸 span 参与 flex 收缩,被挤成两行还贴到右边缘外。 */
|
||||||
|
.iwb-editor-optionbar-tip {
|
||||||
|
flex: 0 0 auto; white-space: nowrap;
|
||||||
|
color: #6c7086; font-size: 11px; padding-left: 4px;
|
||||||
|
}
|
||||||
.iwb-opt-label { color: #a6adc8; white-space: nowrap; }
|
.iwb-opt-label { color: #a6adc8; white-space: nowrap; }
|
||||||
.iwb-opt-btn {
|
.iwb-opt-btn {
|
||||||
background: #313244; color: #cdd6f4; border: 1px solid transparent; border-radius: 5px;
|
background: #313244; color: #cdd6f4; border: 1px solid transparent; border-radius: 5px;
|
||||||
@@ -1433,8 +1460,19 @@
|
|||||||
width: 46px; padding: 2px 4px; background: #313244; color: #e8a735;
|
width: 46px; padding: 2px 4px; background: #313244; color: #e8a735;
|
||||||
border: 1px solid #45475a; border-radius: 5px; text-align: center; font-size: 12px;
|
border: 1px solid #45475a; border-radius: 5px; text-align: center; font-size: 12px;
|
||||||
}
|
}
|
||||||
|
/* 字体下拉:flex:0 0 auto 不能被压 —— 选项文字是 2 个汉字宽,压窄后会被截成「黑…」,
|
||||||
|
用户没法确认自己选的是哪一档。 */
|
||||||
|
.iwb-opt-select {
|
||||||
|
flex: 0 0 auto; padding: 2px 4px; background: #313244; color: #cdd6f4;
|
||||||
|
border: 1px solid #45475a; border-radius: 5px; font-size: 12px; cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-opt-select:hover { background: #45475a; }
|
||||||
|
.iwb-opt-select option { background: #1e1e2e; color: #cdd6f4; }
|
||||||
.iwb-opt-current { color: #e8a735; font-weight: 600; white-space: nowrap; }
|
.iwb-opt-current { color: #e8a735; font-weight: 600; white-space: nowrap; }
|
||||||
.iwb-opt-hint { color: #7f849c; font-size: 11px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
/* hint 是「说明」不是「控件」:不许被压缩。
|
||||||
|
早先带 text-overflow:ellipsis,在 36px 高的选项栏里会被压成「双击改…」这种半截文案,
|
||||||
|
比不显示更误导人;现在由父级 overflow-x 决定是完整显示还是整体滚出视野。 */
|
||||||
|
.iwb-opt-hint { color: #7f849c; font-size: 11px; margin-left: auto; white-space: nowrap; flex: 0 0 auto; }
|
||||||
|
|
||||||
.iwb-editor-more-wrap, .iwb-editor-export-settings-wrap { position: relative; flex: 0 0 auto; z-index: 45; }
|
.iwb-editor-more-wrap, .iwb-editor-export-settings-wrap { position: relative; flex: 0 0 auto; z-index: 45; }
|
||||||
.iwb-editor-more-btn, .iwb-editor-panel-toggle, .iwb-editor-export-settings-btn {
|
.iwb-editor-more-btn, .iwb-editor-panel-toggle, .iwb-editor-export-settings-btn {
|
||||||
@@ -1493,7 +1531,7 @@
|
|||||||
}
|
}
|
||||||
.iwb-editor-main { padding-left: 0; }
|
.iwb-editor-main { padding-left: 0; }
|
||||||
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 260px !important; min-width: 260px !important; width: 260px !important; }
|
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 260px !important; min-width: 260px !important; width: 260px !important; }
|
||||||
.iwb-editor-left { flex: 0 0 220px !important; min-width: 220px !important; width: 220px !important; }
|
.iwb-editor-left { flex: 0 0 var(--iwb-side-w, 280px) !important; min-width: var(--iwb-side-w, 280px) !important; width: var(--iwb-side-w, 280px) !important; }
|
||||||
.iwb-editor-overlay.panels-collapsed .iwb-editor-layer-panel,
|
.iwb-editor-overlay.panels-collapsed .iwb-editor-layer-panel,
|
||||||
.iwb-editor-overlay.panels-collapsed .iwb-editor-left { display: none !important; }
|
.iwb-editor-overlay.panels-collapsed .iwb-editor-left { display: none !important; }
|
||||||
.iwb-editor-zoom-hint { display: none !important; }
|
.iwb-editor-zoom-hint { display: none !important; }
|
||||||
@@ -1646,7 +1684,11 @@
|
|||||||
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:hover:not(:disabled) { background: #45475a; }
|
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:hover:not(:disabled) { background: #45475a; }
|
||||||
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
.iwb-editor-header > .iwb-editor-commands .iwb-editor-layer-btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
||||||
/* 选区命令(全选/反选/取消):v1.2.5 起放在「选择」工具的选项栏里,不再占竖工具条 */
|
/* 选区命令(全选/反选/取消):v1.2.5 起放在「选择」工具的选项栏里,不再占竖工具条 */
|
||||||
.iwb-opt-sep { width: 1px; height: 18px; background: #313244; margin: 0 4px 0 auto; flex: 0 0 auto; }
|
/* 分隔线只负责「分组」,不负责「推到右边」。
|
||||||
|
原来写的是 margin: 0 4px 0 auto —— auto 会把分隔线之后的内容整组推到最右侧,
|
||||||
|
在选项栏已经排满的情况下(文字样式那一行)直接把后面的选区按钮顶出可视区,
|
||||||
|
看起来就是「这个工具下没有那几个按钮」。留白交给末尾的 .iwb-opt-hint。 */
|
||||||
|
.iwb-opt-sep { width: 1px; height: 18px; background: #313244; margin: 0 2px; flex: 0 0 auto; }
|
||||||
.iwb-opt-selcmd {
|
.iwb-opt-selcmd {
|
||||||
width: 26px; height: 26px; min-width: 26px; padding: 0; border: 0; border-radius: 7px;
|
width: 26px; height: 26px; min-width: 26px; padding: 0; border: 0; border-radius: 7px;
|
||||||
background: #26263a; color: #cdd6f4; flex: 0 0 auto;
|
background: #26263a; color: #cdd6f4; flex: 0 0 auto;
|
||||||
@@ -1681,26 +1723,106 @@
|
|||||||
================================================================ */
|
================================================================ */
|
||||||
.iwb-editor-modal { position: relative; }
|
.iwb-editor-modal { position: relative; }
|
||||||
|
|
||||||
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn {
|
/* ---- v1.11:工具栏颜色双槽(描边 + 填充) ----
|
||||||
width: 32px; height: 32px; min-width: 32px; flex: 0 0 auto; padding: 0;
|
一个 30px 的按钮位上叠两颗:左上 19px 是描边,右下 19px 是填充。
|
||||||
border: 0; border-radius: 9px; background: #313244; cursor: pointer;
|
描边压在上面(最常用),填充露出右下角,一眼能看出是两格、谁是上级。
|
||||||
display: inline-flex; align-items: center; justify-content: center;
|
只有「描边」概念的工具(画笔/文字/箭头)把填充槽藏起来,描边槽放大占满,
|
||||||
|
不留一个空位让人猜。 */
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair {
|
||||||
|
position: relative; width: 30px; height: 30px; flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn:hover,
|
.iwb-editor-color-pair .iwb-editor-color-btn {
|
||||||
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn.active { background: #45475a; }
|
position: absolute; width: 19px; height: 19px; min-width: 0; padding: 0;
|
||||||
.iwb-editor-color-btn i {
|
border: 0; border-radius: 6px; background: #181825; cursor: pointer;
|
||||||
width: 18px; height: 18px; border-radius: 50%; display: block; background: #ff4444;
|
display: inline-flex; align-items: center; justify-content: center;
|
||||||
box-shadow: 0 0 0 2px #181825, 0 0 0 3px #585b70;
|
box-shadow: 0 0 0 1.5px #585b70;
|
||||||
|
}
|
||||||
|
.iwb-editor-color-pair [data-color-slot="stroke"] { left: 0; top: 0; z-index: 2; }
|
||||||
|
.iwb-editor-color-pair [data-color-slot="fill"] { right: 0; bottom: 0; z-index: 1; }
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn:hover { box-shadow: 0 0 0 2px #89b4fa; }
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn.active { box-shadow: 0 0 0 2px #e8a735; }
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn i {
|
||||||
|
width: 12px; height: 12px; border-radius: 3px; display: block;
|
||||||
|
background-color: #ff4444; background-size: 100% 100%;
|
||||||
|
}
|
||||||
|
/* 无填充:不露颜色本身,画一道红斜杠 —— 留着上次的颜色会被当成「现在填的就是它」 */
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn.is-none i {
|
||||||
|
background-color: #45475a !important;
|
||||||
|
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||||
|
}
|
||||||
|
/* 填充色还在「跟随描边色」:右下角一个小三角,表示它不是自己指定的 */
|
||||||
|
.iwb-editor-color-pair .iwb-editor-color-btn.is-follow::after {
|
||||||
|
content: ''; position: absolute; right: 0; bottom: 0;
|
||||||
|
border-left: 4px solid transparent; border-bottom: 4px solid #89b4fa;
|
||||||
|
}
|
||||||
|
.iwb-editor-color-pair[data-color-mode="single"] [data-color-slot="fill"] { display: none; }
|
||||||
|
.iwb-editor-color-pair[data-color-mode="single"] [data-color-slot="stroke"] {
|
||||||
|
left: 1px; top: 1px; width: 28px; height: 28px; border-radius: 8px;
|
||||||
|
}
|
||||||
|
.iwb-editor-color-pair[data-color-mode="single"] [data-color-slot="stroke"] i { width: 20px; height: 20px; border-radius: 6px; }
|
||||||
|
|
||||||
|
/* ---- v1.12:文字上下文的第三格「文本框底色」 ----
|
||||||
|
文字对象天生三个颜色(文字 / 描边 / 底色),两格叠放塞不下第三个。
|
||||||
|
文字上下文三格横排,各 18px,谁在调谁戴橙圈。
|
||||||
|
选择器必须带上 .iwb-editor-canvas-wrap > .iwb-editor-tools 前缀:上面那条
|
||||||
|
30px 宽的定位规则是三段选择器,少了前缀优先级压不过它,格子会被挤成 10px。 */
|
||||||
|
.iwb-editor-color-pair [data-color-slot="bg"] { display: none; }
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair[data-color-mode="triple"] {
|
||||||
|
width: 62px; display: flex; align-items: center; justify-content: space-between;
|
||||||
|
}
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair[data-color-mode="triple"] [data-color-slot] {
|
||||||
|
position: relative; left: auto; top: auto; right: auto; bottom: auto; z-index: 1;
|
||||||
|
display: inline-flex; flex: 0 0 auto; width: 18px; height: 18px; border-radius: 5px;
|
||||||
|
}
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair[data-color-mode="triple"] [data-color-slot="bg"] {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
|
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair[data-color-mode="triple"] .iwb-editor-color-btn i {
|
||||||
|
width: 11px; height: 11px; border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.iwb-editor-color-pop {
|
.iwb-editor-color-pop {
|
||||||
position: absolute; z-index: 60; display: flex; align-items: center; gap: 10px;
|
position: absolute; z-index: 60; display: flex; flex-direction: column; align-items: stretch; gap: 9px;
|
||||||
padding: 10px 12px; border-radius: 12px;
|
padding: 10px 12px; border-radius: 12px;
|
||||||
background: rgba(24, 24, 37, 0.97); border: 1px solid #313244;
|
background: rgba(24, 24, 37, 0.97); border: 1px solid #313244;
|
||||||
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
|
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
|
||||||
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
|
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
|
||||||
}
|
}
|
||||||
.iwb-editor-color-pop[hidden] { display: none; }
|
.iwb-editor-color-pop[hidden] { display: none; }
|
||||||
|
/* 弹层头部:说明现在调的是描边还是填充,并可直接换;右侧是「无」(仅填充) */
|
||||||
|
.iwb-color-pop-head { display: flex; align-items: center; gap: 6px; }
|
||||||
|
.iwb-color-pop-tab {
|
||||||
|
display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
|
||||||
|
border: 1px solid transparent; border-radius: 7px; background: #232334;
|
||||||
|
color: #a6adc8; font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab i {
|
||||||
|
width: 11px; height: 11px; border-radius: 3px; display: block;
|
||||||
|
background-color: #ff4444; background-size: 100% 100%;
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab:hover { background: #313244; color: #cdd6f4; }
|
||||||
|
.iwb-color-pop-tab.active { background: #313244; color: #fff; border-color: #e8a735; }
|
||||||
|
.iwb-color-pop-tab.is-none i {
|
||||||
|
background-color: #45475a !important;
|
||||||
|
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab[hidden] { display: none; }
|
||||||
|
.iwb-color-pop-none {
|
||||||
|
margin-left: auto; display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
|
||||||
|
border: 1px dashed #585b70; border-radius: 7px; background: transparent; color: #a6adc8;
|
||||||
|
font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-color-pop-none span {
|
||||||
|
width: 11px; height: 11px; border-radius: 3px; display: block; background-color: #45475a;
|
||||||
|
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||||
|
}
|
||||||
|
.iwb-color-pop-none:hover { border-color: #f38ba8; color: #f38ba8; }
|
||||||
|
.iwb-color-pop-none.active { border-style: solid; border-color: #f38ba8; color: #f38ba8; background: rgba(243, 139, 168, 0.12); }
|
||||||
|
.iwb-color-pop-none[hidden] { display: none; }
|
||||||
|
.iwb-color-pop-body { display: flex; align-items: center; gap: 10px; }
|
||||||
.iwb-color-pop-picker { display: flex; gap: 8px; flex: 0 0 auto; }
|
.iwb-color-pop-picker { display: flex; gap: 8px; flex: 0 0 auto; }
|
||||||
.iwb-editor-color-pop .iwb-color-sv { width: 180px; height: 104px; flex: 0 0 180px; }
|
.iwb-editor-color-pop .iwb-color-sv { width: 180px; height: 104px; flex: 0 0 180px; }
|
||||||
.iwb-editor-color-pop .iwb-color-hue { width: 16px; height: 104px; flex: 0 0 16px; }
|
.iwb-editor-color-pop .iwb-color-hue { width: 16px; height: 104px; flex: 0 0 16px; }
|
||||||
@@ -1826,6 +1948,76 @@
|
|||||||
.iwb-editor-fx-range:disabled::-moz-range-thumb { background: #585b70; }
|
.iwb-editor-fx-range:disabled::-moz-range-thumb { background: #585b70; }
|
||||||
.iwb-editor-fx-range:focus-visible { outline: 2px solid #89b4fa; outline-offset: 2px; }
|
.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 点击)+ 合并按钮
|
v1.6:图层面板多选(⌘/Ctrl 点击)+ 合并按钮
|
||||||
多选用青色侧条与单选(橙色 #e8a735)区分:一个图层可以「被选中但不在合并集合里」,
|
多选用青色侧条与单选(橙色 #e8a735)区分:一个图层可以「被选中但不在合并集合里」,
|
||||||
@@ -1846,3 +2038,195 @@
|
|||||||
border-color: #89b4fa;
|
border-color: #89b4fa;
|
||||||
color: #cdd6f4;
|
color: #cdd6f4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================================
|
||||||
|
v1.9:文字样式控件 / 圆角 / 最近使用颜色 / 复制按钮
|
||||||
|
================================================================ */
|
||||||
|
|
||||||
|
/* 选项栏里的原生颜色框(描边色 / 底色):压成和数字框同高的小方块 */
|
||||||
|
.iwb-opt-color {
|
||||||
|
width: 22px;
|
||||||
|
height: 20px;
|
||||||
|
padding: 0;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
border: 1px solid #45475a;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-opt-color::-webkit-color-swatch-wrapper { padding: 2px; }
|
||||||
|
.iwb-opt-color::-webkit-color-swatch { border: 0; border-radius: 3px; }
|
||||||
|
/* 底色是半透明的:色块按真实不透明度显示(--sw-a),看起来和画布上的效果一致,
|
||||||
|
不再是一块实心纯黑让人以为「又多了一个字体颜色」 */
|
||||||
|
.iwb-opt-color { opacity: var(--sw-a, 1); }
|
||||||
|
/* 该颜色当前没生效(描边宽度 0 / 底色未开 / 图形是描边模式):
|
||||||
|
不再显示那块颜色本身,而是显示为一块灰色斜纹 —— 语义是「这里还没有颜色」。
|
||||||
|
只做半透明灰化的话,纯黑/深色照样是一块黑方块,用户仍会以为「设了个黑色没生效」。 */
|
||||||
|
.iwb-opt-color.is-off {
|
||||||
|
opacity: 1;
|
||||||
|
border-style: dashed;
|
||||||
|
border-color: #4b4f66;
|
||||||
|
background: repeating-linear-gradient(45deg, #353849 0 3px, #262939 3px 6px);
|
||||||
|
}
|
||||||
|
.iwb-opt-color.is-off::-webkit-color-swatch { opacity: 0; }
|
||||||
|
/* 选项栏里色块旁边的分组标签,和「描边 / 底色」这类双字按钮区分开 */
|
||||||
|
.iwb-opt-swatch-label { color: #7f849c; font-size: 11px; flex: 0 0 auto; }
|
||||||
|
|
||||||
|
/* 「最近使用」:色板弹层里 4 列 × 2 行,空的时候整块隐藏(不占位) */
|
||||||
|
.iwb-editor-color-pop .iwb-editor-recent-colors {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, 18px);
|
||||||
|
grid-auto-rows: 18px;
|
||||||
|
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;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 50%;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-editor-color-pop .iwb-editor-recent-colors .iwb-editor-color-panel-swatch:hover { transform: scale(1.12); }
|
||||||
|
|
||||||
|
/* 复制到剪贴板:与「导出」同尺寸但用低饱和色,避免两个绿色按钮抢眼 */
|
||||||
|
.iwb-editor-btn-copy { background: #313244 !important; color: #cdd6f4 !important; }
|
||||||
|
.iwb-editor-btn-copy:hover { background: #3b3d52 !important; }
|
||||||
|
|
||||||
|
/* 选项栏按钮里是中文双字标签(常规/特粗/底色),不给 nowrap 会被挤成竖排 */
|
||||||
|
.iwb-editor-optionbar-body .iwb-opt-btn { white-space: nowrap; }
|
||||||
|
|
||||||
|
/* ================================================================
|
||||||
|
v1.16:右栏常驻调色面板 + 可拖宽度 + 整体字号提升一档
|
||||||
|
需求(用户 2026-11-09):① 面板文字偏小 ② 右栏要能拖宽
|
||||||
|
③ 把调色面板(含常用色)搬进右栏 ④ 顶部切换当前元素可调的颜色项
|
||||||
|
================================================================ */
|
||||||
|
|
||||||
|
/* ---- 1) 右栏宽度手柄:贴在侧栏左边缘(侧栏在画布右侧) ----
|
||||||
|
必须放在 left:0 而不是负值:侧栏本身 overflow-x:hidden,探出去的部分会被裁掉。 */
|
||||||
|
.iwb-editor-side-resizer {
|
||||||
|
position: absolute; left: 0; top: 0; bottom: 0; width: 9px;
|
||||||
|
z-index: 46; cursor: col-resize; touch-action: none;
|
||||||
|
}
|
||||||
|
/* 平时完全隐形,悬停/拖动时才亮一条橙线:
|
||||||
|
常驻一条竖线会和「画布/面板」的分隔线打架,看起来像两条边界。 */
|
||||||
|
.iwb-editor-side-resizer::after {
|
||||||
|
content: ''; position: absolute; left: 3px; top: 0; bottom: 0; width: 2px;
|
||||||
|
border-radius: 1px; background: transparent; transition: background 0.12s ease;
|
||||||
|
}
|
||||||
|
.iwb-editor-side-resizer:hover::after,
|
||||||
|
.iwb-editor-side-resizer.is-dragging::after { background: #e8a735; }
|
||||||
|
|
||||||
|
/* ---- 2) 右栏调色面板 ---- */
|
||||||
|
.iwb-editor-colors {
|
||||||
|
display: flex; flex-direction: column; gap: 9px;
|
||||||
|
padding: 9px 10px 10px; border-radius: 10px;
|
||||||
|
background: #1e1e2c; border: 1px solid #2f2f42;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
.iwb-editor-colors-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
|
||||||
|
.iwb-editor-colors-title { font-size: 13px; font-weight: 600; color: #cdd6f4; }
|
||||||
|
.iwb-editor-colors-hint { font-size: 11.5px; color: #7f87a3; }
|
||||||
|
|
||||||
|
/* 弹层是横排一行;右栏窄,改成竖排:调色器全宽 → HEX 一行 → 常用色 → 最近。
|
||||||
|
结构完全一样(同一份 DOM),差异全在这里用容器选择器覆盖。 */
|
||||||
|
.iwb-editor-colors .iwb-color-pop-head { flex-wrap: wrap; gap: 5px; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-tab { padding: 0 8px; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-body { flex-direction: column; align-items: stretch; gap: 8px; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-sep { display: none; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-picker { width: 100%; gap: 6px; }
|
||||||
|
.iwb-editor-colors .iwb-color-sv { flex: 1 1 auto; width: auto; height: 118px; }
|
||||||
|
.iwb-editor-colors .iwb-color-hue { width: 16px; height: 118px; flex: 0 0 16px; }
|
||||||
|
.iwb-editor-colors .iwb-color-pop-fields { width: 100%; gap: 6px; }
|
||||||
|
.iwb-editor-colors .iwb-editor-color-hex-input { flex: 1 1 auto; width: auto; height: 28px; }
|
||||||
|
.iwb-editor-colors .iwb-editor-color-eye { width: 30px; height: 28px; border-radius: 6px; flex: 0 0 auto; }
|
||||||
|
|
||||||
|
/* 分组:右栏显示「常用色 / 最近」小标题,弹层里隐藏(那里横向排得下,加标题反而占高) */
|
||||||
|
.iwb-color-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 0 0 auto; }
|
||||||
|
.iwb-color-group-label { font-size: 11.5px; color: #7f87a3; letter-spacing: 0.3px; }
|
||||||
|
.iwb-editor-color-pop .iwb-color-group { gap: 0; }
|
||||||
|
.iwb-editor-color-pop .iwb-color-group-label { display: none; }
|
||||||
|
/* display:flex 会盖掉 [hidden] 的默认 display:none,必须显式写一条 */
|
||||||
|
.iwb-color-group[hidden] { display: none; }
|
||||||
|
|
||||||
|
/* 右栏色块:网格按容器宽度自适应,拖宽后一行能多放几个 */
|
||||||
|
.iwb-editor-colors .iwb-editor-color-swatches {
|
||||||
|
display: grid; grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
|
||||||
|
gap: 6px; width: 100%;
|
||||||
|
}
|
||||||
|
.iwb-editor-colors .iwb-editor-recent-colors {
|
||||||
|
display: grid; grid-template-columns: repeat(auto-fill, minmax(22px, 1fr));
|
||||||
|
gap: 6px; width: 100%;
|
||||||
|
}
|
||||||
|
.iwb-editor-colors .iwb-editor-color-panel-swatch {
|
||||||
|
width: 100%; aspect-ratio: 1 / 1; min-height: 22px; padding: 0; border: 0;
|
||||||
|
border-radius: 50%; cursor: pointer; transition: transform 0.08s ease;
|
||||||
|
}
|
||||||
|
.iwb-editor-colors .iwb-editor-color-panel-swatch:hover { transform: scale(1.1); }
|
||||||
|
.iwb-editor-colors .iwb-editor-color-panel-swatch.active { outline: 2px solid #fff; outline-offset: 2px; }
|
||||||
|
|
||||||
|
/* ---- 3) 字号 +1 档 ----
|
||||||
|
旧值大量是 10–11.5px(按 1440 宽屏定的),在 2K/4K 与系统缩放 125% 下发虚。
|
||||||
|
集中用 #iwb-editor-overlay 前缀覆盖而不是逐条改原规则:字号以后只在这块调。
|
||||||
|
宿主画布外的节点浮条(.iwb-node-floatbar 等)不在遮罩内,不受影响。 */
|
||||||
|
#iwb-editor-overlay { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-title em.iwb-editor-doc-size { font-size: 12px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-header > .iwb-editor-session .iwb-editor-btn,
|
||||||
|
#iwb-editor-overlay .iwb-editor-header .iwb-editor-export-actions .iwb-editor-btn { font-size: 12.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-export-settings-btn { font-size: 12.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-export-row > span,
|
||||||
|
#iwb-editor-overlay .iwb-editor-export-note,
|
||||||
|
#iwb-editor-overlay .iwb-editor-more-menu kbd { font-size: 12px; }
|
||||||
|
|
||||||
|
/* 选项栏 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-optionbar { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-opt-label,
|
||||||
|
#iwb-editor-overlay .iwb-opt-current,
|
||||||
|
#iwb-editor-overlay .iwb-opt-btn,
|
||||||
|
#iwb-editor-overlay .iwb-opt-num,
|
||||||
|
#iwb-editor-overlay .iwb-opt-select { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-opt-num { width: 50px; }
|
||||||
|
#iwb-editor-overlay .iwb-opt-hint,
|
||||||
|
#iwb-editor-overlay .iwb-editor-optionbar-tip,
|
||||||
|
#iwb-editor-overlay .iwb-opt-unit,
|
||||||
|
#iwb-editor-overlay .iwb-opt-swatch-label { font-size: 12px; }
|
||||||
|
|
||||||
|
/* 状态栏 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-statusbar { font-size: 12px; height: 28px; min-height: 28px; }
|
||||||
|
|
||||||
|
/* 图层面板 */
|
||||||
|
#iwb-editor-overlay .iwb-layer-name { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-layer-name-input { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-layer-paint { font-size: 12px; }
|
||||||
|
#iwb-editor-overlay .iwb-layer-op,
|
||||||
|
#iwb-editor-overlay .iwb-layer-op-val { font-size: 11.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-layer-op-val { width: 36px; }
|
||||||
|
|
||||||
|
/* 右栏:图片调节 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-title { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-target { font-size: 11.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-reset { font: 500 12px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; padding: 3px 8px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-row { grid-template-columns: 50px 1fr 40px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-name { font-size: 12.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-val { width: 40px; font: 500 12px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-adj-tip { font-size: 11.5px; }
|
||||||
|
|
||||||
|
/* 右栏:快速效果 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-title { font-size: 13px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-target { font-size: 11.5px; max-width: 150px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-btn { font: 500 12px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; padding: 8px 2px 7px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-tip { font-size: 11.5px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-adj-name,
|
||||||
|
#iwb-editor-overlay .iwb-editor-fx-adj-val { font-size: 12px; }
|
||||||
|
|
||||||
|
/* 右栏:缩放 */
|
||||||
|
#iwb-editor-overlay .iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-val,
|
||||||
|
#iwb-editor-overlay .iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-fit { font-size: 12px; }
|
||||||
|
|
||||||
|
/* 调色面板本体 */
|
||||||
|
#iwb-editor-overlay .iwb-color-pop-tab,
|
||||||
|
#iwb-editor-overlay .iwb-color-pop-none { font-size: 12.5px; height: 26px; }
|
||||||
|
#iwb-editor-overlay .iwb-editor-color-pop .iwb-editor-color-hex-input { font-size: 13px; }
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import { S, runtime } from './state.js'
|
import { S, runtime } from './state.js'
|
||||||
import { resizeWorkspace } from './viewport.js'
|
import { resizeWorkspace } from './viewport.js'
|
||||||
|
import { resetOverlayTransform, viewScale } from './scale.js'
|
||||||
import { disposeSelection } from './selection.js'
|
import { disposeSelection } from './selection.js'
|
||||||
import { saveSnapshot } from './history.js'
|
import { saveSnapshot } from './history.js'
|
||||||
import { toast } from './commands.js'
|
import { toast } from './commands.js'
|
||||||
@@ -82,12 +83,13 @@ import { toast } from './commands.js'
|
|||||||
|
|
||||||
export function clearOverlay() {
|
export function clearOverlay() {
|
||||||
const ctx = S.overlayCtx
|
const ctx = S.overlayCtx
|
||||||
const pad = S.overlayPad || 0
|
if (!ctx) return
|
||||||
ctx.save()
|
// 缓冲已按 overlayScale 放大,必须按设备像素整幅清,再恢复图片坐标基准
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
ctx.save()
|
||||||
ctx.clearRect(0, 0, S.imgW + pad * 2, S.imgH + pad * 2)
|
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||||
ctx.restore()
|
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
|
||||||
ctx.setTransform(1, 0, 0, 1, pad, pad)
|
ctx.restore()
|
||||||
|
resetOverlayTransform(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function drawCropPreview(x1, y1, x2, y2) {
|
export function drawCropPreview(x1, y1, x2, y2) {
|
||||||
@@ -112,8 +114,8 @@ import { toast } from './commands.js'
|
|||||||
ctx.restore()
|
ctx.restore()
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.strokeStyle = '#4488ff'
|
ctx.strokeStyle = '#4488ff'
|
||||||
ctx.lineWidth = 2 / S.zoom
|
ctx.lineWidth = 2 / viewScale()
|
||||||
ctx.setLineDash([8 / S.zoom, 4 / S.zoom])
|
ctx.setLineDash([8 / viewScale(), 4 / viewScale()])
|
||||||
ctx.strokeRect(rx, ry, rw, rh)
|
ctx.strokeRect(rx, ry, rw, rh)
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
if (S.cropRect && !S.cropHandle) drawCropHandles(rx, ry, rw, rh)
|
if (S.cropRect && !S.cropHandle) drawCropHandles(rx, ry, rw, rh)
|
||||||
@@ -131,11 +133,11 @@ import { toast } from './commands.js'
|
|||||||
function drawCropHandles(rx, ry, rw, rh) {
|
function drawCropHandles(rx, ry, rw, rh) {
|
||||||
const ctx = S.overlayCtx
|
const ctx = S.overlayCtx
|
||||||
const pts = cropHandlePoints(rx, ry, rw, rh)
|
const pts = cropHandlePoints(rx, ry, rw, rh)
|
||||||
const hs = 4 / S.zoom
|
const hs = 4 / viewScale()
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.fillStyle = '#ffffff'
|
ctx.fillStyle = '#ffffff'
|
||||||
ctx.strokeStyle = '#4488ff'
|
ctx.strokeStyle = '#4488ff'
|
||||||
ctx.lineWidth = 1.5 / S.zoom
|
ctx.lineWidth = 1.5 / viewScale()
|
||||||
for (const name in pts) {
|
for (const name in pts) {
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.rect(pts[name][0] - hs, pts[name][1] - hs, hs * 2, hs * 2)
|
ctx.rect(pts[name][0] - hs, pts[name][1] - hs, hs * 2, hs * 2)
|
||||||
@@ -153,7 +155,7 @@ import { toast } from './commands.js'
|
|||||||
export function hitCropHandle(pos) {
|
export function hitCropHandle(pos) {
|
||||||
if (!S.cropRect) return null
|
if (!S.cropRect) return null
|
||||||
const pts = cropHandlePoints(S.cropRect.x, S.cropRect.y, S.cropRect.w, S.cropRect.h)
|
const pts = cropHandlePoints(S.cropRect.x, S.cropRect.y, S.cropRect.w, S.cropRect.h)
|
||||||
const R = 12 / S.zoom
|
const R = 12 / viewScale()
|
||||||
let best = null, bestDist = 1e9
|
let best = null, bestDist = 1e9
|
||||||
for (const name in pts) {
|
for (const name in pts) {
|
||||||
const dx = pos.x - pts[name][0], dy = pos.y - pts[name][1]
|
const dx = pos.x - pts[name][0], dy = pos.y - pts[name][1]
|
||||||
|
|||||||
@@ -10,6 +10,55 @@ import { S, runtime } from './state.js'
|
|||||||
import { bindEvents } from './events.js'
|
import { bindEvents } from './events.js'
|
||||||
|
|
||||||
|
|
||||||
|
// ============ 调色面板(两处共用) ============
|
||||||
|
/**
|
||||||
|
* v1.16:调色面板从「只能弹层」变成「右栏常驻 + 弹层保留」,两处用同一份 DOM。
|
||||||
|
*
|
||||||
|
* 为什么抽成函数而不是复制两段 HTML:这套控件有 4 组联动(tab 高亮、SV/色相指示点、
|
||||||
|
* HEX 回填、常用色/最近色的 active 圈),复制两段 = 以后每加一种颜色语义都要改两遍,
|
||||||
|
* 漏一处就是「一边改了另一边不变」。同一份结构 + 按 `[data-color-surface]` 遍历,
|
||||||
|
* 才可能保证一致(events.js#updateColorUI 就是按 surface 逐个刷的)。
|
||||||
|
*
|
||||||
|
* 布局差异全部交给 CSS:弹层是横排一行,右栏窄,改成竖排(picker 全宽、色块自动换行)。
|
||||||
|
*/
|
||||||
|
const COMMON_COLORS = [
|
||||||
|
'#ff4444', '#ff8a00', '#ffd400', '#4cd964', '#00bfa5', '#4488ff',
|
||||||
|
'#aa44ff', '#ff66aa', '#ffffff', '#d0d0d0', '#808080', '#000000'
|
||||||
|
]
|
||||||
|
|
||||||
|
function colorSurfaceHtml() {
|
||||||
|
return `
|
||||||
|
<div class="iwb-color-pop-head">
|
||||||
|
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
|
||||||
|
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色 / 文字描边色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
|
||||||
|
<button type="button" class="iwb-color-pop-tab" data-color-slot="bg" hidden title="正在调文本框底色(垫在文字下面)"><i></i><span class="iwb-color-pop-tab-label">底色</span></button>
|
||||||
|
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="无填充:形状内部透明,只留描边"><span></span>无</button>
|
||||||
|
</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>
|
||||||
|
<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>`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ============ DOM 创建 ============
|
// ============ DOM 创建 ============
|
||||||
export function createEl() {
|
export function createEl() {
|
||||||
if (runtime.el) return
|
if (runtime.el) return
|
||||||
@@ -31,21 +80,10 @@ import { bindEvents } from './events.js'
|
|||||||
<button class="iwb-editor-action" data-action="redo" title="重做 (Ctrl+Shift+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>
|
<button class="iwb-editor-action" data-action="redo" title="重做 (Ctrl+Shift+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>
|
||||||
<button class="iwb-editor-action iwb-editor-action-reset" data-action="reset" title="还原原图:删掉所有标注/图层,回到打开时的样子(Ctrl+Z 可撤销)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/></svg></button>
|
<button class="iwb-editor-action iwb-editor-action-reset" data-action="reset" title="还原原图:删掉所有标注/图层,回到打开时的样子(Ctrl+Z 可撤销)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/></svg></button>
|
||||||
</div>
|
</div>
|
||||||
<span class="iwb-editor-divider"></span>
|
<!-- 顶栏命令带已清空(v1.13):
|
||||||
<!-- 顶栏命令带(v1.2.6):撤销/重做/还原 | 顺序 | 视图;图层新建/导入回图层面板标题栏 -->
|
四个「置顶/上移/下移/置底」按钮删除(图层面板可拖动 + Ctrl+]/[ 已覆盖);
|
||||||
<div class="iwb-editor-commands">
|
「适应窗口 / 收起侧栏」搬到画布底部工具栏最右侧,离画布更近。
|
||||||
<div class="iwb-editor-cmdgroup" data-group="order" title="调整选中元素的图层顺序">
|
整个 .iwb-editor-commands 容器一并移除,不留一条空分隔线。 -->
|
||||||
<button class="iwb-editor-layer-btn" data-layer="top" title="置顶:选中元素移到最上层 (Ctrl+Shift+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="5" x2="20" y2="5"/><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="up" title="上移一层 (Ctrl+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="down" title="下移一层 (Ctrl+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/></svg></button>
|
|
||||||
<button class="iwb-editor-layer-btn" data-layer="bottom" title="置底:选中元素移到最下层 (Ctrl+Shift+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/><line x1="4" y1="19" x2="20" y2="19"/></svg></button>
|
|
||||||
</div>
|
|
||||||
<span class="iwb-editor-divider"></span>
|
|
||||||
<div class="iwb-editor-cmdgroup" data-group="view">
|
|
||||||
<button class="iwb-editor-action" data-action="zoomFit" title="适应窗口 (Ctrl+0)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 3 3 3 3 9"/><polyline points="15 3 21 3 21 9"/><polyline points="3 15 3 21 9 21"/><polyline points="21 15 21 21 15 21"/></svg></button>
|
|
||||||
<button class="iwb-editor-action" data-action="togglePanels" title="收起 / 展开侧栏 (Tab)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="9" y1="4" x2="9" y2="20"/></svg></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="iwb-editor-export-actions">
|
<div class="iwb-editor-export-actions">
|
||||||
<div class="iwb-editor-export-settings-wrap">
|
<div class="iwb-editor-export-settings-wrap">
|
||||||
@@ -79,13 +117,14 @@ import { bindEvents } from './events.js'
|
|||||||
<div class="iwb-editor-export-note">一次只输出一个结果;设置会记住</div>
|
<div class="iwb-editor-export-note">一次只输出一个结果;设置会记住</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<button class="iwb-editor-btn iwb-editor-btn-copy" data-action="copyClipboard" title="复制当前结果到系统剪贴板(可直接粘到聊天窗口/后台),不关闭编辑器">复制</button>
|
||||||
<button class="iwb-editor-btn iwb-editor-btn-download" data-action="download" title="导出当前这一张(不关闭编辑器)">导出</button>
|
<button class="iwb-editor-btn iwb-editor-btn-download" data-action="download" title="导出当前这一张(不关闭编辑器)">导出</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-optionbar">
|
<div class="iwb-editor-optionbar">
|
||||||
<span class="iwb-editor-optionbar-label">工具选项</span>
|
<span class="iwb-editor-optionbar-label">工具选项</span>
|
||||||
<div class="iwb-editor-optionbar-body"></div>
|
<div class="iwb-editor-optionbar-body"></div>
|
||||||
<span class="iwb-editor-optionbar-tip">选区也可右键;Ctrl+J 复制 · Delete 清除 · Ctrl+D 取消</span>
|
<span class="iwb-editor-optionbar-tip" title="选中后还可右键;Ctrl+J 复制 · Delete 清除 · Ctrl+D 取消选区">Ctrl+J 复制 · Delete 清除</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-main">
|
<div class="iwb-editor-main">
|
||||||
|
|
||||||
@@ -114,7 +153,8 @@ import { bindEvents } from './events.js'
|
|||||||
<canvas class="iwb-editor-selection-overlay"></canvas>
|
<canvas class="iwb-editor-selection-overlay"></canvas>
|
||||||
<canvas class="iwb-editor-cursor-overlay"></canvas>
|
<canvas class="iwb-editor-cursor-overlay"></canvas>
|
||||||
</div>
|
</div>
|
||||||
<input class="iwb-editor-text-input" type="text" placeholder="输入文字,Enter确认,Esc取消">
|
<!-- v1.9:input → textarea,支持 Shift+Enter 换行(Enter 仍是确认) -->
|
||||||
|
<textarea class="iwb-editor-text-input" rows="1" wrap="off" placeholder="输入文字,Enter 确认,Shift+Enter 换行" spellcheck="false"></textarea>
|
||||||
<div class="iwb-editor-picker-tip"><span class="iwb-editor-picker-chip"></span><span class="iwb-editor-picker-hex">#ffffff</span></div>
|
<div class="iwb-editor-picker-tip"><span class="iwb-editor-picker-chip"></span><span class="iwb-editor-picker-hex">#ffffff</span></div>
|
||||||
<!-- 裁剪参数已迁入选项栏(v1.2.2),画布下方浮窗删除 -->
|
<!-- 裁剪参数已迁入选项栏(v1.2.2),画布下方浮窗删除 -->
|
||||||
<div class="iwb-editor-sel-bar">
|
<div class="iwb-editor-sel-bar">
|
||||||
@@ -128,14 +168,23 @@ import { bindEvents } from './events.js'
|
|||||||
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-tools">
|
<div class="iwb-editor-tools">
|
||||||
<!-- 当前色圆点(v1.3):点开就是完整色板,侧栏不再放调色板 -->
|
<!-- 颜色(v1.11 两格 → v1.12 文字三格):
|
||||||
<button type="button" class="iwb-editor-color-btn" data-action="toggleColorPop" aria-expanded="false" title="颜色:点开色板(调色器 / 吸管 / 推荐色)"><i></i></button>
|
形状下是「描边 + 填充」两格叠放在一个按钮位里(PS 式前/背景色);
|
||||||
|
文字下是「文字 / 描边 / 底色」三格横排 —— 文字对象天生就有三个颜色,
|
||||||
|
只给两格必然有一格无处安放(用户反馈「文本不支持描边与字体色切换」)。
|
||||||
|
点哪格就调哪格:色板只有一套,写谁由 S.colorTarget 决定。
|
||||||
|
关掉的那格画斜杠,跟随描边色的填充块带一个小三角角标。 -->
|
||||||
|
<div class="iwb-editor-color-pair" data-color-mode="single">
|
||||||
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="stroke" data-action="toggleColorPop" aria-expanded="false" title="描边色:形状描边 / 画笔 / 文字都用它。点开色板调色"><i></i></button>
|
||||||
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="fill" data-action="toggleColorPop" aria-expanded="false" title="填充色:形状内部颜色。点开色板调色,色板里可切换「无填充」"><i></i></button>
|
||||||
|
<button type="button" class="iwb-editor-color-btn" data-color-slot="bg" data-action="toggleColorPop" aria-expanded="false" title="文本框底色:垫在文字下面的一块半透明色板。点开调色,可选「无」"><i></i></button>
|
||||||
|
</div>
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
<button class="iwb-editor-tool" data-tool="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg></button>
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
|
|
||||||
<button class="iwb-editor-tool" data-tool="marquee" title="选框 (M):拖出矩形/椭圆选区,松手后旁边出现操作条;Shift+M 切换矩形/椭圆"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4 3"><rect x="3" y="4" width="18" height="16" rx="1"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="marquee" title="选框 (M):拖出矩形/椭圆选区,松手后旁边出现操作条;Shift+M 切换矩形/椭圆"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4 3"><rect x="3" y="4" width="18" height="16" rx="1"/></svg></button>
|
||||||
<button class="iwb-editor-tool" data-tool="lasso" title="套索 (L):按住拖动自由圈选,松手闭合"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12c0-4 3.6-7 8-7s8 3 8 7-3.6 7-8 7c-2 0-3.8-.6-5.2-1.6"/><path d="M6.8 17.4 4 20l1.2-3.2"/><circle cx="20" cy="19" r="2"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="lasso" title="套索 (A):按住拖动自由圈选,松手闭合"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12c0-4 3.6-7 8-7s8 3 8 7-3.6 7-8 7c-2 0-3.8-.6-5.2-1.6"/><path d="M6.8 17.4 4 20l1.2-3.2"/><circle cx="20" cy="19" r="2"/></svg></button>
|
||||||
|
|
||||||
<button class="iwb-editor-tool active" data-tool="brush" title="画笔 (B):] 增大 / [ 减小笔刷;按住 Alt 临时吸色"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg></button>
|
<button class="iwb-editor-tool active" data-tool="brush" title="画笔 (B):] 增大 / [ 减小笔刷;按住 Alt 临时吸色"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg></button>
|
||||||
|
|
||||||
@@ -145,11 +194,11 @@ import { bindEvents } from './events.js'
|
|||||||
|
|
||||||
<button class="iwb-editor-tool" data-tool="text" title="文字 (T)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 3 20 3 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="3" x2="12" y2="20"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="text" title="文字 (T)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 3 20 3 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="3" x2="12" y2="20"/></svg></button>
|
||||||
|
|
||||||
<button class="iwb-editor-tool" data-tool="rect" title="矩形 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="rect" title="矩形 (R):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg></button>
|
||||||
|
|
||||||
<button class="iwb-editor-tool" data-tool="circle" title="圆形 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="circle" title="圆形 (O):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8"/></svg></button>
|
||||||
|
|
||||||
<button class="iwb-editor-tool" data-tool="arrow" title="箭头 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="arrow" title="箭头 (L):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
|
||||||
|
|
||||||
<button class="iwb-editor-tool" data-tool="picker" title="吸管 (I):点击画布取色(悬停预览);选中形状/文字时取色直接改它的颜色,取完切回上一工具"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="picker" title="吸管 (I):点击画布取色(悬停预览);选中形状/文字时取色直接改它的颜色,取完切回上一工具"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
|
||||||
|
|
||||||
@@ -159,14 +208,45 @@ import { bindEvents } from './events.js'
|
|||||||
|
|
||||||
<button class="iwb-editor-tool" data-tool="crop" title="裁剪 (C):参数在选项栏;Enter 确认 / Esc 取消"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="crop" title="裁剪 (C):参数在选项栏;Enter 确认 / Esc 取消"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
|
||||||
|
|
||||||
|
<!-- 视图快捷(v1.13):从顶栏搬过来,贴在工具条最右侧的「|」之后。
|
||||||
|
工具条本身是 shrink-to-fit 且居中,所以这一组天然就是「最右边」。 -->
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
|
<button class="iwb-editor-tool iwb-editor-view-btn" data-action="zoomFit" title="适应窗口 (Ctrl+0):整张图缩放到刚好放得下"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 3 3 3 3 9"/><polyline points="15 3 21 3 21 9"/><polyline points="3 15 3 21 9 21"/><polyline points="21 15 21 21 15 21"/></svg></button>
|
||||||
|
<button class="iwb-editor-tool iwb-editor-view-btn" data-action="togglePanels" title="收起 / 展开侧栏 (Tab)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="9" y1="4" x2="9" y2="20"/></svg></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
||||||
|
|
||||||
<aside class="iwb-editor-left">
|
<aside class="iwb-editor-left">
|
||||||
|
<!-- v1.16:侧栏宽度拖拽手柄。贴在侧栏左边缘(它在画布右侧),
|
||||||
|
双击复位。宽度写进 CSS 变量 --iwb-side-w,由 --iwb-side-w 统一裁各条 width 规则。 -->
|
||||||
|
<div class="iwb-editor-side-resizer" data-side-resizer="1" title="拖动调整侧栏宽度,双击复位"></div>
|
||||||
|
<!-- 调色面板(v1.16):从弹层搬进来常驻一份,弹层保留。
|
||||||
|
两处是同一份 DOM(dom.js#colorSurfaceHtml),靠 data-color-surface 区分与遍历,
|
||||||
|
不存在「一边改了另一边不变」。顶部色格 = 当前元素可调的颜色项,
|
||||||
|
跟随选中对象变化:形状=描边/填充,文字=文字/描边/底色,箭头=只要描边。 -->
|
||||||
|
<section class="iwb-editor-colors" data-color-surface="side">
|
||||||
|
<div class="iwb-editor-colors-head">
|
||||||
|
<span class="iwb-editor-colors-title">颜色</span>
|
||||||
|
<span class="iwb-editor-colors-hint" title="点上面的色格选择要调哪个颜色">点色格切换</span>
|
||||||
|
</div>
|
||||||
|
${colorSurfaceHtml()}
|
||||||
|
</section>
|
||||||
<!-- 调色板已迁到工具栏弹层(v1.3,用户裁定 2026-11-05):
|
<!-- 调色板已迁到工具栏弹层(v1.3,用户裁定 2026-11-05):
|
||||||
侧栏只留快速效果 + 缩放;色板 DOM 在 modal 末尾的 .iwb-editor-color-pop -->
|
侧栏只留快速效果 + 缩放;色板 DOM 在 modal 末尾的 .iwb-editor-color-pop -->
|
||||||
|
<!-- 图片调节(v1.15):连续调色,作用于当前位图图层(默认原图)。
|
||||||
|
行由 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 撤销。
|
<!-- 快速效果(v1.4):作用于当前位图图层,点一下就应用,Ctrl+Z 撤销。
|
||||||
目标层名由 effects.js 的 updateFxTargetLabel() 实时刷新。 -->
|
目标层名由 effects.js 的 updateFxTargetLabel() 实时刷新。 -->
|
||||||
<section class="iwb-editor-fx">
|
<section class="iwb-editor-fx">
|
||||||
@@ -225,34 +305,12 @@ import { bindEvents } from './events.js'
|
|||||||
<span class="iwb-editor-status-layer">当前层:原图</span>
|
<span class="iwb-editor-status-layer">当前层:原图</span>
|
||||||
<span class="iwb-editor-status-tool">画笔</span>
|
<span class="iwb-editor-status-tool">画笔</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- 色板弹层(v1.3):工具栏色点点击展开。
|
<!-- 色板弹层(v1.3;v1.16 起与右栏常驻面板共用同一份 DOM):
|
||||||
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
工具栏色块点击展开。必须挂在 modal 下、不能塞进 .iwb-editor-tools ——
|
||||||
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
工具栏是 overflow-x:auto,canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;
|
||||||
<div class="iwb-editor-color-pop" hidden>
|
定位由 events.js 计算。 -->
|
||||||
<div class="iwb-color-pop-picker">
|
<div class="iwb-editor-color-pop" data-color-surface="pop" hidden>
|
||||||
<div class="iwb-color-sv"><span></span></div>
|
${colorSurfaceHtml()}
|
||||||
<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>
|
|
||||||
<div class="iwb-editor-color-swatches">
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff4444" style="background:#ff4444" title="#ff4444"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff8a00" style="background:#ff8a00" title="#ff8a00"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffd400" style="background:#ffd400" title="#ffd400"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#4cd964" style="background:#4cd964" title="#4cd964"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#00bfa5" style="background:#00bfa5" title="#00bfa5"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#4488ff" style="background:#4488ff" title="#4488ff"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#aa44ff" style="background:#aa44ff" title="#aa44ff"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff66aa" style="background:#ff66aa" title="#ff66aa"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffffff" style="background:#ffffff" title="#ffffff"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#d0d0d0" style="background:#d0d0d0" title="#d0d0d0"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#808080" style="background:#808080" title="#808080"></button>
|
|
||||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#000000" style="background:#000000" title="#000000"></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+6
-3
@@ -54,12 +54,15 @@ import { toast } from './commands.js'
|
|||||||
render: (canvas, v) => { if (v > 0) filterCanvas(canvas, 'grayscale(' + (v / 100) + ')') }
|
render: (canvas, v) => { if (v > 0) filterCanvas(canvas, 'grayscale(' + (v / 100) + ')') }
|
||||||
},
|
},
|
||||||
boost: {
|
boost: {
|
||||||
label: '增强', hint: '提亮并略加对比,适合发灰的截图',
|
label: '增强', hint: '提亮并加对比,适合发灰的截图',
|
||||||
param: '强度', unit: '%', min: 0, max: 100, step: 1, def: () => 100,
|
param: '强度', unit: '%', min: 0, max: 100, step: 1, def: () => 100,
|
||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v <= 0) return
|
if (v <= 0) return
|
||||||
const k = v / 100
|
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: {
|
contrast: {
|
||||||
@@ -68,7 +71,7 @@ import { toast } from './commands.js'
|
|||||||
render: (canvas, v) => {
|
render: (canvas, v) => {
|
||||||
if (v <= 0) return
|
if (v <= 0) return
|
||||||
const k = v / 100
|
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: {
|
soft: {
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -294,3 +294,64 @@ import { toast } from './commands.js'
|
|||||||
setTimeout(() => { try { URL.revokeObjectURL(url) } catch (e) { /* ignore */ } }, 2000)
|
setTimeout(() => { try { URL.revokeObjectURL(url) } catch (e) { /* ignore */ } }, 2000)
|
||||||
toast('已下载 ' + name + '(' + Math.round(blob.size / 1024) + 'KB)', 'success')
|
toast('已下载 ' + name + '(' + Math.round(blob.size / 1024) + 'KB)', 'success')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 任意图片 blob → PNG blob(剪贴板对 image/png 支持最稳,体积在剪贴板里无所谓) */
|
||||||
|
async function toPngBlob(blob) {
|
||||||
|
// 优先 createImageBitmap:不经过 URL,绕开宿主 CSP 对 img-src 的限制
|
||||||
|
try {
|
||||||
|
if (typeof createImageBitmap === 'function') {
|
||||||
|
const bmp = await createImageBitmap(blob)
|
||||||
|
const c = document.createElement('canvas')
|
||||||
|
c.width = bmp.width
|
||||||
|
c.height = bmp.height
|
||||||
|
c.getContext('2d').drawImage(bmp, 0, 0)
|
||||||
|
if (typeof bmp.close === 'function') bmp.close()
|
||||||
|
const out = await new Promise(res => c.toBlob(b => res(b), 'image/png'))
|
||||||
|
c.width = 0
|
||||||
|
c.height = 0
|
||||||
|
if (out) return out
|
||||||
|
}
|
||||||
|
} catch (e) { /* 走 img 回退 */ }
|
||||||
|
return await new Promise((resolve) => {
|
||||||
|
const url = URL.createObjectURL(blob)
|
||||||
|
const img = new Image()
|
||||||
|
img.onload = () => {
|
||||||
|
const c = document.createElement('canvas')
|
||||||
|
c.width = img.naturalWidth
|
||||||
|
c.height = img.naturalHeight
|
||||||
|
c.getContext('2d').drawImage(img, 0, 0)
|
||||||
|
try { URL.revokeObjectURL(url) } catch (e) { /* ignore */ }
|
||||||
|
c.toBlob(b => resolve(b || blob), 'image/png')
|
||||||
|
}
|
||||||
|
img.onerror = () => {
|
||||||
|
try { URL.revokeObjectURL(url) } catch (e) { /* ignore */ }
|
||||||
|
resolve(blob)
|
||||||
|
}
|
||||||
|
img.src = url
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制到系统剪贴板:运营场景最常用的一条路 —— 复制后直接粘进聊天窗口/小红书后台,
|
||||||
|
* 省掉「下载 → 再上传」。必须在用户手势里调用(浏览器要求),失败给可操作提示。
|
||||||
|
*/
|
||||||
|
export async function copyBlobToClipboard(blob) {
|
||||||
|
const nav = typeof navigator !== 'undefined' ? navigator : null
|
||||||
|
const CI = typeof window !== 'undefined' ? window.ClipboardItem : null
|
||||||
|
if (!nav || !nav.clipboard || typeof nav.clipboard.write !== 'function' || typeof CI !== 'function') {
|
||||||
|
toast('当前浏览器不支持复制图片,请用「导出」下载', 'warn')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let png = blob
|
||||||
|
if (blob.type !== 'image/png') {
|
||||||
|
try { png = await toPngBlob(blob) } catch (e) { png = blob }
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await nav.clipboard.write([new CI({ 'image/png': png })])
|
||||||
|
toast('已复制到剪贴板(' + Math.round(png.size / 1024) + 'KB),可直接粘贴', 'success')
|
||||||
|
return true
|
||||||
|
} catch (e) {
|
||||||
|
toast('复制失败:' + ((e && e.message) || '浏览器拒绝了剪贴板写入') + ';可用「导出」下载', 'error')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -266,6 +266,7 @@ import { toast } from './commands.js'
|
|||||||
if (S.history.length === 0) { toast('没有可撤销的操作'); return }
|
if (S.history.length === 0) { toast('没有可撤销的操作'); return }
|
||||||
pushHistory(S.redoStack, snapshotState())
|
pushHistory(S.redoStack, snapshotState())
|
||||||
restoreState(S.history.pop())
|
restoreState(S.history.pop())
|
||||||
|
if (S.onHistoryRestore) S.onHistoryRestore()
|
||||||
if (S.renderAll) S.renderAll()
|
if (S.renderAll) S.renderAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +276,7 @@ import { toast } from './commands.js'
|
|||||||
if (S.redoStack.length === 0) { toast('没有可重做的操作'); return }
|
if (S.redoStack.length === 0) { toast('没有可重做的操作'); return }
|
||||||
pushHistory(S.history, snapshotState())
|
pushHistory(S.history, snapshotState())
|
||||||
restoreState(S.redoStack.pop())
|
restoreState(S.redoStack.pop())
|
||||||
|
if (S.onHistoryRestore) S.onHistoryRestore()
|
||||||
if (S.renderAll) S.renderAll()
|
if (S.renderAll) S.renderAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,13 +30,16 @@ import { HISTORY_MAX_BYTES, HISTORY_MAX_ENTRIES, historyBudgetBytes, snapshotSta
|
|||||||
import { cancelImagePlacement } from './placement.js'
|
import { cancelImagePlacement } from './placement.js'
|
||||||
import { clearSelection, purgeVectorCanvases, renderLayerPanel } from './layers.js'
|
import { clearSelection, purgeVectorCanvases, renderLayerPanel } from './layers.js'
|
||||||
import { createEl, loadImage } from './dom.js'
|
import { createEl, loadImage } from './dom.js'
|
||||||
import { renderObjects, hideTextInput } from './objects.js'
|
import { renderObjects, hideTextInput, textBounds } from './objects.js'
|
||||||
import { setupCanvas } from './viewport.js'
|
import { setupCanvas } from './viewport.js'
|
||||||
import { updateAllUI, bindLiteUI, renderOptionBar, updateStatusbar } from './events.js'
|
import { resetOverlayTransform } from './scale.js'
|
||||||
|
import { updateAllUI, bindLiteUI, renderOptionBar, updateStatusbar, loadSideWidth } from './events.js'
|
||||||
import { disposeSelection, renderSelection, selectionInfo, syncAnts, registerSelectionCommands } from './selection.js'
|
import { disposeSelection, renderSelection, selectionInfo, syncAnts, registerSelectionCommands } from './selection.js'
|
||||||
import { bindFloating, positionFloating, hideSelectionContext } from './floating.js'
|
import { bindFloating, positionFloating, hideSelectionContext } from './floating.js'
|
||||||
import { renderFxPanel } from './effects.js'
|
import { renderFxPanel } from './effects.js'
|
||||||
import { loadExportOptions, prepareOutput, downloadBlob, bindExportUI, renderExportUI } from './export.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'
|
import { toast } from './commands.js'
|
||||||
|
|
||||||
// ============ 打开编辑器 ============
|
// ============ 打开编辑器 ============
|
||||||
@@ -48,6 +51,9 @@ import { toast } from './commands.js'
|
|||||||
S.renderAll = renderAll
|
S.renderAll = renderAll
|
||||||
S.positionFloating = positionFloating
|
S.positionFloating = positionFloating
|
||||||
S.renderFxPanel = renderFxPanel
|
S.renderFxPanel = renderFxPanel
|
||||||
|
S.renderAdjustPanel = renderAdjustPanel
|
||||||
|
// 撤销/重做后调节参数必须归零(详见 adjust.js#onHistoryRestore 的注释)
|
||||||
|
S.onHistoryRestore = onAdjustHistoryRestore
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const img = await loadImage(options.imageBase64)
|
const img = await loadImage(options.imageBase64)
|
||||||
@@ -62,10 +68,14 @@ import { toast } from './commands.js'
|
|||||||
updateAllUI()
|
updateAllUI()
|
||||||
registerSelectionCommands()
|
registerSelectionCommands()
|
||||||
loadExportOptions()
|
loadExportOptions()
|
||||||
|
loadRecentColors()
|
||||||
bindLiteUI()
|
bindLiteUI()
|
||||||
bindFloating()
|
bindFloating()
|
||||||
bindExportUI()
|
bindExportUI()
|
||||||
initPanels()
|
initPanels()
|
||||||
|
// 右栏宽度跟着用户上次拖的位置(v1.16);必须在 initPanels 之后——
|
||||||
|
// 侧栏收起时元素虽 display:none,写 CSS 变量仍然有效,下次展开直接生效
|
||||||
|
loadSideWidth()
|
||||||
renderAll()
|
renderAll()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[IWB编辑器] 打开失败:', e)
|
console.error('[IWB编辑器] 打开失败:', e)
|
||||||
@@ -123,6 +133,9 @@ import { toast } from './commands.js'
|
|||||||
S.altPicker = false
|
S.altPicker = false
|
||||||
// 快速效果的基准像素属于上一张图,重开必须清掉(否则滑杆会往新图上写旧像素)
|
// 快速效果的基准像素属于上一张图,重开必须清掉(否则滑杆会往新图上写旧像素)
|
||||||
S.fx = { key: null, value: 0, layerId: null, source: null }
|
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.zCounter = Math.max(S.layers.length - 1, 0)
|
||||||
S.placingImage = null
|
S.placingImage = null
|
||||||
S.placingHandle = null
|
S.placingHandle = null
|
||||||
@@ -139,10 +152,9 @@ import { toast } from './commands.js'
|
|||||||
hideSelectionContext()
|
hideSelectionContext()
|
||||||
if (S.selectionCtx) renderSelection()
|
if (S.selectionCtx) renderSelection()
|
||||||
if (S.cursorCtx) {
|
if (S.cursorCtx) {
|
||||||
const pad = S.overlayPad || 0
|
|
||||||
S.cursorCtx.setTransform(1, 0, 0, 1, 0, 0)
|
S.cursorCtx.setTransform(1, 0, 0, 1, 0, 0)
|
||||||
S.cursorCtx.clearRect(0, 0, S.imgW + pad * 2, S.imgH + pad * 2)
|
S.cursorCtx.clearRect(0, 0, S.cursorCtx.canvas.width, S.cursorCtx.canvas.height)
|
||||||
S.cursorCtx.setTransform(1, 0, 0, 1, pad, pad)
|
resetOverlayTransform(S.cursorCtx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +164,8 @@ import { toast } from './commands.js'
|
|||||||
renderObjects()
|
renderObjects()
|
||||||
renderLayerPanel()
|
renderLayerPanel()
|
||||||
renderFxPanel()
|
renderFxPanel()
|
||||||
|
// 调节面板跟着图层走:新建/切换/删除图层都要刷新 target 与滑块值
|
||||||
|
renderAdjustPanel()
|
||||||
renderOptionBar()
|
renderOptionBar()
|
||||||
updateStatusbar()
|
updateStatusbar()
|
||||||
renderExportUI()
|
renderExportUI()
|
||||||
@@ -216,6 +230,9 @@ import { toast } from './commands.js'
|
|||||||
S.pickerComposite = null
|
S.pickerComposite = null
|
||||||
// 2b) 快速效果的基准像素:又一张全幅位图,不释放就白占一份图大小的内存
|
// 2b) 快速效果的基准像素:又一张全幅位图,不释放就白占一份图大小的内存
|
||||||
S.fx = { key: null, value: 0, layerId: null, source: null }
|
S.fx = { key: null, value: 0, layerId: null, source: null }
|
||||||
|
// 2c) 图片调节的基准像素与预览副本(两张全幅位图)+ 按 layer.id 的缓存 Map。
|
||||||
|
// 缓存必须清,否则下次打开新图时 'base' 会命中这份旧像素(v1.15.1)
|
||||||
|
resetAdjustCache()
|
||||||
// 3) 交互态复位:关闭后 window mouseup 等全局监听仍活着,靠标志位保证不落到绘制路径
|
// 3) 交互态复位:关闭后 window mouseup 等全局监听仍活着,靠标志位保证不落到绘制路径
|
||||||
S.isDrawing = false
|
S.isDrawing = false
|
||||||
S.panning = false
|
S.panning = false
|
||||||
@@ -274,6 +291,19 @@ import { toast } from './commands.js'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 复制当前结果为图片到系统剪贴板:不关编辑器、不写宿主节点 */
|
||||||
|
export async function copyResult() {
|
||||||
|
if (S.placingImage) cancelImagePlacement()
|
||||||
|
try {
|
||||||
|
const { blob } = await prepareOutput()
|
||||||
|
await copyBlobToClipboard(blob)
|
||||||
|
if (S.renderAll) S.renderAll() // 摘要里的「上次输出 …KB」要跟上
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[IWB编辑器] 复制失败:', e)
|
||||||
|
toast('复制失败:' + ((e && e.message) || '图片可能跨域'), 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ============ 暴露接口 ============
|
// ============ 暴露接口 ============
|
||||||
/**
|
/**
|
||||||
* 快照/历史开销观测口(性能回归与手测用):
|
* 快照/历史开销观测口(性能回归与手测用):
|
||||||
@@ -308,9 +338,34 @@ import { toast } from './commands.js'
|
|||||||
opacity: l.opacity == null ? 1 : l.opacity,
|
opacity: l.opacity == null ? 1 : l.opacity,
|
||||||
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
||||||
})),
|
})),
|
||||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color })),
|
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
|
||||||
texts: S.textLayers.map(t => ({ id: t.id, text: t.text })),
|
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,
|
||||||
|
strokeWidth: t.strokeWidth, strokeColor: t.strokeColor, bgFill: !!t.bgFill, bgColor: t.bgColor,
|
||||||
|
// 包围盒:吸附/多行/底色/描边的断言都靠它,和绘制共用同一套度量
|
||||||
|
box: (() => { const b = textBounds(t); return { x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h) } })()
|
||||||
|
})),
|
||||||
|
// 吸附参考线(拖动中才有)与最近使用颜色:交互回归用
|
||||||
|
guides: S.guides ? S.guides.map(g => ({ axis: g.axis, at: Math.round(g.at * 10) / 10 })) : [],
|
||||||
|
recentColors: (S.recentColors || []).slice(),
|
||||||
|
textDefaults: {
|
||||||
|
weight: S.textWeight, family: S.textFamily, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||||
|
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
||||||
|
bgFill: S.textBgFill, bgColor: S.textBgColor, bgAlpha: S.textBgAlpha
|
||||||
|
},
|
||||||
|
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
|
||||||
|
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null },
|
||||||
|
// 色板当前在调哪一格:stroke / fill / bg(文字上下文里 fill=描边、bg=底色)
|
||||||
|
colorTarget: S.colorTarget,
|
||||||
selectedShapeId: S.selectedShapeId,
|
selectedShapeId: S.selectedShapeId,
|
||||||
|
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
||||||
|
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
||||||
|
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
|
||||||
|
drag: S.shapeDrag ? ('shape:' + S.shapeDrag.mode + (S.shapeDrag.handle ? ':' + S.shapeDrag.handle : ''))
|
||||||
|
: S.textDrag ? ('text:' + S.textDrag.mode)
|
||||||
|
: S.bitmapDrag ? ('bitmap:' + S.bitmapDrag.mode + (S.bitmapDrag.handle ? ':' + S.bitmapDrag.handle : ''))
|
||||||
|
: null,
|
||||||
selectedTextId: S.selectedTextId,
|
selectedTextId: S.selectedTextId,
|
||||||
penEditId: S.penEditId,
|
penEditId: S.penEditId,
|
||||||
activeLayerId: S.activeLayerId,
|
activeLayerId: S.activeLayerId,
|
||||||
@@ -333,6 +388,14 @@ import { toast } from './commands.js'
|
|||||||
lastExport: S.lastExport ? { ...S.lastExport } : null,
|
lastExport: S.lastExport ? { ...S.lastExport } : null,
|
||||||
// 快速效果的可重调状态:hasSource=false 表示还没点过效果(滑杆应置灰)
|
// 快速效果的可重调状态:hasSource=false 表示还没点过效果(滑杆应置灰)
|
||||||
fx: { key: S.fx.key, value: S.fx.value, layerId: S.fx.layerId, hasSource: Boolean(S.fx.source) },
|
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,
|
interaction: S.interaction,
|
||||||
ants: !!S._antFrame,
|
ants: !!S._antFrame,
|
||||||
view: S.viewX !== null ? [Math.round(S.viewX), Math.round(S.viewY)] : null,
|
view: S.viewX !== null ? [Math.round(S.viewX), Math.round(S.viewY)] : null,
|
||||||
|
|||||||
@@ -8,8 +8,11 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
import { S, runtime } from './state.js'
|
import { S, runtime } from './state.js'
|
||||||
import { TEXT_FONT, allObjects, assignLayerZ, deleteSelectedShape, deleteSelectedText, layerUnits, layerUnitsDesc, renderObjects, selectUnit, sortLayersByZ, textBounds } from './objects.js'
|
import { allObjects, assignLayerZ, deleteSelectedShape, deleteSelectedText, layerUnits, layerUnitsDesc, otherObjectBoxes, renderObjects, selectUnit, sortLayersByZ } from './objects.js'
|
||||||
|
import { drawTextObject } from './text.js'
|
||||||
|
import { snapMove } from './snap.js'
|
||||||
import { boxCorners, clamp, drawRotationHandles, hitRotationHandle, rotPt, unrotPt } from './viewport.js'
|
import { boxCorners, clamp, drawRotationHandles, hitRotationHandle, rotPt, unrotPt } from './viewport.js'
|
||||||
|
import { viewScale } from './scale.js'
|
||||||
import { drawShape } from './tools.js'
|
import { drawShape } from './tools.js'
|
||||||
import { saveSnapshot, snapshotState } from './history.js'
|
import { saveSnapshot, snapshotState } from './history.js'
|
||||||
import { placeImageDirectly } from './placement.js'
|
import { placeImageDirectly } from './placement.js'
|
||||||
@@ -115,7 +118,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const rot = layer.rotation || 0
|
const rot = layer.rotation || 0
|
||||||
const cx = box.x + box.w / 2, cy = box.y + box.h / 2
|
const cx = box.x + box.w / 2, cy = box.y + box.h / 2
|
||||||
const lp = unrotPt(pos.x, pos.y, cx, cy, rot)
|
const lp = unrotPt(pos.x, pos.y, cx, cy, rot)
|
||||||
const R = 14 / S.zoom
|
const R = 14 / viewScale()
|
||||||
if (hitRotationHandle(lp, box)) return 'rotate'
|
if (hitRotationHandle(lp, box)) return 'rotate'
|
||||||
const points = {
|
const points = {
|
||||||
nw: [box.x, box.y], ne: [box.x + box.w, box.y],
|
nw: [box.x, box.y], ne: [box.x + box.w, box.y],
|
||||||
@@ -201,18 +204,17 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
if (!(box.w > 0 && box.h > 0)) return
|
if (!(box.w > 0 && box.h > 0)) return
|
||||||
const ctx = S.overlayCtx
|
const ctx = S.overlayCtx
|
||||||
const rot = layer.rotation || 0
|
const rot = layer.rotation || 0
|
||||||
const hs = 5.5 / S.zoom
|
const hs = 5.5 / viewScale()
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.strokeStyle = '#e8a735'
|
ctx.strokeStyle = '#e8a735'
|
||||||
ctx.lineWidth = 1.5 / S.zoom
|
ctx.lineWidth = 1.5 / viewScale()
|
||||||
ctx.setLineDash([6 / S.zoom, 3 / S.zoom])
|
// 图层/对象选中一律实线(虚线是像素选区的语义,见 objects.js 同处注释)
|
||||||
const corners = boxCorners(box.x, box.y, box.w, box.h, rot)
|
const corners = boxCorners(box.x, box.y, box.w, box.h, rot)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(corners[0][0], corners[0][1])
|
ctx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
||||||
ctx.closePath()
|
ctx.closePath()
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
ctx.setLineDash([])
|
|
||||||
ctx.fillStyle = '#fff'
|
ctx.fillStyle = '#fff'
|
||||||
ctx.strokeStyle = '#e8a735'
|
ctx.strokeStyle = '#e8a735'
|
||||||
const pts = frameHandlePoints(box, rot)
|
const pts = frameHandlePoints(box, rot)
|
||||||
@@ -275,8 +277,19 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
if (!drag || !layer) return
|
if (!drag || !layer) return
|
||||||
const base = drag.layer
|
const base = drag.layer
|
||||||
if (drag.mode === 'move') {
|
if (drag.mode === 'move') {
|
||||||
layer.x = base.x + pos.x - drag.start.x
|
let nx = base.x + pos.x - drag.start.x
|
||||||
layer.y = base.y + pos.y - drag.start.y
|
let ny = base.y + pos.y - drag.start.y
|
||||||
|
// 吸附到画布中线/边界与其它元素(按住 Alt 临时关掉)
|
||||||
|
if (!S._altDown && base.w > 0 && base.h > 0) {
|
||||||
|
const s = snapMove({ x: nx, y: ny, w: base.w, h: base.h }, otherObjectBoxes(layer))
|
||||||
|
nx += s.dx
|
||||||
|
ny += s.dy
|
||||||
|
S.guides = s.guides.length ? s.guides : null
|
||||||
|
} else {
|
||||||
|
S.guides = null
|
||||||
|
}
|
||||||
|
layer.x = nx
|
||||||
|
layer.y = ny
|
||||||
if (isDrawableLayer(layer)) layer._bounds = undefined
|
if (isDrawableLayer(layer)) layer._bounds = undefined
|
||||||
} else if (drag.mode === 'rotate') {
|
} else if (drag.mode === 'rotate') {
|
||||||
const rcx = base.x + base.w / 2, rcy = base.y + base.h / 2
|
const rcx = base.x + base.w / 2, rcy = base.y + base.h / 2
|
||||||
@@ -321,6 +334,8 @@ export function setActiveLayer(id) {
|
|||||||
// 否则用户会在新层上拖出一个属于旧层的像素结果(v1.8)。
|
// 否则用户会在新层上拖出一个属于旧层的像素结果(v1.8)。
|
||||||
// 走注入而不是直接 import effects.js —— 后者已经 import 本模块,硬连会成环。
|
// 走注入而不是直接 import effects.js —— 后者已经 import 本模块,硬连会成环。
|
||||||
if (S.renderFxPanel) S.renderFxPanel()
|
if (S.renderFxPanel) S.renderFxPanel()
|
||||||
|
// 图片调节面板同样按「当前层」走:切层后 target 名与滑块值都要换成新层的
|
||||||
|
if (S.renderAdjustPanel) S.renderAdjustPanel()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 添加位图图层(导入图片)— 便利版:一步落层,不再需要 Enter 二次确认
|
/** 添加位图图层(导入图片)— 便利版:一步落层,不再需要 Enter 二次确认
|
||||||
@@ -453,21 +468,9 @@ export function setActiveLayer(id) {
|
|||||||
if (kind === 'shape') {
|
if (kind === 'shape') {
|
||||||
drawShape(ctx, obj)
|
drawShape(ctx, obj)
|
||||||
} else {
|
} else {
|
||||||
ctx.save()
|
// 文字绘制统一走 text.js:预览、落层、缩略图必须是同一套度量与画法,
|
||||||
ctx.textBaseline = 'top'
|
// 否则「量出来的选中框」和「画出来的字」会各说各话(多行/描边/底色尤其明显)
|
||||||
ctx.globalAlpha = obj.opacity != null ? obj.opacity : 1
|
drawTextObject(ctx, obj)
|
||||||
const rot = obj.rotation || 0
|
|
||||||
if (rot) {
|
|
||||||
const b = textBounds(obj)
|
|
||||||
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
|
||||||
ctx.translate(cx, cy)
|
|
||||||
ctx.rotate(rot * Math.PI / 180)
|
|
||||||
ctx.translate(-cx, -cy)
|
|
||||||
}
|
|
||||||
ctx.font = TEXT_FONT(obj.fontSize)
|
|
||||||
ctx.fillStyle = obj.color
|
|
||||||
ctx.fillText(obj.text, obj.x, obj.y)
|
|
||||||
ctx.restore()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,10 +614,13 @@ export function setActiveLayer(id) {
|
|||||||
// 免得窄面板里「名字 + ✎ + 角标 + 锁 + 删除」把图层名挤成几个字
|
// 免得窄面板里「名字 + ✎ + 角标 + 锁 + 删除」把图层名挤成几个字
|
||||||
const pct = opacityPct(item.opacity)
|
const pct = opacityPct(item.opacity)
|
||||||
const canRename = item.type === 'bitmap'
|
const canRename = item.type === 'bitmap'
|
||||||
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" draggable="${item.id !== 'base'}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
// 注意:整项不能用 HTML5 draggable —— 它会把子元素上的原生拖动一起接管,
|
||||||
|
// 不透明度滑杆因此「只能点、不能拖」。排序改由 bindLayerDragSort 自己实现。
|
||||||
|
const sortHint = item.id === 'base' ? '原图(其他图层可以拖到它下面)' : '拖动调整叠放顺序'
|
||||||
|
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" data-layer-id="${item.id}" data-layer-type="${item.type}">
|
||||||
<div class="iwb-layer-row">
|
<div class="iwb-layer-row">
|
||||||
<button class="iwb-layer-vis" data-vis-id="${item.id}" data-vis-type="${item.type}" title="${item.visible ? '隐藏' : '显示'}">${visSvg}</button>
|
<button class="iwb-layer-vis" data-vis-id="${item.id}" data-vis-type="${item.type}" title="${item.visible ? '隐藏' : '显示'}">${visSvg}</button>
|
||||||
<span class="iwb-layer-thumb"><canvas width="44" height="44" data-thumb-id="${item.id}" data-thumb-type="${item.type}"></canvas><span class="iwb-layer-icon">${typeIconSvg}</span></span>
|
<span class="iwb-layer-thumb" title="${sortHint}"><canvas width="44" height="44" data-thumb-id="${item.id}" data-thumb-type="${item.type}"></canvas><span class="iwb-layer-icon">${typeIconSvg}</span></span>
|
||||||
<span class="iwb-layer-name${canRename ? ' renamable' : ''}" data-name-id="${item.id}" data-name-type="${item.type}" title="${esc(item.name)}${canRename ? ' · 双击重命名' : ''}">${esc(item.name)}</span>
|
<span class="iwb-layer-name${canRename ? ' renamable' : ''}" data-name-id="${item.id}" data-name-type="${item.type}" title="${esc(item.name)}${canRename ? ' · 双击重命名' : ''}">${esc(item.name)}</span>
|
||||||
${item.paintTarget ? '<span class="iwb-layer-paint" title="当前画笔 / 橡皮作用图层">✎</span>' : ''}
|
${item.paintTarget ? '<span class="iwb-layer-paint" title="当前画笔 / 橡皮作用图层">✎</span>' : ''}
|
||||||
${(pct < 100 && !item.active) ? `<span class="iwb-layer-op" title="不透明度 ${pct}%(选中该层可调)">${pct}%</span>` : ''}
|
${(pct < 100 && !item.active) ? `<span class="iwb-layer-op" title="不透明度 ${pct}%(选中该层可调)">${pct}%</span>` : ''}
|
||||||
@@ -645,25 +651,184 @@ export function setActiveLayer(id) {
|
|||||||
bindLayerPanelEvents()
|
bindLayerPanelEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
function reorderPanelItem(dragId, targetId) {
|
/**
|
||||||
if (!dragId || !targetId || dragId === targetId || dragId === 'base' || targetId === 'base') return
|
* 把图层面板的顺序(降序展示 = 最上层在前)算成目标 z 序。
|
||||||
const all = layerUnits()
|
* 单独抽出来是因为「拖动排序」和「面板顺序」必须共用同一套写入路径:
|
||||||
const baseIdx = all.findIndex(u => u.obj.id === 'base')
|
* 面板倒序 → z 升序由 layerUnits() 的排序保证,这里只按面板倒序反转后重排。
|
||||||
if (baseIdx > 0) { const [b] = all.splice(baseIdx, 1); all.unshift(b) }
|
*
|
||||||
const from = all.findIndex(item => item.obj.id === dragId)
|
* 任何单元对不上(图层在拖动期间被删/被合并)就整体放弃,宁可不排序也不能丢层。
|
||||||
const to0 = all.findIndex(item => item.obj.id === targetId)
|
* @param {string[]} descKeys 「类型:id」组成的降序数组
|
||||||
if (from < 0 || to0 < 0) return
|
* @returns {{ordered: Array, changed: boolean}|null} 无法安全重排时返回 null
|
||||||
const before = all.map(u => u.obj.id).join('|')
|
*/
|
||||||
const [moved] = all.splice(from, 1)
|
function planPanelOrder(descKeys) {
|
||||||
const to = Math.max(all.findIndex(item => item.obj.id === targetId), baseIdx >= 0 ? 1 : 0)
|
const units = layerUnits() // z 升序
|
||||||
all.splice(to, 0, moved)
|
const byKey = new Map(units.map(u => [u.kind + ':' + u.obj.id, u]))
|
||||||
if (all.map(u => u.obj.id).join('|') === before) return
|
const ordered = []
|
||||||
saveSnapshot()
|
for (const key of descKeys.slice().reverse()) {
|
||||||
assignLayerZ(all)
|
const u = byKey.get(key)
|
||||||
|
if (!u) continue
|
||||||
|
byKey.delete(key)
|
||||||
|
ordered.push(u)
|
||||||
|
}
|
||||||
|
if (!ordered.length || byKey.size) return null
|
||||||
|
// v1.13:原图不再强制压在最底层(用户裁定「希望能移动到原图下方」)。
|
||||||
|
// 典型用法是垫一张纯色/背景层到原图底下。原图行本身仍不可拖(见 bindLayerDragSort),
|
||||||
|
// 但其他层可以任意穿过它 —— 顺序完全由面板说了算。
|
||||||
|
const before = units.map(u => u.obj.id).join('|')
|
||||||
|
return { ordered, changed: before !== ordered.map(u => u.obj.id).join('|') }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 落地面板顺序:只有顺序真的变了才拍快照 + 重排,空拖动不留无效撤销。
|
||||||
|
* 无论走哪条分支都必须重绘面板 —— 调用方(拖动排序)在此之前已经改过 DOM 次序。 */
|
||||||
|
function applyPanelOrder(descKeys) {
|
||||||
|
const plan = planPanelOrder(descKeys)
|
||||||
|
if (!plan || !plan.changed) { renderLayerPanel(); return false }
|
||||||
|
saveSnapshot('调整图层顺序')
|
||||||
|
assignLayerZ(plan.ordered)
|
||||||
reorderLayerCanvas()
|
reorderLayerCanvas()
|
||||||
sortLayersByZ()
|
sortLayersByZ()
|
||||||
renderObjects()
|
renderObjects()
|
||||||
renderLayerPanel()
|
renderLayerPanel()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 拖动排序(指针事件,替代原来的 HTML5 draggable) ----------
|
||||||
|
// v1.8.3 老实现的三个硬伤:
|
||||||
|
// 1) 整项 draggable 会把子元素上的原生拖动一起接管 —— 不透明度滑杆于是只能点、不能拖;
|
||||||
|
// 2) 插入位置按「目标项索引」算,向下拖一格时先删自己再取索引会回退,等于原地不动;
|
||||||
|
// 3) 只有 .dragging 半透明,没有任何落点反馈,看起来像没反应。
|
||||||
|
// 现在:行跟着指针浮动(transform 位移),越过谁的中线就真的插到谁前面,
|
||||||
|
// 其余行实时让位;松手时直接读 DOM 顺序落地,不再自己算索引。
|
||||||
|
const SORT_THRESHOLD = 4 // 位移超过 4px 才算拖动,否则仍然是一次点击
|
||||||
|
let _sortDrag = null
|
||||||
|
|
||||||
|
function bindLayerDragSort(list) {
|
||||||
|
if (list._iwbSortBound) return
|
||||||
|
list._iwbSortBound = true
|
||||||
|
|
||||||
|
list.addEventListener('pointerdown', (e) => {
|
||||||
|
if (e.button !== 0 || _sortDrag) return
|
||||||
|
const item = e.target.closest('.iwb-layer-item')
|
||||||
|
if (!item || !list.contains(item)) return
|
||||||
|
if (item.dataset.layerId === 'base') return // 原图行不拖:它下面要不要垫层,拖别的层过去即可
|
||||||
|
// 控件、不透明度滑杆行、改名输入框都不参与排序:
|
||||||
|
// 否则滑杆刚按下就被判成「拖图层」,又回到只能点不能拖的老问题
|
||||||
|
if (e.target.closest('.iwb-layer-op-row, input, button, .iwb-layer-name-input')) return
|
||||||
|
_sortDrag = {
|
||||||
|
list, item,
|
||||||
|
id: item.dataset.layerId, type: item.dataset.layerType,
|
||||||
|
startY: e.clientY, y: e.clientY,
|
||||||
|
pointerId: e.pointerId, active: false
|
||||||
|
}
|
||||||
|
document.addEventListener('pointermove', onSortMove, true)
|
||||||
|
document.addEventListener('pointerup', onSortEnd, true)
|
||||||
|
document.addEventListener('pointercancel', onSortCancel, true)
|
||||||
|
// 兜底:切窗口时 pointerup 可能永远不来,不收拾干净的话下一次按下会被
|
||||||
|
// _sortDrag 挡住,整个排序从此失效。
|
||||||
|
// 注意 blur 不冒泡但**会**被捕获阶段收到(聚焦的按钮/输入框失焦也算),
|
||||||
|
// 所以必须判 target 是不是 window 本身 —— 否则鼠标一按在图层行上,
|
||||||
|
// 焦点从工具栏挪走就会立刻把这次拖动取消掉(踩过一次)。
|
||||||
|
window.addEventListener('blur', onWindowBlur, true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSortMove(e) {
|
||||||
|
const d = _sortDrag
|
||||||
|
if (!d) return
|
||||||
|
if (e.pointerId != null && d.pointerId != null && e.pointerId !== d.pointerId) return
|
||||||
|
d.y = e.clientY
|
||||||
|
if (!d.active) {
|
||||||
|
if (Math.abs(e.clientY - d.startY) < SORT_THRESHOLD) return
|
||||||
|
const rect = d.item.getBoundingClientRect()
|
||||||
|
d.grabY = e.clientY - rect.top // 抓取点在行内的偏移,浮动时保持手感
|
||||||
|
d.active = true
|
||||||
|
d.list.classList.add('sorting')
|
||||||
|
d.item.classList.add('dragging')
|
||||||
|
// 拖过图层名就算拖排序了,别让之前那次按下残留成「双击改名」的第一次点击
|
||||||
|
S.lastNameClick = null
|
||||||
|
}
|
||||||
|
updateSortTarget(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSortTarget(d) {
|
||||||
|
const list = d.list
|
||||||
|
const lr = list.getBoundingClientRect()
|
||||||
|
// 贴近上下边缘时自动滚动,长列表也能一路拖到底
|
||||||
|
if (d.y < lr.top + 18) list.scrollTop -= 8
|
||||||
|
else if (d.y > lr.bottom - 18) list.scrollTop += 8
|
||||||
|
|
||||||
|
// 落点:指针越过哪一行的中线,就把自己挪到那一行之前。
|
||||||
|
// v1.13 起不再把「原图」当固定锚点 —— 拖到原图下半区就真的落到它下面(垫背景层用)。
|
||||||
|
const rows = Array.from(list.querySelectorAll('.iwb-layer-item'))
|
||||||
|
const movable = rows.filter(el => el !== d.item)
|
||||||
|
let anchor = null // null = 落到最底(可能是原图之下)
|
||||||
|
for (const el of movable) {
|
||||||
|
const r = el.getBoundingClientRect()
|
||||||
|
if (d.y < r.top + r.height / 2) { anchor = el; break }
|
||||||
|
}
|
||||||
|
if (d.item.nextElementSibling !== anchor || d.item.parentNode !== list) {
|
||||||
|
// 真的搬 DOM:其余行当场让位,这就是最直观的落点反馈
|
||||||
|
if (anchor) list.insertBefore(d.item, anchor)
|
||||||
|
else list.appendChild(d.item)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搬完之后让行继续贴着指针:先清 transform 量出它在新位置的顶边,再补回位移
|
||||||
|
d.item.style.transform = ''
|
||||||
|
const r = d.item.getBoundingClientRect()
|
||||||
|
const dy = Math.round(d.y - d.grabY - r.top)
|
||||||
|
d.item.style.transform = dy ? 'translateY(' + dy + 'px)' : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 松手:直接读 DOM 顺序落地(顺序已经在这之前实时调整好了) */
|
||||||
|
function onSortEnd(e) {
|
||||||
|
const d = _sortDrag
|
||||||
|
if (!d) return
|
||||||
|
if (e && e.pointerId != null && d.pointerId != null && e.pointerId !== d.pointerId) return
|
||||||
|
cleanupSortDrag()
|
||||||
|
if (!d.active) return // 没越过阈值:当成普通点击,走原来的选中逻辑
|
||||||
|
|
||||||
|
const rows = Array.from(d.list.querySelectorAll('.iwb-layer-item'))
|
||||||
|
const keyOf = (el) => el.dataset.layerType + ':' + el.dataset.layerId
|
||||||
|
// v1.13:面板顺序就是最终顺序(原图可以被压在下面),不再把它补到末尾
|
||||||
|
const desc = rows.map(keyOf)
|
||||||
|
|
||||||
|
// 拖动即选中:拖完直接能在下面调不透明度/继续操作,不用再点一次
|
||||||
|
if (d.type === 'bitmap') {
|
||||||
|
if (S.layers.some(l => l.id === d.id)) S.selectedLayerId = d.id
|
||||||
|
} else if (d.type === 'text' || d.type === 'shape') {
|
||||||
|
selectUnit(d.type, d.id)
|
||||||
|
}
|
||||||
|
// 落地(含「顺序没变」的面板刷新)全在 applyPanelOrder 里,它会整块重绘
|
||||||
|
applyPanelOrder(desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 指针被系统打断(触摸手势 / 浏览器抢事件):放弃这次拖动,顺序回到拖动前 */
|
||||||
|
function onSortCancel(e) {
|
||||||
|
const d = _sortDrag
|
||||||
|
if (!d) return
|
||||||
|
if (e && e.pointerId != null && d.pointerId != null && e.pointerId !== d.pointerId) return
|
||||||
|
const wasActive = d.active
|
||||||
|
cleanupSortDrag()
|
||||||
|
if (wasActive) renderLayerPanel()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 只有「窗口本身失焦」才算打断;子元素失焦的 blur 也会被捕获到,必须滤掉 */
|
||||||
|
function onWindowBlur(e) {
|
||||||
|
if (e.target !== window && e.target !== document) return
|
||||||
|
onSortCancel(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanupSortDrag() {
|
||||||
|
const d = _sortDrag
|
||||||
|
if (!d) return
|
||||||
|
document.removeEventListener('pointermove', onSortMove, true)
|
||||||
|
document.removeEventListener('pointerup', onSortEnd, true)
|
||||||
|
document.removeEventListener('pointercancel', onSortCancel, true)
|
||||||
|
window.removeEventListener('blur', onWindowBlur, true)
|
||||||
|
_sortDrag = null
|
||||||
|
d.list.classList.remove('sorting')
|
||||||
|
d.item.classList.remove('dragging')
|
||||||
|
d.item.style.transform = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindLayerPanelEvents() {
|
function bindLayerPanelEvents() {
|
||||||
@@ -671,6 +836,7 @@ export function setActiveLayer(id) {
|
|||||||
if (!list) return
|
if (!list) return
|
||||||
|
|
||||||
bindLayerItemEvents(list)
|
bindLayerItemEvents(list)
|
||||||
|
bindLayerDragSort(list)
|
||||||
bindLayerNameRename(list)
|
bindLayerNameRename(list)
|
||||||
bindLayerOpacityInputs(list)
|
bindLayerOpacityInputs(list)
|
||||||
bindLayerVisButtons(list)
|
bindLayerVisButtons(list)
|
||||||
@@ -678,15 +844,11 @@ export function setActiveLayer(id) {
|
|||||||
bindLayerDelButtons(list)
|
bindLayerDelButtons(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 图层面板项:点击选中(位图/文字/形状)+ 拖到另一项上排序 */
|
/** 图层面板项:点击选中(位图/文字/形状)+ 指针拖动排序(见 bindLayerDragSort) */
|
||||||
function bindLayerItemEvents(list) {
|
function bindLayerItemEvents(list) {
|
||||||
// 点击图层项 → 设为活跃
|
// 点击图层项 → 设为活跃
|
||||||
list.querySelectorAll('.iwb-layer-item').forEach(item => {
|
list.querySelectorAll('.iwb-layer-item').forEach(item => {
|
||||||
item.addEventListener('mousedown', (e) => e.stopPropagation())
|
item.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
item.addEventListener('dragstart', (e) => { if (item.draggable) { e.dataTransfer.setData('text/plain', item.dataset.layerId); item.classList.add('dragging') } })
|
|
||||||
item.addEventListener('dragend', () => item.classList.remove('dragging'))
|
|
||||||
item.addEventListener('dragover', (e) => { if (item.draggable) e.preventDefault() })
|
|
||||||
item.addEventListener('drop', (e) => { e.preventDefault(); reorderPanelItem(e.dataTransfer.getData('text/plain'), item.dataset.layerId) })
|
|
||||||
item.addEventListener('click', (e) => {
|
item.addEventListener('click', (e) => {
|
||||||
if (e.target.closest('.iwb-layer-vis') || e.target.closest('.iwb-layer-lock') || e.target.closest('.iwb-layer-del')) return
|
if (e.target.closest('.iwb-layer-vis') || e.target.closest('.iwb-layer-lock') || e.target.closest('.iwb-layer-del')) return
|
||||||
// 拖动不透明度滑杆 / 正在改名:都不能触发整块重绘,否则控件节点会被换掉
|
// 拖动不透明度滑杆 / 正在改名:都不能触发整块重绘,否则控件节点会被换掉
|
||||||
@@ -752,8 +914,7 @@ export function setActiveLayer(id) {
|
|||||||
input.value = layer.name
|
input.value = layer.name
|
||||||
input.maxLength = 40
|
input.maxLength = 40
|
||||||
span.replaceWith(input)
|
span.replaceWith(input)
|
||||||
// 重命名期间禁用整项拖动,否则在输入框里拖选文字会变成拖动图层排序
|
// 输入框本身被拖动排序逻辑排除(input 选择器),在框里拖选文字不会变成拖图层
|
||||||
item.draggable = false
|
|
||||||
|
|
||||||
let done = false
|
let done = false
|
||||||
const finish = (commit) => {
|
const finish = (commit) => {
|
||||||
@@ -791,13 +952,22 @@ export function setActiveLayer(id) {
|
|||||||
// 双击滑块复位 100%(PS 里双击「不透明度」标题即可复位,这里沿用同一习惯)
|
// 双击滑块复位 100%(PS 里双击「不透明度」标题即可复位,这里沿用同一习惯)
|
||||||
input.addEventListener('dblclick', (e) => {
|
input.addEventListener('dblclick', (e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
input._opSnapTaken = false
|
||||||
input.value = '100'
|
input.value = '100'
|
||||||
applyOpacityFromInput(input)
|
applyOpacityFromInput(input)
|
||||||
|
input._opSnapTaken = false
|
||||||
})
|
})
|
||||||
input.addEventListener('input', (e) => {
|
input.addEventListener('input', (e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
applyOpacityFromInput(input)
|
applyOpacityFromInput(input)
|
||||||
})
|
})
|
||||||
|
// 一次拖动 / 一次方向键操作结束后重开快照闸门:
|
||||||
|
// 否则滑杆在面板重绘前一直复用一个标记,第二次拖动就不再记撤销了
|
||||||
|
const resetSnap = () => { input._opSnapTaken = false }
|
||||||
|
input.addEventListener('change', resetSnap)
|
||||||
|
input.addEventListener('pointerup', resetSnap)
|
||||||
|
input.addEventListener('pointercancel', resetSnap)
|
||||||
|
input.addEventListener('blur', resetSnap)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1004,6 +1174,8 @@ export function setActiveLayer(id) {
|
|||||||
const insertAt = all.slice(0, Math.max(lowIdx, 0)).filter(u => !chosenSet.has(u.obj)).length
|
const insertAt = all.slice(0, Math.max(lowIdx, 0)).filter(u => !chosenSet.has(u.obj)).length
|
||||||
|
|
||||||
let carrier
|
let carrier
|
||||||
|
// 原图原来的 z:合并后要落回原位(v1.13 起原图不再被强制压到最底,不能 unshift)
|
||||||
|
const baseZ = baseUnit ? (baseUnit.obj.z || 0) : 0
|
||||||
if (baseUnit) {
|
if (baseUnit) {
|
||||||
carrier = baseUnit.obj
|
carrier = baseUnit.obj
|
||||||
// 合并后它就是纯像素层:断掉 image/sourceCanvas,避免后续按原图重新重绘
|
// 合并后它就是纯像素层:断掉 image/sourceCanvas,避免后续按原图重新重绘
|
||||||
@@ -1021,9 +1193,10 @@ export function setActiveLayer(id) {
|
|||||||
carrier._bounds = undefined
|
carrier._bounds = undefined
|
||||||
composeUnitsInto(carrier, sorted)
|
composeUnitsInto(carrier, sorted)
|
||||||
for (const u of sorted) if (u.obj !== carrier) dropUnit(u)
|
for (const u of sorted) if (u.obj !== carrier) dropUnit(u)
|
||||||
// base 永远压在最底,其余层保持原有相对顺序
|
// 落回原图原来的叠放位置:低于它的层留在它下面(v1.13 允许原图上面压着别的层)
|
||||||
const rest = layerUnits().filter(u => u.obj !== carrier)
|
const rest = layerUnits().filter(u => u.obj !== carrier)
|
||||||
rest.unshift({ kind: 'bitmap', obj: carrier })
|
const at = rest.filter(u => (u.obj.z || 0) < baseZ).length
|
||||||
|
rest.splice(Math.min(at, rest.length), 0, { kind: 'bitmap', obj: carrier })
|
||||||
assignLayerZ(rest)
|
assignLayerZ(rest)
|
||||||
} else {
|
} else {
|
||||||
const canvas = createLayerCanvas()
|
const canvas = createLayerCanvas()
|
||||||
|
|||||||
@@ -8,26 +8,27 @@
|
|||||||
|
|
||||||
import { S, runtime } from './state.js'
|
import { S, runtime } from './state.js'
|
||||||
import { boxCorners, clamp, drawRotationHandles, hitRotationHandle, rotPt, unrotPt } from './viewport.js'
|
import { boxCorners, clamp, drawRotationHandles, hitRotationHandle, rotPt, unrotPt } from './viewport.js'
|
||||||
|
import { viewScale } from './scale.js'
|
||||||
import { clearOverlay, drawCropPreview } from './crop.js'
|
import { clearOverlay, drawCropPreview } from './crop.js'
|
||||||
import { drawBitmapSelection, drawVectorToCanvas, hitBitmapAt, removeVecCanvas, renderLayerPanel, reorderLayerCanvas } from './layers.js'
|
import { drawBitmapSelection, drawVectorToCanvas, hitBitmapAt, removeVecCanvas, renderLayerPanel, reorderLayerCanvas } from './layers.js'
|
||||||
import { drawPlacementPreview } from './placement.js'
|
import { drawPlacementPreview } from './placement.js'
|
||||||
import { drawShape, setTool } from './tools.js'
|
import { drawShape, setTool } from './tools.js'
|
||||||
import { saveSnapshot, snapshotState } from './history.js'
|
import { saveSnapshot, snapshotState } from './history.js'
|
||||||
import { toast } from './commands.js'
|
import { toast } from './commands.js'
|
||||||
import { renderOptionBar, updateLayerUI } from './events.js'
|
import { renderOptionBar } from './events.js'
|
||||||
|
import { fontOf, fontStackOf, newTextStyle, textBox, weightOf } from './text.js'
|
||||||
|
import { drawGuides } from './snap.js'
|
||||||
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||||
|
|
||||||
|
|
||||||
// ============ 文字图层 ============
|
// ============ 文字图层 ============
|
||||||
|
|
||||||
export const TEXT_FONT = (size) => 'bold ' + size + 'px sans-serif'
|
/** 兼容旧调用点:TEXT_FONT(size) 返回粗体字体串;带样式的字体请用 text.js 的 fontOf(obj) */
|
||||||
|
export const TEXT_FONT = (size) => fontOf({ fontSize: size, fontWeight: 'bold' })
|
||||||
|
|
||||||
|
/** 文字包围盒:含多行、底色 padding 与描边外扩(单行时与旧实现完全一致) */
|
||||||
export function textBounds(t) {
|
export function textBounds(t) {
|
||||||
const ctx = S.textCtx
|
return textBox(t)
|
||||||
ctx.font = TEXT_FONT(t.fontSize)
|
|
||||||
const w = ctx.measureText(t.text).width
|
|
||||||
const h = t.fontSize * 1.25
|
|
||||||
return { x: t.x, y: t.y, w, h }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSelectedText() {
|
export function getSelectedText() {
|
||||||
@@ -67,7 +68,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const lp = rot ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, rot) : [pos.x, pos.y]
|
const lp = rot ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, rot) : [pos.x, pos.y]
|
||||||
if (hitRotationHandle(lp, b)) return 'rotate'
|
if (hitRotationHandle(lp, b)) return 'rotate'
|
||||||
const local = { nw: [b.x, b.y], ne: [b.x + b.w, b.y], sw: [b.x, b.y + b.h], se: [b.x + b.w, b.y + b.h] }
|
const local = { nw: [b.x, b.y], ne: [b.x + b.w, b.y], sw: [b.x, b.y + b.h], se: [b.x + b.w, b.y + b.h] }
|
||||||
const R = 12 / S.zoom
|
const R = 12 / viewScale()
|
||||||
let best = null, bestDist = 1e9
|
let best = null, bestDist = 1e9
|
||||||
for (const name in local) {
|
for (const name in local) {
|
||||||
const dx = lp[0] - local[name][0], dy = lp[1] - local[name][1]
|
const dx = lp[0] - local[name][0], dy = lp[1] - local[name][1]
|
||||||
@@ -103,7 +104,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const lp = unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, s.rotation)
|
const lp = unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, s.rotation)
|
||||||
pos = { x: lp[0], y: lp[1] }
|
pos = { x: lp[0], y: lp[1] }
|
||||||
}
|
}
|
||||||
if (s.type === 'pen') { const pts = s.pts || []; for (let i = 1; i < pts.length; i++) if (distToSeg(pos.x, pos.y, pts[i-1].x, pts[i-1].y, pts[i].x, pts[i].y) <= Math.max(8 / S.zoom, s.lw)) return true; if (s.closed && pts.length > 2 && distToSeg(pos.x, pos.y, pts[pts.length-1].x, pts[pts.length-1].y, pts[0].x, pts[0].y) <= Math.max(8 / S.zoom, s.lw)) return true; if (!includeInterior) return false; const b = shapeBounds(s); return pos.x >= b.x && pos.x <= b.x + b.w && pos.y >= b.y && pos.y <= b.y + b.h }
|
if (s.type === 'pen') { const pts = s.pts || []; for (let i = 1; i < pts.length; i++) if (distToSeg(pos.x, pos.y, pts[i-1].x, pts[i-1].y, pts[i].x, pts[i].y) <= Math.max(8 / viewScale(), s.lw)) return true; if (s.closed && pts.length > 2 && distToSeg(pos.x, pos.y, pts[pts.length-1].x, pts[pts.length-1].y, pts[0].x, pts[0].y) <= Math.max(8 / viewScale(), s.lw)) return true; if (!includeInterior) return false; const b = shapeBounds(s); return pos.x >= b.x && pos.x <= b.x + b.w && pos.y >= b.y && pos.y <= b.y + b.h }
|
||||||
if (s.type === 'circle') {
|
if (s.type === 'circle') {
|
||||||
const b = shapeBounds(s)
|
const b = shapeBounds(s)
|
||||||
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
||||||
@@ -111,7 +112,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const nx = (pos.x - cx) / rx, ny = (pos.y - cy) / ry
|
const nx = (pos.x - cx) / rx, ny = (pos.y - cy) / ry
|
||||||
const value = nx * nx + ny * ny
|
const value = nx * nx + ny * ny
|
||||||
if (includeInterior || s.fill) return value <= 1
|
if (includeInterior || s.fill) return value <= 1
|
||||||
const edgeTolerance = Math.max(4 / S.zoom, s.lw / Math.min(rx, ry))
|
const edgeTolerance = Math.max(4 / viewScale(), s.lw / Math.min(rx, ry))
|
||||||
const outer = (1 + edgeTolerance) * (1 + edgeTolerance)
|
const outer = (1 + edgeTolerance) * (1 + edgeTolerance)
|
||||||
const inner = Math.max(0, 1 - edgeTolerance) * Math.max(0, 1 - edgeTolerance)
|
const inner = Math.max(0, 1 - edgeTolerance) * Math.max(0, 1 - edgeTolerance)
|
||||||
return value >= inner && value <= outer
|
return value >= inner && value <= outer
|
||||||
@@ -127,7 +128,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
pos.y >= b.y + pad && pos.y <= b.y + b.h - pad
|
pos.y >= b.y + pad && pos.y <= b.y + b.h - pad
|
||||||
return !inInner
|
return !inInner
|
||||||
}
|
}
|
||||||
return distToSeg(pos.x, pos.y, s.x1, s.y1, s.x2, s.y2) <= Math.max(8 / S.zoom, s.lw)
|
return distToSeg(pos.x, pos.y, s.x1, s.y1, s.x2, s.y2) <= Math.max(8 / viewScale(), s.lw)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hitShapeLayer(pos, includeInterior) {
|
export function hitShapeLayer(pos, includeInterior) {
|
||||||
@@ -203,6 +204,23 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 其它可见元素的包围盒(拖动吸附用):排除自己与原图底图(底图边界=画布边界,重复) */
|
||||||
|
export function otherObjectBoxes(exclude) {
|
||||||
|
const out = []
|
||||||
|
for (const unit of layerUnits()) {
|
||||||
|
const o = unit.obj
|
||||||
|
if (!o || o === exclude || o.id === 'base' || o.visible === false) continue
|
||||||
|
if (unit.kind === 'bitmap') {
|
||||||
|
if (isFinite(o.x) && isFinite(o.y) && o.w > 0 && o.h > 0) out.push({ x: o.x, y: o.y, w: o.w, h: o.h })
|
||||||
|
} else if (unit.kind === 'text') {
|
||||||
|
out.push(textBox(o))
|
||||||
|
} else {
|
||||||
|
out.push(shapeBounds(o))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
export function hitAnyObject(pos) {
|
export function hitAnyObject(pos) {
|
||||||
for (const unit of layerUnitsDesc()) {
|
for (const unit of layerUnitsDesc()) {
|
||||||
if (unit.kind === 'bitmap') continue
|
if (unit.kind === 'bitmap') continue
|
||||||
@@ -233,12 +251,11 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
if (!sel) { toast('先在画布或图层面板选中要调整的元素', 'info'); return }
|
if (!sel) { toast('先在画布或图层面板选中要调整的元素', 'info'); return }
|
||||||
if (sel.obj.locked || sel.obj.id === 'base') return
|
if (sel.obj.locked || sel.obj.id === 'base') return
|
||||||
const units = layerUnits()
|
const units = layerUnits()
|
||||||
// base 是锁定且不透明的底图,固定在最下层;任何元素都不许置底到它下面(否则等于消失)
|
// v1.13:不再把原图钉在最底层 —— 「置底」可以真的沉到原图下面(垫背景层的常见用法)。
|
||||||
const baseIdx = units.findIndex(u => u.obj.id === 'base')
|
// 原图行本身仍不可参与(上面已 return),避免把底图整层挪走。
|
||||||
if (baseIdx > 0) { const [b] = units.splice(baseIdx, 1); units.unshift(b) }
|
|
||||||
const from = units.findIndex(u => u.obj === sel.obj)
|
const from = units.findIndex(u => u.obj === sel.obj)
|
||||||
if (from < 0) return
|
if (from < 0) return
|
||||||
const min = baseIdx >= 0 ? 1 : 0
|
const min = 0
|
||||||
let to
|
let to
|
||||||
if (dir === 'up') to = Math.min(from + 1, units.length - 1)
|
if (dir === 'up') to = Math.min(from + 1, units.length - 1)
|
||||||
else if (dir === 'down') to = Math.max(from - 1, min)
|
else if (dir === 'down') to = Math.max(from - 1, min)
|
||||||
@@ -310,8 +327,8 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const lp = rot ? unrotPt(pos.x, pos.y, cx, cy, rot) : [pos.x, pos.y]
|
const lp = rot ? unrotPt(pos.x, pos.y, cx, cy, rot) : [pos.x, pos.y]
|
||||||
if (hitRotationHandle(lp, b)) return 'rotate'
|
if (hitRotationHandle(lp, b)) return 'rotate'
|
||||||
const pts = shapeHandlePoints(s)
|
const pts = shapeHandlePoints(s)
|
||||||
const offset = 8 / S.zoom
|
const offset = 8 / viewScale()
|
||||||
const R = Math.max(14 / S.zoom, 9)
|
const R = 14 / viewScale()
|
||||||
let best = null, bestDist = 1e9
|
let best = null, bestDist = 1e9
|
||||||
for (const name in pts) {
|
for (const name in pts) {
|
||||||
const px = pts[name][0] + (name.includes('w') ? -offset : name.includes('e') ? offset : 0)
|
const px = pts[name][0] + (name.includes('w') ? -offset : name.includes('e') ? offset : 0)
|
||||||
@@ -352,7 +369,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const b = shapeBounds(s)
|
const b = shapeBounds(s)
|
||||||
const offset = 8 / S.zoom
|
const offset = 8 / viewScale()
|
||||||
const adjusted = { x: pos.x - (handle.includes('w') ? -offset : handle.includes('e') ? offset : 0), y: pos.y - (handle.includes('n') ? -offset : handle.includes('s') ? offset : 0) }
|
const adjusted = { x: pos.x - (handle.includes('w') ? -offset : handle.includes('e') ? offset : 0), y: pos.y - (handle.includes('n') ? -offset : handle.includes('s') ? offset : 0) }
|
||||||
let x1 = b.x, y1 = b.y, x2 = b.x + b.w, y2 = b.y + b.h
|
let x1 = b.x, y1 = b.y, x2 = b.x + b.w, y2 = b.y + b.h
|
||||||
if (handle.includes('e')) x2 = Math.max(x1 + 2, adjusted.x)
|
if (handle.includes('e')) x2 = Math.max(x1 + 2, adjusted.x)
|
||||||
@@ -368,13 +385,14 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const ctx = S.overlayCtx
|
const ctx = S.overlayCtx
|
||||||
const pts = path.pts.slice()
|
const pts = path.pts.slice()
|
||||||
const first = pts[0]
|
const first = pts[0]
|
||||||
const nearStart = path.preview && pts.length >= 3 && Math.hypot(path.preview.x - first.x, path.preview.y - first.y) <= Math.max(12 / S.zoom, S.shapeLineWidth * 1.5)
|
const nearStart = path.preview && pts.length >= 3 && Math.hypot(path.preview.x - first.x, path.preview.y - first.y) <= Math.max(12 / viewScale(), S.shapeLineWidth * 1.5)
|
||||||
if (path.preview) pts.push(nearStart ? first : path.preview)
|
if (path.preview) pts.push(nearStart ? first : path.preview)
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.strokeStyle = S.color
|
ctx.strokeStyle = S.color
|
||||||
ctx.fillStyle = nearStart ? 'rgba(232, 167, 53, 0.18)' : 'transparent'
|
ctx.fillStyle = nearStart ? 'rgba(232, 167, 53, 0.18)' : 'transparent'
|
||||||
ctx.lineWidth = Math.max(1, S.shapeLineWidth) / S.zoom
|
// 预览线宽 = 实际线宽(图片单位),不再除缩放,做到所见即所得
|
||||||
ctx.setLineDash([8 / S.zoom, 5 / S.zoom])
|
ctx.lineWidth = Math.max(1, S.shapeLineWidth)
|
||||||
|
ctx.setLineDash([8 / viewScale(), 5 / viewScale()])
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(pts[0].x, pts[0].y)
|
ctx.moveTo(pts[0].x, pts[0].y)
|
||||||
for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y)
|
for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y)
|
||||||
@@ -386,7 +404,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.fillStyle = i === 0 && nearStart ? '#e8a735' : '#ffffff'
|
ctx.fillStyle = i === 0 && nearStart ? '#e8a735' : '#ffffff'
|
||||||
ctx.strokeStyle = S.color
|
ctx.strokeStyle = S.color
|
||||||
ctx.arc(point.x, point.y, Math.max(4, 6 / S.zoom), 0, Math.PI * 2)
|
ctx.arc(point.x, point.y, 6 / viewScale(), 0, Math.PI * 2)
|
||||||
ctx.fill(); ctx.stroke()
|
ctx.fill(); ctx.stroke()
|
||||||
}
|
}
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
@@ -398,16 +416,16 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const rot = s.rotation || 0
|
const rot = s.rotation || 0
|
||||||
octx.save()
|
octx.save()
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
octx.lineWidth = 1.5 / S.zoom
|
octx.lineWidth = 1.5 / viewScale()
|
||||||
octx.setLineDash([6 / S.zoom, 3 / S.zoom])
|
// v1.10:对象选中框用**实线**。虚线在 PS 语义里是「像素选区(蚂蚁线)」,
|
||||||
|
// 用户看到文字/图形外面一圈虚线会当成「莫名其妙多出来的选区」。
|
||||||
const corners = boxCorners(b.x, b.y, b.w, b.h, rot)
|
const corners = boxCorners(b.x, b.y, b.w, b.h, rot)
|
||||||
octx.beginPath()
|
octx.beginPath()
|
||||||
octx.moveTo(corners[0][0], corners[0][1])
|
octx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
||||||
octx.closePath()
|
octx.closePath()
|
||||||
octx.stroke()
|
octx.stroke()
|
||||||
octx.setLineDash([])
|
const hs = 5.5 / viewScale()
|
||||||
const hs = 5.5 / S.zoom
|
|
||||||
octx.fillStyle = '#ffffff'
|
octx.fillStyle = '#ffffff'
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
const pts = shapeHandleWorld(s)
|
const pts = shapeHandleWorld(s)
|
||||||
@@ -437,6 +455,8 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
for (const { kind, obj } of allObjects()) drawVectorToCanvas(kind, obj)
|
for (const { kind, obj } of allObjects()) drawVectorToCanvas(kind, obj)
|
||||||
reorderLayerCanvas()
|
reorderLayerCanvas()
|
||||||
clearOverlay()
|
clearOverlay()
|
||||||
|
// 吸附参考线:拖动中才有值,松手清空。画在 overlay 层,不参与合成与导出
|
||||||
|
drawGuides(S.overlayCtx, S.guides)
|
||||||
if (tempShape) drawShape(S.overlayCtx, tempShape)
|
if (tempShape) drawShape(S.overlayCtx, tempShape)
|
||||||
if (S.tool === 'pen' && S.penPath && S.penPath.pts.length) drawPenPathPreview()
|
if (S.tool === 'pen' && S.penPath && S.penPath.pts.length) drawPenPathPreview()
|
||||||
// 图片放置模式优先显示放置预览
|
// 图片放置模式优先显示放置预览
|
||||||
@@ -453,16 +473,15 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const octx = S.overlayCtx
|
const octx = S.overlayCtx
|
||||||
octx.save()
|
octx.save()
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
octx.lineWidth = 1.5 / S.zoom
|
octx.lineWidth = 1.5 / viewScale()
|
||||||
octx.setLineDash([6 / S.zoom, 3 / S.zoom])
|
// 同上:对象选中是实线(虚线只留给像素选区的蚂蚁线)
|
||||||
const corners = boxCorners(b.x - 2 / S.zoom, b.y - 2 / S.zoom, b.w + 4 / S.zoom, b.h + 4 / S.zoom, rot)
|
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot)
|
||||||
octx.beginPath()
|
octx.beginPath()
|
||||||
octx.moveTo(corners[0][0], corners[0][1])
|
octx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
||||||
octx.closePath()
|
octx.closePath()
|
||||||
octx.stroke()
|
octx.stroke()
|
||||||
octx.setLineDash([])
|
const hs = 5.5 / viewScale()
|
||||||
const hs = 5.5 / S.zoom
|
|
||||||
octx.fillStyle = '#ffffff'
|
octx.fillStyle = '#ffffff'
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
const pts = textHandlePoints(sel)
|
const pts = textHandlePoints(sel)
|
||||||
@@ -480,7 +499,6 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const penShape = getPenEditingShape()
|
const penShape = getPenEditingShape()
|
||||||
if (penShape) drawPenEditOverlay(penShape)
|
if (penShape) drawPenEditOverlay(penShape)
|
||||||
if (S.cropRect) drawCropPreview()
|
if (S.cropRect) drawCropPreview()
|
||||||
updateLayerUI()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ 钢笔二次编辑(移动/添加/删除节点) ============
|
// ============ 钢笔二次编辑(移动/添加/删除节点) ============
|
||||||
@@ -522,7 +540,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const pts = shape.pts || []
|
const pts = shape.pts || []
|
||||||
const b = shapeBounds(shape)
|
const b = shapeBounds(shape)
|
||||||
const lp = shape.rotation ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, shape.rotation) : [pos.x, pos.y]
|
const lp = shape.rotation ? unrotPt(pos.x, pos.y, b.x + b.w / 2, b.y + b.h / 2, shape.rotation) : [pos.x, pos.y]
|
||||||
const r = Math.max(12 / S.zoom, 6)
|
const r = 12 / viewScale()
|
||||||
for (let i = 0; i < pts.length - 1; i++) {
|
for (let i = 0; i < pts.length - 1; i++) {
|
||||||
if (distToSeg(lp[0], lp[1], pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y) <= r) return i
|
if (distToSeg(lp[0], lp[1], pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y) <= r) return i
|
||||||
}
|
}
|
||||||
@@ -539,9 +557,9 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const rot = shape.rotation || 0
|
const rot = shape.rotation || 0
|
||||||
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
||||||
const W = (p) => rotPt(p.x, p.y, cx, cy, rot)
|
const W = (p) => rotPt(p.x, p.y, cx, cy, rot)
|
||||||
const R = Math.max(7 / S.zoom, 5)
|
const R = 7 / viewScale()
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.lineWidth = 1.5 / S.zoom
|
ctx.lineWidth = 1.5 / viewScale()
|
||||||
const segments = []
|
const segments = []
|
||||||
for (let i = 0; i < pts.length - 1; i++) segments.push([pts[i], pts[i + 1]])
|
for (let i = 0; i < pts.length - 1; i++) segments.push([pts[i], pts[i + 1]])
|
||||||
if (shape.closed && pts.length >= 3) segments.push([pts[pts.length - 1], pts[0]])
|
if (shape.closed && pts.length >= 3) segments.push([pts[pts.length - 1], pts[0]])
|
||||||
@@ -550,7 +568,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
const wa = W(a), wb = W(bb)
|
const wa = W(a), wb = W(bb)
|
||||||
const mx = (wa[0] + wb[0]) / 2, my = (wa[1] + wb[1]) / 2
|
const mx = (wa[0] + wb[0]) / 2, my = (wa[1] + wb[1]) / 2
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.arc(mx, my, Math.max(3 / S.zoom, 2), 0, Math.PI * 2)
|
ctx.arc(mx, my, 3 / viewScale(), 0, Math.PI * 2)
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
}
|
}
|
||||||
for (let i = 0; i < pts.length; i++) {
|
for (let i = 0; i < pts.length; i++) {
|
||||||
@@ -568,12 +586,20 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
// ============ 文字输入框 ============
|
// ============ 文字输入框 ============
|
||||||
export function showTextInput(x, y, layer) {
|
export function showTextInput(x, y, layer) {
|
||||||
const input = runtime.el.querySelector('.iwb-editor-text-input')
|
const input = runtime.el.querySelector('.iwb-editor-text-input')
|
||||||
const rect = S.canvasStack.getBoundingClientRect()
|
|
||||||
const wrapRect = S.canvasWrap.getBoundingClientRect()
|
const wrapRect = S.canvasWrap.getBoundingClientRect()
|
||||||
const sx = rect.width / S.imgW
|
// 不能用 canvasStack 的矩形换算:stack 的尺寸是 (imgW + 2*overlayPad) * scale,
|
||||||
const sy = rect.height / S.imgH
|
// 图片在 stack 内部还额外偏移了 pad*scale(图层 canvas 的 left/top)。
|
||||||
input.style.left = (rect.left - wrapRect.left + x * sx) + 'px'
|
// 拿它算比例会偏小、又漏掉这段偏移,输入框就整体跑到点击点的左上方。
|
||||||
input.style.top = (rect.top - wrapRect.top + y * sy) + 'px'
|
// textCanvas 与图层 canvas 同基准,矩形精确等于「图片显示区域」。
|
||||||
|
const box = (S.textCanvas || S.canvasStack).getBoundingClientRect()
|
||||||
|
const sx = S.imgW ? box.width / S.imgW : 1
|
||||||
|
const sy = S.imgH ? box.height / S.imgH : 1
|
||||||
|
// textarea 有 2px 边框 + 8/4px 内边距,反向抵消后「输入框里的字起点」正压在点击点上,
|
||||||
|
// 与提交后 drawTextObject 从 t.x/t.y 起画的位置完全一致(所见即所得)。
|
||||||
|
const INSET_X = 10
|
||||||
|
const INSET_Y = 6
|
||||||
|
input.style.left = (box.left - wrapRect.left + x * sx - INSET_X) + 'px'
|
||||||
|
input.style.top = (box.top - wrapRect.top + y * sy - INSET_Y) + 'px'
|
||||||
input.style.display = 'block'
|
input.style.display = 'block'
|
||||||
if (layer) {
|
if (layer) {
|
||||||
input.value = layer.text
|
input.value = layer.text
|
||||||
@@ -582,10 +608,19 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
input.value = ''
|
input.value = ''
|
||||||
S.textEditingId = null
|
S.textEditingId = null
|
||||||
}
|
}
|
||||||
|
// 输入时看到的字形要和提交后一致:字体族与字重跟随这段文字自己的样式
|
||||||
|
// (新建时跟随「下一段文字的默认值」)。字号仍按 CSS 的 14px —— 那是输入框的可读性取舍,
|
||||||
|
// 跟字体不同:字体不一致会让人以为「选错字体了」,字号不一致只是大小不同。
|
||||||
|
const styleSrc = layer || { fontFamily: S.textFamily, fontWeight: S.textWeight }
|
||||||
|
input.style.fontFamily = fontStackOf(styleSrc)
|
||||||
|
input.style.fontWeight = weightOf(styleSrc)
|
||||||
input.focus()
|
input.focus()
|
||||||
input.select()
|
input.select()
|
||||||
input.dataset.x = x
|
input.dataset.x = x
|
||||||
input.dataset.y = y
|
input.dataset.y = y
|
||||||
|
// textarea 不会自己长高:先按内容撑开,否则多行文本会挤在一行里
|
||||||
|
input.style.height = 'auto'
|
||||||
|
input.style.height = Math.max(30, input.scrollHeight + 4) + 'px'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hideTextInput() {
|
export function hideTextInput() {
|
||||||
@@ -630,6 +665,12 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
x, y, text,
|
x, y, text,
|
||||||
color: S.color,
|
color: S.color,
|
||||||
fontSize: Math.max(8, S.textSize),
|
fontSize: Math.max(8, S.textSize),
|
||||||
|
// 样式一次性随默认值落进对象:老对象没有这些字段,text.js 会各自回退到等价默认值
|
||||||
|
...newTextStyle({
|
||||||
|
fontWeight: S.textWeight, fontFamily: S.textFamily, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||||
|
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
||||||
|
bgFill: S.textBgFill, bgColor: S.textBgColor
|
||||||
|
}),
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
visible: true,
|
visible: true,
|
||||||
locked: false,
|
locked: false,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import { S } from './state.js'
|
import { S } from './state.js'
|
||||||
import { boxCorners, drawRotationHandles, hitRotationHandle, rotPt, unrotPt } from './viewport.js'
|
import { boxCorners, drawRotationHandles, hitRotationHandle, rotPt, unrotPt } from './viewport.js'
|
||||||
|
import { viewScale } from './scale.js'
|
||||||
import { clearOverlay } from './crop.js'
|
import { clearOverlay } from './crop.js'
|
||||||
import { createLayerCanvas, redrawBitmapLayer, renderLayerPanel, reorderLayerCanvas, setActiveLayer, updateLayerCanvasStyles } from './layers.js'
|
import { createLayerCanvas, redrawBitmapLayer, renderLayerPanel, reorderLayerCanvas, setActiveLayer, updateLayerCanvasStyles } from './layers.js'
|
||||||
import { saveSnapshot } from './history.js'
|
import { saveSnapshot } from './history.js'
|
||||||
@@ -131,8 +132,8 @@ import { updateCursor } from './events.js'
|
|||||||
const corners = boxCorners(x, y, w, h, rot)
|
const corners = boxCorners(x, y, w, h, rot)
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.strokeStyle = '#4488ff'
|
ctx.strokeStyle = '#4488ff'
|
||||||
ctx.lineWidth = 2 / S.zoom
|
ctx.lineWidth = 2 / viewScale()
|
||||||
ctx.setLineDash([8 / S.zoom, 4 / S.zoom])
|
ctx.setLineDash([8 / viewScale(), 4 / viewScale()])
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(corners[0][0], corners[0][1])
|
ctx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
||||||
@@ -140,10 +141,10 @@ import { updateCursor } from './events.js'
|
|||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
ctx.setLineDash([])
|
ctx.setLineDash([])
|
||||||
// 8 个缩放手柄(旋转后位置)
|
// 8 个缩放手柄(旋转后位置)
|
||||||
const hs = 5.5 / S.zoom
|
const hs = 5.5 / viewScale()
|
||||||
ctx.fillStyle = '#fff'
|
ctx.fillStyle = '#fff'
|
||||||
ctx.strokeStyle = '#4488ff'
|
ctx.strokeStyle = '#4488ff'
|
||||||
ctx.lineWidth = 1.5 / S.zoom
|
ctx.lineWidth = 1.5 / viewScale()
|
||||||
const localPts = {
|
const localPts = {
|
||||||
nw: [x, y], ne: [x + w, y],
|
nw: [x, y], ne: [x + w, y],
|
||||||
sw: [x, y + h], se: [x + w, y + h],
|
sw: [x, y + h], se: [x + w, y + h],
|
||||||
@@ -162,17 +163,17 @@ import { updateCursor } from './events.js'
|
|||||||
drawRotationHandles(ctx, { x, y, w, h }, rot)
|
drawRotationHandles(ctx, { x, y, w, h }, rot)
|
||||||
// 提示文字
|
// 提示文字
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.font = 'bold ' + Math.round(14 / S.zoom) + 'px sans-serif'
|
ctx.font = 'bold ' + Math.round(14 / viewScale()) + 'px sans-serif'
|
||||||
ctx.textAlign = 'center'
|
ctx.textAlign = 'center'
|
||||||
ctx.textBaseline = 'top'
|
ctx.textBaseline = 'top'
|
||||||
const hintText = '拖拽手柄调整大小 · 圆点=旋转 · Shift=等比/15°吸附 · Enter=确认 · Esc=取消'
|
const hintText = '拖拽手柄调整大小 · 圆点=旋转 · Shift=等比/15°吸附 · Enter=确认 · Esc=取消'
|
||||||
const br = boxCorners(x, y, w, h, rot).reduce((acc, pt) => Math.max(acc, pt[1]), -Infinity)
|
const br = boxCorners(x, y, w, h, rot).reduce((acc, pt) => Math.max(acc, pt[1]), -Infinity)
|
||||||
const hintY = br + 10 / S.zoom
|
const hintY = br + 10 / viewScale()
|
||||||
const tw = ctx.measureText(hintText).width
|
const tw = ctx.measureText(hintText).width
|
||||||
ctx.fillStyle = 'rgba(0,0,0,0.6)'
|
ctx.fillStyle = 'rgba(0,0,0,0.6)'
|
||||||
ctx.fillRect(cx - tw / 2 - 6 / S.zoom, hintY, tw + 12 / S.zoom, 22 / S.zoom)
|
ctx.fillRect(cx - tw / 2 - 6 / viewScale(), hintY, tw + 12 / viewScale(), 22 / viewScale())
|
||||||
ctx.fillStyle = 'rgba(255,255,255,0.95)'
|
ctx.fillStyle = 'rgba(255,255,255,0.95)'
|
||||||
ctx.fillText(hintText, cx, hintY + 4 / S.zoom)
|
ctx.fillText(hintText, cx, hintY + 4 / viewScale())
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +183,7 @@ import { updateCursor } from './events.js'
|
|||||||
const rot = S.placingImage.rotation || 0
|
const rot = S.placingImage.rotation || 0
|
||||||
const cx = x + w / 2, cy = y + h / 2
|
const cx = x + w / 2, cy = y + h / 2
|
||||||
const lp = unrotPt(pos.x, pos.y, cx, cy, rot)
|
const lp = unrotPt(pos.x, pos.y, cx, cy, rot)
|
||||||
const R = 12 / S.zoom
|
const R = 12 / viewScale()
|
||||||
// 四角外侧圆弧 = 旋转手柄
|
// 四角外侧圆弧 = 旋转手柄
|
||||||
if (hitRotationHandle(lp, { x, y, w, h })) return 'rotate'
|
if (hitRotationHandle(lp, { x, y, w, h })) return 'rotate'
|
||||||
const pts = {
|
const pts = {
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/* recent-colors.js - 最近使用颜色(v1.9)
|
||||||
|
*
|
||||||
|
* 只依赖 state.js(叶子模块):tools.js 在改色时调用 rememberColor(),
|
||||||
|
* color pop 打开时 renderRecentColors() 把最近 8 个色块铺出来。
|
||||||
|
* 持久化走宿主 ctx.settings(小 KV,不放像素,符合宿主存储约定)。
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { S, runtime } from './state.js'
|
||||||
|
|
||||||
|
const MAX = 8
|
||||||
|
const KEY = 'recentColors'
|
||||||
|
|
||||||
|
function valid(hex) {
|
||||||
|
return /^#[0-9a-f]{6}$/i.test(String(hex || ''))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadRecentColors() {
|
||||||
|
const st = S.callbacks && S.callbacks.settings
|
||||||
|
let list = []
|
||||||
|
if (st && typeof st.get === 'function') {
|
||||||
|
try {
|
||||||
|
const got = st.get(KEY)
|
||||||
|
if (Array.isArray(got)) list = got
|
||||||
|
} catch (e) { /* 宿主 KV 不可用就当没有 */ }
|
||||||
|
}
|
||||||
|
S.recentColors = list.filter(valid).map(c => String(c).toLowerCase()).slice(0, MAX)
|
||||||
|
renderRecentColors()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 记一个颜色:去重后置顶,最多 8 个 */
|
||||||
|
export function rememberColor(hex) {
|
||||||
|
if (!valid(hex)) return
|
||||||
|
const c = String(hex).toLowerCase()
|
||||||
|
if (S.recentColors && S.recentColors[0] === c) return // 已经是最新,别每次重排
|
||||||
|
const list = [c].concat((S.recentColors || []).filter(x => x !== c))
|
||||||
|
S.recentColors = list.slice(0, MAX)
|
||||||
|
const st = S.callbacks && S.callbacks.settings
|
||||||
|
if (st && typeof st.set === 'function') {
|
||||||
|
try { st.set(KEY, S.recentColors) } catch (e) { /* 存不下就只在本次会话用 */ }
|
||||||
|
}
|
||||||
|
renderRecentColors()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function renderRecentColors() {
|
||||||
|
if (!runtime.el) return
|
||||||
|
// v1.16:右栏常驻面板与工具栏弹层各有一份,按集合刷
|
||||||
|
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
|
||||||
|
// v1.16:右栏给了一组加了「最近」小标题,没有最近色时整组一起藏,
|
||||||
|
// 否则标题下面留一块空白,看起来像没加载出来。
|
||||||
|
const group = wrap.closest('.iwb-color-group')
|
||||||
|
if (group) group.hidden = !list.length
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/* scale.js - 视图缩放换算(零依赖叶子模块,只读 S)
|
||||||
|
*
|
||||||
|
* 为什么单独成文件:这三个函数被 viewport / objects / layers / crop / selection /
|
||||||
|
* placement / events 共用,而 viewport 与 crop、objects、layers 之间存在**循环 import**。
|
||||||
|
* 把换算函数放在有循环的模块里,esbuild 打成 IIFE 后另一侧会拿到 undefined:
|
||||||
|
* 实测 clearOverlay 报 "resetOverlayTransform is not defined"(setupCanvas 调 clearOverlay,
|
||||||
|
* 此时 viewport 模块尚在求值中)。叶子模块没有反向依赖,任何时候都可用。
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { S } from './state.js'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视图缩放:**1 个图片像素 = 多少屏幕 CSS 像素**。
|
||||||
|
*
|
||||||
|
* ⚠️ 这不是 S.zoom。S.zoom 是「相对 fitW 的倍数」:图片适应窗口后 fitW ≠ imgW,
|
||||||
|
* 所以 zoom=1 时屏幕上每个图片像素只占 fitW/imgW 个 CSS 像素。
|
||||||
|
*
|
||||||
|
* 所有「屏幕上恒定大小」的界面元素(控制点、描边粗细、虚线间距、命中半径、
|
||||||
|
* 预览文字)都必须用 X / viewScale() 换算。直接写 X / S.zoom 会让实际屏幕尺寸
|
||||||
|
* 变成 X * fitW / imgW —— 只跟图片尺寸走、和缩放无关:
|
||||||
|
* 小图被放大铺满容器时 fitW/imgW 可达 4~8,控制点就会大得离谱;大图则缩成看不见。
|
||||||
|
*/
|
||||||
|
export function viewScale() {
|
||||||
|
return (S.imgW && S.fitW) ? (S.fitW * S.zoom) / S.imgW : 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* overlay 系列画布(选中框 / 蚂蚁线 / 笔刷环)的像素倍率。
|
||||||
|
*
|
||||||
|
* 这三张画布的像素缓冲原本就等于「图片尺寸 + padding」,CSS 再按 viewScale 拉伸显示。
|
||||||
|
* 小图被「适应窗口」放大 5~10 倍时缓冲严重不足,控制点、虚线全糊成一团发光点。
|
||||||
|
*
|
||||||
|
* 倍率只看适应窗口的基准比例(fitW / imgW,**不含 zoom**):拖动缩放不会改变它,
|
||||||
|
* 所以不会在缩放过程中反复重建 canvas。上限 4 是为内存 —— 缓冲面积按平方增长。
|
||||||
|
*/
|
||||||
|
export function overlayScale() {
|
||||||
|
const base = (S.imgW && S.fitW) ? S.fitW / S.imgW : 1
|
||||||
|
return Math.max(1, Math.min(4, base))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 把 ctx 重置到「图片坐标」基准:含 pad 偏移与 overlayScale 倍率。
|
||||||
|
* 清屏后必须用它恢复,否则后续绘制会按 1:1 铺到设备像素上、整体偏移。 */
|
||||||
|
export function resetOverlayTransform(cx) {
|
||||||
|
const k = overlayScale()
|
||||||
|
const pad = S.overlayPad || 0
|
||||||
|
cx.setTransform(k, 0, 0, k, pad * k, pad * k)
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
import { S } from './state.js'
|
import { S } from './state.js'
|
||||||
import { clamp, getPos } from './viewport.js'
|
import { clamp, getPos } from './viewport.js'
|
||||||
|
import { resetOverlayTransform, viewScale } from './scale.js'
|
||||||
import { clearOverlay } from './crop.js'
|
import { clearOverlay } from './crop.js'
|
||||||
import { defineCommand, runCommand, toast } from './commands.js'
|
import { defineCommand, runCommand, toast } from './commands.js'
|
||||||
import { createLayerCanvas, ensureWritableLayer, getActiveLayer, reorderLayerCanvas, setActiveLayer, updateLayerCanvasStyles } from './layers.js'
|
import { createLayerCanvas, ensureWritableLayer, getActiveLayer, reorderLayerCanvas, setActiveLayer, updateLayerCanvasStyles } from './layers.js'
|
||||||
@@ -32,23 +33,21 @@ import { createLayerCanvas, ensureWritableLayer, getActiveLayer, reorderLayerCan
|
|||||||
function clearSelectionCanvas() {
|
function clearSelectionCanvas() {
|
||||||
const ctx = S.selectionCtx
|
const ctx = S.selectionCtx
|
||||||
if (!ctx) return
|
if (!ctx) return
|
||||||
const pad = S.overlayPad || 0
|
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||||
ctx.clearRect(0, 0, S.imgW + pad * 2, S.imgH + pad * 2)
|
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
ctx.setTransform(1, 0, 0, 1, pad, pad)
|
resetOverlayTransform(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearCursorCanvas() {
|
export function clearCursorCanvas() {
|
||||||
const ctx = S.cursorCtx
|
const ctx = S.cursorCtx
|
||||||
if (!ctx) return
|
if (!ctx) return
|
||||||
const pad = S.overlayPad || 0
|
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||||
ctx.clearRect(0, 0, S.imgW + pad * 2, S.imgH + pad * 2)
|
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
ctx.setTransform(1, 0, 0, 1, pad, pad)
|
resetOverlayTransform(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 蚂蚁线:黑白两段错位的虚线,rAF 只重绘这一张小画布 */
|
/** 蚂蚁线:黑白两段错位的虚线,rAF 只重绘这一张小画布 */
|
||||||
@@ -56,7 +55,7 @@ import { createLayerCanvas, ensureWritableLayer, getActiveLayer, reorderLayerCan
|
|||||||
if (!S.selectionCtx) return
|
if (!S.selectionCtx) return
|
||||||
clearSelectionCanvas()
|
clearSelectionCanvas()
|
||||||
const ctx = S.selectionCtx
|
const ctx = S.selectionCtx
|
||||||
const k = 1 / Math.max(S.zoom, 0.0001)
|
const k = 1 / Math.max(viewScale(), 0.0001)
|
||||||
|
|
||||||
// 拉框 / 套索过程中:画预览,不画正式选区
|
// 拉框 / 套索过程中:画预览,不画正式选区
|
||||||
if (S.marquee || (S.lassoPts && S.lassoPts.length > 1)) {
|
if (S.marquee || (S.lassoPts && S.lassoPts.length > 1)) {
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/* snap.js - 拖动吸附与参考线(v1.9)
|
||||||
|
*
|
||||||
|
* 只做两件事:算「要不要吸、吸多少」,以及把参考线画出来。
|
||||||
|
* 不碰对象的写入 —— 调用方拿到 dx/dy 自己应用到 x/y,再在 render 里画线。
|
||||||
|
* 这样位图、文字、形状三种拖动可以共用同一套吸附,不会各写一遍阈值。
|
||||||
|
*
|
||||||
|
* 吸附目标:画布中线/四边 + 其它可见元素的左/中/右与上/中/下。
|
||||||
|
* 阈值按屏幕像素给(6px),换算成图片像素后再比较 —— 否则放大图片时
|
||||||
|
* 吸附范围会跟着放大到几十像素,鼠标还没靠近就被拽走。
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { S } from './state.js'
|
||||||
|
import { viewScale } from './scale.js'
|
||||||
|
|
||||||
|
/** 吸附触发距离(屏幕像素) */
|
||||||
|
export const SNAP_SCREEN_PX = 6
|
||||||
|
|
||||||
|
/** 参考线颜色:洋红,和选中框的橙色区分开 */
|
||||||
|
const GUIDE_COLOR = '#ff2d95'
|
||||||
|
|
||||||
|
function pushBox(targets, box) {
|
||||||
|
const x2 = box.x + box.w
|
||||||
|
const y2 = box.y + box.h
|
||||||
|
targets.x.push(box.x, box.x + box.w / 2, x2)
|
||||||
|
targets.y.push(box.y, box.y + box.h / 2, y2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 在候选线里找「离得最近且不超过阈值」的那条,返回需要平移的量 */
|
||||||
|
function nearest(targets, sources, tol, axis) {
|
||||||
|
let best = null
|
||||||
|
for (let i = 0; i < targets.length; i++) {
|
||||||
|
for (let j = 0; j < sources.length; j++) {
|
||||||
|
const delta = targets[i] - sources[j]
|
||||||
|
const abs = Math.abs(delta)
|
||||||
|
if (abs > tol) continue
|
||||||
|
if (!best || abs < Math.abs(best.delta)) best = { delta: delta, at: targets[i], axis: axis }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算吸附位移。
|
||||||
|
* @param {{x:number,y:number,w:number,h:number}} box 被拖元素的包围盒(已按指针位移算好,未吸附)
|
||||||
|
* @param {Array<{x:number,y:number,w:number,h:number}>} others 其它元素的包围盒
|
||||||
|
* @returns {{dx:number, dy:number, guides:Array}}
|
||||||
|
*/
|
||||||
|
export function snapMove(box, others) {
|
||||||
|
const tol = SNAP_SCREEN_PX / Math.max(0.02, viewScale())
|
||||||
|
const targets = { x: [0, S.imgW / 2, S.imgW], y: [0, S.imgH / 2, S.imgH] }
|
||||||
|
for (const o of others || []) {
|
||||||
|
if (!o || !isFinite(o.x) || !isFinite(o.y)) continue
|
||||||
|
pushBox(targets, o)
|
||||||
|
}
|
||||||
|
const sourcesX = [box.x, box.x + box.w / 2, box.x + box.w]
|
||||||
|
const sourcesY = [box.y, box.y + box.h / 2, box.y + box.h]
|
||||||
|
const gx = nearest(targets.x, sourcesX, tol, 'x')
|
||||||
|
const gy = nearest(targets.y, sourcesY, tol, 'y')
|
||||||
|
const guides = []
|
||||||
|
if (gx) guides.push(gx)
|
||||||
|
if (gy) guides.push(gy)
|
||||||
|
return { dx: gx ? gx.delta : 0, dy: gy ? gy.delta : 0, guides: guides }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 画参考线(贯穿整个画布 + overlay 外扩区,拖动时一眼看到对齐到哪) */
|
||||||
|
export function drawGuides(ctx, guides) {
|
||||||
|
if (!guides || !guides.length || !ctx) return
|
||||||
|
const scale = viewScale()
|
||||||
|
const pad = S.overlayPad || 0
|
||||||
|
ctx.save()
|
||||||
|
ctx.strokeStyle = GUIDE_COLOR
|
||||||
|
ctx.lineWidth = 1 / Math.max(0.02, scale)
|
||||||
|
ctx.setLineDash([6 / Math.max(0.02, scale), 4 / Math.max(0.02, scale)])
|
||||||
|
for (const g of guides) {
|
||||||
|
ctx.beginPath()
|
||||||
|
if (g.axis === 'x') {
|
||||||
|
ctx.moveTo(g.at, -pad)
|
||||||
|
ctx.lineTo(g.at, S.imgH + pad)
|
||||||
|
} else {
|
||||||
|
ctx.moveTo(-pad, g.at)
|
||||||
|
ctx.lineTo(S.imgW + pad, g.at)
|
||||||
|
}
|
||||||
|
ctx.stroke()
|
||||||
|
}
|
||||||
|
ctx.setLineDash([])
|
||||||
|
ctx.restore()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearGuides() {
|
||||||
|
if (!S.guides) return
|
||||||
|
S.guides = null
|
||||||
|
}
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
// text.js 是零依赖叶子模块,这里引它的默认值常量不会形成循环
|
||||||
|
import { TEXT_DEFAULTS } from './text.js'
|
||||||
|
|
||||||
export const ZOOM_MIN = 0.1
|
export const ZOOM_MIN = 0.1
|
||||||
export const ZOOM_MAX = 10
|
export const ZOOM_MAX = 10
|
||||||
export const ZOOM_STEP = 1.15
|
export const ZOOM_STEP = 1.15
|
||||||
@@ -33,12 +36,39 @@
|
|||||||
// 拖强度滑杆时一律从 source 重算,绝不在上一次结果上叠加(否则来回拖会越拖越糊)。
|
// 拖强度滑杆时一律从 source 重算,绝不在上一次结果上叠加(否则来回拖会越拖越糊)。
|
||||||
// layerId 用于判断源是否还对得上当前目标层:切层后滑杆自动置灰,切回即恢复。
|
// layerId 用于判断源是否还对得上当前目标层:切层后滑杆自动置灰,切回即恢复。
|
||||||
fx: { key: null, value: 0, layerId: null, source: null },
|
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, // 矩形/圆形是否实心填充
|
rectFill: false, // 矩形/圆形是否实心填充
|
||||||
penFill: true, // 钢笔闭合路径是否实心填充(只对闭合路径有意义)
|
penFill: true, // 钢笔闭合路径是否实心填充(只对闭合路径有意义)
|
||||||
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
||||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||||
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
||||||
|
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||||
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
|
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||||
|
shapeFillColor: null,
|
||||||
|
// v1.11:工具栏色板当前在调哪个颜色。描边与填充是同一个控件上的两个槽,
|
||||||
|
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
|
||||||
|
// 否则「三个地方各调各的颜色」会一直存在。
|
||||||
|
colorTarget: 'stroke', // stroke | fill
|
||||||
|
// v1.16:右侧栏宽度(px)。0 = 按默认值走,打开编辑器时从宿主 KV 恢复。
|
||||||
|
// 宽度统一落在 CSS 变量 --iwb-side-w 上,不再各条规则各写一个魔数。
|
||||||
|
sideWidth: 0,
|
||||||
textSize: 32, // 新建文字的字号 px
|
textSize: 32, // 新建文字的字号 px
|
||||||
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
|
textWeight: 'bold', // bold | normal | 900
|
||||||
|
textFamily: 'sans', // v1.14 字体预设 key:sans 黑体 | serif 宋体 | kai 楷体 | round 圆体
|
||||||
|
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
||||||
|
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
||||||
|
textStrokeWidth: TEXT_DEFAULTS.strokeWidth, // 描边宽度 px,0 = 无描边
|
||||||
|
textStrokeColor: TEXT_DEFAULTS.strokeColor,
|
||||||
|
textBgFill: TEXT_DEFAULTS.bgFill, // 底色块
|
||||||
|
textBgColor: TEXT_DEFAULTS.bgColor, // 中性近黑,不再是纯黑 #000000
|
||||||
|
textBgAlpha: TEXT_DEFAULTS.bgAlpha, // 底色透明度(色块按这个不透明度显示,所见即所得)
|
||||||
|
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
||||||
|
recentColors: [],
|
||||||
// 图层系统
|
// 图层系统
|
||||||
layers: [], // 位图图层数组 [{ id, name, canvas, ctx, opacity, visible, z }]
|
layers: [], // 位图图层数组 [{ id, name, canvas, ctx, opacity, visible, z }]
|
||||||
activeLayerId: null, // 当前活跃位图图层 ID(画笔/橡皮操作目标)
|
activeLayerId: null, // 当前活跃位图图层 ID(画笔/橡皮操作目标)
|
||||||
@@ -113,6 +143,11 @@
|
|||||||
exportOptions: null, // { preset, format, bg, maxKB, size },来自 ctx.settings
|
exportOptions: null, // { preset, format, bg, maxKB, size },来自 ctx.settings
|
||||||
interaction: 'idle', // 轻量交互状态机:idle | marquee | lasso | placing | cropping
|
interaction: 'idle', // 轻量交互状态机:idle | marquee | lasso | placing | cropping
|
||||||
renderAll: null, // 由 index.js 注入的统一重绘出口
|
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 }
|
lastExport: null // 观测口:{ bytes, width, height, format, preset }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,224 @@
|
|||||||
|
/* text.js - 文字的字体串、度量与绘制(v1.9)
|
||||||
|
*
|
||||||
|
* 为什么单独一个模块:文字要在两处画 —— 落层(layers.js#drawVectorToCanvas)与
|
||||||
|
* 预览/度量(objects.js)。两边各写一遍必然出现「量出来的框和画出来的字不一样」。
|
||||||
|
* 这里做成零依赖叶子模块(不 import 任何编辑器模块),objects.js 与 layers.js
|
||||||
|
* 都只往下依赖它,不会形成循环 import(esbuild 打成 IIFE 时循环 import 会拿到 undefined)。
|
||||||
|
*
|
||||||
|
* 坐标语义(与 v1.8 之前保持一致,勿随意改动):
|
||||||
|
* t.x / t.y 是「文字块」左上角;底色 padding 与描边从这一点向内/外扩展。
|
||||||
|
* 单行 + 无底色 + 无描边时,textBox() 与老版 textBounds() 完全相等(w=文字宽,h=fontSize×1.25)。
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
/** 默认行高倍数:必须等于老版的 fontSize×1.25,否则单行文字的选中框会变高 */
|
||||||
|
export const TEXT_LINE_HEIGHT = 1.25
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文字默认样式:**唯一的真相源**。
|
||||||
|
* 以前 '#ff4444' / '#ffffff' / '#000000' / 0.68 散落在 state.js、text.js、
|
||||||
|
* events.js 三处,改一处另两处不跟,界面上就会出现「同一个概念三种颜色」——
|
||||||
|
* 用户实测反馈「字体颜色有 3 个位置,那个黑色应该换成默认的参数」正是这么来的。
|
||||||
|
* 底色默认也不再是纯黑 #000000:纯黑在深色/花色底图上像抠了个洞,
|
||||||
|
* 而且和「文字色」看起来像是同一件事。改成中性近黑 #101014 + 68% 透明。
|
||||||
|
*/
|
||||||
|
export const TEXT_DEFAULTS = {
|
||||||
|
color: '#ff4444',
|
||||||
|
strokeWidth: 0,
|
||||||
|
strokeColor: '#ffffff',
|
||||||
|
bgFill: false,
|
||||||
|
bgColor: '#101014',
|
||||||
|
bgAlpha: 0.68
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 底色块相对字号的 padding 系数 */
|
||||||
|
const BG_PAD_RATIO = 0.3
|
||||||
|
|
||||||
|
let _measureCtx = null
|
||||||
|
|
||||||
|
/** 度量用的离屏 ctx:不依赖编辑器 DOM 是否已建好,避免 textBounds 在早期调用时抛错 */
|
||||||
|
function measureCtx() {
|
||||||
|
if (!_measureCtx) {
|
||||||
|
const c = document.createElement('canvas')
|
||||||
|
c.width = 8
|
||||||
|
c.height = 8
|
||||||
|
_measureCtx = c.getContext('2d')
|
||||||
|
}
|
||||||
|
return _measureCtx
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 字重:'bold' | 'normal' | '900' …(默认粗体,与老版一致) */
|
||||||
|
export function weightOf(t) {
|
||||||
|
const w = t && t.fontWeight
|
||||||
|
return w == null || w === '' ? 'bold' : String(w)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字体预设(v1.14):key → { label, stack }。
|
||||||
|
*
|
||||||
|
* 为什么只做「系统字体族」而不是内置字体文件:
|
||||||
|
* 1. 宿主 CSP 是 `default-src 'self'`,font-src 回落它,第三方字体 CDN 会被浏览器直接拦;
|
||||||
|
* 2. 中文字体动辄 2–64MB(本机宋体 2.3MB / 楷体 2.2MB / 苹方全字重 64MB),
|
||||||
|
* 插件产物现在才 389KB,内联等于体积涨 5–150 倍;
|
||||||
|
* 3. 系统字体同步可用,没有「字体没加载完就 measureText」导致框和字错位的时序问题。
|
||||||
|
* 每个 stack 都是跨平台候选队列:macOS 先命中苹方/宋体,Windows 命中雅黑/宋体,
|
||||||
|
* 全不命中时退到通用的 sans-serif / serif —— 永远不会渲染失败。
|
||||||
|
*
|
||||||
|
* 注意:中文是全角等宽,换字体不改字宽(实测 10 字 48px 在 6 种字体下都是 480px),
|
||||||
|
* 所以切换不会引起版面跳动;只有拉丁字母和数字会伸缩。
|
||||||
|
*/
|
||||||
|
export const TEXT_FONTS = {
|
||||||
|
sans: {
|
||||||
|
label: '黑体',
|
||||||
|
stack: '"PingFang SC", "Microsoft YaHei", "Heiti SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans SC", sans-serif'
|
||||||
|
},
|
||||||
|
serif: {
|
||||||
|
label: '宋体',
|
||||||
|
stack: '"Songti SC", "SimSun", "STSong", "Source Han Serif SC", "Noto Serif SC", serif'
|
||||||
|
},
|
||||||
|
kai: {
|
||||||
|
label: '楷体',
|
||||||
|
stack: '"Kaiti SC", "KaiTi", "STKaiti", "AR PL UKai CN", "Noto Serif SC", serif'
|
||||||
|
},
|
||||||
|
round: {
|
||||||
|
label: '圆体',
|
||||||
|
stack: '"Yuanti SC", "YouYuan", "STYuanti", "PingFang SC", sans-serif'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TEXT_FONT_KEYS = ['sans', 'serif', 'kai', 'round']
|
||||||
|
export const TEXT_FONT_DEFAULT = 'sans'
|
||||||
|
|
||||||
|
/** 把任意输入收敛成已知的字体 key:老对象没有 fontFamily、或存了脏值,都回退到默认 */
|
||||||
|
export function fontKeyOf(t) {
|
||||||
|
const k = t && t.fontFamily
|
||||||
|
return TEXT_FONTS[k] ? k : TEXT_FONT_DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 字体栈串(不含字号字重),选项栏下拉与预览都用它 */
|
||||||
|
export function fontStackOf(t) {
|
||||||
|
return TEXT_FONTS[fontKeyOf(t)].stack
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fontOf(t) {
|
||||||
|
const size = Math.max(4, Number(t && t.fontSize) || 32)
|
||||||
|
return weightOf(t) + ' ' + size + 'px ' + fontStackOf(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 文字的排布度量:分行、每行宽度、行高、底色 padding、描边宽度 */
|
||||||
|
export function textMetrics(t) {
|
||||||
|
const ctx = measureCtx()
|
||||||
|
const font = fontOf(t)
|
||||||
|
ctx.font = font
|
||||||
|
const raw = (t && t.text) == null ? '' : String(t.text)
|
||||||
|
const lines = raw.split('\n')
|
||||||
|
const widths = lines.map(line => ctx.measureText(line).width)
|
||||||
|
const size = Math.max(4, Number(t && t.fontSize) || 32)
|
||||||
|
const lh = size * (Number(t && t.lineHeight) || TEXT_LINE_HEIGHT)
|
||||||
|
const w = lines.length ? Math.max.apply(null, widths) : 0
|
||||||
|
const pad = t && t.bgFill ? Math.round(size * BG_PAD_RATIO) : 0
|
||||||
|
const sw = Math.max(0, Number(t && t.strokeWidth) || 0)
|
||||||
|
return { lines, widths, w, h: lh * lines.length, lh, pad, sw, font, size }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 包围盒(图片坐标):含底色 padding 与描边向外扩出的一半 */
|
||||||
|
export function textBox(t) {
|
||||||
|
const m = textMetrics(t)
|
||||||
|
const half = m.sw / 2
|
||||||
|
return {
|
||||||
|
x: t.x - half,
|
||||||
|
y: t.y - half,
|
||||||
|
w: Math.max(m.w, 2) + m.pad * 2 + m.sw,
|
||||||
|
h: Math.max(m.h, 1) + m.pad * 2 + m.sw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function alignOf(t) {
|
||||||
|
const a = t && t.align
|
||||||
|
return a === 'center' || a === 'right' ? a : 'left'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 画一段文字(含底色块、描边、多行、旋转)。
|
||||||
|
* 底色块与描边都按「块」来画:底色覆盖整块,描边沿字形外沿。
|
||||||
|
*/
|
||||||
|
export function drawTextObject(ctx, t) {
|
||||||
|
const m = textMetrics(t)
|
||||||
|
ctx.save()
|
||||||
|
ctx.textBaseline = 'top'
|
||||||
|
ctx.globalAlpha = t.opacity != null ? t.opacity : 1
|
||||||
|
const b = textBox(t)
|
||||||
|
const rot = t.rotation || 0
|
||||||
|
if (rot) {
|
||||||
|
const cx = b.x + b.w / 2
|
||||||
|
const cy = b.y + b.h / 2
|
||||||
|
ctx.translate(cx, cy)
|
||||||
|
ctx.rotate(rot * Math.PI / 180)
|
||||||
|
ctx.translate(-cx, -cy)
|
||||||
|
}
|
||||||
|
ctx.font = m.font
|
||||||
|
const align = alignOf(t)
|
||||||
|
const boxW = m.w + m.pad * 2
|
||||||
|
|
||||||
|
// 底色块:先于文字画,圆角按字号比例给一点(纯直角贴小字会很硬)
|
||||||
|
if (t.bgFill) {
|
||||||
|
const r = Math.min(m.pad + 2, Math.min(boxW, m.h + m.pad * 2) / 2)
|
||||||
|
// 0.55 在浅色/花色底图上偏透,用户容易以为「底色没生效」;0.68 既压得住底图,
|
||||||
|
// 也还看得见一点背景,是「垫一块板让字立起来」的常用手感。
|
||||||
|
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : t.bgAlpha)
|
||||||
|
ctx.fillStyle = t.bgColor || TEXT_DEFAULTS.bgColor
|
||||||
|
const bx = t.x, by = t.y
|
||||||
|
const bw = boxW, bh = m.h + m.pad * 2
|
||||||
|
ctx.beginPath()
|
||||||
|
if (typeof ctx.roundRect === 'function') {
|
||||||
|
ctx.roundRect(bx, by, bw, bh, r)
|
||||||
|
} else {
|
||||||
|
ctx.moveTo(bx + r, by)
|
||||||
|
ctx.arcTo(bx + bw, by, bx + bw, by + bh, r)
|
||||||
|
ctx.arcTo(bx + bw, by + bh, bx, by + bh, r)
|
||||||
|
ctx.arcTo(bx, by + bh, bx, by, r)
|
||||||
|
ctx.arcTo(bx, by, bx + bw, by, r)
|
||||||
|
ctx.closePath()
|
||||||
|
}
|
||||||
|
ctx.fill()
|
||||||
|
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对齐以「块内可用宽度(不含 padding)」为基准:多行时各行按这个宽度对齐
|
||||||
|
ctx.textAlign = align
|
||||||
|
const left = t.x + m.pad
|
||||||
|
const ox = align === 'center' ? left + m.w / 2 : align === 'right' ? left + m.w : left
|
||||||
|
|
||||||
|
ctx.lineJoin = 'round'
|
||||||
|
ctx.miterLimit = 2
|
||||||
|
for (let i = 0; i < m.lines.length; i++) {
|
||||||
|
const y = t.y + m.pad + i * m.lh
|
||||||
|
if (m.sw > 0) {
|
||||||
|
ctx.lineWidth = m.sw
|
||||||
|
ctx.strokeStyle = t.strokeColor || TEXT_DEFAULTS.strokeColor
|
||||||
|
ctx.strokeText(m.lines[i], ox, y)
|
||||||
|
}
|
||||||
|
ctx.fillStyle = t.color || TEXT_DEFAULTS.color
|
||||||
|
ctx.fillText(m.lines[i], ox, y)
|
||||||
|
}
|
||||||
|
ctx.restore()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从默认样式造一段文字的字段(新建文字 / 老对象补默认值共用) */
|
||||||
|
export function newTextStyle(src) {
|
||||||
|
const s = src || {}
|
||||||
|
return {
|
||||||
|
fontWeight: weightOf(s),
|
||||||
|
// 字体 key 过一遍收敛:外部传进来不认识的字符串不会进 ctx.font(脏值会让整个
|
||||||
|
// 字体串失效、静默退回浏览器默认,文件本身看不出问题,极难排查)
|
||||||
|
fontFamily: fontKeyOf(s),
|
||||||
|
align: alignOf(s),
|
||||||
|
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
||||||
|
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
||||||
|
strokeColor: s.strokeColor || TEXT_DEFAULTS.strokeColor,
|
||||||
|
bgFill: !!s.bgFill,
|
||||||
|
bgColor: s.bgColor || TEXT_DEFAULTS.bgColor,
|
||||||
|
bgAlpha: s.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : Number(s.bgAlpha)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,11 +12,13 @@ import { commitTextInput, getSelectedShape, getSelectedText, layerUnits, renderO
|
|||||||
import { cancelCrop, clearOverlay, hideCropBar, showCropBar, updateCropInfo } from './crop.js'
|
import { cancelCrop, clearOverlay, hideCropBar, showCropBar, updateCropInfo } from './crop.js'
|
||||||
import { cancelImagePlacement } from './placement.js'
|
import { cancelImagePlacement } from './placement.js'
|
||||||
import { clamp } from './viewport.js'
|
import { clamp } from './viewport.js'
|
||||||
|
import { resetOverlayTransform } from './scale.js'
|
||||||
import { getActiveCtx, getActiveLayer, renderLayerPanel } from './layers.js'
|
import { getActiveCtx, getActiveLayer, renderLayerPanel } from './layers.js'
|
||||||
import { saveSnapshot } from './history.js'
|
import { saveSnapshot } from './history.js'
|
||||||
import { updateBrushParamUI, updateColorUI, updateToolUI } from './events.js'
|
import { updateBrushParamUI, updateColorUI, updateToolUI } from './events.js'
|
||||||
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||||
import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
||||||
|
import { rememberColor } from './recent-colors.js'
|
||||||
|
|
||||||
|
|
||||||
// ============ 绘制工具 ============
|
// ============ 绘制工具 ============
|
||||||
@@ -159,7 +161,31 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
|||||||
S.pickerComposite = null
|
S.pickerComposite = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 圆角半径:夹在短边一半以内,避免圆角把矩形吃掉变胶囊/消失 */
|
||||||
|
function roundedRadius(s, w, h) {
|
||||||
|
const r = Number(s && s.radius) || 0
|
||||||
|
if (r <= 0) return 0
|
||||||
|
return Math.min(r, Math.min(w, h) / 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 圆角矩形路径:不用 ctx.roundRect(老浏览器没有),手写 arcs,行为可控 */
|
||||||
|
function roundRectPath(ctx, x, y, w, h, r) {
|
||||||
|
const rr = Math.min(r, Math.min(w, h) / 2)
|
||||||
|
ctx.moveTo(x + rr, y)
|
||||||
|
ctx.arcTo(x + w, y, x + w, y + h, rr)
|
||||||
|
ctx.arcTo(x + w, y + h, x, y + h, rr)
|
||||||
|
ctx.arcTo(x, y + h, x, y, rr)
|
||||||
|
ctx.arcTo(x, y, x + w, y, rr)
|
||||||
|
ctx.closePath()
|
||||||
|
}
|
||||||
|
|
||||||
/** 按形状对象绘制(矩形/箭头),预览与最终渲染共用 */
|
/** 按形状对象绘制(矩形/箭头),预览与最终渲染共用 */
|
||||||
|
/** 形状描边色:每个形状自己存 color(v1.10 起选项栏可单独调) */
|
||||||
|
export function strokeOf(s) { return (s && s.color) || S.color }
|
||||||
|
|
||||||
|
/** 形状填充色:自己设过 fillColor 就用它,否则跟随描边色(同色实心是默认手感) */
|
||||||
|
export function fillOf(s) { return (s && s.fillColor) || strokeOf(s) }
|
||||||
|
|
||||||
export function drawShape(ctx, s) {
|
export function drawShape(ctx, s) {
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.globalAlpha = s.opacity != null ? s.opacity : 1
|
ctx.globalAlpha = s.opacity != null ? s.opacity : 1
|
||||||
@@ -171,26 +197,34 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
|||||||
ctx.rotate(rot * Math.PI / 180)
|
ctx.rotate(rot * Math.PI / 180)
|
||||||
ctx.translate(-cx, -cy)
|
ctx.translate(-cx, -cy)
|
||||||
}
|
}
|
||||||
ctx.strokeStyle = s.color
|
ctx.strokeStyle = strokeOf(s)
|
||||||
ctx.lineWidth = s.lw
|
ctx.lineWidth = s.lw
|
||||||
ctx.lineCap = 'round'
|
ctx.lineCap = 'round'
|
||||||
ctx.lineJoin = 'round'
|
ctx.lineJoin = 'round'
|
||||||
if (s.type === 'pen') {
|
if (s.type === 'pen') {
|
||||||
const pts = Array.isArray(s.pts) ? s.pts : []
|
const pts = Array.isArray(s.pts) ? s.pts : []
|
||||||
if (pts.length > 1) { ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y); for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); if (s.closed) ctx.closePath(); if (s.closed && s.fill) { ctx.fillStyle = s.color; ctx.fill() } ctx.stroke() }
|
if (pts.length > 1) { ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y); for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); if (s.closed) ctx.closePath(); if (s.closed && s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() } ctx.stroke() }
|
||||||
} else if (s.type === 'rect') {
|
} else if (s.type === 'rect') {
|
||||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
||||||
if (s.fill) { ctx.fillStyle = s.color; ctx.fillRect(rx, ry, rw, rh) }
|
const radius = roundedRadius(s, rw, rh)
|
||||||
ctx.strokeRect(rx, ry, rw, rh)
|
if (radius > 0) {
|
||||||
|
ctx.beginPath()
|
||||||
|
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
||||||
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
|
ctx.stroke()
|
||||||
|
} else {
|
||||||
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fillRect(rx, ry, rw, rh) }
|
||||||
|
ctx.strokeRect(rx, ry, rw, rh)
|
||||||
|
}
|
||||||
} else if (s.type === 'circle') {
|
} else if (s.type === 'circle') {
|
||||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2)
|
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2)
|
||||||
const rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
const rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2)
|
ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2)
|
||||||
if (s.fill) { ctx.fillStyle = s.color; ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
} else {
|
} else {
|
||||||
ctx.fillStyle = s.color
|
ctx.fillStyle = strokeOf(s)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(s.x1, s.y1)
|
ctx.moveTo(s.x1, s.y1)
|
||||||
ctx.lineTo(s.x2, s.y2)
|
ctx.lineTo(s.x2, s.y2)
|
||||||
@@ -222,12 +256,11 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
|||||||
export function clearToolRing() {
|
export function clearToolRing() {
|
||||||
const ctx = S.cursorCtx
|
const ctx = S.cursorCtx
|
||||||
if (!ctx) return
|
if (!ctx) return
|
||||||
const pad = S.overlayPad || 0
|
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||||
ctx.clearRect(0, 0, S.imgW + pad * 2, S.imgH + pad * 2)
|
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
ctx.setTransform(1, 0, 0, 1, pad, pad)
|
resetOverlayTransform(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 圆形笔刷光标:画在独立 cursorCanvas,避免 clearOverlay() 擦掉其它交互层 */
|
/** 圆形笔刷光标:画在独立 cursorCanvas,避免 clearOverlay() 擦掉其它交互层 */
|
||||||
@@ -380,6 +413,9 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
|
|||||||
export function applyColorChange(color, opts) {
|
export function applyColorChange(color, opts) {
|
||||||
const skipHistory = !!(opts && opts.skipHistory)
|
const skipHistory = !!(opts && opts.skipHistory)
|
||||||
S.color = color
|
S.color = color
|
||||||
|
// 只有「确认型」改色才进最近使用:拖 SV 时 skipHistory=true 每帧都调,
|
||||||
|
// 全记进去会把最近色刷成一串相邻色,毫无用处。
|
||||||
|
if (!skipHistory) rememberColor(color)
|
||||||
updateColorUI()
|
updateColorUI()
|
||||||
const t = getSelectedText()
|
const t = getSelectedText()
|
||||||
if (t && !t.locked && t.color !== S.color) {
|
if (t && !t.locked && t.color !== S.color) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
import { S, ZOOM_MAX, ZOOM_MIN } from './state.js'
|
import { S, ZOOM_MAX, ZOOM_MIN } from './state.js'
|
||||||
|
import { overlayScale, resetOverlayTransform, viewScale } from './scale.js'
|
||||||
import { bindCanvasEvents, updateZoomUI } from './events.js'
|
import { bindCanvasEvents, updateZoomUI } from './events.js'
|
||||||
import { clearOverlay } from './crop.js'
|
import { clearOverlay } from './crop.js'
|
||||||
import { createLayerCanvas, purgeVectorCanvases, renderLayerPanel, styleVectorViewport } from './layers.js'
|
import { createLayerCanvas, purgeVectorCanvases, renderLayerPanel, styleVectorViewport } from './layers.js'
|
||||||
@@ -46,11 +47,14 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
|||||||
S.strokeCanvas.style.display = 'none'
|
S.strokeCanvas.style.display = 'none'
|
||||||
// 裁剪越界区域属于交互工作区,不改变图片本身的画布尺寸。
|
// 裁剪越界区域属于交互工作区,不改变图片本身的画布尺寸。
|
||||||
S.overlayPad = Math.max(96, Math.ceil(Math.max(S.imgW, S.imgH) * 0.18))
|
S.overlayPad = Math.max(96, Math.ceil(Math.max(S.imgW, S.imgH) * 0.18))
|
||||||
|
// overlayScale 依赖 fitW,必须先算出适应尺寸再建交互层缓冲
|
||||||
|
computeFit()
|
||||||
|
const uiK = overlayScale()
|
||||||
for (const [c, cx] of [[S.overlayCanvas, S.overlayCtx], [S.selectionCanvas, S.selectionCtx], [S.cursorCanvas, S.cursorCtx]]) {
|
for (const [c, cx] of [[S.overlayCanvas, S.overlayCtx], [S.selectionCanvas, S.selectionCtx], [S.cursorCanvas, S.cursorCtx]]) {
|
||||||
if (!c || !cx) continue
|
if (!c || !cx) continue
|
||||||
c.width = S.imgW + S.overlayPad * 2
|
c.width = Math.round((S.imgW + S.overlayPad * 2) * uiK)
|
||||||
c.height = S.imgH + S.overlayPad * 2
|
c.height = Math.round((S.imgH + S.overlayPad * 2) * uiK)
|
||||||
cx.setTransform(1, 0, 0, 1, S.overlayPad, S.overlayPad)
|
resetOverlayTransform(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建图层 1: 原图
|
// 创建图层 1: 原图
|
||||||
@@ -82,7 +86,6 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
|||||||
|
|
||||||
renderObjects()
|
renderObjects()
|
||||||
|
|
||||||
computeFit()
|
|
||||||
S.viewX = null
|
S.viewX = null
|
||||||
applyView()
|
applyView()
|
||||||
renderLayerPanel()
|
renderLayerPanel()
|
||||||
@@ -108,11 +111,13 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
|||||||
S.strokeCanvas.width = S.imgW
|
S.strokeCanvas.width = S.imgW
|
||||||
S.strokeCanvas.height = S.imgH
|
S.strokeCanvas.height = S.imgH
|
||||||
S.overlayPad = Math.max(96, Math.ceil(Math.max(S.imgW, S.imgH) * 0.18))
|
S.overlayPad = Math.max(96, Math.ceil(Math.max(S.imgW, S.imgH) * 0.18))
|
||||||
|
computeFit()
|
||||||
|
const uiK = overlayScale()
|
||||||
for (const [c, cx] of [[S.overlayCanvas, S.overlayCtx], [S.selectionCanvas, S.selectionCtx], [S.cursorCanvas, S.cursorCtx]]) {
|
for (const [c, cx] of [[S.overlayCanvas, S.overlayCtx], [S.selectionCanvas, S.selectionCtx], [S.cursorCanvas, S.cursorCtx]]) {
|
||||||
if (!c || !cx) continue
|
if (!c || !cx) continue
|
||||||
c.width = S.imgW + S.overlayPad * 2
|
c.width = Math.round((S.imgW + S.overlayPad * 2) * uiK)
|
||||||
c.height = S.imgH + S.overlayPad * 2
|
c.height = Math.round((S.imgH + S.overlayPad * 2) * uiK)
|
||||||
cx.setTransform(1, 0, 0, 1, S.overlayPad, S.overlayPad)
|
resetOverlayTransform(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
purgeVectorCanvases()
|
purgeVectorCanvases()
|
||||||
@@ -124,7 +129,6 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
|||||||
|
|
||||||
S.pickerComposite = null
|
S.pickerComposite = null
|
||||||
clearOverlay()
|
clearOverlay()
|
||||||
computeFit()
|
|
||||||
S.viewX = null
|
S.viewX = null
|
||||||
applyView()
|
applyView()
|
||||||
renderObjects()
|
renderObjects()
|
||||||
@@ -238,6 +242,18 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
|||||||
|
|
||||||
export function clamp(v, min, max) { return Math.max(min, Math.min(max, v)) }
|
export function clamp(v, min, max) { return Math.max(min, Math.min(max, v)) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视图缩放:**1 个图片像素 = 多少屏幕 CSS 像素**。
|
||||||
|
*
|
||||||
|
* ⚠️ 这不是 S.zoom。S.zoom 是「相对 fitW 的倍数」:图片适应窗口后 fitW ≠ imgW,
|
||||||
|
* 所以 zoom=1 时屏幕上每个图片像素只占 fitW/imgW 个 CSS 像素。
|
||||||
|
*
|
||||||
|
* 所有「屏幕上恒定大小」的界面元素(控制点、描边粗细、虚线间距、命中半径、
|
||||||
|
* 预览文字)都必须用 X / viewScale() 换算。直接写 X / S.zoom 会让实际屏幕尺寸
|
||||||
|
* 变成 X * fitW / imgW —— 只跟图片尺寸走、和缩放无关:
|
||||||
|
* 小图被放大铺满容器时 fitW/imgW 可达 4~8,控制点就会大得离谱;大图则缩成看不见。
|
||||||
|
*/
|
||||||
|
|
||||||
// ============ 旋转辅助 ============
|
// ============ 旋转辅助 ============
|
||||||
export function rotPt(px, py, cx, cy, deg) {
|
export function rotPt(px, py, cx, cy, deg) {
|
||||||
if (!deg) return [px, py]
|
if (!deg) return [px, py]
|
||||||
@@ -251,7 +267,8 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
|||||||
/** 旋转手柄:四个角沿对角线向外偏移(局部坐标) */
|
/** 旋转手柄:四个角沿对角线向外偏移(局部坐标) */
|
||||||
function rotationHandlesLocal(b) {
|
function rotationHandlesLocal(b) {
|
||||||
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
||||||
const d = 26 / Math.max(S.zoom, 0.0001)
|
// 26 屏幕像素的间距,换算成图片单位(不能除以 S.zoom,否则随图片尺寸漂移)
|
||||||
|
const d = 26 / Math.max(viewScale(), 0.0001)
|
||||||
return [[b.x, b.y], [b.x + b.w, b.y], [b.x + b.w, b.y + b.h], [b.x, b.y + b.h]].map(c => {
|
return [[b.x, b.y], [b.x + b.w, b.y], [b.x + b.w, b.y + b.h], [b.x, b.y + b.h]].map(c => {
|
||||||
const dx = c[0] - cx, dy = c[1] - cy, len = Math.hypot(dx, dy) || 1
|
const dx = c[0] - cx, dy = c[1] - cy, len = Math.hypot(dx, dy) || 1
|
||||||
return [c[0] + dx / len * d, c[1] + dy / len * d]
|
return [c[0] + dx / len * d, c[1] + dy / len * d]
|
||||||
@@ -260,7 +277,9 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
|||||||
/** 命中旋转手柄(传局部坐标点) */
|
/** 命中旋转手柄(传局部坐标点) */
|
||||||
export function hitRotationHandle(lp, b) {
|
export function hitRotationHandle(lp, b) {
|
||||||
const pts = rotationHandlesLocal(b)
|
const pts = rotationHandlesLocal(b)
|
||||||
const R = Math.max(11 / Math.max(S.zoom, 0.0001), 8)
|
// 11 屏幕像素的命中半径。原先用 Math.max(..., 8) 托底,但托底值是图片单位,
|
||||||
|
// 放大显示时会变成巨大的屏幕命中区(误触),故只按 viewScale 换算。
|
||||||
|
const R = 11 / Math.max(viewScale(), 0.0001)
|
||||||
for (const pt of pts) {
|
for (const pt of pts) {
|
||||||
if (Math.hypot(lp[0] - pt[0], lp[1] - pt[1]) < R) return true
|
if (Math.hypot(lp[0] - pt[0], lp[1] - pt[1]) < R) return true
|
||||||
}
|
}
|
||||||
@@ -270,10 +289,10 @@ import { getSelectedShape, getSelectedText, renderObjects, shapeBounds, textBoun
|
|||||||
export function drawRotationHandles(ctx, b, rot) {
|
export function drawRotationHandles(ctx, b, rot) {
|
||||||
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
const cx = b.x + b.w / 2, cy = b.y + b.h / 2
|
||||||
const pts = rotationHandlesLocal(b)
|
const pts = rotationHandlesLocal(b)
|
||||||
const k = Math.max(S.zoom, 0.0001)
|
const k = Math.max(viewScale(), 0.0001)
|
||||||
const r = Math.max(6.5 / k, 5)
|
const r = 6.5 / k
|
||||||
const lw = 1.5 / k
|
const lw = 1.5 / k
|
||||||
const ah = Math.max(3 / k, 2.6) // 箭头长度
|
const ah = 3 / k // 箭头长度
|
||||||
const A0 = Math.PI * 0.2, A1 = Math.PI * 1.72
|
const A0 = Math.PI * 0.2, A1 = Math.PI * 1.72
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.strokeStyle = '#f0b34e'
|
ctx.strokeStyle = '#f0b34e'
|
||||||
|
|||||||
+4267
-336
File diff suppressed because it is too large.
Load diff
@@ -176,20 +176,108 @@ if (!SKIP_PASTE) {
|
|||||||
check('点击「截图+图形」重叠区选中最上层截图(不被下方图形抢走)',
|
check('点击「截图+图形」重叠区选中最上层截图(不被下方图形抢走)',
|
||||||
Boolean(activeItem && activeItem.type === 'bitmap' && /图层/.test(activeItem.name)), JSON.stringify(activeItem))
|
Boolean(activeItem && activeItem.type === 'bitmap' && /图层/.test(activeItem.name)), JSON.stringify(activeItem))
|
||||||
|
|
||||||
|
// v1.13 起顶栏四个层级按钮已删除(改为图层拖动 + Ctrl+]/[ 快捷键),
|
||||||
|
// 这里改为断言「按钮确实没了」+ 用快捷键验证排序仍然可用。
|
||||||
|
check('顶栏不再有层级排序按钮(改用图层拖动 + Ctrl+]/[)',
|
||||||
|
(await page.locator('.iwb-editor-layer-btn').count()) === 0 &&
|
||||||
|
(await page.locator('.iwb-editor-header .iwb-editor-commands').count()) === 0,
|
||||||
|
'layerBtn=' + await page.locator('.iwb-editor-layer-btn').count())
|
||||||
|
|
||||||
|
const toolsTail = await page.evaluate(() => Array.from(document.querySelectorAll('.iwb-editor-tools > *'))
|
||||||
|
.slice(-2).map((n) => n.dataset.action || n.className))
|
||||||
|
check('工具栏最右两个按钮是「适应窗口 / 收起侧栏」',
|
||||||
|
JSON.stringify(toolsTail) === JSON.stringify(['zoomFit', 'togglePanels']), JSON.stringify(toolsTail))
|
||||||
|
|
||||||
const before = await panelSeq()
|
const before = await panelSeq()
|
||||||
await page.locator('.iwb-editor-layer-btn[data-layer="down"]').click()
|
const activeName = await page.evaluate(() => document.querySelector('.iwb-editor-layer-list .iwb-layer-item.active .iwb-layer-name')?.textContent)
|
||||||
|
await page.keyboard.press('Control+[') // 下移一层
|
||||||
const afterDown = await panelSeq()
|
const afterDown = await panelSeq()
|
||||||
check('「下移一层」改变图层顺序', before !== afterDown, before + ' → ' + afterDown)
|
check('Ctrl+[ 下移一层改变图层顺序', before !== afterDown, before + ' → ' + afterDown)
|
||||||
await page.locator('.iwb-editor-layer-btn[data-layer="up"]').click()
|
await page.keyboard.press('Control+]') // 上移一层
|
||||||
check('「上移一层」恢复原顺序', (await panelSeq()) === before, await panelSeq())
|
check('Ctrl+] 上移一层恢复原顺序', (await panelSeq()) === before, await panelSeq())
|
||||||
await page.locator('.iwb-editor-layer-btn[data-layer="bottom"]').click()
|
|
||||||
|
await page.keyboard.press('Control+Shift+[') // 置底
|
||||||
const afterBottom = await panelSeq()
|
const afterBottom = await panelSeq()
|
||||||
check('「置底」生效且原图仍在最底(元素不会消失)',
|
check('Ctrl+Shift+[ 置底生效(元素不会消失)',
|
||||||
afterBottom !== before && afterBottom.endsWith('原图'), afterBottom)
|
afterBottom !== before && afterBottom.endsWith(String(activeName)), afterBottom)
|
||||||
await page.locator('.iwb-editor-layer-btn[data-layer="top"]').click()
|
check('置底后原图不再被钉在最底 —— 图层可以压到原图下面(v1.13 解封)',
|
||||||
check('「置顶」生效', (await panelSeq()) !== afterBottom, await panelSeq())
|
!afterBottom.endsWith('原图'), afterBottom)
|
||||||
|
await page.keyboard.press('Control+Shift+]') // 置顶
|
||||||
|
check('Ctrl+Shift+] 置顶生效', (await panelSeq()) !== afterBottom, await panelSeq())
|
||||||
check('排序后仍只有一个选中项', (await activeCount()) === 1, 'active=' + await activeCount())
|
check('排序后仍只有一个选中项', (await activeCount()) === 1, 'active=' + await activeCount())
|
||||||
|
|
||||||
|
// v1.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.16:右栏常驻调色面板 + 可拖宽度。真站里 DOM 与 CSS 是分别打包的,
|
||||||
|
// 只验面板在不在、拖宽后宽度有没有真的变 —— 样式漏打包时这里会直接露出来。
|
||||||
|
const sideColor = await page.evaluate(() => {
|
||||||
|
const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]')
|
||||||
|
if (!side) return null
|
||||||
|
return {
|
||||||
|
tabs: side.querySelectorAll('.iwb-color-pop-tab').length,
|
||||||
|
swatches: side.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]').length,
|
||||||
|
sv: !!side.querySelector('.iwb-color-sv')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('右栏常驻调色面板(色格切换 + 调色器 + 12 个常用色)',
|
||||||
|
Boolean(sideColor) && sideColor.tabs === 3 && sideColor.swatches === 12 && sideColor.sv,
|
||||||
|
JSON.stringify(sideColor))
|
||||||
|
|
||||||
|
const sideBefore = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||||
|
const sideGrip = await page.locator('.iwb-editor-side-resizer').boundingBox()
|
||||||
|
if (sideGrip) {
|
||||||
|
await page.mouse.move(sideGrip.x + 3, sideGrip.y + 120)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(sideGrip.x + 3 - 70, sideGrip.y + 120, { steps: 6 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await page.waitForTimeout(180)
|
||||||
|
}
|
||||||
|
const sideAfter = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||||
|
check('右栏可以拖宽(不再固定 220)', sideAfter >= sideBefore + 60, sideBefore + ' → ' + sideAfter)
|
||||||
|
await page.locator('.iwb-editor-side-resizer').dblclick()
|
||||||
|
await page.waitForTimeout(150)
|
||||||
|
|
||||||
|
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
||||||
|
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
||||||
|
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||||||
|
const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]'
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||||||
|
const famBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||||||
|
await page.mouse.click(famBox.x + 60, famBox.y + 60)
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-text-input')
|
||||||
|
if (!el) return
|
||||||
|
el.focus()
|
||||||
|
el.value = '字体测试'
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.keyboard.press('Enter')
|
||||||
|
await page.waitForTimeout(400)
|
||||||
|
|
||||||
|
const famOpts = await page.locator(FAM_SEL + ' option').allTextContents()
|
||||||
|
check('真站选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体',
|
||||||
|
famOpts.length === 4, JSON.stringify(famOpts))
|
||||||
|
|
||||||
|
const wSans = ((await famDbg()).texts.find((t) => t.text === '字体测试') || {}).box
|
||||||
|
await page.selectOption(FAM_SEL, 'serif')
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const tSerif = (await famDbg()).texts.find((t) => t.text === '字体测试')
|
||||||
|
check('真站切换宋体生效,且中文宽度不变(全角等宽,版面不跳动)',
|
||||||
|
Boolean(tSerif && tSerif.fontFamily === 'serif' && wSans && Math.abs(tSerif.box.w - wSans.w) <= 1),
|
||||||
|
(wSans ? wSans.w : '?') + ' → ' + (tSerif ? tSerif.box.w : '?'))
|
||||||
|
await page.keyboard.press('Delete')
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
|
||||||
// 复原成画笔工具,避免影响后面「覆盖」链路的画笔取样
|
// 复原成画笔工具,避免影响后面「覆盖」链路的画笔取样
|
||||||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||||||
}
|
}
|
||||||
|
|||||||
+1334
-33
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user