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

gesture-frame

v2.0.1

Published

A Web Component that supports `pinch-zoom` and `pan` for PC and Touch Devices.

Downloads

550

Readme

<gesture-frame>

A Web Component that supports pinch-zoom and pan for PC and touch devices.

Demo: https://luncheon.github.io/gesture-frame/

Installation

npm i gesture-frame

Usage

<link rel="stylesheet" href="gesture-frame/gesture-frame.css">
<script type="module" src="gesture-frame/gesture-frame.js"></script>

<gesture-frame pan-x pan-y pinch-zoom min-scale="0.01" max-scale="1000" scale="2" offset-x="20" offset-y="20">
  <!-- Content -->
</gesture-frame>

or using module bundler:

import 'gesture-frame/gesture-frame.css';
import 'gesture-frame/gesture-frame.js';

const gestureFrame = document.createElement('gesture-frame');
gestureFrame.pinchZoom = true;
gestureFrame.minScale = 0.01;
gestureFrame.fit({ marginX: 20, marginY: 20 });

If you use TypeScript with import elision and need the custom element type, import it separately.

See:

import { GestureFrame } from 'gesture-frame';
import 'gesture-frame/gesture-frame.css';
import 'gesture-frame/gesture-frame.js'; // when *import elision* is disabled, this line is not necessary.

// type usage
const gestureFrame: GestureFrame = document.createElement('gesture-frame');

// constructor usage
if (gestureFrame instanceof GestureFrame) {
}

HTML Attributes and DOM Element Properties

States (auto-updated by panning and zooming)

| HTML Attribute | DOM Element Property | Default | Description | | -------------- | -------------------- | ------- | ------------ | | scale | scale | 1 | Scale. | | offset-x | offsetX | 0 | Left margin. | | offset-y | offsetY | 0 | Top margin. |

These attributes can be observed using MutationObserver.

Options

| HTML Attribute | DOM Element Property | Default | Description | | ------------------------ | -------------------- | ------- | ----------------------------------------------------------------------------------------------- | | min-scale | minScale | 0.1 | Minimum scale. | | max-scale | maxScale | 100 | Maximum scale. | | pan-x (existence) | panX | false | Whether horizontal panning is enabled. | | pan-y (existence) | panY | false | Whether vertical panning is enabled. | | pinch-zoom (existence) | pinchZoom | false | Whether two-finger panning and zooming is enabled. For PC, follows Ctrl + Wheel events. | | pan-button | panButton | 0 | Mouse button for panning on PC. | | anchor-leftanchor-rightanchor-topanchor-bottom(existence) | anchorLeftanchorRightanchorTopanchorBottom | falsefalsefalsefalse | Edges to which the content is bound. When the element is resized, the content is resized while keeping the distance from the bound edges.* Only up to three anchors can be set; if all anchors are set, only the left and right anchors will be enabled. |

DOM Element API

fit(options?: { marginX?: number, marginY?: number }): void

Adjust the scale and offset to display the entire content.

fitX(options?: { margin?: number }): void

Adjust the scale and offset-x to fit the width.

fitY(options?: { margin?: number }): void

Adjust the scale and offset-y to fit the height.

zoom(scaleRatio: number, origin?: { x?: number | `${number}%`, y?: number | `${number}%`): void

Zoom keeping the apparent position of (origin.x, origin.y). Zoom in when scaleRatio > 1 and zoom out when scaleRatio < 1. origin.x and origin.y can be specified as a number (px) or a `${number}%`. The default value for both is "50%" (center).

License

WTFPL

Similar Libraries

  • https://github.com/GoogleChromeLabs/pinch-zoom
  • https://github.com/worka/vanilla-js-wheel-zoom