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

@douyinfe/semi-animation

v2.72.0

Published

animation base library for semi-ui

Downloads

14,147

Readme

Provides basic JS animation engine:

  • Simulate animation changes based on interpolation,the performance is more natural
  • Support the definition of various easing functions
  • Provides a complete life cycle hook and operation method, allowing developers to freely control the animation

Install

npm install @douyinfe/semi-animation

Usage

Animation

semi-animation provides a class called Animation . It has a complete life cycle hook and control method to support operating animation like audio and video.

  • Use in JS
import { Animation } from '@douyinfe/semi-animation';

const div = document.createElement('span');
div.style.display = 'inline-block';
document.body.appendChild(div);

const animation = new Animation({
    from: { value: 0 },
    to: { value: 1 },
});

animation.on('frame', props => {
    const num = props.value.toFixed(2);
    div.style.transform = `scale(${num})`;
    div.innerText = num;
});
  • Use in React
import { Animation } from '@douyinfe/semi-animation';
import { Component } from 'react';

class App extends Component {
    constructor(props) {
        super(props);
        this.state = { value: 0 };

        this.animation = new Animation({
            from: { value: 0 },
            to: { value: 1 },
        });

        this.animation.on('frame', props => {
            this.setState({ value: props.value.toFixed(2) });
        });
    }

    componentDidMount() {
        this.animation.start();
    }

    componentWillUnmount() {
        this.animation.destroy();
    }

    render() {
        const { value } = this.state;

        return <div style={{ display: 'inline-block', transform: `scale(${value})` }}>{value}</div>;
    }
}
  • Use in Vue
<template>
    <div :style="{ transform: `scale(${value})`, display: 'inline-block' }">{{value}}</div>
</template>

<script>
    import { Animation } from '@douyinfe/semi-animation';

    export default {
        data() {
            return { value: 0 };
        },
        created() {
            this.animation = new Animation({
                from: { value: 0 },
                to: { value: 1 },
            });

            this.animation.on('frame', props => {
                this.value = props.value;
            });
        },
        mounted() {
            this.animation.start();
        },
        beforeDestroy() {
            this.animation.destroy();
        },
    };
</script>

Show results:

API

new Animation({ ...props }, { ...config });

props

| Prop Name | Type | Required | Default | Description | | ------ | ------ | -------- | ------ | -------- | | from | Object | Y | | Initial state | | to | Object | Y | | Termination state |

config

| Prop Name | Type | Required | Default | Description | | -------- | ---------------- | -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | duration | Number | N | 1000 | Animation duration. If this parameter is passed in, the easing function of the animation will use easing or linear function,unit: ms | | | easing | Function|String | N | | Easing function for animation. If duration is not passed, the spring easing function is used by default. If the duration parameter is passed in, the linear easing function will be used by default.For example, incoming "cubic-bezier(.17,.67,.83,.67)" will cause the animation frame update performed according to this easing function | | | tension | Number | N | 170 | Tension, used for spring easing function | | friction | Number | N | 14 | Friction, used for spring easing function |

Instance methods

| Name | Params | Return | Description | | ---------------- | ------------------------------------------------------------ | ------ | --------------------------------------------------------------------- | | start | | | Start the animation | | pause | | | Pause the animation.After pausing, you must use the resume method to continue playing, not using start. | | resume | | | Continue the animation.Only has an effect when the animation is paused. | | reverse | | | Reverse the animation | | stop | | | Stop the animation.Only have an effect during animation playback, pause, and after end | | end | | | Immediately terminate the animation, and pass the final state value of the animation to the callback method | | reset | | | Reset the animation | | destroy | | | Destroy the animation | | getInitialStates | | Object | Get the initial state | | getCurrentStates | | Object | Get the current state | | getFinalStates | | Object | Get the final state | | on | eventName:string, eventHandler:Function(props: object): void | | Binding event callback method。The parameters received by each callback are the current animation state objects. |

Supported events

  • start: Triggered when the animation starts
  • pause: Triggered when the animation pauses(The event is triggered when the animation state is changed from playing to pause, and it will not be triggered in other cases)
  • resume: Triggered when the animation continues to play(The event is triggered when the animation state is changed from paused to playing, and it will not be triggered in other cases)
  • frame: Triggered when the animation frame is updated
  • rest: Triggered when the animation ends(The event will be triggered when the animation ends normally)
  • stop: Triggered when the animation stops(This event is triggered when the instance stop method is called)

Developers can use animation.on(eventName: string, cb: Function(currentStyle: object)) to bind the above events.

import { Animation } from '@douyinfe/semi-animation';
// ...
const animation = new Animation(
    {
        from: { value1: 0, value2: 1 /* ... */ },
        to: { value1: 1, value2: 2 /* ... */ },
    },
    {
        duration: 1000, // After passing in duration, the default is linear interpolation
    }
);

animation.on('frame', currentState => {
    // currentState: is the state value object at the current moment
    // { value1: xxx, value2: xxx, ... }
});

// The callbacks such as start and pause are the same as the frame above, and the parameters are also the same.
animation.on('start', currentState => { /* ... */ });
animation.on('pause', currentState => { /* ... */ });
animation.on('resume', currentState => { /* ... */ });
animation.on('rest', currentState => { /* ... */ });
animation.on('stop', currentState => { /* ... */ });

Licence

MIT