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/surface-core

v1.0.0

Published

Framework-agnostic interaction kernel for floating surfaces (menus, tooltips, popovers)

Readme

@affino/surface-core

Headless interaction kernel for any floating surface: menus, tooltips, contextual panels, or popovers.

The package centralizes the primitives that every surface needs:

  • Deterministic open/close state machine
  • Shared timer orchestration (delayed open/close)
  • Pointer-aware helpers for hover/focus driven workflows
  • Geometry utilities (computePosition) for viewport-safe anchoring
  • Callback plumbing with predictable ordering

Adapters like @affino/menu-core or the upcoming tooltip primitives build on top of this package so they can focus on domain-specific behavior (selection, tree coordination, etc.) while sharing the interaction basics.

pnpm add @affino/surface-core
# or
npm install @affino/surface-core

Quick start

import { SurfaceCore } from "@affino/surface-core"

class TooltipCore extends SurfaceCore {
  protected composeState(surface) {
    return surface
  }

  getTriggerProps() {
    return {
      onPointerEnter: () => this.open("pointer"),
      onPointerLeave: () => this.close("pointer"),
    }
  }
}

See packages/menu-core for a full example of composing SurfaceCore with richer selection logic.

Lifecycle

Every controller created from SurfaceCore flows through the same deterministic states:

┌─────────────┐   open() / pointer enter    ┌──────────────┐
│   closed    │ ───────────────────────────▶ │   opening    │
└─────────────┘                             └──────┬───────┘
        ▲                                        timers settle
        │ close() / pointer leave                 │
        │                                         ▼
┌─────────────┐   timers complete / settle   ┌──────────────┐
│  closing    │ ◀─────────────────────────── │    open      │
└─────────────┘                             └──────────────┘
  • open / close always respect the configured openDelay / closeDelay timers.
  • getSnapshot() emits open: true/false the moment timers settle, so adapters can rely on consistent paint timing.
  • Subscribers run in the order they were registered; clean up via subscription.unsubscribe() or destroy().

Diagnostics

Use SurfaceDiagnostics to catch malformed geometry or options before they reach production:

import { SurfaceDiagnostics } from "@affino/surface-core"

SurfaceDiagnostics.configure((message, details) => {
  myLogger.warn(message, details)
})

SurfaceDiagnostics.validatePositionArgs(anchorRect, surfaceRect, options)
  • In development builds the helper warns about missing rects, negative dimensions, or invalid viewport sizes.
  • computePosition() already calls validatePositionArgs(), so you get warnings for free unless you opt out.
  • Provide a custom reporter via configure() to forward diagnostics into your own logging system or tests.

API reference

| Method | Description | | --- | --- | | open(reason?) / close(reason?) / toggle() | Transition the surface with consistent timer semantics. | | getSnapshot() | Returns { open: boolean } or your extended state. | | subscribe(listener) | Receive snapshot updates (returns { unsubscribe }). | | computePosition(anchorRect, surfaceRect, options?) | Resolves { left, top, placement, align } while emitting onPositionChange. | | destroy() | Clears timers + subscriptions; call when disposing custom controllers.

Position options

| Option | Type | Notes | | --- | --- | --- | | gutter | number | Gap between anchor and surface in px (defaults to 4). | | viewportPadding | number | Minimum space to keep from viewport edges. | | placement | "top" | "bottom" | "left" | "right" | "auto" | Preferred side; auto picks the best fit. | | align | "start" | "center" | "end" | "auto" | Horizontal/vertical alignment depending on placement. |

Surface primitives (menus, tooltips, contextual panels) can now share identical timing and pointer semantics while layering on their own domain logic.