feat(canvas-v3): P2 out 结果缩略图 Canvas 化
This commit is contained in:
1 parent
db50733876
commit
2d0abb1b79
9 files changed
+61
-10
No files matched your search
@@ -65,6 +65,7 @@
|
||||
const widthOf = typeof o.widthOf === 'function' ? o.widthOf : (n) => n.w || 240
|
||||
const heightOf = typeof o.heightOf === 'function' ? o.heightOf : (n) => n.h || 220
|
||||
const imageFor = typeof o.imageFor === 'function' ? o.imageFor : () => ''
|
||||
const outThumbsFor = typeof o.outThumbsFor === 'function' ? o.outThumbsFor : () => []
|
||||
const onImageLoad = o.onImageLoad
|
||||
const types = Array.isArray(o.types) && o.types.length ? o.types : ['ref']
|
||||
const bg = css('--iwb-panel', '#ffffff')
|
||||
@@ -114,6 +115,29 @@
|
||||
ctx.font = Math.max(10, 12 / scale * 0.9) + 'px -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif'
|
||||
ctx.fillText(entry && entry.failed ? '图片源失效' : '图片加载中…', ix + 12, iy + 24)
|
||||
}
|
||||
} else if (n.type === 'out') {
|
||||
// 输出节点:画结果缩略图网格;没有结果时提示选中查看。
|
||||
const urls = outThumbsFor(n) || []
|
||||
if (urls.length) {
|
||||
const cols = 2
|
||||
const gap = 4
|
||||
const cw = Math.max(1, (iw - gap) / cols)
|
||||
const ch = cw * 0.75
|
||||
for (let i = 0; i < Math.min(4, urls.length); i++) {
|
||||
const col = i % cols, row = Math.floor(i / cols)
|
||||
const x0 = ix + col * (cw + gap), y0 = iy + row * (ch + gap)
|
||||
const entry = imageOf(imageFor(n, urls[i]), onImageLoad)
|
||||
ctx.fillStyle = css('--iwb-layer2', '#f1f2f4')
|
||||
roundRect(ctx, x0, y0, cw, ch, 6); ctx.fill()
|
||||
if (entry && entry.loaded && !entry.failed) {
|
||||
try { ctx.drawImage(entry.img, x0, y0, cw, ch) } catch (e) { /* ignore */ }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx.fillStyle = text
|
||||
ctx.font = Math.max(10, 12 / scale * 0.9) + 'px -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif'
|
||||
ctx.fillText('选中查看结果', ix + 2, iy + Math.max(14, 16 / scale))
|
||||
}
|
||||
} else {
|
||||
// P2 文本节点:画截断文本,选中后由 NodeCard 负责编辑。
|
||||
ctx.save()
|
||||
|
||||
+1
-1
@@ -61,6 +61,6 @@
|
||||
}
|
||||
|
||||
// P2 第一批:ref 图片节点 + prompt/textout 文本类节点。
|
||||
const TYPES = ['ref', 'prompt', 'textout', 'combine', 'batch', 'relay', 'gen']
|
||||
const TYPES = ['ref', 'prompt', 'textout', 'combine', 'batch', 'relay', 'gen', 'out']
|
||||
global.IWBCanvasV3 = { KEY, TYPES, isEnabled, setEnabled, init, stats }
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
+17
-1
@@ -1190,6 +1190,22 @@
|
||||
return line.length > 40 ? (line.slice(0, 40) + '…') : line
|
||||
}
|
||||
|
||||
// Canvas V3:out 节点的结果图 URL 列表(只读;仍复用 outGroupsOf 的分组/排序)。
|
||||
function outThumbUrlsOf (node, nodes, edges) {
|
||||
const nodeMap = new Map((nodes || []).map((n) => [n.id, n]))
|
||||
// Canvas V3 可能在 NodeCard 还没渲染过时调用本函数,此时 inject 还没发生 —— 用本职能兜底。
|
||||
const isProducer = typeof isImageProducer === 'function' ? isImageProducer : (n) => !!(n && (n.type === 'gen' || n.type === 'out' || n.type === 'ref' || n.type === 'combine' || n.type === 'batch'))
|
||||
const tasksOf = typeof cachedGenerationTasks === 'function' ? cachedGenerationTasks : () => []
|
||||
const srcGens = (edges || [])
|
||||
.filter((e) => e.to === node.id)
|
||||
.map((e) => nodeMap.get(e.from))
|
||||
.filter((n) => isProducer(n) && !(n.data && n.data.enabled === false))
|
||||
const merged = outGroupsOf(srcGens, (g) => tasksOf(g, nodes || [], edges || []).map((t) => ({ id: t.id, title: t.title || '' })))
|
||||
const urls = []
|
||||
for (const m of merged) for (const r of m.items) if (r && r.url) urls.push(r.url)
|
||||
return urls
|
||||
}
|
||||
|
||||
function lodBody(node, mode) {
|
||||
const isImg = LOD_IMG_TYPES.indexOf(node.type) >= 0
|
||||
if (mode !== 'plain' && isImg) {
|
||||
@@ -1213,5 +1229,5 @@
|
||||
}
|
||||
|
||||
// md:纯函数(Markdown ⇄ 编辑器 HTML)的测试钩子 —— 行距翻倍的回归由 tests/prompt-md-roundtrip-test.js 守住
|
||||
global.IWBNodeBodies = { inject, openPromptExpand, md: { toHtml: mdToHtml, toMd: htmlToMd }, relay: renderRelayBody, prompt: renderPromptBody, plugin: renderPluginBody, textout: renderTextoutBody, combine: renderCombineBody, llm: renderLlmBody, batch: renderBatchBody, ref: renderRefBody, out: renderOutBody, gen: renderGenBody, outGroupsOf, lodBody }
|
||||
global.IWBNodeBodies = { inject, openPromptExpand, md: { toHtml: mdToHtml, toMd: htmlToMd }, relay: renderRelayBody, prompt: renderPromptBody, plugin: renderPluginBody, textout: renderTextoutBody, combine: renderCombineBody, llm: renderLlmBody, batch: renderBatchBody, ref: renderRefBody, out: renderOutBody, gen: renderGenBody, outGroupsOf, outThumbUrlsOf, lodBody }
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
Reference in new issue
Block a user