Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
inline-style-prefixer
Advanced tools
Autoprefixer for Inline Style objects using userAgent and caniuse data
The inline-style-prefixer is a JavaScript library used for automatically adding vendor prefixes to CSS styles defined in JavaScript objects. This is particularly useful when developing React applications that handle styles primarily in JavaScript. The prefixer uses the user agent to determine which prefixes are necessary for the current browser, ensuring cross-browser compatibility for CSS properties that require vendor prefixes.
Automatic Prefixing
Automatically adds necessary CSS vendor prefixes to style objects based on the current browser's requirements.
{"display": 'flex'} // becomes {'display': ['-webkit-box', '-moz-box', '-ms-flexbox', '-webkit-flex', 'flex']} after processing
User Agent Based Prefixing
Initializes the prefixer with a specific user agent to tailor the prefixing process to a particular browser's needs.
const prefixer = new Prefixer({userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}); const style = prefixer.prefix({display: 'flex'});
Autoprefixer is a more robust solution that integrates with build tools like PostCSS to automatically add vendor prefixes to CSS files. Unlike inline-style-prefixer, which is designed for inline styles in JavaScript, Autoprefixer works with static CSS files, making it suitable for a broader range of web development tasks.
PostCSS-prefixer is a PostCSS plugin that allows developers to add prefixes to CSS properties manually. It requires explicit configuration for each prefix, offering more control but less automation compared to inline-style-prefixer, which automatically determines necessary prefixes.
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.
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
}
}
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)
prefixer.prefix(styles)
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'
Supports the major browsers with the following versions.
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
The following list shows all supported properties that get evaluated.
They are grouped in caniuse groups.
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:
calc
values on any property.cursor
values zoom-in
, zoom-out
, grab
, grabbing
.display
values using display: flex
or display: inline-flex
.background
and backgroundImage
values linear-gradient
, radial-gradient
, repeating-linear-gradient
and repeating-radial-gradient
.maxHeight
, maxWidth
, width
, height
, columnWidth
,minWidth
, minHeight
intrinsic & extrinsic sizing values min-content
, max-content
, fill-available
, fit-content
, contain-floats
inline-style-prefixer is licensed under the MIT License.
Created with ♥ by @rofrischmann.
FAQs
Run-time Autoprefixer for JavaScript style objects
We found that inline-style-prefixer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.