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

zoomist

v2.1.1

Published

A TypeScript library for zooming any element. Also supports mobile devices.

Downloads

22,669

Readme

🚀 Installation

There are few ways to import Zoomist into your project:

Install from NPM

You can easily install Zoomist from NPM.

npm i zoomist
// import Zoomist styles
import 'zoomist/css'
// import Zoomist
import Zoomist from 'zoomist'

// initialize
const zoomist = new Zoomist(...)

Using CDN

There are two ways to include Zoomist by using CDN.

UMD:

<!-- styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zoomist@2/zoomist.css" />

<!-- scripts -->
<script src="https://cdn.jsdelivr.net/npm/zoomist@2/zoomist.umd.js"></script>
<script>
  const zoomist = new Zoomist(...)
</script>

ES modules in browser:

<!-- styles -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zoomist@2/zoomist.css" />

<!-- scripts -->
<script type="module">
  import Zoomist from 'https://cdn.jsdelivr.net/npm/zoomist@2/zoomist.js'

  const zoomist = new Zoomist(...)
</script>

Download assets

Or you can use Zoomist locally by DOWNLOAD assets.


📝 Basic usage

After downloading Zoomist, there are a few steps to create a Zoomist:

Add Zoomist HTML layout

You need to add Zoomist layout in your HTML:

<!-- zoomist-container -->
<div class="zoomist-container">
  <!-- zoomist-wrapper is required -->
  <div class="zoomist-wrapper">
    <!-- zoomist-image is required -->
    <div class="zoomist-image">
      <!-- you can add anything you want to zoom here. -->
      <img src="..." />
    </div>
  </div>
</div>

Custom Zoomist styles

You may want to add some custom styles:

.zoomist-container {
  width: 100%;
  max-width: 600px;
}

.zoomist-image {
  width: 100%;
  aspect-ratio: 1;
}

.zoomist-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

Initialize Zoomist

Finally, initialize Zoomist in your js file:

const zoomist = new Zoomist('.zoomist-container', {
  // Optional parameters
  maxScale: 4,
  bounds: true,
  // if you need slider
  slider: true,
  // if you need zoomer
  zoomer: true
})

📖 Documentation

Parameters

All available parameters and initial value:

new Zoomist('.zoomist-container', {
  // set is draggable or not
  draggable: true,
  // set is wheelable or not
  wheelable: true,
  // set is pinchable or not
  pinchable: true,
  // set image stuck on bounds
  bounds: true,
  // the ratio of zooming at one time
  zoomRatio: 0.1,
  // the max scale of zoomist-image (must be number larger then initScale)
  maxScale: 10,
  // the min scale of zoomist-image (must be number smaller then initScale)
  minScale: 1,
  // set initial scale of zoomist-image
  initScale: null,
  // if set to true, enable to release touch events to allow for further page scrolling when .zoomist-image is on bounds.
  dragReleaseOnBounds: false,
  // if set to true, enable to release wheel events to allow for further page scrolling when .zoomist-image is on mixScale or maxScale.
  wheelReleaseOnMinMax: false,
  // elements matched this class will not be dragged.
  disableDraggingClass: '.zoomist-not-draggable',
  // elements matched this class will not be zoomed by mouse wheel.
  disableWheelingClass: '.zoomist-not-wheelable',
  // zoomist slider module
  slider: {
    // the css selector string or a element of the slider
    el: null,
    // the direction of the slider 'horizontal' or 'vertical'
    direction: 'horizontal'
  },
  //
  zoomer: {
    // the wrapper of all zoomer buttons
    el: null,
    // the css selector string or a element for in-zoomer
    inEl: null,
    // the css selector string or a element for out-zoomer
    outEl: null,
    // the css selector string or a element for reset-zoomer
    resetEl: null,
    // in zoomer and out zoomer will be disabled when image comes to maximin or minimum
    disabledClass: 'zoomist-zoomer-disabled'
  }
})

Methods

All available methods:

const zoomist = new Zoomist(...)

zoomist.zoom(ratio)
zoomist.zoomTo(ratio)
zoomist.move({ x, y })
zoomist.moveTo({ x, y })
zoomist.slideTo(value)
zoomist.reset()
zoomist.update(options)
zoomist.destroy(cleanStyle)
zoomist.destroySlider()
zoomist.destroyZoomer()
zoomist.destroyModules()

zoomist.on(event, handler)

zoomist.getImageData()
zoomist.getContainerData()
zoomist.getSliderValue()

zoomist.isOnBoundX()
zoomist.isOnBoundY()
zoomist.isOnBoundTop()
zoomist.isOnBoundBottom()
zoomist.isOnBoundLeft()
zoomist.isOnBoundRight()
zoomist.isOnMinScale()
zoomist.isOnMaxScale()

Events

// Using on parameter before initialization.
const zoomist = new Zoomist('.zoomist-container', {
  on: {
    // invoked when zoomist instance ready
    ready(zoomist) {...},
    // invoked when reset methods be used
    reset(zoomist) {...},
    // invoked when image changes it's size
    resize(zoomist) {...},
    // invoked before destroy methods be used
    beforeDestroy(zoomist) {...},
    // invoked after destroy methods be used
    destroy(zoomist) {...},
    // invoked before update methods be used
    beforeUpdate(zoomist) {...},
    // invoked when update methods be used
    update(zoomist) {...},
    // invoked when image is zooming
    zoom(zoomist, scale) {...},
    // invoked when wheeling
    wheel(zoomist, scale, event) {...},
    // invoked when mousedown on wrapper
    dragStart(zoomist, transform, event) {...},
    // invoked when dragging the image
    drag(zoomist, transform, event) {...},
    // invoked when mouseup on wrapper
    dragEnd(zoomist, transform, event) {...},
    // invoked when mousedown on wrapper
    pinchStart(zoomist, scale, event) {...},
    // invoked when pinching the image
    pinch(zoomist, scale, event) {...},
    // invoked when mouseup on wrapper
    pinchEnd(zoomist, scale, event) {...},
    // invoked when mousedown on slider
    slideStart(zoomist, value, event) {...},
    // invoked when sliding the slider
    slide(zoomist, value, event) {...},
    // invoked when mouseup on slider
    slideEnd(zoomist, value, event) {...}
  }
})

// Using on method after initialization.
// For example:
zoomist.on('zoom', (zoomist, scale) => {...})