type-heading 0.0.13 → 0.0.14

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,25 +1,53 @@
1
- // Helpers
2
- //
3
- // @group Functions / Helpers
4
- // @author Elliot Mitchum
1
+ ////
2
+ /// Helpers
3
+ /// @group Helpers
4
+ /// @access private
5
+ ////
6
+
7
+ // Logic
8
+ // ------------------------------
9
+
10
+ // th-if()
11
+ /// Shorthand if else statement.
12
+ ///
13
+ /// @since 0.0.14
14
+ /// @return {mixed} The return value of the condition.
15
+ ///
16
+ /// @param {boolean} $condition - The condition to pass.
17
+ /// @param {mixed} $if-value - The return value if condition is true.
18
+ /// @param {mixed} $else-value - The return value if condition is false.
19
+ ///
20
+ /// @example scss - If 2 plus 2 equals 8, return 10px, else return 20px.
21
+ /// th-if(2 + 2, 10px, 20px);
22
+ /// // 20px
23
+
24
+ @function th-if(
25
+ $condition,
26
+ $if-value,
27
+ $else-value
28
+ ){
29
+ @if ($condition == true) {
30
+ @return $if-value;
31
+ } @else {
32
+ @return $else-value;
33
+ }
34
+ }
5
35
 
6
36
  // Math
7
37
  // ------------------------------
8
38
 
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
39
+ // th-math-power()
40
+ /// Returns a powered number by exponent.
41
+ ///
42
+ /// @since 0.0.11
43
+ /// @return {number} The powered number.
44
+ ///
45
+ /// @param {number} $number - The base number.
46
+ /// @param {number} $exponent - The base number's exponent.
47
+ ///
48
+ /// @example scss - Calculate 10 to the power of 3.
49
+ /// th-math-power(10, 3)
50
+ /// // 1000
23
51
 
24
52
  @function th-math-power(
25
53
  $number,
@@ -39,22 +67,18 @@
39
67
  @return $_return;
40
68
  }
41
69
 
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
70
+ // th-math-round-to()
71
+ /// Returns a floated number rounded to a decimal point.
72
+ ///
73
+ /// @since 0.0.11
74
+ /// @return {number} The rounded number.
75
+ ///
76
+ /// @param {number} $number - The number to round from.
77
+ /// @param {number} $decimal - The decimal place to round to.
78
+ ///
79
+ /// @example scss - Round 1.234 to 2 decimal places.
80
+ /// th-math-round-to(1.234, 2)
81
+ /// // 1.23
58
82
 
