postcss-calc 5.1.0 → 5.3.1
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 +20 -0
- package/README.md +36 -1
- package/index.js +28 -13
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
+
# 5.3.1 - 2016-08-22
|
|
2
|
+
|
|
3
|
+
- Fixed: avoid security issue related to ``reduce-css-calc@< 1.2.4``.
|
|
4
|
+
|
|
5
|
+
# 5.3.0 - 2016-07-11
|
|
6
|
+
|
|
7
|
+
- Added: support for selector transformation via `selectors` option.
|
|
8
|
+
([#29](https://github.com/postcss/postcss-calc/pull/29) - @uniquegestaltung)
|
|
9
|
+
|
|
10
|
+
# 5.2.1 - 2016-04-10
|
|
11
|
+
|
|
12
|
+
- Fixed: support for multiline value
|
|
13
|
+
([#27](https://github.com/postcss/postcss-calc/pull/27))
|
|
14
|
+
|
|
15
|
+
# 5.2.0 - 2016-01-08
|
|
16
|
+
|
|
17
|
+
- Added: "mediaQueries" option for `@media` support
|
|
18
|
+
([#22](https://github.com/postcss/postcss-calc/pull/22))
|
|
19
|
+
|
|
1
20
|
# 5.1.0 - 2016-01-07
|
|
2
21
|
|
|
3
22
|
- Added: "warnWhenCannotResolve" option to warn when calc() are not reduced to a single value
|
|
23
|
+
([#20](https://github.com/postcss/postcss-calc/pull/20))
|
|
4
24
|
|
|
5
25
|
# 5.0.0 - 2015-08-25
|
|
6
26
|
|
package/README.md
CHANGED
|
@@ -65,6 +65,10 @@ body {
|
|
|
65
65
|
h1 {
|
|
66
66
|
font-size: calc(var(--main-font-size) * 2);
|
|
67
67
|
height: calc(100px - 2em);
|
|
68
|
+
margin-bottom: calc(
|
|
69
|
+
var(--main-font-size)
|
|
70
|
+
* 1.5
|
|
71
|
+
)
|
|
68
72
|
}
|
|
69
73
|
```
|
|
70
74
|
|
|
@@ -77,7 +81,8 @@ body {
|
|
|
77
81
|
|
|
78
82
|
h1 {
|
|
79
83
|
font-size: 32px;
|
|
80
|
-
height: calc(100px - 2em)
|
|
84
|
+
height: calc(100px - 2em);
|
|
85
|
+
margin-bottom: 24px
|
|
81
86
|
}
|
|
82
87
|
```
|
|
83
88
|
|
|
@@ -118,6 +123,36 @@ var out = postcss()
|
|
|
118
123
|
.css
|
|
119
124
|
```
|
|
120
125
|
|
|
126
|
+
#### `mediaQueries` (default: `false`)
|
|
127
|
+
|
|
128
|
+
Allows calc() usage as part of media query declarations.
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
var out = postcss()
|
|
132
|
+
.use(calc({mediaQueries: true}))
|
|
133
|
+
.process(css)
|
|
134
|
+
.css
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### `selectors` (default: `false`)
|
|
138
|
+
|
|
139
|
+
Allows calc() usage as part of selectors.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
var out = postcss()
|
|
143
|
+
.use(calc({selectors: true}))
|
|
144
|
+
.process(css)
|
|
145
|
+
.css
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Example:
|
|
149
|
+
|
|
150
|
+
```css
|
|
151
|
+
div[data-size="calc(3*3)"] {
|
|
152
|
+
width: 100px;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
121
156
|
---
|
|
122
157
|
|
|
123
158
|
## Contributing
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var reduceCSSCalc = require("reduce-css-calc")
|
|
|
5
5
|
var helpers = require("postcss-message-helpers")
|
|
6
6
|
var postcss = require("postcss")
|
|
7
7
|
|
|
8
|
-
var CONTAINS_CALC =
|
|
8
|
+
var CONTAINS_CALC = /\bcalc\([\s\S]*?\)/
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* PostCSS plugin to reduce calc() function calls.
|
|
@@ -15,33 +15,48 @@ module.exports = postcss.plugin("postcss-calc", function(options) {
|
|
|
15
15
|
var precision = options.precision
|
|
16
16
|
var preserve = options.preserve
|
|
17
17
|
var warnWhenCannotResolve = options.warnWhenCannotResolve
|
|
18
|
+
var mediaQueries = options.mediaQueries
|
|
19
|
+
var selectors = options.selectors
|
|
18
20
|
|
|
19
21
|
return function(style, result) {
|
|
22
|
+
function transformValue(node, property) {
|
|
23
|
+
var value = node[property]
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
if (!decl.value || decl.value.indexOf("calc(") === -1) {
|
|
25
|
+
if (!value || !CONTAINS_CALC.test(value)) {
|
|
23
26
|
return
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
helpers.try(function transformCSSCalc() {
|
|
27
|
-
var
|
|
30
|
+
var reducedValue = reduceCSSCalc(value, precision)
|
|
28
31
|
|
|
29
|
-
if (warnWhenCannotResolve && CONTAINS_CALC.test(
|
|
30
|
-
result.warn("Could not reduce expression: " +
|
|
31
|
-
{plugin: "postcss-calc", node:
|
|
32
|
+
if (warnWhenCannotResolve && CONTAINS_CALC.test(reducedValue)) {
|
|
33
|
+
result.warn("Could not reduce expression: " + value,
|
|
34
|
+
{plugin: "postcss-calc", node: node})
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
if (!preserve) {
|
|
35
|
-
|
|
38
|
+
node[property] = reducedValue
|
|
36
39
|
return
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
if (
|
|
40
|
-
var clone =
|
|
41
|
-
clone
|
|
42
|
-
|
|
42
|
+
if (reducedValue != value) {
|
|
43
|
+
var clone = node.clone()
|
|
44
|
+
clone[property] = reducedValue
|
|
45
|
+
node.parent.insertBefore(node, clone)
|
|
43
46
|
}
|
|
44
|
-
},
|
|
47
|
+
}, node.source)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
style.walk(function(rule) {
|
|
51
|
+
if (mediaQueries && rule.type === "atrule") {
|
|
52
|
+
return transformValue(rule, "params")
|
|
53
|
+
}
|
|
54
|
+
else if (rule.type === "decl") {
|
|
55
|
+
return transformValue(rule, "value")
|
|
56
|
+
}
|
|
57
|
+
else if (selectors && rule.type === "rule") {
|
|
58
|
+
return transformValue(rule, "selector")
|
|
59
|
+
}
|
|
45
60
|
})
|
|
46
61
|
}
|
|
47
62
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-calc",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"description": "PostCSS plugin to reduce calc()",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -17,15 +17,17 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"postcss-message-helpers": "^2.0.0",
|
|
20
|
-
"reduce-css-calc": "^1.2.
|
|
20
|
+
"reduce-css-calc": "^1.2.6",
|
|
21
21
|
"postcss": "^5.0.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"eslint": "^1.0.0",
|
|
25
|
+
"npmpub": "^3.1.0",
|
|
25
26
|
"postcss-custom-properties": "^5.0.0",
|
|
26
27
|
"tape": "^3.0.0"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
|
-
"test": "eslint . && tape test"
|
|
30
|
+
"test": "eslint . && tape test",
|
|
31
|
+
"release": "npmpub"
|
|
30
32
|
}
|
|
31
33
|
}
|