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

@xaro/css-class-animations

v0.1.11

Published

[![DeepScan grade](https://deepscan.io/api/teams/11657/projects/14877/branches/287085/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=11657&pid=14877&bid=287085)

Downloads

4

Readme

DeepScan grade

@xaro/css-class-animations

Micro lib for css animations with events

Install

$ npm install @xaro/css-class-animations

Usage

const animation = new CSSClassAnimations({
  el: '.el', // string | string[] | Element | Element[]
  on: {
    start: (event: AnimationEvent | TransitionEvent) => {
      console.log('[start]', event);
    },
    cancel: (event: AnimationEvent | TransitionEvent) => {
      console.log('[cancel]', event);
    },
    end: (event: AnimationEvent | TransitionEvent) => {
      console.log('[end]', event);
    },
    iteration: (event: AnimationEvent) => {
      console.log('[iteration]', event);
    },
    run: (event: TransitionEvent) => {
      console.log('[run]', event);
    }
  }
});

Now information about the event will be displayed in the console when it occurs.


ATTENTION

Сallback function will be called for each element when the event occurs


Why is this needed?

This is mainly needed to control the animations and transitions of appearance and disappearance of elements, if you are NOT using Vue, React and etc.

For example: opening a modal window with animation using only css classes.

// modal.ts

class Modal {
  container: Element;
  animation: CSSClassAnimations;
  // ...

  constructor(/* ... */) {
    this.animation = new CSSClassAnimations({
      el: this.container
    });
    // ...

    this.animation.on('end', () => {
      this.container.style.display = 'none';
    });
  }
  
  close() {
    this.container.classList.add('class with hide animation/transition');
  }
}

Now, when calling the "close" method, a class with some disappearance animation will be added, and after the animation is complete, the value of container's display attribute will be assigned "none".

Advanced usage

When an object is initialized, without the "allow" and "disallow" properties, all animation and transition events are set ups on the passed elements.

If there are many objects, this can load the client's device.

Therefore, it is recommended to indicate only those events that you will listen to.

const animation = new CSSClassAnimations({
  el: '.el'
  allow: [
    'animationend'
  ]
});

It is recommended to specify one of the following parameters:

  • allow: Adds only the specified event keys
  • disallow: Adds all handlers except the specified ones

Methods

  • addEvent(domEventKey: T_DOMEventsKeys): void Adds listener to the elements

  • removeEvent(domEventKey: T_DOMEventsKeys): void Remove listener from elements (calls removeEventListener, but callbacks remain in the object)

  • on(eventKey: T_EmitterEventsKeys, cb: Function | Function[]): void Adds callback functions to an event by its key

    The first parameter does not need to specify the DOM event key, but the CSSClassAnimations event key ( start, cancel, end, iteration, run )


The library uses

  • @xaro/micro-dom, all its features through the els property of the CSSClassAnimations object instance
  • @xaro/event-emitter, all its features through the emitter property of the CSSClassAnimations object instance
    const animation = new CSSClassAnimations({
      el: '.el'
    });
    animation.emitter.subscribe('start', (event: AnimationEvent | TransitionEvent) => {
      console.log('[start]', event);
    });
    animation.emitter.emit('start', /* ... */);

Interfaces & Types

types.d.ts

import { I_EventEmitter } from "@xaro/event-emitter";
import { I_MicroDOM } from "@xaro/micro-dom";

export interface I_CSSClassAnimations {
  els:      I_MicroDOM;
  emitter:  I_EventEmitter;
  allow:    T_DOMEventsKeys[];

  addEvent(domEventKey: T_DOMEventsKeys): void;
  removeEvent(domEventKey: T_DOMEventsKeys): void;
  on(eventKey: T_EmitterEventsKeys, cb: Function | Function[]): void;
}

export interface I_CSSClassAnimationsConstructorConfig {
  el:         string | Element | Array<string | Element>;
  allow?:     T_DOMEventsKeys | T_DOMEventsKeys[];
  disallow?:  T_DOMEventsKeys | T_DOMEventsKeys[];
  on?: {
    start?:     ((event: AnimationEvent | TransitionEvent) => void) | ((event: AnimationEvent | TransitionEvent) => void)[];
    cancel?:    ((event: AnimationEvent | TransitionEvent) => void) | ((event: AnimationEvent | TransitionEvent) => void)[];
    end?:       ((event: AnimationEvent | TransitionEvent) => void) | ((event: AnimationEvent | TransitionEvent) => void)[];
    iteration?: ((event: AnimationEvent) => void) | ((event: AnimationEvent) => void)[];
    run?:       ((event: TransitionEvent) => void) | ((event: TransitionEvent) => void)[];
  }
}

export type T_DOMEventsKeys =
  'animationstart'      |
  'animationcancel'     |
  'animationend'        |
  'animationiteration'  |
  'transitionstart'     |
  'transitioncancel'    |
  'transitionend'       |
  'transitionrun';

export type T_EmitterEventsKeys =
  'start'     |
  'cancel'    |
  'end'       |
  'iteration' |
  'run';

License

MIT