postcss-colormin
Advanced tools
Comparing version 2.2.2 to 4.0.0-nightly.2020.1.9
@@ -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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
9636
0
7
191
0
5
46
1
+ Addedbrowserslist@^4.6.0
+ Addedcolor@^3.1.1
+ Addedhas@^1.0.3
+ Addedbrowserslist@4.24.2(transitive)
+ Addedcaniuse-lite@1.0.30001680(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addedelectron-to-chromium@1.5.63(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addedpicocolors@0.2.11.1.1(transitive)
+ Addedpostcss@7.0.39(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
- Removedcolormin@^1.0.5
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedclone@1.0.4(transitive)
- Removedcolor@0.11.4(transitive)
- Removedcolor-string@0.3.0(transitive)
- Removedcolormin@1.1.2(transitive)
- Removedcss-color-names@0.0.4(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-flag@1.0.0(transitive)
- Removedjs-base64@2.6.4(transitive)
- Removedpostcss@5.2.18(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.03.2.3(transitive)
Updatedpostcss@^7.0.16
Updatedpostcss-value-parser@^3.3.1