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

@dblechoc/style-vendorizer

v2.0.1

Published

Tiny CSS vendor prefixer and property alias mapper for runtime styling solutions

Downloads

5

Readme

style-vendorizer

Tiny CSS vendor prefixer and property alias mapper for runtime styling solutions.

npm npm bundle size Travis (.com) Contributor Covenant

Usage

Install the library with a package manager, e.g. npm:

npm install style-vendorizer

After that, import transformer functions on demand. A recommended starting point is shown below:

import {
  cssPropertyAlias,
  cssPropertyPrefixFlags,
  cssValuePrefixFlags,
} from "style-vendorizer";

function styleDeclaration(property, value) {
  let cssText = "";

  /* Resolve aliases, e.g. `gap` -> `grid-gap` */
  const propertyAlias = cssPropertyAlias(property);
  if (propertyAlias) cssText += `${propertyAlias}:${value};`;

  /* Prefix properties, e.g. `backdrop-filter` -> `-webkit-backdrop-filter` */
  const propertyFlags = cssPropertyPrefixFlags(property);
  if (propertyFlags & 0b001) cssText += `-webkit-${property}:${value};`;
  if (propertyFlags & 0b010) cssText += `-moz-${property}:${value};`;
  if (propertyFlags & 0b100) cssText += `-ms-${property}:${value};`;

  /* Prefix values, e.g. `position: "sticky"` -> `position: "-webkit-sticky"` */
  /* Notice that flags don't overlap and property prefixing isn't needed here */
  const valueFlags = cssValuePrefixFlags(property, value);
  if (valueFlags & 0b001) cssText += `${property}:-webkit-${value};`;
  else if (valueFlags & 0b010) cssText += `${property}:-moz-${value};`;
  else if (valueFlags & 0b100) cssText += `${property}:-ms-${value};`;

  /* Include the standardized declaration last */
  /* https://css-tricks.com/ordering-css3-properties/ */
  cssText += `${property}:${value};`;

  return cssText;
}

Prefix flags may be defined in TypeScript without any overhead as follows:

const enum CSSPrefixFlags {
  "-webkit-" = 1 << 0, // 0b001
     "-moz-" = 1 << 1, // 0b010
      "-ms-" = 1 << 2, // 0b100
}

/* Magic numbers from the previous snippet should be replaced like below: */
if (flags & CSSPrefixFlags["-webkit-"]) cssText += "...";
if (flags & CSSPrefixFlags["-moz-"]) cssText += "...";
if (flags & CSSPrefixFlags["-ms-"]) cssText += "...";

Browser Support

Every browser in the default Browserslist configuration is supported and tested against:

  • Baidu Browser for Android 7.12+
  • Chrome 57+
  • Edge 16+
  • Firefox 48+
  • Internet Explorer 11
  • KaiOS Browser 2.5+
  • Opera 46+
  • Safari 12.2+
  • Samsung Internet Browser 11.1+
  • QQ Browser for Android 10.4+
  • UC Browser for Android 12.12+

Quirks

  • Function values are only prefixed for longhand properties. This guarantees that only the start of each value is compared, for efficiency:

    // Prints "1 0"
    console.log(
      cssPropertyPrefixFlags(
        "background-image", // Longhand
        "image-set('example.png' 1x, 'example-2x.png' 2x)", // Prefixed
      ),
      cssPropertyPrefixFlags(
        "background", // Shorthand
        "image-set('example.png' 1x, 'example-2x.png' 2x)", // Not prefixed
      ),
    );
  • CSS Grid works in IE 11 only when using the following longhand properties:

    • grid-template-rows, grid-template-columns
    • grid-row-start, grid-column-start
    • -ms-grid-row-span and -ms-grid-column-span (along with grid-row-end and grid-column-end for cross-browser compatibility)
    • align-self, justify-self
  • cross-fade() and element() functions are not prefixed, due to the lack of standard implementations.

  • Selectors are not yet supported.

Acknowledgements

This project was heavily inspired by tiny-css-prefixer. Test vectors are obtained from @mdn/browser-compat-data.