diff options
author | 2022-09-13 18:05:38 +0700 | |
---|---|---|
committer | 2022-09-13 18:05:38 +0700 | |
commit | 49d7007b4797dc1b74b7aca49b3684e750345228 (patch) | |
tree | a75a0f258e13222bec4ee57d71224eceee7b34bf /source/helpers/calculate-css-calc-string.ts | |
parent | e32685ecb16367b9d02aa431efce74df30a95e1d (diff) | |
download | refined-github-49d7007b4797dc1b74b7aca49b3684e750345228.tar.gz refined-github-49d7007b4797dc1b74b7aca49b3684e750345228.tar.zst refined-github-49d7007b4797dc1b74b7aca49b3684e750345228.zip |
Don't change `sticky-sidebar` state while interacting with it (#5961)
Diffstat (limited to 'source/helpers/calculate-css-calc-string.ts')
-rw-r--r-- | source/helpers/calculate-css-calc-string.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/helpers/calculate-css-calc-string.ts b/source/helpers/calculate-css-calc-string.ts new file mode 100644 index 00000000..e711ca85 --- /dev/null +++ b/source/helpers/calculate-css-calc-string.ts @@ -0,0 +1,12 @@ +import looseParseInt from './loose-parse-int'; + +/** +Compute the sum in a `calc()`. Only works with very simple sums of px values. +When used with custom properties, `calc()` are not evaluated when retrieved via `getComputedStyle()` + +@example calculateCssCalcString('calc(1px + 2px)') => 3; +*/ +export default function calculateCssCalcString(string: string): number { + const addends = string.split('+').map(part => looseParseInt(part)); + return addends.reduce((a, b) => a + b); +} |