Compare commits

...
Author SHA1 Message Date
qiqi 9c938887c1 feat(image-annotate): v1.11.0 工具栏改为描边/填充双色槽,填充支持「无」
用户反馈:「工具栏的调色、描边、填充 3 个位置调色有问题,应该是 2 个调色,
就是描边与填充,但现在没跟工具栏的调色关联上」+「填色里还要一个取消颜色的按钮」。

问题是真的:工具栏只有一个色点(主色),选项栏另有两个色块。看起来三个调色口,
但工具栏那个**不参与填充**——填充只能在选项栏那个小色块里改,于是「填充跟工具栏
没关系」。颜色值本身也没错,错在入口分散、各自为政。

1) 工具栏改成「描边 + 填充」两个槽(PS 式前后色叠放,30px 位里两颗 19px)
   - 描边槽 = S.color(同时是画笔色/文字色/形状描边色,仍是一个值)
   - 填充槽 = 形状自己的 fillColor;null 时跟随描边色,右下角画蓝三角标出来
   - S.colorTarget 记录「色板在调哪一格」,调色器/SV/hex/吸管/推荐色/最近色
     全部经 applyPanelColor 按目标写,不再一律写主色
   - 点另一个槽只换目标、不收起弹层,「描边改完顺手改填充」不用开关两次
   - 选项栏 data-shape-color 两个色块与工具栏**双向同步**(都走 colorSlots())

2) colorSlots() 成为唯一取值处:工具栏色块、色板头部、hex、SV 标记全从它读,
   避免上一版那类「同一个概念算两遍必然分叉」。syncOptionBar 收尾调 updateColorUI,
   于是「选中对象 → 选项栏显示它的颜色 → 工具栏跟着换」自动成立。

3) 填充可以设「无」:色板里「无」(只在调填充时出现)把 fill 关掉,
   形状内部透明只留描边,**颜色保留**(下次点颜色还是它)。
   无填充时工具栏填充槽显示灰底红斜杠,不露颜色——露着上次的颜色会被当成
   「现在填的就是它」。fillSlotOn() 判定当前上下文有没有填充概念:
   箭头没内部、未闭合钢笔没面积、画笔/文字根本没有,这些情况只显示一格。

4) 槽位命名随工具变:文字工具下叫「文字」、画笔下叫「画笔」、形状下叫「描边」。
   一律写「描边」会让文字工具下的用户以为这个颜色跟自己没关系。

harness 172 → 179 条全通(新增:两格都在且可见、点填充槽后目标是填充、
色板选色只进填充不动主色、无填充清空画面但保留颜色、无填充显示斜杠、
选项栏改色工具栏跟随、画笔只一格);validate 9/9。
harness 顺带修两处:toggleColorPop 选择器要指定槽位(现在有两个按钮);
无填充的像素断言改用画布上不存在的 #a014b2,否则会数到前面用例留下的图形。
2026-11-08 21:52:35 +08:00
qiqi b63771f6e4 feat(image-annotate): v1.10.0 颜色语义统一、选中框改实线、选区命令归位、矢量图形补描边与填充
四个问题来自同一张界面截图,都是真缺陷。

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
(以前只看全局默认值,选中已实心的矩形却高亮「描边」,和画面反着来)。

顺带简化:文本样式与形状颜色共用同一套色块控件与 CSS,is-off 用斜纹 +
虚线边框;底色色块用 --sw-a 变量体现半透明。

harness 162 → 172 条全通(新增:默认色不写死、色块生效态、选区命令归位、
选中框实线覆盖率 ≥0.85、图形描边/填充色与实际像素);validate 9/9。
harness 自身两处改法:清选中改用「切到别的工具再切回」(画布上早有别的用例
留下的图形,点空白会点到它们);像素断言改成全画布统计同色像素
(矢量画布含 overlayPad 外扩,按图片坐标换算单点会采到别处)。
2026-11-08 21:24:38 +08:00
14 changed files with 1250 additions and 322 deletions

No files matched your search

