Debian Codegraph @

debian/missing-sources/bourbon/app/assets/stylesheets/functions/_modular-scale.scss

raw
1 // Scaling Variables
2 $golden: 1.618;
3 $minor-second: 1.067;
4 $major-second: 1.125;
5 $minor-third: 1.2;
6 $major-third: 1.25;
7 $perfect-fourth: 1.333;
8 $augmented-fourth: 1.414;
9 $perfect-fifth: 1.5;
10 $minor-sixth: 1.6;
11 $major-sixth: 1.667;
12 $minor-seventh: 1.778;
13 $major-seventh: 1.875;
14 $octave: 2;
15 $major-tenth: 2.5;
16 $major-eleventh: 2.667;
17 $major-twelfth: 3;
18 $double-octave: 4;
19
20 $user-output-deprecation-warnings-setting: $output-bourbon-deprecation-warnings;
21 $output-bourbon-deprecation-warnings: false;
22
23 $modular-scale-ratio: $perfect-fourth !default;
24 $modular-scale-base: em($em-base) !default;
25
26 $output-bourbon-deprecation-warnings: $user-output-deprecation-warnings-setting;
27
28 @function modular-scale($increment, $value: $modular-scale-base, $ratio: $modular-scale-ratio) {
29 $v1: nth($value, 1);
30 $v2: nth($value, length($value));
31 $value: $v1;
32
33 // scale $v2 to just above $v1
34 @while $v2 > $v1 {
35 $v2: ($v2 / $ratio); // will be off-by-1
36 }
37 @while $v2 < $v1 {
38 $v2: ($v2 * $ratio); // will fix off-by-1
39 }
40
41 // check AFTER scaling $v2 to prevent double-counting corner-case
42 $double-stranded: $v2 > $v1;
43
44 @if $increment > 0 {
45 @for $i from 1 through $increment {
46 @if $double-stranded and ($v1 * $ratio) > $v2 {
47 $value: $v2;
48 $v2: ($v2 * $ratio);
49 } @else {
50 $v1: ($v1 * $ratio);
51 $value: $v1;
52 }
53 }
54 }
55
56 @if $increment < 0 {
57 // adjust $v2 to just below $v1
58 @if $double-stranded {
59 $v2: ($v2 / $ratio);
60 }
61
62 @for $i from $increment through -1 {
63 @if $double-stranded and ($v1 / $ratio) < $v2 {
64 $value: $v2;
65 $v2: ($v2 / $ratio);
66 } @else {
67 $v1: ($v1 / $ratio);
68 $value: $v1;
69 }
70 }
71 }
72
73 @return $value;
74 }