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

zoom.ts

v8.0.0

Published

A lightweight TypeScript library for image zooming, as seen on Medium.

Downloads

198

Readme

Installation

Install the package via npm:

npm install --save zoom.ts

Usage

The example directory contains the code used to demonstrate an application with zoom.ts installed.

Static Site

To integrate zoom.ts into a static site, import the UMD module and interface with the library via the global window.zoom. The snippet below demonstrates linking the bundle (dist/zoom.js) and the stylesheet (dist/zoom.css). It then calls the listen function to add an event listener to the document.body when the page is ready.

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="dist/zoom.css">
    <script type="text/javascript" src="dist/zoom.js"></script>
    <script>window.zoom.listen();</script>
  </head>

  <body>
    <img
      class="zoom__image"
      src="tower.jpeg"
      data-width="2048"
      data-height="1366"
      data-src="tower-full.jpeg"
    />
  </body>
</html>

Application

To integrate zoom.ts into a web application, follow the steps outlined below:

  1. Detect and store the Features of the document.body.style
  2. Locate the element you wish to make zoomable
  3. Register a ZoomListener on the target image
  4. In the listener's callback, create and store a Zoom instance
  5. Call expand on the Zoom instance to begin zooming the image
  6. If the user navigates to a different page in the application, call destroy on the Zoom instance

The snippet below demonstrates finding the first element with the zoom__image class and adding a ZoomListener to any click events it fires. When fired, the event listener will create a Zoom instance and store it as a variable named zoom, then immediately expand the image. After 5 seconds have passed, the zoom will be forcefully removed via the call to destroy.

import { Features, Zoom, ZoomDOM, ZoomListener } from 'zoom.ts';

let features = Features.of(document.body.style); // (1)
let image = document.querySelector('.zoom__image'); // (2)

image.addEventListener('click', new ZoomListener((dom) => { // (3)
    let zoom = new Zoom(dom, features); // (4)
    
    zoom.expand(); // (5)
    
    setTimeout(() => {
        zoom.destroy(); // (6)
    }, 5000);
}));

Contributing

Bug reports and pull requests are welcome on GitHub.

License

This project is available under the terms of the ISC license. See the LICENSE file for the copyright information and licensing terms.