postcss-lab-function 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changes to PostCSS Lab Function
2
2
 
3
+ ### 2.0.1 (September 18, 2018)
4
+
5
+ - Updated: PostCSS Values Parser 2.0.0
6
+
7
+ ### 2.0.0 (September 17, 2018)
8
+
9
+ - Updated: Support for PostCSS 7+
10
+ - Updated: Support for Node 6+
11
+
12
+ ### 1.1.0 (July 24, 2018)
13
+
14
+ - Added: Support for `gray(a / b)` as `lab(a 0 0 / b)`
15
+
16
+ ### 1.0.1 (May 11, 2018)
17
+
18
+ - Fixed: Values beyond the acceptable 0-255 RGB range
19
+
3
20
  ### 1.0.0 (May 11, 2018)
4
21
 
5
22
  - Initial version
package/README.md CHANGED
@@ -3,16 +3,17 @@
3
3
  [![NPM Version][npm-img]][npm-url]
4
4
  [![CSS Standard Status][css-img]][css-url]
5
5
  [![Build Status][cli-img]][cli-url]
6
- [![Windows Build Status][win-img]][win-url]
7
6
  [![Support Chat][git-img]][git-url]
8
7
 
9
- [PostCSS Lab Function] lets you use `lab` and `lch` color functions in CSS,
10
- following the [CSS Color] specification.
8
+ [PostCSS Lab Function] lets you use `lab`, `lch`, and `gray` color functions in
9
+ CSS, following the [CSS Color] specification.
11
10
 
12
11
  ```pcss
13
12
  :root {
14
13
  --firebrick: lab(40 56.6 39);
15
14
  --firebrick-a50: lch(40 68.8 34.5 / 50%);
15
+ --gray-40: gray(40);
16
+ --gray-40a50: gray(40 / .5);
16
17
  }
17
18
 
18
19
  /* becomes */
@@ -20,131 +21,43 @@ following the [CSS Color] specification.
20
21
  :root {
21
22
  --firebrick: rgb(178, 34, 34);
22
23
  --firebrick-a50: rgba(178, 34, 34, .5);
24
+ --gray-40: rgb(94,94,94);
25
+ --gray-40a50: rgba(94,94,94, .5);
23
26
  }
24
27
  ```
25
28
 
26
29
  ## Usage
27
30
 
28
- Add [PostCSS Lab Function] to your build tool:
31
+ Add [PostCSS Lab Function] to your project:
29
32
 
30
33
  ```bash
31
34
  npm install postcss-lab-function --save-dev
32
35
  ```
33
36
 
34
- #### Node
35
-
36
37
  Use [PostCSS Lab Function] to process your CSS:
37
38
 
38
39
  ```js
39
- import postcssLabFunction from 'postcss-lab-function';
40
-
41
- postcssLabFunction.process(YOUR_CSS, /* processOptions */, /* pluginOptions */);
42
- ```
43
-
44
- #### PostCSS
40
+ const postcssLabFunction = require('postcss-lab-function');
45
41
 
46
- Add [PostCSS] to your build tool:
47
-
48
- ```bash
49
- npm install postcss --save-dev
42
+ postcssLabFunction.process(YOUR_CSS /*, processOptions, pluginOptions */);
50
43
  ```
51
44
 
52
- Use [PostCSS Lab Function] as a plugin:
45
+ Or use it as a [PostCSS] plugin:
53
46
 
54
47
  ```js
55
- import postcss from 'gulp-postcss';
56
- import postcssLabFunction from 'postcss-lab-function';
48
+ const postcss = require('postcss');
49
+ const postcssLabFunction = require('postcss-lab-function');
57
50
 
58
51
  postcss([
59
52
  postcssLabFunction(/* pluginOptions */)
60
- ]).process(YOUR_CSS);
61
- ```
62
-
63
- #### Webpack
64
-
65
- Add [PostCSS Loader] to your build tool:
66
-
67
- ```bash
68
- npm install postcss-loader --save-dev
69
- ```
70
-
71
- Use [PostCSS Lab Function] in your Webpack configuration:
72
-
73
- ```js
74
- import postcssLabFunction from 'postcss-lab-function';
75
-
76
- module.exports = {
77
- module: {
78
- rules: [
79
- {
80
- test: /\.css$/,
81
- use: [
82
- 'style-loader',
83
- { loader: 'css-loader', options: { importLoaders: 1 } },
84
- { loader: 'postcss-loader', options: {
85
- ident: 'postcss',
86
- plugins: () => [
87
- postcssLabFunction(/* pluginOptions */)
88
- ]
89
- } }
90
- ]
91
- }
92
- ]
93
- }
94
- }
53
+ ]).process(YOUR_CSS /*, processOptions */);
95
54
  ```
96
55
 
97
- #### Gulp
56
+ [PostCSS Lab Function] runs in all Node environments, with special
57
+ instructions for:
98
58
 
