Compare commits

..
Author SHA1 Message Date
qiqi 20118eec0b feat(style-source): v1.3.0 新增「样式节点」——带变量表单、可继续连线的插件节点
详情页底部新增第三颗「样式节点」按钮(点一下自动找位 / 按住拖到画布松手),
原「插入参考图 / 插入提示词」行为一个字没改。

节点 data 契约:variant/styleId/name/code/outKind:'prompt'/promptTpl/varMeta/vars/
text/preview/refOn/refUrl/refName/collapsed —— 随画布存档,撤销备份跨设备都白拿。

五条硬约束(README 已写死):
1. 不传 run ⇒ 节点上没有生成按钮,出图交给下游生图节点(用户明确要求)
2. 变量全部露出、单行 28px(label 左 / 输入右),24 个变量也不到 800px;「收起」按钮可折
3. vars 与 text 同一次 onUpdate 写回;输入 300ms 防抖 + 失焦立即提交
4. ports 只出不入(宿主兜底分支会用上游顶掉自己的文本)
5. render(node, props, host) 往 host 里画并做增量同步,正在编辑的输入框不覆盖

harness 78 → 88 项(含「二次渲染复用同一批 DOM」这条防失焦回归);
顺手修掉一处既有偶发:拖拽用例的 justDragged 400ms 窗口会吞掉紧随其后的 click。
2026-11-14 08:35:25 +08:00
qiqi a8512ba777 feat(image-annotate): v1.20.1 吸管+色值整组右对齐(不再随 tab 数量浮动),色值框 124→96 2026-11-10 08:48:25 +08:00
qiqi d16e68bfa9 feat(image-annotate): v1.20.0 去色下移为常用色第一格 + 头部控件全部定宽(不再被 flex 抵掉)
- 去色:头部按钮 → 常用色网格第一格(20px 同尺寸、虚线圆 + 斜圈)
- 不可用上下文(文字色 / 未闭合钢笔)不再 hidden,改 disabled + 42% 不透明度,title 说明原因
- 头部定宽:色值框 flex 0 0 124px(原 0 1 150)、加「底色」tab 后色值框与图钉位置不动
- 常用色 16 → 15(亮紫让位,深紫保留),去色 + 15 = 8 列 2 行
- 删掉 :has(...[hidden]) 隐藏竖线的规则,头部结构变纯静态
- harness 231 项 / 真站 e2e 40 项
2026-11-10 07:54:32 +08:00
qiqi 00a2699e89 docs(image-annotate): README 补 v1.19.0 章节 2026-11-10 07:33:04 +08:00
12 changed files with 820 additions and 135 deletions

No files matched your search

