Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85f98fe

Browse files
committed
Use custom divide() function instead of Dart Sass math module for greater compatibility
1 parent d41ef89 commit 85f98fe

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

scss/_functions.scss

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
123123
$l1: luminance($background);
124124
$l2: luminance(opaque($background, $foreground));
125125

126-
@return if($l1 > $l2, ($l1 + .05) / ($l2 + .05), ($l2 + .05) / ($l1 + .05));
126+
@return if($l1 > $l2, divide($l1 + .05, $l2 + .05), divide($l2 + .05, $l1 + .05));
127127
}
128128

129129
// Return WCAG2.0 relative luminance
@@ -137,7 +137,7 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
137137
);
138138

139139
@each $name, $value in $rgb {
140-
$value: if($value * .555 < .03928, $value * .555 / 12.92, nth($_luminance-list, $value + 1));
140+
$value: if($value * .555 < .03928, divide($value * .555, 12.92), nth($_luminance-list, $value + 1));
141141
$rgb: map-merge($rgb, ($name: $value));
142142
}
143143

@@ -219,3 +219,28 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
219219

220220
@return if($return-calc == true, calc(#{$value1} - #{$value2}), $value1 + unquote(" - ") + $value2);
221221
}
222+
223+
@function divide($dividend, $divisor, $precision: 10) {
224+
$sign: if($dividend > 0 and $divisor > 0, 1, -1);
225+
$dividend: abs($dividend);
226+
$divisor: abs($divisor);
227+
$quotient: 0;
228+
$remainder: $dividend;
229+
@if $dividend == 0 {
230+
@return 0;
231+
}
232+
@if $divisor == 0 {
233+
@error "Cannot divide by 0";
234+
}
235+
@if $divisor == 1 {
236+
@return $dividend;
237+
}
238+
@while $remainder >= $divisor {
239+
$quotient: $quotient + 1;
240+
$remainder: $remainder - $divisor;
241+
}
242+
@if $remainder > 0 and $precision > 0 {
243+
$remainder: divide($remainder * 10, $divisor, $precision - 1) * .1;
244+
}
245+
@return ($quotient + $remainder) * $sign;
246+
}

scss/mixins/_grid.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:math";
2+
13
/// Grid system
24
//
35
// Generate semantic grid columns with these mixins.
@@ -29,7 +31,8 @@
2931
@mixin make-col($size: false, $columns: $grid-columns) {
3032
@if $size {
3133
flex: 0 0 auto;
32-
width: percentage($size / $columns);
34+
width: percentage(divide($size, $columns));
35+
3336
} @else {
3437
flex: 1 1 0;
3538
max-width: 100%;

0 commit comments

Comments
 (0)