postcss-color-function
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,3 +1,7 @@ | ||
# 1.1.0 - 2014-11-25 | ||
- Enhanced exceptions | ||
# 1.0.0 - 2014-10-04 | ||
Initial release from [postcss-color](https://github.com/postcss/postcss-color) |
43
index.js
@@ -6,2 +6,3 @@ /** | ||
var colorFn = require("css-color-function") | ||
var helpers = require("postcss-message-helpers") | ||
@@ -13,8 +14,10 @@ /** | ||
return function(style) { | ||
style.eachDecl(function transformDecl(dec) { | ||
if (!dec.value) { | ||
style.eachDecl(function transformDecl(decl) { | ||
if (!decl.value || decl.value.indexOf("color(") === -1) { | ||
return | ||
} | ||
dec.value = transform(dec.value, dec.source) | ||
decl.value = helpers.try(function transformColorValue() { | ||
return transformColor(decl.value, decl.source) | ||
}, decl.source) | ||
}) | ||
@@ -25,23 +28,2 @@ } | ||
/** | ||
* Transform colors to rgb() or rgba() on a declaration value | ||
* | ||
* @param {String} string | ||
* @return {String} | ||
*/ | ||
function transform(string, source) { | ||
// order of transformation is important | ||
try { | ||
if (string.indexOf("color(") > -1) { | ||
string = transformColor(string, source) | ||
} | ||
} | ||
catch (e) { | ||
throw new Error(gnuMessage(e.message, source)) | ||
} | ||
return string | ||
} | ||
/** | ||
* Transform color() to rgb() | ||
@@ -61,3 +43,3 @@ * | ||
if (!balancedMatches) { | ||
throw new SyntaxError(gnuMessage("Missing closing parentheses in '" + string + "'", source)) | ||
throw new Error("Missing closing parentheses in '" + string + "'", source) | ||
} | ||
@@ -67,12 +49,1 @@ | ||
} | ||
/** | ||
* return GNU style message | ||
* | ||
* @param {String} message | ||
* @param {Object} source | ||
*/ | ||
function gnuMessage(message, source) { | ||
return (source ? (source.file ? source.file : "<css input>") + ":" + source.start.line + ":" + source.start.column : "") + " " + message | ||
} |
{ | ||
"name": "postcss-color-function", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "PostCSS plugin to transform W3C CSS color function to more compatible CSS.", | ||
@@ -22,3 +22,2 @@ "keywords": [ | ||
"LICENSE", | ||
"README.md", | ||
"index.js" | ||
@@ -28,3 +27,4 @@ ], | ||
"balanced-match": "^0.1.0", | ||
"css-color-function": "^1.1.1" | ||
"css-color-function": "^1.1.1", | ||
"postcss-message-helpers": "^1.1.0" | ||
}, | ||
@@ -34,3 +34,3 @@ "devDependencies": { | ||
"jshint": "^2.5.6", | ||
"postcss": "^2.2.5", | ||
"postcss": "^3.0.0", | ||
"tape": "^3.0.0" | ||
@@ -37,0 +37,0 @@ }, |
4511
3
39
+ Addedpostcss-message-helpers@1.1.1(transitive)