Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dd3b0985b | ||
|
|
e015b26e0b | ||
|
|
9b09c7606f | ||
|
|
b136217e2f | ||
|
|
20118eec0b |
No files matched your search
+80
-5
@@ -1,6 +1,6 @@
|
|||||||
# 风格库(style-source)
|
# 风格库(style-source)
|
||||||
|
|
||||||
资源库面板里的 AI 绘画风格浏览器。310 个风格、12 个分类,点到哪个风格就能把**预览图**插进画布(`ref` 节点)或把**提示词**插进画布(`prompt` 节点)。
|
资源库面板里的 AI 绘画风格浏览器。367 个风格、12 个分类,点到哪个风格就能把**预览图**插进画布(`ref` 节点)、把**提示词**插进画布(`prompt` 节点),或者插一个**样式节点**(带变量表单、能继续连线的插件节点)。
|
||||||
|
|
||||||
风格数据来自开源项目 [style-source](https://github.com/malongan/style-source),插件直连它的 GitHub Pages 静态资源,无后端、无 Key。
|
风格数据来自开源项目 [style-source](https://github.com/malongan/style-source),插件直连它的 GitHub Pages 静态资源,无后端、无 Key。
|
||||||
|
|
||||||
@@ -9,8 +9,9 @@
|
|||||||
| 声明 | 用途 |
|
| 声明 | 用途 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `panels` | 注册「风格库」标签页到资源库面板 |
|
| `panels` | 注册「风格库」标签页到资源库面板 |
|
||||||
| `canvas` | `getNodes` / `getSelectedNode`(算插入坐标) |
|
| `canvas` | `getNodes` / `getSelectedNode`(算插入坐标)/ `screenToWorld`(拖拽落点) |
|
||||||
| `canvasWrite` | `createImageNode`(插参考图)/ `createNode('prompt', …)`(插提示词) |
|
| `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,无避让」)。
|
- **点击**:不传坐标(`createNode('prompt', null, null, …)`),交给宿主 `findSpot()` —— 从**视口中心**向外螺旋扫空位、跳过已有节点、并**避开压在画布上的浮层**(资源中心 / 插件面板 / 左右侧栏)。插件只有节点的 `x/y`,拿不到 pan/zoom 和实测高度,自己排必然插到看不见的地方或压在别的节点上(旧版就是「选中节点右侧固定 380,无避让」)。
|
||||||
- **按住拖到画布上松手**:节点落在**松手点**(`screenToWorld` 换算,节点左上角对齐光标)。落点由宿主算:pan/zoom 只有它知道。拖动中光标下跟一张幽灵卡片,进入画布会提示「松手放这里」;松手点不在画布上(还在面板里)⇒ 取消。位移不足 6px 视作点击,两条路径并存、互不干扰。落点**压住已有节点或被浮层遮住**时,宿主会就近吸附到旁边的空位(`snapToFreeSpot`,20px 间隙、优先留在视口内);落在空处则**完全按松手点**,不偏移。
|
- **按住拖到画布上松手**:节点落在**松手点**(`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` 里真实出现的 `{名字}`。插入时替换的就是这段文本,所以
|
**判断依据只有一条**:`prompt` 里真实出现的 `{名字}`。插入时替换的就是这段文本,所以
|
||||||
@@ -118,16 +181,28 @@
|
|||||||
|
|
||||||
数据与图片都是公网 `https://`,宿主 `_headers` 的 `img-src … https:` / `connect-src … https:` 已经放行。对比 `ai-chat`(连本机 `http://127.0.0.1:3425`)必须单独加端口。
|
数据与图片都是公网 `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
|
```bash
|
||||||
cp src/index.js /tmp/plugin-style-source.js
|
cp src/index.js /tmp/plugin-style-source.js
|
||||||
cd ../image-workbench-web
|
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`,效果一致)。
|
图标:宿主 `app.js` 的 `PLUGIN_ICONS` 可加 `'style-source': 'palette'`(不加则用面板 manifest 自带的 `palette`,效果一致)。
|
||||||
|
|
||||||
## 数据结构(上游 styles.json)
|
## 数据结构(上游 styles.json)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/style-source",
|
"name": "@iwb-plugin/style-source",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.0",
|
"version": "1.3.2",
|
||||||
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
|
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "style-source",
|
"id": "style-source",
|
||||||
|
|||||||
+349
-4
@@ -288,16 +288,76 @@
|
|||||||
opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
|
opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
|
||||||
}
|
}
|
||||||
.iwb-ss-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
|
.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() {
|
function ensureStyle() {
|
||||||
const id = 'iwb-ss-style'
|
const id = 'iwb-ss-style'
|
||||||
|
if (typeof document === 'undefined' || !document.createElement) return
|
||||||
if (document.getElementById(id)) return
|
if (document.getElementById(id)) return
|
||||||
try {
|
try {
|
||||||
;(document.head || document.documentElement).appendChild(el('style', { id: id, text: CSS }))
|
;(document.head || document.documentElement).appendChild(el('style', { id: id, text: CSS }))
|
||||||
} catch (error) { /* 样式注入失败不影响功能,只是丑一点 */ }
|
} 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(无上限),
|
// 宿主 renderPromptBody 用 autoGrow 把 textarea 高度直接设成 scrollHeight(无上限),
|
||||||
@@ -528,6 +588,228 @@
|
|||||||
return prefAll().thumbOnly === true
|
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 共享。
|
// 每个 mount 容器一个实例:独立 DOM 引用 + 独立 ResizeObserver,数据走 CACHE 共享。
|
||||||
|
|
||||||
@@ -669,6 +951,40 @@
|
|||||||
toast((left ? '已插入提示词(还有 ' + left + ' 个变量没填)' : '已插入提示词') + tail)
|
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 猜位置(视口中心、避开已有节点与浮层),
|
// 为什么要有第二套交互:点击插入只能由宿主 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', {
|
ui.btnRef = el('button', {
|
||||||
class: 'iwb-ss-btn', text: '插入参考图',
|
class: 'iwb-ss-btn', text: '插入参考图',
|
||||||
title: '点击:自动找位置插入参考图;按住拖到画布上松手:放在你指定的位置',
|
title: '点击:自动找位置插入参考图;按住拖到画布上松手:放在你指定的位置',
|
||||||
onClick: () => { if (ui.justDragged) return; insertImage(style) },
|
onClick: () => { if (ui.justDragged) return; insertImage(style) },
|
||||||
})
|
})
|
||||||
const style0 = style
|
|
||||||
ui.btnPrompt = el('button', {
|
ui.btnPrompt = el('button', {
|
||||||
class: 'iwb-ss-btn is-key', text: '插入提示词',
|
class: 'iwb-ss-btn is-key', text: '插入提示词',
|
||||||
title: '点击:自动找位置插入提示词;按住拖到画布上松手:放在你指定的位置。内容按「最大高度」截断显示,节点内可滚动,全文用气泡「放大编辑」⌘E 查看',
|
title: '点击:自动找位置插入提示词;按住拖到画布上松手:放在你指定的位置。内容按「最大高度」截断显示,节点内可滚动,全文用气泡「放大编辑」⌘E 查看',
|
||||||
onClick: () => { if (ui.justDragged) return; insertPrompt(style0) },
|
onClick: () => { if (ui.justDragged) return; insertPrompt(style0) },
|
||||||
})
|
})
|
||||||
|
attachDragInsert(ui.btnStyle, '样式节点', (at) => insertStyleNode(style0, at))
|
||||||
attachDragInsert(ui.btnRef, '参考图', (at) => insertImage(style0, at))
|
attachDragInsert(ui.btnRef, '参考图', (at) => insertImage(style0, at))
|
||||||
attachDragInsert(ui.btnPrompt, '提示词', (at) => insertPrompt(style0, at))
|
attachDragInsert(ui.btnPrompt, '提示词', (at) => insertPrompt(style0, at))
|
||||||
|
|
||||||
ui.detail.appendChild(head)
|
ui.detail.appendChild(head)
|
||||||
ui.detail.appendChild(bodyEl)
|
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() {
|
function renderAll() {
|
||||||
@@ -1061,9 +1384,9 @@
|
|||||||
global.IWBPluginHost.register({
|
global.IWBPluginHost.register({
|
||||||
id: 'style-source',
|
id: 'style-source',
|
||||||
name: '风格库',
|
name: '风格库',
|
||||||
version: '1.2.0',
|
version: '1.3.2',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['panels', 'canvas', 'canvasWrite'],
|
capabilities: ['panels', 'canvas', 'canvasWrite', 'nodeTypes'],
|
||||||
settings: {
|
settings: {
|
||||||
dataUrl: {
|
dataUrl: {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
@@ -1090,6 +1413,28 @@
|
|||||||
mount: (host) => mount(host, ctx),
|
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 {}
|
return {}
|
||||||
})
|
})
|
||||||
})(typeof window !== 'undefined' ? window : globalThis)
|
})(typeof window !== 'undefined' ? window : globalThis)
|
||||||
@@ -64,7 +64,7 @@ async function main() {
|
|||||||
|
|
||||||
await page.goto(`http://127.0.0.1:${port}/`)
|
await page.goto(`http://127.0.0.1:${port}/`)
|
||||||
await page.evaluate(() => {
|
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.__nodes = [{ id: 'n1', type: 'prompt', x: 100, y: 100, data: { text: 'x' } }]
|
||||||
window.__sel = { id: 'n1', type: 'prompt', name: 'x' }
|
window.__sel = { id: 'n1', type: 'prompt', name: 'x' }
|
||||||
window.IWBPluginHost = { register(m, s) { window.__m = m; window.__s = s } }
|
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 },
|
settings: { get: (k) => (window.__m.settings[k] || {}).default },
|
||||||
storage: null,
|
storage: null,
|
||||||
ui: { registerPanel: (p) => window.__calls.panels.push(p) },
|
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: {
|
canvas: {
|
||||||
getNodes: () => window.__nodes,
|
getNodes: () => window.__nodes,
|
||||||
getSelectedNode: () => window.__sel,
|
getSelectedNode: () => window.__sel,
|
||||||
@@ -99,7 +101,8 @@ async function main() {
|
|||||||
check('真实网络拉到数据并渲染卡片', Boolean(gotData), 'cards=' + gotData)
|
check('真实网络拉到数据并渲染卡片', Boolean(gotData), 'cards=' + gotData)
|
||||||
|
|
||||||
const status = await page.locator('#h .iwb-ss-status').innerText().catch(() => '')
|
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 () => {
|
const decoded = await poll(async () => {
|
||||||
@@ -114,12 +117,34 @@ async function main() {
|
|||||||
// 真实 webp → dataURL
|
// 真实 webp → dataURL
|
||||||
await page.locator('#h .iwb-ss-card').first().click()
|
await page.locator('#h .iwb-ss-card').first().click()
|
||||||
await page.waitForTimeout(300)
|
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)
|
const img = await poll(() => page.evaluate(() => window.__calls.images[0] || null), 30000)
|
||||||
check('真实图插入画布(createImageNode 被调用)', Boolean(img))
|
check('真实图插入画布(createImageNode 被调用)', Boolean(img))
|
||||||
check('dataURL 是真实内容而非空图', Boolean(img) && String(img.dataUrl).length > 5000,
|
check('dataURL 是真实内容而非空图', Boolean(img) && String(img.dataUrl).length > 5000,
|
||||||
img ? 'len=' + String(img.dataUrl).length + ' head=' + String(img.dataUrl).slice(0, 22) : '')
|
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('无 GitHub 资源请求失败', netFail.length === 0, netFail.slice(0, 2).join(' | '))
|
||||||
check('无页面 JS 异常', errors.length === 0, errors.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(() => {
|
await page.evaluate(() => {
|
||||||
window.__calls = { nodes: [], images: [], panels: [], manifests: [], setups: 0 }
|
window.__calls = { nodes: [], images: [], panels: [], manifests: [], setups: 0, variants: [] }
|
||||||
window.__nodes = [
|
window.__nodes = [
|
||||||
{ id: 'n_prompt', type: 'prompt', x: 100, y: 120, data: { text: '原有提示词' } },
|
{ id: 'n_prompt', type: 'prompt', x: 100, y: 120, data: { text: '原有提示词' } },
|
||||||
{ id: 'n_ref', type: 'ref', x: 520, y: 120, data: { name: '参考图' } },
|
{ id: 'n_ref', type: 'ref', x: 520, y: 120, data: { name: '参考图' } },
|
||||||
@@ -182,10 +182,22 @@ async function main() {
|
|||||||
check('manifest id/version 与 package.json 一致',
|
check('manifest id/version 与 package.json 一致',
|
||||||
manifest.id === 'style-source' && manifest.version === pkgVersion,
|
manifest.id === 'style-source' && manifest.version === pkgVersion,
|
||||||
JSON.stringify({ id: manifest.id, manifest: manifest.version, pkg: pkgVersion }))
|
JSON.stringify({ id: manifest.id, manifest: manifest.version, pkg: pkgVersion }))
|
||||||
check('capabilities 含 panels+canvas+canvasWrite',
|
check('capabilities 含 panels+canvas+canvasWrite+nodeTypes',
|
||||||
['panels', 'canvas', 'canvasWrite'].every((c) => manifest.caps.includes(c)), manifest.caps.join(','))
|
['panels', 'canvas', 'canvasWrite', 'nodeTypes'].every((c) => manifest.caps.includes(c)), manifest.caps.join(','))
|
||||||
check('settings 暴露 dataUrl', manifest.hasDataUrl)
|
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) ----
|
// ---- 建面板(窄:320) ----
|
||||||
const mounted = await page.evaluate(() => {
|
const mounted = await page.evaluate(() => {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
@@ -193,6 +205,9 @@ async function main() {
|
|||||||
settings: { get: (k) => (window.__manifest.settings[k] || {}).default },
|
settings: { get: (k) => (window.__manifest.settings[k] || {}).default },
|
||||||
storage: null,
|
storage: null,
|
||||||
ui: { registerPanel: (p) => { window.__calls.panels.push(p) } },
|
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: {
|
canvas: {
|
||||||
getNodes: () => window.__nodes,
|
getNodes: () => window.__nodes,
|
||||||
getSelectedNode: () => window.__sel,
|
getSelectedNode: () => window.__sel,
|
||||||
@@ -369,7 +384,9 @@ async function main() {
|
|||||||
check('已填变量不再残留占位符', varResult.hasVars && !varResult.stillHasPlaceholder)
|
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)
|
await page.waitForTimeout(120)
|
||||||
const promptCall = await page.evaluate(() => window.__calls.nodes[0] || null)
|
const promptCall = await page.evaluate(() => window.__calls.nodes[0] || null)
|
||||||
check('插入提示词调用 createNode', Boolean(promptCall) && promptCall.type === 'prompt', promptCall ? 'type=' + promptCall.type : '未调用')
|
check('插入提示词调用 createNode', Boolean(promptCall) && promptCall.type === 'prompt', promptCall ? 'type=' + promptCall.type : '未调用')
|
||||||
@@ -391,7 +408,7 @@ async function main() {
|
|||||||
document.body.appendChild(cv)
|
document.body.appendChild(cv)
|
||||||
window.__calls.nodes.length = 0
|
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 dropX = 700
|
||||||
const dropY = 300
|
const dropY = 300
|
||||||
await page.mouse.move(btnBox.x + btnBox.width / 2, btnBox.y + btnBox.height / 2)
|
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 })
|
await page.evaluate(() => { const cv = document.getElementById('fakeCanvas'); if (cv) cv.remove(); window.__calls.nodes.length = 0 })
|
||||||
|
|
||||||
// ---- 插参考图(blob → dataURL) ----
|
// ---- 插参考图(blob → dataURL) ----
|
||||||
await page.locator('#hostA .iwb-ss-dfoot .iwb-ss-btn').first().click()
|
// 拖拽用例松手时会设 justDragged 抑制 400ms 内的 click(防「松手回到按钮上又插一次」),
|
||||||
const imgCall = await poll(() => page.evaluate(() => window.__calls.images[0] || null), 8000)
|
// 这里必须等过那个窗口,否则 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('插入参考图调用 createImageNode', Boolean(imgCall))
|
||||||
check('传入的是 data: URL(宿主只认这个)', Boolean(imgCall) && /^data:image\//.test(String(imgCall.dataUrl)), imgCall ? String(imgCall.dataUrl).slice(0, 24) + '…' : '')
|
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 : '')
|
check('节点名带风格编号', Boolean(imgCall) && /^ST\d+_/.test(String(imgCall.name)), imgCall ? imgCall.name : '')
|
||||||
@@ -754,6 +775,189 @@ async function main() {
|
|||||||
console.log('· 截图:' + shotNarrow)
|
console.log('· 截图:' + shotNarrow)
|
||||||
console.log('· 截图:' + shotVars)
|
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(' | '))
|
check('无页面 JS 异常', errors.length === 0, errors.slice(0, 2).join(' | '))
|
||||||
|
|
||||||
await finish()
|
await finish()
|
||||||
|
|||||||
Reference in new issue
Block a user