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

postcss-minify-gradients

Package Overview
Dependencies
Maintainers
4
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-minify-gradients - npm Package Compare versions

Comparing version 1.0.5 to 4.0.0-nightly.2020.7.24

257

dist/index.js

@@ -1,126 +0,179 @@

'use strict';
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _postcss = _interopRequireDefault(require("postcss"));
var _postcss = require('postcss');
var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
var _postcss2 = _interopRequireDefault(_postcss);
var _cssnanoUtils = require("cssnano-utils");
var _postcssValueParser = require('postcss-value-parser');
var _isColorStop = _interopRequireDefault(require("is-color-stop"));
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
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 }; }
var angles = {
top: '0deg',
right: '90deg',
bottom: '180deg',
left: '270deg'
const angles = {
top: '0deg',
right: '90deg',
bottom: '180deg',
left: '270deg'
};
function getArguments(node) {
return node.nodes.reduce(function (list, child) {
if (child.type !== 'div') {
list[list.length - 1].push(child);
} else {
list.push([]);
}
return list;
}, [[]]);
}
function isLessThan(a, b) {
return a.unit === b.unit && parseFloat(a.number) >= parseFloat(b.number);
return a.unit.toLowerCase() === b.unit.toLowerCase() && parseFloat(a.number) >= parseFloat(b.number);
}
function optimise(decl) {
if (!~decl.value.indexOf('gradient')) {
return;
const value = decl.value;
if (!value) {
return;
}
const normalizedValue = value.toLowerCase();
if (normalizedValue.includes('var(') || normalizedValue.includes('env(')) {
return;
}
if (!normalizedValue.includes('gradient')) {
return;
}
decl.value = (0, _postcssValueParser.default)(value).walk(node => {
if (node.type !== 'function' || !node.nodes.length) {
return false;
}
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
if (node.type !== 'function') {
return false;
const lowerCasedValue = node.value.toLowerCase();
if (lowerCasedValue === 'linear-gradient' || lowerCasedValue === 'repeating-linear-gradient' || lowerCasedValue === '-webkit-linear-gradient' || lowerCasedValue === '-webkit-repeating-linear-gradient') {
let args = (0, _cssnanoUtils.getArguments)(node);
if (node.nodes[0].value.toLowerCase() === 'to' && args[0].length === 3) {
node.nodes = node.nodes.slice(2);
node.nodes[0].value = angles[node.nodes[0].value.toLowerCase()];
}
let lastStop = null;
args.forEach((arg, index) => {
if (!arg[2]) {
return;
}
if (node.value === 'linear-gradient' || node.value === 'repeating-linear-gradient' || node.value === '-webkit-linear-gradient' || node.value === '-webkit-repeating-linear-gradient') {
var _ret = function () {
if (!node.nodes.length) {
return {
v: false
};
}
var args = getArguments(node);
if (node.nodes[0].value === 'to' && args[0].length === 3) {
node.nodes = node.nodes.slice(2);
node.nodes[0].value = angles[node.nodes[0].value];
}
var lastStop = null;
args.forEach(function (arg, index) {
if (!arg[2]) {
return;
}
var isFinalStop = index === args.length - 1;
var thisStop = (0, _postcssValueParser.unit)(arg[2].value);
if (lastStop === null) {
lastStop = thisStop;
if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit !== 'deg') {
arg[1].value = arg[2].value = '';
}
return;
}
if (isLessThan(lastStop, thisStop)) {
arg[2].value = 0;
}
lastStop = thisStop;
if (isFinalStop && arg[2].value === '100%') {
arg[1].value = arg[2].value = '';
}
});
return {
v: false
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
let isFinalStop = index === args.length - 1;
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
if (lastStop === null) {
lastStop = thisStop;
if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit.toLowerCase() !== 'deg') {
arg[1].value = arg[2].value = '';
}
return;
}
if (node.value === 'radial-gradient' || node.value === 'repeating-radial-gradient' || node.value === '-webkit-radial-gradient' || node.value === '-webkit-repeating-radial-gradient') {
var _ret2 = function () {
if (!node.nodes.length) {
return {
v: false
};
}
var args = getArguments(node);
var lastStop = void 0;
args.forEach(function (arg) {
if (!arg[2]) {
return;
}
var thisStop = (0, _postcssValueParser.unit)(arg[2].value);
if (!lastStop) {
lastStop = thisStop;
return;
}
if (isLessThan(lastStop, thisStop)) {
arg[2].value = 0;
}
lastStop = thisStop;
});
return {
v: false
};
}();
if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v;
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
arg[2].value = 0;
}
}).toString();
lastStop = thisStop;
if (isFinalStop && arg[2].value === '100%') {
arg[1].value = arg[2].value = '';
}
});
return false;
}
if (lowerCasedValue === 'radial-gradient' || lowerCasedValue === 'repeating-radial-gradient') {
let args = (0, _cssnanoUtils.getArguments)(node);
let lastStop;
const hasAt = args[0].find(n => n.value.toLowerCase() === 'at');
args.forEach((arg, index) => {
if (!arg[2] || !index && hasAt) {
return;
}
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
if (!lastStop) {
lastStop = thisStop;
return;
}
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
arg[2].value = 0;
}
lastStop = thisStop;
});
return false;
}
if (lowerCasedValue === '-webkit-radial-gradient' || lowerCasedValue === '-webkit-repeating-radial-gradient') {
let args = (0, _cssnanoUtils.getArguments)(node);
let lastStop;
args.forEach(arg => {
let color;
let stop;
if (arg[2] !== undefined) {
if (arg[0].type === 'function') {
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
} else {
color = arg[0].value;
}
if (arg[2].type === 'function') {
stop = `${arg[2].value}(${(0, _postcssValueParser.stringify)(arg[2].nodes)})`;
} else {
stop = arg[2].value;
}
} else {
if (arg[0].type === 'function') {
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
}
color = arg[0].value;
}
color = color.toLowerCase();
const colorStop = stop || stop === 0 ? (0, _isColorStop.default)(color, stop.toLowerCase()) : (0, _isColorStop.default)(color);
if (!colorStop || !arg[2]) {
return;
}
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
if (!lastStop) {
lastStop = thisStop;
return;
}
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
arg[2].value = 0;
}
lastStop = thisStop;
});
return false;
}
}).toString();
}
exports.default = _postcss2.default.plugin('postcss-minify-gradients', function () {
return function (css) {
return css.walkDecls(optimise);
};
var _default = _postcss.default.plugin('postcss-minify-gradients', () => {
return css => css.walkDecls(optimise);
});
module.exports = exports['default'];
exports.default = _default;
module.exports = exports.default;
{
"name": "postcss-minify-gradients",
"version": "1.0.5",
"version": "4.0.0-nightly.2020.7.24",
"description": "Minify gradient parameters with PostCSS.",
"main": "dist/index.js",
"scripts": {
"contributorAdd": "all-contributors add",
"contributorGenerate": "all-contributors generate",
"pretest": "eslint src",
"prepublish": "del-cli dist && BABEL_ENV=publish 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__/\"",
"prepublish": ""
},

@@ -24,19 +21,3 @@ "files": [

"license": "MIT",
"devDependencies": {
"all-contributors-cli": "^3.0.5",
"ava": "^0.16.0",
"babel-cli": "^6.3.17",
"babel-core": "^6.3.26",
"babel-plugin-add-module-exports": "^0.2.1",
"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-minify-gradients",
"homepage": "https://github.com/cssnano/cssnano",
"author": {

@@ -47,13 +28,15 @@ "name": "Ben Briggs",

},
"repository": "ben-eb/postcss-minify-gradients",
"repository": "cssnano/cssnano",
"dependencies": {
"postcss": "^5.0.12",
"postcss-value-parser": "^3.3.0"
"cssnano-utils": "nightly",
"is-color-stop": "^1.1.0",
"postcss": "^7.0.16",
"postcss-value-parser": "^3.3.1"
},
"ava": {
"require": "babel-register"
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
},
"eslintConfig": {
"extends": "cssnano"
"engines": {
"node": ">=6.9.0"
}
}
}

@@ -1,2 +0,2 @@

# [postcss][postcss]-minify-gradients [![Build Status](https://travis-ci.org/ben-eb/postcss-minify-gradients.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-minify-gradients.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-minify-gradients.svg)][deps]
# [postcss][postcss]-minify-gradients

@@ -46,13 +46,5 @@ > Minify gradient parameters with PostCSS.

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/ben-eb/postcss-minify-gradients/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-minify-gradients/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-minify-gradients/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[💻](https://github.com/ben-eb/postcss-minify-gradients/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/1448788?v=3" width="100px;"/><br /><sub></sub>](https://github.com/huan086)<br />[🐛](https://github.com/ben-eb/postcss-minify-gradients/issues?q=author%3Ahuan086) | [<img src="https://avatars.githubusercontent.com/u/2485494?v=3" width="100px;"/><br /><sub>Mikhail</sub>](https://github.com/jaybekster)<br />[🐛](https://github.com/ben-eb/postcss-minify-gradients/issues?q=author%3Ajaybekster) [💻](https://github.com/ben-eb/postcss-minify-gradients/commits?author=jaybekster) [⚠️](https://github.com/ben-eb/postcss-minify-gradients/commits?author=jaybekster) |
| :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors] specification. Contributions of
any kind welcome!
## License

@@ -62,7 +54,2 @@

[all-contributors]: https://github.com/kentcdodds/all-contributors
[ci]: https://travis-ci.org/ben-eb/postcss-minify-gradients
[deps]: https://gemnasium.com/ben-eb/postcss-minify-gradients
[npm]: http://badge.fury.io/js/postcss-minify-gradients
[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