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

css-keyframer

v1.0.1

Published

Dynamic css animation keyframes Manipulation library.

Downloads

9,725

Readme

Build Status npm version David

Dynamic css animation keyframes Manipulation library.

See demo page: https://tsuyoshiwada.github.io/css-keyframer/

Description

css-keyframer.js provides a Low-level API that add to the head element dynamically generates a style element.
Therefore, linking to the DOM element must be handled by the user side.

WHY?

When you want to apply the same animation to multiple elements, it is inefficient to update the in-line style of all the elements.
If you reuse one of @keyframes it can be realized efficient animation.

Install

You can install the css-keyframer.js from npm.

$ npm install css-keyframer --save

or Download the css-keyframer.min.js

Getting started

In the following example, to apply the spin animation to div.element.

<div class="element"></div>
import CSSKeyframer from "css-keyframer";

const keyframer = new CSSKeyframer({ /* options */ });

// CSS property will be added vendor-prefix is automatically!
keyframer.register("spin", [
  { transform: "rotate(0deg)" },
  { transform: "rotate(360deg)" }
]);

document.querySelector(".element").style[keyframer.animationProp.js] = "spin 1500ms linear infinite";

Options

To the constructor of CSSKeyframer You can specify the following options.

| Key | Default | Description | |:----------------|:-------------------|:------------------------------------------------------------------------------------------------------------------------------| | namePrefix | "" | Grant prefix to @keyframes. | | styleDataName | "data-keyframes" | To specify the attributes to be used in the style element. | | pretty | false | Output pretty code @keyframes. Primarily used for debugging applications. | | useAgent | null | Specify the UserAgent to be used for inline-style-prefixer. When set to null, it is judged automatically. since: v1.0.0 |

API

getKeyframesString(name: string, keyframe: Object | Array): string

since: v1.0.0

Get CSS string containing the keyframes.

keyframer.getKeyframesString("spin", {
  "0%": { transform: "rotate(0deg)" },
  "100%": { transform: "rotate(360deg)" }
});

// or Array style
keyframer.getKeyframesString("spin", [
  { transform: "rotate(0deg)" },
  { transform: "rotate(360deg)" }
]);

// Result (pretty: true)
// @keyframes spin {
//   0% {
//     transform: rotate(0deg);
//   }
//   100% {
//     transform: rotate(360deg);
//   }
// }

getKeyframeStylesheet(name: string, keyframe: Object | Array): string

since: v1.0.0

Get a style element containing a keyframe as a string.
It is an API that you do not normally use. But, this is a useful API for Server-side Rendering.

keyframer.getKeyframeStylesheet("spin", {
  "0%": { transform: "rotate(0deg)" },
  "100%": { transform: "rotate(360deg)" }
});

// or Array style
keyframer.getKeyframeStylesheet("spin", [
  { transform: "rotate(0deg)" },
  { transform: "rotate(360deg)" }
]);

// Result (pretty: true)
// <style type="text/css" data-keyframe="spin">@keyframes spin {
//   0% {
//     transform: rotate(0deg);
//   }
//   100% {
//     transform: rotate(360deg);
//   }
// }</style>

register(name: string, keyframe: Object | Array): void

Register the @keyframes.
If @keyframes of the same name exists overwrites it.

Example:

// Object style
keyframer.register("spin", {
  "0%": { transform: "rotate(0deg)" },
  "100%": { transform: "rotate(360deg)" }
});

// or Array style
keyframer.register("spin", [
  { transform: "rotate(0deg)" },
  { transform: "rotate(360deg)" }
]);

// Result (pretty: true)
// <style type="text/css" data-keyframe="spin">
// @keyframes spin {
//   0% {
//     transform: rotate(0deg);
//   }
//   100% {
//     transform: rotate(360deg);
//   }
// }
// </style>

unregister(name: string): void

Unregister the @keyframes.

Example:

keyframer.unregister("spin");

unregisterAll(): void

Unregister all @keyframes.

Example:

keyframer.unregisterAll();

contains(name: string): boolean

Check whether the specified @keyframes exists.

Example:

keyframer.contains("spin"); // true or false

animationProp: { js: string, css: string }

since: v1.0.0

It provides the name of the property required for the animation of the set with a vendor prefix. (CSS and JS)

Example:

import CSSKeyframer from "css-keyframer";

const keyframer = new CSSKeyframer();
keyframer.register("spin", [
  { transform: "rotate(0deg)" },
  { transform: "rotate(360deg)" }
]);

document.querySelector(".target").style[keyframer.animationProp.js] = "spin 1500ms linear infinite";

License

Released under the MIT Licence

ChangeLog

See CHANGELOG.md.

Author

tsuyoshiwada

Development

Initialization of the project.

$ cd /your/project/dir
$ git clone https://github.com/tsuyoshiwada/css-keyframer.git

Install some dependencies.

$ npm install

Start the development and can you see demo page (access to the http://localhost:3000/).

$ npm start

Run lint and testing.

$ npm test

Generates build file.

$ npm run build

Contribution

Thank you for your interest in css-keyframer.js.
Bugs, feature requests and comments are more than welcome in the issues.

Before you open a PR:

Be careful to follow the code style of the project. Run npm test after your changes and ensure you do not introduce any new errors or warnings. All new features and changes need documentation.

Thanks!