Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-colormin

Package Overview
Dependencies
Maintainers
7
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-colormin - npm Package Compare versions

Comparing version 2.2.2 to 4.0.0-nightly.2020.1.9

dist/colours.js

152

dist/index.js

@@ -1,78 +0,116 @@

'use strict';
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _postcss = require('postcss');
var _browserslist = _interopRequireDefault(require("browserslist"));
var _postcss2 = _interopRequireDefault(_postcss);
var _postcss = _interopRequireDefault(require("postcss"));
var _postcssValueParser = require('postcss-value-parser');
var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _colours = _interopRequireDefault(require("./colours"));
var _colormin = require('colormin');
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
var _colormin2 = _interopRequireDefault(_colormin);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function reduceWhitespaces(decl) {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (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);
}
});
}
/*
* IE 8 & 9 do not properly handle clicks on elements
* with a `transparent` `background-color`.
*
* https://developer.mozilla.org/en-US/docs/Web/Events/click#Internet_Explorer
*/
function walk(parent, callback) {
parent.nodes.forEach(function (node, index) {
var bubble = callback(node, index, parent);
if (node.nodes && bubble !== false) {
walk(node, callback);
}
});
function hasTransparentBug(browser) {
return ~['ie 8', 'ie 9'].indexOf(browser);
}
function transform(decl, opts) {
if (decl.prop === '-webkit-tap-highlight-color') {
if (decl.value === 'inherit' || decl.value === 'transparent') {
return;
function isMathFunctionNode(node) {
if (node.type !== 'function') {
return false;
}
return ['calc', 'min', 'max', 'clamp'].includes(node.value.toLowerCase());
}
function transform(value, isLegacy, colorminCache) {
const parsed = (0, _postcssValueParser.default)(value);
walk(parsed, (node, index, parent) => {
if (node.type === 'function') {
if (/^(rgb|hsl)a?$/i.test(node.value)) {
const {
value: originalValue
} = node;
node.value = (0, _colours.default)((0, _postcssValueParser.stringify)(node), isLegacy, colorminCache);
node.type = 'word';
const next = parent.nodes[index + 1];
if (node.value !== originalValue && next && (next.type === 'word' || next.type === 'function')) {
parent.nodes.splice(index + 1, 0, {
type: 'space',
value: ' '
});
}
reduceWhitespaces(decl);
return;
} else if (isMathFunctionNode(node)) {
return false;
}
} else if (node.type === 'word') {
node.value = (0, _colours.default)(node.value, isLegacy, colorminCache);
}
if (/^(composes|font|filter)/i.test(decl.prop)) {
return;
}
var ast = (0, _postcssValueParser2.default)(decl.value);
walk(ast, function (node, index, parent) {
if (node.type === 'function') {
if (/^(rgb|hsl)a?$/.test(node.value)) {
var value = node.value;
});
return parsed.toString();
}
node.value = (0, _colormin2.default)((0, _postcssValueParser.stringify)(node), opts);
node.type = 'word';
var 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 = (0, _colormin2.default)(node.value, opts);
}
var _default = _postcss.default.plugin('postcss-colormin', () => {
return (css, result) => {
const resultOpts = result.opts || {};
const browsers = (0, _browserslist.default)(null, {
stats: resultOpts.stats,
path: __dirname,
env: resultOpts.env
});
decl.value = ast.toString();
}
const isLegacy = browsers.some(hasTransparentBug);
const colorminCache = {};
const cache = {};
css.walkDecls(decl => {
if (/^(composes|font|filter|-webkit-tap-highlight-color)/i.test(decl.prop)) {
return;
}
exports.default = _postcss2.default.plugin('postcss-colormin', function () {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const value = decl.value;
return function (css) {
return css.walkDecls(function (node) {
return transform(node, opts);
});
};
if (!value) {
return;
}
const cacheKey = `${decl.prop}|${decl.value}`;
if (cache[cacheKey]) {
decl.value = cache[cacheKey];
return;
}
const newValue = transform(value, isLegacy, colorminCache);
decl.value = newValue;
cache[cacheKey] = newValue;
});
};
});
module.exports = exports['default'];
exports.default = _default;
module.exports = exports.default;
{
"name": "postcss-colormin",
"version": "2.2.2",
"version": "4.0.0-nightly.2020.1.9",
"description": "Minify colors in your CSS files with PostCSS.",

@@ -11,6 +11,5 @@ "main": "dist/index.js",

"scripts": {
"pretest": "eslint src",
"prepublish": "del-cli dist && babel src --out-dir dist --ignore /__tests__/",
"test": "ava src/__tests__",
"test-012": "ava src/__tests__"
"prebuild": "",
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\" && babel-node script/generate",
"prepublish": ""
},

@@ -27,18 +26,3 @@ "keywords": [

"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",
"homepage": "https://github.com/cssnano/cssnano",
"author": {

@@ -49,14 +33,16 @@ "name": "Ben Briggs",

},
"repository": "ben-eb/postcss-colormin",
"repository": "cssnano/cssnano",
"dependencies": {
"colormin": "^1.0.5",
"postcss": "^5.0.13",
"postcss-value-parser": "^3.2.3"
"browserslist": "^4.6.0",
"color": "^3.1.1",
"has": "^1.0.3",
"postcss": "^7.0.16",
"postcss-value-parser": "^3.3.1"
},
"eslintConfig": {
"extends": "cssnano"
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
},
"ava": {
"require": "babel-register"
"engines": {
"node": ">=10.13.0"
}
}
}

@@ -1,2 +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]
# [postcss][postcss]-colormin

@@ -29,24 +29,13 @@ > Minify colors in your CSS files with PostCSS.

## API
## Usage
### colormin([options])
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
#### options
##### legacy
## Contributors
Type: `boolean`
Default: `false`
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
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

@@ -57,5 +46,2 @@

[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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc