@use "sass:math";

/* creates unitless number value, ie .875rem -> .875 */
@function parse_int($n) {
   @return math.div($n, ($n * 0 + 1));
}

@function rem2px($size) {
   $value: parse_int($size) * 16px;
   @return round($value);
}

@function to-rem($value) {
   $remValue: (calc($value / 16)) + rem;
   @return $remValue;
}

// Characters which are escaped by the escape-svg function
$escaped-characters: (
   ("<","%3c"),
   (">","%3e"),
   ("#","%23"),
) !default;

// See https://codepen.io/kevinweber/pen/dXWoRw
@function escape-svg($string) {
   @if str-index($string, "data:image/svg+xml") {
      @each $char, $encoded in $escaped-characters {
         $string: str-replace($string, $char, $encoded);
      }
   }

   @return $string;
}

// http://thesassway.com/intermediate/dynamically-change-text-color-based-on-its-background-with-sass
@function pick-color-adjustment($color, $perc) {
   @if (lightness($color) > 45) {
      @return darken($color, $perc);
   }
   @else {
      @return lighten($color, $perc);
   }
}
