UNPKG

typerules

Version:

A typography toolkit that sets vertical rhythm and provides type functions.

25 lines (19 loc) 1 kB
/* REM function */ // Convert pixel units to rem units rem($pixels) (floor($pixels/$base-font-size, 10))rem // True if a number has a relative unit. check-unit(number) if (unit(number) is 'px') warn('relative-font-sizing is false but a relative font size was passed to the rhythm function') // Calculates rhythm units. calculates-rhythm-units($lines = 1, $offset = 0) if (not $relative-font-sizing) and ($font-size is not $base-font-size) warn('relative-font-sizing is false but a relative font size was passed to the rhythm function') return rem($lines * $base-line-height - $offset) // Calculates the minimum multiple of rhythm units needed to contain the font-size. lines-for-font-size($font-size) $lines = $round-to-nearest-half-line ? ceil(2 * $font-size / $base-line-height) / 2 : ceil($font-size / $base-line-height) if $lines * $base-line-height - $font-size < $min-line-padding * 2 $lines = $lines + ($round-to-nearest-half-line ? 0.5 : 1) return unit($lines, '')