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

japit

v0.0.0

Published

Japit -----

Downloads

61

Readme

Japit

Japit is a library for animating SVGs. It makes it easy to express dependencies between different elements.

[!CAUTION] Japit is still in early development. There are going to be breaking changes!

Getting Started

Right now the easiest way to get started is by cloning the repository and making changes to src/main.ts.

$ git clone https://github.com/janekhaertter/Japit # Clone the project
$ cd Japit
$ npm install # Install dependencies
$ npm run dev # Start the development server that previews the code in `src/main.ts`
$ $EDITOR src/main.ts # Edit `src/main.ts` with your favourite editor

Examples

Basic Usage

Create a red circle that changes its color to blue.

const svg: SVGSVGElement = document.querySelector('svg')!; // Get SVG DOM element

// Set dimensions of SVG
svg.style.width = '500px';
svg.style.height = '500px';

// create a new animation with two steps
const player = createAnimation(svg, [
  // step 1:
  (b) => {
    b.select(0) // create an element with id 0
      .circle((c) => c.centerX(100).centerY(100).radius(50)) // give it the shape circle and specify its position and radius
      .fill('red'); // color it red
  },
  // step 2:
  (b) => {
    b.duration(1); // the transition from red to blue should take 1 second
    b.select(0).fill('blue'); // change color of element with id 0 to blue
  },
]);

player.play(); // start playing the animation

Expressing Dependencies

We bind the start- and endpoint of a line to the centers of two circles. By moving the first circle around, we thus also move the startpoint of the line. Similarly, we bind the color of the second circle to the color of the first circle.

const svg: SVGSVGElement = document.querySelector('svg')!;

svg.style.width = '500px';
svg.style.height = '500px';

const player = createAnimation(svg, [
  (b) => {
    // create the left black circle
    b.select(0)
      .fill('black')
      .circle((c) => c.centerX(100).centerY(100).radius(50));

    // create the right black circle
    b.select(1)
      .fill($fill(0)) // it has the same fill as the left circle
      .circle((c) => c.centerX(300).centerY(100).radius(50));

    // create the line between the two circles
    b.select('0-1')
      .zIndex(-10) // ensures that the line is behind the circles
      .stroke('black')
      .strokeWidth(20)
      .line(
        (l) =>
          l
            .start($center(0)) // the starting point of the line is the center of the left circle
            .end($center(1)), // the ending point of the line is the center of the right circle
      );
  },
  (b) => {
    b.duration(1);

    b.select(0)
      .fill('blue') // this also affects the color of circle 1 as its fill is equal to the fill of circle 0
      .circle((c) => c.radius(50).centerX(100).centerY(300)); // the line '0-1' follows the center of the circle
  },
]);

player.play();

Parallel Animations

Create two animations in parallel. The first shifts circle 0 down; the second waits for two seconds, and then moves circle 1 to circle 0.

const svg: SVGSVGElement = document.querySelector('svg')!;

svg.style.width = '500px';
svg.style.height = '500px';

const player = createAnimation(svg, [
  (b) => {
    // create two circles next to each other
    b.select(0)
      .fill('black')
      .circle((c) => c.centerX(100).centerY(100).radius(50));

    b.select(1)
      .fill($fill(0)) // it has the same fill as the left circle
      .circle((c) => c.centerX(300).centerY(100).radius(50));
  },
  // the array of animations will be played in parallel
  [
    (b) => {
      // shift circle '0' down
      b.duration(5);
      b.select(0).circle((c) => c.radius(50).centerX(100).centerY(300));
    },

    // the array of animations will be played in sequence
    [
      (b) => b.duration(2), // wait for 2 seconds
      (b) => {
        // move circle '1' to circle '0'
        b.duration(1);
        b.select(1).circle((c) => c.radius(50).center($center(0)));
      },
    ],
  ],
]);

player.play();