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

dom-css-transform

v2.0.2

Published

transforms a DOM element by string, matrix or components

Downloads

13

Readme

dom-css-transform

stable

Applies a CSS transform to a DOM element's style, accepting a string, array matrix, or discrete components to be recomposed according to CSS3 transform spec. Also handles vendor prefixing.

var transform = require('dom-css-transform')

var div = document.createElement('div')

//typical string style
transform(div, 'translateX(25px) rotateX(25deg)')

//a flat mat2d (9 elements) or mat4 (16 elements) array
var matrix = [0.5, 0, 0, 0.25, 0, 0]
transform(div, matrix)

//results in 3D "matrix3d()"
transform(div, {
    scale: [x, y, z],
    translate: [x, y, z] 
    rotate: [x, y, z]
})

//results in 2D "matrix()"
transform(div, {
    rotate: [0, 0, -Math.PI],
    translate: [-15, 25],
    scale: [0.15, 0.5]
})
// result --> "matrix(-0.15, 0, 0, -0.5, -15, 25)"

//reset to identity
transform(div, null)
// result --> "none"

Usage

NPM

transform(element, opt)

Applies a CSS transform to the given DOM element, using the specified options. Types supported:

  • string like "translateX(25px) rotateZ(25deg)" or "matrix(0.5,0,0,1,0,0)"
  • array of 16 elements (4x4 matrix) or 9 elements (3x2 matrix for 2D transformations)
  • an object with discrete components.
  • null or undefined, which leads to identity transform (i.e. "none")

When an object is specified, the reuslt is a 4x4 matrix composed by css-mat4. Options:

  • translate an array of [x, y] or [x, y, z] in pixels
  • rotate an array of [x, y, z] in radians
  • scale an array of [x, y] or [x, y, z] (z component defaults to 1)
  • skew an array of [x, y] in radians for a combined 2D skew matrix
  • skewX, skewY numbers in radians to mimic the independent CSS operations by the same name
  • quaternion can be specified if rotation is undefined; it's an array of [x, y, z, w] components

License

MIT, see LICENSE.md for details.