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

on-paint

v0.5.4

Published

A small library to run any number of actions on every animation frame, meaning these actions will run as fast as your web browser is capable of running them.

Downloads

2,470

Readme

on-paint

A tiny library (approximately 684 bytes) to run any number of actions on every animation frame, meaning these actions will run as fast as your web browser is capable of running them.

Installation

npm install on-paint

or

yarn add on-paint

or

pnpm add on-paint

Usage

See an example for details.

An example action called tether is included in the library to give you an idea what's possible. All included example actions can be viewed by inspecting onPaint.fns.

The tether action can be used to keep an element pinned to the same position as a different reference element.

Why include example code in the library? It's the only example I could think of where using this library is the best way to accomplish something, so it's entirely possible that it'll be the only function you ever need or use.

import onPaint from 'on-paint';

const originalElement = document.getElementById('original');

const placeholderElement = document.getElementById('placeholder');

// Use "tether" function
onPaint.set(onPaint.fns.tether({source: originalElement, target: placeholderElement}));

API

set(action, paused)

Sets an action to be run. An action must be a function.

If paused is set to true, then the action will not immediately be run, otherwise an action will be run as soon as it is set, and will continue to run until otherwise specified.

Calling set(action, paused) will return a unique identifier that can be used to selectively pause/resume/delete this particular action.

delete(actionID)

Deletes an action from the queue. When called, it must be passed the unique identier that is returned from the set action above.

Automatically pauses the execution of onPaint if there are no longer any active actions.

pause(actionID)

Pauses an action, as specified by the unique identifier that is returned from the set action above.

Automatically pauses the execution of onPaint if there are no longer any active actions.

resume(actionID)

Resumes an action, as specified by the unique identifier that is returned from the set action above.

run()

Runs all the actions.

stop()

Stops all the actions from executing, and pauses the execution of onPaint.

clear()

Clears all the actions from memory. Automatically pauses the executionof onPaint.

fns

Returns a object of all the example actions included with the onPaint library.

logPerformance

When set to true, onPaint will log the performance characteristics of every action as it is run and give an average of how long each action takes to perform.

Performance

Wait, so we're running these actions every single frame? Isn't that terrible for overall browser performance?

PROBABLY.

If your actions take too long to run, it's entirely possible that you'll encounter negative effects.

These negative effects can range from:

  • Trivial: Dropping some frames, leading to jank
  • Serious: Tying up the main thread, causing lag between user input and effect
  • Catastrophic: Freezing your browser

In other words, use this library at your own risk.

Ideally you should write performant enough actions that all of them are capable of being run in less than 1/60th of a second (or approximately 16ms).

You should also ensure that you either pause or delete every action that you are not actively using so as to avoid any unnecessary performance hits.

If using this library can hurt performance, why make it at all?

Because sometimes ... very, very rarely ... it's actually the best way to accomplish something.

See an example for details.