@csstools/postcss-sign-functions 1.0.0 → 1.1.0
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 +6 -4
- package/README.md +25 -8
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Changes to PostCSS Sign Functions
|
|
2
2
|
|
|
3
|
-
### 1.
|
|
3
|
+
### 1.1.0
|
|
4
4
|
|
|
5
|
-
_November
|
|
5
|
+
_November 17, 2024_
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
7
|
+
- Add support for unresolvable values (e.g. `%` and `var()` in `abs()`)
|
|
8
|
+
- Change `preserve` option to default to `false`
|
|
9
|
+
|
|
10
|
+
[Full CHANGELOG](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-sign-functions/CHANGELOG.md)
|
package/README.md
CHANGED
|
@@ -29,36 +29,38 @@
|
|
|
29
29
|
z-index: abs(10px);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
.abs {
|
|
33
|
+
z-index: abs(10%);
|
|
34
|
+
}
|
|
35
|
+
|
|
32
36
|
/* becomes */
|
|
33
37
|
|
|
34
38
|
.sign {
|
|
35
39
|
z-index: -1;
|
|
36
|
-
z-index: sign(-10px);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
.sign {
|
|
40
43
|
z-index: 0;
|
|
41
|
-
z-index: sign(0);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
.sign {
|
|
45
47
|
z-index: 1;
|
|
46
|
-
z-index: sign(10px);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
.abs {
|
|
50
51
|
z-index: 10px;
|
|
51
|
-
z-index: abs(-10px);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
.abs {
|
|
55
55
|
z-index: 0;
|
|
56
|
-
z-index: abs(0);
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
.abs {
|
|
60
59
|
z-index: 10px;
|
|
61
|
-
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.abs {
|
|
63
|
+
z-index: max((10%), -1 * (10%));
|
|
62
64
|
}
|
|
63
65
|
```
|
|
64
66
|
|
|
@@ -99,10 +101,10 @@ Because of that, any usage that contains a `var` is skipped.
|
|
|
99
101
|
### preserve
|
|
100
102
|
|
|
101
103
|
The `preserve` option determines whether the original notation
|
|
102
|
-
is preserved. By default, it is preserved.
|
|
104
|
+
is preserved. By default, it is not preserved.
|
|
103
105
|
|
|
104
106
|
```js
|
|
105
|
-
postcssSignFunctions({ preserve:
|
|
107
|
+
postcssSignFunctions({ preserve: true })
|
|
106
108
|
```
|
|
107
109
|
|
|
108
110
|
```css
|
|
@@ -130,30 +132,45 @@ postcssSignFunctions({ preserve: false })
|
|
|
130
132
|
z-index: abs(10px);
|
|
131
133
|
}
|
|
132
134
|
|
|
135
|
+
.abs {
|
|
136
|
+
z-index: abs(10%);
|
|
137
|
+
}
|
|
138
|
+
|
|
133
139
|
/* becomes */
|
|
134
140
|
|
|
135
141
|
.sign {
|
|
136
142
|
z-index: -1;
|
|
143
|
+
z-index: sign(-10px);
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
.sign {
|
|
140
147
|
z-index: 0;
|
|
148
|
+
z-index: sign(0);
|
|
141
149
|
}
|
|
142
150
|
|
|
143
151
|
.sign {
|
|
144
152
|
z-index: 1;
|
|
153
|
+
z-index: sign(10px);
|
|
145
154
|
}
|
|
146
155
|
|
|
147
156
|
.abs {
|
|
148
157
|
z-index: 10px;
|
|
158
|
+
z-index: abs(-10px);
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
.abs {
|
|
152
162
|
z-index: 0;
|
|
163
|
+
z-index: abs(0);
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
.abs {
|
|
156
167
|
z-index: 10px;
|
|
168
|
+
z-index: abs(10px);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.abs {
|
|
172
|
+
z-index: max((10%), -1 * (10%));
|
|
173
|
+
z-index: abs(10%);
|
|
157
174
|
}
|
|
158
175
|
```
|
|
159
176
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=require("@csstools/css-calc"),o=require("@csstools/css-tokenizer"),n=require("@csstools/css-parser-algorithms");const s=/(?<![-\w])(?:sign|abs)\(/i,a=/(?<![-\w])(?:sign|abs)\(/i,creator=t=>{const r=Object.assign({preserve:!1},t);return{postcssPlugin:"postcss-sign-functions",Declaration(t){if(!s.test(t.value))return;let i;i=a.test(t.value)?n.replaceComponentValues(n.parseCommaSeparatedListOfComponentValues(o.tokenize({css:t.value})),replacer):n.parseCommaSeparatedListOfComponentValues(o.tokenize({css:t.value}));const p=n.stringify(e.calcFromComponentValues(i,{precision:5,toCanonicalUnits:!0}));p!==t.value&&(t.cloneBefore({value:p}),r.preserve||t.remove())}}};function replacer(e){if(!n.isFunctionNode(e))return;if("abs"!==e.getName().toLowerCase())return;const[s]=n.replaceComponentValues([e.value],replacer);return[new n.FunctionNode([o.TokenType.Function,"max(",-1,-1,{value:"max"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[new n.SimpleBlockNode([o.TokenType.OpenParen,"(",-1,-1,void 0],[o.TokenType.CloseParen,")",-1,-1,void 0],n.parseListOfComponentValues(s.flatMap((e=>e.tokens())))),new n.TokenNode([o.TokenType.Comma,",",-1,-1,void 0]),new n.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),new n.TokenNode([o.TokenType.Number,"-1",-1,-1,{value:-1,type:o.NumberType.Integer,signCharacter:"-"}]),new n.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),new n.TokenNode([o.TokenType.Delim,"*",-1,-1,{value:"*"}]),new n.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),new n.SimpleBlockNode([o.TokenType.OpenParen,"(",-1,-1,void 0],[o.TokenType.CloseParen,")",-1,-1,void 0],n.parseListOfComponentValues(s.flatMap((e=>e.tokens()))))])]}creator.postcss=!0,module.exports=creator;
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{calc as s}from"@csstools/css-
|
|
1
|
+
import{calcFromComponentValues as e}from"@csstools/css-calc";import{tokenize as s,TokenType as o,NumberType as n}from"@csstools/css-tokenizer";import{replaceComponentValues as t,parseCommaSeparatedListOfComponentValues as a,isFunctionNode as r,FunctionNode as i,SimpleBlockNode as c,parseListOfComponentValues as l,TokenNode as p,WhitespaceNode as v,stringify as u}from"@csstools/css-parser-algorithms";const m=/(?<![-\w])(?:sign|abs)\(/i,f=/(?<![-\w])(?:sign|abs)\(/i,creator=o=>{const n=Object.assign({preserve:!1},o);return{postcssPlugin:"postcss-sign-functions",Declaration(o){if(!m.test(o.value))return;let r;r=f.test(o.value)?t(a(s({css:o.value})),replacer):a(s({css:o.value}));const i=u(e(r,{precision:5,toCanonicalUnits:!0}));i!==o.value&&(o.cloneBefore({value:i}),n.preserve||o.remove())}}};function replacer(e){if(!r(e))return;if("abs"!==e.getName().toLowerCase())return;const[s]=t([e.value],replacer);return[new i([o.Function,"max(",-1,-1,{value:"max"}],[o.CloseParen,")",-1,-1,void 0],[new c([o.OpenParen,"(",-1,-1,void 0],[o.CloseParen,")",-1,-1,void 0],l(s.flatMap((e=>e.tokens())))),new p([o.Comma,",",-1,-1,void 0]),new v([[o.Whitespace," ",-1,-1,void 0]]),new p([o.Number,"-1",-1,-1,{value:-1,type:n.Integer,signCharacter:"-"}]),new v([[o.Whitespace," ",-1,-1,void 0]]),new p([o.Delim,"*",-1,-1,{value:"*"}]),new v([[o.Whitespace," ",-1,-1,void 0]]),new c([o.OpenParen,"(",-1,-1,void 0],[o.CloseParen,")",-1,-1,void 0],l(s.flatMap((e=>e.tokens()))))])]}creator.postcss=!0;export{creator as default};
|