type-director 0.8 → 0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f3c69ad4cffb5ad9de8771730d4896f8d70bea8
4
- data.tar.gz: 157eda8173d909e5d61baf484ea462a47adb1d1c
3
+ metadata.gz: 1a07ea61bcc2bb553dd26cdd142224b67198eca5
4
+ data.tar.gz: 257a8e2ee3726c18ad8e2d02d95415300a958c7f
5
5
  SHA512:
6
- metadata.gz: 26eae284ce0b33847e048e2b8e194c243e88632e8ce1924c7e409796a5c6ce57bfe45beebad8d3329f2f66b787174c7bc737874549b7086f6e2c7cbbadb287e3
7
- data.tar.gz: 463a852223ec99cfe9921f983b8c0deb23a780e8a1ab460c5371a3bf9f694a20ddcfa078d364b54d38edabfa1059688686e8f8a39852dce922c2ec9683b7672f
6
+ metadata.gz: 608d93c0744c122b5eb73e660eb38ea5680f615258b566fec5d97bd113152956e150567aa3fc5ec297b34e8b6e409bca39978912ed7e7734db1422c3c3256efb
7
+ data.tar.gz: 516936a7ce8c135002f2e687e08ff0b40b13c9121cc70c1740745af1b69e564f626950c74635c07d91fcf946346b8710c8d041b7260c65f35af3423eea715463
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
 
2
2
  # Type Director
3
3
 
4
- Type Director is a SASS framework for defining and applying typographic styles. Its goal is to generate a complex, nuanced typographic system from only a few key variables.
4
+ Type Director is a SASS framework that generates a responsive, modular, nuanced typographic system from only a few key variables.
5
5
 
6
6
 
7
7
 
8
8
  ## Features
9
9
 
10
10
  1. Modular. Typographic measurements are based on proportional lists of values.
11
- 2. Responsive. Typography adjusts to the constraints of each breakpoint.
12
- 3. Font rebalancing. Different fonts set to the same size often don't appear to be. Fonts are normalized, so every font appears to be exactly the size you intend.
11
+ 2. Responsive. Typography adjusts to the unique constraints of each breakpoint.
12
+ 3. Nuanced. Various properties allow detail-oriented typographers to align additional fonts or uppercase styles to a modular scale.
13
13
 
14
14
 
15
15
 
@@ -26,78 +26,87 @@ Or create a new project with a sample config and type specimen:
26
26
 
27
27
  ## Usage
28
28
 
29
- ### Declare your fonts
29
+ ### Declare your typefaces
30
30
 
31
- Fonts are defined via SASS maps in the following format:
31
+ Typefaces associate a font-family with various typeface-specific adjustments. Define them via SASS maps in the following format:
32
32
 
33
33
  ```scss
34
- // Default font
34
+ $typefaces: (
35
35
 
36
- $font-georgia: (
37
- "family": unquote("Georgia, serif"),
38
- "font-size-adjustment": 1.00,
39
- "line-height-adjustment": 1.00
40
- );
36
+ // Default typeface
37
+ "georgia": (
38
+ "family": (Georgia, serif),
39
+ "font-size-adjustment": 1.00,
40
+ "line-height-adjustment": 1.00
41
+ ),
41
42
 
42
- // Additional fonts
43
+ // Additional typefaces
44
+ "verdana": (
45
+ "family": (Verdana, sans-serif),
46
+ "font-size-adjustment": 0.89,
47
+ "line-height-adjustment": 0.94
48
+ ),
43
49
 
44
- $font-verdana: (
45
- "family": unquote("Verdana, sans-serif"),
46
- "font-size-adjustment": 0.89,
47
- "line-height-adjustment": 0.93
48
- );
49
-
50
- $font-feather: (
51
- "family": unquote("'Feather'"),
52
- "font-size-adjustment": 0.95,
53
- "line-height-adjustment": 1.00
54
- );
50
+ "feather": (
51
+ "family": ("Feather"),
52
+ "font-size-adjustment": 1.00,
53
+ "line-height-adjustment": 1.00
54
+ )
55
+ )
55
56
  ```
