@csstools/postcss-sign-functions 1.0.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 ADDED
@@ -0,0 +1,8 @@
1
+ # Changes to PostCSS Sign Functions
2
+
3
+ ### 1.0.0
4
+
5
+ _November 11, 2024_
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)
package/LICENSE.md ADDED
@@ -0,0 +1,18 @@
1
+ MIT No Attribution (MIT-0)
2
+
3
+ Copyright © CSSTools Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the “Software”), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so.
11
+
12
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # PostCSS Sign Functions [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS]
2
+
3
+ `npm install @csstools/postcss-sign-functions --save-dev`
4
+
5
+ [PostCSS Sign Functions] lets you use the `sign` and `abs` functions, following the [CSS Values 4] specification.
6
+
7
+ ```css
8
+ .sign {
9
+ z-index: sign(-10px);
10
+ }
11
+
12
+ .sign {
13
+ z-index: sign(0);
14
+ }
15
+
16
+ .sign {
17
+ z-index: sign(10px);
18
+ }
19
+
20
+ .abs {
21
+ z-index: abs(-10px);
22
+ }
23
+
24
+ .abs {
25
+ z-index: abs(0);
26
+ }
27
+
28
+ .abs {
29
+ z-index: abs(10px);
30
+ }
31
+
32
+ /* becomes */
33
+
34
+ .sign {
35
+ z-index: -1;
36
+ z-index: sign(-10px);
37
+ }
38
+
39
+ .sign {
40
+ z-index: 0;
41
+ z-index: sign(0);
42
+ }
43
+
44
+ .sign {
45
+ z-index: 1;
46
+ z-index: sign(10px);
47
+ }
48
+
49
+ .abs {
50
+ z-index: 10px;
51
+ z-index: abs(-10px);
52
+ }
53
+
54
+ .abs {
55
+ z-index: 0;
56
+ z-index: abs(0);
57
+ }
58
+
59
+ .abs {
60
+ z-index: 10px;
61
+ z-index: abs(10px);
62
+ }
63
+ ```
64
+
65
+ > [!NOTE]
66
+ > The utility of static fallbacks for `sign` and `abs` is limited.
67
+ > The most interesting values are variables and dynamic values (e.g. those containing `%`).
68
+ > It is impossible to generate static fallbacks in a build process for values that are dynamic on the client.
69
+
70
+ ## Usage
71
+
72
+ Add [PostCSS Sign Functions] to your project:
73
+
74
+ ```bash
75
+ npm install postcss @csstools/postcss-sign-functions --save-dev
76
+ ```
77
+
78
+ Use it as a [PostCSS] plugin:
79
+
80
+ ```js
81
+ const postcss = require('postcss');
82
+ const postcssSignFunctions = require('@csstools/postcss-sign-functions');
83
+
84
+ postcss([
85
+ postcssSignFunctions(/* pluginOptions */)
86
+ ]).process(YOUR_CSS /*, processOptions */);
87
+ ```
88
+
89
+
90
+
91
+ ## ⚠️ About custom properties
92
+
93
+ Given the dynamic nature of custom properties it's impossible to know what the variable value is, which means the plugin can't compute a final value for the stylesheet.
94
+
95
+ Because of that, any usage that contains a `var` is skipped.
96
+
97
+ ## Options
98
+
99
+ ### preserve
100
+
101
+ The `preserve` option determines whether the original notation
102
+ is preserved. By default, it is preserved.
103
+
104
+ ```js
105
+ postcssSignFunctions({ preserve: false })
106
+ ```
107
+
108
+ ```css
109
+ .sign {
110
+ z-index: sign(-10px);
111
+ }
112
+
113
+ .sign {
114
+ z-index: sign(0);
115
+ }
116
+
117
+ .sign {
118
+ z-index: sign(10px);
119
+ }
120
+
121
+ .abs {
122
+ z-index: abs(-10px);
123
+ }
124
+
125
+ .abs {
126
+ z-index: abs(0);
127
+ }
128
+
129
+ .abs {
130
+ z-index: abs(10px);
131
+ }
132
+
133
+ /* becomes */
134
+
135
+ .sign {
136
+ z-index: -1;
137
+ }
138
+
139
+ .sign {
140
+ z-index: 0;
141
+ }
142
+
143
+ .sign {
144
+ z-index: 1;
145
+ }
146
+
147
+ .abs {
148
+ z-index: 10px;
149
+ }
150
+
151
+ .abs {
152
+ z-index: 0;
153
+ }
154
+
155
+ .abs {
156
+ z-index: 10px;
157
+ }
158
+ ```
159
+
160
+ [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
161
+ [css-url]: https://cssdb.org/#sign-functions
162
+ [discord]: https://discord.gg/bUadyRwkJS
163
+ [npm-url]: https://www.npmjs.com/package/@csstools/postcss-sign-functions
164
+
165
+ [PostCSS]: https://github.com/postcss/postcss
166
+ [PostCSS Sign Functions]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-sign-functions
167
+ [CSS Values 4]: https://drafts.csswg.org/css-values-4/#sign-funcs
package/dist/index.cjs ADDED
@@ -0,0 +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;
@@ -0,0 +1,12 @@
1
+ import type { PluginCreator } from 'postcss';
2
+
3
+ declare const creator: PluginCreator<pluginOptions>;
4
+ export default creator;
5
+
6
+ /** postcss-sign-functions plugin options */
7
+ export declare type pluginOptions = {
8
+ /** Preserve the original notation. default: true */
9
+ preserve?: boolean;
10
+ };
11
+
12
+ export { }
package/dist/index.mjs ADDED
@@ -0,0 +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};
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@csstools/postcss-sign-functions",
3
+ "description": "Use sign and abs functions in CSS",
4
+ "version": "1.0.0",
5
+ "contributors": [
6
+ {
7
+ "name": "Antonio Laguna",
8
+ "email": "antonio@laguna.es",
9
+ "url": "https://antonio.laguna.es"
10
+ },
11
+ {
12
+ "name": "Romain Menke",
13
+ "email": "romainmenke@gmail.com"
14
+ }
15
+ ],
16
+ "license": "MIT-0",
17
+ "funding": [
18
+ {
19
+ "type": "github",
20
+ "url": "https://github.com/sponsors/csstools"
21
+ },
22
+ {
23
+ "type": "opencollective",
24
+ "url": "https://opencollective.com/csstools"
25
+ }
26
+ ],
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "type": "module",
31
+ "main": "dist/index.cjs",
32
+ "module": "dist/index.mjs",
33
+ "exports": {
34
+ ".": {
35
+ "import": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.mjs"
38
+ },
39
+ "require": {
40
+ "default": "./dist/index.cjs"
41
+ }
42
+ }
43
+ },
44
+ "files": [
45
+ "CHANGELOG.md",
46
+ "LICENSE.md",
47
+ "README.md",
48
+ "dist"
49
+ ],
50
+ "dependencies": {
51
+ "@csstools/css-calc": "^2.1.0",
52
+ "@csstools/css-parser-algorithms": "^3.0.4",
53
+ "@csstools/css-tokenizer": "^3.0.3"
54
+ },
55
+ "peerDependencies": {
56
+ "postcss": "^8.4"
57
+ },
58
+ "scripts": {},
59
+ "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-sign-functions#readme",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/csstools/postcss-plugins.git",
63
+ "directory": "plugins/postcss-sign-functions"
64
+ },
65
+ "bugs": "https://github.com/csstools/postcss-plugins/issues",
66
+ "keywords": [
67
+ "abs",
68
+ "css",
69
+ "postcss-plugin",
70
+ "sign"
71
+ ]
72
+ }