From 49d7007b4797dc1b74b7aca49b3684e750345228 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Tue, 13 Sep 2022 18:05:38 +0700 Subject: Don't change `sticky-sidebar` state while interacting with it (#5961) --- source/helpers/calculate-css-calc-string.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 source/helpers/calculate-css-calc-string.ts (limited to 'source/helpers/calculate-css-calc-string.ts') 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); +} -- cgit v1.2.3