postcss-double-position-gradients 3.0.0 → 3.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/.github/workflows/test.yml +3 -3
- package/.gitignore +1 -1
- package/CHANGELOG.md +12 -0
- package/README.md +2 -2
- package/index.js +30 -13
- package/package.json +4 -4
- package/test/basic.css +4 -0
- package/test/basic.expect.css +4 -0
- package/test/basic.preserve.expect.css +4 -0
|
@@ -7,12 +7,12 @@ jobs:
|
|
|
7
7
|
runs-on: ubuntu-latest
|
|
8
8
|
strategy:
|
|
9
9
|
matrix:
|
|
10
|
-
node: [12, 16]
|
|
10
|
+
node: [12, 14, 16]
|
|
11
11
|
steps:
|
|
12
12
|
- uses: actions/checkout@v2
|
|
13
13
|
- uses: actions/setup-node@v2
|
|
14
14
|
with:
|
|
15
15
|
node-version: ${{ matrix.node }}
|
|
16
16
|
|
|
17
|
-
- run:
|
|
18
|
-
- run:
|
|
17
|
+
- run: npm install --ignore-scripts
|
|
18
|
+
- run: npm run test
|
package/.gitignore
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changes to PostCSS Double Position Gradients
|
|
2
2
|
|
|
3
|
+
### 3.0.1 (November 18, 2021)
|
|
4
|
+
|
|
5
|
+
- Added: Safeguards against postcss-values-parser potentially throwing an error.
|
|
6
|
+
|
|
7
|
+
- Fixed: Issue with some gradients creating an infinite loop.
|
|
8
|
+
|
|
9
|
+
- Updated: `postcss-value-parser` to 6.0.1 (patch)
|
|
10
|
+
- Updated: `eslint` to 8.2.0 (major)
|
|
11
|
+
- Updated: `postcss` to 8.3.11 (patch)
|
|
12
|
+
|
|
13
|
+
- Removed: yarn.lock is no longer version controlled
|
|
14
|
+
|
|
3
15
|
### 3.0.0 (September 17, 2021)
|
|
4
16
|
|
|
5
17
|
- Updated: Support for PostCS 8+ (major).
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[<img alt="NPM Version" src="https://img.shields.io/npm/v/postcss-double-position-gradients.svg" height="20">][npm-url]
|
|
4
4
|
[<img alt="CSS Standard Status" src="https://cssdb.org/badge/double-position-gradients.svg" height="20">][css-url]
|
|
5
|
-
[<img alt="Build Status" src="https://
|
|
5
|
+
[<img alt="Build Status" src="https://img.shields.io/travis/csstools/postcss-double-position-gradients/master.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 Double Position Gradients] lets you use double-position gradients in
|
|
@@ -94,7 +94,7 @@ postcssDoublePositionGradients({ preserve: false })
|
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
[css-url]: https://cssdb.org/#double-position-gradients
|
|
97
|
-
[cli-url]: https://
|
|
97
|
+
[cli-url]: https://travis-ci.org/csstools/postcss-double-position-gradients
|
|
98
98
|
[git-url]: https://gitter.im/postcss/postcss
|
|
99
99
|
[npm-url]: https://www.npmjs.com/package/postcss-double-position-gradients
|
|
100
100
|
|
package/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
const {parse} = require(
|
|
2
|
-
const Punctuation = require(
|
|
1
|
+
const { parse } = require('postcss-values-parser');
|
|
2
|
+
const Punctuation = require('postcss-values-parser/lib/nodes/Punctuation');
|
|
3
3
|
|
|
4
4
|
// whether the value has a lab() or lch() matcher
|
|
5
5
|
const gradientRegExp = /(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i;
|
|
6
6
|
const gradientPartsRegExp = /^(repeating-)?(conic|linear|radial)-gradient$/i;
|
|
7
7
|
|
|
8
|
+
const isPunctuationCommaNode = node => node.type === 'punctuation' && node.value === ','
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Transform double-position gradients in CSS.
|
|
10
12
|
* @param {{preserve?: boolean}} opts
|
|
@@ -15,33 +17,48 @@ module.exports = function creator(opts) {
|
|
|
15
17
|
|
|
16
18
|
return {
|
|
17
19
|
postcssPlugin: 'postcss-double-position-gradients',
|
|
18
|
-
Declaration(decl) {
|
|
20
|
+
Declaration(decl, { result }) {
|
|
19
21
|
if (!gradientRegExp.test(decl.value)) {
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
let valueAST;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
valueAST = parse(decl.value, { ignoreUnknownWords: true });
|
|
29
|
+
} catch (error) {
|
|
30
|
+
decl.warn(
|
|
31
|
+
result,
|
|
32
|
+
`Failed to parse value '${decl.value}' as a CSS gradient. Leaving the original value intact.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof valueAST === 'undefined') {
|
|
37
|
+
// Bail if there's an error
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
24
40
|
|
|
25
41
|
valueAST.walkFuncs((func) => {
|
|
26
42
|
if (!gradientPartsRegExp.test(func.name)) {
|
|
27
43
|
return;
|
|
28
44
|
}
|
|
29
45
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const node2back = Object(
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
const nodes = func.nodes;
|
|
47
|
+
|
|
48
|
+
nodes.slice(0).forEach((node, index, nodes) => {
|
|
49
|
+
const node1back = Object(nodes[index - 1]);
|
|
50
|
+
const node2back = Object(nodes[index - 2]);
|
|
51
|
+
const node1next = Object(nodes[index + 1]);
|
|
52
|
+
|
|
53
|
+
const isDoublePositionLength = node2back.type && node1back.type === 'numeric' && node.type === 'numeric';
|
|
37
54
|
|
|
38
55
|
// if the argument concludes a double-position gradient
|
|
39
|
-
if (
|
|
56
|
+
if (isDoublePositionLength) {
|
|
40
57
|
// insert the fallback colors
|
|
41
58
|
const color = node2back.clone();
|
|
42
59
|
const comma = new Punctuation({
|
|
43
60
|
value: ',',
|
|
44
|
-
raws: node1next
|
|
61
|
+
raws: isPunctuationCommaNode(node1next)
|
|
45
62
|
? Object.assign({}, node1next.clone().raws)
|
|
46
63
|
: { before: '', after: '' }
|
|
47
64
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-double-position-gradients",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Use double-position gradients in CSS",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "CC0-1.0",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"node": ">=12"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"postcss-values-parser": "6.0.
|
|
22
|
+
"postcss-values-parser": "6.0.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"postcss": "^8.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"eslint": "
|
|
29
|
-
"postcss": "8.3.
|
|
28
|
+
"eslint": "8.2.0",
|
|
29
|
+
"postcss": "8.3.11",
|
|
30
30
|
"postcss-tape": "6.0.1"
|
|
31
31
|
},
|
|
32
32
|
"eslintConfig": {
|
package/test/basic.css
CHANGED
package/test/basic.expect.css
CHANGED