3 /// Increments up or down a defined scale and returns an adjusted value. This
4 /// helps establish consistent measurements and spacial relationships throughout
5 /// your project. We provide a list of commonly used scales as
6 /// [pre-defined variables][scales].
8 /// [scales]: https://github.com/thoughtbot/bourbon/blob/master/core/bourbon/settings/_scales.scss
10 /// @argument {number (unitless)} $increment
11 /// How many steps to increment up or down the scale.
13 /// @argument {number (with unit) | list} $value [1em]
14 /// The base value the scale starts at. Can also be set globally using the
15 /// `modular-scale-base` key in the Bourbon settings.
17 /// @argument {number (unitless)} $ratio [1.25]
18 /// The ratio the scale is built on. Can also be set globally using the
19 /// `modular-scale-ratio` key in the Bourbon settings.
21 /// @return {number (with unit)}
25 /// font-size: modular-scale(2);
30 /// font-size: 1.5625em;
35 /// margin-right: modular-scale(3, 2em);
40 /// margin-right: 3.90625em;
45 /// font-size: modular-scale(3, 1em 1.6em, $major-seventh);
54 /// // Globally change the base ratio
56 /// "modular-scale-ratio": 1.2,
60 /// font-size: modular-scale(3);
65 /// font-size: 1.728em;
68 /// @require {function} _fetch-bourbon-setting
70 @function modular-scale(
72 $value: _fetch-bourbon-setting("modular-scale-base"),
73 $ratio: _fetch-bourbon-setting("modular-scale-ratio")
76 $v2: nth($value, length($value));
79 // scale $v2 to just above $v1
81 $v2: ($v2 / $ratio); // will be off-by-1
84 $v2: ($v2 * $ratio); // will fix off-by-1
87 // check AFTER scaling $v2 to prevent double-counting corner-case
88 $double-stranded: $v2 > $v1;
91 @for $i from 1 through $increment {
92 @if $double-stranded and ($v1 * $ratio) > $v2 {
103 // adjust $v2 to just below $v1
104 @if $double-stranded {
108 @for $i from $increment through -1 {
109 @if $double-stranded and ($v1 / $ratio) < $v2 {