Skip to content

Commit

Permalink
refactor(postcss-merge-longhand): remove css-color-names dep (#1230)
Browse files Browse the repository at this point in the history
css-color-names is a JSON file with a mapping from color name to hex:

1. we don't use the hex code
2. CSS4 color spec says color names are not recommended,
   so unlikely new color names will be added
3. even if we need to add a color, it is easier to add it ourselves
   than to open a PR upstream
4. css-color-names sources the color names from w3schools instead of the spec
5. css-color-names is not future-proof because it exports a JSON file
  • Loading branch information
ludofischer committed Nov 13, 2021
1 parent a519ff5 commit 0717282
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 9 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -31,7 +31,6 @@
"camelcase": "^6.2.0",
"chalk": "^4.1.0",
"cross-env": "^7.0.3",
"css-color-names": "^1.0.1",
"diff": "^5.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
1 change: 0 additions & 1 deletion packages/postcss-merge-longhand/package.json
Expand Up @@ -28,7 +28,6 @@
},
"repository": "cssnano/cssnano",
"dependencies": {
"css-color-names": "^1.0.1",
"postcss-value-parser": "^4.1.0",
"stylehacks": "^5.0.1"
},
Expand Down
151 changes: 151 additions & 0 deletions packages/postcss-merge-longhand/src/lib/colornames.js
@@ -0,0 +1,151 @@
/* https://www.w3.org/TR/css-color-4/#named-colors */
export default [
'aliceblue',
'antiquewhite',
'aqua',
'aquamarine',
'azure',
'beige',
'bisque',
'black',
'blanchedalmond',
'blue',
'blueviolet',
'brown',
'burlywood',
'cadetblue',
'chartreuse',
'chocolate',
'coral',
'cornflowerblue',
'cornsilk',
'crimson',
'cyan',
'darkblue',
'darkcyan',
'darkgoldenrod',
'darkgray',
'darkgreen',
'darkgrey',
'darkkhaki',
'darkmagenta',
'darkolivegreen',
'darkorange',
'darkorchid',
'darkred',
'darksalmon',
'darkseagreen',
'darkslateblue',
'darkslategray',
'darkslategrey',
'darkturquoise',
'darkviolet',
'deeppink',
'deepskyblue',
'dimgray',
'dimgrey',
'dodgerblue',
'firebrick',
'floralwhite',
'forestgreen',
'fuchsia',
'gainsboro',
'ghostwhite',
'gold',
'goldenrod',
'gray',
'green',
'greenyellow',
'grey',
'honeydew',
'hotpink',
'indianred',
'indigo',
'ivory',
'khaki',
'lavender',
'lavenderblush',
'lawngreen',
'lemonchiffon',
'lightblue',
'lightcoral',
'lightcyan',
'lightgoldenrodyellow',
'lightgray',
'lightgreen',
'lightgrey',
'lightpink',
'lightsalmon',
'lightseagreen',
'lightskyblue',
'lightslategray',
'lightslategrey',
'lightsteelblue',
'lightyellow',
'lime',
'limegreen',
'linen',
'magenta',
'maroon',
'mediumaquamarine',
'mediumblue',
'mediumorchid',
'mediumpurple',
'mediumseagreen',
'mediumslateblue',
'mediumspringgreen',
'mediumturquoise',
'mediumvioletred',
'midnightblue',
'mintcream',
'mistyrose',
'moccasin',
'navajowhite',
'navy',
'oldlace',
'olive',
'olivedrab',
'orange',
'orangered',
'orchid',
'palegoldenrod',
'palegreen',
'paleturquoise',
'palevioletred',
'papayawhip',
'peachpuff',
'peru',
'pink',
'plum',
'powderblue',
'purple',
'rebeccapurple',
'red',
'rosybrown',
'royalblue',
'saddlebrown',
'salmon',
'sandybrown',
'seagreen',
'seashell',
'sienna',
'silver',
'skyblue',
'slateblue',
'slategray',
'slategrey',
'snow',
'springgreen',
'steelblue',
'tan',
'teal',
'thistle',
'tomato',
'turquoise',
'violet',
'wheat',
'white',
'whitesmoke',
'yellow',
'yellowgreen',
];
3 changes: 1 addition & 2 deletions packages/postcss-merge-longhand/src/lib/validateWsc.js
@@ -1,4 +1,4 @@
import colorNames from 'css-color-names';
import colors from './colornames.js';

const widths = ['thin', 'medium', 'thick'];
const styles = [
Expand All @@ -13,7 +13,6 @@ const styles = [
'inset',
'outset',
];
const colors = Object.keys(colorNames);

export function isStyle(value) {
return value && !!~styles.indexOf(value.toLowerCase());
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Expand Up @@ -2223,11 +2223,6 @@ cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

css-color-names@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-1.0.1.tgz#6ff7ee81a823ad46e020fa2fd6ab40a887e2ba67"
integrity sha512-/loXYOch1qU1biStIFsHH8SxTmOseh1IJqFvy8IujXOm1h+QjUdDhkzOrR5HG8K8mlxREj0yfi8ewCHx0eMxzA==

css-declaration-sorter@^6.0.3:
version "6.1.3"
resolved "https://registry.yarnpkg.com/css-declaration-sorter/-/css-declaration-sorter-6.1.3.tgz#e9852e4cf940ba79f509d9425b137d1f94438dc2"
Expand Down

0 comments on commit 0717282

Please sign in to comment.