/* canvas-v3-hit.js —— Canvas V3 节点命中测试(2026-12-01) * ref: body + 端口;P2 文本节点只做 body,端口先留给选中后的 NodeCard。 */ ;(function (global) { 'use strict' function hitNode (nodes, wx, wy, opts) { const o = opts || {} const isType = typeof o.isType === 'function' ? o.isType : (n) => n && n.type === 'ref' 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 wantPorts = o.wantPorts !== false const list = Array.isArray(nodes) ? nodes : [] for (let i = list.length - 1; i >= 0; i--) { const n = list[i] if (!n || !isType(n)) continue const w = widthOf(n), h = heightOf(n) const cy = n.y + h / 2 if (wantPorts && n.type === 'ref') { 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 } function hitRefNode (nodes, wx, wy, opts) { return hitNode(nodes, wx, wy, Object.assign({}, opts || {}, { isType: (n) => n && n.type === 'ref', wantPorts: true })) } global.IWBCanvasV3Hit = { hitNode, hitRefNode } })(typeof window !== 'undefined' ? window : globalThis)