{"id":17963331,"url":"https://github.com/kristerkari/css-calc-transform","last_synced_at":"2025-03-25T05:32:15.417Z","repository":{"id":32694760,"uuid":"140110105","full_name":"kristerkari/css-calc-transform","owner":"kristerkari","description":"Tiny Javascript library to transform CSS properties with calc() function values to pixels based on window and element dimensions.","archived":false,"fork":false,"pushed_at":"2024-12-10T22:15:08.000Z","size":1447,"stargazers_count":13,"open_issues_count":8,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T09:11:11.730Z","etag":null,"topics":["calc","css","css-in-js","transform"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kristerkari.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-07T18:58:55.000Z","updated_at":"2024-09-04T17:57:00.000Z","dependencies_parsed_at":"2024-09-06T00:08:41.819Z","dependency_job_id":"26f07521-1704-41b8-9d14-f25f1fedc4f7","html_url":"https://github.com/kristerkari/css-calc-transform","commit_stats":{"total_commits":127,"total_committers":3,"mean_commits":"42.333333333333336","dds":"0.26771653543307083","last_synced_commit":"8fcc75713625410ed575fcb2de0439762e891e01"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Fcss-calc-transform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Fcss-calc-transform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Fcss-calc-transform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Fcss-calc-transform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kristerkari","download_url":"https://codeload.github.com/kristerkari/css-calc-transform/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245407579,"owners_count":20610227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calc","css","css-in-js","transform"],"created_at":"2024-10-29T11:33:32.311Z","updated_at":"2025-03-25T05:32:14.839Z","avatar_url":"https://github.com/kristerkari.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSS calc() to pixels transform\n\n[![NPM version](http://img.shields.io/npm/v/css-calc-transform.svg)](https://www.npmjs.org/package/css-calc-transform)\n[![Build Status](https://github.com/kristerkari/css-calc-transform/workflows/Tests/badge.svg)](https://github.com/kristerkari/css-calc-transform/actions?workflow=Tests)\n![Size](https://img.shields.io/bundlephobia/minzip/css-calc-transform.svg)\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github)\n\nTiny Javascript library to transform CSS properties with [CSS calc() function](https://developer.mozilla.org/en-US/docs/Web/CSS/calc) values to pixels based on window and element dimensions.\n\n## Install\n\n```sh\nyarn add --save css-calc-transform\n```\n\nor\n\n```sh\nnpm install --save css-calc-transform\n```\n\n## Usage\n\n### Pixels\n\n```js\nimport { transform } from \"css-calc-transform\";\n\ntransform({\n  prop: \"width\",\n  value: \"calc(10px + (100px / 3.5))\"\n});\n\n↓ ↓ ↓ ↓ ↓ ↓\n\n38.57142857142857\n```\n\n### Percentages\n\n```js\nimport { transform } from \"css-calc-transform\";\n\nconst parentElementDimensions = {\n  width: 480,\n  height: 100\n};\n\ntransform({\n  prop: \"width\",\n  value: \"calc(100% - 10px)\",\n  parent: parentElementDimensions\n});\n\n↓ ↓ ↓ ↓ ↓ ↓\n\n470\n```\n\n### Viewport units\n\n```js\nimport { transform } from \"css-calc-transform\";\n\nconst windowDimensions = {\n  width: 480,\n  height: 640\n};\n\ntransform({\n  prop: \"height\",\n  value: \"calc(50vh + 10px)\",\n  win: windowDimensions\n});\n\n↓ ↓ ↓ ↓ ↓ ↓\n\n330\n```\n\n### rem unit\n\n```js\nimport { transform } from \"css-calc-transform\";\n\ntransform({\n  prop: \"fontSize\",\n  value: \"calc(2rem + 1px)\",\n});\n\n↓ ↓ ↓ ↓ ↓ ↓\n\n33\n```\n\n### em unit\n\n\u003e When em units are used on font-size, the size is relative to the font-size of the parent.\n\u003e\n\u003e When used on other properties, it’s relative to the font-size of the element itself.\n\u003e\n\u003e https://www.digitalocean.com/community/tutorials/css-rem-vs-em-units\n\n```js\nimport { transform } from \"css-calc-transform\";\n\ntransform({\n  prop: \"fontSize\",\n  value: \"calc(2em + 1px)\",\n  parent: {\n    font: {\n      size: 16\n    }\n  }\n});\n\n↓ ↓ ↓ ↓ ↓ ↓\n\n33\n```\n\n```js\nimport { transform } from \"css-calc-transform\";\n\ntransform({\n  prop: \"height\",\n  value: \"calc(10px + 2em)\",\n  font: {\n    size: 16\n  }\n});\n\n↓ ↓ ↓ ↓ ↓ ↓\n\n42\n```\n\n## min(), max(), clamp()\n\n```js\nimport { transform } from \"css-calc-transform\";\n\ntransform({\n  prop: \"height\",\n  value: \"calc(min(2px, 3px) + clamp(100px, 150px, 200px) + max(1px, 2px))\",\n});\n\n↓ ↓ ↓ ↓ ↓ ↓\n\n154\n```\n\n### More examples\n\nFor more examples, please have a look at [the tests](__tests__/index.spec.js).\n\n## Dependencies\n\n- [evaluator.js](https://github.com/alecrios/evaluator.js) - A replacement for `eval()`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristerkari%2Fcss-calc-transform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristerkari%2Fcss-calc-transform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristerkari%2Fcss-calc-transform/lists"}