Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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();
});
};
});

View File

@@ -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;

View File

@@ -0,0 +1,77 @@
{
"_args": [
[
"postcss-zindex@2.2.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "postcss-zindex@2.2.0",
"_id": "postcss-zindex@2.2.0",
"_inBundle": false,
"_integrity": "sha1-0hCd3AVbka9n/EyzsCWUZjnSryI=",
"_location": "/css-loader/postcss-zindex",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "postcss-zindex@2.2.0",
"name": "postcss-zindex",
"escapedName": "postcss-zindex",
"rawSpec": "2.2.0",
"saveSpec": null,
"fetchSpec": "2.2.0"
},
"_requiredBy": [
"/css-loader/cssnano"
],
"_resolved": "https://registry.npmjs.org/postcss-zindex/-/postcss-zindex-2.2.0.tgz",
"_spec": "2.2.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Ben Briggs",
"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
},
"bugs": {
"url": "https://github.com/ben-eb/postcss-zindex/issues"
},
"dependencies": {
"has": "^1.0.1",
"postcss": "^5.0.4",
"uniqs": "^2.0.0"
},
"description": "Reduce z-index values with PostCSS.",
"devDependencies": {
"jshint": "^2.8.0",
"jshint-stylish": "^2.0.1",
"tap-spec": "^4.1.0",
"tape": "^4.2.0"
},
"files": [
"LICENSE-MIT",
"index.js",
"lib"
],
"homepage": "https://github.com/ben-eb/postcss-zindex",
"keywords": [
"css",
"normalize",
"optimise",
"optimisation",
"postcss",
"postcss-plugin",
"z-index"
],
"license": "MIT",
"main": "index.js",
"name": "postcss-zindex",
"repository": {
"type": "git",
"url": "git+https://github.com/ben-eb/postcss-zindex.git"
},
"scripts": {
"lint": "jshint index.js lib/*.js --reporter node_modules/jshint-stylish/stylish.js",
"test": "tape test.js | tap-spec"
},
"version": "2.2.0"
}