feat(style-source): 变量全部平铺,去掉「展开其余 N 个变量」按钮 (1.0.4)

用户反馈:折叠按钮的「收起」状态容易让人以为变量就这几个,且要多点一次。

- 删掉 VAR_SHOW=6 的折叠逻辑与 .iwb-ss-vartoggle / .iwb-ss-varmore 相关代码样式
- 有多少占位符就平铺多少输入框,详情页本身可滚动(Vigo 那批最多 24 个也能撑住)
- harness:删「先给 6 个 / 折叠默认收起 / 点展开后出现」3 条,换成
  「8 个输入框全可见且无折叠按钮」;顺手修正 2 条随上游数据整改失效的样本断言
  (mondrian 8 个已全部有声明 → 改断言中英混写声明都能对上;
   婚礼那 3 个也不再是零声明 → 改断言标签可读)
This commit is contained in:
qiqi committed 2026-11-02 11:04:25 +08:00
1 parent 005c0307a6
commit 3f3bd5690b
4 files changed
+19 -51

No files matched your search

+2 -2
View File
@@ -18,7 +18,7 @@
- **分类**:chips 按面板宽度**自动换行**(宽档一行铺完,窄档折两三行,永远不会把后面的分类藏起来);按数量降序,记住上次选的分类。窄档不显示数量后缀,省一行高度。
- **网格**:分批渲染(每批 90 个),滚到底自动续渲染;缩略图原生懒加载。
- **详情**:窄面板铺满覆盖层,宽面板变右侧栏;大图 + 标签 + 摘要 + 提示词 + 变量表单。
- **变量替换**:提示词里的 `{角色描述}` 这类占位符给输入框,填了就替换,**留空的保留 `{原占位符}`**(换成空串会把提示词结构弄丢)。未填数量实时提示。输入框最多先摆 6 个,其余折在「展开其余 N 个变量」里(Vigo 那批风格单条提示词最多 24 个占位符)。
- **变量替换**:提示词里的 `{角色描述}` 这类占位符给输入框,填了就替换,**留空的保留 `{原占位符}`**(换成空串会把提示词结构弄丢)。未填数量实时提示。**变量全部平铺,不做折叠**——折叠的「收起」状态容易让人以为变量就这几个(Vigo 那批曾最多 24 个,详情页本身可滚动)。
- **插入参考图**:`fetch` 大图 → blob → dataURL → `createImageNode`(宿主只认 `data:` URL)。
- **插入提示词**:插到当前选中节点右侧;没选中时插到最右节点的右侧;空画布落 `(80, 80)`。
@@ -106,7 +106,7 @@
```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.3
node scripts/plugins-publish.mjs /tmp/plugin-<其余插件>.js /tmp/plugin-style-source.js --upload --version style-source=1.0.4
```
图标:宿主 `app.js` 的 `PLUGIN_ICONS` 可加 `'style-source': 'palette'`(不加则用面板 manifest 自带的 `palette`,效果一致)。
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/style-source",
"private": true,
"version": "1.0.3",
"version": "1.0.4",
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
"ibwPlugin": {
"id": "style-source",
+4 -21
View File
@@ -246,7 +246,6 @@
}
/* 提示词里有 {X}、但数据里没声明变量 ⇒ 标签只能用占位符名,压暗一点做区分 */
.iwb-ss-varlabel.is-implicit { opacity: .62; font-style: italic; }
.iwb-ss-vartoggle { width: 100%; height: 24px; margin: 2px 0 4px; font-size: var(--fs-sm, 11px); }
.iwb-ss-varinput {
flex: 1 1 auto; min-width: 0; height: 24px; padding: 0 7px;
border: 1px solid var(--iwb-border, #d5d9e0); border-radius: var(--rd-sm, 6px);
@@ -396,8 +395,7 @@
// { '`SUBJECT`': 'main subject' } ← 老导入数据:值是人话,只能拿 key 兜底(key 上还残留反引号)
const PH_RE = /\{([^{}\n]{1,40})\}/g
// 变量区默认显示几个,其余折叠(Vigo 那批风格单条提示词最多 24 个占位符)
const VAR_SHOW = 6
// 变量全部平铺,不做折叠:折叠按钮的"收起"状态容易让人以为变量就这些
// 排掉 JSON 碎片、句子、空括号:占位符名只能是一个短标识符
function isPlaceholderName(name) {
@@ -816,23 +814,8 @@
onInput: (event) => { values[item.name] = event.target.value; refreshPreview() },
}),
])
// 一次铺满 24 个输入框会把详情页顶爆(Vigo 那批就是),先给 6 个,其余折起来
for (const item of keys.slice(0, VAR_SHOW)) varBox.appendChild(rowOf(item))
const tail = keys.slice(VAR_SHOW)
if (tail.length) {
const more = el('div', { class: 'iwb-ss-varmore', style: 'display:none' })
for (const item of tail) more.appendChild(rowOf(item))
const toggle = el('button', {
class: 'iwb-ss-btn iwb-ss-vartoggle', text: '展开其余 ' + tail.length + ' 个变量',
onClick: () => {
const opening = more.style.display === 'none'
more.style.display = opening ? '' : 'none'
toggle.textContent = opening ? '收起' : '展开其余 ' + tail.length + ' 个变量'
},
})
varBox.appendChild(toggle)
varBox.appendChild(more)
}
// 全部平铺(Vigo 那批最多 24 个,详情页本身可滚动,不再折叠)
for (const item of keys) varBox.appendChild(rowOf(item))
bodyEl.appendChild(varBox)
}
@@ -968,7 +951,7 @@
global.IWBPluginHost.register({
id: 'style-source',
name: '风格库',
version: '1.0.3',
version: '1.0.4',
apiVersion: 1,
capabilities: ['panels', 'canvas', 'canvasWrite'],
settings: {
+12 -27
View File
@@ -133,7 +133,7 @@ async function main() {
const m = window.__manifest
return { id: m.id, name: m.name, version: m.version, apiVersion: m.apiVersion, caps: m.capabilities, hasDataUrl: Boolean(m.settings && m.settings.dataUrl) }
})
check('manifest id/version 正确', manifest.id === 'style-source' && manifest.version === '1.0.3', JSON.stringify({ id: manifest.id, version: manifest.version }))
check('manifest id/version 正确', manifest.id === 'style-source' && manifest.version === '1.0.4', JSON.stringify({ id: manifest.id, version: manifest.version }))
check('capabilities 含 panels+canvas+canvasWrite',
['panels', 'canvas', 'canvasWrite'].every((c) => manifest.caps.includes(c)), manifest.caps.join(','))
check('settings 暴露 dataUrl', manifest.hasDataUrl)
@@ -416,8 +416,6 @@ async function main() {
return page.evaluate(() => {
const box = window.__hostA.querySelector('.iwb-ss-detail')
const inputs = Array.from(box.querySelectorAll('.iwb-ss-varinput'))
const toggle = box.querySelector('.iwb-ss-vartoggle')
const more = box.querySelector('.iwb-ss-varmore')
const preview = (box.querySelector('.iwb-ss-text') || {}).textContent || ''
const names = inputs.map((i) => i.getAttribute('placeholder'))
return {
@@ -432,8 +430,7 @@ async function main() {
visible: inputs.filter((i) => i.getBoundingClientRect().height > 0).length,
dead: names.filter((n) => preview.indexOf('{' + n + '}') < 0).length,
hasVarLabel: Array.from(box.querySelectorAll('.iwb-ss-label')).some((e) => e.textContent.indexOf('变量') >= 0),
toggle: toggle ? toggle.textContent : '',
moreHidden: more ? getComputedStyle(more).display === 'none' : null,
hasToggle: Boolean(box.querySelector('.iwb-ss-vartoggle')),
}
})
}
@@ -441,6 +438,10 @@ async function main() {
const undeclared = await openBySearch('婚礼喜字影像画报')
check('提示词有占位符、数据没声明的风格也有输入框',
undeclared.names.length === 3 && undeclared.dead === 0, undeclared.name + ' → ' + undeclared.names.join(','))
check('每个输入框都有可读标签(不是空串/裸花括号)',
undeclared.pairs.length === 3 &&
undeclared.pairs.every((p) => p.label.trim().length > 0 && !/[{}]/.test(p.label)),
undeclared.pairs.map((p) => p.label + '→{' + p.name + '}').join(', '))
const vigo = await openBySearch('黄黑漫画食品小志广告风格')
const subj = vigo.pairs.find((p) => p.name === 'SUBJECT')
@@ -451,28 +452,12 @@ async function main() {
vigo.dead === 0, 'inputs=' + vigo.names.length + ' dead=' + vigo.dead)
const mondrian = await openBySearch('蒙德里安秩序风')
check('声明与提示词对不上时退回占位符名(不再静默消失)',
mondrian.names.length === 8 && mondrian.pairs.every((p) => p.implicit && p.label.indexOf('`') < 0),
check('中英文混写的 kv_var 都能对上声明(8 个全部 declared)',
mondrian.names.length === 8 && mondrian.pairs.every((p) => !p.implicit && p.label.indexOf('`') < 0),
mondrian.pairs.slice(0, 3).map((p) => p.label + '→{' + p.name + '}').join(', '))
check('变量超过 6 个时先给 6 个、其余折叠',
mondrian.visible === 6 && mondrian.names.length > 6 && /展开其余 \d+ 个变量/.test(mondrian.toggle),
'可见=' + mondrian.visible + ' 全部=' + mondrian.names.length + ' / ' + mondrian.toggle)
check('折叠区默认收起', mondrian.moreHidden === true)
const expand = await page.evaluate(() => {
const box = window.__hostA.querySelector('.iwb-ss-detail')
const btn = box.querySelector('.iwb-ss-vartoggle')
if (!btn) return null
btn.click()
const more = box.querySelector('.iwb-ss-varmore')
return {
shown: more ? getComputedStyle(more).display !== 'none' : null,
count: more ? more.querySelectorAll('.iwb-ss-varinput').length : 0,
text: btn.textContent,
}
})
check('点「展开」后其余变量出现', Boolean(expand) && expand.shown === true && expand.count > 0,
expand ? '展开 ' + expand.count + ' 个 / 按钮=' + expand.text : '')
check('变量全部平铺:8 个输入框全可见,且没有折叠按钮',
mondrian.names.length === 8 && mondrian.visible === 8 && mondrian.hasToggle === false,
'全部=' + mondrian.names.length + ' 可见=' + mondrian.visible + ' 折叠按钮=' + mondrian.hasToggle)
const noVar = await openBySearch('旷野的风')
check('提示词里没有占位符就不摆空输入框',
@@ -535,7 +520,7 @@ async function main() {
})
await page.waitForTimeout(400)
await page.locator('#hostA').screenshot({ path: shotNarrow }).catch(() => {})
// 变量区留档:8 个占位符 → 前 6 个 + 「展开其余 2 个」
// 变量区留档:8 个占位符全部平铺
await page.evaluate(() => { window.__hostA.style.width = '980px'; window.__hostA.style.height = '1180px' })
await page.waitForTimeout(260)
await page.locator('#hostA .iwb-ss-search').fill('黄黑漫画食品小志广告风格')