Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save singhmohancs/eb9be6c6cb7256a2fb2a2529a6a53f38 to your computer and use it in GitHub Desktop.
Save singhmohancs/eb9be6c6cb7256a2fb2a2529a6a53f38 to your computer and use it in GitHub Desktop.
/**
* Calculates numbers to the mathmatical power (exponent)
*
* @since 1.0.0
*
* @param int $number The number to increase
* @param int $exponent The power to increase the number by
*
* @return int The new number
*/
@function pow( $number, $exponent ) {
$value: 1;
@if $exponent > 0 {
@for $i from 1 through $exponent {
$value: $value * $number;
}
}
@return $value;
}
/**
* Removes units from values for easier modification
*
* @since 1.0.0
*
* @param int $number The number to strip units from
*
* @return int The number without the unit
*/
@function strip-unit( $number ) {
@if type-of( $number ) == 'number' and not unitless( $number ) {
@return $number / ( $number * 0 + 1 );
}
@return $number;
}
/**
* Calculates the line height based on multiple parameters
*
* @since 1.0.0
*
* @param int $font-size The font size
* @param int $content-width The width of the content area
* @param int $ratio The ratio. Default 1.61803398875 (golden ratio)
*
* @return int The calculated line height
*/
@function calculate-line-height( $font-size, $content-width, $ratio: 1.61803398875 ) {
$font-size: strip-unit( $font-size );
$content-width: strip-unit( $content-width );
@return $ratio - ( ( 1 / ( 2 * $ratio ) ) * ( 1 - ( $content-width / ( pow( ( $font-size * $ratio ), 2 ) ) ) ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment