pax_global_header00006660000000000000000000000064130461321470014513gustar00rootroot0000000000000052 comment=538bce656e50ad9172b607edb4f020e941939eeb postcss-colormin-2.2.2/000077500000000000000000000000001304613214700150345ustar00rootroot00000000000000postcss-colormin-2.2.2/.babelrc000066400000000000000000000001221304613214700164220ustar00rootroot00000000000000{ "presets": ["es2015-loose", "stage-0"], "plugins": ["add-module-exports"] } postcss-colormin-2.2.2/.editorconfig000066400000000000000000000002461304613214700175130ustar00rootroot00000000000000# editorconfig.org root = true [*] indent_style = space indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true postcss-colormin-2.2.2/.gitignore000066400000000000000000000000401304613214700170160ustar00rootroot00000000000000node_modules npm-debug.log dist postcss-colormin-2.2.2/.travis.yml000066400000000000000000000003141304613214700171430ustar00rootroot00000000000000sudo: false language: node_js matrix: include: - node_js: '5' - node_js: '4' - node_js: '0.12' env: NO_ESLINT=true script: "[[ $NO_ESLINT == true ]] && npm run test-012 || npm test" postcss-colormin-2.2.2/CHANGELOG.md000066400000000000000000000045601304613214700166520ustar00rootroot00000000000000# 2.2.2 * Resolves an issue where the module would mangle the non-standard `composes` property when consumed via css-loader. # 2.2.1 * Resolves an issue where converting an rgb/hsl function next to another token, such as `linear-gradient(rgb(10, 10, 10)0%, blue)` would result in a mangled value. # 2.2.0 * Adds support for legacy IE versions (< 10). # 2.1.8 * Fixes incorrect minification of percentages used by `rgb` functions; i.e. `rgb(100%,100%,100%)` was not converted correctly to `#fff`. # 2.1.7 * Fixes another regression where `hsla(0,0%,100%,.5)` was converted to `hsla(0,0%,100%,0.5)`. # 2.1.6 * Fixes a regression where codes for `rgba` & `hsla` were not correctly capped at minimum/maximum values. # 2.1.5 * Fixes several regressions from 2.1.3 - shorthand hex color minification, incorrect conversion to `transparent` from `rgba(255, 255, 255, 0)` (thanks to @TrySound). # 2.1.4 * Fixes an error in the last patch where the `lib` directory was ignored by npm. # 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 * Removed an unnecessary `trim` method that was used to work around a now resolved issue in PostCSS (thanks to @TrySound). # 2.1.1 * Fixed a regression that was compressing space around forward slashes in calc functions. # 2.1.0 * Better support for minifying colors in legacy CSS gradients, switched to postcss-value-parser (thanks to @TrySound). # 2.0.0 * Upgraded to PostCSS 5. # 1.2.7 * Fixes an issue where IE filter properties were being converted erroneously (thanks to @faddee). # 1.2.6 * Fixed a crash when specifying `inherit` as a value to `-webkit-tap-highlight-color`. # 1.2.5 * Speed up node iteration by calling `eachDecl` once rather than twice. # 1.2.4 * Fixed an issue caused by upgrading colormin to use ES6. # 1.2.3 * Fixed an issue where `-webkit-tap-highlight-color` was being incorrectly transformed to `transparent`. This is not supported in Safari. # 1.2.2 * Fixed a bug where the module crashed on parsing comma separated values for properties such as `box-shadow`. # 1.2.1 * Extracted each color logic into a function for better readability. # 1.2.0 * Now uses the PostCSS `4.1` plugin API. # 1.1.0 * Now supports optimisation of colors in gradient values. # 1.0.0 * Initial release. postcss-colormin-2.2.2/LICENSE-MIT000066400000000000000000000021041304613214700164650ustar00rootroot00000000000000Copyright (c) Ben Briggs (http://beneb.info) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. postcss-colormin-2.2.2/README.md000066400000000000000000000025231304613214700163150ustar00rootroot00000000000000# [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. ## Install With [npm](https://npmjs.org/package/postcss-colormin) do: ``` npm install postcss-colormin --save ``` ## Example ```js var postcss = require('postcss') var colormin = require('postcss-colormin'); var css = 'h1 {color: rgba(255, 0, 0, 1)}'; console.log(postcss(colormin()).process(css).css); // => 'h1 {color:red}' ``` For more examples see the [tests](src/__tests__/index.js). ## API ### colormin([options]) #### options ##### legacy Type: `boolean` Default: `false` Set this to `true` to enable IE < 10 compatibility; the browser chokes on the `transparent` keyword, so in this mode the conversion from `rgba(0,0,0,0)` is turned off. ## Contributing Pull requests are welcome. If you add functionality, then please add unit tests to cover it. ## License MIT © [Ben Briggs](http://beneb.info) [ci]: https://travis-ci.org/ben-eb/postcss-colormin [deps]: https://gemnasium.com/ben-eb/postcss-colormin [npm]: http://badge.fury.io/js/postcss-colormin [postcss]: https://github.com/postcss/postcss postcss-colormin-2.2.2/package.json000066400000000000000000000026431304613214700173270ustar00rootroot00000000000000{ "name": "postcss-colormin", "version": "2.2.2", "description": "Minify colors in your CSS files with PostCSS.", "main": "dist/index.js", "files": [ "dist", "LICENSE-MIT" ], "scripts": { "pretest": "eslint src", "prepublish": "del-cli dist && babel src --out-dir dist --ignore /__tests__/", "test": "ava src/__tests__", "test-012": "ava src/__tests__" }, "keywords": [ "color", "colors", "compression", "css", "minify", "postcss", "postcss-plugin" ], "license": "MIT", "devDependencies": { "ava": "^0.17.0", "babel-cli": "^6.3.17", "babel-core": "^6.3.26", "babel-plugin-add-module-exports": "^0.2.0", "babel-preset-es2015": "^6.3.13", "babel-preset-es2015-loose": "^7.0.0", "babel-preset-stage-0": "^6.3.13", "babel-register": "^6.9.0", "del-cli": "^0.2.0", "eslint": "^3.0.0", "eslint-config-cssnano": "^3.0.0", "eslint-plugin-babel": "^3.3.0", "eslint-plugin-import": "^2.0.1" }, "homepage": "https://github.com/ben-eb/postcss-colormin", "author": { "name": "Ben Briggs", "email": "beneb.info@gmail.com", "url": "http://beneb.info" }, "repository": "ben-eb/postcss-colormin", "dependencies": { "colormin": "^1.0.5", "postcss": "^5.0.13", "postcss-value-parser": "^3.2.3" }, "eslintConfig": { "extends": "cssnano" }, "ava": { "require": "babel-register" } } postcss-colormin-2.2.2/src/000077500000000000000000000000001304613214700156235ustar00rootroot00000000000000postcss-colormin-2.2.2/src/__tests__/000077500000000000000000000000001304613214700175615ustar00rootroot00000000000000postcss-colormin-2.2.2/src/__tests__/index.js000066400000000000000000000127231304613214700212330ustar00rootroot00000000000000import test from 'ava'; import postcss from 'postcss'; import plugin from '..'; import {name} from '../../package.json'; const tests = [{ message: 'should minify color values', fixture: 'h1{color:yellow}', expected: 'h1{color:#ff0}', }, { message: 'should minify color values (2)', fixture: 'h1{box-shadow:0 1px 3px rgba(255, 230, 220, 0.5)}', expected: 'h1{box-shadow:0 1px 3px rgba(255,230,220,.5)}', }, { message: 'should minify color values (3)', fixture: 'h1{background:hsla(134, 50%, 50%, 1)}', expected: 'h1{background:#40bf5e}', }, { message: 'should minify color values (4)', fixture: 'h1{text-shadow:1px 1px 2px #000000}', expected: 'h1{text-shadow:1px 1px 2px #000}', }, { message: 'should minify color values (5)', fixture: 'h1{text-shadow:1px 1px 2px rgb(255, 255, 255)}', expected: 'h1{text-shadow:1px 1px 2px #fff}', }, { message: 'should minify color values (5)', fixture: 'h1{text-shadow:1px 1px 2px hsl(0,0%,100%)}', expected: 'h1{text-shadow:1px 1px 2px #fff}', }, { message: 'should minify color values in background gradients', fixture: 'h1{background:linear-gradient( #ff0000,yellow )}', expected: 'h1{background:linear-gradient( red,#ff0 )}', }, { message: 'should minify color values in background gradients (2)', fixture: 'h1{background:linear-gradient(yellow, orange), linear-gradient(black, rgba(255, 255, 255, 0))}', expected: 'h1{background:linear-gradient(#ff0, orange), linear-gradient(#000, hsla(0,0%,100%,0))}', }, { message: 'should minify color values in background gradients (3)', fixture: 'h1{background:linear-gradient(0deg, yellow, black 40%, red)}', expected: 'h1{background:linear-gradient(0deg, #ff0, #000 40%, red)}', }, { message: 'should not minify in font properties', fixture: 'h1{font-family:black}', expected: 'h1{font-family:black}', }, { message: 'should correctly parse multiple box shadow values', fixture: 'h1{box-shadow:inset 0 1px 1px rgba(0, 0, 0, .075),0 0 8px rgba(102, 175, 233, .6)}', expected: 'h1{box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}', }, { message: 'should make an exception for webkit tap highlight color (issue 1)', fixture: 'h1{-webkit-tap-highlight-color:rgba(0,0,0,0)}', expected: 'h1{-webkit-tap-highlight-color:rgba(0,0,0,0)}', }, { message: 'should still minify spaces in webkit tap highlight color', fixture: 'h1{-webkit-tap-highlight-color:rgba( 0, 0, 0, 0)}', expected: 'h1{-webkit-tap-highlight-color:rgba(0,0,0,0)}', }, { message: 'should not crash on transparent in webkit tap highlight color', fixture: 'h1{-webkit-tap-highlight-color:transparent}', expected: 'h1{-webkit-tap-highlight-color:transparent}', }, { message: 'should not crash on inherit in webkit tap highlight color', fixture: 'h1{-webkit-tap-highlight-color:inherit}', expected: 'h1{-webkit-tap-highlight-color:inherit}', }, { message: 'should not minify in filter properties', fixture: 'h1{filter:progid:DXImageTransform.Microsoft.gradient(startColorstr= #000000,endColorstr= #ffffff);}', expected: 'h1{filter:progid:DXImageTransform.Microsoft.gradient(startColorstr= #000000,endColorstr= #ffffff);}', }, { message: 'should minify color stops', fixture: 'h1{background-image:-webkit-gradient(linear,50% 0%,50% 100%,color-stop(1px, #fbfbfb),color-stop(1px, #ffffff),color-stop(2px, #ffffff),color-stop(2px, #fbfbfb),color-stop(100%, #ececec))}', expected: 'h1{background-image:-webkit-gradient(linear,50% 0%,50% 100%,color-stop(1px, #fbfbfb),color-stop(1px, #fff),color-stop(2px, #fff),color-stop(2px, #fbfbfb),color-stop(100%, #ececec))}', }, { message: 'should not minify in calc values', fixture: 'h1{width:calc(100vw / 2 - 6px + 0)}', expected: 'h1{width:calc(100vw / 2 - 6px + 0)}', }, { message: 'should minify hex colors without keywords', fixture: 'h1{background:linear-gradient(#ffffff,#999999) no-repeat;}', expected: 'h1{background:linear-gradient(#fff,#999) no-repeat;}', }, { message: 'should not mangle percentage based rgba values', fixture: 'h1{color:rgba(50%,50%,50%,0.5)}', expected: 'h1{color:hsla(0,0%,50%,.5)}', }, { message: 'should convert percentage based rgba values', fixture: 'h1{color:rgb(100%,100%,100%)}', expected: 'h1{color:#fff}', }, { message: 'should handle errored cases', fixture: 'h1{color:rgb(50%, 23, 54)}', expected: 'h1{color:rgb(50%, 23, 54)}', }, { message: 'should add extra spaces when converting rgb', fixture: 'h1{background:linear-gradient(rgb(50, 50, 50)0%,blue 100%)}', expected: 'h1{background:linear-gradient(#323232 0%,blue 100%)}', }, { message: 'should add extra spaces when converting rgb (2)', fixture: 'h1{background:linear-gradient(rgba(0,0,0,0)0%, blue 100%)}', expected: 'h1{background:linear-gradient(transparent 0%, blue 100%)}', }, { message: 'should bail on the "composes" property', fixture: 'h1{composes:black from "styles"}', expected: 'h1{composes:black from "styles"}', }]; function process (css, options) { return postcss(plugin(options)).process(css).css; } tests.forEach(({message, fixture, expected, options = {}}) => { test(message, t => { t.deepEqual(process(fixture, options), expected); }); }); test('should use the postcss plugin api', t => { t.truthy(plugin().postcssVersion, 'should be able to access version'); t.deepEqual(plugin().postcssPlugin, name, 'should be able to access name'); }); postcss-colormin-2.2.2/src/index.js000066400000000000000000000034151304613214700172730ustar00rootroot00000000000000import postcss from 'postcss'; import valueParser, {stringify} from 'postcss-value-parser'; import colormin from 'colormin'; function reduceWhitespaces (decl) { decl.value = valueParser(decl.value).walk(node => { if (node.type === 'function' || node.type === 'div') { node.before = node.after = ''; } }).toString(); } function walk (parent, callback) { parent.nodes.forEach((node, index) => { const bubble = callback(node, index, parent); if (node.nodes && bubble !== false) { walk(node, callback); } }); } function transform (decl, opts) { if (decl.prop === '-webkit-tap-highlight-color') { if (decl.value === 'inherit' || decl.value === 'transparent') { return; } reduceWhitespaces(decl); return; } if (/^(composes|font|filter)/i.test(decl.prop)) { return; } const ast = valueParser(decl.value); walk(ast, (node, index, parent) => { if (node.type === 'function') { if (/^(rgb|hsl)a?$/.test(node.value)) { const {value} = node; node.value = colormin(stringify(node), opts); node.type = 'word'; const next = parent.nodes[index + 1]; if (node.value !== value && next && next.type === 'word') { parent.nodes.splice(index + 1, 0, {type: 'space', value: ' '}); } } else if (node.value === 'calc') { return false; } } else { node.value = colormin(node.value, opts); } }); decl.value = ast.toString(); } export default postcss.plugin('postcss-colormin', (opts = {}) => { return css => css.walkDecls(node => transform(node, opts)); });