modular-scale 1.0.2 → 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/changelog.md +74 -0
- data/lib/modular-scale.rb +24 -108
- data/license.md +9 -0
- data/readme.md +188 -0
- data/stylesheets/_modularscale.scss +17 -0
- data/stylesheets/modularscale/_function.scss +53 -0
- data/stylesheets/modularscale/_pow.scss +39 -0
- data/stylesheets/modularscale/_respond.scss +58 -0
- data/stylesheets/modularscale/_round-px.scss +7 -0
- data/stylesheets/modularscale/_settings.scss +37 -0
- data/stylesheets/modularscale/_sort.scss +34 -0
- data/stylesheets/modularscale/_strip-units.scss +7 -0
- data/stylesheets/modularscale/_sugar.scss +7 -0
- data/stylesheets/modularscale/_target.scss +49 -0
- data/stylesheets/modularscale/_vars.scss +25 -0
- metadata +49 -75
- data/README.mdown +0 -126
- data/stylesheets/_modular-scale.sass +0 -220
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d514928d9de108ca949fe047fdf2e906f40bf68e
|
4
|
+
data.tar.gz: d25cab2c356567128b340e8c4500d07745b350f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d90e8b63152db176cc0ccdc23e5dba0c2e16afc87d57bc1a3e3424fc038a195b84a37f655c478a2fc683885f83c9d5f86b4450f5c257c6d362dd878361fc473e
|
7
|
+
data.tar.gz: f3dbabced398cd32d8d76fc8ed6dce98a8d93a8a915af5ee5dc7b5a49568ac7a914cb59bd93a37dfea07824ca1af42869f4675748658cb4da564f439fcdc9eee
|
data/changelog.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Version 3.0.8
|
2
|
+
|
3
|
+
* Fix issues with removal of rounding, sorry folks.
|
4
|
+
|
5
|
+
# Version 3.0.7
|
6
|
+
|
7
|
+
* Remove rounding.
|
8
|
+
|
9
|
+
# Version 3.0.6
|
10
|
+
|
11
|
+
* Fix deprecation warnings.
|
12
|
+
|
13
|
+
# Version 3.0.5
|
14
|
+
|
15
|
+
* Added an !important flag for specificity in some frameworks like IntuitCSS. [See pull 146 for details](https://github.com/modularscale/modularscale-sass/pull/146).
|
16
|
+
|
17
|
+
# Version 3.0.4
|
18
|
+
|
19
|
+
* Fixed line breaks in error messaging to be compatable with future versions of Sass.
|
20
|
+
|
21
|
+
# Version 3.0.3
|
22
|
+
|
23
|
+
* Updated version for eyeglass (1.2.1)
|
24
|
+
* Fixed scss file path for Bower
|
25
|
+
* Removed `npm-debug.log` file
|
26
|
+
|
27
|
+
# Version 3.0.2
|
28
|
+
|
29
|
+
* Fix bug when the exponent is 0
|
30
|
+
|
31
|
+
# Version 3.0.1
|
32
|
+
|
33
|
+
* Fix issue with generic `pow()` being used instead of `ms-pow()`
|
34
|
+
|
35
|
+
# Version 3.0.0
|
36
|
+
|
37
|
+
Core logic re-write along with settings moved to maps so they can be multithreaded and setup responsive scales better.
|
38
|
+
|
39
|
+
* Settings moved into a map.
|
40
|
+
* Multiple settings threads so you can use different scales in tandem.
|
41
|
+
* Removed the list funciton that outputs a list of values.
|
42
|
+
* Removed multiple ratio support because it was confusing and you should use multiple threads anyway. This dramatically reduced the core logic and bugs.
|
43
|
+
* Fluid is the only responsive setting.
|
44
|
+
* Responsive mixin automatically pulls breakpoints from map threads.
|
45
|
+
* find ratios based on target sizes at points on the scale.
|
46
|
+
|
47
|
+
# Version 2.1.1
|
48
|
+
|
49
|
+
Bugfix an `@else if` statement.
|
50
|
+
|
51
|
+
# Version 2.1.0
|
52
|
+
|
53
|
+
Ground-up re-write of ms-respond based on http://madebymike.com.au/writing/precise-control-responsive-typography/
|
54
|
+
|
55
|
+
# Version 2.0.6
|
56
|
+
|
57
|
+
Pixel rounding and responsive mixins
|
58
|
+
|
59
|
+
# Version 2.0.4
|
60
|
+
|
61
|
+
Version to the same release number as bower.
|
62
|
+
|
63
|
+
# Version 2.0.0
|
64
|
+
|
65
|
+
This is a breaking version. You will need to refactor slightly in order to upgrade to this version from a previous version.
|
66
|
+
|
67
|
+
* Complete re-write.
|
68
|
+
* ratios are variables, not functions
|
69
|
+
* Common variables are scoped to "ms-"
|
70
|
+
* ms-lists() is the list functions
|
71
|
+
* No more mixins at all, only functions.
|
72
|
+
* Increased compatibility with Sass 3.1 and up
|
73
|
+
* Compatibility with LibSass
|
74
|
+
* Compass no longer required (non-integer values require Compass)
|
data/lib/modular-scale.rb
CHANGED
@@ -1,118 +1,34 @@
|
|
1
|
+
# All gems that are required for this extension to work should go here.
|
2
|
+
# These are the requires you would normally put in your config.rb file
|
3
|
+
# By default, you should always included Compass. Do not include your
|
4
|
+
# extension.
|
1
5
|
require 'compass'
|
2
|
-
require 'sassy-math'
|
3
|
-
Compass::Frameworks.register("modular-scale", :path => "#{File.dirname(__FILE__)}/..")
|
4
6
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
7
|
+
# This tells Compass what your Compass extension is called, and where to find
|
8
|
+
# its files
|
9
|
+
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
10
|
+
Compass::Frameworks.register('modular-scale', :path => extension_path)
|
8
11
|
|
12
|
+
# Version and date of version for your Compass extension.
|
13
|
+
# Replace ModularScale with the name of your extension
|
14
|
+
# Letters, numbers, and underscores only
|
15
|
+
# Version is a number. If a version contains alphas, it will be created as
|
16
|
+
# a prerelease version
|
17
|
+
# Date is in the form of YYYY-MM-DD
|
9
18
|
module ModularScale
|
10
|
-
VERSION = "
|
11
|
-
DATE = "
|
19
|
+
VERSION = "3.0.8"
|
20
|
+
DATE = "2018-09-27"
|
12
21
|
end
|
13
22
|
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
class Number < Literal
|
18
|
-
# Comparison
|
19
|
-
def <=>(other)
|
20
|
-
value <=> other.value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
23
|
+
# This is where any custom SassScript should be placed. The functions will be
|
24
|
+
# available on require of your extension without the need for users to import
|
25
|
+
# any partials. Uncomment below.
|
24
26
|
|
25
27
|
module Sass::Script::Functions
|
26
|
-
# Modular Scale
|
27
|
-
def double_octave
|
28
|
-
value = 4 / 1.0
|
29
|
-
Sass::Script::Number.new(value)
|
30
|
-
end
|
31
|
-
def major_twelfth
|
32
|
-
value = 3 / 1.0
|
33
|
-
Sass::Script::Number.new(value)
|
34
|
-
end
|
35
|
-
def major_eleventh
|
36
|
-
value = 8 / 3.0
|
37
|
-
Sass::Script::Number.new(value)
|
38
|
-
end
|
39
|
-
def major_tenth
|
40
|
-
value = 5 / 2.0
|
41
|
-
Sass::Script::Number.new(value)
|
42
|
-
end
|
43
|
-
def octave
|
44
|
-
value = 2 / 1.0
|
45
|
-
Sass::Script::Number.new(value)
|
46
|
-
end
|
47
|
-
def major_seventh
|
48
|
-
value = 15 / 8.0
|
49
|
-
Sass::Script::Number.new(value)
|
50
|
-
end
|
51
|
-
def minor_seventh
|
52
|
-
value = 16 /9.0
|
53
|
-
Sass::Script::Number.new(value)
|
54
|
-
end
|
55
|
-
def major_sixth
|
56
|
-
value = 5 / 3.0
|
57
|
-
Sass::Script::Number.new(value)
|
58
|
-
end
|
59
|
-
def minor_sixth
|
60
|
-
value = 8 / 5.0
|
61
|
-
Sass::Script::Number.new(value)
|
62
|
-
end
|
63
|
-
def fifth
|
64
|
-
value = 3 / 2.0
|
65
|
-
Sass::Script::Number.new(value)
|
66
|
-
end
|
67
|
-
def augmented_forth
|
68
|
-
value = Math.sqrt(2) / 1.0
|
69
|
-
Sass::Script::Number.new(value)
|
70
|
-
end
|
71
|
-
def fourth
|
72
|
-
value = 4 / 3.0
|
73
|
-
Sass::Script::Number.new(value)
|
74
|
-
end
|
75
|
-
def major_third
|
76
|
-
value = 5 / 4.0
|
77
|
-
Sass::Script::Number.new(value)
|
78
|
-
end
|
79
|
-
def minor_third
|
80
|
-
value = 6 / 5.0
|
81
|
-
Sass::Script::Number.new(value)
|
82
|
-
end
|
83
|
-
def major_second
|
84
|
-
value = 9 / 8.0
|
85
|
-
Sass::Script::Number.new(value)
|
86
|
-
end
|
87
|
-
def minor_second
|
88
|
-
value = 16 / 15.0
|
89
|
-
Sass::Script::Number.new(value)
|
90
|
-
end
|
91
28
|
|
92
|
-
#
|
93
|
-
def
|
94
|
-
|
95
|
-
list = list.to_a.sort
|
96
|
-
Sass::Script::List.new(list, sep)
|
97
|
-
end
|
98
|
-
def reverse_list(list)
|
99
|
-
sep = list.separator if list.is_a?(Sass::Script::List)
|
100
|
-
list = list.to_a.reverse
|
101
|
-
Sass::Script::List.new(list, sep)
|
102
|
-
end
|
103
|
-
def trim_list(list, threshold, ascending)
|
104
|
-
# remove list items above or below a threshold
|
105
|
-
sep = list.separator if list.is_a?(Sass::Script::List)
|
106
|
-
list = list.to_a
|
107
|
-
if ascending.value
|
108
|
-
list = list.delete_if {
|
109
|
-
|x| x.value <= threshold.value
|
110
|
-
}
|
111
|
-
else
|
112
|
-
list = list.delete_if {
|
113
|
-
|x| x.value >= threshold.value
|
114
|
-
}
|
115
|
-
end
|
116
|
-
Sass::Script::List.new(list, sep)
|
29
|
+
# Let modularscale know that this was installed via Compass
|
30
|
+
def ms_gem_installed()
|
31
|
+
Sass::Script::Bool.new(true)
|
117
32
|
end
|
118
|
-
|
33
|
+
|
34
|
+
end
|
data/license.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright © 2018 [Scott Kellum](http://www.scottkellum.com/) ([@scottkellum](http://twitter.com/scottkellum)), [Adam Stacoviak](http://adamstacoviak.com/) ([@adamstac](http://twitter.com/adamstac)) and [Mason Wendell](http://thecodingdesigner.com/) ([@codingdesigner](http://twitter.com/codingdesigner))
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
**The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.**
|
data/readme.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
# Modular Scale
|
2
|
+
|
3
|
+
A modular scale is a list of values that share the same relationship. These values are often used to size type and create a sense of harmony in a design. Proportions within modular scales are all around us from the spacing of the joints on our fingers to branches on trees. These natural proportions have been used since the time of the ancient Greeks in architecture and design and can be a tremendously helpful tool to leverage for web designers.
|
4
|
+
|
5
|
+
Ems work especially well with modular scales as their recursive properties mimic modular scales making them more predictable and easier to manage. Pixels and other units work just fine and breakpoints in responsive web design can naturally fall on your scale to create better relevance to your text as all the values in your layout harmonize with each other.
|
6
|
+
|
7
|
+
To get started, you need to select a ratio and a base value. The base value is usually your text font size or 1em. Optionally you can add another value to create a double stranded modular scale which might be useful to create more options for in-between values. This base size paired with a ratio such as the golden ratio or any musical proportion will create your scale of values which all share this proportion.
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
### Eyeglass
|
12
|
+
|
13
|
+
* Terminal: `npm install modularscale-sass --save-dev`
|
14
|
+
* SCSS: `@import 'modularscale'`
|
15
|
+
|
16
|
+
### Webpack with sass-loader
|
17
|
+
|
18
|
+
* Terminal: `npm install modularscale-sass --save-dev`
|
19
|
+
* Webpack config: install and use [sass-loader](https://github.com/jtangelder/sass-loader#apply-via-webpack-config)
|
20
|
+
* SCSS: `@import '~modularscale-sass/stylesheets/modularscale';`
|
21
|
+
|
22
|
+
### Bower
|
23
|
+
|
24
|
+
* Terminal: `bower install modular-scale --save-dev`
|
25
|
+
* SCSS: `@import '../link_to_component_dir/modularscale';`
|
26
|
+
|
27
|
+
### Vanilla Sass
|
28
|
+
|
29
|
+
* [Download the latest zip](https://github.com/modularscale/modularscale-sass/releases/latest)
|
30
|
+
* Extract into your project
|
31
|
+
* SCSS: `@import 'modularscale';`
|
32
|
+
|
33
|
+
### Compass (no longer being updated. Last release v3.0.2)
|
34
|
+
|
35
|
+
* Terminal: `gem install modular-scale --pre`
|
36
|
+
* Compass config: `require 'modular-scale'`
|
37
|
+
* SCSS: `@import 'modularscale';`
|
38
|
+
|
39
|
+
## Using modular scale
|
40
|
+
|
41
|
+
#### Initial setup and usage:
|
42
|
+
|
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.
|
44
|
+
|
45
|
+
```scss
|
46
|
+
$modularscale: (
|
47
|
+
base: 1em,
|
48
|
+
ratio: 1.5
|
49
|
+
);
|
50
|
+
```
|
51
|
+
|
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.
|
53
|
+
|
54
|
+
```scss
|
55
|
+
$modularscale: (
|
56
|
+
base: 1em 1.2em 1.6em,
|
57
|
+
ratio: 1.5
|
58
|
+
);
|
59
|
+
```
|
60
|
+
|
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
|
+
|
63
|
+
```scss
|
64
|
+
h4 {
|
65
|
+
font-size: ms(3);
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
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.
|
74
|
+
|
75
|
+
```scss
|
76
|
+
$modularscale: (
|
77
|
+
base: 1em,
|
78
|
+
ratio: 1.5,
|
79
|
+
a: (
|
80
|
+
ratio: 1.3
|
81
|
+
)
|
82
|
+
);
|
83
|
+
```
|
84
|
+
|
85
|
+
To call the thread named `a`, call it in your function like so:
|
86
|
+
|
87
|
+
```scss
|
88
|
+
h5 {
|
89
|
+
font-size: ms(2, $thread: a);
|
90
|
+
}
|
91
|
+
```
|
92
|
+
|
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:
|
96
|
+
|
97
|
+
```scss
|
98
|
+
$modularscale: (
|
99
|
+
base: 12px,
|
100
|
+
ratio: 1.5,
|
101
|
+
400px: (
|
102
|
+
ratio: 1.2,
|
103
|
+
),
|
104
|
+
900px: (
|
105
|
+
base: 16px,
|
106
|
+
ratio: 1.3,
|
107
|
+
),
|
108
|
+
1200px: (
|
109
|
+
base: 16px,
|
110
|
+
ratio: 1.6,
|
111
|
+
),
|
112
|
+
);
|
113
|
+
```
|
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
|
+
|
119
|
+
Then, call the mixin `@include ms-respond();` and a fully fluid and responsive scale will be generated.
|
120
|
+
|
121
|
+
```scss
|
122
|
+
h2 {
|
123
|
+
@include ms-respond(font-size,5);
|
124
|
+
}
|
125
|
+
```
|
126
|
+
|
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.
|
128
|
+
|
129
|
+
#### Note on non-integer values
|
130
|
+
|
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 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.
|
132
|
+
|
133
|
+
#### Target sizes
|
134
|
+
|
135
|
+
_NOTE: Please see above section on non-integer values before using this feature_
|
136
|
+
|
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.
|
138
|
+
|
139
|
+
```scss
|
140
|
+
$modularscale: (
|
141
|
+
base: 16px,
|
142
|
+
ratio: 42at5
|
143
|
+
);
|
144
|
+
```
|
145
|
+
|
146
|
+
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.
|
147
|
+
|
148
|
+
## Ratios
|
149
|
+
|
150
|
+
Modular scale includes functions for a number of classic design and musical scale ratios. You can add your own ratios as well.
|
151
|
+
|
152
|
+
By default ratio is set to `$fifth`.
|
153
|
+
|
154
|
+
<table>
|
155
|
+
<tr><th>Function </th><th>Ratio </th><th>Decimal value</th></tr>
|
156
|
+
<tr><td>$phi </td><td>1:1.618</td><td>1.618 </td></tr>
|
157
|
+
<tr><td>$golden </td><td>1:1.618</td><td>1.618 </td></tr>
|
158
|
+
<tr><td>$double-octave </td><td>1:4 </td><td>4 </td></tr>
|
159
|
+
<tr><td>$major-twelfth </td><td>1:3 </td><td>3 </td></tr>
|
160
|
+
<tr><td>$major-eleventh </td><td>3:8 </td><td>2.667 </td></tr>
|
161
|
+
<tr><td>$major-tenth </td><td>2:5 </td><td>2.5 </td></tr>
|
162
|
+
<tr><td>$octave </td><td>1:2 </td><td>2 </td></tr>
|
163
|
+
<tr><td>$major-seventh </td><td>8:15 </td><td>1.875 </td></tr>
|
164
|
+
<tr><td>$minor-seventh </td><td>9:16 </td><td>1.778 </td></tr>
|
165
|
+
<tr><td>$major-sixth </td><td>3:5 </td><td>1.667 </td></tr>
|
166
|
+
<tr><td>$minor-sixth </td><td>5:8 </td><td>1.6 </td></tr>
|
167
|
+
<tr><td>$fifth </td><td>2:3 </td><td>1.5 </td></tr>
|
168
|
+
<tr><td>$augmented-fourth</td><td>1:√2 </td><td>1.414 </td></tr>
|
169
|
+
<tr><td>$fourth </td><td>3:4 </td><td>1.333 </td></tr>
|
170
|
+
<tr><td>$major-third </td><td>4:5 </td><td>1.25 </td></tr>
|
171
|
+
<tr><td>$minor-third </td><td>5:6 </td><td>1.2 </td></tr>
|
172
|
+
<tr><td>$major-second </td><td>8:9 </td><td>1.125 </td></tr>
|
173
|
+
<tr><td>$minor-second </td><td>15:16 </td><td>1.067 </td></tr>
|
174
|
+
</table>
|
175
|
+
|
176
|
+
## [Changelog](https://github.com/Team-Sass/modular-scale/releases)
|
177
|
+
|
178
|
+
### License
|
179
|
+
|
180
|
+
The MIT License (MIT)
|
181
|
+
|
182
|
+
Copyright © 2015 [Scott Kellum](http://www.scottkellum.com/) ([@scottkellum](http://twitter.com/scottkellum)), [Adam Stacoviak](http://adamstacoviak.com/) ([@adamstac](http://twitter.com/adamstac)) and [Mason Wendell](http://thecodingdesigner.com/) ([@codingdesigner](http://twitter.com/codingdesigner))
|
183
|
+
|
184
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
185
|
+
|
186
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
187
|
+
|
188
|
+
**The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.**
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// Defaults and variables
|
2
|
+
@import 'modularscale/vars';
|
3
|
+
|
4
|
+
// Core functions
|
5
|
+
@import 'modularscale/settings';
|
6
|
+
@import 'modularscale/pow';
|
7
|
+
@import 'modularscale/strip-units';
|
8
|
+
@import 'modularscale/sort';
|
9
|
+
@import 'modularscale/target';
|
10
|
+
@import 'modularscale/function';
|
11
|
+
@import 'modularscale/round-px';
|
12
|
+
|
13
|
+
// Mixins
|
14
|
+
@import 'modularscale/respond';
|
15
|
+
|
16
|
+
// Syntax sugar
|
17
|
+
@import 'modularscale/sugar';
|
@@ -0,0 +1,53 @@
|
|
1
|
+
@function ms-function($v: 0, $base: false, $ratio: false, $thread: false, $settings: $modularscale) {
|
2
|
+
|
3
|
+
// Parse settings
|
4
|
+
$ms-settings: ms-settings($base,$ratio,$thread,$settings);
|
5
|
+
$base: nth($ms-settings, 1);
|
6
|
+
$ratio: nth($ms-settings, 2);
|
7
|
+
|
8
|
+
// Render target values from settings.
|
9
|
+
@if unit($ratio) != '' {
|
10
|
+
$ratio: ms-target($ratio,$base)
|
11
|
+
}
|
12
|
+
|
13
|
+
// Fast calc if not multi stranded
|
14
|
+
@if(length($base) == 1) {
|
15
|
+
@return ms-pow($ratio, $v) * $base;
|
16
|
+
}
|
17
|
+
|
18
|
+
// Create new base array
|
19
|
+
$ms-bases: nth($base,1);
|
20
|
+
|
21
|
+
// Normalize base values
|
22
|
+
@for $i from 2 through length($base) {
|
23
|
+
// initial base value
|
24
|
+
$ms-base: nth($base,$i);
|
25
|
+
// If the base is bigger than the main base
|
26
|
+
@if($ms-base > nth($base,1)) {
|
27
|
+
// divide the value until it aligns with main base.
|
28
|
+
@while($ms-base > nth($base,1)) {
|
29
|
+
$ms-base: $ms-base / $ratio;
|
30
|
+
}
|
31
|
+
$ms-base: $ms-base * $ratio;
|
32
|
+
}
|
33
|
+
// If the base is smaller than the main base.
|
34
|
+
@else if ($ms-base < nth($base,1)) {
|
35
|
+
// pump up the value until it aligns with main base.
|
36
|
+
@while $ms-base < nth($base,1) {
|
37
|
+
$ms-base: $ms-base * $ratio;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
// Push into new array
|
41
|
+
$ms-bases: append($ms-bases,$ms-base);
|
42
|
+
}
|
43
|
+
|
44
|
+
// Sort array from smallest to largest.
|
45
|
+
$ms-bases: ms-sort($ms-bases);
|
46
|
+
|
47
|
+
// Find step to use in calculation
|
48
|
+
$vtep: floor($v / length($ms-bases));
|
49
|
+
// Find base to use in calculation
|
50
|
+
$ms-base: round(($v / length($ms-bases) - $vtep) * length($ms-bases)) + 1;
|
51
|
+
|
52
|
+
@return ms-pow($ratio, $vtep) * nth($ms-bases,$ms-base);
|
53
|
+
}
|
@@ -0,0 +1,39 @@
|
|
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
|
+
|
6
|
+
@function ms-pow($b,$e) {
|
7
|
+
|
8
|
+
// Return 1 if exponent is 0
|
9
|
+
@if $e == 0 {
|
10
|
+
@return 1;
|
11
|
+
}
|
12
|
+
|
13
|
+
// If pow() exists (compass or mathsass) use that.
|
14
|
+
@if function-exists('pow') {
|
15
|
+
@return pow($b,$e);
|
16
|
+
}
|
17
|
+
|
18
|
+
// This does not support non-integer exponents,
|
19
|
+
// Check and return an error if a non-integer exponent is passed.
|
20
|
+
@if (floor($e) != $e) {
|
21
|
+
@error 'Non-integer values are not supported in modularscale by default. Try using mathsass in your project to add non-integer scale support. https://github.com/terkel/mathsass'
|
22
|
+
}
|
23
|
+
|
24
|
+
// Seed the return.
|
25
|
+
$ms-return: $b;
|
26
|
+
|
27
|
+
// Multiply or divide by the specified number of times.
|
28
|
+
@if $e > 0 {
|
29
|
+
@for $i from 1 to $e {
|
30
|
+
$ms-return: $ms-return * $b;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
@if $e < 0 {
|
34
|
+
@for $i from $e through 0 {
|
35
|
+
$ms-return: $ms-return / $b;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
@return $ms-return;
|
39
|
+
}
|
@@ -0,0 +1,58 @@
|
|
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/
|
4
|
+
@function ms-fluid($val1: 1em, $val2: 1em, $break1: 0, $break2: 0) {
|
5
|
+
$diff: ms-unitless($val2) - ms-unitless($val1);
|
6
|
+
|
7
|
+
// v1 + (v2 - v1) * ( (100vw - b1) / b2 - b1 )
|
8
|
+
@return calc( #{$val1} + #{ms-unitless($val2) - ms-unitless($val1)} * ( ( 100vw - #{$break1}) / #{ms-unitless($break2) - ms-unitless($break1)} ) );
|
9
|
+
}
|
10
|
+
|
11
|
+
// Main responsive mixin
|
12
|
+
@mixin ms-respond($prop, $val, $map: $modularscale, $ms-important: false) {
|
13
|
+
$base: $ms-base;
|
14
|
+
$ratio: $ms-ratio;
|
15
|
+
|
16
|
+
$first-write: true;
|
17
|
+
$last-break: null;
|
18
|
+
|
19
|
+
$important: '';
|
20
|
+
|
21
|
+
@if $ms-important == true {
|
22
|
+
$important: ' !important';
|
23
|
+
}
|
24
|
+
|
25
|
+
// loop through all settings with a breakpoint type value
|
26
|
+
@each $v, $s in $map {
|
27
|
+
@if type-of($v) == number {
|
28
|
+
@if unit($v) != '' {
|
29
|
+
|
30
|
+
// Write out the first value without a media query.
|
31
|
+
@if $first-write {
|
32
|
+
#{$prop}: unquote("#{ms-function($val, $thread: $v, $settings: $map)}#{$important}");
|
33
|
+
|
34
|
+
// Not the first write anymore, reset to false to move on.
|
35
|
+
$first-write: false;
|
36
|
+
$last-break: $v;
|
37
|
+
}
|
38
|
+
|
39
|
+
// Write intermediate breakpoints.
|
40
|
+
@else {
|
41
|
+
@media (min-width: $last-break) and (max-width: $v) {
|
42
|
+
$val1: ms-function($val, $thread: $last-break, $settings: $map);
|
43
|
+
$val2: ms-function($val, $thread: $v, $settings: $map);
|
44
|
+
#{$prop}: unquote("#{ms-fluid($val1,$val2,$last-break,$v)}#{$important}");
|
45
|
+
}
|
46
|
+
$last-break: $v;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
// Write the last breakpoint.
|
53
|
+
@if $last-break {
|
54
|
+
@media (min-width: $last-break) {
|
55
|
+
#{$prop}: unquote("#{ms-function($val, $thread: $last-break, $settings: $map)}#{$important}");
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// Parse settings starting with defaults.
|
2
|
+
// Settings should cascade down like you would expect in CSS.
|
3
|
+
// More specific overrides previous settings.
|
4
|
+
|
5
|
+
@function ms-settings($b: false, $r: false, $t: false, $m: $modularscale) {
|
6
|
+
$base: $ms-base;
|
7
|
+
$ratio: $ms-ratio;
|
8
|
+
$thread: map-get($m, $t);
|
9
|
+
|
10
|
+
// Override with user settings
|
11
|
+
@if map-get($m, base) {
|
12
|
+
$base: map-get($m, base);
|
13
|
+
}
|
14
|
+
@if map-get($m, ratio) {
|
15
|
+
$ratio: map-get($m, ratio);
|
16
|
+
}
|
17
|
+
|
18
|
+
// Override with thread settings
|
19
|
+
@if $thread {
|
20
|
+
@if map-get($thread, base) {
|
21
|
+
$base: map-get($thread, base);
|
22
|
+
}
|
23
|
+
@if map-get($thread, ratio) {
|
24
|
+
$ratio: map-get($thread, ratio);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
// Override with inline settings
|
29
|
+
@if $b {
|
30
|
+
$base: $b;
|
31
|
+
}
|
32
|
+
@if $r {
|
33
|
+
$ratio: $r;
|
34
|
+
}
|
35
|
+
|
36
|
+
@return $base $ratio;
|
37
|
+
}
|
@@ -0,0 +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
|
+
|
5
|
+
@function ms-sort($l) {
|
6
|
+
|
7
|
+
// loop until the list is confirmed to be sorted
|
8
|
+
$sorted: false;
|
9
|
+
@while $sorted == false {
|
10
|
+
|
11
|
+
// Start with the assumption that the lists are sorted.
|
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.
|
17
|
+
@for $i from 2 through length($l) {
|
18
|
+
$n1: nth($l,$i - 1);
|
19
|
+
$n2: nth($l,$i);
|
20
|
+
|
21
|
+
// If the first value is greater than the 2nd, swap them.
|
22
|
+
@if $n1 > $n2 {
|
23
|
+
$l: set-nth($l, $i, $n1);
|
24
|
+
$l: set-nth($l, $i - 1, $n2);
|
25
|
+
|
26
|
+
// The list isn't sorted and needs to be looped through again.
|
27
|
+
$sorted: false;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
// Return the sorted list.
|
33
|
+
@return $l;
|
34
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// Stripping units is not a best practice
|
2
|
+
// This function should not be used elsewhere
|
3
|
+
// It is used here because calc() doesn't do unit logic
|
4
|
+
// AND target ratios use units as a hack to get a number.
|
5
|
+
@function ms-unitless($val) {
|
6
|
+
@return ($val / ($val - $val + 1));
|
7
|
+
}
|
@@ -0,0 +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
|
+
|
5
|
+
@function ms($v: 0, $base: false, $ratio: false, $thread: false, $settings: $modularscale) {
|
6
|
+
@return ms-function($v, $base, $ratio, $thread, $settings);
|
7
|
+
}
|
@@ -0,0 +1,49 @@
|
|
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;
|
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
|
+
@else if $v == '2' { $v: 2; }
|
14
|
+
@else if $v == '3' { $v: 3; }
|
15
|
+
@else if $v == '4' { $v: 4; }
|
16
|
+
@else if $v == '5' { $v: 5; }
|
17
|
+
@else if $v == '6' { $v: 6; }
|
18
|
+
@else if $v == '7' { $v: 7; }
|
19
|
+
@else if $v == '8' { $v: 8; }
|
20
|
+
@else if $v == '9' { $v: 9; }
|
21
|
+
@else if $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
|
+
}
|
32
|
+
|
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');
|
41
|
+
|
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));
|
46
|
+
|
47
|
+
// Solve the modular scale function for the ratio.
|
48
|
+
@return ms-pow(($v/$b),(1/$t));
|
49
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// Ratios
|
2
|
+
$double-octave : 4 ;
|
3
|
+
$pi : 3.14159265359 ;
|
4
|
+
$major-twelfth : 3 ;
|
5
|
+
$major-eleventh : 2.666666667 ;
|
6
|
+
$major-tenth : 2.5 ;
|
7
|
+
$octave : 2 ;
|
8
|
+
$major-seventh : 1.875 ;
|
9
|
+
$minor-seventh : 1.777777778 ;
|
10
|
+
$major-sixth : 1.666666667 ;
|
11
|
+
$phi : 1.618034 ;
|
12
|
+
$golden : $phi ;
|
13
|
+
$minor-sixth : 1.6 ;
|
14
|
+
$fifth : 1.5 ;
|
15
|
+
$augmented-fourth : 1.41421 ;
|
16
|
+
$fourth : 1.333333333 ;
|
17
|
+
$major-third : 1.25 ;
|
18
|
+
$minor-third : 1.2 ;
|
19
|
+
$major-second : 1.125 ;
|
20
|
+
$minor-second : 1.066666667 ;
|
21
|
+
|
22
|
+
// Base config
|
23
|
+
$ms-base : 1em !default;
|
24
|
+
$ms-ratio : $fifth !default;
|
25
|
+
$modularscale : () !default;
|
metadata
CHANGED
@@ -1,97 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: modular-scale
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: 1.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.8
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Scott Kellum
|
13
|
-
- Adam Stacoviak
|
14
8
|
- Mason Wendell
|
9
|
+
- Adam Stacoviak
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 11
|
32
|
-
- 5
|
33
|
-
version: 0.11.5
|
34
|
-
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: sassy-math
|
38
|
-
prerelease: false
|
39
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 1
|
45
|
-
- 2
|
46
|
-
version: "1.2"
|
47
|
-
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
|
-
description: Sassy Modular Scale calculates the incremental values of the modular scale.
|
50
|
-
email:
|
13
|
+
date: 2018-09-27 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: |-
|
16
|
+
A modular scale is a list of values that share the same relationship. These
|
17
|
+
values are often used to size type and create a sense of harmony in a design. Proportions within
|
18
|
+
modular scales are all around us from the spacing of the joints on our fingers to branches on
|
19
|
+
trees. These natural proportions have been used since the time of the ancient Greeks in
|
20
|
+
architecture and design and can be a tremendously helpful tool to leverage for web designers.
|
21
|
+
email:
|
51
22
|
- scott@scottkellum.com
|
23
|
+
- mason@thecodingdesigner.com
|
52
24
|
- adam@stacoviak.com
|
53
|
-
- mason@canarypromo.com
|
54
25
|
executables: []
|
55
|
-
|
56
26
|
extensions: []
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
27
|
+
extra_rdoc_files:
|
28
|
+
- changelog.md
|
29
|
+
- license.md
|
30
|
+
- readme.md
|
31
|
+
files:
|
32
|
+
- changelog.md
|
62
33
|
- lib/modular-scale.rb
|
63
|
-
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
34
|
+
- license.md
|
35
|
+
- readme.md
|
36
|
+
- stylesheets/_modularscale.scss
|
37
|
+
- stylesheets/modularscale/_function.scss
|
38
|
+
- stylesheets/modularscale/_pow.scss
|
39
|
+
- stylesheets/modularscale/_respond.scss
|
40
|
+
- stylesheets/modularscale/_round-px.scss
|
41
|
+
- stylesheets/modularscale/_settings.scss
|
42
|
+
- stylesheets/modularscale/_sort.scss
|
43
|
+
- stylesheets/modularscale/_strip-units.scss
|
44
|
+
- stylesheets/modularscale/_sugar.scss
|
45
|
+
- stylesheets/modularscale/_target.scss
|
46
|
+
- stylesheets/modularscale/_vars.scss
|
47
|
+
homepage: http://modularscale.com
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
68
51
|
post_install_message:
|
69
52
|
rdoc_options: []
|
70
|
-
|
71
|
-
require_paths:
|
53
|
+
require_paths:
|
72
54
|
- lib
|
73
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
75
57
|
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
82
62
|
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
segments:
|
85
|
-
- 1
|
86
|
-
- 3
|
87
|
-
- 6
|
63
|
+
- !ruby/object:Gem::Version
|
88
64
|
version: 1.3.6
|
89
65
|
requirements: []
|
90
|
-
|
91
66
|
rubyforge_project:
|
92
|
-
rubygems_version:
|
67
|
+
rubygems_version: 2.5.2.3
|
93
68
|
signing_key:
|
94
|
-
specification_version:
|
95
|
-
summary:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Modular scale calculator built into your Sass.
|
96
71
|
test_files: []
|
97
|
-
|
data/README.mdown
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
# Sassy Modular Scale
|
2
|
-
|
3
|
-
## Put down the calculator and let Sass do the work.
|
4
|
-
|
5
|
-
Sassy Modular Scale is a Sass based mixin that calculates the incremental values of the modular scale in proportion to a set size and ratio. It was inspired by and adapted from Tim Brown's modularscale.com.
|
6
|
-
|
7
|
-
Sassy Modular Scale can be used as a [Compass](http://compass-style.org/) [extension](http://compass-style.org/help/tutorials/extensions/) and can be installed as a [Ruby gem](https://rubygems.org/gems/modular-scale).
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Usage requires Sass. Visit [sass-lang.com](http://sass-lang.com) to learn more and install.
|
12
|
-
|
13
|
-
`gem install modular-scale`
|
14
|
-
|
15
|
-
Add `require 'modular-scale'` to your Compass config file.
|
16
|
-
|
17
|
-
Import the file into your stylesheets: `@import 'modular-scale';`
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
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.
|
22
|
-
|
23
|
-
```scss
|
24
|
-
width: modular-scale(2); // two up the modular scale
|
25
|
-
width: ms(2); // Shorthand for the line above
|
26
|
-
width: modular-scale(2, 1em); // two up the modular scale with a base size of 1em
|
27
|
-
width: modular-scale(2, 1em, $octave); // Same as above but on an octave scale
|
28
|
-
```
|
29
|
-
|
30
|
-
You can output a list to your terminal to help you find out what values are on your scale.
|
31
|
-
|
32
|
-
```scss
|
33
|
-
@include modular-scale-list($start, $end, $base-size, $ratio);
|
34
|
-
```
|
35
|
-
|
36
|
-
By default, it writes 0-20 on the scale. You can also use shorthand to make things more efficient.
|
37
|
-
|
38
|
-
```scss
|
39
|
-
@include ms-list; // shorthand without attributes
|
40
|
-
@include ms-list($start, $end, $base-size, $ratio); // shorthand with attributes
|
41
|
-
```
|
42
|
-
|
43
|
-
As a side effect of the modular-scale functions a `exponent` function is also available.
|
44
|
-
|
45
|
-
```scss
|
46
|
-
@include exponent($base, $exponent);
|
47
|
-
```
|
48
|
-
|
49
|
-
Sassy Modular Scale can be used as a function, like so:
|
50
|
-
|
51
|
-
```scss
|
52
|
-
// Use as a function. Fill in the multiple, base-size, and ratio
|
53
|
-
height: modular-scale(7, 16px, $golden);
|
54
|
-
```
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
You can also 'lace' multiple ratios together by passing them in as a list (space-separated)
|
59
|
-
|
60
|
-
```scss
|
61
|
-
.lace {
|
62
|
-
width: ms(7, 16px, $golden $fourth);
|
63
|
-
}
|
64
|
-
```
|
65
|
-
|
66
|
-
You can also set the $base-size variable to a list to interrelate two significant known sizes in your design
|
67
|
-
*note:* the starting point of the scale will always be the *lowest* value in this list
|
68
|
-
|
69
|
-
```scss
|
70
|
-
.multibases {
|
71
|
-
width: ms(7, 16px 300px, $golden);
|
72
|
-
}
|
73
|
-
```
|
74
|
-
|
75
|
-
You can use multiple $base-sizes and multiple $ratios together
|
76
|
-
|
77
|
-
```scss
|
78
|
-
.multibase-multiratio {
|
79
|
-
width: ms(7, 16px 300px, $golden $fourth);
|
80
|
-
}
|
81
|
-
```
|
82
|
-
|
83
|
-
|
84
|
-
## Ratios
|
85
|
-
|
86
|
-
The included ratios are called by functions. You can add your own ratios as well.
|
87
|
-
|
88
|
-
Below is a list of ratios to choose from. By default, the variable `$ratio` is set to `golden()`.
|
89
|
-
|
90
|
-
* golden()
|
91
|
-
* double-octave()
|
92
|
-
* major-twelfth()
|
93
|
-
* major-eleventh()
|
94
|
-
* major-tenth()
|
95
|
-
* octave()
|
96
|
-
* major-seventh()
|
97
|
-
* minor-seventh()
|
98
|
-
* major-sixth()
|
99
|
-
* minor-sixth()
|
100
|
-
* fifth()
|
101
|
-
* augfourth()
|
102
|
-
* fourth()
|
103
|
-
* major-third()
|
104
|
-
* minor-third()
|
105
|
-
* major-second()
|
106
|
-
* minor-second()
|
107
|
-
|
108
|
-
Add your own ratio in Sass by setting a variable and passing that to modular-scale.
|
109
|
-
|
110
|
-
```scss
|
111
|
-
$my-variable: 1 / 3.14159265;
|
112
|
-
```
|
113
|
-
|
114
|
-
## Inspiration
|
115
|
-
|
116
|
-
Sassy Modular Scale was adapted from [modularscale.com](http://modularscale.com/) by Tim Brown ([@nicewebtype](http://twitter.com/nicewebtype)). Tim also wrote a supporting article at [A List Apart](http://www.alistapart.com/) titled ["More Meaningful Typography"](http://www.alistapart.com/articles/more-meaningful-typography/). Additional inspiration goes to [Robert Bringhurst](http://en.wikipedia.org/wiki/Robert_Bringhurst), author of ["The Elements of Typographic Style"](http://en.wikipedia.org/wiki/The_Elements_of_Typographic_Style) - specifically Chapter 8 titled "Shaping the Page"
|
117
|
-
|
118
|
-
## License
|
119
|
-
|
120
|
-
Copyright (c) 2011 [Scott Kellum](http://www.scottkellum.com/) ([@scottkellum](http://twitter.com/scottkellum)), [Adam Stacoviak](http://adamstacoviak.com/) ([@adamstac](http://twitter.com/adamstac)) and [Mason Wendell](http://thecodingdesigner.com/) ([@codingdesigner](http://twitter.com/codingdesigner))
|
121
|
-
|
122
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
123
|
-
|
124
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
125
|
-
|
126
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,220 +0,0 @@
|
|
1
|
-
// SASSY MODULAR-SCALE
|
2
|
-
// https://github.com/scottkellum/modular-scale
|
3
|
-
|
4
|
-
// Defaults
|
5
|
-
$ratio: golden_ratio() !default
|
6
|
-
$base-size: 16px !default
|
7
|
-
$round_pixels: true !default
|
8
|
-
|
9
|
-
// Modular Scale function
|
10
|
-
@function modular-scale($multiple, $base-size: $base-size, $ratio: $ratio, $round_pixels: $round_pixels)
|
11
|
-
// return the $base-size if $multiple is zero
|
12
|
-
@if $multiple == 0
|
13
|
-
@if type-of($base-size) == 'list'
|
14
|
-
$base-size: sort_list($base-size)
|
15
|
-
@return nth($base-size, 1)
|
16
|
-
// return just the simple $base-size value if it's not a list
|
17
|
-
@return $base-size
|
18
|
-
|
19
|
-
// if multiple base-sizes are passed in as a list
|
20
|
-
// and multiple ratios are passed in as a list
|
21
|
-
// calculate values in using each base-size / ratio combination
|
22
|
-
@if type-of($base-size) == 'list' and type-of($ratio) == 'list'
|
23
|
-
@if unit(ms-multibase-multiratio($multiple, $base-size, $ratio)) == 'px' and $round_pixels == true
|
24
|
-
@return round(ms-multibase-multiratio($multiple, $base-size, $ratio))
|
25
|
-
@return ms-multibase-multiratio($multiple, $base-size, $ratio)
|
26
|
-
|
27
|
-
// if multiple base-sizes are passed in as a list
|
28
|
-
// calculate values in using each base-size
|
29
|
-
@if type-of($base-size) == 'list' and type-of($ratio) == 'number'
|
30
|
-
@if unit(ms-multibase($multiple, $base-size, $ratio)) == 'px' and $round_pixels == true
|
31
|
-
@return round(ms-multibase($multiple, $base-size, $ratio))
|
32
|
-
@return ms-multibase($multiple, $base-size, $ratio)
|
33
|
-
|
34
|
-
// if multiple ratios are passed in as a list
|
35
|
-
// calculate values in using each ratio
|
36
|
-
@if type-of($base-size) == 'number' and type-of($ratio) == 'list'
|
37
|
-
@if unit(ms-multiratio($multiple, $base-size, $ratio)) == 'px' and $round_pixels == true
|
38
|
-
@return round(ms-multiratio($multiple, $base-size, $ratio))
|
39
|
-
@return ms-multiratio($multiple, $base-size, $ratio)
|
40
|
-
|
41
|
-
// If there are no lists just run the simple function
|
42
|
-
@if unit(power($ratio, $multiple) * $base-size) == 'px' and $round_pixels == true
|
43
|
-
@return round(power($ratio, $multiple) * $base-size)
|
44
|
-
@return power($ratio, $multiple) * $base-size
|
45
|
-
|
46
|
-
|
47
|
-
// calculate values in using each base-size / ratio combination
|
48
|
-
@function ms-multibase-multiratio($multiple, $base-size, $ratio)
|
49
|
-
// start with an empty list to place all values in
|
50
|
-
$scale-values: ()
|
51
|
-
// make sure base sizes are in ascending order
|
52
|
-
$base-size: sort_list($base-size)
|
53
|
-
// take each base-size in turn
|
54
|
-
$k: 1
|
55
|
-
@while $k <= length($base-size)
|
56
|
-
// add each $base-size to the list except the first
|
57
|
-
@if $k > 1
|
58
|
-
$scale-values: append($scale-values, nth($base-size, $k))
|
59
|
-
// take each ratio in turn
|
60
|
-
$j: 1
|
61
|
-
@while $j <= length($ratio)
|
62
|
-
// reset $modular-scale for each set
|
63
|
-
$modular-scale: nth($base-size, $k)
|
64
|
-
// do the scale for each base-size using this ratio
|
65
|
-
@if $multiple > 0
|
66
|
-
// up $multiple times
|
67
|
-
// and add the result to $scale-values
|
68
|
-
@for $i from 1 through $multiple
|
69
|
-
$modular-scale: power(nth($ratio, $j), $i) * nth($base-size, $k)
|
70
|
-
$scale-values: append($scale-values, $modular-scale)
|
71
|
-
// and down until the value is lower than the lowest $base-size
|
72
|
-
// and add the result to $scale-values
|
73
|
-
$i: -1
|
74
|
-
$modular-scale: nth($base-size, $k)
|
75
|
-
@while $modular-scale >= nth($base-size, 1)
|
76
|
-
$modular-scale: power(nth($ratio, $j), $i) * nth($base-size, $k)
|
77
|
-
$scale-values: append($scale-values, $modular-scale)
|
78
|
-
$i: $i - 1
|
79
|
-
@if $multiple < 0
|
80
|
-
// do the scale down for each set to below 1px
|
81
|
-
$i: 0
|
82
|
-
$modular-scale: nth($base-size, $k)
|
83
|
-
@while $i >= $multiple
|
84
|
-
$modular-scale: power(nth($ratio, $j), $i) * nth($base-size, $k)
|
85
|
-
$scale-values: append($scale-values, $modular-scale)
|
86
|
-
$i: $i - 1
|
87
|
-
$j: $j + 1
|
88
|
-
$k: $k + 1
|
89
|
-
// return trimmed and sorted final list
|
90
|
-
@return trim-sort($multiple, $scale-values, $base-size)
|
91
|
-
|
92
|
-
|
93
|
-
// calculate values in using each base-size
|
94
|
-
@function ms-multibase($multiple, $base-size, $ratio)
|
95
|
-
// start with an empty list to place all values in
|
96
|
-
$scale-values: ()
|
97
|
-
// make sure base sizes are in ascending order
|
98
|
-
$base-size: sort_list($base-size)
|
99
|
-
// take each base-size in turn
|
100
|
-
$k: 1
|
101
|
-
@while $k <= length($base-size)
|
102
|
-
// add each $base-size to the list except the first
|
103
|
-
@if $k > 1
|
104
|
-
$scale-values: append($scale-values, nth($base-size, $k))
|
105
|
-
// reset $modular-scale for each set
|
106
|
-
$modular-scale: nth($base-size, $k)
|
107
|
-
// do the scale for each base-size using this ratio
|
108
|
-
@if $multiple > 0
|
109
|
-
// up $multiple times
|
110
|
-
// and add the result to $scale-values
|
111
|
-
@for $i from 1 through $multiple
|
112
|
-
$modular-scale: power($ratio, $i) * nth($base-size, $k)
|
113
|
-
$scale-values: append($scale-values, $modular-scale)
|
114
|
-
// and down until the value is lower than the lowest $base-size
|
115
|
-
// and add the result to $scale-values
|
116
|
-
$i: -1
|
117
|
-
$modular-scale: nth($base-size, $k)
|
118
|
-
@while $modular-scale >= nth($base-size, 1)
|
119
|
-
$modular-scale: power($ratio, $i) * nth($base-size, $k)
|
120
|
-
$scale-values: append($scale-values, $modular-scale)
|
121
|
-
$i: $i - 1
|
122
|
-
@if $multiple < 0
|
123
|
-
// do the scale down for each set to below 1px
|
124
|
-
$i: 0
|
125
|
-
$modular-scale: nth($base-size, $k)
|
126
|
-
@while $i >= $multiple
|
127
|
-
$modular-scale: power($ratio, $i) * nth($base-size, $k)
|
128
|
-
$scale-values: append($scale-values, $modular-scale)
|
129
|
-
$i: $i - 1
|
130
|
-
$k: $k + 1
|
131
|
-
// return trimmed and sorted final list
|
132
|
-
@return trim-sort($multiple, $scale-values, $base-size)
|
133
|
-
|
134
|
-
|
135
|
-
// calculate values in using each ratio
|
136
|
-
@function ms-multiratio($multiple, $base-size, $ratio)
|
137
|
-
// start with an empty list to place all values in
|
138
|
-
$scale-values: ()
|
139
|
-
// If $multiple is a positive integer (up the scale)
|
140
|
-
@if $multiple > 0
|
141
|
-
// take each ratio in turn
|
142
|
-
$j: 1
|
143
|
-
@while $j <= length($ratio)
|
144
|
-
// reset $modular-scale for each set
|
145
|
-
$modular-scale: $base-size
|
146
|
-
// do the scale using this ratio thru the multiple, and add the result to $scale-values
|
147
|
-
@for $i from 1 through $multiple
|
148
|
-
$modular-scale: power(nth($ratio, $j), $i) * $base-size
|
149
|
-
$scale-values: append($scale-values, $modular-scale)
|
150
|
-
$j: $j + 1
|
151
|
-
// sort acsending
|
152
|
-
$scale-values: sort_list($scale-values)
|
153
|
-
// return the final value using the laced list
|
154
|
-
@return nth($scale-values, $multiple)
|
155
|
-
// If $multiple is a negative integer (down the scale)
|
156
|
-
@if $multiple < 0
|
157
|
-
// take each ratio in turn
|
158
|
-
$j: 1
|
159
|
-
@while $j <= length($ratio)
|
160
|
-
// reset $modular-scale for each set
|
161
|
-
$modular-scale: $base-size
|
162
|
-
// do the scale using this ratio thru the multiple, and add the result to $scale-values
|
163
|
-
@for $i from 1 through ($multiple * -1)
|
164
|
-
$modular-scale: power(nth($ratio, $j), -$i) * $base-size
|
165
|
-
$scale-values: append($scale-values, $modular-scale)
|
166
|
-
$j: $j + 1
|
167
|
-
// sort decending
|
168
|
-
$scale-values: reverse_list(sort_list($scale-values))
|
169
|
-
// return the final value using the laced list
|
170
|
-
@return nth($scale-values, $multiple * -1)
|
171
|
-
|
172
|
-
|
173
|
-
// trim and sort the final list
|
174
|
-
@function trim-sort($multiple, $scale-values, $base-size)
|
175
|
-
@if $multiple > 0
|
176
|
-
// trim list so we can count from the lowest $base-size
|
177
|
-
$scale-values: trim_list($scale-values, nth($base-size, 1), true)
|
178
|
-
// sort acsending
|
179
|
-
$scale-values: sort_list($scale-values)
|
180
|
-
// return the final value using the laced list
|
181
|
-
@return nth($scale-values, $multiple)
|
182
|
-
@else
|
183
|
-
// trim list so we can count from the lowest $base-size
|
184
|
-
$scale-values: trim_list($scale-values, nth($base-size, 1), false)
|
185
|
-
// sort acsending
|
186
|
-
$scale-values: reverse_list(sort_list($scale-values))
|
187
|
-
// return the final value using the laced list
|
188
|
-
@return nth($scale-values, -$multiple)
|
189
|
-
|
190
|
-
|
191
|
-
/////////////////////////////////////////////////////////////////////////
|
192
|
-
|
193
|
-
// alias for golden_ratio()
|
194
|
-
@function golden()
|
195
|
-
@return golden_ratio()
|
196
|
-
|
197
|
-
// Shortcut
|
198
|
-
@function ms($args...)
|
199
|
-
// Return the value from the Modular Scale function
|
200
|
-
@return modular-scale($args...)
|
201
|
-
|
202
|
-
// Write Modular Scale List
|
203
|
-
@function modular-scale-list($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio)
|
204
|
-
$ms-list: unquote("MS-LIST:")
|
205
|
-
@for $i from $start through $finish
|
206
|
-
$ms-list: append($ms-list, ms($i, $base-size, $ratio))
|
207
|
-
@return $ms-list
|
208
|
-
|
209
|
-
@function ms-list($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio)
|
210
|
-
@return modular-scale-list($start, $finish, $base-size, $ratio)
|
211
|
-
|
212
|
-
=modular-scale-list($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio)
|
213
|
-
@debug modular-scale-list($start, $finish, $base-size, $ratio)
|
214
|
-
|
215
|
-
=ms-list($start: 0, $finish: 20, $base-size: $base-size, $ratio: $ratio)
|
216
|
-
@debug modular-scale-list($start, $finish, $base-size, $ratio)
|
217
|
-
|
218
|
-
|
219
|
-
// Other libraries can easily query if this function is avalible
|
220
|
-
$modular-scale-loaded: true
|