{"name":"postcss-calc","version":"11.1.1","keywords":["css","postcss","postcss-plugin","calculation","calc"],"author":"Andy Jansson","license":"MIT","_id":"postcss-calc@11.1.1","maintainers":[{"name":"beneb","email":"beneb.info@gmail.com"},{"name":"moox","email":"npm@moox.io"},{"name":"ludovicofischer","email":"livrerie@gmail.com"},{"name":"semigradsky","email":"semigradskyd@gmail.com"},{"name":"jonathantneal","email":"jonathantneal@hotmail.com"},{"name":"andyjansson","email":"jansson.andy@gmail.com"},{"name":"evilebottnawi","email":"sheo13666q@gmail.com"}],"homepage":"https://github.com/postcss/postcss-calc","dist":{"shasum":"14fc77f5afc9051b8694f6f55c4291ceeb341c28","tarball":"http://registry-npm.ywwl.com/postcss-calc/download/postcss-calc-11.1.1.tgz","fileCount":59,"integrity":"sha512-EazB2CtQwKoBOCi8l334i/gnaObqcv418pLTvw4CmcqPLhPgP8IipVSixQO7lTRDrOBIwL72krecBfi5tpl4EA==","signatures":[{"sig":"MEUCIBMokM2ae3wqomRmqpRNIn2NAR4pMM6Qt2rIT51UZul4AiEAgozlQr7m6+DTGDo1pYfFGB8fd63yVbmpcA+Zv6YrqZA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/postcss-calc@11.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":96431,"size":29023,"noattachment":false,"key":"/postcss-calc/-/postcss-calc-11.1.1.tgz"},"type":"module","engines":{"node":"^22.22.3 || ^24.15 || >=26.0"},"exports":{".":{"types":"./types/index.d.ts","default":"./src/index.js"},"./reduce":{"types":"./types/reduce.d.ts","default":"./src/reduce.js"}},"scripts":{"fmt":"oxfmt","lint":"oxlint . && tsc && oxfmt --check","test":"node --test --test-reporter=dot 'test/**/*.test.mjs' test/index.cjs test/convertUnit.cjs","test:corpus:full":"POSTCSS_CALC_FULL_CORPUS=1 node --test test/conformance/corpus.test.mjs","test:mutation:corpus":"node test/mutation/corpus-selection.mjs","benchmark:arithmetic-chains":"node scripts/benchmark-arithmetic-chains.mjs"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","approver":{"name":"ludovicofischer","email":"livrerie@gmail.com"},"trustedPublisher":{"id":"github","oidcConfigId":"oidc:12fec003-011d-4ec1-bc80-f6b0007d9e4b"}},"devEngines":{"packageManager":{"name":"pnpm","version":"11.25.0"}},"repository":{"url":"git+https://github.com/postcss/postcss-calc.git","type":"git"},"description":"PostCSS plugin to reduce calc()","directories":{},"_nodeVersion":"26.0.0","dependencies":{"@csstools/css-tokenizer":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"oxfmt":"^0.66.0","oxlint":"^1.81.0","postcss":"^8.5.28","fast-check":"^4.9.0","typescript":"~7.0.2","@types/node":"^26.4.1","@csstools/css-calc":"^3.3.0","@rmenke/css-tokenizer-tests":"^1.2.0"},"peerDependencies":{"postcss":"^8.5.28"},"_npmOperationalInternal":{"tmp":"tmp/postcss-calc_11.1.1_1788791604248_0.7265969974029798","host":"s3://npm-registry-packages-npm-production"},"readme":"# PostCSS Calc [<img src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS\" width=\"90\" height=\"90\" align=\"right\">][PostCSS]\n\n[![NPM Version][npm-img]][npm-url]\n[![Support Chat][git-img]][git-url]\n\n[PostCSS Calc] lets you reduce `calc()` references whenever it's possible.\nWhen multiple units are mixed together in the same expression, the `calc()`\nstatement is left as is, to fallback to the [W3C calc() implementation].\n\n## Installation\n\n```bash\nnpm install postcss-calc\n```\n\n## PostCSS usage\n\n```js\n// dependencies\nvar fs = require('fs');\nvar postcss = require('postcss');\nvar calc = require('postcss-calc');\n\n// css to be processed\nvar css = fs.readFileSync('input.css', 'utf8');\n\n// process css\nvar output = postcss().use(calc()).process(css).css;\n```\n\nUsing this `input.css`:\n\n```css\nh1 {\n  font-size: calc(16px * 2);\n  height: calc(100px - 2em);\n  width: calc(2 * var(--base-width));\n  margin-bottom: calc(16px * 1.5);\n}\n```\n\nyou will get:\n\n```css\nh1 {\n  font-size: 32px;\n  height: calc(100px - 2em);\n  width: calc(2 * var(--base-width));\n  margin-bottom: 24px;\n}\n```\n\nCheckout [tests] for more examples.\n\n## Use the reducer without PostCSS\n\nFor a single CSS component-value string, import the dedicated reducer entry\npoint. It reduces `calc()` and the supported CSS math functions it finds while\nleaving all other text untouched.\n\n```js\nimport reduceCalc from 'postcss-calc/reduce';\n\nreduceCalc('calc(1in + 10px)');\n// => '1.10417in'\n\nreduceCalc('min(50px, calc(2 * 40px))');\n// => '50px'\n```\n\nIt accepts `precision`, `unwrapSingleNegativeNumber`, `warnWhenCannotResolve`, `onParseError`,\nand `onWarn`:\n\n```js\nconst result = reduceCalc('calc(100% + var(--gap))', {\n  precision: false,\n  warnWhenCannotResolve: true,\n  onWarn: console.warn,\n  onParseError(error, input) {\n    console.error(`Invalid calculation: ${input}`, error);\n  },\n});\n```\n\nUnlike the PostCSS plugin, the standalone reducer does not show warnings\nby default; provide `onParseError` and/or `onWarn` if you want diagnostics.\n\n### Standalone reducer options\n\n#### `unwrapSingleNegativeNumber` (default: `false`)\n\nControls whether a finite negative result is serialized as a bare value or\nwrapped in `calc()`. Keep the default when reducing declaration values; set it\nto `true` when the surrounding CSS context requires a bare negative value, such\nas a selector:\n\n```js\nreduceCalc('calc(5px - 10px)');\n// => 'calc(-5px)'\n\nreduceCalc('calc(5px - 10px)', { unwrapNegativeNumbers: true });\n// => '-5px'\n```\n\n### PostCSS plugin options\n\nThese options apply when using the PostCSS plugin:\n\n```js\npostcss().use(calc({ precision: 10 }));\n```\n\n#### `precision` (default: `5`)\n\nAllows you to define the precision for decimal numbers. Set it to `false` to\ndisable rounding.\n\n```js\nvar out = postcss()\n  .use(calc({ precision: 10 }))\n  .process(css).css;\n```\n\n#### `warnWhenCannotResolve` (default: `false`)\n\nAdds warnings when calc() are not reduced to a single value.\n\n```js\nvar out = postcss()\n  .use(calc({ warnWhenCannotResolve: true }))\n  .process(css).css;\n```\n\n#### `mediaQueries` (default: `false`)\n\nAllows calc() usage in media query parameters.\n\n```js\nvar out = postcss()\n  .use(calc({ mediaQueries: true }))\n  .process(css).css;\n```\n\nExample:\n\n```css\n@media (min-width: calc(100px + 100px)) {\n  div {\n    width: 100px;\n  }\n}\n```\n\nWith `mediaQueries: true`, this becomes:\n\n```css\n@media (min-width: 200px) {\n  div {\n    width: 100px;\n  }\n}\n```\n\n#### `selectors` (default: `false`)\n\nReduces `calc()` functions found in selectors. Selectors do not accept\n`calc()` functions, so the plugin replaces them with their reduced values.\nFinite negative results are serialized as bare values because a selector cannot\ncontain a `calc()` function; the plugin enables `unwrapSingleNegativeNumber` automatically\nfor selectors.\n\n```js\nvar out = postcss()\n  .use(calc({ selectors: true }))\n  .process(css).css;\n```\n\nExample:\n\n```css\ndiv:nth-child(calc(1 + 2)) {\n  width: 100px;\n}\n```\n\nWith `selectors: true`, this becomes `div:nth-child(3)`.\n\n#### `onParseError`\n\nCallback invoked when a `calc()` body fails to parse or simplify. Matches\n[`@csstools/css-calc`][csstools-css-calc]'s shape:\n\n```js\npostcss().use(\n  calc({\n    onParseError: (err, input) => {\n      throw err; // or log, route to a different channel, etc.\n    },\n  })\n);\n```\n\nWhen omitted, errors are reported via PostCSS `result.warn()` so the\nplugin never throws at the postcss level.\n\n### Behavior differences from the legacy parser\n\nThe legacy [jison][jison]-generated parser was replaced by a hand-written\nPratt parser whose simplifier follows [CSS Values 4][css-values-4]. Most\ninputs reduce to identical output; the differences are spec-aligned or\ncanonical-form decisions:\n\n- **Strict whitespace (§10.1).** `calc(2px+3px)` is invalid CSS (binary\n  `+` / `-` require surrounding whitespace) and is preserved with a\n  warning instead of reduced.\n- **Canonical operand order.** Commutative operands serialize\n  numeric-first, matching [`@csstools/css-calc`][csstools-css-calc]:\n  `calc(var(--foo) + 10px)` → `calc(10px + var(--foo))`.\n- **Zero buckets are kept.** `calc(100px - (100px - 100%))` →\n  `calc(0px + 100%)`, not `100%` — [WPT calc-serialization-002][wpt-calc-serialization]\n  requires the zero term because it carries the length-percentage type.\n- **Constant folding.** `calc(43 + pi)` now folds to `46.14159` (§10.7.1).\n  Previously `pi` / `e` stayed symbolic.\n- **Reciprocal conversion.** `calc(var(--x) / 2)` becomes\n  `calc(var(--x) * 0.5)`. The two are mathematically equivalent;\n  previously the division shape was kept.\n- **Distributive multiplication.** `calc(0.5 * (100vw - 10px))` becomes\n  `calc(50vw - 5px)`.\n- **Unit case normalization.** `2PX` becomes `2px` (CSS units are case-\n  insensitive; lowercase is conventional).\n- **Calc unwrap (§10.6).** `calc(var(--foo))` becomes `var(--foo)` — a\n  `calc()` containing a single value is replaced by that value.\n- **Spec-style spaced operators.** `2px*var(--x)` is serialized as\n  `2px * var(--x)`. The tokenizer is unaffected; only output spacing\n  differs.\n- **Division by zero / by a unit.** `calc(500px/0)` reduces to\n  `calc(infinity * 1px)` (§10.13) instead of throwing. Use `onParseError`\n  if you want validation behavior.\n\n[css-values-4]: https://www.w3.org/TR/css-values-4/\n[csstools-css-calc]: https://www.npmjs.com/package/@csstools/css-calc\n[wpt-calc-serialization]: https://github.com/web-platform-tests/wpt/blob/master/css/css-values/calc-serialization-002.html\n[jison]: https://github.com/zaach/jison\n\n---\n\n## Related PostCSS plugins\n\nTo replace the value of CSS custom properties at build time, try [PostCSS Custom Properties].\n\n## Contributing\n\nWork on a branch, install dev-dependencies, respect coding style & run tests\nbefore submitting a bug fix or a feature.\n\n```bash\ngit clone git@github.com:postcss/postcss-calc.git\ngit checkout -b patch-1\nnpm install\nnpm test\n```\n\nThe normal test run uses a deterministic structural sample of the harvested\nreal-world corpus. Run the complete differential corpus before releases or\nwhen changing parsing/simplification behavior:\n\n```bash\npnpm test:corpus:full\n```\n\nProfile long arithmetic parser chains with `pnpm benchmark:arithmetic-chains`.\n\n## [Changelog](CHANGELOG.md)\n\n## [License](LICENSE)\n\n[git-img]: https://img.shields.io/badge/support-chat-blue.svg\n[git-url]: https://gitter.im/postcss/postcss\n[npm-img]: https://img.shields.io/npm/v/postcss-calc.svg\n[npm-url]: https://www.npmjs.com/package/postcss-calc\n[PostCSS]: https://github.com/postcss\n[PostCSS Calc]: https://github.com/postcss/postcss-calc\n[PostCSS Custom Properties]: https://github.com/postcss/postcss-custom-properties\n[tests]: test/index.js\n[W3C calc() implementation]: https://www.w3.org/TR/css3-values/#calc-notation\n","publish_time":1788791604321,"_cnpm_publish_time":1788791604321,"dist-tags":{"latest":"11.2.3","next":"11.0.0-rc.3"}}