From 9e1adc5b5365c2d26121464291cdb5c2afcd3aca Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Tue, 1 Mar 2022 23:55:28 +0100 Subject: [PATCH 1/5] Test replacement of current SASS pow implementation --- NOTICE.txt | 26 +++++ src/global_styling/functions/_math.scss | 126 +++++++++++++++--------- 2 files changed, 103 insertions(+), 49 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 9fe4deacf44..e1e021be0c5 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -52,3 +52,29 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE + +-- +This product bundles code based on sass-math-pow@0.1.7 which is +available under a "MIT" license. + +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE diff --git a/src/global_styling/functions/_math.scss b/src/global_styling/functions/_math.scss index 4b82739e953..c713d5f5ae0 100644 --- a/src/global_styling/functions/_math.scss +++ b/src/global_styling/functions/_math.scss @@ -1,63 +1,91 @@ -//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow -@function pow($number, $power) { - @if ($power != $power or ($power != 0 and $power == $power / 2)) { - @return $power; - } - @if ($power == 1) { - @return $number; +//Forked by @elastic/eui from strarsis/sass-math-pow see https://github.com/strarsis/sass-math-pow + +/** +The MIT License (MIT) + +Copyright (c) 2015 strarsis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + +// By drtimofey, script based on script by davidkpiano, see these links: +// https://github.com/thoughtbot/bitters/issues/167 +// https://github.com/thoughtbot/bourbon/issues/717 +// https://gist.github.com/davidkpiano/ad6e6771df050ff3727f +// + + +@function pow($number, $exp) { + $exp1: round($exp); + $result: powInt($number, $exp1); + + @if ($exp1 != $exp) { + $result: $result * mathExp(($exp - $exp1) * mathLn($number)); } - @if ($power == 0) { + + @return $result; +} + +@function powInt($number, $exp) { + @if $exp == 0 { @return 1; - } - @if ($power < 0) { - @return 1 / pow($number, -$power); - } - @if (0 < $power and $power < 2) { - $hasLeadingOne: false; - @if (floor($power) == 1) { - $power: $power - 1; - $hasLeadingOne: true; - } @else { - $hasLeadingOne: false; - } - $doublePower: pow($number, $power * 2); - $fullPower: nthRoot($doublePower, 2); - @if ($hasLeadingOne) { - $fullPower: $fullPower * $number; - } - @return $fullPower; - } @else if (getDecimal($power) != 0) { - $wholePower: floor($power); - $decimalPower: getDecimal($power); - @return pow($number, $wholePower) * pow($number, $decimalPower); + } @else if $exp < 0 { + @return 1 / powInt($number, -$exp); } @else { - $hasTrailingOne: $power % 2 == 1; - @if ($hasTrailingOne) { - $power: $power - 1; - } - $halfPower: pow($number, floor($power / 2)); - $fullPower: $halfPower * $halfPower; - @if ($hasTrailingOne) { - $fullPower: $fullPower * $number; + $e: floor($exp / 2); + $pow: pow($number, $e); + @if $e * 2 == $exp { + @return $pow * $pow; + } @else { + @return $pow * $pow * $number; } - @return $fullPower; } } -@function getDecimal($number) { - @if ($number < 0) { - $number: -$number; +@function mathExp($value) { + $item: 1; + $result: 1; + + @for $index from 1 to 100 { + $item: $item * $value / $index; + $result: $result + $item; } - @return $number % 1; + + @return $result; } -// From: http://rosettacode.org/wiki/Nth_root#JavaScript -@function nthRoot($num, $n: 2, $prec: 12) { - $x: 1; +@function mathLn($value) { + $tenExp: 0; + $lnTen: 2.30258509; + + @while ($value > 1) { + $tenExp: $tenExp + 1; + $value: $value / 10; + } + + $item: -1; + $result: 0; - @for $i from 0 through $prec { - $x: 1 / $n * (($n - 1) * $x + ($num / pow($x, $n - 1))); + @for $index from 1 to 100 { + $item: $item * (1 - $value); + $result: $result + $item / $index; } - @return $x; + @return $result + $tenExp * $lnTen; } From 1b4c7635d8c401dc728f2b23311fc7cbf6ed9887 Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Wed, 2 Mar 2022 18:33:49 +0100 Subject: [PATCH 2/5] Moved the pow function to its own file --- src/global_styling/functions/_index.scss | 2 +- .../functions/{_math.scss => _math_pow.scss} | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) rename src/global_styling/functions/{_math.scss => _math_pow.scss} (84%) diff --git a/src/global_styling/functions/_index.scss b/src/global_styling/functions/_index.scss index de8260b2bba..4160ec5b17a 100644 --- a/src/global_styling/functions/_index.scss +++ b/src/global_styling/functions/_index.scss @@ -1,5 +1,5 @@ // Math needs to be first in the load order -@import 'math'; +@import 'math_pow'; // Using math, we have functions to manipulate contrast / luminosity for accessibility @import 'colors'; diff --git a/src/global_styling/functions/_math.scss b/src/global_styling/functions/_math_pow.scss similarity index 84% rename from src/global_styling/functions/_math.scss rename to src/global_styling/functions/_math_pow.scss index c713d5f5ae0..2e2d784a845 100644 --- a/src/global_styling/functions/_math.scss +++ b/src/global_styling/functions/_math_pow.scss @@ -1,9 +1,7 @@ -//Forked by @elastic/eui from strarsis/sass-math-pow see https://github.com/strarsis/sass-math-pow - /** The MIT License (MIT) -Copyright (c) 2015 strarsis +Copyright (c) 2015 strarsis https://github.com/strarsis/sass-math-pow Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -24,13 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// By drtimofey, script based on script by davidkpiano, see these links: -// https://github.com/thoughtbot/bitters/issues/167 -// https://github.com/thoughtbot/bourbon/issues/717 -// https://gist.github.com/davidkpiano/ad6e6771df050ff3727f -// - - @function pow($number, $exp) { $exp1: round($exp); $result: powInt($number, $exp1); From 94d66eec35aceece91ded5feb38007a33ef03cab Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Wed, 2 Mar 2022 18:34:21 +0100 Subject: [PATCH 3/5] Removed the license from the NOTICE file --- NOTICE.txt | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index e1e021be0c5..9fe4deacf44 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -52,29 +52,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE - --- -This product bundles code based on sass-math-pow@0.1.7 which is -available under a "MIT" license. - -MIT License - -Copyright (c) Microsoft Corporation. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE From 19338cb7f0f1ff5d6b609687733edac131d74a10 Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Thu, 3 Mar 2022 12:47:33 +0100 Subject: [PATCH 4/5] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cec19347311..2268726322f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Added `textWrap` to `EuiSelectableListItem`, `EuiSelectableList`, and `EuiSelectable.listOptions` ([#5679](https://github.com/elastic/eui/issues/5679)) - Forced `truncation` on `EuiSuggest` items when `isVirtualize` ([#5679](https://github.com/elastic/eui/issues/5679)) - Changed proportion handling between content and image in `horizontal` `EuiEmptyPrompt` and added spacing between ([#5663](https://github.com/elastic/eui/pull/5663)) +- Reduced SASS compilation time using a different math `pow` implementation ([#5674](https://github.com/elastic/eui/pull/5674)) **Bug fixes** From da8e8615677ea9dea3935ba316d8d7135098883b Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Thu, 3 Mar 2022 09:57:27 -0600 Subject: [PATCH 5/5] keep math.scss --- src/global_styling/functions/_index.scss | 2 +- src/global_styling/functions/_math.scss | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 src/global_styling/functions/_math.scss diff --git a/src/global_styling/functions/_index.scss b/src/global_styling/functions/_index.scss index 4160ec5b17a..de8260b2bba 100644 --- a/src/global_styling/functions/_index.scss +++ b/src/global_styling/functions/_index.scss @@ -1,5 +1,5 @@ // Math needs to be first in the load order -@import 'math_pow'; +@import 'math'; // Using math, we have functions to manipulate contrast / luminosity for accessibility @import 'colors'; diff --git a/src/global_styling/functions/_math.scss b/src/global_styling/functions/_math.scss new file mode 100644 index 00000000000..cdec36f3e60 --- /dev/null +++ b/src/global_styling/functions/_math.scss @@ -0,0 +1 @@ +@import 'math_pow'; \ No newline at end of file