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

@snap-engine/snapsort

v0.4.2

Published

Core TypeScript logic for drag-and-drop system

Readme

@snap-engine/snapsort

Core TypeScript logic for SnapEngine drag-and-drop interactions.

A single Container/Item class pair; each container picks its drag behavior with config.mode: "euclidean" (default), "progressive", "insertion", or "swap".

Install

npm install @snap-engine/snapsort @snap-engine/core

Includes

  • Container
  • Item
  • DragSession
  • Event types: ItemInsertEvent, ItemRemoveEvent, ItemMoveEvent, ItemSwapEvent, GhostCreateEvent, GhostInsertEvent, GhostRemoveEvent, DragStartEvent, DragEndEvent, DropTargetChangeEvent, CanDropEvent, DragLocation
  • ContainerCallbacks, ContainerConfig, SortMode, SortStrategy

Usage

import { Container, Item } from "@snap-engine/snapsort";

const container = new Container(engine, parent, { mode: "insertion" });

DOM ownership contract

SnapSort core is designed to work identically across Vanilla JS, Svelte, React, and any future framework adapter. That only works if core and the framework never fight over the same DOM nodes. The contract:

  1. The framework owns the DOM tree. Core never inserts, removes, or reparents an element the framework rendered. All structural intent flows through ContainerCallbacks (onItemMove, onItemInsert, onItemRemove, onGhostInsert, onGhostRemove), which carry everything an adapter needs (index, beforeElement, ghostRect, metadata). The default callback implementations in mutation.ts are the "vanilla JS adapter" — legitimate defaults when no framework owns the DOM, not a parallel mutation path.
  2. Core writes only non-structural properties on the dragged element — transform, position/z-index styles. Every framework tolerates that; none diffs inline styles it didn't set.
  3. Framework mutations commit synchronously. Core runs structural callbacks inside flushMutation(mutation). React and Svelte adapters provide this transaction automatically, committing state and DOM before core performs its final geometry read and writes the inverse FLIP transform.
  4. After flushMutation, the framework's DOM is the truth. Core resolves elements lazily from item identity (findItemByKey), revalidates them with isConnected, and verifies placement. It never silently repairs adapter output, since that would mask an integration bug.

awaitMutation remains deprecated for compatibility. Promise-returning mutation waits are not paint-atomic and are not supported by the FLIP path.

A concrete consequence: the dragged element stays in its original DOM parent for the entire drag. It never gets reparented into whichever container is currently hovered — it's moved only by transform, computed against a coordinate parent frozen at drag start. This is what lets the React adapter stay thin (no DOM snapshot/restore bookkeeping): React's reconciler never observes a node outside the parent it rendered it under.

Accepted trade-offs

  • Clipping/stacking: an overflow: hidden ancestor can clip the dragged element, and a FLIP-transformed ancestor becomes a stacking context, so the dragged item (z-index: 1000) can paint under a later sibling while that ancestor is mid-animation. Avoid overflow: hidden on draggable surfaces if this matters for your layout.
  • Original parent unmounted mid-drag: if the framework unmounts the dragged item's parent while a drag is in flight, the dragged element goes with it (the framework owns that subtree). dragEnd still commits state via onItemMove/onItemInsert, so application state recovers even though the visual drag ends abruptly.
  • Inner scroll containers: core does not track scroll offsets. Dragging within a container that itself scrolls mid-drag is unhandled today (this predates the ownership contract and is a separate, open limitation).