npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@affino/menu-core

v1.1.0

Published

Framework-agnostic headless menu engine with smart mouse prediction, keyboard navigation, and nested submenus

Readme

@affino/menu-core

Headless menu engine for deterministic open/close state, keyboard navigation, submenu intent handling, and ARIA props.

Use this package when you need menu behavior without framework lock-in.

Installation

pnpm add @affino/menu-core

Public exports

import {
  MenuCore,
  SubmenuCore,
  createMenuTree,
  computePosition,
  MousePrediction,
  predictMouseDirection,
} from "@affino/menu-core"

Core contracts

MenuCore

const menu = new MenuCore(
  {
    id: "file-menu",
    closeOnSelect: true,
    loopFocus: true,
    openDelay: 80,
    closeDelay: 120,
  },
  {
    onSelect: (itemId, menuId) => {},
    onHighlight: (itemId, menuId) => {},
  },
)

Primary methods:

  • open(reason?)
  • close(reason?)
  • requestClose(reason?)
  • toggle()
  • subscribe(listener)
  • getSnapshot()
  • registerItem(id, { disabled? })
  • getTriggerProps()
  • getPanelProps()
  • getItemProps(id)
  • highlight(id | null)
  • moveFocus(1 | -1)
  • select(id)
  • destroy()

SubmenuCore

const submenu = new SubmenuCore(menu, {
  parentItemId: "file-export",
  closeOnSelect: true,
})

Additional submenu methods:

  • setTriggerRect(rect | null)
  • setPanelRect(rect | null)
  • recordPointer({ x, y })

SubmenuCore coordinates with parent menu tree and pointer-intent prediction.

createMenuTree

const tree = createMenuTree({ options: { id: "root-menu" } })

const root = tree.root
root.registerItem("file")

const fileSubmenu = tree.createSubmenu({
  parent: root,
  parentItemId: "file",
})

const release = root.subscribe((state) => {
  // render
})

release.unsubscribe()
tree.destroy()

Branch wrapper (MenuTreeBranch) exposes a stable facade:

  • getSnapshot(), subscribe(...)
  • getTriggerProps(), getPanelProps(), getItemProps(id)
  • registerItem(id, options?)
  • open/close/toggle/highlight/moveFocus/select
  • geometry / pointer adapters for submenu branches
  • destroy()

Failure contract:

  • createSubmenu({ parentItemId }) throws if parentItemId is not registered in parent menu.
  • Expected error: Cannot create submenu for unregistered parent item "<id>". Register the parent item before calling createSubmenu().

Adapter responsibilities

menu-core owns:

  • state transitions (open/close/highlight/select),
  • keyboard semantics,
  • ARIA prop contracts,
  • submenu intent logic.

Adapter owns:

  • DOM/render lifecycle,
  • element measurement and positioning application,
  • styling/animation,
  • cleanup on unmount.

Guardrails (anti-misuse)

  • Keep one canonical menu state source (subscribe -> adapter state).
  • Register items with stable ids and call unregister callbacks on unmount.
  • Bind returned props as-is; avoid mixing conflicting custom key handlers in the same phase.
  • For submenus, register parent item id before createSubmenu(...) call.
  • Feed recordPointer + geometry only for submenu contexts; root menus do not need it.
  • Always call destroy() for every MenuCore/SubmenuCore/tree branch.

Positioning

computePosition is re-exported from @affino/surface-core:

const position = computePosition(anchorRect, panelRect, {
  placement: "bottom",
  align: "start",
  gutter: 8,
  viewportPadding: 12,
})

Overlay integration

MenuCore can integrate with @affino/overlay-kernel via:

  • overlayManager
  • getOverlayManager
  • overlayKind
  • overlayEntryTraits

When using overlay kernel, pointer/keyboard close reasons are mediated through overlay manager before local close.

Related packages

  • @affino/menu-laravel
  • @affino/menu-vue
  • @affino/menu-react