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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 046c2bbc74504a6714922aa2ec24b3bde0239a42
4
- data.tar.gz: 8353d90b9502fdc663c404c925f71cca7e0c9596
3
+ metadata.gz: b8a2fcc008da1ed4e223740529f01dac381ff840
4
+ data.tar.gz: 5bafbba66d06b231d4d9287545d17d0d6f3f095f
5
5
  SHA512:
6
- metadata.gz: 29ce6e0c37e1f70edc359929094bc2b9bf863d01329d84d6b0bdb89feb08e917ad66dbe81ea8340fffcebe90855a4b2e6a07936822ba5906241fc858895f9b63
7
- data.tar.gz: 4e7345d6f1c58b1d490e24d98fb5af614eb0a26e4ace57c179da4f91170a30d4259e9d9bc6a339fd13b758a15d141803f552957d48f5922938a38947e5f185b7
6
+ metadata.gz: 75d4b2cb0753bec81d6bb6bf8ef75b86ecaab8176c0b6967356a4b97b5b2d7d8f04989901def48a0964f45e0062bac14d7be13d70b43b327e13d641cf631c04d
7
+ data.tar.gz: 0a953c02680c0e0addad76f1eca31f90a2568aa20302feba84fc8976194b822d16968598d4318518bd1612866ea18dcfbd6971173a7a2ca47aafdbd3eacf5569
data/changelog.md CHANGED
@@ -1,3 +1,14 @@
1
+ # Version 3.0
2
+
3
+ Core logic re-write along with settings moved to maps so they can be multithreaded and setup responsive scales better.
4
+
5
+ * Settings moved into a map.
6
+ * Multiple settings threads so you can use different scales in tandem.
7
+ * Removed the list funciton that outputs a list of values.
8
+ * Removed multiple ratio support because it was confusing and you should use multiple threads anyway. This dramatically reduced the core logic and bugs.
9
+ * Fluid is the only responsive setting.
10
+ * Responsive mixin automatically pulls breakpoints from map threads.
11
+
1
12
  # Version 2.1.1
2
13
 
3
14
  Bugfix an `@else if` statement.
data/lib/modular-scale.rb CHANGED
@@ -16,8 +16,8 @@ Compass::Frameworks.register('modular-scale', :path => extension_path)
16
16
  # a prerelease version
17
17
  # Date is in the form of YYYY-MM-DD
18
18
  module ModularScale
19
- VERSION = "2.1.1"
20
- DATE = "2013-12-20"
19
+ VERSION = "3.0.0.alpha1"
20
+ DATE = "2015-11-08"
21
21
  end
22
22
 
23
23
  # This is where any custom SassScript should be placed. The functions will be
@@ -26,103 +26,9 @@ end
26
26
 
27
27
  module Sass::Script::Functions
28
28
 
29
- # Let MS know that extra functionality is avalible
29
+ # Let modularscale know that this was installed via Compass
30
30
  def ms_gem_installed()
31
31
  Sass::Script::Bool.new(true)
32
32
  end
33
33
 
