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

solenya-animation

v1.5.1

Published

Solenya animation coordinates element animations in response to DOM changes.

Downloads

7

Readme

Solenya Animation

Solenya animation coordinates element animations in response to DOM changes.

For context, this package provides 1 of 3 techniques you can use to animate in Solenya:

  1. CSS animation - this is great for animating an element when the previous bounds of the element or any of the element's siblings is irrelevant.
  2. Web Animations API - this is great for sequencing animations on an element. The Web animations API is supported by most browsers and you can use the web-animations-js shim for the remaining browsers such as Internet Explorer. You can also use third party animation packages.
  3. Measure/flip animations - this is what this package does - it lets you automatically animate the position and size of elements in response to DOM changes. It does this based on the measure/flip technique.

transitionChildren

The transitionChildren function lets you gracefully transition the position and size of each child element as its updated, enters, or leaves the DOM. Use it to build lists where children move around or grow or shrink in response to DOM changes.

It's used as follows:

export class AnimateShuffle extends Component {
  @transient items = range(1, 101)

  view() {
    return div(
      button ({ onclick: () => this.shuffle() }, "shuffle"),
      div (transitionChildren(), this.items.map(n =>
        div ({ key: n }, n)))
    )
  }

  shuffle() {
    this.update(() => this.items = shuffle(this.items))
  }
}

Each child must have a unique key relative to its siblings. When in doubt, the virtual DOM thinks: Same key? Same element. Different key? Different element. So the key instructs the DOM to honor your exact intent when adding, removing, and updating elements.

The properties of transitionChildren are:

export type Orientation = "horizontal"|"vertical"
export type Direction = "forwards"|"backwards"
export type AnimationKind = "fade"|"slide"|"scale"

export interface TransitionChildrenProps {    

    /** The kind of animation - "fade" | "slide" | "scale". Defaults to "slide" if direction is specified, else "scale". */
    kind: AnimationKind

    /** Whether the children are oriented horiontally or vertically. Defaults to "vertical" */
    orientation: Orientation

    /** The duration of the animation */
    duration: number,

    /** Either "forwards" or "backwards" */
    direction: Direction

    /** Whether to reset the scroll position to zero. Useful for full page animations. */
    scrollToStart: boolean,

    /** The animation threshold in pixels. Defaults to 5. */
    animationThreshold: number

    /** Whether width and height changes should be animated. Defaults to false. */
    isSizeAnimated: boolean
}

Children will automatically move to their new positions if necessary.

There's three types of animation kind, that determines what happens to entering and leaving elements:

  • slide - slide in and out
  • scale - expand and collapse
  • fade - fade in and out

If kind is not specified, then it defaults to slide if direction is specified, else scale.

slide is useful for carousel style animations on static lists. scale is useful for animating dynamic lists where elements may be randomly inserted or removed.

Note you can use transitionChildren in the case where there's only 1 child at a time - this is quite a common scenario.

Set scrollToStart to true when animating an element that represents a new page, as it's undesirable when the sliding stops to be scrolled part way into the new page.