modular-scale 3.0.0.alpha1 → 3.0.0

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: b8a2fcc008da1ed4e223740529f01dac381ff840
4
- data.tar.gz: 5bafbba66d06b231d4d9287545d17d0d6f3f095f
3
+ metadata.gz: 5b218cce633b1fbb7aa11f3f1e98b2e591396b3c
4
+ data.tar.gz: 67816e15cee10a7d617928b1dfdff05822062903
5
5
  SHA512:
6
- metadata.gz: 75d4b2cb0753bec81d6bb6bf8ef75b86ecaab8176c0b6967356a4b97b5b2d7d8f04989901def48a0964f45e0062bac14d7be13d70b43b327e13d641cf631c04d
7
- data.tar.gz: 0a953c02680c0e0addad76f1eca31f90a2568aa20302feba84fc8976194b822d16968598d4318518bd1612866ea18dcfbd6971173a7a2ca47aafdbd3eacf5569
6
+ metadata.gz: 3fd24052162a00771535e631b8c53bb6497b08d5f49d2ebb3f2bbf2e1ac41c993ec8e6bef7794dd18f6bfc2878d9a2bcee0817586518b6846ddb57facc2bf1a2
7
+ data.tar.gz: 78b428cbd8d9cf7e12da30ca10b83b7e3534f812006368abb1d7f051b8f0ca7a6b49d46a1c43398ef25be53d89db65794a46e70c83cc4f4a951c3d075e8cfcf9
data/changelog.md CHANGED
@@ -8,6 +8,7 @@
8
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
9
  * Fluid is the only responsive setting.
10
10
  * Responsive mixin automatically pulls breakpoints from map threads.
11
+ * find ratios based on target sizes at points on the scale.
11
12
 
12
13
  # Version 2.1.1
13
14
 
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 = "3.0.0.alpha1"
20
- DATE = "2015-11-08"
19
+ VERSION = "3.0.0"
20
+ DATE = "2017-04-02"
21
21
  end
22
22
 
23
23
  # This is where any custom SassScript should be placed. The functions will be
data/readme.md CHANGED
@@ -10,7 +10,7 @@ To get started, you need to select a ratio and a base value. The base value is u
10
10
 
11
11
  ### Compass
12
12
 
13
- * Terminal: `gem install modular-scale`
13
+ * Terminal: `gem install modular-scale --pre`
14
14
  * Compass config: `require 'modular-scale'`
15
15
  * SCSS: `@import 'modular-scale';`
16
16
 