+56 -1
View File
@@ -234,6 +234,59 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
## v1.20.1:吸管 + 色值整组右对齐 / 色值框 124 → 96
用户截图:「吸色与色值部分有问题,他现在是左对齐,就会因为前面的颜色属性浮动,我需要他不浮动,
你可以改为右对齐看看,设置框可以小一些,现在长了」。
```
[文字●][描边●][底色●] ⌖ [ #2F6FED ] │ 📌
↑ 这一段整组钉在右侧
```
- v1.20 只把**图钉**推到最右,吸管与色值还紧跟 tab —— 文字工具多出「底色」tab 时这一组就整体右移一次,
切回形状又左移一次,视线每次都要重新找。现在 `.iwb-color-pop-tools` 把
**吸管 + 色值 + 竖线 + 图钉**整组包住并 `margin-left: auto`,左侧剩余空隙全由 tab 组吸收。
- 右组前那条竖线删掉:右对齐后它只会孤零零悬在空白里,空隙本身已经把「选槽 / 取色」分开了。
留下的那条竖线是分隔「图钉」这个常驻开关,位置固定。
- 色值框 `124 → 96px`(用户「设置框可以小一些,现在长了」):#RRGGBB 在 13px 等宽下约 55px,
加 padding 仍有 30px 余量。它现在是右组里的一颗「读数」,不该比吸管/图钉更重。
- 回归断言从「宽度不变」升级为「**逐像素坐标不变**」:`sig = [吸管左, 色值左, 图钉左, 图钉右]`,
两 tab 与三 tab 两种上下文下 `597,629,738,762` 必须完全相同,且图钉右边缘贴住头部右边界(`rightPinned`)。
## v1.20.0:去色下移成常用色第一格 / 头部全部定宽,不再被自动布局抵掉
用户截图反馈:「如果是文本元素的时候,就会把那个去色按钮给丢掉…可以让这些颜色选项一直保持在上面,
只是说不可用的时候是灰色。那个吸色、去色,数值框可以就固定了,避免自动布局给它抵掉」,
随后补一句「或者你把去色按钮放在常用颜色的第一个」。
**根因**:头部一行本来就是「3 个 tab + 竖线 + 吸管 + 色值 + 去色 + 图钉」,440px 的面板里
content 只有 416px,文字工具多出「底色」tab 时已经超出 3px —— 色值框当时是 `flex: 0 1 150px`,
自己缩到 147 顶着,再去掉一份宽度,`去色` 就被 flex 压没了(不是被 `hidden` 藏起来的)。
**做法(两条一起做,正好互相成全)**:
```
[文字●][描边●][底色●] │ ⌖ [ #2F6FED ] │ 📌
常用色 [⊘][🔴][🟠][🟡][🟢][🟩][🔵][🩷]
[⚪][⚫灰][⚫][🟥][🟩][🟦][🟪] ← 去色 = 第一格,永远在
```
- **去色 = 常用色网格第一格**(20px 圆、虚线边框 + 斜圈图标、间距跟色块完全一致)。
位置永远固定,切到文字色 / 未闭合钢笔这类「去掉就等于删对象」的上下文——
**不再 hidden,改成 `disabled` + 32%→42% 不透明度**,title 写明原因
(「去色不可用:文字色去掉就等于把文字删了」),hover 反馈也随 `:disabled` 关掉。
- **头部元素全部定宽**:色值框 `flex: 0 0 124px`(原来是可缩的 150px)、吸管 26、图钉 24、tab 不可压缩。
加上「底色」tab 后色值框宽度与图钉右边缘**一格像素都不动**,harness 有专门的回归断言
(`hexW: [124,124]`、`pinR: [762,762]`)。
- 常用色 16 → 15(亮紫 `#aa44ff` 让位给去色第一格,深紫 `#6b4fbb` 还在),
去色 + 15 色正好仍是 8 列 × 2 行,不出现第 3 行孤零零一个色块。
- 删掉 `:has(> .iwb-color-pop-none[hidden]) > .iwb-color-pop-bar { display: none }`:
去色不再隐藏,竖线也就没有「悬空」问题,头部结构变成纯静态。
测试:harness 231 项(新增「去色是第一格 / 加底色 tab 后头部纹丝不动 / 文字色下去色置灰」3 条,
另有 4 条旧断言从看 `.hidden` 改成看 `.disabled`);真站 e2e 40 项(改为校验 `noneFirst` + 15 色)。
## v1.19.0:右栏调色模块退场 / 头部一行装完 / 常用色 16 个 + 最近两排
用户一段话:「右边栏的调色模块就可以去掉了,然后还去一个去色按钮,可以放在钉住按钮的左边,
@@ -256,9 +309,11 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
对描边/填充/底色都生效,title 随当前槽变。
- 没有可去色的上下文(没选中对象、文字色这种单槽)时它本来就隐藏,**它前面那条竖线跟着一起藏**
(`:has(> .iwb-color-pop-none[hidden])`),否则头部右侧会留一截悬空的「||」。
> v1.20 已推翻:隐藏 ⇒ 置灰 disabled,且整颗下移到常用色第一格(见上一节)。
- 「去色 | 图钉」整组用 `margin-left: auto` 贴最右,色值框固定 150px 不被拉成长条
(拉长后视觉重心全跑到输入框上,色块反倒成了配角)。tab 加 `flex: 0 0 auto; white-space: nowrap`——
宽度不够时该缩的是色值框,不是把「描边」压成竖排两个字。
> v1.20 已改:色值框收紧到定宽 124px 且不再可缩 —— 就是「该缩的是色值框」这条把去色缩没了。
**3) 色块 8 列 × 2 行,常用色 12 → 16,最近色 6 → 16。**
@@ -279,7 +334,7 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
- **分隔线从 `#313244` 提到 `#3b3b4e`**。没有小标题时,这条线是唯一能看出「常用 / 最近」分界的东西,
按原色画在深底上几乎看不见。
**验证**:harness 229 项、真站 e2e 见下。新增 harness 断言:头部四个控件同一水平线 + 去色在图钉左边 +
**验证**:harness 229 项、真站 e2e 40 项全绿。新增 harness 断言:头部四个控件同一水平线 + 去色在图钉左边 +
两者之间有竖线 + 三 tab(文字工具)时头部不横向溢出、常用色 16 个严格 8 列 2 行、最近色网格 8 列 2 排、
弹层宽高区间、右栏第一个模块是「图片调节」且无 `[data-color-surface]`。
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/image-annotate",
"private": true,
"version": "1.19.0",
"version": "1.20.1",
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
"ibwPlugin": {
"id": "image-annotate",
+31 -21
View File
@@ -1803,13 +1803,10 @@
.iwb-color-pop-head { display: flex; align-items: center; gap: 6px; }
/* 竖线:分隔「调哪个槽 / 取色工具 / 去色·钉住」三组,比空白更清楚,又不加边框重量 */
.iwb-color-pop-bar { width: 1px; height: 16px; background: #313244; flex: 0 0 auto; }
/* 「去色 | 图钉」整组贴最右(margin-left:auto)。这样色值框不用拉成一条长条去填空,
头部是「左边调色槽与工具 / 右边两个开关」两段式,扫视时不会把 HEX 当成主角。 */
/* 「吸管 + 色值 + 图钉」整组贴最右(margin-left:auto,v1.20.1)。
v1.20 只推图钉、吸管与色值紧跟 tab —— tab 从 2 个变 3 个(文字工具加「底色」),
这组就整块左右浮一次。现在 tab 组独占左侧、空隙全给它吸收,右组从第一条竖线起整体钉住。 */
.iwb-color-pop-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
/* 没有可去色的上下文(未选中对象 / 文字色这种单槽)时「去色」是隐藏的,
它前面那条竖线要一起藏掉,否则头部右侧会留下一截悬空的「||」;
两条都藏掉后整组只剩图钉,竖线也不再夹在「色值 | 图钉」之间显得多余 */
.iwb-color-pop-tools:has(> .iwb-color-pop-none[hidden]) > .iwb-color-pop-bar { display: none; }
.iwb-color-pop-tab {
display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
@@ -1832,16 +1829,28 @@
background-image: linear-gradient(135deg, transparent calc(50% - 1px), #f38ba8 calc(50% - 1px), #f38ba8 calc(50% + 1px), transparent calc(50% + 1px));
}
.iwb-color-pop-tab[hidden] { display: none; }
/* 去色(v1.19):原来的「无」改名挪位。虚线框 + 红斜圈,和「实心色块」区分开;
它是开关不是色块,所以不用填充色表达状态,只换边框/文字色。 */
/* 去色(v1.20,用户 2026-11-10):头部那颗带文字的按钮下移到「常用色第一格」,
尺寸、间距跟色块完全一致(20px 圆),只是画虚线边框 + 斜圈图标 ——
它是开关不是色块,所以不用填充色表达状态,只换边框/图标色。
永远显示(不可用时不 hidden,只 disabled + 变灰),位置才记得住、头部也不重排。 */
.iwb-color-pop-none {
flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px;
border: 1px dashed #585b70; border-radius: 7px; background: transparent; color: #a6adc8;
font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; cursor: pointer;
flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
width: 20px; height: 20px; padding: 0; margin: 0; box-sizing: border-box;
border: 1px dashed #585b70; border-radius: 50%; background: transparent; color: #a6adc8;
cursor: pointer; transition: transform 0.08s ease, border-color 0.12s ease, color 0.12s ease;
}
.iwb-color-pop-none svg { flex: 0 0 auto; width: 12px; height: 12px; }
/* hover 只对可用态生效:disabled 时不该有放大反馈,否则看着像能点 */
.iwb-color-pop-none:not(:disabled):hover { border-color: #f38ba8; color: #f38ba8; transform: scale(1.14); }
.iwb-color-pop-none.active { border-style: solid; border-color: #f38ba8; color: #f38ba8; background: rgba(243, 139, 168, 0.14); }
/* 不可用:整颗压到 42% 不透明度 —— 灰到能看出「这里有个去色,但现在用不上」,
但不至于淡到看不见(32% 时在深底上几乎消失,等于又变成了「消失」,只是慢一点)。
cursor 保持 default,不给 pointer。 */
.iwb-color-pop-none:disabled,
.iwb-color-pop-none.is-disabled {
opacity: 0.42; cursor: default; color: #8b8fa8; border-color: #4a4a5e;
background: transparent; transform: none;
}
.iwb-color-pop-none svg { flex: 0 0 auto; }
.iwb-color-pop-none:hover { border-color: #f38ba8; color: #f38ba8; }
.iwb-color-pop-none.active { border-style: solid; border-color: #f38ba8; color: #f38ba8; background: rgba(243, 139, 168, 0.12); }
.iwb-color-pop-none[hidden] { display: none; }
.iwb-color-pop-body { display: flex; align-items: stretch; gap: 10px; }
.iwb-color-pop-picker { display: flex; gap: 8px; flex: 0 0 auto; }
@@ -1870,11 +1879,11 @@
/* display:flex 会盖掉 [hidden] 的默认 display:none,必须显式写一条 */
.iwb-color-group[hidden] { display: none; }
/* 色值输入固定 150px:够显示 #RRGGBB 还有余量,又不会被 flex-grow 拉成一条长条
(拉长后视觉重心全跑到输入框上,色块反倒成了配角)。
文字工具多出「底色」tab 时按 0 1 150 自动收缩,min-width 保证七个字符看得全。 */
/* 色值输入定宽 96(v1.20.1 由 124 再收窄,用户「设置框可以小一些,现在长了」)。
#RRGGBB 七个字符在 13px 等宽下约 55px,加左右 padding 10px 仍有 30px 余量;
它现在是右组里的一颗「读数」,不该比吸管/图钉重。仍然定宽不可缩。 */
.iwb-editor-color-pop .iwb-editor-color-hex-input {
flex: 0 1 150px; width: 150px; min-width: 58px; height: 26px; padding: 0 5px; text-align: center;
flex: 0 0 96px; width: 96px; height: 26px; padding: 0 4px; text-align: center;
font: 600 12px monospace; border-radius: 6px; box-sizing: border-box;
}
.iwb-editor-color-pop .iwb-editor-color-swatches {
@@ -2248,7 +2257,8 @@
#iwb-editor-overlay .iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-val,
#iwb-editor-overlay .iwb-editor-left .iwb-editor-zoom .iwb-editor-zoom-fit { font-size: 12px; }
/* 调色面板本体 */
#iwb-editor-overlay .iwb-color-pop-tab,
#iwb-editor-overlay .iwb-color-pop-none { font-size: 12.5px; height: 26px; }
/* 调色面板本体(v1.20:去色已下移到色块网格,这里只剩 tab 需要放大字号;
去色是 20px 格子,高度必须跟色块一致,别被这条统一字号的规则顶成 26px) */
#iwb-editor-overlay .iwb-color-pop-tab { font-size: 12.5px; height: 26px; }
#iwb-editor-overlay .iwb-color-pop-none { width: 20px; height: 20px; }
#iwb-editor-overlay .iwb-editor-color-pop .iwb-editor-color-hex-input { font-size: 13px; }
+26 -15
View File
@@ -17,20 +17,28 @@ import { bindEvents } from './events.js'
* HEX 回填、常用色/最近色的 active 圈),events.js#updateColorUI 按
* `[data-color-surface]` 逐个刷 —— 留着这层抽象,将来若再加一处面板不用重写联动。
*/
/* 16 个常用色 = 色板里 8 列 × 2 行(v1.19)。
排布刻意成对:第一行是 8 个饱和亮色(红橙黄绿青蓝紫粉),
/* 15 个常用色 + 第一格「去色」= 色板里 8 列 × 2 行(v1.20)。
排布刻意成对:第一行是 7 个饱和亮色(红橙黄绿青蓝粉)+ 去色打头,
第二行是 4 个中性色(白/浅灰/中灰/黑)+ 4 个同色系「深一档」,
深红/深绿/深蓝/深紫 在浅色底图上比亮色稳,做描边不刺眼。 */
深红/深绿/深蓝/深紫 在浅色底图上比亮色稳,做描边不刺眼。
亮紫 #aa44ff 让位给第一格的「去色」(v1.20,用户 2026-11-10:去色放常用色第一个)——
紫色还留着深一档的 #6b4fbb,色相不缺,8×2 的网格也不用改成 3 行。 */
const COMMON_COLORS = [
'#ff4444', '#ff8a00', '#ffd400', '#4cd964', '#00bfa5', '#4488ff', '#aa44ff', '#ff66aa',
'#ff4444', '#ff8a00', '#ffd400', '#4cd964', '#00bfa5', '#4488ff', '#ff66aa',
'#ffffff', '#d0d0d0', '#808080', '#000000', '#c0392b', '#0f9d58', '#1677ff', '#6b4fbb'
]
/** 色板面板(v1.19 起只有工具栏弹层一份,右栏常驻面板已删)
*
* 头部一行:调哪个槽(描边/填充/底色)│ 吸管 + 色值 │ 去色 │ 图钉
* 头部一行:调哪个槽(描边/填充/底色)│ 吸管 + 色值 │ 图钉
* 把「吸管 + 色值」提到头部,是为了让下面整块高度都留给色块:
* 常用色 2 排 + 最近色 2 排,一屏就能点到,不用滚动、也不用二次点开。
*
* v1.20(用户 2026-11-10):头部不再随上下文增减控件。
* 原因是文字工具会多出「底色」tab,头部一行本来就贴着 440 的极限,
* 再去掉/加上「去色」就会把色值框和吸管挤变形(甚至整颗按钮被 flex 抵没)。
* 现在「去色」下移到常用色网格的第一格 —— 位置永远固定,不可用时只是变灰 + disabled,
* 头部元素因此全是定宽,切工具时头部不再重排。
*/
function colorSurfaceHtml() {
return `
@@ -38,17 +46,15 @@ import { bindEvents } from './events.js'
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色 / 文字描边色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
<button type="button" class="iwb-color-pop-tab" data-color-slot="bg" hidden title="正在调文本框底色(垫在文字下面)"><i></i><span class="iwb-color-pop-tab-label">底色</span></button>
<span class="iwb-color-pop-bar"></span>
<button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:切到吸管工具,在画布上点一下取色"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7" spellcheck="false" autocomplete="off" title="十六进制颜色,回车生效">
<!-- 去色(v1.19,用户 2026-11-10):就是原来的「无」,挪到图钉左边并用竖线隔开。
调色时「这一项我不上色」和「钉住」都是随手要按的开关,放在同一侧最顺。
对描边 / 填充 / 底色都生效,具体含义随当前槽变(见 updateColorUI 的 title)。
外面这层 .iwb-color-pop-tools 用 margin-left:auto 把整组推到最右:
色值框因此不会被拉成一整条(见 CSS 的 max-width)。 -->
<!-- 吸管 + 色值 + 图钉(v1.20.1,用户 2026-11-10):整组右对齐。
v1.20 只把图钉推到最右,吸管和色值还紧跟 tab —— tab 数量一变
(文字工具多出「底色」),这组就左右浮一次,用户截图里就是这个现象。
现在 tab 组独占左侧、剩余空隙由它吸收,右组整体钉在右侧,切工具纹丝不动。
右组前面那条竖线删掉了:空隙已经把「选槽」和「取色」分开,
右对齐后它只会孤零零悬在空白里。留下的那条竖线是分隔「图钉」这个常驻开关。 -->
<span class="iwb-color-pop-tools">
<span class="iwb-color-pop-bar"></span>
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="去色:当前这一项不上色(描边/填充/底色按上下文透明)"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="m5.6 5.6 12.8 12.8"/></svg>去色</button>
<button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:切到吸管工具,在画布上点一下取色"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7" spellcheck="false" autocomplete="off" title="十六进制颜色,回车生效">
<span class="iwb-color-pop-bar"></span>
<!-- 钉住(v1.18,用户 2026-11-10):调色常常要连着改好几处,每次点开色板太碎。
钉住后点画布 / 点别处都不收起,只有再点一次图钉、按 Esc、或点吸管才收。
@@ -69,6 +75,11 @@ import { bindEvents } from './events.js'
<div class="iwb-color-group">
<span class="iwb-color-group-label">常用色</span>
<div class="iwb-editor-color-swatches">
<!-- 去色(v1.20,用户 2026-11-10):原来是头部一颗带文字的按钮,现在占常用色第一格。
好处有二:① 位置永远固定,切到文字/箭头这类「去不掉色」的上下文只是变灰,
不会整颗消失;② 头部腾出一颗按钮的宽度,文字工具多出「底色」tab 也挤不坏色值框。
含义随当前槽变(无描边 / 无填充 / 无底色),title 在 updateColorUI 里刷。 -->
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="去色:当前这一项不上色(描边/填充/底色按上下文透明)"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="m5.6 5.6 12.8 12.8"/></svg></button>
${COMMON_COLORS.map(c => `<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="${c}"></button>`).join('')}
</div>
</div>
+18 -11
View File
@@ -1055,21 +1055,28 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
// 描边格:文字的「描边」是第二格(上面已处理),文字色/单槽上下文不允许「无」
if (!isFill && !isBg) tab.classList.toggle('is-none', !isText && sl.strokeOn === false)
})
// 「去色」(v1.19 前叫「无」):形状/钢笔 = 无描边或无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
// (文字色与箭头单槽没有「去色」—— 去掉就等于把对象删了,不该给这个按钮)
// 按集合刷(原来是右栏 + 弹层各一个,现在只剩弹层一个,写法保持不变以免将来再加面板时漏刷)
// 「去色」:形状/钢笔 = 无描边或无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
// v1.20(用户 2026-11-10):它现在是常用色网格的第一格,**永远显示**。
// 文字色 / 箭头这类「去掉就等于删掉对象」的上下文,改成置灰 + disabled,而不是整颗消失 ——
// 消失会让色板每切一次工具就重排一次,位置记不住。
const onBg = S.colorTarget === 'bg' && isText
const onFill = S.colorTarget === 'fill' && second
const onStroke = S.colorTarget === 'stroke' && !isText && strokeSlotCanBeNone()
const showNone = onBg || onFill || onStroke
const noneUsable = onBg || onFill || onStroke
runtime.el.querySelectorAll('[data-color-none]').forEach(noneBtn => {
noneBtn.hidden = !showNone
noneBtn.classList.toggle('active', showNone && (onBg ? !sl.bgOn : (onFill ? !sl.fillOn : !sl.strokeOn)))
noneBtn.title = onBg
? '去色:文字后面完全透明(无底色)'
: (onStroke
? (sl.strokeOn === false ? '当前已是无描边;点选颜色可恢复描边' : '去色:去掉形状外框,只留内部填充')
: (isText ? '去色:把描边宽度置 0,只留文字本身' : '去色:形状内部透明,只留描边'))
noneBtn.hidden = false
noneBtn.disabled = !noneUsable
noneBtn.classList.toggle('is-disabled', !noneUsable)
noneBtn.classList.toggle('active', noneUsable && (onBg ? !sl.bgOn : (onFill ? !sl.fillOn : !sl.strokeOn)))
noneBtn.title = noneUsable
? (onBg
? '去色:文字后面完全透明(无底色)'
: (onStroke
? (sl.strokeOn === false ? '当前已是无描边;点选颜色可恢复描边' : '去色:去掉形状外框,只留内部填充')
: (isText ? '去色:把描边宽度置 0,只留文字本身' : '去色:形状内部透明,只留描边')))
: (isText && S.colorTarget === 'stroke'
? '去色不可用:文字色去掉就等于把文字删了,要隐藏文字请用「清空标注」'
: '去色不可用:这一格只有一种颜色,去掉就没有了')
})
const cur = activeColor()
+21 -17
View File
@@ -9,7 +9,7 @@
var __IWB_ANNOTATE_MANIFEST__ = {
id: 'image-annotate',
name: '标注 / 修图',
version: '1.19.0',
version: '1.20.1',
apiVersion: 1,
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
settings: {
@@ -3506,7 +3506,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
"#4cd964",
"#00bfa5",
"#4488ff",
"#aa44ff",
"#ff66aa",
"#ffffff",
"#d0d0d0",
@@ -3523,17 +3522,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色 / 文字描边色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
<button type="button" class="iwb-color-pop-tab" data-color-slot="bg" hidden title="正在调文本框底色(垫在文字下面)"><i></i><span class="iwb-color-pop-tab-label">底色</span></button>
<span class="iwb-color-pop-bar"></span>
<button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:切到吸管工具,在画布上点一下取色"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7" spellcheck="false" autocomplete="off" title="十六进制颜色,回车生效">
<!-- 去色(v1.19,用户 2026-11-10):就是原来的「无」,挪到图钉左边并用竖线隔开。
调色时「这一项我不上色」和「钉住」都是随手要按的开关,放在同一侧最顺。
对描边 / 填充 / 底色都生效,具体含义随当前槽变(见 updateColorUI 的 title)。
外面这层 .iwb-color-pop-tools 用 margin-left:auto 把整组推到最右:
色值框因此不会被拉成一整条(见 CSS 的 max-width)。 -->
<!-- 吸管 + 色值 + 图钉(v1.20.1,用户 2026-11-10):整组右对齐。
v1.20 只把图钉推到最右,吸管和色值还紧跟 tab —— tab 数量一变
(文字工具多出「底色」),这组就左右浮一次,用户截图里就是这个现象。
现在 tab 组独占左侧、剩余空隙由它吸收,右组整体钉在右侧,切工具纹丝不动。
右组前面那条竖线删掉了:空隙已经把「选槽」和「取色」分开,
右对齐后它只会孤零零悬在空白里。留下的那条竖线是分隔「图钉」这个常驻开关。 -->
<span class="iwb-color-pop-tools">
<span class="iwb-color-pop-bar"></span>
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="去色:当前这一项不上色(描边/填充/底色按上下文透明)"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="m5.6 5.6 12.8 12.8"/></svg>去色</button>
<button type="button" class="iwb-editor-color-eye" data-action="palettePick" title="吸色:切到吸管工具,在画布上点一下取色"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<input class="iwb-editor-color-hex-input" value="#ff4444" maxlength="7" spellcheck="false" autocomplete="off" title="十六进制颜色,回车生效">
<span class="iwb-color-pop-bar"></span>
<!-- 钉住(v1.18,用户 2026-11-10):调色常常要连着改好几处,每次点开色板太碎。
钉住后点画布 / 点别处都不收起,只有再点一次图钉、按 Esc、或点吸管才收。
@@ -3554,6 +3551,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
<div class="iwb-color-group">
<span class="iwb-color-group-label">常用色</span>
<div class="iwb-editor-color-swatches">
<!-- 去色(v1.20,用户 2026-11-10):原来是头部一颗带文字的按钮,现在占常用色第一格。
好处有二:① 位置永远固定,切到文字/箭头这类「去不掉色」的上下文只是变灰,
不会整颗消失;② 头部腾出一颗按钮的宽度,文字工具多出「底色」tab 也挤不坏色值框。
含义随当前槽变(无描边 / 无填充 / 无底色),title 在 updateColorUI 里刷。 -->
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="去色:当前这一项不上色(描边/填充/底色按上下文透明)"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="m5.6 5.6 12.8 12.8"/></svg></button>
${COMMON_COLORS.map((c) => `<button type="button" class="iwb-editor-color-panel-swatch" data-panel-color="${c}" style="background:${c}" title="${c}"></button>`).join("")}
</div>
</div>
@@ -5459,11 +5461,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
const onBg = S.colorTarget === "bg" && isText;
const onFill = S.colorTarget === "fill" && second;
const onStroke = S.colorTarget === "stroke" && !isText && strokeSlotCanBeNone();
const showNone = onBg || onFill || onStroke;
const noneUsable = onBg || onFill || onStroke;
runtime.el.querySelectorAll("[data-color-none]").forEach((noneBtn) => {
noneBtn.hidden = !showNone;
noneBtn.classList.toggle("active", showNone && (onBg ? !sl.bgOn : onFill ? !sl.fillOn : !sl.strokeOn));
noneBtn.title = onBg ? "去色:文字后面完全透明(无底色)" : onStroke ? sl.strokeOn === false ? "当前已是无描边;点选颜色可恢复描边" : "去色:去掉形状外框,只留内部填充" : isText ? "去色:把描边宽度置 0,只留文字本身" : "去色:形状内部透明,只留描边";
noneBtn.hidden = false;
noneBtn.disabled = !noneUsable;
noneBtn.classList.toggle("is-disabled", !noneUsable);
noneBtn.classList.toggle("active", noneUsable && (onBg ? !sl.bgOn : onFill ? !sl.fillOn : !sl.strokeOn));
noneBtn.title = noneUsable ? onBg ? "去色:文字后面完全透明(无底色)" : onStroke ? sl.strokeOn === false ? "当前已是无描边;点选颜色可恢复描边" : "去色:去掉形状外框,只留内部填充" : isText ? "去色:把描边宽度置 0,只留文字本身" : "去色:形状内部透明,只留描边" : isText && S.colorTarget === "stroke" ? "去色不可用:文字色去掉就等于把文字删了,要隐藏文字请用「清空标注」" : "去色不可用:这一格只有一种颜色,去掉就没有了";
});
const cur = activeColor();
let matchPreset = false;
@@ -8984,7 +8988,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) {
+9 -4
View File
@@ -256,6 +256,7 @@ if (!SKIP_PASTE) {
return { c: b.top + b.height / 2, l: b.left, r: b.right }
})
const sw = [...pop.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
const grid = pop.querySelector('.iwb-editor-color-swatches')
return {
w: Math.round(r(pop).width),
sameRow: items.every((it) =>
@@ -263,11 +264,14 @@ if (!SKIP_PASTE) {
common: sw.length,
cols: new Set(sw.map((b) => Math.round(r(b).left))).size,
swatch: sw.length ? Math.round(r(sw[0]).width) : 0,
// v1.20:去色占常用色第一格(20px 同尺寸、第一排最左)
noneFirst: grid.children[0] === pop.querySelector('[data-color-none]'),
cells: grid.children.length,
}
})
check('色板弹层:头部一行(吸管 / 色值 / 图钉同排)+ 常用色 16 个 8 列',
Boolean(popShape) && popShape.sameRow && popShape.common === 16 &&
popShape.cols === 8 && popShape.swatch === 20 && popShape.w === 440,
check('色板弹层:头部一行(吸管 / 色值 / 图钉同排)+ 去色占常用色第一格 + 15 色 8 列',
Boolean(popShape) && popShape.sameRow && popShape.noneFirst && popShape.cells === 16 &&
popShape.common === 15 && popShape.cols === 8 && popShape.swatch === 20 && popShape.w === 440,
JSON.stringify(popShape))
await page.keyboard.press('Escape')
await page.waitForTimeout(140)
@@ -301,7 +305,8 @@ if (!SKIP_PASTE) {
await page.waitForTimeout(250)
const noneOnStroke = await page.evaluate(() => {
const n = document.querySelector('.iwb-editor-color-pop [data-color-none]')
return Boolean(n) && !n.hidden
// v1.20:去色不再 hidden,改用 disabled 表达「这个上下文不能去色」
return Boolean(n) && Boolean(n.offsetParent) && !n.disabled
})
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
await page.waitForTimeout(300)
+89 -50
View File
@@ -140,13 +140,15 @@ check('打开编辑器默认只有「原图」1 层,且状态栏不再写「
// v1.3(用户裁定 2026-11-05):调色板从侧栏搬进工具栏弹层,侧栏只剩缩放
// v1.19(用户 2026-11-10):右栏那份常驻调色面板删掉,颜色只剩弹层一处
check('调色板只在工具栏弹层:右栏没有调色模块,SV/色相/16 个常用色都在弹层里',
check('调色板只在工具栏弹层:右栏没有调色模块,SV/色相/去色 + 15 个常用色都在弹层里',
await page.evaluate(() => {
const q = (s) => Boolean(document.querySelector(s))
return !q('.iwb-editor-left [data-color-surface]') && !q('.iwb-editor-left .iwb-editor-colors') &&
q('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]') &&
q('.iwb-editor-color-pop .iwb-color-sv') && q('.iwb-editor-color-pop .iwb-color-hue') &&
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-swatches [data-panel-color]').length === 16 &&
// v1.20:去色进网格占第一格,所以 data-panel-color 只剩 15 个(+ 去色 = 16 格)
document.querySelectorAll('.iwb-editor-color-pop .iwb-editor-color-swatches [data-panel-color]').length === 15 &&
q('.iwb-editor-color-pop .iwb-editor-color-swatches [data-color-none]') &&
q('.iwb-editor-zoom') &&
!q('.iwb-editor-brush-size') && !q('.iwb-editor-brush-num') &&
document.querySelectorAll('.iwb-editor-brush-preset').length === 0
@@ -194,10 +196,12 @@ check('色板弹层默认收起;点工具栏色点弹出、且整块在视口
return inView && !(await pop.isVisible()) ? true : 'box=' + JSON.stringify(box)
})())
// ---------- v1.18 / v1.19 色板弹层布局(用户 2026-11-10) ----------
// ---------- v1.18 / v1.19 / v1.20 色板弹层布局(用户 2026-11-10) ----------
// v1.18:「加钉住」「三项不写标题、用细横线分割」
// v1.19:「去色放钉住左边、竖线分割」「吸色与色值放在钉住那一排」「宽度再多一点,
// 颜色一排 8 个,常用色多加 4 个」「最近色放两排」
// v1.20:文字工具多出「底色」tab 时头部挤爆,把「去色」整颗抵没了 ——
// 改成去色占常用色第一格(永远在,不可用只置灰),头部元素全部定宽。
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() // 用选择工具点画布,不落像素
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
await page.waitForTimeout(140)
@@ -205,48 +209,51 @@ const popLayout = await page.evaluate(() => {
const pop = document.querySelector('.iwb-editor-color-pop')
const r = (el) => el.getBoundingClientRect()
const none = pop.querySelector('[data-color-none]')
// 空画布(没选中对象)时「去色」是隐藏的(只有可去色的上下文才给这个按钮),
// 这里临时显出来量几何,量完还原 —— 否则 rect 全是 0,位置断言恒假。
const noneWasHidden = none.hidden
if (noneWasHidden) none.hidden = false
const grid = pop.querySelector('.iwb-editor-color-swatches')
const picker = r(pop.querySelector('.iwb-color-pop-picker'))
const side = r(pop.querySelector('.iwb-color-pop-side'))
const head = r(pop.querySelector('.iwb-color-pop-head'))
const headEl = pop.querySelector('.iwb-color-pop-head')
const head = r(headEl)
const eye = pop.querySelector('[data-action="palettePick"]')
const hex = pop.querySelector('.iwb-editor-color-hex-input')
const pin = pop.querySelector('[data-action="pinColorPop"]')
// 头部一行:吸管 / 色值 / 去色 / 图钉 的竖直中心都必须落在头部这条线上
const sw = [...pop.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
// 去色现在是常用色网格的第一格:位置固定、尺寸和其它色块一致
const noneFirstCell = grid.children[0] === none
const noneSameSize = Math.abs(r(none).width - r(sw[0]).width) < 1 &&
Math.abs(r(none).height - r(sw[0]).height) < 1
const noneRow1 = Math.round(r(none).top) === Math.round(r(sw[0]).top) &&
Math.round(r(none).left) < Math.round(r(sw[0]).left)
// 头部一行:吸管 / 色值 / 图钉 的竖直中心都必须落在头部这条线上
const cy = (el) => r(el).top + r(el).height / 2
const headOneRow = [eye, hex, none, pin].every((el) =>
const headOneRow = [eye, hex, pin].every((el) =>
Math.abs(cy(el) - (head.top + head.height / 2)) < 3 &&
r(el).left >= head.left - 1 && r(el).right <= head.right + 1)
const bars = [...pop.querySelectorAll('.iwb-color-pop-bar')].map(r)
const noneLeftOfPin = r(none).right <= r(pin).left
const barBetweenNonePin = bars.some((b) =>
b.left >= r(none).right - 1 && b.right <= r(pin).left + 1 && b.height > 8)
// 文字工具会多出「底色」tab(三格同显):临时显出来验头部不横扫溢出,
// 否则「吸管 + 色值 + 去色 + 图钉」在窄面板里会把图钉挤出弹层。
// 定宽/不浮动验收(v1.20.1):文字工具会多出「底色」tab,
// 吸管 + 色值 + 图钉这一组**不能跟着 tab 左右浮** —— 用户明确要求「他不浮动」。
// 所以量「两 tab / 三 tab」两种上下文下的左边界签名,必须逐像素一致;
// 同时图钉右边缘要贴住头部右边界(整组右对齐的证据)。
const sig = () => [Math.round(r(eye).left), Math.round(r(hex).left),
Math.round(r(pin).left), Math.round(r(pin).right)].join(',')
const sig2 = sig()
const bgTab = pop.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]')
const bgWasHidden = bgTab.hidden
const headEl = pop.querySelector('.iwb-color-pop-head')
if (bgWasHidden) bgTab.hidden = false
const sig3 = sig()
const rightPinned = Math.abs(r(pin).right - head.right) < 1.5
// 注意用元素本身读 scrollWidth/clientWidth —— DOMRect 上没有这两个属性,写 head.scrollWidth
// 会拿到 undefined,比较恒为 false(本次就是这样白跑了两轮)
const headFitsThreeTabs = headEl.scrollWidth <= headEl.clientWidth + 1 &&
[none, pin].every((el) => r(el).right <= head.right + 1)
const headThreeTabsWidth = headEl.scrollWidth
const headFitsThreeTabs = headEl.scrollWidth <= headEl.clientWidth + 1 && r(pin).right <= head.right + 1
const headDbg = {
client: pop.querySelector('.iwb-color-pop-head').clientWidth,
scroll: pop.querySelector('.iwb-color-pop-head').scrollWidth,
client: headEl.clientWidth, scroll: headEl.scrollWidth,
tabs: [...pop.querySelectorAll('.iwb-color-pop-tab')].map((t) => Math.round(r(t).width)),
hex: Math.round(r(hex).width),
popW: Math.round(r(pop).width),
headRight: Math.round(head.right), noneR: Math.round(r(none).right), pinR: Math.round(r(pin).right),
hex: Math.round(r(hex).width), hexLeft: Math.round(r(hex).left),
popW: Math.round(r(pop).width), headRight: Math.round(head.right),
sig2, sig3,
}
if (bgWasHidden) bgTab.hidden = true
const sw = [...pop.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')]
const row1 = sw.slice(0, 8).map((b) => Math.round(r(b).top))
const row2 = sw.slice(8).map((b) => Math.round(r(b).top))
const row1 = sw.slice(0, 7).map((b) => Math.round(r(b).top))
const row2 = sw.slice(7).map((b) => Math.round(r(b).top))
// 「最近」没有历史色时整组(含外层 group)都是 hidden,量不出网格;
// 这里临时铺满 16 个量完再还原 —— 只解 wrap 的 hidden 不够,外层还压着一层
const rec = pop.querySelector('.iwb-editor-recent-colors')
@@ -272,28 +279,32 @@ const popLayout = await page.evaluate(() => {
h: Math.round(r(pop).height),
headOneRow,
headRows: [head.top, head.bottom, head.left, head.right].map(Math.round),
items: [eye, hex, none, pin].map((el) => [r(el).top, r(el).bottom, r(el).left, r(el).right].map(Math.round)),
items: [eye, hex, pin].map((el) => [r(el).top, r(el).bottom, r(el).left, r(el).right].map(Math.round)),
sideInRight: Math.round(side.left) >= Math.round(picker.right),
noneLeftOfPin,
barBetweenNonePin,
headFitsThreeTabs, headThreeTabsWidth, headDbg,
noneFirstCell, noneSameSize, noneRow1,
headFitsThreeTabs, headFixed: sig2 === sig3, rightPinned,
hexW: Math.round(r(hex).width), headDbg,
common: sw.length,
twoRows: row1.length === 8 && row2.length === 8 &&
new Set(row1).size === 1 && new Set(row2).size === 1 && row1[0] < row2[0],
// 8 列 × 2 行:13 个常用色 + 第一格去色 = 16 格,两排各 8
twoRows: row1.length === 7 && row2.length === 8 &&
new Set(row1).size === 1 && new Set(row2).size === 1 && row1[0] < row2[0] &&
grid.children.length === 16,
cols: new Set(sw.map((b) => Math.round(r(b).left))).size,
recRows, recCols,
dividers: [...pop.querySelectorAll('.iwb-color-pop-side > * + *')].map((g) => getComputedStyle(g).borderTopWidth),
labelsVisible: [...pop.querySelectorAll('.iwb-color-group-label')].filter((l) => l.offsetParent !== null).length,
swatch: Math.round(r(sw[0]).width),
}
if (noneWasHidden) none.hidden = true
return out
})
check('色板头部一行装完:吸管 + 色值 + 去色 + 图钉同一排,「去色」在图钉左边且有竖线隔开',
popLayout.headOneRow && popLayout.noneLeftOfPin && popLayout.barBetweenNonePin && popLayout.headFitsThreeTabs,
JSON.stringify(popLayout))
check('常用色 8 列 × 2 行(16 个),最近色也是 8 列两排,块间 1px 细线且无小标题',
popLayout.common === 16 && popLayout.twoRows && popLayout.cols === 8 &&
check('色板头部:吸管 + 色值 + 图钉整组右对齐,加「底色」tab 后逐像素不浮动',
popLayout.headOneRow && popLayout.headFitsThreeTabs && popLayout.headFixed && popLayout.rightPinned,
JSON.stringify(popLayout.headDbg) + ' rightPinned=' + popLayout.rightPinned)
check('「去色」是常用色的第一格(20px 同尺寸、第一排最左),不再挂在头部',
popLayout.noneFirstCell && popLayout.noneSameSize && popLayout.noneRow1,
JSON.stringify({ first: popLayout.noneFirstCell, size: popLayout.noneSameSize, row: popLayout.noneRow1, sw: popLayout.swatch }))
check('常用色 8 列 × 2 行(去色 + 15 色 = 16 格),最近色也是 8 列两排,块间 1px 细线且无小标题',
popLayout.common === 15 && popLayout.twoRows && popLayout.cols === 8 &&
popLayout.recCols === 8 && popLayout.recRows === 2 &&
popLayout.labelsVisible === 0 && popLayout.dividers.every((d) => d === '1px'),
JSON.stringify(popLayout))
@@ -2135,12 +2146,35 @@ const popTextTarget = await page.evaluate(() => {
fillActive: tab.classList.contains('active'),
fillLabel: tab.querySelector('.iwb-color-pop-tab-label').textContent,
bgVisible: !bgTab.hidden,
noneVisible: !pop.querySelector('[data-color-none]').hidden
// v1.20:去色不再 hidden,改成「在不在 + 能不能用」
noneVisible: !!pop.querySelector('[data-color-none]').offsetParent,
noneUsable: !pop.querySelector('[data-color-none]').disabled
}
})
check('点文字的「描边」格:色板目标是描边(tab 写「描边」),底色 tab 同时可选',
check('点文字的「描边」格:色板目标是描边(tab 写「描边」),底色 tab 同时可选,去色可用',
popTextTarget.open && popTextTarget.fillActive && popTextTarget.fillLabel === '描边' &&
popTextTarget.bgVisible && popTextTarget.noneVisible, JSON.stringify(popTextTarget))
popTextTarget.bgVisible && popTextTarget.noneVisible && popTextTarget.noneUsable,
JSON.stringify(popTextTarget))
// v1.20(用户 2026-11-10 截图):文字色这一格去不掉色,但按钮必须**留在原位变灰**,
// 不能整颗消失 —— 消失会让色板每切一次工具就重排,位置记不住。
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
await page.waitForTimeout(200)
const noneDisabledOnTextColor = await page.evaluate(() => {
const n = document.querySelector('.iwb-editor-color-pop [data-color-none]')
return {
visible: !!n.offsetParent, disabled: n.disabled, dim: Number(getComputedStyle(n).opacity),
title: n.title, bgTabStillHidden: document.querySelector('.iwb-color-pop-tab[data-color-slot="bg"]').hidden
}
})
check('文字色上下文:去色仍在第一格、只是置灰 disabled(说明原因),不整颗消失',
noneDisabledOnTextColor.visible && noneDisabledOnTextColor.disabled &&
noneDisabledOnTextColor.dim < 0.6 && /去色不可用/.test(noneDisabledOnTextColor.title),
JSON.stringify(noneDisabledOnTextColor))
// 开发用:ANNOT_SHOT3=/tmp/pop-text.png 出「文字工具三 tab + 去色置灰」的效果图(用户截图那个场景)
if (process.env.ANNOT_SHOT3) await page.locator('.iwb-editor-color-pop').screenshot({ path: process.env.ANNOT_SHOT3 })
await page.locator('.iwb-editor-color-btn[data-color-slot="fill"]').click()
await page.waitForTimeout(200)
await page.evaluate(() => {
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
@@ -2582,11 +2616,13 @@ const popTarget = await page.evaluate(() => {
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
noneVisible: !!pop.querySelector('[data-color-none]').offsetParent,
noneUsable: !pop.querySelector('[data-color-none]').disabled
}
})
check('点填充槽打开色板:目标是填充,并出现「无」按钮',
popTarget.open && popTarget.fillActive && popTarget.noneVisible, JSON.stringify(popTarget))
check('点填充槽打开色板:目标是填充,去色在第一格且可用',
popTarget.open && popTarget.fillActive && popTarget.noneVisible && popTarget.noneUsable,
JSON.stringify(popTarget))
// 用一个画布上不会出现的怪色(#a014b2)验收:12 个推荐色在前面用例里都用过,
// 拿黄色/绿色统计会数到别的图形,永远清不到 0。
@@ -2746,7 +2782,8 @@ const selectedShapeState = () => page.evaluate(() => {
color: s && s.color, fillColor: s && s.fillColor,
strokeBtnNone: !!btn && btn.classList.contains('is-none'),
optOff: !!opt && opt.classList.contains('is-off'),
noneHidden: !none || none.hidden,
// v1.20:去色永远在,只是不可用时 disabled(灰色),所以断言的是「能不能用」不是「在不在」
noneDisabled: !none || none.disabled,
noneActive: !!none && none.classList.contains('active')
}
})
@@ -2772,7 +2809,9 @@ const magentaBefore = await magentaPerCanvas()
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
await page.waitForTimeout(220)
const noneShownOnStroke = await page.evaluate(() =>
!document.querySelector('.iwb-editor-color-pop [data-color-none]').hidden)
!document.querySelector('.iwb-editor-color-pop [data-color-none]').disabled)
// 开发用:ANNOT_SHOT4=/tmp/pop-none.png 出「去色可用态」的效果图(形状描边上下文)
if (process.env.ANNOT_SHOT4) await page.locator('.iwb-editor-color-pop').screenshot({ path: process.env.ANNOT_SHOT4 })
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
await page.waitForTimeout(320)
const noStroke = await selectedShapeState()
@@ -2849,8 +2888,8 @@ await page.waitForTimeout(280)
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
await page.waitForTimeout(220)
const openPen = await selectedShapeState()
check('未闭合钢笔不给「无描边」(去掉等于把这条线删了)',
openPen.type === 'pen' && openPen.closed === false && openPen.noneHidden === true,
check('未闭合钢笔不给「无描边」(去掉等于把这条线删了):去色留在原位但置灰',
openPen.type === 'pen' && openPen.closed === false && openPen.noneDisabled === true,
JSON.stringify(openPen))
// ---- 一边无色也能交换(用户反馈的第二个问题)----
+45 -3
View File
@@ -1,6 +1,6 @@
# 风格库(style-source)
资源库面板里的 AI 绘画风格浏览器。310 个风格、12 个分类,点到哪个风格就能把**预览图**插进画布(`ref` 节点)或把**提示词**插进画布(`prompt` 节点)。
资源库面板里的 AI 绘画风格浏览器。367 个风格、12 个分类,点到哪个风格就能把**预览图**插进画布(`ref` 节点)、把**提示词**插进画布(`prompt` 节点),或者插一个**样式节点**(带变量表单、能继续连线的插件节点)。
风格数据来自开源项目 [style-source](https://github.com/malongan/style-source),插件直连它的 GitHub Pages 静态资源,无后端、无 Key。
@@ -9,8 +9,9 @@
| 声明 | 用途 |
|---|---|
| `panels` | 注册「风格库」标签页到资源库面板 |
| `canvas` | `getNodes` / `getSelectedNode`(算插入坐标) |
| `canvasWrite` | `createImageNode`(插参考图)/ `createNode('prompt', …)`(插提示词) |
| `canvas` | `getNodes` / `getSelectedNode`(算插入坐标)/ `screenToWorld`(拖拽落点) |
| `canvasWrite` | `createImageNode`(插参考图)/ `createNode`(插提示词、插样式节点) |
| `nodeTypes` | 注册 `style` 变体(`ctx.nodes.register`,注意 key 是 `nodes` 不是 `nodeTypes`) |
## 交互
@@ -24,6 +25,47 @@
- **点击**:不传坐标(`createNode('prompt', null, null, …)`),交给宿主 `findSpot()` —— 从**视口中心**向外螺旋扫空位、跳过已有节点、并**避开压在画布上的浮层**(资源中心 / 插件面板 / 左右侧栏)。插件只有节点的 `x/y`,拿不到 pan/zoom 和实测高度,自己排必然插到看不见的地方或压在别的节点上(旧版就是「选中节点右侧固定 380,无避让」)。
- **按住拖到画布上松手**:节点落在**松手点**(`screenToWorld` 换算,节点左上角对齐光标)。落点由宿主算:pan/zoom 只有它知道。拖动中光标下跟一张幽灵卡片,进入画布会提示「松手放这里」;松手点不在画布上(还在面板里)⇒ 取消。位移不足 6px 视作点击,两条路径并存、互不干扰。落点**压住已有节点或被浮层遮住**时,宿主会就近吸附到旁边的空位(`snapToFreeSpot`,20px 间隙、优先留在视口内);落在空处则**完全按松手点**,不偏移。
## 样式节点(v1.3.0)
详情页底部有三颗按钮:**样式节点**(新)· 插入参考图 · 插入提示词。三颗都支持「点一下自动找位」和「按住拖到画布松手」,原两颗的行为一个字没改。
样式节点与「插入提示词」的区别:后者落一个纯 `prompt` 节点,文本一落地就和风格库脱钩(认不出是哪条风格、改一个词只能删了重插);样式节点把来源和结构一起带上,随画布存档。
### 节点数据契约
```js
{
variant: 'style', // 宿主降级兜底:类型没注册时仍认得出是插件节点
styleId, name, code, // 来源三件套(一张画布常有七八个样式节点,靠它分辨)
outKind: 'prompt', // 关键标记:连线规则里等同提示词节点
promptTpl, // 原始模板(库里模板以后更新,也不会偷偷改老画布)
varMeta: [{ n, l, d, x }], // 变量名 / 中文标签 / 填写说明 / 是否在数据里声明过
vars: {}, // 用户填的值
text: '', // 派生值,恒等于 fillTpl(promptTpl, vars)
preview, refName, // 缩略图 URL(不存 base64)
refOn, refUrl, // 示例图作参考
collapsed: false, // 变量区收起
}
```
### 五条硬约束(改之前先读)
1. **节点上没有生成按钮。** 注册变体时不传 `run`,宿主就不会渲染那颗按钮。出图一律交给下游生图节点(它已经处理了四家渠道差异、尺寸收敛、并发与恢复)。
2. **首行单行布局。** label 左、输入右,一行 28px。早期草稿是「label 一行 + 输入一行」= 56px/个,Vigo 那批 24 个变量就是 1344px,画布上没法看。变量**全部露出**(不折叠),靠「收起」按钮收起来。
3. **`vars` 与 `text` 必须在同一次 `onUpdate` 里写回**,且输入走 300ms 防抖 + 失焦立刻提交。分开写会出现「界面填了新词、生图拿的旧词」;不防抖则每敲一个字符就让整张图的 `graphCacheKey` 失效、撤销历史炸掉。
4. **端口只出不入**(`ports: { in: false, out: true }`)。宿主任务图对未知类型走兜底分支 `children.length ? children : [自己]`——一旦有人连一条边进来,它自己渲染的提示词就会被上游文本顶掉,用户填的变量全部失效。
5. **节点体是「往 host 里画」,不是返回 vDOM。** 宿主给的 `host` 跨渲染稳定(`app.js` 的 `PluginDomBody`),插件必须做「建一次骨架 + 之后只同步值」;每次重建 DOM 的话,输入框每敲一个字就会失焦。正在编辑的输入框(`document.activeElement`)在同步时要跳过。
### 示例图作参考
勾上以后,宿主的任务图会给这个节点补一个**伪 `ref` 节点**(`id = 节点id + ':ref'`,坐标取节点自身 x/y,所以它参与「图片按 X 轴排序」):
- 连生图节点 → 生图节点的参考图区多一张;
- 连组合节点 → 和别的图片节点一样被汇总,再一起传给下游;
- 连分层节点 → `nodeRefsOf` 也会把它带出来。
只存 URL 不转 base64:宿主的 `refArgsOf` 对字符串直接产出 `{ type: 'url' }`,而 URL 参考图本来就是既有的正常路径(`createGenerationJobs` 的注释写着「URL 参考图也定义在 generations 的 image 字段中」)。代价是依赖 CDN 可用性。取消勾选只写 `refOn: false`,**不增删任何节点**,所以不会在画布上留孤儿。
## 变量:只有提示词里的 `{占位符}` 才算数
**判断依据只有一条**:`prompt` 里真实出现的 `{名字}`。插入时替换的就是这段文本,所以
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/style-source",
"private": true,
"version": "1.2.0",
"version": "1.3.0",
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
"ibwPlugin": {
"id": "style-source",
+324 -4
View File
@@ -288,6 +288,58 @@
opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
.iwb-ss-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
/* ─────────── 样式节点(画布内的节点体,v1.3.0 / 2026-11-14)───────────
宿主把这一块交给插件自己画(.iwb-plugin-node-body 不含内边距),所以这里的 padding 是唯一的内边距。
宽度以宿主节点默认宽 264 为基准:264 − 24(padding) = 240 内容宽。 */
.iwb-ssn { display: flex; flex-direction: column; gap: 9px; padding: 10px 12px; color: var(--iwb-text, #1f2430); font-size: 12px; box-sizing: border-box; }
.iwb-ssn-top { display: flex; align-items: flex-start; gap: 9px; }
.iwb-ssn-thumb {
width: 56px; height: 56px; flex: 0 0 auto; border-radius: 7px; object-fit: cover;
background: var(--iwb-layer, #f0f1f4); border: 1px solid var(--iwb-border, #d5d9e0);
}
.iwb-ssn-thumb.is-empty { display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--iwb-text2, #6b7280); }
.iwb-ssn-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.iwb-ssn-name { font-size: 12.5px; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iwb-ssn-code { font-size: 10.5px; color: var(--iwb-text2, #6b7280); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: .02em; }
/* 参考图开关:整行可点(不要求精准点那个小方框 —— 节点在画布上常被缩放) */
.iwb-ssn-ref {
display: flex; align-items: center; gap: 6px; margin-top: 1px; padding: 3px 6px; border-radius: 6px;
background: var(--iwb-layer, #f0f1f4); cursor: pointer; user-select: none;
font-size: 11px; color: var(--iwb-text2, #4d5668);
}
.iwb-ssn-ref input { margin: 0; flex: 0 0 auto; cursor: pointer; }
.iwb-ssn-ref > span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iwb-ssn-ref > em { flex: 0 0 auto; font-style: normal; opacity: .75; font-size: 10px; }
.iwb-ssn-ref.is-on { background: color-mix(in srgb, var(--iwb-brand, #1677ff) 14%, transparent); color: var(--iwb-brand, #1677ff); }
.iwb-ssn-ref.is-off { opacity: .72; }
.iwb-ssn-toggle {
flex: 0 0 auto; width: 22px; height: 22px; padding: 0; margin: 0; border: 0; border-radius: 6px;
background: transparent; color: var(--iwb-text2, #6b7280); cursor: pointer; line-height: 1;
display: inline-flex; align-items: center; justify-content: center; font-size: 13px;
}
.iwb-ssn-toggle:hover { background: var(--iwb-layer, #f0f1f4); color: var(--iwb-text, #1f2430); }
/* 变量行:label 左、输入右,一行 28px。
早期草稿是「label 一行 + 输入一行」= 56px/个,Vigo 那批 24 个变量就是 1344px —— 画布上没法看。
单行布局把同样的信息压到 32px/行(含 gap),不删任何字段。 */
.iwb-ssn-vars { display: flex; flex-direction: column; gap: 4px; }
.iwb-ssn-vars.is-hidden { display: none; }
.iwb-ssn-row { display: flex; align-items: center; gap: 8px; height: 28px; }
.iwb-ssn-row > label {
flex: 0 0 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
font-size: 11.5px; color: var(--iwb-text2, #4d5668);
}
.iwb-ssn-row > label.is-implicit { opacity: .68; }
.iwb-ssn-row > input {
flex: 1 1 auto; min-width: 0; height: 26px; padding: 0 7px; box-sizing: border-box;
border-radius: 6px; border: 1px solid var(--iwb-border, #d5d9e0);
background: var(--iwb-bg, #fff); color: inherit; font: inherit; font-size: 11.5px;
}
.iwb-ssn-row > input:focus { outline: none; border-color: var(--iwb-brand, #1677ff); }
.iwb-ssn-row > input::placeholder { color: var(--iwb-text2, #6b7280); opacity: .6; }
.iwb-ssn-foot { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--iwb-text2, #6b7280); }
.iwb-ssn-warn { color: #d97706; }
.iwb-ssn-empty { padding: 6px 2px; font-size: 11px; color: var(--iwb-text2, #6b7280); line-height: 1.6; }
`
function ensureStyle() {
@@ -528,6 +580,217 @@
return prefAll().thumbOnly === true
}
// ---------------- 样式节点(模块级:注册时就要拿到 render,不能藏在 mount 里)----------------
// ---- 样式节点(v1.3.0 / 2026-11-14)----
//
// 和「插入提示词」的本质区别:那个落一个纯 prompt 节点,文本一落地就和风格库脱钩 ——
// 认不出是哪条风格、改一个词只能删了重插。样式节点把这些一起带上(随画布存档):
// styleId / name / code 来源三件套(一张画布上常有七八个样式节点,靠它分辨)
// promptTpl 原始模板(库里模板以后更新,也不会偷偷改掉老画布)
// varMeta / vars / text 变量结构 + 用户填的值 + 渲染结果
// outKind = 'prompt' 宿主连线白名单据此把它当提示词节点(可连 gen / combine / batch / llm / prompt)
// refOn / refUrl 示例图作参考,走 URL(宿主本来就支持 url 型参考图,不必转 base64)
//
// ⚠️ 节点上**没有生成按钮**,这是用户 2026-11-14 明确定的:样式节点只负责「把变量填进模板」,
// 出图一律交给下游生图节点(它自己已经处理了四家渠道差异、尺寸收敛、并发与恢复)。
const STYLE_NODE_TYPE = 'plugin:style-source:style'
// 节点自带模板,不能再走 varKeys(style)(那要整条 styles.json 记录)。
// 语义与 applyVars 完全一致:只替换「用户真填了的」,留空的保留 {原样}
// —— 替换成空串会把提示词结构弄丢,用户看不出漏了什么。
function fillTpl(tpl, vars) {
let text = String(tpl || '')
const v = vars || {}
for (const name of Object.keys(v)) {
const val = String(v[name] == null ? '' : v[name]).trim()
if (!val) continue
text = text.split('{' + name + '}').join(val)
}
return text
}
// 宿主契约:插件节点的 render(node, props, host) 是**往 host 这个真实 DOM 里画**,不是返回 vDOM。
// host 跨渲染稳定(宿主用固定 div 承载,见 app.js 的 PluginDomBody)—— 这正是为了不重建 DOM:
// 变量输入框一旦被重建,每敲一个字就会失焦。
// 所以这里做「建一次骨架 + 之后只同步值」。
function renderStyleNode(node, props, host) {
let st = host.__ssn
if (!st) {
host.textContent = ''
st = host.__ssn = buildStyleNodeSkeleton(host)
}
st.node = node
st.props = props
syncStyleNode(st, (node && node.data) || {})
}
function buildStyleNodeSkeleton(host) {
const thumb = el('img', { class: 'iwb-ssn-thumb', alt: '', loading: 'lazy', draggable: 'false' })
thumb.addEventListener('error', () => { thumb.style.display = 'none' })
thumb.addEventListener('load', () => { thumb.style.display = '' })
const nameEl = el('div', { class: 'iwb-ssn-name' })
const codeEl = el('div', { class: 'iwb-ssn-code' })
const refChk = el('input', { type: 'checkbox' })
const refTxt = el('span', {})
const refNum = el('em', {})
const refBox = el('label', { class: 'iwb-ssn-ref' }, [refChk, refTxt, refNum])
const toggle = el('button', { class: 'iwb-ssn-toggle', type: 'button', text: '⌃' })
const varsBox = el('div', { class: 'iwb-ssn-vars' })
const foot = el('div', { class: 'iwb-ssn-foot' })
const root = el('div', { class: 'iwb-ssn' }, [
el('div', { class: 'iwb-ssn-top' }, [
thumb,
el('div', { class: 'iwb-ssn-meta' }, [nameEl, codeEl, refBox]),
toggle,
]),
varsBox,
foot,
])
host.appendChild(root)
const st = { root: root, thumb: thumb, nameEl: nameEl, codeEl: codeEl, refBox: refBox, refChk: refChk, refTxt: refTxt, refNum: refNum, toggle: toggle, varsBox: varsBox, foot: foot, rows: {}, varSig: '', footSig: '', timer: null, draft: null, node: null, props: null }
// 收起 / 展开:写回 data.collapsed(随存档走),节点高度由宿主实测,不锁 n.h
toggle.addEventListener('pointerdown', (e) => e.stopPropagation())
toggle.addEventListener('click', (e) => {
e.stopPropagation(); e.preventDefault()
if (!st.node || !st.props) return
st.props.onUpdate(st.node.id, { collapsed: !(st.node.data && st.node.data.collapsed) })
})
// 参考图开关:只切换 refOn,不增删任何节点(所以取消勾选不会在画布上留孤儿)
refChk.addEventListener('change', () => {
if (!st.node || !st.props) return
const on = Boolean(refChk.checked)
st.props.onUpdate(st.node.id, { refOn: on })
st.refBox.classList.toggle('is-on', on)
st.refBox.classList.toggle('is-off', !on)
st.refTxt.textContent = on ? '示例图作参考' : '示例图不作参考'
st.refNum.textContent = on ? '1 张' : '0'
})
return st
}
function commitStyleVars(st) {
if (!st.draft) return
const vars = Object.assign({}, st.draft)
st.draft = null
const tpl = String((st.node.data && st.node.data.promptTpl) || '')
// vars 与 text 必须**同一次** onUpdate 写回:分开写会出现「界面填了新词、生图拿的旧词」
st.props.onUpdate(st.node.id, { vars: vars, text: fillTpl(tpl, vars) })
}
function syncStyleNode(st, d) {
const name = String(d.name || '')
const nameText = name || '(未命名风格)'
if (st.nameEl.textContent !== nameText) st.nameEl.textContent = nameText
st.nameEl.title = nameText
const codeText = String(d.code || d.styleId || '')
if (st.codeEl.textContent !== codeText) st.codeEl.textContent = codeText
st.codeEl.title = codeText
const preview = String(d.preview || '')
if (st.thumb.dataset.src !== preview) {
st.thumb.dataset.src = preview
if (preview) { st.thumb.style.display = ''; st.thumb.style.visibility = ''; st.thumb.src = preview } else {
// 没有预览图时**整块不占位**(display:none 而不是 visibility:hidden):
// 留 56px 空白会让名称和编号无缘无故右移,看起来像排版错位
st.thumb.removeAttribute('src')
st.thumb.style.display = 'none'
}
}
const hasRef = !!String(d.refUrl || '').trim()
const on = d.refOn === true && hasRef
if (st.refChk.checked !== on) st.refChk.checked = on
// 没有示例图就别让人点了还以为是开关坏了:直接禁用并说明原因
if (st.refChk.disabled !== !hasRef) st.refChk.disabled = !hasRef
st.refBox.classList.toggle('is-on', on)
st.refBox.classList.toggle('is-off', !on)
const refLabel = on ? '示例图作参考' : '示例图不作参考'
if (st.refTxt.textContent !== refLabel) st.refTxt.textContent = refLabel
const refCount = on ? '1 张' : '0'
if (st.refNum.textContent !== refCount) st.refNum.textContent = refCount
st.refBox.title = on
? '出图时会带上这张示例图(在生图节点的参考图区能看到它)'
: (hasRef ? '当前只输出提示词,不带这张图;勾上就会带上' : '这条风格没有示例图,无法作参考')
const collapsed = d.collapsed === true
st.varsBox.classList.toggle('is-hidden', collapsed)
const toggleText = collapsed ? '⌄' : '⌃'
if (st.toggle.textContent !== toggleText) st.toggle.textContent = toggleText
st.toggle.title = collapsed ? '展开变量' : '收起变量'
const meta = Array.isArray(d.varMeta) ? d.varMeta : []
const sig = meta.map((m) => m.n).join('\u0000')
if (sig !== st.varSig) {
st.varSig = sig
st.varsBox.textContent = ''
st.rows = {}
if (!meta.length) {
st.varsBox.appendChild(el('div', { class: 'iwb-ssn-empty', text: '这条风格的提示词没有变量,直接连到生图节点即可。' }))
} else {
for (const m of meta) st.varsBox.appendChild(buildVarRow(st, m))
}
}
// 值同步:正在编辑的那个输入框不覆盖(否则光标跳到末尾,等于打断输入)
const vars = d.vars || {}
for (const m of meta) {
const input = st.rows[m.n]
if (!input) continue
if (input === document.activeElement) continue
const cur = String(vars[m.n] == null ? '' : vars[m.n])
if (input.value !== cur) input.value = cur
}
const total = meta.length
const left = meta.filter((m) => !String(vars[m.n] == null ? '' : vars[m.n]).trim()).length
const footText = !total ? '无变量' : (left ? '还有 ' + left + ' 个变量没填(留空的保留 {原样})' : '变量已填完 · 连到生图节点即可出图')
const footSig = footText + '|' + (left ? 'warn' : 'ok')
if (st.footSig !== footSig) {
st.footSig = footSig
st.foot.textContent = ''
st.foot.appendChild(el('span', { class: left ? 'iwb-ssn-warn' : '', text: footText }))
}
}
function buildVarRow(st, m) {
const label = el('label', { text: String(m.l || m.n), title: String(m.l || m.n) + (m.d ? ':' + m.d : '') })
if (!m.x) label.classList.add('is-implicit') // 数据里没声明过的变量:标签就是占位符名,弱化一点
const input = el('input', {
type: 'text',
placeholder: String(m.d || ('{' + m.n + '}')),
spellcheck: 'false',
autocomplete: 'off',
title: String(m.d || ('留空则保留 {' + m.n + '}')),
})
input.value = ''
// 画布上:点输入框是「编辑」,不能顺带拖动节点
input.addEventListener('pointerdown', (e) => e.stopPropagation())
input.addEventListener('input', () => {
if (!st.draft) st.draft = Object.assign({}, (st.node && st.node.data && st.node.data.vars) || {})
st.draft[m.n] = input.value
if (st.timer) global.clearTimeout(st.timer)
// 300ms 防抖:每敲一个字符就 onUpdate,会让整张图的 graphCacheKey 失效十几次、撤销历史也炸掉
st.timer = global.setTimeout(() => { st.timer = null; commitStyleVars(st) }, 300)
})
input.addEventListener('blur', () => {
if (st.timer) { global.clearTimeout(st.timer); st.timer = null }
commitStyleVars(st)
})
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); input.blur() } })
st.rows[m.n] = input
return el('div', { class: 'iwb-ssn-row' }, [label, input])
}
// 插件卸载 / 节点体被 LOD 替换时清掉定时器(宿主会在 host 卸载时调这里)
renderStyleNode.dispose = function (host) {
const st = host && host.__ssn
if (st && st.timer) global.clearTimeout(st.timer)
if (host) host.__ssn = null
}
// ---------------- 面板实例 ----------------
// 每个 mount 容器一个实例:独立 DOM 引用 + 独立 ResizeObserver,数据走 CACHE 共享。
@@ -669,6 +932,40 @@
toast((left ? '已插入提示词(还有 ' + left + ' 个变量没填)' : '已插入提示词') + tail)
}
function insertStyleNode(style, at) {
const api = ctx.canvas
if (!api || typeof api.createNode !== 'function') { toast('当前宿主不支持插入节点(缺 canvasWrite 能力)'); return }
const vars = Object.assign({}, CACHE.vars[style.id] || {})
const thumb = thumbOf(style)
const meta = varKeys(style).map((it) => ({ n: it.name, l: it.label, d: it.desc || '', x: it.declared ? 1 : 0 }))
const data = {
variant: 'style', // 宿主的降级兜底:类型没注册时仍认得出这是插件节点
styleId: String(style.id || ''),
name: String(style.name || ''),
code: String(style.code || ''),
outKind: 'prompt', // 关键标记:让它在连线规则里等同提示词节点
promptTpl: String(style.prompt || ''),
varMeta: meta,
vars: vars,
text: fillTpl(style.prompt, vars).trim(),
preview: String(thumb || ''),
refName: String(style.code || style.id || 'style') + '.png',
// 默认勾选:风格库的示例图本来就是这条风格的视觉基准,带上出图更贴。
// 只想要文字时在节点上取消勾选即可 —— 一次点击,不产生/不残留任何节点。
refOn: Boolean(thumb),
refUrl: String(thumb || ''),
collapsed: false,
}
const dropAt = (at && Number.isFinite(at.x) && Number.isFinite(at.y)) ? { x: at.x, y: at.y } : null
const id = dropAt
? api.createNode(STYLE_NODE_TYPE, dropAt.x, dropAt.y, data)
: api.createNode(STYLE_NODE_TYPE, null, null, data)
if (!id) { toast('插入失败:样式节点类型未注册(宿主版本较旧?)'); return }
const left = meta.filter((m) => !String(vars[m.n] || '').trim()).length
toast(left ? '已插入样式节点(还有 ' + left + ' 个变量没填)' : '已插入样式节点')
}
// ---- 拖拽插入:按住按钮 → 拖到画布上松手 → 节点落在松手位置 ----
//
// 为什么要有第二套交互:点击插入只能由宿主 findSpot 猜位置(视口中心、避开已有节点与浮层),
@@ -946,23 +1243,30 @@
]))
}
const style0 = style
// 新增的第三颗(2026-11-14,用户要求「新增一个插入节点的按钮」,不动原来两颗的行为)
ui.btnStyle = el('button', {
class: 'iwb-ss-btn', text: '样式节点',
title: '插入样式节点:带缩略图、变量表单、示例图开关,连到生图节点即可出图(节点本身不带生成按钮)。也可按住拖到画布上指定位置',
onClick: () => { if (ui.justDragged) return; insertStyleNode(style0) },
})
ui.btnRef = el('button', {
class: 'iwb-ss-btn', text: '插入参考图',
title: '点击:自动找位置插入参考图;按住拖到画布上松手:放在你指定的位置',
onClick: () => { if (ui.justDragged) return; insertImage(style) },
})
const style0 = style
ui.btnPrompt = el('button', {
class: 'iwb-ss-btn is-key', text: '插入提示词',
title: '点击:自动找位置插入提示词;按住拖到画布上松手:放在你指定的位置。内容按「最大高度」截断显示,节点内可滚动,全文用气泡「放大编辑」⌘E 查看',
onClick: () => { if (ui.justDragged) return; insertPrompt(style0) },
})
attachDragInsert(ui.btnStyle, '样式节点', (at) => insertStyleNode(style0, at))
attachDragInsert(ui.btnRef, '参考图', (at) => insertImage(style0, at))
attachDragInsert(ui.btnPrompt, '提示词', (at) => insertPrompt(style0, at))
ui.detail.appendChild(head)
ui.detail.appendChild(bodyEl)
ui.detail.appendChild(el('div', { class: 'iwb-ss-dfoot' }, [ui.btnRef, ui.btnPrompt]))
ui.detail.appendChild(el('div', { class: 'iwb-ss-dfoot' }, [ui.btnStyle, ui.btnRef, ui.btnPrompt]))
}
function renderAll() {
@@ -1061,9 +1365,9 @@
global.IWBPluginHost.register({
id: 'style-source',
name: '风格库',
version: '1.2.0',
version: '1.3.0',
apiVersion: 1,
capabilities: ['panels', 'canvas', 'canvasWrite'],
capabilities: ['panels', 'canvas', 'canvasWrite', 'nodeTypes'],
settings: {
dataUrl: {
type: 'text',
@@ -1090,6 +1394,22 @@
mount: (host) => mount(host, ctx),
})
// 样式节点变体(v1.3.0)。注意能力名是 nodeTypes、但挂在 ctx 上的 key 是 `nodes`
// (plugin-host.js 的 CAPABILITY_API_KEYS:nodeTypes → 'nodes'),写成 ctx.nodeTypes 会静默失效。
// 不传 run ⇒ 节点上不会出现「运行」按钮(用户明确要求:出图交给下游生图节点)。
if (ctx.nodes && typeof ctx.nodes.register === 'function') {
ctx.nodes.register({
id: 'style',
title: '样式节点',
defaults: {},
// 只出不入:宿主任务图的兜底分支是 `children.length ? children : [自己]`,
// 一旦被连了入边,样式节点自己渲染的提示词就会被上游文本顶掉,用户填的变量全部失效。
ports: { in: false, out: true },
height: 360,
render: renderStyleNode,
})
}
return {}
})
})(typeof window !== 'undefined' ? window : globalThis)
+199 -7
View File
@@ -134,7 +134,7 @@ async function main() {
// ---- 合成宿主 ----
await page.evaluate(() => {
window.__calls = { nodes: [], images: [], panels: [], manifests: [], setups: 0 }
window.__calls = { nodes: [], images: [], panels: [], manifests: [], setups: 0, variants: [] }
window.__nodes = [
{ id: 'n_prompt', type: 'prompt', x: 100, y: 120, data: { text: '原有提示词' } },
{ id: 'n_ref', type: 'ref', x: 520, y: 120, data: { name: '参考图' } },
@@ -182,8 +182,8 @@ async function main() {
check('manifest id/version 与 package.json 一致',
manifest.id === 'style-source' && manifest.version === pkgVersion,
JSON.stringify({ id: manifest.id, manifest: manifest.version, pkg: pkgVersion }))
check('capabilities 含 panels+canvas+canvasWrite',
['panels', 'canvas', 'canvasWrite'].every((c) => manifest.caps.includes(c)), manifest.caps.join(','))
check('capabilities 含 panels+canvas+canvasWrite+nodeTypes',
['panels', 'canvas', 'canvasWrite', 'nodeTypes'].every((c) => manifest.caps.includes(c)), manifest.caps.join(','))
check('settings 暴露 dataUrl', manifest.hasDataUrl)
// ---- 建面板(窄:320) ----
@@ -193,6 +193,9 @@ async function main() {
settings: { get: (k) => (window.__manifest.settings[k] || {}).default },
storage: null,
ui: { registerPanel: (p) => { window.__calls.panels.push(p) } },
// v1.3.0:样式节点变体注册。宿主的能力名是 nodeTypes,但挂在 ctx 上的 key 是 `nodes`
//(plugin-host.js 的 CAPABILITY_API_KEYS),这里如实复刻,写错 key 插件那边会静默跳过
nodes: { register: (v) => { window.__calls.variants.push(v); return true } },
canvas: {
getNodes: () => window.__nodes,
getSelectedNode: () => window.__sel,
@@ -369,7 +372,9 @@ async function main() {
check('已填变量不再残留占位符', varResult.hasVars && !varResult.stillHasPlaceholder)
// ---- 插提示词 ----
await page.locator('#hostA .iwb-ss-dfoot .iwb-ss-btn').nth(1).click()
// v1.3.0 起 footer 有三颗(样式节点 / 插入参考图 / 插入提示词),按下标取会随顺序飘 —— 改用文案定位
const btnPromptSel = page.locator('#hostA .iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '插入提示词' })
await btnPromptSel.click()
await page.waitForTimeout(120)
const promptCall = await page.evaluate(() => window.__calls.nodes[0] || null)
check('插入提示词调用 createNode', Boolean(promptCall) && promptCall.type === 'prompt', promptCall ? 'type=' + promptCall.type : '未调用')
@@ -391,7 +396,7 @@ async function main() {
document.body.appendChild(cv)
window.__calls.nodes.length = 0
})
const btnBox = await page.locator('#hostA .iwb-ss-dfoot .iwb-ss-btn').nth(1).boundingBox()
const btnBox = await btnPromptSel.boundingBox()
const dropX = 700
const dropY = 300
await page.mouse.move(btnBox.x + btnBox.width / 2, btnBox.y + btnBox.height / 2)
@@ -429,8 +434,12 @@ async function main() {
await page.evaluate(() => { const cv = document.getElementById('fakeCanvas'); if (cv) cv.remove(); window.__calls.nodes.length = 0 })
// ---- 插参考图(blob → dataURL) ----
await page.locator('#hostA .iwb-ss-dfoot .iwb-ss-btn').first().click()
const imgCall = await poll(() => page.evaluate(() => window.__calls.images[0] || null), 8000)
// 拖拽用例松手时会设 justDragged 抑制 400ms 内的 click(防「松手回到按钮上又插一次」),
// 这里必须等过那个窗口,否则 click 被吞、偶发「未调用 createImageNode」(实测 3 次里 1 次)。
await page.waitForTimeout(460)
await page.locator('#hostA .iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '插入参考图' }).click()
// 15000 而不是 8000:这条要等一次真实 fetch(blob → FileReader → dataURL),慢机器上 8s 会偶发超时
const imgCall = await poll(() => page.evaluate(() => window.__calls.images[0] || null), 15000)
check('插入参考图调用 createImageNode', Boolean(imgCall))
check('传入的是 data: URL(宿主只认这个)', Boolean(imgCall) && /^data:image\//.test(String(imgCall.dataUrl)), imgCall ? String(imgCall.dataUrl).slice(0, 24) + '…' : '')
check('节点名带风格编号', Boolean(imgCall) && /^ST\d+_/.test(String(imgCall.name)), imgCall ? imgCall.name : '')
@@ -754,6 +763,189 @@ async function main() {
console.log('· 截图:' + shotNarrow)
console.log('· 截图:' + shotVars)
// ---- 样式节点(v1.3.0 / 2026-11-14)----
// 用户要求:样式节点只负责「把变量填进模板」,节点上不放生成按钮;能连生图 / 组合 / 批量 / 做事二次编辑。
// 插件侧这一半要验的是:变体参数、节点体结构、变量写回语义、参考图开关、以及「重渲染不重建 DOM」。
const variant = await page.evaluate(() => {
const v = (window.__calls.variants || [])[0]
if (!v) return null
return {
id: v.id, title: v.title, ports: v.ports, height: v.height,
hasRun: typeof v.run === 'function', hasRender: typeof v.render === 'function',
hasDispose: typeof v.render === 'function' && typeof v.render.dispose === 'function',
}
})
check('注册 style 变体:只出不入端口、无 run(节点上不会有生成按钮)、带 render',
Boolean(variant) && variant.id === 'style' && variant.ports && variant.ports.in === false &&
variant.ports.out === true && !variant.hasRun && variant.hasRender,
JSON.stringify(variant))
// 建一个和宿主同构的容器(宿主给的是 .iwb-node-body.iwb-plugin-node-body,内部由插件自己画)
const nodeBody = await page.evaluate(() => {
const v = (window.__calls.variants || [])[0]
if (!v || typeof v.render !== 'function') return { built: false }
const host = document.createElement('div')
host.className = 'iwb-node-body iwb-plugin-node-body'
host.id = 'ssnHost'
// 独立浮到 hostA 右侧拍留档图,避免被面板遮住(hostA 宽 980,视口 1280)
host.style.cssText = 'width:264px;background:#fff;position:fixed;left:1000px;top:20px;z-index:9999'
document.getElementById('stage').appendChild(host)
window.__ssnHost = host
window.__updates = []
window.__ssnProps = { nodes: [], edges: [], editingBody: false, setEditingBody: () => {}, onUpdate: (id, patch) => window.__updates.push({ id: id, patch: patch }) }
const node = {
id: 'n_style1', type: 'plugin:style-source:style', x: 0, y: 0, data: {
variant: 'style', styleId: 'st1', name: 'Vigo 银调夜景', code: 'VIGO-08', outKind: 'prompt',
promptTpl: 'a {角色} in {场景}, {留空变量}',
varMeta: [
{ n: '角色', l: '角色', d: '如:银发少女', x: 1 },
{ n: '场景', l: '场景', d: '', x: 1 },
{ n: '留空变量', l: '留空变量', d: '', x: 0 },
],
vars: { 角色: '银发少女' }, text: 'a 银发少女 in {场景}, {留空变量}',
preview: 'https://malongan.github.io/style-source/previews/probe.webp',
refOn: true, refUrl: 'https://example.com/s.png', refName: 'style.png', collapsed: false,
},
}
window.__ssnNode = node
v.render(node, window.__ssnProps, host)
const q = (s) => host.querySelector(s)
const rows = [...host.querySelectorAll('.iwb-ssn-row')]
return {
built: true,
name: q('.iwb-ssn-name') ? q('.iwb-ssn-name').textContent : '',
code: q('.iwb-ssn-code') ? q('.iwb-ssn-code').textContent : '',
rowCount: rows.length,
labels: rows.map((r) => r.querySelector('label').textContent),
implicit: rows.map((r) => r.querySelector('label').className),
placeholders: rows.map((r) => r.querySelector('input').placeholder),
values: rows.map((r) => r.querySelector('input').value),
refChecked: q('.iwb-ssn-ref input') ? q('.iwb-ssn-ref input').checked : null,
refText: q('.iwb-ssn-ref span') ? q('.iwb-ssn-ref span').textContent : '',
foot: q('.iwb-ssn-foot') ? q('.iwb-ssn-foot').textContent : '',
hasRunBtn: [...host.querySelectorAll('button')].some((b) => /运行|生成/.test(b.textContent)),
thumbShown: (() => { const t = q('.iwb-ssn-thumb'); return Boolean(t) && t.style.display !== 'none' && t.getBoundingClientRect().width > 20 })(),
rowH: rows.length ? Math.round(rows[0].getBoundingClientRect().height) : 0,
}
})
check('样式节点体:名称 / 编号 / 变量行齐备,变量全部露出(不折叠)',
nodeBody.built && nodeBody.name === 'Vigo 银调夜景' && nodeBody.code === 'VIGO-08' && nodeBody.rowCount === 3,
JSON.stringify(nodeBody))
check('变量行是单行布局(28px 级),不是「label 一行 + 输入一行」的 56px',
nodeBody.built && nodeBody.rowH > 20 && nodeBody.rowH <= 32, 'rowH=' + nodeBody.rowH)
check('样式节点上没有「运行 / 生成」按钮(出图交给下游生图节点)',
nodeBody.built && nodeBody.hasRunBtn === false, 'hasRunBtn=' + nodeBody.hasRunBtn)
check('未填变量用 {原样} 当 placeholder(不是空白框),已填的值回填,未声明的变量标签弱化',
nodeBody.built && nodeBody.placeholders[1] === '{场景}' && nodeBody.placeholders[2] === '{留空变量}' &&
nodeBody.values[0] === '银发少女' && nodeBody.values[1] === '' && /is-implicit/.test(nodeBody.implicit[2]),
JSON.stringify({ ph: nodeBody.placeholders, val: nodeBody.values, cls: nodeBody.implicit }))
check('缩略图占 56px 方块并显示(无预览图时整块不占位,名称不会无缘无故右移)',
nodeBody.built && nodeBody.thumbShown === true, 'thumbShown=' + nodeBody.thumbShown)
check('默认勾选「示例图作参考」,文案写明会带上这张图',
nodeBody.built && nodeBody.refChecked === true && nodeBody.refText === '示例图作参考',
JSON.stringify({ checked: nodeBody.refChecked, text: nodeBody.refText }))
// 留档:节点体实际长什么样(3 个变量 + 参考图开关 + 底栏提示)
await page.locator('#ssnHost').screenshot({ path: path.resolve(HERE, 'shot-style-node.png') }).catch(() => {})
console.log('· 截图:' + path.resolve(HERE, 'shot-style-node.png'))
const varCommit = await page.evaluate(async () => {
const host = window.__ssnHost
const inputs = [...host.querySelectorAll('.iwb-ssn-row input')]
window.__updates.length = 0
inputs[1].value = '霓虹街头'
inputs[1].dispatchEvent(new Event('input', { bubbles: true }))
const duringDebounce = window.__updates.length
await new Promise((r) => setTimeout(r, 420))
const last = window.__updates[window.__updates.length - 1]
return {
duringDebounce: duringDebounce,
count: window.__updates.length,
vars: last && last.patch.vars,
text: last && last.patch.text,
sameCall: Boolean(last && last.patch && last.patch.vars && typeof last.patch.text === 'string'),
}
})
check('变量输入 300ms 防抖后才提交(不是每敲一个字就刷一次图缓存与撤销历史)',
varCommit.duringDebounce === 0 && varCommit.count >= 1, JSON.stringify(varCommit))
check('vars 与 text 在同一次 onUpdate 写回;新值已替换、留空的仍保留 {原样}',
varCommit.sameCall && varCommit.vars['场景'] === '霓虹街头' &&
String(varCommit.text).includes('霓虹街头') && String(varCommit.text).includes('{留空变量}'),
JSON.stringify({ vars: varCommit.vars, text: varCommit.text }))
const refToggle = await page.evaluate(() => {
const host = window.__ssnHost
const chk = host.querySelector('.iwb-ssn-ref input')
window.__updates.length = 0
chk.checked = false
chk.dispatchEvent(new Event('change', { bubbles: true }))
const off = window.__updates[0]
chk.checked = true
chk.dispatchEvent(new Event('change', { bubbles: true }))
const on = window.__updates[1]
return {
offPatch: off && off.patch, onPatch: on && on.patch,
label: host.querySelector('.iwb-ssn-ref span').textContent,
tone: host.querySelector('.iwb-ssn-ref').className,
}
})
check('参考图开关只改 refOn 一个字段(不增删节点 ⇒ 取消勾选不会在画布上留孤儿)',
refToggle.offPatch && refToggle.offPatch.refOn === false && Object.keys(refToggle.offPatch).length === 1 &&
refToggle.onPatch && refToggle.onPatch.refOn === true,
JSON.stringify(refToggle))
// 关键回归:宿主 onUpdate 之后会再调一次 render。若插件每次重建 DOM,输入框就会失焦
//(表现是「敲一个字光标就跳走」)。这里直接对比渲染前后是不是同一个 input 元素,
// 并把「用户正在输入、还没提交」的值设成和数据里不同的字符串 —— 渲染后必须原样保留。
const rerender = await page.evaluate(() => {
const host = window.__ssnHost
const v = window.__calls.variants[0]
const input = host.querySelectorAll('.iwb-ssn-row input')[1]
input.focus()
input.value = '正在输入中'
const node = JSON.parse(JSON.stringify(window.__ssnNode))
node.data.vars = Object.assign({}, node.data.vars, { 场景: '霓虹街头' })
v.render(node, window.__ssnProps, host)
const after = host.querySelectorAll('.iwb-ssn-row input')[1]
return {
sameEl: input === after,
keptTyping: after.value,
rows: host.querySelectorAll('.iwb-ssn-row').length,
focusKept: document.activeElement === after,
}
})
check('二次渲染复用同一批 DOM:输入框没被重建,正在编辑的值不被 data 覆盖(不失焦不跳字)',
rerender.sameEl && rerender.rows === 3 && rerender.keptTyping === '正在输入中' && rerender.focusKept,
JSON.stringify(rerender))
const collapse = await page.evaluate(() => {
const host = window.__ssnHost
const btn = host.querySelector('.iwb-ssn-toggle')
window.__updates.length = 0
btn.click()
return { patch: window.__updates[0] && window.__updates[0].patch, text: btn.textContent }
})
check('收起变量只写回 collapsed,不动节点高度(高度由宿主实测,写 h 会把自动高度锁死)',
collapse.patch && collapse.patch.collapsed === true && !('h' in collapse.patch),
JSON.stringify(collapse))
const footBtns = await page.evaluate(() => {
const btns = [...document.querySelectorAll('#hostA .iwb-ss-dfoot .iwb-ss-btn')]
return {
texts: btns.map((b) => b.textContent),
widths: btns.map((b) => Math.round(b.getBoundingClientRect().width)),
clipped: btns.filter((b) => b.scrollWidth > b.clientWidth + 1).length,
rows: new Set(btns.map((b) => Math.round(b.getBoundingClientRect().top))).size,
}
})
check('详情页底部三颗按钮(新增「样式节点」,原「参考图 / 提示词」保持原名)单行均分',
footBtns.texts.length === 3 && footBtns.texts[0] === '样式节点' &&
footBtns.texts[1] === '插入参考图' && footBtns.texts[2] === '插入提示词' &&
footBtns.rows === 1 && footBtns.clipped === 0 &&
Math.max(...footBtns.widths) - Math.min(...footBtns.widths) <= 2,
JSON.stringify(footBtns))
await page.evaluate(() => { if (window.__ssnHost) { window.__ssnHost.remove(); window.__ssnHost = null } })
check('无页面 JS 异常', errors.length === 0, errors.slice(0, 2).join(' | '))
await finish()