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
10 changed files with 632 additions and 45 deletions

No files matched your search

+20
View File
@@ -234,6 +234,26 @@ 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:去色下移成常用色第一格 / 头部全部定宽,不再被自动布局抵掉
用户截图反馈:「如果是文本元素的时候,就会把那个去色按钮给丢掉…可以让这些颜色选项一直保持在上面,
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/image-annotate",
"private": true,
"version": "1.20.0",
"version": "1.20.1",
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
"ibwPlugin": {
"id": "image-annotate",
+7 -7
View File
@@ -1803,8 +1803,9 @@
.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-tab {
@@ -1878,12 +1879,11 @@
/* display:flex 会盖掉 [hidden] 的默认 display:none,必须显式写一条 */
.iwb-color-group[hidden] { display: none; }
/* 色值输入定宽 124(v1.20 由 150 收窄、且不再可缩):#RRGGBB 七个字符 55px 出够,
v1.19 用的是 flex:0 1 150px,文字工具多出「底色」tab 时它会自己缩到 147 ——
头部宽度就跟着上下文抖,最后把「去色」整颗挤掉(用户截图里那次)。
现在头部每个元素都定宽:只有 gap 吸收亚像素误差,切工具不再重排。 */
/* 色值输入定宽 96(v1.20.1 由 124 再收窄,用户「设置框可以小一些,现在长了」)。
#RRGGBB 七个字符在 13px 等宽下约 55px,加左右 padding 10px 仍有 30px 余量;
它现在是右组里的一颗「读数」,不该比吸管/图钉重。仍然定宽不可缩。 */
.iwb-editor-color-pop .iwb-editor-color-hex-input {
flex: 0 0 124px; width: 124px; 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 {
+8 -3
View File
@@ -46,10 +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.20.1,用户 2026-11-10):整组右对齐。
v1.20 只把图钉推到最右,吸管和色值还紧跟 tab —— tab 数量一变
(文字工具多出「底色」),这组就左右浮一次,用户截图里就是这个现象。
现在 tab 组独占左侧、剩余空隙由它吸收,右组整体钉在右侧,切工具纹丝不动。
右组前面那条竖线删掉了:空隙已经把「选槽」和「取色」分开,
右对齐后它只会孤零零悬在空白里。留下的那条竖线是分隔「图钉」这个常驻开关。 -->
<span class="iwb-color-pop-tools">
<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、或点吸管才收。
+10 -5
View File
@@ -9,7 +9,7 @@
var __IWB_ANNOTATE_MANIFEST__ = {
id: 'image-annotate',
name: '标注 / 修图',
version: '1.20.0',
version: '1.20.1',
apiVersion: 1,
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
settings: {
@@ -3522,10 +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.20.1,用户 2026-11-10):整组右对齐。
v1.20 只把图钉推到最右,吸管和色值还紧跟 tab —— tab 数量一变
(文字工具多出「底色」),这组就左右浮一次,用户截图里就是这个现象。
现在 tab 组独占左侧、剩余空隙由它吸收,右组整体钉在右侧,切工具纹丝不动。
右组前面那条竖线删掉了:空隙已经把「选槽」和「取色」分开,
右对齐后它只会孤零零悬在空白里。留下的那条竖线是分隔「图钉」这个常驻开关。 -->
<span class="iwb-color-pop-tools">
<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、或点吸管才收。
@@ -8983,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) {
+17 -14
View File
@@ -229,24 +229,27 @@ const popLayout = await page.evaluate(() => {
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)
// 定宽验收:文字工具会多出「底色」tab,头部宽度必须不变形 ——
// 色值框宽度与图钉右边缘在「两 tab / 三 tab」两种上下文下要完全一致,
// 这条就是用户截图那次 bug 的回归断言(当时去色被 flex 抵掉、色值框从 150 缩到 147)。
const hexW2 = Math.round(r(hex).width)
const pinR2 = Math.round(r(pin).right)
// 定宽/不浮动验收(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
if (bgWasHidden) bgTab.hidden = false
const hexW3 = Math.round(r(hex).width)
const pinR3 = Math.round(r(pin).right)
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 && r(pin).right <= head.right + 1
const headDbg = {
client: headEl.clientWidth, scroll: headEl.scrollWidth,
tabs: [...pop.querySelectorAll('.iwb-color-pop-tab')].map((t) => Math.round(r(t).width)),
hex: hexW3, popW: Math.round(r(pop).width),
headRight: Math.round(head.right), pinR: pinR3,
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 row1 = sw.slice(0, 7).map((b) => Math.round(r(b).top))
@@ -279,8 +282,8 @@ const popLayout = await page.evaluate(() => {
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),
noneFirstCell, noneSameSize, noneRow1,
headFitsThreeTabs, headFixed: hexW2 === hexW3 && pinR2 === pinR3,
hexW: [hexW2, hexW3], pinR: [pinR2, pinR3], headDbg,
headFitsThreeTabs, headFixed: sig2 === sig3, rightPinned,
hexW: Math.round(r(hex).width), headDbg,
common: sw.length,
// 8 列 × 2 行:13 个常用色 + 第一格去色 = 16 格,两排各 8
twoRows: row1.length === 7 && row2.length === 8 &&
@@ -294,9 +297,9 @@ const popLayout = await page.evaluate(() => {
}
return out
})
check('色板头部一行装完:吸管 + 色值 + 图钉同一排,且加「底色」tab 后色值框与图钉位置纹丝不动',
popLayout.headOneRow && popLayout.headFitsThreeTabs && popLayout.headFixed,
JSON.stringify(popLayout))
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 }))
+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()