diff --git a/app.js b/app.js index 0d32e12..6b1fe91 100644 --- a/app.js +++ b/app.js @@ -6027,7 +6027,14 @@ const tbCenterSeed = (type, refs) => { const [selEdge, setSelEdge] = useState(null) const [hoverEdgeId, setHoverEdgeId] = useState(null) const canvasV3On = !!(typeof window !== 'undefined' && window.IWBCanvasV3 && window.IWBCanvasV3.isEnabled && window.IWBCanvasV3.isEnabled()) - const panAllOff = (() => { try { return !!lsGet('iwb_pan_all_off', false) } catch (e) { return false } })() + // v3.26.156:平移期默认不再把全部节点挂上(那会把世界层撑成几十屏,WebKit 分块栅格化 ⇒ 残块/拖影)。 + // iwb_pan_mount_all=1 显式退回旧行为;老开关 iwb_pan_all_off=1 语义不变(= 不全量挂载)。 + const panMountAll = (() => { + try { + if (!!lsGet('iwb_pan_all_off', false)) return false + return !!lsGet('iwb_pan_mount_all', false) + } catch (e) { return false } + })() // 默认平移时移动已画好的边线 canvas,不每帧重画;iwb_pan_edges_redraw=true 可退回每帧重画做 A/B。 const panEdgesFreeze = (() => { try { return !lsGet('iwb_pan_edges_redraw', false) } catch (e) { return true } })() const canvasV3Types = (canvasV3On && window.IWBCanvasV3 && Array.isArray(window.IWBCanvasV3.TYPES)) ? window.IWBCanvasV3.TYPES : ['ref'] @@ -6224,6 +6231,7 @@ const tbCenterSeed = (type, refs) => { const [tick, setTick] = useState(0) const [canvasSize, setCanvasSize] = useState({ w: 0, h: 0 }) const [canvasEl] = useState(() => ({ el: null })) + const [panCull, setPanCull] = React.useState(null) const [groups, setGroups] = useState([]) const [savedGroups, setSavedGroups] = useState([]) const [nodeGroupGroups, setNodeGroupGroups] = useState([]) @@ -7407,6 +7415,16 @@ const tbCenterSeed = (type, refs) => { try { if (typeof refs.edgeCanvasDraw === 'function') refs.edgeCanvasDraw(x, y, scale) } catch (e) { /* ignore */ } } try { if (typeof refs.nodeCanvasDraw === 'function') refs.nodeCanvasDraw(x, y, scale) } catch (e) { /* ignore */ } + // v3.26.156:平移窗口每跨 1/2 屏更新一次(此时才触发一次 React 渲染,代价可控) + if (!refs.pan || panMountAll) { refs.panCullAt = null } else { + const at = refs.panCullAt + const halfW = Math.max(320, (canvasSize.w || 800) * 0.5) + const halfH = Math.max(240, (canvasSize.h || 600) * 0.5) + if (!at || Math.abs(x - at.x) > halfW || Math.abs(y - at.y) > halfH) { + refs.panCullAt = { x: x, y: y } + try { setPanCull({ x: x, y: y, scale: scale }) } catch (e) { /* ignore */ } + } + } } // LOD 滞回状态:plain 在 <15% 进入、>18% 退出(用 ref 保存,不触发额外渲染) @@ -7535,8 +7553,14 @@ const tbCenterSeed = (type, refs) => { // 视口裁剪:大画布只渲染可见节点/连线/组(jsdom 无实际画布尺寸时全渲染,兼容测试) // 视口裁剪矩形(useMemo:拖动时 viewport 不变则复用,避免每帧算除法) // 视口裁剪:宽边距 240(纯文本节点),带图节点 80 —— 见 CanvasGeometry.cullRectsOf 注释 - const cullRects = React.useMemo(() => CanvasGeometry.cullRectsOf(canvasSize, viewport), [canvasSize.w, canvasSize.h, viewport.x, viewport.y, viewport.scale]) - const nodeVisible = (n) => CanvasGeometry.nodeVisibleIn(n, cullRects, { drag: refs.drag, resize: refs.resize, sel: sel, pan: !!refs.pan && !panAllOff, widthOf: nodeWidth, heightOf: hOf }) + // v3.26.156:平移期间裁剪窗口跟着位移走(每跨 1/2 屏更新一次),只挂载窗口附近的节点; + // 窗口额外放 0.7 屏边距,保证两次更新之间不会露白。 + const navView = (refs.pan && panCull && !panMountAll) ? panCull : viewport + const cullRects = React.useMemo(() => { + const extra = (refs.pan && !panMountAll) ? (Math.max(canvasSize.w || 0, canvasSize.h || 0) / (navView.scale || 1)) * 0.7 : 0 + return CanvasGeometry.cullRectsOf(canvasSize, navView, extra) + }, [canvasSize.w, canvasSize.h, navView.x, navView.y, navView.scale, panCull, panMountAll]) + const nodeVisible = (n) => CanvasGeometry.nodeVisibleIn(n, cullRects, { drag: refs.drag, resize: refs.resize, sel: sel, pan: !!refs.pan, mountAll: panMountAll, widthOf: nodeWidth, heightOf: hOf }) const visibleIds = new Set(nodes.filter(nodeVisible).map((n) => n.id)) try { wSetScaleNow(viewport.scale) } catch (e) { /* ignore */ } @@ -7571,6 +7595,7 @@ const tbCenterSeed = (type, refs) => { }, []) // v3.26.134:图库缩略图空闲预热(实现抽在 src/ui-workbench-hooks.js,这里只做装配) IWWorkbenchHooks.useGalleryPrewarm({ len: outputs.length, list: () => outputs, refs, storage: () => wStoreMod(), state: wPrewarmState }) + React.useEffect(() => { if (panCull) setPanCull(null) }, [viewport.x, viewport.y, viewport.scale]) const scaleText = Math.round(viewport.scale * 100) + '%' const saveText = saveState === 'saving' ? '正在保存' : saveState === 'saved' ? '保存成功' : saveState === 'error' ? '保存失败' : '' const connecting = !!conn diff --git a/package.json b/package.json index cd3f161..543c089 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "image-workbench-web", "private": true, - "version": "3.26.155", + "version": "3.26.156", "description": "Browser-based node canvas image workbench", "scripts": { "build": "node scripts/build.js && node scripts/copy-plugins.js", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 5bcdcea..ecccce0 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "image-workbench" -version = "3.26.155" +version = "3.26.156" description = "无限画布 · 生图工作台桌面版" authors = ["malongan"] license = "" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5a4fd7b..2546be0 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "image-workbench", - "version": "3.26.155", + "version": "3.26.156", "identifier": "com.malongan.imageworkbench", "build": { "frontendDist": "../dist", diff --git a/src/canvas-geometry.js b/src/canvas-geometry.js index a248fe6..97eca3b 100644 --- a/src/canvas-geometry.js +++ b/src/canvas-geometry.js @@ -365,17 +365,21 @@ const t = String(type || '') return /^(ref|out|image|combine|batch)$/.test(t) || /^plugin:(album|gallery)/.test(t) } - function cullRectsOf (canvasSize, viewport) { + function cullRectsOf (canvasSize, viewport, extraPad) { const w = Number(canvasSize && canvasSize.w) || 0 const h = Number(canvasSize && canvasSize.h) || 0 const s = Number(viewport && viewport.scale) || 0 if (!w || !h || !s) return null - const mk = (pad) => ({ - left: -viewport.x / s - pad, - top: -viewport.y / s - pad, - right: (w - viewport.x) / s + pad, - bottom: (h - viewport.y) / s + pad, - }) + const extra = Math.max(0, Number(extraPad) || 0) + const mk = (pad) => { + const p = pad + extra + return { + left: -viewport.x / s - p, + top: -viewport.y / s - p, + right: (w - viewport.x) / s + p, + bottom: (h - viewport.y) / s + p, + } + } return { wide: mk(CULL_PAD_WIDE), tight: mk(CULL_PAD_TIGHT) } } function nodeVisibleIn (n, rects, opt) { @@ -384,9 +388,10 @@ if (o.drag && o.drag.start && o.drag.start[n.id] != null) return true if (o.resize && o.resize.nodeId === n.id) return true if (o.sel && o.sel.indexOf(n.id) >= 0) return true - // v3.26.144:平移只改 DOM transform,viewport state 不更新 ⇒ 裁剪窗口会停在起点; - // 平移期间全量渲染(103 节点规模可接受),避免超过 280px 后新区域节点迟到/空白。 - if (o.pan) return true + // v3.26.156:平移期默认只挂载「起点窗口 + 当前窗口」并集内的节点(不再全量)。 + // 全量挂载会把整个世界层撑到几十屏大小,WebKit 只能分块栅格化,平移时就会出现残块/拖影。 + // o.mountAll 保留旧行为(诊断开关 iwb_pan_mount_all=1 时启用)。 + if (o.pan && o.mountAll) return true const r = heavyNodeOf(n.type) ? rects.tight : rects.wide const nw = o.widthOf ? o.widthOf(n) : 0 const nh = o.heightOf ? o.heightOf(n) : 0 diff --git a/style.css b/style.css index e342e81..c9019f9 100644 --- a/style.css +++ b/style.css @@ -1215,6 +1215,10 @@ body .iwb-history-embedded .iwb-history-item.iwb-history-selected:hover img { 平移只剩图层位移,不再每帧重栅格化整个世界层 —— 这是「画面滞留 / 拖动掉帧」的主因。 */ .iwb-canvas.iwb-gesture .iwb-world { will-change: transform; } .iwb-canvas.iwb-gesture .iwb-edges { pointer-events: none; } +/* v3.26.156:手势期间关掉浮层毛玻璃 —— WKWebView 上的 backdrop 采样是异步的, + 画布在下面移动时会留下肉眼可见的拖影。停手后自动恢复。 */ +.iwb-canvas.iwb-gesture .iwb-statusbar, +.iwb-canvas.iwb-gesture .iwb-statusbar *:not(img) { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; } .iwb-world { will-change: auto; } :root[data-layers="on"] .iwb-world { will-change: transform; } /* v3.26.137:毛玻璃开关(诊断页)。关掉后所有 backdrop-filter 失效,用于二分 graphics 占用 */ diff --git a/tests/canvas-geometry-test.js b/tests/canvas-geometry-test.js index df754fe..280d5e4 100644 --- a/tests/canvas-geometry-test.js +++ b/tests/canvas-geometry-test.js @@ -420,7 +420,13 @@ const near = (name, got, wantX, wantY) => { const rects = G.cullRectsOf({ w: 800, h: 600 }, { x: 0, y: 0, scale: 1 }) const far = { id: 'far', type: 'ref', x: 5000, y: 5000, w: 200, h: 200 } assert.strictEqual(G.nodeVisibleIn(far, rects, { widthOf: (n) => n.w, heightOf: (n) => n.h }), false) - assert.strictEqual(G.nodeVisibleIn(far, rects, { pan: true, widthOf: (n) => n.w, heightOf: (n) => n.h }), true, '平移期间必须全量渲染') + // v3.26.156:平移期不再全量渲染(世界层太大 ⇒ WebKit 分块栅格化出残块);只有显式 mountAll 才退回旧行为 + assert.strictEqual(G.nodeVisibleIn(far, rects, { pan: true, widthOf: (n) => n.w, heightOf: (n) => n.h }), false, '平移期间默认按窗口裁剪') + assert.strictEqual(G.nodeVisibleIn(far, rects, { pan: true, mountAll: true, widthOf: (n) => n.w, heightOf: (n) => n.h }), true, 'iwb_pan_mount_all=1 才全量渲染') + const wide = G.cullRectsOf({ w: 800, h: 600 }, { x: 0, y: 0, scale: 1 }, 2000) + const near = { id: 'near', type: 'ref', x: 2900, y: 2700, w: 100, h: 100 } + assert.strictEqual(G.nodeVisibleIn(near, rects, { widthOf: (n) => n.w, heightOf: (n) => n.h }), false, '无额外边距时 2900 在窗口外') + assert.strictEqual(G.nodeVisibleIn(near, wide, { widthOf: (n) => n.w, heightOf: (n) => n.h }), true, '额外边距要能覆盖平移位移') const fake = { attrs: {}, setAttribute(k, v) { this.attrs[k] = v } } G.applyEdgeLayerDom({ querySelector: (s) => (s === '.iwb-edge-world' ? fake : null) }, { w: 1200, h: 900 }, 120, 80, 2) assert.strictEqual(fake.attrs.transform, 'translate(120,80) scale(2)')