feat(canvas-v3): P1 单层 canvas 命中,移除每节点 proxy/端口 DOM
This commit is contained in:
1 parent
1d40e74ead
commit
84d2c1d896
15 files changed
+173
-38
No files matched your search
@@ -0,0 +1,24 @@
|
||||
/* canvas-v3-hit.js —— Canvas V3 的 ref 节点命中测试(2026-12-01,P1 下一步)
|
||||
* 目的:去掉每节点 hit proxy 与 DOM 端口,用单层坐标命中;选中后才恢复 NodeCard。
|
||||
*/
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
function hitRefNode (nodes, wx, wy, opts) {
|
||||
const o = opts || {}
|
||||
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 portR = Number(o.portRadiusWorld) > 0 ? Number(o.portRadiusWorld) : 10
|
||||
const list = Array.isArray(nodes) ? nodes : []
|
||||
for (let i = list.length - 1; i >= 0; i--) {
|
||||
const n = list[i]
|
||||
if (!n || n.type !== 'ref') continue
|
||||
const w = widthOf(n), h = heightOf(n)
|
||||
const cy = n.y + h / 2
|
||||
if (wx >= n.x - portR && wx <= n.x + portR && Math.abs(wy - cy) <= portR) return { node: n, port: 'in' }
|
||||
if (Math.abs(wx - (n.x + w)) <= portR && Math.abs(wy - cy) <= portR) return { node: n, port: 'out' }
|
||||
if (wx >= n.x && wx <= n.x + w && wy >= n.y && wy <= n.y + h) return { node: n, port: '' }
|
||||
}
|
||||
return null
|
||||
}
|
||||
global.IWBCanvasV3Hit = { hitRefNode }
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -112,7 +112,14 @@
|
||||
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)
|
||||
}
|
||||
// 选中/连线提示用边框色(当前未选中,保留扩展点)
|
||||
// 端口:canvas 命中测试用同一坐标;选中后由 NodeCard DOM 端口接管。
|
||||
const portR = Math.max(2, 4 / scale)
|
||||
ctx.fillStyle = bg
|
||||
ctx.strokeStyle = border
|
||||
ctx.lineWidth = 1 / scale
|
||||
for (const [px, py] of [[x, y + nh / 2], [x + nw, y + nh / 2]]) {
|
||||
ctx.beginPath(); ctx.arc(px, py, portR, 0, Math.PI * 2); ctx.fill(); ctx.stroke()
|
||||
}
|
||||
void accent
|
||||
}
|
||||
}
|
||||
|
||||
+2
-23
@@ -14,29 +14,8 @@
|
||||
const batchSourcesById = batchSourcesMap
|
||||
for (const n of nodes) {
|
||||
if (!visibleIds.has(n.id)) continue
|
||||
// Canvas V3 P1:未选中的 ref 节点只保留透明 hit proxy,视觉由 canvas 画;选中后恢复完整 NodeCard。
|
||||
if (canvasV3On && n.type === 'ref' && !sel.includes(n.id)) {
|
||||
nodeEls.push(el('div', {
|
||||
key: n.id,
|
||||
className: 'iwb-node-hit-proxy',
|
||||
'data-node-id': n.id,
|
||||
style: { transform: 'translate(' + n.x + 'px, ' + n.y + 'px)', width: nodeWidth(n) + 'px', height: hOf(n) + 'px' },
|
||||
onPointerDown: (e) => {
|
||||
if (e.button !== 0) return
|
||||
e.stopPropagation()
|
||||
const curSel = selRef.current
|
||||
const ids = (e.shiftKey || e.metaKey || e.ctrlKey)
|
||||
? (curSel.includes(n.id) ? curSel.filter((x) => x !== n.id) : curSel.concat([n.id]))
|
||||
: (curSel.includes(n.id) ? curSel.slice() : [n.id])
|
||||
const start = {}
|
||||
for (const x of refs.nodes) if (ids.includes(x.id)) start[x.id] = { x: x.x, y: x.y }
|
||||
refs.bodyDown = { id: n.id, ids, start, sx: e.clientX / uiZoom(), sy: e.clientY / uiZoom(), active: false }
|
||||
setSel(ids)
|
||||
},
|
||||
onDoubleClick: (e) => { e.stopPropagation() },
|
||||
}, null))
|
||||
continue
|
||||
}
|
||||
// Canvas V3:未选中的 ref 节点完全由 canvas 画,DOM 不挂 NodeCard;点击走 canvas 命中测试。
|
||||
if (canvasV3On && n.type === 'ref' && !sel.includes(n.id)) continue
|
||||
// 细粒度:只传该节点相关的 busy/progress/connTarget(其他节点引用稳定,memo 跳过)
|
||||
let busySelf = nodeDerived.busyById.get(n.id) || EMPTY_OBJ
|
||||
let progSelf = nodeDerived.progById.get(n.id) || EMPTY_OBJ
|
||||
|
||||
Reference in new issue
Block a user