Skip to content

Commit 5d96ee5

Browse files
PostCSS Trigonometric Functions (#381)
* Getting plugin started * Lots of work Plugin should mostly be stable but needs lots of tests around calculations and unexpected values just to be sure * Less strict filtering * Handling pi and e * Better ordering * Enabling WPT tests * Ignore units for `atan2` * Housekeeping * Early exit * Wrong broken tests * Accounting for wrong tests * Support for even more complex calculations * More tests * Linting * Adding documentation * Missing labeler * add tests for the same keywords but as non-functions or without args Co-authored-by: romainmenke <romainmenke@gmail.com>
1 parent edc0fe3 commit 5d96ee5

32 files changed

+2523
-1
lines changed

.github/labeler.yml

+4
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,9 @@
188188
- plugins/postcss-stepped-value-functions/**
189189
- experimental/postcss-stepped-value-functions/**
190190

191+
"plugins/postcss-trigonometric-functions":
192+
- plugins/postcss-trigonometric-functions/**
193+
- experimental/postcss-trigonometric-functions/**
194+
191195
"sites/postcss-preset-env":
192196
- sites/postcss-preset-env/**

package-lock.json

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/postcss-stepped-value-functions/docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
## ⚠️ About custom properties
3232

33-
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.
33+
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.
3434

3535
Because of that, any usage that contains a `var` is skipped.
3636

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
package-lock.json
3+
yarn.lock
4+
*.result.css
5+
*.result.css.map
6+
dist/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v16.13.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import postcssTape from '../../packages/postcss-tape/dist/index.mjs';
2+
import plugin from '@csstools/postcss-trigonometric-functions';
3+
4+
postcssTape(plugin)({
5+
basic: {
6+
message: "supports basic usage",
7+
},
8+
'basic:preserve-true': {
9+
message: 'supports { preserve: true } usage',
10+
options: {
11+
preserve: true
12+
},
13+
},
14+
'examples/example': {
15+
message: 'minimal example',
16+
},
17+
'examples/example:preserve-true': {
18+
message: 'minimal example',
19+
options: {
20+
preserve: true
21+
}
22+
},
23+
wpt: {
24+
message: "supports wpt cases",
25+
},
26+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changes to PostCSS Trigonometric Functions
2+
3+
### 1.0.0 (Unreleased)
4+
5+
- Initial version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Installing PostCSS Trigonometric Functions
2+
3+
[PostCSS Trigonometric Functions] runs in all Node environments, with special instructions for:
4+
5+
| [Node](#node) | [PostCSS CLI](#postcss-cli) | [Webpack](#webpack) | [Create React App](#create-react-app) | [Gulp](#gulp) | [Grunt](#grunt) |
6+
| --- | --- | --- | --- | --- | --- |
7+
8+
## Node
9+
10+
Add [PostCSS Trigonometric Functions] to your project:
11+
12+
```bash
13+
npm install postcss @csstools/postcss-trigonometric-functions --save-dev
14+
```
15+
16+
Use it as a [PostCSS] plugin:
17+
18+
```js
19+
const postcss = require('postcss');
20+
const postcssTrigonometricFunctions = require('@csstools/postcss-trigonometric-functions');
21+
22+
postcss([
23+
postcssTrigonometricFunctions(/* pluginOptions */)
24+
]).process(YOUR_CSS /*, processOptions */);
25+
```
26+
27+
## PostCSS CLI
28+
29+
Add [PostCSS CLI] to your project:
30+
31+
```bash
32+
npm install postcss-cli @csstools/postcss-trigonometric-functions --save-dev
33+
```
34+
35+
Use [PostCSS Trigonometric Functions] in your `postcss.config.js` configuration file:
36+
37+
```js
38+
const postcssTrigonometricFunctions = require('@csstools/postcss-trigonometric-functions');
39+
40+
module.exports = {
41+
plugins: [
42+
postcssTrigonometricFunctions(/* pluginOptions */)
43+
]
44+
}
45+
```
46+
47+
## Webpack
48+
49+
_Webpack version 5_
50+
51+
Add [PostCSS Loader] to your project:
52+
53+
```bash
54+
npm install postcss-loader @csstools/postcss-trigonometric-functions --save-dev
55+
```
56+
57+
Use [PostCSS Trigonometric Functions] in your Webpack configuration:
58+
59+
```js
60+
module.exports = {
61+
module: {
62+
rules: [
63+
{
64+
test: /\.css$/i,
65+
use: [
66+
"style-loader",
67+
{
68+
loader: "css-loader",
69+
options: { importLoaders: 1 },
70+
},
71+
{
72+
loader: "postcss-loader",
73+
options: {
74+
postcssOptions: {
75+
plugins: [
76+
[
77+
"@csstools/postcss-trigonometric-functions",
78+
{
79+
// Options
80+
},
81+
],
82+
],
83+
},
84+
},
85+
},
86+
],
87+
},
88+
],
89+
},
90+
};
91+
```
92+
93+
## Create React App
94+
95+
Add [React App Rewired] and [React App Rewire PostCSS] to your project:
96+
97+
```bash
98+
npm install react-app-rewired react-app-rewire-postcss @csstools/postcss-trigonometric-functions --save-dev
99+
```
100+
101+
Use [React App Rewire PostCSS] and [PostCSS Trigonometric Functions] in your
102+
`config-overrides.js` file:
103+
104+
```js
105+
const reactAppRewirePostcss = require('react-app-rewire-postcss');
106+
const postcssTrigonometricFunctions = require('@csstools/postcss-trigonometric-functions');
107+
108+
module.exports = config => reactAppRewirePostcss(config, {
109+
plugins: () => [
110+
postcssTrigonometricFunctions(/* pluginOptions */)
111+
]
112+
});
113+
```
114+
115+
## Gulp
116+
117+
Add [Gulp PostCSS] to your project:
118+
119+
```bash
120+
npm install gulp-postcss @csstools/postcss-trigonometric-functions --save-dev
121+
```
122+
123+
Use [PostCSS Trigonometric Functions] in your Gulpfile:
124+
125+
```js
126+
const postcss = require('gulp-postcss');
127+
const postcssTrigonometricFunctions = require('@csstools/postcss-trigonometric-functions');
128+
129+
gulp.task('css', function () {
130+
var plugins = [
131+
postcssTrigonometricFunctions(/* pluginOptions */)
132+
];
133+
134+
return gulp.src('./src/*.css')
135+
.pipe(postcss(plugins))
136+
.pipe(gulp.dest('.'));
137+
});
138+
```
139+
140+
## Grunt
141+
142+
Add [Grunt PostCSS] to your project:
143+
144+
```bash
145+
npm install grunt-postcss @csstools/postcss-trigonometric-functions --save-dev
146+
```
147+
148+
Use [PostCSS Trigonometric Functions] in your Gruntfile:
149+
150+
```js
151+
const postcssTrigonometricFunctions = require('@csstools/postcss-trigonometric-functions');
152+
153+
grunt.loadNpmTasks('grunt-postcss');
154+
155+
grunt.initConfig({
156+
postcss: {
157+
options: {
158+
processors: [
159+
postcssTrigonometricFunctions(/* pluginOptions */)
160+
]
161+
},
162+
dist: {
163+
src: '*.css'
164+
}
165+
}
166+
});
167+
```
168+
169+
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
170+
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
171+
[PostCSS]: https://github.com/postcss/postcss
172+
[PostCSS CLI]: https://github.com/postcss/postcss-cli
173+
[PostCSS Loader]: https://github.com/postcss/postcss-loader
174+
[PostCSS Trigonometric Functions]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-trigonometric-functions
175+
[React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
176+
[React App Rewired]: https://github.com/timarney/react-app-rewired
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# CC0 1.0 Universal
2+
3+
## Statement of Purpose
4+
5+
The laws of most jurisdictions throughout the world automatically confer
6+
exclusive Copyright and Related Rights (defined below) upon the creator and
7+
subsequent owner(s) (each and all, an “owner”) of an original work of
8+
authorship and/or a database (each, a “Work”).
9+
10+
Certain owners wish to permanently relinquish those rights to a Work for the
11+
purpose of contributing to a commons of creative, cultural and scientific works
12+
(“Commons”) that the public can reliably and without fear of later claims of
13+
infringement build upon, modify, incorporate in other works, reuse and
14+
redistribute as freely as possible in any form whatsoever and for any purposes,
15+
including without limitation commercial purposes. These owners may contribute
16+
to the Commons to promote the ideal of a free culture and the further
17+
production of creative, cultural and scientific works, or to gain reputation or
18+
greater distribution for their Work in part through the use and efforts of
19+
others.
20+
21+
For these and/or other purposes and motivations, and without any expectation of
22+
additional consideration or compensation, the person associating CC0 with a
23+
Work (the “Affirmer”), to the extent that he or she is an owner of Copyright
24+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and
25+
publicly distribute the Work under its terms, with knowledge of his or her
26+
Copyright and Related Rights in the Work and the meaning and intended legal
27+
effect of CC0 on those rights.
28+
29+
1. Copyright and Related Rights. A Work made available under CC0 may be
30+
protected by copyright and related or neighboring rights (“Copyright and
31+
Related Rights”). Copyright and Related Rights include, but are not limited
32+
to, the following:
33+
1. the right to reproduce, adapt, distribute, perform, display, communicate,
34+
and translate a Work;
35+
2. moral rights retained by the original author(s) and/or performer(s);
36+
3. publicity and privacy rights pertaining to a person’s image or likeness
37+
depicted in a Work;
38+
4. rights protecting against unfair competition in regards to a Work,
39+
subject to the limitations in paragraph 4(i), below;
40+
5. rights protecting the extraction, dissemination, use and reuse of data in
41+
a Work;
42+
6. database rights (such as those arising under Directive 96/9/EC of the
43+
European Parliament and of the Council of 11 March 1996 on the legal
44+
protection of databases, and under any national implementation thereof,
45+
including any amended or successor version of such directive); and
46+
7. other similar, equivalent or corresponding rights throughout the world
47+
based on applicable law or treaty, and any national implementations
48+
thereof.
49+
50+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
51+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
52+
unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright
53+
and Related Rights and associated claims and causes of action, whether now
54+
known or unknown (including existing as well as future claims and causes of
55+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
56+
duration provided by applicable law or treaty (including future time
57+
extensions), (iii) in any current or future medium and for any number of
58+
copies, and (iv) for any purpose whatsoever, including without limitation
59+
commercial, advertising or promotional purposes (the “Waiver”). Affirmer
60+
makes the Waiver for the benefit of each member of the public at large and
61+
to the detriment of Affirmer’s heirs and successors, fully intending that
62+
such Waiver shall not be subject to revocation, rescission, cancellation,
63+
termination, or any other legal or equitable action to disrupt the quiet
64+
enjoyment of the Work by the public as contemplated by Affirmer’s express
65+
Statement of Purpose.
66+
67+
3. Public License Fallback. Should any part of the Waiver for any reason be
68+
judged legally invalid or ineffective under applicable law, then the Waiver
69+
shall be preserved to the maximum extent permitted taking into account
70+
Affirmer’s express Statement of Purpose. In addition, to the extent the
71+
Waiver is so judged Affirmer hereby grants to each affected person a
72+
royalty-free, non transferable, non sublicensable, non exclusive,
73+
irrevocable and unconditional license to exercise Affirmer’s Copyright and
74+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
75+
maximum duration provided by applicable law or treaty (including future time
76+
extensions), (iii) in any current or future medium and for any number of
77+
copies, and (iv) for any purpose whatsoever, including without limitation
78+
commercial, advertising or promotional purposes (the “License”). The License
79+
shall be deemed effective as of the date CC0 was applied by Affirmer to the
80+
Work. Should any part of the License for any reason be judged legally
81+
invalid or ineffective under applicable law, such partial invalidity or
82+
ineffectiveness shall not invalidate the remainder of the License, and in
83+
such case Affirmer hereby affirms that he or she will not (i) exercise any
84+
of his or her remaining Copyright and Related Rights in the Work or (ii)
85+
assert any associated claims and causes of action with respect to the Work,
86+
in either case contrary to Affirmer’s express Statement of Purpose.
87+
88+
4. Limitations and Disclaimers.
89+
1. No trademark or patent rights held by Affirmer are waived, abandoned,
90+
surrendered, licensed or otherwise affected by this document.
91+
2. Affirmer offers the Work as-is and makes no representations or warranties
92+
of any kind concerning the Work, express, implied, statutory or
93+
otherwise, including without limitation warranties of title,
94+
merchantability, fitness for a particular purpose, non infringement, or
95+
the absence of latent or other defects, accuracy, or the present or
96+
absence of errors, whether or not discoverable, all to the greatest
97+
extent permissible under applicable law.
98+
3. Affirmer disclaims responsibility for clearing rights of other persons
99+
that may apply to the Work or any use thereof, including without
100+
limitation any person’s Copyright and Related Rights in the Work.
101+
Further, Affirmer disclaims responsibility for obtaining any necessary
102+
consents, permissions or other rights required for any use of the Work.
103+
4. Affirmer understands and acknowledges that Creative Commons is not a
104+
party to this document and has no duty or obligation with respect to this
105+
CC0 or use of the Work.
106+
107+
For more information, please see
108+
http://creativecommons.org/publicdomain/zero/1.0/.

0 commit comments

Comments
 (0)