spmjs

spm@3.x

Brand new static package manager for browser.

Getting Started 󰅴 Packages

inline-style-prefixer


Autoprefixer for Inline Style objects using userAgent and caniuse data

spm install inline-style-prefixer
Versions 0.5.4
Updated 9 years ago
Keywords react, react styling, prefixer, inline styles, autoprefixer, vendor prefix, userAgent
Repository https://github.com/rofrischmann/inline-style-prefixer
Main dist/Prefixer.js
Owner

Autoprefixer for inline style objects

Build Status Code Climate npm version npm downloads Dependencies Gzipped Size

inline-style-prefixer adds required vendor prefixes to your style object. It only adds prefixes if they're actually required by evaluating the browser's userAgent against data from caniuse.com.

Usage

npm install inline-style-prefixer
import Prefixer from 'inline-style-prefixer'

const styles = {
  transition: '200ms all linear',
  userSelect: 'none',
  nested : {
    boxSizing: 'border-box',
    appearance: 'none',
    color: 'blue',
    flex: 1
  }
}

const prefixer = new Prefixer()
const prefixedStyles = prefixer.prefix(styles)

// Assuming you are using e.g. Chrome version 27.0, prefixedStyles will be:
{
  transition: '200ms all linear',
  WebkitUserSelect: 'none',
  nested: {
    boxSizing: 'border-box',
    WebkitAppearance: 'none',
    color: 'blue',
    WebkitFlex: 1
  }
}

prefixAll (static)

Sometimes you might to prerender something without knowing the userAgent yet. Use the static prefixAll to achieve that.

import Prefixer from 'inline-style-prefixer'

const styles = {
  transition: '200ms all linear'
}

const prefixedStyles = Prefixer.prefixAll(styles)

// prefixedStyles will be:
{
  WebkitTransition: '200ms all linear',
  MozTransition: '200ms all linear',
  msTransition: '200ms all linear',
  transition: '200ms all linear'
}

Custom userAgent

Sometimes your environment does not provide a proper userAgent string e.g. if you are rendering on server-side. Therefore optionally just pass a userAgent-string.

import Prefixer from 'inline-style-prefixer'

const customUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36'
const prefixer = new Prefixer(customUserAgent)

Prefix information

Every Prefixer instance also provides prefix information.

// e.g. using a Chrome version 40 userAgent
prefixer.cssPrefix = '-webkit-'
prefixer.jsPrefix = 'Webkit'
prefixer.prefixedKeyframes = '-webkit-keyframes'

Browser Support

Supports the major browsers with the following versions.

Custom Build & Legacy Support

You may have to create a custom build if you need older browser versions. Just modify the config.js file which includes all the browser version specifications.

npm install
npm run build

Supported properties

The following list shows all supported properties that get evaluated.
They are grouped in caniuse groups.

Special plugins

Sometimes it is not enough to just prefix a property, but you also need to prefix the value or even transform the property and value completely. Plugins are used to tackle browser incompatibilities. File an issue or submit a PR if a plugin you need is missing (these are roughly equivalent to Autoprefixer's hacks). The following plugins are included by default:

License

inline-style-prefixer is licensed under the MIT License.
Created with ♥ by @rofrischmann.