summaryrefslogtreecommitdiff
path: root/node_modules/postcss-colormin
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/postcss-colormin')
-rw-r--r--node_modules/postcss-colormin/LICENSE-MIT22
-rw-r--r--node_modules/postcss-colormin/README.md45
-rw-r--r--node_modules/postcss-colormin/package.json48
-rw-r--r--node_modules/postcss-colormin/src/index.js159
-rw-r--r--node_modules/postcss-colormin/src/minifyColor.js28
-rw-r--r--node_modules/postcss-colormin/types/index.d.ts10
-rw-r--r--node_modules/postcss-colormin/types/minifyColor.d.ts2
7 files changed, 314 insertions, 0 deletions
diff --git a/node_modules/postcss-colormin/LICENSE-MIT b/node_modules/postcss-colormin/LICENSE-MIT
new file mode 100644
index 00000000..fd0e863a
--- /dev/null
+++ b/node_modules/postcss-colormin/LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info)
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/postcss-colormin/README.md b/node_modules/postcss-colormin/README.md
new file mode 100644
index 00000000..5059c52b
--- /dev/null
+++ b/node_modules/postcss-colormin/README.md
@@ -0,0 +1,45 @@
+# [postcss][postcss]-colormin
+
+> Minify colors in your CSS files with PostCSS.
+
+## Install
+
+With [npm](https://npmjs.org/package/postcss-colormin) do:
+
+```
+npm install postcss-colormin --save
+```
+
+
+## Example
+
+```js
+var postcss = require('postcss')
+var colormin = require('postcss-colormin');
+
+var css = 'h1 {color: rgba(255, 0, 0, 1)}';
+console.log(postcss(colormin()).process(css).css);
+
+// => 'h1 {color:red}'
+```
+
+For more examples see the [tests](src/__tests__/index.js).
+
+
+## Usage
+
+See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
+examples for your environment.
+
+
+## Contributors
+
+See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
+
+
+## License
+
+MIT © [Ben Briggs](http://beneb.info)
+
+
+[postcss]: https://github.com/postcss/postcss
diff --git a/node_modules/postcss-colormin/package.json b/node_modules/postcss-colormin/package.json
new file mode 100644
index 00000000..388eb747
--- /dev/null
+++ b/node_modules/postcss-colormin/package.json
@@ -0,0 +1,48 @@
+{
+ "name": "postcss-colormin",
+ "version": "6.0.0",
+ "description": "Minify colors in your CSS files with PostCSS.",
+ "main": "src/index.js",
+ "types": "types/index.d.ts",
+ "files": [
+ "src",
+ "LICENSE-MIT",
+ "types"
+ ],
+ "keywords": [
+ "color",
+ "colors",
+ "compression",
+ "css",
+ "minify",
+ "postcss",
+ "postcss-plugin"
+ ],
+ "license": "MIT",
+ "homepage": "https://github.com/cssnano/cssnano",
+ "author": {
+ "name": "Ben Briggs",
+ "email": "beneb.info@gmail.com",
+ "url": "http://beneb.info"
+ },
+ "repository": "cssnano/cssnano",
+ "dependencies": {
+ "browserslist": "^4.21.4",
+ "caniuse-api": "^3.0.0",
+ "colord": "^2.9.1",
+ "postcss-value-parser": "^4.2.0"
+ },
+ "bugs": {
+ "url": "https://github.com/cssnano/cssnano/issues"
+ },
+ "engines": {
+ "node": "^14 || ^16 || >=18.0"
+ },
+ "devDependencies": {
+ "@types/caniuse-api": "^3.0.2",
+ "postcss": "^8.2.15"
+ },
+ "peerDependencies": {
+ "postcss": "^8.2.15"
+ }
+} \ No newline at end of file
diff --git a/node_modules/postcss-colormin/src/index.js b/node_modules/postcss-colormin/src/index.js
new file mode 100644
index 00000000..13ac273f
--- /dev/null
+++ b/node_modules/postcss-colormin/src/index.js
@@ -0,0 +1,159 @@
+'use strict';
+const browserslist = require('browserslist');
+const { isSupported } = require('caniuse-api');
+const valueParser = require('postcss-value-parser');
+const minifyColor = require('./minifyColor');
+
+/**
+ * @param {{nodes: valueParser.Node[]}} parent
+ * @param {(node: valueParser.Node, index: number, parent: {nodes: valueParser.Node[]}) => false | undefined} callback
+ * @return {void}
+ */
+function walk(parent, callback) {
+ parent.nodes.forEach((node, index) => {
+ const bubble = callback(node, index, parent);
+
+ if (node.type === 'function' && 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
+ */
+const browsersWithTransparentBug = new Set(['ie 8', 'ie 9']);
+const mathFunctions = new Set(['calc', 'min', 'max', 'clamp']);
+
+/**
+ * @param {valueParser.Node} node
+ * @return {boolean}
+ */
+function isMathFunctionNode(node) {
+ if (node.type !== 'function') {
+ return false;
+ }
+ return mathFunctions.has(node.value.toLowerCase());
+}
+
+/**
+ * @param {string} value
+ * @param {Record<string, boolean>} options
+ * @return {string}
+ */
+function transform(value, options) {
+ const parsed = valueParser(value);
+
+ walk(parsed, (node, index, parent) => {
+ if (node.type === 'function') {
+ if (/^(rgb|hsl)a?$/i.test(node.value)) {
+ const { value: originalValue } = node;
+
+ node.value = minifyColor(valueParser.stringify(node), options);
+ /** @type {string} */ (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 {valueParser.SpaceNode} */ ({
+ type: 'space',
+ value: ' ',
+ })
+ );
+ }
+ } else if (isMathFunctionNode(node)) {
+ return false;
+ }
+ } else if (node.type === 'word') {
+ node.value = minifyColor(node.value, options);
+ }
+ });
+
+ return parsed.toString();
+}
+
+/**
+ * @param {Record<string, boolean>} options
+ * @param {string[]} browsers
+ * @return {Record<string, boolean>}
+ */
+function addPluginDefaults(options, browsers) {
+ const defaults = {
+ // Does the browser support 4 & 8 character hex notation
+ transparent:
+ browsers.some((b) => browsersWithTransparentBug.has(b)) === false,
+ // Does the browser support "transparent" value properly
+ alphaHex: isSupported('css-rrggbbaa', browsers),
+ name: true,
+ };
+ return { ...defaults, ...options };
+}
+/**
+ * @type {import('postcss').PluginCreator<Record<string, boolean>>}
+ * @param {Record<string, boolean>} config
+ * @return {import('postcss').Plugin}
+ */
+function pluginCreator(config = {}) {
+ return {
+ postcssPlugin: 'postcss-colormin',
+
+ prepare(result) {
+ /** @type {typeof result.opts & browserslist.Options} */
+ const resultOptions = result.opts || {};
+ const browsers = browserslist(null, {
+ stats: resultOptions.stats,
+ path: __dirname,
+ env: resultOptions.env,
+ });
+
+ const cache = new Map();
+ const options = addPluginDefaults(config, browsers);
+
+ return {
+ OnceExit(css) {
+ css.walkDecls((decl) => {
+ if (
+ /^(composes|font|src$|filter|-webkit-tap-highlight-color)/i.test(
+ decl.prop
+ )
+ ) {
+ return;
+ }
+
+ const value = decl.value;
+
+ if (!value) {
+ return;
+ }
+
+ const cacheKey = JSON.stringify({ value, options, browsers });
+
+ if (cache.has(cacheKey)) {
+ decl.value = cache.get(cacheKey);
+
+ return;
+ }
+
+ const newValue = transform(value, options);
+
+ decl.value = newValue;
+ cache.set(cacheKey, newValue);
+ });
+ },
+ };
+ },
+ };
+}
+
+pluginCreator.postcss = true;
+module.exports = pluginCreator;
diff --git a/node_modules/postcss-colormin/src/minifyColor.js b/node_modules/postcss-colormin/src/minifyColor.js
new file mode 100644
index 00000000..0b287069
--- /dev/null
+++ b/node_modules/postcss-colormin/src/minifyColor.js
@@ -0,0 +1,28 @@
+'use strict';
+const { colord, extend } = require('colord');
+const namesPlugin = require('colord/plugins/names');
+const minifierPlugin = require('colord/plugins/minify');
+
+extend(/** @type {any[]} */ ([namesPlugin, minifierPlugin]));
+
+/**
+ * Performs color value minification
+ *
+ * @param {string} input - CSS value
+ * @param {Record<string, boolean>} options object with colord.minify() options
+ * @return {string}
+ */
+module.exports = function minifyColor(input, options = {}) {
+ const instance = colord(input);
+
+ if (instance.isValid()) {
+ // Try to shorten the string if it is a valid CSS color value
+ const minified = instance.minify(options);
+
+ // Fall back to the original input if it's smaller or has equal length
+ return minified.length < input.length ? minified : input.toLowerCase();
+ } else {
+ // Possibly malformed, so pass through
+ return input;
+ }
+};
diff --git a/node_modules/postcss-colormin/types/index.d.ts b/node_modules/postcss-colormin/types/index.d.ts
new file mode 100644
index 00000000..85728570
--- /dev/null
+++ b/node_modules/postcss-colormin/types/index.d.ts
@@ -0,0 +1,10 @@
+export = pluginCreator;
+/**
+ * @type {import('postcss').PluginCreator<Record<string, boolean>>}
+ * @param {Record<string, boolean>} config
+ * @return {import('postcss').Plugin}
+ */
+declare function pluginCreator(config?: Record<string, boolean>): import('postcss').Plugin;
+declare namespace pluginCreator {
+ const postcss: true;
+}
diff --git a/node_modules/postcss-colormin/types/minifyColor.d.ts b/node_modules/postcss-colormin/types/minifyColor.d.ts
new file mode 100644
index 00000000..9f504e76
--- /dev/null
+++ b/node_modules/postcss-colormin/types/minifyColor.d.ts
@@ -0,0 +1,2 @@
+declare function _exports(input: string, options?: Record<string, boolean>): string;
+export = _exports;