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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kjn/svg-pan-zoom

v1.1.6

Published

Easy to use panning and zoom implementation for SVG

Downloads

15

Readme

@kjn/svg-pan-zoom

semantic-release: angular

npm version

Netlify Status

Live Demo

Gif Demo

The simplest panning and zooming library for SVG elements in HTML. The barebone approach leaves everything besides enabling panning and zooming to the user.

This library allows your SVG elements to be both pannable and zoomable instantly without forcing any coding style, patterns, or requirements on the user, the opt-in library approach allows you to seamlessly add zoom and pan features to any SVG element.

How to use

When using npm simply install the dependency and start using it in your projects.

npm install --save @kjn/svg-pan-zoom
OR
yarn add @kjn/svg-pan-zoom

After acquiring the library you can import the class in any way you'd like.

Option 1 (preferred) - using EcmaScript Modules (ESM):

import SvgPanZoom from "@kjn/svg-pan-zoom";

// Adds panning and zooming capabilities to this element.
new SvgPanZoom(document.getElementById("svg"));

Option 2 - using CommonJS modules:

const SvgPanZoom = require("@kjn/svg-pan-zoom");

// Adds panning and zooming capabilities to this element.
new SvgPanZoom(document.getElementById("svg"));

Example:

<!-- script[type=module] allows you to import modules -->
<script type="module">
  import SvgPanZoom from "@kjn/svg-pan-zoom";

  // This will initialise panning and zooming for this svg element.
  new SvgPanZoom(document.getElementById("svg"));
</script>

See the examples directory for more.

API / Docs

Options

The options object knows the following parameters

| Option | Description | | ------ | -------------------------------------------------------------------------- | | logger | Object implementing info, error, warn debug and log as functions |

const options = {
  logger: {
    info: console.info,
    error: console.error,
    warn: console.warn,
    log: console.log,
    debug: console.debug,
  },
};

new SvgPanZoom(element, options);

Events

SvgPanZoom emits events on action. The events that are exposed are:

| Event | Description | | ----- | --------------------------------------------- | | zoom | The zoom level of the svg element has changed | | pan | The panning of the svg element has changed |

const svgPanZoom = new SvgPanZoom(element);
svgPanZoom.on("zoom", (newScale: number) => {
  console.log(`The element is zoomed in ${newScale}x`);
});
svgPanZoom.on("pan", (x: number, y: number) => {
  console.log(`The top left pixel its viewBox is showing [x:${x}, y:${y}]`);
});

Methods / Properties

The methods that are exposed to the user are:

| Method / Property | Description | | -------------------------- | --------------------------------------------------- | | zoom(desiredScale: number) | Allows the user to set the scale the svg element | | scale | Allows the user to get the scale of the svg element |

const svgPanZoom = new SvgPanZoom(element);
svgPanZoom.zoom(0.1); // Increase the zoomlevel by 10%
svgPanZoom.zoom(-0.1); // Decrease the zoomlevel by 10%

console.log("The current scale is: " + svgPanZoom.scale);

Development

Since this is a small project there aren't too many development guidelines. To just mention some things about the philosophy of this repository, please adhere to the following:

  • All functional source-code should reside in the src directory.
  • All project/setup/ non-functional code should reside outside the src directory
  • When making fixes, features or doing any task, create a new commit in line with the conventional commits guidelines
  • Respect the formatting and linting rules

Publishing

This repository is setup to auto-publish new releases using semantic-release. Essentially this boils down to releases being versioned, tagged and published based on the commitlog.