@@ -98,20 +98,24 @@ If you wish to put breakpoints into your settings for use with responsive typogr
98
98
  $modularscale: (
99
99
  base: 12px,
100
100
  ratio: 1.5,
101
- 30em: (
101
+ 400px: (
102
102
  ratio: 1.2,
103
103
  ),
104
- 40em: (
104
+ 900px: (
105
105
  base: 16px,
106
106
  ratio: 1.3,
107
107
  ),
108
- 60em: (
108
+ 1200px: (
109
109
  base: 16px,
110
110
  ratio: 1.6,
111
111
  ),
112
112
  );
113
113
  ```
114
114
 
115
+ _Note that you must use the same units for both your type and your breakpoints for this to work_
116
+
117
+ This technique is 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.
118
+
115
119
  Then, call the mixin `@include ms-respond();` and a fully fluid and responsive scale will be generated.
116
120
 
117
121
  ```scss
@@ -122,15 +126,13 @@ h2 {
122
126
 
123
127
  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.
124
128
 
125
- #### Non-integer values and target
126
-
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.
129
+ #### Note on non-integer values
128
130
 
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)`.
131
+ Unfortunately [Sass doesn’t natively support exponents](https://github.com/sass/sass/issues/684#issuecomment-196852515). This isn’t all bad news, you can use either use [Compass](http://compass-style.org/), [mathsass](https://github.com/terkel/mathsass), or another library that has a `pow()` function that supports non-integer values and this plugin will pick up on that function and use it. You will then be able to write values like `ms(2.5)`. This is also a prerequisite for _target sizes_ below.
130
132
 
131
- #### Target sizes*
133
+ #### Target sizes
132
134
 
133
- _NOTE: Please see above on using a robust pow function_
135
+ _NOTE: Please see above section on non-integer values before using this feature_
134
136
 
135
137
  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.
136
138
 
@@ -1,9 +1,6 @@
1
1
  // Defaults and variables
2
2
  @import 'modularscale/vars';
3
3
 
4
- // Feature tests
5
- @import 'modularscale/tests';
6
-
7
4
  // Core functions
8
5
  @import 'modularscale/settings';
9
6
  @import 'modularscale/pow';
@@ -1,5 +1,6 @@
1
1
  @function ms-function($v: 0, $base: false, $ratio: false, $thread: false, $settings: $modularscale) {
2
2
 
3
+ // Parse settings
3
4
  $ms-settings: ms-settings($base,$ratio,$thread,$settings);
4
5
  $base: nth($ms-settings, 1);
5
6
  $ratio: nth($ms-settings, 2);
@@ -1,8 +1,17 @@
1
+ // Sass does not have native pow() support so this needs to be added.
2
+ // Compass and other libs implement this more extensively.
3
+ // In order to keep this simple, use those when they are avalible.
4
+ // Issue for pow() support in Sass: https://github.com/sass/sass/issues/684
5
+
1
6
  @function ms-pow($b,$e) {
7
+
8
+ // If pow() exists (compass or mathsass) use that.
2
9
  @if function-exists('pow') {
3
10
  @return pow($b,$e);
4
11
  }
5
12
 
13
+ // This does not support non-integer exponents,
14
+ // Check and return an error if a non-integer exponent is passed.
6
15
  @if (floor($e) != $e) {
7
16
  @error '
8
17
  ======================================================================
@@ -14,7 +23,10 @@ https://github.com/terkel/mathsass
14
23
  '
15
24
  }
16
25
 
26
+ // Seed the return.
17
27
  $ms-return: $b;
28
+
29
+ // Multiply or divide by the specified number of times.
18
30
  @if $e > 0 {
19
31
  @for $i from 1 to $e {
20
32
  $ms-return: $ms-return * $b;
@@ -1,6 +1,10 @@
1
1
  // Generate calc() function
2
+ // based on Mike Riethmuller's Precise control over responsive typography
3
+ // http://madebymike.com.au/writing/precise-control-responsive-typography/
2
4
  @function ms-fluid($val1: 1em, $val2: 1em, $break1: 0, $break2: 0) {
3
5
  $diff: ms-unitless($val2) - ms-unitless($val1);
6
+
7
+ // v1 + (v2 - v1) * ( (100vw - b1) / b2 - b1 )
4
8
  @return calc( #{$val1} + #{ms-unitless($val2) - ms-unitless($val1)} * ( ( 100vw - #{$break1}) / #{ms-unitless($break2) - ms-unitless($break1)} ) );
5
9
  }
6
10
 
@@ -17,11 +21,16 @@
17
21
  @if type-of($v) == number {
18
22
  @if unit($v) != '' {
19
23
 
24
+ // Write out the first value without a media query.
20
25
  @if $first-write {
21
26
  #{$prop}: ms-function($val, $thread: $v, $settings: $map);
27
+
28
+ // Not the first write anymore, reset to false to move on.
22
29
  $first-write: false;
23
30
  $last-break: $v;
24
31
  }
32
+
33
+ // Write intermediate breakpoints.
25
34
  @else {
26
35
  @media (min-width: $last-break) and (max-width: $v) {
27
36
  $val1: ms-function($val, $thread: $last-break, $settings: $map);
@@ -33,6 +42,8 @@
33
42
  }
34
43
  }
35
44
  }
45
+
46
+ // Write the last breakpoint.
36
47
  @if $last-break {
37
48
  @media (min-width: $last-break) {
38
49
  #{$prop}: ms-function($val, $thread: $last-break, $settings: $map);
@@ -1,3 +1,6 @@
1
+ // No reason to have decimal pixel values,
2
+ // normalize them to whole numbers.
3
+
1
4
  @function ms-round-px($r) {
2
5
  @if unit($r) == 'px' {
3
6
  @return round($r);
@@ -1,3 +1,7 @@
1
+ // Parse settings starting with defaults.
2
+ // Settings should cascade down like you would expect in CSS.
3
+ // More specific overrides previous settings.
4
+
1
5
  @function ms-settings($b: false, $r: false, $t: false, $m: $modularscale) {
2
6
  $base: $ms-base;
3
7
  $ratio: $ms-ratio;
@@ -1,18 +1,34 @@
1
+ // Basic list sorting
2
+ // Would like to replace with http://sassmeister.com/gist/30e4863bd03ce0e1617c
3
+ // Unfortunately libsass has a bug with passing arguments into the min() funciton.
4
+
1
5
  @function ms-sort($l) {
2
6
 
7
+ // loop until the list is confirmed to be sorted
3
8
  $sorted: false;
4
9
  @while $sorted == false {
10
+
11
+ // Start with the assumption that the lists are sorted.
5
12
  $sorted: true;
13
+
14
+ // Loop through the list, checking each value with the one next to it.
15
+ // Swap the values if they need to be swapped.
16
+ // Not super fast but simple and modular scale doesn't lean hard on sorting.
6
17
  @for $i from 2 through length($l) {
7
18
  $n1: nth($l,$i - 1);
8
19
  $n2: nth($l,$i);
20
+
21
+ // If the first value is greater than the 2nd, swap them.
9
22
  @if $n1 > $n2 {
10
23
  $l: set-nth($l, $i, $n1);
11
24
  $l: set-nth($l, $i - 1, $n2);
25
+
26
+ // The list isn't sorted and needs to be looped through again.
12
27
  $sorted: false;
13
28
  }
14
29
  }
15
30
  }
16
31
 
32
+ // Return the sorted list.
17
33
  @return $l;
18
34
  }
@@ -3,6 +3,5 @@
3
3
  // It is used here because calc() doesn't do unit logic
4
4
  // AND target ratios use units as a hack to get a number.
5
5
  @function ms-unitless($val) {
6
- $val: $val / ($val - $val + 1);
7
- @return $val;
6
+ @return ($val / ($val - $val + 1));
8
7
  }
@@ -1,3 +1,7 @@
1
+ // To attempt to avoid conflicts with other libraries
2
+ // all funcitons are namespaced with `ms-`.
3
+ // However, to increase usability, a shorthand function is included here.
4
+
1
5
  @function ms($v: 0, $base: false, $ratio: false, $thread: false, $settings: $modularscale) {
2
6
  @return ms-function($v, $base, $ratio, $thread, $settings);
3
7
  }
@@ -1,37 +1,49 @@
1
- @function ms-target($t,$b) {
2
-
3
- @if type-of($b) == 'list' {
4
- @error 'Target ratios don’t work with multi-stranded modular scales.'
1
+ // Convert number string to number
2
+ @function ms-to-num($n) {
3
+ $l: str-length($n);
4
+ $r: 0;
5
+ $m: str-index($n,'.');
6
+ @if $m == null {
7
+ $m: $l + 1;
5
8
  }
9
+ // Loop through digits and convert to numbers
10
+ @for $i from 1 through $l {
11
+ $v: str-slice($n,$i,$i);
12
+ @if $v == '1' { $v: 1; }
13
+ @elseif $v == '2' { $v: 2; }
14
+ @elseif $v == '3' { $v: 3; }
15
+ @elseif $v == '4' { $v: 4; }
16
+ @elseif $v == '5' { $v: 5; }
17
+ @elseif $v == '6' { $v: 6; }
18
+ @elseif $v == '7' { $v: 7; }
19
+ @elseif $v == '8' { $v: 8; }
20
+ @elseif $v == '9' { $v: 9; }
21
+ @elseif $v == '0' { $v: 0; }
22
+ @else { $v: null; }
23
+ @if $v != null {
24
+ $m: $m - 1;
25
+ $r: $r + ms-pow(10,$m - 1) * $v;
26
+ } @else {
27
+ $l: $l - 1;
28
+ }
29
+ }
30
+ @return $r;
31
+ }
6
32
 
7
- // target value
8
- $v: ms-unitless($t);
9
- // base
10
- $b: ms-unitless($b);
11
- // Target place on the scale the value should match
12
- $t: str-slice(unit($t), 3);
13
-
14
- // Convert strings into numbers...
15
- @if $t == '0' { $t: 0; }
16
- @if $t == '1' { $t: 1; }
17
- @if $t == '2' { $t: 2; }
18
- @if $t == '3' { $t: 3; }
19
- @if $t == '4' { $t: 4; }
20
- @if $t == '5' { $t: 5; }
21
- @if $t == '6' { $t: 6; }
22
- @if $t == '7' { $t: 7; }
23
- @if $t == '8' { $t: 8; }
24
- @if $t == '9' { $t: 9; }
25
- @if $t == '10' { $t: 10; }
26
- @if $t == '11' { $t: 11; }
27
- @if $t == '12' { $t: 12; }
28
- @if $t == '13' { $t: 13; }
29
- @if $t == '14' { $t: 14; }
33
+ // Find a ratio based on a target value
34
+ @function ms-target($t,$b) {
35
+ // Convert to string
36
+ $t: $t + '';
37
+ // Remove base units to calulate ratio
38
+ $b: ms-unitless(nth($b,1));
39
+ // Find where 'at' is in the string
40
+ $at: str-index($t,'at');
30
41
 
31
- @if type-of($t) == 'string' {
32
- @error 'Please select an integer between 0 and 14 for a target value in modular scale.'
33
- }
42
+ // Slice the value and target out
43
+ // and convert strings to numbers
44
+ $v: ms-to-num(str-slice($t,0,$at - 1));
45
+ $t: ms-to-num(str-slice($t,$at + 2));
34
46
 
35
- // todo make this n root with n being $t
36
- @return pow(($v/$b),(1/$t));
47
+ // Solve the modular scale function for the ratio.
48
+ @return ms-pow(($v/$b),(1/$t));
37
49
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modular-scale
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Kellum
@@ -10,22 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-11-08 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: compass
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: 1.0.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: 1.0.0
13
+ date: 2017-04-02 00:00:00.000000000 Z
14
+ dependencies: []
29
15
  description: |-
30
16
  A modular scale is a list of values that share the same relationship. These
31
17
  values are often used to size type and create a sense of harmony in a design. Proportions within
@@ -57,7 +43,6 @@ files:
57
43
  - stylesheets/modularscale/_strip-units.scss
58
44
  - stylesheets/modularscale/_sugar.scss
59
45
  - stylesheets/modularscale/_target.scss
60
- - stylesheets/modularscale/_tests.scss
61
46
  - stylesheets/modularscale/_vars.scss
62
47
  homepage: http://modularscale.com
63
48
  licenses:
@@ -1,12 +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();