+73
View File
@@ -234,6 +234,79 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
## 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 上线后用户反馈的三处「操作与实际反应不相符」。
+2
View File
@@ -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 迭代降质、下载、设置记忆;无队列 |
| 颜色体系与矢量属性 | ✅ v1.11.0:颜色收敛为**描边 / 填充两格**——工具栏改 PS 式双色槽(`S.colorTarget` 决定色板写哪一格),选项栏两色块与工具栏双向同步,`colorSlots()` 成为唯一取值处;填充支持**无**(`fill=false`,颜色保留,槽位画灰底红斜杠);画笔/文字/箭头等无填充概念的工具只显示一格 |
| 颜色体系与矢量属性(v1.10) | ✅ v1.10.0:默认值收口到 `TEXT_DEFAULTS`(文字底色去掉纯黑);三个色块标记「生效/未生效」(未生效显示灰色斜纹);对象选中框改实线(虚线只留给像素选区);选区命令归位到矩形/套索选区工具;矢量图形新增独立 `fillColor`,描边色复用主色,选项栏出 `描边 ■ / 填充 ■` 色块,填充缺省跟随描边 |
| 文字样式与吸附 | ✅ v1.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/image-annotate",
"private": true,
"version": "1.9.1",
"version": "1.11.0",
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
"ibwPlugin": {
"id": "image-annotate",
+83 -9
View File
@@ -1713,26 +1713,85 @@
================================================================ */
.iwb-editor-modal { position: relative; }
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn {
width: 32px; height: 32px; min-width: 32px; flex: 0 0 auto; padding: 0;
border: 0; border-radius: 9px; background: #313244; cursor: pointer;
/* ---- v1.11:工具栏颜色双槽(描边 + 填充) ----
一个 30px 的按钮位上叠两颗:左上 19px 是描边,右下 19px 是填充。
描边压在上面(最常用),填充露出右下角,一眼能看出是两格、谁是上级。
只有「描边」概念的工具(画笔/文字/箭头)把填充槽藏起来,描边槽放大占满,
不留一个空位让人猜。 */
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-pair {
position: relative; width: 30px; height: 30px; flex: 0 0 auto;
}
.iwb-editor-color-pair .iwb-editor-color-btn {
position: absolute; width: 19px; height: 19px; min-width: 0; padding: 0;
border: 0; border-radius: 6px; background: #181825; cursor: pointer;
display: inline-flex; align-items: center; justify-content: center;
box-shadow: 0 0 0 1.5px #585b70;
}
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn:hover,
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn.active { background: #45475a; }
.iwb-editor-color-btn i {
width: 18px; height: 18px; border-radius: 50%; display: block; background: #ff4444;
box-shadow: 0 0 0 2px #181825, 0 0 0 3px #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; }
.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;
background: rgba(24, 24, 37, 0.97); border: 1px solid #313244;
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.iwb-editor-color-pop[hidden] { display: none; }
/* 弹层头部:说明现在调的是描边还是填充,并可直接换;右侧是「无」(仅填充) */
.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-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; }
@@ -1896,6 +1955,21 @@
}
.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 {
+18 -2
View File
@@ -130,8 +130,14 @@ import { bindEvents } from './events.js'
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
</div>
<div class="iwb-editor-tools">
<!-- 当前色圆点(v1.3):点开就是完整色板,侧栏不再放调色板 -->
<button type="button" class="iwb-editor-color-btn" data-action="toggleColorPop" aria-expanded="false" title="颜色:点开色板(调色器 / 吸管 / 推荐色)"><i></i></button>
<!-- 颜色(v1.11):描边 + 填充 两个槽叠放在一个按钮位里(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>
</div>
<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>
<span class="iwb-editor-divider"></span>
@@ -231,6 +237,15 @@ import { bindEvents } from './events.js'
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
<div class="iwb-editor-color-pop" hidden>
<!-- 弹层头部(v1.11):标明「现在调的是哪个颜色」,并可直接切换。
与工具栏那两个色块是同一组槽位,两边高亮完全一致。
「无」只对填充有意义:描边关掉会让形状彻底消失,不是用户要的。 -->
<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-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>
@@ -257,6 +272,7 @@ import { bindEvents } from './events.js'
<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>
+330 -72
View File
@@ -17,6 +17,8 @@ import { showSelectionContext, hideSelectionContext } from './floating.js'
import { applyConstraintDrag, cancelCrop, clearOverlay, confirmCrop, drawCropPreview, hideCropBar, hitCropHandle, insideRect, resizeCropRect, setConstraint, showCropBar, updateCropInfo } from './crop.js'
import { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, otherObjectBoxes, renderObjects, selectNeighborLayer, selectUnit, shapeBounds, showTextInput, textBounds } from './objects.js'
import { snapMove } from './snap.js'
import { TEXT_DEFAULTS, TEXT_LINE_HEIGHT } from './text.js'
import { rememberColor } from './recent-colors.js'
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
import { close, copyResult, exportResult } from './index.js'
import { loadImage } from './dom.js'
@@ -255,11 +257,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
showTextInput(pos.x, pos.y)
}
/** 吸管工具的按下:取样并应用颜色后退出吸管模式 */
/** 吸管工具的按下:取样并应用颜色后退出吸管模式。
* v1.11:按当前目标槽写(吸管取色 = 给正在调的那一格上色,而不是永远改主色)。 */
function onPickerMouseDown(pos) {
const s = sampleColor(pos)
if (s && s.a > 0) {
applyColorChange(rgbToHex(s.r, s.g, s.b))
applyPanelColor(rgbToHex(s.r, s.g, s.b))
}
exitPicker()
return
@@ -535,6 +538,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
x1: S.startX, y1: S.startY,
x2: pos.x, y2: pos.y,
color: S.color,
fillColor: S.shapeFillColor,
lw: Math.max(1, S.shapeLineWidth),
lineWidth: Math.max(1, S.shapeLineWidth),
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
@@ -740,6 +744,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
x1: S.startX, y1: S.startY,
x2: pos.x, y2: pos.y,
color: S.color,
fillColor: S.shapeFillColor, // null = 跟随描边色(改主色时整块跟着变)
lw: Math.max(1, S.shapeLineWidth),
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
@@ -860,22 +865,102 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
}
}
/** 当前上下文里「填充」这个概念到底存不存在。
* 箭头只有一条线没有内部;未闭合的钢笔路径也没有可填面积 —— 这两种情况
* 不该给填充色块,否则用户设了颜色画面上没有任何变化,又是一次「坏了」。 */
function fillSlotOn() {
const sh = getSelectedShape()
if (sh) return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
return S.tool === 'rect' || S.tool === 'circle' || S.tool === 'pen'
}
/** 描边 / 填充两个槽的显示值(v1.11)。
* **唯一的取值处**:工具栏色块、色板头部、hex、SV 调色器全从这里读,
* 避免「一个概念三种颜色」再次出现。
* 描边 = 主色(选中形状时读它自己的);填充 = 形状自己的 fillColor,
* 没单独设过(null)就跟随描边色,此时 follow=true。 */
export function colorSlots() {
const sh = getSelectedShape()
const stroke = (sh && sh.color) || S.color
const rawFill = sh ? (sh.fillColor || null) : S.shapeFillColor
const fillOn = sh
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
return { stroke, fill: rawFill || stroke, fillOn, follow: !rawFill }
}
/** 色板/hex/吸管要写的那一格颜色 */
function activeColor() {
const sl = colorSlots()
return S.colorTarget === 'fill' ? sl.fill : sl.stroke
}
export function updateColorUI() {
const sl = colorSlots()
const fillable = fillSlotOn()
// 当前上下文没有填充(切到画笔/文字/箭头,或选中了箭头):把「正在调填充」的状态
// 归位,否则工具栏会高亮一个已经隐藏的槽,色板也停在一个不存在的目标上。
if (!fillable && S.colorTarget === 'fill') S.colorTarget = 'stroke'
// 工具栏:两个槽都按真实值上色,填充关掉时画斜杠、跟随描边时带角标
const pair = runtime.el.querySelector('.iwb-editor-color-pair')
if (pair) pair.dataset.colorMode = fillable ? 'pair' : 'single'
const strokeBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="stroke"]')
const fillBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="fill"]')
// 同一个槽在不同工具下叫法不同:调文字时它改的是文字色,调画笔时是画笔色。
// 一律写「描边」会让人在文字工具下以为这个颜色跟文字没关系。
const textCtx = S.tool === 'text' || (!!S.selectedTextId && S.tool === 'select')
const strokeName = textCtx ? '文字' : (S.tool === 'brush' || S.tool === 'eraser' ? '画笔' : '描边')
if (strokeBtn) {
const dot = strokeBtn.querySelector('i')
if (dot) dot.style.backgroundColor = sl.stroke
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
strokeBtn.title = fillable
? `描边色 ${sl.stroke.toUpperCase()}:形状描边也用这个值。点开色板调色`
: `${strokeName}色 ${sl.stroke.toUpperCase()}:点开色板调色`
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
}
if (fillBtn) {
const dot = fillBtn.querySelector('i')
if (dot) dot.style.backgroundColor = sl.fill
fillBtn.classList.toggle('is-none', !sl.fillOn)
fillBtn.classList.toggle('is-follow', sl.follow && sl.fillOn)
fillBtn.classList.toggle('active', S.colorTarget === 'fill')
fillBtn.title = !sl.fillOn
? '填充:无(形状内部透明)。点开色板选色即可填充'
: (sl.follow ? '填充色:跟随描边色 ' + sl.fill.toUpperCase() + ',点开可单独指定' : '填充色 ' + sl.fill.toUpperCase() + ',点开调色')
}
// 色板头部:两个 tab 与工具栏两个槽同步高亮,「无」只在调填充时出现
runtime.el.querySelectorAll('.iwb-color-pop-tab').forEach(tab => {
const isFill = tab.dataset.colorSlot === 'fill'
tab.classList.toggle('active', S.colorTarget === (isFill ? 'fill' : 'stroke'))
const dot = tab.querySelector('i')
if (dot) dot.style.backgroundColor = isFill ? sl.fill : sl.stroke
const label = tab.querySelector('.iwb-color-pop-tab-label')
// 只有一根槽时,标题写「描边」会显得莫名其妙:这时它就是当前的唯一颜色
if (label) label.textContent = isFill ? '填充' : (fillable ? '描边' : strokeName)
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !fillable }
})
const noneBtn = runtime.el.querySelector('[data-color-none]')
if (noneBtn) {
const show = fillable && S.colorTarget === 'fill'
noneBtn.hidden = !show
noneBtn.classList.toggle('active', show && !sl.fillOn)
}
const cur = activeColor()
let matchPreset = false
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
const on = (s.dataset.color || '').toLowerCase() === S.color.toLowerCase()
const on = (s.dataset.color || '').toLowerCase() === cur.toLowerCase()
if (on) matchPreset = true
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 = S.color.toUpperCase()
// 工具栏色点:色板收起时它就是唯一的颜色指示,必须始终跟随 S.color
const colorDot = runtime.el.querySelector('.iwb-editor-color-btn i')
if (colorDot) colorDot.style.background = S.color
runtime.el.querySelectorAll('.iwb-editor-color-panel-swatch').forEach(sw => sw.classList.toggle('active', (sw.dataset.panelColor || '').toLowerCase() === S.color.toLowerCase()))
if (panelHex) panelHex.textContent = S.color.toUpperCase()
const rgb = hexToRgb(S.color)
if (hexInput && document.activeElement !== hexInput) hexInput.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
@@ -890,7 +975,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (custom) {
custom.classList.toggle('active', !matchPreset)
const inp = custom.querySelector('input')
if (inp) inp.value = S.color
if (inp) inp.value = cur
}
}
@@ -972,11 +1057,31 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
/** 描边/实心切换按钮组:owner 区分两套默认值(rect=矩形/圆,pen=钢笔)。
* 钢笔只在闭合路径上才有填充面积,但开关本身一直可点,便于先选后画。 */
function fillStyleHTML(owner) {
const fill = owner === 'pen' ? S.penFill : S.rectFill
/** 矢量图形的描边色 / 填充色块(v1.10)。
* 描边色就是主色 S.color —— 左侧色板、吸管、选项栏三处读写同一个值,
* 不再为「形状描边」单独造一个色,否则又是一处「同一个概念两个颜色」。
* 填充色独立存在形状自己的 fillColor 上,没单独设过就跟随描边色(同色实心)。
* 填充关着的时候色块置灰(is-off),一眼能看出哪个颜色正在生效。 */
function shapeColorHTML(sh, owner) {
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
const sl = colorSlots()
let html = '<span class="iwb-opt-label">描边</span>'
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`
if (owner) {
html += '<span class="iwb-opt-label">填充</span>'
+ `<input type="color" class="iwb-opt-color${sl.fillOn ? '' : ' is-off'}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? '' : ';当前无填充,选色会自动切成实心'}">`
}
return html
}
function fillStyleHTML(owner, sh) {
// 选中对象时以它自己的 fill 为准:以前只看全局 S.rectFill,
// 选中一个已经实心的矩形,选项栏却高亮「描边」,按钮和画面反着来。
const own = !!sh && (owner === 'pen' ? sh.type === 'pen' : (sh.type === 'rect' || sh.type === 'circle'))
const fill = own ? !!sh.fill : (owner === 'pen' ? S.penFill : S.rectFill)
return `<span class="iwb-opt-label">样式</span>
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="描边 (Shift+X 切换)">描边</button>
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心 (Shift+X 切换)">实心</button>`
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边 (Shift+X 切换)">描边</button>
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`
}
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
@@ -999,11 +1104,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
return {
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
align: pick('align', 'textAlign', 'left'),
lineHeight: Number(pick('lineHeight', 'textLineHeight', 1.25)) || 1.25,
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', 0)) || 0),
strokeColor: pick('strokeColor', 'textStrokeColor', '#ffffff'),
bgFill: !!pick('bgFill', 'textBgFill', false),
bgColor: pick('bgColor', 'textBgColor', '#000000')
lineHeight: Number(pick('lineHeight', 'textLineHeight', TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', TEXT_DEFAULTS.strokeWidth)) || 0),
strokeColor: pick('strokeColor', 'textStrokeColor', TEXT_DEFAULTS.strokeColor),
bgFill: !!pick('bgFill', 'textBgFill', TEXT_DEFAULTS.bgFill),
bgColor: pick('bgColor', 'textBgColor', TEXT_DEFAULTS.bgColor),
bgAlpha: Number(pick('bgAlpha', 'textBgAlpha', TEXT_DEFAULTS.bgAlpha)) || TEXT_DEFAULTS.bgAlpha
}
}
@@ -1021,9 +1127,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
<span class="iwb-opt-sep"></span>
<span class="iwb-opt-label">描边</span>
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
<input type="color" class="iwb-opt-color" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色">
<button class="iwb-opt-btn${v.bgFill ? ' active' : ''}" data-opt-text="bgFill" data-value="${v.bgFill ? '0' : '1'}" title="给文字加一块半透明底色,压在花背景上也能看清">底色</button>
<input type="color" class="iwb-opt-color" data-opt-color="bgColor" value="${v.bgColor}" title="底色颜色;选色会自动开启底色,不用先点左侧按钮">`
<input type="color" class="iwb-opt-color${v.strokeWidth > 0 ? '' : ' is-off'}" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色${v.strokeWidth > 0 ? '' : ';描边宽度是 0,选色会自动给 6px'}">
<button class="iwb-opt-btn${v.bgFill ? ' active' : ''}" data-opt-text="bgFill" data-value="${v.bgFill ? '0' : '1'}" title="给文字加一块底色,压在花背景上也能看清">底色</button>
<input type="color" class="iwb-opt-color${v.bgFill ? '' : ' is-off'}" data-opt-color="bgColor" value="${v.bgColor}" style="--sw-a:${v.bgAlpha}" title="底色 ${Math.round(v.bgAlpha * 100)}% 不透明(色块按真实半透明显示);选色会自动开启底色">`
}
/** 选择工具:只有选中了元素才出该元素的参数。
@@ -1054,21 +1160,22 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
// 圆角只对矩形有意义(圆形本来就是圆的,箭头/钢笔没有这个概念)
+ (t === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, Math.round(sh.radius || 0), 'px') : '')
+ (t === 'arrow' ? '' : fillStyleHTML(owner))
// 描边色 / 填充色:箭头没有填充区域,只给描边色
+ shapeColorHTML(sh, t === 'arrow' ? null : owner)
+ (t === 'arrow' ? '' : fillStyleHTML(owner, sh))
+ (t === 'pen' && !sh.closed
? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>'
: '')
+ selCmdHTML()
}
}
const text = getSelectedText()
if (text) {
// v1.10:这里**不再**放「全选/反选/取消选区」那三个按钮。
// 用户反馈:选中一段文字时选项栏冒出选区命令,看着像「文字自带了一个选区」;
// 那三个命令操作的是像素选区(蚂蚁线),跟文字对象没关系,已归位到选区工具。
return `<span class="iwb-opt-current">已选中:文字</span>`
+ rangeOpt('textSize', '字号', 8, 400, Math.round(text.fontSize || S.textSize), 'px')
+ textStyleHTML(text)
// 控件齐全时这一行很挤,说明文字必须排在按钮之后:
// 真放不下时宁可把 hint 滚出视野,也不能把「复制/取消选区」这些按钮顶没了
+ selCmdHTML()
+ '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>'
}
// 选区命令是全局的,跟「有没有选中元素」无关:没选中时也必须能全选/反选/取消。
@@ -1098,16 +1205,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
+ (tool === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, S.shapeRadius, 'px') : '')
+ shapeColorHTML(null, 'rect')
+ fillStyleHTML('rect')
}
if (tool === 'arrow') {
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
+ shapeColorHTML(null, null)
+ '<span class="iwb-opt-hint">拖出箭头,松手完成</span>'
}
if (tool === 'pen') {
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
+ shapeColorHTML(null, 'pen')
+ fillStyleHTML('pen')
+ '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>'
}
@@ -1117,15 +1227,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
+ '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>'
}
if (tool === 'marquee') {
// 选区命令归位(v1.10):全选/反选/取消选区属于「像素选区」,就该待在选区工具里,
// 而不是跟着文字/图形选中态到处跑。必须排在 hint 之前(hint 带 margin-left:auto)。
return `<span class="iwb-opt-label">形状</span>
<button class="iwb-opt-btn${S.selectionKind === 'rect' ? ' active' : ''}" data-opt="shape" data-value="rect">矩形</button>
<button class="iwb-opt-btn${S.selectionKind === 'ellipse' ? ' active' : ''}" data-opt="shape" data-value="ellipse">椭圆</button>
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>
<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>`
+ selCmdHTML()
+ `<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`
}
if (tool === 'lasso') {
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>
<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>`
+ selCmdHTML()
+ `<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`
}
return `<span class="iwb-opt-current">当前工具:${TOOL_NAMES[tool] || tool}</span>
<span class="iwb-opt-hint">${OPT_HINTS[tool] || '选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层'}</span>`
@@ -1201,10 +1315,36 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
btn.classList.toggle('active', String(sv[k]) === btn.dataset.value)
})
body.querySelectorAll('[data-opt-color]').forEach(inp => {
if (document.activeElement === inp) return
const v = sv[inp.dataset.optColor]
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
const k = inp.dataset.optColor
if (document.activeElement !== inp) {
const v = sv[k]
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
}
// 「正在生效」态:描边宽度 0 时描边色没起作用,底色没开时底色没起作用。
// 三个色块长得一模一样是上一版最误导的地方 —— 用户会以为「字体颜色有三处」。
if (k === 'strokeColor') inp.classList.toggle('is-off', !(sv.strokeWidth > 0))
if (k === 'bgColor') inp.classList.toggle('is-off', !sv.bgFill)
})
// 矢量图形的描边/填充色块(选中对象读对象自己的值,没选中读新建默认值)
body.querySelectorAll('[data-shape-color]').forEach(inp => {
const kind = inp.dataset.shapeColor
const sl = colorSlots()
const v = kind === 'fill' ? sl.fill : sl.stroke
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
if (kind === 'fill') {
// 无填充时也标成「未生效」:色块上留着上次的颜色很容易被当成「现在就是填充色」
inp.classList.toggle('is-off', !sl.fillOn)
inp.title = sl.fillOn
? '填充色:与工具栏右下的填充色块是同一份'
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
} else {
inp.title = '描边色:与工具栏左上的描边色块是同一份'
}
})
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
// 否则会出现「选中一个矩形 → 选项栏显示它的颜色 → 工具栏还停在上一格」。
// updateColorUI 不回调 syncOptionBar,不会递归。
updateColorUI()
}
/** 状态栏:缩放 / 尺寸 / 光标 / 选区 / 当前层 / 工具 */
@@ -1267,23 +1407,24 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (key === 'bgFill') value = raw === true || raw === 1 || raw === '1' || raw === 'true'
else if (key === 'lineHeight') value = clamp(Number(raw) || 125, 80, 300) / 100
else if (key === 'strokeWidth') value = clamp(Number(raw) || 0, 0, 40)
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || '#000000').toLowerCase()
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase()
else value = String(raw)
S[stateKey] = value
// 「选了颜色就说明想用它」:描边宽度 0 / 底色没开的时候选色,画布上一点变化都没有,
// 会被当成「颜色坏了 / 被别的图层盖住」。顺手把开关打开,所见即所得。
if (key === 'strokeColor' && !(Number(S.textStrokeWidth) > 0)) S.textStrokeWidth = 6
if (key === 'bgColor' && !S.textBgFill) S.textBgFill = true
const t = getSelectedText()
if (!t || t.locked) { textStyleSnapDone = false; return }
if (!t || t.locked) { textStyleSnapDone = false; syncOptionBar(); return }
if (committed || !textStyleSnapDone) { saveSnapshot('文字样式'); textStyleSnapDone = true }
t[key] = value
// 只调颜色、没点「底色」开关时,画布上什么都不会变 —— 这是最容易被当成
// 「底色坏了 / 被别的颜色盖住」的路径。选了颜色就说明想用它,顺手把底色打开。
if (key === 'bgColor' && !t.bgFill) {
t.bgFill = true
S.textBgFill = true
}
if (key === 'strokeColor' && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth
if (key === 'bgColor' && !t.bgFill) t.bgFill = true
renderObjects()
// 自动开启底色后按钮的 active 态与色块取值都要跟着刷新
if (key === 'bgColor') syncOptionBar()
// 自动打开描边/底色后,按钮 active 态与色块取值都要跟着刷新
if (key === 'bgColor' || key === 'strokeColor') syncOptionBar()
if (committed) textStyleSnapDone = false
}
@@ -1299,6 +1440,88 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (committed) radiusSnapDone = false
}
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
* 填充色写形状自己的 fillColor;还没切实心时选填充色顺手切实心(与文字底色同一逻辑)。
* kind='none' = 无填充:只关 fill,颜色留着不动,下次点颜色还是它。 */
function applyShapeColor(kind, raw, opts) {
const skipHistory = !!(opts && opts.skipHistory)
const sh = getSelectedShape()
const owner = sh ? (sh.type === 'pen' ? 'pen' : 'rect') : (S.tool === 'pen' ? 'pen' : 'rect')
if (kind === 'none') {
if (!fillSlotOn()) return
S.colorTarget = 'fill'
if (owner === 'pen') S.penFill = false
else S.rectFill = false
if (sh && !sh.locked && sh.fill) {
if (!skipHistory) saveSnapshot('无填充')
sh.fill = false
renderObjects()
}
updateColorUI()
syncOptionBar()
return
}
const hex = String(raw || '').toLowerCase()
if (!/^#[0-9a-f]{6}$/.test(hex)) return
if (kind === 'stroke') {
S.colorTarget = 'stroke'
applyColorChange(hex, opts)
if (skipHistory) syncOptionBarSoon()
else syncOptionBar()
return
}
S.colorTarget = 'fill'
if (skipHistory) {
// 拖 SV 时每帧都会进来:不刷「最近使用」,也不每帧拍快照
} else {
rememberColor(hex)
}
S.shapeFillColor = hex
if (owner === 'pen') S.penFill = true
else S.rectFill = true
updateFillUI()
if (sh && !sh.locked) {
if (!skipHistory) saveSnapshot('填充颜色')
sh.fillColor = hex
sh.fill = owner === 'pen' ? !!sh.closed : true
renderObjects()
}
updateColorUI()
if (skipHistory) syncOptionBarSoon()
else syncOptionBar()
}
/** 色板 / hex / 吸管 / 推荐色统一的写入口(v1.11)。
* 之前这些路径一律调 applyColorChange 写主色,于是「描边」能被色板改动、
* 「填充」只能从选项栏那个小色块改 —— 用户看到的就是「三个地方调色,
* 有一处跟别处不通」。现在按 S.colorTarget 分派,色板调到哪一格就是哪一格。 */
function applyPanelColor(color, opts) {
if (S.colorTarget === 'fill' && fillSlotOn()) { applyShapeColor('fill', color, opts); return }
if (S.colorTarget === 'fill') S.colorTarget = 'stroke' // 当前没有填充语义:退回描边,别让调色静默失效
applyColorChange(color, opts)
if (opts && opts.skipHistory) syncOptionBarSoon()
else syncOptionBar()
}
/** 切换色板正在编辑哪一格(工具栏两个色块 / 色板头部两个 tab 共用) */
function setColorTarget(slot) {
S.colorTarget = slot === 'fill' ? 'fill' : 'stroke'
updateColorUI()
}
/** 选项栏刷新合并到下一帧:拖 SV 调色时每帧重建选项栏纯属浪费,
* 但拖动结束(没有 pointerup 处理)必须保证最终值落到选项栏上。 */
let optionBarSyncRaf = 0
function syncOptionBarSoon() {
if (optionBarSyncRaf) return
optionBarSyncRaf = (typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (fn) => setTimeout(fn, 16))(() => {
optionBarSyncRaf = 0
syncOptionBar()
})
}
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个。
* owner='rect' 作用于矩形/圆,owner='pen' 作用于钢笔闭合路径。 */
function setShapeFill(fill, owner) {
@@ -1306,6 +1529,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (isPen) S.penFill = !!fill
else S.rectFill = !!fill
updateFillUI()
updateColorUI() // 填充块的斜杠(无填充)要跟着变
syncOptionBar()
const sh = getSelectedShape()
const types = isPen ? ['pen'] : ['rect', 'circle']
@@ -1444,6 +1668,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
syncOptionBar()
return
}
// 矢量图形的描边/填充色块(原生取色器关闭时才派发 change)
const shapeColorEl = e.target.closest ? e.target.closest('[data-shape-color]') : null
if (shapeColorEl) {
e.stopPropagation()
applyShapeColor(shapeColorEl.dataset.shapeColor, shapeColorEl.value)
return
}
setOptionFromControl(e.target, true)
})
body.addEventListener('click', (e) => {
@@ -1579,17 +1810,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
if (!pop || pop.hidden) return false
pop.hidden = true
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]')
if (btn) { btn.classList.remove('active'); btn.setAttribute('aria-expanded', 'false') }
runtime.el.querySelectorAll('[data-action="toggleColorPop"]').forEach(btn => {
btn.classList.remove('active')
btn.setAttribute('aria-expanded', 'false')
})
return true
}
/** 弹层定位:贴工具栏色点上方、左对齐;上方放不下翻到下方,左右夹在 modal 内。
/** 弹层定位:贴当前那一格色块上方、左对齐;上方放不下翻到下方,左右夹在 modal 内。
* 坐标用「按钮矩形 − modal 矩形」算,弹层是 modal 的绝对定位子节点,
* 这样宿主页面有 transform 时也不会错位。 */
function positionColorPop() {
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
const btn = runtime.el && runtime.el.querySelector('[data-action="toggleColorPop"]')
const btn = runtime.el && runtime.el.querySelector(`.iwb-editor-color-btn[data-color-slot="${S.colorTarget}"]`)
const modal = runtime.el && runtime.el.querySelector('.iwb-editor-modal')
if (!pop || !btn || !modal || pop.hidden) return
const mr = modal.getBoundingClientRect()
@@ -1603,40 +1836,65 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
pop.style.top = Math.round(top) + 'px'
}
function toggleColorPop() {
/** 点工具栏色块:同一格再点一次收起;点另一格直接换编辑目标(不收起),
* 这样「描边改完顺手改填充」不用开关两次弹层。 */
function toggleColorPop(slot) {
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]')
if (!pop || !btn) return
if (!pop) return
const want = slot === 'fill' ? 'fill' : 'stroke'
if (!pop.hidden && S.colorTarget === want) { closeColorPop(); return }
S.colorTarget = want
if (pop.hidden) {
pop.hidden = false // 先显示再量:hidden 元素 getBoundingClientRect 全是 0
btn.classList.add('active')
btn.setAttribute('aria-expanded', 'true')
updateColorUI()
positionColorPop()
} else {
closeColorPop()
updateColorUI()
positionColorPop()
}
}
/** 色板弹层(v1.3):工具栏色点开关;hex/吸管/推荐色/调色器都在这一个弹层里 */
/** 色板弹层(v1.3;v1.11 起同时服务描边与填充两个槽):
* 工具栏两个色块开关;tab / hex / 吸管 / 推荐色 / 调色器 / 无填充都在这一个弹层里 */
function bindColorPanel() {
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
const colorBtn = runtime.el.querySelector('[data-action="toggleColorPop"]')
if (colorBtn) {
colorBtn.addEventListener('mousedown', (e) => e.stopPropagation())
colorBtn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop() })
}
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')]
colorBtns.forEach(btn => {
btn.addEventListener('mousedown', (e) => e.stopPropagation())
btn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop(btn.dataset.colorSlot) })
})
if (pop) {
pop.addEventListener('mousedown', (e) => e.stopPropagation())
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
// 冒泡阶段拿不到「点了外面」这件事。
document.addEventListener('mousedown', (e) => {
if (!pop.hidden && !pop.contains(e.target) && !(colorBtn && colorBtn.contains(e.target))) closeColorPop()
const onBtn = colorBtns.some(b => b.contains(e.target))
if (!pop.hidden && !pop.contains(e.target) && !onBtn) closeColorPop()
}, true)
window.addEventListener('resize', positionColorPop)
}
// 独立颜色面板:颜色选择后同步当前工具颜色。
const setPanelColor = (color) => applyColorChange(color)
// 弹层头部:切描边/填充,或直接置为「无填充」
if (pop) {
pop.addEventListener('click', (e) => {
const tab = e.target.closest('[data-color-slot]')
if (tab && tab.classList.contains('iwb-color-pop-tab')) {
e.stopPropagation()
setColorTarget(tab.dataset.colorSlot)
positionColorPop()
return
}
const none = e.target.closest('[data-color-none]')
if (none) {
e.stopPropagation()
applyShapeColor('none')
return
}
})
}
// 独立颜色面板:按当前目标槽写色(描边 → 主色,填充 → 形状 fillColor)
const setPanelColor = (color) => applyPanelColor(color)
// 拖动取色期间只拍一次快照:applyColorChange 每改一次颜色都会 saveSnapshot,
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
@@ -1649,7 +1907,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (!dragSnapped) {
if (hasColorTarget()) { saveSnapshot(); dragSnapped = true }
}
applyColorChange(color, { skipHistory: true })
applyPanelColor(color, { skipHistory: true })
}
const panelHexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
if (panelHexInput) panelHexInput.addEventListener('change', () => { if (/^#[0-9a-f]{6}$/i.test(panelHexInput.value)) setPanelColor(panelHexInput.value) })
@@ -1672,7 +1930,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const sv = runtime.el.querySelector('.iwb-color-sv')
const hue = runtime.el.querySelector('.iwb-color-hue')
const initHsv = (() => {
const { r, g, b } = hexToRgb(S.color)
const { r, g, b } = hexToRgb(activeColor())
const rr = r / 255, gg = g / 255, bb = b / 255
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min
let h = 0
@@ -1698,9 +1956,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
setDragColor(hsvToHex(hueValue, satValue, valValue))
}
// 推荐色 / hex / 吸管改色时,闭包里的 h/s/v 会过期(v1.3 修:以前点了绿色再拖 SV 会跳回红色)。
// 每次按下前从 S.color 重新同步;灰阶(d=0,如 #000)反推不出色相,就沿用旧色相。
// 每次按下前从当前槽的颜色重新同步;灰阶(d=0,如 #000)反推不出色相,就沿用旧色相。
const syncFromColor = () => {
const { r, g, b } = hexToRgb(S.color)
const { r, g, b } = hexToRgb(activeColor())
const rr = r / 255, gg = g / 255, bb = b / 255
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min
if (d > 0) {
@@ -1727,18 +1985,18 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
/** 裁剪约束控件已迁入选项栏(bindLiteUI 的点击委托统一处理),旧的直连绑定移除。 */
/** 调色板色块与自定义取色 input */
/** 调色板色块与自定义取色 input(旧侧栏,现已迁到弹层,保留兜底) */
function bindColorPalette() {
// 颜色
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
s.addEventListener('mousedown', (e) => e.stopPropagation())
s.addEventListener('click', () => applyColorChange(s.dataset.color))
s.addEventListener('click', () => applyPanelColor(s.dataset.color))
})
const colorInput = runtime.el.querySelector('.iwb-editor-color-picker-input')
if (colorInput) {
colorInput.addEventListener('mousedown', (e) => e.stopPropagation())
colorInput.addEventListener('input', () => applyColorChange(colorInput.value))
colorInput.addEventListener('input', () => applyPanelColor(colorInput.value))
}
}
@@ -1909,7 +2167,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, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter }
const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, fillColor: S.shapeFillColor, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter }
// 路径落成即回 V 并选中(v1.5):连续画多条就再按一次 P;节点编辑仍走 V 下双击
S.shapeLayers.push(shape); S.penPath = null; renderObjects(); renderLayerPanel()
finishCreateTool('shape', shape.id)
+5 -3
View File
@@ -323,7 +323,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, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
texts: S.textLayers.map(t => ({
id: t.id, text: t.text, x: t.x, y: t.y, fontSize: t.fontSize, color: t.color,
fontWeight: t.fontWeight, align: t.align, lineHeight: t.lineHeight,
@@ -337,8 +337,10 @@ import { toast } from './commands.js'
textDefaults: {
weight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
bgFill: S.textBgFill, bgColor: S.textBgColor
}, selectedShapeId: S.selectedShapeId,
bgFill: S.textBgFill, bgColor: S.textBgColor, bgAlpha: S.textBgAlpha
},
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null }, selectedShapeId: S.selectedShapeId,
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
+1 -2
View File
@@ -208,14 +208,13 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
ctx.save()
ctx.strokeStyle = '#e8a735'
ctx.lineWidth = 1.5 / viewScale()
ctx.setLineDash([6 / viewScale(), 3 / viewScale()])
// 图层/对象选中一律实线(虚线是像素选区的语义,见 objects.js 同处注释)
const corners = boxCorners(box.x, box.y, box.w, box.h, rot)
ctx.beginPath()
ctx.moveTo(corners[0][0], corners[0][1])
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
ctx.closePath()
ctx.stroke()
ctx.setLineDash([])
ctx.fillStyle = '#fff'
ctx.strokeStyle = '#e8a735'
const pts = frameHandlePoints(box, rot)
+3 -4
View File
@@ -418,14 +418,14 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
octx.save()
octx.strokeStyle = '#e8a735'
octx.lineWidth = 1.5 / viewScale()
octx.setLineDash([6 / viewScale(), 3 / viewScale()])
// v1.10:对象选中框用**实线**。虚线在 PS 语义里是「像素选区(蚂蚁线)」,
// 用户看到文字/图形外面一圈虚线会当成「莫名其妙多出来的选区」。
const corners = boxCorners(b.x, b.y, b.w, b.h, rot)
octx.beginPath()
octx.moveTo(corners[0][0], corners[0][1])
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
octx.closePath()
octx.stroke()
octx.setLineDash([])
const hs = 5.5 / viewScale()
octx.fillStyle = '#ffffff'
octx.strokeStyle = '#e8a735'
@@ -475,14 +475,13 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
octx.save()
octx.strokeStyle = '#e8a735'
octx.lineWidth = 1.5 / viewScale()
octx.setLineDash([6 / viewScale(), 3 / viewScale()])
// 同上:对象选中是实线(虚线只留给像素选区的蚂蚁线)
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot)
octx.beginPath()
octx.moveTo(corners[0][0], corners[0][1])
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
octx.closePath()
octx.stroke()
octx.setLineDash([])
const hs = 5.5 / viewScale()
octx.fillStyle = '#ffffff'
octx.strokeStyle = '#e8a735'
+15 -4
View File
@@ -7,6 +7,9 @@
'use strict'
// text.js 是零依赖叶子模块,这里引它的默认值常量不会形成循环
import { TEXT_DEFAULTS } from './text.js'
export const ZOOM_MIN = 0.1
export const ZOOM_MAX = 10
export const ZOOM_STEP = 1.15
@@ -39,15 +42,23 @@
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
shapeFillColor: null,
// v1.11:工具栏色板当前在调哪个颜色。描边与填充是同一个控件上的两个槽,
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
// 否则「三个地方各调各的颜色」会一直存在。
colorTarget: 'stroke', // stroke | fill
textSize: 32, // 新建文字的字号 px
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
textWeight: 'bold', // bold | normal | 900
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
textStrokeWidth: 0, // 描边宽度 px,0 = 无描边
textStrokeColor: '#ffffff',
textBgFill: false, // 底色块
textBgColor: '#000000',
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: [],
// 图层系统
+24 -7
View File
@@ -15,6 +15,23 @@
/** 默认行高倍数:必须等于老版的 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
@@ -102,8 +119,8 @@
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 ? 0.68 : t.bgAlpha)
ctx.fillStyle = t.bgColor || '#000000'
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : t.bgAlpha)
ctx.fillStyle = t.bgColor || TEXT_DEFAULTS.bgColor
const bx = t.x, by = t.y
const bw = boxW, bh = m.h + m.pad * 2
ctx.beginPath()
@@ -132,10 +149,10 @@
const y = t.y + m.pad + i * m.lh
if (m.sw > 0) {
ctx.lineWidth = m.sw
ctx.strokeStyle = t.strokeColor || '#ffffff'
ctx.strokeStyle = t.strokeColor || TEXT_DEFAULTS.strokeColor
ctx.strokeText(m.lines[i], ox, y)
}
ctx.fillStyle = t.color || '#ff4444'
ctx.fillStyle = t.color || TEXT_DEFAULTS.color
ctx.fillText(m.lines[i], ox, y)
}
ctx.restore()
@@ -149,9 +166,9 @@
align: alignOf(s),
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
strokeColor: s.strokeColor || '#ffffff',
strokeColor: s.strokeColor || TEXT_DEFAULTS.strokeColor,
bgFill: !!s.bgFill,
bgColor: s.bgColor || '#000000',
bgAlpha: s.bgAlpha == null ? 0.68 : Number(s.bgAlpha)
bgColor: s.bgColor || TEXT_DEFAULTS.bgColor,
bgAlpha: s.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : Number(s.bgAlpha)
}
}
+12 -6
View File
@@ -180,6 +180,12 @@ import { rememberColor } from './recent-colors.js'
}
/** 按形状对象绘制(矩形/箭头),预览与最终渲染共用 */
/** 形状描边色:每个形状自己存 color(v1.10 起选项栏可单独调) */
export function strokeOf(s) { return (s && s.color) || S.color }
/** 形状填充色:自己设过 fillColor 就用它,否则跟随描边色(同色实心是默认手感) */
export function fillOf(s) { return (s && s.fillColor) || strokeOf(s) }
export function drawShape(ctx, s) {
ctx.save()
ctx.globalAlpha = s.opacity != null ? s.opacity : 1
@@ -191,23 +197,23 @@ import { rememberColor } from './recent-colors.js'
ctx.rotate(rot * Math.PI / 180)
ctx.translate(-cx, -cy)
}
ctx.strokeStyle = s.color
ctx.strokeStyle = strokeOf(s)
ctx.lineWidth = s.lw
ctx.lineCap = 'round'
ctx.lineJoin = 'round'
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 = 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') {
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)
if (radius > 0) {
ctx.beginPath()
roundRectPath(ctx, rx, ry, rw, rh, radius)
if (s.fill) { ctx.fillStyle = s.color; ctx.fill() }
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
ctx.stroke()
} else {
if (s.fill) { ctx.fillStyle = s.color; ctx.fillRect(rx, ry, rw, rh) }
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fillRect(rx, ry, rw, rh) }
ctx.strokeRect(rx, ry, rw, rh)
}
} else if (s.type === 'circle') {
@@ -215,10 +221,10 @@ import { rememberColor } from './recent-colors.js'
const rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
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 = s.color; ctx.fill() }
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
ctx.stroke()
} else {
ctx.fillStyle = s.color
ctx.fillStyle = strokeOf(s)
ctx.beginPath()
ctx.moveTo(s.x1, s.y1)
ctx.lineTo(s.x2, s.y2)
+424 -202
View File
@@ -9,7 +9,7 @@
var __IWB_ANNOTATE_MANIFEST__ = {
id: 'image-annotate',
name: '标注 / 修图',
version: '1.9.1',
version: '1.11.0',
apiVersion: 1,
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
settings: {
@@ -24,6 +24,131 @@ var __IWB_ANNOTATE_MANIFEST__ = {
"use strict";
(() => {
// image-annotate/plugin/editor/text.js
var TEXT_LINE_HEIGHT = 1.25;
var TEXT_DEFAULTS = {
color: "#ff4444",
strokeWidth: 0,
strokeColor: "#ffffff",
bgFill: false,
bgColor: "#101014",
bgAlpha: 0.68
};
var BG_PAD_RATIO = 0.3;
var _measureCtx = null;
function measureCtx() {
if (!_measureCtx) {
const c = document.createElement("canvas");
c.width = 8;
c.height = 8;
_measureCtx = c.getContext("2d");
}
return _measureCtx;
}
function weightOf(t) {
const w = t && t.fontWeight;
return w == null || w === "" ? "bold" : String(w);
}
function fontOf(t) {
const size = Math.max(4, Number(t && t.fontSize) || 32);
return weightOf(t) + " " + size + "px sans-serif";
}
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 };
}
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";
}
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);
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;
}
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();
}
function newTextStyle(src) {
const s = src || {};
return {
fontWeight: weightOf(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)
};
}
// image-annotate/plugin/editor/state.js
var ZOOM_MIN = 0.1;
var ZOOM_MAX = 10;
@@ -65,6 +190,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
// 矩形/圆形/箭头/钢笔的描边粗细
shapeRadius: 0,
// 矩形圆角半径 px(v1.9,仅 rect 有意义)
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
shapeFillColor: null,
// v1.11:工具栏色板当前在调哪个颜色。描边与填充是同一个控件上的两个槽,
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
// 否则「三个地方各调各的颜色」会一直存在。
colorTarget: "stroke",
// stroke | fill
textSize: 32,
// 新建文字的字号 px
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
@@ -74,12 +207,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
// left | center | right(多行时各行按块宽对齐)
textLineHeight: 1.25,
// 行高倍数(1.25 = 老版单行高度,勿随意改)
textStrokeWidth: 0,
textStrokeWidth: TEXT_DEFAULTS.strokeWidth,
// 描边宽度 px,0 = 无描边
textStrokeColor: "#ffffff",
textBgFill: false,
textStrokeColor: TEXT_DEFAULTS.strokeColor,
textBgFill: TEXT_DEFAULTS.bgFill,
// 底色块
textBgColor: "#000000",
textBgColor: TEXT_DEFAULTS.bgColor,
// 中性近黑,不再是纯黑 #000000
textBgAlpha: TEXT_DEFAULTS.bgAlpha,
// 底色透明度(色块按这个不透明度显示,所见即所得)
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
recentColors: [],
// 图层系统
@@ -662,6 +798,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
ctx.arcTo(x, y, x + w, y, rr);
ctx.closePath();
}
function strokeOf(s) {
return s && s.color || S.color;
}
function fillOf(s) {
return s && s.fillColor || strokeOf(s);
}
function drawShape(ctx, s) {
ctx.save();
ctx.globalAlpha = s.opacity != null ? s.opacity : 1;
@@ -673,7 +815,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
ctx.rotate(rot * Math.PI / 180);
ctx.translate(-cx, -cy);
}
ctx.strokeStyle = s.color;
ctx.strokeStyle = strokeOf(s);
ctx.lineWidth = s.lw;
ctx.lineCap = "round";
ctx.lineJoin = "round";
@@ -685,7 +827,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
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.fillStyle = fillOf(s);
ctx.fill();
}
ctx.stroke();
@@ -697,13 +839,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
ctx.beginPath();
roundRectPath(ctx, rx, ry, rw, rh, radius);
if (s.fill) {
ctx.fillStyle = s.color;
ctx.fillStyle = fillOf(s);
ctx.fill();
}
ctx.stroke();
} else {
if (s.fill) {
ctx.fillStyle = s.color;
ctx.fillStyle = fillOf(s);
ctx.fillRect(rx, ry, rw, rh);
}
ctx.strokeRect(rx, ry, rw, rh);
@@ -714,12 +856,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
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 = s.color;
ctx.fillStyle = fillOf(s);
ctx.fill();
}
ctx.stroke();
} else {
ctx.fillStyle = s.color;
ctx.fillStyle = strokeOf(s);
ctx.beginPath();
ctx.moveTo(s.x1, s.y1);
ctx.lineTo(s.x2, s.y2);
@@ -990,123 +1132,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
}, 2600);
}
// image-annotate/plugin/editor/text.js
var TEXT_LINE_HEIGHT = 1.25;
var BG_PAD_RATIO = 0.3;
var _measureCtx = null;
function measureCtx() {
if (!_measureCtx) {
const c = document.createElement("canvas");
c.width = 8;
c.height = 8;
_measureCtx = c.getContext("2d");
}
return _measureCtx;
}
function weightOf(t) {
const w = t && t.fontWeight;
return w == null || w === "" ? "bold" : String(w);
}
function fontOf(t) {
const size = Math.max(4, Number(t && t.fontSize) || 32);
return weightOf(t) + " " + size + "px sans-serif";
}
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 };
}
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";
}
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);
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? 0.68 : t.bgAlpha);
ctx.fillStyle = t.bgColor || "#000000";
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;
}
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 || "#ffffff";
ctx.strokeText(m.lines[i], ox, y);
}
ctx.fillStyle = t.color || "#ff4444";
ctx.fillText(m.lines[i], ox, y);
}
ctx.restore();
}
function newTextStyle(src) {
const s = src || {};
return {
fontWeight: weightOf(s),
align: alignOf(s),
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
strokeColor: s.strokeColor || "#ffffff",
bgFill: !!s.bgFill,
bgColor: s.bgColor || "#000000",
bgAlpha: s.bgAlpha == null ? 0.68 : Number(s.bgAlpha)
};
}
// image-annotate/plugin/editor/snap.js
var SNAP_SCREEN_PX = 6;
var GUIDE_COLOR = "#ff2d95";
@@ -1548,14 +1573,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
octx.save();
octx.strokeStyle = "#e8a735";
octx.lineWidth = 1.5 / viewScale();
octx.setLineDash([6 / viewScale(), 3 / viewScale()]);
const corners = boxCorners(b.x, b.y, b.w, b.h, rot);
octx.beginPath();
octx.moveTo(corners[0][0], corners[0][1]);
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]);
octx.closePath();
octx.stroke();
octx.setLineDash([]);
const hs = 5.5 / viewScale();
octx.fillStyle = "#ffffff";
octx.strokeStyle = "#e8a735";
@@ -1600,14 +1623,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
octx.save();
octx.strokeStyle = "#e8a735";
octx.lineWidth = 1.5 / viewScale();
octx.setLineDash([6 / viewScale(), 3 / viewScale()]);
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot);
octx.beginPath();
octx.moveTo(corners[0][0], corners[0][1]);
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]);
octx.closePath();
octx.stroke();
octx.setLineDash([]);
const hs = 5.5 / viewScale();
octx.fillStyle = "#ffffff";
octx.strokeStyle = "#e8a735";
@@ -2030,14 +2051,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
ctx.save();
ctx.strokeStyle = "#e8a735";
ctx.lineWidth = 1.5 / viewScale();
ctx.setLineDash([6 / viewScale(), 3 / viewScale()]);
const corners = boxCorners(box.x, box.y, box.w, box.h, rot);
ctx.beginPath();
ctx.moveTo(corners[0][0], corners[0][1]);
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1]);
ctx.closePath();
ctx.stroke();
ctx.setLineDash([]);
ctx.fillStyle = "#fff";
ctx.strokeStyle = "#e8a735";
const pts = frameHandlePoints(box, rot);
@@ -3545,8 +3564,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
</div>
<div class="iwb-editor-tools">
<!-- 当前色圆点(v1.3):点开就是完整色板,侧栏不再放调色板 -->
<button type="button" class="iwb-editor-color-btn" data-action="toggleColorPop" aria-expanded="false" title="颜色:点开色板(调色器 / 吸管 / 推荐色)"><i></i></button>
<!-- 颜色(v1.11):描边 + 填充 两个槽叠放在一个按钮位里(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>
</div>
<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>
<span class="iwb-editor-divider"></span>
@@ -3646,6 +3671,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
<div class="iwb-editor-color-pop" hidden>
<!-- 弹层头部(v1.11):标明「现在调的是哪个颜色」,并可直接切换。
与工具栏那两个色块是同一组槽位,两边高亮完全一致。
「无」只对填充有意义:描边关掉会让形状彻底消失,不是用户要的。 -->
<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-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>
@@ -3672,6 +3706,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<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>
@@ -4249,7 +4284,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
function onPickerMouseDown(pos) {
const s = sampleColor(pos);
if (s && s.a > 0) {
applyColorChange(rgbToHex(s.r, s.g, s.b));
applyPanelColor(rgbToHex(s.r, s.g, s.b));
}
exitPicker();
return;
@@ -4498,6 +4533,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
x2: pos.x,
y2: pos.y,
color: S.color,
fillColor: S.shapeFillColor,
lw: Math.max(1, S.shapeLineWidth),
lineWidth: Math.max(1, S.shapeLineWidth),
fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false,
@@ -4688,6 +4724,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
x2: pos.x,
y2: pos.y,
color: S.color,
fillColor: S.shapeFillColor,
// null = 跟随描边色(改主色时整块跟着变)
lw: Math.max(1, S.shapeLineWidth),
fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false,
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
@@ -4792,21 +4830,79 @@ var __IWB_ANNOTATE_MANIFEST__ = {
layer.canvas.style.cursor = cur;
}
};
function fillSlotOn() {
const sh = getSelectedShape();
if (sh) return sh.type === "rect" || sh.type === "circle" || sh.type === "pen" && !!sh.closed;
return S.tool === "rect" || S.tool === "circle" || S.tool === "pen";
}
function colorSlots() {
const sh = getSelectedShape();
const stroke = sh && sh.color || S.color;
const rawFill = sh ? sh.fillColor || null : S.shapeFillColor;
const fillOn = sh ? sh.type === "pen" ? !!sh.fill && !!sh.closed : !!sh.fill : S.tool === "pen" ? !!S.penFill : !!S.rectFill;
return { stroke, fill: rawFill || stroke, fillOn, follow: !rawFill };
}
function activeColor() {
const sl = colorSlots();
return S.colorTarget === "fill" ? sl.fill : sl.stroke;
}
function updateColorUI() {
const sl = colorSlots();
const fillable = fillSlotOn();
if (!fillable && S.colorTarget === "fill") S.colorTarget = "stroke";
const pair = runtime.el.querySelector(".iwb-editor-color-pair");
if (pair) pair.dataset.colorMode = fillable ? "pair" : "single";
const strokeBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="stroke"]');
const fillBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="fill"]');
const textCtx = S.tool === "text" || !!S.selectedTextId && S.tool === "select";
const strokeName = textCtx ? "文字" : S.tool === "brush" || S.tool === "eraser" ? "画笔" : "描边";
if (strokeBtn) {
const dot = strokeBtn.querySelector("i");
if (dot) dot.style.backgroundColor = sl.stroke;
strokeBtn.classList.toggle("active", S.colorTarget === "stroke");
strokeBtn.title = fillable ? `描边色 ${sl.stroke.toUpperCase()}:形状描边也用这个值。点开色板调色` : `${strokeName}色 ${sl.stroke.toUpperCase()}:点开色板调色`;
const popEl = runtime.el.querySelector(".iwb-editor-color-pop");
strokeBtn.setAttribute("aria-expanded", String(!!(popEl && !popEl.hidden && S.colorTarget === "stroke")));
}
if (fillBtn) {
const dot = fillBtn.querySelector("i");
if (dot) dot.style.backgroundColor = sl.fill;
fillBtn.classList.toggle("is-none", !sl.fillOn);
fillBtn.classList.toggle("is-follow", sl.follow && sl.fillOn);
fillBtn.classList.toggle("active", S.colorTarget === "fill");
fillBtn.title = !sl.fillOn ? "填充:无(形状内部透明)。点开色板选色即可填充" : sl.follow ? "填充色:跟随描边色 " + sl.fill.toUpperCase() + ",点开可单独指定" : "填充色 " + sl.fill.toUpperCase() + ",点开调色";
}
runtime.el.querySelectorAll(".iwb-color-pop-tab").forEach((tab) => {
const isFill = tab.dataset.colorSlot === "fill";
tab.classList.toggle("active", S.colorTarget === (isFill ? "fill" : "stroke"));
const dot = tab.querySelector("i");
if (dot) dot.style.backgroundColor = isFill ? sl.fill : sl.stroke;
const label = tab.querySelector(".iwb-color-pop-tab-label");
if (label) label.textContent = isFill ? "填充" : fillable ? "描边" : strokeName;
if (isFill) {
tab.classList.toggle("is-none", !sl.fillOn);
tab.hidden = !fillable;
}
});
const noneBtn = runtime.el.querySelector("[data-color-none]");
if (noneBtn) {
const show = fillable && S.colorTarget === "fill";
noneBtn.hidden = !show;
noneBtn.classList.toggle("active", show && !sl.fillOn);
}
const cur = activeColor();
let matchPreset = false;
runtime.el.querySelectorAll(".iwb-editor-color[data-color]").forEach((s) => {
const on = (s.dataset.color || "").toLowerCase() === S.color.toLowerCase();
const on = (s.dataset.color || "").toLowerCase() === cur.toLowerCase();
if (on) matchPreset = true;
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 = S.color.toUpperCase();
const colorDot = runtime.el.querySelector(".iwb-editor-color-btn i");
if (colorDot) colorDot.style.background = S.color;
runtime.el.querySelectorAll(".iwb-editor-color-panel-swatch").forEach((sw) => sw.classList.toggle("active", (sw.dataset.panelColor || "").toLowerCase() === S.color.toLowerCase()));
if (panelHex) panelHex.textContent = S.color.toUpperCase();
const rgb = hexToRgb(S.color);
if (hexInput && document.activeElement !== hexInput) hexInput.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;
@@ -4831,7 +4927,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (custom) {
custom.classList.toggle("active", !matchPreset);
const inp = custom.querySelector("input");
if (inp) inp.value = S.color;
if (inp) inp.value = cur;
}
}
function updateBrushUI() {
@@ -4902,11 +4998,20 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<button type="button" class="iwb-editor-crop-cancel" data-action="cancelCrop" title="Esc">✗ 取消</button>
<span class="iwb-opt-hint">拖出裁剪框;Enter 确认 · Esc 取消;裁剪后可 Ctrl+Z</span>`;
}
function fillStyleHTML(owner) {
const fill = owner === "pen" ? S.penFill : S.rectFill;
function shapeColorHTML(sh, owner) {
const sl = colorSlots();
let html = `<span class="iwb-opt-label">描边</span><input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`;
if (owner) {
html += `<span class="iwb-opt-label">填充</span><input type="color" class="iwb-opt-color${sl.fillOn ? "" : " is-off"}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? "" : ";当前无填充,选色会自动切成实心"}">`;
}
return html;
}
function fillStyleHTML(owner, sh) {
const own = !!sh && (owner === "pen" ? sh.type === "pen" : sh.type === "rect" || sh.type === "circle");
const fill = own ? !!sh.fill : owner === "pen" ? S.penFill : S.rectFill;
return `<span class="iwb-opt-label">样式</span>
<button class="iwb-opt-btn${fill ? "" : " active"}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="描边 (Shift+X 切换)">描边</button>
<button class="iwb-opt-btn${fill ? " active" : ""}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心 (Shift+X 切换)">实心</button>`;
<button class="iwb-opt-btn${fill ? "" : " active"}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边 (Shift+X 切换)">描边</button>
<button class="iwb-opt-btn${fill ? " active" : ""}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`;
}
var SHAPE_NAMES = { rect: "矩形", circle: "圆形", arrow: "箭头", pen: "钢笔路径" };
var TEXT_STYLE_STATE_KEY = {
@@ -4926,11 +5031,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
return {
fontWeight: String(pick("fontWeight", "textWeight", "bold")),
align: pick("align", "textAlign", "left"),
lineHeight: Number(pick("lineHeight", "textLineHeight", 1.25)) || 1.25,
strokeWidth: Math.max(0, Number(pick("strokeWidth", "textStrokeWidth", 0)) || 0),
strokeColor: pick("strokeColor", "textStrokeColor", "#ffffff"),
bgFill: !!pick("bgFill", "textBgFill", false),
bgColor: pick("bgColor", "textBgColor", "#000000")
lineHeight: Number(pick("lineHeight", "textLineHeight", TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
strokeWidth: Math.max(0, Number(pick("strokeWidth", "textStrokeWidth", TEXT_DEFAULTS.strokeWidth)) || 0),
strokeColor: pick("strokeColor", "textStrokeColor", TEXT_DEFAULTS.strokeColor),
bgFill: !!pick("bgFill", "textBgFill", TEXT_DEFAULTS.bgFill),
bgColor: pick("bgColor", "textBgColor", TEXT_DEFAULTS.bgColor),
bgAlpha: Number(pick("bgAlpha", "textBgAlpha", TEXT_DEFAULTS.bgAlpha)) || TEXT_DEFAULTS.bgAlpha
};
}
function textStyleHTML(t) {
@@ -4945,9 +5051,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<span class="iwb-opt-sep"></span>
<span class="iwb-opt-label">描边</span>
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
<input type="color" class="iwb-opt-color" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色">
<button class="iwb-opt-btn${v.bgFill ? " active" : ""}" data-opt-text="bgFill" data-value="${v.bgFill ? "0" : "1"}" title="给文字加一块半透明底色,压在花背景上也能看清">底色</button>
<input type="color" class="iwb-opt-color" data-opt-color="bgColor" value="${v.bgColor}" title="底色颜色;选色会自动开启底色,不用先点左侧按钮">`;
<input type="color" class="iwb-opt-color${v.strokeWidth > 0 ? "" : " is-off"}" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色${v.strokeWidth > 0 ? "" : ";描边宽度是 0,选色会自动给 6px"}">
<button class="iwb-opt-btn${v.bgFill ? " active" : ""}" data-opt-text="bgFill" data-value="${v.bgFill ? "0" : "1"}" title="给文字加一块底色,压在花背景上也能看清">底色</button>
<input type="color" class="iwb-opt-color${v.bgFill ? "" : " is-off"}" data-opt-color="bgColor" value="${v.bgColor}" style="--sw-a:${v.bgAlpha}" title="底色 ${Math.round(v.bgAlpha * 100)}% 不透明(色块按真实半透明显示);选色会自动开启底色">`;
}
var SELCMD_SVGS = {
all: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="3 2"><rect x="3.5" y="3.5" width="17" height="17" rx="1"/></svg>',
@@ -4965,12 +5071,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (t === "rect" || t === "circle" || t === "pen" || t === "arrow") {
const owner = t === "pen" ? "pen" : "rect";
const lw = Math.max(1, Math.round(sh.lw || S.shapeLineWidth));
return `<span class="iwb-opt-current">已选中:${SHAPE_NAMES[t] || t}</span>` + rangeOpt("shapeLineWidth", "线宽", 1, 60, lw, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (t === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, Math.round(sh.radius || 0), "px") : "") + (t === "arrow" ? "" : fillStyleHTML(owner)) + (t === "pen" && !sh.closed ? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>' : "") + selCmdHTML();
return `<span class="iwb-opt-current">已选中:${SHAPE_NAMES[t] || t}</span>` + rangeOpt("shapeLineWidth", "线宽", 1, 60, lw, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (t === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, Math.round(sh.radius || 0), "px") : "") + shapeColorHTML(sh, t === "arrow" ? null : owner) + (t === "arrow" ? "" : fillStyleHTML(owner, sh)) + (t === "pen" && !sh.closed ? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>' : "");
}
}
const text = getSelectedText();
if (text) {
return `<span class="iwb-opt-current">已选中:文字</span>` + rangeOpt("textSize", "字号", 8, 400, Math.round(text.fontSize || S.textSize), "px") + textStyleHTML(text) + selCmdHTML() + '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>';
return `<span class="iwb-opt-current">已选中:文字</span>` + rangeOpt("textSize", "字号", 8, 400, Math.round(text.fontSize || S.textSize), "px") + textStyleHTML(text) + '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>';
}
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>` + selCmdHTML() + '<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里出现它的描边、实心与粗细</span>';
}
@@ -4986,13 +5092,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<span class="iwb-opt-val" data-opt-val="brushOpacity">${Math.round(S.brushOpacity * 100)}%</span>` + presetDots("brushHardness", [0, 25, 50, 75, 100]);
}
if (tool === "rect" || tool === "circle") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (tool === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, S.shapeRadius, "px") : "") + fillStyleHTML("rect");
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (tool === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, S.shapeRadius, "px") : "") + shapeColorHTML(null, "rect") + fillStyleHTML("rect");
}
if (tool === "arrow") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + '<span class="iwb-opt-hint">拖出箭头,松手完成</span>';
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + shapeColorHTML(null, null) + '<span class="iwb-opt-hint">拖出箭头,松手完成</span>';
}
if (tool === "pen") {
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + fillStyleHTML("pen") + '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>';
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + shapeColorHTML(null, "pen") + fillStyleHTML("pen") + '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>';
}
if (tool === "text") {
return rangeOpt("textSize", "字号", 8, 400, S.textSize, "px") + textStyleHTML(null) + '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>';
@@ -5001,12 +5107,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
return `<span class="iwb-opt-label">形状</span>
<button class="iwb-opt-btn${S.selectionKind === "rect" ? " active" : ""}" data-opt="shape" data-value="rect">矩形</button>
<button class="iwb-opt-btn${S.selectionKind === "ellipse" ? " active" : ""}" data-opt="shape" data-value="ellipse">椭圆</button>
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>
<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`;
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>` + selCmdHTML() + `<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`;
}
if (tool === "lasso") {
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>
<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`;
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>` + selCmdHTML() + `<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`;
}
return `<span class="iwb-opt-current">当前工具:${TOOL_NAMES[tool] || tool}</span>
<span class="iwb-opt-hint">${OPT_HINTS[tool] || "选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层"}</span>`;
@@ -5073,10 +5177,27 @@ var __IWB_ANNOTATE_MANIFEST__ = {
btn.classList.toggle("active", String(sv[k]) === btn.dataset.value);
});
body.querySelectorAll("[data-opt-color]").forEach((inp) => {
if (document.activeElement === inp) return;
const v = sv[inp.dataset.optColor];
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
const k = inp.dataset.optColor;
if (document.activeElement !== inp) {
const v = sv[k];
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
}
if (k === "strokeColor") inp.classList.toggle("is-off", !(sv.strokeWidth > 0));
if (k === "bgColor") inp.classList.toggle("is-off", !sv.bgFill);
});
body.querySelectorAll("[data-shape-color]").forEach((inp) => {
const kind = inp.dataset.shapeColor;
const sl = colorSlots();
const v = kind === "fill" ? sl.fill : sl.stroke;
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
if (kind === "fill") {
inp.classList.toggle("is-off", !sl.fillOn);
inp.title = sl.fillOn ? "填充色:与工具栏右下的填充色块是同一份" : "当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」";
} else {
inp.title = "描边色:与工具栏左上的描边色块是同一份";
}
});
updateColorUI();
}
function updateStatusbar() {
if (!runtime.el) return;
@@ -5132,12 +5253,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
if (key === "bgFill") value = raw === true || raw === 1 || raw === "1" || raw === "true";
else if (key === "lineHeight") value = clamp(Number(raw) || 125, 80, 300) / 100;
else if (key === "strokeWidth") value = clamp(Number(raw) || 0, 0, 40);
else if (key === "strokeColor" || key === "bgColor") value = String(raw || "#000000").toLowerCase();
else if (key === "strokeColor" || key === "bgColor") value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase();
else value = String(raw);
S[stateKey] = value;
if (key === "strokeColor" && !(Number(S.textStrokeWidth) > 0)) S.textStrokeWidth = 6;
if (key === "bgColor" && !S.textBgFill) S.textBgFill = true;
const t = getSelectedText();
if (!t || t.locked) {
textStyleSnapDone = false;
syncOptionBar();
return;
}
if (committed || !textStyleSnapDone) {
@@ -5145,12 +5269,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
textStyleSnapDone = true;
}
t[key] = value;
if (key === "bgColor" && !t.bgFill) {
t.bgFill = true;
S.textBgFill = true;
}
if (key === "strokeColor" && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth;
if (key === "bgColor" && !t.bgFill) t.bgFill = true;
renderObjects();
if (key === "bgColor") syncOptionBar();
if (key === "bgColor" || key === "strokeColor") syncOptionBar();
if (committed) textStyleSnapDone = false;
}
var radiusSnapDone = false;
@@ -5168,11 +5290,80 @@ var __IWB_ANNOTATE_MANIFEST__ = {
renderObjects();
if (committed) radiusSnapDone = false;
}
function applyShapeColor(kind, raw, opts) {
const skipHistory = !!(opts && opts.skipHistory);
const sh = getSelectedShape();
const owner = sh ? sh.type === "pen" ? "pen" : "rect" : S.tool === "pen" ? "pen" : "rect";
if (kind === "none") {
if (!fillSlotOn()) return;
S.colorTarget = "fill";
if (owner === "pen") S.penFill = false;
else S.rectFill = false;
if (sh && !sh.locked && sh.fill) {
if (!skipHistory) saveSnapshot("无填充");
sh.fill = false;
renderObjects();
}
updateColorUI();
syncOptionBar();
return;
}
const hex = String(raw || "").toLowerCase();
if (!/^#[0-9a-f]{6}$/.test(hex)) return;
if (kind === "stroke") {
S.colorTarget = "stroke";
applyColorChange(hex, opts);
if (skipHistory) syncOptionBarSoon();
else syncOptionBar();
return;
}
S.colorTarget = "fill";
if (skipHistory) {
} else {
rememberColor(hex);
}
S.shapeFillColor = hex;
if (owner === "pen") S.penFill = true;
else S.rectFill = true;
updateFillUI();
if (sh && !sh.locked) {
if (!skipHistory) saveSnapshot("填充颜色");
sh.fillColor = hex;
sh.fill = owner === "pen" ? !!sh.closed : true;
renderObjects();
}
updateColorUI();
if (skipHistory) syncOptionBarSoon();
else syncOptionBar();
}
function applyPanelColor(color, opts) {
if (S.colorTarget === "fill" && fillSlotOn()) {
applyShapeColor("fill", color, opts);
return;
}
if (S.colorTarget === "fill") S.colorTarget = "stroke";
applyColorChange(color, opts);
if (opts && opts.skipHistory) syncOptionBarSoon();
else syncOptionBar();
}
function setColorTarget(slot) {
S.colorTarget = slot === "fill" ? "fill" : "stroke";
updateColorUI();
}
var optionBarSyncRaf = 0;
function syncOptionBarSoon() {
if (optionBarSyncRaf) return;
optionBarSyncRaf = (typeof requestAnimationFrame === "function" ? requestAnimationFrame : (fn) => setTimeout(fn, 16))(() => {
optionBarSyncRaf = 0;
syncOptionBar();
});
}
function setShapeFill(fill, owner) {
const isPen = owner === "pen";
if (isPen) S.penFill = !!fill;
else S.rectFill = !!fill;
updateFillUI();
updateColorUI();
syncOptionBar();
const sh = getSelectedShape();
const types = isPen ? ["pen"] : ["rect", "circle"];
@@ -5293,6 +5484,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
syncOptionBar();
return;
}
const shapeColorEl = e.target.closest ? e.target.closest("[data-shape-color]") : null;
if (shapeColorEl) {
e.stopPropagation();
applyShapeColor(shapeColorEl.dataset.shapeColor, shapeColorEl.value);
return;
}
setOptionFromControl(e.target, true);
});
body.addEventListener("click", (e) => {
@@ -5416,16 +5613,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
const pop = runtime.el && runtime.el.querySelector(".iwb-editor-color-pop");
if (!pop || pop.hidden) return false;
pop.hidden = true;
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]');
if (btn) {
runtime.el.querySelectorAll('[data-action="toggleColorPop"]').forEach((btn) => {
btn.classList.remove("active");
btn.setAttribute("aria-expanded", "false");
}
});
return true;
}
function positionColorPop() {
const pop = runtime.el && runtime.el.querySelector(".iwb-editor-color-pop");
const btn = runtime.el && runtime.el.querySelector('[data-action="toggleColorPop"]');
const btn = runtime.el && runtime.el.querySelector(`.iwb-editor-color-btn[data-color-slot="${S.colorTarget}"]`);
const modal = runtime.el && runtime.el.querySelector(".iwb-editor-modal");
if (!pop || !btn || !modal || pop.hidden) return;
const mr = modal.getBoundingClientRect();
@@ -5438,37 +5634,60 @@ var __IWB_ANNOTATE_MANIFEST__ = {
pop.style.left = Math.round(left) + "px";
pop.style.top = Math.round(top) + "px";
}
function toggleColorPop() {
function toggleColorPop(slot) {
const pop = runtime.el.querySelector(".iwb-editor-color-pop");
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]');
if (!pop || !btn) return;
if (!pop) return;
const want = slot === "fill" ? "fill" : "stroke";
if (!pop.hidden && S.colorTarget === want) {
closeColorPop();
return;
}
S.colorTarget = want;
if (pop.hidden) {
pop.hidden = false;
btn.classList.add("active");
btn.setAttribute("aria-expanded", "true");
updateColorUI();
positionColorPop();
} else {
closeColorPop();
updateColorUI();
positionColorPop();
}
}
function bindColorPanel() {
const pop = runtime.el.querySelector(".iwb-editor-color-pop");
const colorBtn = runtime.el.querySelector('[data-action="toggleColorPop"]');
if (colorBtn) {
colorBtn.addEventListener("mousedown", (e) => e.stopPropagation());
colorBtn.addEventListener("click", (e) => {
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')];
colorBtns.forEach((btn) => {
btn.addEventListener("mousedown", (e) => e.stopPropagation());
btn.addEventListener("click", (e) => {
e.stopPropagation();
toggleColorPop();
toggleColorPop(btn.dataset.colorSlot);
});
}
});
if (pop) {
pop.addEventListener("mousedown", (e) => e.stopPropagation());
document.addEventListener("mousedown", (e) => {
if (!pop.hidden && !pop.contains(e.target) && !(colorBtn && colorBtn.contains(e.target))) closeColorPop();
const onBtn = colorBtns.some((b) => b.contains(e.target));
if (!pop.hidden && !pop.contains(e.target) && !onBtn) closeColorPop();
}, true);
window.addEventListener("resize", positionColorPop);
}
const setPanelColor = (color) => applyColorChange(color);
if (pop) {
pop.addEventListener("click", (e) => {
const tab = e.target.closest("[data-color-slot]");
if (tab && tab.classList.contains("iwb-color-pop-tab")) {
e.stopPropagation();
setColorTarget(tab.dataset.colorSlot);
positionColorPop();
return;
}
const none = e.target.closest("[data-color-none]");
if (none) {
e.stopPropagation();
applyShapeColor("none");
return;
}
});
}
const setPanelColor = (color) => applyPanelColor(color);
let dragSnapped = false;
const hasColorTarget = () => {
const t = getSelectedText(), sh = getSelectedShape();
@@ -5481,7 +5700,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
dragSnapped = true;
}
}
applyColorChange(color, { skipHistory: true });
applyPanelColor(color, { skipHistory: true });
};
const panelHexInput = runtime.el.querySelector(".iwb-editor-color-hex-input");
if (panelHexInput) panelHexInput.addEventListener("change", () => {
@@ -5506,7 +5725,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
const sv = runtime.el.querySelector(".iwb-color-sv");
const hue = runtime.el.querySelector(".iwb-color-hue");
const initHsv = (() => {
const { r, g, b } = hexToRgb(S.color);
const { r, g, b } = hexToRgb(activeColor());
const rr = r / 255, gg = g / 255, bb = b / 255;
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min;
let h = 0;
@@ -5557,7 +5776,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
setDragColor(hsvToHex(hueValue, satValue, valValue));
};
const syncFromColor = () => {
const { r, g, b } = hexToRgb(S.color);
const { r, g, b } = hexToRgb(activeColor());
const rr = r / 255, gg = g / 255, bb = b / 255;
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min;
if (d > 0) {
@@ -5597,12 +5816,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
function bindColorPalette() {
runtime.el.querySelectorAll(".iwb-editor-color[data-color]").forEach((s) => {
s.addEventListener("mousedown", (e) => e.stopPropagation());
s.addEventListener("click", () => applyColorChange(s.dataset.color));
s.addEventListener("click", () => applyPanelColor(s.dataset.color));
});
const colorInput = runtime.el.querySelector(".iwb-editor-color-picker-input");
if (colorInput) {
colorInput.addEventListener("mousedown", (e) => e.stopPropagation());
colorInput.addEventListener("input", () => applyColorChange(colorInput.value));
colorInput.addEventListener("input", () => applyPanelColor(colorInput.value));
}
}
function bindFillToggle() {
@@ -5746,7 +5965,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
return;
}
saveSnapshot();
const shape = { id: "s" + Date.now() + Math.floor(Math.random() * 1e3), type: "pen", pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter };
const shape = { id: "s" + Date.now() + Math.floor(Math.random() * 1e3), 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 };
S.shapeLayers.push(shape);
S.penPath = null;
renderObjects();
@@ -7715,7 +7934,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
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, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
texts: S.textLayers.map((t) => ({
id: t.id,
text: t.text,
@@ -7746,8 +7965,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
strokeWidth: S.textStrokeWidth,
strokeColor: S.textStrokeColor,
bgFill: S.textBgFill,
bgColor: S.textBgColor
bgColor: S.textBgColor,
bgAlpha: S.textBgAlpha
},
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null },
selectedShapeId: S.selectedShapeId,
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
@@ -7847,7 +8069,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
};
// image-annotate/plugin/editor.css
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
// image-annotate/plugin/glue.js
function createGlue(ctx, css) {
+259 -10
View File
@@ -143,7 +143,7 @@ check('调色板已搬进工具栏:侧栏只剩缩放,SV/色相/推荐色都
await page.evaluate(() => {
const q = (s) => Boolean(document.querySelector(s))
return !q('.iwb-editor-left .iwb-editor-color-panel') &&
q('.iwb-editor-tools [data-action="toggleColorPop"]') &&
q('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]') &&
q('.iwb-editor-color-pop .iwb-color-sv') && q('.iwb-editor-color-pop .iwb-color-hue') &&
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-panel-swatch').length === 12 &&
q('.iwb-editor-zoom') &&
@@ -180,7 +180,7 @@ check('色板弹层默认收起;点工具栏色点弹出、且整块在视口
await (async () => {
const pop = page.locator('.iwb-editor-color-pop')
if (await pop.isVisible()) return 'pre: 弹层一开始就开着'
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click()
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
await page.waitForTimeout(100)
if (!(await pop.isVisible())) return 'post: 点了没开'
const box = await pop.boundingBox()
@@ -944,9 +944,9 @@ check('选中矢量形状后切吸管:选中态保留、取色写回形状、
const selId = (await dbg()).selectedShapeId
if (!selId) return 'pre: 没有选中形状'
// 先换成一个可辨识的颜色,便于判断取色真的改了对象(v1.3:推荐色在弹层里,先点开色点)
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click()
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
await page.locator('.iwb-editor-color-pop .iwb-editor-color-panel-swatch[data-panel-color="#4488ff"]').click()
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click() // 收起,别挡住后面的画布取色点
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() // 收起,别挡住后面的画布取色点
const before = (await dbg()).shapes.find(s => s.id === selId)
if (!before || before.color !== '#4488ff') return 'pre: color=' + (before && before.color)
await page.keyboard.press('i') // 切吸管
@@ -1003,7 +1003,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
await page.waitForTimeout(120)
if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状'
const h0 = (await dbg()).history
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click()
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
const sv = await page.locator('.iwb-color-sv').boundingBox()
await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2)
await page.mouse.down()
@@ -1011,7 +1011,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
await page.mouse.up()
await page.waitForTimeout(150)
const h1 = (await dbg()).history
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click() // 收起
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() // 收起
return h1 - h0 === 1 ? true : 'history ' + h0 + '→' + h1
})())
@@ -1724,13 +1724,15 @@ check('文字支持多行(Shift+Enter 换行,包围盒高 ≈ 两行)',
// 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。
// 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区,
// 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。
// 清选中用「切到别的工具再切回来」:画布上早就有别的用例留下的图形,
// 靠「点空白」清选中会点到它们(点位随用例顺序变化,很容易变成假失败)。
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
await page.waitForTimeout(120)
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
const blankPt = await imgToScreen(60, 90)
await page.mouse.click(blankPt.x, blankPt.y)
await page.waitForTimeout(220)
const selIconNoSel = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
check('选择工具未选中元素时仍有全选/反选/取消三个图标(且不重复)',
selIconNoSel === 3, 'count=' + selIconNoSel)
selIconNoSel === 3, 'count=' + selIconNoSel + ' 选中=' + (await dbg()).selectedShapeId)
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
p0 = await imgToScreen(10, 12)
@@ -1802,6 +1804,83 @@ check('只选底色颜色就自动开启底色(不必先点开关)',
'关前=' + bgOff + ' 改色后 bgFill=' + vdbg.texts[0].bgFill +
' bgColor=' + vdbg.texts[0].bgColor + ' 按钮 active=' + bgBtnOn)
// ---- v1.10:三个色块的「生效 / 未生效」语义 ----
// 用户反馈「字体颜色有 3 个位置,那个黑色应该换成默认的参数」:底色默认曾是纯黑 #000000,
// 关闭时也显示成一块死黑,看起来就像「又多了一个字体颜色」。现在默认值单点定义,
// 且没生效的色块显示为灰色斜纹(不再显示颜色本身),语义变成「这里还没有颜色」。
const colorMeta = await page.evaluate(() => {
const body = document.querySelector('.iwb-editor-optionbar-body')
const out = {}
body.querySelectorAll('[data-opt-color]').forEach(el => {
out[el.dataset.optColor] = { off: el.classList.contains('is-off'), value: el.value }
})
return { defaults: window.__iwbEditor.__debug().textDefaults, swatches: out }
})
check('文字底色默认不再是纯黑(默认值收口到 text.js,近黑 #101014 + 68% 透明)',
colorMeta.defaults.bgColor !== '#000000' && /^#[0-9a-f]{6}$/.test(colorMeta.defaults.bgColor) &&
Math.abs(colorMeta.defaults.bgAlpha - 0.68) < 1e-6,
JSON.stringify(colorMeta.defaults))
// 关掉底色 + 描边宽度归零 → 两个色块都应变成「未启用」
await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click()
await page.evaluate(() => {
const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="textStrokeWidth"]')
el.value = '0'
el.dispatchEvent(new Event('input', { bubbles: true }))
el.dispatchEvent(new Event('change', { bubbles: true }))
})
await page.waitForTimeout(200)
const offStates = await page.evaluate(() => [...document.querySelectorAll('.iwb-editor-optionbar-body [data-opt-color]')]
.map(el => ({ k: el.dataset.optColor, off: el.classList.contains('is-off') })))
check('描边宽度为 0 / 底色关闭时,对应色块标记为「未启用」(不再显示颜色本身)',
offStates.length === 2 && offStates.every(o => o.off), JSON.stringify(offStates))
// 选区命令(全选/反选/取消)属于像素选区,必须待在选区工具里
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
await page.waitForTimeout(160)
const marqueeIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
await page.locator('.iwb-editor-tool[data-tool="lasso"]').click()
await page.waitForTimeout(160)
const lassoIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
check('选区工具(矩形 / 套索)都有全选、反选、取消选区三个按钮',
marqueeIcons === 3 && lassoIcons === 3, 'marquee=' + marqueeIcons + ' lasso=' + lassoIcons)
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
p0 = await imgToScreen(10, 12)
await page.mouse.click(p0.x, p0.y)
await page.waitForTimeout(220)
const textSelIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
check('选中文字时选项栏不再冒出选区命令按钮(那三个命令跟文字对象无关)',
textSelIcons === 0, 'count=' + textSelIcons)
// 选中框必须是实线:虚线圈会被当成「莫名其妙多出来的像素选区」。
// 沿选中框顶边扫一行橙色像素,虚线(6/3)覆盖率约 0.6~0.7,实线接近 1。
const frameCoverage = await page.evaluate(() => {
const d = window.__iwbEditor.__debug()
const cv = document.querySelector('.iwb-editor-crop-overlay')
if (!d.selectedTextId) return { err: 'no-selected-text' }
if (!cv) return { err: 'no-overlay' }
const ctx = cv.getContext('2d')
const img = ctx.getImageData(0, 0, cv.width, cv.height).data
const W = cv.width
// 不按图片坐标换算:overlay 画布含 overlayPad 外扩,直接全画布扫,
// 找第一条「橙色连续段」,再量这一段的覆盖率 —— 实线接近 1,6/3 虚线约 0.6~0.7。
const isOrange = (i) => img[i + 3] > 60 && img[i] > 170 && img[i + 1] > 100 && img[i + 2] < 130
for (let y = 0; y < cv.height; y++) {
const base = y * W * 4
let first = -1, last = -1, n = 0
for (let x = 0; x < W; x++) {
if (isOrange(base + x * 4)) { if (first < 0) first = x; last = x; n++ }
}
if (n >= 20 && last - first >= 40) {
return { ratio: +(n / (last - first + 1)).toFixed(2), n, span: last - first + 1, y }
}
}
return { err: 'no-orange-row' }
})
check('对象选中框是实线(虚线的语义是像素选区,会把用户绕晕)',
!!frameCoverage && frameCoverage.ratio >= 0.85, JSON.stringify(frameCoverage))
// 吸附:画一个实心矩形,拖到画布中心附近应被精确吸到中心并出现参考线
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
await page.waitForTimeout(100)
@@ -1928,7 +2007,7 @@ check('矩形圆角生效(角落被切,墨迹减少)',
'radius=' + JSON.stringify(radiusVal) + ' ink ' + inkSharp + '→' + inkRound)
// 最近使用颜色
await page.locator('[data-action="toggleColorPop"]').click()
await page.locator('[data-action="toggleColorPop"][data-color-slot="stroke"]').click()
await page.waitForTimeout(150)
await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click()
await page.waitForTimeout(200)
@@ -1942,6 +2021,176 @@ check('选过的颜色进入「最近使用」并出现在色板弹层',
// 复制到剪贴板:harness 跑在 about:blank(非安全上下文),
// 这里只验「按钮存在 + 点击有明确反馈 + 不抛错」,真安全上下文由本地 http 探针覆盖
// ---- v1.10:矢量图形也有描边色 / 填充色 ----
// 用户要求「把其他的矢量图形也加上描边与填充色属性,工具栏上加描边色设置」。
// 设计:描边色 = 主色(左侧色板 / 吸管 / 选项栏一个真相源),填充色独立存形状的
// fillColor,没单独设过就跟随描边色 —— 于是「切实心 = 同色实心」,不会突兀。
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
await page.waitForTimeout(120)
const shapeColorUI = await page.evaluate(() => {
const body = document.querySelector('.iwb-editor-optionbar-body')
return {
stroke: body.querySelectorAll('[data-shape-color="stroke"]').length,
fill: body.querySelectorAll('[data-shape-color="fill"]').length
}
})
check('矩形工具的选项栏就带描边色 / 填充色块(画之前就能定色)',
shapeColorUI.stroke === 1 && shapeColorUI.fill === 1, JSON.stringify(shapeColorUI))
pa = await imgToScreen(62, 6)
pb = await imgToScreen(90, 28)
await page.mouse.move(pa.x, pa.y)
await page.mouse.down()
await page.mouse.move(pb.x, pb.y, { steps: 6 })
await page.mouse.up()
await page.waitForTimeout(300)
const shapeFresh = await page.evaluate(() => {
const d = window.__iwbEditor.__debug()
return d.shapes[d.shapes.length - 1]
})
check('新建图形的填充默认「跟随描边色」(fillColor=null),不是写死某个填充色',
shapeFresh.fillColor === null, JSON.stringify({ fill: shapeFresh.fill, fillColor: shapeFresh.fillColor }))
// 数「目标颜色」的像素:矢量画布含 overlayPad 外扩,按图片坐标换算单点会采到别处,
// 直接全画布统计同色像素最稳(0 → 上千,量级差别足够断言)
const countColorInVec = (rgb, tol) => page.evaluate(({ rgb, tol }) => {
let n = 0
for (const cv of [...document.querySelectorAll('.iwb-editor-vec-canvas')]) {
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
for (let i = 0; i < d.length; i += 4) {
if (d[i + 3] > 200 && Math.abs(d[i] - rgb[0]) < tol && Math.abs(d[i + 1] - rgb[1]) < tol && Math.abs(d[i + 2] - rgb[2]) < tol) n++
}
}
return n
}, { rgb, tol })
const greenBefore = await countColorInVec([34, 204, 85], 8)
await page.evaluate(() => {
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
el.value = '#22cc55'
el.dispatchEvent(new Event('change', { bubbles: true }))
})
await page.waitForTimeout(280)
const shapeFilled = await page.evaluate(() => {
const d = window.__iwbEditor.__debug()
const s = d.shapes[d.shapes.length - 1]
const body = document.querySelector('.iwb-editor-optionbar-body')
return {
fill: s.fill, fillColor: s.fillColor,
fillBtnOn: !!body.querySelector('[data-opt-toggle="fill"]').classList.contains('active'),
fillSwatchOff: body.querySelector('[data-shape-color="fill"]').classList.contains('is-off')
}
})
const greenAfter = await countColorInVec([34, 204, 85], 8)
check('选填充色即自动切实心,画面上真的是这个颜色(不是只改了个字段)',
shapeFilled.fill === true && shapeFilled.fillColor === '#22cc55' && greenBefore === 0 && greenAfter > 200,
JSON.stringify(shapeFilled) + ' 绿色像素 ' + greenBefore + '→' + greenAfter)
check('填充色块随之变为「生效」态(不再是灰色斜纹)',
shapeFilled.fillSwatchOff === false && shapeFilled.fillBtnOn === true,
JSON.stringify({ off: shapeFilled.fillSwatchOff, btn: shapeFilled.fillBtnOn }))
await page.evaluate(() => {
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
el.value = '#3388ff'
el.dispatchEvent(new Event('change', { bubbles: true }))
})
await page.waitForTimeout(280)
const shapeStroked = await page.evaluate(() => {
const d = window.__iwbEditor.__debug()
const s = d.shapes[d.shapes.length - 1]
return { shapeColor: s.color, mainColor: d.color }
})
check('改图形描边色 = 改主色(色板 / 吸管 / 选项栏不会各说各话)',
shapeStroked.shapeColor === '#3388ff' && shapeStroked.mainColor === '#3388ff',
JSON.stringify(shapeStroked))
// ---- v1.11:颜色收敛成「描边 / 填充」两格,工具栏与选项栏读同一份 ----
// 用户原话:「3 个位置调色有问题,应该是 2 个调色」「请给工具栏加一个描边色,
// 工具选择的填充与描边与这里对应上」「填色里还需要添加一个取消颜色的按钮,就是无色状态」
const pairMode = await page.evaluate(() => {
const pair = document.querySelector('.iwb-editor-color-pair')
const btns = [...pair.querySelectorAll('.iwb-editor-color-btn')]
return { mode: pair.dataset.colorMode, visible: btns.filter(b => b.offsetParent !== null).map(b => b.dataset.colorSlot) }
})
check('工具栏给出「描边 + 填充」两格(形状工具下两格都在)',
pairMode.mode === 'pair' && pairMode.visible.join(',') === 'stroke,fill', JSON.stringify(pairMode))
// 从工具栏填充槽进色板:目标应当是填充,且出现「无」
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
await page.waitForTimeout(220)
const popTarget = await page.evaluate(() => {
const pop = document.querySelector('.iwb-editor-color-pop')
return {
open: !pop.hidden,
fillActive: pop.querySelector('.iwb-color-pop-tab[data-color-slot="fill"]').classList.contains('active'),
noneVisible: !pop.querySelector('[data-color-none]').hidden
}
})
check('点填充槽打开色板:目标是填充,并出现「无」按钮',
popTarget.open && popTarget.fillActive && popTarget.noneVisible, JSON.stringify(popTarget))
// 用一个画布上不会出现的怪色(#a014b2)验收:12 个推荐色在前面用例里都用过,
// 拿黄色/绿色统计会数到别的图形,永远清不到 0。
const mainBefore = await page.evaluate(() => window.__iwbEditor.__debug().color)
await page.evaluate(() => {
const el = document.querySelector('.iwb-editor-color-hex-input')
el.value = '#a014b2'
el.dispatchEvent(new Event('change', { bubbles: true }))
})
await page.waitForTimeout(300)
const fromPop = await page.evaluate(() => {
const d = window.__iwbEditor.__debug()
const s = d.shapes[d.shapes.length - 1]
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
return { main: d.color, fillColor: s.fillColor, fill: s.fill, fillBtnBg: fillBtn.querySelector('i').style.backgroundColor }
})
check('色板里选色写进填充、主色(描边)不动,工具栏填充格同步变色',
fromPop.main === mainBefore && fromPop.fillColor === '#a014b2' && fromPop.fill === true &&
/160, 20, 178/.test(fromPop.fillBtnBg), JSON.stringify(fromPop))
// 「无」:关填充,画面清空,但颜色留着
const purpleBefore = await countColorInVec([160, 20, 178], 10)
await page.evaluate(() => document.querySelector('[data-color-none]').click())
await page.waitForTimeout(320)
const afterNone = await page.evaluate(() => {
const d = window.__iwbEditor.__debug()
const s = d.shapes[d.shapes.length - 1]
const fillBtn = document.querySelector('.iwb-editor-color-pair [data-color-slot="fill"]')
return { fill: s.fill, fillColor: s.fillColor, btnCls: fillBtn.className, noneActive: document.querySelector('[data-color-none]').classList.contains('active') }
})
const purpleAfter = await countColorInVec([160, 20, 178], 10)
check('「无」把填充关掉:画面清空、颜色留着(下次点颜色还是它)',
afterNone.fill === false && afterNone.fillColor === '#a014b2' && purpleBefore > 200 && purpleAfter === 0,
JSON.stringify(afterNone) + ' 紫色像素 ' + purpleBefore + '→' + purpleAfter)
check('无填充时工具栏填充格显示「无」(斜杠态,不露颜色本身)',
/is-none/.test(afterNone.btnCls) && afterNone.noneActive === true, JSON.stringify(afterNone))
// 反方向:选项栏改填充 → 工具栏填充格跟上
await page.evaluate(() => {
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
el.value = '#22cc55'
el.dispatchEvent(new Event('change', { bubbles: true }))
})
await page.waitForTimeout(300)
const reverse = await page.evaluate(() => {
const pair = document.querySelector('.iwb-editor-color-pair')
const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
return { fillBtnBg: pair.querySelector('[data-color-slot="fill"] i').style.backgroundColor, optVal: opt.value }
})
check('选项栏改填充色,工具栏填充格立刻跟上(两处同一份值)',
reverse.optVal === '#22cc55' && /34, 204, 85/.test(reverse.fillBtnBg), JSON.stringify(reverse))
// 画笔没有填充概念:只留一格
await page.keyboard.press('Escape')
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
await page.waitForTimeout(220)
const brushPair = await page.evaluate(() => {
const pair = document.querySelector('.iwb-editor-color-pair')
return { mode: pair.dataset.colorMode, visible: [...pair.querySelectorAll('.iwb-editor-color-btn')].filter(b => b.offsetParent !== null).length }
})
check('画笔工具下只留一格(画笔没有填充概念,不留空格让人猜)',
brushPair.mode === 'single' && brushPair.visible === 1, JSON.stringify(brushPair))
const copyExists = await page.locator('[data-action="copyClipboard"]').count()
await page.locator('[data-action="copyClipboard"]').click()
await page.waitForTimeout(400)