postcss-colormin
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -0,1 +1,6 @@ | ||
# 2.1.3 | ||
* Updates postcss-value-parser to version 3 (thanks to @TrySound). | ||
* Removes the dependency on colormin, conversion is now done in-module. | ||
# 2.1.2 | ||
@@ -2,0 +7,0 @@ |
69
index.js
'use strict'; | ||
var colormin = require('colormin'); | ||
var colormin = require('./lib/colormin'); | ||
var postcss = require('postcss'); | ||
var parser = require('postcss-value-parser'); | ||
var stringify = parser.stringify; | ||
var trim = parser.trim; | ||
function optimise (decl) { | ||
if (/^(?!font|filter|-webkit-tap-highlight-color)/.test(decl.prop)) { | ||
decl.value = parser(decl.value).walk(function (node) { | ||
if (node.type === 'function') { | ||
if (/^(rgb|hsl)a?$/.test(node.value)) { | ||
node.value = colormin(stringify(node)); | ||
node.type = 'word'; | ||
} else { | ||
trim(node.nodes); | ||
} | ||
} else if (node.type === 'div' && node.value !== '/') { | ||
node.before = ''; | ||
node.after = ''; | ||
} else if (node.type === 'space') { | ||
node.value = ' '; | ||
function extractColorArguments(nodes) { | ||
var i, max; | ||
var result = []; | ||
for (i = 0, max = nodes.length; i < max; i += 1) { | ||
if (nodes[i].type === 'word') { | ||
result.push(parseFloat(nodes[i].value)); | ||
} | ||
} | ||
return result; | ||
} | ||
function reduceColor (decl) { | ||
decl.value = parser(decl.value).walk(function (node) { | ||
if (node.type === 'function') { | ||
if (/^(rgb|hsl)a?$/.test(node.value)) { | ||
node.value = colormin(node.value, extractColorArguments(node.nodes)); | ||
node.type = 'word'; | ||
} else { | ||
node.value = colormin(node.value); | ||
node.before = node.after = ''; | ||
} | ||
}).toString(); | ||
} | ||
} else if (node.type === 'word') { | ||
node.value = colormin(node.value); | ||
} | ||
}).toString(); | ||
} | ||
function reduceWhitespaces (decl) { | ||
decl.value = parser(decl.value).walk(function (node) { | ||
if (node.type === 'function' || node.type === 'div') { | ||
node.before = node.after = ''; | ||
} | ||
}).toString(); | ||
} | ||
function transform (decl) { | ||
if (decl.prop === '-webkit-tap-highlight-color') { | ||
@@ -33,10 +47,5 @@ if (decl.value === 'inherit' || decl.value === 'transparent') { | ||
} | ||
decl.value = parser(decl.value).walk(function (node) { | ||
if (node.type === 'function') { | ||
trim(node.nodes); | ||
} else if (node.type === 'div') { | ||
node.before = ''; | ||
node.after = ''; | ||
} | ||
}).toString(); | ||
reduceWhitespaces(decl); | ||
} else if (/^(?!font|filter)/.test(decl.prop)) { | ||
reduceColor(decl); | ||
} | ||
@@ -47,4 +56,4 @@ } | ||
return function (css) { | ||
css.walkDecls(optimise); | ||
css.walkDecls(transform); | ||
}; | ||
}); |
{ | ||
"name": "postcss-colormin", | ||
"version": "2.1.2", | ||
"description": "Minify colors in your CSS files with PostCSS and colormin.", | ||
"version": "2.1.3", | ||
"description": "Minify colors in your CSS files with PostCSS.", | ||
"main": "index.js", | ||
@@ -35,6 +35,7 @@ "files": [ | ||
"dependencies": { | ||
"colormin": "^1.0.4", | ||
"colr-convert": "^1.0.5", | ||
"css-color-names": "0.0.2", | ||
"postcss": "^5.0.4", | ||
"postcss-value-parser": "^2.0.2" | ||
"postcss-value-parser": "^3.0.2" | ||
} | ||
} |
# [postcss][postcss]-colormin [![Build Status](https://travis-ci.org/ben-eb/postcss-colormin.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-colormin.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-colormin.svg)][deps] | ||
> Minify colors in your CSS files with PostCSS and [colormin][colormin]. | ||
> Minify colors in your CSS files with PostCSS. | ||
@@ -36,3 +36,2 @@ ## Install | ||
[colormin]: https://github.com/ben-eb/colormin | ||
[ci]: https://travis-ci.org/ben-eb/postcss-colormin | ||
@@ -39,0 +38,0 @@ [deps]: https://gemnasium.com/ben-eb/postcss-colormin |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6007
50
4
40
+ Addedcolr-convert@^1.0.5
+ Addedcss-color-names@0.0.2
+ Addedcolr-convert@1.0.5(transitive)
+ Addedcss-color-names@0.0.2(transitive)
+ Addedpostcss-value-parser@3.3.1(transitive)
- Removedcolormin@^1.0.4
- Removedclone@1.0.4(transitive)
- Removedcolor@0.11.4(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcolor-string@0.3.0(transitive)
- Removedcolormin@1.1.2(transitive)
- Removedcss-color-names@0.0.4(transitive)
- Removedhas@1.0.4(transitive)
- Removedpostcss-value-parser@2.0.5(transitive)
Updatedpostcss-value-parser@^3.0.2