postcss-colormin
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [5.1.0](https://github.com/cssnano/cssnano/compare/postcss-colormin@5.0.0...postcss-colormin@5.1.0) (2021-05-19) | ||
### Features | ||
* **postcss-colormin:** switch to colord and solve multiple issues ([#1107](https://github.com/cssnano/cssnano/issues/1107)) ([a7f0be4](https://github.com/cssnano/cssnano/commit/a7f0be4acc640aab89cace53a720b3d59b6f7b4f)), closes [#819](https://github.com/cssnano/cssnano/issues/819) [#1042](https://github.com/cssnano/cssnano/issues/1042) [#819](https://github.com/cssnano/cssnano/issues/819) [#771](https://github.com/cssnano/cssnano/issues/771) | ||
# [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-colormin@5.0.0-rc.2...postcss-colormin@5.0.0) (2021-04-06) | ||
@@ -8,0 +19,0 @@ |
@@ -8,5 +8,5 @@ "use strict"; | ||
var _color = _interopRequireDefault(require("color")); | ||
var _colord = require("colord"); | ||
var _keywords = _interopRequireDefault(require("./keywords.json")); | ||
var _names = _interopRequireDefault(require("colord/plugins/names")); | ||
@@ -17,43 +17,52 @@ var _toShorthand = _interopRequireDefault(require("./lib/toShorthand")); | ||
const shorter = (a, b) => (a && a.length < b.length ? a : b).toLowerCase(); | ||
(0, _colord.extend)([_names.default]); | ||
var _default = (colour, isLegacy = false, cache = false) => { | ||
const key = colour + '|' + isLegacy; | ||
var _default = (colour, isLegacy = false) => { | ||
if ((0, _colord.getFormat)(colour) === 'rgb') { | ||
/* check that it is a valid CSS value | ||
https://www.w3.org/TR/css-color-4/#rgb-functions */ | ||
let percentCount = 0; | ||
if (cache && cache[key]) { | ||
return cache[key]; | ||
for (const c of colour) { | ||
if (c === '%') { | ||
percentCount++; | ||
} | ||
} // rgb values should either be all percentages or all numbers | ||
if (percentCount !== 3 && percentCount !== 0) { | ||
return colour; | ||
} | ||
} | ||
try { | ||
const parsed = (0, _color.default)(colour.toLowerCase()); | ||
const parsed = (0, _colord.colord)(colour.toLowerCase()); | ||
if (parsed.isValid()) { | ||
const alpha = parsed.alpha(); | ||
if (alpha === 1) { | ||
const toHex = (0, _toShorthand.default)(parsed.hex().toLowerCase()); | ||
const result = shorter(_keywords.default[toHex], toHex); | ||
const toHex = (0, _toShorthand.default)(parsed.toHex()); | ||
const toName = parsed.toName(); | ||
if (cache) { | ||
cache[key] = result; | ||
if (toName && toName.length < toHex.length) { | ||
return toName; | ||
} else { | ||
return toHex; | ||
} | ||
return result; | ||
} else { | ||
const rgb = parsed.rgb(); | ||
const rgb = parsed.toRgb(); | ||
if (!isLegacy && !rgb.color[0] && !rgb.color[1] && !rgb.color[2] && !alpha) { | ||
const result = 'transparent'; | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
return result; | ||
if (!isLegacy && !rgb.r && !rgb.g && !rgb.b && !alpha) { | ||
return 'transparent'; | ||
} | ||
let hsla = parsed.hsl().string(); | ||
let rgba = rgb.string(); | ||
let result = hsla.length < rgba.length ? hsla : rgba; | ||
let hsla = parsed.toHslString(); | ||
let rgba = parsed.toRgbString(); | ||
const shortestConversion = hsla.length < rgba.length ? hsla : rgba; | ||
let result; | ||
if (cache) { | ||
cache[key] = result; | ||
if (colour.length < shortestConversion.length) { | ||
result = colour; | ||
} else { | ||
result = shortestConversion; | ||
} | ||
@@ -63,11 +72,5 @@ | ||
} | ||
} catch (e) { | ||
} else { | ||
// Possibly malformed, so pass through | ||
const result = colour; | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
return result; | ||
return colour; | ||
} | ||
@@ -74,0 +77,0 @@ }; |
@@ -14,5 +14,5 @@ "use strict"; | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
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 _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; } | ||
@@ -50,3 +50,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function transform(value, isLegacy, colorminCache) { | ||
function transform(value, isLegacy) { | ||
const parsed = (0, _postcssValueParser.default)(value); | ||
@@ -59,3 +59,3 @@ walk(parsed, (node, index, parent) => { | ||
} = node; | ||
node.value = (0, _colours.default)((0, _postcssValueParser.stringify)(node), isLegacy, colorminCache); | ||
node.value = (0, _colours.default)((0, _postcssValueParser.stringify)(node), isLegacy); | ||
node.type = 'word'; | ||
@@ -74,3 +74,3 @@ const next = parent.nodes[index + 1]; | ||
} else if (node.type === 'word') { | ||
node.value = (0, _colours.default)(node.value, isLegacy, colorminCache); | ||
node.value = (0, _colours.default)(node.value, isLegacy); | ||
} | ||
@@ -93,3 +93,2 @@ }); | ||
const isLegacy = browsers.some(hasTransparentBug); | ||
const colorminCache = {}; | ||
const cache = {}; | ||
@@ -109,3 +108,3 @@ return { | ||
const cacheKey = `${decl.prop}|${decl.value}`; | ||
const cacheKey = value + '|' + isLegacy; | ||
@@ -117,3 +116,3 @@ if (cache[cacheKey]) { | ||
const newValue = transform(value, isLegacy, colorminCache); | ||
const newValue = transform(value, isLegacy); | ||
decl.value = newValue; | ||
@@ -120,0 +119,0 @@ cache[cacheKey] = newValue; |
{ | ||
"name": "postcss-colormin", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "Minify colors in your CSS files with PostCSS.", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"prebuild": "del-cli dist", | ||
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\" && babel-node script/generate", | ||
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"", | ||
"prepublish": "yarn build" | ||
@@ -35,3 +35,3 @@ }, | ||
"browserslist": "^4.16.0", | ||
"color": "^3.1.1", | ||
"colord": "^1.7.0", | ||
"postcss-value-parser": "^4.1.0" | ||
@@ -46,8 +46,8 @@ }, | ||
"devDependencies": { | ||
"postcss": "^8.2.1" | ||
"postcss": "^8.2.15" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.2.1" | ||
"postcss": "^8.2.15" | ||
}, | ||
"gitHead": "0e2c3bf5835bafcdc8783bef66f730a24194c8f3" | ||
"gitHead": "28c247175032fa03f04911cde56ad82d74d211cc" | ||
} |
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
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
12411
7
171
+ Addedcolord@^1.7.0
+ Addedcolord@1.7.2(transitive)
- Removedcolor@^3.1.1
- Removedcolor@3.2.1(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcolor-string@1.9.1(transitive)
- Removedis-arrayish@0.3.2(transitive)
- Removedsimple-swizzle@0.2.2(transitive)