59
83
  @function th-math-round-to(
60
84
  $number,
@@ -69,20 +93,18 @@
69
93
  // Lists
70
94
  // ------------------------------
71
95
 
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
96
+ // th-list-has-index()
97
+ /// Check list for a index.
98
+ ///
99
+ /// @since 0.0.11
100
+ /// @return {boolean} If list contains index.
101
+ ///
102
+ /// @param {list} $list - List to search.
103
+ /// @param {number} $index - The list index to retrieve.
104
+ ///
105
+ /// @example scss - Check list for 2n index.
106
+ /// th-list-has-index((a, b, c), 2);
107
+ /// // true
86
108
 
87
109
  @function th-list-has-index(
88
110
  $list,
@@ -95,23 +117,18 @@
95
117
  @return $_return;
96
118
  }
97
119
 
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
120
+ // th-list-get-index-deep()
121
+ /// Return the index of a value within multiple lists.
122
+ ///
123
+ /// @since 0.0.11
124
+ /// @return {list} The index of the found value.
125
+ ///
126
+ /// @param {list} $list - The list to search through.
127
+ /// @param {number | string} $find - The value to find.
128
+ ///
129
+ /// @example scss - Get the index of 'f' in (a, b, (c, d, (e, f))).
130
+ /// th-list-get-index-deep( (a, b, (c, d, (e, f))), f )
131
+ /// // 3 3 2
115
132
 
116
133
  @function th-list-get-index-deep(
117
134
  $list,
@@ -137,20 +154,18 @@
137
154
  @return $_return;
138
155
  }
139
156
 
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
157
+ // th-list-has()
158
+ /// Check list for a value.
159
+ ///
160
+ /// @since 0.0.11
161
+ /// @return {boolean} If list contains value.
162
+ ///
163
+ /// @param {list} $list - List to search.
164
+ /// @param {number | string} $find - Value to find.
165
+ ///
166
+ /// @example scss - Check list for 'b'.
167
+ /// th-list-has((a b c), b);
168
+ /// // true
154
169
 
155
170
  @function th-list-has(
156
171
  $list,
@@ -165,20 +180,51 @@
165
180
  @return $_return;
166
181
  }
167
182
 
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
183
+ // th-list-get-nth-deep()
184
+ /// Return a nested value by index (recursive).
185
+ ///
186
+ /// @since 0.0.14
187
+ /// @return {mixed} The nested list value.
188
+ ///
189
+ /// @param {list} $list - List to search through.
190
+ /// @param {list} $indexes - List of indexes to recurse.
191
+ ///
192
+ /// @example scss - Get (3 3 2)n in (a, b, (c, d, (e, f))).
193
+ /// th-list-get-nth-deep(3 3 2)
194
+ /// // f
195
+
196
+ @function th-list-get-nth-deep(
197
+ $list,
198
+ $indexes
199
+ ){
200
+ $_return: false;
201
+ @if list == type-of($list) {
202
+ $_return: $list;
203
+ @for $i from 1 through length($indexes) {
204
+ @if th-list-has-index($_return, nth($indexes, $i)) {
205
+ $_return: nth($_return, nth($indexes, $i));
206
+ } @else if $i == 1 {
207
+ $_return: false;
208
+ }
209
+ }
210
+ } @else if $indexes == 1 {
211
+ $_return: $list;
212
+ }
213
+ @return $_return;
214
+ }
215
+
216
+ // th-list-has-deep()
217
+ /// Check list for a value (recursive).
218
+ ///
219
+ /// @since 0.0.10
220
+ /// @return {boolean} If list contains value.
221
+ ///
222
+ /// @param {list} $list - List to search.
223
+ /// @param {number | string} $find - Value to find.
224
+ ///
225
+ /// @example scss - Check for 'f' in (a b (c d (e f))).
226
+ /// th-list-has-deep((a b (c d (e f))), f)
227
+ /// // true
182
228
 
183
229
  @function th-list-has-deep(
184
230
  $list,
@@ -200,19 +246,47 @@
200
246
  // Units
201
247
  // ------------------------------
202
248
 
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
249
+ // _th-unit-convert()
250
+ /// Coverts a number into another unit.
251
+ ///
252
+ /// @since 0.0.14
253
+ /// @return {number} The converted number.
254
+ ///
255
+ /// @param {string} $unit - (px|em|rem|rel|percent) A unit to convert the number to.
256
+ /// @param {number} $number - The number to convert.
257
+ /// @param {number} $base-font-size [$th-base-font-size] - Font size used for relative calculations.
258
+ ///
259
+ /// @example scss - Convert 14px to em.
260
+ /// _th-unit-convert($unit: em, $number: 14px)
261
+ /// // 0.875em
262
+ /// @example scss - Convert 14px with base font size of 20px to em.
263
+ /// _th-unit-convert($unit: em, $number: 14px, $base-font-size: 20px)
264
+ /// // 0.700em
265
+
266
+ @function th-unit-convert(
267
+ $unit,
268
+ $number,
269
+ $base-font-size: $th-base-font-size
270
+ ){
271
+ $function: th-unit-convert-#{$unit};
272
+ @if function-exists($function) and unit($number) != $unit {
273
+ @return call($function, $number, $base-font-size);
274
+ } @else {
275
+ @return $number;
276
+ }
277
+ }
278
+
279
+ // th-unit-strip()
280
+ /// Strips the unit from a number.
281
+ ///
282
+ /// @since 0.0.11
283
+ /// @return {number} The stripped number.
284
+ ///
285
+ /// @param {number} $number - Number to strip unit from.
286
+ ///
287
+ /// @example scss - Strip px from 24px.
288
+ /// th-unit-strip(24px)
289
+ /// // 24
216
290
 
217
291
  @function th-unit-strip(
218
292
  $number
@@ -221,20 +295,18 @@
221
295
  @return $_return;
222
296
  }
223
297
 
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
298
+ // th-unit-cast()
299
+ /// Creates a number with a unit.
300
+ ///
301
+ /// @since 0.0.11
302
+ /// @return {number} The number with new unit.
303
+ ///
304
+ /// @param {number} $number - The unitless number to create.
305
+ /// @param {string} $unit - The type of unit to create.
306
+ ///
307
+ /// @example scss - Change 24 to 24px.
308
+ /// th-unit-cast(24, px);
309
+ /// // 24px
238
310
 
239
311
  @function th-unit-cast(
240
312
  $number,
@@ -250,25 +322,20 @@
250
322
  @return $_return;
251
323
  }
252
324
 
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(
325
+ // th-unit-convert-number()
326
+ /// Converts the unit of a number.
327
+ ///
328
+ /// @since 0.0.11
329
+ /// @return {number} The converted number.
330
+ ///
331
+ /// @param {number} $number - The numbered unit to convert.
332
+ /// @param {string} $unit - The unit to convert to.
333
+ ///
334
+ /// @example scss - Convert unit of 24px to em.
335
+ /// th-unit-convert-number(24px, em)
336
+ /// // 24em
337
+
338
+ @function th-unit-convert-number(
272
339
  $number,
273
340
  $unit
274
341
  ){
@@ -280,28 +347,22 @@
280
347
  @return $_return;
281
348
  }
282
349
 
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
350
+ // th-unit-convert-absolute()
351
+ /// Converts a relative number to an absolute number.
352
+ ///
353
+ /// @since 0.0.11
354
+ /// @return {number} The converted absolute number.
355
+ ///
356
+ /// @param {number} $number - The number to convert.
357
+ /// @param {string} $unit - The type of absolute unit.
358
+ /// @param {number} $base-font-size [$th-base-font-size] - Font size used for relative calculations.
359
+ ///
360
+ /// @example scss - Convert 2em to px.
361
+ /// th-unit-convert-absolute(2em, px)
362
+ /// // 32px
363
+ /// @example scss - Convert 2em to px with base font size of 10px.
364
+ /// th-unit-convert-absolute(2em, px, 10px);
365
+ /// // 20px
305
366
 
306
367
  @function th-unit-convert-absolute(
307
368
  $number,
@@ -312,33 +373,27 @@
312
373
  $_return: th-unit-strip($number) * th-unit-strip($base-font-size);
313
374
  $_return: th-math-round-to($_return, 5);
314
375
  @if $unit {
315
- $_return: th-unit-convert($_return, $unit);
376
+ $_return: th-unit-convert-number($_return, $unit);
316
377
  }
317
378
  @return $_return;
318
379
  }
319
380
 
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
381
+ // th-unit-convert-relative()
382
+ /// Converts an absolute number to a relative number.
383
+ ///
384
+ /// @since 0.0.11
385
+ /// @return {number} The converted relative number.
386
+ ///
387
+ /// @param {number} $number - The number to convert.
388
+ /// @param {string} $unit - The type of relative unit.
389
+ /// @param {number} $base-font-size [$th-base-font-size] - Font size used for relative calculations.
390
+ ///
391
+ /// @example scss - Convert 24px to em.
392
+ /// th-unit-convert-relative(24px, em)
393
+ /// // 1.5
394
+ /// @example scss - Convert 24px to em with a base font size of 32px.
395
+ /// th-unit-convert-relative(24px, em, 32px)
396
+ /// // 0.75em
342
397
 
343
398
  @function th-unit-convert-relative(
344
399
  $number,
@@ -347,125 +402,139 @@
347
402
  ){
348
403
  $_return: $number;
349
404
  $_return: th-unit-strip($number) / th-unit-strip($base-font-size);
350
- $_return: th-math-round-to($_return, 5);
351
405
  @if $unit {
352
- $_return: th-unit-convert($_return, $unit);
406
+ $_return: th-unit-convert-number($_return, $unit);
353
407
  }
354
408
  @return $_return;
355
409
  }
356
410
 
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
411
+ // th-unit-convert-em()
412
+ /// Converts an absolute number to an em number.
413
+ ///
414
+ /// @since 0.0.11
415
+ /// @return {number} The converted number with em unit.
416
+ ///
417
+ /// @param {number} $number - The number to convert.
418
+ /// @param {number} $base-font-size [$th-base-font-size] - Font size used for relative calculations.
419
+ ///
420
+ /// @example scss - Convert 24px to em.
421
+ /// th-unit-convert-em(24px)
422
+ /// // 1.5em
423
+ /// @example scss - Convert 24px to em with a base font size of 32px.
424
+ /// th-unit-convert-em(24px, 32px)
425
+ /// // 0.75em
376
426
 
377
427
  @function th-unit-convert-em(
378
428
  $number,
379
429
  $base-font-size: $th-base-font-size
380
430
  ){
381
431
  $_return: $number;
382
- $_return: th-unit-convert-relative($number, em, $base-font-size);
432
+ $_return: th-math-round-to($_return, 5);
433
+ $_return: th-unit-convert-relative($_return, em, $base-font-size);
383
434
  @return $_return;
384
435
  }
385
436
 
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
437
+ // th-unit-convert-rem()
438
+ /// Converts an absolute number to an rem number.
439
+ ///
440
+ /// @since 0.0.11
441
+ /// @return {number} The converted number with rem unit.
442
+ ///
443
+ /// @param {number} $number - The number to convert.
444
+ /// @param {number} $base-font-size [$th-rem-base] - Font size used for rem calculations.
445
+ ///
446
+ /// @example scss - Convert 24px to rem.
447
+ /// th-unit-convert-rem(24px)
448
+ /// // 1.5rem
449
+ /// @example scss - Convert 24px to rem with a rem base of 32px.
450
+ /// th-unit-convert-rem(24px, 32px)
451
+ /// // 0.75rem
405
452
 
406
453
  @function th-unit-convert-rem(
407
454
  $number,
408
- $base-font-size: $th-base-font-size
455
+ $base-font-size: $th-rem-base
409
456
  ){
410
457
  $_return: $number;
411
- $_return: th-unit-convert-relative($number, rem, $base-font-size);
458
+ $_return: th-math-round-to($_return, 5);
459
+ $_return: th-unit-convert-relative($_return, rem, $th-rem-base);
412
460
  @return $_return;
413
461
  }
414
462
 
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
463
+ // th-unit-convert-rel
464
+ /// Converts an absolute number to a relative number.
465
+ ///
466
+ /// @since 0.0.11
467
+ /// @return {number} The converted relative number.
468
+ ///
469
+ /// @param {number} $number - The number to convert.
470
+ /// @param {number} $base-font-size [$th-base-font-size] - Font size used for relative calculations.
471
+ ///
472
+ /// @example scss - Convert 24px to a relative number.
473
+ /// th-unit-convert-rel(24px)
474
+ /// // 1.5
475
+ /// @example scss - 24px to a relative number with a base font size of 32px.
476
+ /// th-unit-convert-rel(24px, 32px)
477
+ /// // 0.75
434
478
 
435
479
  @function th-unit-convert-rel(
436
480
  $number,
437
481
  $base-font-size: $th-base-font-size
438
482
  ){
439
483
  $_return: $number;
440
- $_return: th-unit-convert-relative($number, false, $base-font-size);
484
+ $_return: th-math-round-to($_return, 5);
485
+ $_return: th-unit-convert-relative($_return, false, $base-font-size);
441
486
  @return $_return;
442
487
  }
443
488
 
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
489
+ // th-unit-convert-px()
490
+ /// Converts a relative number to a px number.
491
+ ///
492
+ /// @since 0.0.11
493
+ /// @return {number} The converted absolute number.
494
+ ///
495
+ /// @param {number} $number - The number to convert.
496
+ /// @param {number} $base-font-size [$th-base-font-size] - Font size used for relative calculations.
497
+ ///
498
+ /// @example scss - Convert 2em to a px number.
499
+ /// th-unit-convert-absolute(2em)
500
+ /// // 32px
501
+ /// @example scss - Convert 2em to a px number with a base font size of 18px.
502
+ /// th-unit-convert-px(2em, 18px)
503
+ /// // 36px
463
504
 
464
505
  @function th-unit-convert-px(
465
506
  $number,
466
507
  $base-font-size: $th-base-font-size
467
508
  ){
468
509
  $_return: $number;
469
- $_return: th-unit-convert-absolute($number, px, $base-font-size);
510
+ $_return: th-math-round-to($_return, 5);
511
+ $_return: th-unit-convert-absolute($_return, px, $base-font-size);
512
+ @return $_return;
513
+ }
514
+
515
+ // th-unit-convert-percent
516
+ /// Converts an absolute number to a percentage.
517
+ ///
518
+ /// @since 0.0.11
519
+ /// @return {number} The converted percentage number.
520
+ ///
521
+ /// @param {number} $number - The number to convert.
522
+ /// @param {number} $base-font-size [$th-base-font-size] - Font size used for relative calculations.
523
+ ///
524
+ /// @example scss - Convert 24px to a percentage.
525
+ /// th-unit-convert-rel(24px)
526
+ /// // 150%
527
+ /// @example scss - Convert 24px to a percentage with a base font size of 32px.
528
+ /// th-unit-convert-rel(24px, 32px)
529
+ /// // 75%
530
+
531
+ @function th-unit-convert-percent(
532
+ $number,
533
+ $base-font-size: $th-base-font-size
534
+ ){
535
+ $_return: $number;
536
+ $_return: th-math-round-to($_return, 7);
537
+ $_return: th-unit-convert-relative($number, false, $base-font-size);
538
+ $_return: $_return * 100%;
470
539
  @return $_return;
471
540
  }