-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_config.scss
266 lines (235 loc) · 5.92 KB
/
_config.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
@use "sass:map";
@use "sass:math";
@use "sass:meta";
$_font-size: null;
$_font-stack: null;
$_line-height: null;
$_color: null;
$_whitespace: null;
$_font-size-scale: null;
$_whitespace-scale: null;
/**
* Call this mixin first if you want to override GutenType's default config:
*
* ```
* @use "guten-type";
*
* main {
* @include guten-type.set(
* $font-size: 20px,
* $font-stack: (
* "serif": (Baskerville, serif),
* "sans": (Helvetica, sans-serif),
* "mono": (Consolas, monospace),
* )
* );
*
* @include guten-type.press();
* }
* ```
*
* @param $font-size
* - The body text's font-size. Must be in px. This is automatically scaled
* smaller for elements like captions, code, etc.
*
* @param $font-stack
* - The various serif, sans-serif, and monospace fonts used for all text.
*
* @param $line-height
* - The body text's line-height. This is automatically scaled smaller for
* headings.
*
* @param $color
* - `normal` is used for text. `light` is used for lines (tables, hr, etc.).
* `action` is used for links.
*
* @param $whitespace
* - The size of line breaks. Must be in rem.
*
* @param $font-size-scale
* - The typographic scale for heading font-size.
*
* E.g. given a `start` value of 4, the scale starts at h4. h4's font-size
* gets calculated as follows:
* h4-font-size = $font-size * `base`.
*
* Then, the remaining headings scale exponentially:
* h3-font-size = h4-font-size * `ratio`^1
* h2-font-size = h4-font-size * `ratio`^2
* h1-font-size = h4-font-size * `ratio`^3
*
* @param $whitespace-scale
* - Same concept as $font-size-scale.
*/
@mixin set(
$font-size: null,
$font-stack: null,
$line-height: null,
$color: null,
$whitespace: null,
$font-size-scale: null,
$whitespace-scale: null
) {
@if $font-size {
@include _expect-same-unit(font-size(), $font-size, "$font-size");
$_font-size: $font-size !global;
}
@if $font-stack {
@include _expect-same-keys(font-stack(), $font-stack, "$font-stack");
$_font-stack: $font-stack !global;
}
@if $line-height {
@include _expect-same-unit(line-height(), $line-height, "$line-height");
$_line-height: $line-height !global;
}
@if $color {
@include _expect-same-keys(color(), $color, "$color");
$_color: $color !global;
}
@if $whitespace {
@include _expect-same-unit(whitespace(), $whitespace, "$whitespace");
$_whitespace: $whitespace !global;
}
@if $font-size-scale {
@include _expect-same-keys(
font-size-scale(),
$font-size-scale,
"$font-size-scale"
);
$_font-size-scale: $font-size-scale !global;
}
@if $whitespace-scale {
@include _expect-same-keys(
whitespace-scale(),
$whitespace-scale,
"$whitespace-scale"
);
$_whitespace-scale: $whitespace-scale !global;
}
}
@function font-size() {
@return $_font-size or 18px;
}
@function font-stack($key: null) {
$map: $_font-stack or
(
"serif": (
"Iowan Old Style",
"Palatino Linotype",
"URW Palladio L",
P052,
serif,
),
"sans": (
Inter,
Roboto,
"Helvetica Neue",
"Arial Nova",
"Nimbus Sans",
Arial,
sans-serif,
),
"mono": (
ui-monospace,
"Cascadia Code",
"Source Code Pro",
Menlo,
Consolas,
"DejaVu Sans Mono",
monospace,
),
);
@if ($key) {
@return map.get($map, $key);
} @else {
@return $map;
}
}
@function line-height() {
@return $_line-height or 1.5;
}
@function color($key: null) {
$map: $_color or
(
"normal": rgba(1, 2, 3, 0.95),
"light": rgba(0, 0, 0, 0.55),
"action": rgba(1, 2, 3, 0.95),
);
@if ($key) {
@return map.get($map, $key);
} @else {
@return $map;
}
}
@function whitespace() {
@return $_whitespace or 1rem * line-height();
}
@function font-size-scale($key: null) {
$map: $_font-size-scale or
(
"start": 4,
"base": 1.33333,
"ratio": 1.25,
);
@if ($key) {
@return map.get($map, $key);
} @else {
@return $map;
}
}
@function whitespace-scale($key: null) {
$map: $_whitespace-scale or
(
"start": 4,
"base": 1.5,
"ratio": 1.33333,
);
@if ($key) {
@return map.get($map, $key);
} @else {
@return $map;
}
}
////////////////////////////////////////////////////////////////////////////////
// Private
////////////////////////////////////////////////////////////////////////////////
// Validate that the given numbers have the same unit.
@mixin _expect-same-unit($var1, $var2, $var2Name) {
@include _expect-same-type($var1, $var2, $var2Name);
$unit1: math.unit($var1);
$unit2: math.unit($var2);
@if $unit1 != $unit2 {
@if $unit1 == "" {
@include error("expected #{$var2Name} to be unitless.");
} @else {
@include error("expected #{$var2Name}'s units to be #{$unit1}.");
}
}
}
// Validate that the given maps have the same keys.
@mixin _expect-same-keys($var1, $var2, $var2Name) {
@include _expect-same-type($var1, $var2, $var2Name);
@each $key in map.keys($var1) {
@if not map.has-key($var2, $key) {
@include _error("expected #{$var2Name} to have a value for #{$key}.");
}
$value1: map.get($var1, $key);
$value2: map.get($var2, $key);
@include _expect-same-type($value1, $value2, "#{$var2Name}.#{$key}");
@if meta.type-of($value1) == "number" {
@include _expect-same-unit($value1, $value2, "#{$var2Name}.#{$key}");
}
}
}
// Validate that the given vars are the same type.
@mixin _expect-same-type($var1, $var2, $var2Name) {
$type1: meta.type-of($var1);
$type2: meta.type-of($var2);
@if $type1 != $type2 {
@include _error("expected #{$var2Name} to be a #{$type1}.");
}
}
// Throws a formatted error message.
@mixin _error($message) {
@error 'guten-type.set(): #{$message}';
}