@use "sass:list";
@use "sass:map";
@use "sass:string";

// Fonts
// ============================================================================
//  Includes all font face variants for Oslo Sans.
//  Medium is used as the bold font, so font-weight: bold will use OsloSans-Medium
@mixin font-face($name, $path, $weight: null, $style: null, $exts: eot woff2 woff ttf svg) {
  $src: null;
  $extmods: (
    eot: "?",
    svg: "#" + str-replace($name, " ", "_"),
  );
  $formats: (
    otf: "opentype",
    ttf: "truetype",
  );
  @each $ext in $exts {
    $extmod: if(map.has-key($extmods, $ext), $ext + map.get($extmods, $ext), $ext);
    $format: if(map.has-key($formats, $ext), map.get($formats, $ext), $ext);
    $src: list.append($src, url(string.quote($path + "." + $extmod)) format(string.quote($format)), comma);
  }
  @font-face {
    font-family: string.quote($name);
    font-style: $style;
    font-weight: $weight;
    font-display: swap;
    src: $src;
  }
}
