Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dd3b0985b | ||
|
|
e015b26e0b | ||
|
|
9b09c7606f | ||
|
|
b136217e2f | ||
|
|
20118eec0b | ||
|
|
a8512ba777 |
No files matched your search
@@ -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,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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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、或点吸管才收。
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 }))
|
||||
|
||||
+80
-5
@@ -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,68 @@
|
||||
- **点击**:不传坐标(`createNode('prompt', null, null, …)`),交给宿主 `findSpot()` —— 从**视口中心**向外螺旋扫空位、跳过已有节点、并**避开压在画布上的浮层**(资源中心 / 插件面板 / 左右侧栏)。插件只有节点的 `x/y`,拿不到 pan/zoom 和实测高度,自己排必然插到看不见的地方或压在别的节点上(旧版就是「选中节点右侧固定 380,无避让」)。
|
||||
- **按住拖到画布上松手**:节点落在**松手点**(`screenToWorld` 换算,节点左上角对齐光标)。落点由宿主算:pan/zoom 只有它知道。拖动中光标下跟一张幽灵卡片,进入画布会提示「松手放这里」;松手点不在画布上(还在面板里)⇒ 取消。位移不足 6px 视作点击,两条路径并存、互不干扰。落点**压住已有节点或被浮层遮住**时,宿主会就近吸附到旁边的空位(`snapToFreeSpot`,20px 间隙、优先留在视口内);落在空处则**完全按松手点**,不偏移。
|
||||
|
||||
## 样式节点(v1.3.2)
|
||||
|
||||
详情页底部有三颗按钮:**样式节点**(新)· 插入参考图 · 插入提示词。三颗都支持「点一下自动找位」和「按住拖到画布松手」,原两颗的行为一个字没改。
|
||||
|
||||
样式节点与「插入提示词」的区别:后者落一个纯 `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, // 变量区收起
|
||||
}
|
||||
```
|
||||
|
||||
### v1.3.1(2026-11-14)CSS 改为激活时注入
|
||||
|
||||
`ensureStyle()` 原本只在 `mount()`(面板)里调用 ⇒ **没打开过「风格库」面板**时,节点体是无样式的裸 DOM,
|
||||
`<img class="iwb-ssn-thumb">` 按原图尺寸铺满整个节点(真机表现:图片"跑出来了")。
|
||||
现在 setup 注册变体前注入一次,`renderStyleNode()` 里再兜一次(幂等)。
|
||||
回归用例:`tools/e2e-test-site.mjs` 第 9 段(不开面板直接进存档画布,断言缩略图宽高 ≈56px)。
|
||||
|
||||
### v1.3.2(2026-11-14)注入点再提前到脚本执行 + 缩略图内联兜底
|
||||
|
||||
1.3.1 那一版**发布链路上只传了字节、KV 清单没换**(线上仍指 1.3.0 的 hash),所以用户看到的还是坏的那版。
|
||||
连带教训:只验证「本地/合成宿主通过」不够,发布后必须回读线上清单与字节(见宿主 `scripts/plugins-publish.sh` 末尾的验收三步)。
|
||||
|
||||
这次的改动:
|
||||
|
||||
- `ensureStyle()` 在**脚本执行时**就调一次(`CSS` 常量下面紧跟一句),不再等 setup —— 三处兜底:
|
||||
脚本执行 → setup → `renderStyleNode()`。
|
||||
- 缩略图加行内兜底(`width/height:56px`、`object-fit:cover`、`border-radius:7px`):
|
||||
样式表因为任何原因失效时,图片不会按原图尺寸把节点撑爆。样式正常时取值与 CSS 相同,零视觉差异。
|
||||
- `tools/harness.mjs` 新增闸门:宿主 stub **不调用 setup** 的情况下,`#iwb-ss-style` 必须已存在且含
|
||||
`.iwb-ssn-thumb` 规则 —— 这条会直接挡住「样式注入点又跑到 mount 里」的回退。
|
||||
|
||||
### 五条硬约束(改之前先读)
|
||||
|
||||
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` 里真实出现的 `{名字}`。插入时替换的就是这段文本,所以
|
||||
@@ -118,16 +181,28 @@
|
||||
|
||||
数据与图片都是公网 `https://`,宿主 `_headers` 的 `img-src … https:` / `connect-src … https:` 已经放行。对比 `ai-chat`(连本机 `http://127.0.0.1:3425`)必须单独加端口。
|
||||
|
||||
## 测试(三层,从快到慢)
|
||||
|
||||
| 层 | 命令 | 覆盖什么 | 依赖 |
|
||||
|---|---|---|---|
|
||||
| 合成宿主 | `node tools/harness.mjs`(88 项) | 面板交互、详情页按钮顺序与同色、节点体结构、变量写入/防抖/不失焦、收起变量、截图 | 无(自带 mock 宿主) |
|
||||
| 线上真网 | `node tools/e2e-real.mjs`(10 项) | 线上 `styles.json` 真拉的到、真 CSP、卡片渲染、样式节点入口 | 网络 |
|
||||
| 测试站端到端 | `node tools/e2e-test-site.mjs`(15 项) | **宿主新接口到底接上没有**:双击进画布 → 开资源库 → 点「样式节点」→ 节点体由插件渲染、示例图默认勾选、变量输入不失焦、多变量不裁切、收起生效 | 宿主已发测试站(`SITE=` 换地址,`HEADED=1` 看着跑) |
|
||||
|
||||
前两支只验插件自己;**第三支才验宿主**,发布宿主改动后必跑。
|
||||
|
||||
## 发布
|
||||
|
||||
`src/index.js` 是手写单文件 IIFE,不构建,直接发布:
|
||||
`src/index.js` 是手写单文件 IIFE,不构建。走宿主仓带守卫的发布脚本(会拒发「宿主工作区脏」和「HEAD 不在 origin/main」):
|
||||
|
||||
```bash
|
||||
cp src/index.js /tmp/plugin-style-source.js
|
||||
cd ../image-workbench-web
|
||||
node scripts/plugins-publish.mjs /tmp/plugin-<其余插件>.js /tmp/plugin-style-source.js --upload --version style-source=1.0.5
|
||||
scripts/plugins-publish.sh style-source /tmp/plugin-style-source.js 1.3.0
|
||||
```
|
||||
|
||||
脚本会算 SRI、生成内容寻址名 `plugin-style-source.<hash12>.js`、**合并**进 KV 清单,并把宿主仓本地的 `plugins/index.json` 一起改掉(**记得提交那一处改动**)。它顺手打的 tag `style-source@1.3.0` **不会自动推**:`git push origin style-source@1.3.0`。
|
||||
|
||||
图标:宿主 `app.js` 的 `PLUGIN_ICONS` 可加 `'style-source': 'palette'`(不加则用面板 manifest 自带的 `palette`,效果一致)。
|
||||
|
||||
## 数据结构(上游 styles.json)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/style-source",
|
||||
"private": true,
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.2",
|
||||
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
|
||||
"ibwPlugin": {
|
||||
"id": "style-source",
|
||||
|
||||
+349
-4
@@ -288,16 +288,76 @@
|
||||
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() {
|
||||
const id = 'iwb-ss-style'
|
||||
if (typeof document === 'undefined' || !document.createElement) return
|
||||
if (document.getElementById(id)) return
|
||||
try {
|
||||
;(document.head || document.documentElement).appendChild(el('style', { id: id, text: CSS }))
|
||||
} catch (error) { /* 样式注入失败不影响功能,只是丑一点 */ }
|
||||
}
|
||||
|
||||
// v1.3.2(2026-11-14,同一事故的第三次):样式在**脚本执行时**就注入,不等 setup,更不等面板 mount。
|
||||
// 1.3.0 只在 mount() 里注入 —— 从存档直接进画布(面板从不 mount)时节点体是无样式裸 DOM,
|
||||
// `<img class="iwb-ssn-thumb">` 按原图尺寸铺满节点,就是用户看到的「图片都跑出来了 / 样式坏了」。
|
||||
// 1.3.1 把注入提前到 setup,但发布链路只上传了字节、清单没换(线上仍是 1.3.0),等于没修。
|
||||
// 现在三层兜底:脚本执行(这里)→ setup → renderStyleNode。
|
||||
ensureStyle()
|
||||
|
||||
// ---------------- 长提示词:节点内滚动,不让节点越拉越长 ----------------
|
||||
//
|
||||
// 宿主 renderPromptBody 用 autoGrow 把 textarea 高度直接设成 scrollHeight(无上限),
|
||||
@@ -528,6 +588,228 @@
|
||||
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) {
|
||||
// 兜底:万一节点体先于 setup 渲染(宿主注册表现在支持「注册后立刻重画」),
|
||||
// 这一句保证样式一定在 —— 少一次注入就是「缩略图铺满节点」那种事故。
|
||||
ensureStyle()
|
||||
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 = '' })
|
||||
// 内联兜底(v1.3.2):`.iwb-ssn-thumb` 的 56px 如果因为样式表缺失/被覆盖没生效,
|
||||
// 浏览器会按图片**原始尺寸**铺开 —— 一张 1024px 的示例图足以把节点撑爆。
|
||||
// 这里用行内样式钉死尺寸:样式表正常时两者取值相同(零视觉差异),样式表失效时至少不炸。
|
||||
thumb.style.width = '56px'
|
||||
thumb.style.height = '56px'
|
||||
thumb.style.flex = '0 0 auto'
|
||||
thumb.style.objectFit = 'cover'
|
||||
thumb.style.borderRadius = '7px'
|
||||
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 +951,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 +1262,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 +1384,9 @@
|
||||
global.IWBPluginHost.register({
|
||||
id: 'style-source',
|
||||
name: '风格库',
|
||||
version: '1.2.0',
|
||||
version: '1.3.2',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'canvas', 'canvasWrite'],
|
||||
capabilities: ['panels', 'canvas', 'canvasWrite', 'nodeTypes'],
|
||||
settings: {
|
||||
dataUrl: {
|
||||
type: 'text',
|
||||
@@ -1090,6 +1413,28 @@
|
||||
mount: (host) => mount(host, ctx),
|
||||
})
|
||||
|
||||
// 样式节点变体(v1.3.0)。注意能力名是 nodeTypes、但挂在 ctx 上的 key 是 `nodes`
|
||||
// (plugin-host.js 的 CAPABILITY_API_KEYS:nodeTypes → 'nodes'),写成 ctx.nodeTypes 会静默失效。
|
||||
// 不传 run ⇒ 节点上不会出现「运行」按钮(用户明确要求:出图交给下游生图节点)。
|
||||
//
|
||||
// v1.3.1(2026-11-14,用户报障「图片都跑出来了」):CSS 原先进在 `mount()` 里 ——
|
||||
// 只有打开过「风格库」面板才会注入。但从存档打开画布时,节点体先渲染、面板根本不 mount ⇒
|
||||
// 节点里的 `<img class="iwb-ssn-thumb">` 拿不到 56px 约束,按原图尺寸铺满整个节点。
|
||||
// 现在在注册变体前就把样式注入(mount 里那次是幂等兜底)。
|
||||
ensureStyle()
|
||||
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)
|
||||
@@ -64,7 +64,7 @@ async function main() {
|
||||
|
||||
await page.goto(`http://127.0.0.1:${port}/`)
|
||||
await page.evaluate(() => {
|
||||
window.__calls = { panels: [], images: [], nodes: [] }
|
||||
window.__calls = { panels: [], images: [], nodes: [], variants: [] }
|
||||
window.__nodes = [{ id: 'n1', type: 'prompt', x: 100, y: 100, data: { text: 'x' } }]
|
||||
window.__sel = { id: 'n1', type: 'prompt', name: 'x' }
|
||||
window.IWBPluginHost = { register(m, s) { window.__m = m; window.__s = s } }
|
||||
@@ -77,6 +77,8 @@ async function main() {
|
||||
settings: { get: (k) => (window.__m.settings[k] || {}).default },
|
||||
storage: null,
|
||||
ui: { registerPanel: (p) => window.__calls.panels.push(p) },
|
||||
// v1.3.0:样式节点变体(宿主能力名 nodeTypes → ctx.nodes)
|
||||
nodes: { register: (v) => { window.__calls.variants.push(v); return true } },
|
||||
canvas: {
|
||||
getNodes: () => window.__nodes,
|
||||
getSelectedNode: () => window.__sel,
|
||||
@@ -99,7 +101,8 @@ async function main() {
|
||||
check('真实网络拉到数据并渲染卡片', Boolean(gotData), 'cards=' + gotData)
|
||||
|
||||
const status = await page.locator('#h .iwb-ss-status').innerText().catch(() => '')
|
||||
check('总数显示 310', /310/.test(status), status.replace(/\n/g, ' '))
|
||||
// 数量随上游数据增长会变(310 → 367);这里只要求「显示的是三位数总量」
|
||||
check('总数显示三位数风格条数', /\b[1-9]\d{2}\b/.test(status), status.replace(/\n/g, ' '))
|
||||
|
||||
// 真实缩略图必须真的解码出来
|
||||
const decoded = await poll(async () => {
|
||||
@@ -114,12 +117,34 @@ async function main() {
|
||||
// 真实 webp → dataURL
|
||||
await page.locator('#h .iwb-ss-card').first().click()
|
||||
await page.waitForTimeout(300)
|
||||
await page.locator('#h .iwb-ss-dfoot .iwb-ss-btn').first().click()
|
||||
await page.locator('#h .iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '插入参考图' }).click()
|
||||
const img = await poll(() => page.evaluate(() => window.__calls.images[0] || null), 30000)
|
||||
check('真实图插入画布(createImageNode 被调用)', Boolean(img))
|
||||
check('dataURL 是真实内容而非空图', Boolean(img) && String(img.dataUrl).length > 5000,
|
||||
img ? 'len=' + String(img.dataUrl).length + ' head=' + String(img.dataUrl).slice(0, 22) : '')
|
||||
|
||||
// v1.3.0:样式节点(真实数据 + 真实模板)
|
||||
const styleCall = await page.evaluate(async () => {
|
||||
const v = window.__calls.variants[0]
|
||||
const btn = [...document.querySelectorAll('#h .iwb-ss-dfoot .iwb-ss-btn')].find((b) => b.textContent === '样式节点')
|
||||
if (!btn) return { noBtn: true }
|
||||
window.__calls.nodes.length = 0
|
||||
btn.click()
|
||||
await new Promise((r) => setTimeout(r, 60))
|
||||
return { hasRender: typeof v.render === 'function', ports: v.ports, call: window.__calls.nodes[0] || null }
|
||||
})
|
||||
check('详情页有「样式节点」按钮,且变体已注册(render + 只出不入)',
|
||||
!styleCall.noBtn && styleCall.hasRender === true && styleCall.ports.in === false && styleCall.ports.out === true,
|
||||
JSON.stringify({ noBtn: styleCall.noBtn, hasRender: styleCall.hasRender, ports: styleCall.ports }))
|
||||
check('样式节点落的是 plugin:style-source:style,数据带 outKind/promptTpl/varMeta',
|
||||
Boolean(styleCall.call) && styleCall.call.t === 'plugin:style-source:style' &&
|
||||
styleCall.call.d.outKind === 'prompt' && typeof styleCall.call.d.promptTpl === 'string' &&
|
||||
Array.isArray(styleCall.call.d.varMeta),
|
||||
styleCall.call ? 't=' + styleCall.call.t + ' varMeta=' + (styleCall.call.d.varMeta || []).length : '未调用')
|
||||
check('未填变量时 text 原样保留 {占位符}(不是被替换成空串)',
|
||||
Boolean(styleCall.call) && (styleCall.call.d.varMeta.length === 0 || /\{[^{}\n]{1,40}\}/.test(String(styleCall.call.d.text))),
|
||||
styleCall.call ? 'text=' + String(styleCall.call.d.text).slice(0, 48) : '未调用')
|
||||
|
||||
check('无 GitHub 资源请求失败', netFail.length === 0, netFail.slice(0, 2).join(' | '))
|
||||
check('无页面 JS 异常', errors.length === 0, errors.slice(0, 2).join(' | '))
|
||||
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
// 真机验收:**测试站上「宿主新接口 + 本插件」端到端**跑通(harness / e2e-real 都覆盖不到的那一层)。
|
||||
//
|
||||
// 为什么单独一支:
|
||||
// - `tools/harness.mjs` 跑在合成宿主里,验不了「宿主的 PluginDomBody / 声明式参考图」是否真的接上;
|
||||
// - `tools/e2e-real.mjs` 验的是「线上真网 + 插件面板」,不去点画布、不落节点。
|
||||
// 这支脚本在**真的 test 站**里:双击进工作台 → 开资源库 → 点风格 → 点「样式节点」→ 检查节点体与输入体验。
|
||||
//
|
||||
// 用法:
|
||||
// node tools/e2e-test-site.mjs # 默认 https://test.image-workbench-web.pages.dev/
|
||||
// SITE=https://xxx.pages.dev/ node tools/e2e-test-site.mjs
|
||||
// HEADED=1 node tools/e2e-test-site.mjs # 看着它跑
|
||||
//
|
||||
// 前置:宿主已部署含「插件节点体 + 声明式参考图」的版本,且 style-source 已在 KV 清单里。
|
||||
// 全程只读:不动线上数据,浏览器用一次性 profile(跑完即弃)。
|
||||
|
||||
import { createRequire } from 'node:module'
|
||||
import path from 'node:path'
|
||||
import fs from 'node:fs'
|
||||
|
||||
const HERE = path.dirname(new URL(import.meta.url).pathname)
|
||||
let chromium = null
|
||||
for (const base of [path.resolve(HERE, '../..'), path.resolve(HERE, '../../../image-workbench-web'), process.cwd()]) {
|
||||
const pkg = path.join(base, 'package.json')
|
||||
if (!fs.existsSync(pkg)) continue
|
||||
try { chromium = createRequire(pkg)('playwright').chromium; break } catch { /* 换下一个 */ }
|
||||
}
|
||||
if (!chromium) {
|
||||
console.error('找不到 playwright:请在插件仓根目录或宿主仓(image-workbench-web)里跑')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
const SITE = process.env.SITE || 'https://test.image-workbench-web.pages.dev/'
|
||||
let failed = 0
|
||||
const check = (name, ok, detail) => {
|
||||
if (!ok) failed++
|
||||
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
|
||||
}
|
||||
const shot = (name) => page.screenshot({ path: path.join(HERE, 'shot-testsite-' + name + '.png') }).catch(() => {})
|
||||
|
||||
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy
|
||||
const browser = await chromium.launch({
|
||||
headless: process.env.HEADED !== '1',
|
||||
...(proxy ? { proxy: { server: proxy } } : {}),
|
||||
})
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
|
||||
const errors = []
|
||||
page.on('pageerror', (e) => errors.push(String(e)))
|
||||
|
||||
await page.goto(SITE, { waitUntil: 'domcontentloaded' })
|
||||
await page.waitForTimeout(1200)
|
||||
// 启停状态只落 localStorage['iwb_plugins'](真机同款键)
|
||||
await page.evaluate(() => {
|
||||
localStorage.setItem('iwb_plugins', JSON.stringify({ 'style-source': { enabled: true, settings: {}, data: {} } }))
|
||||
})
|
||||
await page.reload({ waitUntil: 'domcontentloaded' })
|
||||
await page.waitForTimeout(4000)
|
||||
|
||||
// ── 1. 宿主版本:三处新接口的特征串(压缩后函数名会变,只能查字符串) ──────────
|
||||
const host = await page.evaluate(async () => {
|
||||
const src = await (await fetch('/app.js', { cache: 'no-store' })).text()
|
||||
const ver = await (await fetch('/version.json', { cache: 'no-store' })).json().catch(() => ({}))
|
||||
return {
|
||||
pluginBody: src.includes('iwb-plugin-node-body'),
|
||||
selfRef: src.includes('style-ref.png'),
|
||||
combineTag: src.includes('iwb-combine-src-tag'),
|
||||
version: ver.version || '',
|
||||
len: src.length,
|
||||
}
|
||||
})
|
||||
check('测试站 app.js 含插件节点体 + 声明式参考图 + 组合来源标签', host.pluginBody && host.selfRef && host.combineTag,
|
||||
JSON.stringify({ version: host.version, len: host.len }))
|
||||
|
||||
// ── 2. 插件已启用并激活 ───────────────────────────────────────────────────
|
||||
const list = await page.evaluate(() => {
|
||||
const h = window.IWBPluginHost
|
||||
if (!h) return { noHost: true }
|
||||
const l = typeof h.list === 'function' ? h.list() : []
|
||||
return { list: l.map((p) => ({ id: p.id, version: p.version, enabled: p.enabled, active: p.active, error: p.error })) }
|
||||
})
|
||||
const me = (list.list || []).find((p) => p.id === 'style-source')
|
||||
check('style-source 已启用并激活', Boolean(me && me.active), JSON.stringify(me))
|
||||
|
||||
// ── 3. 进工作台(首页卡片是「双击打开」,单击只是选中) ──────────────────────
|
||||
await page.locator('.iwb-home-card').first().dblclick({ timeout: 8000 })
|
||||
await page.waitForTimeout(3000)
|
||||
const entered = await page.evaluate(() => ({ cards: document.querySelectorAll('.iwb-home-card').length }))
|
||||
check('双击首页卡片进入画布', entered.cards === 0, JSON.stringify(entered))
|
||||
|
||||
// ── 4. 资源库 → 风格库 tab(N 是宿主「开关资源库」的快捷键) ──────────────────
|
||||
await page.evaluate(() => { const a = document.activeElement; if (a && a.blur) a.blur() })
|
||||
await page.keyboard.press('n')
|
||||
await page.waitForTimeout(1200)
|
||||
const tabs = await page.evaluate(() => [...document.querySelectorAll('.iwb-res-tab')].map((b) => (b.textContent || '').trim()))
|
||||
await page.evaluate(() => {
|
||||
const hit = [...document.querySelectorAll('.iwb-res-tab')].find((b) => /风格库/.test(b.textContent || ''))
|
||||
if (hit) hit.click()
|
||||
})
|
||||
check('资源库里有「风格库」tab', tabs.includes('风格库'), JSON.stringify(tabs))
|
||||
|
||||
// 风格数据是直连 GitHub Pages 拉的,首次没缓存时快时慢 ⇒ 轮询,别写死等待
|
||||
await page.waitForFunction(() => document.querySelectorAll('.iwb-ss-card').length > 0, null, { timeout: 30000 }).catch(() => {})
|
||||
await page.waitForTimeout(300)
|
||||
const cards = await page.locator('.iwb-ss-card').count()
|
||||
check('风格库渲染出卡片', cards > 0, String(cards))
|
||||
|
||||
// ── 5. 详情页底部三颗按钮:同行、均分、「样式节点」在最左(不是替换掉原来两颗) ──
|
||||
await page.locator('.iwb-ss-card').first().click()
|
||||
await page.waitForTimeout(900)
|
||||
const footInfo = await page.evaluate(() => {
|
||||
const btns = [...document.querySelectorAll('.iwb-ss-dfoot .iwb-ss-btn')]
|
||||
return { labels: btns.map((b) => (b.textContent || '').trim()), tops: btns.map((b) => Math.round(b.getBoundingClientRect().top)) }
|
||||
})
|
||||
check('详情页底部三颗按钮同行,「样式节点」在最左',
|
||||
footInfo.labels.length === 3 && footInfo.labels[0] === '样式节点' && new Set(footInfo.tops).size <= 1,
|
||||
JSON.stringify(footInfo))
|
||||
|
||||
// ── 6. 点「样式节点」→ 节点落地,节点体由插件渲染 ─────────────────────────────
|
||||
await page.locator('.iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '样式节点' }).first().click()
|
||||
await page.waitForTimeout(1600)
|
||||
await page.keyboard.press('Escape')
|
||||
await page.waitForTimeout(400)
|
||||
await page.keyboard.press('f')
|
||||
await page.waitForTimeout(700)
|
||||
await shot('node')
|
||||
|
||||
const node1 = await page.evaluate(() => {
|
||||
const b = document.querySelector('.iwb-plugin-node-body')
|
||||
if (!b) return { bodies: 0 }
|
||||
const rows = [...b.querySelectorAll('.iwb-ssn-row')]
|
||||
return {
|
||||
bodies: document.querySelectorAll('.iwb-plugin-node-body').length,
|
||||
hasRoot: Boolean(b.querySelector('.iwb-ssn')),
|
||||
name: (b.querySelector('.iwb-ssn-name') || {}).textContent || '',
|
||||
code: (b.querySelector('.iwb-ssn-code') || {}).textContent || '',
|
||||
rows: rows.length,
|
||||
refChecked: b.querySelector('.iwb-ssn-ref input') ? b.querySelector('.iwb-ssn-ref input').checked : null,
|
||||
hasRunBtn: [...b.querySelectorAll('button')].some((x) => /运行|生成/.test(x.textContent)),
|
||||
foot: (b.querySelector('.iwb-ssn-foot') || {}).textContent || '',
|
||||
}
|
||||
})
|
||||
check('样式节点落地且节点体由插件渲染(.iwb-ssn 存在)', node1.hasRoot === true, JSON.stringify(node1).slice(0, 300))
|
||||
check('节点体有名称/编号/变量行,示例图默认勾选,且没有生成按钮',
|
||||
Boolean(node1.name) && Boolean(node1.code) && node1.refChecked === true && node1.hasRunBtn === false,
|
||||
JSON.stringify(node1).slice(0, 300))
|
||||
|
||||
// ── 7. 变量输入不失焦、值不被重渲染覆盖(PluginDomBody 固定容器生效) ─────────
|
||||
const typing = await page.evaluate(async () => {
|
||||
const b = document.querySelector('.iwb-plugin-node-body .iwb-ssn')
|
||||
const input = b && b.querySelector('.iwb-ssn-row input')
|
||||
if (!input) return { noBody: true }
|
||||
input.focus()
|
||||
input.value = '真机测试值'
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
await new Promise((r) => setTimeout(r, 700))
|
||||
const b2 = document.querySelector('.iwb-plugin-node-body .iwb-ssn')
|
||||
const input2 = b2.querySelector('.iwb-ssn-row input')
|
||||
return { sameInput: input === input2, kept: input2.value, focusKept: document.activeElement === input2 }
|
||||
})
|
||||
check('变量输入不失焦、值不被重渲染覆盖',
|
||||
typing.sameInput === true && typing.kept === '真机测试值' && typing.focusKept === true, JSON.stringify(typing))
|
||||
|
||||
// ── 8. 变量多的样式:全部露出、不裁切、单行 28px、收起/展开生效 ──────────────
|
||||
// 上一步把焦点留在了变量输入框里;宿主的快捷键在 INPUT 上直接 return ⇒ 先 blur,否则按 n 只会打出一个字母
|
||||
await page.evaluate(() => { const a = document.activeElement; if (a && a.blur) a.blur() })
|
||||
await page.keyboard.press('n')
|
||||
await page.waitForTimeout(1200)
|
||||
await page.evaluate(() => {
|
||||
const hit = [...document.querySelectorAll('.iwb-res-tab')].find((b) => /风格库/.test(b.textContent || ''))
|
||||
if (hit) hit.click()
|
||||
})
|
||||
await page.waitForFunction(() => document.querySelectorAll('.iwb-ss-card').length > 0, null, { timeout: 30000 }).catch(() => {})
|
||||
|
||||
let picked = null
|
||||
const total = await page.locator('.iwb-ss-card').count()
|
||||
for (let i = 0; i < Math.min(total, 30); i++) {
|
||||
await page.locator('.iwb-ss-card').nth(i).click()
|
||||
await page.waitForTimeout(380)
|
||||
const info = await page.evaluate(() => ({
|
||||
n: document.querySelectorAll('.iwb-ss-dbody .iwb-ss-var').length,
|
||||
title: (document.querySelector('.iwb-ss-dtitle') || {}).textContent || '',
|
||||
}))
|
||||
if (info.n >= 3) { picked = { idx: i, ...info }; break }
|
||||
}
|
||||
check('能找到一个变量 ≥3 的样式(用于压力验证)', Boolean(picked), JSON.stringify(picked))
|
||||
|
||||
if (picked) {
|
||||
await page.locator('.iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '样式节点' }).first().click()
|
||||
await page.waitForTimeout(1600)
|
||||
await page.keyboard.press('Escape')
|
||||
await page.waitForTimeout(400)
|
||||
await page.keyboard.press('f')
|
||||
await page.waitForTimeout(700)
|
||||
await shot('multivar')
|
||||
|
||||
const multi = await page.evaluate(() => {
|
||||
const all = [...document.querySelectorAll('.iwb-plugin-node-body')]
|
||||
const b = all[all.length - 1]
|
||||
if (!b) return { noBody: true }
|
||||
const rows = [...b.querySelectorAll('.iwb-ssn-row')]
|
||||
return {
|
||||
bodies: all.length,
|
||||
rows: rows.length,
|
||||
labels: rows.map((x) => ((x.querySelector('label') || {}).textContent || '')).filter(Boolean),
|
||||
rowH: rows.length ? Math.round(rows[0].getBoundingClientRect().height) : 0,
|
||||
hiddenRows: rows.filter((x) => x.getBoundingClientRect().height < 8).length,
|
||||
scrollH: b.scrollHeight,
|
||||
clientH: b.clientHeight,
|
||||
}
|
||||
})
|
||||
check('变量多的样式:所有变量行都露出、无零高行', multi.rows >= 3 && multi.hiddenRows === 0, JSON.stringify(multi).slice(0, 320))
|
||||
check('节点体没有裁切(scrollHeight ≈ clientHeight)', Math.abs(multi.scrollH - multi.clientH) <= 2,
|
||||
JSON.stringify({ s: multi.scrollH, c: multi.clientH }))
|
||||
check('变量单行高度 28px 量级', multi.rowH >= 24 && multi.rowH <= 32, String(multi.rowH))
|
||||
|
||||
const collapsed = await page.evaluate(async () => {
|
||||
const all = [...document.querySelectorAll('.iwb-plugin-node-body')]
|
||||
const b = all[all.length - 1]
|
||||
const btn = b && b.querySelector('.iwb-ssn-toggle')
|
||||
if (!btn) return { noBtn: true }
|
||||
const before = Math.round(b.querySelector('.iwb-ssn-vars').getBoundingClientRect().height)
|
||||
btn.click()
|
||||
await new Promise((r) => setTimeout(r, 500))
|
||||
const box = b.querySelector('.iwb-ssn-vars')
|
||||
return { before, after: Math.round(box.getBoundingClientRect().height), hidden: box.classList.contains('is-hidden'), tip: btn.title }
|
||||
})
|
||||
check('「收起变量」生效(变量区收起,按钮变成「展开变量」)',
|
||||
collapsed.hidden === true && collapsed.after === 0 && collapsed.tip === '展开变量', JSON.stringify(collapsed))
|
||||
await shot('collapsed')
|
||||
}
|
||||
|
||||
// ── 9. 冷启动:**一次都没打开过「风格库」面板**,节点体也必须是有样式的 ──────────────
|
||||
// v1.3.1 修的事故:CSS 原先进在 mount() 里,从存档打开画布时面板不 mount ⇒ `<img class="iwb-ssn-thumb">`
|
||||
// 拿不到 56px 约束,按原图尺寸铺满整个节点(用户原话「图片都跑出来了」)。
|
||||
{
|
||||
const COLD_NODE = {
|
||||
id: 'cold1', type: 'plugin:style-source:style', x: 260, y: 200, w: 300, h: 380,
|
||||
data: {
|
||||
variant: 'style', styleId: 'cold-style', name: '冷启动样式', code: 'ST9999', outKind: 'prompt',
|
||||
promptTpl: '一张{主体}的图', varMeta: [{ key: '主体', label: '主体' }], vars: { 主体: '手表' },
|
||||
text: '一张手表的图', preview: 'https://example.invalid/cold.png', refName: 'ST9999.png',
|
||||
refOn: true, refUrl: 'https://example.invalid/cold.png', collapsed: false,
|
||||
},
|
||||
}
|
||||
const ws = { workspaces: [{ id: 'w1', name: '冷启动', nodes: [COLD_NODE], edges: [], groups: [] }], activeId: 'w1', rev: 1 }
|
||||
const ctx2 = await browser.newContext({ viewport: { width: 1400, height: 900 } })
|
||||
const p2 = await ctx2.newPage()
|
||||
await p2.addInitScript(({ ws, board }) => {
|
||||
localStorage.clear()
|
||||
localStorage.setItem('iwb_plugins', JSON.stringify({ 'style-source': { enabled: true, settings: {}, data: {} } }))
|
||||
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
|
||||
localStorage.setItem('iwb_ws_active', 'w1')
|
||||
localStorage.setItem('iwb_ws_w1', JSON.stringify(board))
|
||||
}, { ws, board: ws.workspaces[0] })
|
||||
await p2.goto(SITE, { waitUntil: 'domcontentloaded' })
|
||||
await p2.waitForTimeout(1500)
|
||||
await p2.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick().catch(() => {})
|
||||
await p2.waitForFunction(() => Boolean(document.querySelector('.iwb-plugin-node-body')), null, { timeout: 20000 }).catch(() => {})
|
||||
const cold = await p2.evaluate(() => {
|
||||
const th = document.querySelector('.iwb-ssn-thumb')
|
||||
const body = document.querySelector('.iwb-plugin-node-body')
|
||||
const node = document.querySelector('.iwb-node')
|
||||
return {
|
||||
hasBody: Boolean(body),
|
||||
hasStyle: Boolean(document.getElementById('iwb-ss-style')),
|
||||
thumbW: th ? Math.round(th.getBoundingClientRect().width) : 0,
|
||||
thumbH: th ? Math.round(th.getBoundingClientRect().height) : 0,
|
||||
nodeW: node ? Math.round(node.getBoundingClientRect().width) : 0,
|
||||
}
|
||||
})
|
||||
check('冷启动(没开过风格库):节点体成立 + 样式已注入', cold.hasBody && cold.hasStyle, JSON.stringify(cold))
|
||||
check('冷启动:缩略图被 CSS 约束在 56px(不是按原图铺满节点)',
|
||||
cold.thumbW >= 40 && cold.thumbW <= 62 && cold.thumbH >= 40 && cold.thumbH <= 62,
|
||||
JSON.stringify({ w: cold.thumbW, h: cold.thumbH, nodeW: cold.nodeW }))
|
||||
await p2.screenshot({ path: path.join(HERE, 'shot-testsite-coldstart.png') }).catch(() => {})
|
||||
await ctx2.close()
|
||||
}
|
||||
|
||||
check('全程无页面 JS 异常', errors.length === 0, errors.slice(0, 3).join(' | '))
|
||||
|
||||
await browser.close()
|
||||
console.log('')
|
||||
console.log(failed === 0 ? '全部通过' : failed + ' 项失败')
|
||||
process.exit(failed === 0 ? 0 : 1)
|
||||
@@ -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,10 +182,22 @@ 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)
|
||||
|
||||
// v1.3.2 回归闸门:样式表必须在**脚本执行时**就已注入 —— 不依赖 setup,更不依赖面板 mount。
|
||||
// 反面教材(2026-11-14,连续两次报障):1.3.0 只在 mount() 里注入,从存档直接进画布时面板
|
||||
// 从不 mount ⇒ 节点体是无样式裸 DOM,`<img class="iwb-ssn-thumb">` 按原图尺寸铺满整个节点,
|
||||
// 用户看到的就是「图片都跑出来了」「样式全坏了」。上面的宿主 stub 刻意**不调用 setup**,
|
||||
// 所以这条 check 通过 = 注入点足够早。
|
||||
const bootStyle = await page.evaluate(() => {
|
||||
const s = document.getElementById('iwb-ss-style')
|
||||
return { exists: Boolean(s), hasThumbRule: s ? s.textContent.indexOf('.iwb-ssn-thumb') >= 0 : false, len: s ? s.textContent.length : 0 }
|
||||
})
|
||||
check('样式表在脚本执行时就已注入(不开面板、不跑 setup 也在)',
|
||||
bootStyle.exists && bootStyle.hasThumbRule, JSON.stringify(bootStyle))
|
||||
|
||||
// ---- 建面板(窄:320) ----
|
||||
const mounted = await page.evaluate(() => {
|
||||
const ctx = {
|
||||
@@ -193,6 +205,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 +384,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 +408,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 +446,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 +775,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()
|
||||
|
||||
Reference in new issue
Block a user