Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@csstools/postcss-trigonometric-functions
Advanced tools
Use sin(), cos(), tan(), acos(), atan(), and atan2() to compute trigonometric relationships
@csstools/postcss-trigonometric-functions is a PostCSS plugin that allows you to use trigonometric functions like sine, cosine, and tangent directly in your CSS. This can be particularly useful for creating complex animations, responsive designs, and other dynamic styles that require mathematical calculations.
Sine Function
This feature allows you to use the sine function in your CSS. In this example, the sine of 45 degrees is calculated and used to translate an element along the X-axis.
body {
--angle: 45deg;
--sine-value: sin(var(--angle));
transform: translateX(calc(100px * var(--sine-value)));
}
Cosine Function
This feature allows you to use the cosine function in your CSS. In this example, the cosine of 45 degrees is calculated and used to translate an element along the Y-axis.
body {
--angle: 45deg;
--cosine-value: cos(var(--angle));
transform: translateY(calc(100px * var(--cosine-value)));
}
Tangent Function
This feature allows you to use the tangent function in your CSS. In this example, the tangent of 45 degrees is calculated and used to skew an element along the X-axis.
body {
--angle: 45deg;
--tangent-value: tan(var(--angle));
transform: skewX(calc(10deg * var(--tangent-value)));
}
postcss-math is a PostCSS plugin that allows you to perform mathematical operations in your CSS. It supports basic arithmetic, trigonometric functions, and more. Compared to @csstools/postcss-trigonometric-functions, postcss-math offers a broader range of mathematical operations but may not be as specialized in trigonometric functions.
postcss-calc is a PostCSS plugin that reduces calc() references whenever possible. While it doesn't specifically focus on trigonometric functions, it can simplify complex calculations in your CSS. It is more general-purpose compared to @csstools/postcss-trigonometric-functions.
npm install @csstools/postcss-trigonometric-functions --save-dev
PostCSS Trigonometric Functions lets you use sin
, cos
, tan
, asin
, acos
, atan
and atan2
to be able to compute trigonometric relationships following the CSS Values 4 specification.
.trigonometry {
line-height: sin(pi / 4);
line-height: cos(.125turn);
line-height: tan(50grad);
transform: rotate(asin(-1));
transform: rotate(asin(sin(30deg + 1.0471967rad)));
transform: rotate(acos(-1));
transform: rotate(acos(cos(0 / 2 + 1 - 1)));
transform: rotate(atan(infinity));
transform: rotate(atan(e - 2.7182818284590452354));
transform: rotate(atan2(-infinity,-infinity));
transform: rotate(atan2(-infinity,infinity));
transform: rotate(atan2(-infinity,infinity));
transform: rotate(atan2(90, 15));
}
/* becomes */
.trigonometry {
line-height: 0.70711;
line-height: 0.70711;
line-height: 1;
transform: rotate(-90deg);
transform: rotate(89.99995deg);
transform: rotate(180deg);
transform: rotate(0deg);
transform: rotate(90deg);
transform: rotate(0deg);
transform: rotate(-135deg);
transform: rotate(-45deg);
transform: rotate(-45deg);
transform: rotate(80.53768deg);
}
Add PostCSS Trigonometric Functions to your project:
npm install postcss @csstools/postcss-trigonometric-functions --save-dev
Use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssTrigonometricFunctions = require('@csstools/postcss-trigonometric-functions');
postcss([
postcssTrigonometricFunctions(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
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.
Because of that, any usage that contains a var
is skipped.
PostCSS Trigonometric Functions lets you use different special units that are within the spec and computed at run time to be able to calculate the result of the trigonometric function.
The following units are supported:
pi
: Computes to Math.PI
which is 3.141592653589793
e
: Computes to Math.E
which is 2.718281828459045
infinity
, -infinity
: Compute to Infinity
and -Infinity
respectively. Note that the usage is case insensitive so InFiNiTy
is a valid value.Some calculations (such as sin(-infinity)
) might return NaN
as per the spec. Given that NaN
can't be replaced with a value that's useful to CSS it is left as is, as the result will be effectively ignored by the browser.
The preserve
option determines whether the original notation
is preserved. By default, it is not preserved.
postcssTrigonometricFunctions({ preserve: true })
.trigonometry {
line-height: sin(pi / 4);
line-height: cos(.125turn);
line-height: tan(50grad);
transform: rotate(asin(-1));
transform: rotate(asin(sin(30deg + 1.0471967rad)));
transform: rotate(acos(-1));
transform: rotate(acos(cos(0 / 2 + 1 - 1)));
transform: rotate(atan(infinity));
transform: rotate(atan(e - 2.7182818284590452354));
transform: rotate(atan2(-infinity,-infinity));
transform: rotate(atan2(-infinity,infinity));
transform: rotate(atan2(-infinity,infinity));
transform: rotate(atan2(90, 15));
}
/* becomes */
.trigonometry {
line-height: 0.70711;
line-height: sin(pi / 4);
line-height: 0.70711;
line-height: cos(.125turn);
line-height: 1;
line-height: tan(50grad);
transform: rotate(-90deg);
transform: rotate(asin(-1));
transform: rotate(89.99995deg);
transform: rotate(asin(sin(30deg + 1.0471967rad)));
transform: rotate(180deg);
transform: rotate(acos(-1));
transform: rotate(0deg);
transform: rotate(acos(cos(0 / 2 + 1 - 1)));
transform: rotate(90deg);
transform: rotate(atan(infinity));
transform: rotate(0deg);
transform: rotate(atan(e - 2.7182818284590452354));
transform: rotate(-135deg);
transform: rotate(atan2(-infinity,-infinity));
transform: rotate(-45deg);
transform: rotate(atan2(-infinity,infinity));
transform: rotate(-45deg);
transform: rotate(atan2(-infinity,infinity));
transform: rotate(80.53768deg);
transform: rotate(atan2(90, 15));
}
FAQs
Use sin(), cos(), tan(), acos(), atan(), and atan2() to compute trigonometric relationships
The npm package @csstools/postcss-trigonometric-functions receives a total of 3,468,504 weekly downloads. As such, @csstools/postcss-trigonometric-functions popularity was classified as popular.
We found that @csstools/postcss-trigonometric-functions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.