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

most-gestures

v0.4.1

Published

unified desktop/mobile high level pointer gestures, using most.js

Downloads

1,050

Readme

most-gestures

GitHub version experimental Build Status Dependency Status devDependency Status

unified desktop/mobile high level pointer gestures, using most.js

This is a set of pointer gesture helpers, unifying pointer apis accross browsers & mobile/desktop works (and manually tested ) in :

  • Chrome (desktop & mobile, MacOS & Android)
  • Firefox
  • Safari (desktop & mobile , MacOs & IOS)
  • Ios & Android web views

It

  • is coded in es6
  • uses most.js observables
  • provides relatively high level tools : ie taps, zooms , drags

Table of Contents

Installation

npm install most-gestures

Usage

import {pointerGestures} from 'most-gestures'

const element = document.getElementById("foo")
const gestures = pointerGestures(element)

//or alternatively
const element = document.getElementById("foo")
const baseInteractions = baseInteractionsFromEvents(element)
const gestures = pointerGestures(baseInteractions)

//now you can use:
/*gestures.taps : tap/click once & release quickly
gestures.drags: press, keep pressed & move around
zooms: mouse wheel & pinch zoom alike
pointerMoves: simple moves
*/

//each one of those is an observable , so to react on taps you can do:
gestures.taps.forEach(function(e){
  console.log('tapped',e)
  })

API

the module exposes two main functions:

baseInteractionsFromEvents(element)

this creates an object containing the low level streams (mouseDowns$, mouseUps$ etc) from a DOM element, you usually don't want to use this directly, use the following function instead.

options allows you to refine the gestures by modifying the following parameters:

Note: these will also get passed along correctly if set on the pointerGestures function below

  • passiveEventsHandlers: true: Whenever possible make event listeners passive (see here https://developers.google.com/web/updates/2016/06/passive-event-listeners for more details)
  • preventScroll: true : Prevent all forms of scrolling on the target element
  • preventMenu: true: Prevent default right click menu on the target element

pointerGestures(baseInteractionsOrElement, options)

you can either pass in a reference to a dom element or the output from baseInteractionsFromEvents(element)

what you are likely interested in, is pointerGestures:

  • gestures.presses (used as a basis for the two below)
  • gestures.taps : quick press/tap & release
  • gestures.holds : press/tap for a long time (defined by the longPressDelay)& release
  • gestures.drags : press & move before releasing
  • gestures.zooms : pinch , scrollwheel etc

they are all observables , so the power is yours !

options allows you to refine the gestures by modifying the following parameters:

  • multiTapDelay: time in ms between multiple taps
  • longPressDelay (default: 250) : time in ms after which a HOLD is emitted
  • maxStaticDeltaSqr (default: 100): maximum delta (in pixels squared) above which we consider a pointer to have moved
  • zoomMultiplier: (default: 200): zoomFactor for normalized interactions across browsers
  • pinchThreshold: (default: 4000) The minimum amount in pixels squared the inputs must move until it is fired.
  • pixelRatio : (default: window.pixelRatio if available)

examples :

gestures.drags.forEach(function(e){
  console.log('dragged',e)
  })

custom gestures:

you can also easily define your custom gestures, based on the existing ones: using map, filter etc on the observables

const singleTaps$ = taps$.filter(x => x.nb === 1).map(e => e.list).map(e => e[0])
const doubleTaps$ = taps$.filter(x => x.nb === 2).map(e => e.list).map(e => e[0])

Contribute

PRs accepted.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

The MIT License (MIT) (unless specified otherwise)