// Type
// ====


// Get Lines [function]
// --------------------
/// Determine the number of typographic "lines" required
/// for a given font size and rhythm.
///
/// @access private
///
/// @param {String | Length | List} $size -
///   The name, length, or calculations required
///   for defining the font-size.
/// @param {String | Length | List} $rhythm -
///   The name, length, or calculations required
///   for defining the typographic rhythm.
@function _get-lines(
  $size: 'root',
  $rhythm: 'rhythm'
) {
  $font-size: size($size);
  $line-height: size($rhythm);

  @if (not comparable($font-size, $line-height)) {
    $font-size: convert-units($font-size, 'px');
    $line-height: convert-units($line-height, 'px');
  }

  @return ceil(2 * $font-size / $line-height) / 2;
}

// Round-to-even [function]
//-------------------------
//
/// Rounds the values to the nearest even.
/// @access private
///
/// @param {Number} $value - number
/// @returns {Number} even number
@function _round-to-even($value) {
  @if type-of($value) == number {
     $result: 2 * round($value / 2);

     @return $result;
  }

  @error ' type-of #{$value} should a number.';
}

// Calc leading [function]
// Rounds up an integer value and converts it to a rem unit
// @param {String} - $leading -
//  The name of key from $sizes map, which contains the word leading.
// @returns {Number} - Rounded to integer and converted to rem number.

@function calc-leading($leading) {
  $result: _round-to-even(size($leading));

  @return convert-units($result, 'rem');
}


// Browser Ems [function]
// ----------------------
/// Convert any comparable size into browser-default ems
/// usable in media-queries.
///
/// @group type
///
/// @param {String | Length | List} $size -
///   The name, length, or calculations required
///   for defining the font-size.
/// @return {Length} -
///   The given size, converted to `16px`-based `em` units.
@function browser-ems(
  $size
) {
  $size: size($size, 'px');

  @return $size / $_BROWSER-DEFAULT-FONT-SIZE * 1em;
}