56
57
 
57
- Oftentimes two fonts set to the same size do not appear to be. This is because the heights of their lowercase letters are not equal. By using the `font-size-adjustment` property, additional fonts can be normalized to the default font. This will ensure they align to the modular scale.
58
+ Oftentimes two typfaces set to the same font-size do not appear to be. This is because the heights of their lowercase letters are not equal. By using the `font-size-adjustment` property, additional typefaces can be normalized to the default typeface. This will ensure they align to the modular scale.
58
59
 
59
60
  For example, Verdana appears 11% larger than Georgia. To normalize it with Georgia, we can set a `font-size-adjustment: 0.89`. This will cause Verdana to be 11% smaller than Georgia when set to the same size.
60
61
 
61
- Similarly, you can also apply an adjustment to line-height on a font-by-font basis by specifying a `line-height-adjustment`.
62
+ Similarly, you can also apply an adjustment to line-height on a typeface-by-typeface basis by specifying a `line-height-adjustment`.
62
63
 
63
64
 
64
65
 
65
- ### Build font scales
66
+ ### Declare your environments
66
67
 
67
- From a few constraints, `td-build-typography` builds a modular scale for each specified media query.
68
+ Environments associate media queries with a modular type scale. Define them via SASS maps in the following format:
68
69
 
69
70
  ```scss
70
- $typography: td-build-typography((
71
-
72
- // Define your font scales and their constraints.
73
- "scales": (
74
-
75
- // Phone sizes
76
- "default": (
77
- "base-font-size": 16px,
78
- "base-line-height": 1.5,
79
- "max-font-size": 28px,
80
- "max-line-height": 1.35
81
- ),
82
-
83
- // Tablet sizes and larger
84
- "tablet": (
85
- "media-query": "screen and (min-width: 768px)",
86
- "base-font-size": 18px,
87
- "base-line-height": 1.6,
88
- "max-font-size": 42px,
89
- "max-line-height": 1.25
90
- )
71
+ $environments: (
72
+
73
+ // Phone sizes
74
+ "phone": (
75
+ "base-font-size": 16px,
76
+ "base-line-height": 1.5,
77
+ "max-font-size": 28px,
78
+ "max-line-height": 1.35
91
79
  ),
92
80
 
93
- // Other than the base, how many sizes do you need?
81
+ // Tablet sizes and larger
82
+ "tablet": (
83
+ "media-query": "screen and (min-width: 768px)",
84
+ "base-font-size": 18px,
85
+ "base-line-height": 1.6,
86
+ "max-font-size": 42px,
87
+ "max-line-height": 1.25
88
+ )
89
+ );
90
+ ```
91
+ For each environment, you'll need to specify font-size and line-height for both a base size and a max size. A type scale for each environment will be interpolated from these constraints.
92
+
93
+ A `media-query` property should also be set for each environment, except for the environment you'd like to be default.
94
+
95
+
96
+
97
+ ### Build typography
98
+
99
+ ```scss
100
+ $typography: td-typography(
101
+
102
+ "typefaces": $typefaces,
103
+ "environments": $environments,
104
+
105
+ // Other than the base, how many type sizes do you need?
94
106
  "numb-smaller-sizes": 1,
95
107
  "numb-larger-sizes": 4
96
- ));
108
+ );
97
109
  ```
98
- For each scale, you'll need to specify font-size and line-height for both a base size and a max size. Additional font-sizes and line-heights will be interpolated from these constraints.
99
-
100
- A `media-query` property should also be set for each, exluding the "default" scale. Feel free to name the other scales whatever you like.
101
110
 
102
111
  That's it! Note that `$typography` is a key variable. This map will be used by the following mixins to lookup and apply sizes.
103
112
 
