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

behaviour-primitive

v1.0.3

Published

103 framework‑agnostic behaviour primitive – SSR‑safe, TypeScript, zero dependencies

Readme

Framework‑Agnostic Behaviour Primitives

A collection of 103 behaviour primitives – reusable, framework‑agnostic functions and classes that solve common web interaction problems: focus management, dynamic positioning, gesture recognition, drag & drop, virtual scrolling, keyboard navigation, selection, autocomplete, accessibility, and more.

This is not a UI component library. It provides no buttons, no modals, no dropdowns.
Instead, it gives you the reliable building blocks to implement those components yourself – in React, Vue, Svelte, Angular, or vanilla JavaScript.

📖 Live documentation & interactive demos:
https://adnenre.github.io/behaviour-primitive/

📦 Installation

npm install behaviour-primitive

or using pnpm:

pnpm add behaviour-primitive

🚀 Quick Start

Import a primitive by name and use it directly:

import { TabTrap } from "behaviour-primitive";

const modalElement = document.getElementById("my-modal");
const focusTrap = new TabTrap(modalElement);
focusTrap.activate(); // Now Tab key cycles only inside the modal

🧩 What is a “behaviour primitive”?

A behaviour primitive is a pure logic unit that implements a specific interaction pattern:

  • Trap keyboard focus inside a modal → TabTrap
  • Keep a tooltip attached to a button while scrolling → AutoUpdater
  • Detect a two‑finger rotation gesture → RotateDetector
  • Manage a dynamic array of form fields → FieldArray

You bring the DOM elements and your own styling. We bring the battle‑tested, accessible, framework‑independent behaviour.

📦 What’s inside?

103 primitives organised into 11 categories:

  • Focus Management (8)
  • Dynamic Positioning (10)
  • Gesture & Touch Recognition (9)
  • Drag & Drop (9)
  • Virtual & Advanced Scrolling (7)
  • Keyboard Navigation (5)
  • Selection & List Management (7)
  • Autocomplete & Typeahead (5)
  • UI State & Transitions (7)
  • Accessibility Helpers (4)
  • Infrastructure & Utilities (34)

See the full list in the documentation site linked above.

🛠️ Usage Examples

Focus Trap

import { TabTrap, FocusLock } from "behaviour-primitive";

const modal = document.getElementById("modal");
const trap = new TabTrap(modal);
trap.activate();

Dynamic Positioning with AutoUpdater

import { AutoUpdater } from "behaviour-primitive";

const tooltip = document.getElementById("tooltip");
const button = document.getElementById("button");

function positionTooltip() {
  const rect = button.getBoundingClientRect();
  tooltip.style.top = rect.bottom + 5 + "px";
  tooltip.style.left = rect.left + "px";
}

const updater = new AutoUpdater(positionTooltip, { scroll: true, resize: true });
updater.start();

Gesture Detection

import { SwipeDetector } from "behaviour-primitive";

const element = document.getElementById("swipe-area");
const detector = new SwipeDetector(element, (direction) => {
  console.log(`Swiped ${direction}`);
});

🌐 Framework‑agnostic design

All primitives are written in plain TypeScript and do not depend on any framework. Use them wherever JavaScript runs:

  • React – call primitives inside useEffect or event handlers.
  • Vue – use inside mounted or setup with ref.
  • Svelte – call within onMount or actions.
  • Angular – use inside directives or components.
  • Vanilla JS – directly in your script.

♿ Accessibility

Every primitive is built with accessibility in mind:

  • ARIA roles and attributes (where applicable)
  • Keyboard navigation support (Tab, Enter, Escape, Arrow keys)
  • Focus management (trapping, restoring, redirecting)
  • Screen reader announcements via live regions

📖 Full Documentation

Interactive demos and detailed documentation for every primitive are available at:
👉 https://adnenre.github.io/behaviour-primitive/

You can also browse the source code in src/primitives/ on GitHub.

🤝 Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.

📄 License

MIT

🙏 Acknowledgements

Inspired by real‑world UI problems encountered while building component libraries without a framework.
This project focuses on how things behave, not how they look.