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

@smart-overflow/core

v0.1.1

Published

A tiny framework-agnostic TypeScript engine for responsive toolbars, tabs, menus and action bars.

Readme

SmartOverflow

A tiny framework-agnostic TypeScript engine for responsive toolbars, tabs, menus, breadcrumbs and action bars.

SmartOverflow is not a UI component. It does not render buttons, dropdowns, portals, animations or CSS. It only answers one question:

Given item widths and container width, which items stay visible and which move into “More”?

That makes the package easy to use with Vue, React, Svelte, Solid, Web Components, vanilla TypeScript or any internal design system.

Why this exists

Frontend products often need an action row like this:

[Edit] [Delete] [Duplicate] [Export] [Share] [Archive]

When the container shrinks, the least important actions should move into a stable overflow menu:

[Edit] [Delete] [More]

Most implementations end up as fragile component-specific logic. SmartOverflow keeps the difficult part — deterministic overflow calculation — in a small, typed, tested core.

Features

  • Framework-agnostic, headless TypeScript core
  • Zero runtime dependencies
  • Pure deterministic calculateOverflow() function
  • Optional stateful SmartOverflowEngine
  • Priority-based or order-based collapse strategies
  • Pinned items that never intentionally move into overflow
  • Handles overflow indicator width and CSS gaps
  • Fully typed public API
  • Unit test suite with high coverage thresholds
  • Playwright e2e demo tests
  • CI and npm release workflow prepared for trusted publishing/provenance

Installation

npm install smart-overflow

Until you publish the package, install locally from the generated tarball or workspace folder:

npm install ./smart-overflow

Quick start

import { calculateOverflow } from 'smart-overflow';

const result = calculateOverflow({
  containerWidth: 260,
  overflowIndicatorWidth: 64,
  gap: 8,
  strategy: 'priority',
  items: [
    { id: 'edit', width: 48, priority: 100, pinned: true },
    { id: 'delete', width: 64, priority: 80 },
    { id: 'duplicate', width: 92, priority: 40 },
    { id: 'export', width: 72, priority: 60 },
    { id: 'archive', width: 80, priority: 10 },
  ],
});

console.log(result.visibleIds); // ['edit', 'delete']
console.log(result.hiddenIds); // ['duplicate', 'export', 'archive']

In your UI layer, render visibleIds in the main row and hiddenIds inside your own dropdown/menu/popover.

Core API

calculateOverflow(input)

Pure function. It performs no DOM reads, no DOM writes, no observers, no timers and no network calls.

import { calculateOverflow, type CalculateOverflowInput } from 'smart-overflow';

const input: CalculateOverflowInput = {
  containerWidth: 320,
  overflowIndicatorWidth: 64,
  gap: 8,
  minVisibleItems: 1,
  strategy: 'collapse-end',
  items: [
    { id: 'overview', width: 88 },
    { id: 'settings', width: 96 },
  ],
};

const result = calculateOverflow(input);

Input

| Field | Type | Default | Description | | --- | --- | --- | --- | | containerWidth | number | required | Available inner width of the container in CSS pixels. | | items | SmartOverflowItem[] | required | Items in visual order. | | overflowIndicatorWidth | number | 0 | Width of your “More” button. Counted only when at least one item is hidden. | | gap | number | 0 | Gap between visible items and between last visible item and “More”. | | minVisibleItems | number | 0 | Minimum number of non-pinned items to keep visible when possible. | | strategy | 'collapse-end' \| 'collapse-start' \| 'priority' | 'collapse-end' | How the engine chooses the next hideable item. |

Item

export type SmartOverflowItem<TMeta = unknown> = {
  id: string | number;
  width: number;
  priority?: number;
  pinned?: boolean;
  meta?: TMeta;
};

priority is used only with strategy: 'priority'. Higher priority means “keep this item visible longer”. Ties are collapsed from the end to match common toolbar behavior.

pinned means the item is never intentionally hidden. If pinned items alone cannot fit, SmartOverflow reports isOverflowing: true and remainingOverflowWidth.

Result

export type SmartOverflowResult<TMeta = unknown> = {
  visibleItems: SmartOverflowPlacement<TMeta>[];
  hiddenItems: SmartOverflowPlacement<TMeta>[];
  visibleIds: Array<string | number>;
  hiddenIds: Array<string | number>;
  overflowIndicatorVisible: boolean;
  usedWidth: number;
  isOverflowing: boolean;
  remainingOverflowWidth: number;
  options: {
    containerWidth: number;
    overflowIndicatorWidth: number;
    gap: number;
    minVisibleItems: number;
    strategy: SmartOverflowStrategy;
  };
};

Stateful engine

For apps that already own measurements but want a small observable store:

import { SmartOverflowEngine } from 'smart-overflow';

const engine = new SmartOverflowEngine({
  containerWidth: 320,
  overflowIndicatorWidth: 64,
  gap: 8,
  items,
});

const unsubscribe = engine.subscribe((result) => {
  renderToolbar(result.visibleIds, result.hiddenIds);
});

engine.patch({ containerWidth: 240 });
unsubscribe();
engine.destroy();

Measuring items in a real UI

SmartOverflow expects measured widths. Keep measurement in your app/design-system layer:

const items = Array.from(toolbar.querySelectorAll('[data-action-id]')).map((element) => ({
  id: element.getAttribute('data-action-id')!,
  width: element.getBoundingClientRect().width,
}));

const result = calculateOverflow({
  containerWidth: toolbar.clientWidth,
  overflowIndicatorWidth: moreButton.getBoundingClientRect().width,
  gap: 8,
  items,
});

Recommended production pattern:

  1. Measure after fonts and layout are ready.
  2. Recalculate on ResizeObserver events.
  3. Debounce only if your UI causes heavy re-rendering.
  4. Keep the “More” button measurable even when not rendered, or cache its width.
  5. Use stable id values and render output in original order.

Demo

npm install
npm run demo

The demo is intentionally vanilla TypeScript. It proves that the core works without Vue/React adapters.

Tests

npm run test:unit
npm run test:e2e
npm run check
  • Unit tests validate pure algorithm behavior and engine subscriptions.
  • E2E tests run the Vite demo in Chromium and verify real responsive behavior.
  • Coverage thresholds are configured in vitest.config.ts.

Package quality

The repository includes:

  • strict TypeScript config
  • ESLint flat config
  • Prettier config
  • GitHub Actions CI
  • release workflow for npm trusted publishing/provenance
  • Dependabot config
  • security policy
  • contributing guide
  • issue templates
  • changelog

License

MIT