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

@lit-labs/motion

v1.0.7

Published

Lit directives for making things move.

Downloads

38,088

Readme

@lit-labs/motion

Lit directives for making things move.

Installation

From inside your project folder, run:

$ npm install @lit-labs/motion

Animate directive

The animate directive can be used to animate DOM elements from one lit render to the next. If the animate element changes state between renders, the directive performs a "tweening" animation between the two states based on the options given. In addition, elements can animate when they initially render to DOM and when they are removed.

The directive supports a number of options:

| Option | Usage | | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | keyframeOptions | configure animation via the KeyframeEffect Options from the Web Animation API. | | properties | list of properties to animate, defaults to ['left', 'top','width', 'height', 'opacity', 'color', 'background'] | | disabled | disables animation | | guard | function producing values that must change for the animate to run | | in | keyframes to use when animating in | | out | keyframes to use when animating out | | skipInitial | skip animating in the first time | | id | used to link to other animate's via inId | | inId | id of the animate to render from when animating in | | onStart | run when the animate starts | | onComplete | run when the animate completes | | onFrames | run when the frames are produced, use to modify frames |

How it works

The directive uses the FLIP animation technique--derived from First, Last, Invert, Play. This describes how the directive works. It measures the styling of the animate element before a layout change (first) and after a layout change (last). Then it inverts the last layout such that it matches the first layout. Finally it plays an animation which removes the inverted layout such that the element animates to the "last" layout. See the FLIP article by Paul Lewis for more information about the technique.

The directive uses a reactive controller to coordinate measuring the DOM of the animate element. The first layout is measured when the hosting element updates, and the last layout is measured when the hosting element renders and completes its update.

Usage

Here's an example:

import {animate} from '@lit-labs/motion';
// ...

class MyElement extends LitElement {
  static properties = {shifted: {}};
  static styles = css`
    .box {
      position: absolute;
      width: 100px;
      height: 100px;
      background: steelblue;
      top: 100px;
      border-radius: 50%;
    }

    .shifted {
      right: 0;
    }
  `;

  render() {
    return html`
      <button @click=${this._toggle}>Move</button>
      <div class="box ${this.shifted ? 'shifted' : ''}" ${animate()}></div>
    `;
  }

  _toggle() {
    this.shifted = !this.shifted;
  }
}

AnimateController

The animate controller allows you to coordinate and control animate directives within a given element.

The controller constructor takes an options object with the following properties:

| Property | Usage | | -------------- | ----------------------------------------------------------- | | defaultOptions | default options for all element animate directives | | startPaused | all element animations start paused | | disabled | disables all element animations | | onComplete | run when all element animations complete for a given update |

The animate controller also provides API for controlling animate animations, including play(), pause(), cancel(), finish(), and togglePlay(). These methods affect all the animate animations for a given element. Finally, animate controller has properties which reflect the state of the animate animations in the host element: isPlaying returns true if any animate's are currently playing; isAnimating returns true if any animates currently have animations (which may be paused).

Contributing

Please see CONTRIBUTING.md.