Skip to content

Commit 8b29263

Browse files
jonathantnealromainmenke
authored andcommitted
2.0.0
1 parent 70db2c0 commit 8b29263

18 files changed

+181
-126
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

plugins/postcss-double-position-gradients/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
dist
12
node_modules
2-
index.*.*
33
package-lock.json
44
*.log*
55
*.result.css
66
.*
77
!.editorconfig
8+
!.gitattributes
89
!.gitignore
910
!.rollup.js
1011
!.tape.js
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import babel from 'rollup-plugin-babel';
1+
import pkg from './package.json'
22

33
export default {
4-
input: 'index.js',
5-
output: [
6-
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true },
7-
{ file: 'index.es.mjs', format: 'es', sourcemap: true }
8-
],
9-
plugins: [
10-
babel({
11-
presets: [
12-
['@babel/env', { modules: false, targets: { node: 6 } }]
13-
]
14-
})
15-
]
16-
};
4+
...pkg.rollup,
5+
plugins: pkg.rollup.plugins.map(plugin => require(plugin)()),
6+
onwarn(warning, warn) {
7+
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning)
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
module.exports = {
2-
'postcss-double-position-gradients': {
3-
'basic': {
4-
message: 'supports basic usage'
5-
},
6-
'basic:preserve': {
7-
message: 'supports { preserve: false } usage',
8-
options: { preserve: false }
9-
}
2+
'basic': {
3+
message: 'supports basic usage'
4+
},
5+
'basic:preserve': {
6+
message: 'supports { preserve: false } usage',
7+
options: { preserve: false }
108
}
119
};

plugins/postcss-double-position-gradients/.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
language: node_js
44

55
node_js:
6-
- 6
6+
- 10
77

88
install:
99
- npm install --ignore-scripts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes to PostCSS Double Position Gradients
22

3+
### 2.0.0 (April 25, 2020)
4+
5+
- Updated: `postcss` to 7.0.27 (patch)
6+
- Updated: `postcss-value-parser` to 3.2.1 (major)
7+
- Updated: Support for Node 10+ (major)
8+
39
### 1.0.0 (October 28, 2018)
410

511
- Initial version

plugins/postcss-double-position-gradients/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ scope and avoid unrelated commits.
2626
cd postcss-double-position-gradients
2727

2828
# Assign the original repo to a remote called "upstream"
29-
git remote add upstream git@github.com:jonathantneal/postcss-double-position-gradients.git
29+
git remote add upstream git@github.com:csstools/postcss-double-position-gradients.git
3030

3131
# Install the tools necessary for testing
3232
npm install

plugins/postcss-double-position-gradients/INSTALL.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,6 @@ grunt.initConfig({
165165
[PostCSS]: https://github.com/postcss/postcss
166166
[PostCSS CLI]: https://github.com/postcss/postcss-cli
167167
[PostCSS Loader]: https://github.com/postcss/postcss-loader
168-
[PostCSS Double Position Gradients]: https://github.com/jonathantneal/postcss-double-position-gradients
168+
[PostCSS Double Position Gradients]: https://github.com/csstools/postcss-double-position-gradients
169169
[React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
170170
[React App Rewired]: https://github.com/timarney/react-app-rewired

plugins/postcss-double-position-gradients/README.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# PostCSS Double Position Gradients [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]
22

3-
[![NPM Version][npm-img]][npm-url]
4-
[![Build Status][cli-img]][cli-url]
5-
[![Support Chat][git-img]][git-url]
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/badge/double-position-gradients.svg" height="20">][css-url]
5+
[<img alt="Build Status" src="https://img.shields.io/travis/csstools/postcss-double-position-gradients/master.svg" height="20">][cli-url]
6+
[<img alt="Support Chat" src="https://img.shields.io/badge/support-chat-blue.svg" height="20">][git-url]
67

78
[PostCSS Double Position Gradients] lets you use double-position gradients in
89
CSS, following the [CSS Image Values and Replaced Content] specification.
@@ -92,13 +93,11 @@ postcssDoublePositionGradients({ preserve: false })
9293
}
9394
```
9495

95-
[cli-img]: https://img.shields.io/travis/jonathantneal/postcss-double-position-gradients/master.svg
96-
[cli-url]: https://travis-ci.org/jonathantneal/postcss-double-position-gradients
97-
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
96+
[css-url]: https://cssdb.org/#double-position-gradients
97+
[cli-url]: https://travis-ci.org/csstools/postcss-double-position-gradients
9898
[git-url]: https://gitter.im/postcss/postcss
99-
[npm-img]: https://img.shields.io/npm/v/postcss-double-position-gradients.svg
10099
[npm-url]: https://www.npmjs.com/package/postcss-double-position-gradients
101100

102101
[CSS Image Values and Replaced Content]: https://www.w3.org/TR/css-images-4/#color-stop-syntax
103102
[PostCSS]: https://github.com/postcss/postcss
104-
[PostCSS Double Position Gradients]: https://github.com/jonathantneal/postcss-double-position-gradients
103+
[PostCSS Double Position Gradients]: https://github.com/csstools/postcss-double-position-gradients

plugins/postcss-double-position-gradients/index.js

-60
This file was deleted.

plugins/postcss-double-position-gradients/package.json

+56-28
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,78 @@
11
{
22
"name": "postcss-double-position-gradients",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "Use double-position gradients in CSS",
55
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
66
"license": "CC0-1.0",
7-
"repository": "jonathantneal/postcss-double-position-gradients",
8-
"homepage": "https://github.com/jonathantneal/postcss-double-position-gradients#readme",
9-
"bugs": "https://github.com/jonathantneal/postcss-double-position-gradients/issues",
10-
"main": "index.cjs.js",
11-
"module": "index.es.mjs",
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": "dist/index.js",
11+
"module": "dist/index.mjs",
1212
"files": [
13-
"index.cjs.js",
14-
"index.cjs.js.map",
15-
"index.es.mjs",
16-
"index.es.mjs.map"
13+
"dist"
1714
],
1815
"scripts": {
19-
"prepublishOnly": "npm test",
20-
"pretest": "rollup -c .rollup.js --silent",
21-
"test": "npm run test:js && npm run test:tape",
22-
"test:js": "eslint *.js --cache --ignore-path .gitignore --quiet",
23-
"test:tape": "postcss-tape"
16+
"build": "npx rollup -c .rollup.js",
17+
"build:watch": "npx rollup -c .rollup.js --watch",
18+
"lint": "npx eslint --cache src",
19+
"lint:fix": "npx eslint --cache --fix",
20+
"pretest": "npm install && npm run build",
21+
"test": "npm run lint && npm run tape",
22+
"tape": "npx postcss-tape",
23+
"prepublishOnly": "npm test"
2424
},
2525
"engines": {
26-
"node": ">=6.0.0"
26+
"node": ">=10.0.0"
2727
},
2828
"dependencies": {
29-
"postcss": "^7.0.5",
30-
"postcss-values-parser": "^2.0.0"
29+
"postcss": "^7.0.27",
30+
"postcss-values-parser": "^3.2.1"
3131
},
3232
"devDependencies": {
33-
"@babel/core": "^7.1.2",
34-
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
35-
"@babel/preset-env": "^7.1.0",
36-
"babel-eslint": "^10.0.1",
37-
"eslint": "^5.8.0",
38-
"eslint-config-dev": "^2.0.0",
39-
"postcss-tape": "^2.2.0",
33+
"@babel/core": "^7.9.0",
34+
"@babel/preset-env": "^7.9.5",
35+
"babel-eslint": "^10.1.0",
36+
"eslint": "^6.8.0",
37+
"postcss-tape": "^5.0.2",
4038
"pre-commit": "^1.2.2",
41-
"rollup": "^0.66.6",
42-
"rollup-plugin-babel": "^4.0.3"
39+
"rollup": "^2.7.2",
40+
"rollup-plugin-babel": "^4.4.0"
41+
},
42+
"babel": {
43+
"presets": [
44+
[
45+
"@babel/env",
46+
{
47+
"targets": "maintained node versions"
48+
}
49+
]
50+
]
4351
},
4452
"eslintConfig": {
45-
"extends": "dev",
53+
"env": {
54+
"es6": true,
55+
"node": true
56+
},
57+
"extends": "eslint:recommended",
4658
"parser": "babel-eslint"
4759
},
60+
"rollup": {
61+
"input": "src/index.js",
62+
"plugins": [
63+
"rollup-plugin-babel"
64+
],
65+
"output": [
66+
{
67+
"file": "dist/index.js",
68+
"format": "cjs"
69+
},
70+
{
71+
"file": "dist/index.mjs",
72+
"format": "esm"
73+
}
74+
]
75+
},
4876
"keywords": [
4977
"postcss",
5078
"css",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import postcss from 'postcss'
2+
import onCSSDeclaration from './onCSSDeclaration'
3+
import options from './options'
4+
5+
/** Transform double-position gradients in CSS. */
6+
const postcssPlugin = postcss.plugin('postcss-double-position-gradients', /** @type {PostCSSPluginInitializer} */ opts => {
7+
if ('preserve' in Object(opts)) options.preserve = Boolean(opts.preserve)
8+
9+
return root => {
10+
root.walkDecls(onCSSDeclaration)
11+
}
12+
})
13+
14+
export default postcssPlugin
15+
16+
/** @typedef {import('postcss').Root} CSSRoot */
17+
/** @typedef {(root: CSSRoot) => void} PostCSSTransformCallback */
18+
/** @typedef {(opts: options) => PostCSSTransformCallback} PostCSSPluginInitializer */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { parse } from 'postcss-values-parser'
2+
import onCSSFunction from './onCSSFunction'
3+
import options from './options'
4+
5+
/** @type {(decl: CSSDeclaration) => void} Transform double-position gradients in CSS Declarations. */
6+
const onCSSDeclaration = decl => {
7+
const { value: originalValue } = decl
8+
9+
if (hasGradientFunction(originalValue)) {
10+
const valueAST = parse(originalValue, { ignoreUnknownWords: true })
11+
12+
valueAST.walkType('func', onCSSFunction)
13+
14+
const modifiedValue = String(valueAST)
15+
16+
if (modifiedValue !== originalValue) {
17+
if (options.preserve) decl.cloneBefore({ value: modifiedValue })
18+
else decl.value = modifiedValue
19+
}
20+
}
21+
}
22+
23+
export default onCSSDeclaration
24+
25+
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
26+
const createRegExpTest = Function.bind.bind(RegExp.prototype.test)
27+
28+
/** Return whether the value has a lab() or lch() function. */
29+
const hasGradientFunction = createRegExpTest(/(repeating-)?(conic|linear|radial)-gradient\([\W\w]*\)/i)
30+
31+
/** @typedef {import('postcss').Declaration} CSSDeclaration */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Punctuation from 'postcss-values-parser/lib/nodes/Punctuation';
2+
3+
/** @type {(decl: CSSFunction) => void} Transform lab() and lch() functions. */
4+
const onCSSFunction = func => {
5+
/** @type {{ name: string, nodes: CSSNode[] }} */
6+
const { name, nodes } = func
7+
8+
if (isGradientFunctionName(name)) {
9+
nodes.slice(0).forEach((node, index, nodes) => {
10+
const node1back = Object(nodes[index - 1]);
11+
const node2back = Object(nodes[index - 2]);
12+
const node1next = Object(nodes[index + 1]);
13+
14+
const isDoublePositionLength = node2back.type && node1back.type === 'numeric' && node.type === 'numeric';
15+
16+
// if the argument concludes a double-position gradient
17+
if (isDoublePositionLength) {
18+
// insert the fallback colors
19+
const color = node2back.clone();
20+
const comma = new Punctuation({ value: ',', raws: isPunctuationCommaNode(node1next) ? { ...node1next.clone().raws } : { before: '', after: '' } })
21+
22+
func.insertBefore(node, [comma, color]);
23+
}
24+
})
25+
}
26+
}
27+
28+
export default onCSSFunction
29+
30+
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
31+
const createRegExpTest = Function.bind.bind(RegExp.prototype.test)
32+
33+
/** Return whether the function name is `lab` or `lch`. */
34+
const isGradientFunctionName = createRegExpTest(/^(repeating-)?(conic|linear|radial)-gradient$/i)
35+
36+
const isPunctuationCommaNode = node => node.type === 'punctuation' && node.value === ','
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
/** Whether to preserve the original hexa. */
3+
preserve: true
4+
}

plugins/postcss-double-position-gradients/test/basic.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
}
44

55
.test-conic-gradient {
6-
background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%, #f06 0deg);
6+
background-image: conic-gradient(yellowgreen 40%, gold 0deg 75% , #f06 0deg);
77
}

0 commit comments

Comments
 (0)