25 lines
1.2 KiB
JavaScript
25 lines
1.2 KiB
JavaScript
/* 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)
|