@use "sass:math";
@use "sass:map";

@function v($var, $fallback: null) {
    @if ($fallback) {
        @return var(--#{$var}, #{$fallback});
    } @else {
        @return var(--#{$var});
    }
}
@function mapReverseValues($map) {
    $keys: map.keys($map);
    $map-reversed: ();

    @for $i from length($keys) through 1 {
        $currentPos: calc(length($keys) - $i + 1);

        $map-reversed: map.merge(
            $map-reversed,
            (nth($keys, $currentPos): map.get($map, nth($keys, $i)))
        );
    }
    @return $map-reversed;
}
@function map-deep-get($map, $keys...) {
    @each $key in $keys {
        @debug #{$map};
        $map: map-get($map, $key);
    }
    @return $map;
}

@function strip-units($value) {
    @return math.div($value, $value * 0 + 1);
}
@function to-rem($pxval) {
    @if not unitless($pxval) {
        $pxval: strip-units($pxval);
    }
    $base: 16px;
    @if not unitless($base) {
        $base: strip-units($base);
    }
    @return math.div($pxval, $base) * 1rem;
}
