type-heading 0.0.11
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 +7 -0
- data/README.md +22 -0
- data/lib/compass-type-heading.rb +1 -0
- data/lib/type-heading.rb +14 -0
- data/stylesheets/_type-heading.scss +12 -0
- data/stylesheets/type-heading/_settings.scss +46 -0
- data/stylesheets/type-heading/functions/_heading.scss +141 -0
- data/stylesheets/type-heading/functions/_helpers.scss +471 -0
- data/stylesheets/type-heading/functions/_property.scss +396 -0
- data/stylesheets/type-heading/mixins/_breakpoint.scss +51 -0
- data/stylesheets/type-heading/mixins/_heading.scss +139 -0
- data/stylesheets/type-heading/mixins/_property.scss +140 -0
- data/templates/project/manifest.rb +1 -0
- data/templates/project/style.scss +1 -0
- metadata +97 -0
@@ -0,0 +1,471 @@
|
|
1
|
+
// Helpers
|
2
|
+
//
|
3
|
+
// @group Functions / Helpers
|
4
|
+
// @author Elliot Mitchum
|
5
|
+
|
6
|
+
// Math
|
7
|
+
// ------------------------------
|
8
|
+
|
9
|
+
// th-math-power
|
10
|
+
// Returns a powered number by exponent.
|
11
|
+
//
|
12
|
+
// @since 0.0.11
|
13
|
+
// @type function
|
14
|
+
//
|
15
|
+
// @param {number} $number The base number (required).
|
16
|
+
// @param {number} $exponent The base number's exponent (required).
|
17
|
+
//
|
18
|
+
// @returns {number} The powered number.
|
19
|
+
//
|
20
|
+
// @example scss Calculate 10 to the power of 3.
|
21
|
+
// // th-math-power(10, 3)
|
22
|
+
// // // 1000
|
23
|
+
|
24
|
+
@function th-math-power(
|
25
|
+
$number,
|
26
|
+
$exponent
|
27
|
+
){
|
28
|
+
$_return: $number;
|
29
|
+
@if $exponent > 1 {
|
30
|
+
@for $i from 2 through $exponent {
|
31
|
+
$_return: $_return * $number;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
@if $exponent < 1 {
|
35
|
+
@for $i from 0 through -#{$exponent} {
|
36
|
+
$_return: $_return / $number;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
@return $_return;
|
40
|
+
}
|
41
|
+
|
42
|
+
// th-math-round-to
|
43
|
+
// Returns a floated number rounded to a decimal point.
|
44
|
+
//
|
45
|
+
// @since 0.0.11
|
46
|
+
// @type function
|
47
|
+
//
|
48
|
+
// @requires {function} th-math-power
|
49
|
+
//
|
50
|
+
// @param {number} $number The number to round from (required).
|
51
|
+
// @param {number} $decimal The decimal place to round to (required).
|
52
|
+
//
|
53
|
+
// @returns {number} The rounded number.
|
54
|
+
//
|
55
|
+
// @example scss Round 1.234 to 2 decimal places.
|
56
|
+
// // th-math-round-to(1.234, 2)
|
57
|
+
// // // 1.23
|
58
|
+
|
59
|
+
@function th-math-round-to(
|
60
|
+
$number,
|
61
|
+
$decimal
|
62
|
+
){
|
63
|
+
$_return: $number;
|
64
|
+
$_return: round( $number * th-math-power(10, $decimal) );
|
65
|
+
$_return: $_return / th-math-power(10, $decimal);
|
66
|
+
@return $_return;
|
67
|
+
}
|
68
|
+
|
69
|
+
// Lists
|
70
|
+
// ------------------------------
|
71
|
+
|
72
|
+
// th-list-has-index
|
73
|
+
// Check list for a index.
|
74
|
+
//
|
75
|
+
// @since 0.0.1
|
76
|
+
// @type function
|
77
|
+
//
|
78
|
+
// @param {list} $list List to search (required).
|
79
|
+
// @param {number} $index The list index to retrieve (required).
|
80
|
+
//
|
81
|
+
// @returns {boolean} If list contains index.
|
82
|
+
//
|
83
|
+
// @example scss Check list for 2nd index.
|
84
|
+
// // @debug th-list-has-index((a, b, c), 2);
|
85
|
+
// // // true
|
86
|
+
|
87
|
+
@function th-list-has-index(
|
88
|
+
$list,
|
89
|
+
$index
|
90
|
+
){
|
91
|
+
$_return: false;
|
92
|
+
@if list == type-of($list) and length($list) >= $index {
|
93
|
+
$_return: true;
|
94
|
+
}
|
95
|
+
@return $_return;
|
96
|
+
}
|
97
|
+
|
98
|
+
// th-list-get-index-deep
|
99
|
+
// Return the index of a value within multiple lists.
|
100
|
+
//
|
101
|
+
// @since 0.0.11
|
102
|
+
// @type function
|
103
|
+
//
|
104
|
+
// @requires {function} th-list-has
|
105
|
+
//
|
106
|
+
// @param {list} $list The list to search through (required).
|
107
|
+
// @param {number | string} $find The value to find (required).
|
108
|
+
// @param {list} $indexes List of previous indexes.
|
109
|
+
//
|
110
|
+
// @returns {list} The index of the found value.
|
111
|
+
//
|
112
|
+
// @example scss Get the index of 'f' in (a, b, (c, d, (e, f))).
|
113
|
+
// // th-list-get-index-deep( (a, b, (c, d, (e, f))), f )
|
114
|
+
// // // 3 3 2
|
115
|
+
|
116
|
+
@function th-list-get-index-deep(
|
117
|
+
$list,
|
118
|
+
$find,
|
119
|
+
$indexes: ()
|
120
|
+
){
|
121
|
+
$_return: $find;
|
122
|
+
$index: 0;
|
123
|
+
@if th-list-has($list, $find) {
|
124
|
+
@if length($indexes) > 0 {
|
125
|
+
$_return: append($indexes, index($list, $find));
|
126
|
+
} @else {
|
127
|
+
$_return: index($list, $find);
|
128
|
+
}
|
129
|
+
} @else {
|
130
|
+
@each $value in $list {
|
131
|
+
$index: $index + 1;
|
132
|
+
@if type-of($value) == list {
|
133
|
+
$_return: th-list-get-index-deep($value, $find, append($indexes, $index));
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
@return $_return;
|
138
|
+
}
|
139
|
+
|
140
|
+
// th-list-has
|
141
|
+
// Check list for a value.
|
142
|
+
//
|
143
|
+
// @since 0.0.1
|
144
|
+
// @type function
|
145
|
+
//
|
146
|
+
// @param {list} $list List to search (required).
|
147
|
+
// @param {number | string} $find Value to find (required).
|
148
|
+
//
|
149
|
+
// @returns {boolean} If list contains value.
|
150
|
+
//
|
151
|
+
// @example scss Check list for 'b'.
|
152
|
+
// // th-list-has((a b c), b);
|
153
|
+
// // // true
|
154
|
+
|
155
|
+
@function th-list-has(
|
156
|
+
$list,
|
157
|
+
$find
|
158
|
+
){
|
159
|
+
$_return: false;
|
160
|
+
@each $value in $list {
|
161
|
+
@if $find == $value {
|
162
|
+
@return true;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
@return $_return;
|
166
|
+
}
|
167
|
+
|
168
|
+
// th-list-has-deep
|
169
|
+
// Check list for a value (recurring).
|
170
|
+
//
|
171
|
+
// @since 0.0.10
|
172
|
+
// @type function
|
173
|
+
//
|
174
|
+
// @param {list} $list List to search (required).
|
175
|
+
// @param {number | string} $find Value to find (required).
|
176
|
+
//
|
177
|
+
// @returns {boolean} If list contains value.
|
178
|
+
//
|
179
|
+
// @example scss Check for 'f' in (a b (c d (e f))).
|
180
|
+
// // th-list-has-deep((a b (c d (e f))), f)
|
181
|
+
// // // true
|
182
|
+
|
183
|
+
@function th-list-has-deep(
|
184
|
+
$list,
|
185
|
+
$find
|
186
|
+
){
|
187
|
+
$_return: false;
|
188
|
+
@each $value in $list {
|
189
|
+
@if list == type-of($value) {
|
190
|
+
$_return: th-list-has-deep($value, $find);
|
191
|
+
} @else {
|
192
|
+
@if $find == $value {
|
193
|
+
@return true;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
@return $_return;
|
198
|
+
}
|
199
|
+
|
200
|
+
// Units
|
201
|
+
// ------------------------------
|
202
|
+
|
203
|
+
// th-unit-strip
|
204
|
+
// Strips the unit from a number.
|
205
|
+
//
|
206
|
+
// @since 0.0.11
|
207
|
+
// @type function
|
208
|
+
//
|
209
|
+
// @param {number} $number Number to strip unit from (required).
|
210
|
+
//
|
211
|
+
// @returns {number} The stripped number.
|
212
|
+
//
|
213
|
+
// @example scss Strip px from 24px.
|
214
|
+
// // th-unit-strip(24px)
|
215
|
+
// // // 24
|
216
|
+
|
217
|
+
@function th-unit-strip(
|
218
|
+
$number
|
219
|
+
){
|
220
|
+
$_return: $number / ($number * 0 + 1);
|
221
|
+
@return $_return;
|
222
|
+
}
|
223
|
+
|
224
|
+
// th-unit-cast
|
225
|
+
// Creates a number with a unit.
|
226
|
+
//
|
227
|
+
// @since 0.0.11
|
228
|
+
// @type function
|
229
|
+
//
|
230
|
+
// @param {number} $number The unitless number to create (required).
|
231
|
+
// @param {string} $unit The type of unit to create (required).
|
232
|
+
//
|
233
|
+
// @returns {number} The created number with new unit.
|
234
|
+
//
|
235
|
+
// @example scss Create 24px.
|
236
|
+
// // th-unit-cast(24, px);
|
237
|
+
// // // 24px
|
238
|
+
|
239
|
+
@function th-unit-cast(
|
240
|
+
$number,
|
241
|
+
$unit
|
242
|
+
){
|
243
|
+
$_return: $number;
|
244
|
+
$strings: px em rem;
|
245
|
+
$units: 1px 1em 1rem;
|
246
|
+
$index: index($strings, $unit);
|
247
|
+
@if $index {
|
248
|
+
$_return: $number * nth($units, $index);
|
249
|
+
}
|
250
|
+
@return $_return;
|
251
|
+
}
|
252
|
+
|
253
|
+
// th-unit-convert
|
254
|
+
// Converts the unit of a number.
|
255
|
+
//
|
256
|
+
// @since 0.0.11
|
257
|
+
// @type function
|
258
|
+
//
|
259
|
+
// @requires {function} th-unit-strip
|
260
|
+
// @requires {function} th-unit-cast
|
261
|
+
//
|
262
|
+
// @param {number} $number The numbered unit to convert (required).
|
263
|
+
// @param {string} $unit The unit to convert to (required).
|
264
|
+
//
|
265
|
+
// @returns {number} The converted number.
|
266
|
+
//
|
267
|
+
// @example scss Convert 24px to 24em.
|
268
|
+
// // th-unit-convert(24px, em)
|
269
|
+
// // // 24em
|
270
|
+
|
271
|
+
@function th-unit-convert(
|
272
|
+
$number,
|
273
|
+
$unit
|
274
|
+
){
|
275
|
+
$_return: $number;
|
276
|
+
$_return: th-unit-strip($number) * th-unit-cast(1, $unit);
|
277
|
+
@if ($_return == th-unit-cast(0, $unit)) {
|
278
|
+
$_return: 0;
|
279
|
+
}
|
280
|
+
@return $_return;
|
281
|
+
}
|
282
|
+
|
283
|
+
// th-unit-convert-absolute
|
284
|
+
// Converts a relative number to an absolute number.
|
285
|
+
//
|
286
|
+
// @since 0.0.11
|
287
|
+
// @type function
|
288
|
+
//
|
289
|
+
// @requires {function} th-unit-strip
|
290
|
+
// @requires {function} th-math-round-to
|
291
|
+
// @requires {function} th-unit-convert
|
292
|
+
//
|
293
|
+
// @param {number} $number The number to convert (required).
|
294
|
+
// @param {string} $unit The type of absolute unit (required).
|
295
|
+
// @param {number} $base-font-size ($th-base-font-size) Font size used for relative calculations.
|
296
|
+
//
|
297
|
+
// @returns {number} The converted absolute number.
|
298
|
+
//
|
299
|
+
// @example scss Convert 2em to px.
|
300
|
+
// // th-unit-convert-absolute(2em, px)
|
301
|
+
// // // 32px
|
302
|
+
// @example scss Convert 2em to px with base font size of 10px.
|
303
|
+
// // th-unit-convert-absolute(2em, px, 10px);
|
304
|
+
// // // 20px
|
305
|
+
|
306
|
+
@function th-unit-convert-absolute(
|
307
|
+
$number,
|
308
|
+
$unit,
|
309
|
+
$base-font-size: $th-base-font-size
|
310
|
+
){
|
311
|
+
$_return: $number;
|
312
|
+
$_return: th-unit-strip($number) * th-unit-strip($base-font-size);
|
313
|
+
$_return: th-math-round-to($_return, 5);
|
314
|
+
@if $unit {
|
315
|
+
$_return: th-unit-convert($_return, $unit);
|
316
|
+
}
|
317
|
+
@return $_return;
|
318
|
+
}
|
319
|
+
|
320
|
+
// th-unit-convert-relative
|
321
|
+
// Converts an absolute number to a relative number.
|
322
|
+
//
|
323
|
+
// @since 0.0.11
|
324
|
+
// @type function
|
325
|
+
//
|
326
|
+
// @requires {function} th-unit-strip
|
327
|
+
// @requires {function} th-math-round-to
|
328
|
+
// @requires {function} th-unit-convert
|
329
|
+
//
|
330
|
+
// @param {number} $number The number to convert (required).
|
331
|
+
// @param {string} $unit The type of relative unit (required).
|
332
|
+
// @param {number} $base-font-size ($th-base-font-size) Font size used for relative calculations.
|
333
|
+
//
|
334
|
+
// @returns {number} The converted number.
|
335
|
+
//
|
336
|
+
// @example scss Convert 24px to em.
|
337
|
+
// // th-unit-convert-relative(24px, em)
|
338
|
+
// // // 1.5
|
339
|
+
// @example scss Convert 24px to em with a base font size of 32px.
|
340
|
+
// // th-unit-convert-relative(24px, em, 32px)
|
341
|
+
// // // 0.75em
|
342
|
+
|
343
|
+
@function th-unit-convert-relative(
|
344
|
+
$number,
|
345
|
+
$unit,
|
346
|
+
$base-font-size: $th-base-font-size
|
347
|
+
){
|
348
|
+
$_return: $number;
|
349
|
+
$_return: th-unit-strip($number) / th-unit-strip($base-font-size);
|
350
|
+
$_return: th-math-round-to($_return, 5);
|
351
|
+
@if $unit {
|
352
|
+
$_return: th-unit-convert($_return, $unit);
|
353
|
+
}
|
354
|
+
@return $_return;
|
355
|
+
}
|
356
|
+
|
357
|
+
// th-unit-convert-em
|
358
|
+
// Converts an absolute number to an em number.
|
359
|
+
//
|
360
|
+
// @since 0.0.11
|
361
|
+
// @type function
|
362
|
+
//
|
363
|
+
// @requires th-unit-convert-relative
|
364
|
+
//
|
365
|
+
// @param {number} $number The number to convert (required).
|
366
|
+
// @param {number} $base-font-size ($th-base-font-size) Font size used for relative calculations.
|
367
|
+
//
|
368
|
+
// @returns {number} The converted number.
|
369
|
+
//
|
370
|
+
// @example scss Convert 24px to em.
|
371
|
+
// // th-unit-convert-em(24px)
|
372
|
+
// // // 1.5
|
373
|
+
// @example scss Convert 24px to em with a base font size of 32px.
|
374
|
+
// // th-unit-convert-em(24px, 32px)
|
375
|
+
// // // 0.75em
|
376
|
+
|
377
|
+
@function th-unit-convert-em(
|
378
|
+
$number,
|
379
|
+
$base-font-size: $th-base-font-size
|
380
|
+
){
|
381
|
+
$_return: $number;
|
382
|
+
$_return: th-unit-convert-relative($number, em, $base-font-size);
|
383
|
+
@return $_return;
|
384
|
+
}
|
385
|
+
|
386
|
+
// th-unit-convert-rem
|
387
|
+
// Converts an absolute number to an rem number.
|
388
|
+
//
|
389
|
+
// @since 0.0.11
|
390
|
+
// @type function
|
391
|
+
//
|
392
|
+
// @requires th-unit-convert-relative
|
393
|
+
//
|
394
|
+
// @param {number} $number The number to convert (required).
|
395
|
+
// @param {number} $base-font-size ($th-base-font-size) Font size used for relative calculations.
|
396
|
+
//
|
397
|
+
// @returns {number} The converted number.
|
398
|
+
//
|
399
|
+
// @example scss Convert 24px to rem.
|
400
|
+
// // th-unit-convert-rem(24px)
|
401
|
+
// // // 1.5
|
402
|
+
// @example scss Convert 24px to rem with a base font size of 32px.
|
403
|
+
// // th-unit-convert-rem(24px, 32px)
|
404
|
+
// // // 0.75rem
|
405
|
+
|
406
|
+
@function th-unit-convert-rem(
|
407
|
+
$number,
|
408
|
+
$base-font-size: $th-base-font-size
|
409
|
+
){
|
410
|
+
$_return: $number;
|
411
|
+
$_return: th-unit-convert-relative($number, rem, $base-font-size);
|
412
|
+
@return $_return;
|
413
|
+
}
|
414
|
+
|
415
|
+
// th-unit-convert-rel
|
416
|
+
// Converts an absolute number to a relative number.
|
417
|
+
//
|
418
|
+
// @since 0.0.11
|
419
|
+
// @type function
|
420
|
+
//
|
421
|
+
// @requires th-unit-convert-relative
|
422
|
+
//
|
423
|
+
// @param {number} $number The number to convert (required).
|
424
|
+
// @param {number} $base-font-size ($th-base-font-size) Font size used for relative calculations.
|
425
|
+
//
|
426
|
+
// @returns {number} The converted number.
|
427
|
+
//
|
428
|
+
// @example scss Convert 24px to a relative number.
|
429
|
+
// // th-unit-convert-rel(24px)
|
430
|
+
// // // 1.5
|
431
|
+
// @example scss Convert 24px to a relative number with a base font size of 32px.
|
432
|
+
// // th-unit-convert-rel(24px, 32px)
|
433
|
+
// // // 0.75
|
434
|
+
|
435
|
+
@function th-unit-convert-rel(
|
436
|
+
$number,
|
437
|
+
$base-font-size: $th-base-font-size
|
438
|
+
){
|
439
|
+
$_return: $number;
|
440
|
+
$_return: th-unit-convert-relative($number, false, $base-font-size);
|
441
|
+
@return $_return;
|
442
|
+
}
|
443
|
+
|
444
|
+
// th-unit-convert-px
|
445
|
+
// Converts a relative number to a px number.
|
446
|
+
//
|
447
|
+
// @since 0.0.11
|
448
|
+
// @type function
|
449
|
+
//
|
450
|
+
// @requires th-unit-convert-absolute
|
451
|
+
//
|
452
|
+
// @param {number} $number The number to convert (required).
|
453
|
+
// @param {number} $base-font-size ($th-base-font-size) Font size used for relative calculations.
|
454
|
+
//
|
455
|
+
// @returns {number} The converted number.
|
456
|
+
//
|
457
|
+
// @example scss Convert 2em to a px number.
|
458
|
+
// // th-unit-convert-absolute(2em)
|
459
|
+
// // // 32px
|
460
|
+
// @example scss Convert 2em to a px number with a base font size of 18px.
|
461
|
+
// // th-unit-convert-px(2em, 18px)
|
462
|
+
// // // 36px
|
463
|
+
|
464
|
+
@function th-unit-convert-px(
|
465
|
+
$number,
|
466
|
+
$base-font-size: $th-base-font-size
|
467
|
+
){
|
468
|
+
$_return: $number;
|
469
|
+
$_return: th-unit-convert-absolute($number, px, $base-font-size);
|
470
|
+
@return $_return;
|
471
|
+
}
|