@@ -107,38 +116,40 @@ If you need a bit of typographic guidance, [Responsive Typography: The Basics](h
107
116
 
108
117
  ### Apply responsize sizing
109
118
 
110
- Use `@include td-set-responsive-font-size($font, $size)` to apply a responsive size. The sizes available to you are based on your parameters:
119
+ Use `@include td-responsive-type-size($typface-name, $size)` to apply a responsive size. The type sizes available to you are based on your parameters:
111
120
  * 0 is your base size.
112
121
  * 1, 2, 3... are your increasingly larger sizes.
113
122
  * -1, -2, -3... are your increasingly smaller sizes.
114
123
 
115
124
  ```scss
116
125
  .lead {
117
- @include td-set-responsive-font-size($font-georgia, 1);
126
+ @include td-responsive-type-size("georgia", 1);
118
127
  }
119
128
  ```
120
- We just applied responsive styling to the lead paragraph style. It will use media queries to apply `$font-georgia` at size `1` from the corresponding scale: 18.4px by default, and then resizing to 22.2px for tablets and larger.
129
+ We just applied responsive styling to the lead paragraph style. It will use media queries to apply Georgia at size `1` from the corresponding scale: 18.4px for phone, and then resizing to 22.2px for tablets and larger.
121
130
 
122
131
  ```scss
123
132
  .h4 {
124
- @include td-set-responsive-font-size($font-verdana, 1);
133
+ @include td-responsive-type-size("verdana", 1);
125
134
  }
126
135
  ```
127
- We used the same size for the `.h4` heading, but with `$font-verdana`. This will result in a font-size of 16.4px by default and 19.8px for tablets and larger. Mathematically different, but visually equal.
136
+ We used the same size for the `.h4` heading, but with Verdana. This will result in a font-size of 16.4px for phones and 19.8px for tablets and larger. Mathematically different than Georgia at size `1`, but visually equal.
128
137
 
129
138
 
130
139
 
131
140
  ### Apply static sizing
132
141
 
133
- You might occassionally want finer-grained control of your type styles. For these cases, use the `td-set-font-size()` mixin which accepts an additional `$breakpoint` parameter:
142
+ You might occassionally want finer-grained control of your type styles. For these cases, use the `td-type-size()` mixin which accepts an additional `$environment-name` parameter:
134
143
 
135
144
  ```scss
136
145
  .h4 {
137
- @include td-set-font-size($font-verdana, 1, "tablet");
146
+ @include td-font-size("verdana", 1, "phone");
147
+ @include td-font-size("verdana", 2, "tablet");
138
148
  }
139
149
  ```
140
150
 
141
- Here we just styled our h4 to have the size 1 for only the tablet breakpoint. With `td-set-responsive-font-size()` the corresponding sizes for each other breakpoint would have also been applied.
151
+ Here we just applied size 1 for phones and size 2 for tablets. If we had used `td-set-responsive-font-size()` the same size would have been applied for each environment.
152
+
142
153
 
143
154
 
144
155
  ## Advanced Usage
@@ -148,32 +159,30 @@ Here we just styled our h4 to have the size 1 for only the tablet breakpoint. Wi
148
159
  Rounding to any precision is supported.
149
160
 
150
161
  ```scss
151
- $typography: td-build-typography((
152
-
153
- // Define your font scales and their constraints.
154
- "scales": (
155
-
156
- // Phone sizes
157
- "default": (
158
- "base-font-size": 16px,
159
- "base-line-height": 1.5,
160
- "max-font-size": 28px,
161
- "max-line-height": 1.35,
162
- "font-size-precision": 0.1,
163
- "line-height-precision": 0.01
164
- ),
165
-
166
- // ...
167
- ));
162
+ $environments: (
163
+
164
+ "phone": (
165
+ "base-font-size": 16px,
166
+ "base-line-height": 1.5,
167
+ "max-font-size": 28px,
168
+ "max-line-height": 1.35,
169
+ "font-size-precision": 0.1,
170
+ "line-height-precision": 0.01
171
+ ),
172
+
173
+ // ...
174
+ );
168
175
  ```
169
176
 
170
- ### Solid and tight line-height
177
+
178
+
179
+ ### Solid and tight line-heights
171
180
 
172
181
  Oftentimes you may need to set very narrow lines of text, causing your line-height to look too loose. For a tighter line-height, use the `"line-height": "tight"` option.
173
182
 
174
183
  ```scss
175
184
  .caption-tight {
176
- @include td-set-responsive-font-size($font-verdana, -1, $opts: ("line-height": "tight"));
185
+ @include td-responsive-type-size("verdana", -1, $opts: ("line-height": "tight"));
177
186
  }
178
187
  ```
179
188
 
@@ -181,27 +190,45 @@ Other times you may want to set text to be solid (meaning no "leading"). In term
181
190
 
182
191
  ```scss
183
192
  .btn {
184
- @include td-set-responsive-font-size($font-verdana, 1, $opts: ("line-height": "solid"));
193
+ @include td-responsive-type-size("verdana", 1, $opts: ("line-height": "solid"));
185
194
  }
186
195
  ```
187
196
 
197
+
198
+
188
199
  ### Uppercase styles
189
200
 
190
- If you'd like to set something in all caps and have it align to your font scales, include an `uppercase-adjustment` when defining fonts:
201
+ If you'd like to set something in all caps and have it align to your type scales, include an `uppercase-adjustment` when defining fonts:
191
202
 
192
203
  ```scss
193
- $font-verdana: (
194
- "family": unquote("Verdana, sans-serif"),
195
- "font-size-adjustment": 0.89,
196
- "line-height-adjustment": 0.94,
197
- "uppercase-adjustment": 0.85
198
- );
204
+ $typefaces: (
205
+
206
+ "verdana": (
207
+ "family": (Verdana, sans-serif),
208
+ "font-size-adjustment": 0.89,
209
+ "line-height-adjustment": 0.94,
210
+ "uppercase-adjustment": 0.85
211
+ ),
212
+
213
+ // ...
214
+ )
199
215
  ```
200
216
 
201
217
  Apply an uppercase style like so:
202
218
  ```scss
203
219
  .h4 {
204
- @include td-set-responsive-font-size($font-verdana, 1, $opts: ("uppercase": true));
220
+ @include td-responsive-type-size("verdana", 1, $opts: ("uppercase": true));
205
221
  }
206
222
  ```
207
223
 
224
+
225
+
226
+ ### Overrides
227
+
228
+ You can use `td-override-type-size($environment-name, $size, $font-size, $line-heigt) to override a type size after typography has been built.
229
+
230
+ ```scss
231
+ $typography: td-override-type-size("tablet", -1, 12px, 1.8);
232
+ ```
233
+
234
+
data/lib/type-director.rb CHANGED
@@ -17,7 +17,7 @@ Compass::Frameworks.register('type-director', :path => extension_path)
17
17
  # version contains alphas, it will be created as a
18
18
  # prerelease version. Date is in the form of YYYY-MM-DD
19
19
  module TypeDirector
20
- VERSION = "0.8"
20
+ VERSION = "0.9"
21
21
  DATE = "2016-08-14"
22
22
  end
23
23
 
@@ -1,10 +1,12 @@
1
- @import "type-director/map-deep-get";
2
- @import "type-director/build-scale";
3
- @import "type-director/build-font-scale";
4
- @import "type-director/build-typography";
1
+ @import "type-director/map-get-deep";
2
+ @import "type-director/map-set-deep";
3
+ @import "type-director/scale";
4
+ @import "type-director/type-scale";
5
+ @import "type-director/environment";
6
+ @import "type-director/typography";
5
7
 
6
- $typography: td-build-typography() !default;
8
+ $typography: td-typography() !default;
7
9
 
8
10
  @import "type-director/round";
9
- @import "type-director/set-font-size";
11
+ @import "type-director/type-size";
10
12
 
@@ -0,0 +1,29 @@
1
+
2
+ // Returns an environment profile, which associates a
3
+ // media query with a type-scale and other parameters.
4
+
5
+ @function td-environment($opts: ()) {
6
+
7
+ // Extend default opts with passed opts.
8
+ $opts: map-merge((
9
+ "media-query": null,
10
+ "font-size-precision": null,
11
+ "line-height-precision": null,
12
+ "base-font-size": 16px,
13
+ "base-line-height": 1.5,
14
+ "max-font-size": 28px,
15
+ "max-line-height": 1.35,
16
+ "numb-smaller-sizes": 1,
17
+ "numb-larger-sizes": 4
18
+ ), $opts);
19
+
20
+ // Create environment.
21
+ $environment: (
22
+ "media-query": map-get($opts, "media-query"),
23
+ "font-size-precision": map-get($opts, "font-size-precision"),
24
+ "line-height-precision": map-get($opts, "line-height-precision"),
25
+ "sizes": td-type-scale($opts)
26
+ );
27
+
28
+ @return $environment;
29
+ }
@@ -0,0 +1,12 @@
1
+ /// Map deep get
2
+ /// @author Hugo Giraudel
3
+ /// @access public
4
+ /// @param {Map} $map - Map
5
+ /// @param {Arglist} $keys - Key chain
6
+ /// @return {*} - Desired value
7
+ @function map-get-deep($map, $keys...) {
8
+ @each $key in $keys {
9
+ $map: map-get($map, $key);
10
+ }
11
+ @return $map;
12
+ }
@@ -0,0 +1,48 @@
1
+ /// Deep set function to set a value in nested maps
2
+ /// @author Hugo Giraudel
3
+ /// @access public
4
+ /// @param {Map} $map - Map
5
+ /// @param {List} $keys - Key chaine
6
+ /// @param {*} $value - Value to assign
7
+ /// @return {Map}
8
+ @function map-set-deep($map, $keys, $value) {
9
+ $maps: ($map,);
10
+ $result: null;
11
+
12
+ // If the last key is a map already
13
+ // Warn the user we will be overriding it with $value
14
+ @if type-of(nth($keys, -1)) == "map" {
15
+ @warn "The last key you specified is a map; it will be overrided with `#{$value}`.";
16
+ }
17
+
18
+ // If $keys is a single key
19
+ // Just merge and return
20
+ @if length($keys) == 1 {
21
+ @return map-merge($map, ($keys: $value));
22
+ }
23
+
24
+ // Loop from the first to the second to last key from $keys
25
+ // Store the associated map to this key in the $maps list
26
+ // If the key doesn't exist, throw an error
27
+ @for $i from 1 through length($keys) - 1 {
28
+ $current-key: nth($keys, $i);
29
+ $current-map: nth($maps, -1);
30
+ $current-get: map-get($current-map, $current-key);
31
+ @if $current-get == null {
32
+ @error "Key `#{$key}` doesn't exist at current level in map.";
33
+ }
34
+ $maps: append($maps, $current-get);
35
+ }
36
+
37
+ // Loop from the last map to the first one
38
+ // Merge it with the previous one
39
+ @for $i from length($maps) through 1 {
40
+ $current-map: nth($maps, $i);
41
+ $current-key: nth($keys, $i);
42
+ $current-val: if($i == length($maps), $value, $result);
43
+ $result: map-merge($current-map, ($current-key: $current-val));
44
+ }
45
+
46
+ // Return result
47
+ @return $result;
48
+ }
@@ -0,0 +1,4 @@
1
+ @function td-override-type-size($environment-name, $size, $font-size, $line-height) {
2
+ map-set-deep($typography, "environments", $environment-name, "sizes", $size, "font-size", $font-size);
3
+ map-set-deep($typography, "environments", $environment-name, "sizes", $size, "line-height", $line-height);
4
+ }