34
- def ms_gem_func(value, bases, ratios)
35
-
36
- # Convert to native ruby things
37
- rvalue = value.value.to_i
38
-
39
- if bases.class == Sass::Script::Number
40
- bases = [] << bases
41
- else
42
- bases = bases.value.to_a
43
- end
44
- if ratios.class == Sass::Script::Number
45
- ratios = [] << ratios
46
- else
47
- ratios = ratios.value.to_a
48
- end
49
-
50
- # Convert items in arrays to floating point numbers
51
- rbases = []
52
- rratios = []
53
- bases.each do |num|
54
- rbases << num.value.to_f
55
- end
56
- ratios.each do |num|
57
- rratios << num.value.to_f
58
- end
59
-
60
-
61
- # Blank array for return
62
- r = [rbases[0]]
63
-
64
- # loop through all possibilities
65
- # NOTE THIS IS NOT FULLY FUNCTIONAL YET
66
- # ONLY LOOPS THROUGH SOME/MOST OF THE POSSIBILITES
67
-
68
- rratios.each do |ratio|
69
- rbases.each do |base|
70
-
71
- base_counter = 0
72
-
73
- # Seed list with an initial value
74
- r << base
75
-
76
- # Find values on a positive scale
77
- if rvalue >= 0
78
- # Find higher values on the scale
79
- i = 0;
80
- while ((ratio ** i) * base) >= (rbases[0])
81
- r << (ratio ** i) * base
82
- i = i - 1;
83
- end
84
-
85
- # Find lower possible values on the scale
86
- i = 0;
87
- while ((ratio ** i) * base) <= ((ratio ** (rvalue + 1)) * base)
88
- r << (ratio ** i) * base
89
- i = i + 1;
90
- end
91
-
92
- else
93
-
94
- # Find lower values on the scale
95
- i = 0;
96
- while ((ratio ** i) * base) <= (rbases[0])
97
- r << (ratio ** i) * base
98
- i = i + 1;
99
- end
100
-
101
- # Find higher possible values on the scale
102
- i = 0;
103
- while ((ratio ** i) * base) >= ((ratio ** (rvalue - 1)) * base)
104
- r << (ratio ** i) * base
105
- i = i - 1;
106
- end
107
- end
108
-
109
- end
110
- end
111
-
112
- # Sort and trim
113
- r.sort!
114
- r.uniq!
115
-
116
-
117
- if rvalue < 0
118
- r = r.keep_if { |a| a <= rbases[0] }
119
- # Final value
120
- r = r[(rvalue - 1)]
121
- else
122
- r = r[rvalue]
123
- end
124
-
125
-
126
- Sass::Script::Number.new(r)
127
- end
128
34
  end
data/readme.md CHANGED
@@ -19,6 +19,12 @@ To get started, you need to select a ratio and a base value. The base value is u
19
19
  * Terminal: `npm install modularscale-sass --save-dev`
20
20
  * SCSS: `@import 'modular-scale'`
21
21
 
