/// Apply a font size and line height computed using a modular scale.
///
/// Font size will be computed directly using the modular scale.
///
/// Line-height is optional. If it is not defined, it will be set to the
/// closest multiple of the base line height above the computed font size.
///
/// @group typography
///
/// @parameter {Number} $step               - the modular scale step to compute
/// @parameter {Number} $line-height [null] - the line-height
/// @parameter {Boolean} $without-line-height [false]
///   - the boolean that lets the line height to be use
///
/// @example scss - Usage
///   $k-typography: (
///     font-size:   1rem,
///     line-height: 1.5rem,
///     scale-multiplier: 1.618,
///     …
///   );
///
///   @include k-typographyFontSize(3);
///
/// @example css - CSS output
///   font-size:   4.236rem;
///   line-height: 4.5rem;

@mixin k-typographyFontSize(
  $step: 0,
  $line-height: null,
  $without-line-height: false
) {

  // Modular scale multiplier
  $multiplier: k-map-fetch($k-typography, 'scale-multiplier');

  $valid:
    k-all(
      k-validate(
        $multiplier, k-number-schema($unit: none),
        'k-typographyFontSize', '$multiplier'
      ),
      k-validate(
        $step, k-number-schema($unit: none),
        'k-typographyFontSize', '$step'
      )
    );

  // The starting font size applied to the body element.
  $base-font-size: k-map-fetch($k-typography, 'font-size');

  // The base line height.
  $base-line-height: k-map-fetch($k-typography, 'line-height');

  // Given the requested step on our modular scale, compute font size.
  $font-size: ms($step, $base-font-size, $multiplier);

  @if not $line-height {
   // If line-height is not defined, we use the vertical rhythm rule to compute
   // if. Line height should be the closest multiple of the base line height.
    $line-height: ceil($font-size / $base-line-height) * $base-line-height;
  }

  // Apply font size and line height.
  font-size: $font-size;

  @if not $without-line-height {
    line-height: $line-height;
  }
}
