fix(canvas): 复制落点扣除停靠栏;暗色自定义底色改近黑文字

缺陷 1(复制落点):Ctrl+D 复制节点时 copyOffset 用整窗画布尺寸算可放范围,
未扣停靠栏 ⇒ 允许把副本放到屏幕左侧。实测原节点 x=398,副本落在 x=78(整块被 318px 左栏盖住)。
- copyOffset 的 bounds 改用 canvasSafeInsets(与 doFit 同口径)
- findSpot 的浮层禁区补 .iwb-dock(新建/粘贴节点同一类问题)

缺陷 2(暗色可读性):暗色主题的节点文字已是浅色 #e3e3e3,但自定义底色的暗色令牌仍是
中灰(yellow #c7bf9a)⇒ 实测对比度 1.4(要求 ≥7),文字几乎不可读。
- 新增 .theme-dark .iwb-node[data-bg] { --iwb-node-text: #1d1d1f }(实测对比度 ≈9.4)
- 修正 style.css 里「暗色=中灰底+近黑字」的过时注释

顺带加固(同一类:启动时停靠栏还没挂载):
- ui-dock 写入 --iwb-dock-l/-r 后广播 iwb:dock-insets
- Workbench 监听:仅当视口仍是「自动适应」的产物(用户没缩放/平移过)才按新占位重新适应
  ⇒ 修掉「首帧算错后不纠正」,且不会覆盖用户早期的缩放操作

棘轮:app.js 8315→8326、Workbench 2169→2180(+11,见 commit 说明);文档数字已 sync。
验证:verify:ci 全绿;视觉基线 24/24 无 diff。
This commit is contained in:
qiqi committed 2026-11-27 00:29:35 +08:00
1 parent ebfbbfc67a
commit 9df38163ea
7 files changed
+31 -12

No files matched your search

+9 -5
View File
@@ -1756,7 +1756,9 @@
const x0 = Math.min(...list.map((n) => n.x)), y0 = Math.min(...list.map((n) => n.y))
const box = { x: x0, y: y0, w: Math.max(...list.map((n) => n.x + nodeWidth(n))) - x0, h: Math.max(...list.map((n) => n.y + hOf(n))) - y0 }
const obstacles = refs.nodes.map((n) => ({ x: n.x, y: n.y, w: nodeWidth(n), h: hOf(n) }))
const spot = CanvasGeometry.placeBeside(box, obstacles, { gap, bounds: { minX: Math.round((pad - vp.x) / sc), minY: Math.round((pad - vp.y) / sc), maxX: Math.round((cw - pad - vp.x) / sc) - box.w, maxY: Math.round((ch - pad - vp.y) / sc) - box.h } })
// v3.26.108:可放范围必须扣除停靠栏/工具条占位,否则副本会被放到屏幕左侧(= 被左栏盖住)
const ins = canvasSafeInsets()
const spot = CanvasGeometry.placeBeside(box, obstacles, { gap, bounds: { minX: Math.round((ins.left + pad - vp.x) / sc), minY: Math.round((ins.top + pad - vp.y) / sc), maxX: Math.round((cw - ins.right - pad - vp.x) / sc) - box.w, maxY: Math.round((ch - ins.bottom - pad - vp.y) / sc) - box.h } })
const sx = vp.x + spot.x * sc, sy = vp.y + spot.y * sc, sw = box.w * sc, sh = box.h * sc
// 只有整块都看不见才挪相机:露一半就不动 —— 视角跳动比"露一半"更打断方向感
if (sx + sw <= pad || sx >= cw - pad || sy + sh <= pad || sy >= ch - pad) {
@@ -2037,7 +2039,7 @@
// (面板常停靠左侧),候选位与禁区相交也一律跳过。世界→屏幕换算:screen = world * scale + vp
const blockedRects = []
try {
document.querySelectorAll('.iwb-fullmask, .iwb-navrail, .iwb-plugin-page, .iwb-lib, .iwb-lib-embedded').forEach((elm) => {
document.querySelectorAll('.iwb-dock, .iwb-fullmask, .iwb-navrail, .iwb-plugin-page, .iwb-lib, .iwb-lib-embedded').forEach((elm) => {
const r = elm.getBoundingClientRect()
if (r && r.width > 4 && r.height > 4) blockedRects.push(r)
})
@@ -2212,13 +2214,13 @@
const doFit = (nodeList, _tries) => {
const ins = canvasSafeInsets()
// 停靠栏/画布工具条在首帧还没挂载(实测 --iwb-dock-l 约 180ms 后才写入):
// 此刻算出的占位是 0,会把节点放到栏底。等它就绪再适应,最多约 400ms,之后按当前值兜底。
// 此刻算出的占位是 0,会把节点放到栏底。等它就绪再适应(最多约 1.5s:插件面板多的首屏更慢),之后按当前值兜底。
const tries = _tries || 0
if (ins.pending && tries < 25) {
setTimeout(() => doFit(nodeList, tries + 1), 16)
return
}
if (!nodeList || !nodeList.length) { setViewport({ x: ins.left + ins.pad, y: ins.top + ins.pad, scale: 1 }); return }
if (!nodeList || !nodeList.length) { const empty = { x: ins.left + ins.pad, y: ins.top + ins.pad, scale: 1 }; refs.lastAutoFit = empty; setViewport(empty); return }
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity
for (const n of nodeList) {
minX = Math.min(minX, n.x); minY = Math.min(minY, n.y)
@@ -2230,7 +2232,9 @@
const vw = Math.max(120, window.innerWidth - ins.left - ins.right - ins.pad * 2)
const vh = Math.max(120, window.innerHeight - ins.top - ins.bottom - ins.pad * 2)
const scale = Math.max(0.01, Math.min(1, Math.min(vw / Math.max(1, maxX - minX), vh / Math.max(1, maxY - minY))))
setViewport({ x: ins.left + ins.pad - minX * scale, y: ins.top + ins.pad - minY * scale, scale })
const next = { x: ins.left + ins.pad - minX * scale, y: ins.top + ins.pad - minY * scale, scale }
refs.lastAutoFit = next // 供「停靠栏稍后就绪」时判断视口是否仍是自动适应(用户没动过才重新适应)
setViewport(next)
}
return { historyStore, HISTORY_IMG_REF_FIELDS, historyRefUsable, historyRefData, historyRawSnapshot, pushHistory, pushHistoryDebounced, restore, undo, redo, addPromptToLibrary, UNDO_KEYS, updateNode, clearGenResults, deleteNodes, deleteEdge, copyOffset, duplicateNodes, floatbarRefPaste, outResultUrls, stageClip, copyNodes, pasteGraph, readClipboardGraph, pasteCopiedNodes, clearClipboard, cutNodes, groupOf, makeGroup, ungroup, joinGroupOf, renameGroup, duplicateGroup, saveGroupSnapshot, saveSelectionAsGroup, instantiateGroup, loadSavedGroups, findSpot, placeAtDrop, addNode, addPluginNode, addRefFromUrl, refSrcOf, refreshOutputs, deleteOutputs, loadDemo, doFit }
+2
View File
@@ -171,6 +171,8 @@
const rw = dock.right.open ? dock.right.w : 0
r.style.setProperty('--iwb-dock-l', lw + 'px')
r.style.setProperty('--iwb-dock-r', rw + 'px')
// 2026-11-27:占位变化通知宿主 —— 启动 doFit 若在停靠栏就绪前跑过,需要按新占位重新适应一次
try { global.dispatchEvent(new global.CustomEvent('iwb:dock-insets', { detail: { left: lw, right: rw } })) } catch (err) { /* ignore */ }
return function () { r.style.setProperty('--iwb-dock-l', '0px'); r.style.setProperty('--iwb-dock-r', '0px') }
}, [dock.left.open, dock.left.w, dock.right.open, dock.right.w])