diff options
Diffstat (limited to 'node_modules/postcss-minify-selectors')
| -rw-r--r-- | node_modules/postcss-minify-selectors/CHANGELOG.md | 114 | ||||
| -rw-r--r-- | node_modules/postcss-minify-selectors/LICENSE-MIT | 22 | ||||
| -rw-r--r-- | node_modules/postcss-minify-selectors/README.md | 46 | ||||
| -rw-r--r-- | node_modules/postcss-minify-selectors/dist/index.js | 168 | ||||
| -rw-r--r-- | node_modules/postcss-minify-selectors/dist/lib/canUnquote.js | 28 | ||||
| -rw-r--r-- | node_modules/postcss-minify-selectors/dist/lib/unquote.js | 9 | ||||
| -rw-r--r-- | node_modules/postcss-minify-selectors/package.json | 62 |
7 files changed, 449 insertions, 0 deletions
diff --git a/node_modules/postcss-minify-selectors/CHANGELOG.md b/node_modules/postcss-minify-selectors/CHANGELOG.md new file mode 100644 index 00000000..c8eee780 --- /dev/null +++ b/node_modules/postcss-minify-selectors/CHANGELOG.md @@ -0,0 +1,114 @@ +# 2.1.1 + +* Fixes a compatibility issue with `modular-css` - now the module will only + use the raw selector value if it equal to the 'cleaned' selector value. + +# 2.1.0 + +* Adds support for converting between similar `:nth-child` selectors. For + example, `:nth-child(1)` can be converted to `:first-child`, and + `p:nth-last-child(2n + 1)` converts to `p:nth-last-child(odd)`. + +# 2.0.7 + +* Fixes a regression where postcss-minify-selectors would transform `[title=""]` + into `[title=]` (thanks to @arperry). + +# 2.0.6 + +* Performance tweaks; now calls `Node#toString()` ~50% less often, removed dead + branches, extracted each node type into a separate transformer function. +* Resolves an issue where extraneous whitespace around a case-insensitive + attribute selector (`[href="foo" i]`) would not be removed. + +# 2.0.5 + +* Updated postcss-selector-parser to `2.0.0`. + +# 2.0.4 + +* Now compiled with babel 6. + +# 2.0.3 + +* Fixed an issue where `[a="-"]` was incorrectly minified to `[a=-]`. + +# 2.0.2 + +* Fixed a crash with Polymer mixins; now the module will pass through any + selector string with a trailing colon. + +# 2.0.1 + +* Replaced javascript-natural-sort with alphanum-sort (thanks to @TrySound). + +# 2.0.0 + +* Upgraded to PostCSS 5. +* At-rule parameter minification was extracted out of this module into + postcss-minify-params (thanks to @TrySound). + +# 1.5.0 + +* Added support for converting pseudo elements with double colon syntax to + the single colon syntax. + +# 1.4.7 + +* Further performance improvements by using less postcss-selector-parser + iterations. + +# 1.4.6 + +* Bump normalize-selector to `0.2.0`, decreases overall package weight. +* Speed up node iteration by calling `eachInside` once rather than twice. + +# 1.4.5 + +* Update normalize-selector to cut down package weight. + +# 1.4.4 + +* Fixed an integration issue with postcss-font-magician. + +# 1.4.3 + +* Fixed an issue where `.from` was transformed to `0%`. + +# 1.4.2 + +* Bump dependencies. +* Fixes for PostCSS plugin guidelines. + +# 1.4.1 + +* Fixes incorrect deduplication of pseudo selector rules. + +# 1.4.0 + +* Update to postcss-selector-parser to greatly improve parsing logic. + +# 1.3.1 + +* Fixes a crash when nothing was passed to `node-balanced`. + +# 1.3.0 + +* Now uses the PostCSS `4.1` plugin API. + +# 1.2.1 + +* Passes original test case in issue 1. + +# 1.2.0 + +* Does not touch quoted values in attribute selectors. +* No longer will mangle values such as `2100%` in keyframes. + +# 1.1.0 + +* Now minifies `from` to `0%` and `100%` to `to` in keyframe declarations. + +# 1.0.0 + +* Initial release. diff --git a/node_modules/postcss-minify-selectors/LICENSE-MIT b/node_modules/postcss-minify-selectors/LICENSE-MIT new file mode 100644 index 00000000..fd0e863a --- /dev/null +++ b/node_modules/postcss-minify-selectors/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-minify-selectors/README.md b/node_modules/postcss-minify-selectors/README.md new file mode 100644 index 00000000..aa9ccc92 --- /dev/null +++ b/node_modules/postcss-minify-selectors/README.md @@ -0,0 +1,46 @@ +# [postcss][postcss]-minify-selectors [][ci] [][npm] [][deps] + +> Minify selectors with PostCSS. + +## Install + +With [npm](https://www.npmjs.com/package/postcss-minify-selectors) do: + +``` +npm install postcss-minify-selectors --save +``` + +## Example + +### Input + +```css +h1 + p, h2, h3, h2{color:blue} +``` + +### Output + +```css +h1+p,h2,h3{color:blue} +``` + +For more examples see the [tests](test.js). + +## Usage + +See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for +examples for your environment. + +## Contributing + +Pull requests are welcome. If you add functionality, then please add unit tests +to cover it. + +## License + +MIT © [Ben Briggs](http://beneb.info) + +[ci]: https://travis-ci.org/ben-eb/postcss-minify-selectors +[deps]: https://gemnasium.com/ben-eb/postcss-minify-selectors +[npm]: http://badge.fury.io/js/postcss-minify-selectors +[postcss]: https://github.com/postcss/postcss diff --git a/node_modules/postcss-minify-selectors/dist/index.js b/node_modules/postcss-minify-selectors/dist/index.js new file mode 100644 index 00000000..5e917fdc --- /dev/null +++ b/node_modules/postcss-minify-selectors/dist/index.js @@ -0,0 +1,168 @@ +'use strict'; + +exports.__esModule = true; + +var _postcss = require('postcss'); + +var _alphanumSort = require('alphanum-sort'); + +var _alphanumSort2 = _interopRequireDefault(_alphanumSort); + +var _has = require('has'); + +var _has2 = _interopRequireDefault(_has); + +var _postcssSelectorParser = require('postcss-selector-parser'); + +var _postcssSelectorParser2 = _interopRequireDefault(_postcssSelectorParser); + +var _unquote = require('./lib/unquote'); + +var _unquote2 = _interopRequireDefault(_unquote); + +var _canUnquote = require('./lib/canUnquote'); + +var _canUnquote2 = _interopRequireDefault(_canUnquote); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var pseudoElements = ['::before', '::after', '::first-letter', '::first-line']; + +function getParsed(selectors, callback) { + return (0, _postcssSelectorParser2.default)(callback).process(selectors).result; +} + +function attribute(selector) { + if (selector.value) { + // Join selectors that are split over new lines + selector.value = selector.value.replace(/\\\n/g, '').trim(); + if ((0, _canUnquote2.default)(selector.value)) { + selector.value = (0, _unquote2.default)(selector.value); + } + selector.operator = selector.operator.trim(); + } + if (selector.raws && selector.raws.insensitive) { + selector.raws.insensitive = ''; + } + selector.attribute = selector.attribute.trim(); +} + +function combinator(selector) { + var value = selector.value.trim(); + selector.value = value.length ? value : ' '; +} + +var pseudoReplacements = { + ':nth-child': ':first-child', + ':nth-of-type': ':first-of-type', + ':nth-last-child': ':last-child', + ':nth-last-of-type': ':last-of-type' +}; + +function pseudo(selector) { + if (selector.nodes.length === 1 && pseudoReplacements[selector.value]) { + var first = selector.at(0); + var one = first.at(0); + if (first.length === 1) { + if (one.value === '1') { + selector.replaceWith(_postcssSelectorParser2.default.pseudo({ + value: pseudoReplacements[selector.value] + })); + } + if (one.value === 'even') { + one.value = '2n'; + } + } + if (first.length === 3) { + var two = first.at(1); + var three = first.at(2); + if (one.value === '2n' && two.value === '+' && three.value === '1') { + one.value = 'odd'; + two.remove(); + three.remove(); + } + } + + return; + } + var uniques = []; + selector.walk(function (child) { + if (child.type === 'selector') { + var childStr = String(child); + if (!~uniques.indexOf(childStr)) { + uniques.push(childStr); + } else { + child.remove(); + } + } + }); + if (~pseudoElements.indexOf(selector.value)) { + selector.value = selector.value.slice(1); + } +} + +var tagReplacements = { + from: '0%', + '100%': 'to' +}; + +function tag(selector) { + var value = selector.value; + + if ((0, _has2.default)(tagReplacements, value)) { + selector.value = tagReplacements[value]; + } +} + +function universal(selector) { + var next = selector.next(); + if (next && next.type !== 'combinator') { + selector.remove(); + } +} + +var reducers = { + attribute: attribute, + combinator: combinator, + pseudo: pseudo, + tag: tag, + universal: universal +}; + +function optimise(rule) { + var selector = rule.raws.selector && rule.raws.selector.value === rule.selector ? rule.raws.selector.raw : rule.selector; + // If the selector ends with a ':' it is likely a part of a custom mixin, + // so just pass through. + if (selector[selector.length - 1] === ':') { + return; + } + rule.selector = getParsed(selector, function (selectors) { + selectors.nodes = (0, _alphanumSort2.default)(selectors.nodes, { insensitive: true }); + var uniqueSelectors = []; + selectors.walk(function (sel) { + var type = sel.type; + // Trim whitespace around the value + + sel.spaces.before = sel.spaces.after = ''; + if ((0, _has2.default)(reducers, type)) { + reducers[type](sel); + return; + } + var toString = String(sel); + if (type === 'selector' && sel.parent.type !== 'pseudo') { + if (!~uniqueSelectors.indexOf(toString)) { + uniqueSelectors.push(toString); + } else { + sel.remove(); + } + } + }); + }); +} + +exports.default = (0, _postcss.plugin)('postcss-minify-selectors', function () { + return function (css) { + return css.walkRules(optimise); + }; +}); +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/postcss-minify-selectors/dist/lib/canUnquote.js b/node_modules/postcss-minify-selectors/dist/lib/canUnquote.js new file mode 100644 index 00000000..d540c2c5 --- /dev/null +++ b/node_modules/postcss-minify-selectors/dist/lib/canUnquote.js @@ -0,0 +1,28 @@ +'use strict'; + +exports.__esModule = true; +exports.default = canUnquote; + +var _unquote = require('./unquote'); + +var _unquote2 = _interopRequireDefault(_unquote); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/** + * Can unquote attribute detection from mothereff.in + * Copyright Mathias Bynens <https://mathiasbynens.be/> + * https://github.com/mathiasbynens/mothereff.in + */ +var escapes = /\\([0-9A-Fa-f]{1,6})[ \t\n\f\r]?/g; +var range = /[\u0000-\u002c\u002e\u002f\u003A-\u0040\u005B-\u005E\u0060\u007B-\u009f]/; + +function canUnquote(value) { + value = (0, _unquote2.default)(value); + if (value === '-' || value === '') { + return false; + } + value = value.replace(escapes, 'a').replace(/\\./g, 'a'); + return !(range.test(value) || /^(?:-?\d|--)/.test(value)); +} +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/postcss-minify-selectors/dist/lib/unquote.js b/node_modules/postcss-minify-selectors/dist/lib/unquote.js new file mode 100644 index 00000000..12c21eb6 --- /dev/null +++ b/node_modules/postcss-minify-selectors/dist/lib/unquote.js @@ -0,0 +1,9 @@ +'use strict'; + +exports.__esModule = true; + +exports.default = function (string) { + return string.replace(/["']/g, ''); +}; + +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/postcss-minify-selectors/package.json b/node_modules/postcss-minify-selectors/package.json new file mode 100644 index 00000000..ba2d6255 --- /dev/null +++ b/node_modules/postcss-minify-selectors/package.json @@ -0,0 +1,62 @@ +{ + "name": "postcss-minify-selectors", + "version": "2.1.1", + "description": "Minify selectors with PostCSS.", + "main": "dist/index.js", + "files": [ + "dist", + "LICENSE-MIT" + ], + "scripts": { + "pretest": "eslint src", + "prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/", + "report": "nyc report --reporter=html", + "test": "nyc ava", + "test-012": "nyc ava" + }, + "keywords": [ + "css", + "minify", + "optimise", + "postcss", + "postcss-plugin", + "selectors" + ], + "license": "MIT", + "devDependencies": { + "ava": "^0.17.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", + "nyc": "^10.0.0", + "postcss-font-magician": "^1.4.0" + }, + "homepage": "https://github.com/ben-eb/postcss-minify-selectors", + "author": { + "name": "Ben Briggs", + "email": "beneb.info@gmail.com", + "url": "http://beneb.info" + }, + "repository": "ben-eb/postcss-minify-selectors.git", + "dependencies": { + "alphanum-sort": "^1.0.2", + "has": "^1.0.1", + "postcss": "^5.0.14", + "postcss-selector-parser": "^2.0.0" + }, + "eslintConfig": { + "extends": "cssnano" + }, + "ava": { + "require": "babel-register" + } +} |
