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

clapperboard

v1.0.5

Published

Easily set frames to create an animation rendered from an object (like the state of a react component).

Downloads

1

Readme

clapperboard

Easily set frames to create an animation rendered from an object (like the state of a react component).

Rationale

I found React to be a simple way of rendering an animation—whether svg or simple HTML.

With clapperboard, it is simple of scheduling updates to the React component state or props to animate it.

Installation

Using npm:

npm i --save clapperboard

Usage with react

Simple example of animating a browser:

  import animator from 'clapperboard';
  import React from 'react';
  import ReactDOM from 'react-dom';

  class BrowserAnimation extends React.Component {
    render() {
      return (<div className="browser-animation">
        <div
          className="browser-animation__cursor"
          style={{
            top: this.state.cursor.y.toString() + '%',
            left: this.state.cursor.x.toString() + '%'
          }}
          />
        <div className="browser-animation__top-bar">
          <span className="url">{this.state.url}</span>
        </div>
        <div
          className="browser-animation__document"
          style={{
            backgroundImage: `url(${this.state.currentPage})`,
            backgroundPosition: `0 -${this.state.scrollPosition}px`
          }}
          >
        </div>
      </div>);
    }
  }

  var component; // Render BrowserAnimation and store it here.

  var initialState = {
    cursor: {
      x: 40,
      y: 20
    },
    url: 'https://acme.com/',
    currentPage: 'homepage'
  };

  component.setState(initialState);

  const timeline = [
    ['+1', 'cursor.y', 50],
    ['+0.5', 'cursor', {x: 10, y: 15}],
    ['+0.2', 'url', 'https://acme.com/sign_up', 'type'],
    ['+0.1:signUpPage', 'currentPage', 'sign_up'],
    ['=', 'scrollPosition', 0],
    // ... all the frames here
  ];

  const [stop, onEnd] = animator(initialState, timeline, function (obj) {
      component.setState(obj);
  });

API

Frames

The timeline consists of a list of frames. Each frame is a list of the following: time, property, change, method.

time

The time is in one of these formats:

  • +N (where N is a float number of seconds): Frame will be executed N seconds after the previous change is complete
  • =: Frame will be executed at the same time as the previous one

Frames can further be 'tagged':

  • timingInfo:frameName (ex +1:pageChanged): The frame will be named and will be referenceable as frameName.
  • =frameName: The frame will be executed at the same time as frameName.
  • frameName+N (where N is a float number of seconds): The frame will be executed N seconds after frameName's change is completed.

These can be combined, so that sessionStart+5:sessionEnd is a valid time.

property

This will be the property of the master object to be changed, in dot format.

change

This is what the property will be changed to.

method

Method can be left empty or be type, in which case the change will be "typed" and not immediate. This is useful to simulate user input.

animator function

The animator function will need to be called with:

  • initialState: the object frames will apply changes to
  • frames: the list of frames
  • callback: a function to call after each change. It will be called with the changed object as only argument
  • infinite (optional): set to false to only run the animation once

It will return a function stop which you can use to stop the animation.

Big disclaimer

I'm pretty sure this stuff works, but not 100% sure. I have extracted it from an old project as I needed it again. You're welcome to submit improvements as you see fit.