@csstools/postcss-sign-functions 1.0.0 → 1.1.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 CHANGED
@@ -1,8 +1,9 @@
1
1
  # Changes to PostCSS Sign Functions
2
2
 
3
- ### 1.0.0
3
+ ### 1.1.1
4
4
 
5
- _November 11, 2024_
5
+ _December 27, 2024_
6
6
 
7
- - Initial version
8
- - Updated [`@csstools/css-calc`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-calc) to [`2.1.0`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-calc/CHANGELOG.md#210) (minor)
7
+ - Updated [`@csstools/css-calc`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-calc) to [`2.1.1`](https://github.com/csstools/postcss-plugins/tree/main/packages/css-calc/CHANGELOG.md#211) (patch)
8
+
9
+ [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
- z-index: abs(10px);
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: false })
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 s=require("@csstools/css-calc");const e=/(?<![-\w])(?:sign|abs)\(/i,creator=c=>{const t=Object.assign({preserve:!0},c);return{postcssPlugin:"postcss-sign-functions",Declaration(c){if(!e.test(c.value))return;const o=s.calc(c.value,{precision:5,toCanonicalUnits:!0});o!==c.value&&(c.cloneBefore({value:o}),t.preserve||c.remove())}}};creator.postcss=!0,module.exports=creator;
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
@@ -5,7 +5,7 @@ export default creator;
5
5
 
6
6
  /** postcss-sign-functions plugin options */
7
7
  export declare type pluginOptions = {
8
- /** Preserve the original notation. default: true */
8
+ /** Preserve the original notation. default: false */
9
9
  preserve?: boolean;
10
10
  };
11
11
 
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{calc as s}from"@csstools/css-calc";const e=/(?<![-\w])(?:sign|abs)\(/i,creator=o=>{const t=Object.assign({preserve:!0},o);return{postcssPlugin:"postcss-sign-functions",Declaration(o){if(!e.test(o.value))return;const n=s(o.value,{precision:5,toCanonicalUnits:!0});n!==o.value&&(o.cloneBefore({value:n}),t.preserve||o.remove())}}};creator.postcss=!0;export{creator as default};
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,stringify as r,isFunctionNode as i,FunctionNode as c,SimpleBlockNode as l,parseListOfComponentValues as p,TokenNode as v,WhitespaceNode 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 i;i=f.test(o.value)?t(a(s({css:o.value})),replacer):a(s({css:o.value}));const c=r(e(i,{precision:5,toCanonicalUnits:!0}));c!==o.value&&(o.cloneBefore({value:c}),n.preserve||o.remove())}}};function replacer(e){if(!i(e))return;if("abs"!==e.getName().toLowerCase())return;const[s]=t([e.value],replacer);return[new c([o.Function,"max(",-1,-1,{value:"max"}],[o.CloseParen,")",-1,-1,void 0],[new l([o.OpenParen,"(",-1,-1,void 0],[o.CloseParen,")",-1,-1,void 0],p(s.flatMap((e=>e.tokens())))),new v([o.Comma,",",-1,-1,void 0]),new u([[o.Whitespace," ",-1,-1,void 0]]),new v([o.Number,"-1",-1,-1,{value:-1,type:n.Integer,signCharacter:"-"}]),new u([[o.Whitespace," ",-1,-1,void 0]]),new v([o.Delim,"*",-1,-1,{value:"*"}]),new u([[o.Whitespace," ",-1,-1,void 0]]),new l([o.OpenParen,"(",-1,-1,void 0],[o.CloseParen,")",-1,-1,void 0],p(s.flatMap((e=>e.tokens()))))])]}creator.postcss=!0;export{creator as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@csstools/postcss-sign-functions",
3
3
  "description": "Use sign and abs functions in CSS",
4
- "version": "1.0.0",
4
+ "version": "1.1.1",
5
5
  "contributors": [
6
6
  {
7
7
  "name": "Antonio Laguna",
@@ -48,7 +48,7 @@
48
48
  "dist"
49
49
  ],
50
50
  "dependencies": {
51
- "@csstools/css-calc": "^2.1.0",
51
+ "@csstools/css-calc": "^2.1.1",
52
52
  "@csstools/css-parser-algorithms": "^3.0.4",
53
53
  "@csstools/css-tokenizer": "^3.0.3"
54
54
  },