postcss-double-position-gradients 3.0.0 → 3.0.4

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,31 @@
1
1
  # Changes to PostCSS Double Position Gradients
2
2
 
3
+ ### 3.0.4 (January 2, 2022)
4
+
5
+ - Removed Sourcemaps from package tarball.
6
+ - Moved CLI to CLI Package. See [announcement](https://github.com/csstools/postcss-plugins/discussions/121).
7
+
8
+ ### 3.0.3 (December 14, 2021)
9
+
10
+ - Fixed: infinite loop in complex gradients.
11
+
12
+ ### 3.0.2 (December 13, 2021)
13
+
14
+ - Changed: now uses `postcss-value-parser` for parsing.
15
+ - Updated: documentation
16
+
17
+ ### 3.0.1 (November 18, 2021)
18
+
19
+ - Added: Safeguards against postcss-values-parser potentially throwing an error.
20
+
21
+ - Fixed: Issue with some gradients creating an infinite loop.
22
+
23
+ - Updated: `postcss-value-parser` to 6.0.1 (patch)
24
+ - Updated: `eslint` to 8.2.0 (major)
25
+ - Updated: `postcss` to 8.3.11 (patch)
26
+
27
+ - Removed: yarn.lock is no longer version controlled
28
+
3
29
  ### 3.0.0 (September 17, 2021)
4
30
 
5
31
  - Updated: Support for PostCS 8+ (major).
package/README.md CHANGED
@@ -2,7 +2,6 @@
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://github.com/csstools/postcss-double-position-gradients/workflows/test/badge.svg" height="20">][cli-url]
6
5
  [<img alt="Support Chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]
7
6
 
8
7
  [PostCSS Double Position Gradients] lets you use double-position gradients in
@@ -94,10 +93,9 @@ postcssDoublePositionGradients({ preserve: false })
94
93
  ```
95
94
 
96
95
  [css-url]: https://cssdb.org/#double-position-gradients
97
- [cli-url]: https://github.com/csstools/postcss-double-position-gradients/actions/workflows/test.yml?query=workflow/test
98
96
  [git-url]: https://gitter.im/postcss/postcss
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";const e=require("postcss-value-parser"),t=/(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i,r=/^(repeating-)?(conic|linear|radial)-gradient$/i,n=e=>"div"===e.type&&","===e.value;function a(t){try{return!1!==e.unit(null==t?void 0:t.value)}catch(e){return!1}}module.exports=function(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&&a(o)&&a(t)){const r={type:l.type,value:l.value},a={type:"div",value:",",before:n(c)?c.before:"",after:n(c)?"":" "};!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,[a,r])}})),!1}));const s=c.toString();if(s!==i.value){if(o)return void i.cloneBefore({value:s});i.value=s}}}},module.exports.postcss=!0;
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ const e=require("postcss-value-parser"),t=/(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i,r=/^(repeating-)?(conic|linear|radial)-gradient$/i,n=e=>"div"===e.type&&","===e.value;function a(t){try{return!1!==e.unit(null==t?void 0:t.value)}catch(e){return!1}}module.exports=function(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&&a(o)&&a(t)){const r={type:l.type,value:l.value},a={type:"div",value:",",before:n(c)?c.before:"",after:n(c)?"":" "};!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,[a,r])}})),!1}));const s=c.toString();if(s!==i.value){if(o)return void i.cloneBefore({value:s});i.value=s}}}},module.exports.postcss=!0;
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
1
  {
2
2
  "name": "postcss-double-position-gradients",
3
- "version": "3.0.0",
3
+ "version": "3.0.4",
4
4
  "description": "Use double-position gradients in CSS",
5
5
  "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
6
  "license": "CC0-1.0",
7
- "repository": "csstools/postcss-double-position-gradients",
8
- "homepage": "https://github.com/csstools/postcss-double-position-gradients#readme",
9
- "bugs": "https://github.com/csstools/postcss-double-position-gradients/issues",
10
- "main": "index.js",
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
+ "files": [
12
+ "CHANGELOG.md",
13
+ "LICENSE.md",
14
+ "README.md",
15
+ "dist"
16
+ ],
11
17
  "scripts": {
12
- "prepublishOnly": "npm test",
13
- "lint": "eslint *.js --cache",
14
- "lint:fix": "eslint *.js --cache --fix",
15
- "test": "npm run lint && npm run tape",
16
- "tape": "postcss-tape"
18
+ "build": "rollup -c ../../rollup/default.js",
19
+ "clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"",
20
+ "lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
21
+ "prepublishOnly": "npm run clean && npm run build && npm run test",
22
+ "stryker": "stryker run --logLevel error",
23
+ "test": "postcss-tape --ci && npm run test:exports",
24
+ "test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
17
25
  },
18
26
  "engines": {
19
- "node": ">=12"
27
+ "node": "^12 || ^14 || >=16"
20
28
  },
21
29
  "dependencies": {
22
- "postcss-values-parser": "6.0.0"
23
- },
24
- "peerDependencies": {
25
- "postcss": "^8.3"
30
+ "postcss-value-parser": "^4.2.0"
26
31
  },
27
32
  "devDependencies": {
28
- "eslint": "7.32.0",
29
- "postcss": "8.3.6",
30
- "postcss-tape": "6.0.1"
33
+ "postcss": "^8.3.6",
34
+ "postcss-tape": "^6.0.1"
31
35
  },
32
- "eslintConfig": {
33
- "env": {
34
- "es6": true,
35
- "node": true
36
- },
37
- "extends": "eslint:recommended"
36
+ "peerDependencies": {
37
+ "postcss": "^8.3"
38
38
  },
39
39
  "keywords": [
40
40
  "postcss",
@@ -50,5 +50,13 @@
50
50
  "stop",
51
51
  "syntax",
52
52
  "repeating"
53
- ]
53
+ ],
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "https://github.com/csstools/postcss-plugins.git",
57
+ "directory": "plugins/postcss-double-position-gradients"
58
+ },
59
+ "volta": {
60
+ "extends": "../../package.json"
61
+ }
54
62
  }
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, 16]
11
- steps:
12
- - uses: actions/checkout@v2
13
- - uses: actions/setup-node@v2
14
- with:
15
- node-version: ${{ matrix.node }}
16
-
17
- - run: yarn install --ignore-scripts
18
- - run: yarn run test
package/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- node_modules
2
- package-lock.json
3
- yarn.lock
4
- *.log*
5
- *.result.css
6
- .*
7
- !.editorconfig
8
- !.gitattributes
9
- !.gitignore
10
- !.tape.js
11
- !.github
package/.tape.js DELETED
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- 'basic': {
3
- message: 'supports basic usage'
4
- },
5
- 'basic:preserve': {
6
- message: 'supports { preserve: false } usage',
7
- options: { preserve: false }
8
- }
9
- };
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,64 +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
- /**
9
- * Transform double-position gradients in CSS.
10
- * @param {{preserve?: boolean}} opts
11
- * @returns {import('postcss').Plugin}
12
- */
13
- module.exports = function creator(opts) {
14
- const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true;
15
-
16
- return {
17
- postcssPlugin: 'postcss-double-position-gradients',
18
- Declaration(decl) {
19
- if (!gradientRegExp.test(decl.value)) {
20
- return;
21
- }
22
-
23
- const valueAST = parse(decl.value, { ignoreUnknownWords: true });
24
-
25
- valueAST.walkFuncs((func) => {
26
- if (!gradientPartsRegExp.test(func.name)) {
27
- return;
28
- }
29
-
30
- func.walkNumerics((node, index) => {
31
- /** @type {import('postcss-values-parser').ChildNode} */
32
- const node1back = Object(func.nodes[index - 1]);
33
- /** @type {import('postcss-values-parser').ChildNode} */
34
- const node2back = Object(func.nodes[index - 2]);
35
- /** @type {import('postcss-values-parser').ChildNode} */
36
- const node1next = Object(func.nodes[index + 1]);
37
-
38
- // if the argument concludes a double-position gradient
39
- if (node2back.type && node1back.type === 'numeric') {
40
- // insert the fallback colors
41
- const color = node2back.clone();
42
- const comma = new Punctuation({
43
- value: ',',
44
- raws: node1next.type === 'punctuation' && node1next.value === ','
45
- ? Object.assign({}, node1next.clone().raws)
46
- : { before: '', after: '' }
47
- });
48
-
49
- func.insertBefore(node, [comma, color]);
50
- }
51
- })
52
- })
53
-
54
- const modifiedValue = String(valueAST);
55
-
56
- if (modifiedValue !== decl.value) {
57
- if (preserve) decl.cloneBefore({ value: modifiedValue });
58
- else decl.value = modifiedValue;
59
- }
60
- }
61
- }
62
- }
63
-
64
- module.exports.postcss = true;
package/test/basic.css DELETED
@@ -1,19 +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
- }
@@ -1,21 +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
- }
@@ -1,19 +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
- }