From e015b26e0b67cada061552a624605476e8838223 Mon Sep 17 00:00:00 2001 From: qiqi Date: Sat, 14 Nov 2026 13:04:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(style-source):=201.3.1=20CSS=20=E5=9C=A8?= =?UTF-8?q?=E6=BF=80=E6=B4=BB=E6=97=B6=E6=B3=A8=E5=85=A5=EF=BC=88=E4=B8=8D?= =?UTF-8?q?=E5=BC=80=E9=9D=A2=E6=9D=BF=E4=B9=9F=E4=B8=8D=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E7=BC=A9=E7=95=A5=E5=9B=BE=E9=93=BA=E6=BB=A1=E8=8A=82?= =?UTF-8?q?=E7=82=B9=EF=BC=89=EF=BC=9B=E8=A1=A5=E5=86=B7=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=9B=9E=E5=BD=92=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- style-source/README.md | 9 +++++- style-source/package.json | 2 +- style-source/src/index.js | 11 ++++++- style-source/tools/e2e-test-site.mjs | 47 ++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/style-source/README.md b/style-source/README.md index ec6be97..4d20e59 100644 --- a/style-source/README.md +++ b/style-source/README.md @@ -25,7 +25,7 @@ - **点击**:不传坐标(`createNode('prompt', null, null, …)`),交给宿主 `findSpot()` —— 从**视口中心**向外螺旋扫空位、跳过已有节点、并**避开压在画布上的浮层**(资源中心 / 插件面板 / 左右侧栏)。插件只有节点的 `x/y`,拿不到 pan/zoom 和实测高度,自己排必然插到看不见的地方或压在别的节点上(旧版就是「选中节点右侧固定 380,无避让」)。 - **按住拖到画布上松手**:节点落在**松手点**(`screenToWorld` 换算,节点左上角对齐光标)。落点由宿主算:pan/zoom 只有它知道。拖动中光标下跟一张幽灵卡片,进入画布会提示「松手放这里」;松手点不在画布上(还在面板里)⇒ 取消。位移不足 6px 视作点击,两条路径并存、互不干扰。落点**压住已有节点或被浮层遮住**时,宿主会就近吸附到旁边的空位(`snapToFreeSpot`,20px 间隙、优先留在视口内);落在空处则**完全按松手点**,不偏移。 -## 样式节点(v1.3.0) +## 样式节点(v1.3.1) 详情页底部有三颗按钮:**样式节点**(新)· 插入参考图 · 插入提示词。三颗都支持「点一下自动找位」和「按住拖到画布松手」,原两颗的行为一个字没改。 @@ -48,6 +48,13 @@ } ``` +### v1.3.1(2026-11-14)CSS 改为激活时注入 + +`ensureStyle()` 原本只在 `mount()`(面板)里调用 ⇒ **没打开过「风格库」面板**时,节点体是无样式的裸 DOM, +`` 按原图尺寸铺满整个节点(真机表现:图片"跑出来了")。 +现在 setup 注册变体前注入一次,`renderStyleNode()` 里再兜一次(幂等)。 +回归用例:`tools/e2e-test-site.mjs` 第 9 段(不开面板直接进存档画布,断言缩略图宽高 ≈56px)。 + ### 五条硬约束(改之前先读) 1. **节点上没有生成按钮。** 注册变体时不传 `run`,宿主就不会渲染那颗按钮。出图一律交给下游生图节点(它已经处理了四家渠道差异、尺寸收敛、并发与恢复)。 diff --git a/style-source/package.json b/style-source/package.json index 1542811..f0c3231 100644 --- a/style-source/package.json +++ b/style-source/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/style-source", "private": true, - "version": "1.3.0", + "version": "1.3.1", "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 4b07838..b793e82 100644 --- a/style-source/src/index.js +++ b/style-source/src/index.js @@ -614,6 +614,9 @@ // 变量输入框一旦被重建,每敲一个字就会失焦。 // 所以这里做「建一次骨架 + 之后只同步值」。 function renderStyleNode(node, props, host) { + // 兜底:万一节点体先于 setup 渲染(宿主注册表现在支持「注册后立刻重画」), + // 这一句保证样式一定在 —— 少一次注入就是「缩略图铺满节点」那种事故。 + ensureStyle() let st = host.__ssn if (!st) { host.textContent = '' @@ -1365,7 +1368,7 @@ global.IWBPluginHost.register({ id: 'style-source', name: '风格库', - version: '1.3.0', + version: '1.3.1', apiVersion: 1, capabilities: ['panels', 'canvas', 'canvasWrite', 'nodeTypes'], settings: { @@ -1397,6 +1400,12 @@ // 样式节点变体(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 ⇒ + // 节点里的 `` 拿不到 56px 约束,按原图尺寸铺满整个节点。 + // 现在在注册变体前就把样式注入(mount 里那次是幂等兜底)。 + ensureStyle() if (ctx.nodes && typeof ctx.nodes.register === 'function') { ctx.nodes.register({ id: 'style', diff --git a/style-source/tools/e2e-test-site.mjs b/style-source/tools/e2e-test-site.mjs index d8f5cf3..d0d2645 100644 --- a/style-source/tools/e2e-test-site.mjs +++ b/style-source/tools/e2e-test-site.mjs @@ -228,6 +228,53 @@ if (picked) { await shot('collapsed') } +// ── 9. 冷启动:**一次都没打开过「风格库」面板**,节点体也必须是有样式的 ────────────── +// v1.3.1 修的事故:CSS 原先进在 mount() 里,从存档打开画布时面板不 mount ⇒ `` +// 拿不到 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()