Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c938887c1 |
No files matched your search
@@ -234,6 +234,32 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
|||||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||||
|
|
||||||
|
## v1.11.0:工具栏变成「描边 + 填充」两格,填充可以设「无」
|
||||||
|
|
||||||
|
用户这次的反馈是「工具栏的调色、描边、填充 3 个位置调色有问题,应该是 2 个调色,
|
||||||
|
就是描边与填充,但现在没跟工具栏的调色关联上」,以及「填色里还要一个取消颜色的按钮」。
|
||||||
|
|
||||||
|
### 1. 颜色从三处收敛成两处
|
||||||
|
|
||||||
|
以前工具栏只有一个色点(主色),选项栏另有两个色块(描边 / 填充)。看起来是三个调色口,
|
||||||
|
其中工具栏那个**不参与填充**,于是「填充跟工具栏没关系」。现在工具栏就是
|
||||||
|
**描边 + 填充两个槽**(PS 式前/背景色叠放):点哪个槽,色板就调哪个槽。
|
||||||
|
|
||||||
|
- 描边槽 = `S.color`(也是画笔色、文字色、形状描边色,仍然一个值)
|
||||||
|
- 填充槽 = 形状自己的 `fillColor`,没单独设过就跟随描边色(右下角一个蓝三角)
|
||||||
|
- 色板新增当前目标切换(描边 / 填充),调色器、吸管、hex、推荐色、最近色全部按目标写
|
||||||
|
- 选项栏那两个色块与工具栏**双向同步**:改哪边,另一边立刻跟上
|
||||||
|
- 只有一笔颜色概念的工具(画笔、橡皮、文字、箭头)只显示一个槽,不留空格
|
||||||
|
|
||||||
|
### 2. 填充可以设「无」
|
||||||
|
|
||||||
|
色板里多了「无」按钮(只在调填充时出现):点它把 `fill` 关掉,形状内部透明、只留描边;
|
||||||
|
**颜色本身保留**,下次再选颜色还是它。无填充时工具栏填充槽显示为**灰底红斜杠**,
|
||||||
|
不露颜色 —— 露着上次的颜色会被当成「现在填的就是它」。
|
||||||
|
|
||||||
|
`S.colorTarget` 记录当前在调哪一格,`source` 只有一处:`colorSlots()` 同时供给工具栏、
|
||||||
|
色板头部、hex 与调色器,避免「一个概念两种颜色」再次出现。
|
||||||
|
|
||||||
## v1.10.0:颜色语义统一 / 选中框改实线 / 选区命令归位 / 矢量图形补描边与填充
|
## v1.10.0:颜色语义统一 / 选中框改实线 / 选区命令归位 / 矢量图形补描边与填充
|
||||||
|
|
||||||
这一版全部来自同一张界面截图上的四个疑问:「字体颜色有 3 个位置」「那个黑色应该换成
|
这一版全部来自同一张界面截图上的四个疑问:「字体颜色有 3 个位置」「那个黑色应该换成
|
||||||
|
|||||||
@@ -311,7 +311,8 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
||||||
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
||||||
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
||||||
| 颜色体系与矢量属性 | ✅ v1.10.0:默认值收口到 `TEXT_DEFAULTS`(文字底色去掉纯黑);三个色块标记「生效/未生效」(未生效显示灰色斜纹);对象选中框改实线(虚线只留给像素选区);选区命令归位到矩形/套索选区工具;矢量图形新增独立 `fillColor`,描边色复用主色,选项栏出 `描边 ■ / 填充 ■` 色块,填充缺省跟随描边 |
|
| 颜色体系与矢量属性 | ✅ 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`,跨会话) |
|
| 文字样式与吸附 | ✅ v1.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
|
||||||
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
||||||
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.10.0",
|
"version": "1.11.0",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -1713,26 +1713,85 @@
|
|||||||
================================================================ */
|
================================================================ */
|
||||||
.iwb-editor-modal { position: relative; }
|
.iwb-editor-modal { position: relative; }
|
||||||
|
|
||||||
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn {
|
/* ---- v1.11:工具栏颜色双槽(描边 + 填充) ----
|
||||||
width: 32px; height: 32px; min-width: 32px; flex: 0 0 auto; padding: 0;
|
一个 30px 的按钮位上叠两颗:左上 19px 是描边,右下 19px 是填充。
|
||||||
border: 0; border-radius: 9px; background: #313244; cursor: pointer;
|
描边压在上面(最常用),填充露出右下角,一眼能看出是两格、谁是上级。
|
||||||
|
只有「描边」概念的工具(画笔/文字/箭头)把填充槽藏起来,描边槽放大占满,
|
||||||
|
不留一个空位让人猜。 */
|
||||||
|
.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;
|
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-color-pair [data-color-slot="stroke"] { left: 0; top: 0; z-index: 2; }
|
||||||
.iwb-editor-canvas-wrap > .iwb-editor-tools .iwb-editor-color-btn.active { background: #45475a; }
|
.iwb-editor-color-pair [data-color-slot="fill"] { right: 0; bottom: 0; z-index: 1; }
|
||||||
.iwb-editor-color-btn i {
|
.iwb-editor-color-pair .iwb-editor-color-btn:hover { box-shadow: 0 0 0 2px #89b4fa; }
|
||||||
width: 18px; height: 18px; border-radius: 50%; display: block; background: #ff4444;
|
.iwb-editor-color-pair .iwb-editor-color-btn.active { box-shadow: 0 0 0 2px #e8a735; }
|
||||||
box-shadow: 0 0 0 2px #181825, 0 0 0 3px #585b70;
|
.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 {
|
.iwb-editor-color-pop {
|
||||||
position: absolute; z-index: 60; display: flex; align-items: center; gap: 10px;
|
position: absolute; z-index: 60; display: flex; flex-direction: column; align-items: stretch; gap: 9px;
|
||||||
padding: 10px 12px; border-radius: 12px;
|
padding: 10px 12px; border-radius: 12px;
|
||||||
background: rgba(24, 24, 37, 0.97); border: 1px solid #313244;
|
background: rgba(24, 24, 37, 0.97); border: 1px solid #313244;
|
||||||
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
|
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
|
||||||
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
|
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
|
||||||
}
|
}
|
||||||
.iwb-editor-color-pop[hidden] { display: none; }
|
.iwb-editor-color-pop[hidden] { display: none; }
|
||||||
|
/* 弹层头部:说明现在调的是描边还是填充,并可直接换;右侧是「无」(仅填充) */
|
||||||
|
.iwb-color-pop-head { display: flex; align-items: center; gap: 6px; }
|
||||||
|
.iwb-color-pop-tab {
|
||||||
|
display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
|
||||||
|
border: 1px solid transparent; border-radius: 7px; background: #232334;
|
||||||
|
color: #a6adc8; font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab i {
|
||||||
|
width: 11px; height: 11px; border-radius: 3px; display: block;
|
||||||
|
background-color: #ff4444; background-size: 100% 100%;
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab:hover { background: #313244; color: #cdd6f4; }
|
||||||
|
.iwb-color-pop-tab.active { background: #313244; color: #fff; border-color: #e8a735; }
|
||||||
|
.iwb-color-pop-tab.is-none i {
|
||||||
|
background-color: #45475a !important;
|
||||||
|
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||||
|
}
|
||||||
|
.iwb-color-pop-tab[hidden] { display: none; }
|
||||||
|
.iwb-color-pop-none {
|
||||||
|
margin-left: auto; display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
|
||||||
|
border: 1px dashed #585b70; border-radius: 7px; background: transparent; color: #a6adc8;
|
||||||
|
font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; cursor: pointer;
|
||||||
|
}
|
||||||
|
.iwb-color-pop-none span {
|
||||||
|
width: 11px; height: 11px; border-radius: 3px; display: block; background-color: #45475a;
|
||||||
|
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
|
||||||
|
}
|
||||||
|
.iwb-color-pop-none:hover { border-color: #f38ba8; color: #f38ba8; }
|
||||||
|
.iwb-color-pop-none.active { border-style: solid; border-color: #f38ba8; color: #f38ba8; background: rgba(243, 139, 168, 0.12); }
|
||||||
|
.iwb-color-pop-none[hidden] { display: none; }
|
||||||
|
.iwb-color-pop-body { display: flex; align-items: center; gap: 10px; }
|
||||||
.iwb-color-pop-picker { display: flex; gap: 8px; flex: 0 0 auto; }
|
.iwb-color-pop-picker { display: flex; gap: 8px; flex: 0 0 auto; }
|
||||||
.iwb-editor-color-pop .iwb-color-sv { width: 180px; height: 104px; flex: 0 0 180px; }
|
.iwb-editor-color-pop .iwb-color-sv { width: 180px; height: 104px; flex: 0 0 180px; }
|
||||||
.iwb-editor-color-pop .iwb-color-hue { width: 16px; height: 104px; flex: 0 0 16px; }
|
.iwb-editor-color-pop .iwb-color-hue { width: 16px; height: 104px; flex: 0 0 16px; }
|
||||||
|
|||||||
@@ -130,8 +130,14 @@ import { bindEvents } from './events.js'
|
|||||||
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-tools">
|
<div class="iwb-editor-tools">
|
||||||
<!-- 当前色圆点(v1.3):点开就是完整色板,侧栏不再放调色板 -->
|
<!-- 颜色(v1.11):描边 + 填充 两个槽叠放在一个按钮位里(PS 式前/背景色)。
|
||||||
<button type="button" class="iwb-editor-color-btn" data-action="toggleColorPop" aria-expanded="false" title="颜色:点开色板(调色器 / 吸管 / 推荐色)"><i></i></button>
|
点哪个槽就调哪个:色板只有一套,写谁由 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>
|
<span class="iwb-editor-divider"></span>
|
||||||
<button class="iwb-editor-tool" data-tool="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg></button>
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
@@ -231,6 +237,15 @@ import { bindEvents } from './events.js'
|
|||||||
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
||||||
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
||||||
<div class="iwb-editor-color-pop" hidden>
|
<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-pop-picker">
|
||||||
<div class="iwb-color-sv"><span></span></div>
|
<div class="iwb-color-sv"><span></span></div>
|
||||||
<div class="iwb-color-hue"><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="#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>
|
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#000000" style="background:#000000" title="#000000"></button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -257,11 +257,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
showTextInput(pos.x, pos.y)
|
showTextInput(pos.x, pos.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 吸管工具的按下:取样并应用颜色后退出吸管模式 */
|
/** 吸管工具的按下:取样并应用颜色后退出吸管模式。
|
||||||
|
* v1.11:按当前目标槽写(吸管取色 = 给正在调的那一格上色,而不是永远改主色)。 */
|
||||||
function onPickerMouseDown(pos) {
|
function onPickerMouseDown(pos) {
|
||||||
const s = sampleColor(pos)
|
const s = sampleColor(pos)
|
||||||
if (s && s.a > 0) {
|
if (s && s.a > 0) {
|
||||||
applyColorChange(rgbToHex(s.r, s.g, s.b))
|
applyPanelColor(rgbToHex(s.r, s.g, s.b))
|
||||||
}
|
}
|
||||||
exitPicker()
|
exitPicker()
|
||||||
return
|
return
|
||||||
@@ -864,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() {
|
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
|
let matchPreset = false
|
||||||
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
|
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
|
if (on) matchPreset = true
|
||||||
s.classList.toggle('active', on)
|
s.classList.toggle('active', on)
|
||||||
})
|
})
|
||||||
const panelHex = runtime.el.querySelector('.iwb-editor-color-hex')
|
const panelHex = runtime.el.querySelector('.iwb-editor-color-hex')
|
||||||
const hexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
const hexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
||||||
if (hexInput && document.activeElement !== hexInput) hexInput.value = S.color.toUpperCase()
|
if (hexInput && document.activeElement !== hexInput) hexInput.value = cur.toUpperCase()
|
||||||
// 工具栏色点:色板收起时它就是唯一的颜色指示,必须始终跟随 S.color
|
runtime.el.querySelectorAll('.iwb-editor-color-panel-swatch').forEach(sw => sw.classList.toggle('active', (sw.dataset.panelColor || '').toLowerCase() === cur.toLowerCase()))
|
||||||
const colorDot = runtime.el.querySelector('.iwb-editor-color-btn i')
|
if (panelHex) panelHex.textContent = cur.toUpperCase()
|
||||||
if (colorDot) colorDot.style.background = S.color
|
const rgb = hexToRgb(cur)
|
||||||
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)
|
|
||||||
const max = Math.max(rgb.r, rgb.g, rgb.b) / 255, min = Math.min(rgb.r, rgb.g, rgb.b) / 255
|
const max = Math.max(rgb.r, rgb.g, rgb.b) / 255, min = Math.min(rgb.r, rgb.g, rgb.b) / 255
|
||||||
const d = max - min
|
const d = max - min
|
||||||
let h = 0
|
let h = 0
|
||||||
@@ -894,7 +975,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (custom) {
|
if (custom) {
|
||||||
custom.classList.toggle('active', !matchPreset)
|
custom.classList.toggle('active', !matchPreset)
|
||||||
const inp = custom.querySelector('input')
|
const inp = custom.querySelector('input')
|
||||||
if (inp) inp.value = S.color
|
if (inp) inp.value = cur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -982,14 +1063,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
* 填充色独立存在形状自己的 fillColor 上,没单独设过就跟随描边色(同色实心)。
|
* 填充色独立存在形状自己的 fillColor 上,没单独设过就跟随描边色(同色实心)。
|
||||||
* 填充关着的时候色块置灰(is-off),一眼能看出哪个颜色正在生效。 */
|
* 填充关着的时候色块置灰(is-off),一眼能看出哪个颜色正在生效。 */
|
||||||
function shapeColorHTML(sh, owner) {
|
function shapeColorHTML(sh, owner) {
|
||||||
const stroke = sh ? (sh.color || S.color) : S.color
|
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
|
||||||
const fillOn = sh ? !!sh.fill : (owner === 'pen' ? S.penFill : S.rectFill)
|
const sl = colorSlots()
|
||||||
const fill = sh ? (sh.fillColor || sh.color || S.color) : (S.shapeFillColor || S.color)
|
|
||||||
let html = '<span class="iwb-opt-label">描边</span>'
|
let html = '<span class="iwb-opt-label">描边</span>'
|
||||||
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${stroke}" title="描边颜色(与左侧主色同步,吸管取色也写这里)">`
|
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`
|
||||||
if (owner) {
|
if (owner) {
|
||||||
html += '<span class="iwb-opt-label">填充</span>'
|
html += '<span class="iwb-opt-label">填充</span>'
|
||||||
+ `<input type="color" class="iwb-opt-color${fillOn ? '' : ' is-off'}" data-shape-color="fill" data-fill-owner="${owner}" value="${fill}" title="填充颜色${fillOn ? '' : ';当前是描边模式,选色会自动切成实心'}">`
|
+ `<input type="color" class="iwb-opt-color${sl.fillOn ? '' : ' is-off'}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? '' : ';当前无填充,选色会自动切成实心'}">`
|
||||||
}
|
}
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
@@ -1248,16 +1328,23 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
// 矢量图形的描边/填充色块(选中对象读对象自己的值,没选中读新建默认值)
|
// 矢量图形的描边/填充色块(选中对象读对象自己的值,没选中读新建默认值)
|
||||||
body.querySelectorAll('[data-shape-color]').forEach(inp => {
|
body.querySelectorAll('[data-shape-color]').forEach(inp => {
|
||||||
const kind = inp.dataset.shapeColor
|
const kind = inp.dataset.shapeColor
|
||||||
const owner = inp.dataset.fillOwner === 'pen' ? 'pen' : 'rect'
|
const sl = colorSlots()
|
||||||
const stroke = selShape ? (selShape.color || S.color) : S.color
|
const v = kind === 'fill' ? sl.fill : sl.stroke
|
||||||
const fill = selShape ? (selShape.fillColor || selShape.color || S.color) : (S.shapeFillColor || S.color)
|
|
||||||
const v = kind === 'fill' ? fill : stroke
|
|
||||||
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
||||||
if (kind === 'fill') {
|
if (kind === 'fill') {
|
||||||
const on = selShape ? !!selShape.fill : (owner === 'pen' ? S.penFill : S.rectFill)
|
// 无填充时也标成「未生效」:色块上留着上次的颜色很容易被当成「现在就是填充色」
|
||||||
inp.classList.toggle('is-off', !on)
|
inp.classList.toggle('is-off', !sl.fillOn)
|
||||||
|
inp.title = sl.fillOn
|
||||||
|
? '填充色:与工具栏右下的填充色块是同一份'
|
||||||
|
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
|
||||||
|
} else {
|
||||||
|
inp.title = '描边色:与工具栏左上的描边色块是同一份'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
|
||||||
|
// 否则会出现「选中一个矩形 → 选项栏显示它的颜色 → 工具栏还停在上一格」。
|
||||||
|
// updateColorUI 不回调 syncOptionBar,不会递归。
|
||||||
|
updateColorUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 状态栏:缩放 / 尺寸 / 光标 / 选区 / 当前层 / 工具 */
|
/** 状态栏:缩放 / 尺寸 / 光标 / 选区 / 当前层 / 工具 */
|
||||||
@@ -1353,33 +1440,86 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (committed) radiusSnapDone = false
|
if (committed) radiusSnapDone = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 形状描边色 / 填充色(v1.10)。
|
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
|
||||||
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
||||||
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
||||||
* 填充色写形状自己的 fillColor;还没切实心时选填充色顺手切实心(与文字底色同一逻辑)。 */
|
* 填充色写形状自己的 fillColor;还没切实心时选填充色顺手切实心(与文字底色同一逻辑)。
|
||||||
function applyShapeColor(kind, raw) {
|
* kind='none' = 无填充:只关 fill,颜色留着不动,下次点颜色还是它。 */
|
||||||
const hex = String(raw || '').toLowerCase()
|
function applyShapeColor(kind, raw, opts) {
|
||||||
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
const skipHistory = !!(opts && opts.skipHistory)
|
||||||
if (kind === 'stroke') {
|
const sh = getSelectedShape()
|
||||||
applyColorChange(hex)
|
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()
|
syncOptionBar()
|
||||||
return
|
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
|
S.shapeFillColor = hex
|
||||||
rememberColor(hex)
|
|
||||||
const sh = getSelectedShape()
|
|
||||||
const owner = sh ? (sh.type === 'pen' ? 'pen' : 'rect') : (S.tool === 'pen' ? 'pen' : 'rect')
|
|
||||||
if (owner === 'pen') S.penFill = true
|
if (owner === 'pen') S.penFill = true
|
||||||
else S.rectFill = true
|
else S.rectFill = true
|
||||||
updateFillUI()
|
updateFillUI()
|
||||||
if (sh && !sh.locked) {
|
if (sh && !sh.locked) {
|
||||||
saveSnapshot('填充颜色')
|
if (!skipHistory) saveSnapshot('填充颜色')
|
||||||
// 未闭合的钢笔路径没有可填区域,保持描边(否则按钮亮着、画面没变化)
|
|
||||||
sh.fillColor = hex
|
sh.fillColor = hex
|
||||||
sh.fill = owner === 'pen' ? !!sh.closed : true
|
sh.fill = owner === 'pen' ? !!sh.closed : true
|
||||||
renderObjects()
|
renderObjects()
|
||||||
}
|
}
|
||||||
syncOptionBar()
|
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()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个。
|
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个。
|
||||||
@@ -1389,6 +1529,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (isPen) S.penFill = !!fill
|
if (isPen) S.penFill = !!fill
|
||||||
else S.rectFill = !!fill
|
else S.rectFill = !!fill
|
||||||
updateFillUI()
|
updateFillUI()
|
||||||
|
updateColorUI() // 填充块的斜杠(无填充)要跟着变
|
||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
const sh = getSelectedShape()
|
const sh = getSelectedShape()
|
||||||
const types = isPen ? ['pen'] : ['rect', 'circle']
|
const types = isPen ? ['pen'] : ['rect', 'circle']
|
||||||
@@ -1669,17 +1810,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
if (!pop || pop.hidden) return false
|
if (!pop || pop.hidden) return false
|
||||||
pop.hidden = true
|
pop.hidden = true
|
||||||
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]')
|
runtime.el.querySelectorAll('[data-action="toggleColorPop"]').forEach(btn => {
|
||||||
if (btn) { btn.classList.remove('active'); btn.setAttribute('aria-expanded', 'false') }
|
btn.classList.remove('active')
|
||||||
|
btn.setAttribute('aria-expanded', 'false')
|
||||||
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 弹层定位:贴工具栏色点上方、左对齐;上方放不下翻到下方,左右夹在 modal 内。
|
/** 弹层定位:贴当前那一格色块上方、左对齐;上方放不下翻到下方,左右夹在 modal 内。
|
||||||
* 坐标用「按钮矩形 − modal 矩形」算,弹层是 modal 的绝对定位子节点,
|
* 坐标用「按钮矩形 − modal 矩形」算,弹层是 modal 的绝对定位子节点,
|
||||||
* 这样宿主页面有 transform 时也不会错位。 */
|
* 这样宿主页面有 transform 时也不会错位。 */
|
||||||
function positionColorPop() {
|
function positionColorPop() {
|
||||||
const pop = runtime.el && runtime.el.querySelector('.iwb-editor-color-pop')
|
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')
|
const modal = runtime.el && runtime.el.querySelector('.iwb-editor-modal')
|
||||||
if (!pop || !btn || !modal || pop.hidden) return
|
if (!pop || !btn || !modal || pop.hidden) return
|
||||||
const mr = modal.getBoundingClientRect()
|
const mr = modal.getBoundingClientRect()
|
||||||
@@ -1693,40 +1836,65 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
pop.style.top = Math.round(top) + 'px'
|
pop.style.top = Math.round(top) + 'px'
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleColorPop() {
|
/** 点工具栏色块:同一格再点一次收起;点另一格直接换编辑目标(不收起),
|
||||||
|
* 这样「描边改完顺手改填充」不用开关两次弹层。 */
|
||||||
|
function toggleColorPop(slot) {
|
||||||
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]')
|
if (!pop) return
|
||||||
if (!pop || !btn) return
|
const want = slot === 'fill' ? 'fill' : 'stroke'
|
||||||
|
if (!pop.hidden && S.colorTarget === want) { closeColorPop(); return }
|
||||||
|
S.colorTarget = want
|
||||||
if (pop.hidden) {
|
if (pop.hidden) {
|
||||||
pop.hidden = false // 先显示再量:hidden 元素 getBoundingClientRect 全是 0
|
pop.hidden = false // 先显示再量:hidden 元素 getBoundingClientRect 全是 0
|
||||||
btn.classList.add('active')
|
updateColorUI()
|
||||||
btn.setAttribute('aria-expanded', 'true')
|
|
||||||
positionColorPop()
|
positionColorPop()
|
||||||
} else {
|
} else {
|
||||||
closeColorPop()
|
updateColorUI()
|
||||||
|
positionColorPop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 色板弹层(v1.3):工具栏色点开关;hex/吸管/推荐色/调色器都在这一个弹层里 */
|
/** 色板弹层(v1.3;v1.11 起同时服务描边与填充两个槽):
|
||||||
|
* 工具栏两个色块开关;tab / hex / 吸管 / 推荐色 / 调色器 / 无填充都在这一个弹层里 */
|
||||||
function bindColorPanel() {
|
function bindColorPanel() {
|
||||||
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
const colorBtn = runtime.el.querySelector('[data-action="toggleColorPop"]')
|
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')]
|
||||||
if (colorBtn) {
|
colorBtns.forEach(btn => {
|
||||||
colorBtn.addEventListener('mousedown', (e) => e.stopPropagation())
|
btn.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
colorBtn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop() })
|
btn.addEventListener('click', (e) => { e.stopPropagation(); toggleColorPop(btn.dataset.colorSlot) })
|
||||||
}
|
})
|
||||||
if (pop) {
|
if (pop) {
|
||||||
pop.addEventListener('mousedown', (e) => e.stopPropagation())
|
pop.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
|
// 点外面关闭:必须用捕获阶段 —— 画布的 mousedown 会 preventDefault,
|
||||||
// 冒泡阶段拿不到「点了外面」这件事。
|
// 冒泡阶段拿不到「点了外面」这件事。
|
||||||
document.addEventListener('mousedown', (e) => {
|
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)
|
}, true)
|
||||||
window.addEventListener('resize', positionColorPop)
|
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,
|
// 拖动取色期间只拍一次快照:applyColorChange 每改一次颜色都会 saveSnapshot,
|
||||||
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
|
// 在 SV 里拖一下会连拍几百张全画质 ImageData(4K 图直接吃掉几百 MB)。
|
||||||
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
|
// pointerdown 先拍(此时颜色还没变,快照是「改之前」),之后每步只改对象。
|
||||||
@@ -1739,7 +1907,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (!dragSnapped) {
|
if (!dragSnapped) {
|
||||||
if (hasColorTarget()) { saveSnapshot(); dragSnapped = true }
|
if (hasColorTarget()) { saveSnapshot(); dragSnapped = true }
|
||||||
}
|
}
|
||||||
applyColorChange(color, { skipHistory: true })
|
applyPanelColor(color, { skipHistory: true })
|
||||||
}
|
}
|
||||||
const panelHexInput = runtime.el.querySelector('.iwb-editor-color-hex-input')
|
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) })
|
if (panelHexInput) panelHexInput.addEventListener('change', () => { if (/^#[0-9a-f]{6}$/i.test(panelHexInput.value)) setPanelColor(panelHexInput.value) })
|
||||||
@@ -1762,7 +1930,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const sv = runtime.el.querySelector('.iwb-color-sv')
|
const sv = runtime.el.querySelector('.iwb-color-sv')
|
||||||
const hue = runtime.el.querySelector('.iwb-color-hue')
|
const hue = runtime.el.querySelector('.iwb-color-hue')
|
||||||
const initHsv = (() => {
|
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 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
|
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min
|
||||||
let h = 0
|
let h = 0
|
||||||
@@ -1788,9 +1956,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
setDragColor(hsvToHex(hueValue, satValue, valValue))
|
setDragColor(hsvToHex(hueValue, satValue, valValue))
|
||||||
}
|
}
|
||||||
// 推荐色 / hex / 吸管改色时,闭包里的 h/s/v 会过期(v1.3 修:以前点了绿色再拖 SV 会跳回红色)。
|
// 推荐色 / hex / 吸管改色时,闭包里的 h/s/v 会过期(v1.3 修:以前点了绿色再拖 SV 会跳回红色)。
|
||||||
// 每次按下前从 S.color 重新同步;灰阶(d=0,如 #000)反推不出色相,就沿用旧色相。
|
// 每次按下前从当前槽的颜色重新同步;灰阶(d=0,如 #000)反推不出色相,就沿用旧色相。
|
||||||
const syncFromColor = () => {
|
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 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
|
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min
|
||||||
if (d > 0) {
|
if (d > 0) {
|
||||||
@@ -1817,18 +1985,18 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
|
|
||||||
/** 裁剪约束控件已迁入选项栏(bindLiteUI 的点击委托统一处理),旧的直连绑定移除。 */
|
/** 裁剪约束控件已迁入选项栏(bindLiteUI 的点击委托统一处理),旧的直连绑定移除。 */
|
||||||
|
|
||||||
/** 调色板色块与自定义取色 input */
|
/** 调色板色块与自定义取色 input(旧侧栏,现已迁到弹层,保留兜底) */
|
||||||
function bindColorPalette() {
|
function bindColorPalette() {
|
||||||
// 颜色
|
// 颜色
|
||||||
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
|
runtime.el.querySelectorAll('.iwb-editor-color[data-color]').forEach(s => {
|
||||||
s.addEventListener('mousedown', (e) => e.stopPropagation())
|
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')
|
const colorInput = runtime.el.querySelector('.iwb-editor-color-picker-input')
|
||||||
if (colorInput) {
|
if (colorInput) {
|
||||||
colorInput.addEventListener('mousedown', (e) => e.stopPropagation())
|
colorInput.addEventListener('mousedown', (e) => e.stopPropagation())
|
||||||
colorInput.addEventListener('input', () => applyColorChange(colorInput.value))
|
colorInput.addEventListener('input', () => applyPanelColor(colorInput.value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,10 @@
|
|||||||
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||||
shapeFillColor: null,
|
shapeFillColor: null,
|
||||||
|
// v1.11:工具栏色板当前在调哪个颜色。描边与填充是同一个控件上的两个槽,
|
||||||
|
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
|
||||||
|
// 否则「三个地方各调各的颜色」会一直存在。
|
||||||
|
colorTarget: 'stroke', // stroke | fill
|
||||||
textSize: 32, // 新建文字的字号 px
|
textSize: 32, // 新建文字的字号 px
|
||||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
textWeight: 'bold', // bold | normal | 900
|
textWeight: 'bold', // bold | normal | 900
|
||||||
|
|||||||
+203
-57
@@ -9,7 +9,7 @@
|
|||||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||||
id: 'image-annotate',
|
id: 'image-annotate',
|
||||||
name: '标注 / 修图',
|
name: '标注 / 修图',
|
||||||
version: '1.10.0',
|
version: '1.11.0',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
@@ -193,6 +193,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||||
shapeFillColor: null,
|
shapeFillColor: null,
|
||||||
|
// v1.11:工具栏色板当前在调哪个颜色。描边与填充是同一个控件上的两个槽,
|
||||||
|
// 色板(调色器 / 吸管 / 推荐色 / hex)按这个值决定写 S.color 还是 shapeFillColor,
|
||||||
|
// 否则「三个地方各调各的颜色」会一直存在。
|
||||||
|
colorTarget: "stroke",
|
||||||
|
// stroke | fill
|
||||||
textSize: 32,
|
textSize: 32,
|
||||||
// 新建文字的字号 px
|
// 新建文字的字号 px
|
||||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
@@ -3559,8 +3564,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-tools">
|
<div class="iwb-editor-tools">
|
||||||
<!-- 当前色圆点(v1.3):点开就是完整色板,侧栏不再放调色板 -->
|
<!-- 颜色(v1.11):描边 + 填充 两个槽叠放在一个按钮位里(PS 式前/背景色)。
|
||||||
<button type="button" class="iwb-editor-color-btn" data-action="toggleColorPop" aria-expanded="false" title="颜色:点开色板(调色器 / 吸管 / 推荐色)"><i></i></button>
|
点哪个槽就调哪个:色板只有一套,写谁由 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>
|
<span class="iwb-editor-divider"></span>
|
||||||
<button class="iwb-editor-tool" data-tool="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg></button>
|
<button class="iwb-editor-tool" data-tool="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg></button>
|
||||||
<span class="iwb-editor-divider"></span>
|
<span class="iwb-editor-divider"></span>
|
||||||
@@ -3660,6 +3671,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
|
||||||
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
|
||||||
<div class="iwb-editor-color-pop" hidden>
|
<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-pop-picker">
|
||||||
<div class="iwb-color-sv"><span></span></div>
|
<div class="iwb-color-sv"><span></span></div>
|
||||||
<div class="iwb-color-hue"><span></span></div>
|
<div class="iwb-color-hue"><span></span></div>
|
||||||
@@ -3686,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="#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>
|
<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="#000000" style="background:#000000" title="#000000"></button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
<div class="iwb-editor-toast" role="status" aria-live="polite"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -4263,7 +4284,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
function onPickerMouseDown(pos) {
|
function onPickerMouseDown(pos) {
|
||||||
const s = sampleColor(pos);
|
const s = sampleColor(pos);
|
||||||
if (s && s.a > 0) {
|
if (s && s.a > 0) {
|
||||||
applyColorChange(rgbToHex(s.r, s.g, s.b));
|
applyPanelColor(rgbToHex(s.r, s.g, s.b));
|
||||||
}
|
}
|
||||||
exitPicker();
|
exitPicker();
|
||||||
return;
|
return;
|
||||||
@@ -4809,21 +4830,79 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
layer.canvas.style.cursor = cur;
|
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() {
|
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;
|
let matchPreset = false;
|
||||||
runtime.el.querySelectorAll(".iwb-editor-color[data-color]").forEach((s) => {
|
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;
|
if (on) matchPreset = true;
|
||||||
s.classList.toggle("active", on);
|
s.classList.toggle("active", on);
|
||||||
});
|
});
|
||||||
const panelHex = runtime.el.querySelector(".iwb-editor-color-hex");
|
const panelHex = runtime.el.querySelector(".iwb-editor-color-hex");
|
||||||
const hexInput = runtime.el.querySelector(".iwb-editor-color-hex-input");
|
const hexInput = runtime.el.querySelector(".iwb-editor-color-hex-input");
|
||||||
if (hexInput && document.activeElement !== hexInput) hexInput.value = S.color.toUpperCase();
|
if (hexInput && document.activeElement !== hexInput) hexInput.value = cur.toUpperCase();
|
||||||
const colorDot = runtime.el.querySelector(".iwb-editor-color-btn i");
|
runtime.el.querySelectorAll(".iwb-editor-color-panel-swatch").forEach((sw) => sw.classList.toggle("active", (sw.dataset.panelColor || "").toLowerCase() === cur.toLowerCase()));
|
||||||
if (colorDot) colorDot.style.background = S.color;
|
if (panelHex) panelHex.textContent = cur.toUpperCase();
|
||||||
runtime.el.querySelectorAll(".iwb-editor-color-panel-swatch").forEach((sw) => sw.classList.toggle("active", (sw.dataset.panelColor || "").toLowerCase() === S.color.toLowerCase()));
|
const rgb = hexToRgb(cur);
|
||||||
if (panelHex) panelHex.textContent = S.color.toUpperCase();
|
|
||||||
const rgb = hexToRgb(S.color);
|
|
||||||
const max = Math.max(rgb.r, rgb.g, rgb.b) / 255, min = Math.min(rgb.r, rgb.g, rgb.b) / 255;
|
const max = Math.max(rgb.r, rgb.g, rgb.b) / 255, min = Math.min(rgb.r, rgb.g, rgb.b) / 255;
|
||||||
const d = max - min;
|
const d = max - min;
|
||||||
let h = 0;
|
let h = 0;
|
||||||
@@ -4848,7 +4927,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (custom) {
|
if (custom) {
|
||||||
custom.classList.toggle("active", !matchPreset);
|
custom.classList.toggle("active", !matchPreset);
|
||||||
const inp = custom.querySelector("input");
|
const inp = custom.querySelector("input");
|
||||||
if (inp) inp.value = S.color;
|
if (inp) inp.value = cur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function updateBrushUI() {
|
function updateBrushUI() {
|
||||||
@@ -4920,12 +4999,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
<span class="iwb-opt-hint">拖出裁剪框;Enter 确认 · Esc 取消;裁剪后可 Ctrl+Z</span>`;
|
<span class="iwb-opt-hint">拖出裁剪框;Enter 确认 · Esc 取消;裁剪后可 Ctrl+Z</span>`;
|
||||||
}
|
}
|
||||||
function shapeColorHTML(sh, owner) {
|
function shapeColorHTML(sh, owner) {
|
||||||
const stroke = sh ? sh.color || S.color : S.color;
|
const sl = colorSlots();
|
||||||
const fillOn = sh ? !!sh.fill : owner === "pen" ? S.penFill : S.rectFill;
|
let html = `<span class="iwb-opt-label">描边</span><input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`;
|
||||||
const fill = sh ? sh.fillColor || sh.color || S.color : S.shapeFillColor || S.color;
|
|
||||||
let html = `<span class="iwb-opt-label">描边</span><input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${stroke}" title="描边颜色(与左侧主色同步,吸管取色也写这里)">`;
|
|
||||||
if (owner) {
|
if (owner) {
|
||||||
html += `<span class="iwb-opt-label">填充</span><input type="color" class="iwb-opt-color${fillOn ? "" : " is-off"}" data-shape-color="fill" data-fill-owner="${owner}" value="${fill}" title="填充颜色${fillOn ? "" : ";当前是描边模式,选色会自动切成实心"}">`;
|
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;
|
return html;
|
||||||
}
|
}
|
||||||
@@ -5110,16 +5187,17 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
});
|
});
|
||||||
body.querySelectorAll("[data-shape-color]").forEach((inp) => {
|
body.querySelectorAll("[data-shape-color]").forEach((inp) => {
|
||||||
const kind = inp.dataset.shapeColor;
|
const kind = inp.dataset.shapeColor;
|
||||||
const owner = inp.dataset.fillOwner === "pen" ? "pen" : "rect";
|
const sl = colorSlots();
|
||||||
const stroke = selShape ? selShape.color || S.color : S.color;
|
const v = kind === "fill" ? sl.fill : sl.stroke;
|
||||||
const fill = selShape ? selShape.fillColor || selShape.color || S.color : S.shapeFillColor || S.color;
|
|
||||||
const v = kind === "fill" ? fill : stroke;
|
|
||||||
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
|
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
|
||||||
if (kind === "fill") {
|
if (kind === "fill") {
|
||||||
const on = selShape ? !!selShape.fill : owner === "pen" ? S.penFill : S.rectFill;
|
inp.classList.toggle("is-off", !sl.fillOn);
|
||||||
inp.classList.toggle("is-off", !on);
|
inp.title = sl.fillOn ? "填充色:与工具栏右下的填充色块是同一份" : "当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」";
|
||||||
|
} else {
|
||||||
|
inp.title = "描边色:与工具栏左上的描边色块是同一份";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
updateColorUI();
|
||||||
}
|
}
|
||||||
function updateStatusbar() {
|
function updateStatusbar() {
|
||||||
if (!runtime.el) return;
|
if (!runtime.el) return;
|
||||||
@@ -5212,34 +5290,80 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
renderObjects();
|
renderObjects();
|
||||||
if (committed) radiusSnapDone = false;
|
if (committed) radiusSnapDone = false;
|
||||||
}
|
}
|
||||||
function applyShapeColor(kind, raw) {
|
function applyShapeColor(kind, raw, opts) {
|
||||||
const hex = String(raw || "").toLowerCase();
|
const skipHistory = !!(opts && opts.skipHistory);
|
||||||
if (!/^#[0-9a-f]{6}$/.test(hex)) return;
|
const sh = getSelectedShape();
|
||||||
if (kind === "stroke") {
|
const owner = sh ? sh.type === "pen" ? "pen" : "rect" : S.tool === "pen" ? "pen" : "rect";
|
||||||
applyColorChange(hex);
|
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();
|
syncOptionBar();
|
||||||
return;
|
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;
|
S.shapeFillColor = hex;
|
||||||
rememberColor(hex);
|
|
||||||
const sh = getSelectedShape();
|
|
||||||
const owner = sh ? sh.type === "pen" ? "pen" : "rect" : S.tool === "pen" ? "pen" : "rect";
|
|
||||||
if (owner === "pen") S.penFill = true;
|
if (owner === "pen") S.penFill = true;
|
||||||
else S.rectFill = true;
|
else S.rectFill = true;
|
||||||
updateFillUI();
|
updateFillUI();
|
||||||
if (sh && !sh.locked) {
|
if (sh && !sh.locked) {
|
||||||
saveSnapshot("填充颜色");
|
if (!skipHistory) saveSnapshot("填充颜色");
|
||||||
sh.fillColor = hex;
|
sh.fillColor = hex;
|
||||||
sh.fill = owner === "pen" ? !!sh.closed : true;
|
sh.fill = owner === "pen" ? !!sh.closed : true;
|
||||||
renderObjects();
|
renderObjects();
|
||||||
}
|
}
|
||||||
syncOptionBar();
|
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) {
|
function setShapeFill(fill, owner) {
|
||||||
const isPen = owner === "pen";
|
const isPen = owner === "pen";
|
||||||
if (isPen) S.penFill = !!fill;
|
if (isPen) S.penFill = !!fill;
|
||||||
else S.rectFill = !!fill;
|
else S.rectFill = !!fill;
|
||||||
updateFillUI();
|
updateFillUI();
|
||||||
|
updateColorUI();
|
||||||
syncOptionBar();
|
syncOptionBar();
|
||||||
const sh = getSelectedShape();
|
const sh = getSelectedShape();
|
||||||
const types = isPen ? ["pen"] : ["rect", "circle"];
|
const types = isPen ? ["pen"] : ["rect", "circle"];
|
||||||
@@ -5489,16 +5613,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const pop = runtime.el && runtime.el.querySelector(".iwb-editor-color-pop");
|
const pop = runtime.el && runtime.el.querySelector(".iwb-editor-color-pop");
|
||||||
if (!pop || pop.hidden) return false;
|
if (!pop || pop.hidden) return false;
|
||||||
pop.hidden = true;
|
pop.hidden = true;
|
||||||
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]');
|
runtime.el.querySelectorAll('[data-action="toggleColorPop"]').forEach((btn) => {
|
||||||
if (btn) {
|
|
||||||
btn.classList.remove("active");
|
btn.classList.remove("active");
|
||||||
btn.setAttribute("aria-expanded", "false");
|
btn.setAttribute("aria-expanded", "false");
|
||||||
}
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function positionColorPop() {
|
function positionColorPop() {
|
||||||
const pop = runtime.el && runtime.el.querySelector(".iwb-editor-color-pop");
|
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");
|
const modal = runtime.el && runtime.el.querySelector(".iwb-editor-modal");
|
||||||
if (!pop || !btn || !modal || pop.hidden) return;
|
if (!pop || !btn || !modal || pop.hidden) return;
|
||||||
const mr = modal.getBoundingClientRect();
|
const mr = modal.getBoundingClientRect();
|
||||||
@@ -5511,37 +5634,60 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
pop.style.left = Math.round(left) + "px";
|
pop.style.left = Math.round(left) + "px";
|
||||||
pop.style.top = Math.round(top) + "px";
|
pop.style.top = Math.round(top) + "px";
|
||||||
}
|
}
|
||||||
function toggleColorPop() {
|
function toggleColorPop(slot) {
|
||||||
const pop = runtime.el.querySelector(".iwb-editor-color-pop");
|
const pop = runtime.el.querySelector(".iwb-editor-color-pop");
|
||||||
const btn = runtime.el.querySelector('[data-action="toggleColorPop"]');
|
if (!pop) return;
|
||||||
if (!pop || !btn) return;
|
const want = slot === "fill" ? "fill" : "stroke";
|
||||||
|
if (!pop.hidden && S.colorTarget === want) {
|
||||||
|
closeColorPop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
S.colorTarget = want;
|
||||||
if (pop.hidden) {
|
if (pop.hidden) {
|
||||||
pop.hidden = false;
|
pop.hidden = false;
|
||||||
btn.classList.add("active");
|
updateColorUI();
|
||||||
btn.setAttribute("aria-expanded", "true");
|
|
||||||
positionColorPop();
|
positionColorPop();
|
||||||
} else {
|
} else {
|
||||||
closeColorPop();
|
updateColorUI();
|
||||||
|
positionColorPop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function bindColorPanel() {
|
function bindColorPanel() {
|
||||||
const pop = runtime.el.querySelector(".iwb-editor-color-pop");
|
const pop = runtime.el.querySelector(".iwb-editor-color-pop");
|
||||||
const colorBtn = runtime.el.querySelector('[data-action="toggleColorPop"]');
|
const colorBtns = [...runtime.el.querySelectorAll('[data-action="toggleColorPop"]')];
|
||||||
if (colorBtn) {
|
colorBtns.forEach((btn) => {
|
||||||
colorBtn.addEventListener("mousedown", (e) => e.stopPropagation());
|
btn.addEventListener("mousedown", (e) => e.stopPropagation());
|
||||||
colorBtn.addEventListener("click", (e) => {
|
btn.addEventListener("click", (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
toggleColorPop();
|
toggleColorPop(btn.dataset.colorSlot);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
if (pop) {
|
if (pop) {
|
||||||
pop.addEventListener("mousedown", (e) => e.stopPropagation());
|
pop.addEventListener("mousedown", (e) => e.stopPropagation());
|
||||||
document.addEventListener("mousedown", (e) => {
|
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);
|
}, true);
|
||||||
window.addEventListener("resize", positionColorPop);
|
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;
|
let dragSnapped = false;
|
||||||
const hasColorTarget = () => {
|
const hasColorTarget = () => {
|
||||||
const t = getSelectedText(), sh = getSelectedShape();
|
const t = getSelectedText(), sh = getSelectedShape();
|
||||||
@@ -5554,7 +5700,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
dragSnapped = true;
|
dragSnapped = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
applyColorChange(color, { skipHistory: true });
|
applyPanelColor(color, { skipHistory: true });
|
||||||
};
|
};
|
||||||
const panelHexInput = runtime.el.querySelector(".iwb-editor-color-hex-input");
|
const panelHexInput = runtime.el.querySelector(".iwb-editor-color-hex-input");
|
||||||
if (panelHexInput) panelHexInput.addEventListener("change", () => {
|
if (panelHexInput) panelHexInput.addEventListener("change", () => {
|
||||||
@@ -5579,7 +5725,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const sv = runtime.el.querySelector(".iwb-color-sv");
|
const sv = runtime.el.querySelector(".iwb-color-sv");
|
||||||
const hue = runtime.el.querySelector(".iwb-color-hue");
|
const hue = runtime.el.querySelector(".iwb-color-hue");
|
||||||
const initHsv = (() => {
|
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 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;
|
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min;
|
||||||
let h = 0;
|
let h = 0;
|
||||||
@@ -5630,7 +5776,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
setDragColor(hsvToHex(hueValue, satValue, valValue));
|
setDragColor(hsvToHex(hueValue, satValue, valValue));
|
||||||
};
|
};
|
||||||
const syncFromColor = () => {
|
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 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;
|
const max = Math.max(rr, gg, bb), min = Math.min(rr, gg, bb), d = max - min;
|
||||||
if (d > 0) {
|
if (d > 0) {
|
||||||
@@ -5670,12 +5816,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
function bindColorPalette() {
|
function bindColorPalette() {
|
||||||
runtime.el.querySelectorAll(".iwb-editor-color[data-color]").forEach((s) => {
|
runtime.el.querySelectorAll(".iwb-editor-color[data-color]").forEach((s) => {
|
||||||
s.addEventListener("mousedown", (e) => e.stopPropagation());
|
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");
|
const colorInput = runtime.el.querySelector(".iwb-editor-color-picker-input");
|
||||||
if (colorInput) {
|
if (colorInput) {
|
||||||
colorInput.addEventListener("mousedown", (e) => e.stopPropagation());
|
colorInput.addEventListener("mousedown", (e) => e.stopPropagation());
|
||||||
colorInput.addEventListener("input", () => applyColorChange(colorInput.value));
|
colorInput.addEventListener("input", () => applyPanelColor(colorInput.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function bindFillToggle() {
|
function bindFillToggle() {
|
||||||
@@ -7923,7 +8069,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// image-annotate/plugin/editor.css
|
// 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
|
// image-annotate/plugin/glue.js
|
||||||
function createGlue(ctx, css) {
|
function createGlue(ctx, css) {
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ check('调色板已搬进工具栏:侧栏只剩缩放,SV/色相/推荐色都
|
|||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
const q = (s) => Boolean(document.querySelector(s))
|
const q = (s) => Boolean(document.querySelector(s))
|
||||||
return !q('.iwb-editor-left .iwb-editor-color-panel') &&
|
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') &&
|
q('.iwb-editor-color-pop .iwb-color-sv') && q('.iwb-editor-color-pop .iwb-color-hue') &&
|
||||||
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-panel-swatch').length === 12 &&
|
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-panel-swatch').length === 12 &&
|
||||||
q('.iwb-editor-zoom') &&
|
q('.iwb-editor-zoom') &&
|
||||||
@@ -180,7 +180,7 @@ check('色板弹层默认收起;点工具栏色点弹出、且整块在视口
|
|||||||
await (async () => {
|
await (async () => {
|
||||||
const pop = page.locator('.iwb-editor-color-pop')
|
const pop = page.locator('.iwb-editor-color-pop')
|
||||||
if (await pop.isVisible()) return 'pre: 弹层一开始就开着'
|
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)
|
await page.waitForTimeout(100)
|
||||||
if (!(await pop.isVisible())) return 'post: 点了没开'
|
if (!(await pop.isVisible())) return 'post: 点了没开'
|
||||||
const box = await pop.boundingBox()
|
const box = await pop.boundingBox()
|
||||||
@@ -944,9 +944,9 @@ check('选中矢量形状后切吸管:选中态保留、取色写回形状、
|
|||||||
const selId = (await dbg()).selectedShapeId
|
const selId = (await dbg()).selectedShapeId
|
||||||
if (!selId) return 'pre: 没有选中形状'
|
if (!selId) return 'pre: 没有选中形状'
|
||||||
// 先换成一个可辨识的颜色,便于判断取色真的改了对象(v1.3:推荐色在弹层里,先点开色点)
|
// 先换成一个可辨识的颜色,便于判断取色真的改了对象(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-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)
|
const before = (await dbg()).shapes.find(s => s.id === selId)
|
||||||
if (!before || before.color !== '#4488ff') return 'pre: color=' + (before && before.color)
|
if (!before || before.color !== '#4488ff') return 'pre: color=' + (before && before.color)
|
||||||
await page.keyboard.press('i') // 切吸管
|
await page.keyboard.press('i') // 切吸管
|
||||||
@@ -1003,7 +1003,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
|
|||||||
await page.waitForTimeout(120)
|
await page.waitForTimeout(120)
|
||||||
if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状'
|
if (!(await dbg()).selectedShapeId) return 'pre: 没选中形状'
|
||||||
const h0 = (await dbg()).history
|
const h0 = (await dbg()).history
|
||||||
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"]').click()
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||||
const sv = await page.locator('.iwb-color-sv').boundingBox()
|
const sv = await page.locator('.iwb-color-sv').boundingBox()
|
||||||
await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2)
|
await page.mouse.move(sv.x + sv.width * 0.2, sv.y + sv.height * 0.2)
|
||||||
await page.mouse.down()
|
await page.mouse.down()
|
||||||
@@ -1011,7 +1011,7 @@ check('拖调色器改选中形状颜色:历史只增加 1 条', await (async
|
|||||||
await page.mouse.up()
|
await page.mouse.up()
|
||||||
await page.waitForTimeout(150)
|
await page.waitForTimeout(150)
|
||||||
const h1 = (await dbg()).history
|
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
|
return h1 - h0 === 1 ? true : 'history ' + h0 + '→' + h1
|
||||||
})())
|
})())
|
||||||
|
|
||||||
@@ -2007,7 +2007,7 @@ check('矩形圆角生效(角落被切,墨迹减少)',
|
|||||||
'radius=' + JSON.stringify(radiusVal) + ' ink ' + inkSharp + '→' + inkRound)
|
'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.waitForTimeout(150)
|
||||||
await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click()
|
await page.locator('.iwb-editor-color-pop [data-panel-color="#ffd400"]').first().click()
|
||||||
await page.waitForTimeout(200)
|
await page.waitForTimeout(200)
|
||||||
@@ -2104,6 +2104,93 @@ check('改图形描边色 = 改主色(色板 / 吸管 / 选项栏不会各说
|
|||||||
shapeStroked.shapeColor === '#3388ff' && shapeStroked.mainColor === '#3388ff',
|
shapeStroked.shapeColor === '#3388ff' && shapeStroked.mainColor === '#3388ff',
|
||||||
JSON.stringify(shapeStroked))
|
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()
|
const copyExists = await page.locator('[data-action="copyClipboard"]').count()
|
||||||
await page.locator('[data-action="copyClipboard"]').click()
|
await page.locator('[data-action="copyClipboard"]').click()
|
||||||
await page.waitForTimeout(400)
|
await page.waitForTimeout(400)
|
||||||
|
|||||||
Reference in new issue
Block a user