///
/// Miscellaneous functions, mostly used in the headings helpers
///
@use "sass:math";
@use "../../settings";

@function strip-unit($num) {
    @return math.div($num, ($num * 0 + 1));
}

@function get-unit($value) {
  @return str-slice($value * 0 + "", 2, -1);
}

@function px-to-em ($px, $base: settings.$root-font-size) {
    @return math.div($px, $base) * 1em;
}

@function px-to-rem ($px, $base: settings.$root-font-size) {
    @return math.div($px, $base) * 1rem;
}

@function rem-to-px ($rem, $base: settings.$root-font-size) {
    @return strip-unit($rem * $base) * 1px;
}

@function nearest-grid-size ($value, $grid: 8px) {
    @return round(math.div($value, $grid)) * $grid;
}

@function line-height-on-grid ($font-size, $line-height: 1.5, $grid: 8px) {
    @return math.div(nearest-grid-size($font-size * $line-height, $grid), $font-size);
}
