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

drag-handler

v0.2.3

Published

Performant mouse/touch event wrapper for handling drag and swipe interactions

Readme

Drag Handler

A tiny (1kb gzipped), high-performance, zero-dependency mouse/touch event wrapper for handling drag interactions. Useful for creating drag and drop interactions or detecting swipes on a touch device. Inspired by Matt Hinchliffe.

Installation

npm i drag-handler --save

Usage

import { createDragHandler } from 'drag-handler'

// Get a target element
let targetElement = document.getElementById('hasDragEvents');

// Create the handler by passing the element to createDragHandler
let handler = createDragHandler(targetElement);

// Attach event listeners
handler.on('dragstart' (e: CustomEvent<DragGesture>) => {
	// Do something at the start of the drag
});

handler.on('drag' (e: CustomEvent<DragGesture>) => {
	// Do something during the drag interaction
});

handler.on('dragend' (e: CustomEvent<DragGesture>) => {
	// Do something at the end of the drag
});

Handler.on Arguments

|Name|Type|Description |--|--|--| |eventName| string| The event name to listen for |callback| function| The event listener callback function

Handler Event Names

|Name|Description |--|--| |"dragstart"| Triggered on the initial touchstart/mousedown event |"drag"| Triggered between dragstart and dragend when the pointer position moves |"dragend"| Triggered on the next touchend/mouseup event, when the drag is finished

Handler Event Details

Each handler event will include a DragGesture object as the event details. This object contains several pieces of information about the drag event.

handler.on('drag' (e: CustomEvent<DragGesture>) => {
	let { distance, direction, position, timeStamp, velocity } = e.details;
});

DragGesture

|Property|Type|Description |--|--|--| |direction| object|The direction of the drag from the previous gesture |distance| object|The horizontal and vertical distance from the first gesture |elementPoint| object| The position of the drag event relative to the element |windowPoint| object| The position of the drag event relative to the window |timeStamp| number| The event timestamp in milliseconds |velocity| object| The velocity of the drag from the previous gesture

DragGesture.direction

|Property|Type|Description |--|--|--| |x| string, null| If not null, the horizontal direction as a string "left" or "right" |y| string, null| If not null, the vertical direction as a string "up" or "down"

DragGesture.distance

|Property|Type|Description |--|--|--| |x| number| The horizontal distance from the first event in px |y| number| The vertical distance from the first event in px

DragGesture.elementPoint

|Property|Type|Description |--|--|--| |x| number| The horizontal coordinate of the touch/mouse event relative to the element |y| number| The vertical coordinate of the touch/mouse event relative to the element

DragGesture.windowPoint

|Property|Type|Description |--|--|--| |x| number| The horizontal coordinate of the touch/mouse event relative to the page |y| number| The vertical coordinate of the touch/mouse event relative to the page

DragGesture.velocity

|Property|Type|Description |--|--|--| |x| number| The horizontal velocity of the gesture |y| number| The vertical velocity of the gesture

Example Usages

Dragging and dropping an element

import { createDragHandler } from 'drag-handler'

let draggable = document.getElementById('myDraggableElement');
let handler = createDragHandler(draggable);

handler.on('drag' (e: CustomEvent<DragGesture>) => {
	let { x, y } = e.details.distance;
	draggable.style.transform = `translate3d(${x}px, ${y}px, 0)`;
});

Dragging and swiping horizontal carousel slides

import { createDragHandler } from 'drag-handler'

let carousel = new ExampleCarouselLibrary('#myCarousel');
let handler = createDragHandler(carousel.viewport as HTMLElement);
let paginationDistance = carousel.width() / 3;

handler.on('drag' (e: CustomEvent<DragGesture>) => {
	let { x } = e.details.distance;
	carousel.activeSlide.style.transform = `translate3d(${x}px, 0, 0)`;
});

handler.on('dragend' (e: CustomEvent<DragGesture>) => {
	if(Math.abs(e.details.distance.x) > paginationDistance) {
		let direction = e.details.direction.x;
		if(direction === 'left') carousel.slideNext();
		if(direction === 'right') carousel.slidePrevious();
	} else {
		carousel.activeSlide.style.transform = 'none';
	}
});

License - MIT