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

touch-sampler

v0.0.4

Published

A lightweight manager for user interaction with an animated HTML element

Downloads

11

Readme

touch-sampler

tests

A lightweight manager for user interaction with an animated HTML element.

touch-sampler records information about mouse or touch interaction with an HTML element, and reports that information when requested. This enables the calling program to sample user interactions when it is ready for them, rather than having to handle them as they occur.

This on-demand reporting of interactions is useful for animations based on physical modeling. In these animations, the physical state (velocity, acceleration, etc) is updated once per frame, at typical frame rates of 60 frames per second.

At each frame, the updated physical state depends on both the state from the previous frame, and any user interactions that have occured between the last and current frames. These interactions are reported to the program by DOM events, which can fire at arbitrary times, not in sync with the frame rate. touch-sampler helps keep track of these events by storing information about them until the next frame, when the main program is ready to use them.

Check out the simple example of touch-sampler being used to interactively update a Canvas transform.

Usage

import { initTouch } from "touch-sampler";

const cursor = initTouch(HTMLElement);

initTouch takes one argument: the HTML element on which mouse or touch events will be detected. initTouch returns a cursor object with methods to query and reset the stored information.

At each frame refresh, the calling code should:

  1. Retrieve information about the cursor state, via cursor.touchStarted(), etc
  2. Reset the state flags for the next call, via cursor.reset()

For details about the API, see src/cursor.js