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

use-snapping-konva

v1.1.1

Published

Konva snapping object hook using typescript

Downloads

488

Readme

use-snapping-konva

npm version License: MIT GitHub

A lightweight TypeScript utility for Konva.js that adds smart snapping and visual guidelines when dragging or resizing shapes on a canvas.

Features

  • Snap shapes to the stage center, stage borders, and other shapes
  • Snap to left edge, center, and right edge (horizontal) and top, center, and bottom edges (vertical)
  • Customizable visual snap guidelines with configurable color, thickness, and dash style
  • Works with any Konva stage — no framework required
  • Full TypeScript support

Installation

npm install use-snapping-konva
yarn add use-snapping-konva

Peer dependency: konva >= 8.0.0 must be installed in your project.

Usage

import Konva from "konva";
import { useSnapKonva } from "use-snapping-konva";

const { handleDragging, handleDragEnd, handleResize, handleResizeEnd } = useSnapKonva({
  snapRange: 8,
  guidelineColor: "#00dc82",
  snapToStageCenter: true,
  snapToStageBorders: true,
  snapToShapes: true,
  pageSize: { width: 1920, height: 1080 },
  workspacePadding: 1500,
  onDragEnd: (e) => {
    console.log("Drag ended", e.target.position());
  },
  onResizeEnd: (e) => {
    console.log("Resize ended", e.target.position());
  },
});

// Attach to a draggable shape
shape.on("dragmove", handleDragging);
shape.on("dragend", handleDragEnd);

// Attach to a Konva.Transformer for resize snapping
transformer.on("transform", handleResize);
transformer.on("transformend", handleResizeEnd);

TypeScript

The settings type is exported for use in your own code:

import { useSnapKonva, UseSnapKonvaSettings } from "use-snapping-konva";

const mySettings: Partial<UseSnapKonvaSettings> = {
  snapRange: 10,
  guidelineColor: "red",
};

const handlers = useSnapKonva(mySettings);

API

useSnapKonva(settings?)

Returns an object with four event handlers to attach to Konva nodes.

| Handler | Konva event | Description | |---|---|---| | handleDragging | dragmove | Calculates snapping and draws guidelines while dragging | | handleDragEnd | dragend | Clears all guidelines and invokes onDragEnd callback | | handleResize | transform | Clears guidelines during a resize | | handleResizeEnd | transformend | Clears all guidelines and invokes onResizeEnd callback |

Settings

All settings are optional. Defaults are shown below.

| Option | Type | Default | Description | |---|---|---|---| | snapRange | number | 5 | Distance in pixels within which snapping activates | | guidelineColor | string | "#00dc82" | Color of the snap guideline | | guidelineDash | boolean | true | Whether the guideline is dashed | | showGuidelines | boolean | true | Whether to draw guidelines at all | | guideThickness | number | 1 | Stroke width of the guideline | | snapToStageCenter | boolean | true | Snap to the center of the page | | snapToStageBorders | boolean | true | Snap to the edges of the page | | snapToShapes | boolean | true | Snap to edges and centers of other shapes | | pageSize | { width, height } | { width: 800, height: 600 } | The logical page dimensions | | workspacePadding | number | 1500 | Padding around the page within the stage | | onDragEnd | (e: KonvaEventObject<DragEvent>) => void | undefined | Callback invoked after drag ends and guidelines are cleared | | onResizeEnd | (e: KonvaEventObject<Event>) => void | undefined | Callback invoked after resize ends and guidelines are cleared |

Repository

https://github.com/saroto/UseSnapKonva

License

MIT © Kimsinh Seang

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

This project was inspired by and adapted from the excellent use-konva-snapping by Farid.