modular-scale 2.1.1 → 3.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,68 +0,0 @@
1
- // Outputs a list of values instead of a single value
2
- @function ms-list($Start: 0, $End: 0, $Bases: $ms-base, $Ratios: $ms-ratio) {
3
-
4
- // Seed results
5
- $Positive-return: ();
6
- $Negitive-return: ();
7
- $Return: ();
8
-
9
- @if $End >= 0 {
10
- // Generate a list of all possible values
11
- $Positive-return: ms-generate-list($End, $Bases, $Ratios);
12
-
13
- // Sort the generated lists
14
- $Positive-return: ms-sort-list($Positive-return);
15
-
16
- // Trim list
17
- $Trim-list: ();
18
- // If the starting value is a positive number
19
- // trim the positive return from that
20
- @if $Start >= 0 {
21
- @for $i from ($Start + 1) through $End + 1 {
22
- $Trim-list: join($Trim-list, nth($Positive-return, $i));
23
- }
24
- }
25
- // If not, then include everything up to the end.
26
- @else {
27
- @for $i from 1 through $End + 1 {
28
- $Trim-list: join($Trim-list, nth($Positive-return, $i));
29
- }
30
- }
31
- $Positive-return: $Trim-list;
32
- }
33
-
34
- // Generate a negitive list
35
- @if $Start < 0 {
36
- // Generate a list of all possible values
37
- $Negitive-return: ms-generate-list($Start, $Bases, $Ratios);
38
-
39
- // Sort the generated lists
40
- $Negitive-return: ms-sort-list($Negitive-return);
41
-
42
- // Reverse negitive list results.
43
- $MS-new-return: ();
44
- @each $i in $Negitive-return {
45
- $MS-new-return: join($i, $MS-new-return);
46
- }
47
- $Negitive-return: $MS-new-return;
48
-
49
- // Trim list
50
- $Trim-list: ();
51
- @if $End < 0 {
52
- @for $i from abs($End) through (abs($Start) + 2) {
53
- $Trim-list: join(nth($Negitive-return, $i), $Trim-list);
54
- }
55
- }
56
- @else {
57
- @for $i from 2 through (abs($Start) + 1) {
58
- $Trim-list: join(nth($Negitive-return, $i), $Trim-list);
59
- }
60
- }
61
- $Negitive-return: $Trim-list;
62
- }
63
-
64
- // Join both positive and negitive possibilities.
65
- $Return: join($Negitive-return, $Positive-return);
66
-
67
- @return $Return;
68
- }
@@ -1,55 +0,0 @@
1
- // The main function that brings it all together
2
- @function ms($Value: 0, $Bases: $ms-base, $Ratios: $ms-ratio) {
3
-
4
- // If no multi-base or multi-ratio stuff is going on
5
- // then just retrn the basic calculaiton
6
- @if length($Bases) == 1 and length($Ratios) == 1 {
7
- @return ms-round-px(ms-calc($Value, $Bases, $Ratios));
8
- }
9
-
10
- // Do calculations directly in Ruby when avalible
11
- @if $MS-gem-exists {
12
-
13
- // Remove units from bases
14
- $Unit: nth($Bases, 1) * 0 + 1; // Extracts the unit from the base
15
- $Unitless-Bases: ();
16
- @each $Base in $Bases {
17
- $Base: $Base/$Unit;
18
- $Unitless-Bases: join($Unitless-Bases, $Base);
19
- }
20
-
21
- // Calculate natively in Ruby
22
- @return ms-round-px(ms-gem-func($Value, $Unitless-Bases, $Ratios) * $Unit);
23
- }
24
-
25
- // Generate a list of all possible values
26
- $Return: ms-generate-list($Value, $Bases, $Ratios);
27
-
28
- // Sort the generated lists
29
- $Return: ms-sort-list($Return);
30
-
31
- // Reverse list if its negitive.
32
- @if $Value < 0 {
33
- $MS-new-return: ();
34
- @each $i in $Return {
35
- $MS-new-return: join($i, $MS-new-return);
36
- }
37
- $Return: $MS-new-return;
38
- }
39
-
40
- // Normalize value for counting from 1
41
- // Because CSS counts things from 1
42
- // So Sass does as well
43
- // So I get to write fun stuff like this
44
- $Value: abs($Value) + 1;
45
-
46
- // Find the correct value in the list
47
- $Return: nth($Return, $Value);
48
-
49
- @return ms-round-px($Return);
50
- }
51
-
52
- // Same function, different name, for good measure.
53
- @function modular-scale($Value: 0, $Bases: $ms-base, $Ratios: $ms-ratio) {
54
- @return ms($Value, $Bases, $Ratios);
55
- }
@@ -1,103 +0,0 @@
1
- @function ms-reverse-list($list) {
2
- @if length($list) > 1 {
3
- @if nth($list, 1) > nth($list, length($list)) {
4
- $MS-reversed-list: ();
5
- @each $Value in $list {
6
- $MS-reversed-list: join($Value, $MS-reversed-list);
7
- }
8
- @return $MS-reversed-list;
9
- }
10
- }
11
- @return $list;
12
- }
13
-
14
-
15
- @function ms-generate-list($Value: 0, $Bases: $ms-base, $Ratios: $ms-ratio) {
16
-
17
- // Create blank lists
18
- $MS-list: ();
19
- $MS-base-list: ();
20
-
21
- // Loop through each ratio AND each base
22
- // to generate all possibilities.
23
- @each $Ratio in $Ratios {
24
- @each $Base in $Bases {
25
-
26
- // Set base variables
27
- $MS-base-list: ();
28
- $Base-counter: 0;
29
-
30
- // Seed list with an initial value
31
- $MS-base-list: $Base;
32
-
33
- // Find values on a positive scale
34
- @if $Value >= 0 {
35
-
36
- // Find lower values on the scale
37
- $Base-counter: -1;
38
- @while ms-calc($Base-counter, $Base, $Ratio) >= nth($Bases, 1) {
39
- $MS-base-list: join($MS-base-list, ms-calc($Base-counter, $Base, $Ratio));
40
- $Base-counter: $Base-counter - 1;
41
- }
42
-
43
- // Ensure the list is smallest to largest
44
- $MS-base-list: ms-reverse-list($MS-base-list);
45
-
46
- // Find higher possible values on the scale
47
- $Base-counter: 1;
48
- @while ms-calc($Base-counter, $Base, $Ratio) <= ms-calc($Value, nth($Bases, 1), $Ratio) {
49
- $MS-base-list: join($MS-base-list, ms-calc($Base-counter, $Base, $Ratio));
50
- $Base-counter: $Base-counter + 1;
51
- }
52
- }
53
-
54
- // Find values on a negitive scale
55
- @else {
56
-
57
- // Find lower values on the scale
58
- $Base-counter: 1;
59
- @while ms-calc($Base-counter, $Base, $Ratio) <= nth($Bases, 1) {
60
- $MS-base-list: join($MS-base-list, ms-calc($Base-counter, $Base, $Ratio));
61
- $Base-counter: $Base-counter + 1;
62
- }
63
-
64
- // Ensure the list is smallest to largest
65
- $MS-base-list: ms-reverse-list($MS-base-list);
66
-
67
- // Find higher possible values on the scale
68
- $Base-counter: -1;
69
- @while ms-calc($Base-counter, $Base, $Ratio) >= ms-calc($Value, nth($Bases, 1), $Ratio) {
70
- $MS-calc: ms-calc($Base-counter, $Base, $Ratio);
71
- // detect if the value excedes the main base value
72
- @if $MS-calc < nth($Bases, 1) {
73
- $MS-base-list: join($MS-base-list, $MS-calc);
74
- }
75
- $Base-counter: $Base-counter - 1;
76
- }
77
-
78
- // Trim outlier base.
79
- @if length($Bases) > 1 {
80
- @for $i from 2 through length($Bases) {
81
- @if nth($MS-base-list, 1) > nth($Bases, 1) {
82
- $MS-new-list: ();
83
- @for $i from 2 through length($MS-base-list) {
84
- $MS-new-list: join($MS-new-list, nth($MS-base-list, $i));
85
- }
86
- $MS-base-list: $MS-new-list;
87
- }
88
- }
89
- }
90
- }
91
-
92
- // reverse list if its largest to smallest
93
- $MS-base-list: ms-reverse-list($MS-base-list);
94
-
95
- // Add new possibilities to the master list
96
- $MS-list: append($MS-list, $MS-base-list, comma);
97
-
98
- }
99
- }
100
-
101
- // After all the possibilities are found, output a master list
102
- @return $MS-list;
103
- }
@@ -1,40 +0,0 @@
1
- // If a native exponent function doesnt exist
2
- // this one is needed.
3
- @function ms-pow($Base, $Exponent) {
4
-
5
- // Find and remove unit.
6
- // Avoids messyness with unit calculations
7
- $Unit: $Base * 0 + 1;
8
- $Base: $Base/$Unit;
9
-
10
- // This function doesnt support non-interger exponents.
11
- // Warn the user about why this is breaking.
12
- @if round($Exponent) != $Exponent {
13
- @warn "Unfortunately, you need Compass to use non-integer exponents";
14
- }
15
-
16
- // Set up the loop, priming the return with the base.
17
- $Return: $Base;
18
-
19
- // If the number is positive, multiply it.
20
- @if $Exponent > 0 {
21
- // Basic feedback loop as exponents
22
- // are recursivley multiplied numbers.
23
- @for $i from 1 to $Exponent {
24
- $Return: $Return * $Base;
25
- }
26
- }
27
-
28
- // If the number is 0 or negitive
29
- // divide instead of multiply.
30
- @else {
31
- // Libsass doesnt allow negitive values in loops
32
- @for $i from (-1 + 1) to (abs($Exponent) + 1) {
33
- $Return: $Return / $Base;
34
- }
35
- }
36
-
37
- // Return is now compounded redy to be returned.
38
- // Add the unit back onto the number.
39
- @return $Return * $Unit;
40
- }
@@ -1,49 +0,0 @@
1
- // Stripping units is rarely a best practice and this function
2
- // should not be used elsewhere
3
- @function ms-unitless($val) {
4
- $val: $val / ($val - $val + 1);
5
- @return $val;
6
- }
7
-
8
- // Search config for values
9
- @function ms-range($x,$y,$range:$ms-range) {
10
- @return nth(nth($range,$x),$y);
11
- }
12
-
13
- // Generate calc() function
14
- @function ms-respond-calc($value, $n, $range: $ms-range, $base: $ms-base) {
15
- $val1: ms($value,$base,ms-range($n,1,$range));
16
- $val2: ms($value,$base,ms-range($n+1,1,$range));
17
- $break1: ms-range($n,2,$range);
18
- $break2: ms-range($n+1,2,$range);
19
- $diff: ms-unitless($val2) - ms-unitless($val1);
20
- @if $ms-fluid {
21
- @return calc( #{$val1} + #{$diff} * ( ( 100vw - #{$break1}) / #{ms-unitless($break2) - ms-unitless($break1)} ) );
22
- } @else {
23
- @return ms($value,$base,ms-range($n,1,$range));
24
- }
25
- }
26
-
27
- // Main responsive mixin
28
- @mixin ms-respond($property, $value, $range: $ms-range, $base: $ms-base) {
29
- // If there is no responsive config, just output the property and value
30
- @if $ms-range == null {
31
- #{$property}: ms($value,$base,$ms-ratio);
32
- } @else {
33
-
34
- // Initial value
35
- #{$property}: ms($value,$base,ms-range(1,1,$range));
36
-
37
- // Loop through breakpoints
38
- @for $i from 1 through (length($range) - 1) {
39
- @media (min-width: ms-range($i,2,$range)) and (max-width: ms-range($i+1,2,$range)) {
40
- #{$property}: ms-respond-calc($value, $i, $range, $base);
41
- }
42
- }
43
-
44
- // Final breakpoint is just an override value
45
- @media (min-width: ms-range(length($range),2,$range)) {
46
- #{$property}: ms($value,$base,ms-range(length($range),1,$range));
47
- }
48
- }
49
- }
@@ -1,6 +0,0 @@
1
- @function ms-round-px($Result) {
2
- @if unit($Result) == 'px' {
3
- @return round($Result);
4
- }
5
- @return $Result;
6
- }
@@ -1,93 +0,0 @@
1
- // List sorting via a modified merge-sort algorythmn
2
- // http://en.wikipedia.org/wiki/Merge_sort
3
-
4
- @function ms-merge($A, $B) {
5
-
6
- $Return: ();
7
-
8
- // Some empty lists get passed through
9
- // so just pass the other list throguh
10
- @if length($A) == 0 {
11
- @return $B;
12
- }
13
-
14
- // If lists fit next to each other, just merge them
15
- // This helps performance skipping the need to check each value
16
- @if nth($A, length($A)) < nth($B, 1) {
17
- @return join($A, $B);
18
- }
19
- @if nth($B, length($B)) < nth($A, 1) {
20
- @return join($B, $A);
21
- }
22
-
23
- // Counters start at 1
24
- $A-counter: 1;
25
- $B-counter: 1;
26
-
27
- // Start looping through all numbers in array
28
- @while $A-counter <= length($A) and $B-counter <= length($B) {
29
-
30
- // Check if the A value is smaller
31
- // Uses or equal to avoid duplicate numbers
32
- @if nth($A, $A-counter) <= nth($B, $B-counter) {
33
- $Return: join($Return, nth($A, $A-counter));
34
- $A-counter: $A-counter + 1;
35
- }
36
-
37
- // Check if the B value is smaller
38
- @else if nth($A, $A-counter) > nth($B, $B-counter) {
39
- $Return: join($Return, nth($B, $B-counter));
40
- $B-counter: $B-counter + 1;
41
- }
42
- }
43
-
44
- // Run through remainder values in the list
45
- @while $A-counter <= length($A) {
46
- $Current: nth($A, $A-counter);
47
- @if $Current != nth($Return, length($Return)) {
48
- $Return: join($Return, $Current);
49
- }
50
- $A-counter: $A-counter + 1;
51
- }
52
- @while $B-counter <= length($B) {
53
- $Current: nth($B, $B-counter);
54
- @if $Current != nth($Return, length($Return)) {
55
- $Return: join($Return, $Current);
56
- }
57
- $B-counter: $B-counter + 1;
58
- }
59
-
60
- // Done! return is now sorted and complete
61
- @return $Return;
62
- }
63
-
64
-
65
-
66
- // Pull it all together
67
- @function ms-sort-list($Lists) {
68
-
69
- $Return: ();
70
-
71
- @each $List in $Lists {
72
- @if $Return == () {
73
- $Return: $List;
74
- }
75
- @else {
76
- $Return: ms-merge($List, $Return);
77
- }
78
- }
79
-
80
- // final cleanup of repeated items
81
- $Last: null;
82
- $New-list: ();
83
- @each $Item in $Return {
84
- @if $Item != $Last {
85
- $New-list: join($New-list, $Item);
86
- }
87
- $Last: $Item;
88
- }
89
- $Return: $New-list;
90
-
91
-
92
- @return $Return;
93
- }
@@ -1,22 +0,0 @@
1
- // Feature testing
2
-
3
-
4
- // Test if the pow() function exists
5
- @function ms-pow-exists() {
6
- @if pow(4, 2) == 16 {
7
- @return true;
8
- }
9
- @return false;
10
- }
11
-
12
- $MS-pow-exists: ms-pow-exists();
13
-
14
- // Test if MS was installed via the gem
15
- @function ms-gem-exists() {
16
- @if ms-gem-installed() == true {
17
- @return true;
18
- }
19
- @return false;
20
- }
21
-
22
- $MS-gem-exists: ms-gem-exists();