From 26105034da4fcce7ac883c899d781f016559310d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 8 Nov 2018 00:38:48 +0800 Subject: switch to vuepress --- node_modules/postcss-zindex/CHANGELOG.md | 50 +++++++++++++++ node_modules/postcss-zindex/LICENSE-MIT | 22 +++++++ node_modules/postcss-zindex/README.md | 89 +++++++++++++++++++++++++++ node_modules/postcss-zindex/index.js | 39 ++++++++++++ node_modules/postcss-zindex/lib/layerCache.js | 48 +++++++++++++++ node_modules/postcss-zindex/package.json | 43 +++++++++++++ 6 files changed, 291 insertions(+) create mode 100644 node_modules/postcss-zindex/CHANGELOG.md create mode 100644 node_modules/postcss-zindex/LICENSE-MIT create mode 100644 node_modules/postcss-zindex/README.md create mode 100644 node_modules/postcss-zindex/index.js create mode 100644 node_modules/postcss-zindex/lib/layerCache.js create mode 100644 node_modules/postcss-zindex/package.json (limited to 'node_modules/postcss-zindex') diff --git a/node_modules/postcss-zindex/CHANGELOG.md b/node_modules/postcss-zindex/CHANGELOG.md new file mode 100644 index 00000000..236b2da1 --- /dev/null +++ b/node_modules/postcss-zindex/CHANGELOG.md @@ -0,0 +1,50 @@ +# 2.2.0 + +* Added an option to set the starting index, useful to mitigate conflicts with + third-party CSS files. +* Performance improvements, including O(1) lookup of cached values rather than + O(n), aborting PostCSS walk altogether when a negative index is found, and + not running an optimize step if there are no z-index declarations. + +# 2.1.1 + +* Fixes an issue where all positive indices before a negative index were + transformed (thanks to @niccai). + +# 2.1.0 + +* Now aborts early when encountering negative indices, making the transform + safer overall. + +# 2.0.1 + +* Improved performance of the module by sorting/deduplicating values in one pass + instead of per-value (thanks to @pgilad). + +# 2.0.0 + +* Upgraded to PostCSS 5. + +# 1.1.3 + +* Improved performance by iterating the AST in a single pass and caching nodes for the second iteration. + +# 1.1.2 + +* Documentation/metadata tweaks for plugin guidelines compatibility. + +# 1.1.1 + +* Corrected dependency tree when installing from npm. + +# 1.1.0 + +* Now uses the PostCSS `4.1` plugin API. + +# 1.0.1 + +* Adds a JSHint config, code tidied up. + +# 1.0.0 + +* Initial release. diff --git a/node_modules/postcss-zindex/LICENSE-MIT b/node_modules/postcss-zindex/LICENSE-MIT new file mode 100644 index 00000000..fd0e863a --- /dev/null +++ b/node_modules/postcss-zindex/LICENSE-MIT @@ -0,0 +1,22 @@ +Copyright (c) Ben Briggs (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-zindex/README.md b/node_modules/postcss-zindex/README.md new file mode 100644 index 00000000..e27eacf3 --- /dev/null +++ b/node_modules/postcss-zindex/README.md @@ -0,0 +1,89 @@ +# [postcss][postcss]-zindex [![Build Status](https://travis-ci.org/ben-eb/postcss-zindex.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-zindex.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-zindex.svg)][deps] + +> Reduce z-index values with PostCSS. + +## Install + +With [npm](https://npmjs.org/package/postcss-zindex) do: + +``` +npm install postcss-zindex --save +``` + +## Example + +Sometimes, you may introduce z-index values into your CSS that are larger than +necessary, in order to improve your understanding of how each stack relates to +the others. For example, you might have a modal overlay at `5000` and the dialog +for it at `5500` - so that modal classes occupy the `5xxx` space. + +But in production, it is unnecessary to use such large values for z-index where +smaller values would suffice. This module will reduce all z-index declarations +whilst respecting your original intent; such that the overlay becomes `1` and +the dialog becomes `2`. For more examples, see the [tests](test.js). + +### Input + +```css +.modal { + z-index: 5000 +} + +.modal-overlay { + z-index: 5500 +} +``` + +### Output + +```css +.modal { + z-index: 1 +} + +.modal-overlay { + z-index: 2 +} +``` + +Note that this module does not attempt to normalize relative z-index values, +such as `-1`; indeed, it will abort immediately when encountering these values +as it cannot be sure that rebasing mixed positive & negative values will keep +the stacking context intact. Be careful with using this module alongside +JavaScript injected CSS; ideally you should have already extracted all of your +stacking context into CSS. + +## API + +### zindex([options]) + +#### options + +##### startIndex + +Type: `number` +Default: `1` + +Set this to any other positive integer if you want to override z-indices from +other sources outside your control. For example if a third party widget has a +maximum z-index of `99`, you can set this to `100` and not have to worry about +stacking conflicts. + +## 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-zindex +[deps]: https://gemnasium.com/ben-eb/postcss-zindex +[npm]: http://badge.fury.io/js/postcss-zindex +[postcss]: https://github.com/postcss/postcss diff --git a/node_modules/postcss-zindex/index.js b/node_modules/postcss-zindex/index.js new file mode 100644 index 00000000..aa118363 --- /dev/null +++ b/node_modules/postcss-zindex/index.js @@ -0,0 +1,39 @@ +'use strict'; + +var postcss = require('postcss'); + +module.exports = postcss.plugin('postcss-zindex', function (opts) { + opts = opts || {}; + return function (css) { + var cache = require('./lib/layerCache')(opts); + var nodes = []; + var abort = false; + // First pass; cache all z indexes + css.walkDecls('z-index', function (decl) { + // Check that no negative values exist. Rebasing is only + // safe if all indices are positive numbers. + if (decl.value[0] === '-') { + abort = true; + // Stop PostCSS iterating through the rest of the decls + return false; + } + nodes.push(decl); + cache.addValue(decl.value); + }); + + // Abort if we found any negative values + // or there are no z-index declarations + if (abort || !nodes.length) { + return; + } + + cache.optimizeValues(); + + // Second pass; optimize + nodes.forEach(function (decl) { + // Need to coerce to string so that the + // AST is updated correctly + decl.value = cache.getValue(decl.value).toString(); + }); + }; +}); diff --git a/node_modules/postcss-zindex/lib/layerCache.js b/node_modules/postcss-zindex/lib/layerCache.js new file mode 100644 index 00000000..b6433c60 --- /dev/null +++ b/node_modules/postcss-zindex/lib/layerCache.js @@ -0,0 +1,48 @@ +'use strict'; + +var has = require('has'); +var uniq = require('uniqs'); + +function LayerCache (opts) { + if (!(this instanceof LayerCache)) { + return new LayerCache(opts); + } + this._values = []; + this._startIndex = opts.startIndex || 1; +} + +function ascending (a, b) { + return a - b; +} + +function reduceValues (list, value, index) { + list[value] = index + this._startIndex; + return list; +} + +LayerCache.prototype._findValue = function (value) { + if (has(this._values, value)) { + return this._values[value]; + } + return false; +}; + +LayerCache.prototype.optimizeValues = function () { + this._values = uniq(this._values).sort(ascending).reduce(reduceValues.bind(this), {}); +}; + +LayerCache.prototype.addValue = function (value) { + var parsedValue = parseInt(value, 10); + // pass only valid values + if (!parsedValue || parsedValue < 0) { + return; + } + this._values.push(parsedValue); +}; + +LayerCache.prototype.getValue = function (value) { + var parsedValue = parseInt(value, 10); + return this._findValue(parsedValue) || value; +}; + +module.exports = LayerCache; diff --git a/node_modules/postcss-zindex/package.json b/node_modules/postcss-zindex/package.json new file mode 100644 index 00000000..14580012 --- /dev/null +++ b/node_modules/postcss-zindex/package.json @@ -0,0 +1,43 @@ +{ + "name": "postcss-zindex", + "version": "2.2.0", + "description": "Reduce z-index values with PostCSS.", + "main": "index.js", + "scripts": { + "lint": "jshint index.js lib/*.js --reporter node_modules/jshint-stylish/stylish.js", + "test": "tape test.js | tap-spec" + }, + "files": [ + "LICENSE-MIT", + "index.js", + "lib" + ], + "keywords": [ + "css", + "normalize", + "optimise", + "optimisation", + "postcss", + "postcss-plugin", + "z-index" + ], + "license": "MIT", + "dependencies": { + "has": "^1.0.1", + "postcss": "^5.0.4", + "uniqs": "^2.0.0" + }, + "devDependencies": { + "jshint": "^2.8.0", + "jshint-stylish": "^2.0.1", + "tap-spec": "^4.1.0", + "tape": "^4.2.0" + }, + "homepage": "https://github.com/ben-eb/postcss-zindex", + "author": { + "name": "Ben Briggs", + "email": "beneb.info@gmail.com", + "url": "http://beneb.info" + }, + "repository": "ben-eb/postcss-zindex" +} -- cgit v1.2.3