import type { RectLike } from "./floating.js"; export type MenuPoint = {x:number;y:number}; /** Delay sibling activation only while the pointer advances through the corridor to the open menu. */ export function movingToMenu(origin:MenuPoint, previous:MenuPoint, current:MenuPoint, surface:RectLike):boolean { const horizontal = origin.x < surface.left || origin.x > surface.right; const edge = horizontal ? (origin.x < surface.left ? surface.left : surface.right) : (origin.y < surface.top ? surface.top : surface.bottom); const a = horizontal ? {x:edge,y:surface.top-6} : {x:surface.left-6,y:edge}; const b = horizontal ? {x:edge,y:surface.bottom+6} : {x:surface.right+6,y:edge}; const cross=(p:MenuPoint,q:MenuPoint,v:MenuPoint)=>(q.x-p.x)*(v.y-p.y)-(q.y-p.y)*(v.x-p.x); const signs=[cross(origin,a,current),cross(a,b,current),cross(b,origin,current)]; const inside=signs.every(v=>v>=-0.01)||signs.every(v=>v<=0.01); const axis=horizontal?"x":"y"; return inside && Math.abs(current[axis]-edge)