postcss-double-position-gradients 3.0.1 → 3.0.5
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 +18 -0
- package/README.md +4 -6
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +40 -25
- package/.editorconfig +0 -15
- package/.gitattributes +0 -1
- package/.github/workflows/test.yml +0 -18
- package/.gitignore +0 -11
- package/.tape.js +0 -9
- package/CONTRIBUTING.md +0 -65
- package/INSTALL.md +0 -170
- package/index.js +0 -81
- package/test/basic.css +0 -23
- package/test/basic.expect.css +0 -25
- package/test/basic.preserve.expect.css +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changes to PostCSS Double Position Gradients
|
|
2
2
|
|
|
3
|
+
### 3.0.5 (February 5, 2022)
|
|
4
|
+
|
|
5
|
+
- Improved `es module` and `commonjs` compatibility
|
|
6
|
+
|
|
7
|
+
### 3.0.4 (January 2, 2022)
|
|
8
|
+
|
|
9
|
+
- Removed Sourcemaps from package tarball.
|
|
10
|
+
- Moved CLI to CLI Package. See [announcement](https://github.com/csstools/postcss-plugins/discussions/121).
|
|
11
|
+
|
|
12
|
+
### 3.0.3 (December 14, 2021)
|
|
13
|
+
|
|
14
|
+
- Fixed: infinite loop in complex gradients.
|
|
15
|
+
|
|
16
|
+
### 3.0.2 (December 13, 2021)
|
|
17
|
+
|
|
18
|
+
- Changed: now uses `postcss-value-parser` for parsing.
|
|
19
|
+
- Updated: documentation
|
|
20
|
+
|
|
3
21
|
### 3.0.1 (November 18, 2021)
|
|
4
22
|
|
|
5
23
|
- Added: Safeguards against postcss-values-parser potentially throwing an error.
|
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# PostCSS Double Position Gradients [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]
|
|
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
|
-
[<img alt="CSS Standard Status" src="https://cssdb.org/
|
|
5
|
-
[<img alt="
|
|
6
|
-
[<img alt="Support Chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]
|
|
4
|
+
[<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/double-position-gradients.svg" height="20">][css-url]
|
|
5
|
+
[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|
7
6
|
|
|
8
7
|
[PostCSS Double Position Gradients] lets you use double-position gradients in
|
|
9
8
|
CSS, following the [CSS Image Values and Replaced Content] specification.
|
|
@@ -94,10 +93,9 @@ postcssDoublePositionGradients({ preserve: false })
|
|
|
94
93
|
```
|
|
95
94
|
|
|
96
95
|
[css-url]: https://cssdb.org/#double-position-gradients
|
|
97
|
-
[
|
|
98
|
-
[git-url]: https://gitter.im/postcss/postcss
|
|
96
|
+
[discord]: https://discord.gg/bUadyRwkJS
|
|
99
97
|
[npm-url]: https://www.npmjs.com/package/postcss-double-position-gradients
|
|
100
98
|
|
|
101
99
|
[CSS Image Values and Replaced Content]: https://www.w3.org/TR/css-images-4/#color-stop-syntax
|
|
102
100
|
[PostCSS]: https://github.com/postcss/postcss
|
|
103
|
-
[PostCSS Double Position Gradients]: https://github.com/csstools/postcss-double-position-gradients
|
|
101
|
+
[PostCSS Double Position Gradients]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-double-position-gradients
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=e(require("postcss-value-parser"));const r=/(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i,n=/^(repeating-)?(conic|linear|radial)-gradient$/i,a=e=>"div"===e.type&&","===e.value;function i(e){try{return!1!==t.default.unit(null==e?void 0:e.value)}catch(e){return!1}}function o(e){const o=!("preserve"in Object(e))||Boolean(e.preserve);return{postcssPlugin:"postcss-double-position-gradients",Declaration(e,{result:l}){if(!r.test(e.value))return;let u;try{u=t.default(e.value)}catch(t){e.warn(l,`Failed to parse value '${e.value}' as a CSS gradient. Leaving the original value intact.`)}if(void 0===u)return;u.walk((e=>{if("function"!==e.type||!n.test(e.value))return;return e.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type)).forEach(((t,r,n)=>{const o=Object(n[r-1]),l=Object(n[r-2]),u=Object(n[r+1]);if(l.type&&i(o)&&i(t)){const r={type:l.type,value:l.value},n={type:"div",value:",",before:a(u)?u.before:"",after:a(u)?"":" "};!function(e,t,...r){const n=e.findIndex((e=>e===t));e.splice.apply(e,[n-1,0].concat(Array.prototype.slice.call(...r,0)))}(e.nodes,t,[n,r])}})),!1}));const c=u.toString();if(c!==e.value){if(o)return void e.cloneBefore({value:c});e.value=c}}}}o.postcss=!0,module.exports=o;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"postcss-value-parser";const t=/(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i,r=/^(repeating-)?(conic|linear|radial)-gradient$/i,a=e=>"div"===e.type&&","===e.value;function n(t){try{return!1!==e.unit(null==t?void 0:t.value)}catch(e){return!1}}function i(i){const o=!("preserve"in Object(i))||Boolean(i.preserve);return{postcssPlugin:"postcss-double-position-gradients",Declaration(i,{result:l}){if(!t.test(i.value))return;let c;try{c=e(i.value)}catch(e){i.warn(l,`Failed to parse value '${i.value}' as a CSS gradient. Leaving the original value intact.`)}if(void 0===c)return;c.walk((e=>{if("function"!==e.type||!r.test(e.value))return;return e.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type)).forEach(((t,r,i)=>{const o=Object(i[r-1]),l=Object(i[r-2]),c=Object(i[r+1]);if(l.type&&n(o)&&n(t)){const r={type:l.type,value:l.value},n={type:"div",value:",",before:a(c)?c.before:"",after:a(c)?"":" "};!function(e,t,...r){const a=e.findIndex((e=>e===t));e.splice.apply(e,[a-1,0].concat(Array.prototype.slice.call(...r,0)))}(e.nodes,t,[n,r])}})),!1}));const s=c.toString();if(s!==i.value){if(o)return void i.cloneBefore({value:s});i.value=s}}}}i.postcss=!0;export{i as default};
|
package/package.json
CHANGED
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-double-position-gradients",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "Use double-position gradients in CSS",
|
|
5
5
|
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
|
|
6
6
|
"license": "CC0-1.0",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
7
|
+
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-double-position-gradients#readme",
|
|
8
|
+
"bugs": "https://github.com/csstools/postcss-plugins/issues",
|
|
9
|
+
"main": "dist/index.cjs",
|
|
10
|
+
"module": "dist/index.mjs",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"default": "./dist/index.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"LICENSE.md",
|
|
21
|
+
"README.md",
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
11
24
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"lint
|
|
15
|
-
"
|
|
16
|
-
"
|
|
25
|
+
"build": "rollup -c ../../rollup/default.js",
|
|
26
|
+
"clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
|
|
27
|
+
"lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
|
|
28
|
+
"prepublishOnly": "npm run clean && npm run build && npm run test",
|
|
29
|
+
"stryker": "stryker run --logLevel error",
|
|
30
|
+
"test": "postcss-tape --ci && npm run test:exports",
|
|
31
|
+
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
|
|
17
32
|
},
|
|
18
33
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
34
|
+
"node": "^12 || ^14 || >=16"
|
|
20
35
|
},
|
|
21
36
|
"dependencies": {
|
|
22
|
-
"postcss-
|
|
23
|
-
},
|
|
24
|
-
"peerDependencies": {
|
|
25
|
-
"postcss": "^8.3"
|
|
37
|
+
"postcss-value-parser": "^4.2.0"
|
|
26
38
|
},
|
|
27
39
|
"devDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"postcss": "
|
|
30
|
-
"postcss-tape": "6.0.1"
|
|
40
|
+
"postcss": "^8.3.6",
|
|
41
|
+
"postcss-tape": "^6.0.1"
|
|
31
42
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"es6": true,
|
|
35
|
-
"node": true
|
|
36
|
-
},
|
|
37
|
-
"extends": "eslint:recommended"
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"postcss": "^8.4"
|
|
38
45
|
},
|
|
39
46
|
"keywords": [
|
|
40
47
|
"postcss",
|
|
@@ -50,5 +57,13 @@
|
|
|
50
57
|
"stop",
|
|
51
58
|
"syntax",
|
|
52
59
|
"repeating"
|
|
53
|
-
]
|
|
60
|
+
],
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "https://github.com/csstools/postcss-plugins.git",
|
|
64
|
+
"directory": "plugins/postcss-double-position-gradients"
|
|
65
|
+
},
|
|
66
|
+
"volta": {
|
|
67
|
+
"extends": "../../package.json"
|
|
68
|
+
}
|
|
54
69
|
}
|
package/.editorconfig
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
charset = utf-8
|
|
5
|
-
end_of_line = lf
|
|
6
|
-
indent_style = tab
|
|
7
|
-
insert_final_newline = true
|
|
8
|
-
trim_trailing_whitespace = true
|
|
9
|
-
|
|
10
|
-
[*.md]
|
|
11
|
-
trim_trailing_whitespace = false
|
|
12
|
-
|
|
13
|
-
[*.{json,md,yml}]
|
|
14
|
-
indent_size = 2
|
|
15
|
-
indent_style = space
|
package/.gitattributes
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
* text=auto eol=lf
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
name: test
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
test:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
strategy:
|
|
9
|
-
matrix:
|
|
10
|
-
node: [12, 14, 16]
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v2
|
|
13
|
-
- uses: actions/setup-node@v2
|
|
14
|
-
with:
|
|
15
|
-
node-version: ${{ matrix.node }}
|
|
16
|
-
|
|
17
|
-
- run: npm install --ignore-scripts
|
|
18
|
-
- run: npm run test
|
package/.gitignore
DELETED
package/.tape.js
DELETED
package/CONTRIBUTING.md
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# Contributing to PostCSS Double Position Gradients
|
|
2
|
-
|
|
3
|
-
You want to help? You rock! Now, take a moment to be sure your contributions
|
|
4
|
-
make sense to everyone else.
|
|
5
|
-
|
|
6
|
-
## Reporting Issues
|
|
7
|
-
|
|
8
|
-
Found a problem? Want a new feature?
|
|
9
|
-
|
|
10
|
-
- See if your issue or idea has [already been reported].
|
|
11
|
-
- Provide a [reduced test case] or a [live example].
|
|
12
|
-
|
|
13
|
-
Remember, a bug is a _demonstrable problem_ caused by _our_ code.
|
|
14
|
-
|
|
15
|
-
## Submitting Pull Requests
|
|
16
|
-
|
|
17
|
-
Pull requests are the greatest contributions, so be sure they are focused in
|
|
18
|
-
scope and avoid unrelated commits.
|
|
19
|
-
|
|
20
|
-
1. To begin; [fork this project], clone your fork, and add our upstream.
|
|
21
|
-
```bash
|
|
22
|
-
# Clone your fork of the repo into the current directory
|
|
23
|
-
git clone git@github.com:YOUR_USER/postcss-double-position-gradients.git
|
|
24
|
-
|
|
25
|
-
# Navigate to the newly cloned directory
|
|
26
|
-
cd postcss-double-position-gradients
|
|
27
|
-
|
|
28
|
-
# Assign the original repo to a remote called "upstream"
|
|
29
|
-
git remote add upstream git@github.com:csstools/postcss-double-position-gradients.git
|
|
30
|
-
|
|
31
|
-
# Install the tools necessary for testing
|
|
32
|
-
npm install
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
2. Create a branch for your feature or fix:
|
|
36
|
-
```bash
|
|
37
|
-
# Move into a new branch for your feature
|
|
38
|
-
git checkout -b feature/thing
|
|
39
|
-
```
|
|
40
|
-
```bash
|
|
41
|
-
# Move into a new branch for your fix
|
|
42
|
-
git checkout -b fix/something
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
3. If your code follows our practices, then push your feature branch:
|
|
46
|
-
```bash
|
|
47
|
-
# Test current code
|
|
48
|
-
npm test
|
|
49
|
-
```
|
|
50
|
-
```bash
|
|
51
|
-
# Push the branch for your new feature
|
|
52
|
-
git push origin feature/thing
|
|
53
|
-
```
|
|
54
|
-
```bash
|
|
55
|
-
# Or, push the branch for your update
|
|
56
|
-
git push origin update/something
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
That’s it! Now [open a pull request] with a clear title and description.
|
|
60
|
-
|
|
61
|
-
[already been reported]: issues
|
|
62
|
-
[fork this project]: fork
|
|
63
|
-
[live example]: https://codepen.io/pen
|
|
64
|
-
[open a pull request]: https://help.github.com/articles/using-pull-requests/
|
|
65
|
-
[reduced test case]: https://css-tricks.com/reduced-test-cases/
|
package/INSTALL.md
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
# Installing PostCSS Double Position Gradients
|
|
2
|
-
|
|
3
|
-
[PostCSS Double Position Gradients] runs in all Node environments, with special instructions for:
|
|
4
|
-
|
|
5
|
-
| [Node](#node) | [PostCSS CLI](#postcss-cli) | [Webpack](#webpack) | [Create React App](#create-react-app) | [Gulp](#gulp) | [Grunt](#grunt) |
|
|
6
|
-
| --- | --- | --- | --- | --- | --- |
|
|
7
|
-
|
|
8
|
-
## Node
|
|
9
|
-
|
|
10
|
-
Add [PostCSS Double Position Gradients] to your project:
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
npm install postcss-double-position-gradients --save-dev
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Use [PostCSS Double Position Gradients] to process your CSS:
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|
20
|
-
|
|
21
|
-
postcssDoublePositionGradients.process(YOUR_CSS /*, processOptions, pluginOptions */);
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Or use it as a [PostCSS] plugin:
|
|
25
|
-
|
|
26
|
-
```js
|
|
27
|
-
const postcss = require('postcss');
|
|
28
|
-
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|
29
|
-
|
|
30
|
-
postcss([
|
|
31
|
-
postcssDoublePositionGradients(/* pluginOptions */)
|
|
32
|
-
]).process(YOUR_CSS /*, processOptions */);
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## PostCSS CLI
|
|
36
|
-
|
|
37
|
-
Add [PostCSS CLI] to your project:
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
npm install postcss-cli --save-dev
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Use [PostCSS Double Position Gradients] in your `postcss.config.js` configuration file:
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|
47
|
-
|
|
48
|
-
module.exports = {
|
|
49
|
-
plugins: [
|
|
50
|
-
postcssDoublePositionGradients(/* pluginOptions */)
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Webpack
|
|
56
|
-
|
|
57
|
-
Add [PostCSS Loader] to your project:
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npm install postcss-loader --save-dev
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Use [PostCSS Double Position Gradients] in your Webpack configuration:
|
|
64
|
-
|
|
65
|
-
```js
|
|
66
|
-
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|
67
|
-
|
|
68
|
-
module.exports = {
|
|
69
|
-
module: {
|
|
70
|
-
rules: [
|
|
71
|
-
{
|
|
72
|
-
test: /\.css$/,
|
|
73
|
-
use: [
|
|
74
|
-
'style-loader',
|
|
75
|
-
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
|
76
|
-
{ loader: 'postcss-loader', options: {
|
|
77
|
-
ident: 'postcss',
|
|
78
|
-
plugins: () => [
|
|
79
|
-
postcssDoublePositionGradients(/* pluginOptions */)
|
|
80
|
-
]
|
|
81
|
-
} }
|
|
82
|
-
]
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Create React App
|
|
90
|
-
|
|
91
|
-
Add [React App Rewired] and [React App Rewire PostCSS] to your project:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
npm install react-app-rewired react-app-rewire-postcss --save-dev
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Use [React App Rewire PostCSS] and [PostCSS Double Position Gradients] in your
|
|
98
|
-
`config-overrides.js` file:
|
|
99
|
-
|
|
100
|
-
```js
|
|
101
|
-
const reactAppRewirePostcss = require('react-app-rewire-postcss');
|
|
102
|
-
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|
103
|
-
|
|
104
|
-
module.exports = config => reactAppRewirePostcss(config, {
|
|
105
|
-
plugins: () => [
|
|
106
|
-
postcssDoublePositionGradients(/* pluginOptions */)
|
|
107
|
-
]
|
|
108
|
-
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Gulp
|
|
112
|
-
|
|
113
|
-
Add [Gulp PostCSS] to your project:
|
|
114
|
-
|
|
115
|
-
```bash
|
|
116
|
-
npm install gulp-postcss --save-dev
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
Use [PostCSS Double Position Gradients] in your Gulpfile:
|
|
120
|
-
|
|
121
|
-
```js
|
|
122
|
-
const postcss = require('gulp-postcss');
|
|
123
|
-
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|
124
|
-
|
|
125
|
-
gulp.task('css', () => gulp.src('./src/*.css').pipe(
|
|
126
|
-
postcss([
|
|
127
|
-
postcssDoublePositionGradients(/* pluginOptions */)
|
|
128
|
-
])
|
|
129
|
-
).pipe(
|
|
130
|
-
gulp.dest('.')
|
|
131
|
-
));
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## Grunt
|
|
135
|
-
|
|
136
|
-
Add [Grunt PostCSS] to your project:
|
|
137
|
-
|
|
138
|
-
```bash
|
|
139
|
-
npm install grunt-postcss --save-dev
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Use [PostCSS Double Position Gradients] in your Gruntfile:
|
|
143
|
-
|
|
144
|
-
```js
|
|
145
|
-
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
|
|
146
|
-
|
|
147
|
-
grunt.loadNpmTasks('grunt-postcss');
|
|
148
|
-
|
|
149
|
-
grunt.initConfig({
|
|
150
|
-
postcss: {
|
|
151
|
-
options: {
|
|
152
|
-
use: [
|
|
153
|
-
postcssDoublePositionGradients(/* pluginOptions */)
|
|
154
|
-
]
|
|
155
|
-
},
|
|
156
|
-
dist: {
|
|
157
|
-
src: '*.css'
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|
164
|
-
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|
165
|
-
[PostCSS]: https://github.com/postcss/postcss
|
|
166
|
-
[PostCSS CLI]: https://github.com/postcss/postcss-cli
|
|
167
|
-
[PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|
168
|
-
[PostCSS Double Position Gradients]: https://github.com/csstools/postcss-double-position-gradients
|
|
169
|
-
[React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
|
|
170
|
-
[React App Rewired]: https://github.com/timarney/react-app-rewired
|
package/index.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
const { parse } = require('postcss-values-parser');
|
|
2
|
-
const Punctuation = require('postcss-values-parser/lib/nodes/Punctuation');
|
|
3
|
-
|
|
4
|
-
// whether the value has a lab() or lch() matcher
|
|
5
|
-
const gradientRegExp = /(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i;
|
|
6
|
-
const gradientPartsRegExp = /^(repeating-)?(conic|linear|radial)-gradient$/i;
|
|
7
|
-
|
|
8
|
-
const isPunctuationCommaNode = node => node.type === 'punctuation' && node.value === ','
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Transform double-position gradients in CSS.
|
|
12
|
-
* @param {{preserve?: boolean}} opts
|
|
13
|
-
* @returns {import('postcss').Plugin}
|
|
14
|
-
*/
|
|
15
|
-
module.exports = function creator(opts) {
|
|
16
|
-
const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
postcssPlugin: 'postcss-double-position-gradients',
|
|
20
|
-
Declaration(decl, { result }) {
|
|
21
|
-
if (!gradientRegExp.test(decl.value)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
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
|
-
}
|
|
40
|
-
|
|
41
|
-
valueAST.walkFuncs((func) => {
|
|
42
|
-
if (!gradientPartsRegExp.test(func.name)) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
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';
|
|
54
|
-
|
|
55
|
-
// if the argument concludes a double-position gradient
|
|
56
|
-
if (isDoublePositionLength) {
|
|
57
|
-
// insert the fallback colors
|
|
58
|
-
const color = node2back.clone();
|
|
59
|
-
const comma = new Punctuation({
|
|
60
|
-
value: ',',
|
|
61
|
-
raws: isPunctuationCommaNode(node1next)
|
|
62
|
-
? Object.assign({}, node1next.clone().raws)
|
|
63
|
-
: { before: '', after: '' }
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
func.insertBefore(node, [comma, color]);
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const modifiedValue = String(valueAST);
|
|
72
|
-
|
|
73
|
-
if (modifiedValue !== decl.value) {
|
|
74
|
-
if (preserve) decl.cloneBefore({ value: modifiedValue });
|
|
75
|
-
else decl.value = modifiedValue;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
module.exports.postcss = true;
|
package/test/basic.css
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
.test-linear-gradient {
|
|
2
|
-
background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.test-conic-gradient {
|
|
6
|
-
background-image: conic-gradient(yellowgreen 40%, gold 0deg 75% , #f06 0deg);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.test-invalid-function {
|
|
10
|
-
background-image: some-func(yellowgreen 40%, gold 0deg 75% , #f06 0deg);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.test-linear-gradient-ignored {
|
|
14
|
-
background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.test-conic-gradient-ignored {
|
|
18
|
-
background-image: conic-gradient(yellowgreen 40%, gold 0deg , gold 75% , #f06 0deg);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.test-linear-gradient-loop {
|
|
22
|
-
background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 25%, transparent);
|
|
23
|
-
}
|
package/test/basic.expect.css
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
.test-linear-gradient {
|
|
2
|
-
background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
|
|
3
|
-
background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
.test-conic-gradient {
|
|
7
|
-
background-image: conic-gradient(yellowgreen 40%, gold 0deg , gold 75% , #f06 0deg);
|
|
8
|
-
background-image: conic-gradient(yellowgreen 40%, gold 0deg 75% , #f06 0deg);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.test-invalid-function {
|
|
12
|
-
background-image: some-func(yellowgreen 40%, gold 0deg 75% , #f06 0deg);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.test-linear-gradient-ignored {
|
|
16
|
-
background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.test-conic-gradient-ignored {
|
|
20
|
-
background-image: conic-gradient(yellowgreen 40%, gold 0deg , gold 75% , #f06 0deg);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.test-linear-gradient-loop {
|
|
24
|
-
background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 25%, transparent);
|
|
25
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
.test-linear-gradient {
|
|
2
|
-
background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.test-conic-gradient {
|
|
6
|
-
background-image: conic-gradient(yellowgreen 40%, gold 0deg , gold 75% , #f06 0deg);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.test-invalid-function {
|
|
10
|
-
background-image: some-func(yellowgreen 40%, gold 0deg 75% , #f06 0deg);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.test-linear-gradient-ignored {
|
|
14
|
-
background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.test-conic-gradient-ignored {
|
|
18
|
-
background-image: conic-gradient(yellowgreen 40%, gold 0deg , gold 75% , #f06 0deg);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.test-linear-gradient-loop {
|
|
22
|
-
background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 25%, transparent);
|
|
23
|
-
}
|