Files
NODEDC_DESIGN_GUIDELINE/packages/ui-core/src/menuAim.ts
T
Codex cb534dbe39 feat(ui): add docking, viewport controls and composed settings
Add shared dock layouts, navigation cube, range bands, progress actions and comparison surfaces. Extend toolbar menus and loading composition, and align tokens, registry entries, documentation and the living catalog.
2026-10-29 09:38:25 +03:00

15 lines
1.0 KiB
TypeScript

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)<Math.abs(previous[axis]-edge)-0.1;
}