99
- Add [Gulp PostCSS] to your build tool:
100
-
101
- ```bash
102
- npm install gulp-postcss --save-dev
103
- ```
104
-
105
- Use [PostCSS Lab Function] in your Gulpfile:
106
-
107
- ```js
108
- import postcss from 'gulp-postcss';
109
- import postcssLabFunction from 'postcss-lab-function';
110
-
111
- gulp.task('css', () => gulp.src('./src/*.css').pipe(
112
- postcss([
113
- postcssLabFunction(/* pluginOptions */)
114
- ])
115
- ).pipe(
116
- gulp.dest('.')
117
- ));
118
- ```
119
-
120
- #### Grunt
121
-
122
- Add [Grunt PostCSS] to your build tool:
123
-
124
- ```bash
125
- npm install grunt-postcss --save-dev
126
- ```
127
-
128
- Use [PostCSS Lab Function] in your Gruntfile:
129
-
130
- ```js
131
- import postcssLabFunction from 'postcss-lab-function';
132
-
133
- grunt.loadNpmTasks('grunt-postcss');
134
-
135
- grunt.initConfig({
136
- postcss: {
137
- options: {
138
- use: [
139
- postcssLabFunction(/* pluginOptions */)
140
- ]
141
- },
142
- dist: {
143
- src: '*.css'
144
- }
145
- }
146
- });
147
- ```
59
+ | [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
60
+ | --- | --- | --- | --- | --- | --- |
148
61
 
149
62
  ## Options
150
63
 
@@ -154,7 +67,7 @@ The `preserve` option determines whether the original functional color notation
154
67
  is preserved. By default, it is not preserved.
155
68
 
156
69
  ```js
157
- postcssImageSetFunction({ preserve: true })
70
+ postcssLabFunction({ preserve: true })
158
71
  ```
159
72
 
160
73
  ```pcss
@@ -181,8 +94,6 @@ postcssImageSetFunction({ preserve: true })
181
94
  [git-url]: https://gitter.im/postcss/postcss
182
95
  [npm-img]: https://img.shields.io/npm/v/postcss-lab-function.svg
183
96
  [npm-url]: https://www.npmjs.com/package/postcss-lab-function
184
- [win-img]: https://img.shields.io/appveyor/ci/jonathantneal/postcss-lab-function.svg
185
- [win-url]: https://ci.appveyor.com/project/jonathantneal/postcss-lab-function
186
97
 
187
98
  [CSS Color]: https://drafts.csswg.org/css-color/#specifying-lab-lch
188
99
  [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
package/index.cjs.js CHANGED
@@ -6,120 +6,127 @@ var convertColors = require('@csstools/convert-colors');
6
6
  var postcss = _interopDefault(require('postcss'));
7
7
  var parser = _interopDefault(require('postcss-values-parser'));
8
8
 
9
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
10
-
11
- var index = postcss.plugin('postcss-lab-function', function (opts) {
12
- var preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
13
-
14
- return function (root) {
15
- root.walkDecls(function (decl) {
16
- var value = decl.value;
17
-
18
-
19
- if (colorAnyRegExp.test(value)) {
20
- var ast = parser(value).parse();
21
-
22
- ast.walkType('func', function (node) {
23
- if (colorRegExp.test(node.value)) {
24
- var children = node.nodes.slice(1, -1);
25
- var isLab = labRegExp.test(node.value);
26
- var isFunctionalLAB = matchFunctionalLAB(children);
27
- var isFunctionalLCH = matchFunctionalLCH(children);
28
-
29
- if (isFunctionalLAB || isFunctionalLCH) {
30
- node.value = 'rgb';
31
-
32
- var slashNode = children[3];
33
- var alphaNode = children[4];
34
-
35
- if (alphaNode) {
36
- if (isPercentage(alphaNode) && !isCalc(alphaNode)) {
37
- alphaNode.unit = '';
38
- alphaNode.value = String(alphaNode.value / 100);
39
- }
40
-
41
- if (alphaNode.value === '1') {
42
- slashNode.remove();
43
- alphaNode.remove();
44
- } else {
45
- node.value += 'a';
46
- }
47
- }
48
-
49
- if (isSlash(slashNode)) {
50
- slashNode.replaceWith(newComma());
51
- }
52
-
53
- var converter = isLab ? convertColors.lab2rgb : convertColors.lch2rgb;
54
-
55
- var rgbValues = converter.apply(undefined, _toConsumableArray([children[0].value, children[1].value, children[2].value].map(function (number) {
56
- return parseFloat(number);
57
- }))).map(function (sourceValue) {
58
- return parseInt(sourceValue * 2.55);
59
- });
60
-
61
- children[0].value = String(rgbValues[0]);
62
- children[1].value = String(rgbValues[1]);
63
- children[2].value = String(rgbValues[2]);
64
-
65
- node.nodes.splice(3, 0, [newComma()]);
66
- node.nodes.splice(2, 0, [newComma()]);
67
- }
68
- }
69
- });
70
-
71
- var newValue = String(ast);
72
-
73
- if (preserve) {
74
- decl.cloneBefore({ value: newValue });
75
- } else {
76
- decl.value = newValue;
77
- }
78
- }
79
- });
80
- };
9
+ var index = postcss.plugin('postcss-lab-function', opts => {
10
+ const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
11
+ return root => {
12
+ root.walkDecls(decl => {
13
+ const value = decl.value;
14
+
15
+ if (colorAnyRegExp.test(value)) {
16
+ const ast = parser(value).parse();
17
+ ast.walkType('func', node => {
18
+ if (colorRegExp.test(node.value)) {
19
+ const children = node.nodes.slice(1, -1);
20
+ const isLab = labRegExp.test(node.value);
21
+ const isGray = grayRegExp.test(node.value);
22
+ const isFunctionalLAB = !isGray && matchFunctionalLAB(children);
23
+ const isFunctionalLCH = !isGray && matchFunctionalLCH(children);
24
+ const isFunctionalGray = isGray && matchFunctionalGray(children);
25
+
26
+ if (isFunctionalLAB || isFunctionalLCH) {
27
+ node.value = 'rgb';
28
+ const slashNode = children[3];
29
+ const alphaNode = children[4];
30
+
31
+ if (alphaNode) {
32
+ if (isPercentage(alphaNode) && !isCalc(alphaNode)) {
33
+ alphaNode.unit = '';
34
+ alphaNode.value = String(alphaNode.value / 100);
35
+ }
36
+
37
+ if (alphaNode.value === '1') {
38
+ slashNode.remove();
39
+ alphaNode.remove();
40
+ } else {
41
+ node.value += 'a';
42
+ }
43
+ }
44
+
45
+ if (slashNode && isSlash(slashNode)) {
46
+ slashNode.replaceWith(newComma());
47
+ }
48
+
49
+ const converter = isLab ? convertColors.lab2rgb : convertColors.lch2rgb;
50
+ const rgbValues = converter(...[children[0].value, children[1].value, children[2].value].map(number => parseFloat(number))).map(sourceValue => Math.max(Math.min(parseInt(sourceValue * 2.55), 255), 0));
51
+ children[0].value = String(rgbValues[0]);
52
+ children[1].value = String(rgbValues[1]);
53
+ children[2].value = String(rgbValues[2]);
54
+ node.nodes.splice(3, 0, [newComma()]);
55
+ node.nodes.splice(2, 0, [newComma()]);
56
+ } else if (isFunctionalGray) {
57
+ node.value = 'rgb';
58
+ const alphaNode = children[2];
59
+ const rgbValues = convertColors.lab2rgb(...[children[0].value, 0, 0].map(number => parseFloat(number))).map(sourceValue => Math.max(Math.min(parseInt(sourceValue * 2.55), 255), 0));
60
+ node.removeAll().append(newParen('(')).append(newNumber(rgbValues[0])).append(newComma()).append(newNumber(rgbValues[1])).append(newComma()).append(newNumber(rgbValues[2])).append(newParen(')'));
61
+
62
+ if (alphaNode) {
63
+ if (isPercentage(alphaNode) && !isCalc(alphaNode)) {
64
+ alphaNode.unit = '';
65
+ alphaNode.value = String(alphaNode.value / 100);
66
+ }
67
+
68
+ if (alphaNode.value !== '1') {
69
+ node.value += 'a';
70
+ node.insertBefore(node.last, newComma()).insertBefore(node.last, alphaNode);
71
+ }
72
+ }
73
+ }
74
+ }
75
+ });
76
+ const newValue = String(ast);
77
+
78
+ if (preserve) {
79
+ decl.cloneBefore({
80
+ value: newValue
81
+ });
82
+ } else {
83
+ decl.value = newValue;
84
+ }
85
+ }
86
+ });
87
+ };
81
88
  });
89
+ const colorAnyRegExp = /(^|[^\w-])(lab|lch|gray)\(/i;
90
+ const colorRegExp = /^(lab|lch|gray)$/i;
91
+ const labRegExp = /^lab$/i;
92
+ const grayRegExp = /^gray$/i;
93
+ const alphaUnitMatch = /^%?$/i;
94
+ const calcFuncMatch = /^calc$/i;
95
+ const hueUnitMatch = /^(deg|grad|rad|turn)?$/i;
82
96
 
83
- var colorAnyRegExp = /(^|[^\w-])(lab?|lch?)\(/i;
84
- var colorRegExp = /^(lab?|lch?)$/i;
85
- var labRegExp = /^lab$/i;
86
- var alphaUnitMatch = /^%?$/i;
87
- var calcFuncMatch = /^calc$/i;
88
- var hueUnitMatch = /^(deg|grad|rad|turn)?$/i;
89
-
90
- var isAlphaValue = function isAlphaValue(node) {
91
- return isCalc(node) || Object(node).type === 'number' && alphaUnitMatch.test(node.unit);
92
- };
93
- var isCalc = function isCalc(node) {
94
- return Object(node).type === 'func' && calcFuncMatch.test(node.value);
95
- };
96
- var isHue = function isHue(node) {
97
- return isCalc(node) || Object(node).type === 'number' && hueUnitMatch.test(node.unit);
98
- };
99
- var isNumber = function isNumber(node) {
100
- return isCalc(node) || Object(node).type === 'number' && node.unit === '';
101
- };
102
- var isPercentage = function isPercentage(node) {
103
- return isCalc(node) || Object(node).type === 'number' && node.unit === '%';
104
- };
105
- var isSlash = function isSlash(node) {
106
- return Object(node).type === 'operator' && node.value === '/';
107
- };
108
- var functionalLABMatch = [isNumber, isNumber, isNumber, isSlash, isAlphaValue];
109
- var functionalLCHMatch = [isNumber, isNumber, isHue, isSlash, isAlphaValue];
110
- var matchFunctionalLAB = function matchFunctionalLAB(children) {
111
- return children.every(function (child, index) {
112
- return typeof functionalLABMatch[index] === 'function' && functionalLABMatch[index](child);
113
- });
114
- };
115
- var matchFunctionalLCH = function matchFunctionalLCH(children) {
116
- return children.every(function (child, index) {
117
- return typeof functionalLCHMatch[index] === 'function' && functionalLCHMatch[index](child);
118
- });
119
- };
120
-
121
- var newComma = function newComma() {
122
- return parser.comma({ value: ',' });
123
- };
97
+ const isAlphaValue = node => isCalc(node) || node.type === 'number' && alphaUnitMatch.test(node.unit);
98
+
99
+ const isCalc = node => node.type === 'func' && calcFuncMatch.test(node.value);
100
+
101
+ const isHue = node => isCalc(node) || node.type === 'number' && hueUnitMatch.test(node.unit);
102
+
103
+ const isNumber = node => isCalc(node) || node.type === 'number' && node.unit === '';
104
+
105
+ const isPercentage = node => isCalc(node) || node.type === 'number' && node.unit === '%';
106
+
107
+ const isSlash = node => node.type === 'operator' && node.value === '/';
108
+
109
+ const functionalLABMatch = [isNumber, isNumber, isNumber, isSlash, isAlphaValue];
110
+ const functionalLCHMatch = [isNumber, isNumber, isHue, isSlash, isAlphaValue];
111
+ const functionalGrayMatch = [isNumber, isSlash, isAlphaValue];
112
+
113
+ const matchFunctionalLAB = children => children.every((child, index) => typeof functionalLABMatch[index] === 'function' && functionalLABMatch[index](child));
114
+
115
+ const matchFunctionalLCH = children => children.every((child, index) => typeof functionalLCHMatch[index] === 'function' && functionalLCHMatch[index](child));
116
+
117
+ const matchFunctionalGray = children => children.every((child, index) => typeof functionalGrayMatch[index] === 'function' && functionalGrayMatch[index](child));
118
+
119
+ const newComma = () => parser.comma({
120
+ value: ','
121
+ });
122
+
123
+ const newNumber = value => parser.number({
124
+ value
125
+ });
126
+
127
+ const newParen = value => parser.paren({
128
+ value
129
+ });
124
130
 
125
131
  module.exports = index;
132
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["index.js"],"sourcesContent":["import { lab2rgb, lch2rgb } from '@csstools/convert-colors';\nimport postcss from 'postcss';\nimport parser from 'postcss-values-parser';\n\nexport default postcss.plugin('postcss-lab-function', opts => {\n\tconst preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;\n\n\treturn root => {\n\t\troot.walkDecls(decl => {\n\t\t\tconst { value } = decl;\n\n\t\t\tif (colorAnyRegExp.test(value)) {\n\t\t\t\tconst ast = parser(value).parse();\n\n\t\t\t\tast.walkType('func', node => {\n\t\t\t\t\tif (colorRegExp.test(node.value)) {\n\t\t\t\t\t\tconst children = node.nodes.slice(1, -1);\n\t\t\t\t\t\tconst isLab = labRegExp.test(node.value);\n\t\t\t\t\t\tconst isGray = grayRegExp.test(node.value);\n\t\t\t\t\t\tconst isFunctionalLAB = !isGray && matchFunctionalLAB(children);\n\t\t\t\t\t\tconst isFunctionalLCH = !isGray && matchFunctionalLCH(children);\n\t\t\t\t\t\tconst isFunctionalGray = isGray && matchFunctionalGray(children);\n\n\t\t\t\t\t\tif (isFunctionalLAB || isFunctionalLCH) {\n\t\t\t\t\t\t\tnode.value = 'rgb';\n\n\t\t\t\t\t\t\tconst slashNode = children[3];\n\t\t\t\t\t\t\tconst alphaNode = children[4];\n\n\t\t\t\t\t\t\tif (alphaNode) {\n\t\t\t\t\t\t\t\tif (isPercentage(alphaNode) && !isCalc(alphaNode)) {\n\t\t\t\t\t\t\t\t\talphaNode.unit = '';\n\t\t\t\t\t\t\t\t\talphaNode.value = String(alphaNode.value / 100);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (alphaNode.value === '1') {\n\t\t\t\t\t\t\t\t\tslashNode.remove();\n\t\t\t\t\t\t\t\t\talphaNode.remove();\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tnode.value += 'a';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (slashNode && isSlash(slashNode)) {\n\t\t\t\t\t\t\t\tslashNode.replaceWith( newComma() );\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst converter = isLab ? lab2rgb : lch2rgb;\n\n\t\t\t\t\t\t\tconst rgbValues = converter(\n\t\t\t\t\t\t\t\t...[\n\t\t\t\t\t\t\t\t\tchildren[0].value,\n\t\t\t\t\t\t\t\t\tchildren[1].value,\n\t\t\t\t\t\t\t\t\tchildren[2].value\n\t\t\t\t\t\t\t\t].map(\n\t\t\t\t\t\t\t\t\tnumber => parseFloat(number)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t).map(\n\t\t\t\t\t\t\t\tsourceValue => Math.max(Math.min(parseInt(sourceValue * 2.55), 255), 0)\n\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\tchildren[0].value = String(rgbValues[0]);\n\t\t\t\t\t\t\tchildren[1].value = String(rgbValues[1]);\n\t\t\t\t\t\t\tchildren[2].value = String(rgbValues[2]);\n\n\t\t\t\t\t\t\tnode.nodes.splice(3, 0, [ newComma() ]);\n\t\t\t\t\t\t\tnode.nodes.splice(2, 0, [ newComma() ]);\n\t\t\t\t\t\t} else if (isFunctionalGray) {\n\t\t\t\t\t\t\tnode.value = 'rgb';\n\n\t\t\t\t\t\t\tconst alphaNode = children[2];\n\n\t\t\t\t\t\t\tconst rgbValues = lab2rgb(\n\t\t\t\t\t\t\t\t...[\n\t\t\t\t\t\t\t\t\tchildren[0].value,\n\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t0\n\t\t\t\t\t\t\t\t].map(\n\t\t\t\t\t\t\t\t\tnumber => parseFloat(number)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t).map(\n\t\t\t\t\t\t\t\tsourceValue => Math.max(Math.min(parseInt(sourceValue * 2.55), 255), 0)\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tnode.removeAll()\n\t\t\t\t\t\t\t.append(newParen('('))\n\t\t\t\t\t\t\t.append(newNumber(rgbValues[0]))\n\t\t\t\t\t\t\t.append(newComma())\n\t\t\t\t\t\t\t.append(newNumber(rgbValues[1]))\n\t\t\t\t\t\t\t.append(newComma())\n\t\t\t\t\t\t\t.append(newNumber(rgbValues[2]))\n\t\t\t\t\t\t\t.append(newParen(')'));\n\n\t\t\t\t\t\t\tif (alphaNode) {\n\t\t\t\t\t\t\t\tif (isPercentage(alphaNode) && !isCalc(alphaNode)) {\n\t\t\t\t\t\t\t\t\talphaNode.unit = '';\n\t\t\t\t\t\t\t\t\talphaNode.value = String(alphaNode.value / 100);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (alphaNode.value !== '1') {\n\t\t\t\t\t\t\t\t\tnode.value += 'a';\n\n\t\t\t\t\t\t\t\t\tnode\n\t\t\t\t\t\t\t\t\t.insertBefore(node.last, newComma())\n\t\t\t\t\t\t\t\t\t.insertBefore(node.last, alphaNode)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tconst newValue = String(ast);\n\n\t\t\t\tif (preserve) {\n\t\t\t\t\tdecl.cloneBefore({ value: newValue });\n\t\t\t\t} else {\n\t\t\t\t\tdecl.value = newValue;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n});\n\nconst colorAnyRegExp = /(^|[^\\w-])(lab|lch|gray)\\(/i;\nconst colorRegExp = /^(lab|lch|gray)$/i;\nconst labRegExp = /^lab$/i;\nconst grayRegExp = /^gray$/i;\nconst alphaUnitMatch = /^%?$/i;\nconst calcFuncMatch = /^calc$/i;\nconst hueUnitMatch = /^(deg|grad|rad|turn)?$/i;\n\nconst isAlphaValue = node => isCalc(node) || node.type === 'number' && alphaUnitMatch.test(node.unit);\nconst isCalc = node => node.type === 'func' && calcFuncMatch.test(node.value);\nconst isHue = node => isCalc(node) || node.type === 'number' && hueUnitMatch.test(node.unit);\nconst isNumber = node => isCalc(node) || node.type === 'number' && node.unit === '';\nconst isPercentage = node => isCalc(node) || node.type === 'number' && node.unit === '%';\nconst isSlash = node => node.type === 'operator' && node.value === '/';\nconst functionalLABMatch = [isNumber, isNumber, isNumber, isSlash, isAlphaValue];\nconst functionalLCHMatch = [isNumber, isNumber, isHue, isSlash, isAlphaValue];\nconst functionalGrayMatch = [isNumber, isSlash, isAlphaValue];\nconst matchFunctionalLAB = children => children.every(\n\t(child, index) => typeof functionalLABMatch[index] === 'function' && functionalLABMatch[index](child)\n);\nconst matchFunctionalLCH = children => children.every(\n\t(child, index) => typeof functionalLCHMatch[index] === 'function' && functionalLCHMatch[index](child)\n);\nconst matchFunctionalGray = children => children.every(\n\t(child, index) => typeof functionalGrayMatch[index] === 'function' && functionalGrayMatch[index](child)\n);\n\nconst newComma = () => parser.comma({ value: ',' });\nconst newNumber = value => parser.number({ value });\nconst newParen = value => parser.paren({ value });\n"],"names":["postcss","plugin","opts","preserve","Object","Boolean","root","walkDecls","decl","value","colorAnyRegExp","test","ast","parser","parse","walkType","node","colorRegExp","children","nodes","slice","isLab","labRegExp","isGray","grayRegExp","isFunctionalLAB","matchFunctionalLAB","isFunctionalLCH","matchFunctionalLCH","isFunctionalGray","matchFunctionalGray","slashNode","alphaNode","isPercentage","isCalc","unit","String","remove","isSlash","replaceWith","newComma","converter","lab2rgb","lch2rgb","rgbValues","map","number","parseFloat","sourceValue","Math","max","min","parseInt","splice","removeAll","append","newParen","newNumber","insertBefore","last","newValue","cloneBefore","alphaUnitMatch","calcFuncMatch","hueUnitMatch","isAlphaValue","type","isHue","isNumber","functionalLABMatch","functionalLCHMatch","functionalGrayMatch","every","child","index","comma","paren"],"mappings":";;;;;;;;AAIA,YAAeA,OAAO,CAACC,MAAR,CAAe,sBAAf,EAAuCC,IAAI,IAAI;QACvDC,QAAQ,GAAG,cAAcC,MAAM,CAACF,IAAD,CAApB,GAA6BG,OAAO,CAACH,IAAI,CAACC,QAAN,CAApC,GAAsD,KAAvE;SAEOG,IAAI,IAAI;IACdA,IAAI,CAACC,SAAL,CAAeC,IAAI,IAAI;YACdC,KADc,GACJD,IADI,CACdC,KADc;;UAGlBC,cAAc,CAACC,IAAf,CAAoBF,KAApB,CAAJ,EAAgC;cACzBG,GAAG,GAAGC,MAAM,CAACJ,KAAD,CAAN,CAAcK,KAAd,EAAZ;QAEAF,GAAG,CAACG,QAAJ,CAAa,MAAb,EAAqBC,IAAI,IAAI;cACxBC,WAAW,CAACN,IAAZ,CAAiBK,IAAI,CAACP,KAAtB,CAAJ,EAAkC;kBAC3BS,QAAQ,GAAGF,IAAI,CAACG,KAAL,CAAWC,KAAX,CAAiB,CAAjB,EAAoB,CAAC,CAArB,CAAjB;kBACMC,KAAK,GAAGC,SAAS,CAACX,IAAV,CAAeK,IAAI,CAACP,KAApB,CAAd;kBACMc,MAAM,GAAGC,UAAU,CAACb,IAAX,CAAgBK,IAAI,CAACP,KAArB,CAAf;kBACMgB,eAAe,GAAG,CAACF,MAAD,IAAW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,CAACK,KAAD,CAAlB,CAA0BD,KAA1B,CAD/B,CAAvC;;AAGA,MAAM7C,kBAAkB,GAAGV,QAAQ,IAAIA,QAAQ,CAACsD,KAAT,CACtC,CAACC,KAAD,EAAQC,KAAR,KAAkB,OAAOJ,kBAAkB,CAACI,KAAD,CAAzB,KAAqC,UAArC,IAAmDJ,kBAAkB,CAACI,KAAD,CAAlB,CAA0BD,KAA1B,CAD/B,CAAvC;;AAGA,MAAM3C,mBAAmB,GAAGZ,QAAQ,IAAIA,QAAQ,CAACsD,KAAT,CACvC,CAACC,KAAD,EAAQC,KAAR,KAAkB,OAAOH,mBAAmB,CAACG,KAAD,CAA1B,KAAsC,UAAtC,IAAoDH,mBAAmB,CAACG,KAAD,CAAnB,CAA2BD,KAA3B,CAD/B,CAAxC;;AAIA,MAAMjC,QAAQ,GAAG,MAAM3B,MAAM,CAAC8D,KAAP,CAAa;EAAElE,KAAK,EAAE;CAAtB,CAAvB;;AACA,MAAMgD,SAAS,GAAGhD,KAAK,IAAII,MAAM,CAACiC,MAAP,CAAc;EAAErC;CAAhB,CAA3B;;AACA,MAAM+C,QAAQ,GAAG/C,KAAK,IAAII,MAAM,CAAC+D,KAAP,CAAa;EAAEnE;CAAf,CAA1B;;;;"}
package/index.es.mjs ADDED
@@ -0,0 +1,128 @@
1
+ import { lab2rgb, lch2rgb } from '@csstools/convert-colors';
2
+ import postcss from 'postcss';
3
+ import parser from 'postcss-values-parser';
4
+
5
+ var index = postcss.plugin('postcss-lab-function', opts => {
6
+ const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
7
+ return root => {
8
+ root.walkDecls(decl => {
9
+ const value = decl.value;
10
+
11
+ if (colorAnyRegExp.test(value)) {
12
+ const ast = parser(value).parse();
13
+ ast.walkType('func', node => {
14
+ if (colorRegExp.test(node.value)) {
15
+ const children = node.nodes.slice(1, -1);
16
+ const isLab = labRegExp.test(node.value);
17
+ const isGray = grayRegExp.test(node.value);
18
+ const isFunctionalLAB = !isGray && matchFunctionalLAB(children);
19
+ const isFunctionalLCH = !isGray && matchFunctionalLCH(children);
20
+ const isFunctionalGray = isGray && matchFunctionalGray(children);
21
+
22
+ if (isFunctionalLAB || isFunctionalLCH) {
23
+ node.value = 'rgb';
24
+ const slashNode = children[3];
25
+ const alphaNode = children[4];
26
+
27
+ if (alphaNode) {
28
+ if (isPercentage(alphaNode) && !isCalc(alphaNode)) {
29
+ alphaNode.unit = '';
30
+ alphaNode.value = String(alphaNode.value / 100);
31
+ }
32
+
33
+ if (alphaNode.value === '1') {
34
+ slashNode.remove();
35
+ alphaNode.remove();
36
+ } else {
37
+ node.value += 'a';
38
+ }
39
+ }
40
+
41
+ if (slashNode && isSlash(slashNode)) {
42
+ slashNode.replaceWith(newComma());
43
+ }
44
+
45
+ const converter = isLab ? lab2rgb : lch2rgb;
46
+ const rgbValues = converter(...[children[0].value, children[1].value, children[2].value].map(number => parseFloat(number))).map(sourceValue => Math.max(Math.min(parseInt(sourceValue * 2.55), 255), 0));
47
+ children[0].value = String(rgbValues[0]);
48
+ children[1].value = String(rgbValues[1]);
49
+ children[2].value = String(rgbValues[2]);
50
+ node.nodes.splice(3, 0, [newComma()]);
51
+ node.nodes.splice(2, 0, [newComma()]);
52
+ } else if (isFunctionalGray) {
53
+ node.value = 'rgb';
54
+ const alphaNode = children[2];
55
+ const rgbValues = lab2rgb(...[children[0].value, 0, 0].map(number => parseFloat(number))).map(sourceValue => Math.max(Math.min(parseInt(sourceValue * 2.55), 255), 0));
56
+ node.removeAll().append(newParen('(')).append(newNumber(rgbValues[0])).append(newComma()).append(newNumber(rgbValues[1])).append(newComma()).append(newNumber(rgbValues[2])).append(newParen(')'));
57
+
58
+ if (alphaNode) {
59
+ if (isPercentage(alphaNode) && !isCalc(alphaNode)) {
60
+ alphaNode.unit = '';
61
+ alphaNode.value = String(alphaNode.value / 100);
62
+ }
63
+
64
+ if (alphaNode.value !== '1') {
65
+ node.value += 'a';
66
+ node.insertBefore(node.last, newComma()).insertBefore(node.last, alphaNode);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ });
72
+ const newValue = String(ast);
73
+
74
+ if (preserve) {
75
+ decl.cloneBefore({
76
+ value: newValue
77
+ });
78
+ } else {
79
+ decl.value = newValue;
80
+ }
81
+ }
82
+ });
83
+ };
84
+ });
85
+ const colorAnyRegExp = /(^|[^\w-])(lab|lch|gray)\(/i;
86
+ const colorRegExp = /^(lab|lch|gray)$/i;
87
+ const labRegExp = /^lab$/i;
88
+ const grayRegExp = /^gray$/i;
89
+ const alphaUnitMatch = /^%?$/i;
90
+ const calcFuncMatch = /^calc$/i;
91
+ const hueUnitMatch = /^(deg|grad|rad|turn)?$/i;
92
+
93
+ const isAlphaValue = node => isCalc(node) || node.type === 'number' && alphaUnitMatch.test(node.unit);
94
+
95
+ const isCalc = node => node.type === 'func' && calcFuncMatch.test(node.value);
96
+
97
+ const isHue = node => isCalc(node) || node.type === 'number' && hueUnitMatch.test(node.unit);
98
+
99
+ const isNumber = node => isCalc(node) || node.type === 'number' && node.unit === '';
100
+
101
+ const isPercentage = node => isCalc(node) || node.type === 'number' && node.unit === '%';
102
+
103
+ const isSlash = node => node.type === 'operator' && node.value === '/';
104
+
105
+ const functionalLABMatch = [isNumber, isNumber, isNumber, isSlash, isAlphaValue];
106
+ const functionalLCHMatch = [isNumber, isNumber, isHue, isSlash, isAlphaValue];
107
+ const functionalGrayMatch = [isNumber, isSlash, isAlphaValue];
108
+
109
+ const matchFunctionalLAB = children => children.every((child, index) => typeof functionalLABMatch[index] === 'function' && functionalLABMatch[index](child));
110
+
111
+ const matchFunctionalLCH = children => children.every((child, index) => typeof functionalLCHMatch[index] === 'function' && functionalLCHMatch[index](child));
112
+
113
+ const matchFunctionalGray = children => children.every((child, index) => typeof functionalGrayMatch[index] === 'function' && functionalGrayMatch[index](child));
114
+
115
+ const newComma = () => parser.comma({
116
+ value: ','
117
+ });
118
+
119
+ const newNumber = value => parser.number({
120
+ value
121
+ });
122
+
123
+ const newParen = value => parser.paren({
124
+ value
125
+ });
126
+
127
+ export default index;
128
+ //# sourceMappingURL=index.es.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.mjs","sources":["index.js"],"sourcesContent":["import { lab2rgb, lch2rgb } from '@csstools/convert-colors';\nimport postcss from 'postcss';\nimport parser from 'postcss-values-parser';\n\nexport default postcss.plugin('postcss-lab-function', opts => {\n\tconst preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;\n\n\treturn root => {\n\t\troot.walkDecls(decl => {\n\t\t\tconst { value } = decl;\n\n\t\t\tif (colorAnyRegExp.test(value)) {\n\t\t\t\tconst ast = parser(value).parse();\n\n\t\t\t\tast.walkType('func', node => {\n\t\t\t\t\tif (colorRegExp.test(node.value)) {\n\t\t\t\t\t\tconst children = node.nodes.slice(1, -1);\n\t\t\t\t\t\tconst isLab = labRegExp.test(node.value);\n\t\t\t\t\t\tconst isGray = grayRegExp.test(node.value);\n\t\t\t\t\t\tconst isFunctionalLAB = !isGray && matchFunctionalLAB(children);\n\t\t\t\t\t\tconst isFunctionalLCH = !isGray && matchFunctionalLCH(children);\n\t\t\t\t\t\tconst isFunctionalGray = isGray && matchFunctionalGray(children);\n\n\t\t\t\t\t\tif (isFunctionalLAB || isFunctionalLCH) {\n\t\t\t\t\t\t\tnode.value = 'rgb';\n\n\t\t\t\t\t\t\tconst slashNode = children[3];\n\t\t\t\t\t\t\tconst alphaNode = children[4];\n\n\t\t\t\t\t\t\tif (alphaNode) {\n\t\t\t\t\t\t\t\tif (isPercentage(alphaNode) && !isCalc(alphaNode)) {\n\t\t\t\t\t\t\t\t\talphaNode.unit = '';\n\t\t\t\t\t\t\t\t\talphaNode.value = String(alphaNode.value / 100);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (alphaNode.value === '1') {\n\t\t\t\t\t\t\t\t\tslashNode.remove();\n\t\t\t\t\t\t\t\t\talphaNode.remove();\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tnode.value += 'a';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (slashNode && isSlash(slashNode)) {\n\t\t\t\t\t\t\t\tslashNode.replaceWith( newComma() );\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst converter = isLab ? lab2rgb : lch2rgb;\n\n\t\t\t\t\t\t\tconst rgbValues = converter(\n\t\t\t\t\t\t\t\t...[\n\t\t\t\t\t\t\t\t\tchildren[0].value,\n\t\t\t\t\t\t\t\t\tchildren[1].value,\n\t\t\t\t\t\t\t\t\tchildren[2].value\n\t\t\t\t\t\t\t\t].map(\n\t\t\t\t\t\t\t\t\tnumber => parseFloat(number)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t).map(\n\t\t\t\t\t\t\t\tsourceValue => Math.max(Math.min(parseInt(sourceValue * 2.55), 255), 0)\n\t\t\t\t\t\t\t)\n\n\t\t\t\t\t\t\tchildren[0].value = String(rgbValues[0]);\n\t\t\t\t\t\t\tchildren[1].value = String(rgbValues[1]);\n\t\t\t\t\t\t\tchildren[2].value = String(rgbValues[2]);\n\n\t\t\t\t\t\t\tnode.nodes.splice(3, 0, [ newComma() ]);\n\t\t\t\t\t\t\tnode.nodes.splice(2, 0, [ newComma() ]);\n\t\t\t\t\t\t} else if (isFunctionalGray) {\n\t\t\t\t\t\t\tnode.value = 'rgb';\n\n\t\t\t\t\t\t\tconst alphaNode = children[2];\n\n\t\t\t\t\t\t\tconst rgbValues = lab2rgb(\n\t\t\t\t\t\t\t\t...[\n\t\t\t\t\t\t\t\t\tchildren[0].value,\n\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t0\n\t\t\t\t\t\t\t\t].map(\n\t\t\t\t\t\t\t\t\tnumber => parseFloat(number)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t).map(\n\t\t\t\t\t\t\t\tsourceValue => Math.max(Math.min(parseInt(sourceValue * 2.55), 255), 0)\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tnode.removeAll()\n\t\t\t\t\t\t\t.append(newParen('('))\n\t\t\t\t\t\t\t.append(newNumber(rgbValues[0]))\n\t\t\t\t\t\t\t.append(newComma())\n\t\t\t\t\t\t\t.append(newNumber(rgbValues[1]))\n\t\t\t\t\t\t\t.append(newComma())\n\t\t\t\t\t\t\t.append(newNumber(rgbValues[2]))\n\t\t\t\t\t\t\t.append(newParen(')'));\n\n\t\t\t\t\t\t\tif (alphaNode) {\n\t\t\t\t\t\t\t\tif (isPercentage(alphaNode) && !isCalc(alphaNode)) {\n\t\t\t\t\t\t\t\t\talphaNode.unit = '';\n\t\t\t\t\t\t\t\t\talphaNode.value = String(alphaNode.value / 100);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (alphaNode.value !== '1') {\n\t\t\t\t\t\t\t\t\tnode.value += 'a';\n\n\t\t\t\t\t\t\t\t\tnode\n\t\t\t\t\t\t\t\t\t.insertBefore(node.last, newComma())\n\t\t\t\t\t\t\t\t\t.insertBefore(node.last, alphaNode)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tconst newValue = String(ast);\n\n\t\t\t\tif (preserve) {\n\t\t\t\t\tdecl.cloneBefore({ value: newValue });\n\t\t\t\t} else {\n\t\t\t\t\tdecl.value = newValue;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n});\n\nconst colorAnyRegExp = /(^|[^\\w-])(lab|lch|gray)\\(/i;\nconst colorRegExp = /^(lab|lch|gray)$/i;\nconst labRegExp = /^lab$/i;\nconst grayRegExp = /^gray$/i;\nconst alphaUnitMatch = /^%?$/i;\nconst calcFuncMatch = /^calc$/i;\nconst hueUnitMatch = /^(deg|grad|rad|turn)?$/i;\n\nconst isAlphaValue = node => isCalc(node) || node.type === 'number' && alphaUnitMatch.test(node.unit);\nconst isCalc = node => node.type === 'func' && calcFuncMatch.test(node.value);\nconst isHue = node => isCalc(node) || node.type === 'number' && hueUnitMatch.test(node.unit);\nconst isNumber = node => isCalc(node) || node.type === 'number' && node.unit === '';\nconst isPercentage = node => isCalc(node) || node.type === 'number' && node.unit === '%';\nconst isSlash = node => node.type === 'operator' && node.value === '/';\nconst functionalLABMatch = [isNumber, isNumber, isNumber, isSlash, isAlphaValue];\nconst functionalLCHMatch = [isNumber, isNumber, isHue, isSlash, isAlphaValue];\nconst functionalGrayMatch = [isNumber, isSlash, isAlphaValue];\nconst matchFunctionalLAB = children => children.every(\n\t(child, index) => typeof functionalLABMatch[index] === 'function' && functionalLABMatch[index](child)\n);\nconst matchFunctionalLCH = children => children.every(\n\t(child, index) => typeof functionalLCHMatch[index] === 'function' && functionalLCHMatch[index](child)\n);\nconst matchFunctionalGray = children => children.every(\n\t(child, index) => typeof functionalGrayMatch[index] === 'function' && functionalGrayMatch[index](child)\n);\n\nconst newComma = () => parser.comma({ value: ',' });\nconst newNumber = value => parser.number({ value });\nconst newParen = value => parser.paren({ value });\n"],"names":["postcss","plugin","opts","preserve","Object","Boolean","root","walkDecls","decl","value","colorAnyRegExp","test","ast","parser","parse","walkType","node","colorRegExp","children","nodes","slice","isLab","labRegExp","isGray","grayRegExp","isFunctionalLAB","matchFunctionalLAB","isFunctionalLCH","matchFunctionalLCH","isFunctionalGray","matchFunctionalGray","slashNode","alphaNode","isPercentage","isCalc","unit","String","remove","isSlash","replaceWith","newComma","converter","lab2rgb","lch2rgb","rgbValues","map","number","parseFloat","sourceValue","Math","max","min","parseInt","splice","removeAll","append","newParen","newNumber","insertBefore","last","newValue","cloneBefore","alphaUnitMatch","calcFuncMatch","hueUnitMatch","isAlphaValue","type","isHue","isNumber","functionalLABMatch","functionalLCHMatch","functionalGrayMatch","every","child","index","comma","paren"],"mappings":";;;;AAIA,YAAeA,OAAO,CAACC,MAAR,CAAe,sBAAf,EAAuCC,IAAI,IAAI;QACvDC,QAAQ,GAAG,cA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B,MAAM,CAAC8D,KAAP,CAAa;EAAElE,KAAK,EAAE;CAAtB,CAAvB;;AACA,MAAMgD,SAAS,GAAGhD,KAAK,IAAII,MAAM,CAACiC,MAAP,CAAc;EAAErC;CAAhB,CAA3B;;AACA,MAAM+C,QAAQ,GAAG/C,KAAK,IAAII,MAAM,CAAC+D,KAAP,CAAa;EAAEnE;CAAf,CAA1B;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-lab-function",
3
- "version": "1.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Use lab() and lch() color functions in CSS",
5
5
  "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
6
  "license": "CC0-1.0",
@@ -8,10 +8,12 @@
8
8
  "homepage": "https://github.com/jonathantneal/postcss-lab-function#readme",
9
9
  "bugs": "https://github.com/jonathantneal/postcss-lab-function/issues",
10
10
  "main": "index.cjs.js",
11
- "module": "index.es.js",
11
+ "module": "index.es.mjs",
12
12
  "files": [
13
13
  "index.cjs.js",
14
- "index.es.js"
14
+ "index.cjs.js.map",
15
+ "index.es.mjs",
16
+ "index.es.mjs.map"
15
17
  ],
16
18
  "scripts": {
17
19
  "prepublishOnly": "npm test",
@@ -22,23 +24,23 @@
22
24
  "test:tape": "postcss-tape"
23
25
  },
24
26
  "engines": {
25
- "node": ">=4.0.0"
27
+ "node": ">=6.0.0"
26
28
  },
27
29
  "dependencies": {
28
30
  "@csstools/convert-colors": "^1.4.0",
29
- "postcss": "^6.0.22",
30
- "postcss-values-parser": "^1.5.0"
31
+ "postcss": "^7.0.2",
32
+ "postcss-values-parser": "^2.0.0"
31
33
  },
32
34
  "devDependencies": {
33
- "babel-core": "^6.26.3",
34
- "babel-eslint": "^8.2.3",
35
- "babel-preset-env": "^1.7.0",
36
- "eslint": "^4.19.1",
35
+ "@babel/core": "^7.1.0",
36
+ "@babel/preset-env": "^7.1.0",
37
+ "babel-eslint": "^9.0.0",
38
+ "eslint": "^5.6.0",
37
39
  "eslint-config-dev": "^2.0.0",
38
40
  "postcss-tape": "^2.2.0",
39
41
  "pre-commit": "^1.2.2",
40
- "rollup": "^0.58.2",
41
- "rollup-plugin-babel": "^3.0.4"
42
+ "rollup": "^0.66.0",
43
+ "rollup-plugin-babel": "^4.0.3"
42
44
  },
43
45
  "eslintConfig": {
44
46
  "extends": "dev",
package/index.es.js DELETED
@@ -1,121 +0,0 @@
1
- import { lab2rgb, lch2rgb } from '@csstools/convert-colors';
2
- import postcss from 'postcss';
3
- import parser from 'postcss-values-parser';
4
-
5
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
6
-
7
- var index = postcss.plugin('postcss-lab-function', function (opts) {
8
- var preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
9
-
10
- return function (root) {
11
- root.walkDecls(function (decl) {
12
- var value = decl.value;
13
-
14
-
15
- if (colorAnyRegExp.test(value)) {
16
- var ast = parser(value).parse();
17
-
18
- ast.walkType('func', function (node) {
19
- if (colorRegExp.test(node.value)) {
20
- var children = node.nodes.slice(1, -1);
21
- var isLab = labRegExp.test(node.value);
22
- var isFunctionalLAB = matchFunctionalLAB(children);
23
- var isFunctionalLCH = matchFunctionalLCH(children);
24
-
25
- if (isFunctionalLAB || isFunctionalLCH) {
26
- node.value = 'rgb';
27
-
28
- var slashNode = children[3];
29
- var alphaNode = children[4];
30
-
31
- if (alphaNode) {
32
- if (isPercentage(alphaNode) && !isCalc(alphaNode)) {
33
- alphaNode.unit = '';
34
- alphaNode.value = String(alphaNode.value / 100);
35
- }
36
-
37
- if (alphaNode.value === '1') {
38
- slashNode.remove();
39
- alphaNode.remove();
40
- } else {
41
- node.value += 'a';
42
- }
43
- }
44
-
45
- if (isSlash(slashNode)) {
46
- slashNode.replaceWith(newComma());
47
- }
48
-
49
- var converter = isLab ? lab2rgb : lch2rgb;
50
-
51
- var rgbValues = converter.apply(undefined, _toConsumableArray([children[0].value, children[1].value, children[2].value].map(function (number) {
52
- return parseFloat(number);
53
- }))).map(function (sourceValue) {
54
- return parseInt(sourceValue * 2.55);
55
- });
56
-
57
- children[0].value = String(rgbValues[0]);
58
- children[1].value = String(rgbValues[1]);
59
- children[2].value = String(rgbValues[2]);
60
-
61
- node.nodes.splice(3, 0, [newComma()]);
62
- node.nodes.splice(2, 0, [newComma()]);
63
- }
64
- }
65
- });
66
-
67
- var newValue = String(ast);
68
-
69
- if (preserve) {
70
- decl.cloneBefore({ value: newValue });
71
- } else {
72
- decl.value = newValue;
73
- }
74
- }
75
- });
76
- };
77
- });
78
-
79
- var colorAnyRegExp = /(^|[^\w-])(lab?|lch?)\(/i;
80
- var colorRegExp = /^(lab?|lch?)$/i;
81
- var labRegExp = /^lab$/i;
82
- var alphaUnitMatch = /^%?$/i;
83
- var calcFuncMatch = /^calc$/i;
84
- var hueUnitMatch = /^(deg|grad|rad|turn)?$/i;
85
-
86
- var isAlphaValue = function isAlphaValue(node) {
87
- return isCalc(node) || Object(node).type === 'number' && alphaUnitMatch.test(node.unit);
88
- };
89
- var isCalc = function isCalc(node) {
90
- return Object(node).type === 'func' && calcFuncMatch.test(node.value);
91
- };
92
- var isHue = function isHue(node) {
93
- return isCalc(node) || Object(node).type === 'number' && hueUnitMatch.test(node.unit);
94
- };
95
- var isNumber = function isNumber(node) {
96
- return isCalc(node) || Object(node).type === 'number' && node.unit === '';
97
- };
98
- var isPercentage = function isPercentage(node) {
99
- return isCalc(node) || Object(node).type === 'number' && node.unit === '%';
100
- };
101
- var isSlash = function isSlash(node) {
102
- return Object(node).type === 'operator' && node.value === '/';
103
- };
104
- var functionalLABMatch = [isNumber, isNumber, isNumber, isSlash, isAlphaValue];
105
- var functionalLCHMatch = [isNumber, isNumber, isHue, isSlash, isAlphaValue];
106
- var matchFunctionalLAB = function matchFunctionalLAB(children) {
107
- return children.every(function (child, index) {
108
- return typeof functionalLABMatch[index] === 'function' && functionalLABMatch[index](child);
109
- });
110
- };
111
- var matchFunctionalLCH = function matchFunctionalLCH(children) {
112
- return children.every(function (child, index) {
113
- return typeof functionalLCHMatch[index] === 'function' && functionalLCHMatch[index](child);
114
- });
115
- };
116
-
117
- var newComma = function newComma() {
118
- return parser.comma({ value: ',' });
119
- };
120
-
121
- export default index;