postcss-colormin
Advanced tools
Comparing version 4.0.3 to 5.0.0-alpha.0
@@ -1,19 +0,14 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _color = require('color'); | ||
var _color = _interopRequireDefault(require("color")); | ||
var _color2 = _interopRequireDefault(_color); | ||
var _keywords = _interopRequireDefault(require("./keywords.json")); | ||
var _keywords = require('./keywords.json'); | ||
var _toShorthand = _interopRequireDefault(require("./lib/toShorthand")); | ||
var _keywords2 = _interopRequireDefault(_keywords); | ||
var _toShorthand = require('./lib/toShorthand'); | ||
var _toShorthand2 = _interopRequireDefault(_toShorthand); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -23,55 +18,58 @@ | ||
exports.default = (colour, isLegacy = false, cache = false) => { | ||
const key = colour + "|" + isLegacy; | ||
var _default = (colour, isLegacy = false, cache = false) => { | ||
const key = colour + '|' + isLegacy; | ||
if (cache && cache[key]) { | ||
return cache[key]; | ||
} | ||
if (cache && cache[key]) { | ||
return cache[key]; | ||
} | ||
try { | ||
const parsed = (0, _color2.default)(colour.toLowerCase()); | ||
const alpha = parsed.alpha(); | ||
try { | ||
const parsed = (0, _color.default)(colour.toLowerCase()); | ||
const alpha = parsed.alpha(); | ||
if (alpha === 1) { | ||
const toHex = (0, _toShorthand2.default)(parsed.hex().toLowerCase()); | ||
const result = shorter(_keywords2.default[toHex], toHex); | ||
if (alpha === 1) { | ||
const toHex = (0, _toShorthand.default)(parsed.hex().toLowerCase()); | ||
const result = shorter(_keywords.default[toHex], toHex); | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
return result; | ||
} else { | ||
const rgb = parsed.rgb(); | ||
return result; | ||
} else { | ||
const rgb = parsed.rgb(); | ||
if (!isLegacy && !rgb.color[0] && !rgb.color[1] && !rgb.color[2] && !alpha) { | ||
const result = 'transparent'; | ||
if (!isLegacy && !rgb.color[0] && !rgb.color[1] && !rgb.color[2] && !alpha) { | ||
const result = 'transparent'; | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
return result; | ||
} | ||
return result; | ||
} | ||
let hsla = parsed.hsl().string(); | ||
let rgba = rgb.string(); | ||
let result = hsla.length < rgba.length ? hsla : rgba; | ||
let hsla = parsed.hsl().string(); | ||
let rgba = rgb.string(); | ||
let result = hsla.length < rgba.length ? hsla : rgba; | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
return result; | ||
} | ||
} catch (e) { | ||
// Possibly malformed, so pass through | ||
const result = colour; | ||
return result; | ||
} | ||
} catch (e) { | ||
// Possibly malformed, so pass through | ||
const result = colour; | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
if (cache) { | ||
cache[key] = result; | ||
} | ||
return result; | ||
} | ||
}; | ||
return result; | ||
} | ||
}; | ||
exports.default = _default; | ||
module.exports = exports.default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _browserslist = require("browserslist"); | ||
var _browserslist = _interopRequireDefault(require("browserslist")); | ||
var _browserslist2 = _interopRequireDefault(_browserslist); | ||
var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser")); | ||
var _postcss = require("postcss"); | ||
var _colours = _interopRequireDefault(require("./colours")); | ||
var _postcss2 = _interopRequireDefault(_postcss); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
var _postcssValueParser = require("postcss-value-parser"); | ||
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; } | ||
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser); | ||
var _colours = require("./colours"); | ||
var _colours2 = _interopRequireDefault(_colours); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function walk(parent, callback) { | ||
parent.nodes.forEach((node, index) => { | ||
const bubble = callback(node, index, parent); | ||
parent.nodes.forEach((node, index) => { | ||
const bubble = callback(node, index, parent); | ||
if (node.nodes && bubble !== false) { | ||
walk(node, callback); | ||
} | ||
}); | ||
if (node.nodes && bubble !== false) { | ||
walk(node, callback); | ||
} | ||
}); | ||
} | ||
/* | ||
@@ -42,61 +36,92 @@ * IE 8 & 9 do not properly handle clicks on elements | ||
function hasTransparentBug(browser) { | ||
return ~["ie 8", "ie 9"].indexOf(browser); | ||
return ~['ie 8', 'ie 9'].indexOf(browser); | ||
} | ||
exports.default = _postcss2.default.plugin("postcss-colormin", () => { | ||
return (css, result) => { | ||
const resultOpts = result.opts || {}; | ||
const browsers = (0, _browserslist2.default)(null, { | ||
stats: resultOpts.stats, | ||
path: __dirname, | ||
env: resultOpts.env | ||
}); | ||
const isLegacy = browsers.some(hasTransparentBug); | ||
const colorminCache = {}; | ||
const cache = {}; | ||
function isMathFunctionNode(node) { | ||
if (node.type !== 'function') { | ||
return false; | ||
} | ||
css.walkDecls(decl => { | ||
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: ' ' | ||
}); | ||
} | ||
} else if (isMathFunctionNode(node)) { | ||
return false; | ||
} | ||
} else if (node.type === 'word') { | ||
node.value = (0, _colours.default)(node.value, isLegacy, colorminCache); | ||
} | ||
}); | ||
return parsed.toString(); | ||
} | ||
function pluginCreator() { | ||
return { | ||
postcssPlugin: 'postcss-colormin', | ||
prepare(result) { | ||
const resultOpts = result.opts || {}; | ||
const browsers = (0, _browserslist.default)(null, { | ||
stats: resultOpts.stats, | ||
path: __dirname, | ||
env: resultOpts.env | ||
}); | ||
const isLegacy = browsers.some(hasTransparentBug); | ||
const colorminCache = {}; | ||
const cache = {}; | ||
return { | ||
OnceExit(css) { | ||
css.walkDecls(decl => { | ||
if (/^(composes|font|filter|-webkit-tap-highlight-color)/i.test(decl.prop)) { | ||
return; | ||
return; | ||
} | ||
if (cache[decl.value]) { | ||
decl.value = cache[decl.value]; | ||
const value = decl.value; | ||
return; | ||
if (!value) { | ||
return; | ||
} | ||
const parsed = (0, _postcssValueParser2.default)(decl.value); | ||
const cacheKey = `${decl.prop}|${decl.value}`; | ||
walk(parsed, (node, index, parent) => { | ||
if (node.type === "function") { | ||
if (/^(rgb|hsl)a?$/i.test(node.value)) { | ||
const { value } = node; | ||
if (cache[cacheKey]) { | ||
decl.value = cache[cacheKey]; | ||
return; | ||
} | ||
node.value = (0, _colours2.default)((0, _postcssValueParser.stringify)(node), isLegacy, colorminCache); | ||
node.type = "word"; | ||
const newValue = transform(value, isLegacy, colorminCache); | ||
decl.value = newValue; | ||
cache[cacheKey] = newValue; | ||
}); | ||
} | ||
const next = parent.nodes[index + 1]; | ||
}; | ||
} | ||
if (node.value !== value && next && (next.type === "word" || next.type === "function")) { | ||
parent.nodes.splice(index + 1, 0, { | ||
type: "space", | ||
value: " " | ||
}); | ||
} | ||
} else if (node.value.toLowerCase() === "calc") { | ||
return false; | ||
} | ||
} else if (node.type === "word") { | ||
node.value = (0, _colours2.default)(node.value, isLegacy, colorminCache); | ||
} | ||
}); | ||
}; | ||
} | ||
const optimizedValue = parsed.toString(); | ||
decl.value = optimizedValue; | ||
cache[decl.value] = optimizedValue; | ||
}); | ||
}; | ||
}); | ||
pluginCreator.postcss = true; | ||
var _default = pluginCreator; | ||
exports.default = _default; | ||
module.exports = exports.default; |
@@ -1,13 +0,17 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
exports.default = hex => { | ||
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) { | ||
return '#' + hex[2] + hex[4] + hex[6]; | ||
} | ||
var _default = hex => { | ||
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) { | ||
return '#' + hex[2] + hex[4] + hex[6]; | ||
} | ||
return hex; | ||
}; | ||
return hex; | ||
}; | ||
exports.default = _default; | ||
module.exports = exports.default; |
{ | ||
"name": "postcss-colormin", | ||
"version": "4.0.3", | ||
"version": "5.0.0-alpha.0", | ||
"description": "Minify colors in your CSS files with PostCSS.", | ||
@@ -11,3 +11,5 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"prepublish": "cross-env BABEL_ENV=publish babel-node ./src/generate.js && babel src --out-dir dist --ignore /__tests__/,src/generate.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", | ||
"prepublish": "yarn build" | ||
}, | ||
@@ -24,8 +26,2 @@ "keywords": [ | ||
"license": "MIT", | ||
"devDependencies": { | ||
"babel-cli": "^6.0.0", | ||
"cross-env": "^5.0.0", | ||
"css-color-names": "0.0.4", | ||
"write-file": "^1.0.0" | ||
}, | ||
"homepage": "https://github.com/cssnano/cssnano", | ||
@@ -39,7 +35,5 @@ "author": { | ||
"dependencies": { | ||
"browserslist": "^4.0.0", | ||
"color": "^3.0.0", | ||
"has": "^1.0.0", | ||
"postcss": "^7.0.0", | ||
"postcss-value-parser": "^3.0.0" | ||
"browserslist": "^4.16.0", | ||
"color": "^3.1.1", | ||
"postcss-value-parser": "^4.1.0" | ||
}, | ||
@@ -50,4 +44,11 @@ "bugs": { | ||
"engines": { | ||
"node": ">=6.9.0" | ||
} | ||
"node": "^10 || ^12 || >=14.0" | ||
}, | ||
"devDependencies": { | ||
"postcss": "^8.2.1" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.2.1" | ||
}, | ||
"gitHead": "023c532464a06ccea2951fd6e5d2949b3b29e7bd" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a 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
11695
4
1
8
199
1
1
+ Addedelectron-to-chromium@1.5.63(transitive)
+ Addednanoid@3.3.7(transitive)
+ Addedpostcss@8.4.49(transitive)
+ Addedpostcss-value-parser@4.2.0(transitive)
+ Addedsource-map-js@1.2.1(transitive)
- Removedhas@^1.0.0
- Removedpostcss@^7.0.0
- Removedelectron-to-chromium@1.5.59(transitive)
- Removedhas@1.0.4(transitive)
- Removedpicocolors@0.2.1(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedpostcss-value-parser@3.3.1(transitive)
- Removedsource-map@0.6.1(transitive)
Updatedbrowserslist@^4.16.0
Updatedcolor@^3.1.1
Updatedpostcss-value-parser@^4.1.0