This commit is contained in:
Aevann1 2021-12-13 22:28:32 +00:00
parent 628618df89
commit e031240dff
3749 changed files with 1120848 additions and 1 deletions

167
node_modules/reduce-css-calc/CHANGELOG.md generated vendored Executable file
View file

@ -0,0 +1,167 @@
# Changelog of `reduce-css-call`
## 2.1.8 - 2020-01-08
- Fix Parse error on custom property fallback ([#68](https://github.com/MoOx/reduce-css-calc/pull/68)) - @snowystinger)
## 2.1.7 - 2019-10-22
- Switch to a maintained jison fork ([#57](https://github.com/MoOx/reduce-css-calc/pull/57)) - @davidgovea)
## 2.1.6 - 2019-01-11
- Fixed: Incorrect calculation when subtracting (e.g. `calc(100% - calc(120px + 1em + 2em + 100px))`) ([#52](https://github.com/MoOx/reduce-css-calc/pull/53) - @sylvainpolletvillard)
## 2.1.5 - 2018-09-20
- [Avoid breaking when seeing ` constant()`` or `env()`](https://github.com/MoOx/reduce-css-calc/commit/409c9ba2cd5e06e7f8f679f7f0c3c3a14ff3e673) by @dlee
## 2.1.4 - 2018-01-22
- Prevent webpack parsing issue
(see https://github.com/zaach/jison/pull/352)
## 2.1.3 - 2017-11-27
- Fixed: Incorrect reduction for a specific case (e.g. `calc(1em + (1em - 5px))`) ([#43](https://github.com/MoOx/reduce-css-calc/pull/43) - @Justineo)
## 2.1.2 - 2017-11-26
- Fixed: Incorrect reduction of division with custom property (e.g. `calc(var(--foo) / 2)`) ([#41](https://github.com/MoOx/reduce-css-calc/issues/41) - @Semigradsky)
## 2.1.1 - 2017-10-12
- Fixed: Incorrect reduction of nested expression (e.g. `calc( (1em - calc( 10px + 1em)) / 2)`) ([#39](https://github.com/MoOx/reduce-css-calc/pull/39) - @gyoshev)
## 2.1.0 - 2017-10-10
- Added: Support for working in browsers without transpiling ([#36](https://github.com/MoOx/reduce-css-calc/pull/36) - @Semigradsky)
- Fixed: `calc(100vw - (100vw - 100%))` does not evaluate to `100%` ([#35](https://github.com/MoOx/reduce-css-calc/pull/35) - @Semigradsky)
## 2.0.5 - 2017-05-12
- Fixed: Support division with a CSS variable.
## 2.0.4 - 2017-05-09
- Fixed: CSS variable regex was overly greedy and caused a crash in some
cases. ([#27](https://github.com/MoOx/reduce-css-calc/pull/27) - @andyjansson)
## 2.0.3 - 2017-05-09
- Fixed: Regression in handling decimals without having any numbers after
the decimal place (e.g. `10.px`).
## 2.0.2 - 2017-05-08
- Fixed: Regression in consecutive subtraction handling
([#25](https://github.com/MoOx/reduce-css-calc/pull/25) - @andyjansson)
## 2.0.1 - 2017-05-08
- Fixed: Support for nested calc e.g. `calc(100% - calc(50px - 25px))`.
- Fixed: Support for CSS variables e.g. `calc(var(--mouseX) * 1px)`.
## 2.0.0 - 2017-05-08
- Rewritten with a jison parser for more accurate value parsing.
- Breaking: reduce-css-calc will now throw when trying to multiply or divide
by the same unit (e.g. `calc(200px * 20px)`), and also when trying to divide
by zero.
- Added: Better handling of zero values (e.g. `calc(100vw / 2 - 6px + 0px)`
becomes `calc(100vw / 2 - 6px)`).
- Added: Better handling of mixed time values (e.g. `calc(1s - 50ms)`
becomes `0.95s`).
- Added: Inner parentheses calculation to simplify complex expressions (e.g.
`calc(14px + 6 * ((100vw - 320px) / 448))` becomes `calc(9.71px + 1.34vw)`
with precision set to `2`).
- Fixed: `calc(1px + 1)` does not evaluate to `2px`.
([#22](https://github.com/MoOx/reduce-css-calc/pull/22) - @andyjansson)
## 1.3.0 - 2016-08-26
- Added: calc identifier from unresolved nested expressions are removed for
better browser support
([#19](https://github.com/MoOx/reduce-css-calc/pull/19) - @ben-eb)
## 1.2.8 - 2016-08-26
- Fixed: regression from 1.2.5 on calc() with value without leading 0
([#17](https://github.com/MoOx/reduce-css-calc/pull/17) - @ben-eb)
## 1.2.7 - 2016-08-22
- Fixed: regression from 1.2.5 on calc() with value without leading 0
(@MoOx)
## 1.2.6 - 2016-08-22
- Fixed: regression from 1.2.5 on calc() on multiple lines
(@MoOx)
## 1.2.5 - 2016-08-22
- Fixed: security issue due to the usage of `eval()`.
This is to avoid an arbitrary code execution.
Now operations are resolved using
[`math-expression-evaluator`](https://github.com/redhivesoftware/math-expression-evaluator)
## 1.2.4 - 2016-06-09
- Fixed: zero values are not unitless anymore.
Browsers do not calculate calc() with 0 unitless values.
http://jsbin.com/punivivipo/edit?html,css,output
([#11](https://github.com/MoOx/reduce-css-calc/pull/11))
## 1.2.3 - 2016-04-28
- Fixed: wrong rouding in some edge cases
([#10](https://github.com/MoOx/reduce-css-calc/pull/10))
## 1.2.2 - 2016-04-19
- Fixed: Don't reduce expression containing CSS variables.
([#9](https://github.com/MoOx/reduce-css-calc/pull/9))
## 1.2.1 - 2016-02-22
- Fixed: uppercase letters in units are now supported
([#8](https://github.com/MoOx/reduce-css-calc/pull/8))
## 1.2.0 - 2014-11-24
- Decimal precision is now customisable as the `precision` option
## 1.1.4 - 2014-11-12
- 5 decimals rounding for everything
## 1.1.3 - 2014-08-13
- 5 decimals rounding for percentage
## 1.1.2 - 2014-08-10
- Prevent infinite loop by adding a `Call stack overflow`
- Correctly ignore unrecognized values (safer evaluation for nested expressions,
see [postcss/postcss-calc#2](https://github.com/postcss/postcss-calc/issues/2))
- Handle rounding issues (eg: 10% \* 20% now give 2%, not 2.0000000000000004%)
## 1.1.1 - 2014-08-06
- Fix issue when using mutiples differents prefixes in the same function
## 1.1.0 - 2014-08-06
- support more complex formulas
- use `reduce-function-call`
- better error message
## 1.0.0 - 2014-08-04
First release
- based on [rework-calc](https://github.com/reworkcss/rework-calc) v1.1.0
- add error if the calc() embed an empty calc() or empty ()
- jscs + jshint added before tests

20
node_modules/reduce-css-calc/LICENSE generated vendored Executable file
View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2014 Maxime Thirouin & Joakim Bengtson
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.

76
node_modules/reduce-css-calc/README.md generated vendored Executable file
View file

@ -0,0 +1,76 @@
# reduce-css-calc
[![Build Status](https://travis-ci.org/MoOx/reduce-css-calc.svg)](https://travis-ci.org/MoOx/reduce-css-calc)
> Reduce CSS calc() function to the maximum.
Particularly useful for packages like [rework-calc](https://github.com/reworkcss/rework-calc) or [postcss-calc](https://github.com/postcss/postcss-calc).
## Installation
```console
npm install reduce-css-calc
```
## Usage
### `var reducedString = reduceCSSCalc(string, precision)`
```javascript
var reduceCSSCalc = require('reduce-css-calc')
reduceCSSCalc("calc(1 + 1)")
// 2
reduceCSSCalc("calc((6 / 2) - (4 * 2) + 1)")
// -4
reduceCSSCalc("calc(1/3)")
// 0.33333
reduceCSSCalc("calc(1/3)", 10)
// 0.3333333333
reduceCSSCalc("calc(3rem * 2 - 1rem)")
// 5rem
reduceCSSCalc("calc(2 * 50%)")
// 100%
reduceCSSCalc("calc(120% * 50%)")
// 60%
reduceCSSCalc("a calc(1 + 1) b calc(1 - 1) c")
// a 2 b 0 c
reduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1rem)")
// 0.125rem
reduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1px)")
// calc(1.125rem - 1px)
reduceCSSCalc("-moz-calc(100px / 2)")
// 50px
reduceCSSCalc("-moz-calc(50% - 2em)")
// -moz-calc(50% - 2em)
```
See [unit tests](src/__tests__/index.js) for others examples.
---
## Contributing
Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.
```console
git clone https://github.com/MoOx/reduce-css-calc.git
git checkout -b patch-1
npm install
npm test
```
## [Changelog](CHANGELOG.md)
## [License](LICENSE-MIT)

51
node_modules/reduce-css-calc/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,51 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _postcssValueParser = require('postcss-value-parser');
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _parser = require('./parser');
var _reducer = require('./lib/reducer');
var _reducer2 = _interopRequireDefault(_reducer);
var _stringifier = require('./lib/stringifier');
var _stringifier2 = _interopRequireDefault(_stringifier);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// eslint-disable-line
var MATCH_CALC = /((?:\-[a-z]+\-)?calc)/;
exports.default = function (value) {
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
return (0, _postcssValueParser2.default)(value).walk(function (node) {
// skip anything which isn't a calc() function
if (node.type !== 'function' || !MATCH_CALC.test(node.value)) return;
// stringify calc expression and produce an AST
var contents = _postcssValueParser2.default.stringify(node.nodes);
// skip constant() and env()
if (contents.indexOf('constant') >= 0 || contents.indexOf('env') >= 0) return;
var ast = _parser.parser.parse(contents);
// reduce AST to its simplest form, that is, either to a single value
// or a simplified calc expression
var reducedAst = (0, _reducer2.default)(ast, precision);
// stringify AST and write it back
node.type = 'word';
node.value = (0, _stringifier2.default)(node.value, reducedAst, precision);
}, true).toString();
};
module.exports = exports['default'];

38
node_modules/reduce-css-calc/dist/lib/convert.js generated vendored Normal file
View file

@ -0,0 +1,38 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _cssUnitConverter = require('css-unit-converter');
var _cssUnitConverter2 = _interopRequireDefault(_cssUnitConverter);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function convertNodes(left, right, precision) {
switch (left.type) {
case 'LengthValue':
case 'AngleValue':
case 'TimeValue':
case 'FrequencyValue':
case 'ResolutionValue':
return convertAbsoluteLength(left, right, precision);
default:
return { left: left, right: right };
}
}
function convertAbsoluteLength(left, right, precision) {
if (right.type === left.type) {
right = {
type: left.type,
value: (0, _cssUnitConverter2.default)(right.value, right.unit, left.unit, precision),
unit: left.unit
};
}
return { left: left, right: right };
}
exports.default = convertNodes;
module.exports = exports['default'];

258
node_modules/reduce-css-calc/dist/lib/reducer.js generated vendored Normal file
View file

@ -0,0 +1,258 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.flip = flip;
var _convert = require("./convert");
var _convert2 = _interopRequireDefault(_convert);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function reduce(node, precision) {
if (node.type === "MathExpression") return reduceMathExpression(node, precision);
if (node.type === "Calc") return reduce(node.value, precision);
return node;
}
function isEqual(left, right) {
return left.type === right.type && left.value === right.value;
}
function isValueType(type) {
switch (type) {
case 'LengthValue':
case 'AngleValue':
case 'TimeValue':
case 'FrequencyValue':
case 'ResolutionValue':
case 'EmValue':
case 'ExValue':
case 'ChValue':
case 'RemValue':
case 'VhValue':
case 'VwValue':
case 'VminValue':
case 'VmaxValue':
case 'PercentageValue':
case 'Value':
return true;
}
return false;
}
function convertMathExpression(node, precision) {
var nodes = (0, _convert2.default)(node.left, node.right, precision);
var left = reduce(nodes.left, precision);
var right = reduce(nodes.right, precision);
if (left.type === "MathExpression" && right.type === "MathExpression") {
if (left.operator === '/' && right.operator === '*' || left.operator === '-' && right.operator === '+' || left.operator === '*' && right.operator === '/' || left.operator === '+' && right.operator === '-') {
if (isEqual(left.right, right.right)) nodes = (0, _convert2.default)(left.left, right.left, precision);else if (isEqual(left.right, right.left)) nodes = (0, _convert2.default)(left.left, right.right, precision);
left = reduce(nodes.left, precision);
right = reduce(nodes.right, precision);
}
}
node.left = left;
node.right = right;
return node;
}
function flip(operator) {
return operator === '+' ? '-' : '+';
}
function flipValue(node) {
if (isValueType(node.type)) node.value = -node.value;else if (node.type == 'MathExpression') {
node.left = flipValue(node.left);
node.right = flipValue(node.right);
}
return node;
}
function reduceAddSubExpression(node, precision) {
var _node = node,
left = _node.left,
right = _node.right,
op = _node.operator;
if (left.type === 'CssVariable' || right.type === 'CssVariable') return node;
// something + 0 => something
// something - 0 => something
if (right.value === 0) return left;
// 0 + something => something
if (left.value === 0 && op === "+") return right;
// 0 - something => -something
if (left.value === 0 && op === "-") return flipValue(right);
// value + value
// value - value
if (left.type === right.type && isValueType(left.type)) {
node = Object.assign({}, left);
if (op === "+") node.value = left.value + right.value;else node.value = left.value - right.value;
}
// value <op> (expr)
if (isValueType(left.type) && (right.operator === '+' || right.operator === '-') && right.type === 'MathExpression') {
// value + (value + something) => (value + value) + something
// value + (value - something) => (value + value) - something
// value - (value + something) => (value - value) - something
// value - (value - something) => (value - value) + something
if (left.type === right.left.type) {
node = Object.assign({}, node);
node.left = reduce({
type: 'MathExpression',
operator: op,
left: left,
right: right.left
}, precision);
node.right = right.right;
node.operator = op === '-' ? flip(right.operator) : right.operator;
return reduce(node, precision);
}
// value + (something + value) => (value + value) + something
// value + (something - value) => (value - value) + something
// value - (something + value) => (value - value) - something
// value - (something - value) => (value + value) - something
else if (left.type === right.right.type) {
node = Object.assign({}, node);
node.left = reduce({
type: 'MathExpression',
operator: op === '-' ? flip(right.operator) : right.operator,
left: left,
right: right.right
}, precision);
node.right = right.left;
return reduce(node, precision);
}
}
// (expr) <op> value
if (left.type === 'MathExpression' && (left.operator === '+' || left.operator === '-') && isValueType(right.type)) {
// (value + something) + value => (value + value) + something
// (value - something) + value => (value + value) - something
// (value + something) - value => (value - value) + something
// (value - something) - value => (value - value) - something
if (right.type === left.left.type) {
node = Object.assign({}, left);
node.left = reduce({
type: 'MathExpression',
operator: op,
left: left.left,
right: right
}, precision);
return reduce(node, precision);
}
// (something + value) + value => something + (value + value)
// (something - value1) + value2 => something - (value2 - value1)
// (something + value) - value => something + (value - value)
// (something - value) - value => something - (value + value)
else if (right.type === left.right.type) {
node = Object.assign({}, left);
if (left.operator === '-') {
node.right = reduce({
type: 'MathExpression',
operator: op === '-' ? '+' : '-',
left: right,
right: left.right
}, precision);
node.operator = op === '-' ? '-' : '+';
} else {
node.right = reduce({
type: 'MathExpression',
operator: op,
left: left.right,
right: right
}, precision);
}
if (node.right.value < 0) {
node.right.value *= -1;
node.operator = node.operator === '-' ? '+' : '-';
}
return reduce(node, precision);
}
}
return node;
}
function reduceDivisionExpression(node, precision) {
if (!isValueType(node.right.type)) return node;
if (node.right.type !== 'Value') throw new Error("Cannot divide by \"" + node.right.unit + "\", number expected");
if (node.right.value === 0) throw new Error('Cannot divide by zero');
// (expr) / value
if (node.left.type === 'MathExpression') {
if (isValueType(node.left.left.type) && isValueType(node.left.right.type)) {
node.left.left.value /= node.right.value;
node.left.right.value /= node.right.value;
return reduce(node.left, precision);
}
return node;
}
// something / value
else if (isValueType(node.left.type)) {
node.left.value /= node.right.value;
return node.left;
}
return node;
}
function reduceMultiplicationExpression(node) {
// (expr) * value
if (node.left.type === 'MathExpression' && node.right.type === 'Value') {
if (isValueType(node.left.left.type) && isValueType(node.left.right.type)) {
node.left.left.value *= node.right.value;
node.left.right.value *= node.right.value;
return node.left;
}
}
// something * value
else if (isValueType(node.left.type) && node.right.type === 'Value') {
node.left.value *= node.right.value;
return node.left;
}
// value * (expr)
else if (node.left.type === 'Value' && node.right.type === 'MathExpression') {
if (isValueType(node.right.left.type) && isValueType(node.right.right.type)) {
node.right.left.value *= node.left.value;
node.right.right.value *= node.left.value;
return node.right;
}
}
// value * something
else if (node.left.type === 'Value' && isValueType(node.right.type)) {
node.right.value *= node.left.value;
return node.right;
}
return node;
}
function reduceMathExpression(node, precision) {
node = convertMathExpression(node, precision);
switch (node.operator) {
case "+":
case "-":
return reduceAddSubExpression(node, precision);
case "/":
return reduceDivisionExpression(node, precision);
case "*":
return reduceMultiplicationExpression(node);
}
return node;
}
exports.default = reduce;

78
node_modules/reduce-css-calc/dist/lib/stringifier.js generated vendored Normal file
View file

@ -0,0 +1,78 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (calc, node, precision) {
var str = stringify(node, precision);
if (node.type === "MathExpression") {
// if calc expression couldn't be resolved to a single value, re-wrap it as
// a calc()
str = calc + "(" + str + ")";
}
return str;
};
var _reducer = require("./reducer");
var order = {
"*": 0,
"/": 0,
"+": 1,
"-": 1
};
function round(value, prec) {
if (prec !== false) {
var precision = Math.pow(10, prec);
return Math.round(value * precision) / precision;
}
return value;
}
function stringify(node, prec) {
switch (node.type) {
case "MathExpression":
{
var left = node.left,
right = node.right,
op = node.operator;
var str = "";
if (left.type === 'MathExpression' && order[op] < order[left.operator]) str += "(" + stringify(left, prec) + ")";else str += stringify(left, prec);
str += " " + node.operator + " ";
if (right.type === 'MathExpression' && order[op] < order[right.operator]) {
str += "(" + stringify(right, prec) + ")";
} else if (right.type === 'MathExpression' && op === "-" && ["+", "-"].includes(right.operator)) {
// fix #52 : a-(b+c) = a-b-c
right.operator = (0, _reducer.flip)(right.operator);
str += stringify(right, prec);
} else {
str += stringify(right, prec);
}
return str;
}
case "Value":
return round(node.value, prec);
case 'CssVariable':
if (node.fallback) {
return "var(" + node.value + ", " + stringify(node.fallback, prec, true) + ")";
}
return "var(" + node.value + ")";
case 'Calc':
if (node.prefix) {
return "-" + node.prefix + "-calc(" + stringify(node.value, prec) + ")";
}
return "calc(" + stringify(node.value, prec) + ")";
default:
return round(node.value, prec) + node.unit;
}
}
module.exports = exports["default"];

3858
node_modules/reduce-css-calc/dist/parser.js generated vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,22 @@
Copyright (c) Bogdan Chadkin <trysound@yandex.ru>
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,253 @@
# postcss-value-parser
[![Travis CI](https://travis-ci.org/TrySound/postcss-value-parser.svg)](https://travis-ci.org/TrySound/postcss-value-parser)
Transforms CSS declaration values and at-rule parameters into a tree of nodes, and provides a simple traversal API.
## Usage
```js
var valueParser = require('postcss-value-parser');
var cssBackgroundValue = 'url(foo.png) no-repeat 40px 73%';
var parsedValue = valueParser(cssBackgroundValue);
// parsedValue exposes an API described below,
// e.g. parsedValue.walk(..), parsedValue.toString(), etc.
```
For example, parsing the value `rgba(233, 45, 66, .5)` will return the following:
```js
{
nodes: [
{
type: 'function',
value: 'rgba',
before: '',
after: '',
nodes: [
{ type: 'word', value: '233' },
{ type: 'div', value: ',', before: '', after: ' ' },
{ type: 'word', value: '45' },
{ type: 'div', value: ',', before: '', after: ' ' },
{ type: 'word', value: '66' },
{ type: 'div', value: ',', before: ' ', after: '' },
{ type: 'word', value: '.5' }
]
}
]
}
```
If you wanted to convert each `rgba()` value in `sourceCSS` to a hex value, you could do so like this:
```js
var valueParser = require('postcss-value-parser');
var parsed = valueParser(sourceCSS);
// walk() will visit all the of the nodes in the tree,
// invoking the callback for each.
parsed.walk(function (node) {
// Since we only want to transform rgba() values,
// we can ignore anything else.
if (node.type !== 'function' && node.value !== 'rgba') return;
// We can make an array of the rgba() arguments to feed to a
// convertToHex() function
var color = node.nodes.filter(function (node) {
return node.type === 'word';
}).map(function (node) {
return Number(node.value);
}); // [233, 45, 66, .5]
// Now we will transform the existing rgba() function node
// into a word node with the hex value
node.type = 'word';
node.value = convertToHex(color);
})
parsed.toString(); // #E92D42
```
## Nodes
Each node is an object with these common properties:
- **type**: The type of node (`word`, `string`, `div`, `space`, `comment`, or `function`).
Each type is documented below.
- **value**: Each node has a `value` property; but what exactly `value` means
is specific to the node type. Details are documented for each type below.
- **sourceIndex**: The starting index of the node within the original source
string. For example, given the source string `10px 20px`, the `word` node
whose value is `20px` will have a `sourceIndex` of `5`.
### word
The catch-all node type that includes keywords (e.g. `no-repeat`),
quantities (e.g. `20px`, `75%`, `1.5`), and hex colors (e.g. `#e6e6e6`).
Node-specific properties:
- **value**: The "word" itself.
### string
A quoted string value, e.g. `"something"` in `content: "something";`.
Node-specific properties:
- **value**: The text content of the string.
- **quote**: The quotation mark surrounding the string, either `"` or `'`.
- **unclosed**: `true` if the string was not closed properly. e.g. `"unclosed string `.
### div
A divider, for example
- `,` in `animation-duration: 1s, 2s, 3s`
- `/` in `border-radius: 10px / 23px`
- `:` in `(min-width: 700px)`
Node-specific properties:
- **value**: The divider character. Either `,`, `/`, or `:` (see examples above).
- **before**: Whitespace before the divider.
- **after**: Whitespace after the divider.
### space
Whitespace used as a separator, e.g. ` ` occurring twice in `border: 1px solid black;`.
Node-specific properties:
- **value**: The whitespace itself.
### comment
A CSS comment starts with `/*` and ends with `*/`
Node-specific properties:
- **value**: The comment value without `/*` and `*/`
- **unclosed**: `true` if the comment was not closed properly. e.g. `/* comment without an end `.
### function
A CSS function, e.g. `rgb(0,0,0)` or `url(foo.bar)`.
Function nodes have nodes nested within them: the function arguments.
Additional properties:
- **value**: The name of the function, e.g. `rgb` in `rgb(0,0,0)`.
- **before**: Whitespace after the opening parenthesis and before the first argument,
e.g. ` ` in `rgb( 0,0,0)`.
- **after**: Whitespace before the closing parenthesis and after the last argument,
e.g. ` ` in `rgb(0,0,0 )`.
- **nodes**: More nodes representing the arguments to the function.
- **unclosed**: `true` if the parentheses was not closed properly. e.g. `( unclosed-function `.
Media features surrounded by parentheses are considered functions with an
empty value. For example, `(min-width: 700px)` parses to these nodes:
```js
[
{
type: 'function', value: '', before: '', after: '',
nodes: [
{ type: 'word', value: 'min-width' },
{ type: 'div', value: ':', before: '', after: ' ' },
{ type: 'word', value: '700px' }
]
}
]
```
`url()` functions can be parsed a little bit differently depending on
whether the first character in the argument is a quotation mark.
`url( /gfx/img/bg.jpg )` parses to:
```js
{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [
{ type: 'word', sourceIndex: 5, value: '/gfx/img/bg.jpg' }
] }
```
`url( "/gfx/img/bg.jpg" )`, on the other hand, parses to:
```js
{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [
type: 'string', sourceIndex: 5, quote: '"', value: '/gfx/img/bg.jpg' },
] }
```
## API
```
var valueParser = require('postcss-value-parser');
```
### valueParser.unit(quantity)
Parses `quantity`, distinguishing the number from the unit. Returns an object like the following:
```js
// Given 2rem
{
number: '2',
unit: 'rem'
}
```
If the `quantity` argument cannot be parsed as a number, returns `false`.
*This function does not parse complete values*: you cannot pass it `1px solid black` and expect `px` as
the unit. Instead, you should pass it single quantities only. Parse `1px solid black`, then pass it
the stringified `1px` node (a `word` node) to parse the number and unit.
### valueParser.stringify(nodes[, custom])
Stringifies a node or array of nodes.
The `custom` function is called for each `node`; return a string to override the default behaviour.
### valueParser.walk(nodes, callback[, bubble])
Walks each provided node, recursively walking all descendent nodes within functions.
Returning `false` in the `callback` will prevent traversal of descendent nodes (within functions).
You can use this feature to for shallow iteration, walking over only the *immediate* children.
*Note: This only applies if `bubble` is `false` (which is the default).*
By default, the tree is walked from the outermost node inwards.
To reverse the direction, pass `true` for the `bubble` argument.
The `callback` is invoked with three arguments: `callback(node, index, nodes)`.
- `node`: The current node.
- `index`: The index of the current node.
- `nodes`: The complete nodes array passed to `walk()`.
Returns the `valueParser` instance.
### var parsed = valueParser(value)
Returns the parsed node tree.
### parsed.nodes
The array of nodes.
### parsed.toString()
Stringifies the node tree.
### parsed.walk(callback[, bubble])
Walks each node inside `parsed.nodes`. See the documentation for `valueParser.walk()` above.
# License
MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)

View file

@ -0,0 +1,28 @@
var parse = require("./parse");
var walk = require("./walk");
var stringify = require("./stringify");
function ValueParser(value) {
if (this instanceof ValueParser) {
this.nodes = parse(value);
return this;
}
return new ValueParser(value);
}
ValueParser.prototype.toString = function() {
return Array.isArray(this.nodes) ? stringify(this.nodes) : "";
};
ValueParser.prototype.walk = function(cb, bubble) {
walk(this.nodes, cb, bubble);
return this;
};
ValueParser.unit = require("./unit");
ValueParser.walk = walk;
ValueParser.stringify = stringify;
module.exports = ValueParser;

View file

@ -0,0 +1,251 @@
var openParentheses = "(".charCodeAt(0);
var closeParentheses = ")".charCodeAt(0);
var singleQuote = "'".charCodeAt(0);
var doubleQuote = '"'.charCodeAt(0);
var backslash = "\\".charCodeAt(0);
var slash = "/".charCodeAt(0);
var comma = ",".charCodeAt(0);
var colon = ":".charCodeAt(0);
var star = "*".charCodeAt(0);
module.exports = function(input) {
var tokens = [];
var value = input;
var next, quote, prev, token, escape, escapePos, whitespacePos;
var pos = 0;
var code = value.charCodeAt(pos);
var max = value.length;
var stack = [{ nodes: tokens }];
var balanced = 0;
var parent;
var name = "";
var before = "";
var after = "";
while (pos < max) {
// Whitespaces
if (code <= 32) {
next = pos;
do {
next += 1;
code = value.charCodeAt(next);
} while (code <= 32);
token = value.slice(pos, next);
prev = tokens[tokens.length - 1];
if (code === closeParentheses && balanced) {
after = token;
} else if (prev && prev.type === "div") {
prev.after = token;
} else if (
code === comma ||
code === colon ||
(code === slash && value.charCodeAt(next + 1) !== star)
) {
before = token;
} else {
tokens.push({
type: "space",
sourceIndex: pos,
value: token
});
}
pos = next;
// Quotes
} else if (code === singleQuote || code === doubleQuote) {
next = pos;
quote = code === singleQuote ? "'" : '"';
token = {
type: "string",
sourceIndex: pos,
quote: quote
};
do {
escape = false;
next = value.indexOf(quote, next + 1);
if (~next) {
escapePos = next;
while (value.charCodeAt(escapePos - 1) === backslash) {
escapePos -= 1;
escape = !escape;
}
} else {
value += quote;
next = value.length - 1;
token.unclosed = true;
}
} while (escape);
token.value = value.slice(pos + 1, next);
tokens.push(token);
pos = next + 1;
code = value.charCodeAt(pos);
// Comments
} else if (code === slash && value.charCodeAt(pos + 1) === star) {
token = {
type: "comment",
sourceIndex: pos
};
next = value.indexOf("*/", pos);
if (next === -1) {
token.unclosed = true;
next = value.length;
}
token.value = value.slice(pos + 2, next);
tokens.push(token);
pos = next + 2;
code = value.charCodeAt(pos);
// Dividers
} else if (code === slash || code === comma || code === colon) {
token = value[pos];
tokens.push({
type: "div",
sourceIndex: pos - before.length,
value: token,
before: before,
after: ""
});
before = "";
pos += 1;
code = value.charCodeAt(pos);
// Open parentheses
} else if (openParentheses === code) {
// Whitespaces after open parentheses
next = pos;
do {
next += 1;
code = value.charCodeAt(next);
} while (code <= 32);
token = {
type: "function",
sourceIndex: pos - name.length,
value: name,
before: value.slice(pos + 1, next)
};
pos = next;
if (name === "url" && code !== singleQuote && code !== doubleQuote) {
next -= 1;
do {
escape = false;
next = value.indexOf(")", next + 1);
if (~next) {
escapePos = next;
while (value.charCodeAt(escapePos - 1) === backslash) {
escapePos -= 1;
escape = !escape;
}
} else {
value += ")";
next = value.length - 1;
token.unclosed = true;
}
} while (escape);
// Whitespaces before closed
whitespacePos = next;
do {
whitespacePos -= 1;
code = value.charCodeAt(whitespacePos);
} while (code <= 32);
if (pos !== whitespacePos + 1) {
token.nodes = [
{
type: "word",
sourceIndex: pos,
value: value.slice(pos, whitespacePos + 1)
}
];
} else {
token.nodes = [];
}
if (token.unclosed && whitespacePos + 1 !== next) {
token.after = "";
token.nodes.push({
type: "space",
sourceIndex: whitespacePos + 1,
value: value.slice(whitespacePos + 1, next)
});
} else {
token.after = value.slice(whitespacePos + 1, next);
}
pos = next + 1;
code = value.charCodeAt(pos);
tokens.push(token);
} else {
balanced += 1;
token.after = "";
tokens.push(token);
stack.push(token);
tokens = token.nodes = [];
parent = token;
}
name = "";
// Close parentheses
} else if (closeParentheses === code && balanced) {
pos += 1;
code = value.charCodeAt(pos);
parent.after = after;
after = "";
balanced -= 1;
stack.pop();
parent = stack[balanced];
tokens = parent.nodes;
// Words
} else {
next = pos;
do {
if (code === backslash) {
next += 1;
}
next += 1;
code = value.charCodeAt(next);
} while (
next < max &&
!(
code <= 32 ||
code === singleQuote ||
code === doubleQuote ||
code === comma ||
code === colon ||
code === slash ||
code === openParentheses ||
(code === closeParentheses && balanced)
)
);
token = value.slice(pos, next);
if (openParentheses === code) {
name = token;
} else {
tokens.push({
type: "word",
sourceIndex: pos,
value: token
});
}
pos = next;
}
}
for (pos = stack.length - 1; pos; pos -= 1) {
stack[pos].unclosed = true;
}
return stack[0].nodes;
};

View file

@ -0,0 +1,48 @@
function stringifyNode(node, custom) {
var type = node.type;
var value = node.value;
var buf;
var customResult;
if (custom && (customResult = custom(node)) !== undefined) {
return customResult;
} else if (type === "word" || type === "space") {
return value;
} else if (type === "string") {
buf = node.quote || "";
return buf + value + (node.unclosed ? "" : buf);
} else if (type === "comment") {
return "/*" + value + (node.unclosed ? "" : "*/");
} else if (type === "div") {
return (node.before || "") + value + (node.after || "");
} else if (Array.isArray(node.nodes)) {
buf = stringify(node.nodes);
if (type !== "function") {
return buf;
}
return (
value +
"(" +
(node.before || "") +
buf +
(node.after || "") +
(node.unclosed ? "" : ")")
);
}
return value;
}
function stringify(nodes, custom) {
var result, i;
if (Array.isArray(nodes)) {
result = "";
for (i = nodes.length - 1; ~i; i -= 1) {
result = stringifyNode(nodes[i], custom) + result;
}
return result;
}
return stringifyNode(nodes, custom);
}
module.exports = stringify;

View file

@ -0,0 +1,49 @@
var minus = "-".charCodeAt(0);
var plus = "+".charCodeAt(0);
var dot = ".".charCodeAt(0);
var exp = "e".charCodeAt(0);
var EXP = "E".charCodeAt(0);
module.exports = function(value) {
var pos = 0;
var length = value.length;
var dotted = false;
var sciPos = -1;
var containsNumber = false;
var code;
while (pos < length) {
code = value.charCodeAt(pos);
if (code >= 48 && code <= 57) {
containsNumber = true;
} else if (code === exp || code === EXP) {
if (sciPos > -1) {
break;
}
sciPos = pos;
} else if (code === dot) {
if (dotted) {
break;
}
dotted = true;
} else if (code === plus || code === minus) {
if (pos !== 0) {
break;
}
} else {
break;
}
pos += 1;
}
if (sciPos + 1 === pos) pos--;
return containsNumber
? {
number: value.slice(0, pos),
unit: value.slice(pos)
}
: false;
};

View file

@ -0,0 +1,22 @@
module.exports = function walk(nodes, cb, bubble) {
var i, max, node, result;
for (i = 0, max = nodes.length; i < max; i += 1) {
node = nodes[i];
if (!bubble) {
result = cb(node, i, nodes);
}
if (
result !== false &&
node.type === "function" &&
Array.isArray(node.nodes)
) {
walk(node.nodes, cb, bubble);
}
if (bubble) {
cb(node, i, nodes);
}
}
};

View file

@ -0,0 +1,89 @@
{
"_args": [
[
"postcss-value-parser@3.3.1",
"/d"
]
],
"_from": "postcss-value-parser@3.3.1",
"_id": "postcss-value-parser@3.3.1",
"_inBundle": false,
"_integrity": "sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ==",
"_location": "/reduce-css-calc/postcss-value-parser",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "postcss-value-parser@3.3.1",
"name": "postcss-value-parser",
"escapedName": "postcss-value-parser",
"rawSpec": "3.3.1",
"saveSpec": null,
"fetchSpec": "3.3.1"
},
"_requiredBy": [
"/reduce-css-calc"
],
"_resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz",
"_spec": "3.3.1",
"_where": "/d",
"author": {
"name": "Bogdan Chadkin",
"email": "trysound@yandex.ru"
},
"bugs": {
"url": "https://github.com/TrySound/postcss-value-parser/issues"
},
"description": "Transforms css values and at-rule params into the tree",
"devDependencies": {
"eslint": "^5.6.1",
"husky": "^1.0.0",
"lint-staged": "^7.3.0",
"prettier": "^1.4.4",
"tap-spec": "^5.0.0",
"tape": "^4.2.0"
},
"eslintConfig": {
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended"
},
"files": [
"lib"
],
"homepage": "https://github.com/TrySound/postcss-value-parser",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"keywords": [
"postcss",
"value",
"parser"
],
"license": "MIT",
"lint-staged": {
"*.js": [
"eslint",
"prettier --write",
"git add"
]
},
"main": "lib/index.js",
"name": "postcss-value-parser",
"repository": {
"type": "git",
"url": "git+https://github.com/TrySound/postcss-value-parser.git"
},
"scripts": {
"lint": "yarn lint:js && yarn lint:prettier",
"lint:js": "eslint . --cache",
"lint:prettier": "prettier '**/*.js' --list-different",
"pretest": "yarn lint",
"test": "tape test/*.js | tap-spec"
},
"version": "3.3.1"
}

86
node_modules/reduce-css-calc/package.json generated vendored Normal file
View file

@ -0,0 +1,86 @@
{
"_args": [
[
"reduce-css-calc@2.1.8",
"/d"
]
],
"_from": "reduce-css-calc@2.1.8",
"_id": "reduce-css-calc@2.1.8",
"_inBundle": false,
"_integrity": "sha512-8liAVezDmUcH+tdzoEGrhfbGcP7nOV4NkGE3a74+qqvE7nt9i4sKLGBuZNOnpI4WiGksiNPklZxva80061QiPg==",
"_location": "/reduce-css-calc",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "reduce-css-calc@2.1.8",
"name": "reduce-css-calc",
"escapedName": "reduce-css-calc",
"rawSpec": "2.1.8",
"saveSpec": null,
"fetchSpec": "2.1.8"
},
"_requiredBy": [
"/tailwindcss"
],
"_resolved": "https://registry.npmjs.org/reduce-css-calc/-/reduce-css-calc-2.1.8.tgz",
"_spec": "2.1.8",
"_where": "/d",
"author": {
"name": "Maxime Thirouin"
},
"bugs": {
"url": "https://github.com/MoOx/reduce-css-calc/issues"
},
"dependencies": {
"css-unit-converter": "^1.1.1",
"postcss-value-parser": "^3.3.0"
},
"description": "Reduce CSS calc() function to the maximum",
"devDependencies": {
"ava": "^0.18.2",
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"babel-eslint": "^7.1.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-env": "^1.6.0",
"babel-register": "^6.18.0",
"cross-env": "^3.1.4",
"del-cli": "^0.2.1",
"eslint": "^3.12.2",
"eslint-config-i-am-meticulous": "^6.0.1",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-import": "^2.2.0",
"jison-gho": "^0.6.1-216",
"npmpub": "^5.0.0"
},
"eslintConfig": {
"parser": "babel-eslint",
"extends": "eslint-config-i-am-meticulous"
},
"files": [
"dist"
],
"homepage": "https://github.com/MoOx/reduce-css-calc#readme",
"keywords": [
"css",
"calculation",
"calc"
],
"license": "MIT",
"main": "dist/index.js",
"name": "reduce-css-calc",
"repository": {
"type": "git",
"url": "git+https://github.com/MoOx/reduce-css-calc.git"
},
"scripts": {
"build": "del-cli dist && cross-env BABEL_ENV=publish babel src --out-dir dist && jison parser.jison -o dist/parser.js",
"prepublish": "npm run build && del-cli dist/__tests__",
"pretest": "eslint src && npm run build",
"release": "npmpub",
"test": "ava dist/__tests__/"
},
"version": "2.1.8"
}