Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 8b41822

Browse files
committed
3.1.0
1 parent 56dfc2a commit 8b41822

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to PostCSS Lab Function
22

3+
### 3.1.0 (April 25, 2020)
4+
5+
- Updated: `postcss-values-parser` to 3.2.0 (minor).
6+
37
### 3.0.1 (April 12, 2020)
48

59
- Updated: Ownership moved to CSSTools.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-lab-function",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "Use lab() and lch() color functions in CSS",
55
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
66
"license": "CC0-1.0",
@@ -27,15 +27,15 @@
2727
"dependencies": {
2828
"@csstools/convert-colors": "^2.0.0",
2929
"postcss": "^7.0.27",
30-
"postcss-values-parser": "^3.1.1"
30+
"postcss-values-parser": "^3.2.0"
3131
},
3232
"devDependencies": {
3333
"@babel/core": "^7.9.0",
3434
"@babel/preset-env": "^7.9.5",
3535
"babel-eslint": "^10.1.0",
3636
"eslint": "^6.8.0",
3737
"postcss-tape": "^5.0.2",
38-
"rollup": "^2.6.0",
38+
"rollup": "^2.7.2",
3939
"rollup-plugin-babel": "^4.4.0"
4040
},
4141
"babel": {

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import postcss from 'postcss'
2-
import onDeclaration from './onDeclaration'
2+
import onCSSDeclaration from './onCSSDeclaration'
33
import options from './options'
44

55
/** Transform lab() and lch() functions in CSS. */
6-
const plugin = postcss.plugin('postcss-lab-function', /** @type {PostCSSPluginInitializer} */ opts => {
6+
const postcssPlugin = postcss.plugin('postcss-lab-function', /** @type {PostCSSPluginInitializer} */ opts => {
77
options.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false
88

99
return root => {
10-
root.walkDecls(onDeclaration)
10+
root.walkDecls(onCSSDeclaration)
1111
}
1212
})
1313

14-
export default plugin
14+
export default postcssPlugin
1515

1616
/** @typedef {import('postcss').Root} CSSRoot */
1717
/** @typedef {(root: CSSRoot) => void} PostCSSTransformCallback */
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import { parse } from 'postcss-values-parser'
2-
import onFunction from './onFunction'
2+
import onCSSFunction from './onCSSFunction'
33
import options from './options'
44

55
/** @type {(decl: CSSDeclaration) => void} Transform lab() and lch() functions in CSS Declarations. */
6-
const visitor = decl => {
7-
const { value } = decl
6+
const onCSSDeclaration = decl => {
7+
const { value: originalValue } = decl
88

9-
if (hasAnyColorFunction(value)) {
10-
const valueAST = parse(value)
9+
if (hasAnyColorFunction(originalValue)) {
10+
const valueAST = parse(originalValue)
1111

12-
valueAST.walkFuncs(onFunction)
12+
valueAST.walkFuncs(onCSSFunction)
1313

14-
const newValue = String(valueAST)
14+
const modifiedValue = String(valueAST)
1515

16-
if (options.preserve) decl.cloneBefore({ value: newValue })
17-
else decl.value = newValue
16+
if (modifiedValue !== originalValue) {
17+
if (options.preserve) decl.cloneBefore({ value: modifiedValue })
18+
else decl.value = modifiedValue
19+
}
1820
}
1921
}
2022

21-
export default visitor
23+
export default onCSSDeclaration
2224

2325
/** @type {(value: RegExp) => (value: string) => boolean} Return a function that checks whether the expression exists in a value. */
2426
const createRegExpTest = Function.bind.bind(RegExp.prototype.test)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { lab2rgb, lch2rgb } from '@csstools/convert-colors'
22
import { parse } from 'postcss-values-parser'
33

44
/** @type {(decl: CSSFunction) => void} Transform lab() and lch() functions. */
5-
const visitor = node => {
5+
const onCSSFunction = node => {
66
/** @type {{ name: string, nodes: CSSNode[] }} */
77
const { name, nodes } = node
88

@@ -75,7 +75,7 @@ const visitor = node => {
7575
}
7676
}
7777

78-
export default visitor
78+
export default onCSSFunction
7979

8080
const commaNode = parse(',').first
8181

0 commit comments

Comments
 (0)