Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3baa76d0cd | ||
|
|
a477705c7f |
No files matched your search
@@ -234,6 +234,84 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||
|
||||
## v1.17.0:描边也能是「无色」+ 一边无色时 Shift+X 照样交换
|
||||
|
||||
用户两句话:「让矢量图形与钢笔的描边色也可以去掉」「描边与填充有一个是无色的时候可以交换,
|
||||
现在是不可以的」。
|
||||
|
||||
### 描边的第三态
|
||||
|
||||
以前描边只有「什么颜色」,没有「有没有」。现在形状对象多一个 `strokeOn`(缺省 = 有,
|
||||
老对象与历史快照没有这个字段一律当有描边,不需要数据迁移):
|
||||
|
||||
- `drawShape()` 里所有 `ctx.stroke()` 都按 `strokeOn` 跳过。**不能用 `lineWidth = 0` 实现**——
|
||||
canvas 会忽略 0 并保留上一次的线宽,且改回需要记住原值;
|
||||
- 「无」按钮出现在**描边槽**(色板头部 / 右栏面板同一份 DOM),点一下只关外框、颜色留着,
|
||||
下次选色直接恢复(与「文字描边宽度 0 时选色自动给 6px」同一条逻辑,选色共用一张快照,撤销一步);
|
||||
- 「只描边」的形状去掉描边会整体消失,所以**顺手切实心** —— 结果是「一个没有框的色块」,
|
||||
而不是「对象凭空没了」;反过来在选项栏点「描边」也会自动恢复 `strokeOn`;
|
||||
- 只有**「去掉后还看得见」才给「无」**:矩形/圆形、闭合钢笔可以;箭头、未闭合钢笔不给
|
||||
(判据复用 `fillSlotOn()`,与「填充槽存不存在」同一份逻辑);
|
||||
- 视觉:工具栏描边格与色板 tab 画红斜杠(复用 `.is-none`),选项栏描边色块置灰(`.is-off`)。
|
||||
|
||||
### Shift+X:交换的是「颜色 + 有无」
|
||||
|
||||
以前只交换颜色值,所以「无填充」时按 X 看不出任何变化(只有一个颜色,被判定为「无需交换」)。
|
||||
现在交换整份状态:
|
||||
|
||||
- 两边都有色 → 颜色对调,开关不动(v1.13.1 的语义保留);
|
||||
- 只有一边有色 → 有色那边连同颜色整体换到另一边(无填充 + 有色描边 ⇄ 有色填充 + 无描边);
|
||||
- 填充色还在「跟随描边色」(`fillColor=null`)→ 只换有无,颜色继续跟随,不拆成独立色;
|
||||
- 两边都无色、或箭头/未闭合钢笔(换完什么都不剩)→ toast 提示,不写历史。
|
||||
|
||||
`__debug().shapes` 增加 `strokeOn`,harness 补 6 条(描边像素清零、三处 UI 斜杠态、
|
||||
选色恢复描边、钢笔闭合可去描边、未闭合不给入口、一边无色可交换并回退)。
|
||||
|
||||
## 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:修「换一张图调节,画面还原成上一张」
|
||||
|
||||
### 病灶
|
||||
|
||||
@@ -311,6 +311,8 @@ getCompositeCanvas() // 当前这一张
|
||||
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
||||
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
||||
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
||||
| 描边「无色」+ X 交换整份状态(v1.17.0) | ✅ 形状对象新增 `strokeOn`(缺省有描边,老对象/历史快照无此字段照旧),`drawShape()` 按它跳过 `ctx.stroke()`(不能用 `lineWidth=0`:canvas 忽略 0 且丢失原值);「无」按钮扩到**描边槽**,只关外框、颜色留着,选色即恢复(共用一张快照);去掉描边后会把「只描边」的形状顺手切实心,避免对象消失;箭头与未闭合钢笔不给入口(判据复用 `fillSlotOn()`)。Shift+X 从「只交换颜色」升级为**交换颜色 + 有无**:一边有色时连同颜色整体换到另一边,填充「跟随描边色」时只换有无不拆独立色,两边都无色或换完一无所有则提示不执行 |
|
||||
| 右栏调色面板 / 可拖宽度 / 字号(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 才漏掉 |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/image-annotate",
|
||||
"private": true,
|
||||
"version": "1.15.1",
|
||||
"version": "1.17.0",
|
||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||
"ibwPlugin": {
|
||||
"id": "image-annotate",
|
||||
|
||||
@@ -1218,7 +1218,9 @@
|
||||
|
||||
/* 左栏:调色板在上,参数竖排,导出按钮底部 */
|
||||
.iwb-editor-left {
|
||||
width: 240px; min-width: 240px; flex: 0 0 240px;
|
||||
/* v1.16:宽度唯一出处。拖拽手柄写 --iwb-side-w,下面两条历史规则也都读它,
|
||||
不再各写一个 240/220 的魔数(以前三处硬编码,改一次要搜三次)。 */
|
||||
width: var(--iwb-side-w, 280px); min-width: var(--iwb-side-w, 280px); flex: 0 0 var(--iwb-side-w, 280px);
|
||||
display: flex; flex-direction: column; gap: 14px;
|
||||
padding: 12px; background: #181825; border-right: 1px solid #313244; overflow-y: auto;
|
||||
}
|
||||
@@ -1322,7 +1324,7 @@
|
||||
.iwb-editor-main { display: flex; flex-direction: row; align-items: stretch; }
|
||||
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 290px; min-width: 290px; width: 290px; }
|
||||
.iwb-editor-main > .iwb-editor-canvas-wrap { flex: 1 1 auto; min-width: 0; }
|
||||
.iwb-editor-left { flex: 0 0 240px; min-width: 240px; width: 240px; }
|
||||
.iwb-editor-left { flex: 0 0 var(--iwb-side-w, 280px); min-width: var(--iwb-side-w, 280px); width: var(--iwb-side-w, 280px); }
|
||||
.iwb-editor-layer-panel .iwb-editor-layer-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
|
||||
|
||||
/* ======== 顶部布局 v5:左侧重置类 / 中间工具 / 右侧保存类 ======== */
|
||||
@@ -1529,7 +1531,7 @@
|
||||
}
|
||||
.iwb-editor-main { padding-left: 0; }
|
||||
.iwb-editor-main > .iwb-editor-layer-panel { flex: 0 0 260px !important; min-width: 260px !important; width: 260px !important; }
|
||||
.iwb-editor-left { flex: 0 0 220px !important; min-width: 220px !important; width: 220px !important; }
|
||||
.iwb-editor-left { flex: 0 0 var(--iwb-side-w, 280px) !important; min-width: var(--iwb-side-w, 280px) !important; width: var(--iwb-side-w, 280px) !important; }
|
||||
.iwb-editor-overlay.panels-collapsed .iwb-editor-layer-panel,
|
||||
.iwb-editor-overlay.panels-collapsed .iwb-editor-left { display: none !important; }
|
||||
.iwb-editor-zoom-hint { display: none !important; }
|
||||
@@ -2096,3 +2098,135 @@
|
||||
|
||||
/* 选项栏按钮里是中文双字标签(常规/特粗/底色),不给 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; }
|
||||
@@ -10,6 +10,55 @@ import { S, runtime } from './state.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 创建 ============
|
||||
export function createEl() {
|
||||
if (runtime.el) return
|
||||
@@ -169,6 +218,20 @@ import { bindEvents } from './events.js'
|
||||
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
|
||||
|
||||
<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):
|
||||
侧栏只留快速效果 + 缩放;色板 DOM 在 modal 末尾的 .iwb-editor-color-pop -->
|
||||
<!-- 图片调节(v1.15):连续调色,作用于当前位图图层(默认原图)。
|
||||
@@ -242,47 +305,12 @@ import { bindEvents } from './events.js'
|
||||
<span class="iwb-editor-status-layer">当前层:原图</span>
|
||||
<span class="iwb-editor-status-tool">画笔</span>
|
||||
</div>
|
||||
<!-- 色板弹层(v1.3):工具栏色点点击展开。
|
||||
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
||||
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
||||
<div class="iwb-editor-color-pop" hidden>
|
||||
<!-- 弹层头部(v1.11 两格 → v1.12 文字三格):标明「现在调的是哪个颜色」,
|
||||
并可直接切换。与工具栏那几个色块是同一组槽位,两边高亮完全一致。
|
||||
「无」只对「可以没有」的颜色有意义:文字色没有无,描边/底色/填充才有。 -->
|
||||
<div class="iwb-color-pop-head">
|
||||
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
|
||||
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色 / 文字描边色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
|
||||
<button type="button" class="iwb-color-pop-tab" data-color-slot="bg" hidden title="正在调文本框底色(垫在文字下面)"><i></i><span class="iwb-color-pop-tab-label">底色</span></button>
|
||||
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="无填充:形状内部透明,只留描边"><span></span>无</button>
|
||||
</div>
|
||||
<div class="iwb-color-pop-body">
|
||||
<div class="iwb-color-pop-picker">
|
||||
<div class="iwb-color-sv"><span></span></div>
|
||||
<div class="iwb-color-hue"><span></span></div>
|
||||
</div>
|
||||
<span class="iwb-color-pop-sep"></span>
|
||||
<div class="iwb-color-pop-fields">
|
||||
<button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:切到吸管工具,在画布上点一下取色"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
|
||||
<input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7" spellcheck="false" autocomplete="off" title="十六进制颜色,回车生效">
|
||||
</div>
|
||||
<span class="iwb-color-pop-sep"></span>
|
||||
<!-- 最近使用(v1.9):由 recent-colors.js 动态填充,空的时候整行隐藏 -->
|
||||
<div class="iwb-editor-recent-colors" hidden title="最近使用"></div>
|
||||
<div class="iwb-editor-color-swatches">
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff4444" style="background:#ff4444" title="#ff4444"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff8a00" style="background:#ff8a00" title="#ff8a00"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffd400" style="background:#ffd400" title="#ffd400"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#4cd964" style="background:#4cd964" title="#4cd964"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#00bfa5" style="background:#00bfa5" title="#00bfa5"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#4488ff" style="background:#4488ff" title="#4488ff"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#aa44ff" style="background:#aa44ff" title="#aa44ff"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ff66aa" style="background:#ff66aa" title="#ff66aa"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#ffffff" style="background:#ffffff" title="#ffffff"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#d0d0d0" style="background:#d0d0d0" title="#d0d0d0"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#808080" style="background:#808080" title="#808080"></button>
|
||||
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#000000" style="background:#000000" title="#000000"></button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 色板弹层(v1.3;v1.16 起与右栏常驻面板共用同一份 DOM):
|
||||
工具栏色块点击展开。必须挂在 modal 下、不能塞进 .iwb-editor-tools ——
|
||||
工具栏是 overflow-x:auto,canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;
|
||||
定位由 events.js 计算。 -->
|
||||
<div class="iwb-editor-color-pop" data-color-surface="pop" hidden>
|
||||
${colorSurfaceHtml()}
|
||||
</div>
|
||||
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
||||
</div>
|
||||
|
||||
@@ -27,6 +27,12 @@ import { applyQuickEffect, setEffectValue } from './effects.js'
|
||||
import { applyAdjust, ensureAdjustTarget, mountAdjustPanel, resetAdjust, setAdjustValue, syncAdjustControls } from './adjust.js'
|
||||
import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
|
||||
/* 右栏宽度(v1.16):默认 280 —— 220 放 11 项调节时「温度/色调」会被压成两字,
|
||||
而这是用户最常拖的滑杆区。上限还要跟窗口宽度取小,窄窗口不把画布挤没。 */
|
||||
export const SIDE_DEFAULT = 280
|
||||
export const SIDE_MIN = 220
|
||||
export const SIDE_MAX = 520
|
||||
|
||||
|
||||
// ============ 鼠标事件 ============
|
||||
/**
|
||||
@@ -543,6 +549,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
lw: Math.max(1, S.shapeLineWidth),
|
||||
lineWidth: Math.max(1, S.shapeLineWidth),
|
||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||
strokeOn: S.shapeStrokeOn !== false,
|
||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||
opacity: 1,
|
||||
visible: true
|
||||
@@ -748,6 +755,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
fillColor: S.shapeFillColor, // null = 跟随描边色(改主色时整块跟着变)
|
||||
lw: Math.max(1, S.shapeLineWidth),
|
||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||
strokeOn: S.shapeStrokeOn !== false,
|
||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||
opacity: 1,
|
||||
visible: true,
|
||||
@@ -893,6 +901,16 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
||||
}
|
||||
|
||||
/** 「无描边」(v1.17)能不能给:只有「去掉描边后画面还看得见」才给。
|
||||
* 判据就是 fillSlotOn() —— 能填充才谈得上不要描边:
|
||||
* 箭头没有内部、未闭合的钢笔没有面积,去掉描边等于把这个对象删掉,
|
||||
* 这两种情况宁可不给按钮,也别让用户点出一个「看不见的对象」。
|
||||
* 文字不在此列:文字描边是第二格「描边」,早就有「无」了。 */
|
||||
function strokeSlotCanBeNone() {
|
||||
const ctx = colorContext()
|
||||
return ctx.kind === 'shape' && fillSlotOn()
|
||||
}
|
||||
|
||||
/** 文字的三个颜色槽(v1.12)。
|
||||
* 文字对象本来就有三个颜色字段:color(文字本身)/ strokeColor(字的外描边)/
|
||||
* bgColor(文本框底色)。上一版把它们硬塞进「描边 / 填充」两格,第二格其实是
|
||||
@@ -929,9 +947,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
const fillOn = sh
|
||||
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
|
||||
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
|
||||
// v1.17:描边也有「有 / 无」两态。老对象没有 strokeOn 字段 ⇒ 视为有描边。
|
||||
// 只有 shape 上下文才谈得上无描边:箭头/画笔那一格是「唯一颜色」,
|
||||
// 显示成斜杠会让人以为画笔也画不出颜色。
|
||||
const strokeOn = ctx.kind !== 'shape'
|
||||
? true
|
||||
: (sh ? (sh.strokeOn !== false) : (S.shapeStrokeOn !== false))
|
||||
return {
|
||||
mode: ctx.kind === 'shape' ? 'shape' : 'single',
|
||||
stroke, fill: rawFill || stroke, fillOn, follow: !rawFill,
|
||||
stroke, strokeOn, fill: rawFill || stroke, fillOn, follow: !rawFill,
|
||||
bg: null, bgOn: false, bgAlpha: 1,
|
||||
strokeName: '描边', fillName: '填充', bgName: '底色'
|
||||
}
|
||||
@@ -966,11 +990,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
const dot = strokeBtn.querySelector('i')
|
||||
if (dot) dot.style.backgroundColor = sl.stroke
|
||||
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
||||
// v1.17:无描边时色块画红斜杠,和「无填充」同一套视觉语言
|
||||
strokeBtn.classList.toggle('is-none', !isText && sl.strokeOn === false)
|
||||
strokeBtn.title = isText
|
||||
? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)`
|
||||
: (second
|
||||
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色`
|
||||
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`)
|
||||
: (sl.strokeOn === false
|
||||
? '描边:无(只有填充)。点开选色会自动恢复描边'
|
||||
: (second
|
||||
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色,「无」= 去掉描边`
|
||||
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`))
|
||||
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
||||
}
|
||||
@@ -1024,20 +1052,25 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
: (isText ? '正在调文字色(文字本身的颜色)' : '正在调描边色'))
|
||||
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !second }
|
||||
if (isBg) { tab.classList.toggle('is-none', !sl.bgOn); tab.hidden = !isText }
|
||||
// 描边格:文字的「描边」是第二格(上面已处理),文字色/单槽上下文不允许「无」
|
||||
if (!isFill && !isBg) tab.classList.toggle('is-none', !isText && sl.strokeOn === false)
|
||||
})
|
||||
// 「无」:形状 = 无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
||||
// (文字色没有「无」—— 字没有颜色就等于把字删了,不该给这个按钮)
|
||||
const noneBtn = runtime.el.querySelector('[data-color-none]')
|
||||
if (noneBtn) {
|
||||
const onBg = S.colorTarget === 'bg' && isText
|
||||
const onFill = S.colorTarget === 'fill' && second
|
||||
const show = onBg || onFill
|
||||
noneBtn.hidden = !show
|
||||
noneBtn.classList.toggle('active', show && (onBg ? !sl.bgOn : !sl.fillOn))
|
||||
// 「无」:形状/钢笔 = 无描边或无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
||||
// (文字色与箭头单槽没有「无」—— 去掉就等于把对象删了,不该给这个按钮)
|
||||
// v1.16:右栏与弹层各有一个「无」,必须按集合刷,否则只有先出现的那个对
|
||||
const onBg = S.colorTarget === 'bg' && isText
|
||||
const onFill = S.colorTarget === 'fill' && second
|
||||
const onStroke = S.colorTarget === 'stroke' && !isText && strokeSlotCanBeNone()
|
||||
const showNone = onBg || onFill || onStroke
|
||||
runtime.el.querySelectorAll('[data-color-none]').forEach(noneBtn => {
|
||||
noneBtn.hidden = !showNone
|
||||
noneBtn.classList.toggle('active', showNone && (onBg ? !sl.bgOn : (onFill ? !sl.fillOn : !sl.strokeOn)))
|
||||
noneBtn.title = onBg
|
||||
? '无底色:文字后面完全透明'
|
||||
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边')
|
||||
}
|
||||
: (onStroke
|
||||
? (sl.strokeOn === false ? '当前已是无描边;点选颜色可恢复描边' : '无描边:去掉形状外框,只留内部填充')
|
||||
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边'))
|
||||
})
|
||||
|
||||
const cur = activeColor()
|
||||
let matchPreset = false
|
||||
@@ -1046,28 +1079,34 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (on) matchPreset = true
|
||||
s.classList.toggle('active', on)
|
||||
})
|
||||
const panelHex = runtime.el.querySelector('.iwb-editor-color-hex')
|
||||
const hexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
||||
if (hexInput && document.activeElement !== hexInput) hexInput.value = cur.toUpperCase()
|
||||
// v1.16:hex / 调色器在两处面板各有一份 → 一律按集合刷
|
||||
runtime.el.querySelectorAll('.iwb-editor-color-hex').forEach(el => { el.textContent = cur.toUpperCase() })
|
||||
runtime.el.querySelectorAll('.iwb-editor-color-hex-input').forEach(inp => {
|
||||
if (document.activeElement !== inp) inp.value = cur.toUpperCase()
|
||||
})
|
||||
runtime.el.querySelectorAll('.iwb-editor-color-panel-swatch').forEach(sw => sw.classList.toggle('active', (sw.dataset.panelColor || '').toLowerCase() === cur.toLowerCase()))
|
||||
if (panelHex) panelHex.textContent = cur.toUpperCase()
|
||||
const rgb = hexToRgb(cur)
|
||||
const max = Math.max(rgb.r, rgb.g, rgb.b) / 255, min = Math.min(rgb.r, rgb.g, rgb.b) / 255
|
||||
const d = max - min
|
||||
let h = 0
|
||||
if (d) { if (max === rgb.r / 255) h = 60 * (((rgb.g - rgb.b) / 255 / d) % 6); else if (max === rgb.g / 255) h = 60 * ((rgb.b - rgb.r) / 255 / d + 2); else h = 60 * ((rgb.r - rgb.g) / 255 / d + 4) }
|
||||
if (h < 0) h += 360
|
||||
const sv = runtime.el.querySelector('.iwb-color-sv'), hue = runtime.el.querySelector('.iwb-color-hue')
|
||||
if (sv) sv.style.backgroundColor = `hsl(${h} 100% 50%)`
|
||||
if (hue) hue.dataset.hue = h
|
||||
const hueMarker = hue && hue.querySelector('span'); if (hueMarker) hueMarker.style.top = (h / 360 * 100) + '%'
|
||||
const svMarker = sv && sv.querySelector('span'); if (svMarker) { const sat = max ? d / max : 0; svMarker.style.left = (sat * 100) + '%'; svMarker.style.top = ((1 - max) * 100) + '%' }
|
||||
const custom = runtime.el.querySelector('.iwb-editor-color-custom')
|
||||
if (custom) {
|
||||
const sat = max ? d / max : 0
|
||||
runtime.el.querySelectorAll('.iwb-color-sv').forEach(sv => {
|
||||
sv.style.backgroundColor = `hsl(${h} 100% 50%)`
|
||||
const m = sv.querySelector('span')
|
||||
if (m) { m.style.left = (sat * 100) + '%'; m.style.top = ((1 - max) * 100) + '%' }
|
||||
})
|
||||
runtime.el.querySelectorAll('.iwb-color-hue').forEach(hue => {
|
||||
hue.dataset.hue = h
|
||||
const m = hue.querySelector('span')
|
||||
if (m) m.style.top = (h / 360 * 100) + '%'
|
||||
})
|
||||
runtime.el.querySelectorAll('.iwb-editor-color-custom').forEach(custom => {
|
||||
custom.classList.toggle('active', !matchPreset)
|
||||
const inp = custom.querySelector('input')
|
||||
if (inp) inp.value = cur
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 画笔大小/硬度/透明曾经在侧栏也有一份,2026-11-04 起只保留工具选项栏一处,
|
||||
@@ -1150,7 +1189,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
|
||||
const sl = colorSlots()
|
||||
let html = '<span class="iwb-opt-label">描边</span>'
|
||||
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`
|
||||
+ `<input type="color" class="iwb-opt-color${sl.strokeOn === false ? ' is-off' : ''}" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样${sl.strokeOn === false ? ';当前无描边,选色会自动恢复' : ''}">`
|
||||
if (owner) {
|
||||
html += '<span class="iwb-opt-label">填充</span>'
|
||||
+ `<input type="color" class="iwb-opt-color${sl.fillOn ? '' : ' is-off'}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? '' : ';当前无填充,选色会自动切成实心'}">`
|
||||
@@ -1429,7 +1468,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
? '填充色:与工具栏右下的填充色块是同一份'
|
||||
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
|
||||
} else {
|
||||
inp.title = '描边色:与工具栏左上的描边色块是同一份'
|
||||
// v1.17:无描边时描边色块也要置灰(和「无填充」同一套提示)
|
||||
const off = sl.strokeOn === false
|
||||
inp.classList.toggle('is-off', off)
|
||||
inp.title = off
|
||||
? '当前无描边(只有填充)。选色会自动恢复描边,也可点工具栏描边色块选「无」'
|
||||
: '描边色:与工具栏左上的描边色块是同一份'
|
||||
}
|
||||
})
|
||||
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
|
||||
@@ -1568,9 +1612,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
syncOptionBar()
|
||||
}
|
||||
|
||||
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派):
|
||||
* 形状填充 → 内部透明;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
||||
* 三种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
||||
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派;v1.17 起描边也支持):
|
||||
* 形状填充 → 内部透明;形状描边 → 不画外框;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
||||
* 四种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
||||
function applyColorNone() {
|
||||
const sl = colorSlots()
|
||||
if (sl.mode === 'text') {
|
||||
@@ -1580,9 +1624,33 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
syncOptionBar()
|
||||
return
|
||||
}
|
||||
if (S.colorTarget === 'stroke') { applyStrokeNone(); return }
|
||||
applyShapeColor('none')
|
||||
}
|
||||
|
||||
/** 无描边(v1.17):只关外框,描边色留着,下次选色直接恢复。
|
||||
* 「只描边」的形状去掉描边会整体消失 —— 顺手切实心,
|
||||
* 让结果是「一个没有框的色块」而不是「对象凭空没了」。 */
|
||||
function applyStrokeNone() {
|
||||
if (!strokeSlotCanBeNone()) return
|
||||
S.colorTarget = 'stroke'
|
||||
S.shapeStrokeOn = false
|
||||
const sh = getSelectedShape()
|
||||
if (sh && !sh.locked && sh.strokeOn !== false) {
|
||||
saveSnapshot('无描边')
|
||||
sh.strokeOn = false
|
||||
if (!sh.fill && (sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && sh.closed))) {
|
||||
sh.fill = true
|
||||
if (sh.type === 'pen') S.penFill = true
|
||||
else S.rectFill = true
|
||||
}
|
||||
renderObjects()
|
||||
}
|
||||
updateFillUI()
|
||||
updateColorUI()
|
||||
syncOptionBar()
|
||||
}
|
||||
|
||||
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
|
||||
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
||||
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
||||
@@ -1610,6 +1678,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
||||
if (kind === 'stroke') {
|
||||
S.colorTarget = 'stroke'
|
||||
// 新建默认值也恢复描边:否则「无描边」状态下改一次描边色,
|
||||
// 下一个新形状仍然是没框的,用户会以为设置没生效
|
||||
S.shapeStrokeOn = true
|
||||
applyColorChange(hex, opts)
|
||||
if (skipHistory) syncOptionBarSoon()
|
||||
else syncOptionBar()
|
||||
@@ -1690,30 +1761,52 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
saveSnapshot('填充')
|
||||
// 未闭合的钢笔路径没有可填区域:保持描边,不动视觉结果
|
||||
sh.fill = isPen ? (!!S.penFill && !!sh.closed) : !!S.rectFill
|
||||
// 用户明确点了「描边」= 要看见框:无描边的对象顺手恢复,否则点完毫无变化
|
||||
if (!sh.fill && sh.strokeOn === false) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||
renderObjects()
|
||||
// 对象的 fill 更新在 sync 之后,选择工具下按钮的激活态要再刷一次
|
||||
syncOptionBar()
|
||||
}
|
||||
}
|
||||
|
||||
/** PS 的 X 语义(v1.13.1):把选中形状的「填充色」与「描边色」对调。
|
||||
* 以前 Shift+X 绑的是「实心 ↔ 只描边」开关 —— 按下去填充被关掉、描边纹丝不动,
|
||||
* 用户的主观体验就是「填充色丢了」,再按一次才回来。用户要的是**交换两个颜色**:
|
||||
* 填充色换到描边的位置、描边色换到填充的位置,填充的开关状态不变(交换的是颜色,不是有无)。
|
||||
* 填充色仍「跟随描边色」(fillColor=null)时只有一个颜色,没有可交换的对象,只提示不动数据。 */
|
||||
/** PS 的 X 语义:把选中形状的「描边」与「填充」对调。
|
||||
* v1.13.1:以前 Shift+X 绑的是「实心 ↔ 只描边」开关,按下去填充被关掉、
|
||||
* 描边纹丝不动,用户的主观体验就是「填充色丢了」。改为**交换两个颜色**。
|
||||
* v1.17:交换的是整份状态(颜色 + 有/无),不只是颜色 ——
|
||||
* 「无填充 + 有色描边」按一下 → 「有色填充 + 无描边」,反之亦然。
|
||||
* 这样「有一边是无色」时也能用(用户反馈的第二个问题);
|
||||
* 两边都有色且填充还在跟随描边时只有一个颜色,才提示不动。
|
||||
* 「未闭合钢笔 / 箭头」没有可填内部:交换后整条路径会消失,直接提示不执行。 */
|
||||
function swapShapeColors() {
|
||||
const sh = getSelectedShape()
|
||||
if (!sh || sh.locked) return false
|
||||
if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true }
|
||||
const stroke = sh.color || S.color
|
||||
const fill = sh.fillColor || null
|
||||
if (!fill) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
||||
const canFill = sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
||||
const strokeOn = sh.strokeOn !== false
|
||||
const fillOn = !!sh.fill
|
||||
const strokeColor = sh.color || S.color
|
||||
const fillColor = sh.fillColor || null // null = 跟随描边色
|
||||
if (!canFill && !fillOn) { toast('这条路径没有可填内部,交换后什么都看不见', 'info'); return true }
|
||||
if (!strokeOn && !fillOn) { toast('描边与填充都是无色,没有可交换的颜色', 'info'); return true }
|
||||
if (strokeOn && fillOn && !fillColor) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
||||
|
||||
saveSnapshot('交换填充与描边色')
|
||||
sh.color = fill
|
||||
S.color = fill // 描边色与主色永远同一份(v1.10 的约定)
|
||||
sh.fillColor = stroke
|
||||
S.shapeFillColor = stroke // 交换后就是独立填充色了,不再跟随描边
|
||||
// 1) 交换「有 / 无」:哪边有色,交换后就跑到另一边去
|
||||
sh.strokeOn = fillOn
|
||||
sh.fill = strokeOn && canFill
|
||||
S.shapeStrokeOn = fillOn
|
||||
if (sh.type === 'pen') S.penFill = !!(sh.fill && sh.closed)
|
||||
else if (sh.type === 'rect' || sh.type === 'circle') S.rectFill = !!sh.fill
|
||||
// 2) 交换颜色。填充原来「跟随描边色」(fillColor=null)就继续跟随 ——
|
||||
// 跟随值恰好就是原描边色,换过去还是同一个颜色,不必把它拆成独立色。
|
||||
if (fillColor) {
|
||||
sh.color = fillColor
|
||||
S.color = fillColor
|
||||
sh.fillColor = strokeColor
|
||||
S.shapeFillColor = strokeColor
|
||||
}
|
||||
renderObjects()
|
||||
updateFillUI()
|
||||
updateColorUI()
|
||||
syncOptionBar()
|
||||
return true
|
||||
@@ -2060,9 +2153,81 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
bindExportActions()
|
||||
bindWheelZoom()
|
||||
bindTextInput()
|
||||
bindSideResize()
|
||||
bindGlobalListeners()
|
||||
}
|
||||
|
||||
/* ============ 右栏宽度(v1.16) ============ */
|
||||
|
||||
/** 应用宽度:夹在 [SIDE_MIN, min(SIDE_MAX, 窗口 45%)],写 CSS 变量 */
|
||||
export function applySideWidth(w) {
|
||||
if (!runtime.el) return S.sideWidth || SIDE_DEFAULT
|
||||
const cap = Math.min(SIDE_MAX, Math.max(SIDE_MIN, Math.floor((window.innerWidth || 1440) * 0.45)))
|
||||
const v = Math.round(Math.min(cap, Math.max(SIDE_MIN, Number(w) || SIDE_DEFAULT)))
|
||||
runtime.el.style.setProperty('--iwb-side-w', v + 'px')
|
||||
S.sideWidth = v
|
||||
return v
|
||||
}
|
||||
|
||||
/** 打开编辑器时恢复上次宽度(没存过就用默认值) */
|
||||
export function loadSideWidth() {
|
||||
const st = S.callbacks && S.callbacks.settings
|
||||
let w = 0
|
||||
if (st && typeof st.get === 'function') { try { w = Number(st.get('sideWidth')) || 0 } catch (e) { /* ignore */ } }
|
||||
return applySideWidth(w > 0 ? w : SIDE_DEFAULT)
|
||||
}
|
||||
|
||||
function saveSideWidth() {
|
||||
const st = S.callbacks && S.callbacks.settings
|
||||
if (st && typeof st.set === 'function') { try { st.set('sideWidth', S.sideWidth) } catch (e) { /* ignore */ } }
|
||||
}
|
||||
|
||||
/**
|
||||
* 拖拽右栏宽度。
|
||||
* 侧栏在画布右侧,所以指针左移 = 变宽(startW - dx),别写反。
|
||||
* 用 pointer capture:指针拖出 7px 宽的手柄后事件仍然回到手柄上,
|
||||
* 否则鼠标一快就跟丢、宽度卡住。
|
||||
*/
|
||||
function bindSideResize() {
|
||||
const handle = runtime.el && runtime.el.querySelector('[data-side-resizer]')
|
||||
if (!handle) return
|
||||
let dragging = false
|
||||
let startX = 0
|
||||
let startW = 0
|
||||
const endDrag = () => {
|
||||
if (!dragging) return
|
||||
dragging = false
|
||||
handle.classList.remove('is-dragging')
|
||||
document.body.style.cursor = ''
|
||||
document.body.style.userSelect = ''
|
||||
saveSideWidth()
|
||||
}
|
||||
handle.addEventListener('pointerdown', (e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
dragging = true
|
||||
startX = e.clientX
|
||||
startW = S.sideWidth || SIDE_DEFAULT
|
||||
handle.classList.add('is-dragging')
|
||||
document.body.style.cursor = 'col-resize'
|
||||
document.body.style.userSelect = 'none'
|
||||
try { handle.setPointerCapture(e.pointerId) } catch (err) { /* 老浏览器退回普通事件 */ }
|
||||
})
|
||||
handle.addEventListener('pointermove', (e) => {
|
||||
if (!dragging) return
|
||||
applySideWidth(startW - (e.clientX - startX))
|
||||
})
|
||||
handle.addEventListener('pointerup', endDrag)
|
||||
handle.addEventListener('pointercancel', endDrag)
|
||||
handle.addEventListener('lostpointercapture', endDrag)
|
||||
// 双击复位:拖窄了想回去,不用精确拖回 280
|
||||
handle.addEventListener('dblclick', (e) => {
|
||||
e.stopPropagation()
|
||||
applySideWidth(SIDE_DEFAULT)
|
||||
saveSideWidth()
|
||||
})
|
||||
}
|
||||
|
||||
/** 工具条按钮:点击切换当前工具(选区命令按钮也借用 .iwb-editor-tool 样式,靠 data-tool 过滤掉) */
|
||||
function bindToolButtons() {
|
||||
// 工具
|
||||
@@ -2122,8 +2287,10 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
}
|
||||
|
||||
/** 色板弹层(v1.3;v1.11 起同时服务描边与填充两个槽):
|
||||
* 工具栏两个色块开关;tab / hex / 吸管 / 推荐色 / 调色器 / 无填充都在这一个弹层里 */
|
||||
/** 调色面板(v1.3 弹层 → v1.16 弹层 + 右栏常驻):
|
||||
* 两处是同一份 DOM(dom.js#colorSurfaceHtml),按 [data-color-surface] 逐个绑定。
|
||||
* 每个 surface 各自持有一份 HSV 拖拽状态,但取值一律从 activeColor() 现算,
|
||||
* 所以「在右栏取色、再去弹层拖 SV」不会跳色。 */
|
||||
function bindColorPanel() {
|
||||
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')]
|
||||
@@ -2132,37 +2299,50 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
btn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop(btn.dataset.colorSlot) })
|
||||
})
|
||||
if (pop) {
|
||||
pop.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
|
||||
// 冒泡阶段拿不到「点了外面」这件事。
|
||||
// 冒泡阶段拿不到「点了外面」这件事。右栏面板常驻,不参与关闭。
|
||||
document.addEventListener('mousedown', (e) => {
|
||||
const onBtn = colorBtns.some(b => b.contains(e.target))
|
||||
if (!pop.hidden && !pop.contains(e.target) && !onBtn) closeColorPop()
|
||||
}, true)
|
||||
window.addEventListener('resize', positionColorPop)
|
||||
}
|
||||
runtime.el.querySelectorAll('[data-color-surface]').forEach(surface => bindColorSurface(surface))
|
||||
}
|
||||
|
||||
// 弹层头部:切描边/填充,或直接置为「无填充」
|
||||
if (pop) {
|
||||
pop.addEventListener('click', (e) => {
|
||||
const tab = e.target.closest('[data-color-slot]')
|
||||
if (tab && tab.classList.contains('iwb-color-pop-tab')) {
|
||||
e.stopPropagation()
|
||||
setColorTarget(tab.dataset.colorSlot)
|
||||
positionColorPop()
|
||||
return
|
||||
}
|
||||
const none = e.target.closest('[data-color-none]')
|
||||
if (none) {
|
||||
e.stopPropagation()
|
||||
applyColorNone()
|
||||
return
|
||||
}
|
||||
/** 一块调色面板的全部交互:弹层与右栏各一份,代码只有这一处 */
|
||||
function bindColorSurface(surface) {
|
||||
const isPop = surface.classList.contains('iwb-editor-color-pop')
|
||||
surface.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||
// tab 切换目标槽 / 「无」 / 常用色与最近色,统一委托:
|
||||
// 静态 12 色 + 动态插入的「最近使用」都要能点,一次性 querySelectorAll 会漏掉后者
|
||||
surface.addEventListener('click', (e) => {
|
||||
const tab = e.target.closest('.iwb-color-pop-tab[data-color-slot]')
|
||||
if (tab) {
|
||||
e.stopPropagation()
|
||||
setColorTarget(tab.dataset.colorSlot)
|
||||
if (isPop) positionColorPop() // 换 tab 后弹层宽度会变,重新贴一次
|
||||
return
|
||||
}
|
||||
const none = e.target.closest('[data-color-none]')
|
||||
if (none) { e.stopPropagation(); applyColorNone(); return }
|
||||
const sw = e.target.closest('[data-panel-color]')
|
||||
if (sw) { e.stopPropagation(); applyPanelColor(sw.dataset.panelColor) }
|
||||
})
|
||||
|
||||
const hexInput = surface.querySelector('.iwb-editor-color-hex-input')
|
||||
if (hexInput) {
|
||||
hexInput.addEventListener('change', () => {
|
||||
if (/^#[0-9a-f]{6}$/i.test(hexInput.value)) applyPanelColor(hexInput.value)
|
||||
})
|
||||
}
|
||||
const palettePick = surface.querySelector('[data-action="palettePick"]')
|
||||
if (palettePick) {
|
||||
palettePick.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||
// 取色要回画布点,弹层必须先收起,否则它会挡住取样点(右栏面板在画布外,不挡)
|
||||
palettePick.addEventListener('click', () => { closeColorPop(); setTool('picker') })
|
||||
}
|
||||
|
||||
// 独立颜色面板:按当前目标槽写色(描边 → 主色,填充 → 形状 fillColor)
|
||||
const setPanelColor = (color) => applyPanelColor(color)
|
||||
// 拖动取色期间只拍一次快照:applyColorChange 每改一次颜色都会 saveSnapshot,
|
||||
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
|
||||
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
|
||||
@@ -2177,26 +2357,10 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
applyPanelColor(color, { skipHistory: true })
|
||||
}
|
||||
const panelHexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
||||
if (panelHexInput) panelHexInput.addEventListener('change', () => { if (/^#[0-9a-f]{6}$/i.test(panelHexInput.value)) setPanelColor(panelHexInput.value) })
|
||||
// 色块统一走委托:静态 12 色 + 动态插入的「最近使用」都要能点,
|
||||
// 一次性 querySelectorAll 绑定会漏掉后来插进来的按钮
|
||||
if (pop) {
|
||||
pop.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('[data-panel-color]')
|
||||
if (!btn) return
|
||||
e.stopPropagation()
|
||||
setPanelColor(btn.dataset.panelColor)
|
||||
})
|
||||
}
|
||||
const palettePick = runtime.el.querySelector('[data-action="palettePick"]')
|
||||
if (palettePick) {
|
||||
palettePick.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||
// 取色要回画布点,弹层必须先收起,否则它会挡住取样点
|
||||
palettePick.addEventListener('click', () => { closeColorPop(); setTool('picker') })
|
||||
}
|
||||
const sv = runtime.el.querySelector('.iwb-color-sv')
|
||||
const hue = runtime.el.querySelector('.iwb-color-hue')
|
||||
|
||||
const sv = surface.querySelector('.iwb-color-sv')
|
||||
const hue = surface.querySelector('.iwb-color-hue')
|
||||
if (!sv || !hue) return
|
||||
const initHsv = (() => {
|
||||
const { r, g, b } = hexToRgb(activeColor())
|
||||
const rr = r / 255, gg = g / 255, bb = b / 255
|
||||
@@ -2426,7 +2590,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
function commitPenPath() {
|
||||
if (!S.penPath || S.penPath.pts.length < 2) { S.penPath = null; renderObjects(); return }
|
||||
saveSnapshot()
|
||||
const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, fillColor: S.shapeFillColor, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter }
|
||||
const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, fillColor: S.shapeFillColor, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, strokeOn: S.shapeStrokeOn !== false, opacity: 1, visible: true, locked: false, z: ++S.zCounter }
|
||||
// 路径落成即回 V 并选中(v1.5):连续画多条就再按一次 P;节点编辑仍走 V 下双击
|
||||
S.shapeLayers.push(shape); S.penPath = null; renderObjects(); renderLayerPanel()
|
||||
finishCreateTool('shape', shape.id)
|
||||
|
||||
@@ -33,7 +33,7 @@ import { createEl, loadImage } from './dom.js'
|
||||
import { renderObjects, hideTextInput, textBounds } from './objects.js'
|
||||
import { setupCanvas } from './viewport.js'
|
||||
import { resetOverlayTransform } from './scale.js'
|
||||
import { updateAllUI, bindLiteUI, renderOptionBar, updateStatusbar } from './events.js'
|
||||
import { updateAllUI, bindLiteUI, renderOptionBar, updateStatusbar, loadSideWidth } from './events.js'
|
||||
import { disposeSelection, renderSelection, selectionInfo, syncAnts, registerSelectionCommands } from './selection.js'
|
||||
import { bindFloating, positionFloating, hideSelectionContext } from './floating.js'
|
||||
import { renderFxPanel } from './effects.js'
|
||||
@@ -73,6 +73,9 @@ import { toast } from './commands.js'
|
||||
bindFloating()
|
||||
bindExportUI()
|
||||
initPanels()
|
||||
// 右栏宽度跟着用户上次拖的位置(v1.16);必须在 initPanels 之后——
|
||||
// 侧栏收起时元素虽 display:none,写 CSS 变量仍然有效,下次展开直接生效
|
||||
loadSideWidth()
|
||||
renderAll()
|
||||
} catch (e) {
|
||||
console.error('[IWB编辑器] 打开失败:', e)
|
||||
@@ -335,7 +338,7 @@ import { toast } from './commands.js'
|
||||
opacity: l.opacity == null ? 1 : l.opacity,
|
||||
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
||||
})),
|
||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
|
||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, strokeOn: s.strokeOn !== false, z: s.z, color: s.color, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
|
||||
texts: S.textLayers.map(t => ({
|
||||
id: t.id, text: t.text, x: t.x, y: t.y, fontSize: t.fontSize, color: t.color,
|
||||
fontWeight: t.fontWeight, fontFamily: t.fontFamily, align: t.align, lineHeight: t.lineHeight,
|
||||
|
||||
@@ -43,12 +43,21 @@ import { S, runtime } from './state.js'
|
||||
renderRecentColors()
|
||||
}
|
||||
|
||||
export function renderRecentColors() {
|
||||
const wrap = runtime.el && runtime.el.querySelector('.iwb-editor-recent-colors')
|
||||
if (!wrap) return
|
||||
const list = S.recentColors || []
|
||||
wrap.innerHTML = list.map(c =>
|
||||
`<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="最近使用 ${c}"></button>`
|
||||
).join('')
|
||||
export function renderRecentColors() {
|
||||
if (!runtime.el) return
|
||||
// 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
|
||||
})
|
||||
}
|
||||
@@ -45,6 +45,9 @@
|
||||
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
||||
// v1.17:默认是否画描边。关掉后形状只剩填充(「无描边」),
|
||||
// 对象上另存 strokeOn,老对象没有这个字段一律视为有描边。
|
||||
shapeStrokeOn: true,
|
||||
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||
@@ -53,6 +56,9 @@
|
||||
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
|
||||
// 否则「三个地方各调各的颜色」会一直存在。
|
||||
colorTarget: 'stroke', // stroke | fill
|
||||
// v1.16:右侧栏宽度(px)。0 = 按默认值走,打开编辑器时从宿主 KV 恢复。
|
||||
// 宽度统一落在 CSS 变量 --iwb-side-w 上,不再各条规则各写一个魔数。
|
||||
sideWidth: 0,
|
||||
textSize: 32, // 新建文字的字号 px
|
||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||
textWeight: 'bold', // bold | normal | 900
|
||||
|
||||
@@ -201,9 +201,18 @@ import { rememberColor } from './recent-colors.js'
|
||||
ctx.lineWidth = s.lw
|
||||
ctx.lineCap = 'round'
|
||||
ctx.lineJoin = 'round'
|
||||
// v1.17:无描边(strokeOn === false)。老对象没有这个字段,一律当有描边。
|
||||
// 注意不能靠 lineWidth = 0 实现:canvas 会忽略 0 从而保持上一次的值。
|
||||
const strokeOn = s.strokeOn !== false
|
||||
if (s.type === 'pen') {
|
||||
const pts = Array.isArray(s.pts) ? s.pts : []
|
||||
if (pts.length > 1) { ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y); for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); if (s.closed) ctx.closePath(); if (s.closed && s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() } ctx.stroke() }
|
||||
if (pts.length > 1) {
|
||||
ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y)
|
||||
for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y)
|
||||
if (s.closed) ctx.closePath()
|
||||
if (s.closed && s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||
if (strokeOn) ctx.stroke()
|
||||
}
|
||||
} else if (s.type === 'rect') {
|
||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
||||
const radius = roundedRadius(s, rw, rh)
|
||||
@@ -211,10 +220,10 @@ import { rememberColor } from './recent-colors.js'
|
||||
ctx.beginPath()
|
||||
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||
ctx.stroke()
|
||||
if (strokeOn) ctx.stroke()
|
||||
} else {
|
||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fillRect(rx, ry, rw, rh) }
|
||||
ctx.strokeRect(rx, ry, rw, rh)
|
||||
if (strokeOn) ctx.strokeRect(rx, ry, rw, rh)
|
||||
}
|
||||
} else if (s.type === 'circle') {
|
||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2)
|
||||
@@ -222,8 +231,9 @@ import { rememberColor } from './recent-colors.js'
|
||||
ctx.beginPath()
|
||||
ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2)
|
||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||
ctx.stroke()
|
||||
} else {
|
||||
if (strokeOn) ctx.stroke()
|
||||
} else if (strokeOn) {
|
||||
// 箭头:没有可填内部,去掉描边等于不画(UI 也不提供这个入口)
|
||||
ctx.fillStyle = strokeOf(s)
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(s.x1, s.y1)
|
||||
@@ -424,9 +434,13 @@ import { rememberColor } from './recent-colors.js'
|
||||
renderObjects()
|
||||
}
|
||||
const sh = getSelectedShape()
|
||||
if (sh && !sh.locked && S.tool !== 'text' && sh.color !== S.color) {
|
||||
if (sh && !sh.locked && S.tool !== 'text' && (sh.color !== S.color || sh.strokeOn === false)) {
|
||||
// v1.17:给「无描边」的形状选颜色 = 想再看见描边,顺手打开。
|
||||
// 与改色共用同一张快照,撤销一步就能回到「无描边 + 旧色」。
|
||||
const revive = sh.strokeOn === false
|
||||
if (!skipHistory) saveSnapshot()
|
||||
sh.color = S.color
|
||||
if (revive) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||
renderObjects()
|
||||
}
|
||||
}
|
||||
|
||||
+2543
-131
File diff suppressed because it is too large.
Load diff
@@ -217,6 +217,65 @@ if (!SKIP_PASTE) {
|
||||
(await page.locator('.iwb-editor-adj-target').textContent()) !== '无图层',
|
||||
await page.locator('.iwb-editor-adj-target').textContent())
|
||||
|
||||
// v1.16:右栏常驻调色面板 + 可拖宽度。真站里 DOM 与 CSS 是分别打包的,
|
||||
// 只验面板在不在、拖宽后宽度有没有真的变 —— 样式漏打包时这里会直接露出来。
|
||||
const sideColor = await page.evaluate(() => {
|
||||
const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]')
|
||||
if (!side) return null
|
||||
return {
|
||||
tabs: side.querySelectorAll('.iwb-color-pop-tab').length,
|
||||
swatches: side.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]').length,
|
||||
sv: !!side.querySelector('.iwb-color-sv')
|
||||
}
|
||||
})
|
||||
check('右栏常驻调色面板(色格切换 + 调色器 + 12 个常用色)',
|
||||
Boolean(sideColor) && sideColor.tabs === 3 && sideColor.swatches === 12 && sideColor.sv,
|
||||
JSON.stringify(sideColor))
|
||||
|
||||
const sideBefore = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||
const sideGrip = await page.locator('.iwb-editor-side-resizer').boundingBox()
|
||||
if (sideGrip) {
|
||||
await page.mouse.move(sideGrip.x + 3, sideGrip.y + 120)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(sideGrip.x + 3 - 70, sideGrip.y + 120, { steps: 6 })
|
||||
await page.mouse.up()
|
||||
await page.waitForTimeout(180)
|
||||
}
|
||||
const sideAfter = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||
check('右栏可以拖宽(不再固定 220)', sideAfter >= sideBefore + 60, sideBefore + ' → ' + sideAfter)
|
||||
await page.locator('.iwb-editor-side-resizer').dblclick()
|
||||
await page.waitForTimeout(150)
|
||||
|
||||
// v1.17:描边可以是「无色」。真站要验的是按钮真的出现在描边槽、点完对象上真的关了,
|
||||
// 而不只是 CSS 里多了个类 —— 形状消失与否只有跑起来才知道。
|
||||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||
await page.mouse.move(imgBox.x + imgBox.width * 0.12, imgBox.y + imgBox.height * 0.12)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(imgBox.x + imgBox.width * 0.30, imgBox.y + imgBox.height * 0.30, { steps: 6 })
|
||||
await page.mouse.up()
|
||||
await page.waitForTimeout(250)
|
||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||
await page.mouse.click(imgBox.x + imgBox.width * 0.21, imgBox.y + imgBox.height * 0.21)
|
||||
await page.waitForTimeout(200)
|
||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||
await page.waitForTimeout(250)
|
||||
const noneOnStroke = await page.evaluate(() => {
|
||||
const n = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
||||
return Boolean(n) && !n.hidden
|
||||
})
|
||||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||
await page.waitForTimeout(300)
|
||||
const noStrokeState = await page.evaluate(() => {
|
||||
const d = window.__iwbEditor.__debug()
|
||||
const s = d.shapes.find((x) => x.id === d.selectedShapeId)
|
||||
return s ? { strokeOn: s.strokeOn, fill: s.fill } : null
|
||||
})
|
||||
check('真站:描边能置「无」(去掉描边顺手切实心,对象不会消失)',
|
||||
noneOnStroke && Boolean(noStrokeState) && noStrokeState.strokeOn === false && noStrokeState.fill === true,
|
||||
JSON.stringify({ noneOnStroke, noStrokeState }))
|
||||
await page.keyboard.press('Escape')
|
||||
await page.waitForTimeout(120)
|
||||
|
||||
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
||||
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
||||
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||||
|
||||
@@ -1001,7 +1001,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
|
||||
if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状'
|
||||
const h0 = (await dbg()).history
|
||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||
const sv = await page.locator('.iwb-color-sv').boundingBox()
|
||||
const sv = await page.locator('.iwb-editor-color-pop .iwb-color-sv').boundingBox()
|
||||
await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(sv.x + sv.width * 0.9, sv.y + sv.height * 0.85, { steps: 20 })
|
||||
@@ -1983,7 +1983,7 @@ check('点文字的「描边」格:色板目标是描边(tab 写「描边」
|
||||
popTextTarget.bgVisible && popTextTarget.noneVisible, JSON.stringify(popTextTarget))
|
||||
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||
el.value = '#00a3ff'
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
@@ -2019,7 +2019,7 @@ const popBgTarget = await page.evaluate(() => {
|
||||
check('点文字的「底色」格:色板切到底色', popBgTarget.bgActive && popBgTarget.label === '底色', JSON.stringify(popBgTarget))
|
||||
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||
el.value = '#123456'
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
@@ -2045,7 +2045,7 @@ check('底色格显示真实颜色(半透明显示,不是实心块)',
|
||||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||
await page.waitForTimeout(200)
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||
el.value = '#ff00aa'
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
@@ -2062,12 +2062,12 @@ check('文字色 / 描边色 / 底色三格互不串(改一格不动另外两
|
||||
// 「无」在底色格 = 关掉底色块,颜色留着
|
||||
await page.locator('.iwb-editor-color-btn[data-color-slot="bg"]').click()
|
||||
await page.waitForTimeout(200)
|
||||
await page.evaluate(() => document.querySelector('[data-color-none]').click())
|
||||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||
await page.waitForTimeout(260)
|
||||
const bgNone = await page.evaluate(() => {
|
||||
const t = window.__iwbEditor.__debug().texts[0]
|
||||
const chip = document.querySelector('.iwb-editor-color-pair [data-color-slot="bg"]')
|
||||
return { bgFill: t.bgFill, bgColor: t.bgColor, cls: chip.className, noneActive: document.querySelector('[data-color-none]').classList.contains('active') }
|
||||
return { bgFill: t.bgFill, bgColor: t.bgColor, cls: chip.className, noneActive: document.querySelector('.iwb-editor-color-pop [data-color-none]').classList.contains('active') }
|
||||
})
|
||||
check('底色格点「无」:关掉底色块、颜色留着,格子回到斜杠态',
|
||||
bgNone.bgFill === false && bgNone.bgColor === '#123456' && /is-none/.test(bgNone.cls) && bgNone.noneActive,
|
||||
@@ -2264,7 +2264,7 @@ await page.waitForTimeout(150)
|
||||
await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click()
|
||||
await page.waitForTimeout(200)
|
||||
const recents = (await dbg()).recentColors
|
||||
const recentsInPop = await page.locator('.iwb-editor-recent-colors [data-panel-color]').count()
|
||||
const recentsInPop = await page.locator('.iwb-editor-color-pop .iwb-editor-recent-colors [data-panel-color]').count()
|
||||
await page.keyboard.press('Escape')
|
||||
await page.waitForTimeout(120)
|
||||
check('选过的颜色进入「最近使用」并出现在色板弹层',
|
||||
@@ -2415,7 +2415,7 @@ check('点填充槽打开色板:目标是填充,并出现「无」按钮',
|
||||
// 拿黄色/绿色统计会数到别的图形,永远清不到 0。
|
||||
const mainBefore = await page.evaluate(() => window.__iwbEditor.__debug().color)
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-color-hex-input')
|
||||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||
el.value = '#a014b2'
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
@@ -2432,13 +2432,13 @@ check('色板里选色写进填充、主色(描边)不动,工具栏填充
|
||||
|
||||
// 「无」:关填充,画面清空,但颜色留着
|
||||
const purpleBefore = await countColorInVec([160, 20, 178], 10)
|
||||
await page.evaluate(() => document.querySelector('[data-color-none]').click())
|
||||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||
await page.waitForTimeout(320)
|
||||
const afterNone = await page.evaluate(() => {
|
||||
const d = window.__iwbEditor.__debug()
|
||||
const s = d.shapes[d.shapes.length - 1]
|
||||
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
|
||||
return { fill: s.fill, fillColor: s.fillColor, btnCls: fillBtn.className, noneActive: document.querySelector('[data-color-none]').classList.contains('active') }
|
||||
return { fill: s.fill, fillColor: s.fillColor, btnCls: fillBtn.className, noneActive: document.querySelector('.iwb-editor-color-pop [data-color-none]').classList.contains('active') }
|
||||
})
|
||||
const purpleAfter = await countColorInVec([160, 20, 178], 10)
|
||||
check('「无」把填充关掉:画面清空、颜色留着(下次点颜色还是它)',
|
||||
@@ -2532,6 +2532,159 @@ const shiftXSwap = await (async () => {
|
||||
})()
|
||||
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
||||
|
||||
// ================================================================
|
||||
// v1.17:描边也能是「无色」;只要有一边无色,Shift+X 照样能交换
|
||||
// ================================================================
|
||||
// 用户原话:「让矢量图形与钢笔的描边色也可以去掉」
|
||||
// 「让描边与填充,有一个是无色的时候,可以交换,现在是不可以的」
|
||||
const setOptColor = (slot, hex) => page.evaluate(({ slot, hex }) => {
|
||||
const el = document.querySelector(`.iwb-editor-optionbar-body [data-shape-color="${slot}"]`)
|
||||
el.value = hex
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
}, { slot, hex })
|
||||
|
||||
async function drawRectAt(x1, y1, x2, y2) {
|
||||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||
const a = { x: imgBox.x + imgBox.width * x1, y: imgBox.y + imgBox.height * y1 }
|
||||
const b = { x: imgBox.x + imgBox.width * x2, y: imgBox.y + imgBox.height * y2 }
|
||||
await page.mouse.move(a.x, a.y); await page.mouse.down()
|
||||
await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up()
|
||||
await page.waitForTimeout(180)
|
||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||
await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2)
|
||||
await page.waitForTimeout(160)
|
||||
return { a, b }
|
||||
}
|
||||
|
||||
// 取选中形状 + 三处 UI 的「无」状态,后面几条都用它
|
||||
const selectedShapeState = () => page.evaluate(() => {
|
||||
const d = window.__iwbEditor.__debug()
|
||||
const s = d.shapes.find(x => x.id === d.selectedShapeId)
|
||||
const btn = document.querySelector('.iwb-editor-color-pair [data-color-slot="stroke"]')
|
||||
const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
||||
const none = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
||||
return {
|
||||
type: s && s.type, closed: s && s.closed,
|
||||
strokeOn: s && s.strokeOn, fill: s && s.fill,
|
||||
color: s && s.color, fillColor: s && s.fillColor,
|
||||
strokeBtnNone: !!btn && btn.classList.contains('is-none'),
|
||||
optOff: !!opt && opt.classList.contains('is-off'),
|
||||
noneHidden: !none || none.hidden,
|
||||
noneActive: !!none && none.classList.contains('active')
|
||||
}
|
||||
})
|
||||
|
||||
// ---- 形状:去掉描边 ----
|
||||
// 描边给一个画布上没出现过的洋红,靠像素数证明「框真的没了」而不是只改了数据
|
||||
await drawRectAt(0.55, 0.52, 0.82, 0.74)
|
||||
await setOptColor('fill', '#0aa6c8')
|
||||
await page.waitForTimeout(160)
|
||||
await setOptColor('stroke', '#ff00aa')
|
||||
await page.waitForTimeout(220)
|
||||
// 按画布分别数:画布上还躺着别的早期用例留下的同色对象(文字就用了 #ff00aa),
|
||||
// 全局求和会把它们算进来 —— 只认「某一个画布从有变没有」才说得清这条描边真的没了
|
||||
const magentaPerCanvas = () => page.evaluate(() => [...document.querySelectorAll('.iwb-editor-vec-canvas')].map(cv => {
|
||||
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||||
let n = 0
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
if (d[i + 3] > 200 && Math.abs(d[i] - 255) < 8 && d[i + 1] < 8 && Math.abs(d[i + 2] - 170) < 8) n++
|
||||
}
|
||||
return n
|
||||
}))
|
||||
const magentaBefore = await magentaPerCanvas()
|
||||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||
await page.waitForTimeout(220)
|
||||
const noneShownOnStroke = await page.evaluate(() =>
|
||||
!document.querySelector('.iwb-editor-color-pop [data-color-none]').hidden)
|
||||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||
await page.waitForTimeout(320)
|
||||
const noStroke = await selectedShapeState()
|
||||
const magentaAfter = await magentaPerCanvas()
|
||||
const cyanStill = await countColorInVec([10, 166, 200], 8)
|
||||
const strokeGone = magentaBefore.some((n, i) => n > 300 && magentaAfter[i] === 0)
|
||||
const noNewMagenta = magentaAfter.every((n, i) => n <= magentaBefore[i])
|
||||
check('形状可以去掉描边:描边像素清零,填充色与描边色都留着',
|
||||
noneShownOnStroke && strokeGone && noNewMagenta &&
|
||||
noStroke.strokeOn === false && noStroke.fill === true &&
|
||||
noStroke.color === '#ff00aa' && cyanStill > 300,
|
||||
JSON.stringify({ noneShownOnStroke, magentaBefore, magentaAfter, cyanStill, ...noStroke }))
|
||||
check('无描边时工具栏描边格画斜杠、选项栏描边色块置灰、色板「无」高亮',
|
||||
noStroke.strokeBtnNone === true && noStroke.optOff === true && noStroke.noneActive === true,
|
||||
JSON.stringify({ btn: noStroke.strokeBtnNone, opt: noStroke.optOff, none: noStroke.noneActive }))
|
||||
|
||||
// 选色即恢复描边:与「文字描边宽度 0 时选色自动给 6px」同一条逻辑,
|
||||
// 否则用户选了颜色画面没变化,会以为颜色设置坏了
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||
el.value = '#ff00aa'
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
await page.waitForTimeout(320)
|
||||
const revivedStroke = await selectedShapeState()
|
||||
const magentaRevived = await magentaPerCanvas()
|
||||
const strokeBack = magentaRevived.some((n, i) => n > 300 && magentaAfter[i] === 0)
|
||||
check('无描边时再选一次颜色 → 自动恢复描边(选了色一定有变化)',
|
||||
revivedStroke.strokeOn === true && revivedStroke.color === '#ff00aa' && strokeBack,
|
||||
JSON.stringify({ ...revivedStroke, strokeBack, magentaAfter, magentaRevived }))
|
||||
|
||||
// ---- 钢笔闭合路径:同样能去掉描边 ----
|
||||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||||
const t1 = { x: imgBox.x + imgBox.width * 0.34, y: imgBox.y + imgBox.height * 0.16 }
|
||||
const t2 = { x: imgBox.x + imgBox.width * 0.46, y: imgBox.y + imgBox.height * 0.16 }
|
||||
const t3 = { x: imgBox.x + imgBox.width * 0.40, y: imgBox.y + imgBox.height * 0.34 }
|
||||
await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(90)
|
||||
await page.mouse.click(t2.x, t2.y); await page.waitForTimeout(90)
|
||||
await page.mouse.click(t3.x, t3.y); await page.waitForTimeout(90)
|
||||
await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(280) // 回到起点 = 闭合
|
||||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||
await page.waitForTimeout(220)
|
||||
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||
await page.waitForTimeout(320)
|
||||
const penNoStroke = await selectedShapeState()
|
||||
check('钢笔闭合路径也能去掉描边(去掉后只剩填充面,不会整个消失)',
|
||||
penNoStroke.type === 'pen' && penNoStroke.closed === true &&
|
||||
penNoStroke.strokeOn === false && penNoStroke.fill === true,
|
||||
JSON.stringify(penNoStroke))
|
||||
|
||||
// 未闭合路径没有可填内部:去掉描边 = 这条线没了,索性不给「无」
|
||||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||||
await page.mouse.click(imgBox.x + imgBox.width * 0.62, imgBox.y + imgBox.height * 0.36)
|
||||
await page.waitForTimeout(90)
|
||||
await page.mouse.click(imgBox.x + imgBox.width * 0.76, imgBox.y + imgBox.height * 0.42)
|
||||
await page.waitForTimeout(90)
|
||||
await page.keyboard.press('Enter') // 回车结束开放路径
|
||||
await page.waitForTimeout(280)
|
||||
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||
await page.waitForTimeout(220)
|
||||
const openPen = await selectedShapeState()
|
||||
check('未闭合钢笔不给「无描边」(去掉等于把这条线删了)',
|
||||
openPen.type === 'pen' && openPen.closed === false && openPen.noneHidden === true,
|
||||
JSON.stringify(openPen))
|
||||
|
||||
// ---- 一边无色也能交换(用户反馈的第二个问题)----
|
||||
await page.keyboard.press('Escape')
|
||||
await drawRectAt(0.08, 0.10, 0.30, 0.30)
|
||||
// 先做成「只有描边」:fill 关掉,描边给独立色
|
||||
await page.evaluate(() => {
|
||||
const btn = document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="stroke"]')
|
||||
if (btn) btn.click()
|
||||
})
|
||||
await page.waitForTimeout(200)
|
||||
await setOptColor('stroke', '#ff00aa')
|
||||
await page.waitForTimeout(220)
|
||||
const onlyStroke = await selectedShapeState()
|
||||
await page.keyboard.press('Shift+x')
|
||||
await page.waitForTimeout(260)
|
||||
const afterSwap1 = await selectedShapeState()
|
||||
await page.keyboard.press('Shift+x')
|
||||
await page.waitForTimeout(260)
|
||||
const afterSwap2 = await selectedShapeState()
|
||||
check('一边无色也能交换:只描边 → 只填充(描边关、填充开),再按回到原样',
|
||||
onlyStroke.strokeOn === true && onlyStroke.fill === false &&
|
||||
afterSwap1.strokeOn === false && afterSwap1.fill === true &&
|
||||
afterSwap2.strokeOn === true && afterSwap2.fill === false,
|
||||
JSON.stringify({ 原: onlyStroke, 按一次: afterSwap1, 再按: afterSwap2 }))
|
||||
|
||||
// ================================================================
|
||||
// v1.15 图片调节(放最后:会改像素,放中间会污染依赖像素的用例)
|
||||
// ================================================================
|
||||
@@ -2553,6 +2706,73 @@ check('右侧栏出现「图片调节」,11 项齐全且顺序固定',
|
||||
adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度',
|
||||
'rows=' + adjRowCount + ' ' + adjNames.join('/'))
|
||||
|
||||
// ---------- v1.16:右栏常驻调色面板 / 两处同步 / 可拖宽度 / 字号 ----------
|
||||
const sideSurface = await page.evaluate(() => {
|
||||
const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]')
|
||||
if (!side) return null
|
||||
const tabs = [...side.querySelectorAll('.iwb-color-pop-tab')]
|
||||
return {
|
||||
tabs: tabs.length,
|
||||
visibleTabs: tabs.filter(t => !t.hidden).length,
|
||||
swatches: side.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]').length,
|
||||
sv: !!side.querySelector('.iwb-color-sv'),
|
||||
hue: !!side.querySelector('.iwb-color-hue'),
|
||||
hex: !!side.querySelector('.iwb-editor-color-hex-input')
|
||||
}
|
||||
})
|
||||
check('右栏有常驻调色面板:可调颜色项 + 调色器 + 12 个常用色',
|
||||
Boolean(sideSurface) && sideSurface.tabs === 3 && sideSurface.visibleTabs >= 1 &&
|
||||
sideSurface.swatches === 12 && sideSurface.sv && sideSurface.hue && sideSurface.hex,
|
||||
JSON.stringify(sideSurface))
|
||||
|
||||
// 在右栏点常用色 → 弹层里同一色块也必须高亮(两处共用一份颜色状态)
|
||||
await page.locator('.iwb-editor-left [data-color-surface="side"] [data-panel-color="#00bfa5"]').click()
|
||||
await page.waitForTimeout(220)
|
||||
const colorSync = await page.evaluate(() => {
|
||||
// 只看「常用色」网格:最近使用里同色也会高亮,那是正常的两处提示,不该算进断言
|
||||
const activeIn = (root) => [...root.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
|
||||
.filter(b => b.classList.contains('active')).map(b => b.dataset.panelColor)
|
||||
const side = document.querySelector('.iwb-editor-left [data-color-surface="side"]')
|
||||
const pop = document.querySelector('.iwb-editor-color-pop')
|
||||
return { side: activeIn(side), pop: activeIn(pop), color: window.__iwbEditor.__debug().color }
|
||||
})
|
||||
check('右栏选色后弹层同一色块同步高亮(不是两套各管各的)',
|
||||
colorSync.side.length === 1 && colorSync.side[0] === '#00bfa5' &&
|
||||
colorSync.pop.length === 1 && colorSync.pop[0] === '#00bfa5' && colorSync.color === '#00bfa5',
|
||||
JSON.stringify(colorSync))
|
||||
|
||||
// 拖右栏宽度:侧栏在画布右侧,指针左移 80px ⇒ 宽 80px
|
||||
const sideW0 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||
const grip = await page.locator('.iwb-editor-side-resizer').boundingBox()
|
||||
await page.mouse.move(grip.x + grip.width / 2, grip.y + grip.height / 2)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(grip.x + grip.width / 2 - 80, grip.y + grip.height / 2, { steps: 8 })
|
||||
await page.mouse.up()
|
||||
await page.waitForTimeout(180)
|
||||
const sideW1 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||
check('拖右栏手柄:宽度随拖动变大(不是固定 220)',
|
||||
sideW1 >= sideW0 + 70 && sideW1 <= 520, sideW0 + ' → ' + sideW1)
|
||||
|
||||
await page.locator('.iwb-editor-side-resizer').dblclick()
|
||||
await page.waitForTimeout(180)
|
||||
const sideW2 = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width))
|
||||
// 注意:aside 是 content-box,width 280 + 左右 padding 24 ⇒ rect 约 304/305。
|
||||
// 这里跟「拖之前」比才对,写死 280 会误判。
|
||||
check('双击手柄复位到默认宽度(回到拖动前)', Math.abs(sideW2 - sideW0) <= 2, sideW0 + ' ← ' + sideW2)
|
||||
|
||||
const fontSizes = await page.evaluate(() => ({
|
||||
adjName: getComputedStyle(document.querySelector('.iwb-editor-adj-name')).fontSize,
|
||||
adjTitle: getComputedStyle(document.querySelector('.iwb-editor-adj-title')).fontSize,
|
||||
statusbar: getComputedStyle(document.querySelector('.iwb-editor-statusbar')).fontSize,
|
||||
optionbar: getComputedStyle(document.querySelector('.iwb-editor-optionbar')).fontSize,
|
||||
layerName: document.querySelector('.iwb-layer-name') ? getComputedStyle(document.querySelector('.iwb-layer-name')).fontSize : null
|
||||
}))
|
||||
check('整体字号提升一档(面板行名 12.5 / 标题 13 / 状态栏 12 / 选项栏 13)',
|
||||
fontSizes.adjName === '12.5px' && fontSizes.adjTitle === '13px' &&
|
||||
fontSizes.statusbar === '12px' && fontSizes.optionbar === '13px' &&
|
||||
(!fontSizes.layerName || fontSizes.layerName === '13px'),
|
||||
JSON.stringify(fontSizes))
|
||||
|
||||
/** 合成整幅可见像素后统计:平均亮度 / 灰像素占比 / R、B 均值 */
|
||||
const adjStat = () => page.evaluate(() => {
|
||||
const list = [...document.querySelectorAll('.iwb-editor-layer-canvas')]
|
||||
|
||||
Reference in new issue
Block a user