@csstools/postcss-trigonometric-functions 2.0.0 → 2.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 +9 -0
- package/README.md +4 -6
- package/dist/calc.d.ts +1 -0
- package/dist/checks.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +11 -10
- package/dist/acos.d.ts +0 -4
- package/dist/asin.d.ts +0 -4
- package/dist/atan.d.ts +0 -4
- package/dist/atan2.d.ts +0 -4
- package/dist/cos.d.ts +0 -4
- package/dist/sin.d.ts +0 -4
- package/dist/tan.d.ts +0 -4
- package/dist/utils.d.ts +0 -61
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes to PostCSS Trigonometric Functions
|
|
2
2
|
|
|
3
|
+
### 2.1.0 (March 21, 2023)
|
|
4
|
+
|
|
5
|
+
- Added: `@csstools/css-calc`
|
|
6
|
+
- Added: unit conversions (`sin(30deg + (.125turn / 3))`)
|
|
7
|
+
|
|
8
|
+
### 2.0.1 (January 28, 2023)
|
|
9
|
+
|
|
10
|
+
- Improve `types` declaration in `package.json`
|
|
11
|
+
|
|
3
12
|
### 2.0.0 (January 24, 2023)
|
|
4
13
|
|
|
5
14
|
- Updated: Support for Node v14+ (major).
|
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
line-height: 0.70711;
|
|
29
29
|
line-height: 1;
|
|
30
30
|
transform: rotate(-90deg);
|
|
31
|
-
transform: rotate(
|
|
31
|
+
transform: rotate(89.99995deg);
|
|
32
32
|
transform: rotate(180deg);
|
|
33
33
|
transform: rotate(0deg);
|
|
34
34
|
transform: rotate(90deg);
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
transform: rotate(-135deg);
|
|
37
37
|
transform: rotate(-45deg);
|
|
38
38
|
transform: rotate(-45deg);
|
|
39
|
-
transform: rotate(80.
|
|
39
|
+
transform: rotate(80.53768deg);
|
|
40
40
|
}
|
|
41
41
|
```
|
|
42
42
|
|
|
@@ -127,13 +127,11 @@ postcssTrigonometricFunctions({ preserve: true })
|
|
|
127
127
|
line-height: tan(50grad);
|
|
128
128
|
transform: rotate(-90deg);
|
|
129
129
|
transform: rotate(asin(-1));
|
|
130
|
-
transform: rotate(
|
|
131
|
-
transform: rotate(asin(1));
|
|
130
|
+
transform: rotate(89.99995deg);
|
|
132
131
|
transform: rotate(asin(sin(30deg + 1.0471967rad)));
|
|
133
132
|
transform: rotate(180deg);
|
|
134
133
|
transform: rotate(acos(-1));
|
|
135
134
|
transform: rotate(0deg);
|
|
136
|
-
transform: rotate(acos(1));
|
|
137
135
|
transform: rotate(acos(cos(0 / 2 + 1 - 1)));
|
|
138
136
|
transform: rotate(90deg);
|
|
139
137
|
transform: rotate(atan(infinity));
|
|
@@ -145,7 +143,7 @@ postcssTrigonometricFunctions({ preserve: true })
|
|
|
145
143
|
transform: rotate(atan2(-infinity,infinity));
|
|
146
144
|
transform: rotate(-45deg);
|
|
147
145
|
transform: rotate(atan2(-infinity,infinity));
|
|
148
|
-
transform: rotate(80.
|
|
146
|
+
transform: rotate(80.53768deg);
|
|
149
147
|
transform: rotate(atan2(90, 15));
|
|
150
148
|
}
|
|
151
149
|
```
|
package/dist/calc.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function calc(css: string): string;
|
package/dist/checks.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const checks: string[];
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
1
|
+
"use strict";var e=require("@csstools/css-calc"),s=require("@csstools/css-parser-algorithms"),o=require("@csstools/css-tokenizer");const n=["asin(","acos(","atan(","atan2(","sin(","cos(","tan("];function calc(t){const r=o.tokenizer({css:t}),c=[];for(;!r.endOfFile();)c.push(r.nextToken());c.push(r.nextToken());const i=s.parseCommaSeparatedListOfComponentValues(c,{});let a=!1;for(let e=0;e<i.length;e++){const o=i[e];for(let e=0;e<o.length;e++){const t=o[e];if(s.isFunctionNode(t)&&n.includes(t.getName().toLowerCase()+"(")){a=!0;break}(s.isSimpleBlockNode(t)||s.isFunctionNode(t))&&t.walk(((e,o)=>{if("number"!=typeof o)return;const t=e.node;return s.isFunctionNode(t)&&n.includes(t.getName().toLowerCase()+"(")?(a=!0,!1):void 0}))}}return a?e.calcFromComponentValues(i,{precision:5,toCanonicalUnits:!0}).map((e=>e.map((e=>o.stringify(...e.tokens()))).join(""))).join(","):t}const creator=e=>{const s=Object.assign({preserve:!1},e);return{postcssPlugin:"postcss-trigonometric-functions",Declaration(e){if(!n.some((s=>e.value.toLowerCase().includes(s))))return;const o=calc(e.value);o!==e.value&&(e.cloneBefore({value:o}),s.preserve||e.remove())}}};creator.postcss=!0,module.exports=creator;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e
|
|
1
|
+
import{calcFromComponentValues as e}from"@csstools/css-calc";import{parseCommaSeparatedListOfComponentValues as s,isFunctionNode as o,isSimpleBlockNode as t}from"@csstools/css-parser-algorithms";import{tokenizer as n,stringify as r}from"@csstools/css-tokenizer";const c=["asin(","acos(","atan(","atan2(","sin(","cos(","tan("];function calc(a){const i=n({css:a}),l=[];for(;!i.endOfFile();)l.push(i.nextToken());l.push(i.nextToken());const u=s(l,{});let p=!1;for(let e=0;e<u.length;e++){const s=u[e];for(let e=0;e<s.length;e++){const n=s[e];if(o(n)&&c.includes(n.getName().toLowerCase()+"(")){p=!0;break}(t(n)||o(n))&&n.walk(((e,s)=>{if("number"!=typeof s)return;const t=e.node;return o(t)&&c.includes(t.getName().toLowerCase()+"(")?(p=!0,!1):void 0}))}}return p?e(u,{precision:5,toCanonicalUnits:!0}).map((e=>e.map((e=>r(...e.tokens()))).join(""))).join(","):a}const creator=e=>{const s=Object.assign({preserve:!1},e);return{postcssPlugin:"postcss-trigonometric-functions",Declaration(e){if(!c.some((s=>e.value.toLowerCase().includes(s))))return;const o=calc(e.value);o!==e.value&&(e.cloneBefore({value:o}),s.preserve||e.remove())}}};creator.postcss=!0;export{creator as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csstools/postcss-trigonometric-functions",
|
|
3
3
|
"description": "Use sin(), cos(), tan(), acos(), atan(), and atan2() to compute trigonometric relationships",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Antonio Laguna",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"types": "dist/index.d.ts",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
29
30
|
"import": "./dist/index.mjs",
|
|
30
31
|
"require": "./dist/index.cjs",
|
|
31
32
|
"default": "./dist/index.mjs"
|
|
@@ -38,22 +39,22 @@
|
|
|
38
39
|
"dist"
|
|
39
40
|
],
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
+
"@csstools/css-calc": "^1.0.0",
|
|
43
|
+
"@csstools/css-parser-algorithms": "^2.0.1",
|
|
44
|
+
"@csstools/css-tokenizer": "^2.0.1"
|
|
42
45
|
},
|
|
43
46
|
"peerDependencies": {
|
|
44
47
|
"postcss": "^8.4"
|
|
45
48
|
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@csstools/postcss-tape": "*"
|
|
51
|
+
},
|
|
46
52
|
"scripts": {
|
|
47
|
-
"prebuild": "npm run clean",
|
|
48
53
|
"build": "rollup -c ../../rollup/default.mjs",
|
|
49
|
-
"clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true }); fs.mkdirSync('./dist');\"",
|
|
50
54
|
"docs": "node ../../.github/bin/generate-docs/install.mjs && node ../../.github/bin/generate-docs/readme.mjs",
|
|
51
|
-
"lint": "
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"prepublishOnly": "npm run clean && npm run build && npm run test",
|
|
55
|
-
"test": "node .tape.mjs && npm run test:exports",
|
|
56
|
-
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs",
|
|
55
|
+
"lint": "node ../../.github/bin/format-package-json.mjs",
|
|
56
|
+
"prepublishOnly": "npm run build && npm run test",
|
|
57
|
+
"test": "node .tape.mjs && node ./test/_import.mjs && node ./test/_require.cjs",
|
|
57
58
|
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs"
|
|
58
59
|
},
|
|
59
60
|
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-trigonometric-functions#readme",
|
package/dist/acos.d.ts
DELETED
package/dist/asin.d.ts
DELETED
package/dist/atan.d.ts
DELETED
package/dist/atan2.d.ts
DELETED
package/dist/cos.d.ts
DELETED
package/dist/sin.d.ts
DELETED
package/dist/tan.d.ts
DELETED
package/dist/utils.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { FunctionNode, WordNode, Node } from 'postcss-value-parser';
|
|
2
|
-
export declare function turnToRad(turn: number): number;
|
|
3
|
-
export declare function degToRad(deg: number): number;
|
|
4
|
-
export declare function gradToRad(grad: number): number;
|
|
5
|
-
export declare function radToDeg(rad: number): number;
|
|
6
|
-
export declare function gradToDeg(grad: number): number;
|
|
7
|
-
export declare function turnToDeg(turn: number): number;
|
|
8
|
-
declare const toRad: {
|
|
9
|
-
turn: typeof turnToRad;
|
|
10
|
-
deg: typeof degToRad;
|
|
11
|
-
grad: typeof gradToRad;
|
|
12
|
-
};
|
|
13
|
-
declare const toDeg: {
|
|
14
|
-
grad: typeof gradToDeg;
|
|
15
|
-
turn: typeof turnToDeg;
|
|
16
|
-
rad: typeof radToDeg;
|
|
17
|
-
};
|
|
18
|
-
export declare function filterOnlyWords(node: Node): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Try to compute a calculation from a Node.
|
|
21
|
-
*
|
|
22
|
-
* This validates that the calculation has a valid order which is:
|
|
23
|
-
* - `{Number} {Operation} {Number} ...`
|
|
24
|
-
*
|
|
25
|
-
* Only basic arithmetic operations are allowed, and it has to be separate words
|
|
26
|
-
* similarly to how CSS calc works:
|
|
27
|
-
*
|
|
28
|
-
* - `sin(3.14159 * 2)` -> is valid
|
|
29
|
-
* - `sin(3.14159*2)` -> is not valid
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @param {FunctionNode} nodes Nodes to be parsed
|
|
33
|
-
* @param {Boolean} ignoreUnit Whether units are ignored or converted to radians
|
|
34
|
-
* @return {FunctionNode} Returns the node, if it managed to calculate, it will
|
|
35
|
-
* simplify inner nodes.
|
|
36
|
-
* @see https://www.w3.org/TR/css-values-4/#trig-funcs
|
|
37
|
-
*/
|
|
38
|
-
export declare function computeCalculation(nodes: Node[], ignoreUnit?: boolean): Node[];
|
|
39
|
-
export declare function functionNodeToWordNode(fn: FunctionNode): WordNode;
|
|
40
|
-
/**
|
|
41
|
-
* Formats a number that's intended to be put into CSS.
|
|
42
|
-
*
|
|
43
|
-
* Due to processing of Number(number.toFixed(decimals)) this will get
|
|
44
|
-
* rid of ending zeroes, usually helping with the rounding which is the
|
|
45
|
-
* intended effect.
|
|
46
|
-
*
|
|
47
|
-
* For example, converting 4.71238898038469 radians into deg leads to
|
|
48
|
-
* 270.000000000669786 which is going to result as 270 unless a
|
|
49
|
-
* precision of 10 is chosen.
|
|
50
|
-
*
|
|
51
|
-
* @param {Number} number Number to be formatted
|
|
52
|
-
* @param {Number} decimals Precision of decimals, CSS doesn't usually handle further than 5.
|
|
53
|
-
*/
|
|
54
|
-
export declare function formatResultingNumber(number: number, decimals: number): string;
|
|
55
|
-
export declare function parseNumber(value: string): false | {
|
|
56
|
-
number: any;
|
|
57
|
-
unit: string;
|
|
58
|
-
};
|
|
59
|
-
type validateNodeReturn = [WordNode, number] | undefined;
|
|
60
|
-
export declare function validateNode(node: FunctionNode, parseUnit?: boolean): validateNodeReturn;
|
|
61
|
-
export { toRad, toDeg };
|