Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

pleeease-filters

iamvdo522.6k4.0.0

Convert CSS shorthand filters to SVG ones

postprocessor, css, postcss, pleeease, filters

readme

Pleeease: filters

Convert CSS shorthand filters to SVG equivalent.

Used by Pleeease, a CSS post-processor.

Try it by yourself in the Pleeease playground

Example

You write foo.css:

.blur {
    filter: blur(4px);
}

You get bar.css:

.blur {
    filter: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><filter id="filter"><feGaussianBlur stdDeviation="4" /></filter></svg>#filter');
    filter: blur(4px);
}

Filters

It converts all 10 CSS shorthand filters:

  • grayscale
  • sepia
  • saturate
  • hue-rotate
  • invert
  • opacity
  • brightness
  • contrast
  • blur
  • drop-shadow

Learn more about CSS filters

Prefixes

This tool doesn't add prefixes. If you want them, you should use Autoprefixer. This is what Pleeease does:

.blur {
    filter: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><filter id="filter"><feGaussianBlur stdDeviation="4" /></filter></svg>#filter');
    -webkit-filter: blur(4px);
            filter: blur(4px);
}

Usage

$ npm install pleeease-filters
var filters = require('pleeease-filters'),
    fs      = require('fs');

var css = fs.readFileSync('app.css', 'utf8');

// define options here
var options = {};

var fixed = filters.process(css, options);

fs.writeFile('app.min.css', fixed, function (err) {
  if (err) {
    throw err;
  }
  console.log('File saved!');
});

Options

You can also add IE filters with an option:

// set options
var options = {
    oldIE: true
}

Using the first example, you'll get:

.blur {
    filter: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><filter id="filter"><feGaussianBlur stdDeviation="4" /></filter></svg>#filter');
    filter: blur(4px);
    filter: progid:DXImageTransform.Microsoft.Blur(pixelradius=4);
}

Note

Be careful, not all browsers support CSS or SVG filters on HTML content:

  • latest WebKit browsers support CSS shorthand
  • Firefox support SVG filters (and CSS shorthand since FF35)
  • IE9- support IE filters (limited and slightly degraded)

It means that IE10+, Opera Mini and Android browsers have no support at all on HTML, only in SVG.

Moreover, IE filters shouldn't be used.

See caniuse for more info.

Licence

MIT © 2014 Vincent De Oliveira · iamvdo

This module is an adaptation of CSS-Filters-Polyfill. Copyright (c) 2012 - 2013 Christian Schepp Schaefer

changelog

4.0.0 - 2017-05-09

  • Update to PostCSS 6
  • Remove Node 0.12 support

3.0.1 - 2017-02-07 - Better splitting of filters functions and trim colors (fix #14)

3.0.0 - 2016-04-01

2.0.0 - 2015-09-14

  • Update to PostCSS 5

1.0.1 - 2015-05-25

  • Avoid drop-shadow spread to throw an error, and keep as-is

1.0.0 - 2015-01-27

  • Added: upgrade to postcss v4.x
  • Added: travis CI

0.1.5 - 2014-12-23

  • Fixed: npm "No repository field" warning

0.1.4 - 2014

  • Added: color functions support for drop-shadow filter. Now support rgb, rgba, hsl and hsla (#3)
  • Added: upgrade to postcss v3.x

0.1.3 - 2014

  • Fixed: charset issue

0.1.2 - 2014

  • Added: Create SVG blur filter, even with unit-less 0

0.1.1 - 2014

  • Changed: Don't add filters if they're already presents

0.1.0 - 2014

✨ Initial release