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

@techzunction/collide.js

v1.0.0

Published

IntersectionObserver for any two elements — proximity, collision, and time-to-collision detection for the DOM

Readme

collide.js

IntersectionObserver for any two elements.

Proximity, collision, and time-to-collision detection for the DOM. Tiny, shape-agnostic, TypeScript-first.


Why collide.js?

The browser gives you IntersectionObserver — but only against the viewport (or one ancestor). There's nothing built-in for "is this element near, or hitting, that other element?"

collide.js fills that gap. It's ~2KB, has zero deps, and uses a single shared RAF loop to batch all observer reads.


Quick Start

<script src="https://cdn.jsdelivr.net/npm/@techzunction/collide.js"></script>
<script>
  const pair = Collide.watch(cardA, cardB, { near: 80 });
  pair.on('near',     (m) => console.log('near:', m.distance, 'px'));
  pair.on('collide',  (m) => console.log('hit:', m.overlap));
  pair.on('separate', ()  => console.log('clear'));
</script>

Or with a bundler:

npm install @techzunction/collide.js
import Collide from '@techzunction/collide.js';

API

Collide.watch(a, b, opts?) → Pair

Watch two elements. Emits near, collide, separate, leave, tick.

const pair = Collide.watch(el1, el2, {
  near: 60,           // px threshold for 'near' event (default 60)
  shape: 'aabb',      // 'aabb' | 'circle' (default aabb)
  trackVelocity: true,// compute velocity + TTC (default true)
});
pair.on('near',    (m) => ...);
pair.on('collide', (m) => ...);
pair.metrics();      // one-off snapshot
pair.destroy();

Metrics shape:

{
  colliding: boolean;
  distance: number;       // min distance between shapes
  overlap: { x, y };      // overlap dimensions when colliding
  centerA, centerB: Vec2;
  direction: Vec2;        // unit vector A → B
  angle: number;          // radians
  velocity: Vec2;         // B relative to A, px/sec
  closingSpeed: number;   // positive = approaching, px/sec
  ttc: number | null;     // time-to-collision in seconds
}

Collide.group(source, targets, opts?) → Group

Watch one element against many targets (drag-to-drop zones).

const g = Collide.group(drag, dropZones, { near: 80 });
g.on('near',    (zone, m) => zone.classList.add('highlight'));
g.on('collide', (zone, m) => commitDrop(zone));
g.closest();  // { target, metrics }

Collide.all(elements, opts?) → All

N×N observer — every pair tested every frame. Great for crowd avoidance, packing.

const a = Collide.all(nodes);
a.on('collide', (a, b, m) => separate(a, b, m.direction));

Collide.check(a, b, opts?) → CollisionMetrics

One-shot check. No observer, no RAF — use for discrete hit-tests.

if (Collide.check(bullet, target).colliding) score();

Collide.shapes(a, b) → CollisionMetrics

Low-level geometry: collide two Shape objects directly. Framework-agnostic.

Collide.shapes(
  { kind: 'aabb', x: 0, y: 0, w: 10, h: 10 },
  { kind: 'circle', cx: 5, cy: 20, r: 4 },
);

Performance

  • Single shared RAF — every observer registers into the same loop. Runtime cost scales with the number of observed pairs, not the number of observer instances.
  • Batched getBoundingClientRect — one read per element per frame, never during event handlers.
  • Auto-stops when idle — the loop pauses when the last observer is destroyed.

License

MIT © TechZunction