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.
@@ -1,9 +1,9 @@
1
1
 
2
2
  // Create a modular scale. Returns a list of values.
3
3
 
4
- @function td-build-scale($opts: ()) {
4
+ @function td-scale($opts: ()) {
5
5
 
6
- // Extend default opts
6
+ // Extend default opts with passed opts.
7
7
  $opts: map-merge((
8
8
  "base-value": 16px,
9
9
  "max-value": 28px,
@@ -16,23 +16,14 @@
16
16
  $numb-larger-values: map-get($opts, "numb-larger-values");
17
17
  $numb-smaller-values: map-get($opts, "numb-smaller-values");
18
18
 
19
- // Build the scale.
19
+ // The object we'll return.
20
20
  $scale: ();
21
21
 
22
22
  // The ratio we'll use to calculate the missing sizes.
23
23
  $scaling-ratio: nth-root($max-value / $base-value, $numb-larger-values);
24
24
 
25
- // Calculate and add smaller values to the scale.
26
- @for $i from -$numb-smaller-values through -1 {
27
- $size: $base-value * power($scaling-ratio, $i);
28
- $scale: append($scale, $size);
29
- }
30
-
31
- // Add the base value to the scale.
32
- $scale: append($scale, $base-value);
33
-
34
- // Calculate and add larger values to the scale.
35
- @for $i from 1 through ($numb-larger-values) {
25
+ // Calculate and add values to the scale.
26
+ @for $i from -$numb-smaller-values through $numb-larger-values {
36
27
  $size: $base-value * power($scaling-ratio, $i);
37
28
  $scale: append($scale, $size);
38
29
  }
@@ -1,10 +1,10 @@
1
1
 
2
- // Create a modular font scale.
3
- // Returns a nested list of font-size and line-height values.
2
+ // Returns a scale of a map of proportionally-related type sizes.
3
+ // Each size is composed of a font-size and line-height value.
4
4
 
5
- @function td-build-font-scale($opts: ()) {
5
+ @function td-type-scale($opts: ()) {
6
6
 
7
- // Extend default opts
7
+ // Extend default opts with passed opts.
8
8
  $opts: map-merge((
9
9
  "base-font-size": 16px,
10
10
  "base-line-height": 1.5,
@@ -15,7 +15,7 @@
15
15
  ), $opts);
16
16
 
17
17
  // Create font-size scale
18
- $font-size-scale: td-build-scale((
18
+ $font-size-scale: td-scale((
19
19
  "base-value": map-get($opts, "base-font-size"),
20
20
  "max-value": map-get($opts, "max-font-size"),
21
21
  "numb-smaller-values": map-get($opts, "numb-smaller-sizes"),
@@ -23,13 +23,14 @@
23
23
  ));
24
24
 
25
25
  // Create line-height scale
26
- $line-height-scale: td-build-scale((
26
+ $line-height-scale: td-scale((
27
27
  "base-value": map-get($opts, "base-line-height"),
28
28
  "max-value": map-get($opts, "max-line-height"),
29
29
  "numb-smaller-values": map-get($opts, "numb-smaller-sizes"),
30
30
  "numb-larger-values": map-get($opts, "numb-larger-sizes")
31
31
  ));
32
32
 
33
+ // The object we'll return.
33
34
  $sizes: ();
34
35
 
35
36
  // Pair each size with the correponding font-size
@@ -52,6 +53,5 @@
52
53
  $sizes: map-merge($sizes, ($name-of-size: $values));
53
54
  }
54
55
 
55
- $font-scale: map-merge($opts, ("sizes": $sizes));
56
- @return $font-scale;
56
+ @return $sizes;
57
57
  }
@@ -0,0 +1,193 @@
1
+
2
+ /******************************************************
3
+ * MIXINS
4
+ ******************************************************/
5
+
6
+ @function td-override-type-size($environment-name, $size, $font-size, $line-height) {
7
+ $typography: map-set-deep($typography, ("environments", $environment-name, "sizes", $size, "font-size"), $font-size);
8
+ $typography: map-set-deep($typography, ("environments", $environment-name, "sizes", $size, "line-height"), $line-height);
9
+ @return $typography;
10
+ }
11
+
12
+ @function td-get-font-size-adjustment($typeface-name, $opts: ()) {
13
+
14
+ // Extend default opts with passed opts.
15
+ $opts: map-merge((
16
+ "uppercase": false,
17
+ "line-height": "normal"
18
+ ), $opts);
19
+
20
+ // Apply font-size adjustment for the font passed.
21
+ $font-size-adjustment: map-get-deep($typography, "typefaces", $typeface-name, "font-size-adjustment") or 1.00;
22
+
23
+ // If uppercase option passed, also apply uppercase adjustment for the font passed.
24
+ @if map-get($opts, "uppercase") {
25
+ $uppercase-adjustment: map-get-deep($typography, "typefaces", $typeface-name, "uppercase-adjustment") or 1.00;
26
+ $font-size-adjustment: $font-size-adjustment * $uppercase-adjustment;
27
+ }
28
+
29
+ @return $font-size-adjustment;
30
+ }
31
+
32
+ @function td-get-line-height-adjustment($typeface-name, $line-height, $opts: ()) {
33
+
34
+ // Extend default opts with passed opts.
35
+ $opts: map-merge((
36
+ "uppercase": false,
37
+ "line-height": "normal"
38
+ ), $opts);
39
+
40
+ // Calculate adjustments.
41
+ $line-height-adjustment: map-get-deep($typography, "typefaces", $typeface-name, "line-height-adjustment") or 1.00;
42
+ $font-size-adjustment: td-get-font-size-adjustment($typeface-name, $opts);
43
+
44
+ // If using relative line heights, the font-size-adjustment will
45
+ // affect the line-height. This removes the unwanted effect.
46
+ @if unitless($line-height) {
47
+ $line-height-adjustment: $line-height-adjustment * (1 / $font-size-adjustment);
48
+ }
49
+
50
+ @return $line-height-adjustment;
51
+ }
52
+
53
+
54
+ // Get adjusted font-size for specific font, environment, and size.
55
+ @mixin td-apply-adjusted-font-size($typeface-name, $size, $environment-name, $opts: ()) {
56
+
57
+ // Extend default opts with passed opts.
58
+ $opts: map-merge((
59
+ "uppercase": false,
60
+ "line-height": "normal"
61
+ ), $opts);
62
+
63
+ // Default size.
64
+ $font-size: map-get-deep($typography, "environments", $environment-name, "sizes", $size, "font-size");
65
+
66
+ // Apply font-size adjustment for the font passed.
67
+ $font-size-adjustment: td-get-font-size-adjustment($typeface-name, $opts);
68
+ $font-size: $font-size * $font-size-adjustment;
69
+
70
+ // Round final value.
71
+ $font-size-precision: map-get-deep($typography, "environments", $environment-name, "font-size-precision") or null;
72
+ @if ($font-size-precision) {
73
+ $font-size: td-round($font-size, $font-size-precision);
74
+ }
75
+
76
+ font-size: $font-size;
77
+ }
78
+
79
+
80
+
81
+ // Get adjusted line-height for specific font, environment, and size.
82
+ @mixin td-apply-adjusted-line-height($typeface-name, $size, $environment-name, $opts: ()) {
83
+
84
+ // Extend default opts with passed opts.
85
+ $opts: map-merge((
86
+ "uppercase": false,
87
+ "line-height": "normal"
88
+ ), $opts);
89
+
90
+ $line-height: null;
91
+
92
+ // Normal line-height associated with environment and size.
93
+ $normal-line-height: map-get-deep($typography, "environments", $environment-name, "sizes", $size, "line-height");
94
+
95
+ // Solid line-height, meaning no space between lines.
96
+ // 1.0 if unitless, otherwise equal to font-size.
97
+ $solid-line-height: if(unitless($normal-line-height), 1.0, $font-size);
98
+
99
+ // Halfway between normal and solid line-height.
100
+ $tight-line-height: (($normal-line-height - $solid-line-height) / 2) + $solid-line-height;
101
+
102
+
103
+ $line-height-setting: map-get($opts, "line-height");
104
+ $line-height-adjustment: td-get-line-height-adjustment($typeface-name, $normal-line-height, $opts);
105
+
106
+
107
+ // Use solid line height, but don't apply adjustment.
108
+ @if $line-height-setting == "solid" {
109
+ $line-height: $solid-line-height;
110
+
111
+ // Use tight line-height and apply line-height adjustment.
112
+ } @else if $line-height-setting == "tight" {
113
+ $line-height: $tight-line-height * $line-height-adjustment;
114
+
115
+ // Use normal line-height and apply line-height adjustment.
116
+ } @else {
117
+ $line-height: $normal-line-height * $line-height-adjustment;
118
+ }
119
+
120
+ // Round line-height.
121
+ $line-height-precision: map-get-deep($typography, "environments", $environment-name, "line-height-precision") or null;
122
+ @if ($line-height-precision) {
123
+ $line-height: td-round($line-height, $line-height-precision);
124
+ }
125
+
126
+ line-height: $line-height;
127
+ }
128
+
129
+
130
+
131
+ // Apply styles for a specific font, environment, and size.
132
+ @mixin td-apply-adjusted-type-size($typeface-name, $size, $environment-name, $opts: ()) {
133
+
134
+ // Extend default opts with passed opts.
135
+ $opts: map-merge((
136
+ "uppercase": false,
137
+ "line-height": "normal"
138
+ ), $opts);
139
+
140
+ @include td-apply-adjusted-font-size($typeface-name, $size, $environment-name, $opts);
141
+ @include td-apply-adjusted-line-height($typeface-name, $size, $environment-name, $opts);
142
+ }
143
+
144
+
145
+ // Apply non-responsive styling. Only the size used for
146
+ // the specified environment will be applied.
147
+ @mixin td-type-size($typeface-name, $size, $environment-name, $opts: ()) {
148
+
149
+ // Extend default opts with passed opts.
150
+ $opts: map-merge((
151
+ "uppercase": false,
152
+ "line-height": "normal"
153
+ ), $opts);
154
+
155
+ $media-query: map-get-deep($typography, "environments", $environment-name, "media-query");
156
+
157
+ // If media query is null, apply styles w/o media query.
158
+ @if $media-query == null {
159
+
160
+ // Apply general styles.
161
+ font-family: map-get-deep($typography, "typefaces", $typeface-name, "family");
162
+
163
+ @if map-get($opts, "uppercase") {
164
+ text-transform: uppercase;
165
+ }
166
+
167
+ @include td-apply-adjusted-type-size($typeface-name, $size, $environment-name, $opts);
168
+ }
169
+
170
+ // Otherwise, apply within media query.
171
+ @else {
172
+ @media #{$media-query} {
173
+ @include td-apply-adjusted-type-size($typeface-name, $size, $environment-name, $opts);
174
+ }
175
+ }
176
+ }
177
+
178
+
179
+ // Apply responsive styling. Unique font-size and line-height
180
+ // will be applied for each environment.
181
+ @mixin td-responsive-type-size($typeface-name, $size: 0, $opts: ()) {
182
+
183
+ // Extend default opts with passed opts.
184
+ $opts: map-merge((
185
+ "uppercase": false,
186
+ "line-height": "normal"
187
+ ), $opts);
188
+
189
+ // Apply type size (font-size and line-height) for each environment.
190
+ @each $environment-name, $environment in map-get($typography, "environments") {
191
+ @include td-type-size($typeface-name, $size, $environment-name, $opts);
192
+ }
193
+ }
@@ -0,0 +1,62 @@
1
+
2
+ // An comprehensize map defining typography. Composed of multiple
3
+ // environment profiles, each associating a media query with a type
4
+ // scale. Each type scale is composed of proportionally related
5
+ // sizes, themselves composed of a font-size and a line-height.
6
+
7
+ @function td-typography($opts: ()) {
8
+
9
+ // Extend default opts with passed opts.
10
+ $opts: map-merge((
11
+ "typefaces": (
12
+ "georgia": (
13
+ "family": (Georgia, serif),
14
+ "font-size-adjustment": 1.00,
15
+ "line-height-adjustment": 1.00,
16
+ "uppercase-adjustment": 0.82
17
+ )
18
+ ),
19
+ "environments": (
20
+ "default": (
21
+ "base-font-size": 16px,
22
+ "base-line-height": 1.5,
23
+ "max-font-size": 28px,
24
+ "max-line-height": 1.35
25
+ ),
26
+ "tablet": (
27
+ "media-query": "screen and (min-width: 768px)",
28
+ "base-font-size": 18px,
29
+ "base-line-height": 1.6,
30
+ "max-font-size": 42px,
31
+ "max-line-height": 1.25
32
+ )
33
+ ),
34
+ "numb-smaller-sizes": 1,
35
+ "numb-larger-sizes": 4
36
+ ), $opts);
37
+
38
+ $typefaces: map-get($opts, "typefaces");
39
+ $environments: ();
40
+
41
+ // Create a type environment for each environment.
42
+ @each $environment-name, $environment-opts in map-get($opts, "environments") {
43
+
44
+ // Create environment opts by merging global opts with environment opts
45
+ $environment-opts: map-merge($environment-opts, (
46
+ "numb-smaller-sizes": map-get($opts, "numb-smaller-sizes"),
47
+ "numb-larger-sizes": map-get($opts, "numb-larger-sizes")
48
+ ));
49
+
50
+ // Create environment and merge into typography.
51
+ $environment: td-environment($environment-opts);
52
+ $environments: map-merge($environments, ($environment-name: $environment));
53
+ }
54
+
55
+ // The object we'll return.
56
+ $typography: (
57
+ "typefaces": $typefaces,
58
+ "environments": $environments
59
+ );
60
+
61
+ @return $typography;
62
+ }
@@ -1,67 +1,48 @@
1
1
  @import "type-director";
2
2
 
3
3
  /******************************************************
4
- * FONTS
5
- ******************************************************/
6
-
7
- // Default font
8
-
9
- $font-georgia: (
10
- "family": unquote("Georgia, serif"),
11
- "font-size-adjustment": 1.00,
12
- "line-height-adjustment": 1.00,
13
- "uppercase-adjustment": 0.82
14
- );
15
-
16
- // Additional fonts
17
-
18
- $font-verdana: (
19
- "family": unquote("Verdana, sans-serif"),
20
- "font-size-adjustment": 0.89,
21
- "line-height-adjustment": 0.94,
22
- "uppercase-adjustment": 0.85
23
- );
24
-
25
- $font-feather: (
26
- "family": unquote("'Feather'"),
27
- "font-size-adjustment": 0.95,
28
- "line-height-adjustment": 1.00
29
- );
30
-
31
- /******************************************************
32
- * FONT ROLES
4
+ * TYPOGRAPHY CONFIG
33
5
  ******************************************************/
34
6
 
35
- // For simple projects I like to define font-copy, font-heading
36
- // and font-icon roles, but this may not always be appropriate.
37
-
38
- $font-copy: $font-georgia;
39
- $font-copy-weight: normal;
7
+ $typography: td-typography((
40
8
 
41
- $font-heading: $font-verdana;
42
- $font-heading-weight: bold;
9
+ // Define your typefaces and any relevant adjustments.
10
+ "typefaces": (
43
11
 
44
- $font-icon: $font-feather;
45
- $font-icon-weight: normal;
12
+ "georgia": (
13
+ "family": (Georgia, serif),
14
+ "font-size-adjustment": 1.00,
15
+ "line-height-adjustment": 1.00,
16
+ "uppercase-adjustment": 0.82
17
+ ),
46
18
 
47
- /******************************************************
48
- * TYPOGRAPHY CONFIG
49
- ******************************************************/
19
+ "verdana": (
20
+ "family": (Verdana, sans-serif),
21
+ "font-size-adjustment": 0.89,
22
+ "line-height-adjustment": 0.94,
23
+ "uppercase-adjustment": 0.85
24
+ ),
50
25
 
51
- $typography: td-build-typography((
26
+ "feather": (
27
+ "family": ("Feather"),
28
+ "font-size-adjustment": 1.00,
29
+ "line-height-adjustment": 1.00,
30
+ "uppercase-adjustment": 0.82
31
+ )
32
+ ),
52
33
 
53
- // Define your font scales and their constraints.
54
- "scales": (
34
+ // Define your environments and their constraints.
35
+ "environments": (
55
36
 
56
- // Phone sizes
57
- "default": (
37
+ // Phone environment
38
+ "phone": (
58
39
  "base-font-size": 16px,
59
40
  "base-line-height": 1.5,
60
41
  "max-font-size": 28px,
61
42
  "max-line-height": 1.35
62
43
  ),
63
44
 
64
- // Tablet sizes and larger
45
+ // Tablet and larger environments
65
46
  "tablet": (
66
47
  "media-query": "screen and (min-width: 768px)",
67
48
  "base-font-size": 18px,
@@ -71,8 +52,20 @@ $typography: td-build-typography((
71
52
  )
72
53
  ),
73
54
 
74
- // Other than the base, how many sizes do you need?
75
- "numb-smaller-sizes": 1,
55
+ // Other than the base, how many type sizes do you need?
56
+ "numb-smaller-sizes": 2,
76
57
  "numb-larger-sizes": 4
77
58
  ));
78
59
 
60
+
61
+ /******************************************************
62
+ * TYPEFACE ROLES
63
+ ******************************************************/
64
+
65
+ // It's a good idea to future-proof yourself by
66
+ // mapping typefaces to more functional names.
67
+
68
+ $typeface-default: "georgia";
69
+ $typeface-alternate: "verdana";
70
+ $typeface-icon: "feather";
71
+