From 4f7bed96c6a1bdcd52d1c232d321a40ab8632390 Mon Sep 17 00:00:00 2001 From: qiqi Date: Mon, 2 Nov 2026 10:06:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(style-source):=20=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E6=8B=89=E9=AB=98=E6=8F=90=E7=A4=BA=E8=AF=8D=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=97=B6=E6=96=87=E5=AD=97=E4=B8=8D=E5=86=8D=E5=8D=A1=E5=9C=A8?= =?UTF-8?q?=20240px=20(1.0.2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一版注入的 `.iwb-node .iwb-textarea-plain{max-height:240px}` 把宿主 `.iwb-node-fixed .iwb-textarea{max-height:none;height:auto!important}` 盖掉了: 两者特异性同为 (0,2,0),插件样式注在 style.css 之后 ⇒ 上限赢。用户拉高节点 后文字仍停在 240px,下面一大片空白。 - 上限改为只作用于 `.iwb-node:not(.iwb-node-fixed)`(node.h 有值 = 手动拉过尺寸), 并补 `.iwb-node.iwb-node-fixed .iwb-textarea-plain{max-height:none}` 兜底 - harness:合成宿主补抄 style.css 的 fixed 规则;新增 2 条断言(文本域随节点撑满 / maxH=none) - 实测 273px 默认节点仍限 240 内滚动;拉高到 522 时 textarea 撑到 492,无裁切 --- style-source/README.md | 14 +++++++++---- style-source/package.json | 2 +- style-source/src/index.js | 11 ++++++++-- style-source/tools/harness.mjs | 38 ++++++++++++++++++++++++++++++++-- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/style-source/README.md b/style-source/README.md index 71a497d..f11cf0b 100644 --- a/style-source/README.md +++ b/style-source/README.md @@ -45,14 +45,20 @@ 风格提示词动辄上千字。宿主 `renderPromptBody` 用 `autoGrow` 把 textarea 高度直接设成 `scrollHeight`(**没有上限**), 所以一条长提示词插进画布会变成一根两米高的柱子,一张卡吃掉整个视口。 -插件在挂载时注入一条(幂等的)样式: +插件在挂载时注入两条(幂等的)样式: ```css -.iwb-node .iwb-textarea-plain { max-height: 240px } /* 高度来自设置项 promptMaxH */ +/* 自动高节点:压住上限,高度来自设置项 promptMaxH */ +.iwb-node:not(.iwb-node-fixed) .iwb-textarea-plain { max-height: 240px } +/* 用户手动拉过尺寸的节点(node.h 有值 → 宿主加 .iwb-node-fixed):让开上限,交给宿主拉伸规则 */ +.iwb-node.iwb-node-fixed .iwb-textarea-plain { max-height: none } ``` -- 节点尺寸从此**固定**(≈ max-height + 内边距),插了几张卡一眼看清; +- **默认**节点尺寸固定(≈ max-height + 内边距),插了几张卡一眼看清; - 宿主 `.iwb-textarea` 本来就是 `overflow-y: auto`,超出的部分在节点内滚动,**内容一个字都不丢**; +- **手动拉过右下角缩放手柄**的节点不受上限约束:宿主 `.iwb-node-fixed .iwb-textarea{flex:1 1 auto;height:auto!important}` + 会把文本域撑满节点,想多高就多高(⚠️ 前提是选择器带 `:not(.iwb-node-fixed)`——两条规则特异性同为 `(0,2,0)`, + 且插件样式注入得更晚,不排除的话会把宿主的拉伸规则压掉,节点被拉高后文字仍卡在 240px,下面留一片空白); - 想看全文照旧用节点气泡的「**放大编辑**」(⌘/Ctrl + E),那是不限高的浮层; - 选择器只碰**节点内**的纯文本域,宿主的弹窗 / 设置面板(`.iwb-modal-lg .iwb-textarea`)不受影响。 @@ -71,7 +77,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.1 +node scripts/plugins-publish.mjs /tmp/plugin-<其余插件>.js /tmp/plugin-style-source.js --upload --version style-source=1.0.2 ``` 图标:宿主 `app.js` 的 `PLUGIN_ICONS` 可加 `'style-source': 'palette'`(不加则用面板 manifest 自带的 `palette`,效果一致)。 diff --git a/style-source/package.json b/style-source/package.json index d1326bf..8873ccd 100644 --- a/style-source/package.json +++ b/style-source/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/style-source", "private": true, - "version": "1.0.1", + "version": "1.0.2", "description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点", "ibwPlugin": { "id": "style-source", diff --git a/style-source/src/index.js b/style-source/src/index.js index 0975555..0f8e9eb 100644 --- a/style-source/src/index.js +++ b/style-source/src/index.js @@ -289,6 +289,11 @@ // · 宿主 .iwb-textarea 本身是 overflow-y:auto,超出部分在节点内滚动,内容一个字都不丢; // · 想看全文照旧用节点气泡的「放大编辑」(⌘/Ctrl+E),那里是不限高的浮层。 // 选择器只碰节点内的纯文本域,宿主的弹窗/设置面板(.iwb-modal-lg .iwb-textarea)不受影响。 + // + // ⚠️ 必须排除 `.iwb-node-fixed`(节点 h 有值 = 用户手动拉过尺寸): + // 宿主 style.css 里有 `.iwb-node-fixed .iwb-textarea{flex:1 1 auto;max-height:none;height:auto!important}`, + // 手拉节点时靠它把文本域撑满节点。原来不加 :not() 时两条规则特异性同为 (0,2,0), + // 而插件样式注入得更晚 ⇒ 上限赢了 ⇒ 节点被拉高后文字仍卡在 240px、下面一片空白(2026-11-02 反馈)。 const PROMPT_MAX_H = 240 function capHeightOf(ctx) { @@ -308,7 +313,9 @@ node = el('style', { id: id }) ;(document.head || document.documentElement).appendChild(node) } - node.textContent = '.iwb-node .iwb-textarea-plain{max-height:' + maxH + 'px}' + // 默认(自动高)节点压住上限;手动拉过尺寸的节点交给宿主拉伸规则,一个字都不裁 + node.textContent = '.iwb-node:not(.iwb-node-fixed) .iwb-textarea-plain{max-height:' + maxH + 'px}' + + '.iwb-node.iwb-node-fixed .iwb-textarea-plain{max-height:none}' } catch (error) { /* 注入失败只是节点还会被拉长,不影响插入 */ } } @@ -885,7 +892,7 @@ global.IWBPluginHost.register({ id: 'style-source', name: '风格库', - version: '1.0.1', + version: '1.0.2', apiVersion: 1, capabilities: ['panels', 'canvas', 'canvasWrite'], settings: { diff --git a/style-source/tools/harness.mjs b/style-source/tools/harness.mjs index a26086c..4f23a01 100644 --- a/style-source/tools/harness.mjs +++ b/style-source/tools/harness.mjs @@ -54,7 +54,14 @@ const PNG_1PX = Buffer.from( const PAGE_HTML = ` +#stage{display:flex;align-items:stretch;height:100vh;padding:0} +/* 从宿主 style.css 抄的关键几条,否则「手动拉过尺寸的节点」这条测不出来 */ +.iwb-node{display:flex;flex-direction:column;border:1px solid #d5d9e0;border-radius:14px;position:relative} +.iwb-node-body{padding:8px 10px;flex:1 1 auto;min-height:0} +.iwb-textarea{min-height:56px;overflow-y:auto;width:100%;box-sizing:border-box;resize:none} +.iwb-node-fixed .iwb-node-body{display:flex;flex-direction:column;overflow:visible;min-height:0} +.iwb-node-fixed .iwb-textarea{flex:1 1 auto;max-height:none;min-height:56px;height:auto !important} +
` async function main() { @@ -126,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.1', JSON.stringify({ id: manifest.id, version: manifest.version })) + check('manifest id/version 正确', manifest.id === 'style-source' && manifest.version === '1.0.2', 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) @@ -182,6 +189,33 @@ async function main() { check('内联 height=1200 的文本域被压到 240(节点不再被拉长)', cap.cappedH > 0 && cap.cappedH <= 260, 'h=' + cap.cappedH + '(240 内容 + 边框)') check('超出部分在文本域内滚动', cap.overflowY === 'auto', cap.overflowY) + // 回归守门:默认只压「自动高」的节点;用户手动拉过尺寸(node.h → .iwb-node-fixed)时不能压, + // 否则节点被拉高一米,文字还卡在 240px,下面留一大片空白 + const stretched = await page.evaluate(() => { + const wrap = document.createElement('div') + wrap.className = 'iwb-node iwb-node-fixed' // node.h 有值 → 宿主加这个 class + wrap.style.cssText = 'width:280px;min-height:520px' + const body = document.createElement('div') + body.className = 'iwb-node-body' + const ta = document.createElement('textarea') + ta.className = 'iwb-textarea iwb-textarea-plain' + ta.style.height = '1200px' + ta.value = 'x'.repeat(4000) + body.appendChild(ta) + wrap.appendChild(body) + document.getElementById('stage').appendChild(wrap) + const r = { + nodeH: Math.round(wrap.getBoundingClientRect().height), + taH: Math.round(ta.getBoundingClientRect().height), + cap: getComputedStyle(ta).maxHeight, + } + wrap.remove() + return r + }) + check('手动拉高节点后文本域跟着撑满(不再卡在 240)', + stretched.taH > stretched.nodeH * 0.6, 'node=' + stretched.nodeH + ' textarea=' + stretched.taH + ' maxH=' + stretched.cap) + check('手动拉高节点时上限被让开', stretched.cap === 'none', stretched.cap) + // ---- 数据加载 ---- const loaded = await poll(async () => { const txt = await page.locator('.iwb-ss-status').innerText().catch(() => '')