postcss-clamp
Advanced tools
Comparing version 1.1.0 to 2.0.0
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 2.0.0 | ||
* Rewrite package to PostCSS 8 (#2) | ||
## 1.1.0 | ||
@@ -5,0 +9,0 @@ |
38
index.js
@@ -1,2 +0,1 @@ | ||
let postcss = require('postcss') | ||
let valueParser = require('postcss-value-parser') | ||
@@ -23,8 +22,9 @@ | ||
module.exports = postcss.plugin('postcss-clamp', opts => { | ||
module.exports = opts => { | ||
opts = opts || {} | ||
let precalculate = opts.precalculate ? Boolean(opts.precalculate) : false | ||
return function (css) { | ||
css.walkDecls(decl => { | ||
return { | ||
postcssPlugin: 'postcss-clamp', | ||
Declaration (decl) { | ||
if (!decl || !decl.value.includes('clamp')) { | ||
@@ -42,7 +42,5 @@ return | ||
} | ||
let first = nodes[0] | ||
let second = nodes[2] | ||
let third = nodes[4] | ||
let naive = compose( | ||
@@ -53,11 +51,12 @@ valueParser.stringify(first), | ||
) | ||
if (!precalculate || second.type !== 'word' || third.type !== 'word') { | ||
if ( | ||
!precalculate || | ||
second.type !== 'word' || | ||
third.type !== 'word' | ||
) { | ||
decl.value = naive | ||
return | ||
} | ||
let parsedSecond = parseValue(second.value) | ||
let parsedThird = parseValue(third.value) | ||
if (parsedSecond === undefined || parsedThird === undefined) { | ||
@@ -67,6 +66,4 @@ decl.value = naive | ||
} | ||
let [secondValue, secondUnit] = parsedSecond | ||
let [thirdValue, thirdUnit] = parsedThird | ||
if (secondUnit !== thirdUnit) { | ||
@@ -76,24 +73,23 @@ decl.value = naive | ||
} | ||
let parsedFirst = parseValue(first.value) | ||
if (parsedFirst === undefined) { | ||
let secondThirdValue = `${ secondValue + thirdValue }${ secondUnit }` | ||
let secondThirdValue = | ||
`${ secondValue + thirdValue }${ secondUnit }` | ||
decl.value = compose(valueParser.stringify(first), secondThirdValue) | ||
return | ||
} | ||
let [firstValue, firstUnit] = parsedFirst | ||
if (firstUnit !== secondUnit) { | ||
let secondThirdValue = `${ secondValue + thirdValue }${ secondUnit }` | ||
let secondThirdValue = | ||
`${ secondValue + thirdValue }${ secondUnit }` | ||
decl.value = compose(valueParser.stringify(first), secondThirdValue) | ||
return | ||
} | ||
decl.value = | ||
compose(`${ firstValue + secondValue + thirdValue }${ secondUnit }`) | ||
}) | ||
}) | ||
} | ||
} | ||
}) | ||
} | ||
module.exports.postcss = true |
{ | ||
"name": "postcss-clamp", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "PostCSS plugin to transform clamp() to combination of min/max", | ||
@@ -18,5 +18,7 @@ "keywords": [ | ||
"dependencies": { | ||
"postcss": "^7.0.29", | ||
"postcss-value-parser": "^4.1.0" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.1.1" | ||
}, | ||
"engines": { | ||
@@ -23,0 +25,0 @@ "node": ">=7.6.0" |
@@ -47,5 +47,5 @@ # PostCSS Clamp | ||
```bash | ||
$ npm install postcss-clamp --save-dev | ||
$ npm install postcss postcss-clamp --save-dev | ||
or | ||
$ yarn add --dev postcss-clamp | ||
$ yarn add --dev postcss postcss-clamp | ||
``` | ||
@@ -52,0 +52,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14206
213
+ Addednanoid@3.3.7(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.4.49(transitive)
+ Addedsource-map-js@1.2.1(transitive)
- Removedpostcss@^7.0.29
- Removedpicocolors@0.2.1(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedsource-map@0.6.1(transitive)