Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Wring colors to keyword if shorter than HEX
  • Loading branch information
Kyo Nagashima committed Aug 25, 2014
1 parent f8f3475 commit 79d5d70
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
35 changes: 35 additions & 0 deletions lib/color_keywords.js
@@ -0,0 +1,35 @@
module.exports = {
short: {
'#f00': 'red',
'#000080': 'navy',
'#008000': 'green',
'#008080': 'teal',
'#4b0082': 'indigo',
'#800000': 'maroon',
'#800080': 'purple',
'#808000': 'olive',
'#808080': 'gray',
'#a0522d': 'sienna',
'#a52a2a': 'brown',
'#c0c0c0': 'silver',
'#cd853f': 'peru',
'#d2b48c': 'tan',
'#da70d6': 'orchid',
'#dda0dd': 'plum',
'#ee82ee': 'violet',
'#f0e68c': 'khaki',
'#f0ffff': 'azure',
'#f5deb3': 'wheat',
'#f5f5dc': 'beige',
'#fa8072': 'salmon',
'#faf0e6': 'linen',
'#ff6347': 'tomato',
'#ff7f50': 'coral',
'#ffa500': 'orange',
'#ffc0cb': 'pink',
'#ffd700': 'gold',
'#ffe4c4': 'bisque',
'#fffafa': 'snow',
'#fffff0': 'ivory'
}
};
6 changes: 6 additions & 0 deletions lib/csswring.js
Expand Up @@ -5,6 +5,8 @@ var postcss = require('postcss');
var list = require('postcss/lib/list');
var onecolor = require('onecolor');

var shortColors = require('./color_keywords').short;

var _reQuotedString = /("|')?(.*)\1/;
var _reIdentifier = /([\x21-\x2c\x2e\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\x9f]|^([0-9]|-(-|[0-9])))/;
var _reWhiteSpaces = /\s+/g;
Expand Down Expand Up @@ -47,6 +49,10 @@ var _to3DigitHex = function (m, space, r1, r2, g1, g2, b1, b2) {
m = space + '#' + r1 + g1 + b1;
}

if (shortColors.hasOwnProperty(m)) {
m = shortColors[m];
}

return m.toLowerCase();
};

Expand Down
2 changes: 1 addition & 1 deletion test/expected/color.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/color.css
Expand Up @@ -3,4 +3,5 @@
background-color: hsL(22, 48.245823%, 34.8592227%);
color: #aa00EE;
background-image: linear-gradient(rgb(255, 255, 255), #000000);
outline-color: rgb(255, 0, 0);
}

0 comments on commit 79d5d70

Please sign in to comment.