22
+ ### Webpack with sass-loader
23
+
24
+ * Terminal: `npm install modularscale-sass --save-dev`
25
+ * Webpack config: install and use [sass-loader](https://github.com/jtangelder/sass-loader#apply-via-webpack-config)
26
+ * SCSS: `@import '~modularscale-sass/stylesheets/modular-scale';`
27
+
22
28
  ### Bower
23
29
 
24
30
  * Terminal: `bower install modular-scale --save-dev`
@@ -30,143 +36,140 @@ To get started, you need to select a ratio and a base value. The base value is u
30
36
  * Extract into your project
31
37
  * SCSS: `@import 'modular-scale';`
32
38
 
33
- ## Compatibility
34
-
35
- I have been working incredibly hard to make Modular Scale compatible with multiple versions of Sass. As a result, it will work and has been tested in **Libsass**, **Sass 3.2**, **Sass 3.3**, and **Sass 3.4**.
36
-
37
- These are dramatically different environments so things may have slight differences. **[For best results, install via the gem with Compass](https://github.com/Team-Sass/modular-scale/tree/2.x#compass)**.
38
-
39
- #### **Compass + Sass (best):**
40
-
41
- * non-integer values work with the `ms()` function. (Compass only)
42
- * Significant speed increases as the gem does calculations natively in Ruby
43
-
44
- #### **Libsass:**
45
-
46
- * Everything should be working, and work very quickly.
39
+ ## Using modular scale
47
40
 
48
- #### **Vanilla Sass:**
41
+ #### Initial setup and usage:
49
42
 
50
- * Works fine, but is slow when using multiple bases and ratios.
43
+ The first thing you’ll want to do when you start using modular scale is configure it to meet your needs. This is done in the `$modularscale` map.
51
44
 
52
- ## Usage
45
+ ```scss
46
+ $modularscale: (
47
+ base: 1em,
48
+ ratio: 1.5
49
+ );
50
+ ```
53
51
 
54
- Modular Scale has two default variables that you should place with your other site wide variables. `$ms-base` is usually your font size or `1em` and can have multiple values. `$ms-ratio` is the factor of change between each number so if the ratio is `1.5` then each number in the sequence will be 1.5 times that of the previous number. Just as you can have multiple bases you can have multiple ratios.
52
+ You can use any unit you wish as your base and any ratio. Multiple bases can be defined for creating multi stranded scales. There is no limit here to the number of strands you use.
55
53
 
56
54
  ```scss
57
- $ms-base: 1em;
58
- $ms-ratio: $golden;
55
+ $modularscale: (
56
+ base: 1em 1.2em 1.6em,
57
+ ratio: 1.5
58
+ );
59
59
  ```
60
60
 
61
- Modular-scale is used as a function. Simply pass it through in place of any value to generate a value based on a modular scale.
61
+ Now that we have defined your scale, we can start using it anywhere. Simply call the `ms(n)` function where `n` is the point on the scale.
62
62
 
63
63
  ```scss
64
- font-size: ms(2); // two up the modular scale
65
- font-size: ms(2, 16px); // two up the modular scale with a base size of 16px, default is 1em
66
- font-size: ms(2, 1em, $octave); // Same as above but on an octave scale
64
+ h4 {
65
+ font-size: ms(3);
66
+ }
67
67
  ```
68
68
 
69
- You can output a list to your terminal to help you find out what values are on your scale.
69
+ Occasionally you may wind up with conflicts. All critical components are name-spaced to avoid conflicts with other libraries. If you do run into a conflict, `ms-function()` is the no-conflict function.
70
+
71
+ #### Multiple scale threads
72
+
73
+ Modular scale now supports different settings threads, so you can set up various threads to configure different ratios or breakpoints.
70
74
 
71
75
  ```scss
72
- @debug ms-list($start, $end, $ms-base, $ms-ratio);
76
+ $modularscale: (
77
+ base: 1em,
78
+ ratio: 1.5,
79
+ a: (
80
+ ratio: 1.3
81
+ )
82
+ );
73
83
  ```
74
84
 
75
- You can use a double standard scale by simply adding more base sizes in a space-separated list.
76
- **note:** the starting point of the scale will always be the **first** value in this list
85
+ To call the thread named `a`, call it in your function like so:
77
86
 
78
87
  ```scss
79
- .double-standard {
80
- width: ms(7, 1em 2em);
88
+ h5 {
89
+ font-size: ms(2, $thread: a);
81
90
  }
82
91
  ```
83
92
 
84
- You can do the same thing with ratios
93
+ Your settings will cascade into the threads so no need to redefine a base or ratio if you want to re-use it from the main config.
94
+
95
+ If you wish to put breakpoints into your settings for use with responsive typography then there are helpers in place for this. Simply organize your config with breakpoint values from smallest to largest:
85
96
 
86
97
  ```scss
87
- .multi-ratio {
88
- width: ms(7, 1em, $golden $octave);
89
- }
98
+ $modularscale: (
99
+ base: 12px,
100
+ ratio: 1.5,
101
+ 30em: (
102
+ ratio: 1.2,
103
+ ),
104
+ 40em: (
105
+ base: 16px,
106
+ ratio: 1.3,
107
+ ),
108
+ 60em: (
109
+ base: 16px,
110
+ ratio: 1.6,
111
+ ),
112
+ );
90
113
  ```
91
114
 
92
- You can use multiple $ms-bases and multiple $ms-ratio together
115
+ Then, call the mixin `@include ms-respond();` and a fully fluid and responsive scale will be generated.
93
116
 
94
117
  ```scss
95
- .multibase-multiratio {
96
- width: ms(7, 16px 24px, $golden $fourth);
118
+ h2 {
119
+ @include ms-respond(font-size,5);
97
120
  }
98
121
  ```
99
122
 
100
- ## Ratios
123
+ If you do happen to have any values that are just named without numbers they will be ignored by the responsive mixin, it’s smart enough to just pull values that look like breakpoints.
101
124
 
102
- Modular scale includes functions for a number of classic design and musical scale ratios. You can add your own ratios as well.
125
+ #### Non-integer values and target
103
126
 
104
- By default, the variable `$ms-ratio` is set to `$golden`.
127
+ Unfortunately Sass doesn’t natively support exponents. You will need to either use Compass, math-sass, or another library that has a fully featured `pow()` function to use non-integer values in modular scale.
105
128
 
106
- <table>
129
+ Fortunately Compass and math-sass are excellent and if you install them alongside modular scale it will pick up on the added functionality and you will be able to write values like `ms(2.5)`.
107
130
 
108
- <tr><th>Function</th><th>Ratio</th><th>Decimal value</th></tr>
109
-
110
- <tr><td>$phi</td><td>1:1.618</td><td>1.618</td></tr>
111
- <tr><td>$golden</td><td>1:1.618</td><td>1.618</td></tr>
112
- <tr><td>$double-octave</td><td>1:4</td><td>4</td></tr>
113
- <tr><td>$major-twelfth</td><td>1:3</td><td>3</td></tr>
114
- <tr><td>$major-eleventh</td><td>3:8</td><td>2.667</td></tr>
115
- <tr><td>$major-tenth</td><td>2:5</td><td>2.5</td></tr>
116
- <tr><td>$octave</td><td>1:2</td><td>2</td></tr>
117
- <tr><td>$major-seventh</td><td>8:15</td><td>1.875</td></tr>
118
- <tr><td>$minor-seventh</td><td>9:16</td><td>1.778</td></tr>
119
- <tr><td>$major-sixth</td><td>3:5</td><td>1.667</td></tr>
120
- <tr><td>$minor-sixth</td><td>5:8</td><td>1.6</td></tr>
121
- <tr><td>$fifth</td><td>2:3</td><td>1.5</td></tr>
122
- <tr><td>$augmented-fourth</td><td>1:√2</td><td>1.414</td></tr>
123
- <tr><td>$fourth</td><td>3:4</td><td>1.333</td></tr>
124
- <tr><td>$major-third</td><td>4:5</td><td>1.25</td></tr>
125
- <tr><td>$minor-third</td><td>5:6</td><td>1.2</td></tr>
126
- <tr><td>$major-second</td><td>8:9</td><td>1.125</td></tr>
127
- <tr><td>$minor-second</td><td>15:16</td><td>1.067</td></tr>
131
+ #### Target sizes*
128
132
 
129
- </table>
133
+ _NOTE: Please see above on using a robust pow function_
130
134
 
131
- Add your own ratio in Sass by setting a variable and passing that to modular-scale.
135
+ One of the more difficult parts of setting up your scales is finding a ratio that works for you. In many cases you know what size you want your text to be and what size you want larger headings to be. The `at` helper allows you to plug in a target size into the ratio value and it will generate your ratio.
132
136
 
133
137
  ```scss
134
- $my-ratio: 1 / 3.14159265;
135
- $ms-ratio: $my-ratio;
138
+ $modularscale: (
139
+ base: 16px,
140
+ ratio: 42at5
141
+ );
136
142
  ```
137
143
 
138
- ## Responsive scales
139
-
140
- Based on [Mike Riethmuller’s](https://twitter.com/MikeRiethmuller) [_Precise control over responsive typography_](http://madebymike.com.au/writing/precise-control-responsive-typography/). A fantastic technique for fluidly scaling typography.
141
-
142
- First, you will need to set your range. A range is a list of ratio and breakpoint values from smallest to largest. Because this will render as a fluid range by default you will probably only want or need a range of two.
144
+ Now your base is `16px` and when you call `ms(5)` it will be `42px`. Everything in-between falls neatly on a scale created with these two values.
143
145
 
144
- ```scss
145
- $ms-range:
146
- 1.1 20em,
147
- 1.333 60em;
148
- ```
149
-
150
- If you want to have specified steps instead of fluid type set `$ms-fluid` to `false` and you may want to add more values to your range.
146
+ ## Ratios
151
147
 
152
- ```scss
153
- $ms-fluid: false;
154
-
155
- $ms-range:
156
- 1.2 20em,
157
- 1.3 30em,
158
- 1.4 40em,
159
- 1.5 50em,
160
- 1.6 60em;
161
- ```
148
+ Modular scale includes functions for a number of classic design and musical scale ratios. You can add your own ratios as well.
162
149
 
163
- Now you can use the `ms-respond` mixin to output a range of values for a single point on a scale.
150
+ By default ratio is set to `$fifth`.
164
151
 
165
- ```scss
166
- foo {
167
- @include ms-respond(font-size, 2);
168
- }
169
- ```
152
+ <table>
153
+ <tr><th>Function </th><th>Ratio </th><th>Decimal value</th></tr>
154
+ <tr><td>$phi </td><td>1:1.618</td><td>1.618 </td></tr>
155
+ <tr><td>$golden </td><td>1:1.618</td><td>1.618 </td></tr>
156
+ <tr><td>$double-octave </td><td>1:4 </td><td>4 </td></tr>
157
+ <tr><td>$major-twelfth </td><td>1:3 </td><td>3 </td></tr>
158
+ <tr><td>$major-eleventh </td><td>3:8 </td><td>2.667 </td></tr>
159
+ <tr><td>$major-tenth </td><td>2:5 </td><td>2.5 </td></tr>
160
+ <tr><td>$octave </td><td>1:2 </td><td>2 </td></tr>
161
+ <tr><td>$major-seventh </td><td>8:15 </td><td>1.875 </td></tr>
162
+ <tr><td>$minor-seventh </td><td>9:16 </td><td>1.778 </td></tr>
163
+ <tr><td>$major-sixth </td><td>3:5 </td><td>1.667 </td></tr>
164
+ <tr><td>$minor-sixth </td><td>5:8 </td><td>1.6 </td></tr>
165
+ <tr><td>$fifth </td><td>2:3 </td><td>1.5 </td></tr>
166
+ <tr><td>$augmented-fourth</td><td>1:√2 </td><td>1.414 </td></tr>
167
+ <tr><td>$fourth </td><td>3:4 </td><td>1.333 </td></tr>
168
+ <tr><td>$major-third </td><td>4:5 </td><td>1.25 </td></tr>
169
+ <tr><td>$minor-third </td><td>5:6 </td><td>1.2 </td></tr>
170
+ <tr><td>$major-second </td><td>8:9 </td><td>1.125 </td></tr>
171
+ <tr><td>$minor-second </td><td>15:16 </td><td>1.067 </td></tr>
172
+ </table>
170
173
 
171
174
  ## [Changelog](https://github.com/Team-Sass/modular-scale/releases)
172
175
 
@@ -0,0 +1,20 @@
1
+ // Defaults and variables
2
+ @import 'modularscale/vars';
3
+
4
+ // Feature tests
5
+ @import 'modularscale/tests';
6
+
7
+ // Core functions
8
+ @import 'modularscale/settings';
9
+ @import 'modularscale/pow';
10
+ @import 'modularscale/strip-units';
11
+ @import 'modularscale/sort';
12
+ @import 'modularscale/round-px';
13
+ @import 'modularscale/target';
14
+ @import 'modularscale/function';
15
+
16
+ // Mixins
17
+ @import 'modularscale/respond';
18
+
19
+ // Syntax sugar
20
+ @import 'modularscale/sugar';
@@ -0,0 +1,52 @@
1
+ @function ms-function($v: 0, $base: false, $ratio: false, $thread: false, $settings: $modularscale) {
2
+
3
+ $ms-settings: ms-settings($base,$ratio,$thread,$settings);
4
+ $base: nth($ms-settings, 1);
5
+ $ratio: nth($ms-settings, 2);
6
+
7
+ // Render target values from settings.
8
+ @if unit($ratio) != '' {
9
+ $ratio: ms-target($ratio,$base)
10
+ }
11
+
12
+ // Fast calc if not multi stranded
13
+ @if(length($base) == 1) {
14
+ @return ms-round-px(pow($ratio, $v) * $base);
15
+ }
16
+
17
+ // Create new base array
18
+ $ms-bases: nth($base,1);
19
+
20
+ // Normalize base values
21
+ @for $i from 2 through length($base) {
22
+ // initial base value
23
+ $ms-base: nth($base,$i);
24
+ // If the base is bigger than the main base
25
+ @if($ms-base > nth($base,1)) {
26
+ // divide the value until it aligns with main base.
27
+ @while($ms-base > nth($base,1)) {
28
+ $ms-base: $ms-base / $ratio;
29
+ }
30
+ $ms-base: $ms-base * $ratio;
31
+ }
32
+ // If the base is smaller than the main base.
33
+ @elseif ($ms-base < nth($base,1)) {
34
+ // pump up the value until it aligns with main base.
35
+ @while $ms-base < nth($base,1) {
36
+ $ms-base: $ms-base * $ratio;
37
+ }
38
+ }
39
+ // Push into new array
40
+ $ms-bases: append($ms-bases,$ms-base);
41
+ }
42
+
43
+ // Sort array from smallest to largest.
44
+ $ms-bases: ms-sort($ms-bases);
45
+
46
+ // Find step to use in calculation
47
+ $vtep: floor($v / length($ms-bases));
48
+ // Find base to use in calculation
49
+ $ms-base: round(($v / length($ms-bases) - $vtep) * length($ms-bases)) + 1;
50
+
51
+ @return ms-round-px(pow($ratio, $vtep) * nth($ms-bases,$ms-base));
52
+ }