@csstools/postcss-trigonometric-functions 1.0.2 → 2.0.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 +8 -0
- package/README.md +8 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changes to PostCSS Trigonometric Functions
|
|
2
2
|
|
|
3
|
+
### 2.0.1 (January 28, 2023)
|
|
4
|
+
|
|
5
|
+
- Improve `types` declaration in `package.json`
|
|
6
|
+
|
|
7
|
+
### 2.0.0 (January 24, 2023)
|
|
8
|
+
|
|
9
|
+
- Updated: Support for Node v14+ (major).
|
|
10
|
+
|
|
3
11
|
### 1.0.2 (July 8, 2022)
|
|
4
12
|
|
|
5
13
|
- Fix case insensitive matching.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# PostCSS Trigonometric Functions [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][
|
|
1
|
+
# PostCSS Trigonometric Functions [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][PostCSS]
|
|
2
2
|
|
|
3
3
|
[<img alt="npm version" src="https://img.shields.io/npm/v/@csstools/postcss-trigonometric-functions.svg" height="20">][npm-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/trigonometric-functions.svg" height="20">][css-url] [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url] [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|
4
4
|
|
|
@@ -62,8 +62,13 @@ postcss([
|
|
|
62
62
|
[PostCSS Trigonometric Functions] runs in all Node environments, with special
|
|
63
63
|
instructions for:
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
- [Node](INSTALL.md#node)
|
|
66
|
+
- [PostCSS CLI](INSTALL.md#postcss-cli)
|
|
67
|
+
- [PostCSS Load Config](INSTALL.md#postcss-load-config)
|
|
68
|
+
- [Webpack](INSTALL.md#webpack)
|
|
69
|
+
- [Next.js](INSTALL.md#nextjs)
|
|
70
|
+
- [Gulp](INSTALL.md#gulp)
|
|
71
|
+
- [Grunt](INSTALL.md#grunt)
|
|
67
72
|
|
|
68
73
|
## ⚠️ About custom properties
|
|
69
74
|
|
|
@@ -150,9 +155,6 @@ postcssTrigonometricFunctions({ preserve: true })
|
|
|
150
155
|
[discord]: https://discord.gg/bUadyRwkJS
|
|
151
156
|
[npm-url]: https://www.npmjs.com/package/@csstools/postcss-trigonometric-functions
|
|
152
157
|
|
|
153
|
-
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|
154
|
-
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|
155
158
|
[PostCSS]: https://github.com/postcss/postcss
|
|
156
|
-
[PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|
157
159
|
[PostCSS Trigonometric Functions]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-trigonometric-functions
|
|
158
160
|
[CSS Values 4]: https://www.w3.org/TR/css-values-4/#trig-funcs
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=require("postcss-value-parser"),t=require("vm");function radToDeg(e){return e*(180/Math.PI)}const n={turn:function turnToRad(e){return 2*e*Math.PI},deg:function degToRad(e){return e*(Math.PI/180)},grad:function gradToRad(e){return e*(Math.PI/200)}};function filterOnlyWords(e){return"word"===e.type}const r=["+","-","*","/"];var u;function isFiniteNumber(e){return!Number.isNaN(e)&&Number.isFinite(e)}function computeCalculation(o,i=!1){let a=!0;const s=[];if(o.filter((e=>"function"===e.type)).forEach((e=>{var t;if(!a)return;if(""!==e.value)return void(a=!1);const n=computeCalculation(e.nodes.slice(0),i),r=1===n.length,u=Number((null==(t=n[0])?void 0:t.value)||"");r&&"word"===n[0].type&&!Number.isNaN(u)?(functionNodeToWordNode(e),e.value=n[0].value):a=!1})),!a)return o;const l=o.filter((e=>"word"===e.type||r.includes(e.value)));let c=u.Number;const f=[];let m;const addToExpression=(e,t,n)=>{if(c===t){if(t===u.Number){const t=n||"";f.includes(t)||f.push({number:e,unit:t,index:s.length})}s.push(e),c=t===u.Number?u.Operation:u.Number}else a=!1};for(let t=0,o=l.length;t<o&&a;t++){const o=l[t];if(r.includes(o.value)){addToExpression(o.value,u.Operation);continue}if("pi"===o.value){addToExpression(Math.PI.toString(),u.Number);continue}if("e"===o.value){addToExpression(Math.E.toString(),u.Number);continue}const s=e.unit(o.value);if(!s){a=!1;break}if(i){if(m||(m=s.unit),m!==s.unit){a=!1;break}addToExpression(o.value,u.Operation)}else s.unit?"rad"!==s.unit&&"function"!=typeof n[s.unit]?a=!1:addToExpression(s.number,u.Number,s.unit):addToExpression(o.value,u.Number)}if(!a)return o;if(s.length%2==0||s.length<3)return o;let d;try{let e="";const r=new Set(f.map((e=>e.unit)));if(r.size>1)if(r.has("")){if(2!==r.size)throw new Error;[e]=Array.from(r).filter((e=>""!==e))}else f.forEach((e=>{if("rad"!==e.unit){const t=n[e.unit](Number(e.number));if(!isFiniteNumber(t))throw new Error;s[e.index]=t.toString()}}));const u=t.createContext({result:NaN});new t.Script(`result = ${s.join(" ")}`).runInContext(u),"number"==typeof u.result&&isFiniteNumber(u.result)&&(e&&(u.result=n[e](u.result)),isFiniteNumber(u.result)&&(d=u.result))}catch(e){}if(void 0!==d){let e=d.toString();m&&(e+=m);const t=o[0].sourceIndex,n=e.length;o.length=0,o.push({type:"word",value:e,sourceIndex:t,sourceEndIndex:n})}return o}function functionNodeToWordNode(e){delete e.nodes;const t=e;return t.type="word",t}function formatResultingNumber(e,t){if(!Number.isNaN(e)){if(e>Number.MAX_SAFE_INTEGER)return"infinity";if(e<Number.MIN_SAFE_INTEGER)return"-infinity"}return Number(e.toFixed(t)).toString()}function parseNumber(t){let n,r="";if("infinity"===t.toLowerCase()?n=1/0:"-infinity"===t.toLowerCase()?n=-1/0:"pi"===t?n=Math.PI:"e"===t&&(n=Math.E),!n){const u=e.unit(t);if(!u)return!1;n=Number(u.number),Number.isNaN(n)||(r=u.unit)}return{number:n,unit:r}}function validateNode(e,t=!0){e.nodes=computeCalculation(e.nodes);const r=e.nodes.filter(filterOnlyWords);if(1!==e.nodes.length||1!==r.length)return;const{value:u}=r[0],o=parseNumber(u);if(!o)return;let i=o.number;if(t){if(o.unit&&"rad"!==o.unit){if(!n[o.unit])return;i=n[o.unit](i)}}else if(o.unit)return;return[functionNodeToWordNode(e),i]}!function(e){e[e.Number=0]="Number",e[e.Operation=1]="Operation"}(u||(u={}));const o=[{check:"asin(",transform:function transformAsinFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"asin"!==e.value.toLowerCase())return;const t=validateNode(e,!1);if(!t)return;const[n,r]=t;let u=Math.asin(r);Number.isNaN(u)||"number"!=typeof u||(u=`${formatResultingNumber(radToDeg(u),2)}deg`),n.value=u+""}),!0),n.toString()}},{check:"acos(",transform:function transformAcosFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"acos"!==e.value.toLowerCase())return;const t=validateNode(e,!1);if(!t)return;const[n,r]=t;let u=Math.acos(r);Number.isNaN(u)||"number"!=typeof u||(u=`${formatResultingNumber(radToDeg(u),2)}deg`),n.value=u+""}),!0),n.toString()}},{check:"atan(",transform:function transformAtanFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"atan"!==e.value.toLowerCase())return;const t=validateNode(e,!1);if(!t)return;const[n,r]=t;let u=Math.atan(r);Number.isNaN(u)||"number"!=typeof u||(u=`${formatResultingNumber(radToDeg(u),2)}deg`),n.value=u+""}),!0),n.toString()}},{check:"atan2(",transform:function transformAtan2Function(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"atan2"!==e.value.toLowerCase())return;const t=e.nodes.findIndex((e=>"div"===e.type&&","===e.value));if(t<0)return;let n=e.nodes.slice(0,t).filter(filterOnlyWords),r=e.nodes.slice(t+1).filter(filterOnlyWords);if(0===n.length||0===r.length)return;if(n.length>1&&(n=computeCalculation(n,!0)),r.length>1&&(r=computeCalculation(r,!0)),1!==n.length||1!==r.length)return;const u=parseNumber(n[0].value),o=parseNumber(r[0].value);if(!u||!o)return;if(u.unit!==o.unit)return;let i=Math.atan2(u.number,o.number);Number.isNaN(i)||"number"!=typeof i||(i=`${formatResultingNumber(radToDeg(i),2)}deg`);functionNodeToWordNode(e).value=i+""}),!0),n.toString()}},{check:"sin(",transform:function transformSinFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"sin"!==e.value.toLowerCase())return;const t=validateNode(e);if(!t)return;const[n,r]=t;n.value=formatResultingNumber(Math.sin(r),5)}),!0),n.toString()}},{check:"cos(",transform:function transformCosFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"cos"!==e.value.toLowerCase())return;const t=validateNode(e);if(!t)return;const[n,r]=t;n.value=formatResultingNumber(Math.cos(r),5)}),!0),n.toString()}},{check:"tan(",transform:function transformTanFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"tan"!==e.value.toLowerCase())return;const t=validateNode(e);if(!t)return;const[n,r]=t,u=Number(formatResultingNumber(radToDeg(r),2)),o=u/90;n.value=u%90==0&&o%2!=0?o>0?"infinity":"-infinity":formatResultingNumber(Math.tan(r),5)}),!0),n.toString()}}],creator=e=>{const t=Object.assign({preserve:!1},e);return{postcssPlugin:"postcss-trigonometric-functions",Declaration(e){const n=o.filter((t=>e.value.toLowerCase().includes(t.check)));if(!e||0===n.length)return;const r=e.clone();n.forEach((e=>{const t=e.transform(r);t&&(r.value=t)})),e.value!==r.value&&(e.before(r),t.preserve||e.remove())}}};creator.postcss=!0,module.exports=creator;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { PluginCreator } from 'postcss';
|
|
2
|
-
|
|
2
|
+
/** postcss-trigonometric-functions plugin options */
|
|
3
|
+
export type pluginOptions = {
|
|
4
|
+
/** Preserve the original notation. default: false */
|
|
3
5
|
preserve?: boolean;
|
|
4
6
|
};
|
|
5
7
|
declare const creator: PluginCreator<pluginOptions>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from"postcss-value-parser";import t from"vm";function radToDeg(e){return e*(180/Math.PI)}const n={turn:function turnToRad(e){return 2*e*Math.PI},deg:function degToRad(e){return e*(Math.PI/180)},grad:function gradToRad(e){return e*(Math.PI/200)}};function filterOnlyWords(e){return"word"===e.type}const r=["+","-","*","/"];var o;function isFiniteNumber(e){return!Number.isNaN(e)&&Number.isFinite(e)}function computeCalculation(u,i=!1){let a=!0;const s=[];if(u.filter((e=>"function"===e.type)).forEach((e=>{var t;if(!a)return;if(""!==e.value)return void(a=!1);const n=computeCalculation(e.nodes.slice(0),i),r=1===n.length,o=Number((null==(t=n[0])?void 0:t.value)||"");r&&"word"===n[0].type&&!Number.isNaN(o)?(functionNodeToWordNode(e),e.value=n[0].value):a=!1})),!a)return u;const l=u.filter((e=>"word"===e.type||r.includes(e.value)));let c=o.Number;const f=[];let m;const addToExpression=(e,t,n)=>{if(c===t){if(t===o.Number){const t=n||"";f.includes(t)||f.push({number:e,unit:t,index:s.length})}s.push(e),c=t===o.Number?o.Operation:o.Number}else a=!1};for(let t=0,u=l.length;t<u&&a;t++){const u=l[t];if(r.includes(u.value)){addToExpression(u.value,o.Operation);continue}if("pi"===u.value){addToExpression(Math.PI.toString(),o.Number);continue}if("e"===u.value){addToExpression(Math.E.toString(),o.Number);continue}const s=e.unit(u.value);if(!s){a=!1;break}if(i){if(m||(m=s.unit),m!==s.unit){a=!1;break}addToExpression(u.value,o.Operation)}else s.unit?"rad"!==s.unit&&"function"!=typeof n[s.unit]?a=!1:addToExpression(s.number,o.Number,s.unit):addToExpression(u.value,o.Number)}if(!a)return u;if(s.length%2==0||s.length<3)return u;let d;try{let e="";const r=new Set(f.map((e=>e.unit)));if(r.size>1)if(r.has("")){if(2!==r.size)throw new Error;[e]=Array.from(r).filter((e=>""!==e))}else f.forEach((e=>{if("rad"!==e.unit){const t=n[e.unit](Number(e.number));if(!isFiniteNumber(t))throw new Error;s[e.index]=t.toString()}}));const o=t.createContext({result:NaN});new t.Script(`result = ${s.join(" ")}`).runInContext(o),"number"==typeof o.result&&isFiniteNumber(o.result)&&(e&&(o.result=n[e](o.result)),isFiniteNumber(o.result)&&(d=o.result))}catch(e){}if(void 0!==d){let e=d.toString();m&&(e+=m);const t=u[0].sourceIndex,n=e.length;u.length=0,u.push({type:"word",value:e,sourceIndex:t,sourceEndIndex:n})}return u}function functionNodeToWordNode(e){delete e.nodes;const t=e;return t.type="word",t}function formatResultingNumber(e,t){if(!Number.isNaN(e)){if(e>Number.MAX_SAFE_INTEGER)return"infinity";if(e<Number.MIN_SAFE_INTEGER)return"-infinity"}return Number(e.toFixed(t)).toString()}function parseNumber(t){let n,r="";if("infinity"===t.toLowerCase()?n=1/0:"-infinity"===t.toLowerCase()?n=-1/0:"pi"===t?n=Math.PI:"e"===t&&(n=Math.E),!n){const o=e.unit(t);if(!o)return!1;n=Number(o.number),Number.isNaN(n)||(r=o.unit)}return{number:n,unit:r}}function validateNode(e,t=!0){e.nodes=computeCalculation(e.nodes);const r=e.nodes.filter(filterOnlyWords);if(1!==e.nodes.length||1!==r.length)return;const{value:o}=r[0],u=parseNumber(o);if(!u)return;let i=u.number;if(t){if(u.unit&&"rad"!==u.unit){if(!n[u.unit])return;i=n[u.unit](i)}}else if(u.unit)return;return[functionNodeToWordNode(e),i]}!function(e){e[e.Number=0]="Number",e[e.Operation=1]="Operation"}(o||(o={}));const u=[{check:"asin(",transform:function transformAsinFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"asin"!==e.value.toLowerCase())return;const t=validateNode(e,!1);if(!t)return;const[n,r]=t;let o=Math.asin(r);Number.isNaN(o)||"number"!=typeof o||(o=`${formatResultingNumber(radToDeg(o),2)}deg`),n.value=o+""}),!0),n.toString()}},{check:"acos(",transform:function transformAcosFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"acos"!==e.value.toLowerCase())return;const t=validateNode(e,!1);if(!t)return;const[n,r]=t;let o=Math.acos(r);Number.isNaN(o)||"number"!=typeof o||(o=`${formatResultingNumber(radToDeg(o),2)}deg`),n.value=o+""}),!0),n.toString()}},{check:"atan(",transform:function transformAtanFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"atan"!==e.value.toLowerCase())return;const t=validateNode(e,!1);if(!t)return;const[n,r]=t;let o=Math.atan(r);Number.isNaN(o)||"number"!=typeof o||(o=`${formatResultingNumber(radToDeg(o),2)}deg`),n.value=o+""}),!0),n.toString()}},{check:"atan2(",transform:function transformAtan2Function(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"atan2"!==e.value.toLowerCase())return;const t=e.nodes.findIndex((e=>"div"===e.type&&","===e.value));if(t<0)return;let n=e.nodes.slice(0,t).filter(filterOnlyWords),r=e.nodes.slice(t+1).filter(filterOnlyWords);if(0===n.length||0===r.length)return;if(n.length>1&&(n=computeCalculation(n,!0)),r.length>1&&(r=computeCalculation(r,!0)),1!==n.length||1!==r.length)return;const o=parseNumber(n[0].value),u=parseNumber(r[0].value);if(!o||!u)return;if(o.unit!==u.unit)return;let i=Math.atan2(o.number,u.number);Number.isNaN(i)||"number"!=typeof i||(i=`${formatResultingNumber(radToDeg(i),2)}deg`);functionNodeToWordNode(e).value=i+""}),!0),n.toString()}},{check:"sin(",transform:function transformSinFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"sin"!==e.value.toLowerCase())return;const t=validateNode(e);if(!t)return;const[n,r]=t;n.value=formatResultingNumber(Math.sin(r),5)}),!0),n.toString()}},{check:"cos(",transform:function transformCosFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"cos"!==e.value.toLowerCase())return;const t=validateNode(e);if(!t)return;const[n,r]=t;n.value=formatResultingNumber(Math.cos(r),5)}),!0),n.toString()}},{check:"tan(",transform:function transformTanFunction(t){const n=e(t.value);return n.walk((e=>{if("function"!==e.type||"tan"!==e.value.toLowerCase())return;const t=validateNode(e);if(!t)return;const[n,r]=t,o=Number(formatResultingNumber(radToDeg(r),2)),u=o/90;n.value=o%90==0&&u%2!=0?u>0?"infinity":"-infinity":formatResultingNumber(Math.tan(r),5)}),!0),n.toString()}}],creator=e=>{const t=Object.assign({preserve:!1},e);return{postcssPlugin:"postcss-trigonometric-functions",Declaration(e){const n=u.filter((t=>e.value.toLowerCase().includes(t.check)));if(!e||0===n.length)return;const r=e.clone();n.forEach((e=>{const t=e.transform(r);t&&(r.value=t)})),e.value!==r.value&&(e.before(r),t.preserve||e.remove())}}};creator.postcss=!0;export{creator as default};
|
package/dist/utils.d.ts
CHANGED
|
@@ -56,6 +56,6 @@ export declare function parseNumber(value: string): false | {
|
|
|
56
56
|
number: any;
|
|
57
57
|
unit: string;
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
type validateNodeReturn = [WordNode, number] | undefined;
|
|
60
60
|
export declare function validateNode(node: FunctionNode, parseUnit?: boolean): validateNodeReturn;
|
|
61
61
|
export { toRad, toDeg };
|
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": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Antonio Laguna",
|
|
@@ -19,13 +19,14 @@
|
|
|
19
19
|
"url": "https://opencollective.com/csstools"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": "^14 || >=
|
|
22
|
+
"node": "^14 || ^16 || >=18"
|
|
23
23
|
},
|
|
24
24
|
"main": "dist/index.cjs",
|
|
25
25
|
"module": "dist/index.mjs",
|
|
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"
|
|
@@ -41,11 +42,12 @@
|
|
|
41
42
|
"postcss-value-parser": "^4.2.0"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
|
-
"postcss": "^8.
|
|
45
|
+
"postcss": "^8.4"
|
|
45
46
|
},
|
|
46
47
|
"scripts": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
48
|
+
"prebuild": "npm run clean",
|
|
49
|
+
"build": "rollup -c ../../rollup/default.mjs",
|
|
50
|
+
"clean": "node -e \"fs.rmSync('./dist', { recursive: true, force: true }); fs.mkdirSync('./dist');\"",
|
|
49
51
|
"docs": "node ../../.github/bin/generate-docs/install.mjs && node ../../.github/bin/generate-docs/readme.mjs",
|
|
50
52
|
"lint": "npm run lint:eslint && npm run lint:package-json",
|
|
51
53
|
"lint:eslint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
|