postcss-color-functional-notation 3.0.0 → 4.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/README.md +2 -10
- package/dist/index.cjs.js +34 -24
- package/dist/index.esm.js +34 -22
- package/package.json +18 -12
- package/CHANGELOG.md +0 -28
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[<img alt="NPM Version" src="https://img.shields.io/npm/v/postcss-color-functional-notation.svg" height="20">][npm-url]
|
|
4
4
|
[<img alt="CSS Standard Status" src="https://cssdb.org/badge/lab-function.svg" height="20">][css-url]
|
|
5
|
-
[<img alt="Build Status" src="https://
|
|
5
|
+
[<img alt="Build Status" src="https://github.com/csstools/postcss-color-functional-notation/workflows/test/badge.svg" height="20">][cli-url]
|
|
6
6
|
[<img alt="Support Chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]
|
|
7
7
|
|
|
8
8
|
[PostCSS Color Functional Notation] lets you use space and slash separated
|
|
@@ -36,14 +36,6 @@ npm install postcss-color-functional-notation --save-dev
|
|
|
36
36
|
|
|
37
37
|
Use [PostCSS Color Functional Notation] to process your CSS:
|
|
38
38
|
|
|
39
|
-
```js
|
|
40
|
-
const postcssColorFunctionalNotation = require('postcss-color-functional-notation');
|
|
41
|
-
|
|
42
|
-
postcssColorFunctionalNotation.process(YOUR_CSS /*, processOptions, pluginOptions */);
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Or use it as a [PostCSS] plugin:
|
|
46
|
-
|
|
47
39
|
```js
|
|
48
40
|
const postcss = require('postcss');
|
|
49
41
|
const postcssColorFunctionalNotation = require('postcss-color-functional-notation');
|
|
@@ -91,7 +83,7 @@ postcssImageSetFunction({ preserve: true })
|
|
|
91
83
|
}
|
|
92
84
|
```
|
|
93
85
|
|
|
94
|
-
[cli-url]: https://
|
|
86
|
+
[cli-url]: https://github.com/csstools/postcss-color-functional-notation/actions/workflows/test.yml?query=workflow/test
|
|
95
87
|
[css-url]: https://cssdb.org/#color-functional-notation
|
|
96
88
|
[git-url]: https://gitter.im/postcss/postcss
|
|
97
89
|
[npm-url]: https://www.npmjs.com/package/postcss-color-functional-notation
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
-
|
|
5
|
-
var postcss = _interopDefault(require('postcss'));
|
|
6
3
|
var postcssValuesParser = require('postcss-values-parser');
|
|
7
4
|
|
|
8
5
|
/** @type {(decl: CSSFunction) => void} Transform a space and slash separated color function. */
|
|
@@ -19,10 +16,6 @@ const onCSSFunction = node => {
|
|
|
19
16
|
const isRgbWithNumbers = isRgbColorFunctionName(name) && isRgbNumberFunctionContents(nodes);
|
|
20
17
|
const isRgbWithPercents = isRgbColorFunctionName(name) && isRgbPercentFunctionContents(nodes);
|
|
21
18
|
|
|
22
|
-
if (name === 'hsl' && !isHsl) {
|
|
23
|
-
console.log([name, isHue(nodes[0])], nodes[0]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
19
|
if (isHsl || isRgbWithNumbers || isRgbWithPercents) {
|
|
27
20
|
// rename the Color function to `hsl` or `rgb`
|
|
28
21
|
Object.assign(node, {
|
|
@@ -95,25 +88,25 @@ function to255ColorValue(value) {
|
|
|
95
88
|
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
96
89
|
|
|
97
90
|
|
|
98
|
-
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
91
|
+
const createRegExpTest$1 = Function.bind.bind(RegExp.prototype.test);
|
|
99
92
|
/** Return whether the function name is `hsl()`, `hsla()`, `rgb()`, or `rgba()`. */
|
|
100
93
|
|
|
101
|
-
const isColorFunctionName = createRegExpTest(/^(hsl|rgb)a?$/i);
|
|
94
|
+
const isColorFunctionName = createRegExpTest$1(/^(hsl|rgb)a?$/i);
|
|
102
95
|
/** Return whether the function name is `hsl()` or `hsla()`. */
|
|
103
96
|
|
|
104
|
-
const isHslColorFunctionName = createRegExpTest(/^hsla?$/i);
|
|
97
|
+
const isHslColorFunctionName = createRegExpTest$1(/^hsla?$/i);
|
|
105
98
|
/** Return whether the function name is `rgb()` or `rgba()`. */
|
|
106
99
|
|
|
107
|
-
const isRgbColorFunctionName = createRegExpTest(/^rgba?$/i);
|
|
100
|
+
const isRgbColorFunctionName = createRegExpTest$1(/^rgba?$/i);
|
|
108
101
|
/** Return whether the function name is `calc`. */
|
|
109
102
|
|
|
110
|
-
const isCalcFunctionName = createRegExpTest(/^calc$/i);
|
|
103
|
+
const isCalcFunctionName = createRegExpTest$1(/^calc$/i);
|
|
111
104
|
/** Return whether the unit is alpha-like. */
|
|
112
105
|
|
|
113
|
-
const isAlphaLikeUnit = createRegExpTest(/^%?$/i);
|
|
106
|
+
const isAlphaLikeUnit = createRegExpTest$1(/^%?$/i);
|
|
114
107
|
/** Return whether the unit is hue-like. */
|
|
115
108
|
|
|
116
|
-
const isHueLikeUnit = createRegExpTest(/^(deg|grad|rad|turn)?$/i);
|
|
109
|
+
const isHueLikeUnit = createRegExpTest$1(/^(deg|grad|rad|turn)?$/i);
|
|
117
110
|
/** @type {(node: CSSNumber) => boolean} Return whether the node is an Alpha-like unit. */
|
|
118
111
|
|
|
119
112
|
const isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit);
|
|
@@ -176,14 +169,29 @@ var options = {
|
|
|
176
169
|
|
|
177
170
|
/** @type {(decl: CSSDeclaration) => void} Transform space and slash separated color functions in CSS Declarations. */
|
|
178
171
|
|
|
179
|
-
const onCSSDeclaration = decl
|
|
172
|
+
const onCSSDeclaration = (decl, {
|
|
173
|
+
result
|
|
174
|
+
}) => {
|
|
180
175
|
const {
|
|
181
176
|
value: originalValue
|
|
182
177
|
} = decl;
|
|
183
178
|
|
|
184
179
|
if (hasAnyColorFunction(originalValue)) {
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
let valueAST;
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
valueAST = postcssValuesParser.parse(originalValue, {
|
|
184
|
+
ignoreUnknownWords: true
|
|
185
|
+
});
|
|
186
|
+
} catch (error) {
|
|
187
|
+
decl.warn(result, `Failed to parse value '${originalValue}' as a color function. Leaving the original value intact.`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (typeof valueAST === 'undefined') {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
valueAST.walkType('func', onCSSFunction);
|
|
187
195
|
const modifiedValue = String(valueAST);
|
|
188
196
|
|
|
189
197
|
if (modifiedValue !== originalValue) {
|
|
@@ -195,24 +203,26 @@ const onCSSDeclaration = decl => {
|
|
|
195
203
|
};
|
|
196
204
|
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
197
205
|
|
|
198
|
-
const createRegExpTest
|
|
206
|
+
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
199
207
|
/** Return whether the value has an `hsl()`, `hsla()`, `rgb()`, or `rgba()` function. */
|
|
200
208
|
|
|
201
|
-
const hasAnyColorFunction = createRegExpTest
|
|
209
|
+
const hasAnyColorFunction = createRegExpTest(/(^|[^\w-])(hsla?|rgba?)\(/i);
|
|
202
210
|
/** @typedef {import('postcss').Declaration} CSSDeclaration */
|
|
203
211
|
|
|
204
212
|
/** Transform space and slash separated color functions in CSS. */
|
|
205
213
|
|
|
206
|
-
|
|
214
|
+
function postcssColorFunctionalNotation(opts) {
|
|
207
215
|
options.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
|
|
208
|
-
return
|
|
209
|
-
|
|
216
|
+
return {
|
|
217
|
+
postcssPlugin: 'postcss-color-functional-notation',
|
|
218
|
+
Declaration: onCSSDeclaration
|
|
210
219
|
};
|
|
211
|
-
}
|
|
220
|
+
}
|
|
221
|
+
postcssColorFunctionalNotation.postcss = true;
|
|
212
222
|
/** @typedef {import('postcss').Root} CSSRoot */
|
|
213
223
|
|
|
214
224
|
/** @typedef {(root: CSSRoot) => void} PostCSSTransformCallback */
|
|
215
225
|
|
|
216
226
|
/** @typedef {(opts: options) => PostCSSTransformCallback} PostCSSPluginInitializer */
|
|
217
227
|
|
|
218
|
-
module.exports =
|
|
228
|
+
module.exports = postcssColorFunctionalNotation;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import postcss from 'postcss';
|
|
2
1
|
import { parse } from 'postcss-values-parser';
|
|
3
2
|
|
|
4
3
|
/** @type {(decl: CSSFunction) => void} Transform a space and slash separated color function. */
|
|
@@ -15,10 +14,6 @@ const onCSSFunction = node => {
|
|
|
15
14
|
const isRgbWithNumbers = isRgbColorFunctionName(name) && isRgbNumberFunctionContents(nodes);
|
|
16
15
|
const isRgbWithPercents = isRgbColorFunctionName(name) && isRgbPercentFunctionContents(nodes);
|
|
17
16
|
|
|
18
|
-
if (name === 'hsl' && !isHsl) {
|
|
19
|
-
console.log([name, isHue(nodes[0])], nodes[0]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
17
|
if (isHsl || isRgbWithNumbers || isRgbWithPercents) {
|
|
23
18
|
// rename the Color function to `hsl` or `rgb`
|
|
24
19
|
Object.assign(node, {
|
|
@@ -91,25 +86,25 @@ function to255ColorValue(value) {
|
|
|
91
86
|
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
92
87
|
|
|
93
88
|
|
|
94
|
-
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
89
|
+
const createRegExpTest$1 = Function.bind.bind(RegExp.prototype.test);
|
|
95
90
|
/** Return whether the function name is `hsl()`, `hsla()`, `rgb()`, or `rgba()`. */
|
|
96
91
|
|
|
97
|
-
const isColorFunctionName = createRegExpTest(/^(hsl|rgb)a?$/i);
|
|
92
|
+
const isColorFunctionName = createRegExpTest$1(/^(hsl|rgb)a?$/i);
|
|
98
93
|
/** Return whether the function name is `hsl()` or `hsla()`. */
|
|
99
94
|
|
|
100
|
-
const isHslColorFunctionName = createRegExpTest(/^hsla?$/i);
|
|
95
|
+
const isHslColorFunctionName = createRegExpTest$1(/^hsla?$/i);
|
|
101
96
|
/** Return whether the function name is `rgb()` or `rgba()`. */
|
|
102
97
|
|
|
103
|
-
const isRgbColorFunctionName = createRegExpTest(/^rgba?$/i);
|
|
98
|
+
const isRgbColorFunctionName = createRegExpTest$1(/^rgba?$/i);
|
|
104
99
|
/** Return whether the function name is `calc`. */
|
|
105
100
|
|
|
106
|
-
const isCalcFunctionName = createRegExpTest(/^calc$/i);
|
|
101
|
+
const isCalcFunctionName = createRegExpTest$1(/^calc$/i);
|
|
107
102
|
/** Return whether the unit is alpha-like. */
|
|
108
103
|
|
|
109
|
-
const isAlphaLikeUnit = createRegExpTest(/^%?$/i);
|
|
104
|
+
const isAlphaLikeUnit = createRegExpTest$1(/^%?$/i);
|
|
110
105
|
/** Return whether the unit is hue-like. */
|
|
111
106
|
|
|
112
|
-
const isHueLikeUnit = createRegExpTest(/^(deg|grad|rad|turn)?$/i);
|
|
107
|
+
const isHueLikeUnit = createRegExpTest$1(/^(deg|grad|rad|turn)?$/i);
|
|
113
108
|
/** @type {(node: CSSNumber) => boolean} Return whether the node is an Alpha-like unit. */
|
|
114
109
|
|
|
115
110
|
const isAlphaValue = node => isCalc(node) || node.type === 'numeric' && isAlphaLikeUnit(node.unit);
|
|
@@ -172,14 +167,29 @@ var options = {
|
|
|
172
167
|
|
|
173
168
|
/** @type {(decl: CSSDeclaration) => void} Transform space and slash separated color functions in CSS Declarations. */
|
|
174
169
|
|
|
175
|
-
const onCSSDeclaration = decl
|
|
170
|
+
const onCSSDeclaration = (decl, {
|
|
171
|
+
result
|
|
172
|
+
}) => {
|
|
176
173
|
const {
|
|
177
174
|
value: originalValue
|
|
178
175
|
} = decl;
|
|
179
176
|
|
|
180
177
|
if (hasAnyColorFunction(originalValue)) {
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
let valueAST;
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
valueAST = parse(originalValue, {
|
|
182
|
+
ignoreUnknownWords: true
|
|
183
|
+
});
|
|
184
|
+
} catch (error) {
|
|
185
|
+
decl.warn(result, `Failed to parse value '${originalValue}' as a color function. Leaving the original value intact.`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (typeof valueAST === 'undefined') {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
valueAST.walkType('func', onCSSFunction);
|
|
183
193
|
const modifiedValue = String(valueAST);
|
|
184
194
|
|
|
185
195
|
if (modifiedValue !== originalValue) {
|
|
@@ -191,24 +201,26 @@ const onCSSDeclaration = decl => {
|
|
|
191
201
|
};
|
|
192
202
|
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
|
|
193
203
|
|
|
194
|
-
const createRegExpTest
|
|
204
|
+
const createRegExpTest = Function.bind.bind(RegExp.prototype.test);
|
|
195
205
|
/** Return whether the value has an `hsl()`, `hsla()`, `rgb()`, or `rgba()` function. */
|
|
196
206
|
|
|
197
|
-
const hasAnyColorFunction = createRegExpTest
|
|
207
|
+
const hasAnyColorFunction = createRegExpTest(/(^|[^\w-])(hsla?|rgba?)\(/i);
|
|
198
208
|
/** @typedef {import('postcss').Declaration} CSSDeclaration */
|
|
199
209
|
|
|
200
210
|
/** Transform space and slash separated color functions in CSS. */
|
|
201
211
|
|
|
202
|
-
|
|
212
|
+
function postcssColorFunctionalNotation(opts) {
|
|
203
213
|
options.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
|
|
204
|
-
return
|
|
205
|
-
|
|
214
|
+
return {
|
|
215
|
+
postcssPlugin: 'postcss-color-functional-notation',
|
|
216
|
+
Declaration: onCSSDeclaration
|
|
206
217
|
};
|
|
207
|
-
}
|
|
218
|
+
}
|
|
219
|
+
postcssColorFunctionalNotation.postcss = true;
|
|
208
220
|
/** @typedef {import('postcss').Root} CSSRoot */
|
|
209
221
|
|
|
210
222
|
/** @typedef {(root: CSSRoot) => void} PostCSSTransformCallback */
|
|
211
223
|
|
|
212
224
|
/** @typedef {(opts: options) => PostCSSTransformCallback} PostCSSPluginInitializer */
|
|
213
225
|
|
|
214
|
-
export default
|
|
226
|
+
export { postcssColorFunctionalNotation as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-color-functional-notation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Use space and slash separated color notation in CSS",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "CC0-1.0",
|
|
@@ -19,23 +19,26 @@
|
|
|
19
19
|
"lint:fix": "npx eslint --cache --fix",
|
|
20
20
|
"pretest": "npm install && npm run build",
|
|
21
21
|
"test": "npm run lint && npm run tape",
|
|
22
|
-
"tape": "npx postcss-tape"
|
|
22
|
+
"tape": "npx postcss-tape",
|
|
23
|
+
"prepublishOnly": "npm test"
|
|
23
24
|
},
|
|
24
25
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
26
|
+
"node": ">=12"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"postcss": "
|
|
29
|
-
|
|
29
|
+
"postcss-values-parser": "6.0.1"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"postcss": "^8.3"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/preset-env": "^7.
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"postcss-tape": "^
|
|
35
|
+
"@babel/core": "^7.16.0",
|
|
36
|
+
"@babel/preset-env": "^7.16.4",
|
|
37
|
+
"eslint": "^8.2.0",
|
|
38
|
+
"postcss": "^8.3.11",
|
|
39
|
+
"postcss-tape": "^6.0.1",
|
|
37
40
|
"pre-commit": "^1.2.2",
|
|
38
|
-
"rollup": "^2.
|
|
41
|
+
"rollup": "^2.60.0",
|
|
39
42
|
"rollup-plugin-babel": "^4.4.0"
|
|
40
43
|
},
|
|
41
44
|
"babel": {
|
|
@@ -54,7 +57,9 @@
|
|
|
54
57
|
"node": true
|
|
55
58
|
},
|
|
56
59
|
"extends": "eslint:recommended",
|
|
57
|
-
"
|
|
60
|
+
"parserOptions": {
|
|
61
|
+
"sourceType": "module"
|
|
62
|
+
}
|
|
58
63
|
},
|
|
59
64
|
"rollup": {
|
|
60
65
|
"input": "src/index.js",
|
|
@@ -63,6 +68,7 @@
|
|
|
63
68
|
],
|
|
64
69
|
"output": [
|
|
65
70
|
{
|
|
71
|
+
"exports": "default",
|
|
66
72
|
"file": "dist/index.cjs.js",
|
|
67
73
|
"format": "cjs"
|
|
68
74
|
},
|
package/CHANGELOG.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Changes to PostCSS Color Functional Notation
|
|
2
|
-
|
|
3
|
-
### 3.0.0 (April 25, 2020)
|
|
4
|
-
|
|
5
|
-
- Updated: Support for Node 10+
|
|
6
|
-
- Updated: `postcss` to 7.0.27 (patch)
|
|
7
|
-
- Updated: `postcss-values-parser` to 3.2.0 (minor)
|
|
8
|
-
|
|
9
|
-
### 2.0.1 (September 18, 2018)
|
|
10
|
-
|
|
11
|
-
- Updated: PostCSS Values Parser 2 (patch for this project)
|
|
12
|
-
|
|
13
|
-
### 2.0.0 (September 17, 2018)
|
|
14
|
-
|
|
15
|
-
- Updated: Support for PostCSS v7+
|
|
16
|
-
- Updated: Support for Node 6+
|
|
17
|
-
|
|
18
|
-
### 1.0.2 (July 13, 2018)
|
|
19
|
-
|
|
20
|
-
- Fixed: Poorly detected hsl() and rgb() now resolve correctly
|
|
21
|
-
|
|
22
|
-
### 1.0.1 (May 11, 2018)
|
|
23
|
-
|
|
24
|
-
- Fixed: A non-percentage 0 works alongside other percentages
|
|
25
|
-
|
|
26
|
-
### 1.0.0 (May 7, 2018)
|
|
27
|
-
|
|
28
|
-
- Initial version
|